@mui/x-date-pickers 7.0.0-alpha.7 → 7.0.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/AdapterDateFns/AdapterDateFns.d.ts +4 -21
  2. package/AdapterDateFns/AdapterDateFns.js +11 -255
  3. package/AdapterDateFnsBase/AdapterDateFnsBase.d.ts +62 -0
  4. package/AdapterDateFnsBase/AdapterDateFnsBase.js +291 -0
  5. package/AdapterDateFnsBase/index.d.ts +1 -0
  6. package/AdapterDateFnsBase/index.js +1 -0
  7. package/AdapterDateFnsBase/package.json +6 -0
  8. package/AdapterDateFnsJalali/AdapterDateFnsJalali.d.ts +1 -0
  9. package/AdapterDateFnsV3/AdapterDateFnsV3.d.ts +80 -0
  10. package/AdapterDateFnsV3/AdapterDateFnsV3.js +287 -0
  11. package/AdapterDateFnsV3/index.d.ts +1 -0
  12. package/AdapterDateFnsV3/index.js +1 -0
  13. package/AdapterDateFnsV3/package.json +6 -0
  14. package/CHANGELOG.md +175 -49
  15. package/DatePicker/DatePickerToolbar.d.ts +2 -2
  16. package/DatePicker/DatePickerToolbar.js +2 -7
  17. package/DigitalClock/DigitalClock.js +1 -0
  18. package/DigitalClock/DigitalClock.types.d.ts +5 -0
  19. package/LocalizationProvider/LocalizationProvider.js +1 -1
  20. package/MultiSectionDigitalClock/MultiSectionDigitalClock.js +1 -0
  21. package/MultiSectionDigitalClock/MultiSectionDigitalClock.types.d.ts +5 -0
  22. package/PickersSectionList/PickersSectionList.js +1 -1
  23. package/TimeClock/TimeClock.js +1 -0
  24. package/TimeClock/TimeClock.types.d.ts +5 -0
  25. package/hooks/useClearableField.js +3 -3
  26. package/index.js +1 -1
  27. package/internals/components/PickersInput/PickersInput.d.ts +2 -4
  28. package/internals/components/PickersInput/PickersInput.js +2 -3
  29. package/internals/hooks/useField/useField.utils.js +5 -5
  30. package/internals/hooks/usePicker/index.d.ts +1 -1
  31. package/internals/hooks/usePicker/usePickerValue.js +2 -2
  32. package/internals/hooks/useUtils.js +2 -2
  33. package/internals/hooks/useViews.js +2 -2
  34. package/internals/index.d.ts +9 -3
  35. package/internals/index.js +6 -2
  36. package/internals/models/common.d.ts +1 -1
  37. package/internals/models/helpers.d.ts +1 -0
  38. package/internals/utils/views.js +1 -1
  39. package/legacy/AdapterDateFns/AdapterDateFns.js +222 -458
  40. package/legacy/AdapterDateFnsBase/AdapterDateFnsBase.js +293 -0
  41. package/legacy/AdapterDateFnsBase/index.js +1 -0
  42. package/legacy/AdapterDateFnsV3/AdapterDateFnsV3.js +306 -0
  43. package/legacy/AdapterDateFnsV3/index.js +1 -0
  44. package/legacy/AdapterMomentHijri/AdapterMomentHijri.js +5 -6
  45. package/legacy/AdapterMomentJalaali/AdapterMomentJalaali.js +5 -6
  46. package/legacy/DatePicker/DatePickerToolbar.js +2 -7
  47. package/legacy/DigitalClock/DigitalClock.js +1 -0
  48. package/legacy/LocalizationProvider/LocalizationProvider.js +1 -1
  49. package/legacy/MultiSectionDigitalClock/MultiSectionDigitalClock.js +1 -0
  50. package/legacy/PickersSectionList/PickersSectionList.js +1 -1
  51. package/legacy/TimeClock/TimeClock.js +1 -0
  52. package/legacy/hooks/useClearableField.js +3 -3
  53. package/legacy/index.js +1 -1
  54. package/legacy/internals/components/PickersInput/PickersInput.js +2 -3
  55. package/legacy/internals/hooks/useField/useField.utils.js +5 -5
  56. package/legacy/internals/hooks/usePicker/usePickerValue.js +2 -2
  57. package/legacy/internals/hooks/useUtils.js +2 -2
  58. package/legacy/internals/hooks/useViews.js +2 -2
  59. package/legacy/internals/index.js +6 -2
  60. package/legacy/internals/utils/views.js +1 -1
  61. package/legacy/locales/index.js +1 -0
  62. package/locales/enUS.d.ts +1 -1
  63. package/locales/index.d.ts +1 -0
  64. package/locales/index.js +1 -0
  65. package/locales/mk.d.ts +1 -1
  66. package/locales/utils/getPickersLocalization.d.ts +1 -1
  67. package/modern/AdapterDateFns/AdapterDateFns.js +11 -254
  68. package/modern/AdapterDateFnsBase/AdapterDateFnsBase.js +290 -0
  69. package/modern/AdapterDateFnsBase/index.js +1 -0
  70. package/modern/AdapterDateFnsV3/AdapterDateFnsV3.js +287 -0
  71. package/modern/AdapterDateFnsV3/index.js +1 -0
  72. package/modern/DatePicker/DatePickerToolbar.js +2 -7
  73. package/modern/DigitalClock/DigitalClock.js +1 -0
  74. package/modern/LocalizationProvider/LocalizationProvider.js +1 -1
  75. package/modern/MultiSectionDigitalClock/MultiSectionDigitalClock.js +1 -0
  76. package/modern/PickersSectionList/PickersSectionList.js +1 -1
  77. package/modern/TimeClock/TimeClock.js +1 -0
  78. package/modern/hooks/useClearableField.js +3 -3
  79. package/modern/index.js +1 -1
  80. package/modern/internals/components/PickersInput/PickersInput.js +2 -3
  81. package/modern/internals/hooks/useField/useField.utils.js +5 -5
  82. package/modern/internals/hooks/usePicker/usePickerValue.js +2 -2
  83. package/modern/internals/hooks/useUtils.js +2 -2
  84. package/modern/internals/hooks/useViews.js +2 -2
  85. package/modern/internals/index.js +6 -2
  86. package/modern/internals/utils/views.js +1 -1
  87. package/modern/locales/index.js +1 -0
  88. package/node/AdapterDateFns/AdapterDateFns.js +11 -254
  89. package/node/AdapterDateFnsBase/AdapterDateFnsBase.js +298 -0
  90. package/node/AdapterDateFnsBase/index.js +12 -0
  91. package/node/AdapterDateFnsV3/AdapterDateFnsV3.js +295 -0
  92. package/node/AdapterDateFnsV3/index.js +12 -0
  93. package/node/DatePicker/DatePickerToolbar.js +0 -4
  94. package/node/DigitalClock/DigitalClock.js +1 -0
  95. package/node/LocalizationProvider/LocalizationProvider.js +1 -1
  96. package/node/MultiSectionDigitalClock/MultiSectionDigitalClock.js +1 -0
  97. package/node/PickersSectionList/PickersSectionList.js +1 -1
  98. package/node/TimeClock/TimeClock.js +1 -0
  99. package/node/hooks/useClearableField.js +3 -3
  100. package/node/index.js +1 -1
  101. package/node/internals/components/PickersInput/PickersInput.js +2 -3
  102. package/node/internals/hooks/useField/useField.utils.js +5 -5
  103. package/node/internals/hooks/usePicker/usePickerValue.js +2 -2
  104. package/node/internals/hooks/useUtils.js +2 -2
  105. package/node/internals/hooks/useViews.js +2 -2
  106. package/node/internals/index.js +47 -1
  107. package/node/internals/utils/views.js +1 -1
  108. package/node/locales/index.js +11 -0
  109. package/package.json +2 -2
