@mui/x-date-pickers 6.18.7 → 6.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/AdapterDateFns/AdapterDateFns.d.ts +3 -24
  2. package/AdapterDateFns/AdapterDateFns.js +11 -272
  3. package/AdapterDateFnsBase/AdapterDateFnsBase.d.ts +65 -0
  4. package/AdapterDateFnsBase/AdapterDateFnsBase.js +308 -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/AdapterDateFnsV3/AdapterDateFnsV3.d.ts +88 -0
  9. package/AdapterDateFnsV3/AdapterDateFnsV3.js +357 -0
  10. package/AdapterDateFnsV3/index.d.ts +1 -0
  11. package/AdapterDateFnsV3/index.js +1 -0
  12. package/AdapterDateFnsV3/package.json +6 -0
  13. package/CHANGELOG.md +42 -0
  14. package/hooks/useClearableField.d.ts +1 -1
  15. package/hooks/useClearableField.js +3 -3
  16. package/index.js +1 -1
  17. package/internals/models/helpers.d.ts +1 -0
  18. package/legacy/AdapterDateFns/AdapterDateFns.js +278 -528
  19. package/legacy/AdapterDateFnsBase/AdapterDateFnsBase.js +308 -0
  20. package/legacy/AdapterDateFnsBase/index.js +1 -0
  21. package/legacy/AdapterDateFnsV3/AdapterDateFnsV3.js +376 -0
  22. package/legacy/AdapterDateFnsV3/index.js +1 -0
  23. package/legacy/hooks/useClearableField.js +3 -3
  24. package/legacy/index.js +1 -1
  25. package/legacy/locales/index.js +1 -0
  26. package/locales/index.d.ts +1 -0
  27. package/locales/index.js +1 -0
  28. package/modern/AdapterDateFns/AdapterDateFns.js +11 -271
  29. package/modern/AdapterDateFnsBase/AdapterDateFnsBase.js +307 -0
  30. package/modern/AdapterDateFnsBase/index.js +1 -0
  31. package/modern/AdapterDateFnsV3/AdapterDateFnsV3.js +357 -0
  32. package/modern/AdapterDateFnsV3/index.js +1 -0
  33. package/modern/hooks/useClearableField.js +3 -3
  34. package/modern/index.js +1 -1
  35. package/modern/locales/index.js +1 -0
  36. package/node/AdapterDateFns/AdapterDateFns.js +11 -271
  37. package/node/AdapterDateFnsBase/AdapterDateFnsBase.js +315 -0
  38. package/node/AdapterDateFnsBase/index.js +12 -0
  39. package/node/AdapterDateFnsV3/AdapterDateFnsV3.js +366 -0
  40. package/node/AdapterDateFnsV3/index.js +12 -0
  41. package/node/hooks/useClearableField.js +3 -3
  42. package/node/index.js +1 -1
  43. package/node/locales/index.js +11 -0
  44. package/package.json +2 -2
