@react-stately/datepicker 3.0.0-rc.0 → 3.0.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 +460 -62
- package/dist/main.js.map +1 -1
- package/dist/module.js +460 -62
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +7 -7
- package/dist/types.d.ts.map +1 -1
- package/package.json +9 -8
- package/src/placeholders.ts +108 -0
- package/src/useDateFieldState.ts +66 -43
- package/src/useDatePickerState.ts +2 -1
- package/src/useDateRangePickerState.ts +7 -23
- package/src/utils.ts +6 -1
package/dist/main.js
CHANGED
|
@@ -2,6 +2,7 @@ var $h2qOe$internationalizeddate = require("@internationalized/date");
|
|
|
2
2
|
var $h2qOe$reactstatelyutils = require("@react-stately/utils");
|
|
3
3
|
var $h2qOe$reactstatelyoverlays = require("@react-stately/overlays");
|
|
4
4
|
var $h2qOe$react = require("react");
|
|
5
|
+
var $h2qOe$internationalizedstring = require("@internationalized/string");
|
|
5
6
|
|
|
6
7
|
function $parcel$export(e, n, v, s) {
|
|
7
8
|
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
@@ -47,6 +48,7 @@ function $50d5d6a623389320$export$7e319ea407e63bc0(fieldOptions, options) {
|
|
|
47
48
|
opts1.timeZone = options.timeZone || 'UTC';
|
|
48
49
|
let hasTime = granularity === 'hour' || granularity === 'minute' || granularity === 'second';
|
|
49
50
|
if (hasTime && options.timeZone && !options.hideTimeZone) opts1.timeZoneName = 'short';
|
|
51
|
+
if (options.showEra && startIdx === 0) opts1.era = 'short';
|
|
50
52
|
return opts1;
|
|
51
53
|
}
|
|
52
54
|
function $50d5d6a623389320$export$c5221a78ef73c5e9(placeholderValue) {
|
|
@@ -149,7 +151,8 @@ function $aaab7a647e17e1fd$export$87194bb378cc3ac2(props) {
|
|
|
149
151
|
granularity: granularity,
|
|
150
152
|
timeZone: defaultTimeZone,
|
|
151
153
|
hideTimeZone: props.hideTimeZone,
|
|
152
|
-
hourCycle: props.hourCycle
|
|
154
|
+
hourCycle: props.hourCycle,
|
|
155
|
+
showEra: value.calendar.identifier === 'gregory' && value.era === 'BC'
|
|
153
156
|
});
|
|
154
157
|
let formatter = new $h2qOe$internationalizeddate.DateFormatter(locale, formatOptions);
|
|
155
158
|
return formatter.format(dateValue);
|
|
@@ -161,6 +164,396 @@ function $aaab7a647e17e1fd$export$87194bb378cc3ac2(props) {
|
|
|
161
164
|
|
|
162
165
|
|
|
163
166
|
|
|
167
|
+
// These placeholders are based on the strings used by the <input type="date">
|
|
168
|
+
// implementations in Chrome and Firefox. Additional languages are supported
|
|
169
|
+
// here than React Spectrum's typical translations.
|
|
170
|
+
const $e1e8ada727fae1a1$var$placeholders = new $h2qOe$internationalizedstring.LocalizedStringDictionary({
|
|
171
|
+
ach: {
|
|
172
|
+
year: 'mwaka',
|
|
173
|
+
month: 'dwe',
|
|
174
|
+
day: 'nino'
|
|
175
|
+
},
|
|
176
|
+
af: {
|
|
177
|
+
year: 'jjjj',
|
|
178
|
+
month: 'mm',
|
|
179
|
+
day: 'dd'
|
|
180
|
+
},
|
|
181
|
+
am: {
|
|
182
|
+
year: 'ዓዓዓዓ',
|
|
183
|
+
month: 'ሚሜ',
|
|
184
|
+
day: 'ቀቀ'
|
|
185
|
+
},
|
|
186
|
+
an: {
|
|
187
|
+
year: 'aaaa',
|
|
188
|
+
month: 'mm',
|
|
189
|
+
day: 'dd'
|
|
190
|
+
},
|
|
191
|
+
ar: {
|
|
192
|
+
year: 'سنة',
|
|
193
|
+
month: 'شهر',
|
|
194
|
+
day: 'يوم'
|
|
195
|
+
},
|
|
196
|
+
ast: {
|
|
197
|
+
year: 'aaaa',
|
|
198
|
+
month: 'mm',
|
|
199
|
+
day: 'dd'
|
|
200
|
+
},
|
|
201
|
+
az: {
|
|
202
|
+
year: 'iiii',
|
|
203
|
+
month: 'aa',
|
|
204
|
+
day: 'gg'
|
|
205
|
+
},
|
|
206
|
+
be: {
|
|
207
|
+
year: 'гггг',
|
|
208
|
+
month: 'мм',
|
|
209
|
+
day: 'дд'
|
|
210
|
+
},
|
|
211
|
+
bg: {
|
|
212
|
+
year: 'гггг',
|
|
213
|
+
month: 'мм',
|
|
214
|
+
day: 'дд'
|
|
215
|
+
},
|
|
216
|
+
bn: {
|
|
217
|
+
year: 'yyyy',
|
|
218
|
+
month: 'মিমি',
|
|
219
|
+
day: 'dd'
|
|
220
|
+
},
|
|
221
|
+
br: {
|
|
222
|
+
year: 'bbbb',
|
|
223
|
+
month: 'mm',
|
|
224
|
+
day: 'dd'
|
|
225
|
+
},
|
|
226
|
+
bs: {
|
|
227
|
+
year: 'gggg',
|
|
228
|
+
month: 'mm',
|
|
229
|
+
day: 'dd'
|
|
230
|
+
},
|
|
231
|
+
ca: {
|
|
232
|
+
year: 'aaaa',
|
|
233
|
+
month: 'mm',
|
|
234
|
+
day: 'dd'
|
|
235
|
+
},
|
|
236
|
+
cak: {
|
|
237
|
+
year: 'jjjj',
|
|
238
|
+
month: 'ii',
|
|
239
|
+
day: "q'q'"
|
|
240
|
+
},
|
|
241
|
+
ckb: {
|
|
242
|
+
year: 'ساڵ',
|
|
243
|
+
month: 'مانگ',
|
|
244
|
+
day: 'ڕۆژ'
|
|
245
|
+
},
|
|
246
|
+
cs: {
|
|
247
|
+
year: 'rrrr',
|
|
248
|
+
month: 'mm',
|
|
249
|
+
day: 'dd'
|
|
250
|
+
},
|
|
251
|
+
cy: {
|
|
252
|
+
year: 'bbbb',
|
|
253
|
+
month: 'mm',
|
|
254
|
+
day: 'dd'
|
|
255
|
+
},
|
|
256
|
+
da: {
|
|
257
|
+
year: 'åååå',
|
|
258
|
+
month: 'mm',
|
|
259
|
+
day: 'dd'
|
|
260
|
+
},
|
|
261
|
+
de: {
|
|
262
|
+
year: 'jjjj',
|
|
263
|
+
month: 'mm',
|
|
264
|
+
day: 'tt'
|
|
265
|
+
},
|
|
266
|
+
dsb: {
|
|
267
|
+
year: 'llll',
|
|
268
|
+
month: 'mm',
|
|
269
|
+
day: 'źź'
|
|
270
|
+
},
|
|
271
|
+
el: {
|
|
272
|
+
year: 'εεεε',
|
|
273
|
+
month: 'μμ',
|
|
274
|
+
day: 'ηη'
|
|
275
|
+
},
|
|
276
|
+
en: {
|
|
277
|
+
year: 'yyyy',
|
|
278
|
+
month: 'mm',
|
|
279
|
+
day: 'dd'
|
|
280
|
+
},
|
|
281
|
+
eo: {
|
|
282
|
+
year: 'jjjj',
|
|
283
|
+
month: 'mm',
|
|
284
|
+
day: 'tt'
|
|
285
|
+
},
|
|
286
|
+
es: {
|
|
287
|
+
year: 'aaaa',
|
|
288
|
+
month: 'mm',
|
|
289
|
+
day: 'dd'
|
|
290
|
+
},
|
|
291
|
+
et: {
|
|
292
|
+
year: 'aaaa',
|
|
293
|
+
month: 'kk',
|
|
294
|
+
day: 'pp'
|
|
295
|
+
},
|
|
296
|
+
eu: {
|
|
297
|
+
year: 'uuuu',
|
|
298
|
+
month: 'hh',
|
|
299
|
+
day: 'ee'
|
|
300
|
+
},
|
|
301
|
+
fa: {
|
|
302
|
+
year: 'سال',
|
|
303
|
+
month: 'ماه',
|
|
304
|
+
day: 'روز'
|
|
305
|
+
},
|
|
306
|
+
ff: {
|
|
307
|
+
year: 'hhhh',
|
|
308
|
+
month: 'll',
|
|
309
|
+
day: 'ññ'
|
|
310
|
+
},
|
|
311
|
+
fi: {
|
|
312
|
+
year: 'vvvv',
|
|
313
|
+
month: 'kk',
|
|
314
|
+
day: 'pp'
|
|
315
|
+
},
|
|
316
|
+
fr: {
|
|
317
|
+
year: 'aaaa',
|
|
318
|
+
month: 'mm',
|
|
319
|
+
day: 'jj'
|
|
320
|
+
},
|
|
321
|
+
fy: {
|
|
322
|
+
year: 'jjjj',
|
|
323
|
+
month: 'mm',
|
|
324
|
+
day: 'dd'
|
|
325
|
+
},
|
|
326
|
+
ga: {
|
|
327
|
+
year: 'bbbb',
|
|
328
|
+
month: 'mm',
|
|
329
|
+
day: 'll'
|
|
330
|
+
},
|
|
331
|
+
gd: {
|
|
332
|
+
year: 'bbbb',
|
|
333
|
+
month: 'mm',
|
|
334
|
+
day: 'll'
|
|
335
|
+
},
|
|
336
|
+
gl: {
|
|
337
|
+
year: 'aaaa',
|
|
338
|
+
month: 'mm',
|
|
339
|
+
day: 'dd'
|
|
340
|
+
},
|
|
341
|
+
he: {
|
|
342
|
+
year: 'שנה',
|
|
343
|
+
month: 'חודש',
|
|
344
|
+
day: 'יום'
|
|
345
|
+
},
|
|
346
|
+
hr: {
|
|
347
|
+
year: 'gggg',
|
|
348
|
+
month: 'mm',
|
|
349
|
+
day: 'dd'
|
|
350
|
+
},
|
|
351
|
+
hsb: {
|
|
352
|
+
year: 'llll',
|
|
353
|
+
month: 'mm',
|
|
354
|
+
day: 'dd'
|
|
355
|
+
},
|
|
356
|
+
hu: {
|
|
357
|
+
year: 'éééé',
|
|
358
|
+
month: 'hh',
|
|
359
|
+
day: 'nn'
|
|
360
|
+
},
|
|
361
|
+
ia: {
|
|
362
|
+
year: 'aaaa',
|
|
363
|
+
month: 'mm',
|
|
364
|
+
day: 'dd'
|
|
365
|
+
},
|
|
366
|
+
id: {
|
|
367
|
+
year: 'tttt',
|
|
368
|
+
month: 'bb',
|
|
369
|
+
day: 'hh'
|
|
370
|
+
},
|
|
371
|
+
it: {
|
|
372
|
+
year: 'aaaa',
|
|
373
|
+
month: 'mm',
|
|
374
|
+
day: 'gg'
|
|
375
|
+
},
|
|
376
|
+
ja: {
|
|
377
|
+
year: ' 年 ',
|
|
378
|
+
month: '月',
|
|
379
|
+
day: '日'
|
|
380
|
+
},
|
|
381
|
+
ka: {
|
|
382
|
+
year: 'წწწწ',
|
|
383
|
+
month: 'თთ',
|
|
384
|
+
day: 'რრ'
|
|
385
|
+
},
|
|
386
|
+
kk: {
|
|
387
|
+
year: 'жжжж',
|
|
388
|
+
month: 'аа',
|
|
389
|
+
day: 'кк'
|
|
390
|
+
},
|
|
391
|
+
kn: {
|
|
392
|
+
year: 'ವವವವ',
|
|
393
|
+
month: 'ಮಿಮೀ',
|
|
394
|
+
day: 'ದಿದಿ'
|
|
395
|
+
},
|
|
396
|
+
ko: {
|
|
397
|
+
year: '연도',
|
|
398
|
+
month: '월',
|
|
399
|
+
day: '일'
|
|
400
|
+
},
|
|
401
|
+
lb: {
|
|
402
|
+
year: 'jjjj',
|
|
403
|
+
month: 'mm',
|
|
404
|
+
day: 'dd'
|
|
405
|
+
},
|
|
406
|
+
lo: {
|
|
407
|
+
year: 'ປປປປ',
|
|
408
|
+
month: 'ດດ',
|
|
409
|
+
day: 'ວວ'
|
|
410
|
+
},
|
|
411
|
+
lt: {
|
|
412
|
+
year: 'mmmm',
|
|
413
|
+
month: 'mm',
|
|
414
|
+
day: 'dd'
|
|
415
|
+
},
|
|
416
|
+
lv: {
|
|
417
|
+
year: 'gggg',
|
|
418
|
+
month: 'mm',
|
|
419
|
+
day: 'dd'
|
|
420
|
+
},
|
|
421
|
+
meh: {
|
|
422
|
+
year: 'aaaa',
|
|
423
|
+
month: 'mm',
|
|
424
|
+
day: 'dd'
|
|
425
|
+
},
|
|
426
|
+
ml: {
|
|
427
|
+
year: 'വർഷം',
|
|
428
|
+
month: 'മാസം',
|
|
429
|
+
day: 'തീയതി'
|
|
430
|
+
},
|
|
431
|
+
ms: {
|
|
432
|
+
year: 'tttt',
|
|
433
|
+
month: 'mm',
|
|
434
|
+
day: 'hh'
|
|
435
|
+
},
|
|
436
|
+
nl: {
|
|
437
|
+
year: 'jjjj',
|
|
438
|
+
month: 'mm',
|
|
439
|
+
day: 'dd'
|
|
440
|
+
},
|
|
441
|
+
nn: {
|
|
442
|
+
year: 'åååå',
|
|
443
|
+
month: 'mm',
|
|
444
|
+
day: 'dd'
|
|
445
|
+
},
|
|
446
|
+
no: {
|
|
447
|
+
year: 'åååå',
|
|
448
|
+
month: 'mm',
|
|
449
|
+
day: 'dd'
|
|
450
|
+
},
|
|
451
|
+
oc: {
|
|
452
|
+
year: 'aaaa',
|
|
453
|
+
month: 'mm',
|
|
454
|
+
day: 'jj'
|
|
455
|
+
},
|
|
456
|
+
pl: {
|
|
457
|
+
year: 'rrrr',
|
|
458
|
+
month: 'mm',
|
|
459
|
+
day: 'dd'
|
|
460
|
+
},
|
|
461
|
+
pt: {
|
|
462
|
+
year: 'aaaa',
|
|
463
|
+
month: 'mm',
|
|
464
|
+
day: 'dd'
|
|
465
|
+
},
|
|
466
|
+
rm: {
|
|
467
|
+
year: 'oooo',
|
|
468
|
+
month: 'mm',
|
|
469
|
+
day: 'dd'
|
|
470
|
+
},
|
|
471
|
+
ro: {
|
|
472
|
+
year: 'aaaa',
|
|
473
|
+
month: 'll',
|
|
474
|
+
day: 'zz'
|
|
475
|
+
},
|
|
476
|
+
ru: {
|
|
477
|
+
year: 'гггг',
|
|
478
|
+
month: 'мм',
|
|
479
|
+
day: 'дд'
|
|
480
|
+
},
|
|
481
|
+
sc: {
|
|
482
|
+
year: 'aaaa',
|
|
483
|
+
month: 'mm',
|
|
484
|
+
day: 'dd'
|
|
485
|
+
},
|
|
486
|
+
scn: {
|
|
487
|
+
year: 'aaaa',
|
|
488
|
+
month: 'mm',
|
|
489
|
+
day: 'jj'
|
|
490
|
+
},
|
|
491
|
+
sk: {
|
|
492
|
+
year: 'rrrr',
|
|
493
|
+
month: 'mm',
|
|
494
|
+
day: 'dd'
|
|
495
|
+
},
|
|
496
|
+
sl: {
|
|
497
|
+
year: 'llll',
|
|
498
|
+
month: 'mm',
|
|
499
|
+
day: 'dd'
|
|
500
|
+
},
|
|
501
|
+
sr: {
|
|
502
|
+
year: 'гггг',
|
|
503
|
+
month: 'мм',
|
|
504
|
+
day: 'дд'
|
|
505
|
+
},
|
|
506
|
+
sv: {
|
|
507
|
+
year: 'åååå',
|
|
508
|
+
month: 'mm',
|
|
509
|
+
day: 'dd'
|
|
510
|
+
},
|
|
511
|
+
szl: {
|
|
512
|
+
year: 'rrrr',
|
|
513
|
+
month: 'mm',
|
|
514
|
+
day: 'dd'
|
|
515
|
+
},
|
|
516
|
+
tg: {
|
|
517
|
+
year: 'сссс',
|
|
518
|
+
month: 'мм',
|
|
519
|
+
day: 'рр'
|
|
520
|
+
},
|
|
521
|
+
th: {
|
|
522
|
+
year: 'ปปปป',
|
|
523
|
+
month: 'ดด',
|
|
524
|
+
day: 'วว'
|
|
525
|
+
},
|
|
526
|
+
tr: {
|
|
527
|
+
year: 'yyyy',
|
|
528
|
+
month: 'aa',
|
|
529
|
+
day: 'gg'
|
|
530
|
+
},
|
|
531
|
+
uk: {
|
|
532
|
+
year: 'рррр',
|
|
533
|
+
month: 'мм',
|
|
534
|
+
day: 'дд'
|
|
535
|
+
},
|
|
536
|
+
'zh-CN': {
|
|
537
|
+
year: '年',
|
|
538
|
+
month: '月',
|
|
539
|
+
day: '日'
|
|
540
|
+
},
|
|
541
|
+
'zh-TW': {
|
|
542
|
+
year: '年',
|
|
543
|
+
month: '月',
|
|
544
|
+
day: '日'
|
|
545
|
+
}
|
|
546
|
+
}, 'en');
|
|
547
|
+
function $e1e8ada727fae1a1$export$d3f5c5e0a5023fa0(field, value, locale) {
|
|
548
|
+
// Use the actual placeholder value for the era and day period fields.
|
|
549
|
+
if (field === 'era' || field === 'dayPeriod') return value;
|
|
550
|
+
if (field === 'year' || field === 'month' || field === 'day') return $e1e8ada727fae1a1$var$placeholders.getStringForLocale(field, locale);
|
|
551
|
+
// For time fields (e.g. hour, minute, etc.), use two dashes as the placeholder.
|
|
552
|
+
return '––';
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
|
|
164
557
|
|
|
165
558
|
const $596a1f0f523d6752$var$EDITABLE_SEGMENTS = {
|
|
166
559
|
year: true,
|
|
@@ -191,20 +584,45 @@ function $596a1f0f523d6752$export$60e84778edff6d26(props) {
|
|
|
191
584
|
let timeZone = defaultTimeZone || 'UTC';
|
|
192
585
|
// props.granularity must actually exist in the value if one is provided.
|
|
193
586
|
if (v1 && !(granularity in v1)) throw new Error('Invalid granularity ' + granularity + ' for value ' + v1.toString());
|
|
587
|
+
let defaultFormatter = $h2qOe$react.useMemo(()=>new $h2qOe$internationalizeddate.DateFormatter(locale)
|
|
588
|
+
, [
|
|
589
|
+
locale
|
|
590
|
+
]);
|
|
591
|
+
let calendar = $h2qOe$react.useMemo(()=>createCalendar(defaultFormatter.resolvedOptions().calendar)
|
|
592
|
+
, [
|
|
593
|
+
createCalendar,
|
|
594
|
+
defaultFormatter
|
|
595
|
+
]);
|
|
596
|
+
let [value1, setDate] = $h2qOe$reactstatelyutils.useControlledState(props.value, props.defaultValue, props.onChange);
|
|
597
|
+
let calendarValue = $h2qOe$react.useMemo(()=>$50d5d6a623389320$export$61a490a80c552550(value1, calendar)
|
|
598
|
+
, [
|
|
599
|
+
value1,
|
|
600
|
+
calendar
|
|
601
|
+
]);
|
|
602
|
+
// We keep track of the placeholder date separately in state so that onChange is not called
|
|
603
|
+
// until all segments are set. If the value === null (not undefined), then assume the component
|
|
604
|
+
// is controlled, so use the placeholder as the value until all segments are entered so it doesn't
|
|
605
|
+
// change from uncontrolled to controlled and emit a warning.
|
|
606
|
+
let [placeholderDate, setPlaceholderDate] = $h2qOe$react.useState(()=>$50d5d6a623389320$export$66aa2b09de4b1ea5(props.placeholderValue, granularity, calendar, defaultTimeZone)
|
|
607
|
+
);
|
|
608
|
+
let val = calendarValue || placeholderDate;
|
|
609
|
+
let showEra = calendar.identifier === 'gregory' && val.era === 'BC';
|
|
194
610
|
var _maxGranularity;
|
|
195
611
|
let formatOpts = $h2qOe$react.useMemo(()=>({
|
|
196
612
|
granularity: granularity,
|
|
197
613
|
maxGranularity: (_maxGranularity = props.maxGranularity) !== null && _maxGranularity !== void 0 ? _maxGranularity : 'year',
|
|
198
614
|
timeZone: defaultTimeZone,
|
|
199
615
|
hideTimeZone: hideTimeZone,
|
|
200
|
-
hourCycle: props.hourCycle
|
|
616
|
+
hourCycle: props.hourCycle,
|
|
617
|
+
showEra: showEra
|
|
201
618
|
})
|
|
202
619
|
, [
|
|
203
620
|
props.maxGranularity,
|
|
204
621
|
granularity,
|
|
205
622
|
props.hourCycle,
|
|
206
623
|
defaultTimeZone,
|
|
207
|
-
hideTimeZone
|
|
624
|
+
hideTimeZone,
|
|
625
|
+
showEra
|
|
208
626
|
]);
|
|
209
627
|
let opts = $h2qOe$react.useMemo(()=>$50d5d6a623389320$export$7e319ea407e63bc0({
|
|
210
628
|
}, formatOpts)
|
|
@@ -220,11 +638,6 @@ function $596a1f0f523d6752$export$60e84778edff6d26(props) {
|
|
|
220
638
|
, [
|
|
221
639
|
dateFormatter
|
|
222
640
|
]);
|
|
223
|
-
let calendar = $h2qOe$react.useMemo(()=>createCalendar(resolvedOptions.calendar)
|
|
224
|
-
, [
|
|
225
|
-
createCalendar,
|
|
226
|
-
resolvedOptions.calendar
|
|
227
|
-
]);
|
|
228
641
|
// Determine how many editable segments there are for validation purposes.
|
|
229
642
|
// The result is cached for performance.
|
|
230
643
|
let allSegments = $h2qOe$react.useMemo(()=>dateFormatter.formatToParts(new Date()).filter((seg)=>$596a1f0f523d6752$var$EDITABLE_SEGMENTS[seg.type]
|
|
@@ -239,12 +652,6 @@ function $596a1f0f523d6752$export$60e84778edff6d26(props) {
|
|
|
239
652
|
} : {
|
|
240
653
|
}
|
|
241
654
|
);
|
|
242
|
-
// We keep track of the placeholder date separately in state so that onChange is not called
|
|
243
|
-
// until all segments are set. If the value === null (not undefined), then assume the component
|
|
244
|
-
// is controlled, so use the placeholder as the value until all segments are entered so it doesn't
|
|
245
|
-
// change from uncontrolled to controlled and emit a warning.
|
|
246
|
-
let [placeholderDate, setPlaceholderDate] = $h2qOe$react.useState(()=>$50d5d6a623389320$export$66aa2b09de4b1ea5(props.placeholderValue, granularity, calendar, defaultTimeZone)
|
|
247
|
-
);
|
|
248
655
|
// Reset placeholder when calendar changes
|
|
249
656
|
let lastCalendarIdentifier = $h2qOe$react.useRef(calendar.identifier);
|
|
250
657
|
$h2qOe$react.useEffect(()=>{
|
|
@@ -260,12 +667,6 @@ function $596a1f0f523d6752$export$60e84778edff6d26(props) {
|
|
|
260
667
|
defaultTimeZone,
|
|
261
668
|
props.placeholderValue
|
|
262
669
|
]);
|
|
263
|
-
let [value1, setDate] = $h2qOe$reactstatelyutils.useControlledState(props.value, props.defaultValue, props.onChange);
|
|
264
|
-
let calendarValue = $h2qOe$react.useMemo(()=>$50d5d6a623389320$export$61a490a80c552550(value1, calendar)
|
|
265
|
-
, [
|
|
266
|
-
value1,
|
|
267
|
-
calendar
|
|
268
|
-
]);
|
|
269
670
|
// If there is a value prop, and some segments were previously placeholders, mark them all as valid.
|
|
270
671
|
if (value1 && Object.keys(validSegments).length < Object.keys(allSegments).length) {
|
|
271
672
|
validSegments = {
|
|
@@ -299,11 +700,14 @@ function $596a1f0f523d6752$export$60e84778edff6d26(props) {
|
|
|
299
700
|
let segments = $h2qOe$react.useMemo(()=>dateFormatter.formatToParts(dateValue).map((segment)=>{
|
|
300
701
|
let isEditable = $596a1f0f523d6752$var$EDITABLE_SEGMENTS[segment.type];
|
|
301
702
|
if (segment.type === 'era' && calendar.getEras().length === 1) isEditable = false;
|
|
703
|
+
let isPlaceholder = $596a1f0f523d6752$var$EDITABLE_SEGMENTS[segment.type] && !validSegments[segment.type];
|
|
704
|
+
let placeholder = $596a1f0f523d6752$var$EDITABLE_SEGMENTS[segment.type] ? $e1e8ada727fae1a1$export$d3f5c5e0a5023fa0(segment.type, segment.value, locale) : null;
|
|
302
705
|
return {
|
|
303
706
|
type: $596a1f0f523d6752$var$TYPE_MAPPING[segment.type] || segment.type,
|
|
304
|
-
text: segment.value,
|
|
707
|
+
text: isPlaceholder ? placeholder : segment.value,
|
|
305
708
|
...$596a1f0f523d6752$var$getSegmentLimits(displayValue, segment.type, resolvedOptions),
|
|
306
|
-
isPlaceholder:
|
|
709
|
+
isPlaceholder: isPlaceholder,
|
|
710
|
+
placeholder: placeholder,
|
|
307
711
|
isEditable: isEditable
|
|
308
712
|
};
|
|
309
713
|
})
|
|
@@ -313,29 +717,41 @@ function $596a1f0f523d6752$export$60e84778edff6d26(props) {
|
|
|
313
717
|
dateFormatter,
|
|
314
718
|
resolvedOptions,
|
|
315
719
|
displayValue,
|
|
316
|
-
calendar
|
|
317
|
-
|
|
318
|
-
let hasEra = $h2qOe$react.useMemo(()=>segments.some((s)=>s.type === 'era'
|
|
319
|
-
)
|
|
320
|
-
, [
|
|
321
|
-
segments
|
|
720
|
+
calendar,
|
|
721
|
+
locale
|
|
322
722
|
]);
|
|
723
|
+
// When the era field appears, mark it valid if the year field is already valid.
|
|
724
|
+
// If the era field disappears, remove it from the valid segments.
|
|
725
|
+
if (allSegments.era && validSegments.year && !validSegments.era) {
|
|
726
|
+
validSegments.era = true;
|
|
727
|
+
setValidSegments({
|
|
728
|
+
...validSegments
|
|
729
|
+
});
|
|
730
|
+
} else if (!allSegments.era && validSegments.era) {
|
|
731
|
+
delete validSegments.era;
|
|
732
|
+
setValidSegments({
|
|
733
|
+
...validSegments
|
|
734
|
+
});
|
|
735
|
+
}
|
|
323
736
|
let markValid = (part)=>{
|
|
324
737
|
validSegments[part] = true;
|
|
325
|
-
if (part === 'year' &&
|
|
738
|
+
if (part === 'year' && allSegments.era) validSegments.era = true;
|
|
326
739
|
setValidSegments({
|
|
327
740
|
...validSegments
|
|
328
741
|
});
|
|
329
742
|
};
|
|
330
743
|
let adjustSegment = (type, amount)=>{
|
|
331
|
-
|
|
332
|
-
|
|
744
|
+
if (!validSegments[type]) {
|
|
745
|
+
markValid(type);
|
|
746
|
+
if (Object.keys(validSegments).length >= Object.keys(allSegments).length) setValue(displayValue);
|
|
747
|
+
} else setValue($596a1f0f523d6752$var$addSegment(displayValue, type, amount, resolvedOptions));
|
|
333
748
|
};
|
|
334
749
|
let validationState = props.validationState || ($50d5d6a623389320$export$eac50920cf2fd59a(calendarValue, props.minValue, props.maxValue) ? 'invalid' : null);
|
|
335
750
|
var _maxGranularity1;
|
|
336
751
|
return {
|
|
337
752
|
value: calendarValue,
|
|
338
753
|
dateValue: dateValue,
|
|
754
|
+
calendar: calendar,
|
|
339
755
|
setValue: setValue,
|
|
340
756
|
segments: segments,
|
|
341
757
|
dateFormatter: dateFormatter,
|
|
@@ -361,20 +777,16 @@ function $596a1f0f523d6752$export$60e84778edff6d26(props) {
|
|
|
361
777
|
markValid(part);
|
|
362
778
|
setValue($596a1f0f523d6752$var$setSegment(displayValue, part, v, resolvedOptions));
|
|
363
779
|
},
|
|
364
|
-
confirmPlaceholder (
|
|
780
|
+
confirmPlaceholder () {
|
|
365
781
|
if (props.isDisabled || props.isReadOnly) return;
|
|
366
|
-
if
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
setValue(displayValue.copy());
|
|
375
|
-
}
|
|
376
|
-
} else if (!validSegments[part]) {
|
|
377
|
-
markValid(part);
|
|
782
|
+
// Confirm the placeholder if only the day period is not filled in.
|
|
783
|
+
let validKeys = Object.keys(validSegments);
|
|
784
|
+
let allKeys = Object.keys(allSegments);
|
|
785
|
+
if (validKeys.length === allKeys.length - 1 && allSegments.dayPeriod && !validSegments.dayPeriod) {
|
|
786
|
+
validSegments = {
|
|
787
|
+
...allSegments
|
|
788
|
+
};
|
|
789
|
+
setValidSegments(validSegments);
|
|
378
790
|
setValue(displayValue.copy());
|
|
379
791
|
}
|
|
380
792
|
},
|
|
@@ -509,6 +921,7 @@ function $596a1f0f523d6752$var$setSegment(value, part, segmentValue, options) {
|
|
|
509
921
|
case 'day':
|
|
510
922
|
case 'month':
|
|
511
923
|
case 'year':
|
|
924
|
+
case 'era':
|
|
512
925
|
return value.set({
|
|
513
926
|
[part]: segmentValue
|
|
514
927
|
});
|
|
@@ -565,16 +978,13 @@ function $7072d26f58deb33b$export$e50a61c1de9f574(props) {
|
|
|
565
978
|
setPlaceholderValue(placeholderValue);
|
|
566
979
|
}
|
|
567
980
|
let value1 = controlledValue || placeholderValue;
|
|
568
|
-
let valueRef = $h2qOe$react.useRef(value1);
|
|
569
|
-
valueRef.current = value1;
|
|
570
981
|
let setValue = (value)=>{
|
|
571
|
-
valueRef.current = value;
|
|
572
982
|
setPlaceholderValue(value);
|
|
573
983
|
if ((value === null || value === void 0 ? void 0 : value.start) && value.end) setControlledValue(value);
|
|
574
984
|
else setControlledValue(null);
|
|
575
985
|
};
|
|
576
986
|
let v = (value1 === null || value1 === void 0 ? void 0 : value1.start) || (value1 === null || value1 === void 0 ? void 0 : value1.end) || props.placeholderValue;
|
|
577
|
-
let [granularity
|
|
987
|
+
let [granularity] = $50d5d6a623389320$export$2440da353cedad43(v, props.granularity);
|
|
578
988
|
let hasTime = granularity === 'hour' || granularity === 'minute' || granularity === 'second' || granularity === 'millisecond';
|
|
579
989
|
var _shouldCloseOnSelect;
|
|
580
990
|
let shouldCloseOnSelect = (_shouldCloseOnSelect = props.shouldCloseOnSelect) !== null && _shouldCloseOnSelect !== void 0 ? _shouldCloseOnSelect : true;
|
|
@@ -657,7 +1067,8 @@ function $7072d26f58deb33b$export$e50a61c1de9f574(props) {
|
|
|
657
1067
|
granularity: startGranularity,
|
|
658
1068
|
timeZone: startTimeZone,
|
|
659
1069
|
hideTimeZone: props.hideTimeZone,
|
|
660
|
-
hourCycle: props.hourCycle
|
|
1070
|
+
hourCycle: props.hourCycle,
|
|
1071
|
+
showEra: value1.start.calendar.identifier === 'gregory' && value1.start.era === 'BC' || value1.end.calendar.identifier === 'gregory' && value1.end.era === 'BC'
|
|
661
1072
|
});
|
|
662
1073
|
let startDate = value1.start.toDate(startTimeZone || 'UTC');
|
|
663
1074
|
let endDate = value1.end.toDate(endTimeZone || 'UTC');
|
|
@@ -705,19 +1116,6 @@ function $7072d26f58deb33b$export$e50a61c1de9f574(props) {
|
|
|
705
1116
|
start: startFormatter.format(startDate),
|
|
706
1117
|
end: endFormatter.format(endDate)
|
|
707
1118
|
};
|
|
708
|
-
},
|
|
709
|
-
confirmPlaceholder () {
|
|
710
|
-
// Need to use ref value here because the value can be set in the same tick as
|
|
711
|
-
// a blur, which means the component won't have re-rendered yet.
|
|
712
|
-
let value = valueRef.current;
|
|
713
|
-
if (value && Boolean(value.start) !== Boolean(value.end)) {
|
|
714
|
-
let calendar = (value.start || value.end).calendar;
|
|
715
|
-
let placeholder = $50d5d6a623389320$export$66aa2b09de4b1ea5(props.placeholderValue, granularity, calendar, defaultTimeZone);
|
|
716
|
-
setValue({
|
|
717
|
-
start: value.start || placeholder,
|
|
718
|
-
end: value.end || placeholder
|
|
719
|
-
});
|
|
720
|
-
}
|
|
721
1119
|
}
|
|
722
1120
|
};
|
|
723
1121
|
}
|