@react-stately/datepicker 3.0.0-alpha.1 → 3.0.0-alpha.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/dist/main.js +718 -816
- package/dist/main.js.map +1 -1
- package/dist/module.js +701 -780
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +159 -33
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/index.ts +1 -1
- package/src/{useDatePickerFieldState.ts → useDateFieldState.ts} +86 -18
- package/src/useDatePickerState.ts +48 -13
- package/src/useDateRangePickerState.ts +61 -17
- package/src/useTimeFieldState.ts +15 -8
package/dist/module.js
CHANGED
|
@@ -1,837 +1,758 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import { DateFormatter, toCalendarDateTime, toDateFields, now, Time, toCalendar, toCalendarDate, getMinimumDayInMonth, getMinimumMonthInYear, GregorianCalendar, getLocalTimeZone, today, toTime } from "@internationalized/date";
|
|
1
|
+
import {toCalendarDate as $7UzoM$toCalendarDate, toCalendarDateTime as $7UzoM$toCalendarDateTime, DateFormatter as $7UzoM$DateFormatter, Time as $7UzoM$Time, toCalendar as $7UzoM$toCalendar, now as $7UzoM$now, GregorianCalendar as $7UzoM$GregorianCalendar, getMinimumMonthInYear as $7UzoM$getMinimumMonthInYear, getMinimumDayInMonth as $7UzoM$getMinimumDayInMonth, toTime as $7UzoM$toTime, today as $7UzoM$today, getLocalTimeZone as $7UzoM$getLocalTimeZone} from "@internationalized/date";
|
|
2
|
+
import {useControlledState as $7UzoM$useControlledState} from "@react-stately/utils";
|
|
3
|
+
import {useState as $7UzoM$useState, useRef as $7UzoM$useRef, useMemo as $7UzoM$useMemo, useEffect as $7UzoM$useEffect} from "react";
|
|
5
4
|
|
|
6
|
-
function $
|
|
7
|
-
|
|
5
|
+
function $parcel$export(e, n, v, s) {
|
|
6
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
8
7
|
}
|
|
8
|
+
var $ab5bf3f618090389$exports = {};
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
year: 'numeric',
|
|
12
|
-
month: 'numeric',
|
|
13
|
-
day: 'numeric',
|
|
14
|
-
hour: 'numeric',
|
|
15
|
-
minute: '2-digit',
|
|
16
|
-
second: '2-digit'
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
function $d98d1ab08708c80c4fc9e163fea8b89e$export$getFormatOptions(fieldOptions, options) {
|
|
20
|
-
var _options$maxGranulari;
|
|
21
|
-
|
|
22
|
-
fieldOptions = _babelRuntimeHelpersEsmExtends({}, $d98d1ab08708c80c4fc9e163fea8b89e$var$DEFAULT_FIELD_OPTIONS, fieldOptions);
|
|
23
|
-
let granularity = options.granularity || 'minute';
|
|
24
|
-
let keys = Object.keys(fieldOptions);
|
|
25
|
-
let startIdx = keys.indexOf((_options$maxGranulari = options.maxGranularity) != null ? _options$maxGranulari : 'year');
|
|
26
|
-
|
|
27
|
-
if (startIdx < 0) {
|
|
28
|
-
startIdx = 0;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
let endIdx = keys.indexOf(granularity);
|
|
32
|
-
|
|
33
|
-
if (endIdx < 0) {
|
|
34
|
-
endIdx = 2;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (startIdx > endIdx) {
|
|
38
|
-
throw new Error('maxGranularity must be greater than granularity');
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
let opts = keys.slice(startIdx, endIdx + 1).reduce((opts, key) => {
|
|
42
|
-
opts[key] = fieldOptions[key];
|
|
43
|
-
return opts;
|
|
44
|
-
}, {});
|
|
45
|
-
|
|
46
|
-
if (options.hourCycle != null) {
|
|
47
|
-
opts.hour12 = options.hourCycle === 12;
|
|
48
|
-
}
|
|
10
|
+
$parcel$export($ab5bf3f618090389$exports, "useDatePickerState", () => $ab5bf3f618090389$export$87194bb378cc3ac2);
|
|
49
11
|
|
|
50
|
-
opts.timeZone = options.timeZone || 'UTC';
|
|
51
|
-
let hasTime = granularity === 'hour' || granularity === 'minute' || granularity === 'second';
|
|
52
12
|
|
|
53
|
-
if (hasTime && options.timeZone && !options.hideTimeZone) {
|
|
54
|
-
opts.timeZoneName = 'short';
|
|
55
|
-
}
|
|
56
13
|
|
|
57
|
-
|
|
14
|
+
function $35a22f14a1f04b11$export$eac50920cf2fd59a(value, minValue, maxValue) {
|
|
15
|
+
return value != null && (minValue != null && value.compare(minValue) < 0 || maxValue != null && value.compare(maxValue) > 0);
|
|
58
16
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
17
|
+
const $35a22f14a1f04b11$var$DEFAULT_FIELD_OPTIONS = {
|
|
18
|
+
year: 'numeric',
|
|
19
|
+
month: 'numeric',
|
|
20
|
+
day: 'numeric',
|
|
21
|
+
hour: 'numeric',
|
|
22
|
+
minute: '2-digit',
|
|
23
|
+
second: '2-digit'
|
|
24
|
+
};
|
|
25
|
+
function $35a22f14a1f04b11$export$7e319ea407e63bc0(fieldOptions, options) {
|
|
26
|
+
fieldOptions = {
|
|
27
|
+
...$35a22f14a1f04b11$var$DEFAULT_FIELD_OPTIONS,
|
|
28
|
+
...fieldOptions
|
|
29
|
+
};
|
|
30
|
+
let granularity = options.granularity || 'minute';
|
|
31
|
+
let keys = Object.keys(fieldOptions);
|
|
32
|
+
var _maxGranularity;
|
|
33
|
+
let startIdx = keys.indexOf((_maxGranularity = options.maxGranularity) !== null && _maxGranularity !== void 0 ? _maxGranularity : 'year');
|
|
34
|
+
if (startIdx < 0) startIdx = 0;
|
|
35
|
+
let endIdx = keys.indexOf(granularity);
|
|
36
|
+
if (endIdx < 0) endIdx = 2;
|
|
37
|
+
if (startIdx > endIdx) throw new Error('maxGranularity must be greater than granularity');
|
|
38
|
+
let opts1 = keys.slice(startIdx, endIdx + 1).reduce((opts, key)=>{
|
|
39
|
+
opts[key] = fieldOptions[key];
|
|
40
|
+
return opts;
|
|
41
|
+
}, {
|
|
42
|
+
});
|
|
43
|
+
if (options.hourCycle != null) opts1.hour12 = options.hourCycle === 12;
|
|
44
|
+
opts1.timeZone = options.timeZone || 'UTC';
|
|
45
|
+
let hasTime = granularity === 'hour' || granularity === 'minute' || granularity === 'second';
|
|
46
|
+
if (hasTime && options.timeZone && !options.hideTimeZone) opts1.timeZoneName = 'short';
|
|
47
|
+
return opts1;
|
|
66
48
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (!value) {
|
|
74
|
-
return undefined;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return toCalendar(value, calendar);
|
|
49
|
+
function $35a22f14a1f04b11$export$c5221a78ef73c5e9(placeholderValue) {
|
|
50
|
+
if (placeholderValue && 'hour' in placeholderValue) return placeholderValue;
|
|
51
|
+
return new $7UzoM$Time();
|
|
78
52
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
return $
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
let date = toCalendar(now(timeZone).set({
|
|
86
|
-
hour: 0,
|
|
87
|
-
minute: 0,
|
|
88
|
-
second: 0,
|
|
89
|
-
millisecond: 0
|
|
90
|
-
}), calendar);
|
|
91
|
-
|
|
92
|
-
if (granularity === 'year' || granularity === 'month' || granularity === 'day') {
|
|
93
|
-
return toCalendarDate(date);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
if (!timeZone) {
|
|
97
|
-
return toCalendarDateTime(date);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return date;
|
|
53
|
+
function $35a22f14a1f04b11$export$61a490a80c552550(value, calendar) {
|
|
54
|
+
if (value === null) return null;
|
|
55
|
+
if (!value) return undefined;
|
|
56
|
+
return $7UzoM$toCalendar(value, calendar);
|
|
101
57
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
granularity = granularity || (v && 'minute' in v ? 'minute' : 'day'); // props.granularity must actually exist in the value if one is provided.
|
|
114
|
-
|
|
115
|
-
if (v && !(granularity in v)) {
|
|
116
|
-
throw new Error('Invalid granularity ' + granularity + ' for value ' + v.toString());
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return [granularity, defaultTimeZone];
|
|
58
|
+
function $35a22f14a1f04b11$export$66aa2b09de4b1ea5(placeholderValue, granularity, calendar, timeZone) {
|
|
59
|
+
if (placeholderValue) return $35a22f14a1f04b11$export$61a490a80c552550(placeholderValue, calendar);
|
|
60
|
+
let date = $7UzoM$toCalendar($7UzoM$now(timeZone).set({
|
|
61
|
+
hour: 0,
|
|
62
|
+
minute: 0,
|
|
63
|
+
second: 0,
|
|
64
|
+
millisecond: 0
|
|
65
|
+
}), calendar);
|
|
66
|
+
if (granularity === 'year' || granularity === 'month' || granularity === 'day') return $7UzoM$toCalendarDate(date);
|
|
67
|
+
if (!timeZone) return $7UzoM$toCalendarDateTime(date);
|
|
68
|
+
return date;
|
|
120
69
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (value) {
|
|
133
|
-
selectedDate = value;
|
|
134
|
-
|
|
135
|
-
if ('hour' in value) {
|
|
136
|
-
selectedTime = value;
|
|
137
|
-
}
|
|
138
|
-
} // props.granularity must actually exist in the value if one is provided.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (v && !(granularity in v)) {
|
|
142
|
-
throw new Error('Invalid granularity ' + granularity + ' for value ' + v.toString());
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
let commitValue = (date, time) => {
|
|
146
|
-
setValue('timeZone' in time ? time.set(toDateFields(date)) : toCalendarDateTime(date, time));
|
|
147
|
-
}; // Intercept setValue to make sure the Time section is not changed by date selection in Calendar
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
let selectDate = newValue => {
|
|
151
|
-
if (hasTime) {
|
|
152
|
-
if (selectedTime) {
|
|
153
|
-
commitValue(newValue, selectedTime);
|
|
154
|
-
} else {
|
|
155
|
-
setSelectedDate(newValue);
|
|
156
|
-
}
|
|
157
|
-
} else {
|
|
158
|
-
setValue(newValue);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (!hasTime) {
|
|
162
|
-
setOpen(false);
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
let selectTime = newValue => {
|
|
167
|
-
if (selectedDate) {
|
|
168
|
-
commitValue(selectedDate, newValue);
|
|
169
|
-
} else {
|
|
170
|
-
setSelectedTime(newValue);
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
let validationState = props.validationState || ($d98d1ab08708c80c4fc9e163fea8b89e$export$isInvalid(value, props.minValue, props.maxValue) ? 'invalid' : null);
|
|
175
|
-
return {
|
|
176
|
-
value,
|
|
177
|
-
setValue,
|
|
178
|
-
dateValue: selectedDate,
|
|
179
|
-
timeValue: selectedTime,
|
|
180
|
-
setDateValue: selectDate,
|
|
181
|
-
setTimeValue: selectTime,
|
|
182
|
-
granularity,
|
|
183
|
-
isOpen,
|
|
184
|
-
|
|
185
|
-
setOpen(isOpen) {
|
|
186
|
-
// Commit the selected date when the calendar is closed. Use a placeholder time if one wasn't set.
|
|
187
|
-
// If only the time was set and not the date, don't commit. The state will be preserved until
|
|
188
|
-
// the user opens the popover again.
|
|
189
|
-
if (!isOpen && !value && selectedDate && hasTime) {
|
|
190
|
-
commitValue(selectedDate, selectedTime || $d98d1ab08708c80c4fc9e163fea8b89e$export$getPlaceholderTime(props.placeholderValue));
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
setOpen(isOpen);
|
|
194
|
-
},
|
|
195
|
-
|
|
196
|
-
validationState,
|
|
197
|
-
|
|
198
|
-
formatValue(locale, fieldOptions) {
|
|
199
|
-
if (!dateValue) {
|
|
200
|
-
return '';
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
let formatOptions = $d98d1ab08708c80c4fc9e163fea8b89e$export$getFormatOptions(fieldOptions, {
|
|
70
|
+
function $35a22f14a1f04b11$export$2440da353cedad43(v, granularity) {
|
|
71
|
+
// Compute default granularity and time zone from the value. If the value becomes null, keep the last values.
|
|
72
|
+
let lastValue = $7UzoM$useRef(v);
|
|
73
|
+
if (v) lastValue.current = v;
|
|
74
|
+
v = lastValue.current;
|
|
75
|
+
let defaultTimeZone = v && 'timeZone' in v ? v.timeZone : undefined;
|
|
76
|
+
granularity = granularity || (v && 'minute' in v ? 'minute' : 'day');
|
|
77
|
+
// props.granularity must actually exist in the value if one is provided.
|
|
78
|
+
if (v && !(granularity in v)) throw new Error('Invalid granularity ' + granularity + ' for value ' + v.toString());
|
|
79
|
+
return [
|
|
204
80
|
granularity,
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
hourCycle: props.hourCycle
|
|
208
|
-
});
|
|
209
|
-
let formatter = new DateFormatter(locale, formatOptions);
|
|
210
|
-
return formatter.format(dateValue);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
};
|
|
81
|
+
defaultTimeZone
|
|
82
|
+
];
|
|
214
83
|
}
|
|
215
|
-
const $cadbb83c92e54ed3477855c493450ee4$var$EDITABLE_SEGMENTS = {
|
|
216
|
-
year: true,
|
|
217
|
-
month: true,
|
|
218
|
-
day: true,
|
|
219
|
-
hour: true,
|
|
220
|
-
minute: true,
|
|
221
|
-
second: true,
|
|
222
|
-
dayPeriod: true,
|
|
223
|
-
era: true
|
|
224
|
-
};
|
|
225
|
-
const $cadbb83c92e54ed3477855c493450ee4$var$PAGE_STEP = {
|
|
226
|
-
year: 5,
|
|
227
|
-
month: 2,
|
|
228
|
-
day: 7,
|
|
229
|
-
hour: 2,
|
|
230
|
-
minute: 15,
|
|
231
|
-
second: 15
|
|
232
|
-
}; // Node seems to convert everything to lowercase...
|
|
233
|
-
|
|
234
|
-
const $cadbb83c92e54ed3477855c493450ee4$var$TYPE_MAPPING = {
|
|
235
|
-
dayperiod: 'dayPeriod'
|
|
236
|
-
};
|
|
237
|
-
export function useDatePickerFieldState(props) {
|
|
238
|
-
let {
|
|
239
|
-
locale,
|
|
240
|
-
createCalendar,
|
|
241
|
-
hideTimeZone
|
|
242
|
-
} = props;
|
|
243
|
-
let v = props.value || props.defaultValue || props.placeholderValue;
|
|
244
|
-
let [granularity, defaultTimeZone] = $d98d1ab08708c80c4fc9e163fea8b89e$export$useDefaultProps(v, props.granularity);
|
|
245
|
-
let timeZone = defaultTimeZone || 'UTC'; // props.granularity must actually exist in the value if one is provided.
|
|
246
|
-
|
|
247
|
-
if (v && !(granularity in v)) {
|
|
248
|
-
throw new Error('Invalid granularity ' + granularity + ' for value ' + v.toString());
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
let formatOpts = useMemo(() => {
|
|
252
|
-
var _props$maxGranularity;
|
|
253
84
|
|
|
254
|
-
return {
|
|
255
|
-
granularity,
|
|
256
|
-
maxGranularity: (_props$maxGranularity = props.maxGranularity) != null ? _props$maxGranularity : 'year',
|
|
257
|
-
timeZone: defaultTimeZone,
|
|
258
|
-
hideTimeZone,
|
|
259
|
-
hourCycle: props.hourCycle
|
|
260
|
-
};
|
|
261
|
-
}, [props.maxGranularity, granularity, props.hourCycle, defaultTimeZone, hideTimeZone]);
|
|
262
|
-
let opts = useMemo(() => $d98d1ab08708c80c4fc9e163fea8b89e$export$getFormatOptions({}, formatOpts), [formatOpts]);
|
|
263
|
-
let dateFormatter = useMemo(() => new DateFormatter(locale, opts), [locale, opts]);
|
|
264
|
-
let resolvedOptions = useMemo(() => dateFormatter.resolvedOptions(), [dateFormatter]);
|
|
265
|
-
let calendar = useMemo(() => createCalendar(resolvedOptions.calendar), [createCalendar, resolvedOptions.calendar]); // Determine how many editable segments there are for validation purposes.
|
|
266
|
-
// The result is cached for performance.
|
|
267
|
-
|
|
268
|
-
let allSegments = useMemo(() => dateFormatter.formatToParts(new Date()).filter(seg => $cadbb83c92e54ed3477855c493450ee4$var$EDITABLE_SEGMENTS[seg.type]).reduce((p, seg) => (p[seg.type] = true, p), {}), [dateFormatter]);
|
|
269
|
-
let [validSegments, setValidSegments] = useState(() => props.value || props.defaultValue ? _babelRuntimeHelpersEsmExtends({}, allSegments) : {}); // We keep track of the placeholder date separately in state so that onChange is not called
|
|
270
|
-
// until all segments are set. If the value === null (not undefined), then assume the component
|
|
271
|
-
// is controlled, so use the placeholder as the value until all segments are entered so it doesn't
|
|
272
|
-
// change from uncontrolled to controlled and emit a warning.
|
|
273
|
-
|
|
274
|
-
let [placeholderDate, setPlaceholderDate] = useState(() => $d98d1ab08708c80c4fc9e163fea8b89e$export$createPlaceholderDate(props.placeholderValue, granularity, calendar, defaultTimeZone)); // Reset placeholder when calendar changes
|
|
275
|
-
|
|
276
|
-
let lastCalendarIdentifier = useRef(calendar.identifier);
|
|
277
|
-
useEffect(() => {
|
|
278
|
-
if (calendar.identifier !== lastCalendarIdentifier.current) {
|
|
279
|
-
lastCalendarIdentifier.current = calendar.identifier;
|
|
280
|
-
setPlaceholderDate(placeholder => Object.keys(validSegments).length > 0 ? toCalendar(placeholder, calendar) : $d98d1ab08708c80c4fc9e163fea8b89e$export$createPlaceholderDate(props.placeholderValue, granularity, calendar, defaultTimeZone));
|
|
281
|
-
}
|
|
282
|
-
}, [calendar, granularity, validSegments, defaultTimeZone, props.placeholderValue]);
|
|
283
|
-
let [value, setDate] = useControlledState(props.value, props.defaultValue, props.onChange);
|
|
284
|
-
let calendarValue = useMemo(() => $d98d1ab08708c80c4fc9e163fea8b89e$export$convertValue(value, calendar), [value, calendar]); // If there is a value prop, and some segments were previously placeholders, mark them all as valid.
|
|
285
|
-
|
|
286
|
-
if (value && Object.keys(validSegments).length < Object.keys(allSegments).length) {
|
|
287
|
-
validSegments = _babelRuntimeHelpersEsmExtends({}, allSegments);
|
|
288
|
-
setValidSegments(validSegments);
|
|
289
|
-
} // If the value is set to null and all segments are valid, reset the placeholder.
|
|
290
85
|
|
|
291
86
|
|
|
292
|
-
if (value == null && Object.keys(validSegments).length === Object.keys(allSegments).length) {
|
|
293
|
-
validSegments = {};
|
|
294
|
-
setValidSegments(validSegments);
|
|
295
|
-
setPlaceholderDate($d98d1ab08708c80c4fc9e163fea8b89e$export$createPlaceholderDate(props.placeholderValue, granularity, calendar, defaultTimeZone));
|
|
296
|
-
} // If all segments are valid, use the date from state, otherwise use the placeholder date.
|
|
297
87
|
|
|
298
88
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
89
|
+
function $ab5bf3f618090389$export$87194bb378cc3ac2(props) {
|
|
90
|
+
var ref;
|
|
91
|
+
let [isOpen1, setOpen] = $7UzoM$useState(false);
|
|
92
|
+
let [value, setValue] = $7UzoM$useControlledState(props.value, props.defaultValue || null, props.onChange);
|
|
93
|
+
let v = value || props.placeholderValue;
|
|
94
|
+
let [granularity, defaultTimeZone] = $35a22f14a1f04b11$export$2440da353cedad43(v, props.granularity);
|
|
95
|
+
let dateValue = value != null ? value.toDate(defaultTimeZone !== null && defaultTimeZone !== void 0 ? defaultTimeZone : 'UTC') : null;
|
|
96
|
+
let hasTime = granularity === 'hour' || granularity === 'minute' || granularity === 'second' || granularity === 'millisecond';
|
|
97
|
+
var _shouldCloseOnSelect;
|
|
98
|
+
let shouldCloseOnSelect = (_shouldCloseOnSelect = props.shouldCloseOnSelect) !== null && _shouldCloseOnSelect !== void 0 ? _shouldCloseOnSelect : true;
|
|
99
|
+
let [selectedDate, setSelectedDate] = $7UzoM$useState(null);
|
|
100
|
+
let [selectedTime, setSelectedTime] = $7UzoM$useState(null);
|
|
101
|
+
if (value) {
|
|
102
|
+
selectedDate = value;
|
|
103
|
+
if ('hour' in value) selectedTime = value;
|
|
304
104
|
}
|
|
105
|
+
// props.granularity must actually exist in the value if one is provided.
|
|
106
|
+
if (v && !(granularity in v)) throw new Error('Invalid granularity ' + granularity + ' for value ' + v.toString());
|
|
107
|
+
let commitValue = (date, time)=>{
|
|
108
|
+
setValue('timeZone' in time ? time.set($7UzoM$toCalendarDate(date)) : $7UzoM$toCalendarDateTime(date, time));
|
|
109
|
+
};
|
|
110
|
+
// Intercept setValue to make sure the Time section is not changed by date selection in Calendar
|
|
111
|
+
let selectDate = (newValue)=>{
|
|
112
|
+
let shouldClose = typeof shouldCloseOnSelect === 'function' ? shouldCloseOnSelect() : shouldCloseOnSelect;
|
|
113
|
+
if (hasTime) {
|
|
114
|
+
if (selectedTime || shouldClose) commitValue(newValue, selectedTime || $35a22f14a1f04b11$export$c5221a78ef73c5e9(props.placeholderValue));
|
|
115
|
+
else setSelectedDate(newValue);
|
|
116
|
+
} else setValue(newValue);
|
|
117
|
+
if (shouldClose) setOpen(false);
|
|
118
|
+
};
|
|
119
|
+
let selectTime = (newValue)=>{
|
|
120
|
+
if (selectedDate) commitValue(selectedDate, newValue);
|
|
121
|
+
else setSelectedTime(newValue);
|
|
122
|
+
};
|
|
123
|
+
let validationState = props.validationState || ($35a22f14a1f04b11$export$eac50920cf2fd59a(value, props.minValue, props.maxValue) ? 'invalid' : null) || (value && ((ref = props.isDateUnavailable) === null || ref === void 0 ? void 0 : ref.call(props, value)) ? 'invalid' : null);
|
|
124
|
+
return {
|
|
125
|
+
value: value,
|
|
126
|
+
setValue: setValue,
|
|
127
|
+
dateValue: selectedDate,
|
|
128
|
+
timeValue: selectedTime,
|
|
129
|
+
setDateValue: selectDate,
|
|
130
|
+
setTimeValue: selectTime,
|
|
131
|
+
granularity: granularity,
|
|
132
|
+
hasTime: hasTime,
|
|
133
|
+
isOpen: isOpen1,
|
|
134
|
+
setOpen (isOpen) {
|
|
135
|
+
// Commit the selected date when the calendar is closed. Use a placeholder time if one wasn't set.
|
|
136
|
+
// If only the time was set and not the date, don't commit. The state will be preserved until
|
|
137
|
+
// the user opens the popover again.
|
|
138
|
+
if (!isOpen && !value && selectedDate && hasTime) commitValue(selectedDate, selectedTime || $35a22f14a1f04b11$export$c5221a78ef73c5e9(props.placeholderValue));
|
|
139
|
+
setOpen(isOpen);
|
|
140
|
+
},
|
|
141
|
+
validationState: validationState,
|
|
142
|
+
formatValue (locale, fieldOptions) {
|
|
143
|
+
if (!dateValue) return '';
|
|
144
|
+
let formatOptions = $35a22f14a1f04b11$export$7e319ea407e63bc0(fieldOptions, {
|
|
145
|
+
granularity: granularity,
|
|
146
|
+
timeZone: defaultTimeZone,
|
|
147
|
+
hideTimeZone: props.hideTimeZone,
|
|
148
|
+
hourCycle: props.hourCycle
|
|
149
|
+
});
|
|
150
|
+
let formatter = new $7UzoM$DateFormatter(locale, formatOptions);
|
|
151
|
+
return formatter.format(dateValue);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
}
|
|
305
155
|
|
|
306
|
-
if (Object.keys(validSegments).length >= Object.keys(allSegments).length) {
|
|
307
|
-
// The display calendar should not have any effect on the emitted value.
|
|
308
|
-
// Emit dates in the same calendar as the original value, if any, otherwise gregorian.
|
|
309
|
-
newValue = toCalendar(newValue, (v == null ? void 0 : v.calendar) || new GregorianCalendar());
|
|
310
|
-
setDate(newValue);
|
|
311
|
-
} else {
|
|
312
|
-
setPlaceholderDate(newValue);
|
|
313
|
-
}
|
|
314
|
-
};
|
|
315
156
|
|
|
316
|
-
|
|
317
|
-
let segments = useMemo(() => dateFormatter.formatToParts(dateValue).map(segment => {
|
|
318
|
-
let isEditable = $cadbb83c92e54ed3477855c493450ee4$var$EDITABLE_SEGMENTS[segment.type];
|
|
157
|
+
var $3c0fc76039f1c516$exports = {};
|
|
319
158
|
|
|
320
|
-
|
|
321
|
-
isEditable = false;
|
|
322
|
-
}
|
|
159
|
+
$parcel$export($3c0fc76039f1c516$exports, "useDateFieldState", () => $3c0fc76039f1c516$export$60e84778edff6d26);
|
|
323
160
|
|
|
324
|
-
return _babelRuntimeHelpersEsmExtends({
|
|
325
|
-
type: $cadbb83c92e54ed3477855c493450ee4$var$TYPE_MAPPING[segment.type] || segment.type,
|
|
326
|
-
text: segment.value
|
|
327
|
-
}, $cadbb83c92e54ed3477855c493450ee4$var$getSegmentLimits(displayValue, segment.type, resolvedOptions), {
|
|
328
|
-
isPlaceholder: $cadbb83c92e54ed3477855c493450ee4$var$EDITABLE_SEGMENTS[segment.type] && !validSegments[segment.type],
|
|
329
|
-
isEditable
|
|
330
|
-
});
|
|
331
|
-
}), [dateValue, validSegments, dateFormatter, resolvedOptions, displayValue, calendar]);
|
|
332
|
-
let hasEra = useMemo(() => segments.some(s => s.type === 'era'), [segments]);
|
|
333
161
|
|
|
334
|
-
let markValid = part => {
|
|
335
|
-
validSegments[part] = true;
|
|
336
162
|
|
|
337
|
-
if (part === 'year' && hasEra) {
|
|
338
|
-
validSegments.era = true;
|
|
339
|
-
}
|
|
340
163
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
164
|
+
const $3c0fc76039f1c516$var$EDITABLE_SEGMENTS = {
|
|
165
|
+
year: true,
|
|
166
|
+
month: true,
|
|
167
|
+
day: true,
|
|
168
|
+
hour: true,
|
|
169
|
+
minute: true,
|
|
170
|
+
second: true,
|
|
171
|
+
dayPeriod: true,
|
|
172
|
+
era: true
|
|
173
|
+
};
|
|
174
|
+
const $3c0fc76039f1c516$var$PAGE_STEP = {
|
|
175
|
+
year: 5,
|
|
176
|
+
month: 2,
|
|
177
|
+
day: 7,
|
|
178
|
+
hour: 2,
|
|
179
|
+
minute: 15,
|
|
180
|
+
second: 15
|
|
181
|
+
};
|
|
182
|
+
// Node seems to convert everything to lowercase...
|
|
183
|
+
const $3c0fc76039f1c516$var$TYPE_MAPPING = {
|
|
184
|
+
dayperiod: 'dayPeriod'
|
|
185
|
+
};
|
|
186
|
+
function $3c0fc76039f1c516$export$60e84778edff6d26(props) {
|
|
187
|
+
let { locale: locale , createCalendar: createCalendar , hideTimeZone: hideTimeZone , isDisabled: isDisabled , isReadOnly: isReadOnly , isRequired: isRequired } = props;
|
|
188
|
+
let v1 = props.value || props.defaultValue || props.placeholderValue;
|
|
189
|
+
let [granularity, defaultTimeZone] = $35a22f14a1f04b11$export$2440da353cedad43(v1, props.granularity);
|
|
190
|
+
let timeZone = defaultTimeZone || 'UTC';
|
|
191
|
+
// props.granularity must actually exist in the value if one is provided.
|
|
192
|
+
if (v1 && !(granularity in v1)) throw new Error('Invalid granularity ' + granularity + ' for value ' + v1.toString());
|
|
193
|
+
var _maxGranularity;
|
|
194
|
+
let formatOpts = $7UzoM$useMemo(()=>({
|
|
195
|
+
granularity: granularity,
|
|
196
|
+
maxGranularity: (_maxGranularity = props.maxGranularity) !== null && _maxGranularity !== void 0 ? _maxGranularity : 'year',
|
|
197
|
+
timeZone: defaultTimeZone,
|
|
198
|
+
hideTimeZone: hideTimeZone,
|
|
199
|
+
hourCycle: props.hourCycle
|
|
200
|
+
})
|
|
201
|
+
, [
|
|
202
|
+
props.maxGranularity,
|
|
203
|
+
granularity,
|
|
204
|
+
props.hourCycle,
|
|
205
|
+
defaultTimeZone,
|
|
206
|
+
hideTimeZone
|
|
207
|
+
]);
|
|
208
|
+
let opts = $7UzoM$useMemo(()=>$35a22f14a1f04b11$export$7e319ea407e63bc0({
|
|
209
|
+
}, formatOpts)
|
|
210
|
+
, [
|
|
211
|
+
formatOpts
|
|
212
|
+
]);
|
|
213
|
+
let dateFormatter = $7UzoM$useMemo(()=>new $7UzoM$DateFormatter(locale, opts)
|
|
214
|
+
, [
|
|
215
|
+
locale,
|
|
216
|
+
opts
|
|
217
|
+
]);
|
|
218
|
+
let resolvedOptions = $7UzoM$useMemo(()=>dateFormatter.resolvedOptions()
|
|
219
|
+
, [
|
|
220
|
+
dateFormatter
|
|
221
|
+
]);
|
|
222
|
+
let calendar = $7UzoM$useMemo(()=>createCalendar(resolvedOptions.calendar)
|
|
223
|
+
, [
|
|
224
|
+
createCalendar,
|
|
225
|
+
resolvedOptions.calendar
|
|
226
|
+
]);
|
|
227
|
+
// Determine how many editable segments there are for validation purposes.
|
|
228
|
+
// The result is cached for performance.
|
|
229
|
+
let allSegments = $7UzoM$useMemo(()=>dateFormatter.formatToParts(new Date()).filter((seg)=>$3c0fc76039f1c516$var$EDITABLE_SEGMENTS[seg.type]
|
|
230
|
+
).reduce((p, seg)=>(p[seg.type] = true, p)
|
|
231
|
+
, {
|
|
232
|
+
})
|
|
233
|
+
, [
|
|
234
|
+
dateFormatter
|
|
235
|
+
]);
|
|
236
|
+
let [validSegments, setValidSegments] = $7UzoM$useState(()=>props.value || props.defaultValue ? {
|
|
237
|
+
...allSegments
|
|
238
|
+
} : {
|
|
393
239
|
}
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
let shouldBePM = placeholder.hour >= 12;
|
|
409
|
-
|
|
410
|
-
if (isPM && !shouldBePM) {
|
|
411
|
-
value = displayValue.set({
|
|
412
|
-
hour: displayValue.hour - 12
|
|
413
|
-
});
|
|
414
|
-
} else if (!isPM && shouldBePM) {
|
|
415
|
-
value = displayValue.set({
|
|
416
|
-
hour: displayValue.hour + 12
|
|
417
|
-
});
|
|
240
|
+
);
|
|
241
|
+
// We keep track of the placeholder date separately in state so that onChange is not called
|
|
242
|
+
// until all segments are set. If the value === null (not undefined), then assume the component
|
|
243
|
+
// is controlled, so use the placeholder as the value until all segments are entered so it doesn't
|
|
244
|
+
// change from uncontrolled to controlled and emit a warning.
|
|
245
|
+
let [placeholderDate, setPlaceholderDate] = $7UzoM$useState(()=>$35a22f14a1f04b11$export$66aa2b09de4b1ea5(props.placeholderValue, granularity, calendar, defaultTimeZone)
|
|
246
|
+
);
|
|
247
|
+
// Reset placeholder when calendar changes
|
|
248
|
+
let lastCalendarIdentifier = $7UzoM$useRef(calendar.identifier);
|
|
249
|
+
$7UzoM$useEffect(()=>{
|
|
250
|
+
if (calendar.identifier !== lastCalendarIdentifier.current) {
|
|
251
|
+
lastCalendarIdentifier.current = calendar.identifier;
|
|
252
|
+
setPlaceholderDate((placeholder)=>Object.keys(validSegments).length > 0 ? $7UzoM$toCalendar(placeholder, calendar) : $35a22f14a1f04b11$export$66aa2b09de4b1ea5(props.placeholderValue, granularity, calendar, defaultTimeZone)
|
|
253
|
+
);
|
|
418
254
|
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
function $cadbb83c92e54ed3477855c493450ee4$var$getSegmentLimits(date, type, options) {
|
|
437
|
-
switch (type) {
|
|
438
|
-
case 'era':
|
|
439
|
-
{
|
|
440
|
-
let eras = date.calendar.getEras();
|
|
441
|
-
return {
|
|
442
|
-
value: eras.indexOf(date.era),
|
|
443
|
-
minValue: 0,
|
|
444
|
-
maxValue: eras.length - 1
|
|
255
|
+
}, [
|
|
256
|
+
calendar,
|
|
257
|
+
granularity,
|
|
258
|
+
validSegments,
|
|
259
|
+
defaultTimeZone,
|
|
260
|
+
props.placeholderValue
|
|
261
|
+
]);
|
|
262
|
+
let [value1, setDate] = $7UzoM$useControlledState(props.value, props.defaultValue, props.onChange);
|
|
263
|
+
let calendarValue = $7UzoM$useMemo(()=>$35a22f14a1f04b11$export$61a490a80c552550(value1, calendar)
|
|
264
|
+
, [
|
|
265
|
+
value1,
|
|
266
|
+
calendar
|
|
267
|
+
]);
|
|
268
|
+
// If there is a value prop, and some segments were previously placeholders, mark them all as valid.
|
|
269
|
+
if (value1 && Object.keys(validSegments).length < Object.keys(allSegments).length) {
|
|
270
|
+
validSegments = {
|
|
271
|
+
...allSegments
|
|
445
272
|
};
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
minValue: 1,
|
|
452
|
-
maxValue: date.calendar.getYearsInEra(date)
|
|
453
|
-
};
|
|
454
|
-
|
|
455
|
-
case 'month':
|
|
456
|
-
return {
|
|
457
|
-
value: date.month,
|
|
458
|
-
minValue: getMinimumMonthInYear(date),
|
|
459
|
-
maxValue: date.calendar.getMonthsInYear(date)
|
|
460
|
-
};
|
|
461
|
-
|
|
462
|
-
case 'day':
|
|
463
|
-
return {
|
|
464
|
-
value: date.day,
|
|
465
|
-
minValue: getMinimumDayInMonth(date),
|
|
466
|
-
maxValue: date.calendar.getDaysInMonth(date)
|
|
467
|
-
};
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
if ('hour' in date) {
|
|
471
|
-
switch (type) {
|
|
472
|
-
case 'dayPeriod':
|
|
473
|
-
return {
|
|
474
|
-
value: date.hour >= 12 ? 12 : 0,
|
|
475
|
-
minValue: 0,
|
|
476
|
-
maxValue: 12
|
|
273
|
+
setValidSegments(validSegments);
|
|
274
|
+
}
|
|
275
|
+
// If the value is set to null and all segments are valid, reset the placeholder.
|
|
276
|
+
if (value1 == null && Object.keys(validSegments).length === Object.keys(allSegments).length) {
|
|
277
|
+
validSegments = {
|
|
477
278
|
};
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
279
|
+
setValidSegments(validSegments);
|
|
280
|
+
setPlaceholderDate($35a22f14a1f04b11$export$66aa2b09de4b1ea5(props.placeholderValue, granularity, calendar, defaultTimeZone));
|
|
281
|
+
}
|
|
282
|
+
// If all segments are valid, use the date from state, otherwise use the placeholder date.
|
|
283
|
+
let displayValue = calendarValue && Object.keys(validSegments).length >= Object.keys(allSegments).length ? calendarValue : placeholderDate;
|
|
284
|
+
let setValue = (newValue)=>{
|
|
285
|
+
if (props.isDisabled || props.isReadOnly) return;
|
|
286
|
+
if (Object.keys(validSegments).length >= Object.keys(allSegments).length) {
|
|
287
|
+
// The display calendar should not have any effect on the emitted value.
|
|
288
|
+
// Emit dates in the same calendar as the original value, if any, otherwise gregorian.
|
|
289
|
+
newValue = $7UzoM$toCalendar(newValue, (v1 === null || v1 === void 0 ? void 0 : v1.calendar) || new $7UzoM$GregorianCalendar());
|
|
290
|
+
setDate(newValue);
|
|
291
|
+
} else setPlaceholderDate(newValue);
|
|
292
|
+
};
|
|
293
|
+
let dateValue = $7UzoM$useMemo(()=>displayValue.toDate(timeZone)
|
|
294
|
+
, [
|
|
295
|
+
displayValue,
|
|
296
|
+
timeZone
|
|
297
|
+
]);
|
|
298
|
+
let segments = $7UzoM$useMemo(()=>dateFormatter.formatToParts(dateValue).map((segment)=>{
|
|
299
|
+
let isEditable = $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[segment.type];
|
|
300
|
+
if (segment.type === 'era' && calendar.getEras().length === 1) isEditable = false;
|
|
301
|
+
return {
|
|
302
|
+
type: $3c0fc76039f1c516$var$TYPE_MAPPING[segment.type] || segment.type,
|
|
303
|
+
text: segment.value,
|
|
304
|
+
...$3c0fc76039f1c516$var$getSegmentLimits(displayValue, segment.type, resolvedOptions),
|
|
305
|
+
isPlaceholder: $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[segment.type] && !validSegments[segment.type],
|
|
306
|
+
isEditable: isEditable
|
|
307
|
+
};
|
|
308
|
+
})
|
|
309
|
+
, [
|
|
310
|
+
dateValue,
|
|
311
|
+
validSegments,
|
|
312
|
+
dateFormatter,
|
|
313
|
+
resolvedOptions,
|
|
314
|
+
displayValue,
|
|
315
|
+
calendar
|
|
316
|
+
]);
|
|
317
|
+
let hasEra = $7UzoM$useMemo(()=>segments.some((s)=>s.type === 'era'
|
|
318
|
+
)
|
|
319
|
+
, [
|
|
320
|
+
segments
|
|
321
|
+
]);
|
|
322
|
+
let markValid = (part)=>{
|
|
323
|
+
validSegments[part] = true;
|
|
324
|
+
if (part === 'year' && hasEra) validSegments.era = true;
|
|
325
|
+
setValidSegments({
|
|
326
|
+
...validSegments
|
|
327
|
+
});
|
|
328
|
+
};
|
|
329
|
+
let adjustSegment = (type, amount)=>{
|
|
330
|
+
markValid(type);
|
|
331
|
+
setValue($3c0fc76039f1c516$var$addSegment(displayValue, type, amount, resolvedOptions));
|
|
332
|
+
};
|
|
333
|
+
let validationState = props.validationState || ($35a22f14a1f04b11$export$eac50920cf2fd59a(calendarValue, props.minValue, props.maxValue) ? 'invalid' : null);
|
|
334
|
+
return {
|
|
335
|
+
value: calendarValue,
|
|
336
|
+
dateValue: dateValue,
|
|
337
|
+
setValue: setValue,
|
|
338
|
+
segments: segments,
|
|
339
|
+
dateFormatter: dateFormatter,
|
|
340
|
+
validationState: validationState,
|
|
341
|
+
granularity: granularity,
|
|
342
|
+
isDisabled: isDisabled,
|
|
343
|
+
isReadOnly: isReadOnly,
|
|
344
|
+
isRequired: isRequired,
|
|
345
|
+
increment (part) {
|
|
346
|
+
adjustSegment(part, 1);
|
|
347
|
+
},
|
|
348
|
+
decrement (part) {
|
|
349
|
+
adjustSegment(part, -1);
|
|
350
|
+
},
|
|
351
|
+
incrementPage (part) {
|
|
352
|
+
adjustSegment(part, $3c0fc76039f1c516$var$PAGE_STEP[part] || 1);
|
|
353
|
+
},
|
|
354
|
+
decrementPage (part) {
|
|
355
|
+
adjustSegment(part, -($3c0fc76039f1c516$var$PAGE_STEP[part] || 1));
|
|
356
|
+
},
|
|
357
|
+
setSegment (part, v) {
|
|
358
|
+
markValid(part);
|
|
359
|
+
setValue($3c0fc76039f1c516$var$setSegment(displayValue, part, v, resolvedOptions));
|
|
360
|
+
},
|
|
361
|
+
confirmPlaceholder (part) {
|
|
362
|
+
if (props.isDisabled || props.isReadOnly) return;
|
|
363
|
+
if (!part) {
|
|
364
|
+
// Confirm the rest of the placeholder if any of the segments are valid.
|
|
365
|
+
let numValid = Object.keys(validSegments).length;
|
|
366
|
+
if (numValid > 0 && numValid < Object.keys(allSegments).length) {
|
|
367
|
+
validSegments = {
|
|
368
|
+
...allSegments
|
|
369
|
+
};
|
|
370
|
+
setValidSegments(validSegments);
|
|
371
|
+
setValue(displayValue.copy());
|
|
372
|
+
}
|
|
373
|
+
} else if (!validSegments[part]) {
|
|
374
|
+
markValid(part);
|
|
375
|
+
setValue(displayValue.copy());
|
|
376
|
+
}
|
|
377
|
+
},
|
|
378
|
+
clearSegment (part) {
|
|
379
|
+
delete validSegments[part];
|
|
380
|
+
setValidSegments({
|
|
381
|
+
...validSegments
|
|
382
|
+
});
|
|
383
|
+
let placeholder = $35a22f14a1f04b11$export$66aa2b09de4b1ea5(props.placeholderValue, granularity, calendar, defaultTimeZone);
|
|
384
|
+
let value = displayValue;
|
|
385
|
+
// Reset day period to default without changing the hour.
|
|
386
|
+
if (part === 'dayPeriod' && 'hour' in displayValue && 'hour' in placeholder) {
|
|
387
|
+
let isPM = displayValue.hour >= 12;
|
|
388
|
+
let shouldBePM = placeholder.hour >= 12;
|
|
389
|
+
if (isPM && !shouldBePM) value = displayValue.set({
|
|
390
|
+
hour: displayValue.hour - 12
|
|
391
|
+
});
|
|
392
|
+
else if (!isPM && shouldBePM) value = displayValue.set({
|
|
393
|
+
hour: displayValue.hour + 12
|
|
394
|
+
});
|
|
395
|
+
} else if (part in displayValue) value = displayValue.set({
|
|
396
|
+
[part]: placeholder[part]
|
|
397
|
+
});
|
|
398
|
+
setDate(null);
|
|
399
|
+
setValue(value);
|
|
400
|
+
},
|
|
401
|
+
formatValue (fieldOptions) {
|
|
402
|
+
if (!calendarValue) return '';
|
|
403
|
+
let formatOptions = $35a22f14a1f04b11$export$7e319ea407e63bc0(fieldOptions, formatOpts);
|
|
404
|
+
let formatter = new $7UzoM$DateFormatter(locale, formatOptions);
|
|
405
|
+
return formatter.format(dateValue);
|
|
487
406
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
function $3c0fc76039f1c516$var$getSegmentLimits(date, type, options) {
|
|
410
|
+
switch(type){
|
|
411
|
+
case 'era':
|
|
412
|
+
{
|
|
413
|
+
let eras = date.calendar.getEras();
|
|
414
|
+
return {
|
|
415
|
+
value: eras.indexOf(date.era),
|
|
416
|
+
minValue: 0,
|
|
417
|
+
maxValue: eras.length - 1
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
case 'year':
|
|
421
|
+
return {
|
|
422
|
+
value: date.year,
|
|
423
|
+
minValue: 1,
|
|
424
|
+
maxValue: date.calendar.getYearsInEra(date)
|
|
425
|
+
};
|
|
426
|
+
case 'month':
|
|
427
|
+
return {
|
|
428
|
+
value: date.month,
|
|
429
|
+
minValue: $7UzoM$getMinimumMonthInYear(date),
|
|
430
|
+
maxValue: date.calendar.getMonthsInYear(date)
|
|
431
|
+
};
|
|
432
|
+
case 'day':
|
|
433
|
+
return {
|
|
434
|
+
value: date.day,
|
|
435
|
+
minValue: $7UzoM$getMinimumDayInMonth(date),
|
|
436
|
+
maxValue: date.calendar.getDaysInMonth(date)
|
|
437
|
+
};
|
|
508
438
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
439
|
+
if ('hour' in date) switch(type){
|
|
440
|
+
case 'dayPeriod':
|
|
441
|
+
return {
|
|
442
|
+
value: date.hour >= 12 ? 12 : 0,
|
|
443
|
+
minValue: 0,
|
|
444
|
+
maxValue: 12
|
|
445
|
+
};
|
|
446
|
+
case 'hour':
|
|
447
|
+
if (options.hour12) {
|
|
448
|
+
let isPM = date.hour >= 12;
|
|
449
|
+
return {
|
|
450
|
+
value: date.hour,
|
|
451
|
+
minValue: isPM ? 12 : 0,
|
|
452
|
+
maxValue: isPM ? 23 : 11
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
return {
|
|
456
|
+
value: date.hour,
|
|
457
|
+
minValue: 0,
|
|
458
|
+
maxValue: 23
|
|
459
|
+
};
|
|
460
|
+
case 'minute':
|
|
461
|
+
return {
|
|
462
|
+
value: date.minute,
|
|
463
|
+
minValue: 0,
|
|
464
|
+
maxValue: 59
|
|
465
|
+
};
|
|
466
|
+
case 'second':
|
|
467
|
+
return {
|
|
468
|
+
value: date.second,
|
|
469
|
+
minValue: 0,
|
|
470
|
+
maxValue: 59
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
return {
|
|
474
|
+
};
|
|
512
475
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
return value.cycle(part, amount, {
|
|
540
|
-
round: part !== 'hour',
|
|
541
|
-
hourCycle: options.hour12 ? 12 : 24
|
|
542
|
-
});
|
|
476
|
+
function $3c0fc76039f1c516$var$addSegment(value, part, amount, options) {
|
|
477
|
+
switch(part){
|
|
478
|
+
case 'era':
|
|
479
|
+
case 'year':
|
|
480
|
+
case 'month':
|
|
481
|
+
case 'day':
|
|
482
|
+
return value.cycle(part, amount, {
|
|
483
|
+
round: part === 'year'
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
if ('hour' in value) switch(part){
|
|
487
|
+
case 'dayPeriod':
|
|
488
|
+
{
|
|
489
|
+
let hours = value.hour;
|
|
490
|
+
let isPM = hours >= 12;
|
|
491
|
+
return value.set({
|
|
492
|
+
hour: isPM ? hours - 12 : hours + 12
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
case 'hour':
|
|
496
|
+
case 'minute':
|
|
497
|
+
case 'second':
|
|
498
|
+
return value.cycle(part, amount, {
|
|
499
|
+
round: part !== 'hour',
|
|
500
|
+
hourCycle: options.hour12 ? 12 : 24
|
|
501
|
+
});
|
|
543
502
|
}
|
|
544
|
-
}
|
|
545
503
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
if (!wasPM && segmentValue === 12) {
|
|
581
|
-
segmentValue = 0;
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
if (wasPM && segmentValue < 12) {
|
|
585
|
-
segmentValue += 12;
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
// fallthrough
|
|
590
|
-
|
|
591
|
-
case 'minute':
|
|
592
|
-
case 'second':
|
|
593
|
-
return value.set({
|
|
594
|
-
[part]: segmentValue
|
|
595
|
-
});
|
|
504
|
+
function $3c0fc76039f1c516$var$setSegment(value, part, segmentValue, options) {
|
|
505
|
+
switch(part){
|
|
506
|
+
case 'day':
|
|
507
|
+
case 'month':
|
|
508
|
+
case 'year':
|
|
509
|
+
return value.set({
|
|
510
|
+
[part]: segmentValue
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
if ('hour' in value) switch(part){
|
|
514
|
+
case 'dayPeriod':
|
|
515
|
+
{
|
|
516
|
+
let hours = value.hour;
|
|
517
|
+
let wasPM = hours >= 12;
|
|
518
|
+
let isPM = segmentValue >= 12;
|
|
519
|
+
if (isPM === wasPM) return value;
|
|
520
|
+
return value.set({
|
|
521
|
+
hour: wasPM ? hours - 12 : hours + 12
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
case 'hour':
|
|
525
|
+
// In 12 hour time, ensure that AM/PM does not change
|
|
526
|
+
if (options.hour12) {
|
|
527
|
+
let hours = value.hour;
|
|
528
|
+
let wasPM = hours >= 12;
|
|
529
|
+
if (!wasPM && segmentValue === 12) segmentValue = 0;
|
|
530
|
+
if (wasPM && segmentValue < 12) segmentValue += 12;
|
|
531
|
+
}
|
|
532
|
+
// fallthrough
|
|
533
|
+
case 'minute':
|
|
534
|
+
case 'second':
|
|
535
|
+
return value.set({
|
|
536
|
+
[part]: segmentValue
|
|
537
|
+
});
|
|
596
538
|
}
|
|
597
|
-
}
|
|
598
539
|
}
|
|
599
540
|
|
|
600
|
-
export function useDateRangePickerState(props) {
|
|
601
|
-
let [isOpen, setOpen] = useState(false);
|
|
602
|
-
let [controlledValue, setControlledValue] = useControlledState(props.value, props.defaultValue || null, props.onChange);
|
|
603
|
-
let [placeholderValue, setPlaceholderValue] = useState(() => controlledValue || {
|
|
604
|
-
start: null,
|
|
605
|
-
end: null
|
|
606
|
-
}); // Reset the placeholder if the value prop is set to null.
|
|
607
|
-
|
|
608
|
-
if (controlledValue == null && placeholderValue.start && placeholderValue.end) {
|
|
609
|
-
placeholderValue = {
|
|
610
|
-
start: null,
|
|
611
|
-
end: null
|
|
612
|
-
};
|
|
613
|
-
setPlaceholderValue(placeholderValue);
|
|
614
|
-
}
|
|
615
541
|
|
|
616
|
-
|
|
617
|
-
let valueRef = useRef(value);
|
|
618
|
-
valueRef.current = value;
|
|
542
|
+
var $93c38a5e28be6249$exports = {};
|
|
619
543
|
|
|
620
|
-
|
|
621
|
-
valueRef.current = value;
|
|
622
|
-
setPlaceholderValue(value);
|
|
544
|
+
$parcel$export($93c38a5e28be6249$exports, "useDateRangePickerState", () => $93c38a5e28be6249$export$e50a61c1de9f574);
|
|
623
545
|
|
|
624
|
-
if (value != null && value.start && value.end) {
|
|
625
|
-
setControlledValue(value);
|
|
626
|
-
} else {
|
|
627
|
-
setControlledValue(null);
|
|
628
|
-
}
|
|
629
|
-
};
|
|
630
|
-
|
|
631
|
-
let v = (value == null ? void 0 : value.start) || (value == null ? void 0 : value.end) || props.placeholderValue;
|
|
632
|
-
let [granularity, defaultTimeZone] = $d98d1ab08708c80c4fc9e163fea8b89e$export$useDefaultProps(v, props.granularity);
|
|
633
|
-
let hasTime = granularity === 'hour' || granularity === 'minute' || granularity === 'second' || granularity === 'millisecond';
|
|
634
|
-
let [dateRange, setSelectedDateRange] = useState(null);
|
|
635
|
-
let [timeRange, setSelectedTimeRange] = useState(null);
|
|
636
546
|
|
|
637
|
-
if (value && value.start && value.end) {
|
|
638
|
-
dateRange = value;
|
|
639
547
|
|
|
640
|
-
if ('hour' in value.start) {
|
|
641
|
-
timeRange = value;
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
548
|
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
if
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
}
|
|
662
|
-
} else if (range.start && range.end) {
|
|
663
|
-
setValue(range);
|
|
664
|
-
} else {
|
|
665
|
-
setSelectedDateRange(range);
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
if (!hasTime) {
|
|
669
|
-
setOpen(false);
|
|
549
|
+
function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
|
|
550
|
+
var ref, ref1;
|
|
551
|
+
let [isOpen1, setOpen] = $7UzoM$useState(false);
|
|
552
|
+
let [controlledValue, setControlledValue] = $7UzoM$useControlledState(props.value, props.defaultValue || null, props.onChange);
|
|
553
|
+
let [placeholderValue, setPlaceholderValue] = $7UzoM$useState(()=>controlledValue || {
|
|
554
|
+
start: null,
|
|
555
|
+
end: null
|
|
556
|
+
}
|
|
557
|
+
);
|
|
558
|
+
// Reset the placeholder if the value prop is set to null.
|
|
559
|
+
if (controlledValue == null && placeholderValue.start && placeholderValue.end) {
|
|
560
|
+
placeholderValue = {
|
|
561
|
+
start: null,
|
|
562
|
+
end: null
|
|
563
|
+
};
|
|
564
|
+
setPlaceholderValue(placeholderValue);
|
|
670
565
|
}
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
566
|
+
let value1 = controlledValue || placeholderValue;
|
|
567
|
+
let valueRef = $7UzoM$useRef(value1);
|
|
568
|
+
valueRef.current = value1;
|
|
569
|
+
let setValue = (value)=>{
|
|
570
|
+
valueRef.current = value;
|
|
571
|
+
setPlaceholderValue(value);
|
|
572
|
+
if ((value === null || value === void 0 ? void 0 : value.start) && value.end) setControlledValue(value);
|
|
573
|
+
else setControlledValue(null);
|
|
574
|
+
};
|
|
575
|
+
let v = (value1 === null || value1 === void 0 ? void 0 : value1.start) || (value1 === null || value1 === void 0 ? void 0 : value1.end) || props.placeholderValue;
|
|
576
|
+
let [granularity, defaultTimeZone] = $35a22f14a1f04b11$export$2440da353cedad43(v, props.granularity);
|
|
577
|
+
let hasTime = granularity === 'hour' || granularity === 'minute' || granularity === 'second' || granularity === 'millisecond';
|
|
578
|
+
var _shouldCloseOnSelect;
|
|
579
|
+
let shouldCloseOnSelect = (_shouldCloseOnSelect = props.shouldCloseOnSelect) !== null && _shouldCloseOnSelect !== void 0 ? _shouldCloseOnSelect : true;
|
|
580
|
+
let [dateRange1, setSelectedDateRange] = $7UzoM$useState(null);
|
|
581
|
+
let [timeRange1, setSelectedTimeRange] = $7UzoM$useState(null);
|
|
582
|
+
if (value1 && value1.start && value1.end) {
|
|
583
|
+
dateRange1 = value1;
|
|
584
|
+
if ('hour' in value1.start) timeRange1 = value1;
|
|
680
585
|
}
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
value,
|
|
686
|
-
setValue,
|
|
687
|
-
dateRange,
|
|
688
|
-
timeRange,
|
|
689
|
-
granularity,
|
|
690
|
-
|
|
691
|
-
setDate(part, date) {
|
|
692
|
-
setDateRange(_babelRuntimeHelpersEsmExtends({}, dateRange, {
|
|
693
|
-
[part]: date
|
|
694
|
-
}));
|
|
695
|
-
},
|
|
696
|
-
|
|
697
|
-
setTime(part, time) {
|
|
698
|
-
setTimeRange(_babelRuntimeHelpersEsmExtends({}, timeRange, {
|
|
699
|
-
[part]: time
|
|
700
|
-
}));
|
|
701
|
-
},
|
|
702
|
-
|
|
703
|
-
setDateTime(part, dateTime) {
|
|
704
|
-
setValue(_babelRuntimeHelpersEsmExtends({}, value, {
|
|
705
|
-
[part]: dateTime
|
|
706
|
-
}));
|
|
707
|
-
},
|
|
708
|
-
|
|
709
|
-
setDateRange,
|
|
710
|
-
setTimeRange,
|
|
711
|
-
isOpen,
|
|
712
|
-
|
|
713
|
-
setOpen(isOpen) {
|
|
714
|
-
var _dateRange3, _dateRange4;
|
|
715
|
-
|
|
716
|
-
// Commit the selected date range when the calendar is closed. Use a placeholder time if one wasn't set.
|
|
717
|
-
// If only the time range was set and not the date range, don't commit. The state will be preserved until
|
|
718
|
-
// the user opens the popover again.
|
|
719
|
-
if (!isOpen && !(value != null && value.start && value != null && value.end) && (_dateRange3 = dateRange) != null && _dateRange3.start && (_dateRange4 = dateRange) != null && _dateRange4.end && hasTime) {
|
|
720
|
-
var _timeRange3, _timeRange4;
|
|
721
|
-
|
|
722
|
-
commitValue(dateRange, {
|
|
723
|
-
start: ((_timeRange3 = timeRange) == null ? void 0 : _timeRange3.start) || $d98d1ab08708c80c4fc9e163fea8b89e$export$getPlaceholderTime(props.placeholderValue),
|
|
724
|
-
end: ((_timeRange4 = timeRange) == null ? void 0 : _timeRange4.end) || $d98d1ab08708c80c4fc9e163fea8b89e$export$getPlaceholderTime(props.placeholderValue)
|
|
586
|
+
let commitValue = (dateRange, timeRange)=>{
|
|
587
|
+
setValue({
|
|
588
|
+
start: 'timeZone' in timeRange.start ? timeRange.start.set($7UzoM$toCalendarDate(dateRange.start)) : $7UzoM$toCalendarDateTime(dateRange.start, timeRange.start),
|
|
589
|
+
end: 'timeZone' in timeRange.end ? timeRange.end.set($7UzoM$toCalendarDate(dateRange.end)) : $7UzoM$toCalendarDateTime(dateRange.end, timeRange.end)
|
|
725
590
|
});
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
}
|
|
591
|
+
};
|
|
592
|
+
// Intercept setValue to make sure the Time section is not changed by date selection in Calendar
|
|
593
|
+
let setDateRange = (range)=>{
|
|
594
|
+
let shouldClose = typeof shouldCloseOnSelect === 'function' ? shouldCloseOnSelect() : shouldCloseOnSelect;
|
|
595
|
+
if (hasTime) {
|
|
596
|
+
if (shouldClose || range.start && range.end && (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.start) && (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.end)) commitValue(range, {
|
|
597
|
+
start: (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.start) || $35a22f14a1f04b11$export$c5221a78ef73c5e9(props.placeholderValue),
|
|
598
|
+
end: (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.end) || $35a22f14a1f04b11$export$c5221a78ef73c5e9(props.placeholderValue)
|
|
599
|
+
});
|
|
600
|
+
else setSelectedDateRange(range);
|
|
601
|
+
} else if (range.start && range.end) setValue(range);
|
|
602
|
+
else setSelectedDateRange(range);
|
|
603
|
+
if (shouldClose) setOpen(false);
|
|
604
|
+
};
|
|
605
|
+
let setTimeRange = (range)=>{
|
|
606
|
+
if ((dateRange1 === null || dateRange1 === void 0 ? void 0 : dateRange1.start) && (dateRange1 === null || dateRange1 === void 0 ? void 0 : dateRange1.end) && range.start && range.end) commitValue(dateRange1, range);
|
|
607
|
+
else setSelectedTimeRange(range);
|
|
608
|
+
};
|
|
609
|
+
let validationState = props.validationState || (value1 != null && ($35a22f14a1f04b11$export$eac50920cf2fd59a(value1.start, props.minValue, props.maxValue) || $35a22f14a1f04b11$export$eac50920cf2fd59a(value1.end, props.minValue, props.maxValue) || value1.end != null && value1.start != null && value1.end.compare(value1.start) < 0 || (value1 === null || value1 === void 0 ? void 0 : value1.start) && ((ref = props.isDateUnavailable) === null || ref === void 0 ? void 0 : ref.call(props, value1.start)) || (value1 === null || value1 === void 0 ? void 0 : value1.end) && ((ref1 = props.isDateUnavailable) === null || ref1 === void 0 ? void 0 : ref1.call(props, value1.end))) ? 'invalid' : null);
|
|
610
|
+
return {
|
|
611
|
+
value: value1,
|
|
612
|
+
setValue: setValue,
|
|
613
|
+
dateRange: dateRange1,
|
|
614
|
+
timeRange: timeRange1,
|
|
615
|
+
granularity: granularity,
|
|
616
|
+
hasTime: hasTime,
|
|
617
|
+
setDate (part, date) {
|
|
618
|
+
setDateRange({
|
|
619
|
+
...dateRange1,
|
|
620
|
+
[part]: date
|
|
621
|
+
});
|
|
622
|
+
},
|
|
623
|
+
setTime (part, time) {
|
|
624
|
+
setTimeRange({
|
|
625
|
+
...timeRange1,
|
|
626
|
+
[part]: time
|
|
627
|
+
});
|
|
628
|
+
},
|
|
629
|
+
setDateTime (part, dateTime) {
|
|
630
|
+
setValue({
|
|
631
|
+
...value1,
|
|
632
|
+
[part]: dateTime
|
|
633
|
+
});
|
|
634
|
+
},
|
|
635
|
+
setDateRange: setDateRange,
|
|
636
|
+
setTimeRange: setTimeRange,
|
|
637
|
+
isOpen: isOpen1,
|
|
638
|
+
setOpen (isOpen) {
|
|
639
|
+
// Commit the selected date range when the calendar is closed. Use a placeholder time if one wasn't set.
|
|
640
|
+
// If only the time range was set and not the date range, don't commit. The state will be preserved until
|
|
641
|
+
// the user opens the popover again.
|
|
642
|
+
if (!isOpen && !((value1 === null || value1 === void 0 ? void 0 : value1.start) && (value1 === null || value1 === void 0 ? void 0 : value1.end)) && (dateRange1 === null || dateRange1 === void 0 ? void 0 : dateRange1.start) && (dateRange1 === null || dateRange1 === void 0 ? void 0 : dateRange1.end) && hasTime) commitValue(dateRange1, {
|
|
643
|
+
start: (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.start) || $35a22f14a1f04b11$export$c5221a78ef73c5e9(props.placeholderValue),
|
|
644
|
+
end: (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.end) || $35a22f14a1f04b11$export$c5221a78ef73c5e9(props.placeholderValue)
|
|
645
|
+
});
|
|
646
|
+
setOpen(isOpen);
|
|
647
|
+
},
|
|
648
|
+
validationState: validationState,
|
|
649
|
+
formatValue (locale, fieldOptions) {
|
|
650
|
+
if (!value1 || !value1.start || !value1.end) return '';
|
|
651
|
+
let startTimeZone = 'timeZone' in value1.start ? value1.start.timeZone : undefined;
|
|
652
|
+
let startGranularity = props.granularity || (value1.start && 'minute' in value1.start ? 'minute' : 'day');
|
|
653
|
+
let endTimeZone = 'timeZone' in value1.end ? value1.end.timeZone : undefined;
|
|
654
|
+
let endGranularity = props.granularity || (value1.end && 'minute' in value1.end ? 'minute' : 'day');
|
|
655
|
+
let startOptions = $35a22f14a1f04b11$export$7e319ea407e63bc0(fieldOptions, {
|
|
656
|
+
granularity: startGranularity,
|
|
657
|
+
timeZone: startTimeZone,
|
|
658
|
+
hideTimeZone: props.hideTimeZone,
|
|
659
|
+
hourCycle: props.hourCycle
|
|
660
|
+
});
|
|
661
|
+
let startFormatter = new $7UzoM$DateFormatter(locale, startOptions);
|
|
662
|
+
let endFormatter;
|
|
663
|
+
if (startTimeZone === endTimeZone && startGranularity === endGranularity) {
|
|
664
|
+
// Use formatRange, as it results in shorter output when some of the fields
|
|
665
|
+
// are shared between the start and end dates (e.g. the same month).
|
|
666
|
+
// Formatting will fail if the end date is before the start date. Fall back below when that happens.
|
|
667
|
+
try {
|
|
668
|
+
return startFormatter.formatRange(value1.start.toDate(startTimeZone), value1.end.toDate(endTimeZone));
|
|
669
|
+
} catch (e) {
|
|
670
|
+
// ignore
|
|
671
|
+
}
|
|
672
|
+
endFormatter = startFormatter;
|
|
673
|
+
} else {
|
|
674
|
+
let endOptions = $35a22f14a1f04b11$export$7e319ea407e63bc0(fieldOptions, {
|
|
675
|
+
granularity: endGranularity,
|
|
676
|
+
timeZone: endTimeZone,
|
|
677
|
+
hideTimeZone: props.hideTimeZone,
|
|
678
|
+
hourCycle: props.hourCycle
|
|
679
|
+
});
|
|
680
|
+
endFormatter = new $7UzoM$DateFormatter(locale, endOptions);
|
|
681
|
+
}
|
|
682
|
+
return `${startFormatter.format(value1.start.toDate(startTimeZone))} – ${endFormatter.format(value1.end.toDate(endTimeZone))}`;
|
|
683
|
+
},
|
|
684
|
+
confirmPlaceholder () {
|
|
685
|
+
// Need to use ref value here because the value can be set in the same tick as
|
|
686
|
+
// a blur, which means the component won't have re-rendered yet.
|
|
687
|
+
let value = valueRef.current;
|
|
688
|
+
if (value && Boolean(value.start) !== Boolean(value.end)) {
|
|
689
|
+
let calendar = (value.start || value.end).calendar;
|
|
690
|
+
let placeholder = $35a22f14a1f04b11$export$66aa2b09de4b1ea5(props.placeholderValue, granularity, calendar, defaultTimeZone);
|
|
691
|
+
setValue({
|
|
692
|
+
start: value.start || placeholder,
|
|
693
|
+
end: value.end || placeholder
|
|
694
|
+
});
|
|
695
|
+
}
|
|
758
696
|
}
|
|
697
|
+
};
|
|
698
|
+
}
|
|
759
699
|
|
|
760
|
-
endFormatter = startFormatter;
|
|
761
|
-
} else {
|
|
762
|
-
let endOptions = $d98d1ab08708c80c4fc9e163fea8b89e$export$getFormatOptions(fieldOptions, {
|
|
763
|
-
granularity: endGranularity,
|
|
764
|
-
timeZone: endTimeZone,
|
|
765
|
-
hideTimeZone: props.hideTimeZone,
|
|
766
|
-
hourCycle: props.hourCycle
|
|
767
|
-
});
|
|
768
|
-
endFormatter = new DateFormatter(locale, endOptions);
|
|
769
|
-
}
|
|
770
|
-
|
|
771
|
-
return startFormatter.format(value.start.toDate(startTimeZone)) + " \u2013 " + endFormatter.format(value.end.toDate(endTimeZone));
|
|
772
|
-
},
|
|
773
|
-
|
|
774
|
-
confirmPlaceholder() {
|
|
775
|
-
// Need to use ref value here because the value can be set in the same tick as
|
|
776
|
-
// a blur, which means the component won't have re-rendered yet.
|
|
777
|
-
let value = valueRef.current;
|
|
778
|
-
|
|
779
|
-
if (value && Boolean(value.start) !== Boolean(value.end)) {
|
|
780
|
-
let calendar = (value.start || value.end).calendar;
|
|
781
|
-
let placeholder = $d98d1ab08708c80c4fc9e163fea8b89e$export$createPlaceholderDate(props.placeholderValue, granularity, calendar, defaultTimeZone);
|
|
782
|
-
setValue({
|
|
783
|
-
start: value.start || placeholder,
|
|
784
|
-
end: value.end || placeholder
|
|
785
|
-
});
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
700
|
|
|
789
|
-
|
|
701
|
+
var $eff5d8ee529ac4bb$exports = {};
|
|
702
|
+
|
|
703
|
+
$parcel$export($eff5d8ee529ac4bb$exports, "useTimeFieldState", () => $eff5d8ee529ac4bb$export$fd53cef0cc796101);
|
|
704
|
+
|
|
705
|
+
|
|
706
|
+
|
|
707
|
+
|
|
708
|
+
function $eff5d8ee529ac4bb$export$fd53cef0cc796101(props) {
|
|
709
|
+
let { placeholderValue: placeholderValue = new $7UzoM$Time() , minValue: minValue , maxValue: maxValue , granularity: granularity } = props;
|
|
710
|
+
let [value, setValue] = $7UzoM$useControlledState(props.value, props.defaultValue, props.onChange);
|
|
711
|
+
let v = value || placeholderValue;
|
|
712
|
+
let day = v && 'day' in v ? v : undefined;
|
|
713
|
+
let placeholderDate = $7UzoM$useMemo(()=>$eff5d8ee529ac4bb$var$convertValue(placeholderValue)
|
|
714
|
+
, [
|
|
715
|
+
placeholderValue
|
|
716
|
+
]);
|
|
717
|
+
let minDate = $7UzoM$useMemo(()=>$eff5d8ee529ac4bb$var$convertValue(minValue, day)
|
|
718
|
+
, [
|
|
719
|
+
minValue,
|
|
720
|
+
day
|
|
721
|
+
]);
|
|
722
|
+
let maxDate = $7UzoM$useMemo(()=>$eff5d8ee529ac4bb$var$convertValue(maxValue, day)
|
|
723
|
+
, [
|
|
724
|
+
maxValue,
|
|
725
|
+
day
|
|
726
|
+
]);
|
|
727
|
+
let dateTime = $7UzoM$useMemo(()=>value == null ? null : $eff5d8ee529ac4bb$var$convertValue(value)
|
|
728
|
+
, [
|
|
729
|
+
value
|
|
730
|
+
]);
|
|
731
|
+
let onChange = (newValue)=>{
|
|
732
|
+
setValue(v && 'day' in v ? newValue : newValue && $7UzoM$toTime(newValue));
|
|
733
|
+
};
|
|
734
|
+
return $3c0fc76039f1c516$export$60e84778edff6d26({
|
|
735
|
+
...props,
|
|
736
|
+
value: dateTime,
|
|
737
|
+
defaultValue: undefined,
|
|
738
|
+
minValue: minDate,
|
|
739
|
+
maxValue: maxDate,
|
|
740
|
+
onChange: onChange,
|
|
741
|
+
granularity: granularity || 'minute',
|
|
742
|
+
maxGranularity: 'hour',
|
|
743
|
+
placeholderValue: placeholderDate,
|
|
744
|
+
// Calendar should not matter for time fields.
|
|
745
|
+
createCalendar: ()=>new $7UzoM$GregorianCalendar()
|
|
746
|
+
});
|
|
790
747
|
}
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
maxValue,
|
|
796
|
-
granularity
|
|
797
|
-
} = props;
|
|
798
|
-
let [value, setValue] = useControlledState(props.value, props.defaultValue, props.onChange);
|
|
799
|
-
let v = value || placeholderValue;
|
|
800
|
-
let day = v && 'day' in v ? v : undefined;
|
|
801
|
-
let placeholderDate = useMemo(() => $fc899fd619e5c84d71eda3c7a349a873$var$convertValue(placeholderValue), [placeholderValue]);
|
|
802
|
-
let minDate = useMemo(() => $fc899fd619e5c84d71eda3c7a349a873$var$convertValue(minValue, day), [minValue, day]);
|
|
803
|
-
let maxDate = useMemo(() => $fc899fd619e5c84d71eda3c7a349a873$var$convertValue(maxValue, day), [maxValue, day]);
|
|
804
|
-
let dateTime = useMemo(() => value == null ? null : $fc899fd619e5c84d71eda3c7a349a873$var$convertValue(value), [value]);
|
|
805
|
-
|
|
806
|
-
let onChange = newValue => {
|
|
807
|
-
setValue(v && 'day' in v ? newValue : newValue && toTime(newValue));
|
|
808
|
-
};
|
|
809
|
-
|
|
810
|
-
return useDatePickerFieldState(_babelRuntimeHelpersEsmExtends({}, props, {
|
|
811
|
-
value: dateTime,
|
|
812
|
-
defaultValue: undefined,
|
|
813
|
-
minValue: minDate,
|
|
814
|
-
maxValue: maxDate,
|
|
815
|
-
onChange,
|
|
816
|
-
granularity: granularity || 'minute',
|
|
817
|
-
maxGranularity: 'hour',
|
|
818
|
-
placeholderValue: placeholderDate
|
|
819
|
-
}));
|
|
748
|
+
function $eff5d8ee529ac4bb$var$convertValue(value, date = $7UzoM$today($7UzoM$getLocalTimeZone())) {
|
|
749
|
+
if (!value) return null;
|
|
750
|
+
if ('day' in value) return value;
|
|
751
|
+
return $7UzoM$toCalendarDateTime(date, value);
|
|
820
752
|
}
|
|
821
753
|
|
|
822
|
-
function $fc899fd619e5c84d71eda3c7a349a873$var$convertValue(value, date) {
|
|
823
|
-
if (date === void 0) {
|
|
824
|
-
date = today(getLocalTimeZone());
|
|
825
|
-
}
|
|
826
754
|
|
|
827
|
-
if (!value) {
|
|
828
|
-
return null;
|
|
829
|
-
}
|
|
830
755
|
|
|
831
|
-
if ('day' in value) {
|
|
832
|
-
return value;
|
|
833
|
-
}
|
|
834
756
|
|
|
835
|
-
|
|
836
|
-
}
|
|
757
|
+
export {$ab5bf3f618090389$export$87194bb378cc3ac2 as useDatePickerState, $3c0fc76039f1c516$export$60e84778edff6d26 as useDateFieldState, $93c38a5e28be6249$export$e50a61c1de9f574 as useDateRangePickerState, $eff5d8ee529ac4bb$export$fd53cef0cc796101 as useTimeFieldState};
|
|
837
758
|
//# sourceMappingURL=module.js.map
|