@mui/x-date-pickers 5.0.0-beta.7 → 5.0.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 (144) hide show
  1. package/AdapterDateFns/index.d.ts +7 -1
  2. package/AdapterDateFns/index.js +51 -1
  3. package/AdapterDayjs/index.d.ts +12 -1
  4. package/AdapterDayjs/index.js +45 -1
  5. package/CHANGELOG.md +78 -1
  6. package/CalendarPicker/CalendarPicker.d.ts +4 -1
  7. package/CalendarPicker/CalendarPicker.js +40 -10
  8. package/CalendarPicker/DayPicker.d.ts +2 -1
  9. package/CalendarPicker/DayPicker.js +100 -4
  10. package/CalendarPicker/PickersCalendarHeader.d.ts +8 -0
  11. package/CalendarPicker/useCalendarState.d.ts +10 -4
  12. package/CalendarPicker/useCalendarState.js +4 -3
  13. package/ClockPicker/ClockPicker.d.ts +3 -8
  14. package/DateField/DateField.interfaces.d.ts +4 -4
  15. package/DateField/index.d.ts +1 -1
  16. package/DateField/useDateField.d.ts +1 -1
  17. package/DateField/useDateField.js +35 -4
  18. package/DateTimePicker/DateTimePicker.js +2 -1
  19. package/DateTimePicker/DateTimePickerTabs.d.ts +20 -4
  20. package/DateTimePicker/DateTimePickerTabs.js +34 -5
  21. package/DateTimePicker/DateTimePickerToolbar.js +54 -68
  22. package/DateTimePicker/index.d.ts +2 -0
  23. package/DateTimePicker/index.js +2 -1
  24. package/DateTimePicker/shared.d.ts +2 -1
  25. package/DesktopDateTimePicker/DesktopDateTimePicker.js +13 -5
  26. package/MobileDateTimePicker/MobileDateTimePicker.js +13 -5
  27. package/MonthPicker/MonthPicker.d.ts +4 -0
  28. package/MonthPicker/MonthPicker.js +87 -10
  29. package/MonthPicker/PickersMonth.d.ts +6 -2
  30. package/MonthPicker/PickersMonth.js +23 -4
  31. package/PickersDay/PickersDay.d.ts +4 -2
  32. package/PickersDay/PickersDay.js +13 -74
  33. package/StaticDateTimePicker/StaticDateTimePicker.js +12 -5
  34. package/YearPicker/PickersYear.d.ts +3 -0
  35. package/YearPicker/PickersYear.js +11 -4
  36. package/YearPicker/YearPicker.d.ts +3 -0
  37. package/YearPicker/YearPicker.js +42 -8
  38. package/index.js +1 -1
  39. package/internals/components/CalendarOrClockPicker/CalendarOrClockPicker.d.ts +8 -0
  40. package/internals/components/CalendarOrClockPicker/CalendarOrClockPicker.js +26 -4
  41. package/internals/components/CalendarOrClockPicker/useFocusManagement.d.ts +10 -0
  42. package/internals/components/CalendarOrClockPicker/useFocusManagement.js +18 -0
  43. package/internals/components/PickersArrowSwitcher.d.ts +16 -0
  44. package/internals/components/PickersModalDialog.d.ts +2 -2
  45. package/internals/components/PureDateInput.d.ts +4 -0
  46. package/internals/components/PureDateInput.js +1 -1
  47. package/internals/components/wrappers/WrapperProps.d.ts +8 -0
  48. package/internals/hooks/useField/index.d.ts +1 -1
  49. package/internals/hooks/useField/useField.d.ts +2 -2
  50. package/internals/hooks/useField/useField.interfaces.d.ts +24 -20
  51. package/internals/hooks/useField/useField.js +44 -15
  52. package/internals/hooks/useField/useField.utils.d.ts +8 -8
  53. package/internals/hooks/useField/useField.utils.js +14 -52
  54. package/internals/hooks/validation/useDateValidation.d.ts +1 -0
  55. package/internals/hooks/validation/useDateValidation.js +1 -3
  56. package/internals/index.d.ts +0 -2
  57. package/internals/index.js +0 -1
  58. package/internals/models/muiPickersAdapter.d.ts +8 -0
  59. package/internals/models/props/baseToolbarProps.d.ts +0 -1
  60. package/internals-fields/index.d.ts +2 -0
  61. package/internals-fields/index.js +3 -0
  62. package/internals-fields/package.json +6 -0
  63. package/legacy/AdapterDateFns/index.js +76 -1
  64. package/legacy/AdapterDayjs/index.js +74 -1
  65. package/legacy/CalendarPicker/CalendarPicker.js +49 -9
  66. package/legacy/CalendarPicker/DayPicker.js +109 -5
  67. package/legacy/CalendarPicker/useCalendarState.js +4 -3
  68. package/legacy/DateField/useDateField.js +33 -4
  69. package/legacy/DateTimePicker/DateTimePicker.js +2 -1
  70. package/legacy/DateTimePicker/DateTimePickerTabs.js +34 -5
  71. package/legacy/DateTimePicker/DateTimePickerToolbar.js +60 -74
  72. package/legacy/DateTimePicker/index.js +2 -1
  73. package/legacy/DesktopDateTimePicker/DesktopDateTimePicker.js +15 -4
  74. package/legacy/MobileDateTimePicker/MobileDateTimePicker.js +15 -4
  75. package/legacy/MonthPicker/MonthPicker.js +100 -8
  76. package/legacy/MonthPicker/PickersMonth.js +28 -3
  77. package/legacy/PickersDay/PickersDay.js +22 -75
  78. package/legacy/StaticDateTimePicker/StaticDateTimePicker.js +14 -4
  79. package/legacy/YearPicker/PickersYear.js +16 -3
  80. package/legacy/YearPicker/YearPicker.js +50 -8
  81. package/legacy/index.js +1 -1
  82. package/legacy/internals/components/CalendarOrClockPicker/CalendarOrClockPicker.js +25 -3
  83. package/legacy/internals/components/CalendarOrClockPicker/useFocusManagement.js +27 -0
  84. package/legacy/internals/components/PureDateInput.js +1 -1
  85. package/legacy/internals/hooks/useField/useField.js +64 -26
  86. package/legacy/internals/hooks/useField/useField.utils.js +14 -52
  87. package/legacy/internals/hooks/validation/useDateValidation.js +1 -3
  88. package/legacy/internals/index.js +0 -1
  89. package/legacy/internals-fields/index.js +3 -0
  90. package/modern/AdapterDateFns/index.js +51 -1
  91. package/modern/AdapterDayjs/index.js +43 -1
  92. package/modern/CalendarPicker/CalendarPicker.js +40 -10
  93. package/modern/CalendarPicker/DayPicker.js +100 -4
  94. package/modern/CalendarPicker/useCalendarState.js +4 -3
  95. package/modern/DateField/useDateField.js +35 -4
  96. package/modern/DateTimePicker/DateTimePicker.js +2 -1
  97. package/modern/DateTimePicker/DateTimePickerTabs.js +34 -5
  98. package/modern/DateTimePicker/DateTimePickerToolbar.js +54 -68
  99. package/modern/DateTimePicker/index.js +2 -1
  100. package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +13 -5
  101. package/modern/MobileDateTimePicker/MobileDateTimePicker.js +13 -5
  102. package/modern/MonthPicker/MonthPicker.js +87 -10
  103. package/modern/MonthPicker/PickersMonth.js +21 -4
  104. package/modern/PickersDay/PickersDay.js +13 -74
  105. package/modern/StaticDateTimePicker/StaticDateTimePicker.js +12 -5
  106. package/modern/YearPicker/PickersYear.js +11 -4
  107. package/modern/YearPicker/YearPicker.js +42 -8
  108. package/modern/index.js +1 -1
  109. package/modern/internals/components/CalendarOrClockPicker/CalendarOrClockPicker.js +24 -4
  110. package/modern/internals/components/CalendarOrClockPicker/useFocusManagement.js +18 -0
  111. package/modern/internals/components/PureDateInput.js +1 -1
  112. package/modern/internals/hooks/useField/useField.js +42 -15
  113. package/modern/internals/hooks/useField/useField.utils.js +14 -52
  114. package/modern/internals/hooks/validation/useDateValidation.js +1 -3
  115. package/modern/internals/index.js +0 -1
  116. package/modern/internals-fields/index.js +3 -0
  117. package/node/AdapterDateFns/index.js +57 -6
  118. package/node/AdapterDayjs/index.js +49 -6
  119. package/node/CalendarPicker/CalendarPicker.js +39 -9
  120. package/node/CalendarPicker/DayPicker.js +100 -3
  121. package/node/CalendarPicker/useCalendarState.js +4 -3
  122. package/node/DateField/useDateField.js +35 -3
  123. package/node/DateTimePicker/DateTimePicker.js +2 -1
  124. package/node/DateTimePicker/DateTimePickerTabs.js +32 -4
  125. package/node/DateTimePicker/DateTimePickerToolbar.js +54 -70
  126. package/node/DateTimePicker/index.js +9 -1
  127. package/node/DesktopDateTimePicker/DesktopDateTimePicker.js +13 -5
  128. package/node/MobileDateTimePicker/MobileDateTimePicker.js +13 -5
  129. package/node/MonthPicker/MonthPicker.js +87 -9
  130. package/node/MonthPicker/PickersMonth.js +26 -6
  131. package/node/PickersDay/PickersDay.js +12 -73
  132. package/node/StaticDateTimePicker/StaticDateTimePicker.js +13 -5
  133. package/node/YearPicker/PickersYear.js +11 -4
  134. package/node/YearPicker/YearPicker.js +43 -8
  135. package/node/index.js +1 -1
  136. package/node/internals/components/CalendarOrClockPicker/CalendarOrClockPicker.js +27 -4
  137. package/node/internals/components/CalendarOrClockPicker/useFocusManagement.js +32 -0
  138. package/node/internals/components/PureDateInput.js +1 -1
  139. package/node/internals/hooks/useField/useField.js +44 -15
  140. package/node/internals/hooks/useField/useField.utils.js +16 -56
  141. package/node/internals/hooks/validation/useDateValidation.js +3 -1
  142. package/node/internals/index.js +0 -26
  143. package/node/internals-fields/index.js +31 -0
  144. package/package.json +1 -1
