@react-stately/datepicker 3.0.0-nightly.3175 → 3.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +98 -82
- package/dist/main.js.map +1 -1
- package/dist/module.js +95 -67
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +148 -35
- package/dist/types.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/index.ts +9 -4
- package/src/{useDatePickerFieldState.ts → useDateFieldState.ts} +103 -36
- package/src/useDatePickerState.ts +37 -13
- package/src/useDateRangePickerState.ts +82 -21
- package/src/useTimeFieldState.ts +10 -4
- package/src/utils.ts +6 -1
package/dist/module.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
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
2
|
import {useControlledState as $7UzoM$useControlledState} from "@react-stately/utils";
|
|
3
|
+
import {useOverlayTriggerState as $7UzoM$useOverlayTriggerState} from "@react-stately/overlays";
|
|
3
4
|
import {useState as $7UzoM$useState, useRef as $7UzoM$useRef, useMemo as $7UzoM$useMemo, useEffect as $7UzoM$useEffect} from "react";
|
|
4
5
|
|
|
5
|
-
function $parcel$export(e, n, v, s) {
|
|
6
|
-
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
7
|
-
}
|
|
8
|
-
var $ab5bf3f618090389$exports = {};
|
|
9
|
-
|
|
10
|
-
$parcel$export($ab5bf3f618090389$exports, "useDatePickerState", () => $ab5bf3f618090389$export$87194bb378cc3ac2);
|
|
11
6
|
|
|
12
7
|
|
|
13
8
|
|
|
@@ -44,6 +39,7 @@ function $35a22f14a1f04b11$export$7e319ea407e63bc0(fieldOptions, options) {
|
|
|
44
39
|
opts1.timeZone = options.timeZone || 'UTC';
|
|
45
40
|
let hasTime = granularity === 'hour' || granularity === 'minute' || granularity === 'second';
|
|
46
41
|
if (hasTime && options.timeZone && !options.hideTimeZone) opts1.timeZoneName = 'short';
|
|
42
|
+
if (options.showEra && startIdx === 0) opts1.era = 'short';
|
|
47
43
|
return opts1;
|
|
48
44
|
}
|
|
49
45
|
function $35a22f14a1f04b11$export$c5221a78ef73c5e9(placeholderValue) {
|
|
@@ -86,9 +82,10 @@ function $35a22f14a1f04b11$export$2440da353cedad43(v, granularity) {
|
|
|
86
82
|
|
|
87
83
|
|
|
88
84
|
|
|
85
|
+
|
|
89
86
|
function $ab5bf3f618090389$export$87194bb378cc3ac2(props) {
|
|
90
87
|
var ref;
|
|
91
|
-
let
|
|
88
|
+
let overlayState = $7UzoM$useOverlayTriggerState(props);
|
|
92
89
|
let [value, setValue] = $7UzoM$useControlledState(props.value, props.defaultValue || null, props.onChange);
|
|
93
90
|
let v = value || props.placeholderValue;
|
|
94
91
|
let [granularity, defaultTimeZone] = $35a22f14a1f04b11$export$2440da353cedad43(v, props.granularity);
|
|
@@ -114,7 +111,7 @@ function $ab5bf3f618090389$export$87194bb378cc3ac2(props) {
|
|
|
114
111
|
if (selectedTime || shouldClose) commitValue(newValue, selectedTime || $35a22f14a1f04b11$export$c5221a78ef73c5e9(props.placeholderValue));
|
|
115
112
|
else setSelectedDate(newValue);
|
|
116
113
|
} else setValue(newValue);
|
|
117
|
-
if (shouldClose) setOpen(false);
|
|
114
|
+
if (shouldClose) overlayState.setOpen(false);
|
|
118
115
|
};
|
|
119
116
|
let selectTime = (newValue)=>{
|
|
120
117
|
if (selectedDate) commitValue(selectedDate, newValue);
|
|
@@ -130,13 +127,13 @@ function $ab5bf3f618090389$export$87194bb378cc3ac2(props) {
|
|
|
130
127
|
setTimeValue: selectTime,
|
|
131
128
|
granularity: granularity,
|
|
132
129
|
hasTime: hasTime,
|
|
133
|
-
isOpen:
|
|
130
|
+
isOpen: overlayState.isOpen,
|
|
134
131
|
setOpen (isOpen) {
|
|
135
132
|
// Commit the selected date when the calendar is closed. Use a placeholder time if one wasn't set.
|
|
136
133
|
// If only the time was set and not the date, don't commit. The state will be preserved until
|
|
137
134
|
// the user opens the popover again.
|
|
138
135
|
if (!isOpen && !value && selectedDate && hasTime) commitValue(selectedDate, selectedTime || $35a22f14a1f04b11$export$c5221a78ef73c5e9(props.placeholderValue));
|
|
139
|
-
setOpen(isOpen);
|
|
136
|
+
overlayState.setOpen(isOpen);
|
|
140
137
|
},
|
|
141
138
|
validationState: validationState,
|
|
142
139
|
formatValue (locale, fieldOptions) {
|
|
@@ -145,7 +142,8 @@ function $ab5bf3f618090389$export$87194bb378cc3ac2(props) {
|
|
|
145
142
|
granularity: granularity,
|
|
146
143
|
timeZone: defaultTimeZone,
|
|
147
144
|
hideTimeZone: props.hideTimeZone,
|
|
148
|
-
hourCycle: props.hourCycle
|
|
145
|
+
hourCycle: props.hourCycle,
|
|
146
|
+
showEra: value.calendar.identifier === 'gregory' && value.era === 'BC'
|
|
149
147
|
});
|
|
150
148
|
let formatter = new $7UzoM$DateFormatter(locale, formatOptions);
|
|
151
149
|
return formatter.format(dateValue);
|
|
@@ -154,14 +152,11 @@ function $ab5bf3f618090389$export$87194bb378cc3ac2(props) {
|
|
|
154
152
|
}
|
|
155
153
|
|
|
156
154
|
|
|
157
|
-
var $09e80d602234613d$exports = {};
|
|
158
155
|
|
|
159
|
-
$parcel$export($09e80d602234613d$exports, "useDatePickerFieldState", () => $09e80d602234613d$export$714a241b39a650d6);
|
|
160
156
|
|
|
161
157
|
|
|
162
158
|
|
|
163
|
-
|
|
164
|
-
const $09e80d602234613d$var$EDITABLE_SEGMENTS = {
|
|
159
|
+
const $3c0fc76039f1c516$var$EDITABLE_SEGMENTS = {
|
|
165
160
|
year: true,
|
|
166
161
|
month: true,
|
|
167
162
|
day: true,
|
|
@@ -171,7 +166,7 @@ const $09e80d602234613d$var$EDITABLE_SEGMENTS = {
|
|
|
171
166
|
dayPeriod: true,
|
|
172
167
|
era: true
|
|
173
168
|
};
|
|
174
|
-
const $
|
|
169
|
+
const $3c0fc76039f1c516$var$PAGE_STEP = {
|
|
175
170
|
year: 5,
|
|
176
171
|
month: 2,
|
|
177
172
|
day: 7,
|
|
@@ -180,30 +175,55 @@ const $09e80d602234613d$var$PAGE_STEP = {
|
|
|
180
175
|
second: 15
|
|
181
176
|
};
|
|
182
177
|
// Node seems to convert everything to lowercase...
|
|
183
|
-
const $
|
|
178
|
+
const $3c0fc76039f1c516$var$TYPE_MAPPING = {
|
|
184
179
|
dayperiod: 'dayPeriod'
|
|
185
180
|
};
|
|
186
|
-
function $
|
|
181
|
+
function $3c0fc76039f1c516$export$60e84778edff6d26(props) {
|
|
187
182
|
let { locale: locale , createCalendar: createCalendar , hideTimeZone: hideTimeZone , isDisabled: isDisabled , isReadOnly: isReadOnly , isRequired: isRequired } = props;
|
|
188
183
|
let v1 = props.value || props.defaultValue || props.placeholderValue;
|
|
189
184
|
let [granularity, defaultTimeZone] = $35a22f14a1f04b11$export$2440da353cedad43(v1, props.granularity);
|
|
190
185
|
let timeZone = defaultTimeZone || 'UTC';
|
|
191
186
|
// props.granularity must actually exist in the value if one is provided.
|
|
192
187
|
if (v1 && !(granularity in v1)) throw new Error('Invalid granularity ' + granularity + ' for value ' + v1.toString());
|
|
188
|
+
let defaultFormatter = $7UzoM$useMemo(()=>new $7UzoM$DateFormatter(locale)
|
|
189
|
+
, [
|
|
190
|
+
locale
|
|
191
|
+
]);
|
|
192
|
+
let calendar = $7UzoM$useMemo(()=>createCalendar(defaultFormatter.resolvedOptions().calendar)
|
|
193
|
+
, [
|
|
194
|
+
createCalendar,
|
|
195
|
+
defaultFormatter
|
|
196
|
+
]);
|
|
197
|
+
let [value1, setDate] = $7UzoM$useControlledState(props.value, props.defaultValue, props.onChange);
|
|
198
|
+
let calendarValue = $7UzoM$useMemo(()=>$35a22f14a1f04b11$export$61a490a80c552550(value1, calendar)
|
|
199
|
+
, [
|
|
200
|
+
value1,
|
|
201
|
+
calendar
|
|
202
|
+
]);
|
|
203
|
+
// We keep track of the placeholder date separately in state so that onChange is not called
|
|
204
|
+
// until all segments are set. If the value === null (not undefined), then assume the component
|
|
205
|
+
// is controlled, so use the placeholder as the value until all segments are entered so it doesn't
|
|
206
|
+
// change from uncontrolled to controlled and emit a warning.
|
|
207
|
+
let [placeholderDate, setPlaceholderDate] = $7UzoM$useState(()=>$35a22f14a1f04b11$export$66aa2b09de4b1ea5(props.placeholderValue, granularity, calendar, defaultTimeZone)
|
|
208
|
+
);
|
|
209
|
+
let val = calendarValue || placeholderDate;
|
|
210
|
+
let showEra = calendar.identifier === 'gregory' && val.era === 'BC';
|
|
193
211
|
var _maxGranularity;
|
|
194
212
|
let formatOpts = $7UzoM$useMemo(()=>({
|
|
195
213
|
granularity: granularity,
|
|
196
214
|
maxGranularity: (_maxGranularity = props.maxGranularity) !== null && _maxGranularity !== void 0 ? _maxGranularity : 'year',
|
|
197
215
|
timeZone: defaultTimeZone,
|
|
198
216
|
hideTimeZone: hideTimeZone,
|
|
199
|
-
hourCycle: props.hourCycle
|
|
217
|
+
hourCycle: props.hourCycle,
|
|
218
|
+
showEra: showEra
|
|
200
219
|
})
|
|
201
220
|
, [
|
|
202
221
|
props.maxGranularity,
|
|
203
222
|
granularity,
|
|
204
223
|
props.hourCycle,
|
|
205
224
|
defaultTimeZone,
|
|
206
|
-
hideTimeZone
|
|
225
|
+
hideTimeZone,
|
|
226
|
+
showEra
|
|
207
227
|
]);
|
|
208
228
|
let opts = $7UzoM$useMemo(()=>$35a22f14a1f04b11$export$7e319ea407e63bc0({
|
|
209
229
|
}, formatOpts)
|
|
@@ -219,14 +239,9 @@ function $09e80d602234613d$export$714a241b39a650d6(props) {
|
|
|
219
239
|
, [
|
|
220
240
|
dateFormatter
|
|
221
241
|
]);
|
|
222
|
-
let calendar = $7UzoM$useMemo(()=>createCalendar(resolvedOptions.calendar)
|
|
223
|
-
, [
|
|
224
|
-
createCalendar,
|
|
225
|
-
resolvedOptions.calendar
|
|
226
|
-
]);
|
|
227
242
|
// Determine how many editable segments there are for validation purposes.
|
|
228
243
|
// The result is cached for performance.
|
|
229
|
-
let allSegments = $7UzoM$useMemo(()=>dateFormatter.formatToParts(new Date()).filter((seg)=>$
|
|
244
|
+
let allSegments = $7UzoM$useMemo(()=>dateFormatter.formatToParts(new Date()).filter((seg)=>$3c0fc76039f1c516$var$EDITABLE_SEGMENTS[seg.type]
|
|
230
245
|
).reduce((p, seg)=>(p[seg.type] = true, p)
|
|
231
246
|
, {
|
|
232
247
|
})
|
|
@@ -238,12 +253,6 @@ function $09e80d602234613d$export$714a241b39a650d6(props) {
|
|
|
238
253
|
} : {
|
|
239
254
|
}
|
|
240
255
|
);
|
|
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
256
|
// Reset placeholder when calendar changes
|
|
248
257
|
let lastCalendarIdentifier = $7UzoM$useRef(calendar.identifier);
|
|
249
258
|
$7UzoM$useEffect(()=>{
|
|
@@ -259,12 +268,6 @@ function $09e80d602234613d$export$714a241b39a650d6(props) {
|
|
|
259
268
|
defaultTimeZone,
|
|
260
269
|
props.placeholderValue
|
|
261
270
|
]);
|
|
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
271
|
// If there is a value prop, and some segments were previously placeholders, mark them all as valid.
|
|
269
272
|
if (value1 && Object.keys(validSegments).length < Object.keys(allSegments).length) {
|
|
270
273
|
validSegments = {
|
|
@@ -296,13 +299,13 @@ function $09e80d602234613d$export$714a241b39a650d6(props) {
|
|
|
296
299
|
timeZone
|
|
297
300
|
]);
|
|
298
301
|
let segments = $7UzoM$useMemo(()=>dateFormatter.formatToParts(dateValue).map((segment)=>{
|
|
299
|
-
let isEditable = $
|
|
302
|
+
let isEditable = $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[segment.type];
|
|
300
303
|
if (segment.type === 'era' && calendar.getEras().length === 1) isEditable = false;
|
|
301
304
|
return {
|
|
302
|
-
type: $
|
|
305
|
+
type: $3c0fc76039f1c516$var$TYPE_MAPPING[segment.type] || segment.type,
|
|
303
306
|
text: segment.value,
|
|
304
|
-
...$
|
|
305
|
-
isPlaceholder: $
|
|
307
|
+
...$3c0fc76039f1c516$var$getSegmentLimits(displayValue, segment.type, resolvedOptions),
|
|
308
|
+
isPlaceholder: $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[segment.type] && !validSegments[segment.type],
|
|
306
309
|
isEditable: isEditable
|
|
307
310
|
};
|
|
308
311
|
})
|
|
@@ -328,9 +331,10 @@ function $09e80d602234613d$export$714a241b39a650d6(props) {
|
|
|
328
331
|
};
|
|
329
332
|
let adjustSegment = (type, amount)=>{
|
|
330
333
|
markValid(type);
|
|
331
|
-
setValue($
|
|
334
|
+
setValue($3c0fc76039f1c516$var$addSegment(displayValue, type, amount, resolvedOptions));
|
|
332
335
|
};
|
|
333
336
|
let validationState = props.validationState || ($35a22f14a1f04b11$export$eac50920cf2fd59a(calendarValue, props.minValue, props.maxValue) ? 'invalid' : null);
|
|
337
|
+
var _maxGranularity1;
|
|
334
338
|
return {
|
|
335
339
|
value: calendarValue,
|
|
336
340
|
dateValue: dateValue,
|
|
@@ -339,6 +343,7 @@ function $09e80d602234613d$export$714a241b39a650d6(props) {
|
|
|
339
343
|
dateFormatter: dateFormatter,
|
|
340
344
|
validationState: validationState,
|
|
341
345
|
granularity: granularity,
|
|
346
|
+
maxGranularity: (_maxGranularity1 = props.maxGranularity) !== null && _maxGranularity1 !== void 0 ? _maxGranularity1 : 'year',
|
|
342
347
|
isDisabled: isDisabled,
|
|
343
348
|
isReadOnly: isReadOnly,
|
|
344
349
|
isRequired: isRequired,
|
|
@@ -349,14 +354,14 @@ function $09e80d602234613d$export$714a241b39a650d6(props) {
|
|
|
349
354
|
adjustSegment(part, -1);
|
|
350
355
|
},
|
|
351
356
|
incrementPage (part) {
|
|
352
|
-
adjustSegment(part, $
|
|
357
|
+
adjustSegment(part, $3c0fc76039f1c516$var$PAGE_STEP[part] || 1);
|
|
353
358
|
},
|
|
354
359
|
decrementPage (part) {
|
|
355
|
-
adjustSegment(part, -($
|
|
360
|
+
adjustSegment(part, -($3c0fc76039f1c516$var$PAGE_STEP[part] || 1));
|
|
356
361
|
},
|
|
357
362
|
setSegment (part, v) {
|
|
358
363
|
markValid(part);
|
|
359
|
-
setValue($
|
|
364
|
+
setValue($3c0fc76039f1c516$var$setSegment(displayValue, part, v, resolvedOptions));
|
|
360
365
|
},
|
|
361
366
|
confirmPlaceholder (part) {
|
|
362
367
|
if (props.isDisabled || props.isReadOnly) return;
|
|
@@ -398,12 +403,15 @@ function $09e80d602234613d$export$714a241b39a650d6(props) {
|
|
|
398
403
|
setDate(null);
|
|
399
404
|
setValue(value);
|
|
400
405
|
},
|
|
401
|
-
|
|
402
|
-
|
|
406
|
+
formatValue (fieldOptions) {
|
|
407
|
+
if (!calendarValue) return '';
|
|
408
|
+
let formatOptions = $35a22f14a1f04b11$export$7e319ea407e63bc0(fieldOptions, formatOpts);
|
|
409
|
+
let formatter = new $7UzoM$DateFormatter(locale, formatOptions);
|
|
410
|
+
return formatter.format(dateValue);
|
|
403
411
|
}
|
|
404
412
|
};
|
|
405
413
|
}
|
|
406
|
-
function $
|
|
414
|
+
function $3c0fc76039f1c516$var$getSegmentLimits(date, type, options) {
|
|
407
415
|
switch(type){
|
|
408
416
|
case 'era':
|
|
409
417
|
{
|
|
@@ -470,7 +478,7 @@ function $09e80d602234613d$var$getSegmentLimits(date, type, options) {
|
|
|
470
478
|
return {
|
|
471
479
|
};
|
|
472
480
|
}
|
|
473
|
-
function $
|
|
481
|
+
function $3c0fc76039f1c516$var$addSegment(value, part, amount, options) {
|
|
474
482
|
switch(part){
|
|
475
483
|
case 'era':
|
|
476
484
|
case 'year':
|
|
@@ -498,7 +506,7 @@ function $09e80d602234613d$var$addSegment(value, part, amount, options) {
|
|
|
498
506
|
});
|
|
499
507
|
}
|
|
500
508
|
}
|
|
501
|
-
function $
|
|
509
|
+
function $3c0fc76039f1c516$var$setSegment(value, part, segmentValue, options) {
|
|
502
510
|
switch(part){
|
|
503
511
|
case 'day':
|
|
504
512
|
case 'month':
|
|
@@ -536,16 +544,14 @@ function $09e80d602234613d$var$setSegment(value, part, segmentValue, options) {
|
|
|
536
544
|
}
|
|
537
545
|
|
|
538
546
|
|
|
539
|
-
var $93c38a5e28be6249$exports = {};
|
|
540
547
|
|
|
541
|
-
$parcel$export($93c38a5e28be6249$exports, "useDateRangePickerState", () => $93c38a5e28be6249$export$e50a61c1de9f574);
|
|
542
548
|
|
|
543
549
|
|
|
544
550
|
|
|
545
551
|
|
|
546
552
|
function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
|
|
547
553
|
var ref, ref1;
|
|
548
|
-
let
|
|
554
|
+
let overlayState = $7UzoM$useOverlayTriggerState(props);
|
|
549
555
|
let [controlledValue, setControlledValue] = $7UzoM$useControlledState(props.value, props.defaultValue || null, props.onChange);
|
|
550
556
|
let [placeholderValue, setPlaceholderValue] = $7UzoM$useState(()=>controlledValue || {
|
|
551
557
|
start: null,
|
|
@@ -597,7 +603,7 @@ function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
|
|
|
597
603
|
else setSelectedDateRange(range);
|
|
598
604
|
} else if (range.start && range.end) setValue(range);
|
|
599
605
|
else setSelectedDateRange(range);
|
|
600
|
-
if (shouldClose) setOpen(false);
|
|
606
|
+
if (shouldClose) overlayState.setOpen(false);
|
|
601
607
|
};
|
|
602
608
|
let setTimeRange = (range)=>{
|
|
603
609
|
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);
|
|
@@ -631,7 +637,7 @@ function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
|
|
|
631
637
|
},
|
|
632
638
|
setDateRange: setDateRange,
|
|
633
639
|
setTimeRange: setTimeRange,
|
|
634
|
-
isOpen:
|
|
640
|
+
isOpen: overlayState.isOpen,
|
|
635
641
|
setOpen (isOpen) {
|
|
636
642
|
// Commit the selected date range when the calendar is closed. Use a placeholder time if one wasn't set.
|
|
637
643
|
// If only the time range was set and not the date range, don't commit. The state will be preserved until
|
|
@@ -640,11 +646,11 @@ function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
|
|
|
640
646
|
start: (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.start) || $35a22f14a1f04b11$export$c5221a78ef73c5e9(props.placeholderValue),
|
|
641
647
|
end: (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.end) || $35a22f14a1f04b11$export$c5221a78ef73c5e9(props.placeholderValue)
|
|
642
648
|
});
|
|
643
|
-
setOpen(isOpen);
|
|
649
|
+
overlayState.setOpen(isOpen);
|
|
644
650
|
},
|
|
645
651
|
validationState: validationState,
|
|
646
652
|
formatValue (locale, fieldOptions) {
|
|
647
|
-
if (!value1 || !value1.start || !value1.end) return
|
|
653
|
+
if (!value1 || !value1.start || !value1.end) return null;
|
|
648
654
|
let startTimeZone = 'timeZone' in value1.start ? value1.start.timeZone : undefined;
|
|
649
655
|
let startGranularity = props.granularity || (value1.start && 'minute' in value1.start ? 'minute' : 'day');
|
|
650
656
|
let endTimeZone = 'timeZone' in value1.end ? value1.end.timeZone : undefined;
|
|
@@ -653,16 +659,38 @@ function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
|
|
|
653
659
|
granularity: startGranularity,
|
|
654
660
|
timeZone: startTimeZone,
|
|
655
661
|
hideTimeZone: props.hideTimeZone,
|
|
656
|
-
hourCycle: props.hourCycle
|
|
662
|
+
hourCycle: props.hourCycle,
|
|
663
|
+
showEra: value1.start.calendar.identifier === 'gregory' && value1.start.era === 'BC' || value1.end.calendar.identifier === 'gregory' && value1.end.era === 'BC'
|
|
657
664
|
});
|
|
665
|
+
let startDate = value1.start.toDate(startTimeZone || 'UTC');
|
|
666
|
+
let endDate = value1.end.toDate(endTimeZone || 'UTC');
|
|
658
667
|
let startFormatter = new $7UzoM$DateFormatter(locale, startOptions);
|
|
659
668
|
let endFormatter;
|
|
660
|
-
if (startTimeZone === endTimeZone && startGranularity === endGranularity) {
|
|
669
|
+
if (startTimeZone === endTimeZone && startGranularity === endGranularity && value1.start.compare(value1.end) !== 0) {
|
|
661
670
|
// Use formatRange, as it results in shorter output when some of the fields
|
|
662
671
|
// are shared between the start and end dates (e.g. the same month).
|
|
663
672
|
// Formatting will fail if the end date is before the start date. Fall back below when that happens.
|
|
664
673
|
try {
|
|
665
|
-
|
|
674
|
+
let parts = startFormatter.formatRangeToParts(startDate, endDate);
|
|
675
|
+
// Find the separator between the start and end date. This is determined
|
|
676
|
+
// by finding the last shared literal before the end range.
|
|
677
|
+
let separatorIndex = -1;
|
|
678
|
+
for(let i = 0; i < parts.length; i++){
|
|
679
|
+
let part = parts[i];
|
|
680
|
+
if (part.source === 'shared' && part.type === 'literal') separatorIndex = i;
|
|
681
|
+
else if (part.source === 'endRange') break;
|
|
682
|
+
}
|
|
683
|
+
// Now we can combine the parts into start and end strings.
|
|
684
|
+
let start = '';
|
|
685
|
+
let end = '';
|
|
686
|
+
for(let i1 = 0; i1 < parts.length; i1++){
|
|
687
|
+
if (i1 < separatorIndex) start += parts[i1].value;
|
|
688
|
+
else if (i1 > separatorIndex) end += parts[i1].value;
|
|
689
|
+
}
|
|
690
|
+
return {
|
|
691
|
+
start: start,
|
|
692
|
+
end: end
|
|
693
|
+
};
|
|
666
694
|
} catch (e) {
|
|
667
695
|
// ignore
|
|
668
696
|
}
|
|
@@ -676,7 +704,10 @@ function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
|
|
|
676
704
|
});
|
|
677
705
|
endFormatter = new $7UzoM$DateFormatter(locale, endOptions);
|
|
678
706
|
}
|
|
679
|
-
return
|
|
707
|
+
return {
|
|
708
|
+
start: startFormatter.format(startDate),
|
|
709
|
+
end: endFormatter.format(endDate)
|
|
710
|
+
};
|
|
680
711
|
},
|
|
681
712
|
confirmPlaceholder () {
|
|
682
713
|
// Need to use ref value here because the value can be set in the same tick as
|
|
@@ -695,9 +726,6 @@ function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
|
|
|
695
726
|
}
|
|
696
727
|
|
|
697
728
|
|
|
698
|
-
var $eff5d8ee529ac4bb$exports = {};
|
|
699
|
-
|
|
700
|
-
$parcel$export($eff5d8ee529ac4bb$exports, "useTimeFieldState", () => $eff5d8ee529ac4bb$export$fd53cef0cc796101);
|
|
701
729
|
|
|
702
730
|
|
|
703
731
|
|
|
@@ -728,7 +756,7 @@ function $eff5d8ee529ac4bb$export$fd53cef0cc796101(props) {
|
|
|
728
756
|
let onChange = (newValue)=>{
|
|
729
757
|
setValue(v && 'day' in v ? newValue : newValue && $7UzoM$toTime(newValue));
|
|
730
758
|
};
|
|
731
|
-
return $
|
|
759
|
+
return $3c0fc76039f1c516$export$60e84778edff6d26({
|
|
732
760
|
...props,
|
|
733
761
|
value: dateTime,
|
|
734
762
|
defaultValue: undefined,
|
|
@@ -751,5 +779,5 @@ function $eff5d8ee529ac4bb$var$convertValue(value, date = $7UzoM$today($7UzoM$ge
|
|
|
751
779
|
|
|
752
780
|
|
|
753
781
|
|
|
754
|
-
export {$ab5bf3f618090389$export$87194bb378cc3ac2 as useDatePickerState, $
|
|
782
|
+
export {$ab5bf3f618090389$export$87194bb378cc3ac2 as useDatePickerState, $3c0fc76039f1c516$export$60e84778edff6d26 as useDateFieldState, $93c38a5e28be6249$export$e50a61c1de9f574 as useDateRangePickerState, $eff5d8ee529ac4bb$export$fd53cef0cc796101 as useTimeFieldState};
|
|
755
783
|
//# sourceMappingURL=module.js.map
|