@mui/x-date-pickers 8.0.0-beta.0 → 8.0.0-beta.2

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 (237) hide show
  1. package/CHANGELOG.md +171 -0
  2. package/DateCalendar/DateCalendar.js +4 -8
  3. package/DateCalendar/DayCalendar.d.ts +3 -7
  4. package/DateCalendar/DayCalendar.js +18 -10
  5. package/DateCalendar/index.d.ts +0 -1
  6. package/DateField/useDateField.d.ts +1 -1
  7. package/DateField/useDateField.js +2 -16
  8. package/DatePicker/DatePicker.js +1 -0
  9. package/DatePicker/shared.js +3 -9
  10. package/DateTimeField/useDateTimeField.d.ts +1 -1
  11. package/DateTimeField/useDateTimeField.js +2 -16
  12. package/DateTimePicker/DateTimePicker.js +1 -0
  13. package/DateTimePicker/shared.js +3 -13
  14. package/DesktopDatePicker/DesktopDatePicker.js +1 -0
  15. package/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -0
  16. package/DesktopTimePicker/DesktopTimePicker.js +1 -0
  17. package/MobileDatePicker/MobileDatePicker.js +1 -0
  18. package/MobileDateTimePicker/MobileDateTimePicker.js +1 -0
  19. package/MobileTimePicker/MobileTimePicker.js +1 -0
  20. package/MonthCalendar/MonthCalendar.js +4 -9
  21. package/PickersDay/PickersDay.d.ts +1 -72
  22. package/PickersDay/PickersDay.js +30 -28
  23. package/PickersDay/PickersDay.types.d.ts +114 -0
  24. package/PickersDay/PickersDay.types.js +5 -0
  25. package/PickersDay/index.d.ts +1 -1
  26. package/PickersDay/usePickerDayOwnerState.d.ts +14 -0
  27. package/PickersDay/usePickerDayOwnerState.js +40 -0
  28. package/PickersSectionList/PickersSectionList.d.ts +1 -1
  29. package/PickersSectionList/PickersSectionList.types.d.ts +2 -6
  30. package/TimeField/useTimeField.d.ts +1 -1
  31. package/TimeField/useTimeField.js +2 -16
  32. package/TimePicker/TimePicker.js +1 -0
  33. package/TimePicker/shared.js +3 -3
  34. package/YearCalendar/YearCalendar.js +4 -10
  35. package/esm/DateCalendar/DateCalendar.js +6 -10
  36. package/esm/DateCalendar/DayCalendar.d.ts +3 -7
  37. package/esm/DateCalendar/DayCalendar.js +18 -10
  38. package/esm/DateCalendar/index.d.ts +0 -1
  39. package/esm/DateField/useDateField.d.ts +1 -1
  40. package/esm/DateField/useDateField.js +3 -17
  41. package/esm/DatePicker/DatePicker.js +1 -0
  42. package/esm/DatePicker/shared.js +3 -9
  43. package/esm/DateTimeField/useDateTimeField.d.ts +1 -1
  44. package/esm/DateTimeField/useDateTimeField.js +3 -17
  45. package/esm/DateTimePicker/DateTimePicker.js +1 -0
  46. package/esm/DateTimePicker/shared.js +4 -14
  47. package/esm/DesktopDatePicker/DesktopDatePicker.js +1 -0
  48. package/esm/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -0
  49. package/esm/DesktopTimePicker/DesktopTimePicker.js +1 -0
  50. package/esm/MobileDatePicker/MobileDatePicker.js +1 -0
  51. package/esm/MobileDateTimePicker/MobileDateTimePicker.js +1 -0
  52. package/esm/MobileTimePicker/MobileTimePicker.js +1 -0
  53. package/esm/MonthCalendar/MonthCalendar.js +6 -11
  54. package/esm/PickersDay/PickersDay.d.ts +1 -72
  55. package/esm/PickersDay/PickersDay.js +30 -28
  56. package/esm/PickersDay/PickersDay.types.d.ts +114 -0
  57. package/esm/PickersDay/PickersDay.types.js +1 -0
  58. package/esm/PickersDay/index.d.ts +1 -1
  59. package/esm/PickersDay/usePickerDayOwnerState.d.ts +14 -0
  60. package/esm/PickersDay/usePickerDayOwnerState.js +32 -0
  61. package/esm/PickersSectionList/PickersSectionList.d.ts +1 -1
  62. package/esm/PickersSectionList/PickersSectionList.types.d.ts +2 -6
  63. package/esm/TimeField/useTimeField.d.ts +1 -1
  64. package/esm/TimeField/useTimeField.js +3 -17
  65. package/esm/TimePicker/TimePicker.js +1 -0
  66. package/esm/TimePicker/shared.js +3 -3
  67. package/esm/YearCalendar/YearCalendar.js +5 -11
  68. package/esm/hooks/useSplitFieldProps.d.ts +1 -1
  69. package/esm/index.js +1 -1
  70. package/esm/internals/components/PickerFieldUI.d.ts +5 -5
  71. package/esm/internals/hooks/useField/buildSectionsFromFormat.d.ts +2 -2
  72. package/esm/internals/hooks/useField/buildSectionsFromFormat.js +9 -9
  73. package/esm/internals/hooks/useField/index.d.ts +1 -1
  74. package/esm/internals/hooks/useField/syncSelectionToDOM.d.ts +9 -0
  75. package/esm/internals/hooks/useField/syncSelectionToDOM.js +50 -0
  76. package/esm/internals/hooks/useField/useField.d.ts +2 -4
  77. package/esm/internals/hooks/useField/useField.js +5 -229
  78. package/esm/internals/hooks/useField/useField.types.d.ts +55 -68
  79. package/esm/internals/hooks/useField/useField.utils.d.ts +3 -8
  80. package/esm/internals/hooks/useField/useField.utils.js +7 -149
  81. package/esm/internals/hooks/useField/useFieldCharacterEditing.d.ts +19 -26
  82. package/esm/internals/hooks/useField/useFieldCharacterEditing.js +42 -60
  83. package/esm/internals/hooks/useField/useFieldHiddenInputProps.d.ts +20 -0
  84. package/esm/internals/hooks/useField/useFieldHiddenInputProps.js +31 -0
  85. package/esm/internals/hooks/useField/useFieldInternalPropsWithDefaults.js +8 -10
  86. package/esm/internals/hooks/useField/useFieldRootHandleKeyDown.d.ts +16 -0
  87. package/esm/internals/hooks/useField/useFieldRootHandleKeyDown.js +205 -0
  88. package/esm/internals/hooks/useField/useFieldRootProps.d.ts +32 -0
  89. package/esm/internals/hooks/useField/useFieldRootProps.js +150 -0
  90. package/esm/internals/hooks/useField/useFieldSectionContainerProps.d.ts +15 -0
  91. package/esm/internals/hooks/useField/useFieldSectionContainerProps.js +29 -0
  92. package/esm/internals/hooks/useField/useFieldSectionContentProps.d.ts +23 -0
  93. package/esm/internals/hooks/useField/useFieldSectionContentProps.js +226 -0
  94. package/esm/internals/hooks/useField/useFieldState.d.ts +23 -13
  95. package/esm/internals/hooks/useField/useFieldState.js +103 -30
  96. package/esm/internals/hooks/useField/useFieldV6TextField.d.ts +3 -3
  97. package/esm/internals/hooks/useField/useFieldV6TextField.js +202 -135
  98. package/esm/internals/hooks/useField/useFieldV7TextField.d.ts +3 -2
  99. package/esm/internals/hooks/useField/useFieldV7TextField.js +200 -367
  100. package/esm/internals/hooks/usePicker/usePicker.types.d.ts +1 -0
  101. package/esm/internals/index.d.ts +6 -5
  102. package/esm/internals/index.js +4 -3
  103. package/esm/locales/deDE.js +2 -3
  104. package/esm/managers/useDateManager.d.ts +4 -13
  105. package/esm/managers/useDateManager.js +21 -31
  106. package/esm/managers/useDateTimeManager.d.ts +4 -13
  107. package/esm/managers/useDateTimeManager.js +26 -36
  108. package/esm/managers/useTimeManager.d.ts +4 -13
  109. package/esm/managers/useTimeManager.js +17 -27
  110. package/esm/models/fields.d.ts +2 -2
  111. package/esm/models/manager.d.ts +6 -10
  112. package/esm/validation/validateDate.js +3 -4
  113. package/hooks/useSplitFieldProps.d.ts +1 -1
  114. package/index.js +1 -1
  115. package/internals/components/PickerFieldUI.d.ts +5 -5
  116. package/internals/hooks/useField/buildSectionsFromFormat.d.ts +2 -2
  117. package/internals/hooks/useField/buildSectionsFromFormat.js +9 -9
  118. package/internals/hooks/useField/index.d.ts +1 -1
  119. package/internals/hooks/useField/syncSelectionToDOM.d.ts +9 -0
  120. package/internals/hooks/useField/syncSelectionToDOM.js +56 -0
  121. package/internals/hooks/useField/useField.d.ts +2 -4
  122. package/internals/hooks/useField/useField.js +5 -231
  123. package/internals/hooks/useField/useField.types.d.ts +55 -68
  124. package/internals/hooks/useField/useField.utils.d.ts +3 -8
  125. package/internals/hooks/useField/useField.utils.js +9 -154
  126. package/internals/hooks/useField/useFieldCharacterEditing.d.ts +19 -26
  127. package/internals/hooks/useField/useFieldCharacterEditing.js +41 -59
  128. package/internals/hooks/useField/useFieldHiddenInputProps.d.ts +20 -0
  129. package/internals/hooks/useField/useFieldHiddenInputProps.js +39 -0
  130. package/internals/hooks/useField/useFieldInternalPropsWithDefaults.js +8 -10
  131. package/internals/hooks/useField/useFieldRootHandleKeyDown.d.ts +16 -0
  132. package/internals/hooks/useField/useFieldRootHandleKeyDown.js +211 -0
  133. package/internals/hooks/useField/useFieldRootProps.d.ts +32 -0
  134. package/internals/hooks/useField/useFieldRootProps.js +156 -0
  135. package/internals/hooks/useField/useFieldSectionContainerProps.d.ts +15 -0
  136. package/internals/hooks/useField/useFieldSectionContainerProps.js +37 -0
  137. package/internals/hooks/useField/useFieldSectionContentProps.d.ts +23 -0
  138. package/internals/hooks/useField/useFieldSectionContentProps.js +234 -0
  139. package/internals/hooks/useField/useFieldState.d.ts +23 -13
  140. package/internals/hooks/useField/useFieldState.js +102 -29
  141. package/internals/hooks/useField/useFieldV6TextField.d.ts +3 -3
  142. package/internals/hooks/useField/useFieldV6TextField.js +202 -135
  143. package/internals/hooks/useField/useFieldV7TextField.d.ts +3 -2
  144. package/internals/hooks/useField/useFieldV7TextField.js +200 -367
  145. package/internals/hooks/usePicker/usePicker.types.d.ts +1 -0
  146. package/internals/index.d.ts +6 -5
  147. package/internals/index.js +25 -18
  148. package/locales/deDE.js +2 -3
  149. package/managers/useDateManager.d.ts +4 -13
  150. package/managers/useDateManager.js +21 -31
  151. package/managers/useDateTimeManager.d.ts +4 -13
  152. package/managers/useDateTimeManager.js +26 -36
  153. package/managers/useTimeManager.d.ts +4 -13
  154. package/managers/useTimeManager.js +18 -28
  155. package/models/fields.d.ts +2 -2
  156. package/models/manager.d.ts +6 -10
  157. package/modern/DateCalendar/DateCalendar.js +6 -10
  158. package/modern/DateCalendar/DayCalendar.d.ts +3 -7
  159. package/modern/DateCalendar/DayCalendar.js +18 -10
  160. package/modern/DateCalendar/index.d.ts +0 -1
  161. package/modern/DateField/useDateField.d.ts +1 -1
  162. package/modern/DateField/useDateField.js +3 -17
  163. package/modern/DatePicker/DatePicker.js +1 -0
  164. package/modern/DatePicker/shared.js +3 -9
  165. package/modern/DateTimeField/useDateTimeField.d.ts +1 -1
  166. package/modern/DateTimeField/useDateTimeField.js +3 -17
  167. package/modern/DateTimePicker/DateTimePicker.js +1 -0
  168. package/modern/DateTimePicker/shared.js +4 -14
  169. package/modern/DesktopDatePicker/DesktopDatePicker.js +1 -0
  170. package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -0
  171. package/modern/DesktopTimePicker/DesktopTimePicker.js +1 -0
  172. package/modern/MobileDatePicker/MobileDatePicker.js +1 -0
  173. package/modern/MobileDateTimePicker/MobileDateTimePicker.js +1 -0
  174. package/modern/MobileTimePicker/MobileTimePicker.js +1 -0
  175. package/modern/MonthCalendar/MonthCalendar.js +6 -11
  176. package/modern/PickersDay/PickersDay.d.ts +1 -72
  177. package/modern/PickersDay/PickersDay.js +30 -28
  178. package/modern/PickersDay/PickersDay.types.d.ts +114 -0
  179. package/modern/PickersDay/PickersDay.types.js +1 -0
  180. package/modern/PickersDay/index.d.ts +1 -1
  181. package/modern/PickersDay/usePickerDayOwnerState.d.ts +14 -0
  182. package/modern/PickersDay/usePickerDayOwnerState.js +32 -0
  183. package/modern/PickersSectionList/PickersSectionList.d.ts +1 -1
  184. package/modern/PickersSectionList/PickersSectionList.types.d.ts +2 -6
  185. package/modern/TimeField/useTimeField.d.ts +1 -1
  186. package/modern/TimeField/useTimeField.js +3 -17
  187. package/modern/TimePicker/TimePicker.js +1 -0
  188. package/modern/TimePicker/shared.js +3 -3
  189. package/modern/YearCalendar/YearCalendar.js +5 -11
  190. package/modern/hooks/useSplitFieldProps.d.ts +1 -1
  191. package/modern/index.js +1 -1
  192. package/modern/internals/components/PickerFieldUI.d.ts +5 -5
  193. package/modern/internals/hooks/useField/buildSectionsFromFormat.d.ts +2 -2
  194. package/modern/internals/hooks/useField/buildSectionsFromFormat.js +9 -9
  195. package/modern/internals/hooks/useField/index.d.ts +1 -1
  196. package/modern/internals/hooks/useField/syncSelectionToDOM.d.ts +9 -0
  197. package/modern/internals/hooks/useField/syncSelectionToDOM.js +50 -0
  198. package/modern/internals/hooks/useField/useField.d.ts +2 -4
  199. package/modern/internals/hooks/useField/useField.js +5 -229
  200. package/modern/internals/hooks/useField/useField.types.d.ts +55 -68
  201. package/modern/internals/hooks/useField/useField.utils.d.ts +3 -8
  202. package/modern/internals/hooks/useField/useField.utils.js +7 -149
  203. package/modern/internals/hooks/useField/useFieldCharacterEditing.d.ts +19 -26
  204. package/modern/internals/hooks/useField/useFieldCharacterEditing.js +42 -60
  205. package/modern/internals/hooks/useField/useFieldHiddenInputProps.d.ts +20 -0
  206. package/modern/internals/hooks/useField/useFieldHiddenInputProps.js +31 -0
  207. package/modern/internals/hooks/useField/useFieldInternalPropsWithDefaults.js +8 -10
  208. package/modern/internals/hooks/useField/useFieldRootHandleKeyDown.d.ts +16 -0
  209. package/modern/internals/hooks/useField/useFieldRootHandleKeyDown.js +205 -0
  210. package/modern/internals/hooks/useField/useFieldRootProps.d.ts +32 -0
  211. package/modern/internals/hooks/useField/useFieldRootProps.js +150 -0
  212. package/modern/internals/hooks/useField/useFieldSectionContainerProps.d.ts +15 -0
  213. package/modern/internals/hooks/useField/useFieldSectionContainerProps.js +29 -0
  214. package/modern/internals/hooks/useField/useFieldSectionContentProps.d.ts +23 -0
  215. package/modern/internals/hooks/useField/useFieldSectionContentProps.js +226 -0
  216. package/modern/internals/hooks/useField/useFieldState.d.ts +23 -13
  217. package/modern/internals/hooks/useField/useFieldState.js +103 -30
  218. package/modern/internals/hooks/useField/useFieldV6TextField.d.ts +3 -3
  219. package/modern/internals/hooks/useField/useFieldV6TextField.js +202 -135
  220. package/modern/internals/hooks/useField/useFieldV7TextField.d.ts +3 -2
  221. package/modern/internals/hooks/useField/useFieldV7TextField.js +200 -367
  222. package/modern/internals/hooks/usePicker/usePicker.types.d.ts +1 -0
  223. package/modern/internals/index.d.ts +6 -5
  224. package/modern/internals/index.js +4 -3
  225. package/modern/locales/deDE.js +2 -3
  226. package/modern/managers/useDateManager.d.ts +4 -13
  227. package/modern/managers/useDateManager.js +21 -31
  228. package/modern/managers/useDateTimeManager.d.ts +4 -13
  229. package/modern/managers/useDateTimeManager.js +26 -36
  230. package/modern/managers/useTimeManager.d.ts +4 -13
  231. package/modern/managers/useTimeManager.js +17 -27
  232. package/modern/models/fields.d.ts +2 -2
  233. package/modern/models/manager.d.ts +6 -10
  234. package/modern/validation/validateDate.js +3 -4
  235. package/package.json +2 -2
  236. package/tsconfig.build.tsbuildinfo +1 -1
  237. package/validation/validateDate.js +3 -4
