@react-stately/datepicker 3.0.0-nightly.3173 → 3.0.0-rc.0
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 +66 -61
- package/dist/main.js.map +1 -1
- package/dist/module.js +63 -46
- 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 +7 -7
- package/src/index.ts +9 -4
- package/src/{useDatePickerFieldState.ts → useDateFieldState.ts} +79 -17
- package/src/useDatePickerState.ts +35 -12
- package/src/useDateRangePickerState.ts +79 -20
- package/src/useTimeFieldState.ts +10 -4
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
|
|
|
@@ -86,9 +81,10 @@ function $35a22f14a1f04b11$export$2440da353cedad43(v, granularity) {
|
|
|
86
81
|
|
|
87
82
|
|
|
88
83
|
|
|
84
|
+
|
|
89
85
|
function $ab5bf3f618090389$export$87194bb378cc3ac2(props) {
|
|
90
86
|
var ref;
|
|
91
|
-
let
|
|
87
|
+
let overlayState = $7UzoM$useOverlayTriggerState(props);
|
|
92
88
|
let [value, setValue] = $7UzoM$useControlledState(props.value, props.defaultValue || null, props.onChange);
|
|
93
89
|
let v = value || props.placeholderValue;
|
|
94
90
|
let [granularity, defaultTimeZone] = $35a22f14a1f04b11$export$2440da353cedad43(v, props.granularity);
|
|
@@ -114,7 +110,7 @@ function $ab5bf3f618090389$export$87194bb378cc3ac2(props) {
|
|
|
114
110
|
if (selectedTime || shouldClose) commitValue(newValue, selectedTime || $35a22f14a1f04b11$export$c5221a78ef73c5e9(props.placeholderValue));
|
|
115
111
|
else setSelectedDate(newValue);
|
|
116
112
|
} else setValue(newValue);
|
|
117
|
-
if (shouldClose) setOpen(false);
|
|
113
|
+
if (shouldClose) overlayState.setOpen(false);
|
|
118
114
|
};
|
|
119
115
|
let selectTime = (newValue)=>{
|
|
120
116
|
if (selectedDate) commitValue(selectedDate, newValue);
|
|
@@ -130,13 +126,13 @@ function $ab5bf3f618090389$export$87194bb378cc3ac2(props) {
|
|
|
130
126
|
setTimeValue: selectTime,
|
|
131
127
|
granularity: granularity,
|
|
132
128
|
hasTime: hasTime,
|
|
133
|
-
isOpen:
|
|
129
|
+
isOpen: overlayState.isOpen,
|
|
134
130
|
setOpen (isOpen) {
|
|
135
131
|
// Commit the selected date when the calendar is closed. Use a placeholder time if one wasn't set.
|
|
136
132
|
// If only the time was set and not the date, don't commit. The state will be preserved until
|
|
137
133
|
// the user opens the popover again.
|
|
138
134
|
if (!isOpen && !value && selectedDate && hasTime) commitValue(selectedDate, selectedTime || $35a22f14a1f04b11$export$c5221a78ef73c5e9(props.placeholderValue));
|
|
139
|
-
setOpen(isOpen);
|
|
135
|
+
overlayState.setOpen(isOpen);
|
|
140
136
|
},
|
|
141
137
|
validationState: validationState,
|
|
142
138
|
formatValue (locale, fieldOptions) {
|
|
@@ -154,14 +150,11 @@ function $ab5bf3f618090389$export$87194bb378cc3ac2(props) {
|
|
|
154
150
|
}
|
|
155
151
|
|
|
156
152
|
|
|
157
|
-
var $09e80d602234613d$exports = {};
|
|
158
153
|
|
|
159
|
-
$parcel$export($09e80d602234613d$exports, "useDatePickerFieldState", () => $09e80d602234613d$export$714a241b39a650d6);
|
|
160
154
|
|
|
161
155
|
|
|
162
156
|
|
|
163
|
-
|
|
164
|
-
const $09e80d602234613d$var$EDITABLE_SEGMENTS = {
|
|
157
|
+
const $3c0fc76039f1c516$var$EDITABLE_SEGMENTS = {
|
|
165
158
|
year: true,
|
|
166
159
|
month: true,
|
|
167
160
|
day: true,
|
|
@@ -171,7 +164,7 @@ const $09e80d602234613d$var$EDITABLE_SEGMENTS = {
|
|
|
171
164
|
dayPeriod: true,
|
|
172
165
|
era: true
|
|
173
166
|
};
|
|
174
|
-
const $
|
|
167
|
+
const $3c0fc76039f1c516$var$PAGE_STEP = {
|
|
175
168
|
year: 5,
|
|
176
169
|
month: 2,
|
|
177
170
|
day: 7,
|
|
@@ -180,10 +173,10 @@ const $09e80d602234613d$var$PAGE_STEP = {
|
|
|
180
173
|
second: 15
|
|
181
174
|
};
|
|
182
175
|
// Node seems to convert everything to lowercase...
|
|
183
|
-
const $
|
|
176
|
+
const $3c0fc76039f1c516$var$TYPE_MAPPING = {
|
|
184
177
|
dayperiod: 'dayPeriod'
|
|
185
178
|
};
|
|
186
|
-
function $
|
|
179
|
+
function $3c0fc76039f1c516$export$60e84778edff6d26(props) {
|
|
187
180
|
let { locale: locale , createCalendar: createCalendar , hideTimeZone: hideTimeZone , isDisabled: isDisabled , isReadOnly: isReadOnly , isRequired: isRequired } = props;
|
|
188
181
|
let v1 = props.value || props.defaultValue || props.placeholderValue;
|
|
189
182
|
let [granularity, defaultTimeZone] = $35a22f14a1f04b11$export$2440da353cedad43(v1, props.granularity);
|
|
@@ -226,7 +219,7 @@ function $09e80d602234613d$export$714a241b39a650d6(props) {
|
|
|
226
219
|
]);
|
|
227
220
|
// Determine how many editable segments there are for validation purposes.
|
|
228
221
|
// The result is cached for performance.
|
|
229
|
-
let allSegments = $7UzoM$useMemo(()=>dateFormatter.formatToParts(new Date()).filter((seg)=>$
|
|
222
|
+
let allSegments = $7UzoM$useMemo(()=>dateFormatter.formatToParts(new Date()).filter((seg)=>$3c0fc76039f1c516$var$EDITABLE_SEGMENTS[seg.type]
|
|
230
223
|
).reduce((p, seg)=>(p[seg.type] = true, p)
|
|
231
224
|
, {
|
|
232
225
|
})
|
|
@@ -296,13 +289,13 @@ function $09e80d602234613d$export$714a241b39a650d6(props) {
|
|
|
296
289
|
timeZone
|
|
297
290
|
]);
|
|
298
291
|
let segments = $7UzoM$useMemo(()=>dateFormatter.formatToParts(dateValue).map((segment)=>{
|
|
299
|
-
let isEditable = $
|
|
292
|
+
let isEditable = $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[segment.type];
|
|
300
293
|
if (segment.type === 'era' && calendar.getEras().length === 1) isEditable = false;
|
|
301
294
|
return {
|
|
302
|
-
type: $
|
|
295
|
+
type: $3c0fc76039f1c516$var$TYPE_MAPPING[segment.type] || segment.type,
|
|
303
296
|
text: segment.value,
|
|
304
|
-
...$
|
|
305
|
-
isPlaceholder: $
|
|
297
|
+
...$3c0fc76039f1c516$var$getSegmentLimits(displayValue, segment.type, resolvedOptions),
|
|
298
|
+
isPlaceholder: $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[segment.type] && !validSegments[segment.type],
|
|
306
299
|
isEditable: isEditable
|
|
307
300
|
};
|
|
308
301
|
})
|
|
@@ -328,9 +321,10 @@ function $09e80d602234613d$export$714a241b39a650d6(props) {
|
|
|
328
321
|
};
|
|
329
322
|
let adjustSegment = (type, amount)=>{
|
|
330
323
|
markValid(type);
|
|
331
|
-
setValue($
|
|
324
|
+
setValue($3c0fc76039f1c516$var$addSegment(displayValue, type, amount, resolvedOptions));
|
|
332
325
|
};
|
|
333
326
|
let validationState = props.validationState || ($35a22f14a1f04b11$export$eac50920cf2fd59a(calendarValue, props.minValue, props.maxValue) ? 'invalid' : null);
|
|
327
|
+
var _maxGranularity1;
|
|
334
328
|
return {
|
|
335
329
|
value: calendarValue,
|
|
336
330
|
dateValue: dateValue,
|
|
@@ -339,6 +333,7 @@ function $09e80d602234613d$export$714a241b39a650d6(props) {
|
|
|
339
333
|
dateFormatter: dateFormatter,
|
|
340
334
|
validationState: validationState,
|
|
341
335
|
granularity: granularity,
|
|
336
|
+
maxGranularity: (_maxGranularity1 = props.maxGranularity) !== null && _maxGranularity1 !== void 0 ? _maxGranularity1 : 'year',
|
|
342
337
|
isDisabled: isDisabled,
|
|
343
338
|
isReadOnly: isReadOnly,
|
|
344
339
|
isRequired: isRequired,
|
|
@@ -349,14 +344,14 @@ function $09e80d602234613d$export$714a241b39a650d6(props) {
|
|
|
349
344
|
adjustSegment(part, -1);
|
|
350
345
|
},
|
|
351
346
|
incrementPage (part) {
|
|
352
|
-
adjustSegment(part, $
|
|
347
|
+
adjustSegment(part, $3c0fc76039f1c516$var$PAGE_STEP[part] || 1);
|
|
353
348
|
},
|
|
354
349
|
decrementPage (part) {
|
|
355
|
-
adjustSegment(part, -($
|
|
350
|
+
adjustSegment(part, -($3c0fc76039f1c516$var$PAGE_STEP[part] || 1));
|
|
356
351
|
},
|
|
357
352
|
setSegment (part, v) {
|
|
358
353
|
markValid(part);
|
|
359
|
-
setValue($
|
|
354
|
+
setValue($3c0fc76039f1c516$var$setSegment(displayValue, part, v, resolvedOptions));
|
|
360
355
|
},
|
|
361
356
|
confirmPlaceholder (part) {
|
|
362
357
|
if (props.isDisabled || props.isReadOnly) return;
|
|
@@ -398,12 +393,15 @@ function $09e80d602234613d$export$714a241b39a650d6(props) {
|
|
|
398
393
|
setDate(null);
|
|
399
394
|
setValue(value);
|
|
400
395
|
},
|
|
401
|
-
|
|
402
|
-
|
|
396
|
+
formatValue (fieldOptions) {
|
|
397
|
+
if (!calendarValue) return '';
|
|
398
|
+
let formatOptions = $35a22f14a1f04b11$export$7e319ea407e63bc0(fieldOptions, formatOpts);
|
|
399
|
+
let formatter = new $7UzoM$DateFormatter(locale, formatOptions);
|
|
400
|
+
return formatter.format(dateValue);
|
|
403
401
|
}
|
|
404
402
|
};
|
|
405
403
|
}
|
|
406
|
-
function $
|
|
404
|
+
function $3c0fc76039f1c516$var$getSegmentLimits(date, type, options) {
|
|
407
405
|
switch(type){
|
|
408
406
|
case 'era':
|
|
409
407
|
{
|
|
@@ -470,7 +468,7 @@ function $09e80d602234613d$var$getSegmentLimits(date, type, options) {
|
|
|
470
468
|
return {
|
|
471
469
|
};
|
|
472
470
|
}
|
|
473
|
-
function $
|
|
471
|
+
function $3c0fc76039f1c516$var$addSegment(value, part, amount, options) {
|
|
474
472
|
switch(part){
|
|
475
473
|
case 'era':
|
|
476
474
|
case 'year':
|
|
@@ -498,7 +496,7 @@ function $09e80d602234613d$var$addSegment(value, part, amount, options) {
|
|
|
498
496
|
});
|
|
499
497
|
}
|
|
500
498
|
}
|
|
501
|
-
function $
|
|
499
|
+
function $3c0fc76039f1c516$var$setSegment(value, part, segmentValue, options) {
|
|
502
500
|
switch(part){
|
|
503
501
|
case 'day':
|
|
504
502
|
case 'month':
|
|
@@ -536,16 +534,14 @@ function $09e80d602234613d$var$setSegment(value, part, segmentValue, options) {
|
|
|
536
534
|
}
|
|
537
535
|
|
|
538
536
|
|
|
539
|
-
var $93c38a5e28be6249$exports = {};
|
|
540
537
|
|
|
541
|
-
$parcel$export($93c38a5e28be6249$exports, "useDateRangePickerState", () => $93c38a5e28be6249$export$e50a61c1de9f574);
|
|
542
538
|
|
|
543
539
|
|
|
544
540
|
|
|
545
541
|
|
|
546
542
|
function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
|
|
547
543
|
var ref, ref1;
|
|
548
|
-
let
|
|
544
|
+
let overlayState = $7UzoM$useOverlayTriggerState(props);
|
|
549
545
|
let [controlledValue, setControlledValue] = $7UzoM$useControlledState(props.value, props.defaultValue || null, props.onChange);
|
|
550
546
|
let [placeholderValue, setPlaceholderValue] = $7UzoM$useState(()=>controlledValue || {
|
|
551
547
|
start: null,
|
|
@@ -597,7 +593,7 @@ function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
|
|
|
597
593
|
else setSelectedDateRange(range);
|
|
598
594
|
} else if (range.start && range.end) setValue(range);
|
|
599
595
|
else setSelectedDateRange(range);
|
|
600
|
-
if (shouldClose) setOpen(false);
|
|
596
|
+
if (shouldClose) overlayState.setOpen(false);
|
|
601
597
|
};
|
|
602
598
|
let setTimeRange = (range)=>{
|
|
603
599
|
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 +627,7 @@ function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
|
|
|
631
627
|
},
|
|
632
628
|
setDateRange: setDateRange,
|
|
633
629
|
setTimeRange: setTimeRange,
|
|
634
|
-
isOpen:
|
|
630
|
+
isOpen: overlayState.isOpen,
|
|
635
631
|
setOpen (isOpen) {
|
|
636
632
|
// Commit the selected date range when the calendar is closed. Use a placeholder time if one wasn't set.
|
|
637
633
|
// If only the time range was set and not the date range, don't commit. The state will be preserved until
|
|
@@ -640,11 +636,11 @@ function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
|
|
|
640
636
|
start: (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.start) || $35a22f14a1f04b11$export$c5221a78ef73c5e9(props.placeholderValue),
|
|
641
637
|
end: (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.end) || $35a22f14a1f04b11$export$c5221a78ef73c5e9(props.placeholderValue)
|
|
642
638
|
});
|
|
643
|
-
setOpen(isOpen);
|
|
639
|
+
overlayState.setOpen(isOpen);
|
|
644
640
|
},
|
|
645
641
|
validationState: validationState,
|
|
646
642
|
formatValue (locale, fieldOptions) {
|
|
647
|
-
if (!value1 || !value1.start || !value1.end) return
|
|
643
|
+
if (!value1 || !value1.start || !value1.end) return null;
|
|
648
644
|
let startTimeZone = 'timeZone' in value1.start ? value1.start.timeZone : undefined;
|
|
649
645
|
let startGranularity = props.granularity || (value1.start && 'minute' in value1.start ? 'minute' : 'day');
|
|
650
646
|
let endTimeZone = 'timeZone' in value1.end ? value1.end.timeZone : undefined;
|
|
@@ -655,14 +651,35 @@ function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
|
|
|
655
651
|
hideTimeZone: props.hideTimeZone,
|
|
656
652
|
hourCycle: props.hourCycle
|
|
657
653
|
});
|
|
654
|
+
let startDate = value1.start.toDate(startTimeZone || 'UTC');
|
|
655
|
+
let endDate = value1.end.toDate(endTimeZone || 'UTC');
|
|
658
656
|
let startFormatter = new $7UzoM$DateFormatter(locale, startOptions);
|
|
659
657
|
let endFormatter;
|
|
660
|
-
if (startTimeZone === endTimeZone && startGranularity === endGranularity) {
|
|
658
|
+
if (startTimeZone === endTimeZone && startGranularity === endGranularity && value1.start.compare(value1.end) !== 0) {
|
|
661
659
|
// Use formatRange, as it results in shorter output when some of the fields
|
|
662
660
|
// are shared between the start and end dates (e.g. the same month).
|
|
663
661
|
// Formatting will fail if the end date is before the start date. Fall back below when that happens.
|
|
664
662
|
try {
|
|
665
|
-
|
|
663
|
+
let parts = startFormatter.formatRangeToParts(startDate, endDate);
|
|
664
|
+
// Find the separator between the start and end date. This is determined
|
|
665
|
+
// by finding the last shared literal before the end range.
|
|
666
|
+
let separatorIndex = -1;
|
|
667
|
+
for(let i = 0; i < parts.length; i++){
|
|
668
|
+
let part = parts[i];
|
|
669
|
+
if (part.source === 'shared' && part.type === 'literal') separatorIndex = i;
|
|
670
|
+
else if (part.source === 'endRange') break;
|
|
671
|
+
}
|
|
672
|
+
// Now we can combine the parts into start and end strings.
|
|
673
|
+
let start = '';
|
|
674
|
+
let end = '';
|
|
675
|
+
for(let i1 = 0; i1 < parts.length; i1++){
|
|
676
|
+
if (i1 < separatorIndex) start += parts[i1].value;
|
|
677
|
+
else if (i1 > separatorIndex) end += parts[i1].value;
|
|
678
|
+
}
|
|
679
|
+
return {
|
|
680
|
+
start: start,
|
|
681
|
+
end: end
|
|
682
|
+
};
|
|
666
683
|
} catch (e) {
|
|
667
684
|
// ignore
|
|
668
685
|
}
|
|
@@ -676,7 +693,10 @@ function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
|
|
|
676
693
|
});
|
|
677
694
|
endFormatter = new $7UzoM$DateFormatter(locale, endOptions);
|
|
678
695
|
}
|
|
679
|
-
return
|
|
696
|
+
return {
|
|
697
|
+
start: startFormatter.format(startDate),
|
|
698
|
+
end: endFormatter.format(endDate)
|
|
699
|
+
};
|
|
680
700
|
},
|
|
681
701
|
confirmPlaceholder () {
|
|
682
702
|
// Need to use ref value here because the value can be set in the same tick as
|
|
@@ -695,9 +715,6 @@ function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
|
|
|
695
715
|
}
|
|
696
716
|
|
|
697
717
|
|
|
698
|
-
var $eff5d8ee529ac4bb$exports = {};
|
|
699
|
-
|
|
700
|
-
$parcel$export($eff5d8ee529ac4bb$exports, "useTimeFieldState", () => $eff5d8ee529ac4bb$export$fd53cef0cc796101);
|
|
701
718
|
|
|
702
719
|
|
|
703
720
|
|
|
@@ -728,7 +745,7 @@ function $eff5d8ee529ac4bb$export$fd53cef0cc796101(props) {
|
|
|
728
745
|
let onChange = (newValue)=>{
|
|
729
746
|
setValue(v && 'day' in v ? newValue : newValue && $7UzoM$toTime(newValue));
|
|
730
747
|
};
|
|
731
|
-
return $
|
|
748
|
+
return $3c0fc76039f1c516$export$60e84778edff6d26({
|
|
732
749
|
...props,
|
|
733
750
|
value: dateTime,
|
|
734
751
|
defaultValue: undefined,
|
|
@@ -751,5 +768,5 @@ function $eff5d8ee529ac4bb$var$convertValue(value, date = $7UzoM$today($7UzoM$ge
|
|
|
751
768
|
|
|
752
769
|
|
|
753
770
|
|
|
754
|
-
export {$ab5bf3f618090389$export$87194bb378cc3ac2 as useDatePickerState, $
|
|
771
|
+
export {$ab5bf3f618090389$export$87194bb378cc3ac2 as useDatePickerState, $3c0fc76039f1c516$export$60e84778edff6d26 as useDateFieldState, $93c38a5e28be6249$export$e50a61c1de9f574 as useDateRangePickerState, $eff5d8ee529ac4bb$export$fd53cef0cc796101 as useTimeFieldState};
|
|
755
772
|
//# sourceMappingURL=module.js.map
|