@mui/x-date-pickers 8.10.0 → 8.11.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.
Files changed (34) hide show
  1. package/AdapterDateFns/AdapterDateFns.js +194 -195
  2. package/AdapterDateFnsBase/AdapterDateFnsBase.js +57 -62
  3. package/AdapterDateFnsJalali/AdapterDateFnsJalali.js +197 -198
  4. package/AdapterDateFnsJalaliV2/AdapterDateFnsJalaliV2.js +196 -196
  5. package/AdapterDateFnsV2/AdapterDateFnsV2.js +193 -193
  6. package/AdapterDayjs/AdapterDayjs.js +378 -379
  7. package/AdapterLuxon/AdapterLuxon.js +324 -326
  8. package/AdapterMoment/AdapterMoment.js +297 -302
  9. package/AdapterMomentHijri/AdapterMomentHijri.js +78 -78
  10. package/AdapterMomentJalaali/AdapterMomentJalaali.js +78 -80
  11. package/CHANGELOG.md +309 -0
  12. package/PickersTextField/PickersInputBase/PickersInputBase.js +14 -1
  13. package/PickersTextField/PickersTextField.js +3 -2
  14. package/esm/AdapterDateFns/AdapterDateFns.js +194 -194
  15. package/esm/AdapterDateFnsBase/AdapterDateFnsBase.js +57 -62
  16. package/esm/AdapterDateFnsJalali/AdapterDateFnsJalali.js +197 -197
  17. package/esm/AdapterDateFnsJalaliV2/AdapterDateFnsJalaliV2.js +196 -196
  18. package/esm/AdapterDateFnsV2/AdapterDateFnsV2.js +193 -193
  19. package/esm/AdapterDayjs/AdapterDayjs.js +378 -379
  20. package/esm/AdapterLuxon/AdapterLuxon.js +324 -325
  21. package/esm/AdapterMoment/AdapterMoment.js +297 -301
  22. package/esm/AdapterMomentHijri/AdapterMomentHijri.js +78 -78
  23. package/esm/AdapterMomentJalaali/AdapterMomentJalaali.js +78 -80
  24. package/esm/PickersTextField/PickersInputBase/PickersInputBase.js +14 -1
  25. package/esm/PickersTextField/PickersTextField.js +3 -2
  26. package/esm/index.js +1 -1
  27. package/esm/internals/hooks/useField/syncSelectionToDOM.js +3 -1
  28. package/esm/internals/models/helpers.d.ts +1 -1
  29. package/esm/models/fields.d.ts +4 -0
  30. package/index.js +1 -1
  31. package/internals/hooks/useField/syncSelectionToDOM.js +3 -1
  32. package/internals/models/helpers.d.ts +1 -1
  33. package/models/fields.d.ts +4 -0
  34. package/package.json +15 -16
@@ -48,8 +48,6 @@ var _startOfYear = require("date-fns/startOfYear");
48
48
  var _isWithinInterval = require("date-fns/isWithinInterval");
49
49
  var _enUS = require("date-fns/locale/en-US");
50
50
  var _AdapterDateFnsBase = require("../AdapterDateFnsBase");