@@ -1,23 +1,5 @@
1
- import { PickersTimezone, InferFieldSection } from "../../../models/index.js";
2
- import { FieldSectionsValueBoundaries } from "./useField.types.js";
3
- import { UpdateSectionValueParams } from "./useFieldState.js";
1
+ import { UseFieldStateReturnValue } from "./useFieldState.js";
4
2
  import { PickerValidValue } from "../../models/index.js";
5
- export interface ApplyCharacterEditingParams {
6
- keyPressed: string;
7
- sectionIndex: number;
8
- }
9
- interface UseFieldCharacterEditingParams<TValue extends PickerValidValue> {
10
- sections: InferFieldSection<TValue>[];
11
- updateSectionValue: (params: UpdateSectionValueParams<TValue>) => void;
12
- sectionsValueBoundaries: FieldSectionsValueBoundaries;
13
- localizedDigits: string[];
14
- setTempAndroidValueStr: (newValue: string | null) => void;
15
- timezone: PickersTimezone;
16
- }
17
- export interface UseFieldCharacterEditingResponse {
18
- applyCharacterEditing: (params: ApplyCharacterEditingParams) => void;
19
- resetCharacterQuery: () => void;
20
- }
21
3
  /**
22
4
  * Update the active section value when the user pressed a key that is not a navigation key (arrow key for example).
23
5
  * This hook has two main editing behaviors
@@ -26,11 +8,22 @@ export interface UseFieldCharacterEditingResponse {
26
8
  * 2. The letter editing when the user presses another key
27
9
  */
