@moltenship/calendar-solid 2.0.0-beta.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,26 +1,32 @@
1
1
  # @moltenship/calendar-solid
2
2
 
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.
3
+ > **New in 2.0.** The Solid registry has every ready-made view:
4
+ > `npx shadcn@latest add https://time.molten.sh/r/solid/calendar-full.json` installs them all.
5
+ > For a view of your own, you define one with `defineCalendarView`, over the engine's
6
+ > projections, and bind keyboard navigation, dragging, drafts and undo to it with this package's
7
+ > hooks.
7
8
 
8
9
  The headless [SolidJS](https://www.solidjs.com) 2 layer of Moltenship Time. It renders the
9
10
  calendar primitive from `@moltenship/calendar-primitives` with
10
11
  [ui-sdk](https://ui-sdk.dev)'s Solid adapter, the way `@moltenship/calendar-react` does for React,
11
12
  so both frameworks share one implementation of the calendar's state, actions and event changes.
12
13
  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.
14
+ toolbar, title, viewport, view switcher, the previous, next and today triggers, the active view,
15
+ `Event` and `Announcer`) and hooks that return accessors where React's return values. A view binds
16
+ keyboard navigation with `useCalendarKeyboard` and `useRovingFocus`, pointer dragging, resizing
17
+ and creating with `useCalendarPointer` over `@moltenship/calendar-dnd`, and undo with
18
+ `useCalendarHistory`. Agents drive the calendar through ui-sdk's bridge, which the application
19
+ creates.
16
20
 
17
21
  ## Install
18
22
 
19
23
  ```bash
20
- pnpm add @moltenship/calendar-solid @moltenship/calendar-core solid-js @solidjs/web @ui-sdk/core @ui-sdk/solid
24
+ pnpm add @moltenship/calendar-solid solid-js @solidjs/web @ui-sdk/core @ui-sdk/solid
21
25
  ```
22
26
 
23
- - `@moltenship/calendar-core` for the event adapter and the views' projections.
27
+ - It re-exports `@moltenship/calendar-core` and `@moltenship/calendar-temporal`, as
28
+ `@moltenship/calendar` does for React, so the event adapter, the views' projections and the
29
+ Temporal helpers import from it.
24
30
  - Solid 2: `solid-js` and `@solidjs/web` are peer dependencies.
25
31
  - ui-sdk's `@ui-sdk/core` and `@ui-sdk/solid` 0.1 beta. They are peer dependencies, and still
26
32
  pre-1.0, so this package takes the beta the calendar was tested with and the ones after it in
@@ -34,7 +40,7 @@ it.
34
40
 
35
41
  ## Documentation
36
42
 
37
- - [Solid](https://time.molten.sh/docs/api/solid)
43
+ - [Solid](https://time.molten.sh/docs/solid)
38
44
  - [Repository](https://github.com/Moltenship/time)
39
45
 
40
46
  ## License
package/dist/index.d.mts CHANGED
@@ -1,8 +1,20 @@
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";
1
+ import { AvailabilityBand, AvailabilityExtent, AvailabilitySnapshot, CalendarAnnotation, CalendarAnnotationSource, CalendarAnnouncementMessages, CalendarAnnouncer, CalendarAvailability, CalendarDraft, CalendarEnvironment, CalendarEnvironmentBase, CalendarEventChangeHandler, CalendarEventInput, CalendarEventInterval, CalendarFocus, CalendarInteractionCheck, CalendarKeyboardSession, CalendarNowSource, CalendarPendingChanges, CalendarPolicy, CalendarProposalDetail, CalendarSecondaryTimeZone, CalendarSelection, CalendarTransactionResult, CalendarViewStrategy, CalendarWeekRules, ClosedDate, EventAdapter, EventHistory, EventId, EventSnapshot, InvalidCalendarEventPolicy, NormalizedCalendarEvent, ResourceId, ResourceVisibilityOptions, TimeGridAnnotationGeometry, TimeGridAnnotationMark, TimeGridColumn, VisibleResource } from "@moltenship/calendar-core";
2
+ import { InstantInterval, PlainDateInterval } from "@moltenship/calendar-temporal";
3
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";
4
+ import { JSX } from "@solidjs/web";
5
+ import { CalendarActions, CalendarActiveView, CalendarActiveView as CalendarActiveView$1, CalendarAgentEvent, CalendarAgentEvent as CalendarAgentEvent$1, CalendarAnnotations, CalendarBusyResources, CalendarChangeReason, CalendarChangeSource, CalendarCommandOptions, CalendarCommandOptions as CalendarCommandOptions$1, CalendarControlledState, CalendarDiagnostic, CalendarDiagnostic as CalendarDiagnostic$1, CalendarDraftBusy, CalendarHistory, CalendarHistoryAnnouncementBuilder, CalendarHistoryAnnouncementContext, CalendarHistoryCommandOptions, CalendarHistoryMessages, CalendarHistoryOptions, CalendarHistoryShortcutsTarget, CalendarKeyboardOptions, CalendarPartIds, CalendarPartIds as CalendarPartIds$1, CalendarPublicState, CalendarPublicState as CalendarPublicState$1, CalendarResourceStatus, 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";
6
+ import { CalendarDragFollower, CalendarDragMonitor, CalendarDragPreview, CalendarDropOptions, CalendarDropSession, CalendarDropSource, CalendarEventDrag, CalendarPoint, CalendarPointerOptions, CalendarPointerOptions as CalendarPointerOptions$1, CalendarRect, CalendarRegion, attachCalendarPointer, eventIdAttributes, eventIdOf, monitorCalendarDrags, observeCalendarRegions, resourceIdAttributes, resourceIdOf, startCalendarDrop } from "@moltenship/calendar-dnd";
7
+ export * from "@moltenship/calendar-core";
8
+ export * from "@moltenship/calendar-temporal";
9
+ /** A value, or an accessor of one: what the hooks take wherever an argument may change. */
10
+ type MaybeAccessor<T> = T | Accessor<T>;
11
+ /** The root's annotations and their sources, as an accessor. Works inside any calendar's root. */
12
+ export declare function useCalendarAnnotations(): Accessor<CalendarAnnotations>;
13
+ /**
14
+ * The root's annotations laid out beside a time grid's columns, one list of marks per column, as
15
+ * an accessor; see `projectTimeGridAnnotations`. Marks carry the root's source objects unchanged.
16
+ */
17
+ export declare function useTimeGridAnnotations(columns: MaybeAccessor<readonly TimeGridColumn[]>, geometry?: MaybeAccessor<TimeGridAnnotationGeometry>): Accessor<readonly (readonly TimeGridAnnotationMark[])[]>;
6
18
  /**
7
19
  * What `ActiveView` passes the active view's renderer. They are Solid props: getters that read the
8
20
  * calendar's current values, so read them where they are used, in JSX or a memo, and don't
@@ -188,6 +200,24 @@ type CalendarTriggerProps = Omit<ElementProps<"button">, "children"> & CalendarA
188
200
  type CalendarViewSwitcherProps<TView extends string = string> = Omit<ElementProps<"select">, "children" | "value"> & {
189
201
  readonly getViewLabel: (view: TView) => string;
190
202
  };
203
+ type CalendarAnnouncerProps = Omit<ElementProps<"div">, "children"> & {
204
+ /** What each phase says, in the calendar's language; read each time something is said. */
205
+ readonly messages: CalendarAnnouncementMessages;
206
+ };
207
+ interface CalendarEventRenderValue<TEvent, TEventId extends EventId, TResourceId extends ResourceId> {
208
+ readonly event: TEvent;
209
+ readonly normalized: NormalizedCalendarEvent<TEvent, TEventId, TResourceId>;
210
+ }
211
+ interface CalendarEventProps<TEvent, TEventId extends EventId = EventId, TResourceId extends ResourceId = ResourceId> {
212
+ /**
213
+ * Renders the event as the calendar shows it, pending changes included. It gets an accessor and
214
+ * stays rendered while the event changes, as `Show` does; read it where it is used.
215
+ */
216
+ readonly children: (value: Accessor<CalendarEventRenderValue<TEvent, TEventId, TResourceId>>) => JSX.Element;
217
+ readonly eventId: TEventId;
218
+ /** What shows while the calendar has no such event. */
219
+ readonly fallback?: JSX.Element;
220
+ }
191
221
  interface CalendarActiveViewProps {
192
222
  /** What shows while the active view is unregistered. */
193
223
  readonly fallback?: JSX.Element;
@@ -204,6 +234,13 @@ interface CreateCalendarOptions<TEvent, TViewDef extends AnyCalendarView, TEvent
204
234
  interface CalendarFactory<TEvent, TResource, TViewDef extends AnyCalendarView = AnyCalendarView, TSelection = CalendarSelection, TFocus = CalendarFocus, TEventId extends EventId = EventId, TResourceId extends ResourceId = ResourceId> {
205
235
  /** Renders the active view's `Renderer` with its projection. */
206
236
  readonly ActiveView: Component<CalendarActiveViewProps>;
237
+ /**
238
+ * A polite live region that speaks keyboard and pointer moves, resizes, and creates through
239
+ * `messages`. Render one inside `Root`.
240
+ */
241
+ readonly Announcer: Component<CalendarAnnouncerProps>;
242
+ /** Renders one event by its ID as the calendar shows it, or `fallback` without it. */
243
+ readonly Event: Component<CalendarEventProps<TEvent, TEventId, TResourceId>>;
207
244
  /** A `section`: the calendar's frame, named by `label` or the title, which agents find. */
208
245
  readonly Frame: Component<CalendarFrameProps>;
209
246
  readonly NextTrigger: Component<CalendarTriggerProps>;
@@ -236,6 +273,36 @@ interface CalendarFactory<TEvent, TResource, TViewDef extends AnyCalendarView =
236
273
  /** The active view's visible dates; `null` when it is unregistered. */
237
274
  useVisibleRange(): Accessor<PlainDateInterval | null>;
238
275
  }
276
+ /**
277
+ * A polite live region that speaks keyboard and pointer moves, resizes, and creates in the
278
+ * calendar's locale through `messages`. Render one inside `Root`. `messages` is read when
279
+ * something is said, so a new set takes effect at once.
280
+ */
281
+ export declare function Announcer(props: CalendarAnnouncerProps): JSX.Element;
282
+ /**
283
+ * The announcer views pass to the pointer layer (`useCalendarPointer({ announcer })`), so pointer
284
+ * gestures are spoken by the same messages and its preview labels ranges the same way. The same
285
+ * object for the root's lifetime.
286
+ */
287
+ export declare function useCalendarAnnouncer(): CalendarAnnouncer;
288
+ /** The root's working hours, as an accessor: the calendar's, and each resource's on its zone. */
289
+ export declare function useCalendarAvailability(): Accessor<AvailabilitySnapshot>;
290
+ /**
291
+ * The closed time of each time-grid column, as bands on its 24-hour axis with their reasons: the
292
+ * calendar's, or with `resourceId` that resource's, on its own time zone. See
293
+ * `projectTimeGridAvailability`.
294
+ */
295
+ export declare function useTimeGridAvailability(columns: MaybeAccessor<readonly TimeGridColumn[]>, resourceId?: MaybeAccessor<ResourceId | null | undefined>): Accessor<readonly (readonly AvailabilityBand[])[]>;
296
+ /**
297
+ * The closed time along a timeline of `columns`: the calendar's, or with `resourceId` that
298
+ * resource's. See `projectTimelineAvailability`.
299
+ */
300
+ export declare function useTimelineAvailability(columns: MaybeAccessor<readonly TimeGridColumn[]>, resourceId?: MaybeAccessor<ResourceId | null | undefined>): Accessor<readonly AvailabilityExtent[]>;
301
+ /**
302
+ * The dates of `range` with no open time on their day in the display time zone: the calendar's,
303
+ * or with `resourceId` that resource's. See `closedDates`.
304
+ */
305
+ export declare function useClosedDates(range: MaybeAccessor<PlainDateInterval>, resourceId?: MaybeAccessor<ResourceId | null | undefined>): Accessor<ReadonlyMap<string, ClosedDate>>;
239
306
  /**
240
307
  * Creates a typed calendar, as `@moltenship/calendar-react`'s factory does. The first call fixes
241
308
  * the application's record types; the second infers the view-name union and identifier types from
@@ -247,6 +314,204 @@ interface CalendarFactory<TEvent, TResource, TViewDef extends AnyCalendarView =
247
314
  * ```
248
315
  */
249
316
  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>;
317
+ type AnyDraft = CalendarDraft<EventId, ResourceId>;
318
+ interface CalendarBusyResourcesOptions {
319
+ /** An event to leave out, such as the one being moved. */
320
+ readonly exclude?: EventId | null;
321
+ /** Only these resources; every resource by default. */
322
+ readonly resourceIds?: readonly ResourceId[];
323
+ }
324
+ /**
325
+ * The resources busy during `range`, such as a meeting being placed, with their events, as an
326
+ * accessor; free ones are absent. It queries the root's events, pending changes included, once
327
+ * per change of events, range or options. `null` asks nothing.
328
+ */
329
+ export declare function useBusyResources(range: MaybeAccessor<InstantInterval | CalendarEventInterval | null>, options?: MaybeAccessor<CalendarBusyResourcesOptions>): Accessor<CalendarBusyResources>;
330
+ /** Reports the pointer's draft to the root, for `onPreview` of `useCalendarPointer`. */
331
+ export declare function useCalendarDraftReporter(): (draft: AnyDraft | null) => void;
332
+ /**
333
+ * The change being drafted, by pointer or keyboard, as an accessor: the event it changes (`null`
334
+ * when creating) and where it would land; `null` without one, and on the server and while
335
+ * hydrating. It changes once a slot step, so pass its `proposed` to `useBusyResources` for any
336
+ * "who's busy" UI of your own.
337
+ */
338
+ export declare function useCalendarDraft(): Accessor<AnyDraft | null>;
339
+ /**
340
+ * A resource during the draft's time while one is being made, by pointer or keyboard: the busy
341
+ * events that overlap it (the draft's own event aside; see `isBusy` on the event adapter), and
342
+ * whether the time falls outside its hours. `null` without a draft, or for a `null` resource.
343
+ * Whatever reads it updates only when its own resource's answer changes.
344
+ */
345
+ export declare function useDraftBusy(resourceId: MaybeAccessor<ResourceId | null>): Accessor<CalendarDraftBusy | null>;
346
+ /**
347
+ * Binds an event history to the nearest `Root`, as an accessor: undo and redo propose the inverse
348
+ * through the root's `proposeEventChange`, against the events the user sees, and with `messages`
349
+ * their outcomes are spoken through the root's `Announcer`. The history records through `Root`'s
350
+ * `onEventChangeResult`:
351
+ *
352
+ * ```tsx
353
+ * const history = createEventHistory<Meeting, string, string>();
354
+ * <Calendar.Root onEventChangeResult={history.record} …>
355
+ * <UndoButtons history={history} />
356
+ * </Calendar.Root>
357
+ * // Inside: const bound = useCalendarHistory(history, { messages });
358
+ * // <button disabled={!bound().canUndo} onClick={() => bound().undo()}>Undo</button>
359
+ * ```
360
+ *
361
+ * `messages` is read when a step runs. The server and hydration read an empty history.
362
+ */
363
+ export declare function useCalendarHistory<TEvent, TEventId extends EventId, TResourceId extends ResourceId>(history: EventHistory<TEvent, TEventId, TResourceId>, options?: MaybeAccessor<CalendarHistoryOptions<NoInfer<TEvent>, NoInfer<TEventId>, NoInfer<TResourceId>>>): Accessor<CalendarHistory<TEvent, TEventId, TResourceId>>;
364
+ interface CalendarHistoryShortcutsOptions {
365
+ /** Listens for nothing while `true`. */
366
+ readonly disabled?: boolean;
367
+ /**
368
+ * Keys that redo, such as `"Shift+Mod+Z"`: modifiers joined by `+`, then the key. `Mod` is ⌘
369
+ * on Apple platforms and Ctrl elsewhere. `["Shift+Mod+Z", "Ctrl+Y"]` by default; `[]` turns
370
+ * them off.
371
+ */
372
+ readonly redo?: readonly string[];
373
+ /**
374
+ * The element whose keys undo and redo, usually the root's frame: `meta().refs.frame`, read
375
+ * inside the options' accessor. Keys elsewhere on the page are left alone.
376
+ */
377
+ readonly scope: MaybeAccessor<HTMLElement | null | undefined>;
378
+ /** Keys that undo; `["Mod+Z"]` by default, and `[]` turns them off. */
379
+ readonly undo?: readonly string[];
380
+ }
381
+ /**
382
+ * Undo and redo keys for a calendar: Mod+Z undoes, and Shift+Mod+Z or Ctrl+Y redoes, where Mod is
383
+ * ⌘ on Apple platforms and Ctrl elsewhere. While the hook's owner lives and it is enabled, one
384
+ * `keydown` listener on the document acts on keys whose target is inside `scope`, after the page's
385
+ * own handlers. Keys never undo in a text field, where the browser undoes the text, or in a
386
+ * dialog, menu or list inside the scope, nor during a keyboard or pointer gesture, nor once
387
+ * something else handled them. Commands pass `{ input: "keyboard" }`.
388
+ *
389
+ * `history` is `useCalendarHistory`'s accessor, or any object with `undo` and `redo`; it, the
390
+ * scope and the keys are read when a key arrives.
391
+ *
392
+ * ```ts
393
+ * const history = useCalendarHistory(eventHistory);
394
+ * const meta = Calendar.useCalendarMeta();
395
+ * useCalendarHistoryShortcuts(history, () => ({ scope: meta().refs.frame }));
396
+ * ```
397
+ */
398
+ export declare function useCalendarHistoryShortcuts(history: MaybeAccessor<CalendarHistoryShortcutsTarget>, options: MaybeAccessor<CalendarHistoryShortcutsOptions>): void;
399
+ /**
400
+ * Keyboard navigation and keyboard move, resize, and create for a view. Returns a ref for the
401
+ * element around its focusable cells and events (see `useRovingFocus`): `<div ref={keyboard}>`,
402
+ * or `ref={[keyboard, pointer]}` beside `useCalendarPointer`.
403
+ *
404
+ * - Arrow keys, Home, End, Page Up, and Page Down move focus through the view's
405
+ * `getSpatialNavigation`, navigating the view when focus leaves it. Enter moves into a cell's
406
+ * events and Escape back out.
407
+ * - Space grabs the focused event to move it, or the focused cell to create an event there;
408
+ * Shift+Space grabs an event's end to resize it, and again switches to its start. Navigation
409
+ * keys then step the gesture, Enter or Space commits it through `proposeEventChange`, and
410
+ * Escape, Tab, or leaving the view cancels it. On a root without `onEventChange`, Space grabs
411
+ * nothing.
412
+ *
413
+ * The ref listens for `keydown` and `focusout` on the element itself, not through Solid's
414
+ * delegation to the document, so Escape's stopped propagation keeps it from the handlers around
415
+ * the view. A delegated `onKeyDown` inside the view therefore runs after the calendar has taken
416
+ * its key; an element that takes a key for itself listens natively, from a ref, and calls
417
+ * `preventDefault()`, which the calendar respects. `options` is read whenever a key arrives.
418
+ * Every phase is announced through the root's `Announcer`, and a view that unmounts mid-gesture
419
+ * leaves nothing grabbed.
420
+ */
421
+ export declare function useCalendarKeyboard(options?: MaybeAccessor<CalendarKeyboardOptions>): (element: HTMLElement) => void;
422
+ /**
423
+ * The keyboard gesture in progress, or `null` while idle, as an accessor. Pass a selector to
424
+ * update only when its result changes, such as whether a cell is inside a create's range. The
425
+ * selector also gets what the root's policies say about committing the gesture now, to show an
426
+ * invalid preview.
427
+ */
428
+ export declare function useCalendarInteraction(): Accessor<CalendarKeyboardSession | null>;
429
+ export declare function useCalendarInteraction<TSelected>(selector: (session: CalendarKeyboardSession | null, check: CalendarInteractionCheck) => TSelected, options?: CalendarStateSelectorOptions$1<TSelected>): Accessor<TSelected>;
430
+ /**
431
+ * Pointer move, resize, and create for a view region; see `attachCalendarPointer` for the data
432
+ * attributes the view renders. Returns a ref for the region element: `<div ref={pointer}>`, or
433
+ * `ref={[keyboard, pointer]}` beside `useCalendarKeyboard`. `options`, an object or an accessor
434
+ * of one, is read when a gesture starts, and `columns` again as it moves, so changing them never
435
+ * re-attaches listeners, and dragging never updates Solid. `disabled` is the exception: a
436
+ * disabled region doesn't listen for touch moves, so a read-only calendar's swipes never wait for
437
+ * its listener, and changing it attaches the listeners again. Everything is detached with the
438
+ * owner, a drag in progress included.
439
+ */
440
+ export declare function useCalendarPointer<TEvent, TEventId extends EventId, TResourceId extends ResourceId>(options: MaybeAccessor<CalendarPointerOptions$1<TEvent, TEventId, TResourceId>>): (element: HTMLElement) => void;
441
+ /**
442
+ * Calls `listener` whenever something asks the calendar for an anchor date: Previous, Next,
443
+ * Today, keys paging past the view, or `setAnchorDate`, even a date that is already the anchor.
444
+ * `range` is what the view on screen shows for that date, so a view can tell a request for the
445
+ * range it has, as Today in this week, from one that moves it. A view whose scroll position can
446
+ * run ahead of the anchor, as a scrolling view's does while a controlled anchor catches up, uses
447
+ * it to show its range again when asked. It listens for as long as its owner lives, never on the
448
+ * server.
449
+ */
450
+ export declare function useAnchorDateRequests(listener: (date: Temporal.PlainDate, range: PlainDateInterval | null) => void): void;
451
+ /**
452
+ * What an expansion command passes on to `onExpandedResourceIdsChange`: the DOM event behind it
453
+ * (so `onClick={toggle}` works) or a command's options. Its reason is `"resource-toggle"` unless
454
+ * the options give another.
455
+ */
456
+ type CalendarResourceExpansionCause = CalendarCommandOptions$1 | Event;
457
+ /**
458
+ * An expansion command. It reads a `CalendarResourceExpansionCause` from its argument and ignores
459
+ * any other value, so it fits a callback that passes something else, as a switch's change
460
+ * handler passes a boolean.
461
+ */
462
+ type CalendarResourceExpansionCommand = (cause?: unknown) => void;
463
+ interface CalendarResourceExpansion {
464
+ /** Whether the resource's children show; whatever reads it updates when that changes. */
465
+ readonly expanded: Accessor<boolean>;
466
+ readonly collapse: CalendarResourceExpansionCommand;
467
+ readonly expand: CalendarResourceExpansionCommand;
468
+ readonly toggle: CalendarResourceExpansionCommand;
469
+ }
470
+ /**
471
+ * The root's resources as a view shows them, as an accessor: depth first, with collapsed
472
+ * resources' descendants left out (see `visibleResources`). It changes when the resources or
473
+ * their expansion do.
474
+ */
475
+ export declare function useVisibleResources(options?: MaybeAccessor<ResourceVisibilityOptions>): Accessor<readonly VisibleResource[]>;
476
+ /**
477
+ * One resource's expansion and the commands that change it, through `expandedResourceIds`.
478
+ * `expanded` updates only when this resource expands or collapses, so a resource header can own
479
+ * its toggle. `resourceId` may be an accessor; each command acts on the resource it names then.
480
+ */
481
+ export declare function useResourceExpansion(resourceId: MaybeAccessor<ResourceId>): CalendarResourceExpansion;
482
+ interface CalendarRovingFocusOptions {
483
+ /** Dates an event element shows from `target.date`, such as a month segment's span. */
484
+ readonly days?: number;
485
+ }
486
+ /** Spread on the element, or pass each: `<button {...roving}>`. `tabindex` is a getter. */
487
+ interface CalendarRovingFocusProps {
488
+ readonly onFocus: (event: FocusEvent) => void;
489
+ readonly ref: (element: HTMLElement) => void;
490
+ readonly tabindex: 0 | -1;
491
+ }
492
+ /**
493
+ * Props for one focusable element of a view: a day cell, a slot, or an event. The view's one tab
494
+ * stop gets `tabindex={0}`; focusing an element makes it the calendar's focus, and keyboard
495
+ * navigation moves DOM focus to the new target, even when it renders in a new place. Only the
496
+ * elements whose tab stop changes update. `target` and `options` may be accessors, as a keyed
497
+ * `For` item's are; the element registers again when its target changes.
498
+ *
499
+ * The element stays registered until the hook's owner is disposed, as Solid never calls a ref
500
+ * with `null`: render it for as long as the component lives, and put `Show` around the component
501
+ * rather than around the element.
502
+ */
503
+ export declare function useRovingFocus(target: MaybeAccessor<CalendarFocus>, options?: MaybeAccessor<CalendarRovingFocusOptions>): CalendarRovingFocusProps;
504
+ /**
505
+ * Selects from the calendar's focus for a view's item, such as whether a slot cursor sits on this
506
+ * column, as an accessor; whatever reads it updates only when its result changes. Works inside
507
+ * any calendar's root.
508
+ */
509
+ export declare function useCalendarFocus<TSelected>(selector: (focus: CalendarFocus | null) => TSelected, options?: CalendarStateSelectorOptions$1<TSelected>): Accessor<TSelected>;
510
+ /**
511
+ * Selects from the calendar's selection, as `useCalendarFocus` does from its focus:
512
+ * `useCalendarSelection((selection) => selection?.kind === "event" && selection.eventId === id)`.
513
+ */
514
+ export declare function useCalendarSelection<TSelected>(selector: (selection: CalendarSelection | null) => TSelected, options?: CalendarStateSelectorOptions$1<TSelected>): Accessor<TSelected>;
250
515
  /**
251
516
  * Reads a selection from an external store as an accessor. Whatever reads it re-runs only when the
252
517
  * selection changes by `isEqual`, and a selector that reads props or signals re-selects when they
@@ -262,4 +527,24 @@ export declare function createCalendar<TEvent, TResource = unknown, TSelection =
262
527
  * handler right after a command, reads `source.getSnapshot()` instead.
263
528
  */
264
529
  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 };
530
+ /**
531
+ * Whether a resource is within its working hours and whether its events occupy it, `at` an
532
+ * instant or now on the calendar's clock, as an accessor; see `resourceStatusAt`. Without
533
+ * `resourceId` it is the calendar's hours and every event. All-day and floating events count on
534
+ * the display time zone, as the views show them. On the clock it updates only when the status
535
+ * changes, and is `null` while server rendering and hydrating unless the calendar fixes `now`. A
536
+ * `null` resource turns it off, such as for the Unassigned column, with nothing computed or
537
+ * scheduled.
538
+ */
539
+ export declare function useResourceStatus(resourceId?: MaybeAccessor<ResourceId | null | undefined>, at?: MaybeAccessor<Temporal.Instant | undefined>): Accessor<CalendarResourceStatus | null>;
540
+ interface UseNowOptions {
541
+ /** How often the clock is sampled. Defaults to one minute. */
542
+ readonly intervalMs?: number;
543
+ }
544
+ /**
545
+ * The current instant from the nearest calendar's `now` or `clock`, as an accessor; outside a
546
+ * calendar, the system clock's. It is `null` during server rendering and hydration unless the
547
+ * calendar fixes `now`.
548
+ */
549
+ export declare function useNow(options?: MaybeAccessor<UseNowOptions>): Accessor<Temporal.Instant | null>;
550
+ export { type AnyCalendarView, type CalendarActions, type CalendarActiveView, type CalendarActiveViewProps, type CalendarAgentEvent, type CalendarAnnotations, type CalendarAnnouncerProps, type CalendarBusyResources, type CalendarBusyResourcesOptions, type CalendarChangeReason, type CalendarChangeSource, type CalendarCommandOptions, type CalendarContextValue, type CalendarControlledState, type CalendarDiagnostic, type CalendarDraftBusy, type CalendarDragFollower, type CalendarDragMonitor, type CalendarDragPreview, type CalendarDropOptions, type CalendarDropSession, type CalendarDropSource, type CalendarEventDrag, type CalendarEventProps, type CalendarEventRenderValue, type CalendarFactory, type CalendarFrameProps, type CalendarHistory, type CalendarHistoryAnnouncementBuilder, type CalendarHistoryAnnouncementContext, type CalendarHistoryCommandOptions, type CalendarHistoryMessages, type CalendarHistoryOptions, type CalendarHistoryShortcutsOptions, type CalendarHistoryShortcutsTarget, type CalendarKeyboardOptions, type CalendarMeta, type CalendarPartIds, type CalendarPartRefs, type CalendarPoint, type CalendarPointerOptions, type CalendarPublicState, type CalendarRect, type CalendarRegion, type CalendarResourceExpansion, type CalendarResourceExpansionCause, type CalendarResourceExpansionCommand, type CalendarResourceStatus, type CalendarRootProps, type CalendarRootStore, type CalendarRovingFocusOptions, type CalendarRovingFocusProps, 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, type MaybeAccessor, type UseNowOptions, attachCalendarPointer, createCalendarStore, eventIdAttributes, eventIdOf, monitorCalendarDrags, observeCalendarRegions, resolveViewOptions, resourceIdAttributes, resourceIdOf, startCalendarDrop };
package/dist/index.mjs CHANGED
@@ -1,21 +1,72 @@
1
- import { TODAY_SAMPLE_INTERVAL_MS, clockOf, createCalendarPartIds, createCalendarPrimitive, createCalendarRuntime, createCalendarStore, createClockTicker, resolveCalendarStoreDefaults, resolveViewOptions, sameRange } from "@moltenship/calendar-primitives";
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";
2
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";
3
5
  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
+ 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
6
10
  /**
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.
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.
9
14
  */
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)
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
+ });
19
70
  });
