@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,347 @@
1
+ # Undo and redo
2
+
3
+ Record the changes people make, and take them back through the same pipeline that saved them.
4
+
5
+ Source: https://time.molten.sh/docs/react/undo-redo
6
+
7
+ > Live example: see it at https://time.molten.sh/docs/react/undo-redo
8
+
9
+ An event history records the changes your calendar commits, and undoes them by proposing the
10
+ inverse change. The inverse goes through the same pipeline as a drag: your policies check it, the
11
+ calendar shows it while it saves, and your `onEventChange` saves it. Redo proposes the change again.
12
+
13
+ It's opt-in, and each part is separate: recording, the buttons you draw, the keyboard shortcuts and
14
+ the registry's undo toast. A calendar without a history records nothing, listens for no keys, and
15
+ bundles none of its code.
16
+
17
+ This page uses the `Calendar` and `Meeting` from the [Quick start](./quick-start.md). The example
18
+ above also renders the [undo toast](#undo-toast).
19
+
20
+ ## Connect a history
21
+
22
+ Create a history with `createEventHistory` and pass its `record` to `Root`'s `onEventChangeResult`,
23
+ which hears how every proposal ended. If you have your own `onEventChangeResult`, call
24
+ `history.record(result, detail)` from it.
25
+
26
+ ```tsx title="undoable-calendar.tsx"
27
+ export function UndoableCalendar() {
28
+ const [meetings, setMeetings] = useState(initialMeetings);
29
+ // The meeting each create became, by change ID, so the history can find it to undo.
30
+ const [createdIds] = useState(() => new Map<string, string>());
31
+ const [history] = useState(() =>
32
+ createEventHistory<Meeting, string, never>({
33
+ limit: 50,
34
+ // Once the meetings show it.
35
+ createdEventId: (change, events) => {
36
+ const id = createdIds.get(change.id);
37
+ return id !== undefined && events.get(id) !== undefined ? id : undefined;
38
+ },
39
+ }),
40
+ );
41
+
42
+ return (
43
+ <Calendar.Root
44
+ events={meetings}
45
+ onEventChange={(change) => {
46
+ // A restored meeting keeps its ID; one made from a range gets a new one.
47
+ const id =
48
+ change.cause === "create" ? (change.event?.id ?? crypto.randomUUID()) : undefined;
49
+ if (id !== undefined) createdIds.set(change.id, id);
50
+ setMeetings((current) => applyChange(current, change, id));
51
+ }}
52
+ onEventChangeResult={history.record}
53
+ policies={[timedOnly]}
54
+ defaultAnchorDate={Temporal.PlainDate.from("2026-10-08")}
55
+ defaultTimeZone="Europe/Berlin"
56
+ locale="en-US"
57
+ weekRules={weekRules}
58
+ >
59
+ <Calendar.Frame className="flex h-full flex-col">
60
+ <CalendarToolbar calendar={Calendar}>
61
+ <UndoButtons history={history} />
62
+ </CalendarToolbar>
63
+ <Calendar.Viewport className="min-h-0 flex-1">
64
+ <Calendar.ActiveView />
65
+ </Calendar.Viewport>
66
+ </Calendar.Frame>
67
+ <Calendar.Announcer messages={calendarAnnouncements} />
68
+ {/* An Undo toast after each change, with Mod+Z and Shift+Mod+Z in the frame. */}
69
+ <CalendarHistoryToast calendar={Calendar} history={history} />
70
+ </Calendar.Root>
71
+ );
72
+ }
73
+ ```
74
+
75
+ Inside `Root`, `useCalendarHistory(history)` binds the history to the calendar: `undo()` and
76
+ `redo()` propose through the root's `proposeEventChange`, and `canUndo` and `canRedo` say whether
77
+ there is anything to take.
78
+
79
+ ```tsx title="undoable-calendar.tsx"
80
+ // Anywhere inside Root.
81
+ function UndoButtons({ history }: { readonly history: MeetingHistory }) {
82
+ const { canRedo, canUndo, redo, undo } = useCalendarHistory(history, {
83
+ messages: calendarHistoryAnnouncements,
84
+ });
85
+
86
+ return (
87
+ <div className="flex gap-1">
88
+ <Button disabled={!canUndo} onClick={() => undo()} variant="ghost">
89
+ Undo
90
+ </Button>
91
+ <Button disabled={!canRedo} onClick={() => redo()} variant="ghost">
92
+ Redo
93
+ </Button>
94
+ </div>
95
+ );
96
+ }
97
+ ```
98
+
99
+ `useCalendarHistory` returns:
100
+
101
+ | Field | Contents |
102
+ | ------------------ | ----------------------------------------------------------------------------------------------------- |
103
+ | `undo({ input? })` | Takes the last step back. Resolves with the [outcome](#outcomes) |
104
+ | `redo({ input? })` | Takes the last undone step forward again. Resolves with the outcome |
105
+ | `canUndo` | Whether there is a step to undo |
106
+ | `canRedo` | Whether there is a step to redo |
107
+ | `past`, `future` | The steps undo and redo take, oldest first: each takes the last |
108
+ | `pending` | `{ direction, step }` while an undo or redo waits for its result, or `null` |
109
+ | `latest` | The latest thing the history did: `{ type: "record", step }` or `{ type: "undo" \| "redo", outcome }` |
110
+
111
+ `input` says where the command came from, `"api"` by default. Your `onEventChangeResult` gets it
112
+ back, with `history: "undo"` or `"redo"` on the detail, so it can tell an undo from a drag. The
113
+ server and hydration read an empty history.
114
+
115
+ ## Keyboard shortcuts
116
+
117
+ `useCalendarHistoryShortcuts(history, options)` adds undo and redo keys to the element its `scope`
118
+ option names, usually the root's frame. They're Mod+Z to undo and Shift+Mod+Z or Ctrl+Y to redo,
119
+ where Mod is ⌘ on Apple platforms and Ctrl elsewhere.
120
+
121
+ ```tsx
122
+ const history = useCalendarHistory(eventHistory, { messages: calendarHistoryAnnouncements });
123
+ useCalendarHistoryShortcuts(history, { scope: Calendar.useCalendarMeta().refs.frame });
124
+ ```
125
+
126
+ | Option | Default | Effect |
127
+ | ---------- | --------------------------- | ----------------------------------------------------- |
128
+ | `scope` | required | The element whose keys undo and redo |
129
+ | `undo` | `["Mod+Z"]` | Keys that undo: modifiers joined by `+`, then the key |
130
+ | `redo` | `["Shift+Mod+Z", "Ctrl+Y"]` | Keys that redo. `[]` turns an action's keys off |
131
+ | `disabled` | `false` | Listens for nothing |
132
+
133
+ While it's mounted and enabled, the hook adds one `keydown` listener to the document, which acts
134
+ only on keys whose target is inside the scope, after the page's own handlers, React's included.
135
+ Keys elsewhere on the page are left alone, as are dialogs rendered in a portal outside the scope,
136
+ and so are keys:
137
+
138
+ - in a text field or an editable element, where the browser undoes the text;
139
+ - in a dialog, menu or list inside the scope;
140
+ - during a keyboard grab or a pointer drag, or while an input method composes text;
141
+ - that something else already handled.
142
+
143
+ A key matches by the letter it types. One that types no Latin letter, as on a Russian layout or
144
+ with Option on a Mac, matches by its position, so Ctrl+Z still works there. Commands from the keys
145
+ pass `{ input: "keyboard" }`.
146
+
147
+ ## Undo toast
148
+
149
+ The registry's `calendar-history-toast` item is an "Undo" toast built on the calendar's toast, in
150
+ `components/calendar/ui/toast.tsx`. After each change it offers to undo it, and after an undo, to
151
+ redo it. It also adds the keys above in the calendar's frame and speaks undo and redo through the
152
+ `Announcer`. Install it with the [shadcn CLI](./installation.md#ui-source-optional), then render
153
+ it inside `Root`:
154
+
155
+ ```tsx
156
+ import { CalendarHistoryToast } from "@/components/calendar/calendar-history-toast/calendar-history-toast";
157
+
158
+ <Calendar.Root onEventChangeResult={history.record} …>
159
+ …
160
+ <CalendarHistoryToast calendar={Calendar} history={history} />
161
+ </Calendar.Root>;
162
+ ```
163
+
164
+ | Prop | Default | Effect |
165
+ | --------------- | ------------------------------ | ---------------------------------------------------------------------- |
166
+ | `calendar` | required | Your calendar, for its frame and event titles |
167
+ | `history` | required | The history `onEventChangeResult` records into |
168
+ | `messages` | `calendarHistoryToastMessages` | What the toast says: English, in the item's file, to edit or translate |
169
+ | `announcements` | `calendarHistoryAnnouncements` | What the `Announcer` says after an undo or redo; `null` says nothing |
170
+ | `shortcuts` | the default keys | `{ undo?, redo? }` to change them, `false` to turn them off |
171
+ | `timeout` | `6000` | How long a toast stays, in milliseconds |
172
+ | `className` | | Classes for the toast's region, such as where it sits |
173
+
174
+ Undo and Redo buttons of your own, such as in the toolbar, take `useCalendarHistory` beside the
175
+ toast. The toast already adds the keys, so they need no `useCalendarHistoryShortcuts`.
176
+
177
+ One toast shows at a time, and a cleared history closes it. A message that returns `null` shows no
178
+ toast and closes the one on screen: the English set does so for an empty stack or a change you
179
+ cancelled. A screen reader reads each toast as it shows. Changes made by a gesture are announced
180
+ as they're made, so their toast's title follows that announcement, and undo and redo are spoken by
181
+ the `Announcer` too. Deletes, updates and changes from your own UI, which no gesture announced,
182
+ add how to reach Undo after the title (`recordedHint`), and that toast stays at least 10 seconds,
183
+ long enough to hear it out. F6 moves focus to the toast's region and back, Tab reaches its
184
+ buttons, and Escape dismisses it. The region's name is `region`.
185
+
186
+ The toast's look comes from the kit's `toast.styles.ts` and `history-toast.styles.ts` beside the
187
+ item, which the registry's React and Solid toasts share.
188
+
189
+ ## What gets recorded
190
+
191
+ A history records a change only when it committed: a policy's rejection, a failed save, a cancel or
192
+ a proposal a newer one superseded never becomes a step. Its own undos and redos don't either. A new
193
+ step clears what redo would take forward.
194
+
195
+ Each step changes one event: where it was before (`before`) and where the step left it (`after`),
196
+ with `null` where there's no event, as before a create or after a delete. A step also keeps its
197
+ `cause`, the `input` that made it, your record (`event`), the event's ID and the changes it was made
198
+ of.
199
+
200
+ An [AI agent](./agents.md)'s committed changes are recorded like anyone else's, with the input
201
+ `"agent"`, so one undo stack covers what people and agents did. To give agents an undo stack of
202
+ their own, see [Undo an agent's changes](./agents/changes.md#undo-an-agents-changes).
203
+
204
+ A step holds a placement and nothing else. When an agent renames an event, the history records
205
+ the change and its undo proposes the same placement, without the old title: restore the fields
206
+ your app saved yourself, from the step's `event`, as that section shows.
207
+
208
+ `createEventHistory` takes these options:
209
+
210
+ | Option | Default | Effect |
211
+ | -------------------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
212
+ | `limit` | `100` | The most steps the undo stack keeps; the oldest drops. `0` records nothing |
213
+ | `inputs` | all four | The inputs whose changes are recorded: `"pointer"`, `"keyboard"`, `"api"`, `"agent"` |
214
+ | `filter(change, detail)` | keeps all | Records a change only when it returns `true` |
215
+ | `coalesce(change, step, detail)` | never | Return `true` to fold a change into the step on top, when both change the same event: the step keeps its `before`, takes the new `after` |
216
+ | `createdEventId(change, events)` | none | The event a committed create became. Without it, creates aren't recorded. See [creates and deletes](#creates-and-deletes) |
217
+
218
+ A keyboard grab is already one step: arrow keys move its preview, and Enter proposes once.
219
+ `coalesce` is for several proposals you want undone together, such as nudges from your own buttons.
220
+ A step that spans several events isn't supported yet.
221
+
222
+ ## How undo works
223
+
224
+ | Step | Undo proposes | Redo proposes |
225
+ | -------------------- | ------------------------------------------------------------------------ | ----------------------------------------- |
226
+ | move, resize, update | the same cause, with the placement `before`, resources included | the same, with the placement `after` |
227
+ | delete | a create with the deleted record: `{ cause: "create", event, proposed }` | a delete of the restored event |
228
+ | create | a delete of the event it became | a create with the record the undo removed |
229
+
230
+ Undos and redos run one at a time: pressing undo three times undoes three steps, in order. An undo
231
+ pressed while a change still saves waits for it, so it takes that change back rather than the one
232
+ before. It waits for every change in the calendar, so a save that never ends holds undo and redo.
233
+ When an inverse commits, its step moves to the other stack, with the placement that was saved,
234
+ since a policy may have adjusted it. A redo that commits after a new change goes back on top of the
235
+ undo stack.
236
+
237
+ ### Outcomes
238
+
239
+ `undo()` and `redo()` resolve with one of these. Through `useCalendarHistory`, they reject only if
240
+ your `createdEventId` throws.
241
+
242
+ | `status` | When |
243
+ | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
244
+ | `"committed"` | The inverse saved. `result` is its transaction result, `step` the step as it is now |
245
+ | `"rejected"` | A policy rejected the inverse, the save failed, or a drag superseded it. Or `createdEventId` can't name the event yet (`unknown-event`). The step stays where it was, so the user can try again |
246
+ | `"stale"` | The step's event changed elsewhere since. The step is dropped and nothing is proposed |
247
+ | `"empty"` | There was nothing to undo or redo |
248
+
249
+ ### Changes from elsewhere
250
+
251
+ Before it proposes, the history checks that the event is still where the step left it: at `after`
252
+ for an undo, at `before` for a redo, gone for an undone create, and so on. If another user moved
253
+ it, a server push deleted it, or someone restored it first, the step is stale. The history drops it
254
+ rather than move the event back over that change, and the next undo goes on with the next step.
255
+
256
+ Only the placement counts. A title changed elsewhere doesn't make a step stale, and since an undo
257
+ proposes only a placement, your handler keeps the new title.
258
+
259
+ ## Creates and deletes
260
+
261
+ Undoing a delete proposes a create that carries the deleted record as `change.event`. Restore it in
262
+ your handler: a create with `event: null` is a new event, as from a range dragged out in a view.
263
+
264
+ ```tsx title="undoable-calendar.tsx"
265
+ function applyChange(
266
+ meetings: readonly Meeting[],
267
+ change: MeetingChange,
268
+ id = crypto.randomUUID(),
269
+ ): readonly Meeting[] {
270
+ if (change.cause === "delete") {
271
+ return meetings.filter((meeting) => meeting.id !== change.eventId);
272
+ }
273
+ if (change.proposed.kind !== "timed") return meetings;
274
+
275
+ const { start, end } = change.proposed;
276
+ if (change.cause === "create") {
277
+ // Undoing a delete proposes a create with the deleted meeting: bring it back as it was.
278
+ const meeting = change.event ?? { id, title: "New meeting", color: "blue" as const };
279
+ return [...meetings, { ...meeting, start, end }];
280
+ }
281
+ return meetings.map((meeting) =>
282
+ meeting.id === change.eventId ? { ...meeting, start, end } : meeting,
283
+ );
284
+ }
285
+ ```
286
+
287
+ The calendar can't tell which event a create became, so the history needs your help to undo one:
288
+
289
+ - **A restored event** is looked for under the ID it had. If you restore records as they were, under
290
+ their own IDs, there is nothing to do.
291
+ - **`createdEventId(change, events)`** returns the event a committed create became, or `undefined`
292
+ while your events don't show it yet. The history asks it when it undoes or redoes the step, not
293
+ when it records it. With it, creates are recorded, and a restored event that got a new ID, as
294
+ from a server that assigns them, is found under that ID. The other steps for the event follow it
295
+ to the new ID.
296
+ - **An event it can't name** leaves the step for another try (`unknown-event`). If newer events
297
+ still don't have it, it was deleted somewhere the history didn't see, and the step is dropped as
298
+ stale.
299
+
300
+ If your handler can't restore a deleted record, leave deletes out:
301
+ `filter: (change) => change.cause !== "delete"`.
302
+
303
+ ## Recurring events
304
+
305
+ Changes to occurrences of a recurring event aren't supported yet. Your handler turns such a change
306
+ into an edit of the series ("this event", "this and following", "all events"), and taking back a
307
+ split series or a shifted one isn't a change of one event's placement. Leave them out with the
308
+ recurrence package's `isRecurringChange`:
309
+
310
+ ```ts
311
+ import { isRecurringChange } from "@moltenship/calendar-recurrence";
312
+
313
+ const history = createEventHistory<TeamEvent, string, string>({
314
+ filter: (change) => !isRecurringChange(change),
315
+ });
316
+ ```
317
+
318
+ ## Announcements
319
+
320
+ With `messages`, `useCalendarHistory` speaks each undo and redo outcome through the root's
321
+ `Announcer`, such as "Undid the move: Design review is back at Thursday, October 8, 3:00 – 4:00
322
+ PM." The packages ship no text: the registry's `calendar/announcements.ts` has an English set,
323
+ `calendarHistoryAnnouncements`, to edit or translate. Each message gets the outcome and the
324
+ announcement context, with the step's event when the calendar shows it.
325
+
326
+ ## Without a framework
327
+
328
+ `createEventHistory` needs no `Root`. Record each result yourself, and pass `undo` and `redo` the
329
+ events the user sees and a function that proposes, such as `propose` from
330
+ [`createEventTransactions`](./api/changes.md#results). `getEvents` must return the same snapshot
331
+ until the events change: the history tells events that haven't caught up with its own saves by
332
+ that. Pass `whenSettled` too, a promise for when no change is validating or saving, so an undo
333
+ waits for a change still saving:
334
+
335
+ ```ts
336
+ const history = createEventHistory<Meeting, string, never>();
337
+ history.record(result, { input: "api" });
338
+
339
+ await history.undo({
340
+ getEvents: () => visibleEvents(),
341
+ propose: (proposal, detail) => proposeAndRecord(proposal, detail),
342
+ whenSettled: () => changesSettled(),
343
+ });
344
+ ```
345
+
346
+ `history.subscribe` and `history.getSnapshot` follow the store contract, and `history.clear()`
347
+ empties both stacks.
@@ -0,0 +1,222 @@
1
+ # Agenda
2
+
3
+ A chronological list of upcoming events, grouped by day, and a version that scrolls through months or years.
4
+
5
+ Source: https://time.molten.sh/docs/react/views/agenda
6
+
7
+ > Live example of the `agenda` view: see it at https://time.molten.sh/docs/react/views/agenda
8
+
9
+ Try it in the [live demo](https://moltenship-time-demo.vercel.app): pick Agenda in the view switcher.
10
+
11
+ `createAgendaView` lists the events in the coming weeks, one group per day. Days without events are
12
+ left out. Only the days in view render, so a long range, such as `weeks: 104`, stays fast. For a
13
+ list that scrolls without end and loads events as you go, use the
14
+ [scrolling agenda](#scrolling-agenda).
15
+
16
+ ## Add it
17
+
18
+ Add the view to your app with the shadcn CLI, as described in
19
+ [UI source](../installation.md#ui-source-optional). The item brings the theme and the shared
20
+ `calendar` parts:
21
+
22
+ ```bash
23
+ npx shadcn@latest add https://time.molten.sh/r/list-view.json
24
+ ```
25
+
26
+ Then register the view:
27
+
28
+ ```tsx
29
+ import { createAgendaView } from "@/components/calendar/list-view/agenda-view";
30
+
31
+ export const Calendar = createCalendar<Meeting>()({
32
+ eventAdapter,
33
+ views: [createAgendaView<Meeting>({ weeks: 2, getEventColor: (meeting) => meeting.color })],
34
+ });
35
+ ```
36
+
37
+ The view is named `agenda`. It decides which days render with `@tanstack/virtual-core`, which the
38
+ registry item installs. A Solid app adds the [Solid agenda](https://time.molten.sh/docs/solid/views/agenda.md), built from the same
39
+ styles, labels and virtualizer.
40
+
41
+ ## Scrolling agenda
42
+
43
+ > Live example of the `scrolling-agenda` view: see it at https://time.molten.sh/docs/react/views/agenda
44
+
45
+ `createScrollingAgendaView` from the `scrolling-list-view` item is the agenda as a
46
+ [scrolling view](./scrolling.md): one list that scrolls through months or years, with the
47
+ anchor date on top. This preview holds a year of events either way of today, a few thousand of
48
+ them, and fetches them from a pretend server as you scroll. Try it in the demo with "Scroll days,
49
+ weeks, months and agenda" on in the settings.
50
+
51
+ ```bash
52
+ npx shadcn@latest add https://time.molten.sh/r/scrolling-list-view.json
53
+ ```
54
+
55
+ ```tsx
56
+ import { createScrollingAgendaView } from "@/components/calendar/scrolling-list-view/scrolling-agenda-view";
57
+
58
+ views: [createScrollingAgendaView<Meeting>({ dayView: "scrolling-day", getEventColor })];
59
+ ```
60
+
61
+ | View | Shows | Loads | Previous and Next | Today |
62
+ | ------------------ | -------------------------------- | ------------------ | ----------------- | ------------ |
63
+ | `scrolling-agenda` | `weeks` from the anchor date (4) | A page either side | `weeks` | Today on top |
64
+
65
+ - **The anchor date is the day on top.** The range starts at the anchor date rather than its week,
66
+ since the list comes to rest on any day. When a scroll comes to rest, the anchor date moves to the
67
+ day on top, so `Calendar.Title`, `onAnchorDateChange`, and a URL that stores the date follow it.
68
+ On a long scroll it moves every half page on the way, so the next weeks load before they scroll
69
+ into view.
70
+ - **Today, Previous, Next, and any other anchor date jump the list** to put that date on top, or
71
+ the next day with events, at once, as Google Calendar's agenda does, rather than gliding there as
72
+ the other scrolling views do over a page or two. The list holds that date on top while its events
73
+ load, until you scroll. With a controlled `anchorDate`, the list stays where it was scrolled until
74
+ your state takes the latest date `onAnchorDateChange` sent, as in the other
75
+ [scrolling views](./scrolling.md#how-they-move).
76
+ - **Only the days in view render.** Each is measured once it renders, as its events wrap, and days
77
+ that load above or below the ones on screen don't move them.
78
+ - **The end of the list** follows the last loaded day. It's as tall as the view, so any day can
79
+ scroll to the top, and says "Loading events…" while `loading` is set, or that nothing more is
80
+ scheduled. Scrolling on past either end of the loaded days moves a page that way, once per
81
+ gesture, so the list crosses weeks without events. Weeks shown without events get the empty
82
+ state, at the end of the list or among the days after them.
83
+
84
+ ### Loading events as you scroll
85
+
86
+ The scrolling agenda's load range is a page of weeks either way of the ones it shows. As with the
87
+ other scrolling views, `onVisibleRangeChange` on `Root` reports it after the first render and
88
+ whenever the anchor date moves it. Fetch what you haven't fetched yet, and set `loading` while some
89
+ is on its way:
90
+
91
+ ```tsx title="long-agenda.tsx"
92
+ const timeZone = "Europe/Berlin";
93
+
94
+ /**
95
+ * Fetches meetings for the dates the agenda lists, each date once, as it scrolls, and says so
96
+ * while some are still on their way.
97
+ */
98
+ export function LongAgenda({
99
+ loadMeetings,
100
+ }: {
101
+ readonly loadMeetings: (from: Temporal.Instant, to: Temporal.Instant) => Promise<Meeting[]>;
102
+ }) {
103
+ const [loaded, setLoaded] = useState<ReadonlyMap<string, Meeting>>(new Map());
104
+ const [fetching, setFetching] = useState(0);
105
+ const requested = useRef(new Set<string>());
106
+ const meetings = useMemo(() => [...loaded.values()], [loaded]);
107
+
108
+ const load = useCallback(
109
+ ({ loadRange }: CalendarVisibleRange) => {
110
+ const missing = [...iteratePlainDates(loadRange)].filter(
111
+ (date) => !requested.current.has(date.toString()),
112
+ );
113
+ if (missing.length === 0) return;
114
+ for (const date of missing) requested.current.add(date.toString());
115
+ const from = missing[0]!.toZonedDateTime(timeZone).toInstant();
116
+ const to = missing.at(-1)!.add({ days: 1 }).toZonedDateTime(timeZone).toInstant();
117
+ setFetching((count) => count + 1);
118
+ void loadMeetings(from, to)
119
+ .then((arrived) =>
120
+ setLoaded((current) => new Map([...current, ...arrived.map((m) => [m.id, m] as const)])),
121
+ )
122
+ .finally(() => setFetching((count) => count - 1));
123
+ },
124
+ [loadMeetings],
125
+ );
126
+
127
+ return (
128
+ <Calendar.Root
129
+ events={meetings}
130
+ defaultAnchorDate={Temporal.Now.plainDateISO(timeZone)}
131
+ onVisibleRangeChange={load}
132
+ timeZone={timeZone}
133
+ locale="en-US"
134
+ viewOptions={{ "scrolling-agenda": { loading: fetching > 0 } }}
135
+ weekRules={weekRules}
136
+ >
137
+ <Calendar.ActiveView />
138
+ </Calendar.Root>
139
+ );
140
+ }
141
+ ```
142
+
143
+ While `loading` is set, the end of the list says "Loading events…", and a view without events
144
+ shows a loading state in place of the empty one. Time never fetches or keeps events itself.
145
+
146
+ ## Anatomy
147
+
148
+ `AgendaView` from `registry/list-view` renders a list with one group per day. The view builds these
149
+ parts itself, so they're not parts you compose: to change one, edit its file. The tree shows where
150
+ each part lives.
151
+
152
+ > Diagram: see it at https://time.molten.sh/docs/react/views/agenda
153
+
154
+ ```txt title="Rendered by AgendaView"
155
+ AgendaView agenda-view.tsx
156
+ ├── AgendaList agenda-list.tsx, scrolls the days in view
157
+ │ ├── Day group agenda-day.tsx, data-date, one per day
158
+ │ │ ├── Day group header weekday and date, sticky
159
+ │ │ └── AgendaItem agenda-item.tsx, one per event
160
+ │ └── End of list agenda-states.tsx, AgendaEnd: scrolling agenda only
161
+ └── Empty state agenda-states.tsx, EmptyAgenda: in place of the list
162
+ ```
163
+
164
+ `AgendaItem` shows the time range or an "All day" badge, the title, and "Day 2 of 3", which comes
165
+ from `dayIndex` and `dayCount`. `agenda-virtualizer.ts` decides which days render, and `use-agenda-virtualizer.ts` binds it to the list. The
166
+ scrolling agenda's `ScrollingAgendaView` renders the same parts, and `use-agenda-scroll.ts` in
167
+ `registry/scrolling-list-view` keeps its scroll position and the anchor date together.
168
+
169
+ ## Options
170
+
171
+ | Name | Type | Default | Description |
172
+ | --------------- | ---------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
173
+ | `weeks` | `number` | `4` | How many whole weeks to show, from the week of the anchor date, or from the anchor date itself in the scrolling agenda. Previous and Next move by the same number of weeks. |
174
+ | `getEventColor` | `(event: TEvent) => CalendarEventColor` | | The color for each event. See [event colors](../theming.md#event-colors). |
175
+ | `getEventIcon` | `(event: TEvent) => ReactNode` | | A small icon before each event's title, such as a repeat mark on recurring events, or nothing. It's decorative and hidden from screen readers: say the same in `describeEvent`, which adds to the event's [accessible name](../accessibility.md#event-names). |
176
+ | `describeEvent` | `(event: TEvent) => string \| undefined` | | Extra words for each event's accessible name, such as its calendar. |
177
+ | `loading` | `boolean` | `false` | Events for the view's dates are still being fetched: the view says they're loading instead of that nothing is scheduled. |
178
+ | `dayView` | `string` | `"day"` | Scrolling agenda only: the registered view a date opens. |
179
+
180
+ ## What it shows
181
+
182
+ - **Days:** each day with events gets a date column that stays in view while you scroll its
183
+ events. Today is highlighted.
184
+ - **Times** are formatted as a range with `Intl`, as in "10:00 – 11:30 AM". Events that started the
185
+ day before read "Until 2:00 AM"; events that run into the next day read "From 10:00 PM".
186
+ - **All-day events** show an "All day" badge, and events longer than a day show "Day 2 of 3".
187
+ - **Empty range:** a short message when the weeks shown have no events, or a loading one while
188
+ `loading` is set.
189
+ - **Clicking a date** opens that day in the view named `day`. Register a
190
+ [day view](./week-and-day.md) so the click has somewhere to go.
191
+ - **Changes being saved:** events with a [pending change](../interactions.md#pending-changes) get
192
+ `aria-busy` and render at 60% opacity.
193
+
194
+ Each day has `data-date`, and each event is a `<button>` with `data-event-id`.
195
+
196
+ ## Keyboard
197
+
198
+ Tab into the preview above and try these keys. The [Accessibility](../accessibility.md#keyboard)
199
+ page has the full map.
200
+
201
+ | Focus | Key | Effect |
202
+ | ---------------------- | ---------------------------- | --------------------------------------- |
203
+ | An event | ↑ ↓ | Previous or next event |
204
+ | An event | Page Up, Page Down | First event of the previous or next day |
205
+ | An event | Home, End | First or last event |
206
+ | An event | Enter | Open it, as a click does |
207
+ | An event | Shift+Enter | Open its date in the day view |
208
+ | A range without events | ↑ or Page Up, ↓ or Page Down | The previous or next range |
209
+
210
+ Moving past the first or last event shows the previous or next weeks. In the scrolling agenda the
211
+ keys move through the weeks it shows, and moving past them pages on as focus moves to the next
212
+ event, scrolling it into view. The list scrolls to keep the focused event in view, and the focused
213
+ day stays rendered while focus is in the list. Focus belongs to an event on a date, not to an
214
+ element: if its day scrolls out of the loaded weeks, focus goes with it, and it returns once the day
215
+ is in view again. The agenda doesn't move or create events from the keyboard, since it has no days or
216
+ times to move them to.
217
+
218
+ ## Screen readers
219
+
220
+ The list is an `<ol>` named by its weeks. Only the days in view render, so each day's `<li>`
221
+ carries `aria-posinset` and `aria-setsize`, counting every day listed: "list item, 5 of 41". The
222
+ list is `aria-busy` while `loading` is set.