@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.
Files changed (78) hide show
  1. package/README.md +27 -6
  2. package/dist/index.d.mts +3 -3
  3. package/dist/index.mjs +2 -2
  4. package/docs/accessibility.md +305 -0
  5. package/docs/agents/changes.md +449 -0
  6. package/docs/agents/coding-agents.md +116 -0
  7. package/docs/agents/connect.md +444 -0
  8. package/docs/agents/deleting.md +296 -0
  9. package/docs/agents/reference.md +511 -0
  10. package/docs/agents/server.md +317 -0
  11. package/docs/agents/webmcp.md +153 -0
  12. package/docs/agents.md +355 -0
  13. package/docs/annotations.md +198 -0
  14. package/docs/api/changes.md +264 -0
  15. package/docs/api/components.md +245 -0
  16. package/docs/api/dnd-kit.md +265 -0
  17. package/docs/api/events.md +153 -0
  18. package/docs/api/primitives.md +218 -0
  19. package/docs/api/store.md +92 -0
  20. package/docs/api.md +57 -0
  21. package/docs/availability.md +576 -0
  22. package/docs/comparison.md +278 -0
  23. package/docs/concepts/anatomy.md +73 -0
  24. package/docs/concepts/events.md +163 -0
  25. package/docs/concepts/how-it-works.md +112 -0
  26. package/docs/concepts/state.md +244 -0
  27. package/docs/concepts/time.md +168 -0
  28. package/docs/customization.md +271 -0
  29. package/docs/frameworks.md +116 -0
  30. package/docs/guides/dnd-kit.md +333 -0
  31. package/docs/guides/google-calendar-sync.md +1246 -0
  32. package/docs/guides/google-calendar.md +367 -0
  33. package/docs/guides/motion.md +414 -0
  34. package/docs/guides/nextjs-app-router.md +630 -0
  35. package/docs/guides/nextjs.md +149 -0
  36. package/docs/guides/performance.md +103 -0
  37. package/docs/guides/tanstack-query.md +485 -0
  38. package/docs/ics/feed.md +484 -0
  39. package/docs/ics/import.md +183 -0
  40. package/docs/ics/reference.md +482 -0
  41. package/docs/ics.md +142 -0
  42. package/docs/index.md +149 -0
  43. package/docs/installation.md +209 -0
  44. package/docs/interactions.md +441 -0
  45. package/docs/llms.txt +99 -0
  46. package/docs/migrating-to-2.md +497 -0
  47. package/docs/quick-start.md +163 -0
  48. package/docs/recurrence/calendar.md +598 -0
  49. package/docs/recurrence/model.md +128 -0
  50. package/docs/recurrence/reference.md +547 -0
  51. package/docs/recurrence.md +122 -0
  52. package/docs/stylex.md +290 -0
  53. package/docs/temporal/daylight-saving-time.md +172 -0
  54. package/docs/temporal/month-grid.md +119 -0
  55. package/docs/temporal/reference.md +167 -0
  56. package/docs/temporal.md +105 -0
  57. package/docs/testing.md +600 -0
  58. package/docs/theme-builder.md +82 -0
  59. package/docs/theming.md +275 -0
  60. package/docs/undo-redo.md +347 -0
  61. package/docs/views/agenda.md +222 -0
  62. package/docs/views/custom-views.md +195 -0
  63. package/docs/views/month.md +110 -0
  64. package/docs/views/resource-columns.md +265 -0
  65. package/docs/views/resource-timeline.md +226 -0
  66. package/docs/views/scrolling.md +193 -0
  67. package/docs/views/week-and-day.md +258 -0
  68. package/docs/views/year.md +138 -0
  69. package/docs/views.md +69 -0
  70. package/package.json +42 -14
  71. package/skills/moltenship-time/SKILL.md +77 -0
  72. package/skills/moltenship-time/references/agent-ready.md +272 -0
  73. package/skills/moltenship-time/references/changes.md +188 -0
  74. package/skills/moltenship-time/references/compose.md +175 -0
  75. package/skills/moltenship-time/references/mistakes.md +100 -0
  76. package/skills/moltenship-time/references/solid.md +213 -0
  77. package/skills/moltenship-time/references/state.md +129 -0
  78. package/skills/moltenship-time/references/testing.md +176 -0
