Fragiola

API: core (@fragiola/calendar)

Features

The opt-in features, each on its own entry point, with what each factory adds, its options, its parts in React, and the types for writing a feature.

The core is a minimal calendar: the document, the views and their layout, the event commands with their edit rules, the keyboard over dates and events. Everything else is an opt-in feature, a factory from its own entry point that the main entry never imports, so a calendar that does not drag ships no drag code (Features). The features are given to the model once, for its life; which ones a screen offers is yours.

import { Calendar } from "@fragiola/calendar-react";
import { dragAndDrop } from "@fragiola/calendar-react/drag-and-drop";
import { resize } from "@fragiola/calendar-react/resize";
import { selection } from "@fragiola/calendar-react/selection";

// a const tuple, outside the component: read once by the root
const FEATURES = [selection(), dragAndDrop(), resize()] as const;

export function Planner() {
    return (
        <Calendar.Root features={FEATURES} defaultView="week">
            {/* the time grid, with Selection, DragPreview and ResizeHandle parts */}
        </Calendar.Root>
    );
}

Each adapter's entry (@fragiola/calendar-react/<entry>, @fragiola/calendar-vue/<entry>, @fragiola/calendar-angular/<entry>) re-exports the core's @fragiola/calendar/<entry> and adds the feature's parts and hooks (Vue's composables of the same names, Angular's directives and injection functions), so an app installs one package. A feature's command, key, setting or document field in a model without it is refused, naming the feature; a feature's root callback (onSelect, or @select on a typedCalendar root in Vue) is a type error without it (in Angular, its root directive warns once and never emits).

The features

factoryentryadds
selection(options?)@fragiola/calendar/selectionselecting a range of days or time by pointer and keyboard: selection.set, selection.clear, "selected-range", the select event
dragAndDrop(options?)@fragiola/calendar/drag-and-dropmoving events by pointer and keyboard, across days and between the all-day row and the time grid: one event.move on drop
resize()@fragiola/calendar/resizechanging an event's start or end by its handles and by keyboard
recurrence()@fragiola/calendar/recurrencerecurring events: RRULE, excluded dates, overrides, edit scopes
nowIndicator(options?)@fragiola/calendar/now-indicatorthe current time's place in the time grid, updated on each tick
constraints()@fragiola/calendar/constraintsbusiness hours, allowed ranges and overlap rules that refuse commands
externalDrop(options?)@fragiola/calendar/external-dropreceiving drags from outside: native drops and app-driven drags (requires dragAndDrop())
eventSources()@fragiola/calendar/event-sourcesthe ranges to fetch per source and their loading state; the fetch is yours

Each factory returns its feature type: SelectionFeature, DragAndDropFeature, ResizeFeature, RecurrenceFeature, NowIndicatorFeature, ConstraintsFeature, ExternalDropFeature, EventSourcesFeature. model.get("features") lists the installed ones as CalendarFeatureInfo (name, requires).

Options

SelectionOptions, DragAndDropOptions, NowIndicatorOptions and ExternalDropOptions:

optionofdefaultdescription
selectMinDistanceselection()0the pixels a mouse or pen press moves before it selects; 0: a click selects its day or slot
recurringScopedragAndDrop()"this"the EditScope a drop of a recurring occurrence runs with; ask the user in a middleware instead (Recurring events)
intervalnowIndicator()60000how often the position moves, in ms, on the interval's boundaries (at least a second)
acceptexternalDrop()anywhether a native drag may drop, from its DataTransfer.types ("Files", "text/plain")
draftexternalDrop()nonethe ExternalEventDraft a native drop adds, from its DataTransfer and GridPoint, or null to leave the drop to the app
import { externalDrop } from "@fragiola/calendar/external-drop";

const files = externalDrop({
    accept: (types) => types.includes("Files"),
    draft: (dataTransfer) => {
        const file = dataTransfer.files[0];
        return file ? { title: file.name, duration: { minutes: 30 } } : null;
    },
});

What each entry exports

