@moltenship/calendar-solid 0.0.0-stage → 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/dist/index.mjs ADDED
@@ -0,0 +1,1177 @@
1
+ import { closedDates, projectTimeGridAnnotations, projectTimeGridAvailability, projectTimelineAvailability, resourceStatusAt, visibleResources } from "@moltenship/calendar-core";
2
+ import { For, Show, createContext, createEffect, createMemo, createRenderEffect, createSignal, createUniqueId, isHydrating, merge, omit, onCleanup, onSettled, untrack, useContext } from "solid-js";
3
+ import { createComponent, dynamic, isServer } from "@solidjs/web";
4
+ import { TODAY_SAMPLE_INTERVAL_MS, attachCalendarHistoryShortcuts, bindCalendarHistory, calendarFocusKey, calendarViewEntry, clockOf, createAnnouncerLiveText, createBusyResourcesQuery, createCalendarKeyboard, createCalendarPartIds, createCalendarPrimitive, createCalendarRuntime, createCalendarStore, createCalendarViewRuntime, createClockTicker, createDraftBusyQuery, createResourceExpansionCommands, createResourceStatusClock, focusRovingTarget, resolveCalendarStoreDefaults, resolveViewOptions, sameElements, sameRange, subscribeAnchorDateRequests } from "@moltenship/calendar-primitives";
5
+ import { usePart, usePrimitive } from "@ui-sdk/solid/primitive";
6
+ import { attachCalendarPointer, attachCalendarPointer as attachCalendarPointer$1, eventIdAttributes, eventIdOf, monitorCalendarDrags, observeCalendarRegions, resourceIdAttributes, resourceIdOf, startCalendarDrop } from "@moltenship/calendar-dnd";
7
+ export * from "@moltenship/calendar-core";
8
+ export * from "@moltenship/calendar-temporal";
9
+ // src/root-context.ts
10
+ /**
11
+ * Solid 2.0's own default-less context throws `ContextNotFoundError` outside a provider. A `null`
12
+ * default with our own check throws the error code the React package throws instead, so both
13
+ * adapters fail the same way.
14
+ */
15
+ function createRootContext(name, error = "calendar-hook-outside-root") {
16
+ const context = createContext(null, { name });
17
+ return Object.freeze({
18
+ context,
19
+ provide: (value, children) => createComponent(context, {
20
+ value,
21
+ get children() {
22
+ return children();
23
+ }
24
+ }),
25
+ use() {
26
+ const value = useContext(context);
27
+ if (value === null) throw new Error(error);
28
+ return value;
29
+ }
30
+ });
31
+ }
32
+ // src/shared.ts
33
+ const sharedContext = createRootContext("calendar-shared");
34
+ /** The active view's focus plumbing, which `ActiveView` provides to the view it renders. */
35
+ const viewRuntimeContext = createRootContext("calendar-view-runtime", "calendar-view-hook-outside-active-view");
36
+ function useShared() {
37
+ return sharedContext.use();
38
+ }
39
+ /**
40
+ * The root's interaction runtime as it is now. Its stores (`keyboard`, `draft`, `pointerDraft`,
41
+ * `announcements`, `changes`) live as long as the root, so a hook may keep them.
42
+ */
43
+ function useInteractionNow() {
44
+ return untrack(sharedContext.use().interaction);
45
+ }
46
+ /** Reads a `MaybeAccessor`. Only for values that are never functions themselves. */
47
+ function access(value) {
48
+ return typeof value === "function" ? value() : value;
49
+ }
50
+ // src/annotations.ts
51
+ /** The root's annotations and their sources, as an accessor. Works inside any calendar's root. */
52
+ function useCalendarAnnotations() {
53
+ return useShared().annotations;
54
+ }
55
+ /**
56
+ * The root's annotations laid out beside a time grid's columns, one list of marks per column, as
57
+ * an accessor; see `projectTimeGridAnnotations`. Marks carry the root's source objects unchanged.
58
+ */
59
+ function useTimeGridAnnotations(columns, geometry = {}) {
60
+ const { annotations } = useShared();
61
+ return createMemo(() => {
62
+ const { snapshot, sources } = annotations();
63
+ const { layout, maxLanes, minGap, minHeight } = access(geometry);
64
+ return projectTimeGridAnnotations(access(columns), snapshot, sources, {
65
+ layout,
66
+ maxLanes,
67
+ minGap,
68
+ minHeight
69
+ });
70
+ });
71
+ }
72
+ // src/props.ts
73
+ const elements = /* @__PURE__ */ new Map();
74
+ /**
75
+ * A component that renders one native element, for writing parts without JSX. It creates or, while
76
+ * hydrating, claims the element and spreads its props, as compiled JSX does, on the client and the
77
+ * server. One per tag, so repeated renders don't make new factories.
78
+ */
79
+ function element(tag) {
80
+ let component = elements.get(tag);
81
+ if (component === void 0) {
82
+ component = dynamic(() => tag, { static: true });
83
+ elements.set(tag, component);
84
+ }
85
+ return component;
86
+ }
87
+ // src/state-selector.ts
88
+ /**
89
+ * Reads a selection from an external store as an accessor. Whatever reads it re-runs only when the
90
+ * selection changes by `isEqual`, and a selector that reads props or signals re-selects when they
91
+ * change too. Subscribes for as long as the current owner lives; on the server it reads the
92
+ * snapshot once and never subscribes, and while hydrating it reads the server snapshot until the
93
+ * tree settles, so the first client render matches the server's HTML.
94
+ *
95
+ * `source` may be an accessor of a source, for a store whose identity follows props, as a root's
96
+ * connection does: a new source is subscribed to before it is read, and the old one let go.
97
+ *
98
+ * The accessor follows Solid's scheduling: after the store changes, it reads the new selection once
99
+ * Solid flushes (a microtask, or `flush()`). Code that must see a change at once, like an event
100
+ * handler right after a command, reads `source.getSnapshot()` instead.
101
+ */
102
+ function createStateSelector(source, selector, { isEqual = Object.is } = {}) {
103
+ const current = typeof source === "function" ? source : () => source;
104
+ const initial = untrack(current);
105
+ let readServer = isServer || isHydrating() && initial.getServerSnapshot !== void 0;
106
+ const [version, setVersion] = createSignal(0, { ownedWrite: true });
107
+ const notify = () => setVersion((value) => value + 1);
108
+ const subscribed = createMemo(() => {
109
+ const next = current();
110
+ if (!isServer) onCleanup(next.subscribe(() => notify()));
111
+ return next;
112
+ }, { transparent: true });
113
+ const selected = createMemo(() => {
114
+ const store = subscribed();
115
+ version();
116
+ return selector((readServer ? store.getServerSnapshot ?? store.getSnapshot : store.getSnapshot)());
117
+ }, {
118
+ equals: isEqual,
119
+ transparent: true
120
+ });
121
+ if (initial.getServerSnapshot !== void 0) onSettled(() => {
122
+ if (!readServer) return;
123
+ readServer = false;
124
+ notify();
125
+ });
126
+ return selected;
127
+ }
128
+ // src/announcer.ts
129
+ /** Hidden from view but read by screen readers. */
130
+ const visuallyHidden = {
131
+ border: "0",
132
+ "clip-path": "inset(50%)",
133
+ height: "1px",
134
+ margin: "-1px",
135
+ overflow: "hidden",
136
+ padding: "0",
137
+ position: "absolute",
138
+ "white-space": "nowrap",
139
+ width: "1px"
140
+ };
141
+ const visuallyHiddenText = Object.entries(visuallyHidden).map(([name, value]) => `${name}:${String(value)}`).join(";");
142
+ const same$5 = (value) => value;
143
+ const Div = element("div");
144
+ /**
145
+ * A polite live region that speaks keyboard and pointer moves, resizes, and creates in the
146
+ * calendar's locale through `messages`. Render one inside `Root`. `messages` is read when
147
+ * something is said, so a new set takes effect at once.
148
+ */
149
+ function Announcer(props) {
150
+ const { announcements } = useInteractionNow();
151
+ const live = createAnnouncerLiveText();
152
+ const spoken = createStateSelector(live, same$5);
153
+ createRenderEffect(() => announcements, (channel) => isServer ? void 0 : channel.mount(() => untrack(() => props.messages), live.speak));
154
+ return createComponent(Div, merge({
155
+ "aria-atomic": "true",
156
+ "aria-live": "polite",
157
+ role: "status"
158
+ }, omit(props, "messages", "style"), {
159
+ get children() {
160
+ return spoken();
161
+ },
162
+ "data-calendar-part": "announcer",
163
+ get style() {
164
+ const { style } = props;
165
+ if (style === void 0) return visuallyHidden;
166
+ return typeof style === "string" ? `${visuallyHiddenText};${style}` : {
167
+ ...visuallyHidden,
168
+ ...style
169
+ };
170
+ }
171
+ }));
172
+ }
173
+ /**
174
+ * The announcer views pass to the pointer layer (`useCalendarPointer({ announcer })`), so pointer
175
+ * gestures are spoken by the same messages and its preview labels ranges the same way. The same
176
+ * object for the root's lifetime.
177
+ */
178
+ function useCalendarAnnouncer() {
179
+ return useInteractionNow().announcements.announcer;
180
+ }
181
+ // src/availability.ts
182
+ /** The root's working hours, as an accessor: the calendar's, and each resource's on its zone. */
183
+ function useCalendarAvailability() {
184
+ return useShared().availability;
185
+ }
186
+ /**
187
+ * The closed time of each time-grid column, as bands on its 24-hour axis with their reasons: the
188
+ * calendar's, or with `resourceId` that resource's, on its own time zone. See
189
+ * `projectTimeGridAvailability`.
190
+ */
191
+ function useTimeGridAvailability(columns, resourceId) {
192
+ const { availability } = useShared();
193
+ return createMemo(() => projectTimeGridAvailability(access(columns), availability().forResource(access(resourceId) ?? null)));
194
+ }
195
+ /**
196
+ * The closed time along a timeline of `columns`: the calendar's, or with `resourceId` that
197
+ * resource's. See `projectTimelineAvailability`.
198
+ */
199
+ function useTimelineAvailability(columns, resourceId) {
200
+ const { availability } = useShared();
201
+ return createMemo(() => projectTimelineAvailability(access(columns), availability().forResource(access(resourceId) ?? null)));
202
+ }
203
+ /**
204
+ * The dates of `range` with no open time on their day in the display time zone: the calendar's,
205
+ * or with `resourceId` that resource's. See `closedDates`.
206
+ */
207
+ function useClosedDates(range, resourceId) {
208
+ const { availability } = useShared();
209
+ return createMemo(() => {
210
+ const current = availability();
211
+ return closedDates(access(range), current.forResource(access(resourceId) ?? null), current.timeZone);
212
+ });
213
+ }
214
+ // src/flow.ts
215
+ /**
216
+ * Renders one element per item of `each()`, keyed by identity: an item that stays keeps its
217
+ * elements, and `render` gets it as a value and its index as an accessor.
218
+ */
219
+ function keyedList(each, render, fallback) {
220
+ return createComponent(For, {
221
+ get each() {
222
+ return each();
223
+ },
224
+ get fallback() {
225
+ return fallback?.();
226
+ },
227
+ children: (item, index) => render(item, index)
228
+ });
229
+ }
230
+ /**
231
+ * Renders `render` while `condition()` is truthy, and `fallback` otherwise. `render` gets the value
232
+ * as an accessor and stays mounted while it changes from one truthy value to another.
233
+ */
234
+ function when(condition, render, fallback) {
235
+ return createComponent(Show, {
236
+ get when() {
237
+ return condition();
238
+ },
239
+ get fallback() {
240
+ return fallback?.();
241
+ },
242
+ children: (value) => render(value)
243
+ });
244
+ }
245
+ // src/roving-focus.ts
246
+ const selectFocus = (state) => state.focus;
247
+ const nothing = () => null;
248
+ /**
249
+ * Keeps the active view's roving store on the root's focus and the view's entry. A user effect,
250
+ * so it runs once the view's elements of a flush are in the document and registered, and DOM
251
+ * focus can move to one of them, as React's layout effect after the view does.
252
+ */
253
+ function syncRovingFocus(roving, source, view) {
254
+ const focus = createStateSelector(source, selectFocus);
255
+ createEffect(() => ({
256
+ focus: focus(),
257
+ view: view()
258
+ }), (next) => {
259
+ roving.update(next.focus, calendarViewEntry(next.view));
260
+ });
261
+ }
262
+ /**
263
+ * Props for one focusable element of a view: a day cell, a slot, or an event. The view's one tab
264
+ * stop gets `tabindex={0}`; focusing an element makes it the calendar's focus, and keyboard
265
+ * navigation moves DOM focus to the new target, even when it renders in a new place. Only the
266
+ * elements whose tab stop changes update. `target` and `options` may be accessors, as a keyed
267
+ * `For` item's are; the element registers again when its target changes.
268
+ *
269
+ * The element stays registered until the hook's owner is disposed, as Solid never calls a ref
270
+ * with `null`: render it for as long as the component lives, and put `Show` around the component
271
+ * rather than around the element.
272
+ */
273
+ function useRovingFocus(target, options = {}) {
274
+ const { interaction } = useShared();
275
+ const { roving } = viewRuntimeContext.use();
276
+ const targetOf = createMemo(() => access(target), { equals: (left, right) => calendarFocusKey(left) === calendarFocusKey(right) });
277
+ const daysOf = createMemo(() => access(options).days ?? 1);
278
+ const tabStop = createStateSelector({
279
+ getSnapshot: nothing,
280
+ subscribe: roving.subscribe
281
+ }, () => roving.isTabStop(targetOf(), daysOf()));
282
+ const key = createMemo(() => `${calendarFocusKey(targetOf())}#${daysOf()}`);
283
+ let element;
284
+ let release;
285
+ const register = () => {
286
+ release?.();
287
+ release = element === void 0 ? void 0 : roving.register(element, untrack(targetOf), untrack(daysOf));
288
+ };
289
+ createRenderEffect(key, () => {
290
+ if (!isServer && release !== void 0) register();
291
+ });
292
+ onSettled(() => {
293
+ if (release === void 0) register();
294
+ });
295
+ if (!isServer) onCleanup(() => release?.());
296
+ return {
297
+ onFocus(event) {
298
+ if (event.target !== event.currentTarget) return;
299
+ focusRovingTarget(untrack(interaction), untrack(targetOf), untrack(daysOf), event);
300
+ },
301
+ ref(node) {
302
+ element = node;
303
+ if (release !== void 0 || !isHydrating()) register();
304
+ },
305
+ get tabindex() {
306
+ return tabStop() ? 0 : -1;
307
+ }
308
+ };
309
+ }
310
+ // src/parts.ts
311
+ /** Calls an element handler as Solid would: a function, or a bound `[handler, data]` pair. */
312
+ function callHandler(handler, event) {
313
+ if (typeof handler === "function") handler(event);
314
+ else if (Array.isArray(handler) && typeof handler[0] === "function") handler[0](handler[1], event);
315
+ }
316
+ /** Solid's refs are callbacks once compiled, or arrays of them. */
317
+ function applyRef(ref, node) {
318
+ if (typeof ref === "function") ref(node);
319
+ else if (Array.isArray(ref)) for (const each of ref) applyRef(each, node);
320
+ }
321
+ /**
322
+ * The part's element goes to `meta.refs` and to the application's own `ref`. Read once, as Solid
323
+ * reads a `ref`: it binds the element as it is created.
324
+ */
325
+ function recordRef(record, user) {
326
+ let release;
327
+ if (!isServer) onCleanup(() => release?.());
328
+ return (node) => {
329
+ release?.();
330
+ release = record(node);
331
+ applyRef(user, node);
332
+ };
333
+ }
334
+ const asPartProps = (props) => props;
335
+ /** Builds the compound parts that read one factory's root. */
336
+ function createCalendarParts(root) {
337
+ function Frame(props) {
338
+ const { handle, meta, setRef } = root.use();
339
+ const rest = omit(props, "children", "ref");
340
+ const name = {
341
+ get "aria-label"() {
342
+ return meta().label;
343
+ },
344
+ get "aria-labelledby"() {
345
+ return meta().label === void 0 ? meta().ids.title : void 0;
346
+ }
347
+ };
348
+ const own = {
349
+ get children() {
350
+ return props.children;
351
+ },
352
+ get "data-calendar-instance"() {
353
+ return meta().instanceId;
354
+ },
355
+ "data-calendar-part": "frame",
356
+ get id() {
357
+ return meta().ids.frame;
358
+ },
359
+ ref: recordRef(setRef.frame, untrack(() => props.ref))
360
+ };
361
+ return usePart(handle, "root", void 0, asPartProps(merge(name, rest, own)), "section");
362
+ }
363
+ function Toolbar(props) {
364
+ const { handle, setRef } = root.use();
365
+ const own = {
366
+ get children() {
367
+ return props.children;
368
+ },
369
+ "data-calendar-part": "toolbar",
370
+ ref: recordRef(setRef.toolbar, untrack(() => props.ref))
371
+ };
372
+ const rest = omit(props, "children", "ref");
373
+ return usePart(handle, "toolbar", void 0, asPartProps(merge(rest, own)), "header");
374
+ }
375
+ function Viewport(props) {
376
+ const { handle, meta, setRef } = root.use();
377
+ const own = {
378
+ get children() {
379
+ return props.children;
380
+ },
381
+ "data-calendar-part": "viewport",
382
+ get id() {
383
+ return meta().ids.viewport;
384
+ },
385
+ ref: recordRef(setRef.viewport, untrack(() => props.ref))
386
+ };
387
+ const rest = omit(props, "children", "ref");
388
+ return usePart(handle, "viewport", void 0, asPartProps(merge(rest, own)), "div");
389
+ }
390
+ function Title(props) {
391
+ const { handle, meta, setRef, view } = root.use();
392
+ const title = createMemo(() => {
393
+ const active = view();
394
+ return active?.definition.strategy.getTitle(active.range, active.environment, active.options) ?? "";
395
+ });
396
+ const own = {
397
+ get children() {
398
+ return props.children ?? title();
399
+ },
400
+ "data-calendar-part": "title",
401
+ get id() {
402
+ return meta().ids.title;
403
+ },
404
+ ref: recordRef(setRef.title, untrack(() => props.ref))
405
+ };
406
+ const rest = omit(props, "children", "ref");
407
+ return usePart(handle, "title", void 0, asPartProps(merge(rest, own)), "span");
408
+ }
409
+ function createTrigger(part, requiresView) {
410
+ return function Trigger(props) {
411
+ const { handle, meta } = root.use();
412
+ const own = {
413
+ get "aria-controls"() {
414
+ return props["aria-controls"] ?? meta().ids.viewport;
415
+ },
416
+ get children() {
417
+ return props.children;
418
+ },
419
+ "data-calendar-part": part,
420
+ get disabled() {
421
+ return props.disabled ?? (requiresView && meta().activeView === void 0);
422
+ },
423
+ get type() {
424
+ return props.type ?? "button";
425
+ }
426
+ };
427
+ const rest = omit(props, "aria-controls", "children", "disabled", "type");
428
+ return usePart(handle, part, void 0, asPartProps(merge(rest, own)), "button");
429
+ };
430
+ }
431
+ const PreviousTrigger = createTrigger("previous-trigger", true);
432
+ const NextTrigger = createTrigger("next-trigger", true);
433
+ const TodayTrigger = createTrigger("today-trigger", false);
434
+ const Option = element("option");
435
+ function ViewSwitcher(props) {
436
+ const { handle, meta, state } = root.use();
437
+ const view = createMemo(() => state().view);
438
+ const own = {
439
+ get children() {
440
+ return keyedList(() => meta().views, (definition) => createComponent(Option, {
441
+ get children() {
442
+ return props.getViewLabel(definition.name);
443
+ },
444
+ value: definition.name
445
+ }));
446
+ },
447
+ "data-calendar-part": "view-switcher",
448
+ onChange(event) {
449
+ const select = event.currentTarget;
450
+ let prevented = event.defaultPrevented;
451
+ const preventDefault = event.preventDefault.bind(event);
452
+ Object.defineProperty(event, "preventDefault", {
453
+ configurable: true,
454
+ value() {
455
+ prevented = true;
456
+ preventDefault();
457
+ }
458
+ });
459
+ callHandler(props.onChange, event);
460
+ if (!prevented) handle.api.selectView(select.value, {
461
+ event,
462
+ reason: "input-change"
463
+ });
464
+ onSettled(() => {
465
+ const shown = untrack(view);
466
+ if (select.value !== shown) select.value = shown;
467
+ });
468
+ },
469
+ get value() {
470
+ return view();
471
+ }
472
+ };
473
+ const rest = omit(props, "getViewLabel", "onChange");
474
+ return usePart(handle, "view-switcher", void 0, asPartProps(merge(rest, own)), "select");
475
+ }
476
+ function ActiveView(props) {
477
+ const { actions, model, source, view } = root.use();
478
+ const definition = createMemo(() => view()?.definition);
479
+ const runtime = createCalendarViewRuntime(() => untrack(view));
480
+ syncRovingFocus(runtime.roving, source, view);
481
+ function render(own) {
482
+ const active = createMemo((previous) => {
483
+ const next = view();
484
+ return next !== null && next.definition === own ? next : previous;
485
+ });
486
+ return createComponent(own.Renderer, {
487
+ actions,
488
+ get environment() {
489
+ return active().environment;
490
+ },
491
+ get events() {
492
+ return active().events;
493
+ },
494
+ get isReadOnly() {
495
+ return model().isReadOnly;
496
+ },
497
+ get loadRange() {
498
+ return active().loadRange;
499
+ },
500
+ get options() {
501
+ return active().options;
502
+ },
503
+ get projection() {
504
+ return active().projection;
505
+ },
506
+ get range() {
507
+ return active().range;
508
+ }
509
+ });
510
+ }
511
+ return viewRuntimeContext.provide(runtime, () => keyedList(() => {
512
+ const current = definition();
513
+ return current === void 0 ? [] : [current];
514
+ }, render, () => props.fallback));
515
+ }
516
+ function EventPart(props) {
517
+ const { meta } = root.use();
518
+ return when(createMemo(() => {
519
+ const normalized = meta().eventSnapshot.get(props.eventId);
520
+ return normalized === void 0 ? void 0 : {
521
+ event: normalized.event,
522
+ normalized
523
+ };
524
+ }, { equals: (left, right) => left?.normalized === right?.normalized }), (current) => untrack(() => props.children(current)), () => props.fallback);
525
+ }
526
+ return Object.freeze({
527
+ ActiveView,
528
+ EventPart,
529
+ Frame,
530
+ NextTrigger,
531
+ PreviousTrigger,
532
+ Title,
533
+ TodayTrigger,
534
+ Toolbar,
535
+ ViewSwitcher,
536
+ Viewport
537
+ });
538
+ }
539
+ // src/use-now.ts
540
+ const same$4 = (value) => value;
541
+ const noop$2 = () => void 0;
542
+ /** What a fixed `now` subscribes to: nothing. */
543
+ const noClock = Object.freeze({
544
+ getSnapshot: () => null,
545
+ subscribe: () => noop$2
546
+ });
547
+ /**
548
+ * Samples `source` every `intervalMs`: `null` on the server and while hydrating, as the server's
549
+ * time isn't the reader's, unless `source.now` fixes it. The timer runs while something reads it.
550
+ */
551
+ function createNowSampler(source, intervalMs) {
552
+ const clock = createMemo(() => clockOf(source()));
553
+ const ticker = createMemo(() => createClockTicker(clock(), intervalMs()));
554
+ const sampled = createStateSelector(() => {
555
+ if (source()?.now !== void 0) return noClock;
556
+ const { getSnapshot, subscribe } = ticker();
557
+ return {
558
+ getServerSnapshot: () => null,
559
+ getSnapshot,
560
+ subscribe
561
+ };
562
+ }, same$4);
563
+ return () => source()?.now ?? sampled();
564
+ }
565
+ const outsideRoot = () => void 0;
566
+ /**
567
+ * The current instant from the nearest calendar's `now` or `clock`, as an accessor; outside a
568
+ * calendar, the system clock's. It is `null` during server rendering and hydration unless the
569
+ * calendar fixes `now`.
570
+ */
571
+ function useNow(options = {}) {
572
+ return createNowSampler(useContext(sharedContext.context)?.environment ?? outsideRoot, () => access(options).intervalMs ?? 6e4);
573
+ }
574
+ // src/root.ts
575
+ const same$3 = (value) => value;
576
+ const noop$1 = () => void 0;
577
+ /** What an events array subscribes to: nothing. Its server snapshot is the array itself. */
578
+ const noEventSource = Object.freeze({
579
+ getSnapshot: () => null,
580
+ subscribe: () => noop$1
581
+ });
582
+ function isEventSource(input) {
583
+ return !Array.isArray(input);
584
+ }
585
+ function sameMeta(left, right) {
586
+ for (const key of Object.keys(left)) if (!Object.is(left[key], right[key])) return false;
587
+ return true;
588
+ }
589
+ /**
590
+ * Where one structural part's element goes for `meta.refs`. An application may render two copies
591
+ * of a part, so the slot holds the latest one still mounted: a copy that unmounts gives it back
592
+ * to the other instead of emptying it.
593
+ */
594
+ function createRefSlot() {
595
+ const [read, write] = createSignal(void 0, { ownedWrite: true });
596
+ const mounted = [];
597
+ const record = (element) => {
598
+ mounted.push(element);
599
+ write(() => element);
600
+ return () => {
601
+ const index = mounted.lastIndexOf(element);
602
+ if (index !== -1) mounted.splice(index, 1);
603
+ write(() => mounted.at(-1));
604
+ };
605
+ };
606
+ return [read, record];
607
+ }
608
+ function sameVisibleRange(left, right) {
609
+ return left === right || left !== null && right !== null && sameRange(left, right);
610
+ }
611
+ /**
612
+ * The Solid adapter of the calendar kernel. It creates the root's runtime once, derives the model
613
+ * in a memo from the props and what it subscribes to, and runs the runtime's effects at their
614
+ * moments in Solid's queue:
615
+ *
616
+ * - `commit` and `attach` in render effects, which Solid runs before user effects and before any
617
+ * event handler or agent can run a command;
618
+ * - `reconcile` in a render effect too, so new events confirm pending changes before paint;
619
+ * - the diagnostics and visible range in user effects, after the DOM is updated, never on the
620
+ * server.
621
+ *
622
+ * The effects are created on the server as well, with their side effects skipped there, so the
623
+ * server and the client claim the same hydration ids.
624
+ */
625
+ function createCalendarRoot(config, root) {
626
+ const runtimeConfig = {
627
+ eventAdapter: config.eventAdapter,
628
+ invalidEventPolicy: config.invalidEventPolicy,
629
+ views: config.views
630
+ };
631
+ return function Root(props) {
632
+ const runtime = createCalendarRuntime(runtimeConfig);
633
+ const generatedId = createUniqueId();
634
+ const instanceId = () => props.id ?? generatedId;
635
+ const connection = createMemo(() => runtime.connect({
636
+ controlled: {
637
+ anchorDate: props.anchorDate,
638
+ expandedResourceIds: props.expandedResourceIds,
639
+ focus: props.focus,
640
+ selection: props.selection,
641
+ timeZone: props.timeZone,
642
+ view: props.view
643
+ },
644
+ defaults: () => untrack(() => resolveCalendarStoreDefaults({
645
+ anchorDate: props.anchorDate,
646
+ defaultAnchorDate: props.defaultAnchorDate,
647
+ defaultExpandedResourceIds: props.defaultExpandedResourceIds,
648
+ defaultFocus: props.defaultFocus,
649
+ defaultSelection: props.defaultSelection,
650
+ defaultTimeZone: props.defaultTimeZone,
651
+ defaultView: props.defaultView,
652
+ timeZone: props.timeZone,
653
+ view: props.view
654
+ }, config.views)),
655
+ store: props.store
656
+ }));
657
+ const source = () => connection().source;
658
+ const state = createStateSelector(source, same$3);
659
+ const overlay = createStateSelector(runtime.overlay, same$3);
660
+ const sourcedEvents = createStateSelector(() => {
661
+ const input = props.events;
662
+ if (!isEventSource(input)) return noEventSource;
663
+ return {
664
+ getServerSnapshot: () => input.getServerSnapshot(),
665
+ getSnapshot: () => input.getSnapshot(),
666
+ subscribe: (listener) => input.subscribe(listener)
667
+ };
668
+ }, same$3);
669
+ const events = () => {
670
+ const input = props.events;
671
+ return isEventSource(input) ? sourcedEvents() ?? [] : input;
672
+ };
673
+ const instant = createNowSampler(() => ({
674
+ clock: props.clock,
675
+ now: props.now
676
+ }), () => TODAY_SAMPLE_INTERVAL_MS);
677
+ const derived = createMemo(() => {
678
+ const inputs = {
679
+ allowAgentDelete: props.allowAgentDelete,
680
+ annotationSources: props.annotationSources,
681
+ annotations: props.annotations,
682
+ availability: props.availability,
683
+ clock: props.clock,
684
+ connection: connection(),
685
+ direction: props.direction,
686
+ disambiguation: props.disambiguation,
687
+ events: events(),
688
+ handlers: {
689
+ onAnchorDateChange: props.onAnchorDateChange,
690
+ onExpandedResourceIdsChange: props.onExpandedResourceIdsChange,
691
+ onFocusChange: props.onFocusChange,
692
+ onSelectionChange: props.onSelectionChange,
693
+ onTimeZoneChange: props.onTimeZoneChange,
694
+ onViewChange: props.onViewChange
695
+ },
696
+ instant: instant(),
697
+ locale: props.locale,
698
+ now: props.now,
699
+ onDiagnosticsChange: props.onDiagnosticsChange,
700
+ onEventChange: props.onEventChange,
701
+ onEventChangeResult: props.onEventChangeResult,
702
+ onVisibleRangeChange: props.onVisibleRangeChange,
703
+ overlay: overlay(),
704
+ policies: props.policies,
705
+ resources: props.resources,
706
+ secondaryTimeZones: props.secondaryTimeZones,
707
+ state: state(),
708
+ viewOptions: props.viewOptions,
709
+ weekRules: props.weekRules
710
+ };
711
+ return {
712
+ inputs,
713
+ model: untrack(() => runtime.derive(inputs))
714
+ };
715
+ });
716
+ const model = () => derived().model;
717
+ createRenderEffect(derived, ({ inputs, model: next }) => {
718
+ if (!isServer) runtime.commit(next, inputs);
719
+ });
720
+ const binding = createMemo(() => connection().binding);
721
+ const eventSnapshot = createMemo(() => model().eventSnapshot);
722
+ const diagnostics = createMemo(() => model().diagnostics);
723
+ createRenderEffect(binding, (next) => isServer ? void 0 : next.attach());
724
+ createRenderEffect(eventSnapshot, (next) => {
725
+ if (!isServer) runtime.reconcile(next);
726
+ });
727
+ createEffect(diagnostics, (next) => runtime.reportDiagnostics(next));
728
+ createEffect(() => model().visibleRange, (next) => runtime.reportVisibleRange(next));
729
+ const handle = usePrimitive(config.primitive, () => ({
730
+ allowAgentDelete: props.allowAgentDelete,
731
+ formatAgentEventLabel: props.formatAgentEventLabel,
732
+ runtime,
733
+ ...state()
734
+ }));
735
+ const [frame, setFrame] = createRefSlot();
736
+ const [title, setTitle] = createRefSlot();
737
+ const [toolbar, setToolbar] = createRefSlot();
738
+ const [viewport, setViewport] = createRefSlot();
739
+ const refs = Object.freeze({
740
+ frame,
741
+ title,
742
+ toolbar,
743
+ viewport
744
+ });
745
+ const ids = createMemo(() => createCalendarPartIds(instanceId()));
746
+ const meta = createMemo(() => {
747
+ const current = model();
748
+ return Object.freeze({
749
+ activeView: current.activeDefinition,
750
+ diagnostics: current.diagnostics,
751
+ environment: current.environment,
752
+ eventSnapshot: current.visibleEvents,
753
+ ids: ids(),
754
+ instanceId: instanceId(),
755
+ label: props.label,
756
+ refs,
757
+ resources: current.resources,
758
+ views: config.views
759
+ });
760
+ }, { equals: sameMeta });
761
+ const view = createMemo(() => model().activeView);
762
+ const visibleDates = createMemo(() => view()?.range ?? null, { equals: sameVisibleRange });
763
+ const first = untrack(model).actions;
764
+ const actions = {};
765
+ for (const key of Object.keys(first)) actions[key] = (...args) => (runtime.committed() ?? untrack(model)).actions[key](...args);
766
+ const value = {
767
+ actions: Object.freeze(actions),
768
+ handle,
769
+ meta,
770
+ model,
771
+ runtime,
772
+ setRef: {
773
+ frame: setFrame,
774
+ title: (element) => setTitle(element),
775
+ toolbar: setToolbar,
776
+ viewport: (element) => setViewport(element)
777
+ },
778
+ source,
779
+ state,
780
+ view,
781
+ visibleRange: visibleDates
782
+ };
783
+ const shared = {
784
+ annotations: createMemo(() => model().annotations),
785
+ availability: createMemo(() => model().availability),
786
+ environment: createMemo(() => model().environment),
787
+ events: createMemo(() => model().visibleEvents),
788
+ interaction: createMemo(() => model().interaction),
789
+ resources: createMemo(() => model().resourceTree)
790
+ };
791
+ return root.provide(value, () => sharedContext.provide(shared, () => props.children));
792
+ };
793
+ }
794
+ // src/calendar.ts
795
+ /** `useCalendarPendingChanges` without a selector: the map itself. */
796
+ const allChanges = (changes) => changes;
797
+ /**
798
+ * Creates a typed calendar, as `@moltenship/calendar-react`'s factory does. The first call fixes
799
+ * the application's record types; the second infers the view-name union and identifier types from
800
+ * `views` and `eventAdapter`. Its root, parts and hooks share a context no other factory reads, so
801
+ * a calendar inside another reads its own.
802
+ *
803
+ * ```ts
804
+ * const Calendar = createCalendar<Meeting>()({ eventAdapter, views: [monthView, listView] });
805
+ * ```
806
+ */
807
+ function createCalendar() {
808
+ return function createTypedCalendar(options) {
809
+ const views = Object.freeze([...options.views ?? []]);
810
+ const names = /* @__PURE__ */ new Set();
811
+ for (const view of views) {
812
+ if (names.has(view.name)) throw new TypeError(`calendar-duplicate-view-name:${view.name}`);
813
+ names.add(view.name);
814
+ }
815
+ const root = createRootContext("calendar-root");
816
+ const primitive = createCalendarPrimitive({ views });
817
+ const { EventPart, ...parts } = createCalendarParts(root);
818
+ const Root = createCalendarRoot({
819
+ eventAdapter: options.eventAdapter,
820
+ invalidEventPolicy: options.invalidEventPolicy,
821
+ primitive,
822
+ views
823
+ }, root);
824
+ const useCalendarActions = () => root.use().actions;
825
+ const useCalendarMeta = () => root.use().meta;
826
+ const useCalendarState = () => root.use().state;
827
+ function useCalendarPendingChanges(selector, selectorOptions) {
828
+ return createStateSelector(root.use().runtime.pendingChanges, selector ?? allChanges, selectorOptions);
829
+ }
830
+ const factory = {
831
+ ...parts,
832
+ Announcer,
833
+ Event: EventPart,
834
+ Root,
835
+ ViewSwitcher: parts.ViewSwitcher,
836
+ views,
837
+ useCalendar() {
838
+ const { actions, meta, state } = root.use();
839
+ return Object.freeze({
840
+ actions,
841
+ get meta() {
842
+ return meta();
843
+ },
844
+ get state() {
845
+ return state();
846
+ }
847
+ });
848
+ },
849
+ useCalendarActions,
850
+ useCalendarMeta,
851
+ useCalendarPendingChanges,
852
+ useCalendarSelector(selector, selectorOptions) {
853
+ const { source } = root.use();
854
+ return createStateSelector(source, selector, selectorOptions);
855
+ },
856
+ useCalendarState,
857
+ useViewProjection: () => root.use().view,
858
+ useVisibleRange: () => root.use().visibleRange
859
+ };
860
+ return Object.freeze(factory);
861
+ };
862
+ }
863
+ // src/draft.ts
864
+ const same$2 = (value) => value;
865
+ /**
866
+ * The resources busy during `range`, such as a meeting being placed, with their events, as an
867
+ * accessor; free ones are absent. It queries the root's events, pending changes included, once
868
+ * per change of events, range or options. `null` asks nothing.
869
+ */
870
+ function useBusyResources(range, options = {}) {
871
+ const { availability, events } = useShared();
872
+ const query = createBusyResourcesQuery();
873
+ return createMemo(() => {
874
+ const { exclude, resourceIds } = access(options);
875
+ return query(events(), access(range), {
876
+ exclude,
877
+ resourceIds,
878
+ timeZone: availability().timeZone
879
+ });
880
+ });
881
+ }
882
+ /** Reports the pointer's draft to the root, for `onPreview` of `useCalendarPointer`. */
883
+ function useCalendarDraftReporter() {
884
+ return useInteractionNow().pointerDraft.set;
885
+ }
886
+ /**
887
+ * The change being drafted, by pointer or keyboard, as an accessor: the event it changes (`null`
888
+ * when creating) and where it would land; `null` without one, and on the server and while
889
+ * hydrating. It changes once a slot step, so pass its `proposed` to `useBusyResources` for any
890
+ * "who's busy" UI of your own.
891
+ */
892
+ function useCalendarDraft() {
893
+ return createStateSelector(useInteractionNow().draft, same$2);
894
+ }
895
+ /**
896
+ * A resource during the draft's time while one is being made, by pointer or keyboard: the busy
897
+ * events that overlap it (the draft's own event aside; see `isBusy` on the event adapter), and
898
+ * whether the time falls outside its hours. `null` without a draft, or for a `null` resource.
899
+ * Whatever reads it updates only when its own resource's answer changes.
900
+ */
901
+ function useDraftBusy(resourceId) {
902
+ const { availability, events } = useShared();
903
+ const query = createDraftBusyQuery();
904
+ return createStateSelector(useInteractionNow().draft, (draft) => query(draft, events(), availability(), access(resourceId)));
905
+ }
906
+ // src/history.ts
907
+ const same$1 = (value) => value;
908
+ /**
909
+ * Binds an event history to the nearest `Root`, as an accessor: undo and redo propose the inverse
910
+ * through the root's `proposeEventChange`, against the events the user sees, and with `messages`
911
+ * their outcomes are spoken through the root's `Announcer`. The history records through `Root`'s
912
+ * `onEventChangeResult`:
913
+ *
914
+ * ```tsx
915
+ * const history = createEventHistory<Meeting, string, string>();
916
+ * <Calendar.Root onEventChangeResult={history.record} …>
917
+ * <UndoButtons history={history} />
918
+ * </Calendar.Root>
919
+ * // Inside: const bound = useCalendarHistory(history, { messages });
920
+ * // <button disabled={!bound().canUndo} onClick={() => bound().undo()}>Undo</button>
921
+ * ```
922
+ *
923
+ * `messages` is read when a step runs. The server and hydration read an empty history.
924
+ */
925
+ function useCalendarHistory(history, options = {}) {
926
+ const { events, interaction } = useShared();
927
+ const actions = createMemo(() => interaction().actions);
928
+ const announcements = createMemo(() => interaction().announcements);
929
+ const changes = createMemo(() => interaction().changes);
930
+ return createStateSelector(createMemo(() => bindCalendarHistory({
931
+ actions: actions(),
932
+ announcements: announcements(),
933
+ changes: changes()
934
+ }, history, () => untrack(() => ({
935
+ events: events(),
936
+ messages: access(options).messages
937
+ })))), same$1);
938
+ }
939
+ // src/history-shortcuts.ts
940
+ /**
941
+ * Undo and redo keys for a calendar: Mod+Z undoes, and Shift+Mod+Z or Ctrl+Y redoes, where Mod is
942
+ * ⌘ on Apple platforms and Ctrl elsewhere. While the hook's owner lives and it is enabled, one
943
+ * `keydown` listener on the document acts on keys whose target is inside `scope`, after the page's
944
+ * own handlers. Keys never undo in a text field, where the browser undoes the text, or in a
945
+ * dialog, menu or list inside the scope, nor during a keyboard or pointer gesture, nor once
946
+ * something else handled them. Commands pass `{ input: "keyboard" }`.
947
+ *
948
+ * `history` is `useCalendarHistory`'s accessor, or any object with `undo` and `redo`; it, the
949
+ * scope and the keys are read when a key arrives.
950
+ *
951
+ * ```ts
952
+ * const history = useCalendarHistory(eventHistory);
953
+ * const meta = Calendar.useCalendarMeta();
954
+ * useCalendarHistoryShortcuts(history, () => ({ scope: meta().refs.frame }));
955
+ * ```
956
+ */
957
+ function useCalendarHistoryShortcuts(history, options) {
958
+ const { keyboard, pointerDraft } = useInteractionNow();
959
+ const disabled = createMemo(() => access(options).disabled === true);
960
+ createEffect(disabled, (off) => {
961
+ if (off || isServer) return void 0;
962
+ return attachCalendarHistoryShortcuts({
963
+ keyboard,
964
+ pointerDraft
965
+ }, () => untrack(() => {
966
+ const current = access(options);
967
+ return {
968
+ history: access(history),
969
+ redo: current.redo,
970
+ scope: access(current.scope) ?? null,
971
+ undo: current.undo
972
+ };
973
+ }));
974
+ });
975
+ }
976
+ // src/keyboard.ts
977
+ /**
978
+ * Keyboard navigation and keyboard move, resize, and create for a view. Returns a ref for the
979
+ * element around its focusable cells and events (see `useRovingFocus`): `<div ref={keyboard}>`,
980
+ * or `ref={[keyboard, pointer]}` beside `useCalendarPointer`.
981
+ *
982
+ * - Arrow keys, Home, End, Page Up, and Page Down move focus through the view's
983
+ * `getSpatialNavigation`, navigating the view when focus leaves it. Enter moves into a cell's
984
+ * events and Escape back out.
985
+ * - Space grabs the focused event to move it, or the focused cell to create an event there;
986
+ * Shift+Space grabs an event's end to resize it, and again switches to its start. Navigation
987
+ * keys then step the gesture, Enter or Space commits it through `proposeEventChange`, and
988
+ * Escape, Tab, or leaving the view cancels it. On a root without `onEventChange`, Space grabs
989
+ * nothing.
990
+ *
991
+ * The ref listens for `keydown` and `focusout` on the element itself, not through Solid's
992
+ * delegation to the document, so Escape's stopped propagation keeps it from the handlers around
993
+ * the view. A delegated `onKeyDown` inside the view therefore runs after the calendar has taken
994
+ * its key; an element that takes a key for itself listens natively, from a ref, and calls
995
+ * `preventDefault()`, which the calendar respects. `options` is read whenever a key arrives.
996
+ * Every phase is announced through the root's `Announcer`, and a view that unmounts mid-gesture
997
+ * leaves nothing grabbed.
998
+ */
999
+ function useCalendarKeyboard(options = {}) {
1000
+ const { interaction, resources } = useShared();
1001
+ const view = viewRuntimeContext.use();
1002
+ const keyboard = createMemo(() => createCalendarKeyboard(interaction(), view, () => untrack(() => access(options)), () => untrack(resources)));
1003
+ const session = useInteractionNow().keyboard;
1004
+ let detach;
1005
+ if (!isServer) onCleanup(() => {
1006
+ detach?.();
1007
+ session.set(null);
1008
+ });
1009
+ return (element) => {
1010
+ detach?.();
1011
+ const keyDown = (event) => untrack(keyboard).keyDown(event);
1012
+ const focusOut = (event) => untrack(keyboard).focusOut(event, element);
1013
+ element.addEventListener("keydown", keyDown);
1014
+ element.addEventListener("focusout", focusOut);
1015
+ detach = () => {
1016
+ element.removeEventListener("keydown", keyDown);
1017
+ element.removeEventListener("focusout", focusOut);
1018
+ };
1019
+ };
1020
+ }
1021
+ const selectSession = (session) => session;
1022
+ function useCalendarInteraction(selector = selectSession, options) {
1023
+ return createStateSelector(useInteractionNow().keyboard.grabs, (grab) => selector(grab?.session ?? null, grab?.check ?? null), options);
1024
+ }
1025
+ // src/pointer.ts
1026
+ /**
1027
+ * Pointer move, resize, and create for a view region; see `attachCalendarPointer` for the data
1028
+ * attributes the view renders. Returns a ref for the region element: `<div ref={pointer}>`, or
1029
+ * `ref={[keyboard, pointer]}` beside `useCalendarKeyboard`. `options`, an object or an accessor
1030
+ * of one, is read when a gesture starts, and `columns` again as it moves, so changing them never
1031
+ * re-attaches listeners, and dragging never updates Solid. `disabled` is the exception: a
1032
+ * disabled region doesn't listen for touch moves, so a read-only calendar's swipes never wait for
1033
+ * its listener, and changing it attaches the listeners again. Everything is detached with the
1034
+ * owner, a drag in progress included.
1035
+ */
1036
+ function useCalendarPointer(options) {
1037
+ const read = () => untrack(() => access(options));
1038
+ const disabled = createMemo(() => access(options).disabled === true);
1039
+ let element;
1040
+ let attachedDisabled;
1041
+ let detach;
1042
+ const attach = () => {
1043
+ detach?.();
1044
+ attachedDisabled = untrack(disabled);
1045
+ detach = element === void 0 ? void 0 : attachCalendarPointer$1(element, read);
1046
+ };
1047
+ createRenderEffect(disabled, (next) => {
1048
+ if (!isServer && element !== void 0 && next !== attachedDisabled) attach();
1049
+ });
1050
+ if (!isServer) onCleanup(() => {
1051
+ detach?.();
1052
+ detach = void 0;
1053
+ });
1054
+ return (node) => {
1055
+ element = node;
1056
+ attach();
1057
+ };
1058
+ }
1059
+ // src/requests.ts
1060
+ /**
1061
+ * Calls `listener` whenever something asks the calendar for an anchor date: Previous, Next,
1062
+ * Today, keys paging past the view, or `setAnchorDate`, even a date that is already the anchor.
1063
+ * `range` is what the view on screen shows for that date, so a view can tell a request for the
1064
+ * range it has, as Today in this week, from one that moves it. A view whose scroll position can
1065
+ * run ahead of the anchor, as a scrolling view's does while a controlled anchor catches up, uses
1066
+ * it to show its range again when asked. It listens for as long as its owner lives, never on the
1067
+ * server.
1068
+ */
1069
+ function useAnchorDateRequests(listener) {
1070
+ const { interaction } = useShared();
1071
+ createRenderEffect(interaction, ({ rangeOf, requests }) => isServer ? void 0 : subscribeAnchorDateRequests({
1072
+ rangeOf,
1073
+ requests
1074
+ }, listener));
1075
+ }
1076
+ // src/resources.ts
1077
+ const selectExpanded = (state) => state.expandedResourceIds;
1078
+ /**
1079
+ * The root's resources as a view shows them, as an accessor: depth first, with collapsed
1080
+ * resources' descendants left out (see `visibleResources`). It changes when the resources or
1081
+ * their expansion do.
1082
+ */
1083
+ function useVisibleResources(options = {}) {
1084
+ const { interaction, resources } = useShared();
1085
+ const expanded = createStateSelector(() => interaction().source, selectExpanded, { isEqual: sameElements });
1086
+ return createMemo(() => visibleResources(resources(), expanded(), { unassigned: access(options).unassigned }));
1087
+ }
1088
+ /**
1089
+ * One resource's expansion and the commands that change it, through `expandedResourceIds`.
1090
+ * `expanded` updates only when this resource expands or collapses, so a resource header can own
1091
+ * its toggle. `resourceId` may be an accessor; each command acts on the resource it names then.
1092
+ */
1093
+ function useResourceExpansion(resourceId) {
1094
+ const { interaction } = useShared();
1095
+ const expanded = createStateSelector(() => interaction().source, (state) => state.expandedResourceIds.includes(access(resourceId)));
1096
+ const commands = () => untrack(() => createResourceExpansionCommands(interaction(), access(resourceId)));
1097
+ return Object.freeze({
1098
+ collapse: (cause) => commands().collapse(cause),
1099
+ expand: (cause) => commands().expand(cause),
1100
+ expanded,
1101
+ toggle: (cause) => commands().toggle(cause)
1102
+ });
1103
+ }
1104
+ // src/selectors.ts
1105
+ /**
1106
+ * Selects from the calendar's focus for a view's item, such as whether a slot cursor sits on this
1107
+ * column, as an accessor; whatever reads it updates only when its result changes. Works inside
1108
+ * any calendar's root.
1109
+ */
1110
+ function useCalendarFocus(selector, options) {
1111
+ const { interaction } = useShared();
1112
+ return createStateSelector(() => interaction().source, (state) => selector(state.focus), options);
1113
+ }
1114
+ /**
1115
+ * Selects from the calendar's selection, as `useCalendarFocus` does from its focus:
1116
+ * `useCalendarSelection((selection) => selection?.kind === "event" && selection.eventId === id)`.
1117
+ */
1118
+ function useCalendarSelection(selector, options) {
1119
+ const { interaction } = useShared();
1120
+ return createStateSelector(() => interaction().source, (state) => selector(state.selection), options);
1121
+ }
1122
+ // src/status.ts
1123
+ const same = (value) => value;
1124
+ const noop = () => void 0;
1125
+ /** What a resource off the clock reads: nothing, the same shape as a clock's store. */
1126
+ const offClock = Object.freeze({
1127
+ getServerSnapshot: () => null,
1128
+ getSnapshot: () => null,
1129
+ subscribe: () => noop
1130
+ });
1131
+ /**
1132
+ * Whether a resource is within its working hours and whether its events occupy it, `at` an
1133
+ * instant or now on the calendar's clock, as an accessor; see `resourceStatusAt`. Without
1134
+ * `resourceId` it is the calendar's hours and every event. All-day and floating events count on
1135
+ * the display time zone, as the views show them. On the clock it updates only when the status
1136
+ * changes, and is `null` while server rendering and hydrating unless the calendar fixes `now`. A
1137
+ * `null` resource turns it off, such as for the Unassigned column, with nothing computed or
1138
+ * scheduled.
1139
+ */
1140
+ function useResourceStatus(resourceId, at) {
1141
+ const { availability, environment, events } = useShared();
1142
+ const resource = () => access(resourceId);
1143
+ const fixed = () => access(at) ?? environment().now;
1144
+ const off = () => resource() === null;
1145
+ const compute = createMemo(() => {
1146
+ const schedule = availability();
1147
+ const snapshot = events();
1148
+ const options = {
1149
+ resourceId: resource() ?? void 0,
1150
+ timeZone: schedule.timeZone
1151
+ };
1152
+ return (instant) => resourceStatusAt(schedule, snapshot, instant, options);
1153
+ });
1154
+ const onClock = createMemo(() => fixed() === void 0 && !off());
1155
+ const sampled = createStateSelector(createMemo(() => onClock() ? createResourceStatusClock(environment(), compute()) : offClock), same);
1156
+ const pinnedAt = createMemo(() => off() ? void 0 : fixed()?.epochNanoseconds);
1157
+ const pinned = createMemo(() => {
1158
+ const nanoseconds = pinnedAt();
1159
+ return nanoseconds === void 0 ? null : compute()(Temporal.Instant.fromEpochNanoseconds(nanoseconds));
1160
+ });
1161
+ return () => pinned() ?? sampled();
1162
+ }
1163
+ // src/views.ts
1164
+ /**
1165
+ * Defines a view: a name, the core strategy that ranges, navigates and projects it, and the Solid
1166
+ * component that renders the projection. The same shape as `@moltenship/calendar-react`'s, with a
1167
+ * Solid `Renderer`.
1168
+ */
1169
+ function defineCalendarView(view) {
1170
+ return Object.freeze({
1171
+ defaultOptions: view.defaultOptions,
1172
+ name: view.name,
1173
+ Renderer: view.Renderer,
1174
+ strategy: view.strategy
1175
+ });
1176
+ }
1177
+ export { Announcer, attachCalendarPointer, createCalendar, createCalendarStore, createStateSelector, defineCalendarView, eventIdAttributes, eventIdOf, monitorCalendarDrags, observeCalendarRegions, resolveViewOptions, resourceIdAttributes, resourceIdOf, startCalendarDrop, useAnchorDateRequests, useBusyResources, useCalendarAnnotations, useCalendarAnnouncer, useCalendarAvailability, useCalendarDraft, useCalendarDraftReporter, useCalendarFocus, useCalendarHistory, useCalendarHistoryShortcuts, useCalendarInteraction, useCalendarKeyboard, useCalendarPointer, useCalendarSelection, useClosedDates, useDraftBusy, useNow, useResourceExpansion, useResourceStatus, useRovingFocus, useTimeGridAnnotations, useTimeGridAvailability, useTimelineAvailability, useVisibleResources };