@mui/x-date-pickers 8.0.0-alpha.13 → 8.0.0-alpha.14

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 (197) hide show
  1. package/CHANGELOG.md +131 -0
  2. package/DatePicker/shared.d.ts +1 -1
  3. package/DateTimePicker/DateTimePicker.types.d.ts +2 -2
  4. package/DateTimePicker/DateTimePickerToolbar.d.ts +1 -1
  5. package/DateTimePicker/DateTimePickerToolbar.js +1 -1
  6. package/DateTimePicker/shared.d.ts +18 -10
  7. package/DateTimePicker/shared.js +23 -2
  8. package/DesktopDateTimePicker/DesktopDateTimePicker.js +2 -11
  9. package/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +4 -7
  10. package/DesktopTimePicker/DesktopTimePicker.types.d.ts +2 -2
  11. package/MobileDateTimePicker/MobileDateTimePicker.d.ts +1 -2
  12. package/MobileDateTimePicker/MobileDateTimePicker.js +61 -6
  13. package/MobileDateTimePicker/MobileDateTimePicker.types.d.ts +1 -3
  14. package/PickersTextField/PickersTextField.js +3 -1
  15. package/StaticDateTimePicker/StaticDateTimePicker.js +60 -6
  16. package/StaticDateTimePicker/StaticDateTimePicker.types.d.ts +1 -2
  17. package/TimePicker/shared.d.ts +1 -1
  18. package/esm/DatePicker/shared.d.ts +1 -1
  19. package/esm/DateTimePicker/DateTimePicker.types.d.ts +2 -2
  20. package/esm/DateTimePicker/DateTimePickerToolbar.d.ts +1 -1
  21. package/esm/DateTimePicker/DateTimePickerToolbar.js +1 -1
  22. package/esm/DateTimePicker/shared.d.ts +18 -10
  23. package/esm/DateTimePicker/shared.js +23 -2
  24. package/esm/DesktopDateTimePicker/DesktopDateTimePicker.js +3 -12
  25. package/esm/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +4 -7
  26. package/esm/DesktopTimePicker/DesktopTimePicker.types.d.ts +2 -2
  27. package/esm/MobileDateTimePicker/MobileDateTimePicker.d.ts +1 -2
  28. package/esm/MobileDateTimePicker/MobileDateTimePicker.js +62 -7
  29. package/esm/MobileDateTimePicker/MobileDateTimePicker.types.d.ts +1 -3
  30. package/esm/PickersTextField/PickersTextField.js +3 -1
  31. package/esm/StaticDateTimePicker/StaticDateTimePicker.js +61 -7
  32. package/esm/StaticDateTimePicker/StaticDateTimePicker.types.d.ts +1 -2
  33. package/esm/TimePicker/shared.d.ts +1 -1
  34. package/esm/index.js +1 -1
  35. package/esm/internals/components/PickerFieldUI.js +6 -2
  36. package/esm/internals/components/PickerPopper/PickerPopper.js +3 -3
  37. package/esm/internals/components/PickerProvider.d.ts +137 -6
  38. package/esm/internals/components/PickerProvider.js +1 -1
  39. package/esm/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +4 -7
  40. package/esm/internals/hooks/useField/useField.js +7 -8
  41. package/esm/internals/hooks/useField/useField.types.d.ts +46 -43
  42. package/esm/internals/hooks/useField/useField.utils.js +4 -1
  43. package/esm/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
  44. package/esm/internals/hooks/useField/useFieldState.d.ts +2 -1
  45. package/esm/internals/hooks/useField/useFieldState.js +136 -83
  46. package/esm/internals/hooks/useField/useFieldV6TextField.js +1 -1
  47. package/esm/internals/hooks/useField/useFieldV7TextField.js +2 -1
  48. package/esm/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +4 -7
  49. package/esm/internals/hooks/useNullableFieldPrivateContext.d.ts +5 -2
  50. package/esm/internals/hooks/usePicker/hooks/useOrientation.d.ts +2 -0
  51. package/esm/internals/hooks/usePicker/hooks/useOrientation.js +34 -0
  52. package/esm/internals/hooks/usePicker/hooks/useValueAndOpenStates.d.ts +19 -0
  53. package/esm/internals/hooks/usePicker/hooks/useValueAndOpenStates.js +210 -0
  54. package/esm/internals/hooks/usePicker/index.d.ts +1 -3
  55. package/esm/internals/hooks/usePicker/usePicker.d.ts +5 -5
  56. package/esm/internals/hooks/usePicker/usePicker.js +276 -34
  57. package/esm/internals/hooks/usePicker/usePicker.types.d.ts +181 -9
  58. package/esm/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +3 -4
  59. package/esm/internals/hooks/useValueWithTimezone.d.ts +1 -1
  60. package/esm/internals/index.d.ts +3 -6
  61. package/esm/internals/models/manager.d.ts +108 -4
  62. package/esm/internals/models/props/basePickerProps.d.ts +2 -2
  63. package/esm/internals/models/props/time.d.ts +1 -1
  64. package/esm/internals/utils/date-time-utils.d.ts +2 -2
  65. package/esm/internals/utils/valueManagers.d.ts +1 -1
  66. package/esm/internals/utils/valueManagers.js +10 -18
  67. package/esm/managers/useDateManager.d.ts +3 -4
  68. package/esm/managers/useDateTimeManager.d.ts +3 -4
  69. package/esm/managers/useTimeManager.d.ts +3 -4
  70. package/esm/models/adapters.d.ts +2 -1
  71. package/esm/models/manager.d.ts +4 -5
  72. package/esm/validation/useValidation.d.ts +1 -1
  73. package/index.js +1 -1
  74. package/internals/components/PickerFieldUI.js +6 -2
  75. package/internals/components/PickerPopper/PickerPopper.js +3 -3
  76. package/internals/components/PickerProvider.d.ts +137 -6
  77. package/internals/components/PickerProvider.js +1 -1
  78. package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +4 -7
  79. package/internals/hooks/useField/useField.js +7 -8
  80. package/internals/hooks/useField/useField.types.d.ts +46 -43
  81. package/internals/hooks/useField/useField.utils.js +4 -1
  82. package/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
  83. package/internals/hooks/useField/useFieldState.d.ts +2 -1
  84. package/internals/hooks/useField/useFieldState.js +135 -82
  85. package/internals/hooks/useField/useFieldV6TextField.js +1 -1
  86. package/internals/hooks/useField/useFieldV7TextField.js +2 -1
  87. package/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +4 -7
  88. package/internals/hooks/useNullableFieldPrivateContext.d.ts +5 -2
  89. package/internals/hooks/usePicker/hooks/useOrientation.d.ts +2 -0
  90. package/internals/hooks/usePicker/hooks/useOrientation.js +42 -0
  91. package/internals/hooks/usePicker/hooks/useValueAndOpenStates.d.ts +19 -0
  92. package/internals/hooks/usePicker/{usePickerValue.js → hooks/useValueAndOpenStates.js} +97 -114
  93. package/internals/hooks/usePicker/index.d.ts +1 -3
  94. package/internals/hooks/usePicker/usePicker.d.ts +5 -5
  95. package/internals/hooks/usePicker/usePicker.js +278 -34
  96. package/internals/hooks/usePicker/usePicker.types.d.ts +181 -9
  97. package/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +3 -4
  98. package/internals/hooks/useValueWithTimezone.d.ts +1 -1
  99. package/internals/index.d.ts +3 -6
  100. package/internals/models/manager.d.ts +108 -4
  101. package/internals/models/props/basePickerProps.d.ts +2 -2
  102. package/internals/models/props/time.d.ts +1 -1
  103. package/internals/utils/date-time-utils.d.ts +2 -2
  104. package/internals/utils/valueManagers.d.ts +1 -1
  105. package/internals/utils/valueManagers.js +10 -18
  106. package/managers/useDateManager.d.ts +3 -4
  107. package/managers/useDateTimeManager.d.ts +3 -4
  108. package/managers/useTimeManager.d.ts +3 -4
  109. package/models/adapters.d.ts +2 -1
  110. package/models/manager.d.ts +4 -5
  111. package/modern/DatePicker/shared.d.ts +1 -1
  112. package/modern/DateTimePicker/DateTimePicker.types.d.ts +2 -2
  113. package/modern/DateTimePicker/DateTimePickerToolbar.d.ts +1 -1
  114. package/modern/DateTimePicker/DateTimePickerToolbar.js +1 -1
  115. package/modern/DateTimePicker/shared.d.ts +18 -10
  116. package/modern/DateTimePicker/shared.js +23 -2
  117. package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +3 -12
  118. package/modern/DesktopDateTimePicker/DesktopDateTimePicker.types.d.ts +4 -7
  119. package/modern/DesktopTimePicker/DesktopTimePicker.types.d.ts +2 -2
  120. package/modern/MobileDateTimePicker/MobileDateTimePicker.d.ts +1 -2
  121. package/modern/MobileDateTimePicker/MobileDateTimePicker.js +62 -7
  122. package/modern/MobileDateTimePicker/MobileDateTimePicker.types.d.ts +1 -3
  123. package/modern/PickersTextField/PickersTextField.js +3 -1
  124. package/modern/StaticDateTimePicker/StaticDateTimePicker.js +61 -7
  125. package/modern/StaticDateTimePicker/StaticDateTimePicker.types.d.ts +1 -2
  126. package/modern/TimePicker/shared.d.ts +1 -1
  127. package/modern/index.js +1 -1
  128. package/modern/internals/components/PickerFieldUI.js +6 -2
  129. package/modern/internals/components/PickerPopper/PickerPopper.js +3 -3
  130. package/modern/internals/components/PickerProvider.d.ts +137 -6
  131. package/modern/internals/components/PickerProvider.js +1 -1
  132. package/modern/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +4 -7
  133. package/modern/internals/hooks/useField/useField.js +7 -8
  134. package/modern/internals/hooks/useField/useField.types.d.ts +46 -43
  135. package/modern/internals/hooks/useField/useField.utils.js +4 -1
  136. package/modern/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
  137. package/modern/internals/hooks/useField/useFieldState.d.ts +2 -1
  138. package/modern/internals/hooks/useField/useFieldState.js +136 -83
  139. package/modern/internals/hooks/useField/useFieldV6TextField.js +1 -1
  140. package/modern/internals/hooks/useField/useFieldV7TextField.js +2 -1
  141. package/modern/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +4 -7
  142. package/modern/internals/hooks/useNullableFieldPrivateContext.d.ts +5 -2
  143. package/modern/internals/hooks/usePicker/hooks/useOrientation.d.ts +2 -0
  144. package/modern/internals/hooks/usePicker/hooks/useOrientation.js +34 -0
  145. package/modern/internals/hooks/usePicker/hooks/useValueAndOpenStates.d.ts +19 -0
  146. package/modern/internals/hooks/usePicker/hooks/useValueAndOpenStates.js +210 -0
  147. package/modern/internals/hooks/usePicker/index.d.ts +1 -3
  148. package/modern/internals/hooks/usePicker/usePicker.d.ts +5 -5
  149. package/modern/internals/hooks/usePicker/usePicker.js +276 -34
  150. package/modern/internals/hooks/usePicker/usePicker.types.d.ts +181 -9
  151. package/modern/internals/hooks/useStaticPicker/useStaticPicker.types.d.ts +3 -4
  152. package/modern/internals/hooks/useValueWithTimezone.d.ts +1 -1
  153. package/modern/internals/index.d.ts +3 -6
  154. package/modern/internals/models/manager.d.ts +108 -4
  155. package/modern/internals/models/props/basePickerProps.d.ts +2 -2
  156. package/modern/internals/models/props/time.d.ts +1 -1
  157. package/modern/internals/utils/date-time-utils.d.ts +2 -2
  158. package/modern/internals/utils/valueManagers.d.ts +1 -1
  159. package/modern/internals/utils/valueManagers.js +10 -18
  160. package/modern/managers/useDateManager.d.ts +3 -4
  161. package/modern/managers/useDateTimeManager.d.ts +3 -4
  162. package/modern/managers/useTimeManager.d.ts +3 -4
  163. package/modern/models/adapters.d.ts +2 -1
  164. package/modern/models/manager.d.ts +4 -5
  165. package/modern/validation/useValidation.d.ts +1 -1
  166. package/package.json +1 -1
  167. package/tsconfig.build.tsbuildinfo +1 -1
  168. package/validation/useValidation.d.ts +1 -1
  169. package/esm/internals/hooks/useOpenState.d.ts +0 -14
  170. package/esm/internals/hooks/useOpenState.js +0 -37
  171. package/esm/internals/hooks/usePicker/usePickerProvider.d.ts +0 -65
  172. package/esm/internals/hooks/usePicker/usePickerProvider.js +0 -125
  173. package/esm/internals/hooks/usePicker/usePickerValue.d.ts +0 -12
  174. package/esm/internals/hooks/usePicker/usePickerValue.js +0 -226
  175. package/esm/internals/hooks/usePicker/usePickerValue.types.d.ts +0 -327
  176. package/esm/internals/hooks/usePicker/usePickerValue.types.js +0 -1
  177. package/esm/internals/hooks/usePicker/usePickerViews.d.ts +0 -137
  178. package/esm/internals/hooks/usePicker/usePickerViews.js +0 -188
  179. package/internals/hooks/useOpenState.d.ts +0 -14
  180. package/internals/hooks/useOpenState.js +0 -46
  181. package/internals/hooks/usePicker/usePickerProvider.d.ts +0 -65
  182. package/internals/hooks/usePicker/usePickerProvider.js +0 -135
  183. package/internals/hooks/usePicker/usePickerValue.d.ts +0 -12
  184. package/internals/hooks/usePicker/usePickerValue.types.d.ts +0 -327
  185. package/internals/hooks/usePicker/usePickerValue.types.js +0 -5
  186. package/internals/hooks/usePicker/usePickerViews.d.ts +0 -137
  187. package/internals/hooks/usePicker/usePickerViews.js +0 -195
  188. package/modern/internals/hooks/useOpenState.d.ts +0 -14
  189. package/modern/internals/hooks/useOpenState.js +0 -37
  190. package/modern/internals/hooks/usePicker/usePickerProvider.d.ts +0 -65
  191. package/modern/internals/hooks/usePicker/usePickerProvider.js +0 -125
  192. package/modern/internals/hooks/usePicker/usePickerValue.d.ts +0 -12
  193. package/modern/internals/hooks/usePicker/usePickerValue.js +0 -226
  194. package/modern/internals/hooks/usePicker/usePickerValue.types.d.ts +0 -327
  195. package/modern/internals/hooks/usePicker/usePickerValue.types.js +0 -1
  196. package/modern/internals/hooks/usePicker/usePickerViews.d.ts +0 -137
  197. package/modern/internals/hooks/usePicker/usePickerViews.js +0 -188