20
71
  }
21
72
  // src/props.ts
@@ -33,6 +84,229 @@ function element(tag) {
33
84
  }
34
85
  return component;
35
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
+ }
36
310
  // src/parts.ts
37
311
  /** Calls an element handler as Solid would: a function, or a bound `[handler, data]` pair. */
38
312
  function callHandler(handler, event) {
@@ -200,8 +474,10 @@ function createCalendarParts(root) {
200
474
  return usePart(handle, "view-switcher", void 0, asPartProps(merge(rest, own)), "select");
201
475
  }
202
476
  function ActiveView(props) {
203
- const { actions, model, view } = root.use();
477
+ const { actions, model, source, view } = root.use();
204
478
  const definition = createMemo(() => view()?.definition);
479
+ const runtime = createCalendarViewRuntime(() => untrack(view));
480
+ syncRovingFocus(runtime.roving, source, view);
205
481
  function render(own) {
206
482
  const active = createMemo((previous) => {
207
483
  const next = view();
@@ -232,13 +508,24 @@ function createCalendarParts(root) {
232
508
  }
233
509
  });
234
510
  }
235
- return keyedList(() => {
511
+ return viewRuntimeContext.provide(runtime, () => keyedList(() => {
236
512
  const current = definition();
237
513
  return current === void 0 ? [] : [current];
238
- }, render, () => props.fallback);
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);
239
525
  }
240
526
  return Object.freeze({
241
527
  ActiveView,
528
+ EventPart,
242
529
  Frame,
243
530
  NextTrigger,
244
531
  PreviousTrigger,
@@ -249,59 +536,48 @@ function createCalendarParts(root) {
249
536
  Viewport
250
537
  });
251
538
  }
252
- // src/state-selector.ts
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
+ });
253
547
  /**
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.
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.
266
550
  */
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;
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);
292
573
  }
