@moltenship/calendar 1.0.0-rc.2 → 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/README.md +27 -6
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +2 -2
- package/docs/accessibility.md +305 -0
- package/docs/agents/changes.md +449 -0
- package/docs/agents/coding-agents.md +116 -0
- package/docs/agents/connect.md +444 -0
- package/docs/agents/deleting.md +296 -0
- package/docs/agents/reference.md +511 -0
- package/docs/agents/server.md +317 -0
- package/docs/agents/webmcp.md +153 -0
- package/docs/agents.md +355 -0
- package/docs/annotations.md +198 -0
- package/docs/api/changes.md +264 -0
- package/docs/api/components.md +245 -0
- package/docs/api/dnd-kit.md +265 -0
- package/docs/api/events.md +153 -0
- package/docs/api/primitives.md +218 -0
- package/docs/api/store.md +92 -0
- package/docs/api.md +57 -0
- package/docs/availability.md +576 -0
- package/docs/comparison.md +278 -0
- package/docs/concepts/anatomy.md +73 -0
- package/docs/concepts/events.md +163 -0
- package/docs/concepts/how-it-works.md +112 -0
- package/docs/concepts/state.md +244 -0
- package/docs/concepts/time.md +168 -0
- package/docs/customization.md +271 -0
- package/docs/frameworks.md +116 -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/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/tanstack-query.md +485 -0
- package/docs/ics/feed.md +484 -0
- package/docs/ics/import.md +183 -0
- package/docs/ics/reference.md +482 -0
- package/docs/ics.md +142 -0
- package/docs/index.md +149 -0
- package/docs/installation.md +209 -0
- package/docs/interactions.md +441 -0
- package/docs/llms.txt +99 -0
- package/docs/migrating-to-2.md +497 -0
- package/docs/quick-start.md +163 -0
- package/docs/recurrence/calendar.md +598 -0
- package/docs/recurrence/model.md +128 -0
- package/docs/recurrence/reference.md +547 -0
- package/docs/recurrence.md +122 -0
- package/docs/stylex.md +290 -0
- package/docs/temporal/daylight-saving-time.md +172 -0
- package/docs/temporal/month-grid.md +119 -0
- package/docs/temporal/reference.md +167 -0
- package/docs/temporal.md +105 -0
- package/docs/testing.md +600 -0
- package/docs/theme-builder.md +82 -0
- package/docs/theming.md +275 -0
- package/docs/undo-redo.md +347 -0
- package/docs/views/agenda.md +222 -0
- package/docs/views/custom-views.md +195 -0
- package/docs/views/month.md +110 -0
- package/docs/views/resource-columns.md +265 -0
- package/docs/views/resource-timeline.md +226 -0
- package/docs/views/scrolling.md +193 -0
- package/docs/views/week-and-day.md +258 -0
- package/docs/views/year.md +138 -0
- package/docs/views.md +69 -0
- package/package.json +42 -14
- package/skills/moltenship-time/SKILL.md +77 -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 +175 -0
- package/skills/moltenship-time/references/mistakes.md +100 -0
- package/skills/moltenship-time/references/solid.md +213 -0
- package/skills/moltenship-time/references/state.md +129 -0
- package/skills/moltenship-time/references/testing.md +176 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Mistakes agents make with this library
|
|
2
|
+
|
|
3
|
+
These are the mistakes this library's shape makes easy: the ones a coding agent makes when it guesses from other calendar libraries, or from the 1.x API. Check your work against the list before you finish.
|
|
4
|
+
|
|
5
|
+
## Dates and times
|
|
6
|
+
|
|
7
|
+
| Mistake | Fix |
|
|
8
|
+
| -------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
|
|
9
|
+
| `new Date()` or an ISO string as an event's `start` | `Temporal.Instant.from("2026-10-08T07:00:00Z")` for timed events. Convert where data enters the app |
|
|
10
|
+
| An all-day event that ends on its last day | The end is exclusive: one day on October 8 is `start: 2026-10-08`, `end: 2026-10-09` |
|
|
11
|
+
| `Temporal.PlainDate` in a `kind: "timed"` interval | Timed takes instants, all-day takes plain dates, floating takes plain date-times |
|
|
12
|
+
| No time zone on `Root`, expecting the browser's | Pass `defaultTimeZone`. For the person's zone: `Temporal.Now.timeZoneId()`, read in the browser |
|
|
13
|
+
| `Temporal.Now` during server rendering | Pass `now` from the server and a fixed `defaultAnchorDate`, or hydration mismatches |
|
|
14
|
+
| Assuming `Temporal` exists everywhere | Load a polyfill before any calendar import where it's missing (`docs/installation.md`) |
|
|
15
|
+
| Adding hours to move an event across a DST change | Use the placement helpers (`moveEventPlacement`) or wall-clock arithmetic on a `ZonedDateTime` |
|
|
16
|
+
|
|
17
|
+
## Structure
|
|
18
|
+
|
|
19
|
+
| Mistake | Fix |
|
|
20
|
+
| -------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
|
|
21
|
+
| `createCalendar` inside a component | Module scope. A new `Calendar` each render remounts everything |
|
|
22
|
+
| `createCalendar<Meeting>({ … })` or `defineEventAdapter<Meeting>({ … })` | Both are called twice: `createCalendar<Meeting>()({ … })` |
|
|
23
|
+
| Importing a view from `@moltenship/calendar` | Views are source in the app: `@/components/calendar/…`. Add them with `shadcn add` |
|
|
24
|
+
| Looking for a view's code in `node_modules` | It's in `components/calendar/`. Edit it there |
|
|
25
|
+
| Importing `useCalendarActions` from the package | Use `Calendar.useCalendarActions()`, from the calendar you created, so the types are yours |
|
|
26
|
+
| A hook or part outside `Root` | Move it inside. It throws `calendar-hook-outside-root` |
|
|
27
|
+
| A calendar with no height | Give `Calendar.Frame` a height; `Viewport` takes `min-h-0 flex-1` |
|
|
28
|
+
| Missing `"use client"` in the App Router | Calendar modules are Client Components |
|
|
29
|
+
| Wrapping the calendar in a context "provider" you invented | `Root` is the provider. There is no other |
|
|
30
|
+
| `shadcn add` into an app without shadcn's tokens | The views read `--background`, `--primary` and the rest. Add `base-tokens` |
|
|
31
|
+
| Installing only `@moltenship/calendar` on 2.0 | Also `@ui-sdk/core` and `@ui-sdk/react`, on the calendar's version |
|
|
32
|
+
| No `@layer ui-sdk;` before `@import "tailwindcss"` | ui-sdk's popover CSS wins over Tailwind: the view select's list loses its look |
|
|
33
|
+
| Selecting `[data-slot="calendar"]` to find a shadcn date picker | In 2.0 `Calendar.Frame` renders it too. Scope the selector, or use `data-calendar-part="frame"` for the scheduler |
|
|
34
|
+
| `useCalendarPointer` from `@moltenship/calendar-dnd` on 2.0 | 2.0 moved it to the React integration. Import it from `@moltenship/calendar` |
|
|
35
|
+
|
|
36
|
+
## State
|
|
37
|
+
|
|
38
|
+
| Mistake | Fix |
|
|
39
|
+
| -------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
|
|
40
|
+
| `view={view}` without `onViewChange` | A controlled value never changes on its own. Add the handler, or use `defaultView` |
|
|
41
|
+
| Both `view` and `defaultView` | One or the other |
|
|
42
|
+
| `selection={undefined}` to clear a controlled selection | `undefined` means uncontrolled. Pass `null` |
|
|
43
|
+
| Reading state with `useCalendarState()` for one value | `useCalendarSelector((state) => state.view)` re-renders less |
|
|
44
|
+
| A new `clock`, or a new `selection` object, each render | Those are compared by identity. Keep them in state or at module scope |
|
|
45
|
+
|
|
46
|
+
## Changes
|
|
47
|
+
|
|
48
|
+
| Mistake | Fix |
|
|
49
|
+
| -------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
|
|
50
|
+
| Expecting the calendar to move the event itself | It proposes. `onEventChange` must update the `events` you pass |
|
|
51
|
+
| No `onEventChange`, then wondering why nothing drags | Without it the calendar is read-only |
|
|
52
|
+
| Mutating a record in `onEventChange` | Return new records. Untouched ones stay the same objects |
|
|
53
|
+
| Reading `change.proposed.start` on a delete | `proposed` is `null` for a delete. Check `cause` first |
|
|
54
|
+
| Treating `change.id` as the event's ID | It's the change's ID. The event's is `change.eventId`, `null` for a create |
|
|
55
|
+
| A create handler that forgets to make an ID and a title | A create brings a placement and no record |
|
|
56
|
+
| Validation by throwing in `onEventChange` | Write a policy. Its `reason` reaches people and agents; a thrown error reads `handler-error` |
|
|
57
|
+
| Side effects in a policy | Policies also run for previews, where nothing is saved |
|
|
58
|
+
| `await proposeEventChange(…)` in a `try`/`catch` | It never rejects. Read `result.status` |
|
|
59
|
+
| Applying a slow save's result over a newer edit | Number changes as they start (`docs/interactions.md#pending-changes`) |
|
|
60
|
+
| An exhaustive `switch` on `detail.input` with three cases | 2.0 adds `"agent"`: four values |
|
|
61
|
+
| `onEventChange={save}` where `save` has its own second parameter | 2.0 passes the detail second. Wrap it: `onEventChange={(change) => save(change)}` |
|
|
62
|
+
| An `onEventChange` that starts a save and returns nothing | The change counts as saved at once. Return the promise, so it shows as pending until it lands |
|
|
63
|
+
|
|
64
|
+
## Agents
|
|
65
|
+
|
|
66
|
+
| Mistake | Fix |
|
|
67
|
+
| -------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
|
|
68
|
+
| No `label` on `Root` | The agent's name for the calendar becomes its title, which changes on every navigation |
|
|
69
|
+
| No `Calendar.Frame` | The calendar isn't listed for agents |
|
|
70
|
+
| A bridge per component, or created in render | One `createAgent()` for the app, in its own module |
|
|
71
|
+
| `createAgent()` with no `allow` in production | Without `allow` every step runs. List what's permitted |
|
|
72
|
+
| `allowAgentDelete` with `allow: () => true` | A delete needs a person's yes: return a promise from `allow` (`docs/agents/deleting.md`) |
|
|
73
|
+
| An `allow` that asks only for `deleteEvent`, with a ui-sdk delete button on the page | An agent's `press` on that button deletes as the agent. Ask for it too, or hide the button with `data-agent-hidden` |
|
|
74
|
+
| Passing `{ input: "api" }` from a button to keep a change from counting as the agent's | What an agent's step causes is `"agent"`, whatever the code passes |
|
|
75
|
+
| Importing `@ui-sdk/react/agent` in a Next.js route handler | On the server, `agentTools` comes from `@ui-sdk/core/agent` |
|
|
76
|
+
| Calling a model from the browser | The key stays on the server. The page only runs tool calls |
|
|
77
|
+
| Positional arguments: `args: ["review", "2026-10-09T10:00"]` | Every action takes one object: `args: [{ eventId: "review", start: "2026-10-09T10:00" }]` |
|
|
78
|
+
| An `onEventChange` that ignores `detail` | An agent's title arrives as `detail.fields.title`. Store it, or the event is saved unnamed |
|
|
79
|
+
| Storing `detail.fields` as it came | Nothing inside it is checked. Take the fields the app knows, and check each one's type |
|
|
80
|
+
| Listing events right after a `createEvent` that's `"saving"` | The new event is listed once the app's `events` has it. Read `getChange` first |
|
|
81
|
+
| An allow-list without `describeCalendar`, `listEvents`, `getChange` | Reading is made of steps. Without them the agent can't learn an event's ID |
|
|
82
|
+
| Reading `status: "saving"` or `"validating"` as saved | It isn't done. `getChange({ changeId })` says how it ended |
|
|
83
|
+
| Telling the model about an action that isn't there | The fifteen actions are in `agent-ready.md`. There's no dry run and no bulk action |
|
|
84
|
+
| Listing each action's arguments in the system prompt | Send the model to `describeCalendar`, which returns them for the version installed |
|
|
85
|
+
| A system prompt with today's date pasted in | `describeCalendar` returns `today` and `now` in the calendar's time zone |
|
|
86
|
+
| Expecting `deleteEvent` to fail with a calendar error | Without `allowAgentDelete` the action isn't there: the bridge says the calendar doesn't take it |
|
|
87
|
+
| Catching exceptions around `agent.act` | A failed step resolves with `ok: false`. Send the message back to the model as a result |
|
|
88
|
+
| Two versions of `@ui-sdk/core` | The agent sees `[]`. Keep every `@ui-sdk/*` package on one version |
|
|
89
|
+
| A model ID from memory | Use a current one, such as `claude-opus-5-5`, `claude-sonnet-5-5` or `claude-haiku-5-5` |
|
|
90
|
+
|
|
91
|
+
## Tests
|
|
92
|
+
|
|
93
|
+
| Mistake | Fix |
|
|
94
|
+
| -------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
|
|
95
|
+
| Fake timers or a patched `Temporal.Now` to fix the date | `createTestEnvironment()` fixes it through props |
|
|
96
|
+
| Pointer drags in jsdom | jsdom has no layout. Use the keyboard drivers there, and browser mode for pointers |
|
|
97
|
+
| Asserting right after a driver | `await calendar.settled()` first |
|
|
98
|
+
| Finding an event by its rendered text | `calendar.getEvent("Standup")`: by ID or title, whatever the locale |
|
|
99
|
+
| Asserting `detail.source === "mouse"` after a scripted click | A script's click reads `"programmatic"` |
|
|
100
|
+
| Mocking `@moltenship/calendar` | Render the real calendar with `renderCalendar` |
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# Solid
|
|
2
|
+
|
|
3
|
+
`@moltenship/calendar-solid` is the SolidJS 2 integration. It renders the same primitive as React, so state, actions, event changes, policies and the agent surface are the same. It has every hook React has. The Solid registry has ready-made views for the week and day, the month, the year and the agenda, each but the year also as a scrolling view, the resource columns and the resource timeline, with a toolbar, a view switcher, a mini month, the recurring-event dialog, the undo toast and a kit of controls. `calendar-full` installs all of them. `https://time.molten.sh/docs/solid/frameworks.md` says what Solid doesn't have. Read the Solid docs before you write Solid code, and check the package's own types. The docs in the package are React's. Solid's are on the site: `https://time.molten.sh/llms.txt` lists them, and `https://time.molten.sh/docs/solid/api/components.md` is the reference.
|
|
4
|
+
|
|
5
|
+
## What it has, and what it doesn't
|
|
6
|
+
|
|
7
|
+
| Has | Doesn't have |
|
|
8
|
+
| ----------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- |
|
|
9
|
+
| `createCalendar`, `defineCalendarView`, `Root` with the same props as React's | A testing package: `@moltenship/calendar-testing` is React only |
|
|
10
|
+
| Every part: the structural ones, `Event` and `Announcer` | `@moltenship/calendar-dnd-kit`, which has React as a peer |
|
|
11
|
+
| The read hooks: state, selector, actions, meta, range, projection, pending changes | The registry's views in StyleX: Solid's are Tailwind CSS |
|
|
12
|
+
| `useCalendarKeyboard`, `useRovingFocus`, `useCalendarFocus`, `useCalendarSelection` | |
|
|
13
|
+
| `useCalendarPointer`, `eventIdAttributes`, `resourceIdAttributes` | |
|
|
14
|
+
| `useCalendarInteraction`, `useCalendarDraft`, `useCalendarDraftReporter`, `useDraftBusy` | |
|
|
15
|
+
| `useCalendarAnnouncer`, `useCalendarHistory`, `useCalendarHistoryShortcuts` | |
|
|
16
|
+
| `useNow`, resources, status, availability, closed dates, annotations, `useAnchorDateRequests` | |
|
|
17
|
+
| `createStateSelector`, `createCalendarStore`, `resolveViewOptions`; the agent actions | |
|
|
18
|
+
| The registry's week and day, month, year, agenda, their scrolling versions, resource columns and resource timeline, its dialog and toast | |
|
|
19
|
+
|
|
20
|
+
Every hook React's integration exports has a Solid one with the same name. If the user asks for something in the right column, say Solid doesn't have it.
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pnpm add @moltenship/calendar-solid solid-js @solidjs/web @ui-sdk/core @ui-sdk/solid
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
- `@moltenship/calendar-solid` is the one package to import. It re-exports the engine and the Temporal helpers, so the adapter and the view functions come from it too.
|
|
29
|
+
- The views install with the shadcn CLI from the Solid registry: `npx shadcn@latest add https://time.molten.sh/r/solid/calendar-full.json` adds every Solid item but `base-tokens`, `list-view.json` the agenda alone, and `time-grid-view`, `month-view` and `year-view` the week and day, the month and the year. `scrolling-time-grid-view`, `scrolling-month-view` and `scrolling-list-view` add the scrolling week and day, month and agenda (`https://time.molten.sh/docs/solid/views/scrolling.md`), `resource-columns-view` the resource columns (`https://time.molten.sh/docs/solid/views/resource-columns.md`), and `resource-timeline-view` the resource timeline (`https://time.molten.sh/docs/solid/views/resource-timeline.md`). `https://time.molten.sh/docs/solid/installation.md` has the setup, and `https://time.molten.sh/docs/solid/views.md` links each view's page.
|
|
30
|
+
- The same registry's `calendar` item has the toolbar, the view switcher and the mini month (`https://time.molten.sh/docs/solid/views/toolbar.md`), and `calendar-ui` the controls they're built from (`https://time.molten.sh/docs/solid/views/controls.md`). `recurrence-scope-dialog` is the recurring-event dialog (`https://time.molten.sh/docs/solid/recurrence/calendar.md`), and `calendar-history-toast` the undo toast (`https://time.molten.sh/docs/solid/undo-redo.md`).
|
|
31
|
+
- Don't install `@moltenship/calendar` in a Solid app. It's the React package.
|
|
32
|
+
- 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.
|
|
33
|
+
|
|
34
|
+
## A calendar
|
|
35
|
+
|
|
36
|
+
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.
|
|
37
|
+
|
|
38
|
+
```tsx title="calendar.tsx"
|
|
39
|
+
import {
|
|
40
|
+
createCalendar,
|
|
41
|
+
defineCalendarView,
|
|
42
|
+
defineEventAdapter,
|
|
43
|
+
getListRange,
|
|
44
|
+
getListTitle,
|
|
45
|
+
navigateList,
|
|
46
|
+
projectList,
|
|
47
|
+
type CalendarEventInterval,
|
|
48
|
+
type CalendarViewRendererProps,
|
|
49
|
+
type ListProjection,
|
|
50
|
+
type ListViewOptions,
|
|
51
|
+
} from "@moltenship/calendar-solid";
|
|
52
|
+
import { For } from "solid-js";
|
|
53
|
+
|
|
54
|
+
export interface Meeting {
|
|
55
|
+
readonly id: string;
|
|
56
|
+
readonly title: string;
|
|
57
|
+
readonly interval: CalendarEventInterval;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const eventAdapter = defineEventAdapter<Meeting>()({
|
|
61
|
+
getId: (meeting) => meeting.id,
|
|
62
|
+
getTitle: (meeting) => meeting.title,
|
|
63
|
+
getInterval: (meeting) => meeting.interval,
|
|
64
|
+
getResourceIds: () => [],
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
type List = ListProjection<Meeting, string, string>;
|
|
68
|
+
|
|
69
|
+
// Props are getters: read `props.projection` in the JSX. Don't destructure it.
|
|
70
|
+
function Agenda(props: CalendarViewRendererProps<List, ListViewOptions>) {
|
|
71
|
+
return (
|
|
72
|
+
<For each={props.projection.days} fallback={<p>Nothing in these weeks.</p>}>
|
|
73
|
+
{(entry) => (
|
|
74
|
+
<section>
|
|
75
|
+
<h3>{entry.date.toLocaleString(props.environment.locale, { dateStyle: "full" })}</h3>
|
|
76
|
+
<ul>
|
|
77
|
+
<For each={entry.items}>
|
|
78
|
+
{(item) => <li data-event-id={item.event.id}>{item.event.title}</li>}
|
|
79
|
+
</For>
|
|
80
|
+
</ul>
|
|
81
|
+
</section>
|
|
82
|
+
)}
|
|
83
|
+
</For>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const listView = defineCalendarView({
|
|
88
|
+
name: "list",
|
|
89
|
+
defaultOptions: { weeks: 2 } as ListViewOptions,
|
|
90
|
+
strategy: {
|
|
91
|
+
getRange: (anchor, environment, options) => getListRange(anchor, environment, options),
|
|
92
|
+
getTitle: (range, environment) => getListTitle(range, environment),
|
|
93
|
+
navigate: (anchor, delta, options) => navigateList(anchor, delta, options),
|
|
94
|
+
project: (input) => projectList(input) as List,
|
|
95
|
+
},
|
|
96
|
+
Renderer: Agenda,
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
export const Calendar = createCalendar<Meeting>()({ eventAdapter, views: [listView] });
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
```tsx title="app.tsx"
|
|
103
|
+
import type { CalendarWeekRules } from "@moltenship/calendar-solid";
|
|
104
|
+
import { createSignal } from "solid-js";
|
|
105
|
+
|
|
106
|
+
import { Calendar, type Meeting } from "./calendar";
|
|
107
|
+
|
|
108
|
+
const timeZone = "Europe/Berlin";
|
|
109
|
+
const at = (value: string) =>
|
|
110
|
+
Temporal.PlainDateTime.from(value).toZonedDateTime(timeZone).toInstant();
|
|
111
|
+
|
|
112
|
+
const seed: readonly Meeting[] = [
|
|
113
|
+
{
|
|
114
|
+
id: "standup",
|
|
115
|
+
title: "Standup",
|
|
116
|
+
interval: { kind: "timed", start: at("2026-10-08T09:00"), end: at("2026-10-08T09:30") },
|
|
117
|
+
},
|
|
118
|
+
];
|
|
119
|
+
|
|
120
|
+
const weekRules: CalendarWeekRules = { firstDay: 1, minimalDays: 4, weekend: [6, 7] };
|
|
121
|
+
|
|
122
|
+
export function App() {
|
|
123
|
+
const [meetings, setMeetings] = createSignal<readonly Meeting[]>(seed);
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<Calendar.Root
|
|
127
|
+
label="Team calendar"
|
|
128
|
+
events={meetings()}
|
|
129
|
+
defaultAnchorDate={Temporal.PlainDate.from("2026-10-08")}
|
|
130
|
+
defaultTimeZone={timeZone}
|
|
131
|
+
locale="en-US"
|
|
132
|
+
weekRules={weekRules}
|
|
133
|
+
onEventChange={(change, detail) => {
|
|
134
|
+
// A title an agent sent with `createEvent` or `updateEvent`. A person's change has none.
|
|
135
|
+
const sent = detail.fields?.title;
|
|
136
|
+
const title = typeof sent === "string" && sent.trim() !== "" ? sent.trim() : undefined;
|
|
137
|
+
if (change.cause === "delete") {
|
|
138
|
+
setMeetings((current) => current.filter((meeting) => meeting.id !== change.eventId));
|
|
139
|
+
} else if (change.cause === "create") {
|
|
140
|
+
setMeetings((current) => [
|
|
141
|
+
...current,
|
|
142
|
+
{ id: crypto.randomUUID(), title: title ?? "New meeting", interval: change.proposed },
|
|
143
|
+
]);
|
|
144
|
+
} else {
|
|
145
|
+
setMeetings((current) =>
|
|
146
|
+
current.map((meeting) =>
|
|
147
|
+
meeting.id === change.eventId
|
|
148
|
+
? { ...meeting, title: title ?? meeting.title, interval: change.proposed }
|
|
149
|
+
: meeting,
|
|
150
|
+
),
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
}}
|
|
154
|
+
>
|
|
155
|
+
<Calendar.Frame>
|
|
156
|
+
<Calendar.Toolbar>
|
|
157
|
+
<Calendar.PreviousTrigger>Previous</Calendar.PreviousTrigger>
|
|
158
|
+
<Calendar.TodayTrigger>Today</Calendar.TodayTrigger>
|
|
159
|
+
<Calendar.NextTrigger>Next</Calendar.NextTrigger>
|
|
160
|
+
<Calendar.Title />
|
|
161
|
+
</Calendar.Toolbar>
|
|
162
|
+
<Calendar.Viewport>
|
|
163
|
+
<Calendar.ActiveView />
|
|
164
|
+
</Calendar.Viewport>
|
|
165
|
+
</Calendar.Frame>
|
|
166
|
+
</Calendar.Root>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Rules that differ from React
|
|
172
|
+
|
|
173
|
+
- **Hooks return accessors.** `const state = Calendar.useCalendarState()`, then `state().view`. `useCalendarActions()` returns the actions object itself.
|
|
174
|
+
- **Don't destructure.** A `Renderer`'s props, and `useCalendar()`'s `meta` and `state`, are getters. Read them in JSX, a memo or an effect.
|
|
175
|
+
- **Pass a signal's value to a prop that changes:** `events={meetings()}`, `view={view()}`.
|
|
176
|
+
- **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.
|
|
177
|
+
- **`class`, not `className`**, on the parts.
|
|
178
|
+
- **A trigger needs children or an `aria-label`.** TypeScript requires one of them.
|
|
179
|
+
- **An accessor has the new value once Solid flushes**, a microtask after the action.
|
|
180
|
+
- **`useCalendarKeyboard()` and `useCalendarPointer(options)` return refs**, not handlers: `<div ref={[keyboard, pointer]}>`. Spread `useRovingFocus(target)` on each day, slot and event.
|
|
181
|
+
- **Pass an accessor where an argument changes:** `useRovingFocus(() => ({ date: props.day.date, kind: "day" }))`. A plain value is read once.
|
|
182
|
+
- **Key a `For` by identity** so an element keeps its focus across projections: `keyed={(segment) => segment.event.id}`. The children then get accessors.
|
|
183
|
+
- **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.
|
|
184
|
+
|
|
185
|
+
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. The history hooks apply too, from `@moltenship/calendar-solid`. What they say about the registry's views is React's: in Solid, check the view's own page.
|
|
186
|
+
|
|
187
|
+
## Agents
|
|
188
|
+
|
|
189
|
+
```ts title="agent.ts"
|
|
190
|
+
import { createAgent } from "@ui-sdk/solid/agent";
|
|
191
|
+
|
|
192
|
+
// One bridge for the page. Import this module before the one that calls `render`.
|
|
193
|
+
export const agent = createAgent({
|
|
194
|
+
allow: (step) => step.action !== "deleteEvent",
|
|
195
|
+
});
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
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.
|
|
199
|
+
|
|
200
|
+
## Keyboard, dragging and undo
|
|
201
|
+
|
|
202
|
+
`https://time.molten.sh/docs/solid/accessibility.md` has a month view with the keyboard ref, `https://time.molten.sh/docs/solid/interactions.md` a week view with the pointer ref, and `https://time.molten.sh/docs/solid/undo-redo.md` the undo buttons. In short:
|
|
203
|
+
|
|
204
|
+
- Give the strategy a `getSpatialNavigation`, such as `monthSpatialNavigation`, or the keys move nothing.
|
|
205
|
+
- Pass `useCalendarPointer` the Renderer's `events`, `actions.proposeEventChange` as `onPropose`, `isReadOnly` as `disabled` and the environment's `timeZone`. Three more options are optional: `actions.checkEventChange` as `check` marks a preview a policy would reject, `useCalendarAnnouncer()` as `announcer` says each drag to a screen reader, and `useCalendarDraftReporter()` as `onPreview` lets `useCalendarDraft` and `useDraftBusy` follow the drag. Render `data-date` on each day, `eventIdAttributes(id)` on each event and `data-resize="start"` or `"end"` on its handles.
|
|
206
|
+
- Render `<Calendar.Announcer messages={...} />` inside `Root`. The registry's `calendar/announcements.ts` has English messages; the packages ship none.
|
|
207
|
+
- Record results in `Root`'s `onEventChangeResult` with `history.record`, then bind `useCalendarHistory(history)` and `useCalendarHistoryShortcuts(controls, () => ({ scope: meta().refs.frame }))`. Pass `createdEventId` to `createEventHistory` so creates can be undone.
|
|
208
|
+
|
|
209
|
+
A person can also change 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.
|
|
210
|
+
|
|
211
|
+
## Testing
|
|
212
|
+
|
|
213
|
+
`@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.
|