28
10
  export declare const useFieldCharacterEditing: <TValue extends PickerValidValue>({
29
- sections,
30
- updateSectionValue,
31
- sectionsValueBoundaries,
32
- localizedDigits,
33
- setTempAndroidValueStr,
34
- timezone
35
- }: UseFieldCharacterEditingParams<TValue>) => UseFieldCharacterEditingResponse;
11
+ stateResponse: {
12
+ localizedDigits,
13
+ sectionsValueBoundaries,
14
+ state,
15
+ timezone,
16
+ setCharacterQuery,
17
+ setTempAndroidValueStr,
18
+ updateSectionValue
19
+ }
20
+ }: UseFieldCharacterEditingParameters<TValue>) => UseFieldCharacterEditingReturnValue;
21
+ export interface ApplyCharacterEditingParameters {
22
+ keyPressed: string;
23
+ sectionIndex: number;
24
+ }
25
+ interface UseFieldCharacterEditingParameters<TValue extends PickerValidValue> {
26
+ stateResponse: UseFieldStateReturnValue<TValue>;
27
+ }
28
+ export type UseFieldCharacterEditingReturnValue = (params: ApplyCharacterEditingParameters) => void;
36
29
  export {};
@@ -1,32 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
- import * as React from 'react';
3
2
  import useEventCallback from '@mui/utils/useEventCallback';
