@react-stately/datepicker 3.2.1 → 3.4.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.
@@ -0,0 +1,1218 @@
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
+ import {useOverlayTriggerState as $7UzoM$useOverlayTriggerState} from "@react-stately/overlays";
3
+ import {useControlledState as $7UzoM$useControlledState} from "@react-stately/utils";
4
+ import {useState as $7UzoM$useState, useRef as $7UzoM$useRef, useMemo as $7UzoM$useMemo, useEffect as $7UzoM$useEffect} from "react";
5
+ import {LocalizedStringDictionary as $7UzoM$LocalizedStringDictionary} from "@internationalized/string";
6
+
7
+ /*
8
+ * Copyright 2020 Adobe. All rights reserved.
9
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License. You may obtain a copy
11
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software distributed under
14
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
15
+ * OF ANY KIND, either express or implied. See the License for the specific language
16
+ * governing permissions and limitations under the License.
17
+ */ /*
18
+ * Copyright 2020 Adobe. All rights reserved.
19
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
20
+ * you may not use this file except in compliance with the License. You may obtain a copy
21
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
22
+ *
23
+ * Unless required by applicable law or agreed to in writing, software distributed under
24
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
25
+ * OF ANY KIND, either express or implied. See the License for the specific language
26
+ * governing permissions and limitations under the License.
27
+ */
28
+ /*
29
+ * Copyright 2020 Adobe. All rights reserved.
30
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
31
+ * you may not use this file except in compliance with the License. You may obtain a copy
32
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
33
+ *
34
+ * Unless required by applicable law or agreed to in writing, software distributed under
35
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
36
+ * OF ANY KIND, either express or implied. See the License for the specific language
37
+ * governing permissions and limitations under the License.
38
+ */
39
+
40
+ function $35a22f14a1f04b11$export$eac50920cf2fd59a(value, minValue, maxValue) {
41
+ return value != null && (minValue != null && value.compare(minValue) < 0 || maxValue != null && value.compare(maxValue) > 0);
42
+ }
43
+ const $35a22f14a1f04b11$var$DEFAULT_FIELD_OPTIONS = {
44
+ year: "numeric",
45
+ month: "numeric",
46
+ day: "numeric",
47
+ hour: "numeric",
48
+ minute: "2-digit",
49
+ second: "2-digit"
50
+ };
51
+ function $35a22f14a1f04b11$export$7e319ea407e63bc0(fieldOptions, options) {
52
+ fieldOptions = {
53
+ ...$35a22f14a1f04b11$var$DEFAULT_FIELD_OPTIONS,
54
+ ...fieldOptions
55
+ };
56
+ let granularity = options.granularity || "minute";
57
+ let keys = Object.keys(fieldOptions);
58
+ var _options_maxGranularity;
59
+ let startIdx = keys.indexOf((_options_maxGranularity = options.maxGranularity) !== null && _options_maxGranularity !== void 0 ? _options_maxGranularity : "year");
60
+ if (startIdx < 0) startIdx = 0;
61
+ let endIdx = keys.indexOf(granularity);
62
+ if (endIdx < 0) endIdx = 2;
63
+ if (startIdx > endIdx) throw new Error("maxGranularity must be greater than granularity");
64
+ let opts = keys.slice(startIdx, endIdx + 1).reduce((opts, key)=>{
65
+ opts[key] = fieldOptions[key];
66
+ return opts;
67
+ }, {});
68
+ if (options.hourCycle != null) opts.hour12 = options.hourCycle === 12;
69
+ opts.timeZone = options.timeZone || "UTC";
70
+ let hasTime = granularity === "hour" || granularity === "minute" || granularity === "second";
71
+ if (hasTime && options.timeZone && !options.hideTimeZone) opts.timeZoneName = "short";
72
+ if (options.showEra && startIdx === 0) opts.era = "short";
73
+ return opts;
74
+ }
75
+ function $35a22f14a1f04b11$export$c5221a78ef73c5e9(placeholderValue) {
76
+ if (placeholderValue && "hour" in placeholderValue) return placeholderValue;
77
+ return new (0, $7UzoM$Time)();
78
+ }
79
+ function $35a22f14a1f04b11$export$61a490a80c552550(value, calendar) {
80
+ if (value === null) return null;
81
+ if (!value) return undefined;
82
+ return (0, $7UzoM$toCalendar)(value, calendar);
83
+ }
84
+ function $35a22f14a1f04b11$export$66aa2b09de4b1ea5(placeholderValue, granularity, calendar, timeZone) {
85
+ if (placeholderValue) return $35a22f14a1f04b11$export$61a490a80c552550(placeholderValue, calendar);
86
+ let date = (0, $7UzoM$toCalendar)((0, $7UzoM$now)(timeZone).set({
87
+ hour: 0,
88
+ minute: 0,
89
+ second: 0,
90
+ millisecond: 0
91
+ }), calendar);
92
+ if (granularity === "year" || granularity === "month" || granularity === "day") return (0, $7UzoM$toCalendarDate)(date);
93
+ if (!timeZone) return (0, $7UzoM$toCalendarDateTime)(date);
94
+ return date;
95
+ }
96
+ function $35a22f14a1f04b11$export$2440da353cedad43(v, granularity) {
97
+ // Compute default granularity and time zone from the value. If the value becomes null, keep the last values.
98
+ let lastValue = (0, $7UzoM$useRef)(v);
99
+ if (v) lastValue.current = v;
100
+ v = lastValue.current;
101
+ let defaultTimeZone = v && "timeZone" in v ? v.timeZone : undefined;
102
+ granularity = granularity || (v && "minute" in v ? "minute" : "day");
103
+ // props.granularity must actually exist in the value if one is provided.
104
+ if (v && !(granularity in v)) throw new Error("Invalid granularity " + granularity + " for value " + v.toString());
105
+ return [
106
+ granularity,
107
+ defaultTimeZone
108
+ ];
109
+ }
110
+
111
+
112
+
113
+
114
+
115
+
116
+ function $ab5bf3f618090389$export$87194bb378cc3ac2(props) {
117
+ var _props_isDateUnavailable;
118
+ let overlayState = (0, $7UzoM$useOverlayTriggerState)(props);
119
+ let [value, setValue] = (0, $7UzoM$useControlledState)(props.value, props.defaultValue || null, props.onChange);
120
+ let v = value || props.placeholderValue;
121
+ let [granularity, defaultTimeZone] = (0, $35a22f14a1f04b11$export$2440da353cedad43)(v, props.granularity);
122
+ let dateValue = value != null ? value.toDate(defaultTimeZone !== null && defaultTimeZone !== void 0 ? defaultTimeZone : "UTC") : null;
123
+ let hasTime = granularity === "hour" || granularity === "minute" || granularity === "second";
124
+ var _props_shouldCloseOnSelect;
125
+ let shouldCloseOnSelect = (_props_shouldCloseOnSelect = props.shouldCloseOnSelect) !== null && _props_shouldCloseOnSelect !== void 0 ? _props_shouldCloseOnSelect : true;
126
+ let [selectedDate, setSelectedDate] = (0, $7UzoM$useState)(null);
127
+ let [selectedTime, setSelectedTime] = (0, $7UzoM$useState)(null);
128
+ if (value) {
129
+ selectedDate = value;
130
+ if ("hour" in value) selectedTime = value;
131
+ }
132
+ // props.granularity must actually exist in the value if one is provided.
133
+ if (v && !(granularity in v)) throw new Error("Invalid granularity " + granularity + " for value " + v.toString());
134
+ let commitValue = (date, time)=>{
135
+ setValue("timeZone" in time ? time.set((0, $7UzoM$toCalendarDate)(date)) : (0, $7UzoM$toCalendarDateTime)(date, time));
136
+ setSelectedDate(null);
137
+ setSelectedTime(null);
138
+ };
139
+ // Intercept setValue to make sure the Time section is not changed by date selection in Calendar
140
+ let selectDate = (newValue)=>{
141
+ let shouldClose = typeof shouldCloseOnSelect === "function" ? shouldCloseOnSelect() : shouldCloseOnSelect;
142
+ if (hasTime) {
143
+ if (selectedTime || shouldClose) commitValue(newValue, selectedTime || (0, $35a22f14a1f04b11$export$c5221a78ef73c5e9)(props.placeholderValue));
144
+ else setSelectedDate(newValue);
145
+ } else setValue(newValue);
146
+ if (shouldClose) overlayState.setOpen(false);
147
+ };
148
+ let selectTime = (newValue)=>{
149
+ if (selectedDate) commitValue(selectedDate, newValue);
150
+ else setSelectedTime(newValue);
151
+ };
152
+ let validationState = props.validationState || ((0, $35a22f14a1f04b11$export$eac50920cf2fd59a)(value, props.minValue, props.maxValue) ? "invalid" : null) || (value && ((_props_isDateUnavailable = props.isDateUnavailable) === null || _props_isDateUnavailable === void 0 ? void 0 : _props_isDateUnavailable.call(props, value)) ? "invalid" : null);
153
+ return {
154
+ value: value,
155
+ setValue: setValue,
156
+ dateValue: selectedDate,
157
+ timeValue: selectedTime,
158
+ setDateValue: selectDate,
159
+ setTimeValue: selectTime,
160
+ granularity: granularity,
161
+ hasTime: hasTime,
162
+ ...overlayState,
163
+ setOpen (isOpen) {
164
+ // Commit the selected date when the calendar is closed. Use a placeholder time if one wasn't set.
165
+ // If only the time was set and not the date, don't commit. The state will be preserved until
166
+ // the user opens the popover again.
167
+ if (!isOpen && !value && selectedDate && hasTime) commitValue(selectedDate, selectedTime || (0, $35a22f14a1f04b11$export$c5221a78ef73c5e9)(props.placeholderValue));
168
+ overlayState.setOpen(isOpen);
169
+ },
170
+ validationState: validationState,
171
+ formatValue (locale, fieldOptions) {
172
+ if (!dateValue) return "";
173
+ let formatOptions = (0, $35a22f14a1f04b11$export$7e319ea407e63bc0)(fieldOptions, {
174
+ granularity: granularity,
175
+ timeZone: defaultTimeZone,
176
+ hideTimeZone: props.hideTimeZone,
177
+ hourCycle: props.hourCycle,
178
+ showEra: value.calendar.identifier === "gregory" && value.era === "BC"
179
+ });
180
+ let formatter = new (0, $7UzoM$DateFormatter)(locale, formatOptions);
181
+ return formatter.format(dateValue);
182
+ }
183
+ };
184
+ }
185
+
186
+
187
+ /*
188
+ * Copyright 2020 Adobe. All rights reserved.
189
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
190
+ * you may not use this file except in compliance with the License. You may obtain a copy
191
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
192
+ *
193
+ * Unless required by applicable law or agreed to in writing, software distributed under
194
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
195
+ * OF ANY KIND, either express or implied. See the License for the specific language
196
+ * governing permissions and limitations under the License.
197
+ */
198
+
199
+ /*
200
+ * Copyright 2020 Adobe. All rights reserved.
201
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
202
+ * you may not use this file except in compliance with the License. You may obtain a copy
203
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
204
+ *
205
+ * Unless required by applicable law or agreed to in writing, software distributed under
206
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
207
+ * OF ANY KIND, either express or implied. See the License for the specific language
208
+ * governing permissions and limitations under the License.
209
+ */
210
+ // These placeholders are based on the strings used by the <input type="date">
211
+ // implementations in Chrome and Firefox. Additional languages are supported
212
+ // here than React Spectrum's typical translations.
213
+ const $3e3ed55ab2966714$var$placeholders = new (0, $7UzoM$LocalizedStringDictionary)({
214
+ ach: {
215
+ year: "mwaka",
216
+ month: "dwe",
217
+ day: "nino"
218
+ },
219
+ af: {
220
+ year: "jjjj",
221
+ month: "mm",
222
+ day: "dd"
223
+ },
224
+ am: {
225
+ year: "ዓዓዓዓ",
226
+ month: "ሚሜ",
227
+ day: "ቀቀ"
228
+ },
229
+ an: {
230
+ year: "aaaa",
231
+ month: "mm",
232
+ day: "dd"
233
+ },
234
+ ar: {
235
+ year: "سنة",
236
+ month: "شهر",
237
+ day: "يوم"
238
+ },
239
+ ast: {
240
+ year: "aaaa",
241
+ month: "mm",
242
+ day: "dd"
243
+ },
244
+ az: {
245
+ year: "iiii",
246
+ month: "aa",
247
+ day: "gg"
248
+ },
249
+ be: {
250
+ year: "гггг",
251
+ month: "мм",
252
+ day: "дд"
253
+ },
254
+ bg: {
255
+ year: "гггг",
256
+ month: "мм",
257
+ day: "дд"
258
+ },
259
+ bn: {
260
+ year: "yyyy",
261
+ month: "মিমি",
262
+ day: "dd"
263
+ },
264
+ br: {
265
+ year: "bbbb",
266
+ month: "mm",
267
+ day: "dd"
268
+ },
269
+ bs: {
270
+ year: "gggg",
271
+ month: "mm",
272
+ day: "dd"
273
+ },
274
+ ca: {
275
+ year: "aaaa",
276
+ month: "mm",
277
+ day: "dd"
278
+ },
279
+ cak: {
280
+ year: "jjjj",
281
+ month: "ii",
282
+ day: "q'q'"
283
+ },
284
+ ckb: {
285
+ year: "ساڵ",
286
+ month: "مانگ",
287
+ day: "ڕۆژ"
288
+ },
289
+ cs: {
290
+ year: "rrrr",
291
+ month: "mm",
292
+ day: "dd"
293
+ },
294
+ cy: {
295
+ year: "bbbb",
296
+ month: "mm",
297
+ day: "dd"
298
+ },
299
+ da: {
300
+ year: "\xe5\xe5\xe5\xe5",
301
+ month: "mm",
302
+ day: "dd"
303
+ },
304
+ de: {
305
+ year: "jjjj",
306
+ month: "mm",
307
+ day: "tt"
308
+ },
309
+ dsb: {
310
+ year: "llll",
311
+ month: "mm",
312
+ day: "źź"
313
+ },
314
+ el: {
315
+ year: "εεεε",
316
+ month: "μμ",
317
+ day: "ηη"
318
+ },
319
+ en: {
320
+ year: "yyyy",
321
+ month: "mm",
322
+ day: "dd"
323
+ },
324
+ eo: {
325
+ year: "jjjj",
326
+ month: "mm",
327
+ day: "tt"
328
+ },
329
+ es: {
330
+ year: "aaaa",
331
+ month: "mm",
332
+ day: "dd"
333
+ },
334
+ et: {
335
+ year: "aaaa",
336
+ month: "kk",
337
+ day: "pp"
338
+ },
339
+ eu: {
340
+ year: "uuuu",
341
+ month: "hh",
342
+ day: "ee"
343
+ },
344
+ fa: {
345
+ year: "سال",
346
+ month: "ماه",
347
+ day: "روز"
348
+ },
349
+ ff: {
350
+ year: "hhhh",
351
+ month: "ll",
352
+ day: "\xf1\xf1"
353
+ },
354
+ fi: {
355
+ year: "vvvv",
356
+ month: "kk",
357
+ day: "pp"
358
+ },
359
+ fr: {
360
+ year: "aaaa",
361
+ month: "mm",
362
+ day: "jj"
363
+ },
364
+ fy: {
365
+ year: "jjjj",
366
+ month: "mm",
367
+ day: "dd"
368
+ },
369
+ ga: {
370
+ year: "bbbb",
371
+ month: "mm",
372
+ day: "ll"
373
+ },
374
+ gd: {
375
+ year: "bbbb",
376
+ month: "mm",
377
+ day: "ll"
378
+ },
379
+ gl: {
380
+ year: "aaaa",
381
+ month: "mm",
382
+ day: "dd"
383
+ },
384
+ he: {
385
+ year: "שנה",
386
+ month: "חודש",
387
+ day: "יום"
388
+ },
389
+ hr: {
390
+ year: "gggg",
391
+ month: "mm",
392
+ day: "dd"
393
+ },
394
+ hsb: {
395
+ year: "llll",
396
+ month: "mm",
397
+ day: "dd"
398
+ },
399
+ hu: {
400
+ year: "\xe9\xe9\xe9\xe9",
401
+ month: "hh",
402
+ day: "nn"
403
+ },
404
+ ia: {
405
+ year: "aaaa",
406
+ month: "mm",
407
+ day: "dd"
408
+ },
409
+ id: {
410
+ year: "tttt",
411
+ month: "bb",
412
+ day: "hh"
413
+ },
414
+ it: {
415
+ year: "aaaa",
416
+ month: "mm",
417
+ day: "gg"
418
+ },
419
+ ja: {
420
+ year: " 年 ",
421
+ month: "月",
422
+ day: "日"
423
+ },
424
+ ka: {
425
+ year: "წწწწ",
426
+ month: "თთ",
427
+ day: "რრ"
428
+ },
429
+ kk: {
430
+ year: "жжжж",
431
+ month: "аа",
432
+ day: "кк"
433
+ },
434
+ kn: {
435
+ year: "ವವವವ",
436
+ month: "ಮಿಮೀ",
437
+ day: "ದಿದಿ"
438
+ },
439
+ ko: {
440
+ year: "연도",
441
+ month: "월",
442
+ day: "일"
443
+ },
444
+ lb: {
445
+ year: "jjjj",
446
+ month: "mm",
447
+ day: "dd"
448
+ },
449
+ lo: {
450
+ year: "ປປປປ",
451
+ month: "ດດ",
452
+ day: "ວວ"
453
+ },
454
+ lt: {
455
+ year: "mmmm",
456
+ month: "mm",
457
+ day: "dd"
458
+ },
459
+ lv: {
460
+ year: "gggg",
461
+ month: "mm",
462
+ day: "dd"
463
+ },
464
+ meh: {
465
+ year: "aaaa",
466
+ month: "mm",
467
+ day: "dd"
468
+ },
469
+ ml: {
470
+ year: "വർഷം",
471
+ month: "മാസം",
472
+ day: "തീയതി"
473
+ },
474
+ ms: {
475
+ year: "tttt",
476
+ month: "mm",
477
+ day: "hh"
478
+ },
479
+ nl: {
480
+ year: "jjjj",
481
+ month: "mm",
482
+ day: "dd"
483
+ },
484
+ nn: {
485
+ year: "\xe5\xe5\xe5\xe5",
486
+ month: "mm",
487
+ day: "dd"
488
+ },
489
+ no: {
490
+ year: "\xe5\xe5\xe5\xe5",
491
+ month: "mm",
492
+ day: "dd"
493
+ },
494
+ oc: {
495
+ year: "aaaa",
496
+ month: "mm",
497
+ day: "jj"
498
+ },
499
+ pl: {
500
+ year: "rrrr",
501
+ month: "mm",
502
+ day: "dd"
503
+ },
504
+ pt: {
505
+ year: "aaaa",
506
+ month: "mm",
507
+ day: "dd"
508
+ },
509
+ rm: {
510
+ year: "oooo",
511
+ month: "mm",
512
+ day: "dd"
513
+ },
514
+ ro: {
515
+ year: "aaaa",
516
+ month: "ll",
517
+ day: "zz"
518
+ },
519
+ ru: {
520
+ year: "гггг",
521
+ month: "мм",
522
+ day: "дд"
523
+ },
524
+ sc: {
525
+ year: "aaaa",
526
+ month: "mm",
527
+ day: "dd"
528
+ },
529
+ scn: {
530
+ year: "aaaa",
531
+ month: "mm",
532
+ day: "jj"
533
+ },
534
+ sk: {
535
+ year: "rrrr",
536
+ month: "mm",
537
+ day: "dd"
538
+ },
539
+ sl: {
540
+ year: "llll",
541
+ month: "mm",
542
+ day: "dd"
543
+ },
544
+ sr: {
545
+ year: "гггг",
546
+ month: "мм",
547
+ day: "дд"
548
+ },
549
+ sv: {
550
+ year: "\xe5\xe5\xe5\xe5",
551
+ month: "mm",
552
+ day: "dd"
553
+ },
554
+ szl: {
555
+ year: "rrrr",
556
+ month: "mm",
557
+ day: "dd"
558
+ },
559
+ tg: {
560
+ year: "сссс",
561
+ month: "мм",
562
+ day: "рр"
563
+ },
564
+ th: {
565
+ year: "ปปปป",
566
+ month: "ดด",
567
+ day: "วว"
568
+ },
569
+ tr: {
570
+ year: "yyyy",
571
+ month: "aa",
572
+ day: "gg"
573
+ },
574
+ uk: {
575
+ year: "рррр",
576
+ month: "мм",
577
+ day: "дд"
578
+ },
579
+ "zh-CN": {
580
+ year: "年",
581
+ month: "月",
582
+ day: "日"
583
+ },
584
+ "zh-TW": {
585
+ year: "年",
586
+ month: "月",
587
+ day: "日"
588
+ }
589
+ }, "en");
590
+ function $3e3ed55ab2966714$export$d3f5c5e0a5023fa0(field, value, locale) {
591
+ // Use the actual placeholder value for the era and day period fields.
592
+ if (field === "era" || field === "dayPeriod") return value;
593
+ if (field === "year" || field === "month" || field === "day") return $3e3ed55ab2966714$var$placeholders.getStringForLocale(field, locale);
594
+ // For time fields (e.g. hour, minute, etc.), use two dashes as the placeholder.
595
+ return "––";
596
+ }
597
+
598
+
599
+
600
+
601
+ const $3c0fc76039f1c516$var$EDITABLE_SEGMENTS = {
602
+ year: true,
603
+ month: true,
604
+ day: true,
605
+ hour: true,
606
+ minute: true,
607
+ second: true,
608
+ dayPeriod: true,
609
+ era: true
610
+ };
611
+ const $3c0fc76039f1c516$var$PAGE_STEP = {
612
+ year: 5,
613
+ month: 2,
614
+ day: 7,
615
+ hour: 2,
616
+ minute: 15,
617
+ second: 15
618
+ };
619
+ // Node seems to convert everything to lowercase...
620
+ const $3c0fc76039f1c516$var$TYPE_MAPPING = {
621
+ dayperiod: "dayPeriod"
622
+ };
623
+ function $3c0fc76039f1c516$export$60e84778edff6d26(props) {
624
+ let { locale: locale , createCalendar: createCalendar , hideTimeZone: hideTimeZone , isDisabled: isDisabled , isReadOnly: isReadOnly , isRequired: isRequired } = props;
625
+ let v = props.value || props.defaultValue || props.placeholderValue;
626
+ let [granularity, defaultTimeZone] = (0, $35a22f14a1f04b11$export$2440da353cedad43)(v, props.granularity);
627
+ let timeZone = defaultTimeZone || "UTC";
628
+ // props.granularity must actually exist in the value if one is provided.
629
+ if (v && !(granularity in v)) throw new Error("Invalid granularity " + granularity + " for value " + v.toString());
630
+ let defaultFormatter = (0, $7UzoM$useMemo)(()=>new (0, $7UzoM$DateFormatter)(locale), [
631
+ locale
632
+ ]);
633
+ let calendar = (0, $7UzoM$useMemo)(()=>createCalendar(defaultFormatter.resolvedOptions().calendar), [
634
+ createCalendar,
635
+ defaultFormatter
636
+ ]);
637
+ let [value, setDate] = (0, $7UzoM$useControlledState)(props.value, props.defaultValue, props.onChange);
638
+ let calendarValue = (0, $7UzoM$useMemo)(()=>(0, $35a22f14a1f04b11$export$61a490a80c552550)(value, calendar), [
639
+ value,
640
+ calendar
641
+ ]);
642
+ // We keep track of the placeholder date separately in state so that onChange is not called
643
+ // until all segments are set. If the value === null (not undefined), then assume the component
644
+ // is controlled, so use the placeholder as the value until all segments are entered so it doesn't
645
+ // change from uncontrolled to controlled and emit a warning.
646
+ let [placeholderDate, setPlaceholderDate] = (0, $7UzoM$useState)(()=>(0, $35a22f14a1f04b11$export$66aa2b09de4b1ea5)(props.placeholderValue, granularity, calendar, defaultTimeZone));
647
+ let val = calendarValue || placeholderDate;
648
+ let showEra = calendar.identifier === "gregory" && val.era === "BC";
649
+ var _props_maxGranularity;
650
+ let formatOpts = (0, $7UzoM$useMemo)(()=>({
651
+ granularity: granularity,
652
+ maxGranularity: (_props_maxGranularity = props.maxGranularity) !== null && _props_maxGranularity !== void 0 ? _props_maxGranularity : "year",
653
+ timeZone: defaultTimeZone,
654
+ hideTimeZone: hideTimeZone,
655
+ hourCycle: props.hourCycle,
656
+ showEra: showEra
657
+ }), [
658
+ props.maxGranularity,
659
+ granularity,
660
+ props.hourCycle,
661
+ defaultTimeZone,
662
+ hideTimeZone,
663
+ showEra
664
+ ]);
665
+ let opts = (0, $7UzoM$useMemo)(()=>(0, $35a22f14a1f04b11$export$7e319ea407e63bc0)({}, formatOpts), [
666
+ formatOpts
667
+ ]);
668
+ let dateFormatter = (0, $7UzoM$useMemo)(()=>new (0, $7UzoM$DateFormatter)(locale, opts), [
669
+ locale,
670
+ opts
671
+ ]);
672
+ let resolvedOptions = (0, $7UzoM$useMemo)(()=>dateFormatter.resolvedOptions(), [
673
+ dateFormatter
674
+ ]);
675
+ // Determine how many editable segments there are for validation purposes.
676
+ // The result is cached for performance.
677
+ let allSegments = (0, $7UzoM$useMemo)(()=>dateFormatter.formatToParts(new Date()).filter((seg)=>$3c0fc76039f1c516$var$EDITABLE_SEGMENTS[seg.type]).reduce((p, seg)=>(p[seg.type] = true, p), {}), [
678
+ dateFormatter
679
+ ]);
680
+ let [validSegments, setValidSegments] = (0, $7UzoM$useState)(()=>props.value || props.defaultValue ? {
681
+ ...allSegments
682
+ } : {});
683
+ // Reset placeholder when calendar changes
684
+ let lastCalendarIdentifier = (0, $7UzoM$useRef)(calendar.identifier);
685
+ (0, $7UzoM$useEffect)(()=>{
686
+ if (calendar.identifier !== lastCalendarIdentifier.current) {
687
+ lastCalendarIdentifier.current = calendar.identifier;
688
+ setPlaceholderDate((placeholder)=>Object.keys(validSegments).length > 0 ? (0, $7UzoM$toCalendar)(placeholder, calendar) : (0, $35a22f14a1f04b11$export$66aa2b09de4b1ea5)(props.placeholderValue, granularity, calendar, defaultTimeZone));
689
+ }
690
+ }, [
691
+ calendar,
692
+ granularity,
693
+ validSegments,
694
+ defaultTimeZone,
695
+ props.placeholderValue
696
+ ]);
697
+ // If there is a value prop, and some segments were previously placeholders, mark them all as valid.
698
+ if (value && Object.keys(validSegments).length < Object.keys(allSegments).length) {
699
+ validSegments = {
700
+ ...allSegments
701
+ };
702
+ setValidSegments(validSegments);
703
+ }
704
+ // If the value is set to null and all segments are valid, reset the placeholder.
705
+ if (value == null && Object.keys(validSegments).length === Object.keys(allSegments).length) {
706
+ validSegments = {};
707
+ setValidSegments(validSegments);
708
+ setPlaceholderDate((0, $35a22f14a1f04b11$export$66aa2b09de4b1ea5)(props.placeholderValue, granularity, calendar, defaultTimeZone));
709
+ }
710
+ // If all segments are valid, use the date from state, otherwise use the placeholder date.
711
+ let displayValue = calendarValue && Object.keys(validSegments).length >= Object.keys(allSegments).length ? calendarValue : placeholderDate;
712
+ let setValue = (newValue)=>{
713
+ if (props.isDisabled || props.isReadOnly) return;
714
+ if (Object.keys(validSegments).length >= Object.keys(allSegments).length) {
715
+ // The display calendar should not have any effect on the emitted value.
716
+ // Emit dates in the same calendar as the original value, if any, otherwise gregorian.
717
+ newValue = (0, $7UzoM$toCalendar)(newValue, (v === null || v === void 0 ? void 0 : v.calendar) || new (0, $7UzoM$GregorianCalendar)());
718
+ setDate(newValue);
719
+ } else setPlaceholderDate(newValue);
720
+ };
721
+ let dateValue = (0, $7UzoM$useMemo)(()=>displayValue.toDate(timeZone), [
722
+ displayValue,
723
+ timeZone
724
+ ]);
725
+ let segments = (0, $7UzoM$useMemo)(()=>dateFormatter.formatToParts(dateValue).map((segment)=>{
726
+ let isEditable = $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[segment.type];
727
+ if (segment.type === "era" && calendar.getEras().length === 1) isEditable = false;
728
+ let isPlaceholder = $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[segment.type] && !validSegments[segment.type];
729
+ let placeholder = $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[segment.type] ? (0, $3e3ed55ab2966714$export$d3f5c5e0a5023fa0)(segment.type, segment.value, locale) : null;
730
+ return {
731
+ type: $3c0fc76039f1c516$var$TYPE_MAPPING[segment.type] || segment.type,
732
+ text: isPlaceholder ? placeholder : segment.value,
733
+ ...$3c0fc76039f1c516$var$getSegmentLimits(displayValue, segment.type, resolvedOptions),
734
+ isPlaceholder: isPlaceholder,
735
+ placeholder: placeholder,
736
+ isEditable: isEditable
737
+ };
738
+ }), [
739
+ dateValue,
740
+ validSegments,
741
+ dateFormatter,
742
+ resolvedOptions,
743
+ displayValue,
744
+ calendar,
745
+ locale
746
+ ]);
747
+ // When the era field appears, mark it valid if the year field is already valid.
748
+ // If the era field disappears, remove it from the valid segments.
749
+ if (allSegments.era && validSegments.year && !validSegments.era) {
750
+ validSegments.era = true;
751
+ setValidSegments({
752
+ ...validSegments
753
+ });
754
+ } else if (!allSegments.era && validSegments.era) {
755
+ delete validSegments.era;
756
+ setValidSegments({
757
+ ...validSegments
758
+ });
759
+ }
760
+ let markValid = (part)=>{
761
+ validSegments[part] = true;
762
+ if (part === "year" && allSegments.era) validSegments.era = true;
763
+ setValidSegments({
764
+ ...validSegments
765
+ });
766
+ };
767
+ let adjustSegment = (type, amount)=>{
768
+ if (!validSegments[type]) {
769
+ markValid(type);
770
+ if (Object.keys(validSegments).length >= Object.keys(allSegments).length) setValue(displayValue);
771
+ } else setValue($3c0fc76039f1c516$var$addSegment(displayValue, type, amount, resolvedOptions));
772
+ };
773
+ let validationState = props.validationState || ((0, $35a22f14a1f04b11$export$eac50920cf2fd59a)(calendarValue, props.minValue, props.maxValue) ? "invalid" : null);
774
+ var _props_maxGranularity1;
775
+ return {
776
+ value: calendarValue,
777
+ dateValue: dateValue,
778
+ calendar: calendar,
779
+ setValue: setValue,
780
+ segments: segments,
781
+ dateFormatter: dateFormatter,
782
+ validationState: validationState,
783
+ granularity: granularity,
784
+ maxGranularity: (_props_maxGranularity1 = props.maxGranularity) !== null && _props_maxGranularity1 !== void 0 ? _props_maxGranularity1 : "year",
785
+ isDisabled: isDisabled,
786
+ isReadOnly: isReadOnly,
787
+ isRequired: isRequired,
788
+ increment (part) {
789
+ adjustSegment(part, 1);
790
+ },
791
+ decrement (part) {
792
+ adjustSegment(part, -1);
793
+ },
794
+ incrementPage (part) {
795
+ adjustSegment(part, $3c0fc76039f1c516$var$PAGE_STEP[part] || 1);
796
+ },
797
+ decrementPage (part) {
798
+ adjustSegment(part, -($3c0fc76039f1c516$var$PAGE_STEP[part] || 1));
799
+ },
800
+ setSegment (part, v) {
801
+ markValid(part);
802
+ setValue($3c0fc76039f1c516$var$setSegment(displayValue, part, v, resolvedOptions));
803
+ },
804
+ confirmPlaceholder () {
805
+ if (props.isDisabled || props.isReadOnly) return;
806
+ // Confirm the placeholder if only the day period is not filled in.
807
+ let validKeys = Object.keys(validSegments);
808
+ let allKeys = Object.keys(allSegments);
809
+ if (validKeys.length === allKeys.length - 1 && allSegments.dayPeriod && !validSegments.dayPeriod) {
810
+ validSegments = {
811
+ ...allSegments
812
+ };
813
+ setValidSegments(validSegments);
814
+ setValue(displayValue.copy());
815
+ }
816
+ },
817
+ clearSegment (part) {
818
+ delete validSegments[part];
819
+ setValidSegments({
820
+ ...validSegments
821
+ });
822
+ let placeholder = (0, $35a22f14a1f04b11$export$66aa2b09de4b1ea5)(props.placeholderValue, granularity, calendar, defaultTimeZone);
823
+ let value = displayValue;
824
+ // Reset day period to default without changing the hour.
825
+ if (part === "dayPeriod" && "hour" in displayValue && "hour" in placeholder) {
826
+ let isPM = displayValue.hour >= 12;
827
+ let shouldBePM = placeholder.hour >= 12;
828
+ if (isPM && !shouldBePM) value = displayValue.set({
829
+ hour: displayValue.hour - 12
830
+ });
831
+ else if (!isPM && shouldBePM) value = displayValue.set({
832
+ hour: displayValue.hour + 12
833
+ });
834
+ } else if (part in displayValue) value = displayValue.set({
835
+ [part]: placeholder[part]
836
+ });
837
+ setDate(null);
838
+ setValue(value);
839
+ },
840
+ formatValue (fieldOptions) {
841
+ if (!calendarValue) return "";
842
+ let formatOptions = (0, $35a22f14a1f04b11$export$7e319ea407e63bc0)(fieldOptions, formatOpts);
843
+ let formatter = new (0, $7UzoM$DateFormatter)(locale, formatOptions);
844
+ return formatter.format(dateValue);
845
+ }
846
+ };
847
+ }
848
+ function $3c0fc76039f1c516$var$getSegmentLimits(date, type, options) {
849
+ switch(type){
850
+ case "era":
851
+ {
852
+ let eras = date.calendar.getEras();
853
+ return {
854
+ value: eras.indexOf(date.era),
855
+ minValue: 0,
856
+ maxValue: eras.length - 1
857
+ };
858
+ }
859
+ case "year":
860
+ return {
861
+ value: date.year,
862
+ minValue: 1,
863
+ maxValue: date.calendar.getYearsInEra(date)
864
+ };
865
+ case "month":
866
+ return {
867
+ value: date.month,
868
+ minValue: (0, $7UzoM$getMinimumMonthInYear)(date),
869
+ maxValue: date.calendar.getMonthsInYear(date)
870
+ };
871
+ case "day":
872
+ return {
873
+ value: date.day,
874
+ minValue: (0, $7UzoM$getMinimumDayInMonth)(date),
875
+ maxValue: date.calendar.getDaysInMonth(date)
876
+ };
877
+ }
878
+ if ("hour" in date) switch(type){
879
+ case "dayPeriod":
880
+ return {
881
+ value: date.hour >= 12 ? 12 : 0,
882
+ minValue: 0,
883
+ maxValue: 12
884
+ };
885
+ case "hour":
886
+ if (options.hour12) {
887
+ let isPM = date.hour >= 12;
888
+ return {
889
+ value: date.hour,
890
+ minValue: isPM ? 12 : 0,
891
+ maxValue: isPM ? 23 : 11
892
+ };
893
+ }
894
+ return {
895
+ value: date.hour,
896
+ minValue: 0,
897
+ maxValue: 23
898
+ };
899
+ case "minute":
900
+ return {
901
+ value: date.minute,
902
+ minValue: 0,
903
+ maxValue: 59
904
+ };
905
+ case "second":
906
+ return {
907
+ value: date.second,
908
+ minValue: 0,
909
+ maxValue: 59
910
+ };
911
+ }
912
+ return {};
913
+ }
914
+ function $3c0fc76039f1c516$var$addSegment(value, part, amount, options) {
915
+ switch(part){
916
+ case "era":
917
+ case "year":
918
+ case "month":
919
+ case "day":
920
+ return value.cycle(part, amount, {
921
+ round: part === "year"
922
+ });
923
+ }
924
+ if ("hour" in value) switch(part){
925
+ case "dayPeriod":
926
+ {
927
+ let hours = value.hour;
928
+ let isPM = hours >= 12;
929
+ return value.set({
930
+ hour: isPM ? hours - 12 : hours + 12
931
+ });
932
+ }
933
+ case "hour":
934
+ case "minute":
935
+ case "second":
936
+ return value.cycle(part, amount, {
937
+ round: part !== "hour",
938
+ hourCycle: options.hour12 ? 12 : 24
939
+ });
940
+ }
941
+ }
942
+ function $3c0fc76039f1c516$var$setSegment(value, part, segmentValue, options) {
943
+ switch(part){
944
+ case "day":
945
+ case "month":
946
+ case "year":
947
+ case "era":
948
+ return value.set({
949
+ [part]: segmentValue
950
+ });
951
+ }
952
+ if ("hour" in value) switch(part){
953
+ case "dayPeriod":
954
+ {
955
+ let hours = value.hour;
956
+ let wasPM = hours >= 12;
957
+ let isPM = segmentValue >= 12;
958
+ if (isPM === wasPM) return value;
959
+ return value.set({
960
+ hour: wasPM ? hours - 12 : hours + 12
961
+ });
962
+ }
963
+ case "hour":
964
+ // In 12 hour time, ensure that AM/PM does not change
965
+ if (options.hour12) {
966
+ let hours1 = value.hour;
967
+ let wasPM1 = hours1 >= 12;
968
+ if (!wasPM1 && segmentValue === 12) segmentValue = 0;
969
+ if (wasPM1 && segmentValue < 12) segmentValue += 12;
970
+ }
971
+ // fallthrough
972
+ case "minute":
973
+ case "second":
974
+ return value.set({
975
+ [part]: segmentValue
976
+ });
977
+ }
978
+ }
979
+
980
+
981
+ /*
982
+ * Copyright 2020 Adobe. All rights reserved.
983
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
984
+ * you may not use this file except in compliance with the License. You may obtain a copy
985
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
986
+ *
987
+ * Unless required by applicable law or agreed to in writing, software distributed under
988
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
989
+ * OF ANY KIND, either express or implied. See the License for the specific language
990
+ * governing permissions and limitations under the License.
991
+ */
992
+
993
+
994
+
995
+
996
+ function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
997
+ var _props_isDateUnavailable, _props_isDateUnavailable1;
998
+ let overlayState = (0, $7UzoM$useOverlayTriggerState)(props);
999
+ let [controlledValue, setControlledValue] = (0, $7UzoM$useControlledState)(props.value, props.defaultValue || null, props.onChange);
1000
+ let [placeholderValue, setPlaceholderValue] = (0, $7UzoM$useState)(()=>controlledValue || {
1001
+ start: null,
1002
+ end: null
1003
+ });
1004
+ // Reset the placeholder if the value prop is set to null.
1005
+ if (controlledValue == null && placeholderValue.start && placeholderValue.end) {
1006
+ placeholderValue = {
1007
+ start: null,
1008
+ end: null
1009
+ };
1010
+ setPlaceholderValue(placeholderValue);
1011
+ }
1012
+ let value = controlledValue || placeholderValue;
1013
+ let setValue = (value)=>{
1014
+ setPlaceholderValue(value);
1015
+ if ((value === null || value === void 0 ? void 0 : value.start) && value.end) setControlledValue(value);
1016
+ else setControlledValue(null);
1017
+ };
1018
+ let v = (value === null || value === void 0 ? void 0 : value.start) || (value === null || value === void 0 ? void 0 : value.end) || props.placeholderValue;
1019
+ let [granularity] = (0, $35a22f14a1f04b11$export$2440da353cedad43)(v, props.granularity);
1020
+ let hasTime = granularity === "hour" || granularity === "minute" || granularity === "second";
1021
+ var _props_shouldCloseOnSelect;
1022
+ let shouldCloseOnSelect = (_props_shouldCloseOnSelect = props.shouldCloseOnSelect) !== null && _props_shouldCloseOnSelect !== void 0 ? _props_shouldCloseOnSelect : true;
1023
+ let [dateRange, setSelectedDateRange] = (0, $7UzoM$useState)(null);
1024
+ let [timeRange, setSelectedTimeRange] = (0, $7UzoM$useState)(null);
1025
+ if (value && value.start && value.end) {
1026
+ dateRange = value;
1027
+ if ("hour" in value.start) timeRange = value;
1028
+ }
1029
+ let commitValue = (dateRange, timeRange)=>{
1030
+ setValue({
1031
+ start: "timeZone" in timeRange.start ? timeRange.start.set((0, $7UzoM$toCalendarDate)(dateRange.start)) : (0, $7UzoM$toCalendarDateTime)(dateRange.start, timeRange.start),
1032
+ end: "timeZone" in timeRange.end ? timeRange.end.set((0, $7UzoM$toCalendarDate)(dateRange.end)) : (0, $7UzoM$toCalendarDateTime)(dateRange.end, timeRange.end)
1033
+ });
1034
+ setSelectedDateRange(null);
1035
+ setSelectedTimeRange(null);
1036
+ };
1037
+ // Intercept setValue to make sure the Time section is not changed by date selection in Calendar
1038
+ let setDateRange = (range)=>{
1039
+ let shouldClose = typeof shouldCloseOnSelect === "function" ? shouldCloseOnSelect() : shouldCloseOnSelect;
1040
+ if (hasTime) {
1041
+ if (shouldClose || range.start && range.end && (timeRange === null || timeRange === void 0 ? void 0 : timeRange.start) && (timeRange === null || timeRange === void 0 ? void 0 : timeRange.end)) commitValue(range, {
1042
+ start: (timeRange === null || timeRange === void 0 ? void 0 : timeRange.start) || (0, $35a22f14a1f04b11$export$c5221a78ef73c5e9)(props.placeholderValue),
1043
+ end: (timeRange === null || timeRange === void 0 ? void 0 : timeRange.end) || (0, $35a22f14a1f04b11$export$c5221a78ef73c5e9)(props.placeholderValue)
1044
+ });
1045
+ else setSelectedDateRange(range);
1046
+ } else if (range.start && range.end) setValue(range);
1047
+ else setSelectedDateRange(range);
1048
+ if (shouldClose) overlayState.setOpen(false);
1049
+ };
1050
+ let setTimeRange = (range)=>{
1051
+ if ((dateRange === null || dateRange === void 0 ? void 0 : dateRange.start) && (dateRange === null || dateRange === void 0 ? void 0 : dateRange.end) && range.start && range.end) commitValue(dateRange, range);
1052
+ else setSelectedTimeRange(range);
1053
+ };
1054
+ let validationState = props.validationState || (value != null && ((0, $35a22f14a1f04b11$export$eac50920cf2fd59a)(value.start, props.minValue, props.maxValue) || (0, $35a22f14a1f04b11$export$eac50920cf2fd59a)(value.end, props.minValue, props.maxValue) || value.end != null && value.start != null && value.end.compare(value.start) < 0 || (value === null || value === void 0 ? void 0 : value.start) && ((_props_isDateUnavailable = props.isDateUnavailable) === null || _props_isDateUnavailable === void 0 ? void 0 : _props_isDateUnavailable.call(props, value.start)) || (value === null || value === void 0 ? void 0 : value.end) && ((_props_isDateUnavailable1 = props.isDateUnavailable) === null || _props_isDateUnavailable1 === void 0 ? void 0 : _props_isDateUnavailable1.call(props, value.end))) ? "invalid" : null);
1055
+ return {
1056
+ value: value,
1057
+ setValue: setValue,
1058
+ dateRange: dateRange,
1059
+ timeRange: timeRange,
1060
+ granularity: granularity,
1061
+ hasTime: hasTime,
1062
+ setDate (part, date) {
1063
+ setDateRange({
1064
+ ...dateRange,
1065
+ [part]: date
1066
+ });
1067
+ },
1068
+ setTime (part, time) {
1069
+ setTimeRange({
1070
+ ...timeRange,
1071
+ [part]: time
1072
+ });
1073
+ },
1074
+ setDateTime (part, dateTime) {
1075
+ setValue({
1076
+ ...value,
1077
+ [part]: dateTime
1078
+ });
1079
+ },
1080
+ setDateRange: setDateRange,
1081
+ setTimeRange: setTimeRange,
1082
+ ...overlayState,
1083
+ setOpen (isOpen) {
1084
+ // Commit the selected date range when the calendar is closed. Use a placeholder time if one wasn't set.
1085
+ // If only the time range was set and not the date range, don't commit. The state will be preserved until
1086
+ // the user opens the popover again.
1087
+ if (!isOpen && !((value === null || value === void 0 ? void 0 : value.start) && (value === null || value === void 0 ? void 0 : value.end)) && (dateRange === null || dateRange === void 0 ? void 0 : dateRange.start) && (dateRange === null || dateRange === void 0 ? void 0 : dateRange.end) && hasTime) commitValue(dateRange, {
1088
+ start: (timeRange === null || timeRange === void 0 ? void 0 : timeRange.start) || (0, $35a22f14a1f04b11$export$c5221a78ef73c5e9)(props.placeholderValue),
1089
+ end: (timeRange === null || timeRange === void 0 ? void 0 : timeRange.end) || (0, $35a22f14a1f04b11$export$c5221a78ef73c5e9)(props.placeholderValue)
1090
+ });
1091
+ overlayState.setOpen(isOpen);
1092
+ },
1093
+ validationState: validationState,
1094
+ formatValue (locale, fieldOptions) {
1095
+ if (!value || !value.start || !value.end) return null;
1096
+ let startTimeZone = "timeZone" in value.start ? value.start.timeZone : undefined;
1097
+ let startGranularity = props.granularity || (value.start && "minute" in value.start ? "minute" : "day");
1098
+ let endTimeZone = "timeZone" in value.end ? value.end.timeZone : undefined;
1099
+ let endGranularity = props.granularity || (value.end && "minute" in value.end ? "minute" : "day");
1100
+ let startOptions = (0, $35a22f14a1f04b11$export$7e319ea407e63bc0)(fieldOptions, {
1101
+ granularity: startGranularity,
1102
+ timeZone: startTimeZone,
1103
+ hideTimeZone: props.hideTimeZone,
1104
+ hourCycle: props.hourCycle,
1105
+ showEra: value.start.calendar.identifier === "gregory" && value.start.era === "BC" || value.end.calendar.identifier === "gregory" && value.end.era === "BC"
1106
+ });
1107
+ let startDate = value.start.toDate(startTimeZone || "UTC");
1108
+ let endDate = value.end.toDate(endTimeZone || "UTC");
1109
+ let startFormatter = new (0, $7UzoM$DateFormatter)(locale, startOptions);
1110
+ let endFormatter;
1111
+ if (startTimeZone === endTimeZone && startGranularity === endGranularity && value.start.compare(value.end) !== 0) {
1112
+ // Use formatRange, as it results in shorter output when some of the fields
1113
+ // are shared between the start and end dates (e.g. the same month).
1114
+ // Formatting will fail if the end date is before the start date. Fall back below when that happens.
1115
+ try {
1116
+ let parts = startFormatter.formatRangeToParts(startDate, endDate);
1117
+ // Find the separator between the start and end date. This is determined
1118
+ // by finding the last shared literal before the end range.
1119
+ let separatorIndex = -1;
1120
+ for(let i = 0; i < parts.length; i++){
1121
+ let part = parts[i];
1122
+ if (part.source === "shared" && part.type === "literal") separatorIndex = i;
1123
+ else if (part.source === "endRange") break;
1124
+ }
1125
+ // Now we can combine the parts into start and end strings.
1126
+ let start = "";
1127
+ let end = "";
1128
+ for(let i1 = 0; i1 < parts.length; i1++){
1129
+ if (i1 < separatorIndex) start += parts[i1].value;
1130
+ else if (i1 > separatorIndex) end += parts[i1].value;
1131
+ }
1132
+ return {
1133
+ start: start,
1134
+ end: end
1135
+ };
1136
+ } catch (e) {
1137
+ // ignore
1138
+ }
1139
+ endFormatter = startFormatter;
1140
+ } else {
1141
+ let endOptions = (0, $35a22f14a1f04b11$export$7e319ea407e63bc0)(fieldOptions, {
1142
+ granularity: endGranularity,
1143
+ timeZone: endTimeZone,
1144
+ hideTimeZone: props.hideTimeZone,
1145
+ hourCycle: props.hourCycle
1146
+ });
1147
+ endFormatter = new (0, $7UzoM$DateFormatter)(locale, endOptions);
1148
+ }
1149
+ return {
1150
+ start: startFormatter.format(startDate),
1151
+ end: endFormatter.format(endDate)
1152
+ };
1153
+ }
1154
+ };
1155
+ }
1156
+
1157
+
1158
+ /*
1159
+ * Copyright 2020 Adobe. All rights reserved.
1160
+ * This file is licensed to you under the Apache License, Version 2.0 (the 'License');
1161
+ * you may not use this file except in compliance with the License. You may obtain a copy
1162
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
1163
+ *
1164
+ * Unless required by applicable law or agreed to in writing, software distributed under
1165
+ * the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
1166
+ * OF ANY KIND, either express or implied. See the License for the specific language
1167
+ * governing permissions and limitations under the License.
1168
+ */
1169
+
1170
+
1171
+
1172
+ function $eff5d8ee529ac4bb$export$fd53cef0cc796101(props) {
1173
+ let { placeholderValue: placeholderValue = new (0, $7UzoM$Time)() , minValue: minValue , maxValue: maxValue , granularity: granularity } = props;
1174
+ let [value, setValue] = (0, $7UzoM$useControlledState)(props.value, props.defaultValue, props.onChange);
1175
+ let v = value || placeholderValue;
1176
+ let day = v && "day" in v ? v : undefined;
1177
+ let placeholderDate = (0, $7UzoM$useMemo)(()=>$eff5d8ee529ac4bb$var$convertValue(placeholderValue), [
1178
+ placeholderValue
1179
+ ]);
1180
+ let minDate = (0, $7UzoM$useMemo)(()=>$eff5d8ee529ac4bb$var$convertValue(minValue, day), [
1181
+ minValue,
1182
+ day
1183
+ ]);
1184
+ let maxDate = (0, $7UzoM$useMemo)(()=>$eff5d8ee529ac4bb$var$convertValue(maxValue, day), [
1185
+ maxValue,
1186
+ day
1187
+ ]);
1188
+ let dateTime = (0, $7UzoM$useMemo)(()=>value == null ? null : $eff5d8ee529ac4bb$var$convertValue(value), [
1189
+ value
1190
+ ]);
1191
+ let onChange = (newValue)=>{
1192
+ setValue(v && "day" in v ? newValue : newValue && (0, $7UzoM$toTime)(newValue));
1193
+ };
1194
+ return (0, $3c0fc76039f1c516$export$60e84778edff6d26)({
1195
+ ...props,
1196
+ value: dateTime,
1197
+ defaultValue: undefined,
1198
+ minValue: minDate,
1199
+ maxValue: maxDate,
1200
+ onChange: onChange,
1201
+ granularity: granularity || "minute",
1202
+ maxGranularity: "hour",
1203
+ placeholderValue: placeholderDate,
1204
+ // Calendar should not matter for time fields.
1205
+ createCalendar: ()=>new (0, $7UzoM$GregorianCalendar)()
1206
+ });
1207
+ }
1208
+ function $eff5d8ee529ac4bb$var$convertValue(value, date = (0, $7UzoM$today)((0, $7UzoM$getLocalTimeZone)())) {
1209
+ if (!value) return null;
1210
+ if ("day" in value) return value;
1211
+ return (0, $7UzoM$toCalendarDateTime)(date, value);
1212
+ }
1213
+
1214
+
1215
+
1216
+
1217
+ export {$ab5bf3f618090389$export$87194bb378cc3ac2 as useDatePickerState, $3c0fc76039f1c516$export$60e84778edff6d26 as useDateFieldState, $93c38a5e28be6249$export$e50a61c1de9f574 as useDateRangePickerState, $eff5d8ee529ac4bb$export$fd53cef0cc796101 as useTimeFieldState};
1218
+ //# sourceMappingURL=module.js.map