@@ -2,8 +2,8 @@ import * as React from 'react';
2
2
  import { DialogProps as MuiDialogProps } from '@mui/material/Dialog';
3
3
  import { PickersActionBarProps } from '../../PickersActionBar';
4
4
  import { PickerStateWrapperProps } from '../hooks/usePickerState';
5
- export interface PickersModalDialogSlotsComponent {
6
- ActionBar: React.ElementType<PickersActionBarProps>;
5
+ import { PickersSlotsComponent } from './wrappers/WrapperProps';
6
+ export interface PickersModalDialogSlotsComponent extends Omit<PickersSlotsComponent, 'PaperContent'> {
7
7
  }
8
8
  export interface PickersModalDialogSlotsComponentsProps {
9
9
  actionBar: Omit<PickersActionBarProps, 'onAccept' | 'onClear' | 'onCancel' | 'onSetToday'>;
@@ -5,6 +5,10 @@ import { InputAdornmentProps } from '@mui/material/InputAdornment';
5
5
  import { MuiPickersAdapter } from '../models';
6
6
  export declare type MuiTextFieldProps = MuiTextFieldPropsType | Omit<MuiTextFieldPropsType, 'variant'>;
7
7
  export interface DateInputSlotsComponent {
8
+ /**
9
+ * Icon displayed in the open picker button.
10
+ * @default Calendar or Clock
11
+ */
8
12
  OpenPickerIcon: React.ElementType;
9
13
  }
10
14
  export interface DateInputProps<TInputDate, TDate> {
@@ -43,7 +43,7 @@ export const PureDateInput = /*#__PURE__*/React.forwardRef(function PureDateInpu
43
43
  'aria-label': getOpenDialogAriaText(rawValue, utils),
44
44
  value: inputValue
45
45
  }, !props.readOnly && {
46
- onClick: onOpen
46
+ onMouseDown: onOpen
47
47
  }, {
48
48
  onKeyDown: onSpaceOrEnter(onOpen)
49
49
  })
@@ -6,7 +6,15 @@ export interface DateInputPropsLike extends Omit<DateInputProps<any, any>, 'rend
6
6
  validationError?: any;
7
7
  }
8
8
  export interface PickersSlotsComponent {
9
+ /**
10
+ * The action bar placed bellow picker views.
11
+ * @default PickersActionBar
12
+ */
9
13
  ActionBar: React.ElementType<PickersActionBarProps>;
14
+ /**
15
+ * The content of the Paper wrapping views.
16
+ * @default React.Fragment
17
+ */
10
18
  PaperContent: React.ElementType<{
11
19
  children: React.ReactNode;
12
20
  }>;
@@ -1,3 +1,3 @@
1
1
  export { useField } from './useField';
2
- export type { FieldValueManager, FieldSection, UseFieldProps, UseFieldParams, UseFieldResponse, } from './useField.interfaces';
2
+ export type { FieldValueManager, FieldSection, UseFieldInternalProps, UseFieldParams, UseFieldResponse, } from './useField.interfaces';
3
3
  export { splitFormatIntoSections, addPositionPropertiesToSections, createDateStrFromSections, } from './useField.utils';
@@ -1,2 +1,2 @@
1
- import { FieldSection, UseFieldParams, UseFieldProps, UseFieldResponse } from './useField.interfaces';
2
- export declare const useField: <TInputValue, TValue, TDate, TSection extends FieldSection, TProps extends UseFieldProps<any, any, any>>(params: UseFieldParams<TInputValue, TValue, TDate, TSection, TProps>) => UseFieldResponse<TProps>;
1
+ import { FieldSection, UseFieldParams, UseFieldResponse, UseFieldForwardedProps, UseFieldInternalProps } from './useField.interfaces';
2
+ export declare const useField: <TInputValue, TValue, TDate, TSection extends FieldSection, TForwardedProps extends UseFieldForwardedProps, TInternalProps extends UseFieldInternalProps<any, any, any>>(params: UseFieldParams<TInputValue, TValue, TDate, TSection, TForwardedProps, TInternalProps>) => UseFieldResponse<TForwardedProps>;
@@ -1,15 +1,15 @@
1
1
  import * as React from 'react';
2
- import { MuiPickersAdapter } from '../../models';
2
+ import { MuiDateSectionName, MuiPickerFieldAdapter } from '../../models';
3
3
  import { PickerStateValueManager } from '../usePickerState';
4
4
  import { InferError, Validator } from '../validation/useValidation';
5
- export declare type DateSectionName = 'day' | 'month' | 'year' | 'hour' | 'minute' | 'second' | 'am-pm';
6
- export interface UseFieldParams<TInputValue, TValue, TDate, TSection extends FieldSection, TProps extends UseFieldProps<any, any, any>> {
7
- props: TProps;
5
+ export interface UseFieldParams<TInputValue, TValue, TDate, TSection extends FieldSection, TForwardedProps extends UseFieldForwardedProps, TInternalProps extends UseFieldInternalProps<any, any, any>> {
6
+ forwardedProps: TForwardedProps;
7
+ internalProps: TInternalProps;
8
8
  valueManager: PickerStateValueManager<TInputValue, TValue, TDate>;
9
- fieldValueManager: FieldValueManager<TValue, TDate, TSection, InferError<TProps>>;
10
- validator: Validator<TDate, UseFieldValidationProps<TInputValue, TProps>>;
9
+ fieldValueManager: FieldValueManager<TValue, TDate, TSection, InferError<TInternalProps>>;
10
+ validator: Validator<TDate, UseFieldValidationProps<TInputValue, TInternalProps>>;
11
11
  }
12
- export interface UseFieldProps<TInputValue, TValue, TError> {
12
+ export interface UseFieldInternalProps<TInputValue, TValue, TError> {
13
13
  value?: TInputValue;
14
14
  onChange?: (value: TValue) => void;
15
15
  onError?: (error: TError, value: TInputValue) => void;
@@ -25,31 +25,34 @@ export interface UseFieldProps<TInputValue, TValue, TError> {
25
25
  */
26
26
  readOnly?: boolean;
27
27
  }
28
- export interface UseFieldResponse<TProps> {
29
- inputProps: Omit<TProps, keyof UseFieldProps<any, any, any>> & {
30
- value: string;
31
- onClick: React.MouseEventHandler<HTMLInputElement>;
32
- onKeyDown: React.KeyboardEventHandler<HTMLInputElement>;
33
- onFocus: () => void;
34
- onBlur: () => void;
35
- error: boolean;
36
- };
28
+ export interface UseFieldForwardedProps {
29
+ onKeyDown?: React.KeyboardEventHandler;
30
+ onClick?: () => void;
31
+ onFocus?: () => void;
32
+ onBlur?: () => void;
33
+ }
34
+ export interface UseFieldResponse<TForwardedProps extends UseFieldForwardedProps> {
35
+ inputProps: UseFieldResponseInputProps<TForwardedProps>;
37
36
  inputRef: React.RefObject<HTMLInputElement>;
38
37
  }
38
+ export declare type UseFieldResponseInputProps<TForwardedProps extends UseFieldForwardedProps> = Omit<TForwardedProps, keyof UseFieldForwardedProps> & NonNullable<UseFieldForwardedProps> & {
39
+ value: string;
40
+ error: boolean;
41
+ };
39
42
  export interface FieldSection {
40
43
  start: number;
41
44
  end: number;
42
45
  value: string;
43
46
  emptyValue: string;
44
47
  separator: string | null;
45
- dateSectionName: DateSectionName;
48
+ dateSectionName: MuiDateSectionName;
46
49
  formatValue: string;
47
50
  query: string | null;
48
51
  }
49
52
  export interface FieldValueManager<TValue, TDate, TSection extends FieldSection, TError> {
50
- getSectionsFromValue: (utils: MuiPickersAdapter<TDate>, prevSections: TSection[] | null, value: TValue, format: string) => TSection[];
53
+ getSectionsFromValue: (utils: MuiPickerFieldAdapter<TDate>, prevSections: TSection[] | null, value: TValue, format: string) => TSection[];
51
54
  getValueStrFromSections: (sections: TSection[]) => string;
52
- getValueFromSections: (utils: MuiPickersAdapter<TDate>, prevSections: TSection[], sections: TSection[], format: string) => {
55
+ getValueFromSections: (utils: MuiPickerFieldAdapter<TDate>, prevSections: TSection[], sections: TSection[], format: string) => {
53
56
  value: TValue;
54
57
  shouldPublish: boolean;
55
58
  };
@@ -58,6 +61,7 @@ export interface FieldValueManager<TValue, TDate, TSection extends FieldSection,
58
61
  update: (newActiveDate: TDate | null) => TValue;
59
62
  };
60
63
  hasError: (error: TError) => boolean;
64
+ isSameError: (error: TError, prevError: TError | null) => boolean;
61
65
  }
62
66
  export interface UseFieldState<TValue, TSections> {
63
67
  valueStr: string;
@@ -68,7 +72,7 @@ export interface UseFieldState<TValue, TSections> {
68
72
  end: number;
69
73
  } | null;
70
74
  }
71
- export declare type UseFieldValidationProps<TInputValue, TProps extends UseFieldProps<any, any, any>> = Omit<TProps, 'value' | 'defaultValue'> & {
75
+ export declare type UseFieldValidationProps<TInputValue, TInternalProps extends UseFieldInternalProps<any, any, any>> = Omit<TInternalProps, 'value' | 'defaultValue'> & {
72
76
  value: TInputValue;
73
77
  };
74
78
  export declare type AvailableAdjustKeyCode = 'ArrowUp' | 'ArrowDown' | 'PageUp' | 'PageDown' | 'Home' | 'End';
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["value", "defaultValue", "onChange", "onError", "format", "readOnly"];
3
+ const _excluded = ["onClick", "onKeyDown", "onFocus", "onBlur"];
4
4
  import * as React from 'react';
5
5
  import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
6
6
  import useEventCallback from '@mui/utils/useEventCallback';
@@ -9,23 +9,35 @@ import { useUtils } from '../useUtils';
9
9
  import { cleanTrailingZeroInNumericSectionValue, getMonthsMatchingQuery, getSectionValueNumericBoundaries, getSectionVisibleValue, adjustDateSectionValue, adjustInvalidDateSectionValue, setSectionValue } from './useField.utils';
10
10
  export const useField = params => {
11
11
  const utils = useUtils();
12
+
13
+ if (!utils.formatTokenMap) {
14
+ throw new Error('This adapter is not compatible with the field components');
15
+ }
16
+
12
17
  const inputRef = React.useRef(null);
13
18
 
14
19
  const {
15
- props: {
20
+ internalProps: {
16
21
  value: valueProp,
17
22
  defaultValue,
18
23
  onChange,
19
24
  format = utils.formats.keyboardDate,
20
25
  readOnly = false
21
26
  },
27
+ forwardedProps: {
28
+ onClick,
29
+ onKeyDown,
30
+ onFocus,
31
+ onBlur
32
+ },
22
33
  valueManager,
23
34
  fieldValueManager,
24
35
  validator
25
36
  } = params,
26
- otherProps = _objectWithoutPropertiesLoose(params.props, _excluded);
37
+ otherForwardedProps = _objectWithoutPropertiesLoose(params.forwardedProps, _excluded);
27
38
 
28
39
  const firstDefaultValue = React.useRef(defaultValue);
40
+ const focusTimeoutRef = React.useRef(undefined);
29
41
  const valueParsed = React.useMemo(() => {
30
42
  var _ref, _firstDefaultValue$cu;
31
43
 
@@ -69,7 +81,9 @@ export const useField = params => {
69
81
  }));
70
82
  };
71
83
 
72
- const handleInputClick = useEventCallback(() => {
84
+ const handleInputClick = useEventCallback((...args) => {
85
+ onClick == null ? void 0 : onClick(...args);
86
+
73
87
  if (state.sections.length === 0) {
74
88
  return;
75
89
  }
@@ -82,7 +96,25 @@ export const useField = params => {
82
96
  const sectionIndex = nextSectionIndex === -1 ? state.sections.length - 1 : nextSectionIndex - 1;
83
97
  updateSelectedSections(sectionIndex);
84
98
  });
99
+ const handleInputFocus = useEventCallback((...args) => {
100
+ onFocus == null ? void 0 : onFocus(...args);
101
+ focusTimeoutRef.current = setTimeout(() => {
102
+ var _inputRef$current$sel2, _inputRef$current2, _inputRef$current$sel3, _inputRef$current3;
103
+
104
+ if (((_inputRef$current$sel2 = (_inputRef$current2 = inputRef.current) == null ? void 0 : _inputRef$current2.selectionEnd) != null ? _inputRef$current$sel2 : 0) - ((_inputRef$current$sel3 = (_inputRef$current3 = inputRef.current) == null ? void 0 : _inputRef$current3.selectionStart) != null ? _inputRef$current$sel3 : 0) === 0) {
105
+ handleInputClick();
106
+ } else {
107
+ updateSelectedSections(0, state.sections.length - 1);
108
+ }
109
+ });
110
+ });
111
+ const handleInputBlur = useEventCallback((...args) => {
112
+ onBlur == null ? void 0 : onBlur(...args);
113
+ updateSelectedSections();
114
+ });
85
115
  const handleInputKeyDown = useEventCallback(event => {
116
+ onKeyDown == null ? void 0 : onKeyDown(event);
117
+
86
118
  if (!inputRef.current || state.sections.length === 0) {
87
119
  return;
88
120
  } // eslint-disable-next-line default-case
@@ -235,11 +267,6 @@ export const useField = params => {
235
267
  }
236
268
  }
237
269
  });
238
- const handleInputFocus = useEventCallback(() => {
239
- // TODO: Avoid applying focus when focus is caused by a click
240
- updateSelectedSections(0, state.sections.length - 1);
241
- });
242
- const handleInputBlur = useEventCallback(() => updateSelectedSections());
243
270
  useEnhancedEffect(() => {
244
271
  if (!inputRef.current || state.selectedSectionIndexes == null) {
245
272
  return;
@@ -265,22 +292,24 @@ export const useField = params => {
265
292
  }));
266
293
  }
267
294
  }, [valueParsed]); // eslint-disable-line react-hooks/exhaustive-deps
268
- // TODO: Support `isSameError`.
269
295
  // TODO: Make validation work with TDate instead of TInputDate
270
296
 
271
- const validationError = useValidation(_extends({}, params.props, {
297
+ const validationError = useValidation(_extends({}, params.internalProps, {
272
298
  value: state.valueParsed
273
- }), validator, () => true);
299
+ }), validator, fieldValueManager.isSameError);
274
300
  const inputError = React.useMemo(() => fieldValueManager.hasError(validationError), [fieldValueManager, validationError]);
301
+ React.useEffect(() => {
302
+ return () => window.clearTimeout(focusTimeoutRef.current);
303
+ }, []);
275
304
  return {
276
- inputProps: _extends({
305
+ inputProps: _extends({}, otherForwardedProps, {
277
306
  value: state.valueStr,
278
307
  onClick: handleInputClick,
279
- onKeyDown: handleInputKeyDown,
280
308
  onFocus: handleInputFocus,
281
309
  onBlur: handleInputBlur,
310
+ onKeyDown: handleInputKeyDown,
282
311
  error: inputError
283
- }, otherProps),
312
+ }),
284
313
  inputRef
285
314
  };
286
315
  };
@@ -1,15 +1,15 @@
1
- import { FieldSection, DateSectionName, AvailableAdjustKeyCode } from './useField.interfaces';
2
- import { MuiPickersAdapter } from '../../models';
3
- export declare const getDateSectionNameFromFormat: (format: string) => DateSectionName;
4
- export declare const adjustDateSectionValue: <TDate>(utils: MuiPickersAdapter<TDate>, date: TDate, datePartName: DateSectionName, keyCode: AvailableAdjustKeyCode) => TDate;
5
- export declare const adjustInvalidDateSectionValue: <TDate, TSection extends FieldSection>(utils: MuiPickersAdapter<TDate>, section: TSection, keyCode: AvailableAdjustKeyCode) => string;
1
+ import { FieldSection, AvailableAdjustKeyCode } from './useField.interfaces';
2
+ import { MuiPickerFieldAdapter, MuiDateSectionName } from '../../models';
3
+ export declare const getDateSectionNameFromFormatToken: <TDate>(utils: MuiPickerFieldAdapter<TDate>, formatToken: string) => MuiDateSectionName;
4
+ export declare const adjustDateSectionValue: <TDate>(utils: MuiPickerFieldAdapter<TDate>, date: TDate, dateSectionName: MuiDateSectionName, keyCode: AvailableAdjustKeyCode) => TDate;
5
+ export declare const adjustInvalidDateSectionValue: <TDate, TSection extends FieldSection>(utils: MuiPickerFieldAdapter<TDate>, section: TSection, keyCode: AvailableAdjustKeyCode) => string;
6
6
  export declare const getSectionVisibleValue: (section: Omit<FieldSection, 'start' | 'end'>) => string;
7
7
  export declare const addPositionPropertiesToSections: <TSection extends FieldSection>(sections: Omit<TSection, "end" | "start">[]) => TSection[];
8
- export declare const splitFormatIntoSections: <TDate>(utils: MuiPickersAdapter<TDate>, format: string, date: TDate | null) => Omit<FieldSection, "end" | "start">[];
8
+ export declare const splitFormatIntoSections: <TDate>(utils: MuiPickerFieldAdapter<TDate>, format: string, date: TDate | null) => Omit<FieldSection, "end" | "start">[];
9
9
  export declare const createDateStrFromSections: (sections: FieldSection[]) => string;
10
10
  export declare const setSectionValue: <TSection extends FieldSection>(sections: TSection[], sectionIndex: number, sectionNewValue: string, sectionNewQuery?: string | null) => TSection[];
11
- export declare const getMonthsMatchingQuery: <TDate>(utils: MuiPickersAdapter<TDate>, format: string, query: string) => string[];
12
- export declare const getSectionValueNumericBoundaries: <TDate>(utils: MuiPickersAdapter<TDate>, date: TDate, dateSectionName: DateSectionName) => {
11
+ export declare const getMonthsMatchingQuery: <TDate>(utils: MuiPickerFieldAdapter<TDate>, format: string, query: string) => string[];
12
+ export declare const getSectionValueNumericBoundaries: <TDate>(utils: MuiPickerFieldAdapter<TDate>, date: TDate, dateSectionName: MuiDateSectionName) => {
13
13
  minimum: number;
14
14
  maximum: number;
15
15
  };
@@ -1,38 +1,13 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
- import defaultLocale from 'date-fns/locale/en-US'; // @ts-ignore
3
-
4
- import longFormatters from 'date-fns/_lib/format/longFormatters';
5
2
  // TODO: Improve and test with different calendars (move to date-io ?)
6
- export const getDateSectionNameFromFormat = format => {
7
- if (['MMMM', 'MM'].includes(format)) {
8
- return 'month';
9
- }
3
+ export const getDateSectionNameFromFormatToken = (utils, formatToken) => {
4
+ const dateSectionName = utils.formatTokenMap[formatToken];
10
5
 
11
- if (['y', 'yy', 'yyy', 'yyyy'].includes(format)) {
12
- return 'year';
6
+ if (dateSectionName == null) {
7
+ throw new Error(`getDatePartNameFromFormat doesn't understand the format ${formatToken}`);
13
8
  }
14
9
 
15
- if (['dd'].includes(format)) {
16
- return 'day';
17
- }
18
-
19
- if (['h', 'H', 'hh', 'HH'].includes(format)) {
20
- return 'hour';
21
- }
22
-
23
- if (['mm'].includes(format)) {
24
- return 'minute';
25
- }
26
-
27
- if (['ss'].includes(format)) {
28
- return 'second';
29
- }
30
-
31
- if (['a', 'aa', 'aaa'].includes(format)) {
32
- return 'am-pm';
33
- }
34
-
35
- throw new Error(`getDatePartNameFromFormat don't understand the format ${format}`);
10
+ return dateSectionName;
36
11
  };
37
12
 
38
13
  const getDeltaFromKeyCode = keyCode => {
@@ -54,12 +29,12 @@ const getDeltaFromKeyCode = keyCode => {
54
29
  }
55
30
  };
56
31
 
57
- export const adjustDateSectionValue = (utils, date, datePartName, keyCode) => {
32
+ export const adjustDateSectionValue = (utils, date, dateSectionName, keyCode) => {
58
33
  const delta = getDeltaFromKeyCode(keyCode);
59
34
  const isStart = keyCode === 'Home';
60
35
  const isEnd = keyCode === 'End';
61
36
 
62
- switch (datePartName) {
37
+ switch (dateSectionName) {
63
38
  case 'day':
64
39
  {
65
40
  if (isStart) {
@@ -295,24 +270,11 @@ const formatDateWithPlaceholder = (utils, date, format) => {
295
270
 
296
271
  export const splitFormatIntoSections = (utils, format, date) => {
297
272
  let currentTokenValue = '';
298
- const sections = []; // Copy pasted from the `getFormatHelperText` in the date-fns adapter
299
- // Would need to be turned into an adapter method
300
-
301
- const longFormatRegexp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
302
- const locale = utils.locale || defaultLocale;
303
- const cleanFormat = format.match(longFormatRegexp).map(token => {
304
- const firstCharacter = token[0];
305
-
306
- if (firstCharacter === 'p' || firstCharacter === 'P') {
307
- const longFormatter = longFormatters[firstCharacter];
308
- return longFormatter(token, locale.formatLong, {});
309
- }
310
-
311
- return token;
312
- }).join('');
273
+ const sections = [];
274
+ const expandedFormat = utils.expandFormat(format);
313
275
 
314
- for (let i = 0; i < cleanFormat.length; i += 1) {
315
- const char = cleanFormat[i];
276
+ for (let i = 0; i < expandedFormat.length; i += 1) {
277
+ const char = expandedFormat[i];
316
278
 
317
279
  if (!char.match(/([A-zÀ-ú]+)/g)) {
318
280
  if (currentTokenValue === '') {
@@ -324,7 +286,7 @@ export const splitFormatIntoSections = (utils, format, date) => {
324
286
  sections[sections.length - 1].separator += currentTokenValue;
325
287
  currentTokenValue = '';
326
288
  } else {
327
- const dateSectionName = getDateSectionNameFromFormat(currentTokenValue);
289
+ const dateSectionName = getDateSectionNameFromFormatToken(utils, currentTokenValue);
328
290
  sections.push({
329
291
  formatValue: currentTokenValue,
330
292
  value: dateForCurrentToken,
@@ -340,13 +302,13 @@ export const splitFormatIntoSections = (utils, format, date) => {
340
302
  currentTokenValue += char;
341
303
  }
342
304
 
343
- if (i === cleanFormat.length - 1) {
305
+ if (i === expandedFormat.length - 1) {
344
306
  const dateForCurrentToken = formatDateWithPlaceholder(utils, date, currentTokenValue);
345
307
 
346
308
  if (dateForCurrentToken === currentTokenValue) {
347
309
  sections[sections.length - 1].separator += currentTokenValue;
348
310
  } else {
349
- const dateSectionName = getDateSectionNameFromFormat(currentTokenValue);
311
+ const dateSectionName = getDateSectionNameFromFormatToken(utils, currentTokenValue);
350
312
  sections.push({
351
313
  formatValue: currentTokenValue,
352
314
  value: dateForCurrentToken,
@@ -7,4 +7,5 @@ export interface DateValidationProps<TInputDate, TDate> extends ValidationProps<
7
7
  export declare type DateValidationError = 'invalidDate' | 'shouldDisableDate' | 'disableFuture' | 'disablePast' | 'minDate' | 'maxDate' | null;
8
8
  export declare const validateDate: Validator<any, DateValidationProps<any, any>>;
9
9
  export declare const useIsDayDisabled: <TDate>({ shouldDisableDate, minDate, maxDate, disableFuture, disablePast, }: DayValidationProps<TDate> & Required<BaseDateValidationProps<TDate>>) => (day: TDate | null) => boolean;
10
+ export declare const isSameDateError: (a: DateValidationError, b: DateValidationError) => boolean;
10
11
  export declare const useDateValidation: <TInputDate, TDate>(props: DateValidationProps<TInputDate, TDate>) => DateValidationError;
@@ -59,7 +59,5 @@ export const useIsDayDisabled = ({
59
59
  }
60
60
  }) !== null, [adapter, shouldDisableDate, minDate, maxDate, disableFuture, disablePast]);
61
61
  };
62
-
63
- const isSameDateError = (a, b) => a === b;
64
-
62
+ export const isSameDateError = (a, b) => a === b;
65
63
  export const useDateValidation = props => useValidation(props, validateDate, isSameDateError);
@@ -14,8 +14,6 @@ export type { DateInputPropsLike } from './components/wrappers/WrapperProps';
14
14
  export { WrapperVariantContext } from './components/wrappers/WrapperVariantContext';
15
15
  export type { WrapperVariant } from './components/wrappers/WrapperVariantContext';
16
16
  export { DAY_MARGIN } from './constants/dimensions';
17
- export { useField, createDateStrFromSections, addPositionPropertiesToSections, splitFormatIntoSections, } from './hooks/useField';
18
- export type { UseFieldProps, UseFieldParams, UseFieldResponse, FieldValueManager, FieldSection, } from './hooks/useField';
19
17
  export { useMaskedInput } from './hooks/useMaskedInput';
20
18
  export { usePickerState } from './hooks/usePickerState';
21
19
  export type { PickerStateProps, PickerStatePickerProps } from './hooks/usePickerState';
@@ -7,7 +7,6 @@ export { PickersToolbar, pickersToolbarClasses } from './components/PickersToolb
7
7
  export { PickersToolbarButton } from './components/PickersToolbarButton';
8
8
  export { WrapperVariantContext } from './components/wrappers/WrapperVariantContext';
9
9
  export { DAY_MARGIN } from './constants/dimensions';
10
- export { useField, createDateStrFromSections, addPositionPropertiesToSections, splitFormatIntoSections } from './hooks/useField';
11
10
  export { useMaskedInput } from './hooks/useMaskedInput';
12
11
  export { usePickerState } from './hooks/usePickerState';
13
12
  export { useDefaultDates, useUtils, useLocaleText } from './hooks/useUtils';
@@ -1,2 +1,10 @@
1
1
  import { IUtils } from '@date-io/core/IUtils';
2
2
  export declare type MuiPickersAdapter<TDate> = IUtils<TDate>;
3
+ export declare type MuiDateSectionName = 'day' | 'month' | 'year' | 'hour' | 'minute' | 'second' | 'am-pm';
4
+ export declare type MuiFormatTokenMap = {
5
+ [formatToken: string]: MuiDateSectionName;
6
+ };
7
+ export interface MuiPickerFieldAdapter<TDate> extends MuiPickersAdapter<TDate> {
8
+ formatTokenMap: MuiFormatTokenMap;
9
+ expandFormat: (format: string) => string;
10
+ }
@@ -15,7 +15,6 @@ export interface BaseToolbarProps<TDate, TValue> extends ExportedCalendarPickerP
15
15
  * @returns {string} The arial label
16
16
  */
17
17
  getMobileKeyboardInputViewButtonText?: (isKeyboardInputOpen: boolean, viewType: 'calendar' | 'clock') => string;
18
- hideTabs?: boolean;
19
18
  isLandscape: boolean;
20
19
  onChange: PickerOnChangeFn<TDate>;
21
20
  openView: CalendarOrClockPickerView;
@@ -0,0 +1,2 @@
1
+ export { useField, createDateStrFromSections, addPositionPropertiesToSections, splitFormatIntoSections, } from '../internals/hooks/useField';
2
+ export type { UseFieldInternalProps, UseFieldParams, UseFieldResponse, FieldValueManager, FieldSection, } from '../internals/hooks/useField';
@@ -0,0 +1,3 @@
1
+ // We don't add those exports to the regular `@mui/x-date-pickers/internals`,
2
+ // Because they rely on date-fns, which is not used by all applications.
3
+ export { useField, createDateStrFromSections, addPositionPropertiesToSections, splitFormatIntoSections } from '../internals/hooks/useField';
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "./index.js",
4
+ "main": "../node/internals-fields/index.js",
5
+ "types": "./index.d.ts"
6
+ }
@@ -1 +1,76 @@
1
- export { default as AdapterDateFns } from '@date-io/date-fns';
1
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
2
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
4
+ import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
5
+ import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
6
+
7
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
8
+
9
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
10
+
11
+ import BaseAdapterDateFns from '@date-io/date-fns';
12
+ import defaultLocale from 'date-fns/locale/en-US'; // @ts-ignore
13
+
14
+ import longFormatters from 'date-fns/_lib/format/longFormatters';
15
+ var formatTokenMap = {
16
+ y: 'year',
17
+ yy: 'year',
18
+ yyy: 'year',
19
+ yyyy: 'year',
20
+ MMMM: 'month',
21
+ MM: 'month',
22
+ DD: 'day',
23
+ d: 'day',
24
+ dd: 'day',
25
+ H: 'hour',
26
+ HH: 'hour',
27
+ h: 'hour',
28
+ hh: 'hour',
29
+ mm: 'minute',
30
+ ss: 'second',
31
+ a: 'am-pm',
32
+ aa: 'am-pm',
33
+ aaa: 'am-pm'
34
+ };
35
+ export var AdapterDateFns = /*#__PURE__*/function (_BaseAdapterDateFns) {
36
+ _inherits(AdapterDateFns, _BaseAdapterDateFns);
37
+
38
+ var _super = _createSuper(AdapterDateFns);
39
+
40
+ function AdapterDateFns() {
41
+ var _this;
42
+
43
+ _classCallCheck(this, AdapterDateFns);
44
+
45
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
46
+ args[_key] = arguments[_key];
47
+ }
48
+
49
+ _this = _super.call.apply(_super, [this].concat(args));
50
+ _this.formatTokenMap = formatTokenMap;
51
+
52
+ _this.expandFormat = function (format) {
53
+ var longFormatRegexp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g; // @see https://github.com/date-fns/date-fns/blob/master/src/format/index.js#L31
54
+
55
+ return format.match(longFormatRegexp).map(function (token) {
56
+ var firstCharacter = token[0];
57
+
58
+ if (firstCharacter === 'p' || firstCharacter === 'P') {
59
+ var longFormatter = longFormatters[firstCharacter];
60
+ var locale = _this.locale || defaultLocale;
61
+ return longFormatter(token, locale.formatLong, {});
62
+ }
63
+
64
+ return token;
65
+ }).join('');
66
+ };
67
+
68
+ _this.getFormatHelperText = function (format) {
69
+ return _this.expandFormat(format).replace(/(aaa|aa|a)/g, '(a|p)m').toLocaleLowerCase();
70
+ };
71
+
72
+ return _this;
73
+ }
74
+
75
+ return _createClass(AdapterDateFns);
76
+ }(BaseAdapterDateFns);
@@ -1 +1,74 @@
1
- export { default as AdapterDayjs } from '@date-io/dayjs';
1
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
2
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
4
+ import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
5
+ import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
6
+
7
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
8
+
9
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
10
+
11
+ import BaseAdapterDayjs from '@date-io/dayjs';
12
+ var formatTokenMap = {
13
+ YY: 'year',
14
+ YYYY: 'year',
15
+ M: 'month',
16
+ MM: 'month',
17
+ MMM: 'month',
18
+ MMMM: 'month',
19
+ D: 'day',
20
+ DD: 'day',
21
+ H: 'hour',
22
+ HH: 'hour',
23
+ h: 'hour',
24
+ hh: 'hour',
25
+ m: 'minute',
26
+ mm: 'minute',
27
+ s: 'second',
28
+ ss: 'second',
29
+ A: 'am-pm',
30
+ a: 'am-pm'
31
+ };
32
+ export var AdapterDayjs = /*#__PURE__*/function (_BaseAdapterDayjs) {
33
+ _inherits(AdapterDayjs, _BaseAdapterDayjs);
34
+
35
+ var _super = _createSuper(AdapterDayjs);
36
+
37
+ function AdapterDayjs() {
38
+ var _this;
39
+
40
+ _classCallCheck(this, AdapterDayjs);
41
+
42
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
43
+ args[_key] = arguments[_key];
44
+ }
45
+
46
+ _this = _super.call.apply(_super, [this].concat(args));
47
+ _this.formatTokenMap = formatTokenMap;
48
+
49
+ _this.expandFormat = function (format) {
50
+ var _this$rawDayJsInstanc;
51
+
52
+ var localeFormats = (_this$rawDayJsInstanc = _this.rawDayJsInstance.Ls[_this.locale || 'en']) == null ? void 0 : _this$rawDayJsInstanc.formats; // @see https://github.com/iamkun/dayjs/blob/dev/src/plugin/localizedFormat/index.js
53
+
54
+ var t = function t(formatBis) {
55
+ return formatBis.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g, function (_, a, b) {
56
+ return a || b.slice(1);
57
+ });
58
+ };
59
+
60
+ return format.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g, function (_, a, b) {
61
+ var B = b && b.toUpperCase();
62
+ return a || localeFormats[b] || t(localeFormats[B]);
63
+ });
64
+ };
65
+
66
+ _this.getFormatHelperText = function (format) {
67
+ return _this.expandFormat(format).replace(/a/gi, '(a|p)m').toLocaleLowerCase();
68
+ };
69
+
70
+ return _this;
71
+ }
72
+
73
+ return _createClass(AdapterDayjs);
74
+ }(BaseAdapterDayjs);