@moltenship/calendar-primitives 0.0.0-stage → 2.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,817 @@
1
+ import { CalendarClock, InstantInterval, PlainDateInterval } from "@moltenship/calendar-temporal";
2
+ import { AnnotationSnapshot, AnnotationSnapshotIssue, AvailabilityIssue, AvailabilitySnapshot, CalendarAnnotation, CalendarAnnotationSource, CalendarAnnouncementContext, CalendarAnnouncementMessages, CalendarAnnouncer, CalendarAvailability, CalendarCellFocus, CalendarChangeCause, CalendarDraft, CalendarEnvironment, CalendarEnvironmentBase, CalendarEventChangeHandler, CalendarEventPlacement, CalendarEventProposal, CalendarFocus, CalendarInteractionCheck, CalendarKeyboardSession, CalendarNowSource, CalendarPendingChanges, CalendarPendingPlacements, CalendarPolicy, CalendarPolicyResult, CalendarProposalDetail, CalendarProposalOutcome, CalendarSecondaryTimeZone, CalendarSelection, CalendarTransactionResult, CalendarViewStrategy, CalendarWeekRules, EventAdapter, EventId, EventSnapshot, EventSnapshotIssue, EventTransactions, InvalidCalendarEventPolicy, NormalizedCalendarEvent, ResourceId, ResourceTree, SecondaryTimeZoneIssue } from "@moltenship/calendar-core";
3
+ import { PrimitiveInstance, PropSpec, SlotDefinition } from "@ui-sdk/core";
4
+ interface CalendarPublicState<TView extends string = string, TSelection = CalendarSelection, TFocus = CalendarFocus, TResourceId extends ResourceId = ResourceId> {
5
+ readonly anchorDate: Temporal.PlainDate;
6
+ readonly expandedResourceIds: readonly TResourceId[];
7
+ readonly focus: TFocus | null;
8
+ readonly selection: TSelection | null;
9
+ readonly timeZone: string;
10
+ readonly view: TView;
11
+ }
12
+ type CalendarStateSlice = keyof CalendarPublicState;
13
+ interface CalendarStoreOptions<TView extends string = string, TSelection = CalendarSelection, TFocus = CalendarFocus, TResourceId extends ResourceId = ResourceId> {
14
+ readonly defaultAnchorDate: Temporal.PlainDate;
15
+ readonly defaultExpandedResourceIds?: readonly TResourceId[];
16
+ readonly defaultFocus?: TFocus | null;
17
+ readonly defaultSelection?: TSelection | null;
18
+ readonly defaultTimeZone: string;
19
+ readonly defaultView: TView;
20
+ }
21
+ /** Slices whose value is owned by props. `undefined` leaves a slice uncontrolled. */
22
+ type CalendarControlledState<TView extends string = string, TSelection = CalendarSelection, TFocus = CalendarFocus, TResourceId extends ResourceId = ResourceId> = Partial<CalendarPublicState<TView, TSelection, TFocus, TResourceId>>;
23
+ /**
24
+ * Why a slice changed: `"imperative"` for a command called from code, the press of the
25
+ * navigation trigger that asked for it, `"input-change"` for the view switcher,
26
+ * `"keyboard-navigation"` for a view's keys moving focus or the range, `"focus-change"` for focus
27
+ * a person moves onto a cell or event, and `"resource-toggle"` for a resource's expand or collapse.
28
+ */
29
+ type CalendarChangeReason = "focus-change" | "imperative" | "input-change" | "keyboard-navigation" | "next-press" | "previous-press" | "resource-toggle" | "today-press";
30
+ /**
31
+ * Who caused a change: a person by `"mouse"`, `"touch"`, `"pen"`, `"keyboard"` or `"virtual"` (a
32
+ * click with no pointer or key behind it, which may be assistive technology), an AI agent
33
+ * (`"agent"`), or code (`"programmatic"`). For analytics and focus choices, not for behaviour;
34
+ * a change to refuse an agent's is the place for that.
35
+ */
36
+ type CalendarChangeSource = "agent" | "keyboard" | "mouse" | "pen" | "programmatic" | "touch" | "virtual";
37
+ /** What a command passes on to the change handler it reaches. */
38
+ interface CalendarCommandOptions {
39
+ /** The DOM event behind the command, which tells the handler how the person caused it. */
40
+ readonly event?: Event;
41
+ /** `"imperative"` by default. */
42
+ readonly reason?: CalendarChangeReason;
43
+ /**
44
+ * Who asked, when the command doesn't learn it from `event`: the calendar's agent actions pass
45
+ * `"agent"`. Worked out from the event, or `"programmatic"`, when absent.
46
+ */
47
+ readonly source?: CalendarChangeSource;
48
+ }
49
+ /**
50
+ * What a change handler hears beside the new value: why it changed, the DOM event behind it, who
51
+ * caused it (`"agent"` for a change an AI agent asked for) and `cancel()`, plus the slice, its
52
+ * previous value and whether a prop controls it. `cancel()` keeps an uncontrolled slice as it
53
+ * was; a controlled one changes only when its owner passes the new value anyway.
54
+ */
55
+ interface CalendarStateChangeDetail<TValue, TSlice extends CalendarStateSlice = CalendarStateSlice> {
56
+ /** Stops the change: an uncontrolled slice keeps its value. */
57
+ readonly cancel: () => void;
58
+ /** Whether `cancel()` was called. */
59
+ readonly canceled: boolean;
60
+ readonly controlled: boolean;
61
+ /** The DOM event behind the change, as a trigger's click; absent for code and agents. */
62
+ readonly event?: Event;
63
+ readonly previous: TValue;
64
+ readonly reason: CalendarChangeReason;
65
+ readonly slice: TSlice;
66
+ readonly source: CalendarChangeSource;
67
+ }
68
+ type CalendarStateChangeHandler<TValue, TSlice extends CalendarStateSlice> = (next: TValue, detail: CalendarStateChangeDetail<TValue, TSlice>) => void;
69
+ type CalendarStateChangeHandlers<TView extends string = string, TSelection = CalendarSelection, TFocus = CalendarFocus, TResourceId extends ResourceId = ResourceId> = { readonly [TSlice in CalendarStateSlice as `on${Capitalize<TSlice>}Change`]?: CalendarStateChangeHandler<CalendarPublicState<TView, TSelection, TFocus, TResourceId>[TSlice], TSlice>; };
70
+ type CalendarActions<TView extends string = string, TSelection = CalendarSelection, TFocus = CalendarFocus, TResourceId extends ResourceId = ResourceId> = { readonly [TSlice in CalendarStateSlice as `set${Capitalize<TSlice>}`]: (next: CalendarPublicState<TView, TSelection, TFocus, TResourceId>[TSlice], options?: CalendarCommandOptions) => void; };
71
+ /**
72
+ * Uncontrolled calendar state. While a `Root` is mounted with this store, `actions` honor that
73
+ * root's controlled slices and change handlers.
74
+ */
75
+ interface CalendarStore<TView extends string = string, TSelection = CalendarSelection, TFocus = CalendarFocus, TResourceId extends ResourceId = ResourceId> {
76
+ readonly actions: CalendarActions<TView, TSelection, TFocus, TResourceId>;
77
+ readonly getSnapshot: () => CalendarPublicState<TView, TSelection, TFocus, TResourceId>;
78
+ readonly subscribe: (listener: () => void) => () => void;
79
+ }
80
+ /**
81
+ * The store a root takes: one made with the root's types, or, for a calendar without resources,
82
+ * one made with the default `ResourceId`. An adapter whose `getResourceIds` returns `[]` infers
83
+ * `never` for its resource IDs, which a store made without type arguments doesn't match; such a
84
+ * calendar has no resource ID to keep, so either fits.
85
+ */
86
+ type CalendarRootStore<TView extends string = string, TSelection = CalendarSelection, TFocus = CalendarFocus, TResourceId extends ResourceId = ResourceId> = CalendarStore<TView, TSelection, TFocus, TResourceId> | ([TResourceId] extends [never] ? CalendarStore<TView, TSelection, TFocus> : never);
87
+ type CalendarStateSelector<TState, TSelected> = (state: TState) => TSelected;
88
+ interface CalendarStateSelectorOptions<TSelected> {
89
+ readonly isEqual?: (previous: TSelected, next: TSelected) => boolean;
90
+ }
91
+ /** Something that holds a value and says when it changes, as a store or a root's pending changes. */
92
+ interface CalendarStateSource<TState = AnyCalendarState> {
93
+ /** What the server and hydration read, when it differs from `getSnapshot`. */
94
+ readonly getServerSnapshot?: () => TState;
95
+ readonly getSnapshot: () => TState;
96
+ readonly subscribe: (listener: () => void) => () => void;
97
+ }
98
+ type AnyCalendarState = CalendarPublicState<string, unknown, unknown>;
99
+ /**
100
+ * A view as the kernel knows it: a name and the strategy that ranges, navigates and projects it.
101
+ * A framework adapter adds what renders it, as React's `defineCalendarView` adds a `Renderer`.
102
+ */
103
+ interface CalendarViewDefinition<TName extends string = string, TProjection = unknown, TOptions = unknown, TEvent = unknown> {
104
+ readonly defaultOptions: TOptions;
105
+ readonly name: TName;
106
+ readonly strategy: CalendarViewStrategy<TProjection, TOptions, TEvent>;
107
+ }
108
+ type AnyCalendarViewDefinition<TEvent = any> = CalendarViewDefinition<string, any, any, TEvent>;
109
+ /** The semantic commands a view renderer may issue without knowing its calendar's types. */
110
+ interface CalendarViewActions {
111
+ /**
112
+ * Asks the policies about a proposal without saving it, as a gesture's preview does; pass it to
113
+ * the pointer layer's `check`. A plain function, so it can be passed on as a callback.
114
+ */
115
+ readonly checkEventChange: (proposal: CalendarEventProposal<EventId, ResourceId, unknown>) => CalendarPolicyResult<unknown, EventId, ResourceId> | null;
116
+ navigateNext(options?: CalendarCommandOptions): void;
117
+ navigatePrevious(options?: CalendarCommandOptions): void;
118
+ navigateToday(options?: CalendarCommandOptions): void;
119
+ /**
120
+ * Proposes a move, resize, create, or delete, such as the result of a pointer drag; the pointer
121
+ * layer passes `{ input: "pointer" }` as `detail`. A create may carry the application's record
122
+ * as `event`, as an item dropped in from outside the calendar does. A plain function, so it can
123
+ * be passed on as a callback.
124
+ */
125
+ readonly proposeEventChange: (proposal: CalendarEventProposal<EventId, ResourceId, unknown>, detail?: CalendarProposalDetail) => Promise<CalendarTransactionResult<unknown, EventId, ResourceId>>;
126
+ setAnchorDate(anchorDate: Temporal.PlainDate, options?: CalendarCommandOptions): void;
127
+ /** Moves the calendar's focus; `useRovingFocus` and `useCalendarKeyboard` call it for you. */
128
+ setFocus(focus: CalendarFocus | null, options?: CalendarCommandOptions): void;
129
+ setSelection(selection: CalendarSelection | null, options?: CalendarCommandOptions): void;
130
+ setView(view: string, options?: CalendarCommandOptions): void;
131
+ }
132
+ /** Options a root passes to its registered views, keyed by view name. */
133
+ type CalendarViewOptionsMap<TViewDef extends AnyCalendarViewDefinition> = { readonly [TName in TViewDef["name"]]?: Partial<Extract<TViewDef, {
134
+ readonly name: TName;
135
+ }>["defaultOptions"]>; };
136
+ /** The active view of a calendar with its visible range and memoized projection. */
137
+ type CalendarActiveView<TViewDef extends AnyCalendarViewDefinition> = TViewDef extends unknown ? {
138
+ readonly definition: TViewDef;
139
+ readonly environment: CalendarEnvironmentBase;
140
+ /** The events the projection was built from, pending changes included. */
141
+ readonly events: EventSnapshot<unknown, EventId, ResourceId>;
142
+ readonly instantRange: InstantInterval;
143
+ /** `loadRange` resolved to instants in the display time zone. */
144
+ readonly loadInstantRange: InstantInterval;
145
+ /** The dates the projection covers: `range`, or more for a scrolling view. */
146
+ readonly loadRange: PlainDateInterval;
147
+ readonly options: TViewDef["defaultOptions"];
148
+ readonly projection: ReturnType<TViewDef["strategy"]["project"]>;
149
+ readonly range: PlainDateInterval;
150
+ readonly view: TViewDef["name"];
151
+ } : never;
152
+ /** Applies a root's partial overrides to a view's `defaultOptions`. */
153
+ export declare function resolveViewOptions(view: AnyCalendarViewDefinition, overrides: object | undefined): unknown;
154
+ /**
155
+ * Argument parsing for the calendar's agent surface. An agent sends JSON, so dates and times
156
+ * arrive as ISO strings; each parser accepts the Temporal value too, for code that calls the
157
+ * same methods, and throws an error that says what it expected, which the agent reads.
158
+ */
159
+ type AnyEvent = NormalizedCalendarEvent<unknown, EventId, ResourceId>;
160
+ type AnyEvents = EventSnapshot<unknown, EventId, ResourceId>;
161
+ /** One visible event, as an agent's `query` lists it: its ID as a string, its title and time. */
162
+ interface CalendarAgentItem {
163
+ readonly label: string;
164
+ readonly value: string;
165
+ }
166
+ /**
167
+ * An event as an agent reads it, in JSON an agent can compute with. Times are ISO 8601: a timed
168
+ * event's with the offset of the calendar's time zone, as `"2026-03-14T09:00:00+01:00"`; an all-day
169
+ * event's as dates; a floating event's as wall-clock date-times without an offset. `end` is
170
+ * exclusive, as everywhere in the calendar.
171
+ */
172
+ interface CalendarAgentEvent {
173
+ readonly end: string;
174
+ /** The ID as the event adapter gives it, a string or a number. */
175
+ readonly id: EventId;
176
+ readonly kind: "all-day" | "floating" | "timed";
177
+ /** Set while a change to the event is still being decided or saved. */
178
+ readonly pending?: true;
179
+ /** Set when the event can't be changed. */
180
+ readonly readOnly?: true;
181
+ readonly resourceIds: readonly ResourceId[];
182
+ readonly start: string;
183
+ readonly title: string;
184
+ }
185
+ export declare function parsePlainDate(value: unknown, name: string): Temporal.PlainDate;
186
+ /** A time zone as an IANA name, checked against the platform's database. */
187
+ export declare function parseTimeZone(value: unknown): string;
188
+ /**
189
+ * An exact time: with an offset or `Z` it means that instant, as `2026-03-14T09:00Z`; without
190
+ * one it is wall-clock time in the display time zone, as `2026-03-14T09:00`.
191
+ */
192
+ export declare function parseInstant(value: unknown, name: string, environment: Pick<CalendarEnvironmentBase, "disambiguation" | "timeZone">): Temporal.Instant;
193
+ /** A wall-clock date-time, for floating events. */
194
+ export declare function parsePlainDateTime(value: unknown, name: string): Temporal.PlainDateTime;
195
+ /**
196
+ * An action's one JSON object argument, checked against the keys it takes: `true` for a required
197
+ * key, `false` for an optional one. Anything else, a second argument, an unknown key or a missing
198
+ * one, fails with the action's signature, so the agent can retry with what it expected.
199
+ */
200
+ export declare function readAgentInput<TKey extends string>(action: string, signature: string, input: unknown, keys: Readonly<Record<TKey, boolean>>, extra?: readonly unknown[], nullable?: readonly TKey[]): Readonly<Partial<Record<TKey, unknown>>>;
201
+ /** The event an agent names, by its ID as the adapter gives it or as a string. */
202
+ export declare function findEvent(events: AnyEvents, id: unknown): AnyEvent;
203
+ /** The events that overlap `range` in the calendar's time zone, all-day ones first, then by start. */
204
+ export declare function eventsInRange(events: AnyEvents, range: PlainDateInterval, environment: CalendarEnvironmentBase): readonly AnyEvent[];
205
+ /** The events the active view shows, in the order a reader meets them: all-day ones first. */
206
+ export declare function visibleEventsOf(events: AnyEvents, view: CalendarActiveView<AnyCalendarViewDefinition> | null): readonly AnyEvent[];
207
+ /** Where an event is or would be, in `listEvents`' terms. */
208
+ type CalendarAgentPlacement = Pick<CalendarAgentEvent, "end" | "kind" | "resourceIds" | "start">;
209
+ /** A placement as JSON, with its times in `timeZone`. */
210
+ export declare function describeAgentPlacement(placement: CalendarEventPlacement, timeZone: string): CalendarAgentPlacement;
211
+ /** An event as JSON, with its times in the calendar's time zone. */
212
+ export declare function describeAgentEvent(event: AnyEvent, environment: Pick<CalendarEnvironmentBase, "timeZone">): CalendarAgentEvent;
213
+ /**
214
+ * An event's default label for an agent: its title, then when it happens in ISO 8601, in the
215
+ * calendar's time zone, as `Design review · 2026-03-14T09:00 to 2026-03-14T10:00 (Europe/Berlin)`.
216
+ * Unlike a localized date, an agent can read it back exactly. An all-day event's last day is
217
+ * inclusive here, as a person reads `to`; `listEvents` gives the exclusive end.
218
+ */
219
+ export declare function agentEventLabel(event: CalendarAgentEvent, timeZone: string): string;
220
+ /** `agentEventLabel` of a normalized event, in the calendar's time zone. */
221
+ export declare function eventLabel(event: AnyEvent, environment: CalendarEnvironmentBase): string;
222
+ /** Connects the root's announcer to the live region that is mounted, if any. */
223
+ interface AnnouncerChannel {
224
+ readonly announcer: CalendarAnnouncer;
225
+ /** Speaks through `speak` with `messages` until the cleanup runs; the latest mount wins. */
226
+ readonly mount: (getMessages: () => CalendarAnnouncementMessages, speak: (text: string) => void) => () => void;
227
+ /**
228
+ * Speaks what `build` returns through the mounted live region, if any, with the context and
229
+ * messages an interaction's announcement gets; an undo's text is built this way.
230
+ */
231
+ readonly say: (build: (context: CalendarAnnouncementContext, messages: CalendarAnnouncementMessages) => string | null) => void;
232
+ }
233
+ /** `getEnvironment` and `getResources` read the root's last commit when an update arrives. */
234
+ export declare function createAnnouncerChannel(getEnvironment: () => Pick<CalendarEnvironmentBase, "locale" | "timeZone">, getResources: () => ResourceTree): AnnouncerChannel;
235
+ type CalendarSemanticActions<TView extends string = string, TSelection = CalendarSelection, TFocus = CalendarFocus, TResourceId extends ResourceId = ResourceId, TEvent = unknown, TEventId extends EventId = EventId> = CalendarActions<TView, TSelection, TFocus, TResourceId> & {
236
+ navigateNext(options?: CalendarCommandOptions): void;
237
+ navigatePrevious(options?: CalendarCommandOptions): void;
238
+ navigateToday(options?: CalendarCommandOptions): void;
239
+ /**
240
+ * Runs a change through the root's policies without showing or saving it, as a gesture's
241
+ * preview does: `rejected` with the reason `proposeEventChange` would give, or `accepted`, with
242
+ * any `change.warnings`. `null` for an unknown event, or when a policy answers asynchronously.
243
+ * Policies read `detail`, `{ input: "api" }` by default, as `proposeEventChange` gives it.
244
+ */
245
+ readonly checkEventChange: (proposal: CalendarEventProposal<TEventId, TResourceId, TEvent>, detail?: CalendarProposalDetail) => CalendarPolicyResult<TEvent, TEventId, TResourceId> | null;
246
+ /**
247
+ * Validates a change against the root's policies, shows it while `onEventChange` persists it,
248
+ * and resolves with the outcome, which `onEventChangeResult` hears first, with `detail` as
249
+ * given. Read-only events and roots without `onEventChange` reject. `detail.input` names the
250
+ * input that made the proposal, `"api"` by default. A plain function, so it can be passed on as
251
+ * a callback.
252
+ */
253
+ readonly proposeEventChange: (proposal: CalendarEventProposal<TEventId, TResourceId, TEvent>, detail?: CalendarProposalDetail) => Promise<CalendarTransactionResult<TEvent, TEventId, TResourceId>>;
254
+ };
255
+ type CalendarDiagnostic<TEvent, TEventId extends EventId> = {
256
+ readonly code: "unregistered-active-view";
257
+ readonly severity: "error";
258
+ readonly viewName: string;
259
+ } | {
260
+ readonly code: "invalid-event";
261
+ readonly issue: EventSnapshotIssue<TEvent, TEventId>;
262
+ readonly severity: "error";
263
+ } | {
264
+ readonly code: "invalid-annotation";
265
+ readonly issue: AnnotationSnapshotIssue;
266
+ readonly severity: "error";
267
+ } | {
268
+ readonly code: "invalid-availability";
269
+ readonly issue: AvailabilityIssue;
270
+ readonly severity: "error";
271
+ } | {
272
+ readonly code: "invalid-secondary-time-zone";
273
+ readonly issue: SecondaryTimeZoneIssue;
274
+ readonly severity: "error";
275
+ };
276
+ interface CalendarPartIds {
277
+ readonly frame: string;
278
+ readonly title: string;
279
+ readonly viewport: string;
280
+ }
281
+ /** The ids a root's chrome parts point at each other with. */
282
+ export declare function createCalendarPartIds(instanceId: string): CalendarPartIds;
283
+ /** What the active view shows and which events it needs, as `onVisibleRangeChange` reports it. */
284
+ interface CalendarVisibleRange<TView extends string = string> {
285
+ /** `range` resolved to instants in the display time zone. */
286
+ readonly instantRange: InstantInterval;
287
+ /** `loadRange` resolved to instants in the display time zone. */
288
+ readonly loadInstantRange: InstantInterval;
289
+ /**
290
+ * The dates to have events for: `range`, plus the pages a scrolling view keeps ready on each
291
+ * side, so a swipe shows their events at once.
292
+ */
293
+ readonly loadRange: PlainDateInterval;
294
+ /** The visible dates. */
295
+ readonly range: PlainDateInterval;
296
+ readonly view: TView;
297
+ }
298
+ /** The clock a root reads when it has neither `now` nor `clock`. */
299
+ export declare const systemClock: CalendarClock;
300
+ /** How often a root samples its clock for `today`. */
301
+ export declare const TODAY_SAMPLE_INTERVAL_MS = 6e4;
302
+ interface CalendarClockTicker {
303
+ /** The last sample, taken now if there is none yet. */
304
+ readonly getSnapshot: () => Temporal.Instant;
305
+ /**
306
+ * Samples at once and then every interval, calling `onChange` when the instant moved; returns
307
+ * the cleanup that stops the timer.
308
+ */
309
+ readonly subscribe: (onChange: () => void) => () => void;
310
+ }
311
+ /** Samples `clock` every `intervalMs` while subscribed. */
312
+ export declare function createClockTicker(clock: CalendarClock, intervalMs: number): CalendarClockTicker;
313
+ /** The clock a source samples: its own, or the system's. */
314
+ export declare function clockOf(source: CalendarNowSource | undefined): CalendarClock;
315
+ type AnyDraft = CalendarDraft<EventId, ResourceId>;
316
+ /** The pointer's draft, which the pointer layer reports to the root while a drag previews a change. */
317
+ interface DraftStore extends CalendarStateSource<AnyDraft | null> {
318
+ readonly set: (draft: AnyDraft | null) => void;
319
+ }
320
+ export declare function createDraftStore(): DraftStore;
321
+ export declare function sameElements<T>(left: readonly T[], right: readonly T[]): boolean;
322
+ /** Compares own enumerable properties with `Object.is`; non-objects compare with `Object.is`. */
323
+ export declare function shallowEqual<T>(left: T, right: T): boolean;
324
+ export declare function samePlainDate(left: Temporal.PlainDate | null | undefined, right: Temporal.PlainDate | null | undefined): boolean;
325
+ export declare function sameInstant(left: Temporal.Instant | undefined, right: Temporal.Instant | undefined): boolean;
326
+ export declare function sameRange(left: PlainDateInterval | undefined, right: PlainDateInterval | undefined): boolean;
327
+ export declare function sameWeekRules(left: CalendarWeekRules, right: CalendarWeekRules): boolean;
328
+ /**
329
+ * Compares working hours by value, so an inline `availability` keeps its shading cached. Invalid
330
+ * entries never throw here; the snapshot reports them.
331
+ */
332
+ export declare function sameAvailability(left: CalendarAvailability | undefined, right: CalendarAvailability | undefined): boolean;
333
+ /**
334
+ * Compares secondary time zones by value, so an inline list keeps the environment as it is. A
335
+ * single zone passed where a list belongs, which the root reports, compares by value too.
336
+ */
337
+ export declare function sameSecondaryTimeZones(left: readonly (CalendarSecondaryTimeZone | string)[], right: readonly (CalendarSecondaryTimeZone | string)[]): boolean;
338
+ /** A keyboard session with what it needs to restart, restore focus, and announce itself. */
339
+ interface KeyboardGrab {
340
+ /** The cell the grabbed event sits in, or where a create started. */
341
+ readonly cell: CalendarCellFocus;
342
+ /** What the root's policies say about the session's proposal. */
343
+ readonly check: CalendarInteractionCheck;
344
+ /** The event as it was when grabbed; `null` when creating. */
345
+ readonly event: NormalizedCalendarEvent<unknown, EventId, ResourceId> | null;
346
+ /** Focus before the grab, restored on cancel. */
347
+ readonly origin: CalendarFocus;
348
+ readonly session: CalendarKeyboardSession;
349
+ }
350
+ /** The root's keyboard session. Its preview patches the grabbed event into the projection. */
351
+ interface KeyboardSessionStore {
352
+ readonly get: () => KeyboardGrab | null;
353
+ /** The grabbed event's proposed placement, for `applyEventOverlay`. */
354
+ readonly getPreview: () => CalendarPendingPlacements<EventId, ResourceId>;
355
+ /** The gesture in progress, for `useCalendarInteraction`. */
356
+ readonly grabs: CalendarStateSource<KeyboardGrab | null>;
357
+ readonly set: (grab: KeyboardGrab | null) => void;
358
+ readonly subscribe: (listener: () => void) => () => void;
359
+ }
360
+ export declare function createKeyboardSessionStore(): KeyboardSessionStore;
361
+ interface CalendarStoreBinding<TView extends string, TSelection, TFocus, TResourceId extends ResourceId> {
362
+ readonly controlled: CalendarControlledState<TView, TSelection, TFocus, TResourceId>;
363
+ readonly handlers: CalendarStateChangeHandlers<TView, TSelection, TFocus, TResourceId>;
364
+ }
365
+ /** One root's view of a shared store: its controlled slices, handlers, and pending requests. */
366
+ interface CalendarRootStoreBinding<TView extends string, TSelection, TFocus, TResourceId extends ResourceId> {
367
+ /** Commands that honor this root's controlled slices and handlers. */
368
+ readonly actions: CalendarActions<TView, TSelection, TFocus, TResourceId>;
369
+ /** Routes `store.actions` through this root until the cleanup runs; the latest mounted root wins. */
370
+ readonly attach: () => () => void;
371
+ /** Publishes the root's committed props, settling requests for slices whose owner changed them. */
372
+ readonly commit: (binding: CalendarStoreBinding<TView, TSelection, TFocus, TResourceId>) => void;
373
+ /**
374
+ * The latest requested state. A controlled change requested since the last commit is visible
375
+ * here before its owner commits it, so consecutive commands in one event handler compose.
376
+ */
377
+ readonly read: () => CalendarPublicState<TView, TSelection, TFocus, TResourceId>;
378
+ /**
379
+ * Calls `listener` with every command, even one that asks for the value a slice already has,
380
+ * as Today does when the view only looks as if it had moved. Returns the unsubscribe function.
381
+ */
382
+ readonly subscribeRequests: (listener: CalendarRequestListener) => () => void;
383
+ }
384
+ /** A command a root received: the slice it asks to change, and the value it asks for. */
385
+ type CalendarRequestListener = (slice: CalendarStateSlice, value: unknown) => void;
386
+ interface CalendarStoreInternals<TView extends string, TSelection, TFocus, TResourceId extends ResourceId> {
387
+ readonly bind: (binding: CalendarStoreBinding<TView, TSelection, TFocus, TResourceId>) => CalendarRootStoreBinding<TView, TSelection, TFocus, TResourceId>;
388
+ }
389
+ /** The six slices, in a fixed order. */
390
+ export declare const calendarStateSlices: readonly CalendarStateSlice[];
391
+ /** Dates by value and resource lists by element; everything else by identity. */
392
+ export declare function sameSliceValue(slice: CalendarStateSlice, previous: unknown, next: unknown): boolean;
393
+ /** Overlays every defined controlled slice on the uncontrolled state. */
394
+ export declare function mergeControlledState<TState extends CalendarPublicState<string, unknown, unknown>>(state: TState, controlled: Partial<TState> | undefined): TState;
395
+ export declare function getCalendarStoreInternals<TView extends string, TSelection, TFocus, TResourceId extends ResourceId>(store: CalendarStore<TView, TSelection, TFocus, TResourceId>): CalendarStoreInternals<TView, TSelection, TFocus, TResourceId>;
396
+ export declare function createCalendarStore<TView extends string = string, TSelection = CalendarSelection, TFocus = CalendarFocus, TResourceId extends ResourceId = ResourceId>(options: CalendarStoreOptions<TView, TSelection, TFocus, TResourceId>): CalendarStore<TView, TSelection, TFocus, TResourceId>;
397
+ type AnyPendingChanges = CalendarPendingChanges<unknown, EventId, ResourceId>;
398
+ /**
399
+ * A root's interaction plumbing, which views and their gestures drive whatever calendar they
400
+ * render in; the nearest root wins.
401
+ */
402
+ interface CalendarInteractionRuntime {
403
+ readonly actions: CalendarSemanticActions<any, any, any, any, any, any>;
404
+ readonly announcements: AnnouncerChannel;
405
+ /** The root's pending changes, which an event history waits out before it undoes. */
406
+ readonly changes: CalendarStateSource<AnyPendingChanges>;
407
+ /** The root has no `onEventChange`, so it rejects every change and views start no gestures. */
408
+ readonly isReadOnly: boolean;
409
+ readonly keyboard: KeyboardSessionStore;
410
+ /** The pointer's draft while a drag previews a change; the keyboard's is in `keyboard`. */
411
+ readonly pointerDraft: DraftStore;
412
+ /**
413
+ * The dates the view on screen shows for `anchor`, as of the last commit, so a change of view
414
+ * still waiting for its owner doesn't count; `null` without one.
415
+ */
416
+ readonly rangeOf: (anchor: Temporal.PlainDate) => PlainDateInterval | null;
417
+ /**
418
+ * The latest state, controlled slices and requests not yet committed included; read it in
419
+ * callbacks that run after the render that created them.
420
+ */
421
+ readonly read: () => AnyCalendarState;
422
+ /** Subscribes to every command the root receives, even one that changes nothing. */
423
+ readonly requests: (listener: CalendarRequestListener) => () => void;
424
+ /** For subscribing; its identity changes with controlled values. */
425
+ readonly source: CalendarStateSource<AnyCalendarState>;
426
+ }
427
+ /**
428
+ * Memo cells: what `useMemo` and a stable-value hook do in a component, as plain closures a
429
+ * runtime owns, so a framework can derive during render (or in a signal's memo) and get the same
430
+ * objects back while their inputs hold.
431
+ */
432
+ /** A value that keeps its first identity while `isEqual` says each next one is the same. */
433
+ export declare function createStableCell<T>(isEqual: (previous: T, next: T) => boolean): (next: T) => T;
434
+ /** A value computed again only when one of its dependencies changes identity. */
435
+ export declare function createMemoCell<T>(): (deps: readonly unknown[], compute: () => T) => T;
436
+ /** What a runtime is made from: the factory's adapter, its policy for invalid events, its views. */
437
+ interface CalendarRuntimeConfig<TEvent, TViewDef extends AnyCalendarViewDefinition, TEventId extends EventId, TResourceId extends ResourceId> {
438
+ readonly eventAdapter: EventAdapter<TEvent, TEventId, TResourceId>;
439
+ readonly invalidEventPolicy?: InvalidCalendarEventPolicy;
440
+ readonly views: readonly TViewDef[];
441
+ }
442
+ /** The store a root reads its state from, bound to its controlled slices. */
443
+ interface CalendarRuntimeConnection<TView extends string, TSelection, TFocus, TResourceId extends ResourceId> {
444
+ readonly binding: CalendarRootStoreBinding<TView, TSelection, TFocus, TResourceId>;
445
+ /** The controlled slices, the same object while their values hold. */
446
+ readonly controlled: CalendarControlledState<TView, TSelection, TFocus, TResourceId>;
447
+ /** The store's state with the controlled slices laid over it; subscribe and read state here. */
448
+ readonly source: CalendarStateSource<CalendarPublicState<TView, TSelection, TFocus, TResourceId>>;
449
+ readonly store: CalendarStore<TView, TSelection, TFocus, TResourceId>;
450
+ }
451
+ interface CalendarRuntimeConnectOptions<TView extends string, TSelection, TFocus, TResourceId extends ResourceId> {
452
+ readonly controlled: CalendarControlledState<TView, TSelection, TFocus, TResourceId>;
453
+ /** The defaults of the store the root owns, read once, when it has no `store` of its own. */
454
+ readonly defaults: () => CalendarStoreOptions<TView, TSelection, TFocus, TResourceId>;
455
+ readonly store?: CalendarRootStore<TView, TSelection, TFocus, TResourceId>;
456
+ }
457
+ /** What changes at runtime beside the root's state: pending changes and a keyboard preview. */
458
+ interface CalendarRuntimeOverlay<TEventId extends EventId, TResourceId extends ResourceId> {
459
+ readonly pending: CalendarPendingPlacements<TEventId, TResourceId>;
460
+ readonly preview: CalendarPendingPlacements<TEventId, TResourceId>;
461
+ }
462
+ /** Everything a root derives its model from: its props, and what the adapter subscribed to. */
463
+ interface CalendarRuntimeInputs<TEvent, TResource, TViewDef extends AnyCalendarViewDefinition, TSelection, TFocus, TEventId extends EventId, TResourceId extends ResourceId> {
464
+ /** Whether an agent may delete events; without it the engine refuses an agent's delete. */
465
+ readonly allowAgentDelete?: boolean;
466
+ readonly annotationSources?: readonly CalendarAnnotationSource[];
467
+ readonly annotations?: readonly CalendarAnnotation<unknown, TResourceId>[];
468
+ readonly availability?: CalendarAvailability;
469
+ readonly clock?: CalendarClock;
470
+ readonly connection: CalendarRuntimeConnection<TViewDef["name"], TSelection, TFocus, TResourceId>;
471
+ readonly direction?: CalendarEnvironment["direction"];
472
+ readonly disambiguation?: CalendarEnvironment["disambiguation"];
473
+ /** The application's events as an array; an adapter reads an event source's current one. */
474
+ readonly events: readonly TEvent[];
475
+ readonly handlers: CalendarStateChangeHandlers<TViewDef["name"], TSelection, TFocus, TResourceId>;
476
+ /** The clock's latest sample, for `today`; `null` while server rendering and hydrating. */
477
+ readonly instant: Temporal.Instant | null;
478
+ readonly locale: Intl.Locale | string;
479
+ readonly now?: Temporal.Instant;
480
+ readonly onDiagnosticsChange?: (diagnostics: readonly CalendarDiagnostic<TEvent, TEventId>[]) => void;
481
+ readonly onEventChange?: CalendarEventChangeHandler<TEvent, TEventId, TResourceId>;
482
+ readonly onEventChangeResult?: (result: CalendarTransactionResult<TEvent, TEventId, TResourceId>, detail: CalendarProposalDetail) => void;
483
+ readonly onVisibleRangeChange?: (range: CalendarVisibleRange<TViewDef["name"]>) => void;
484
+ /** `runtime.overlay`'s snapshot, read where the adapter subscribes to it. */
485
+ readonly overlay: CalendarRuntimeOverlay<TEventId, TResourceId>;
486
+ readonly policies?: readonly CalendarPolicy<TEvent, TEventId, TResourceId>[];
487
+ readonly resources?: readonly TResource[];
488
+ readonly secondaryTimeZones?: readonly (CalendarSecondaryTimeZone | string)[];
489
+ /** `connection.source`'s snapshot, read where the adapter subscribes to it. */
490
+ readonly state: CalendarPublicState<TViewDef["name"], TSelection, TFocus, TResourceId>;
491
+ readonly viewOptions?: CalendarViewOptionsMap<TViewDef>;
492
+ readonly weekRules: CalendarWeekRules;
493
+ }
494
+ /** The root's annotations and the sources it shows. */
495
+ interface CalendarAnnotations {
496
+ readonly snapshot: AnnotationSnapshot;
497
+ readonly sources: readonly CalendarAnnotationSource[];
498
+ }
499
+ /** Everything a root shows, derived from its inputs; each part keeps its identity while it holds. */
500
+ interface CalendarRuntimeModel<TEvent, TResource, TViewDef extends AnyCalendarViewDefinition, TSelection, TFocus, TEventId extends EventId, TResourceId extends ResourceId> {
501
+ readonly actions: CalendarSemanticActions<TViewDef["name"], TSelection, TFocus, TResourceId, TEvent, TEventId>;
502
+ /** The active view's definition; `undefined` while the active view is unregistered. */
503
+ readonly activeDefinition: TViewDef | undefined;
504
+ readonly activeView: CalendarActiveView<TViewDef> | null;
505
+ readonly annotations: CalendarAnnotations;
506
+ readonly availability: AvailabilitySnapshot;
507
+ readonly diagnostics: readonly CalendarDiagnostic<TEvent, TEventId>[];
508
+ readonly environment: CalendarEnvironment;
509
+ /** The application's events, without pending changes. */
510
+ readonly eventSnapshot: EventSnapshot<TEvent, TEventId, TResourceId>;
511
+ readonly interaction: CalendarInteractionRuntime;
512
+ /** The root has no `onEventChange`, so it rejects every change. */
513
+ readonly isReadOnly: boolean;
514
+ readonly resourceTree: ResourceTree;
515
+ readonly resources: readonly TResource[];
516
+ readonly state: CalendarPublicState<TViewDef["name"], TSelection, TFocus, TResourceId>;
517
+ /** The state source views subscribe to; its identity changes with controlled values. */
518
+ readonly source: CalendarStateSource<CalendarPublicState<TViewDef["name"], TSelection, TFocus, TResourceId>>;
519
+ readonly today: Temporal.PlainDate | null;
520
+ /** The environment views get: `environment` without the clock. */
521
+ readonly viewEnvironment: CalendarEnvironmentBase;
522
+ /** The events views show: the application's, with pending changes and the keyboard's preview. */
523
+ readonly visibleEvents: EventSnapshot<TEvent, TEventId, TResourceId>;
524
+ readonly visibleRange: CalendarVisibleRange<TViewDef["name"]> | null;
525
+ }
526
+ /**
527
+ * One calendar root's behavior without a framework. An adapter creates it once per root, feeds it
528
+ * the latest inputs, and calls its effects at the moments their names give:
529
+ *
530
+ * 1. `connect` and `derive` while rendering; both are pure and return memoized values.
531
+ * 2. `commit(model, inputs)` and `connection.binding.attach()` once a render commits, before
532
+ * anything can run a command (React: an insertion effect).
533
+ * 3. `reconcile(model.eventSnapshot)` before the commit paints (React: a layout effect).
534
+ * 4. `reportDiagnostics(model.diagnostics)` and `reportVisibleRange(model.visibleRange)` after it
535
+ * paints, each when its value changes.
536
+ */
537
+ interface CalendarRuntime<TEvent, TResource, TViewDef extends AnyCalendarViewDefinition, TSelection, TFocus, TEventId extends EventId, TResourceId extends ResourceId> {
538
+ readonly announcements: AnnouncerChannel;
539
+ /** Publishes a committed render: its handlers and controlled slices, its callbacks and model. */
540
+ readonly commit: (model: CalendarRuntimeModel<TEvent, TResource, TViewDef, TSelection, TFocus, TEventId, TResourceId>, inputs: CalendarRuntimeInputs<TEvent, TResource, TViewDef, TSelection, TFocus, TEventId, TResourceId>) => void;
541
+ /** The model of the last committed render, or the first derived one before any commits. */
542
+ readonly committed: () => CalendarRuntimeModel<TEvent, TResource, TViewDef, TSelection, TFocus, TEventId, TResourceId> | undefined;
543
+ /** The store the root reads, bound to its controlled slices; the same object while they hold. */
544
+ readonly connect: (options: CalendarRuntimeConnectOptions<TViewDef["name"], TSelection, TFocus, TResourceId>) => CalendarRuntimeConnection<TViewDef["name"], TSelection, TFocus, TResourceId>;
545
+ /** Derives the root's model, synchronously; parts that hold keep their identity. */
546
+ readonly derive: (inputs: CalendarRuntimeInputs<TEvent, TResource, TViewDef, TSelection, TFocus, TEventId, TResourceId>) => CalendarRuntimeModel<TEvent, TResource, TViewDef, TSelection, TFocus, TEventId, TResourceId>;
547
+ readonly keyboard: KeyboardSessionStore;
548
+ /** Pending changes and the keyboard's preview; the snapshot keeps its identity until either changes. */
549
+ readonly overlay: CalendarStateSource<CalendarRuntimeOverlay<TEventId, TResourceId>>;
550
+ /** The root's pending changes, for an adapter's `useCalendarPendingChanges`. */
551
+ readonly pendingChanges: CalendarStateSource<CalendarPendingChanges<TEvent, TEventId, TResourceId>>;
552
+ readonly pointerDraft: DraftStore;
553
+ /**
554
+ * The model's `proposeEventChange` from the last commit, returning the outcome itself when it
555
+ * is known at once: a policy's synchronous refusal, a synchronous save, or a proposal that can't
556
+ * apply. Otherwise the pending proposal, whose `result` never rejects. The policies run once and
557
+ * `onEventChangeResult` hears every proposal once, when it settles. An agent's step uses it: the
558
+ * bridge reports a returned promise only as pending, and never sees how it ends.
559
+ */
560
+ readonly proposeNow: (proposal: CalendarEventProposal<TEventId, TResourceId, TEvent>, detail?: CalendarProposalDetail) => CalendarProposalOutcome<TEvent, TEventId, TResourceId>;
561
+ /**
562
+ * The state the latest commands asked for, with the dates its view covers then, before a
563
+ * framework renders it: what an agent reads back in the step after a command. `undefined` before
564
+ * the first derive; `range` is `null` while the view is unregistered.
565
+ */
566
+ readonly latest: () => {
567
+ readonly range: PlainDateInterval | null;
568
+ readonly state: CalendarPublicState<TViewDef["name"], TSelection, TFocus, TResourceId>;
569
+ } | undefined;
570
+ /** New events confirm resolved changes; call it before the commit that shows them paints. */
571
+ readonly reconcile: (eventSnapshot: EventSnapshot<TEvent, TEventId, TResourceId>) => void;
572
+ /** Calls the committed `onDiagnosticsChange` with `diagnostics`. */
573
+ readonly reportDiagnostics: (diagnostics: readonly CalendarDiagnostic<TEvent, TEventId>[]) => void;
574
+ /**
575
+ * Calls the committed `onVisibleRangeChange` once per visible range: calling it again for the
576
+ * same range, as an effect that runs twice does, reports nothing.
577
+ */
578
+ readonly reportVisibleRange: (visibleRange: CalendarVisibleRange<TViewDef["name"]> | null) => void;
579
+ readonly transactions: EventTransactions<TEvent, TEventId, TResourceId>;
580
+ readonly views: readonly TViewDef[];
581
+ readonly viewsByName: ReadonlyMap<string, TViewDef>;
582
+ }
583
+ /**
584
+ * The store defaults a root's props give, for `connect`'s `defaults`: a default wins over a
585
+ * controlled value, and the first registered view stands in for a missing one.
586
+ */
587
+ export declare function resolveCalendarStoreDefaults<TView extends string, TSelection, TFocus, TResourceId extends ResourceId>(props: {
588
+ readonly anchorDate?: Temporal.PlainDate;
589
+ readonly defaultAnchorDate?: Temporal.PlainDate;
590
+ readonly defaultExpandedResourceIds?: readonly TResourceId[];
591
+ readonly defaultFocus?: TFocus | null;
592
+ readonly defaultSelection?: TSelection | null;
593
+ readonly defaultTimeZone?: string;
594
+ readonly defaultView?: TView;
595
+ readonly timeZone?: string;
596
+ readonly view?: TView;
597
+ }, views: readonly {
598
+ readonly name: string;
599
+ }[]): CalendarStoreOptions<TView, TSelection, TFocus, TResourceId>;
600
+ export declare function createCalendarRuntime<TEvent, TResource = unknown, TViewDef extends AnyCalendarViewDefinition = AnyCalendarViewDefinition, TSelection = CalendarSelection, TFocus = CalendarFocus, TEventId extends EventId = EventId, TResourceId extends ResourceId = ResourceId>(config: CalendarRuntimeConfig<TEvent, TViewDef, TEventId, TResourceId>): CalendarRuntime<TEvent, TResource, TViewDef, TSelection, TFocus, TEventId, TResourceId>;
601
+ type AnyRuntime = CalendarRuntime<any, any, any, any, any, any, any>;
602
+ /**
603
+ * A calendar instance's options: the root's runtime, and its six slices as the adapter rendered
604
+ * them, the application's controlled values laid over the calendar store's. The instance holds no
605
+ * state of its own: the store and the application own the slices, and the instance mirrors what
606
+ * the adapter passes in the render that computed it.
607
+ */
608
+ type CalendarPrimitiveOptions<TView extends string = string, TSelection = CalendarSelection, TFocus = CalendarFocus, TResourceId extends ResourceId = ResourceId> = CalendarPublicState<TView, TSelection, TFocus, TResourceId> & {
609
+ /**
610
+ * Lets an agent delete events. Off by default, since a delete needs a person: an application
611
+ * that turns it on asks one in its bridge's `allow` for each `deleteEvent` step. While it is
612
+ * off, `deleteEvent` isn't among the calendar's actions.
613
+ */
614
+ readonly allowAgentDelete?: boolean;
615
+ /**
616
+ * Names an event for an agent, in the calendar's items and in `query`. The title with when it
617
+ * happens in ISO 8601 by default, which an agent can read back exactly.
618
+ */
619
+ readonly formatAgentEventLabel?: (event: CalendarAgentEvent) => string;
620
+ readonly runtime: AnyRuntime;
621
+ };
622
+ /** A range of dates an agent asks for; either end defaults to the visible range's. */
623
+ interface CalendarAgentRange {
624
+ /** An ISO date, exclusive. */
625
+ readonly end?: string;
626
+ /** An ISO date. */
627
+ readonly start?: string;
628
+ }
629
+ /** The event an action acts on, by the ID `listEvents` gives. */
630
+ interface CalendarAgentEventRef {
631
+ readonly eventId: EventId;
632
+ }
633
+ /** What an agent says about an event beside its placement; it reaches the application unvalidated. */
634
+ interface CalendarAgentEventFields {
635
+ /**
636
+ * Anything else the application understands, as JSON, such as a location or a recurrence edit's
637
+ * scope. It reaches policies and `onEventChange` as the proposal detail's `fields`.
638
+ */
639
+ readonly fields?: Readonly<Record<string, unknown>>;
640
+ /** The event's title, which reaches the application as `fields.title`. */
641
+ readonly title?: string;
642
+ }
643
+ /** A new event: ISO dates for an all-day event, ISO date-times for a timed one. */
644
+ interface CalendarAgentCreateInput extends CalendarAgentEventFields {
645
+ readonly end: string;
646
+ readonly resourceIds?: readonly ResourceId[];
647
+ readonly start: string;
648
+ }
649
+ /** An event's new start, keeping its length unless `end` is given, and its new resources. */
650
+ interface CalendarAgentMoveInput extends CalendarAgentEventRef {
651
+ readonly end?: string;
652
+ readonly resourceIds?: readonly ResourceId[];
653
+ readonly start: string;
654
+ }
655
+ /** An event's new start or new end, one of the two. */
656
+ interface CalendarAgentResizeInput extends CalendarAgentEventRef {
657
+ readonly end?: string;
658
+ readonly start?: string;
659
+ }
660
+ /** Changes to an event: its fields, its placement, or both, as one `"update"`. */
661
+ interface CalendarAgentUpdateInput extends CalendarAgentEventRef, CalendarAgentEventFields {
662
+ readonly end?: string;
663
+ readonly resourceIds?: readonly ResourceId[];
664
+ readonly start?: string;
665
+ }
666
+ /**
667
+ * Where a change an agent proposed is: still `validating` or `saving`, `saved`, or `rejected` with
668
+ * its reason. A step returns it at once, and `getChange` reads it again later by `changeId`.
669
+ */
670
+ interface CalendarAgentChange {
671
+ readonly cause: CalendarChangeCause;
672
+ readonly changeId: string;
673
+ /** `null` for a new event, whose ID the application gives it when it saves it. */
674
+ readonly eventId: EventId | null;
675
+ /** Where the event would land, in `listEvents`' terms; `null` for a delete. */
676
+ readonly proposed: CalendarAgentPlacement | null;
677
+ readonly reason?: string;
678
+ readonly status: "rejected" | "saved" | "saving" | "validating";
679
+ }
680
+ /** The calendar as `describeCalendar` returns it: what an agent needs before it acts. */
681
+ interface CalendarAgentDescription {
682
+ /** The actions the calendar takes now, each with the one JSON object it takes. */
683
+ readonly actions: Readonly<Record<string, string>>;
684
+ readonly anchorDate: string;
685
+ /** Whether `deleteEvent` is among the actions. */
686
+ readonly canDelete: boolean;
687
+ /** How the calendar's dates and times read, for an agent that has no other description. */
688
+ readonly conventions: string;
689
+ readonly locale: string;
690
+ /** The current time in the calendar's time zone, ISO 8601 with its offset. */
691
+ readonly now: string;
692
+ /** Changes still being decided or saved, a person's and an agent's. */
693
+ readonly pendingChanges: readonly CalendarAgentChange[];
694
+ /** The calendar takes no event changes: it has no `onEventChange`. */
695
+ readonly readOnly: boolean;
696
+ readonly resources: readonly {
697
+ readonly id: ResourceId;
698
+ readonly parentId: ResourceId | null;
699
+ readonly title: string;
700
+ }[];
701
+ readonly selectedEventId: EventId | null;
702
+ readonly timeZone: string;
703
+ readonly today: string;
704
+ readonly view: string;
705
+ readonly views: readonly string[];
706
+ /** The visible dates, `end` exclusive; `null` while the view is unregistered. */
707
+ readonly visibleRange: {
708
+ readonly end: string;
709
+ readonly start: string;
710
+ } | null;
711
+ }
712
+ /**
713
+ * The actions an AI agent calls through ui-sdk's agent bridge. Each takes nothing or one JSON
714
+ * object and checks it, failing with what it expected. The reads return JSON; a change returns
715
+ * where it is at once, as the bridge reports a returned promise only as pending. The event
716
+ * changes are absent while the root is read-only, and `deleteEvent` unless the root allows it.
717
+ */
718
+ interface CalendarAgentApi<TView extends string = string> {
719
+ /** Proposes a new event, as the agent. */
720
+ readonly createEvent?: (input: CalendarAgentCreateInput) => CalendarAgentChange;
721
+ /** Proposes deleting an event, as the agent; only where the root sets `allowAgentDelete`. */
722
+ readonly deleteEvent?: (input: CalendarAgentEventRef) => CalendarAgentChange;
723
+ /** Today, the time zone, the views, the visible range, what the calendar takes now. */
724
+ describeCalendar(): CalendarAgentDescription;
725
+ /** Where a change the agent proposed is now, by the `changeId` its step returned. */
726
+ getChange(input: {
727
+ readonly changeId: string;
728
+ }): CalendarAgentChange;
729
+ /** Shows the dates around `date`, an ISO date such as `"2026-03-14"`. */
730
+ goToDate(input: {
731
+ readonly date: string;
732
+ }): void;
733
+ /** The events in a range of dates, the visible range by default, as JSON. */
734
+ listEvents(input?: CalendarAgentRange): readonly CalendarAgentEvent[];
735
+ /** Proposes moving an event, as the agent. */
736
+ readonly moveEvent?: (input: CalendarAgentMoveInput) => CalendarAgentChange;
737
+ navigateNext(): void;
738
+ navigatePrevious(): void;
739
+ navigateToday(): void;
740
+ /** Proposes a new start or end for an event, as the agent. */
741
+ readonly resizeEvent?: (input: CalendarAgentResizeInput) => CalendarAgentChange;
742
+ /** Selects an event, or clears the selection with `null`. */
743
+ selectEvent(input: {
744
+ readonly eventId: EventId | null;
745
+ }): void;
746
+ /** Shows the dates in `timeZone`, an IANA name such as `"Europe/Berlin"`. */
747
+ setTimeZone(input: {
748
+ readonly timeZone: string;
749
+ }): void;
750
+ /** Switches to a registered view; any other name fails with the list of views. */
751
+ setView(input: {
752
+ readonly view: TView;
753
+ }): void;
754
+ /** Proposes changes to an event's fields, its placement or both, as the agent. */
755
+ readonly updateEvent?: (input: CalendarAgentUpdateInput) => CalendarAgentChange;
756
+ }
757
+ /**
758
+ * What the calendar's parts and its agent call. The agent's actions attribute themselves to the
759
+ * agent; the parts' commands pass on the event and reason of the press that ran them.
760
+ */
761
+ interface CalendarPrimitiveApi<TView extends string = string> extends CalendarAgentApi<TView> {
762
+ /** A previous, next or today trigger's command. */
763
+ showNext(options?: CalendarCommandOptions): void;
764
+ showPrevious(options?: CalendarCommandOptions): void;
765
+ showToday(options?: CalendarCommandOptions): void;
766
+ /**
767
+ * Switches to the registered view named `view`, as a view switcher does when its value changes;
768
+ * any other value, as a stale option's, changes nothing. Returns whether it asked for the view.
769
+ */
770
+ selectView(view: string, options?: CalendarCommandOptions): boolean;
771
+ /** The names of the registered views. */
772
+ viewNames(): readonly TView[];
773
+ /** The events the active view shows, as `{ value: id, label }`, the agent's items. */
774
+ visibleEvents(): readonly CalendarAgentItem[];
775
+ }
776
+ /** The calendar's structural parts, each a slot of its primitive. */
777
+ type CalendarSlotName = "next-trigger" | "previous-trigger" | "root" | "title" | "today-trigger" | "toolbar" | "view-switcher" | "viewport";
778
+ type CalendarSlots<TView extends string, TSelection, TFocus, TResourceId extends ResourceId> = Record<CalendarSlotName, SlotDefinition<CalendarPublicState<TView, TSelection, TFocus, TResourceId>, CalendarPrimitiveApi<TView>, object>>;
779
+ /** An instance of the calendar primitive, as an adapter creates and drives it. */
780
+ interface CalendarPrimitiveInstance<TView extends string = string, TSelection = CalendarSelection, TFocus = CalendarFocus, TResourceId extends ResourceId = ResourceId> extends PrimitiveInstance {
781
+ readonly api: CalendarPrimitiveApi<TView>;
782
+ readonly get: () => CalendarPublicState<TView, TSelection, TFocus, TResourceId>;
783
+ readonly types: {
784
+ readonly api: CalendarPrimitiveApi<TView>;
785
+ readonly options: CalendarPrimitiveOptions<TView, TSelection, TFocus, TResourceId>;
786
+ readonly slots: CalendarSlots<TView, TSelection, TFocus, TResourceId>;
787
+ readonly state: CalendarPublicState<TView, TSelection, TFocus, TResourceId>;
788
+ };
789
+ }
790
+ /**
791
+ * A calendar's ui-sdk primitive, as `createCalendarPrimitive` returns it: what a renderer's
792
+ * `usePrimitive` and `usePart`, or a test's `mount`, take. Declared here rather than inferred, so
793
+ * the calendar's types don't print ui-sdk's internals.
794
+ */
795
+ type CalendarPrimitive<TView extends string = string, TSelection = CalendarSelection, TFocus = CalendarFocus, TResourceId extends ResourceId = ResourceId> = ((initialOptions: CalendarPrimitiveOptions<TView, TSelection, TFocus, TResourceId> & {
796
+ readonly id: string;
797
+ }) => CalendarPrimitiveInstance<TView, TSelection, TFocus, TResourceId>) & {
798
+ readonly options: Record<string, PropSpec> | undefined;
799
+ readonly slots: CalendarSlots<TView, TSelection, TFocus, TResourceId>;
800
+ };
801
+ /** What a calendar primitive is made from. */
802
+ interface CalendarPrimitiveConfig<TViewDef extends AnyCalendarViewDefinition> {
803
+ readonly views: readonly TViewDef[];
804
+ }
805
+ /** The methods an agent may call, with JSON arguments. */
806
+ export declare const calendarAgentActions: readonly (keyof CalendarAgentApi)[];
807
+ /**
808
+ * Defines a calendar's ui-sdk primitive: the six state slices as always-controlled keys, the
809
+ * semantic commands as its api, its chrome as slots, and what an AI agent may see and do. The
810
+ * slices live in the calendar store and the application's props; the instance is a projection of
811
+ * them for parts and agents, and every change goes through the root's store, which tells the
812
+ * application's handlers.
813
+ */
814
+ export declare function createCalendarPrimitive<TViewDef extends AnyCalendarViewDefinition, TSelection = CalendarSelection, TFocus = CalendarFocus, TResourceId extends ResourceId = ResourceId>(config: CalendarPrimitiveConfig<TViewDef>): CalendarPrimitive<TViewDef["name"], TSelection, TFocus, TResourceId>;
815
+ /** Reports an application callback's error without failing what it was told about. */
816
+ export declare function reportCallbackError(error: unknown): void;
817
+ export type { AnnouncerChannel, AnyCalendarState, AnyCalendarViewDefinition, AnyPendingChanges, CalendarActions, CalendarActiveView, CalendarAgentApi, CalendarAgentChange, CalendarAgentCreateInput, CalendarAgentDescription, CalendarAgentEvent, CalendarAgentEventFields, CalendarAgentEventRef, CalendarAgentItem, CalendarAgentMoveInput, CalendarAgentPlacement, CalendarAgentRange, CalendarAgentResizeInput, CalendarAgentUpdateInput, CalendarAnnotations, CalendarChangeReason, CalendarChangeSource, CalendarClockTicker, CalendarCommandOptions, CalendarControlledState, CalendarDiagnostic, CalendarInteractionRuntime, CalendarPartIds, CalendarPrimitive, CalendarPrimitiveApi, CalendarPrimitiveConfig, CalendarPrimitiveInstance, CalendarPrimitiveOptions, CalendarPublicState, CalendarRequestListener, CalendarRootStore, CalendarRootStoreBinding, CalendarRuntime, CalendarRuntimeConfig, CalendarRuntimeConnectOptions, CalendarRuntimeConnection, CalendarRuntimeInputs, CalendarRuntimeModel, CalendarRuntimeOverlay, CalendarSemanticActions, CalendarSlotName, CalendarStateChangeDetail, CalendarStateChangeHandler, CalendarStateChangeHandlers, CalendarStateSelector, CalendarStateSelectorOptions, CalendarStateSlice, CalendarStateSource, CalendarStore, CalendarStoreBinding, CalendarStoreInternals, CalendarStoreOptions, CalendarViewActions, CalendarViewDefinition, CalendarViewOptionsMap, CalendarVisibleRange, DraftStore, KeyboardGrab, KeyboardSessionStore };