@@ -1,12 +1,13 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import useControlled from '@mui/utils/useControlled';
4
+ import useTimeout from '@mui/utils/useTimeout';
4
5
  import { useRtl } from '@mui/system/RtlProvider';
5
6
  import { usePickerTranslations } from "../../../hooks/usePickerTranslations.js";
6
7
  import { useUtils, useLocalizationContext } from "../useUtils.js";
7
8
  import { mergeDateIntoReferenceDate, getSectionsBoundaries, validateSections, getDateFromDateSections, parseSelectedSections, getLocalizedDigits } from "./useField.utils.js";
8
9
  import { buildSectionsFromFormat } from "./buildSectionsFromFormat.js";
9
- import { useValueWithTimezone } from "../useValueWithTimezone.js";
10
+ import { useControlledValueWithTimezone } from "../useValueWithTimezone.js";
10
11
  import { getSectionTypeGranularity } from "../../utils/getDefaultReferenceDate.js";
11
12
  export const useFieldState = params => {
12
13
  const utils = useUtils();
@@ -34,10 +35,11 @@ export const useFieldState = params => {
34
35
  }
35
36
  } = params;
36
37
  const {
37
- timezone,
38
- value: valueFromTheOutside,
39
- handleValueChange
40
- } = useValueWithTimezone({
38
+ value,
39
+ handleValueChange,
40
+ timezone
41
+ } = useControlledValueWithTimezone({
42
+ name: 'a field component',
41
43
  timezone: timezoneProp,
42
44
  value: valueProp,
43
45
  defaultValue,
@@ -45,9 +47,13 @@ export const useFieldState = params => {
45
47
  onChange,
46
48
  valueManager
47
49
  });
50
+ const valueRef = React.useRef(value);
51
+ React.useEffect(() => {
52
+ valueRef.current = value;
53
+ }, [value]);
48
54
  const localizedDigits = React.useMemo(() => getLocalizedDigits(utils), [utils]);
49
55
  const sectionsValueBoundaries = React.useMemo(() => getSectionsBoundaries(utils, localizedDigits, timezone), [utils, localizedDigits, timezone]);
50
- const getSectionsFromValue = React.useCallback((value, fallbackSections = null) => fieldValueManager.getSectionsFromValue(utils, value, fallbackSections, date => buildSectionsFromFormat({
56
+ const getSectionsFromValue = React.useCallback(valueToAnalyze => fieldValueManager.getSectionsFromValue(valueToAnalyze, date => buildSectionsFromFormat({
51
57
  utils,
52
58
  localeText: translations,
53
59
  localizedDigits,
@@ -59,17 +65,22 @@ export const useFieldState = params => {
59
65
  isRtl
60
66
  })), [fieldValueManager, format, translations, localizedDigits, isRtl, shouldRespectLeadingZeros, utils, formatDensity, enableAccessibleFieldDOMStructure]);
61
67
  const [state, setState] = React.useState(() => {
62
- const sections = getSectionsFromValue(valueFromTheOutside);
68
+ const sections = getSectionsFromValue(value);
63
69
  validateSections(sections, valueType);
64
70
  const stateWithoutReferenceDate = {
65
71
  sections,
66
- value: valueFromTheOutside,
72
+ lastValue: value,
73
+ lastSectionsDependencies: {
74
+ format,
75
+ isRtl,
76
+ locale: utils.locale
77
+ },
67
78
  tempValueStrAndroid: null
68
79
  };
69
80
  const granularity = getSectionTypeGranularity(sections);
70
81
  const referenceValue = valueManager.getInitialReferenceValue({
71
82
  referenceDate: referenceDateProp,
72
- value: valueFromTheOutside,
83
+ value,
73
84
  utils,
74
85
  props: internalProps,
75
86
  granularity,
@@ -91,29 +102,16 @@ export const useFieldState = params => {
91
102
  };
92
103
  const parsedSelectedSections = React.useMemo(() => parseSelectedSections(selectedSections, state.sections), [selectedSections, state.sections]);
93
104
  const activeSectionIndex = parsedSelectedSections === 'all' ? 0 : parsedSelectedSections;
94
- const publishValue = ({
95
- value,
96
- referenceValue,
97
- sections
98
- }) => {
99
- setState(prevState => _extends({}, prevState, {
100
- sections,
101
- value,
102
- referenceValue,
103
- tempValueStrAndroid: null
104
- }));
105
- if (valueManager.areValuesEqual(utils, state.value, value)) {
106
- return;
107
- }
105
+ const publishValue = newValue => {
108
106
  const context = {
109
107
  validationError: validator({
110
108
  adapter,
111
- value,
109
+ value: newValue,
112
110
  timezone,
113
111
  props: internalProps
114
112
  })
115
113
  };
116
- handleValueChange(value, context);
114
+ handleValueChange(newValue, context);
117
115
  };
118
116
  const setSectionValue = (sectionIndex, newSectionValue) => {
119
117
  const newSections = [...state.sections];
@@ -123,27 +121,49 @@ export const useFieldState = params => {
123
121
  });
124
122
  return newSections;
125
123
  };
126
- const clearValue = () => {
127
- publishValue({
128
- value: valueManager.emptyValue,
129
- referenceValue: state.referenceValue,
130
- sections: getSectionsFromValue(valueManager.emptyValue)
124
+ const sectionToUpdateOnNextInvalidDateRef = React.useRef(null);
125
+ const timeoutToUpdateSectionValueOnNextInvalidDate = useTimeout();
126
+ const setSectionUpdateToApplyOnNextInvalidDate = newSectionValue => {
127
+ if (activeSectionIndex == null) {
128
+ return;
129
+ }
130
+ sectionToUpdateOnNextInvalidDateRef.current = {
131
+ sectionIndex: activeSectionIndex,
132
+ value: newSectionValue
133
+ };
134
+ timeoutToUpdateSectionValueOnNextInvalidDate.start(0, () => {
135
+ sectionToUpdateOnNextInvalidDateRef.current = null;
131
136
  });
132
137
  };
138
+ const clearValue = () => {
139
+ if (valueManager.areValuesEqual(utils, value, valueManager.emptyValue)) {
140
+ setState(prevState => _extends({}, prevState, {
141
+ sections: prevState.sections.map(section => _extends({}, section, {
142
+ value: ''
143
+ })),
144
+ tempValueStrAndroid: null
145
+ }));
146
+ } else {
147
+ publishValue(valueManager.emptyValue);
148
+ }
149
+ };
133
150
  const clearActiveSection = () => {
134
151
  if (activeSectionIndex == null) {
135
152
  return;
136
153
  }
137
154
  const activeSection = state.sections[activeSectionIndex];
138
- const activeDateManager = fieldValueManager.getActiveDateManager(utils, state, activeSection);
139
- const nonEmptySectionCountBefore = activeDateManager.getSections(state.sections).filter(section => section.value !== '').length;
140
- const hasNoOtherNonEmptySections = nonEmptySectionCountBefore === (activeSection.value === '' ? 0 : 1);
141
- const newSections = setSectionValue(activeSectionIndex, '');
142
- const newActiveDate = hasNoOtherNonEmptySections ? null : utils.getInvalidDate();
143
- const newValues = activeDateManager.getNewValuesFromNewActiveDate(newActiveDate);
144
- publishValue(_extends({}, newValues, {
145
- sections: newSections
146
- }));
155
+ if (activeSection.value === '') {
156
+ return;
157
+ }
158
+ setSectionUpdateToApplyOnNextInvalidDate('');
159
+ if (fieldValueManager.getDateFromSection(value, activeSection) === null) {
160
+ setState(prevState => _extends({}, prevState, {
161
+ sections: setSectionValue(activeSectionIndex, ''),
162
+ tempValueStrAndroid: null
163
+ }));
164
+ } else {
165
+ publishValue(fieldValueManager.updateDateInValue(value, activeSection, null));
166
+ }
147
167
  };
148
168
  const updateValueFromValueStr = valueStr => {
149
169
  const parseDateStr = (dateStr, referenceDate) => {
@@ -165,34 +185,31 @@ export const useFieldState = params => {
165
185
  return mergeDateIntoReferenceDate(utils, date, sections, referenceDate, false);
166
186
  };
167
187
  const newValue = fieldValueManager.parseValueStr(valueStr, state.referenceValue, parseDateStr);
168
- const newReferenceValue = fieldValueManager.updateReferenceValue(utils, newValue, state.referenceValue);
169
- publishValue({
170
- value: newValue,
171
- referenceValue: newReferenceValue,
172
- sections: getSectionsFromValue(newValue, state.sections)
173
- });
188
+ publishValue(newValue);
174
189
  };
190
+ const timeoutToCleanActiveDateSectionsIfValueNull = useTimeout();
175
191
  const updateSectionValue = ({
176
- activeSection,
192
+ section,
177
193
  newSectionValue,
178
194
  shouldGoToNextSection
179
195
  }) => {
196
+ timeoutToUpdateSectionValueOnNextInvalidDate.clear();
197
+ timeoutToCleanActiveDateSectionsIfValueNull.clear();
198
+ const activeDate = fieldValueManager.getDateFromSection(value, section);
199
+
180
200
  /**
181
- * 1. Decide which section should be focused
201
+ * Decide which section should be focused
182
202
  */
183
203
  if (shouldGoToNextSection && activeSectionIndex < state.sections.length - 1) {
184
204
  setSelectedSections(activeSectionIndex + 1);
185
205
  }
186
206
 
187
207
  /**
188
- * 2. Try to build a valid date from the new section value
208
+ * Try to build a valid date from the new section value
189
209
  */
190
- const activeDateManager = fieldValueManager.getActiveDateManager(utils, state, activeSection);
191
210
  const newSections = setSectionValue(activeSectionIndex, newSectionValue);
192
- const newActiveDateSections = activeDateManager.getSections(newSections);
211
+ const newActiveDateSections = fieldValueManager.getDateSectionsFromValue(newSections, section);
193
212
  const newActiveDate = getDateFromDateSections(utils, newActiveDateSections, localizedDigits);
194
- let values;
195
- let shouldPublish;
196
213
 
197
214
  /**
198
215
  * If the new date is valid,
@@ -200,23 +217,43 @@ export const useFieldState = params => {
200
217
  * This makes sure that we don't lose some information of the initial date (like the time on a date field).
201
218
  */
202
219
  if (utils.isValid(newActiveDate)) {
203
- const mergedDate = mergeDateIntoReferenceDate(utils, newActiveDate, newActiveDateSections, activeDateManager.referenceDate, true);
204
- values = activeDateManager.getNewValuesFromNewActiveDate(mergedDate);
205
- shouldPublish = true;
206
- } else {
207
- values = activeDateManager.getNewValuesFromNewActiveDate(newActiveDate);
208
- shouldPublish = (newActiveDate != null && !utils.isValid(newActiveDate)) !== (activeDateManager.date != null && !utils.isValid(activeDateManager.date));
220
+ const mergedDate = mergeDateIntoReferenceDate(utils, newActiveDate, newActiveDateSections, fieldValueManager.getDateFromSection(state.referenceValue, section), true);
221
+ if (activeDate == null) {
222
+ timeoutToCleanActiveDateSectionsIfValueNull.start(0, () => {
223
+ if (valueRef.current === value) {
224
+ setState(prevState => _extends({}, prevState, {
225
+ sections: fieldValueManager.clearDateSections(state.sections, section),
226
+ tempValueStrAndroid: null
227
+ }));
228
+ }
229
+ });
230
+ }
231
+ return publishValue(fieldValueManager.updateDateInValue(value, section, mergedDate));
209
232
  }
210
233
 
211
234
  /**
212
- * Publish or update the internal state with the new value and sections.
235
+ * If all the sections are filled but the date is invalid,
236
+ * Then we publish an invalid date.
213
237
  */
214
- if (shouldPublish) {
215
- return publishValue(_extends({}, values, {
216
- sections: newSections
217
- }));
238
+ if (newActiveDateSections.every(sectionBis => sectionBis.value !== '')) {
239
+ setSectionUpdateToApplyOnNextInvalidDate(newSectionValue);
240
+ return publishValue(fieldValueManager.updateDateInValue(value, section, newActiveDate));
241
+ }
242
+
243
+ /**
244
+ * If the previous date is not null,
245
+ * Then we publish the date as `null`.
246
+ */
247
+ if (activeDate != null) {
248
+ setSectionUpdateToApplyOnNextInvalidDate(newSectionValue);
249
+ return publishValue(fieldValueManager.updateDateInValue(value, section, null));
218
250
  }
219
- return setState(prevState => _extends({}, prevState, values, {
251
+
252
+ /**
253
+ * If the previous date is already null,
254
+ * Then we don't publish the date and we update the sections.
255
+ */
256
+ return setState(prevState => _extends({}, prevState, {
220
257
  sections: newSections,
221
258
  tempValueStrAndroid: null
222
259
  }));
@@ -224,32 +261,48 @@ export const useFieldState = params => {
224
261
  const setTempAndroidValueStr = tempValueStrAndroid => setState(prev => _extends({}, prev, {
225
262
  tempValueStrAndroid
226
263
  }));
227
- React.useEffect(() => {
228
- const sections = getSectionsFromValue(state.value);
264
+
265
+ // If `prop.value` changes, we update the state to reflect the new value
266
+ if (value !== state.lastValue) {
267
+ let sections;
268
+ if (sectionToUpdateOnNextInvalidDateRef.current != null && !utils.isValid(fieldValueManager.getDateFromSection(value, state.sections[sectionToUpdateOnNextInvalidDateRef.current.sectionIndex]))) {
269
+ sections = setSectionValue(sectionToUpdateOnNextInvalidDateRef.current.sectionIndex, sectionToUpdateOnNextInvalidDateRef.current.value);
270
+ } else {
271
+ sections = getSectionsFromValue(value);
272
+ }
273
+ setState(prevState => _extends({}, prevState, {
274
+ lastValue: value,
275
+ sections,
276
+ sectionsDependencies: {
277
+ format,
278
+ isRtl,
279
+ locale: utils.locale
280
+ },
281
+ referenceValue: fieldValueManager.updateReferenceValue(utils, value, prevState.referenceValue),
282
+ tempValueStrAndroid: null
283
+ }));
284
+ }
285
+ if (isRtl !== state.lastSectionsDependencies.isRtl || format !== state.lastSectionsDependencies.format || utils.locale !== state.lastSectionsDependencies.locale) {
286
+ const sections = getSectionsFromValue(value);
229
287
  validateSections(sections, valueType);
230
288
  setState(prevState => _extends({}, prevState, {
231
- sections
289
+ lastSectionsDependencies: {
290
+ format,
291
+ isRtl,
292
+ locale: utils.locale
293
+ },
294
+ sections,
295
+ tempValueStrAndroid: null
232
296
  }));
233
- }, [format, utils.locale, isRtl]); // eslint-disable-line react-hooks/exhaustive-deps
234
-
297
+ }
235
298
  React.useEffect(() => {
236
- let shouldUpdate;
237
- if (!valueManager.areValuesEqual(utils, state.value, valueFromTheOutside)) {
238
- shouldUpdate = true;
239
- } else {
240
- shouldUpdate = valueManager.getTimezone(utils, state.value) !== valueManager.getTimezone(utils, valueFromTheOutside);
241
- }
242
- if (shouldUpdate) {
243
- setState(prevState => _extends({}, prevState, {
244
- value: valueFromTheOutside,
245
- referenceValue: fieldValueManager.updateReferenceValue(utils, valueFromTheOutside, prevState.referenceValue),
246
- sections: getSectionsFromValue(valueFromTheOutside)
247
- }));
299
+ if (sectionToUpdateOnNextInvalidDateRef.current != null) {
300
+ sectionToUpdateOnNextInvalidDateRef.current = null;
248
301
  }
249
- }, [valueFromTheOutside]); // eslint-disable-line react-hooks/exhaustive-deps
250
-
302
+ });
251
303
  return {
252
304
  state,
305
+ value,
253
306
  activeSectionIndex,
254
307
  parsedSelectedSections,
255
308
  setSelectedSections,
@@ -206,7 +206,7 @@ export const useFieldV6TextField = params => {
206
206
  if (isValidPastedValue) {
207
207
  resetCharacterQuery();
208
208
  updateSectionValue({
209
- activeSection,
209
+ section: activeSection,
210
210
  newSectionValue: pastedValue,
211
211
  shouldGoToNextSection: true
212
212
  });
@@ -254,7 +254,7 @@ export const useFieldV7TextField = params => {
254
254
  if (isValidPastedValue) {
255
255
  resetCharacterQuery();
256
256
  updateSectionValue({
257
- activeSection,
257
+ section: activeSection,
258
258
  newSectionValue: pastedValue,
259
259
  shouldGoToNextSection: true
260
260
  });
@@ -292,6 +292,7 @@ export const useFieldV7TextField = params => {
292
292
  return;
293
293
  }
294
294
  resetCharacterQuery();
295
+ revertDOMSectionChange(sectionIndex);
295
296
  clearActiveSection();
296
297
  return;
297
298
  }
@@ -2,13 +2,10 @@ import * as React from 'react';
2
2
  import { MakeRequired, SlotComponentPropsFromProps } from '@mui/x-internals/types';
3
3
  import { BasePickerProps } from "../../models/props/basePickerProps.js";
4
4
  import { PickersModalDialogSlots, PickersModalDialogSlotProps } from "../../components/PickersModalDialog.js";
5
- import { UsePickerParams } from "../usePicker/index.js";
5
+ import { UsePickerParameters, UsePickerNonStaticProps, UsePickerProps } from "../usePicker/index.js";
6
6
  import { PickerFieldSlotProps, PickerOwnerState } from "../../../models/index.js";
7
7
  import { ExportedPickersLayoutSlots, ExportedPickersLayoutSlotProps, PickersLayoutSlotProps } from "../../../PickersLayout/PickersLayout.types.js";
8
- import { UsePickerValueNonStaticProps } from "../usePicker/usePickerValue.types.js";
9
- import { UsePickerViewsProps } from "../usePicker/usePickerViews.js";
10
8
  import { DateOrTimeViewWithMeridiem, PickerValue } from "../../models/index.js";
11
- import { UsePickerProviderNonStaticProps } from "../usePicker/usePickerProvider.js";
12
9
  import { PickerFieldUISlotsFromContext, PickerFieldUISlotPropsFromContext } from "../../components/PickerFieldUI.js";
13
10
  export interface UseMobilePickerSlots extends PickersModalDialogSlots, ExportedPickersLayoutSlots<PickerValue>, PickerFieldUISlotsFromContext {
14
11
  /**
@@ -20,8 +17,8 @@ export interface ExportedUseMobilePickerSlotProps<TEnableAccessibleFieldDOMStruc
20
17
  field?: SlotComponentPropsFromProps<PickerFieldSlotProps<PickerValue, TEnableAccessibleFieldDOMStructure>, {}, PickerOwnerState>;
21
18
  }
22
19
  export interface UseMobilePickerSlotProps<TEnableAccessibleFieldDOMStructure extends boolean> extends ExportedUseMobilePickerSlotProps<TEnableAccessibleFieldDOMStructure>, Pick<PickersLayoutSlotProps<PickerValue>, 'toolbar'> {}
23
- export interface MobileOnlyPickerProps extends UsePickerValueNonStaticProps, UsePickerProviderNonStaticProps {}
24
- export interface UseMobilePickerProps<TView extends DateOrTimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure extends boolean, TError, TExternalProps extends UsePickerViewsProps<any, TView, any>> extends BasePickerProps<PickerValue, TView, TError, TExternalProps>, MakeRequired<MobileOnlyPickerProps, 'format'> {
20
+ export interface MobileOnlyPickerProps extends UsePickerNonStaticProps {}
21
+ export interface UseMobilePickerProps<TView extends DateOrTimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure extends boolean, TError, TExternalProps extends UsePickerProps<PickerValue, TView, TError, any>> extends BasePickerProps<PickerValue, TView, TError, TExternalProps>, MakeRequired<MobileOnlyPickerProps, 'format'> {
25
22
  /**
26
23
  * Overridable component slots.
27
24
  * @default {}
@@ -33,6 +30,6 @@ export interface UseMobilePickerProps<TView extends DateOrTimeViewWithMeridiem,
33
30
  */
34
31
  slotProps?: UseMobilePickerSlotProps<TEnableAccessibleFieldDOMStructure>;
35
32
  }
36
- export interface UseMobilePickerParams<TView extends DateOrTimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure extends boolean, TExternalProps extends UseMobilePickerProps<TView, TEnableAccessibleFieldDOMStructure, any, TExternalProps>> extends Pick<UsePickerParams<PickerValue, TView, TExternalProps>, 'valueManager' | 'valueType' | 'validator' | 'ref'> {
33
+ export interface UseMobilePickerParams<TView extends DateOrTimeViewWithMeridiem, TEnableAccessibleFieldDOMStructure extends boolean, TExternalProps extends UseMobilePickerProps<TView, TEnableAccessibleFieldDOMStructure, any, TExternalProps>> extends Pick<UsePickerParameters<PickerValue, TView, TExternalProps>, 'valueManager' | 'valueType' | 'validator' | 'ref'> {
37
34
  props: TExternalProps;
38
35
  }
@@ -1,6 +1,9 @@
1
1
  import * as React from 'react';
2
2
  import type { UseFieldInternalProps } from './useField';
3
- import { UsePickerViewsFieldPrivateContextValue } from "./usePicker/usePickerViews.js";
3
+ import { FieldRef } from "../../models/index.js";
4
+ import { PickerRangeValue, PickerValue } from "../models/index.js";
4
5
  export declare const PickerFieldPrivateContext: React.Context<PickerFieldPrivateContextValue | null>;
5
6
  export declare function useNullableFieldPrivateContext(): PickerFieldPrivateContextValue | null;
6
- export interface PickerFieldPrivateContextValue extends Pick<UseFieldInternalProps<any, any, any>, 'formatDensity' | 'enableAccessibleFieldDOMStructure' | 'selectedSections' | 'onSelectedSectionsChange'>, UsePickerViewsFieldPrivateContextValue {}
7
+ export interface PickerFieldPrivateContextValue extends Pick<UseFieldInternalProps<any, any, any>, 'formatDensity' | 'enableAccessibleFieldDOMStructure' | 'selectedSections' | 'onSelectedSectionsChange'> {
8
+ fieldRef: React.RefObject<FieldRef<PickerValue> | FieldRef<PickerRangeValue> | null>;
9
+ }
@@ -0,0 +1,2 @@
1
+ import { DateOrTimeViewWithMeridiem, PickerOrientation } from "../../../models/index.js";
2
+ export declare function useOrientation(views: readonly DateOrTimeViewWithMeridiem[], customOrientation: PickerOrientation | undefined): PickerOrientation;
@@ -0,0 +1,34 @@
1
+ import * as React from 'react';
2
+ import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
3
+ import { arrayIncludes } from "../../../utils/utils.js";
4
+ function getOrientation() {
5
+ if (typeof window === 'undefined') {
6
+ return 'portrait';
7
+ }
8
+ if (window.screen && window.screen.orientation && window.screen.orientation.angle) {
9
+ return Math.abs(window.screen.orientation.angle) === 90 ? 'landscape' : 'portrait';
10
+ }
11
+
12
+ // Support IOS safari
13
+ if (window.orientation) {
14
+ return Math.abs(Number(window.orientation)) === 90 ? 'landscape' : 'portrait';
15
+ }
16
+ return 'portrait';
17
+ }
18
+ export function useOrientation(views, customOrientation) {
19
+ const [orientation, setOrientation] = React.useState(getOrientation);
20
+ useEnhancedEffect(() => {
21
+ const eventHandler = () => {
22
+ setOrientation(getOrientation());
23
+ };
24
+ window.addEventListener('orientationchange', eventHandler);
25
+ return () => {
26
+ window.removeEventListener('orientationchange', eventHandler);
27
+ };
28
+ }, []);
29
+ if (arrayIncludes(views, ['hours', 'minutes', 'seconds'])) {
30
+ // could not display 13:34:44 in landscape mode
31
+ return 'portrait';
32
+ }
33
+ return customOrientation ?? orientation;
34
+ }
@@ -0,0 +1,19 @@
1
+ import * as React from 'react';
2
+ import { DateOrTimeViewWithMeridiem, PickerValidValue, PickerValueManager } from "../../../models/index.js";
3
+ import { PickerSelectionState, UsePickerProps, UsePickerState } from "../usePicker.types.js";
4
+ import { InferError } from "../../../../models/index.js";
5
+ import { SetValueActionOptions } from "../../../components/PickerProvider.js";
6
+ import { Validator } from "../../../../validation/index.js";
7
+ export declare function useValueAndOpenStates<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerProps<TValue, TView, any, any>>(parameters: UsePickerDateStateParameters<TValue, TView, TExternalProps>): {
8
+ timezone: string;
9
+ state: UsePickerState<TValue>;
10
+ setValue: (newValue: TValue, options?: SetValueActionOptions<InferError<TExternalProps>>) => void;
11
+ setValueFromView: (newValue: TValue, selectionState?: PickerSelectionState) => void;
12
+ setOpen: (action: React.SetStateAction<boolean>) => void;
13
+ };
14
+ interface UsePickerDateStateParameters<TValue extends PickerValidValue, TView extends DateOrTimeViewWithMeridiem, TExternalProps extends UsePickerProps<TValue, TView, any, any>> {
15
+ props: TExternalProps;
16
+ valueManager: PickerValueManager<TValue, InferError<TExternalProps>>;
17
+ validator: Validator<TValue, InferError<TExternalProps>, TExternalProps>;
18
+ }
19
+ export {};