@gravity-ui/date-components 1.5.0 → 2.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.
Files changed (265) hide show
  1. package/dist/cjs/components/Calendar/Calendar.d.ts +6 -5
  2. package/dist/cjs/components/Calendar/Calendar.js +4 -4
  3. package/dist/cjs/components/Calendar/index.d.ts +6 -6
  4. package/dist/cjs/components/Calendar/index.js +5 -5
  5. package/dist/cjs/components/{CalendarBase → CalendarView}/Calendar.css +9 -6
  6. package/dist/cjs/components/{CalendarBase/CalendarBase.d.ts → CalendarView/CalendarView.d.ts} +2 -2
  7. package/dist/cjs/components/{CalendarBase/CalendarBase.js → CalendarView/CalendarView.js} +4 -3
  8. package/dist/{esm/components/CalendarBase → cjs/components/CalendarView}/hooks/types.d.ts +37 -31
  9. package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useCalendarCellProps.js +1 -2
  10. package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useCalendarGridProps.d.ts +2 -2
  11. package/dist/{esm/components/CalendarBase → cjs/components/CalendarView}/hooks/useCalendarState.d.ts +1 -1
  12. package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useCalendarState.js +45 -23
  13. package/dist/cjs/components/CalendarView/hooks/useRangeCalendarState.d.ts +8 -0
  14. package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useRangeCalendarState.js +25 -14
  15. package/dist/cjs/components/DateField/DateField.d.ts +1 -4
  16. package/dist/cjs/components/DateField/DateField.js +3 -1
  17. package/dist/cjs/components/DateField/hooks/useBaseDateFieldState.d.ts +97 -0
  18. package/dist/cjs/components/DateField/hooks/useBaseDateFieldState.js +316 -0
  19. package/dist/cjs/components/DateField/hooks/useDateFieldProps.d.ts +6 -3
  20. package/dist/cjs/components/DateField/hooks/useDateFieldProps.js +14 -12
  21. package/dist/cjs/components/DateField/hooks/useDateFieldState.d.ts +2 -65
  22. package/dist/cjs/components/DateField/hooks/useDateFieldState.js +98 -410
  23. package/dist/cjs/components/DateField/index.d.ts +1 -0
  24. package/dist/cjs/components/DateField/index.js +1 -0
  25. package/dist/cjs/components/DateField/utils.d.ts +10 -1
  26. package/dist/cjs/components/DateField/utils.js +114 -2
  27. package/dist/cjs/components/DatePicker/DatePicker.d.ts +4 -4
  28. package/dist/cjs/components/DatePicker/DatePicker.js +6 -6
  29. package/dist/cjs/components/DatePicker/MobileCalendar.css +6 -6
  30. package/dist/cjs/components/DatePicker/MobileCalendar.js +17 -12
  31. package/dist/cjs/components/DatePicker/hooks/useDatePickerProps.js +5 -16
  32. package/dist/cjs/components/DatePicker/hooks/useDatePickerState.d.ts +5 -4
  33. package/dist/cjs/components/DatePicker/hooks/useDatePickerState.js +71 -56
  34. package/dist/cjs/components/RangeCalendar/RangeCalendar.d.ts +3 -3
  35. package/dist/cjs/components/RangeCalendar/RangeCalendar.js +4 -4
  36. package/dist/cjs/components/RangeDateField/RangeDateField.css +4 -0
  37. package/dist/cjs/components/RangeDateField/RangeDateField.d.ts +12 -0
  38. package/dist/cjs/components/RangeDateField/RangeDateField.js +25 -0
  39. package/dist/cjs/components/RangeDateField/hooks/useRangeDateFieldState.d.ts +9 -0
  40. package/dist/cjs/components/RangeDateField/hooks/useRangeDateFieldState.js +227 -0
  41. package/dist/cjs/components/RangeDateField/index.d.ts +2 -0
  42. package/dist/cjs/components/RangeDateField/index.js +5 -0
  43. package/dist/cjs/components/RangeDateField/utils/createPlaceholderRangeValue.d.ts +5 -0
  44. package/dist/cjs/components/RangeDateField/utils/createPlaceholderRangeValue.js +9 -0
  45. package/dist/cjs/components/RangeDateField/utils/getRangeEditableSections.d.ts +5 -0
  46. package/dist/cjs/components/RangeDateField/utils/getRangeEditableSections.js +42 -0
  47. package/dist/cjs/components/RangeDateField/utils/index.d.ts +3 -0
  48. package/dist/cjs/components/RangeDateField/utils/index.js +6 -0
  49. package/dist/cjs/components/RangeDateField/utils/isValidRange.d.ts +3 -0
  50. package/dist/cjs/components/RangeDateField/utils/isValidRange.js +8 -0
  51. package/dist/cjs/components/RelativeDateField/RelativeDateField.d.ts +2 -2
  52. package/dist/cjs/components/RelativeDateField/RelativeDateField.js +5 -2
  53. package/dist/cjs/components/RelativeDateField/hooks/useRelativeDateFieldProps.js +5 -11
  54. package/dist/cjs/components/RelativeDateField/hooks/useRelativeDateFieldState.d.ts +3 -1
  55. package/dist/cjs/components/RelativeDateField/hooks/useRelativeDateFieldState.js +5 -4
  56. package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.css +3 -0
  57. package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.d.ts +2 -2
  58. package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.js +13 -2
  59. package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.js +35 -27
  60. package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerState.d.ts +2 -2
  61. package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerState.js +12 -16
  62. package/dist/cjs/components/RelativeRangeDatePicker/RelativeRangeDatePicker.css +56 -0
  63. package/dist/cjs/components/RelativeRangeDatePicker/RelativeRangeDatePicker.d.ts +27 -0
  64. package/dist/cjs/components/RelativeRangeDatePicker/RelativeRangeDatePicker.js +90 -0
  65. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.css +32 -0
  66. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.d.ts +14 -0
  67. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.js +43 -0
  68. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/i18n/en.json +8 -0
  69. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/i18n/index.d.ts +1 -0
  70. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/i18n/index.js +9 -0
  71. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/i18n/ru.json +8 -0
  72. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.d.ts +16 -0
  73. package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.js +104 -0
  74. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/Presets.css +26 -0
  75. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/Presets.d.ts +18 -0
  76. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/Presets.js +67 -0
  77. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.css +14 -0
  78. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.d.ts +7 -0
  79. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.js +90 -0
  80. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/defaultPresets.d.ts +9 -0
  81. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/defaultPresets.js +186 -0
  82. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/i18n/en.json +40 -0
  83. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/i18n/index.d.ts +1 -0
  84. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/i18n/index.js +9 -0
  85. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/i18n/ru.json +40 -0
  86. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/utils.d.ts +16 -0
  87. package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/utils.js +85 -0
  88. package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/Zones.css +3 -0
  89. package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/Zones.d.ts +9 -0
  90. package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/Zones.js +62 -0
  91. package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/i18n/en.json +4 -0
  92. package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/i18n/index.d.ts +1 -0
  93. package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/i18n/index.js +9 -0
  94. package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/i18n/ru.json +4 -0
  95. package/dist/cjs/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.d.ts +26 -0
  96. package/dist/cjs/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.js +58 -0
  97. package/dist/cjs/components/RelativeRangeDatePicker/i18n/en.json +8 -0
  98. package/dist/cjs/components/RelativeRangeDatePicker/i18n/index.d.ts +1 -0
  99. package/dist/cjs/components/RelativeRangeDatePicker/i18n/index.js +9 -0
  100. package/dist/cjs/components/RelativeRangeDatePicker/i18n/ru.json +8 -0
  101. package/dist/cjs/components/RelativeRangeDatePicker/index.d.ts +4 -0
  102. package/dist/cjs/components/RelativeRangeDatePicker/index.js +8 -0
  103. package/dist/cjs/components/RelativeRangeDatePicker/utils.d.ts +15 -0
  104. package/dist/cjs/components/RelativeRangeDatePicker/utils.js +53 -0
  105. package/dist/cjs/components/index.d.ts +3 -0
  106. package/dist/cjs/components/index.js +2 -0
  107. package/dist/cjs/components/types/datePicker.d.ts +5 -2
  108. package/dist/cjs/components/types/events.d.ts +4 -4
  109. package/dist/cjs/components/types/inputs.d.ts +10 -9
  110. package/dist/cjs/components/utils/dates.d.ts +1 -2
  111. package/dist/cjs/components/utils/useDefaultTimeZone.d.ts +2 -0
  112. package/dist/cjs/components/utils/useDefaultTimeZone.js +15 -0
  113. package/dist/cjs/components/utils/validation/datePicker.d.ts +6 -0
  114. package/dist/cjs/components/utils/validation/datePicker.js +30 -0
  115. package/dist/cjs/components/utils/validation/i18n/en.json +6 -0
  116. package/dist/cjs/components/utils/validation/i18n/index.d.ts +1 -0
  117. package/dist/cjs/components/utils/validation/i18n/index.js +9 -0
  118. package/dist/cjs/components/utils/validation/i18n/ru.json +6 -0
  119. package/dist/esm/components/Calendar/Calendar.d.ts +6 -5
  120. package/dist/esm/components/Calendar/Calendar.js +4 -4
  121. package/dist/esm/components/Calendar/index.d.ts +6 -6
  122. package/dist/esm/components/Calendar/index.js +5 -5
  123. package/dist/esm/components/{CalendarBase → CalendarView}/Calendar.css +9 -6
  124. package/dist/esm/components/{CalendarBase/CalendarBase.d.ts → CalendarView/CalendarView.d.ts} +2 -2
  125. package/dist/esm/components/{CalendarBase/CalendarBase.js → CalendarView/CalendarView.js} +3 -2
  126. package/dist/{cjs/components/CalendarBase → esm/components/CalendarView}/hooks/types.d.ts +37 -31
  127. package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarCellProps.js +1 -2
  128. package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarGridProps.d.ts +2 -2
  129. package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarGridProps.js +0 -1
  130. package/dist/{cjs/components/CalendarBase → esm/components/CalendarView}/hooks/useCalendarState.d.ts +1 -1
  131. package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarState.js +46 -24
  132. package/dist/esm/components/CalendarView/hooks/useRangeCalendarState.d.ts +8 -0
  133. package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useRangeCalendarState.js +24 -13
  134. package/dist/esm/components/DateField/DateField.d.ts +1 -4
  135. package/dist/esm/components/DateField/DateField.js +4 -2
  136. package/dist/esm/components/DateField/hooks/useBaseDateFieldState.d.ts +97 -0
  137. package/dist/esm/components/DateField/hooks/useBaseDateFieldState.js +311 -0
  138. package/dist/esm/components/DateField/hooks/useDateFieldProps.d.ts +6 -3
  139. package/dist/esm/components/DateField/hooks/useDateFieldProps.js +14 -12
  140. package/dist/esm/components/DateField/hooks/useDateFieldState.d.ts +2 -65
  141. package/dist/esm/components/DateField/hooks/useDateFieldState.js +97 -409
  142. package/dist/esm/components/DateField/index.d.ts +1 -0
  143. package/dist/esm/components/DateField/index.js +1 -0
  144. package/dist/esm/components/DateField/utils.d.ts +10 -1
  145. package/dist/esm/components/DateField/utils.js +105 -2
  146. package/dist/esm/components/DatePicker/DatePicker.d.ts +4 -4
  147. package/dist/esm/components/DatePicker/DatePicker.js +6 -6
  148. package/dist/esm/components/DatePicker/MobileCalendar.css +6 -6
  149. package/dist/esm/components/DatePicker/MobileCalendar.js +17 -12
  150. package/dist/esm/components/DatePicker/hooks/useDatePickerProps.js +5 -16
  151. package/dist/esm/components/DatePicker/hooks/useDatePickerState.d.ts +5 -4
  152. package/dist/esm/components/DatePicker/hooks/useDatePickerState.js +71 -56
  153. package/dist/esm/components/RangeCalendar/RangeCalendar.d.ts +3 -3
  154. package/dist/esm/components/RangeCalendar/RangeCalendar.js +4 -4
  155. package/dist/esm/components/RangeDateField/RangeDateField.css +4 -0
  156. package/dist/esm/components/RangeDateField/RangeDateField.d.ts +12 -0
  157. package/dist/esm/components/RangeDateField/RangeDateField.js +21 -0
  158. package/dist/esm/components/RangeDateField/hooks/useRangeDateFieldState.d.ts +9 -0
  159. package/dist/esm/components/RangeDateField/hooks/useRangeDateFieldState.js +222 -0
  160. package/dist/esm/components/RangeDateField/index.d.ts +2 -0
  161. package/dist/esm/components/RangeDateField/index.js +2 -0
  162. package/dist/esm/components/RangeDateField/utils/createPlaceholderRangeValue.d.ts +5 -0
  163. package/dist/esm/components/RangeDateField/utils/createPlaceholderRangeValue.js +5 -0
  164. package/dist/esm/components/RangeDateField/utils/getRangeEditableSections.d.ts +5 -0
  165. package/dist/esm/components/RangeDateField/utils/getRangeEditableSections.js +38 -0
  166. package/dist/esm/components/RangeDateField/utils/index.d.ts +3 -0
  167. package/dist/esm/components/RangeDateField/utils/index.js +3 -0
  168. package/dist/esm/components/RangeDateField/utils/isValidRange.d.ts +3 -0
  169. package/dist/esm/components/RangeDateField/utils/isValidRange.js +4 -0
  170. package/dist/esm/components/RelativeDateField/RelativeDateField.d.ts +2 -2
  171. package/dist/esm/components/RelativeDateField/RelativeDateField.js +5 -2
  172. package/dist/esm/components/RelativeDateField/hooks/useRelativeDateFieldProps.js +5 -11
  173. package/dist/esm/components/RelativeDateField/hooks/useRelativeDateFieldState.d.ts +3 -1
  174. package/dist/esm/components/RelativeDateField/hooks/useRelativeDateFieldState.js +5 -4
  175. package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.css +3 -0
  176. package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.d.ts +2 -2
  177. package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.js +13 -2
  178. package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.js +35 -27
  179. package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerState.d.ts +2 -2
  180. package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerState.js +12 -16
  181. package/dist/esm/components/RelativeRangeDatePicker/RelativeRangeDatePicker.css +56 -0
  182. package/dist/esm/components/RelativeRangeDatePicker/RelativeRangeDatePicker.d.ts +27 -0
  183. package/dist/esm/components/RelativeRangeDatePicker/RelativeRangeDatePicker.js +85 -0
  184. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.css +32 -0
  185. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.d.ts +14 -0
  186. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.js +39 -0
  187. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/i18n/en.json +8 -0
  188. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/i18n/index.d.ts +1 -0
  189. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/i18n/index.js +5 -0
  190. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/i18n/ru.json +8 -0
  191. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.d.ts +16 -0
  192. package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.js +99 -0
  193. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/Presets.css +26 -0
  194. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/Presets.d.ts +18 -0
  195. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/Presets.js +62 -0
  196. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.css +14 -0
  197. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.d.ts +7 -0
  198. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.js +85 -0
  199. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/defaultPresets.d.ts +9 -0
  200. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/defaultPresets.js +183 -0
  201. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/i18n/en.json +40 -0
  202. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/i18n/index.d.ts +1 -0
  203. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/i18n/index.js +5 -0
  204. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/i18n/ru.json +40 -0
  205. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/utils.d.ts +16 -0
  206. package/dist/esm/components/RelativeRangeDatePicker/components/Presets/utils.js +78 -0
  207. package/dist/esm/components/RelativeRangeDatePicker/components/Zones/Zones.css +3 -0
  208. package/dist/esm/components/RelativeRangeDatePicker/components/Zones/Zones.d.ts +9 -0
  209. package/dist/esm/components/RelativeRangeDatePicker/components/Zones/Zones.js +58 -0
  210. package/dist/esm/components/RelativeRangeDatePicker/components/Zones/i18n/en.json +4 -0
  211. package/dist/esm/components/RelativeRangeDatePicker/components/Zones/i18n/index.d.ts +1 -0
  212. package/dist/esm/components/RelativeRangeDatePicker/components/Zones/i18n/index.js +5 -0
  213. package/dist/esm/components/RelativeRangeDatePicker/components/Zones/i18n/ru.json +4 -0
  214. package/dist/esm/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.d.ts +26 -0
  215. package/dist/esm/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.js +53 -0
  216. package/dist/esm/components/RelativeRangeDatePicker/i18n/en.json +8 -0
  217. package/dist/esm/components/RelativeRangeDatePicker/i18n/index.d.ts +1 -0
  218. package/dist/esm/components/RelativeRangeDatePicker/i18n/index.js +5 -0
  219. package/dist/esm/components/RelativeRangeDatePicker/i18n/ru.json +8 -0
  220. package/dist/esm/components/RelativeRangeDatePicker/index.d.ts +4 -0
  221. package/dist/esm/components/RelativeRangeDatePicker/index.js +3 -0
  222. package/dist/esm/components/RelativeRangeDatePicker/utils.d.ts +15 -0
  223. package/dist/esm/components/RelativeRangeDatePicker/utils.js +46 -0
  224. package/dist/esm/components/index.d.ts +3 -0
  225. package/dist/esm/components/index.js +2 -0
  226. package/dist/esm/components/types/datePicker.d.ts +5 -2
  227. package/dist/esm/components/types/events.d.ts +4 -4
  228. package/dist/esm/components/types/inputs.d.ts +10 -9
  229. package/dist/esm/components/utils/dates.d.ts +1 -2
  230. package/dist/esm/components/utils/useDefaultTimeZone.d.ts +2 -0
  231. package/dist/esm/components/utils/useDefaultTimeZone.js +10 -0
  232. package/dist/esm/components/utils/validation/datePicker.d.ts +6 -0
  233. package/dist/esm/components/utils/validation/datePicker.js +26 -0
  234. package/dist/esm/components/utils/validation/i18n/en.json +6 -0
  235. package/dist/esm/components/utils/validation/i18n/index.d.ts +1 -0
  236. package/dist/esm/components/utils/validation/i18n/index.js +5 -0
  237. package/dist/esm/components/utils/validation/i18n/ru.json +6 -0
  238. package/package.json +27 -27
  239. package/dist/cjs/components/CalendarBase/hooks/useRangeCalendarState.d.ts +0 -7
  240. package/dist/cjs/components/hooks/useControlledState.d.ts +0 -1
  241. package/dist/cjs/components/hooks/useControlledState.js +0 -28
  242. package/dist/esm/components/CalendarBase/hooks/useRangeCalendarState.d.ts +0 -7
  243. package/dist/esm/components/hooks/useControlledState.d.ts +0 -1
  244. package/dist/esm/components/hooks/useControlledState.js +0 -23
  245. /package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/types.js +0 -0
  246. /package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useCalendarCellProps.d.ts +0 -0
  247. /package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useCalendarGridProps.js +0 -0
  248. /package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useCalendarProps.d.ts +0 -0
  249. /package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useCalendarProps.js +0 -0
  250. /package/dist/cjs/components/{CalendarBase → CalendarView}/i18n/en.json +0 -0
  251. /package/dist/cjs/components/{CalendarBase → CalendarView}/i18n/index.d.ts +0 -0
  252. /package/dist/cjs/components/{CalendarBase → CalendarView}/i18n/index.js +0 -0
  253. /package/dist/cjs/components/{CalendarBase → CalendarView}/i18n/ru.json +0 -0
  254. /package/dist/cjs/components/{CalendarBase → CalendarView}/utils.d.ts +0 -0
  255. /package/dist/cjs/components/{CalendarBase → CalendarView}/utils.js +0 -0
  256. /package/dist/esm/components/{CalendarBase → CalendarView}/hooks/types.js +0 -0
  257. /package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarCellProps.d.ts +0 -0
  258. /package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarProps.d.ts +0 -0
  259. /package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarProps.js +0 -0
  260. /package/dist/esm/components/{CalendarBase → CalendarView}/i18n/en.json +0 -0
  261. /package/dist/esm/components/{CalendarBase → CalendarView}/i18n/index.d.ts +0 -0
  262. /package/dist/esm/components/{CalendarBase → CalendarView}/i18n/index.js +0 -0
  263. /package/dist/esm/components/{CalendarBase → CalendarView}/i18n/ru.json +0 -0
  264. /package/dist/esm/components/{CalendarBase → CalendarView}/utils.d.ts +0 -0
  265. /package/dist/esm/components/{CalendarBase → CalendarView}/utils.js +0 -0
