@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,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,39 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
4
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.useFieldCharacterEditing = void 0;
|
|
9
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
|
-
var React = _interopRequireWildcard(require("react"));
|
|
11
9
|
var _useEventCallback = _interopRequireDefault(require("@mui/utils/useEventCallback"));
|
|
12
10
|
var _useUtils = require("../useUtils");
|
|
13
11
|
var _useField = require("./useField.utils");
|
|
14
|
-
/**
|
|
15
|
-
* The letter editing and the numeric editing each define a `CharacterEditingApplier`.
|
|
16
|
-
* This function decides what the new section value should be and if the focus should switch to the next section.
|
|
17
|
-
*
|
|
18
|
-
* If it returns `null`, then the section value is not updated and the focus does not move.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Function called by `applyQuery` which decides:
|
|
23
|
-
* - what is the new section value ?
|
|
24
|
-
* - should the query used to get this value be stored for the next key press ?
|
|
25
|
-
*
|
|
26
|
-
* If it returns `{ sectionValue: string; shouldGoToNextSection: boolean }`,
|
|
27
|
-
* Then we store the query and update the section with the new value.
|
|
28
|
-
*
|
|
29
|
-
* If it returns `{ saveQuery: true` },
|
|
30
|
-
* Then we store the query and don't update the section.
|
|
31
|
-
*
|
|
32
|
-
* If it returns `{ saveQuery: false },
|
|
33
|
-
* Then we do nothing.
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
const QUERY_LIFE_DURATION_MS = 5000;
|
|
37
12
|
const isQueryResponseWithoutValue = response => response.saveQuery != null;
|
|
38
13
|
|
|
39
14
|
/**
|
|
@@ -44,44 +19,33 @@ const isQueryResponseWithoutValue = response => response.saveQuery != null;
|
|
|
44
19
|
* 2. The letter editing when the user presses another key
|
|
45
20
|
*/
|
|
46
21
|
const useFieldCharacterEditing = ({
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
22
|
+
stateResponse: {
|
|
23
|
+
// States and derived states
|
|
24
|
+
localizedDigits,
|
|
25
|
+
sectionsValueBoundaries,
|
|
26
|
+
state,
|
|
27
|
+
timezone,
|
|
28
|
+
// Methods to update the states
|
|
29
|
+
setCharacterQuery,
|
|
30
|
+
setTempAndroidValueStr,
|
|
31
|
+
updateSectionValue
|
|
32
|
+
}
|
|
53
33
|
}) => {
|
|
54
34
|
const utils = (0, _useUtils.useUtils)();
|
|
55
|
-
const [query, setQuery] = React.useState(null);
|
|
56
|
-
const resetQuery = (0, _useEventCallback.default)(() => setQuery(null));
|
|
57
|
-
React.useEffect(() => {
|
|
58
|
-
if (query != null && sections[query.sectionIndex]?.type !== query.sectionType) {
|
|
59
|
-
resetQuery();
|
|
60
|
-
}
|
|
61
|
-
}, [sections, query, resetQuery]);
|
|
62
|
-
React.useEffect(() => {
|
|
63
|
-
if (query != null) {
|
|
64
|
-
const timeout = setTimeout(() => resetQuery(), QUERY_LIFE_DURATION_MS);
|
|
65
|
-
return () => {
|
|
66
|
-
clearTimeout(timeout);
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
return () => {};
|
|
70
|
-
}, [query, resetQuery]);
|
|
71
35
|
const applyQuery = ({
|
|
72
36
|
keyPressed,
|
|
73
37
|
sectionIndex
|
|
74
38
|
}, getFirstSectionValueMatchingWithQuery, isValidQueryValue) => {
|
|
75
39
|
const cleanKeyPressed = keyPressed.toLowerCase();
|
|
76
|
-
const activeSection = sections[sectionIndex];
|
|
40
|
+
const activeSection = state.sections[sectionIndex];
|
|
77
41
|
|
|
78
42
|
// The current query targets the section being editing
|
|
79
43
|
// We can try to concatenate the value
|
|
80
|
-
if (
|
|
81
|
-
const concatenatedQueryValue = `${
|
|
44
|
+
if (state.characterQuery != null && (!isValidQueryValue || isValidQueryValue(state.characterQuery.value)) && state.characterQuery.sectionIndex === sectionIndex) {
|
|
45
|
+
const concatenatedQueryValue = `${state.characterQuery.value}${cleanKeyPressed}`;
|
|
82
46
|
const queryResponse = getFirstSectionValueMatchingWithQuery(concatenatedQueryValue, activeSection);
|
|
83
47
|
if (!isQueryResponseWithoutValue(queryResponse)) {
|
|
84
|
-
|
|
48
|
+
setCharacterQuery({
|
|
85
49
|
sectionIndex,
|
|
86
50
|
value: concatenatedQueryValue,
|
|
87
51
|
sectionType: activeSection.type
|
|
@@ -91,10 +55,10 @@ const useFieldCharacterEditing = ({
|
|
|
91
55
|
}
|
|
92
56
|
const queryResponse = getFirstSectionValueMatchingWithQuery(cleanKeyPressed, activeSection);
|
|
93
57
|
if (isQueryResponseWithoutValue(queryResponse) && !queryResponse.saveQuery) {
|
|
94
|
-
|
|
58
|
+
setCharacterQuery(null);
|
|
95
59
|
return null;
|
|
96
60
|
}
|
|
97
|
-
|
|
61
|
+
setCharacterQuery({
|
|
98
62
|
sectionIndex,
|
|
99
63
|
value: cleanKeyPressed,
|
|
100
64
|
sectionType: activeSection.type
|
|
@@ -242,8 +206,8 @@ const useFieldCharacterEditing = ({
|
|
|
242
206
|
};
|
|
243
207
|
return applyQuery(params, getFirstSectionValueMatchingWithQuery, queryValue => (0, _useField.isStringNumber)(queryValue, localizedDigits));
|
|
244
208
|
};
|
|
245
|
-
|
|
246
|
-
const section = sections[params.sectionIndex];
|
|
209
|
+
return (0, _useEventCallback.default)(params => {
|
|
210
|
+
const section = state.sections[params.sectionIndex];
|
|
247
211
|
const isNumericEditing = (0, _useField.isStringNumber)(params.keyPressed, localizedDigits);
|
|
248
212
|
const response = isNumericEditing ? applyNumericEditing((0, _extends2.default)({}, params, {
|
|
249
213
|
keyPressed: (0, _useField.applyLocalizedDigits)(params.keyPressed, localizedDigits)
|
|
@@ -258,9 +222,27 @@ const useFieldCharacterEditing = ({
|
|
|
258
222
|
shouldGoToNextSection: response.shouldGoToNextSection
|
|
259
223
|
});
|
|
260
224
|
});
|
|
261
|
-
return {
|
|
262
|
-
applyCharacterEditing,
|
|
263
|
-
resetCharacterQuery: resetQuery
|
|
264
|
-
};
|
|
265
225
|
};
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* The letter editing and the numeric editing each define a `CharacterEditingApplier`.
|
|
229
|
+
* This function decides what the new section value should be and if the focus should switch to the next section.
|
|
230
|
+
*
|
|
231
|
+
* If it returns `null`, then the section value is not updated and the focus does not move.
|
|
232
|
+
*/
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Function called by `applyQuery` which decides:
|
|
236
|
+
* - what is the new section value ?
|
|
237
|
+
* - should the query used to get this value be stored for the next key press ?
|
|
238
|
+
*
|
|
239
|
+
* If it returns `{ sectionValue: string; shouldGoToNextSection: boolean }`,
|
|
240
|
+
* Then we store the query and update the section with the new value.
|
|
241
|
+
*
|
|
242
|
+
* If it returns `{ saveQuery: true` },
|
|
243
|
+
* Then we store the query and don't update the section.
|
|
244
|
+
*
|
|
245
|
+
* If it returns `{ saveQuery: false },
|
|
246
|
+
* Then we do nothing.
|
|
247
|
+
*/
|
|
266
248
|
exports.useFieldCharacterEditing = useFieldCharacterEditing;
|
|
@@ -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 {};
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.useFieldRootHandleKeyDown = useFieldRootHandleKeyDown;
|
|
8
|
+
var _useEventCallback = _interopRequireDefault(require("@mui/utils/useEventCallback"));
|
|
9
|
+
var _useUtils = require("../useUtils");
|
|
10
|
+
var _useField = require("./useField.utils");
|
|
11
|
+
/**
|
|
12
|
+
* Returns the `onKeyDown` handler to pass to the root element of the field.
|
|
13
|
+
*/
|
|
14
|
+
function useFieldRootHandleKeyDown(parameters) {
|
|
15
|
+
const utils = (0, _useUtils.useUtils)();
|
|
16
|
+
const {
|
|
17
|
+
manager: {
|
|
18
|
+
internal_fieldValueManager: fieldValueManager
|
|
19
|
+
},
|
|
20
|
+
internalPropsWithDefaults: {
|
|
21
|
+
minutesStep,
|
|
22
|
+
disabled,
|
|
23
|
+
readOnly
|
|
24
|
+
},
|
|
25
|
+
stateResponse: {
|
|
26
|
+
// States and derived states
|
|
27
|
+
state,
|
|
28
|
+
value,
|
|
29
|
+
activeSectionIndex,
|
|
30
|
+
parsedSelectedSections,
|
|
31
|
+
sectionsValueBoundaries,
|
|
32
|
+
localizedDigits,
|
|
33
|
+
timezone,
|
|
34
|
+
sectionOrder,
|
|
35
|
+
// Methods to update the states
|
|
36
|
+
clearValue,
|
|
37
|
+
clearActiveSection,
|
|
38
|
+
setSelectedSections,
|
|
39
|
+
updateSectionValue
|
|
40
|
+
}
|
|
41
|
+
} = parameters;
|
|
42
|
+
return (0, _useEventCallback.default)(event => {
|
|
43
|
+
if (disabled) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
// eslint-disable-next-line default-case
|
|
47
|
+
switch (true) {
|
|
48
|
+
// Select all
|
|
49
|
+
case (event.ctrlKey || event.metaKey) && String.fromCharCode(event.keyCode) === 'A' && !event.shiftKey && !event.altKey:
|
|
50
|
+
{
|
|
51
|
+
// prevent default to make sure that the next line "select all" while updating
|
|
52
|
+
// the internal state at the same time.
|
|
53
|
+
event.preventDefault();
|
|
54
|
+
setSelectedSections('all');
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Move selection to next section
|
|
59
|
+
case event.key === 'ArrowRight':
|
|
60
|
+
{
|
|
61
|
+
event.preventDefault();
|
|
62
|
+
if (parsedSelectedSections == null) {
|
|
63
|
+
setSelectedSections(sectionOrder.startIndex);
|
|
64
|
+
} else if (parsedSelectedSections === 'all') {
|
|
65
|
+
setSelectedSections(sectionOrder.endIndex);
|
|
66
|
+
} else {
|
|
67
|
+
const nextSectionIndex = sectionOrder.neighbors[parsedSelectedSections].rightIndex;
|
|
68
|
+
if (nextSectionIndex !== null) {
|
|
69
|
+
setSelectedSections(nextSectionIndex);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Move selection to previous section
|
|
76
|
+
case event.key === 'ArrowLeft':
|
|
77
|
+
{
|
|
78
|
+
event.preventDefault();
|
|
79
|
+
if (parsedSelectedSections == null) {
|
|
80
|
+
setSelectedSections(sectionOrder.endIndex);
|
|
81
|
+
} else if (parsedSelectedSections === 'all') {
|
|
82
|
+
setSelectedSections(sectionOrder.startIndex);
|
|
83
|
+
} else {
|
|
84
|
+
const nextSectionIndex = sectionOrder.neighbors[parsedSelectedSections].leftIndex;
|
|
85
|
+
if (nextSectionIndex !== null) {
|
|
86
|
+
setSelectedSections(nextSectionIndex);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Reset the value of the selected section
|
|
93
|
+
case event.key === 'Delete':
|
|
94
|
+
{
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
if (readOnly) {
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
if (parsedSelectedSections == null || parsedSelectedSections === 'all') {
|
|
100
|
+
clearValue();
|
|
101
|
+
} else {
|
|
102
|
+
clearActiveSection();
|
|
103
|
+
}
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Increment / decrement the selected section value
|
|
108
|
+
case ['ArrowUp', 'ArrowDown', 'Home', 'End', 'PageUp', 'PageDown'].includes(event.key):
|
|
109
|
+
{
|
|
110
|
+
event.preventDefault();
|
|
111
|
+
if (readOnly || activeSectionIndex == null) {
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// if all sections are selected, mark the currently editing one as selected
|
|
116
|
+
if (parsedSelectedSections === 'all') {
|
|
117
|
+
setSelectedSections(activeSectionIndex);
|
|
118
|
+
}
|
|
119
|
+
const activeSection = state.sections[activeSectionIndex];
|
|
120
|
+
const newSectionValue = adjustSectionValue(utils, timezone, activeSection, event.key, sectionsValueBoundaries, localizedDigits, fieldValueManager.getDateFromSection(value, activeSection), {
|
|
121
|
+
minutesStep
|
|
122
|
+
});
|
|
123
|
+
updateSectionValue({
|
|
124
|
+
section: activeSection,
|
|
125
|
+
newSectionValue,
|
|
126
|
+
shouldGoToNextSection: false
|
|
127
|
+
});
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function getDeltaFromKeyCode(keyCode) {
|
|
134
|
+
switch (keyCode) {
|
|
135
|
+
case 'ArrowUp':
|
|
136
|
+
return 1;
|
|
137
|
+
case 'ArrowDown':
|
|
138
|
+
return -1;
|
|
139
|
+
case 'PageUp':
|
|
140
|
+
return 5;
|
|
141
|
+
case 'PageDown':
|
|
142
|
+
return -5;
|
|
143
|
+
default:
|
|
144
|
+
return 0;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
function adjustSectionValue(utils, timezone, section, keyCode, sectionsValueBoundaries, localizedDigits, activeDate, stepsAttributes) {
|
|
148
|
+
const delta = getDeltaFromKeyCode(keyCode);
|
|
149
|
+
const isStart = keyCode === 'Home';
|
|
150
|
+
const isEnd = keyCode === 'End';
|
|
151
|
+
const shouldSetAbsolute = section.value === '' || isStart || isEnd;
|
|
152
|
+
const adjustDigitSection = () => {
|
|
153
|
+
const sectionBoundaries = sectionsValueBoundaries[section.type]({
|
|
154
|
+
currentDate: activeDate,
|
|
155
|
+
format: section.format,
|
|
156
|
+
contentType: section.contentType
|
|
157
|
+
});
|
|
158
|
+
const getCleanValue = value => (0, _useField.cleanDigitSectionValue)(utils, value, sectionBoundaries, localizedDigits, section);
|
|
159
|
+
const step = section.type === 'minutes' && stepsAttributes?.minutesStep ? stepsAttributes.minutesStep : 1;
|
|
160
|
+
let newSectionValueNumber;
|
|
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
|
+
} else {
|
|
171
|
+
const currentSectionValue = parseInt((0, _useField.removeLocalizedDigits)(section.value, localizedDigits), 10);
|
|
172
|
+
newSectionValueNumber = currentSectionValue + delta * step;
|
|
173
|
+
}
|
|
174
|
+
if (newSectionValueNumber % step !== 0) {
|
|
175
|
+
if (delta < 0 || isStart) {
|
|
176
|
+
newSectionValueNumber += step - (step + newSectionValueNumber) % step; // for JS -3 % 5 = -3 (should be 2)
|
|
177
|
+
}
|
|
178
|
+
if (delta > 0 || isEnd) {
|
|
179
|
+
newSectionValueNumber -= newSectionValueNumber % step;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (newSectionValueNumber > sectionBoundaries.maximum) {
|
|
183
|
+
return getCleanValue(sectionBoundaries.minimum + (newSectionValueNumber - sectionBoundaries.maximum - 1) % (sectionBoundaries.maximum - sectionBoundaries.minimum + 1));
|
|
184
|
+
}
|
|
185
|
+
if (newSectionValueNumber < sectionBoundaries.minimum) {
|
|
186
|
+
return getCleanValue(sectionBoundaries.maximum - (sectionBoundaries.minimum - newSectionValueNumber - 1) % (sectionBoundaries.maximum - sectionBoundaries.minimum + 1));
|
|
187
|
+
}
|
|
188
|
+
return getCleanValue(newSectionValueNumber);
|
|
189
|
+
};
|
|
190
|
+
const adjustLetterSection = () => {
|
|
191
|
+
const options = (0, _useField.getLetterEditingOptions)(utils, timezone, section.type, section.format);
|
|
192
|
+
if (options.length === 0) {
|
|
193
|
+
return section.value;
|
|
194
|
+
}
|
|
195
|
+
if (shouldSetAbsolute) {
|
|
196
|
+
if (delta > 0 || isStart) {
|
|
197
|
+
return options[0];
|
|
198
|
+
}
|
|
199
|
+
return options[options.length - 1];
|
|
200
|
+
}
|
|
201
|
+
const currentOptionIndex = options.indexOf(section.value);
|
|
202
|
+
const newOptionIndex = (currentOptionIndex + delta) % options.length;
|
|
203
|
+
const clampedIndex = (newOptionIndex + options.length) % options.length;
|
|
204
|
+
return options[clampedIndex];
|
|
205
|
+
};
|
|
206
|
+
if (section.contentType === 'digit' || section.contentType === 'digit-with-letter') {
|
|
207
|
+
return adjustDigitSection();
|
|
208
|
+
}
|
|
209
|
+
return adjustLetterSection();
|
|
210
|
+
}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import { UseFieldInternalProps,
|
|
2
|
-
import { FieldSelectedSections, PickersTimezone, InferFieldSection } from "../../../models/index.js";
|
|
1
|
+
import { UseFieldInternalProps, UseFieldState, FieldParsedSelectedSections, FieldSectionsValueBoundaries, SectionOrdering, UseFieldForwardedProps, CharacterEditingQuery } from "./useField.types.js";
|
|
2
|
+
import { FieldSelectedSections, PickersTimezone, InferFieldSection, PickerManager } from "../../../models/index.js";
|
|
3
3
|
import { PickerValidValue } from "../../models/index.js";
|
|
4
|
-
export
|
|
4
|
+
export declare const useFieldState: <TValue extends PickerValidValue, TEnableAccessibleFieldDOMStructure extends boolean, TError, TValidationProps extends {}, TForwardedProps extends UseFieldForwardedProps<TEnableAccessibleFieldDOMStructure>>(parameters: UseFieldStateParameters<TValue, TEnableAccessibleFieldDOMStructure, TError, TValidationProps, TForwardedProps>) => UseFieldStateReturnValue<TValue>;
|
|
5
|
+
interface UseFieldStateParameters<TValue extends PickerValidValue, TEnableAccessibleFieldDOMStructure extends boolean, TError, TValidationProps extends {}, TForwardedProps extends UseFieldForwardedProps<TEnableAccessibleFieldDOMStructure>> {
|
|
6
|
+
manager: PickerManager<TValue, TEnableAccessibleFieldDOMStructure, TError, TValidationProps, any>;
|
|
7
|
+
internalPropsWithDefaults: UseFieldInternalProps<TValue, TEnableAccessibleFieldDOMStructure, TError> & TValidationProps;
|
|
8
|
+
forwardedProps: TForwardedProps;
|
|
9
|
+
}
|
|
10
|
+
export interface UpdateSectionValueParameters<TValue extends PickerValidValue> {
|
|
5
11
|
/**
|
|
6
12
|
* The section on which we want to apply the new value.
|
|
7
13
|
*/
|
|
@@ -15,20 +21,24 @@ export interface UpdateSectionValueParams<TValue extends PickerValidValue> {
|
|
|
15
21
|
*/
|
|
16
22
|
shouldGoToNextSection: boolean;
|
|
17
23
|
}
|
|
18
|
-
export interface
|
|
19
|
-
state: UseFieldState<TValue>;
|
|
20
|
-
value: TValue;
|
|
24
|
+
export interface UseFieldStateReturnValue<TValue extends PickerValidValue> {
|
|
21
25
|
activeSectionIndex: number | null;
|
|
26
|
+
areAllSectionsEmpty: boolean;
|
|
27
|
+
error: boolean;
|
|
28
|
+
localizedDigits: string[];
|
|
22
29
|
parsedSelectedSections: FieldParsedSelectedSections;
|
|
23
|
-
|
|
30
|
+
sectionOrder: SectionOrdering;
|
|
31
|
+
sectionsValueBoundaries: FieldSectionsValueBoundaries;
|
|
32
|
+
state: UseFieldState<TValue>;
|
|
33
|
+
timezone: PickersTimezone;
|
|
34
|
+
value: TValue;
|
|
24
35
|
clearValue: () => void;
|
|
25
36
|
clearActiveSection: () => void;
|
|
26
|
-
|
|
27
|
-
|
|
37
|
+
setCharacterQuery: (characterQuery: CharacterEditingQuery | null) => void;
|
|
38
|
+
setSelectedSections: (sections: FieldSelectedSections) => void;
|
|
28
39
|
setTempAndroidValueStr: (tempAndroidValueStr: string | null) => void;
|
|
29
|
-
|
|
40
|
+
updateSectionValue: (parameters: UpdateSectionValueParameters<TValue>) => void;
|
|
41
|
+
updateValueFromValueStr: (valueStr: string) => void;
|
|
30
42
|
getSectionsFromValue: (value: TValue, fallbackSections?: InferFieldSection<TValue>[] | null) => InferFieldSection<TValue>[];
|
|
31
|
-
localizedDigits: string[];
|
|
32
|
-
timezone: PickersTimezone;
|
|
33
43
|
}
|
|
34
|
-
export
|
|
44
|
+
export {};
|