@mui/x-date-pickers 7.3.2 → 7.5.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 (55) hide show
  1. package/AdapterDateFns/AdapterDateFns.d.ts +5 -0
  2. package/AdapterDateFnsBase/AdapterDateFnsBase.d.ts +1 -5
  3. package/AdapterDateFnsBase/AdapterDateFnsBase.js +4 -2
  4. package/AdapterDateFnsJalali/AdapterDateFnsJalali.d.ts +3 -20
  5. package/AdapterDateFnsJalali/AdapterDateFnsJalali.js +14 -224
  6. package/AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.d.ts +87 -0
  7. package/AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.js +332 -0
  8. package/AdapterDateFnsJalaliV3/index.d.ts +1 -0
  9. package/AdapterDateFnsJalaliV3/index.js +1 -0
  10. package/AdapterDateFnsJalaliV3/package.json +6 -0
  11. package/AdapterDateFnsV3/AdapterDateFnsV3.d.ts +5 -0
  12. package/AdapterDateFnsV3/AdapterDateFnsV3.js +0 -1
  13. package/AdapterMomentJalaali/AdapterMomentJalaali.js +2 -6
  14. package/CHANGELOG.md +160 -2
  15. package/DateCalendar/DateCalendar.js +5 -4
  16. package/PickersLayout/usePickerLayout.js +6 -7
  17. package/PickersShortcuts/PickersShortcuts.d.ts +5 -0
  18. package/PickersShortcuts/PickersShortcuts.js +4 -3
  19. package/index.js +1 -1
  20. package/internals/components/PickersModalDialog.d.ts +2 -2
  21. package/internals/demo/DemoContainer.js +1 -1
  22. package/internals/hooks/useField/useField.js +0 -5
  23. package/internals/hooks/useField/useFieldV6TextField.js +1 -1
  24. package/internals/hooks/useField/useFieldV7TextField.js +5 -0
  25. package/internals/hooks/usePicker/usePickerViews.js +1 -0
  26. package/modern/AdapterDateFnsBase/AdapterDateFnsBase.js +4 -2
  27. package/modern/AdapterDateFnsJalali/AdapterDateFnsJalali.js +14 -224
  28. package/modern/AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.js +332 -0
  29. package/modern/AdapterDateFnsJalaliV3/index.js +1 -0
  30. package/modern/AdapterDateFnsV3/AdapterDateFnsV3.js +0 -1
  31. package/modern/AdapterMomentJalaali/AdapterMomentJalaali.js +2 -6
  32. package/modern/DateCalendar/DateCalendar.js +5 -4
  33. package/modern/PickersLayout/usePickerLayout.js +6 -7
  34. package/modern/PickersShortcuts/PickersShortcuts.js +4 -3
  35. package/modern/index.js +1 -1
  36. package/modern/internals/demo/DemoContainer.js +1 -1
  37. package/modern/internals/hooks/useField/useField.js +0 -5
  38. package/modern/internals/hooks/useField/useFieldV6TextField.js +1 -1
  39. package/modern/internals/hooks/useField/useFieldV7TextField.js +5 -0
  40. package/modern/internals/hooks/usePicker/usePickerViews.js +1 -0
  41. package/node/AdapterDateFnsBase/AdapterDateFnsBase.js +4 -2
  42. package/node/AdapterDateFnsJalali/AdapterDateFnsJalali.js +14 -224
  43. package/node/AdapterDateFnsJalaliV3/AdapterDateFnsJalaliV3.js +341 -0
  44. package/node/AdapterDateFnsJalaliV3/index.js +12 -0
  45. package/node/AdapterMomentJalaali/AdapterMomentJalaali.js +2 -6
  46. package/node/DateCalendar/DateCalendar.js +5 -4
  47. package/node/PickersLayout/usePickerLayout.js +6 -7
  48. package/node/PickersShortcuts/PickersShortcuts.js +4 -3
  49. package/node/index.js +1 -1
  50. package/node/internals/demo/DemoContainer.js +1 -1
  51. package/node/internals/hooks/useField/useField.js +0 -5
  52. package/node/internals/hooks/useField/useFieldV6TextField.js +1 -1
  53. package/node/internals/hooks/useField/useFieldV7TextField.js +5 -0
  54. package/node/internals/hooks/usePicker/usePickerViews.js +1 -0
  55. package/package.json +4 -4
@@ -3,6 +3,11 @@ import defaultLocale from 'date-fns/locale/en-US';
3
3
  import { AdapterFormats, AdapterOptions, MuiPickersAdapter } from '../models';
