@mui/x-date-pickers 6.18.6 → 6.19.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/AdapterDateFns/AdapterDateFns.d.ts +3 -24
- package/AdapterDateFns/AdapterDateFns.js +11 -272
- package/AdapterDateFnsBase/AdapterDateFnsBase.d.ts +65 -0
- package/AdapterDateFnsBase/AdapterDateFnsBase.js +308 -0
- package/AdapterDateFnsBase/index.d.ts +1 -0
- package/AdapterDateFnsBase/index.js +1 -0
- package/AdapterDateFnsBase/package.json +6 -0
- package/AdapterDateFnsV3/AdapterDateFnsV3.d.ts +88 -0
- package/AdapterDateFnsV3/AdapterDateFnsV3.js +357 -0
- package/AdapterDateFnsV3/index.d.ts +1 -0
- package/AdapterDateFnsV3/index.js +1 -0
- package/AdapterDateFnsV3/package.json +6 -0
- package/AdapterLuxon/AdapterLuxon.d.ts +32 -32
- package/CHANGELOG.md +85 -1
- package/DateCalendar/DateCalendar.js +6 -4
- package/DateCalendar/DateCalendar.types.d.ts +0 -8
- package/DigitalClock/DigitalClock.js +3 -2
- package/MultiSectionDigitalClock/MultiSectionDigitalClock.js +9 -13
- package/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +8 -12
- package/TimeClock/TimeClock.js +3 -2
- package/hooks/useClearableField.d.ts +1 -1
- package/hooks/useClearableField.js +3 -3
- package/index.js +1 -1
- package/internals/hooks/useViews.d.ts +4 -4
- package/internals/hooks/useViews.js +13 -13
- package/internals/models/helpers.d.ts +1 -0
- package/internals/models/props/clock.d.ts +0 -9
- package/legacy/AdapterDateFns/AdapterDateFns.js +278 -528
- package/legacy/AdapterDateFnsBase/AdapterDateFnsBase.js +308 -0
- package/legacy/AdapterDateFnsBase/index.js +1 -0
- package/legacy/AdapterDateFnsV3/AdapterDateFnsV3.js +376 -0
- package/legacy/AdapterDateFnsV3/index.js +1 -0
- package/legacy/DateCalendar/DateCalendar.js +6 -4
- package/legacy/DigitalClock/DigitalClock.js +3 -2
- package/legacy/MultiSectionDigitalClock/MultiSectionDigitalClock.js +9 -13
- package/legacy/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +8 -12
- package/legacy/TimeClock/TimeClock.js +3 -2
- package/legacy/hooks/useClearableField.js +3 -3
- package/legacy/index.js +1 -1
- package/legacy/internals/hooks/useViews.js +13 -13
- package/legacy/locales/index.js +1 -0
- package/locales/index.d.ts +1 -0
- package/locales/index.js +1 -0
- package/modern/AdapterDateFns/AdapterDateFns.js +11 -271
- package/modern/AdapterDateFnsBase/AdapterDateFnsBase.js +307 -0
- package/modern/AdapterDateFnsBase/index.js +1 -0
- package/modern/AdapterDateFnsV3/AdapterDateFnsV3.js +357 -0
- package/modern/AdapterDateFnsV3/index.js +1 -0
- package/modern/DateCalendar/DateCalendar.js +6 -4
- package/modern/DigitalClock/DigitalClock.js +3 -2
- package/modern/MultiSectionDigitalClock/MultiSectionDigitalClock.js +9 -13
- package/modern/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +8 -12
- package/modern/TimeClock/TimeClock.js +3 -2
- package/modern/hooks/useClearableField.js +3 -3
- package/modern/index.js +1 -1
- package/modern/internals/hooks/useViews.js +13 -13
- package/modern/locales/index.js +1 -0
- package/node/AdapterDateFns/AdapterDateFns.js +11 -271
- package/node/AdapterDateFnsBase/AdapterDateFnsBase.js +315 -0
- package/node/AdapterDateFnsBase/index.js +12 -0
- package/node/AdapterDateFnsV3/AdapterDateFnsV3.js +366 -0
- package/node/AdapterDateFnsV3/index.js +12 -0
- package/node/DateCalendar/DateCalendar.js +6 -4
- package/node/DigitalClock/DigitalClock.js +3 -2
- package/node/MultiSectionDigitalClock/MultiSectionDigitalClock.js +9 -13
- package/node/MultiSectionDigitalClock/MultiSectionDigitalClockSection.js +8 -12
- package/node/TimeClock/TimeClock.js +3 -2
- package/node/hooks/useClearableField.js +3 -3
- package/node/index.js +1 -1
- package/node/internals/hooks/useViews.js +13 -13
- package/node/locales/index.js +11 -0
- package/package.json +2 -2
|
@@ -125,7 +125,7 @@ export const MultiSectionDigitalClock = /*#__PURE__*/React.forwardRef(function M
|
|
|
125
125
|
}, [ampm, inViews]);
|
|
126
126
|
const {
|
|
127
127
|
view,
|
|
128
|
-
|
|
128
|
+
setValueAndGoToNextView,
|
|
129
129
|
focusedView
|
|
130
130
|
} = useViews({
|
|
131
131
|
view: inView,
|
|
@@ -137,7 +137,7 @@ export const MultiSectionDigitalClock = /*#__PURE__*/React.forwardRef(function M
|
|
|
137
137
|
onFocusedViewChange
|
|
138
138
|
});
|
|
139
139
|
const handleMeridiemValueChange = useEventCallback(newValue => {
|
|
140
|
-
|
|
140
|
+
setValueAndGoToNextView(newValue, 'finish', 'meridiem');
|
|
141
141
|
});
|
|
142
142
|
const {
|
|
143
143
|
meridiemMode,
|
|
@@ -221,11 +221,6 @@ export const MultiSectionDigitalClock = /*#__PURE__*/React.forwardRef(function M
|
|
|
221
221
|
throw new Error('not supported');
|
|
222
222
|
}
|
|
223
223
|
}, [ampm, valueOrReferenceDate, disableIgnoringDatePartForTimeValidation, maxTime, meridiemMode, minTime, minutesStep, shouldDisableClock, shouldDisableTime, utils, disableFuture, disablePast, now, views]);
|
|
224
|
-
const handleSectionChange = useEventCallback((sectionView, newValue) => {
|
|
225
|
-
const viewIndex = views.indexOf(sectionView);
|
|
226
|
-
const nextView = views[viewIndex + 1];
|
|
227
|
-
setValueAndGoToView(newValue, nextView, sectionView);
|
|
228
|
-
});
|
|
229
224
|
const buildViewProps = React.useCallback(viewToBuild => {
|
|
230
225
|
switch (viewToBuild) {
|
|
231
226
|
case 'hours':
|
|
@@ -233,7 +228,7 @@ export const MultiSectionDigitalClock = /*#__PURE__*/React.forwardRef(function M
|
|
|
233
228
|
return {
|
|
234
229
|
onChange: hours => {
|
|
235
230
|
const valueWithMeridiem = convertValueToMeridiem(hours, meridiemMode, ampm);
|
|
236
|
-
|
|
231
|
+
setValueAndGoToNextView(utils.setHours(valueOrReferenceDate, valueWithMeridiem), 'finish', 'hours');
|
|
237
232
|
},
|
|
238
233
|
items: getHourSectionOptions({
|
|
239
234
|
now,
|
|
@@ -250,7 +245,7 @@ export const MultiSectionDigitalClock = /*#__PURE__*/React.forwardRef(function M
|
|
|
250
245
|
{
|
|
251
246
|
return {
|
|
252
247
|
onChange: minutes => {
|
|
253
|
-
|
|
248
|
+
setValueAndGoToNextView(utils.setMinutes(valueOrReferenceDate, minutes), 'finish', 'minutes');
|
|
254
249
|
},
|
|
255
250
|
items: getTimeSectionOptions({
|
|
256
251
|
value: utils.getMinutes(valueOrReferenceDate),
|
|
@@ -267,7 +262,7 @@ export const MultiSectionDigitalClock = /*#__PURE__*/React.forwardRef(function M
|
|
|
267
262
|
{
|
|
268
263
|
return {
|
|
269
264
|
onChange: seconds => {
|
|
270
|
-
|
|
265
|
+
setValueAndGoToNextView(utils.setSeconds(valueOrReferenceDate, seconds), 'finish', 'seconds');
|
|
271
266
|
},
|
|
272
267
|
items: getTimeSectionOptions({
|
|
273
268
|
value: utils.getSeconds(valueOrReferenceDate),
|
|
@@ -302,7 +297,7 @@ export const MultiSectionDigitalClock = /*#__PURE__*/React.forwardRef(function M
|
|
|
302
297
|
default:
|
|
303
298
|
throw new Error(`Unknown view: ${viewToBuild} found.`);
|
|
304
299
|
}
|
|
305
|
-
}, [now, value, ampm, utils, timeSteps.hours, timeSteps.minutes, timeSteps.seconds, localeText.hoursClockNumberText, localeText.minutesClockNumberText, localeText.secondsClockNumberText, meridiemMode,
|
|
300
|
+
}, [now, value, ampm, utils, timeSteps.hours, timeSteps.minutes, timeSteps.seconds, localeText.hoursClockNumberText, localeText.minutesClockNumberText, localeText.secondsClockNumberText, meridiemMode, setValueAndGoToNextView, valueOrReferenceDate, disabled, isTimeDisabled, handleMeridiemChange]);
|
|
306
301
|
const viewTimeOptions = React.useMemo(() => {
|
|
307
302
|
return views.reduce((result, currentView) => {
|
|
308
303
|
return _extends({}, result, {
|
|
@@ -412,8 +407,9 @@ process.env.NODE_ENV !== "production" ? MultiSectionDigitalClock.propTypes = {
|
|
|
412
407
|
minutesStep: PropTypes.number,
|
|
413
408
|
/**
|
|
414
409
|
* Callback fired when the value changes.
|
|
415
|
-
* @template
|
|
416
|
-
* @
|
|
410
|
+
* @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value.
|
|
411
|
+
* @template TView The view type. Will be one of date or time views.
|
|
412
|
+
* @param {TValue} value The new value.
|
|
417
413
|
* @param {PickerSelectionState | undefined} selectionState Indicates if the date selection is complete.
|
|
418
414
|
* @param {TView | undefined} selectedView Indicates the view in which the selection has been made.
|
|
419
415
|
*/
|
|
@@ -88,7 +88,7 @@ const MultiSectionDigitalClockSectionItem = styled(MenuItem, {
|
|
|
88
88
|
export const MultiSectionDigitalClockSection = /*#__PURE__*/React.forwardRef(function MultiSectionDigitalClockSection(inProps, ref) {
|
|
89
89
|
const containerRef = React.useRef(null);
|
|
90
90
|
const handleRef = useForkRef(ref, containerRef);
|
|
91
|
-
const
|
|
91
|
+
const previousActive = React.useRef(null);
|
|
92
92
|
const props = useThemeProps({
|
|
93
93
|
props: inProps,
|
|
94
94
|
name: 'MuiMultiSectionDigitalClockSection'
|
|
@@ -115,19 +115,15 @@ export const MultiSectionDigitalClockSection = /*#__PURE__*/React.forwardRef(fun
|
|
|
115
115
|
if (containerRef.current === null) {
|
|
116
116
|
return;
|
|
117
117
|
}
|
|
118
|
-
const
|
|
119
|
-
if (
|
|
120
|
-
|
|
121
|
-
if (previousSelected.current !== selectedItem) {
|
|
122
|
-
previousSelected.current = selectedItem;
|
|
123
|
-
}
|
|
124
|
-
return;
|
|
118
|
+
const activeItem = containerRef.current.querySelector('[role="option"][aria-selected="true"]');
|
|
119
|
+
if (active && autoFocus && activeItem) {
|
|
120
|
+
activeItem.focus();
|
|
125
121
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
selectedItem.focus();
|
|
122
|
+
if (!activeItem || previousActive.current === activeItem) {
|
|
123
|
+
return;
|
|
129
124
|
}
|
|
130
|
-
|
|
125
|
+
previousActive.current = activeItem;
|
|
126
|
+
const offsetTop = activeItem.offsetTop;
|
|
131
127
|
|
|
132
128
|
// Subtracting the 4px of extra margin intended for the first visible section item
|
|
133
129
|
containerRef.current.scrollTop = offsetTop - 4;
|
|
@@ -404,8 +404,9 @@ process.env.NODE_ENV !== "production" ? TimeClock.propTypes = {
|
|
|
404
404
|
minutesStep: PropTypes.number,
|
|
405
405
|
/**
|
|
406
406
|
* Callback fired when the value changes.
|
|
407
|
-
* @template
|
|
408
|
-
* @
|
|
407
|
+
* @template TValue The value type. Will be either the same type as `value` or `null`. Can be in `[start, end]` format in case of range value.
|
|
408
|
+
* @template TView The view type. Will be one of date or time views.
|
|
409
|
+
* @param {TValue} value The new value.
|
|
409
410
|
* @param {PickerSelectionState | undefined} selectionState Indicates if the date selection is complete.
|
|
410
411
|
* @param {TView | undefined} selectedView Indicates the view in which the selection has been made.
|
|
411
412
|
*/
|
|
@@ -39,8 +39,8 @@ export const useClearableField = ({
|
|
|
39
39
|
ownerState: {}
|
|
40
40
|
});
|
|
41
41
|
const InputProps = _extends({}, ForwardedInputProps, {
|
|
42
|
-
endAdornment:
|
|
43
|
-
children: [/*#__PURE__*/_jsx(InputAdornment, {
|
|
42
|
+
endAdornment: /*#__PURE__*/_jsxs(React.Fragment, {
|
|
43
|
+
children: [clearable && /*#__PURE__*/_jsx(InputAdornment, {
|
|
44
44
|
position: "end",
|
|
45
45
|
sx: {
|
|
46
46
|
marginRight: ForwardedInputProps?.endAdornment ? -1 : -1.5
|
|
@@ -52,7 +52,7 @@ export const useClearableField = ({
|
|
|
52
52
|
}, endClearIconProps))
|
|
53
53
|
}))
|
|
54
54
|
}), ForwardedInputProps?.endAdornment]
|
|
55
|
-
})
|
|
55
|
+
})
|
|
56
56
|
});
|
|
57
57
|
const fieldProps = _extends({}, forwardedFieldProps, {
|
|
58
58
|
sx: [{
|
package/modern/index.js
CHANGED
|
@@ -64,11 +64,12 @@ export function useViews({
|
|
|
64
64
|
onFocusedViewChange?.(viewToFocus, hasFocus);
|
|
65
65
|
});
|
|
66
66
|
const handleChangeView = useEventCallback(newView => {
|
|
67
|
+
// always keep the focused view in sync
|
|
68
|
+
handleFocusedViewChange(newView, true);
|
|
67
69
|
if (newView === view) {
|
|
68
70
|
return;
|
|
69
71
|
}
|
|
70
72
|
setView(newView);
|
|
71
|
-
handleFocusedViewChange(newView, true);
|
|
72
73
|
if (onViewChange) {
|
|
73
74
|
onViewChange(newView);
|
|
74
75
|
}
|
|
@@ -77,7 +78,6 @@ export function useViews({
|
|
|
77
78
|
if (nextView) {
|
|
78
79
|
handleChangeView(nextView);
|
|
79
80
|
}
|
|
80
|
-
handleFocusedViewChange(nextView, true);
|
|
81
81
|
});
|
|
82
82
|
const setValueAndGoToNextView = useEventCallback((value, currentViewSelectionState, selectedView) => {
|
|
83
83
|
const isSelectionFinishedOnCurrentView = currentViewSelectionState === 'finish';
|
|
@@ -86,18 +86,19 @@ export function useViews({
|
|
|
86
86
|
// but we it's not the final view given all `views` -> overall selection state should be `partial`.
|
|
87
87
|
views.indexOf(selectedView) < views.length - 1 : Boolean(nextView);
|
|
88
88
|
const globalSelectionState = isSelectionFinishedOnCurrentView && hasMoreViews ? 'partial' : currentViewSelectionState;
|
|
89
|
-
onChange(value, globalSelectionState);
|
|
90
|
-
if
|
|
89
|
+
onChange(value, globalSelectionState, selectedView);
|
|
90
|
+
// Detects if the selected view is not the active one.
|
|
91
|
+
// Can happen if multiple views are displayed, like in `DesktopDateTimePicker` or `MultiSectionDigitalClock`.
|
|
92
|
+
if (selectedView && selectedView !== view) {
|
|
93
|
+
const nextViewAfterSelected = views[views.indexOf(selectedView) + 1];
|
|
94
|
+
if (nextViewAfterSelected) {
|
|
95
|
+
// move to next view after the selected one
|
|
96
|
+
handleChangeView(nextViewAfterSelected);
|
|
97
|
+
}
|
|
98
|
+
} else if (isSelectionFinishedOnCurrentView) {
|
|
91
99
|
goToNextView();
|
|
92
100
|
}
|
|
93
101
|
});
|
|
94
|
-
const setValueAndGoToView = useEventCallback((value, newView, selectedView) => {
|
|
95
|
-
onChange(value, newView ? 'partial' : 'finish', selectedView);
|
|
96
|
-
if (newView) {
|
|
97
|
-
handleChangeView(newView);
|
|
98
|
-
handleFocusedViewChange(newView, true);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
102
|
return {
|
|
102
103
|
view,
|
|
103
104
|
setView: handleChangeView,
|
|
@@ -108,7 +109,6 @@ export function useViews({
|
|
|
108
109
|
// Always return up to date default view instead of the initial one (i.e. defaultView.current)
|
|
109
110
|
defaultView: views.includes(openTo) ? openTo : views[0],
|
|
110
111
|
goToNextView,
|
|
111
|
-
setValueAndGoToNextView
|
|
112
|
-
setValueAndGoToView
|
|
112
|
+
setValueAndGoToNextView
|
|
113
113
|
};
|
|
114
114
|
}
|
package/modern/locales/index.js
CHANGED
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.AdapterDateFns = void 0;
|
|
8
|
-
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
8
|
var _addDays = _interopRequireDefault(require("date-fns/addDays"));
|
|
10
9
|
var _addSeconds = _interopRequireDefault(require("date-fns/addSeconds"));
|
|
11
10
|
var _addMinutes = _interopRequireDefault(require("date-fns/addMinutes"));
|
|
@@ -62,206 +61,11 @@ var _formatISO = _interopRequireDefault(require("date-fns/formatISO"));
|
|
|
62
61
|
var _isWithinInterval = _interopRequireDefault(require("date-fns/isWithinInterval"));
|
|
63
62
|
var _enUS = _interopRequireDefault(require("date-fns/locale/en-US"));
|
|
64
63
|
var _longFormatters = _interopRequireDefault(require("date-fns/_lib/format/longFormatters"));
|
|
64
|
+
var _AdapterDateFnsBase = require("../AdapterDateFnsBase");
|
|
65
65
|
/* eslint-disable class-methods-use-this */
|
|
66
66
|
|
|
67
67
|
// @ts-ignore
|
|
68
68
|
|
|
69
|
-
const formatTokenMap = {
|
|
70
|
-
// Year
|
|
71
|
-
y: {
|
|
72
|
-
sectionType: 'year',
|
|
73
|
-
contentType: 'digit',
|
|
74
|
-
maxLength: 4
|
|
75
|
-
},
|
|
76
|
-
yy: 'year',
|
|
77
|
-
yyy: {
|
|
78
|
-
sectionType: 'year',
|
|
79
|
-
contentType: 'digit',
|
|
80
|
-
maxLength: 4
|
|
81
|
-
},
|
|
82
|
-
yyyy: 'year',
|
|
83
|
-
// Month
|
|
84
|
-
M: {
|
|
85
|
-
sectionType: 'month',
|
|
86
|
-
contentType: 'digit',
|
|
87
|
-
maxLength: 2
|
|
88
|
-
},
|
|
89
|
-
MM: 'month',
|
|
90
|
-
MMMM: {
|
|
91
|
-
sectionType: 'month',
|
|
92
|
-
contentType: 'letter'
|
|
93
|
-
},
|
|
94
|
-
MMM: {
|
|
95
|
-
sectionType: 'month',
|
|
96
|
-
contentType: 'letter'
|
|
97
|
-
},
|
|
98
|
-
L: {
|
|
99
|
-
sectionType: 'month',
|
|
100
|
-
contentType: 'digit',
|
|
101
|
-
maxLength: 2
|
|
102
|
-
},
|
|
103
|
-
LL: 'month',
|
|
104
|
-
LLL: {
|
|
105
|
-
sectionType: 'month',
|
|
106
|
-
contentType: 'letter'
|
|
107
|
-
},
|
|
108
|
-
LLLL: {
|
|
109
|
-
sectionType: 'month',
|
|
110
|
-
contentType: 'letter'
|
|
111
|
-
},
|
|
112
|
-
// Day of the month
|
|
113
|
-
d: {
|
|
114
|
-
sectionType: 'day',
|
|
115
|
-
contentType: 'digit',
|
|
116
|
-
maxLength: 2
|
|
117
|
-
},
|
|
118
|
-
dd: 'day',
|
|
119
|
-
do: {
|
|
120
|
-
sectionType: 'day',
|
|
121
|
-
contentType: 'digit-with-letter'
|
|
122
|
-
},
|
|
123
|
-
// Day of the week
|
|
124
|
-
E: {
|
|
125
|
-
sectionType: 'weekDay',
|
|
126
|
-
contentType: 'letter'
|
|
127
|
-
},
|
|
128
|
-
EE: {
|
|
129
|
-
sectionType: 'weekDay',
|
|
130
|
-
contentType: 'letter'
|
|
131
|
-
},
|
|
132
|
-
EEE: {
|
|
133
|
-
sectionType: 'weekDay',
|
|
134
|
-
contentType: 'letter'
|
|
135
|
-
},
|
|
136
|
-
EEEE: {
|
|
137
|
-
sectionType: 'weekDay',
|
|
138
|
-
contentType: 'letter'
|
|
139
|
-
},
|
|
140
|
-
EEEEE: {
|
|
141
|
-
sectionType: 'weekDay',
|
|
142
|
-
contentType: 'letter'
|
|
143
|
-
},
|
|
144
|
-
i: {
|
|
145
|
-
sectionType: 'weekDay',
|
|
146
|
-
contentType: 'digit',
|
|
147
|
-
maxLength: 1
|
|
148
|
-
},
|
|
149
|
-
ii: 'weekDay',
|
|
150
|
-
iii: {
|
|
151
|
-
sectionType: 'weekDay',
|
|
152
|
-
contentType: 'letter'
|
|
153
|
-
},
|
|
154
|
-
iiii: {
|
|
155
|
-
sectionType: 'weekDay',
|
|
156
|
-
contentType: 'letter'
|
|
157
|
-
},
|
|
158
|
-
e: {
|
|
159
|
-
sectionType: 'weekDay',
|
|
160
|
-
contentType: 'digit',
|
|
161
|
-
maxLength: 1
|
|
162
|
-
},
|
|
163
|
-
ee: 'weekDay',
|
|
164
|
-
eee: {
|
|
165
|
-
sectionType: 'weekDay',
|
|
166
|
-
contentType: 'letter'
|
|
167
|
-
},
|
|
168
|
-
eeee: {
|
|
169
|
-
sectionType: 'weekDay',
|
|
170
|
-
contentType: 'letter'
|
|
171
|
-
},
|
|
172
|
-
eeeee: {
|
|
173
|
-
sectionType: 'weekDay',
|
|
174
|
-
contentType: 'letter'
|
|
175
|
-
},
|
|
176
|
-
eeeeee: {
|
|
177
|
-
sectionType: 'weekDay',
|
|
178
|
-
contentType: 'letter'
|
|
179
|
-
},
|
|
180
|
-
c: {
|
|
181
|
-
sectionType: 'weekDay',
|
|
182
|
-
contentType: 'digit',
|
|
183
|
-
maxLength: 1
|
|
184
|
-
},
|
|
185
|
-
cc: 'weekDay',
|
|
186
|
-
ccc: {
|
|
187
|
-
sectionType: 'weekDay',
|
|
188
|
-
contentType: 'letter'
|
|
189
|
-
},
|
|
190
|
-
cccc: {
|
|
191
|
-
sectionType: 'weekDay',
|
|
192
|
-
contentType: 'letter'
|
|
193
|
-
},
|
|
194
|
-
ccccc: {
|
|
195
|
-
sectionType: 'weekDay',
|
|
196
|
-
contentType: 'letter'
|
|
197
|
-
},
|
|
198
|
-
cccccc: {
|
|
199
|
-
sectionType: 'weekDay',
|
|
200
|
-
contentType: 'letter'
|
|
201
|
-
},
|
|
202
|
-
// Meridiem
|
|
203
|
-
a: 'meridiem',
|
|
204
|
-
aa: 'meridiem',
|
|
205
|
-
aaa: 'meridiem',
|
|
206
|
-
// Hours
|
|
207
|
-
H: {
|
|
208
|
-
sectionType: 'hours',
|
|
209
|
-
contentType: 'digit',
|
|
210
|
-
maxLength: 2
|
|
211
|
-
},
|
|
212
|
-
HH: 'hours',
|
|
213
|
-
h: {
|
|
214
|
-
sectionType: 'hours',
|
|
215
|
-
contentType: 'digit',
|
|
216
|
-
maxLength: 2
|
|
217
|
-
},
|
|
218
|
-
hh: 'hours',
|
|
219
|
-
// Minutes
|
|
220
|
-
m: {
|
|
221
|
-
sectionType: 'minutes',
|
|
222
|
-
contentType: 'digit',
|
|
223
|
-
maxLength: 2
|
|
224
|
-
},
|
|
225
|
-
mm: 'minutes',
|
|
226
|
-
// Seconds
|
|
227
|
-
s: {
|
|
228
|
-
sectionType: 'seconds',
|
|
229
|
-
contentType: 'digit',
|
|
230
|
-
maxLength: 2
|
|
231
|
-
},
|
|
232
|
-
ss: 'seconds'
|
|
233
|
-
};
|
|
234
|
-
const defaultFormats = {
|
|
235
|
-
year: 'yyyy',
|
|
236
|
-
month: 'LLLL',
|
|
237
|
-
monthShort: 'MMM',
|
|
238
|
-
dayOfMonth: 'd',
|
|
239
|
-
weekday: 'EEEE',
|
|
240
|
-
weekdayShort: 'EEEEEE',
|
|
241
|
-
hours24h: 'HH',
|
|
242
|
-
hours12h: 'hh',
|
|
243
|
-
meridiem: 'aa',
|
|
244
|
-
minutes: 'mm',
|
|
245
|
-
seconds: 'ss',
|
|
246
|
-
fullDate: 'PP',
|
|
247
|
-
fullDateWithWeekday: 'PPPP',
|
|
248
|
-
keyboardDate: 'P',
|
|
249
|
-
shortDate: 'MMM d',
|
|
250
|
-
normalDate: 'd MMMM',
|
|
251
|
-
normalDateWithWeekday: 'EEE, MMM d',
|
|
252
|
-
monthAndYear: 'LLLL yyyy',
|
|
253
|
-
monthAndDate: 'MMMM d',
|
|
254
|
-
fullTime: 'p',
|
|
255
|
-
fullTime12h: 'hh:mm aa',
|
|
256
|
-
fullTime24h: 'HH:mm',
|
|
257
|
-
fullDateTime: 'PP p',
|
|
258
|
-
fullDateTime12h: 'PP hh:mm aa',
|
|
259
|
-
fullDateTime24h: 'PP HH:mm',
|
|
260
|
-
keyboardDateTime: 'P p',
|
|
261
|
-
keyboardDateTime12h: 'P hh:mm aa',
|
|
262
|
-
keyboardDateTime24h: 'P HH:mm'
|
|
263
|
-
};
|
|
264
|
-
|
|
265
69
|
/**
|
|
266
70
|
* Based on `@date-io/date-fns`
|
|
267
71
|
*
|
|
@@ -287,42 +91,19 @@ const defaultFormats = {
|
|
|
287
91
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
288
92
|
* SOFTWARE.
|
|
289
93
|
*/
|
|
290
|
-
class AdapterDateFns {
|
|
94
|
+
class AdapterDateFns extends _AdapterDateFnsBase.AdapterDateFnsBase {
|
|
291
95
|
constructor({
|
|
292
|
-
locale
|
|
96
|
+
locale,
|
|
293
97
|
formats
|
|
294
98
|
} = {}) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
end: "'"
|
|
304
|
-
};
|
|
305
|
-
this.date = value => {
|
|
306
|
-
if (typeof value === 'undefined') {
|
|
307
|
-
return new Date();
|
|
308
|
-
}
|
|
309
|
-
if (value === null) {
|
|
310
|
-
return null;
|
|
311
|
-
}
|
|
312
|
-
return new Date(value);
|
|
313
|
-
};
|
|
314
|
-
this.dateWithTimezone = value => {
|
|
315
|
-
return this.date(value);
|
|
316
|
-
};
|
|
317
|
-
this.getTimezone = () => {
|
|
318
|
-
return 'default';
|
|
319
|
-
};
|
|
320
|
-
this.setTimezone = value => {
|
|
321
|
-
return value;
|
|
322
|
-
};
|
|
323
|
-
this.toJsDate = value => {
|
|
324
|
-
return value;
|
|
325
|
-
};
|
|
99
|
+
if (typeof _addDays.default !== 'function') {
|
|
100
|
+
throw new Error(['MUI: The `date-fns` package v3.x is not compatible with this adapter.', 'Please, install v2.x of the package or use the `AdapterDateFnsV3` instead.'].join('\n'));
|
|
101
|
+
}
|
|
102
|
+
super({
|
|
103
|
+
locale: locale ?? _enUS.default,
|
|
104
|
+
formats,
|
|
105
|
+
longFormatters: _longFormatters.default
|
|
106
|
+
});
|
|
326
107
|
this.parseISO = isoString => {
|
|
327
108
|
return (0, _parseISO.default)(isoString);
|
|
328
109
|
};
|
|
@@ -339,39 +120,6 @@ class AdapterDateFns {
|
|
|
339
120
|
locale: this.locale
|
|
340
121
|
});
|
|
341
122
|
};
|
|
342
|
-
this.getCurrentLocaleCode = () => {
|
|
343
|
-
return this.locale?.code || 'en-US';
|
|
344
|
-
};
|
|
345
|
-
// Note: date-fns input types are more lenient than this adapter, so we need to expose our more
|
|
346
|
-
// strict signature and delegate to the more lenient signature. Otherwise, we have downstream type errors upon usage.
|
|
347
|
-
this.is12HourCycleInCurrentLocale = () => {
|
|
348
|
-
if (this.locale) {
|
|
349
|
-
return /a/.test(this.locale.formatLong.time());
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
// By default, date-fns is using en-US locale with am/pm enabled
|
|
353
|
-
return true;
|
|
354
|
-
};
|
|
355
|
-
this.expandFormat = format => {
|
|
356
|
-
const longFormatRegexp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
|
|
357
|
-
|
|
358
|
-
// @see https://github.com/date-fns/date-fns/blob/master/src/format/index.js#L31
|
|
359
|
-
return format.match(longFormatRegexp).map(token => {
|
|
360
|
-
const firstCharacter = token[0];
|
|
361
|
-
if (firstCharacter === 'p' || firstCharacter === 'P') {
|
|
362
|
-
const longFormatter = _longFormatters.default[firstCharacter];
|
|
363
|
-
const locale = this.locale || _enUS.default;
|
|
364
|
-
return longFormatter(token, locale.formatLong, {});
|
|
365
|
-
}
|
|
366
|
-
return token;
|
|
367
|
-
}).join('');
|
|
368
|
-
};
|
|
369
|
-
this.getFormatHelperText = format => {
|
|
370
|
-
return this.expandFormat(format).replace(/(aaa|aa|a)/g, '(a|p)m').toLocaleLowerCase();
|
|
371
|
-
};
|
|
372
|
-
this.isNull = value => {
|
|
373
|
-
return value === null;
|
|
374
|
-
};
|
|
375
123
|
this.isValid = value => {
|
|
376
124
|
return (0, _isValid.default)(this.date(value));
|
|
377
125
|
};
|
|
@@ -383,9 +131,6 @@ class AdapterDateFns {
|
|
|
383
131
|
locale: this.locale
|
|
384
132
|
});
|
|
385
133
|
};
|
|
386
|
-
this.formatNumber = numberToFormat => {
|
|
387
|
-
return numberToFormat;
|
|
388
|
-
};
|
|
389
134
|
this.getDiff = (value, comparing, unit) => {
|
|
390
135
|
switch (unit) {
|
|
391
136
|
case 'years':
|
|
@@ -610,11 +355,6 @@ class AdapterDateFns {
|
|
|
610
355
|
}
|
|
611
356
|
return years;
|
|
612
357
|
};
|
|
613
|
-
this.getMeridiemText = ampm => {
|
|
614
|
-
return ampm === 'am' ? 'AM' : 'PM';
|
|
615
|
-
};
|
|
616
|
-
this.locale = _locale;
|
|
617
|
-
this.formats = (0, _extends2.default)({}, defaultFormats, formats);
|
|
618
358
|
}
|
|
619
359
|
}
|
|
620
360
|
exports.AdapterDateFns = AdapterDateFns;
|