@gravity-ui/date-components 3.4.2 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -0
- package/dist/cjs/components/Calendar/Calendar.d.ts +6 -2
- package/dist/cjs/components/Calendar/Calendar.js +1 -1
- package/dist/cjs/components/Calendar/Calendar.js.map +1 -1
- package/dist/cjs/components/CalendarView/Calendar.css +3 -0
- package/dist/cjs/components/CalendarView/Calendar.css.map +1 -1
- package/dist/cjs/components/CalendarView/CalendarView.d.ts +2 -1
- package/dist/cjs/components/CalendarView/CalendarView.js +8 -8
- package/dist/cjs/components/CalendarView/CalendarView.js.map +1 -1
- package/dist/cjs/components/CalendarView/hooks/types.d.ts +5 -3
- package/dist/cjs/components/CalendarView/hooks/types.js.map +1 -1
- package/dist/cjs/components/CalendarView/hooks/useCalendarCellProps.js +1 -2
- package/dist/cjs/components/CalendarView/hooks/useCalendarCellProps.js.map +1 -1
- package/dist/cjs/components/CalendarView/hooks/useCalendarGridProps.js +10 -3
- package/dist/cjs/components/CalendarView/hooks/useCalendarGridProps.js.map +1 -1
- package/dist/cjs/components/CalendarView/hooks/useCalendarProps.js +7 -1
- package/dist/cjs/components/CalendarView/hooks/useCalendarProps.js.map +1 -1
- package/dist/cjs/components/CalendarView/hooks/useCalendarState.d.ts +5 -3
- package/dist/cjs/components/CalendarView/hooks/useCalendarState.js +74 -30
- package/dist/cjs/components/CalendarView/hooks/useCalendarState.js.map +1 -1
- package/dist/cjs/components/CalendarView/hooks/useRangeCalendarState.js +16 -9
- package/dist/cjs/components/CalendarView/hooks/useRangeCalendarState.js.map +1 -1
- package/dist/cjs/components/DateField/DateField.d.ts +1 -1
- package/dist/cjs/components/DateField/DateField.js +5 -17
- package/dist/cjs/components/DateField/DateField.js.map +1 -1
- package/dist/cjs/components/DateField/IncompleteDate.d.ts +28 -0
- package/dist/cjs/components/DateField/IncompleteDate.js +116 -0
- package/dist/cjs/components/DateField/IncompleteDate.js.map +1 -0
- package/dist/cjs/components/DateField/hooks/useBaseDateFieldState.d.ts +34 -68
- package/dist/cjs/components/DateField/hooks/useBaseDateFieldState.js +18 -249
- package/dist/cjs/components/DateField/hooks/useBaseDateFieldState.js.map +1 -1
- package/dist/cjs/components/DateField/hooks/useDateFieldProps.d.ts +2 -0
- package/dist/cjs/components/DateField/hooks/useDateFieldProps.js +250 -54
- package/dist/cjs/components/DateField/hooks/useDateFieldProps.js.map +1 -1
- package/dist/cjs/components/DateField/hooks/useDateFieldState.d.ts +20 -2
- package/dist/cjs/components/DateField/hooks/useDateFieldState.js +84 -118
- package/dist/cjs/components/DateField/hooks/useDateFieldState.js.map +1 -1
- package/dist/cjs/components/DateField/hooks/useFocusManager.d.ts +29 -0
- package/dist/cjs/components/DateField/hooks/useFocusManager.js +116 -0
- package/dist/cjs/components/DateField/hooks/useFocusManager.js.map +1 -0
- package/dist/cjs/components/{RangeDateField → DateField}/hooks/useRangeDateFieldState.d.ts +1 -1
- package/dist/cjs/components/DateField/hooks/useRangeDateFieldState.js +236 -0
- package/dist/cjs/components/DateField/hooks/useRangeDateFieldState.js.map +1 -0
- package/dist/cjs/components/DateField/i18n/ru.json +1 -1
- package/dist/cjs/components/DateField/index.d.ts +2 -1
- package/dist/cjs/components/DateField/index.js +1 -1
- package/dist/cjs/components/DateField/index.js.map +1 -1
- package/dist/cjs/components/DateField/types.d.ts +2 -22
- package/dist/cjs/components/DateField/types.js.map +1 -1
- package/dist/cjs/components/DateField/utils.d.ts +21 -34
- package/dist/cjs/components/DateField/utils.js +180 -132
- package/dist/cjs/components/DateField/utils.js.map +1 -1
- package/dist/cjs/components/DatePicker/DatePicker.d.ts +3 -3
- package/dist/cjs/components/DatePicker/DatePicker.js +3 -4
- package/dist/cjs/components/DatePicker/DatePicker.js.map +1 -1
- package/dist/cjs/components/DatePicker/MobileCalendar.d.ts +1 -1
- package/dist/cjs/components/DatePicker/MobileCalendar.js +3 -5
- package/dist/cjs/components/DatePicker/MobileCalendar.js.map +1 -1
- package/dist/cjs/components/DatePicker/StubButton.d.ts +1 -1
- package/dist/cjs/components/DatePicker/hooks/datePickerStateFactory.d.ts +1 -1
- package/dist/cjs/components/DatePicker/hooks/datePickerStateFactory.js +15 -6
- package/dist/cjs/components/DatePicker/hooks/datePickerStateFactory.js.map +1 -1
- package/dist/cjs/components/DatePicker/hooks/useDatePickerProps.d.ts +2 -2
- package/dist/cjs/components/DatePicker/hooks/useDatePickerProps.js +30 -17
- package/dist/cjs/components/DatePicker/hooks/useDatePickerProps.js.map +1 -1
- package/dist/cjs/components/HiddenInput/HiddenInput.d.ts +2 -5
- package/dist/cjs/components/HiddenInput/HiddenInput.js +2 -4
- package/dist/cjs/components/HiddenInput/HiddenInput.js.map +1 -1
- package/dist/cjs/components/RangeCalendar/RangeCalendar.d.ts +2 -2
- package/dist/cjs/components/RangeCalendar/RangeCalendar.js +2 -3
- package/dist/cjs/components/RangeCalendar/RangeCalendar.js.map +1 -1
- package/dist/cjs/components/RangeDateField/RangeDateField.d.ts +1 -1
- package/dist/cjs/components/RangeDateField/RangeDateField.js +6 -19
- package/dist/cjs/components/RangeDateField/RangeDateField.js.map +1 -1
- package/dist/cjs/components/RangeDateField/index.d.ts +0 -1
- package/dist/cjs/components/RangeDateField/index.js +0 -1
- package/dist/cjs/components/RangeDateField/index.js.map +1 -1
- package/dist/cjs/components/RangeDatePicker/RangeDatePicker.d.ts +2 -1
- package/dist/cjs/components/RangeDatePicker/RangeDatePicker.js +4 -5
- package/dist/cjs/components/RangeDatePicker/RangeDatePicker.js.map +1 -1
- package/dist/cjs/components/RangeDatePicker/hooks/useRangeDatePickerState.d.ts +1 -1
- package/dist/cjs/components/RangeDatePicker/hooks/useRangeDatePickerState.js +3 -4
- package/dist/cjs/components/RangeDatePicker/hooks/useRangeDatePickerState.js.map +1 -1
- package/dist/cjs/components/RangeDateSelection/RangeDateSelection.d.ts +1 -1
- package/dist/cjs/components/RangeDateSelection/RangeDateSelection.js +4 -5
- package/dist/cjs/components/RangeDateSelection/RangeDateSelection.js.map +1 -1
- package/dist/cjs/components/RangeDateSelection/components/NowLine/NowLine.d.ts +2 -1
- package/dist/cjs/components/RangeDateSelection/components/Ruler/Ruler.d.ts +1 -1
- package/dist/cjs/components/RangeDateSelection/components/Ruler/Ruler.js +1 -1
- package/dist/cjs/components/RangeDateSelection/components/Ruler/Ruler.js.map +1 -1
- package/dist/cjs/components/RangeDateSelection/components/RulerViewport/RulerViewport.js +2 -2
- package/dist/cjs/components/RangeDateSelection/components/RulerViewport/RulerViewport.js.map +1 -1
- package/dist/cjs/components/RangeDateSelection/components/SelectionControl/SelectionControl.d.ts +2 -1
- package/dist/cjs/components/RangeDateSelection/components/SelectionControl/SelectionControl.js +12 -21
- package/dist/cjs/components/RangeDateSelection/components/SelectionControl/SelectionControl.js.map +1 -1
- package/dist/cjs/components/RangeDateSelection/components/Ticks/MiddleTicks.d.ts +1 -1
- package/dist/cjs/components/RangeDateSelection/components/Ticks/SlitTicks.d.ts +1 -1
- package/dist/cjs/components/RangeDateSelection/components/Ticks/Ticks.d.ts +2 -2
- package/dist/cjs/components/RangeDateSelection/components/Ticks/Ticks.js.map +1 -1
- package/dist/cjs/components/RangeDateSelection/components/Ticks/UnavialableTicks.d.ts +3 -4
- package/dist/cjs/components/RangeDateSelection/components/Ticks/UnavialableTicks.js +0 -3
- package/dist/cjs/components/RangeDateSelection/components/Ticks/UnavialableTicks.js.map +1 -1
- package/dist/cjs/components/RangeDateSelection/hooks/useRangeDateSelectionState.js +9 -10
- package/dist/cjs/components/RangeDateSelection/hooks/useRangeDateSelectionState.js.map +1 -1
- package/dist/cjs/components/RangeDateSelection/utils/span.d.ts +2 -1
- package/dist/cjs/components/RangeDateSelection/utils/span.js.map +1 -1
- package/dist/cjs/components/RelativeDateField/RelativeDateField.d.ts +1 -1
- package/dist/cjs/components/RelativeDateField/RelativeDateField.js +3 -40
- package/dist/cjs/components/RelativeDateField/RelativeDateField.js.map +1 -1
- package/dist/cjs/components/RelativeDateField/hooks/useRelativeDateFieldProps.d.ts +7 -2
- package/dist/cjs/components/RelativeDateField/hooks/useRelativeDateFieldProps.js +71 -9
- package/dist/cjs/components/RelativeDateField/hooks/useRelativeDateFieldProps.js.map +1 -1
- package/dist/cjs/components/RelativeDateField/hooks/useRelativeDateFieldState.d.ts +2 -0
- package/dist/cjs/components/RelativeDateField/hooks/useRelativeDateFieldState.js +48 -34
- package/dist/cjs/components/RelativeDateField/hooks/useRelativeDateFieldState.js.map +1 -1
- package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.d.ts +1 -1
- package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.js +7 -4
- package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.js.map +1 -1
- package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.d.ts +1 -1
- package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.js +52 -21
- package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.js.map +1 -1
- package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerState.js +9 -10
- package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerState.js.map +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/RelativeRangeDatePicker.d.ts +2 -1
- package/dist/cjs/components/RelativeRangeDatePicker/RelativeRangeDatePicker.js +13 -5
- package/dist/cjs/components/RelativeRangeDatePicker/RelativeRangeDatePicker.js.map +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/components/Control/Control.css +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/components/Control/Control.css.map +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/components/Control/Control.d.ts +2 -1
- package/dist/cjs/components/RelativeRangeDatePicker/components/Control/Control.js +12 -6
- package/dist/cjs/components/RelativeRangeDatePicker/components/Control/Control.js.map +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.d.ts +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.js +6 -8
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.js.map +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDoc.d.ts +5 -3
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDoc.js +18 -16
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDoc.js.map +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerForm.d.ts +5 -1
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerForm.js +34 -7
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerForm.js.map +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.d.ts +3 -3
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.js +19 -18
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.js.map +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/Presets.d.ts +6 -9
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/Presets.js +9 -12
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/Presets.js.map +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/defaultPresets.d.ts +2 -2
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/defaultPresets.js.map +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/utils.d.ts +9 -4
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/utils.js +27 -16
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/utils.js.map +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/Zones.d.ts +3 -3
- package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/Zones.js +3 -4
- package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/Zones.js.map +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.js +8 -7
- package/dist/cjs/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.js.map +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/types.d.ts +3 -1
- package/dist/cjs/components/RelativeRangeDatePicker/types.js.map +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/utils.d.ts +2 -2
- package/dist/cjs/components/RelativeRangeDatePicker/utils.js +32 -9
- package/dist/cjs/components/RelativeRangeDatePicker/utils.js.map +1 -1
- package/dist/cjs/components/utils/constants.d.ts +2 -0
- package/dist/cjs/components/utils/constants.js +7 -1
- package/dist/cjs/components/utils/constants.js.map +1 -1
- package/dist/cjs/components/utils/dates.d.ts +6 -1
- package/dist/cjs/components/utils/dates.js +6 -1
- package/dist/cjs/components/utils/dates.js.map +1 -1
- package/dist/cjs/components/utils/filterDOMProps.js +1 -1
- package/dist/cjs/components/utils/filterDOMProps.js.map +1 -1
- package/dist/cjs/components/utils/mergeProps.js +1 -1
- package/dist/cjs/components/utils/mergeProps.js.map +1 -1
- package/dist/cjs/components/utils/validation/datePicker.js +1 -1
- package/dist/cjs/components/utils/validation/datePicker.js.map +1 -1
- package/dist/cjs/components/utils/validation/i18n/ru.json +2 -2
- package/dist/cjs/components/utils/validation/relativeRangeDatePicker.d.ts +7 -11
- package/dist/cjs/components/utils/validation/relativeRangeDatePicker.js +6 -1
- package/dist/cjs/components/utils/validation/relativeRangeDatePicker.js.map +1 -1
- package/dist/cjs/hooks/useEventHandler.js +1 -2
- package/dist/cjs/hooks/useEventHandler.js.map +1 -1
- package/dist/cjs/hooks/useMove.d.ts +2 -2
- package/dist/cjs/hooks/useMove.js +6 -9
- package/dist/cjs/hooks/useMove.js.map +1 -1
- package/dist/cjs/hooks/useResizeObserver.js +1 -1
- package/dist/cjs/hooks/useResizeObserver.js.map +1 -1
- package/dist/cjs/package.json +1 -1
- package/dist/docs/INDEX.md +131 -0
- package/dist/docs/components/Calendar.md +125 -0
- package/dist/docs/components/DateField.md +206 -0
- package/dist/docs/components/DatePicker.md +194 -0
- package/dist/docs/components/RangeCalendar.md +125 -0
- package/dist/docs/components/RelativeDateField.md +73 -0
- package/dist/docs/components/RelativeDatePicker.md +59 -0
- package/dist/esm/components/Calendar/Calendar.d.ts +6 -2
- package/dist/esm/components/Calendar/Calendar.js +1 -1
- package/dist/esm/components/Calendar/Calendar.js.map +1 -1
- package/dist/esm/components/CalendarView/Calendar.css +3 -0
- package/dist/esm/components/CalendarView/Calendar.css.map +1 -1
- package/dist/esm/components/CalendarView/CalendarView.d.ts +2 -1
- package/dist/esm/components/CalendarView/CalendarView.js +8 -8
- package/dist/esm/components/CalendarView/CalendarView.js.map +1 -1
- package/dist/esm/components/CalendarView/hooks/types.d.ts +5 -3
- package/dist/esm/components/CalendarView/hooks/types.js.map +1 -1
- package/dist/esm/components/CalendarView/hooks/useCalendarCellProps.js +1 -2
- package/dist/esm/components/CalendarView/hooks/useCalendarCellProps.js.map +1 -1
- package/dist/esm/components/CalendarView/hooks/useCalendarGridProps.js +10 -3
- package/dist/esm/components/CalendarView/hooks/useCalendarGridProps.js.map +1 -1
- package/dist/esm/components/CalendarView/hooks/useCalendarProps.js +7 -1
- package/dist/esm/components/CalendarView/hooks/useCalendarProps.js.map +1 -1
- package/dist/esm/components/CalendarView/hooks/useCalendarState.d.ts +5 -3
- package/dist/esm/components/CalendarView/hooks/useCalendarState.js +74 -30
- package/dist/esm/components/CalendarView/hooks/useCalendarState.js.map +1 -1
- package/dist/esm/components/CalendarView/hooks/useRangeCalendarState.js +16 -10
- package/dist/esm/components/CalendarView/hooks/useRangeCalendarState.js.map +1 -1
- package/dist/esm/components/DateField/DateField.d.ts +1 -1
- package/dist/esm/components/DateField/DateField.js +6 -18
- package/dist/esm/components/DateField/DateField.js.map +1 -1
- package/dist/esm/components/DateField/IncompleteDate.d.ts +28 -0
- package/dist/esm/components/DateField/IncompleteDate.js +112 -0
- package/dist/esm/components/DateField/IncompleteDate.js.map +1 -0
- package/dist/esm/components/DateField/hooks/useBaseDateFieldState.d.ts +34 -68
- package/dist/esm/components/DateField/hooks/useBaseDateFieldState.js +17 -248
- package/dist/esm/components/DateField/hooks/useBaseDateFieldState.js.map +1 -1
- package/dist/esm/components/DateField/hooks/useDateFieldProps.d.ts +2 -0
- package/dist/esm/components/DateField/hooks/useDateFieldProps.js +250 -54
- package/dist/esm/components/DateField/hooks/useDateFieldProps.js.map +1 -1
- package/dist/esm/components/DateField/hooks/useDateFieldState.d.ts +20 -2
- package/dist/esm/components/DateField/hooks/useDateFieldState.js +85 -119
- package/dist/esm/components/DateField/hooks/useDateFieldState.js.map +1 -1
- package/dist/esm/components/DateField/hooks/useFocusManager.d.ts +29 -0
- package/dist/esm/components/DateField/hooks/useFocusManager.js +112 -0
- package/dist/esm/components/DateField/hooks/useFocusManager.js.map +1 -0
- package/dist/esm/components/{RangeDateField → DateField}/hooks/useRangeDateFieldState.d.ts +1 -1
- package/dist/esm/components/DateField/hooks/useRangeDateFieldState.js +232 -0
- package/dist/esm/components/DateField/hooks/useRangeDateFieldState.js.map +1 -0
- package/dist/esm/components/DateField/i18n/ru.json +1 -1
- package/dist/esm/components/DateField/index.d.ts +2 -1
- package/dist/esm/components/DateField/index.js +1 -1
- package/dist/esm/components/DateField/index.js.map +1 -1
- package/dist/esm/components/DateField/types.d.ts +2 -22
- package/dist/esm/components/DateField/types.js.map +1 -1
- package/dist/esm/components/DateField/utils.d.ts +21 -34
- package/dist/esm/components/DateField/utils.js +179 -125
- package/dist/esm/components/DateField/utils.js.map +1 -1
- package/dist/esm/components/DatePicker/DatePicker.d.ts +3 -3
- package/dist/esm/components/DatePicker/DatePicker.js +3 -5
- package/dist/esm/components/DatePicker/DatePicker.js.map +1 -1
- package/dist/esm/components/DatePicker/MobileCalendar.d.ts +1 -1
- package/dist/esm/components/DatePicker/MobileCalendar.js +3 -5
- package/dist/esm/components/DatePicker/MobileCalendar.js.map +1 -1
- package/dist/esm/components/DatePicker/StubButton.d.ts +1 -1
- package/dist/esm/components/DatePicker/hooks/datePickerStateFactory.d.ts +1 -1
- package/dist/esm/components/DatePicker/hooks/datePickerStateFactory.js +15 -6
- package/dist/esm/components/DatePicker/hooks/datePickerStateFactory.js.map +1 -1
- package/dist/esm/components/DatePicker/hooks/useDatePickerProps.d.ts +2 -2
- package/dist/esm/components/DatePicker/hooks/useDatePickerProps.js +30 -18
- package/dist/esm/components/DatePicker/hooks/useDatePickerProps.js.map +1 -1
- package/dist/esm/components/HiddenInput/HiddenInput.d.ts +2 -5
- package/dist/esm/components/HiddenInput/HiddenInput.js +3 -4
- package/dist/esm/components/HiddenInput/HiddenInput.js.map +1 -1
- package/dist/esm/components/RangeCalendar/RangeCalendar.d.ts +2 -2
- package/dist/esm/components/RangeCalendar/RangeCalendar.js +2 -3
- package/dist/esm/components/RangeCalendar/RangeCalendar.js.map +1 -1
- package/dist/esm/components/RangeDateField/RangeDateField.d.ts +1 -1
- package/dist/esm/components/RangeDateField/RangeDateField.js +7 -20
- package/dist/esm/components/RangeDateField/RangeDateField.js.map +1 -1
- package/dist/esm/components/RangeDateField/index.d.ts +0 -1
- package/dist/esm/components/RangeDateField/index.js +0 -1
- package/dist/esm/components/RangeDateField/index.js.map +1 -1
- package/dist/esm/components/RangeDatePicker/RangeDatePicker.d.ts +2 -1
- package/dist/esm/components/RangeDatePicker/RangeDatePicker.js +4 -6
- package/dist/esm/components/RangeDatePicker/RangeDatePicker.js.map +1 -1
- package/dist/esm/components/RangeDatePicker/hooks/useRangeDatePickerState.d.ts +1 -1
- package/dist/esm/components/RangeDatePicker/hooks/useRangeDatePickerState.js +2 -3
- package/dist/esm/components/RangeDatePicker/hooks/useRangeDatePickerState.js.map +1 -1
- package/dist/esm/components/RangeDateSelection/RangeDateSelection.d.ts +1 -1
- package/dist/esm/components/RangeDateSelection/RangeDateSelection.js +4 -5
- package/dist/esm/components/RangeDateSelection/RangeDateSelection.js.map +1 -1
- package/dist/esm/components/RangeDateSelection/components/NowLine/NowLine.d.ts +2 -1
- package/dist/esm/components/RangeDateSelection/components/Ruler/Ruler.d.ts +1 -1
- package/dist/esm/components/RangeDateSelection/components/Ruler/Ruler.js +1 -1
- package/dist/esm/components/RangeDateSelection/components/Ruler/Ruler.js.map +1 -1
- package/dist/esm/components/RangeDateSelection/components/RulerViewport/RulerViewport.js +2 -2
- package/dist/esm/components/RangeDateSelection/components/RulerViewport/RulerViewport.js.map +1 -1
- package/dist/esm/components/RangeDateSelection/components/SelectionControl/SelectionControl.d.ts +2 -1
- package/dist/esm/components/RangeDateSelection/components/SelectionControl/SelectionControl.js +12 -22
- package/dist/esm/components/RangeDateSelection/components/SelectionControl/SelectionControl.js.map +1 -1
- package/dist/esm/components/RangeDateSelection/components/Ticks/MiddleTicks.d.ts +1 -1
- package/dist/esm/components/RangeDateSelection/components/Ticks/SlitTicks.d.ts +1 -1
- package/dist/esm/components/RangeDateSelection/components/Ticks/Ticks.d.ts +2 -2
- package/dist/esm/components/RangeDateSelection/components/Ticks/Ticks.js.map +1 -1
- package/dist/esm/components/RangeDateSelection/components/Ticks/UnavialableTicks.d.ts +3 -4
- package/dist/esm/components/RangeDateSelection/components/Ticks/UnavialableTicks.js +1 -2
- package/dist/esm/components/RangeDateSelection/components/Ticks/UnavialableTicks.js.map +1 -1
- package/dist/esm/components/RangeDateSelection/hooks/useRangeDateSelectionState.js +9 -10
- package/dist/esm/components/RangeDateSelection/hooks/useRangeDateSelectionState.js.map +1 -1
- package/dist/esm/components/RangeDateSelection/utils/span.d.ts +2 -1
- package/dist/esm/components/RangeDateSelection/utils/span.js.map +1 -1
- package/dist/esm/components/RelativeDateField/RelativeDateField.d.ts +1 -1
- package/dist/esm/components/RelativeDateField/RelativeDateField.js +4 -40
- package/dist/esm/components/RelativeDateField/RelativeDateField.js.map +1 -1
- package/dist/esm/components/RelativeDateField/hooks/useRelativeDateFieldProps.d.ts +7 -2
- package/dist/esm/components/RelativeDateField/hooks/useRelativeDateFieldProps.js +71 -9
- package/dist/esm/components/RelativeDateField/hooks/useRelativeDateFieldProps.js.map +1 -1
- package/dist/esm/components/RelativeDateField/hooks/useRelativeDateFieldState.d.ts +2 -0
- package/dist/esm/components/RelativeDateField/hooks/useRelativeDateFieldState.js +48 -34
- package/dist/esm/components/RelativeDateField/hooks/useRelativeDateFieldState.js.map +1 -1
- package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.d.ts +1 -1
- package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.js +7 -4
- package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.js.map +1 -1
- package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.d.ts +1 -1
- package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.js +52 -22
- package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.js.map +1 -1
- package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerState.js +9 -10
- package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerState.js.map +1 -1
- package/dist/esm/components/RelativeRangeDatePicker/RelativeRangeDatePicker.d.ts +2 -1
- package/dist/esm/components/RelativeRangeDatePicker/RelativeRangeDatePicker.js +13 -5
- package/dist/esm/components/RelativeRangeDatePicker/RelativeRangeDatePicker.js.map +1 -1
- package/dist/esm/components/RelativeRangeDatePicker/components/Control/Control.css +1 -1
- package/dist/esm/components/RelativeRangeDatePicker/components/Control/Control.css.map +1 -1
- package/dist/esm/components/RelativeRangeDatePicker/components/Control/Control.d.ts +2 -1
- package/dist/esm/components/RelativeRangeDatePicker/components/Control/Control.js +12 -6
- package/dist/esm/components/RelativeRangeDatePicker/components/Control/Control.js.map +1 -1
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.d.ts +1 -1
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.js +6 -8
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.js.map +1 -1
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDoc.d.ts +5 -3
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDoc.js +18 -17
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDoc.js.map +1 -1
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerForm.d.ts +5 -1
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerForm.js +33 -7
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerForm.js.map +1 -1
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.d.ts +3 -3
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.js +19 -18
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.js.map +1 -1
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/Presets.d.ts +6 -9
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/Presets.js +8 -10
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/Presets.js.map +1 -1
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/defaultPresets.d.ts +2 -2
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/defaultPresets.js.map +1 -1
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/utils.d.ts +9 -4
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/utils.js +26 -15
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/utils.js.map +1 -1
- package/dist/esm/components/RelativeRangeDatePicker/components/Zones/Zones.d.ts +3 -3
- package/dist/esm/components/RelativeRangeDatePicker/components/Zones/Zones.js +3 -4
- package/dist/esm/components/RelativeRangeDatePicker/components/Zones/Zones.js.map +1 -1
- package/dist/esm/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.js +8 -7
- package/dist/esm/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.js.map +1 -1
- package/dist/esm/components/RelativeRangeDatePicker/types.d.ts +3 -1
- package/dist/esm/components/RelativeRangeDatePicker/types.js.map +1 -1
- package/dist/esm/components/RelativeRangeDatePicker/utils.d.ts +2 -2
- package/dist/esm/components/RelativeRangeDatePicker/utils.js +33 -9
- package/dist/esm/components/RelativeRangeDatePicker/utils.js.map +1 -1
- package/dist/esm/components/utils/constants.d.ts +2 -0
- package/dist/esm/components/utils/constants.js +6 -0
- package/dist/esm/components/utils/constants.js.map +1 -1
- package/dist/esm/components/utils/dates.d.ts +6 -1
- package/dist/esm/components/utils/dates.js +5 -1
- package/dist/esm/components/utils/dates.js.map +1 -1
- package/dist/esm/components/utils/filterDOMProps.js +1 -1
- package/dist/esm/components/utils/filterDOMProps.js.map +1 -1
- package/dist/esm/components/utils/mergeProps.js +1 -1
- package/dist/esm/components/utils/mergeProps.js.map +1 -1
- package/dist/esm/components/utils/validation/datePicker.js +1 -1
- package/dist/esm/components/utils/validation/datePicker.js.map +1 -1
- package/dist/esm/components/utils/validation/i18n/ru.json +2 -2
- package/dist/esm/components/utils/validation/relativeRangeDatePicker.d.ts +7 -11
- package/dist/esm/components/utils/validation/relativeRangeDatePicker.js +6 -1
- package/dist/esm/components/utils/validation/relativeRangeDatePicker.js.map +1 -1
- package/dist/esm/hooks/useEventHandler.js +1 -2
- package/dist/esm/hooks/useEventHandler.js.map +1 -1
- package/dist/esm/hooks/useMove.d.ts +2 -2
- package/dist/esm/hooks/useMove.js +6 -9
- package/dist/esm/hooks/useMove.js.map +1 -1
- package/dist/esm/hooks/useResizeObserver.js +1 -1
- package/dist/esm/hooks/useResizeObserver.js.map +1 -1
- package/dist/esm/package.json +1 -1
- package/package.json +34 -27
- package/dist/cjs/components/RangeDateField/hooks/useRangeDateFieldState.js +0 -224
- package/dist/cjs/components/RangeDateField/hooks/useRangeDateFieldState.js.map +0 -1
- package/dist/cjs/components/RangeDateField/utils/createPlaceholderRangeValue.d.ts +0 -5
- package/dist/cjs/components/RangeDateField/utils/createPlaceholderRangeValue.js +0 -9
- package/dist/cjs/components/RangeDateField/utils/createPlaceholderRangeValue.js.map +0 -1
- package/dist/cjs/components/RangeDateField/utils/getRangeEditableSections.d.ts +0 -5
- package/dist/cjs/components/RangeDateField/utils/getRangeEditableSections.js +0 -42
- package/dist/cjs/components/RangeDateField/utils/getRangeEditableSections.js.map +0 -1
- package/dist/cjs/components/RangeDateField/utils/index.d.ts +0 -3
- package/dist/cjs/components/RangeDateField/utils/index.js +0 -7
- package/dist/cjs/components/RangeDateField/utils/index.js.map +0 -1
- package/dist/cjs/components/RangeDateField/utils/isValidRange.d.ts +0 -3
- package/dist/cjs/components/RangeDateField/utils/isValidRange.js +0 -7
- package/dist/cjs/components/RangeDateField/utils/isValidRange.js.map +0 -1
- package/dist/esm/components/RangeDateField/hooks/useRangeDateFieldState.js +0 -220
- package/dist/esm/components/RangeDateField/hooks/useRangeDateFieldState.js.map +0 -1
- package/dist/esm/components/RangeDateField/utils/createPlaceholderRangeValue.d.ts +0 -5
- package/dist/esm/components/RangeDateField/utils/createPlaceholderRangeValue.js +0 -6
- package/dist/esm/components/RangeDateField/utils/createPlaceholderRangeValue.js.map +0 -1
- package/dist/esm/components/RangeDateField/utils/getRangeEditableSections.d.ts +0 -5
- package/dist/esm/components/RangeDateField/utils/getRangeEditableSections.js +0 -39
- package/dist/esm/components/RangeDateField/utils/getRangeEditableSections.js.map +0 -1
- package/dist/esm/components/RangeDateField/utils/index.d.ts +0 -3
- package/dist/esm/components/RangeDateField/utils/index.js +0 -4
- package/dist/esm/components/RangeDateField/utils/index.js.map +0 -1
- package/dist/esm/components/RangeDateField/utils/isValidRange.d.ts +0 -3
- package/dist/esm/components/RangeDateField/utils/isValidRange.js +0 -4
- package/dist/esm/components/RangeDateField/utils/isValidRange.js.map +0 -1
|
@@ -2,190 +2,156 @@ import React from 'react';
|
|
|
2
2
|
import { useControlledState, useLang } from '@gravity-ui/uikit';
|
|
3
3
|
import { createPlaceholderValue, isInvalid } from "../../utils/dates.js";
|
|
4
4
|
import { useDefaultTimeZone } from "../../utils/useDefaultTimeZone.js";
|
|
5
|
-
import {
|
|
5
|
+
import { IncompleteDate } from "../IncompleteDate.js";
|
|
6
|
+
import { addSegment, adjustDateToFormat, getEditableSections, getFormatInfo, isEditableSectionType, parseDateFromString, setSegment, useFormatSections, } from "../utils.js";
|
|
6
7
|
import { useBaseDateFieldState } from "./useBaseDateFieldState.js";
|
|
7
8
|
export function useDateFieldState(props) {
|
|
8
|
-
|
|
9
|
-
const [value, setDate] = useControlledState(props.value, (_a = props.defaultValue) !== null && _a !== void 0 ? _a : null, props.onUpdate);
|
|
9
|
+
const [value, setDate] = useControlledState(props.value, props.defaultValue ?? null, props.onUpdate);
|
|
10
10
|
const inputTimeZone = useDefaultTimeZone(props.value || props.defaultValue || props.placeholderValue);
|
|
11
11
|
const timeZone = props.timeZone || inputTimeZone;
|
|
12
12
|
const handleUpdateDate = (v) => {
|
|
13
13
|
setDate(v ? v.timeZone(inputTimeZone) : v);
|
|
14
14
|
};
|
|
15
|
-
const [
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
15
|
+
const [lastPlaceholder, setLastPlaceholder] = React.useState(props.placeholderValue);
|
|
16
|
+
if ((props.placeholderValue &&
|
|
17
|
+
(!lastPlaceholder || !props.placeholderValue.isSame(lastPlaceholder))) ||
|
|
18
|
+
(!props.placeholderValue && lastPlaceholder)) {
|
|
19
|
+
setLastPlaceholder(props.placeholderValue);
|
|
20
|
+
}
|
|
21
|
+
const placeholder = React.useMemo(() => createPlaceholderValue({
|
|
22
|
+
placeholderValue: lastPlaceholder,
|
|
23
|
+
timeZone,
|
|
24
|
+
}), [lastPlaceholder, timeZone]);
|
|
21
25
|
const format = props.format || 'L';
|
|
22
26
|
const sections = useFormatSections(format);
|
|
23
27
|
const formatInfo = React.useMemo(() => getFormatInfo(sections), [sections]);
|
|
24
28
|
const allSegments = formatInfo.availableUnits;
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
setValidSegments(validSegments);
|
|
37
|
-
setPlaceholderDate(createPlaceholderValue({
|
|
38
|
-
placeholderValue: props.placeholderValue,
|
|
39
|
-
timeZone,
|
|
40
|
-
}));
|
|
29
|
+
const [displayValue, setDisplayValue] = React.useState(() => {
|
|
30
|
+
return new IncompleteDate(value && value.isValid() ? value.timeZone(timeZone) : null);
|
|
31
|
+
});
|
|
32
|
+
const [lastValue, setLastValue] = React.useState(value);
|
|
33
|
+
const [lastTimezone, setLastTimezone] = React.useState(timeZone);
|
|
34
|
+
if ((value && (!lastValue || !value.isSame(lastValue))) ||
|
|
35
|
+
(value && lastTimezone !== timeZone) ||
|
|
36
|
+
(value === null && lastValue !== null)) {
|
|
37
|
+
setLastValue(value);
|
|
38
|
+
setLastTimezone(timeZone);
|
|
39
|
+
setDisplayValue(new IncompleteDate(value?.timeZone(timeZone)));
|
|
41
40
|
}
|
|
42
41
|
const { lang } = useLang();
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (selectedSections === 'all') {
|
|
53
|
-
return {
|
|
54
|
-
startIndex: 0,
|
|
55
|
-
endIndex: sectionsState.editableSections.length - 1,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
if (typeof selectedSections === 'number') {
|
|
59
|
-
return { startIndex: selectedSections, endIndex: selectedSections };
|
|
60
|
-
}
|
|
61
|
-
if (typeof selectedSections === 'string') {
|
|
62
|
-
const selectedSectionIndex = sectionsState.editableSections.findIndex((section) => section.type === selectedSections);
|
|
63
|
-
return { startIndex: selectedSectionIndex, endIndex: selectedSectionIndex };
|
|
64
|
-
}
|
|
65
|
-
return selectedSections;
|
|
66
|
-
}, [selectedSections, sectionsState.editableSections]);
|
|
42
|
+
const dateValue = React.useMemo(() => {
|
|
43
|
+
return displayValue
|
|
44
|
+
.toDateTime(value?.timeZone(timeZone) ?? placeholder, {
|
|
45
|
+
setDate: formatInfo.hasDate,
|
|
46
|
+
setTime: formatInfo.hasTime,
|
|
47
|
+
})
|
|
48
|
+
.locale(lang);
|
|
49
|
+
}, [displayValue, value, placeholder, formatInfo, timeZone, lang]);
|
|
50
|
+
const sectionsState = useSectionsState(sections, displayValue, dateValue);
|
|
67
51
|
function setValue(newValue) {
|
|
68
52
|
if (props.disabled || props.readOnly) {
|
|
69
53
|
return;
|
|
70
54
|
}
|
|
71
|
-
if (
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
55
|
+
if (newValue === null ||
|
|
56
|
+
(newValue instanceof IncompleteDate && newValue.isCleared(allSegments))) {
|
|
57
|
+
setDate(null);
|
|
58
|
+
setDisplayValue(new IncompleteDate());
|
|
75
59
|
}
|
|
76
|
-
else {
|
|
77
|
-
if (
|
|
78
|
-
|
|
60
|
+
else if (newValue instanceof IncompleteDate) {
|
|
61
|
+
if (newValue.isComplete(allSegments)) {
|
|
62
|
+
const newDate = newValue.toDateTime(dateValue, {
|
|
63
|
+
setDate: formatInfo.hasDate,
|
|
64
|
+
setTime: formatInfo.hasTime,
|
|
65
|
+
});
|
|
66
|
+
if (newValue.validate(newDate, allSegments)) {
|
|
67
|
+
if (!value || !newDate.isSame(value)) {
|
|
68
|
+
handleUpdateDate(adjustDateToFormat(newDate, formatInfo));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
79
71
|
}
|
|
80
|
-
|
|
72
|
+
setDisplayValue(newValue);
|
|
73
|
+
}
|
|
74
|
+
else if (!value || !newValue.isSame(value)) {
|
|
75
|
+
handleUpdateDate(newValue);
|
|
81
76
|
}
|
|
82
|
-
}
|
|
83
|
-
function markValid(part) {
|
|
84
|
-
validSegments = markValidSection(allSegments, validSegments, part);
|
|
85
|
-
setValidSegments(Object.assign({}, validSegments));
|
|
86
77
|
}
|
|
87
78
|
function setSection(sectionIndex, amount) {
|
|
88
79
|
const section = sectionsState.editableSections[sectionIndex];
|
|
89
80
|
if (section) {
|
|
90
|
-
|
|
91
|
-
setValue(setSegment(section, displayValue, amount));
|
|
81
|
+
setValue(setSegment(section, displayValue, amount, dateValue));
|
|
92
82
|
}
|
|
93
83
|
}
|
|
94
84
|
function adjustSection(sectionIndex, amount) {
|
|
95
85
|
const section = sectionsState.editableSections[sectionIndex];
|
|
96
86
|
if (section) {
|
|
97
|
-
|
|
98
|
-
setValue(addSegment(section, displayValue, amount));
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
markValid(section.type);
|
|
102
|
-
if (Object.keys(validSegments).length >= Object.keys(allSegments).length) {
|
|
103
|
-
setValue(displayValue);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
87
|
+
setValue(addSegment(section, displayValue, amount, dateValue));
|
|
106
88
|
}
|
|
107
89
|
}
|
|
108
|
-
function
|
|
90
|
+
function clearSection(sectionIndex) {
|
|
109
91
|
const section = sectionsState.editableSections[sectionIndex];
|
|
110
|
-
if (section) {
|
|
111
|
-
|
|
92
|
+
if (section && isEditableSectionType(section.type)) {
|
|
93
|
+
setValue(displayValue.clear(section.type));
|
|
112
94
|
}
|
|
113
|
-
setValidSegments(Object.assign({}, validSegments));
|
|
114
|
-
}
|
|
115
|
-
function flushAllValidSections() {
|
|
116
|
-
validSegments = {};
|
|
117
|
-
setValidSegments({});
|
|
118
|
-
}
|
|
119
|
-
function getSectionValue(_sectionIndex) {
|
|
120
|
-
return displayValue;
|
|
121
|
-
}
|
|
122
|
-
function setSectionValue(_sectionIndex, currentValue) {
|
|
123
|
-
setValue(currentValue);
|
|
124
|
-
}
|
|
125
|
-
function createPlaceholder() {
|
|
126
|
-
return createPlaceholderValue({
|
|
127
|
-
placeholderValue: props.placeholderValue,
|
|
128
|
-
timeZone,
|
|
129
|
-
}).timeZone(timeZone);
|
|
130
95
|
}
|
|
131
96
|
function setValueFromString(str) {
|
|
132
|
-
|
|
133
|
-
const parseDate = (_a = props.parseDateFromString) !== null && _a !== void 0 ? _a : parseDateFromString;
|
|
97
|
+
const parseDate = props.parseDateFromString ?? parseDateFromString;
|
|
134
98
|
const date = parseDate(str, format, timeZone);
|
|
135
99
|
if (date.isValid()) {
|
|
136
|
-
|
|
100
|
+
setValue(date);
|
|
137
101
|
return true;
|
|
138
102
|
}
|
|
139
103
|
return false;
|
|
140
104
|
}
|
|
105
|
+
function confirmPlaceholder() {
|
|
106
|
+
if (props.disabled || props.readOnly) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
// If the display value is complete but invalid, we need to constrain it and emit onChange on blur.
|
|
110
|
+
if (displayValue.isComplete(allSegments)) {
|
|
111
|
+
const newValue = displayValue.toDateTime(dateValue, {
|
|
112
|
+
setDate: formatInfo.hasDate,
|
|
113
|
+
setTime: formatInfo.hasTime,
|
|
114
|
+
});
|
|
115
|
+
setValue(adjustDateToFormat(newValue, formatInfo, 'startOf'));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
141
118
|
const validationState = props.validationState ||
|
|
142
119
|
(isInvalid(value, props.minValue, props.maxValue) ? 'invalid' : undefined) ||
|
|
143
|
-
(value &&
|
|
120
|
+
(value && props.isDateUnavailable?.(value) ? 'invalid' : undefined);
|
|
144
121
|
return useBaseDateFieldState({
|
|
145
122
|
value,
|
|
146
|
-
displayValue,
|
|
147
|
-
placeholderValue: props.placeholderValue,
|
|
148
|
-
timeZone,
|
|
123
|
+
displayValue: dateValue,
|
|
149
124
|
validationState,
|
|
150
125
|
editableSections: sectionsState.editableSections,
|
|
151
126
|
formatInfo,
|
|
152
127
|
readOnly: props.readOnly,
|
|
153
128
|
disabled: props.disabled,
|
|
154
|
-
|
|
155
|
-
selectedSections,
|
|
156
|
-
isEmpty: Object.keys(validSegments).length === 0,
|
|
157
|
-
flushAllValidSections,
|
|
158
|
-
flushValidSection,
|
|
159
|
-
setSelectedSections,
|
|
129
|
+
isEmpty: displayValue.isCleared(allSegments),
|
|
160
130
|
setValue,
|
|
161
|
-
setDate: handleUpdateDate,
|
|
162
131
|
adjustSection,
|
|
163
132
|
setSection,
|
|
164
|
-
|
|
165
|
-
setSectionValue,
|
|
166
|
-
createPlaceholder,
|
|
133
|
+
clearSection,
|
|
167
134
|
setValueFromString,
|
|
135
|
+
confirmPlaceholder,
|
|
168
136
|
});
|
|
169
137
|
}
|
|
170
|
-
function useSectionsState(sections, value,
|
|
138
|
+
function useSectionsState(sections, value, placeholder) {
|
|
171
139
|
const [state, setState] = React.useState(() => {
|
|
140
|
+
const editableSections = getEditableSections(sections, value, placeholder);
|
|
172
141
|
return {
|
|
173
142
|
value,
|
|
174
143
|
sections,
|
|
175
|
-
|
|
176
|
-
editableSections
|
|
144
|
+
placeholder,
|
|
145
|
+
editableSections,
|
|
177
146
|
};
|
|
178
147
|
});
|
|
179
|
-
if (sections !== state.sections ||
|
|
180
|
-
|
|
181
|
-
!value.isSame(state.value) ||
|
|
182
|
-
value.timeZone() !== state.value.timeZone() ||
|
|
183
|
-
value.locale() !== state.value.locale()) {
|
|
148
|
+
if (sections !== state.sections || placeholder !== state.placeholder || value !== state.value) {
|
|
149
|
+
const editableSections = getEditableSections(sections, value, placeholder);
|
|
184
150
|
setState({
|
|
185
151
|
value,
|
|
186
152
|
sections,
|
|
187
|
-
|
|
188
|
-
editableSections
|
|
153
|
+
placeholder,
|
|
154
|
+
editableSections,
|
|
189
155
|
});
|
|
190
156
|
}
|
|
191
157
|
return state;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDateFieldState.js","sourceRoot":"../../../../../src","sources":["components/DateField/hooks/useDateFieldState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAC,kBAAkB,EAAE,OAAO,EAAC,MAAM,mBA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AM,CAAC,KAAK,CAAC,KAAK,CAAC;QAC1B,KAAK,CAAC,QAAQ,EAAE,KAAK,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE;QAC3C,KAAK,CAAC,MAAM,EAAE,KAAK,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,EACzC,CAAC;QACC,QAAQ,CAAC;YACL,KAAK;YACL,QAAQ;YACR,aAAa;YACb,gBAAgB,EAAE,mBAAmB,CAAC,QAAQ,EAAE,KAAK,EAAE,aAAa,CAAC;SACxE,CAAC,CAAC;IACP,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import React from 'react';\n\nimport type {DateTime} from '@gravity-ui/date-utils';\nimport {useControlledState, useLang} from '@gravity-ui/uikit';\n\nimport type {DateFieldBase} from '../../types/datePicker';\nimport {createPlaceholderValue, isInvalid} from '../../utils/dates';\nimport {useDefaultTimeZone} from '../../utils/useDefaultTimeZone';\nimport type {\n AvailableSections,\n DateFieldSectionType,\n DateFieldSectionWithoutPosition,\n} from '../types';\nimport {\n addSegment,\n adjustDateToFormat,\n getEditableSections,\n getFormatInfo,\n isAllSegmentsValid,\n markValidSection,\n parseDateFromString,\n setSegment,\n useFormatSections,\n} from '../utils';\n\nimport {useBaseDateFieldState} from './useBaseDateFieldState';\nimport type {DateFieldState} from './useBaseDateFieldState';\n\nexport interface DateFieldStateOptions extends DateFieldBase {}\n\nexport function useDateFieldState(props: DateFieldStateOptions): DateFieldState {\n const [value, setDate] = useControlledState(\n props.value,\n props.defaultValue ?? null,\n props.onUpdate,\n );\n\n const inputTimeZone = useDefaultTimeZone(\n props.value || props.defaultValue || props.placeholderValue,\n );\n const timeZone = props.timeZone || inputTimeZone;\n\n const handleUpdateDate = (v: DateTime | null) => {\n setDate(v ? v.timeZone(inputTimeZone) : v);\n };\n\n const [placeholderDate, setPlaceholderDate] = React.useState(() => {\n return createPlaceholderValue({\n placeholderValue: props.placeholderValue,\n timeZone,\n });\n });\n\n const format = props.format || 'L';\n const sections = useFormatSections(format);\n const formatInfo = React.useMemo(() => getFormatInfo(sections), [sections]);\n const allSegments = formatInfo.availableUnits;\n\n const validSegmentsState = React.useState<AvailableSections>(() =>\n value ? {...allSegments} : {},\n );\n\n let validSegments = validSegmentsState[0];\n const setValidSegments = validSegmentsState[1];\n\n if (value && !isAllSegmentsValid(allSegments, validSegments)) {\n setValidSegments({...allSegments});\n }\n\n if (\n !value &&\n Object.keys(allSegments).length > 0 &&\n isAllSegmentsValid(allSegments, validSegments) &&\n Object.keys(validSegments).length === Object.keys(allSegments).length\n ) {\n validSegments = {};\n setValidSegments(validSegments);\n setPlaceholderDate(\n createPlaceholderValue({\n placeholderValue: props.placeholderValue,\n timeZone,\n }),\n );\n }\n\n const {lang} = useLang();\n const displayValue =\n value && value.isValid() && isAllSegmentsValid(allSegments, validSegments)\n ? value.timeZone(timeZone).locale(lang)\n : placeholderDate.timeZone(timeZone).locale(lang);\n const sectionsState = useSectionsState(sections, displayValue, validSegments);\n\n const [selectedSections, setSelectedSections] = React.useState<number | 'all'>(-1);\n\n const selectedSectionIndexes = React.useMemo<{\n startIndex: number;\n endIndex: number;\n } | null>(() => {\n if (selectedSections === -1) {\n return null;\n }\n\n if (selectedSections === 'all') {\n return {\n startIndex: 0,\n endIndex: sectionsState.editableSections.length - 1,\n };\n }\n\n if (typeof selectedSections === 'number') {\n return {startIndex: selectedSections, endIndex: selectedSections};\n }\n\n if (typeof selectedSections === 'string') {\n const selectedSectionIndex = sectionsState.editableSections.findIndex(\n (section) => section.type === selectedSections,\n );\n\n return {startIndex: selectedSectionIndex, endIndex: selectedSectionIndex};\n }\n\n return selectedSections;\n }, [selectedSections, sectionsState.editableSections]);\n\n function setValue(newValue: DateTime) {\n if (props.disabled || props.readOnly) {\n return;\n }\n\n if (isAllSegmentsValid(allSegments, validSegments)) {\n if (!value || !newValue.isSame(value)) {\n handleUpdateDate(adjustDateToFormat(newValue, formatInfo));\n }\n } else {\n if (value) {\n handleUpdateDate(null);\n }\n setPlaceholderDate(newValue);\n }\n }\n\n function markValid(part: DateFieldSectionType) {\n validSegments = markValidSection(allSegments, validSegments, part);\n setValidSegments({...validSegments});\n }\n\n function setSection(sectionIndex: number, amount: number) {\n const section = sectionsState.editableSections[sectionIndex];\n if (section) {\n markValid(section.type);\n setValue(setSegment(section, displayValue, amount));\n }\n }\n\n function adjustSection(sectionIndex: number, amount: number) {\n const section = sectionsState.editableSections[sectionIndex];\n if (section) {\n if (validSegments[section.type]) {\n setValue(addSegment(section, displayValue, amount));\n } else {\n markValid(section.type);\n if (Object.keys(validSegments).length >= Object.keys(allSegments).length) {\n setValue(displayValue);\n }\n }\n }\n }\n\n function flushValidSection(sectionIndex: number) {\n const section = sectionsState.editableSections[sectionIndex];\n if (section) {\n delete validSegments[section.type];\n }\n setValidSegments({...validSegments});\n }\n\n function flushAllValidSections() {\n validSegments = {};\n setValidSegments({});\n }\n\n function getSectionValue(_sectionIndex: number) {\n return displayValue;\n }\n\n function setSectionValue(_sectionIndex: number, currentValue: DateTime) {\n setValue(currentValue);\n }\n\n function createPlaceholder() {\n return createPlaceholderValue({\n placeholderValue: props.placeholderValue,\n timeZone,\n }).timeZone(timeZone);\n }\n\n function setValueFromString(str: string) {\n const parseDate = props.parseDateFromString ?? parseDateFromString;\n const date = parseDate(str, format, timeZone);\n if (date.isValid()) {\n handleUpdateDate(date);\n return true;\n }\n return false;\n }\n\n const validationState =\n props.validationState ||\n (isInvalid(value, props.minValue, props.maxValue) ? 'invalid' : undefined) ||\n (value && props.isDateUnavailable?.(value) ? 'invalid' : undefined);\n\n return useBaseDateFieldState({\n value,\n displayValue,\n placeholderValue: props.placeholderValue,\n timeZone,\n validationState,\n editableSections: sectionsState.editableSections,\n formatInfo,\n readOnly: props.readOnly,\n disabled: props.disabled,\n selectedSectionIndexes,\n selectedSections,\n isEmpty: Object.keys(validSegments).length === 0,\n flushAllValidSections,\n flushValidSection,\n setSelectedSections,\n setValue,\n setDate: handleUpdateDate,\n adjustSection,\n setSection,\n getSectionValue,\n setSectionValue,\n createPlaceholder,\n setValueFromString,\n });\n}\n\nfunction useSectionsState(\n sections: DateFieldSectionWithoutPosition[],\n value: DateTime,\n validSegments: AvailableSections,\n) {\n const [state, setState] = React.useState(() => {\n return {\n value,\n sections,\n validSegments,\n editableSections: getEditableSections(sections, value, validSegments),\n };\n });\n\n if (\n sections !== state.sections ||\n validSegments !== state.validSegments ||\n !value.isSame(state.value) ||\n value.timeZone() !== state.value.timeZone() ||\n value.locale() !== state.value.locale()\n ) {\n setState({\n value,\n sections,\n validSegments,\n editableSections: getEditableSections(sections, value, validSegments),\n });\n }\n\n return state;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"useDateFieldState.js","sourceRoot":"../../../../../src","sources":["components/DateField/hooks/useDateFieldState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAC,kBAAkB,EAAE,OAAO,EAAC,MAAM,mBAAmB,CAAC;AAG9D,OAAO,EAAC,sBAAsB,EAAE,SAAS,EAAC,6BAA0B;AACpE,OAAO,EAAC,kBAAkB,EAAC,0CAAuC;AAClE,OAAO,EAAC,cAAc,EAAC,6BAA0B;AAEjD,OAAO,EACH,UAAU,EACV,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,EACb,qBAAqB,EACrB,mBAAmB,EACnB,UAAU,EACV,iBAAiB,GACpB,oBAAiB;AAElB,OAAO,EAAC,qBAAqB,EAAC,mCAAgC;AAuB9D,MAAM,UAAU,iBAAiB,CAAC,KAA4B;IAC1D,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,kBAAkB,CACvC,KAAK,CAAC,KAAK,EACX,KAAK,CAAC,YAAY,IAAI,IAAI,EAC1B,KAAK,CAAC,QAAQ,CACjB,CAAC;IAEF,MAAM,aAAa,GAAG,kBAAkB,CACpC,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,YAAY,IAAI,KAAK,CAAC,gBAAgB,CAC9D,CAAC;IAC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AC,QAAQ,IAAI,WAAW,KAAK,KAAK,CAAC,WAAW,IAAI,KAAK,KAAK,KAAK,CAAC,KAAK,EAAE,CAAC;QAC5F,MAAM,gBAAgB,GAAG,mBAAmB,CAAC,QAAQ,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;QAC3E,QAAQ,CAAC;YACL,KAAK;YACL,QAAQ;YACR,WAAW;YACX,gBAAgB;SACnB,CAAC,CAAC;IACP,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import React from 'react';\n\nimport type {DateTime} from '@gravity-ui/date-utils';\nimport {useControlledState, useLang} from '@gravity-ui/uikit';\n\nimport type {InputBase, Validation, ValueBase} from '../../types';\nimport {createPlaceholderValue, isInvalid} from '../../utils/dates';\nimport {useDefaultTimeZone} from '../../utils/useDefaultTimeZone';\nimport {IncompleteDate} from '../IncompleteDate';\nimport type {FormatSection} from '../types';\nimport {\n addSegment,\n adjustDateToFormat,\n getEditableSections,\n getFormatInfo,\n isEditableSectionType,\n parseDateFromString,\n setSegment,\n useFormatSections,\n} from '../utils';\n\nimport {useBaseDateFieldState} from './useBaseDateFieldState';\nimport type {DateFieldState} from './useBaseDateFieldState';\n\nexport interface DateFieldStateOptions extends ValueBase<DateTime | null>, InputBase, Validation {\n /** The minimum allowed date that a user may select. */\n minValue?: DateTime;\n /** The maximum allowed date that a user may select. */\n maxValue?: DateTime;\n /** Callback that is called for each date of the calendar. If it returns true, then the date is unavailable. */\n isDateUnavailable?: (date: DateTime) => boolean;\n /** Format of the date when rendered in the input. [Available formats](https://day.js.org/docs/en/display/format) */\n format?: string;\n /** A placeholder date that controls the default values of each segment when the user first interacts with them. Defaults to today's date at midnight. */\n placeholderValue?: DateTime;\n /**\n * Which timezone use to show values. Example: 'default', 'system', 'Europe/Amsterdam'.\n * @default The timezone of the `value` or `defaultValue` or `placeholderValue`, 'default' otherwise.\n */\n timeZone?: string;\n /** Custom parser function for parsing pasted date strings. If not provided, the default parser will be used. */\n parseDateFromString?: (dateStr: string, format: string, timeZone?: string) => DateTime;\n}\n\nexport function useDateFieldState(props: DateFieldStateOptions): DateFieldState {\n const [value, setDate] = useControlledState(\n props.value,\n props.defaultValue ?? null,\n props.onUpdate,\n );\n\n const inputTimeZone = useDefaultTimeZone(\n props.value || props.defaultValue || props.placeholderValue,\n );\n const timeZone = props.timeZone || inputTimeZone;\n\n const handleUpdateDate = (v: DateTime | null) => {\n setDate(v ? v.timeZone(inputTimeZone) : v);\n };\n\n const [lastPlaceholder, setLastPlaceholder] = React.useState(props.placeholderValue);\n if (\n (props.placeholderValue &&\n (!lastPlaceholder || !props.placeholderValue.isSame(lastPlaceholder))) ||\n (!props.placeholderValue && lastPlaceholder)\n ) {\n setLastPlaceholder(props.placeholderValue);\n }\n const placeholder = React.useMemo(\n () =>\n createPlaceholderValue({\n placeholderValue: lastPlaceholder,\n timeZone,\n }),\n [lastPlaceholder, timeZone],\n );\n\n const format = props.format || 'L';\n const sections = useFormatSections(format);\n const formatInfo = React.useMemo(() => getFormatInfo(sections), [sections]);\n const allSegments = formatInfo.availableUnits;\n\n const [displayValue, setDisplayValue] = React.useState(() => {\n return new IncompleteDate(value && value.isValid() ? value.timeZone(timeZone) : null);\n });\n\n const [lastValue, setLastValue] = React.useState(value);\n const [lastTimezone, setLastTimezone] = React.useState(timeZone);\n if (\n (value && (!lastValue || !value.isSame(lastValue))) ||\n (value && lastTimezone !== timeZone) ||\n (value === null && lastValue !== null)\n ) {\n setLastValue(value);\n setLastTimezone(timeZone);\n setDisplayValue(new IncompleteDate(value?.timeZone(timeZone)));\n }\n\n const {lang} = useLang();\n const dateValue = React.useMemo(() => {\n return displayValue\n .toDateTime(value?.timeZone(timeZone) ?? placeholder, {\n setDate: formatInfo.hasDate,\n setTime: formatInfo.hasTime,\n })\n .locale(lang);\n }, [displayValue, value, placeholder, formatInfo, timeZone, lang]);\n\n const sectionsState = useSectionsState(sections, displayValue, dateValue);\n\n function setValue(newValue: DateTime | IncompleteDate | null) {\n if (props.disabled || props.readOnly) {\n return;\n }\n\n if (\n newValue === null ||\n (newValue instanceof IncompleteDate && newValue.isCleared(allSegments))\n ) {\n setDate(null);\n setDisplayValue(new IncompleteDate());\n } else if (newValue instanceof IncompleteDate) {\n if (newValue.isComplete(allSegments)) {\n const newDate = newValue.toDateTime(dateValue, {\n setDate: formatInfo.hasDate,\n setTime: formatInfo.hasTime,\n });\n if (newValue.validate(newDate, allSegments)) {\n if (!value || !newDate.isSame(value)) {\n handleUpdateDate(adjustDateToFormat(newDate, formatInfo));\n }\n }\n }\n setDisplayValue(newValue);\n } else if (!value || !newValue.isSame(value)) {\n handleUpdateDate(newValue);\n }\n }\n\n function setSection(sectionIndex: number, amount: number) {\n const section = sectionsState.editableSections[sectionIndex];\n if (section) {\n setValue(setSegment(section, displayValue, amount, dateValue));\n }\n }\n\n function adjustSection(sectionIndex: number, amount: number) {\n const section = sectionsState.editableSections[sectionIndex];\n if (section) {\n setValue(addSegment(section, displayValue, amount, dateValue));\n }\n }\n\n function clearSection(sectionIndex: number) {\n const section = sectionsState.editableSections[sectionIndex];\n if (section && isEditableSectionType(section.type)) {\n setValue(displayValue.clear(section.type));\n }\n }\n\n function setValueFromString(str: string) {\n const parseDate = props.parseDateFromString ?? parseDateFromString;\n const date = parseDate(str, format, timeZone);\n if (date.isValid()) {\n setValue(date);\n return true;\n }\n return false;\n }\n\n function confirmPlaceholder() {\n if (props.disabled || props.readOnly) {\n return;\n }\n\n // If the display value is complete but invalid, we need to constrain it and emit onChange on blur.\n if (displayValue.isComplete(allSegments)) {\n const newValue = displayValue.toDateTime(dateValue, {\n setDate: formatInfo.hasDate,\n setTime: formatInfo.hasTime,\n });\n setValue(adjustDateToFormat(newValue, formatInfo, 'startOf'));\n }\n }\n\n const validationState =\n props.validationState ||\n (isInvalid(value, props.minValue, props.maxValue) ? 'invalid' : undefined) ||\n (value && props.isDateUnavailable?.(value) ? 'invalid' : undefined);\n\n return useBaseDateFieldState({\n value,\n displayValue: dateValue,\n validationState,\n editableSections: sectionsState.editableSections,\n formatInfo,\n readOnly: props.readOnly,\n disabled: props.disabled,\n isEmpty: displayValue.isCleared(allSegments),\n setValue,\n adjustSection,\n setSection,\n clearSection,\n setValueFromString,\n confirmPlaceholder,\n });\n}\n\nfunction useSectionsState(sections: FormatSection[], value: IncompleteDate, placeholder: DateTime) {\n const [state, setState] = React.useState(() => {\n const editableSections = getEditableSections(sections, value, placeholder);\n return {\n value,\n sections,\n placeholder,\n editableSections,\n };\n });\n\n if (sections !== state.sections || placeholder !== state.placeholder || value !== state.value) {\n const editableSections = getEditableSections(sections, value, placeholder);\n setState({\n value,\n sections,\n placeholder,\n editableSections,\n });\n }\n\n return state;\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { DateFieldSection } from "../types.js";
|
|
2
|
+
interface FocusManagerOptions {
|
|
3
|
+
sections: DateFieldSection[];
|
|
4
|
+
}
|
|
5
|
+
interface FocusManager {
|
|
6
|
+
/** Active section index */
|
|
7
|
+
activeSectionIndex: number;
|
|
8
|
+
/** Selected sections */
|
|
9
|
+
selectedSectionIndexes: {
|
|
10
|
+
startIndex: number;
|
|
11
|
+
endIndex: number;
|
|
12
|
+
} | null;
|
|
13
|
+
/** Return true if it is the first section */
|
|
14
|
+
isFistSection: (position: number) => boolean;
|
|
15
|
+
/** Return true if it is the last section */
|
|
16
|
+
isLastSection: (position: number) => boolean;
|
|
17
|
+
/** Focus section in position or all sections. */
|
|
18
|
+
focusSection: (position: number | 'all') => void;
|
|
19
|
+
/** Focuses the next section if present */
|
|
20
|
+
focusNextSection: () => void;
|
|
21
|
+
/** Focuses the previous section if present */
|
|
22
|
+
focusPreviousSection: () => void;
|
|
23
|
+
/** Focuses the first section */
|
|
24
|
+
focusFirstSection: () => void;
|
|
25
|
+
/** Focuses the last section */
|
|
26
|
+
focusLastSection: () => void;
|
|
27
|
+
}
|
|
28
|
+
export declare function useFocusManager({ sections }: FocusManagerOptions): FocusManager;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { isEditableSectionType } from "../utils.js";
|
|
3
|
+
export function useFocusManager({ sections }) {
|
|
4
|
+
const [selectedSections, setSelectedSections] = React.useState(-1);
|
|
5
|
+
const connections = React.useMemo(() => connectEditableSections(sections), [sections]);
|
|
6
|
+
const selectedSectionIndexes = React.useMemo(() => {
|
|
7
|
+
if (selectedSections === -1) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
if (selectedSections === 'all') {
|
|
11
|
+
return {
|
|
12
|
+
startIndex: 0,
|
|
13
|
+
endIndex: connections.length - 1,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
if (typeof selectedSections === 'number') {
|
|
17
|
+
return { startIndex: selectedSections, endIndex: selectedSections };
|
|
18
|
+
}
|
|
19
|
+
return selectedSections;
|
|
20
|
+
}, [selectedSections, connections]);
|
|
21
|
+
const activeSectionIndex = getCurrentEditableSectionIndex(connections, selectedSections);
|
|
22
|
+
return {
|
|
23
|
+
activeSectionIndex,
|
|
24
|
+
selectedSectionIndexes,
|
|
25
|
+
isFistSection(position) {
|
|
26
|
+
const p = connections[position];
|
|
27
|
+
if (!p) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
return position === p.previousEditableSection;
|
|
31
|
+
},
|
|
32
|
+
isLastSection(position) {
|
|
33
|
+
const p = connections[position];
|
|
34
|
+
if (!p) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
return position === p.nextEditableSection;
|
|
38
|
+
},
|
|
39
|
+
focusSection(index) {
|
|
40
|
+
if (index === 'all' || index === -1) {
|
|
41
|
+
setSelectedSections(index);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
setSelectedSections(getCurrentEditableSectionIndex(connections, index));
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
focusNextSection() {
|
|
48
|
+
const currentIndex = selectedSections === 'all' ? 0 : selectedSections;
|
|
49
|
+
const newIndex = connections[currentIndex]?.nextEditableSection ?? -1;
|
|
50
|
+
if (newIndex !== -1) {
|
|
51
|
+
setSelectedSections(newIndex);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
focusPreviousSection() {
|
|
55
|
+
const currentIndex = selectedSections === 'all' ? 0 : selectedSections;
|
|
56
|
+
const newIndex = connections[currentIndex]?.previousEditableSection ?? -1;
|
|
57
|
+
if (newIndex !== -1) {
|
|
58
|
+
setSelectedSections(newIndex);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
focusFirstSection() {
|
|
62
|
+
const newIndex = connections[0]?.previousEditableSection ?? -1;
|
|
63
|
+
if (newIndex !== -1) {
|
|
64
|
+
setSelectedSections(newIndex);
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
focusLastSection() {
|
|
68
|
+
const newIndex = connections[sections.length - 1]?.nextEditableSection ?? -1;
|
|
69
|
+
if (newIndex !== -1) {
|
|
70
|
+
setSelectedSections(newIndex);
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function connectEditableSections(sections) {
|
|
76
|
+
let previousEditableSection = -1;
|
|
77
|
+
const connections = new Array(sections.length);
|
|
78
|
+
for (let i = 0; i < sections.length; i++) {
|
|
79
|
+
const section = sections[i];
|
|
80
|
+
if (!section) {
|
|
81
|
+
throw new Error('section must be defined');
|
|
82
|
+
}
|
|
83
|
+
const connection = {
|
|
84
|
+
type: section.type,
|
|
85
|
+
previousEditableSection,
|
|
86
|
+
nextEditableSection: previousEditableSection,
|
|
87
|
+
};
|
|
88
|
+
connections[i] = connection;
|
|
89
|
+
if (isEditableSectionType(connection.type)) {
|
|
90
|
+
for (let j = Math.max(0, previousEditableSection); j <= i; j++) {
|
|
91
|
+
const prevSection = connections[j];
|
|
92
|
+
if (prevSection) {
|
|
93
|
+
prevSection.nextEditableSection = i;
|
|
94
|
+
if (prevSection.previousEditableSection === -1) {
|
|
95
|
+
prevSection.previousEditableSection = i;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
previousEditableSection = i;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return connections;
|
|
103
|
+
}
|
|
104
|
+
function getCurrentEditableSectionIndex(sections, selectedSections) {
|
|
105
|
+
const currentIndex = selectedSections === 'all' || selectedSections === -1 ? 0 : selectedSections;
|
|
106
|
+
const section = sections[currentIndex];
|
|
107
|
+
if (section && !isEditableSectionType(section.type)) {
|
|
108
|
+
return section.nextEditableSection;
|
|
109
|
+
}
|
|
110
|
+
return isEditableSectionType(section?.type) ? currentIndex : -1;
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=useFocusManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFocusManager.js","sourceRoot":"../../../../../src","sources":["components/DateField/hooks/useFocusManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAC,qBAAqB,EAAC,oBAAiB;AA2B/C,MAAM,UAAU,eAAe,CAAC,EAAC,QAAQ,EAAsB;IAC3D,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAiB,CAAC,CAAC,CAAC,CAAC;IAEnF,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,uBAAuB,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEvF,MAAM,sBAAsB,GAAG,KAAK,CAAC,OAAO,CAGlC,GAAG,EAAE;QACX,IAAI,gBAAgB,KAAK,CAAC,CAAC,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC;QAChB,CAAC;QAED,IAAI,gBAAgB,KAAK,KAAK,EAAE,CAAC;YAC7B,OAAO;gBACH,UAAU,EAAE,CAAC;gBACb,QAAQ,EAAE,WAAW,CAAC,MAAM,GAAG,C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AqB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACpE,CAAC","sourcesContent":["import React from 'react';\n\nimport type {DateFieldSection, DateFieldSectionType} from '../types';\nimport {isEditableSectionType} from '../utils';\n\ninterface FocusManagerOptions {\n sections: DateFieldSection[];\n}\n\ninterface FocusManager {\n /** Active section index */\n activeSectionIndex: number;\n /** Selected sections */\n selectedSectionIndexes: {startIndex: number; endIndex: number} | null;\n /** Return true if it is the first section */\n isFistSection: (position: number) => boolean;\n /** Return true if it is the last section */\n isLastSection: (position: number) => boolean;\n /** Focus section in position or all sections. */\n focusSection: (position: number | 'all') => void;\n /** Focuses the next section if present */\n focusNextSection: () => void;\n /** Focuses the previous section if present */\n focusPreviousSection: () => void;\n /** Focuses the first section */\n focusFirstSection: () => void;\n /** Focuses the last section */\n focusLastSection: () => void;\n}\n\nexport function useFocusManager({sections}: FocusManagerOptions): FocusManager {\n const [selectedSections, setSelectedSections] = React.useState<number | 'all'>(-1);\n\n const connections = React.useMemo(() => connectEditableSections(sections), [sections]);\n\n const selectedSectionIndexes = React.useMemo<{\n startIndex: number;\n endIndex: number;\n } | null>(() => {\n if (selectedSections === -1) {\n return null;\n }\n\n if (selectedSections === 'all') {\n return {\n startIndex: 0,\n endIndex: connections.length - 1,\n };\n }\n\n if (typeof selectedSections === 'number') {\n return {startIndex: selectedSections, endIndex: selectedSections};\n }\n\n return selectedSections;\n }, [selectedSections, connections]);\n\n const activeSectionIndex = getCurrentEditableSectionIndex(connections, selectedSections);\n\n return {\n activeSectionIndex,\n selectedSectionIndexes,\n isFistSection(position) {\n const p = connections[position];\n if (!p) {\n return false;\n }\n return position === p.previousEditableSection;\n },\n isLastSection(position) {\n const p = connections[position];\n if (!p) {\n return false;\n }\n return position === p.nextEditableSection;\n },\n focusSection(index: number | 'all') {\n if (index === 'all' || index === -1) {\n setSelectedSections(index);\n } else {\n setSelectedSections(getCurrentEditableSectionIndex(connections, index));\n }\n },\n focusNextSection() {\n const currentIndex = selectedSections === 'all' ? 0 : selectedSections;\n const newIndex = connections[currentIndex]?.nextEditableSection ?? -1;\n if (newIndex !== -1) {\n setSelectedSections(newIndex);\n }\n },\n focusPreviousSection() {\n const currentIndex = selectedSections === 'all' ? 0 : selectedSections;\n const newIndex = connections[currentIndex]?.previousEditableSection ?? -1;\n if (newIndex !== -1) {\n setSelectedSections(newIndex);\n }\n },\n focusFirstSection() {\n const newIndex = connections[0]?.previousEditableSection ?? -1;\n if (newIndex !== -1) {\n setSelectedSections(newIndex);\n }\n },\n focusLastSection() {\n const newIndex = connections[sections.length - 1]?.nextEditableSection ?? -1;\n if (newIndex !== -1) {\n setSelectedSections(newIndex);\n }\n },\n };\n}\n\ninterface Connection {\n type: DateFieldSectionType;\n previousEditableSection: number;\n nextEditableSection: number;\n}\n\nfunction connectEditableSections(sections: DateFieldSection[]) {\n let previousEditableSection = -1;\n const connections: Connection[] = new Array(sections.length);\n for (let i = 0; i < sections.length; i++) {\n const section = sections[i];\n if (!section) {\n throw new Error('section must be defined');\n }\n\n const connection = {\n type: section.type,\n previousEditableSection,\n nextEditableSection: previousEditableSection,\n };\n connections[i] = connection;\n\n if (isEditableSectionType(connection.type)) {\n for (let j = Math.max(0, previousEditableSection); j <= i; j++) {\n const prevSection = connections[j];\n if (prevSection) {\n prevSection.nextEditableSection = i;\n if (prevSection.previousEditableSection === -1) {\n prevSection.previousEditableSection = i;\n }\n }\n }\n previousEditableSection = i;\n }\n }\n\n return connections;\n}\n\nfunction getCurrentEditableSectionIndex(sections: Connection[], selectedSections: 'all' | number) {\n const currentIndex =\n selectedSections === 'all' || selectedSections === -1 ? 0 : selectedSections;\n const section = sections[currentIndex];\n if (section && !isEditableSectionType(section.type)) {\n return section.nextEditableSection;\n }\n return isEditableSectionType(section?.type) ? currentIndex : -1;\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DateTime } from '@gravity-ui/date-utils';
|
|
2
|
-
import type { DateFieldState } from "../../DateField/index.js";
|
|
3
2
|
import type { DateFieldBase } from "../../types/datePicker.js";
|
|
4
3
|
import type { RangeValue } from "../../types/inputs.js";
|
|
4
|
+
import type { DateFieldState } from "./useBaseDateFieldState.js";
|
|
5
5
|
export interface RangeDateFieldStateOptions extends DateFieldBase<RangeValue<DateTime>> {
|
|
6
6
|
delimiter?: string;
|
|
7
7
|
}
|