@moltenship/calendar 1.0.0-rc.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -6
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +2 -2
- package/docs/accessibility.md +305 -0
- package/docs/agents/changes.md +449 -0
- package/docs/agents/coding-agents.md +116 -0
- package/docs/agents/connect.md +444 -0
- package/docs/agents/deleting.md +296 -0
- package/docs/agents/reference.md +511 -0
- package/docs/agents/server.md +317 -0
- package/docs/agents/webmcp.md +153 -0
- package/docs/agents.md +355 -0
- package/docs/annotations.md +198 -0
- package/docs/api/changes.md +264 -0
- package/docs/api/components.md +245 -0
- package/docs/api/dnd-kit.md +265 -0
- package/docs/api/events.md +153 -0
- package/docs/api/primitives.md +218 -0
- package/docs/api/store.md +92 -0
- package/docs/api.md +57 -0
- package/docs/availability.md +576 -0
- package/docs/comparison.md +278 -0
- package/docs/concepts/anatomy.md +73 -0
- package/docs/concepts/events.md +163 -0
- package/docs/concepts/how-it-works.md +112 -0
- package/docs/concepts/state.md +244 -0
- package/docs/concepts/time.md +168 -0
- package/docs/customization.md +271 -0
- package/docs/frameworks.md +116 -0
- package/docs/guides/dnd-kit.md +333 -0
- package/docs/guides/google-calendar-sync.md +1246 -0
- package/docs/guides/google-calendar.md +367 -0
- package/docs/guides/motion.md +414 -0
- package/docs/guides/nextjs-app-router.md +630 -0
- package/docs/guides/nextjs.md +149 -0
- package/docs/guides/performance.md +103 -0
- package/docs/guides/tanstack-query.md +485 -0
- package/docs/ics/feed.md +484 -0
- package/docs/ics/import.md +183 -0
- package/docs/ics/reference.md +482 -0
- package/docs/ics.md +142 -0
- package/docs/index.md +149 -0
- package/docs/installation.md +209 -0
- package/docs/interactions.md +441 -0
- package/docs/llms.txt +99 -0
- package/docs/migrating-to-2.md +497 -0
- package/docs/quick-start.md +163 -0
- package/docs/recurrence/calendar.md +598 -0
- package/docs/recurrence/model.md +128 -0
- package/docs/recurrence/reference.md +547 -0
- package/docs/recurrence.md +122 -0
- package/docs/stylex.md +290 -0
- package/docs/temporal/daylight-saving-time.md +172 -0
- package/docs/temporal/month-grid.md +119 -0
- package/docs/temporal/reference.md +167 -0
- package/docs/temporal.md +105 -0
- package/docs/testing.md +600 -0
- package/docs/theme-builder.md +82 -0
- package/docs/theming.md +275 -0
- package/docs/undo-redo.md +347 -0
- package/docs/views/agenda.md +222 -0
- package/docs/views/custom-views.md +195 -0
- package/docs/views/month.md +110 -0
- package/docs/views/resource-columns.md +265 -0
- package/docs/views/resource-timeline.md +226 -0
- package/docs/views/scrolling.md +193 -0
- package/docs/views/week-and-day.md +258 -0
- package/docs/views/year.md +138 -0
- package/docs/views.md +69 -0
- package/package.json +42 -14
- package/skills/moltenship-time/SKILL.md +77 -0
- package/skills/moltenship-time/references/agent-ready.md +272 -0
- package/skills/moltenship-time/references/changes.md +188 -0
- package/skills/moltenship-time/references/compose.md +175 -0
- package/skills/moltenship-time/references/mistakes.md +100 -0
- package/skills/moltenship-time/references/solid.md +213 -0
- package/skills/moltenship-time/references/state.md +129 -0
- package/skills/moltenship-time/references/testing.md +176 -0
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
# Migrating to 2.0
|
|
2
|
+
|
|
3
|
+
What changes between Time 1.x and 2.0, and what to do about each change.
|
|
4
|
+
|
|
5
|
+
Source: https://time.molten.sh/docs/react/migrating-to-2
|
|
6
|
+
|
|
7
|
+
2.0 rebuilds the calendar's parts on [ui-sdk](https://ui-sdk.dev). With it, an
|
|
8
|
+
[agent](./agents.md) can call the calendar's actions, and the calendar has a second framework,
|
|
9
|
+
Solid, with [docs of its own](https://time.molten.sh/docs/solid.md). The engine didn't move: dates, time zones, recurrence, layouts, transactions and policies work as they did.
|
|
10
|
+
|
|
11
|
+
For most apps the upgrade is two more packages to install. The rest of this page is for code that
|
|
12
|
+
names the types 2.0 widened.
|
|
13
|
+
|
|
14
|
+
## In short
|
|
15
|
+
|
|
16
|
+
| Change | Do this | Who it affects |
|
|
17
|
+
| --------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- |
|
|
18
|
+
| `@ui-sdk/core` and `@ui-sdk/react` are peer dependencies | [Install them](#install-the-new-peer-dependencies) | Everyone |
|
|
19
|
+
| `CalendarInputMethod` has a fourth value, `"agent"` | [Handle it](#handle-the-agent-input) | Code that switches on `detail.input` |
|
|
20
|
+
| `onEventChange` and policies get the proposal's detail, with `fields` | [Check handlers with a second parameter](#handlers-and-policies-hear-who-proposed) | Handlers with an optional second parameter, and code that calls a typed handler |
|
|
21
|
+
| The toolbar parts and the frame render a `data-slot` attribute | [Check selectors on `data-slot="calendar"`](#the-parts-have-data-slot) | Apps with shadcn's date picker, or such CSS |
|
|
22
|
+
| State handlers hear `reason`, `source`, `event` and can `cancel()` | Nothing. [Use it](#state-handlers-hear-why-and-who) | Code that builds a `detail` by hand, in tests |
|
|
23
|
+
| Actions take options last | [Wrap an action used as an event handler](#actions-take-options) | Code such as `onClick={actions.navigateNext}` |
|
|
24
|
+
| `Root` has `label`, `allowAgentDelete` and `formatAgentEventLabel` | [Name your calendar](#name-the-calendar) | Apps that want agents, or a fixed name |
|
|
25
|
+
| The store and state types moved to `@moltenship/calendar-primitives` | Nothing: [the old imports still work](#new-packages) | Nobody |
|
|
26
|
+
| `useCalendarPointer` moved to `@moltenship/calendar-react` | [Import it from there](#the-pointer-hook-moved) | Code that imports it from `@moltenship/calendar-dnd` |
|
|
27
|
+
| The registry's controls and popups come from a new item, `calendar-ui`, without Base UI | [Add the registry's items again](#add-the-registrys-items-again) | Apps with the Tailwind items from the registry |
|
|
28
|
+
| The StyleX items' controls come from `stylex-calendar-ui`, without Astryx or Base UI | [Add the StyleX items again](#add-the-stylex-items-again) | Apps with the StyleX items from the registry |
|
|
29
|
+
|
|
30
|
+
What didn't change: the engine, what the registry's views do, the `data-calendar-part` attributes
|
|
31
|
+
and the other attributes your CSS and tests target, the keyboard model, and every hook's name and return
|
|
32
|
+
value. The parts gained one attribute, [`data-slot`](#the-parts-have-data-slot).
|
|
33
|
+
|
|
34
|
+
## Install the new peer dependencies
|
|
35
|
+
|
|
36
|
+
**pnpm**
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pnpm add @moltenship/calendar @ui-sdk/core @ui-sdk/react
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**npm**
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npm install @moltenship/calendar @ui-sdk/core @ui-sdk/react
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**yarn**
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
yarn add @moltenship/calendar @ui-sdk/core @ui-sdk/react
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
**bun**
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
bun add @moltenship/calendar @ui-sdk/core @ui-sdk/react
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
- **`react-dom` is needed too.** `@ui-sdk/react` has it as a peer dependency. A React app on the web
|
|
61
|
+
already has it.
|
|
62
|
+
- **Install the 2.0 version of every `@moltenship/*` package you use.** They share one version,
|
|
63
|
+
and a 1.x package beside a 2.0 one brings a second copy of the engine.
|
|
64
|
+
- **`@moltenship/calendar-testing` has the same two peers.** A project that tests with it needs
|
|
65
|
+
nothing more once the app has them.
|
|
66
|
+
- **`shadcn add` installs them only if they're missing.** The registry's `calendar-ui` item lists
|
|
67
|
+
the ui-sdk packages without a version, so an app that already has them keeps its own. Install
|
|
68
|
+
the version the calendar asks for yourself.
|
|
69
|
+
- **Keep one copy of `@ui-sdk/core`.** The calendar and an [agent bridge](./agents/connect.md)
|
|
70
|
+
find each other through it. Your package manager keeps one as long as every `@ui-sdk/*` package
|
|
71
|
+
is on the same version; `pnpm why @ui-sdk/core` shows whether it did.
|
|
72
|
+
|
|
73
|
+
The calendar takes `@ui-sdk/core` and `@ui-sdk/react` from `0.1.0-beta.16` on, within the 0.1
|
|
74
|
+
line.
|
|
75
|
+
|
|
76
|
+
## Handle the agent input
|
|
77
|
+
|
|
78
|
+
`CalendarInputMethod` was `"pointer" | "keyboard" | "api"`. It's now
|
|
79
|
+
`"pointer" | "keyboard" | "api" | "agent"`. The value is the `input` of the detail that
|
|
80
|
+
`onEventChangeResult` gets, and of a history step.
|
|
81
|
+
|
|
82
|
+
Code that only compares, such as `detail.input === "keyboard"`, keeps working. A `switch` that
|
|
83
|
+
TypeScript checks for every case stops compiling until it has the fourth:
|
|
84
|
+
|
|
85
|
+
```ts title="input-label.ts"
|
|
86
|
+
import type { CalendarInputMethod } from "@moltenship/calendar";
|
|
87
|
+
|
|
88
|
+
export function inputLabel(input: CalendarInputMethod): string {
|
|
89
|
+
switch (input) {
|
|
90
|
+
case "pointer":
|
|
91
|
+
return "Dragged";
|
|
92
|
+
case "keyboard":
|
|
93
|
+
return "Moved with the keyboard";
|
|
94
|
+
case "api":
|
|
95
|
+
return "Changed from a form";
|
|
96
|
+
// New in 2.0: an AI agent proposed the change.
|
|
97
|
+
case "agent":
|
|
98
|
+
return "Changed by the assistant";
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
No agent proposes anything until your app creates a bridge, so `"agent"` never arrives in an app
|
|
104
|
+
that doesn't opt in. In one that does, `"agent"` is the input of everything an agent's step
|
|
105
|
+
causes. That includes a `proposeEventChange` your own button's handler makes when an agent
|
|
106
|
+
presses the button, which a person's click still reports as `"api"`.
|
|
107
|
+
|
|
108
|
+
An [event history](./undo-redo.md) records every input by default, and now that includes an
|
|
109
|
+
agent's. To leave an agent's changes out of undo, list the inputs you want:
|
|
110
|
+
|
|
111
|
+
```ts title="history.ts"
|
|
112
|
+
import { createEventHistory } from "@moltenship/calendar";
|
|
113
|
+
|
|
114
|
+
import type { Meeting } from "./calendar";
|
|
115
|
+
|
|
116
|
+
// Undo and redo take back what people did, and leave an agent's changes alone.
|
|
117
|
+
export const history = createEventHistory<Meeting, string, never>({
|
|
118
|
+
inputs: ["pointer", "keyboard", "api"],
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Handlers and policies hear who proposed
|
|
123
|
+
|
|
124
|
+
In 1.x only `onEventChangeResult` got the proposal's detail. In 2.0 `onEventChange` gets it as a
|
|
125
|
+
second argument, and a policy as `detail` in its second argument. Handlers that take one argument
|
|
126
|
+
are unchanged.
|
|
127
|
+
|
|
128
|
+
```tsx title="saving.tsx"
|
|
129
|
+
"use client";
|
|
130
|
+
|
|
131
|
+
import type { CalendarPolicy } from "@moltenship/calendar";
|
|
132
|
+
import { useState } from "react";
|
|
133
|
+
|
|
134
|
+
import { applyChange } from "./agent-save";
|
|
135
|
+
import { Calendar, meetings as initialMeetings, weekRules, type Meeting } from "./calendar";
|
|
136
|
+
|
|
137
|
+
// `detail` is absent when your own code calls a policy outside a proposal.
|
|
138
|
+
const noAgentDeletes: CalendarPolicy<Meeting, string, never> = (change, { detail }) =>
|
|
139
|
+
change.cause === "delete" && detail?.input === "agent"
|
|
140
|
+
? { type: "reject", reason: "a-person-deletes-meetings" }
|
|
141
|
+
: { type: "accept" };
|
|
142
|
+
|
|
143
|
+
export function SavingCalendar() {
|
|
144
|
+
const [meetings, setMeetings] = useState(initialMeetings);
|
|
145
|
+
|
|
146
|
+
return (
|
|
147
|
+
<Calendar.Root
|
|
148
|
+
events={meetings}
|
|
149
|
+
onEventChange={(change, detail) => {
|
|
150
|
+
if (detail.input === "agent") console.info(`The assistant proposed a ${change.cause}.`);
|
|
151
|
+
setMeetings((current) => applyChange(current, change, detail));
|
|
152
|
+
}}
|
|
153
|
+
policies={[noAgentDeletes]}
|
|
154
|
+
defaultAnchorDate={Temporal.PlainDate.from("2026-10-08")}
|
|
155
|
+
defaultTimeZone="Europe/Berlin"
|
|
156
|
+
locale="en-US"
|
|
157
|
+
weekRules={weekRules}
|
|
158
|
+
>
|
|
159
|
+
<Calendar.ActiveView />
|
|
160
|
+
</Calendar.Root>
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Two kinds of code do change:
|
|
166
|
+
|
|
167
|
+
- **A handler with a second parameter of its own.** 1.x called `onEventChange` with the change
|
|
168
|
+
alone. A function passed directly, as `onEventChange={save}` where `save` is
|
|
169
|
+
`(change, options?) => …`, now receives the detail as `options`. TypeScript reports it when the
|
|
170
|
+
two types differ, and stays silent when `options` is loose enough to take a detail. Wrap the
|
|
171
|
+
call: `onEventChange={(change) => save(change)}`.
|
|
172
|
+
- **Code that calls a typed handler.** `CalendarEventChangeHandler` now has two parameters, and
|
|
173
|
+
`detail` is required. A test or a wrapper that calls such a handler with one argument stops
|
|
174
|
+
compiling. Pass a detail: `handler(change, { input: "api" })`.
|
|
175
|
+
|
|
176
|
+
`applyChange` and `calendar.tsx` are the ones from [Connect an agent](./agents/connect.md#name-the-calendar)
|
|
177
|
+
and the [Quick start](./quick-start.md).
|
|
178
|
+
|
|
179
|
+
The detail has a new optional member, `fields`: what a change says beside where the event goes.
|
|
180
|
+
An agent's `createEvent` and `updateEvent` put the title there, and whatever else the agent sent.
|
|
181
|
+
A person's gestures send none, so a handler that ignores `detail` saves a person's changes as it
|
|
182
|
+
did. It saves an agent's too, but without the title, which is why `applyChange` above takes the
|
|
183
|
+
detail. See [Save what the agent sent](./agents/connect.md#save-what-the-agent-sent).
|
|
184
|
+
|
|
185
|
+
`actions.checkEventChange(proposal, detail?)` takes the detail as well, so a preview can ask the
|
|
186
|
+
policies the question the real proposal will.
|
|
187
|
+
|
|
188
|
+
A policy you call yourself, in a unit test for example, has a context type with one more optional
|
|
189
|
+
field. Code that builds the context as `{ events, timeZone }` still compiles.
|
|
190
|
+
|
|
191
|
+
## State handlers hear why and who
|
|
192
|
+
|
|
193
|
+
The second argument of `onViewChange`, `onAnchorDateChange` and the other four state handlers had
|
|
194
|
+
`previous`, `controlled` and `slice`. It now also has:
|
|
195
|
+
|
|
196
|
+
| Field | Contents |
|
|
197
|
+
| ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
198
|
+
| `reason` | `"next-press"`, `"previous-press"`, `"today-press"`, `"input-change"`, `"keyboard-navigation"`, `"focus-change"`, `"resource-toggle"` or `"imperative"` |
|
|
199
|
+
| `source` | `"mouse"`, `"touch"`, `"pen"`, `"keyboard"`, `"virtual"`, `"programmatic"` or `"agent"` |
|
|
200
|
+
| `event` | The DOM event, when one of the calendar's own controls caused the change |
|
|
201
|
+
| `cancel()` | Keeps the value as it was |
|
|
202
|
+
| `canceled` | Whether a handler cancelled |
|
|
203
|
+
|
|
204
|
+
`"keyboard"` is a person's keys, on a toolbar button and in a view: arrow-key navigation, moving
|
|
205
|
+
focus and expanding a resource report it. `"programmatic"` is a call from your own code, and
|
|
206
|
+
`"agent"` anything an [agent's step](./agents/changes.md#two-kinds-of-change) causes.
|
|
207
|
+
|
|
208
|
+
Handlers still run when they did: before a controlled value changes, since your handler is what
|
|
209
|
+
changes it, and after an uncontrolled one. `cancel()` puts an uncontrolled value back.
|
|
210
|
+
[State](./concepts/state.md#what-a-handler-hears) has an example.
|
|
211
|
+
|
|
212
|
+
This breaks one thing: a test or a wrapper that builds a `CalendarStateChangeDetail` object by
|
|
213
|
+
hand. Add the new fields, or let the calendar make the detail by calling an action.
|
|
214
|
+
|
|
215
|
+
## Actions take options
|
|
216
|
+
|
|
217
|
+
`setView`, `setAnchorDate`, `setTimeZone`, `setSelection`, `setFocus`, `setExpandedResourceIds`,
|
|
218
|
+
`navigateNext`, `navigatePrevious` and `navigateToday` take an options object last:
|
|
219
|
+
`{ event?, reason?, source? }`. It says why the app made the call, and a state handler reads it
|
|
220
|
+
back.
|
|
221
|
+
|
|
222
|
+
Calls without it are unchanged. One pattern stops compiling: a navigation action passed directly
|
|
223
|
+
as an event handler. TypeScript reports that the click event "has no properties in common with
|
|
224
|
+
type `CalendarCommandOptions`". Wrap the call, and pass the event if a handler should hear it:
|
|
225
|
+
|
|
226
|
+
```tsx title="next-button.tsx"
|
|
227
|
+
"use client";
|
|
228
|
+
|
|
229
|
+
import { Calendar } from "./calendar";
|
|
230
|
+
|
|
231
|
+
export function NextButton() {
|
|
232
|
+
const actions = Calendar.useCalendarActions();
|
|
233
|
+
|
|
234
|
+
return (
|
|
235
|
+
// Before: onClick={actions.navigateNext}. The click isn't the options object.
|
|
236
|
+
<button type="button" onClick={(event) => actions.navigateNext({ event: event.nativeEvent })}>
|
|
237
|
+
Next
|
|
238
|
+
</button>
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
`Calendar.NextTrigger`, `Calendar.PreviousTrigger` and `Calendar.TodayTrigger` already do this.
|
|
244
|
+
|
|
245
|
+
## The parts have `data-slot`
|
|
246
|
+
|
|
247
|
+
`Calendar.Frame` and the toolbar parts are ui-sdk slots now, and each renders a `data-slot`
|
|
248
|
+
attribute beside its `data-calendar-part`:
|
|
249
|
+
|
|
250
|
+
| Part | `data-slot` |
|
|
251
|
+
| ----------------- | --------------------------- |
|
|
252
|
+
| `Frame` | `calendar` |
|
|
253
|
+
| `Toolbar` | `calendar-toolbar` |
|
|
254
|
+
| `Title` | `calendar-title` |
|
|
255
|
+
| `Viewport` | `calendar-viewport` |
|
|
256
|
+
| `PreviousTrigger` | `calendar-previous-trigger` |
|
|
257
|
+
| `TodayTrigger` | `calendar-today-trigger` |
|
|
258
|
+
| `NextTrigger` | `calendar-next-trigger` |
|
|
259
|
+
| `ViewSwitcher` | `calendar-view-switcher` |
|
|
260
|
+
|
|
261
|
+
They matter when your app already targets one of those names, and `calendar` is the likely one:
|
|
262
|
+
shadcn's date picker renders `data-slot="calendar"` on its root. A rule such as `[data-slot="calendar"] { … }`, or a test's
|
|
263
|
+
`querySelector('[data-slot="calendar"]')`, written for the date picker now matches the scheduler's
|
|
264
|
+
frame too. Scope such a selector to the date picker, or select the scheduler by
|
|
265
|
+
`data-calendar-part="frame"`.
|
|
266
|
+
|
|
267
|
+
## Add the registry's items again
|
|
268
|
+
|
|
269
|
+
In 1.x the registry's Tailwind items used shadcn's `button`, `badge`, `tooltip`, `select`,
|
|
270
|
+
`popover` and `dialog` from your app's `components/ui`, and Base UI's toast, so a change you made
|
|
271
|
+
there changed the calendar too, and your app needed a Base UI style. In 2.0 they use
|
|
272
|
+
`calendar-ui`, the calendar's own controls, built on ui-sdk, and no longer need Base UI. The controls no longer follow your
|
|
273
|
+
app's `components/ui`: they look the same in every app, and you restyle them in their own files.
|
|
274
|
+
They are a default and the files are yours, so you can still put your own components in their
|
|
275
|
+
place. [Customization](./customization.md) lists every way to change the calendar's UI.
|
|
276
|
+
|
|
277
|
+
1. Add the items you use again, or all of them:
|
|
278
|
+
|
|
279
|
+
```bash
|
|
280
|
+
npx shadcn@latest add https://time.molten.sh/r/calendar-full.json
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
This now installs `calendar-ui` too: `button.tsx`, `badge.tsx`, `tooltip.tsx`, `select.tsx`,
|
|
284
|
+
`popover.tsx`, `dialog.tsx` and `toast.tsx` in `components/calendar/ui/`, with the classes each
|
|
285
|
+
one uses in a `*.styles.ts` file beside it.
|
|
286
|
+
It adds `@ui-sdk/core` and `@ui-sdk/react` if your app doesn't have them yet. `shadcn add` asks
|
|
287
|
+
before it replaces a file you changed; redo your changes on the new files.
|
|
288
|
+
|
|
289
|
+
2. ui-sdk adds a little CSS to the page in a layer named `ui-sdk`. Name that layer before Tailwind
|
|
290
|
+
in your global CSS, so Tailwind's utilities win over it:
|
|
291
|
+
|
|
292
|
+
```css title="globals.css"
|
|
293
|
+
@layer ui-sdk;
|
|
294
|
+
@import "tailwindcss";
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
The calendar's popups, from the view select's list and the tooltips to the popovers, the
|
|
298
|
+
recurrence dialog and the undo toast, open in the browser's top layer, through the Popover API,
|
|
299
|
+
so the registry's items now need Chrome and Edge 114, Safari 17 or Firefox 125. In
|
|
300
|
+
an older browser they render at the end of the page, and a server-rendered page doesn't
|
|
301
|
+
hydrate them cleanly.
|
|
302
|
+
|
|
303
|
+
3. If you restyled the calendar's buttons, badges, tooltips, popovers, dialogs or the view
|
|
304
|
+
switcher through `components/ui`, make those changes in `components/calendar/ui/` instead. To
|
|
305
|
+
keep using your own components there, make those files render them, as
|
|
306
|
+
[Use your own controls](./theming.md#use-your-own-controls) shows.
|
|
307
|
+
|
|
308
|
+
4. The items no longer install shadcn's components or `@base-ui/react`, and any shadcn style
|
|
309
|
+
works. Keep the ones your app uses itself; the calendar doesn't need them. An app without
|
|
310
|
+
shadcn's tokens can add `base-tokens`, as [UI source](./installation.md#ui-source-optional)
|
|
311
|
+
shows.
|
|
312
|
+
|
|
313
|
+
An [agent bridge](./agents/connect.md) now lists the toolbar's buttons and the view select
|
|
314
|
+
beside the calendar, as `button` and `select` entries, and your `allow` hears the steps an agent
|
|
315
|
+
takes on them. The calendar's tooltips no longer need a `TooltipProvider`, and they don't follow
|
|
316
|
+
its `delay`: the toolbar's open after 400 ms, which `tooltipDefaults` in
|
|
317
|
+
`components/calendar/ui/tooltip.styles.ts` sets.
|
|
318
|
+
|
|
319
|
+
If you edited the views, in either flavour, a few of their own props changed with the move:
|
|
320
|
+
|
|
321
|
+
- `renderUnavailable` is a function of the band's props and its state, `(props, state) =>
|
|
322
|
+
element`. An element alone no longer works: wrap it in a function that spreads `props` on it.
|
|
323
|
+
- `AnnotationMark`'s `render` takes an element, and the mark's props merge into it. A function no
|
|
324
|
+
longer works.
|
|
325
|
+
- The history toast's `recordedAnnouncement(step, title)` message is now
|
|
326
|
+
`recordedHint(step)`, in `stylex-calendar-history-toast` too. It returns only the part after the
|
|
327
|
+
toast's title, such as "To undo it, press F6 and choose Undo.", since the title is read first. A screen reader now reads every toast
|
|
328
|
+
as it shows, after the announcement of the gesture that caused it.
|
|
329
|
+
- A popover trigger has `aria-expanded` while its popover is open, in place of Base UI's
|
|
330
|
+
`data-popup-open`. Style it with `aria-expanded:`, or `"[aria-expanded=true]"` in StyleX.
|
|
331
|
+
- The time grid's event tooltips share one tooltip per view. A composition that renders
|
|
332
|
+
`TimeGridEvent` outside the registry's views wraps them in `TimeGridEventTooltip` to do the
|
|
333
|
+
same; without it, each event brings its own.
|
|
334
|
+
|
|
335
|
+
## Add the StyleX items again
|
|
336
|
+
|
|
337
|
+
In 1.x the `stylex-` items took their buttons, badges, tooltips and the view select from Astryx,
|
|
338
|
+
and their popovers, dialog and toast from Base UI. Their base colors, such as `--background` and
|
|
339
|
+
`--primary`, read the Astryx theme around them. In 2.0 they use `stylex-calendar-ui`, the StyleX
|
|
340
|
+
twin of `calendar-ui`, on ui-sdk, with the same look as the Tailwind items, and their tokens hold
|
|
341
|
+
their own values.
|
|
342
|
+
|
|
343
|
+
1. Add the items you use again, or all of them:
|
|
344
|
+
|
|
345
|
+
```bash
|
|
346
|
+
npx shadcn@latest add https://time.molten.sh/r/stylex-calendar-full.json
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
This installs `stylex-calendar-ui` in `components/calendar-stylex/ui/`, with each control's
|
|
350
|
+
styles in a `*.styles.ts` file beside it, and adds `@ui-sdk/core` and `@ui-sdk/react`.
|
|
351
|
+
|
|
352
|
+
2. Name ui-sdk's layer at the top of your global CSS, as [Add the global CSS](./stylex.md#add-the-global-css)
|
|
353
|
+
shows. If Astryx's `Theme` set your root's `color-scheme`, and you drop it, set it yourself.
|
|
354
|
+
|
|
355
|
+
3. To keep the calendar in your Astryx theme's colors, map them onto the base colors, as
|
|
356
|
+
[Use your design system's colors](./stylex.md#use-your-design-systems-colors) shows. Without
|
|
357
|
+
that, the calendar takes the Tailwind theme's neutral colors. Astryx's root `Theme` puts its
|
|
358
|
+
variables on `<html>`, so the theme goes there too:
|
|
359
|
+
|
|
360
|
+
```tsx
|
|
361
|
+
const astryxCalendarTheme = stylex.createTheme(calendarVars, {
|
|
362
|
+
"--radius": "var(--radius-element)",
|
|
363
|
+
"--background": "var(--color-background-surface)",
|
|
364
|
+
"--foreground": "var(--color-text-primary)",
|
|
365
|
+
"--popover": "var(--color-background-popover)",
|
|
366
|
+
"--primary": "var(--color-accent)",
|
|
367
|
+
"--muted-foreground": "var(--color-text-secondary)",
|
|
368
|
+
"--border": "var(--color-border)",
|
|
369
|
+
"--ring": "var(--focus-outline-color)",
|
|
370
|
+
// …and the rest of the base colors, in the same way.
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
document.documentElement.classList.add(
|
|
374
|
+
...(stylex.props(astryxCalendarTheme).className ?? "").split(" "),
|
|
375
|
+
);
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
4. The items no longer list `@astryxdesign/core` or `@base-ui/react`. Keep them if your app uses
|
|
379
|
+
them itself. The views hide text visually with `visuallyHiddenStyles`, in
|
|
380
|
+
`components/calendar-stylex/visually-hidden.styles.ts`, in place of Astryx's `VisuallyHidden`.
|
|
381
|
+
|
|
382
|
+
The props that changed for the Tailwind views, listed above, changed in the StyleX views too.
|
|
383
|
+
|
|
384
|
+
## Name the calendar
|
|
385
|
+
|
|
386
|
+
`Root` takes three new props:
|
|
387
|
+
|
|
388
|
+
| Prop | Effect |
|
|
389
|
+
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
|
|
390
|
+
| `label` | Names the calendar. `Calendar.Frame` takes it as its `aria-label`, and an agent finds the calendar by it |
|
|
391
|
+
| `allowAgentDelete` | Gives an agent the `deleteEvent` action. Off by default: the calendar has no such action then, and refuses any delete an agent causes |
|
|
392
|
+
| `formatAgentEventLabel` | Names each visible event in the list an agent reads. By default the title and ISO times |
|
|
393
|
+
|
|
394
|
+
Without `label`, the frame is labelled by the title, as in 1.x, so nothing changes for a screen
|
|
395
|
+
reader until you set it. With `label`, the frame's name is the label and the title is no longer
|
|
396
|
+
part of it. `useCalendarMeta()` has the label as `meta.label`.
|
|
397
|
+
|
|
398
|
+
## Make it agent-ready
|
|
399
|
+
|
|
400
|
+
Upgrading exposes nothing. An agent reaches a calendar only after your app creates a bridge.
|
|
401
|
+
When you want that:
|
|
402
|
+
|
|
403
|
+
1. Give `Root` a `label`.
|
|
404
|
+
2. Render `Calendar.Frame` inside `Root`. A calendar without a frame works for people and isn't
|
|
405
|
+
listed for agents.
|
|
406
|
+
3. Read `detail.fields` in `onEventChange`, so a title an agent sends is saved. See
|
|
407
|
+
[Save what the agent sent](./agents/connect.md#save-what-the-agent-sent).
|
|
408
|
+
4. Create the bridge with an `allow`, as [Connect an agent](./agents/connect.md) shows.
|
|
409
|
+
|
|
410
|
+
A calendar without `onEventChange` gives an agent the reading and navigation actions and no
|
|
411
|
+
event action, as it gives a person no editing.
|
|
412
|
+
|
|
413
|
+
## New packages
|
|
414
|
+
|
|
415
|
+
| Package | What it is | Install it when |
|
|
416
|
+
| --------------------------------- | ------------------------------------------------------ | --------------------------------- |
|
|
417
|
+
| `@moltenship/calendar-primitives` | The framework-free runtime, store and ui-sdk primitive | You write a framework integration |
|
|
418
|
+
| `@moltenship/calendar-solid` | The Solid integration | Your app is on SolidJS 2 |
|
|
419
|
+
|
|
420
|
+
`createCalendarStore`, `resolveViewOptions` and the state types moved from
|
|
421
|
+
`@moltenship/calendar-react` into the primitives. Both `@moltenship/calendar` and
|
|
422
|
+
`@moltenship/calendar-react` re-export them, so imports from either still work and a store you
|
|
423
|
+
created keeps its contract. See [Primitives](./api/primitives.md).
|
|
424
|
+
|
|
425
|
+
## The pointer hook moved
|
|
426
|
+
|
|
427
|
+
`@moltenship/calendar-dnd` imports no framework in 2.0, and `@moltenship/calendar-solid` binds it too. Its
|
|
428
|
+
one React hook, `useCalendarPointer`, is in `@moltenship/calendar-react` now, with the same
|
|
429
|
+
options and return value. `@moltenship/calendar` exports it as before, so an import from the
|
|
430
|
+
facade doesn't change. An import from the pointer package does:
|
|
431
|
+
|
|
432
|
+
```ts title="my-week-view.tsx"
|
|
433
|
+
// 1.x
|
|
434
|
+
import { useCalendarPointer } from "@moltenship/calendar-dnd";
|
|
435
|
+
// 2.0
|
|
436
|
+
import { useCalendarPointer } from "@moltenship/calendar-react";
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
Everything else in `@moltenship/calendar-dnd` stays where it was: `attachCalendarPointer`,
|
|
440
|
+
`startCalendarDrop`, `monitorCalendarDrags` and the attribute helpers. It no longer has React as a
|
|
441
|
+
peer dependency.
|
|
442
|
+
|
|
443
|
+
### With React but without calendar-react
|
|
444
|
+
|
|
445
|
+
An app that used `@moltenship/calendar-dnd` in React without `@moltenship/calendar-react` has two
|
|
446
|
+
ways on:
|
|
447
|
+
|
|
448
|
+
- **Add `@moltenship/calendar-react`** and its peers, `@ui-sdk/core` and `@ui-sdk/react`, then
|
|
449
|
+
import the hook from it as above.
|
|
450
|
+
- **Keep the hook in the app.** It's a few lines around `attachCalendarPointer`:
|
|
451
|
+
|
|
452
|
+
```tsx title="use-calendar-pointer.ts"
|
|
453
|
+
import type { EventId, ResourceId } from "@moltenship/calendar-core";
|
|
454
|
+
import { attachCalendarPointer, type CalendarPointerOptions } from "@moltenship/calendar-dnd";
|
|
455
|
+
import { useCallback, useInsertionEffect, useRef, type RefCallback } from "react";
|
|
456
|
+
|
|
457
|
+
export function useCalendarPointer<
|
|
458
|
+
TEvent,
|
|
459
|
+
TEventId extends EventId,
|
|
460
|
+
TResourceId extends ResourceId,
|
|
461
|
+
>(options: CalendarPointerOptions<TEvent, TEventId, TResourceId>): RefCallback<HTMLElement> {
|
|
462
|
+
const latest = useRef(options);
|
|
463
|
+
useInsertionEffect(() => {
|
|
464
|
+
latest.current = options;
|
|
465
|
+
});
|
|
466
|
+
const disabled = options.disabled === true;
|
|
467
|
+
// Options are read as a gesture goes; only `disabled` attaches the listeners again.
|
|
468
|
+
return useCallback(
|
|
469
|
+
(element: HTMLElement | null) =>
|
|
470
|
+
element === null ? undefined : attachCalendarPointer(element, () => latest.current),
|
|
471
|
+
[disabled],
|
|
472
|
+
);
|
|
473
|
+
}
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
Either way, keep every `@moltenship/calendar*` package on one version. `@moltenship/calendar-react`
|
|
477
|
+
depends on `@moltenship/calendar-dnd` at its own exact version, and the pointer package keeps its
|
|
478
|
+
drag registry in the module: two copies of it don't hear each other's drags, so a drop from one
|
|
479
|
+
never reaches a view bound through the other.
|
|
480
|
+
|
|
481
|
+
## Tests
|
|
482
|
+
|
|
483
|
+
- **Scripted clicks.** A click a test dispatches reads `source: "programmatic"` in a state
|
|
484
|
+
handler. Only a real pointer reads `"mouse"`.
|
|
485
|
+
- **The frame's name.** A test that finds the frame by its accessible name finds the `label` once
|
|
486
|
+
you set one.
|
|
487
|
+
- **The registry's controls in jsdom.** They're ui-sdk's, which read paint timing, measure
|
|
488
|
+
toasts and wait for transitions, none of which jsdom has, and jsdom hides every popup. Add the
|
|
489
|
+
stubs [Testing](./testing.md#set-up-vitest) lists to your test setup file.
|
|
490
|
+
- **Agent changes.** [Testing](./testing.md#changes-an-agent-makes) shows how to run an agent's
|
|
491
|
+
step in a test.
|
|
492
|
+
|
|
493
|
+
## For coding agents
|
|
494
|
+
|
|
495
|
+
If a coding agent does the upgrade, give it the docs for the version you install. They ship in the
|
|
496
|
+
package, at `node_modules/@moltenship/calendar/docs`, with a skill beside them. See
|
|
497
|
+
[Build with a coding agent](./agents/coding-agents.md).
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# Quick start
|
|
2
|
+
|
|
3
|
+
Build a week, day, month and agenda calendar in React with the built-in views.
|
|
4
|
+
|
|
5
|
+
Source: https://time.molten.sh/docs/react/quick-start
|
|
6
|
+
|
|
7
|
+
You'll build this calendar in React: a toolbar, a view switcher, and the built-in week, day, month
|
|
8
|
+
and agenda views, showing your own meetings.
|
|
9
|
+
|
|
10
|
+
> Live example: see it at https://time.molten.sh/docs/react/quick-start
|
|
11
|
+
|
|
12
|
+
To see these views running with more data before you start, open the [live demo](https://moltenship-time-demo.vercel.app).
|
|
13
|
+
|
|
14
|
+
**Step 1**
|
|
15
|
+
|
|
16
|
+
### Install
|
|
17
|
+
|
|
18
|
+
Install `@moltenship/calendar` and its peer dependencies as [Installation](./installation.md#install)
|
|
19
|
+
describes, with a `Temporal` polyfill if your browsers need one.
|
|
20
|
+
|
|
21
|
+
**Step 2**
|
|
22
|
+
|
|
23
|
+
### Add the UI source
|
|
24
|
+
|
|
25
|
+
The views are source files that you add to your app with the shadcn CLI. They use shadcn/ui's
|
|
26
|
+
tokens and bring their own controls, so any shadcn style works (see
|
|
27
|
+
[UI source](./installation.md#ui-source-optional)). Name ui-sdk's CSS layer before Tailwind in
|
|
28
|
+
your global CSS, then add the week and day, month, and agenda views:
|
|
29
|
+
|
|
30
|
+
```css title="globals.css"
|
|
31
|
+
@layer ui-sdk;
|
|
32
|
+
@import "tailwindcss";
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npx shadcn@latest add \
|
|
37
|
+
https://time.molten.sh/r/time-grid-view.json \
|
|
38
|
+
https://time.molten.sh/r/month-view.json \
|
|
39
|
+
https://time.molten.sh/r/list-view.json
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
They bring the theme, the toolbar, view switcher and event chip from the shared `calendar` item,
|
|
43
|
+
and the calendar's controls and popups from `calendar-ui`. The files land in
|
|
44
|
+
`components/calendar/` and are yours to change, as [Customization](./customization.md) describes.
|
|
45
|
+
The controls are built on ui-sdk, so name its CSS layer before Tailwind in
|
|
46
|
+
your global CSS:
|
|
47
|
+
|
|
48
|
+
```css title="globals.css"
|
|
49
|
+
@layer ui-sdk;
|
|
50
|
+
@import "tailwindcss";
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**Step 3**
|
|
54
|
+
|
|
55
|
+
### Create the calendar
|
|
56
|
+
|
|
57
|
+
Describe your records with an adapter, then create a calendar with the views you want. The first
|
|
58
|
+
view in the list is shown first.
|
|
59
|
+
|
|
60
|
+
```tsx title="calendar.tsx"
|
|
61
|
+
"use client";
|
|
62
|
+
|
|
63
|
+
import { createCalendar, defineEventAdapter } from "@moltenship/calendar";
|
|
64
|
+
|
|
65
|
+
import { CalendarToolbar } from "@/components/calendar/calendar-toolbar";
|
|
66
|
+
import type { CalendarEventColor } from "@/components/calendar/event-colors";
|
|
67
|
+
import { createAgendaView } from "@/components/calendar/list-view/agenda-view";
|
|
68
|
+
import { createMonthView } from "@/components/calendar/month-view/month-view";
|
|
69
|
+
import { createDayView, createWeekView } from "@/components/calendar/time-grid-view/time-grid-view";
|
|
70
|
+
import { ViewSwitcher } from "@/components/calendar/view-switcher";
|
|
71
|
+
|
|
72
|
+
export interface Meeting {
|
|
73
|
+
readonly id: string;
|
|
74
|
+
readonly title: string;
|
|
75
|
+
readonly start: Temporal.Instant;
|
|
76
|
+
readonly end: Temporal.Instant;
|
|
77
|
+
readonly color: CalendarEventColor;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export const eventAdapter = defineEventAdapter<Meeting>()({
|
|
81
|
+
getId: (meeting) => meeting.id,
|
|
82
|
+
getTitle: (meeting) => meeting.title,
|
|
83
|
+
getInterval: (meeting) => ({ kind: "timed", start: meeting.start, end: meeting.end }),
|
|
84
|
+
getResourceIds: () => [],
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const getEventColor = (meeting: Meeting) => meeting.color;
|
|
88
|
+
|
|
89
|
+
export const Calendar = createCalendar<Meeting>()({
|
|
90
|
+
eventAdapter,
|
|
91
|
+
views: [
|
|
92
|
+
createWeekView<Meeting>({ dayView: "day", getEventColor }),
|
|
93
|
+
createDayView<Meeting>({ getEventColor }),
|
|
94
|
+
createMonthView<Meeting>({ getEventColor }),
|
|
95
|
+
createAgendaView<Meeting>({ getEventColor }),
|
|
96
|
+
],
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
`getEventColor` picks each event's color from the [palette](./theming.md#event-colors).
|
|
101
|
+
`dayView: "day"` makes the dates in the week header open the day view.
|
|
102
|
+
|
|
103
|
+
**Step 4**
|
|
104
|
+
|
|
105
|
+
### Render it
|
|
106
|
+
|
|
107
|
+
`Root` holds the calendar state. It needs your events, a starting date, a time zone, a locale, and
|
|
108
|
+
week rules (the first day of the week, where 1 is Monday, and the weekend days).
|
|
109
|
+
`CalendarToolbar` adds the Today, previous, and next buttons and the title, and the registry's
|
|
110
|
+
`ViewSwitcher` switches between your views.
|
|
111
|
+
|
|
112
|
+
```tsx title="calendar.tsx"
|
|
113
|
+
const viewLabels = { week: "Week", day: "Day", month: "Month", agenda: "Agenda" };
|
|
114
|
+
const viewSwitcherOptions = Calendar.views.map(({ name }) => ({
|
|
115
|
+
value: name,
|
|
116
|
+
label: viewLabels[name],
|
|
117
|
+
}));
|
|
118
|
+
|
|
119
|
+
function CalendarViewSwitcher() {
|
|
120
|
+
const view = Calendar.useCalendarSelector((state) => state.view);
|
|
121
|
+
const { setView } = Calendar.useCalendarActions();
|
|
122
|
+
return <ViewSwitcher value={view} onValueChange={setView} options={viewSwitcherOptions} />;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export const weekRules = { firstDay: 1, minimalDays: 4, weekend: [6, 7] } as const;
|
|
126
|
+
|
|
127
|
+
export function TeamCalendar({ meetings }: { readonly meetings: readonly Meeting[] }) {
|
|
128
|
+
return (
|
|
129
|
+
<Calendar.Root
|
|
130
|
+
events={meetings}
|
|
131
|
+
defaultAnchorDate={Temporal.PlainDate.from("2026-10-08")}
|
|
132
|
+
defaultTimeZone="Europe/Berlin"
|
|
133
|
+
locale="en-US"
|
|
134
|
+
weekRules={weekRules}
|
|
135
|
+
>
|
|
136
|
+
<Calendar.Frame className="flex h-[640px] flex-col rounded-xl border">
|
|
137
|
+
<CalendarToolbar calendar={Calendar}>
|
|
138
|
+
<CalendarViewSwitcher />
|
|
139
|
+
</CalendarToolbar>
|
|
140
|
+
<Calendar.Viewport className="min-h-0 flex-1">
|
|
141
|
+
<Calendar.ActiveView />
|
|
142
|
+
</Calendar.Viewport>
|
|
143
|
+
</Calendar.Frame>
|
|
144
|
+
</Calendar.Root>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Give the frame a height: the views fill it and scroll inside it. The calendar is read-only until
|
|
150
|
+
you add an `onEventChange` handler; [Interactions](./interactions.md) shows how to save dragged and
|
|
151
|
+
resized events.
|
|
152
|
+
|
|
153
|
+
> **Using Next.js?**
|
|
154
|
+
>
|
|
155
|
+
> Calendar modules are Client Components, which is why the file starts with `"use client"`. See
|
|
156
|
+
> [Next.js and server rendering](./guides/nextjs.md) for passing data from a Server Component.
|
|
157
|
+
|
|
158
|
+
## Next steps
|
|
159
|
+
|
|
160
|
+
- [Interactions](./interactions.md): Let people move, resize, create, and delete events.
|
|
161
|
+
- [Views](./views.md): Options for each built-in view.
|
|
162
|
+
- [Customization](./customization.md): Set tokens, edit the files you added, swap the controls, or build your own UI.
|
|
163
|
+
- [Agents](./agents/connect.md): Let an AI agent read this calendar and change it, under your rules.
|