@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,102 @@
|
|
|
1
|
+
import { type Attributes, type Availability, type AvailabilitySpec, type HiddenInput, type Messages, type PlainTime, type TimeInput } from "../../foundation/index.js";
|
|
2
|
+
import type { HourCycle, TimeGranularity, TimePartName, TimeValue } from "../types.js";
|
|
3
|
+
import { type TimeParseContext } from "./parse.js";
|
|
4
|
+
import { type TimeValidity } from "./validity.js";
|
|
5
|
+
export type TimeInputOptions = {
|
|
6
|
+
id?: string;
|
|
7
|
+
value?: TimeValue;
|
|
8
|
+
defaultValue?: TimeValue | undefined;
|
|
9
|
+
onValueChange?: (value: TimeValue) => void;
|
|
10
|
+
/** On blur or Enter with a valid value. */
|
|
11
|
+
onValueCommit?: (value: PlainTime) => void;
|
|
12
|
+
mode?: "segmented" | "text" | undefined;
|
|
13
|
+
granularity?: TimeGranularity | undefined;
|
|
14
|
+
hourCycle?: HourCycle | undefined;
|
|
15
|
+
step?: {
|
|
16
|
+
minutes?: number;
|
|
17
|
+
seconds?: number;
|
|
18
|
+
} | undefined;
|
|
19
|
+
/** The value ↑/↓ starts from on an empty part (default: now, rounded down to the step). */
|
|
20
|
+
placeholderValue?: TimeInput;
|
|
21
|
+
parse?: (text: string, context: TimeParseContext) => PlainTime | null;
|
|
22
|
+
format?: (time: PlainTime, context: {
|
|
23
|
+
locale?: string | undefined;
|
|
24
|
+
hourCycle: HourCycle;
|
|
25
|
+
}) => string;
|
|
26
|
+
onInvalidInput?: ((text: string) => void) | undefined;
|
|
27
|
+
name?: string;
|
|
28
|
+
required?: boolean | undefined;
|
|
29
|
+
readOnly?: boolean | undefined;
|
|
30
|
+
disabled?: boolean | undefined;
|
|
31
|
+
min?: TimeInput | undefined;
|
|
32
|
+
max?: TimeInput | undefined;
|
|
33
|
+
disabledRanges?: readonly {
|
|
34
|
+
start: TimeInput;
|
|
35
|
+
end: TimeInput;
|
|
36
|
+
}[];
|
|
37
|
+
isTimeDisabled?: ((time: PlainTime) => boolean) | undefined;
|
|
38
|
+
isTimeUnavailable?: ((time: PlainTime) => boolean) | undefined;
|
|
39
|
+
/** Availability model (plan 11 V6): `daily` rules only. */
|
|
40
|
+
availability?: AvailabilitySpec | Availability;
|
|
41
|
+
locale?: string | undefined;
|
|
42
|
+
timeZone?: string | undefined;
|
|
43
|
+
now?: number | undefined;
|
|
44
|
+
messages?: Partial<Messages> | undefined;
|
|
45
|
+
/** Internal: called when focus tries to leave the first (-1) or last (1) part. */
|
|
46
|
+
onFocusEdge?: (direction: 1 | -1) => void;
|
|
47
|
+
};
|
|
48
|
+
export type TimeSegmentView = {
|
|
49
|
+
type: TimePartName | "literal";
|
|
50
|
+
text: string;
|
|
51
|
+
value: number | null;
|
|
52
|
+
placeholder: string;
|
|
53
|
+
min: number;
|
|
54
|
+
max: number;
|
|
55
|
+
valueText: string;
|
|
56
|
+
editable: boolean;
|
|
57
|
+
};
|
|
58
|
+
export type TimeInputState = {
|
|
59
|
+
id: string;
|
|
60
|
+
mode: "segmented" | "text";
|
|
61
|
+
segments: TimeSegmentView[];
|
|
62
|
+
text: string;
|
|
63
|
+
value: TimeValue;
|
|
64
|
+
validity: TimeValidity;
|
|
65
|
+
focusedPart: TimePartName;
|
|
66
|
+
granularity: TimeGranularity;
|
|
67
|
+
hourCycle: HourCycle;
|
|
68
|
+
pattern: string;
|
|
69
|
+
required: boolean;
|
|
70
|
+
readOnly: boolean;
|
|
71
|
+
disabled: boolean;
|
|
72
|
+
direction: "ltr" | "rtl";
|
|
73
|
+
locale?: string;
|
|
74
|
+
messages: Messages;
|
|
75
|
+
hidden: HiddenInput[];
|
|
76
|
+
};
|
|
77
|
+
export type TimeKeyModifiers = {
|
|
78
|
+
shift: boolean;
|
|
79
|
+
ctrl: boolean;
|
|
80
|
+
meta: boolean;
|
|
81
|
+
};
|
|
82
|
+
export type TimeInputController = {
|
|
83
|
+
getState(): TimeInputState;
|
|
84
|
+
subscribe(listener: (state: TimeInputState) => void): () => void;
|
|
85
|
+
setOptions(options: Partial<TimeInputOptions>): void;
|
|
86
|
+
handleKeyDown(part: TimePartName, key: string, modifiers: TimeKeyModifiers): boolean;
|
|
87
|
+
focusPart(part: TimePartName): void;
|
|
88
|
+
settle(): void;
|
|
89
|
+
paste(text: string): boolean;
|
|
90
|
+
setText(text: string): void;
|
|
91
|
+
commitText(): boolean;
|
|
92
|
+
commit(): void;
|
|
93
|
+
clear(): void;
|
|
94
|
+
reset(): void;
|
|
95
|
+
handleTextKeyDown(key: string): boolean;
|
|
96
|
+
getRootAttributes(): Attributes;
|
|
97
|
+
getSegmentAttributes(segment: TimeSegmentView): Attributes;
|
|
98
|
+
getTextFieldAttributes(): Attributes;
|
|
99
|
+
getClearButtonAttributes(): Attributes;
|
|
100
|
+
destroy(): void;
|
|
101
|
+
};
|
|
102
|
+
export declare function createTimeInputController(initial?: TimeInputOptions): TimeInputController;
|
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
import { backspace, compileAvailability, createControllable, createId, defaultMessages, emptySegment, filterDailyRules, fold, formatTime, getDayPeriodNames, getHiddenInputs, getHourCycle, getTextDirection, isSameTime, mergeMessages, nowZoned, plainTime, today as readTodayDate, resolveLocale, segmentOf, snapTime, stepSegment, toLatinDigits, toLocaleDigits, toPlainTime, typeDigit, } from "../../foundation/index.js";
|
|
2
|
+
import { parseTime } from "./parse.js";
|
|
3
|
+
import { getTimeValidity, isTimeInvalid } from "./validity.js";
|
|
4
|
+
import { withOptional } from "../../foundation/store/with-optional.js";
|
|
5
|
+
const sameNullable = (a, b) => a === b || (a !== null && b !== null && isSameTime(a, b));
|
|
6
|
+
/** Part order and separators from `Intl`, e.g. `hour : minute " " dayPeriod`. */
|
|
7
|
+
function layoutOf(locale, hourCycle, granularity) {
|
|
8
|
+
const formatter = new Intl.DateTimeFormat(locale, {
|
|
9
|
+
hour: "numeric",
|
|
10
|
+
minute: granularity === "hour" ? undefined : "2-digit",
|
|
11
|
+
second: granularity === "second" ? "2-digit" : undefined,
|
|
12
|
+
hourCycle,
|
|
13
|
+
timeZone: "UTC",
|
|
14
|
+
});
|
|
15
|
+
const result = [];
|
|
16
|
+
for (const part of formatter.formatToParts(Date.UTC(2020, 0, 1, 15, 4, 5))) {
|
|
17
|
+
if (part.type === "hour" ||
|
|
18
|
+
part.type === "minute" ||
|
|
19
|
+
part.type === "second" ||
|
|
20
|
+
part.type === "dayPeriod") {
|
|
21
|
+
result.push({ type: part.type, text: "" });
|
|
22
|
+
}
|
|
23
|
+
else if (part.type === "literal") {
|
|
24
|
+
result.push({ type: "literal", text: part.value });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (hourCycle === "h12" && !result.some((item) => item.type === "dayPeriod")) {
|
|
28
|
+
result.push({ type: "literal", text: " " }, { type: "dayPeriod", text: "" });
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
export function createTimeInputController(initial = {}) {
|
|
33
|
+
let options = initial;
|
|
34
|
+
const id = options.id ?? createId("chrono-time-input");
|
|
35
|
+
const localeOf = () => options.locale === undefined ? undefined : resolveLocale(options.locale);
|
|
36
|
+
const granularity = () => options.granularity ?? "minute";
|
|
37
|
+
const hourCycle = () => options.hourCycle ?? getHourCycle(localeOf());
|
|
38
|
+
const bound = (value) => value === undefined ? undefined : toPlainTime(value);
|
|
39
|
+
const availabilityOf = () => {
|
|
40
|
+
if (options.availability === undefined) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
const input = typeof options.availability.getDayStatus === "function"
|
|
44
|
+
? options.availability
|
|
45
|
+
: filterDailyRules(options.availability);
|
|
46
|
+
return compileAvailability(input, {
|
|
47
|
+
timeZone: options.timeZone,
|
|
48
|
+
now: options.now,
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
const unavailableAt = (time) => {
|
|
52
|
+
const availability = availabilityOf();
|
|
53
|
+
return ((options.isTimeUnavailable?.(time) ?? false) ||
|
|
54
|
+
(availability
|
|
55
|
+
? !availability.isTimeAvailable(readTodayDate(options.timeZone, options.now), time)
|
|
56
|
+
: false));
|
|
57
|
+
};
|
|
58
|
+
const constraints = () => ({
|
|
59
|
+
min: bound(options.min),
|
|
60
|
+
max: bound(options.max),
|
|
61
|
+
step: options.step,
|
|
62
|
+
disabledRanges: options.disabledRanges?.map((range) => ({
|
|
63
|
+
start: toPlainTime(range.start),
|
|
64
|
+
end: toPlainTime(range.end),
|
|
65
|
+
})),
|
|
66
|
+
isTimeDisabled: options.isTimeDisabled,
|
|
67
|
+
isTimeUnavailable: unavailableAt,
|
|
68
|
+
});
|
|
69
|
+
const control = createControllable({
|
|
70
|
+
value: options.value,
|
|
71
|
+
defaultValue: options.defaultValue ?? null,
|
|
72
|
+
onChange: (value) => options.onValueChange?.(value),
|
|
73
|
+
equals: sameNullable,
|
|
74
|
+
});
|
|
75
|
+
let parts = {
|
|
76
|
+
hour: emptySegment,
|
|
77
|
+
minute: emptySegment,
|
|
78
|
+
second: emptySegment,
|
|
79
|
+
dayPeriod: emptySegment,
|
|
80
|
+
};
|
|
81
|
+
let text = "";
|
|
82
|
+
let textValue = null;
|
|
83
|
+
let invalidText = false;
|
|
84
|
+
let letters = "";
|
|
85
|
+
let state;
|
|
86
|
+
const listeners = new Set();
|
|
87
|
+
const requiredParts = () => {
|
|
88
|
+
const list = ["hour"];
|
|
89
|
+
if (granularity() !== "hour")
|
|
90
|
+
list.push("minute");
|
|
91
|
+
if (granularity() === "second")
|
|
92
|
+
list.push("second");
|
|
93
|
+
if (hourCycle() === "h12")
|
|
94
|
+
list.push("dayPeriod");
|
|
95
|
+
return list;
|
|
96
|
+
};
|
|
97
|
+
const visibleOrder = () => layoutOf(localeOf(), hourCycle(), granularity())
|
|
98
|
+
.map((item) => item.type)
|
|
99
|
+
.filter((type) => type !== "literal");
|
|
100
|
+
let focusedPart = visibleOrder()[0];
|
|
101
|
+
const formatValue = (time) => options.format
|
|
102
|
+
? options.format(time, { locale: localeOf(), hourCycle: hourCycle() })
|
|
103
|
+
: formatTime(time, localeOf(), {
|
|
104
|
+
hour: "numeric",
|
|
105
|
+
minute: granularity() === "hour" ? undefined : "2-digit",
|
|
106
|
+
second: granularity() === "second" ? "2-digit" : undefined,
|
|
107
|
+
hourCycle: hourCycle(),
|
|
108
|
+
});
|
|
109
|
+
const parseContext = () => ({
|
|
110
|
+
locale: localeOf(),
|
|
111
|
+
hourCycle: hourCycle(),
|
|
112
|
+
granularity: granularity(),
|
|
113
|
+
});
|
|
114
|
+
const parseText = (value) => {
|
|
115
|
+
if (options.parse) {
|
|
116
|
+
if (value.trim() === "")
|
|
117
|
+
return { error: "empty" };
|
|
118
|
+
const time = options.parse(value, parseContext());
|
|
119
|
+
return time ? { time } : { error: "unparseable" };
|
|
120
|
+
}
|
|
121
|
+
return parseTime(value, parseContext());
|
|
122
|
+
};
|
|
123
|
+
const syncParts = (value) => {
|
|
124
|
+
if (value) {
|
|
125
|
+
const h12 = hourCycle() === "h12";
|
|
126
|
+
parts = {
|
|
127
|
+
hour: segmentOf(h12 ? value.hour % 12 || 12 : value.hour),
|
|
128
|
+
minute: segmentOf(value.minute),
|
|
129
|
+
second: segmentOf(value.second),
|
|
130
|
+
dayPeriod: segmentOf(value.hour >= 12 ? 1 : 0),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
parts = {
|
|
135
|
+
hour: emptySegment,
|
|
136
|
+
minute: emptySegment,
|
|
137
|
+
second: emptySegment,
|
|
138
|
+
dayPeriod: emptySegment,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
text = value ? formatValue(value) : "";
|
|
142
|
+
textValue = value;
|
|
143
|
+
invalidText = false;
|
|
144
|
+
};
|
|
145
|
+
syncParts(control.get());
|
|
146
|
+
const derive = () => {
|
|
147
|
+
const required = requiredParts();
|
|
148
|
+
if (required.some((part) => parts[part].value === null))
|
|
149
|
+
return null;
|
|
150
|
+
let hour = parts.hour.value;
|
|
151
|
+
if (hourCycle() === "h12")
|
|
152
|
+
hour = (hour % 12) + (parts.dayPeriod.value === 1 ? 12 : 0);
|
|
153
|
+
return plainTime(hour, granularity() === "hour" ? 0 : parts.minute.value, granularity() === "second" ? parts.second.value : 0);
|
|
154
|
+
};
|
|
155
|
+
const filledCount = () => requiredParts().filter((part) => parts[part].value !== null).length;
|
|
156
|
+
const def = (part) => {
|
|
157
|
+
if (part === "hour") {
|
|
158
|
+
return hourCycle() === "h12"
|
|
159
|
+
? { min: 1, max: 12, maxDigits: 2, pageStep: 3 }
|
|
160
|
+
: { min: 0, max: 23, maxDigits: 2, pageStep: 3 };
|
|
161
|
+
}
|
|
162
|
+
if (part === "dayPeriod")
|
|
163
|
+
return { min: 0, max: 1, maxDigits: 1, pageStep: 1 };
|
|
164
|
+
return { min: 0, max: 59, maxDigits: 2, pageStep: 15 };
|
|
165
|
+
};
|
|
166
|
+
const stepOf = (part) => part === "minute"
|
|
167
|
+
? (options.step?.minutes ?? 1)
|
|
168
|
+
: part === "second"
|
|
169
|
+
? (options.step?.seconds ?? 1)
|
|
170
|
+
: 1;
|
|
171
|
+
const placeholder = () => {
|
|
172
|
+
if (options.placeholderValue !== undefined)
|
|
173
|
+
return toPlainTime(options.placeholderValue);
|
|
174
|
+
const zoned = nowZoned(options.timeZone ?? "UTC", options.now);
|
|
175
|
+
const time = plainTime(zoned.hour, zoned.minute, 0);
|
|
176
|
+
const size = (options.step?.minutes ?? 0) * 60 + (options.step?.seconds ?? 0);
|
|
177
|
+
return size > 0 ? snapTime(time, options.step ?? {}, "floor") : time;
|
|
178
|
+
};
|
|
179
|
+
const validityNow = () => {
|
|
180
|
+
if (options.mode === "text") {
|
|
181
|
+
if (text.trim() === "")
|
|
182
|
+
return "empty";
|
|
183
|
+
if (invalidText)
|
|
184
|
+
return "incomplete";
|
|
185
|
+
const value = control.get();
|
|
186
|
+
return value ? getTimeValidity(1, 1, value, constraints()) : "incomplete";
|
|
187
|
+
}
|
|
188
|
+
return getTimeValidity(filledCount(), requiredParts().length, derive(), constraints());
|
|
189
|
+
};
|
|
190
|
+
const compute = () => {
|
|
191
|
+
const locale = localeOf();
|
|
192
|
+
const messages = mergeMessages(defaultMessages, options.messages);
|
|
193
|
+
const names = getDayPeriodNames(locale);
|
|
194
|
+
const placeholders = {
|
|
195
|
+
hour: messages.placeholderHour,
|
|
196
|
+
minute: messages.placeholderMinute,
|
|
197
|
+
second: messages.placeholderSecond,
|
|
198
|
+
dayPeriod: messages.placeholderDayPeriod,
|
|
199
|
+
};
|
|
200
|
+
const display = (part) => {
|
|
201
|
+
const segment = parts[part];
|
|
202
|
+
if (part === "dayPeriod") {
|
|
203
|
+
return segment.value === null
|
|
204
|
+
? placeholders[part]
|
|
205
|
+
: segment.value === 1
|
|
206
|
+
? names.pm
|
|
207
|
+
: names.am;
|
|
208
|
+
}
|
|
209
|
+
if (segment.buffer !== "")
|
|
210
|
+
return toLocaleDigits(segment.buffer, locale);
|
|
211
|
+
if (segment.value === null)
|
|
212
|
+
return placeholders[part];
|
|
213
|
+
const pad = part !== "hour" || hourCycle() === "h23";
|
|
214
|
+
return toLocaleDigits(String(segment.value).padStart(pad ? 2 : 1, "0"), locale);
|
|
215
|
+
};
|
|
216
|
+
const segments = layoutOf(locale, hourCycle(), granularity()).map((item) => {
|
|
217
|
+
if (item.type === "literal") {
|
|
218
|
+
return {
|
|
219
|
+
type: "literal",
|
|
220
|
+
text: item.text,
|
|
221
|
+
value: null,
|
|
222
|
+
placeholder: "",
|
|
223
|
+
min: 0,
|
|
224
|
+
max: 0,
|
|
225
|
+
valueText: "",
|
|
226
|
+
editable: false,
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
const bounds = def(item.type);
|
|
230
|
+
const shown = display(item.type);
|
|
231
|
+
return {
|
|
232
|
+
type: item.type,
|
|
233
|
+
text: shown,
|
|
234
|
+
value: parts[item.type].value,
|
|
235
|
+
placeholder: placeholders[item.type],
|
|
236
|
+
min: bounds.min,
|
|
237
|
+
max: bounds.max,
|
|
238
|
+
valueText: parts[item.type].value === null ? messages.empty : shown,
|
|
239
|
+
editable: true,
|
|
240
|
+
};
|
|
241
|
+
});
|
|
242
|
+
const value = control.get();
|
|
243
|
+
const pattern = segments
|
|
244
|
+
.map((item) => (item.type === "literal" ? item.text : item.placeholder))
|
|
245
|
+
.join("");
|
|
246
|
+
return withOptional({
|
|
247
|
+
id,
|
|
248
|
+
mode: options.mode ?? "segmented",
|
|
249
|
+
segments,
|
|
250
|
+
text,
|
|
251
|
+
value,
|
|
252
|
+
validity: validityNow(),
|
|
253
|
+
focusedPart,
|
|
254
|
+
granularity: granularity(),
|
|
255
|
+
hourCycle: hourCycle(),
|
|
256
|
+
pattern,
|
|
257
|
+
required: options.required ?? false,
|
|
258
|
+
readOnly: options.readOnly ?? false,
|
|
259
|
+
disabled: options.disabled ?? false,
|
|
260
|
+
direction: getTextDirection(locale),
|
|
261
|
+
locale,
|
|
262
|
+
messages,
|
|
263
|
+
hidden: getHiddenInputs([
|
|
264
|
+
[
|
|
265
|
+
options.name,
|
|
266
|
+
value
|
|
267
|
+
? `${String(value.hour).padStart(2, "0")}:${String(value.minute).padStart(2, "0")}${granularity() === "second" ? `:${String(value.second).padStart(2, "0")}` : ""}`
|
|
268
|
+
: null,
|
|
269
|
+
],
|
|
270
|
+
]),
|
|
271
|
+
});
|
|
272
|
+
};
|
|
273
|
+
const refresh = () => {
|
|
274
|
+
const next = compute();
|
|
275
|
+
if (state && JSON.stringify(state) === JSON.stringify(next))
|
|
276
|
+
return;
|
|
277
|
+
state = next;
|
|
278
|
+
for (const listener of [...listeners])
|
|
279
|
+
listener(state);
|
|
280
|
+
};
|
|
281
|
+
state = compute();
|
|
282
|
+
const afterEdit = () => {
|
|
283
|
+
const next = derive();
|
|
284
|
+
if (!sameNullable(next, control.get()))
|
|
285
|
+
control.set(next);
|
|
286
|
+
refresh();
|
|
287
|
+
};
|
|
288
|
+
const moveFocus = (part, step) => {
|
|
289
|
+
const order = visibleOrder();
|
|
290
|
+
const target = order[order.indexOf(part) + step];
|
|
291
|
+
if (target)
|
|
292
|
+
focusedPart = target;
|
|
293
|
+
else
|
|
294
|
+
options.onFocusEdge?.(step);
|
|
295
|
+
};
|
|
296
|
+
const setSegment = (part, segment) => {
|
|
297
|
+
parts = { ...parts, [part]: segment };
|
|
298
|
+
};
|
|
299
|
+
let lastCommitted = control.get();
|
|
300
|
+
/** Match typed letters against the localized AM/PM labels (prefix, case-insensitive). */
|
|
301
|
+
const typeLetter = (key) => {
|
|
302
|
+
if (key.length !== 1 || !/\p{L}/u.test(key))
|
|
303
|
+
return false;
|
|
304
|
+
const names = getDayPeriodNames(localeOf());
|
|
305
|
+
const clean = (value) => fold(value).replace(/[.\s]/g, "");
|
|
306
|
+
const labels = [clean(names.am), clean(names.pm)];
|
|
307
|
+
const match = (buffer) => labels.flatMap((label, index) => (label.startsWith(buffer) ? [index] : []));
|
|
308
|
+
letters += clean(key);
|
|
309
|
+
let found = match(letters);
|
|
310
|
+
if (found.length === 0) {
|
|
311
|
+
letters = clean(key);
|
|
312
|
+
found = match(letters);
|
|
313
|
+
}
|
|
314
|
+
if (found.length === 0)
|
|
315
|
+
return true;
|
|
316
|
+
if (found.length === 1) {
|
|
317
|
+
setSegment("dayPeriod", segmentOf(found[0]));
|
|
318
|
+
letters = "";
|
|
319
|
+
afterEdit();
|
|
320
|
+
}
|
|
321
|
+
return true;
|
|
322
|
+
};
|
|
323
|
+
const controller = {
|
|
324
|
+
getState: () => state,
|
|
325
|
+
subscribe(listener) {
|
|
326
|
+
listeners.add(listener);
|
|
327
|
+
return () => {
|
|
328
|
+
listeners.delete(listener);
|
|
329
|
+
};
|
|
330
|
+
},
|
|
331
|
+
setOptions(next) {
|
|
332
|
+
options = { ...options, ...next };
|
|
333
|
+
control.sync({ value: options.value });
|
|
334
|
+
if (options.mode === "text") {
|
|
335
|
+
if (!sameNullable(textValue, control.get()))
|
|
336
|
+
syncParts(control.get());
|
|
337
|
+
}
|
|
338
|
+
else if (!sameNullable(derive(), control.get())) {
|
|
339
|
+
syncParts(control.get());
|
|
340
|
+
}
|
|
341
|
+
refresh();
|
|
342
|
+
},
|
|
343
|
+
focusPart(part) {
|
|
344
|
+
if (focusedPart !== part) {
|
|
345
|
+
focusedPart = part;
|
|
346
|
+
letters = "";
|
|
347
|
+
refresh();
|
|
348
|
+
}
|
|
349
|
+
},
|
|
350
|
+
settle() {
|
|
351
|
+
letters = "";
|
|
352
|
+
},
|
|
353
|
+
handleKeyDown(part, key, modifiers) {
|
|
354
|
+
if (options.disabled || modifiers.ctrl || modifiers.meta)
|
|
355
|
+
return false;
|
|
356
|
+
const rtl = state.direction === "rtl";
|
|
357
|
+
if (key === "ArrowLeft" || key === "ArrowRight") {
|
|
358
|
+
letters = "";
|
|
359
|
+
moveFocus(part, (key === "ArrowRight") !== rtl ? 1 : -1);
|
|
360
|
+
refresh();
|
|
361
|
+
return true;
|
|
362
|
+
}
|
|
363
|
+
if (key === "Enter") {
|
|
364
|
+
controller.commit();
|
|
365
|
+
return false;
|
|
366
|
+
}
|
|
367
|
+
if (options.readOnly)
|
|
368
|
+
return false;
|
|
369
|
+
if (part === "dayPeriod" && typeLetter(key))
|
|
370
|
+
return true;
|
|
371
|
+
const latin = toLatinDigits(key, localeOf());
|
|
372
|
+
if (part !== "dayPeriod" && /^\d$/.test(latin)) {
|
|
373
|
+
const result = typeDigit(def(part), parts[part], Number(latin));
|
|
374
|
+
setSegment(part, result.segment);
|
|
375
|
+
if (result.advance)
|
|
376
|
+
moveFocus(part, 1);
|
|
377
|
+
afterEdit();
|
|
378
|
+
return true;
|
|
379
|
+
}
|
|
380
|
+
const bounds = def(part);
|
|
381
|
+
if (key === "ArrowUp" || key === "ArrowDown" || key === "PageUp" || key === "PageDown") {
|
|
382
|
+
const direction = key === "ArrowUp" || key === "PageUp" ? 1 : -1;
|
|
383
|
+
const amount = part === "dayPeriod" ? 1 : key.startsWith("Page") ? bounds.pageStep : stepOf(part);
|
|
384
|
+
const p = placeholder();
|
|
385
|
+
const start = part === "hour"
|
|
386
|
+
? hourCycle() === "h12"
|
|
387
|
+
? p.hour % 12 || 12
|
|
388
|
+
: p.hour
|
|
389
|
+
: part === "minute"
|
|
390
|
+
? p.minute
|
|
391
|
+
: part === "second"
|
|
392
|
+
? p.second
|
|
393
|
+
: p.hour >= 12
|
|
394
|
+
? 1
|
|
395
|
+
: 0;
|
|
396
|
+
setSegment(part, stepSegment(bounds, parts[part], direction * amount, start));
|
|
397
|
+
afterEdit();
|
|
398
|
+
return true;
|
|
399
|
+
}
|
|
400
|
+
if (key === "Home" || key === "End") {
|
|
401
|
+
setSegment(part, segmentOf(key === "Home" ? bounds.min : bounds.max));
|
|
402
|
+
afterEdit();
|
|
403
|
+
return true;
|
|
404
|
+
}
|
|
405
|
+
if (key === "Backspace" || key === "Delete") {
|
|
406
|
+
setSegment(part, key === "Backspace" && part !== "dayPeriod" ? backspace(parts[part]) : emptySegment);
|
|
407
|
+
afterEdit();
|
|
408
|
+
return true;
|
|
409
|
+
}
|
|
410
|
+
return false;
|
|
411
|
+
},
|
|
412
|
+
paste(value) {
|
|
413
|
+
if (options.disabled || options.readOnly)
|
|
414
|
+
return false;
|
|
415
|
+
const result = parseText(value);
|
|
416
|
+
if ("time" in result) {
|
|
417
|
+
syncParts(result.time);
|
|
418
|
+
afterEdit();
|
|
419
|
+
return true;
|
|
420
|
+
}
|
|
421
|
+
options.onInvalidInput?.(value);
|
|
422
|
+
return false;
|
|
423
|
+
},
|
|
424
|
+
setText(value) {
|
|
425
|
+
text = value;
|
|
426
|
+
invalidText = false;
|
|
427
|
+
refresh();
|
|
428
|
+
},
|
|
429
|
+
commitText() {
|
|
430
|
+
const result = parseText(text);
|
|
431
|
+
if ("time" in result) {
|
|
432
|
+
invalidText = false;
|
|
433
|
+
control.set(result.time);
|
|
434
|
+
text = formatValue(result.time);
|
|
435
|
+
textValue = result.time;
|
|
436
|
+
refresh();
|
|
437
|
+
return true;
|
|
438
|
+
}
|
|
439
|
+
if (result.error === "empty") {
|
|
440
|
+
invalidText = false;
|
|
441
|
+
text = "";
|
|
442
|
+
textValue = null;
|
|
443
|
+
control.set(null);
|
|
444
|
+
refresh();
|
|
445
|
+
return true;
|
|
446
|
+
}
|
|
447
|
+
invalidText = true;
|
|
448
|
+
options.onInvalidInput?.(text);
|
|
449
|
+
refresh();
|
|
450
|
+
return false;
|
|
451
|
+
},
|
|
452
|
+
handleTextKeyDown(key) {
|
|
453
|
+
if (key === "Enter") {
|
|
454
|
+
controller.commitText();
|
|
455
|
+
controller.commit();
|
|
456
|
+
return false;
|
|
457
|
+
}
|
|
458
|
+
if (key === "Escape") {
|
|
459
|
+
const before = text;
|
|
460
|
+
const value = control.get();
|
|
461
|
+
text = value ? formatValue(value) : "";
|
|
462
|
+
invalidText = false;
|
|
463
|
+
refresh();
|
|
464
|
+
return before !== text;
|
|
465
|
+
}
|
|
466
|
+
return false;
|
|
467
|
+
},
|
|
468
|
+
commit() {
|
|
469
|
+
if (options.mode === "text")
|
|
470
|
+
controller.commitText();
|
|
471
|
+
const value = control.get();
|
|
472
|
+
if (value && state.validity === "valid" && !sameNullable(value, lastCommitted)) {
|
|
473
|
+
lastCommitted = value;
|
|
474
|
+
options.onValueCommit?.(value);
|
|
475
|
+
}
|
|
476
|
+
},
|
|
477
|
+
clear() {
|
|
478
|
+
if (options.disabled || options.readOnly)
|
|
479
|
+
return;
|
|
480
|
+
syncParts(null);
|
|
481
|
+
focusedPart = visibleOrder()[0];
|
|
482
|
+
control.set(null);
|
|
483
|
+
lastCommitted = null;
|
|
484
|
+
refresh();
|
|
485
|
+
},
|
|
486
|
+
reset() {
|
|
487
|
+
const value = options.defaultValue ?? null;
|
|
488
|
+
syncParts(value);
|
|
489
|
+
focusedPart = visibleOrder()[0];
|
|
490
|
+
control.set(value);
|
|
491
|
+
lastCommitted = value;
|
|
492
|
+
refresh();
|
|
493
|
+
},
|
|
494
|
+
getRootAttributes: () => ({
|
|
495
|
+
role: "group",
|
|
496
|
+
"data-chrono-time-input": true,
|
|
497
|
+
"data-mode": state.mode,
|
|
498
|
+
"data-disabled": state.disabled,
|
|
499
|
+
"data-readonly": state.readOnly,
|
|
500
|
+
"data-invalid": isTimeInvalid(state.validity),
|
|
501
|
+
"aria-disabled": state.disabled ? "true" : undefined,
|
|
502
|
+
dir: state.direction,
|
|
503
|
+
}),
|
|
504
|
+
getSegmentAttributes(segment) {
|
|
505
|
+
if (segment.type === "literal") {
|
|
506
|
+
return { "aria-hidden": "true", "data-chrono-literal": true };
|
|
507
|
+
}
|
|
508
|
+
return {
|
|
509
|
+
role: "spinbutton",
|
|
510
|
+
"aria-label": state.messages[segment.type],
|
|
511
|
+
"aria-valuenow": segment.value ?? undefined,
|
|
512
|
+
"aria-valuemin": segment.min,
|
|
513
|
+
"aria-valuemax": segment.max,
|
|
514
|
+
"aria-valuetext": segment.valueText,
|
|
515
|
+
"aria-readonly": state.readOnly ? "true" : undefined,
|
|
516
|
+
"aria-disabled": state.disabled ? "true" : undefined,
|
|
517
|
+
"aria-required": state.required ? "true" : undefined,
|
|
518
|
+
"aria-invalid": isTimeInvalid(state.validity) ? "true" : undefined,
|
|
519
|
+
tabindex: state.disabled ? undefined : segment.type === state.focusedPart ? 0 : -1,
|
|
520
|
+
inputmode: segment.type === "dayPeriod" ? "text" : "numeric",
|
|
521
|
+
"data-placeholder": segment.value === null,
|
|
522
|
+
"data-invalid": isTimeInvalid(state.validity),
|
|
523
|
+
"data-chrono-part": segment.type,
|
|
524
|
+
};
|
|
525
|
+
},
|
|
526
|
+
getTextFieldAttributes: () => ({
|
|
527
|
+
type: "text",
|
|
528
|
+
autocomplete: "off",
|
|
529
|
+
spellcheck: "false",
|
|
530
|
+
placeholder: state.pattern,
|
|
531
|
+
"aria-invalid": isTimeInvalid(state.validity) ? "true" : undefined,
|
|
532
|
+
"aria-required": state.required ? "true" : undefined,
|
|
533
|
+
"data-invalid": isTimeInvalid(state.validity),
|
|
534
|
+
disabled: state.disabled,
|
|
535
|
+
readonly: state.readOnly,
|
|
536
|
+
}),
|
|
537
|
+
getClearButtonAttributes: () => ({
|
|
538
|
+
type: "button",
|
|
539
|
+
"aria-label": state.messages.clear,
|
|
540
|
+
"data-disabled": state.disabled || state.validity === "empty",
|
|
541
|
+
}),
|
|
542
|
+
destroy() {
|
|
543
|
+
listeners.clear();
|
|
544
|
+
},
|
|
545
|
+
};
|
|
546
|
+
return controller;
|
|
547
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type Attributes, type HiddenInput, type PlainTime } from "../../foundation/index.js";
|
|
2
|
+
import { type TimeRangeInvalidReason } from "../selection/range.js";
|
|
3
|
+
import type { TimeRangeValue } from "../types.js";
|
|
4
|
+
import { type TimeInputController, type TimeInputOptions, type TimeInputState } from "./time-input-controller.js";
|
|
5
|
+
import { type TimeValidity } from "./validity.js";
|
|
6
|
+
export type TimeRangeInputOptions = Omit<TimeInputOptions, "value" | "defaultValue" | "onValueChange" | "onValueCommit" | "name"> & {
|
|
7
|
+
value?: TimeRangeValue;
|
|
8
|
+
defaultValue?: TimeRangeValue;
|
|
9
|
+
onValueChange?: (value: TimeRangeValue) => void;
|
|
10
|
+
onValueCommit?: (value: {
|
|
11
|
+
start: PlainTime;
|
|
12
|
+
end: PlainTime;
|
|
13
|
+
}) => void;
|
|
14
|
+
name?: string;
|
|
15
|
+
startName?: string;
|
|
16
|
+
endName?: string;
|
|
17
|
+
allowOvernight?: boolean;
|
|
18
|
+
/** Minutes. */
|
|
19
|
+
minDuration?: number;
|
|
20
|
+
maxDuration?: number;
|
|
21
|
+
};
|
|
22
|
+
export type TimeRangeValidity = TimeValidity | TimeRangeInvalidReason;
|
|
23
|
+
export type TimeRangeInputState = {
|
|
24
|
+
id: string;
|
|
25
|
+
value: TimeRangeValue;
|
|
26
|
+
validity: TimeRangeValidity;
|
|
27
|
+
start: TimeInputState;
|
|
28
|
+
end: TimeInputState;
|
|
29
|
+
/** Minutes, when the range is valid. */
|
|
30
|
+
duration: number | null;
|
|
31
|
+
crossesMidnight: boolean;
|
|
32
|
+
disabled: boolean;
|
|
33
|
+
readOnly: boolean;
|
|
34
|
+
hidden: HiddenInput[];
|
|
35
|
+
messages: TimeInputState["messages"];
|
|
36
|
+
};
|
|
37
|
+
export type TimeRangeInputController = {
|
|
38
|
+
getState(): TimeRangeInputState;
|
|
39
|
+
subscribe(listener: (state: TimeRangeInputState) => void): () => void;
|
|
40
|
+
setOptions(options: Partial<TimeRangeInputOptions>): void;
|
|
41
|
+
getStart(): TimeInputController;
|
|
42
|
+
getEnd(): TimeInputController;
|
|
43
|
+
commit(): void;
|
|
44
|
+
clear(): void;
|
|
45
|
+
reset(): void;
|
|
46
|
+
getRootAttributes(): Attributes;
|
|
47
|
+
destroy(): void;
|
|
48
|
+
};
|
|
49
|
+
export declare function createTimeRangeInputController(initial?: TimeRangeInputOptions): TimeRangeInputController;
|