293
574
  // src/root.ts
294
- const same = (value) => value;
295
- const noop = () => void 0;
575
+ const same$3 = (value) => value;
576
+ const noop$1 = () => void 0;
296
577
  /** What an events array subscribes to: nothing. Its server snapshot is the array itself. */
297
578
  const noEventSource = Object.freeze({
298
579
  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
580
+ subscribe: () => noop$1
305
581
  });
306
582
  function isEventSource(input) {
307
583
  return !Array.isArray(input);
@@ -379,8 +655,8 @@ function createCalendarRoot(config, root) {
379
655
  store: props.store
380
656
  }));
381
657
  const source = () => connection().source;
382
- const state = createStateSelector(source, same);
383
- const overlay = createStateSelector(runtime.overlay, same);
658
+ const state = createStateSelector(source, same$3);
659
+ const overlay = createStateSelector(runtime.overlay, same$3);
384
660
  const sourcedEvents = createStateSelector(() => {
385
661
  const input = props.events;
386
662
  if (!isEventSource(input)) return noEventSource;
@@ -389,22 +665,15 @@ function createCalendarRoot(config, root) {
389
665
  getSnapshot: () => input.getSnapshot(),
390
666
  subscribe: (listener) => input.subscribe(listener)
391
667
  };
392
- }, same);
668
+ }, same$3);
393
669
  const events = () => {
394
670
  const input = props.events;
395
671
  return isEventSource(input) ? sourcedEvents() ?? [] : input;
396
672
  };
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();
673
+ const instant = createNowSampler(() => ({
674
+ clock: props.clock,
675
+ now: props.now
676
+ }), () => TODAY_SAMPLE_INTERVAL_MS);
408
677
  const derived = createMemo(() => {
409
678
  const inputs = {
410
679
  allowAgentDelete: props.allowAgentDelete,
@@ -511,32 +780,17 @@ function createCalendarRoot(config, root) {
511
780
  view,
512
781
  visibleRange: visibleDates
513
782
  };
514
- return root.provide(value, () => props.children);
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));
515
792
  };
