@react-stately/datepicker 3.0.0-alpha.3 → 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 +137 -116
- package/dist/main.js.map +1 -1
- package/dist/module.js +134 -113
- 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 +4 -4
- 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/main.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var $
|
|
2
|
-
var $
|
|
3
|
-
var $
|
|
1
|
+
var $h2qOe$internationalizeddate = require("@internationalized/date");
|
|
2
|
+
var $h2qOe$reactstatelyutils = require("@react-stately/utils");
|
|
3
|
+
var $h2qOe$react = require("react");
|
|
4
4
|
|
|
5
5
|
function $parcel$exportWildcard(dest, source) {
|
|
6
6
|
Object.keys(source).forEach(function(key) {
|
|
@@ -21,16 +21,16 @@ function $parcel$exportWildcard(dest, source) {
|
|
|
21
21
|
function $parcel$export(e, n, v, s) {
|
|
22
22
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
23
23
|
}
|
|
24
|
-
var $
|
|
24
|
+
var $aaab7a647e17e1fd$exports = {};
|
|
25
25
|
|
|
26
|
-
$parcel$export($
|
|
26
|
+
$parcel$export($aaab7a647e17e1fd$exports, "useDatePickerState", () => $aaab7a647e17e1fd$export$87194bb378cc3ac2);
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
|
|
30
|
-
function $
|
|
30
|
+
function $50d5d6a623389320$export$eac50920cf2fd59a(value, minValue, maxValue) {
|
|
31
31
|
return value != null && (minValue != null && value.compare(minValue) < 0 || maxValue != null && value.compare(maxValue) > 0);
|
|
32
32
|
}
|
|
33
|
-
const $
|
|
33
|
+
const $50d5d6a623389320$var$DEFAULT_FIELD_OPTIONS = {
|
|
34
34
|
year: 'numeric',
|
|
35
35
|
month: 'numeric',
|
|
36
36
|
day: 'numeric',
|
|
@@ -38,9 +38,9 @@ const $895c09bc3a8da163$var$DEFAULT_FIELD_OPTIONS = {
|
|
|
38
38
|
minute: '2-digit',
|
|
39
39
|
second: '2-digit'
|
|
40
40
|
};
|
|
41
|
-
function $
|
|
41
|
+
function $50d5d6a623389320$export$7e319ea407e63bc0(fieldOptions, options) {
|
|
42
42
|
fieldOptions = {
|
|
43
|
-
...$
|
|
43
|
+
...$50d5d6a623389320$var$DEFAULT_FIELD_OPTIONS,
|
|
44
44
|
...fieldOptions
|
|
45
45
|
};
|
|
46
46
|
let granularity = options.granularity || 'minute';
|
|
@@ -62,30 +62,30 @@ function $895c09bc3a8da163$export$7e319ea407e63bc0(fieldOptions, options) {
|
|
|
62
62
|
if (hasTime && options.timeZone && !options.hideTimeZone) opts1.timeZoneName = 'short';
|
|
63
63
|
return opts1;
|
|
64
64
|
}
|
|
65
|
-
function $
|
|
65
|
+
function $50d5d6a623389320$export$c5221a78ef73c5e9(placeholderValue) {
|
|
66
66
|
if (placeholderValue && 'hour' in placeholderValue) return placeholderValue;
|
|
67
|
-
return new $
|
|
67
|
+
return new $h2qOe$internationalizeddate.Time();
|
|
68
68
|
}
|
|
69
|
-
function $
|
|
69
|
+
function $50d5d6a623389320$export$61a490a80c552550(value, calendar) {
|
|
70
70
|
if (value === null) return null;
|
|
71
71
|
if (!value) return undefined;
|
|
72
|
-
return $
|
|
72
|
+
return $h2qOe$internationalizeddate.toCalendar(value, calendar);
|
|
73
73
|
}
|
|
74
|
-
function $
|
|
75
|
-
if (placeholderValue) return $
|
|
76
|
-
let date = $
|
|
74
|
+
function $50d5d6a623389320$export$66aa2b09de4b1ea5(placeholderValue, granularity, calendar, timeZone) {
|
|
75
|
+
if (placeholderValue) return $50d5d6a623389320$export$61a490a80c552550(placeholderValue, calendar);
|
|
76
|
+
let date = $h2qOe$internationalizeddate.toCalendar($h2qOe$internationalizeddate.now(timeZone).set({
|
|
77
77
|
hour: 0,
|
|
78
78
|
minute: 0,
|
|
79
79
|
second: 0,
|
|
80
80
|
millisecond: 0
|
|
81
81
|
}), calendar);
|
|
82
|
-
if (granularity === 'year' || granularity === 'month' || granularity === 'day') return $
|
|
83
|
-
if (!timeZone) return $
|
|
82
|
+
if (granularity === 'year' || granularity === 'month' || granularity === 'day') return $h2qOe$internationalizeddate.toCalendarDate(date);
|
|
83
|
+
if (!timeZone) return $h2qOe$internationalizeddate.toCalendarDateTime(date);
|
|
84
84
|
return date;
|
|
85
85
|
}
|
|
86
|
-
function $
|
|
86
|
+
function $50d5d6a623389320$export$2440da353cedad43(v, granularity) {
|
|
87
87
|
// Compute default granularity and time zone from the value. If the value becomes null, keep the last values.
|
|
88
|
-
let lastValue = $
|
|
88
|
+
let lastValue = $h2qOe$react.useRef(v);
|
|
89
89
|
if (v) lastValue.current = v;
|
|
90
90
|
v = lastValue.current;
|
|
91
91
|
let defaultTimeZone = v && 'timeZone' in v ? v.timeZone : undefined;
|
|
@@ -102,15 +102,18 @@ function $895c09bc3a8da163$export$2440da353cedad43(v, granularity) {
|
|
|
102
102
|
|
|
103
103
|
|
|
104
104
|
|
|
105
|
-
function $
|
|
106
|
-
|
|
107
|
-
let [
|
|
105
|
+
function $aaab7a647e17e1fd$export$87194bb378cc3ac2(props) {
|
|
106
|
+
var ref;
|
|
107
|
+
let [isOpen1, setOpen] = $h2qOe$react.useState(false);
|
|
108
|
+
let [value, setValue] = $h2qOe$reactstatelyutils.useControlledState(props.value, props.defaultValue || null, props.onChange);
|
|
108
109
|
let v = value || props.placeholderValue;
|
|
109
|
-
let [granularity, defaultTimeZone] = $
|
|
110
|
+
let [granularity, defaultTimeZone] = $50d5d6a623389320$export$2440da353cedad43(v, props.granularity);
|
|
110
111
|
let dateValue = value != null ? value.toDate(defaultTimeZone !== null && defaultTimeZone !== void 0 ? defaultTimeZone : 'UTC') : null;
|
|
111
112
|
let hasTime = granularity === 'hour' || granularity === 'minute' || granularity === 'second' || granularity === 'millisecond';
|
|
112
|
-
|
|
113
|
-
let
|
|
113
|
+
var _shouldCloseOnSelect;
|
|
114
|
+
let shouldCloseOnSelect = (_shouldCloseOnSelect = props.shouldCloseOnSelect) !== null && _shouldCloseOnSelect !== void 0 ? _shouldCloseOnSelect : true;
|
|
115
|
+
let [selectedDate, setSelectedDate] = $h2qOe$react.useState(null);
|
|
116
|
+
let [selectedTime, setSelectedTime] = $h2qOe$react.useState(null);
|
|
114
117
|
if (value) {
|
|
115
118
|
selectedDate = value;
|
|
116
119
|
if ('hour' in value) selectedTime = value;
|
|
@@ -118,21 +121,22 @@ function $3515ee73693e64c8$export$87194bb378cc3ac2(props) {
|
|
|
118
121
|
// props.granularity must actually exist in the value if one is provided.
|
|
119
122
|
if (v && !(granularity in v)) throw new Error('Invalid granularity ' + granularity + ' for value ' + v.toString());
|
|
120
123
|
let commitValue = (date, time)=>{
|
|
121
|
-
setValue('timeZone' in time ? time.set($
|
|
124
|
+
setValue('timeZone' in time ? time.set($h2qOe$internationalizeddate.toCalendarDate(date)) : $h2qOe$internationalizeddate.toCalendarDateTime(date, time));
|
|
122
125
|
};
|
|
123
126
|
// Intercept setValue to make sure the Time section is not changed by date selection in Calendar
|
|
124
127
|
let selectDate = (newValue)=>{
|
|
128
|
+
let shouldClose = typeof shouldCloseOnSelect === 'function' ? shouldCloseOnSelect() : shouldCloseOnSelect;
|
|
125
129
|
if (hasTime) {
|
|
126
|
-
if (selectedTime) commitValue(newValue, selectedTime);
|
|
130
|
+
if (selectedTime || shouldClose) commitValue(newValue, selectedTime || $50d5d6a623389320$export$c5221a78ef73c5e9(props.placeholderValue));
|
|
127
131
|
else setSelectedDate(newValue);
|
|
128
132
|
} else setValue(newValue);
|
|
129
|
-
if (
|
|
133
|
+
if (shouldClose) setOpen(false);
|
|
130
134
|
};
|
|
131
135
|
let selectTime = (newValue)=>{
|
|
132
136
|
if (selectedDate) commitValue(selectedDate, newValue);
|
|
133
137
|
else setSelectedTime(newValue);
|
|
134
138
|
};
|
|
135
|
-
let validationState = props.validationState || ($
|
|
139
|
+
let validationState = props.validationState || ($50d5d6a623389320$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);
|
|
136
140
|
return {
|
|
137
141
|
value: value,
|
|
138
142
|
setValue: setValue,
|
|
@@ -141,38 +145,39 @@ function $3515ee73693e64c8$export$87194bb378cc3ac2(props) {
|
|
|
141
145
|
setDateValue: selectDate,
|
|
142
146
|
setTimeValue: selectTime,
|
|
143
147
|
granularity: granularity,
|
|
148
|
+
hasTime: hasTime,
|
|
144
149
|
isOpen: isOpen1,
|
|
145
150
|
setOpen (isOpen) {
|
|
146
151
|
// Commit the selected date when the calendar is closed. Use a placeholder time if one wasn't set.
|
|
147
152
|
// If only the time was set and not the date, don't commit. The state will be preserved until
|
|
148
153
|
// the user opens the popover again.
|
|
149
|
-
if (!isOpen && !value && selectedDate && hasTime) commitValue(selectedDate, selectedTime || $
|
|
154
|
+
if (!isOpen && !value && selectedDate && hasTime) commitValue(selectedDate, selectedTime || $50d5d6a623389320$export$c5221a78ef73c5e9(props.placeholderValue));
|
|
150
155
|
setOpen(isOpen);
|
|
151
156
|
},
|
|
152
157
|
validationState: validationState,
|
|
153
158
|
formatValue (locale, fieldOptions) {
|
|
154
159
|
if (!dateValue) return '';
|
|
155
|
-
let formatOptions = $
|
|
160
|
+
let formatOptions = $50d5d6a623389320$export$7e319ea407e63bc0(fieldOptions, {
|
|
156
161
|
granularity: granularity,
|
|
157
162
|
timeZone: defaultTimeZone,
|
|
158
163
|
hideTimeZone: props.hideTimeZone,
|
|
159
164
|
hourCycle: props.hourCycle
|
|
160
165
|
});
|
|
161
|
-
let formatter = new $
|
|
166
|
+
let formatter = new $h2qOe$internationalizeddate.DateFormatter(locale, formatOptions);
|
|
162
167
|
return formatter.format(dateValue);
|
|
163
168
|
}
|
|
164
169
|
};
|
|
165
170
|
}
|
|
166
171
|
|
|
167
172
|
|
|
168
|
-
var $
|
|
173
|
+
var $596a1f0f523d6752$exports = {};
|
|
169
174
|
|
|
170
|
-
$parcel$export($
|
|
175
|
+
$parcel$export($596a1f0f523d6752$exports, "useDateFieldState", () => $596a1f0f523d6752$export$60e84778edff6d26);
|
|
171
176
|
|
|
172
177
|
|
|
173
178
|
|
|
174
179
|
|
|
175
|
-
const $
|
|
180
|
+
const $596a1f0f523d6752$var$EDITABLE_SEGMENTS = {
|
|
176
181
|
year: true,
|
|
177
182
|
month: true,
|
|
178
183
|
day: true,
|
|
@@ -182,7 +187,7 @@ const $551c2f64769d99c0$var$EDITABLE_SEGMENTS = {
|
|
|
182
187
|
dayPeriod: true,
|
|
183
188
|
era: true
|
|
184
189
|
};
|
|
185
|
-
const $
|
|
190
|
+
const $596a1f0f523d6752$var$PAGE_STEP = {
|
|
186
191
|
year: 5,
|
|
187
192
|
month: 2,
|
|
188
193
|
day: 7,
|
|
@@ -191,18 +196,18 @@ const $551c2f64769d99c0$var$PAGE_STEP = {
|
|
|
191
196
|
second: 15
|
|
192
197
|
};
|
|
193
198
|
// Node seems to convert everything to lowercase...
|
|
194
|
-
const $
|
|
199
|
+
const $596a1f0f523d6752$var$TYPE_MAPPING = {
|
|
195
200
|
dayperiod: 'dayPeriod'
|
|
196
201
|
};
|
|
197
|
-
function $
|
|
198
|
-
let { locale: locale , createCalendar: createCalendar , hideTimeZone: hideTimeZone } = props;
|
|
202
|
+
function $596a1f0f523d6752$export$60e84778edff6d26(props) {
|
|
203
|
+
let { locale: locale , createCalendar: createCalendar , hideTimeZone: hideTimeZone , isDisabled: isDisabled , isReadOnly: isReadOnly , isRequired: isRequired } = props;
|
|
199
204
|
let v1 = props.value || props.defaultValue || props.placeholderValue;
|
|
200
|
-
let [granularity, defaultTimeZone] = $
|
|
205
|
+
let [granularity, defaultTimeZone] = $50d5d6a623389320$export$2440da353cedad43(v1, props.granularity);
|
|
201
206
|
let timeZone = defaultTimeZone || 'UTC';
|
|
202
207
|
// props.granularity must actually exist in the value if one is provided.
|
|
203
208
|
if (v1 && !(granularity in v1)) throw new Error('Invalid granularity ' + granularity + ' for value ' + v1.toString());
|
|
204
209
|
var _maxGranularity;
|
|
205
|
-
let formatOpts = $
|
|
210
|
+
let formatOpts = $h2qOe$react.useMemo(()=>({
|
|
206
211
|
granularity: granularity,
|
|
207
212
|
maxGranularity: (_maxGranularity = props.maxGranularity) !== null && _maxGranularity !== void 0 ? _maxGranularity : 'year',
|
|
208
213
|
timeZone: defaultTimeZone,
|
|
@@ -216,35 +221,35 @@ function $551c2f64769d99c0$export$714a241b39a650d6(props) {
|
|
|
216
221
|
defaultTimeZone,
|
|
217
222
|
hideTimeZone
|
|
218
223
|
]);
|
|
219
|
-
let opts = $
|
|
224
|
+
let opts = $h2qOe$react.useMemo(()=>$50d5d6a623389320$export$7e319ea407e63bc0({
|
|
220
225
|
}, formatOpts)
|
|
221
226
|
, [
|
|
222
227
|
formatOpts
|
|
223
228
|
]);
|
|
224
|
-
let dateFormatter = $
|
|
229
|
+
let dateFormatter = $h2qOe$react.useMemo(()=>new $h2qOe$internationalizeddate.DateFormatter(locale, opts)
|
|
225
230
|
, [
|
|
226
231
|
locale,
|
|
227
232
|
opts
|
|
228
233
|
]);
|
|
229
|
-
let resolvedOptions = $
|
|
234
|
+
let resolvedOptions = $h2qOe$react.useMemo(()=>dateFormatter.resolvedOptions()
|
|
230
235
|
, [
|
|
231
236
|
dateFormatter
|
|
232
237
|
]);
|
|
233
|
-
let calendar = $
|
|
238
|
+
let calendar = $h2qOe$react.useMemo(()=>createCalendar(resolvedOptions.calendar)
|
|
234
239
|
, [
|
|
235
240
|
createCalendar,
|
|
236
241
|
resolvedOptions.calendar
|
|
237
242
|
]);
|
|
238
243
|
// Determine how many editable segments there are for validation purposes.
|
|
239
244
|
// The result is cached for performance.
|
|
240
|
-
let allSegments = $
|
|
245
|
+
let allSegments = $h2qOe$react.useMemo(()=>dateFormatter.formatToParts(new Date()).filter((seg)=>$596a1f0f523d6752$var$EDITABLE_SEGMENTS[seg.type]
|
|
241
246
|
).reduce((p, seg)=>(p[seg.type] = true, p)
|
|
242
247
|
, {
|
|
243
248
|
})
|
|
244
249
|
, [
|
|
245
250
|
dateFormatter
|
|
246
251
|
]);
|
|
247
|
-
let [validSegments, setValidSegments] = $
|
|
252
|
+
let [validSegments, setValidSegments] = $h2qOe$react.useState(()=>props.value || props.defaultValue ? {
|
|
248
253
|
...allSegments
|
|
249
254
|
} : {
|
|
250
255
|
}
|
|
@@ -253,14 +258,14 @@ function $551c2f64769d99c0$export$714a241b39a650d6(props) {
|
|
|
253
258
|
// until all segments are set. If the value === null (not undefined), then assume the component
|
|
254
259
|
// is controlled, so use the placeholder as the value until all segments are entered so it doesn't
|
|
255
260
|
// change from uncontrolled to controlled and emit a warning.
|
|
256
|
-
let [placeholderDate, setPlaceholderDate] = $
|
|
261
|
+
let [placeholderDate, setPlaceholderDate] = $h2qOe$react.useState(()=>$50d5d6a623389320$export$66aa2b09de4b1ea5(props.placeholderValue, granularity, calendar, defaultTimeZone)
|
|
257
262
|
);
|
|
258
263
|
// Reset placeholder when calendar changes
|
|
259
|
-
let lastCalendarIdentifier = $
|
|
260
|
-
$
|
|
264
|
+
let lastCalendarIdentifier = $h2qOe$react.useRef(calendar.identifier);
|
|
265
|
+
$h2qOe$react.useEffect(()=>{
|
|
261
266
|
if (calendar.identifier !== lastCalendarIdentifier.current) {
|
|
262
267
|
lastCalendarIdentifier.current = calendar.identifier;
|
|
263
|
-
setPlaceholderDate((placeholder)=>Object.keys(validSegments).length > 0 ? $
|
|
268
|
+
setPlaceholderDate((placeholder)=>Object.keys(validSegments).length > 0 ? $h2qOe$internationalizeddate.toCalendar(placeholder, calendar) : $50d5d6a623389320$export$66aa2b09de4b1ea5(props.placeholderValue, granularity, calendar, defaultTimeZone)
|
|
264
269
|
);
|
|
265
270
|
}
|
|
266
271
|
}, [
|
|
@@ -270,8 +275,8 @@ function $551c2f64769d99c0$export$714a241b39a650d6(props) {
|
|
|
270
275
|
defaultTimeZone,
|
|
271
276
|
props.placeholderValue
|
|
272
277
|
]);
|
|
273
|
-
let [value1, setDate] = $
|
|
274
|
-
let calendarValue = $
|
|
278
|
+
let [value1, setDate] = $h2qOe$reactstatelyutils.useControlledState(props.value, props.defaultValue, props.onChange);
|
|
279
|
+
let calendarValue = $h2qOe$react.useMemo(()=>$50d5d6a623389320$export$61a490a80c552550(value1, calendar)
|
|
275
280
|
, [
|
|
276
281
|
value1,
|
|
277
282
|
calendar
|
|
@@ -288,7 +293,7 @@ function $551c2f64769d99c0$export$714a241b39a650d6(props) {
|
|
|
288
293
|
validSegments = {
|
|
289
294
|
};
|
|
290
295
|
setValidSegments(validSegments);
|
|
291
|
-
setPlaceholderDate($
|
|
296
|
+
setPlaceholderDate($50d5d6a623389320$export$66aa2b09de4b1ea5(props.placeholderValue, granularity, calendar, defaultTimeZone));
|
|
292
297
|
}
|
|
293
298
|
// If all segments are valid, use the date from state, otherwise use the placeholder date.
|
|
294
299
|
let displayValue = calendarValue && Object.keys(validSegments).length >= Object.keys(allSegments).length ? calendarValue : placeholderDate;
|
|
@@ -297,23 +302,23 @@ function $551c2f64769d99c0$export$714a241b39a650d6(props) {
|
|
|
297
302
|
if (Object.keys(validSegments).length >= Object.keys(allSegments).length) {
|
|
298
303
|
// The display calendar should not have any effect on the emitted value.
|
|
299
304
|
// Emit dates in the same calendar as the original value, if any, otherwise gregorian.
|
|
300
|
-
newValue = $
|
|
305
|
+
newValue = $h2qOe$internationalizeddate.toCalendar(newValue, (v1 === null || v1 === void 0 ? void 0 : v1.calendar) || new $h2qOe$internationalizeddate.GregorianCalendar());
|
|
301
306
|
setDate(newValue);
|
|
302
307
|
} else setPlaceholderDate(newValue);
|
|
303
308
|
};
|
|
304
|
-
let dateValue = $
|
|
309
|
+
let dateValue = $h2qOe$react.useMemo(()=>displayValue.toDate(timeZone)
|
|
305
310
|
, [
|
|
306
311
|
displayValue,
|
|
307
312
|
timeZone
|
|
308
313
|
]);
|
|
309
|
-
let segments = $
|
|
310
|
-
let isEditable = $
|
|
314
|
+
let segments = $h2qOe$react.useMemo(()=>dateFormatter.formatToParts(dateValue).map((segment)=>{
|
|
315
|
+
let isEditable = $596a1f0f523d6752$var$EDITABLE_SEGMENTS[segment.type];
|
|
311
316
|
if (segment.type === 'era' && calendar.getEras().length === 1) isEditable = false;
|
|
312
317
|
return {
|
|
313
|
-
type: $
|
|
318
|
+
type: $596a1f0f523d6752$var$TYPE_MAPPING[segment.type] || segment.type,
|
|
314
319
|
text: segment.value,
|
|
315
|
-
...$
|
|
316
|
-
isPlaceholder: $
|
|
320
|
+
...$596a1f0f523d6752$var$getSegmentLimits(displayValue, segment.type, resolvedOptions),
|
|
321
|
+
isPlaceholder: $596a1f0f523d6752$var$EDITABLE_SEGMENTS[segment.type] && !validSegments[segment.type],
|
|
317
322
|
isEditable: isEditable
|
|
318
323
|
};
|
|
319
324
|
})
|
|
@@ -325,7 +330,7 @@ function $551c2f64769d99c0$export$714a241b39a650d6(props) {
|
|
|
325
330
|
displayValue,
|
|
326
331
|
calendar
|
|
327
332
|
]);
|
|
328
|
-
let hasEra = $
|
|
333
|
+
let hasEra = $h2qOe$react.useMemo(()=>segments.some((s)=>s.type === 'era'
|
|
329
334
|
)
|
|
330
335
|
, [
|
|
331
336
|
segments
|
|
@@ -339,9 +344,9 @@ function $551c2f64769d99c0$export$714a241b39a650d6(props) {
|
|
|
339
344
|
};
|
|
340
345
|
let adjustSegment = (type, amount)=>{
|
|
341
346
|
markValid(type);
|
|
342
|
-
setValue($
|
|
347
|
+
setValue($596a1f0f523d6752$var$addSegment(displayValue, type, amount, resolvedOptions));
|
|
343
348
|
};
|
|
344
|
-
let validationState = props.validationState || ($
|
|
349
|
+
let validationState = props.validationState || ($50d5d6a623389320$export$eac50920cf2fd59a(calendarValue, props.minValue, props.maxValue) ? 'invalid' : null);
|
|
345
350
|
return {
|
|
346
351
|
value: calendarValue,
|
|
347
352
|
dateValue: dateValue,
|
|
@@ -350,6 +355,9 @@ function $551c2f64769d99c0$export$714a241b39a650d6(props) {
|
|
|
350
355
|
dateFormatter: dateFormatter,
|
|
351
356
|
validationState: validationState,
|
|
352
357
|
granularity: granularity,
|
|
358
|
+
isDisabled: isDisabled,
|
|
359
|
+
isReadOnly: isReadOnly,
|
|
360
|
+
isRequired: isRequired,
|
|
353
361
|
increment (part) {
|
|
354
362
|
adjustSegment(part, 1);
|
|
355
363
|
},
|
|
@@ -357,14 +365,14 @@ function $551c2f64769d99c0$export$714a241b39a650d6(props) {
|
|
|
357
365
|
adjustSegment(part, -1);
|
|
358
366
|
},
|
|
359
367
|
incrementPage (part) {
|
|
360
|
-
adjustSegment(part, $
|
|
368
|
+
adjustSegment(part, $596a1f0f523d6752$var$PAGE_STEP[part] || 1);
|
|
361
369
|
},
|
|
362
370
|
decrementPage (part) {
|
|
363
|
-
adjustSegment(part, -($
|
|
371
|
+
adjustSegment(part, -($596a1f0f523d6752$var$PAGE_STEP[part] || 1));
|
|
364
372
|
},
|
|
365
373
|
setSegment (part, v) {
|
|
366
374
|
markValid(part);
|
|
367
|
-
setValue($
|
|
375
|
+
setValue($596a1f0f523d6752$var$setSegment(displayValue, part, v, resolvedOptions));
|
|
368
376
|
},
|
|
369
377
|
confirmPlaceholder (part) {
|
|
370
378
|
if (props.isDisabled || props.isReadOnly) return;
|
|
@@ -388,7 +396,7 @@ function $551c2f64769d99c0$export$714a241b39a650d6(props) {
|
|
|
388
396
|
setValidSegments({
|
|
389
397
|
...validSegments
|
|
390
398
|
});
|
|
391
|
-
let placeholder = $
|
|
399
|
+
let placeholder = $50d5d6a623389320$export$66aa2b09de4b1ea5(props.placeholderValue, granularity, calendar, defaultTimeZone);
|
|
392
400
|
let value = displayValue;
|
|
393
401
|
// Reset day period to default without changing the hour.
|
|
394
402
|
if (part === 'dayPeriod' && 'hour' in displayValue && 'hour' in placeholder) {
|
|
@@ -406,12 +414,15 @@ function $551c2f64769d99c0$export$714a241b39a650d6(props) {
|
|
|
406
414
|
setDate(null);
|
|
407
415
|
setValue(value);
|
|
408
416
|
},
|
|
409
|
-
|
|
410
|
-
|
|
417
|
+
formatValue (fieldOptions) {
|
|
418
|
+
if (!calendarValue) return '';
|
|
419
|
+
let formatOptions = $50d5d6a623389320$export$7e319ea407e63bc0(fieldOptions, formatOpts);
|
|
420
|
+
let formatter = new $h2qOe$internationalizeddate.DateFormatter(locale, formatOptions);
|
|
421
|
+
return formatter.format(dateValue);
|
|
411
422
|
}
|
|
412
423
|
};
|
|
413
424
|
}
|
|
414
|
-
function $
|
|
425
|
+
function $596a1f0f523d6752$var$getSegmentLimits(date, type, options) {
|
|
415
426
|
switch(type){
|
|
416
427
|
case 'era':
|
|
417
428
|
{
|
|
@@ -431,13 +442,13 @@ function $551c2f64769d99c0$var$getSegmentLimits(date, type, options) {
|
|
|
431
442
|
case 'month':
|
|
432
443
|
return {
|
|
433
444
|
value: date.month,
|
|
434
|
-
minValue: $
|
|
445
|
+
minValue: $h2qOe$internationalizeddate.getMinimumMonthInYear(date),
|
|
435
446
|
maxValue: date.calendar.getMonthsInYear(date)
|
|
436
447
|
};
|
|
437
448
|
case 'day':
|
|
438
449
|
return {
|
|
439
450
|
value: date.day,
|
|
440
|
-
minValue: $
|
|
451
|
+
minValue: $h2qOe$internationalizeddate.getMinimumDayInMonth(date),
|
|
441
452
|
maxValue: date.calendar.getDaysInMonth(date)
|
|
442
453
|
};
|
|
443
454
|
}
|
|
@@ -478,7 +489,7 @@ function $551c2f64769d99c0$var$getSegmentLimits(date, type, options) {
|
|
|
478
489
|
return {
|
|
479
490
|
};
|
|
480
491
|
}
|
|
481
|
-
function $
|
|
492
|
+
function $596a1f0f523d6752$var$addSegment(value, part, amount, options) {
|
|
482
493
|
switch(part){
|
|
483
494
|
case 'era':
|
|
484
495
|
case 'year':
|
|
@@ -506,7 +517,7 @@ function $551c2f64769d99c0$var$addSegment(value, part, amount, options) {
|
|
|
506
517
|
});
|
|
507
518
|
}
|
|
508
519
|
}
|
|
509
|
-
function $
|
|
520
|
+
function $596a1f0f523d6752$var$setSegment(value, part, segmentValue, options) {
|
|
510
521
|
switch(part){
|
|
511
522
|
case 'day':
|
|
512
523
|
case 'month':
|
|
@@ -544,17 +555,18 @@ function $551c2f64769d99c0$var$setSegment(value, part, segmentValue, options) {
|
|
|
544
555
|
}
|
|
545
556
|
|
|
546
557
|
|
|
547
|
-
var $
|
|
558
|
+
var $7072d26f58deb33b$exports = {};
|
|
548
559
|
|
|
549
|
-
$parcel$export($
|
|
560
|
+
$parcel$export($7072d26f58deb33b$exports, "useDateRangePickerState", () => $7072d26f58deb33b$export$e50a61c1de9f574);
|
|
550
561
|
|
|
551
562
|
|
|
552
563
|
|
|
553
564
|
|
|
554
|
-
function $
|
|
555
|
-
|
|
556
|
-
let [
|
|
557
|
-
let [
|
|
565
|
+
function $7072d26f58deb33b$export$e50a61c1de9f574(props) {
|
|
566
|
+
var ref, ref1;
|
|
567
|
+
let [isOpen1, setOpen] = $h2qOe$react.useState(false);
|
|
568
|
+
let [controlledValue, setControlledValue] = $h2qOe$reactstatelyutils.useControlledState(props.value, props.defaultValue || null, props.onChange);
|
|
569
|
+
let [placeholderValue, setPlaceholderValue] = $h2qOe$react.useState(()=>controlledValue || {
|
|
558
570
|
start: null,
|
|
559
571
|
end: null
|
|
560
572
|
}
|
|
@@ -568,7 +580,7 @@ function $6da0ec721ca9cb39$export$e50a61c1de9f574(props) {
|
|
|
568
580
|
setPlaceholderValue(placeholderValue);
|
|
569
581
|
}
|
|
570
582
|
let value1 = controlledValue || placeholderValue;
|
|
571
|
-
let valueRef = $
|
|
583
|
+
let valueRef = $h2qOe$react.useRef(value1);
|
|
572
584
|
valueRef.current = value1;
|
|
573
585
|
let setValue = (value)=>{
|
|
574
586
|
valueRef.current = value;
|
|
@@ -577,40 +589,47 @@ function $6da0ec721ca9cb39$export$e50a61c1de9f574(props) {
|
|
|
577
589
|
else setControlledValue(null);
|
|
578
590
|
};
|
|
579
591
|
let v = (value1 === null || value1 === void 0 ? void 0 : value1.start) || (value1 === null || value1 === void 0 ? void 0 : value1.end) || props.placeholderValue;
|
|
580
|
-
let [granularity, defaultTimeZone] = $
|
|
592
|
+
let [granularity, defaultTimeZone] = $50d5d6a623389320$export$2440da353cedad43(v, props.granularity);
|
|
581
593
|
let hasTime = granularity === 'hour' || granularity === 'minute' || granularity === 'second' || granularity === 'millisecond';
|
|
582
|
-
|
|
583
|
-
let
|
|
594
|
+
var _shouldCloseOnSelect;
|
|
595
|
+
let shouldCloseOnSelect = (_shouldCloseOnSelect = props.shouldCloseOnSelect) !== null && _shouldCloseOnSelect !== void 0 ? _shouldCloseOnSelect : true;
|
|
596
|
+
let [dateRange1, setSelectedDateRange] = $h2qOe$react.useState(null);
|
|
597
|
+
let [timeRange1, setSelectedTimeRange] = $h2qOe$react.useState(null);
|
|
584
598
|
if (value1 && value1.start && value1.end) {
|
|
585
599
|
dateRange1 = value1;
|
|
586
600
|
if ('hour' in value1.start) timeRange1 = value1;
|
|
587
601
|
}
|
|
588
602
|
let commitValue = (dateRange, timeRange)=>{
|
|
589
603
|
setValue({
|
|
590
|
-
start: 'timeZone' in timeRange.start ? timeRange.start.set($
|
|
591
|
-
end: 'timeZone' in timeRange.end ? timeRange.end.set($
|
|
604
|
+
start: 'timeZone' in timeRange.start ? timeRange.start.set($h2qOe$internationalizeddate.toCalendarDate(dateRange.start)) : $h2qOe$internationalizeddate.toCalendarDateTime(dateRange.start, timeRange.start),
|
|
605
|
+
end: 'timeZone' in timeRange.end ? timeRange.end.set($h2qOe$internationalizeddate.toCalendarDate(dateRange.end)) : $h2qOe$internationalizeddate.toCalendarDateTime(dateRange.end, timeRange.end)
|
|
592
606
|
});
|
|
593
607
|
};
|
|
594
608
|
// Intercept setValue to make sure the Time section is not changed by date selection in Calendar
|
|
595
609
|
let setDateRange = (range)=>{
|
|
610
|
+
let shouldClose = typeof shouldCloseOnSelect === 'function' ? shouldCloseOnSelect() : shouldCloseOnSelect;
|
|
596
611
|
if (hasTime) {
|
|
597
|
-
if (range.start && range.end && (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.start) && (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.end)) commitValue(range,
|
|
612
|
+
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, {
|
|
613
|
+
start: (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.start) || $50d5d6a623389320$export$c5221a78ef73c5e9(props.placeholderValue),
|
|
614
|
+
end: (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.end) || $50d5d6a623389320$export$c5221a78ef73c5e9(props.placeholderValue)
|
|
615
|
+
});
|
|
598
616
|
else setSelectedDateRange(range);
|
|
599
617
|
} else if (range.start && range.end) setValue(range);
|
|
600
618
|
else setSelectedDateRange(range);
|
|
601
|
-
if (
|
|
619
|
+
if (shouldClose) setOpen(false);
|
|
602
620
|
};
|
|
603
621
|
let setTimeRange = (range)=>{
|
|
604
622
|
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);
|
|
605
623
|
else setSelectedTimeRange(range);
|
|
606
624
|
};
|
|
607
|
-
let validationState = props.validationState || (value1 != null && ($
|
|
625
|
+
let validationState = props.validationState || (value1 != null && ($50d5d6a623389320$export$eac50920cf2fd59a(value1.start, props.minValue, props.maxValue) || $50d5d6a623389320$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);
|
|
608
626
|
return {
|
|
609
627
|
value: value1,
|
|
610
628
|
setValue: setValue,
|
|
611
629
|
dateRange: dateRange1,
|
|
612
630
|
timeRange: timeRange1,
|
|
613
631
|
granularity: granularity,
|
|
632
|
+
hasTime: hasTime,
|
|
614
633
|
setDate (part, date) {
|
|
615
634
|
setDateRange({
|
|
616
635
|
...dateRange1,
|
|
@@ -637,8 +656,8 @@ function $6da0ec721ca9cb39$export$e50a61c1de9f574(props) {
|
|
|
637
656
|
// If only the time range was set and not the date range, don't commit. The state will be preserved until
|
|
638
657
|
// the user opens the popover again.
|
|
639
658
|
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, {
|
|
640
|
-
start: (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.start) || $
|
|
641
|
-
end: (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.end) || $
|
|
659
|
+
start: (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.start) || $50d5d6a623389320$export$c5221a78ef73c5e9(props.placeholderValue),
|
|
660
|
+
end: (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.end) || $50d5d6a623389320$export$c5221a78ef73c5e9(props.placeholderValue)
|
|
642
661
|
});
|
|
643
662
|
setOpen(isOpen);
|
|
644
663
|
},
|
|
@@ -649,13 +668,13 @@ function $6da0ec721ca9cb39$export$e50a61c1de9f574(props) {
|
|
|
649
668
|
let startGranularity = props.granularity || (value1.start && 'minute' in value1.start ? 'minute' : 'day');
|
|
650
669
|
let endTimeZone = 'timeZone' in value1.end ? value1.end.timeZone : undefined;
|
|
651
670
|
let endGranularity = props.granularity || (value1.end && 'minute' in value1.end ? 'minute' : 'day');
|
|
652
|
-
let startOptions = $
|
|
671
|
+
let startOptions = $50d5d6a623389320$export$7e319ea407e63bc0(fieldOptions, {
|
|
653
672
|
granularity: startGranularity,
|
|
654
673
|
timeZone: startTimeZone,
|
|
655
674
|
hideTimeZone: props.hideTimeZone,
|
|
656
675
|
hourCycle: props.hourCycle
|
|
657
676
|
});
|
|
658
|
-
let startFormatter = new $
|
|
677
|
+
let startFormatter = new $h2qOe$internationalizeddate.DateFormatter(locale, startOptions);
|
|
659
678
|
let endFormatter;
|
|
660
679
|
if (startTimeZone === endTimeZone && startGranularity === endGranularity) {
|
|
661
680
|
// Use formatRange, as it results in shorter output when some of the fields
|
|
@@ -668,13 +687,13 @@ function $6da0ec721ca9cb39$export$e50a61c1de9f574(props) {
|
|
|
668
687
|
}
|
|
669
688
|
endFormatter = startFormatter;
|
|
670
689
|
} else {
|
|
671
|
-
let endOptions = $
|
|
690
|
+
let endOptions = $50d5d6a623389320$export$7e319ea407e63bc0(fieldOptions, {
|
|
672
691
|
granularity: endGranularity,
|
|
673
692
|
timeZone: endTimeZone,
|
|
674
693
|
hideTimeZone: props.hideTimeZone,
|
|
675
694
|
hourCycle: props.hourCycle
|
|
676
695
|
});
|
|
677
|
-
endFormatter = new $
|
|
696
|
+
endFormatter = new $h2qOe$internationalizeddate.DateFormatter(locale, endOptions);
|
|
678
697
|
}
|
|
679
698
|
return `${startFormatter.format(value1.start.toDate(startTimeZone))} – ${endFormatter.format(value1.end.toDate(endTimeZone))}`;
|
|
680
699
|
},
|
|
@@ -684,7 +703,7 @@ function $6da0ec721ca9cb39$export$e50a61c1de9f574(props) {
|
|
|
684
703
|
let value = valueRef.current;
|
|
685
704
|
if (value && Boolean(value.start) !== Boolean(value.end)) {
|
|
686
705
|
let calendar = (value.start || value.end).calendar;
|
|
687
|
-
let placeholder = $
|
|
706
|
+
let placeholder = $50d5d6a623389320$export$66aa2b09de4b1ea5(props.placeholderValue, granularity, calendar, defaultTimeZone);
|
|
688
707
|
setValue({
|
|
689
708
|
start: value.start || placeholder,
|
|
690
709
|
end: value.end || placeholder
|
|
@@ -695,40 +714,40 @@ function $6da0ec721ca9cb39$export$e50a61c1de9f574(props) {
|
|
|
695
714
|
}
|
|
696
715
|
|
|
697
716
|
|
|
698
|
-
var $
|
|
717
|
+
var $2654e87be0231a69$exports = {};
|
|
699
718
|
|
|
700
|
-
$parcel$export($
|
|
719
|
+
$parcel$export($2654e87be0231a69$exports, "useTimeFieldState", () => $2654e87be0231a69$export$fd53cef0cc796101);
|
|
701
720
|
|
|
702
721
|
|
|
703
722
|
|
|
704
723
|
|
|
705
|
-
function $
|
|
706
|
-
let { placeholderValue: placeholderValue = new $
|
|
707
|
-
let [value, setValue] = $
|
|
724
|
+
function $2654e87be0231a69$export$fd53cef0cc796101(props) {
|
|
725
|
+
let { placeholderValue: placeholderValue = new $h2qOe$internationalizeddate.Time() , minValue: minValue , maxValue: maxValue , granularity: granularity } = props;
|
|
726
|
+
let [value, setValue] = $h2qOe$reactstatelyutils.useControlledState(props.value, props.defaultValue, props.onChange);
|
|
708
727
|
let v = value || placeholderValue;
|
|
709
728
|
let day = v && 'day' in v ? v : undefined;
|
|
710
|
-
let placeholderDate = $
|
|
729
|
+
let placeholderDate = $h2qOe$react.useMemo(()=>$2654e87be0231a69$var$convertValue(placeholderValue)
|
|
711
730
|
, [
|
|
712
731
|
placeholderValue
|
|
713
732
|
]);
|
|
714
|
-
let minDate = $
|
|
733
|
+
let minDate = $h2qOe$react.useMemo(()=>$2654e87be0231a69$var$convertValue(minValue, day)
|
|
715
734
|
, [
|
|
716
735
|
minValue,
|
|
717
736
|
day
|
|
718
737
|
]);
|
|
719
|
-
let maxDate = $
|
|
738
|
+
let maxDate = $h2qOe$react.useMemo(()=>$2654e87be0231a69$var$convertValue(maxValue, day)
|
|
720
739
|
, [
|
|
721
740
|
maxValue,
|
|
722
741
|
day
|
|
723
742
|
]);
|
|
724
|
-
let dateTime = $
|
|
743
|
+
let dateTime = $h2qOe$react.useMemo(()=>value == null ? null : $2654e87be0231a69$var$convertValue(value)
|
|
725
744
|
, [
|
|
726
745
|
value
|
|
727
746
|
]);
|
|
728
747
|
let onChange = (newValue)=>{
|
|
729
|
-
setValue(v && 'day' in v ? newValue : newValue && $
|
|
748
|
+
setValue(v && 'day' in v ? newValue : newValue && $h2qOe$internationalizeddate.toTime(newValue));
|
|
730
749
|
};
|
|
731
|
-
return $
|
|
750
|
+
return $596a1f0f523d6752$export$60e84778edff6d26({
|
|
732
751
|
...props,
|
|
733
752
|
value: dateTime,
|
|
734
753
|
defaultValue: undefined,
|
|
@@ -737,20 +756,22 @@ function $090850ffe5b21f13$export$fd53cef0cc796101(props) {
|
|
|
737
756
|
onChange: onChange,
|
|
738
757
|
granularity: granularity || 'minute',
|
|
739
758
|
maxGranularity: 'hour',
|
|
740
|
-
placeholderValue: placeholderDate
|
|
759
|
+
placeholderValue: placeholderDate,
|
|
760
|
+
// Calendar should not matter for time fields.
|
|
761
|
+
createCalendar: ()=>new $h2qOe$internationalizeddate.GregorianCalendar()
|
|
741
762
|
});
|
|
742
763
|
}
|
|
743
|
-
function $
|
|
764
|
+
function $2654e87be0231a69$var$convertValue(value, date = $h2qOe$internationalizeddate.today($h2qOe$internationalizeddate.getLocalTimeZone())) {
|
|
744
765
|
if (!value) return null;
|
|
745
766
|
if ('day' in value) return value;
|
|
746
|
-
return $
|
|
767
|
+
return $h2qOe$internationalizeddate.toCalendarDateTime(date, value);
|
|
747
768
|
}
|
|
748
769
|
|
|
749
770
|
|
|
750
|
-
$parcel$exportWildcard(module.exports, $
|
|
751
|
-
$parcel$exportWildcard(module.exports, $
|
|
752
|
-
$parcel$exportWildcard(module.exports, $
|
|
753
|
-
$parcel$exportWildcard(module.exports, $
|
|
771
|
+
$parcel$exportWildcard(module.exports, $aaab7a647e17e1fd$exports);
|
|
772
|
+
$parcel$exportWildcard(module.exports, $596a1f0f523d6752$exports);
|
|
773
|
+
$parcel$exportWildcard(module.exports, $7072d26f58deb33b$exports);
|
|
774
|
+
$parcel$exportWildcard(module.exports, $2654e87be0231a69$exports);
|
|
754
775
|
|
|
755
776
|
|
|
756
777
|
//# sourceMappingURL=main.js.map
|