@react-stately/datepicker 3.9.2 → 3.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/import.mjs +4 -1514
  2. package/dist/intlStrings.main.js +108 -0
  3. package/dist/intlStrings.main.js.map +1 -0
  4. package/dist/intlStrings.mjs +110 -0
  5. package/dist/intlStrings.module.js +110 -0
  6. package/dist/intlStrings.module.js.map +1 -0
  7. package/dist/main.js +8 -1518
  8. package/dist/main.js.map +1 -1
  9. package/dist/module.js +4 -1514
  10. package/dist/module.js.map +1 -1
  11. package/dist/placeholders.main.js +409 -0
  12. package/dist/placeholders.main.js.map +1 -0
  13. package/dist/placeholders.mjs +404 -0
  14. package/dist/placeholders.module.js +404 -0
  15. package/dist/placeholders.module.js.map +1 -0
  16. package/dist/types.d.ts.map +1 -1
  17. package/dist/useDateFieldState.main.js +441 -0
  18. package/dist/useDateFieldState.main.js.map +1 -0
  19. package/dist/useDateFieldState.mjs +436 -0
  20. package/dist/useDateFieldState.module.js +436 -0
  21. package/dist/useDateFieldState.module.js.map +1 -0
  22. package/dist/useDatePickerState.main.js +130 -0
  23. package/dist/useDatePickerState.main.js.map +1 -0
  24. package/dist/useDatePickerState.mjs +125 -0
  25. package/dist/useDatePickerState.module.js +125 -0
  26. package/dist/useDatePickerState.module.js.map +1 -0
  27. package/dist/useDateRangePickerState.main.js +237 -0
  28. package/dist/useDateRangePickerState.main.js.map +1 -0
  29. package/dist/useDateRangePickerState.mjs +232 -0
  30. package/dist/useDateRangePickerState.module.js +232 -0
  31. package/dist/useDateRangePickerState.module.js.map +1 -0
  32. package/dist/useTimeFieldState.main.js +86 -0
  33. package/dist/useTimeFieldState.main.js.map +1 -0
  34. package/dist/useTimeFieldState.mjs +81 -0
  35. package/dist/useTimeFieldState.module.js +81 -0
  36. package/dist/useTimeFieldState.module.js.map +1 -0
  37. package/dist/utils.main.js +190 -0
  38. package/dist/utils.main.js.map +1 -0
  39. package/dist/utils.mjs +179 -0
  40. package/dist/utils.module.js +179 -0
  41. package/dist/utils.module.js.map +1 -0
  42. package/package.json +9 -9
  43. package/src/utils.ts +2 -1
package/dist/import.mjs CHANGED
@@ -1,69 +1,8 @@
1
- import $b3427c06585c22a0$exports from "./ar-AE.mjs";
2
- import $d282528f459122b9$exports from "./bg-BG.mjs";
3
- import $2d5eecd634a9ca45$exports from "./cs-CZ.mjs";
4
- import $c8e2288226c24a67$exports from "./da-DK.mjs";
5
- import $6f5745e389c346d7$exports from "./de-DE.mjs";
6
- import $8c882ccf4300d1da$exports from "./el-GR.mjs";
7
- import $22195056771860be$exports from "./en-US.mjs";
8
- import $cedfa43b4e2a5906$exports from "./es-ES.mjs";
9
- import $eeeaa8daee3601c7$exports from "./et-EE.mjs";
10
- import $35e0614a49b3bb40$exports from "./fi-FI.mjs";
11
- import $929bc63f7705a78f$exports from "./fr-FR.mjs";
12
- import $9a28d073b034d183$exports from "./he-IL.mjs";
13
- import $7743e79780ebcca3$exports from "./hr-HR.mjs";
14
- import $3351817a04898858$exports from "./hu-HU.mjs";
15
- import $4120bdb1d03484db$exports from "./it-IT.mjs";
16
- import $65e5e1569f34ea4f$exports from "./ja-JP.mjs";
17
- import $d34552a7550967e7$exports from "./ko-KR.mjs";
18
- import $8f855bffe63f6eca$exports from "./lt-LT.mjs";
19
- import $ce40f46d09034645$exports from "./lv-LV.mjs";
20
- import $dd1a9a73340c793e$exports from "./nb-NO.mjs";
21
- import $4ee1fb3f0cbe6f59$exports from "./nl-NL.mjs";
22
- import $c85829aebb0bc94b$exports from "./pl-PL.mjs";
23
- import $27f5cd2291ca8a02$exports from "./pt-BR.mjs";
24
- import $e046fdccd69bea8e$exports from "./pt-PT.mjs";
25
- import $fa5f88e804986547$exports from "./ro-RO.mjs";
26
- import $28e4714602d1b568$exports from "./ru-RU.mjs";
27
- import $4e3bc8cf783ad569$exports from "./sk-SK.mjs";
28
- import $bee07513333bdc15$exports from "./sl-SI.mjs";
29
- import $7ed9c6fad16a15ec$exports from "./sr-SP.mjs";
30
- import $8bef6d5a236de86c$exports from "./sv-SE.mjs";
31
- import $098b9a2d2340cfc5$exports from "./tr-TR.mjs";
32
- import $54a862ea7fad7419$exports from "./uk-UA.mjs";
33
- import $e6cc491d590dfda5$exports from "./zh-CN.mjs";
34
- import $9aebf53181a474bd$exports from "./zh-TW.mjs";
35
- 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, toZoned as $7UzoM$toZoned, toTime as $7UzoM$toTime, today as $7UzoM$today, getLocalTimeZone as $7UzoM$getLocalTimeZone} from "@internationalized/date";
36
- import {useFormValidationState as $7UzoM$useFormValidationState, mergeValidation as $7UzoM$mergeValidation, VALID_VALIDITY_STATE as $7UzoM$VALID_VALIDITY_STATE} from "@react-stately/form";
37
- import {useOverlayTriggerState as $7UzoM$useOverlayTriggerState} from "@react-stately/overlays";
38
- import {useControlledState as $7UzoM$useControlledState} from "@react-stately/utils";
39
- import {useState as $7UzoM$useState, useMemo as $7UzoM$useMemo, useRef as $7UzoM$useRef, useEffect as $7UzoM$useEffect, useCallback as $7UzoM$useCallback} from "react";
40
- import {LocalizedStringDictionary as $7UzoM$LocalizedStringDictionary, LocalizedStringFormatter as $7UzoM$LocalizedStringFormatter} from "@internationalized/string";
1
+ import {useDatePickerState as $ab5bf3f618090389$export$87194bb378cc3ac2} from "./useDatePickerState.mjs";
2
+ import {useDateFieldState as $3c0fc76039f1c516$export$60e84778edff6d26} from "./useDateFieldState.mjs";
3
+ import {useDateRangePickerState as $93c38a5e28be6249$export$e50a61c1de9f574} from "./useDateRangePickerState.mjs";
4
+ import {useTimeFieldState as $eff5d8ee529ac4bb$export$fd53cef0cc796101} from "./useTimeFieldState.mjs";
41
5
 
42
-
43
- function $parcel$interopDefault(a) {
44
- return a && a.__esModule ? a.default : a;
45
- }
46
- /*
47
- * Copyright 2020 Adobe. All rights reserved.
48
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
49
- * you may not use this file except in compliance with the License. You may obtain a copy
50
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
51
- *
52
- * Unless required by applicable law or agreed to in writing, software distributed under
53
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
54
- * OF ANY KIND, either express or implied. See the License for the specific language
55
- * governing permissions and limitations under the License.
56
- */ /*
57
- * Copyright 2020 Adobe. All rights reserved.
58
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
59
- * you may not use this file except in compliance with the License. You may obtain a copy
60
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
61
- *
62
- * Unless required by applicable law or agreed to in writing, software distributed under
63
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
64
- * OF ANY KIND, either express or implied. See the License for the specific language
65
- * governing permissions and limitations under the License.
66
- */
67
6
  /*
68
7
  * Copyright 2020 Adobe. All rights reserved.
69
8
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -75,1456 +14,7 @@ function $parcel$interopDefault(a) {
75
14
  * OF ANY KIND, either express or implied. See the License for the specific language
76
15
  * governing permissions and limitations under the License.
77
16
  */
