@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,179 @@
1
+ import $bUJMr$intlStringsmodulejs from "./intlStrings.module.js";
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.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAWD,MAAM,mCAAa,IAAI,CAAA,GAAA,gCAAwB,EAAE,CAAA,GAAA,oDAAW;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,UAAU,CAAA,GAAA,gCAAwB,EAAE,6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AoB;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.module.js.map"}
package/dist/zh-CN.mjs CHANGED
@@ -8,4 +8,4 @@ $e6cc491d590dfda5$exports = {
8
8
 
9
9
 
10
10
  export {$e6cc491d590dfda5$exports as default};
11
- //# sourceMappingURL=zh-CN.module.js.map
11
+ //# sourceMappingURL=zh-CN.mjs.map
package/dist/zh-TW.mjs CHANGED
@@ -8,4 +8,4 @@ $9aebf53181a474bd$exports = {
8
8
 
9
9
 
10
10
  export {$9aebf53181a474bd$exports as default};
11
- //# sourceMappingURL=zh-TW.module.js.map
11
+ //# sourceMappingURL=zh-TW.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/datepicker",
3
- "version": "3.9.1",
3
+ "version": "3.9.3",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,13 +22,13 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@internationalized/date": "^3.5.1",
26
- "@internationalized/string": "^3.2.0",
27
- "@react-stately/form": "^3.0.0",
28
- "@react-stately/overlays": "^3.6.4",
29
- "@react-stately/utils": "^3.9.0",
30
- "@react-types/datepicker": "^3.7.1",
31
- "@react-types/shared": "^3.22.0",
25
+ "@internationalized/date": "^3.5.3",
26
+ "@internationalized/string": "^3.2.2",
27
+ "@react-stately/form": "^3.0.2",
28
+ "@react-stately/overlays": "^3.6.6",
29
+ "@react-stately/utils": "^3.10.0",
30
+ "@react-types/datepicker": "^3.7.3",
31
+ "@react-types/shared": "^3.23.0",
32
32
  "@swc/helpers": "^0.5.0"
33
33
  },
34
34
  "peerDependencies": {
@@ -37,5 +37,5 @@
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "86b38c87868ce7f262e0df905e5ac4eb2653791d"
40
+ "gitHead": "f645f29edc1322153fd60af4640cbcab1d992dbd"
41
41
  }
package/src/utils.ts CHANGED
@@ -105,9 +105,10 @@ export function getRangeValidationResult(
105
105
 
106
106
  let result = mergeValidation(startValidation, endValidation);
107
107
  if (value.end != null && value.start != null && value.end.compare(value.start) < 0) {
108
+ let strings = LocalizedStringDictionary.getGlobalDictionaryForPackage('@react-stately/datepicker') || dictionary;
108
109
  result = mergeValidation(result, {
109
110
  isInvalid: true,
110
- validationErrors: [dictionary.getStringForLocale('rangeReversed', getLocale())],
111
+ validationErrors: [strings.getStringForLocale('rangeReversed', getLocale())],
111
112
  validationDetails: {
112
113
  ...VALID_VALIDITY_STATE,
113
114
  rangeUnderflow: true,