@moltenship/calendar-primitives 0.0.0-stage → 2.0.0
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.
- package/LICENSE +21 -0
- package/README.md +47 -2
- package/dist/index.d.mts +1131 -0
- package/dist/index.mjs +2748 -0
- package/package.json +46 -3
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,1131 @@
|
|
|
1
|
+
import { CalendarClock, InstantInterval, PlainDateInterval, WallTimeSnapOptions } from "@moltenship/calendar-temporal";
|
|
2
|
+
import { AnnotationSnapshot, AnnotationSnapshotIssue, AvailabilityIssue, AvailabilitySnapshot, CalendarAnnotation, CalendarAnnotationSource, CalendarAnnouncementContext, CalendarAnnouncementMessages, CalendarAnnouncer, CalendarAvailability, CalendarCellFocus, CalendarChangeCause, CalendarDraft, CalendarEnvironment, CalendarEnvironmentBase, CalendarEventChangeHandler, CalendarEventInterval, CalendarEventPlacement, CalendarEventProposal, CalendarFocus, CalendarInputMethod, CalendarInteractionCheck, CalendarKeyboardSession, CalendarNowSource, CalendarPendingChanges, CalendarPendingPlacements, CalendarPolicy, CalendarPolicyResult, CalendarProposalDetail, CalendarProposalOutcome, CalendarSecondaryTimeZone, CalendarSelection, CalendarTransactionResult, CalendarViewStrategy, CalendarWeekRules, EventAdapter, EventHistory, EventHistoryOutcome, EventHistorySnapshot, EventId, EventSnapshot, EventSnapshotIssue, EventTransactions, InvalidCalendarEventPolicy, NormalizedCalendarEvent, ResourceId, ResourceStatus, 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
|
+
/**
|
|
236
|
+
* The text of a mounted live region, as a store: pass `speak` to `AnnouncerChannel.mount` and
|
|
237
|
+
* render the snapshot as the region's text. A message that repeats the last one gets a trailing
|
|
238
|
+
* no-break space, so the region changes and a screen reader reads it again. Empty until something
|
|
239
|
+
* is said, on the server too.
|
|
240
|
+
*/
|
|
241
|
+
interface AnnouncerLiveText extends CalendarStateSource<string> {
|
|
242
|
+
readonly speak: (text: string) => void;
|
|
243
|
+
}
|
|
244
|
+
/** Creates the text of one mounted live region; see `AnnouncerLiveText`. */
|
|
245
|
+
export declare function createAnnouncerLiveText(): AnnouncerLiveText;
|
|
246
|
+
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> & {
|
|
247
|
+
navigateNext(options?: CalendarCommandOptions): void;
|
|
248
|
+
navigatePrevious(options?: CalendarCommandOptions): void;
|
|
249
|
+
navigateToday(options?: CalendarCommandOptions): void;
|
|
250
|
+
/**
|
|
251
|
+
* Runs a change through the root's policies without showing or saving it, as a gesture's
|
|
252
|
+
* preview does: `rejected` with the reason `proposeEventChange` would give, or `accepted`, with
|
|
253
|
+
* any `change.warnings`. `null` for an unknown event, or when a policy answers asynchronously.
|
|
254
|
+
* Policies read `detail`, `{ input: "api" }` by default, as `proposeEventChange` gives it.
|
|
255
|
+
*/
|
|
256
|
+
readonly checkEventChange: (proposal: CalendarEventProposal<TEventId, TResourceId, TEvent>, detail?: CalendarProposalDetail) => CalendarPolicyResult<TEvent, TEventId, TResourceId> | null;
|
|
257
|
+
/**
|
|
258
|
+
* Validates a change against the root's policies, shows it while `onEventChange` persists it,
|
|
259
|
+
* and resolves with the outcome, which `onEventChangeResult` hears first, with `detail` as
|
|
260
|
+
* given. Read-only events and roots without `onEventChange` reject. `detail.input` names the
|
|
261
|
+
* input that made the proposal, `"api"` by default. A plain function, so it can be passed on as
|
|
262
|
+
* a callback.
|
|
263
|
+
*/
|
|
264
|
+
readonly proposeEventChange: (proposal: CalendarEventProposal<TEventId, TResourceId, TEvent>, detail?: CalendarProposalDetail) => Promise<CalendarTransactionResult<TEvent, TEventId, TResourceId>>;
|
|
265
|
+
};
|
|
266
|
+
type CalendarDiagnostic<TEvent, TEventId extends EventId> = {
|
|
267
|
+
readonly code: "unregistered-active-view";
|
|
268
|
+
readonly severity: "error";
|
|
269
|
+
readonly viewName: string;
|
|
270
|
+
} | {
|
|
271
|
+
readonly code: "invalid-event";
|
|
272
|
+
readonly issue: EventSnapshotIssue<TEvent, TEventId>;
|
|
273
|
+
readonly severity: "error";
|
|
274
|
+
} | {
|
|
275
|
+
readonly code: "invalid-annotation";
|
|
276
|
+
readonly issue: AnnotationSnapshotIssue;
|
|
277
|
+
readonly severity: "error";
|
|
278
|
+
} | {
|
|
279
|
+
readonly code: "invalid-availability";
|
|
280
|
+
readonly issue: AvailabilityIssue;
|
|
281
|
+
readonly severity: "error";
|
|
282
|
+
} | {
|
|
283
|
+
readonly code: "invalid-secondary-time-zone";
|
|
284
|
+
readonly issue: SecondaryTimeZoneIssue;
|
|
285
|
+
readonly severity: "error";
|
|
286
|
+
};
|
|
287
|
+
interface CalendarPartIds {
|
|
288
|
+
readonly frame: string;
|
|
289
|
+
readonly title: string;
|
|
290
|
+
readonly viewport: string;
|
|
291
|
+
}
|
|
292
|
+
/** The ids a root's chrome parts point at each other with. */
|
|
293
|
+
export declare function createCalendarPartIds(instanceId: string): CalendarPartIds;
|
|
294
|
+
/** What the active view shows and which events it needs, as `onVisibleRangeChange` reports it. */
|
|
295
|
+
interface CalendarVisibleRange<TView extends string = string> {
|
|
296
|
+
/** `range` resolved to instants in the display time zone. */
|
|
297
|
+
readonly instantRange: InstantInterval;
|
|
298
|
+
/** `loadRange` resolved to instants in the display time zone. */
|
|
299
|
+
readonly loadInstantRange: InstantInterval;
|
|
300
|
+
/**
|
|
301
|
+
* The dates to have events for: `range`, plus the pages a scrolling view keeps ready on each
|
|
302
|
+
* side, so a swipe shows their events at once.
|
|
303
|
+
*/
|
|
304
|
+
readonly loadRange: PlainDateInterval;
|
|
305
|
+
/** The visible dates. */
|
|
306
|
+
readonly range: PlainDateInterval;
|
|
307
|
+
readonly view: TView;
|
|
308
|
+
}
|
|
309
|
+
/** A keyboard session with what it needs to restart, restore focus, and announce itself. */
|
|
310
|
+
interface KeyboardGrab {
|
|
311
|
+
/** The cell the grabbed event sits in, or where a create started. */
|
|
312
|
+
readonly cell: CalendarCellFocus;
|
|
313
|
+
/** What the root's policies say about the session's proposal. */
|
|
314
|
+
readonly check: CalendarInteractionCheck;
|
|
315
|
+
/** The event as it was when grabbed; `null` when creating. */
|
|
316
|
+
readonly event: NormalizedCalendarEvent<unknown, EventId, ResourceId> | null;
|
|
317
|
+
/** Focus before the grab, restored on cancel. */
|
|
318
|
+
readonly origin: CalendarFocus;
|
|
319
|
+
readonly session: CalendarKeyboardSession;
|
|
320
|
+
}
|
|
321
|
+
/** The root's keyboard session. Its preview patches the grabbed event into the projection. */
|
|
322
|
+
interface KeyboardSessionStore {
|
|
323
|
+
readonly get: () => KeyboardGrab | null;
|
|
324
|
+
/** The grabbed event's proposed placement, for `applyEventOverlay`. */
|
|
325
|
+
readonly getPreview: () => CalendarPendingPlacements<EventId, ResourceId>;
|
|
326
|
+
/** The gesture in progress, for `useCalendarInteraction`. */
|
|
327
|
+
readonly grabs: CalendarStateSource<KeyboardGrab | null>;
|
|
328
|
+
readonly set: (grab: KeyboardGrab | null) => void;
|
|
329
|
+
readonly subscribe: (listener: () => void) => () => void;
|
|
330
|
+
}
|
|
331
|
+
export declare function createKeyboardSessionStore(): KeyboardSessionStore;
|
|
332
|
+
type AnyDraft = CalendarDraft<EventId, ResourceId>;
|
|
333
|
+
/** The pointer's draft, which the pointer layer reports to the root while a drag previews a change. */
|
|
334
|
+
interface DraftStore extends CalendarStateSource<AnyDraft | null> {
|
|
335
|
+
readonly set: (draft: AnyDraft | null) => void;
|
|
336
|
+
}
|
|
337
|
+
export declare function createDraftStore(): DraftStore;
|
|
338
|
+
/**
|
|
339
|
+
* Where focus enters the active view: its default entry (`"home"`), or its last target (`"end"`),
|
|
340
|
+
* as focus does after paging back. `calendarViewEntry` gives a view's.
|
|
341
|
+
*/
|
|
342
|
+
type CalendarRovingEntry = (command: "end" | "home") => CalendarFocus | null;
|
|
343
|
+
/**
|
|
344
|
+
* The elements of the active view that can take focus. Exactly one is the tab stop: the focused
|
|
345
|
+
* one, else the view's entry, else the first in document order, so the view stays reachable when
|
|
346
|
+
* focus is on something it does not render. Before any element registers, as on the server and
|
|
347
|
+
* while hydrating, the entry is the tab stop: whether the view renders the focus is only known
|
|
348
|
+
* once its elements register.
|
|
349
|
+
*/
|
|
350
|
+
interface RovingFocusStore {
|
|
351
|
+
/** Enters the next range from its end, after paging back, until something takes focus. */
|
|
352
|
+
readonly enterFromEnd: () => void;
|
|
353
|
+
/** Moves DOM focus to the tab stop, now or after the next `update`. */
|
|
354
|
+
readonly focusTabStop: (when: "now" | "after-update") => void;
|
|
355
|
+
/** The focus a key pressed on `node` moves from. */
|
|
356
|
+
readonly focusAt: (node: Node) => CalendarFocus | null;
|
|
357
|
+
/** Whether the element showing `target` across `days` dates is the tab stop. */
|
|
358
|
+
readonly isTabStop: (target: CalendarFocus, days: number) => boolean;
|
|
359
|
+
/**
|
|
360
|
+
* Adds an element that shows `target` across `days` dates; returns the cleanup that removes it.
|
|
361
|
+
* Elements a commit registers one by one are told about once, after it, in a microtask.
|
|
362
|
+
*/
|
|
363
|
+
readonly register: (element: HTMLElement, target: CalendarFocus, days: number) => () => void;
|
|
364
|
+
/** Tells `listener` when the tab stop may have moved. */
|
|
365
|
+
readonly subscribe: (listener: () => void) => () => void;
|
|
366
|
+
/**
|
|
367
|
+
* Follows the root's focus and the active view's entry. Call it once the elements of a render
|
|
368
|
+
* have registered, so DOM focus can move to one of them.
|
|
369
|
+
*/
|
|
370
|
+
readonly update: (focus: CalendarFocus | null, getEntry: CalendarRovingEntry) => void;
|
|
371
|
+
}
|
|
372
|
+
/** The active view's entry points, from its spatial navigation with no focus. */
|
|
373
|
+
export declare function calendarViewEntry(view: CalendarActiveView<AnyCalendarViewDefinition> | null): CalendarRovingEntry;
|
|
374
|
+
/**
|
|
375
|
+
* The focus plumbing of one rendered active view: `getView` reads the latest active view, and the
|
|
376
|
+
* roving store starts from the view `getView` returns now, so server markup gets its tab stop.
|
|
377
|
+
* Keep the store on the root's focus with `roving.update(focus, calendarViewEntry(view))` after
|
|
378
|
+
* the view's elements register.
|
|
379
|
+
*/
|
|
380
|
+
export declare function createCalendarViewRuntime(getView: () => CalendarActiveView<AnyCalendarViewDefinition> | null): CalendarViewRuntime;
|
|
381
|
+
/**
|
|
382
|
+
* A key for a focus target that changes exactly when the target does, for an integration that
|
|
383
|
+
* registers an element again when its target changes. `1` and `"1"` are distinct IDs, and `null`
|
|
384
|
+
* (unassigned) differs from no resource.
|
|
385
|
+
*/
|
|
386
|
+
export declare function calendarFocusKey(target: CalendarFocus): string;
|
|
387
|
+
/**
|
|
388
|
+
* What an element showing `target` across `days` dates does when it takes DOM focus itself (call
|
|
389
|
+
* it only when the focus event's target is that element): it becomes the calendar's focus. Focus
|
|
390
|
+
* already on it stays as it is, keeping an event's date within the element. `event`, the focus
|
|
391
|
+
* event, reaches the state handlers, so they hear the click or key that moved focus.
|
|
392
|
+
*/
|
|
393
|
+
export declare function focusRovingTarget({ actions, read }: Pick<CalendarInteractionRuntime, "actions" | "read">, target: CalendarFocus, days: number, event: Event): void;
|
|
394
|
+
interface CalendarStoreBinding<TView extends string, TSelection, TFocus, TResourceId extends ResourceId> {
|
|
395
|
+
readonly controlled: CalendarControlledState<TView, TSelection, TFocus, TResourceId>;
|
|
396
|
+
readonly handlers: CalendarStateChangeHandlers<TView, TSelection, TFocus, TResourceId>;
|
|
397
|
+
}
|
|
398
|
+
/** One root's view of a shared store: its controlled slices, handlers, and pending requests. */
|
|
399
|
+
interface CalendarRootStoreBinding<TView extends string, TSelection, TFocus, TResourceId extends ResourceId> {
|
|
400
|
+
/** Commands that honor this root's controlled slices and handlers. */
|
|
401
|
+
readonly actions: CalendarActions<TView, TSelection, TFocus, TResourceId>;
|
|
402
|
+
/** Routes `store.actions` through this root until the cleanup runs; the latest mounted root wins. */
|
|
403
|
+
readonly attach: () => () => void;
|
|
404
|
+
/** Publishes the root's committed props, settling requests for slices whose owner changed them. */
|
|
405
|
+
readonly commit: (binding: CalendarStoreBinding<TView, TSelection, TFocus, TResourceId>) => void;
|
|
406
|
+
/**
|
|
407
|
+
* The latest requested state. A controlled change requested since the last commit is visible
|
|
408
|
+
* here before its owner commits it, so consecutive commands in one event handler compose.
|
|
409
|
+
*/
|
|
410
|
+
readonly read: () => CalendarPublicState<TView, TSelection, TFocus, TResourceId>;
|
|
411
|
+
/**
|
|
412
|
+
* Calls `listener` with every command, even one that asks for the value a slice already has,
|
|
413
|
+
* as Today does when the view only looks as if it had moved. Returns the unsubscribe function.
|
|
414
|
+
*/
|
|
415
|
+
readonly subscribeRequests: (listener: CalendarRequestListener) => () => void;
|
|
416
|
+
}
|
|
417
|
+
/** A command a root received: the slice it asks to change, and the value it asks for. */
|
|
418
|
+
type CalendarRequestListener = (slice: CalendarStateSlice, value: unknown) => void;
|
|
419
|
+
interface CalendarStoreInternals<TView extends string, TSelection, TFocus, TResourceId extends ResourceId> {
|
|
420
|
+
readonly bind: (binding: CalendarStoreBinding<TView, TSelection, TFocus, TResourceId>) => CalendarRootStoreBinding<TView, TSelection, TFocus, TResourceId>;
|
|
421
|
+
}
|
|
422
|
+
/** The six slices, in a fixed order. */
|
|
423
|
+
export declare const calendarStateSlices: readonly CalendarStateSlice[];
|
|
424
|
+
/** Dates by value and resource lists by element; everything else by identity. */
|
|
425
|
+
export declare function sameSliceValue(slice: CalendarStateSlice, previous: unknown, next: unknown): boolean;
|
|
426
|
+
/** Overlays every defined controlled slice on the uncontrolled state. */
|
|
427
|
+
export declare function mergeControlledState<TState extends CalendarPublicState<string, unknown, unknown>>(state: TState, controlled: Partial<TState> | undefined): TState;
|
|
428
|
+
export declare function getCalendarStoreInternals<TView extends string, TSelection, TFocus, TResourceId extends ResourceId>(store: CalendarStore<TView, TSelection, TFocus, TResourceId>): CalendarStoreInternals<TView, TSelection, TFocus, TResourceId>;
|
|
429
|
+
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>;
|
|
430
|
+
type AnyPendingChanges = CalendarPendingChanges<unknown, EventId, ResourceId>;
|
|
431
|
+
/**
|
|
432
|
+
* A root's interaction plumbing, which views and their gestures drive whatever calendar they
|
|
433
|
+
* render in; the nearest root wins.
|
|
434
|
+
*/
|
|
435
|
+
interface CalendarInteractionRuntime {
|
|
436
|
+
readonly actions: CalendarSemanticActions<any, any, any, any, any, any>;
|
|
437
|
+
readonly announcements: AnnouncerChannel;
|
|
438
|
+
/** The root's pending changes, which an event history waits out before it undoes. */
|
|
439
|
+
readonly changes: CalendarStateSource<AnyPendingChanges>;
|
|
440
|
+
/**
|
|
441
|
+
* The change being drafted, by keyboard or pointer: the keyboard's session while one is in
|
|
442
|
+
* progress, else the pointer's draft. A keyboard session's draft keeps its identity for as long
|
|
443
|
+
* as the session does.
|
|
444
|
+
*/
|
|
445
|
+
readonly draft: CalendarStateSource<CalendarDraft<EventId, ResourceId> | null>;
|
|
446
|
+
/** The root has no `onEventChange`, so it rejects every change and views start no gestures. */
|
|
447
|
+
readonly isReadOnly: boolean;
|
|
448
|
+
readonly keyboard: KeyboardSessionStore;
|
|
449
|
+
/** The pointer's draft while a drag previews a change; the keyboard's is in `keyboard`. */
|
|
450
|
+
readonly pointerDraft: DraftStore;
|
|
451
|
+
/**
|
|
452
|
+
* The dates the view on screen shows for `anchor`, as of the last commit, so a change of view
|
|
453
|
+
* still waiting for its owner doesn't count; `null` without one.
|
|
454
|
+
*/
|
|
455
|
+
readonly rangeOf: (anchor: Temporal.PlainDate) => PlainDateInterval | null;
|
|
456
|
+
/**
|
|
457
|
+
* The latest state, controlled slices and requests not yet committed included; read it in
|
|
458
|
+
* callbacks that run after the render that created them.
|
|
459
|
+
*/
|
|
460
|
+
readonly read: () => AnyCalendarState;
|
|
461
|
+
/** Subscribes to every command the root receives, even one that changes nothing. */
|
|
462
|
+
readonly requests: (listener: CalendarRequestListener) => () => void;
|
|
463
|
+
/** For subscribing; its identity changes with controlled values. */
|
|
464
|
+
readonly source: CalendarStateSource<AnyCalendarState>;
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* The active view's focus plumbing, which an integration creates once per rendered active view
|
|
468
|
+
* (`createCalendarViewRuntime`) and hands to the view's keyboard and focusable elements.
|
|
469
|
+
*/
|
|
470
|
+
interface CalendarViewRuntime {
|
|
471
|
+
/** The latest active view, read when a key is handled; `null` once none is registered. */
|
|
472
|
+
readonly getView: () => CalendarActiveView<AnyCalendarViewDefinition> | null;
|
|
473
|
+
/** The view's focusable elements and its one tab stop. */
|
|
474
|
+
readonly roving: RovingFocusStore;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Calls `listener` whenever something asks the root for an anchor date, until the returned
|
|
478
|
+
* cleanup runs: Previous, Next, Today, keys paging past the view, or `setAnchorDate`, even a date
|
|
479
|
+
* that is already the anchor. `range` is what the view on screen shows for that date (`null`
|
|
480
|
+
* without one), so a view can tell a request for the range it has, as Today in this week, from
|
|
481
|
+
* one that moves it.
|
|
482
|
+
*/
|
|
483
|
+
export declare function subscribeAnchorDateRequests({ rangeOf, requests }: Pick<CalendarInteractionRuntime, "rangeOf" | "requests">, listener: (date: Temporal.PlainDate, range: PlainDateInterval | null) => void): () => void;
|
|
484
|
+
/** The busy resources of a range, with the events that make them busy; see `busyResources`. */
|
|
485
|
+
type CalendarBusyResources = ReadonlyMap<ResourceId, readonly NormalizedCalendarEvent<unknown, EventId, ResourceId>[]>;
|
|
486
|
+
/** A resource during the draft's time; see `useDraftBusy`. */
|
|
487
|
+
interface CalendarDraftBusy {
|
|
488
|
+
/** The busy events that overlap the draft, by start; empty when the resource is free. */
|
|
489
|
+
readonly events: readonly NormalizedCalendarEvent<unknown, EventId, ResourceId>[];
|
|
490
|
+
/** Whether the draft falls outside the resource's hours. */
|
|
491
|
+
readonly outsideHours: boolean;
|
|
492
|
+
}
|
|
493
|
+
/** What a busy-resources query asks about a range, besides the range. */
|
|
494
|
+
interface CalendarBusyResourcesQuery {
|
|
495
|
+
/** An event left out, such as the one being moved; `null` and `undefined` leave none out. */
|
|
496
|
+
readonly exclude?: EventId | null;
|
|
497
|
+
/** The resources asked about; every resource by default. */
|
|
498
|
+
readonly resourceIds?: readonly ResourceId[];
|
|
499
|
+
/** The display time zone, which all-day and floating events count on. */
|
|
500
|
+
readonly timeZone: string;
|
|
501
|
+
}
|
|
502
|
+
/** The time a busy-resources query asks about: an instant range, or an event's interval. */
|
|
503
|
+
type BusyRange = InstantInterval | CalendarEventInterval;
|
|
504
|
+
/**
|
|
505
|
+
* A memoized query for the resources busy during a range, with their events; free ones are
|
|
506
|
+
* absent. Call it with the root's events, pending changes included, as often as a framework
|
|
507
|
+
* renders: it queries again only when the events, the range or the query change, the range and
|
|
508
|
+
* the resource IDs by value, so ones made inline cost nothing. A `null` range asks nothing.
|
|
509
|
+
*/
|
|
510
|
+
export declare function createBusyResourcesQuery(): (events: AnyEvents, range: BusyRange | null, query: CalendarBusyResourcesQuery) => CalendarBusyResources;
|
|
511
|
+
/**
|
|
512
|
+
* One resource's query of the draft (`CalendarInteractionRuntime.draft`): the busy events that
|
|
513
|
+
* overlap the draft's time, the draft's own event aside, and whether the time falls outside the
|
|
514
|
+
* resource's hours; `null` without a draft, or for a `null` resource. The draft's busy resources
|
|
515
|
+
* are worked out once per draft and events for every resource that asks, and the result keeps its
|
|
516
|
+
* identity while the answer is the same, so a framework re-renders only when it changes.
|
|
517
|
+
*/
|
|
518
|
+
export declare function createDraftBusyQuery(): (draft: AnyDraft | null, events: AnyEvents, availability: AvailabilitySnapshot, resourceId: ResourceId | null) => CalendarDraftBusy | null;
|
|
519
|
+
/** The clock a root reads when it has neither `now` nor `clock`. */
|
|
520
|
+
export declare const systemClock: CalendarClock;
|
|
521
|
+
/** How often a root samples its clock for `today`. */
|
|
522
|
+
export declare const TODAY_SAMPLE_INTERVAL_MS = 6e4;
|
|
523
|
+
interface CalendarClockTicker {
|
|
524
|
+
/** The last sample, taken now if there is none yet. */
|
|
525
|
+
readonly getSnapshot: () => Temporal.Instant;
|
|
526
|
+
/**
|
|
527
|
+
* Samples at once, and then every interval while anyone is subscribed, calling every
|
|
528
|
+
* subscriber when the instant moved; returns the cleanup that ends this subscription.
|
|
529
|
+
*/
|
|
530
|
+
readonly subscribe: (onChange: () => void) => () => void;
|
|
531
|
+
}
|
|
532
|
+
/**
|
|
533
|
+
* Samples `clock` every `intervalMs` while subscribed: one timer for every subscriber, started by
|
|
534
|
+
* the first and stopped by the last.
|
|
535
|
+
*/
|
|
536
|
+
export declare function createClockTicker(clock: CalendarClock, intervalMs: number): CalendarClockTicker;
|
|
537
|
+
/** The clock a source samples: its own, or the system's. */
|
|
538
|
+
export declare function clockOf(source: CalendarNowSource | undefined): CalendarClock;
|
|
539
|
+
export declare function sameElements<T>(left: readonly T[], right: readonly T[]): boolean;
|
|
540
|
+
/** Compares own enumerable properties with `Object.is`; non-objects compare with `Object.is`. */
|
|
541
|
+
export declare function shallowEqual<T>(left: T, right: T): boolean;
|
|
542
|
+
export declare function samePlainDate(left: Temporal.PlainDate | null | undefined, right: Temporal.PlainDate | null | undefined): boolean;
|
|
543
|
+
export declare function sameInstant(left: Temporal.Instant | undefined, right: Temporal.Instant | undefined): boolean;
|
|
544
|
+
export declare function sameRange(left: PlainDateInterval | undefined, right: PlainDateInterval | undefined): boolean;
|
|
545
|
+
export declare function sameWeekRules(left: CalendarWeekRules, right: CalendarWeekRules): boolean;
|
|
546
|
+
/**
|
|
547
|
+
* Compares working hours by value, so an inline `availability` keeps its shading cached. Invalid
|
|
548
|
+
* entries never throw here; the snapshot reports them.
|
|
549
|
+
*/
|
|
550
|
+
export declare function sameAvailability(left: CalendarAvailability | undefined, right: CalendarAvailability | undefined): boolean;
|
|
551
|
+
/**
|
|
552
|
+
* Compares secondary time zones by value, so an inline list keeps the environment as it is. A
|
|
553
|
+
* single zone passed where a list belongs, which the root reports, compares by value too.
|
|
554
|
+
*/
|
|
555
|
+
export declare function sameSecondaryTimeZones(left: readonly (CalendarSecondaryTimeZone | string)[], right: readonly (CalendarSecondaryTimeZone | string)[]): boolean;
|
|
556
|
+
/** What an undo or redo announcement is built from: the root's announcement context and the step's event. */
|
|
557
|
+
interface CalendarHistoryAnnouncementContext<TEvent = unknown, TEventId extends EventId = EventId, TResourceId extends ResourceId = ResourceId> extends CalendarAnnouncementContext {
|
|
558
|
+
/**
|
|
559
|
+
* The step's event as the calendar shows it, for its title: from the latest events the calendar
|
|
560
|
+
* rendered, which may still be those from before the undo or redo, or from the events the step
|
|
561
|
+
* was checked against. `undefined` when neither has it, as a restored event the events don't
|
|
562
|
+
* include yet.
|
|
563
|
+
*/
|
|
564
|
+
readonly event: NormalizedCalendarEvent<TEvent, TEventId, TResourceId> | undefined;
|
|
565
|
+
}
|
|
566
|
+
/** Builds what a screen reader hears after an undo or a redo; `null` says nothing. */
|
|
567
|
+
type CalendarHistoryAnnouncementBuilder<TEvent = unknown, TEventId extends EventId = EventId, TResourceId extends ResourceId = ResourceId> = (outcome: EventHistoryOutcome<TEvent, TEventId, TResourceId>, context: CalendarHistoryAnnouncementContext<TEvent, TEventId, TResourceId>) => string | null;
|
|
568
|
+
/**
|
|
569
|
+
* Localized announcements for undo and redo. The calendar packages ship no text: the registry's
|
|
570
|
+
* calendar source has an English set to copy and translate.
|
|
571
|
+
*/
|
|
572
|
+
interface CalendarHistoryMessages<TEvent = unknown, TEventId extends EventId = EventId, TResourceId extends ResourceId = ResourceId> {
|
|
573
|
+
readonly redo: CalendarHistoryAnnouncementBuilder<TEvent, TEventId, TResourceId>;
|
|
574
|
+
readonly undo: CalendarHistoryAnnouncementBuilder<TEvent, TEventId, TResourceId>;
|
|
575
|
+
}
|
|
576
|
+
/** How a bound history speaks; see `useCalendarHistory`. */
|
|
577
|
+
interface CalendarHistoryOptions<TEvent, TEventId extends EventId = EventId, TResourceId extends ResourceId = ResourceId> {
|
|
578
|
+
/**
|
|
579
|
+
* Speaks each undo and redo outcome through the root's `Announcer`. Read from the latest
|
|
580
|
+
* render; without it, nothing is said.
|
|
581
|
+
*/
|
|
582
|
+
readonly messages?: CalendarHistoryMessages<TEvent, TEventId, TResourceId>;
|
|
583
|
+
}
|
|
584
|
+
/** What an undo or redo button passes on in the proposal's detail. */
|
|
585
|
+
interface CalendarHistoryCommandOptions {
|
|
586
|
+
/** The input the command came from; `"api"` by default. */
|
|
587
|
+
readonly input?: CalendarInputMethod;
|
|
588
|
+
}
|
|
589
|
+
/** A history bound to a root: its stacks, and undo and redo through the root's pipeline. */
|
|
590
|
+
interface CalendarHistory<TEvent, TEventId extends EventId = EventId, TResourceId extends ResourceId = ResourceId> extends EventHistorySnapshot<TEvent, TEventId, TResourceId> {
|
|
591
|
+
readonly canRedo: boolean;
|
|
592
|
+
readonly canUndo: boolean;
|
|
593
|
+
/** Takes the last undone step forward again; resolves with the outcome. */
|
|
594
|
+
readonly redo: (options?: CalendarHistoryCommandOptions) => Promise<EventHistoryOutcome<TEvent, TEventId, TResourceId>>;
|
|
595
|
+
/** Takes the last step back by proposing its inverse; resolves with the outcome. */
|
|
596
|
+
readonly undo: (options?: CalendarHistoryCommandOptions) => Promise<EventHistoryOutcome<TEvent, TEventId, TResourceId>>;
|
|
597
|
+
}
|
|
598
|
+
/** What a history binding reads from the latest render each time it undoes or redoes. */
|
|
599
|
+
interface CalendarHistoryBindingOptions<TEvent, TEventId extends EventId = EventId, TResourceId extends ResourceId = ResourceId> extends CalendarHistoryOptions<TEvent, TEventId, TResourceId> {
|
|
600
|
+
/** The events the calendar shows, pending changes included: the root's latest. */
|
|
601
|
+
readonly events: EventSnapshot<TEvent, TEventId, TResourceId>;
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Binds an event history to a root, as a store of `CalendarHistory` values: undo and redo propose
|
|
605
|
+
* the inverse through the root's `proposeEventChange`, against the events `getOptions` gives, and
|
|
606
|
+
* with its `messages` their outcomes are spoken through the root's announcer channel. The
|
|
607
|
+
* snapshot keeps its identity until the history changes; the server snapshot is an empty history.
|
|
608
|
+
* `getOptions` is read whenever a command runs and when it ends, so the binding is made once per
|
|
609
|
+
* root and history.
|
|
610
|
+
*/
|
|
611
|
+
export declare function bindCalendarHistory<TEvent, TEventId extends EventId, TResourceId extends ResourceId>({ actions, announcements, changes }: Pick<CalendarInteractionRuntime, "actions" | "announcements" | "changes">, history: EventHistory<TEvent, TEventId, TResourceId>, getOptions: () => CalendarHistoryBindingOptions<TEvent, TEventId, TResourceId>): CalendarStateSource<CalendarHistory<TEvent, TEventId, TResourceId>>;
|
|
612
|
+
/** What undo and redo the shortcuts call: a bound history, as `bindCalendarHistory` gives. */
|
|
613
|
+
interface CalendarHistoryShortcutsTarget {
|
|
614
|
+
readonly redo: (options?: CalendarHistoryCommandOptions) => unknown;
|
|
615
|
+
readonly undo: (options?: CalendarHistoryCommandOptions) => unknown;
|
|
616
|
+
}
|
|
617
|
+
/** What the history shortcuts read each time a key arrives. */
|
|
618
|
+
interface CalendarHistoryShortcutsConfig {
|
|
619
|
+
readonly history: CalendarHistoryShortcutsTarget;
|
|
620
|
+
/**
|
|
621
|
+
* Keys that redo, such as `"Shift+Mod+Z"`: modifiers joined by `+`, then the key. `Mod` is ⌘
|
|
622
|
+
* on Apple platforms and Ctrl elsewhere. `["Shift+Mod+Z", "Ctrl+Y"]` by default; `[]` turns
|
|
623
|
+
* them off.
|
|
624
|
+
*/
|
|
625
|
+
readonly redo?: readonly string[];
|
|
626
|
+
/**
|
|
627
|
+
* The element whose keys undo and redo, usually the root's frame; `null` while it isn't
|
|
628
|
+
* mounted. Keys elsewhere on the page are left alone.
|
|
629
|
+
*/
|
|
630
|
+
readonly scope: HTMLElement | null;
|
|
631
|
+
/** Keys that undo; `["Mod+Z"]` by default, and `[]` turns them off. */
|
|
632
|
+
readonly undo?: readonly string[];
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* Listens for a calendar's undo and redo keys until the returned cleanup runs: Mod+Z undoes, and
|
|
636
|
+
* Shift+Mod+Z or Ctrl+Y redoes, where Mod is ⌘ on Apple platforms and Ctrl elsewhere. One
|
|
637
|
+
* `keydown` listener on the document acts on keys whose target is inside the scope, after the
|
|
638
|
+
* page's own handlers, a framework's delegated ones included. Keys never undo in a text field,
|
|
639
|
+
* where the browser undoes the text, or in a dialog, menu or list inside the scope, nor during a
|
|
640
|
+
* keyboard or pointer gesture of the root's, nor once something else handled them. Commands pass
|
|
641
|
+
* `{ input: "keyboard" }`.
|
|
642
|
+
*
|
|
643
|
+
* `getConfig` is read when a key arrives, so a scope that mounts after the listener, or remounts,
|
|
644
|
+
* keeps its keys, and a portal outside it, such as a dialog, never reaches them.
|
|
645
|
+
*/
|
|
646
|
+
export declare function attachCalendarHistoryShortcuts({ keyboard, pointerDraft }: Pick<CalendarInteractionRuntime, "keyboard" | "pointerDraft">, getConfig: () => CalendarHistoryShortcutsConfig): () => void;
|
|
647
|
+
/** How a view's keyboard creates, moves and resizes events; read whenever a key arrives. */
|
|
648
|
+
interface CalendarKeyboardOptions {
|
|
649
|
+
/**
|
|
650
|
+
* Which way time runs through the view's slots: down the block axis, as in a time grid (the
|
|
651
|
+
* default), or along the inline axis, as in a timeline. A slot create grows that way.
|
|
652
|
+
*/
|
|
653
|
+
readonly axis?: "block" | "inline";
|
|
654
|
+
/**
|
|
655
|
+
* How long an event created on a slot starts out, in whole slots; arrow keys then change it
|
|
656
|
+
* as a pointer drag would. One hour by default. A create on a day starts as that day.
|
|
657
|
+
*/
|
|
658
|
+
readonly createDuration?: Temporal.DurationLike;
|
|
659
|
+
/** Length and alignment of time-grid slots; pass the pointer layer's `snap`. 15 minutes by default. */
|
|
660
|
+
readonly snap?: WallTimeSnapOptions;
|
|
661
|
+
}
|
|
662
|
+
/**
|
|
663
|
+
* What a framework's handler got for a DOM event, when the framework wraps DOM events in its own,
|
|
664
|
+
* as React does: the keyboard prevents its default and stops its propagation, so the framework's
|
|
665
|
+
* own handlers further out see both.
|
|
666
|
+
*/
|
|
667
|
+
interface CalendarKeyEventWrapper {
|
|
668
|
+
readonly preventDefault: () => void;
|
|
669
|
+
readonly stopPropagation: () => void;
|
|
670
|
+
}
|
|
671
|
+
/**
|
|
672
|
+
* A view's keyboard, from `createCalendarKeyboard`. An integration calls its methods from the
|
|
673
|
+
* `keydown` and `focusout` handlers of the element around the view's focusable cells and events.
|
|
674
|
+
* Bind `keydown` on that element itself (`addEventListener` from a ref in Solid, not
|
|
675
|
+
* `onKeyDown`): a handler the framework delegates to the document runs once the key has bubbled
|
|
676
|
+
* past every element, too late for Escape's stopped propagation to keep it from the handlers
|
|
677
|
+
* around the view.
|
|
678
|
+
*/
|
|
679
|
+
interface CalendarKeyboardController {
|
|
680
|
+
/**
|
|
681
|
+
* Leaves the element: focus moving outside `region`, the element the handler is on, cancels a
|
|
682
|
+
* gesture in progress, a task later, unless focus has come back by then, as it does when a
|
|
683
|
+
* grabbed event re-renders in a new place.
|
|
684
|
+
*/
|
|
685
|
+
readonly focusOut: (event: FocusEvent, region: HTMLElement) => void;
|
|
686
|
+
/**
|
|
687
|
+
* Handles a key pressed inside the view. A key the calendar acts on has its default prevented,
|
|
688
|
+
* and Escape also stops propagating, through `wrapper` when given (see
|
|
689
|
+
* `CalendarKeyEventWrapper`), else through `event` itself. Keys with Alt, Ctrl or Meta, keys
|
|
690
|
+
* composing text, and keys whose default is already prevented are left alone.
|
|
691
|
+
*/
|
|
692
|
+
readonly keyDown: (event: KeyboardEvent, wrapper?: CalendarKeyEventWrapper) => void;
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* The keyboard of one rendered active view: navigation, and keyboard move, resize and create.
|
|
696
|
+
* `getOptions` and `getResources` (the root's resource tree) are read whenever a key arrives, so
|
|
697
|
+
* the controller is created once per root and view and never again for new options.
|
|
698
|
+
*
|
|
699
|
+
* - Arrow keys, Home, End, Page Up, and Page Down move focus through the view's
|
|
700
|
+
* `getSpatialNavigation`, navigating the view when focus leaves it. Enter moves into a cell's
|
|
701
|
+
* events and Escape back out.
|
|
702
|
+
* - Space grabs the focused event to move it, or the focused cell to create an event there;
|
|
703
|
+
* Shift+Space grabs an event's end to resize it, and again switches to its start. Navigation
|
|
704
|
+
* keys then step the gesture, Enter or Space commits it through `proposeEventChange`, and
|
|
705
|
+
* Escape, Tab, or leaving the view cancels it. On a read-only root, Space grabs nothing.
|
|
706
|
+
*
|
|
707
|
+
* Every phase is announced through the root's announcer channel. A view that unmounts mid-gesture
|
|
708
|
+
* lets go of it with `interaction.keyboard.set(null)`.
|
|
709
|
+
*/
|
|
710
|
+
export declare function createCalendarKeyboard({ actions, announcements, isReadOnly, keyboard, read }: CalendarInteractionRuntime, { getView, roving }: CalendarViewRuntime, getOptions: () => CalendarKeyboardOptions, getResources: () => ResourceTree | null): CalendarKeyboardController;
|
|
711
|
+
/**
|
|
712
|
+
* Memo cells: what `useMemo` and a stable-value hook do in a component, as plain closures a
|
|
713
|
+
* runtime owns, so a framework can derive during render (or in a signal's memo) and get the same
|
|
714
|
+
* objects back while their inputs hold.
|
|
715
|
+
*/
|
|
716
|
+
/** A value that keeps its first identity while `isEqual` says each next one is the same. */
|
|
717
|
+
export declare function createStableCell<T>(isEqual: (previous: T, next: T) => boolean): (next: T) => T;
|
|
718
|
+
/** A value computed again only when one of its dependencies changes identity. */
|
|
719
|
+
export declare function createMemoCell<T>(): (deps: readonly unknown[], compute: () => T) => T;
|
|
720
|
+
/** What a runtime is made from: the factory's adapter, its policy for invalid events, its views. */
|
|
721
|
+
interface CalendarRuntimeConfig<TEvent, TViewDef extends AnyCalendarViewDefinition, TEventId extends EventId, TResourceId extends ResourceId> {
|
|
722
|
+
readonly eventAdapter: EventAdapter<TEvent, TEventId, TResourceId>;
|
|
723
|
+
readonly invalidEventPolicy?: InvalidCalendarEventPolicy;
|
|
724
|
+
readonly views: readonly TViewDef[];
|
|
725
|
+
}
|
|
726
|
+
/** The store a root reads its state from, bound to its controlled slices. */
|
|
727
|
+
interface CalendarRuntimeConnection<TView extends string, TSelection, TFocus, TResourceId extends ResourceId> {
|
|
728
|
+
readonly binding: CalendarRootStoreBinding<TView, TSelection, TFocus, TResourceId>;
|
|
729
|
+
/** The controlled slices, the same object while their values hold. */
|
|
730
|
+
readonly controlled: CalendarControlledState<TView, TSelection, TFocus, TResourceId>;
|
|
731
|
+
/** The store's state with the controlled slices laid over it; subscribe and read state here. */
|
|
732
|
+
readonly source: CalendarStateSource<CalendarPublicState<TView, TSelection, TFocus, TResourceId>>;
|
|
733
|
+
readonly store: CalendarStore<TView, TSelection, TFocus, TResourceId>;
|
|
734
|
+
}
|
|
735
|
+
interface CalendarRuntimeConnectOptions<TView extends string, TSelection, TFocus, TResourceId extends ResourceId> {
|
|
736
|
+
readonly controlled: CalendarControlledState<TView, TSelection, TFocus, TResourceId>;
|
|
737
|
+
/** The defaults of the store the root owns, read once, when it has no `store` of its own. */
|
|
738
|
+
readonly defaults: () => CalendarStoreOptions<TView, TSelection, TFocus, TResourceId>;
|
|
739
|
+
readonly store?: CalendarRootStore<TView, TSelection, TFocus, TResourceId>;
|
|
740
|
+
}
|
|
741
|
+
/** What changes at runtime beside the root's state: pending changes and a keyboard preview. */
|
|
742
|
+
interface CalendarRuntimeOverlay<TEventId extends EventId, TResourceId extends ResourceId> {
|
|
743
|
+
readonly pending: CalendarPendingPlacements<TEventId, TResourceId>;
|
|
744
|
+
readonly preview: CalendarPendingPlacements<TEventId, TResourceId>;
|
|
745
|
+
}
|
|
746
|
+
/** Everything a root derives its model from: its props, and what the adapter subscribed to. */
|
|
747
|
+
interface CalendarRuntimeInputs<TEvent, TResource, TViewDef extends AnyCalendarViewDefinition, TSelection, TFocus, TEventId extends EventId, TResourceId extends ResourceId> {
|
|
748
|
+
/** Whether an agent may delete events; without it the engine refuses an agent's delete. */
|
|
749
|
+
readonly allowAgentDelete?: boolean;
|
|
750
|
+
readonly annotationSources?: readonly CalendarAnnotationSource[];
|
|
751
|
+
readonly annotations?: readonly CalendarAnnotation<unknown, TResourceId>[];
|
|
752
|
+
readonly availability?: CalendarAvailability;
|
|
753
|
+
readonly clock?: CalendarClock;
|
|
754
|
+
readonly connection: CalendarRuntimeConnection<TViewDef["name"], TSelection, TFocus, TResourceId>;
|
|
755
|
+
readonly direction?: CalendarEnvironment["direction"];
|
|
756
|
+
readonly disambiguation?: CalendarEnvironment["disambiguation"];
|
|
757
|
+
/** The application's events as an array; an adapter reads an event source's current one. */
|
|
758
|
+
readonly events: readonly TEvent[];
|
|
759
|
+
readonly handlers: CalendarStateChangeHandlers<TViewDef["name"], TSelection, TFocus, TResourceId>;
|
|
760
|
+
/** The clock's latest sample, for `today`; `null` while server rendering and hydrating. */
|
|
761
|
+
readonly instant: Temporal.Instant | null;
|
|
762
|
+
readonly locale: Intl.Locale | string;
|
|
763
|
+
readonly now?: Temporal.Instant;
|
|
764
|
+
readonly onDiagnosticsChange?: (diagnostics: readonly CalendarDiagnostic<TEvent, TEventId>[]) => void;
|
|
765
|
+
readonly onEventChange?: CalendarEventChangeHandler<TEvent, TEventId, TResourceId>;
|
|
766
|
+
readonly onEventChangeResult?: (result: CalendarTransactionResult<TEvent, TEventId, TResourceId>, detail: CalendarProposalDetail) => void;
|
|
767
|
+
readonly onVisibleRangeChange?: (range: CalendarVisibleRange<TViewDef["name"]>) => void;
|
|
768
|
+
/** `runtime.overlay`'s snapshot, read where the adapter subscribes to it. */
|
|
769
|
+
readonly overlay: CalendarRuntimeOverlay<TEventId, TResourceId>;
|
|
770
|
+
readonly policies?: readonly CalendarPolicy<TEvent, TEventId, TResourceId>[];
|
|
771
|
+
readonly resources?: readonly TResource[];
|
|
772
|
+
readonly secondaryTimeZones?: readonly (CalendarSecondaryTimeZone | string)[];
|
|
773
|
+
/** `connection.source`'s snapshot, read where the adapter subscribes to it. */
|
|
774
|
+
readonly state: CalendarPublicState<TViewDef["name"], TSelection, TFocus, TResourceId>;
|
|
775
|
+
readonly viewOptions?: CalendarViewOptionsMap<TViewDef>;
|
|
776
|
+
readonly weekRules: CalendarWeekRules;
|
|
777
|
+
}
|
|
778
|
+
/** The root's annotations and the sources it shows. */
|
|
779
|
+
interface CalendarAnnotations {
|
|
780
|
+
readonly snapshot: AnnotationSnapshot;
|
|
781
|
+
readonly sources: readonly CalendarAnnotationSource[];
|
|
782
|
+
}
|
|
783
|
+
/** Everything a root shows, derived from its inputs; each part keeps its identity while it holds. */
|
|
784
|
+
interface CalendarRuntimeModel<TEvent, TResource, TViewDef extends AnyCalendarViewDefinition, TSelection, TFocus, TEventId extends EventId, TResourceId extends ResourceId> {
|
|
785
|
+
readonly actions: CalendarSemanticActions<TViewDef["name"], TSelection, TFocus, TResourceId, TEvent, TEventId>;
|
|
786
|
+
/** The active view's definition; `undefined` while the active view is unregistered. */
|
|
787
|
+
readonly activeDefinition: TViewDef | undefined;
|
|
788
|
+
readonly activeView: CalendarActiveView<TViewDef> | null;
|
|
789
|
+
readonly annotations: CalendarAnnotations;
|
|
790
|
+
readonly availability: AvailabilitySnapshot;
|
|
791
|
+
readonly diagnostics: readonly CalendarDiagnostic<TEvent, TEventId>[];
|
|
792
|
+
readonly environment: CalendarEnvironment;
|
|
793
|
+
/** The application's events, without pending changes. */
|
|
794
|
+
readonly eventSnapshot: EventSnapshot<TEvent, TEventId, TResourceId>;
|
|
795
|
+
readonly interaction: CalendarInteractionRuntime;
|
|
796
|
+
/** The root has no `onEventChange`, so it rejects every change. */
|
|
797
|
+
readonly isReadOnly: boolean;
|
|
798
|
+
readonly resourceTree: ResourceTree;
|
|
799
|
+
readonly resources: readonly TResource[];
|
|
800
|
+
readonly state: CalendarPublicState<TViewDef["name"], TSelection, TFocus, TResourceId>;
|
|
801
|
+
/** The state source views subscribe to; its identity changes with controlled values. */
|
|
802
|
+
readonly source: CalendarStateSource<CalendarPublicState<TViewDef["name"], TSelection, TFocus, TResourceId>>;
|
|
803
|
+
readonly today: Temporal.PlainDate | null;
|
|
804
|
+
/** The environment views get: `environment` without the clock. */
|
|
805
|
+
readonly viewEnvironment: CalendarEnvironmentBase;
|
|
806
|
+
/** The events views show: the application's, with pending changes and the keyboard's preview. */
|
|
807
|
+
readonly visibleEvents: EventSnapshot<TEvent, TEventId, TResourceId>;
|
|
808
|
+
readonly visibleRange: CalendarVisibleRange<TViewDef["name"]> | null;
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* One calendar root's behavior without a framework. An adapter creates it once per root, feeds it
|
|
812
|
+
* the latest inputs, and calls its effects at the moments their names give:
|
|
813
|
+
*
|
|
814
|
+
* 1. `connect` and `derive` while rendering; both are pure and return memoized values.
|
|
815
|
+
* 2. `commit(model, inputs)` and `connection.binding.attach()` once a render commits, before
|
|
816
|
+
* anything can run a command (React: an insertion effect).
|
|
817
|
+
* 3. `reconcile(model.eventSnapshot)` before the commit paints (React: a layout effect).
|
|
818
|
+
* 4. `reportDiagnostics(model.diagnostics)` and `reportVisibleRange(model.visibleRange)` after it
|
|
819
|
+
* paints, each when its value changes.
|
|
820
|
+
*/
|
|
821
|
+
interface CalendarRuntime<TEvent, TResource, TViewDef extends AnyCalendarViewDefinition, TSelection, TFocus, TEventId extends EventId, TResourceId extends ResourceId> {
|
|
822
|
+
readonly announcements: AnnouncerChannel;
|
|
823
|
+
/** Publishes a committed render: its handlers and controlled slices, its callbacks and model. */
|
|
824
|
+
readonly commit: (model: CalendarRuntimeModel<TEvent, TResource, TViewDef, TSelection, TFocus, TEventId, TResourceId>, inputs: CalendarRuntimeInputs<TEvent, TResource, TViewDef, TSelection, TFocus, TEventId, TResourceId>) => void;
|
|
825
|
+
/** The model of the last committed render, or the first derived one before any commits. */
|
|
826
|
+
readonly committed: () => CalendarRuntimeModel<TEvent, TResource, TViewDef, TSelection, TFocus, TEventId, TResourceId> | undefined;
|
|
827
|
+
/** The store the root reads, bound to its controlled slices; the same object while they hold. */
|
|
828
|
+
readonly connect: (options: CalendarRuntimeConnectOptions<TViewDef["name"], TSelection, TFocus, TResourceId>) => CalendarRuntimeConnection<TViewDef["name"], TSelection, TFocus, TResourceId>;
|
|
829
|
+
/** Derives the root's model, synchronously; parts that hold keep their identity. */
|
|
830
|
+
readonly derive: (inputs: CalendarRuntimeInputs<TEvent, TResource, TViewDef, TSelection, TFocus, TEventId, TResourceId>) => CalendarRuntimeModel<TEvent, TResource, TViewDef, TSelection, TFocus, TEventId, TResourceId>;
|
|
831
|
+
readonly keyboard: KeyboardSessionStore;
|
|
832
|
+
/** Pending changes and the keyboard's preview; the snapshot keeps its identity until either changes. */
|
|
833
|
+
readonly overlay: CalendarStateSource<CalendarRuntimeOverlay<TEventId, TResourceId>>;
|
|
834
|
+
/** The root's pending changes, for an adapter's `useCalendarPendingChanges`. */
|
|
835
|
+
readonly pendingChanges: CalendarStateSource<CalendarPendingChanges<TEvent, TEventId, TResourceId>>;
|
|
836
|
+
readonly pointerDraft: DraftStore;
|
|
837
|
+
/**
|
|
838
|
+
* The model's `proposeEventChange` from the last commit, returning the outcome itself when it
|
|
839
|
+
* is known at once: a policy's synchronous refusal, a synchronous save, or a proposal that can't
|
|
840
|
+
* apply. Otherwise the pending proposal, whose `result` never rejects. The policies run once and
|
|
841
|
+
* `onEventChangeResult` hears every proposal once, when it settles. An agent's step uses it: the
|
|
842
|
+
* bridge reports a returned promise only as pending, and never sees how it ends.
|
|
843
|
+
*/
|
|
844
|
+
readonly proposeNow: (proposal: CalendarEventProposal<TEventId, TResourceId, TEvent>, detail?: CalendarProposalDetail) => CalendarProposalOutcome<TEvent, TEventId, TResourceId>;
|
|
845
|
+
/**
|
|
846
|
+
* The state the latest commands asked for, with the dates its view covers then, before a
|
|
847
|
+
* framework renders it: what an agent reads back in the step after a command. `undefined` before
|
|
848
|
+
* the first derive; `range` is `null` while the view is unregistered.
|
|
849
|
+
*/
|
|
850
|
+
readonly latest: () => {
|
|
851
|
+
readonly range: PlainDateInterval | null;
|
|
852
|
+
readonly state: CalendarPublicState<TViewDef["name"], TSelection, TFocus, TResourceId>;
|
|
853
|
+
} | undefined;
|
|
854
|
+
/** New events confirm resolved changes; call it before the commit that shows them paints. */
|
|
855
|
+
readonly reconcile: (eventSnapshot: EventSnapshot<TEvent, TEventId, TResourceId>) => void;
|
|
856
|
+
/** Calls the committed `onDiagnosticsChange` with `diagnostics`. */
|
|
857
|
+
readonly reportDiagnostics: (diagnostics: readonly CalendarDiagnostic<TEvent, TEventId>[]) => void;
|
|
858
|
+
/**
|
|
859
|
+
* Calls the committed `onVisibleRangeChange` once per visible range: calling it again for the
|
|
860
|
+
* same range, as an effect that runs twice does, reports nothing.
|
|
861
|
+
*/
|
|
862
|
+
readonly reportVisibleRange: (visibleRange: CalendarVisibleRange<TViewDef["name"]> | null) => void;
|
|
863
|
+
readonly transactions: EventTransactions<TEvent, TEventId, TResourceId>;
|
|
864
|
+
readonly views: readonly TViewDef[];
|
|
865
|
+
readonly viewsByName: ReadonlyMap<string, TViewDef>;
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* The store defaults a root's props give, for `connect`'s `defaults`: a default wins over a
|
|
869
|
+
* controlled value, and the first registered view stands in for a missing one.
|
|
870
|
+
*/
|
|
871
|
+
export declare function resolveCalendarStoreDefaults<TView extends string, TSelection, TFocus, TResourceId extends ResourceId>(props: {
|
|
872
|
+
readonly anchorDate?: Temporal.PlainDate;
|
|
873
|
+
readonly defaultAnchorDate?: Temporal.PlainDate;
|
|
874
|
+
readonly defaultExpandedResourceIds?: readonly TResourceId[];
|
|
875
|
+
readonly defaultFocus?: TFocus | null;
|
|
876
|
+
readonly defaultSelection?: TSelection | null;
|
|
877
|
+
readonly defaultTimeZone?: string;
|
|
878
|
+
readonly defaultView?: TView;
|
|
879
|
+
readonly timeZone?: string;
|
|
880
|
+
readonly view?: TView;
|
|
881
|
+
}, views: readonly {
|
|
882
|
+
readonly name: string;
|
|
883
|
+
}[]): CalendarStoreOptions<TView, TSelection, TFocus, TResourceId>;
|
|
884
|
+
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>;
|
|
885
|
+
type AnyRuntime = CalendarRuntime<any, any, any, any, any, any, any>;
|
|
886
|
+
/**
|
|
887
|
+
* A calendar instance's options: the root's runtime, and its six slices as the adapter rendered
|
|
888
|
+
* them, the application's controlled values laid over the calendar store's. The instance holds no
|
|
889
|
+
* state of its own: the store and the application own the slices, and the instance mirrors what
|
|
890
|
+
* the adapter passes in the render that computed it.
|
|
891
|
+
*/
|
|
892
|
+
type CalendarPrimitiveOptions<TView extends string = string, TSelection = CalendarSelection, TFocus = CalendarFocus, TResourceId extends ResourceId = ResourceId> = CalendarPublicState<TView, TSelection, TFocus, TResourceId> & {
|
|
893
|
+
/**
|
|
894
|
+
* Lets an agent delete events. Off by default, since a delete needs a person: an application
|
|
895
|
+
* that turns it on asks one in its bridge's `allow` for each `deleteEvent` step. While it is
|
|
896
|
+
* off, `deleteEvent` isn't among the calendar's actions.
|
|
897
|
+
*/
|
|
898
|
+
readonly allowAgentDelete?: boolean;
|
|
899
|
+
/**
|
|
900
|
+
* Names an event for an agent, in the calendar's items and in `query`. The title with when it
|
|
901
|
+
* happens in ISO 8601 by default, which an agent can read back exactly.
|
|
902
|
+
*/
|
|
903
|
+
readonly formatAgentEventLabel?: (event: CalendarAgentEvent) => string;
|
|
904
|
+
readonly runtime: AnyRuntime;
|
|
905
|
+
};
|
|
906
|
+
/** A range of dates an agent asks for; either end defaults to the visible range's. */
|
|
907
|
+
interface CalendarAgentRange {
|
|
908
|
+
/** An ISO date, exclusive. */
|
|
909
|
+
readonly end?: string;
|
|
910
|
+
/** An ISO date. */
|
|
911
|
+
readonly start?: string;
|
|
912
|
+
}
|
|
913
|
+
/** The event an action acts on, by the ID `listEvents` gives. */
|
|
914
|
+
interface CalendarAgentEventRef {
|
|
915
|
+
readonly eventId: EventId;
|
|
916
|
+
}
|
|
917
|
+
/** What an agent says about an event beside its placement; it reaches the application unvalidated. */
|
|
918
|
+
interface CalendarAgentEventFields {
|
|
919
|
+
/**
|
|
920
|
+
* Anything else the application understands, as JSON, such as a location or a recurrence edit's
|
|
921
|
+
* scope. It reaches policies and `onEventChange` as the proposal detail's `fields`.
|
|
922
|
+
*/
|
|
923
|
+
readonly fields?: Readonly<Record<string, unknown>>;
|
|
924
|
+
/** The event's title, which reaches the application as `fields.title`. */
|
|
925
|
+
readonly title?: string;
|
|
926
|
+
}
|
|
927
|
+
/** A new event: ISO dates for an all-day event, ISO date-times for a timed one. */
|
|
928
|
+
interface CalendarAgentCreateInput extends CalendarAgentEventFields {
|
|
929
|
+
readonly end: string;
|
|
930
|
+
readonly resourceIds?: readonly ResourceId[];
|
|
931
|
+
readonly start: string;
|
|
932
|
+
}
|
|
933
|
+
/** An event's new start, keeping its length unless `end` is given, and its new resources. */
|
|
934
|
+
interface CalendarAgentMoveInput extends CalendarAgentEventRef {
|
|
935
|
+
readonly end?: string;
|
|
936
|
+
readonly resourceIds?: readonly ResourceId[];
|
|
937
|
+
readonly start: string;
|
|
938
|
+
}
|
|
939
|
+
/** An event's new start or new end, one of the two. */
|
|
940
|
+
interface CalendarAgentResizeInput extends CalendarAgentEventRef {
|
|
941
|
+
readonly end?: string;
|
|
942
|
+
readonly start?: string;
|
|
943
|
+
}
|
|
944
|
+
/** Changes to an event: its fields, its placement, or both, as one `"update"`. */
|
|
945
|
+
interface CalendarAgentUpdateInput extends CalendarAgentEventRef, CalendarAgentEventFields {
|
|
946
|
+
readonly end?: string;
|
|
947
|
+
readonly resourceIds?: readonly ResourceId[];
|
|
948
|
+
readonly start?: string;
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* Where a change an agent proposed is: still `validating` or `saving`, `saved`, or `rejected` with
|
|
952
|
+
* its reason. A step returns it at once, and `getChange` reads it again later by `changeId`.
|
|
953
|
+
*/
|
|
954
|
+
interface CalendarAgentChange {
|
|
955
|
+
readonly cause: CalendarChangeCause;
|
|
956
|
+
readonly changeId: string;
|
|
957
|
+
/** `null` for a new event, whose ID the application gives it when it saves it. */
|
|
958
|
+
readonly eventId: EventId | null;
|
|
959
|
+
/** Where the event would land, in `listEvents`' terms; `null` for a delete. */
|
|
960
|
+
readonly proposed: CalendarAgentPlacement | null;
|
|
961
|
+
readonly reason?: string;
|
|
962
|
+
readonly status: "rejected" | "saved" | "saving" | "validating";
|
|
963
|
+
}
|
|
964
|
+
/** The calendar as `describeCalendar` returns it: what an agent needs before it acts. */
|
|
965
|
+
interface CalendarAgentDescription {
|
|
966
|
+
/** The actions the calendar takes now, each with the one JSON object it takes. */
|
|
967
|
+
readonly actions: Readonly<Record<string, string>>;
|
|
968
|
+
readonly anchorDate: string;
|
|
969
|
+
/** Whether `deleteEvent` is among the actions. */
|
|
970
|
+
readonly canDelete: boolean;
|
|
971
|
+
/** How the calendar's dates and times read, for an agent that has no other description. */
|
|
972
|
+
readonly conventions: string;
|
|
973
|
+
readonly locale: string;
|
|
974
|
+
/** The current time in the calendar's time zone, ISO 8601 with its offset. */
|
|
975
|
+
readonly now: string;
|
|
976
|
+
/** Changes still being decided or saved, a person's and an agent's. */
|
|
977
|
+
readonly pendingChanges: readonly CalendarAgentChange[];
|
|
978
|
+
/** The calendar takes no event changes: it has no `onEventChange`. */
|
|
979
|
+
readonly readOnly: boolean;
|
|
980
|
+
readonly resources: readonly {
|
|
981
|
+
readonly id: ResourceId;
|
|
982
|
+
readonly parentId: ResourceId | null;
|
|
983
|
+
readonly title: string;
|
|
984
|
+
}[];
|
|
985
|
+
readonly selectedEventId: EventId | null;
|
|
986
|
+
readonly timeZone: string;
|
|
987
|
+
readonly today: string;
|
|
988
|
+
readonly view: string;
|
|
989
|
+
readonly views: readonly string[];
|
|
990
|
+
/** The visible dates, `end` exclusive; `null` while the view is unregistered. */
|
|
991
|
+
readonly visibleRange: {
|
|
992
|
+
readonly end: string;
|
|
993
|
+
readonly start: string;
|
|
994
|
+
} | null;
|
|
995
|
+
}
|
|
996
|
+
/**
|
|
997
|
+
* The actions an AI agent calls through ui-sdk's agent bridge. Each takes nothing or one JSON
|
|
998
|
+
* object and checks it, failing with what it expected. The reads return JSON; a change returns
|
|
999
|
+
* where it is at once, as the bridge reports a returned promise only as pending. The event
|
|
1000
|
+
* changes are absent while the root is read-only, and `deleteEvent` unless the root allows it.
|
|
1001
|
+
*/
|
|
1002
|
+
interface CalendarAgentApi<TView extends string = string> {
|
|
1003
|
+
/** Proposes a new event, as the agent. */
|
|
1004
|
+
readonly createEvent?: (input: CalendarAgentCreateInput) => CalendarAgentChange;
|
|
1005
|
+
/** Proposes deleting an event, as the agent; only where the root sets `allowAgentDelete`. */
|
|
1006
|
+
readonly deleteEvent?: (input: CalendarAgentEventRef) => CalendarAgentChange;
|
|
1007
|
+
/** Today, the time zone, the views, the visible range, what the calendar takes now. */
|
|
1008
|
+
describeCalendar(): CalendarAgentDescription;
|
|
1009
|
+
/** Where a change the agent proposed is now, by the `changeId` its step returned. */
|
|
1010
|
+
getChange(input: {
|
|
1011
|
+
readonly changeId: string;
|
|
1012
|
+
}): CalendarAgentChange;
|
|
1013
|
+
/** Shows the dates around `date`, an ISO date such as `"2026-03-14"`. */
|
|
1014
|
+
goToDate(input: {
|
|
1015
|
+
readonly date: string;
|
|
1016
|
+
}): void;
|
|
1017
|
+
/** The events in a range of dates, the visible range by default, as JSON. */
|
|
1018
|
+
listEvents(input?: CalendarAgentRange): readonly CalendarAgentEvent[];
|
|
1019
|
+
/** Proposes moving an event, as the agent. */
|
|
1020
|
+
readonly moveEvent?: (input: CalendarAgentMoveInput) => CalendarAgentChange;
|
|
1021
|
+
navigateNext(): void;
|
|
1022
|
+
navigatePrevious(): void;
|
|
1023
|
+
navigateToday(): void;
|
|
1024
|
+
/** Proposes a new start or end for an event, as the agent. */
|
|
1025
|
+
readonly resizeEvent?: (input: CalendarAgentResizeInput) => CalendarAgentChange;
|
|
1026
|
+
/** Selects an event, or clears the selection with `null`. */
|
|
1027
|
+
selectEvent(input: {
|
|
1028
|
+
readonly eventId: EventId | null;
|
|
1029
|
+
}): void;
|
|
1030
|
+
/** Shows the dates in `timeZone`, an IANA name such as `"Europe/Berlin"`. */
|
|
1031
|
+
setTimeZone(input: {
|
|
1032
|
+
readonly timeZone: string;
|
|
1033
|
+
}): void;
|
|
1034
|
+
/** Switches to a registered view; any other name fails with the list of views. */
|
|
1035
|
+
setView(input: {
|
|
1036
|
+
readonly view: TView;
|
|
1037
|
+
}): void;
|
|
1038
|
+
/** Proposes changes to an event's fields, its placement or both, as the agent. */
|
|
1039
|
+
readonly updateEvent?: (input: CalendarAgentUpdateInput) => CalendarAgentChange;
|
|
1040
|
+
}
|
|
1041
|
+
/**
|
|
1042
|
+
* What the calendar's parts and its agent call. The agent's actions attribute themselves to the
|
|
1043
|
+
* agent; the parts' commands pass on the event and reason of the press that ran them.
|
|
1044
|
+
*/
|
|
1045
|
+
interface CalendarPrimitiveApi<TView extends string = string> extends CalendarAgentApi<TView> {
|
|
1046
|
+
/** A previous, next or today trigger's command. */
|
|
1047
|
+
showNext(options?: CalendarCommandOptions): void;
|
|
1048
|
+
showPrevious(options?: CalendarCommandOptions): void;
|
|
1049
|
+
showToday(options?: CalendarCommandOptions): void;
|
|
1050
|
+
/**
|
|
1051
|
+
* Switches to the registered view named `view`, as a view switcher does when its value changes;
|
|
1052
|
+
* any other value, as a stale option's, changes nothing. Returns whether it asked for the view.
|
|
1053
|
+
*/
|
|
1054
|
+
selectView(view: string, options?: CalendarCommandOptions): boolean;
|
|
1055
|
+
/** The names of the registered views. */
|
|
1056
|
+
viewNames(): readonly TView[];
|
|
1057
|
+
/** The events the active view shows, as `{ value: id, label }`, the agent's items. */
|
|
1058
|
+
visibleEvents(): readonly CalendarAgentItem[];
|
|
1059
|
+
}
|
|
1060
|
+
/** The calendar's structural parts, each a slot of its primitive. */
|
|
1061
|
+
type CalendarSlotName = "next-trigger" | "previous-trigger" | "root" | "title" | "today-trigger" | "toolbar" | "view-switcher" | "viewport";
|
|
1062
|
+
type CalendarSlots<TView extends string, TSelection, TFocus, TResourceId extends ResourceId> = Record<CalendarSlotName, SlotDefinition<CalendarPublicState<TView, TSelection, TFocus, TResourceId>, CalendarPrimitiveApi<TView>, object>>;
|
|
1063
|
+
/** An instance of the calendar primitive, as an adapter creates and drives it. */
|
|
1064
|
+
interface CalendarPrimitiveInstance<TView extends string = string, TSelection = CalendarSelection, TFocus = CalendarFocus, TResourceId extends ResourceId = ResourceId> extends PrimitiveInstance {
|
|
1065
|
+
readonly api: CalendarPrimitiveApi<TView>;
|
|
1066
|
+
readonly get: () => CalendarPublicState<TView, TSelection, TFocus, TResourceId>;
|
|
1067
|
+
readonly types: {
|
|
1068
|
+
readonly api: CalendarPrimitiveApi<TView>;
|
|
1069
|
+
readonly options: CalendarPrimitiveOptions<TView, TSelection, TFocus, TResourceId>;
|
|
1070
|
+
readonly slots: CalendarSlots<TView, TSelection, TFocus, TResourceId>;
|
|
1071
|
+
readonly state: CalendarPublicState<TView, TSelection, TFocus, TResourceId>;
|
|
1072
|
+
};
|
|
1073
|
+
}
|
|
1074
|
+
/**
|
|
1075
|
+
* A calendar's ui-sdk primitive, as `createCalendarPrimitive` returns it: what a renderer's
|
|
1076
|
+
* `usePrimitive` and `usePart`, or a test's `mount`, take. Declared here rather than inferred, so
|
|
1077
|
+
* the calendar's types don't print ui-sdk's internals.
|
|
1078
|
+
*/
|
|
1079
|
+
type CalendarPrimitive<TView extends string = string, TSelection = CalendarSelection, TFocus = CalendarFocus, TResourceId extends ResourceId = ResourceId> = ((initialOptions: CalendarPrimitiveOptions<TView, TSelection, TFocus, TResourceId> & {
|
|
1080
|
+
readonly id: string;
|
|
1081
|
+
}) => CalendarPrimitiveInstance<TView, TSelection, TFocus, TResourceId>) & {
|
|
1082
|
+
readonly options: Record<string, PropSpec> | undefined;
|
|
1083
|
+
readonly slots: CalendarSlots<TView, TSelection, TFocus, TResourceId>;
|
|
1084
|
+
};
|
|
1085
|
+
/** What a calendar primitive is made from. */
|
|
1086
|
+
interface CalendarPrimitiveConfig<TViewDef extends AnyCalendarViewDefinition> {
|
|
1087
|
+
readonly views: readonly TViewDef[];
|
|
1088
|
+
}
|
|
1089
|
+
/** The methods an agent may call, with JSON arguments. */
|
|
1090
|
+
export declare const calendarAgentActions: readonly (keyof CalendarAgentApi)[];
|
|
1091
|
+
/**
|
|
1092
|
+
* Defines a calendar's ui-sdk primitive: the six state slices as always-controlled keys, the
|
|
1093
|
+
* semantic commands as its api, its chrome as slots, and what an AI agent may see and do. The
|
|
1094
|
+
* slices live in the calendar store and the application's props; the instance is a projection of
|
|
1095
|
+
* them for parts and agents, and every change goes through the root's store, which tells the
|
|
1096
|
+
* application's handlers.
|
|
1097
|
+
*/
|
|
1098
|
+
export declare function createCalendarPrimitive<TViewDef extends AnyCalendarViewDefinition, TSelection = CalendarSelection, TFocus = CalendarFocus, TResourceId extends ResourceId = ResourceId>(config: CalendarPrimitiveConfig<TViewDef>): CalendarPrimitive<TViewDef["name"], TSelection, TFocus, TResourceId>;
|
|
1099
|
+
/** Reports an application callback's error without failing what it was told about. */
|
|
1100
|
+
export declare function reportCallbackError(error: unknown): void;
|
|
1101
|
+
/**
|
|
1102
|
+
* One resource's expansion commands. Each reads what caused it from its argument: a DOM event,
|
|
1103
|
+
* which `onExpandedResourceIdsChange` hears with the reason `"resource-toggle"`, or a command's
|
|
1104
|
+
* options, `"resource-toggle"` unless they give another reason. Any other value is ignored, so a
|
|
1105
|
+
* command fits a callback that passes something else, as a switch's change handler passes a
|
|
1106
|
+
* boolean.
|
|
1107
|
+
*/
|
|
1108
|
+
interface CalendarResourceExpansionCommands {
|
|
1109
|
+
readonly collapse: (cause?: unknown) => void;
|
|
1110
|
+
readonly expand: (cause?: unknown) => void;
|
|
1111
|
+
readonly toggle: (cause?: unknown) => void;
|
|
1112
|
+
}
|
|
1113
|
+
/**
|
|
1114
|
+
* Expands and collapses `resourceId` through the root's `expandedResourceIds`. Each command reads
|
|
1115
|
+
* the latest requested state, so consecutive commands in one handler compose, and one that would
|
|
1116
|
+
* change nothing asks nothing.
|
|
1117
|
+
*/
|
|
1118
|
+
export declare function createResourceExpansionCommands({ actions, read }: Pick<CalendarInteractionRuntime, "actions" | "read">, resourceId: ResourceId): CalendarResourceExpansionCommands;
|
|
1119
|
+
/** A resource's status, with the events in progress as the root's snapshot has them. */
|
|
1120
|
+
type CalendarResourceStatus = ResourceStatus<NormalizedCalendarEvent<unknown, EventId, ResourceId>>;
|
|
1121
|
+
/**
|
|
1122
|
+
* A resource's status on a root's clock, as a store: `compute` (usually `resourceStatusAt` with
|
|
1123
|
+
* the root's availability and events) runs when the status next changes, and every minute in case
|
|
1124
|
+
* the clock jumps, and subscribers hear only when the status differs. One timer serves every
|
|
1125
|
+
* subscriber: it starts with the first and stops with the last. Each new subscription samples
|
|
1126
|
+
* again, so a view revealed after a while shows no stale status, and every subscriber hears it
|
|
1127
|
+
* when that sample differs. Only `source`'s clock is read: a root that fixes `source.now` computes
|
|
1128
|
+
* at it without this store. The server snapshot is `null`, as the server reads no clock.
|
|
1129
|
+
*/
|
|
1130
|
+
export declare function createResourceStatusClock(source: CalendarNowSource | undefined, compute: (at: Temporal.Instant) => CalendarResourceStatus): CalendarStateSource<CalendarResourceStatus | null>;
|
|
1131
|
+
export type { AnnouncerChannel, AnnouncerLiveText, AnyCalendarState, AnyCalendarViewDefinition, AnyPendingChanges, BusyRange, CalendarActions, CalendarActiveView, CalendarAgentApi, CalendarAgentChange, CalendarAgentCreateInput, CalendarAgentDescription, CalendarAgentEvent, CalendarAgentEventFields, CalendarAgentEventRef, CalendarAgentItem, CalendarAgentMoveInput, CalendarAgentPlacement, CalendarAgentRange, CalendarAgentResizeInput, CalendarAgentUpdateInput, CalendarAnnotations, CalendarBusyResources, CalendarBusyResourcesQuery, CalendarChangeReason, CalendarChangeSource, CalendarClockTicker, CalendarCommandOptions, CalendarControlledState, CalendarDiagnostic, CalendarDraftBusy, CalendarHistory, CalendarHistoryAnnouncementBuilder, CalendarHistoryAnnouncementContext, CalendarHistoryBindingOptions, CalendarHistoryCommandOptions, CalendarHistoryMessages, CalendarHistoryOptions, CalendarHistoryShortcutsConfig, CalendarHistoryShortcutsTarget, CalendarInteractionRuntime, CalendarKeyEventWrapper, CalendarKeyboardController, CalendarKeyboardOptions, CalendarPartIds, CalendarPrimitive, CalendarPrimitiveApi, CalendarPrimitiveConfig, CalendarPrimitiveInstance, CalendarPrimitiveOptions, CalendarPublicState, CalendarRequestListener, CalendarResourceExpansionCommands, CalendarResourceStatus, CalendarRootStore, CalendarRootStoreBinding, CalendarRovingEntry, CalendarRuntime, CalendarRuntimeConfig, CalendarRuntimeConnectOptions, CalendarRuntimeConnection, CalendarRuntimeInputs, CalendarRuntimeModel, CalendarRuntimeOverlay, CalendarSemanticActions, CalendarSlotName, CalendarStateChangeDetail, CalendarStateChangeHandler, CalendarStateChangeHandlers, CalendarStateSelector, CalendarStateSelectorOptions, CalendarStateSlice, CalendarStateSource, CalendarStore, CalendarStoreBinding, CalendarStoreInternals, CalendarStoreOptions, CalendarViewActions, CalendarViewDefinition, CalendarViewOptionsMap, CalendarViewRuntime, CalendarVisibleRange, DraftStore, KeyboardGrab, KeyboardSessionStore, RovingFocusStore };
|