entrythe core'sReact's own
selectionselection, SelectionOptions, SelectionFeature, SelectionRange, SelectionSlice (the selection state slice)Selection, SelectionProps, SelectionState, useSelection, CalendarSelection (Selection)
drag-and-dropdragAndDrop, DragAndDropOptions, DragAndDropFeature, DragPreview, PreviewSegments, PreviewTimesDragPreview (the component shadows the type), DragPreviewProps, DragPreviewState, useDragPreview (DragPreview)
resizeresize, ResizeFeature, DragPreviewResizeHandle, ResizeHandleProps, ResizeHandleState, and DragPreview (ResizeHandle)
recurrencerecurrence, RecurrenceFeature, RecurrenceJson, EditScope, OccurrenceTarget, parseRecurrenceRule, formatRecurrenceRule, RecurrenceRule, RecurrenceFrequency, RecurrenceWeekdaythe core's only
now-indicatornowIndicator, NowIndicatorOptions, NowIndicatorFeature, NowPositionNowIndicator, NowIndicatorProps, NowIndicatorState, useNowPosition (NowIndicator)
constraintsconstraints, ConstraintsFeature, BusinessHours, ConstraintRange, EventConstraint, BusinessHoursRange, SelectionRangeBusinessHours (the component shadows the type), BusinessHoursProps, BusinessHoursState, useBusinessHours (BusinessHours)
external-dropexternalDrop, ExternalDropOptions, ExternalDropFeature, ExternalEventDraft, DragPreviewthe core's only
event-sourceseventSources, EventSourcesFeature, EventSource, EventSourceStatus, RangeToFetch, EventSourcesSlice, SourceStatethe core's only

Recurrence rules

parseRecurrenceRule(value) reads an RRULE string into a RecurrenceRule (a ValidationResult: an unknown part is an issue naming it); formatRecurrenceRule(rule) writes one back. A rule's freq is a RecurrenceFrequency ("DAILY", "WEEKLY", "MONTHLY", "YEARLY"), its byDay a list of RecurrenceWeekday ({ weekday, ordinal? }).

import {
    formatRecurrenceRule,
    parseRecurrenceRule,
} from "@fragiola/calendar/recurrence";

const parsed = parseRecurrenceRule("FREQ=MONTHLY;BYDAY=-1FR");
if (parsed.ok) {
    parsed.value.byDay; // [{ weekday: 5, ordinal: -1 }]: the last Friday
    formatRecurrenceRule({ ...parsed.value, count: 6 }); // "FREQ=MONTHLY;COUNT=6;BYDAY=-1FR"
}

Event sources' state

SourceState is what the model knows of one source (fetched and loading ranges, merged); EventSourcesSlice holds them by source id (eventSourceStates), model state that the document does not write. model.get("event-source-by", { id }) gives an EventSourceStatus, model.get("ranges-to-fetch") the RangeToFetch entries (Loading events from a server).

Feature names

FEATURE_KEYS lists what each feature owns by name (its commands, keys, fields, settings and engine events), which is how the core refuses what belongs to a feature that is not installed and types the verbs from the installed ones. FeatureName is one of its keys: "selection", "drag-and-drop", "resize", "recurrence", "now-indicator", "constraints", "external-drop" and "event-sources". emittersOf(type) names the features that emit an engine event (emittersOf("drop") is drag and drop and resize).

Typing with features

A model's type carries its features: CalendarModel<T, typeof FEATURES> checks a feature's command and keys, and CalendarStateOf<T, F> adds their state slices. The type helpers:

typedescription
CalendarFeaturesa tuple of features, as features takes it
AnyCalendarFeatureany one feature
AnyFeatures<F>whether F is the open tuple (any features)
CalendarStateOf<T, F>the state with the features' slices
EngineRunKeyOf<F, All>, EngineGetKeyOf<F, All>, EngineIsKeyOf<F, All>the engine keys the features allow
EngineEventTypeOf<F, All>the engine events they emit

Writing a feature

defineFeature(spec) freezes a CalendarFeature: its name (a FeatureName), the features it requires, its settings, commands and keys, and the contribution points the core calls (its occurrences, its edit writes, its checks, its engine side). The built-in features are written with it; it is the extension point the core is built on, documented for readers of their code.

typerole
CalendarFeaturea feature: its name, requirements, settings, commands, keys and contribution points
FeatureCommanda command it adds, with its JSON Schemas
FeatureStatethe state its rules read: the DraftState with its slice
FeatureDocumentthe document fields it loads and writes
FeatureReadsreads the core lends its rules: every event's occurrences, a recurring one's expanded
EditRequest, EditWritean edit of an occurrence the core computed, and how a feature writes it (an override, an exdate, a split)
EventChangethe change a constraint checks: the event before and after, the occurrence it started from
PartAttributes, MutablePartAttributesthe attributes a part gets, read-only and while a feature adds its own
FeatureModelthe model as a feature's engine side sees it
FeatureEnginea feature's engine side: its keys, its key handling, its press handling
FeatureEngineHostwhat the engine lends it: the model, the clock, the measured grid, the shared drag session
FeatureGesturea press that became a gesture: move, end, cancel, active
PressTargetwhat a press started on
Draft, DraftStatethe state a command's reducer writes, and its ids and clock