@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,188 @@
1
+ # Event changes
2
+
3
+ The calendar never edits your events. A drag, a keyboard move, a button of yours or an agent's step **proposes a change**. Policies check it, `onEventChange` saves it, and the app updates the `events` it passes. The full pages are `docs/interactions.md` and `docs/api/changes.md`.
4
+
5
+ ```text
6
+ drag · keys · proposeEventChange · agent step
7
+ │
8
+ ▼
9
+ policies ──reject──▶ result: rejected, with the policy's reason
10
+ │ accept / adjust / warn
11
+ ▼
12
+ onEventChange(change, detail) ──throws or rejects──▶ rolled back: handler-error
13
+ │ returns, or its promise resolves
14
+ ▼
15
+ onEventChangeResult(result, detail) how it ended, once per proposal
16
+ ```
17
+
18
+ ## Save a change
19
+
20
+ ```tsx title="editable-calendar.tsx"
21
+ "use client";
22
+
23
+ import {
24
+ minimumDurationPolicy,
25
+ snapPolicy,
26
+ type CalendarEventChange,
27
+ type CalendarPolicy,
28
+ } from "@moltenship/calendar";
29
+ import { useState } from "react";
30
+
31
+ import { Calendar, weekRules, type Meeting } from "./calendar";
32
+
33
+ type MeetingChange = CalendarEventChange<Meeting, string, never>;
34
+
35
+ function applyChange(meetings: readonly Meeting[], change: MeetingChange): readonly Meeting[] {
36
+ if (change.cause === "delete") {
37
+ return meetings.filter((meeting) => meeting.id !== change.eventId);
38
+ }
39
+ if (change.proposed.kind !== "timed") return meetings;
40
+
41
+ const { start, end } = change.proposed;
42
+ if (change.cause === "create") {
43
+ // A create brings times and no record: the app makes the record and its ID.
44
+ const meeting = change.event ?? {
45
+ id: crypto.randomUUID(),
46
+ title: "New meeting",
47
+ color: "blue" as const,
48
+ };
49
+ return [...meetings, { ...meeting, start, end }];
50
+ }
51
+ return meetings.map((meeting) =>
52
+ meeting.id === change.eventId ? { ...meeting, start, end } : meeting,
53
+ );
54
+ }
55
+
56
+ // Meetings always have a time, so a drop on the all-day row is refused with a reason.
57
+ const timedOnly: CalendarPolicy<Meeting, string, never> = ({ proposed }) =>
58
+ proposed === null || proposed.kind === "timed"
59
+ ? { type: "accept" }
60
+ : { type: "reject", reason: "meetings-need-a-time" };
61
+
62
+ export function EditableCalendar({ initial }: { readonly initial: readonly Meeting[] }) {
63
+ const [meetings, setMeetings] = useState(initial);
64
+
65
+ return (
66
+ <Calendar.Root
67
+ events={meetings}
68
+ onEventChange={(change) => setMeetings((current) => applyChange(current, change))}
69
+ policies={[timedOnly, snapPolicy({ minutes: 15 }), minimumDurationPolicy({ minutes: 15 })]}
70
+ defaultAnchorDate={Temporal.PlainDate.from("2026-10-08")}
71
+ defaultTimeZone="Europe/Berlin"
72
+ locale="en-US"
73
+ weekRules={weekRules}
74
+ >
75
+ <Calendar.Frame className="flex h-[640px] flex-col">
76
+ <Calendar.Viewport className="min-h-0 flex-1">
77
+ <Calendar.ActiveView />
78
+ </Calendar.Viewport>
79
+ </Calendar.Frame>
80
+ </Calendar.Root>
81
+ );
82
+ }
83
+ ```
84
+
85
+ ## The change object
86
+
87
+ | Field | Contents |
88
+ | ---------- | ---------------------------------------------------------------------------------------------- |
89
+ | `cause` | `"move"`, `"resize-start"`, `"resize-end"`, `"create"`, `"delete"` or `"update"` |
90
+ | `eventId` | The event's ID, or `null` for a create |
91
+ | `event` | Your record. `null` for a create, unless an undo restores a deleted record or a drop brings one |
92
+ | `original` | Where the event was, or `null` for a create |
93
+ | `proposed` | Where it should go: `{ kind, start, end, resourceIds }`, or `null` for a delete |
94
+ | `id` | The change's own ID, such as `change-3`. Not an event ID |
95
+ | `warnings` | Reasons policies flagged and let through. Absent when there are none |
96
+
97
+ Narrow before you read: check `cause === "delete"` before `proposed`, and `proposed.kind` before treating `start` as an instant.
98
+
99
+ `onEventChange`'s second argument is `{ input, history?, fields? }`. `input` is `"pointer"`, `"keyboard"`, `"api"` or `"agent"`. `"agent"` is anything an agent's step causes: the calendar's own actions, and a proposal the app's own button makes when an agent presses it. `history` is `"undo"` or `"redo"` for a change the event history proposes. `fields` is what the proposer sent beside the placement: an agent's `createEvent` and `updateEvent` put the title and the app's own fields there, with nothing inside them checked, and the handler stores what it accepts (`agent-ready.md#save-what-the-agent-sent`). A drag has none.
100
+
101
+ ## Saving that takes time
102
+
103
+ - A handler that returns nothing commits the change at once. Update the events in that handler.
104
+ - A handler that returns a promise keeps the change **pending** until it settles. The event shows in its new place meanwhile, with `isPending: true`, `data-pending` and `aria-busy`.
105
+ - Resolved: the calendar keeps showing the change until `events` next changes, so include the saved change in that update.
106
+ - Rejected, or the handler throws: the change is rolled back.
107
+ - Two changes to one event can save in either order. Number them as they start and apply a result only if no newer one was applied, as `docs/interactions.md#pending-changes` shows. Copy that pattern for a real backend.
108
+
109
+ `Calendar.useCalendarPendingChanges()` lists changes still on their way, for a "Saving…" indicator.
110
+
111
+ ## Policies
112
+
113
+ A policy is `(change, context) => decision`. `context` is `{ events, timeZone, availability?, detail? }`. A decision is `{ type: "accept" }`, `{ type: "adjust", proposed }`, `{ type: "reject", reason }` or `{ type: "warn", reason }`. Policies run in order, each on the change as the ones before adjusted it, and can be `async`.
114
+
115
+ | Built in | Does |
116
+ | ------------------------------------------- | -------------------------------------------------------------- |
117
+ | `snapPolicy({ minutes: 15 })` | Rounds to a grid in the calendar's time zone |
118
+ | `minimumDurationPolicy({ minutes: 15 })` | Lengthens what would be too short |
119
+ | `boundsPolicy({ start, end })` | Rejects what lands outside two instants: `out-of-bounds` |
120
+ | `availabilityPolicy({ mode })` | Blocks or warns outside working hours: `outside-availability` |
121
+ | `conflictPolicy({ mode, getResourceMode })` | Blocks or warns on double booking: `resource-conflict` |
122
+ | `readOnlyResourcesPolicy(isReadOnly)` | Rejects changes on marked resources: `read-only-resource` |
123
+ | `readOnlyPolicy()` | Always runs first. Don't pass it |
124
+
125
+ - **Put rules in policies, not in the handler.** A policy's `reason` reaches the person (as a refused drop) and an agent (as the step's error). An error thrown from `onEventChange` reads `handler-error`, for a person and an agent alike.
126
+ - **Keep policies free of side effects.** They also run to preview a drop or a keyboard move, with the `input` the commit will have, so a rule on `detail?.input` marks the preview the way it decides the drop.
127
+ - **Read `context.detail` as `detail?.input`.** It's `undefined` when code calls a policy outside a proposal.
128
+
129
+ ## Propose from your own UI
130
+
131
+ ```tsx title="push-back-button.tsx"
132
+ "use client";
133
+
134
+ import { Calendar, type Meeting } from "./calendar";
135
+
136
+ export function PushBackButton({ meeting }: { readonly meeting: Meeting }) {
137
+ const actions = Calendar.useCalendarActions();
138
+
139
+ async function pushBack() {
140
+ // Resolves with how it ended. It never rejects.
141
+ const result = await actions.proposeEventChange({
142
+ cause: "move",
143
+ eventId: meeting.id,
144
+ proposed: {
145
+ kind: "timed",
146
+ start: meeting.start.add({ hours: 1 }),
147
+ end: meeting.end.add({ hours: 1 }),
148
+ },
149
+ });
150
+ if (result.status === "rejected") console.warn(`Not moved: ${result.reason}`);
151
+ }
152
+
153
+ return (
154
+ <button type="button" onClick={pushBack}>
155
+ Push back an hour
156
+ </button>
157
+ );
158
+ }
159
+ ```
160
+
161
+ Create with `{ cause: "create", proposed: { kind, start, end } }`. Delete with `{ cause: "delete", eventId }`. A change to anything but time and resources, such as a title, is the app's own state update: the calendar isn't involved.
162
+
163
+ Rejection reasons: a policy's own reason, `read-only`, `invalid-placement` (an empty or reversed range), `handler-error`, `policy-error`, `superseded` (a newer change to the same event replaced it), `unknown-event`, and `agent-delete-not-allowed` (an agent caused a delete on a `Root` without `allowAgentDelete`).
164
+
165
+ ## How a change ended
166
+
167
+ `onEventChangeResult(result, detail)` hears every proposal once it settles: `result.status` is `"committed"` or `"rejected"` with a `reason`, and `detail.input` says who proposed it. Use it for a toast on a failed save, for logging, and for undo.
168
+
169
+ ## Undo and redo
170
+
171
+ ```tsx
172
+ import { createEventHistory, useCalendarHistory } from "@moltenship/calendar";
173
+
174
+ const [history] = useState(() => createEventHistory<Meeting, string, never>({ limit: 50 }));
175
+
176
+ <Calendar.Root onEventChangeResult={history.record} … />;
177
+
178
+ // Anywhere inside Root:
179
+ const { canRedo, canUndo, redo, undo } = useCalendarHistory(history);
180
+ ```
181
+
182
+ An undo is a proposal like any other: it goes through the policies and `onEventChange`. Undoing a create or a delete needs the history to find the record a create became (`createdEventId`). Read `docs/undo-redo.md#creates-and-deletes` before wiring that. The history records every input by default, an agent's included.
183
+
184
+ ## Dragging
185
+
186
+ With `onEventChange` set, the registry views let people move, resize and create with a mouse, a pen, touch and the keyboard. There is nothing to turn on. Each finished drag sends exactly one change. Clicking an empty slot creates nothing: creating needs a drag, or keys.
187
+
188
+ To drag the app's own items into the calendar, use `@moltenship/calendar-dnd-kit` (`docs/guides/dnd-kit.md`).
@@ -0,0 +1,168 @@
1
+ # Compose a calendar
2
+
3
+ A calendar is three things: an adapter that reads your records, a `Calendar` made from the views you want, and a `Root` that renders it. The full walk-through is `docs/quick-start.md`.
4
+
5
+ ## 1. Add the views
6
+
7
+ The views are source files, added with the shadcn CLI from the registry at `https://time.molten.sh/r/`. They're built on shadcn/ui with Base UI primitives, so `style` in the app's `components.json` must start with `base-`. Check for existing files in `components/calendar/` before adding: the app may already have them.
8
+
9
+ ```bash
10
+ npx shadcn@latest add \
11
+ https://time.molten.sh/r/time-grid-view.json \
12
+ https://time.molten.sh/r/month-view.json \
13
+ https://time.molten.sh/r/list-view.json
14
+ ```
15
+
16
+ | Registry item | Factories | Import from `@/components/calendar/…` | Docs page |
17
+ | -------------------------- | ------------------------------------------------------------------------- | -------------------------------------------------------- | --------------------------------- |
18
+ | `time-grid-view` | `createWeekView`, `createDayView`, `createThreeDayView` | `time-grid-view/time-grid-view` | `docs/views/week-and-day.md` |
19
+ | `month-view` | `createMonthView` | `month-view/month-view` | `docs/views/month.md` |
20
+ | `year-view` | `createYearView` | `year-view/year-view` | `docs/views/year.md` |
21
+ | `list-view` | `createAgendaView` | `list-view/agenda-view` | `docs/views/agenda.md` |
22
+ | `resource-columns-view` | `createResourceColumnsView` | `resource-columns-view/resource-columns-view` | `docs/views/resource-columns.md` |
23
+ | `resource-timeline-view` | `createTimelineDayView`, `createTimelineWeekView`, `createTimelineMonthView` | `resource-timeline-view/resource-timeline-view` | `docs/views/resource-timeline.md` |
24
+ | `scrolling-time-grid-view` | `createScrollingWeekView`, `createScrollingDayView`, `createScrollingThreeDayView` | `scrolling-time-grid-view/scrolling-time-grid-view` | `docs/views/scrolling.md` |
25
+ | `scrolling-month-view` | `createScrollingMonthView` | `scrolling-month-view/scrolling-month-view` | `docs/views/scrolling.md` |
26
+ | `scrolling-list-view` | `createScrollingAgendaView` | `scrolling-list-view/scrolling-agenda-view` | `docs/views/agenda.md` |
27
+ | `calendar-full` | Every other item in this table | | `docs/installation.md` |
28
+ | `calendar-history-toast` | `CalendarHistoryToast` (an Undo toast) | `calendar-history-toast/calendar-history-toast` | `docs/undo-redo.md` |
29
+ | `recurrence-scope-dialog` | "This event, following, or all?" | `recurrence-scope-dialog/use-recurrence-scope-prompt` | `docs/guides/recurring-events.md` |
30
+
31
+ Every view item brings the shared `calendar` item: `calendar-toolbar`, `view-switcher`, `event-colors`, `announcements`, the theme. Each item also has a `stylex-` twin for apps on StyleX (`docs/stylex.md`).
32
+
33
+ `shadcn add` installs `@moltenship/calendar` and doesn't add `@ui-sdk/core` or `@ui-sdk/react`. Install those yourself.
34
+
35
+ Read a view's docs page for its options before you set any. Options differ between views.
36
+
37
+ ## 2. The adapter and the calendar
38
+
39
+ ```tsx title="calendar.tsx"
40
+ "use client";
41
+
42
+ import { createCalendar, defineEventAdapter } from "@moltenship/calendar";
43
+
44
+ import type { CalendarEventColor } from "@/components/calendar/event-colors";
45
+ import { createMonthView } from "@/components/calendar/month-view/month-view";
46
+ import { createDayView, createWeekView } from "@/components/calendar/time-grid-view/time-grid-view";
47
+
48
+ export interface Meeting {
49
+ readonly id: string;
50
+ readonly title: string;
51
+ readonly start: Temporal.Instant;
52
+ readonly end: Temporal.Instant;
53
+ readonly color: CalendarEventColor;
54
+ }
55
+
56
+ // Called twice on purpose: the first call fixes the record type, the second infers the ID types.
57
+ export const eventAdapter = defineEventAdapter<Meeting>()({
58
+ getId: (meeting) => meeting.id,
59
+ getTitle: (meeting) => meeting.title,
60
+ getInterval: (meeting) => ({ kind: "timed", start: meeting.start, end: meeting.end }),
61
+ getResourceIds: () => [],
62
+ });
63
+
64
+ const getEventColor = (meeting: Meeting) => meeting.color;
65
+
66
+ // Also called twice: type arguments first, then the options.
67
+ export const Calendar = createCalendar<Meeting>()({
68
+ eventAdapter,
69
+ views: [
70
+ createWeekView<Meeting>({ dayView: "day", getEventColor }),
71
+ createDayView<Meeting>({ getEventColor }),
72
+ createMonthView<Meeting>({ getEventColor }),
73
+ ],
74
+ });
75
+
76
+ export const weekRules = { firstDay: 1, minimalDays: 4, weekend: [6, 7] } as const;
77
+ ```
78
+
79
+ - `getInterval` returns `{ kind: "timed", start, end }` with instants, `{ kind: "all-day", start, end }` with plain dates, or `{ kind: "floating", start, end }` with plain date-times. The end is exclusive.
80
+ - Optional adapter fields: `isReadOnly`, `isBusy`, `getRevision` (`docs/api/events.md`).
81
+ - The first view in `views` is shown first. View names must be unique, and TypeScript learns them from the list, so `setView("yaer")` is a type error.
82
+ - Records already in the library's shape (`{ id, title, start, end, data }`) can use `createCanonicalEventAdapter<TData>()` instead of writing an adapter.
83
+ - Create `Calendar` and the adapter at module scope, never inside a component.
84
+
85
+ ## 3. Render it
86
+
87
+ ```tsx title="team-calendar.tsx"
88
+ "use client";
89
+
90
+ import { CalendarToolbar } from "@/components/calendar/calendar-toolbar";
91
+ import { ViewSwitcher } from "@/components/calendar/view-switcher";
92
+
93
+ import { Calendar, weekRules, type Meeting } from "./calendar";
94
+
95
+ const viewLabels = { week: "Week", day: "Day", month: "Month" };
96
+ const viewOptions = Calendar.views.map(({ name }) => ({ value: name, label: viewLabels[name] }));
97
+
98
+ function CalendarViewSwitcher() {
99
+ const view = Calendar.useCalendarSelector((state) => state.view);
100
+ const { setView } = Calendar.useCalendarActions();
101
+ return <ViewSwitcher value={view} onValueChange={setView} options={viewOptions} />;
102
+ }
103
+
104
+ export function TeamCalendar({ meetings }: { readonly meetings: readonly Meeting[] }) {
105
+ return (
106
+ <Calendar.Root
107
+ label="Team calendar"
108
+ events={meetings}
109
+ defaultAnchorDate={Temporal.Now.plainDateISO("Europe/Berlin")}
110
+ defaultTimeZone="Europe/Berlin"
111
+ locale="en-US"
112
+ weekRules={weekRules}
113
+ >
114
+ <Calendar.Frame className="flex h-[640px] flex-col rounded-xl border">
115
+ <CalendarToolbar calendar={Calendar}>
116
+ <CalendarViewSwitcher />
117
+ </CalendarToolbar>
118
+ <Calendar.Viewport className="min-h-0 flex-1">
119
+ <Calendar.ActiveView />
120
+ </Calendar.Viewport>
121
+ </Calendar.Frame>
122
+ </Calendar.Root>
123
+ );
124
+ }
125
+ ```
126
+
127
+ `Root` requires `events`, `locale`, `weekRules`, a date (`defaultAnchorDate` or `anchorDate`) and a time zone (`defaultTimeZone` or `timeZone`). It renders no element of its own.
128
+
129
+ The registry toolbar's buttons use shadcn's `Tooltip`: the app needs one `TooltipProvider` from `@/components/ui/tooltip` around it.
130
+
131
+ With server rendering, the server and the browser must agree on the date and time. Pass `now` (a `Temporal.Instant` made on the server) and a fixed date instead of `Temporal.Now` in the component (`docs/guides/nextjs.md`).
132
+
133
+ ## The parts
134
+
135
+ Each part renders one element with a `data-calendar-part` attribute and takes that element's props.
136
+
137
+ | Part | Renders | Notes |
138
+ | ------------------------------------------------- | ----------- | ------------------------------------------------------------------ |
139
+ | `Calendar.Root` | nothing | Holds the state. Everything else goes inside |
140
+ | `Calendar.Frame` | `<section>` | Named by `Root`'s `label`, or else by the title. Agents find the calendar by it |
141
+ | `Calendar.Toolbar` | `<header>` | A wrapper for controls |
142
+ | `Calendar.Title` | `<span>` | The active view's title |
143
+ | `Calendar.PreviousTrigger`, `NextTrigger`, `TodayTrigger` | `<button>` | Give each text or an `aria-label` |
144
+ | `Calendar.ViewSwitcher` | `<select>` | Needs `getViewLabel(name)` |
145
+ | `Calendar.Viewport` | `<div>` | Wraps the view |
146
+ | `Calendar.ActiveView` | the view | Renders the active view's `Renderer` |
147
+ | `Calendar.Event` | your output | Looks one event up by `eventId` and calls `children` with it |
148
+ | `Calendar.Announcer` | `<div>` | A live region for screen readers. Needs `messages`, as `calendarAnnouncements` from `@/components/calendar/announcements` |
149
+
150
+ The registry's `CalendarToolbar` composes `Toolbar`, the three triggers and `Title`. Use the bare parts when the app has its own toolbar.
151
+
152
+ `Frame`, `Title` and `Viewport` don't take `id`. Set `id` on `Root`.
153
+
154
+ ## Resources
155
+
156
+ Rooms or people that events belong to are `resources` on `Root`, and `getResourceIds` in the adapter says which ones an event is on. The resource views need them: `docs/views/resource-columns.md`, `docs/views/resource-timeline.md`, `docs/concepts/events.md#resources`.
157
+
158
+ ## Recurring events
159
+
160
+ Recurrence is a layer over ordinary events, in `@moltenship/calendar-recurrence`: you expand series into occurrences and pass those as `events`. Read `docs/concepts/recurrence.md` and `docs/guides/recurring-events.md` before writing any of it. Don't expand RRULEs by hand.
161
+
162
+ ## A view of your own
163
+
164
+ `defineCalendarView({ name, defaultOptions, strategy, Renderer })` from `@moltenship/calendar`. Write `strategy` before `Renderer` in the object, so the Renderer's `projection` gets its type from `strategy.project`. Read `docs/views/custom-views.md` first, and `docs/interactions.md#in-your-own-views` if people should drag events in it.
165
+
166
+ ## Styling
167
+
168
+ The views are styled with Tailwind classes and CSS variables from the `calendar-theme` item. Change tokens in your own CSS rules, not in the block `shadcn add` writes (`docs/theming.md`). Event colors come from `getEventColor` and the palette in `event-colors`.
@@ -0,0 +1,98 @@
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 whose style isn't `base-*` | The views need Base UI primitives. Check `components.json` first |
31
+ | Installing only `@moltenship/calendar` on 2.0 | Also `@ui-sdk/core` and `@ui-sdk/react`. `shadcn add` doesn't add them |
32
+ | 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 |
33
+
34
+ ## State
35
+
36
+ | Mistake | Fix |
37
+ | -------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
38
+ | `view={view}` without `onViewChange` | A controlled value never changes on its own. Add the handler, or use `defaultView` |
39
+ | Both `view` and `defaultView` | One or the other |
40
+ | `selection={undefined}` to clear a controlled selection | `undefined` means uncontrolled. Pass `null` |
41
+ | Reading state with `useCalendarState()` for one value | `useCalendarSelector((state) => state.view)` re-renders less |
42
+ | A new `clock`, or a new `selection` object, each render | Those are compared by identity. Keep them in state or at module scope |
43
+
44
+ ## Changes
45
+
46
+ | Mistake | Fix |
47
+ | -------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
48
+ | Expecting the calendar to move the event itself | It proposes. `onEventChange` must update the `events` you pass |
49
+ | No `onEventChange`, then wondering why nothing drags | Without it the calendar is read-only |
50
+ | Mutating a record in `onEventChange` | Return new records. Untouched ones stay the same objects |
51
+ | Reading `change.proposed.start` on a delete | `proposed` is `null` for a delete. Check `cause` first |
52
+ | Treating `change.id` as the event's ID | It's the change's ID. The event's is `change.eventId`, `null` for a create |
53
+ | A create handler that forgets to make an ID and a title | A create brings a placement and no record |
54
+ | Validation by throwing in `onEventChange` | Write a policy. Its `reason` reaches people and agents; a thrown error reads `handler-error` |
55
+ | Side effects in a policy | Policies also run for previews, where nothing is saved |
56
+ | `await proposeEventChange(…)` in a `try`/`catch` | It never rejects. Read `result.status` |
57
+ | Applying a slow save's result over a newer edit | Number changes as they start (`docs/interactions.md#pending-changes`) |
58
+ | An exhaustive `switch` on `detail.input` with three cases | 2.0 adds `"agent"`: four values |
59
+ | `onEventChange={save}` where `save` has its own second parameter | 2.0 passes the detail second. Wrap it: `onEventChange={(change) => save(change)}` |
60
+ | 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 |
61
+
62
+ ## Agents
63
+
64
+ | Mistake | Fix |
65
+ | -------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
66
+ | No `label` on `Root` | The agent's name for the calendar becomes its title, which changes on every navigation |
67
+ | No `Calendar.Frame` | The calendar isn't listed for agents |
68
+ | A bridge per component, or created in render | One `createAgent()` for the app, in its own module |
69
+ | `createAgent()` with no `allow` in production | Without `allow` every step runs. List what's permitted |
70
+ | `allowAgentDelete` with `allow: () => true` | A delete needs a person's yes: return a promise from `allow` (`docs/agents/deleting.md`) |
71
+ | 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` |
72
+ | 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 |
73
+ | Importing `@ui-sdk/react/agent` in a Next.js route handler | On the server, `agentTools` comes from `@ui-sdk/core/agent` |
74
+ | Calling a model from the browser | The key stays on the server. The page only runs tool calls |
75
+ | Positional arguments: `args: ["review", "2026-10-09T10:00"]` | Every action takes one object: `args: [{ eventId: "review", start: "2026-10-09T10:00" }]` |
76
+ | An `onEventChange` that ignores `detail` | An agent's title arrives as `detail.fields.title`. Store it, or the event is saved unnamed |
77
+ | Storing `detail.fields` as it came | Nothing inside it is checked. Take the fields the app knows, and check each one's type |
78
+ | Listing events right after a `createEvent` that's `"saving"` | The new event is listed once the app's `events` has it. Read `getChange` first |
79
+ | An allow-list without `describeCalendar`, `listEvents`, `getChange` | Reading is made of steps. Without them the agent can't learn an event's ID |
80
+ | Reading `status: "saving"` or `"validating"` as saved | It isn't done. `getChange({ changeId })` says how it ended |
81
+ | 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 |
82
+ | Listing each action's arguments in the system prompt | Send the model to `describeCalendar`, which returns them for the version installed |
83
+ | A system prompt with today's date pasted in | `describeCalendar` returns `today` and `now` in the calendar's time zone |
84
+ | Expecting `deleteEvent` to fail with a calendar error | Without `allowAgentDelete` the action isn't there: the bridge says the calendar doesn't take it |
85
+ | Catching exceptions around `agent.act` | A failed step resolves with `ok: false`. Send the message back to the model as a result |
86
+ | Two versions of `@ui-sdk/core` | The agent sees `[]`. Keep every `@ui-sdk/*` package on one version |
87
+ | A model ID from memory | Use a current one, such as `claude-opus-5-5`, `claude-sonnet-5-5` or `claude-haiku-5-5` |
88
+
89
+ ## Tests
90
+
91
+ | Mistake | Fix |
92
+ | -------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
93
+ | Fake timers or a patched `Temporal.Now` to fix the date | `createTestEnvironment()` fixes it through props |
94
+ | Pointer drags in jsdom | jsdom has no layout. Use the keyboard drivers there, and browser mode for pointers |
95
+ | Asserting right after a driver | `await calendar.settled()` first |
96
+ | Finding an event by its rendered text | `calendar.getEvent("Standup")`: by ID or title, whatever the locale |
97
+ | Asserting `detail.source === "mouse"` after a scripted click | A script's click reads `"programmatic"` |
98
+ | Mocking `@moltenship/calendar` | Render the real calendar with `renderCalendar` |