@moltenship/calendar 1.0.0-rc.2 → 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.
- package/README.md +24 -4
- package/dist/index.d.mts +2 -2
- package/docs/accessibility.md +304 -0
- package/docs/agents/changes.md +449 -0
- package/docs/agents/coding-agents.md +117 -0
- package/docs/agents/connect.md +435 -0
- package/docs/agents/deleting.md +296 -0
- package/docs/agents/reference.md +512 -0
- package/docs/agents/server.md +317 -0
- package/docs/agents/webmcp.md +153 -0
- package/docs/agents.md +353 -0
- package/docs/annotations.md +196 -0
- package/docs/api/changes.md +248 -0
- package/docs/api/dnd-kit.md +267 -0
- package/docs/api/events.md +152 -0
- package/docs/api/ics.md +524 -0
- package/docs/api/primitives.md +168 -0
- package/docs/api/react.md +236 -0
- package/docs/api/recurrence.md +586 -0
- package/docs/api/solid.md +460 -0
- package/docs/api/store.md +92 -0
- package/docs/api/temporal.md +172 -0
- package/docs/api.md +57 -0
- package/docs/availability.md +573 -0
- package/docs/comparison.md +279 -0
- package/docs/concepts/anatomy.md +73 -0
- package/docs/concepts/events.md +164 -0
- package/docs/concepts/how-it-works.md +95 -0
- package/docs/concepts/recurrence.md +127 -0
- package/docs/concepts/state.md +244 -0
- package/docs/concepts/time.md +170 -0
- package/docs/guides/dnd-kit.md +333 -0
- package/docs/guides/google-calendar-sync.md +1246 -0
- package/docs/guides/google-calendar.md +367 -0
- package/docs/guides/ics.md +486 -0
- package/docs/guides/motion.md +414 -0
- package/docs/guides/nextjs-app-router.md +630 -0
- package/docs/guides/nextjs.md +149 -0
- package/docs/guides/performance.md +103 -0
- package/docs/guides/recurring-events.md +583 -0
- package/docs/guides/tanstack-query.md +485 -0
- package/docs/index.md +118 -0
- package/docs/installation.md +194 -0
- package/docs/interactions.md +408 -0
- package/docs/llms.txt +86 -0
- package/docs/migrating-to-2.md +322 -0
- package/docs/quick-start.md +159 -0
- package/docs/stylex.md +265 -0
- package/docs/testing.md +581 -0
- package/docs/theme-builder.md +81 -0
- package/docs/theming.md +169 -0
- package/docs/undo-redo.md +339 -0
- package/docs/views/agenda.md +221 -0
- package/docs/views/custom-views.md +192 -0
- package/docs/views/month.md +109 -0
- package/docs/views/resource-columns.md +261 -0
- package/docs/views/resource-timeline.md +225 -0
- package/docs/views/scrolling.md +192 -0
- package/docs/views/week-and-day.md +257 -0
- package/docs/views/year.md +138 -0
- package/docs/views.md +69 -0
- package/package.json +41 -14
- package/skills/moltenship-time/SKILL.md +75 -0
- package/skills/moltenship-time/references/agent-ready.md +272 -0
- package/skills/moltenship-time/references/changes.md +188 -0
- package/skills/moltenship-time/references/compose.md +168 -0
- package/skills/moltenship-time/references/mistakes.md +98 -0
- package/skills/moltenship-time/references/solid.md +202 -0
- package/skills/moltenship-time/references/state.md +129 -0
- package/skills/moltenship-time/references/testing.md +176 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# Primitives
|
|
2
|
+
|
|
3
|
+
The framework-free layer under the React and Solid integrations, the calendar as a ui-sdk primitive, and the types of its agent actions.
|
|
4
|
+
|
|
5
|
+
Source: https://time.molten.sh/docs/api/primitives
|
|
6
|
+
|
|
7
|
+
`@moltenship/calendar-primitives` is the layer between the engine and a framework. It holds what
|
|
8
|
+
`Root` does, with no React or Solid in it: the state store, the runtime that turns events and state
|
|
9
|
+
into what a view draws, and the calendar as a [ui-sdk](https://ui-sdk.dev) primitive, which is what
|
|
10
|
+
an [agent](../agents.md) operates.
|
|
11
|
+
|
|
12
|
+
> **Unsettled API**
|
|
13
|
+
>
|
|
14
|
+
> This package is new in 2.0 and its API can change in any release before 2.0.0. Apps don't need it:
|
|
15
|
+
> `@moltenship/calendar` re-exports the parts an app uses. Install it to write an integration for
|
|
16
|
+
> another framework, or to name the agent types below.
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pnpm add @moltenship/calendar-primitives @ui-sdk/core
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
`@ui-sdk/core` is a peer dependency, from `0.1.0-beta.16` on within the 0.1 line. The package
|
|
25
|
+
imports no UI framework. It needs a runtime with `Temporal`, as the rest of the library does.
|
|
26
|
+
|
|
27
|
+
## Where it sits
|
|
28
|
+
|
|
29
|
+
```text
|
|
30
|
+
@moltenship/calendar-react @moltenship/calendar-solid thin: render parts, bind state
|
|
31
|
+
└──────────────┬──────────────┘
|
|
32
|
+
@moltenship/calendar-primitives runtime, store, primitive, agent actions
|
|
33
|
+
┌──────────────┴──────────────┐
|
|
34
|
+
@moltenship/calendar-core @ui-sdk/core the engine · parts and the agent bridge
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The engine doesn't import ui-sdk, and ui-sdk's own date components aren't used. Dates, time zones,
|
|
38
|
+
recurrence, layouts, transactions and policies are the calendar's own.
|
|
39
|
+
|
|
40
|
+
## What it exports
|
|
41
|
+
|
|
42
|
+
| Export | What it is |
|
|
43
|
+
| ----------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
|
|
44
|
+
| `createCalendarStore(options)` | The store of the six state values. The same one [`@moltenship/calendar` exports](./store.md) |
|
|
45
|
+
| `createCalendarRuntime(config)` | What `Root` runs: event snapshots, pending changes, the active view's projection, the visible range, diagnostics |
|
|
46
|
+
| `createCalendarPrimitive({ views })` | The calendar as a ui-sdk primitive: the six values as controlled keys, slots for the parts, and the agent actions |
|
|
47
|
+
| `calendarAgentActions` | The fifteen action names an agent can call |
|
|
48
|
+
| `calendarStateSlices` | The six state value names |
|
|
49
|
+
| `resolveViewOptions(view, overrides)` | A view's options: its `defaultOptions` with a root's `viewOptions` over them |
|
|
50
|
+
| `createDraftStore()`, `createKeyboardSessionStore()` | The stores behind gesture previews and keyboard grabs |
|
|
51
|
+
| `createAnnouncerChannel(getEnvironment, getResources)` | The channel a live region reads announcements from |
|
|
52
|
+
| `createClockTicker(clock, intervalMs)`, `systemClock`, `clockOf` | The clock a root samples for today and the current time |
|
|
53
|
+
| `eventLabel`, `agentEventLabel`, `visibleEventsOf` | How an agent's items are made: an event's label, the default label of a described event, the events in view |
|
|
54
|
+
| `describeAgentEvent`, `describeAgentPlacement`, `eventsInRange` | An event and a placement as an agent reads them, and the events `listEvents` returns for a range |
|
|
55
|
+
| `findEvent`, `readAgentInput` | An event by the ID an agent sent, and an action's one input object checked against its keys |
|
|
56
|
+
| `parseInstant`, `parsePlainDate`, `parsePlainDateTime`, `parseTimeZone` | How an agent's JSON values are read, with the errors the [reference](../agents/reference.md#errors) lists |
|
|
57
|
+
|
|
58
|
+
It also exports the equality helpers the integrations compare props with (`sameInstant`,
|
|
59
|
+
`samePlainDate`, `sameRange`, `sameWeekRules` and others), `createMemoCell` and `createStableCell`,
|
|
60
|
+
and the state types: `CalendarPublicState`, `CalendarActions`, `CalendarStore`,
|
|
61
|
+
`CalendarStateChangeDetail`, `CalendarChangeReason`, `CalendarChangeSource` and
|
|
62
|
+
`CalendarCommandOptions`.
|
|
63
|
+
|
|
64
|
+
## The primitive
|
|
65
|
+
|
|
66
|
+
`createCalendarPrimitive` defines the calendar for ui-sdk, once per `createCalendar` call. An
|
|
67
|
+
integration renders it with its framework's ui-sdk package, `@ui-sdk/react` or `@ui-sdk/solid`.
|
|
68
|
+
|
|
69
|
+
Its slots are the calendar's structural parts:
|
|
70
|
+
|
|
71
|
+
| Slot | The part in React |
|
|
72
|
+
| ------------------ | -------------------------- |
|
|
73
|
+
| `root` | `Calendar.Frame` |
|
|
74
|
+
| `toolbar` | `Calendar.Toolbar` |
|
|
75
|
+
| `title` | `Calendar.Title` |
|
|
76
|
+
| `previous-trigger` | `Calendar.PreviousTrigger` |
|
|
77
|
+
| `next-trigger` | `Calendar.NextTrigger` |
|
|
78
|
+
| `today-trigger` | `Calendar.TodayTrigger` |
|
|
79
|
+
| `view-switcher` | `Calendar.ViewSwitcher` |
|
|
80
|
+
| `viewport` | `Calendar.Viewport` |
|
|
81
|
+
|
|
82
|
+
Events and cells aren't slots. A view renders them as ordinary elements with the
|
|
83
|
+
[data attributes](../interactions.md#in-your-own-views) the pointer layer reads, so a calendar with
|
|
84
|
+
a thousand events doesn't make a thousand ui-sdk parts.
|
|
85
|
+
|
|
86
|
+
The six state values are always controlled keys of the primitive. The integration merges what the
|
|
87
|
+
app controls with what the calendar store holds, and passes the result in. ui-sdk's own store is a
|
|
88
|
+
copy of that for the parts and for agents, never the owner of a value. That keeps what
|
|
89
|
+
[State](../concepts/state.md) promises: actions in one handler build on each other, and dates
|
|
90
|
+
compare by value.
|
|
91
|
+
|
|
92
|
+
## Agent types
|
|
93
|
+
|
|
94
|
+
The primitive's `api` is what an agent calls. Its TypeScript types are exported for code that
|
|
95
|
+
wraps the bridge:
|
|
96
|
+
|
|
97
|
+
```ts title="agent-actions.ts"
|
|
98
|
+
import {
|
|
99
|
+
calendarAgentActions,
|
|
100
|
+
type CalendarAgentApi,
|
|
101
|
+
type CalendarAgentChange,
|
|
102
|
+
type CalendarAgentEvent,
|
|
103
|
+
type CalendarAgentItem,
|
|
104
|
+
} from "@moltenship/calendar-primitives";
|
|
105
|
+
|
|
106
|
+
// The fifteen action names. A snapshot lists the ones a calendar takes, in alphabetical order.
|
|
107
|
+
export const actionNames: readonly (keyof CalendarAgentApi)[] = calendarAgentActions;
|
|
108
|
+
|
|
109
|
+
// One entry of a calendar's `items`: `{ value, label }`.
|
|
110
|
+
export type VisibleEvent = CalendarAgentItem;
|
|
111
|
+
|
|
112
|
+
// What `listEvents` returns for an event, and what an event action returns.
|
|
113
|
+
export type ListedEvent = CalendarAgentEvent;
|
|
114
|
+
export type ChangeResult = CalendarAgentChange;
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
`CalendarAgentApi` has one method per action. Each takes nothing or one object, which is the one
|
|
118
|
+
argument of an agent's step:
|
|
119
|
+
|
|
120
|
+
| Method | Input | Returns |
|
|
121
|
+
| --------------------------------------------------------- | -------------------------------------------------------------------------------------- | ------------------------------- |
|
|
122
|
+
| `describeCalendar()` | none | `CalendarAgentDescription` |
|
|
123
|
+
| `listEvents(input?)` | `CalendarAgentRange`: `{ start?, end? }` | `readonly CalendarAgentEvent[]` |
|
|
124
|
+
| `getChange(input)` | `{ changeId }` | `CalendarAgentChange` |
|
|
125
|
+
| `navigateNext()`, `navigatePrevious()`, `navigateToday()` | none | nothing |
|
|
126
|
+
| `goToDate(input)` | `{ date }` | nothing |
|
|
127
|
+
| `setView(input)` | `{ view }` | nothing |
|
|
128
|
+
| `setTimeZone(input)` | `{ timeZone }` | nothing |
|
|
129
|
+
| `selectEvent(input)` | `{ eventId }`, or `{ eventId: null }` to clear | nothing |
|
|
130
|
+
| `createEvent(input)` | `CalendarAgentCreateInput`: `{ start, end, title?, resourceIds?, fields? }` | `CalendarAgentChange` |
|
|
131
|
+
| `updateEvent(input)` | `CalendarAgentUpdateInput`: `{ eventId, title?, start?, end?, resourceIds?, fields? }` | `CalendarAgentChange` |
|
|
132
|
+
| `moveEvent(input)` | `CalendarAgentMoveInput`: `{ eventId, start, end?, resourceIds? }` | `CalendarAgentChange` |
|
|
133
|
+
| `resizeEvent(input)` | `CalendarAgentResizeInput`: `{ eventId, start }` or `{ eventId, end }` | `CalendarAgentChange` |
|
|
134
|
+
| `deleteEvent(input)` | `CalendarAgentEventRef`: `{ eventId }` | `CalendarAgentChange` |
|
|
135
|
+
|
|
136
|
+
The five event methods are optional in the type, because a calendar has them only when it can
|
|
137
|
+
take them: `createEvent`, `updateEvent`, `moveEvent` and `resizeEvent` when its root has
|
|
138
|
+
`onEventChange`, and `deleteEvent` when the root also has `allowAgentDelete`. A read-only
|
|
139
|
+
calendar's snapshot doesn't list them.
|
|
140
|
+
|
|
141
|
+
Dates and times are ISO strings in both directions. `CalendarAgentChange` is
|
|
142
|
+
`{ changeId, cause, eventId, proposed, status, reason? }`, with `status` one of `"saved"`,
|
|
143
|
+
`"saving"`, `"validating"` and `"rejected"`.
|
|
144
|
+
|
|
145
|
+
The types say what a well-formed call sends. A model can send anything, so the calendar checks
|
|
146
|
+
the input when the step runs, and fails the step with a message that names the action's input.
|
|
147
|
+
The [agent reference](../agents/reference.md) has every input, result and error.
|
|
148
|
+
|
|
149
|
+
An app doesn't call these methods. An agent calls them by name through the bridge, where your
|
|
150
|
+
`allow` decides first.
|
|
151
|
+
|
|
152
|
+
## Writing an integration
|
|
153
|
+
|
|
154
|
+
`@moltenship/calendar-solid` is the model to read: it's the smaller of the two. An integration
|
|
155
|
+
does four things:
|
|
156
|
+
|
|
157
|
+
1. Creates the runtime and the primitive in its factory, as `createCalendar` does.
|
|
158
|
+
2. In its `Root`, connects the runtime to a store (`runtime.connect`), merges controlled state, and
|
|
159
|
+
calls `runtime.derive(inputs)` in the framework's reactive idiom. `derive` is synchronous and
|
|
160
|
+
memoized per root.
|
|
161
|
+
3. Renders the primitive's slots as parts through the framework's ui-sdk package.
|
|
162
|
+
4. Passes the model to custom views and hooks through a context of its own.
|
|
163
|
+
|
|
164
|
+
The keyboard session, the gesture drafts and the announcer channel are shared from here as stores
|
|
165
|
+
and plain functions. The pointer layer is `@moltenship/calendar-dnd`.
|
|
166
|
+
|
|
167
|
+
There's no guide beyond this page yet, and the runtime's types change as the Solid integration
|
|
168
|
+
grows. If you plan an integration, open an issue first.
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# React components and hooks
|
|
2
|
+
|
|
3
|
+
createCalendar, Root and its props, the components, hooks, meta, and diagnostics.
|
|
4
|
+
|
|
5
|
+
Source: https://time.molten.sh/docs/api/react
|
|
6
|
+
|
|
7
|
+
Everything on this page is exported from `@moltenship/calendar`.
|
|
8
|
+
|
|
9
|
+
## createCalendar
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
const Calendar = createCalendar<TEvent, TResource, TSelection, TFocus>()(options);
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Creates a calendar: a set of components and hooks typed to your records. Call it once at module
|
|
16
|
+
scope. It's called twice: the first call takes your types, and the second infers the view names
|
|
17
|
+
from `views` and the ID types from the adapter.
|
|
18
|
+
|
|
19
|
+
- `TEvent`: your event record. Required.
|
|
20
|
+
- `TResource`: your resource record. Defaults to `unknown`; use `never` if you don't have resources.
|
|
21
|
+
- `TSelection`, `TFocus`: the types of the `selection` and `focus` state. Default to
|
|
22
|
+
`CalendarSelection` and `CalendarFocus`, the days, slots, and events the built-in views read and
|
|
23
|
+
write. A calendar with only custom views can use its own types.
|
|
24
|
+
|
|
25
|
+
| Name | Type | Default | Description |
|
|
26
|
+
| -------------------- | ------------------------------ | ------------------- | ------------------------------------------------------------------------------------------ |
|
|
27
|
+
| `eventAdapter` | `EventAdapter<TEvent>` | | Required. How to read your records. See [adapter](./events.md#adapter). |
|
|
28
|
+
| `views` | `readonly CalendarView[]` | | Views made with `defineCalendarView`. The first is the default view. Names must be unique. |
|
|
29
|
+
| `invalidEventPolicy` | `"report-and-skip" \| "throw"` | `"report-and-skip"` | What to do with invalid records. |
|
|
30
|
+
|
|
31
|
+
The returned object holds the components and hooks below, plus `views`, the list you passed in.
|
|
32
|
+
Use it to derive the view-name type: `(typeof Calendar.views)[number]["name"]`.
|
|
33
|
+
|
|
34
|
+
## defineCalendarView
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
const view = defineCalendarView({ name, defaultOptions, strategy, Renderer });
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Defines a view. `defaultOptions` is required only when the strategy's options can't be `undefined`.
|
|
41
|
+
[Custom views](../views/custom-views.md) covers the strategy, the projection input, and the
|
|
42
|
+
Renderer props. The related types are `CalendarViewStrategy`, `CalendarViewProjectionInput`, and
|
|
43
|
+
`CalendarViewRendererProps`.
|
|
44
|
+
|
|
45
|
+
`resolveViewInstantRange(range, timeZone)` turns visible dates into the instant range that `Root`
|
|
46
|
+
passes to `project` as `instantRange`, and `resolveViewLoadRange(strategy, anchor, environment,
|
|
47
|
+
options, range)` gives the `loadRange` it passes. Use them to run a strategy outside React, for
|
|
48
|
+
example in a test.
|
|
49
|
+
|
|
50
|
+
`withAsciiSpaces(text)` writes the thin and narrow no-break spaces in `Intl` output as plain spaces.
|
|
51
|
+
Node.js and browsers disagree on them in date ranges, so wrap `formatRange` output that renders on
|
|
52
|
+
the server, as the built-in titles and views do, and hydration matches.
|
|
53
|
+
|
|
54
|
+
## Root
|
|
55
|
+
|
|
56
|
+
`<Calendar.Root>` holds the state and provides it to everything inside. It renders no element of its
|
|
57
|
+
own.
|
|
58
|
+
|
|
59
|
+
| Name | Type | Default | Description |
|
|
60
|
+
| -------------------------------------------------- | ------------------------------------------------------------- | --------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
61
|
+
| `events` | `readonly TEvent[] \| CalendarEventSource<TEvent>` | | Required. Your events. A new array holding the same records is treated as unchanged. A source is an external store `Root` subscribes to; see [events from an external store](../concepts/events.md#events-from-an-external-store). |
|
|
62
|
+
| `locale` | `Intl.Locale \| string` | | Required. Used by views to format dates and times. |
|
|
63
|
+
| `weekRules` | `CalendarWeekRules` | | Required. `{ firstDay, minimalDays, weekend }`, with days numbered 1 (Monday) to 7 (Sunday). `minimalDays` is the minimum number of days in the first week of a year. |
|
|
64
|
+
| `defaultAnchorDate` | `Temporal.PlainDate` | | Initial date, uncontrolled. Pass this or `anchorDate`. |
|
|
65
|
+
| `anchorDate` | `Temporal.PlainDate` | | Controlled date. |
|
|
66
|
+
| `defaultTimeZone` | `string` | | Initial IANA time zone, uncontrolled. Pass this or `timeZone`. |
|
|
67
|
+
| `timeZone` | `string` | | Controlled time zone. |
|
|
68
|
+
| `secondaryTimeZones` | `readonly (string \| { timeZone: string; label?: string })[]` | `[]` | Other IANA time zones that time grids label their hours in, beside the calendar's. A `label` names a zone in the header. Invalid entries are left out and reported as diagnostics. See [secondary time zones](../concepts/time.md#secondary-time-zones). |
|
|
69
|
+
| `defaultView` | `view name` | `the first registered view` | Initial view, uncontrolled. |
|
|
70
|
+
| `view` | `view name` | | Controlled view. |
|
|
71
|
+
| `viewOptions` | `{ [view]: Partial<options> }` | | Overrides for each view's `defaultOptions`, keyed by view name. |
|
|
72
|
+
| `defaultSelection / selection` | `TSelection \| null` | | Uncontrolled or controlled selection. |
|
|
73
|
+
| `defaultFocus / focus` | `TFocus \| null` | | Uncontrolled or controlled focus. |
|
|
74
|
+
| `defaultExpandedResourceIds / expandedResourceIds` | `readonly TResourceId[]` | | Uncontrolled or controlled expanded resources. |
|
|
75
|
+
| `onViewChange, onAnchorDateChange, …` | `(next, detail) => void` | | One handler per value. `detail` has `previous`, `controlled`, `slice`, why it changed (`reason`), who caused it (`source`, `"agent"` for an AI agent), the DOM `event` and `cancel()`. See [what a handler hears](../concepts/state.md#what-a-handler-hears). |
|
|
76
|
+
| `onEventChange` | `(change, detail) => void \| Promise<void>` | | Saves a proposed change. Return a promise to keep it pending until it settles. Without it the calendar is read-only. `detail.input` says what proposed it, as for `onEventChangeResult`, and `detail.fields` has what an agent sent beside the times, such as a title. See [Interactions](../interactions.md) and [saving what an agent sent](../agents/connect.md#save-what-the-agent-sent). |
|
|
77
|
+
| `onEventChangeResult` | `(result, detail) => void` | | Hears how each proposal ended, once it settles: the result `proposeEventChange` resolves with, and the detail it was proposed with, whose `input` is `"pointer"`, `"keyboard"`, `"api"` or `"agent"`. Pass an event history's `record` here to [undo and redo](../undo-redo.md). See [how changes end](../interactions.md#how-changes-end). |
|
|
78
|
+
| `policies` | `readonly CalendarPolicy[]` | | Run in order on every proposed change, after the built-in read-only check. See [policies](./changes.md#policies). |
|
|
79
|
+
| `resources` | `readonly TResource[]` | `[]` | Rooms, people, or anything else events are assigned to. |
|
|
80
|
+
| `availability` | `CalendarAvailability` | | Working hours: `weekly` rules, dated `exceptions`, and an optional `timeZone`. Views shade the closed time. See [Availability](../availability.md). |
|
|
81
|
+
| `annotations` | `readonly CalendarAnnotation[]` | `[]` | Read-only marks beside the events, such as sleep or music. See [Annotations](../annotations.md). |
|
|
82
|
+
| `annotationSources` | `readonly CalendarAnnotationSource[]` | `[]` | The annotation sources, in display order. A source left out is hidden. |
|
|
83
|
+
| `now` | `Temporal.Instant` | | Fixes the current time, so server and browser agree. Pass `now` or `clock`, not both. |
|
|
84
|
+
| `clock` | `{ instant(): Temporal.Instant }` | | A source of the current time. Without now or clock, Time uses the system clock. |
|
|
85
|
+
| `direction` | `"ltr" \| "rtl"` | `"ltr"` | Which way the arrow keys move, and which way the resource and scrolling views scroll sideways; the resource timeline and scrolling week and day also set `dir` on their grid from it. `Root` doesn't set `dir` itself: set it on an ancestor to match; see [right-to-left](../accessibility.md#right-to-left). |
|
|
86
|
+
| `disambiguation` | `"compatible" \| "earlier" \| "later" \| "reject"` | `"compatible"` | Given to views as `environment.disambiguation`, for your own views to resolve skipped or repeated wall-clock times, and used for the wall-clock times an [agent](../agents/reference.md#events) sends. The built-in views and interactions don't read it. See [daylight saving time](../concepts/time.md#daylight-saving-time). |
|
|
87
|
+
| `onVisibleRangeChange` | `(range: CalendarVisibleRange) => void` | | Called after mount and whenever the active view, its dates, or the time zone change, with the visible `range` and the `loadRange` to have events for. Each change is reported once, also under Strict Mode or when a hidden `Activity` is revealed, and never on the server. See [loading events](../views/scrolling.md#loading-events-as-you-scroll) and [TanStack Query](../guides/tanstack-query.md). |
|
|
88
|
+
| `onDiagnosticsChange` | `(diagnostics) => void` | | Called after mount and whenever the [diagnostics](#diagnostics) change. |
|
|
89
|
+
| `id` | `string` | `derived from useId()` | Base for element IDs, such as `{id}-frame`. |
|
|
90
|
+
| `label` | `string` | | The calendar's name, such as `"Team calendar"`. `Frame` takes it as its `aria-label`, so screen readers and [AI agents](../agents/connect.md#name-the-calendar) find the calendar by a name that stays the same while it navigates. Without it, the frame is labelled by the title. |
|
|
91
|
+
| `allowAgentDelete` | `boolean` | `false` | Gives an AI agent the `deleteEvent` action. Without it the calendar has no such action, a step that asks for it fails, and a delete an agent causes another way, such as by pressing a button of yours, is refused. Turn it on only with an agent bridge that asks a person first. See [Deleting](../agents/deleting.md). |
|
|
92
|
+
| `formatAgentEventLabel` | `(event: CalendarAgentEvent) => string` | | Names each visible event in the list an AI agent reads. By default the title and the times in ISO 8601 in the calendar's time zone. See the [agent reference](../agents/reference.md#snapshot-entry). |
|
|
93
|
+
| `store` | `CalendarStore` | | Use a store you created. See [State store](./store.md). |
|
|
94
|
+
|
|
95
|
+
You can write most props inline. `locale`, `weekRules`, `secondaryTimeZones`, `availability`, `now`,
|
|
96
|
+
and a controlled `anchorDate`, `timeZone` or `view` are compared by value; `events`, `resources`,
|
|
97
|
+
`annotations`, `annotationSources` and a controlled `expandedResourceIds` are compared item by item;
|
|
98
|
+
`policies`, `onDiagnosticsChange`, and the change handlers are read from the latest render.
|
|
99
|
+
`viewOptions` is too, but the active view's options are compared one option at a time, so keep
|
|
100
|
+
functions and objects in them stable. A
|
|
101
|
+
`clock` object and a controlled `selection` or `focus` are compared by identity: keep them stable,
|
|
102
|
+
for example in state or at module scope.
|
|
103
|
+
|
|
104
|
+
`Root` throws on its first render if it has no date (`calendar-root-requires-anchor-date`), no
|
|
105
|
+
time zone (`calendar-root-requires-time-zone`), or no view (`calendar-root-requires-view`).
|
|
106
|
+
|
|
107
|
+
## Components
|
|
108
|
+
|
|
109
|
+
Use these inside `Root`. Each renders one plain element with a `data-calendar-part` attribute and
|
|
110
|
+
accepts that element's usual props, including `className`, `style`, `ref`, and event handlers.
|
|
111
|
+
|
|
112
|
+
| Component | Renders | Notes |
|
|
113
|
+
| ----------------- | ----------- | ----------------------------------------------------------------------------------------- |
|
|
114
|
+
| `Frame` | `<section>` | Outer wrapper. Gets the `{id}-frame` ID, and its name from `Root`'s `label` or the title. |
|
|
115
|
+
| `Toolbar` | `<header>` | Wrapper for controls. |
|
|
116
|
+
| `Title` | `<span>` | The active view's title, or its children. Gets the `{id}-title` ID. |
|
|
117
|
+
| `PreviousTrigger` | `<button>` | Moves back one step of the active view. Disabled when no view is active. |
|
|
118
|
+
| `NextTrigger` | `<button>` | Moves forward one step of the active view. Disabled when no view is active. |
|
|
119
|
+
| `TodayTrigger` | `<button>` | Moves to today in the calendar's time zone, from `now`, `clock`, or the system clock. |
|
|
120
|
+
| `ViewSwitcher` | `<select>` | One option per view. Requires `getViewLabel(name)`. |
|
|
121
|
+
| `Viewport` | `<div>` | Wrapper for the view. Gets the `{id}-viewport` ID. |
|
|
122
|
+
| `ActiveView` | view output | Renders the active view, or `fallback` if it isn't registered. |
|
|
123
|
+
| `Event` | your output | Looks up one event by `eventId` and calls `children` with it. |
|
|
124
|
+
| `Announcer` | `<div>` | A hidden live region that speaks moves, resizes, and creates. Requires `messages`. |
|
|
125
|
+
|
|
126
|
+
- The buttons default to `type="button"` and set `aria-controls` to the viewport. Give each one
|
|
127
|
+
text or an `aria-label`.
|
|
128
|
+
- Your `onClick` or `onChange` runs first. Call `event.preventDefault()` in it to skip the built-in
|
|
129
|
+
action.
|
|
130
|
+
- `Frame`, `Title`, and `Viewport` don't accept `id`. Set `id` on `Root` instead, so the IDs and
|
|
131
|
+
`aria-controls` always match.
|
|
132
|
+
- The parts are [ui-sdk](https://ui-sdk.dev) components, which is how an
|
|
133
|
+
[agent bridge](../agents/connect.md) finds a calendar. A calendar is listed for agents only when
|
|
134
|
+
it renders `Frame`. Events and cells stay elements your views render.
|
|
135
|
+
|
|
136
|
+
`Event` passes your record and its normalized form:
|
|
137
|
+
|
|
138
|
+
```tsx
|
|
139
|
+
<Calendar.Event eventId="standup" fallback={<p>Not found</p>}>
|
|
140
|
+
{({ event, normalized }) => (
|
|
141
|
+
<p>
|
|
142
|
+
{event.title} starts at {normalized.start.toString()}
|
|
143
|
+
</p>
|
|
144
|
+
)}
|
|
145
|
+
</Calendar.Event>
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Hooks
|
|
149
|
+
|
|
150
|
+
The hooks on your calendar work anywhere inside its `Root`. Using them, or any component above,
|
|
151
|
+
outside `Root` throws `calendar-hook-outside-root`.
|
|
152
|
+
|
|
153
|
+
| Hook | Returns |
|
|
154
|
+
| --------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
|
|
155
|
+
| `useCalendar()` | `{ state, actions, meta }` |
|
|
156
|
+
| `useCalendarState()` | The six [state](../concepts/state.md) values |
|
|
157
|
+
| `useCalendarActions()` | The actions below. The object never changes. |
|
|
158
|
+
| `useCalendarMeta()` | The [meta](#meta) object |
|
|
159
|
+
| `useCalendarSelector(selector, opts?)` | `selector(state)`. Re-renders only when it changes. |
|
|
160
|
+
| `useCalendarPendingChanges(selector?, opts?)` | The changes still on their way, or `selector(changes)`. See [pending changes](../interactions.md#across-the-calendar). |
|
|
161
|
+
| `useVisibleRange()` | The active view's visible dates, or `null` |
|
|
162
|
+
| `useViewProjection()` | The active view and its projection, or `null` |
|
|
163
|
+
|
|
164
|
+
`useCalendarSelector` and `useCalendarPendingChanges` compare results with `Object.is`. Pass
|
|
165
|
+
`{ isEqual }` to compare another way. The selector can be an inline function.
|
|
166
|
+
|
|
167
|
+
`useCalendarHistory(history, { messages? })` is exported on its own too. It binds an event history
|
|
168
|
+
to the nearest `Root`, with `undo`, `redo`, `canUndo` and `canRedo`, and
|
|
169
|
+
`useCalendarHistoryShortcuts(history, { scope, undo?, redo?, disabled? })` adds its keys; see
|
|
170
|
+
[Undo and redo](../undo-redo.md).
|
|
171
|
+
|
|
172
|
+
`Announcer`'s messages, and the keyboard hooks for your own views (`useCalendarKeyboard`,
|
|
173
|
+
`useRovingFocus`, `useCalendarInteraction`, `useCalendarAnnouncer`), are covered in
|
|
174
|
+
[Accessibility](../accessibility.md#announcements).
|
|
175
|
+
|
|
176
|
+
`useNow({ intervalMs })` is exported on its own, not from your calendar. It returns the current
|
|
177
|
+
instant from the nearest `Root`'s `now` or `clock`, or the system clock, and samples it every
|
|
178
|
+
`intervalMs` (one minute by default). It returns `null` during server rendering and hydration unless
|
|
179
|
+
`Root` has `now`.
|
|
180
|
+
|
|
181
|
+
`useAnchorDateRequests(listener)` calls `listener(date, range)` with every date the calendar is
|
|
182
|
+
asked to show: from Previous, Next, Today, keys paging past the view, or `setAnchorDate`. That
|
|
183
|
+
includes a date that is already the anchor. `range` holds the dates the active view shows for
|
|
184
|
+
`date`, so a week view can tell Today inside its week from a date that moves it. A view whose
|
|
185
|
+
scroll position can run ahead of the anchor uses it to show its range again when Today asks for
|
|
186
|
+
it. The [scrolling views](../views/scrolling.md) do this.
|
|
187
|
+
|
|
188
|
+
### Actions
|
|
189
|
+
|
|
190
|
+
| Action | Effect |
|
|
191
|
+
| --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
192
|
+
| `setView(name, options?)` | Changes the view. Every setter and navigation action takes `{ event?, reason?, source? }` last, for the [change handler](../concepts/state.md#what-a-handler-hears) |
|
|
193
|
+
| `setAnchorDate(date)` | Changes the date |
|
|
194
|
+
| `setTimeZone(zone)` | Changes the time zone |
|
|
195
|
+
| `setSelection(value)` | Changes the selection (`null` clears it) |
|
|
196
|
+
| `setFocus(value)` | Changes the focus (`null` clears it) |
|
|
197
|
+
| `setExpandedResourceIds(ids)` | Changes the expanded resources |
|
|
198
|
+
| `navigatePrevious()`, `navigateNext()` | Moves by one step of the active view |
|
|
199
|
+
| `navigateToday()` | Moves to today in the calendar's time zone |
|
|
200
|
+
| `proposeEventChange(proposal, detail?)` | Proposes a change to an event and resolves with the outcome. `detail.input` names the input for policies, `onEventChange` and `onEventChangeResult`, `"api"` by default. See [Interactions](../interactions.md#changing-events-from-your-own-ui). |
|
|
201
|
+
| `checkEventChange(proposal, detail?)` | Runs the policies on a proposal without showing or saving it. Returns `{ status: "accepted", change }` or `{ status: "rejected", change, reason }`, or `null` for an unknown event or an async policy. |
|
|
202
|
+
|
|
203
|
+
Setting the current value again (the same date, view, time zone or resource IDs, or the same
|
|
204
|
+
`selection` or `focus` object) doesn't change state or call its handler, unless the value is
|
|
205
|
+
controlled and you haven't applied a change the calendar asked for (see
|
|
206
|
+
[State](../concepts/state.md)). `useAnchorDateRequests` still hears a request for the current anchor
|
|
207
|
+
date. Calling two actions in a row builds on the
|
|
208
|
+
first, so `navigateNext(); navigateNext()` moves two steps, even for controlled values.
|
|
209
|
+
|
|
210
|
+
### Meta
|
|
211
|
+
|
|
212
|
+
| Name | Type | Description |
|
|
213
|
+
| --------------- | ------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- |
|
|
214
|
+
| `eventSnapshot` | `EventSnapshot` | Validated, indexed events. See [snapshots](./events.md#snapshots). |
|
|
215
|
+
| `resources` | `readonly TResource[]` | The resources prop. |
|
|
216
|
+
| `environment` | `CalendarEnvironment` | `locale`, `timeZone`, `secondaryTimeZones`, `weekRules`, `direction`, `disambiguation`, and `now` or `clock` when set. |
|
|
217
|
+
| `activeView` | `CalendarView \| undefined` | The active view's definition, if it's registered. |
|
|
218
|
+
| `views` | `readonly CalendarView[]` | The registered views. |
|
|
219
|
+
| `diagnostics` | `readonly CalendarDiagnostic[]` | See below. |
|
|
220
|
+
| `ids` | `{ frame, title, viewport }` | Element IDs. |
|
|
221
|
+
| `refs` | `{ frame, title, toolbar, viewport }` | Refs to the rendered elements. |
|
|
222
|
+
| `instanceId` | `string` | The base for the element IDs. |
|
|
223
|
+
| `label` | `string \| undefined` | Root's label prop. |
|
|
224
|
+
|
|
225
|
+
## Diagnostics
|
|
226
|
+
|
|
227
|
+
Problems that don't stop rendering are collected in `meta.diagnostics` and passed to
|
|
228
|
+
`onDiagnosticsChange`. Time doesn't log them.
|
|
229
|
+
|
|
230
|
+
| `code` | `severity` | Cause |
|
|
231
|
+
| ----------------------------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
232
|
+
| `unregistered-active-view` | error | The `view` state names a view that isn't registered. |
|
|
233
|
+
| `invalid-event` | error | A record was skipped. `issue` has the details ([issue codes](./events.md#invalid-records)). |
|
|
234
|
+
| `invalid-annotation` | error | An annotation was skipped. `issue` has its `code`, `index`, and the `annotation`. |
|
|
235
|
+
| `invalid-availability` | error | A working-hours rule, exception, or time zone was left out. `issue` has the `code`, the `value`, and the `resourceId` when it's a resource's. |
|
|
236
|
+
| `invalid-secondary-time-zone` | error | An entry of `secondaryTimeZones` was left out. `issue` has the `value`, and its `index` in a list. |
|