@react-stately/datepicker 3.9.1 → 3.9.3

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 (77) hide show
  1. package/dist/ar-AE.mjs +1 -1
  2. package/dist/bg-BG.mjs +1 -1
  3. package/dist/cs-CZ.mjs +1 -1
  4. package/dist/da-DK.mjs +1 -1
  5. package/dist/de-DE.mjs +1 -1
  6. package/dist/el-GR.mjs +1 -1
  7. package/dist/en-US.mjs +1 -1
  8. package/dist/es-ES.mjs +1 -1
  9. package/dist/et-EE.mjs +1 -1
  10. package/dist/fi-FI.mjs +1 -1
  11. package/dist/fr-FR.mjs +1 -1
  12. package/dist/he-IL.mjs +1 -1
  13. package/dist/hr-HR.mjs +1 -1
  14. package/dist/hu-HU.mjs +1 -1
  15. package/dist/import.mjs +4 -1514
  16. package/dist/intlStrings.main.js +108 -0
  17. package/dist/intlStrings.main.js.map +1 -0
  18. package/dist/intlStrings.mjs +110 -0
  19. package/dist/intlStrings.module.js +110 -0
  20. package/dist/intlStrings.module.js.map +1 -0
  21. package/dist/it-IT.mjs +1 -1
  22. package/dist/ja-JP.mjs +1 -1
  23. package/dist/ko-KR.mjs +1 -1
  24. package/dist/lt-LT.mjs +1 -1
  25. package/dist/lv-LV.mjs +1 -1
  26. package/dist/main.js +8 -1518
  27. package/dist/main.js.map +1 -1
  28. package/dist/module.js +4 -1514
  29. package/dist/module.js.map +1 -1
  30. package/dist/nb-NO.mjs +1 -1
  31. package/dist/nl-NL.mjs +1 -1
  32. package/dist/pl-PL.mjs +1 -1
  33. package/dist/placeholders.main.js +409 -0
  34. package/dist/placeholders.main.js.map +1 -0
  35. package/dist/placeholders.mjs +404 -0
  36. package/dist/placeholders.module.js +404 -0
  37. package/dist/placeholders.module.js.map +1 -0
  38. package/dist/pt-BR.mjs +1 -1
  39. package/dist/pt-PT.mjs +1 -1
  40. package/dist/ro-RO.mjs +1 -1
  41. package/dist/ru-RU.mjs +1 -1
  42. package/dist/sk-SK.mjs +1 -1
  43. package/dist/sl-SI.mjs +1 -1
  44. package/dist/sr-SP.mjs +1 -1
  45. package/dist/sv-SE.mjs +1 -1
  46. package/dist/tr-TR.mjs +1 -1
  47. package/dist/types.d.ts.map +1 -1
  48. package/dist/uk-UA.mjs +1 -1
  49. package/dist/useDateFieldState.main.js +441 -0
  50. package/dist/useDateFieldState.main.js.map +1 -0
  51. package/dist/useDateFieldState.mjs +436 -0
  52. package/dist/useDateFieldState.module.js +436 -0
  53. package/dist/useDateFieldState.module.js.map +1 -0
  54. package/dist/useDatePickerState.main.js +130 -0
  55. package/dist/useDatePickerState.main.js.map +1 -0
  56. package/dist/useDatePickerState.mjs +125 -0
  57. package/dist/useDatePickerState.module.js +125 -0
  58. package/dist/useDatePickerState.module.js.map +1 -0
  59. package/dist/useDateRangePickerState.main.js +237 -0
  60. package/dist/useDateRangePickerState.main.js.map +1 -0
  61. package/dist/useDateRangePickerState.mjs +232 -0
  62. package/dist/useDateRangePickerState.module.js +232 -0
  63. package/dist/useDateRangePickerState.module.js.map +1 -0
  64. package/dist/useTimeFieldState.main.js +86 -0
  65. package/dist/useTimeFieldState.main.js.map +1 -0
  66. package/dist/useTimeFieldState.mjs +81 -0
  67. package/dist/useTimeFieldState.module.js +81 -0
  68. package/dist/useTimeFieldState.module.js.map +1 -0
  69. package/dist/utils.main.js +190 -0
  70. package/dist/utils.main.js.map +1 -0
  71. package/dist/utils.mjs +179 -0
  72. package/dist/utils.module.js +179 -0
  73. package/dist/utils.module.js.map +1 -0
  74. package/dist/zh-CN.mjs +1 -1
  75. package/dist/zh-TW.mjs +1 -1
  76. package/package.json +9 -9
  77. package/src/utils.ts +2 -1
