@mui/x-date-pickers 7.19.0 → 7.20.0
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 +105 -13
- package/DateCalendar/DateCalendar.js +1 -1
- package/DateCalendar/DateCalendar.types.d.ts +1 -1
- package/DateField/DateField.types.d.ts +2 -7
- package/DateField/index.d.ts +1 -1
- package/DatePicker/DatePicker.js +1 -1
- package/DatePicker/DatePicker.types.d.ts +8 -1
- package/DatePicker/index.d.ts +1 -1
- package/DateTimeField/DateTimeField.types.d.ts +2 -7
- package/DateTimeField/index.d.ts +1 -1
- package/DateTimePicker/DateTimePicker.js +1 -1
- package/DateTimePicker/DateTimePicker.types.d.ts +9 -1
- package/DateTimePicker/DateTimePickerTabs.js +1 -1
- package/DateTimePicker/index.d.ts +1 -1
- package/DesktopDatePicker/DesktopDatePicker.js +1 -1
- package/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -1
- package/DigitalClock/DigitalClock.js +39 -0
- package/MobileDatePicker/MobileDatePicker.js +1 -1
- package/MobileDateTimePicker/MobileDateTimePicker.js +1 -1
- package/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +38 -1
- package/StaticDatePicker/StaticDatePicker.js +1 -1
- package/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
- package/TimeClock/Clock.js +8 -0
- package/TimeField/TimeField.types.d.ts +2 -7
- package/TimeField/index.d.ts +1 -1
- package/TimePicker/TimePicker.types.d.ts +9 -1
- package/TimePicker/index.d.ts +1 -1
- package/hooks/index.d.ts +2 -0
- package/hooks/index.js +3 -1
- package/hooks/useParsedFormat.d.ts +15 -0
- package/hooks/useParsedFormat.js +43 -0
- package/hooks/usePickersContext.d.ts +4 -0
- package/hooks/usePickersContext.js +15 -0
- package/index.js +1 -1
- package/internals/components/PickersProvider.d.ts +34 -0
- package/internals/components/PickersProvider.js +26 -0
- package/internals/hooks/useDesktopPicker/useDesktopPicker.js +7 -4
- package/internals/hooks/useField/buildSectionsFromFormat.d.ts +1 -2
- package/internals/hooks/useField/buildSectionsFromFormat.js +4 -5
- package/internals/hooks/useField/useField.utils.d.ts +3 -3
- package/internals/hooks/useField/useField.utils.js +13 -13
- package/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
- package/internals/hooks/useField/useFieldState.js +3 -5
- package/internals/hooks/useMobilePicker/useMobilePicker.js +7 -4
- package/internals/hooks/usePicker/usePicker.js +3 -1
- package/internals/hooks/usePicker/usePickerValue.js +7 -2
- package/internals/hooks/usePicker/usePickerValue.types.d.ts +2 -0
- package/internals/index.d.ts +1 -0
- package/internals/index.js +1 -0
- package/internals/utils/utils.d.ts +7 -0
- package/internals/utils/utils.js +11 -0
- package/models/pickers.d.ts +1 -1
- package/modern/DateCalendar/DateCalendar.js +1 -1
- package/modern/DatePicker/DatePicker.js +1 -1
- package/modern/DateTimePicker/DateTimePicker.js +1 -1
- package/modern/DateTimePicker/DateTimePickerTabs.js +1 -1
- package/modern/DesktopDatePicker/DesktopDatePicker.js +1 -1
- package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -1
- package/modern/DigitalClock/DigitalClock.js +39 -0
- package/modern/MobileDatePicker/MobileDatePicker.js +1 -1
- package/modern/MobileDateTimePicker/MobileDateTimePicker.js +1 -1
- package/modern/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +38 -1
- package/modern/StaticDatePicker/StaticDatePicker.js +1 -1
- package/modern/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
- package/modern/TimeClock/Clock.js +8 -0
- package/modern/hooks/index.js +3 -1
- package/modern/hooks/useParsedFormat.js +43 -0
- package/modern/hooks/usePickersContext.js +15 -0
- package/modern/index.js +1 -1
- package/modern/internals/components/PickersProvider.js +26 -0
- package/modern/internals/hooks/useDesktopPicker/useDesktopPicker.js +7 -4
- package/modern/internals/hooks/useField/buildSectionsFromFormat.js +4 -5
- package/modern/internals/hooks/useField/useField.utils.js +13 -13
- package/modern/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
- package/modern/internals/hooks/useField/useFieldState.js +3 -5
- package/modern/internals/hooks/useMobilePicker/useMobilePicker.js +7 -4
- package/modern/internals/hooks/usePicker/usePicker.js +3 -1
- package/modern/internals/hooks/usePicker/usePickerValue.js +7 -2
- package/modern/internals/index.js +1 -0
- package/modern/internals/utils/utils.js +11 -0
- package/node/DateCalendar/DateCalendar.js +1 -1
- package/node/DatePicker/DatePicker.js +1 -1
- package/node/DateTimePicker/DateTimePicker.js +1 -1
- package/node/DateTimePicker/DateTimePickerTabs.js +1 -1
- package/node/DesktopDatePicker/DesktopDatePicker.js +1 -1
- package/node/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -1
- package/node/DigitalClock/DigitalClock.js +39 -0
- package/node/MobileDatePicker/MobileDatePicker.js +1 -1
- package/node/MobileDateTimePicker/MobileDateTimePicker.js +1 -1
- package/node/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +38 -1
- package/node/StaticDatePicker/StaticDatePicker.js +1 -1
- package/node/StaticDateTimePicker/StaticDateTimePicker.js +1 -1
- package/node/TimeClock/Clock.js +8 -0
- package/node/hooks/index.js +15 -1
- package/node/hooks/useParsedFormat.js +50 -0
- package/node/hooks/usePickersContext.js +21 -0
- package/node/index.js +1 -1
- package/node/internals/components/PickersProvider.js +34 -0
- package/node/internals/hooks/useDesktopPicker/useDesktopPicker.js +5 -3
- package/node/internals/hooks/useField/buildSectionsFromFormat.js +4 -5
- package/node/internals/hooks/useField/useField.utils.js +13 -13
- package/node/internals/hooks/useField/useFieldCharacterEditing.js +2 -2
- package/node/internals/hooks/useField/useFieldState.js +3 -5
- package/node/internals/hooks/useMobilePicker/useMobilePicker.js +5 -3
- package/node/internals/hooks/usePicker/usePicker.js +3 -1
- package/node/internals/hooks/usePicker/usePickerValue.js +7 -1
- package/node/internals/index.js +7 -0
- package/node/internals/utils/utils.js +13 -1
- package/package.json +4 -4
|
@@ -32,4 +32,15 @@ export const getActiveElement = (root = document) => {
|
|
|
32
32
|
}
|
|
33
33
|
return activeEl;
|
|
34
34
|
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Gets the index of the focused list item in a given ul list element.
|
|
38
|
+
*
|
|
39
|
+
* @param {HTMLUListElement} listElement - The list element to search within.
|
|
40
|
+
* @returns {number} The index of the focused list item, or -1 if none is focused.
|
|
41
|
+
*/
|
|
42
|
+
export const getFocusedListItemIndex = listElement => {
|
|
43
|
+
const children = listElement.children;
|
|
44
|
+
return Array.from(children).findIndex(child => child === getActiveElement(document));
|
|
45
|
+
};
|
|
35
46
|
export const DEFAULT_DESKTOP_MODE_MEDIA_QUERY = '@media (pointer: fine)';
|
|
@@ -494,7 +494,7 @@ process.env.NODE_ENV !== "production" ? DateCalendar.propTypes = {
|
|
|
494
494
|
/**
|
|
495
495
|
* Component displaying when passed `loading` true.
|
|
496
496
|
* @returns {React.ReactNode} The node to render when loading.
|
|
497
|
-
* @default () => <span
|
|
497
|
+
* @default () => <span>...</span>
|
|
498
498
|
*/
|
|
499
499
|
renderLoading: _propTypes.default.func,
|
|
500
500
|
/**
|
|
@@ -263,7 +263,7 @@ process.env.NODE_ENV !== "production" ? DatePicker.propTypes = {
|
|
|
263
263
|
/**
|
|
264
264
|
* Component displaying when passed `loading` true.
|
|
265
265
|
* @returns {React.ReactNode} The node to render when loading.
|
|
266
|
-
* @default () => <span
|
|
266
|
+
* @default () => <span>...</span>
|
|
267
267
|
*/
|
|
268
268
|
renderLoading: _propTypes.default.func,
|
|
269
269
|
/**
|
|
@@ -301,7 +301,7 @@ process.env.NODE_ENV !== "production" ? DateTimePicker.propTypes = {
|
|
|
301
301
|
/**
|
|
302
302
|
* Component displaying when passed `loading` true.
|
|
303
303
|
* @returns {React.ReactNode} The node to render when loading.
|
|
304
|
-
* @default () => <span
|
|
304
|
+
* @default () => <span>...</span>
|
|
305
305
|
*/
|
|
306
306
|
renderLoading: _propTypes.default.func,
|
|
307
307
|
/**
|
|
@@ -94,7 +94,7 @@ const DateTimePickerTabs = exports.DateTimePickerTabs = function DateTimePickerT
|
|
|
94
94
|
variant: "fullWidth",
|
|
95
95
|
value: viewToTab(view),
|
|
96
96
|
onChange: handleChange,
|
|
97
|
-
className: (0, _clsx.default)(classes.root
|
|
97
|
+
className: (0, _clsx.default)(className, classes.root),
|
|
98
98
|
sx: sx,
|
|
99
99
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Tab.default, {
|
|
100
100
|
value: "date",
|
|
@@ -284,7 +284,7 @@ DesktopDatePicker.propTypes = {
|
|
|
284
284
|
/**
|
|
285
285
|
* Component displaying when passed `loading` true.
|
|
286
286
|
* @returns {React.ReactNode} The node to render when loading.
|
|
287
|
-
* @default () => <span
|
|
287
|
+
* @default () => <span>...</span>
|
|
288
288
|
*/
|
|
289
289
|
renderLoading: _propTypes.default.func,
|
|
290
290
|
/**
|
|
@@ -409,7 +409,7 @@ DesktopDateTimePicker.propTypes = {
|
|
|
409
409
|
/**
|
|
410
410
|
* Component displaying when passed `loading` true.
|
|
411
411
|
* @returns {React.ReactNode} The node to render when loading.
|
|
412
|
-
* @default () => <span
|
|
412
|
+
* @default () => <span>...</span>
|
|
413
413
|
*/
|
|
414
414
|
renderLoading: _propTypes.default.func,
|
|
415
415
|
/**
|
|
@@ -29,6 +29,7 @@ var _dimensions = require("../internals/constants/dimensions");
|
|
|
29
29
|
var _useValueWithTimezone = require("../internals/hooks/useValueWithTimezone");
|
|
30
30
|
var _valueManagers = require("../internals/utils/valueManagers");
|
|
31
31
|
var _useClockReferenceDate = require("../internals/hooks/useClockReferenceDate");
|
|
32
|
+
var _utils = require("../internals/utils/utils");
|
|
32
33
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
33
34
|
const _excluded = ["ampm", "timeStep", "autoFocus", "slots", "slotProps", "value", "defaultValue", "referenceDate", "disableIgnoringDatePartForTimeValidation", "maxTime", "minTime", "disableFuture", "disablePast", "minutesStep", "shouldDisableTime", "onChange", "view", "openTo", "onViewChange", "focusedView", "onFocusedViewChange", "className", "disabled", "readOnly", "views", "skipDisabled", "timezone"];
|
|
34
35
|
const useUtilityClasses = ownerState => {
|
|
@@ -111,6 +112,7 @@ const DigitalClock = exports.DigitalClock = /*#__PURE__*/React.forwardRef(functi
|
|
|
111
112
|
const utils = (0, _useUtils.useUtils)();
|
|
112
113
|
const containerRef = React.useRef(null);
|
|
113
114
|
const handleRef = (0, _useForkRef.default)(ref, containerRef);
|
|
115
|
+
const listRef = React.useRef(null);
|
|
114
116
|
const props = (0, _styles.useThemeProps)({
|
|
115
117
|
props: inProps,
|
|
116
118
|
name: 'MuiDigitalClock'
|
|
@@ -243,15 +245,52 @@ const DigitalClock = exports.DigitalClock = /*#__PURE__*/React.forwardRef(functi
|
|
|
243
245
|
}, (_, index) => utils.addMinutes(startOfDay, timeStep * (index + 1)))];
|
|
244
246
|
}, [valueOrReferenceDate, timeStep, utils]);
|
|
245
247
|
const focusedOptionIndex = timeOptions.findIndex(option => utils.isEqual(option, valueOrReferenceDate));
|
|
248
|
+
const handleKeyDown = event => {
|
|
249
|
+
switch (event.key) {
|
|
250
|
+
case 'PageUp':
|
|
251
|
+
{
|
|
252
|
+
if (!listRef.current) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
const newIndex = (0, _utils.getFocusedListItemIndex)(listRef.current) - 5;
|
|
256
|
+
const children = listRef.current?.children;
|
|
257
|
+
const newFocusedIndex = Math.max(0, newIndex);
|
|
258
|
+
const childToFocus = children[newFocusedIndex];
|
|
259
|
+
if (childToFocus) {
|
|
260
|
+
childToFocus.focus();
|
|
261
|
+
}
|
|
262
|
+
event.preventDefault();
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
case 'PageDown':
|
|
266
|
+
{
|
|
267
|
+
if (!listRef.current) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const newIndex = (0, _utils.getFocusedListItemIndex)(listRef.current) + 5;
|
|
271
|
+
const children = listRef.current?.children;
|
|
272
|
+
const newFocusedIndex = Math.min(children.length - 1, newIndex);
|
|
273
|
+
const childToFocus = children[newFocusedIndex];
|
|
274
|
+
if (childToFocus) {
|
|
275
|
+
childToFocus.focus();
|
|
276
|
+
}
|
|
277
|
+
event.preventDefault();
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
default:
|
|
281
|
+
}
|
|
282
|
+
};
|
|
246
283
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(DigitalClockRoot, (0, _extends2.default)({
|
|
247
284
|
ref: handleRef,
|
|
248
285
|
className: (0, _clsx.default)(classes.root, className),
|
|
249
286
|
ownerState: ownerState
|
|
250
287
|
}, other, {
|
|
251
288
|
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(DigitalClockList, {
|
|
289
|
+
ref: listRef,
|
|
252
290
|
role: "listbox",
|
|
253
291
|
"aria-label": translations.timePickerToolbarTitle,
|
|
254
292
|
className: classes.list,
|
|
293
|
+
onKeyDown: handleKeyDown,
|
|
255
294
|
children: timeOptions.map((option, index) => {
|
|
256
295
|
if (skipDisabled && isTimeDisabled(option)) {
|
|
257
296
|
return null;
|
|
@@ -281,7 +281,7 @@ MobileDatePicker.propTypes = {
|
|
|
281
281
|
/**
|
|
282
282
|
* Component displaying when passed `loading` true.
|
|
283
283
|
* @returns {React.ReactNode} The node to render when loading.
|
|
284
|
-
* @default () => <span
|
|
284
|
+
* @default () => <span>...</span>
|
|
285
285
|
*/
|
|
286
286
|
renderLoading: _propTypes.default.func,
|
|
287
287
|
/**
|
|
@@ -329,7 +329,7 @@ MobileDateTimePicker.propTypes = {
|
|
|
329
329
|
/**
|
|
330
330
|
* Component displaying when passed `loading` true.
|
|
331
331
|
* @returns {React.ReactNode} The node to render when loading.
|
|
332
|
-
* @default () => <span
|
|
332
|
+
* @default () => <span>...</span>
|
|
333
333
|
*/
|
|
334
334
|
renderLoading: _propTypes.default.func,
|
|
335
335
|
/**
|
|
@@ -17,6 +17,7 @@ var _MenuItem = _interopRequireDefault(require("@mui/material/MenuItem"));
|
|
|
17
17
|
var _useForkRef = _interopRequireDefault(require("@mui/utils/useForkRef"));
|
|
18
18
|
var _multiSectionDigitalClockSectionClasses = require("./multiSectionDigitalClockSectionClasses");
|
|
19
19
|
var _dimensions = require("../internals/constants/dimensions");
|
|
20
|
+
var _utils = require("../internals/utils/utils");
|
|
20
21
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
21
22
|
const _excluded = ["autoFocus", "onChange", "className", "disabled", "readOnly", "items", "active", "slots", "slotProps", "skipDisabled"];
|
|
22
23
|
const useUtilityClasses = ownerState => {
|
|
@@ -146,12 +147,48 @@ const MultiSectionDigitalClockSection = exports.MultiSectionDigitalClockSection
|
|
|
146
147
|
containerRef.current.scrollTop = offsetTop - 4;
|
|
147
148
|
});
|
|
148
149
|
const focusedOptionIndex = items.findIndex(item => item.isFocused(item.value));
|
|
150
|
+
const handleKeyDown = event => {
|
|
151
|
+
switch (event.key) {
|
|
152
|
+
case 'PageUp':
|
|
153
|
+
{
|
|
154
|
+
if (!containerRef.current) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const newIndex = (0, _utils.getFocusedListItemIndex)(containerRef.current) - 5;
|
|
158
|
+
const children = containerRef.current?.children;
|
|
159
|
+
const newFocusedIndex = Math.max(0, newIndex);
|
|
160
|
+
const childToFocus = children[newFocusedIndex];
|
|
161
|
+
if (childToFocus) {
|
|
162
|
+
childToFocus.focus();
|
|
163
|
+
}
|
|
164
|
+
event.preventDefault();
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
case 'PageDown':
|
|
168
|
+
{
|
|
169
|
+
if (!containerRef.current) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
const newIndex = (0, _utils.getFocusedListItemIndex)(containerRef.current) + 5;
|
|
173
|
+
const children = containerRef.current?.children;
|
|
174
|
+
const newFocusedIndex = Math.min(children.length - 1, newIndex);
|
|
175
|
+
const childToFocus = children[newFocusedIndex];
|
|
176
|
+
if (childToFocus) {
|
|
177
|
+
childToFocus.focus();
|
|
178
|
+
}
|
|
179
|
+
event.preventDefault();
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
default:
|
|
183
|
+
}
|
|
184
|
+
};
|
|
149
185
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(MultiSectionDigitalClockSectionRoot, (0, _extends2.default)({
|
|
150
186
|
ref: handleRef,
|
|
151
187
|
className: (0, _clsx.default)(classes.root, className),
|
|
152
188
|
ownerState: ownerState,
|
|
153
189
|
autoFocusItem: autoFocus && active,
|
|
154
|
-
role: "listbox"
|
|
190
|
+
role: "listbox",
|
|
191
|
+
onKeyDown: handleKeyDown
|
|
155
192
|
}, other, {
|
|
156
193
|
children: items.map((option, index) => {
|
|
157
194
|
const isItemDisabled = option.isDisabled?.(option.value);
|
|
@@ -215,7 +215,7 @@ StaticDatePicker.propTypes = {
|
|
|
215
215
|
/**
|
|
216
216
|
* Component displaying when passed `loading` true.
|
|
217
217
|
* @returns {React.ReactNode} The node to render when loading.
|
|
218
|
-
* @default () => <span
|
|
218
|
+
* @default () => <span>...</span>
|
|
219
219
|
*/
|
|
220
220
|
renderLoading: _propTypes.default.func,
|
|
221
221
|
/**
|
|
@@ -263,7 +263,7 @@ StaticDateTimePicker.propTypes = {
|
|
|
263
263
|
/**
|
|
264
264
|
* Component displaying when passed `loading` true.
|
|
265
265
|
* @returns {React.ReactNode} The node to render when loading.
|
|
266
|
-
* @default () => <span
|
|
266
|
+
* @default () => <span>...</span>
|
|
267
267
|
*/
|
|
268
268
|
renderLoading: _propTypes.default.func,
|
|
269
269
|
/**
|
package/node/TimeClock/Clock.js
CHANGED
|
@@ -282,6 +282,14 @@ function Clock(inProps) {
|
|
|
282
282
|
handleValueChange(viewValue - keyboardControlStep, 'partial');
|
|
283
283
|
event.preventDefault();
|
|
284
284
|
break;
|
|
285
|
+
case 'PageUp':
|
|
286
|
+
handleValueChange(viewValue + 5, 'partial');
|
|
287
|
+
event.preventDefault();
|
|
288
|
+
break;
|
|
289
|
+
case 'PageDown':
|
|
290
|
+
handleValueChange(viewValue - 5, 'partial');
|
|
291
|
+
event.preventDefault();
|
|
292
|
+
break;
|
|
285
293
|
case 'Enter':
|
|
286
294
|
case ' ':
|
|
287
295
|
handleValueChange(viewValue, 'finish');
|
package/node/hooks/index.js
CHANGED
|
@@ -9,6 +9,18 @@ Object.defineProperty(exports, "useClearableField", {
|
|
|
9
9
|
return _useClearableField.useClearableField;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
+
Object.defineProperty(exports, "useParsedFormat", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _useParsedFormat.useParsedFormat;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "usePickersContext", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _usePickersContext.usePickersContext;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
12
24
|
Object.defineProperty(exports, "usePickersTranslations", {
|
|
13
25
|
enumerable: true,
|
|
14
26
|
get: function () {
|
|
@@ -23,4 +35,6 @@ Object.defineProperty(exports, "useSplitFieldProps", {
|
|
|
23
35
|
});
|
|
24
36
|
var _useClearableField = require("./useClearableField");
|
|
25
37
|
var _usePickersTranslations = require("./usePickersTranslations");
|
|
26
|
-
var _useSplitFieldProps = require("./useSplitFieldProps");
|
|
38
|
+
var _useSplitFieldProps = require("./useSplitFieldProps");
|
|
39
|
+
var _useParsedFormat = require("./useParsedFormat");
|
|
40
|
+
var _usePickersContext = require("./usePickersContext");
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.useParsedFormat = void 0;
|
|
9
|
+
var React = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _RtlProvider = require("@mui/system/RtlProvider");
|
|
11
|
+
var _useUtils = require("../internals/hooks/useUtils");
|
|
12
|
+
var _buildSectionsFromFormat = require("../internals/hooks/useField/buildSectionsFromFormat");
|
|
13
|
+
var _useField = require("../internals/hooks/useField/useField.utils");
|
|
14
|
+
var _usePickersTranslations = require("./usePickersTranslations");
|
|
15
|
+
/**
|
|
16
|
+
* Returns the parsed format to be rendered in the field when there is no value or in other parts of the Picker.
|
|
17
|
+
* This format is localized (e.g: `AAAA` for the year with the French locale) and cannot be parsed by your date library.
|
|
18
|
+
* @param {object} The parameters needed to build the placeholder.
|
|
19
|
+
* @param {string} params.format Format of the date to use.
|
|
20
|
+
* @param {'dense' | 'spacious'} params.formatDensity Density of the format (setting `formatDensity` to `"spacious"` will add a space before and after each `/`, `-` and `.` character).
|
|
21
|
+
* @param {boolean} params.shouldRespectLeadingZeros If `true`, the format will respect the leading zeroes, if `false`, the format will always add leading zeroes.
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
const useParsedFormat = parameters => {
|
|
25
|
+
const {
|
|
26
|
+
format,
|
|
27
|
+
formatDensity = 'dense',
|
|
28
|
+
shouldRespectLeadingZeros = false
|
|
29
|
+
} = parameters;
|
|
30
|
+
const utils = (0, _useUtils.useUtils)();
|
|
31
|
+
const isRtl = (0, _RtlProvider.useRtl)();
|
|
32
|
+
const translations = (0, _usePickersTranslations.usePickersTranslations)();
|
|
33
|
+
const localizedDigits = React.useMemo(() => (0, _useField.getLocalizedDigits)(utils), [utils]);
|
|
34
|
+
return React.useMemo(() => {
|
|
35
|
+
const sections = (0, _buildSectionsFromFormat.buildSectionsFromFormat)({
|
|
36
|
+
utils,
|
|
37
|
+
format,
|
|
38
|
+
formatDensity,
|
|
39
|
+
isRtl,
|
|
40
|
+
shouldRespectLeadingZeros,
|
|
41
|
+
localeText: translations,
|
|
42
|
+
localizedDigits,
|
|
43
|
+
date: null,
|
|
44
|
+
// TODO v9: Make sure we still don't reverse in `buildSectionsFromFormat` when using `useParsedFormat`.
|
|
45
|
+
enableAccessibleFieldDOMStructure: false
|
|
46
|
+
});
|
|
47
|
+
return sections.map(section => `${section.startSeparator}${section.placeholder}${section.endSeparator}`).join('');
|
|
48
|
+
}, [utils, isRtl, translations, localizedDigits, format, formatDensity, shouldRespectLeadingZeros]);
|
|
49
|
+
};
|
|
50
|
+
exports.useParsedFormat = useParsedFormat;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.usePickersContext = void 0;
|
|
9
|
+
var React = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _PickersProvider = require("../internals/components/PickersProvider");
|
|
11
|
+
/**
|
|
12
|
+
* Returns the context passed by the picker that wraps the current component.
|
|
13
|
+
*/
|
|
14
|
+
const usePickersContext = () => {
|
|
15
|
+
const value = React.useContext(_PickersProvider.PickersContext);
|
|
16
|
+
if (value == null) {
|
|
17
|
+
throw new Error(['MUI X: The `usePickersContext` can only be called in fields that are used as a slot of a picker component'].join('\n'));
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
};
|
|
21
|
+
exports.usePickersContext = usePickersContext;
|
package/node/index.js
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.PickersContext = void 0;
|
|
8
|
+
exports.PickersProvider = PickersProvider;
|
|
9
|
+
var React = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _LocalizationProvider = require("../../LocalizationProvider");
|
|
11
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
|
+
const PickersContext = exports.PickersContext = /*#__PURE__*/React.createContext(null);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Provides the context for the various parts of a picker component:
|
|
16
|
+
* - contextValue: the context for the picker sub-components.
|
|
17
|
+
* - localizationProvider: the translations passed through the props and through a parent LocalizationProvider.
|
|
18
|
+
*
|
|
19
|
+
* @ignore - do not document.
|
|
20
|
+
*/
|
|
21
|
+
function PickersProvider(props) {
|
|
22
|
+
const {
|
|
23
|
+
contextValue,
|
|
24
|
+
localeText,
|
|
25
|
+
children
|
|
26
|
+
} = props;
|
|
27
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(PickersContext.Provider, {
|
|
28
|
+
value: contextValue,
|
|
29
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_LocalizationProvider.LocalizationProvider, {
|
|
30
|
+
localeText: localeText,
|
|
31
|
+
children: children
|
|
32
|
+
})
|
|
33
|
+
});
|
|
34
|
+
}
|
|
@@ -16,8 +16,8 @@ var _useForkRef = _interopRequireDefault(require("@mui/utils/useForkRef"));
|
|
|
16
16
|
var _useId = _interopRequireDefault(require("@mui/utils/useId"));
|
|
17
17
|
var _PickersPopper = require("../../components/PickersPopper");
|
|
18
18
|
var _usePicker = require("../usePicker");
|
|
19
|
-
var _LocalizationProvider = require("../../../LocalizationProvider");
|
|
20
19
|
var _PickersLayout = require("../../../PickersLayout");
|
|
20
|
+
var _PickersProvider = require("../../components/PickersProvider");
|
|
21
21
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
22
22
|
const _excluded = ["props", "getOpenDialogAriaText"],
|
|
23
23
|
_excluded2 = ["ownerState"],
|
|
@@ -65,7 +65,8 @@ const useDesktopPicker = _ref => {
|
|
|
65
65
|
layoutProps,
|
|
66
66
|
renderCurrentView,
|
|
67
67
|
shouldRestoreFocus,
|
|
68
|
-
fieldProps: pickerFieldProps
|
|
68
|
+
fieldProps: pickerFieldProps,
|
|
69
|
+
contextValue
|
|
69
70
|
} = (0, _usePicker.usePicker)((0, _extends2.default)({}, pickerParams, {
|
|
70
71
|
props,
|
|
71
72
|
fieldRef,
|
|
@@ -169,7 +170,8 @@ const useDesktopPicker = _ref => {
|
|
|
169
170
|
}, innerSlotProps?.popper)
|
|
170
171
|
});
|
|
171
172
|
const handleFieldRef = (0, _useForkRef.default)(fieldRef, fieldProps.unstableFieldRef);
|
|
172
|
-
const renderPicker = () => /*#__PURE__*/(0, _jsxRuntime.jsxs)(
|
|
173
|
+
const renderPicker = () => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_PickersProvider.PickersProvider, {
|
|
174
|
+
contextValue: contextValue,
|
|
173
175
|
localeText: localeText,
|
|
174
176
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Field, (0, _extends2.default)({}, fieldProps, {
|
|
175
177
|
slots: slotsForField,
|
|
@@ -45,12 +45,12 @@ const getEscapedPartsFromFormat = ({
|
|
|
45
45
|
}
|
|
46
46
|
return escapedParts;
|
|
47
47
|
};
|
|
48
|
-
const getSectionPlaceholder = (utils,
|
|
48
|
+
const getSectionPlaceholder = (utils, localeText, sectionConfig, sectionFormat) => {
|
|
49
49
|
switch (sectionConfig.type) {
|
|
50
50
|
case 'year':
|
|
51
51
|
{
|
|
52
52
|
return localeText.fieldYearPlaceholder({
|
|
53
|
-
digitAmount: utils.formatByString(utils.date(undefined,
|
|
53
|
+
digitAmount: utils.formatByString(utils.date(undefined, 'default'), sectionFormat).length,
|
|
54
54
|
format: sectionFormat
|
|
55
55
|
});
|
|
56
56
|
}
|
|
@@ -106,7 +106,6 @@ const getSectionPlaceholder = (utils, timezone, localeText, sectionConfig, secti
|
|
|
106
106
|
};
|
|
107
107
|
const createSection = ({
|
|
108
108
|
utils,
|
|
109
|
-
timezone,
|
|
110
109
|
date,
|
|
111
110
|
shouldRespectLeadingZeros,
|
|
112
111
|
localeText,
|
|
@@ -119,7 +118,7 @@ const createSection = ({
|
|
|
119
118
|
throw new Error('MUI X: Should not call `commitToken` with an empty token');
|
|
120
119
|
}
|
|
121
120
|
const sectionConfig = (0, _useField.getDateSectionConfigFromFormatToken)(utils, token);
|
|
122
|
-
const hasLeadingZerosInFormat = (0, _useField.doesSectionFormatHaveLeadingZeros)(utils,
|
|
121
|
+
const hasLeadingZerosInFormat = (0, _useField.doesSectionFormatHaveLeadingZeros)(utils, sectionConfig.contentType, sectionConfig.type, token);
|
|
123
122
|
const hasLeadingZerosInInput = shouldRespectLeadingZeros ? hasLeadingZerosInFormat : sectionConfig.contentType === 'digit';
|
|
124
123
|
const isValidDate = date != null && utils.isValid(date);
|
|
125
124
|
let sectionValue = isValidDate ? utils.formatByString(date, token) : '';
|
|
@@ -141,7 +140,7 @@ const createSection = ({
|
|
|
141
140
|
format: token,
|
|
142
141
|
maxLength,
|
|
143
142
|
value: sectionValue,
|
|
144
|
-
placeholder: getSectionPlaceholder(utils,
|
|
143
|
+
placeholder: getSectionPlaceholder(utils, localeText, sectionConfig, token),
|
|
145
144
|
hasLeadingZerosInFormat,
|
|
146
145
|
hasLeadingZerosInInput,
|
|
147
146
|
startSeparator,
|
|
@@ -38,9 +38,9 @@ const getDeltaFromKeyCode = keyCode => {
|
|
|
38
38
|
return 0;
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
|
-
const getDaysInWeekStr = (utils,
|
|
41
|
+
const getDaysInWeekStr = (utils, format) => {
|
|
42
42
|
const elements = [];
|
|
43
|
-
const now = utils.date(undefined,
|
|
43
|
+
const now = utils.date(undefined, 'default');
|
|
44
44
|
const startDate = utils.startOfWeek(now);
|
|
45
45
|
const endDate = utils.endOfWeek(now);
|
|
46
46
|
let current = startDate;
|
|
@@ -59,7 +59,7 @@ const getLetterEditingOptions = (utils, timezone, sectionType, format) => {
|
|
|
59
59
|
}
|
|
60
60
|
case 'weekDay':
|
|
61
61
|
{
|
|
62
|
-
return getDaysInWeekStr(utils,
|
|
62
|
+
return getDaysInWeekStr(utils, format);
|
|
63
63
|
}
|
|
64
64
|
case 'meridiem':
|
|
65
65
|
{
|
|
@@ -252,17 +252,17 @@ const changeSectionValueFormat = (utils, valueStr, currentFormat, newFormat) =>
|
|
|
252
252
|
return utils.formatByString(utils.parse(valueStr, currentFormat), newFormat);
|
|
253
253
|
};
|
|
254
254
|
exports.changeSectionValueFormat = changeSectionValueFormat;
|
|
255
|
-
const isFourDigitYearFormat = (utils,
|
|
256
|
-
const doesSectionFormatHaveLeadingZeros = (utils,
|
|
255
|
+
const isFourDigitYearFormat = (utils, format) => utils.formatByString(utils.date(undefined, 'system'), format).length === 4;
|
|
256
|
+
const doesSectionFormatHaveLeadingZeros = (utils, contentType, sectionType, format) => {
|
|
257
257
|
if (contentType !== 'digit') {
|
|
258
258
|
return false;
|
|
259
259
|
}
|
|
260
|
-
const now = utils.date(undefined,
|
|
260
|
+
const now = utils.date(undefined, 'default');
|
|
261
261
|
switch (sectionType) {
|
|
262
262
|
// We can't use `changeSectionValueFormat`, because `utils.parse('1', 'YYYY')` returns `1971` instead of `1`.
|
|
263
263
|
case 'year':
|
|
264
264
|
{
|
|
265
|
-
if (isFourDigitYearFormat(utils,
|
|
265
|
+
if (isFourDigitYearFormat(utils, format)) {
|
|
266
266
|
const formatted0001 = utils.formatByString(utils.setYear(now, 1), format);
|
|
267
267
|
return formatted0001 === '0001';
|
|
268
268
|
}
|
|
@@ -372,7 +372,7 @@ const getSectionsBoundaries = (utils, localizedDigits, timezone) => {
|
|
|
372
372
|
format
|
|
373
373
|
}) => ({
|
|
374
374
|
minimum: 0,
|
|
375
|
-
maximum: isFourDigitYearFormat(utils,
|
|
375
|
+
maximum: isFourDigitYearFormat(utils, format) ? 9999 : 99
|
|
376
376
|
}),
|
|
377
377
|
month: () => ({
|
|
378
378
|
minimum: 1,
|
|
@@ -391,7 +391,7 @@ const getSectionsBoundaries = (utils, localizedDigits, timezone) => {
|
|
|
391
391
|
contentType
|
|
392
392
|
}) => {
|
|
393
393
|
if (contentType === 'digit') {
|
|
394
|
-
const daysInWeek = getDaysInWeekStr(utils,
|
|
394
|
+
const daysInWeek = getDaysInWeekStr(utils, format).map(Number);
|
|
395
395
|
return {
|
|
396
396
|
minimum: Math.min(...daysInWeek),
|
|
397
397
|
maximum: Math.max(...daysInWeek)
|
|
@@ -459,7 +459,7 @@ const validateSections = (sections, valueType) => {
|
|
|
459
459
|
}
|
|
460
460
|
};
|
|
461
461
|
exports.validateSections = validateSections;
|
|
462
|
-
const transferDateSectionValue = (utils,
|
|
462
|
+
const transferDateSectionValue = (utils, section, dateToTransferFrom, dateToTransferTo) => {
|
|
463
463
|
switch (section.type) {
|
|
464
464
|
case 'year':
|
|
465
465
|
{
|
|
@@ -471,7 +471,7 @@ const transferDateSectionValue = (utils, timezone, section, dateToTransferFrom,
|
|
|
471
471
|
}
|
|
472
472
|
case 'weekDay':
|
|
473
473
|
{
|
|
474
|
-
const formattedDaysInWeek = getDaysInWeekStr(utils,
|
|
474
|
+
const formattedDaysInWeek = getDaysInWeekStr(utils, section.format);
|
|
475
475
|
const dayInWeekStrOfActiveDate = utils.formatByString(dateToTransferFrom, section.format);
|
|
476
476
|
const dayInWeekOfActiveDate = formattedDaysInWeek.indexOf(dayInWeekStrOfActiveDate);
|
|
477
477
|
const dayInWeekOfNewSectionValue = formattedDaysInWeek.indexOf(section.value);
|
|
@@ -523,11 +523,11 @@ const reliableSectionModificationOrder = {
|
|
|
523
523
|
meridiem: 8,
|
|
524
524
|
empty: 9
|
|
525
525
|
};
|
|
526
|
-
const mergeDateIntoReferenceDate = (utils,
|
|
526
|
+
const mergeDateIntoReferenceDate = (utils, dateToTransferFrom, sections, referenceDate, shouldLimitToEditedSections) =>
|
|
527
527
|
// cloning sections before sort to avoid mutating it
|
|
528
528
|
[...sections].sort((a, b) => reliableSectionModificationOrder[a.type] - reliableSectionModificationOrder[b.type]).reduce((mergedDate, section) => {
|
|
529
529
|
if (!shouldLimitToEditedSections || section.modified) {
|
|
530
|
-
return transferDateSectionValue(utils,
|
|
530
|
+
return transferDateSectionValue(utils, section, dateToTransferFrom, mergedDate);
|
|
531
531
|
}
|
|
532
532
|
return mergedDate;
|
|
533
533
|
}, referenceDate);
|
|
@@ -206,7 +206,7 @@ const useFieldCharacterEditing = ({
|
|
|
206
206
|
// When editing a letter-format month and the user presses a digit,
|
|
207
207
|
// We can support the numeric editing by using the digit-format month and re-formatting the result.
|
|
208
208
|
if (activeSection.type === 'month') {
|
|
209
|
-
const hasLeadingZerosInFormat = (0, _useField.doesSectionFormatHaveLeadingZeros)(utils,
|
|
209
|
+
const hasLeadingZerosInFormat = (0, _useField.doesSectionFormatHaveLeadingZeros)(utils, 'digit', 'month', 'MM');
|
|
210
210
|
const response = getNewSectionValue(queryValue, {
|
|
211
211
|
type: activeSection.type,
|
|
212
212
|
format: 'MM',
|
|
@@ -231,7 +231,7 @@ const useFieldCharacterEditing = ({
|
|
|
231
231
|
if (isQueryResponseWithoutValue(response)) {
|
|
232
232
|
return response;
|
|
233
233
|
}
|
|
234
|
-
const formattedValue = (0, _useField.getDaysInWeekStr)(utils,
|
|
234
|
+
const formattedValue = (0, _useField.getDaysInWeekStr)(utils, activeSection.format)[Number(response.sectionValue) - 1];
|
|
235
235
|
return (0, _extends2.default)({}, response, {
|
|
236
236
|
sectionValue: formattedValue
|
|
237
237
|
});
|
|
@@ -56,7 +56,6 @@ const useFieldState = params => {
|
|
|
56
56
|
const sectionsValueBoundaries = React.useMemo(() => (0, _useField.getSectionsBoundaries)(utils, localizedDigits, timezone), [utils, localizedDigits, timezone]);
|
|
57
57
|
const getSectionsFromValue = React.useCallback((value, fallbackSections = null) => fieldValueManager.getSectionsFromValue(utils, value, fallbackSections, date => (0, _buildSectionsFromFormat.buildSectionsFromFormat)({
|
|
58
58
|
utils,
|
|
59
|
-
timezone,
|
|
60
59
|
localeText: translations,
|
|
61
60
|
localizedDigits,
|
|
62
61
|
format,
|
|
@@ -65,7 +64,7 @@ const useFieldState = params => {
|
|
|
65
64
|
shouldRespectLeadingZeros,
|
|
66
65
|
enableAccessibleFieldDOMStructure,
|
|
67
66
|
isRtl
|
|
68
|
-
})), [fieldValueManager, format, translations, localizedDigits, isRtl, shouldRespectLeadingZeros, utils, formatDensity,
|
|
67
|
+
})), [fieldValueManager, format, translations, localizedDigits, isRtl, shouldRespectLeadingZeros, utils, formatDensity, enableAccessibleFieldDOMStructure]);
|
|
69
68
|
const [state, setState] = React.useState(() => {
|
|
70
69
|
const sections = getSectionsFromValue(valueFromTheOutside);
|
|
71
70
|
(0, _useField.validateSections)(sections, valueType);
|
|
@@ -162,7 +161,6 @@ const useFieldState = params => {
|
|
|
162
161
|
}
|
|
163
162
|
const sections = (0, _buildSectionsFromFormat.buildSectionsFromFormat)({
|
|
164
163
|
utils,
|
|
165
|
-
timezone,
|
|
166
164
|
localeText: translations,
|
|
167
165
|
localizedDigits,
|
|
168
166
|
format,
|
|
@@ -172,7 +170,7 @@ const useFieldState = params => {
|
|
|
172
170
|
enableAccessibleFieldDOMStructure,
|
|
173
171
|
isRtl
|
|
174
172
|
});
|
|
175
|
-
return (0, _useField.mergeDateIntoReferenceDate)(utils,
|
|
173
|
+
return (0, _useField.mergeDateIntoReferenceDate)(utils, date, sections, referenceDate, false);
|
|
176
174
|
};
|
|
177
175
|
const newValue = fieldValueManager.parseValueStr(valueStr, state.referenceValue, parseDateStr);
|
|
178
176
|
const newReferenceValue = fieldValueManager.updateReferenceValue(utils, newValue, state.referenceValue);
|
|
@@ -210,7 +208,7 @@ const useFieldState = params => {
|
|
|
210
208
|
* This makes sure that we don't lose some information of the initial date (like the time on a date field).
|
|
211
209
|
*/
|
|
212
210
|
if (newActiveDate != null && utils.isValid(newActiveDate)) {
|
|
213
|
-
const mergedDate = (0, _useField.mergeDateIntoReferenceDate)(utils,
|
|
211
|
+
const mergedDate = (0, _useField.mergeDateIntoReferenceDate)(utils, newActiveDate, newActiveDateSections, activeDateManager.referenceDate, true);
|
|
214
212
|
values = activeDateManager.getNewValuesFromNewActiveDate(mergedDate);
|
|
215
213
|
shouldPublish = true;
|
|
216
214
|
} else {
|