@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.
Files changed (70) hide show
  1. package/README.md +24 -4
  2. package/dist/index.d.mts +2 -2
  3. package/docs/accessibility.md +304 -0
  4. package/docs/agents/changes.md +449 -0
  5. package/docs/agents/coding-agents.md +117 -0
  6. package/docs/agents/connect.md +435 -0
  7. package/docs/agents/deleting.md +296 -0
  8. package/docs/agents/reference.md +512 -0
  9. package/docs/agents/server.md +317 -0
  10. package/docs/agents/webmcp.md +153 -0
  11. package/docs/agents.md +353 -0
  12. package/docs/annotations.md +196 -0
  13. package/docs/api/changes.md +248 -0
  14. package/docs/api/dnd-kit.md +267 -0
  15. package/docs/api/events.md +152 -0
  16. package/docs/api/ics.md +524 -0
  17. package/docs/api/primitives.md +168 -0
  18. package/docs/api/react.md +236 -0
  19. package/docs/api/recurrence.md +586 -0
  20. package/docs/api/solid.md +460 -0
  21. package/docs/api/store.md +92 -0
  22. package/docs/api/temporal.md +172 -0
  23. package/docs/api.md +57 -0
  24. package/docs/availability.md +573 -0
  25. package/docs/comparison.md +279 -0
  26. package/docs/concepts/anatomy.md +73 -0
  27. package/docs/concepts/events.md +164 -0
  28. package/docs/concepts/how-it-works.md +95 -0
  29. package/docs/concepts/recurrence.md +127 -0
  30. package/docs/concepts/state.md +244 -0
  31. package/docs/concepts/time.md +170 -0
  32. package/docs/guides/dnd-kit.md +333 -0
  33. package/docs/guides/google-calendar-sync.md +1246 -0
  34. package/docs/guides/google-calendar.md +367 -0
  35. package/docs/guides/ics.md +486 -0
  36. package/docs/guides/motion.md +414 -0
  37. package/docs/guides/nextjs-app-router.md +630 -0
  38. package/docs/guides/nextjs.md +149 -0
  39. package/docs/guides/performance.md +103 -0
  40. package/docs/guides/recurring-events.md +583 -0
  41. package/docs/guides/tanstack-query.md +485 -0
  42. package/docs/index.md +118 -0
  43. package/docs/installation.md +194 -0
  44. package/docs/interactions.md +408 -0
  45. package/docs/llms.txt +86 -0
  46. package/docs/migrating-to-2.md +322 -0
  47. package/docs/quick-start.md +159 -0
  48. package/docs/stylex.md +265 -0
  49. package/docs/testing.md +581 -0
  50. package/docs/theme-builder.md +81 -0
  51. package/docs/theming.md +169 -0
  52. package/docs/undo-redo.md +339 -0
  53. package/docs/views/agenda.md +221 -0
  54. package/docs/views/custom-views.md +192 -0
  55. package/docs/views/month.md +109 -0
  56. package/docs/views/resource-columns.md +261 -0
  57. package/docs/views/resource-timeline.md +225 -0
  58. package/docs/views/scrolling.md +192 -0
  59. package/docs/views/week-and-day.md +257 -0
  60. package/docs/views/year.md +138 -0
  61. package/docs/views.md +69 -0
  62. package/package.json +41 -14
  63. package/skills/moltenship-time/SKILL.md +75 -0
  64. package/skills/moltenship-time/references/agent-ready.md +272 -0
  65. package/skills/moltenship-time/references/changes.md +188 -0
  66. package/skills/moltenship-time/references/compose.md +168 -0
  67. package/skills/moltenship-time/references/mistakes.md +98 -0
  68. package/skills/moltenship-time/references/solid.md +202 -0
  69. package/skills/moltenship-time/references/state.md +129 -0
  70. package/skills/moltenship-time/references/testing.md +176 -0
