@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,194 @@
1
+ # Installation
2
+
3
+ Requirements, packages, the ui-sdk peer dependencies, and Temporal setup.
4
+
5
+ Source: https://time.molten.sh/docs/installation
6
+
7
+ ## Requirements
8
+
9
+ - **React 19.** React and React DOM are peer dependencies.
10
+ - **ui-sdk.** `@ui-sdk/core` and `@ui-sdk/react` are peer dependencies since 2.0. The calendar's
11
+ parts are [ui-sdk](https://ui-sdk.dev) components, which is how an [agent](./agents.md) reaches
12
+ them. ui-sdk is in beta: the calendar takes `0.1.0-beta.16` and the betas after it.
13
+ - **A JavaScript runtime with `Temporal`.** Node.js 26 and later include it. Browser support is
14
+ still rolling out, so check the
15
+ [MDN compatibility table](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal#browser_compatibility)
16
+ for the browsers you support and add a polyfill if needed (see below).
17
+ - **TypeScript 6 or later** with `"lib": ["DOM", "DOM.Iterable", "ESNext"]`. `ESNext` has the
18
+ `Temporal` types.
19
+
20
+ ## Install
21
+
22
+ > **2.0 is a pre-release**
23
+ >
24
+ > These docs describe Time 2.0. Its API can still change before 2.0.0, and so can ui-sdk's while it
25
+ > is in beta. Coming from 1.x? See [Migrating to 2.0](./migrating-to-2.md).
26
+
27
+ **pnpm**
28
+
29
+ ```bash
30
+ pnpm add @moltenship/calendar @ui-sdk/core @ui-sdk/react react react-dom
31
+ ```
32
+
33
+ **npm**
34
+
35
+ ```bash
36
+ npm install @moltenship/calendar @ui-sdk/core @ui-sdk/react react react-dom
37
+ ```
38
+
39
+ **yarn**
40
+
41
+ ```bash
42
+ yarn add @moltenship/calendar @ui-sdk/core @ui-sdk/react react react-dom
43
+ ```
44
+
45
+ **bun**
46
+
47
+ ```bash
48
+ bun add @moltenship/calendar @ui-sdk/core @ui-sdk/react react react-dom
49
+ ```
50
+
51
+ `@moltenship/calendar` is the only calendar package most apps import. It includes the React
52
+ components, the event engine, the Temporal helpers, and the pointer interactions. Recurring events
53
+ add `@moltenship/calendar-recurrence`, reading ICS feeds `@moltenship/ics`, and dragging your own
54
+ dnd-kit items into the calendar `@moltenship/calendar-dnd-kit`. See
55
+ [How it works](./concepts/how-it-works.md) for what's inside.
56
+
57
+ You import ui-sdk yourself in one case: to create the [agent bridge](./agents/connect.md), from
58
+ `@ui-sdk/react/agent`. Keep one copy of `@ui-sdk/core` in your app. The calendar and the bridge
59
+ find each other through it, and with two copies an agent sees no calendar. Your package manager
60
+ keeps one as long as every `@ui-sdk/*` package is on the same version.
61
+
62
+ For SolidJS 2, install `@moltenship/calendar-solid` instead; see [Solid](./api/solid.md).
63
+
64
+ ## Temporal
65
+
66
+ Time uses the global `Temporal` object and never bundles a polyfill. In a runtime without
67
+ `Temporal`, load one before any code that imports the calendar. This entry file loads
68
+ [`temporal-polyfill`](https://www.npmjs.com/package/temporal-polyfill) only where it's missing,
69
+ then loads the app:
70
+
71
+ ```tsx title="main.tsx"
72
+ if (!("Temporal" in globalThis)) await import("temporal-polyfill/global");
73
+
74
+ // Import the app afterwards, so no module runs before Temporal exists.
75
+ const { App } = await import("./app");
76
+ ```
77
+
78
+ Any polyfill that defines `globalThis.Temporal` works.
79
+
80
+ ## TypeScript
81
+
82
+ Make sure your `tsconfig.json` includes the `ESNext` library so `Temporal` is typed:
83
+
84
+ ```json title="tsconfig.json"
85
+ {
86
+ "compilerOptions": {
87
+ "lib": ["DOM", "DOM.Iterable", "ESNext"]
88
+ }
89
+ }
90
+ ```
91
+
92
+ ## UI source (optional)
93
+
94
+ The packages render plain, unstyled elements. The styled views, toolbar and theme are source files
95
+ that you add to your app and then own, the way shadcn/ui works. They install with the shadcn CLI
96
+ from this site's registry. There's no other installer.
97
+
98
+ **Step 1**
99
+
100
+ Set up [shadcn/ui](https://ui.shadcn.com/docs/installation) with Tailwind CSS 4 if your app
101
+ doesn't use it yet. The files need shadcn's default primitives, built on
102
+ [Base UI](https://base-ui.com), which `init` sets up:
103
+
104
+ ```bash
105
+ npx shadcn@latest init
106
+ ```
107
+
108
+ If your app already uses shadcn/ui, check that `style` in `components.json` starts with `base-`,
109
+ such as `base-nova`. `shadcn add` installs components in your app's existing style, and the
110
+ calendar's files don't compile against primitives from other styles.
111
+
112
+ **Step 2**
113
+
114
+ Add the calendar. `calendar-full` installs every view, the theme and the parts they share:
115
+
116
+ ```bash
117
+ npx shadcn@latest add https://time.molten.sh/r/calendar-full.json
118
+ ```
119
+
120
+ Or add only the views you use. Each one brings what it builds on: the theme, the shared
121
+ `calendar` parts, the shadcn components it uses, and npm packages such as `@moltenship/calendar`.
122
+
123
+ | Item | What it adds |
124
+ | -------------------------- | ---------------------------------------------------------------------------- |
125
+ | `calendar-full` | Every item below |
126
+ | `calendar-theme` | The calendar's tokens and event colors, added to your global CSS |
127
+ | `calendar` | `CalendarToolbar`, `ViewSwitcher`, `EventChip`, `MiniMonth` and shared parts |
128
+ | `time-grid-view` | The [week and day](./views/week-and-day.md) views |
129
+ | `month-view` | The [month](./views/month.md) view |
130
+ | `list-view` | The [agenda](./views/agenda.md) view |
131
+ | `year-view` | The [year](./views/year.md) view |
132
+ | `scrolling-time-grid-view` | The [scrolling](./views/scrolling.md) week and day views |
133
+ | `scrolling-month-view` | The scrolling month view |
134
+ | `scrolling-list-view` | The scrolling agenda |
135
+ | `resource-columns-view` | The [resource columns](./views/resource-columns.md) view |
136
+ | `resource-timeline-view` | The [resource timeline](./views/resource-timeline.md) views |
137
+ | `recurrence-scope-dialog` | The [recurrence scope dialog](./guides/recurring-events.md) |
138
+ | `calendar-history-toast` | The [undo toast](./undo-redo.md#undo-toast) |
139
+
140
+ Each item's address is `https://time.molten.sh/r/<item>.json`:
141
+
142
+ ```bash
143
+ npx shadcn@latest add https://time.molten.sh/r/month-view.json
144
+ ```
145
+
146
+ The files land in `calendar/` under the `components` alias in your `components.json`, such as
147
+ `components/calendar/month-view/month-view.tsx`, and their imports follow your aliases. Each item
148
+ asks for the `@moltenship/calendar` versions it was built for, and `shadcn add` installs a
149
+ matching one. It doesn't add `@ui-sdk/core` and `@ui-sdk/react` to your `package.json`; install
150
+ them as above.
151
+
152
+ To add items by name, add the registry to `components.json` once:
153
+
154
+ ```json title="components.json"
155
+ {
156
+ "registries": {
157
+ "@moltenship": "https://time.molten.sh/r/{name}.json"
158
+ }
159
+ }
160
+ ```
161
+
162
+ Then `npx shadcn@latest add @moltenship/month-view` works too.
163
+
164
+ **Step 3**
165
+
166
+ The toolbar's buttons use shadcn's tooltip, so wrap your app in `TooltipProvider` from
167
+ `@/components/ui/tooltip` once, as `shadcn add` reminds you and shadcn's
168
+ [tooltip instructions](https://ui.shadcn.com/docs/components/tooltip) describe.
169
+
170
+ For an app on StyleX and Astryx rather than Tailwind, every item has a `stylex-` version; see
171
+ [StyleX](./stylex.md).
172
+
173
+ The theme's tokens and rules go into your global CSS inside `@layer base`, so your own rules win
174
+ over them. Each `shadcn add` writes that block again, so change tokens in your own rules instead,
175
+ as [Theming](./theming.md#changing-tokens) shows. Run `shadcn add` again to update the files: it
176
+ asks before it replaces a file you already have, and `--overwrite` replaces them all, with any
177
+ changes you made.
178
+
179
+ ## Run from source
180
+
181
+ To work on Time, or to try changes that aren't released yet, run it and this documentation site
182
+ from the repository. You need Node.js 26 and the [Vite+ CLI](https://viteplus.dev/guide/) (`vp`).
183
+
184
+ ```bash
185
+ git clone https://github.com/Moltenship/time.git
186
+ cd time
187
+ vp install
188
+ vp run dev
189
+ ```
190
+
191
+ `vp run dev` starts this site locally. The examples on these pages are real files in
192
+ `apps/showcase/content/examples`, type-checked against the current packages.
193
+
194
+ Next, build a calendar in the [Quick start](./quick-start.md).
@@ -0,0 +1,408 @@
1
+ # Interactions
2
+
3
+ Save moved, resized, created, and deleted events, show them while they save, and decide which changes to allow.
4
+
5
+ Source: https://time.molten.sh/docs/interactions
6
+
7
+ Time never edits your events itself. When someone moves, resizes, creates, or deletes an event, the
8
+ calendar **proposes a change**. Your `onEventChange` handler saves it and updates your events. While
9
+ it saves, the calendar shows the change as **pending**; if saving fails, the event goes back to where
10
+ it was.
11
+
12
+ This page uses the `Calendar` and `Meeting` from the [Quick start](./quick-start.md).
13
+
14
+ ## Saving changes
15
+
16
+ Pass `onEventChange` to `Root`. Without it, the calendar is read-only: the views start no drags or
17
+ keyboard grabs and draw no resize handles, and every change proposed through `actions` is rejected
18
+ as `read-only`.
19
+
20
+ ```tsx title="editable-calendar.tsx"
21
+ export function EditableCalendar() {
22
+ const [meetings, setMeetings] = useState(initialMeetings);
23
+ // Number changes as they start, and remember the newest one applied to each event, so a slow
24
+ // save never replaces a newer saved edit.
25
+ const nextOrder = useRef(0);
26
+ const lastApplied = useRef(new Map<string, number>());
27
+
28
+ return (
29
+ <Calendar.Root
30
+ events={meetings}
31
+ onEventChange={async (change) => {
32
+ const order = ++nextOrder.current;
33
+ await saveToServer(change);
34
+ if (change.eventId !== null) {
35
+ if ((lastApplied.current.get(change.eventId) ?? 0) > order) return;
36
+ lastApplied.current.set(change.eventId, order);
37
+ }
38
+ setMeetings((current) => applyChange(current, change));
39
+ }}
40
+ policies={[timedOnly, snapPolicy({ minutes: 15 }), minimumDurationPolicy({ minutes: 15 })]}
41
+ defaultAnchorDate={Temporal.PlainDate.from("2026-10-08")}
42
+ defaultTimeZone="Europe/Berlin"
43
+ locale="en-US"
44
+ weekRules={weekRules}
45
+ >
46
+ <Calendar.ActiveView />
47
+ </Calendar.Root>
48
+ );
49
+ }
50
+ ```
51
+
52
+ The handler receives a change object:
53
+
54
+ | Field | Contents |
55
+ | ---------- | ---------------------------------------------------------------------------------------------------------------------- |
56
+ | `cause` | `"move"`, `"resize-start"`, `"resize-end"`, `"create"`, `"delete"`, or `"update"` |
57
+ | `eventId` | The event's ID, or `null` for `"create"` |
58
+ | `event` | Your record. For `"create"`, `null`, or the record an [undo](./undo-redo.md#creates-and-deletes) restores |
59
+ | `original` | Where the event was, as the user saw it, or `null` for `"create"` |
60
+ | `proposed` | Where it should go: a range with `kind`, `start`, `end`, and `resourceIds`, or `null` for `"delete"` |
61
+ | `id` | Identifies the change within this calendar, such as `change-3`. It isn't an event ID |
62
+ | `warnings` | Reasons policies flagged the change with but let through, such as `"outside-availability"`. Absent when there are none |
63
+
64
+ The handler's second argument is the detail the change was proposed with: `{ input }`, one of
65
+ `"pointer"`, `"keyboard"`, `"api"` or `"agent"`. `"api"` is your own `proposeEventChange` call, and
66
+ `"agent"` is an AI agent acting through the [agent bridge](./agents.md). A change an
67
+ [event history](./undo-redo.md) proposes also has `history`, `"undo"` or `"redo"`. An agent that
68
+ names or renames an event sends the title in `detail.fields`, which a handler has to read to save
69
+ it: see [Save what the agent sent](./agents/connect.md#save-what-the-agent-sent).
70
+
71
+ `applyChange` turns a change into new state. A created event needs an ID of your own, usually from
72
+ your server; this example makes one up. Records you don't touch stay the same objects:
73
+
74
+ ```tsx title="editable-calendar.tsx"
75
+ import {
76
+ eventPlacement,
77
+ minimumDurationPolicy,
78
+ moveEventPlacement,
79
+ snapPolicy,
80
+ type CalendarEventChange,
81
+ type CalendarPolicy,
82
+ type CalendarProposalDetail,
83
+ type CalendarTransactionResult,
84
+ } from "@moltenship/calendar";
85
+ import { useEffect, useRef, useState } from "react";
86
+
87
+ import { Calendar, meetings as initialMeetings, weekRules, type Meeting } from "./quick-start";
88
+
89
+ type MeetingChange = CalendarEventChange<Meeting, string, never>;
90
+
91
+ function applyChange(meetings: readonly Meeting[], change: MeetingChange): readonly Meeting[] {
92
+ if (change.cause === "delete") {
93
+ return meetings.filter((meeting) => meeting.id !== change.eventId);
94
+ }
95
+ if (change.proposed.kind !== "timed") return meetings;
96
+
97
+ const { start, end } = change.proposed;
98
+ if (change.cause === "create") {
99
+ const id = crypto.randomUUID();
100
+ return [...meetings, { id, title: "New meeting", color: "blue", start, end }];
101
+ }
102
+ return meetings.map((meeting) =>
103
+ meeting.id === change.eventId ? { ...meeting, start, end } : meeting,
104
+ );
105
+ }
106
+ ```
107
+
108
+ ## Pending changes
109
+
110
+ How long a change stays pending depends on your handler:
111
+
112
+ - **A handler that returns nothing** (or doesn't `await`) commits the change right away. Update your
113
+ events in the same handler.
114
+ - **A handler that returns a promise** keeps the change pending until the promise settles. The event
115
+ shows in its new place in the meantime.
116
+ - If the promise resolves, the calendar keeps showing the change until your `events` next change.
117
+ From then on your `events` decide where the event is, so include the saved change in that
118
+ update, as `setMeetings` does in the example. If another update arrives first, such as a
119
+ refetch that doesn't have the change yet, the event moves to where that update puts it.
120
+ - If it rejects or the handler throws, the change is undone.
121
+
122
+ ```tsx title="editable-calendar.tsx"
123
+ async function saveToServer(change: MeetingChange): Promise<void> {
124
+ const response = await fetch("/api/meeting-changes", {
125
+ method: "POST",
126
+ headers: { "content-type": "application/json" },
127
+ body: JSON.stringify(change),
128
+ });
129
+ if (!response.ok) throw new Error(`Saving failed with ${response.status}`);
130
+ }
131
+ ```
132
+
133
+ Pending events have `isPending: true` in projections, in `meta.eventSnapshot`, and in
134
+ `Calendar.Event`. Every built-in view renders them at 60% opacity with `data-pending` and
135
+ `aria-busy`, and adds "saving" to the event's accessible name. Target those attributes to style
136
+ pending events your own way. A keyboard gesture previews the grabbed event the same way, so it also
137
+ reads `isPending: true` until the gesture ends; the built-in views don't show it as saving.
138
+
139
+ If the same event changes again before the first change finishes saving, the calendar shows the
140
+ newer change. Your handler still receives both, unless an async policy was still deciding on the
141
+ first; that one is rejected with the reason `superseded` and never reaches your handler. Their saves can finish in either
142
+ order, or one can fail. The example numbers each change as it starts. When a save succeeds, it updates the state
143
+ only if no newer change to that event has been applied yet. So a slow save never replaces a newer
144
+ saved edit, and if the newer save fails, the older one that succeeded is still shown. Your server
145
+ needs the same care, for example by rejecting writes that carry an outdated version.
146
+
147
+ ### Across the calendar
148
+
149
+ `Calendar.useCalendarPendingChanges()` lists every change still on its way, for a calendar-wide
150
+ "Saving…" or a question before the page closes. It returns a read-only `Map` from change ID to
151
+ `{ change, phase }`, in the order the changes were proposed:
152
+
153
+ | `phase` | Meaning |
154
+ | ----------------- | ---------------------------------------------------------------------------------------------- |
155
+ | `validating` | An async policy is still deciding; your handler hasn't seen the change yet |
156
+ | `saving` | Your handler's promise is still running |
157
+ | `awaiting-events` | The promise resolved, but your `events` don't show the change yet; it ends with your next ones |
158
+
159
+ The map includes creates, and an older change to an event that is still saving after a newer one
160
+ replaced it on screen. A change that never waits, with policies that answer at once and a handler
161
+ that returns no promise, never shows. Neither does a keyboard gesture's preview: it isn't a change yet.
162
+
163
+ Pass a selector, and the component re-renders only when what it picks changes; `{ isEqual }`
164
+ compares another way than `Object.is`. Without one, it re-renders whenever a change starts, moves to
165
+ its next phase, or ends.
166
+
167
+ ```tsx title="saving-status.tsx"
168
+ // Anywhere inside Root, such as in the toolbar.
169
+ export function SavingStatus() {
170
+ // Saved changes that only wait for your events don't count.
171
+ const saving = Calendar.useCalendarPendingChanges((changes) =>
172
+ [...changes.values()].some(({ phase }) => phase !== "awaiting-events"),
173
+ );
174
+
175
+ useEffect(() => {
176
+ if (!saving) return;
177
+ // Ask before the page closes while a change is still on its way.
178
+ const warn = (event: BeforeUnloadEvent) => event.preventDefault();
179
+ window.addEventListener("beforeunload", warn);
180
+ return () => window.removeEventListener("beforeunload", warn);
181
+ }, [saving]);
182
+
183
+ return <output>{saving ? "Saving…" : "All changes saved"}</output>;
184
+ }
185
+ ```
186
+
187
+ ## How changes end
188
+
189
+ `onEventChangeResult` on `Root` hears how every proposal ended: drags, keyboard moves and creates,
190
+ and your own `proposeEventChange` calls. It gets the result `proposeEventChange` resolves with, and
191
+ the detail it was proposed with, `{ input }`: `"pointer"`, `"keyboard"`, `"api"`, or `"agent"` for
192
+ an [AI agent](./agents/changes.md)'s change. Use it for a toast when a drop is refused or a save fails, to log what happens, or to record changes to
193
+ [undo](./undo-redo.md):
194
+
195
+ ```tsx title="editable-calendar.tsx"
196
+ // <Calendar.Root onEventChangeResult={reportOutcome} … />
197
+ export function reportOutcome(
198
+ result: CalendarTransactionResult<Meeting, string, never>,
199
+ { input }: CalendarProposalDetail,
200
+ ) {
201
+ if (result.status === "committed") return;
202
+ // An AbortError is your own handler cancelling the change, not a failed save.
203
+ if (result.error instanceof DOMException && result.error.name === "AbortError") return;
204
+ console.warn(`A ${input} change wasn't saved: ${result.reason}`, result.error);
205
+ }
206
+ ```
207
+
208
+ - It's called once per proposal, after the proposal settles, before code that awaits
209
+ `proposeEventChange` goes on. A cancelled drag or keyboard gesture proposes nothing, so it isn't
210
+ called. It's read from the latest render, so it can be inline.
211
+ - `committed` means your handler finished. After an async save the change can still wait for your
212
+ `events`, as `awaiting-events` above.
213
+ - Each result belongs to its own proposal. When a newer change to an event replaced an older one,
214
+ the older one's late failure is still reported, though the newer change stays on screen.
215
+ - A rejected result has a [reason](#changing-events-from-your-own-ui). If the callback throws, the
216
+ error is reported with `reportError`, as an uncaught error is, and the result stays as it was.
217
+
218
+ ## Policies
219
+
220
+ Policies decide which changes are allowed. Each one looks at a change and accepts it, adjusts it,
221
+ rejects it, or accepts it with a warning in `change.warnings`. They run in order, and each sees the change as adjusted by the ones before it. Pass
222
+ them to `Root` as `policies`, as in the example above.
223
+
224
+ | Policy | What it does |
225
+ | ------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
226
+ | `snapPolicy({ minutes: 15 })` | Rounds timed and floating changes to a grid in the calendar's time zone |
227
+ | `minimumDurationPolicy({ minutes: 15 })` | Lengthens timed and floating events that would be shorter than the minimum |
228
+ | `boundsPolicy({ start, end })` | Rejects changes that end up outside the given instants |
229
+ | `availabilityPolicy({ mode })` | Blocks changes outside [working hours](./availability.md), or saves them with a warning in `change.warnings` |
230
+ | `conflictPolicy({ mode, getResourceMode })` | Blocks a change that makes a busy event overlap another busy event on one of its resources, saves it with a warning, or allows it, by a mode per resource. Deletes always pass. See [double booking](./availability.md#double-booking) |
231
+ | `readOnlyResourcesPolicy(isReadOnly)` | Rejects changes to the schedule of the resources `isReadOnly(resourceId)` marks |
232
+ | `readOnlyPolicy()` | Rejects changes to events your adapter marks with `isReadOnly`. `Root` always runs it first, so you don't need to pass it. |
233
+
234
+ A policy is a function, so you can write your own. This one keeps meetings out of the all-day row.
235
+ Policies can also be `async`, for example to check availability on your server.
236
+
237
+ A policy's second argument is a context: the `events` as the user sees them, the calendar's
238
+ `timeZone`, its `availability`, and the proposal's `detail`. Read `detail?.input` to treat one input differently, such as refusing an
239
+ [agent's change](./agents/changes.md#refuse-an-agents-change) that a person may make. `detail` is
240
+ absent when a policy runs outside a proposal.
241
+
242
+ ```tsx title="editable-calendar.tsx"
243
+ // Meetings always have a time, so refuse drops onto the all-day row.
244
+ const timedOnly: CalendarPolicy<Meeting, string, never> = ({ proposed }) =>
245
+ proposed === null || proposed.kind === "timed"
246
+ ? { type: "accept" }
247
+ : { type: "reject", reason: "meetings-need-a-time" };
248
+ ```
249
+
250
+ ## Changing events from your own UI
251
+
252
+ Buttons, forms, and dialogs can propose changes too, with `proposeEventChange` from
253
+ `useCalendarActions()` (or the `actions` prop inside a view). The change goes through the same
254
+ policies, pending state, and handler as a drag. The returned promise tells you how it ended; it
255
+ never rejects. `onEventChange`, policies and `onEventChangeResult` hear it with the input `"api"`; a
256
+ gesture layer of your own can name its input as the second argument, as in
257
+ `proposeEventChange(proposal, { input: "pointer" })`.
258
+
259
+ ```tsx title="push-back-button.tsx"
260
+ export function PushBackButton({ meeting }: { readonly meeting: Meeting }) {
261
+ const actions = Calendar.useCalendarActions();
262
+ const [message, setMessage] = useState("");
263
+
264
+ async function pushBack() {
265
+ const result = await actions.proposeEventChange({
266
+ cause: "move",
267
+ eventId: meeting.id,
268
+ proposed: {
269
+ kind: "timed",
270
+ start: meeting.start.add({ hours: 1 }),
271
+ end: meeting.end.add({ hours: 1 }),
272
+ },
273
+ });
274
+ setMessage(result.status === "committed" ? "Moved" : `Not moved: ${result.reason}`);
275
+ }
276
+
277
+ return (
278
+ <>
279
+ <button type="button" onClick={pushBack}>
280
+ Push back an hour
281
+ </button>
282
+ <output>{message}</output>
283
+ </>
284
+ );
285
+ }
286
+ ```
287
+
288
+ A rejected result has a `reason`, and the `change` it would have made, except for
289
+ `unknown-event`:
290
+
291
+ | `reason` | Meaning |
292
+ | -------------------------- | --------------------------------------------------------------------------------------- |
293
+ | `read-only` | The event is read-only, or `Root` has no `onEventChange` |
294
+ | a policy's reason | A policy rejected it, such as `out-of-bounds` |
295
+ | `superseded` | A newer change for the same event replaced it |
296
+ | `handler-error` | Your handler threw or its promise rejected; `error` has the cause |
297
+ | `policy-error` | A policy threw |
298
+ | `invalid-placement` | The proposed range is empty or reversed |
299
+ | `unknown-event` | No event has that ID |
300
+ | `agent-delete-not-allowed` | An [agent](./agents/deleting.md) caused a delete, and `Root` has no `allowAgentDelete` |
301
+
302
+ To create an event, propose `{ cause: "create", proposed: { kind, start, end } }`. To delete one,
303
+ propose `{ cause: "delete", eventId }`.
304
+
305
+ ## Drag, resize, and create
306
+
307
+ Once `Root` has an `onEventChange` handler, the built-in views let people edit events with the
308
+ mouse, a pen, or touch:
309
+
310
+ | View | Move | Resize | Create |
311
+ | ------------ | -------------------------------------------------------------------- | --------------------------- | ----------------------------------------------- |
312
+ | Week and day | Across days and times. Dropping on the all-day row makes it all-day. | Drag the top or bottom edge | Drag across empty time, or across all-day cells |
313
+ | Month | Across days. Timed events keep their time. | – | Drag across days to make an all-day event |
314
+
315
+ The resource columns and resource timeline views, and the scrolling week, day and month views, use
316
+ the same pointer layer; a drop on another resource swaps that resource in the event's
317
+ `resourceIds`.
318
+
319
+ Each finished drag sends exactly one change to your handler, so the policies and pending state above
320
+ apply. A few details:
321
+
322
+ - Time grids snap to 15 minutes, and a resized event keeps at least one slot. Hour timelines snap
323
+ to 30 minutes, and day timelines step whole days.
324
+ - A movement under 4px is a click, so clicking an event still works. The click that ends a drag
325
+ doesn't count as a click.
326
+ - Escape cancels a drag, and so does dropping outside the view.
327
+ - On touch screens, press and hold for about half a second to start a drag; a finger that moves
328
+ sooner scrolls. Once a drag starts, the page holds still under it. While the calendar is
329
+ editable, the built-in views select no text and show no callout on a touch screen, so a
330
+ long-press only picks events up.
331
+ - The view scrolls when you drag near any edge of its scroll container.
332
+ - Read-only events (your adapter's `isReadOnly`) can't be dragged and have no resize handles.
333
+ - While dragging, the original event dims (it has `data-dragging`) and a preview follows the
334
+ pointer. Dragging never re-renders the view.
335
+
336
+ Clicking an empty slot doesn't create an event; creating needs a drag.
337
+
338
+ ### From the rest of the page
339
+
340
+ Items of your own, such as unscheduled tasks, can be dragged into the calendar, and events dragged
341
+ out to your own drop zones. With dnd-kit, [`@moltenship/calendar-dnd-kit`](./api/dnd-kit.md) does
342
+ both, as [Drag tasks in with dnd-kit](./guides/dnd-kit.md) shows live; without it, the pointer layer's [drags from and to the rest of the page](./api/changes.md#drags-from-and-to-the-rest-of-the-page)
343
+ take the points of any drag library. A dropped item is a create carrying your record as
344
+ `change.event`, through the same policies and handler.
345
+
346
+ ### In your own views
347
+
348
+ The built-in views use `useCalendarPointer`, and your views can too. Call it in the Renderer with
349
+ the props the Renderer receives, and put the returned ref on the element that contains the days.
350
+ Pass `isReadOnly` as `disabled`, so a calendar without `onEventChange` starts no drags, and draw no
351
+ resize handles while it's set:
352
+
353
+ ```tsx title="my-week-view.tsx"
354
+ import { defineCalendarView, timeGridStrategy, useCalendarPointer } from "@moltenship/calendar";
355
+
356
+ export const myWeekView = defineCalendarView({
357
+ name: "week",
358
+ strategy: timeGridStrategy({ kind: "week" }),
359
+ Renderer: function MyWeek({ actions, environment, events, isReadOnly, projection }) {
360
+ const ref = useCalendarPointer({
361
+ columns: projection.days.map((day) => day.column),
362
+ disabled: isReadOnly,
363
+ events,
364
+ onPropose: actions.proposeEventChange,
365
+ timeZone: environment.timeZone,
366
+ });
367
+
368
+ return (
369
+ <div
370
+ ref={ref}
371
+ // On a touch screen, a long-press picks an event up instead of selecting its text.
372
+ className={
373
+ isReadOnly
374
+ ? undefined
375
+ : "pointer-coarse:select-none pointer-coarse:[-webkit-touch-callout:none]"
376
+ }
377
+ >
378
+ {/* Day columns with data-date, events with data-event-id */}
379
+ </div>
380
+ );
381
+ },
382
+ });
383
+ ```
384
+
385
+ Pass `columns` in views with a time axis: a time grid, resource columns or an hour timeline. A month
386
+ grid or a day timeline finds days by their `data-date`. The hook reads these attributes from your markup:
387
+
388
+ | Element | Attribute |
389
+ | ----------------------------------------------------------- | ----------------------------------------------------------- |
390
+ | A day column in a time grid, covering 24 hours | `data-date="2026-10-08"` |
391
+ | An all-day cell | `data-date="…" data-all-day` |
392
+ | A day cell in a month grid | `data-date="…"` |
393
+ | An event (render it as a `<button>`) | `data-event-id` |
394
+ | A resize handle inside an event | `data-resize="start"` or `"end"` |
395
+ | A control that never starts a drag | `data-calendar-pointer="none"` |
396
+ | A cell or row of one resource, in a resource view | `data-resource-id`, from `resourceIdAttributes(id)` |
397
+ | An event whose ID is a number | `data-event-id-type="number"`, from `eventIdAttributes(id)` |
398
+ | The element inside an event that shows its time | `data-event-time` |
399
+ | A part over the cells, such as a sticky header | `data-occludes` |
400
+ | A timeline's time strip for one date, its date in `columns` | `data-date="…" data-axis="inline"` |
401
+
402
+ On touch screens, a long-press should pick an event up rather than select its text: while
403
+ `isReadOnly` is false, give the element with the ref `user-select: none` and
404
+ `-webkit-touch-callout: none` for a coarse pointer, as the built-in views do with
405
+ `pointer-coarse:select-none pointer-coarse:[-webkit-touch-callout:none]`.
406
+
407
+ The [pointer layer reference](./api/changes.md#pointer-layer) lists the hook's options and styling
408
+ hooks.