4
4
  import { AdapterDateFnsBase } from '../AdapterDateFnsBase';
5
5
  type DateFnsLocale = typeof defaultLocale;
6
+ declare module '@mui/x-date-pickers/models' {
7
+ interface PickerValidDateLookup {
8
+ 'date-fns': Date;
9
+ }
10
+ }
6
11
  /**
7
12
  * Based on `@date-io/date-fns`
8
13
  *
@@ -10,12 +10,8 @@ type DateFnsLocaleBase = {
10
10
  };
11
11
  type DateFnsAdapterBaseOptions<DateFnsLocale extends DateFnsLocaleBase> = MakeRequired<AdapterOptions<DateFnsLocale, never>, 'locale'> & {
12
12
  longFormatters: Record<'p' | 'P', (token: string, formatLong: any) => string>;
13
+ lib?: string;
13
14
  };
14
- declare module '@mui/x-date-pickers/models' {
15
- interface PickerValidDateLookup {
16
- 'date-fns': Date;
17
- }
18
- }
19
15
  /**
20
16
  * Based on `@date-io/date-fns`
21
17
  *
@@ -220,7 +220,7 @@ export class AdapterDateFnsBase {
220
220
  constructor(props) {
221
221
  this.isMUIAdapter = true;
222
222
  this.isTimezoneCompatible = false;
223
- this.lib = 'date-fns';
223
+ this.lib = void 0;
224
224
  this.locale = void 0;
225
225
  this.formats = void 0;
226
226
  this.formatTokenMap = formatTokenMap;
@@ -285,10 +285,12 @@ export class AdapterDateFnsBase {
285
285
  const {
286
286
  locale,
287
287
  formats,
288
- longFormatters
288
+ longFormatters,
289
+ lib
289
290
  } = props;
290
291
  this.locale = locale;
291
292
  this.formats = _extends({}, defaultFormats, formats);
292
293
  this.longFormatters = longFormatters;
294
+ this.lib = lib || 'date-fns';
293
295
  }
294
296
  }
@@ -1,6 +1,7 @@
1
1
  /// <reference types="date-fns-jalali" />
2
2
  import defaultLocale from 'date-fns-jalali/locale/fa-IR';
3
- import { AdapterFormats, AdapterOptions, DateBuilderReturnType, FieldFormatTokenMap, MuiPickersAdapter } from '../models';
3
+ import { AdapterFormats, AdapterOptions, MuiPickersAdapter } from '../models';
4
+ import { AdapterDateFnsBase } from '../AdapterDateFnsBase';
4
5
  type DateFnsLocale = typeof defaultLocale;
5
6
  declare module '@mui/x-date-pickers/models' {
6
7
  interface PickerValidDateLookup {
@@ -32,27 +33,10 @@ declare module '@mui/x-date-pickers/models' {
32
33
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
34
  * SOFTWARE.
34
35
  */
