@mui/x-date-pickers-pro 6.0.3 → 6.0.4
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 +61 -0
- package/DateRangePicker/DateRangePicker.js +12 -0
- package/DateRangePicker/DateRangePickerToolbar.d.ts +1 -1
- package/DateRangePicker/shared.d.ts +1 -1
- package/DesktopDateRangePicker/DesktopDateRangePicker.js +12 -0
- package/MobileDateRangePicker/MobileDateRangePicker.js +12 -0
- package/MultiInputDateRangeField/MultiInputDateRangeField.types.d.ts +1 -1
- package/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.types.d.ts +1 -1
- package/MultiInputTimeRangeField/MultiInputTimeRangeField.types.d.ts +1 -1
- package/SingleInputDateRangeField/SingleInputDateRangeField.d.ts +1 -0
- package/SingleInputDateRangeField/SingleInputDateRangeField.js +1 -0
- package/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.d.ts +1 -0
- package/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.js +1 -0
- package/SingleInputTimeRangeField/SingleInputTimeRangeField.d.ts +1 -0
- package/SingleInputTimeRangeField/SingleInputTimeRangeField.js +1 -0
- package/dateRangeViewRenderers/dateRangeViewRenderers.d.ts +1 -1
- package/index.js +1 -1
- package/internal/hooks/useDesktopRangePicker/useDesktopRangePicker.d.ts +1 -1
- package/internal/hooks/useDesktopRangePicker/useDesktopRangePicker.js +32 -40
- package/internal/hooks/useDesktopRangePicker/useDesktopRangePicker.types.d.ts +9 -29
- package/internal/hooks/useEnrichedRangePickerFieldProps.d.ts +53 -0
- package/internal/hooks/useEnrichedRangePickerFieldProps.js +202 -0
- package/internal/hooks/useMobileRangePicker/useMobileRangePicker.d.ts +1 -1
- package/internal/hooks/useMobileRangePicker/useMobileRangePicker.js +36 -39
- package/internal/hooks/useMobileRangePicker/useMobileRangePicker.types.d.ts +9 -28
- package/internal/hooks/useMultiInputRangeField/useMultiInputDateRangeField.d.ts +1 -1
- package/internal/hooks/useMultiInputRangeField/useMultiInputDateTimeRangeField.d.ts +1 -1
- package/internal/hooks/useMultiInputRangeField/useMultiInputRangeField.types.d.ts +3 -3
- package/internal/hooks/useMultiInputRangeField/useMultiInputTimeRangeField.d.ts +1 -1
- package/internal/hooks/useRangePosition.d.ts +4 -0
- package/internal/hooks/useRangePosition.js +16 -1
- package/internal/hooks/useStaticRangePicker/useStaticRangePicker.d.ts +1 -1
- package/internal/hooks/useStaticRangePicker/useStaticRangePicker.types.d.ts +3 -2
- package/internal/hooks/validation/useDateRangeValidation.d.ts +2 -1
- package/internal/hooks/validation/useDateTimeRangeValidation.d.ts +2 -1
- package/internal/hooks/validation/useTimeRangeValidation.d.ts +2 -1
- package/internal/models/fields.d.ts +7 -2
- package/internal/models/index.d.ts +1 -0
- package/internal/models/index.js +2 -1
- package/internal/models/rangePickerProps.d.ts +17 -0
- package/internal/models/rangePickerProps.js +1 -0
- package/internal/utils/releaseInfo.js +1 -1
- package/internal/utils/valueManagers.js +21 -19
- package/legacy/DateRangePicker/DateRangePicker.js +12 -0
- package/legacy/DesktopDateRangePicker/DesktopDateRangePicker.js +12 -0
- package/legacy/MobileDateRangePicker/MobileDateRangePicker.js +12 -0
- package/legacy/SingleInputDateRangeField/SingleInputDateRangeField.js +1 -0
- package/legacy/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.js +1 -0
- package/legacy/SingleInputTimeRangeField/SingleInputTimeRangeField.js +1 -0
- package/legacy/index.js +1 -1
- package/legacy/internal/hooks/useDesktopRangePicker/useDesktopRangePicker.js +32 -40
- package/legacy/internal/hooks/useEnrichedRangePickerFieldProps.js +200 -0
- package/legacy/internal/hooks/useMobileRangePicker/useMobileRangePicker.js +36 -39
- package/legacy/internal/hooks/useRangePosition.js +16 -1
- package/legacy/internal/models/index.js +2 -1
- package/legacy/internal/models/rangePickerProps.js +1 -0
- package/legacy/internal/utils/releaseInfo.js +1 -1
- package/legacy/internal/utils/valueManagers.js +21 -19
- package/modern/DateRangePicker/DateRangePicker.js +12 -0
- package/modern/DesktopDateRangePicker/DesktopDateRangePicker.js +12 -0
- package/modern/MobileDateRangePicker/MobileDateRangePicker.js +12 -0
- package/modern/SingleInputDateRangeField/SingleInputDateRangeField.js +1 -0
- package/modern/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.js +1 -0
- package/modern/SingleInputTimeRangeField/SingleInputTimeRangeField.js +1 -0
- package/modern/index.js +1 -1
- package/modern/internal/hooks/useDesktopRangePicker/useDesktopRangePicker.js +30 -38
- package/modern/internal/hooks/useEnrichedRangePickerFieldProps.js +195 -0
- package/modern/internal/hooks/useMobileRangePicker/useMobileRangePicker.js +35 -38
- package/modern/internal/hooks/useRangePosition.js +16 -1
- package/modern/internal/models/index.js +2 -1
- package/modern/internal/models/rangePickerProps.js +1 -0
- package/modern/internal/utils/releaseInfo.js +1 -1
- package/modern/internal/utils/valueManagers.js +21 -19
- package/node/DateRangePicker/DateRangePicker.js +12 -0
- package/node/DesktopDateRangePicker/DesktopDateRangePicker.js +12 -0
- package/node/MobileDateRangePicker/MobileDateRangePicker.js +12 -0
- package/node/SingleInputDateRangeField/SingleInputDateRangeField.js +1 -0
- package/node/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.js +1 -0
- package/node/SingleInputTimeRangeField/SingleInputTimeRangeField.js +1 -0
- package/node/index.js +1 -1
- package/node/internal/hooks/useDesktopRangePicker/useDesktopRangePicker.js +29 -37
- package/node/internal/hooks/useEnrichedRangePickerFieldProps.js +205 -0
- package/node/internal/hooks/useMobileRangePicker/useMobileRangePicker.js +34 -37
- package/node/internal/hooks/useRangePosition.js +18 -1
- package/node/internal/models/index.js +11 -0
- package/node/internal/models/rangePickerProps.js +5 -0
- package/node/internal/utils/releaseInfo.js +1 -1
- package/node/internal/utils/valueManagers.js +20 -18
- package/package.json +2 -2
- package/internal/hooks/useRangePickerInputProps.d.ts +0 -19
- package/internal/hooks/useRangePickerInputProps.js +0 -89
- package/legacy/internal/hooks/useRangePickerInputProps.js +0 -88
- package/modern/internal/hooks/useRangePickerInputProps.js +0 -86
- package/node/internal/hooks/useRangePickerInputProps.js +0 -96
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.useEnrichedRangePickerFieldProps = void 0;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var React = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _utils = require("@mui/base/utils");
|
|
11
|
+
var _useEventCallback = _interopRequireDefault(require("@mui/utils/useEventCallback"));
|
|
12
|
+
var _useForkRef = _interopRequireDefault(require("@mui/utils/useForkRef"));
|
|
13
|
+
var _internals = require("@mui/x-date-pickers/internals");
|
|
14
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
16
|
+
const useMultiInputFieldSlotProps = ({
|
|
17
|
+
wrapperVariant,
|
|
18
|
+
open,
|
|
19
|
+
actions,
|
|
20
|
+
readOnly,
|
|
21
|
+
labelId,
|
|
22
|
+
disableOpenPicker,
|
|
23
|
+
onBlur,
|
|
24
|
+
rangePosition,
|
|
25
|
+
onRangePositionChange,
|
|
26
|
+
localeText: inLocaleText,
|
|
27
|
+
pickerSlotProps,
|
|
28
|
+
pickerSlots,
|
|
29
|
+
fieldProps
|
|
30
|
+
}) => {
|
|
31
|
+
const localeText = (0, _internals.useLocaleText)();
|
|
32
|
+
const startRef = React.useRef(null);
|
|
33
|
+
const endRef = React.useRef(null);
|
|
34
|
+
React.useEffect(() => {
|
|
35
|
+
if (!open) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (rangePosition === 'start') {
|
|
39
|
+
startRef.current?.focus();
|
|
40
|
+
} else if (rangePosition === 'end') {
|
|
41
|
+
endRef.current?.focus();
|
|
42
|
+
}
|
|
43
|
+
}, [rangePosition, open]);
|
|
44
|
+
const openRangeStartSelection = event => {
|
|
45
|
+
event.stopPropagation();
|
|
46
|
+
onRangePositionChange('start');
|
|
47
|
+
if (!readOnly && !disableOpenPicker) {
|
|
48
|
+
actions.onOpen();
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const openRangeEndSelection = event => {
|
|
52
|
+
event.stopPropagation();
|
|
53
|
+
onRangePositionChange('end');
|
|
54
|
+
if (!readOnly && !disableOpenPicker) {
|
|
55
|
+
actions.onOpen();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const handleFocusStart = () => {
|
|
59
|
+
if (open) {
|
|
60
|
+
onRangePositionChange('start');
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const handleFocusEnd = () => {
|
|
64
|
+
if (open) {
|
|
65
|
+
onRangePositionChange('end');
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const slots = (0, _extends2.default)({
|
|
69
|
+
textField: pickerSlots?.textField,
|
|
70
|
+
root: pickerSlots?.fieldRoot,
|
|
71
|
+
separator: pickerSlots?.fieldSeparator
|
|
72
|
+
}, fieldProps.slots);
|
|
73
|
+
const slotProps = (0, _extends2.default)({}, fieldProps.slotProps, {
|
|
74
|
+
textField: ownerState => {
|
|
75
|
+
let inputProps;
|
|
76
|
+
if (ownerState.position === 'start') {
|
|
77
|
+
inputProps = (0, _extends2.default)({
|
|
78
|
+
inputRef: startRef,
|
|
79
|
+
label: inLocaleText?.start ?? localeText.start,
|
|
80
|
+
onKeyDown: (0, _internals.onSpaceOrEnter)(openRangeStartSelection),
|
|
81
|
+
onFocus: handleFocusStart,
|
|
82
|
+
focused: open ? rangePosition === 'start' : undefined
|
|
83
|
+
}, !readOnly && !fieldProps.disabled && {
|
|
84
|
+
onClick: openRangeStartSelection
|
|
85
|
+
}, wrapperVariant === 'mobile' && {
|
|
86
|
+
readOnly: true
|
|
87
|
+
});
|
|
88
|
+
} else {
|
|
89
|
+
inputProps = (0, _extends2.default)({
|
|
90
|
+
inputRef: endRef,
|
|
91
|
+
label: inLocaleText?.end ?? localeText.end,
|
|
92
|
+
onKeyDown: (0, _internals.onSpaceOrEnter)(openRangeEndSelection),
|
|
93
|
+
onFocus: handleFocusEnd,
|
|
94
|
+
focused: open ? rangePosition === 'end' : undefined
|
|
95
|
+
}, !readOnly && !fieldProps.disabled && {
|
|
96
|
+
onClick: openRangeEndSelection
|
|
97
|
+
}, wrapperVariant === 'mobile' && {
|
|
98
|
+
readOnly: true
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return (0, _extends2.default)({}, labelId != null && {
|
|
102
|
+
id: `${labelId}-${ownerState.position}`
|
|
103
|
+
}, inputProps, (0, _utils.resolveComponentProps)(pickerSlotProps?.textField, ownerState));
|
|
104
|
+
},
|
|
105
|
+
root: ownerState => {
|
|
106
|
+
const rootProps = {
|
|
107
|
+
onBlur
|
|
108
|
+
};
|
|
109
|
+
return (0, _extends2.default)({}, rootProps, (0, _utils.resolveComponentProps)(pickerSlotProps?.fieldRoot, ownerState));
|
|
110
|
+
},
|
|
111
|
+
separator: pickerSlotProps?.fieldSeparator
|
|
112
|
+
});
|
|
113
|
+
const enrichedFieldProps = (0, _extends2.default)({}, fieldProps, {
|
|
114
|
+
slots,
|
|
115
|
+
slotProps
|
|
116
|
+
});
|
|
117
|
+
return enrichedFieldProps;
|
|
118
|
+
};
|
|
119
|
+
const useSingleInputFieldSlotProps = ({
|
|
120
|
+
wrapperVariant,
|
|
121
|
+
open,
|
|
122
|
+
actions,
|
|
123
|
+
readOnly,
|
|
124
|
+
inputRef: inInputRef,
|
|
125
|
+
labelId,
|
|
126
|
+
disableOpenPicker,
|
|
127
|
+
label,
|
|
128
|
+
onBlur,
|
|
129
|
+
rangePosition,
|
|
130
|
+
onRangePositionChange,
|
|
131
|
+
singleInputFieldRef,
|
|
132
|
+
pickerSlots,
|
|
133
|
+
pickerSlotProps,
|
|
134
|
+
fieldProps
|
|
135
|
+
}) => {
|
|
136
|
+
const inputRef = React.useRef(null);
|
|
137
|
+
const handleInputRef = (0, _useForkRef.default)(inInputRef, inputRef);
|
|
138
|
+
const handleFieldRef = (0, _useForkRef.default)(fieldProps.unstableFieldRef, singleInputFieldRef);
|
|
139
|
+
React.useEffect(() => {
|
|
140
|
+
if (!open) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
inputRef.current?.focus();
|
|
144
|
+
}, [rangePosition, open]);
|
|
145
|
+
const updateRangePosition = () => {
|
|
146
|
+
if (!singleInputFieldRef.current || inputRef.current !== (0, _internals.getActiveElement)(document)) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const sections = singleInputFieldRef.current.getSections();
|
|
150
|
+
const activeSectionIndex = singleInputFieldRef.current?.getActiveSectionIndex();
|
|
151
|
+
const domRangePosition = activeSectionIndex == null || activeSectionIndex < sections.length / 2 ? 'start' : 'end';
|
|
152
|
+
if (domRangePosition != null && domRangePosition !== rangePosition) {
|
|
153
|
+
onRangePositionChange(domRangePosition);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const handleSelectedSectionsChange = (0, _useEventCallback.default)(selectedSections => {
|
|
157
|
+
setTimeout(updateRangePosition);
|
|
158
|
+
fieldProps.onSelectedSectionsChange?.(selectedSections);
|
|
159
|
+
});
|
|
160
|
+
const openPicker = event => {
|
|
161
|
+
event.stopPropagation();
|
|
162
|
+
if (!readOnly && !disableOpenPicker) {
|
|
163
|
+
actions.onOpen();
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
const slots = (0, _extends2.default)({}, fieldProps.slots, {
|
|
167
|
+
textField: pickerSlots?.textField
|
|
168
|
+
});
|
|
169
|
+
const slotProps = (0, _extends2.default)({}, fieldProps.slotProps, {
|
|
170
|
+
textField: pickerSlotProps?.textField
|
|
171
|
+
});
|
|
172
|
+
const enrichedFieldProps = (0, _extends2.default)({}, fieldProps, {
|
|
173
|
+
slots,
|
|
174
|
+
slotProps,
|
|
175
|
+
label,
|
|
176
|
+
unstableFieldRef: handleFieldRef,
|
|
177
|
+
inputRef: handleInputRef,
|
|
178
|
+
onKeyDown: (0, _internals.onSpaceOrEnter)(openPicker, fieldProps.onKeyDown),
|
|
179
|
+
onSelectedSectionsChange: handleSelectedSectionsChange,
|
|
180
|
+
onBlur,
|
|
181
|
+
focused: open
|
|
182
|
+
}, labelId != null && {
|
|
183
|
+
id: labelId
|
|
184
|
+
}, wrapperVariant === 'mobile' && {
|
|
185
|
+
readOnly: true
|
|
186
|
+
}, !readOnly && !fieldProps.disabled && {
|
|
187
|
+
onClick: openPicker
|
|
188
|
+
});
|
|
189
|
+
return enrichedFieldProps;
|
|
190
|
+
};
|
|
191
|
+
const useEnrichedRangePickerFieldProps = params => {
|
|
192
|
+
/* eslint-disable react-hooks/rules-of-hooks */
|
|
193
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
194
|
+
const fieldTypeRef = React.useRef(params.fieldType);
|
|
195
|
+
if (params.fieldType !== fieldTypeRef.current) {
|
|
196
|
+
console.error('Should not switch between a multi input field and a single input field on a range picker.');
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (params.fieldType === 'multi-input') {
|
|
200
|
+
return useMultiInputFieldSlotProps(params);
|
|
201
|
+
}
|
|
202
|
+
return useSingleInputFieldSlotProps(params);
|
|
203
|
+
/* eslint-enable react-hooks/rules-of-hooks */
|
|
204
|
+
};
|
|
205
|
+
exports.useEnrichedRangePickerFieldProps = useEnrichedRangePickerFieldProps;
|
|
@@ -13,7 +13,7 @@ var _LocalizationProvider = require("@mui/x-date-pickers/LocalizationProvider");
|
|
|
13
13
|
var _PickersLayout = require("@mui/x-date-pickers/PickersLayout");
|
|
14
14
|
var _internals = require("@mui/x-date-pickers/internals");
|
|
15
15
|
var _useId = _interopRequireDefault(require("@mui/utils/useId"));
|
|
16
|
-
var
|
|
16
|
+
var _useEnrichedRangePickerFieldProps = require("../useEnrichedRangePickerFieldProps");
|
|
17
17
|
var _releaseInfo = require("../../utils/releaseInfo");
|
|
18
18
|
var _useRangePosition = require("../useRangePosition");
|
|
19
19
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
@@ -32,6 +32,8 @@ const useMobileRangePicker = ({
|
|
|
32
32
|
className,
|
|
33
33
|
sx,
|
|
34
34
|
format,
|
|
35
|
+
label,
|
|
36
|
+
inputRef,
|
|
35
37
|
readOnly,
|
|
36
38
|
disabled,
|
|
37
39
|
disableOpenPicker,
|
|
@@ -39,7 +41,8 @@ const useMobileRangePicker = ({
|
|
|
39
41
|
} = props;
|
|
40
42
|
const {
|
|
41
43
|
rangePosition,
|
|
42
|
-
onRangePositionChange
|
|
44
|
+
onRangePositionChange,
|
|
45
|
+
singleInputFieldRef
|
|
43
46
|
} = (0, _useRangePosition.useRangePosition)(props);
|
|
44
47
|
const labelId = (0, _useId.default)();
|
|
45
48
|
const contextLocaleText = (0, _internals.useLocaleText)();
|
|
@@ -60,18 +63,8 @@ const useMobileRangePicker = ({
|
|
|
60
63
|
onRangePositionChange
|
|
61
64
|
}
|
|
62
65
|
});
|
|
63
|
-
const fieldSlotProps = (0, _useRangePickerInputProps.useRangePickerInputProps)({
|
|
64
|
-
wrapperVariant: 'mobile',
|
|
65
|
-
open,
|
|
66
|
-
actions,
|
|
67
|
-
readOnly,
|
|
68
|
-
disabled,
|
|
69
|
-
disableOpenPicker,
|
|
70
|
-
localeText,
|
|
71
|
-
rangePosition,
|
|
72
|
-
onRangePositionChange
|
|
73
|
-
});
|
|
74
66
|
const Field = slots.field;
|
|
67
|
+
const fieldType = Field.fieldType ?? 'multi-input';
|
|
75
68
|
const fieldProps = (0, _utils.useSlotProps)({
|
|
76
69
|
elementType: Field,
|
|
77
70
|
externalSlotProps: innerSlotProps?.field,
|
|
@@ -81,25 +74,28 @@ const useMobileRangePicker = ({
|
|
|
81
74
|
className,
|
|
82
75
|
sx,
|
|
83
76
|
format
|
|
77
|
+
}, fieldType === 'single-input' && {
|
|
78
|
+
inputRef
|
|
84
79
|
}),
|
|
85
80
|
ownerState: props
|
|
86
81
|
});
|
|
87
|
-
const slotsForField = (0, _extends2.default)({
|
|
88
|
-
textField: slots.textField
|
|
89
|
-
}, fieldProps.slots);
|
|
90
82
|
const isToolbarHidden = innerSlotProps?.toolbar?.hidden ?? false;
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
83
|
+
const enrichedFieldProps = (0, _useEnrichedRangePickerFieldProps.useEnrichedRangePickerFieldProps)({
|
|
84
|
+
wrapperVariant: 'mobile',
|
|
85
|
+
fieldType,
|
|
86
|
+
open,
|
|
87
|
+
actions,
|
|
88
|
+
readOnly,
|
|
89
|
+
labelId,
|
|
90
|
+
disableOpenPicker,
|
|
91
|
+
label,
|
|
92
|
+
localeText,
|
|
93
|
+
rangePosition,
|
|
94
|
+
onRangePositionChange,
|
|
95
|
+
singleInputFieldRef,
|
|
96
|
+
pickerSlots: slots,
|
|
97
|
+
pickerSlotProps: innerSlotProps,
|
|
98
|
+
fieldProps
|
|
103
99
|
});
|
|
104
100
|
const slotPropsForLayout = (0, _extends2.default)({}, innerSlotProps, {
|
|
105
101
|
toolbar: (0, _extends2.default)({}, innerSlotProps?.toolbar, {
|
|
@@ -113,11 +109,15 @@ const useMobileRangePicker = ({
|
|
|
113
109
|
let labelledById = labelId;
|
|
114
110
|
if (isToolbarHidden) {
|
|
115
111
|
const labels = [];
|
|
116
|
-
if (
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
112
|
+
if (fieldType === 'multi-input') {
|
|
113
|
+
if (finalLocaleText.start) {
|
|
114
|
+
labels.push(`${labelId}-start-label`);
|
|
115
|
+
}
|
|
116
|
+
if (finalLocaleText.end) {
|
|
117
|
+
labels.push(`${labelId}-end-label`);
|
|
118
|
+
}
|
|
119
|
+
} else if (label != null) {
|
|
120
|
+
labels.push(`${labelId}-label`);
|
|
121
121
|
}
|
|
122
122
|
labelledById = labels.length > 0 ? labels.join(' ') : undefined;
|
|
123
123
|
}
|
|
@@ -128,10 +128,7 @@ const useMobileRangePicker = ({
|
|
|
128
128
|
});
|
|
129
129
|
const renderPicker = () => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_LocalizationProvider.LocalizationProvider, {
|
|
130
130
|
localeText: localeText,
|
|
131
|
-
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Field, (0, _extends2.default)({},
|
|
132
|
-
slots: slotsForField,
|
|
133
|
-
slotProps: slotPropsForField
|
|
134
|
-
})), /*#__PURE__*/(0, _jsxRuntime.jsx)(_internals.PickersModalDialog, (0, _extends2.default)({}, actions, {
|
|
131
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Field, (0, _extends2.default)({}, enrichedFieldProps)), /*#__PURE__*/(0, _jsxRuntime.jsx)(_internals.PickersModalDialog, (0, _extends2.default)({}, actions, {
|
|
135
132
|
open: open,
|
|
136
133
|
slots: slots,
|
|
137
134
|
slotProps: slotProps,
|
|
@@ -5,22 +5,39 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.useRangePosition = void 0;
|
|
8
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
9
|
var _useControlled = _interopRequireDefault(require("@mui/utils/useControlled"));
|
|
9
10
|
var _useEventCallback = _interopRequireDefault(require("@mui/utils/useEventCallback"));
|
|
11
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
12
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
10
13
|
const useRangePosition = props => {
|
|
14
|
+
const singleInputFieldRef = React.useRef();
|
|
11
15
|
const [rangePosition, setRangePosition] = (0, _useControlled.default)({
|
|
12
16
|
name: 'useRangePosition',
|
|
13
17
|
state: 'rangePosition',
|
|
14
18
|
controlled: props.rangePosition,
|
|
15
19
|
default: props.defaultRangePosition ?? 'start'
|
|
16
20
|
});
|
|
21
|
+
|
|
22
|
+
// When using a single input field,
|
|
23
|
+
// we want to select the 1st section of the edited date when updating the range position.
|
|
24
|
+
const syncRangePositionWithSingleInputField = newRangePosition => {
|
|
25
|
+
if (singleInputFieldRef.current == null) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const sections = singleInputFieldRef.current.getSections();
|
|
29
|
+
const targetActiveSectionIndex = newRangePosition === 'start' ? 0 : sections.length / 2;
|
|
30
|
+
singleInputFieldRef.current.setSelectedSections(targetActiveSectionIndex);
|
|
31
|
+
};
|
|
17
32
|
const handleRangePositionChange = (0, _useEventCallback.default)(newRangePosition => {
|
|
18
33
|
setRangePosition(newRangePosition);
|
|
19
34
|
props.onRangePositionChange?.(newRangePosition);
|
|
35
|
+
syncRangePositionWithSingleInputField(newRangePosition);
|
|
20
36
|
});
|
|
21
37
|
return {
|
|
22
38
|
rangePosition,
|
|
23
|
-
onRangePositionChange: handleRangePositionChange
|
|
39
|
+
onRangePositionChange: handleRangePositionChange,
|
|
40
|
+
singleInputFieldRef
|
|
24
41
|
};
|
|
25
42
|
};
|
|
26
43
|
exports.useRangePosition = useRangePosition;
|
|
@@ -57,4 +57,15 @@ Object.keys(_fields).forEach(function (key) {
|
|
|
57
57
|
return _fields[key];
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
|
+
});
|
|
61
|
+
var _rangePickerProps = require("./rangePickerProps");
|
|
62
|
+
Object.keys(_rangePickerProps).forEach(function (key) {
|
|
63
|
+
if (key === "default" || key === "__esModule") return;
|
|
64
|
+
if (key in exports && exports[key] === _rangePickerProps[key]) return;
|
|
65
|
+
Object.defineProperty(exports, key, {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
get: function () {
|
|
68
|
+
return _rangePickerProps[key];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
60
71
|
});
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.getReleaseInfo = void 0;
|
|
7
7
|
var _utils = require("@mui/utils");
|
|
8
8
|
const getReleaseInfo = () => {
|
|
9
|
-
const releaseInfo = "
|
|
9
|
+
const releaseInfo = "MTY4MDEyNzIwMDAwMA==";
|
|
10
10
|
if (process.env.NODE_ENV !== 'production') {
|
|
11
11
|
// A simple hack to set the value in the test environment (has no build step).
|
|
12
12
|
// eslint-disable-next-line no-useless-concat
|
|
@@ -32,17 +32,17 @@ const rangeFieldValueManager = {
|
|
|
32
32
|
}
|
|
33
33
|
return [prevReferenceValue[1], value[1]];
|
|
34
34
|
},
|
|
35
|
-
getSectionsFromValue: (utils,
|
|
36
|
-
const
|
|
35
|
+
getSectionsFromValue: (utils, [start, end], fallbackSections, isRTL, getSectionsFromDate) => {
|
|
36
|
+
const separatedFallbackSections = fallbackSections == null ? {
|
|
37
37
|
startDate: null,
|
|
38
38
|
endDate: null
|
|
39
|
-
} : (0, _dateFieldsUtils.splitDateRangeSections)(
|
|
40
|
-
const getSections = (newDate,
|
|
41
|
-
const shouldReUsePrevDateSections = !utils.isValid(newDate) && !!
|
|
39
|
+
} : (0, _dateFieldsUtils.splitDateRangeSections)(fallbackSections);
|
|
40
|
+
const getSections = (newDate, fallbackDateSections, position) => {
|
|
41
|
+
const shouldReUsePrevDateSections = !utils.isValid(newDate) && !!fallbackDateSections;
|
|
42
42
|
if (shouldReUsePrevDateSections) {
|
|
43
|
-
return
|
|
43
|
+
return fallbackDateSections;
|
|
44
44
|
}
|
|
45
|
-
const sections = (
|
|
45
|
+
const sections = getSectionsFromDate(newDate);
|
|
46
46
|
return sections.map((section, sectionIndex) => {
|
|
47
47
|
if (sectionIndex === sections.length - 1 && position === 'start') {
|
|
48
48
|
return (0, _extends2.default)({}, section, {
|
|
@@ -55,16 +55,11 @@ const rangeFieldValueManager = {
|
|
|
55
55
|
});
|
|
56
56
|
});
|
|
57
57
|
};
|
|
58
|
-
return (0, _internals.addPositionPropertiesToSections)([...getSections(start,
|
|
58
|
+
return (0, _internals.addPositionPropertiesToSections)([...getSections(start, separatedFallbackSections.startDate, 'start'), ...getSections(end, separatedFallbackSections.endDate, 'end')], isRTL);
|
|
59
59
|
},
|
|
60
|
-
getValueStrFromSections: sections => {
|
|
60
|
+
getValueStrFromSections: (sections, isRTL) => {
|
|
61
61
|
const dateRangeSections = (0, _dateFieldsUtils.splitDateRangeSections)(sections);
|
|
62
|
-
return (0, _internals.createDateStrForInputFromSections)([...dateRangeSections.startDate, ...dateRangeSections.endDate]);
|
|
63
|
-
},
|
|
64
|
-
getActiveDateSections: (sections, activeSection) => {
|
|
65
|
-
const index = activeSection.dateName === 'start' ? 0 : 1;
|
|
66
|
-
const dateRangeSections = (0, _dateFieldsUtils.splitDateRangeSections)(sections);
|
|
67
|
-
return index === 0 ? (0, _dateFieldsUtils.removeLastSeparator)(dateRangeSections.startDate) : dateRangeSections.endDate;
|
|
62
|
+
return (0, _internals.createDateStrForInputFromSections)([...dateRangeSections.startDate, ...dateRangeSections.endDate], isRTL);
|
|
68
63
|
},
|
|
69
64
|
parseValueStr: (valueStr, referenceValue, parseDate) => {
|
|
70
65
|
// TODO: Improve because it would not work if the date format has `–` as a separator.
|
|
@@ -80,9 +75,16 @@ const rangeFieldValueManager = {
|
|
|
80
75
|
const index = activeSection.dateName === 'start' ? 0 : 1;
|
|
81
76
|
const updateDateInRange = (newDate, prevDateRange) => index === 0 ? [newDate, prevDateRange[1]] : [prevDateRange[0], newDate];
|
|
82
77
|
return {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
78
|
+
date: state.value[index],
|
|
79
|
+
referenceDate: state.referenceValue[index],
|
|
80
|
+
getSections: sections => {
|
|
81
|
+
const dateRangeSections = (0, _dateFieldsUtils.splitDateRangeSections)(sections);
|
|
82
|
+
if (index === 0) {
|
|
83
|
+
return (0, _dateFieldsUtils.removeLastSeparator)(dateRangeSections.startDate);
|
|
84
|
+
}
|
|
85
|
+
return dateRangeSections.endDate;
|
|
86
|
+
},
|
|
87
|
+
getNewValuesFromNewActiveDate: newActiveDate => ({
|
|
86
88
|
value: updateDateInRange(newActiveDate, state.value),
|
|
87
89
|
referenceValue: newActiveDate == null || !utils.isValid(newActiveDate) ? state.referenceValue : updateDateInRange(newActiveDate, state.referenceValue)
|
|
88
90
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-date-pickers-pro",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.4",
|
|
4
4
|
"description": "The commercial edition of the date picker components (MUI X).",
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"main": "./node/index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@date-io/luxon": "^2.16.1",
|
|
37
37
|
"@date-io/moment": "^2.16.1",
|
|
38
38
|
"@mui/utils": "^5.11.13",
|
|
39
|
-
"@mui/x-date-pickers": "6.0.
|
|
39
|
+
"@mui/x-date-pickers": "6.0.4",
|
|
40
40
|
"@mui/x-license-pro": "6.0.3",
|
|
41
41
|
"clsx": "^1.2.1",
|
|
42
42
|
"prop-types": "^15.8.1",
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { PickersInputLocaleText } from '@mui/x-date-pickers';
|
|
2
|
-
import { DateOrTimeView, UsePickerResponse, WrapperVariant } from '@mui/x-date-pickers/internals';
|
|
3
|
-
import { DateRange, MultiInputFieldSlotRootProps, MultiInputFieldSlotTextFieldProps, RangeFieldSection, RangePosition } from '../models';
|
|
4
|
-
interface UseRangePickerFieldParams<TDate, TView extends DateOrTimeView> extends Pick<UsePickerResponse<DateRange<TDate>, TView, RangeFieldSection, any>, 'open' | 'actions'> {
|
|
5
|
-
wrapperVariant: WrapperVariant;
|
|
6
|
-
readOnly?: boolean;
|
|
7
|
-
disabled?: boolean;
|
|
8
|
-
disableOpenPicker?: boolean;
|
|
9
|
-
onBlur?: () => void;
|
|
10
|
-
rangePosition: RangePosition;
|
|
11
|
-
onRangePositionChange: (newPosition: RangePosition) => void;
|
|
12
|
-
localeText: PickersInputLocaleText<TDate> | undefined;
|
|
13
|
-
}
|
|
14
|
-
export declare const useRangePickerInputProps: <TDate, TView extends DateOrTimeView>({ wrapperVariant, open, actions, readOnly, disabled, disableOpenPicker, onBlur, rangePosition, onRangePositionChange, localeText: inLocaleText, }: UseRangePickerFieldParams<TDate, TView>) => {
|
|
15
|
-
startInput: MultiInputFieldSlotTextFieldProps;
|
|
16
|
-
endInput: MultiInputFieldSlotTextFieldProps;
|
|
17
|
-
root: MultiInputFieldSlotRootProps;
|
|
18
|
-
};
|
|
19
|
-
export {};
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { onSpaceOrEnter, useLocaleText } from '@mui/x-date-pickers/internals';
|
|
4
|
-
export const useRangePickerInputProps = ({
|
|
5
|
-
wrapperVariant,
|
|
6
|
-
open,
|
|
7
|
-
actions,
|
|
8
|
-
readOnly,
|
|
9
|
-
disabled,
|
|
10
|
-
disableOpenPicker,
|
|
11
|
-
onBlur,
|
|
12
|
-
rangePosition,
|
|
13
|
-
onRangePositionChange,
|
|
14
|
-
localeText: inLocaleText
|
|
15
|
-
}) => {
|
|
16
|
-
var _inLocaleText$start, _inLocaleText$end;
|
|
17
|
-
const localeText = useLocaleText();
|
|
18
|
-
const startRef = React.useRef(null);
|
|
19
|
-
const endRef = React.useRef(null);
|
|
20
|
-
React.useEffect(() => {
|
|
21
|
-
if (!open) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
if (rangePosition === 'start') {
|
|
25
|
-
var _startRef$current;
|
|
26
|
-
(_startRef$current = startRef.current) == null ? void 0 : _startRef$current.focus();
|
|
27
|
-
} else if (rangePosition === 'end') {
|
|
28
|
-
var _endRef$current;
|
|
29
|
-
(_endRef$current = endRef.current) == null ? void 0 : _endRef$current.focus();
|
|
30
|
-
}
|
|
31
|
-
}, [rangePosition, open]);
|
|
32
|
-
const openRangeStartSelection = event => {
|
|
33
|
-
event.stopPropagation();
|
|
34
|
-
onRangePositionChange('start');
|
|
35
|
-
if (!readOnly && !disableOpenPicker) {
|
|
36
|
-
actions.onOpen();
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
const openRangeEndSelection = event => {
|
|
40
|
-
event.stopPropagation();
|
|
41
|
-
onRangePositionChange('end');
|
|
42
|
-
if (!readOnly && !disableOpenPicker) {
|
|
43
|
-
actions.onOpen();
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
const focusOnRangeStart = () => {
|
|
47
|
-
if (open) {
|
|
48
|
-
onRangePositionChange('start');
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
const focusOnRangeEnd = () => {
|
|
52
|
-
if (open) {
|
|
53
|
-
onRangePositionChange('end');
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
const readOnlyInput = readOnly != null ? readOnly : wrapperVariant === 'mobile';
|
|
57
|
-
const startInputProps = _extends({
|
|
58
|
-
inputRef: startRef,
|
|
59
|
-
label: (_inLocaleText$start = inLocaleText == null ? void 0 : inLocaleText.start) != null ? _inLocaleText$start : localeText.start,
|
|
60
|
-
onKeyDown: onSpaceOrEnter(openRangeStartSelection),
|
|
61
|
-
onFocus: focusOnRangeStart,
|
|
62
|
-
focused: open ? rangePosition === 'start' : undefined
|
|
63
|
-
}, !readOnly && !disabled && {
|
|
64
|
-
onClick: openRangeStartSelection
|
|
65
|
-
}, {
|
|
66
|
-
readOnly: readOnlyInput,
|
|
67
|
-
disabled
|
|
68
|
-
});
|
|
69
|
-
const endInputProps = _extends({
|
|
70
|
-
inputRef: endRef,
|
|
71
|
-
label: (_inLocaleText$end = inLocaleText == null ? void 0 : inLocaleText.end) != null ? _inLocaleText$end : localeText.end,
|
|
72
|
-
onKeyDown: onSpaceOrEnter(openRangeEndSelection),
|
|
73
|
-
onFocus: focusOnRangeEnd,
|
|
74
|
-
focused: open ? rangePosition === 'end' : undefined
|
|
75
|
-
}, !readOnly && !disabled && {
|
|
76
|
-
onClick: openRangeEndSelection
|
|
77
|
-
}, {
|
|
78
|
-
readOnly: readOnlyInput,
|
|
79
|
-
disabled
|
|
80
|
-
});
|
|
81
|
-
const rootProps = {
|
|
82
|
-
onBlur
|
|
83
|
-
};
|
|
84
|
-
return {
|
|
85
|
-
startInput: startInputProps,
|
|
86
|
-
endInput: endInputProps,
|
|
87
|
-
root: rootProps
|
|
88
|
-
};
|
|
89
|
-
};
|