@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,149 @@
|
|
|
1
|
+
# Next.js and server rendering
|
|
2
|
+
|
|
3
|
+
Fetch events in a Server Component and render the same calendar on the server and in the browser.
|
|
4
|
+
|
|
5
|
+
Source: https://time.molten.sh/docs/react/guides/nextjs
|
|
6
|
+
|
|
7
|
+
Time works with any React 19 framework that renders on the server. This guide uses the Next.js App
|
|
8
|
+
Router. The same rules apply elsewhere.
|
|
9
|
+
|
|
10
|
+
## Calendars are Client Components
|
|
11
|
+
|
|
12
|
+
Calendar state lives in React state, so `createCalendar`, `defineCalendarView`, and the components
|
|
13
|
+
are client-only. Put your calendar, its views, and `Root` in files that start with `"use client"`,
|
|
14
|
+
as the [Quick start](../quick-start.md) does. Server Components can render those components and pass
|
|
15
|
+
them props.
|
|
16
|
+
|
|
17
|
+
The rest of `@moltenship/calendar` works on the server too. A Server Component can import the
|
|
18
|
+
Temporal helpers or build a snapshot, for example to filter events before sending them.
|
|
19
|
+
|
|
20
|
+
## Send strings, not Temporal objects
|
|
21
|
+
|
|
22
|
+
Props from a Server Component to a Client Component must be serializable. Temporal objects aren't,
|
|
23
|
+
so send ISO 8601 strings and turn them into Temporal values in the client:
|
|
24
|
+
|
|
25
|
+
```tsx title="team-calendar.tsx"
|
|
26
|
+
// app/calendar/team-calendar.tsx
|
|
27
|
+
"use client";
|
|
28
|
+
|
|
29
|
+
import { useMemo } from "react";
|
|
30
|
+
|
|
31
|
+
import { Calendar, weekRules, type Meeting } from "./quick-start";
|
|
32
|
+
|
|
33
|
+
// A Meeting with its times as ISO 8601 strings.
|
|
34
|
+
export type MeetingJson = Omit<Meeting, "start" | "end"> & {
|
|
35
|
+
readonly start: string;
|
|
36
|
+
readonly end: string;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
interface TeamCalendarProps {
|
|
40
|
+
readonly meetings: readonly MeetingJson[];
|
|
41
|
+
readonly now: string;
|
|
42
|
+
readonly timeZone: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function TeamCalendar({ meetings, now, timeZone }: TeamCalendarProps) {
|
|
46
|
+
const events = useMemo(
|
|
47
|
+
() =>
|
|
48
|
+
meetings.map((meeting): Meeting => ({
|
|
49
|
+
...meeting,
|
|
50
|
+
start: Temporal.Instant.from(meeting.start),
|
|
51
|
+
end: Temporal.Instant.from(meeting.end),
|
|
52
|
+
})),
|
|
53
|
+
[meetings],
|
|
54
|
+
);
|
|
55
|
+
const nowInstant = Temporal.Instant.from(now);
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<Calendar.Root
|
|
59
|
+
events={events}
|
|
60
|
+
now={nowInstant}
|
|
61
|
+
defaultAnchorDate={nowInstant.toZonedDateTimeISO(timeZone).toPlainDate()}
|
|
62
|
+
defaultTimeZone={timeZone}
|
|
63
|
+
locale="en-US"
|
|
64
|
+
weekRules={weekRules}
|
|
65
|
+
>
|
|
66
|
+
<Calendar.Frame>
|
|
67
|
+
<Calendar.Toolbar>
|
|
68
|
+
<Calendar.PreviousTrigger>Previous</Calendar.PreviousTrigger>
|
|
69
|
+
<Calendar.TodayTrigger>Today</Calendar.TodayTrigger>
|
|
70
|
+
<Calendar.NextTrigger>Next</Calendar.NextTrigger>
|
|
71
|
+
<Calendar.Title />
|
|
72
|
+
</Calendar.Toolbar>
|
|
73
|
+
<Calendar.Viewport>
|
|
74
|
+
<Calendar.ActiveView />
|
|
75
|
+
</Calendar.Viewport>
|
|
76
|
+
</Calendar.Frame>
|
|
77
|
+
</Calendar.Root>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
`useMemo` keeps the converted array stable between renders, so the calendar only re-reads events
|
|
83
|
+
when `meetings` actually changes.
|
|
84
|
+
|
|
85
|
+
The page fetches the data on the server:
|
|
86
|
+
|
|
87
|
+
```tsx title="page.tsx"
|
|
88
|
+
// app/calendar/page.tsx (a Server Component)
|
|
89
|
+
import { TeamCalendar, type MeetingJson } from "./team-calendar";
|
|
90
|
+
|
|
91
|
+
async function getMeetings(): Promise<readonly MeetingJson[]> {
|
|
92
|
+
// Replace with your database or API call. Return ISO 8601 strings, not Temporal objects.
|
|
93
|
+
return [
|
|
94
|
+
{
|
|
95
|
+
id: "standup",
|
|
96
|
+
title: "Standup",
|
|
97
|
+
color: "blue",
|
|
98
|
+
start: "2026-10-08T07:00:00Z",
|
|
99
|
+
end: "2026-10-08T07:15:00Z",
|
|
100
|
+
},
|
|
101
|
+
];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export default async function CalendarPage() {
|
|
105
|
+
const meetings = await getMeetings();
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<TeamCalendar
|
|
109
|
+
meetings={meetings}
|
|
110
|
+
now={Temporal.Now.instant().toString()}
|
|
111
|
+
timeZone="Europe/Berlin"
|
|
112
|
+
/>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Match the server and the browser
|
|
118
|
+
|
|
119
|
+
During server rendering and hydration, Time doesn't read the clock, the host time zone, or `window`.
|
|
120
|
+
Everything that affects the first render comes from props, so the server and the browser produce the
|
|
121
|
+
same markup as long as they get the same props. In practice:
|
|
122
|
+
|
|
123
|
+
- **Compute "now" once on the server** and pass it down, as `now` above. Calling
|
|
124
|
+
`Temporal.Now.instant()` in a Client Component gives the server and the browser different values.
|
|
125
|
+
Without `now`, anything that depends on the current time (a view's `today`, `useNow()`) is empty
|
|
126
|
+
on the server and fills in after hydration. A fixed `now` also stops the clock, so the
|
|
127
|
+
[App Router example](./nextjs-app-router.md#the-calendar) passes it only while the page
|
|
128
|
+
hydrates.
|
|
129
|
+
- **Choose the time zone on the server**, for example from the user's profile or a cookie. The
|
|
130
|
+
server's own zone is rarely the user's.
|
|
131
|
+
- **Pass the same `locale`** to both. Dates and times are formatted with `Intl`, which depends on it.
|
|
132
|
+
Runtimes also disagree on some spaces: Node.js puts thin spaces around the dash in "Oct 12 – 18"
|
|
133
|
+
where Chrome puts plain ones. The views' titles, times and labels use plain spaces, and so can your
|
|
134
|
+
own formatting, with `withAsciiSpaces(format.formatRange(start, end))`.
|
|
135
|
+
|
|
136
|
+
If you only learn the user's time zone in the browser, render the calendar after hydration, or pass
|
|
137
|
+
the zone as a controlled `timeZone` and update it once you know it.
|
|
138
|
+
|
|
139
|
+
## Element IDs
|
|
140
|
+
|
|
141
|
+
`Root` derives element IDs from React's `useId`, so they match between server and browser. If you
|
|
142
|
+
render several separate React roots on one page, give each a distinct `identifierPrefix` when you
|
|
143
|
+
create it (on both server and client), or pass an explicit `id` to each `Root`.
|
|
144
|
+
|
|
145
|
+
## A complete example
|
|
146
|
+
|
|
147
|
+
[Next.js App Router example](./nextjs-app-router.md) builds a whole route on this page: the
|
|
148
|
+
view and the date in the URL, events fetched by a Server Component, changes saved through Server
|
|
149
|
+
Actions, and the time zone in a cookie.
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# Performance
|
|
2
|
+
|
|
3
|
+
Where Time does its work, and how to keep that work small.
|
|
4
|
+
|
|
5
|
+
Source: https://time.molten.sh/docs/react/guides/performance
|
|
6
|
+
|
|
7
|
+
Time does its work in two steps, and caches each one:
|
|
8
|
+
|
|
9
|
+
1. **Reading events.** `Root` runs your records through the adapter into a snapshot. This happens
|
|
10
|
+
again only when the records change.
|
|
11
|
+
2. **Projecting the view.** `Root` calls the active view's `project` with the snapshot and the
|
|
12
|
+
visible range. This happens again only when the snapshot, range, options, resources,
|
|
13
|
+
environment, or today's date change.
|
|
14
|
+
|
|
15
|
+
Everything else is a normal React render. These habits keep both steps rare and cheap.
|
|
16
|
+
|
|
17
|
+
## Replace records, don't mutate them
|
|
18
|
+
|
|
19
|
+
`Root` compares `events` item by item. A new array with the same record objects in the same order
|
|
20
|
+
counts as unchanged, so you can filter or map inline, as in `events={meetings.filter((meeting) => !meeting.cancelled)}`.
|
|
21
|
+
|
|
22
|
+
When the array changes, Time reads every record through the adapter again, except those with an
|
|
23
|
+
unchanged [revision](#add-a-revision-to-your-adapter); if every record comes out the same, in the
|
|
24
|
+
same order, it keeps its interval indexes. Update records immutably: replace the changed record with
|
|
25
|
+
a new object. A record changed in place keeps its identity, so if nothing else in the array changed,
|
|
26
|
+
the item-by-item comparison sees no change and the calendar doesn't update.
|
|
27
|
+
|
|
28
|
+
## Add a revision to your adapter
|
|
29
|
+
|
|
30
|
+
When you refetch, your data layer usually creates new objects for every record, even unchanged ones.
|
|
31
|
+
`getRevision` lets Time skip those. Return anything that changes whenever the record changes, such as
|
|
32
|
+
an `updatedAt` timestamp or a version number:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
const bookingAdapter = defineEventAdapter<Booking>()({
|
|
36
|
+
getId: (booking) => booking.id,
|
|
37
|
+
getTitle: (booking) => booking.summary,
|
|
38
|
+
getInterval: (booking) => ({ kind: "timed", start: booking.startsAt, end: booking.endsAt }),
|
|
39
|
+
getResourceIds: (booking) => booking.roomIds,
|
|
40
|
+
getRevision: (booking) => booking.updatedAt,
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Records with the same ID and revision as last time reuse their earlier result. The revision must
|
|
45
|
+
change whenever anything the adapter reads changes; otherwise Time keeps showing the old title or
|
|
46
|
+
time.
|
|
47
|
+
|
|
48
|
+
## Do the heavy work in project
|
|
49
|
+
|
|
50
|
+
A view's `project` runs only when its inputs change, while its `Renderer` re-renders like any component. Put filtering, sorting, and layout in `project`, and keep the Renderer to drawing.
|
|
51
|
+
|
|
52
|
+
Inside `project`, ask the snapshot for the visible range instead of looping over every event:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
project: ({ snapshot, instantRange }) => snapshot.queryTimed(instantRange),
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Queries use an interval index, so they don't scan every event. Each snapshot also remembers the
|
|
59
|
+
results of its last 128 distinct queries, so asking again for the same range returns the same
|
|
60
|
+
array.
|
|
61
|
+
|
|
62
|
+
## Keep functions in options stable
|
|
63
|
+
|
|
64
|
+
`Root` compares `locale`, `weekRules`, `now` and a controlled `anchorDate`, `timeZone` or `view` by
|
|
65
|
+
value, and each view's options key by key, so an inline options object is fine. Its values are
|
|
66
|
+
compared by identity, though: a new function or nested object, such as a time grid's `annotations`,
|
|
67
|
+
is a new value.
|
|
68
|
+
|
|
69
|
+
A `getEventColor` written inline in `viewOptions` makes the view project again on
|
|
70
|
+
every render of the component that renders `Root`. Define it once instead:
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
// At module scope, outside the component that renders Root:
|
|
74
|
+
const getEventColor = (meeting: Meeting) => (meeting.title === "Standup" ? "green" : "blue");
|
|
75
|
+
|
|
76
|
+
// Then, on Root:
|
|
77
|
+
viewOptions={{ agenda: { getEventColor } }}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The same goes for a `clock` object. Change handlers and `onDiagnosticsChange` can be inline: `Root`
|
|
81
|
+
reads them when it needs them.
|
|
82
|
+
|
|
83
|
+
## Subscribe to what you use
|
|
84
|
+
|
|
85
|
+
`useCalendarState()` and `useCalendar()` re-render their component whenever any state changes. For a
|
|
86
|
+
component that needs one value, use a selector:
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
function ViewName() {
|
|
90
|
+
const view = Calendar.useCalendarSelector((state) => state.view);
|
|
91
|
+
return <span>{view}</span>;
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The component re-renders only when the selected value changes. If your selector builds a new object
|
|
96
|
+
each time, pass `isEqual` so equal results don't count as changes:
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
const position = Calendar.useCalendarSelector(
|
|
100
|
+
(state) => ({ view: state.view, anchorDate: state.anchorDate }),
|
|
101
|
+
{ isEqual: (a, b) => a.view === b.view && a.anchorDate.equals(b.anchorDate) },
|
|
102
|
+
);
|
|
103
|
+
```
|