4
3
  import { useUtils } from "../useUtils.js";
5
4
  import { changeSectionValueFormat, cleanDigitSectionValue, doesSectionFormatHaveLeadingZeros, getDateSectionConfigFromFormatToken, getDaysInWeekStr, getLetterEditingOptions, applyLocalizedDigits, removeLocalizedDigits, isStringNumber } from "./useField.utils.js";
6
-
7
- /**
8
- * The letter editing and the numeric editing each define a `CharacterEditingApplier`.
9
- * This function decides what the new section value should be and if the focus should switch to the next section.
10
- *
11
- * If it returns `null`, then the section value is not updated and the focus does not move.
12
- */
13
-
14
- /**
15
- * Function called by `applyQuery` which decides:
16
- * - what is the new section value ?
17
- * - should the query used to get this value be stored for the next key press ?
18
- *
19
- * If it returns `{ sectionValue: string; shouldGoToNextSection: boolean }`,
20
- * Then we store the query and update the section with the new value.
21
- *
22
- * If it returns `{ saveQuery: true` },
23
- * Then we store the query and don't update the section.
24
- *
25
- * If it returns `{ saveQuery: false },
26
- * Then we do nothing.
27
- */
28
-
29
- const QUERY_LIFE_DURATION_MS = 5000;
30
5
  const isQueryResponseWithoutValue = response => response.saveQuery != null;
31
6
 
32
7
  /**
@@ -37,44 +12,33 @@ const isQueryResponseWithoutValue = response => response.saveQuery != null;
37
12
  * 2. The letter editing when the user presses another key
38
13
  */
