@gravity-ui/date-components 3.0.0-beta.0 → 3.0.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/dist/cjs/components/DateField/hooks/useBaseDateFieldState.d.ts +12 -3
- package/dist/cjs/components/DateField/hooks/useBaseDateFieldState.js +6 -15
- package/dist/cjs/components/DateField/hooks/useBaseDateFieldState.js.map +1 -1
- package/dist/cjs/components/DateField/hooks/useDateFieldState.js +5 -11
- package/dist/cjs/components/DateField/hooks/useDateFieldState.js.map +1 -1
- package/dist/cjs/components/DateField/i18n/en.json +1 -0
- package/dist/cjs/components/DateField/i18n/index.d.ts +2 -2
- package/dist/cjs/components/DateField/i18n/ru.json +1 -0
- package/dist/cjs/components/DateField/types.d.ts +9 -1
- package/dist/cjs/components/DateField/types.js.map +1 -1
- package/dist/cjs/components/DateField/utils.d.ts +22 -6
- package/dist/cjs/components/DateField/utils.js +83 -0
- package/dist/cjs/components/DateField/utils.js.map +1 -1
- package/dist/cjs/components/DatePicker/DatePicker.d.ts +2 -2
- package/dist/cjs/components/DatePicker/DatePicker.js +2 -2
- package/dist/cjs/components/DatePicker/DatePicker.js.map +1 -1
- package/dist/cjs/components/DatePicker/MobileCalendar.js +4 -4
- package/dist/cjs/components/DatePicker/MobileCalendar.js.map +1 -1
- package/dist/cjs/components/DatePicker/hooks/datePickerStateFactory.d.ts +13 -3
- package/dist/cjs/components/DatePicker/hooks/datePickerStateFactory.js +17 -15
- package/dist/cjs/components/DatePicker/hooks/datePickerStateFactory.js.map +1 -1
- package/dist/cjs/components/DatePicker/hooks/useDatePickerProps.js +8 -2
- package/dist/cjs/components/DatePicker/hooks/useDatePickerProps.js.map +1 -1
- package/dist/cjs/components/DatePicker/hooks/useDatePickerState.js +4 -2
- package/dist/cjs/components/DatePicker/hooks/useDatePickerState.js.map +1 -1
- package/dist/cjs/components/DatePicker/utils/getCalendarModes.d.ts +5 -0
- package/dist/cjs/components/DatePicker/utils/getCalendarModes.js +21 -0
- package/dist/cjs/components/DatePicker/utils/getCalendarModes.js.map +1 -0
- package/dist/cjs/components/DatePicker/utils/index.d.ts +1 -0
- package/dist/cjs/components/DatePicker/utils/index.js +1 -0
- package/dist/cjs/components/DatePicker/utils/index.js.map +1 -1
- package/dist/cjs/components/RangeDateField/hooks/useRangeDateFieldState.js +8 -16
- package/dist/cjs/components/RangeDateField/hooks/useRangeDateFieldState.js.map +1 -1
- package/dist/cjs/components/RangeDateField/utils/createPlaceholderRangeValue.js +1 -1
- package/dist/cjs/components/RangeDateField/utils/createPlaceholderRangeValue.js.map +1 -1
- package/dist/cjs/components/RangeDatePicker/RangeDatePicker.js +2 -2
- package/dist/cjs/components/RangeDatePicker/RangeDatePicker.js.map +1 -1
- package/dist/cjs/components/RangeDatePicker/hooks/useRangeDatePickerState.d.ts +4 -1
- package/dist/cjs/components/RangeDatePicker/hooks/useRangeDatePickerState.js +11 -4
- package/dist/cjs/components/RangeDatePicker/hooks/useRangeDatePickerState.js.map +1 -1
- package/dist/cjs/components/RelativeDateField/RelativeDateField.d.ts +2 -2
- package/dist/cjs/components/RelativeDateField/RelativeDateField.js +1 -1
- package/dist/cjs/components/RelativeDateField/RelativeDateField.js.map +1 -1
- package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.d.ts +2 -2
- package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.js +2 -2
- package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.js.map +1 -1
- package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.js +8 -1
- package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.js.map +1 -1
- package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerState.js +11 -3
- package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerState.js.map +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/RelativeRangeDatePicker.js +8 -7
- package/dist/cjs/components/RelativeRangeDatePicker/RelativeRangeDatePicker.js.map +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.css +0 -22
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.css.map +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.d.ts +13 -13
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.js +13 -38
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.js.map +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerForm.css +23 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerForm.css.map +1 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerForm.d.ts +33 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerForm.js +39 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerForm.js.map +1 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.d.ts +2 -3
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.js +49 -42
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.js.map +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/Presets.js +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/Presets.js.map +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/Zones.js +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/Zones.js.map +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.d.ts +12 -1
- package/dist/cjs/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.js +5 -2
- package/dist/cjs/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.js.map +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/i18n/index.d.ts +2 -2
- package/dist/cjs/components/RelativeRangeDatePicker/index.d.ts +2 -0
- package/dist/cjs/components/RelativeRangeDatePicker/index.js +3 -1
- package/dist/cjs/components/RelativeRangeDatePicker/index.js.map +1 -1
- package/dist/cjs/components/RelativeRangeDatePicker/types.d.ts +2 -7
- package/dist/cjs/components/RelativeRangeDatePicker/types.js.map +1 -1
- package/dist/cjs/components/index.d.ts +1 -0
- package/dist/cjs/components/index.js.map +1 -1
- package/dist/cjs/components/types/datePicker.d.ts +11 -0
- package/dist/cjs/components/types/datePicker.js.map +1 -1
- package/dist/cjs/components/types/i18n.d.ts +17 -0
- package/dist/cjs/components/types/i18n.js +3 -0
- package/dist/cjs/components/types/i18n.js.map +1 -0
- package/dist/cjs/components/utils/dates.js +1 -1
- package/dist/cjs/components/utils/dates.js.map +1 -1
- package/dist/cjs/components/utils/validation/i18n/ru.json +3 -3
- package/dist/esm/components/DateField/hooks/useBaseDateFieldState.d.ts +12 -3
- package/dist/esm/components/DateField/hooks/useBaseDateFieldState.js +6 -15
- package/dist/esm/components/DateField/hooks/useBaseDateFieldState.js.map +1 -1
- package/dist/esm/components/DateField/hooks/useDateFieldState.js +6 -12
- package/dist/esm/components/DateField/hooks/useDateFieldState.js.map +1 -1
- package/dist/esm/components/DateField/i18n/en.json +1 -0
- package/dist/esm/components/DateField/i18n/index.d.ts +2 -2
- package/dist/esm/components/DateField/i18n/ru.json +1 -0
- package/dist/esm/components/DateField/types.d.ts +9 -1
- package/dist/esm/components/DateField/types.js.map +1 -1
- package/dist/esm/components/DateField/utils.d.ts +22 -6
- package/dist/esm/components/DateField/utils.js +80 -0
- package/dist/esm/components/DateField/utils.js.map +1 -1
- package/dist/esm/components/DatePicker/DatePicker.d.ts +2 -2
- package/dist/esm/components/DatePicker/DatePicker.js +2 -2
- package/dist/esm/components/DatePicker/DatePicker.js.map +1 -1
- package/dist/esm/components/DatePicker/MobileCalendar.js +4 -4
- package/dist/esm/components/DatePicker/MobileCalendar.js.map +1 -1
- package/dist/esm/components/DatePicker/hooks/datePickerStateFactory.d.ts +13 -3
- package/dist/esm/components/DatePicker/hooks/datePickerStateFactory.js +17 -15
- package/dist/esm/components/DatePicker/hooks/datePickerStateFactory.js.map +1 -1
- package/dist/esm/components/DatePicker/hooks/useDatePickerProps.js +9 -3
- package/dist/esm/components/DatePicker/hooks/useDatePickerProps.js.map +1 -1
- package/dist/esm/components/DatePicker/hooks/useDatePickerState.js +2 -0
- package/dist/esm/components/DatePicker/hooks/useDatePickerState.js.map +1 -1
- package/dist/esm/components/DatePicker/utils/getCalendarModes.d.ts +5 -0
- package/dist/esm/components/DatePicker/utils/getCalendarModes.js +18 -0
- package/dist/esm/components/DatePicker/utils/getCalendarModes.js.map +1 -0
- package/dist/esm/components/DatePicker/utils/index.d.ts +1 -0
- package/dist/esm/components/DatePicker/utils/index.js +1 -0
- package/dist/esm/components/DatePicker/utils/index.js.map +1 -1
- package/dist/esm/components/RangeDateField/hooks/useRangeDateFieldState.js +9 -17
- package/dist/esm/components/RangeDateField/hooks/useRangeDateFieldState.js.map +1 -1
- package/dist/esm/components/RangeDateField/utils/createPlaceholderRangeValue.js +1 -1
- package/dist/esm/components/RangeDateField/utils/createPlaceholderRangeValue.js.map +1 -1
- package/dist/esm/components/RangeDatePicker/RangeDatePicker.js +2 -2
- package/dist/esm/components/RangeDatePicker/RangeDatePicker.js.map +1 -1
- package/dist/esm/components/RangeDatePicker/hooks/useRangeDatePickerState.d.ts +4 -1
- package/dist/esm/components/RangeDatePicker/hooks/useRangeDatePickerState.js +10 -3
- package/dist/esm/components/RangeDatePicker/hooks/useRangeDatePickerState.js.map +1 -1
- package/dist/esm/components/RelativeDateField/RelativeDateField.d.ts +2 -2
- package/dist/esm/components/RelativeDateField/RelativeDateField.js +1 -1
- package/dist/esm/components/RelativeDateField/RelativeDateField.js.map +1 -1
- package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.d.ts +2 -2
- package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.js +2 -2
- package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.js.map +1 -1
- package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.js +8 -1
- package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.js.map +1 -1
- package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerState.js +11 -3
- package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerState.js.map +1 -1
- package/dist/esm/components/RelativeRangeDatePicker/RelativeRangeDatePicker.js +8 -7
- package/dist/esm/components/RelativeRangeDatePicker/RelativeRangeDatePicker.js.map +1 -1
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.css +0 -22
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.css.map +1 -1
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.d.ts +13 -13
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.js +15 -40
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.js.map +1 -1
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerForm.css +23 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerForm.css.map +1 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerForm.d.ts +33 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerForm.js +36 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerForm.js.map +1 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.d.ts +2 -3
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.js +49 -42
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.js.map +1 -1
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/Presets.js +2 -2
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/Presets.js.map +1 -1
- package/dist/esm/components/RelativeRangeDatePicker/components/Zones/Zones.js +1 -1
- package/dist/esm/components/RelativeRangeDatePicker/components/Zones/Zones.js.map +1 -1
- package/dist/esm/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.d.ts +12 -1
- package/dist/esm/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.js +5 -3
- package/dist/esm/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.js.map +1 -1
- package/dist/esm/components/RelativeRangeDatePicker/i18n/index.d.ts +2 -2
- package/dist/esm/components/RelativeRangeDatePicker/index.d.ts +2 -0
- package/dist/esm/components/RelativeRangeDatePicker/index.js +1 -0
- package/dist/esm/components/RelativeRangeDatePicker/index.js.map +1 -1
- package/dist/esm/components/RelativeRangeDatePicker/types.d.ts +2 -7
- package/dist/esm/components/RelativeRangeDatePicker/types.js.map +1 -1
- package/dist/esm/components/index.d.ts +1 -0
- package/dist/esm/components/index.js.map +1 -1
- package/dist/esm/components/types/datePicker.d.ts +11 -0
- package/dist/esm/components/types/datePicker.js.map +1 -1
- package/dist/esm/components/types/i18n.d.ts +17 -0
- package/dist/esm/components/types/i18n.js +2 -0
- package/dist/esm/components/types/i18n.js.map +1 -0
- package/dist/esm/components/utils/dates.js +1 -1
- package/dist/esm/components/utils/dates.js.map +1 -1
- package/dist/esm/components/utils/validation/i18n/ru.json +3 -3
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.js","sourceRoot":"../../../../src","sources":["components/types/i18n.ts"],"names":[],"mappings":"","sourcesContent":["import type {i18n as CalendarKeyset} from '../CalendarView/i18n';\nimport type {i18n as DateFieldKeyset} from '../DateField/i18n';\nimport type {i18n as DatePickerKeyset} from '../DatePicker/i18n';\nimport type {i18n as RangeDateSelectionKeyset} from '../RangeDateSelection/i18n';\nimport type {i18n as RelativeDatePickerKeyset} from '../RelativeDatePicker/i18n';\nimport type {i18n as RelativeRangeDatePickerControlKeyset} from '../RelativeRangeDatePicker/components/Control/i18n';\nimport type {i18n as RelativeRangeDatePickerFormKeyset} from '../RelativeRangeDatePicker/components/PickerDialog/i18n';\nimport type {i18n as RelativeRangeDatePickerPresetsKeyset} from '../RelativeRangeDatePicker/components/Presets/i18n';\nimport type {i18n as RelativeRangeDatePickerZonesKeyset} from '../RelativeRangeDatePicker/components/Zones/i18n';\nimport type {i18n as RelativeRangeDatePickerKeyset} from '../RelativeRangeDatePicker/i18n';\nimport type {i18n as ValidationKeyset} from '../utils/validation/i18n';\n\n/* DeepPartial with depth limitation up to 9 */\ntype DeepPartial<T, N extends number = 9> = N extends 0\n ? T\n : Partial<{[P in keyof T]: DeepPartial<T[P], [never, 0, 1, 2, 3, 4, 5, 6, 7, 8][N]>}>;\n\nexport type Keysets = typeof CalendarKeyset.keysetData &\n typeof DateFieldKeyset.keysetData &\n typeof DatePickerKeyset.keysetData &\n typeof RangeDateSelectionKeyset.keysetData &\n typeof RelativeDatePickerKeyset.keysetData &\n typeof RelativeRangeDatePickerKeyset.keysetData &\n typeof RelativeRangeDatePickerFormKeyset.keysetData &\n typeof RelativeRangeDatePickerPresetsKeyset.keysetData &\n typeof RelativeRangeDatePickerZonesKeyset.keysetData &\n typeof RelativeRangeDatePickerControlKeyset.keysetData &\n typeof ValidationKeyset.keysetData;\nexport type PartialKeysets = DeepPartial<Keysets, 2>;\n"]}
|
|
@@ -11,7 +11,7 @@ function isWeekend(date) {
|
|
|
11
11
|
return [0, 6].includes(date.day());
|
|
12
12
|
}
|
|
13
13
|
function createPlaceholderValue({ placeholderValue, timeZone }) {
|
|
14
|
-
return
|
|
14
|
+
return placeholderValue !== null && placeholderValue !== void 0 ? placeholderValue : (0, date_utils_1.dateTime)({ timeZone }).startOf('day');
|
|
15
15
|
}
|
|
16
16
|
function isInvalid(value, minValue, maxValue) {
|
|
17
17
|
if (!value) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dates.js","sourceRoot":"../../../../src","sources":["components/utils/dates.ts"],"names":[],"mappings":";;AAGA,8BAEC;AAMD,
|
|
1
|
+
{"version":3,"file":"dates.js","sourceRoot":"../../../../src","sources":["components/utils/dates.ts"],"names":[],"mappings":";;AAGA,8BAEC;AAMD,wDAEC;AAED,8BAiBC;AAED,wCAaC;AAED,sCAKC;AAED,wCAEC;AA1DD,uDAAgD;AAGhD,SAAgB,SAAS,CAAC,IAAc;IACpC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;AACvC,CAAC;AAMD,SAAgB,sBAAsB,CAAC,EAAC,gBAAgB,EAAE,QAAQ,EAA0B;IACxF,OAAO,gBAAgB,aAAhB,gBAAgB,cAAhB,gBAAgB,GAAI,IAAA,qBAAQ,EAAC,EAAC,QAAQ,EAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AACnE,CAAC;AAED,SAAgB,SAAS,CACrB,KAAkC,EAClC,QAA8B,EAC9B,QAA8B;IAE9B,IAAI,CAAC,KAAK,EAAE,CAAC;QACT,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,IAAI,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QACvC,OAAO,IAAI,CAAC;IAChB,CAAC;IACD,IAAI,QAAQ,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACvC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAgB,cAAc,CAC1B,KAAe,EACf,QAA8B,EAC9B,QAA8B;IAE9B,IAAI,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QACvC,OAAO,QAAQ,CAAC;IACpB,CAAC;IACD,IAAI,QAAQ,IAAI,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACvC,OAAO,QAAQ,CAAC;IACpB,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC;AAED,SAAgB,aAAa,CAAC,IAAc,EAAE,IAAc;IACxD,OAAO,IAAI;SACN,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;SACzB,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;SAC7B,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;AACvC,CAAC;AAED,SAAgB,cAAc,CAAC,IAAc,EAAE,MAAc,EAAE,QAAgB;IAC3E,OAAO,IAAA,qBAAQ,EAAC,EAAC,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AACtE,CAAC","sourcesContent":["import {dateTime} from '@gravity-ui/date-utils';\nimport type {DateTime} from '@gravity-ui/date-utils';\n\nexport function isWeekend(date: DateTime) {\n return [0, 6].includes(date.day());\n}\n\nexport interface PlaceholderValueOptions {\n placeholderValue?: DateTime;\n timeZone?: string;\n}\nexport function createPlaceholderValue({placeholderValue, timeZone}: PlaceholderValueOptions) {\n return placeholderValue ?? dateTime({timeZone}).startOf('day');\n}\n\nexport function isInvalid(\n value: DateTime | null | undefined,\n minValue: DateTime | undefined,\n maxValue: DateTime | undefined,\n) {\n if (!value) {\n return false;\n }\n\n if (minValue && value.isBefore(minValue)) {\n return true;\n }\n if (maxValue && maxValue.isBefore(value)) {\n return true;\n }\n\n return false;\n}\n\nexport function constrainValue(\n value: DateTime,\n minValue: DateTime | undefined,\n maxValue: DateTime | undefined,\n) {\n if (minValue && value.isBefore(minValue)) {\n return minValue;\n }\n if (maxValue && maxValue.isBefore(value)) {\n return maxValue;\n }\n\n return value;\n}\n\nexport function mergeDateTime(date: DateTime, time: DateTime) {\n return date\n .set('hours', time.hour())\n .set('minutes', time.minute())\n .set('seconds', time.second());\n}\n\nexport function formatDateTime(date: DateTime, format: string, timezone: string) {\n return dateTime({input: date, timeZone: timezone}).format(format);\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
|
-
"Value must be {minValue} or later.": "{value} должно ровняться {minValue} или быть позже.",
|
|
3
|
-
"Value must be {maxValue} or earlier.": "{value} должно ровняться {maxValue} или быть раньше.",
|
|
2
|
+
"Value must be {minValue} or later.": "{{value}} должно ровняться {{minValue}} или быть позже.",
|
|
3
|
+
"Value must be {maxValue} or earlier.": "{{value}} должно ровняться {{maxValue}} или быть раньше.",
|
|
4
4
|
"Selected date unavailable.": "Выбранная дата недоступна.",
|
|
5
|
-
"Value is required.": "{value} обязательно."
|
|
5
|
+
"Value is required.": "{{value}} обязательно."
|
|
6
6
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DateTime } from '@gravity-ui/date-utils';
|
|
2
2
|
import type { ValidationState } from "../../types/index.js";
|
|
3
|
-
import type { DateFieldSection } from "../types.js";
|
|
3
|
+
import type { DateFieldSection, FormatInfo } from "../types.js";
|
|
4
4
|
export type BaseDateFieldStateOptions<T = DateTime> = {
|
|
5
5
|
value: T | null;
|
|
6
6
|
displayValue: T;
|
|
@@ -8,6 +8,7 @@ export type BaseDateFieldStateOptions<T = DateTime> = {
|
|
|
8
8
|
timeZone: string;
|
|
9
9
|
validationState?: ValidationState;
|
|
10
10
|
editableSections: DateFieldSection[];
|
|
11
|
+
formatInfo: FormatInfo;
|
|
11
12
|
readOnly?: boolean;
|
|
12
13
|
disabled?: boolean;
|
|
13
14
|
selectedSectionIndexes: {
|
|
@@ -47,9 +48,17 @@ export type DateFieldState<T = DateTime> = {
|
|
|
47
48
|
disabled?: boolean;
|
|
48
49
|
/** A list of segments for the current value. */
|
|
49
50
|
sections: DateFieldSection[];
|
|
50
|
-
/**
|
|
51
|
+
/** Some info about available sections */
|
|
52
|
+
formatInfo: FormatInfo;
|
|
53
|
+
/**
|
|
54
|
+
* @deprecated use formatInfo.hasDate instead.
|
|
55
|
+
* Whether the the format is containing date parts
|
|
56
|
+
*/
|
|
51
57
|
hasDate: boolean;
|
|
52
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* @deprecated use formatInfo.hasTime instead.
|
|
60
|
+
* Whether the the format is containing time parts
|
|
61
|
+
*/
|
|
53
62
|
hasTime: boolean;
|
|
54
63
|
/** Selected sections */
|
|
55
64
|
selectedSectionIndexes: {
|
|
@@ -3,6 +3,7 @@ import { createPlaceholderValue } from "../../utils/dates.js";
|
|
|
3
3
|
import { EDITABLE_SEGMENTS, formatSections, getCurrentEditableSectionIndex, getDurationUnitFromSectionType, } from "../utils.js";
|
|
4
4
|
const PAGE_STEP = {
|
|
5
5
|
year: 5,
|
|
6
|
+
quarter: 2,
|
|
6
7
|
month: 2,
|
|
7
8
|
weekday: 3,
|
|
8
9
|
day: 7,
|
|
@@ -11,20 +12,8 @@ const PAGE_STEP = {
|
|
|
11
12
|
second: 15,
|
|
12
13
|
};
|
|
13
14
|
export function useBaseDateFieldState(props) {
|
|
14
|
-
const { value, validationState, displayValue, editableSections, selectedSectionIndexes, selectedSections, isEmpty, flushAllValidSections, flushValidSection, setSelectedSections, setValue, setDate, adjustSection, setSection, getSectionValue, setSectionValue, createPlaceholder, setValueFromString, } = props;
|
|
15
|
+
const { value, validationState, displayValue, editableSections, formatInfo, selectedSectionIndexes, selectedSections, isEmpty, flushAllValidSections, flushValidSection, setSelectedSections, setValue, setDate, adjustSection, setSection, getSectionValue, setSectionValue, createPlaceholder, setValueFromString, } = props;
|
|
15
16
|
const enteredKeys = React.useRef('');
|
|
16
|
-
const { hasDate, hasTime } = React.useMemo(() => {
|
|
17
|
-
let hasDateInner = false;
|
|
18
|
-
let hasTimeInner = false;
|
|
19
|
-
for (const s of editableSections) {
|
|
20
|
-
hasTimeInner || (hasTimeInner = ['hour', 'minute', 'second'].includes(s.type));
|
|
21
|
-
hasDateInner || (hasDateInner = ['day', 'month', 'year'].includes(s.type));
|
|
22
|
-
}
|
|
23
|
-
return {
|
|
24
|
-
hasTime: hasTimeInner,
|
|
25
|
-
hasDate: hasDateInner,
|
|
26
|
-
};
|
|
27
|
-
}, [editableSections]);
|
|
28
17
|
return {
|
|
29
18
|
value,
|
|
30
19
|
isEmpty,
|
|
@@ -35,8 +24,9 @@ export function useBaseDateFieldState(props) {
|
|
|
35
24
|
readOnly: props.readOnly,
|
|
36
25
|
disabled: props.disabled,
|
|
37
26
|
sections: editableSections,
|
|
38
|
-
|
|
39
|
-
|
|
27
|
+
formatInfo,
|
|
28
|
+
hasDate: formatInfo.hasDate,
|
|
29
|
+
hasTime: formatInfo.hasTime,
|
|
40
30
|
selectedSectionIndexes,
|
|
41
31
|
validationState,
|
|
42
32
|
setSelectedSections(position) {
|
|
@@ -279,6 +269,7 @@ export function useBaseDateFieldState(props) {
|
|
|
279
269
|
case 'hour':
|
|
280
270
|
case 'minute':
|
|
281
271
|
case 'second':
|
|
272
|
+
case 'quarter':
|
|
282
273
|
case 'year': {
|
|
283
274
|
if (!Number.isInteger(Number(newValue))) {
|
|
284
275
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBaseDateFieldState.js","sourceRoot":"../../../../../src","sources":["components/DateField/hooks/useBaseDateFieldState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,OAAO,EAAC,sBAAsB,EAAC,6BAA0B;AAEzD,OAAO,EACH,iBAAiB,EACjB,cAAc,EACd,8BAA8B,EAC9B,8BAA8B,GACjC,oBAAiB;AAElB,MAAM,SAAS,GAAkD;IAC7D,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;IACR,OAAO,EAAE,CAAC;IACV,GAAG,EAAE,CAAC;IACN,IAAI,EAAE,CAAC;IACP,MAAM,EAAE,EAAE;IACV,MAAM,EAAE,EAAE;CACb,CAAC;AA8FF,MAAM,UAAU,qBAAq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EAAE,CAAC;gBACnB,KAAK,KAAK,CAAC;gBACX,KAAK,MAAM,CAAC;gBACZ,KAAK,QAAQ,CAAC;gBACd,KAAK,QAAQ,CAAC;gBACd,KAAK,MAAM,CAAC,CAAC,CAAC;oBACV,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;wBACtC,OAAO;oBACX,CAAC;oBACD,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;oBACrC,aAAa,CAAC,WAAW,CAAC,CAAC;oBAC3B,MAAM;gBACV,CAAC;gBACD,KAAK,WAAW,CAAC,CAAC,CAAC;oBACf,aAAa,CAAC,QAAQ,CAAC,CAAC;oBACxB,MAAM;gBACV,CAAC;gBACD,KAAK,SAAS,CAAC;gBACf,KAAK,OAAO,CAAC,CAAC,CAAC;oBACX,IAAI,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;wBACrC,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;wBACrC,aAAa,CAAC,WAAW,CAAC,CAAC;oBAC/B,CAAC;yBAAM,CAAC;wBACJ,aAAa,CAAC,QAAQ,CAAC,CAAC;oBAC5B,CAAC;oBACD,MAAM;gBACV,CAAC;YACL,CAAC;QACL,CAAC;QACD,kBAAkB,CAAC,GAAW;YAC1B,WAAW,CAAC,OAAO,GAAG,EAAE,CAAC;YACzB,OAAO,kBAAkB,CAAC,GAAG,CAAC,CAAC;QACnC,CAAC;KACJ,CAAC;AACN,CAAC","sourcesContent":["import React from 'react';\n\nimport type {DateTime} from '@gravity-ui/date-utils';\n\nimport type {ValidationState} from '../../types';\nimport {createPlaceholderValue} from '../../utils/dates';\nimport type {DateFieldSection, DateFieldSectionType} from '../types';\nimport {\n EDITABLE_SEGMENTS,\n formatSections,\n getCurrentEditableSectionIndex,\n getDurationUnitFromSectionType,\n} from '../utils';\n\nconst PAGE_STEP: Partial<Record<DateFieldSectionType, number>> = {\n year: 5,\n month: 2,\n weekday: 3,\n day: 7,\n hour: 2,\n minute: 15,\n second: 15,\n};\n\nexport type BaseDateFieldStateOptions<T = DateTime> = {\n value: T | null;\n displayValue: T;\n placeholderValue?: DateTime;\n timeZone: string;\n validationState?: ValidationState;\n editableSections: DateFieldSection[];\n readOnly?: boolean;\n disabled?: boolean;\n selectedSectionIndexes: {startIndex: number; endIndex: number} | null;\n selectedSections: number | 'all';\n isEmpty: boolean;\n flushAllValidSections: () => void;\n flushValidSection: (sectionIndex: number) => void;\n setSelectedSections: (position: number | 'all') => void;\n setValue: (value: T) => void;\n setDate: (value: T | null) => void;\n adjustSection: (sectionIndex: number, amount: number) => void;\n setSection: (sectionIndex: number, amount: number) => void;\n getSectionValue: (sectionIndex: number) => DateTime;\n setSectionValue: (sectionIndex: number, currentValue: DateTime) => void;\n createPlaceholder: () => T;\n setValueFromString: (str: string) => boolean;\n};\n\nexport type DateFieldState<T = DateTime> = {\n /** The current field value. */\n value: T | null;\n /** Is no part of value is filled. */\n isEmpty: boolean;\n /** The current used value. value or placeholderValue */\n displayValue: T;\n /** Sets the field's value. */\n setValue: (value: T) => void;\n /** Sets the date value. */\n setDate: (value: T | null) => void;\n /** Formatted value */\n text: string;\n /** Whether the field is read only. */\n readOnly?: boolean;\n /** Whether the field is disabled. */\n disabled?: boolean;\n /** A list of segments for the current value. */\n sections: DateFieldSection[];\n /** Whether the the format is containing date parts */\n hasDate: boolean;\n /** Whether the the format is containing time parts */\n hasTime: boolean;\n /** Selected sections */\n selectedSectionIndexes: {startIndex: number; endIndex: number} | null;\n /** The current validation state of the date field, based on the `validationState`, `minValue`, and `maxValue` props. */\n validationState?: ValidationState;\n /** Sets selection for segment in position. */\n setSelectedSections: (position: number | 'all') => void;\n /** Focuses segment in position */\n focusSectionInPosition: (position: number) => void;\n /** Focuses the next segment if present */\n focusNextSection: () => void;\n /** Focuses the previous segment if present */\n focusPreviousSection: () => void;\n /** Focuses the first segment */\n focusFirstSection: () => void;\n /** Focuses the last segment */\n focusLastSection: () => void;\n /** Increments the currently selected segment. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit. */\n increment: () => void;\n /** Decrements the currently selected segment. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit. */\n decrement: () => void;\n /**\n * Increments the currently selected segment by a larger amount, rounding it to the nearest increment.\n * The amount to increment by depends on the field, for example 15 minutes, 7 days, and 5 years.\n * Upon reaching the minimum or maximum value, the value wraps around to the opposite limit.\n */\n incrementPage: () => void;\n /**\n * Decrements the currently selected segment by a larger amount, rounding it to the nearest decrement.\n * The amount to increment by depends on the field, for example 15 minutes, 7 days, and 5 years.\n * Upon reaching the minimum or maximum value, the value wraps around to the opposite limit.\n */\n decrementPage: () => void;\n incrementToMax: () => void;\n decrementToMin: () => void;\n /** Clears the value of the currently selected segment, reverting it to the placeholder. */\n clearSection: () => void;\n /** Clears all segments, reverting them to the placeholder. */\n clearAll: () => void;\n /** Handles input key in the currently selected segment */\n onInput: (key: string) => void;\n //** Tries to set value from str. Supports date in input format or ISO */\n setValueFromString: (str: string) => boolean;\n};\n\nexport function useBaseDateFieldState<T = DateTime>(\n props: BaseDateFieldStateOptions<T>,\n): DateFieldState<T> {\n const {\n value,\n validationState,\n displayValue,\n editableSections,\n selectedSectionIndexes,\n selectedSections,\n isEmpty,\n flushAllValidSections,\n flushValidSection,\n setSelectedSections,\n setValue,\n setDate,\n adjustSection,\n setSection,\n getSectionValue,\n setSectionValue,\n createPlaceholder,\n setValueFromString,\n } = props;\n\n const enteredKeys = React.useRef('');\n\n const {hasDate, hasTime} = React.useMemo(() => {\n let hasDateInner = false;\n let hasTimeInner = false;\n for (const s of editableSections) {\n hasTimeInner ||= ['hour', 'minute', 'second'].includes(s.type);\n hasDateInner ||= ['day', 'month', 'year'].includes(s.type);\n }\n return {\n hasTime: hasTimeInner,\n hasDate: hasDateInner,\n };\n }, [editableSections]);\n\n return {\n value,\n isEmpty,\n displayValue,\n setValue,\n setDate,\n text: formatSections(editableSections),\n readOnly: props.readOnly,\n disabled: props.disabled,\n sections: editableSections,\n hasDate,\n hasTime,\n selectedSectionIndexes,\n validationState,\n setSelectedSections(position) {\n enteredKeys.current = '';\n setSelectedSections(position);\n },\n focusSectionInPosition(position) {\n const nextSectionIndex = this.sections.findIndex((s) => s.end >= position);\n const index = nextSectionIndex === -1 ? 0 : nextSectionIndex;\n const nextSection = this.sections[index];\n if (nextSection) {\n this.setSelectedSections(\n EDITABLE_SEGMENTS[nextSection.type] ? index : nextSection.nextEditableSection,\n );\n }\n },\n focusNextSection() {\n const currentIndex = selectedSections === 'all' ? 0 : selectedSections;\n const newIndex = this.sections[currentIndex]?.nextEditableSection ?? -1;\n if (newIndex !== -1) {\n this.setSelectedSections(newIndex);\n }\n },\n focusPreviousSection() {\n const currentIndex = selectedSections === 'all' ? 0 : selectedSections;\n const newIndex = this.sections[currentIndex]?.previousEditableSection ?? -1;\n if (newIndex !== -1) {\n this.setSelectedSections(newIndex);\n }\n },\n focusFirstSection() {\n const newIndex = this.sections[0]?.previousEditableSection ?? -1;\n if (newIndex !== -1) {\n setSelectedSections(newIndex);\n }\n },\n focusLastSection() {\n const newIndex = this.sections[this.sections.length - 1]?.nextEditableSection ?? -1;\n if (newIndex !== -1) {\n this.setSelectedSections(newIndex);\n }\n },\n increment() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n adjustSection(sectionIndex, 1);\n }\n },\n decrement() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n adjustSection(sectionIndex, -1);\n }\n },\n incrementPage() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n adjustSection(sectionIndex, PAGE_STEP[this.sections[sectionIndex].type] || 1);\n }\n },\n decrementPage() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n adjustSection(sectionIndex, -(PAGE_STEP[this.sections[sectionIndex].type] || 1));\n }\n },\n incrementToMax() {\n if (this.readOnly || this.disabled) {\n return;\n }\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n const section = this.sections[sectionIndex];\n if (typeof section.maxValue === 'number') {\n setSection(sectionIndex, section.maxValue);\n }\n }\n },\n decrementToMin() {\n if (this.readOnly || this.disabled) {\n return;\n }\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n const section = this.sections[sectionIndex];\n if (typeof section.minValue === 'number') {\n setSection(sectionIndex, section.minValue);\n }\n }\n },\n clearSection() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n if (selectedSections === 'all') {\n this.clearAll();\n return;\n }\n\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex === -1) {\n return;\n }\n\n flushValidSection(sectionIndex);\n\n const section = this.sections[sectionIndex];\n\n const placeholder = createPlaceholderValue({\n placeholderValue: props.placeholderValue,\n timeZone: props.timeZone,\n }).timeZone(props.timeZone);\n\n const displayPortion = getSectionValue(sectionIndex);\n let currentValue = displayPortion;\n\n // Reset day period to default without changing the hour.\n if (section.type === 'dayPeriod') {\n const isPM = displayPortion.hour() >= 12;\n const shouldBePM = placeholder.hour() >= 12;\n if (isPM && !shouldBePM) {\n currentValue = displayPortion.set('hour', displayPortion.hour() - 12);\n } else if (!isPM && shouldBePM) {\n currentValue = displayPortion.set('hour', displayPortion.hour() + 12);\n }\n } else {\n const type = getDurationUnitFromSectionType(section.type);\n currentValue = displayPortion.set(type, placeholder[type]());\n }\n\n setSectionValue(sectionIndex, currentValue);\n },\n clearAll() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n flushAllValidSections();\n if (value !== null) {\n setDate(null);\n }\n\n const date = createPlaceholder();\n\n setValue(date);\n },\n onInput(key: string) {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex === -1) {\n return;\n }\n\n const section = this.sections[sectionIndex];\n let newValue = enteredKeys.current + key;\n\n const onInputNumber = (numberValue: number) => {\n let sectionValue = section.type === 'month' ? numberValue - 1 : numberValue;\n const allowsZero = section.minValue === 0;\n if (\n section.type === 'hour' &&\n (section.minValue === 12 || section.maxValue === 11)\n ) {\n if (numberValue > 12) {\n sectionValue = Number(key);\n }\n if (section.minValue === 12 && sectionValue > 1) {\n sectionValue += 12;\n }\n } else if (sectionValue > (section.maxValue ?? 0)) {\n sectionValue = Number(key) - (section.type === 'month' ? 1 : 0);\n newValue = key;\n if (sectionValue > (section.maxValue ?? 0)) {\n enteredKeys.current = '';\n return;\n }\n }\n\n const shouldSetValue = sectionValue > 0 || (sectionValue === 0 && allowsZero);\n if (shouldSetValue) {\n setSection(sectionIndex, sectionValue);\n }\n\n if (\n Number(numberValue + '0') > (section.maxValue ?? 0) ||\n newValue.length >= String(section.maxValue).length\n ) {\n enteredKeys.current = '';\n if (shouldSetValue) {\n this.focusNextSection();\n }\n } else {\n enteredKeys.current = newValue;\n }\n };\n\n const onInputString = (stringValue: string) => {\n const options = section.options ?? [];\n let sectionValue = stringValue.toLocaleUpperCase();\n let foundOptions = options.filter((v) => v.startsWith(sectionValue));\n if (foundOptions.length === 0) {\n if (stringValue !== key) {\n sectionValue = key.toLocaleUpperCase();\n foundOptions = options.filter((v) => v.startsWith(sectionValue));\n }\n if (foundOptions.length === 0) {\n enteredKeys.current = '';\n return;\n }\n }\n const foundValue = foundOptions[0];\n const index = options.indexOf(foundValue);\n\n if (section.type === 'dayPeriod') {\n setSection(sectionIndex, index === 1 ? 12 : 0);\n } else {\n setSection(sectionIndex, index);\n }\n\n if (foundOptions.length > 1) {\n enteredKeys.current = newValue;\n } else {\n enteredKeys.current = '';\n this.focusNextSection();\n }\n };\n\n switch (section.type) {\n case 'day':\n case 'hour':\n case 'minute':\n case 'second':\n case 'year': {\n if (!Number.isInteger(Number(newValue))) {\n return;\n }\n const numberValue = Number(newValue);\n onInputNumber(numberValue);\n break;\n }\n case 'dayPeriod': {\n onInputString(newValue);\n break;\n }\n case 'weekday':\n case 'month': {\n if (Number.isInteger(Number(newValue))) {\n const numberValue = Number(newValue);\n onInputNumber(numberValue);\n } else {\n onInputString(newValue);\n }\n break;\n }\n }\n },\n setValueFromString(str: string) {\n enteredKeys.current = '';\n return setValueFromString(str);\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"useBaseDateFieldState.js","sourceRoot":"../../../../../src","sources":["components/DateField/hooks/useBaseDateFieldState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,OAAO,EAAC,sBAAsB,EAAC,6BAA0B;AAEzD,OAAO,EACH,iBAAiB,EACjB,cAAc,EACd,8BAA8B,EAC9B,8BAA8B,GACjC,oBAAiB;AAElB,MAAM,SAAS,GAAkD;IAC7D,IAAI,EAAE,CAAC;IACP,OAAO,EAAE,CAAC;IACV,KAAK,EAAE,CAAC;IACR,OAAO,EAAE,CAAC;IACV,GAAG,EAAE,CAAC;IACN,IAAI,EAAE,CAAC;IACP,MAAM,EAAE,EAAE;IACV,MAAM,EAAE,EAAE;CACb,CAAC;AAuGF,MAAM,UAAU,qBAAqB,CACjC,KAAmC;IAEnC,MAAM,EACF,KAAK,EACL,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,UAAU,EACV,sBAAsB,EACtB,gBAAgB,EAChB,OAAO,EACP,qBAAqB,EACrB,iBAAiB,EACjB,mBAAmB,EACnB,QA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C;wBACrC,aAAa,CAAC,WAAW,CAAC,CAAC;oBAC/B,CAAC;yBAAM,CAAC;wBACJ,aAAa,CAAC,QAAQ,CAAC,CAAC;oBAC5B,CAAC;oBACD,MAAM;gBACV,CAAC;YACL,CAAC;QACL,CAAC;QACD,kBAAkB,CAAC,GAAW;YAC1B,WAAW,CAAC,OAAO,GAAG,EAAE,CAAC;YACzB,OAAO,kBAAkB,CAAC,GAAG,CAAC,CAAC;QACnC,CAAC;KACJ,CAAC;AACN,CAAC","sourcesContent":["import React from 'react';\n\nimport type {DateTime} from '@gravity-ui/date-utils';\n\nimport type {ValidationState} from '../../types';\nimport {createPlaceholderValue} from '../../utils/dates';\nimport type {DateFieldSection, DateFieldSectionType, FormatInfo} from '../types';\nimport {\n EDITABLE_SEGMENTS,\n formatSections,\n getCurrentEditableSectionIndex,\n getDurationUnitFromSectionType,\n} from '../utils';\n\nconst PAGE_STEP: Partial<Record<DateFieldSectionType, number>> = {\n year: 5,\n quarter: 2,\n month: 2,\n weekday: 3,\n day: 7,\n hour: 2,\n minute: 15,\n second: 15,\n};\n\nexport type BaseDateFieldStateOptions<T = DateTime> = {\n value: T | null;\n displayValue: T;\n placeholderValue?: DateTime;\n timeZone: string;\n validationState?: ValidationState;\n editableSections: DateFieldSection[];\n formatInfo: FormatInfo;\n readOnly?: boolean;\n disabled?: boolean;\n selectedSectionIndexes: {startIndex: number; endIndex: number} | null;\n selectedSections: number | 'all';\n isEmpty: boolean;\n flushAllValidSections: () => void;\n flushValidSection: (sectionIndex: number) => void;\n setSelectedSections: (position: number | 'all') => void;\n setValue: (value: T) => void;\n setDate: (value: T | null) => void;\n adjustSection: (sectionIndex: number, amount: number) => void;\n setSection: (sectionIndex: number, amount: number) => void;\n getSectionValue: (sectionIndex: number) => DateTime;\n setSectionValue: (sectionIndex: number, currentValue: DateTime) => void;\n createPlaceholder: () => T;\n setValueFromString: (str: string) => boolean;\n};\n\nexport type DateFieldState<T = DateTime> = {\n /** The current field value. */\n value: T | null;\n /** Is no part of value is filled. */\n isEmpty: boolean;\n /** The current used value. value or placeholderValue */\n displayValue: T;\n /** Sets the field's value. */\n setValue: (value: T) => void;\n /** Sets the date value. */\n setDate: (value: T | null) => void;\n /** Formatted value */\n text: string;\n /** Whether the field is read only. */\n readOnly?: boolean;\n /** Whether the field is disabled. */\n disabled?: boolean;\n /** A list of segments for the current value. */\n sections: DateFieldSection[];\n /** Some info about available sections */\n formatInfo: FormatInfo;\n /**\n * @deprecated use formatInfo.hasDate instead.\n * Whether the the format is containing date parts\n */\n hasDate: boolean;\n /**\n * @deprecated use formatInfo.hasTime instead.\n * Whether the the format is containing time parts\n */\n hasTime: boolean;\n /** Selected sections */\n selectedSectionIndexes: {startIndex: number; endIndex: number} | null;\n /** The current validation state of the date field, based on the `validationState`, `minValue`, and `maxValue` props. */\n validationState?: ValidationState;\n /** Sets selection for segment in position. */\n setSelectedSections: (position: number | 'all') => void;\n /** Focuses segment in position */\n focusSectionInPosition: (position: number) => void;\n /** Focuses the next segment if present */\n focusNextSection: () => void;\n /** Focuses the previous segment if present */\n focusPreviousSection: () => void;\n /** Focuses the first segment */\n focusFirstSection: () => void;\n /** Focuses the last segment */\n focusLastSection: () => void;\n /** Increments the currently selected segment. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit. */\n increment: () => void;\n /** Decrements the currently selected segment. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit. */\n decrement: () => void;\n /**\n * Increments the currently selected segment by a larger amount, rounding it to the nearest increment.\n * The amount to increment by depends on the field, for example 15 minutes, 7 days, and 5 years.\n * Upon reaching the minimum or maximum value, the value wraps around to the opposite limit.\n */\n incrementPage: () => void;\n /**\n * Decrements the currently selected segment by a larger amount, rounding it to the nearest decrement.\n * The amount to increment by depends on the field, for example 15 minutes, 7 days, and 5 years.\n * Upon reaching the minimum or maximum value, the value wraps around to the opposite limit.\n */\n decrementPage: () => void;\n incrementToMax: () => void;\n decrementToMin: () => void;\n /** Clears the value of the currently selected segment, reverting it to the placeholder. */\n clearSection: () => void;\n /** Clears all segments, reverting them to the placeholder. */\n clearAll: () => void;\n /** Handles input key in the currently selected segment */\n onInput: (key: string) => void;\n //** Tries to set value from str. Supports date in input format or ISO */\n setValueFromString: (str: string) => boolean;\n};\n\nexport function useBaseDateFieldState<T = DateTime>(\n props: BaseDateFieldStateOptions<T>,\n): DateFieldState<T> {\n const {\n value,\n validationState,\n displayValue,\n editableSections,\n formatInfo,\n selectedSectionIndexes,\n selectedSections,\n isEmpty,\n flushAllValidSections,\n flushValidSection,\n setSelectedSections,\n setValue,\n setDate,\n adjustSection,\n setSection,\n getSectionValue,\n setSectionValue,\n createPlaceholder,\n setValueFromString,\n } = props;\n\n const enteredKeys = React.useRef('');\n\n return {\n value,\n isEmpty,\n displayValue,\n setValue,\n setDate,\n text: formatSections(editableSections),\n readOnly: props.readOnly,\n disabled: props.disabled,\n sections: editableSections,\n formatInfo,\n hasDate: formatInfo.hasDate,\n hasTime: formatInfo.hasTime,\n selectedSectionIndexes,\n validationState,\n setSelectedSections(position) {\n enteredKeys.current = '';\n setSelectedSections(position);\n },\n focusSectionInPosition(position) {\n const nextSectionIndex = this.sections.findIndex((s) => s.end >= position);\n const index = nextSectionIndex === -1 ? 0 : nextSectionIndex;\n const nextSection = this.sections[index];\n if (nextSection) {\n this.setSelectedSections(\n EDITABLE_SEGMENTS[nextSection.type] ? index : nextSection.nextEditableSection,\n );\n }\n },\n focusNextSection() {\n const currentIndex = selectedSections === 'all' ? 0 : selectedSections;\n const newIndex = this.sections[currentIndex]?.nextEditableSection ?? -1;\n if (newIndex !== -1) {\n this.setSelectedSections(newIndex);\n }\n },\n focusPreviousSection() {\n const currentIndex = selectedSections === 'all' ? 0 : selectedSections;\n const newIndex = this.sections[currentIndex]?.previousEditableSection ?? -1;\n if (newIndex !== -1) {\n this.setSelectedSections(newIndex);\n }\n },\n focusFirstSection() {\n const newIndex = this.sections[0]?.previousEditableSection ?? -1;\n if (newIndex !== -1) {\n setSelectedSections(newIndex);\n }\n },\n focusLastSection() {\n const newIndex = this.sections[this.sections.length - 1]?.nextEditableSection ?? -1;\n if (newIndex !== -1) {\n this.setSelectedSections(newIndex);\n }\n },\n increment() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n adjustSection(sectionIndex, 1);\n }\n },\n decrement() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n adjustSection(sectionIndex, -1);\n }\n },\n incrementPage() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n adjustSection(sectionIndex, PAGE_STEP[this.sections[sectionIndex].type] || 1);\n }\n },\n decrementPage() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n adjustSection(sectionIndex, -(PAGE_STEP[this.sections[sectionIndex].type] || 1));\n }\n },\n incrementToMax() {\n if (this.readOnly || this.disabled) {\n return;\n }\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n const section = this.sections[sectionIndex];\n if (typeof section.maxValue === 'number') {\n setSection(sectionIndex, section.maxValue);\n }\n }\n },\n decrementToMin() {\n if (this.readOnly || this.disabled) {\n return;\n }\n enteredKeys.current = '';\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex !== -1) {\n const section = this.sections[sectionIndex];\n if (typeof section.minValue === 'number') {\n setSection(sectionIndex, section.minValue);\n }\n }\n },\n clearSection() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n if (selectedSections === 'all') {\n this.clearAll();\n return;\n }\n\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex === -1) {\n return;\n }\n\n flushValidSection(sectionIndex);\n\n const section = this.sections[sectionIndex];\n\n const placeholder = createPlaceholderValue({\n placeholderValue: props.placeholderValue,\n timeZone: props.timeZone,\n }).timeZone(props.timeZone);\n\n const displayPortion = getSectionValue(sectionIndex);\n let currentValue = displayPortion;\n\n // Reset day period to default without changing the hour.\n if (section.type === 'dayPeriod') {\n const isPM = displayPortion.hour() >= 12;\n const shouldBePM = placeholder.hour() >= 12;\n if (isPM && !shouldBePM) {\n currentValue = displayPortion.set('hour', displayPortion.hour() - 12);\n } else if (!isPM && shouldBePM) {\n currentValue = displayPortion.set('hour', displayPortion.hour() + 12);\n }\n } else {\n const type = getDurationUnitFromSectionType(section.type);\n currentValue = displayPortion.set(type, placeholder[type]());\n }\n\n setSectionValue(sectionIndex, currentValue);\n },\n clearAll() {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n enteredKeys.current = '';\n flushAllValidSections();\n if (value !== null) {\n setDate(null);\n }\n\n const date = createPlaceholder();\n\n setValue(date);\n },\n onInput(key: string) {\n if (this.readOnly || this.disabled) {\n return;\n }\n\n const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);\n if (sectionIndex === -1) {\n return;\n }\n\n const section = this.sections[sectionIndex];\n let newValue = enteredKeys.current + key;\n\n const onInputNumber = (numberValue: number) => {\n let sectionValue = section.type === 'month' ? numberValue - 1 : numberValue;\n const allowsZero = section.minValue === 0;\n if (\n section.type === 'hour' &&\n (section.minValue === 12 || section.maxValue === 11)\n ) {\n if (numberValue > 12) {\n sectionValue = Number(key);\n }\n if (section.minValue === 12 && sectionValue > 1) {\n sectionValue += 12;\n }\n } else if (sectionValue > (section.maxValue ?? 0)) {\n sectionValue = Number(key) - (section.type === 'month' ? 1 : 0);\n newValue = key;\n if (sectionValue > (section.maxValue ?? 0)) {\n enteredKeys.current = '';\n return;\n }\n }\n\n const shouldSetValue = sectionValue > 0 || (sectionValue === 0 && allowsZero);\n if (shouldSetValue) {\n setSection(sectionIndex, sectionValue);\n }\n\n if (\n Number(numberValue + '0') > (section.maxValue ?? 0) ||\n newValue.length >= String(section.maxValue).length\n ) {\n enteredKeys.current = '';\n if (shouldSetValue) {\n this.focusNextSection();\n }\n } else {\n enteredKeys.current = newValue;\n }\n };\n\n const onInputString = (stringValue: string) => {\n const options = section.options ?? [];\n let sectionValue = stringValue.toLocaleUpperCase();\n let foundOptions = options.filter((v) => v.startsWith(sectionValue));\n if (foundOptions.length === 0) {\n if (stringValue !== key) {\n sectionValue = key.toLocaleUpperCase();\n foundOptions = options.filter((v) => v.startsWith(sectionValue));\n }\n if (foundOptions.length === 0) {\n enteredKeys.current = '';\n return;\n }\n }\n const foundValue = foundOptions[0];\n const index = options.indexOf(foundValue);\n\n if (section.type === 'dayPeriod') {\n setSection(sectionIndex, index === 1 ? 12 : 0);\n } else {\n setSection(sectionIndex, index);\n }\n\n if (foundOptions.length > 1) {\n enteredKeys.current = newValue;\n } else {\n enteredKeys.current = '';\n this.focusNextSection();\n }\n };\n\n switch (section.type) {\n case 'day':\n case 'hour':\n case 'minute':\n case 'second':\n case 'quarter':\n case 'year': {\n if (!Number.isInteger(Number(newValue))) {\n return;\n }\n const numberValue = Number(newValue);\n onInputNumber(numberValue);\n break;\n }\n case 'dayPeriod': {\n onInputString(newValue);\n break;\n }\n case 'weekday':\n case 'month': {\n if (Number.isInteger(Number(newValue))) {\n const numberValue = Number(newValue);\n onInputNumber(numberValue);\n } else {\n onInputString(newValue);\n }\n break;\n }\n }\n },\n setValueFromString(str: string) {\n enteredKeys.current = '';\n return setValueFromString(str);\n },\n };\n}\n"]}
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { useControlledState } 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 { addSegment, adjustDateToFormat, getEditableSections, getFormatInfo, isAllSegmentsValid, markValidSection, parseDateFromString, setSegment, useFormatSections, } from "../utils.js";
|
|
6
6
|
import { useBaseDateFieldState } from "./useBaseDateFieldState.js";
|
|
7
7
|
export function useDateFieldState(props) {
|
|
8
8
|
var _a, _b;
|
|
@@ -20,9 +20,8 @@ export function useDateFieldState(props) {
|
|
|
20
20
|
});
|
|
21
21
|
const format = props.format || 'L';
|
|
22
22
|
const sections = useFormatSections(format);
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
.reduce((p, seg) => (Object.assign(Object.assign({}, p), { [seg.type]: true })), {}), [sections]);
|
|
23
|
+
const formatInfo = React.useMemo(() => getFormatInfo(sections), [sections]);
|
|
24
|
+
const allSegments = formatInfo.availableUnits;
|
|
26
25
|
const validSegmentsState = React.useState(() => value ? Object.assign({}, allSegments) : {});
|
|
27
26
|
let validSegments = validSegmentsState[0];
|
|
28
27
|
const setValidSegments = validSegmentsState[1];
|
|
@@ -70,7 +69,7 @@ export function useDateFieldState(props) {
|
|
|
70
69
|
}
|
|
71
70
|
if (isAllSegmentsValid(allSegments, validSegments)) {
|
|
72
71
|
if (!value || !newValue.isSame(value)) {
|
|
73
|
-
handleUpdateDate(newValue);
|
|
72
|
+
handleUpdateDate(adjustDateToFormat(newValue, formatInfo));
|
|
74
73
|
}
|
|
75
74
|
}
|
|
76
75
|
else {
|
|
@@ -81,13 +80,7 @@ export function useDateFieldState(props) {
|
|
|
81
80
|
}
|
|
82
81
|
}
|
|
83
82
|
function markValid(part) {
|
|
84
|
-
validSegments
|
|
85
|
-
if (validSegments.day && validSegments.month && validSegments.year && allSegments.weekday) {
|
|
86
|
-
validSegments.weekday = true;
|
|
87
|
-
}
|
|
88
|
-
if (validSegments.hour && allSegments.dayPeriod) {
|
|
89
|
-
validSegments.dayPeriod = true;
|
|
90
|
-
}
|
|
83
|
+
validSegments = markValidSection(allSegments, validSegments, part);
|
|
91
84
|
setValidSegments(Object.assign({}, validSegments));
|
|
92
85
|
}
|
|
93
86
|
function setSection(sectionIndex, amount) {
|
|
@@ -152,6 +145,7 @@ export function useDateFieldState(props) {
|
|
|
152
145
|
timeZone,
|
|
153
146
|
validationState,
|
|
154
147
|
editableSections: sectionsState.editableSections,
|
|
148
|
+
formatInfo,
|
|
155
149
|
readOnly: props.readOnly,
|
|
156
150
|
disabled: props.disabled,
|
|
157
151
|
selectedSectionIndexes,
|
|
@@ -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,EAAC,MAAM,mBAAmB,CAAC;AAGrD,OAAO,EAAC,sBAAsB,EAAE,SAAS,EAAC,6BAA0B;AACpE,OAAO,EAAC,kBAAkB,EAAC,0CAAuC;AAElE,OAAO,EACH,iBAAiB,EACjB,UAAU,EACV,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,UAAU,EACV,iBAAiB,GACpB,oBAAiB;AAElB,OAAO,EAAC,qBAAqB,EAAC,mCAAgC;AAK9D,MAAM,UAAU,iBAAiB,CAAC,KAA4B;;IAC1D,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,kBAAkB,CACvC,KAAK,CAAC,KAAK,EACX,MAAA,KAAK,CAAC,YAAY,mCAAI,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;IACF,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,IAAI,aAAa,CAAC;IAEjD,MAAM,gBAAgB,GAAG,CAAC,CAAkB,EAAE,EAAE;QAC5C,O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ACxB,sBAAsB;QACtB,gBAAgB;QAChB,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,MAAM,KAAK,CAAC;QAChD,qBAAqB;QACrB,iBAAiB;QACjB,mBAAmB;QACnB,QAAQ;QACR,OAAO,EAAE,gBAAgB;QACzB,aAAa;QACb,UAAU;QACV,eAAe;QACf,eAAe;QACf,iBAAiB;QACjB,kBAAkB;KACrB,CAAC,CAAC;AACP,CAAC;AAED,SAAS,gBAAgB,CACrB,QAA2C,EAC3C,KAAe,EACf,aAAuC;IAEvC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,EAAE;QAC1C,OAAO;YACH,KAAK;YACL,QAAQ;YACR,aAAa;YACb,gBAAgB,EAAE,mBAAmB,CAAC,QAAQ,EAAE,KAAK,EAAE,aAAa,CAAC;SACxE,CAAC;IACN,CAAC,CAAC,CAAC;IAEH,IACI,QAAQ,KAAK,KAAK,CAAC,QAAQ;QAC3B,aAAa,KAAK,KAAK,CAAC,aAAa;QACrC,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC;QAC1B,KAAK,CAAC,QAAQ,EAAE,KAAK,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE,EAC7C,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} from '@gravity-ui/uikit';\n\nimport type {DateFieldBase} from '../../types/datePicker';\nimport {createPlaceholderValue, isInvalid} from '../../utils/dates';\nimport {useDefaultTimeZone} from '../../utils/useDefaultTimeZone';\nimport type {DateFieldSectionType, DateFieldSectionWithoutPosition} from '../types';\nimport {\n EDITABLE_SEGMENTS,\n addSegment,\n getEditableSections,\n isAllSegmentsValid,\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 allSegments: typeof EDITABLE_SEGMENTS = React.useMemo(\n () =>\n sections\n .filter((seg) => EDITABLE_SEGMENTS[seg.type])\n .reduce<typeof EDITABLE_SEGMENTS>((p, seg) => ({...p, [seg.type]: true}), {}),\n [sections],\n );\n\n const validSegmentsState = React.useState<typeof EDITABLE_SEGMENTS>(() =>\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 displayValue =\n value && value.isValid() && isAllSegmentsValid(allSegments, validSegments)\n ? value.timeZone(timeZone)\n : placeholderDate.timeZone(timeZone);\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(newValue);\n }\n } else {\n if (value) {\n handleUpdateDate(null);\n }\n setPlaceholderDate(newValue);\n }\n }\n\n function markValid(part: DateFieldSectionType) {\n validSegments[part] = true;\n if (validSegments.day && validSegments.month && validSegments.year && allSegments.weekday) {\n validSegments.weekday = true;\n }\n if (validSegments.hour && allSegments.dayPeriod) {\n validSegments.dayPeriod = true;\n }\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 date = parseDateFromString(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 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: typeof EDITABLE_SEGMENTS,\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 ) {\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;A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L,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} 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 displayValue =\n value && value.isValid() && isAllSegmentsValid(allSegments, validSegments)\n ? value.timeZone(timeZone)\n : placeholderDate.timeZone(timeZone);\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 date = parseDateFromString(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 ) {\n setState({\n value,\n sections,\n validSegments,\n editableSections: getEditableSections(sections, value, validSegments),\n });\n }\n\n return state;\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export declare const i18n: ((key: "year_placeholder" | "month_placeholder" | "weekday_placeholder" | "day_placeholder" | "hour_placeholder" | "minute_placeholder" | "second_placeholder" | "dayPeriod_placeholder", params?: import("@gravity-ui/i18n").Params) => string) & {
|
|
1
|
+
export declare const i18n: ((key: "year_placeholder" | "quarter_placeholder" | "month_placeholder" | "weekday_placeholder" | "day_placeholder" | "hour_placeholder" | "minute_placeholder" | "second_placeholder" | "dayPeriod_placeholder", params?: import("@gravity-ui/i18n").Params) => string) & {
|
|
2
2
|
keysetData: {
|
|
3
|
-
"g-date-date-field": Record<"year_placeholder" | "month_placeholder" | "weekday_placeholder" | "day_placeholder" | "hour_placeholder" | "minute_placeholder" | "second_placeholder" | "dayPeriod_placeholder", import("@gravity-ui/i18n").KeyData>;
|
|
3
|
+
"g-date-date-field": Record<"year_placeholder" | "quarter_placeholder" | "month_placeholder" | "weekday_placeholder" | "day_placeholder" | "hour_placeholder" | "minute_placeholder" | "second_placeholder" | "dayPeriod_placeholder", import("@gravity-ui/i18n").KeyData>;
|
|
4
4
|
};
|
|
5
5
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type DateFieldSectionType = Extract<Intl.DateTimeFormatPartTypes, 'day' | 'dayPeriod' | 'hour' | 'literal' | 'minute' | 'month' | 'second' | 'timeZoneName' | 'weekday' | 'year' | 'unknown'
|
|
1
|
+
export type DateFieldSectionType = Extract<Intl.DateTimeFormatPartTypes, 'day' | 'dayPeriod' | 'hour' | 'literal' | 'minute' | 'month' | 'second' | 'timeZoneName' | 'weekday' | 'year' | 'unknown'> | 'quarter';
|
|
2
2
|
export type DateFormatTokenMap = {
|
|
3
3
|
[formatToken: string]: DateFieldSectionType | {
|
|
4
4
|
sectionType: DateFieldSectionType;
|
|
@@ -65,3 +65,11 @@ export interface DateFieldSection {
|
|
|
65
65
|
nextEditableSection: number;
|
|
66
66
|
}
|
|
67
67
|
export type DateFieldSectionWithoutPosition<TSection extends DateFieldSection = DateFieldSection> = Omit<TSection, 'start' | 'end' | 'value' | 'textValue' | 'modified' | 'previousEditableSection' | 'nextEditableSection'>;
|
|
68
|
+
export type AvailableSections = Partial<Record<DateFieldSectionType, boolean>>;
|
|
69
|
+
export interface FormatInfo {
|
|
70
|
+
hasTime: boolean;
|
|
71
|
+
hasDate: boolean;
|
|
72
|
+
availableUnits: AvailableSections;
|
|
73
|
+
minDateUnit: 'day' | 'month' | 'quarter' | 'year';
|
|
74
|
+
minTimeUnit: 'second' | 'minute' | 'hour';
|
|
75
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"../../../../src","sources":["components/DateField/types.ts"],"names":[],"mappings":"","sourcesContent":["export type DateFieldSectionType
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"../../../../src","sources":["components/DateField/types.ts"],"names":[],"mappings":"","sourcesContent":["export type DateFieldSectionType =\n | Extract<\n Intl.DateTimeFormatPartTypes,\n | 'day'\n | 'dayPeriod'\n | 'hour'\n | 'literal'\n | 'minute'\n | 'month'\n | 'second'\n | 'timeZoneName'\n | 'weekday'\n | 'year'\n | 'unknown'\n >\n | 'quarter';\n\nexport type DateFormatTokenMap = {\n [formatToken: string]:\n | DateFieldSectionType\n | {sectionType: DateFieldSectionType; contentType: 'digit' | 'letter'};\n};\n\nexport interface DateFieldSection {\n value: number | undefined;\n /**\n * Value of the section, as rendered inside the input.\n * For example, in the date `May 25, 1995`, the value of the month section is \"May\".\n */\n textValue: string;\n /**\n * Format token used to parse the value of this section from the date object.\n * For example, in the format `MMMM D, YYYY`, the format of the month section is \"MMMM\".\n */\n format: string;\n /**\n * Placeholder rendered when the value of this section is empty.\n */\n placeholder: string;\n /**\n * Type of the section.\n */\n type: DateFieldSectionType;\n /**\n * Type of content of the section.\n * Will determine if we should apply a digit-based editing or a letter-based editing.\n */\n contentType: 'digit' | 'letter';\n /**\n * Available values\n */\n options?: string[];\n /** The minimum numeric value for the segment, if applicable. */\n minValue?: number;\n /** The maximum numeric value for the segment, if applicable. */\n maxValue?: number;\n /**\n * If `true`, the value of this section is supposed to have leading zeroes.\n * For example, the value `1` should be rendered as \"01\" instead of \"1\".\n */\n hasLeadingZeros: boolean;\n /**\n * If `true`, the section value has been modified since the last time the sections were generated from a valid date.\n * When we can generate a valid date from the section, we don't directly pass it to `onChange`,\n * Otherwise, we would lose all the information contained in the original date, things like:\n * - time if the format does not contain it\n * - timezone / UTC\n *\n * To avoid losing that information, we transfer the values of the modified sections from the newly generated date to the original date.\n */\n modified: boolean;\n /**\n * Start index of the section in the format\n */\n start: number;\n /**\n * End index of the section in the format\n */\n end: number;\n\n previousEditableSection: number;\n nextEditableSection: number;\n}\n\nexport type DateFieldSectionWithoutPosition<TSection extends DateFieldSection = DateFieldSection> =\n Omit<\n TSection,\n | 'start'\n | 'end'\n | 'value'\n | 'textValue'\n | 'modified'\n | 'previousEditableSection'\n | 'nextEditableSection'\n >;\n\nexport type AvailableSections = Partial<Record<DateFieldSectionType, boolean>>;\n\nexport interface FormatInfo {\n hasTime: boolean;\n hasDate: boolean;\n availableUnits: AvailableSections;\n minDateUnit: 'day' | 'month' | 'quarter' | 'year';\n minTimeUnit: 'second' | 'minute' | 'hour';\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DateTime } from '@gravity-ui/date-utils';
|
|
2
|
-
import type { DateFieldSection, DateFieldSectionType, DateFieldSectionWithoutPosition } from "./types.js";
|
|
3
|
-
export declare const EDITABLE_SEGMENTS:
|
|
2
|
+
import type { AvailableSections, DateFieldSection, DateFieldSectionType, DateFieldSectionWithoutPosition, FormatInfo } from "./types.js";
|
|
3
|
+
export declare const EDITABLE_SEGMENTS: AvailableSections;
|
|
4
4
|
export declare function getSectionLimits(section: DateFieldSectionWithoutPosition, date: DateTime): {
|
|
5
5
|
minValue: number;
|
|
6
6
|
maxValue: number;
|
|
@@ -9,16 +9,32 @@ export declare function getSectionLimits(section: DateFieldSectionWithoutPositio
|
|
|
9
9
|
maxValue?: undefined;
|
|
10
10
|
};
|
|
11
11
|
export declare function getSectionValue(section: DateFieldSectionWithoutPosition, date: DateTime): number | undefined;
|
|
12
|
-
export declare function getDurationUnitFromSectionType(type: DateFieldSectionType): "year" | "month" | "day" | "hour" | "minute" | "second" | "date";
|
|
12
|
+
export declare function getDurationUnitFromSectionType(type: DateFieldSectionType): "year" | "month" | "day" | "hour" | "minute" | "second" | "quarter" | "date";
|
|
13
13
|
export declare function addSegment(section: DateFieldSection, date: DateTime, amount: number): DateTime;
|
|
14
14
|
export declare function setSegment(section: DateFieldSection, date: DateTime, amount: number): DateTime;
|
|
15
15
|
export declare function splitFormatIntoSections(format: string): DateFieldSectionWithoutPosition[];
|
|
16
16
|
export declare function cleanString(dirtyString: string): string;
|
|
17
|
-
export declare function getEditableSections(sections: DateFieldSectionWithoutPosition[], value: DateTime, validSegments:
|
|
17
|
+
export declare function getEditableSections(sections: DateFieldSectionWithoutPosition[], value: DateTime, validSegments: AvailableSections): DateFieldSection[];
|
|
18
18
|
export declare function isEditableSection(section: DateFieldSectionWithoutPosition): boolean;
|
|
19
|
-
export declare function toEditableSection(section: DateFieldSectionWithoutPosition, value: DateTime, validSegments:
|
|
19
|
+
export declare function toEditableSection(section: DateFieldSectionWithoutPosition, value: DateTime, validSegments: AvailableSections, position: number, previousEditableSection: number): DateFieldSection;
|
|
20
20
|
export declare function getCurrentEditableSectionIndex(sections: DateFieldSection[], selectedSections: 'all' | number): number;
|
|
21
21
|
export declare function formatSections(sections: DateFieldSection[]): string;
|
|
22
22
|
export declare function parseDateFromString(str: string, format: string, timeZone?: string): DateTime;
|
|
23
|
-
export declare function isAllSegmentsValid(allSegments:
|
|
23
|
+
export declare function isAllSegmentsValid(allSegments: AvailableSections, validSegments: AvailableSections): boolean;
|
|
24
24
|
export declare function useFormatSections(format: string): DateFieldSectionWithoutPosition[];
|
|
25
|
+
export declare function getFormatInfo(sections: DateFieldSectionWithoutPosition[]): FormatInfo;
|
|
26
|
+
export declare function adjustDateToFormat(date: DateTime, formatInfo: FormatInfo, method?: 'startOf' | 'endOf'): DateTime;
|
|
27
|
+
export declare function markValidSection(allSections: AvailableSections, editableSections: AvailableSections, unit: DateFieldSectionType): {
|
|
28
|
+
year?: boolean | undefined;
|
|
29
|
+
month?: boolean | undefined;
|
|
30
|
+
day?: boolean | undefined;
|
|
31
|
+
hour?: boolean | undefined;
|
|
32
|
+
minute?: boolean | undefined;
|
|
33
|
+
second?: boolean | undefined;
|
|
34
|
+
quarter?: boolean | undefined;
|
|
35
|
+
weekday?: boolean | undefined;
|
|
36
|
+
dayPeriod?: boolean | undefined;
|
|
37
|
+
literal?: boolean | undefined;
|
|
38
|
+
timeZoneName?: boolean | undefined;
|
|
39
|
+
unknown?: boolean | undefined;
|
|
40
|
+
};
|