@@ -0,0 +1,202 @@
1
+ # Solid
2
+
3
+ `@moltenship/calendar-solid` is the SolidJS 2 integration, a preview. It renders the same primitive as React, so state, actions, event changes, policies and the agent surface are the same. Much of what React has isn't in it yet. Read `docs/api/solid.md` before you write Solid code, and check the package's own types: the preview changes between releases.
4
+
5
+ ## What it has, and what it doesn't
6
+
7
+ | Has | Doesn't have yet |
8
+ | ------------------------------------------------------------------- | ---------------------------------------------------------------------- |
9
+ | `createCalendar`, `defineCalendarView` | Ready-made views. The registry's views are React source |
10
+ | `Root` with the same props as React's | Keyboard navigation inside a view, roving focus |
11
+ | `Frame`, `Toolbar`, `Title`, `Viewport`, `ActiveView` | Dragging, resizing or creating with a pointer |
12
+ | `PreviousTrigger`, `NextTrigger`, `TodayTrigger`, `ViewSwitcher` | Gesture previews (`useCalendarDraft`, `useCalendarInteraction`) |
13
+ | `useCalendarState`, `useCalendarSelector`, `useCalendarActions` | Undo bindings (`useCalendarHistory`, `useCalendarHistoryShortcuts`) |
14
+ | `useCalendarMeta`, `useVisibleRange`, `useViewProjection` | `Calendar.Announcer`, `Calendar.Event` |
15
+ | `useCalendarPendingChanges`, `useCalendar` | Hooks for selection, annotations, availability, resources, the clock |
16
+ | `createStateSelector`, `createCalendarStore`, `resolveViewOptions` | A testing package: `@moltenship/calendar-testing` is React only |
17
+ | The fifteen agent actions, through `@ui-sdk/solid/agent` | |
18
+
19
+ If the user asks for something in the right column, say it isn't in the Solid preview. Don't import a React hook's name from the Solid package: it isn't exported.
20
+
21
+ ## Install
22
+
23
+ ```bash
24
+ pnpm add @moltenship/calendar-solid @moltenship/calendar-core solid-js @solidjs/web @ui-sdk/core @ui-sdk/solid
25
+ ```
26
+
27
+ - The adapter and the view functions come from `@moltenship/calendar-core`. The Solid package doesn't re-export them.
28
+ - Don't install `@moltenship/calendar` in a Solid app. It's the React package.
29
+ - With Vite, use `@solidjs/vite-plugin`, and set `"jsx": "preserve"` and `"jsxImportSource": "@solidjs/web"` in `tsconfig.json`. Exclude `@ui-sdk/core` from `optimizeDeps` so the dev server loads one copy.
30
+
31
+ ## A calendar
32
+
33
+ A view is a strategy from the engine and a Solid component that draws its projection. The engine has projections for a month (`getMonthRange`, `getMonthTitle`, `navigateMonth`, `projectMonth`) and a list (`getListRange`, `getListTitle`, `navigateList`, `projectList`), among others.
34
+
35
+ ```tsx title="calendar.tsx"
36
+ import {
37
+ defineEventAdapter,
38
+ getListRange,
39
+ getListTitle,
40
+ navigateList,
41
+ projectList,
42
+ type CalendarEventInterval,
43
+ type ListProjection,
44
+ type ListViewOptions,
45
+ } from "@moltenship/calendar-core";
46
+ import {
47
+ createCalendar,
48
+ defineCalendarView,
49
+ type CalendarViewRendererProps,
50
+ } from "@moltenship/calendar-solid";
51
+ import { For } from "solid-js";
52
+
53
+ export interface Meeting {
54
+ readonly id: string;
55
+ readonly title: string;
56
+ readonly interval: CalendarEventInterval;
57
+ }
58
+
59
+ const eventAdapter = defineEventAdapter<Meeting>()({
60
+ getId: (meeting) => meeting.id,
61
+ getTitle: (meeting) => meeting.title,
62
+ getInterval: (meeting) => meeting.interval,
63
+ getResourceIds: () => [],
64
+ });
65
+
66
+ type List = ListProjection<Meeting, string, string>;
67
+
68
+ // Props are getters: read `props.projection` in the JSX. Don't destructure it.
69
+ function Agenda(props: CalendarViewRendererProps<List, ListViewOptions>) {
70
+ return (
71
+ <For each={props.projection.days} fallback={<p>Nothing in these weeks.</p>}>
72
+ {(entry) => (
73
+ <section>
74
+ <h3>{entry.date.toLocaleString(props.environment.locale, { dateStyle: "full" })}</h3>
75
+ <ul>
76
+ <For each={entry.items}>
77
+ {(item) => <li data-event-id={item.event.id}>{item.event.title}</li>}
78
+ </For>
79
+ </ul>
80
+ </section>
81
+ )}
82
+ </For>
83
+ );
84
+ }
85
+
86
+ const listView = defineCalendarView({
87
+ name: "list",
88
+ defaultOptions: { weeks: 2 } as ListViewOptions,
89
+ strategy: {
90
+ getRange: (anchor, environment, options) => getListRange(anchor, environment, options),
91
+ getTitle: (range, environment) => getListTitle(range, environment),
92
+ navigate: (anchor, delta, options) => navigateList(anchor, delta, options),
93
+ project: (input) => projectList(input) as List,
94
+ },
95
+ Renderer: Agenda,
96
+ });
97
+
98
+ export const Calendar = createCalendar<Meeting>()({ eventAdapter, views: [listView] });
99
+ ```
100
+
101
+ ```tsx title="app.tsx"
102
+ import type { CalendarWeekRules } from "@moltenship/calendar-core";
103
+ import { createSignal } from "solid-js";
104
+
105
+ import { Calendar, type Meeting } from "./calendar";
106
+
107
+ const timeZone = "Europe/Berlin";
108
+ const at = (value: string) =>
109
+ Temporal.PlainDateTime.from(value).toZonedDateTime(timeZone).toInstant();
110
+
111
+ const seed: readonly Meeting[] = [
112
+ {
113
+ id: "standup",
114
+ title: "Standup",
115
+ interval: { kind: "timed", start: at("2026-10-08T09:00"), end: at("2026-10-08T09:30") },
116
+ },
117
+ ];
118
+
119
+ const weekRules: CalendarWeekRules = { firstDay: 1, minimalDays: 4, weekend: [6, 7] };
120
+
121
+ export function App() {
122
+ const [meetings, setMeetings] = createSignal<readonly Meeting[]>(seed);
123
+
124
+ return (
125
+ <Calendar.Root
126
+ label="Team calendar"
127
+ events={meetings()}
128
+ defaultAnchorDate={Temporal.PlainDate.from("2026-10-08")}
129
+ defaultTimeZone={timeZone}
130
+ locale="en-US"
131
+ weekRules={weekRules}
132
+ onEventChange={(change, detail) => {
133
+ // A title an agent sent with `createEvent` or `updateEvent`. A person's change has none.
134
+ const sent = detail.fields?.title;
135
+ const title = typeof sent === "string" && sent.trim() !== "" ? sent.trim() : undefined;
136
+ if (change.cause === "delete") {
137
+ setMeetings((current) => current.filter((meeting) => meeting.id !== change.eventId));
138
+ } else if (change.cause === "create") {
139
+ setMeetings((current) => [
140
+ ...current,
141
+ { id: crypto.randomUUID(), title: title ?? "New meeting", interval: change.proposed },
142
+ ]);
143
+ } else {
144
+ setMeetings((current) =>
145
+ current.map((meeting) =>
146
+ meeting.id === change.eventId
147
+ ? { ...meeting, title: title ?? meeting.title, interval: change.proposed }
148
+ : meeting,
149
+ ),
150
+ );
151
+ }
152
+ }}
153
+ >
154
+ <Calendar.Frame>
155
+ <Calendar.Toolbar>
156
+ <Calendar.PreviousTrigger>Previous</Calendar.PreviousTrigger>
157
+ <Calendar.TodayTrigger>Today</Calendar.TodayTrigger>
158
+ <Calendar.NextTrigger>Next</Calendar.NextTrigger>
159
+ <Calendar.Title />
160
+ </Calendar.Toolbar>
161
+ <Calendar.Viewport>
162
+ <Calendar.ActiveView />
163
+ </Calendar.Viewport>
164
+ </Calendar.Frame>
165
+ </Calendar.Root>
166
+ );
167
+ }
168
+ ```
169
+
170
+ ## Rules that differ from React
171
+
172
+ - **Hooks return accessors.** `const state = Calendar.useCalendarState()`, then `state().view`. `useCalendarActions()` returns the actions object itself.
173
+ - **Don't destructure.** A `Renderer`'s props, and `useCalendar()`'s `meta` and `state`, are getters. Read them in JSX, a memo or an effect.
174
+ - **Pass a signal's value to a prop that changes:** `events={meetings()}`, `view={view()}`.
175
+ - **Don't read a prop in a component's body** to seed a signal: Solid 2 warns, and the value never updates. Read props in JSX or a memo.
176
+ - **`class`, not `className`**, on the parts.
177
+ - **A trigger needs children or an `aria-label`.** TypeScript requires one of them.
178
+ - **An accessor has the new value once Solid flushes**, a microtask after the action.
179
+ - **The store's view type has to be the calendar's:** `createCalendarStore<View>(...)`. A calendar without resources takes a store made without the resource ID type.
180
+
181
+ The rest is in the other references and applies as written: `state.md` for controlled and uncontrolled state, `changes.md` for `onEventChange`, policies and pending changes. Skip their parts on history hooks, dragging and the registry.
182
+
183
+ ## Agents
184
+
185
+ ```ts title="agent.ts"
186
+ import { createAgent } from "@ui-sdk/solid/agent";
187
+
188
+ // One bridge for the page. Import this module before the one that calls `render`.
189
+ export const agent = createAgent({
190
+ allow: (step) => step.action !== "deleteEvent",
191
+ });
192
+ ```
193
+
194
+ Everything in `agent-ready.md` holds: `label` on `Root`, `Calendar.Frame` rendered, `detail.fields` read in `onEventChange`, `allowAgentDelete` for deletes, the same fifteen actions with one object each, the same results and errors. Only the import path differs.
195
+
196
+ ## Changing an event without a drag
197
+
198
+ There's no pointer layer yet, so a person changes an event through your own controls. Call `actions.proposeEventChange(proposal)` from `Calendar.useCalendarActions()`: it runs the policies and `onEventChange` and resolves with the result. `changes.md` has the proposal's shape.
199
+
200
+ ## Testing
201
+
202
+ `@moltenship/calendar-testing` doesn't render Solid. The package's own tests show a pattern that works with Vitest and jsdom: render with `render` from `@solidjs/web`, call `flush()` from `solid-js` after an action, and assert on the DOM. For an agent's step, create a bridge with `createAgent` from `@ui-sdk/solid/agent` before anything renders, and `await agent.act(...)`. Those tests build components with `createComponent` instead of JSX, so they need no compiler; a test file with JSX needs the Solid plugin in the test config.
@@ -0,0 +1,129 @@
1
+ # State
2
+
3
+ `Root` keeps six values. Each is uncontrolled (the calendar owns it) or controlled (the app owns it), independently of the others. The full page is `docs/concepts/state.md`.
4
+
5
+ | Value | Type | Uncontrolled prop | Controlled prop | Handler |
6
+ | --------------------- | ---------------------- | ---------------------------- | --------------------- | ----------------------------- |
7
+ | `view` | one of your view names | `defaultView` | `view` | `onViewChange` |
8
+ | `anchorDate` | `Temporal.PlainDate` | `defaultAnchorDate` | `anchorDate` | `onAnchorDateChange` |
9
+ | `timeZone` | IANA name | `defaultTimeZone` | `timeZone` | `onTimeZoneChange` |
10
+ | `selection` | your type, or `null` | `defaultSelection` | `selection` | `onSelectionChange` |
11
+ | `focus` | your type, or `null` | `defaultFocus` | `focus` | `onFocusChange` |
12
+ | `expandedResourceIds` | resource IDs | `defaultExpandedResourceIds` | `expandedResourceIds` | `onExpandedResourceIdsChange` |
13
+
14
+ ## Rules
15
+
16
+ - **Start uncontrolled.** Control a value only when something outside the calendar must set it or stay in sync with it: a date picker beside the calendar, the URL, a saved preference.
17
+ - **A controlled value needs its handler.** The calendar never changes a controlled value itself. It calls the handler, and nothing moves until the app stores the new value.
18
+ - **`undefined` means uncontrolled.** To control `selection` or `focus` with nothing selected, pass `null`.
19
+ - **Defaults are read once**, when `Root` mounts.
20
+ - **Handlers run for uncontrolled values too**, after the calendar updates them.
21
+ - **`Root` needs a date, a time zone and a view on its first render**, or it throws `calendar-root-requires-anchor-date`, `calendar-root-requires-time-zone` or `calendar-root-requires-view`.
22
+
23
+ ```tsx title="controlled-date.tsx"
24
+ "use client";
25
+
26
+ import { useState } from "react";
27
+
28
+ import { Calendar, weekRules, type Meeting } from "./calendar";
29
+
30
+ export function ControlledCalendar({ meetings }: { readonly meetings: readonly Meeting[] }) {
31
+ const [anchorDate, setAnchorDate] = useState(() => Temporal.PlainDate.from("2026-10-08"));
32
+
33
+ return (
34
+ <Calendar.Root
35
+ events={meetings}
36
+ anchorDate={anchorDate}
37
+ onAnchorDateChange={setAnchorDate}
38
+ defaultTimeZone="Europe/Berlin"
39
+ locale="en-US"
40
+ weekRules={weekRules}
41
+ >
42
+ <Calendar.Frame className="flex h-[640px] flex-col">
43
+ <Calendar.Viewport className="min-h-0 flex-1">
44
+ <Calendar.ActiveView />
45
+ </Calendar.Viewport>
46
+ </Calendar.Frame>
47
+ </Calendar.Root>
48
+ );
49
+ }
50
+ ```
51
+
52
+ ## Reading and changing it
53
+
54
+ Inside `Root`, use the hooks on your `Calendar`:
55
+
56
+ | Hook | Returns |
57
+ | --------------------------------------- | ---------------------------------------------------------------------------------- |
58
+ | `Calendar.useCalendarSelector(selector)` | One derived value. The component re-renders only when it changes. Prefer this one |
59
+ | `Calendar.useCalendarState()` | All six values |
60
+ | `Calendar.useCalendarActions()` | The actions below. Stable: safe in dependency lists |
61
+ | `Calendar.useCalendarMeta()` | The event snapshot, resources, environment, active view, diagnostics, `label` |
62
+ | `Calendar.useVisibleRange()` | The dates the active view shows |
63
+
64
+ The actions: `setView`, `setAnchorDate`, `setTimeZone`, `setSelection`, `setFocus`, `setExpandedResourceIds`, `navigateNext`, `navigatePrevious`, `navigateToday`, `proposeEventChange`, `checkEventChange`.
65
+
66
+ ```tsx title="skip-a-week.tsx"
67
+ "use client";
68
+
69
+ import { Calendar } from "./calendar";
70
+
71
+ export function SkipAWeek() {
72
+ const anchorDate = Calendar.useCalendarSelector((state) => state.anchorDate);
73
+ const actions = Calendar.useCalendarActions();
74
+
75
+ return (
76
+ <button type="button" onClick={() => actions.setAnchorDate(anchorDate.add({ weeks: 1 }))}>
77
+ Skip a week
78
+ </button>
79
+ );
80
+ }
81
+ ```
82
+
83
+ Actions called one after another build on each other: `navigateNext()` twice in one click moves two steps, controlled or not.
84
+
85
+ ## What a handler hears
86
+
87
+ Every state handler is `(next, detail)`:
88
+
89
+ | `detail` field | Contents |
90
+ | -------------- | -------------------------------------------------------------------------------------------- |
91
+ | `previous` | The value before |
92
+ | `controlled` | Whether the app controls this value |
93
+ | `slice` | Which value: `"view"`, `"anchorDate"`, … |
94
+ | `reason` | `"next-press"`, `"previous-press"`, `"today-press"`, `"input-change"` (the view switcher part), `"keyboard-navigation"` (a view's keys), `"focus-change"` (focus a person moved), `"resource-toggle"`, or `"imperative"` (an action call) |
95
+ | `source` | `"mouse"`, `"touch"`, `"pen"`, `"keyboard"`, `"virtual"`, `"programmatic"`, or `"agent"` |
96
+ | `event` | The DOM event, when a part's own control caused the change |
97
+ | `cancel()` | Keeps the value as it was |
98
+ | `canceled` | Whether a handler cancelled |
99
+
100
+ ```tsx
101
+ <Calendar.Root
102
+ onViewChange={(view, detail) => {
103
+ // An agent may look around the week and day views, and not switch to the month.
104
+ if (detail.source === "agent" && view === "month") detail.cancel();
105
+ }}
106
+ />
107
+ ```
108
+
109
+ An action takes options last, `{ event?, reason?, source? }`, to say why and how the app called it: `actions.navigateNext({ event: event.nativeEvent })`. Without them a call reads `reason: "imperative"`, `source: "programmatic"`.
110
+
111
+ `"keyboard"` is a person's keys, on a toolbar button and in a view: arrow-key navigation, moving focus between cells and events, and expanding a resource report it. `"agent"` is anything an agent's step causes, including an action the app's own button calls when an agent presses it.
112
+
113
+ A click dispatched by a script reads `source: "programmatic"`. Only a real pointer reads `"mouse"`, so don't assert `"mouse"` in a jsdom test.
114
+
115
+ ## Selection and focus
116
+
117
+ The app chooses their shape: the third and fourth type arguments of `createCalendar`, after the event and resource types.
118
+
119
+ ```tsx
120
+ type Selection = { readonly eventId: string } | { readonly date: Temporal.PlainDate };
121
+
122
+ const Calendar = createCalendar<Meeting, never, Selection>()({ eventAdapter, views });
123
+ ```
124
+
125
+ The calendar stores the values as they are. Keep them serializable if agents should read them: both are in the agent's snapshot.
126
+
127
+ ## State outside `Root`
128
+
129
+ `createCalendarStore` holds the six values outside React, for a toolbar in another part of the page or state that outlives a `Root`. Pass it as `store` on `Root`. Read `docs/api/store.md` before using it; most apps don't need one.
@@ -0,0 +1,176 @@
1
+ # Test a calendar
2
+
3
+ `@moltenship/calendar-testing` renders your real `Calendar`, fixes the clock and the zone, and gives you queries and keyboard and pointer drivers. It depends on no test runner; the examples use Vitest with jsdom. The full page is `docs/testing.md`.
4
+
5
+ ```bash
6
+ pnpm add -D @moltenship/calendar-testing vitest jsdom
7
+ ```
8
+
9
+ Its peers are `react`, `react-dom`, `@ui-sdk/core` and `@ui-sdk/react`, which a 2.0 app already has.
10
+
11
+ ```ts title="vitest.config.ts"
12
+ import { defineConfig } from "vitest/config";
13
+
14
+ export default defineConfig({
15
+ test: { environment: "jsdom", setupFiles: ["./tests/setup.ts"] },
16
+ });
17
+ ```
18
+
19
+ ```ts title="tests/setup.ts"
20
+ // Only on a runtime without Temporal. Node.js 26 has it.
21
+ if (!("Temporal" in globalThis)) await import("temporal-polyfill/global");
22
+ ```
23
+
24
+ ## A test
25
+
26
+ ```tsx title="calendar.test.tsx"
27
+ import {
28
+ createCalendar,
29
+ createCanonicalEventAdapter,
30
+ type CalendarEvent,
31
+ } from "@moltenship/calendar";
32
+ import {
33
+ buildEvent,
34
+ cleanup,
35
+ createTestEnvironment,
36
+ renderCalendar,
37
+ } from "@moltenship/calendar-testing";
38
+ import { afterEach, expect, test } from "vitest";
39
+
40
+ import { createWeekView } from "@/components/calendar/time-grid-view/time-grid-view";
41
+
42
+ type Meeting = CalendarEvent<null>;
43
+
44
+ const Calendar = createCalendar<Meeting>()({
45
+ eventAdapter: createCanonicalEventAdapter<null>(),
46
+ views: [createWeekView<Meeting>()],
47
+ });
48
+
49
+ afterEach(cleanup);
50
+
51
+ // Thursday, 8 October 2026 at noon UTC unless you say otherwise.
52
+ const environment = createTestEnvironment({ timeZone: "Europe/Berlin" });
53
+ const standup = buildEvent({ title: "Standup", start: environment.at("09:00") });
54
+
55
+ test("a saved move reaches onEventChange and the events", async () => {
56
+ const calendar = await renderCalendar(Calendar, { environment, events: [standup] });
57
+
58
+ await calendar.propose({
59
+ cause: "move",
60
+ eventId: "Standup",
61
+ proposed: {
62
+ kind: "timed",
63
+ start: environment.at("10:00"),
64
+ end: environment.at("10:30"),
65
+ },
66
+ });
67
+
68
+ expect(calendar.changes.map((change) => change.cause)).toEqual(["move"]);
69
+ expect(calendar.results[0]?.result.status).toBe("committed");
70
+ expect(String(calendar.events()[0]?.start)).toBe("2026-10-08T08:00:00Z");
71
+ });
72
+ ```
73
+
74
+ Test the app's own `Calendar` where you can: import it from the app instead of creating one in the test, and pass `applyChange` and `createEvent` to the harness for the app's record shape. The default `applyCanonicalChange` only knows canonical events.
75
+
76
+ ## What you get
77
+
78
+ | Piece | Use |
79
+ | -------------------------------------- | ------------------------------------------------------------------------------------- |
80
+ | `createTestEnvironment(options?)` | A fixed `now`, time zone, locale and week rules. `environment.at("09:00")` is an instant on its date |
81
+ | `buildEvent`, `buildAllDayEvent`, `buildResource`, `buildRecurringEvent`, `buildAvailability` | Canonical records with defaults. An event's ID defaults to its title |
82
+ | `renderCalendar(Calendar, options)` | Renders `Root` inside `act` and returns the harness. It owns the events and applies saved changes |
83
+ | `hydrateCalendar(Calendar, options)` | Renders on the server, hydrates, and throws on a mismatch |
84
+ | `calendar.changes`, `calendar.results` | Every `onEventChange` change, and every `onEventChangeResult` call as `{ result, detail }` |
85
+ | `calendar.events()`, `state()`, `meta()`, `pendingChanges()` | What the calendar has now |
86
+ | `calendar.act(callback)` | Calls the actions inside `act`: `await calendar.act((actions) => actions.setView("day"))` |
87
+ | `calendar.propose(proposal)` | `proposeEventChange` inside `act`, resolved once it settles |
88
+ | `calendar.settled()` | Waits until no change is pending |
89
+ | `calendar.getEvent`, `queryEvent`, `getDayCell`, `getTimeColumn`, `placementOf` | Queries by ID, title or start, not by rendered text |
90
+ | `calendar.keyboard` | `moveEvent`, `resizeEvent`, `createEvent`, `focusEvent`, `focusCell`, `press` |
91
+ | `calendar.pointer` | Real Pointer Event drags. Browser only |
92
+ | `calendar.lastAnnouncement()` | What the `Announcer` said. Pass `messages` to render one |
93
+ | Fixtures, such as `dstWeekFixture()` | Ready datasets for hard cases: DST weeks, many zones, series |
94
+
95
+ Other `Root` props go through `rootProps`: `rootProps: { policies: [timedOnly], label: "Team calendar" }`. What `Root` renders goes through `children`; it's `<Calendar.ActiveView />` by default.
96
+
97
+ ## Keyboard
98
+
99
+ ```tsx
100
+ // Focus the event, Space, two slots down and a day across, then Enter.
101
+ await calendar.keyboard.moveEvent("Standup", { across: 1, down: 2 });
102
+ await calendar.settled();
103
+
104
+ expect(calendar.placementOf("Standup").wallRange).toBe("2026-10-09T09:30/2026-10-09T10:30");
105
+ expect(calendar.results[0]?.detail.input).toBe("keyboard");
106
+ ```
107
+
108
+ Drivers return once their keys are handled, not when the change is saved. Call `settled()` before asserting on a save.
109
+
110
+ ## An agent's change
111
+
112
+ No model is involved: a step is a plain object, run through the real bridge.
113
+
114
+ ```tsx title="calendar.test.tsx"
115
+ import { createAgent } from "@ui-sdk/react/agent";
116
+
117
+ test("an agent's move is saved like a person's, and says who asked", async () => {
118
+ const agent = createAgent();
119
+ const calendar = await renderCalendar(Calendar, {
120
+ environment,
121
+ events: [standup],
122
+ // An agent finds a calendar by its name, on the frame.
123
+ rootProps: { label: "Team calendar" },
124
+ children: (
125
+ <Calendar.Frame>
126
+ <Calendar.ActiveView />
127
+ </Calendar.Frame>
128
+ ),
129
+ });
130
+
131
+ const outcome = await calendar.act(() =>
132
+ agent.act({
133
+ steps: [
134
+ {
135
+ ref: "Team calendar",
136
+ action: "moveEvent",
137
+ // Every action takes one object.
138
+ args: [{ eventId: "Standup", start: "2026-10-08T11:00" }],
139
+ },
140
+ ],
141
+ }),
142
+ );
143
+ await calendar.settled();
144
+
145
+ expect(outcome.ok).toBe(true);
146
+ // The step's result is the change, with how it ended.
147
+ expect(outcome.steps[0]?.result).toMatchObject({ cause: "move", status: "saved" });
148
+ expect(calendar.results[0]?.detail.input).toBe("agent");
149
+ expect(calendar.placementOf("Standup").wallRange).toBe("2026-10-08T11:00/2026-10-08T12:00");
150
+ });
151
+ ```
152
+
153
+ Three things make it work: the frame as `children` (the harness renders no frame by default), the agent's call inside `calendar.act`, and `settled()` before reading `results`.
154
+
155
+ Test the app's own bridge too: import it, run a step its `allow` should refuse, and expect `ok: false` with `The app refused …` in `error.message`. Test a policy's refusal the same way, expecting its reason in the message.
156
+
157
+ Without the harness, in your own render: wrap `agent.act` in React's `act`, and stub `ResizeObserver` and `matchMedia` in jsdom if the views need them.
158
+
159
+ ## What jsdom can't do
160
+
161
+ jsdom and happy-dom lay nothing out: every element is an empty box at the top left, and nothing scrolls.
162
+
163
+ - The pointer drivers throw `PointerLayoutError`. Run pointer tests in Vitest's browser mode (`docs/testing.md#pointer-and-touch`), and give the calendar a height there.
164
+ - Sizes, scrolling, virtualization and what's visible aren't there to test.
165
+ - CSS doesn't apply.
166
+ - A script's click reads `source: "programmatic"` in a state handler, not `"mouse"`.
167
+
168
+ Queries, the keyboard drivers, saves, announcements, hydration and agent steps work in jsdom.
169
+
170
+ ## Rules
171
+
172
+ - **Fix time through props, not fake timers.** The environment sets `now`, the zone, the locale and the week rules. Don't patch `Temporal.Now` or `Date`.
173
+ - **Find events with the queries**, not by text: a view formats times by locale.
174
+ - **Assert with `placementOf(event).range` or `.wallRange`.** They're text, and read plainly when they fail.
175
+ - **`afterEach(cleanup)`**, or calendars pile up in the document.
176
+ - **Don't mock the calendar.** Render the real one; that's what the package is for.