39
14
  export const useFieldCharacterEditing = ({
40
- sections,
41
- updateSectionValue,
42
- sectionsValueBoundaries,
43
- localizedDigits,
44
- setTempAndroidValueStr,
45
- timezone
15
+ stateResponse: {
16
+ // States and derived states
17
+ localizedDigits,
18
+ sectionsValueBoundaries,
19
+ state,
20
+ timezone,
21
+ // Methods to update the states
22
+ setCharacterQuery,
23
+ setTempAndroidValueStr,
24
+ updateSectionValue
25
+ }
46
26
  }) => {
47
27
  const utils = useUtils();
48
- const [query, setQuery] = React.useState(null);
49
- const resetQuery = useEventCallback(() => setQuery(null));
50
- React.useEffect(() => {
51
- if (query != null && sections[query.sectionIndex]?.type !== query.sectionType) {
52
- resetQuery();
53
- }
54
- }, [sections, query, resetQuery]);
55
- React.useEffect(() => {
56
- if (query != null) {
57
- const timeout = setTimeout(() => resetQuery(), QUERY_LIFE_DURATION_MS);
58
- return () => {
59
- clearTimeout(timeout);
60
- };
61
- }
62
- return () => {};
63
- }, [query, resetQuery]);
64
28
  const applyQuery = ({
65
29
  keyPressed,
66
30
  sectionIndex
67
31
  }, getFirstSectionValueMatchingWithQuery, isValidQueryValue) => {
68
32
  const cleanKeyPressed = keyPressed.toLowerCase();
69
- const activeSection = sections[sectionIndex];
33
+ const activeSection = state.sections[sectionIndex];
70
34
 
71
35
  // The current query targets the section being editing
72
36
  // We can try to concatenate the value
73
- if (query != null && (!isValidQueryValue || isValidQueryValue(query.value)) && query.sectionIndex === sectionIndex) {
74
- const concatenatedQueryValue = `${query.value}${cleanKeyPressed}`;
37
+ if (state.characterQuery != null && (!isValidQueryValue || isValidQueryValue(state.characterQuery.value)) && state.characterQuery.sectionIndex === sectionIndex) {
38
+ const concatenatedQueryValue = `${state.characterQuery.value}${cleanKeyPressed}`;
75
39
  const queryResponse = getFirstSectionValueMatchingWithQuery(concatenatedQueryValue, activeSection);
76
40
  if (!isQueryResponseWithoutValue(queryResponse)) {
77
- setQuery({
41
+ setCharacterQuery({
78
42
  sectionIndex,
79
43
  value: concatenatedQueryValue,
80
44
  sectionType: activeSection.type
@@ -84,10 +48,10 @@ export const useFieldCharacterEditing = ({
84
48
  }
85
49
  const queryResponse = getFirstSectionValueMatchingWithQuery(cleanKeyPressed, activeSection);
86
50
  if (isQueryResponseWithoutValue(queryResponse) && !queryResponse.saveQuery) {
87
- resetQuery();
51
+ setCharacterQuery(null);
88
52
  return null;
89
53
  }
90
- setQuery({
54
+ setCharacterQuery({
91
55
  sectionIndex,
92
56
  value: cleanKeyPressed,
93
57
  sectionType: activeSection.type
@@ -235,8 +199,8 @@ export const useFieldCharacterEditing = ({
235
199
  };
236
200
  return applyQuery(params, getFirstSectionValueMatchingWithQuery, queryValue => isStringNumber(queryValue, localizedDigits));
237
201
  };
238
- const applyCharacterEditing = useEventCallback(params => {
239
- const section = sections[params.sectionIndex];
202
+ return useEventCallback(params => {
203
+ const section = state.sections[params.sectionIndex];
240
204
  const isNumericEditing = isStringNumber(params.keyPressed, localizedDigits);
241
205
  const response = isNumericEditing ? applyNumericEditing(_extends({}, params, {
242
206
  keyPressed: applyLocalizedDigits(params.keyPressed, localizedDigits)
@@ -251,8 +215,26 @@ export const useFieldCharacterEditing = ({
251
215
  shouldGoToNextSection: response.shouldGoToNextSection
252
216
  });
253
217
  });
254
- return {
255
- applyCharacterEditing,
256
- resetCharacterQuery: resetQuery
257
- };
258
- };
218
+ };
219
+
220
+ /**
221
+ * The letter editing and the numeric editing each define a `CharacterEditingApplier`.
222
+ * This function decides what the new section value should be and if the focus should switch to the next section.
223
+ *
224
+ * If it returns `null`, then the section value is not updated and the focus does not move.
225
+ */
226
+
227
+ /**
228
+ * Function called by `applyQuery` which decides:
229
+ * - what is the new section value ?
230
+ * - should the query used to get this value be stored for the next key press ?
231
+ *
232
+ * If it returns `{ sectionValue: string; shouldGoToNextSection: boolean }`,
233
+ * Then we store the query and update the section with the new value.
234
+ *
235
+ * If it returns `{ saveQuery: true` },
236
+ * Then we store the query and don't update the section.
237
+ *
238
+ * If it returns `{ saveQuery: false },
239
+ * Then we do nothing.
240
+ */
@@ -0,0 +1,20 @@
1
+ import * as React from 'react';
2
+ import { PickerManager } from "../../../models/index.js";
3
+ import { UseFieldStateReturnValue } from "./useFieldState.js";
4
+ /**
5
+ * Generate the props to pass to the hidden input element of the field.
6
+ * It is not used by the non-accessible DOM structure (with an <input /> element for editing).
7
+ * It should be used in the MUI accessible DOM structure and the Base UI implementation.
8
+ * @param {UseFieldHiddenInputPropsParameters} parameters The parameters of the hook.
9
+ * @returns {UseFieldHiddenInputPropsReturnValue} The props to forward to the hidden input element of the field.
10
+ */
11
+ export declare function useFieldHiddenInputProps(parameters: UseFieldHiddenInputPropsParameters): UseFieldHiddenInputPropsReturnValue;
12
+ interface UseFieldHiddenInputPropsParameters {
13
+ manager: PickerManager<any, any, any, any, any>;
14
+ stateResponse: UseFieldStateReturnValue<any>;
15
+ }
16
+ interface UseFieldHiddenInputPropsReturnValue {
17
+ value: string;
18
+ onChange: React.ChangeEventHandler<HTMLInputElement>;
19
+ }
20
+ export {};
@@ -0,0 +1,31 @@
1
+ import * as React from 'react';
2
+ import useEventCallback from '@mui/utils/useEventCallback';
3
+ /**
4
+ * Generate the props to pass to the hidden input element of the field.
5
+ * It is not used by the non-accessible DOM structure (with an <input /> element for editing).
6
+ * It should be used in the MUI accessible DOM structure and the Base UI implementation.
7
+ * @param {UseFieldHiddenInputPropsParameters} parameters The parameters of the hook.
8
+ * @returns {UseFieldHiddenInputPropsReturnValue} The props to forward to the hidden input element of the field.
9
+ */
10
+ export function useFieldHiddenInputProps(parameters) {
11
+ const {
12
+ manager: {
13
+ internal_fieldValueManager: fieldValueManager
14
+ },
15
+ stateResponse: {
16
+ // States and derived states
17
+ areAllSectionsEmpty,
18
+ state,
19
+ // Methods to update the states
20
+ updateValueFromValueStr
21
+ }
22
+ } = parameters;
23
+ const handleChange = useEventCallback(event => {
24
+ updateValueFromValueStr(event.target.value);
25
+ });
26
+ const valueStr = React.useMemo(() => areAllSectionsEmpty ? '' : fieldValueManager.getV7HiddenInputValueFromSections(state.sections), [areAllSectionsEmpty, state.sections, fieldValueManager]);
27
+ return {
28
+ value: valueStr,
29
+ onChange: handleChange
30
+ };
31
+ }
@@ -1,7 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import useForkRef from '@mui/utils/useForkRef';
4
- import { useLocalizationContext } from "../useUtils.js";
5
4
  import { useNullablePickerContext } from "../useNullablePickerContext.js";
6
5
  import { useNullableFieldPrivateContext } from "../useNullableFieldPrivateContext.js";
7
6
 
@@ -12,11 +11,12 @@ import { useNullableFieldPrivateContext } from "../useNullableFieldPrivateContex
12
11
  */
13
12
  export function useFieldInternalPropsWithDefaults(parameters) {
14
13
  const {
15
- manager,
14
+ manager: {
15
+ internal_useApplyDefaultValuesToFieldInternalProps: useApplyDefaultValuesToFieldInternalProps
16
+ },
16
17
  internalProps,
17
18
  skipContextFieldRefAssignment
18
19
  } = parameters;
19
- const localizationContext = useLocalizationContext();
20
20
  const pickerContext = useNullablePickerContext();
21
21
  const fieldPrivateContext = useNullableFieldPrivateContext();
22
22
  const handleFieldRef = useForkRef(internalProps.unstableFieldRef, skipContextFieldRefAssignment ? null : fieldPrivateContext?.fieldRef);
@@ -27,12 +27,11 @@ export function useFieldInternalPropsWithDefaults(parameters) {
27
27
  shouldClose: false
28
28
  });
29
29
  }, [setValue]);
30
- return React.useMemo(() => {
31
- let internalPropsWithDefaultsFromContext = internalProps;
30
+ const internalPropsWithDefaultsFromContext = React.useMemo(() => {
32
31
  // If one of the context is null,
33
32
  // Then the field is used as a standalone component and the other context will be null as well.
34
33
  if (fieldPrivateContext != null && pickerContext != null) {
35
- internalPropsWithDefaultsFromContext = _extends({
34
+ return _extends({
36
35
  value: pickerContext.value,
37
36
  onChange: handleChangeFromPicker,
38
37
  timezone: pickerContext.timezone,
@@ -48,8 +47,7 @@ export function useFieldInternalPropsWithDefaults(parameters) {
48
47
  unstableFieldRef: handleFieldRef
49
48
  }, internalProps);
50
49
  }
51
- return manager.internal_applyDefaultsToFieldInternalProps(_extends({}, localizationContext, {
52
- internalProps: internalPropsWithDefaultsFromContext
53
- }));
54
- }, [manager, localizationContext, pickerContext, fieldPrivateContext, internalProps, handleChangeFromPicker, handleFieldRef]);
50
+ return internalProps;
51
+ }, [pickerContext, fieldPrivateContext, internalProps, handleChangeFromPicker, handleFieldRef]);
52
+ return useApplyDefaultValuesToFieldInternalProps(internalPropsWithDefaultsFromContext);
55
53
  }
@@ -0,0 +1,16 @@
1
+ import { PickerManager } from "../../../models/index.js";
2
+ import { PickerValidValue } from "../../models/index.js";
3
+ import { UseFieldStateReturnValue } from "./useFieldState.js";
4
+ import { UseFieldInternalProps } from "./useField.types.js";
5
+ /**
6
+ * Returns the `onKeyDown` handler to pass to the root element of the field.
7
+ */
8
+ export declare function useFieldRootHandleKeyDown<TValue extends PickerValidValue>(parameters: UseFieldRootHandleKeyDownParameters<TValue>): (event: React.KeyboardEvent<HTMLSpanElement>) => void;
9
+ interface UseFieldRootHandleKeyDownParameters<TValue extends PickerValidValue> {
10
+ manager: PickerManager<TValue, any, any, any, any>;
11
+ stateResponse: UseFieldStateReturnValue<TValue>;
12
+ internalPropsWithDefaults: UseFieldInternalProps<TValue, any, any> & {
13
+ minutesStep?: number;
14
+ };
15
+ }
16
+ export {};
@@ -0,0 +1,205 @@
1
+ import useEventCallback from '@mui/utils/useEventCallback';
2
+ import { useUtils } from "../useUtils.js";
3
+ import { cleanDigitSectionValue, getLetterEditingOptions, removeLocalizedDigits } from "./useField.utils.js";
4
+
5
+ /**
6
+ * Returns the `onKeyDown` handler to pass to the root element of the field.
7
+ */
8
+ export function useFieldRootHandleKeyDown(parameters) {
9
+ const utils = useUtils();
10
+ const {
11
+ manager: {
12
+ internal_fieldValueManager: fieldValueManager
13
+ },
14
+ internalPropsWithDefaults: {
15
+ minutesStep,
16
+ disabled,
17
+ readOnly
18
+ },
19
+ stateResponse: {
20
+ // States and derived states
21
+ state,
22
+ value,
23
+ activeSectionIndex,
24
+ parsedSelectedSections,
25
+ sectionsValueBoundaries,
26
+ localizedDigits,
27
+ timezone,
28
+ sectionOrder,
29
+ // Methods to update the states
30
+ clearValue,
31
+ clearActiveSection,
32
+ setSelectedSections,
33
+ updateSectionValue
34
+ }
35
+ } = parameters;
36
+ return useEventCallback(event => {
37
+ if (disabled) {
38
+ return;
39
+ }
40
+
41
+ // eslint-disable-next-line default-case
42
+ switch (true) {
43
+ // Select all
44
+ case (event.ctrlKey || event.metaKey) && String.fromCharCode(event.keyCode) === 'A' && !event.shiftKey && !event.altKey:
45
+ {
46
+ // prevent default to make sure that the next line "select all" while updating
47
+ // the internal state at the same time.
48
+ event.preventDefault();
49
+ setSelectedSections('all');
50
+ break;
51
+ }
52
+
53
+ // Move selection to next section
54
+ case event.key === 'ArrowRight':
55
+ {
56
+ event.preventDefault();
57
+ if (parsedSelectedSections == null) {
58
+ setSelectedSections(sectionOrder.startIndex);
59
+ } else if (parsedSelectedSections === 'all') {
60
+ setSelectedSections(sectionOrder.endIndex);
61
+ } else {
62
+ const nextSectionIndex = sectionOrder.neighbors[parsedSelectedSections].rightIndex;
63
+ if (nextSectionIndex !== null) {
64
+ setSelectedSections(nextSectionIndex);
65
+ }
66
+ }
67
+ break;
68
+ }
69
+
70
+ // Move selection to previous section
71
+ case event.key === 'ArrowLeft':
72
+ {
73
+ event.preventDefault();
74
+ if (parsedSelectedSections == null) {
75
+ setSelectedSections(sectionOrder.endIndex);
76
+ } else if (parsedSelectedSections === 'all') {
77
+ setSelectedSections(sectionOrder.startIndex);
78
+ } else {
79
+ const nextSectionIndex = sectionOrder.neighbors[parsedSelectedSections].leftIndex;
80
+ if (nextSectionIndex !== null) {
81
+ setSelectedSections(nextSectionIndex);
82
+ }
83
+ }
84
+ break;
85
+ }
86
+
87
+ // Reset the value of the selected section
88
+ case event.key === 'Delete':
89
+ {
90
+ event.preventDefault();
91
+ if (readOnly) {
92
+ break;
93
+ }
94
+ if (parsedSelectedSections == null || parsedSelectedSections === 'all') {
95
+ clearValue();
96
+ } else {
97
+ clearActiveSection();
98
+ }
99
+ break;
100
+ }
101
+
102
+ // Increment / decrement the selected section value
103
+ case ['ArrowUp', 'ArrowDown', 'Home', 'End', 'PageUp', 'PageDown'].includes(event.key):
104
+ {
105
+ event.preventDefault();
106
+ if (readOnly || activeSectionIndex == null) {
107
+ break;
108
+ }
109
+
110
+ // if all sections are selected, mark the currently editing one as selected
111
+ if (parsedSelectedSections === 'all') {
112
+ setSelectedSections(activeSectionIndex);
113
+ }
114
+ const activeSection = state.sections[activeSectionIndex];
115
+ const newSectionValue = adjustSectionValue(utils, timezone, activeSection, event.key, sectionsValueBoundaries, localizedDigits, fieldValueManager.getDateFromSection(value, activeSection), {
116
+ minutesStep
117
+ });
118
+ updateSectionValue({
119
+ section: activeSection,
120
+ newSectionValue,
121
+ shouldGoToNextSection: false
122
+ });
123
+ break;
124
+ }
125
+ }
126
+ });
127
+ }
128
+ function getDeltaFromKeyCode(keyCode) {
129
+ switch (keyCode) {
130
+ case 'ArrowUp':
131
+ return 1;
132
+ case 'ArrowDown':
133
+ return -1;
134
+ case 'PageUp':
135
+ return 5;
136
+ case 'PageDown':
137
+ return -5;
138
+ default:
139
+ return 0;
140
+ }
141
+ }
142
+ function adjustSectionValue(utils, timezone, section, keyCode, sectionsValueBoundaries, localizedDigits, activeDate, stepsAttributes) {
143
+ const delta = getDeltaFromKeyCode(keyCode);
144
+ const isStart = keyCode === 'Home';
145
+ const isEnd = keyCode === 'End';
146
+ const shouldSetAbsolute = section.value === '' || isStart || isEnd;
147
+ const adjustDigitSection = () => {
148
+ const sectionBoundaries = sectionsValueBoundaries[section.type]({
149
+ currentDate: activeDate,
150
+ format: section.format,
151
+ contentType: section.contentType
152
+ });
153
+ const getCleanValue = value => cleanDigitSectionValue(utils, value, sectionBoundaries, localizedDigits, section);
154
+ const step = section.type === 'minutes' && stepsAttributes?.minutesStep ? stepsAttributes.minutesStep : 1;
155
+ let newSectionValueNumber;
156
+ if (shouldSetAbsolute) {
157
+ if (section.type === 'year' && !isEnd && !isStart) {
158
+ return utils.formatByString(utils.date(undefined, timezone), section.format);
159
+ }
160
+ if (delta > 0 || isStart) {
161
+ newSectionValueNumber = sectionBoundaries.minimum;
162
+ } else {
163
+ newSectionValueNumber = sectionBoundaries.maximum;
164
+ }
165
+ } else {
166
+ const currentSectionValue = parseInt(removeLocalizedDigits(section.value, localizedDigits), 10);
167
+ newSectionValueNumber = currentSectionValue + delta * step;
168
+ }
169
+ if (newSectionValueNumber % step !== 0) {
170
+ if (delta < 0 || isStart) {
171
+ newSectionValueNumber += step - (step + newSectionValueNumber) % step; // for JS -3 % 5 = -3 (should be 2)
172
+ }
173
+ if (delta > 0 || isEnd) {
174
+ newSectionValueNumber -= newSectionValueNumber % step;
175
+ }
176
+ }
177
+ if (newSectionValueNumber > sectionBoundaries.maximum) {
178
+ return getCleanValue(sectionBoundaries.minimum + (newSectionValueNumber - sectionBoundaries.maximum - 1) % (sectionBoundaries.maximum - sectionBoundaries.minimum + 1));
179
+ }
180
+ if (newSectionValueNumber < sectionBoundaries.minimum) {
181
+ return getCleanValue(sectionBoundaries.maximum - (sectionBoundaries.minimum - newSectionValueNumber - 1) % (sectionBoundaries.maximum - sectionBoundaries.minimum + 1));
182
+ }
183
+ return getCleanValue(newSectionValueNumber);
184
+ };
185
+ const adjustLetterSection = () => {
186
+ const options = getLetterEditingOptions(utils, timezone, section.type, section.format);
187
+ if (options.length === 0) {
188
+ return section.value;
189
+ }
190
+ if (shouldSetAbsolute) {
191
+ if (delta > 0 || isStart) {
192
+ return options[0];
193
+ }
194
+ return options[options.length - 1];
195
+ }
196
+ const currentOptionIndex = options.indexOf(section.value);
197
+ const newOptionIndex = (currentOptionIndex + delta) % options.length;
198
+ const clampedIndex = (newOptionIndex + options.length) % options.length;
199
+ return options[clampedIndex];
200
+ };
201
+ if (section.contentType === 'digit' || section.contentType === 'digit-with-letter') {
202
+ return adjustDigitSection();
203
+ }
204
+ return adjustLetterSection();
205
+ }
@@ -0,0 +1,32 @@
1
+ import { PickerManager } from "../../../models/index.js";
2
+ import { UseFieldDOMGetters, UseFieldInternalProps } from "./useField.types.js";
3
+ import { UseFieldStateReturnValue } from "./useFieldState.js";
4
+ import { UseFieldCharacterEditingReturnValue } from "./useFieldCharacterEditing.js";
5
+ /**
6
+ * Generate the props to pass to the root element of the field.
7
+ * It is not used by the non-accessible DOM structure (with an <input /> element for editing).
8
+ * It should be used in the MUI accessible DOM structure and the Base UI implementation.
9
+ * @param {UseFieldRootPropsParameters} parameters The parameters of the hook.
10
+ * @returns {UseFieldRootPropsReturnValue} The props to forward to the root element of the field.
11
+ */
12
+ export declare function useFieldRootProps(parameters: UseFieldRootPropsParameters): UseFieldRootPropsReturnValue;
13
+ interface UseFieldRootPropsParameters {
14
+ manager: PickerManager<any, any, any, any, any>;
15
+ stateResponse: UseFieldStateReturnValue<any>;
16
+ applyCharacterEditing: UseFieldCharacterEditingReturnValue;
17
+ internalPropsWithDefaults: UseFieldInternalProps<any, any, any>;
18
+ domGetters: UseFieldDOMGetters;
19
+ focused: boolean;
20
+ setFocused: (focused: boolean) => void;
21
+ }
22
+ interface UseFieldRootPropsReturnValue {
23
+ onKeyDown: React.KeyboardEventHandler<HTMLDivElement>;
24
+ onBlur: React.FocusEventHandler<HTMLDivElement>;
25
+ onFocus: React.FocusEventHandler<HTMLDivElement>;
26
+ onClick: React.MouseEventHandler<HTMLDivElement>;
27
+ onPaste: React.ClipboardEventHandler<HTMLDivElement>;
28
+ onInput: React.FormEventHandler<HTMLDivElement>;
29
+ contentEditable: boolean;
30
+ tabIndex: number;
31
+ }
32
+ export {};