@@ -1,62 +1,48 @@
1
1
  import React from 'react';
2
- import { dateTime, isValid } from '@gravity-ui/date-utils';
3
- import { useControlledState } from '../../hooks/useControlledState';
4
- import { createPlaceholderValue, isInvalid, mergeDateTime } from '../../utils/dates';
5
- import { addSegment, getDurationUnitFromSectionType, getSectionLimits, getSectionValue, setSegment, splitFormatIntoSections, } from '../utils';
6
- const EDITABLE_SEGMENTS = {
7
- year: true,
8
- month: true,
9
- day: true,
10
- hour: true,
11
- minute: true,
12
- second: true,
13
- dayPeriod: true,
14
- weekday: true,
15
- };
16
- const PAGE_STEP = {
17
- year: 5,
18
- month: 2,
19
- weekday: 3,
20
- day: 7,
21
- hour: 2,
22
- minute: 15,
23
- second: 15,
24
- };
2
+ import { isValid } from '@gravity-ui/date-utils';
3
+ import { useControlledState } from '@gravity-ui/uikit';
4
+ import { createPlaceholderValue, isInvalid } from '../../utils/dates';
5
+ import { useDefaultTimeZone } from '../../utils/useDefaultTimeZone';
6
+ import { EDITABLE_SEGMENTS, addSegment, getEditableSections, isAllSegmentsValid, parseDateFromString, setSegment, useFormatSections, } from '../utils';
7
+ import { useBaseDateFieldState } from './useBaseDateFieldState';
25
8
  export function useDateFieldState(props) {
26
- var _a;
27
- const [value, setDate] = useControlledState(props.value, props.defaultValue, props.onUpdate);
9
+ var _a, _b;
10
+ const [value, setDate] = useControlledState(props.value, (_a = props.defaultValue) !== null && _a !== void 0 ? _a : null, props.onUpdate);
11
+ const inputTimeZone = useDefaultTimeZone(props.value || props.defaultValue || props.placeholderValue);
12
+ const timeZone = props.timeZone || inputTimeZone;
13
+ const handleUpdateDate = (v) => {
14
+ setDate(v ? v.timeZone(inputTimeZone) : v);
15
+ };
28
16
  const [placeholderDate, setPlaceholderDate] = React.useState(() => {
29
17
  return createPlaceholderValue({
30
18
  placeholderValue: props.placeholderValue,
31
- timeZone: props.timeZone,
19
+ timeZone,
32
20
  });
33
21
  });
34
22
  const format = props.format || 'L';
35
23
  const sections = useFormatSections(format);
36
24
  const allSegments = React.useMemo(() => sections
37
25
  .filter((seg) => EDITABLE_SEGMENTS[seg.type])
38
- .reduce((p, seg) => {
39
- p[seg.type] = true;
40
- return p;
41
- }, {}), [sections]);
42
- const validSegmentsState = React.useState(() => props.value || props.defaultValue ? Object.assign({}, allSegments) : {});
26
+ .reduce((p, seg) => (Object.assign(Object.assign({}, p), { [seg.type]: true })), {}), [sections]);
27
+ const validSegmentsState = React.useState(() => value ? Object.assign({}, allSegments) : {});
43
28
  let validSegments = validSegmentsState[0];