@@ -0,0 +1,441 @@
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/react/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 shows where it
334
+ would land. Dragging never re-renders the view.
335
+
336
+ Clicking an empty slot doesn't create an event; creating needs a drag.
337
+
338
+ ### Snapped and free drags
339
+
340
+ By default the preview snaps: it draws the event where a drop would land, so it steps from slot to
341
+ slot. Set a view's `dragPreview` option to `"free"` and the preview follows the pointer instead:
342
+
343
+ - **Move:** a copy of the event moves with the pointer, pixel for pixel, over a marker of where a
344
+ drop would land. On release the copy slides onto the event in its new place.
345
+ - **Resize:** on a time axis, the dragged edge stays under the pointer while the marker steps from
346
+ slot to slot. A resized event still keeps at least one slot.
347
+ - **Create:** on a time axis, the new range grows with the pointer, from the slot you pressed in.
348
+
349
+ In a month grid or a day timeline, a resize or create still steps whole days, as it does when
350
+ snapped.
351
+
352
+ ```tsx
353
+ <Calendar.Root viewOptions={{ week: { dragPreview: "free" } }} />
354
+ ```
355
+
356
+ > Live example: see it at https://time.molten.sh/docs/react/interactions
357
+
358
+ The drop is the same in both modes. Your handler, the policies, the draft hooks, the announcements
359
+ and your own drop zones all hear the snapped placement, never the pointer's exact position.
360
+
361
+ The copy settles in 150ms with an ease-out curve. Under `prefers-reduced-motion: reduce` it doesn't
362
+ slide: the event just appears in its new place. Escape, a drop outside the view, and a drop that a
363
+ policy or your handler refuses right away all send the copy back to where the event started.
364
+
365
+ If your handler returns nothing and updates your events only later, after a save, the copy slides
366
+ to where the drop landed and disappears before the event shows up there. Return the save's promise
367
+ instead, so the event shows in its new place while it's [pending](#pending-changes).
368
+
369
+ The [pointer layer](./api/changes.md#pointer-layer) documents the marker's styling hooks.
370
+
371
+ ### From the rest of the page
372
+
373
+ Items of your own, such as unscheduled tasks, can be dragged into the calendar, and events dragged
374
+ out to your own drop zones. With dnd-kit, [`@moltenship/calendar-dnd-kit`](./api/dnd-kit.md) does
375
+ 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)
376
+ take the points of any drag library. A dropped item is a create carrying your record as
377
+ `change.event`, through the same policies and handler.
378
+
379
+ ### In your own views
380
+
381
+ The built-in views use `useCalendarPointer`, and your views can too. Call it in the Renderer with
382
+ the props the Renderer receives, and put the returned ref on the element that contains the days.
383
+ Pass `isReadOnly` as `disabled`, so a calendar without `onEventChange` starts no drags, and draw no
384
+ resize handles while it's set:
385
+
386
+ ```tsx title="my-week-view.tsx"
387
+ import { defineCalendarView, timeGridStrategy, useCalendarPointer } from "@moltenship/calendar";
388
+
389
+ export const myWeekView = defineCalendarView({
390
+ name: "week",
391
+ strategy: timeGridStrategy({ kind: "week" }),
392
+ Renderer: function MyWeek({ actions, environment, events, isReadOnly, projection }) {
393
+ const ref = useCalendarPointer({
394
+ columns: projection.days.map((day) => day.column),
395
+ disabled: isReadOnly,
396
+ events,
397
+ onPropose: actions.proposeEventChange,
398
+ timeZone: environment.timeZone,
399
+ });
400
+
401
+ return (
402
+ <div
403
+ ref={ref}
404
+ // On a touch screen, a long-press picks an event up instead of selecting its text.
405
+ className={
406
+ isReadOnly
407
+ ? undefined
408
+ : "pointer-coarse:select-none pointer-coarse:[-webkit-touch-callout:none]"
409
+ }
410
+ >
411
+ {/* Day columns with data-date, events with data-event-id */}
412
+ </div>
413
+ );
414
+ },
415
+ });
416
+ ```
417
+
418
+ Pass `columns` in views with a time axis: a time grid, resource columns or an hour timeline. A month
419
+ grid or a day timeline finds days by their `data-date`. The hook reads these attributes from your markup:
420
+
421
+ | Element | Attribute |
422
+ | ----------------------------------------------------------- | ----------------------------------------------------------- |
423
+ | A day column in a time grid, covering 24 hours | `data-date="2026-10-08"` |
424
+ | An all-day cell | `data-date="…" data-all-day` |
425
+ | A day cell in a month grid | `data-date="…"` |
426
+ | An event (render it as a `<button>`) | `data-event-id` |
427
+ | A resize handle inside an event | `data-resize="start"` or `"end"` |
428
+ | A control that never starts a drag | `data-calendar-pointer="none"` |
429
+ | A cell or row of one resource, in a resource view | `data-resource-id`, from `resourceIdAttributes(id)` |
430
+ | An event whose ID is a number | `data-event-id-type="number"`, from `eventIdAttributes(id)` |
431
+ | The element inside an event that shows its time | `data-event-time` |
432
+ | A part over the cells, such as a sticky header | `data-occludes` |
433
+ | A timeline's time strip for one date, its date in `columns` | `data-date="…" data-axis="inline"` |
434
+
435
+ On touch screens, a long-press should pick an event up rather than select its text: while
436
+ `isReadOnly` is false, give the element with the ref `user-select: none` and
437
+ `-webkit-touch-callout: none` for a coarse pointer, as the built-in views do with
438
+ `pointer-coarse:select-none pointer-coarse:[-webkit-touch-callout:none]`.
439
+
440
+ The [pointer layer reference](./api/changes.md#pointer-layer) lists the hook's options and styling
441
+ hooks.
package/docs/llms.txt ADDED
@@ -0,0 +1,99 @@
1
+ # Moltenship Time
2
+
3
+ > A calendar on the Temporal API whose engine imports no UI framework. React renders it, with week, day, month, year, agenda and resource views you copy and own, and drag and keyboard editing. SolidJS 2 renders it too, with the same views in Tailwind CSS. It is built on ui-sdk, so an AI agent can read a calendar and act on it once the app creates a bridge.
4
+
5
+ These are the docs for @moltenship/calendar 2.0.0, as Markdown. Each link below is a file beside this one. They're generated from the same source as https://time.molten.sh/docs/react, where the live examples run.
6
+
7
+ Read this index first, then only the pages your task needs. To let an AI agent operate a calendar, start at [Agents](./agents.md). The exact API is in the package's `.d.mts` types.
8
+
9
+ ## Get started
10
+
11
+ - [Introduction](./index.md): A calendar engine on the Temporal API, rendered in React and in SolidJS 2, with actions an AI agent can call.
12
+ - [Installation](./installation.md): Requirements, the packages to install, the ui-sdk peer dependencies, and Temporal setup.
13
+ - [Quick start](./quick-start.md): Build a week, day, month and agenda calendar in React with the built-in views.
14
+ - [React and Solid](./frameworks.md): What the React and SolidJS 2 integrations share, what each one has, and what Solid doesn't have.
15
+
16
+ ## Build a calendar
17
+
18
+ - [Concepts: How it works](./concepts/how-it-works.md): The packages, which of them React and Solid share, and how your events become a rendered view.
19
+ - [Concepts: Anatomy](./concepts/anatomy.md): The parts a calendar is built from, and their names in code.
20
+ - [Concepts: Events and adapters](./concepts/events.md): How Time reads your event records, and what happens when one is invalid.
21
+ - [Concepts: Time and time zones](./concepts/time.md): Timed, all-day, and floating events, exclusive end times, and daylight saving time.
22
+ - [Concepts: State](./concepts/state.md): Let the calendar own its state, or control it from your app, one value at a time.
23
+ - [Views: Overview](./views.md): How views work, how to switch between them, and which ones exist today.
24
+ - [Views: Week and day](./views/week-and-day.md): Time-grid views with an all-day row, a current-time line, and DST-aware hours.
25
+ - [Views: Month](./views/month.md): A month grid with multi-day bars and a "+N more" popover.
26
+ - [Views: Year](./views/year.md): Twelve months at a glance, with a dot for each event color on a day and a popover of its events.
27
+ - [Views: Scrolling views](./views/scrolling.md): Week, day and month views that scroll without end, swiping a page at a time.
28
+ - [Views: Agenda](./views/agenda.md): A chronological list of upcoming events, grouped by day, and a version that scrolls through months or years.
29
+ - [Views: Resource columns](./views/resource-columns.md): A day or a few days of rooms or people side by side, grouped by team, with hundreds of columns.
30
+ - [Views: Resource timeline](./views/resource-timeline.md): Rooms or people as rows and time as columns, for a day, a week or a month, with hundreds of rows.
31
+ - [Views: Custom views](./views/custom-views.md): Define a view with a pure strategy and a Renderer component.
32
+ - [Interactions](./interactions.md): Save moved, resized, created, and deleted events, show them while they save, and decide which changes to allow.
33
+ - [Undo and redo](./undo-redo.md): Record the changes people make, and take them back through the same pipeline that saved them.
34
+ - [Availability](./availability.md): Working hours, closed days and holidays, people and rooms in their own time zones, shading you can restyle, a busy or free status, and policies that keep bookings inside working hours and rooms from being double-booked.
35
+ - [Annotations](./annotations.md): Time-based information beside events, such as listening history, sleep, workouts and focus sessions.
36
+ - [Accessibility](./accessibility.md): The keyboard map, screen reader announcements, the ARIA patterns each view uses, reduced motion, and right-to-left layout.
37
+ - [Testing](./testing.md): Test the calendar you built with a fixed clock, typed builders, a render harness, and keyboard and pointer drivers.
38
+ - [Guides: Next.js and server rendering](./guides/nextjs.md): Fetch events in a Server Component and render the same calendar on the server and in the browser.
39
+ - [Guides: Next.js App Router example](./guides/nextjs-app-router.md): A calendar whose view and date live in the URL, loaded by a Server Component and saved through Server Actions.
40
+ - [Guides: Google Calendar events](./guides/google-calendar.md): Read recurring events from the Google Calendar API, with their RRULE, EXDATE and RDATE lines, and show and edit them.
41
+ - [Guides: Sync with Google Calendar](./guides/google-calendar-sync.md): Load a Google calendar from the dates on screen, keep it current with sync tokens, and write changes back with etags.
42
+ - [Guides: Load events with TanStack Query](./guides/tanstack-query.md): Fetch the dates the calendar shows with useQuery, and save its changes with useMutation and optimistic updates.
43
+ - [Guides: Drag tasks in with dnd-kit](./guides/dnd-kit.md): Drag a backlog of your own into the calendar, and meetings back out, with dnd-kit and @moltenship/calendar-dnd-kit.
44
+ - [Guides: Animate with Motion](./guides/motion.md): Grow a clicked meeting into its card and let a card follow each drag, with Motion and the calendar's own hooks.
45
+ - [Guides: Performance](./guides/performance.md): Where Time does its work, and how to keep that work small.
46
+
47
+ ## Recurring events
48
+
49
+ - [Overview](./recurrence.md): What @moltenship/calendar-recurrence is, how to install it, and a first expansion of a rule into dates.
50
+ - [Series and occurrences](./recurrence/model.md): Series, exceptions and overrides, how each series keeps its own time, occurrence IDs, and what "this", "following" and "all" change.
51
+ - [Show and edit recurring events](./recurrence/calendar.md): Expand series for the dates on screen, and ask which events a change applies to.
52
+ - [API reference](./recurrence/reference.md): Everything @moltenship/calendar-recurrence exports. Series and adapters, expansion, occurrence IDs, rules, the ICS bridge and edits.
53
+
54
+ ## iCalendar (ICS)
55
+
56
+ - [Overview](./ics.md): What @moltenship/ics is, how to install it, and a first parse of iCalendar text into Temporal values.
57
+ - [Read an .ics file](./ics/import.md): Parse an iCalendar file a person picks or uploads, report its problems with their lines, and turn its dates into instants.
58
+ - [Show an ICS feed](./ics/feed.md): Parse a Google, Outlook or iCloud feed on the server and show its events in the calendar.
59
+ - [API reference](./ics/reference.md): Everything @moltenship/ics exports. Calendars and events, dates and time zones, issues and strict mode, extensions, and the lower layers.
60
+
61
+ ## Temporal helpers
62
+
63
+ - [Overview](./temporal.md): What @moltenship/calendar-temporal is, how to install it, and a first example of its date ranges.
64
+ - [Build a month grid](./temporal/month-grid.md): Lay out the weeks of a month with monthGrid, weekRange and iteratePlainDates, for a date picker or a view of your own.
65
+ - [Handle daylight saving time](./temporal/daylight-saving-time.md): Days of 23 and 25 hours, wall-clock times the clocks skip or repeat, and the rows of a day view, with @moltenship/calendar-temporal.
66
+ - [API reference](./temporal/reference.md): Everything @moltenship/calendar-temporal exports. Ranges, date and time grids, rounding, day boundaries, daylight saving time, keys and clocks.
67
+
68
+ ## Styling
69
+
70
+ - [Customization](./customization.md): How much of the calendar's UI is yours to change, from its tokens to every element on screen, built on the unstyled parts and hooks.
71
+ - [Theming](./theming.md): Calendar color tokens, dark mode, the event color palette, and controls of your own.
72
+ - [StyleX](./stylex.md): The calendar's views styled with StyleX, for apps without Tailwind.
73
+
74
+ ## AI
75
+
76
+ - [Agents in your app](./agents.md): What an AI agent sees of your calendar, what it can do to it, and where your app stays in charge.
77
+ - [Agents in your app: Connect an agent](./agents/connect.md): Create the agent bridge, name your calendar, and decide which actions an agent may run.
78
+ - [Agents in your app: Who made a change](./agents/changes.md): Tell an agent's change from a person's, refuse it with a policy, and undo it without touching what the person did.
79
+ - [Agents in your app: Deleting](./agents/deleting.md): Let an agent delete an event only after the person on the page says yes.
80
+ - [Agents in your app: WebMCP](./agents/webmcp.md): Hand the calendar's tools to the agent built into a browser, with rules of their own for an agent you didn't write.
81
+ - [Agents in your app: A model on your server](./agents/server.md): Give a model the bridge's tool definitions from your server, and run its tool calls on the calendar in the browser.
82
+ - [Agents in your app: Agent reference](./agents/reference.md): Every action an agent can call on a calendar, with its arguments, results and errors, and every field of the calendar's snapshot entry.
83
+ - [Build with a coding agent](./agents/coding-agents.md): Give Claude Code, Cursor or another coding agent these docs as Markdown, and a skill that teaches it the library.
84
+
85
+ ## Reference
86
+
87
+ - [API reference: Overview](./api.md): What each package exports, and where to import it from.
88
+ - [API reference: Components and hooks](./api/components.md): createCalendar, Root and its props, the components, hooks, actions, meta, and diagnostics.
89
+ - [API reference: Events and snapshots](./api/events.md): Adapters, event ranges, validation, snapshots, and queries.
90
+ - [API reference: Event changes](./api/changes.md): Proposals, changes, results, policies, placement helpers, and the pointer layer.
91
+ - [API reference: State store](./api/store.md): Create calendar state outside Root, and change it from anywhere in your app.
92
+ - [API reference: Primitives](./api/primitives.md): The framework-free layer under the React and Solid integrations, the calendar as a ui-sdk primitive, and the types of its agent actions.
93
+ - [API reference: dnd-kit adapter](./api/dnd-kit.md): Drag your own dnd-kit items into the calendar, and calendar events out to your droppables, with @moltenship/calendar-dnd-kit.
94
+
95
+ ## Optional
96
+
97
+ - [Migrating to 2.0](./migrating-to-2.md): What changes between Time 1.x and 2.0, and what to do about each change.
98
+ - [Theme builder](./theme-builder.md): Change the calendar's tokens in light and dark, see them live, and copy the CSS or a StyleX theme.
99
+ - [Comparison](./comparison.md): How Time compares with FullCalendar and react-big-calendar, as of October 2026.