@zealakit/chrono-react 0.0.0-stage → 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +624 -2
- package/dist/calendar/components.d.ts +346 -0
- package/dist/calendar/components.js +245 -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 +50 -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 +156 -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 +202 -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 +169 -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/merge-props.d.ts +9 -0
- package/dist/shared/merge-props.js +33 -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 +60 -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 +174 -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 +74 -0
- package/dist/vendor/core/calendar/controllers/calendar-controller.d.ts +251 -0
- package/dist/vendor/core/calendar/controllers/calendar-controller.js +1448 -0
- package/dist/vendor/core/calendar/controllers/drag-engine.d.ts +99 -0
- package/dist/vendor/core/calendar/controllers/drag-engine.js +382 -0
- package/dist/vendor/core/calendar/controllers/mini-calendar-controller.d.ts +66 -0
- package/dist/vendor/core/calendar/controllers/mini-calendar-controller.js +170 -0
- package/dist/vendor/core/calendar/controllers/shared.d.ts +29 -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 +71 -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 +107 -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 +156 -0
- package/dist/vendor/core/calendar/events/normalize.d.ts +33 -0
- package/dist/vendor/core/calendar/events/normalize.js +159 -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 +184 -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 +19 -0
- package/dist/vendor/core/calendar/interaction/auto-scroll.js +64 -0
- package/dist/vendor/core/calendar/interaction/drag-geometry.d.ts +52 -0
- package/dist/vendor/core/calendar/interaction/drag-geometry.js +125 -0
- package/dist/vendor/core/calendar/interaction/drag-keyboard.d.ts +38 -0
- package/dist/vendor/core/calendar/interaction/drag-keyboard.js +56 -0
- package/dist/vendor/core/calendar/interaction/drag-pointer.d.ts +23 -0
- package/dist/vendor/core/calendar/interaction/drag-pointer.js +203 -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/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 +119 -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 +83 -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 +61 -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 +207 -0
- package/dist/vendor/core/calendar/recurrence/expand.d.ts +27 -0
- package/dist/vendor/core/calendar/recurrence/expand.js +302 -0
- package/dist/vendor/core/calendar/recurrence/pack.d.ts +3 -0
- package/dist/vendor/core/calendar/recurrence/pack.js +251 -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 +288 -0
- package/dist/vendor/core/calendar/recurrence/series.d.ts +25 -0
- package/dist/vendor/core/calendar/recurrence/series.js +165 -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 +130 -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 +111 -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 +39 -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 +30 -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 +478 -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 +189 -0
- package/dist/vendor/core/date/input/parse.d.ts +22 -0
- package/dist/vendor/core/date/input/parse.js +84 -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 +726 -0
- package/dist/vendor/core/date/presets.d.ts +22 -0
- package/dist/vendor/core/date/presets.js +104 -0
- package/dist/vendor/core/date/selection/multiple.d.ts +7 -0
- package/dist/vendor/core/date/selection/multiple.js +32 -0
- package/dist/vendor/core/date/selection/range.d.ts +29 -0
- package/dist/vendor/core/date/selection/range.js +39 -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 +395 -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 +182 -0
- package/dist/vendor/core/datetime/input/parse.d.ts +20 -0
- package/dist/vendor/core/datetime/input/parse.js +59 -0
- package/dist/vendor/core/datetime/panel/controller.d.ts +64 -0
- package/dist/vendor/core/datetime/panel/controller.js +197 -0
- package/dist/vendor/core/datetime/panel/range-controller.d.ts +71 -0
- package/dist/vendor/core/datetime/panel/range-controller.js +217 -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 +54 -0
- package/dist/vendor/core/datetime/zone/resolve.d.ts +16 -0
- package/dist/vendor/core/datetime/zone/resolve.js +26 -0
- package/dist/vendor/core/foundation/a11y/announcer.d.ts +7 -0
- package/dist/vendor/core/foundation/a11y/announcer.js +36 -0
- package/dist/vendor/core/foundation/a11y/grid-navigation.d.ts +19 -0
- package/dist/vendor/core/foundation/a11y/grid-navigation.js +86 -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 +52 -0
- package/dist/vendor/core/foundation/constraints/availability-rules.d.ts +52 -0
- package/dist/vendor/core/foundation/constraints/availability-rules.js +66 -0
- package/dist/vendor/core/foundation/constraints/availability.d.ts +93 -0
- package/dist/vendor/core/foundation/constraints/availability.js +490 -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 +49 -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 +37 -0
- package/dist/vendor/core/foundation/locale/format.d.ts +31 -0
- package/dist/vendor/core/foundation/locale/format.js +79 -0
- package/dist/vendor/core/foundation/locale/hour-cycle.d.ts +12 -0
- package/dist/vendor/core/foundation/locale/hour-cycle.js +45 -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 +29 -0
- package/dist/vendor/core/foundation/locale/week-info.d.ts +5 -0
- package/dist/vendor/core/foundation/locale/week-info.js +61 -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 +56 -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/global-state.d.ts +1 -0
- package/dist/vendor/core/foundation/store/global-state.js +21 -0
- package/dist/vendor/core/foundation/store/ids.d.ts +2 -0
- package/dist/vendor/core/foundation/store/ids.js +7 -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/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 +112 -0
- package/dist/vendor/core/foundation/values/epoch-day.d.ts +15 -0
- package/dist/vendor/core/foundation/values/epoch-day.js +47 -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 +113 -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 +45 -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 +155 -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 +84 -0
- package/dist/vendor/core/time/input/time-input-controller.d.ts +102 -0
- package/dist/vendor/core/time/input/time-input-controller.js +562 -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 +185 -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 +839 -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 +78 -0
- package/dist/vendor/core/time/types.d.ts +11 -0
- package/dist/vendor/core/time/types.js +1 -0
- package/package.json +90 -4
|
@@ -0,0 +1,726 @@
|
|
|
1
|
+
import { addDays, addMonths, addYears, compare, compileAvailability, createControllable, createId, daysInMonth, defaultMessages, endOfMonth, formatDate, formatDateRange, getDateLabel, getDateStatus, getMonthNames, getMonths, getTextDirection, getWeekInfo, getWeekdayHeaders, isSameDay, mergeMessages, nextFocusedDate, plainDate, plainDateTime, plainTime, resolveLocale, startOfMonth, toIsoString, toPlainDate, today as readToday, } from "../../foundation/index.js";
|
|
2
|
+
import { isBlocked, pickRange, previewRange, } from "../selection/range.js";
|
|
3
|
+
import { addBetween, toggleDate } from "../selection/multiple.js";
|
|
4
|
+
const LEVELS = ["day", "month", "year"];
|
|
5
|
+
const NAV_KEYS = new Set([
|
|
6
|
+
"ArrowLeft",
|
|
7
|
+
"ArrowRight",
|
|
8
|
+
"ArrowUp",
|
|
9
|
+
"ArrowDown",
|
|
10
|
+
"Home",
|
|
11
|
+
"End",
|
|
12
|
+
"PageUp",
|
|
13
|
+
"PageDown",
|
|
14
|
+
]);
|
|
15
|
+
const sameMonth = (a, b) => a.year === b.year && a.month === b.month;
|
|
16
|
+
const monthOf = (date) => ({
|
|
17
|
+
year: date.year,
|
|
18
|
+
month: date.month,
|
|
19
|
+
});
|
|
20
|
+
const sameNullable = (a, b) => a === b || (a !== null && b !== null && isSameDay(a, b));
|
|
21
|
+
const sameRangeValue = (a, b) => a === b ||
|
|
22
|
+
(a !== null &&
|
|
23
|
+
b !== null &&
|
|
24
|
+
sameNullable(a.start, b.start) &&
|
|
25
|
+
sameNullable(a.end, b.end));
|
|
26
|
+
const sameMulti = (a, b) => a.length === b.length &&
|
|
27
|
+
a.every((date, index) => isSameDay(date, b[index]));
|
|
28
|
+
const isDraft = (value) => value !== null && value.start !== null && value.end === null;
|
|
29
|
+
function createPanel(kind, initial) {
|
|
30
|
+
let options = initial;
|
|
31
|
+
const id = options.id ?? createId("chrono-date-panel");
|
|
32
|
+
const titleId = `${id}-title`;
|
|
33
|
+
const todayNow = () => readToday(options.timeZone, options.now);
|
|
34
|
+
const bound = (value) => value === undefined ? undefined : toPlainDate(value, options.timeZone);
|
|
35
|
+
const availabilityOf = () => options.availability === undefined
|
|
36
|
+
? undefined
|
|
37
|
+
: compileAvailability(options.availability, {
|
|
38
|
+
timeZone: options.timeZone,
|
|
39
|
+
now: options.now,
|
|
40
|
+
});
|
|
41
|
+
const dayReason = (date) => {
|
|
42
|
+
const availability = availabilityOf();
|
|
43
|
+
if (!availability) {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
return availability
|
|
47
|
+
.getIntervals(plainDateTime(date, plainTime(0, 0)), plainDateTime(addDays(date, 1), plainTime(0, 0)))
|
|
48
|
+
.find((piece) => piece.status === "unavailable" && piece.rules.length > 0)
|
|
49
|
+
?.rules[0]?.reason;
|
|
50
|
+
};
|
|
51
|
+
const constraints = () => ({
|
|
52
|
+
min: bound(options.min),
|
|
53
|
+
max: bound(options.max),
|
|
54
|
+
isDateDisabled: options.isDateDisabled,
|
|
55
|
+
isDateUnavailable: (date) => (options.isDateUnavailable?.(date) ?? false) ||
|
|
56
|
+
availabilityOf()?.getDayStatus(date) === "unavailable",
|
|
57
|
+
});
|
|
58
|
+
const pickConstraints = () => ({
|
|
59
|
+
...constraints(),
|
|
60
|
+
minDays: options.minDays,
|
|
61
|
+
maxDays: options.maxDays,
|
|
62
|
+
allowUnavailableInside: options.allowUnavailableInside,
|
|
63
|
+
allowDisabledInside: options.allowDisabledInside,
|
|
64
|
+
});
|
|
65
|
+
const monthCount = () => Math.max(1, options.months ?? 1);
|
|
66
|
+
const levelBounds = () => [
|
|
67
|
+
LEVELS.indexOf(options.minLevel ?? "day"),
|
|
68
|
+
LEVELS.indexOf(options.maxLevel ?? "year"),
|
|
69
|
+
];
|
|
70
|
+
const emptyValue = () => kind === "single" ? null : kind === "range" ? null : [];
|
|
71
|
+
const valueControl = createControllable({
|
|
72
|
+
value: options.value,
|
|
73
|
+
defaultValue: options.defaultValue ?? emptyValue(),
|
|
74
|
+
onChange: (value) => options.onValueChange?.(value),
|
|
75
|
+
equals: (a, b) => kind === "single"
|
|
76
|
+
? sameNullable(a, b)
|
|
77
|
+
: kind === "range"
|
|
78
|
+
? sameRangeValue(a, b)
|
|
79
|
+
: sameMulti(a, b),
|
|
80
|
+
});
|
|
81
|
+
/** The date the panel starts on: the value, else today, else the first selectable day. */
|
|
82
|
+
const anchorOf = (value) => kind === "single"
|
|
83
|
+
? (value ?? undefined)
|
|
84
|
+
: kind === "range"
|
|
85
|
+
? (value?.start ?? undefined)
|
|
86
|
+
: value[0];
|
|
87
|
+
const startMonth = () => {
|
|
88
|
+
const anchor = anchorOf(valueControl.get());
|
|
89
|
+
return monthOf(anchor ?? todayNow());
|
|
90
|
+
};
|
|
91
|
+
const monthControl = createControllable({
|
|
92
|
+
value: options.visibleMonth,
|
|
93
|
+
defaultValue: options.defaultVisibleMonth ?? startMonth(),
|
|
94
|
+
onChange: (month) => options.onVisibleMonthChange?.(month),
|
|
95
|
+
equals: sameMonth,
|
|
96
|
+
});
|
|
97
|
+
const levelControl = createControllable({
|
|
98
|
+
value: options.level,
|
|
99
|
+
defaultValue: options.defaultLevel ?? "day",
|
|
100
|
+
onChange: (level) => options.onLevelChange?.(level),
|
|
101
|
+
});
|
|
102
|
+
const firstSelectable = () => {
|
|
103
|
+
const month = monthControl.get();
|
|
104
|
+
const first = plainDate(month.year, month.month, 1);
|
|
105
|
+
const c = constraints();
|
|
106
|
+
for (let offset = 0; offset < daysInMonth(month.year, month.month); offset += 1) {
|
|
107
|
+
const day = plainDate(month.year, month.month, 1 + offset);
|
|
108
|
+
if (getDateStatus(day, c).selectable)
|
|
109
|
+
return day;
|
|
110
|
+
}
|
|
111
|
+
return first;
|
|
112
|
+
};
|
|
113
|
+
let focusedDate = (() => {
|
|
114
|
+
const anchor = anchorOf(valueControl.get());
|
|
115
|
+
if (anchor)
|
|
116
|
+
return anchor;
|
|
117
|
+
const today = todayNow();
|
|
118
|
+
const month = monthControl.get();
|
|
119
|
+
return sameMonth(monthOf(today), month) &&
|
|
120
|
+
getDateStatus(today, constraints()).selectable
|
|
121
|
+
? today
|
|
122
|
+
: firstSelectable();
|
|
123
|
+
})();
|
|
124
|
+
let hoverDate = null;
|
|
125
|
+
let beforeDraft = null;
|
|
126
|
+
let lastToggled = null;
|
|
127
|
+
let lastPreviewKey = "";
|
|
128
|
+
let lastAnchorKey = anchorOf(valueControl.get())
|
|
129
|
+
? toIsoString(anchorOf(valueControl.get()))
|
|
130
|
+
: "";
|
|
131
|
+
let state;
|
|
132
|
+
const listeners = new Set();
|
|
133
|
+
const blockedCache = new Map();
|
|
134
|
+
const fix = () => {
|
|
135
|
+
const level = levelControl.get();
|
|
136
|
+
const month = monthControl.get();
|
|
137
|
+
if (level === "day") {
|
|
138
|
+
const last = addMonths(plainDate(month.year, month.month, 1), monthCount() - 1);
|
|
139
|
+
const first = plainDate(month.year, month.month, 1);
|
|
140
|
+
if (compare(focusedDate, first) < 0 ||
|
|
141
|
+
compare(focusedDate, endOfMonth(last)) > 0) {
|
|
142
|
+
focusedDate = plainDate(month.year, month.month, Math.min(focusedDate.day, daysInMonth(month.year, month.month)));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
else if (focusedDate.year !== month.year && level === "month") {
|
|
146
|
+
focusedDate = plainDate(month.year, focusedDate.month, 1);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
const compute = () => {
|
|
150
|
+
fix();
|
|
151
|
+
const locale = options.locale === undefined ? undefined : resolveLocale(options.locale);
|
|
152
|
+
const weekInfo = getWeekInfo(locale);
|
|
153
|
+
const weekStartsOn = options.weekStartsOn ?? weekInfo.firstDay;
|
|
154
|
+
const messages = mergeMessages(defaultMessages, options.messages);
|
|
155
|
+
const today = todayNow();
|
|
156
|
+
const c = constraints();
|
|
157
|
+
const pc = pickConstraints();
|
|
158
|
+
const level = levelControl.get();
|
|
159
|
+
const month = monthControl.get();
|
|
160
|
+
const count = monthCount();
|
|
161
|
+
const value = valueControl.get();
|
|
162
|
+
const draft = kind === "range" && isDraft(value);
|
|
163
|
+
const rangeValue = kind === "range" ? value : null;
|
|
164
|
+
const multi = kind === "multi" ? value : [];
|
|
165
|
+
const multiKeys = new Set(multi.map(toIsoString));
|
|
166
|
+
const start = rangeValue?.start ?? null;
|
|
167
|
+
const end = rangeValue?.end ?? null;
|
|
168
|
+
let preview = null;
|
|
169
|
+
if (draft && start) {
|
|
170
|
+
preview = previewRange(start, hoverDate ?? focusedDate, pc);
|
|
171
|
+
}
|
|
172
|
+
const blockedFor = (day) => {
|
|
173
|
+
if (kind === "multi") {
|
|
174
|
+
return (options.maxSelected !== undefined &&
|
|
175
|
+
multi.length >= options.maxSelected &&
|
|
176
|
+
!multiKeys.has(toIsoString(day)));
|
|
177
|
+
}
|
|
178
|
+
if (!draft || !start)
|
|
179
|
+
return false;
|
|
180
|
+
const cacheKey = `${toIsoString(start)}|${toIsoString(day)}`;
|
|
181
|
+
let blocked = blockedCache.get(cacheKey);
|
|
182
|
+
if (blocked === undefined) {
|
|
183
|
+
blocked = isBlocked(start, day, pc);
|
|
184
|
+
blockedCache.set(cacheKey, blocked);
|
|
185
|
+
}
|
|
186
|
+
return blocked;
|
|
187
|
+
};
|
|
188
|
+
const first = plainDate(month.year, month.month, 1);
|
|
189
|
+
const grids = getMonths(month, count, {
|
|
190
|
+
weekStartsOn,
|
|
191
|
+
weekInfo,
|
|
192
|
+
today,
|
|
193
|
+
weekNumbers: options.weekNumbers || undefined,
|
|
194
|
+
fixedWeeks: count > 1,
|
|
195
|
+
});
|
|
196
|
+
const names = getMonthNames(locale, "long");
|
|
197
|
+
const months = level === "day"
|
|
198
|
+
? grids.map((grid) => ({
|
|
199
|
+
key: `${grid.year}-${String(grid.month).padStart(2, "0")}`,
|
|
200
|
+
title: `${names[grid.month - 1]} ${grid.year}`,
|
|
201
|
+
weeks: grid.weeks.map((week) => ({
|
|
202
|
+
weekNumber: week.weekNumber,
|
|
203
|
+
days: week.days.map((day) => {
|
|
204
|
+
const status = getDateStatus(day.date, c);
|
|
205
|
+
const hidden = count > 1 && day.outsideMonth;
|
|
206
|
+
const iso = toIsoString(day.date);
|
|
207
|
+
const isStart = start !== null && isSameDay(day.date, start);
|
|
208
|
+
const isEnd = end !== null && isSameDay(day.date, end);
|
|
209
|
+
const previewing = preview !== null &&
|
|
210
|
+
compare(day.date, preview.start) >= 0 &&
|
|
211
|
+
compare(day.date, preview.end) <= 0;
|
|
212
|
+
const selected = kind === "single"
|
|
213
|
+
? value !== null && isSameDay(day.date, value)
|
|
214
|
+
: kind === "multi"
|
|
215
|
+
? multiKeys.has(iso)
|
|
216
|
+
: isStart ||
|
|
217
|
+
isEnd ||
|
|
218
|
+
(start !== null &&
|
|
219
|
+
end !== null &&
|
|
220
|
+
compare(day.date, start) > 0 &&
|
|
221
|
+
compare(day.date, end) < 0);
|
|
222
|
+
return {
|
|
223
|
+
date: day.date,
|
|
224
|
+
key: iso,
|
|
225
|
+
hidden,
|
|
226
|
+
outsideMonth: day.outsideMonth,
|
|
227
|
+
today: day.today,
|
|
228
|
+
weekend: day.weekend,
|
|
229
|
+
selected,
|
|
230
|
+
disabled: status.disabled,
|
|
231
|
+
unavailable: status.unavailable,
|
|
232
|
+
partiallyAvailable: !status.unavailable &&
|
|
233
|
+
availabilityOf()?.getDayStatus(day.date) === "partial",
|
|
234
|
+
blocked: !hidden && blockedFor(day.date),
|
|
235
|
+
focused: !hidden && isSameDay(day.date, focusedDate),
|
|
236
|
+
rangeStart: isStart,
|
|
237
|
+
rangeEnd: isEnd,
|
|
238
|
+
inRange: start !== null &&
|
|
239
|
+
end !== null &&
|
|
240
|
+
compare(day.date, start) > 0 &&
|
|
241
|
+
compare(day.date, end) < 0,
|
|
242
|
+
preview: previewing,
|
|
243
|
+
};
|
|
244
|
+
}),
|
|
245
|
+
})),
|
|
246
|
+
}))
|
|
247
|
+
: [];
|
|
248
|
+
const minDate = c.min;
|
|
249
|
+
const maxDate = c.max;
|
|
250
|
+
const monthCells = () => Array.from({ length: 12 }, (_, index) => {
|
|
251
|
+
const m = index + 1;
|
|
252
|
+
const key = `${month.year}-${String(m).padStart(2, "0")}`;
|
|
253
|
+
const monthStart = plainDate(month.year, m, 1);
|
|
254
|
+
const anchor = anchorOf(value);
|
|
255
|
+
return {
|
|
256
|
+
key,
|
|
257
|
+
year: month.year,
|
|
258
|
+
month: m,
|
|
259
|
+
label: formatDate(monthStart, locale, {
|
|
260
|
+
month: "long",
|
|
261
|
+
year: "numeric",
|
|
262
|
+
}),
|
|
263
|
+
text: names[index],
|
|
264
|
+
selected: anchor !== undefined &&
|
|
265
|
+
anchor.year === month.year &&
|
|
266
|
+
anchor.month === m,
|
|
267
|
+
disabled: (minDate !== undefined &&
|
|
268
|
+
compare(endOfMonth(monthStart), minDate) < 0) ||
|
|
269
|
+
(maxDate !== undefined && compare(monthStart, maxDate) > 0),
|
|
270
|
+
focused: focusedDate.year === month.year && focusedDate.month === m,
|
|
271
|
+
current: today.year === month.year && today.month === m,
|
|
272
|
+
outside: false,
|
|
273
|
+
};
|
|
274
|
+
});
|
|
275
|
+
const decade = Math.floor(month.year / 10) * 10;
|
|
276
|
+
const yearCells = () => Array.from({ length: 12 }, (_, index) => {
|
|
277
|
+
const year = decade - 1 + index;
|
|
278
|
+
const anchor = anchorOf(value);
|
|
279
|
+
return {
|
|
280
|
+
key: String(year),
|
|
281
|
+
year,
|
|
282
|
+
month: 1,
|
|
283
|
+
label: String(year),
|
|
284
|
+
text: String(year),
|
|
285
|
+
selected: anchor !== undefined && anchor.year === year,
|
|
286
|
+
disabled: year < 1 ||
|
|
287
|
+
year > 9999 ||
|
|
288
|
+
(minDate !== undefined && year < minDate.year) ||
|
|
289
|
+
(maxDate !== undefined && year > maxDate.year),
|
|
290
|
+
focused: focusedDate.year === year,
|
|
291
|
+
current: today.year === year,
|
|
292
|
+
outside: year < decade || year > decade + 9,
|
|
293
|
+
};
|
|
294
|
+
}).filter((cell) => cell.year >= 1 && cell.year <= 9999);
|
|
295
|
+
const lastMonth = addMonths(first, count - 1);
|
|
296
|
+
const title = level === "day"
|
|
297
|
+
? count === 1
|
|
298
|
+
? formatDate(first, locale, { month: "long", year: "numeric" })
|
|
299
|
+
: formatDateRange({ start: first, end: endOfMonth(lastMonth) }, locale, {
|
|
300
|
+
month: "long",
|
|
301
|
+
year: "numeric",
|
|
302
|
+
})
|
|
303
|
+
: level === "month"
|
|
304
|
+
? String(month.year)
|
|
305
|
+
: `${Math.max(decade, 1)} – ${Math.min(decade + 9, 9999)}`;
|
|
306
|
+
const step = options.pageBy === "visible" ? count : 1;
|
|
307
|
+
const canGoPrev = level === "day"
|
|
308
|
+
? minDate === undefined || compare(first, minDate) > 0
|
|
309
|
+
: level === "month"
|
|
310
|
+
? minDate === undefined || minDate.year < month.year
|
|
311
|
+
: minDate === undefined || minDate.year < decade;
|
|
312
|
+
const canGoNext = level === "day"
|
|
313
|
+
? maxDate === undefined || compare(endOfMonth(lastMonth), maxDate) < 0
|
|
314
|
+
: level === "month"
|
|
315
|
+
? maxDate === undefined || maxDate.year > month.year
|
|
316
|
+
: maxDate === undefined || maxDate.year > decade + 9;
|
|
317
|
+
void step;
|
|
318
|
+
const [minIndex, maxIndex] = levelBounds();
|
|
319
|
+
const countValue = kind === "multi"
|
|
320
|
+
? multi.length
|
|
321
|
+
: start !== null && end !== null
|
|
322
|
+
? Math.round((Date.UTC(end.year, end.month - 1, end.day) -
|
|
323
|
+
Date.UTC(start.year, start.month - 1, start.day)) /
|
|
324
|
+
86400000) + 1
|
|
325
|
+
: kind === "single" && value !== null
|
|
326
|
+
? 1
|
|
327
|
+
: 0;
|
|
328
|
+
return {
|
|
329
|
+
id,
|
|
330
|
+
kind,
|
|
331
|
+
level,
|
|
332
|
+
value: value,
|
|
333
|
+
draft,
|
|
334
|
+
preview,
|
|
335
|
+
visibleMonth: month,
|
|
336
|
+
title,
|
|
337
|
+
today,
|
|
338
|
+
focusedDate,
|
|
339
|
+
weekdays: getWeekdayHeaders(locale, { weekStartsOn }),
|
|
340
|
+
weekNumbers: Boolean(options.weekNumbers),
|
|
341
|
+
months,
|
|
342
|
+
cells: level === "month" ? monthCells() : level === "year" ? yearCells() : [],
|
|
343
|
+
canGoPrev,
|
|
344
|
+
canGoNext,
|
|
345
|
+
canGoUp: LEVELS.indexOf(level) < maxIndex && LEVELS.indexOf(level) >= minIndex,
|
|
346
|
+
readOnly: options.readOnly ?? false,
|
|
347
|
+
disabled: options.disabled ?? false,
|
|
348
|
+
autoFocus: options.autoFocus ?? false,
|
|
349
|
+
direction: getTextDirection(locale),
|
|
350
|
+
locale,
|
|
351
|
+
messages,
|
|
352
|
+
count: countValue,
|
|
353
|
+
};
|
|
354
|
+
};
|
|
355
|
+
const refresh = () => {
|
|
356
|
+
const next = compute();
|
|
357
|
+
if (state && JSON.stringify(state) === JSON.stringify(next))
|
|
358
|
+
return;
|
|
359
|
+
state = next;
|
|
360
|
+
if (kind === "range") {
|
|
361
|
+
const key = next.preview
|
|
362
|
+
? `${toIsoString(next.preview.start)}|${toIsoString(next.preview.end)}`
|
|
363
|
+
: "";
|
|
364
|
+
if (key !== lastPreviewKey) {
|
|
365
|
+
lastPreviewKey = key;
|
|
366
|
+
options.onRangePreviewChange?.(next.preview);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
for (const listener of [...listeners])
|
|
370
|
+
listener(state);
|
|
371
|
+
};
|
|
372
|
+
state = compute();
|
|
373
|
+
/** Scroll the visible months so `date` is shown. */
|
|
374
|
+
const showDate = (date) => {
|
|
375
|
+
const month = monthControl.get();
|
|
376
|
+
const first = plainDate(month.year, month.month, 1);
|
|
377
|
+
const last = addMonths(first, monthCount() - 1);
|
|
378
|
+
if (compare(date, first) < 0) {
|
|
379
|
+
monthControl.set(monthOf(date));
|
|
380
|
+
}
|
|
381
|
+
else if (compare(date, endOfMonth(last)) > 0) {
|
|
382
|
+
monthControl.set(monthOf(addMonths(startOfMonth(date), -(monthCount() - 1))));
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
const setValue = (value) => {
|
|
386
|
+
blockedCache.clear();
|
|
387
|
+
valueControl.set(value);
|
|
388
|
+
};
|
|
389
|
+
const setLevelClamped = (level) => {
|
|
390
|
+
const [min, max] = levelBounds();
|
|
391
|
+
const index = Math.min(max, Math.max(min, LEVELS.indexOf(level)));
|
|
392
|
+
levelControl.set(LEVELS[index]);
|
|
393
|
+
};
|
|
394
|
+
const controller = {
|
|
395
|
+
getState: () => state,
|
|
396
|
+
getValue: () => valueControl.get(),
|
|
397
|
+
subscribe(listener) {
|
|
398
|
+
listeners.add(listener);
|
|
399
|
+
return () => {
|
|
400
|
+
listeners.delete(listener);
|
|
401
|
+
};
|
|
402
|
+
},
|
|
403
|
+
setOptions(next) {
|
|
404
|
+
options = { ...options, ...next };
|
|
405
|
+
const before = anchorOf(valueControl.get());
|
|
406
|
+
valueControl.sync({ value: options.value });
|
|
407
|
+
monthControl.sync({ value: options.visibleMonth });
|
|
408
|
+
levelControl.sync({ value: options.level });
|
|
409
|
+
blockedCache.clear();
|
|
410
|
+
const anchor = anchorOf(valueControl.get());
|
|
411
|
+
const key = anchor ? toIsoString(anchor) : "";
|
|
412
|
+
if (options.followValue !== false &&
|
|
413
|
+
anchor &&
|
|
414
|
+
key !== lastAnchorKey &&
|
|
415
|
+
!(before && isSameDay(before, anchor) && lastAnchorKey === key)) {
|
|
416
|
+
showDate(anchor);
|
|
417
|
+
if (levelControl.get() === "day")
|
|
418
|
+
focusedDate = anchor;
|
|
419
|
+
}
|
|
420
|
+
lastAnchorKey = key;
|
|
421
|
+
refresh();
|
|
422
|
+
},
|
|
423
|
+
pick(date, _source) {
|
|
424
|
+
if (options.disabled)
|
|
425
|
+
return;
|
|
426
|
+
const level = levelControl.get();
|
|
427
|
+
focusedDate = date;
|
|
428
|
+
if (level !== "day") {
|
|
429
|
+
// Drill down: a month goes to the day level of that month, a year to its months.
|
|
430
|
+
monthControl.set(level === "month"
|
|
431
|
+
? monthOf(date)
|
|
432
|
+
: { year: date.year, month: monthControl.get().month });
|
|
433
|
+
setLevelClamped(LEVELS[LEVELS.indexOf(level) - 1]);
|
|
434
|
+
refresh();
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
showDate(date);
|
|
438
|
+
if (options.readOnly) {
|
|
439
|
+
refresh();
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
if (kind === "single") {
|
|
443
|
+
if (getDateStatus(date, constraints()).selectable) {
|
|
444
|
+
setValue(date);
|
|
445
|
+
options.onValueCommit?.(date);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
else if (kind === "range") {
|
|
449
|
+
const current = valueControl.get();
|
|
450
|
+
const result = pickRange(current, date, pickConstraints());
|
|
451
|
+
if (result.kind === "draft") {
|
|
452
|
+
beforeDraft = current?.start && current.end ? current : null;
|
|
453
|
+
setValue(result.value);
|
|
454
|
+
}
|
|
455
|
+
else if (result.kind === "complete") {
|
|
456
|
+
setValue(result.value);
|
|
457
|
+
options.onValueCommit?.(result.value);
|
|
458
|
+
}
|
|
459
|
+
else {
|
|
460
|
+
options.onInvalidRange?.(result.reason);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
else {
|
|
464
|
+
const current = valueControl.get();
|
|
465
|
+
const next = toggleDate(current, date, constraints(), options.maxSelected);
|
|
466
|
+
lastToggled = date;
|
|
467
|
+
if (next !== current)
|
|
468
|
+
setValue(next);
|
|
469
|
+
}
|
|
470
|
+
refresh();
|
|
471
|
+
},
|
|
472
|
+
extendTo(date) {
|
|
473
|
+
if (kind !== "multi" || options.disabled || options.readOnly)
|
|
474
|
+
return;
|
|
475
|
+
const current = valueControl.get();
|
|
476
|
+
const next = addBetween(current, lastToggled ?? focusedDate, date, constraints(), options.maxSelected);
|
|
477
|
+
lastToggled = date;
|
|
478
|
+
focusedDate = date;
|
|
479
|
+
if (!sameMulti(current, next))
|
|
480
|
+
setValue(next);
|
|
481
|
+
refresh();
|
|
482
|
+
},
|
|
483
|
+
setPreview(date) {
|
|
484
|
+
hoverDate = date;
|
|
485
|
+
refresh();
|
|
486
|
+
},
|
|
487
|
+
cancelDraft() {
|
|
488
|
+
if (kind !== "range" || !isDraft(valueControl.get()))
|
|
489
|
+
return;
|
|
490
|
+
hoverDate = null;
|
|
491
|
+
setValue(beforeDraft);
|
|
492
|
+
beforeDraft = null;
|
|
493
|
+
refresh();
|
|
494
|
+
},
|
|
495
|
+
clear() {
|
|
496
|
+
if (options.disabled || options.readOnly)
|
|
497
|
+
return;
|
|
498
|
+
hoverDate = null;
|
|
499
|
+
setValue(emptyValue());
|
|
500
|
+
refresh();
|
|
501
|
+
},
|
|
502
|
+
commit() {
|
|
503
|
+
if (kind === "multi") {
|
|
504
|
+
options.onValueCommit?.(valueControl.get());
|
|
505
|
+
}
|
|
506
|
+
},
|
|
507
|
+
today() {
|
|
508
|
+
const today = todayNow();
|
|
509
|
+
focusedDate = today;
|
|
510
|
+
monthControl.set(monthOf(today));
|
|
511
|
+
setLevelClamped("day");
|
|
512
|
+
if (kind === "single" &&
|
|
513
|
+
options.selectToday &&
|
|
514
|
+
!options.readOnly &&
|
|
515
|
+
getDateStatus(today, constraints()).selectable) {
|
|
516
|
+
setValue(today);
|
|
517
|
+
options.onValueCommit?.(today);
|
|
518
|
+
}
|
|
519
|
+
refresh();
|
|
520
|
+
},
|
|
521
|
+
prev() {
|
|
522
|
+
page(-1);
|
|
523
|
+
},
|
|
524
|
+
next() {
|
|
525
|
+
page(1);
|
|
526
|
+
},
|
|
527
|
+
setLevel(level) {
|
|
528
|
+
setLevelClamped(level);
|
|
529
|
+
refresh();
|
|
530
|
+
},
|
|
531
|
+
focusDate(date) {
|
|
532
|
+
focusedDate = date;
|
|
533
|
+
const level = levelControl.get();
|
|
534
|
+
if (level === "day") {
|
|
535
|
+
showDate(date);
|
|
536
|
+
}
|
|
537
|
+
else {
|
|
538
|
+
const month = monthControl.get();
|
|
539
|
+
if (level === "month" && date.year !== month.year) {
|
|
540
|
+
monthControl.set({ year: date.year, month: month.month });
|
|
541
|
+
}
|
|
542
|
+
if (level === "year") {
|
|
543
|
+
monthControl.set({ year: date.year, month: month.month });
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
refresh();
|
|
547
|
+
},
|
|
548
|
+
handleKeyDown(key, modifiers) {
|
|
549
|
+
if (options.disabled)
|
|
550
|
+
return false;
|
|
551
|
+
const level = levelControl.get();
|
|
552
|
+
if (modifiers.ctrl || modifiers.meta) {
|
|
553
|
+
if (key === "ArrowUp" && state.canGoUp) {
|
|
554
|
+
setLevelClamped(LEVELS[LEVELS.indexOf(level) + 1]);
|
|
555
|
+
refresh();
|
|
556
|
+
return true;
|
|
557
|
+
}
|
|
558
|
+
return false;
|
|
559
|
+
}
|
|
560
|
+
if (key === "Enter" || key === " ") {
|
|
561
|
+
if (kind === "multi" && modifiers.shift && level === "day") {
|
|
562
|
+
controller.extendTo(state.focusedDate);
|
|
563
|
+
}
|
|
564
|
+
else {
|
|
565
|
+
controller.pick(state.focusedDate, "keyboard");
|
|
566
|
+
}
|
|
567
|
+
return true;
|
|
568
|
+
}
|
|
569
|
+
if (key === "Escape") {
|
|
570
|
+
if (kind === "range" && state.draft) {
|
|
571
|
+
controller.cancelDraft();
|
|
572
|
+
return true;
|
|
573
|
+
}
|
|
574
|
+
return false;
|
|
575
|
+
}
|
|
576
|
+
if (!NAV_KEYS.has(key))
|
|
577
|
+
return false;
|
|
578
|
+
const weekInfo = getWeekInfo(state.locale);
|
|
579
|
+
const c = constraints();
|
|
580
|
+
const moved = nextFocusedDate(state.focusedDate, key, { shift: modifiers.shift }, {
|
|
581
|
+
weekStartsOn: options.weekStartsOn ?? weekInfo.firstDay,
|
|
582
|
+
direction: state.direction,
|
|
583
|
+
min: c.min,
|
|
584
|
+
max: c.max,
|
|
585
|
+
level,
|
|
586
|
+
});
|
|
587
|
+
hoverDate = null;
|
|
588
|
+
controller.focusDate(moved);
|
|
589
|
+
return true;
|
|
590
|
+
},
|
|
591
|
+
getRootAttributes: () => ({
|
|
592
|
+
role: "group",
|
|
593
|
+
"data-chrono-date-panel": kind === "single" ? true : kind,
|
|
594
|
+
"data-level": state.level,
|
|
595
|
+
"data-disabled": state.disabled,
|
|
596
|
+
"data-readonly": state.readOnly,
|
|
597
|
+
dir: state.direction,
|
|
598
|
+
}),
|
|
599
|
+
getTitleAttributes: () => ({ id: titleId, "aria-live": "polite" }),
|
|
600
|
+
getLevelButtonAttributes: () => ({
|
|
601
|
+
type: "button",
|
|
602
|
+
"aria-label": state.level === "day"
|
|
603
|
+
? state.messages.chooseMonth
|
|
604
|
+
: state.messages.chooseYear,
|
|
605
|
+
"aria-disabled": state.canGoUp ? undefined : "true",
|
|
606
|
+
"data-disabled": !state.canGoUp,
|
|
607
|
+
"data-level": state.level,
|
|
608
|
+
}),
|
|
609
|
+
getNavAttributes: (kind) => {
|
|
610
|
+
const disabled = kind === "prev" ? !state.canGoPrev : !state.canGoNext;
|
|
611
|
+
return {
|
|
612
|
+
type: "button",
|
|
613
|
+
"aria-label": kind === "prev" ? state.messages.previous : state.messages.next,
|
|
614
|
+
"aria-disabled": disabled ? "true" : undefined,
|
|
615
|
+
"data-disabled": disabled,
|
|
616
|
+
};
|
|
617
|
+
},
|
|
618
|
+
getTodayButtonAttributes: () => ({
|
|
619
|
+
type: "button",
|
|
620
|
+
"aria-label": state.messages.goToToday,
|
|
621
|
+
"data-disabled": state.disabled,
|
|
622
|
+
}),
|
|
623
|
+
getGridAttributes: () => ({
|
|
624
|
+
role: "grid",
|
|
625
|
+
"aria-labelledby": titleId,
|
|
626
|
+
"aria-multiselectable": kind === "single" ? undefined : "true",
|
|
627
|
+
"aria-readonly": state.readOnly ? "true" : undefined,
|
|
628
|
+
}),
|
|
629
|
+
getColumnHeaderAttributes: (header) => ({
|
|
630
|
+
role: "columnheader",
|
|
631
|
+
abbr: header.long,
|
|
632
|
+
"data-weekend": header.weekend,
|
|
633
|
+
}),
|
|
634
|
+
getWeekNumberAttributes: (weekNumber) => ({
|
|
635
|
+
role: "rowheader",
|
|
636
|
+
"aria-label": state.messages.weekNumber.replace("{number}", String(weekNumber)),
|
|
637
|
+
}),
|
|
638
|
+
getCellAttributes(day) {
|
|
639
|
+
if (day.hidden) {
|
|
640
|
+
return { role: "gridcell", "aria-hidden": "true", "data-hidden": true };
|
|
641
|
+
}
|
|
642
|
+
const unselectable = day.disabled || day.unavailable || day.blocked;
|
|
643
|
+
return {
|
|
644
|
+
role: "gridcell",
|
|
645
|
+
"aria-label": getDateLabel(day.date, state.locale, {
|
|
646
|
+
today: day.today,
|
|
647
|
+
selected: day.selected && !day.rangeStart && !day.rangeEnd && !day.inRange,
|
|
648
|
+
unavailable: day.unavailable,
|
|
649
|
+
partiallyAvailable: day.partiallyAvailable,
|
|
650
|
+
disabled: day.disabled,
|
|
651
|
+
reason: dayReason(day.date),
|
|
652
|
+
rangeStart: day.rangeStart,
|
|
653
|
+
rangeEnd: day.rangeEnd,
|
|
654
|
+
inRange: day.inRange,
|
|
655
|
+
}, state.messages),
|
|
656
|
+
"aria-selected": day.selected
|
|
657
|
+
? "true"
|
|
658
|
+
: unselectable
|
|
659
|
+
? undefined
|
|
660
|
+
: "false",
|
|
661
|
+
"aria-current": day.today ? "date" : undefined,
|
|
662
|
+
"aria-disabled": unselectable ? "true" : undefined,
|
|
663
|
+
tabindex: day.focused ? 0 : -1,
|
|
664
|
+
"data-chrono-key": day.key,
|
|
665
|
+
"data-selected": day.selected,
|
|
666
|
+
"data-today": day.today,
|
|
667
|
+
"data-outside-month": day.outsideMonth,
|
|
668
|
+
"data-weekend": day.weekend,
|
|
669
|
+
"data-disabled": day.disabled,
|
|
670
|
+
"data-unavailable": day.unavailable,
|
|
671
|
+
"data-partially-available": day.partiallyAvailable,
|
|
672
|
+
"data-focused": day.focused,
|
|
673
|
+
"data-range-start": day.rangeStart,
|
|
674
|
+
"data-range-end": day.rangeEnd,
|
|
675
|
+
"data-in-range": day.inRange,
|
|
676
|
+
"data-range-preview": day.preview && !day.selected,
|
|
677
|
+
"data-range-blocked": day.blocked,
|
|
678
|
+
};
|
|
679
|
+
},
|
|
680
|
+
getLevelCellAttributes: (cell) => ({
|
|
681
|
+
role: "gridcell",
|
|
682
|
+
"aria-label": cell.label,
|
|
683
|
+
"aria-selected": cell.selected
|
|
684
|
+
? "true"
|
|
685
|
+
: cell.disabled
|
|
686
|
+
? undefined
|
|
687
|
+
: "false",
|
|
688
|
+
"aria-current": cell.current ? "date" : undefined,
|
|
689
|
+
"aria-disabled": cell.disabled ? "true" : undefined,
|
|
690
|
+
tabindex: cell.focused ? 0 : -1,
|
|
691
|
+
"data-chrono-key": cell.key,
|
|
692
|
+
"data-selected": cell.selected,
|
|
693
|
+
"data-today": cell.current,
|
|
694
|
+
"data-disabled": cell.disabled,
|
|
695
|
+
"data-focused": cell.focused,
|
|
696
|
+
"data-outside-month": cell.outside,
|
|
697
|
+
}),
|
|
698
|
+
destroy() {
|
|
699
|
+
listeners.clear();
|
|
700
|
+
},
|
|
701
|
+
};
|
|
702
|
+
function page(step) {
|
|
703
|
+
if (options.disabled)
|
|
704
|
+
return;
|
|
705
|
+
if (step === -1 ? !state.canGoPrev : !state.canGoNext)
|
|
706
|
+
return;
|
|
707
|
+
const level = levelControl.get();
|
|
708
|
+
const month = monthControl.get();
|
|
709
|
+
const first = plainDate(month.year, month.month, 1);
|
|
710
|
+
if (level === "day") {
|
|
711
|
+
const by = (options.pageBy === "visible" ? monthCount() : 1) * step;
|
|
712
|
+
monthControl.set(monthOf(addMonths(first, by)));
|
|
713
|
+
focusedDate = addMonths(focusedDate, by);
|
|
714
|
+
}
|
|
715
|
+
else {
|
|
716
|
+
const by = (level === "year" ? 10 : 1) * step;
|
|
717
|
+
monthControl.set({ year: month.year + by, month: month.month });
|
|
718
|
+
focusedDate = addYears(focusedDate, by);
|
|
719
|
+
}
|
|
720
|
+
refresh();
|
|
721
|
+
}
|
|
722
|
+
return controller;
|
|
723
|
+
}
|
|
724
|
+
export const createDatePanelController = (options = {}) => createPanel("single", options);
|
|
725
|
+
export const createDateRangePanelController = (options = {}) => createPanel("range", options);
|
|
726
|
+
export const createMultiDatePanelController = (options = {}) => createPanel("multi", options);
|