44
29
  const setValidSegments = validSegmentsState[1];
45
- if (value && Object.keys(validSegments).length < Object.keys(allSegments).length) {
30
+ if (value && !isAllSegmentsValid(allSegments, validSegments)) {
46
31
  setValidSegments(Object.assign({}, allSegments));
47
32
  }
48
33
  if (!value &&
49
- Object.keys(validSegments).length > 0 &&
34
+ isAllSegmentsValid(allSegments, validSegments) &&
50
35
  Object.keys(validSegments).length === Object.keys(allSegments).length) {
51
36
  validSegments = {};
52
37
  setValidSegments(validSegments);
53
- setPlaceholderDate(createPlaceholderValue({ timeZone: props.timeZone }));
38
+ setPlaceholderDate(createPlaceholderValue({
39
+ placeholderValue: props.placeholderValue,
40
+ timeZone,
41
+ }));
54
42
  }
55
- const displayValue = value &&
56
- isValid(value) &&
57
- Object.keys(validSegments).length >= Object.keys(allSegments).length
58
- ? value
59
- : placeholderDate;
43
+ const displayValue = value && isValid(value) && isAllSegmentsValid(allSegments, validSegments)
44
+ ? value.timeZone(timeZone)
45
+ : placeholderDate.timeZone(timeZone);
60
46
  const sectionsState = useSectionsState(sections, displayValue, validSegments);
61
47
  const [selectedSections, setSelectedSections] = React.useState(-1);
62
48
  const selectedSectionIndexes = React.useMemo(() => {
@@ -82,14 +68,14 @@ export function useDateFieldState(props) {
82
68
  if (props.disabled || props.readOnly) {
83
69
  return;
84
70
  }
85
- if (Object.keys(validSegments).length >= Object.keys(allSegments).length) {
71
+ if (isAllSegmentsValid(allSegments, validSegments)) {
86
72
  if (!value || !newValue.isSame(value)) {
87
- setDate(newValue);
73
+ handleUpdateDate(newValue);
88
74
  }
89
75
  }
90
76
  else {
91
77
  if (value) {
92
- setDate(null);
78
+ handleUpdateDate(null);
93
79
  }
94
80
  setPlaceholderDate(newValue);
95
81
  }
@@ -104,348 +90,85 @@ export function useDateFieldState(props) {
104
90
  }
105
91
  setValidSegments(Object.assign({}, validSegments));
106
92
  }
107
- function setSection(section, amount) {
108
- markValid(section.type);
109
- setValue(setSegment(section, displayValue, amount));
93
+ function setSection(sectionIndex, amount) {
94
+ const section = sectionsState.editableSections[sectionIndex];
95
+ if (section) {
96
+ markValid(section.type);
97
+ setValue(setSegment(section, displayValue, amount));
98
+ }
110
99
  }
111
100
  function adjustSection(sectionIndex, amount) {
112
101
  const section = sectionsState.editableSections[sectionIndex];
113
- if (validSegments[section.type]) {
114
- setValue(addSegment(section, displayValue, amount));
115
- }
116
- else {
117
- markValid(section.type);
118
- if (Object.keys(validSegments).length >= Object.keys(allSegments).length) {
119
- setValue(displayValue);
102
+ if (section) {
103
+ if (validSegments[section.type]) {
104
+ setValue(addSegment(section, displayValue, amount));
105
+ }
106
+ else {
107
+ markValid(section.type);
108
+ if (Object.keys(validSegments).length >= Object.keys(allSegments).length) {
109
+ setValue(displayValue);
110
+ }
120
111
  }
121
112
  }
122
113
  }
123
- const enteredKeys = React.useRef('');
114
+ function flushValidSection(sectionIndex) {
115
+ const section = sectionsState.editableSections[sectionIndex];
116
+ if (section) {
117
+ delete validSegments[section.type];
118
+ }
119
+ setValidSegments(Object.assign({}, validSegments));
120
+ }
121
+ function flushAllValidSections() {
122
+ validSegments = {};
123
+ setValidSegments({});
124
+ }
125
+ function getSectionValue(_sectionIndex) {
126
+ return displayValue;
127
+ }
128
+ function setSectionValue(_sectionIndex, currentValue) {
129
+ setValue(currentValue);
130
+ }
131
+ function createPlaceholder() {
132
+ return createPlaceholderValue({
133
+ placeholderValue: props.placeholderValue,
134
+ timeZone,
135
+ }).timeZone(timeZone);
136
+ }
137
+ function setValueFromString(str) {
138
+ const date = parseDateFromString(str, props.format || 'L', timeZone);
139
+ if (isValid(date)) {
140
+ handleUpdateDate(date);
141
+ return true;
142
+ }
143
+ return false;
144
+ }
124
145
  const validationState = props.validationState ||
125
146
  (isInvalid(value, props.minValue, props.maxValue) ? 'invalid' : undefined) ||
126
- (value && ((_a = props.isDateUnavailable) === null || _a === void 0 ? void 0 : _a.call(props, value)) ? 'invalid' : undefined);
127
- return {
128
- value: value !== null && value !== void 0 ? value : null,
129
- isEmpty: Object.keys(validSegments).length === 0,
147
+ (value && ((_b = props.isDateUnavailable) === null || _b === void 0 ? void 0 : _b.call(props, value)) ? 'invalid' : undefined);
148
+ return useBaseDateFieldState({
149
+ value,
130
150
  displayValue,
131
- setValue,
132
- // use ltr direction context to get predictable navigation inside input
133
- text: '\u2066' + sectionsState.editableSections.map((s) => s.textValue).join('') + '\u2069',
151
+ placeholderValue: props.placeholderValue,
152
+ timeZone,
153
+ validationState,
154
+ editableSections: sectionsState.editableSections,
134
155
  readOnly: props.readOnly,
135
156
  disabled: props.disabled,
136
- sections: sectionsState.editableSections,
137
157
  selectedSectionIndexes,
138
- validationState,
139
- setSelectedSections(position) {
140
- enteredKeys.current = '';
141
- setSelectedSections(position);
142
- },
143
- focusSectionInPosition(position) {
144
- const nextSectionIndex = this.sections.findIndex((s) => s.end >= position);
145
- const index = nextSectionIndex === -1 ? 0 : nextSectionIndex;
146
- const nextSection = this.sections[index];
147
- if (nextSection) {
148
- this.setSelectedSections(EDITABLE_SEGMENTS[nextSection.type] ? index : nextSection.nextEditableSection);
149
- }
150
- },
151
- focusNextSection() {
152
- var _a, _b;
153
- const currentIndex = selectedSections === 'all' ? 0 : selectedSections;
154
- const newIndex = (_b = (_a = this.sections[currentIndex]) === null || _a === void 0 ? void 0 : _a.nextEditableSection) !== null && _b !== void 0 ? _b : -1;
155
- if (newIndex !== -1) {
156
- this.setSelectedSections(newIndex);
157
- }
158
- },
159
- focusPreviousSection() {
160
- var _a, _b;
161
- const currentIndex = selectedSections === 'all' ? 0 : selectedSections;
162
- const newIndex = (_b = (_a = this.sections[currentIndex]) === null || _a === void 0 ? void 0 : _a.previousEditableSection) !== null && _b !== void 0 ? _b : -1;
163
- if (newIndex !== -1) {
164
- this.setSelectedSections(newIndex);
165
- }
166
- },
167
- focusFirstSection() {
168
- var _a, _b;
169
- const newIndex = (_b = (_a = this.sections[0]) === null || _a === void 0 ? void 0 : _a.previousEditableSection) !== null && _b !== void 0 ? _b : -1;
170
- if (newIndex !== -1) {
171
- setSelectedSections(newIndex);
172
- }
173
- },
174
- focusLastSection() {
175
- var _a, _b;
176
- const newIndex = (_b = (_a = this.sections[this.sections.length - 1]) === null || _a === void 0 ? void 0 : _a.nextEditableSection) !== null && _b !== void 0 ? _b : -1;
177
- if (newIndex !== -1) {
178
- this.setSelectedSections(newIndex);
179
- }
180
- },
181
- increment() {
182
- if (this.readOnly || this.disabled) {
183
- return;
184
- }
185
- enteredKeys.current = '';
186
- const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);
187
- if (sectionIndex !== -1) {
188
- adjustSection(sectionIndex, 1);
189
- }
190
- },
191
- decrement() {
192
- if (this.readOnly || this.disabled) {
193
- return;
194
- }
195
- enteredKeys.current = '';
196
- const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);
197
- if (sectionIndex !== -1) {
198
- adjustSection(sectionIndex, -1);
199
- }
200
- },
201
- incrementPage() {
202
- if (this.readOnly || this.disabled) {
203
- return;
204
- }
205
- enteredKeys.current = '';
206
- const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);
207
- if (sectionIndex !== -1) {
208
- adjustSection(sectionIndex, PAGE_STEP[this.sections[sectionIndex].type] || 1);
209
- }
210
- },
211
- decrementPage() {
212
- if (this.readOnly || this.disabled) {
213
- return;
214
- }
215
- enteredKeys.current = '';
216
- const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);
217
- if (sectionIndex !== -1) {
218
- adjustSection(sectionIndex, -(PAGE_STEP[this.sections[sectionIndex].type] || 1));
219
- }
220
- },
221
- incrementToMax() {
222
- if (this.readOnly || this.disabled) {
223
- return;
224
- }
225
- enteredKeys.current = '';
226
- const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);
227
- if (sectionIndex !== -1) {
228
- const section = this.sections[sectionIndex];
229
- if (typeof section.maxValue === 'number') {
230
- setSection(section, section.maxValue);
231
- }
232
- }
233
- },
234
- decrementToMin() {
235
- if (this.readOnly || this.disabled) {
236
- return;
237
- }
238
- enteredKeys.current = '';
239
- const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);
240
- if (sectionIndex !== -1) {
241
- const section = this.sections[sectionIndex];
242
- if (typeof section.minValue === 'number') {
243
- setSection(section, section.minValue);
244
- }
245
- }
246
- },
247
- clearSection() {
248
- if (this.readOnly || this.disabled) {
249
- return;
250
- }
251
- enteredKeys.current = '';
252
- if (selectedSections === 'all') {
253
- this.clearAll();
254
- return;
255
- }
256
- const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);
257
- if (sectionIndex === -1) {
258
- return;
259
- }
260
- const section = this.sections[sectionIndex];
261
- delete validSegments[section.type];
262
- setValidSegments(Object.assign({}, validSegments));
263
- const placeholder = createPlaceholderValue({
264
- placeholderValue: props.placeholderValue,
265
- timeZone: props.timeZone,
266
- });
267
- let currentValue = displayValue;
268
- // Reset day period to default without changing the hour.
269
- if (section.type === 'dayPeriod') {
270
- const isPM = displayValue.hour() >= 12;
271
- const shouldBePM = placeholder.hour() >= 12;
272
- if (isPM && !shouldBePM) {
273
- currentValue = displayValue.set('hour', displayValue.hour() - 12);
274
- }
275
- else if (!isPM && shouldBePM) {
276
- currentValue = displayValue.set('hour', displayValue.hour() + 12);
277
- }
278
- }
279
- else {
280
- const type = getDurationUnitFromSectionType(section.type);
281
- currentValue = displayValue.set(type, placeholder[type]());
282
- }
283
- setValue(currentValue);
284
- },
285
- clearAll() {
286
- if (this.readOnly || this.disabled) {
287
- return;
288
- }
289
- enteredKeys.current = '';
290
- validSegments = {};
291
- setValidSegments({});
292
- if (value !== null) {
293
- setDate(null);
294
- }
295
- setValue(createPlaceholderValue({
296
- placeholderValue: props.placeholderValue,
297
- timeZone: props.timeZone,
298
- }));
299
- },
300
- onInput(key) {
301
- if (this.readOnly || this.disabled) {
302
- return;
303
- }
304
- const sectionIndex = getCurrentEditableSectionIndex(this.sections, selectedSections);
305
- if (sectionIndex === -1) {
306
- return;
307
- }
308
- const section = this.sections[sectionIndex];
309
- let newValue = enteredKeys.current + key;
310
- const onInputNumber = (numberValue) => {
311
- var _a, _b, _c;
312
- let sectionValue = section.type === 'month' ? numberValue - 1 : numberValue;
313
- const allowsZero = section.minValue === 0;
314
- if (section.type === 'hour' &&
315
- (section.minValue === 12 || section.maxValue === 11)) {
316
- if (numberValue > 12) {
317
- sectionValue = Number(key);
318
- }
319
- if (section.minValue === 12 && sectionValue > 1) {
320
- sectionValue += 12;
321
- }
322
- }
323
- else if (sectionValue > ((_a = section.maxValue) !== null && _a !== void 0 ? _a : 0)) {
324
- sectionValue = Number(key) - (section.type === 'month' ? 1 : 0);
325
- newValue = key;
326
- if (sectionValue > ((_b = section.maxValue) !== null && _b !== void 0 ? _b : 0)) {
327
- enteredKeys.current = '';
328
- return;
329
- }
330
- }
331
- const shouldSetValue = sectionValue > 0 || (sectionValue === 0 && allowsZero);
332
- if (shouldSetValue) {
333
- setSection(section, sectionValue);
334
- }
335
- if (Number(numberValue + '0') > ((_c = section.maxValue) !== null && _c !== void 0 ? _c : 0) ||
336
- newValue.length >= String(section.maxValue).length) {
337
- enteredKeys.current = '';
338
- if (shouldSetValue) {
339
- this.focusNextSection();
340
- }
341
- }
342
- else {
343
- enteredKeys.current = newValue;
344
- }
345
- };
346
- const onInputString = (stringValue) => {
347
- var _a;
348
- const options = (_a = section.options) !== null && _a !== void 0 ? _a : [];
349
- let sectionValue = stringValue.toLocaleUpperCase();
350
- let foundOptions = options.filter((v) => v.startsWith(sectionValue));
351
- if (foundOptions.length === 0) {
352
- if (stringValue !== key) {
353
- sectionValue = key.toLocaleUpperCase();
354
- foundOptions = options.filter((v) => v.startsWith(sectionValue));
355
- }
356
- if (foundOptions.length === 0) {
357
- enteredKeys.current = '';
358
- return;
359
- }
360
- }
361
- const foundValue = foundOptions[0];
362
- const index = options.indexOf(foundValue);
363
- if (section.type === 'dayPeriod') {
364
- setSection(section, index === 1 ? 12 : 0);
365
- }
366
- else {
367
- setSection(section, index);
368
- }
369
- if (foundOptions.length > 1) {
370
- enteredKeys.current = newValue;
371
- }
372
- else {
373
- enteredKeys.current = '';
374
- this.focusNextSection();
375
- }
376
- };
377
- switch (section.type) {
378
- case 'day':
379
- case 'hour':
380
- case 'minute':
381
- case 'second':
382
- case 'year': {
383
- if (!Number.isInteger(Number(newValue))) {
384
- return;
385
- }
386
- const numberValue = Number(newValue);
387
- onInputNumber(numberValue);
388
- break;
389
- }
390
- case 'dayPeriod': {
391
- onInputString(newValue);
392
- break;
393
- }
394
- case 'weekday':
395
- case 'month': {
396
- if (Number.isInteger(Number(newValue))) {
397
- const numberValue = Number(newValue);
398
- onInputNumber(numberValue);
399
- }
400
- else {
401
- onInputString(newValue);
402
- }
403
- break;
404
- }
405
- }
406
- },
407
- setValueFromString(str) {
408
- enteredKeys.current = '';
409
- let date = parseDate({ input: str, format, timeZone: props.timeZone });
410
- if (isValid(date)) {
411
- if (props.timeZone && !isDateStringWithTimeZone(str)) {
412
- const time = parseDate({ input: str, format });
413
- date = mergeDateTime(date, time);
414
- }
415
- setDate(date);
416
- return true;
417
- }
418
- return false;
419
- },
420
- };
421
- }
422
- function parseDate(options) {
423
- let date = dateTime(options);
424
- if (!isValid(date)) {
425
- date = dateTime(Object.assign(Object.assign({}, options), { format: undefined }));
426
- }
427
- return date;
428
- }
429
- function isDateStringWithTimeZone(str) {
430
- return /z$/i.test(str) || /[+-]\d\d:\d\d$/.test(str);
431
- }
432
- function getCurrentEditableSectionIndex(sections, selectedSections) {
433
- const currentIndex = selectedSections === 'all' || selectedSections === -1 ? 0 : selectedSections;
434
- const section = sections[currentIndex];
435
- if (section && !EDITABLE_SEGMENTS[section.type]) {
436
- return section.nextEditableSection;
437
- }
438
- return section ? currentIndex : -1;
439
- }
440
- function useFormatSections(format) {
441
- const usedFormat = format;
442
- const [sections, setSections] = React.useState(() => splitFormatIntoSections(usedFormat));
443
- const [previousFormat, setFormat] = React.useState(usedFormat);
444
- if (usedFormat !== previousFormat) {
445
- setFormat(usedFormat);
446
- setSections(splitFormatIntoSections(usedFormat));
447
- }
448
- return sections;
158
+ selectedSections,
159
+ isEmpty: Object.keys(validSegments).length === 0,
160
+ flushAllValidSections,
161
+ flushValidSection,
162
+ setSelectedSections,
163
+ setValue,
164
+ setDate: handleUpdateDate,
165
+ adjustSection,
166
+ setSection,
167
+ getSectionValue,
168
+ setSectionValue,
169
+ createPlaceholder,
170
+ setValueFromString,
171
+ });
449
172
  }
