@mui/x-date-pickers 6.0.2 → 6.0.4

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 (234) hide show
  1. package/AdapterDateFns/index.js +1 -0
  2. package/AdapterDateFnsJalali/index.js +69 -0
  3. package/AdapterDayjs/index.js +5 -0
  4. package/AdapterLuxon/index.js +13 -3
  5. package/AdapterMoment/index.js +5 -0
  6. package/AdapterMomentHijri/index.js +5 -0
  7. package/AdapterMomentJalaali/index.js +5 -0
  8. package/CHANGELOG.md +119 -5
  9. package/DateCalendar/DateCalendar.types.d.ts +1 -1
  10. package/DateCalendar/PickersCalendarHeader.d.ts +1 -1
  11. package/DateCalendar/index.d.ts +0 -1
  12. package/DateField/DateField.js +4 -0
  13. package/DateField/DateField.types.d.ts +2 -2
  14. package/DateField/useDateField.js +5 -3
  15. package/DatePicker/DatePickerToolbar.d.ts +1 -1
  16. package/DatePicker/shared.d.ts +2 -2
  17. package/DateTimeField/DateTimeField.js +4 -0
  18. package/DateTimeField/DateTimeField.types.d.ts +2 -2
  19. package/DateTimeField/useDateTimeField.js +5 -3
  20. package/DateTimePicker/DateTimePickerTabs.d.ts +1 -1
  21. package/DateTimePicker/DateTimePickerToolbar.d.ts +1 -1
  22. package/DateTimePicker/shared.d.ts +1 -2
  23. package/DesktopDatePicker/DesktopDatePicker.types.d.ts +1 -1
  24. package/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +1 -1
  25. package/DesktopTimePicker/DesktopTimePicker.types.d.ts +1 -1
  26. package/MobileDatePicker/MobileDatePicker.types.d.ts +1 -1
  27. package/MobileDateTimePicker/MobileDateTimePicker.types.d.ts +1 -1
  28. package/MobileTimePicker/MobileTimePicker.types.d.ts +1 -1
  29. package/PickersDay/PickersDay.js +4 -4
  30. package/PickersLayout/PickersLayout.d.ts +1 -1
  31. package/PickersLayout/PickersLayout.types.d.ts +1 -1
  32. package/PickersLayout/index.d.ts +1 -1
  33. package/PickersLayout/usePickerLayout.d.ts +1 -1
  34. package/README.md +1 -1
  35. package/StaticDatePicker/StaticDatePicker.types.d.ts +2 -1
  36. package/StaticDateTimePicker/StaticDateTimePicker.types.d.ts +2 -1
  37. package/StaticTimePicker/StaticTimePicker.types.d.ts +2 -1
  38. package/TimeClock/Clock.d.ts +1 -1
  39. package/TimeClock/ClockPointer.d.ts +1 -1
  40. package/TimeClock/TimeClock.types.d.ts +1 -1
  41. package/TimeClock/index.d.ts +0 -1
  42. package/TimeField/TimeField.js +4 -0
  43. package/TimeField/TimeField.types.d.ts +2 -2
  44. package/TimeField/useTimeField.js +5 -3
  45. package/TimePicker/TimePickerToolbar.d.ts +1 -1
  46. package/TimePicker/shared.d.ts +1 -2
  47. package/dateViewRenderers/dateViewRenderers.d.ts +1 -1
  48. package/index.d.ts +1 -6
  49. package/index.js +4 -2
  50. package/internals/components/PickersToolbar.d.ts +1 -1
  51. package/internals/demo/DemoContainer.js +15 -7
  52. package/internals/hooks/useDesktopPicker/useDesktopPicker.d.ts +1 -1
  53. package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +7 -7
  54. package/internals/hooks/useField/index.d.ts +2 -2
  55. package/internals/hooks/useField/index.js +1 -1
  56. package/internals/hooks/useField/useField.d.ts +3 -2
  57. package/internals/hooks/useField/useField.js +61 -30
  58. package/internals/hooks/useField/useField.types.d.ts +48 -116
  59. package/internals/hooks/useField/useField.utils.d.ts +7 -5
  60. package/internals/hooks/useField/useField.utils.js +68 -50
  61. package/internals/hooks/useField/useFieldCharacterEditing.d.ts +2 -1
  62. package/internals/hooks/useField/useFieldState.d.ts +4 -3
  63. package/internals/hooks/useField/useFieldState.js +86 -65
  64. package/internals/hooks/useIsLandscape.d.ts +1 -1
  65. package/internals/hooks/useMobilePicker/useMobilePicker.d.ts +1 -1
  66. package/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +7 -7
  67. package/internals/hooks/usePicker/usePicker.d.ts +2 -2
  68. package/internals/hooks/usePicker/usePicker.types.d.ts +4 -4
  69. package/internals/hooks/usePicker/usePickerLayoutProps.d.ts +1 -1
  70. package/internals/hooks/usePicker/usePickerValue.d.ts +9 -8
  71. package/internals/hooks/usePicker/usePickerValue.js +7 -11
  72. package/internals/hooks/usePicker/usePickerViews.d.ts +1 -1
  73. package/internals/hooks/useStaticPicker/useStaticPicker.d.ts +1 -1
  74. package/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +2 -2
  75. package/internals/hooks/useViews.d.ts +1 -1
  76. package/internals/hooks/useViews.js +8 -0
  77. package/internals/hooks/validation/models.d.ts +1 -1
  78. package/internals/hooks/validation/useDateTimeValidation.d.ts +3 -3
  79. package/internals/hooks/validation/useDateValidation.d.ts +2 -2
  80. package/internals/hooks/validation/useTimeValidation.d.ts +2 -2
  81. package/internals/index.d.ts +4 -8
  82. package/internals/index.js +2 -2
  83. package/internals/models/fields.d.ts +2 -20
  84. package/internals/models/index.d.ts +0 -1
  85. package/internals/models/index.js +0 -1
  86. package/internals/models/muiPickersAdapter.d.ts +1 -10
  87. package/internals/models/props/basePickerProps.d.ts +3 -3
  88. package/internals/models/props/tabs.d.ts +1 -1
  89. package/internals/models/props/toolbar.d.ts +1 -1
  90. package/internals/utils/date-utils.d.ts +1 -0
  91. package/internals/utils/date-utils.js +6 -0
  92. package/internals/utils/time-utils.d.ts +2 -1
  93. package/internals/utils/utils.d.ts +1 -1
  94. package/internals/utils/utils.js +3 -3
  95. package/internals/utils/validation.d.ts +1 -1
  96. package/internals/utils/valueManagers.d.ts +2 -4
  97. package/internals/utils/valueManagers.js +11 -12
  98. package/internals/utils/views.d.ts +1 -1
  99. package/legacy/AdapterDateFns/index.js +1 -0
  100. package/legacy/AdapterDateFnsJalali/index.js +69 -0
  101. package/legacy/AdapterDayjs/index.js +5 -0
  102. package/legacy/AdapterLuxon/index.js +13 -3
  103. package/legacy/AdapterMoment/index.js +5 -0
  104. package/legacy/AdapterMomentHijri/index.js +5 -0
  105. package/legacy/AdapterMomentJalaali/index.js +5 -0
  106. package/legacy/DateField/DateField.js +4 -0
  107. package/legacy/DateField/useDateField.js +4 -2
  108. package/legacy/DateTimeField/DateTimeField.js +4 -0
  109. package/legacy/DateTimeField/useDateTimeField.js +4 -2
  110. package/legacy/PickersDay/PickersDay.js +4 -4
  111. package/legacy/TimeField/TimeField.js +4 -0
  112. package/legacy/TimeField/useTimeField.js +4 -2
  113. package/legacy/index.js +4 -2
  114. package/legacy/internals/demo/DemoContainer.js +12 -6
  115. package/legacy/internals/hooks/useField/index.js +1 -1
  116. package/legacy/internals/hooks/useField/useField.js +86 -44
  117. package/legacy/internals/hooks/useField/useField.utils.js +76 -54
  118. package/legacy/internals/hooks/useField/useFieldState.js +92 -72
  119. package/legacy/internals/hooks/usePicker/usePickerValue.js +9 -13
  120. package/legacy/internals/hooks/useViews.js +10 -0
  121. package/legacy/internals/index.js +2 -2
  122. package/legacy/internals/models/index.js +0 -1
  123. package/legacy/internals/utils/date-utils.js +6 -0
  124. package/legacy/internals/utils/utils.js +3 -3
  125. package/legacy/internals/utils/valueManagers.js +12 -19
  126. package/legacy/locales/daDK.js +91 -0
  127. package/legacy/locales/faIR.js +33 -16
  128. package/legacy/locales/nbNO.js +12 -10
  129. package/legacy/locales/nlNL.js +12 -10
  130. package/legacy/locales/plPL.js +12 -10
  131. package/legacy/locales/svSE.js +12 -10
  132. package/legacy/models/index.js +3 -0
  133. package/legacy/tests/describeValue/testPickerOpenCloseLifeCycle.js +2 -3
  134. package/locales/daDK.d.ts +51 -0
  135. package/locales/daDK.js +59 -0
  136. package/locales/faIR.js +13 -16
  137. package/locales/nbNO.js +8 -10
  138. package/locales/nlNL.d.ts +4 -4
  139. package/locales/nlNL.js +8 -10
  140. package/locales/plPL.js +8 -10
  141. package/locales/svSE.js +8 -10
  142. package/locales/utils/pickersLocaleTextApi.d.ts +2 -1
  143. package/models/fields.d.ts +117 -0
  144. package/models/fields.js +1 -0
  145. package/models/index.d.ts +3 -0
  146. package/models/index.js +3 -0
  147. package/models/package.json +6 -0
  148. package/models/validation.d.ts +8 -0
  149. package/models/validation.js +1 -0
  150. package/models/views.js +1 -0
  151. package/modern/AdapterDateFns/index.js +1 -0
  152. package/modern/AdapterDateFnsJalali/index.js +69 -0
  153. package/modern/AdapterDayjs/index.js +5 -0
  154. package/modern/AdapterLuxon/index.js +13 -3
  155. package/modern/AdapterMoment/index.js +5 -0
  156. package/modern/AdapterMomentHijri/index.js +5 -0
  157. package/modern/AdapterMomentJalaali/index.js +5 -0
  158. package/modern/DateField/DateField.js +4 -0
  159. package/modern/DateField/useDateField.js +5 -3
  160. package/modern/DateTimeField/DateTimeField.js +4 -0
  161. package/modern/DateTimeField/useDateTimeField.js +5 -3
  162. package/modern/PickersDay/PickersDay.js +4 -4
  163. package/modern/TimeField/TimeField.js +4 -0
  164. package/modern/TimeField/useTimeField.js +5 -3
  165. package/modern/index.js +4 -2
  166. package/modern/internals/demo/DemoContainer.js +15 -7
  167. package/modern/internals/hooks/useField/index.js +1 -1
  168. package/modern/internals/hooks/useField/useField.js +59 -29
  169. package/modern/internals/hooks/useField/useField.utils.js +68 -50
  170. package/modern/internals/hooks/useField/useFieldState.js +86 -65
  171. package/modern/internals/hooks/usePicker/usePickerValue.js +7 -11
  172. package/modern/internals/hooks/useViews.js +8 -0
  173. package/modern/internals/index.js +2 -2
  174. package/modern/internals/models/index.js +0 -1
  175. package/modern/internals/utils/date-utils.js +6 -0
  176. package/modern/internals/utils/utils.js +3 -3
  177. package/modern/internals/utils/valueManagers.js +11 -12
  178. package/modern/locales/daDK.js +56 -0
  179. package/modern/locales/faIR.js +13 -16
  180. package/modern/locales/nbNO.js +8 -10
  181. package/modern/locales/nlNL.js +8 -10
  182. package/modern/locales/plPL.js +8 -10
  183. package/modern/locales/svSE.js +8 -10
  184. package/modern/models/fields.js +1 -0
  185. package/modern/models/index.js +3 -0
  186. package/modern/models/validation.js +1 -0
  187. package/modern/models/views.js +1 -0
  188. package/modern/tests/describeValue/testPickerOpenCloseLifeCycle.js +2 -3
  189. package/node/AdapterDateFns/index.js +1 -0
  190. package/node/AdapterDateFnsJalali/index.js +69 -0
  191. package/node/AdapterDayjs/index.js +5 -0
  192. package/node/AdapterLuxon/index.js +13 -3
  193. package/node/AdapterMoment/index.js +5 -0
  194. package/node/AdapterMomentHijri/index.js +5 -0
  195. package/node/AdapterMomentJalaali/index.js +5 -0
  196. package/node/DateField/DateField.js +4 -0
  197. package/node/DateField/useDateField.js +5 -3
  198. package/node/DateTimeField/DateTimeField.js +4 -0
  199. package/node/DateTimeField/useDateTimeField.js +5 -3
  200. package/node/PickersDay/PickersDay.js +4 -4
  201. package/node/TimeField/TimeField.js +4 -0
  202. package/node/TimeField/useTimeField.js +5 -3
  203. package/node/index.js +14 -2
  204. package/node/internals/demo/DemoContainer.js +15 -7
  205. package/node/internals/hooks/useField/index.js +0 -6
  206. package/node/internals/hooks/useField/useField.js +58 -28
  207. package/node/internals/hooks/useField/useField.utils.js +71 -52
  208. package/node/internals/hooks/useField/useFieldState.js +85 -64
  209. package/node/internals/hooks/usePicker/usePickerValue.js +7 -11
  210. package/node/internals/hooks/useViews.js +8 -0
  211. package/node/internals/index.js +6 -12
  212. package/node/internals/models/index.js +0 -11
  213. package/node/internals/utils/date-utils.js +9 -2
  214. package/node/internals/utils/utils.js +3 -3
  215. package/node/internals/utils/valueManagers.js +9 -10
  216. package/node/locales/daDK.js +62 -0
  217. package/node/locales/faIR.js +13 -16
  218. package/node/locales/nbNO.js +8 -10
  219. package/node/locales/nlNL.js +8 -10
  220. package/node/locales/plPL.js +8 -10
  221. package/node/locales/svSE.js +8 -10
  222. package/node/models/index.js +38 -0
  223. package/node/models/validation.js +5 -0
  224. package/node/models/views.js +5 -0
  225. package/node/tests/describeValue/testPickerOpenCloseLifeCycle.js +2 -3
  226. package/package.json +2 -2
  227. package/tests/describeValue/testPickerOpenCloseLifeCycle.js +2 -3
  228. package/themeAugmentation/props.d.ts +1 -1
  229. package/timeViewRenderers/timeViewRenderers.d.ts +1 -1
  230. /package/{internals/models/views.js → legacy/models/fields.js} +0 -0
  231. /package/legacy/{internals/models/views.js → models/validation.js} +0 -0
  232. /package/{modern/internals → legacy}/models/views.js +0 -0
  233. /package/{internals/models → models}/views.d.ts +0 -0
  234. /package/node/{internals/models/views.js → models/fields.js} +0 -0