@@ -0,0 +1,81 @@
1
+ import {useDateFieldState as $3c0fc76039f1c516$export$60e84778edff6d26} from "./useDateFieldState.mjs";
2
+ import {Time as $2PRh3$Time, toZoned as $2PRh3$toZoned, toTime as $2PRh3$toTime, GregorianCalendar as $2PRh3$GregorianCalendar, today as $2PRh3$today, getLocalTimeZone as $2PRh3$getLocalTimeZone, toCalendarDateTime as $2PRh3$toCalendarDateTime} from "@internationalized/date";
3
+ import {useMemo as $2PRh3$useMemo, useCallback as $2PRh3$useCallback} from "react";
4
+ import {useControlledState as $2PRh3$useControlledState} from "@react-stately/utils";
5
+
6
+ /*
7
+ * Copyright 2020 Adobe. All rights reserved.
8
+ * This file is licensed to you under the Apache License, Version 2.0 (the 'License');
9
+ * you may not use this file except in compliance with the License. You may obtain a copy
10
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software distributed under
13
+ * the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
14
+ * OF ANY KIND, either express or implied. See the License for the specific language
15
+ * governing permissions and limitations under the License.
16
+ */
17
+
18
+
19
+
20
+ function $eff5d8ee529ac4bb$export$fd53cef0cc796101(props) {
21
+ let { placeholderValue: placeholderValue = new (0, $2PRh3$Time)(), minValue: minValue, maxValue: maxValue, granularity: granularity, validate: validate } = props;
22
+ let [value, setValue] = (0, $2PRh3$useControlledState)(props.value, props.defaultValue, props.onChange);
23
+ let v = value || placeholderValue;
24
+ let day = v && "day" in v ? v : undefined;
25
+ let defaultValueTimeZone = props.defaultValue && "timeZone" in props.defaultValue ? props.defaultValue.timeZone : undefined;
26
+ let placeholderDate = (0, $2PRh3$useMemo)(()=>{
27
+ let valueTimeZone = v && "timeZone" in v ? v.timeZone : undefined;
28
+ return (valueTimeZone || defaultValueTimeZone) && placeholderValue ? (0, $2PRh3$toZoned)($eff5d8ee529ac4bb$var$convertValue(placeholderValue), valueTimeZone || defaultValueTimeZone) : $eff5d8ee529ac4bb$var$convertValue(placeholderValue);
29
+ }, [
30
+ placeholderValue,
31
+ v,
32
+ defaultValueTimeZone
33
+ ]);
34
+ let minDate = (0, $2PRh3$useMemo)(()=>$eff5d8ee529ac4bb$var$convertValue(minValue, day), [
35
+ minValue,
36
+ day
37
+ ]);
38
+ let maxDate = (0, $2PRh3$useMemo)(()=>$eff5d8ee529ac4bb$var$convertValue(maxValue, day), [
39
+ maxValue,
40
+ day
41
+ ]);
42
+ let timeValue = (0, $2PRh3$useMemo)(()=>value && "day" in value ? (0, $2PRh3$toTime)(value) : value, [
43
+ value
44
+ ]);
45
+ let dateTime = (0, $2PRh3$useMemo)(()=>value == null ? null : $eff5d8ee529ac4bb$var$convertValue(value), [
46
+ value
47
+ ]);
48
+ let onChange = (newValue)=>{
49
+ setValue(day || defaultValueTimeZone ? newValue : newValue && (0, $2PRh3$toTime)(newValue));
50
+ };
51
+ let state = (0, $3c0fc76039f1c516$export$60e84778edff6d26)({
52
+ ...props,
53
+ value: dateTime,
54
+ defaultValue: undefined,
55
+ minValue: minDate,
56
+ maxValue: maxDate,
57
+ onChange: onChange,
58
+ granularity: granularity || "minute",
59
+ maxGranularity: "hour",
60
+ placeholderValue: placeholderDate,
61
+ // Calendar should not matter for time fields.
62
+ createCalendar: ()=>new (0, $2PRh3$GregorianCalendar)(),
63
+ validate: (0, $2PRh3$useCallback)(()=>validate === null || validate === void 0 ? void 0 : validate(value), [
64
+ validate,
65
+ value
66
+ ])
67
+ });
68
+ return {
69
+ ...state,
70
+ timeValue: timeValue
71
+ };
72
+ }
73
+ function $eff5d8ee529ac4bb$var$convertValue(value, date = (0, $2PRh3$today)((0, $2PRh3$getLocalTimeZone)())) {
74
+ if (!value) return null;
75
+ if ("day" in value) return value;
76
+ return (0, $2PRh3$toCalendarDateTime)(date, value);
77
+ }
78
+
79
+
80
+ export {$eff5d8ee529ac4bb$export$fd53cef0cc796101 as useTimeFieldState};
81
+ //# sourceMappingURL=useTimeFieldState.mjs.map
@@ -0,0 +1,81 @@
1
+ import {useDateFieldState as $3c0fc76039f1c516$export$60e84778edff6d26} from "./useDateFieldState.module.js";
2
+ import {Time as $2PRh3$Time, toZoned as $2PRh3$toZoned, toTime as $2PRh3$toTime, GregorianCalendar as $2PRh3$GregorianCalendar, today as $2PRh3$today, getLocalTimeZone as $2PRh3$getLocalTimeZone, toCalendarDateTime as $2PRh3$toCalendarDateTime} from "@internationalized/date";
3
+ import {useMemo as $2PRh3$useMemo, useCallback as $2PRh3$useCallback} from "react";
4
+ import {useControlledState as $2PRh3$useControlledState} from "@react-stately/utils";
5
+
6
+ /*
7
+ * Copyright 2020 Adobe. All rights reserved.
8
+ * This file is licensed to you under the Apache License, Version 2.0 (the 'License');
9
+ * you may not use this file except in compliance with the License. You may obtain a copy
10
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software distributed under
13
+ * the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
14
+ * OF ANY KIND, either express or implied. See the License for the specific language
15
+ * governing permissions and limitations under the License.
16
+ */
17
+
18
+
19
+
20
+ function $eff5d8ee529ac4bb$export$fd53cef0cc796101(props) {
21
+ let { placeholderValue: placeholderValue = new (0, $2PRh3$Time)(), minValue: minValue, maxValue: maxValue, granularity: granularity, validate: validate } = props;
22
+ let [value, setValue] = (0, $2PRh3$useControlledState)(props.value, props.defaultValue, props.onChange);
23
+ let v = value || placeholderValue;
24
+ let day = v && "day" in v ? v : undefined;
25
+ let defaultValueTimeZone = props.defaultValue && "timeZone" in props.defaultValue ? props.defaultValue.timeZone : undefined;
26
+ let placeholderDate = (0, $2PRh3$useMemo)(()=>{
27
+ let valueTimeZone = v && "timeZone" in v ? v.timeZone : undefined;
28
+ return (valueTimeZone || defaultValueTimeZone) && placeholderValue ? (0, $2PRh3$toZoned)($eff5d8ee529ac4bb$var$convertValue(placeholderValue), valueTimeZone || defaultValueTimeZone) : $eff5d8ee529ac4bb$var$convertValue(placeholderValue);
29
+ }, [
30
+ placeholderValue,
31
+ v,
32
+ defaultValueTimeZone
33
+ ]);
34
+ let minDate = (0, $2PRh3$useMemo)(()=>$eff5d8ee529ac4bb$var$convertValue(minValue, day), [
35
+ minValue,
36
+ day
37
+ ]);
38
+ let maxDate = (0, $2PRh3$useMemo)(()=>$eff5d8ee529ac4bb$var$convertValue(maxValue, day), [
39
+ maxValue,
40
+ day
41
+ ]);
42
+ let timeValue = (0, $2PRh3$useMemo)(()=>value && "day" in value ? (0, $2PRh3$toTime)(value) : value, [
43
+ value
44
+ ]);
45
+ let dateTime = (0, $2PRh3$useMemo)(()=>value == null ? null : $eff5d8ee529ac4bb$var$convertValue(value), [
46
+ value
47
+ ]);
48
+ let onChange = (newValue)=>{
49
+ setValue(day || defaultValueTimeZone ? newValue : newValue && (0, $2PRh3$toTime)(newValue));
50
+ };
51
+ let state = (0, $3c0fc76039f1c516$export$60e84778edff6d26)({
52
+ ...props,
53
+ value: dateTime,
54
+ defaultValue: undefined,
55
+ minValue: minDate,
56
+ maxValue: maxDate,
57
+ onChange: onChange,
58
+ granularity: granularity || "minute",
59
+ maxGranularity: "hour",
60
+ placeholderValue: placeholderDate,
61
+ // Calendar should not matter for time fields.
62
+ createCalendar: ()=>new (0, $2PRh3$GregorianCalendar)(),
63
+ validate: (0, $2PRh3$useCallback)(()=>validate === null || validate === void 0 ? void 0 : validate(value), [
64
+ validate,
65
+ value
66
+ ])
67
+ });
68
+ return {
69
+ ...state,
70
+ timeValue: timeValue
71
+ };
72
+ }
73
+ function $eff5d8ee529ac4bb$var$convertValue(value, date = (0, $2PRh3$today)((0, $2PRh3$getLocalTimeZone)())) {
74
+ if (!value) return null;
75
+ if ("day" in value) return value;
76
+ return (0, $2PRh3$toCalendarDateTime)(date, value);
77
+ }
78
+
79
+
80
+ export {$eff5d8ee529ac4bb$export$fd53cef0cc796101 as useTimeFieldState};
81
+ //# sourceMappingURL=useTimeFieldState.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AAuBM,SAAS,0CAAmD,KAA+B;IAChG,IAAI,oBACF,mBAAmB,IAAI,CAAA,GAAA,WAAG,eAC1B,QAAQ,YACR,QAAQ,eACR,WAAW,YACX,QAAQ,EACT,GAAG;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AC1C,UAAU,CAAA,GAAA,kBAAU,EAAE,IAAM,qBAAA,+BAAA,SAAW,QAAe;YAAC;YAAU;SAAM;IACzE;IAEA,OAAO;QACL,GAAG,KAAK;mBACR;IACF;AACF;AAEA,SAAS,mCAAa,KAAgB,EAAE,OAAkB,CAAA,GAAA,YAAI,EAAE,CAAA,GAAA,uBAAe,IAAI;IACjF,IAAI,CAAC,OACH,OAAO;IAGT,IAAI,SAAS,OACX,OAAO;IAGT,OAAO,CAAA,GAAA,yBAAiB,EAAE,MAAM;AAClC","sources":["packages/@react-stately/datepicker/src/useTimeFieldState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the 'License');\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {DateFieldState, useDateFieldState} from '.';\nimport {DateValue, TimePickerProps, TimeValue} from '@react-types/datepicker';\nimport {getLocalTimeZone, GregorianCalendar, Time, toCalendarDateTime, today, toTime, toZoned} from '@internationalized/date';\nimport {useCallback, useMemo} from 'react';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface TimeFieldStateOptions<T extends TimeValue = TimeValue> extends TimePickerProps<T> {\n /** The locale to display and edit the value according to. */\n locale: string\n}\n\nexport interface TimeFieldState extends DateFieldState {\n /** The current time value. */\n timeValue: Time\n}\n\n/**\n * Provides state management for a time field component.\n * A time field allows users to enter and edit time values using a keyboard.\n * Each part of a time value is displayed in an individually editable segment.\n */\nexport function useTimeFieldState<T extends TimeValue = TimeValue>(props: TimeFieldStateOptions<T>): TimeFieldState {\n let {\n placeholderValue = new Time(),\n minValue,\n maxValue,\n granularity,\n validate\n } = props;\n\n let [value, setValue] = useControlledState<TimeValue>(\n props.value,\n props.defaultValue,\n props.onChange\n );\n\n let v = value || placeholderValue;\n let day = v && 'day' in v ? v : undefined;\n let defaultValueTimeZone = props.defaultValue && 'timeZone' in props.defaultValue ? props.defaultValue.timeZone : undefined;\n let placeholderDate = useMemo(() => {\n let valueTimeZone = v && 'timeZone' in v ? v.timeZone : undefined;\n\n return (valueTimeZone || defaultValueTimeZone) && placeholderValue ? toZoned(convertValue(placeholderValue), valueTimeZone || defaultValueTimeZone) : convertValue(placeholderValue);\n }, [placeholderValue, v, defaultValueTimeZone]);\n let minDate = useMemo(() => convertValue(minValue, day), [minValue, day]);\n let maxDate = useMemo(() => convertValue(maxValue, day), [maxValue, day]);\n\n let timeValue = useMemo(() => value && 'day' in value ? toTime(value) : value as Time, [value]);\n let dateTime = useMemo(() => value == null ? null : convertValue(value), [value]);\n let onChange = newValue => {\n setValue(day || defaultValueTimeZone ? newValue : newValue && toTime(newValue));\n };\n\n let state = useDateFieldState({\n ...props,\n value: dateTime,\n defaultValue: undefined,\n minValue: minDate,\n maxValue: maxDate,\n onChange,\n granularity: granularity || 'minute',\n maxGranularity: 'hour',\n placeholderValue: placeholderDate,\n // Calendar should not matter for time fields.\n createCalendar: () => new GregorianCalendar(),\n validate: useCallback(() => validate?.(value as any), [validate, value])\n });\n\n return {\n ...state,\n timeValue\n };\n}\n\nfunction convertValue(value: TimeValue, date: DateValue = today(getLocalTimeZone())) {\n if (!value) {\n return null;\n }\n\n if ('day' in value) {\n return value;\n }\n\n return toCalendarDateTime(date, value);\n}\n"],"names":[],"version":3,"file":"useTimeFieldState.module.js.map"}
@@ -0,0 +1,190 @@
1
+ var $5294278fb5cc815e$exports = require("./intlStrings.main.js");
2
+ var $68Tdx$internationalizeddate = require("@internationalized/date");
3
+ var $68Tdx$internationalizedstring = require("@internationalized/string");
4
+ var $68Tdx$reactstatelyform = require("@react-stately/form");
5
+ var $68Tdx$react = require("react");
6
+
7
+
8
+ function $parcel$interopDefault(a) {
9
+ return a && a.__esModule ? a.default : a;
10
+ }
11
+
12
+ function $parcel$export(e, n, v, s) {
13
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
14
+ }
15
+
16
+ $parcel$export(module.exports, "getValidationResult", () => $50d5d6a623389320$export$f18627323ab57ac0);
17
+ $parcel$export(module.exports, "getFormatOptions", () => $50d5d6a623389320$export$7e319ea407e63bc0);
18
+ $parcel$export(module.exports, "getRangeValidationResult", () => $50d5d6a623389320$export$80ff8fc0ae339c13);
19
+ $parcel$export(module.exports, "getPlaceholderTime", () => $50d5d6a623389320$export$c5221a78ef73c5e9);
20
+ $parcel$export(module.exports, "convertValue", () => $50d5d6a623389320$export$61a490a80c552550);
21
+ $parcel$export(module.exports, "createPlaceholderDate", () => $50d5d6a623389320$export$66aa2b09de4b1ea5);
22
+ $parcel$export(module.exports, "useDefaultProps", () => $50d5d6a623389320$export$2440da353cedad43);
23
+ /*
24
+ * Copyright 2020 Adobe. All rights reserved.
25
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
26
+ * you may not use this file except in compliance with the License. You may obtain a copy
27
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
28
+ *
29
+ * Unless required by applicable law or agreed to in writing, software distributed under
30
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
31
+ * OF ANY KIND, either express or implied. See the License for the specific language
32
+ * governing permissions and limitations under the License.
33
+ */
34
+
35
+
36
+
37
+
38
+ const $50d5d6a623389320$var$dictionary = new (0, $68Tdx$internationalizedstring.LocalizedStringDictionary)((0, ($parcel$interopDefault($5294278fb5cc815e$exports))));
39
+ function $50d5d6a623389320$var$getLocale() {
40
+ // Match browser language setting here, NOT react-aria's I18nProvider, so that we match other browser-provided
41
+ // validation messages, which to not respect our provider's language.
42
+ // @ts-ignore
43
+ return typeof navigator !== "undefined" && (navigator.language || navigator.userLanguage) || "en-US";
44
+ }
45
+ function $50d5d6a623389320$export$f18627323ab57ac0(value, minValue, maxValue, isDateUnavailable, options) {
46
+ let rangeOverflow = value != null && maxValue != null && value.compare(maxValue) > 0;
47
+ let rangeUnderflow = value != null && minValue != null && value.compare(minValue) < 0;
48
+ let isUnavailable = value != null && (isDateUnavailable === null || isDateUnavailable === void 0 ? void 0 : isDateUnavailable(value)) || false;
49
+ let isInvalid = rangeOverflow || rangeUnderflow || isUnavailable;
50
+ let errors = [];
51
+ if (isInvalid) {
52
+ let locale = $50d5d6a623389320$var$getLocale();
53
+ let strings = (0, $68Tdx$internationalizedstring.LocalizedStringDictionary).getGlobalDictionaryForPackage("@react-stately/datepicker") || $50d5d6a623389320$var$dictionary;
54
+ let formatter = new (0, $68Tdx$internationalizedstring.LocalizedStringFormatter)(locale, strings);
55
+ let dateFormatter = new (0, $68Tdx$internationalizeddate.DateFormatter)(locale, $50d5d6a623389320$export$7e319ea407e63bc0({}, options));
56
+ let timeZone = dateFormatter.resolvedOptions().timeZone;
57
+ if (rangeUnderflow) errors.push(formatter.format("rangeUnderflow", {
58
+ minValue: dateFormatter.format(minValue.toDate(timeZone))
59
+ }));
60
+ if (rangeOverflow) errors.push(formatter.format("rangeOverflow", {
61
+ maxValue: dateFormatter.format(maxValue.toDate(timeZone))
62
+ }));
63
+ if (isUnavailable) errors.push(formatter.format("unavailableDate"));
64
+ }
65
+ return {
66
+ isInvalid: isInvalid,
67
+ validationErrors: errors,
68
+ validationDetails: {
69
+ badInput: isUnavailable,
70
+ customError: false,
71
+ patternMismatch: false,
72
+ rangeOverflow: rangeOverflow,
73
+ rangeUnderflow: rangeUnderflow,
74
+ stepMismatch: false,
75
+ tooLong: false,
76
+ tooShort: false,
77
+ typeMismatch: false,
78
+ valueMissing: false,
79
+ valid: !isInvalid
80
+ }
81
+ };
82
+ }
83
+ function $50d5d6a623389320$export$80ff8fc0ae339c13(value, minValue, maxValue, isDateUnavailable, options) {
84
+ let startValidation = $50d5d6a623389320$export$f18627323ab57ac0(value === null || value === void 0 ? void 0 : value.start, minValue, maxValue, isDateUnavailable, options);
85
+ let endValidation = $50d5d6a623389320$export$f18627323ab57ac0(value === null || value === void 0 ? void 0 : value.end, minValue, maxValue, isDateUnavailable, options);
86
+ let result = (0, $68Tdx$reactstatelyform.mergeValidation)(startValidation, endValidation);
87
+ if (value.end != null && value.start != null && value.end.compare(value.start) < 0) {
88
+ let strings = (0, $68Tdx$internationalizedstring.LocalizedStringDictionary).getGlobalDictionaryForPackage("@react-stately/datepicker") || $50d5d6a623389320$var$dictionary;
89
+ result = (0, $68Tdx$reactstatelyform.mergeValidation)(result, {
90
+ isInvalid: true,
91
+ validationErrors: [
92
+ strings.getStringForLocale("rangeReversed", $50d5d6a623389320$var$getLocale())
93
+ ],
94
+ validationDetails: {
95
+ ...(0, $68Tdx$reactstatelyform.VALID_VALIDITY_STATE),
96
+ rangeUnderflow: true,
97
+ rangeOverflow: true,
98
+ valid: false
99
+ }
100
+ });
101
+ }
102
+ return result;
103
+ }
104
+ const $50d5d6a623389320$var$DEFAULT_FIELD_OPTIONS = {
105
+ year: "numeric",
106
+ month: "numeric",
107
+ day: "numeric",
108
+ hour: "numeric",
109
+ minute: "2-digit",
110
+ second: "2-digit"
111
+ };
112
+ const $50d5d6a623389320$var$TWO_DIGIT_FIELD_OPTIONS = {
113
+ year: "numeric",
114
+ month: "2-digit",
115
+ day: "2-digit",
116
+ hour: "2-digit",
117
+ minute: "2-digit",
118
+ second: "2-digit"
119
+ };
120
+ function $50d5d6a623389320$export$7e319ea407e63bc0(fieldOptions, options) {
121
+ let defaultFieldOptions = options.shouldForceLeadingZeros ? $50d5d6a623389320$var$TWO_DIGIT_FIELD_OPTIONS : $50d5d6a623389320$var$DEFAULT_FIELD_OPTIONS;
122
+ fieldOptions = {
123
+ ...defaultFieldOptions,
124
+ ...fieldOptions
125
+ };
126
+ let granularity = options.granularity || "minute";
127
+ let keys = Object.keys(fieldOptions);
128
+ var _options_maxGranularity;
129
+ let startIdx = keys.indexOf((_options_maxGranularity = options.maxGranularity) !== null && _options_maxGranularity !== void 0 ? _options_maxGranularity : "year");
130
+ if (startIdx < 0) startIdx = 0;
131
+ let endIdx = keys.indexOf(granularity);
132
+ if (endIdx < 0) endIdx = 2;
133
+ if (startIdx > endIdx) throw new Error("maxGranularity must be greater than granularity");
134
+ let opts = keys.slice(startIdx, endIdx + 1).reduce((opts, key)=>{
135
+ opts[key] = fieldOptions[key];
136
+ return opts;
137
+ }, {});
138
+ if (options.hourCycle != null) opts.hour12 = options.hourCycle === 12;
139
+ opts.timeZone = options.timeZone || "UTC";
140
+ let hasTime = granularity === "hour" || granularity === "minute" || granularity === "second";
141
+ if (hasTime && options.timeZone && !options.hideTimeZone) opts.timeZoneName = "short";
142
+ if (options.showEra && startIdx === 0) opts.era = "short";
143
+ return opts;
144
+ }
145
+ function $50d5d6a623389320$export$c5221a78ef73c5e9(placeholderValue) {
146
+ if (placeholderValue && "hour" in placeholderValue) return placeholderValue;
147
+ return new (0, $68Tdx$internationalizeddate.Time)();
148
+ }
149
+ function $50d5d6a623389320$export$61a490a80c552550(value, calendar) {
150
+ if (value === null) return null;
151
+ if (!value) return undefined;
152
+ return (0, $68Tdx$internationalizeddate.toCalendar)(value, calendar);
153
+ }
154
+ function $50d5d6a623389320$export$66aa2b09de4b1ea5(placeholderValue, granularity, calendar, timeZone) {
155
+ if (placeholderValue) return $50d5d6a623389320$export$61a490a80c552550(placeholderValue, calendar);
156
+ let date = (0, $68Tdx$internationalizeddate.toCalendar)((0, $68Tdx$internationalizeddate.now)(timeZone).set({
157
+ hour: 0,
158
+ minute: 0,
159
+ second: 0,
160
+ millisecond: 0
161
+ }), calendar);
162
+ if (granularity === "year" || granularity === "month" || granularity === "day") return (0, $68Tdx$internationalizeddate.toCalendarDate)(date);
163
+ if (!timeZone) return (0, $68Tdx$internationalizeddate.toCalendarDateTime)(date);
164
+ return date;
165
+ }
166
+ function $50d5d6a623389320$export$2440da353cedad43(v, granularity) {
167
+ // Compute default granularity and time zone from the value. If the value becomes null, keep the last values.
168
+ let defaultTimeZone = v && "timeZone" in v ? v.timeZone : undefined;
169
+ let defaultGranularity = v && "minute" in v ? "minute" : "day";
170
+ // props.granularity must actually exist in the value if one is provided.
171
+ if (v && granularity && !(granularity in v)) throw new Error("Invalid granularity " + granularity + " for value " + v.toString());
172
+ let [lastValue, setLastValue] = (0, $68Tdx$react.useState)([
173
+ defaultGranularity,
174
+ defaultTimeZone
175
+ ]);
176
+ // If the granularity or time zone changed, update the last value.
177
+ if (v && (lastValue[0] !== defaultGranularity || lastValue[1] !== defaultTimeZone)) setLastValue([
178
+ defaultGranularity,
179
+ defaultTimeZone
180
+ ]);
181
+ if (!granularity) granularity = v ? defaultGranularity : lastValue[0];
182
+ let timeZone = v ? defaultTimeZone : lastValue[1];
183
+ return [
184
+ granularity,
185
+ timeZone
186
+ ];
187
+ }
188
+
189
+
190
+ //# sourceMappingURL=utils.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAWD,MAAM,mCAAa,IAAI,CAAA,GAAA,wDAAwB,EAAE,CAAA,GAAA,mDAAW;AAE5D,SAAS;IACP,8GAA8G;IAC9G,qEAAqE;IACrE,aAAa;IACb,OAAO,AAAC,OAAO,cAAc,eAAgB,CAAA,UAAU,QAAQ,IAAI,UAAU,YAAY,AAAD,KAAO;AACjG;AAEO,SAAS,0CACd,KAAgB,EAChB,QAAmB,EACnB,QAAmB,EACnB,iBAA4C,EAC5C,OAAyB;IAEzB,IAAI,gBAAgB,SAAS,QAAQ,YAAY,QAAQ,MAAM,OAAO,CAAC,YAAY;IACnF,IAAI,iBAAiB,SAAS,QAAQ,YAAY,QAAQ,MAAM,OAAO,CAAC,YAAY;IACpF,IAAI,gBAAgB,AAAC,SAAS,SAAQ,8BAAA,wCAAA,kBAAoB,WAAW;IACrE,IAAI,YAAY,iBAAiB,kBAAkB;IACnD,IAAI,SAAS,EAAE;IAEf,IAAI,WAAW;QACb,IAAI,SAAS;QACb,IAAI,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AE,KAAK,eAAc,GAC9E,aAAa;QAAC;QAAoB;KAAgB;IAGpD,IAAI,CAAC,aACH,cAAc,IAAI,qBAAqB,SAAS,CAAC,EAAE;IAGrD,IAAI,WAAW,IAAI,kBAAkB,SAAS,CAAC,EAAE;IACjD,OAAO;QAAC;QAAa;KAAS;AAChC","sources":["packages/@react-stately/datepicker/src/utils.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Calendar, DateFormatter, now, Time, toCalendar, toCalendarDate, toCalendarDateTime} from '@internationalized/date';\nimport {DatePickerProps, DateValue, Granularity, TimeValue} from '@react-types/datepicker';\n// @ts-ignore\nimport i18nMessages from '../intl/*.json';\nimport {LocalizedStringDictionary, LocalizedStringFormatter} from '@internationalized/string';\nimport {mergeValidation, VALID_VALIDITY_STATE} from '@react-stately/form';\nimport {RangeValue, ValidationResult} from '@react-types/shared';\nimport {useState} from 'react';\n\nconst dictionary = new LocalizedStringDictionary(i18nMessages);\n\nfunction getLocale() {\n // Match browser language setting here, NOT react-aria's I18nProvider, so that we match other browser-provided\n // validation messages, which to not respect our provider's language.\n // @ts-ignore\n return (typeof navigator !== 'undefined' && (navigator.language || navigator.userLanguage)) || 'en-US';\n}\n\nexport function getValidationResult(\n value: DateValue,\n minValue: DateValue,\n maxValue: DateValue,\n isDateUnavailable: (v: DateValue) => boolean,\n options: FormatterOptions\n): ValidationResult {\n let rangeOverflow = value != null && maxValue != null && value.compare(maxValue) > 0;\n let rangeUnderflow = value != null && minValue != null && value.compare(minValue) < 0;\n let isUnavailable = (value != null && isDateUnavailable?.(value)) || false;\n let isInvalid = rangeOverflow || rangeUnderflow || isUnavailable;\n let errors = [];\n\n if (isInvalid) {\n let locale = getLocale();\n let strings = LocalizedStringDictionary.getGlobalDictionaryForPackage('@react-stately/datepicker') || dictionary;\n let formatter = new LocalizedStringFormatter(locale, strings);\n let dateFormatter = new DateFormatter(locale, getFormatOptions({}, options));\n let timeZone = dateFormatter.resolvedOptions().timeZone;\n\n if (rangeUnderflow) {\n errors.push(formatter.format('rangeUnderflow', {minValue: dateFormatter.format(minValue.toDate(timeZone))}));\n }\n\n if (rangeOverflow) {\n errors.push(formatter.format('rangeOverflow', {maxValue: dateFormatter.format(maxValue.toDate(timeZone))}));\n }\n\n if (isUnavailable) {\n errors.push(formatter.format('unavailableDate'));\n }\n }\n\n return {\n isInvalid,\n validationErrors: errors,\n validationDetails: {\n badInput: isUnavailable,\n customError: false,\n patternMismatch: false,\n rangeOverflow,\n rangeUnderflow,\n stepMismatch: false,\n tooLong: false,\n tooShort: false,\n typeMismatch: false,\n valueMissing: false,\n valid: !isInvalid\n }\n };\n}\n\nexport function getRangeValidationResult(\n value: RangeValue<DateValue>,\n minValue: DateValue,\n maxValue: DateValue,\n isDateUnavailable: (v: DateValue) => boolean,\n options: FormatterOptions\n) {\n let startValidation = getValidationResult(\n value?.start,\n minValue,\n maxValue,\n isDateUnavailable,\n options\n );\n\n let endValidation = getValidationResult(\n value?.end,\n minValue,\n maxValue,\n isDateUnavailable,\n options\n );\n\n let result = mergeValidation(startValidation, endValidation);\n if (value.end != null && value.start != null && value.end.compare(value.start) < 0) {\n let strings = LocalizedStringDictionary.getGlobalDictionaryForPackage('@react-stately/datepicker') || dictionary;\n result = mergeValidation(result, {\n isInvalid: true,\n validationErrors: [strings.getStringForLocale('rangeReversed', getLocale())],\n validationDetails: {\n ...VALID_VALIDITY_STATE,\n rangeUnderflow: true,\n rangeOverflow: true,\n valid: false\n }\n });\n }\n\n return result;\n}\n\nexport type FieldOptions = Pick<Intl.DateTimeFormatOptions, 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second'>;\ninterface FormatterOptions {\n timeZone?: string,\n hideTimeZone?: boolean,\n granularity?: DatePickerProps<any>['granularity'],\n maxGranularity?: 'year' | 'month' | DatePickerProps<any>['granularity'],\n hourCycle?: 12 | 24,\n showEra?: boolean,\n shouldForceLeadingZeros?: boolean\n}\n\nconst DEFAULT_FIELD_OPTIONS: FieldOptions = {\n year: 'numeric',\n month: 'numeric',\n day: 'numeric',\n hour: 'numeric',\n minute: '2-digit',\n second: '2-digit'\n};\n\nconst TWO_DIGIT_FIELD_OPTIONS: FieldOptions = {\n year: 'numeric',\n month: '2-digit',\n day: '2-digit',\n hour: '2-digit',\n minute: '2-digit',\n second: '2-digit'\n};\n\nexport function getFormatOptions(\n fieldOptions: FieldOptions,\n options: FormatterOptions\n): Intl.DateTimeFormatOptions {\n let defaultFieldOptions = options.shouldForceLeadingZeros ? TWO_DIGIT_FIELD_OPTIONS : DEFAULT_FIELD_OPTIONS;\n fieldOptions = {...defaultFieldOptions, ...fieldOptions};\n let granularity = options.granularity || 'minute';\n let keys = Object.keys(fieldOptions);\n let startIdx = keys.indexOf(options.maxGranularity ?? 'year');\n if (startIdx < 0) {\n startIdx = 0;\n }\n\n let endIdx = keys.indexOf(granularity);\n if (endIdx < 0) {\n endIdx = 2;\n }\n\n if (startIdx > endIdx) {\n throw new Error('maxGranularity must be greater than granularity');\n }\n\n let opts: Intl.DateTimeFormatOptions = keys.slice(startIdx, endIdx + 1).reduce((opts, key) => {\n opts[key] = fieldOptions[key];\n return opts;\n }, {});\n\n if (options.hourCycle != null) {\n opts.hour12 = options.hourCycle === 12;\n }\n\n opts.timeZone = options.timeZone || 'UTC';\n\n let hasTime = granularity === 'hour' || granularity === 'minute' || granularity === 'second';\n if (hasTime && options.timeZone && !options.hideTimeZone) {\n opts.timeZoneName = 'short';\n }\n\n if (options.showEra && startIdx === 0) {\n opts.era = 'short';\n }\n\n return opts;\n}\n\nexport function getPlaceholderTime(placeholderValue: DateValue): TimeValue {\n if (placeholderValue && 'hour' in placeholderValue) {\n return placeholderValue;\n }\n\n return new Time();\n}\n\nexport function convertValue(value: DateValue, calendar: Calendar): DateValue {\n if (value === null) {\n return null;\n }\n\n if (!value) {\n return undefined;\n }\n\n return toCalendar(value, calendar);\n}\n\n\nexport function createPlaceholderDate(placeholderValue: DateValue, granularity: string, calendar: Calendar, timeZone: string) {\n if (placeholderValue) {\n return convertValue(placeholderValue, calendar);\n }\n\n let date = toCalendar(now(timeZone).set({\n hour: 0,\n minute: 0,\n second: 0,\n millisecond: 0\n }), calendar);\n\n if (granularity === 'year' || granularity === 'month' || granularity === 'day') {\n return toCalendarDate(date);\n }\n\n if (!timeZone) {\n return toCalendarDateTime(date);\n }\n\n return date;\n}\n\nexport function useDefaultProps(v: DateValue, granularity: Granularity): [Granularity, string] {\n // Compute default granularity and time zone from the value. If the value becomes null, keep the last values.\n let defaultTimeZone = (v && 'timeZone' in v ? v.timeZone : undefined);\n let defaultGranularity: Granularity = (v && 'minute' in v ? 'minute' : 'day');\n\n // props.granularity must actually exist in the value if one is provided.\n if (v && granularity && !(granularity in v)) {\n throw new Error('Invalid granularity ' + granularity + ' for value ' + v.toString());\n }\n\n let [lastValue, setLastValue] = useState<[Granularity, string]>([defaultGranularity, defaultTimeZone]);\n\n // If the granularity or time zone changed, update the last value.\n if (v && (lastValue[0] !== defaultGranularity || lastValue[1] !== defaultTimeZone)) {\n setLastValue([defaultGranularity, defaultTimeZone]);\n }\n\n if (!granularity) {\n granularity = v ? defaultGranularity : lastValue[0];\n }\n\n let timeZone = v ? defaultTimeZone : lastValue[1];\n return [granularity, timeZone];\n}\n"],"names":[],"version":3,"file":"utils.main.js.map"}
package/dist/utils.mjs ADDED
@@ -0,0 +1,179 @@
1
+ import $bUJMr$intlStringsmodulejs from "./intlStrings.mjs";
2
+ import {DateFormatter as $bUJMr$DateFormatter, Time as $bUJMr$Time, toCalendar as $bUJMr$toCalendar, now as $bUJMr$now, toCalendarDate as $bUJMr$toCalendarDate, toCalendarDateTime as $bUJMr$toCalendarDateTime} from "@internationalized/date";
3
+ import {LocalizedStringDictionary as $bUJMr$LocalizedStringDictionary, LocalizedStringFormatter as $bUJMr$LocalizedStringFormatter} from "@internationalized/string";
4
+ import {mergeValidation as $bUJMr$mergeValidation, VALID_VALIDITY_STATE as $bUJMr$VALID_VALIDITY_STATE} from "@react-stately/form";
5
+ import {useState as $bUJMr$useState} from "react";
6
+
7
+
8
+ function $parcel$interopDefault(a) {
9
+ return a && a.__esModule ? a.default : a;
10
+ }
11
+ /*
12
+ * Copyright 2020 Adobe. All rights reserved.
13
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License. You may obtain a copy
15
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software distributed under
18
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
+ * OF ANY KIND, either express or implied. See the License for the specific language
20
+ * governing permissions and limitations under the License.
21
+ */
22
+
23
+
24
+
25
+
26
+ const $35a22f14a1f04b11$var$dictionary = new (0, $bUJMr$LocalizedStringDictionary)((0, ($parcel$interopDefault($bUJMr$intlStringsmodulejs))));
27
+ function $35a22f14a1f04b11$var$getLocale() {
28
+ // Match browser language setting here, NOT react-aria's I18nProvider, so that we match other browser-provided
29
+ // validation messages, which to not respect our provider's language.
30
+ // @ts-ignore
31
+ return typeof navigator !== "undefined" && (navigator.language || navigator.userLanguage) || "en-US";
32
+ }
33
+ function $35a22f14a1f04b11$export$f18627323ab57ac0(value, minValue, maxValue, isDateUnavailable, options) {
34
+ let rangeOverflow = value != null && maxValue != null && value.compare(maxValue) > 0;
35
+ let rangeUnderflow = value != null && minValue != null && value.compare(minValue) < 0;
36
+ let isUnavailable = value != null && (isDateUnavailable === null || isDateUnavailable === void 0 ? void 0 : isDateUnavailable(value)) || false;
37
+ let isInvalid = rangeOverflow || rangeUnderflow || isUnavailable;
38
+ let errors = [];
39
+ if (isInvalid) {
40
+ let locale = $35a22f14a1f04b11$var$getLocale();
41
+ let strings = (0, $bUJMr$LocalizedStringDictionary).getGlobalDictionaryForPackage("@react-stately/datepicker") || $35a22f14a1f04b11$var$dictionary;
42
+ let formatter = new (0, $bUJMr$LocalizedStringFormatter)(locale, strings);
43
+ let dateFormatter = new (0, $bUJMr$DateFormatter)(locale, $35a22f14a1f04b11$export$7e319ea407e63bc0({}, options));
44
+ let timeZone = dateFormatter.resolvedOptions().timeZone;
45
+ if (rangeUnderflow) errors.push(formatter.format("rangeUnderflow", {
46
+ minValue: dateFormatter.format(minValue.toDate(timeZone))
47
+ }));
48
+ if (rangeOverflow) errors.push(formatter.format("rangeOverflow", {
49
+ maxValue: dateFormatter.format(maxValue.toDate(timeZone))
50
+ }));
51
+ if (isUnavailable) errors.push(formatter.format("unavailableDate"));
52
+ }
53
+ return {
54
+ isInvalid: isInvalid,
55
+ validationErrors: errors,
56
+ validationDetails: {
57
+ badInput: isUnavailable,
58
+ customError: false,
59
+ patternMismatch: false,
60
+ rangeOverflow: rangeOverflow,
61
+ rangeUnderflow: rangeUnderflow,
62
+ stepMismatch: false,
63
+ tooLong: false,
64
+ tooShort: false,
65
+ typeMismatch: false,
66
+ valueMissing: false,
67
+ valid: !isInvalid
68
+ }
69
+ };
70
+ }
71
+ function $35a22f14a1f04b11$export$80ff8fc0ae339c13(value, minValue, maxValue, isDateUnavailable, options) {
72
+ let startValidation = $35a22f14a1f04b11$export$f18627323ab57ac0(value === null || value === void 0 ? void 0 : value.start, minValue, maxValue, isDateUnavailable, options);
73
+ let endValidation = $35a22f14a1f04b11$export$f18627323ab57ac0(value === null || value === void 0 ? void 0 : value.end, minValue, maxValue, isDateUnavailable, options);
74
+ let result = (0, $bUJMr$mergeValidation)(startValidation, endValidation);
75
+ if (value.end != null && value.start != null && value.end.compare(value.start) < 0) {
76
+ let strings = (0, $bUJMr$LocalizedStringDictionary).getGlobalDictionaryForPackage("@react-stately/datepicker") || $35a22f14a1f04b11$var$dictionary;
77
+ result = (0, $bUJMr$mergeValidation)(result, {
78
+ isInvalid: true,
79
+ validationErrors: [
80
+ strings.getStringForLocale("rangeReversed", $35a22f14a1f04b11$var$getLocale())
81
+ ],
82
+ validationDetails: {
83
+ ...(0, $bUJMr$VALID_VALIDITY_STATE),
84
+ rangeUnderflow: true,
85
+ rangeOverflow: true,
86
+ valid: false
87
+ }
88
+ });
89
+ }
90
+ return result;
91
+ }
92
+ const $35a22f14a1f04b11$var$DEFAULT_FIELD_OPTIONS = {
93
+ year: "numeric",
94
+ month: "numeric",
95
+ day: "numeric",
96
+ hour: "numeric",
97
+ minute: "2-digit",
98
+ second: "2-digit"
99
+ };
100
+ const $35a22f14a1f04b11$var$TWO_DIGIT_FIELD_OPTIONS = {
101
+ year: "numeric",
102
+ month: "2-digit",
103
+ day: "2-digit",
104
+ hour: "2-digit",
105
+ minute: "2-digit",
106
+ second: "2-digit"
107
+ };
108
+ function $35a22f14a1f04b11$export$7e319ea407e63bc0(fieldOptions, options) {
109
+ let defaultFieldOptions = options.shouldForceLeadingZeros ? $35a22f14a1f04b11$var$TWO_DIGIT_FIELD_OPTIONS : $35a22f14a1f04b11$var$DEFAULT_FIELD_OPTIONS;
110
+ fieldOptions = {
111
+ ...defaultFieldOptions,
112
+ ...fieldOptions
113
+ };
114
+ let granularity = options.granularity || "minute";
115
+ let keys = Object.keys(fieldOptions);
116
+ var _options_maxGranularity;
117
+ let startIdx = keys.indexOf((_options_maxGranularity = options.maxGranularity) !== null && _options_maxGranularity !== void 0 ? _options_maxGranularity : "year");
118
+ if (startIdx < 0) startIdx = 0;
119
+ let endIdx = keys.indexOf(granularity);
120
+ if (endIdx < 0) endIdx = 2;
121
+ if (startIdx > endIdx) throw new Error("maxGranularity must be greater than granularity");
122
+ let opts = keys.slice(startIdx, endIdx + 1).reduce((opts, key)=>{
123
+ opts[key] = fieldOptions[key];
124
+ return opts;
125
+ }, {});
126
+ if (options.hourCycle != null) opts.hour12 = options.hourCycle === 12;
127
+ opts.timeZone = options.timeZone || "UTC";
128
+ let hasTime = granularity === "hour" || granularity === "minute" || granularity === "second";
129
+ if (hasTime && options.timeZone && !options.hideTimeZone) opts.timeZoneName = "short";
130
+ if (options.showEra && startIdx === 0) opts.era = "short";
131
+ return opts;
132
+ }
133
+ function $35a22f14a1f04b11$export$c5221a78ef73c5e9(placeholderValue) {
134
+ if (placeholderValue && "hour" in placeholderValue) return placeholderValue;
135
+ return new (0, $bUJMr$Time)();
136
+ }
137
+ function $35a22f14a1f04b11$export$61a490a80c552550(value, calendar) {
138
+ if (value === null) return null;
139
+ if (!value) return undefined;
140
+ return (0, $bUJMr$toCalendar)(value, calendar);
141
+ }
142
+ function $35a22f14a1f04b11$export$66aa2b09de4b1ea5(placeholderValue, granularity, calendar, timeZone) {
143
+ if (placeholderValue) return $35a22f14a1f04b11$export$61a490a80c552550(placeholderValue, calendar);
144
+ let date = (0, $bUJMr$toCalendar)((0, $bUJMr$now)(timeZone).set({
145
+ hour: 0,
146
+ minute: 0,
147
+ second: 0,
148
+ millisecond: 0
149
+ }), calendar);
150
+ if (granularity === "year" || granularity === "month" || granularity === "day") return (0, $bUJMr$toCalendarDate)(date);
151
+ if (!timeZone) return (0, $bUJMr$toCalendarDateTime)(date);
152
+ return date;
153
+ }
154
+ function $35a22f14a1f04b11$export$2440da353cedad43(v, granularity) {
155
+ // Compute default granularity and time zone from the value. If the value becomes null, keep the last values.
156
+ let defaultTimeZone = v && "timeZone" in v ? v.timeZone : undefined;
157
+ let defaultGranularity = v && "minute" in v ? "minute" : "day";
158
+ // props.granularity must actually exist in the value if one is provided.
159
+ if (v && granularity && !(granularity in v)) throw new Error("Invalid granularity " + granularity + " for value " + v.toString());
160
+ let [lastValue, setLastValue] = (0, $bUJMr$useState)([
161
+ defaultGranularity,
162
+ defaultTimeZone
163
+ ]);
164
+ // If the granularity or time zone changed, update the last value.
165
+ if (v && (lastValue[0] !== defaultGranularity || lastValue[1] !== defaultTimeZone)) setLastValue([
166
+ defaultGranularity,
167
+ defaultTimeZone
168
+ ]);
169
+ if (!granularity) granularity = v ? defaultGranularity : lastValue[0];
170
+ let timeZone = v ? defaultTimeZone : lastValue[1];
171
+ return [
172
+ granularity,
173
+ timeZone
174
+ ];
175
+ }
176
+
177
+
178
+ export {$35a22f14a1f04b11$export$f18627323ab57ac0 as getValidationResult, $35a22f14a1f04b11$export$7e319ea407e63bc0 as getFormatOptions, $35a22f14a1f04b11$export$80ff8fc0ae339c13 as getRangeValidationResult, $35a22f14a1f04b11$export$c5221a78ef73c5e9 as getPlaceholderTime, $35a22f14a1f04b11$export$61a490a80c552550 as convertValue, $35a22f14a1f04b11$export$66aa2b09de4b1ea5 as createPlaceholderDate, $35a22f14a1f04b11$export$2440da353cedad43 as useDefaultProps};
179
+ //# sourceMappingURL=utils.mjs.map