51
- /* eslint-disable class-methods-use-this */
52
-
53
51
  /**
54
52
  * Based on `@date-io/date-fns`
55
53
  *
@@ -95,199 +93,200 @@ class AdapterDateFns extends _AdapterDateFnsBase.AdapterDateFnsBase {
95
93
  formats,
96
94
  longFormatters: _format.longFormatters
97
95
  });
98
- // TODO: explicit return types can be removed once there is only one date-fns version supported
99
- this.parse = (value, format) => {
100
- if (value === '') {
101
- return null;
102
- }
103
- return (0, _parse.parse)(value, format, new Date(), {
104
- locale: this.locale
105
- });
106
- };
107
- this.isValid = value => {
108
- if (value == null) {
109
- return false;
110
- }
111
- return (0, _isValid.isValid)(value);
112
- };
113
- this.format = (value, formatKey) => {
114
- return this.formatByString(value, this.formats[formatKey]);
115
- };
116
- this.formatByString = (value, formatString) => {
117
- return (0, _format.format)(value, formatString, {
118
- locale: this.locale
119
- });
120
- };
121
- this.isEqual = (value, comparing) => {
122
- if (value === null && comparing === null) {
123
- return true;
124
- }
125
- if (value === null || comparing === null) {
126
- return false;
127
- }
128
- return (0, _isEqual.isEqual)(value, comparing);
129
- };
130
- this.isSameYear = (value, comparing) => {
131
- return (0, _isSameYear.isSameYear)(value, comparing);
132
- };
133
- this.isSameMonth = (value, comparing) => {
134
- return (0, _isSameMonth.isSameMonth)(value, comparing);
135
- };
136
- this.isSameDay = (value, comparing) => {
137
- return (0, _isSameDay.isSameDay)(value, comparing);
138
- };
139
- this.isSameHour = (value, comparing) => {
140
- return (0, _isSameHour.isSameHour)(value, comparing);
141
- };
142
- this.isAfter = (value, comparing) => {
143
- return (0, _isAfter.isAfter)(value, comparing);
144
- };
145
- this.isAfterYear = (value, comparing) => {
146
- return (0, _isAfter.isAfter)(value, (0, _endOfYear.endOfYear)(comparing));
147
- };
148
- this.isAfterDay = (value, comparing) => {
149
- return (0, _isAfter.isAfter)(value, (0, _endOfDay.endOfDay)(comparing));
150
- };
151
- this.isBefore = (value, comparing) => {
152
- return (0, _isBefore.isBefore)(value, comparing);
153
- };
154
- this.isBeforeYear = (value, comparing) => {
155
- return (0, _isBefore.isBefore)(value, this.startOfYear(comparing));
156
- };
157
- this.isBeforeDay = (value, comparing) => {
158
- return (0, _isBefore.isBefore)(value, this.startOfDay(comparing));
159
- };
160
- this.isWithinRange = (value, [start, end]) => {
161
- return (0, _isWithinInterval.isWithinInterval)(value, {
162
- start,
163
- end
164
- });
165
- };
166
- this.startOfYear = value => {
167
- return (0, _startOfYear.startOfYear)(value);
168
- };
169
- this.startOfMonth = value => {
170
- return (0, _startOfMonth.startOfMonth)(value);
171
- };
172
- this.startOfWeek = value => {
173
- return (0, _startOfWeek.startOfWeek)(value, {
174
- locale: this.locale
175
- });
176
- };
177
- this.startOfDay = value => {
178
- return (0, _startOfDay.startOfDay)(value);
179
- };
180
- this.endOfYear = value => {
181
- return (0, _endOfYear.endOfYear)(value);
182
- };
183
- this.endOfMonth = value => {
184
- return (0, _endOfMonth.endOfMonth)(value);
185
- };
186
- this.endOfWeek = value => {
187
- return (0, _endOfWeek.endOfWeek)(value, {
188
- locale: this.locale
189
- });
190
- };
191
- this.endOfDay = value => {
192
- return (0, _endOfDay.endOfDay)(value);
193
- };
194
- this.addYears = (value, amount) => {
195
- return (0, _addYears.addYears)(value, amount);
196
- };
197
- this.addMonths = (value, amount) => {
198
- return (0, _addMonths.addMonths)(value, amount);
199
- };
200
- this.addWeeks = (value, amount) => {
201
- return (0, _addWeeks.addWeeks)(value, amount);
202
- };
203
- this.addDays = (value, amount) => {
204
- return (0, _addDays.addDays)(value, amount);
205
- };
206
- this.addHours = (value, amount) => {
207
- return (0, _addHours.addHours)(value, amount);
208
- };
209
- this.addMinutes = (value, amount) => {
210
- return (0, _addMinutes.addMinutes)(value, amount);
211
- };
212
- this.addSeconds = (value, amount) => {
213
- return (0, _addSeconds.addSeconds)(value, amount);
214
- };
215
- this.getYear = value => {
216
- return (0, _getYear.getYear)(value);
217
- };
218
- this.getMonth = value => {
219
- return (0, _getMonth.getMonth)(value);
220
- };
221
- this.getDate = value => {
222
- return (0, _getDate.getDate)(value);
223
- };
224
- this.getHours = value => {
225
- return (0, _getHours.getHours)(value);
226
- };
227
- this.getMinutes = value => {
228
- return (0, _getMinutes.getMinutes)(value);
229
- };
230
- this.getSeconds = value => {
231
- return (0, _getSeconds.getSeconds)(value);
232
- };
233
- this.getMilliseconds = value => {
234
- return (0, _getMilliseconds.getMilliseconds)(value);
235
- };
236
- this.setYear = (value, year) => {
237
- return (0, _setYear.setYear)(value, year);
238
- };
239
- this.setMonth = (value, month) => {
240
- return (0, _setMonth.setMonth)(value, month);
241
- };
242
- this.setDate = (value, date) => {
243
- return (0, _setDate.setDate)(value, date);
244
- };
245
- this.setHours = (value, hours) => {
246
- return (0, _setHours.setHours)(value, hours);
247
- };
248
- this.setMinutes = (value, minutes) => {
249
- return (0, _setMinutes.setMinutes)(value, minutes);
250
- };
251
- this.setSeconds = (value, seconds) => {
252
- return (0, _setSeconds.setSeconds)(value, seconds);
253
- };
254
- this.setMilliseconds = (value, milliseconds) => {
255
- return (0, _setMilliseconds.setMilliseconds)(value, milliseconds);
256
- };
257
- this.getDaysInMonth = value => {
258
- return (0, _getDaysInMonth.getDaysInMonth)(value);
259
- };
260
- this.getWeekArray = value => {
261
- const start = this.startOfWeek(this.startOfMonth(value));
262
- const end = this.endOfWeek(this.endOfMonth(value));
263
- let count = 0;
264
- let current = start;
265
- const nestedWeeks = [];
266
- while (this.isBefore(current, end)) {
267
- const weekNumber = Math.floor(count / 7);
268
- nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
269
- nestedWeeks[weekNumber].push(current);
270
- current = this.addDays(current, 1);
271
- count += 1;
272
- }
273
- return nestedWeeks;
274
- };
275
- this.getWeekNumber = value => {
276
- return (0, _getWeek.getWeek)(value, {
277
- locale: this.locale
278
- });
279
- };
280
- this.getYearRange = ([start, end]) => {
281
- const startDate = this.startOfYear(start);
282
- const endDate = this.endOfYear(end);
283
- const years = [];
284
- let current = startDate;
285
- while (this.isBefore(current, endDate)) {
286
- years.push(current);
287
- current = this.addYears(current, 1);
288
- }
289
- return years;
290
- };
291
96
  }
97
+
98
+ // TODO: explicit return types can be removed once there is only one date-fns version supported
99
+ parse = (value, format) => {
100
+ if (value === '') {
101
+ return null;
102
+ }
103
+ return (0, _parse.parse)(value, format, new Date(), {
104
+ locale: this.locale
105
+ });
106
+ };
107
+ isValid = value => {
108
+ if (value == null) {
109
+ return false;
110
+ }
111
+ return (0, _isValid.isValid)(value);
112
+ };
113
+ format = (value, formatKey) => {
114
+ return this.formatByString(value, this.formats[formatKey]);
115
+ };
116
+ formatByString = (value, formatString) => {
117
+ return (0, _format.format)(value, formatString, {
118
+ locale: this.locale
119
+ });
120
+ };
121
+ isEqual = (value, comparing) => {
122
+ if (value === null && comparing === null) {
123
+ return true;
124
+ }
125
+ if (value === null || comparing === null) {
126
+ return false;
127
+ }
128
+ return (0, _isEqual.isEqual)(value, comparing);
129
+ };
130
+ isSameYear = (value, comparing) => {
131
+ return (0, _isSameYear.isSameYear)(value, comparing);
132
+ };
133
+ isSameMonth = (value, comparing) => {
134
+ return (0, _isSameMonth.isSameMonth)(value, comparing);
135
+ };
136
+ isSameDay = (value, comparing) => {
137
+ return (0, _isSameDay.isSameDay)(value, comparing);
138
+ };
139
+ isSameHour = (value, comparing) => {
140
+ return (0, _isSameHour.isSameHour)(value, comparing);
141
+ };
142
+ isAfter = (value, comparing) => {
143
+ return (0, _isAfter.isAfter)(value, comparing);
144
+ };
145
+ isAfterYear = (value, comparing) => {
146
+ return (0, _isAfter.isAfter)(value, (0, _endOfYear.endOfYear)(comparing));
147
+ };
148
+ isAfterDay = (value, comparing) => {
149
+ return (0, _isAfter.isAfter)(value, (0, _endOfDay.endOfDay)(comparing));
150
+ };
151
+ isBefore = (value, comparing) => {
152
+ return (0, _isBefore.isBefore)(value, comparing);
153
+ };
154
+ isBeforeYear = (value, comparing) => {
155
+ return (0, _isBefore.isBefore)(value, this.startOfYear(comparing));
156
+ };
157
+ isBeforeDay = (value, comparing) => {
158
+ return (0, _isBefore.isBefore)(value, this.startOfDay(comparing));
159
+ };
160
+ isWithinRange = (value, [start, end]) => {
161
+ return (0, _isWithinInterval.isWithinInterval)(value, {
162
+ start,
163
+ end
164
+ });
165
+ };
166
+ startOfYear = value => {
167
+ return (0, _startOfYear.startOfYear)(value);
168
+ };
169
+ startOfMonth = value => {
170
+ return (0, _startOfMonth.startOfMonth)(value);
171
+ };
172
+ startOfWeek = value => {
173
+ return (0, _startOfWeek.startOfWeek)(value, {
174
+ locale: this.locale
175
+ });
176
+ };
177
+ startOfDay = value => {
178
+ return (0, _startOfDay.startOfDay)(value);
179
+ };
180
+ endOfYear = value => {
181
+ return (0, _endOfYear.endOfYear)(value);
182
+ };
183
+ endOfMonth = value => {
184
+ return (0, _endOfMonth.endOfMonth)(value);
185
+ };
186
+ endOfWeek = value => {
187
+ return (0, _endOfWeek.endOfWeek)(value, {
188
+ locale: this.locale
189
+ });
190
+ };
191
+ endOfDay = value => {
192
+ return (0, _endOfDay.endOfDay)(value);
193
+ };
194
+ addYears = (value, amount) => {
195
+ return (0, _addYears.addYears)(value, amount);
196
+ };
197
+ addMonths = (value, amount) => {
198
+ return (0, _addMonths.addMonths)(value, amount);
199
+ };
200
+ addWeeks = (value, amount) => {
201
+ return (0, _addWeeks.addWeeks)(value, amount);
202
+ };
203
+ addDays = (value, amount) => {
204
+ return (0, _addDays.addDays)(value, amount);
205
+ };
206
+ addHours = (value, amount) => {
207
+ return (0, _addHours.addHours)(value, amount);
208
+ };
209
+ addMinutes = (value, amount) => {
210
+ return (0, _addMinutes.addMinutes)(value, amount);
211
+ };
212
+ addSeconds = (value, amount) => {
213
+ return (0, _addSeconds.addSeconds)(value, amount);
214
+ };
215
+ getYear = value => {
216
+ return (0, _getYear.getYear)(value);
217
+ };
218
+ getMonth = value => {
219
+ return (0, _getMonth.getMonth)(value);
220
+ };
221
+ getDate = value => {
222
+ return (0, _getDate.getDate)(value);
223
+ };
224
+ getHours = value => {
225
+ return (0, _getHours.getHours)(value);
226
+ };
227
+ getMinutes = value => {
228
+ return (0, _getMinutes.getMinutes)(value);
229
+ };
230
+ getSeconds = value => {
231
+ return (0, _getSeconds.getSeconds)(value);
232
+ };
233
+ getMilliseconds = value => {
234
+ return (0, _getMilliseconds.getMilliseconds)(value);
235
+ };
236
+ setYear = (value, year) => {
237
+ return (0, _setYear.setYear)(value, year);
238
+ };
239
+ setMonth = (value, month) => {
240
+ return (0, _setMonth.setMonth)(value, month);
241
+ };
242
+ setDate = (value, date) => {
243
+ return (0, _setDate.setDate)(value, date);
244
+ };
245
+ setHours = (value, hours) => {
246
+ return (0, _setHours.setHours)(value, hours);
247
+ };
248
+ setMinutes = (value, minutes) => {
249
+ return (0, _setMinutes.setMinutes)(value, minutes);
250
+ };
251
+ setSeconds = (value, seconds) => {
252
+ return (0, _setSeconds.setSeconds)(value, seconds);
253
+ };
254
+ setMilliseconds = (value, milliseconds) => {
255
+ return (0, _setMilliseconds.setMilliseconds)(value, milliseconds);
256
+ };
257
+ getDaysInMonth = value => {
258
+ return (0, _getDaysInMonth.getDaysInMonth)(value);
259
+ };
260
+ getWeekArray = value => {
261
+ const start = this.startOfWeek(this.startOfMonth(value));
262
+ const end = this.endOfWeek(this.endOfMonth(value));
263
+ let count = 0;
264
+ let current = start;
265
+ const nestedWeeks = [];
266
+ while (this.isBefore(current, end)) {
267
+ const weekNumber = Math.floor(count / 7);
268
+ nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
269
+ nestedWeeks[weekNumber].push(current);
270
+ current = this.addDays(current, 1);
271
+ count += 1;
272
+ }
273
+ return nestedWeeks;
274
+ };
275
+ getWeekNumber = value => {
276
+ return (0, _getWeek.getWeek)(value, {
277
+ locale: this.locale
278
+ });
279
+ };
280
+ getYearRange = ([start, end]) => {
281
+ const startDate = this.startOfYear(start);
282
+ const endDate = this.endOfYear(end);
283
+ const years = [];
284
+ let current = startDate;
285
+ while (this.isBefore(current, endDate)) {
286
+ years.push(current);
287
+ current = this.addYears(current, 1);
288
+ }
289
+ return years;
290
+ };
292
291
  }
293
292
  exports.AdapterDateFns = AdapterDateFns;
@@ -6,8 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.AdapterDateFnsBase = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
- /* eslint-disable class-methods-use-this */
10
-
11
9
  const formatTokenMap = {
12
10
  // Year
13
11
  y: {
@@ -223,67 +221,14 @@ const defaultFormats = {
223
221
  * SOFTWARE.
224
222
  */
225
223
  class AdapterDateFnsBase {
224
+ isMUIAdapter = true;
225
+ isTimezoneCompatible = false;
226
+ formatTokenMap = formatTokenMap;
227
+ escapedCharacters = {
228
+ start: "'",
229
+ end: "'"
230
+ };
226
231
  constructor(props) {
227
- this.isMUIAdapter = true;
228
- this.isTimezoneCompatible = false;
229
- this.lib = void 0;
230
- this.locale = void 0;
231
- this.formats = void 0;
232
- this.formatTokenMap = formatTokenMap;
233
- this.escapedCharacters = {
234
- start: "'",
235
- end: "'"
236
- };
237
- this.longFormatters = void 0;
238
- this.date = value => {
239
- if (typeof value === 'undefined') {
240
- return new Date();
241
- }
242
- if (value === null) {
243
- return null;
244
- }
245
- return new Date(value);
246
- };
247
- this.getInvalidDate = () => new Date('Invalid Date');
248
- this.getTimezone = () => {
249
- return 'default';
250
- };
251
- this.setTimezone = value => {
252
- return value;
253
- };
254
- this.toJsDate = value => {
255
- return value;
256
- };
257
- this.getCurrentLocaleCode = () => {
258
- // `code` is undefined only in `date-fns` types, but all locales have it
259
- return this.locale.code;
260
- };
261
- // Note: date-fns input types are more lenient than this adapter, so we need to expose our more
262
- // strict signature and delegate to the more lenient signature. Otherwise, we have downstream type errors upon usage.
263
- this.is12HourCycleInCurrentLocale = () => {
264
- return /a/.test(this.locale.formatLong.time({
265
- width: 'short'
266
- }));
267
- };
268
- this.expandFormat = format => {
269
- const longFormatRegexp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
270
-
271
- // @see https://github.com/date-fns/date-fns/blob/master/src/format/index.js#L31
272
- return format.match(longFormatRegexp).map(token => {
273
- const firstCharacter = token[0];
274
- if (firstCharacter === 'p' || firstCharacter === 'P') {
275
- const longFormatter = this.longFormatters[firstCharacter];
276
- return longFormatter(token, this.locale.formatLong);
277
- }
278
- return token;
279
- }).join('');
280
- };
281
- this.formatNumber = numberToFormat => {
282
- return numberToFormat;
283
- };
284
- this.getDayOfWeek = value => {
285
- return value.getDay() + 1;
286
- };
287
232
  const {
288
233
  locale,
289
234
  formats,
@@ -295,5 +240,55 @@ class AdapterDateFnsBase {
295
240
  this.longFormatters = longFormatters;
296
241
  this.lib = lib || 'date-fns';
297
242
  }
243
+ date = value => {
244
+ if (typeof value === 'undefined') {
245
+ return new Date();
246
+ }
247
+ if (value === null) {
248
+ return null;
249
+ }
250
+ return new Date(value);
251
+ };
252
+ getInvalidDate = () => new Date('Invalid Date');
253
+ getTimezone = () => {
254
+ return 'default';
255
+ };
256
+ setTimezone = value => {
257
+ return value;
258
+ };
259
+ toJsDate = value => {
260
+ return value;
261
+ };
262
+ getCurrentLocaleCode = () => {
263
+ // `code` is undefined only in `date-fns` types, but all locales have it
264
+ return this.locale.code;
265
+ };
266
+
267
+ // Note: date-fns input types are more lenient than this adapter, so we need to expose our more
268
+ // strict signature and delegate to the more lenient signature. Otherwise, we have downstream type errors upon usage.
269
+ is12HourCycleInCurrentLocale = () => {
270
+ return /a/.test(this.locale.formatLong.time({
271
+ width: 'short'
272
+ }));
273
+ };
274
+ expandFormat = format => {
275
+ const longFormatRegexp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
276
+
277
+ // @see https://github.com/date-fns/date-fns/blob/master/src/format/index.js#L31
278
+ return format.match(longFormatRegexp).map(token => {
279
+ const firstCharacter = token[0];
280
+ if (firstCharacter === 'p' || firstCharacter === 'P') {
281
+ const longFormatter = this.longFormatters[firstCharacter];
282
+ return longFormatter(token, this.locale.formatLong);
283
+ }
284
+ return token;
285
+ }).join('');
286
+ };
287
+ formatNumber = numberToFormat => {
288
+ return numberToFormat;
289
+ };
290
+ getDayOfWeek = value => {
291
+ return value.getDay() + 1;
292
+ };
298
293
  }
299
294
  exports.AdapterDateFnsBase = AdapterDateFnsBase;