@react-stately/datepicker 3.0.0-rc.1 → 3.0.2

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 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});
@@ -98,7 +99,7 @@ function $aaab7a647e17e1fd$export$87194bb378cc3ac2(props) {
98
99
  let v = value || props.placeholderValue;
99
100
  let [granularity, defaultTimeZone] = $50d5d6a623389320$export$2440da353cedad43(v, props.granularity);
100
101
  let dateValue = value != null ? value.toDate(defaultTimeZone !== null && defaultTimeZone !== void 0 ? defaultTimeZone : 'UTC') : null;
101
- let hasTime = granularity === 'hour' || granularity === 'minute' || granularity === 'second' || granularity === 'millisecond';
102
+ let hasTime = granularity === 'hour' || granularity === 'minute' || granularity === 'second';
102
103
  var _shouldCloseOnSelect;
103
104
  let shouldCloseOnSelect = (_shouldCloseOnSelect = props.shouldCloseOnSelect) !== null && _shouldCloseOnSelect !== void 0 ? _shouldCloseOnSelect : true;
104
105
  let [selectedDate, setSelectedDate] = $h2qOe$react.useState(null);
@@ -163,6 +164,396 @@ function $aaab7a647e17e1fd$export$87194bb378cc3ac2(props) {
163
164
 
164
165
 
165
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
+
166
557
 
167
558
  const $596a1f0f523d6752$var$EDITABLE_SEGMENTS = {
168
559
  year: true,
@@ -309,11 +700,14 @@ function $596a1f0f523d6752$export$60e84778edff6d26(props) {
309
700
  let segments = $h2qOe$react.useMemo(()=>dateFormatter.formatToParts(dateValue).map((segment)=>{
310
701
  let isEditable = $596a1f0f523d6752$var$EDITABLE_SEGMENTS[segment.type];
311
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;
312
705
  return {
313
706
  type: $596a1f0f523d6752$var$TYPE_MAPPING[segment.type] || segment.type,
314
- text: segment.value,
707
+ text: isPlaceholder ? placeholder : segment.value,
315
708
  ...$596a1f0f523d6752$var$getSegmentLimits(displayValue, segment.type, resolvedOptions),
316
- isPlaceholder: $596a1f0f523d6752$var$EDITABLE_SEGMENTS[segment.type] && !validSegments[segment.type],
709
+ isPlaceholder: isPlaceholder,
710
+ placeholder: placeholder,
317
711
  isEditable: isEditable
318
712
  };
319
713
  })
@@ -323,29 +717,41 @@ function $596a1f0f523d6752$export$60e84778edff6d26(props) {
323
717
  dateFormatter,
324
718
  resolvedOptions,
325
719
  displayValue,
326
- calendar
327
- ]);
328
- let hasEra = $h2qOe$react.useMemo(()=>segments.some((s)=>s.type === 'era'
329
- )
330
- , [
331
- segments
720
+ calendar,
721
+ locale
332
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
+ }
333
736
  let markValid = (part)=>{
334
737
  validSegments[part] = true;
335
- if (part === 'year' && hasEra) validSegments.era = true;
738
+ if (part === 'year' && allSegments.era) validSegments.era = true;
336
739
  setValidSegments({
337
740
  ...validSegments
338
741
  });
339
742
  };
340
743
  let adjustSegment = (type, amount)=>{
341
- markValid(type);
342
- setValue($596a1f0f523d6752$var$addSegment(displayValue, type, amount, resolvedOptions));
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));
343
748
  };
344
749
  let validationState = props.validationState || ($50d5d6a623389320$export$eac50920cf2fd59a(calendarValue, props.minValue, props.maxValue) ? 'invalid' : null);
345
750
  var _maxGranularity1;
346
751
  return {
347
752
  value: calendarValue,
348
753
  dateValue: dateValue,
754
+ calendar: calendar,
349
755
  setValue: setValue,
350
756
  segments: segments,
351
757
  dateFormatter: dateFormatter,
@@ -371,20 +777,16 @@ function $596a1f0f523d6752$export$60e84778edff6d26(props) {
371
777
  markValid(part);
372
778
  setValue($596a1f0f523d6752$var$setSegment(displayValue, part, v, resolvedOptions));
373
779
  },
374
- confirmPlaceholder (part) {
780
+ confirmPlaceholder () {
375
781
  if (props.isDisabled || props.isReadOnly) return;
376
- if (!part) {
377
- // Confirm the rest of the placeholder if any of the segments are valid.
378
- let numValid = Object.keys(validSegments).length;
379
- if (numValid > 0 && numValid < Object.keys(allSegments).length) {
380
- validSegments = {
381
- ...allSegments
382
- };
383
- setValidSegments(validSegments);
384
- setValue(displayValue.copy());
385
- }
386
- } else if (!validSegments[part]) {
387
- 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);
388
790
  setValue(displayValue.copy());
389
791
  }
390
792
  },
@@ -519,6 +921,7 @@ function $596a1f0f523d6752$var$setSegment(value, part, segmentValue, options) {
519
921
  case 'day':
520
922
  case 'month':
521
923
  case 'year':
924
+ case 'era':
522
925
  return value.set({
523
926
  [part]: segmentValue
524
927
  });
@@ -575,17 +978,14 @@ function $7072d26f58deb33b$export$e50a61c1de9f574(props) {
575
978
  setPlaceholderValue(placeholderValue);
576
979
  }
577
980
  let value1 = controlledValue || placeholderValue;
578
- let valueRef = $h2qOe$react.useRef(value1);
579
- valueRef.current = value1;
580
981
  let setValue = (value)=>{
581
- valueRef.current = value;
582
982
  setPlaceholderValue(value);
583
983
  if ((value === null || value === void 0 ? void 0 : value.start) && value.end) setControlledValue(value);
584
984
  else setControlledValue(null);
585
985
  };
586
986
  let v = (value1 === null || value1 === void 0 ? void 0 : value1.start) || (value1 === null || value1 === void 0 ? void 0 : value1.end) || props.placeholderValue;
587
- let [granularity, defaultTimeZone] = $50d5d6a623389320$export$2440da353cedad43(v, props.granularity);
588
- let hasTime = granularity === 'hour' || granularity === 'minute' || granularity === 'second' || granularity === 'millisecond';
987
+ let [granularity] = $50d5d6a623389320$export$2440da353cedad43(v, props.granularity);
988
+ let hasTime = granularity === 'hour' || granularity === 'minute' || granularity === 'second';
589
989
  var _shouldCloseOnSelect;
590
990
  let shouldCloseOnSelect = (_shouldCloseOnSelect = props.shouldCloseOnSelect) !== null && _shouldCloseOnSelect !== void 0 ? _shouldCloseOnSelect : true;
591
991
  let [dateRange1, setSelectedDateRange] = $h2qOe$react.useState(null);
@@ -716,19 +1116,6 @@ function $7072d26f58deb33b$export$e50a61c1de9f574(props) {
716
1116
  start: startFormatter.format(startDate),
717
1117
  end: endFormatter.format(endDate)
718
1118
  };
719
- },
720
- confirmPlaceholder () {
721
- // Need to use ref value here because the value can be set in the same tick as
722
- // a blur, which means the component won't have re-rendered yet.
723
- let value = valueRef.current;
724
- if (value && Boolean(value.start) !== Boolean(value.end)) {
725
- let calendar = (value.start || value.end).calendar;
726
- let placeholder = $50d5d6a623389320$export$66aa2b09de4b1ea5(props.placeholderValue, granularity, calendar, defaultTimeZone);
727
- setValue({
728
- start: value.start || placeholder,
729
- end: value.end || placeholder
730
- });
731
- }
732
1119
  }
733
1120
  };
734
1121
  }