@@ -0,0 +1,357 @@
1
+ /* eslint-disable class-methods-use-this */
2
+ // TODO remove when date-fns-v3 is the default
3
+ // @ts-nocheck
4
+ import { addDays } from 'date-fns/addDays';
5
+ import { addSeconds } from 'date-fns/addSeconds';
6
+ import { addMinutes } from 'date-fns/addMinutes';
7
+ import { addHours } from 'date-fns/addHours';
8
+ import { addWeeks } from 'date-fns/addWeeks';
9
+ import { addMonths } from 'date-fns/addMonths';
10
+ import { addYears } from 'date-fns/addYears';
11
+ import { differenceInYears } from 'date-fns/differenceInYears';
12
+ import { differenceInQuarters } from 'date-fns/differenceInQuarters';
13
+ import { differenceInMonths } from 'date-fns/differenceInMonths';
14
+ import { differenceInWeeks } from 'date-fns/differenceInWeeks';
15
+ import { differenceInDays } from 'date-fns/differenceInDays';
16
+ import { differenceInHours } from 'date-fns/differenceInHours';
17
+ import { differenceInMinutes } from 'date-fns/differenceInMinutes';
18
+ import { differenceInSeconds } from 'date-fns/differenceInSeconds';
19
+ import { differenceInMilliseconds } from 'date-fns/differenceInMilliseconds';
20
+ import { eachDayOfInterval } from 'date-fns/eachDayOfInterval';
21
+ import { endOfDay } from 'date-fns/endOfDay';
22
+ import { endOfWeek } from 'date-fns/endOfWeek';
23
+ import { endOfYear } from 'date-fns/endOfYear';
24
+ // @ts-ignore TODO remove when date-fns-v3 is the default
25
+ import { format as dateFnsFormat, longFormatters } from 'date-fns/format';
26
+ import { getDate } from 'date-fns/getDate';
27
+ import { getDaysInMonth } from 'date-fns/getDaysInMonth';
28
+ import { getHours } from 'date-fns/getHours';
29
+ import { getMinutes } from 'date-fns/getMinutes';
30
+ import { getMonth } from 'date-fns/getMonth';
31
+ import { getSeconds } from 'date-fns/getSeconds';
32
+ import { getMilliseconds } from 'date-fns/getMilliseconds';
33
+ import { getWeek } from 'date-fns/getWeek';
34
+ import { getYear } from 'date-fns/getYear';
35
+ import { isAfter } from 'date-fns/isAfter';
36
+ import { isBefore } from 'date-fns/isBefore';
37
+ import { isEqual } from 'date-fns/isEqual';
38
+ import { isSameDay } from 'date-fns/isSameDay';
39
+ import { isSameYear } from 'date-fns/isSameYear';
40
+ import { isSameMonth } from 'date-fns/isSameMonth';
41
+ import { isSameHour } from 'date-fns/isSameHour';
42
+ import { isValid } from 'date-fns/isValid';
43
+ import { parse as dateFnsParse } from 'date-fns/parse';
44
+ import { setDate } from 'date-fns/setDate';
45
+ import { setHours } from 'date-fns/setHours';
46
+ import { setMinutes } from 'date-fns/setMinutes';
47
+ import { setMonth } from 'date-fns/setMonth';
48
+ import { setSeconds } from 'date-fns/setSeconds';
49
+ import { setMilliseconds } from 'date-fns/setMilliseconds';
50
+ import { setYear } from 'date-fns/setYear';
51
+ import { startOfDay } from 'date-fns/startOfDay';
52
+ import { startOfMonth } from 'date-fns/startOfMonth';
53
+ import { endOfMonth } from 'date-fns/endOfMonth';
54
+ import { startOfWeek } from 'date-fns/startOfWeek';
55
+ import { startOfYear } from 'date-fns/startOfYear';
56
+ import { formatISO } from 'date-fns/formatISO';
57
+ import { parseISO } from 'date-fns/parseISO';
58
+ import { isWithinInterval } from 'date-fns/isWithinInterval';
59
+ import { enUS } from 'date-fns/locale/en-US';
60
+ // date-fns v2 does not export types
61
+ // @ts-ignore TODO remove when date-fns-v3 is the default
62
+ import { AdapterDateFnsBase } from '../AdapterDateFnsBase';
63
+
64
+ /**
65
+ * Based on `@date-io/date-fns`
66
+ *
67
+ * MIT License
68
+ *
69
+ * Copyright (c) 2017 Dmitriy Kovalenko
70
+ *
71
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
72
+ * of this software and associated documentation files (the "Software"), to deal
73
+ * in the Software without restriction, including without limitation the rights
74
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
75
+ * copies of the Software, and to permit persons to whom the Software is
76
+ * furnished to do so, subject to the following conditions:
77
+ *
78
+ * The above copyright notice and this permission notice shall be included in all
79
+ * copies or substantial portions of the Software.
80
+ *
81
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
82
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
83
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
84
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
85
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
86
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
87
+ * SOFTWARE.
88
+ */
89
+ export class AdapterDateFns extends AdapterDateFnsBase {
90
+ constructor({
91
+ locale,
92
+ formats
93
+ } = {}) {
94
+ if (typeof addDays !== 'function') {
95
+ throw new Error([`MUI: The \`date-fns\` package v2.x is not compatible with this adapter.`, 'Please, install v3.x of the package or use the `AdapterDateFns` instead.'].join('\n'));
96
+ }
97
+ if (!longFormatters) {
98
+ throw new Error('MUI: The minimum supported `date-fns` package version compatible with this adapter is `3.2.x`.');
99
+ }
100
+ super({
101
+ locale: locale != null ? locale : enUS,
102
+ formats,
103
+ longFormatters
104
+ });
105
+ this.parseISO = isoString => {
106
+ return parseISO(isoString);
107
+ };
108
+ this.toISO = value => {
109
+ return formatISO(value, {
110
+ format: 'extended'
111
+ });
112
+ };
113
+ this.parse = (value, format) => {
114
+ if (value === '') {
115
+ return null;
116
+ }
117
+ return dateFnsParse(value, format, new Date(), {
118
+ locale: this.locale
119
+ });
120
+ };
121
+ this.isValid = value => {
122
+ return isValid(this.date(value));
123
+ };
124
+ this.format = (value, formatKey) => {
125
+ return this.formatByString(value, this.formats[formatKey]);
126
+ };
127
+ this.formatByString = (value, formatString) => {
128
+ return dateFnsFormat(value, formatString, {
129
+ locale: this.locale
130
+ });
131
+ };
132
+ this.getDiff = (value, comparing, unit) => {
133
+ switch (unit) {
134
+ case 'years':
135
+ return differenceInYears(value, this.date(comparing));
136
+ case 'quarters':
137
+ return differenceInQuarters(value, this.date(comparing));
138
+ case 'months':
139
+ return differenceInMonths(value, this.date(comparing));
140
+ case 'weeks':
141
+ return differenceInWeeks(value, this.date(comparing));
142
+ case 'days':
143
+ return differenceInDays(value, this.date(comparing));
144
+ case 'hours':
145
+ return differenceInHours(value, this.date(comparing));
146
+ case 'minutes':
147
+ return differenceInMinutes(value, this.date(comparing));
148
+ case 'seconds':
149
+ return differenceInSeconds(value, this.date(comparing));
150
+ default:
151
+ {
152
+ return differenceInMilliseconds(value, this.date(comparing));
153
+ }
154
+ }
155
+ };
156
+ this.isEqual = (value, comparing) => {
157
+ if (value === null && comparing === null) {
158
+ return true;
159
+ }
160
+ return isEqual(value, comparing);
161
+ };
162
+ this.isSameYear = (value, comparing) => {
163
+ return isSameYear(value, comparing);
164
+ };
165
+ this.isSameMonth = (value, comparing) => {
166
+ return isSameMonth(value, comparing);
167
+ };
168
+ this.isSameDay = (value, comparing) => {
169
+ return isSameDay(value, comparing);
170
+ };
171
+ this.isSameHour = (value, comparing) => {
172
+ return isSameHour(value, comparing);
173
+ };
174
+ this.isAfter = (value, comparing) => {
175
+ return isAfter(value, comparing);
176
+ };
177
+ this.isAfterYear = (value, comparing) => {
178
+ return isAfter(value, endOfYear(comparing));
179
+ };
180
+ this.isAfterDay = (value, comparing) => {
181
+ return isAfter(value, endOfDay(comparing));
182
+ };
183
+ this.isBefore = (value, comparing) => {
184
+ return isBefore(value, comparing);
185
+ };
186
+ this.isBeforeYear = (value, comparing) => {
187
+ return isBefore(value, this.startOfYear(comparing));
188
+ };
189
+ this.isBeforeDay = (value, comparing) => {
190
+ return isBefore(value, this.startOfDay(comparing));
191
+ };
192
+ this.isWithinRange = (value, [start, end]) => {
193
+ return isWithinInterval(value, {
194
+ start,
195
+ end
196
+ });
197
+ };
198
+ this.startOfYear = value => {
199
+ return startOfYear(value);
200
+ };
201
+ this.startOfMonth = value => {
202
+ return startOfMonth(value);
203
+ };
204
+ this.startOfWeek = value => {
205
+ return startOfWeek(value, {
206
+ locale: this.locale
207
+ });
208
+ };
209
+ this.startOfDay = value => {
210
+ return startOfDay(value);
211
+ };
212
+ this.endOfYear = value => {
213
+ return endOfYear(value);
214
+ };
215
+ this.endOfMonth = value => {
216
+ return endOfMonth(value);
217
+ };
218
+ this.endOfWeek = value => {
219
+ return endOfWeek(value, {
220
+ locale: this.locale
221
+ });
222
+ };
223
+ this.endOfDay = value => {
224
+ return endOfDay(value);
225
+ };
226
+ this.addYears = (value, amount) => {
227
+ return addYears(value, amount);
228
+ };
229
+ this.addMonths = (value, amount) => {
230
+ return addMonths(value, amount);
231
+ };
232
+ this.addWeeks = (value, amount) => {
233
+ return addWeeks(value, amount);
234
+ };
235
+ this.addDays = (value, amount) => {
236
+ return addDays(value, amount);
237
+ };
238
+ this.addHours = (value, amount) => {
239
+ return addHours(value, amount);
240
+ };
241
+ this.addMinutes = (value, amount) => {
242
+ return addMinutes(value, amount);
243
+ };
244
+ this.addSeconds = (value, amount) => {
245
+ return addSeconds(value, amount);
246
+ };
247
+ this.getYear = value => {
248
+ return getYear(value);
249
+ };
250
+ this.getMonth = value => {
251
+ return getMonth(value);
252
+ };
253
+ this.getDate = value => {
254
+ return getDate(value);
255
+ };
256
+ this.getHours = value => {
257
+ return getHours(value);
258
+ };
259
+ this.getMinutes = value => {
260
+ return getMinutes(value);
261
+ };
262
+ this.getSeconds = value => {
263
+ return getSeconds(value);
264
+ };
265
+ this.getMilliseconds = value => {
266
+ return getMilliseconds(value);
267
+ };
268
+ this.setYear = (value, year) => {
269
+ return setYear(value, year);
270
+ };
271
+ this.setMonth = (value, month) => {
272
+ return setMonth(value, month);
273
+ };
274
+ this.setDate = (value, date) => {
275
+ return setDate(value, date);
276
+ };
277
+ this.setHours = (value, hours) => {
278
+ return setHours(value, hours);
279
+ };
280
+ this.setMinutes = (value, minutes) => {
281
+ return setMinutes(value, minutes);
282
+ };
283
+ this.setSeconds = (value, seconds) => {
284
+ return setSeconds(value, seconds);
285
+ };
286
+ this.setMilliseconds = (value, milliseconds) => {
287
+ return setMilliseconds(value, milliseconds);
288
+ };
289
+ this.getDaysInMonth = value => {
290
+ return getDaysInMonth(value);
291
+ };
292
+ this.getNextMonth = value => {
293
+ return addMonths(value, 1);
294
+ };
295
+ this.getPreviousMonth = value => {
296
+ return addMonths(value, -1);
297
+ };
298
+ this.getMonthArray = value => {
299
+ const firstMonth = startOfYear(value);
300
+ const monthArray = [firstMonth];
301
+ while (monthArray.length < 12) {
302
+ const prevMonth = monthArray[monthArray.length - 1];
303
+ monthArray.push(this.getNextMonth(prevMonth));
304
+ }
305
+ return monthArray;
306
+ };
307
+ this.mergeDateAndTime = (dateParam, timeParam) => {
308
+ return this.setSeconds(this.setMinutes(this.setHours(dateParam, this.getHours(timeParam)), this.getMinutes(timeParam)), this.getSeconds(timeParam));
309
+ };
310
+ this.getWeekdays = () => {
311
+ const now = new Date();
312
+ return eachDayOfInterval({
313
+ start: startOfWeek(now, {
314
+ locale: this.locale
315
+ }),
316
+ end: endOfWeek(now, {
317
+ locale: this.locale
318
+ })
319
+ }).map(day => this.formatByString(day, 'EEEEEE'));
320
+ };
321
+ this.getWeekArray = value => {
322
+ const start = startOfWeek(startOfMonth(value), {
323
+ locale: this.locale
324
+ });
325
+ const end = endOfWeek(endOfMonth(value), {
326
+ locale: this.locale
327
+ });
328
+ let count = 0;
329
+ let current = start;
330
+ const nestedWeeks = [];
331
+ while (isBefore(current, end)) {
332
+ const weekNumber = Math.floor(count / 7);
333
+ nestedWeeks[weekNumber] = nestedWeeks[weekNumber] || [];
334
+ nestedWeeks[weekNumber].push(current);
335
+ current = addDays(current, 1);
336
+ count += 1;
337
+ }
338
+ return nestedWeeks;
339
+ };
340
+ this.getWeekNumber = value => {
341
+ return getWeek(value, {
342
+ locale: this.locale
343
+ });
344
+ };
345
+ this.getYearRange = (start, end) => {
346
+ const startDate = startOfYear(start);
347
+ const endDate = endOfYear(end);
348
+ const years = [];
349
+ let current = startDate;
350
+ while (isBefore(current, endDate)) {
351
+ years.push(current);
352
+ current = addYears(current, 1);
353
+ }
354
+ return years;
355
+ };
356
+ }
357
+ }
@@ -0,0 +1 @@
1
+ export { AdapterDateFns } from './AdapterDateFnsV3';
@@ -0,0 +1 @@
1
+ export { AdapterDateFns } from './AdapterDateFnsV3';
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "./index.js",
4
+ "main": "../node/AdapterDateFnsV3/index.js",
5
+ "types": "./index.d.ts"
6
+ }
package/CHANGELOG.md CHANGED
@@ -3,6 +3,48 @@
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.19.0
7
+
8
+ _Jan 11, 2024_
9
+
10
+ We'd like to offer a big thanks to the 3 contributors who made this release possible. Here are some highlights ✨:
11
+
12
+ - ⏰ Support date-fns v3 (#11659) @LukasTy
13
+ Pickers support both v2 and v3 of date-fns. For v3 use `AdapterDateFnsV3`.
14
+ ```js
15
+ // with date-fns v2.x
16
+ import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
17
+ import de from 'date-fns/locale/de';
18
+ ```
19
+ ```js
20
+ // with date-fns v3.x
21
+ import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFnsV3';
22
+ import { de } from 'date-fns/locale/de';
23
+ ```
24
+
25
+ ### Date Pickers
26
+
27
+ #### `@mui/x-date-pickers@6.19.0`
28
+
29
+ - [pickers] Add date-fns@3.x adapter (#11659) @LukasTy
30
+ - [pickers] Fix clearable behavior blocking focus return to `OpenPickerButton` (#11643) @noraleonte
31
+ - [l10n] Add missing Danish (da-DK) locale export (#11641) @etlos
32
+
33
+ #### `@mui/x-date-pickers-pro@6.19.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
34
+
35
+ Same changes as in `@mui/x-date-pickers@6.19.0`.
36
+
37
+ ### Docs
38
+
39
+ - [docs] Add missing component @oliviertassinari
40
+ - [docs] Fix parsing of `x-date-pickers-pro` demo adapter imports (#11637) @LukasTy
41
+ - [docs] Push up the MUI X brand (#11533) @oliviertassinari
42
+ - [docs] Improve Server-side data grid docs (#11589) @oliviertassinari
43
+ - [docs] Add demo to the charts overview page (#11586) @danilo-leal
44
+ - [docs] Fix 404 links in the docs @oliviertassinari
45
+ - [docs] Improve landing page (#11570) @oliviertassinari
46
+ - [docs] Give a general revision to the docs (#11249) @danilo-leal
47
+
6
48
  ## 6.18.7
7
49
 
8
50
  _Jan 5, 2024_
@@ -18,7 +18,7 @@ export declare const useClearableField: <TFieldProps extends FieldsTextFieldProp
18
18
  endAdornment?: React.ReactNode;
19
19
  } | undefined, TFieldSlotsComponents extends FieldSlotsComponents, TFieldSlotsComponentsProps extends FieldSlotsComponentsProps>({ clearable, fieldProps: forwardedFieldProps, InputProps: ForwardedInputProps, onClear, slots, slotProps, components, componentsProps, }: UseClearableFieldProps<TFieldProps, TInputProps, TFieldSlotsComponents, TFieldSlotsComponentsProps>) => {
20
20
  InputProps: TInputProps & {
21
- endAdornment: string | number | boolean | Iterable<React.ReactNode> | React.JSX.Element | null | undefined;
21
+ endAdornment: React.JSX.Element;
22
22
  };
23
23
  fieldProps: TFieldProps;
24
24
  };
@@ -40,8 +40,8 @@ export const useClearableField = ({
40
40
  ownerState: {}
41
41
  });
42
42
  const InputProps = _extends({}, ForwardedInputProps, {
43
- endAdornment: clearable ? /*#__PURE__*/_jsxs(React.Fragment, {
44
- children: [/*#__PURE__*/_jsx(InputAdornment, {
43
+ endAdornment: /*#__PURE__*/_jsxs(React.Fragment, {
44
+ children: [clearable && /*#__PURE__*/_jsx(InputAdornment, {
45
45
  position: "end",
46
46
  sx: {
47
47
  marginRight: ForwardedInputProps != null && ForwardedInputProps.endAdornment ? -1 : -1.5
@@ -53,7 +53,7 @@ export const useClearableField = ({
53
53
  }, endClearIconProps))
54
54
  }))
55
55
  }), ForwardedInputProps == null ? void 0 : ForwardedInputProps.endAdornment]
56
- }) : ForwardedInputProps == null ? void 0 : ForwardedInputProps.endAdornment
56
+ })
57
57
  });
58
58
  const fieldProps = _extends({}, forwardedFieldProps, {
59
59
  sx: [{
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-date-pickers v6.18.7
2
+ * @mui/x-date-pickers v6.19.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -5,4 +5,5 @@
5
5
  */
6
6
  export type ExtendMui<C, Removals extends keyof C = never> = Omit<C, 'classes' | 'theme' | Removals>;
7
7
  export type MakeOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
8
+ export type MakeRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
8
9
  export type DefaultizedProps<P extends {}, RequiredProps extends keyof P, AdditionalProps extends {} = {}> = Omit<P, RequiredProps | keyof AdditionalProps> & Required<Pick<P, RequiredProps>> & AdditionalProps;