Fragiola

API: core (@fragiola/calendar)

Engine

createCalendarEngine and the engine of one calendar on screen. Focus, gestures, measurement, the screen's keys and events, and the adapter surface.

The engine is one calendar view on screen, over a model: the roving focus and the keyboard, the pointer and touch gestures (selection, drag, resize, external drops), the measurement of dayMaxEvents: "auto", the midnight refresh and the now line's tick. It reads the DOM only through the root element's window, or through an injected host. Calendar.Root creates it in a layout effect and destroys it on unmount; useCalendar().engine gives it to your components (Model and engine). The words of an announcement, the popover of a "+N more" link and the editor a selection opens are yours.

import { useCalendar } from "@fragiola/calendar-react";

function GoToReview() {
    const { engine } = useCalendar();
    return (
        <button
            type="button"
            onClick={() => engine.run("focus", { occurrenceId: "review" })}
        >
            Focus the review
        </button>
    );
}

engine.run("focus", …) navigates to the event when the view does not show it, then gives it the grid's tab stop and the DOM focus.

createCalendarEngine

createCalendarEngine(model, options?) returns a CalendarEngine; the adapter attaches its root. An app on an adapter never calls it: the root's engine props take the same CalendarEngineOptions (longPressDelay in React, long-press-delay in Vue, the longPressDelay input in Angular).

optiontypedefaultdescription
hostPartial<EngineHost>the root's windowthe timers, frames, ResizeObserver and computed styles; any member can be injected
longPressDelaynumber500ms a touch is held before it drags or selects
dragThresholdnumber5px a mouse or pen press moves before a drag starts
autoScroll{ edge?, speed? } | false{ edge: 40, speed: 12 }the time grid's scroll while a gesture nears its scroller's edges

Members

Every member is one verb, as on the model, and bound.

membersignaturedescription
run(action, payload?) => CommandResultruns a screen action (the keys below)
can(action, payload?) => booleanwhether run would succeed
check(action, payload?) => CommandResultwhat run would return
get(key, payload?) => resultreads a fact of the screen
is(key, payload?) => booleanasks a yes/no question of the screen
subscribe(listener: (event: CalendarEngineEvent) => void) => () => voidlistens to the engine events; returns its remover
destroy() => voidreleases every listener, timer and element
adapterCalendarEngineAdapterwhat only an adapter calls

An engine action has no dot, so it never reads as a command: commands change the calendar through the model; actions are what only the screen does.

run actions

Typed by EngineRunMap (EngineRunKey):

actionpayloadresult
"focus"a FocusTarget: { date, time? } or { occurrenceId, date? }{ focused }: the FocusPosition
"cancel-gesture"none{ cancelled }: a drag, a selection or a grab ended with nothing committed
"measure"none{ maxLanes }: the day cells measured again (dayMaxEvents: "auto")
"external-drag-start"{ event }: an ExternalEventDraftstarts an app-driven drag from outside (externalDrop())
"external-drag-move"{ clientX, clientY }{ point }: the GridPoint under it
"external-drag-end"{ cancel? }{ eventId }: the event added, or null

An ExternalEventDraft is event.add's payload without its times, plus an optional duration ({ minutes?, days? }) (External drop).

get keys

Typed by EngineGetMap (EngineGetKey):

keypayloadresult
"focused"nonethe FocusPosition, or null before anything was focused
"tab-stop"nonewhere the grid's one tab stop is
"day-grid"nonethe DayGrid with the measured lane limit applied
"max-lanes"nonethe measured lane limit of dayMaxEvents: "auto", or null
"direction"none"ltr" or "rtl", read from the root's computed style
"point-at"{ clientX, clientY }the GridPoint under a client point, or null
"drag-preview"nonethe dragged occurrence where it would land, a DragPreview (dragAndDrop())
"resize-preview"nonethe resized occurrence's new times (resize())
"selection-preview"nonethe SelectionRange being selected (selection())
"selection-segments"nonethe selection laid out as an event: PreviewSegments (selection())
"now-position"nonethe current time's NowPosition in the time grid (nowIndicator())

FocusPosition is a CellPosition ({ kind: "day", date } or { kind: "slot", date, time }) or an EventPosition ({ kind: "event", occurrenceId, cell }). A GridPoint is a day ({ kind: "day", date }) or a time snapped to snapDuration ({ kind: "time", date, minutes, time }). Positions are dates and times, never pixels. KeyTarget is where a key takes the focus from a cell, for a feature's key handling.

