@mui/x-date-pickers 6.1.0 → 6.2.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 (163) hide show
  1. package/AdapterDayjs/AdapterDayjs.d.ts +114 -0
  2. package/AdapterDayjs/AdapterDayjs.js +387 -0
  3. package/AdapterDayjs/index.d.ts +1 -28
  4. package/AdapterDayjs/index.js +1 -102
  5. package/CHANGELOG.md +53 -1
  6. package/DateCalendar/DateCalendar.types.d.ts +1 -1
  7. package/DateCalendar/DayCalendar.d.ts +1 -1
  8. package/DateField/DateField.js +6 -0
  9. package/DateField/useDateField.js +3 -1
  10. package/DatePicker/DatePicker.js +6 -0
  11. package/DateTimeField/DateTimeField.js +6 -0
  12. package/DateTimeField/useDateTimeField.js +3 -1
  13. package/DateTimePicker/DateTimePicker.js +6 -0
  14. package/DateTimePicker/shared.js +3 -1
  15. package/DesktopDatePicker/DesktopDatePicker.js +6 -0
  16. package/DesktopDateTimePicker/DesktopDateTimePicker.js +6 -0
  17. package/DesktopTimePicker/DesktopTimePicker.js +6 -0
  18. package/MobileDatePicker/MobileDatePicker.js +6 -0
  19. package/MobileDateTimePicker/MobileDateTimePicker.js +6 -0
  20. package/MobileTimePicker/MobileTimePicker.js +6 -0
  21. package/README.md +1 -0
  22. package/TimeClock/TimeClock.types.d.ts +1 -1
  23. package/TimeField/TimeField.js +6 -0
  24. package/TimeField/useTimeField.js +3 -1
  25. package/TimePicker/TimePicker.js +6 -0
  26. package/index.js +1 -1
  27. package/internals/components/PickersModalDialog.d.ts +1 -1
  28. package/internals/components/PickersPopper.d.ts +1 -1
  29. package/internals/hooks/useDesktopPicker/useDesktopPicker.js +2 -0
  30. package/internals/hooks/useDesktopPicker/useDesktopPicker.types.d.ts +1 -1
  31. package/internals/hooks/useField/useField.types.d.ts +6 -0
  32. package/internals/hooks/useField/useField.utils.d.ts +1 -1
  33. package/internals/hooks/useField/useField.utils.js +16 -4
  34. package/internals/hooks/useField/useFieldState.js +3 -2
  35. package/internals/hooks/useMobilePicker/useMobilePicker.js +2 -0
  36. package/internals/hooks/useMobilePicker/useMobilePicker.types.d.ts +1 -1
  37. package/internals/hooks/usePicker/index.d.ts +1 -1
  38. package/internals/hooks/usePicker/usePicker.types.d.ts +1 -1
  39. package/internals/hooks/usePicker/usePickerLayoutProps.d.ts +1 -1
  40. package/internals/hooks/usePicker/usePickerValue.d.ts +3 -179
  41. package/internals/hooks/usePicker/usePickerValue.js +187 -153
  42. package/internals/hooks/usePicker/usePickerValue.types.d.ts +233 -0
  43. package/internals/hooks/usePicker/usePickerValue.types.js +1 -0
  44. package/internals/hooks/usePicker/usePickerViews.d.ts +1 -1
  45. package/internals/index.d.ts +1 -1
  46. package/internals/models/props/basePickerProps.d.ts +6 -0
  47. package/legacy/AdapterDayjs/AdapterDayjs.js +403 -0
  48. package/legacy/AdapterDayjs/index.js +1 -119
  49. package/legacy/DateField/DateField.js +6 -0
  50. package/legacy/DateField/useDateField.js +3 -1
  51. package/legacy/DatePicker/DatePicker.js +6 -0
  52. package/legacy/DateTimeField/DateTimeField.js +6 -0
  53. package/legacy/DateTimeField/useDateTimeField.js +3 -1
  54. package/legacy/DateTimePicker/DateTimePicker.js +6 -0
  55. package/legacy/DateTimePicker/shared.js +3 -1
  56. package/legacy/DesktopDatePicker/DesktopDatePicker.js +6 -0
  57. package/legacy/DesktopDateTimePicker/DesktopDateTimePicker.js +6 -0
  58. package/legacy/DesktopTimePicker/DesktopTimePicker.js +6 -0
  59. package/legacy/MobileDatePicker/MobileDatePicker.js +6 -0
  60. package/legacy/MobileDateTimePicker/MobileDateTimePicker.js +6 -0
  61. package/legacy/MobileTimePicker/MobileTimePicker.js +6 -0
  62. package/legacy/TimeField/TimeField.js +6 -0
  63. package/legacy/TimeField/useTimeField.js +3 -1
  64. package/legacy/TimePicker/TimePicker.js +6 -0
  65. package/legacy/index.js +1 -1
  66. package/legacy/internals/hooks/useDesktopPicker/useDesktopPicker.js +2 -0
  67. package/legacy/internals/hooks/useField/useField.utils.js +24 -9
  68. package/legacy/internals/hooks/useField/useFieldState.js +5 -3
  69. package/legacy/internals/hooks/useMobilePicker/useMobilePicker.js +2 -0
  70. package/legacy/internals/hooks/usePicker/usePickerValue.js +184 -153
  71. package/legacy/internals/hooks/usePicker/usePickerValue.types.js +1 -0
  72. package/legacy/tests/describeGregorianAdapter/describeGregorianAdapter.js +20 -0
  73. package/legacy/tests/describeGregorianAdapter/describeGregorianAdapter.types.js +1 -0
  74. package/legacy/tests/describeGregorianAdapter/index.js +1 -0
  75. package/legacy/tests/describeGregorianAdapter/testCalculations.js +273 -0
  76. package/legacy/tests/describeGregorianAdapter/testFormat.js +26 -0
  77. package/legacy/tests/describeGregorianAdapter/testLocalization.js +15 -0
  78. package/legacy/tests/describeValidation/describeValidation.js +2 -1
  79. package/legacy/tests/describeValidation/testMinutesViewValidation.js +201 -0
  80. package/legacy/tests/describeValue/testPickerActionBar.js +52 -3
  81. package/legacy/tests/describeValue/testPickerOpenCloseLifeCycle.js +6 -6
  82. package/models/adapters.d.ts +21 -20
  83. package/modern/AdapterDayjs/AdapterDayjs.js +386 -0
  84. package/modern/AdapterDayjs/index.js +1 -101
  85. package/modern/DateField/DateField.js +6 -0
  86. package/modern/DateField/useDateField.js +3 -1
  87. package/modern/DatePicker/DatePicker.js +6 -0
  88. package/modern/DateTimeField/DateTimeField.js +6 -0
  89. package/modern/DateTimeField/useDateTimeField.js +3 -1
  90. package/modern/DateTimePicker/DateTimePicker.js +6 -0
  91. package/modern/DateTimePicker/shared.js +3 -1
  92. package/modern/DesktopDatePicker/DesktopDatePicker.js +6 -0
  93. package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +6 -0
  94. package/modern/DesktopTimePicker/DesktopTimePicker.js +6 -0
  95. package/modern/MobileDatePicker/MobileDatePicker.js +6 -0
  96. package/modern/MobileDateTimePicker/MobileDateTimePicker.js +6 -0
  97. package/modern/MobileTimePicker/MobileTimePicker.js +6 -0
  98. package/modern/TimeField/TimeField.js +6 -0
  99. package/modern/TimeField/useTimeField.js +3 -1
  100. package/modern/TimePicker/TimePicker.js +6 -0
  101. package/modern/index.js +1 -1
  102. package/modern/internals/hooks/useDesktopPicker/useDesktopPicker.js +2 -0
  103. package/modern/internals/hooks/useField/useField.utils.js +16 -4
  104. package/modern/internals/hooks/useField/useFieldState.js +3 -2
  105. package/modern/internals/hooks/useMobilePicker/useMobilePicker.js +2 -0
  106. package/modern/internals/hooks/usePicker/usePickerValue.js +187 -153
  107. package/modern/internals/hooks/usePicker/usePickerValue.types.js +1 -0
  108. package/modern/tests/describeGregorianAdapter/describeGregorianAdapter.js +20 -0
  109. package/modern/tests/describeGregorianAdapter/describeGregorianAdapter.types.js +1 -0
  110. package/modern/tests/describeGregorianAdapter/index.js +1 -0
  111. package/modern/tests/describeGregorianAdapter/testCalculations.js +272 -0
  112. package/modern/tests/describeGregorianAdapter/testFormat.js +27 -0
  113. package/modern/tests/describeGregorianAdapter/testLocalization.js +16 -0
  114. package/modern/tests/describeValidation/describeValidation.js +2 -1
  115. package/modern/tests/describeValidation/testMinutesViewValidation.js +200 -0
  116. package/modern/tests/describeValue/testPickerActionBar.js +52 -3
  117. package/modern/tests/describeValue/testPickerOpenCloseLifeCycle.js +6 -6
  118. package/node/AdapterDayjs/AdapterDayjs.js +395 -0
  119. package/node/AdapterDayjs/index.js +6 -104
  120. package/node/DateField/DateField.js +6 -0
  121. package/node/DateField/useDateField.js +3 -1
  122. package/node/DatePicker/DatePicker.js +6 -0
  123. package/node/DateTimeField/DateTimeField.js +6 -0
  124. package/node/DateTimeField/useDateTimeField.js +3 -1
  125. package/node/DateTimePicker/DateTimePicker.js +6 -0
  126. package/node/DateTimePicker/shared.js +3 -1
  127. package/node/DesktopDatePicker/DesktopDatePicker.js +6 -0
  128. package/node/DesktopDateTimePicker/DesktopDateTimePicker.js +6 -0
  129. package/node/DesktopTimePicker/DesktopTimePicker.js +6 -0
  130. package/node/MobileDatePicker/MobileDatePicker.js +6 -0
  131. package/node/MobileDateTimePicker/MobileDateTimePicker.js +6 -0
  132. package/node/MobileTimePicker/MobileTimePicker.js +6 -0
  133. package/node/TimeField/TimeField.js +6 -0
  134. package/node/TimeField/useTimeField.js +3 -1
  135. package/node/TimePicker/TimePicker.js +6 -0
  136. package/node/index.js +1 -1
  137. package/node/internals/hooks/useDesktopPicker/useDesktopPicker.js +2 -0
  138. package/node/internals/hooks/useField/useField.utils.js +16 -4
  139. package/node/internals/hooks/useField/useFieldState.js +3 -2
  140. package/node/internals/hooks/useMobilePicker/useMobilePicker.js +2 -0
  141. package/node/internals/hooks/usePicker/usePickerValue.js +187 -152
  142. package/node/internals/hooks/usePicker/usePickerValue.types.js +5 -0
  143. package/node/tests/describeGregorianAdapter/describeGregorianAdapter.js +29 -0
  144. package/node/tests/describeGregorianAdapter/describeGregorianAdapter.types.js +5 -0
  145. package/node/tests/describeGregorianAdapter/index.js +18 -0
  146. package/node/tests/describeGregorianAdapter/testCalculations.js +279 -0
  147. package/node/tests/describeGregorianAdapter/testFormat.js +34 -0
  148. package/node/tests/describeGregorianAdapter/testLocalization.js +23 -0
  149. package/node/tests/describeValidation/describeValidation.js +2 -1
  150. package/node/tests/describeValidation/testMinutesViewValidation.js +210 -0
  151. package/node/tests/describeValue/testPickerActionBar.js +52 -3
  152. package/node/tests/describeValue/testPickerOpenCloseLifeCycle.js +6 -6
  153. package/package.json +9 -9
  154. package/tests/describeGregorianAdapter/describeGregorianAdapter.js +20 -0
  155. package/tests/describeGregorianAdapter/describeGregorianAdapter.types.js +1 -0
  156. package/tests/describeGregorianAdapter/index.js +1 -0
  157. package/tests/describeGregorianAdapter/testCalculations.js +272 -0
  158. package/tests/describeGregorianAdapter/testFormat.js +27 -0
  159. package/tests/describeGregorianAdapter/testLocalization.js +16 -0
  160. package/tests/describeValidation/describeValidation.js +2 -1
  161. package/tests/describeValidation/testMinutesViewValidation.js +200 -0
  162. package/tests/describeValue/testPickerActionBar.js +52 -3
  163. package/tests/describeValue/testPickerOpenCloseLifeCycle.js +6 -6
