@mui/x-date-pickers 8.0.0-beta.1 → 8.0.0-beta.2
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 +94 -0
- package/DateCalendar/DateCalendar.js +4 -8
- package/DateCalendar/DayCalendar.js +2 -2
- package/DatePicker/shared.js +3 -9
- package/DateTimePicker/shared.js +3 -13
- package/MonthCalendar/MonthCalendar.js +4 -9
- package/PickersSectionList/PickersSectionList.d.ts +1 -1
- package/PickersSectionList/PickersSectionList.types.d.ts +2 -6
- package/TimePicker/shared.js +3 -3
- package/YearCalendar/YearCalendar.js +4 -10
- package/esm/DateCalendar/DateCalendar.js +6 -10
- package/esm/DateCalendar/DayCalendar.js +2 -2
- package/esm/DatePicker/shared.js +3 -9
- package/esm/DateTimePicker/shared.js +4 -14
- package/esm/MonthCalendar/MonthCalendar.js +6 -11
- package/esm/PickersSectionList/PickersSectionList.d.ts +1 -1
- package/esm/PickersSectionList/PickersSectionList.types.d.ts +2 -6
- package/esm/TimePicker/shared.js +3 -3
- package/esm/YearCalendar/YearCalendar.js +5 -11
- package/esm/index.js +1 -1
- package/esm/internals/hooks/useField/syncSelectionToDOM.d.ts +9 -0
- package/esm/internals/hooks/useField/syncSelectionToDOM.js +50 -0
- package/esm/internals/hooks/useField/useField.types.d.ts +8 -1
- package/esm/internals/hooks/useField/useField.utils.d.ts +1 -3
- package/esm/internals/hooks/useField/useField.utils.js +0 -57
- package/esm/internals/hooks/useField/useFieldHiddenInputProps.d.ts +20 -0
- package/esm/internals/hooks/useField/useFieldHiddenInputProps.js +31 -0
- package/esm/internals/hooks/useField/useFieldInternalPropsWithDefaults.js +8 -10
- package/esm/internals/hooks/useField/useFieldRootHandleKeyDown.js +1 -0
- package/esm/internals/hooks/useField/useFieldRootProps.d.ts +32 -0
- package/esm/internals/hooks/useField/useFieldRootProps.js +150 -0
- package/esm/internals/hooks/useField/useFieldSectionContainerProps.d.ts +15 -0
- package/esm/internals/hooks/useField/useFieldSectionContainerProps.js +29 -0
- package/esm/internals/hooks/useField/useFieldSectionContentProps.d.ts +23 -0
- package/esm/internals/hooks/useField/useFieldSectionContentProps.js +226 -0
- package/esm/internals/hooks/useField/useFieldV7TextField.js +76 -307
- package/esm/internals/index.d.ts +4 -4
- package/esm/internals/index.js +3 -3
- package/esm/locales/deDE.js +2 -3
- package/esm/managers/useDateManager.d.ts +4 -13
- package/esm/managers/useDateManager.js +18 -28
- package/esm/managers/useDateTimeManager.d.ts +4 -13
- package/esm/managers/useDateTimeManager.js +23 -33
- package/esm/managers/useTimeManager.d.ts +4 -13
- package/esm/managers/useTimeManager.js +14 -24
- package/esm/models/manager.d.ts +3 -8
- package/esm/validation/validateDate.js +3 -4
- package/index.js +1 -1
- package/internals/hooks/useField/syncSelectionToDOM.d.ts +9 -0
- package/internals/hooks/useField/syncSelectionToDOM.js +56 -0
- package/internals/hooks/useField/useField.types.d.ts +8 -1
- package/internals/hooks/useField/useField.utils.d.ts +1 -3
- package/internals/hooks/useField/useField.utils.js +2 -61
- package/internals/hooks/useField/useFieldHiddenInputProps.d.ts +20 -0
- package/internals/hooks/useField/useFieldHiddenInputProps.js +39 -0
- package/internals/hooks/useField/useFieldInternalPropsWithDefaults.js +8 -10
- package/internals/hooks/useField/useFieldRootHandleKeyDown.js +1 -0
- package/internals/hooks/useField/useFieldRootProps.d.ts +32 -0
- package/internals/hooks/useField/useFieldRootProps.js +156 -0
- package/internals/hooks/useField/useFieldSectionContainerProps.d.ts +15 -0
- package/internals/hooks/useField/useFieldSectionContainerProps.js +37 -0
- package/internals/hooks/useField/useFieldSectionContentProps.d.ts +23 -0
- package/internals/hooks/useField/useFieldSectionContentProps.js +234 -0
- package/internals/hooks/useField/useFieldV7TextField.js +75 -306
- package/internals/index.d.ts +4 -4
- package/internals/index.js +18 -18
- package/locales/deDE.js +2 -3
- package/managers/useDateManager.d.ts +4 -13
- package/managers/useDateManager.js +18 -28
- package/managers/useDateTimeManager.d.ts +4 -13
- package/managers/useDateTimeManager.js +23 -33
- package/managers/useTimeManager.d.ts +4 -13
- package/managers/useTimeManager.js +15 -25
- package/models/manager.d.ts +3 -8
- package/modern/DateCalendar/DateCalendar.js +6 -10
- package/modern/DateCalendar/DayCalendar.js +2 -2
- package/modern/DatePicker/shared.js +3 -9
- package/modern/DateTimePicker/shared.js +4 -14
- package/modern/MonthCalendar/MonthCalendar.js +6 -11
- package/modern/PickersSectionList/PickersSectionList.d.ts +1 -1
- package/modern/PickersSectionList/PickersSectionList.types.d.ts +2 -6
- package/modern/TimePicker/shared.js +3 -3
- package/modern/YearCalendar/YearCalendar.js +5 -11
- package/modern/index.js +1 -1
- package/modern/internals/hooks/useField/syncSelectionToDOM.d.ts +9 -0
- package/modern/internals/hooks/useField/syncSelectionToDOM.js +50 -0
- package/modern/internals/hooks/useField/useField.types.d.ts +8 -1
- package/modern/internals/hooks/useField/useField.utils.d.ts +1 -3
- package/modern/internals/hooks/useField/useField.utils.js +0 -57
- package/modern/internals/hooks/useField/useFieldHiddenInputProps.d.ts +20 -0
- package/modern/internals/hooks/useField/useFieldHiddenInputProps.js +31 -0
- package/modern/internals/hooks/useField/useFieldInternalPropsWithDefaults.js +8 -10
- package/modern/internals/hooks/useField/useFieldRootHandleKeyDown.js +1 -0
- package/modern/internals/hooks/useField/useFieldRootProps.d.ts +32 -0
- package/modern/internals/hooks/useField/useFieldRootProps.js +150 -0
- package/modern/internals/hooks/useField/useFieldSectionContainerProps.d.ts +15 -0
- package/modern/internals/hooks/useField/useFieldSectionContainerProps.js +29 -0
- package/modern/internals/hooks/useField/useFieldSectionContentProps.d.ts +23 -0
- package/modern/internals/hooks/useField/useFieldSectionContentProps.js +226 -0
- package/modern/internals/hooks/useField/useFieldV7TextField.js +76 -307
- package/modern/internals/index.d.ts +4 -4
- package/modern/internals/index.js +3 -3
- package/modern/locales/deDE.js +2 -3
- package/modern/managers/useDateManager.d.ts +4 -13
- package/modern/managers/useDateManager.js +18 -28
- package/modern/managers/useDateTimeManager.d.ts +4 -13
- package/modern/managers/useDateTimeManager.js +23 -33
- package/modern/managers/useTimeManager.d.ts +4 -13
- package/modern/managers/useTimeManager.js +14 -24
- package/modern/models/manager.d.ts +3 -8
- package/modern/validation/validateDate.js +3 -4
- package/package.json +2 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/validation/validateDate.js +3 -4
|
@@ -5,7 +5,7 @@ import * as React from 'react';
|
|
|
5
5
|
import { applyDefaultDate } from "../internals/utils/date-utils.js";
|
|
6
6
|
import { singleItemFieldValueManager, singleItemValueManager } from "../internals/utils/valueManagers.js";
|
|
7
7
|
import { validateDateTime } from "../validation/index.js";
|
|
8
|
-
import { useUtils } from "../internals/hooks/useUtils.js";
|
|
8
|
+
import { useDefaultDates, useUtils } from "../internals/hooks/useUtils.js";
|
|
9
9
|
import { usePickerTranslations } from "../hooks/usePickerTranslations.js";
|
|
10
10
|
export function useDateTimeManager(parameters = {}) {
|
|
11
11
|
const {
|
|
@@ -17,15 +17,7 @@ export function useDateTimeManager(parameters = {}) {
|
|
|
17
17
|
internal_valueManager: singleItemValueManager,
|
|
18
18
|
internal_fieldValueManager: singleItemFieldValueManager,
|
|
19
19
|
internal_enableAccessibleFieldDOMStructure: enableAccessibleFieldDOMStructure,
|
|
20
|
-
|
|
21
|
-
internalProps,
|
|
22
|
-
utils,
|
|
23
|
-
defaultDates
|
|
24
|
-
}) => _extends({}, internalProps, getDateTimeFieldInternalPropsDefaults({
|
|
25
|
-
internalProps,
|
|
26
|
-
utils,
|
|
27
|
-
defaultDates
|
|
28
|
-
})),
|
|
20
|
+
internal_useApplyDefaultValuesToFieldInternalProps: useApplyDefaultValuesToDateTimeFieldInternalProps,
|
|
29
21
|
internal_useOpenPickerButtonAriaLabel: useOpenPickerButtonAriaLabel
|
|
30
22
|
}), [enableAccessibleFieldDOMStructure]);
|
|
31
23
|
}
|
|
@@ -37,27 +29,25 @@ function useOpenPickerButtonAriaLabel(value) {
|
|
|
37
29
|
return translations.openDatePickerDialogue(formattedValue);
|
|
38
30
|
}, [value, translations, utils]);
|
|
39
31
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
maxTime: internalProps.maxDateTime ?? internalProps.maxTime
|
|
62
|
-
};
|
|
32
|
+
function useApplyDefaultValuesToDateTimeFieldInternalProps(internalProps) {
|
|
33
|
+
const utils = useUtils();
|
|
34
|
+
const validationProps = useApplyDefaultValuesToDateTimeValidationProps(internalProps);
|
|
35
|
+
const ampm = React.useMemo(() => internalProps.ampm ?? utils.is12HourCycleInCurrentLocale(), [internalProps.ampm, utils]);
|
|
36
|
+
return React.useMemo(() => _extends({}, internalProps, validationProps, {
|
|
37
|
+
format: internalProps.format ?? (ampm ? utils.formats.keyboardDateTime12h : utils.formats.keyboardDateTime24h)
|
|
38
|
+
}), [internalProps, validationProps, ampm, utils]);
|
|
39
|
+
}
|
|
40
|
+
export function useApplyDefaultValuesToDateTimeValidationProps(props) {
|
|
41
|
+
const utils = useUtils();
|
|
42
|
+
const defaultDates = useDefaultDates();
|
|
43
|
+
return React.useMemo(() => ({
|
|
44
|
+
disablePast: props.disablePast ?? false,
|
|
45
|
+
disableFuture: props.disableFuture ?? false,
|
|
46
|
+
// TODO: Explore if we can remove it from the public API
|
|
47
|
+
disableIgnoringDatePartForTimeValidation: !!props.minDateTime || !!props.maxDateTime || !!props.disableFuture || !!props.disablePast,
|
|
48
|
+
minDate: applyDefaultDate(utils, props.minDateTime ?? props.minDate, defaultDates.minDate),
|
|
49
|
+
maxDate: applyDefaultDate(utils, props.maxDateTime ?? props.maxDate, defaultDates.maxDate),
|
|
50
|
+
minTime: props.minDateTime ?? props.minTime,
|
|
51
|
+
maxTime: props.maxDateTime ?? props.maxTime
|
|
52
|
+
}), [props.minDateTime, props.maxDateTime, props.minTime, props.maxTime, props.minDate, props.maxDate, props.disableFuture, props.disablePast, utils, defaultDates]);
|
|
63
53
|
}
|
|
@@ -1,24 +1,15 @@
|
|
|
1
1
|
import type { MakeOptional } from '@mui/x-internals/types';
|
|
2
2
|
import { PickerManager, TimeValidationError } from "../models/index.js";
|
|
3
3
|
import { UseFieldInternalProps } from "../internals/hooks/useField/index.js";
|
|
4
|
-
import { MuiPickersAdapterContextValue } from "../LocalizationProvider/LocalizationProvider.js";
|
|
5
4
|
import { AmPmProps } from "../internals/models/props/time.js";
|
|
6
|
-
import { ExportedValidateTimeProps, ValidateTimeProps
|
|
7
|
-
import {
|
|
5
|
+
import { ExportedValidateTimeProps, ValidateTimeProps } from "../validation/validateTime.js";
|
|
6
|
+
import { PickerValue } from "../internals/models/index.js";
|
|
8
7
|
export declare function useTimeManager<TEnableAccessibleFieldDOMStructure extends boolean = true>(parameters?: UseTimeManagerParameters<TEnableAccessibleFieldDOMStructure>): UseTimeManagerReturnValue<TEnableAccessibleFieldDOMStructure>;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* Is used by the `useTimeManager` and `useTimeRangeManager` hooks.
|
|
12
|
-
*/
|
|
13
|
-
export declare function getTimeFieldInternalPropsDefaults(parameters: GetTimeFieldInternalPropsDefaultsParameters): GetTimeFieldInternalPropsDefaultsReturnValue;
|
|
8
|
+
type SharedTimeAndTimeRangeValidationProps = 'disablePast' | 'disableFuture';
|
|
9
|
+
export declare function useApplyDefaultValuesToTimeValidationProps(props: Pick<ExportedValidateTimeProps, SharedTimeAndTimeRangeValidationProps>): Pick<ValidateTimeProps, SharedTimeAndTimeRangeValidationProps>;
|
|
14
10
|
export interface UseTimeManagerParameters<TEnableAccessibleFieldDOMStructure extends boolean> extends AmPmProps {
|
|
15
11
|
enableAccessibleFieldDOMStructure?: TEnableAccessibleFieldDOMStructure;
|
|
16
12
|
}
|
|
17
13
|
export type UseTimeManagerReturnValue<TEnableAccessibleFieldDOMStructure extends boolean> = PickerManager<PickerValue, TEnableAccessibleFieldDOMStructure, TimeValidationError, ValidateTimeProps, TimeManagerFieldInternalProps<TEnableAccessibleFieldDOMStructure>>;
|
|
18
14
|
export interface TimeManagerFieldInternalProps<TEnableAccessibleFieldDOMStructure extends boolean> extends MakeOptional<UseFieldInternalProps<PickerValue, TEnableAccessibleFieldDOMStructure, TimeValidationError>, 'format'>, ExportedValidateTimeProps, AmPmProps {}
|
|
19
|
-
type TimeManagerFieldPropsToDefault = 'format' | ValidateTimePropsToDefault;
|
|
20
|
-
interface GetTimeFieldInternalPropsDefaultsParameters extends Pick<MuiPickersAdapterContextValue, 'utils'> {
|
|
21
|
-
internalProps: Pick<TimeManagerFieldInternalProps<true>, TimeManagerFieldPropsToDefault | 'ampm'>;
|
|
22
|
-
}
|
|
23
|
-
interface GetTimeFieldInternalPropsDefaultsReturnValue extends Pick<PickerManagerFieldInternalPropsWithDefaults<UseTimeManagerReturnValue<true>>, TimeManagerFieldPropsToDefault> {}
|
|
24
15
|
export {};
|
|
@@ -17,13 +17,7 @@ export function useTimeManager(parameters = {}) {
|
|
|
17
17
|
internal_valueManager: singleItemValueManager,
|
|
18
18
|
internal_fieldValueManager: singleItemFieldValueManager,
|
|
19
19
|
internal_enableAccessibleFieldDOMStructure: enableAccessibleFieldDOMStructure,
|
|
20
|
-
|
|
21
|
-
internalProps,
|
|
22
|
-
utils
|
|
23
|
-
}) => _extends({}, internalProps, getTimeFieldInternalPropsDefaults({
|
|
24
|
-
utils,
|
|
25
|
-
internalProps
|
|
26
|
-
})),
|
|
20
|
+
internal_useApplyDefaultValuesToFieldInternalProps: useApplyDefaultValuesToTimeFieldInternalProps,
|
|
27
21
|
internal_useOpenPickerButtonAriaLabel: createUseOpenPickerButtonAriaLabel(ampm)
|
|
28
22
|
}), [ampm, enableAccessibleFieldDOMStructure]);
|
|
29
23
|
}
|
|
@@ -38,21 +32,17 @@ function createUseOpenPickerButtonAriaLabel(ampm) {
|
|
|
38
32
|
}, [value, translations, utils]);
|
|
39
33
|
};
|
|
40
34
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
disablePast: internalProps.disablePast ?? false,
|
|
55
|
-
disableFuture: internalProps.disableFuture ?? false,
|
|
56
|
-
format: internalProps.format ?? defaultFormat
|
|
57
|
-
};
|
|
35
|
+
function useApplyDefaultValuesToTimeFieldInternalProps(internalProps) {
|
|
36
|
+
const utils = useUtils();
|
|
37
|
+
const validationProps = useApplyDefaultValuesToTimeValidationProps(internalProps);
|
|
38
|
+
const ampm = React.useMemo(() => internalProps.ampm ?? utils.is12HourCycleInCurrentLocale(), [internalProps.ampm, utils]);
|
|
39
|
+
return React.useMemo(() => _extends({}, internalProps, validationProps, {
|
|
40
|
+
format: internalProps.format ?? (ampm ? utils.formats.fullTime12h : utils.formats.fullTime24h)
|
|
41
|
+
}), [internalProps, validationProps, ampm, utils]);
|
|
42
|
+
}
|
|
43
|
+
export function useApplyDefaultValuesToTimeValidationProps(props) {
|
|
44
|
+
return React.useMemo(() => ({
|
|
45
|
+
disablePast: props.disablePast ?? false,
|
|
46
|
+
disableFuture: props.disableFuture ?? false
|
|
47
|
+
}), [props.disablePast, props.disableFuture]);
|
|
58
48
|
}
|
package/esm/models/manager.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { FieldValueManager, UseFieldInternalProps } from '../internals/hooks/useField';
|
|
2
|
-
import type { UseLocalizationContextReturnValue } from '../internals/hooks/useUtils';
|
|
3
2
|
import type { PickerValidValue, PickerValueManager } from '../internals/models';
|
|
4
3
|
import type { Validator } from '../validation';
|
|
5
4
|
import type { PickerValueType } from './common';
|
|
@@ -66,18 +65,14 @@ export interface PickerManager<TValue extends PickerValidValue, TEnableAccessibl
|
|
|
66
65
|
* - a default format to display the value in the field
|
|
67
66
|
* - some default validation props that are needed to validate the value (e.g: minDate, maxDate)
|
|
68
67
|
* This property is not part of the public API and should not be used directly.
|
|
69
|
-
* @param {
|
|
68
|
+
* @param {TFieldInternalProps<TFieldInternalProps>} internalProps The field internal props to apply the defaults to.
|
|
70
69
|
* @returns {TFieldInternalPropsWithDefaults} The field internal props with the defaults applied.
|
|
71
70
|
*/
|
|
72
|
-
|
|
71
|
+
internal_useApplyDefaultValuesToFieldInternalProps: (internalProps: TFieldInternalProps) => UseFieldInternalProps<TValue, TEnableAccessibleFieldDOMStructure, TError> & TValidationProps;
|
|
73
72
|
/**
|
|
74
73
|
* Returns a hook that creates the aria-label to apply on the button that opens the Picker.
|
|
75
74
|
* @param {TValue} value The value of the Picker.
|
|
76
75
|
* @returns {string} The aria-label to apply on the button that opens the Picker.
|
|
77
76
|
*/
|
|
78
77
|
internal_useOpenPickerButtonAriaLabel: (value: TValue) => string;
|
|
79
|
-
}
|
|
80
|
-
interface ApplyDefaultsToFieldInternalPropsParameters<TFieldInternalProps extends {}> extends UseLocalizationContextReturnValue {
|
|
81
|
-
internalProps: TFieldInternalProps;
|
|
82
|
-
}
|
|
83
|
-
export {};
|
|
78
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { applyDefaultDate } from "../internals/utils/date-utils.js";
|
|
2
1
|
import { singleItemValueManager } from "../internals/utils/valueManagers.js";
|
|
3
2
|
|
|
4
3
|
/**
|
|
@@ -27,11 +26,11 @@ export const validateDate = ({
|
|
|
27
26
|
shouldDisableMonth,
|
|
28
27
|
shouldDisableYear,
|
|
29
28
|
disablePast,
|
|
30
|
-
disableFuture
|
|
29
|
+
disableFuture,
|
|
30
|
+
minDate,
|
|
31
|
+
maxDate
|
|
31
32
|
} = props;
|
|
32
33
|
const now = adapter.utils.date(undefined, timezone);
|
|
33
|
-
const minDate = applyDefaultDate(adapter.utils, props.minDate, adapter.defaultDates.minDate);
|
|
34
|
-
const maxDate = applyDefaultDate(adapter.utils, props.maxDate, adapter.defaultDates.maxDate);
|
|
35
34
|
switch (true) {
|
|
36
35
|
case !adapter.utils.isValid(value):
|
|
37
36
|
return 'invalidDate';
|
package/index.js
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { PickerValidValue } from "../../models/index.js";
|
|
2
|
+
import { UseFieldDOMGetters } from "./useField.types.js";
|
|
3
|
+
import { UseFieldStateReturnValue } from "./useFieldState.js";
|
|
4
|
+
export declare function syncSelectionToDOM<TValue extends PickerValidValue>(parameters: SyncSelectionToDOMParameters<TValue>): void;
|
|
5
|
+
export interface SyncSelectionToDOMParameters<TValue extends PickerValidValue> {
|
|
6
|
+
domGetters: UseFieldDOMGetters;
|
|
7
|
+
stateResponse: UseFieldStateReturnValue<TValue>;
|
|
8
|
+
focused: boolean;
|
|
9
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.syncSelectionToDOM = syncSelectionToDOM;
|
|
7
|
+
var _utils = require("../../utils/utils");
|
|
8
|
+
function syncSelectionToDOM(parameters) {
|
|
9
|
+
const {
|
|
10
|
+
focused,
|
|
11
|
+
domGetters,
|
|
12
|
+
stateResponse: {
|
|
13
|
+
// States and derived states
|
|
14
|
+
parsedSelectedSections,
|
|
15
|
+
state
|
|
16
|
+
}
|
|
17
|
+
} = parameters;
|
|
18
|
+
if (!domGetters.isReady()) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const selection = document.getSelection();
|
|
22
|
+
if (!selection) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (parsedSelectedSections == null) {
|
|
26
|
+
// If the selection contains an element inside the field, we reset it.
|
|
27
|
+
if (selection.rangeCount > 0 && domGetters.getRoot().contains(selection.getRangeAt(0).startContainer)) {
|
|
28
|
+
selection.removeAllRanges();
|
|
29
|
+
}
|
|
30
|
+
if (focused) {
|
|
31
|
+
domGetters.getRoot().blur();
|
|
32
|
+
}
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// On multi input range pickers we want to update selection range only for the active input
|
|
37
|
+
if (!domGetters.getRoot().contains((0, _utils.getActiveElement)(document))) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const range = new window.Range();
|
|
41
|
+
let target;
|
|
42
|
+
if (parsedSelectedSections === 'all') {
|
|
43
|
+
target = domGetters.getRoot();
|
|
44
|
+
} else {
|
|
45
|
+
const section = state.sections[parsedSelectedSections];
|
|
46
|
+
if (section.type === 'empty') {
|
|
47
|
+
target = domGetters.getSectionContainer(parsedSelectedSections);
|
|
48
|
+
} else {
|
|
49
|
+
target = domGetters.getSectionContent(parsedSelectedSections);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
range.selectNodeContents(target);
|
|
53
|
+
target.focus();
|
|
54
|
+
selection.removeAllRanges();
|
|
55
|
+
selection.addRange(range);
|
|
56
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { FieldSectionType, FieldSection, FieldSelectedSections, MuiPickersAdapter, TimezoneProps, FieldSectionContentType, PickerValidDate, FieldRef, OnErrorProps, InferFieldSection, PickerManager, PickerValueType } from "../../../models/index.js";
|
|
3
3
|
import { InternalPropNames } from "../../../hooks/useSplitFieldProps.js";
|
|
4
|
-
import { PickersSectionElement, PickersSectionListRef } from
|
|
4
|
+
import type { PickersSectionElement, PickersSectionListRef } from '../../../PickersSectionList';
|
|
5
5
|
import { FormProps, InferNonNullablePickerValue, PickerValidValue } from "../../models/index.js";
|
|
6
6
|
export interface UseFieldParameters<TValue extends PickerValidValue, TEnableAccessibleFieldDOMStructure extends boolean, TError, TValidationProps extends {}, TProps extends UseFieldProps<TEnableAccessibleFieldDOMStructure>> {
|
|
7
7
|
manager: PickerManager<TValue, TEnableAccessibleFieldDOMStructure, TError, TValidationProps, any>;
|
|
@@ -319,4 +319,11 @@ export interface CharacterEditingQuery {
|
|
|
319
319
|
export type UseFieldProps<TEnableAccessibleFieldDOMStructure extends boolean> = UseFieldForwardedProps<TEnableAccessibleFieldDOMStructure> & {
|
|
320
320
|
enableAccessibleFieldDOMStructure?: boolean;
|
|
321
321
|
};
|
|
322
|
+
export interface UseFieldDOMGetters {
|
|
323
|
+
isReady: () => boolean;
|
|
324
|
+
getRoot: () => HTMLElement;
|
|
325
|
+
getSectionContainer: (sectionIndex: number) => HTMLElement;
|
|
326
|
+
getSectionContent: (sectionIndex: number) => HTMLElement;
|
|
327
|
+
getSectionIndexFromDOMElement: (element: Element | null | undefined) => number | null;
|
|
328
|
+
}
|
|
322
329
|
export {};
|
|
@@ -33,6 +33,4 @@ export declare const validateSections: <TValue extends PickerValidValue>(section
|
|
|
33
33
|
export declare const mergeDateIntoReferenceDate: (utils: MuiPickersAdapter, dateToTransferFrom: PickerValidDate, sections: FieldSection[], referenceDate: PickerValidDate, shouldLimitToEditedSections: boolean) => PickerValidDate;
|
|
34
34
|
export declare const isAndroid: () => boolean;
|
|
35
35
|
export declare const getSectionOrder: (sections: FieldSection[], shouldApplyRTL: boolean) => SectionOrdering;
|
|
36
|
-
export declare const parseSelectedSections: (selectedSections: FieldSelectedSections, sections: FieldSection[]) => FieldParsedSelectedSections;
|
|
37
|
-
export declare const getSectionValueText: (section: FieldSection, utils: MuiPickersAdapter) => string | undefined;
|
|
38
|
-
export declare const getSectionValueNow: (section: FieldSection, utils: MuiPickersAdapter) => number | undefined;
|
|
36
|
+
export declare const parseSelectedSections: (selectedSections: FieldSelectedSections, sections: FieldSection[]) => FieldParsedSelectedSections;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.validateSections = exports.removeLocalizedDigits = exports.parseSelectedSections = exports.mergeDateIntoReferenceDate = exports.isStringNumber = exports.isAndroid = exports.getSectionsBoundaries = exports.getSectionVisibleValue = exports.
|
|
6
|
+
exports.validateSections = exports.removeLocalizedDigits = exports.parseSelectedSections = exports.mergeDateIntoReferenceDate = exports.isStringNumber = exports.isAndroid = exports.getSectionsBoundaries = exports.getSectionVisibleValue = exports.getSectionOrder = exports.getLocalizedDigits = exports.getLetterEditingOptions = exports.getDaysInWeekStr = exports.getDateSectionConfigFromFormatToken = exports.getDateFromDateSections = exports.doesSectionFormatHaveLeadingZeros = exports.createDateStrForV7HiddenInputFromSections = exports.createDateStrForV6InputFromSections = exports.cleanLeadingZeros = exports.cleanDigitSectionValue = exports.changeSectionValueFormat = exports.applyLocalizedDigits = exports.FORMAT_SECONDS_NO_LEADING_ZEROS = void 0;
|
|
7
7
|
var _dateUtils = require("../../utils/date-utils");
|
|
8
8
|
const getDateSectionConfigFromFormatToken = (utils, formatToken) => {
|
|
9
9
|
const config = utils.formatTokenMap[formatToken];
|
|
@@ -520,63 +520,4 @@ const parseSelectedSections = (selectedSections, sections) => {
|
|
|
520
520
|
}
|
|
521
521
|
return selectedSections;
|
|
522
522
|
};
|
|
523
|
-
exports.parseSelectedSections = parseSelectedSections;
|
|
524
|
-
const getSectionValueText = (section, utils) => {
|
|
525
|
-
if (!section.value) {
|
|
526
|
-
return undefined;
|
|
527
|
-
}
|
|
528
|
-
switch (section.type) {
|
|
529
|
-
case 'month':
|
|
530
|
-
{
|
|
531
|
-
if (section.contentType === 'digit') {
|
|
532
|
-
return utils.format(utils.setMonth(utils.date(), Number(section.value) - 1), 'month');
|
|
533
|
-
}
|
|
534
|
-
const parsedDate = utils.parse(section.value, section.format);
|
|
535
|
-
return parsedDate ? utils.format(parsedDate, 'month') : undefined;
|
|
536
|
-
}
|
|
537
|
-
case 'day':
|
|
538
|
-
return section.contentType === 'digit' ? utils.format(utils.setDate(utils.startOfYear(utils.date()), Number(section.value)), 'dayOfMonthFull') : section.value;
|
|
539
|
-
case 'weekDay':
|
|
540
|
-
// TODO: improve by providing the label of the week day
|
|
541
|
-
return undefined;
|
|
542
|
-
default:
|
|
543
|
-
return undefined;
|
|
544
|
-
}
|
|
545
|
-
};
|
|
546
|
-
exports.getSectionValueText = getSectionValueText;
|
|
547
|
-
const getSectionValueNow = (section, utils) => {
|
|
548
|
-
if (!section.value) {
|
|
549
|
-
return undefined;
|
|
550
|
-
}
|
|
551
|
-
switch (section.type) {
|
|
552
|
-
case 'weekDay':
|
|
553
|
-
{
|
|
554
|
-
if (section.contentType === 'letter') {
|
|
555
|
-
// TODO: improve by resolving the week day number from a letter week day
|
|
556
|
-
return undefined;
|
|
557
|
-
}
|
|
558
|
-
return Number(section.value);
|
|
559
|
-
}
|
|
560
|
-
case 'meridiem':
|
|
561
|
-
{
|
|
562
|
-
const parsedDate = utils.parse(`01:00 ${section.value}`, `${utils.formats.hours12h}:${utils.formats.minutes} ${section.format}`);
|
|
563
|
-
if (parsedDate) {
|
|
564
|
-
return utils.getHours(parsedDate) >= 12 ? 1 : 0;
|
|
565
|
-
}
|
|
566
|
-
return undefined;
|
|
567
|
-
}
|
|
568
|
-
case 'day':
|
|
569
|
-
return section.contentType === 'digit-with-letter' ? parseInt(section.value, 10) : Number(section.value);
|
|
570
|
-
case 'month':
|
|
571
|
-
{
|
|
572
|
-
if (section.contentType === 'digit') {
|
|
573
|
-
return Number(section.value);
|
|
574
|
-
}
|
|
575
|
-
const parsedDate = utils.parse(section.value, section.format);
|
|
576
|
-
return parsedDate ? utils.getMonth(parsedDate) + 1 : undefined;
|
|
577
|
-
}
|
|
578
|
-
default:
|
|
579
|
-
return section.contentType !== 'letter' ? Number(section.value) : undefined;
|
|
580
|
-
}
|
|
581
|
-
};
|
|
582
|
-
exports.getSectionValueNow = getSectionValueNow;
|
|
523
|
+
exports.parseSelectedSections = parseSelectedSections;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { PickerManager } from "../../../models/index.js";
|
|
3
|
+
import { UseFieldStateReturnValue } from "./useFieldState.js";
|
|
4
|
+
/**
|
|
5
|
+
* Generate the props to pass to the hidden input element of the field.
|
|
6
|
+
* It is not used by the non-accessible DOM structure (with an <input /> element for editing).
|
|
7
|
+
* It should be used in the MUI accessible DOM structure and the Base UI implementation.
|
|
8
|
+
* @param {UseFieldHiddenInputPropsParameters} parameters The parameters of the hook.
|
|
9
|
+
* @returns {UseFieldHiddenInputPropsReturnValue} The props to forward to the hidden input element of the field.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useFieldHiddenInputProps(parameters: UseFieldHiddenInputPropsParameters): UseFieldHiddenInputPropsReturnValue;
|
|
12
|
+
interface UseFieldHiddenInputPropsParameters {
|
|
13
|
+
manager: PickerManager<any, any, any, any, any>;
|
|
14
|
+
stateResponse: UseFieldStateReturnValue<any>;
|
|
15
|
+
}
|
|
16
|
+
interface UseFieldHiddenInputPropsReturnValue {
|
|
17
|
+
value: string;
|
|
18
|
+
onChange: React.ChangeEventHandler<HTMLInputElement>;
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.useFieldHiddenInputProps = useFieldHiddenInputProps;
|
|
9
|
+
var React = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _useEventCallback = _interopRequireDefault(require("@mui/utils/useEventCallback"));
|
|
11
|
+
/**
|
|
12
|
+
* Generate the props to pass to the hidden input element of the field.
|
|
13
|
+
* It is not used by the non-accessible DOM structure (with an <input /> element for editing).
|
|
14
|
+
* It should be used in the MUI accessible DOM structure and the Base UI implementation.
|
|
15
|
+
* @param {UseFieldHiddenInputPropsParameters} parameters The parameters of the hook.
|
|
16
|
+
* @returns {UseFieldHiddenInputPropsReturnValue} The props to forward to the hidden input element of the field.
|
|
17
|
+
*/
|
|
18
|
+
function useFieldHiddenInputProps(parameters) {
|
|
19
|
+
const {
|
|
20
|
+
manager: {
|
|
21
|
+
internal_fieldValueManager: fieldValueManager
|
|
22
|
+
},
|
|
23
|
+
stateResponse: {
|
|
24
|
+
// States and derived states
|
|
25
|
+
areAllSectionsEmpty,
|
|
26
|
+
state,
|
|
27
|
+
// Methods to update the states
|
|
28
|
+
updateValueFromValueStr
|
|
29
|
+
}
|
|
30
|
+
} = parameters;
|
|
31
|
+
const handleChange = (0, _useEventCallback.default)(event => {
|
|
32
|
+
updateValueFromValueStr(event.target.value);
|
|
33
|
+
});
|
|
34
|
+
const valueStr = React.useMemo(() => areAllSectionsEmpty ? '' : fieldValueManager.getV7HiddenInputValueFromSections(state.sections), [areAllSectionsEmpty, state.sections, fieldValueManager]);
|
|
35
|
+
return {
|
|
36
|
+
value: valueStr,
|
|
37
|
+
onChange: handleChange
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -9,7 +9,6 @@ exports.useFieldInternalPropsWithDefaults = useFieldInternalPropsWithDefaults;
|
|
|
9
9
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
10
|
var React = _interopRequireWildcard(require("react"));
|
|
11
11
|
var _useForkRef = _interopRequireDefault(require("@mui/utils/useForkRef"));
|
|
12
|
-
var _useUtils = require("../useUtils");
|
|
13
12
|
var _useNullablePickerContext = require("../useNullablePickerContext");
|
|
14
13
|
var _useNullableFieldPrivateContext = require("../useNullableFieldPrivateContext");
|
|
15
14
|
/**
|
|
@@ -19,11 +18,12 @@ var _useNullableFieldPrivateContext = require("../useNullableFieldPrivateContext
|
|
|
19
18
|
*/
|
|
20
19
|
function useFieldInternalPropsWithDefaults(parameters) {
|
|
21
20
|
const {
|
|
22
|
-
manager
|
|
21
|
+
manager: {
|
|
22
|
+
internal_useApplyDefaultValuesToFieldInternalProps: useApplyDefaultValuesToFieldInternalProps
|
|
23
|
+
},
|
|
23
24
|
internalProps,
|
|
24
25
|
skipContextFieldRefAssignment
|
|
25
26
|
} = parameters;
|
|
26
|
-
const localizationContext = (0, _useUtils.useLocalizationContext)();
|
|
27
27
|
const pickerContext = (0, _useNullablePickerContext.useNullablePickerContext)();
|
|
28
28
|
const fieldPrivateContext = (0, _useNullableFieldPrivateContext.useNullableFieldPrivateContext)();
|
|
29
29
|
const handleFieldRef = (0, _useForkRef.default)(internalProps.unstableFieldRef, skipContextFieldRefAssignment ? null : fieldPrivateContext?.fieldRef);
|
|
@@ -34,12 +34,11 @@ function useFieldInternalPropsWithDefaults(parameters) {
|
|
|
34
34
|
shouldClose: false
|
|
35
35
|
});
|
|
36
36
|
}, [setValue]);
|
|
37
|
-
|
|
38
|
-
let internalPropsWithDefaultsFromContext = internalProps;
|
|
37
|
+
const internalPropsWithDefaultsFromContext = React.useMemo(() => {
|
|
39
38
|
// If one of the context is null,
|
|
40
39
|
// Then the field is used as a standalone component and the other context will be null as well.
|
|
41
40
|
if (fieldPrivateContext != null && pickerContext != null) {
|
|
42
|
-
|
|
41
|
+
return (0, _extends2.default)({
|
|
43
42
|
value: pickerContext.value,
|
|
44
43
|
onChange: handleChangeFromPicker,
|
|
45
44
|
timezone: pickerContext.timezone,
|
|
@@ -55,8 +54,7 @@ function useFieldInternalPropsWithDefaults(parameters) {
|
|
|
55
54
|
unstableFieldRef: handleFieldRef
|
|
56
55
|
}, internalProps);
|
|
57
56
|
}
|
|
58
|
-
return
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}, [manager, localizationContext, pickerContext, fieldPrivateContext, internalProps, handleChangeFromPicker, handleFieldRef]);
|
|
57
|
+
return internalProps;
|
|
58
|
+
}, [pickerContext, fieldPrivateContext, internalProps, handleChangeFromPicker, handleFieldRef]);
|
|
59
|
+
return useApplyDefaultValuesToFieldInternalProps(internalPropsWithDefaultsFromContext);
|
|
62
60
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { PickerManager } from "../../../models/index.js";
|
|
2
|
+
import { UseFieldDOMGetters, UseFieldInternalProps } from "./useField.types.js";
|
|
3
|
+
import { UseFieldStateReturnValue } from "./useFieldState.js";
|
|
4
|
+
import { UseFieldCharacterEditingReturnValue } from "./useFieldCharacterEditing.js";
|
|
5
|
+
/**
|
|
6
|
+
* Generate the props to pass to the root element of the field.
|
|
7
|
+
* It is not used by the non-accessible DOM structure (with an <input /> element for editing).
|
|
8
|
+
* It should be used in the MUI accessible DOM structure and the Base UI implementation.
|
|
9
|
+
* @param {UseFieldRootPropsParameters} parameters The parameters of the hook.
|
|
10
|
+
* @returns {UseFieldRootPropsReturnValue} The props to forward to the root element of the field.
|
|
11
|
+
*/
|
|
12
|
+
export declare function useFieldRootProps(parameters: UseFieldRootPropsParameters): UseFieldRootPropsReturnValue;
|
|
13
|
+
interface UseFieldRootPropsParameters {
|
|
14
|
+
manager: PickerManager<any, any, any, any, any>;
|
|
15
|
+
stateResponse: UseFieldStateReturnValue<any>;
|
|
16
|
+
applyCharacterEditing: UseFieldCharacterEditingReturnValue;
|
|
17
|
+
internalPropsWithDefaults: UseFieldInternalProps<any, any, any>;
|
|
18
|
+
domGetters: UseFieldDOMGetters;
|
|
19
|
+
focused: boolean;
|
|
20
|
+
setFocused: (focused: boolean) => void;
|
|
21
|
+
}
|
|
22
|
+
interface UseFieldRootPropsReturnValue {
|
|
23
|
+
onKeyDown: React.KeyboardEventHandler<HTMLDivElement>;
|
|
24
|
+
onBlur: React.FocusEventHandler<HTMLDivElement>;
|
|
25
|
+
onFocus: React.FocusEventHandler<HTMLDivElement>;
|
|
26
|
+
onClick: React.MouseEventHandler<HTMLDivElement>;
|
|
27
|
+
onPaste: React.ClipboardEventHandler<HTMLDivElement>;
|
|
28
|
+
onInput: React.FormEventHandler<HTMLDivElement>;
|
|
29
|
+
contentEditable: boolean;
|
|
30
|
+
tabIndex: number;
|
|
31
|
+
}
|
|
32
|
+
export {};
|