@moltenship/calendar-solid 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +41 -2
- package/dist/index.d.mts +265 -0
- package/dist/index.mjs +621 -0
- package/package.json +54 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Timofey Maximov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,42 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @moltenship/calendar-solid
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> **2.0 preview.** This package is new and its API isn't settled. It can change in any release
|
|
4
|
+
> before 2.0. It ships no ready-made views: the registry's views are React. You define a view
|
|
5
|
+
> with `defineCalendarView`, over the projections in `@moltenship/calendar-core`. Keyboard
|
|
6
|
+
> navigation, drafts, history and dragging aren't in it yet.
|
|
7
|
+
|
|
8
|
+
The headless [SolidJS](https://www.solidjs.com) 2 layer of Moltenship Time. It renders the
|
|
9
|
+
calendar primitive from `@moltenship/calendar-primitives` with
|
|
10
|
+
[ui-sdk](https://ui-sdk.dev)'s Solid adapter, the way `@moltenship/calendar-react` does for React,
|
|
11
|
+
so both frameworks share one implementation of the calendar's state, actions and event changes.
|
|
12
|
+
It renders plain, unstyled elements: `createCalendar` gives a `Root`, the structural parts (frame,
|
|
13
|
+
toolbar, title, viewport, view switcher, the previous, next and today triggers, and the active
|
|
14
|
+
view) and read hooks that return accessors. Agents drive the calendar through ui-sdk's bridge,
|
|
15
|
+
which the application creates.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pnpm add @moltenship/calendar-solid @moltenship/calendar-core solid-js @solidjs/web @ui-sdk/core @ui-sdk/solid
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
- `@moltenship/calendar-core` for the event adapter and the views' projections.
|
|
24
|
+
- Solid 2: `solid-js` and `@solidjs/web` are peer dependencies.
|
|
25
|
+
- ui-sdk's `@ui-sdk/core` and `@ui-sdk/solid` 0.1 beta. They are peer dependencies, and still
|
|
26
|
+
pre-1.0, so this package takes the beta the calendar was tested with and the ones after it in
|
|
27
|
+
the same 0.1 line.
|
|
28
|
+
- A runtime with `Temporal` (Node.js 26 and later include it), or a polyfill that defines
|
|
29
|
+
`globalThis.Temporal`, loaded first.
|
|
30
|
+
- TypeScript 6 or later with `"lib": ["DOM", "DOM.Iterable", "ESNext"]`.
|
|
31
|
+
|
|
32
|
+
This package doesn't use React, and `@moltenship/calendar` (the React facade) doesn't re-export
|
|
33
|
+
it.
|
|
34
|
+
|
|
35
|
+
## Documentation
|
|
36
|
+
|
|
37
|
+
- [Solid](https://time.molten.sh/docs/api/solid)
|
|
38
|
+
- [Repository](https://github.com/Moltenship/time)
|
|
39
|
+
|
|
40
|
+
## License
|
|
41
|
+
|
|
42
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { CalendarActions, CalendarActiveView, CalendarActiveView as CalendarActiveView$1, CalendarAgentEvent, CalendarAgentEvent as CalendarAgentEvent$1, CalendarChangeReason, CalendarChangeSource, CalendarCommandOptions, CalendarControlledState, CalendarDiagnostic, CalendarDiagnostic as CalendarDiagnostic$1, CalendarPartIds, CalendarPartIds as CalendarPartIds$1, CalendarPublicState, CalendarPublicState as CalendarPublicState$1, CalendarRootStore, CalendarRootStore as CalendarRootStore$1, CalendarSemanticActions, CalendarSemanticActions as CalendarSemanticActions$1, CalendarStateChangeDetail, CalendarStateChangeHandler, CalendarStateChangeHandler as CalendarStateChangeHandler$1, CalendarStateChangeHandlers, CalendarStateSelector, CalendarStateSelector as CalendarStateSelector$1, CalendarStateSelectorOptions, CalendarStateSelectorOptions as CalendarStateSelectorOptions$1, CalendarStateSlice, CalendarStateSource, CalendarStateSource as CalendarStateSource$1, CalendarStore, CalendarStoreOptions, CalendarViewActions, CalendarViewActions as CalendarViewActions$1, CalendarViewDefinition, CalendarViewOptionsMap, CalendarViewOptionsMap as CalendarViewOptionsMap$1, CalendarVisibleRange, CalendarVisibleRange as CalendarVisibleRange$1, createCalendarStore, resolveViewOptions } from "@moltenship/calendar-primitives";
|
|
2
|
+
import { JSX } from "@solidjs/web";
|
|
3
|
+
import { Accessor, Component } from "solid-js";
|
|
4
|
+
import { CalendarAnnotation, CalendarAnnotationSource, CalendarAvailability, CalendarEnvironment, CalendarEnvironmentBase, CalendarEventChangeHandler, CalendarEventInput, CalendarFocus, CalendarNowSource, CalendarPendingChanges, CalendarPolicy, CalendarProposalDetail, CalendarSecondaryTimeZone, CalendarSelection, CalendarTransactionResult, CalendarViewStrategy, CalendarWeekRules, EventAdapter, EventId, EventSnapshot, InvalidCalendarEventPolicy, ResourceId } from "@moltenship/calendar-core";
|
|
5
|
+
import { PlainDateInterval } from "@moltenship/calendar-temporal";
|
|
6
|
+
/**
|
|
7
|
+
* What `ActiveView` passes the active view's renderer. They are Solid props: getters that read the
|
|
8
|
+
* calendar's current values, so read them where they are used, in JSX or a memo, and don't
|
|
9
|
+
* destructure them.
|
|
10
|
+
*/
|
|
11
|
+
interface CalendarViewRendererProps<TProjection, TOptions> {
|
|
12
|
+
/** Stable for the lifetime of the calendar root. */
|
|
13
|
+
readonly actions: CalendarViewActions$1;
|
|
14
|
+
readonly environment: CalendarEnvironmentBase;
|
|
15
|
+
/** The events the projection was built from, pending changes included. */
|
|
16
|
+
readonly events: EventSnapshot<unknown, EventId, ResourceId>;
|
|
17
|
+
/** The root has no `onEventChange`, so it rejects every change. */
|
|
18
|
+
readonly isReadOnly?: boolean;
|
|
19
|
+
/** The dates the projection covers: `range`, plus what a scrolling view keeps ready. */
|
|
20
|
+
readonly loadRange?: PlainDateInterval;
|
|
21
|
+
readonly options: TOptions;
|
|
22
|
+
readonly projection: TProjection;
|
|
23
|
+
/** The visible dates. */
|
|
24
|
+
readonly range: PlainDateInterval;
|
|
25
|
+
}
|
|
26
|
+
/** A kernel view definition with the Solid component that renders its projection. */
|
|
27
|
+
interface CalendarView<TName extends string = string, TProjection = unknown, TOptions = unknown, TEvent = unknown> extends CalendarViewDefinition<TName, TProjection, TOptions, TEvent> {
|
|
28
|
+
readonly Renderer: Component<CalendarViewRendererProps<TProjection, TOptions>>;
|
|
29
|
+
}
|
|
30
|
+
type AnyCalendarView<TEvent = any> = CalendarView<string, any, any, TEvent>;
|
|
31
|
+
interface CalendarViewInputBase<TName extends string, TProjection, TOptions, TEvent> {
|
|
32
|
+
readonly name: TName;
|
|
33
|
+
readonly Renderer: Component<CalendarViewRendererProps<TProjection, TOptions>>;
|
|
34
|
+
readonly strategy: CalendarViewStrategy<TProjection, TOptions, TEvent>;
|
|
35
|
+
}
|
|
36
|
+
type CalendarViewInput<TName extends string, TProjection, TOptions, TEvent> = CalendarViewInputBase<TName, TProjection, TOptions, TEvent> & (undefined extends TOptions ? {
|
|
37
|
+
readonly defaultOptions?: TOptions;
|
|
38
|
+
} : {
|
|
39
|
+
readonly defaultOptions: TOptions;
|
|
40
|
+
});
|
|
41
|
+
/**
|
|
42
|
+
* Defines a view: a name, the core strategy that ranges, navigates and projects it, and the Solid
|
|
43
|
+
* component that renders the projection. The same shape as `@moltenship/calendar-react`'s, with a
|
|
44
|
+
* Solid `Renderer`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function defineCalendarView<const TName extends string, TProjection, TOptions = undefined, TEvent = unknown>(view: CalendarViewInput<TName, TProjection, TOptions, TEvent>): CalendarView<TName, TProjection, TOptions, TEvent>;
|
|
47
|
+
/** The elements of a root's structural parts, once they are rendered. */
|
|
48
|
+
interface CalendarPartRefs {
|
|
49
|
+
readonly frame: Accessor<HTMLElement | undefined>;
|
|
50
|
+
readonly title: Accessor<HTMLSpanElement | undefined>;
|
|
51
|
+
readonly toolbar: Accessor<HTMLElement | undefined>;
|
|
52
|
+
readonly viewport: Accessor<HTMLDivElement | undefined>;
|
|
53
|
+
}
|
|
54
|
+
interface CalendarMeta<TEvent, TResource, TViewDef extends AnyCalendarView = AnyCalendarView, TEventId extends EventId = EventId, TResourceId extends ResourceId = ResourceId> {
|
|
55
|
+
readonly activeView: TViewDef | undefined;
|
|
56
|
+
readonly diagnostics: readonly CalendarDiagnostic$1<TEvent, TEventId>[];
|
|
57
|
+
readonly environment: CalendarEnvironment;
|
|
58
|
+
/** The events views show, pending changes included. */
|
|
59
|
+
readonly eventSnapshot: EventSnapshot<TEvent, TEventId, TResourceId>;
|
|
60
|
+
readonly ids: CalendarPartIds$1;
|
|
61
|
+
readonly instanceId: string;
|
|
62
|
+
/** `Root`'s `label`, the frame's name. */
|
|
63
|
+
readonly label: string | undefined;
|
|
64
|
+
readonly refs: CalendarPartRefs;
|
|
65
|
+
readonly resources: readonly TResource[];
|
|
66
|
+
readonly views: readonly TViewDef[];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* `useCalendar()`'s value. `meta` and `state` are getters, as Solid props are: read them in a
|
|
70
|
+
* tracking scope (JSX, a memo, an effect's compute) and don't destructure them.
|
|
71
|
+
*/
|
|
72
|
+
interface CalendarContextValue<TEvent, TResource, TViewDef extends AnyCalendarView = AnyCalendarView, TSelection = CalendarSelection, TFocus = CalendarFocus, TEventId extends EventId = EventId, TResourceId extends ResourceId = ResourceId> {
|
|
73
|
+
readonly actions: CalendarSemanticActions$1<TViewDef["name"], TSelection, TFocus, TResourceId, TEvent, TEventId>;
|
|
74
|
+
readonly meta: CalendarMeta<TEvent, TResource, TViewDef, TEventId, TResourceId>;
|
|
75
|
+
readonly state: CalendarPublicState$1<TViewDef["name"], TSelection, TFocus, TResourceId>;
|
|
76
|
+
}
|
|
77
|
+
interface CalendarRootBaseProps<TEvent, TResource, TViewDef extends AnyCalendarView, TSelection, TFocus, TEventId extends EventId, TResourceId extends ResourceId> {
|
|
78
|
+
/**
|
|
79
|
+
* Lets an AI agent delete events through the calendar's `deleteEvent` action. Off by default,
|
|
80
|
+
* since a delete needs a person: turn it on only with an agent bridge whose `allow` asks one
|
|
81
|
+
* for each `deleteEvent` step. While it's off, `deleteEvent` isn't among the agent's actions.
|
|
82
|
+
*/
|
|
83
|
+
readonly allowAgentDelete?: boolean;
|
|
84
|
+
/** The sources views show annotations of, in order. */
|
|
85
|
+
readonly annotationSources?: readonly CalendarAnnotationSource[];
|
|
86
|
+
/** Time-based information shown beside events; invalid ones go to `onDiagnosticsChange`. */
|
|
87
|
+
readonly annotations?: readonly CalendarAnnotation<unknown, TResourceId>[];
|
|
88
|
+
/** The calendar's working hours; invalid rules go to `onDiagnosticsChange`. */
|
|
89
|
+
readonly availability?: CalendarAvailability;
|
|
90
|
+
readonly children?: JSX.Element;
|
|
91
|
+
readonly defaultExpandedResourceIds?: readonly TResourceId[];
|
|
92
|
+
readonly defaultFocus?: TFocus | null;
|
|
93
|
+
readonly defaultSelection?: TSelection | null;
|
|
94
|
+
readonly defaultView?: TViewDef["name"];
|
|
95
|
+
readonly direction?: CalendarEnvironment["direction"];
|
|
96
|
+
readonly disambiguation?: CalendarEnvironment["disambiguation"];
|
|
97
|
+
/**
|
|
98
|
+
* Names each visible event for an AI agent, in the calendar's agent items. By default its title
|
|
99
|
+
* and when it happens in ISO 8601 in the calendar's time zone, as
|
|
100
|
+
* `Design review · 2026-03-14T09:00 to 2026-03-14T10:00 (Europe/Berlin)`, which an agent reads
|
|
101
|
+
* back exactly; a localized date it can't.
|
|
102
|
+
*/
|
|
103
|
+
readonly formatAgentEventLabel?: (event: CalendarAgentEvent$1) => string;
|
|
104
|
+
/**
|
|
105
|
+
* Your events: an array, or a `CalendarEventSource` an external store updates. A source's
|
|
106
|
+
* updates re-derive the calendar without the component that renders `Root`; the server and
|
|
107
|
+
* hydration read its `getServerSnapshot`.
|
|
108
|
+
*/
|
|
109
|
+
readonly events: CalendarEventInput<TEvent>;
|
|
110
|
+
readonly expandedResourceIds?: readonly TResourceId[];
|
|
111
|
+
readonly focus?: TFocus | null;
|
|
112
|
+
/** The instance's id, which the parts' ids start with; one is generated without it. */
|
|
113
|
+
readonly id?: string;
|
|
114
|
+
/**
|
|
115
|
+
* The calendar's name, as `"Team calendar"`. The frame takes it as its `aria-label`, so screen
|
|
116
|
+
* readers and AI agents find the calendar by a name that stays put while navigating; without
|
|
117
|
+
* it, the frame is labelled by the title, which names the visible dates.
|
|
118
|
+
*/
|
|
119
|
+
readonly label?: string;
|
|
120
|
+
readonly locale: Intl.Locale | string;
|
|
121
|
+
readonly onAnchorDateChange?: CalendarStateChangeHandler$1<Temporal.PlainDate, "anchorDate">;
|
|
122
|
+
readonly onDiagnosticsChange?: (diagnostics: readonly CalendarDiagnostic$1<TEvent, TEventId>[]) => void;
|
|
123
|
+
/**
|
|
124
|
+
* Persists an accepted event change. Apply it to `events` synchronously, or return a promise:
|
|
125
|
+
* the change stays visible as pending until it settles and `events` reflect it, and a rejection
|
|
126
|
+
* rolls it back. Without a handler the calendar is read-only. `detail.input` names what proposed
|
|
127
|
+
* the change: `"pointer"`, `"keyboard"`, `"api"`, or `"agent"` for an AI agent's.
|
|
128
|
+
*/
|
|
129
|
+
readonly onEventChange?: CalendarEventChangeHandler<TEvent, TEventId, TResourceId>;
|
|
130
|
+
/** Hears how each proposal ended, once per proposal, after it settles. */
|
|
131
|
+
readonly onEventChangeResult?: (result: CalendarTransactionResult<TEvent, TEventId, TResourceId>, detail: CalendarProposalDetail) => void;
|
|
132
|
+
readonly onExpandedResourceIdsChange?: CalendarStateChangeHandler$1<readonly TResourceId[], "expandedResourceIds">;
|
|
133
|
+
readonly onFocusChange?: CalendarStateChangeHandler$1<TFocus | null, "focus">;
|
|
134
|
+
readonly onSelectionChange?: CalendarStateChangeHandler$1<TSelection | null, "selection">;
|
|
135
|
+
readonly onTimeZoneChange?: CalendarStateChangeHandler$1<string, "timeZone">;
|
|
136
|
+
readonly onViewChange?: CalendarStateChangeHandler$1<TViewDef["name"], "view">;
|
|
137
|
+
/**
|
|
138
|
+
* Called after the active view first shows its dates and whenever they, the view, or the time
|
|
139
|
+
* zone change, but not when only events do; once per change, and never on the server.
|
|
140
|
+
*/
|
|
141
|
+
readonly onVisibleRangeChange?: (range: CalendarVisibleRange$1<TViewDef["name"]>) => void;
|
|
142
|
+
/** Run in order on every proposed change, after the built-in read-only check. */
|
|
143
|
+
readonly policies?: readonly CalendarPolicy<TEvent, TEventId, TResourceId>[];
|
|
144
|
+
readonly resources?: readonly TResource[];
|
|
145
|
+
/** Other time zones time grids label their hours in, beside the display time zone. */
|
|
146
|
+
readonly secondaryTimeZones?: readonly (CalendarSecondaryTimeZone | string)[];
|
|
147
|
+
readonly selection?: TSelection | null;
|
|
148
|
+
readonly store?: CalendarRootStore$1<TViewDef["name"], TSelection, TFocus, TResourceId>;
|
|
149
|
+
readonly view?: TViewDef["name"];
|
|
150
|
+
/** Per-view overrides of each registered view's `defaultOptions`. */
|
|
151
|
+
readonly viewOptions?: CalendarViewOptionsMap$1<TViewDef>;
|
|
152
|
+
readonly weekRules: CalendarWeekRules;
|
|
153
|
+
}
|
|
154
|
+
type CalendarRootAnchorProps = {
|
|
155
|
+
readonly anchorDate: Temporal.PlainDate;
|
|
156
|
+
readonly defaultAnchorDate?: Temporal.PlainDate;
|
|
157
|
+
} | {
|
|
158
|
+
readonly anchorDate?: undefined;
|
|
159
|
+
readonly defaultAnchorDate: Temporal.PlainDate;
|
|
160
|
+
};
|
|
161
|
+
type CalendarRootTimeZoneProps = {
|
|
162
|
+
readonly defaultTimeZone?: string;
|
|
163
|
+
readonly timeZone: string;
|
|
164
|
+
} | {
|
|
165
|
+
readonly defaultTimeZone: string;
|
|
166
|
+
readonly timeZone?: undefined;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* `Root`'s props. Each of the six slices is controlled by its prop (`view`, `anchorDate`, …) or
|
|
170
|
+
* left to the calendar with its `default…` prop, and reports changes through `on…Change`. Pass
|
|
171
|
+
* them as JSX attributes or getters: Solid reads them where they are used, so a signal passed as
|
|
172
|
+
* `view={view()}` stays live.
|
|
173
|
+
*/
|
|
174
|
+
type CalendarRootProps<TEvent, TResource, TViewDef extends AnyCalendarView = AnyCalendarView, TSelection = CalendarSelection, TFocus = CalendarFocus, TEventId extends EventId = EventId, TResourceId extends ResourceId = ResourceId> = CalendarRootBaseProps<TEvent, TResource, TViewDef, TSelection, TFocus, TEventId, TResourceId> & CalendarRootAnchorProps & CalendarRootTimeZoneProps & CalendarNowSource;
|
|
175
|
+
type ElementProps<Tag extends keyof JSX.IntrinsicElements> = JSX.IntrinsicElements[Tag];
|
|
176
|
+
type CalendarFrameProps = Omit<ElementProps<"section">, "id">;
|
|
177
|
+
type CalendarToolbarProps = ElementProps<"header">;
|
|
178
|
+
type CalendarViewportProps = Omit<ElementProps<"div">, "id">;
|
|
179
|
+
type CalendarTitleProps = Omit<ElementProps<"span">, "id">;
|
|
180
|
+
type CalendarAccessibleName = {
|
|
181
|
+
readonly "aria-label": string;
|
|
182
|
+
readonly children?: JSX.Element;
|
|
183
|
+
} | {
|
|
184
|
+
readonly "aria-label"?: string;
|
|
185
|
+
readonly children: JSX.Element;
|
|
186
|
+
};
|
|
187
|
+
type CalendarTriggerProps = Omit<ElementProps<"button">, "children"> & CalendarAccessibleName;
|
|
188
|
+
type CalendarViewSwitcherProps<TView extends string = string> = Omit<ElementProps<"select">, "children" | "value"> & {
|
|
189
|
+
readonly getViewLabel: (view: TView) => string;
|
|
190
|
+
};
|
|
191
|
+
interface CalendarActiveViewProps {
|
|
192
|
+
/** What shows while the active view is unregistered. */
|
|
193
|
+
readonly fallback?: JSX.Element;
|
|
194
|
+
}
|
|
195
|
+
interface CreateCalendarOptions<TEvent, TViewDef extends AnyCalendarView, TEventId extends EventId, TResourceId extends ResourceId> {
|
|
196
|
+
readonly eventAdapter: EventAdapter<TEvent, TEventId, TResourceId>;
|
|
197
|
+
readonly invalidEventPolicy?: InvalidCalendarEventPolicy;
|
|
198
|
+
readonly views?: readonly TViewDef[];
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* A typed calendar's parts and hooks. The hooks return accessors, as Solid's own primitives do:
|
|
202
|
+
* call them in a tracking scope to follow the calendar, or once to read it now.
|
|
203
|
+
*/
|
|
204
|
+
interface CalendarFactory<TEvent, TResource, TViewDef extends AnyCalendarView = AnyCalendarView, TSelection = CalendarSelection, TFocus = CalendarFocus, TEventId extends EventId = EventId, TResourceId extends ResourceId = ResourceId> {
|
|
205
|
+
/** Renders the active view's `Renderer` with its projection. */
|
|
206
|
+
readonly ActiveView: Component<CalendarActiveViewProps>;
|
|
207
|
+
/** A `section`: the calendar's frame, named by `label` or the title, which agents find. */
|
|
208
|
+
readonly Frame: Component<CalendarFrameProps>;
|
|
209
|
+
readonly NextTrigger: Component<CalendarTriggerProps>;
|
|
210
|
+
readonly PreviousTrigger: Component<CalendarTriggerProps>;
|
|
211
|
+
readonly Root: Component<CalendarRootProps<TEvent, TResource, TViewDef, TSelection, TFocus, TEventId, TResourceId>>;
|
|
212
|
+
/** A `span` with the active view's title, unless it has children of its own. */
|
|
213
|
+
readonly Title: Component<CalendarTitleProps>;
|
|
214
|
+
readonly TodayTrigger: Component<CalendarTriggerProps>;
|
|
215
|
+
readonly Toolbar: Component<CalendarToolbarProps>;
|
|
216
|
+
readonly Viewport: Component<CalendarViewportProps>;
|
|
217
|
+
/** A `select` of the registered views. */
|
|
218
|
+
readonly ViewSwitcher: Component<CalendarViewSwitcherProps<TViewDef["name"]>>;
|
|
219
|
+
readonly views: readonly TViewDef[];
|
|
220
|
+
useCalendar(): CalendarContextValue<TEvent, TResource, TViewDef, TSelection, TFocus, TEventId, TResourceId>;
|
|
221
|
+
/** The calendar's commands; the same object for the root's lifetime. */
|
|
222
|
+
useCalendarActions(): CalendarSemanticActions$1<TViewDef["name"], TSelection, TFocus, TResourceId, TEvent, TEventId>;
|
|
223
|
+
useCalendarMeta(): Accessor<CalendarMeta<TEvent, TResource, TViewDef, TEventId, TResourceId>>;
|
|
224
|
+
/**
|
|
225
|
+
* Proposals still validating or saving, and saved changes `events` don't show yet, by change ID
|
|
226
|
+
* in the order they were proposed. With a selector, whatever reads it re-runs only when its
|
|
227
|
+
* result changes, by `isEqual` (`Object.is` by default).
|
|
228
|
+
*/
|
|
229
|
+
useCalendarPendingChanges(): Accessor<CalendarPendingChanges<TEvent, TEventId, TResourceId>>;
|
|
230
|
+
useCalendarPendingChanges<TSelected>(selector: CalendarStateSelector$1<CalendarPendingChanges<TEvent, TEventId, TResourceId>, TSelected>, options?: CalendarStateSelectorOptions$1<TSelected>): Accessor<TSelected>;
|
|
231
|
+
/** A selection of the state; whatever reads it re-runs only when the selection changes. */
|
|
232
|
+
useCalendarSelector<TSelected>(selector: CalendarStateSelector$1<CalendarPublicState$1<TViewDef["name"], TSelection, TFocus, TResourceId>, TSelected>, options?: CalendarStateSelectorOptions$1<TSelected>): Accessor<TSelected>;
|
|
233
|
+
useCalendarState(): Accessor<CalendarPublicState$1<TViewDef["name"], TSelection, TFocus, TResourceId>>;
|
|
234
|
+
/** The active view's projection, discriminated by `view`; `null` when it is unregistered. */
|
|
235
|
+
useViewProjection(): Accessor<CalendarActiveView$1<TViewDef> | null>;
|
|
236
|
+
/** The active view's visible dates; `null` when it is unregistered. */
|
|
237
|
+
useVisibleRange(): Accessor<PlainDateInterval | null>;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Creates a typed calendar, as `@moltenship/calendar-react`'s factory does. The first call fixes
|
|
241
|
+
* the application's record types; the second infers the view-name union and identifier types from
|
|
242
|
+
* `views` and `eventAdapter`. Its root, parts and hooks share a context no other factory reads, so
|
|
243
|
+
* a calendar inside another reads its own.
|
|
244
|
+
*
|
|
245
|
+
* ```ts
|
|
246
|
+
* const Calendar = createCalendar<Meeting>()({ eventAdapter, views: [monthView, listView] });
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
export declare function createCalendar<TEvent, TResource = unknown, TSelection = CalendarSelection, TFocus = CalendarFocus>(): <TViewDef extends AnyCalendarView<TEvent> = never, TEventId extends EventId = EventId, TResourceId extends ResourceId = ResourceId>(options: CreateCalendarOptions<TEvent, TViewDef, TEventId, TResourceId>) => CalendarFactory<TEvent, TResource, TViewDef, TSelection, TFocus, TEventId, TResourceId>;
|
|
250
|
+
/**
|
|
251
|
+
* Reads a selection from an external store as an accessor. Whatever reads it re-runs only when the
|
|
252
|
+
* selection changes by `isEqual`, and a selector that reads props or signals re-selects when they
|
|
253
|
+
* change too. Subscribes for as long as the current owner lives; on the server it reads the
|
|
254
|
+
* snapshot once and never subscribes, and while hydrating it reads the server snapshot until the
|
|
255
|
+
* tree settles, so the first client render matches the server's HTML.
|
|
256
|
+
*
|
|
257
|
+
* `source` may be an accessor of a source, for a store whose identity follows props, as a root's
|
|
258
|
+
* connection does: a new source is subscribed to before it is read, and the old one let go.
|
|
259
|
+
*
|
|
260
|
+
* The accessor follows Solid's scheduling: after the store changes, it reads the new selection once
|
|
261
|
+
* Solid flushes (a microtask, or `flush()`). Code that must see a change at once, like an event
|
|
262
|
+
* handler right after a command, reads `source.getSnapshot()` instead.
|
|
263
|
+
*/
|
|
264
|
+
export declare function createStateSelector<TState, TSelected>(source: CalendarStateSource$1<TState> | Accessor<CalendarStateSource$1<TState>>, selector: CalendarStateSelector$1<TState, TSelected>, { isEqual }?: CalendarStateSelectorOptions$1<TSelected>): Accessor<TSelected>;
|
|
265
|
+
export { type AnyCalendarView, type CalendarActions, type CalendarActiveView, type CalendarActiveViewProps, type CalendarAgentEvent, type CalendarChangeReason, type CalendarChangeSource, type CalendarCommandOptions, type CalendarContextValue, type CalendarControlledState, type CalendarDiagnostic, type CalendarFactory, type CalendarFrameProps, type CalendarMeta, type CalendarPartIds, type CalendarPartRefs, type CalendarPublicState, type CalendarRootProps, type CalendarRootStore, type CalendarSemanticActions, type CalendarStateChangeDetail, type CalendarStateChangeHandler, type CalendarStateChangeHandlers, type CalendarStateSelector, type CalendarStateSelectorOptions, type CalendarStateSlice, type CalendarStateSource, type CalendarStore, type CalendarStoreOptions, type CalendarTitleProps, type CalendarToolbarProps, type CalendarTriggerProps, type CalendarView, type CalendarViewActions, type CalendarViewInput, type CalendarViewOptionsMap, type CalendarViewRendererProps, type CalendarViewSwitcherProps, type CalendarViewportProps, type CalendarVisibleRange, type CreateCalendarOptions, createCalendarStore, resolveViewOptions };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,621 @@
|
|
|
1
|
+
import { TODAY_SAMPLE_INTERVAL_MS, clockOf, createCalendarPartIds, createCalendarPrimitive, createCalendarRuntime, createCalendarStore, createClockTicker, resolveCalendarStoreDefaults, resolveViewOptions, sameRange } from "@moltenship/calendar-primitives";
|
|
2
|
+
import { createComponent, dynamic, isServer } from "@solidjs/web";
|
|
3
|
+
import { usePart, usePrimitive } from "@ui-sdk/solid/primitive";
|
|
4
|
+
import { For, createContext, createEffect, createMemo, createRenderEffect, createSignal, createUniqueId, isHydrating, merge, omit, onCleanup, onSettled, untrack, useContext } from "solid-js";
|
|
5
|
+
// src/flow.ts
|
|
6
|
+
/**
|
|
7
|
+
* Renders one element per item of `each()`, keyed by identity: an item that stays keeps its
|
|
8
|
+
* elements, and `render` gets it as a value and its index as an accessor.
|
|
9
|
+
*/
|
|
10
|
+
function keyedList(each, render, fallback) {
|
|
11
|
+
return createComponent(For, {
|
|
12
|
+
get each() {
|
|
13
|
+
return each();
|
|
14
|
+
},
|
|
15
|
+
get fallback() {
|
|
16
|
+
return fallback?.();
|
|
17
|
+
},
|
|
18
|
+
children: (item, index) => render(item, index)
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
// src/props.ts
|
|
22
|
+
const elements = /* @__PURE__ */ new Map();
|
|
23
|
+
/**
|
|
24
|
+
* A component that renders one native element, for writing parts without JSX. It creates or, while
|
|
25
|
+
* hydrating, claims the element and spreads its props, as compiled JSX does, on the client and the
|
|
26
|
+
* server. One per tag, so repeated renders don't make new factories.
|
|
27
|
+
*/
|
|
28
|
+
function element(tag) {
|
|
29
|
+
let component = elements.get(tag);
|
|
30
|
+
if (component === void 0) {
|
|
31
|
+
component = dynamic(() => tag, { static: true });
|
|
32
|
+
elements.set(tag, component);
|
|
33
|
+
}
|
|
34
|
+
return component;
|
|
35
|
+
}
|
|
36
|
+
// src/parts.ts
|
|
37
|
+
/** Calls an element handler as Solid would: a function, or a bound `[handler, data]` pair. */
|
|
38
|
+
function callHandler(handler, event) {
|
|
39
|
+
if (typeof handler === "function") handler(event);
|
|
40
|
+
else if (Array.isArray(handler) && typeof handler[0] === "function") handler[0](handler[1], event);
|
|
41
|
+
}
|
|
42
|
+
/** Solid's refs are callbacks once compiled, or arrays of them. */
|
|
43
|
+
function applyRef(ref, node) {
|
|
44
|
+
if (typeof ref === "function") ref(node);
|
|
45
|
+
else if (Array.isArray(ref)) for (const each of ref) applyRef(each, node);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The part's element goes to `meta.refs` and to the application's own `ref`. Read once, as Solid
|
|
49
|
+
* reads a `ref`: it binds the element as it is created.
|
|
50
|
+
*/
|
|
51
|
+
function recordRef(record, user) {
|
|
52
|
+
let release;
|
|
53
|
+
if (!isServer) onCleanup(() => release?.());
|
|
54
|
+
return (node) => {
|
|
55
|
+
release?.();
|
|
56
|
+
release = record(node);
|
|
57
|
+
applyRef(user, node);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const asPartProps = (props) => props;
|
|
61
|
+
/** Builds the compound parts that read one factory's root. */
|
|
62
|
+
function createCalendarParts(root) {
|
|
63
|
+
function Frame(props) {
|
|
64
|
+
const { handle, meta, setRef } = root.use();
|
|
65
|
+
const rest = omit(props, "children", "ref");
|
|
66
|
+
const name = {
|
|
67
|
+
get "aria-label"() {
|
|
68
|
+
return meta().label;
|
|
69
|
+
},
|
|
70
|
+
get "aria-labelledby"() {
|
|
71
|
+
return meta().label === void 0 ? meta().ids.title : void 0;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const own = {
|
|
75
|
+
get children() {
|
|
76
|
+
return props.children;
|
|
77
|
+
},
|
|
78
|
+
get "data-calendar-instance"() {
|
|
79
|
+
return meta().instanceId;
|
|
80
|
+
},
|
|
81
|
+
"data-calendar-part": "frame",
|
|
82
|
+
get id() {
|
|
83
|
+
return meta().ids.frame;
|
|
84
|
+
},
|
|
85
|
+
ref: recordRef(setRef.frame, untrack(() => props.ref))
|
|
86
|
+
};
|
|
87
|
+
return usePart(handle, "root", void 0, asPartProps(merge(name, rest, own)), "section");
|
|
88
|
+
}
|
|
89
|
+
function Toolbar(props) {
|
|
90
|
+
const { handle, setRef } = root.use();
|
|
91
|
+
const own = {
|
|
92
|
+
get children() {
|
|
93
|
+
return props.children;
|
|
94
|
+
},
|
|
95
|
+
"data-calendar-part": "toolbar",
|
|
96
|
+
ref: recordRef(setRef.toolbar, untrack(() => props.ref))
|
|
97
|
+
};
|
|
98
|
+
const rest = omit(props, "children", "ref");
|
|
99
|
+
return usePart(handle, "toolbar", void 0, asPartProps(merge(rest, own)), "header");
|
|
100
|
+
}
|
|
101
|
+
function Viewport(props) {
|
|
102
|
+
const { handle, meta, setRef } = root.use();
|
|
103
|
+
const own = {
|
|
104
|
+
get children() {
|
|
105
|
+
return props.children;
|
|
106
|
+
},
|
|
107
|
+
"data-calendar-part": "viewport",
|
|
108
|
+
get id() {
|
|
109
|
+
return meta().ids.viewport;
|
|
110
|
+
},
|
|
111
|
+
ref: recordRef(setRef.viewport, untrack(() => props.ref))
|
|
112
|
+
};
|
|
113
|
+
const rest = omit(props, "children", "ref");
|
|
114
|
+
return usePart(handle, "viewport", void 0, asPartProps(merge(rest, own)), "div");
|
|
115
|
+
}
|
|
116
|
+
function Title(props) {
|
|
117
|
+
const { handle, meta, setRef, view } = root.use();
|
|
118
|
+
const title = createMemo(() => {
|
|
119
|
+
const active = view();
|
|
120
|
+
return active?.definition.strategy.getTitle(active.range, active.environment, active.options) ?? "";
|
|
121
|
+
});
|
|
122
|
+
const own = {
|
|
123
|
+
get children() {
|
|
124
|
+
return props.children ?? title();
|
|
125
|
+
},
|
|
126
|
+
"data-calendar-part": "title",
|
|
127
|
+
get id() {
|
|
128
|
+
return meta().ids.title;
|
|
129
|
+
},
|
|
130
|
+
ref: recordRef(setRef.title, untrack(() => props.ref))
|
|
131
|
+
};
|
|
132
|
+
const rest = omit(props, "children", "ref");
|
|
133
|
+
return usePart(handle, "title", void 0, asPartProps(merge(rest, own)), "span");
|
|
134
|
+
}
|
|
135
|
+
function createTrigger(part, requiresView) {
|
|
136
|
+
return function Trigger(props) {
|
|
137
|
+
const { handle, meta } = root.use();
|
|
138
|
+
const own = {
|
|
139
|
+
get "aria-controls"() {
|
|
140
|
+
return props["aria-controls"] ?? meta().ids.viewport;
|
|
141
|
+
},
|
|
142
|
+
get children() {
|
|
143
|
+
return props.children;
|
|
144
|
+
},
|
|
145
|
+
"data-calendar-part": part,
|
|
146
|
+
get disabled() {
|
|
147
|
+
return props.disabled ?? (requiresView && meta().activeView === void 0);
|
|
148
|
+
},
|
|
149
|
+
get type() {
|
|
150
|
+
return props.type ?? "button";
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
const rest = omit(props, "aria-controls", "children", "disabled", "type");
|
|
154
|
+
return usePart(handle, part, void 0, asPartProps(merge(rest, own)), "button");
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
const PreviousTrigger = createTrigger("previous-trigger", true);
|
|
158
|
+
const NextTrigger = createTrigger("next-trigger", true);
|
|
159
|
+
const TodayTrigger = createTrigger("today-trigger", false);
|
|
160
|
+
const Option = element("option");
|
|
161
|
+
function ViewSwitcher(props) {
|
|
162
|
+
const { handle, meta, state } = root.use();
|
|
163
|
+
const view = createMemo(() => state().view);
|
|
164
|
+
const own = {
|
|
165
|
+
get children() {
|
|
166
|
+
return keyedList(() => meta().views, (definition) => createComponent(Option, {
|
|
167
|
+
get children() {
|
|
168
|
+
return props.getViewLabel(definition.name);
|
|
169
|
+
},
|
|
170
|
+
value: definition.name
|
|
171
|
+
}));
|
|
172
|
+
},
|
|
173
|
+
"data-calendar-part": "view-switcher",
|
|
174
|
+
onChange(event) {
|
|
175
|
+
const select = event.currentTarget;
|
|
176
|
+
let prevented = event.defaultPrevented;
|
|
177
|
+
const preventDefault = event.preventDefault.bind(event);
|
|
178
|
+
Object.defineProperty(event, "preventDefault", {
|
|
179
|
+
configurable: true,
|
|
180
|
+
value() {
|
|
181
|
+
prevented = true;
|
|
182
|
+
preventDefault();
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
callHandler(props.onChange, event);
|
|
186
|
+
if (!prevented) handle.api.selectView(select.value, {
|
|
187
|
+
event,
|
|
188
|
+
reason: "input-change"
|
|
189
|
+
});
|
|
190
|
+
onSettled(() => {
|
|
191
|
+
const shown = untrack(view);
|
|
192
|
+
if (select.value !== shown) select.value = shown;
|
|
193
|
+
});
|
|
194
|
+
},
|
|
195
|
+
get value() {
|
|
196
|
+
return view();
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
const rest = omit(props, "getViewLabel", "onChange");
|
|
200
|
+
return usePart(handle, "view-switcher", void 0, asPartProps(merge(rest, own)), "select");
|
|
201
|
+
}
|
|
202
|
+
function ActiveView(props) {
|
|
203
|
+
const { actions, model, view } = root.use();
|
|
204
|
+
const definition = createMemo(() => view()?.definition);
|
|
205
|
+
function render(own) {
|
|
206
|
+
const active = createMemo((previous) => {
|
|
207
|
+
const next = view();
|
|
208
|
+
return next !== null && next.definition === own ? next : previous;
|
|
209
|
+
});
|
|
210
|
+
return createComponent(own.Renderer, {
|
|
211
|
+
actions,
|
|
212
|
+
get environment() {
|
|
213
|
+
return active().environment;
|
|
214
|
+
},
|
|
215
|
+
get events() {
|
|
216
|
+
return active().events;
|
|
217
|
+
},
|
|
218
|
+
get isReadOnly() {
|
|
219
|
+
return model().isReadOnly;
|
|
220
|
+
},
|
|
221
|
+
get loadRange() {
|
|
222
|
+
return active().loadRange;
|
|
223
|
+
},
|
|
224
|
+
get options() {
|
|
225
|
+
return active().options;
|
|
226
|
+
},
|
|
227
|
+
get projection() {
|
|
228
|
+
return active().projection;
|
|
229
|
+
},
|
|
230
|
+
get range() {
|
|
231
|
+
return active().range;
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
return keyedList(() => {
|
|
236
|
+
const current = definition();
|
|
237
|
+
return current === void 0 ? [] : [current];
|
|
238
|
+
}, render, () => props.fallback);
|
|
239
|
+
}
|
|
240
|
+
return Object.freeze({
|
|
241
|
+
ActiveView,
|
|
242
|
+
Frame,
|
|
243
|
+
NextTrigger,
|
|
244
|
+
PreviousTrigger,
|
|
245
|
+
Title,
|
|
246
|
+
TodayTrigger,
|
|
247
|
+
Toolbar,
|
|
248
|
+
ViewSwitcher,
|
|
249
|
+
Viewport
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
// src/state-selector.ts
|
|
253
|
+
/**
|
|
254
|
+
* Reads a selection from an external store as an accessor. Whatever reads it re-runs only when the
|
|
255
|
+
* selection changes by `isEqual`, and a selector that reads props or signals re-selects when they
|
|
256
|
+
* change too. Subscribes for as long as the current owner lives; on the server it reads the
|
|
257
|
+
* snapshot once and never subscribes, and while hydrating it reads the server snapshot until the
|
|
258
|
+
* tree settles, so the first client render matches the server's HTML.
|
|
259
|
+
*
|
|
260
|
+
* `source` may be an accessor of a source, for a store whose identity follows props, as a root's
|
|
261
|
+
* connection does: a new source is subscribed to before it is read, and the old one let go.
|
|
262
|
+
*
|
|
263
|
+
* The accessor follows Solid's scheduling: after the store changes, it reads the new selection once
|
|
264
|
+
* Solid flushes (a microtask, or `flush()`). Code that must see a change at once, like an event
|
|
265
|
+
* handler right after a command, reads `source.getSnapshot()` instead.
|
|
266
|
+
*/
|
|
267
|
+
function createStateSelector(source, selector, { isEqual = Object.is } = {}) {
|
|
268
|
+
const current = typeof source === "function" ? source : () => source;
|
|
269
|
+
const initial = untrack(current);
|
|
270
|
+
let readServer = isServer || isHydrating() && initial.getServerSnapshot !== void 0;
|
|
271
|
+
const [version, setVersion] = createSignal(0, { ownedWrite: true });
|
|
272
|
+
const notify = () => setVersion((value) => value + 1);
|
|
273
|
+
const subscribed = createMemo(() => {
|
|
274
|
+
const next = current();
|
|
275
|
+
if (!isServer) onCleanup(next.subscribe(() => notify()));
|
|
276
|
+
return next;
|
|
277
|
+
}, { transparent: true });
|
|
278
|
+
const selected = createMemo(() => {
|
|
279
|
+
const store = subscribed();
|
|
280
|
+
version();
|
|
281
|
+
return selector((readServer ? store.getServerSnapshot ?? store.getSnapshot : store.getSnapshot)());
|
|
282
|
+
}, {
|
|
283
|
+
equals: isEqual,
|
|
284
|
+
transparent: true
|
|
285
|
+
});
|
|
286
|
+
if (initial.getServerSnapshot !== void 0) onSettled(() => {
|
|
287
|
+
if (!readServer) return;
|
|
288
|
+
readServer = false;
|
|
289
|
+
notify();
|
|
290
|
+
});
|
|
291
|
+
return selected;
|
|
292
|
+
}
|
|
293
|
+
// src/root.ts
|
|
294
|
+
const same = (value) => value;
|
|
295
|
+
const noop = () => void 0;
|
|
296
|
+
/** What an events array subscribes to: nothing. Its server snapshot is the array itself. */
|
|
297
|
+
const noEventSource = Object.freeze({
|
|
298
|
+
getSnapshot: () => null,
|
|
299
|
+
subscribe: () => noop
|
|
300
|
+
});
|
|
301
|
+
/** What a fixed `now` subscribes to: nothing. */
|
|
302
|
+
const noClock = Object.freeze({
|
|
303
|
+
getSnapshot: () => null,
|
|
304
|
+
subscribe: () => noop
|
|
305
|
+
});
|
|
306
|
+
function isEventSource(input) {
|
|
307
|
+
return !Array.isArray(input);
|
|
308
|
+
}
|
|
309
|
+
function sameMeta(left, right) {
|
|
310
|
+
for (const key of Object.keys(left)) if (!Object.is(left[key], right[key])) return false;
|
|
311
|
+
return true;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Where one structural part's element goes for `meta.refs`. An application may render two copies
|
|
315
|
+
* of a part, so the slot holds the latest one still mounted: a copy that unmounts gives it back
|
|
316
|
+
* to the other instead of emptying it.
|
|
317
|
+
*/
|
|
318
|
+
function createRefSlot() {
|
|
319
|
+
const [read, write] = createSignal(void 0, { ownedWrite: true });
|
|
320
|
+
const mounted = [];
|
|
321
|
+
const record = (element) => {
|
|
322
|
+
mounted.push(element);
|
|
323
|
+
write(() => element);
|
|
324
|
+
return () => {
|
|
325
|
+
const index = mounted.lastIndexOf(element);
|
|
326
|
+
if (index !== -1) mounted.splice(index, 1);
|
|
327
|
+
write(() => mounted.at(-1));
|
|
328
|
+
};
|
|
329
|
+
};
|
|
330
|
+
return [read, record];
|
|
331
|
+
}
|
|
332
|
+
function sameVisibleRange(left, right) {
|
|
333
|
+
return left === right || left !== null && right !== null && sameRange(left, right);
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* The Solid adapter of the calendar kernel. It creates the root's runtime once, derives the model
|
|
337
|
+
* in a memo from the props and what it subscribes to, and runs the runtime's effects at their
|
|
338
|
+
* moments in Solid's queue:
|
|
339
|
+
*
|
|
340
|
+
* - `commit` and `attach` in render effects, which Solid runs before user effects and before any
|
|
341
|
+
* event handler or agent can run a command;
|
|
342
|
+
* - `reconcile` in a render effect too, so new events confirm pending changes before paint;
|
|
343
|
+
* - the diagnostics and visible range in user effects, after the DOM is updated, never on the
|
|
344
|
+
* server.
|
|
345
|
+
*
|
|
346
|
+
* The effects are created on the server as well, with their side effects skipped there, so the
|
|
347
|
+
* server and the client claim the same hydration ids.
|
|
348
|
+
*/
|
|
349
|
+
function createCalendarRoot(config, root) {
|
|
350
|
+
const runtimeConfig = {
|
|
351
|
+
eventAdapter: config.eventAdapter,
|
|
352
|
+
invalidEventPolicy: config.invalidEventPolicy,
|
|
353
|
+
views: config.views
|
|
354
|
+
};
|
|
355
|
+
return function Root(props) {
|
|
356
|
+
const runtime = createCalendarRuntime(runtimeConfig);
|
|
357
|
+
const generatedId = createUniqueId();
|
|
358
|
+
const instanceId = () => props.id ?? generatedId;
|
|
359
|
+
const connection = createMemo(() => runtime.connect({
|
|
360
|
+
controlled: {
|
|
361
|
+
anchorDate: props.anchorDate,
|
|
362
|
+
expandedResourceIds: props.expandedResourceIds,
|
|
363
|
+
focus: props.focus,
|
|
364
|
+
selection: props.selection,
|
|
365
|
+
timeZone: props.timeZone,
|
|
366
|
+
view: props.view
|
|
367
|
+
},
|
|
368
|
+
defaults: () => untrack(() => resolveCalendarStoreDefaults({
|
|
369
|
+
anchorDate: props.anchorDate,
|
|
370
|
+
defaultAnchorDate: props.defaultAnchorDate,
|
|
371
|
+
defaultExpandedResourceIds: props.defaultExpandedResourceIds,
|
|
372
|
+
defaultFocus: props.defaultFocus,
|
|
373
|
+
defaultSelection: props.defaultSelection,
|
|
374
|
+
defaultTimeZone: props.defaultTimeZone,
|
|
375
|
+
defaultView: props.defaultView,
|
|
376
|
+
timeZone: props.timeZone,
|
|
377
|
+
view: props.view
|
|
378
|
+
}, config.views)),
|
|
379
|
+
store: props.store
|
|
380
|
+
}));
|
|
381
|
+
const source = () => connection().source;
|
|
382
|
+
const state = createStateSelector(source, same);
|
|
383
|
+
const overlay = createStateSelector(runtime.overlay, same);
|
|
384
|
+
const sourcedEvents = createStateSelector(() => {
|
|
385
|
+
const input = props.events;
|
|
386
|
+
if (!isEventSource(input)) return noEventSource;
|
|
387
|
+
return {
|
|
388
|
+
getServerSnapshot: () => input.getServerSnapshot(),
|
|
389
|
+
getSnapshot: () => input.getSnapshot(),
|
|
390
|
+
subscribe: (listener) => input.subscribe(listener)
|
|
391
|
+
};
|
|
392
|
+
}, same);
|
|
393
|
+
const events = () => {
|
|
394
|
+
const input = props.events;
|
|
395
|
+
return isEventSource(input) ? sourcedEvents() ?? [] : input;
|
|
396
|
+
};
|
|
397
|
+
const ticker = createMemo(() => createClockTicker(clockOf({ clock: props.clock }), TODAY_SAMPLE_INTERVAL_MS));
|
|
398
|
+
const sampled = createStateSelector(() => {
|
|
399
|
+
if (props.now !== void 0) return noClock;
|
|
400
|
+
const { getSnapshot, subscribe } = ticker();
|
|
401
|
+
return {
|
|
402
|
+
getServerSnapshot: () => null,
|
|
403
|
+
getSnapshot,
|
|
404
|
+
subscribe
|
|
405
|
+
};
|
|
406
|
+
}, same);
|
|
407
|
+
const instant = () => props.now ?? sampled();
|
|
408
|
+
const derived = createMemo(() => {
|
|
409
|
+
const inputs = {
|
|
410
|
+
allowAgentDelete: props.allowAgentDelete,
|
|
411
|
+
annotationSources: props.annotationSources,
|
|
412
|
+
annotations: props.annotations,
|
|
413
|
+
availability: props.availability,
|
|
414
|
+
clock: props.clock,
|
|
415
|
+
connection: connection(),
|
|
416
|
+
direction: props.direction,
|
|
417
|
+
disambiguation: props.disambiguation,
|
|
418
|
+
events: events(),
|
|
419
|
+
handlers: {
|
|
420
|
+
onAnchorDateChange: props.onAnchorDateChange,
|
|
421
|
+
onExpandedResourceIdsChange: props.onExpandedResourceIdsChange,
|
|
422
|
+
onFocusChange: props.onFocusChange,
|
|
423
|
+
onSelectionChange: props.onSelectionChange,
|
|
424
|
+
onTimeZoneChange: props.onTimeZoneChange,
|
|
425
|
+
onViewChange: props.onViewChange
|
|
426
|
+
},
|
|
427
|
+
instant: instant(),
|
|
428
|
+
locale: props.locale,
|
|
429
|
+
now: props.now,
|
|
430
|
+
onDiagnosticsChange: props.onDiagnosticsChange,
|
|
431
|
+
onEventChange: props.onEventChange,
|
|
432
|
+
onEventChangeResult: props.onEventChangeResult,
|
|
433
|
+
onVisibleRangeChange: props.onVisibleRangeChange,
|
|
434
|
+
overlay: overlay(),
|
|
435
|
+
policies: props.policies,
|
|
436
|
+
resources: props.resources,
|
|
437
|
+
secondaryTimeZones: props.secondaryTimeZones,
|
|
438
|
+
state: state(),
|
|
439
|
+
viewOptions: props.viewOptions,
|
|
440
|
+
weekRules: props.weekRules
|
|
441
|
+
};
|
|
442
|
+
return {
|
|
443
|
+
inputs,
|
|
444
|
+
model: untrack(() => runtime.derive(inputs))
|
|
445
|
+
};
|
|
446
|
+
});
|
|
447
|
+
const model = () => derived().model;
|
|
448
|
+
createRenderEffect(derived, ({ inputs, model: next }) => {
|
|
449
|
+
if (!isServer) runtime.commit(next, inputs);
|
|
450
|
+
});
|
|
451
|
+
const binding = createMemo(() => connection().binding);
|
|
452
|
+
const eventSnapshot = createMemo(() => model().eventSnapshot);
|
|
453
|
+
const diagnostics = createMemo(() => model().diagnostics);
|
|
454
|
+
createRenderEffect(binding, (next) => isServer ? void 0 : next.attach());
|
|
455
|
+
createRenderEffect(eventSnapshot, (next) => {
|
|
456
|
+
if (!isServer) runtime.reconcile(next);
|
|
457
|
+
});
|
|
458
|
+
createEffect(diagnostics, (next) => runtime.reportDiagnostics(next));
|
|
459
|
+
createEffect(() => model().visibleRange, (next) => runtime.reportVisibleRange(next));
|
|
460
|
+
const handle = usePrimitive(config.primitive, () => ({
|
|
461
|
+
allowAgentDelete: props.allowAgentDelete,
|
|
462
|
+
formatAgentEventLabel: props.formatAgentEventLabel,
|
|
463
|
+
runtime,
|
|
464
|
+
...state()
|
|
465
|
+
}));
|
|
466
|
+
const [frame, setFrame] = createRefSlot();
|
|
467
|
+
const [title, setTitle] = createRefSlot();
|
|
468
|
+
const [toolbar, setToolbar] = createRefSlot();
|
|
469
|
+
const [viewport, setViewport] = createRefSlot();
|
|
470
|
+
const refs = Object.freeze({
|
|
471
|
+
frame,
|
|
472
|
+
title,
|
|
473
|
+
toolbar,
|
|
474
|
+
viewport
|
|
475
|
+
});
|
|
476
|
+
const ids = createMemo(() => createCalendarPartIds(instanceId()));
|
|
477
|
+
const meta = createMemo(() => {
|
|
478
|
+
const current = model();
|
|
479
|
+
return Object.freeze({
|
|
480
|
+
activeView: current.activeDefinition,
|
|
481
|
+
diagnostics: current.diagnostics,
|
|
482
|
+
environment: current.environment,
|
|
483
|
+
eventSnapshot: current.visibleEvents,
|
|
484
|
+
ids: ids(),
|
|
485
|
+
instanceId: instanceId(),
|
|
486
|
+
label: props.label,
|
|
487
|
+
refs,
|
|
488
|
+
resources: current.resources,
|
|
489
|
+
views: config.views
|
|
490
|
+
});
|
|
491
|
+
}, { equals: sameMeta });
|
|
492
|
+
const view = createMemo(() => model().activeView);
|
|
493
|
+
const visibleDates = createMemo(() => view()?.range ?? null, { equals: sameVisibleRange });
|
|
494
|
+
const first = untrack(model).actions;
|
|
495
|
+
const actions = {};
|
|
496
|
+
for (const key of Object.keys(first)) actions[key] = (...args) => (runtime.committed() ?? untrack(model)).actions[key](...args);
|
|
497
|
+
const value = {
|
|
498
|
+
actions: Object.freeze(actions),
|
|
499
|
+
handle,
|
|
500
|
+
meta,
|
|
501
|
+
model,
|
|
502
|
+
runtime,
|
|
503
|
+
setRef: {
|
|
504
|
+
frame: setFrame,
|
|
505
|
+
title: (element) => setTitle(element),
|
|
506
|
+
toolbar: setToolbar,
|
|
507
|
+
viewport: (element) => setViewport(element)
|
|
508
|
+
},
|
|
509
|
+
source,
|
|
510
|
+
state,
|
|
511
|
+
view,
|
|
512
|
+
visibleRange: visibleDates
|
|
513
|
+
};
|
|
514
|
+
return root.provide(value, () => props.children);
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
// src/root-context.ts
|
|
518
|
+
/**
|
|
519
|
+
* Solid 2.0's own default-less context throws `ContextNotFoundError` outside a provider. A `null`
|
|
520
|
+
* default with our own check throws the error code the React package throws instead, so both
|
|
521
|
+
* adapters fail the same way.
|
|
522
|
+
*/
|
|
523
|
+
function createRootContext(name) {
|
|
524
|
+
const context = createContext(null, { name });
|
|
525
|
+
return Object.freeze({
|
|
526
|
+
context,
|
|
527
|
+
provide: (value, children) => createComponent(context, {
|
|
528
|
+
value,
|
|
529
|
+
get children() {
|
|
530
|
+
return children();
|
|
531
|
+
}
|
|
532
|
+
}),
|
|
533
|
+
use() {
|
|
534
|
+
const value = useContext(context);
|
|
535
|
+
if (value === null) throw new Error("calendar-hook-outside-root");
|
|
536
|
+
return value;
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
// src/calendar.ts
|
|
541
|
+
/** `useCalendarPendingChanges` without a selector: the map itself. */
|
|
542
|
+
const allChanges = (changes) => changes;
|
|
543
|
+
/**
|
|
544
|
+
* Creates a typed calendar, as `@moltenship/calendar-react`'s factory does. The first call fixes
|
|
545
|
+
* the application's record types; the second infers the view-name union and identifier types from
|
|
546
|
+
* `views` and `eventAdapter`. Its root, parts and hooks share a context no other factory reads, so
|
|
547
|
+
* a calendar inside another reads its own.
|
|
548
|
+
*
|
|
549
|
+
* ```ts
|
|
550
|
+
* const Calendar = createCalendar<Meeting>()({ eventAdapter, views: [monthView, listView] });
|
|
551
|
+
* ```
|
|
552
|
+
*/
|
|
553
|
+
function createCalendar() {
|
|
554
|
+
return function createTypedCalendar(options) {
|
|
555
|
+
const views = Object.freeze([...options.views ?? []]);
|
|
556
|
+
const names = /* @__PURE__ */ new Set();
|
|
557
|
+
for (const view of views) {
|
|
558
|
+
if (names.has(view.name)) throw new TypeError(`calendar-duplicate-view-name:${view.name}`);
|
|
559
|
+
names.add(view.name);
|
|
560
|
+
}
|
|
561
|
+
const root = createRootContext("calendar-root");
|
|
562
|
+
const primitive = createCalendarPrimitive({ views });
|
|
563
|
+
const parts = createCalendarParts(root);
|
|
564
|
+
const Root = createCalendarRoot({
|
|
565
|
+
eventAdapter: options.eventAdapter,
|
|
566
|
+
invalidEventPolicy: options.invalidEventPolicy,
|
|
567
|
+
primitive,
|
|
568
|
+
views
|
|
569
|
+
}, root);
|
|
570
|
+
const useCalendarActions = () => root.use().actions;
|
|
571
|
+
const useCalendarMeta = () => root.use().meta;
|
|
572
|
+
const useCalendarState = () => root.use().state;
|
|
573
|
+
function useCalendarPendingChanges(selector, selectorOptions) {
|
|
574
|
+
return createStateSelector(root.use().runtime.pendingChanges, selector ?? allChanges, selectorOptions);
|
|
575
|
+
}
|
|
576
|
+
const factory = {
|
|
577
|
+
...parts,
|
|
578
|
+
Root,
|
|
579
|
+
ViewSwitcher: parts.ViewSwitcher,
|
|
580
|
+
views,
|
|
581
|
+
useCalendar() {
|
|
582
|
+
const { actions, meta, state } = root.use();
|
|
583
|
+
return Object.freeze({
|
|
584
|
+
actions,
|
|
585
|
+
get meta() {
|
|
586
|
+
return meta();
|
|
587
|
+
},
|
|
588
|
+
get state() {
|
|
589
|
+
return state();
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
},
|
|
593
|
+
useCalendarActions,
|
|
594
|
+
useCalendarMeta,
|
|
595
|
+
useCalendarPendingChanges,
|
|
596
|
+
useCalendarSelector(selector, selectorOptions) {
|
|
597
|
+
const { source } = root.use();
|
|
598
|
+
return createStateSelector(source, selector, selectorOptions);
|
|
599
|
+
},
|
|
600
|
+
useCalendarState,
|
|
601
|
+
useViewProjection: () => root.use().view,
|
|
602
|
+
useVisibleRange: () => root.use().visibleRange
|
|
603
|
+
};
|
|
604
|
+
return Object.freeze(factory);
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
// src/views.ts
|
|
608
|
+
/**
|
|
609
|
+
* Defines a view: a name, the core strategy that ranges, navigates and projects it, and the Solid
|
|
610
|
+
* component that renders the projection. The same shape as `@moltenship/calendar-react`'s, with a
|
|
611
|
+
* Solid `Renderer`.
|
|
612
|
+
*/
|
|
613
|
+
function defineCalendarView(view) {
|
|
614
|
+
return Object.freeze({
|
|
615
|
+
defaultOptions: view.defaultOptions,
|
|
616
|
+
name: view.name,
|
|
617
|
+
Renderer: view.Renderer,
|
|
618
|
+
strategy: view.strategy
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
export { createCalendar, createCalendarStore, createStateSelector, defineCalendarView, resolveViewOptions };
|
package/package.json
CHANGED
|
@@ -1,6 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moltenship/calendar-solid",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "2.0.0-beta.1",
|
|
4
|
+
"description": "Headless SolidJS integration for Moltenship Time.",
|
|
5
|
+
"homepage": "https://time.molten.sh/docs/api/solid",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/Moltenship/time/issues"
|
|
8
|
+
},
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/Moltenship/time.git",
|
|
13
|
+
"directory": "packages/calendar-solid"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"type": "module",
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.mts",
|
|
23
|
+
"import": "./dist/index.mjs"
|
|
24
|
+
},
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@moltenship/calendar-core": "2.0.0-beta.1",
|
|
32
|
+
"@moltenship/calendar-primitives": "2.0.0-beta.1",
|
|
33
|
+
"@moltenship/calendar-temporal": "2.0.0-beta.1"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@solidjs/web": "2.0.3",
|
|
37
|
+
"@types/jsdom": "30.0.0",
|
|
38
|
+
"@ui-sdk/core": "0.1.0-beta.16",
|
|
39
|
+
"@ui-sdk/solid": "0.1.0-beta.16",
|
|
40
|
+
"jsdom": "30.1.3",
|
|
41
|
+
"solid-js": "2.0.3",
|
|
42
|
+
"typescript": "^7.0.2",
|
|
43
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@1.4.0",
|
|
44
|
+
"vite-plus": "1.4.0"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@solidjs/web": "^2.0.0",
|
|
48
|
+
"@ui-sdk/core": "^0.1.0-beta.16",
|
|
49
|
+
"@ui-sdk/solid": "^0.1.0-beta.16",
|
|
50
|
+
"solid-js": "^2.0.0"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"build": "vp pack",
|
|
54
|
+
"dev": "vp pack --watch",
|
|
55
|
+
"test": "vp test --passWithNoTests"
|
|
56
|
+
}
|
|
6
57
|
}
|