@@ -0,0 +1,114 @@
1
+ import defaultDayjs, { Dayjs } from 'dayjs';
2
+ import { FieldFormatTokenMap, MuiPickersAdapter, AdapterFormats, AdapterUnits } from '../models';
3
+ interface Opts {
4
+ locale?: string;
5
+ /** Make sure that your dayjs instance extends customParseFormat and advancedFormat */
6
+ instance?: typeof defaultDayjs;
7
+ formats?: Partial<AdapterFormats>;
8
+ }
9
+ type Constructor = (...args: Parameters<typeof defaultDayjs>) => Dayjs;
10
+ /**
11
+ * Based on `@date-io/dayjs`
12
+ *
13
+ * MIT License
14
+ *
15
+ * Copyright (c) 2017 Dmitriy Kovalenko
16
+ *
17
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
18
+ * of this software and associated documentation files (the "Software"), to deal
19
+ * in the Software without restriction, including without limitation the rights
20
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21
+ * copies of the Software, and to permit persons to whom the Software is
22
+ * furnished to do so, subject to the following conditions:
23
+ *
24
+ * The above copyright notice and this permission notice shall be included in all
25
+ * copies or substantial portions of the Software.
26
+ *
27
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
+ * SOFTWARE.
34
+ */
35
+ export declare class AdapterDayjs implements MuiPickersAdapter<Dayjs> {
36
+ isMUIAdapter: boolean;
37
+ rawDayJsInstance: typeof defaultDayjs;
38
+ lib: string;
39
+ dayjs: Constructor;
40
+ locale?: string;
41
+ formats: AdapterFormats;
42
+ constructor({ locale, formats, instance }?: Opts);
43
+ escapedCharacters: {
44
+ start: string;
45
+ end: string;
46
+ };
47
+ formatTokenMap: FieldFormatTokenMap;
48
+ private getLocaleFormats;
49
+ date: (value?: any) => defaultDayjs.Dayjs | null;
50
+ toJsDate: (value: Dayjs) => Date;
51
+ parseISO: (isoString: string) => defaultDayjs.Dayjs;
52
+ toISO: (value: Dayjs) => string;
53
+ parse: (value: any, format: string) => defaultDayjs.Dayjs | null;
54
+ getCurrentLocaleCode: () => string;
55
+ is12HourCycleInCurrentLocale: () => boolean;
56
+ expandFormat: (format: string) => string;
57
+ getFormatHelperText: (format: string) => string;
58
+ isNull: (date: Dayjs | null) => boolean;
59
+ isValid: (value: any) => boolean;
60
+ format: (date: Dayjs, formatKey: keyof AdapterFormats) => string;
61
+ formatByString: (date: Dayjs, formatString: string) => string;
62
+ formatNumber: (numberToFormat: string) => string;
63
+ getDiff: (date: Dayjs, comparing: Dayjs, units?: AdapterUnits) => number;
64
+ isEqual: (value: any, comparing: any) => boolean;
65
+ isSameYear: (date: Dayjs, comparing: Dayjs) => boolean;
66
+ isSameMonth: (date: Dayjs, comparing: Dayjs) => boolean;
67
+ isSameDay: (date: Dayjs, comparing: Dayjs) => boolean;
68
+ isSameHour: (date: Dayjs, comparing: Dayjs) => boolean;
69
+ isAfter: (date: Dayjs, value: Dayjs) => boolean;
70
+ isAfterYear: (date: Dayjs, value: Dayjs) => boolean;
71
+ isAfterDay: (date: Dayjs, value: Dayjs) => boolean;
72
+ isBefore: (date: Dayjs, value: Dayjs) => boolean;
73
+ isBeforeYear: (date: Dayjs, value: Dayjs) => boolean;
74
+ isBeforeDay: (date: Dayjs, value: Dayjs) => boolean;
75
+ isWithinRange: (date: Dayjs, [start, end]: [Dayjs, Dayjs]) => boolean;
76
+ startOfYear: (date: Dayjs) => defaultDayjs.Dayjs;
77
+ startOfMonth: (date: Dayjs) => defaultDayjs.Dayjs;
78
+ endOfYear: (date: Dayjs) => defaultDayjs.Dayjs;
79
+ startOfWeek: (date: Dayjs) => defaultDayjs.Dayjs;
80
+ startOfDay: (date: Dayjs) => defaultDayjs.Dayjs;
81
+ endOfMonth: (date: Dayjs) => defaultDayjs.Dayjs;
82
+ endOfWeek: (date: Dayjs) => defaultDayjs.Dayjs;
83
+ endOfDay: (date: Dayjs) => defaultDayjs.Dayjs;
84
+ addYears: (date: Dayjs, count: number) => defaultDayjs.Dayjs;
85
+ addMonths: (date: Dayjs, count: number) => defaultDayjs.Dayjs;
86
+ addWeeks: (date: Dayjs, count: number) => defaultDayjs.Dayjs;
87
+ addDays: (date: Dayjs, count: number) => defaultDayjs.Dayjs;
88
+ addHours: (date: Dayjs, count: number) => defaultDayjs.Dayjs;
89
+ addMinutes: (date: Dayjs, count: number) => defaultDayjs.Dayjs;
90
+ addSeconds: (date: Dayjs, count: number) => defaultDayjs.Dayjs;
91
+ getYear: (date: Dayjs) => number;
92
+ getMonth: (date: Dayjs) => number;
93
+ getDate: (date: Dayjs) => number;
94
+ getHours: (date: Dayjs) => number;
95
+ getMinutes: (date: Dayjs) => number;
96
+ getSeconds: (date: Dayjs) => number;
97
+ setYear: (date: Dayjs, year: number) => defaultDayjs.Dayjs;
98
+ setMonth: (date: Dayjs, count: number) => defaultDayjs.Dayjs;
99
+ setDate: (date: Dayjs, count: number) => defaultDayjs.Dayjs;
100
+ setHours: (date: Dayjs, count: number) => defaultDayjs.Dayjs;
101
+ setMinutes: (date: Dayjs, count: number) => defaultDayjs.Dayjs;
102
+ setSeconds: (date: Dayjs, count: number) => defaultDayjs.Dayjs;
103
+ getDaysInMonth: (date: Dayjs) => number;
104
+ getNextMonth: (date: Dayjs) => defaultDayjs.Dayjs;
105
+ getPreviousMonth: (date: Dayjs) => defaultDayjs.Dayjs;
106
+ getMonthArray: (date: Dayjs) => defaultDayjs.Dayjs[];
107
+ mergeDateAndTime: (date: Dayjs, time: Dayjs) => defaultDayjs.Dayjs;
108
+ getWeekdays: () => string[];
109
+ getWeekArray: (date: Dayjs) => defaultDayjs.Dayjs[][];
110
+ getWeekNumber: (date: Dayjs) => number;
111
+ getYearRange: (start: Dayjs, end: Dayjs) => defaultDayjs.Dayjs[];
112
+ getMeridiemText: (ampm: 'am' | 'pm') => "AM" | "PM";
113
+ }
114
+ export {};
@@ -0,0 +1,387 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ /* eslint-disable class-methods-use-this */
3
+ import defaultDayjs from 'dayjs';
4
+ import weekOfYear from 'dayjs/plugin/weekOfYear';
5
+ import customParseFormatPlugin from 'dayjs/plugin/customParseFormat';
6
+ import localizedFormatPlugin from 'dayjs/plugin/localizedFormat';
7
+ import isBetweenPlugin from 'dayjs/plugin/isBetween';
8
+ import { buildWarning } from '../internals/utils/warning';
9
+ defaultDayjs.extend(customParseFormatPlugin);
10
+ defaultDayjs.extend(localizedFormatPlugin);
11
+ defaultDayjs.extend(isBetweenPlugin);
12
+ const localeNotFoundWarning = buildWarning(['Your locale has not been found.', 'Either the locale key is not a supported one. Locales supported by dayjs are available here: https://github.com/iamkun/dayjs/tree/dev/src/locale', "Or you forget to import the locale with `require('dayjs/locale/{localeUsed}')`", 'fallback on English locale']);
13
+ const formatTokenMap = {
14
+ // Year
15
+ YY: 'year',
16
+ YYYY: 'year',
17
+ // Month
18
+ M: 'month',
19
+ MM: 'month',
20
+ MMM: {
21
+ sectionType: 'month',
22
+ contentType: 'letter'
23
+ },
24
+ MMMM: {
25
+ sectionType: 'month',
26
+ contentType: 'letter'
27
+ },
28
+ // Day of the month
29
+ D: 'day',
30
+ DD: 'day',
31
+ Do: 'day',
32
+ // Day of the week
33
+ d: 'weekDay',
34
+ dd: {
35
+ sectionType: 'weekDay',
36
+ contentType: 'letter'
37
+ },
38
+ ddd: {
39
+ sectionType: 'weekDay',
40
+ contentType: 'letter'
41
+ },
42
+ dddd: {
43
+ sectionType: 'weekDay',
44
+ contentType: 'letter'
45
+ },
46
+ // Meridiem
47
+ A: 'meridiem',
48
+ a: 'meridiem',
49
+ // Hours
50
+ H: 'hours',
51
+ HH: 'hours',
52
+ h: 'hours',
53
+ hh: 'hours',
54
+ // Minutes
55
+ m: 'minutes',
56
+ mm: 'minutes',
57
+ // Seconds
58
+ s: 'seconds',
59
+ ss: 'seconds'
60
+ };
61
+ const defaultFormats = {
62
+ normalDateWithWeekday: 'ddd, MMM D',
63
+ normalDate: 'D MMMM',
64
+ shortDate: 'MMM D',
65
+ monthAndDate: 'MMMM D',
66
+ dayOfMonth: 'D',
67
+ year: 'YYYY',
68
+ month: 'MMMM',
69
+ monthShort: 'MMM',
70
+ monthAndYear: 'MMMM YYYY',
71
+ weekday: 'dddd',
72
+ weekdayShort: 'ddd',
73
+ minutes: 'mm',
74
+ hours12h: 'hh',
75
+ hours24h: 'HH',
76
+ seconds: 'ss',
77
+ fullTime: 'LT',
78
+ fullTime12h: 'hh:mm A',
79
+ fullTime24h: 'HH:mm',
80
+ fullDate: 'll',
81
+ fullDateWithWeekday: 'dddd, LL',
82
+ fullDateTime: 'lll',
83
+ fullDateTime12h: 'll hh:mm A',
84
+ fullDateTime24h: 'll HH:mm',
85
+ keyboardDate: 'L',
86
+ keyboardDateTime: 'L LT',
87
+ keyboardDateTime12h: 'L hh:mm A',
88
+ keyboardDateTime24h: 'L HH:mm'
89
+ };
90
+ const withLocale = (dayjs, locale) => !locale ? dayjs : (...args) => dayjs(...args).locale(locale);
91
+
92
+ /**
93
+ * Based on `@date-io/dayjs`
94
+ *
95
+ * MIT License
96
+ *
97
+ * Copyright (c) 2017 Dmitriy Kovalenko
98
+ *
99
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
100
+ * of this software and associated documentation files (the "Software"), to deal
101
+ * in the Software without restriction, including without limitation the rights
102
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
103
+ * copies of the Software, and to permit persons to whom the Software is
104
+ * furnished to do so, subject to the following conditions:
105
+ *
106
+ * The above copyright notice and this permission notice shall be included in all
107
+ * copies or substantial portions of the Software.
108
+ *
109
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
110
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
111
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
112
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
113
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
114
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
115
+ * SOFTWARE.
116
+ */
117
+ export class AdapterDayjs {
118
+ constructor({
119
+ locale: _locale,
120
+ formats,
121
+ instance
122
+ } = {}) {
123
+ this.isMUIAdapter = true;
124
+ this.rawDayJsInstance = void 0;
125
+ this.lib = 'dayjs';
126
+ this.dayjs = void 0;
127
+ this.locale = void 0;
128
+ this.formats = void 0;
129
+ this.escapedCharacters = {
130
+ start: '[',
131
+ end: ']'
132
+ };
133
+ this.formatTokenMap = formatTokenMap;
134
+ this.getLocaleFormats = () => {
135
+ var _this$rawDayJsInstanc;
136
+ const locales = (_this$rawDayJsInstanc = this.rawDayJsInstance.Ls) != null ? _this$rawDayJsInstanc : defaultDayjs.Ls;
137
+ const locale = this.locale || 'en';
138
+ let localeObject = locales[locale];
139
+ if (localeObject === undefined) {
140
+ localeNotFoundWarning();
141
+ localeObject = locales.en;
142
+ }
143
+ return localeObject.formats;
144
+ };
145
+ this.date = value => {
146
+ if (value === null) {
147
+ return null;
148
+ }
149
+ return this.dayjs(value);
150
+ };
151
+ this.toJsDate = value => {
152
+ return value.toDate();
153
+ };
154
+ this.parseISO = isoString => {
155
+ return this.dayjs(isoString);
156
+ };
157
+ this.toISO = value => {
158
+ return value.toISOString();
159
+ };
160
+ this.parse = (value, format) => {
161
+ if (value === '') {
162
+ return null;
163
+ }
164
+ return this.dayjs(value, format, this.locale, true);
165
+ };
166
+ this.getCurrentLocaleCode = () => {
167
+ return this.locale || 'en';
168
+ };
169
+ this.is12HourCycleInCurrentLocale = () => {
170
+ /* istanbul ignore next */
171
+ return /A|a/.test(this.getLocaleFormats().LT || '');
172
+ };
173
+ this.expandFormat = format => {
174
+ const localeFormats = this.getLocaleFormats();
175
+
176
+ // @see https://github.com/iamkun/dayjs/blob/dev/src/plugin/localizedFormat/index.js
177
+ const t = formatBis => formatBis.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g, (_, a, b) => a || b.slice(1));
178
+ return format.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g, (_, a, b) => {
179
+ const B = b && b.toUpperCase();
180
+ return a || localeFormats[b] || t(localeFormats[B]);
181
+ });
182
+ };
183
+ this.getFormatHelperText = format => {
184
+ return this.expandFormat(format).replace(/a/gi, '(a|p)m').toLocaleLowerCase();
185
+ };
186
+ this.isNull = date => {
187
+ return date === null;
188
+ };
189
+ this.isValid = value => {
190
+ return this.dayjs(value).isValid();
191
+ };
192
+ this.format = (date, formatKey) => {
193
+ return this.formatByString(date, this.formats[formatKey]);
194
+ };
195
+ this.formatByString = (date, formatString) => {
196
+ return this.dayjs(date).format(formatString);
197
+ };
198
+ this.formatNumber = numberToFormat => {
199
+ return numberToFormat;
200
+ };
201
+ this.getDiff = (date, comparing, units) => {
202
+ return date.diff(comparing, units);
203
+ };
204
+ this.isEqual = (value, comparing) => {
205
+ if (value === null && comparing === null) {
206
+ return true;
207
+ }
208
+ return this.dayjs(value).isSame(comparing);
209
+ };
210
+ this.isSameYear = (date, comparing) => {
211
+ return date.isSame(comparing, 'year');
212
+ };
213
+ this.isSameMonth = (date, comparing) => {
214
+ return date.isSame(comparing, 'month');
215
+ };
216
+ this.isSameDay = (date, comparing) => {
217
+ return date.isSame(comparing, 'day');
218
+ };
219
+ this.isSameHour = (date, comparing) => {
220
+ return date.isSame(comparing, 'hour');
221
+ };
222
+ this.isAfter = (date, value) => {
223
+ return date.isAfter(value);
224
+ };
225
+ this.isAfterYear = (date, value) => {
226
+ return date.isAfter(value, 'year');
227
+ };
228
+ this.isAfterDay = (date, value) => {
229
+ return date.isAfter(value, 'day');
230
+ };
231
+ this.isBefore = (date, value) => {
232
+ return date.isBefore(value);
233
+ };
234
+ this.isBeforeYear = (date, value) => {
235
+ return date.isBefore(value, 'year');
236
+ };
237
+ this.isBeforeDay = (date, value) => {
238
+ return date.isBefore(value, 'day');
239
+ };
240
+ this.isWithinRange = (date, [start, end]) => {
241
+ return date.isBetween(start, end, null, '[]');
242
+ };
243
+ this.startOfYear = date => {
244
+ return date.startOf('year');
245
+ };
246
+ this.startOfMonth = date => {
247
+ return date.startOf('month');
248
+ };
249
+ this.endOfYear = date => {
250
+ return date.endOf('year');
251
+ };
252
+ this.startOfWeek = date => {
253
+ return date.startOf('week');
254
+ };
255
+ this.startOfDay = date => {
256
+ return date.startOf('day');
257
+ };
258
+ this.endOfMonth = date => {
259
+ return date.endOf('month');
260
+ };
261
+ this.endOfWeek = date => {
262
+ return date.endOf('week');
263
+ };
264
+ this.endOfDay = date => {
265
+ return date.endOf('day');
266
+ };
267
+ this.addYears = (date, count) => {
268
+ return count < 0 ? date.subtract(Math.abs(count), 'year') : date.add(count, 'year');
269
+ };
270
+ this.addMonths = (date, count) => {
271
+ return count < 0 ? date.subtract(Math.abs(count), 'month') : date.add(count, 'month');
272
+ };
273
+ this.addWeeks = (date, count) => {
274
+ return count < 0 ? date.subtract(Math.abs(count), 'week') : date.add(count, 'week');
275
+ };
276
+ this.addDays = (date, count) => {
277
+ return count < 0 ? date.subtract(Math.abs(count), 'day') : date.add(count, 'day');
278
+ };
279
+ this.addHours = (date, count) => {
280
+ return count < 0 ? date.subtract(Math.abs(count), 'hour') : date.add(count, 'hour');
281
+ };
282
+ this.addMinutes = (date, count) => {
283
+ return count < 0 ? date.subtract(Math.abs(count), 'minute') : date.add(count, 'minute');
284
+ };
285
+ this.addSeconds = (date, count) => {
286
+ return count < 0 ? date.subtract(Math.abs(count), 'second') : date.add(count, 'second');
287
+ };
288
+ this.getYear = date => {
289
+ return date.year();
290
+ };
291
+ this.getMonth = date => {
292
+ return date.month();
293
+ };
294
+ this.getDate = date => {
295
+ return date.date();
296
+ };
297
+ this.getHours = date => {
298
+ return date.hour();
299
+ };
300
+ this.getMinutes = date => {
301
+ return date.minute();
302
+ };
303
+ this.getSeconds = date => {
304
+ return date.second();
305
+ };
306
+ this.setYear = (date, year) => {
307
+ return date.set('year', year);
308
+ };
309
+ this.setMonth = (date, count) => {
310
+ return date.set('month', count);
311
+ };
312
+ this.setDate = (date, count) => {
313
+ return date.set('date', count);
314
+ };
315
+ this.setHours = (date, count) => {
316
+ return date.set('hour', count);
317
+ };
318
+ this.setMinutes = (date, count) => {
319
+ return date.set('minute', count);
320
+ };
321
+ this.setSeconds = (date, count) => {
322
+ return date.set('second', count);
323
+ };
324
+ this.getDaysInMonth = date => {
325
+ return date.daysInMonth();
326
+ };
327
+ this.getNextMonth = date => {
328
+ return date.add(1, 'month');
329
+ };
330
+ this.getPreviousMonth = date => {
331
+ return date.subtract(1, 'month');
332
+ };
333
+ this.getMonthArray = date => {
334
+ const firstMonth = date.startOf('year');
335
+ const monthArray = [firstMonth];
336
+ while (monthArray.length < 12) {
337
+ const prevMonth = monthArray[monthArray.length - 1];
338
+ monthArray.push(this.getNextMonth(prevMonth));
339
+ }
340
+ return monthArray;
341
+ };
342
+ this.mergeDateAndTime = (date, time) => {
343
+ return date.hour(time.hour()).minute(time.minute()).second(time.second());
344
+ };
345
+ this.getWeekdays = () => {
346
+ const start = this.dayjs().startOf('week');
347
+ return [0, 1, 2, 3, 4, 5, 6].map(diff => this.formatByString(start.add(diff, 'day'), 'dd'));
348
+ };
349
+ this.getWeekArray = date => {
350
+ const start = this.dayjs(date).startOf('month').startOf('week');
351
+ const end = this.dayjs(date).endOf('month').endOf('week');
352
+ let count = 0;
353
+ let current = start;
354
+ const nestedWeeks = [];
355
+ while (current.isBefore(end)) {
356
+ const weekNumber = Math.floor(count / 7);
357
+ nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
358
+ nestedWeeks[weekNumber].push(current);
359
+ current = current.add(1, 'day');
360
+ count += 1;
361
+ }
362
+ return nestedWeeks;
363
+ };
364
+ this.getWeekNumber = date => {
365
+ return date.week();
366
+ };
367
+ this.getYearRange = (start, end) => {
368
+ const startDate = this.dayjs(start).startOf('year');
369
+ const endDate = this.dayjs(end).endOf('year');
370
+ const years = [];
371
+ let current = startDate;
372
+ while (current.isBefore(endDate)) {
373
+ years.push(current);
374
+ current = current.add(1, 'year');
375
+ }
376
+ return years;
377
+ };
378
+ this.getMeridiemText = ampm => {
379
+ return ampm === 'am' ? 'AM' : 'PM';
380
+ };
381
+ this.rawDayJsInstance = instance || defaultDayjs;
382
+ this.dayjs = withLocale(this.rawDayJsInstance, _locale);
383
+ this.locale = _locale;
384
+ this.formats = _extends({}, defaultFormats, formats);
385
+ defaultDayjs.extend(weekOfYear);
386
+ }
387
+ }
@@ -1,28 +1 @@
1
- import defaultDayjs, { Dayjs } from 'dayjs';
2
- import BaseAdapterDayjs from '@date-io/dayjs';
3
- import { FieldFormatTokenMap, MuiPickersAdapter, AdapterFormats } from '../models';
4
- interface Opts {
5
- locale?: string;
6
- /** Make sure that your dayjs instance extends customParseFormat and advancedFormat */
7
- instance?: typeof defaultDayjs;
8
- formats?: Partial<AdapterFormats>;
9
- }
10
- export declare class AdapterDayjs extends BaseAdapterDayjs implements MuiPickersAdapter<Dayjs> {
11
- isMUIAdapter: boolean;
12
- constructor(options: Opts);
13
- formatTokenMap: FieldFormatTokenMap;
14
- escapedCharacters: {
15
- start: string;
16
- end: string;
17
- };
18
- private getLocaleFormats;
19
- is12HourCycleInCurrentLocale: () => boolean;
20
- /**
21
- * The current getFormatHelperText method uses an outdated format parsing logic.
22
- * We should use this one in the future to support all localized formats.
23
- */
24
- expandFormat: (format: string) => string;
25
- getFormatHelperText: (format: string) => string;
26
- getWeekNumber: (date: Dayjs) => number;
27
- }
28
- export {};
1
+ export { AdapterDayjs } from './AdapterDayjs';
@@ -1,102 +1 @@
1
- /* eslint-disable class-methods-use-this */
2
- import defaultDayjs from 'dayjs';
3
- import weekOfYear from 'dayjs/plugin/weekOfYear';
4
- import BaseAdapterDayjs from '@date-io/dayjs';
5
- import { buildWarning } from '../internals/utils/warning';
6
- const localeNotFoundWarning = buildWarning(['Your locale has not been found.', 'Either the locale key is not a supported one. Locales supported by dayjs are available here: https://github.com/iamkun/dayjs/tree/dev/src/locale', "Or you forget to import the locale with `require('dayjs/locale/{localeUsed}')`", 'fallback on English locale']);
7
- const formatTokenMap = {
8
- // Year
9
- YY: 'year',
10
- YYYY: 'year',
11
- // Month
12
- M: 'month',
13
- MM: 'month',
14
- MMM: {
15
- sectionType: 'month',
16
- contentType: 'letter'
17
- },
18
- MMMM: {
19
- sectionType: 'month',
20
- contentType: 'letter'
21
- },
22
- // Day of the month
23
- D: 'day',
24
- DD: 'day',
25
- Do: 'day',
26
- // Day of the week
27
- d: 'weekDay',
28
- dd: {
29
- sectionType: 'weekDay',
30
- contentType: 'letter'
31
- },
32
- ddd: {
33
- sectionType: 'weekDay',
34
- contentType: 'letter'
35
- },
36
- dddd: {
37
- sectionType: 'weekDay',
38
- contentType: 'letter'
39
- },
40
- // Meridiem
41
- A: 'meridiem',
42
- a: 'meridiem',
43
- // Hours
44
- H: 'hours',
45
- HH: 'hours',
46
- h: 'hours',
47
- hh: 'hours',
48
- // Minutes
49
- m: 'minutes',
50
- mm: 'minutes',
51
- // Seconds
52
- s: 'seconds',
53
- ss: 'seconds'
54
- };
55
- export class AdapterDayjs extends BaseAdapterDayjs {
56
- constructor(options) {
57
- super(options);
58
- this.isMUIAdapter = true;
59
- this.formatTokenMap = formatTokenMap;
60
- this.escapedCharacters = {
61
- start: '[',
62
- end: ']'
63
- };
64
- this.getLocaleFormats = () => {
65
- var _this$rawDayJsInstanc;
66
- const locales = (_this$rawDayJsInstanc = this.rawDayJsInstance.Ls) != null ? _this$rawDayJsInstanc : defaultDayjs.Ls;
67
- const locale = this.locale || 'en';
68
- let localeObject = locales[locale];
69
- if (localeObject === undefined) {
70
- localeNotFoundWarning();
71
- localeObject = locales.en;
72
- }
73
- return localeObject.formats;
74
- };
75
- this.is12HourCycleInCurrentLocale = () => {
76
- /* istanbul ignore next */
77
- return /A|a/.test(this.getLocaleFormats().LT || '');
78
- };
79
- /**
80
- * The current getFormatHelperText method uses an outdated format parsing logic.
81
- * We should use this one in the future to support all localized formats.
82
- */
83
- this.expandFormat = format => {
84
- const localeFormats = this.getLocaleFormats();
85
-
86
- // @see https://github.com/iamkun/dayjs/blob/dev/src/plugin/localizedFormat/index.js
87
- const t = formatBis => formatBis.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g, (_, a, b) => a || b.slice(1));
88
- return format.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g, (_, a, b) => {
89
- const B = b && b.toUpperCase();
90
- return a || localeFormats[b] || t(localeFormats[B]);
91
- });
92
- };
93
- // Redefined here just to show how it can be written using expandFormat
94
- this.getFormatHelperText = format => {
95
- return this.expandFormat(format).replace(/a/gi, '(a|p)m').toLocaleLowerCase();
96
- };
97
- this.getWeekNumber = date => {
98
- return date.week();
99
- };
100
- defaultDayjs.extend(weekOfYear);
101
- }
102
- }
1
+ export { AdapterDayjs } from './AdapterDayjs';
package/CHANGELOG.md CHANGED
@@ -3,9 +3,61 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## 6.2.0
7
+
8
+ _Apr 13, 2023_
9
+
10
+ We'd like to offer a big thanks to the 8 contributors who made this release possible. Here are some highlights ✨:
11
+
12
+ - Add `@mui/base` as a `peerDependency` of `@mui/x-date-pickers` and `@mui/x-date-pickers-pro` (#8590) @LukasTy
13
+
14
+ Both libraries were not working correctly if used without `@mui/base`.
15
+ Most package manager should automatically use the `@mui/base` version installed for `@mui/material`.
16
+
17
+ - The value rendered in the picker or field input no longer has spaces around the `/` characters (#8425) @flaviendelangle
18
+
19
+ You can use the `formatDensity='spacious'` prop to add it back.
20
+ More information on [the dedicated doc section](https://mui.com/x/react-date-pickers/custom-field/#change-the-format-density)
21
+
22
+ - 🌍 Improve French (fr-FR) and Urdu (ur-PK) and locales.
23
+ - 🐞 Bugfixes
24
+ - 📚 Documentation improvements
25
+
26
+ ### `@mui/x-data-grid@v6.2.0` / `@mui/x-data-grid-pro@v6.2.0` / `@mui/x-data-grid-premium@v6.2.0`
27
+
28
+ #### Changes
29
+
30
+ - [DataGrid] Reset selection state on `checkboxSelection` toggle (#8522) @MBilalShafi
31
+ - [DataGrid] Use `baseSelect` slot instead of `baseTextField` with `select={true}` (#8110) @cherniavskii
32
+ - [l10n] Improve French (fr-FR) locale (#8537) @vallereaugabriel
33
+ - [l10n] Improve Urdu (ur-PK) locale (#8513) @SFARPak
34
+
35
+ ### `@mui/x-date-pickers@v6.2.0` / `@mui/x-date-pickers-pro@v6.2.0`
36
+
37
+ #### Changes
38
+
39
+ - [DateTimePicker] Fix `TimeClock` validation ignoring date by default (#8570) @LukasTy
40
+ - [fields] Fix reliance on section order (#8545) @LukasTy
41
+ - [fields] Make the space between format separators controllable (#8425) @flaviendelangle
42
+ - [pickers] Add `@mui/base` to `peerDependencies` (#8590) @LukasTy
43
+ - [pickers] Fix JSDoc for `formatDensity` prop (#8601) @flaviendelangle
44
+ - [pickers] Improve value lifecycle on non-controlled pickers (#8312) @flaviendelangle
45
+ - [pickers] Migrate `AdapterDayjs` to our repository (#8487) @flaviendelangle
46
+
47
+ ### Docs
48
+
49
+ - [docs] Fix "Custom day rendering" demo alignment (#8541) @LukasTy
50
+ - [docs] Fix **below** typo (#8576) @alexfauquette
51
+
52
+ ### Core
53
+
54
+ - [core] Optimize `renovate` rules (#8575) @LukasTy
55
+ - [core] Upgrade monorepo (#8578) @cherniavskii
56
+ - [core] Update last release date (#8569) @DanailH
57
+
6
58
  ## 6.1.0
7
59
 
8
- _Apr 7, 2023_
60
+ _Apr 10, 2023_
9
61
 
10
62
  We'd like to offer a big thanks to the 15 contributors who made this release possible. Here are some highlights ✨:
11
63