@zealakit/chrono-react 0.0.0-stage → 1.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +625 -2
- package/dist/calendar/components.d.ts +346 -0
- package/dist/calendar/components.js +243 -0
- package/dist/calendar/context.d.ts +636 -0
- package/dist/calendar/context.js +21 -0
- package/dist/calendar/index.d.ts +6 -0
- package/dist/calendar/index.js +6 -0
- package/dist/calendar/mini-calendar.d.ts +60 -0
- package/dist/calendar/mini-calendar.js +51 -0
- package/dist/calendar/options.d.ts +4 -0
- package/dist/calendar/options.js +98 -0
- package/dist/calendar/use-calendar.d.ts +340 -0
- package/dist/calendar/use-calendar.js +154 -0
- package/dist/calendar/use-mini-calendar.d.ts +302 -0
- package/dist/calendar/use-mini-calendar.js +56 -0
- package/dist/calendar/utilities.d.ts +9 -0
- package/dist/calendar/utilities.js +8 -0
- package/dist/date/bind-panel.d.ts +30 -0
- package/dist/date/bind-panel.js +125 -0
- package/dist/date/components.d.ts +197 -0
- package/dist/date/components.js +193 -0
- package/dist/date/context.d.ts +34 -0
- package/dist/date/context.js +19 -0
- package/dist/date/index.d.ts +4 -0
- package/dist/date/index.js +4 -0
- package/dist/date/options.d.ts +7 -0
- package/dist/date/options.js +91 -0
- package/dist/date/use-date-input.d.ts +43 -0
- package/dist/date/use-date-input.js +138 -0
- package/dist/date/use-date-panel.d.ts +81 -0
- package/dist/date/use-date-panel.js +21 -0
- package/dist/date/utilities.d.ts +4 -0
- package/dist/date/utilities.js +4 -0
- package/dist/datetime/components.d.ts +121 -0
- package/dist/datetime/components.js +164 -0
- package/dist/datetime/context.d.ts +8 -0
- package/dist/datetime/context.js +18 -0
- package/dist/datetime/index.d.ts +4 -0
- package/dist/datetime/index.js +4 -0
- package/dist/datetime/options.d.ts +5 -0
- package/dist/datetime/options.js +99 -0
- package/dist/datetime/use-datetime-input.d.ts +44 -0
- package/dist/datetime/use-datetime-input.js +145 -0
- package/dist/datetime/use-datetime-panel.d.ts +128 -0
- package/dist/datetime/use-datetime-panel.js +60 -0
- package/dist/datetime/utilities.d.ts +4 -0
- package/dist/datetime/utilities.js +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/shared/defined-options.d.ts +18 -0
- package/dist/shared/defined-options.js +9 -0
- package/dist/shared/merge-props.d.ts +9 -0
- package/dist/shared/merge-props.js +31 -0
- package/dist/shared/modifiers.d.ts +7 -0
- package/dist/shared/modifiers.js +6 -0
- package/dist/shared/part.d.ts +10 -0
- package/dist/shared/part.js +9 -0
- package/dist/shared/slot.d.ts +12 -0
- package/dist/shared/slot.js +57 -0
- package/dist/shared/style-properties.d.ts +8 -0
- package/dist/shared/style-properties.js +13 -0
- package/dist/shared/to-react-props.d.ts +11 -0
- package/dist/shared/to-react-props.js +27 -0
- package/dist/time/bind-panel.d.ts +19 -0
- package/dist/time/bind-panel.js +97 -0
- package/dist/time/components.d.ts +183 -0
- package/dist/time/components.js +169 -0
- package/dist/time/context.d.ts +24 -0
- package/dist/time/context.js +19 -0
- package/dist/time/index.d.ts +4 -0
- package/dist/time/index.js +4 -0
- package/dist/time/options.d.ts +5 -0
- package/dist/time/options.js +85 -0
- package/dist/time/use-time-input.d.ts +43 -0
- package/dist/time/use-time-input.js +138 -0
- package/dist/time/use-time-panel.d.ts +37 -0
- package/dist/time/use-time-panel.js +18 -0
- package/dist/time/utilities.d.ts +4 -0
- package/dist/time/utilities.js +4 -0
- package/dist/vendor/core/calendar/availability.d.ts +39 -0
- package/dist/vendor/core/calendar/availability.js +73 -0
- package/dist/vendor/core/calendar/controllers/calendar-controller.d.ts +251 -0
- package/dist/vendor/core/calendar/controllers/calendar-controller.js +1396 -0
- package/dist/vendor/core/calendar/controllers/drag-engine.d.ts +99 -0
- package/dist/vendor/core/calendar/controllers/drag-engine.js +363 -0
- package/dist/vendor/core/calendar/controllers/mini-calendar-controller.d.ts +66 -0
- package/dist/vendor/core/calendar/controllers/mini-calendar-controller.js +171 -0
- package/dist/vendor/core/calendar/controllers/shared.d.ts +33 -0
- package/dist/vendor/core/calendar/controllers/shared.js +82 -0
- package/dist/vendor/core/calendar/events/agenda-layout.d.ts +21 -0
- package/dist/vendor/core/calendar/events/agenda-layout.js +72 -0
- package/dist/vendor/core/calendar/events/all-day-row.d.ts +22 -0
- package/dist/vendor/core/calendar/events/all-day-row.js +93 -0
- package/dist/vendor/core/calendar/events/background-layout.d.ts +66 -0
- package/dist/vendor/core/calendar/events/background-layout.js +106 -0
- package/dist/vendor/core/calendar/events/index.d.ts +17 -0
- package/dist/vendor/core/calendar/events/index.js +8 -0
- package/dist/vendor/core/calendar/events/month-layout.d.ts +13 -0
- package/dist/vendor/core/calendar/events/month-layout.js +157 -0
- package/dist/vendor/core/calendar/events/normalize.d.ts +33 -0
- package/dist/vendor/core/calendar/events/normalize.js +156 -0
- package/dist/vendor/core/calendar/events/now-indicator.d.ts +18 -0
- package/dist/vendor/core/calendar/events/now-indicator.js +19 -0
- package/dist/vendor/core/calendar/events/overflow.d.ts +36 -0
- package/dist/vendor/core/calendar/events/overflow.js +112 -0
- package/dist/vendor/core/calendar/events/sort.d.ts +21 -0
- package/dist/vendor/core/calendar/events/sort.js +35 -0
- package/dist/vendor/core/calendar/events/time-grid-layout.d.ts +22 -0
- package/dist/vendor/core/calendar/events/time-grid-layout.js +177 -0
- package/dist/vendor/core/calendar/events/types.d.ts +141 -0
- package/dist/vendor/core/calendar/events/types.js +1 -0
- package/dist/vendor/core/calendar/index.d.ts +70 -0
- package/dist/vendor/core/calendar/index.js +37 -0
- package/dist/vendor/core/calendar/interaction/auto-scroll.d.ts +11 -0
- package/dist/vendor/core/calendar/interaction/auto-scroll.js +37 -0
- package/dist/vendor/core/calendar/interaction/drag-geometry.d.ts +52 -0
- package/dist/vendor/core/calendar/interaction/drag-geometry.js +122 -0
- package/dist/vendor/core/calendar/interaction/drag-keyboard.d.ts +38 -0
- package/dist/vendor/core/calendar/interaction/drag-keyboard.js +53 -0
- package/dist/vendor/core/calendar/interaction/drag-pointer.d.ts +24 -0
- package/dist/vendor/core/calendar/interaction/drag-pointer.js +43 -0
- package/dist/vendor/core/calendar/interaction/event-focus.d.ts +28 -0
- package/dist/vendor/core/calendar/interaction/event-focus.js +44 -0
- package/dist/vendor/core/calendar/interaction/gesture-handle.d.ts +17 -0
- package/dist/vendor/core/calendar/interaction/gesture-handle.js +26 -0
- package/dist/vendor/core/calendar/interaction/hit-test.d.ts +17 -0
- package/dist/vendor/core/calendar/interaction/hit-test.js +26 -0
- package/dist/vendor/core/calendar/interaction/pending.d.ts +17 -0
- package/dist/vendor/core/calendar/interaction/pending.js +17 -0
- package/dist/vendor/core/calendar/interaction/pointer.d.ts +21 -0
- package/dist/vendor/core/calendar/interaction/pointer.js +169 -0
- package/dist/vendor/core/calendar/interaction/selection.d.ts +29 -0
- package/dist/vendor/core/calendar/interaction/selection.js +47 -0
- package/dist/vendor/core/calendar/internal/equal.d.ts +3 -0
- package/dist/vendor/core/calendar/internal/equal.js +43 -0
- package/dist/vendor/core/calendar/navigation/navigate.d.ts +33 -0
- package/dist/vendor/core/calendar/navigation/navigate.js +81 -0
- package/dist/vendor/core/calendar/navigation/range.d.ts +15 -0
- package/dist/vendor/core/calendar/navigation/range.js +52 -0
- package/dist/vendor/core/calendar/navigation/title.d.ts +12 -0
- package/dist/vendor/core/calendar/navigation/title.js +39 -0
- package/dist/vendor/core/calendar/navigation/view-definition.d.ts +39 -0
- package/dist/vendor/core/calendar/navigation/view-definition.js +62 -0
- package/dist/vendor/core/calendar/navigation/zoom.d.ts +5 -0
- package/dist/vendor/core/calendar/navigation/zoom.js +11 -0
- package/dist/vendor/core/calendar/recurrence/apply.d.ts +50 -0
- package/dist/vendor/core/calendar/recurrence/apply.js +206 -0
- package/dist/vendor/core/calendar/recurrence/expand.d.ts +27 -0
- package/dist/vendor/core/calendar/recurrence/expand.js +298 -0
- package/dist/vendor/core/calendar/recurrence/pack.d.ts +3 -0
- package/dist/vendor/core/calendar/recurrence/pack.js +248 -0
- package/dist/vendor/core/calendar/recurrence/rrule-types.d.ts +30 -0
- package/dist/vendor/core/calendar/recurrence/rrule-types.js +8 -0
- package/dist/vendor/core/calendar/recurrence/rrule.d.ts +12 -0
- package/dist/vendor/core/calendar/recurrence/rrule.js +278 -0
- package/dist/vendor/core/calendar/recurrence/series.d.ts +25 -0
- package/dist/vendor/core/calendar/recurrence/series.js +163 -0
- package/dist/vendor/core/calendar/recurrence/types.d.ts +30 -0
- package/dist/vendor/core/calendar/recurrence/types.js +1 -0
- package/dist/vendor/core/calendar/resources/keys.d.ts +2 -0
- package/dist/vendor/core/calendar/resources/keys.js +2 -0
- package/dist/vendor/core/calendar/resources/resource-time-grid.d.ts +7 -0
- package/dist/vendor/core/calendar/resources/resource-time-grid.js +129 -0
- package/dist/vendor/core/calendar/resources/timeline-axis.d.ts +10 -0
- package/dist/vendor/core/calendar/resources/timeline-axis.js +98 -0
- package/dist/vendor/core/calendar/resources/timeline-layout.d.ts +7 -0
- package/dist/vendor/core/calendar/resources/timeline-layout.js +109 -0
- package/dist/vendor/core/calendar/resources/tree.d.ts +10 -0
- package/dist/vendor/core/calendar/resources/tree.js +86 -0
- package/dist/vendor/core/calendar/resources/types.d.ts +177 -0
- package/dist/vendor/core/calendar/resources/types.js +1 -0
- package/dist/vendor/core/calendar/resources/views.d.ts +7 -0
- package/dist/vendor/core/calendar/resources/views.js +45 -0
- package/dist/vendor/core/calendar/resources/windowing.d.ts +11 -0
- package/dist/vendor/core/calendar/resources/windowing.js +17 -0
- package/dist/vendor/core/calendar/views/day.d.ts +37 -0
- package/dist/vendor/core/calendar/views/day.js +36 -0
- package/dist/vendor/core/calendar/views/list-layout.d.ts +8 -0
- package/dist/vendor/core/calendar/views/list-layout.js +5 -0
- package/dist/vendor/core/calendar/views/mini-calendar.d.ts +23 -0
- package/dist/vendor/core/calendar/views/mini-calendar.js +31 -0
- package/dist/vendor/core/calendar/views/month-layout.d.ts +30 -0
- package/dist/vendor/core/calendar/views/month-layout.js +63 -0
- package/dist/vendor/core/calendar/views/time-grid-layout.d.ts +26 -0
- package/dist/vendor/core/calendar/views/time-grid-layout.js +27 -0
- package/dist/vendor/core/date/index.d.ts +9 -0
- package/dist/vendor/core/date/index.js +9 -0
- package/dist/vendor/core/date/input/date-input-controller.d.ts +97 -0
- package/dist/vendor/core/date/input/date-input-controller.js +466 -0
- package/dist/vendor/core/date/input/date-range-input-controller.d.ts +43 -0
- package/dist/vendor/core/date/input/date-range-input-controller.js +186 -0
- package/dist/vendor/core/date/input/parse.d.ts +22 -0
- package/dist/vendor/core/date/input/parse.js +78 -0
- package/dist/vendor/core/date/input/validity.d.ts +6 -0
- package/dist/vendor/core/date/input/validity.js +13 -0
- package/dist/vendor/core/date/panel/panel-controller.d.ts +176 -0
- package/dist/vendor/core/date/panel/panel-controller.js +704 -0
- package/dist/vendor/core/date/presets.d.ts +22 -0
- package/dist/vendor/core/date/presets.js +103 -0
- package/dist/vendor/core/date/selection/multiple.d.ts +7 -0
- package/dist/vendor/core/date/selection/multiple.js +29 -0
- package/dist/vendor/core/date/selection/range.d.ts +29 -0
- package/dist/vendor/core/date/selection/range.js +35 -0
- package/dist/vendor/core/date/types.d.ts +12 -0
- package/dist/vendor/core/date/types.js +1 -0
- package/dist/vendor/core/datetime/compose.d.ts +24 -0
- package/dist/vendor/core/datetime/compose.js +49 -0
- package/dist/vendor/core/datetime/constraints.d.ts +42 -0
- package/dist/vendor/core/datetime/constraints.js +56 -0
- package/dist/vendor/core/datetime/index.d.ts +9 -0
- package/dist/vendor/core/datetime/index.js +9 -0
- package/dist/vendor/core/datetime/input/datetime-input-controller.d.ts +96 -0
- package/dist/vendor/core/datetime/input/datetime-input-controller.js +380 -0
- package/dist/vendor/core/datetime/input/datetime-range-input-controller.d.ts +46 -0
- package/dist/vendor/core/datetime/input/datetime-range-input-controller.js +171 -0
- package/dist/vendor/core/datetime/input/parse.d.ts +20 -0
- package/dist/vendor/core/datetime/input/parse.js +56 -0
- package/dist/vendor/core/datetime/panel/controller.d.ts +64 -0
- package/dist/vendor/core/datetime/panel/controller.js +191 -0
- package/dist/vendor/core/datetime/panel/range-controller.d.ts +71 -0
- package/dist/vendor/core/datetime/panel/range-controller.js +205 -0
- package/dist/vendor/core/datetime/types.d.ts +12 -0
- package/dist/vendor/core/datetime/types.js +1 -0
- package/dist/vendor/core/datetime/zone/day-instants.d.ts +19 -0
- package/dist/vendor/core/datetime/zone/day-instants.js +52 -0
- package/dist/vendor/core/datetime/zone/resolve.d.ts +16 -0
- package/dist/vendor/core/datetime/zone/resolve.js +24 -0
- package/dist/vendor/core/dom/auto-scroll.d.ts +37 -0
- package/dist/vendor/core/dom/auto-scroll.js +57 -0
- package/dist/vendor/core/dom/drag-session.d.ts +25 -0
- package/dist/vendor/core/dom/drag-session.js +257 -0
- package/dist/vendor/core/foundation/a11y/announcer.d.ts +12 -0
- package/dist/vendor/core/foundation/a11y/announcer.js +24 -0
- package/dist/vendor/core/foundation/a11y/grid-navigation.d.ts +19 -0
- package/dist/vendor/core/foundation/a11y/grid-navigation.js +76 -0
- package/dist/vendor/core/foundation/a11y/index.d.ts +8 -0
- package/dist/vendor/core/foundation/a11y/index.js +5 -0
- package/dist/vendor/core/foundation/a11y/labels.d.ts +21 -0
- package/dist/vendor/core/foundation/a11y/labels.js +43 -0
- package/dist/vendor/core/foundation/a11y/messages.d.ts +80 -0
- package/dist/vendor/core/foundation/a11y/messages.js +74 -0
- package/dist/vendor/core/foundation/a11y/roving-focus.d.ts +18 -0
- package/dist/vendor/core/foundation/a11y/roving-focus.js +73 -0
- package/dist/vendor/core/foundation/constraints/availability-rules.d.ts +52 -0
- package/dist/vendor/core/foundation/constraints/availability-rules.js +64 -0
- package/dist/vendor/core/foundation/constraints/availability.d.ts +93 -0
- package/dist/vendor/core/foundation/constraints/availability.js +480 -0
- package/dist/vendor/core/foundation/constraints/date.d.ts +21 -0
- package/dist/vendor/core/foundation/constraints/date.js +41 -0
- package/dist/vendor/core/foundation/constraints/index.d.ts +9 -0
- package/dist/vendor/core/foundation/constraints/index.js +4 -0
- package/dist/vendor/core/foundation/constraints/range.d.ts +44 -0
- package/dist/vendor/core/foundation/constraints/range.js +70 -0
- package/dist/vendor/core/foundation/constraints/time.d.ts +30 -0
- package/dist/vendor/core/foundation/constraints/time.js +56 -0
- package/dist/vendor/core/foundation/grid/index.d.ts +8 -0
- package/dist/vendor/core/foundation/grid/index.js +4 -0
- package/dist/vendor/core/foundation/grid/month-grid.d.ts +33 -0
- package/dist/vendor/core/foundation/grid/month-grid.js +52 -0
- package/dist/vendor/core/foundation/grid/time-axis.d.ts +25 -0
- package/dist/vendor/core/foundation/grid/time-axis.js +32 -0
- package/dist/vendor/core/foundation/grid/weekday-headers.d.ts +17 -0
- package/dist/vendor/core/foundation/grid/weekday-headers.js +26 -0
- package/dist/vendor/core/foundation/grid/year-grid.d.ts +29 -0
- package/dist/vendor/core/foundation/grid/year-grid.js +40 -0
- package/dist/vendor/core/foundation/index.d.ts +8 -0
- package/dist/vendor/core/foundation/index.js +8 -0
- package/dist/vendor/core/foundation/input/form.d.ts +7 -0
- package/dist/vendor/core/foundation/input/form.js +10 -0
- package/dist/vendor/core/foundation/input/index.d.ts +6 -0
- package/dist/vendor/core/foundation/input/index.js +3 -0
- package/dist/vendor/core/foundation/input/segment-engine.d.ts +33 -0
- package/dist/vendor/core/foundation/input/segment-engine.js +45 -0
- package/dist/vendor/core/foundation/input/tokenize.d.ts +19 -0
- package/dist/vendor/core/foundation/input/tokenize.js +24 -0
- package/dist/vendor/core/foundation/locale/digits.d.ts +6 -0
- package/dist/vendor/core/foundation/locale/digits.js +35 -0
- package/dist/vendor/core/foundation/locale/direction.d.ts +1 -0
- package/dist/vendor/core/foundation/locale/direction.js +25 -0
- package/dist/vendor/core/foundation/locale/format.d.ts +31 -0
- package/dist/vendor/core/foundation/locale/format.js +77 -0
- package/dist/vendor/core/foundation/locale/hour-cycle.d.ts +12 -0
- package/dist/vendor/core/foundation/locale/hour-cycle.js +41 -0
- package/dist/vendor/core/foundation/locale/index.d.ts +10 -0
- package/dist/vendor/core/foundation/locale/index.js +8 -0
- package/dist/vendor/core/foundation/locale/names.d.ts +6 -0
- package/dist/vendor/core/foundation/locale/names.js +30 -0
- package/dist/vendor/core/foundation/locale/resolve.d.ts +7 -0
- package/dist/vendor/core/foundation/locale/resolve.js +39 -0
- package/dist/vendor/core/foundation/locale/week-info.d.ts +5 -0
- package/dist/vendor/core/foundation/locale/week-info.js +60 -0
- package/dist/vendor/core/foundation/locale/zone-label.d.ts +6 -0
- package/dist/vendor/core/foundation/locale/zone-label.js +24 -0
- package/dist/vendor/core/foundation/ranges/date-range.d.ts +18 -0
- package/dist/vendor/core/foundation/ranges/date-range.js +40 -0
- package/dist/vendor/core/foundation/ranges/index.d.ts +4 -0
- package/dist/vendor/core/foundation/ranges/index.js +2 -0
- package/dist/vendor/core/foundation/ranges/interval.d.ts +24 -0
- package/dist/vendor/core/foundation/ranges/interval.js +54 -0
- package/dist/vendor/core/foundation/store/attributes.d.ts +19 -0
- package/dist/vendor/core/foundation/store/attributes.js +43 -0
- package/dist/vendor/core/foundation/store/controllable.d.ts +19 -0
- package/dist/vendor/core/foundation/store/controllable.js +50 -0
- package/dist/vendor/core/foundation/store/env.d.ts +1 -0
- package/dist/vendor/core/foundation/store/env.js +3 -0
- package/dist/vendor/core/foundation/store/ids.d.ts +9 -0
- package/dist/vendor/core/foundation/store/ids.js +12 -0
- package/dist/vendor/core/foundation/store/index.d.ts +11 -0
- package/dist/vendor/core/foundation/store/index.js +7 -0
- package/dist/vendor/core/foundation/store/store.d.ts +7 -0
- package/dist/vendor/core/foundation/store/store.js +25 -0
- package/dist/vendor/core/foundation/store/ticker.d.ts +11 -0
- package/dist/vendor/core/foundation/store/ticker.js +27 -0
- package/dist/vendor/core/foundation/store/with-optional.d.ts +15 -0
- package/dist/vendor/core/foundation/store/with-optional.js +3 -0
- package/dist/vendor/core/foundation/values/clock.d.ts +4 -0
- package/dist/vendor/core/foundation/values/clock.js +21 -0
- package/dist/vendor/core/foundation/values/compare.d.ts +16 -0
- package/dist/vendor/core/foundation/values/compare.js +70 -0
- package/dist/vendor/core/foundation/values/convert.d.ts +31 -0
- package/dist/vendor/core/foundation/values/convert.js +108 -0
- package/dist/vendor/core/foundation/values/epoch-day.d.ts +15 -0
- package/dist/vendor/core/foundation/values/epoch-day.js +43 -0
- package/dist/vendor/core/foundation/values/index.d.ts +14 -0
- package/dist/vendor/core/foundation/values/index.js +10 -0
- package/dist/vendor/core/foundation/values/iso.d.ts +24 -0
- package/dist/vendor/core/foundation/values/iso.js +111 -0
- package/dist/vendor/core/foundation/values/plain-date-time.d.ts +8 -0
- package/dist/vendor/core/foundation/values/plain-date-time.js +25 -0
- package/dist/vendor/core/foundation/values/plain-date.d.ts +33 -0
- package/dist/vendor/core/foundation/values/plain-date.js +105 -0
- package/dist/vendor/core/foundation/values/plain-time.d.ts +15 -0
- package/dist/vendor/core/foundation/values/plain-time.js +43 -0
- package/dist/vendor/core/foundation/values/types.d.ts +37 -0
- package/dist/vendor/core/foundation/values/types.js +1 -0
- package/dist/vendor/core/foundation/values/week.d.ts +9 -0
- package/dist/vendor/core/foundation/values/week.js +31 -0
- package/dist/vendor/core/foundation/values/year-month.d.ts +10 -0
- package/dist/vendor/core/foundation/values/year-month.js +19 -0
- package/dist/vendor/core/foundation/values/zoned.d.ts +16 -0
- package/dist/vendor/core/foundation/values/zoned.js +152 -0
- package/dist/vendor/core/index.d.ts +5 -0
- package/dist/vendor/core/index.js +5 -0
- package/dist/vendor/core/time/index.d.ts +8 -0
- package/dist/vendor/core/time/index.js +8 -0
- package/dist/vendor/core/time/input/parse.d.ts +19 -0
- package/dist/vendor/core/time/input/parse.js +82 -0
- package/dist/vendor/core/time/input/time-input-controller.d.ts +102 -0
- package/dist/vendor/core/time/input/time-input-controller.js +547 -0
- package/dist/vendor/core/time/input/time-range-input-controller.d.ts +49 -0
- package/dist/vendor/core/time/input/time-range-input-controller.js +178 -0
- package/dist/vendor/core/time/input/validity.d.ts +7 -0
- package/dist/vendor/core/time/input/validity.js +16 -0
- package/dist/vendor/core/time/panel/time-panel-controller.d.ts +163 -0
- package/dist/vendor/core/time/panel/time-panel-controller.js +809 -0
- package/dist/vendor/core/time/selection/range.d.ts +25 -0
- package/dist/vendor/core/time/selection/range.js +35 -0
- package/dist/vendor/core/time/selection/slots.d.ts +46 -0
- package/dist/vendor/core/time/selection/slots.js +76 -0
- package/dist/vendor/core/time/types.d.ts +11 -0
- package/dist/vendor/core/time/types.js +1 -0
- package/package.json +83 -4
|
@@ -0,0 +1,809 @@
|
|
|
1
|
+
import { compileAvailability, createControllable, createId, defaultMessages, filterDailyRules, formatTime, fromSecondOfDay, getDayPeriodLabel, getDayPeriodNames, getHourCycle, getTextDirection, getTimeStatus, isSameTime, mergeMessages, nowZoned, plainTime, today as readTodayDate, resolveLocale, toLatinDigits, toPlainTime, toSecondOfDay, } from "../../foundation/index.js";
|
|
2
|
+
import { checkTimeRangeValue, } from "../selection/range.js";
|
|
3
|
+
import { getBookingSlots, timeKey, } from "../selection/slots.js";
|
|
4
|
+
import { withOptional } from "../../foundation/store/with-optional.js";
|
|
5
|
+
const DAY = 86400;
|
|
6
|
+
const EMPTY = { hour: null, minute: null, second: null, period: null };
|
|
7
|
+
const sameT = (a, b) => a === b || (a !== null && b !== null && isSameTime(a, b));
|
|
8
|
+
const sameR = (a, b) => a === b || (a !== null && b !== null && sameT(a.start, b.start) && sameT(a.end, b.end));
|
|
9
|
+
function createPanel(kind, initial) {
|
|
10
|
+
let options = initial;
|
|
11
|
+
const id = options.id ?? createId("chrono-time-panel");
|
|
12
|
+
const range = kind === "range";
|
|
13
|
+
const layout = () => options.layout ?? (range ? "list" : "columns");
|
|
14
|
+
const localeOf = () => options.locale === undefined ? undefined : resolveLocale(options.locale);
|
|
15
|
+
const gran = () => options.granularity ?? "minute";
|
|
16
|
+
const cycle = () => options.hourCycle ?? getHourCycle(localeOf());
|
|
17
|
+
const bound = (value) => value === undefined ? undefined : toPlainTime(value);
|
|
18
|
+
const constraints = () => ({
|
|
19
|
+
min: bound(options.min),
|
|
20
|
+
max: bound(options.max),
|
|
21
|
+
disabledRanges: options.disabledRanges?.map((r) => ({
|
|
22
|
+
start: toPlainTime(r.start),
|
|
23
|
+
end: toPlainTime(r.end),
|
|
24
|
+
})),
|
|
25
|
+
isTimeDisabled: options.isTimeDisabled,
|
|
26
|
+
});
|
|
27
|
+
const availabilityOf = () => {
|
|
28
|
+
if (options.availability === undefined) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
const input = typeof options.availability.getDayStatus === "function"
|
|
32
|
+
? options.availability
|
|
33
|
+
: filterDailyRules(options.availability);
|
|
34
|
+
return compileAvailability(input, {
|
|
35
|
+
timeZone: options.timeZone,
|
|
36
|
+
now: options.now,
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
const referenceDate = () => readTodayDate(options.timeZone, options.now);
|
|
40
|
+
const unavailableAt = (time) => {
|
|
41
|
+
const availability = availabilityOf();
|
|
42
|
+
return ((options.isTimeUnavailable?.(time) ?? false) ||
|
|
43
|
+
(availability ? !availability.isTimeAvailable(referenceDate(), time) : false));
|
|
44
|
+
};
|
|
45
|
+
const selectable = (time) => getTimeStatus(time, constraints()).selectable && !unavailableAt(time);
|
|
46
|
+
const limits = () => ({
|
|
47
|
+
...constraints(),
|
|
48
|
+
isTimeUnavailable: unavailableAt,
|
|
49
|
+
allowOvernight: options.allowOvernight,
|
|
50
|
+
minDuration: options.minDuration,
|
|
51
|
+
maxDuration: options.maxDuration,
|
|
52
|
+
});
|
|
53
|
+
const control = createControllable({
|
|
54
|
+
value: options.value,
|
|
55
|
+
defaultValue: options.defaultValue ?? null,
|
|
56
|
+
onChange: (value) => {
|
|
57
|
+
if (range)
|
|
58
|
+
options.onValueChange?.(value);
|
|
59
|
+
else
|
|
60
|
+
options.onValueChange?.(value, {
|
|
61
|
+
slot: slotOf(value),
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
equals: (a, b) => range
|
|
65
|
+
? sameR(a, b)
|
|
66
|
+
: sameT(a, b),
|
|
67
|
+
});
|
|
68
|
+
// ---- entries (list layout)
|
|
69
|
+
let entryCache;
|
|
70
|
+
const entries = () => {
|
|
71
|
+
const stepSeconds = (options.step?.minutes ?? 0) * 60 + (options.step?.seconds ?? 0) || 1800;
|
|
72
|
+
const sig = JSON.stringify([
|
|
73
|
+
options.start,
|
|
74
|
+
options.end,
|
|
75
|
+
options.slotDuration,
|
|
76
|
+
options.step,
|
|
77
|
+
options.slots,
|
|
78
|
+
options.min,
|
|
79
|
+
options.max,
|
|
80
|
+
options.disabledRanges,
|
|
81
|
+
]);
|
|
82
|
+
// Functions cannot be part of the signature; recompute when they are present.
|
|
83
|
+
if (entryCache?.sig === sig &&
|
|
84
|
+
!options.isTimeDisabled &&
|
|
85
|
+
!options.isTimeUnavailable &&
|
|
86
|
+
options.availability === undefined) {
|
|
87
|
+
return entryCache.entries;
|
|
88
|
+
}
|
|
89
|
+
const slotMode = options.slots !== undefined || options.slotDuration !== undefined;
|
|
90
|
+
let list;
|
|
91
|
+
if (slotMode) {
|
|
92
|
+
list = getBookingSlots({
|
|
93
|
+
start: options.start,
|
|
94
|
+
end: options.end,
|
|
95
|
+
slotDuration: options.slotDuration,
|
|
96
|
+
step: options.step?.minutes,
|
|
97
|
+
slots: options.slots,
|
|
98
|
+
min: options.min,
|
|
99
|
+
max: options.max,
|
|
100
|
+
disabledRanges: options.disabledRanges,
|
|
101
|
+
isTimeDisabled: options.isTimeDisabled,
|
|
102
|
+
isTimeUnavailable: unavailableAt,
|
|
103
|
+
}).map((slot) => ({
|
|
104
|
+
key: slot.key,
|
|
105
|
+
time: slot.start,
|
|
106
|
+
startSecond: slot.startSecond,
|
|
107
|
+
endSecond: slot.endSecond,
|
|
108
|
+
available: slot.available,
|
|
109
|
+
slot,
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
const first = options.start === undefined ? 0 : toSecondOfDay(toPlainTime(options.start));
|
|
114
|
+
const last = options.end === undefined ? DAY : toSecondOfDay(toPlainTime(options.end)) || DAY;
|
|
115
|
+
list = [];
|
|
116
|
+
for (let at = first; at < last; at += stepSeconds) {
|
|
117
|
+
const time = fromSecondOfDay(at);
|
|
118
|
+
list.push({
|
|
119
|
+
key: timeKey(time),
|
|
120
|
+
time,
|
|
121
|
+
startSecond: at,
|
|
122
|
+
endSecond: at,
|
|
123
|
+
available: selectable(time),
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
entryCache = { sig, entries: list };
|
|
128
|
+
return list;
|
|
129
|
+
};
|
|
130
|
+
const slotOf = (value) => {
|
|
131
|
+
if (!value || range || layout() !== "list")
|
|
132
|
+
return undefined;
|
|
133
|
+
return entries().find((e) => e.key === timeKey(value))?.slot;
|
|
134
|
+
};
|
|
135
|
+
// ---- columns state (partial parts per set)
|
|
136
|
+
const parts = { value: EMPTY, start: EMPTY, end: EMPTY };
|
|
137
|
+
const requiredParts = () => {
|
|
138
|
+
const list = ["hour"];
|
|
139
|
+
if (gran() !== "hour")
|
|
140
|
+
list.push("minute");
|
|
141
|
+
if (gran() === "second")
|
|
142
|
+
list.push("second");
|
|
143
|
+
if (cycle() === "h12")
|
|
144
|
+
list.push("dayPeriod");
|
|
145
|
+
return list;
|
|
146
|
+
};
|
|
147
|
+
const to24 = (hour, period) => cycle() === "h12" ? (hour % 12) + (period === 1 ? 12 : 0) : hour;
|
|
148
|
+
const fromTime = (time) => time
|
|
149
|
+
? {
|
|
150
|
+
hour: cycle() === "h12" ? time.hour % 12 || 12 : time.hour,
|
|
151
|
+
minute: time.minute,
|
|
152
|
+
second: time.second,
|
|
153
|
+
period: time.hour >= 12 ? 1 : 0,
|
|
154
|
+
}
|
|
155
|
+
: EMPTY;
|
|
156
|
+
const toTime = (p) => {
|
|
157
|
+
const need = requiredParts();
|
|
158
|
+
const has = (part) => part === "dayPeriod" ? p.period !== null : p[part] !== null;
|
|
159
|
+
if (!need.every(has))
|
|
160
|
+
return null;
|
|
161
|
+
return plainTime(to24(p.hour, p.period), gran() === "hour" ? 0 : p.minute, gran() === "second" ? p.second : 0);
|
|
162
|
+
};
|
|
163
|
+
const syncParts = () => {
|
|
164
|
+
const value = control.get();
|
|
165
|
+
if (range) {
|
|
166
|
+
const r = value;
|
|
167
|
+
if (!sameT(toTime(parts.start), r?.start ?? null))
|
|
168
|
+
parts.start = fromTime(r?.start ?? null);
|
|
169
|
+
if (!sameT(toTime(parts.end), r?.end ?? null))
|
|
170
|
+
parts.end = fromTime(r?.end ?? null);
|
|
171
|
+
}
|
|
172
|
+
else if (!sameT(toTime(parts.value), value)) {
|
|
173
|
+
parts.value = fromTime(value);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
syncParts();
|
|
177
|
+
let focusKey = "";
|
|
178
|
+
let hover = null;
|
|
179
|
+
let draftStart = null;
|
|
180
|
+
let beforeDraft = null;
|
|
181
|
+
let lastPreview = "";
|
|
182
|
+
let typeBuffer = "";
|
|
183
|
+
let typeAt = 0;
|
|
184
|
+
let state;
|
|
185
|
+
const listeners = new Set();
|
|
186
|
+
const minuteValues = () => {
|
|
187
|
+
const size = options.step?.minutes ?? 1;
|
|
188
|
+
return Array.from({ length: Math.ceil(60 / size) }, (_, i) => i * size);
|
|
189
|
+
};
|
|
190
|
+
const secondValues = () => {
|
|
191
|
+
const size = options.step?.seconds ?? 1;
|
|
192
|
+
return Array.from({ length: Math.ceil(60 / size) }, (_, i) => i * size);
|
|
193
|
+
};
|
|
194
|
+
const hourValues = () => cycle() === "h12"
|
|
195
|
+
? [12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
|
|
196
|
+
: Array.from({ length: 24 }, (_, i) => i);
|
|
197
|
+
/** Does any time in the given hour/minute/second sets satisfy `ok`? Early exit. */
|
|
198
|
+
const anyOk = (hours, minutes, seconds, ok) => {
|
|
199
|
+
for (const h of hours) {
|
|
200
|
+
for (const m of minutes) {
|
|
201
|
+
for (const s of seconds)
|
|
202
|
+
if (ok(plainTime(h, m, s)))
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return false;
|
|
207
|
+
};
|
|
208
|
+
const text = (time) => formatTime(time, localeOf(), {
|
|
209
|
+
hour: "numeric",
|
|
210
|
+
minute: gran() === "hour" ? undefined : "2-digit",
|
|
211
|
+
second: gran() === "second" ? "2-digit" : undefined,
|
|
212
|
+
hourCycle: cycle(),
|
|
213
|
+
});
|
|
214
|
+
const buildColumns = (setKey, messages) => {
|
|
215
|
+
const p = parts[setKey];
|
|
216
|
+
const names = getDayPeriodNames(localeOf());
|
|
217
|
+
const isEnd = range && setKey === "end";
|
|
218
|
+
const start = isEnd ? toTime(parts.start) : null;
|
|
219
|
+
const rangeOk = (end) => !start || checkTimeRangeValue(start, end, limits()).valid;
|
|
220
|
+
const ok = (time) => (isEnd ? true : selectable(time));
|
|
221
|
+
const restMinutes = gran() === "hour" ? [0] : minuteValues();
|
|
222
|
+
const restSeconds = gran() === "second" ? secondValues() : [0];
|
|
223
|
+
const hoursFor = (hour, period) => {
|
|
224
|
+
if (hour === null)
|
|
225
|
+
return Array.from({ length: 24 }, (_, i) => i).filter((h) => cycle() !== "h12" || period === null || h >= 12 === (period === 1));
|
|
226
|
+
return cycle() === "h12"
|
|
227
|
+
? period === null
|
|
228
|
+
? [to24(hour, 0), to24(hour, 1)]
|
|
229
|
+
: [to24(hour, period)]
|
|
230
|
+
: [hour];
|
|
231
|
+
};
|
|
232
|
+
const mark = (hours, minutes, seconds) => {
|
|
233
|
+
const free = anyOk(hours, minutes, seconds, ok);
|
|
234
|
+
const blocked = isEnd && start ? !anyOk(hours, minutes, seconds, (t) => rangeOk(t)) : false;
|
|
235
|
+
return { disabled: !free && !isEnd, blocked };
|
|
236
|
+
};
|
|
237
|
+
const columns = [];
|
|
238
|
+
const prefix = setKey === "value" ? "" : `${setKey}:`;
|
|
239
|
+
const selectedTime = toTime(p);
|
|
240
|
+
const option = (part, value, label, shown, flags, selected) => ({
|
|
241
|
+
key: `${prefix}${part}:${value}`,
|
|
242
|
+
text: shown,
|
|
243
|
+
label: `${label}, ${shown}`,
|
|
244
|
+
value,
|
|
245
|
+
selected,
|
|
246
|
+
disabled: flags.disabled,
|
|
247
|
+
unavailable: false,
|
|
248
|
+
focused: false,
|
|
249
|
+
now: false,
|
|
250
|
+
rangeStart: false,
|
|
251
|
+
rangeEnd: false,
|
|
252
|
+
inRange: false,
|
|
253
|
+
preview: false,
|
|
254
|
+
blocked: flags.blocked,
|
|
255
|
+
});
|
|
256
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
257
|
+
columns.push({
|
|
258
|
+
key: `${prefix}hour`,
|
|
259
|
+
part: "hour",
|
|
260
|
+
label: messages.hour,
|
|
261
|
+
options: hourValues().map((h) => option("hour", h, messages.hour, cycle() === "h12" ? String(h) : pad(h), mark(hoursFor(h, p.period), restMinutes, restSeconds), p.hour === h)),
|
|
262
|
+
});
|
|
263
|
+
if (gran() !== "hour") {
|
|
264
|
+
columns.push({
|
|
265
|
+
key: `${prefix}minute`,
|
|
266
|
+
part: "minute",
|
|
267
|
+
label: messages.minute,
|
|
268
|
+
options: minuteValues().map((m) => option("minute", m, messages.minute, pad(m), mark(hoursFor(p.hour, p.period), [m], restSeconds), p.minute === m)),
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
if (gran() === "second") {
|
|
272
|
+
columns.push({
|
|
273
|
+
key: `${prefix}second`,
|
|
274
|
+
part: "second",
|
|
275
|
+
label: messages.second,
|
|
276
|
+
options: secondValues().map((s) => option("second", s, messages.second, pad(s), mark(hoursFor(p.hour, p.period), p.minute === null ? restMinutes : [p.minute], [s]), p.second === s)),
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
if (cycle() === "h12") {
|
|
280
|
+
columns.push({
|
|
281
|
+
key: `${prefix}dayPeriod`,
|
|
282
|
+
part: "dayPeriod",
|
|
283
|
+
label: messages.dayPeriod,
|
|
284
|
+
options: [0, 1].map((period) => option("dayPeriod", period, messages.dayPeriod, period === 1 ? names.pm : names.am, mark(p.hour === null
|
|
285
|
+
? Array.from({ length: 12 }, (_, i) => i + period * 12)
|
|
286
|
+
: [to24(p.hour, period)], restMinutes, restSeconds), p.period === period)),
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
void selectedTime;
|
|
290
|
+
return columns;
|
|
291
|
+
};
|
|
292
|
+
const compute = () => {
|
|
293
|
+
syncParts();
|
|
294
|
+
const locale = localeOf();
|
|
295
|
+
const messages = mergeMessages(defaultMessages, options.messages);
|
|
296
|
+
const value = control.get();
|
|
297
|
+
const draft = range && value?.start != null && value?.end == null;
|
|
298
|
+
const rv = range ? value : null;
|
|
299
|
+
const lay = layout();
|
|
300
|
+
let sets = [];
|
|
301
|
+
const groups = [];
|
|
302
|
+
let preview = null;
|
|
303
|
+
let crossesMidnight = false;
|
|
304
|
+
let duration = null;
|
|
305
|
+
if (rv?.start && rv.end) {
|
|
306
|
+
const check = checkTimeRangeValue(rv.start, rv.end, limits());
|
|
307
|
+
if (check.valid) {
|
|
308
|
+
crossesMidnight = check.crossesMidnight;
|
|
309
|
+
duration = check.duration;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
if (lay === "columns") {
|
|
313
|
+
sets = (range ? ["start", "end"] : ["value"]).map((key) => ({
|
|
314
|
+
key,
|
|
315
|
+
label: key === "start" ? messages.startTime : key === "end" ? messages.endTime : messages.time,
|
|
316
|
+
columns: buildColumns(key, messages),
|
|
317
|
+
}));
|
|
318
|
+
if (!focusKey ||
|
|
319
|
+
!sets.some((s) => s.columns.some((c) => c.options.some((o) => o.key === focusKey)))) {
|
|
320
|
+
const firstSet = sets[0];
|
|
321
|
+
const chosen = firstSet.columns[0]?.options.find((o) => o.selected);
|
|
322
|
+
focusKey =
|
|
323
|
+
(chosen ??
|
|
324
|
+
firstSet.columns[0]?.options.find((o) => !o.disabled) ??
|
|
325
|
+
firstSet.columns[0]?.options[0])?.key ?? "";
|
|
326
|
+
}
|
|
327
|
+
for (const set of sets)
|
|
328
|
+
for (const column of set.columns)
|
|
329
|
+
for (const o of column.options)
|
|
330
|
+
o.focused = o.key === focusKey;
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
const list = entries();
|
|
334
|
+
const nowSecond = options.now === undefined
|
|
335
|
+
? null
|
|
336
|
+
: (() => {
|
|
337
|
+
const z = nowZoned(options.timeZone ?? "UTC", options.now);
|
|
338
|
+
return z.hour * 3600 + z.minute * 60 + z.second;
|
|
339
|
+
})();
|
|
340
|
+
const target = hover ?? focusKey;
|
|
341
|
+
const startEntry = draft
|
|
342
|
+
? (draftStart ?? list.find((e) => e.key === timeKey(rv?.start)) ?? null)
|
|
343
|
+
: null;
|
|
344
|
+
const rangeFor = (a, b) => {
|
|
345
|
+
let from = a;
|
|
346
|
+
let to = b;
|
|
347
|
+
if (to.startSecond < from.startSecond && !options.allowOvernight)
|
|
348
|
+
[from, to] = [to, from];
|
|
349
|
+
const endSecond = to.endSecond % DAY === 0 && to.endSecond > 0 ? DAY : to.endSecond;
|
|
350
|
+
const end = fromSecondOfDay(endSecond % DAY);
|
|
351
|
+
const check = checkTimeRangeValue(from.time, end, limits(), endSecond);
|
|
352
|
+
return { start: from.time, end, endSecond, valid: check.valid };
|
|
353
|
+
};
|
|
354
|
+
if (draft && startEntry) {
|
|
355
|
+
const targetEntry = list.find((e) => e.key === target);
|
|
356
|
+
if (targetEntry) {
|
|
357
|
+
const r = rangeFor(startEntry, targetEntry);
|
|
358
|
+
if (r.valid)
|
|
359
|
+
preview = { start: r.start, end: r.end };
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
const shown = rv?.start && rv.end ? { start: rv.start, end: rv.end } : preview;
|
|
363
|
+
const startSec = shown ? toSecondOfDay(shown.start) : null;
|
|
364
|
+
let endSec = shown ? toSecondOfDay(shown.end) : null;
|
|
365
|
+
if (startSec !== null && endSec !== null && endSec === 0 && startSec > 0)
|
|
366
|
+
endSec = DAY;
|
|
367
|
+
const flat = list.map((e) => {
|
|
368
|
+
const selectedSingle = !range && value !== null && timeKey(value) === e.key;
|
|
369
|
+
const inShown = startSec !== null &&
|
|
370
|
+
endSec !== null &&
|
|
371
|
+
(endSec > startSec
|
|
372
|
+
? e.startSecond >= startSec && e.startSecond < endSec
|
|
373
|
+
: e.startSecond >= startSec || e.startSecond < endSec - DAY);
|
|
374
|
+
const complete = !!(rv?.start && rv.end);
|
|
375
|
+
const slotMode = e.slot !== undefined;
|
|
376
|
+
return {
|
|
377
|
+
key: e.key,
|
|
378
|
+
text: text(e.time),
|
|
379
|
+
label: [
|
|
380
|
+
slotMode
|
|
381
|
+
? `${text(e.time)} – ${text(fromSecondOfDay(e.endSecond % DAY))}`
|
|
382
|
+
: text(e.time),
|
|
383
|
+
...(selectedSingle ? [messages.selected] : []),
|
|
384
|
+
...(!e.available ? [messages.unavailable] : []),
|
|
385
|
+
].join(", "),
|
|
386
|
+
value: e.startSecond,
|
|
387
|
+
selected: selectedSingle ||
|
|
388
|
+
(range && !!rv?.start && sameT(rv.start, e.time)) ||
|
|
389
|
+
(range && complete && endMatches(e, rv?.end ?? null)),
|
|
390
|
+
disabled: false,
|
|
391
|
+
unavailable: !e.available,
|
|
392
|
+
focused: e.key === focusKey,
|
|
393
|
+
now: nowSecond !== null &&
|
|
394
|
+
nowSecond >= e.startSecond &&
|
|
395
|
+
nowSecond <
|
|
396
|
+
(e.endSecond > e.startSecond
|
|
397
|
+
? e.endSecond
|
|
398
|
+
: e.startSecond + (options.step?.minutes ?? 30) * 60),
|
|
399
|
+
rangeStart: range && !!shown && sameT(shown.start, e.time),
|
|
400
|
+
rangeEnd: range && !!shown && endMatches(e, shown.end),
|
|
401
|
+
inRange: range && complete && inShown,
|
|
402
|
+
preview: range && !complete && inShown,
|
|
403
|
+
blocked: !!(draft && startEntry && !rangeFor(startEntry, e).valid),
|
|
404
|
+
};
|
|
405
|
+
});
|
|
406
|
+
const groupOf = (e) => {
|
|
407
|
+
const by = options.groupBy;
|
|
408
|
+
if (!by)
|
|
409
|
+
return { key: "all", label: "" };
|
|
410
|
+
if (typeof by === "function")
|
|
411
|
+
return by(e.time);
|
|
412
|
+
if (by === "hour")
|
|
413
|
+
return {
|
|
414
|
+
key: String(e.time.hour),
|
|
415
|
+
label: text(plainTime(e.time.hour, 0, 0)),
|
|
416
|
+
};
|
|
417
|
+
const label = getDayPeriodLabel(e.time.hour, locale);
|
|
418
|
+
return { key: label, label };
|
|
419
|
+
};
|
|
420
|
+
for (let i = 0; i < list.length; i += 1) {
|
|
421
|
+
const g = groupOf(list[i]);
|
|
422
|
+
const last = groups[groups.length - 1];
|
|
423
|
+
if (last && last.key === g.key)
|
|
424
|
+
last.options.push(flat[i]);
|
|
425
|
+
else
|
|
426
|
+
groups.push({
|
|
427
|
+
key: g.key,
|
|
428
|
+
label: g.label,
|
|
429
|
+
options: [flat[i]],
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
if (!focusKey || !flat.some((o) => o.key === focusKey)) {
|
|
433
|
+
focusKey =
|
|
434
|
+
(flat.find((o) => o.selected) ?? flat.find((o) => !o.unavailable) ?? flat[0])?.key ?? "";
|
|
435
|
+
for (const o of flat)
|
|
436
|
+
o.focused = o.key === focusKey;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
function endMatches(e, end) {
|
|
440
|
+
if (!end)
|
|
441
|
+
return false;
|
|
442
|
+
const endSecond = toSecondOfDay(end);
|
|
443
|
+
return e.slot ? e.endSecond % DAY === endSecond : e.startSecond === endSecond;
|
|
444
|
+
}
|
|
445
|
+
return withOptional({
|
|
446
|
+
id,
|
|
447
|
+
kind,
|
|
448
|
+
layout: lay,
|
|
449
|
+
value: value,
|
|
450
|
+
draft,
|
|
451
|
+
preview,
|
|
452
|
+
sets,
|
|
453
|
+
groups,
|
|
454
|
+
focusKey,
|
|
455
|
+
crossesMidnight,
|
|
456
|
+
duration,
|
|
457
|
+
readOnly: options.readOnly ?? false,
|
|
458
|
+
disabled: options.disabled ?? false,
|
|
459
|
+
autoFocus: options.autoFocus ?? false,
|
|
460
|
+
scrollToSelected: options.scrollToSelected ?? true,
|
|
461
|
+
direction: getTextDirection(locale),
|
|
462
|
+
locale,
|
|
463
|
+
messages,
|
|
464
|
+
});
|
|
465
|
+
};
|
|
466
|
+
const refresh = () => {
|
|
467
|
+
const next = compute();
|
|
468
|
+
if (state && JSON.stringify(state) === JSON.stringify(next))
|
|
469
|
+
return;
|
|
470
|
+
state = next;
|
|
471
|
+
if (range) {
|
|
472
|
+
const key = next.preview ? `${timeKey(next.preview.start)}|${timeKey(next.preview.end)}` : "";
|
|
473
|
+
if (key !== lastPreview) {
|
|
474
|
+
lastPreview = key;
|
|
475
|
+
options.onRangePreviewChange?.(next.preview);
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
for (const listener of [...listeners])
|
|
479
|
+
listener(state);
|
|
480
|
+
};
|
|
481
|
+
state = compute();
|
|
482
|
+
const setValue = (value) => control.set(value);
|
|
483
|
+
const flatOptions = () => state.layout === "list"
|
|
484
|
+
? state.groups.flatMap((g) => g.options)
|
|
485
|
+
: state.sets.flatMap((s) => s.columns.flatMap((c) => c.options));
|
|
486
|
+
const parseColumnKey = (key) => {
|
|
487
|
+
const bits = key.split(":");
|
|
488
|
+
const set = (bits.length === 3 ? bits[0] : "value");
|
|
489
|
+
return {
|
|
490
|
+
set,
|
|
491
|
+
part: bits[bits.length - 2],
|
|
492
|
+
value: Number(bits[bits.length - 1]),
|
|
493
|
+
};
|
|
494
|
+
};
|
|
495
|
+
const commitSingle = (time) => {
|
|
496
|
+
options.onValueCommit?.(time, { slot: slotOf(time) });
|
|
497
|
+
};
|
|
498
|
+
const pickColumn = (key) => {
|
|
499
|
+
const { set, part, value } = parseColumnKey(key);
|
|
500
|
+
const option = flatOptions().find((o) => o.key === key);
|
|
501
|
+
if (!option || (option.disabled && set !== "end"))
|
|
502
|
+
return;
|
|
503
|
+
const next = { ...parts[set] };
|
|
504
|
+
if (part === "hour")
|
|
505
|
+
next.hour = value;
|
|
506
|
+
else if (part === "minute")
|
|
507
|
+
next.minute = value;
|
|
508
|
+
else if (part === "second")
|
|
509
|
+
next.second = value;
|
|
510
|
+
else
|
|
511
|
+
next.period = value;
|
|
512
|
+
// A part that became disabled by this pick is cleared, never moved silently.
|
|
513
|
+
parts[set] = next;
|
|
514
|
+
const probe = (p) => {
|
|
515
|
+
const time = toTime(p);
|
|
516
|
+
return time ? (set === "end" ? true : selectable(time)) : true;
|
|
517
|
+
};
|
|
518
|
+
if (!probe(next)) {
|
|
519
|
+
const cleared = { ...next };
|
|
520
|
+
if (part === "hour" || part === "dayPeriod")
|
|
521
|
+
cleared.minute = gran() === "hour" ? cleared.minute : null;
|
|
522
|
+
if (cleared.minute === null && gran() === "second")
|
|
523
|
+
cleared.second = null;
|
|
524
|
+
parts[set] = cleared;
|
|
525
|
+
}
|
|
526
|
+
focusKey = key;
|
|
527
|
+
const last = requiredParts()[requiredParts().length - 1];
|
|
528
|
+
if (range) {
|
|
529
|
+
const start = toTime(parts.start);
|
|
530
|
+
const end = toTime(parts.end);
|
|
531
|
+
const current = control.get();
|
|
532
|
+
const nextValue = start === null && end === null ? null : { start, end };
|
|
533
|
+
if (!sameR(current, nextValue))
|
|
534
|
+
setValue(nextValue);
|
|
535
|
+
if (set === "end" && part === last && start && end) {
|
|
536
|
+
const check = checkTimeRangeValue(start, end, limits());
|
|
537
|
+
if (check.valid)
|
|
538
|
+
options.onValueCommit?.({
|
|
539
|
+
start,
|
|
540
|
+
end,
|
|
541
|
+
});
|
|
542
|
+
else
|
|
543
|
+
options.onInvalidRange?.(check.reason);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
else {
|
|
547
|
+
const time = toTime(parts.value);
|
|
548
|
+
if (!sameT(control.get(), time))
|
|
549
|
+
setValue(time);
|
|
550
|
+
if (part === last && time && selectable(time))
|
|
551
|
+
commitSingle(time);
|
|
552
|
+
}
|
|
553
|
+
};
|
|
554
|
+
const pickList = (key) => {
|
|
555
|
+
const list = entries();
|
|
556
|
+
const entry = list.find((e) => e.key === key);
|
|
557
|
+
if (!entry)
|
|
558
|
+
return;
|
|
559
|
+
focusKey = key;
|
|
560
|
+
if (!entry.available) {
|
|
561
|
+
if (range)
|
|
562
|
+
options.onInvalidRange?.("start-invalid");
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
if (!range) {
|
|
566
|
+
setValue(entry.time);
|
|
567
|
+
commitSingle(entry.time);
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
const current = control.get();
|
|
571
|
+
if (!current?.start || current.end) {
|
|
572
|
+
beforeDraft = current?.start && current.end ? current : null;
|
|
573
|
+
draftStart = entry;
|
|
574
|
+
setValue({ start: entry.time, end: null });
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
const first = draftStart ?? list.find((e) => e.key === timeKey(current.start)) ?? entry;
|
|
578
|
+
let from = first;
|
|
579
|
+
let to = entry;
|
|
580
|
+
if (to.startSecond < from.startSecond && !options.allowOvernight)
|
|
581
|
+
[from, to] = [to, from];
|
|
582
|
+
const endSecond = to.endSecond % DAY === 0 && to.endSecond > 0 ? DAY : to.endSecond;
|
|
583
|
+
const end = fromSecondOfDay(endSecond % DAY);
|
|
584
|
+
const check = checkTimeRangeValue(from.time, end, limits(), endSecond);
|
|
585
|
+
if (!check.valid) {
|
|
586
|
+
options.onInvalidRange?.(check.reason);
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
draftStart = null;
|
|
590
|
+
setValue({ start: from.time, end });
|
|
591
|
+
options.onValueCommit?.({
|
|
592
|
+
start: from.time,
|
|
593
|
+
end,
|
|
594
|
+
});
|
|
595
|
+
};
|
|
596
|
+
const move = (to) => {
|
|
597
|
+
if (!to)
|
|
598
|
+
return true;
|
|
599
|
+
focusKey = to;
|
|
600
|
+
hover = null;
|
|
601
|
+
refresh();
|
|
602
|
+
return true;
|
|
603
|
+
};
|
|
604
|
+
const controller = {
|
|
605
|
+
getState: () => state,
|
|
606
|
+
getValue: () => control.get(),
|
|
607
|
+
getSlot: (key) => entries().find((e) => e.key === key)?.slot,
|
|
608
|
+
subscribe(listener) {
|
|
609
|
+
listeners.add(listener);
|
|
610
|
+
return () => {
|
|
611
|
+
listeners.delete(listener);
|
|
612
|
+
};
|
|
613
|
+
},
|
|
614
|
+
setOptions(next) {
|
|
615
|
+
options = { ...options, ...next };
|
|
616
|
+
control.sync({ value: options.value });
|
|
617
|
+
refresh();
|
|
618
|
+
},
|
|
619
|
+
pick(key, _source) {
|
|
620
|
+
if (options.disabled || options.readOnly) {
|
|
621
|
+
focusKey = key;
|
|
622
|
+
refresh();
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
if (layout() === "columns")
|
|
626
|
+
pickColumn(key);
|
|
627
|
+
else
|
|
628
|
+
pickList(key);
|
|
629
|
+
hover = null;
|
|
630
|
+
refresh();
|
|
631
|
+
},
|
|
632
|
+
setPreview(key) {
|
|
633
|
+
hover = key;
|
|
634
|
+
refresh();
|
|
635
|
+
},
|
|
636
|
+
cancelDraft() {
|
|
637
|
+
if (!range || !state.draft)
|
|
638
|
+
return;
|
|
639
|
+
hover = null;
|
|
640
|
+
draftStart = null;
|
|
641
|
+
setValue(beforeDraft);
|
|
642
|
+
beforeDraft = null;
|
|
643
|
+
refresh();
|
|
644
|
+
},
|
|
645
|
+
clear() {
|
|
646
|
+
if (options.disabled || options.readOnly)
|
|
647
|
+
return;
|
|
648
|
+
parts.value = EMPTY;
|
|
649
|
+
parts.start = EMPTY;
|
|
650
|
+
parts.end = EMPTY;
|
|
651
|
+
draftStart = null;
|
|
652
|
+
setValue(range ? null : null);
|
|
653
|
+
refresh();
|
|
654
|
+
},
|
|
655
|
+
commit() {
|
|
656
|
+
const value = control.get();
|
|
657
|
+
if (range) {
|
|
658
|
+
const r = value;
|
|
659
|
+
if (r?.start && r.end)
|
|
660
|
+
options.onValueCommit?.({
|
|
661
|
+
start: r.start,
|
|
662
|
+
end: r.end,
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
else if (value)
|
|
666
|
+
commitSingle(value);
|
|
667
|
+
},
|
|
668
|
+
focusOption(key) {
|
|
669
|
+
focusKey = key;
|
|
670
|
+
refresh();
|
|
671
|
+
},
|
|
672
|
+
handleKeyDown(key, modifiers) {
|
|
673
|
+
if (options.disabled || modifiers.ctrl || modifiers.meta)
|
|
674
|
+
return false;
|
|
675
|
+
if (key === "Escape") {
|
|
676
|
+
if (range && state.draft) {
|
|
677
|
+
controller.cancelDraft();
|
|
678
|
+
return true;
|
|
679
|
+
}
|
|
680
|
+
return false;
|
|
681
|
+
}
|
|
682
|
+
if (key === "Enter" || key === " ") {
|
|
683
|
+
controller.pick(state.focusKey, "keyboard");
|
|
684
|
+
return true;
|
|
685
|
+
}
|
|
686
|
+
const all = flatOptions();
|
|
687
|
+
const index = all.findIndex((o) => o.key === focusKey);
|
|
688
|
+
const current = all[index];
|
|
689
|
+
const digit = toLatinDigits(key, localeOf());
|
|
690
|
+
if (/^\d$/.test(digit)) {
|
|
691
|
+
const now = (options.timer ?? Date.now)();
|
|
692
|
+
typeBuffer = now - typeAt > 700 ? digit : typeBuffer + digit;
|
|
693
|
+
typeAt = now;
|
|
694
|
+
const norm = (value) => toLatinDigits(value, localeOf()).replace(/^0+(?=\d)/, "");
|
|
695
|
+
const scope = state.layout === "columns"
|
|
696
|
+
? (state.sets
|
|
697
|
+
.flatMap((s) => s.columns)
|
|
698
|
+
.find((c) => c.options.some((o) => o.key === focusKey))?.options ?? all)
|
|
699
|
+
: all;
|
|
700
|
+
const found = scope.find((o) => norm(o.text).startsWith(norm(typeBuffer)));
|
|
701
|
+
return move(found?.key);
|
|
702
|
+
}
|
|
703
|
+
if (state.layout === "list") {
|
|
704
|
+
const perHour = Math.max(1, Math.round(3600 /
|
|
705
|
+
((options.step?.minutes ?? 0) * 60 + (options.step?.seconds ?? 0) ||
|
|
706
|
+
(options.slotDuration
|
|
707
|
+
? (options.step?.minutes ?? options.slotDuration) * 60
|
|
708
|
+
: 1800))));
|
|
709
|
+
const by = {
|
|
710
|
+
ArrowDown: 1,
|
|
711
|
+
ArrowUp: -1,
|
|
712
|
+
PageDown: perHour,
|
|
713
|
+
PageUp: -perHour,
|
|
714
|
+
};
|
|
715
|
+
if (key in by)
|
|
716
|
+
return move(all[Math.max(0, Math.min(all.length - 1, index + by[key]))]?.key);
|
|
717
|
+
if (key === "Home")
|
|
718
|
+
return move(all[0]?.key);
|
|
719
|
+
if (key === "End")
|
|
720
|
+
return move(all[all.length - 1]?.key);
|
|
721
|
+
return false;
|
|
722
|
+
}
|
|
723
|
+
// columns: flat list of columns across sets
|
|
724
|
+
const columns = state.sets.flatMap((s) => s.columns);
|
|
725
|
+
const ci = columns.findIndex((c) => c.options.some((o) => o.key === focusKey));
|
|
726
|
+
const column = columns[ci];
|
|
727
|
+
if (!column || !current)
|
|
728
|
+
return false;
|
|
729
|
+
const at = column.options.findIndex((o) => o.key === focusKey);
|
|
730
|
+
const rtl = state.direction === "rtl";
|
|
731
|
+
const clamp = (n) => Math.max(0, Math.min(column.options.length - 1, n));
|
|
732
|
+
if (key === "ArrowDown")
|
|
733
|
+
return move(column.options[clamp(at + 1)]?.key);
|
|
734
|
+
if (key === "ArrowUp")
|
|
735
|
+
return move(column.options[clamp(at - 1)]?.key);
|
|
736
|
+
if (key === "Home")
|
|
737
|
+
return move(column.options[0]?.key);
|
|
738
|
+
if (key === "End")
|
|
739
|
+
return move(column.options[column.options.length - 1]?.key);
|
|
740
|
+
if (key === "PageDown" || key === "PageUp") {
|
|
741
|
+
const size = column.part === "hour" ? 3 : column.part === "dayPeriod" ? 1 : 15;
|
|
742
|
+
return move(column.options[clamp(at + (key === "PageDown" ? size : -size))]?.key);
|
|
743
|
+
}
|
|
744
|
+
if (key === "ArrowLeft" || key === "ArrowRight") {
|
|
745
|
+
const step = (key === "ArrowRight") !== rtl ? 1 : -1;
|
|
746
|
+
const target = columns[ci + step];
|
|
747
|
+
if (!target)
|
|
748
|
+
return true;
|
|
749
|
+
return move(target.options[Math.min(at, target.options.length - 1)]?.key);
|
|
750
|
+
}
|
|
751
|
+
return false;
|
|
752
|
+
},
|
|
753
|
+
getRootAttributes: () => ({
|
|
754
|
+
role: "group",
|
|
755
|
+
"data-chrono-time-panel": range ? "range" : true,
|
|
756
|
+
"data-layout": state.layout,
|
|
757
|
+
"data-disabled": state.disabled,
|
|
758
|
+
"data-readonly": state.readOnly,
|
|
759
|
+
dir: state.direction,
|
|
760
|
+
}),
|
|
761
|
+
getSetAttributes: (set) => ({
|
|
762
|
+
role: "group",
|
|
763
|
+
"aria-label": set.label,
|
|
764
|
+
"data-chrono-set": set.key,
|
|
765
|
+
}),
|
|
766
|
+
getColumnAttributes: (column) => ({
|
|
767
|
+
role: "listbox",
|
|
768
|
+
"aria-label": column.label,
|
|
769
|
+
"data-chrono-part": column.part,
|
|
770
|
+
}),
|
|
771
|
+
getGroupAttributes: (group) => ({
|
|
772
|
+
role: "group",
|
|
773
|
+
"aria-label": group.label || undefined,
|
|
774
|
+
"data-chrono-group": group.key,
|
|
775
|
+
}),
|
|
776
|
+
getListAttributes: () => ({
|
|
777
|
+
role: "listbox",
|
|
778
|
+
"aria-multiselectable": range ? "true" : undefined,
|
|
779
|
+
}),
|
|
780
|
+
getOptionAttributes: (option) => ({
|
|
781
|
+
role: "option",
|
|
782
|
+
"aria-selected": option.selected
|
|
783
|
+
? "true"
|
|
784
|
+
: option.disabled || option.unavailable
|
|
785
|
+
? undefined
|
|
786
|
+
: "false",
|
|
787
|
+
"aria-disabled": option.disabled || option.unavailable || option.blocked ? "true" : undefined,
|
|
788
|
+
"aria-label": option.label,
|
|
789
|
+
tabindex: option.focused ? 0 : -1,
|
|
790
|
+
"data-chrono-key": option.key,
|
|
791
|
+
"data-selected": option.selected,
|
|
792
|
+
"data-focused": option.focused,
|
|
793
|
+
"data-disabled": option.disabled,
|
|
794
|
+
"data-unavailable": option.unavailable,
|
|
795
|
+
"data-now": option.now,
|
|
796
|
+
"data-range-start": option.rangeStart,
|
|
797
|
+
"data-range-end": option.rangeEnd,
|
|
798
|
+
"data-in-range": option.inRange,
|
|
799
|
+
"data-range-preview": option.preview,
|
|
800
|
+
"data-range-blocked": option.blocked,
|
|
801
|
+
}),
|
|
802
|
+
destroy() {
|
|
803
|
+
listeners.clear();
|
|
804
|
+
},
|
|
805
|
+
};
|
|
806
|
+
return controller;
|
|
807
|
+
}
|
|
808
|
+
export const createTimePanelController = (options = {}) => createPanel("single", options);
|
|
809
|
+
export const createTimeRangePanelController = (options = {}) => createPanel("range", options);
|