@moltenship/calendar 1.0.0-rc.2 → 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -4
- package/dist/index.d.mts +2 -2
- package/docs/accessibility.md +304 -0
- package/docs/agents/changes.md +449 -0
- package/docs/agents/coding-agents.md +117 -0
- package/docs/agents/connect.md +435 -0
- package/docs/agents/deleting.md +296 -0
- package/docs/agents/reference.md +512 -0
- package/docs/agents/server.md +317 -0
- package/docs/agents/webmcp.md +153 -0
- package/docs/agents.md +353 -0
- package/docs/annotations.md +196 -0
- package/docs/api/changes.md +248 -0
- package/docs/api/dnd-kit.md +267 -0
- package/docs/api/events.md +152 -0
- package/docs/api/ics.md +524 -0
- package/docs/api/primitives.md +168 -0
- package/docs/api/react.md +236 -0
- package/docs/api/recurrence.md +586 -0
- package/docs/api/solid.md +460 -0
- package/docs/api/store.md +92 -0
- package/docs/api/temporal.md +172 -0
- package/docs/api.md +57 -0
- package/docs/availability.md +573 -0
- package/docs/comparison.md +279 -0
- package/docs/concepts/anatomy.md +73 -0
- package/docs/concepts/events.md +164 -0
- package/docs/concepts/how-it-works.md +95 -0
- package/docs/concepts/recurrence.md +127 -0
- package/docs/concepts/state.md +244 -0
- package/docs/concepts/time.md +170 -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/ics.md +486 -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/recurring-events.md +583 -0
- package/docs/guides/tanstack-query.md +485 -0
- package/docs/index.md +118 -0
- package/docs/installation.md +194 -0
- package/docs/interactions.md +408 -0
- package/docs/llms.txt +86 -0
- package/docs/migrating-to-2.md +322 -0
- package/docs/quick-start.md +159 -0
- package/docs/stylex.md +265 -0
- package/docs/testing.md +581 -0
- package/docs/theme-builder.md +81 -0
- package/docs/theming.md +169 -0
- package/docs/undo-redo.md +339 -0
- package/docs/views/agenda.md +221 -0
- package/docs/views/custom-views.md +192 -0
- package/docs/views/month.md +109 -0
- package/docs/views/resource-columns.md +261 -0
- package/docs/views/resource-timeline.md +225 -0
- package/docs/views/scrolling.md +192 -0
- package/docs/views/week-and-day.md +257 -0
- package/docs/views/year.md +138 -0
- package/docs/views.md +69 -0
- package/package.json +41 -14
- package/skills/moltenship-time/SKILL.md +75 -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 +168 -0
- package/skills/moltenship-time/references/mistakes.md +98 -0
- package/skills/moltenship-time/references/solid.md +202 -0
- package/skills/moltenship-time/references/state.md +129 -0
- package/skills/moltenship-time/references/testing.md +176 -0
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
# Solid
|
|
2
|
+
|
|
3
|
+
The SolidJS 2 integration, a preview. What it has, how it differs from React, and what isn't in it yet.
|
|
4
|
+
|
|
5
|
+
Source: https://time.molten.sh/docs/api/solid
|
|
6
|
+
|
|
7
|
+
`@moltenship/calendar-solid` is the calendar for [SolidJS](https://www.solidjs.com) 2. It renders
|
|
8
|
+
the same [primitive](./primitives.md) as the React integration, so both share one
|
|
9
|
+
implementation of the calendar's state, actions, event changes and [agent surface](../agents.md).
|
|
10
|
+
|
|
11
|
+
> **A preview**
|
|
12
|
+
>
|
|
13
|
+
> This package is new in 2.0 and its API can change in any release before 2.0.0. It has the root,
|
|
14
|
+
> the structural parts, the read hooks and the agent surface. It has no ready-made views, no
|
|
15
|
+
> keyboard navigation and no dragging yet: see [what isn't in it yet](#what-isnt-in-it-yet). The
|
|
16
|
+
> rest of these docs describe React.
|
|
17
|
+
|
|
18
|
+
## Install
|
|
19
|
+
|
|
20
|
+
**pnpm**
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pnpm add @moltenship/calendar-solid @moltenship/calendar-core solid-js @solidjs/web @ui-sdk/core @ui-sdk/solid
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**npm**
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npm install @moltenship/calendar-solid @moltenship/calendar-core solid-js @solidjs/web @ui-sdk/core @ui-sdk/solid
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**yarn**
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
yarn add @moltenship/calendar-solid @moltenship/calendar-core solid-js @solidjs/web @ui-sdk/core @ui-sdk/solid
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**bun**
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
bun add @moltenship/calendar-solid @moltenship/calendar-core solid-js @solidjs/web @ui-sdk/core @ui-sdk/solid
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
- **`@moltenship/calendar-core`** has the event adapter and the functions a view is made of. The
|
|
45
|
+
Solid package doesn't re-export them.
|
|
46
|
+
- **`solid-js` and `@solidjs/web`** 2.0, and **`@ui-sdk/core` and `@ui-sdk/solid`** from
|
|
47
|
+
`0.1.0-beta.16` on within the 0.1 line, are peer dependencies.
|
|
48
|
+
- **Don't install `@moltenship/calendar`.** It's the React package, and it doesn't re-export this
|
|
49
|
+
one.
|
|
50
|
+
- A runtime with `Temporal`, or a polyfill that defines `globalThis.Temporal`, loaded before the
|
|
51
|
+
calendar, and TypeScript 6 or later with `"lib": ["DOM", "DOM.Iterable", "ESNext"]`. Both are the
|
|
52
|
+
same as for React: see [Installation](../installation.md).
|
|
53
|
+
|
|
54
|
+
### Build setup
|
|
55
|
+
|
|
56
|
+
The integration is plain TypeScript, and `@ui-sdk/solid` ships JSX for your app's Solid compiler.
|
|
57
|
+
With Vite, use Solid's plugin:
|
|
58
|
+
|
|
59
|
+
```ts title="vite.config.ts"
|
|
60
|
+
import solid from "@solidjs/vite-plugin";
|
|
61
|
+
import { defineConfig } from "vite";
|
|
62
|
+
|
|
63
|
+
export default defineConfig({
|
|
64
|
+
plugins: [solid()],
|
|
65
|
+
optimizeDeps: {
|
|
66
|
+
// One copy of ui-sdk's core in the dev server. The calendar and the agent bridge find each
|
|
67
|
+
// other through it.
|
|
68
|
+
exclude: ["@ui-sdk/core"],
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```json title="tsconfig.json"
|
|
74
|
+
{
|
|
75
|
+
"compilerOptions": {
|
|
76
|
+
"jsx": "preserve",
|
|
77
|
+
"jsxImportSource": "@solidjs/web",
|
|
78
|
+
"lib": ["ESNext", "DOM", "DOM.Iterable"]
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
If the page fails with `React is not defined` from a file in `@ui-sdk/solid`, the plugin didn't
|
|
84
|
+
compile that package as Solid. Check that `@ui-sdk/solid` is in your app's own `dependencies`,
|
|
85
|
+
where the install command puts it.
|
|
86
|
+
|
|
87
|
+
## A calendar
|
|
88
|
+
|
|
89
|
+
There are no ready-made Solid views. A view is a strategy from `@moltenship/calendar-core` and a
|
|
90
|
+
Solid component that draws its projection. This one is the engine's list projection as an agenda:
|
|
91
|
+
|
|
92
|
+
```tsx title="calendar.tsx"
|
|
93
|
+
import {
|
|
94
|
+
defineEventAdapter,
|
|
95
|
+
getListRange,
|
|
96
|
+
getListTitle,
|
|
97
|
+
navigateList,
|
|
98
|
+
projectList,
|
|
99
|
+
type CalendarEventInterval,
|
|
100
|
+
type ListProjection,
|
|
101
|
+
type ListViewOptions,
|
|
102
|
+
} from "@moltenship/calendar-core";
|
|
103
|
+
import {
|
|
104
|
+
createCalendar,
|
|
105
|
+
defineCalendarView,
|
|
106
|
+
type CalendarViewRendererProps,
|
|
107
|
+
} from "@moltenship/calendar-solid";
|
|
108
|
+
import { For } from "solid-js";
|
|
109
|
+
|
|
110
|
+
export interface Meeting {
|
|
111
|
+
readonly id: string;
|
|
112
|
+
readonly title: string;
|
|
113
|
+
readonly interval: CalendarEventInterval;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const eventAdapter = defineEventAdapter<Meeting>()({
|
|
117
|
+
getId: (meeting) => meeting.id,
|
|
118
|
+
getTitle: (meeting) => meeting.title,
|
|
119
|
+
getInterval: (meeting) => meeting.interval,
|
|
120
|
+
getResourceIds: () => [],
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
type List = ListProjection<Meeting, string, string>;
|
|
124
|
+
|
|
125
|
+
// Props are getters in Solid: read `props.projection` in the JSX, and don't destructure it.
|
|
126
|
+
function Agenda(props: CalendarViewRendererProps<List, ListViewOptions>) {
|
|
127
|
+
const day = (date: Temporal.PlainDate) =>
|
|
128
|
+
date.toLocaleString(props.environment.locale, { dateStyle: "full" });
|
|
129
|
+
|
|
130
|
+
return (
|
|
131
|
+
<For each={props.projection.days} fallback={<p>Nothing in these weeks.</p>}>
|
|
132
|
+
{(entry) => (
|
|
133
|
+
<section>
|
|
134
|
+
<h3>{day(entry.date)}</h3>
|
|
135
|
+
<ul>
|
|
136
|
+
<For each={entry.items}>
|
|
137
|
+
{(item) => <li data-event-id={item.event.id}>{item.event.title}</li>}
|
|
138
|
+
</For>
|
|
139
|
+
</ul>
|
|
140
|
+
</section>
|
|
141
|
+
)}
|
|
142
|
+
</For>
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const listView = defineCalendarView({
|
|
147
|
+
name: "list",
|
|
148
|
+
defaultOptions: { weeks: 2 } as ListViewOptions,
|
|
149
|
+
strategy: {
|
|
150
|
+
getRange: (anchor, environment, options) => getListRange(anchor, environment, options),
|
|
151
|
+
getTitle: (range, environment) => getListTitle(range, environment),
|
|
152
|
+
navigate: (anchor, delta, options) => navigateList(anchor, delta, options),
|
|
153
|
+
project: (input) => projectList(input) as List,
|
|
154
|
+
},
|
|
155
|
+
Renderer: Agenda,
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
export const Calendar = createCalendar<Meeting>()({ eventAdapter, views: [listView] });
|
|
159
|
+
|
|
160
|
+
export type View = (typeof Calendar.views)[number]["name"];
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
`Root` takes your events and the handler that saves a change, as in React. Events live in a
|
|
164
|
+
signal of yours, and the calendar never stores them:
|
|
165
|
+
|
|
166
|
+
```tsx title="app.tsx"
|
|
167
|
+
import type { CalendarProposalDetail, CalendarWeekRules } from "@moltenship/calendar-core";
|
|
168
|
+
import { createSignal } from "solid-js";
|
|
169
|
+
|
|
170
|
+
import { Calendar, type Meeting } from "./calendar";
|
|
171
|
+
|
|
172
|
+
const timeZone = "Europe/Berlin";
|
|
173
|
+
const at = (value: string) =>
|
|
174
|
+
Temporal.PlainDateTime.from(value).toZonedDateTime(timeZone).toInstant();
|
|
175
|
+
|
|
176
|
+
const seed: readonly Meeting[] = [
|
|
177
|
+
{
|
|
178
|
+
id: "standup",
|
|
179
|
+
title: "Standup",
|
|
180
|
+
interval: { kind: "timed", start: at("2026-10-08T09:00"), end: at("2026-10-08T09:30") },
|
|
181
|
+
},
|
|
182
|
+
];
|
|
183
|
+
|
|
184
|
+
const weekRules: CalendarWeekRules = { firstDay: 1, minimalDays: 4, weekend: [6, 7] };
|
|
185
|
+
|
|
186
|
+
// A title an agent sent with `createEvent` or `updateEvent`. A person's gesture sends none.
|
|
187
|
+
function titleFrom(detail: CalendarProposalDetail): string | undefined {
|
|
188
|
+
const title = detail.fields?.title;
|
|
189
|
+
return typeof title === "string" && title.trim() !== "" ? title.trim() : undefined;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function App() {
|
|
193
|
+
const [meetings, setMeetings] = createSignal<readonly Meeting[]>(seed);
|
|
194
|
+
|
|
195
|
+
return (
|
|
196
|
+
<Calendar.Root
|
|
197
|
+
label="Team calendar"
|
|
198
|
+
events={meetings()}
|
|
199
|
+
defaultAnchorDate={Temporal.PlainDate.from("2026-10-08")}
|
|
200
|
+
defaultTimeZone={timeZone}
|
|
201
|
+
locale="en-US"
|
|
202
|
+
weekRules={weekRules}
|
|
203
|
+
onEventChange={(change, detail) => {
|
|
204
|
+
const title = titleFrom(detail);
|
|
205
|
+
if (change.cause === "delete") {
|
|
206
|
+
setMeetings((current) => current.filter((meeting) => meeting.id !== change.eventId));
|
|
207
|
+
} else if (change.cause === "create") {
|
|
208
|
+
setMeetings((current) => [
|
|
209
|
+
...current,
|
|
210
|
+
{ id: crypto.randomUUID(), title: title ?? "New meeting", interval: change.proposed },
|
|
211
|
+
]);
|
|
212
|
+
} else {
|
|
213
|
+
setMeetings((current) =>
|
|
214
|
+
current.map((meeting) =>
|
|
215
|
+
meeting.id === change.eventId
|
|
216
|
+
? { ...meeting, title: title ?? meeting.title, interval: change.proposed }
|
|
217
|
+
: meeting,
|
|
218
|
+
),
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
}}
|
|
222
|
+
>
|
|
223
|
+
<Calendar.Frame>
|
|
224
|
+
<Calendar.Toolbar>
|
|
225
|
+
<Calendar.PreviousTrigger>Previous</Calendar.PreviousTrigger>
|
|
226
|
+
<Calendar.TodayTrigger>Today</Calendar.TodayTrigger>
|
|
227
|
+
<Calendar.NextTrigger>Next</Calendar.NextTrigger>
|
|
228
|
+
<Calendar.Title />
|
|
229
|
+
</Calendar.Toolbar>
|
|
230
|
+
<Calendar.Viewport>
|
|
231
|
+
<Calendar.ActiveView />
|
|
232
|
+
</Calendar.Viewport>
|
|
233
|
+
</Calendar.Frame>
|
|
234
|
+
</Calendar.Root>
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
A page of this site is a React app, so this example isn't live here. The repository's
|
|
240
|
+
[`apps/demo-solid`](https://github.com/Moltenship/time/tree/main/apps/demo-solid) is a running
|
|
241
|
+
Solid calendar with a month grid, an agenda and an agent panel.
|
|
242
|
+
|
|
243
|
+
## What it exports
|
|
244
|
+
|
|
245
|
+
| Export | What it is |
|
|
246
|
+
| ------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------- |
|
|
247
|
+
| `createCalendar<TEvent, TResource, TSelection, TFocus>()(options)` | The factory. Takes `eventAdapter`, `views` and `invalidEventPolicy`, as [React's](./react.md#createcalendar) does |
|
|
248
|
+
| `defineCalendarView({ name, defaultOptions, strategy, Renderer })` | A view. `Renderer` is a Solid component |
|
|
249
|
+
| `createStateSelector(source, selector, options?)` | An accessor of one value of a store |
|
|
250
|
+
| `createCalendarStore(options)` | The [state store](./store.md). The same function `@moltenship/calendar` exports |
|
|
251
|
+
| `resolveViewOptions(view, overrides)` | A view's options: its `defaultOptions` with a root's `viewOptions` over them |
|
|
252
|
+
|
|
253
|
+
It also exports the types of all of these, and the state types: `CalendarPublicState`,
|
|
254
|
+
`CalendarActions`, `CalendarStore`, `CalendarStateChangeDetail`, `CalendarCommandOptions` and the
|
|
255
|
+
others [Primitives](./primitives.md#what-it-exports) lists.
|
|
256
|
+
|
|
257
|
+
## The factory
|
|
258
|
+
|
|
259
|
+
`createCalendar` returns the parts and hooks for your record types.
|
|
260
|
+
|
|
261
|
+
### Parts
|
|
262
|
+
|
|
263
|
+
| Part | Renders | Notes |
|
|
264
|
+
| ----------------- | ----------- | ------------------------------------------------------------------------------------------ |
|
|
265
|
+
| `Root` | nothing | Provides the calendar. Its props are the ones [React's `Root`](./react.md#root) takes |
|
|
266
|
+
| `Frame` | `<section>` | Named by `Root`'s `label`, or by the title without one. An agent finds the calendar here |
|
|
267
|
+
| `Toolbar` | `<header>` | |
|
|
268
|
+
| `Title` | `<span>` | The visible dates, from the view's `getTitle` |
|
|
269
|
+
| `PreviousTrigger` | `<button>` | Needs children or an `aria-label` |
|
|
270
|
+
| `NextTrigger` | `<button>` | Needs children or an `aria-label` |
|
|
271
|
+
| `TodayTrigger` | `<button>` | Needs children or an `aria-label` |
|
|
272
|
+
| `ViewSwitcher` | `<select>` | One option per view. Requires `getViewLabel(name)` |
|
|
273
|
+
| `Viewport` | `<div>` | Wrapper for the view |
|
|
274
|
+
| `ActiveView` | view output | Renders the active view's `Renderer`, or `fallback` if the view isn't registered |
|
|
275
|
+
|
|
276
|
+
Each part has the `data-calendar-part` attribute React's has, so CSS written for one works for the
|
|
277
|
+
other. The parts take the element's own props, in Solid's spelling: `class`, not `className`.
|
|
278
|
+
|
|
279
|
+
`Root`'s props have the same names, types and defaults as in React, the agent's `label`,
|
|
280
|
+
`allowAgentDelete` and `formatAgentEventLabel` included. Pass a signal's value for a prop that
|
|
281
|
+
changes: `events={meetings()}`, `view={view()}`.
|
|
282
|
+
|
|
283
|
+
### Hooks
|
|
284
|
+
|
|
285
|
+
Call them in a component inside `Root`. Where React's hook returns a value, Solid's returns an
|
|
286
|
+
accessor:
|
|
287
|
+
|
|
288
|
+
| Hook | Returns |
|
|
289
|
+
| ----------------------------------------- | ------------------------------------------------------------------------------------------------------ |
|
|
290
|
+
| `useCalendarState()` | `Accessor` of the six state values |
|
|
291
|
+
| `useCalendarSelector(selector, options?)` | `Accessor` of one value from the state. Re-runs readers only when it changes by `options.isEqual` |
|
|
292
|
+
| `useCalendarActions()` | The actions, as an object. Stable for the root's lifetime |
|
|
293
|
+
| `useCalendarMeta()` | `Accessor` of the meta: `label`, `environment`, `eventSnapshot`, `views`, `diagnostics`, `ids`, `refs` |
|
|
294
|
+
| `useVisibleRange()` | `Accessor` of the visible dates, or `null` |
|
|
295
|
+
| `useViewProjection()` | `Accessor` of the active view and its projection, or `null` |
|
|
296
|
+
| `useCalendarPendingChanges(selector?)` | `Accessor` of the changes being saved, or of what `selector` picks from them |
|
|
297
|
+
| `useCalendar()` | `{ actions, meta, state }`. `meta` and `state` are getters |
|
|
298
|
+
|
|
299
|
+
```tsx title="status.tsx"
|
|
300
|
+
import { Calendar } from "./calendar";
|
|
301
|
+
|
|
302
|
+
// Render it inside <Calendar.Root>.
|
|
303
|
+
export function Status() {
|
|
304
|
+
const state = Calendar.useCalendarState();
|
|
305
|
+
const range = Calendar.useVisibleRange();
|
|
306
|
+
const view = Calendar.useCalendarSelector((current) => current.view);
|
|
307
|
+
const saving = Calendar.useCalendarPendingChanges((changes) => changes.size > 0);
|
|
308
|
+
const actions = Calendar.useCalendarActions();
|
|
309
|
+
|
|
310
|
+
return (
|
|
311
|
+
<p>
|
|
312
|
+
{view()} from {range()?.start.toString()}, anchored on {state().anchorDate.toString()}
|
|
313
|
+
{saving() ? ", saving" : ""}
|
|
314
|
+
<button type="button" onClick={() => actions.navigateToday()}>
|
|
315
|
+
Today
|
|
316
|
+
</button>
|
|
317
|
+
</p>
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
## Differences from React
|
|
323
|
+
|
|
324
|
+
| In React | In Solid |
|
|
325
|
+
| -------------------------------------------- | ------------------------------------------------------------------------------------------------- |
|
|
326
|
+
| Hooks return values | Hooks return accessors: `state().view`, not `state.view` |
|
|
327
|
+
| `useCalendar()` returns plain objects | `meta` and `state` are getters. Read them in JSX, a memo or an effect, and don't destructure them |
|
|
328
|
+
| A `Renderer` gets props you can destructure | A `Renderer`'s props are getters: `props.projection`, read where it's used |
|
|
329
|
+
| `meta.refs` holds React refs | `meta.refs` holds accessors: `meta().refs.viewport()` |
|
|
330
|
+
| A state change is visible on the next render | An accessor has the new value once Solid flushes: a microtask later, or after `flush()` |
|
|
331
|
+
| `@moltenship/calendar` is the one package | `@moltenship/calendar-solid` and `@moltenship/calendar-core` |
|
|
332
|
+
| The bridge is `@ui-sdk/react/agent` | The bridge is `@ui-sdk/solid/agent` |
|
|
333
|
+
|
|
334
|
+
What doesn't differ: the [state model](../concepts/state.md), controlled and uncontrolled props,
|
|
335
|
+
[change handlers](../concepts/state.md#what-a-handler-hears), `onEventChange` and
|
|
336
|
+
`onEventChangeResult`, [policies](./changes.md), pending changes, and every agent action.
|
|
337
|
+
|
|
338
|
+
## A store outside Root
|
|
339
|
+
|
|
340
|
+
`createStateSelector` reads one value of a store as an accessor, for a component outside `Root`:
|
|
341
|
+
|
|
342
|
+
```tsx title="store.tsx"
|
|
343
|
+
import { createCalendarStore, createStateSelector } from "@moltenship/calendar-solid";
|
|
344
|
+
|
|
345
|
+
import type { View } from "./calendar";
|
|
346
|
+
|
|
347
|
+
export const store = createCalendarStore<View>({
|
|
348
|
+
defaultView: "list",
|
|
349
|
+
defaultAnchorDate: Temporal.PlainDate.from("2026-10-08"),
|
|
350
|
+
defaultTimeZone: "Europe/Berlin",
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
// An accessor of one value, for a component outside <Calendar.Root store={store}>.
|
|
354
|
+
export function AnchorDate() {
|
|
355
|
+
const anchorDate = createStateSelector(store, (state) => state.anchorDate, {
|
|
356
|
+
isEqual: (a, b) => a.equals(b),
|
|
357
|
+
});
|
|
358
|
+
return <time>{anchorDate().toString()}</time>;
|
|
359
|
+
}
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
Pass the store to `Root` as `store={store}`, and `store.actions.setAnchorDate(date)` moves the
|
|
363
|
+
calendar from anywhere. The store's view type has to be the calendar's, and so do its selection
|
|
364
|
+
and focus types if you changed them. A calendar without resources takes a store made without the
|
|
365
|
+
resource ID type, as here. [State store](./store.md) has the rest.
|
|
366
|
+
|
|
367
|
+
## Agents
|
|
368
|
+
|
|
369
|
+
The agent surface is the primitive's, so it's the same fifteen actions with the same inputs,
|
|
370
|
+
results and errors as in React: see the [agent reference](../agents/reference.md). The bridge
|
|
371
|
+
comes from ui-sdk's Solid package.
|
|
372
|
+
|
|
373
|
+
```ts title="agent.ts"
|
|
374
|
+
import { createAgent } from "@ui-sdk/solid/agent";
|
|
375
|
+
|
|
376
|
+
// One bridge for the page, created before the app renders.
|
|
377
|
+
export const agent = createAgent({
|
|
378
|
+
// Reading, navigation and changes run. A delete doesn't, until your app asks the person.
|
|
379
|
+
allow: (step) => step.action !== "deleteEvent",
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
export async function moveStandup() {
|
|
383
|
+
const outcome = await agent.act({
|
|
384
|
+
steps: [
|
|
385
|
+
{
|
|
386
|
+
ref: "Team calendar",
|
|
387
|
+
action: "moveEvent",
|
|
388
|
+
// Every action takes one object.
|
|
389
|
+
args: [{ eventId: "standup", start: "2026-10-09T11:00" }],
|
|
390
|
+
},
|
|
391
|
+
],
|
|
392
|
+
});
|
|
393
|
+
if (!outcome.ok) {
|
|
394
|
+
return outcome.error?.message ?? "failed";
|
|
395
|
+
}
|
|
396
|
+
// The change the calendar made of the step: `{ changeId, cause, eventId, proposed, status }`.
|
|
397
|
+
return JSON.stringify(outcome.steps[0]?.result);
|
|
398
|
+
}
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
With the calendar above, `moveStandup()` calls your `onEventChange` with `detail.input` equal to
|
|
402
|
+
`"agent"`, the standup shows on October 9, and the function returns the change:
|
|
403
|
+
|
|
404
|
+
```json
|
|
405
|
+
{
|
|
406
|
+
"cause": "move",
|
|
407
|
+
"changeId": "change-1",
|
|
408
|
+
"eventId": "standup",
|
|
409
|
+
"proposed": {
|
|
410
|
+
"end": "2026-10-09T11:30:00+02:00",
|
|
411
|
+
"kind": "timed",
|
|
412
|
+
"resourceIds": [],
|
|
413
|
+
"start": "2026-10-09T11:00:00+02:00"
|
|
414
|
+
},
|
|
415
|
+
"status": "saved"
|
|
416
|
+
}
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
`status` is `"saved"` because this handler saves synchronously. A handler that returns a promise
|
|
420
|
+
gives `"saving"`, and the agent reads how it ended with `getChange`: see
|
|
421
|
+
[What a step returns](../agents.md#what-a-step-returns).
|
|
422
|
+
|
|
423
|
+
- **Create the bridge before the app renders.** Import its module before the one that calls
|
|
424
|
+
`render`.
|
|
425
|
+
- **Give `Root` a `label` and render `Calendar.Frame`.** An agent finds the calendar by the label,
|
|
426
|
+
and a calendar without a frame isn't listed.
|
|
427
|
+
- **Read `detail.fields` in `onEventChange`.** An agent's `createEvent` and `updateEvent` send the
|
|
428
|
+
title there, and the calendar doesn't store it for you. The `App` above does this with
|
|
429
|
+
`titleFrom`. See [Save what the agent sent](../agents/connect.md#save-what-the-agent-sent).
|
|
430
|
+
- **A calendar has `deleteEvent` only when `Root` has `allowAgentDelete`.** Without it the action
|
|
431
|
+
isn't among the calendar's, a step that asks for it fails whatever `allow` returns, and a delete
|
|
432
|
+
an agent causes by pressing a button of yours is refused.
|
|
433
|
+
|
|
434
|
+
The [Agents](../agents.md) guides show React. The bridge's API (`createAgent`, `snapshot`, `act`,
|
|
435
|
+
`agentTools`, `registerTools`) and everything about the calendar's actions carry over; only the
|
|
436
|
+
import path changes.
|
|
437
|
+
|
|
438
|
+
## What isn't in it yet
|
|
439
|
+
|
|
440
|
+
| Missing | In React it's |
|
|
441
|
+
| ----------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
|
|
442
|
+
| Ready-made views | The [registry](../installation.md)'s week, day, month, year, agenda and timeline views, which are React source |
|
|
443
|
+
| Keyboard navigation inside a view | `useCalendarKeyboard`, `useRovingFocus`, `useCalendarFocus` |
|
|
444
|
+
| Dragging, resizing and creating with a pointer | `@moltenship/calendar-dnd` and the hooks that bind it |
|
|
445
|
+
| Gesture previews | `useCalendarDraft`, `useCalendarInteraction` |
|
|
446
|
+
| Undo and redo bindings | `useCalendarHistory`, `useCalendarHistoryShortcuts` |
|
|
447
|
+
| Announcements for screen readers | `Calendar.Announcer`, `useCalendarAnnouncer` |
|
|
448
|
+
| `Calendar.Event` | A part that looks up one event |
|
|
449
|
+
| Hooks for selection, annotations, availability, resources and the clock | `useCalendarSelection`, `useCalendarAnnotations`, `useCalendarAvailability`, `useVisibleResources`, `useNow` and others |
|
|
450
|
+
| A testing package | `@moltenship/calendar-testing`, which is React only |
|
|
451
|
+
|
|
452
|
+
`Root` already takes the props behind some of these: `annotations`, `availability`, `resources`,
|
|
453
|
+
`selection` and `focus`. The calendar validates them, policies get `availability`, and `selection`
|
|
454
|
+
and `focus` are state values you can read and set. What's missing is the hooks that hand
|
|
455
|
+
annotations, availability and the resource tree to a view, and the behaviour built on them.
|
|
456
|
+
|
|
457
|
+
Until they land, a Solid calendar is navigated and changed with its toolbar, with your own
|
|
458
|
+
controls calling `actions`, and by an agent. Events change through
|
|
459
|
+
`actions.proposeEventChange(proposal)`, which runs your policies and `onEventChange` as a drag
|
|
460
|
+
does in React.
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# State store
|
|
2
|
+
|
|
3
|
+
Create calendar state outside Root, and change it from anywhere in your app.
|
|
4
|
+
|
|
5
|
+
Source: https://time.molten.sh/docs/api/store
|
|
6
|
+
|
|
7
|
+
`Root` creates a store for its [state](../concepts/state.md) automatically. Create one yourself when
|
|
8
|
+
code outside `Root` needs to change the calendar, or when the state should survive `Root`
|
|
9
|
+
unmounting. Everything here is exported from `@moltenship/calendar`. The store has no framework in
|
|
10
|
+
it: `@moltenship/calendar-solid` exports the same `createCalendarStore`.
|
|
11
|
+
|
|
12
|
+
## createCalendarStore
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { createCalendarStore } from "@moltenship/calendar";
|
|
16
|
+
|
|
17
|
+
const store = createCalendarStore<"day" | "days">({
|
|
18
|
+
defaultView: "day",
|
|
19
|
+
defaultAnchorDate: Temporal.PlainDate.from("2026-10-08"),
|
|
20
|
+
defaultTimeZone: "Europe/Berlin",
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
store.actions.setView("days");
|
|
24
|
+
store.getSnapshot().view; // "days"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
| Name | Type | Default | Description |
|
|
28
|
+
| ---------------------------- | ------------------------ | ------- | --------------------------------- |
|
|
29
|
+
| `defaultView` | `TView` | | Required. Initial view. |
|
|
30
|
+
| `defaultAnchorDate` | `Temporal.PlainDate` | | Required. Initial date. |
|
|
31
|
+
| `defaultTimeZone` | `string` | | Required. Initial IANA time zone. |
|
|
32
|
+
| `defaultSelection` | `TSelection \| null` | `null` | Initial selection. |
|
|
33
|
+
| `defaultFocus` | `TFocus \| null` | `null` | Initial focus. |
|
|
34
|
+
| `defaultExpandedResourceIds` | `readonly TResourceId[]` | `[]` | Initial expanded resources. |
|
|
35
|
+
|
|
36
|
+
The type arguments are `<TView, TSelection, TFocus, TResourceId>`. The store has three members:
|
|
37
|
+
|
|
38
|
+
- `actions`: `setView`, `setAnchorDate`, `setTimeZone`, `setSelection`, `setFocus`, and
|
|
39
|
+
`setExpandedResourceIds`. Each takes the new value and, optionally, `{ event?, reason?, source? }`
|
|
40
|
+
(`CalendarCommandOptions`), which a mounted `Root` passes on to its
|
|
41
|
+
[change handler](../concepts/state.md#what-a-handler-hears).
|
|
42
|
+
- `getSnapshot()`: the current state as one frozen object. It's a new object after each change.
|
|
43
|
+
- `subscribe(listener)`: calls `listener` after each change and returns an unsubscribe function.
|
|
44
|
+
|
|
45
|
+
`getSnapshot` and `subscribe` fit React's `useSyncExternalStore`, so any component can read the
|
|
46
|
+
store, inside `Root` or not:
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
import { useSyncExternalStore } from "react";
|
|
50
|
+
|
|
51
|
+
function ActiveViewName() {
|
|
52
|
+
const state = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
53
|
+
return <span>{state.view}</span>;
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Sharing a store with Root
|
|
58
|
+
|
|
59
|
+
Pass the store to `Root` with the `store` prop:
|
|
60
|
+
|
|
61
|
+
```tsx
|
|
62
|
+
function JumpToHolidays() {
|
|
63
|
+
return (
|
|
64
|
+
<button onClick={() => store.actions.setAnchorDate(Temporal.PlainDate.from("2026-12-24"))}>
|
|
65
|
+
Holidays
|
|
66
|
+
</button>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
<Calendar.Root
|
|
71
|
+
store={store}
|
|
72
|
+
events={meetings}
|
|
73
|
+
defaultAnchorDate={Temporal.PlainDate.from("2026-10-08")}
|
|
74
|
+
defaultTimeZone="Europe/Berlin"
|
|
75
|
+
locale="en-US"
|
|
76
|
+
weekRules={weekRules}
|
|
77
|
+
>
|
|
78
|
+
<Calendar.ActiveView />
|
|
79
|
+
</Calendar.Root>;
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
- `Root` shows the store's values. TypeScript still asks for `defaultAnchorDate` and
|
|
83
|
+
`defaultTimeZone`, but `Root` ignores them when it has a store.
|
|
84
|
+
- `store.actions` go through the mounted `Root`: controlled props stay controlled, and their change
|
|
85
|
+
handlers run. If several mounted roots share the store, the most recently mounted one handles
|
|
86
|
+
them. A handler hears such a call with `reason: "imperative"` and `source: "programmatic"`, and
|
|
87
|
+
can stop it with `cancel()`.
|
|
88
|
+
- An [agent](../agents.md)'s changes go through the same store. The store has no agent API of its
|
|
89
|
+
own: agents reach the calendar through the mounted `Root`.
|
|
90
|
+
- `getSnapshot()` returns the values the store holds. A value you control with a prop lives in your
|
|
91
|
+
own state, not in the store.
|
|
92
|
+
- Unmounting `Root` leaves the store as it was.
|