@gravity-ui/date-components 3.0.0-beta.0 → 3.0.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.
Files changed (175) hide show
  1. package/dist/cjs/components/DateField/hooks/useBaseDateFieldState.d.ts +12 -3
  2. package/dist/cjs/components/DateField/hooks/useBaseDateFieldState.js +6 -15
  3. package/dist/cjs/components/DateField/hooks/useBaseDateFieldState.js.map +1 -1
  4. package/dist/cjs/components/DateField/hooks/useDateFieldState.js +5 -11
  5. package/dist/cjs/components/DateField/hooks/useDateFieldState.js.map +1 -1
  6. package/dist/cjs/components/DateField/i18n/en.json +1 -0
  7. package/dist/cjs/components/DateField/i18n/index.d.ts +2 -2
  8. package/dist/cjs/components/DateField/i18n/ru.json +1 -0
  9. package/dist/cjs/components/DateField/types.d.ts +9 -1
  10. package/dist/cjs/components/DateField/types.js.map +1 -1
  11. package/dist/cjs/components/DateField/utils.d.ts +22 -6
  12. package/dist/cjs/components/DateField/utils.js +83 -0
  13. package/dist/cjs/components/DateField/utils.js.map +1 -1
  14. package/dist/cjs/components/DatePicker/DatePicker.d.ts +2 -2
  15. package/dist/cjs/components/DatePicker/DatePicker.js +2 -2
  16. package/dist/cjs/components/DatePicker/DatePicker.js.map +1 -1
  17. package/dist/cjs/components/DatePicker/MobileCalendar.js +4 -4
  18. package/dist/cjs/components/DatePicker/MobileCalendar.js.map +1 -1
  19. package/dist/cjs/components/DatePicker/hooks/datePickerStateFactory.d.ts +13 -3
  20. package/dist/cjs/components/DatePicker/hooks/datePickerStateFactory.js +17 -15
  21. package/dist/cjs/components/DatePicker/hooks/datePickerStateFactory.js.map +1 -1
  22. package/dist/cjs/components/DatePicker/hooks/useDatePickerProps.js +8 -2
  23. package/dist/cjs/components/DatePicker/hooks/useDatePickerProps.js.map +1 -1
  24. package/dist/cjs/components/DatePicker/hooks/useDatePickerState.js +4 -2
  25. package/dist/cjs/components/DatePicker/hooks/useDatePickerState.js.map +1 -1
  26. package/dist/cjs/components/DatePicker/utils/getCalendarModes.d.ts +5 -0
  27. package/dist/cjs/components/DatePicker/utils/getCalendarModes.js +21 -0
  28. package/dist/cjs/components/DatePicker/utils/getCalendarModes.js.map +1 -0
  29. package/dist/cjs/components/DatePicker/utils/index.d.ts +1 -0
  30. package/dist/cjs/components/DatePicker/utils/index.js +1 -0
  31. package/dist/cjs/components/DatePicker/utils/index.js.map +1 -1
  32. package/dist/cjs/components/RangeDateField/hooks/useRangeDateFieldState.js +8 -16
  33. package/dist/cjs/components/RangeDateField/hooks/useRangeDateFieldState.js.map +1 -1
  34. package/dist/cjs/components/RangeDateField/utils/createPlaceholderRangeValue.js +1 -1
  35. package/dist/cjs/components/RangeDateField/utils/createPlaceholderRangeValue.js.map +1 -1
  36. package/dist/cjs/components/RangeDatePicker/RangeDatePicker.js +2 -2
  37. package/dist/cjs/components/RangeDatePicker/RangeDatePicker.js.map +1 -1
  38. package/dist/cjs/components/RangeDatePicker/hooks/useRangeDatePickerState.d.ts +4 -1
  39. package/dist/cjs/components/RangeDatePicker/hooks/useRangeDatePickerState.js +11 -4
  40. package/dist/cjs/components/RangeDatePicker/hooks/useRangeDatePickerState.js.map +1 -1
  41. package/dist/cjs/components/RelativeDateField/RelativeDateField.d.ts +2 -2
  42. package/dist/cjs/components/RelativeDateField/RelativeDateField.js +1 -1
  43. package/dist/cjs/components/RelativeDateField/RelativeDateField.js.map +1 -1
  44. package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.d.ts +2 -2
  45. package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.js +2 -2
  46. package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.js.map +1 -1
  47. package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.js +8 -1
  48. package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.js.map +1 -1
  49. package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerState.js +11 -3
  50. package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerState.js.map +1 -1
  51. package/dist/cjs/components/RelativeRangeDatePicker/RelativeRangeDatePicker.js +8 -7
  52. package/dist/cjs/components/RelativeRangeDatePicker/RelativeRangeDatePicker.js.map +1 -1
  53. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.css +0 -22
  54. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.css.map +1 -1
  55. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.d.ts +13 -13
  56. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.js +13 -38
  57. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.js.map +1 -1
  58. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerForm.css +23 -0
  59. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerForm.css.map +1 -0
  60. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerForm.d.ts +33 -0
  61. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerForm.js +39 -0
  62. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerForm.js.map +1 -0
  63. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.d.ts +2 -3
  64. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.js +49 -42
  65. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.js.map +1 -1
  66. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/Presets.js +1 -1
  67. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/Presets.js.map +1 -1
  68. package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/Zones.js +1 -1
  69. package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/Zones.js.map +1 -1
  70. package/dist/cjs/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.d.ts +12 -1
  71. package/dist/cjs/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.js +5 -2
  72. package/dist/cjs/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.js.map +1 -1
  73. package/dist/cjs/components/RelativeRangeDatePicker/i18n/index.d.ts +2 -2
  74. package/dist/cjs/components/RelativeRangeDatePicker/index.d.ts +2 -0
  75. package/dist/cjs/components/RelativeRangeDatePicker/index.js +3 -1
  76. package/dist/cjs/components/RelativeRangeDatePicker/index.js.map +1 -1
  77. package/dist/cjs/components/RelativeRangeDatePicker/types.d.ts +2 -7
  78. package/dist/cjs/components/RelativeRangeDatePicker/types.js.map +1 -1
  79. package/dist/cjs/components/index.d.ts +1 -0
  80. package/dist/cjs/components/index.js.map +1 -1
  81. package/dist/cjs/components/types/datePicker.d.ts +11 -0
  82. package/dist/cjs/components/types/datePicker.js.map +1 -1
  83. package/dist/cjs/components/types/i18n.d.ts +17 -0
  84. package/dist/cjs/components/types/i18n.js +3 -0
  85. package/dist/cjs/components/types/i18n.js.map +1 -0
  86. package/dist/cjs/components/utils/dates.js +1 -1
  87. package/dist/cjs/components/utils/dates.js.map +1 -1
  88. package/dist/esm/components/DateField/hooks/useBaseDateFieldState.d.ts +12 -3
  89. package/dist/esm/components/DateField/hooks/useBaseDateFieldState.js +6 -15
  90. package/dist/esm/components/DateField/hooks/useBaseDateFieldState.js.map +1 -1
  91. package/dist/esm/components/DateField/hooks/useDateFieldState.js +6 -12
  92. package/dist/esm/components/DateField/hooks/useDateFieldState.js.map +1 -1
  93. package/dist/esm/components/DateField/i18n/en.json +1 -0
  94. package/dist/esm/components/DateField/i18n/index.d.ts +2 -2
  95. package/dist/esm/components/DateField/i18n/ru.json +1 -0
  96. package/dist/esm/components/DateField/types.d.ts +9 -1
  97. package/dist/esm/components/DateField/types.js.map +1 -1
  98. package/dist/esm/components/DateField/utils.d.ts +22 -6
  99. package/dist/esm/components/DateField/utils.js +80 -0
  100. package/dist/esm/components/DateField/utils.js.map +1 -1
  101. package/dist/esm/components/DatePicker/DatePicker.d.ts +2 -2
  102. package/dist/esm/components/DatePicker/DatePicker.js +2 -2
  103. package/dist/esm/components/DatePicker/DatePicker.js.map +1 -1
  104. package/dist/esm/components/DatePicker/MobileCalendar.js +4 -4
  105. package/dist/esm/components/DatePicker/MobileCalendar.js.map +1 -1
  106. package/dist/esm/components/DatePicker/hooks/datePickerStateFactory.d.ts +13 -3
  107. package/dist/esm/components/DatePicker/hooks/datePickerStateFactory.js +17 -15
  108. package/dist/esm/components/DatePicker/hooks/datePickerStateFactory.js.map +1 -1
  109. package/dist/esm/components/DatePicker/hooks/useDatePickerProps.js +9 -3
  110. package/dist/esm/components/DatePicker/hooks/useDatePickerProps.js.map +1 -1
  111. package/dist/esm/components/DatePicker/hooks/useDatePickerState.js +2 -0
  112. package/dist/esm/components/DatePicker/hooks/useDatePickerState.js.map +1 -1
  113. package/dist/esm/components/DatePicker/utils/getCalendarModes.d.ts +5 -0
  114. package/dist/esm/components/DatePicker/utils/getCalendarModes.js +18 -0
  115. package/dist/esm/components/DatePicker/utils/getCalendarModes.js.map +1 -0
  116. package/dist/esm/components/DatePicker/utils/index.d.ts +1 -0
  117. package/dist/esm/components/DatePicker/utils/index.js +1 -0
  118. package/dist/esm/components/DatePicker/utils/index.js.map +1 -1
  119. package/dist/esm/components/RangeDateField/hooks/useRangeDateFieldState.js +9 -17
  120. package/dist/esm/components/RangeDateField/hooks/useRangeDateFieldState.js.map +1 -1
  121. package/dist/esm/components/RangeDateField/utils/createPlaceholderRangeValue.js +1 -1
  122. package/dist/esm/components/RangeDateField/utils/createPlaceholderRangeValue.js.map +1 -1
  123. package/dist/esm/components/RangeDatePicker/RangeDatePicker.js +2 -2
  124. package/dist/esm/components/RangeDatePicker/RangeDatePicker.js.map +1 -1
  125. package/dist/esm/components/RangeDatePicker/hooks/useRangeDatePickerState.d.ts +4 -1
  126. package/dist/esm/components/RangeDatePicker/hooks/useRangeDatePickerState.js +10 -3
  127. package/dist/esm/components/RangeDatePicker/hooks/useRangeDatePickerState.js.map +1 -1
  128. package/dist/esm/components/RelativeDateField/RelativeDateField.d.ts +2 -2
  129. package/dist/esm/components/RelativeDateField/RelativeDateField.js +1 -1
  130. package/dist/esm/components/RelativeDateField/RelativeDateField.js.map +1 -1
  131. package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.d.ts +2 -2
  132. package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.js +2 -2
  133. package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.js.map +1 -1
  134. package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.js +8 -1
  135. package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.js.map +1 -1
  136. package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerState.js +11 -3
  137. package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerState.js.map +1 -1
  138. package/dist/esm/components/RelativeRangeDatePicker/RelativeRangeDatePicker.js +8 -7
  139. package/dist/esm/components/RelativeRangeDatePicker/RelativeRangeDatePicker.js.map +1 -1
  140. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.css +0 -22
  141. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.css.map +1 -1
  142. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.d.ts +13 -13
  143. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.js +15 -40
  144. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.js.map +1 -1
  145. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerForm.css +23 -0
  146. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerForm.css.map +1 -0
  147. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerForm.d.ts +33 -0
  148. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerForm.js +36 -0
  149. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerForm.js.map +1 -0
  150. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.d.ts +2 -3
  151. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.js +49 -42
  152. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.js.map +1 -1
  153. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/Presets.js +2 -2
  154. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/Presets.js.map +1 -1
  155. package/dist/esm/components/RelativeRangeDatePicker/components/Zones/Zones.js +1 -1
  156. package/dist/esm/components/RelativeRangeDatePicker/components/Zones/Zones.js.map +1 -1
  157. package/dist/esm/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.d.ts +12 -1
  158. package/dist/esm/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.js +5 -3
  159. package/dist/esm/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.js.map +1 -1
  160. package/dist/esm/components/RelativeRangeDatePicker/i18n/index.d.ts +2 -2
  161. package/dist/esm/components/RelativeRangeDatePicker/index.d.ts +2 -0
  162. package/dist/esm/components/RelativeRangeDatePicker/index.js +1 -0
  163. package/dist/esm/components/RelativeRangeDatePicker/index.js.map +1 -1
  164. package/dist/esm/components/RelativeRangeDatePicker/types.d.ts +2 -7
  165. package/dist/esm/components/RelativeRangeDatePicker/types.js.map +1 -1
  166. package/dist/esm/components/index.d.ts +1 -0
  167. package/dist/esm/components/index.js.map +1 -1
  168. package/dist/esm/components/types/datePicker.d.ts +11 -0
  169. package/dist/esm/components/types/datePicker.js.map +1 -1
  170. package/dist/esm/components/types/i18n.d.ts +17 -0
  171. package/dist/esm/components/types/i18n.js +2 -0
  172. package/dist/esm/components/types/i18n.js.map +1 -0
  173. package/dist/esm/components/utils/dates.js +1 -1
  174. package/dist/esm/components/utils/dates.js.map +1 -1
  175. package/package.json +2 -2