450
173
  function useSectionsState(sections, value, validSegments) {
451
174
  const [state, setState] = React.useState(() => {
@@ -458,7 +181,8 @@ function useSectionsState(sections, value, validSegments) {
458
181
  });
459
182
  if (sections !== state.sections ||
460
183
  validSegments !== state.validSegments ||
461
- !value.isSame(state.value)) {
184
+ !value.isSame(state.value) ||
185
+ value.timeZone() !== state.value.timeZone()) {
462
186
  setState({
463
187
  value,
464
188
  sections,
@@ -468,39 +192,3 @@ function useSectionsState(sections, value, validSegments) {
468
192
  }
469
193
  return state;
470
194
  }
471
- function getEditableSections(sections, value, validSegments) {
472
- let position = 1;
473
- const newSections = [];
474
- let previousEditableSection = -1;
475
- for (let i = 0; i < sections.length; i++) {
476
- const section = sections[i];
477
- const isEditable = EDITABLE_SEGMENTS[section.type];
478
- let renderedValue = section.placeholder;
479
- if ((isEditable && validSegments[section.type]) || section.type === 'timeZoneName') {
480
- renderedValue = value.format(section.format);
481
- if (section.contentType === 'digit' &&
482
- renderedValue.length < section.placeholder.length) {
483
- renderedValue = renderedValue.padStart(section.placeholder.length, '0');
484
- }
485
- }
486
- // use bidirectional context to allow the browser autodetect text direction
487
- renderedValue = '\u2068' + renderedValue + '\u2069';
488
- const sectionLength = renderedValue.length;
489
- const newSection = Object.assign(Object.assign(Object.assign({}, section), { value: getSectionValue(section, value), textValue: renderedValue, start: position, end: position + sectionLength, modified: false, previousEditableSection, nextEditableSection: previousEditableSection }), getSectionLimits(section, value));
490
- newSections.push(newSection);
491
- if (isEditable) {
492
- for (let j = Math.max(0, previousEditableSection); j <= i; j++) {
493
- const prevSection = newSections[j];
494
- if (prevSection) {
495
- prevSection.nextEditableSection = i;
496
- if (prevSection.previousEditableSection === -1) {
497
- prevSection.previousEditableSection = i;
498
- }
499
- }
500
- }
501
- previousEditableSection = i;
502
- }
503
- position += sectionLength;
504
- }
505
- return newSections;
506
- }
@@ -1,3 +1,4 @@
1
1
  export * from './DateField';
2
2
  export * from './hooks/useDateFieldState';
3
3
  export * from './hooks/useDateFieldProps';
4
+ export * from './hooks/useBaseDateFieldState';
@@ -1,3 +1,4 @@
1
1
  export * from './DateField';
2
2
  export * from './hooks/useDateFieldState';
3
3
  export * from './hooks/useDateFieldProps';
4
+ export * from './hooks/useBaseDateFieldState';
@@ -1,5 +1,6 @@
1
1
  import type { DateTime } from '@gravity-ui/date-utils';
2
2
  import type { DateFieldSection, DateFieldSectionType, DateFieldSectionWithoutPosition } from './types';
3
+ export declare const EDITABLE_SEGMENTS: Partial<Record<DateFieldSectionType, boolean>>;
3
4
  export declare function expandFormat(format: string): string;
4
5
  export declare function getSectionLimits(section: DateFieldSectionWithoutPosition, date: DateTime): {
5
6
  minValue: number;
@@ -9,8 +10,16 @@ export declare function getSectionLimits(section: DateFieldSectionWithoutPositio
9
10
  maxValue?: undefined;
10
11
  };
11
12
  export declare function getSectionValue(sections: DateFieldSectionWithoutPosition, date: DateTime): number | undefined;
12
- export declare function getDurationUnitFromSectionType(type: DateFieldSectionType): "year" | "month" | "day" | "date" | "hour" | "minute" | "second";
13
+ export declare function getDurationUnitFromSectionType(type: DateFieldSectionType): "year" | "month" | "day" | "hour" | "minute" | "second" | "date";
13
14
  export declare function addSegment(section: DateFieldSection, date: DateTime, amount: number): DateTime;
14
15
  export declare function setSegment(section: DateFieldSection, date: DateTime, amount: number): DateTime;
15
16
  export declare function splitFormatIntoSections(format: string): DateFieldSectionWithoutPosition[];
16
17
  export declare function cleanString(dirtyString: string): string;
18
+ export declare function getEditableSections(sections: DateFieldSectionWithoutPosition[], value: DateTime, validSegments: typeof EDITABLE_SEGMENTS): DateFieldSection[];
19
+ export declare function isEditableSection(section: DateFieldSectionWithoutPosition): boolean;
20
+ export declare function toEditableSection(section: DateFieldSectionWithoutPosition, value: DateTime, validSegments: typeof EDITABLE_SEGMENTS, position: number, previousEditableSection: number): DateFieldSection;
21
+ export declare function getCurrentEditableSectionIndex(sections: DateFieldSection[], selectedSections: 'all' | number): number;
22
+ export declare function formatSections(sections: DateFieldSection[]): string;
23
+ export declare function parseDateFromString(str: string, format: string, timeZone?: string): DateTime;
24
+ export declare function isAllSegmentsValid(allSegments: typeof EDITABLE_SEGMENTS, validSegments: typeof EDITABLE_SEGMENTS): boolean;
25
+ export declare function useFormatSections(format: string): DateFieldSectionWithoutPosition[];