35
- export declare class AdapterDateFnsJalali implements MuiPickersAdapter<Date, DateFnsLocale> {
36
- isMUIAdapter: boolean;
37
- isTimezoneCompatible: boolean;
38
- lib: string;
39
- locale?: DateFnsLocale;
40
- formats: AdapterFormats;
41
- formatTokenMap: FieldFormatTokenMap;
42
- escapedCharacters: {
43
- start: string;
44
- end: string;
45
- };
36
+ export declare class AdapterDateFnsJalali extends AdapterDateFnsBase<DateFnsLocale> implements MuiPickersAdapter<Date, DateFnsLocale> {
46
37
  constructor({ locale, formats }?: AdapterOptions<DateFnsLocale, never>);
47
- date: <T extends string | null | undefined>(value?: T) => DateBuilderReturnType<T, Date>;
48
- getInvalidDate: () => Date;
49
- getTimezone: () => string;
50
- setTimezone: (value: Date) => Date;
51
- toJsDate: (value: Date) => Date;
52
38
  parse: (value: string, format: string) => Date | null;
53
39
  getCurrentLocaleCode: () => string;
54
- is12HourCycleInCurrentLocale: () => boolean;
55
- expandFormat: (format: string) => string;
56
40
  isValid: (value: Date | null) => boolean;
57
41
  format: (value: Date, formatKey: keyof AdapterFormats) => string;
58
42
  formatByString: (value: Date, formatString: string) => string;
@@ -101,7 +85,6 @@ export declare class AdapterDateFnsJalali implements MuiPickersAdapter<Date, Dat
101
85
  getDaysInMonth: (value: Date) => number;
102
86
  getWeekArray: (value: Date) => Date[][];
103
87
  getWeekNumber: (date: Date) => number;
104
- getDayOfWeek(value: Date): number;
105
88
  getYearRange: ([start, end]: [Date, Date]) => Date[];
106
89
  }
107
90
  export {};
@@ -45,171 +45,7 @@ import isWithinInterval from 'date-fns-jalali/isWithinInterval';
45
45
  import defaultLocale from 'date-fns-jalali/locale/fa-IR';
46
46
  // @ts-ignore
47
47
  import longFormatters from 'date-fns-jalali/_lib/format/longFormatters';
48
- const formatTokenMap = {
49
- // Year
50
- y: {
51
- sectionType: 'year',
52
- contentType: 'digit',
53
- maxLength: 4
54
- },
55
- yy: 'year',
56
- yyy: {
57
- sectionType: 'year',
58
- contentType: 'digit',
59
- maxLength: 4
60
- },
61
- yyyy: 'year',
62
- // Month
63
- M: {
64
- sectionType: 'month',
65
- contentType: 'digit',
66
- maxLength: 2
67
- },
68
- MM: 'month',
69
- MMMM: {
70
- sectionType: 'month',
71
- contentType: 'letter'
72
- },
73
- MMM: {
74
- sectionType: 'month',
75
- contentType: 'letter'
76
- },
77
- L: {
78
- sectionType: 'month',
79
- contentType: 'digit',
80
- maxLength: 2
81
- },
82
- LL: 'month',
83
- LLL: {
84
- sectionType: 'month',
85
- contentType: 'letter'
86
- },
87
- LLLL: {
88
- sectionType: 'month',
89
- contentType: 'letter'
90
- },
91
- // Day of the month
92
- d: {
93
- sectionType: 'day',
94
- contentType: 'digit',
95
- maxLength: 2
96
- },
97
- dd: 'day',
98
- do: {
99
- sectionType: 'day',
100
- contentType: 'digit-with-letter'
101
- },
102
- // Day of the week
103
- E: {
104
- sectionType: 'weekDay',
105
- contentType: 'letter'
106
- },
107
- EE: {
108
- sectionType: 'weekDay',
109
- contentType: 'letter'
110
- },
111
- EEE: {
112
- sectionType: 'weekDay',
113
- contentType: 'letter'
114
- },
115
- EEEE: {
116
- sectionType: 'weekDay',
117
- contentType: 'letter'
118
- },
119
- EEEEE: {
120
- sectionType: 'weekDay',
121
- contentType: 'letter'
122
- },
123
- i: {
124
- sectionType: 'weekDay',
125
- contentType: 'digit',
126
- maxLength: 1
127
- },
128
- ii: 'weekDay',
129
- iii: {
130
- sectionType: 'weekDay',
131
- contentType: 'letter'
132
- },
133
- iiii: {
134
- sectionType: 'weekDay',
135
- contentType: 'letter'
136
- },
137
- e: {
138
- sectionType: 'weekDay',
139
- contentType: 'digit',
140
- maxLength: 1
141
- },
142
- ee: 'weekDay',
143
- eee: {
144
- sectionType: 'weekDay',
145
- contentType: 'letter'
146
- },
147
- eeee: {
148
- sectionType: 'weekDay',
149
- contentType: 'letter'
150
- },
151
- eeeee: {
152
- sectionType: 'weekDay',
153
- contentType: 'letter'
154
- },
155
- eeeeee: {
156
- sectionType: 'weekDay',
157
- contentType: 'letter'
158
- },
159
- c: {
160
- sectionType: 'weekDay',
161
- contentType: 'digit',
162
- maxLength: 1
163
- },
164
- cc: 'weekDay',
165
- ccc: {
166
- sectionType: 'weekDay',
167
- contentType: 'letter'
168
- },
169
- cccc: {
170
- sectionType: 'weekDay',
171
- contentType: 'letter'
172
- },
173
- ccccc: {
174
- sectionType: 'weekDay',
175
- contentType: 'letter'
176
- },
177
- cccccc: {
178
- sectionType: 'weekDay',
179
- contentType: 'letter'
180
- },
181
- // Meridiem
182
- a: 'meridiem',
183
- aa: 'meridiem',
184
- aaa: 'meridiem',
185
- // Hours
186
- H: {
187
- sectionType: 'hours',
188
- contentType: 'digit',
189
- maxLength: 2
190
- },
191
- HH: 'hours',
192
- h: {
193
- sectionType: 'hours',
194
- contentType: 'digit',
195
- maxLength: 2
196
- },
197
- hh: 'hours',
198
- // Minutes
199
- m: {
200
- sectionType: 'minutes',
201
- contentType: 'digit',
202
- maxLength: 2
203
- },
204
- mm: 'minutes',
205
- // Seconds
206
- s: {
207
- sectionType: 'seconds',
208
- contentType: 'digit',
209
- maxLength: 2
210
- },
211
- ss: 'seconds'
212
- };
48
+ import { AdapterDateFnsBase } from '../AdapterDateFnsBase';
213
49
  const defaultFormats = {
214
50
  year: 'yyyy',
215
51
  month: 'LLLL',
@@ -272,40 +108,22 @@ const NUMBER_SYMBOL_MAP = {
272
108
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
273
109
  * SOFTWARE.
274
110
  */
275
- export class AdapterDateFnsJalali {
111
+ export class AdapterDateFnsJalali extends AdapterDateFnsBase {
276
112
  constructor({
277
- locale: _locale,
113
+ locale,
278
114
  formats
279
115
  } = {}) {
280
- this.isMUIAdapter = true;
281
- this.isTimezoneCompatible = false;
282
- this.lib = 'date-fns-jalali';
283
- this.locale = void 0;
284
- this.formats = void 0;
285
- this.formatTokenMap = formatTokenMap;
286
- this.escapedCharacters = {
287
- start: "'",
288
- end: "'"
289
- };
290
- this.date = value => {
291
- if (typeof value === 'undefined') {
292
- return new Date();
293
- }
294
- if (value === null) {
295
- return null;
296
- }
297
- return new Date(value);
298
- };
299
- this.getInvalidDate = () => new Date('Invalid Date');
300
- this.getTimezone = () => {
301
- return 'default';
302
- };
303
- this.setTimezone = value => {
304
- return value;
305
- };
306
- this.toJsDate = value => {
307
- return value;
308
- };
116
+ if (typeof addDays !== 'function') {
117
+ throw new Error(['MUI: The `date-fns-jalali` package v3.x is not compatible with this adapter.', 'Please, install v2.x of the package or use the `AdapterDateFnsJalaliV3` instead.'].join('\n'));
118
+ }
119
+ super({
120
+ locale: locale ?? defaultLocale,
121
+ // some formats are different in jalali adapter,
122
+ // this ensures that `AdapterDateFnsBase` formats are overridden
123
+ formats: _extends({}, defaultFormats, formats),
124
+ longFormatters,
125
+ lib: 'date-fns-jalali'
126
+ });
309
127
  this.parse = (value, format) => {
310
128
  if (value === '') {
311
129
  return null;
@@ -317,29 +135,6 @@ export class AdapterDateFnsJalali {
317
135
  this.getCurrentLocaleCode = () => {
318
136
  return this.locale?.code || 'fa-IR';
319
137
  };
320
- // Note: date-fns input types are more lenient than this adapter, so we need to expose our more
321
- // strict signature and delegate to the more lenient signature. Otherwise, we have downstream type errors upon usage.
322
- this.is12HourCycleInCurrentLocale = () => {
323
- if (this.locale) {
324
- return /a/.test(this.locale.formatLong.time());
325
- }
326
-
327
- // By default, date-fns-jalali is using fa-IR locale with am/pm enabled
328
- return true;
329
- };
330
- this.expandFormat = format => {
331
- // @see https://github.com/date-fns/date-fns/blob/master/src/format/index.js#L31
332
- const longFormatRegexp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
333
- const locale = this.locale ?? defaultLocale;
334
- return format.match(longFormatRegexp).map(token => {
335
- const firstCharacter = token[0];
336
- if (firstCharacter === 'p' || firstCharacter === 'P') {
337
- const longFormatter = longFormatters[firstCharacter];
338
- return longFormatter(token, locale.formatLong, {});
339
- }
340
- return token;
341
- }).join('');
342
- };
343
138
  this.isValid = value => {
344
139
  if (value == null) {
345
140
  return false;
@@ -527,10 +322,5 @@ export class AdapterDateFnsJalali {
527
322
  }
528
323
  return years;
529
324
  };
530
- this.locale = _locale;
531
- this.formats = _extends({}, defaultFormats, formats);
532
- }
533
- getDayOfWeek(value) {
534
- return value.getDay() + 1;
535
325
  }
536
326
  }
@@ -0,0 +1,87 @@
1
+ import { Locale as DateFnsLocale } from 'date-fns-jalali/locale/types';
2
+ import { AdapterFormats, AdapterOptions, MuiPickersAdapter } from '../models';
3
+ import { AdapterDateFnsBase } from '../AdapterDateFnsBase';
4
+ declare module '@mui/x-date-pickers/models' {
5
+ interface PickerValidDateLookup {
6
+ 'date-fns-jalali': Date;
7
+ }
8
+ }
9
+ /**
10
+ * Based on `@date-io/date-fns-jalali`
11
+ *
12
+ * MIT License
13
+ *
14
+ * Copyright (c) 2017 Dmitriy Kovalenko
15
+ *
16
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
17
+ * of this software and associated documentation files (the "Software"), to deal
18
+ * in the Software without restriction, including without limitation the rights
19
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
20
+ * copies of the Software, and to permit persons to whom the Software is
21
+ * furnished to do so, subject to the following conditions:
22
+ *
23
+ * The above copyright notice and this permission notice shall be included in all
24
+ * copies or substantial portions of the Software.
25
+ *
26
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
+ * SOFTWARE.
33
+ */
34
+ export declare class AdapterDateFnsJalali extends AdapterDateFnsBase<DateFnsLocale> implements MuiPickersAdapter<Date, DateFnsLocale> {
35
+ constructor({ locale, formats }?: AdapterOptions<DateFnsLocale, never>);
36
+ parse: (value: string, format: string) => any;
37
+ getCurrentLocaleCode: () => any;
38
+ isValid: (value: Date | null) => any;
39
+ format: (value: Date, formatKey: keyof AdapterFormats) => any;
40
+ formatByString: (value: Date, formatString: string) => any;
41
+ formatNumber: (numberToFormat: string) => string;
42
+ isEqual: (value: Date | null, comparing: Date | null) => any;
43
+ isSameYear: (value: Date, comparing: Date) => any;
44
+ isSameMonth: (value: Date, comparing: Date) => any;
45
+ isSameDay: (value: Date, comparing: Date) => any;
46
+ isSameHour: (value: Date, comparing: Date) => any;
47
+ isAfter: (value: Date, comparing: Date) => any;
48
+ isAfterYear: (value: Date, comparing: Date) => any;
49
+ isAfterDay: (value: Date, comparing: Date) => any;
50
+ isBefore: (value: Date, comparing: Date) => any;
51
+ isBeforeYear: (value: Date, comparing: Date) => any;
52
+ isBeforeDay: (value: Date, comparing: Date) => any;
53
+ isWithinRange: (value: Date, [start, end]: [Date, Date]) => any;
54
+ startOfYear: (value: Date) => any;
55
+ startOfMonth: (value: Date) => any;
56
+ startOfWeek: (value: Date) => any;
57
+ startOfDay: (value: Date) => any;
58
+ endOfYear: (value: Date) => any;
59
+ endOfMonth: (value: Date) => any;
60
+ endOfWeek: (value: Date) => any;
61
+ endOfDay: (value: Date) => any;
62
+ addYears: (value: Date, amount: number) => any;
63
+ addMonths: (value: Date, amount: number) => any;
64
+ addWeeks: (value: Date, amount: number) => any;
65
+ addDays: (value: Date, amount: number) => any;
66
+ addHours: (value: Date, amount: number) => any;
67
+ addMinutes: (value: Date, amount: number) => any;
68
+ addSeconds: (value: Date, amount: number) => any;
69
+ getYear: (value: Date) => any;
70
+ getMonth: (value: Date) => any;
71
+ getDate: (value: Date) => any;
72
+ getHours: (value: Date) => any;
73
+ getMinutes: (value: Date) => any;
74
+ getSeconds: (value: Date) => any;
75
+ getMilliseconds: (value: Date) => any;
76
+ setYear: (value: Date, year: number) => any;
77
+ setMonth: (value: Date, month: number) => any;
78
+ setDate: (value: Date, date: number) => any;
79
+ setHours: (value: Date, hours: number) => any;
80
+ setMinutes: (value: Date, minutes: number) => any;
81
+ setSeconds: (value: Date, seconds: number) => any;
82
+ setMilliseconds: (value: Date, milliseconds: number) => any;
83
+ getDaysInMonth: (value: Date) => any;
84
+ getWeekArray: (value: Date) => Date[][];
85
+ getWeekNumber: (date: Date) => any;
86
+ getYearRange: ([start, end]: [Date, Date]) => Date[];
87
+ }