@@ -1,6 +1,6 @@
1
1
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
- var _excluded = ["value", "defaultValue", "format", "onChange", "readOnly", "onError", "disableFuture", "disablePast", "minTime", "maxTime", "minutesStep", "shouldDisableClock", "shouldDisableTime", "disableIgnoringDatePartForTimeValidation", "selectedSections", "onSelectedSectionsChange", "ampm"];
3
+ var _excluded = ["value", "defaultValue", "format", "onChange", "readOnly", "onError", "disableFuture", "disablePast", "minTime", "maxTime", "minutesStep", "shouldDisableClock", "shouldDisableTime", "disableIgnoringDatePartForTimeValidation", "selectedSections", "onSelectedSectionsChange", "ampm", "unstableFieldRef"];
4
4
  import { singleItemFieldValueManager, singleItemValueManager } from '../internals/utils/valueManagers';
5
5
  import { useField } from '../internals/hooks/useField';
6
6
  import { validateTime } from '../internals/hooks/validation/useTimeValidation';
@@ -37,6 +37,7 @@ export var useTimeField = function useTimeField(_ref) {
37
37
  selectedSections = _useDefaultizedTimeFi.selectedSections,
38
38
  onSelectedSectionsChange = _useDefaultizedTimeFi.onSelectedSectionsChange,
39
39
  ampm = _useDefaultizedTimeFi.ampm,
40
+ unstableFieldRef = _useDefaultizedTimeFi.unstableFieldRef,
40
41
  other = _objectWithoutProperties(_useDefaultizedTimeFi, _excluded);
41
42
  return useField({
42
43
  inputRef: inputRef,
@@ -58,7 +59,8 @@ export var useTimeField = function useTimeField(_ref) {
58
59
  disableIgnoringDatePartForTimeValidation: disableIgnoringDatePartForTimeValidation,
59
60
  selectedSections: selectedSections,
60
61
  onSelectedSectionsChange: onSelectedSectionsChange,
61
- ampm: ampm
62
+ ampm: ampm,
63
+ unstableFieldRef: unstableFieldRef
62
64
  },
63
65
  valueManager: singleItemValueManager,
64
66
  fieldValueManager: singleItemFieldValueManager,
package/legacy/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-date-pickers v6.0.2
2
+ * @mui/x-date-pickers v6.0.4
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -14,6 +14,7 @@ export * from './locales';
14
14
  export * from './DateField';
15
15
  export * from './TimeField';
16
16
  export * from './DateTimeField';
17
+
17
18
  // Calendars
18
19
  export * from './DateCalendar';
19
20
  export * from './MonthCalendar';
@@ -42,4 +43,5 @@ export * from './timeViewRenderers';
42
43
  export * from './PickersLayout';
43
44
  export * from './PickersActionBar';
44
45
  export * from './PickersShortcuts';
45
- export { DEFAULT_DESKTOP_MODE_MEDIA_QUERY } from './internals/utils/utils';
46
+ export { DEFAULT_DESKTOP_MODE_MEDIA_QUERY } from './internals/utils/utils';
47
+ export * from './models';
@@ -95,12 +95,18 @@ export function DemoContainer(props) {
95
95
  if (childrenTypes.has('UI-view')) {
96
96
  // noop
97
97
  } else if (childrenTypes.has('single-input-range-field')) {
98
- sx = _extends({}, sx, _defineProperty({}, "& > .".concat(textFieldClasses.root), {
99
- minWidth: {
100
- xs: 300,
101
- md: 400
102
- }
103
- }));
98
+ if (!childrenSupportedSections.has('date-time')) {
99
+ sx = _extends({}, sx, _defineProperty({}, "& > .".concat(textFieldClasses.root), {
100
+ minWidth: 300
101
+ }));
102
+ } else {
103
+ sx = _extends({}, sx, _defineProperty({}, "& > .".concat(textFieldClasses.root), {
104
+ minWidth: {
105
+ xs: 300,
106
+ md: 400
107
+ }
108
+ }));
109
+ }
104
110
  } else if (childrenSupportedSections.has('date-time')) {
105
111
  sx = _extends({}, sx, _defineProperty({}, "& > .".concat(textFieldClasses.root), {
106
112
  minWidth: 270
@@ -1,2 +1,2 @@
1
1
  export { useField } from './useField';
2
- export { splitFormatIntoSections, addPositionPropertiesToSections, createDateStrForInputFromSections, getSectionOrder } from './useField.utils';
2
+ export { splitFormatIntoSections, addPositionPropertiesToSections, createDateStrForInputFromSections } from './useField.utils';
@@ -6,9 +6,10 @@ import * as React from 'react';
6
6
  import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
7
7
  import useEventCallback from '@mui/utils/useEventCallback';
8
8
  import useForkRef from '@mui/utils/useForkRef';
9
+ import { useTheme } from '@mui/material/styles';
9
10
  import { useValidation } from '../validation/useValidation';
10
11
  import { useUtils } from '../useUtils';
11
- import { adjustSectionValue, isAndroid, cleanString } from './useField.utils';
12
+ import { adjustSectionValue, isAndroid, cleanString, getSectionOrder } from './useField.utils';
12
13
  import { useFieldState } from './useFieldState';
13
14
  import { useFieldCharacterEditing } from './useFieldCharacterEditing';
14
15
  import { getActiveElement } from '../../utils/utils';
@@ -17,14 +18,14 @@ export var useField = function useField(params) {
17
18
  var _useFieldState = useFieldState(params),
18
19
  state = _useFieldState.state,
19
20
  selectedSectionIndexes = _useFieldState.selectedSectionIndexes,
20
- setSelectedSections = _useFieldState.setSelectedSections,
21
+ _setSelectedSections = _useFieldState.setSelectedSections,
21
22
  clearValue = _useFieldState.clearValue,
22
23
  clearActiveSection = _useFieldState.clearActiveSection,
23
24
  updateSectionValue = _useFieldState.updateSectionValue,
24
25
  updateValueFromValueStr = _useFieldState.updateValueFromValueStr,
25
26
  setTempAndroidValueStr = _useFieldState.setTempAndroidValueStr,
26
- sectionOrder = _useFieldState.sectionOrder,
27
- sectionsValueBoundaries = _useFieldState.sectionsValueBoundaries;
27
+ sectionsValueBoundaries = _useFieldState.sectionsValueBoundaries,
28
+ placeholder = _useFieldState.placeholder;
28
29
  var _useFieldCharacterEdi = useFieldCharacterEditing({
29
30
  sections: state.sections,
30
31
  updateSectionValue: updateSectionValue,
@@ -35,8 +36,10 @@ export var useField = function useField(params) {
35
36
  resetCharacterQuery = _useFieldCharacterEdi.resetCharacterQuery;
36
37
  var inputRefProp = params.inputRef,
37
38
  internalProps = params.internalProps,
38
- _params$internalProps = params.internalProps.readOnly,
39
- readOnly = _params$internalProps === void 0 ? false : _params$internalProps,
39
+ _params$internalProps = params.internalProps,
40
+ _params$internalProps2 = _params$internalProps.readOnly,
41
+ readOnly = _params$internalProps2 === void 0 ? false : _params$internalProps2,
42
+ unstableFieldRef = _params$internalProps.unstableFieldRef,
40
43
  _params$forwardedProp = params.forwardedProps,
41
44
  onClick = _params$forwardedProp.onClick,
42
45
  onKeyDown = _params$forwardedProp.onKeyDown,
@@ -52,10 +55,15 @@ export var useField = function useField(params) {
52
55
  var inputRef = React.useRef(null);
53
56
  var handleRef = useForkRef(inputRefProp, inputRef);
54
57
  var focusTimeoutRef = React.useRef(undefined);
58
+ var theme = useTheme();
59
+ var isRTL = theme.direction === 'rtl';
60
+ var sectionOrder = React.useMemo(function () {
61
+ return getSectionOrder(state.sections, isRTL);
62
+ }, [state.sections, isRTL]);
55
63
  var syncSelectionFromDOM = function syncSelectionFromDOM() {
56
64
  var _selectionStart;
57
65
  if (readOnly) {
58
- setSelectedSections(null);
66
+ _setSelectedSections(null);
59
67
  return;
60
68
  }
61
69
  var browserStartIndex = (_selectionStart = inputRef.current.selectionStart) != null ? _selectionStart : 0;
@@ -64,7 +72,7 @@ export var useField = function useField(params) {
64
72
  return section.startInInput - section.startSeparator.length > browserStartIndex;
65
73
  });
66
74
  var sectionIndex = nextSectionIndex === -1 ? state.sections.length - 1 : nextSectionIndex - 1;
67
- setSelectedSections(sectionIndex);
75
+ _setSelectedSections(sectionIndex);
68
76
  };
69
77
  var handleInputClick = useEventCallback(function () {
70
78
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
@@ -98,7 +106,7 @@ export var useField = function useField(params) {
98
106
  if (
99
107
  // avoid selecting all sections when focusing empty field without value
100
108
  input.value.length && Number(input.selectionEnd) - Number(input.selectionStart) === input.value.length) {
101
- setSelectedSections('all');
109
+ _setSelectedSections('all');
102
110
  } else {
103
111
  syncSelectionFromDOM();
104
112
  }
@@ -109,7 +117,7 @@ export var useField = function useField(params) {
109
117
  args[_key3] = arguments[_key3];
110
118
  }
111
119
  onBlur == null ? void 0 : onBlur.apply(void 0, _toConsumableArray(args));
112
- setSelectedSections(null);
120
+ _setSelectedSections(null);
113
121
  });
114
122
  var handleInputPaste = useEventCallback(function (event) {
115
123
  onPaste == null ? void 0 : onPaste(event);
@@ -150,27 +158,32 @@ export var useField = function useField(params) {
150
158
  updateValueFromValueStr(cleanValueStr);
151
159
  return;
152
160
  }
153
- var prevValueStr = cleanString(fieldValueManager.getValueStrFromSections(state.sections));
154
- var startOfDiffIndex = -1;
155
- var endOfDiffIndex = -1;
156
- for (var i = 0; i < prevValueStr.length; i += 1) {
157
- if (startOfDiffIndex === -1 && prevValueStr[i] !== cleanValueStr[i]) {
158
- startOfDiffIndex = i;
161
+ var keyPressed;
162
+ if (selectedSectionIndexes.startIndex === 0 && selectedSectionIndexes.endIndex === state.sections.length - 1) {
163
+ keyPressed = cleanValueStr;
164
+ } else {
165
+ var prevValueStr = cleanString(fieldValueManager.getValueStrFromSections(state.sections, isRTL));
166
+ var startOfDiffIndex = -1;
167
+ var endOfDiffIndex = -1;
168
+ for (var i = 0; i < prevValueStr.length; i += 1) {
169
+ if (startOfDiffIndex === -1 && prevValueStr[i] !== cleanValueStr[i]) {
170
+ startOfDiffIndex = i;
171
+ }
172
+ if (endOfDiffIndex === -1 && prevValueStr[prevValueStr.length - i - 1] !== cleanValueStr[cleanValueStr.length - i - 1]) {
173
+ endOfDiffIndex = i;
174
+ }
159
175
  }
160
- if (endOfDiffIndex === -1 && prevValueStr[prevValueStr.length - i - 1] !== cleanValueStr[cleanValueStr.length - i - 1]) {
161
- endOfDiffIndex = i;
176
+ var activeSection = state.sections[selectedSectionIndexes.startIndex];
177
+ var hasDiffOutsideOfActiveSection = startOfDiffIndex < activeSection.start || prevValueStr.length - endOfDiffIndex - 1 > activeSection.end;
178
+ if (hasDiffOutsideOfActiveSection) {
179
+ // TODO: Support if the new date is valid
180
+ return;
162
181
  }
163
- }
164
- var activeSection = state.sections[selectedSectionIndexes.startIndex];
165
- var hasDiffOutsideOfActiveSection = startOfDiffIndex < activeSection.start || prevValueStr.length - endOfDiffIndex - 1 > activeSection.end;
166
- if (hasDiffOutsideOfActiveSection) {
167
- // TODO: Support if the new date is valid
168
- return;
169
- }
170
182
 
171
- // The active section being selected, the browser has replaced its value with the key pressed by the user.
172
- var activeSectionEndRelativeToNewValue = cleanValueStr.length - prevValueStr.length + activeSection.end - cleanString(activeSection.endSeparator || '').length;
173
- var keyPressed = cleanValueStr.slice(activeSection.start, activeSectionEndRelativeToNewValue);
183
+ // The active section being selected, the browser has replaced its value with the key pressed by the user.
184
+ var activeSectionEndRelativeToNewValue = cleanValueStr.length - prevValueStr.length + activeSection.end - cleanString(activeSection.endSeparator || '').length;
185
+ keyPressed = cleanValueStr.slice(activeSection.start, activeSectionEndRelativeToNewValue);
186
+ }
174
187
  if (isAndroid() && keyPressed.length === 0) {
175
188
  setTempAndroidValueStr(valueStr);
176
189
  return;
@@ -191,7 +204,7 @@ export var useField = function useField(params) {
191
204
  // prevent default to make sure that the next line "select all" while updating
192
205
  // the internal state at the same time.
193
206
  event.preventDefault();
194
- setSelectedSections('all');
207
+ _setSelectedSections('all');
195
208
  break;
196
209
  }
197
210
 
@@ -200,13 +213,13 @@ export var useField = function useField(params) {
200
213
  {
201
214
  event.preventDefault();
202
215
  if (selectedSectionIndexes == null) {
203
- setSelectedSections(sectionOrder.startIndex);
216
+ _setSelectedSections(sectionOrder.startIndex);
204
217
  } else if (selectedSectionIndexes.startIndex !== selectedSectionIndexes.endIndex) {
205
- setSelectedSections(selectedSectionIndexes.endIndex);
218
+ _setSelectedSections(selectedSectionIndexes.endIndex);
206
219
  } else {
207
220
  var nextSectionIndex = sectionOrder.neighbors[selectedSectionIndexes.startIndex].rightIndex;
208
221
  if (nextSectionIndex !== null) {
209
- setSelectedSections(nextSectionIndex);
222
+ _setSelectedSections(nextSectionIndex);
210
223
  }
211
224
  }
212
225
  break;
@@ -217,13 +230,13 @@ export var useField = function useField(params) {
217
230
  {
218
231
  event.preventDefault();
219
232
  if (selectedSectionIndexes == null) {
220
- setSelectedSections(sectionOrder.endIndex);
233
+ _setSelectedSections(sectionOrder.endIndex);
221
234
  } else if (selectedSectionIndexes.startIndex !== selectedSectionIndexes.endIndex) {
222
- setSelectedSections(selectedSectionIndexes.startIndex);
235
+ _setSelectedSections(selectedSectionIndexes.startIndex);
223
236
  } else {
224
237
  var _nextSectionIndex = sectionOrder.neighbors[selectedSectionIndexes.startIndex].leftIndex;
225
238
  if (_nextSectionIndex !== null) {
226
- setSelectedSections(_nextSectionIndex);
239
+ _setSelectedSections(_nextSectionIndex);
227
240
  }
228
241
  }
229
242
  break;
@@ -254,7 +267,7 @@ export var useField = function useField(params) {
254
267
  }
255
268
  var activeSection = state.sections[selectedSectionIndexes.startIndex];
256
269
  var activeDateManager = fieldValueManager.getActiveDateManager(utils, state, activeSection);
257
- var newSectionValue = adjustSectionValue(utils, activeSection, event.key, sectionsValueBoundaries, activeDateManager.activeDate);
270
+ var newSectionValue = adjustSectionValue(utils, activeSection, event.key, sectionsValueBoundaries, activeDateManager.date);
258
271
  updateSectionValue({
259
272
  activeSection: activeSection,
260
273
  newSectionValue: newSectionValue,
@@ -266,9 +279,11 @@ export var useField = function useField(params) {
266
279
  });
267
280
  useEnhancedEffect(function () {
268
281
  if (selectedSectionIndexes == null) {
269
- if (inputRef.current.selectionStart !== 0 || inputRef.current.selectionEnd !== 0) {
270
- // Ensure input selection range is in sync with component selection indexes
271
- inputRef.current.setSelectionRange(0, 0);
282
+ if (inputRef.current.scrollLeft) {
283
+ // Ensure that input content is not marked as selected.
284
+ // setting selection range to 0 causes issues in Safari.
285
+ // https://bugs.webkit.org/show_bug.cgi?id=224425
286
+ inputRef.current.scrollLeft = 0;
272
287
  }
273
288
  return;
274
289
  }
@@ -281,7 +296,11 @@ export var useField = function useField(params) {
281
296
  selectionEnd += lastSelectedSection.endSeparator.length;
282
297
  }
283
298
  if (selectionStart !== inputRef.current.selectionStart || selectionEnd !== inputRef.current.selectionEnd) {
299
+ // Fix scroll jumping on iOS browser: https://github.com/mui/mui-x/issues/8321
300
+ var currentScrollTop = inputRef.current.scrollTop;
284
301
  inputRef.current.setSelectionRange(selectionStart, selectionEnd);
302
+ // Even reading this variable seems to do the trick, but also setting it just to make use of it
303
+ inputRef.current.scrollTop = currentScrollTop;
285
304
  }
286
305
  });
287
306
  var validationError = useValidation(_extends({}, internalProps, {
@@ -298,7 +317,7 @@ export var useField = function useField(params) {
298
317
  React.useEffect(function () {
299
318
  // Select the right section when focused on mount (`autoFocus = true` on the input)
300
319
  if (inputRef.current && inputRef.current === document.activeElement) {
301
- setSelectedSections('all');
320
+ _setSelectedSections('all');
302
321
  }
303
322
  return function () {
304
323
  return window.clearTimeout(focusTimeoutRef.current);
@@ -318,8 +337,8 @@ export var useField = function useField(params) {
318
337
 
319
338
  var valueStr = React.useMemo(function () {
320
339
  var _state$tempValueStrAn;
321
- return (_state$tempValueStrAn = state.tempValueStrAndroid) != null ? _state$tempValueStrAn : fieldValueManager.getValueStrFromSections(state.sections);
322
- }, [state.sections, fieldValueManager, state.tempValueStrAndroid]);
340
+ return (_state$tempValueStrAn = state.tempValueStrAndroid) != null ? _state$tempValueStrAn : fieldValueManager.getValueStrFromSections(state.sections, isRTL);
341
+ }, [state.sections, fieldValueManager, state.tempValueStrAndroid, isRTL]);
323
342
  var inputMode = React.useMemo(function () {
324
343
  if (selectedSectionIndexes == null) {
325
344
  return 'text';
@@ -330,9 +349,32 @@ export var useField = function useField(params) {
330
349
  return 'tel';
331
350
  }, [selectedSectionIndexes, state.sections]);
332
351
  var inputHasFocus = inputRef.current && inputRef.current === getActiveElement(document);
333
- var shouldShowPlaceholder = !inputHasFocus && (!state.value || valueManager.areValuesEqual(utils, state.value, valueManager.emptyValue));
352
+ var shouldShowPlaceholder = !inputHasFocus && valueManager.areValuesEqual(utils, state.value, valueManager.emptyValue);
353
+ React.useImperativeHandle(unstableFieldRef, function () {
354
+ return {
355
+ getSections: function getSections() {
356
+ return state.sections;
357
+ },
358
+ getActiveSectionIndex: function getActiveSectionIndex() {
359
+ var _selectionStart2, _selectionEnd;
360
+ var browserStartIndex = (_selectionStart2 = inputRef.current.selectionStart) != null ? _selectionStart2 : 0;
361
+ var browserEndIndex = (_selectionEnd = inputRef.current.selectionEnd) != null ? _selectionEnd : 0;
362
+ if (browserStartIndex === 0 && browserEndIndex === 0) {
363
+ return null;
364
+ }
365
+ var nextSectionIndex = browserStartIndex <= state.sections[0].startInInput ? 1 // Special case if browser index is in invisible characters at the beginning.
366
+ : state.sections.findIndex(function (section) {
367
+ return section.startInInput - section.startSeparator.length > browserStartIndex;
368
+ });
369
+ return nextSectionIndex === -1 ? state.sections.length - 1 : nextSectionIndex - 1;
370
+ },
371
+ setSelectedSections: function setSelectedSections(activeSectionIndex) {
372
+ return _setSelectedSections(activeSectionIndex);
373
+ }
374
+ };
375
+ });
334
376
  return _extends({
335
- placeholder: state.placeholder,
377
+ placeholder: placeholder,
336
378
  autoComplete: 'off'
337
379
  }, otherForwardedProps, {
338
380
  value: shouldShowPlaceholder ? '' : valueStr,
@@ -155,7 +155,7 @@ export var adjustSectionValue = function adjustSectionValue(utils, section, keyC
155
155
  }
156
156
  return adjustLetterSection();
157
157
  };
158
- var getSectionVisibleValue = function getSectionVisibleValue(section, willBeRenderedInInput) {
158
+ export var getSectionVisibleValue = function getSectionVisibleValue(section, target) {
159
159
  var value = section.value || section.placeholder;
160
160
 
161
161
  // In the input, we add an empty character at the end of each section without leading zeros.
@@ -163,26 +163,25 @@ var getSectionVisibleValue = function getSectionVisibleValue(section, willBeRend
163
163
  // Otherwise, when your input value equals `1/dd/yyyy` (format `M/DD/YYYY` on DayJs),
164
164
  // If you press `1`, on the first section, the new value is also `1/dd/yyyy`,
165
165
  // So the browser will not fire the input `onChange`.
166
- // Adding the ltr mark is not a problem because it's only for digit (which are always ltr)
167
- // The \u2068 and \u2069 are cleaned, but not the \u200e to notice that an update with same digit occurs
168
- if (willBeRenderedInInput && section.contentType === 'digit' && !section.hasLeadingZeros && value.length === 1) {
169
- return "\u2068".concat(value, "\u200E\u2069");
166
+ var shouldAddInvisibleSpace = ['input-rtl', 'input-ltr'].includes(target) && section.contentType === 'digit' && !section.hasLeadingZeros && value.length === 1;
167
+ if (shouldAddInvisibleSpace) {
168
+ value = "".concat(value, "\u200E");
170
169
  }
171
- if (willBeRenderedInInput) {
172
- return "\u2068".concat(value, "\u2069");
170
+ if (target === 'input-rtl') {
171
+ value = "\u2068".concat(value, "\u2069");
173
172
  }
174
173
  return value;
175
174
  };
176
175
  export var cleanString = function cleanString(dirtyString) {
177
176
  return dirtyString.replace(/[\u2066\u2067\u2068\u2069]/g, '');
178
177
  };
179
- export var addPositionPropertiesToSections = function addPositionPropertiesToSections(sections) {
178
+ export var addPositionPropertiesToSections = function addPositionPropertiesToSections(sections, isRTL) {
180
179
  var position = 0;
181
- var positionInInput = 1;
180
+ var positionInInput = isRTL ? 1 : 0;
182
181
  var newSections = [];
183
182
  for (var i = 0; i < sections.length; i += 1) {
184
183
  var section = sections[i];
185
- var renderedValue = getSectionVisibleValue(section, true);
184
+ var renderedValue = getSectionVisibleValue(section, isRTL ? 'input-rtl' : 'input-ltr');
186
185
  var sectionStr = "".concat(section.startSeparator).concat(renderedValue).concat(section.endSeparator);
187
186
  var sectionLength = cleanString(sectionStr).length;
188
187
  var sectionLengthInInput = sectionStr.length;
@@ -328,10 +327,6 @@ export var splitFormatIntoSections = function splitFormatIntoSections(utils, loc
328
327
  if (token === '') {
329
328
  return null;
330
329
  }
331
- var expandedToken = utils.expandFormat(token);
332
- if (expandedToken !== token) {
333
- return expandedToken;
334
- }
335
330
  var sectionConfig = getDateSectionConfigFromFormatToken(utils, token);
336
331
  var sectionValue = date == null || !utils.isValid(date) ? '' : utils.formatByString(date, token);
337
332
  var hasLeadingZeros = doesSectionHaveLeadingZeros(utils, sectionConfig.contentType, sectionConfig.type, token);
@@ -346,44 +341,55 @@ export var splitFormatIntoSections = function splitFormatIntoSections(utils, loc
346
341
  }));
347
342
  return null;
348
343
  };
349
- var splitFormat = function splitFormat(token) {
350
- var escapedParts = getEscapedPartsFromFormat(utils, token);
351
- var currentTokenValue = '';
352
- var _loop = function _loop(i) {
353
- var escapedPartOfCurrentChar = escapedParts.find(function (escapeIndex) {
354
- return escapeIndex.start <= i && escapeIndex.end >= i;
355
- });
356
- var char = token[i];
357
- var isEscapedChar = escapedPartOfCurrentChar != null;
358
- if (!isEscapedChar && char.match(/([A-Za-z]+)/)) {
359
- currentTokenValue += char;
360
- } else {
361
- // If we are on the opening or closing character of an escaped part of the format,
362
- // Then we ignore this character.
363
- var isEscapeBoundary = isEscapedChar && (escapedPartOfCurrentChar == null ? void 0 : escapedPartOfCurrentChar.start) === i || (escapedPartOfCurrentChar == null ? void 0 : escapedPartOfCurrentChar.end) === i;
364
- if (!isEscapeBoundary) {
365
- var _expandedToken = commitToken(currentTokenValue);
366
- if (_expandedToken != null) {
367
- splitFormat(_expandedToken);
368
- }
369
- currentTokenValue = '';
370
- if (sections.length === 0) {
371
- startSeparator += char;
372
- } else {
373
- sections[sections.length - 1].endSeparator += char;
374
- }
344
+
345
+ // Expand the provided format
346
+ var formatExpansionOverflow = 10;
347
+ var prevFormat = format;
348
+ var nextFormat = utils.expandFormat(format);
349
+ while (nextFormat !== prevFormat) {
350
+ prevFormat = nextFormat;
351
+ nextFormat = utils.expandFormat(prevFormat);
352
+ formatExpansionOverflow -= 1;
353
+ if (formatExpansionOverflow < 0) {
354
+ throw new Error('MUI: The format expansion seems to be enter in an infinite loop. Please open an issue with the format passed to the picker component');
355
+ }
356
+ }
357
+ var expandedFormat = nextFormat;
358
+
359
+ // Get start/end indexes of escaped sections
360
+ var escapedParts = getEscapedPartsFromFormat(utils, expandedFormat);
361
+
362
+ // This RegExp test if the beginning of a string correspond to a supported token
363
+ var isTokenStartRegExp = new RegExp("^(".concat(Object.keys(utils.formatTokenMap).join('|'), ")"));
364
+ var currentTokenValue = '';
365
+ var _loop = function _loop(i) {
366
+ var escapedPartOfCurrentChar = escapedParts.find(function (escapeIndex) {
367
+ return escapeIndex.start <= i && escapeIndex.end >= i;
368
+ });
369
+ var char = expandedFormat[i];
370
+ var isEscapedChar = escapedPartOfCurrentChar != null;
371
+ var potentialToken = "".concat(currentTokenValue).concat(expandedFormat.slice(i));
372
+ if (!isEscapedChar && char.match(/([A-Za-z]+)/) && isTokenStartRegExp.test(potentialToken)) {
373
+ currentTokenValue += char;
374
+ } else {
375
+ // If we are on the opening or closing character of an escaped part of the format,
376
+ // Then we ignore this character.
377
+ var isEscapeBoundary = isEscapedChar && (escapedPartOfCurrentChar == null ? void 0 : escapedPartOfCurrentChar.start) === i || (escapedPartOfCurrentChar == null ? void 0 : escapedPartOfCurrentChar.end) === i;
378
+ if (!isEscapeBoundary) {
379
+ commitToken(currentTokenValue);
380
+ currentTokenValue = '';
381
+ if (sections.length === 0) {
382
+ startSeparator += char;
383
+ } else {
384
+ sections[sections.length - 1].endSeparator += char;
375
385
  }
376
386
  }
377
- };
378
- for (var i = 0; i < token.length; i += 1) {
379
- _loop(i);
380
- }
381
- var expandedToken = commitToken(currentTokenValue);
382
- if (expandedToken != null) {
383
- splitFormat(expandedToken);
384
387
  }
385
388
  };
386
- splitFormat(format);
389
+ for (var i = 0; i < expandedFormat.length; i += 1) {
390
+ _loop(i);
391
+ }
392
+ commitToken(currentTokenValue);
387
393
  return sections.map(function (section) {
388
394
  var cleanSeparator = function cleanSeparator(separator) {
389
395
  var cleanedSeparator = separator;
@@ -419,24 +425,28 @@ export var getDateFromDateSections = function getDateFromDateSections(utils, sec
419
425
  var shouldSkip = shouldSkipWeekDays && section.type === 'weekDay';
420
426
  if (!shouldSkip) {
421
427
  sectionFormats.push(section.format);
422
- sectionValues.push(getSectionVisibleValue(section, false));
428
+ sectionValues.push(getSectionVisibleValue(section, 'non-input'));
423
429
  }
424
430
  }
425
431
  var formatWithoutSeparator = sectionFormats.join(' ');
426
432
  var dateWithoutSeparatorStr = sectionValues.join(' ');
427
433
  return utils.parse(dateWithoutSeparatorStr, formatWithoutSeparator);
428
434
  };
429
- export var createDateStrForInputFromSections = function createDateStrForInputFromSections(sections) {
430
- var formattedArray = sections.map(function (section) {
431
- return "".concat(section.startSeparator).concat(getSectionVisibleValue(section, true)).concat(section.endSeparator);
435
+ export var createDateStrForInputFromSections = function createDateStrForInputFromSections(sections, isRTL) {
436
+ var formattedSections = sections.map(function (section) {
437
+ return "".concat(section.startSeparator).concat(getSectionVisibleValue(section, isRTL ? 'input-rtl' : 'input-ltr')).concat(section.endSeparator);
432
438
  });
439
+ var dateStr = formattedSections.join('');
440
+ if (!isRTL) {
441
+ return dateStr;
442
+ }
433
443
 
434
444
  // \u2066: start left-to-right isolation
435
445
  // \u2067: start right-to-left isolation
436
446
  // \u2068: start first strong character isolation
437
447
  // \u2069: pop isolation
438
448
  // wrap into an isolated group such that separators can split the string in smaller ones by adding \u2069\u2068
439
- return "\u2066".concat(formattedArray.join(''), "\u2069");
449
+ return "\u2066".concat(dateStr, "\u2069");
440
450
  };
441
451
  export var getSectionsBoundaries = function getSectionsBoundaries(utils) {
442
452
  var today = utils.date();
@@ -616,7 +626,19 @@ export var mergeDateIntoReferenceDate = function mergeDateIntoReferenceDate(util
616
626
  export var isAndroid = function isAndroid() {
617
627
  return navigator.userAgent.toLowerCase().indexOf('android') > -1;
618
628
  };
619
- export var clampDaySection = function clampDaySection(utils, sections, sectionsValueBoundaries) {
629
+ export var clampDaySectionIfPossible = function clampDaySectionIfPossible(utils, sections, sectionsValueBoundaries) {
630
+ // We can only clamp the day value if:
631
+ // 1. if all the sections are filled (except the week day section which can be empty)
632
+ // 2. there is a day section
633
+ var canClamp = sections.every(function (section) {
634
+ return section.type === 'weekDay' || section.value !== '';
635
+ }) && sections.some(function (section) {
636
+ return section.type === 'day';
637
+ });
638
+ if (!canClamp) {
639
+ return null;
640
+ }
641
+
620
642
  // We try to generate a valid date representing the start of the month of the invalid date typed by the user.
621
643
  var sectionsForStartOfMonth = sections.map(function (section) {
622
644
  if (section.type !== 'day') {