@react-stately/datepicker 3.0.0-nightly.3180 → 3.0.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 +503 -103
- package/dist/main.js.map +1 -1
- package/dist/module.js +499 -87
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +21 -16
- package/dist/types.d.ts.map +1 -1
- package/package.json +9 -8
- package/src/index.ts +9 -4
- package/src/placeholders.ts +108 -0
- package/src/useDateFieldState.ts +71 -45
- package/src/useDatePickerState.ts +9 -7
- package/src/useDateRangePickerState.ts +49 -33
- package/src/useTimeFieldState.ts +2 -2
- package/src/utils.ts +6 -1
package/dist/module.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
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";
|
|
5
|
+
import {MessageDictionary as $7UzoM$MessageDictionary} from "@internationalized/message";
|
|
4
6
|
|
|
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
7
|
|
|
12
8
|
|
|
13
9
|
|
|
@@ -44,6 +40,7 @@ function $35a22f14a1f04b11$export$7e319ea407e63bc0(fieldOptions, options) {
|
|
|
44
40
|
opts1.timeZone = options.timeZone || 'UTC';
|
|
45
41
|
let hasTime = granularity === 'hour' || granularity === 'minute' || granularity === 'second';
|
|
46
42
|
if (hasTime && options.timeZone && !options.hideTimeZone) opts1.timeZoneName = 'short';
|
|
43
|
+
if (options.showEra && startIdx === 0) opts1.era = 'short';
|
|
47
44
|
return opts1;
|
|
48
45
|
}
|
|
49
46
|
function $35a22f14a1f04b11$export$c5221a78ef73c5e9(placeholderValue) {
|
|
@@ -86,9 +83,10 @@ function $35a22f14a1f04b11$export$2440da353cedad43(v, granularity) {
|
|
|
86
83
|
|
|
87
84
|
|
|
88
85
|
|
|
86
|
+
|
|
89
87
|
function $ab5bf3f618090389$export$87194bb378cc3ac2(props) {
|
|
90
88
|
var ref;
|
|
91
|
-
let
|
|
89
|
+
let overlayState = $7UzoM$useOverlayTriggerState(props);
|
|
92
90
|
let [value, setValue] = $7UzoM$useControlledState(props.value, props.defaultValue || null, props.onChange);
|
|
93
91
|
let v = value || props.placeholderValue;
|
|
94
92
|
let [granularity, defaultTimeZone] = $35a22f14a1f04b11$export$2440da353cedad43(v, props.granularity);
|
|
@@ -114,7 +112,7 @@ function $ab5bf3f618090389$export$87194bb378cc3ac2(props) {
|
|
|
114
112
|
if (selectedTime || shouldClose) commitValue(newValue, selectedTime || $35a22f14a1f04b11$export$c5221a78ef73c5e9(props.placeholderValue));
|
|
115
113
|
else setSelectedDate(newValue);
|
|
116
114
|
} else setValue(newValue);
|
|
117
|
-
if (shouldClose) setOpen(false);
|
|
115
|
+
if (shouldClose) overlayState.setOpen(false);
|
|
118
116
|
};
|
|
119
117
|
let selectTime = (newValue)=>{
|
|
120
118
|
if (selectedDate) commitValue(selectedDate, newValue);
|
|
@@ -130,13 +128,13 @@ function $ab5bf3f618090389$export$87194bb378cc3ac2(props) {
|
|
|
130
128
|
setTimeValue: selectTime,
|
|
131
129
|
granularity: granularity,
|
|
132
130
|
hasTime: hasTime,
|
|
133
|
-
isOpen:
|
|
131
|
+
isOpen: overlayState.isOpen,
|
|
134
132
|
setOpen (isOpen) {
|
|
135
133
|
// Commit the selected date when the calendar is closed. Use a placeholder time if one wasn't set.
|
|
136
134
|
// If only the time was set and not the date, don't commit. The state will be preserved until
|
|
137
135
|
// the user opens the popover again.
|
|
138
136
|
if (!isOpen && !value && selectedDate && hasTime) commitValue(selectedDate, selectedTime || $35a22f14a1f04b11$export$c5221a78ef73c5e9(props.placeholderValue));
|
|
139
|
-
setOpen(isOpen);
|
|
137
|
+
overlayState.setOpen(isOpen);
|
|
140
138
|
},
|
|
141
139
|
validationState: validationState,
|
|
142
140
|
formatValue (locale, fieldOptions) {
|
|
@@ -145,7 +143,8 @@ function $ab5bf3f618090389$export$87194bb378cc3ac2(props) {
|
|
|
145
143
|
granularity: granularity,
|
|
146
144
|
timeZone: defaultTimeZone,
|
|
147
145
|
hideTimeZone: props.hideTimeZone,
|
|
148
|
-
hourCycle: props.hourCycle
|
|
146
|
+
hourCycle: props.hourCycle,
|
|
147
|
+
showEra: value.calendar.identifier === 'gregory' && value.era === 'BC'
|
|
149
148
|
});
|
|
150
149
|
let formatter = new $7UzoM$DateFormatter(locale, formatOptions);
|
|
151
150
|
return formatter.format(dateValue);
|
|
@@ -154,9 +153,396 @@ function $ab5bf3f618090389$export$87194bb378cc3ac2(props) {
|
|
|
154
153
|
}
|
|
155
154
|
|
|
156
155
|
|
|
157
|
-
var $3c0fc76039f1c516$exports = {};
|
|
158
156
|
|
|
159
|
-
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
// These placeholders are based on the strings used by the <input type="date">
|
|
160
|
+
// implementations in Chrome and Firefox. Additional languages are supported
|
|
161
|
+
// here than React Spectrum's typical translations.
|
|
162
|
+
const $3e3ed55ab2966714$var$placeholders = new $7UzoM$MessageDictionary({
|
|
163
|
+
ach: {
|
|
164
|
+
year: 'mwaka',
|
|
165
|
+
month: 'dwe',
|
|
166
|
+
day: 'nino'
|
|
167
|
+
},
|
|
168
|
+
af: {
|
|
169
|
+
year: 'jjjj',
|
|
170
|
+
month: 'mm',
|
|
171
|
+
day: 'dd'
|
|
172
|
+
},
|
|
173
|
+
am: {
|
|
174
|
+
year: 'ዓዓዓዓ',
|
|
175
|
+
month: 'ሚሜ',
|
|
176
|
+
day: 'ቀቀ'
|
|
177
|
+
},
|
|
178
|
+
an: {
|
|
179
|
+
year: 'aaaa',
|
|
180
|
+
month: 'mm',
|
|
181
|
+
day: 'dd'
|
|
182
|
+
},
|
|
183
|
+
ar: {
|
|
184
|
+
year: 'سنة',
|
|
185
|
+
month: 'شهر',
|
|
186
|
+
day: 'يوم'
|
|
187
|
+
},
|
|
188
|
+
ast: {
|
|
189
|
+
year: 'aaaa',
|
|
190
|
+
month: 'mm',
|
|
191
|
+
day: 'dd'
|
|
192
|
+
},
|
|
193
|
+
az: {
|
|
194
|
+
year: 'iiii',
|
|
195
|
+
month: 'aa',
|
|
196
|
+
day: 'gg'
|
|
197
|
+
},
|
|
198
|
+
be: {
|
|
199
|
+
year: 'гггг',
|
|
200
|
+
month: 'мм',
|
|
201
|
+
day: 'дд'
|
|
202
|
+
},
|
|
203
|
+
bg: {
|
|
204
|
+
year: 'гггг',
|
|
205
|
+
month: 'мм',
|
|
206
|
+
day: 'дд'
|
|
207
|
+
},
|
|
208
|
+
bn: {
|
|
209
|
+
year: 'yyyy',
|
|
210
|
+
month: 'মিমি',
|
|
211
|
+
day: 'dd'
|
|
212
|
+
},
|
|
213
|
+
br: {
|
|
214
|
+
year: 'bbbb',
|
|
215
|
+
month: 'mm',
|
|
216
|
+
day: 'dd'
|
|
217
|
+
},
|
|
218
|
+
bs: {
|
|
219
|
+
year: 'gggg',
|
|
220
|
+
month: 'mm',
|
|
221
|
+
day: 'dd'
|
|
222
|
+
},
|
|
223
|
+
ca: {
|
|
224
|
+
year: 'aaaa',
|
|
225
|
+
month: 'mm',
|
|
226
|
+
day: 'dd'
|
|
227
|
+
},
|
|
228
|
+
cak: {
|
|
229
|
+
year: 'jjjj',
|
|
230
|
+
month: 'ii',
|
|
231
|
+
day: "q'q'"
|
|
232
|
+
},
|
|
233
|
+
ckb: {
|
|
234
|
+
year: 'ساڵ',
|
|
235
|
+
month: 'مانگ',
|
|
236
|
+
day: 'ڕۆژ'
|
|
237
|
+
},
|
|
238
|
+
cs: {
|
|
239
|
+
year: 'rrrr',
|
|
240
|
+
month: 'mm',
|
|
241
|
+
day: 'dd'
|
|
242
|
+
},
|
|
243
|
+
cy: {
|
|
244
|
+
year: 'bbbb',
|
|
245
|
+
month: 'mm',
|
|
246
|
+
day: 'dd'
|
|
247
|
+
},
|
|
248
|
+
da: {
|
|
249
|
+
year: 'åååå',
|
|
250
|
+
month: 'mm',
|
|
251
|
+
day: 'dd'
|
|
252
|
+
},
|
|
253
|
+
de: {
|
|
254
|
+
year: 'jjjj',
|
|
255
|
+
month: 'mm',
|
|
256
|
+
day: 'tt'
|
|
257
|
+
},
|
|
258
|
+
dsb: {
|
|
259
|
+
year: 'llll',
|
|
260
|
+
month: 'mm',
|
|
261
|
+
day: 'źź'
|
|
262
|
+
},
|
|
263
|
+
el: {
|
|
264
|
+
year: 'εεεε',
|
|
265
|
+
month: 'μμ',
|
|
266
|
+
day: 'ηη'
|
|
267
|
+
},
|
|
268
|
+
en: {
|
|
269
|
+
year: 'yyyy',
|
|
270
|
+
month: 'mm',
|
|
271
|
+
day: 'dd'
|
|
272
|
+
},
|
|
273
|
+
eo: {
|
|
274
|
+
year: 'jjjj',
|
|
275
|
+
month: 'mm',
|
|
276
|
+
day: 'tt'
|
|
277
|
+
},
|
|
278
|
+
es: {
|
|
279
|
+
year: 'aaaa',
|
|
280
|
+
month: 'mm',
|
|
281
|
+
day: 'dd'
|
|
282
|
+
},
|
|
283
|
+
et: {
|
|
284
|
+
year: 'aaaa',
|
|
285
|
+
month: 'kk',
|
|
286
|
+
day: 'pp'
|
|
287
|
+
},
|
|
288
|
+
eu: {
|
|
289
|
+
year: 'uuuu',
|
|
290
|
+
month: 'hh',
|
|
291
|
+
day: 'ee'
|
|
292
|
+
},
|
|
293
|
+
fa: {
|
|
294
|
+
year: 'سال',
|
|
295
|
+
month: 'ماه',
|
|
296
|
+
day: 'روز'
|
|
297
|
+
},
|
|
298
|
+
ff: {
|
|
299
|
+
year: 'hhhh',
|
|
300
|
+
month: 'll',
|
|
301
|
+
day: 'ññ'
|
|
302
|
+
},
|
|
303
|
+
fi: {
|
|
304
|
+
year: 'vvvv',
|
|
305
|
+
month: 'kk',
|
|
306
|
+
day: 'pp'
|
|
307
|
+
},
|
|
308
|
+
fr: {
|
|
309
|
+
year: 'aaaa',
|
|
310
|
+
month: 'mm',
|
|
311
|
+
day: 'jj'
|
|
312
|
+
},
|
|
313
|
+
fy: {
|
|
314
|
+
year: 'jjjj',
|
|
315
|
+
month: 'mm',
|
|
316
|
+
day: 'dd'
|
|
317
|
+
},
|
|
318
|
+
ga: {
|
|
319
|
+
year: 'bbbb',
|
|
320
|
+
month: 'mm',
|
|
321
|
+
day: 'll'
|
|
322
|
+
},
|
|
323
|
+
gd: {
|
|
324
|
+
year: 'bbbb',
|
|
325
|
+
month: 'mm',
|
|
326
|
+
day: 'll'
|
|
327
|
+
},
|
|
328
|
+
gl: {
|
|
329
|
+
year: 'aaaa',
|
|
330
|
+
month: 'mm',
|
|
331
|
+
day: 'dd'
|
|
332
|
+
},
|
|
333
|
+
he: {
|
|
334
|
+
year: 'שנה',
|
|
335
|
+
month: 'חודש',
|
|
336
|
+
day: 'יום'
|
|
337
|
+
},
|
|
338
|
+
hr: {
|
|
339
|
+
year: 'gggg',
|
|
340
|
+
month: 'mm',
|
|
341
|
+
day: 'dd'
|
|
342
|
+
},
|
|
343
|
+
hsb: {
|
|
344
|
+
year: 'llll',
|
|
345
|
+
month: 'mm',
|
|
346
|
+
day: 'dd'
|
|
347
|
+
},
|
|
348
|
+
hu: {
|
|
349
|
+
year: 'éééé',
|
|
350
|
+
month: 'hh',
|
|
351
|
+
day: 'nn'
|
|
352
|
+
},
|
|
353
|
+
ia: {
|
|
354
|
+
year: 'aaaa',
|
|
355
|
+
month: 'mm',
|
|
356
|
+
day: 'dd'
|
|
357
|
+
},
|
|
358
|
+
id: {
|
|
359
|
+
year: 'tttt',
|
|
360
|
+
month: 'bb',
|
|
361
|
+
day: 'hh'
|
|
362
|
+
},
|
|
363
|
+
it: {
|
|
364
|
+
year: 'aaaa',
|
|
365
|
+
month: 'mm',
|
|
366
|
+
day: 'gg'
|
|
367
|
+
},
|
|
368
|
+
ja: {
|
|
369
|
+
year: ' 年 ',
|
|
370
|
+
month: '月',
|
|
371
|
+
day: '日'
|
|
372
|
+
},
|
|
373
|
+
ka: {
|
|
374
|
+
year: 'წწწწ',
|
|
375
|
+
month: 'თთ',
|
|
376
|
+
day: 'რრ'
|
|
377
|
+
},
|
|
378
|
+
kk: {
|
|
379
|
+
year: 'жжжж',
|
|
380
|
+
month: 'аа',
|
|
381
|
+
day: 'кк'
|
|
382
|
+
},
|
|
383
|
+
kn: {
|
|
384
|
+
year: 'ವವವವ',
|
|
385
|
+
month: 'ಮಿಮೀ',
|
|
386
|
+
day: 'ದಿದಿ'
|
|
387
|
+
},
|
|
388
|
+
ko: {
|
|
389
|
+
year: '연도',
|
|
390
|
+
month: '월',
|
|
391
|
+
day: '일'
|
|
392
|
+
},
|
|
393
|
+
lb: {
|
|
394
|
+
year: 'jjjj',
|
|
395
|
+
month: 'mm',
|
|
396
|
+
day: 'dd'
|
|
397
|
+
},
|
|
398
|
+
lo: {
|
|
399
|
+
year: 'ປປປປ',
|
|
400
|
+
month: 'ດດ',
|
|
401
|
+
day: 'ວວ'
|
|
402
|
+
},
|
|
403
|
+
lt: {
|
|
404
|
+
year: 'mmmm',
|
|
405
|
+
month: 'mm',
|
|
406
|
+
day: 'dd'
|
|
407
|
+
},
|
|
408
|
+
lv: {
|
|
409
|
+
year: 'gggg',
|
|
410
|
+
month: 'mm',
|
|
411
|
+
day: 'dd'
|
|
412
|
+
},
|
|
413
|
+
meh: {
|
|
414
|
+
year: 'aaaa',
|
|
415
|
+
month: 'mm',
|
|
416
|
+
day: 'dd'
|
|
417
|
+
},
|
|
418
|
+
ml: {
|
|
419
|
+
year: 'വർഷം',
|
|
420
|
+
month: 'മാസം',
|
|
421
|
+
day: 'തീയതി'
|
|
422
|
+
},
|
|
423
|
+
ms: {
|
|
424
|
+
year: 'tttt',
|
|
425
|
+
month: 'mm',
|
|
426
|
+
day: 'hh'
|
|
427
|
+
},
|
|
428
|
+
nl: {
|
|
429
|
+
year: 'jjjj',
|
|
430
|
+
month: 'mm',
|
|
431
|
+
day: 'dd'
|
|
432
|
+
},
|
|
433
|
+
nn: {
|
|
434
|
+
year: 'åååå',
|
|
435
|
+
month: 'mm',
|
|
436
|
+
day: 'dd'
|
|
437
|
+
},
|
|
438
|
+
no: {
|
|
439
|
+
year: 'åååå',
|
|
440
|
+
month: 'mm',
|
|
441
|
+
day: 'dd'
|
|
442
|
+
},
|
|
443
|
+
oc: {
|
|
444
|
+
year: 'aaaa',
|
|
445
|
+
month: 'mm',
|
|
446
|
+
day: 'jj'
|
|
447
|
+
},
|
|
448
|
+
pl: {
|
|
449
|
+
year: 'rrrr',
|
|
450
|
+
month: 'mm',
|
|
451
|
+
day: 'dd'
|
|
452
|
+
},
|
|
453
|
+
pt: {
|
|
454
|
+
year: 'aaaa',
|
|
455
|
+
month: 'mm',
|
|
456
|
+
day: 'dd'
|
|
457
|
+
},
|
|
458
|
+
rm: {
|
|
459
|
+
year: 'oooo',
|
|
460
|
+
month: 'mm',
|
|
461
|
+
day: 'dd'
|
|
462
|
+
},
|
|
463
|
+
ro: {
|
|
464
|
+
year: 'aaaa',
|
|
465
|
+
month: 'll',
|
|
466
|
+
day: 'zz'
|
|
467
|
+
},
|
|
468
|
+
ru: {
|
|
469
|
+
year: 'гггг',
|
|
470
|
+
month: 'мм',
|
|
471
|
+
day: 'дд'
|
|
472
|
+
},
|
|
473
|
+
sc: {
|
|
474
|
+
year: 'aaaa',
|
|
475
|
+
month: 'mm',
|
|
476
|
+
day: 'dd'
|
|
477
|
+
},
|
|
478
|
+
scn: {
|
|
479
|
+
year: 'aaaa',
|
|
480
|
+
month: 'mm',
|
|
481
|
+
day: 'jj'
|
|
482
|
+
},
|
|
483
|
+
sk: {
|
|
484
|
+
year: 'rrrr',
|
|
485
|
+
month: 'mm',
|
|
486
|
+
day: 'dd'
|
|
487
|
+
},
|
|
488
|
+
sl: {
|
|
489
|
+
year: 'llll',
|
|
490
|
+
month: 'mm',
|
|
491
|
+
day: 'dd'
|
|
492
|
+
},
|
|
493
|
+
sr: {
|
|
494
|
+
year: 'гггг',
|
|
495
|
+
month: 'мм',
|
|
496
|
+
day: 'дд'
|
|
497
|
+
},
|
|
498
|
+
sv: {
|
|
499
|
+
year: 'åååå',
|
|
500
|
+
month: 'mm',
|
|
501
|
+
day: 'dd'
|
|
502
|
+
},
|
|
503
|
+
szl: {
|
|
504
|
+
year: 'rrrr',
|
|
505
|
+
month: 'mm',
|
|
506
|
+
day: 'dd'
|
|
507
|
+
},
|
|
508
|
+
tg: {
|
|
509
|
+
year: 'сссс',
|
|
510
|
+
month: 'мм',
|
|
511
|
+
day: 'рр'
|
|
512
|
+
},
|
|
513
|
+
th: {
|
|
514
|
+
year: 'ปปปป',
|
|
515
|
+
month: 'ดด',
|
|
516
|
+
day: 'วว'
|
|
517
|
+
},
|
|
518
|
+
tr: {
|
|
519
|
+
year: 'yyyy',
|
|
520
|
+
month: 'aa',
|
|
521
|
+
day: 'gg'
|
|
522
|
+
},
|
|
523
|
+
uk: {
|
|
524
|
+
year: 'рррр',
|
|
525
|
+
month: 'мм',
|
|
526
|
+
day: 'дд'
|
|
527
|
+
},
|
|
528
|
+
'zh-CN': {
|
|
529
|
+
year: '年',
|
|
530
|
+
month: '月',
|
|
531
|
+
day: '日'
|
|
532
|
+
},
|
|
533
|
+
'zh-TW': {
|
|
534
|
+
year: '年',
|
|
535
|
+
month: '月',
|
|
536
|
+
day: '日'
|
|
537
|
+
}
|
|
538
|
+
}, 'en');
|
|
539
|
+
function $3e3ed55ab2966714$export$d3f5c5e0a5023fa0(field, value, locale) {
|
|
540
|
+
// Use the actual placeholder value for the era and day period fields.
|
|
541
|
+
if (field === 'era' || field === 'dayPeriod') return value;
|
|
542
|
+
if (field === 'year' || field === 'month' || field === 'day') return $3e3ed55ab2966714$var$placeholders.getStringForLocale(field, locale);
|
|
543
|
+
// For time fields (e.g. hour, minute, etc.), use two dashes as the placeholder.
|
|
544
|
+
return '––';
|
|
545
|
+
}
|
|
160
546
|
|
|
161
547
|
|
|
162
548
|
|
|
@@ -190,20 +576,45 @@ function $3c0fc76039f1c516$export$60e84778edff6d26(props) {
|
|
|
190
576
|
let timeZone = defaultTimeZone || 'UTC';
|
|
191
577
|
// props.granularity must actually exist in the value if one is provided.
|
|
192
578
|
if (v1 && !(granularity in v1)) throw new Error('Invalid granularity ' + granularity + ' for value ' + v1.toString());
|
|
579
|
+
let defaultFormatter = $7UzoM$useMemo(()=>new $7UzoM$DateFormatter(locale)
|
|
580
|
+
, [
|
|
581
|
+
locale
|
|
582
|
+
]);
|
|
583
|
+
let calendar = $7UzoM$useMemo(()=>createCalendar(defaultFormatter.resolvedOptions().calendar)
|
|
584
|
+
, [
|
|
585
|
+
createCalendar,
|
|
586
|
+
defaultFormatter
|
|
587
|
+
]);
|
|
588
|
+
let [value1, setDate] = $7UzoM$useControlledState(props.value, props.defaultValue, props.onChange);
|
|
589
|
+
let calendarValue = $7UzoM$useMemo(()=>$35a22f14a1f04b11$export$61a490a80c552550(value1, calendar)
|
|
590
|
+
, [
|
|
591
|
+
value1,
|
|
592
|
+
calendar
|
|
593
|
+
]);
|
|
594
|
+
// We keep track of the placeholder date separately in state so that onChange is not called
|
|
595
|
+
// until all segments are set. If the value === null (not undefined), then assume the component
|
|
596
|
+
// is controlled, so use the placeholder as the value until all segments are entered so it doesn't
|
|
597
|
+
// change from uncontrolled to controlled and emit a warning.
|
|
598
|
+
let [placeholderDate, setPlaceholderDate] = $7UzoM$useState(()=>$35a22f14a1f04b11$export$66aa2b09de4b1ea5(props.placeholderValue, granularity, calendar, defaultTimeZone)
|
|
599
|
+
);
|
|
600
|
+
let val = calendarValue || placeholderDate;
|
|
601
|
+
let showEra = calendar.identifier === 'gregory' && val.era === 'BC';
|
|
193
602
|
var _maxGranularity;
|
|
194
603
|
let formatOpts = $7UzoM$useMemo(()=>({
|
|
195
604
|
granularity: granularity,
|
|
196
605
|
maxGranularity: (_maxGranularity = props.maxGranularity) !== null && _maxGranularity !== void 0 ? _maxGranularity : 'year',
|
|
197
606
|
timeZone: defaultTimeZone,
|
|
198
607
|
hideTimeZone: hideTimeZone,
|
|
199
|
-
hourCycle: props.hourCycle
|
|
608
|
+
hourCycle: props.hourCycle,
|
|
609
|
+
showEra: showEra
|
|
200
610
|
})
|
|
201
611
|
, [
|
|
202
612
|
props.maxGranularity,
|
|
203
613
|
granularity,
|
|
204
614
|
props.hourCycle,
|
|
205
615
|
defaultTimeZone,
|
|
206
|
-
hideTimeZone
|
|
616
|
+
hideTimeZone,
|
|
617
|
+
showEra
|
|
207
618
|
]);
|
|
208
619
|
let opts = $7UzoM$useMemo(()=>$35a22f14a1f04b11$export$7e319ea407e63bc0({
|
|
209
620
|
}, formatOpts)
|
|
@@ -219,11 +630,6 @@ function $3c0fc76039f1c516$export$60e84778edff6d26(props) {
|
|
|
219
630
|
, [
|
|
220
631
|
dateFormatter
|
|
221
632
|
]);
|
|
222
|
-
let calendar = $7UzoM$useMemo(()=>createCalendar(resolvedOptions.calendar)
|
|
223
|
-
, [
|
|
224
|
-
createCalendar,
|
|
225
|
-
resolvedOptions.calendar
|
|
226
|
-
]);
|
|
227
633
|
// Determine how many editable segments there are for validation purposes.
|
|
228
634
|
// The result is cached for performance.
|
|
229
635
|
let allSegments = $7UzoM$useMemo(()=>dateFormatter.formatToParts(new Date()).filter((seg)=>$3c0fc76039f1c516$var$EDITABLE_SEGMENTS[seg.type]
|
|
@@ -238,12 +644,6 @@ function $3c0fc76039f1c516$export$60e84778edff6d26(props) {
|
|
|
238
644
|
} : {
|
|
239
645
|
}
|
|
240
646
|
);
|
|
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
647
|
// Reset placeholder when calendar changes
|
|
248
648
|
let lastCalendarIdentifier = $7UzoM$useRef(calendar.identifier);
|
|
249
649
|
$7UzoM$useEffect(()=>{
|
|
@@ -259,12 +659,6 @@ function $3c0fc76039f1c516$export$60e84778edff6d26(props) {
|
|
|
259
659
|
defaultTimeZone,
|
|
260
660
|
props.placeholderValue
|
|
261
661
|
]);
|
|
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
662
|
// If there is a value prop, and some segments were previously placeholders, mark them all as valid.
|
|
269
663
|
if (value1 && Object.keys(validSegments).length < Object.keys(allSegments).length) {
|
|
270
664
|
validSegments = {
|
|
@@ -298,11 +692,14 @@ function $3c0fc76039f1c516$export$60e84778edff6d26(props) {
|
|
|
298
692
|
let segments = $7UzoM$useMemo(()=>dateFormatter.formatToParts(dateValue).map((segment)=>{
|
|
299
693
|
let isEditable = $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[segment.type];
|
|
300
694
|
if (segment.type === 'era' && calendar.getEras().length === 1) isEditable = false;
|
|
695
|
+
let isPlaceholder = $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[segment.type] && !validSegments[segment.type];
|
|
696
|
+
let placeholder = $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[segment.type] ? $3e3ed55ab2966714$export$d3f5c5e0a5023fa0(segment.type, segment.value, locale) : null;
|
|
301
697
|
return {
|
|
302
698
|
type: $3c0fc76039f1c516$var$TYPE_MAPPING[segment.type] || segment.type,
|
|
303
|
-
text: segment.value,
|
|
699
|
+
text: isPlaceholder ? placeholder : segment.value,
|
|
304
700
|
...$3c0fc76039f1c516$var$getSegmentLimits(displayValue, segment.type, resolvedOptions),
|
|
305
|
-
isPlaceholder:
|
|
701
|
+
isPlaceholder: isPlaceholder,
|
|
702
|
+
placeholder: placeholder,
|
|
306
703
|
isEditable: isEditable
|
|
307
704
|
};
|
|
308
705
|
})
|
|
@@ -312,33 +709,47 @@ function $3c0fc76039f1c516$export$60e84778edff6d26(props) {
|
|
|
312
709
|
dateFormatter,
|
|
313
710
|
resolvedOptions,
|
|
314
711
|
displayValue,
|
|
315
|
-
calendar
|
|
316
|
-
|
|
317
|
-
let hasEra = $7UzoM$useMemo(()=>segments.some((s)=>s.type === 'era'
|
|
318
|
-
)
|
|
319
|
-
, [
|
|
320
|
-
segments
|
|
712
|
+
calendar,
|
|
713
|
+
locale
|
|
321
714
|
]);
|
|
715
|
+
// When the era field appears, mark it valid if the year field is already valid.
|
|
716
|
+
// If the era field disappears, remove it from the valid segments.
|
|
717
|
+
if (allSegments.era && validSegments.year && !validSegments.era) {
|
|
718
|
+
validSegments.era = true;
|
|
719
|
+
setValidSegments({
|
|
720
|
+
...validSegments
|
|
721
|
+
});
|
|
722
|
+
} else if (!allSegments.era && validSegments.era) {
|
|
723
|
+
delete validSegments.era;
|
|
724
|
+
setValidSegments({
|
|
725
|
+
...validSegments
|
|
726
|
+
});
|
|
727
|
+
}
|
|
322
728
|
let markValid = (part)=>{
|
|
323
729
|
validSegments[part] = true;
|
|
324
|
-
if (part === 'year' &&
|
|
730
|
+
if (part === 'year' && allSegments.era) validSegments.era = true;
|
|
325
731
|
setValidSegments({
|
|
326
732
|
...validSegments
|
|
327
733
|
});
|
|
328
734
|
};
|
|
329
735
|
let adjustSegment = (type, amount)=>{
|
|
330
|
-
|
|
331
|
-
|
|
736
|
+
if (!validSegments[type]) {
|
|
737
|
+
markValid(type);
|
|
738
|
+
if (Object.keys(validSegments).length >= Object.keys(allSegments).length) setValue(displayValue);
|
|
739
|
+
} else setValue($3c0fc76039f1c516$var$addSegment(displayValue, type, amount, resolvedOptions));
|
|
332
740
|
};
|
|
333
741
|
let validationState = props.validationState || ($35a22f14a1f04b11$export$eac50920cf2fd59a(calendarValue, props.minValue, props.maxValue) ? 'invalid' : null);
|
|
742
|
+
var _maxGranularity1;
|
|
334
743
|
return {
|
|
335
744
|
value: calendarValue,
|
|
336
745
|
dateValue: dateValue,
|
|
746
|
+
calendar: calendar,
|
|
337
747
|
setValue: setValue,
|
|
338
748
|
segments: segments,
|
|
339
749
|
dateFormatter: dateFormatter,
|
|
340
750
|
validationState: validationState,
|
|
341
751
|
granularity: granularity,
|
|
752
|
+
maxGranularity: (_maxGranularity1 = props.maxGranularity) !== null && _maxGranularity1 !== void 0 ? _maxGranularity1 : 'year',
|
|
342
753
|
isDisabled: isDisabled,
|
|
343
754
|
isReadOnly: isReadOnly,
|
|
344
755
|
isRequired: isRequired,
|
|
@@ -358,20 +769,16 @@ function $3c0fc76039f1c516$export$60e84778edff6d26(props) {
|
|
|
358
769
|
markValid(part);
|
|
359
770
|
setValue($3c0fc76039f1c516$var$setSegment(displayValue, part, v, resolvedOptions));
|
|
360
771
|
},
|
|
361
|
-
confirmPlaceholder (
|
|
772
|
+
confirmPlaceholder () {
|
|
362
773
|
if (props.isDisabled || props.isReadOnly) return;
|
|
363
|
-
if
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
setValue(displayValue.copy());
|
|
372
|
-
}
|
|
373
|
-
} else if (!validSegments[part]) {
|
|
374
|
-
markValid(part);
|
|
774
|
+
// Confirm the placeholder if only the day period is not filled in.
|
|
775
|
+
let validKeys = Object.keys(validSegments);
|
|
776
|
+
let allKeys = Object.keys(allSegments);
|
|
777
|
+
if (validKeys.length === allKeys.length - 1 && allSegments.dayPeriod && !validSegments.dayPeriod) {
|
|
778
|
+
validSegments = {
|
|
779
|
+
...allSegments
|
|
780
|
+
};
|
|
781
|
+
setValidSegments(validSegments);
|
|
375
782
|
setValue(displayValue.copy());
|
|
376
783
|
}
|
|
377
784
|
},
|
|
@@ -506,6 +913,7 @@ function $3c0fc76039f1c516$var$setSegment(value, part, segmentValue, options) {
|
|
|
506
913
|
case 'day':
|
|
507
914
|
case 'month':
|
|
508
915
|
case 'year':
|
|
916
|
+
case 'era':
|
|
509
917
|
return value.set({
|
|
510
918
|
[part]: segmentValue
|
|
511
919
|
});
|
|
@@ -539,16 +947,14 @@ function $3c0fc76039f1c516$var$setSegment(value, part, segmentValue, options) {
|
|
|
539
947
|
}
|
|
540
948
|
|
|
541
949
|
|
|
542
|
-
var $93c38a5e28be6249$exports = {};
|
|
543
950
|
|
|
544
|
-
$parcel$export($93c38a5e28be6249$exports, "useDateRangePickerState", () => $93c38a5e28be6249$export$e50a61c1de9f574);
|
|
545
951
|
|
|
546
952
|
|
|
547
953
|
|
|
548
954
|
|
|
549
955
|
function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
|
|
550
956
|
var ref, ref1;
|
|
551
|
-
let
|
|
957
|
+
let overlayState = $7UzoM$useOverlayTriggerState(props);
|
|
552
958
|
let [controlledValue, setControlledValue] = $7UzoM$useControlledState(props.value, props.defaultValue || null, props.onChange);
|
|
553
959
|
let [placeholderValue, setPlaceholderValue] = $7UzoM$useState(()=>controlledValue || {
|
|
554
960
|
start: null,
|
|
@@ -564,16 +970,13 @@ function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
|
|
|
564
970
|
setPlaceholderValue(placeholderValue);
|
|
565
971
|
}
|
|
566
972
|
let value1 = controlledValue || placeholderValue;
|
|
567
|
-
let valueRef = $7UzoM$useRef(value1);
|
|
568
|
-
valueRef.current = value1;
|
|
569
973
|
let setValue = (value)=>{
|
|
570
|
-
valueRef.current = value;
|
|
571
974
|
setPlaceholderValue(value);
|
|
572
975
|
if ((value === null || value === void 0 ? void 0 : value.start) && value.end) setControlledValue(value);
|
|
573
976
|
else setControlledValue(null);
|
|
574
977
|
};
|
|
575
978
|
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
|
|
979
|
+
let [granularity] = $35a22f14a1f04b11$export$2440da353cedad43(v, props.granularity);
|
|
577
980
|
let hasTime = granularity === 'hour' || granularity === 'minute' || granularity === 'second' || granularity === 'millisecond';
|
|
578
981
|
var _shouldCloseOnSelect;
|
|
579
982
|
let shouldCloseOnSelect = (_shouldCloseOnSelect = props.shouldCloseOnSelect) !== null && _shouldCloseOnSelect !== void 0 ? _shouldCloseOnSelect : true;
|
|
@@ -600,7 +1003,7 @@ function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
|
|
|
600
1003
|
else setSelectedDateRange(range);
|
|
601
1004
|
} else if (range.start && range.end) setValue(range);
|
|
602
1005
|
else setSelectedDateRange(range);
|
|
603
|
-
if (shouldClose) setOpen(false);
|
|
1006
|
+
if (shouldClose) overlayState.setOpen(false);
|
|
604
1007
|
};
|
|
605
1008
|
let setTimeRange = (range)=>{
|
|
606
1009
|
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);
|
|
@@ -634,7 +1037,7 @@ function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
|
|
|
634
1037
|
},
|
|
635
1038
|
setDateRange: setDateRange,
|
|
636
1039
|
setTimeRange: setTimeRange,
|
|
637
|
-
isOpen:
|
|
1040
|
+
isOpen: overlayState.isOpen,
|
|
638
1041
|
setOpen (isOpen) {
|
|
639
1042
|
// Commit the selected date range when the calendar is closed. Use a placeholder time if one wasn't set.
|
|
640
1043
|
// If only the time range was set and not the date range, don't commit. The state will be preserved until
|
|
@@ -643,11 +1046,11 @@ function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
|
|
|
643
1046
|
start: (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.start) || $35a22f14a1f04b11$export$c5221a78ef73c5e9(props.placeholderValue),
|
|
644
1047
|
end: (timeRange1 === null || timeRange1 === void 0 ? void 0 : timeRange1.end) || $35a22f14a1f04b11$export$c5221a78ef73c5e9(props.placeholderValue)
|
|
645
1048
|
});
|
|
646
|
-
setOpen(isOpen);
|
|
1049
|
+
overlayState.setOpen(isOpen);
|
|
647
1050
|
},
|
|
648
1051
|
validationState: validationState,
|
|
649
1052
|
formatValue (locale, fieldOptions) {
|
|
650
|
-
if (!value1 || !value1.start || !value1.end) return
|
|
1053
|
+
if (!value1 || !value1.start || !value1.end) return null;
|
|
651
1054
|
let startTimeZone = 'timeZone' in value1.start ? value1.start.timeZone : undefined;
|
|
652
1055
|
let startGranularity = props.granularity || (value1.start && 'minute' in value1.start ? 'minute' : 'day');
|
|
653
1056
|
let endTimeZone = 'timeZone' in value1.end ? value1.end.timeZone : undefined;
|
|
@@ -656,16 +1059,38 @@ function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
|
|
|
656
1059
|
granularity: startGranularity,
|
|
657
1060
|
timeZone: startTimeZone,
|
|
658
1061
|
hideTimeZone: props.hideTimeZone,
|
|
659
|
-
hourCycle: props.hourCycle
|
|
1062
|
+
hourCycle: props.hourCycle,
|
|
1063
|
+
showEra: value1.start.calendar.identifier === 'gregory' && value1.start.era === 'BC' || value1.end.calendar.identifier === 'gregory' && value1.end.era === 'BC'
|
|
660
1064
|
});
|
|
1065
|
+
let startDate = value1.start.toDate(startTimeZone || 'UTC');
|
|
1066
|
+
let endDate = value1.end.toDate(endTimeZone || 'UTC');
|
|
661
1067
|
let startFormatter = new $7UzoM$DateFormatter(locale, startOptions);
|
|
662
1068
|
let endFormatter;
|
|
663
|
-
if (startTimeZone === endTimeZone && startGranularity === endGranularity) {
|
|
1069
|
+
if (startTimeZone === endTimeZone && startGranularity === endGranularity && value1.start.compare(value1.end) !== 0) {
|
|
664
1070
|
// Use formatRange, as it results in shorter output when some of the fields
|
|
665
1071
|
// are shared between the start and end dates (e.g. the same month).
|
|
666
1072
|
// Formatting will fail if the end date is before the start date. Fall back below when that happens.
|
|
667
1073
|
try {
|
|
668
|
-
|
|
1074
|
+
let parts = startFormatter.formatRangeToParts(startDate, endDate);
|
|
1075
|
+
// Find the separator between the start and end date. This is determined
|
|
1076
|
+
// by finding the last shared literal before the end range.
|
|
1077
|
+
let separatorIndex = -1;
|
|
1078
|
+
for(let i = 0; i < parts.length; i++){
|
|
1079
|
+
let part = parts[i];
|
|
1080
|
+
if (part.source === 'shared' && part.type === 'literal') separatorIndex = i;
|
|
1081
|
+
else if (part.source === 'endRange') break;
|
|
1082
|
+
}
|
|
1083
|
+
// Now we can combine the parts into start and end strings.
|
|
1084
|
+
let start = '';
|
|
1085
|
+
let end = '';
|
|
1086
|
+
for(let i1 = 0; i1 < parts.length; i1++){
|
|
1087
|
+
if (i1 < separatorIndex) start += parts[i1].value;
|
|
1088
|
+
else if (i1 > separatorIndex) end += parts[i1].value;
|
|
1089
|
+
}
|
|
1090
|
+
return {
|
|
1091
|
+
start: start,
|
|
1092
|
+
end: end
|
|
1093
|
+
};
|
|
669
1094
|
} catch (e) {
|
|
670
1095
|
// ignore
|
|
671
1096
|
}
|
|
@@ -679,28 +1104,15 @@ function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
|
|
|
679
1104
|
});
|
|
680
1105
|
endFormatter = new $7UzoM$DateFormatter(locale, endOptions);
|
|
681
1106
|
}
|
|
682
|
-
return
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
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
|
-
}
|
|
1107
|
+
return {
|
|
1108
|
+
start: startFormatter.format(startDate),
|
|
1109
|
+
end: endFormatter.format(endDate)
|
|
1110
|
+
};
|
|
696
1111
|
}
|
|
697
1112
|
};
|
|
698
1113
|
}
|
|
699
1114
|
|
|
700
1115
|
|
|
701
|
-
var $eff5d8ee529ac4bb$exports = {};
|
|
702
|
-
|
|
703
|
-
$parcel$export($eff5d8ee529ac4bb$exports, "useTimeFieldState", () => $eff5d8ee529ac4bb$export$fd53cef0cc796101);
|
|
704
1116
|
|
|
705
1117
|
|
|
706
1118
|
|