516
793
  }
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
794
  // src/calendar.ts
541
795
  /** `useCalendarPendingChanges` without a selector: the map itself. */
542
796
  const allChanges = (changes) => changes;
@@ -560,7 +814,7 @@ function createCalendar() {
560
814
  }
561
815
  const root = createRootContext("calendar-root");
562
816
  const primitive = createCalendarPrimitive({ views });
563
- const parts = createCalendarParts(root);
817
+ const { EventPart, ...parts } = createCalendarParts(root);
564
818
  const Root = createCalendarRoot({
565
819
  eventAdapter: options.eventAdapter,
566
820
  invalidEventPolicy: options.invalidEventPolicy,
@@ -575,6 +829,8 @@ function createCalendar() {
575
829
  }
576
830
  const factory = {
577
831
  ...parts,
832
+ Announcer,
833
+ Event: EventPart,
578
834
  Root,
579
835
  ViewSwitcher: parts.ViewSwitcher,
580
836
  views,
@@ -604,6 +860,306 @@ function createCalendar() {
604
860
  return Object.freeze(factory);
605
861
  };
606
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
+ }
607
1163
  // src/views.ts
608
1164
  /**
609
1165
  * Defines a view: a name, the core strategy that ranges, navigates and projects it, and the Solid
@@ -618,4 +1174,4 @@ function defineCalendarView(view) {
618
1174
  strategy: view.strategy
619
1175
  });
620
1176
  }
621
- export { createCalendar, createCalendarStore, createStateSelector, defineCalendarView, resolveViewOptions };
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 };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@moltenship/calendar-solid",
3
- "version": "2.0.0-beta.1",
4
- "description": "Headless SolidJS integration for Moltenship Time.",
5
- "homepage": "https://time.molten.sh/docs/api/solid",
3
+ "version": "2.0.0",
4
+ "description": "Headless SolidJS 2 integration for Moltenship Time.",
5
+ "homepage": "https://time.molten.sh/docs/solid",
6
6
  "bugs": {
7
7
  "url": "https://github.com/Moltenship/time/issues"
8
8
  },
@@ -28,9 +28,10 @@
28
28
  "access": "public"
29
29
  },
30
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"
31
+ "@moltenship/calendar-core": "2.0.0",
32
+ "@moltenship/calendar-dnd": "2.0.0",
33
+ "@moltenship/calendar-primitives": "2.0.0",
34
+ "@moltenship/calendar-temporal": "2.0.0"
34
35
  },
35
36
  "devDependencies": {
36
37
  "@solidjs/web": "2.0.3",