78
- var $452ac34de8c2444e$exports = {};
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
-
113
- $452ac34de8c2444e$exports = {
114
- "ar-AE": $b3427c06585c22a0$exports,
115
- "bg-BG": $d282528f459122b9$exports,
116
- "cs-CZ": $2d5eecd634a9ca45$exports,
117
- "da-DK": $c8e2288226c24a67$exports,
118
- "de-DE": $6f5745e389c346d7$exports,
119
- "el-GR": $8c882ccf4300d1da$exports,
120
- "en-US": $22195056771860be$exports,
121
- "es-ES": $cedfa43b4e2a5906$exports,
122
- "et-EE": $eeeaa8daee3601c7$exports,
123
- "fi-FI": $35e0614a49b3bb40$exports,
124
- "fr-FR": $929bc63f7705a78f$exports,
125
- "he-IL": $9a28d073b034d183$exports,
126
- "hr-HR": $7743e79780ebcca3$exports,
127
- "hu-HU": $3351817a04898858$exports,
128
- "it-IT": $4120bdb1d03484db$exports,
129
- "ja-JP": $65e5e1569f34ea4f$exports,
130
- "ko-KR": $d34552a7550967e7$exports,
131
- "lt-LT": $8f855bffe63f6eca$exports,
132
- "lv-LV": $ce40f46d09034645$exports,
133
- "nb-NO": $dd1a9a73340c793e$exports,
134
- "nl-NL": $4ee1fb3f0cbe6f59$exports,
135
- "pl-PL": $c85829aebb0bc94b$exports,
136
- "pt-BR": $27f5cd2291ca8a02$exports,
137
- "pt-PT": $e046fdccd69bea8e$exports,
138
- "ro-RO": $fa5f88e804986547$exports,
139
- "ru-RU": $28e4714602d1b568$exports,
140
- "sk-SK": $4e3bc8cf783ad569$exports,
141
- "sl-SI": $bee07513333bdc15$exports,
142
- "sr-SP": $7ed9c6fad16a15ec$exports,
143
- "sv-SE": $8bef6d5a236de86c$exports,
144
- "tr-TR": $098b9a2d2340cfc5$exports,
145
- "uk-UA": $54a862ea7fad7419$exports,
146
- "zh-CN": $e6cc491d590dfda5$exports,
147
- "zh-TW": $9aebf53181a474bd$exports
148
- };
149
-
150
-
151
-
152
-
153
-
154
- const $35a22f14a1f04b11$var$dictionary = new (0, $7UzoM$LocalizedStringDictionary)((0, (/*@__PURE__*/$parcel$interopDefault($452ac34de8c2444e$exports))));
155
- function $35a22f14a1f04b11$var$getLocale() {
156
- // Match browser language setting here, NOT react-aria's I18nProvider, so that we match other browser-provided
157
- // validation messages, which to not respect our provider's language.
158
- // @ts-ignore
159
- return typeof navigator !== "undefined" && (navigator.language || navigator.userLanguage) || "en-US";
160
- }
161
- function $35a22f14a1f04b11$export$f18627323ab57ac0(value, minValue, maxValue, isDateUnavailable, options) {
162
- let rangeOverflow = value != null && maxValue != null && value.compare(maxValue) > 0;
163
- let rangeUnderflow = value != null && minValue != null && value.compare(minValue) < 0;
164
- let isUnavailable = value != null && (isDateUnavailable === null || isDateUnavailable === void 0 ? void 0 : isDateUnavailable(value)) || false;
165
- let isInvalid = rangeOverflow || rangeUnderflow || isUnavailable;
166
- let errors = [];
167
- if (isInvalid) {
168
- let locale = $35a22f14a1f04b11$var$getLocale();
169
- let strings = (0, $7UzoM$LocalizedStringDictionary).getGlobalDictionaryForPackage("@react-stately/datepicker") || $35a22f14a1f04b11$var$dictionary;
170
- let formatter = new (0, $7UzoM$LocalizedStringFormatter)(locale, strings);
171
- let dateFormatter = new (0, $7UzoM$DateFormatter)(locale, $35a22f14a1f04b11$export$7e319ea407e63bc0({}, options));
172
- let timeZone = dateFormatter.resolvedOptions().timeZone;
173
- if (rangeUnderflow) errors.push(formatter.format("rangeUnderflow", {
174
- minValue: dateFormatter.format(minValue.toDate(timeZone))
175
- }));
176
- if (rangeOverflow) errors.push(formatter.format("rangeOverflow", {
177
- maxValue: dateFormatter.format(maxValue.toDate(timeZone))
178
- }));
179
- if (isUnavailable) errors.push(formatter.format("unavailableDate"));
180
- }
181
- return {
182
- isInvalid: isInvalid,
183
- validationErrors: errors,
184
- validationDetails: {
185
- badInput: isUnavailable,
186
- customError: false,
187
- patternMismatch: false,
188
- rangeOverflow: rangeOverflow,
189
- rangeUnderflow: rangeUnderflow,
190
- stepMismatch: false,
191
- tooLong: false,
192
- tooShort: false,
193
- typeMismatch: false,
194
- valueMissing: false,
195
- valid: !isInvalid
196
- }
197
- };
198
- }
199
- function $35a22f14a1f04b11$export$80ff8fc0ae339c13(value, minValue, maxValue, isDateUnavailable, options) {
200
- let startValidation = $35a22f14a1f04b11$export$f18627323ab57ac0(value === null || value === void 0 ? void 0 : value.start, minValue, maxValue, isDateUnavailable, options);
201
- let endValidation = $35a22f14a1f04b11$export$f18627323ab57ac0(value === null || value === void 0 ? void 0 : value.end, minValue, maxValue, isDateUnavailable, options);
202
- let result = (0, $7UzoM$mergeValidation)(startValidation, endValidation);
203
- if (value.end != null && value.start != null && value.end.compare(value.start) < 0) result = (0, $7UzoM$mergeValidation)(result, {
204
- isInvalid: true,
205
- validationErrors: [
206
- $35a22f14a1f04b11$var$dictionary.getStringForLocale("rangeReversed", $35a22f14a1f04b11$var$getLocale())
207
- ],
208
- validationDetails: {
209
- ...(0, $7UzoM$VALID_VALIDITY_STATE),
210
- rangeUnderflow: true,
211
- rangeOverflow: true,
212
- valid: false
213
- }
214
- });
215
- return result;
216
- }
217
- const $35a22f14a1f04b11$var$DEFAULT_FIELD_OPTIONS = {
218
- year: "numeric",
219
- month: "numeric",
220
- day: "numeric",
221
- hour: "numeric",
222
- minute: "2-digit",
223
- second: "2-digit"
224
- };
225
- const $35a22f14a1f04b11$var$TWO_DIGIT_FIELD_OPTIONS = {
226
- year: "numeric",
227
- month: "2-digit",
228
- day: "2-digit",
229
- hour: "2-digit",
230
- minute: "2-digit",
231
- second: "2-digit"
232
- };
233
- function $35a22f14a1f04b11$export$7e319ea407e63bc0(fieldOptions, options) {
234
- let defaultFieldOptions = options.shouldForceLeadingZeros ? $35a22f14a1f04b11$var$TWO_DIGIT_FIELD_OPTIONS : $35a22f14a1f04b11$var$DEFAULT_FIELD_OPTIONS;
235
- fieldOptions = {
236
- ...defaultFieldOptions,
237
- ...fieldOptions
238
- };
239
- let granularity = options.granularity || "minute";
240
- let keys = Object.keys(fieldOptions);
241
- var _options_maxGranularity;
242
- let startIdx = keys.indexOf((_options_maxGranularity = options.maxGranularity) !== null && _options_maxGranularity !== void 0 ? _options_maxGranularity : "year");
243
- if (startIdx < 0) startIdx = 0;
244
- let endIdx = keys.indexOf(granularity);
245
- if (endIdx < 0) endIdx = 2;
246
- if (startIdx > endIdx) throw new Error("maxGranularity must be greater than granularity");
247
- let opts = keys.slice(startIdx, endIdx + 1).reduce((opts, key)=>{
248
- opts[key] = fieldOptions[key];
249
- return opts;
250
- }, {});
251
- if (options.hourCycle != null) opts.hour12 = options.hourCycle === 12;
252
- opts.timeZone = options.timeZone || "UTC";
253
- let hasTime = granularity === "hour" || granularity === "minute" || granularity === "second";
254
- if (hasTime && options.timeZone && !options.hideTimeZone) opts.timeZoneName = "short";
255
- if (options.showEra && startIdx === 0) opts.era = "short";
256
- return opts;
257
- }
258
- function $35a22f14a1f04b11$export$c5221a78ef73c5e9(placeholderValue) {
259
- if (placeholderValue && "hour" in placeholderValue) return placeholderValue;
260
- return new (0, $7UzoM$Time)();
261
- }
262
- function $35a22f14a1f04b11$export$61a490a80c552550(value, calendar) {
263
- if (value === null) return null;
264
- if (!value) return undefined;
265
- return (0, $7UzoM$toCalendar)(value, calendar);
266
- }
267
- function $35a22f14a1f04b11$export$66aa2b09de4b1ea5(placeholderValue, granularity, calendar, timeZone) {
268
- if (placeholderValue) return $35a22f14a1f04b11$export$61a490a80c552550(placeholderValue, calendar);
269
- let date = (0, $7UzoM$toCalendar)((0, $7UzoM$now)(timeZone).set({
270
- hour: 0,
271
- minute: 0,
272
- second: 0,
273
- millisecond: 0
274
- }), calendar);
275
- if (granularity === "year" || granularity === "month" || granularity === "day") return (0, $7UzoM$toCalendarDate)(date);
276
- if (!timeZone) return (0, $7UzoM$toCalendarDateTime)(date);
277
- return date;
278
- }
279
- function $35a22f14a1f04b11$export$2440da353cedad43(v, granularity) {
280
- // Compute default granularity and time zone from the value. If the value becomes null, keep the last values.
281
- let defaultTimeZone = v && "timeZone" in v ? v.timeZone : undefined;
282
- let defaultGranularity = v && "minute" in v ? "minute" : "day";
283
- // props.granularity must actually exist in the value if one is provided.
284
- if (v && granularity && !(granularity in v)) throw new Error("Invalid granularity " + granularity + " for value " + v.toString());
285
- let [lastValue, setLastValue] = (0, $7UzoM$useState)([
286
- defaultGranularity,
287
- defaultTimeZone
288
- ]);
289
- // If the granularity or time zone changed, update the last value.
290
- if (v && (lastValue[0] !== defaultGranularity || lastValue[1] !== defaultTimeZone)) setLastValue([
291
- defaultGranularity,
292
- defaultTimeZone
293
- ]);
294
- if (!granularity) granularity = v ? defaultGranularity : lastValue[0];
295
- let timeZone = v ? defaultTimeZone : lastValue[1];
296
- return [
297
- granularity,
298
- timeZone
299
- ];
300
- }
301
-
302
-
303
-
304
-
305
-
306
-
307
- function $ab5bf3f618090389$export$87194bb378cc3ac2(props) {
308
- let overlayState = (0, $7UzoM$useOverlayTriggerState)(props);
309
- let [value, setValue] = (0, $7UzoM$useControlledState)(props.value, props.defaultValue || null, props.onChange);
310
- let v = value || props.placeholderValue;
311
- let [granularity, defaultTimeZone] = (0, $35a22f14a1f04b11$export$2440da353cedad43)(v, props.granularity);
312
- let dateValue = value != null ? value.toDate(defaultTimeZone !== null && defaultTimeZone !== void 0 ? defaultTimeZone : "UTC") : null;
313
- let hasTime = granularity === "hour" || granularity === "minute" || granularity === "second";
314
- var _props_shouldCloseOnSelect;
315
- let shouldCloseOnSelect = (_props_shouldCloseOnSelect = props.shouldCloseOnSelect) !== null && _props_shouldCloseOnSelect !== void 0 ? _props_shouldCloseOnSelect : true;
316
- let [selectedDate, setSelectedDate] = (0, $7UzoM$useState)(null);
317
- let [selectedTime, setSelectedTime] = (0, $7UzoM$useState)(null);
318
- if (value) {
319
- selectedDate = value;
320
- if ("hour" in value) selectedTime = value;
321
- }
322
- // props.granularity must actually exist in the value if one is provided.
323
- if (v && !(granularity in v)) throw new Error("Invalid granularity " + granularity + " for value " + v.toString());
324
- let showEra = (value === null || value === void 0 ? void 0 : value.calendar.identifier) === "gregory" && value.era === "BC";
325
- let formatOpts = (0, $7UzoM$useMemo)(()=>({
326
- granularity: granularity,
327
- timeZone: defaultTimeZone,
328
- hideTimeZone: props.hideTimeZone,
329
- hourCycle: props.hourCycle,
330
- shouldForceLeadingZeros: props.shouldForceLeadingZeros,
331
- showEra: showEra
332
- }), [
333
- granularity,
334
- props.hourCycle,
335
- props.shouldForceLeadingZeros,
336
- defaultTimeZone,
337
- props.hideTimeZone,
338
- showEra
339
- ]);
340
- let { minValue: minValue, maxValue: maxValue, isDateUnavailable: isDateUnavailable } = props;
341
- let builtinValidation = (0, $7UzoM$useMemo)(()=>(0, $35a22f14a1f04b11$export$f18627323ab57ac0)(value, minValue, maxValue, isDateUnavailable, formatOpts), [
342
- value,
343
- minValue,
344
- maxValue,
345
- isDateUnavailable,
346
- formatOpts
347
- ]);
348
- let validation = (0, $7UzoM$useFormValidationState)({
349
- ...props,
350
- value: value,
351
- builtinValidation: builtinValidation
352
- });
353
- let isValueInvalid = validation.displayValidation.isInvalid;
354
- let validationState = props.validationState || (isValueInvalid ? "invalid" : null);
355
- let commitValue = (date, time)=>{
356
- setValue("timeZone" in time ? time.set((0, $7UzoM$toCalendarDate)(date)) : (0, $7UzoM$toCalendarDateTime)(date, time));
357
- setSelectedDate(null);
358
- setSelectedTime(null);
359
- validation.commitValidation();
360
- };
361
- // Intercept setValue to make sure the Time section is not changed by date selection in Calendar
362
- let selectDate = (newValue)=>{
363
- let shouldClose = typeof shouldCloseOnSelect === "function" ? shouldCloseOnSelect() : shouldCloseOnSelect;
364
- if (hasTime) {
365
- if (selectedTime || shouldClose) commitValue(newValue, selectedTime || (0, $35a22f14a1f04b11$export$c5221a78ef73c5e9)(props.placeholderValue));
366
- else setSelectedDate(newValue);
367
- } else {
368
- setValue(newValue);
369
- validation.commitValidation();
370
- }
371
- if (shouldClose) overlayState.setOpen(false);
372
- };
373
- let selectTime = (newValue)=>{
374
- if (selectedDate && newValue) commitValue(selectedDate, newValue);
375
- else setSelectedTime(newValue);
376
- };
377
- return {
378
- ...validation,
379
- value: value,
380
- setValue: setValue,
381
- dateValue: selectedDate,
382
- timeValue: selectedTime,
383
- setDateValue: selectDate,
384
- setTimeValue: selectTime,
385
- granularity: granularity,
386
- hasTime: hasTime,
387
- ...overlayState,
388
- setOpen (isOpen) {
389
- // Commit the selected date when the calendar is closed. Use a placeholder time if one wasn't set.
390
- // If only the time was set and not the date, don't commit. The state will be preserved until
391
- // the user opens the popover again.
392
- if (!isOpen && !value && selectedDate && hasTime) commitValue(selectedDate, selectedTime || (0, $35a22f14a1f04b11$export$c5221a78ef73c5e9)(props.placeholderValue));
393
- overlayState.setOpen(isOpen);
394
- },
395
- validationState: validationState,
396
- isInvalid: isValueInvalid,
397
- formatValue (locale, fieldOptions) {
398
- if (!dateValue) return "";
399
- let formatOptions = (0, $35a22f14a1f04b11$export$7e319ea407e63bc0)(fieldOptions, formatOpts);
400
- let formatter = new (0, $7UzoM$DateFormatter)(locale, formatOptions);
401
- return formatter.format(dateValue);
402
- }
403
- };
404
- }
405
-
406
-
407
- /*
408
- * Copyright 2020 Adobe. All rights reserved.
409
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
410
- * you may not use this file except in compliance with the License. You may obtain a copy
411
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
412
- *
413
- * Unless required by applicable law or agreed to in writing, software distributed under
414
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
415
- * OF ANY KIND, either express or implied. See the License for the specific language
416
- * governing permissions and limitations under the License.
417
- */
418
-
419
-
420
- /*
421
- * Copyright 2020 Adobe. All rights reserved.
422
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
423
- * you may not use this file except in compliance with the License. You may obtain a copy
424
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
425
- *
426
- * Unless required by applicable law or agreed to in writing, software distributed under
427
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
428
- * OF ANY KIND, either express or implied. See the License for the specific language
429
- * governing permissions and limitations under the License.
430
- */
431
- // These placeholders are based on the strings used by the <input type="date">
432
- // implementations in Chrome and Firefox. Additional languages are supported
433
- // here than React Spectrum's typical translations.
434
- const $3e3ed55ab2966714$var$placeholders = new (0, $7UzoM$LocalizedStringDictionary)({
435
- ach: {
436
- year: "mwaka",
437
- month: "dwe",
438
- day: "nino"
439
- },
440
- af: {
441
- year: "jjjj",
442
- month: "mm",
443
- day: "dd"
444
- },
445
- am: {
446
- year: "\u12D3\u12D3\u12D3\u12D3",
447
- month: "\u121A\u121C",
448
- day: "\u1240\u1240"
449
- },
450
- an: {
451
- year: "aaaa",
452
- month: "mm",
453
- day: "dd"
454
- },
455
- ar: {
456
- year: "\u0633\u0646\u0629",
457
- month: "\u0634\u0647\u0631",
458
- day: "\u064A\u0648\u0645"
459
- },
460
- ast: {
461
- year: "aaaa",
462
- month: "mm",
463
- day: "dd"
464
- },
465
- az: {
466
- year: "iiii",
467
- month: "aa",
468
- day: "gg"
469
- },
470
- be: {
471
- year: "\u0433\u0433\u0433\u0433",
472
- month: "\u043C\u043C",
473
- day: "\u0434\u0434"
474
- },
475
- bg: {
476
- year: "\u0433\u0433\u0433\u0433",
477
- month: "\u043C\u043C",
478
- day: "\u0434\u0434"
479
- },
480
- bn: {
481
- year: "yyyy",
482
- month: "\u09AE\u09BF\u09AE\u09BF",
483
- day: "dd"
484
- },
485
- br: {
486
- year: "bbbb",
487
- month: "mm",
488
- day: "dd"
489
- },
490
- bs: {
491
- year: "gggg",
492
- month: "mm",
493
- day: "dd"
494
- },
495
- ca: {
496
- year: "aaaa",
497
- month: "mm",
498
- day: "dd"
499
- },
500
- cak: {
501
- year: "jjjj",
502
- month: "ii",
503
- day: "q'q'"
504
- },
505
- ckb: {
506
- year: "\u0633\u0627\u06B5",
507
- month: "\u0645\u0627\u0646\u06AF",
508
- day: "\u0695\u06C6\u0698"
509
- },
510
- cs: {
511
- year: "rrrr",
512
- month: "mm",
513
- day: "dd"
514
- },
515
- cy: {
516
- year: "bbbb",
517
- month: "mm",
518
- day: "dd"
519
- },
520
- da: {
521
- year: "\xe5\xe5\xe5\xe5",
522
- month: "mm",
523
- day: "dd"
524
- },
525
- de: {
526
- year: "jjjj",
527
- month: "mm",
528
- day: "tt"
529
- },
530
- dsb: {
531
- year: "llll",
532
- month: "mm",
533
- day: "\u017A\u017A"
534
- },
535
- el: {
536
- year: "\u03B5\u03B5\u03B5\u03B5",
537
- month: "\u03BC\u03BC",
538
- day: "\u03B7\u03B7"
539
- },
540
- en: {
541
- year: "yyyy",
542
- month: "mm",
543
- day: "dd"
544
- },
545
- eo: {
546
- year: "jjjj",
547
- month: "mm",
548
- day: "tt"
549
- },
550
- es: {
551
- year: "aaaa",
552
- month: "mm",
553
- day: "dd"
554
- },
555
- et: {
556
- year: "aaaa",
557
- month: "kk",
558
- day: "pp"
559
- },
560
- eu: {
561
- year: "uuuu",
562
- month: "hh",
563
- day: "ee"
564
- },
565
- fa: {
566
- year: "\u0633\u0627\u0644",
567
- month: "\u0645\u0627\u0647",
568
- day: "\u0631\u0648\u0632"
569
- },
570
- ff: {
571
- year: "hhhh",
572
- month: "ll",
573
- day: "\xf1\xf1"
574
- },
575
- fi: {
576
- year: "vvvv",
577
- month: "kk",
578
- day: "pp"
579
- },
580
- fr: {
581
- year: "aaaa",
582
- month: "mm",
583
- day: "jj"
584
- },
585
- fy: {
586
- year: "jjjj",
587
- month: "mm",
588
- day: "dd"
589
- },
590
- ga: {
591
- year: "bbbb",
592
- month: "mm",
593
- day: "ll"
594
- },
595
- gd: {
596
- year: "bbbb",
597
- month: "mm",
598
- day: "ll"
599
- },
600
- gl: {
601
- year: "aaaa",
602
- month: "mm",
603
- day: "dd"
604
- },
605
- he: {
606
- year: "\u05E9\u05E0\u05D4",
607
- month: "\u05D7\u05D5\u05D3\u05E9",
608
- day: "\u05D9\u05D5\u05DD"
609
- },
610
- hr: {
611
- year: "gggg",
612
- month: "mm",
613
- day: "dd"
614
- },
615
- hsb: {
616
- year: "llll",
617
- month: "mm",
618
- day: "dd"
619
- },
620
- hu: {
621
- year: "\xe9\xe9\xe9\xe9",
622
- month: "hh",
623
- day: "nn"
624
- },
625
- ia: {
626
- year: "aaaa",
627
- month: "mm",
628
- day: "dd"
629
- },
630
- id: {
631
- year: "tttt",
632
- month: "bb",
633
- day: "hh"
634
- },
635
- it: {
636
- year: "aaaa",
637
- month: "mm",
638
- day: "gg"
639
- },
640
- ja: {
641
- year: " \u5E74 ",
642
- month: "\u6708",
643
- day: "\u65E5"
644
- },
645
- ka: {
646
- year: "\u10EC\u10EC\u10EC\u10EC",
647
- month: "\u10D7\u10D7",
648
- day: "\u10E0\u10E0"
649
- },
650
- kk: {
651
- year: "\u0436\u0436\u0436\u0436",
652
- month: "\u0430\u0430",
653
- day: "\u043A\u043A"
654
- },
655
- kn: {
656
- year: "\u0CB5\u0CB5\u0CB5\u0CB5",
657
- month: "\u0CAE\u0CBF\u0CAE\u0CC0",
658
- day: "\u0CA6\u0CBF\u0CA6\u0CBF"
659
- },
660
- ko: {
661
- year: "\uC5F0\uB3C4",
662
- month: "\uC6D4",
663
- day: "\uC77C"
664
- },
665
- lb: {
666
- year: "jjjj",
667
- month: "mm",
668
- day: "dd"
669
- },
670
- lo: {
671
- year: "\u0E9B\u0E9B\u0E9B\u0E9B",
672
- month: "\u0E94\u0E94",
673
- day: "\u0EA7\u0EA7"
674
- },
675
- lt: {
676
- year: "mmmm",
677
- month: "mm",
678
- day: "dd"
679
- },
680
- lv: {
681
- year: "gggg",
682
- month: "mm",
683
- day: "dd"
684
- },
685
- meh: {
686
- year: "aaaa",
687
- month: "mm",
688
- day: "dd"
689
- },
690
- ml: {
691
- year: "\u0D35\u0D7C\u0D37\u0D02",
692
- month: "\u0D2E\u0D3E\u0D38\u0D02",
693
- day: "\u0D24\u0D40\u0D2F\u0D24\u0D3F"
694
- },
695
- ms: {
696
- year: "tttt",
697
- month: "mm",
698
- day: "hh"
699
- },
700
- nl: {
701
- year: "jjjj",
702
- month: "mm",
703
- day: "dd"
704
- },
705
- nn: {
706
- year: "\xe5\xe5\xe5\xe5",
707
- month: "mm",
708
- day: "dd"
709
- },
710
- no: {
711
- year: "\xe5\xe5\xe5\xe5",
712
- month: "mm",
713
- day: "dd"
714
- },
715
- oc: {
716
- year: "aaaa",
717
- month: "mm",
718
- day: "jj"
719
- },
720
- pl: {
721
- year: "rrrr",
722
- month: "mm",
723
- day: "dd"
724
- },
725
- pt: {
726
- year: "aaaa",
727
- month: "mm",
728
- day: "dd"
729
- },
730
- rm: {
731
- year: "oooo",
732
- month: "mm",
733
- day: "dd"
734
- },
735
- ro: {
736
- year: "aaaa",
737
- month: "ll",
738
- day: "zz"
739
- },
740
- ru: {
741
- year: "\u0433\u0433\u0433\u0433",
742
- month: "\u043C\u043C",
743
- day: "\u0434\u0434"
744
- },
745
- sc: {
746
- year: "aaaa",
747
- month: "mm",
748
- day: "dd"
749
- },
750
- scn: {
751
- year: "aaaa",
752
- month: "mm",
753
- day: "jj"
754
- },
755
- sk: {
756
- year: "rrrr",
757
- month: "mm",
758
- day: "dd"
759
- },
760
- sl: {
761
- year: "llll",
762
- month: "mm",
763
- day: "dd"
764
- },
765
- sr: {
766
- year: "\u0433\u0433\u0433\u0433",
767
- month: "\u043C\u043C",
768
- day: "\u0434\u0434"
769
- },
770
- sv: {
771
- year: "\xe5\xe5\xe5\xe5",
772
- month: "mm",
773
- day: "dd"
774
- },
775
- szl: {
776
- year: "rrrr",
777
- month: "mm",
778
- day: "dd"
779
- },
780
- tg: {
781
- year: "\u0441\u0441\u0441\u0441",
782
- month: "\u043C\u043C",
783
- day: "\u0440\u0440"
784
- },
785
- th: {
786
- year: "\u0E1B\u0E1B\u0E1B\u0E1B",
787
- month: "\u0E14\u0E14",
788
- day: "\u0E27\u0E27"
789
- },
790
- tr: {
791
- year: "yyyy",
792
- month: "aa",
793
- day: "gg"
794
- },
795
- uk: {
796
- year: "\u0440\u0440\u0440\u0440",
797
- month: "\u043C\u043C",
798
- day: "\u0434\u0434"
799
- },
800
- "zh-CN": {
801
- year: "\u5E74",
802
- month: "\u6708",
803
- day: "\u65E5"
804
- },
805
- "zh-TW": {
806
- year: "\u5E74",
807
- month: "\u6708",
808
- day: "\u65E5"
809
- }
810
- }, "en");
811
- function $3e3ed55ab2966714$export$d3f5c5e0a5023fa0(field, value, locale) {
812
- // Use the actual placeholder value for the era and day period fields.
813
- if (field === "era" || field === "dayPeriod") return value;
814
- if (field === "year" || field === "month" || field === "day") return $3e3ed55ab2966714$var$placeholders.getStringForLocale(field, locale);
815
- // For time fields (e.g. hour, minute, etc.), use two dashes as the placeholder.
816
- return "\u2013\u2013";
817
- }
818
-
819
-
820
-
821
-
822
- const $3c0fc76039f1c516$var$EDITABLE_SEGMENTS = {
823
- year: true,
824
- month: true,
825
- day: true,
826
- hour: true,
827
- minute: true,
828
- second: true,
829
- dayPeriod: true,
830
- era: true
831
- };
832
- const $3c0fc76039f1c516$var$PAGE_STEP = {
833
- year: 5,
834
- month: 2,
835
- day: 7,
836
- hour: 2,
837
- minute: 15,
838
- second: 15
839
- };
840
- // Node seems to convert everything to lowercase...
841
- const $3c0fc76039f1c516$var$TYPE_MAPPING = {
842
- dayperiod: "dayPeriod"
843
- };
844
- function $3c0fc76039f1c516$export$60e84778edff6d26(props) {
845
- let { locale: locale, createCalendar: createCalendar, hideTimeZone: hideTimeZone, isDisabled: isDisabled, isReadOnly: isReadOnly, isRequired: isRequired, minValue: minValue, maxValue: maxValue, isDateUnavailable: isDateUnavailable } = props;
846
- let v = props.value || props.defaultValue || props.placeholderValue;
847
- let [granularity, defaultTimeZone] = (0, $35a22f14a1f04b11$export$2440da353cedad43)(v, props.granularity);
848
- let timeZone = defaultTimeZone || "UTC";
849
- // props.granularity must actually exist in the value if one is provided.
850
- if (v && !(granularity in v)) throw new Error("Invalid granularity " + granularity + " for value " + v.toString());
851
- let defaultFormatter = (0, $7UzoM$useMemo)(()=>new (0, $7UzoM$DateFormatter)(locale), [
852
- locale
853
- ]);
854
- let calendar = (0, $7UzoM$useMemo)(()=>createCalendar(defaultFormatter.resolvedOptions().calendar), [
855
- createCalendar,
856
- defaultFormatter
857
- ]);
858
- let [value, setDate] = (0, $7UzoM$useControlledState)(props.value, props.defaultValue, props.onChange);
859
- let calendarValue = (0, $7UzoM$useMemo)(()=>(0, $35a22f14a1f04b11$export$61a490a80c552550)(value, calendar), [
860
- value,
861
- calendar
862
- ]);
863
- // We keep track of the placeholder date separately in state so that onChange is not called
864
- // until all segments are set. If the value === null (not undefined), then assume the component
865
- // is controlled, so use the placeholder as the value until all segments are entered so it doesn't
866
- // change from uncontrolled to controlled and emit a warning.
867
- let [placeholderDate, setPlaceholderDate] = (0, $7UzoM$useState)(()=>(0, $35a22f14a1f04b11$export$66aa2b09de4b1ea5)(props.placeholderValue, granularity, calendar, defaultTimeZone));
868
- let val = calendarValue || placeholderDate;
869
- let showEra = calendar.identifier === "gregory" && val.era === "BC";
870
- let formatOpts = (0, $7UzoM$useMemo)(()=>{
871
- var _props_maxGranularity;
872
- return {
873
- granularity: granularity,
874
- maxGranularity: (_props_maxGranularity = props.maxGranularity) !== null && _props_maxGranularity !== void 0 ? _props_maxGranularity : "year",
875
- timeZone: defaultTimeZone,
876
- hideTimeZone: hideTimeZone,
877
- hourCycle: props.hourCycle,
878
- showEra: showEra,
879
- shouldForceLeadingZeros: props.shouldForceLeadingZeros
880
- };
881
- }, [
882
- props.maxGranularity,
883
- granularity,
884
- props.hourCycle,
885
- props.shouldForceLeadingZeros,
886
- defaultTimeZone,
887
- hideTimeZone,
888
- showEra
889
- ]);
890
- let opts = (0, $7UzoM$useMemo)(()=>(0, $35a22f14a1f04b11$export$7e319ea407e63bc0)({}, formatOpts), [
891
- formatOpts
892
- ]);
893
- let dateFormatter = (0, $7UzoM$useMemo)(()=>new (0, $7UzoM$DateFormatter)(locale, opts), [
894
- locale,
895
- opts
896
- ]);
897
- let resolvedOptions = (0, $7UzoM$useMemo)(()=>dateFormatter.resolvedOptions(), [
898
- dateFormatter
899
- ]);
900
- // Determine how many editable segments there are for validation purposes.
901
- // The result is cached for performance.
902
- 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), {}), [
903
- dateFormatter
904
- ]);
905
- let [validSegments, setValidSegments] = (0, $7UzoM$useState)(()=>props.value || props.defaultValue ? {
906
- ...allSegments
907
- } : {});
908
- let clearedSegment = (0, $7UzoM$useRef)();
909
- // Reset placeholder when calendar changes
910
- let lastCalendarIdentifier = (0, $7UzoM$useRef)(calendar.identifier);
911
- (0, $7UzoM$useEffect)(()=>{
912
- if (calendar.identifier !== lastCalendarIdentifier.current) {
913
- lastCalendarIdentifier.current = calendar.identifier;
914
- setPlaceholderDate((placeholder)=>Object.keys(validSegments).length > 0 ? (0, $7UzoM$toCalendar)(placeholder, calendar) : (0, $35a22f14a1f04b11$export$66aa2b09de4b1ea5)(props.placeholderValue, granularity, calendar, defaultTimeZone));
915
- }
916
- }, [
917
- calendar,
918
- granularity,
919
- validSegments,
920
- defaultTimeZone,
921
- props.placeholderValue
922
- ]);
923
- // If there is a value prop, and some segments were previously placeholders, mark them all as valid.
924
- if (value && Object.keys(validSegments).length < Object.keys(allSegments).length) {
925
- validSegments = {
926
- ...allSegments
927
- };
928
- setValidSegments(validSegments);
929
- }
930
- // If the value is set to null and all segments are valid, reset the placeholder.
931
- if (value == null && Object.keys(validSegments).length === Object.keys(allSegments).length) {
932
- validSegments = {};
933
- setValidSegments(validSegments);
934
- setPlaceholderDate((0, $35a22f14a1f04b11$export$66aa2b09de4b1ea5)(props.placeholderValue, granularity, calendar, defaultTimeZone));
935
- }
936
- // If all segments are valid, use the date from state, otherwise use the placeholder date.
937
- let displayValue = calendarValue && Object.keys(validSegments).length >= Object.keys(allSegments).length ? calendarValue : placeholderDate;
938
- let setValue = (newValue)=>{
939
- if (props.isDisabled || props.isReadOnly) return;
940
- let validKeys = Object.keys(validSegments);
941
- let allKeys = Object.keys(allSegments);
942
- // if all the segments are completed or a timefield with everything but am/pm set the time, also ignore when am/pm cleared
943
- if (newValue == null) {
944
- setDate(null);
945
- setPlaceholderDate((0, $35a22f14a1f04b11$export$66aa2b09de4b1ea5)(props.placeholderValue, granularity, calendar, defaultTimeZone));
946
- setValidSegments({});
947
- } else if (validKeys.length >= allKeys.length || validKeys.length === allKeys.length - 1 && allSegments.dayPeriod && !validSegments.dayPeriod && clearedSegment.current !== "dayPeriod") {
948
- // The display calendar should not have any effect on the emitted value.
949
- // Emit dates in the same calendar as the original value, if any, otherwise gregorian.
950
- newValue = (0, $7UzoM$toCalendar)(newValue, (v === null || v === void 0 ? void 0 : v.calendar) || new (0, $7UzoM$GregorianCalendar)());
951
- setDate(newValue);
952
- } else setPlaceholderDate(newValue);
953
- clearedSegment.current = null;
954
- };
955
- let dateValue = (0, $7UzoM$useMemo)(()=>displayValue.toDate(timeZone), [
956
- displayValue,
957
- timeZone
958
- ]);
959
- let segments = (0, $7UzoM$useMemo)(()=>dateFormatter.formatToParts(dateValue).map((segment)=>{
960
- let isEditable = $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[segment.type];
961
- if (segment.type === "era" && calendar.getEras().length === 1) isEditable = false;
962
- let isPlaceholder = $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[segment.type] && !validSegments[segment.type];
963
- let placeholder = $3c0fc76039f1c516$var$EDITABLE_SEGMENTS[segment.type] ? (0, $3e3ed55ab2966714$export$d3f5c5e0a5023fa0)(segment.type, segment.value, locale) : null;
964
- return {
965
- type: $3c0fc76039f1c516$var$TYPE_MAPPING[segment.type] || segment.type,
966
- text: isPlaceholder ? placeholder : segment.value,
967
- ...$3c0fc76039f1c516$var$getSegmentLimits(displayValue, segment.type, resolvedOptions),
968
- isPlaceholder: isPlaceholder,
969
- placeholder: placeholder,
970
- isEditable: isEditable
971
- };
972
- }), [
973
- dateValue,
974
- validSegments,
975
- dateFormatter,
976
- resolvedOptions,
977
- displayValue,
978
- calendar,
979
- locale
980
- ]);
981
- // When the era field appears, mark it valid if the year field is already valid.
982
- // If the era field disappears, remove it from the valid segments.
983
- if (allSegments.era && validSegments.year && !validSegments.era) {
984
- validSegments.era = true;
985
- setValidSegments({
986
- ...validSegments
987
- });
988
- } else if (!allSegments.era && validSegments.era) {
989
- delete validSegments.era;
990
- setValidSegments({
991
- ...validSegments
992
- });
993
- }
994
- let markValid = (part)=>{
995
- validSegments[part] = true;
996
- if (part === "year" && allSegments.era) validSegments.era = true;
997
- setValidSegments({
998
- ...validSegments
999
- });
1000
- };
1001
- let adjustSegment = (type, amount)=>{
1002
- if (!validSegments[type]) {
1003
- markValid(type);
1004
- let validKeys = Object.keys(validSegments);
1005
- let allKeys = Object.keys(allSegments);
1006
- if (validKeys.length >= allKeys.length || validKeys.length === allKeys.length - 1 && allSegments.dayPeriod && !validSegments.dayPeriod) setValue(displayValue);
1007
- } else setValue($3c0fc76039f1c516$var$addSegment(displayValue, type, amount, resolvedOptions));
1008
- };
1009
- let builtinValidation = (0, $7UzoM$useMemo)(()=>(0, $35a22f14a1f04b11$export$f18627323ab57ac0)(value, minValue, maxValue, isDateUnavailable, formatOpts), [
1010
- value,
1011
- minValue,
1012
- maxValue,
1013
- isDateUnavailable,
1014
- formatOpts
1015
- ]);
1016
- let validation = (0, $7UzoM$useFormValidationState)({
1017
- ...props,
1018
- value: value,
1019
- builtinValidation: builtinValidation
1020
- });
1021
- let isValueInvalid = validation.displayValidation.isInvalid;
1022
- let validationState = props.validationState || (isValueInvalid ? "invalid" : null);
1023
- var _props_maxGranularity;
1024
- return {
1025
- ...validation,
1026
- value: calendarValue,
1027
- dateValue: dateValue,
1028
- calendar: calendar,
1029
- setValue: setValue,
1030
- segments: segments,
1031
- dateFormatter: dateFormatter,
1032
- validationState: validationState,
1033
- isInvalid: isValueInvalid,
1034
- granularity: granularity,
1035
- maxGranularity: (_props_maxGranularity = props.maxGranularity) !== null && _props_maxGranularity !== void 0 ? _props_maxGranularity : "year",
1036
- isDisabled: isDisabled,
1037
- isReadOnly: isReadOnly,
1038
- isRequired: isRequired,
1039
- increment (part) {
1040
- adjustSegment(part, 1);
1041
- },
1042
- decrement (part) {
1043
- adjustSegment(part, -1);
1044
- },
1045
- incrementPage (part) {
1046
- adjustSegment(part, $3c0fc76039f1c516$var$PAGE_STEP[part] || 1);
1047
- },
1048
- decrementPage (part) {
1049
- adjustSegment(part, -($3c0fc76039f1c516$var$PAGE_STEP[part] || 1));
1050
- },
1051
- setSegment (part, v) {
1052
- markValid(part);
1053
- setValue($3c0fc76039f1c516$var$setSegment(displayValue, part, v, resolvedOptions));
1054
- },
1055
- confirmPlaceholder () {
1056
- if (props.isDisabled || props.isReadOnly) return;
1057
- // Confirm the placeholder if only the day period is not filled in.
1058
- let validKeys = Object.keys(validSegments);
1059
- let allKeys = Object.keys(allSegments);
1060
- if (validKeys.length === allKeys.length - 1 && allSegments.dayPeriod && !validSegments.dayPeriod) {
1061
- validSegments = {
1062
- ...allSegments
1063
- };
1064
- setValidSegments(validSegments);
1065
- setValue(displayValue.copy());
1066
- }
1067
- },
1068
- clearSegment (part) {
1069
- delete validSegments[part];
1070
- clearedSegment.current = part;
1071
- setValidSegments({
1072
- ...validSegments
1073
- });
1074
- let placeholder = (0, $35a22f14a1f04b11$export$66aa2b09de4b1ea5)(props.placeholderValue, granularity, calendar, defaultTimeZone);
1075
- let value = displayValue;
1076
- // Reset day period to default without changing the hour.
1077
- if (part === "dayPeriod" && "hour" in displayValue && "hour" in placeholder) {
1078
- let isPM = displayValue.hour >= 12;
1079
- let shouldBePM = placeholder.hour >= 12;
1080
- if (isPM && !shouldBePM) value = displayValue.set({
1081
- hour: displayValue.hour - 12
1082
- });
1083
- else if (!isPM && shouldBePM) value = displayValue.set({
1084
- hour: displayValue.hour + 12
1085
- });
1086
- } else if (part in displayValue) value = displayValue.set({
1087
- [part]: placeholder[part]
1088
- });
1089
- setDate(null);
1090
- setValue(value);
1091
- },
1092
- formatValue (fieldOptions) {
1093
- if (!calendarValue) return "";
1094
- let formatOptions = (0, $35a22f14a1f04b11$export$7e319ea407e63bc0)(fieldOptions, formatOpts);
1095
- let formatter = new (0, $7UzoM$DateFormatter)(locale, formatOptions);
1096
- return formatter.format(dateValue);
1097
- }
1098
- };
1099
- }
1100
- function $3c0fc76039f1c516$var$getSegmentLimits(date, type, options) {
1101
- switch(type){
1102
- case "era":
1103
- {
1104
- let eras = date.calendar.getEras();
1105
- return {
1106
- value: eras.indexOf(date.era),
1107
- minValue: 0,
1108
- maxValue: eras.length - 1
1109
- };
1110
- }
1111
- case "year":
1112
- return {
1113
- value: date.year,
1114
- minValue: 1,
1115
- maxValue: date.calendar.getYearsInEra(date)
1116
- };
1117
- case "month":
1118
- return {
1119
- value: date.month,
1120
- minValue: (0, $7UzoM$getMinimumMonthInYear)(date),
1121
- maxValue: date.calendar.getMonthsInYear(date)
1122
- };
1123
- case "day":
1124
- return {
1125
- value: date.day,
1126
- minValue: (0, $7UzoM$getMinimumDayInMonth)(date),
1127
- maxValue: date.calendar.getDaysInMonth(date)
1128
- };
1129
- }
1130
- if ("hour" in date) switch(type){
1131
- case "dayPeriod":
1132
- return {
1133
- value: date.hour >= 12 ? 12 : 0,
1134
- minValue: 0,
1135
- maxValue: 12
1136
- };
1137
- case "hour":
1138
- if (options.hour12) {
1139
- let isPM = date.hour >= 12;
1140
- return {
1141
- value: date.hour,
1142
- minValue: isPM ? 12 : 0,
1143
- maxValue: isPM ? 23 : 11
1144
- };
1145
- }
1146
- return {
1147
- value: date.hour,
1148
- minValue: 0,
1149
- maxValue: 23
1150
- };
1151
- case "minute":
1152
- return {
1153
- value: date.minute,
1154
- minValue: 0,
1155
- maxValue: 59
1156
- };
1157
- case "second":
1158
- return {
1159
- value: date.second,
1160
- minValue: 0,
1161
- maxValue: 59
1162
- };
1163
- }
1164
- return {};
1165
- }
1166
- function $3c0fc76039f1c516$var$addSegment(value, part, amount, options) {
1167
- switch(part){
1168
- case "era":
1169
- case "year":
1170
- case "month":
1171
- case "day":
1172
- return value.cycle(part, amount, {
1173
- round: part === "year"
1174
- });
1175
- }
1176
- if ("hour" in value) switch(part){
1177
- case "dayPeriod":
1178
- {
1179
- let hours = value.hour;
1180
- let isPM = hours >= 12;
1181
- return value.set({
1182
- hour: isPM ? hours - 12 : hours + 12
1183
- });
1184
- }
1185
- case "hour":
1186
- case "minute":
1187
- case "second":
1188
- return value.cycle(part, amount, {
1189
- round: part !== "hour",
1190
- hourCycle: options.hour12 ? 12 : 24
1191
- });
1192
- }
1193
- }
1194
- function $3c0fc76039f1c516$var$setSegment(value, part, segmentValue, options) {
1195
- switch(part){
1196
- case "day":
1197
- case "month":
1198
- case "year":
1199
- case "era":
1200
- return value.set({
1201
- [part]: segmentValue
1202
- });
1203
- }
1204
- if ("hour" in value) switch(part){
1205
- case "dayPeriod":
1206
- {
1207
- let hours = value.hour;
1208
- let wasPM = hours >= 12;
1209
- let isPM = segmentValue >= 12;
1210
- if (isPM === wasPM) return value;
1211
- return value.set({
1212
- hour: wasPM ? hours - 12 : hours + 12
1213
- });
1214
- }
1215
- case "hour":
1216
- // In 12 hour time, ensure that AM/PM does not change
1217
- if (options.hour12) {
1218
- let hours = value.hour;
1219
- let wasPM = hours >= 12;
1220
- if (!wasPM && segmentValue === 12) segmentValue = 0;
1221
- if (wasPM && segmentValue < 12) segmentValue += 12;
1222
- }
1223
- // fallthrough
1224
- case "minute":
1225
- case "second":
1226
- return value.set({
1227
- [part]: segmentValue
1228
- });
1229
- }
1230
- }
1231
-
1232
-
1233
- /*
1234
- * Copyright 2020 Adobe. All rights reserved.
1235
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
1236
- * you may not use this file except in compliance with the License. You may obtain a copy
1237
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
1238
- *
1239
- * Unless required by applicable law or agreed to in writing, software distributed under
1240
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
1241
- * OF ANY KIND, either express or implied. See the License for the specific language
1242
- * governing permissions and limitations under the License.
1243
- */
1244
-
1245
-
1246
-
1247
-
1248
-
1249
- function $93c38a5e28be6249$export$e50a61c1de9f574(props) {
1250
- var _value_start, _value_end;
1251
- let overlayState = (0, $7UzoM$useOverlayTriggerState)(props);
1252
- let [controlledValue, setControlledValue] = (0, $7UzoM$useControlledState)(props.value, props.defaultValue || null, props.onChange);
1253
- let [placeholderValue, setPlaceholderValue] = (0, $7UzoM$useState)(()=>controlledValue || {
1254
- start: null,
1255
- end: null
1256
- });
1257
- // Reset the placeholder if the value prop is set to null.
1258
- if (controlledValue == null && placeholderValue.start && placeholderValue.end) {
1259
- placeholderValue = {
1260
- start: null,
1261
- end: null
1262
- };
1263
- setPlaceholderValue(placeholderValue);
1264
- }
1265
- let value = controlledValue || placeholderValue;
1266
- let setValue = (value)=>{
1267
- setPlaceholderValue(value || {
1268
- start: null,
1269
- end: null
1270
- });
1271
- if ((value === null || value === void 0 ? void 0 : value.start) && value.end) setControlledValue(value);
1272
- else setControlledValue(null);
1273
- };
1274
- let v = (value === null || value === void 0 ? void 0 : value.start) || (value === null || value === void 0 ? void 0 : value.end) || props.placeholderValue;
1275
- let [granularity, defaultTimeZone] = (0, $35a22f14a1f04b11$export$2440da353cedad43)(v, props.granularity);
1276
- let hasTime = granularity === "hour" || granularity === "minute" || granularity === "second";
1277
- var _props_shouldCloseOnSelect;
1278
- let shouldCloseOnSelect = (_props_shouldCloseOnSelect = props.shouldCloseOnSelect) !== null && _props_shouldCloseOnSelect !== void 0 ? _props_shouldCloseOnSelect : true;
1279
- let [dateRange, setSelectedDateRange] = (0, $7UzoM$useState)(null);
1280
- let [timeRange, setSelectedTimeRange] = (0, $7UzoM$useState)(null);
1281
- if (value && value.start && value.end) {
1282
- dateRange = value;
1283
- if ("hour" in value.start) timeRange = value;
1284
- }
1285
- let commitValue = (dateRange, timeRange)=>{
1286
- setValue({
1287
- start: "timeZone" in timeRange.start ? timeRange.start.set((0, $7UzoM$toCalendarDate)(dateRange.start)) : (0, $7UzoM$toCalendarDateTime)(dateRange.start, timeRange.start),
1288
- end: "timeZone" in timeRange.end ? timeRange.end.set((0, $7UzoM$toCalendarDate)(dateRange.end)) : (0, $7UzoM$toCalendarDateTime)(dateRange.end, timeRange.end)
1289
- });
1290
- setSelectedDateRange(null);
1291
- setSelectedTimeRange(null);
1292
- validation.commitValidation();
1293
- };
1294
- // Intercept setValue to make sure the Time section is not changed by date selection in Calendar
1295
- let setDateRange = (range)=>{
1296
- let shouldClose = typeof shouldCloseOnSelect === "function" ? shouldCloseOnSelect() : shouldCloseOnSelect;
1297
- if (hasTime) {
1298
- 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, {
1299
- start: (timeRange === null || timeRange === void 0 ? void 0 : timeRange.start) || (0, $35a22f14a1f04b11$export$c5221a78ef73c5e9)(props.placeholderValue),
1300
- end: (timeRange === null || timeRange === void 0 ? void 0 : timeRange.end) || (0, $35a22f14a1f04b11$export$c5221a78ef73c5e9)(props.placeholderValue)
1301
- });
1302
- else setSelectedDateRange(range);
1303
- } else if (range.start && range.end) {
1304
- setValue(range);
1305
- validation.commitValidation();
1306
- } else setSelectedDateRange(range);
1307
- if (shouldClose) overlayState.setOpen(false);
1308
- };
1309
- let setTimeRange = (range)=>{
1310
- 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);
1311
- else setSelectedTimeRange(range);
1312
- };
1313
- let showEra = (value === null || value === void 0 ? void 0 : (_value_start = value.start) === null || _value_start === void 0 ? void 0 : _value_start.calendar.identifier) === "gregory" && value.start.era === "BC" || (value === null || value === void 0 ? void 0 : (_value_end = value.end) === null || _value_end === void 0 ? void 0 : _value_end.calendar.identifier) === "gregory" && value.end.era === "BC";
1314
- let formatOpts = (0, $7UzoM$useMemo)(()=>({
1315
- granularity: granularity,
1316
- timeZone: defaultTimeZone,
1317
- hideTimeZone: props.hideTimeZone,
1318
- hourCycle: props.hourCycle,
1319
- shouldForceLeadingZeros: props.shouldForceLeadingZeros,
1320
- showEra: showEra
1321
- }), [
1322
- granularity,
1323
- props.hourCycle,
1324
- props.shouldForceLeadingZeros,
1325
- defaultTimeZone,
1326
- props.hideTimeZone,
1327
- showEra
1328
- ]);
1329
- let { minValue: minValue, maxValue: maxValue, isDateUnavailable: isDateUnavailable } = props;
1330
- let builtinValidation = (0, $7UzoM$useMemo)(()=>(0, $35a22f14a1f04b11$export$80ff8fc0ae339c13)(value, minValue, maxValue, isDateUnavailable, formatOpts), [
1331
- value,
1332
- minValue,
1333
- maxValue,
1334
- isDateUnavailable,
1335
- formatOpts
1336
- ]);
1337
- let validation = (0, $7UzoM$useFormValidationState)({
1338
- ...props,
1339
- value: controlledValue,
1340
- name: (0, $7UzoM$useMemo)(()=>[
1341
- props.startName,
1342
- props.endName
1343
- ], [
1344
- props.startName,
1345
- props.endName
1346
- ]),
1347
- builtinValidation: builtinValidation
1348
- });
1349
- let isValueInvalid = validation.displayValidation.isInvalid;
1350
- let validationState = props.validationState || (isValueInvalid ? "invalid" : null);
1351
- return {
1352
- ...validation,
1353
- value: value,
1354
- setValue: setValue,
1355
- dateRange: dateRange,
1356
- timeRange: timeRange,
1357
- granularity: granularity,
1358
- hasTime: hasTime,
1359
- setDate (part, date) {
1360
- setDateRange({
1361
- ...dateRange,
1362
- [part]: date
1363
- });
1364
- },
1365
- setTime (part, time) {
1366
- setTimeRange({
1367
- ...timeRange,
1368
- [part]: time
1369
- });
1370
- },
1371
- setDateTime (part, dateTime) {
1372
- setValue({
1373
- ...value,
1374
- [part]: dateTime
1375
- });
1376
- },
1377
- setDateRange: setDateRange,
1378
- setTimeRange: setTimeRange,
1379
- ...overlayState,
1380
- setOpen (isOpen) {
1381
- // Commit the selected date range when the calendar is closed. Use a placeholder time if one wasn't set.
1382
- // If only the time range was set and not the date range, don't commit. The state will be preserved until
1383
- // the user opens the popover again.
1384
- 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, {
1385
- start: (timeRange === null || timeRange === void 0 ? void 0 : timeRange.start) || (0, $35a22f14a1f04b11$export$c5221a78ef73c5e9)(props.placeholderValue),
1386
- end: (timeRange === null || timeRange === void 0 ? void 0 : timeRange.end) || (0, $35a22f14a1f04b11$export$c5221a78ef73c5e9)(props.placeholderValue)
1387
- });
1388
- overlayState.setOpen(isOpen);
1389
- },
1390
- validationState: validationState,
1391
- isInvalid: isValueInvalid,
1392
- formatValue (locale, fieldOptions) {
1393
- if (!value || !value.start || !value.end) return null;
1394
- let startTimeZone = "timeZone" in value.start ? value.start.timeZone : undefined;
1395
- let startGranularity = props.granularity || (value.start && "minute" in value.start ? "minute" : "day");
1396
- let endTimeZone = "timeZone" in value.end ? value.end.timeZone : undefined;
1397
- let endGranularity = props.granularity || (value.end && "minute" in value.end ? "minute" : "day");
1398
- let startOptions = (0, $35a22f14a1f04b11$export$7e319ea407e63bc0)(fieldOptions, {
1399
- granularity: startGranularity,
1400
- timeZone: startTimeZone,
1401
- hideTimeZone: props.hideTimeZone,
1402
- hourCycle: props.hourCycle,
1403
- showEra: value.start.calendar.identifier === "gregory" && value.start.era === "BC" || value.end.calendar.identifier === "gregory" && value.end.era === "BC"
1404
- });
1405
- let startDate = value.start.toDate(startTimeZone || "UTC");
1406
- let endDate = value.end.toDate(endTimeZone || "UTC");
1407
- let startFormatter = new (0, $7UzoM$DateFormatter)(locale, startOptions);
1408
- let endFormatter;
1409
- if (startTimeZone === endTimeZone && startGranularity === endGranularity && value.start.compare(value.end) !== 0) {
1410
- // Use formatRange, as it results in shorter output when some of the fields
1411
- // are shared between the start and end dates (e.g. the same month).
1412
- // Formatting will fail if the end date is before the start date. Fall back below when that happens.
1413
- try {
1414
- let parts = startFormatter.formatRangeToParts(startDate, endDate);
1415
- // Find the separator between the start and end date. This is determined
1416
- // by finding the last shared literal before the end range.
1417
- let separatorIndex = -1;
1418
- for(let i = 0; i < parts.length; i++){
1419
- let part = parts[i];
1420
- if (part.source === "shared" && part.type === "literal") separatorIndex = i;
1421
- else if (part.source === "endRange") break;
1422
- }
1423
- // Now we can combine the parts into start and end strings.
1424
- let start = "";
1425
- let end = "";
1426
- for(let i = 0; i < parts.length; i++){
1427
- if (i < separatorIndex) start += parts[i].value;
1428
- else if (i > separatorIndex) end += parts[i].value;
1429
- }
1430
- return {
1431
- start: start,
1432
- end: end
1433
- };
1434
- } catch (e) {
1435
- // ignore
1436
- }
1437
- endFormatter = startFormatter;
1438
- } else {
1439
- let endOptions = (0, $35a22f14a1f04b11$export$7e319ea407e63bc0)(fieldOptions, {
1440
- granularity: endGranularity,
1441
- timeZone: endTimeZone,
1442
- hideTimeZone: props.hideTimeZone,
1443
- hourCycle: props.hourCycle
1444
- });
1445
- endFormatter = new (0, $7UzoM$DateFormatter)(locale, endOptions);
1446
- }
1447
- return {
1448
- start: startFormatter.format(startDate),
1449
- end: endFormatter.format(endDate)
1450
- };
1451
- }
1452
- };
1453
- }
1454
-
1455
-
1456
- /*
1457
- * Copyright 2020 Adobe. All rights reserved.
1458
- * This file is licensed to you under the Apache License, Version 2.0 (the 'License');
1459
- * you may not use this file except in compliance with the License. You may obtain a copy
1460
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
1461
- *
1462
- * Unless required by applicable law or agreed to in writing, software distributed under
1463
- * the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
1464
- * OF ANY KIND, either express or implied. See the License for the specific language
1465
- * governing permissions and limitations under the License.
1466
- */
1467
-
1468
-
1469
17
 