A DragPreview holds its PreviewTimes (eventId, occurrenceId, start, end, allDay), its PreviewSegments (weeks and columns, in the layouts' shape) and its kind ("move", "resize" or "external") and keyboard. A NowPosition is { date, time, top }, top a fraction of the column.

is keys

Typed by EngineIsMap (EngineIsKey):

keypayloadtrue when
"gesture-active"nonea pointer gesture or a keyboard grab is under way
"event-dragging"{ occurrenceId }the occurrence is being dragged (dragAndDrop())
"event-grabbed"{ occurrenceId }it is grabbed by the keyboard (dragAndDrop())
"event-resizing"{ occurrenceId }it is being resized (resize())

Engine events

engine.subscribe hears a CalendarEngineEvent (CalendarEngineEventType names its type, CalendarEngineEventOf<K> one of them). In React, each is a root callback: on plus its ENGINE_EVENT_CALLBACKS name (Calendar.Root); in Vue, a listener on the root, that name in kebab-case (@event-click, @event-drop; Vue primitives); in Angular, an output of the root ((eventClick)), a feature's of its directive on the root ((eventDrop); Angular primitives).

typecallbackcarries
"event-click"onEventClickeventId, occurrenceId, keyboard: a tap on an event, or Enter on a focused one
"date-click"onDateClickdate, allDay, a slot's time and at: a tap on a day or a slot
"more-click"onMoreClickdate, occurrenceIds: a "+N more" link; the popover is yours
"select"onSelectrange, keyboard: a range was selected (selection())
"drop"onEventDropkind ("move" or "resize"), the ids, the new times, keyboard
"external-drop"onExternalDropeventId (or null), point, types, dataTransfer (externalDrop())
"today-change"onTodayChangetoday: the day changed at midnight in the display zone
"announce"onAnnounceannouncement: an Announcement your live region words

An Announcement is data, never text: its kind is "grab", "drag-over", "drop", "drag-cancel" or "select-extend", with the occurrence and the times or range (Keyboard).

import type { Announcement } from "@fragiola/calendar";

function announcementText(announcement: Announcement): string {
    switch (announcement.kind) {
        case "grab":
            return "Grabbed. Use the arrows to move, Enter to drop.";
        case "drop":
            return `Dropped at ${announcement.preview.start}.`;
        case "drag-cancel":
            return "Cancelled.";
        default:
            return "";
    }
}

The host

EngineHost is what the engine schedules and measures with. Every member not injected is the root's window's, read when the root is attached, so the same engine runs in an iframe; a test injects its own timers.

membertypedescription
setTimeout(callback, ms) => numberthe midnight refresh, a long press, the now tick
clearTimeout(id) => voidcancels one
requestAnimationFrame(callback) => numberautoscroll
cancelAnimationFrame(id) => voidcancels one
ResizeObserverResizeObserverConstructorobserves the measured cells (dayMaxEvents: "auto"); none: measured on commit only
getComputedStyle(element) => { direction }the root's direction

The adapter surface

engine.adapter (CalendarEngineAdapter) is what a framework adapter calls; an app does not.

memberdescription
modelthe model this engine shows
attachRootattaches the root element: the engine listens to its pointers, keys, focus and native drags
detachRootdetaches it, cancelling a gesture under way
registerregister(part, payload, element) registers (or, with null, unregisters) a part's element: measured, hit-tested, focused
attributesattributes(part, payload, options?): a part's PartAttributes: data-calendar-part, the model's, the engine's and the features'; options (PartAttributeOptions) say how the app renders the parts: weekNumberColumn, a month's rows render a week number
committedthe adapter committed a render: the engine measures and gives focus to an element it waited for
subscribecalls a listener with a ViewChange (focus, gesture, layout) when the view changes; returns its remover
getSnapshota number that changes whenever the view changes

PartName names a registered part and PartPayloadMap its payload ({ date } for a day, { occurrenceId, date } for an event). Before an engine exists (a server render, the first client render), partAttributes(model, part, payload, options?) gives the same attributes with nothing focused, the tab stop where the model puts it (State attributes).

import { createCalendarModel, partAttributes } from "@fragiola/calendar";

const model = createCalendarModel({
    version: 1,
    events: [],
    view: { type: "month", anchorDate: "2026-11-26" },
});
partAttributes(model, "day", { date: "2026-11-26" });
// { "data-calendar-part": "day", "data-date": "2026-11-26", role: "gridcell", tabindex: ..., ... }