@mui/x-date-pickers 8.0.0-beta.0 → 8.0.0-beta.1
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.
- package/CHANGELOG.md +77 -0
- package/DateCalendar/DayCalendar.d.ts +3 -7
- package/DateCalendar/DayCalendar.js +16 -8
- package/DateCalendar/index.d.ts +0 -1
- package/DateField/useDateField.d.ts +1 -1
- package/DateField/useDateField.js +2 -16
- package/DatePicker/DatePicker.js +1 -0
- package/DateTimeField/useDateTimeField.d.ts +1 -1
- package/DateTimeField/useDateTimeField.js +2 -16
- package/DateTimePicker/DateTimePicker.js +1 -0
- package/DesktopDatePicker/DesktopDatePicker.js +1 -0
- package/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -0
- package/DesktopTimePicker/DesktopTimePicker.js +1 -0
- package/MobileDatePicker/MobileDatePicker.js +1 -0
- package/MobileDateTimePicker/MobileDateTimePicker.js +1 -0
- package/MobileTimePicker/MobileTimePicker.js +1 -0
- package/PickersDay/PickersDay.d.ts +1 -72
- package/PickersDay/PickersDay.js +30 -28
- package/PickersDay/PickersDay.types.d.ts +114 -0
- package/PickersDay/PickersDay.types.js +5 -0
- package/PickersDay/index.d.ts +1 -1
- package/PickersDay/usePickerDayOwnerState.d.ts +14 -0
- package/PickersDay/usePickerDayOwnerState.js +40 -0
- package/TimeField/useTimeField.d.ts +1 -1
- package/TimeField/useTimeField.js +2 -16
- package/TimePicker/TimePicker.js +1 -0
- package/esm/DateCalendar/DayCalendar.d.ts +3 -7
- package/esm/DateCalendar/DayCalendar.js +16 -8
- package/esm/DateCalendar/index.d.ts +0 -1
- package/esm/DateField/useDateField.d.ts +1 -1
- package/esm/DateField/useDateField.js +3 -17
- package/esm/DatePicker/DatePicker.js +1 -0
- package/esm/DateTimeField/useDateTimeField.d.ts +1 -1
- package/esm/DateTimeField/useDateTimeField.js +3 -17
- package/esm/DateTimePicker/DateTimePicker.js +1 -0
- package/esm/DesktopDatePicker/DesktopDatePicker.js +1 -0
- package/esm/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -0
- package/esm/DesktopTimePicker/DesktopTimePicker.js +1 -0
- package/esm/MobileDatePicker/MobileDatePicker.js +1 -0
- package/esm/MobileDateTimePicker/MobileDateTimePicker.js +1 -0
- package/esm/MobileTimePicker/MobileTimePicker.js +1 -0
- package/esm/PickersDay/PickersDay.d.ts +1 -72
- package/esm/PickersDay/PickersDay.js +30 -28
- package/esm/PickersDay/PickersDay.types.d.ts +114 -0
- package/esm/PickersDay/PickersDay.types.js +1 -0
- package/esm/PickersDay/index.d.ts +1 -1
- package/esm/PickersDay/usePickerDayOwnerState.d.ts +14 -0
- package/esm/PickersDay/usePickerDayOwnerState.js +32 -0
- package/esm/TimeField/useTimeField.d.ts +1 -1
- package/esm/TimeField/useTimeField.js +3 -17
- package/esm/TimePicker/TimePicker.js +1 -0
- package/esm/hooks/useSplitFieldProps.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/internals/components/PickerFieldUI.d.ts +5 -5
- package/esm/internals/hooks/useField/buildSectionsFromFormat.d.ts +2 -2
- package/esm/internals/hooks/useField/buildSectionsFromFormat.js +9 -9
- package/esm/internals/hooks/useField/index.d.ts +1 -1
- package/esm/internals/hooks/useField/useField.d.ts +2 -4
- package/esm/internals/hooks/useField/useField.js +5 -229
- package/esm/internals/hooks/useField/useField.types.d.ts +48 -68
- package/esm/internals/hooks/useField/useField.utils.d.ts +2 -5
- package/esm/internals/hooks/useField/useField.utils.js +7 -92
- package/esm/internals/hooks/useField/useFieldCharacterEditing.d.ts +19 -26
- package/esm/internals/hooks/useField/useFieldCharacterEditing.js +42 -60
- package/esm/internals/hooks/useField/useFieldRootHandleKeyDown.d.ts +16 -0
- package/esm/internals/hooks/useField/useFieldRootHandleKeyDown.js +204 -0
- package/esm/internals/hooks/useField/useFieldState.d.ts +23 -13
- package/esm/internals/hooks/useField/useFieldState.js +103 -30
- package/esm/internals/hooks/useField/useFieldV6TextField.d.ts +3 -3
- package/esm/internals/hooks/useField/useFieldV6TextField.js +202 -135
- package/esm/internals/hooks/useField/useFieldV7TextField.d.ts +3 -2
- package/esm/internals/hooks/useField/useFieldV7TextField.js +217 -153
- package/esm/internals/hooks/usePicker/usePicker.types.d.ts +1 -0
- package/esm/internals/index.d.ts +2 -1
- package/esm/internals/index.js +1 -0
- package/esm/managers/useDateManager.js +3 -3
- package/esm/managers/useDateTimeManager.js +3 -3
- package/esm/managers/useTimeManager.js +3 -3
- package/esm/models/fields.d.ts +2 -2
- package/esm/models/manager.d.ts +3 -2
- package/hooks/useSplitFieldProps.d.ts +1 -1
- package/index.js +1 -1
- package/internals/components/PickerFieldUI.d.ts +5 -5
- package/internals/hooks/useField/buildSectionsFromFormat.d.ts +2 -2
- package/internals/hooks/useField/buildSectionsFromFormat.js +9 -9
- package/internals/hooks/useField/index.d.ts +1 -1
- package/internals/hooks/useField/useField.d.ts +2 -4
- package/internals/hooks/useField/useField.js +5 -231
- package/internals/hooks/useField/useField.types.d.ts +48 -68
- package/internals/hooks/useField/useField.utils.d.ts +2 -5
- package/internals/hooks/useField/useField.utils.js +8 -94
- package/internals/hooks/useField/useFieldCharacterEditing.d.ts +19 -26
- package/internals/hooks/useField/useFieldCharacterEditing.js +41 -59
- package/internals/hooks/useField/useFieldRootHandleKeyDown.d.ts +16 -0
- package/internals/hooks/useField/useFieldRootHandleKeyDown.js +210 -0
- package/internals/hooks/useField/useFieldState.d.ts +23 -13
- package/internals/hooks/useField/useFieldState.js +102 -29
- package/internals/hooks/useField/useFieldV6TextField.d.ts +3 -3
- package/internals/hooks/useField/useFieldV6TextField.js +202 -135
- package/internals/hooks/useField/useFieldV7TextField.d.ts +3 -2
- package/internals/hooks/useField/useFieldV7TextField.js +218 -154
- package/internals/hooks/usePicker/usePicker.types.d.ts +1 -0
- package/internals/index.d.ts +2 -1
- package/internals/index.js +7 -0
- package/managers/useDateManager.js +3 -3
- package/managers/useDateTimeManager.js +3 -3
- package/managers/useTimeManager.js +3 -3
- package/models/fields.d.ts +2 -2
- package/models/manager.d.ts +3 -2
- package/modern/DateCalendar/DayCalendar.d.ts +3 -7
- package/modern/DateCalendar/DayCalendar.js +16 -8
- package/modern/DateCalendar/index.d.ts +0 -1
- package/modern/DateField/useDateField.d.ts +1 -1
- package/modern/DateField/useDateField.js +3 -17
- package/modern/DatePicker/DatePicker.js +1 -0
- package/modern/DateTimeField/useDateTimeField.d.ts +1 -1
- package/modern/DateTimeField/useDateTimeField.js +3 -17
- package/modern/DateTimePicker/DateTimePicker.js +1 -0
- package/modern/DesktopDatePicker/DesktopDatePicker.js +1 -0
- package/modern/DesktopDateTimePicker/DesktopDateTimePicker.js +1 -0
- package/modern/DesktopTimePicker/DesktopTimePicker.js +1 -0
- package/modern/MobileDatePicker/MobileDatePicker.js +1 -0
- package/modern/MobileDateTimePicker/MobileDateTimePicker.js +1 -0
- package/modern/MobileTimePicker/MobileTimePicker.js +1 -0
- package/modern/PickersDay/PickersDay.d.ts +1 -72
- package/modern/PickersDay/PickersDay.js +30 -28
- package/modern/PickersDay/PickersDay.types.d.ts +114 -0
- package/modern/PickersDay/PickersDay.types.js +1 -0
- package/modern/PickersDay/index.d.ts +1 -1
- package/modern/PickersDay/usePickerDayOwnerState.d.ts +14 -0
- package/modern/PickersDay/usePickerDayOwnerState.js +32 -0
- package/modern/TimeField/useTimeField.d.ts +1 -1
- package/modern/TimeField/useTimeField.js +3 -17
- package/modern/TimePicker/TimePicker.js +1 -0
- package/modern/hooks/useSplitFieldProps.d.ts +1 -1
- package/modern/index.js +1 -1
- package/modern/internals/components/PickerFieldUI.d.ts +5 -5
- package/modern/internals/hooks/useField/buildSectionsFromFormat.d.ts +2 -2
- package/modern/internals/hooks/useField/buildSectionsFromFormat.js +9 -9
- package/modern/internals/hooks/useField/index.d.ts +1 -1
- package/modern/internals/hooks/useField/useField.d.ts +2 -4
- package/modern/internals/hooks/useField/useField.js +5 -229
- package/modern/internals/hooks/useField/useField.types.d.ts +48 -68
- package/modern/internals/hooks/useField/useField.utils.d.ts +2 -5
- package/modern/internals/hooks/useField/useField.utils.js +7 -92
- package/modern/internals/hooks/useField/useFieldCharacterEditing.d.ts +19 -26
- package/modern/internals/hooks/useField/useFieldCharacterEditing.js +42 -60
- package/modern/internals/hooks/useField/useFieldRootHandleKeyDown.d.ts +16 -0
- package/modern/internals/hooks/useField/useFieldRootHandleKeyDown.js +204 -0
- package/modern/internals/hooks/useField/useFieldState.d.ts +23 -13
- package/modern/internals/hooks/useField/useFieldState.js +103 -30
- package/modern/internals/hooks/useField/useFieldV6TextField.d.ts +3 -3
- package/modern/internals/hooks/useField/useFieldV6TextField.js +202 -135
- package/modern/internals/hooks/useField/useFieldV7TextField.d.ts +3 -2
- package/modern/internals/hooks/useField/useFieldV7TextField.js +217 -153
- package/modern/internals/hooks/usePicker/usePicker.types.d.ts +1 -0
- package/modern/internals/index.d.ts +2 -1
- package/modern/internals/index.js +1 -0
- package/modern/managers/useDateManager.js +3 -3
- package/modern/managers/useDateTimeManager.js +3 -3
- package/modern/managers/useTimeManager.js +3 -3
- package/modern/models/fields.d.ts +2 -2
- package/modern/models/manager.d.ts +3 -2
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { FieldSectionType, FieldSection, FieldSelectedSections, MuiPickersAdapter, TimezoneProps, FieldSectionContentType, PickerValidDate, FieldRef, OnErrorProps,
|
|
3
|
-
import
|
|
4
|
-
import type { Validator } from '../../../validation';
|
|
5
|
-
import type { UseFieldStateResponse } from './useFieldState';
|
|
6
|
-
import type { UseFieldCharacterEditingResponse } from './useFieldCharacterEditing';
|
|
2
|
+
import { FieldSectionType, FieldSection, FieldSelectedSections, MuiPickersAdapter, TimezoneProps, FieldSectionContentType, PickerValidDate, FieldRef, OnErrorProps, InferFieldSection, PickerManager, PickerValueType } from "../../../models/index.js";
|
|
3
|
+
import { InternalPropNames } from "../../../hooks/useSplitFieldProps.js";
|
|
7
4
|
import { PickersSectionElement, PickersSectionListRef } from "../../../PickersSectionList/index.js";
|
|
8
5
|
import { FormProps, InferNonNullablePickerValue, PickerValidValue } from "../../models/index.js";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
valueManager: PickerValueManager<TValue, InferError<TInternalProps>>;
|
|
14
|
-
fieldValueManager: FieldValueManager<TValue>;
|
|
15
|
-
validator: Validator<TValue, InferError<TInternalProps>, TInternalProps>;
|
|
16
|
-
valueType: PickerValueType;
|
|
17
|
-
getOpenPickerButtonAriaLabel: (value: TValue) => string;
|
|
6
|
+
export interface UseFieldParameters<TValue extends PickerValidValue, TEnableAccessibleFieldDOMStructure extends boolean, TError, TValidationProps extends {}, TProps extends UseFieldProps<TEnableAccessibleFieldDOMStructure>> {
|
|
7
|
+
manager: PickerManager<TValue, TEnableAccessibleFieldDOMStructure, TError, TValidationProps, any>;
|
|
8
|
+
props: TProps;
|
|
9
|
+
skipContextFieldRefAssignment?: boolean;
|
|
18
10
|
}
|
|
19
11
|
export interface UseFieldInternalProps<TValue extends PickerValidValue, TEnableAccessibleFieldDOMStructure extends boolean, TError> extends TimezoneProps, FormProps, OnErrorProps<TValue, TError> {
|
|
20
12
|
/**
|
|
@@ -98,39 +90,47 @@ export interface UseFieldInternalProps<TValue extends PickerValidValue, TEnableA
|
|
|
98
90
|
*/
|
|
99
91
|
focused?: boolean;
|
|
100
92
|
}
|
|
101
|
-
export
|
|
102
|
-
|
|
103
|
-
* The aria label to set on the button that opens the Picker.
|
|
104
|
-
*/
|
|
105
|
-
openPickerAriaLabel: string;
|
|
106
|
-
}
|
|
107
|
-
export interface UseFieldCommonForwardedProps extends Pick<ExportedPickerFieldUIProps, 'clearable' | 'onClear'> {
|
|
108
|
-
onKeyDown?: React.KeyboardEventHandler;
|
|
93
|
+
export type UseFieldForwardedProps<TEnableAccessibleFieldDOMStructure extends boolean> = TEnableAccessibleFieldDOMStructure extends false ? {
|
|
94
|
+
clearable?: boolean;
|
|
109
95
|
error?: boolean;
|
|
110
|
-
|
|
111
|
-
export type UseFieldForwardedProps<TEnableAccessibleFieldDOMStructure extends boolean> = UseFieldCommonForwardedProps & (TEnableAccessibleFieldDOMStructure extends false ? UseFieldV6ForwardedProps : UseFieldV7ForwardedProps);
|
|
112
|
-
export interface UseFieldV6ForwardedProps {
|
|
96
|
+
placeholder?: string;
|
|
113
97
|
inputRef?: React.Ref<HTMLInputElement>;
|
|
114
|
-
onBlur?: React.FocusEventHandler;
|
|
115
98
|
onClick?: React.MouseEventHandler;
|
|
116
99
|
onFocus?: React.FocusEventHandler;
|
|
100
|
+
onKeyDown?: React.KeyboardEventHandler;
|
|
101
|
+
onBlur?: React.FocusEventHandler;
|
|
117
102
|
onPaste?: React.ClipboardEventHandler<HTMLDivElement>;
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
focused?: boolean;
|
|
123
|
-
}
|
|
124
|
-
export interface UseFieldV7ForwardedProps {
|
|
103
|
+
onClear?: React.MouseEventHandler;
|
|
104
|
+
} : {
|
|
105
|
+
clearable?: boolean;
|
|
106
|
+
error?: boolean;
|
|
125
107
|
focused?: boolean;
|
|
126
108
|
sectionListRef?: React.Ref<PickersSectionListRef>;
|
|
127
|
-
onBlur?: React.FocusEventHandler;
|
|
128
109
|
onClick?: React.MouseEventHandler;
|
|
110
|
+
onKeyDown?: React.KeyboardEventHandler;
|
|
129
111
|
onFocus?: React.FocusEventHandler;
|
|
112
|
+
onBlur?: React.FocusEventHandler;
|
|
130
113
|
onInput?: React.FormEventHandler<HTMLDivElement>;
|
|
131
114
|
onPaste?: React.ClipboardEventHandler<HTMLDivElement>;
|
|
132
|
-
|
|
133
|
-
|
|
115
|
+
onClear?: React.MouseEventHandler;
|
|
116
|
+
};
|
|
117
|
+
type UseFieldAdditionalProps<TEnableAccessibleFieldDOMStructure extends boolean> = TEnableAccessibleFieldDOMStructure extends false ? {
|
|
118
|
+
/**
|
|
119
|
+
* The aria label to set on the button that opens the Picker.
|
|
120
|
+
*/
|
|
121
|
+
openPickerAriaLabel: string;
|
|
122
|
+
enableAccessibleFieldDOMStructure: false;
|
|
123
|
+
focused: boolean | undefined;
|
|
124
|
+
inputMode: 'text' | 'numeric';
|
|
125
|
+
placeholder: string;
|
|
126
|
+
value: string;
|
|
127
|
+
onChange: React.ChangeEventHandler<HTMLInputElement>;
|
|
128
|
+
autoComplete: 'off';
|
|
129
|
+
} : {
|
|
130
|
+
/**
|
|
131
|
+
* The aria label to set on the button that opens the Picker.
|
|
132
|
+
*/
|
|
133
|
+
openPickerAriaLabel: string;
|
|
134
134
|
enableAccessibleFieldDOMStructure: true;
|
|
135
135
|
elements: PickersSectionElement[];
|
|
136
136
|
tabIndex: number | undefined;
|
|
@@ -139,10 +139,8 @@ interface UseFieldV7AdditionalProps {
|
|
|
139
139
|
onChange: React.ChangeEventHandler<HTMLInputElement>;
|
|
140
140
|
areAllSectionsEmpty: boolean;
|
|
141
141
|
focused: boolean;
|
|
142
|
-
}
|
|
143
|
-
export type
|
|
144
|
-
[key: string]: any;
|
|
145
|
-
}> = Omit<TForwardedProps, keyof UseFieldCommonForwardedProps> & Required<UseFieldCommonForwardedProps> & UseFieldCommonAdditionalProps & (TEnableAccessibleFieldDOMStructure extends false ? UseFieldV6AdditionalProps & Required<UseFieldV6ForwardedProps> : UseFieldV7AdditionalProps & Required<UseFieldV7ForwardedProps>);
|
|
142
|
+
};
|
|
143
|
+
export type UseFieldReturnValue<TEnableAccessibleFieldDOMStructure extends boolean, TProps extends UseFieldProps<TEnableAccessibleFieldDOMStructure>> = Required<Pick<UseFieldInternalProps<any, any, any>, 'disabled' | 'readOnly' | 'autoFocus'>> & Required<UseFieldForwardedProps<TEnableAccessibleFieldDOMStructure>> & UseFieldAdditionalProps<TEnableAccessibleFieldDOMStructure> & Omit<TProps, InternalPropNames<PickerValueType>>;
|
|
146
144
|
export type FieldSectionValueBoundaries<SectionType extends FieldSectionType> = {
|
|
147
145
|
minimum: number;
|
|
148
146
|
maximum: number;
|
|
@@ -282,8 +280,11 @@ export interface UseFieldState<TValue extends PickerValidValue> {
|
|
|
282
280
|
* The property below allows us to set the first `onChange` value into state waiting for the second one.
|
|
283
281
|
*/
|
|
284
282
|
tempValueStrAndroid: string | null;
|
|
283
|
+
/**
|
|
284
|
+
* The current query when editing the field using letters or digits.
|
|
285
|
+
*/
|
|
286
|
+
characterQuery: CharacterEditingQuery | null;
|
|
285
287
|
}
|
|
286
|
-
export type AvailableAdjustKeyCode = 'ArrowUp' | 'ArrowDown' | 'PageUp' | 'PageDown' | 'Home' | 'End';
|
|
287
288
|
export type SectionNeighbors = {
|
|
288
289
|
[sectionIndex: number]: {
|
|
289
290
|
/**
|
|
@@ -310,33 +311,12 @@ export type SectionOrdering = {
|
|
|
310
311
|
*/
|
|
311
312
|
endIndex: number;
|
|
312
313
|
};
|
|
313
|
-
export interface
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
syncSelectionToDOM: () => void;
|
|
318
|
-
/**
|
|
319
|
-
* Returns the index of the active section (the first focused section).
|
|
320
|
-
* If no section is active, returns `null`.
|
|
321
|
-
* @returns {number | null} The index of the active section.
|
|
322
|
-
*/
|
|
323
|
-
getActiveSectionIndexFromDOM: () => number | null;
|
|
324
|
-
/**
|
|
325
|
-
* Focuses the field.
|
|
326
|
-
* @param {number | FieldSectionType} newSelectedSection The section to select once focused.
|
|
327
|
-
*/
|
|
328
|
-
focusField: (newSelectedSection?: number | FieldSectionType) => void;
|
|
329
|
-
setSelectedSections: (newSelectedSections: FieldSelectedSections) => void;
|
|
330
|
-
isFieldFocused: () => boolean;
|
|
314
|
+
export interface CharacterEditingQuery {
|
|
315
|
+
value: string;
|
|
316
|
+
sectionIndex: number;
|
|
317
|
+
sectionType: FieldSectionType;
|
|
331
318
|
}
|
|
332
|
-
export type
|
|
333
|
-
|
|
334
|
-
}>(params: UseFieldTextFieldParams<TValue, TEnableAccessibleFieldDOMStructure, TForwardedProps, TInternalProps>) => {
|
|
335
|
-
interactions: UseFieldTextFieldInteractions;
|
|
336
|
-
returnedValue: TEnableAccessibleFieldDOMStructure extends false ? UseFieldV6AdditionalProps & Required<UseFieldV6ForwardedProps> : UseFieldV7AdditionalProps & Required<UseFieldV7ForwardedProps>;
|
|
319
|
+
export type UseFieldProps<TEnableAccessibleFieldDOMStructure extends boolean> = UseFieldForwardedProps<TEnableAccessibleFieldDOMStructure> & {
|
|
320
|
+
enableAccessibleFieldDOMStructure?: boolean;
|
|
337
321
|
};
|
|
338
|
-
interface UseFieldTextFieldParams<TValue extends PickerValidValue, TEnableAccessibleFieldDOMStructure extends boolean, TForwardedProps extends (TEnableAccessibleFieldDOMStructure extends false ? UseFieldV6ForwardedProps : UseFieldV7ForwardedProps), TInternalProps extends UseFieldInternalProps<TValue, TEnableAccessibleFieldDOMStructure, any>> extends UseFieldParams<TValue, TEnableAccessibleFieldDOMStructure, TForwardedProps, TInternalProps>, UseFieldStateResponse<TValue>, UseFieldCharacterEditingResponse {
|
|
339
|
-
areAllSectionsEmpty: boolean;
|
|
340
|
-
sectionOrder: SectionOrdering;
|
|
341
|
-
}
|
|
342
322
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FieldSectionsValueBoundaries, SectionOrdering, FieldSectionValueBoundaries, FieldParsedSelectedSections } from "./useField.types.js";
|
|
2
2
|
import { FieldSectionType, FieldSection, MuiPickersAdapter, FieldSectionContentType, PickersTimezone, PickerValidDate, FieldSelectedSections, PickerValueType, InferFieldSection } from "../../../models/index.js";
|
|
3
3
|
import { PickerValidValue } from "../../models/index.js";
|
|
4
4
|
export declare const getDateSectionConfigFromFormatToken: (utils: MuiPickersAdapter, formatToken: string) => Pick<FieldSection, "type" | "contentType"> & {
|
|
@@ -12,15 +12,12 @@ export declare const removeLocalizedDigits: (valueStr: string, localizedDigits:
|
|
|
12
12
|
export declare const applyLocalizedDigits: (valueStr: string, localizedDigits: string[]) => string;
|
|
13
13
|
export declare const isStringNumber: (valueStr: string, localizedDigits: string[]) => boolean;
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Make sure the value of a digit section have the right amount of leading zeros.
|
|
16
16
|
* E.g.: `03` => `3`
|
|
17
17
|
* Warning: Should only be called with non-localized digits. Call `removeLocalizedDigits` with your value if needed.
|
|
18
18
|
*/
|
|
19
19
|
export declare const cleanLeadingZeros: (valueStr: string, size: number) => string;
|
|
20
20
|
export declare const cleanDigitSectionValue: (utils: MuiPickersAdapter, value: number, sectionBoundaries: FieldSectionValueBoundaries<any>, localizedDigits: string[], section: Pick<FieldSection, "format" | "type" | "contentType" | "hasLeadingZerosInFormat" | "hasLeadingZerosInInput" | "maxLength">) => string;
|
|
21
|
-
export declare const adjustSectionValue: <TValue extends PickerValidValue>(utils: MuiPickersAdapter, timezone: PickersTimezone, section: InferFieldSection<TValue>, keyCode: AvailableAdjustKeyCode, sectionsValueBoundaries: FieldSectionsValueBoundaries, localizedDigits: string[], activeDate: PickerValidDate | null, stepsAttributes?: {
|
|
22
|
-
minutesStep?: number;
|
|
23
|
-
}) => string;
|
|
24
21
|
export declare const getSectionVisibleValue: (section: FieldSection, target: "input-rtl" | "input-ltr" | "non-input", localizedDigits: string[]) => string;
|
|
25
22
|
export declare const changeSectionValueFormat: (utils: MuiPickersAdapter, valueStr: string, currentFormat: string, newFormat: string) => string;
|
|
26
23
|
export declare const doesSectionFormatHaveLeadingZeros: (utils: MuiPickersAdapter, contentType: FieldSectionContentType, sectionType: FieldSectionType, format: string) => boolean;
|
|
@@ -17,20 +17,6 @@ export const getDateSectionConfigFromFormatToken = (utils, formatToken) => {
|
|
|
17
17
|
maxLength: config.maxLength
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
|
-
const getDeltaFromKeyCode = keyCode => {
|
|
21
|
-
switch (keyCode) {
|
|
22
|
-
case 'ArrowUp':
|
|
23
|
-
return 1;
|
|
24
|
-
case 'ArrowDown':
|
|
25
|
-
return -1;
|
|
26
|
-
case 'PageUp':
|
|
27
|
-
return 5;
|
|
28
|
-
case 'PageDown':
|
|
29
|
-
return -5;
|
|
30
|
-
default:
|
|
31
|
-
return 0;
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
20
|
export const getDaysInWeekStr = (utils, format) => {
|
|
35
21
|
const elements = [];
|
|
36
22
|
const now = utils.date(undefined, 'default');
|
|
@@ -108,21 +94,13 @@ export const isStringNumber = (valueStr, localizedDigits) => {
|
|
|
108
94
|
};
|
|
109
95
|
|
|
110
96
|
/**
|
|
111
|
-
*
|
|
97
|
+
* Make sure the value of a digit section have the right amount of leading zeros.
|
|
112
98
|
* E.g.: `03` => `3`
|
|
113
99
|
* Warning: Should only be called with non-localized digits. Call `removeLocalizedDigits` with your value if needed.
|
|
114
100
|
*/
|
|
115
101
|
export const cleanLeadingZeros = (valueStr, size) => {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
// Remove the leading zeros
|
|
119
|
-
cleanValueStr = Number(cleanValueStr).toString();
|
|
120
|
-
|
|
121
|
-
// Add enough leading zeros to fill the section
|
|
122
|
-
while (cleanValueStr.length < size) {
|
|
123
|
-
cleanValueStr = `0${cleanValueStr}`;
|
|
124
|
-
}
|
|
125
|
-
return cleanValueStr;
|
|
102
|
+
// Remove the leading zeros and then add back as many as needed.
|
|
103
|
+
return Number(valueStr).toString().padStart(size, '0');
|
|
126
104
|
};
|
|
127
105
|
export const cleanDigitSectionValue = (utils, value, sectionBoundaries, localizedDigits, section) => {
|
|
128
106
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -143,68 +121,6 @@ export const cleanDigitSectionValue = (utils, value, sectionBoundaries, localize
|
|
|
143
121
|
}
|
|
144
122
|
return applyLocalizedDigits(valueStr, localizedDigits);
|
|
145
123
|
};
|
|
146
|
-
export const adjustSectionValue = (utils, timezone, section, keyCode, sectionsValueBoundaries, localizedDigits, activeDate, stepsAttributes) => {
|
|
147
|
-
const delta = getDeltaFromKeyCode(keyCode);
|
|
148
|
-
const isStart = keyCode === 'Home';
|
|
149
|
-
const isEnd = keyCode === 'End';
|
|
150
|
-
const shouldSetAbsolute = section.value === '' || isStart || isEnd;
|
|
151
|
-
const adjustDigitSection = () => {
|
|
152
|
-
const sectionBoundaries = sectionsValueBoundaries[section.type]({
|
|
153
|
-
currentDate: activeDate,
|
|
154
|
-
format: section.format,
|
|
155
|
-
contentType: section.contentType
|
|
156
|
-
});
|
|
157
|
-
const getCleanValue = value => cleanDigitSectionValue(utils, value, sectionBoundaries, localizedDigits, section);
|
|
158
|
-
const step = section.type === 'minutes' && stepsAttributes?.minutesStep ? stepsAttributes.minutesStep : 1;
|
|
159
|
-
const currentSectionValue = parseInt(removeLocalizedDigits(section.value, localizedDigits), 10);
|
|
160
|
-
let newSectionValueNumber = currentSectionValue + delta * step;
|
|
161
|
-
if (shouldSetAbsolute) {
|
|
162
|
-
if (section.type === 'year' && !isEnd && !isStart) {
|
|
163
|
-
return utils.formatByString(utils.date(undefined, timezone), section.format);
|
|
164
|
-
}
|
|
165
|
-
if (delta > 0 || isStart) {
|
|
166
|
-
newSectionValueNumber = sectionBoundaries.minimum;
|
|
167
|
-
} else {
|
|
168
|
-
newSectionValueNumber = sectionBoundaries.maximum;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
if (newSectionValueNumber % step !== 0) {
|
|
172
|
-
if (delta < 0 || isStart) {
|
|
173
|
-
newSectionValueNumber += step - (step + newSectionValueNumber) % step; // for JS -3 % 5 = -3 (should be 2)
|
|
174
|
-
}
|
|
175
|
-
if (delta > 0 || isEnd) {
|
|
176
|
-
newSectionValueNumber -= newSectionValueNumber % step;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
if (newSectionValueNumber > sectionBoundaries.maximum) {
|
|
180
|
-
return getCleanValue(sectionBoundaries.minimum + (newSectionValueNumber - sectionBoundaries.maximum - 1) % (sectionBoundaries.maximum - sectionBoundaries.minimum + 1));
|
|
181
|
-
}
|
|
182
|
-
if (newSectionValueNumber < sectionBoundaries.minimum) {
|
|
183
|
-
return getCleanValue(sectionBoundaries.maximum - (sectionBoundaries.minimum - newSectionValueNumber - 1) % (sectionBoundaries.maximum - sectionBoundaries.minimum + 1));
|
|
184
|
-
}
|
|
185
|
-
return getCleanValue(newSectionValueNumber);
|
|
186
|
-
};
|
|
187
|
-
const adjustLetterSection = () => {
|
|
188
|
-
const options = getLetterEditingOptions(utils, timezone, section.type, section.format);
|
|
189
|
-
if (options.length === 0) {
|
|
190
|
-
return section.value;
|
|
191
|
-
}
|
|
192
|
-
if (shouldSetAbsolute) {
|
|
193
|
-
if (delta > 0 || isStart) {
|
|
194
|
-
return options[0];
|
|
195
|
-
}
|
|
196
|
-
return options[options.length - 1];
|
|
197
|
-
}
|
|
198
|
-
const currentOptionIndex = options.indexOf(section.value);
|
|
199
|
-
const newOptionIndex = (currentOptionIndex + delta) % options.length;
|
|
200
|
-
const clampedIndex = (newOptionIndex + options.length) % options.length;
|
|
201
|
-
return options[clampedIndex];
|
|
202
|
-
};
|
|
203
|
-
if (section.contentType === 'digit' || section.contentType === 'digit-with-letter') {
|
|
204
|
-
return adjustDigitSection();
|
|
205
|
-
}
|
|
206
|
-
return adjustLetterSection();
|
|
207
|
-
};
|
|
208
124
|
export const getSectionVisibleValue = (section, target, localizedDigits) => {
|
|
209
125
|
let value = section.value || section.placeholder;
|
|
210
126
|
const hasLeadingZeros = target === 'non-input' ? section.hasLeadingZerosInFormat : section.hasLeadingZerosInInput;
|
|
@@ -244,12 +160,11 @@ export const doesSectionFormatHaveLeadingZeros = (utils, contentType, sectionTyp
|
|
|
244
160
|
// We can't use `changeSectionValueFormat`, because `utils.parse('1', 'YYYY')` returns `1971` instead of `1`.
|
|
245
161
|
case 'year':
|
|
246
162
|
{
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
return
|
|
163
|
+
// Remove once https://github.com/iamkun/dayjs/pull/2847 is merged and bump dayjs version
|
|
164
|
+
if (utils.lib === 'dayjs' && format === 'YY') {
|
|
165
|
+
return true;
|
|
250
166
|
}
|
|
251
|
-
|
|
252
|
-
return formatted2001 === '01';
|
|
167
|
+
return utils.formatByString(utils.setYear(now, 1), format).startsWith('0');
|
|
253
168
|
}
|
|
254
169
|
case 'month':
|
|
255
170
|
{
|
|
@@ -1,23 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { FieldSectionsValueBoundaries } from "./useField.types.js";
|
|
3
|
-
import { UpdateSectionValueParams } from "./useFieldState.js";
|
|
1
|
+
import { UseFieldStateReturnValue } from "./useFieldState.js";
|
|
4
2
|
import { PickerValidValue } from "../../models/index.js";
|
|
5
|
-
export interface ApplyCharacterEditingParams {
|
|
6
|
-
keyPressed: string;
|
|
7
|
-
sectionIndex: number;
|
|
8
|
-
}
|
|
9
|
-
interface UseFieldCharacterEditingParams<TValue extends PickerValidValue> {
|
|
10
|
-
sections: InferFieldSection<TValue>[];
|
|
11
|
-
updateSectionValue: (params: UpdateSectionValueParams<TValue>) => void;
|
|
12
|
-
sectionsValueBoundaries: FieldSectionsValueBoundaries;
|
|
13
|
-
localizedDigits: string[];
|
|
14
|
-
setTempAndroidValueStr: (newValue: string | null) => void;
|
|
15
|
-
timezone: PickersTimezone;
|
|
16
|
-
}
|
|
17
|
-
export interface UseFieldCharacterEditingResponse {
|
|
18
|
-
applyCharacterEditing: (params: ApplyCharacterEditingParams) => void;
|
|
19
|
-
resetCharacterQuery: () => void;
|
|
20
|
-
}
|
|
21
3
|
/**
|
|
22
4
|
* Update the active section value when the user pressed a key that is not a navigation key (arrow key for example).
|
|
23
5
|
* This hook has two main editing behaviors
|
|
@@ -26,11 +8,22 @@ export interface UseFieldCharacterEditingResponse {
|
|
|
26
8
|
* 2. The letter editing when the user presses another key
|
|
27
9
|
*/
|
|
28
10
|
export declare const useFieldCharacterEditing: <TValue extends PickerValidValue>({
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
11
|
+
stateResponse: {
|
|
12
|
+
localizedDigits,
|
|
13
|
+
sectionsValueBoundaries,
|
|
14
|
+
state,
|
|
15
|
+
timezone,
|
|
16
|
+
setCharacterQuery,
|
|
17
|
+
setTempAndroidValueStr,
|
|
18
|
+
updateSectionValue
|
|
19
|
+
}
|
|
20
|
+
}: UseFieldCharacterEditingParameters<TValue>) => UseFieldCharacterEditingReturnValue;
|
|
21
|
+
export interface ApplyCharacterEditingParameters {
|
|
22
|
+
keyPressed: string;
|
|
23
|
+
sectionIndex: number;
|
|
24
|
+
}
|
|
25
|
+
interface UseFieldCharacterEditingParameters<TValue extends PickerValidValue> {
|
|
26
|
+
stateResponse: UseFieldStateReturnValue<TValue>;
|
|
27
|
+
}
|
|
28
|
+
export type UseFieldCharacterEditingReturnValue = (params: ApplyCharacterEditingParameters) => void;
|
|
36
29
|
export {};
|
|
@@ -1,32 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import * as React from 'react';
|
|
3
2
|
import useEventCallback from '@mui/utils/useEventCallback';
|
|
4
3
|
import { useUtils } from "../useUtils.js";
|
|
5
4
|
import { changeSectionValueFormat, cleanDigitSectionValue, doesSectionFormatHaveLeadingZeros, getDateSectionConfigFromFormatToken, getDaysInWeekStr, getLetterEditingOptions, applyLocalizedDigits, removeLocalizedDigits, isStringNumber } from "./useField.utils.js";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* The letter editing and the numeric editing each define a `CharacterEditingApplier`.
|
|
9
|
-
* This function decides what the new section value should be and if the focus should switch to the next section.
|
|
10
|
-
*
|
|
11
|
-
* If it returns `null`, then the section value is not updated and the focus does not move.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Function called by `applyQuery` which decides:
|
|
16
|
-
* - what is the new section value ?
|
|
17
|
-
* - should the query used to get this value be stored for the next key press ?
|
|
18
|
-
*
|
|
19
|
-
* If it returns `{ sectionValue: string; shouldGoToNextSection: boolean }`,
|
|
20
|
-
* Then we store the query and update the section with the new value.
|
|
21
|
-
*
|
|
22
|
-
* If it returns `{ saveQuery: true` },
|
|
23
|
-
* Then we store the query and don't update the section.
|
|
24
|
-
*
|
|
25
|
-
* If it returns `{ saveQuery: false },
|
|
26
|
-
* Then we do nothing.
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
const QUERY_LIFE_DURATION_MS = 5000;
|
|
30
5
|
const isQueryResponseWithoutValue = response => response.saveQuery != null;
|
|
31
6
|
|
|
32
7
|
/**
|
|
@@ -37,44 +12,33 @@ const isQueryResponseWithoutValue = response => response.saveQuery != null;
|
|
|
37
12
|
* 2. The letter editing when the user presses another key
|
|
38
13
|
*/
|
|
39
14
|
export const useFieldCharacterEditing = ({
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
15
|
+
stateResponse: {
|
|
16
|
+
// States and derived states
|
|
17
|
+
localizedDigits,
|
|
18
|
+
sectionsValueBoundaries,
|
|
19
|
+
state,
|
|
20
|
+
timezone,
|
|
21
|
+
// Methods to update the states
|
|
22
|
+
setCharacterQuery,
|
|
23
|
+
setTempAndroidValueStr,
|
|
24
|
+
updateSectionValue
|
|
25
|
+
}
|
|
46
26
|
}) => {
|
|
47
27
|
const utils = useUtils();
|
|
48
|
-
const [query, setQuery] = React.useState(null);
|
|
49
|
-
const resetQuery = useEventCallback(() => setQuery(null));
|
|
50
|
-
React.useEffect(() => {
|
|
51
|
-
if (query != null && sections[query.sectionIndex]?.type !== query.sectionType) {
|
|
52
|
-
resetQuery();
|
|
53
|
-
}
|
|
54
|
-
}, [sections, query, resetQuery]);
|
|
55
|
-
React.useEffect(() => {
|
|
56
|
-
if (query != null) {
|
|
57
|
-
const timeout = setTimeout(() => resetQuery(), QUERY_LIFE_DURATION_MS);
|
|
58
|
-
return () => {
|
|
59
|
-
clearTimeout(timeout);
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
return () => {};
|
|
63
|
-
}, [query, resetQuery]);
|
|
64
28
|
const applyQuery = ({
|
|
65
29
|
keyPressed,
|
|
66
30
|
sectionIndex
|
|
67
31
|
}, getFirstSectionValueMatchingWithQuery, isValidQueryValue) => {
|
|
68
32
|
const cleanKeyPressed = keyPressed.toLowerCase();
|
|
69
|
-
const activeSection = sections[sectionIndex];
|
|
33
|
+
const activeSection = state.sections[sectionIndex];
|
|
70
34
|
|
|
71
35
|
// The current query targets the section being editing
|
|
72
36
|
// We can try to concatenate the value
|
|
73
|
-
if (
|
|
74
|
-
const concatenatedQueryValue = `${
|
|
37
|
+
if (state.characterQuery != null && (!isValidQueryValue || isValidQueryValue(state.characterQuery.value)) && state.characterQuery.sectionIndex === sectionIndex) {
|
|
38
|
+
const concatenatedQueryValue = `${state.characterQuery.value}${cleanKeyPressed}`;
|
|
75
39
|
const queryResponse = getFirstSectionValueMatchingWithQuery(concatenatedQueryValue, activeSection);
|
|
76
40
|
if (!isQueryResponseWithoutValue(queryResponse)) {
|
|
77
|
-
|
|
41
|
+
setCharacterQuery({
|
|
78
42
|
sectionIndex,
|
|
79
43
|
value: concatenatedQueryValue,
|
|
80
44
|
sectionType: activeSection.type
|
|
@@ -84,10 +48,10 @@ export const useFieldCharacterEditing = ({
|
|
|
84
48
|
}
|
|
85
49
|
const queryResponse = getFirstSectionValueMatchingWithQuery(cleanKeyPressed, activeSection);
|
|
86
50
|
if (isQueryResponseWithoutValue(queryResponse) && !queryResponse.saveQuery) {
|
|
87
|
-
|
|
51
|
+
setCharacterQuery(null);
|
|
88
52
|
return null;
|
|
89
53
|
}
|
|
90
|
-
|
|
54
|
+
setCharacterQuery({
|
|
91
55
|
sectionIndex,
|
|
92
56
|
value: cleanKeyPressed,
|
|
93
57
|
sectionType: activeSection.type
|
|
@@ -235,8 +199,8 @@ export const useFieldCharacterEditing = ({
|
|
|
235
199
|
};
|
|
236
200
|
return applyQuery(params, getFirstSectionValueMatchingWithQuery, queryValue => isStringNumber(queryValue, localizedDigits));
|
|
237
201
|
};
|
|
238
|
-
|
|
239
|
-
const section = sections[params.sectionIndex];
|
|
202
|
+
return useEventCallback(params => {
|
|
203
|
+
const section = state.sections[params.sectionIndex];
|
|
240
204
|
const isNumericEditing = isStringNumber(params.keyPressed, localizedDigits);
|
|
241
205
|
const response = isNumericEditing ? applyNumericEditing(_extends({}, params, {
|
|
242
206
|
keyPressed: applyLocalizedDigits(params.keyPressed, localizedDigits)
|
|
@@ -251,8 +215,26 @@ export const useFieldCharacterEditing = ({
|
|
|
251
215
|
shouldGoToNextSection: response.shouldGoToNextSection
|
|
252
216
|
});
|
|
253
217
|
});
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* The letter editing and the numeric editing each define a `CharacterEditingApplier`.
|
|
222
|
+
* This function decides what the new section value should be and if the focus should switch to the next section.
|
|
223
|
+
*
|
|
224
|
+
* If it returns `null`, then the section value is not updated and the focus does not move.
|
|
225
|
+
*/
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Function called by `applyQuery` which decides:
|
|
229
|
+
* - what is the new section value ?
|
|
230
|
+
* - should the query used to get this value be stored for the next key press ?
|
|
231
|
+
*
|
|
232
|
+
* If it returns `{ sectionValue: string; shouldGoToNextSection: boolean }`,
|
|
233
|
+
* Then we store the query and update the section with the new value.
|
|
234
|
+
*
|
|
235
|
+
* If it returns `{ saveQuery: true` },
|
|
236
|
+
* Then we store the query and don't update the section.
|
|
237
|
+
*
|
|
238
|
+
* If it returns `{ saveQuery: false },
|
|
239
|
+
* Then we do nothing.
|
|
240
|
+
*/
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PickerManager } from "../../../models/index.js";
|
|
2
|
+
import { PickerValidValue } from "../../models/index.js";
|
|
3
|
+
import { UseFieldStateReturnValue } from "./useFieldState.js";
|
|
4
|
+
import { UseFieldInternalProps } from "./useField.types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Returns the `onKeyDown` handler to pass to the root element of the field.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useFieldRootHandleKeyDown<TValue extends PickerValidValue>(parameters: UseFieldRootHandleKeyDownParameters<TValue>): (event: React.KeyboardEvent<HTMLSpanElement>) => void;
|
|
9
|
+
interface UseFieldRootHandleKeyDownParameters<TValue extends PickerValidValue> {
|
|
10
|
+
manager: PickerManager<TValue, any, any, any, any>;
|
|
11
|
+
stateResponse: UseFieldStateReturnValue<TValue>;
|
|
12
|
+
internalPropsWithDefaults: UseFieldInternalProps<TValue, any, any> & {
|
|
13
|
+
minutesStep?: number;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export {};
|