1470
- function $eff5d8ee529ac4bb$export$fd53cef0cc796101(props) {
1471
- let { placeholderValue: placeholderValue = new (0, $7UzoM$Time)(), minValue: minValue, maxValue: maxValue, granularity: granularity, validate: validate } = props;
1472
- let [value, setValue] = (0, $7UzoM$useControlledState)(props.value, props.defaultValue, props.onChange);
1473
- let v = value || placeholderValue;
1474
- let day = v && "day" in v ? v : undefined;
1475
- let defaultValueTimeZone = props.defaultValue && "timeZone" in props.defaultValue ? props.defaultValue.timeZone : undefined;
1476
- let placeholderDate = (0, $7UzoM$useMemo)(()=>{
1477
- let valueTimeZone = v && "timeZone" in v ? v.timeZone : undefined;
1478
- return (valueTimeZone || defaultValueTimeZone) && placeholderValue ? (0, $7UzoM$toZoned)($eff5d8ee529ac4bb$var$convertValue(placeholderValue), valueTimeZone || defaultValueTimeZone) : $eff5d8ee529ac4bb$var$convertValue(placeholderValue);
1479
- }, [
1480
- placeholderValue,
1481
- v,
1482
- defaultValueTimeZone
1483
- ]);
1484
- let minDate = (0, $7UzoM$useMemo)(()=>$eff5d8ee529ac4bb$var$convertValue(minValue, day), [
1485
- minValue,
1486
- day
1487
- ]);
1488
- let maxDate = (0, $7UzoM$useMemo)(()=>$eff5d8ee529ac4bb$var$convertValue(maxValue, day), [
1489
- maxValue,
1490
- day
1491
- ]);
1492
- let timeValue = (0, $7UzoM$useMemo)(()=>value && "day" in value ? (0, $7UzoM$toTime)(value) : value, [
1493
- value
1494
- ]);
1495
- let dateTime = (0, $7UzoM$useMemo)(()=>value == null ? null : $eff5d8ee529ac4bb$var$convertValue(value), [
1496
- value
1497
- ]);
1498
- let onChange = (newValue)=>{
1499
- setValue(day || defaultValueTimeZone ? newValue : newValue && (0, $7UzoM$toTime)(newValue));
1500
- };
1501
- let state = (0, $3c0fc76039f1c516$export$60e84778edff6d26)({
1502
- ...props,
1503
- value: dateTime,
1504
- defaultValue: undefined,
1505
- minValue: minDate,
1506
- maxValue: maxDate,
1507
- onChange: onChange,
1508
- granularity: granularity || "minute",
1509
- maxGranularity: "hour",
1510
- placeholderValue: placeholderDate,
1511
- // Calendar should not matter for time fields.
1512
- createCalendar: ()=>new (0, $7UzoM$GregorianCalendar)(),
1513
- validate: (0, $7UzoM$useCallback)(()=>validate === null || validate === void 0 ? void 0 : validate(value), [
1514
- validate,
1515
- value
1516
- ])
1517
- });
1518
- return {
1519
- ...state,
1520
- timeValue: timeValue
1521
- };
1522
- }
1523
- function $eff5d8ee529ac4bb$var$convertValue(value, date = (0, $7UzoM$today)((0, $7UzoM$getLocalTimeZone)())) {
1524
- if (!value) return null;
1525
- if ("day" in value) return value;
1526
- return (0, $7UzoM$toCalendarDateTime)(date, value);
1527
- }
1528
18
 
1529
19
 
1530
20