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