@@ -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
- /** Whether the the format is containing date parts */
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
- /** Whether the the format is containing time parts */
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: {
@@ -7,6 +7,7 @@ const dates_1 = require("../../utils/dates.js");
7
7
  const utils_1 = require("../utils.js");
8
8
  const PAGE_STEP = {
9
9
  year: 5,
10
+ quarter: 2,
10
11
  month: 2,
11
12
  weekday: 3,
12
13
  day: 7,
@@ -15,20 +16,8 @@ const PAGE_STEP = {
15
16
  second: 15,
16
17
  };
17
18
  function useBaseDateFieldState(props) {
18
- const { value, validationState, displayValue, editableSections, selectedSectionIndexes, selectedSections, isEmpty, flushAllValidSections, flushValidSection, setSelectedSections, setValue, setDate, adjustSection, setSection, getSectionValue, setSectionValue, createPlaceholder, setValueFromString, } = props;
19
+ const { value, validationState, displayValue, editableSections, formatInfo, selectedSectionIndexes, selectedSections, isEmpty, flushAllValidSections, flushValidSection, setSelectedSections, setValue, setDate, adjustSection, setSection, getSectionValue, setSectionValue, createPlaceholder, setValueFromString, } = props;
19
20
  const enteredKeys = react_1.default.useRef('');
20
- const { hasDate, hasTime } = react_1.default.useMemo(() => {
21
- let hasDateInner = false;
22
- let hasTimeInner = false;
23
- for (const s of editableSections) {
24
- hasTimeInner || (hasTimeInner = ['hour', 'minute', 'second'].includes(s.type));
25
- hasDateInner || (hasDateInner = ['day', 'month', 'year'].includes(s.type));
26
- }
27
- return {
28
- hasTime: hasTimeInner,
29
- hasDate: hasDateInner,
30
- };
31
- }, [editableSections]);
32
21
  return {
33
22
  value,
34
23
  isEmpty,
@@ -39,8 +28,9 @@ function useBaseDateFieldState(props) {
39
28
  readOnly: props.readOnly,
40
29
  disabled: props.disabled,
41
30
  sections: editableSections,
42
- hasDate,
43
- hasTime,
31
+ formatInfo,
32
+ hasDate: formatInfo.hasDate,
33
+ hasTime: formatInfo.hasTime,
44
34
  selectedSectionIndexes,
45
35
  validationState,
46
36
  setSelectedSections(position) {
@@ -283,6 +273,7 @@ function useBaseDateFieldState(props) {
283
273
  case 'hour':
284
274
  case 'minute':
285
275
  case 'second':
276
+ case 'quarter':
286
277
  case 'year': {
287
278
  if (!Number.isInteger(Number(newValue))) {
288
279
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"useBaseDateFieldState.js","sourceRoot":"../../../../../src","sources":["components/DateField/hooks/useBaseDateFieldState.ts"],"names":[],"mappings":";;AAoHA,sDAoVC;;AAxcD,0DAA0B;AAK1B,gDAAyD;AAEzD,uCAKkB;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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AG,EAAE,CAAC;oBACzB,IAAI,CAAC,gBAAgB,EAAE,CAAC;gBAC5B,CAAC;YACL,CAAC,CAAC;YAEF,QAAQ,OAAO,CAAC,IAAI,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":";;AA8HA,sDA0UC;;AAxcD,0DAA0B;AAK1B,gDAAyD;AAEzD,uCAKkB;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,SAAgB,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,mBAAm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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, 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"]}
@@ -24,9 +24,8 @@ function useDateFieldState(props) {
24
24
  });
25
25
  const format = props.format || 'L';
26
26
  const sections = (0, utils_1.useFormatSections)(format);
27
- const allSegments = react_1.default.useMemo(() => sections
28
- .filter((seg) => utils_1.EDITABLE_SEGMENTS[seg.type])
29
- .reduce((p, seg) => (Object.assign(Object.assign({}, p), { [seg.type]: true })), {}), [sections]);
27
+ const formatInfo = react_1.default.useMemo(() => (0, utils_1.getFormatInfo)(sections), [sections]);
28
+ const allSegments = formatInfo.availableUnits;
30
29
  const validSegmentsState = react_1.default.useState(() => value ? Object.assign({}, allSegments) : {});
31
30
  let validSegments = validSegmentsState[0];
32
31
  const setValidSegments = validSegmentsState[1];
@@ -74,7 +73,7 @@ function useDateFieldState(props) {
74
73
  }
75
74
  if ((0, utils_1.isAllSegmentsValid)(allSegments, validSegments)) {
76
75
  if (!value || !newValue.isSame(value)) {
77
- handleUpdateDate(newValue);
76
+ handleUpdateDate((0, utils_1.adjustDateToFormat)(newValue, formatInfo));
78
77
  }
79
78
  }
80
79
  else {
@@ -85,13 +84,7 @@ function useDateFieldState(props) {
85
84
  }
86
85
  }
87
86
  function markValid(part) {
88
- validSegments[part] = true;
89
- if (validSegments.day && validSegments.month && validSegments.year && allSegments.weekday) {
90
- validSegments.weekday = true;
91
- }
92
- if (validSegments.hour && allSegments.dayPeriod) {
93
- validSegments.dayPeriod = true;
94
- }
87
+ validSegments = (0, utils_1.markValidSection)(allSegments, validSegments, part);
95
88
  setValidSegments(Object.assign({}, validSegments));
96
89
  }
97
90
  function setSection(sectionIndex, amount) {
@@ -156,6 +149,7 @@ function useDateFieldState(props) {
156
149
  timeZone,
157
150
  validationState,
158
151
  editableSections: sectionsState.editableSections,
152
+ formatInfo,
159
153
  readOnly: props.readOnly,
160
154
  disabled: props.disabled,
161
155
  selectedSectionIndexes,
@@ -1 +1 @@
1
- {"version":3,"file":"useDateFieldState.js","sourceRoot":"../../../../../src","sources":["components/DateField/hooks/useDateFieldState.ts"],"names":[],"mappings":";;AAwBA,8CAsNC;;AA9OD,0DAA0B;AAG1B,6CAAqD;AAGrD,gDAAoE;AACpE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AAK,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,IAAA,2BAAmB,EAAC,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":";;AA8BA,8CA4MC;;AA1OD,0DAA0B;AAG1B,6CAAqD;AAGrD,gDAAoE;AACpE,0EAAkE;AAMlE,uCAUkB;AAElB,sEAA8D;AAK9D,SAAgB,iBAAiB,CAAC,KAA4B;;IAC1D,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,IAAA,0BAAkB,EACvC,KAAK,CAAC,KAAK,EACX,MAAA,KAAK,CAAC,YAAY,mCAAI,IAAI,EAC1B,KAAK,CAAC,QAAQ,CACjB,CAAC;IAEF,MAAM,aAAa,GAAG,IAAA,uCAAkB,EACpC,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,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/C,CAAC,CAA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AQ,CAAC,GAAG,EAAE;QAC1C,OAAO;YACH,KAAK;YACL,QAAQ;YACR,aAAa;YACb,gBAAgB,EAAE,IAAA,2BAAmB,EAAC,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,IAAA,2BAAmB,EAAC,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,6 @@
1
1
  {
2
2
  "year_placeholder": "Y",
3
+ "quarter_placeholder": "Q",
3
4
  "month_placeholder": "M",
4
5
  "weekday_placeholder": "E",
5
6
  "day_placeholder": "D",
@@ -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,5 +1,6 @@
1
1
  {
2
2
  "year_placeholder": "Г",
3
+ "quarter_placeholder": "K",
3
4
  "month_placeholder": "М",
4
5
  "weekday_placeholder": "ДН",
5
6
  "day_placeholder": "Д",
@@ -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 = 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\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"]}
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: Partial<Record<DateFieldSectionType, boolean>>;
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: typeof EDITABLE_SEGMENTS): DateFieldSection[];
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: typeof EDITABLE_SEGMENTS, position: number, previousEditableSection: number): DateFieldSection;
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: typeof EDITABLE_SEGMENTS, validSegments: typeof EDITABLE_SEGMENTS): boolean;
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
+ };
@@ -16,6 +16,9 @@ exports.formatSections = formatSections;
16
16
  exports.parseDateFromString = parseDateFromString;
17
17
  exports.isAllSegmentsValid = isAllSegmentsValid;
18
18
  exports.useFormatSections = useFormatSections;
19
+ exports.getFormatInfo = getFormatInfo;
20
+ exports.adjustDateToFormat = adjustDateToFormat;
21
+ exports.markValidSection = markValidSection;
19
22
  const tslib_1 = require("tslib");
20
23
  const react_1 = tslib_1.__importDefault(require("react"));
21
24
  const date_utils_1 = require("@gravity-ui/date-utils");
@@ -23,6 +26,7 @@ const dates_1 = require("../utils/dates.js");
23
26
  const i18n_1 = require("./i18n/index.js");
24
27
  exports.EDITABLE_SEGMENTS = {
25
28
  year: true,
29
+ quarter: true,
26
30
  month: true,
27
31
  day: true,
28
32
  hour: true,
@@ -36,6 +40,8 @@ const formatTokenMap = {
36
40
  // Year
37
41
  YY: 'year',
38
42
  YYYY: 'year',
43
+ // Quarter
44
+ Q: 'quarter',
39
45
  // Month
40
46
  M: 'month',
41
47
  MM: 'month',
@@ -110,6 +116,9 @@ function getSectionLimits(section, date) {
110
116
  maxValue: isFourDigit ? 9999 : 99,
111
117
  };
112
118
  }
119
+ case 'quarter': {
120
+ return { minValue: 1, maxValue: 4 };
121
+ }
113
122
  case 'month': {
114
123
  return {
115
124
  minValue: 0,
@@ -159,6 +168,7 @@ function getSectionValue(section, date) {
159
168
  ? date.year()
160
169
  : Number(date.format(section.format));
161
170
  }
171
+ case 'quarter':
162
172
  case 'month':
163
173
  case 'hour':
164
174
  case 'minute':
@@ -209,6 +219,9 @@ function addSegment(section, date, amount) {
209
219
  if (section.type === 'year' && !isFourDigitYearFormat(section.format)) {
210
220
  val = (0, date_utils_1.dateTime)({ input: `${val}`.padStart(2, '0'), format: section.format }).year();
211
221
  }
222
+ if (section.type === 'quarter') {
223
+ return date.set(getDurationUnitFromSectionType('month'), val * 3 - 1);
224
+ }
212
225
  const type = getDurationUnitFromSectionType(section.type);
213
226
  return date.set(type, val);
214
227
  }
@@ -223,6 +236,9 @@ function setSegment(section, date, amount) {
223
236
  format: section.format,
224
237
  }).year());
225
238
  }
239
+ case 'quarter': {
240
+ return date.set(getDurationUnitFromSectionType('month'), amount * 3 - 1);
241
+ }
226
242
  case 'day':
227
243
  case 'weekday':
228
244
  case 'month': {
@@ -272,6 +288,9 @@ function doesSectionHaveLeadingZeros(contentType, sectionType, format) {
272
288
  const formatted2001 = (0, date_utils_1.dateTime)().set('year', 2001).format(format);
273
289
  return formatted2001 === '01';
274
290
  }
291
+ case 'quarter': {
292
+ return false;
293
+ }
275
294
  case 'month': {
276
295
  return (0, date_utils_1.dateTime)().startOf('year').format(format).length > 1;
277
296
  }
@@ -300,6 +319,9 @@ function getSectionPlaceholder(sectionConfig, currentTokenValue) {
300
319
  case 'year': {
301
320
  return (0, i18n_1.i18n)('year_placeholder').repeat((0, date_utils_1.dateTime)().format(currentTokenValue).length);
302
321
  }
322
+ case 'quarter': {
323
+ return (0, i18n_1.i18n)('quarter_placeholder');
324
+ }
303
325
  case 'month': {
304
326
  return (0, i18n_1.i18n)('month_placeholder').repeat(sectionConfig.contentType === 'letter' ? 4 : 2);
305
327
  }
@@ -521,4 +543,65 @@ function useFormatSections(format) {
521
543
  }
522
544
  return sections;
523
545
  }
546
+ const dateUnits = ['day', 'month', 'quarter', 'year'];
547
+ const timeUnits = ['second', 'minute', 'hour'];
548
+ function getFormatInfo(sections) {
549
+ var _a, _b;
550
+ const availableUnits = {};
551
+ let hasDate = false;
552
+ let hasTime = false;
553
+ let minDateUnitIndex = dateUnits.length - 1;
554
+ let minTimeUnitIndex = timeUnits.length - 1;
555
+ for (const s of sections) {
556
+ if (!isEditableSection(s)) {
557
+ continue;
558
+ }
559
+ const dateUnitIndex = dateUnits.indexOf(s.type);
560
+ const timeUnitIndex = timeUnits.indexOf(s.type);
561
+ availableUnits[s.type] = true;
562
+ hasDate || (hasDate = dateUnitIndex !== -1);
563
+ hasTime || (hasTime = timeUnitIndex !== -1);
564
+ minDateUnitIndex =
565
+ dateUnitIndex === -1 ? minDateUnitIndex : Math.min(dateUnitIndex, minDateUnitIndex);
566
+ minTimeUnitIndex =
567
+ timeUnitIndex === -1 ? minTimeUnitIndex : Math.min(timeUnitIndex, minTimeUnitIndex);
568
+ }
569
+ return {
570
+ availableUnits,
571
+ hasDate,
572
+ hasTime,
573
+ minDateUnit: (_a = dateUnits[minDateUnitIndex]) !== null && _a !== void 0 ? _a : 'day',
574
+ minTimeUnit: (_b = timeUnits[minTimeUnitIndex]) !== null && _b !== void 0 ? _b : 'second',
575
+ };
576
+ }
577
+ function adjustDateToFormat(date, formatInfo, method = 'startOf') {
578
+ let newDate = date;
579
+ if (formatInfo.hasDate) {
580
+ if (formatInfo.minDateUnit !== 'day') {
581
+ newDate = newDate[method](formatInfo.minDateUnit);
582
+ newDate = (0, dates_1.mergeDateTime)(newDate, date);
583
+ }
584
+ }
585
+ if (formatInfo.hasTime) {
586
+ newDate = (0, dates_1.mergeDateTime)(newDate, date[method](formatInfo.minTimeUnit));
587
+ }
588
+ return newDate;
589
+ }
590
+ function markValidSection(allSections, editableSections, unit) {
591
+ const validSections = Object.assign({}, editableSections);
592
+ validSections[unit] = true;
593
+ if (validSections.day && validSections.month && validSections.year && allSections.weekday) {
594
+ validSections.weekday = true;
595
+ }
596
+ if (validSections.month && allSections.quarter) {
597
+ validSections.quarter = true;
598
+ }
599
+ if (validSections.quarter && allSections.month) {
600
+ validSections.month = true;
601
+ }
602
+ if (validSections.hour && allSections.dayPeriod) {
603
+ validSections.dayPeriod = true;
604
+ }
605
+ return validSections;
606
+ }
524
607
  //# sourceMappingURL=utils.js.map