@@ -2,7 +2,6 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
3
  const _excluded = ["elements", "areAllSectionsEmpty", "defaultValue", "label", "value", "onChange", "id", "autoFocus", "endAdornment", "startAdornment", "renderSuffix", "slots", "contentEditable", "tabIndex", "onInput", "onPaste", "onKeyDown", "fullWidth", "inputProps", "inputRef", "sectionListRef"];
4
4
  import * as React from 'react';
5
- import Box from '@mui/material/Box';
6
5
  import { useFormControl } from '@mui/material/FormControl';
7
6
  import { styled } from '@mui/material/styles';
8
7
  import useForkRef from '@mui/utils/useForkRef';
@@ -14,7 +13,7 @@ import { Unstable_PickersSectionList as PickersSectionList, Unstable_PickersSect
14
13
  import { jsx as _jsx } from "react/jsx-runtime";
15
14
  import { jsxs as _jsxs } from "react/jsx-runtime";
16
15
  const round = value => Math.round(value * 1e5) / 1e5;
17
- export const PickersInputRoot = styled(Box, {
16
+ export const PickersInputRoot = styled('div', {
18
17
  name: 'MuiPickersInput',
19
18
  slot: 'Root',
20
19
  overridesResolver: (props, styles) => styles.root
@@ -160,7 +159,7 @@ export const PickersInput = /*#__PURE__*/React.forwardRef(function PickersInput(
160
159
  const handleInputRef = useForkRef(inputProps?.ref, inputRef);
161
160
  const muiFormControl = useFormControl();
162
161
  if (!muiFormControl) {
163
- throw new Error('MUI: PickersInput should always be used inside a PickersTextField component');
162
+ throw new Error('MUI X: PickersInput should always be used inside a PickersTextField component');
164
163
  }
165
164
  const handleInputFocus = event => {
166
165
  // Fix a bug with IE11 where the focus/blur events are triggered
@@ -3,7 +3,7 @@ import { getMonthsInYear } from '../../utils/date-utils';
3
3
  export const getDateSectionConfigFromFormatToken = (utils, formatToken) => {
4
4
  const config = utils.formatTokenMap[formatToken];
5
5
  if (config == null) {
6
- throw new Error([`MUI: The token "${formatToken}" is not supported by the Date and Time Pickers.`, 'Please try using another token or open an issue on https://github.com/mui/mui-x/issues/new/choose if you think it should be supported.'].join('\n'));
6
+ throw new Error([`MUI X: The token "${formatToken}" is not supported by the Date and Time Pickers.`, 'Please try using another token or open an issue on https://github.com/mui/mui-x/issues/new/choose if you think it should be supported.'].join('\n'));
7
7
  }
8
8
  if (typeof config === 'string') {
9
9
  return {
@@ -80,7 +80,7 @@ export const cleanLeadingZeros = (utils, valueStr, size) => {
80
80
  export const cleanDigitSectionValue = (utils, timezone, value, sectionBoundaries, section) => {
81
81
  if (process.env.NODE_ENV !== 'production') {
82
82
  if (section.type !== 'day' && section.contentType === 'digit-with-letter') {
83
- throw new Error([`MUI: The token "${section.format}" is a digit format with letter in it.'
83
+ throw new Error([`MUI X: The token "${section.format}" is a digit format with letter in it.'
84
84
  This type of format is only supported for 'day' sections`].join('\n'));
85
85
  }
86
86
  }
@@ -356,7 +356,7 @@ export const splitFormatIntoSections = (utils, timezone, localeText, format, dat
356
356
  maxLength = sectionValue === '' ? utils.formatByString(now, token).length : sectionValue.length;
357
357
  } else {
358
358
  if (sectionConfig.maxLength == null) {
359
- throw new Error(`MUI: The token ${token} should have a 'maxDigitNumber' property on it's adapter`);
359
+ throw new Error(`MUI X: The token ${token} should have a 'maxDigitNumber' property on it's adapter`);
360
360
  }
361
361
  maxLength = sectionConfig.maxLength;
362
362
  if (isValidDate) {
@@ -387,7 +387,7 @@ export const splitFormatIntoSections = (utils, timezone, localeText, format, dat
387
387
  nextFormat = utils.expandFormat(prevFormat);
388
388
  formatExpansionOverflow -= 1;
389
389
  if (formatExpansionOverflow < 0) {
390
- throw new Error('MUI: The format expansion seems to be enter in an infinite loop. Please open an issue with the format passed to the picker component');
390
+ throw new Error('MUI X: The format expansion seems to be enter in an infinite loop. Please open an issue with the format passed to the picker component.');
391
391
  }
392
392
  }
393
393
  const expandedFormat = nextFormat;
@@ -601,7 +601,7 @@ export const validateSections = (sections, valueType) => {
601
601
  }
602
602
  const invalidSection = sections.find(section => !supportedSections.includes(section.type));
603
603
  if (invalidSection) {
604
- console.warn(`MUI: The field component you are using is not compatible with the "${invalidSection.type}" date section.`, `The supported date sections are ["${supportedSections.join('", "')}"]\`.`);
604
+ console.warn(`MUI X: The field component you are using is not compatible with the "${invalidSection.type}" date section.`, `The supported date sections are ["${supportedSections.join('", "')}"]\`.`);
605
605
  warnedOnceInvalidSection = true;
606
606
  }
607
607
  }
@@ -138,12 +138,12 @@ export const usePickerValue = ({
138
138
  if (process.env.NODE_ENV !== 'production') {
139
139
  React.useEffect(() => {
140
140
  if (isControlled !== (inValue !== undefined)) {
141
- console.error([`MUI: A component is changing the ${isControlled ? '' : 'un'}controlled value of a picker to be ${isControlled ? 'un' : ''}controlled.`, 'Elements should not switch from uncontrolled to controlled (or vice versa).', `Decide between using a controlled or uncontrolled value` + 'for the lifetime of the component.', "The nature of the state is determined during the first render. It's considered controlled if the value is not `undefined`.", 'More info: https://fb.me/react-controlled-components'].join('\n'));
141
+ console.error([`MUI X: A component is changing the ${isControlled ? '' : 'un'}controlled value of a picker to be ${isControlled ? 'un' : ''}controlled.`, 'Elements should not switch from uncontrolled to controlled (or vice versa).', `Decide between using a controlled or uncontrolled value` + 'for the lifetime of the component.', "The nature of the state is determined during the first render. It's considered controlled if the value is not `undefined`.", 'More info: https://fb.me/react-controlled-components'].join('\n'));
142
142
  }
143
143
  }, [inValue]);
144
144
  React.useEffect(() => {
145
145
  if (!isControlled && defaultValue !== inDefaultValue) {
146
- console.error([`MUI: A component is changing the defaultValue of an uncontrolled picker after being initialized. ` + `To suppress this warning opt to use a controlled value.`].join('\n'));
146
+ console.error([`MUI X: A component is changing the defaultValue of an uncontrolled picker after being initialized. ` + `To suppress this warning opt to use a controlled value.`].join('\n'));
147
147
  }
148
148
  }, [JSON.stringify(defaultValue)]);
149
149
  }
@@ -5,10 +5,10 @@ import { DEFAULT_LOCALE } from '../../locales/enUS';
5
5
  export const useLocalizationContext = () => {
6
6
  const localization = React.useContext(MuiPickersAdapterContext);
7
7
  if (localization === null) {
8
- throw new Error(['MUI: Can not find the date and time pickers localization context.', 'It looks like you forgot to wrap your component in LocalizationProvider.', 'This can also happen if you are bundling multiple versions of the `@mui/x-date-pickers` package'].join('\n'));
8
+ throw new Error(['MUI X: Can not find the date and time pickers localization context.', 'It looks like you forgot to wrap your component in LocalizationProvider.', 'This can also happen if you are bundling multiple versions of the `@mui/x-date-pickers` package'].join('\n'));
9
9
  }
10
10
  if (localization.utils === null) {
11
- throw new Error(['MUI: Can not find the date and time pickers adapter from its localization context.', 'It looks like you forgot to pass a `dateAdapter` to your LocalizationProvider.'].join('\n'));
11
+ throw new Error(['MUI X: Can not find the date and time pickers adapter from its localization context.', 'It looks like you forgot to pass a `dateAdapter` to your LocalizationProvider.'].join('\n'));
12
12
  }
13
13
  const localeText = React.useMemo(() => _extends({}, DEFAULT_LOCALE, localization.localeText), [localization.localeText]);
14
14
  return React.useMemo(() => _extends({}, localization, {
@@ -15,11 +15,11 @@ export function useViews({
15
15
  if (process.env.NODE_ENV !== 'production') {
16
16
  if (!warnedOnceNotValidView) {
17
17
  if (inView != null && !views.includes(inView)) {
18
- console.warn(`MUI: \`view="${inView}"\` is not a valid prop.`, `It must be an element of \`views=["${views.join('", "')}"]\`.`);
18
+ console.warn(`MUI X: \`view="${inView}"\` is not a valid prop.`, `It must be an element of \`views=["${views.join('", "')}"]\`.`);
19
19
  warnedOnceNotValidView = true;
20
20
  }
21
21
  if (inView == null && openTo != null && !views.includes(openTo)) {
22
- console.warn(`MUI: \`openTo="${openTo}"\` is not a valid prop.`, `It must be an element of \`views=["${views.join('", "')}"]\`.`);
22
+ console.warn(`MUI X: \`openTo="${openTo}"\` is not a valid prop.`, `It must be an element of \`views=["${views.join('", "')}"]\`.`);
23
23
  warnedOnceNotValidView = true;
24
24
  }
25
25
  }
@@ -14,10 +14,12 @@ export { useField, createDateStrForInputFromSections, addPositionPropertiesToSec
14
14
  export { usePicker } from './hooks/usePicker';
15
15
  export { useStaticPicker } from './hooks/useStaticPicker';
16
16
  export { useLocalizationContext, useDefaultDates, useUtils, useLocaleText, useNow } from './hooks/useUtils';
17
+ export { useViews } from './hooks/useViews';
17
18
  export { useValidation } from './hooks/useValidation';
18
19
  export { usePreviousMonthDisabled, useNextMonthDisabled } from './hooks/date-helpers-hooks';
19
20
  export { convertFieldResponseIntoMuiTextFieldProps } from './utils/convertFieldResponseIntoMuiTextFieldProps';
20
- export { applyDefaultDate, replaceInvalidDateByNull, areDatesEqual, getTodayDate } from './utils/date-utils';
21
+ export { applyDefaultDate, replaceInvalidDateByNull, areDatesEqual, getTodayDate, isDatePickerView, mergeDateAndTime, formatMeridiem } from './utils/date-utils';
22
+ export { resolveTimeViewsResponse } from './utils/date-time-utils';
21
23
  export { splitFieldInternalAndForwardedProps } from './utils/fields';
22
24
  export { getDefaultReferenceDate } from './utils/getDefaultReferenceDate';
23
25
  export { executeInTheNextEventLoopTick, getActiveElement, onSpaceOrEnter, DEFAULT_DESKTOP_MODE_MEDIA_QUERY } from './utils/utils';
@@ -26,6 +28,8 @@ export { extractValidationProps } from './utils/validation/extractValidationProp
26
28
  export { validateDate } from './utils/validation/validateDate';
27
29
  export { validateDateTime } from './utils/validation/validateDateTime';
28
30
  export { validateTime } from './utils/validation/validateTime';
31
+ export { applyDefaultViewProps } from './utils/views';
29
32
  export { buildDeprecatedPropsWarning, buildWarning } from './utils/warning';
30
33
  export { DayCalendar } from '../DateCalendar/DayCalendar';
31
- export { useCalendarState } from '../DateCalendar/useCalendarState';
34
+ export { useCalendarState } from '../DateCalendar/useCalendarState';
35
+ export { isTimeView } from './utils/time-utils';
@@ -19,7 +19,7 @@ export const applyDefaultViewProps = ({
19
19
  } else if (viewsWithDefault.length > 0) {
20
20
  openToWithDefault = viewsWithDefault[0];
21
21
  } else {
22
- throw new Error('MUI: The `views` prop must contain at least one view');
22
+ throw new Error('MUI X: The `views` prop must contain at least one view.');
23
23
  }
24
24
  return {
25
25
  views: viewsWithDefault,
@@ -1,6 +1,7 @@
1
1
  export * from './beBY';
2
2
  export * from './caES';
3
3
  export * from './csCZ';
4
+ export * from './daDK';
4
5
  export * from './deDE';
5
6
  export * from './elGR';
6
7
  export * from './enUS';
@@ -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"));
@@ -50,200 +49,11 @@ var _startOfYear = _interopRequireDefault(require("date-fns/startOfYear"));
50
49
  var _isWithinInterval = _interopRequireDefault(require("date-fns/isWithinInterval"));
51
50
  var _enUS = _interopRequireDefault(require("date-fns/locale/en-US"));
52
51
  var _longFormatters = _interopRequireDefault(require("date-fns/_lib/format/longFormatters"));
52
+ var _AdapterDateFnsBase = require("../AdapterDateFnsBase");
53
53
  /* eslint-disable class-methods-use-this */
54
54
 
55
55
  // @ts-ignore
56
56
 
57
- const formatTokenMap = {
58
- // Year
59
- y: {
60
- sectionType: 'year',
61
- contentType: 'digit',
62
- maxLength: 4
63
- },
64
- yy: 'year',
65
- yyy: {
66
- sectionType: 'year',
67
- contentType: 'digit',
68
- maxLength: 4
69
- },
70
- yyyy: 'year',
71
- // Month
72
- M: {
73
- sectionType: 'month',
74
- contentType: 'digit',
75
- maxLength: 2
76
- },
77
- MM: 'month',
78
- MMMM: {
79
- sectionType: 'month',
80
- contentType: 'letter'
81
- },
82
- MMM: {
83
- sectionType: 'month',
84
- contentType: 'letter'
85
- },
86
- L: {
87
- sectionType: 'month',
88
- contentType: 'digit',
89
- maxLength: 2
90
- },
91
- LL: 'month',
92
- LLL: {
93
- sectionType: 'month',
94
- contentType: 'letter'
95
- },
96
- LLLL: {
97
- sectionType: 'month',
98
- contentType: 'letter'
99
- },
100
- // Day of the month
101
- d: {
102
- sectionType: 'day',
103
- contentType: 'digit',
104
- maxLength: 2
105
- },
106
- dd: 'day',
107
- do: {
108
- sectionType: 'day',
109
- contentType: 'digit-with-letter'
110
- },
111
- // Day of the week
112
- E: {
113
- sectionType: 'weekDay',
114
- contentType: 'letter'
115
- },
116
- EE: {
117
- sectionType: 'weekDay',
118
- contentType: 'letter'
119
- },
120
- EEE: {
121
- sectionType: 'weekDay',
122
- contentType: 'letter'
123
- },
124
- EEEE: {
125
- sectionType: 'weekDay',
126
- contentType: 'letter'
127
- },
128
- EEEEE: {
129
- sectionType: 'weekDay',
130
- contentType: 'letter'
131
- },
132
- i: {
133
- sectionType: 'weekDay',
134
- contentType: 'digit',
135
- maxLength: 1
136
- },
137
- ii: 'weekDay',
138
- iii: {
139
- sectionType: 'weekDay',
140
- contentType: 'letter'
141
- },
142
- iiii: {
143
- sectionType: 'weekDay',
144
- contentType: 'letter'
145
- },
146
- e: {
147
- sectionType: 'weekDay',
148
- contentType: 'digit',
149
- maxLength: 1
150
- },
151
- ee: 'weekDay',
152
- eee: {
153
- sectionType: 'weekDay',
154
- contentType: 'letter'
155
- },
156
- eeee: {
157
- sectionType: 'weekDay',
158
- contentType: 'letter'
159
- },
160
- eeeee: {
161
- sectionType: 'weekDay',
162
- contentType: 'letter'
163
- },
164
- eeeeee: {
165
- sectionType: 'weekDay',
166
- contentType: 'letter'
167
- },
168
- c: {
169
- sectionType: 'weekDay',
170
- contentType: 'digit',
171
- maxLength: 1
172
- },
173
- cc: 'weekDay',
174
- ccc: {
175
- sectionType: 'weekDay',
176
- contentType: 'letter'
177
- },
178
- cccc: {
179
- sectionType: 'weekDay',
180
- contentType: 'letter'
181
- },
182
- ccccc: {
183
- sectionType: 'weekDay',
184
- contentType: 'letter'
185
- },
186
- cccccc: {
187
- sectionType: 'weekDay',
188
- contentType: 'letter'
189
- },
190
- // Meridiem
191
- a: 'meridiem',
192
- aa: 'meridiem',
193
- aaa: 'meridiem',
194
- // Hours
195
- H: {
196
- sectionType: 'hours',
197
- contentType: 'digit',
198
- maxLength: 2
199
- },
200
- HH: 'hours',
201
- h: {
202
- sectionType: 'hours',
203
- contentType: 'digit',
204
- maxLength: 2
205
- },
206
- hh: 'hours',
207
- // Minutes
208
- m: {
209
- sectionType: 'minutes',
210
- contentType: 'digit',
211
- maxLength: 2
212
- },
213
- mm: 'minutes',
214
- // Seconds
215
- s: {
216
- sectionType: 'seconds',
217
- contentType: 'digit',
218
- maxLength: 2
219
- },
220
- ss: 'seconds'
221
- };
222
- const defaultFormats = {
223
- year: 'yyyy',
224
- month: 'LLLL',
225
- monthShort: 'MMM',
226
- dayOfMonth: 'd',
227
- weekday: 'EEEE',
228
- weekdayShort: 'EEEEEE',
229
- hours24h: 'HH',
230
- hours12h: 'hh',
231
- meridiem: 'aa',
232
- minutes: 'mm',
233
- seconds: 'ss',
234
- fullDate: 'PP',
235
- keyboardDate: 'P',
236
- shortDate: 'MMM d',
237
- normalDate: 'd MMMM',
238
- normalDateWithWeekday: 'EEE, MMM d',
239
- fullTime: 'p',
240
- fullTime12h: 'hh:mm aa',
241
- fullTime24h: 'HH:mm',
242
- keyboardDateTime: 'P p',
243
- keyboardDateTime12h: 'P hh:mm aa',
244
- keyboardDateTime24h: 'P HH:mm'
245
- };
246
-
247
57
  /**
248
58
  * Based on `@date-io/date-fns`
249
59
  *
@@ -269,40 +79,19 @@ const defaultFormats = {
269
79
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
270
80
  * SOFTWARE.
271
81
  */
272
- class AdapterDateFns {
82
+ class AdapterDateFns extends _AdapterDateFnsBase.AdapterDateFnsBase {
273
83
  constructor({
274
- locale: _locale,
84
+ locale,
275
85
  formats
276
86
  } = {}) {
277
- this.isMUIAdapter = true;
278
- this.isTimezoneCompatible = false;
279
- this.lib = 'date-fns';
280
- this.locale = void 0;
281
- this.formats = void 0;
282
- this.formatTokenMap = formatTokenMap;
283
- this.escapedCharacters = {
284
- start: "'",
285
- end: "'"
286
- };
287
- this.date = value => {
288
- if (typeof value === 'undefined') {
289
- return new Date();
290
- }
291
- if (value === null) {
292
- return null;
293
- }
294
- return new Date(value);
295
- };
296
- this.getInvalidDate = () => new Date('Invalid Date');
297
- this.getTimezone = () => {
298
- return 'default';
299
- };
300
- this.setTimezone = value => {
301
- return value;
302
- };
303
- this.toJsDate = value => {
304
- return value;
305
- };
87
+ if (typeof _addDays.default !== 'function') {
88
+ 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'));
89
+ }
90
+ super({
91
+ locale: locale ?? _enUS.default,
92
+ formats,
93
+ longFormatters: _longFormatters.default
94
+ });
306
95
  this.parse = (value, format) => {
307
96
  if (value === '') {
308
97
  return null;
@@ -311,33 +100,6 @@ class AdapterDateFns {
311
100
  locale: this.locale
312
101
  });
313
102
  };
314
- this.getCurrentLocaleCode = () => {
315
- return this.locale?.code || 'en-US';
316
- };
317
- // Note: date-fns input types are more lenient than this adapter, so we need to expose our more
318
- // strict signature and delegate to the more lenient signature. Otherwise, we have downstream type errors upon usage.
319
- this.is12HourCycleInCurrentLocale = () => {
320
- if (this.locale) {
321
- return /a/.test(this.locale.formatLong.time());
322
- }
323
-
324
- // By default, date-fns is using en-US locale with am/pm enabled
325
- return true;
326
- };
327
- this.expandFormat = format => {
328
- const longFormatRegexp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
329
-
330
- // @see https://github.com/date-fns/date-fns/blob/master/src/format/index.js#L31
331
- return format.match(longFormatRegexp).map(token => {
332
- const firstCharacter = token[0];
333
- if (firstCharacter === 'p' || firstCharacter === 'P') {
334
- const longFormatter = _longFormatters.default[firstCharacter];
335
- const locale = this.locale || _enUS.default;
336
- return longFormatter(token, locale.formatLong, {});
337
- }
338
- return token;
339
- }).join('');
340
- };
341
103
  this.isValid = value => {
342
104
  if (value == null) {
343
105
  return false;
@@ -352,9 +114,6 @@ class AdapterDateFns {
352
114
  locale: this.locale
353
115
  });
354
116
  };
355
- this.formatNumber = numberToFormat => {
356
- return numberToFormat;
357
- };
358
117
  this.isEqual = (value, comparing) => {
359
118
  if (value === null && comparing === null) {
360
119
  return true;
@@ -525,8 +284,6 @@ class AdapterDateFns {
525
284
  }
526
285
  return years;
527
286
  };
528
- this.locale = _locale;
529
- this.formats = (0, _extends2.default)({}, defaultFormats, formats);
530
287
  }
531
288
  }
532
289
  exports.AdapterDateFns = AdapterDateFns;