@react-stately/datepicker 3.9.3 → 3.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) 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/intlStrings.mjs +1 -1
  16. package/dist/it-IT.mjs +1 -1
  17. package/dist/ja-JP.mjs +1 -1
  18. package/dist/ko-KR.mjs +1 -1
  19. package/dist/lt-LT.mjs +1 -1
  20. package/dist/lv-LV.mjs +1 -1
  21. package/dist/nb-NO.mjs +1 -1
  22. package/dist/nl-NL.mjs +1 -1
  23. package/dist/pl-PL.mjs +1 -1
  24. package/dist/placeholders.main.js +155 -155
  25. package/dist/placeholders.mjs +156 -156
  26. package/dist/placeholders.module.js +155 -155
  27. package/dist/pt-BR.mjs +1 -1
  28. package/dist/pt-PT.mjs +1 -1
  29. package/dist/ro-RO.mjs +1 -1
  30. package/dist/ru-RU.mjs +1 -1
  31. package/dist/sk-SK.mjs +1 -1
  32. package/dist/sl-SI.mjs +1 -1
  33. package/dist/sr-SP.mjs +1 -1
  34. package/dist/sv-SE.mjs +1 -1
  35. package/dist/tr-TR.mjs +1 -1
  36. package/dist/types.d.ts +16 -1
  37. package/dist/types.d.ts.map +1 -1
  38. package/dist/uk-UA.mjs +1 -1
  39. package/dist/useDateFieldState.main.js +50 -42
  40. package/dist/useDateFieldState.main.js.map +1 -1
  41. package/dist/useDateFieldState.mjs +51 -43
  42. package/dist/useDateFieldState.module.js +50 -42
  43. package/dist/useDateFieldState.module.js.map +1 -1
  44. package/dist/useDatePickerState.main.js +17 -9
  45. package/dist/useDatePickerState.main.js.map +1 -1
  46. package/dist/useDatePickerState.mjs +18 -10
  47. package/dist/useDatePickerState.module.js +17 -9
  48. package/dist/useDatePickerState.module.js.map +1 -1
  49. package/dist/useDateRangePickerState.main.js +26 -18
  50. package/dist/useDateRangePickerState.main.js.map +1 -1
  51. package/dist/useDateRangePickerState.mjs +27 -19
  52. package/dist/useDateRangePickerState.module.js +26 -18
  53. package/dist/useDateRangePickerState.module.js.map +1 -1
  54. package/dist/useTimeFieldState.main.js +7 -7
  55. package/dist/useTimeFieldState.mjs +8 -8
  56. package/dist/useTimeFieldState.module.js +7 -7
  57. package/dist/utils.main.js +31 -31
  58. package/dist/utils.main.js.map +1 -1
  59. package/dist/utils.mjs +32 -32
  60. package/dist/utils.module.js +31 -31
  61. package/dist/utils.module.js.map +1 -1
  62. package/dist/zh-CN.mjs +1 -1
  63. package/dist/zh-TW.mjs +1 -1
  64. package/package.json +10 -10
  65. package/src/useDateFieldState.ts +10 -3
  66. package/src/useDatePickerState.ts +9 -2
  67. package/src/useDateRangePickerState.ts +10 -2
  68. package/src/utils.ts +1 -1
@@ -40,7 +40,7 @@ function $50d5d6a623389320$var$getLocale() {
40
40
  // Match browser language setting here, NOT react-aria's I18nProvider, so that we match other browser-provided
41
41
  // validation messages, which to not respect our provider's language.
42
42
  // @ts-ignore
43
- return typeof navigator !== "undefined" && (navigator.language || navigator.userLanguage) || "en-US";
43
+ return typeof navigator !== 'undefined' && (navigator.language || navigator.userLanguage) || 'en-US';
44
44
  }
45
45
  function $50d5d6a623389320$export$f18627323ab57ac0(value, minValue, maxValue, isDateUnavailable, options) {
46
46
  let rangeOverflow = value != null && maxValue != null && value.compare(maxValue) > 0;
@@ -50,17 +50,17 @@ function $50d5d6a623389320$export$f18627323ab57ac0(value, minValue, maxValue, is
50
50
  let errors = [];
51
51
  if (isInvalid) {
52
52
  let locale = $50d5d6a623389320$var$getLocale();
53
- let strings = (0, $68Tdx$internationalizedstring.LocalizedStringDictionary).getGlobalDictionaryForPackage("@react-stately/datepicker") || $50d5d6a623389320$var$dictionary;
53
+ let strings = (0, $68Tdx$internationalizedstring.LocalizedStringDictionary).getGlobalDictionaryForPackage('@react-stately/datepicker') || $50d5d6a623389320$var$dictionary;
54
54
  let formatter = new (0, $68Tdx$internationalizedstring.LocalizedStringFormatter)(locale, strings);
55
55
  let dateFormatter = new (0, $68Tdx$internationalizeddate.DateFormatter)(locale, $50d5d6a623389320$export$7e319ea407e63bc0({}, options));
56
56
  let timeZone = dateFormatter.resolvedOptions().timeZone;
57
- if (rangeUnderflow) errors.push(formatter.format("rangeUnderflow", {
57
+ if (rangeUnderflow) errors.push(formatter.format('rangeUnderflow', {
58
58
  minValue: dateFormatter.format(minValue.toDate(timeZone))
59
59
  }));
60
- if (rangeOverflow) errors.push(formatter.format("rangeOverflow", {
60
+ if (rangeOverflow) errors.push(formatter.format('rangeOverflow', {
61
61
  maxValue: dateFormatter.format(maxValue.toDate(timeZone))
62
62
  }));
63
- if (isUnavailable) errors.push(formatter.format("unavailableDate"));
63
+ if (isUnavailable) errors.push(formatter.format('unavailableDate'));
64
64
  }
65
65
  return {
66
66
  isInvalid: isInvalid,
@@ -85,11 +85,11 @@ function $50d5d6a623389320$export$80ff8fc0ae339c13(value, minValue, maxValue, is
85
85
  let endValidation = $50d5d6a623389320$export$f18627323ab57ac0(value === null || value === void 0 ? void 0 : value.end, minValue, maxValue, isDateUnavailable, options);
86
86
  let result = (0, $68Tdx$reactstatelyform.mergeValidation)(startValidation, endValidation);
87
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;
88
+ let strings = (0, $68Tdx$internationalizedstring.LocalizedStringDictionary).getGlobalDictionaryForPackage('@react-stately/datepicker') || $50d5d6a623389320$var$dictionary;
89
89
  result = (0, $68Tdx$reactstatelyform.mergeValidation)(result, {
90
90
  isInvalid: true,
91
91
  validationErrors: [
92
- strings.getStringForLocale("rangeReversed", $50d5d6a623389320$var$getLocale())
92
+ strings.getStringForLocale('rangeReversed', $50d5d6a623389320$var$getLocale())
93
93
  ],
94
94
  validationDetails: {
95
95
  ...(0, $68Tdx$reactstatelyform.VALID_VALIDITY_STATE),
@@ -102,20 +102,20 @@ function $50d5d6a623389320$export$80ff8fc0ae339c13(value, minValue, maxValue, is
102
102
  return result;
103
103
  }
104
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"
105
+ year: 'numeric',
106
+ month: 'numeric',
107
+ day: 'numeric',
108
+ hour: 'numeric',
109
+ minute: '2-digit',
110
+ second: '2-digit'
111
111
  };
112
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"
113
+ year: 'numeric',
114
+ month: '2-digit',
115
+ day: '2-digit',
116
+ hour: '2-digit',
117
+ minute: '2-digit',
118
+ second: '2-digit'
119
119
  };
120
120
  function $50d5d6a623389320$export$7e319ea407e63bc0(fieldOptions, options) {
121
121
  let defaultFieldOptions = options.shouldForceLeadingZeros ? $50d5d6a623389320$var$TWO_DIGIT_FIELD_OPTIONS : $50d5d6a623389320$var$DEFAULT_FIELD_OPTIONS;
@@ -123,27 +123,27 @@ function $50d5d6a623389320$export$7e319ea407e63bc0(fieldOptions, options) {
123
123
  ...defaultFieldOptions,
124
124
  ...fieldOptions
125
125
  };
126
- let granularity = options.granularity || "minute";
126
+ let granularity = options.granularity || 'minute';
127
127
  let keys = Object.keys(fieldOptions);
128
128
  var _options_maxGranularity;
129
- let startIdx = keys.indexOf((_options_maxGranularity = options.maxGranularity) !== null && _options_maxGranularity !== void 0 ? _options_maxGranularity : "year");
129
+ let startIdx = keys.indexOf((_options_maxGranularity = options.maxGranularity) !== null && _options_maxGranularity !== void 0 ? _options_maxGranularity : 'year');
130
130
  if (startIdx < 0) startIdx = 0;
131
131
  let endIdx = keys.indexOf(granularity);
132
132
  if (endIdx < 0) endIdx = 2;
133
- if (startIdx > endIdx) throw new Error("maxGranularity must be greater than granularity");
133
+ if (startIdx > endIdx) throw new Error('maxGranularity must be greater than granularity');
134
134
  let opts = keys.slice(startIdx, endIdx + 1).reduce((opts, key)=>{
135
135
  opts[key] = fieldOptions[key];
136
136
  return opts;
137
137
  }, {});
138
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";
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
143
  return opts;
144
144
  }
145
145
  function $50d5d6a623389320$export$c5221a78ef73c5e9(placeholderValue) {
146
- if (placeholderValue && "hour" in placeholderValue) return placeholderValue;
146
+ if (placeholderValue && 'hour' in placeholderValue) return placeholderValue;
147
147
  return new (0, $68Tdx$internationalizeddate.Time)();
148
148
  }
149
149
  function $50d5d6a623389320$export$61a490a80c552550(value, calendar) {
@@ -159,16 +159,16 @@ function $50d5d6a623389320$export$66aa2b09de4b1ea5(placeholderValue, granularity
159
159
  second: 0,
160
160
  millisecond: 0
161
161
  }), calendar);
162
- if (granularity === "year" || granularity === "month" || granularity === "day") return (0, $68Tdx$internationalizeddate.toCalendarDate)(date);
162
+ if (granularity === 'year' || granularity === 'month' || granularity === 'day') return (0, $68Tdx$internationalizeddate.toCalendarDate)(date);
163
163
  if (!timeZone) return (0, $68Tdx$internationalizeddate.toCalendarDateTime)(date);
164
164
  return date;
165
165
  }
166
166
  function $50d5d6a623389320$export$2440da353cedad43(v, granularity) {
167
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";
168
+ let defaultTimeZone = v && 'timeZone' in v ? v.timeZone : undefined;
169
+ let defaultGranularity = v && 'minute' in v ? 'minute' : 'day';
170
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());
171
+ if (v && granularity && !(granularity in v)) throw new Error('Invalid granularity ' + granularity + ' for value ' + v.toString());
172
172
  let [lastValue, setLastValue] = (0, $68Tdx$react.useState)([
173
173
  defaultGranularity,
174
174
  defaultTimeZone
@@ -1 +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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AG,CAAA,GAAA,qBAAO,EAAyB;QAAC;QAAoB;KAAgB;IAErG,kEAAkE;IAClE,IAAI,KAAM,CAAA,SAAS,CAAC,EAAE,KAAK,sBAAsB,SAAS,CAAC,EAAE,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"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;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QAAQ;QACR,aAAa;IACf,IAAI;IAEJ,IAAI,gBAAgB,UAAU,gBAAgB,WAAW,gBAAgB,OACvE,OAAO,CAAA,GAAA,2CAAa,EAAE;IAGxB,IAAI,CAAC,UACH,OAAO,CAAA,GAAA,+CAAiB,EAAE;IAG5B,OAAO;AACT;AAEO,SAAS,0CAAgB,CAAY,EAAE,WAAwB;IACpE,6GAA6G;IAC7G,IAAI,kBAAmB,KAAK,cAAc,IAAI,EAAE,QAAQ,GAAG;IAC3D,IAAI,qBAAmC,KAAK,YAAY,IAAI,WAAW;IAEvE,yEAAyE;IACzE,IAAI,KAAK,eAAe,CAAE,CAAA,eAAe,CAAA,GACvC,MAAM,IAAI,MAAM,yBAAyB,cAAc,gBAAgB,EAAE,QAAQ;IAGnF,IAAI,CAAC,WAAW,aAAa,GAAG,CAAA,GAAA,qBAAO,EAAyB;QAAC;QAAoB;KAAgB;IAErG,kEAAkE;IAClE,IAAI,KAAM,CAAA,SAAS,CAAC,EAAE,KAAK,sBAAsB,SAAS,CAAC,EAAE,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'>;\nexport interface 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 CHANGED
@@ -28,7 +28,7 @@ function $35a22f14a1f04b11$var$getLocale() {
28
28
  // Match browser language setting here, NOT react-aria's I18nProvider, so that we match other browser-provided
29
29
  // validation messages, which to not respect our provider's language.
30
30
  // @ts-ignore
31
- return typeof navigator !== "undefined" && (navigator.language || navigator.userLanguage) || "en-US";
31
+ return typeof navigator !== 'undefined' && (navigator.language || navigator.userLanguage) || 'en-US';
32
32
  }
33
33
  function $35a22f14a1f04b11$export$f18627323ab57ac0(value, minValue, maxValue, isDateUnavailable, options) {
34
34
  let rangeOverflow = value != null && maxValue != null && value.compare(maxValue) > 0;
@@ -38,17 +38,17 @@ function $35a22f14a1f04b11$export$f18627323ab57ac0(value, minValue, maxValue, is
38
38
  let errors = [];
39
39
  if (isInvalid) {
40
40
  let locale = $35a22f14a1f04b11$var$getLocale();
41
- let strings = (0, $bUJMr$LocalizedStringDictionary).getGlobalDictionaryForPackage("@react-stately/datepicker") || $35a22f14a1f04b11$var$dictionary;
41
+ let strings = (0, $bUJMr$LocalizedStringDictionary).getGlobalDictionaryForPackage('@react-stately/datepicker') || $35a22f14a1f04b11$var$dictionary;
42
42
  let formatter = new (0, $bUJMr$LocalizedStringFormatter)(locale, strings);
43
43
  let dateFormatter = new (0, $bUJMr$DateFormatter)(locale, $35a22f14a1f04b11$export$7e319ea407e63bc0({}, options));
44
44
  let timeZone = dateFormatter.resolvedOptions().timeZone;
45
- if (rangeUnderflow) errors.push(formatter.format("rangeUnderflow", {
45
+ if (rangeUnderflow) errors.push(formatter.format('rangeUnderflow', {
46
46
  minValue: dateFormatter.format(minValue.toDate(timeZone))
47
47
  }));
48
- if (rangeOverflow) errors.push(formatter.format("rangeOverflow", {
48
+ if (rangeOverflow) errors.push(formatter.format('rangeOverflow', {
49
49
  maxValue: dateFormatter.format(maxValue.toDate(timeZone))
50
50
  }));
51
- if (isUnavailable) errors.push(formatter.format("unavailableDate"));
51
+ if (isUnavailable) errors.push(formatter.format('unavailableDate'));
52
52
  }
53
53
  return {
54
54
  isInvalid: isInvalid,
@@ -73,11 +73,11 @@ function $35a22f14a1f04b11$export$80ff8fc0ae339c13(value, minValue, maxValue, is
73
73
  let endValidation = $35a22f14a1f04b11$export$f18627323ab57ac0(value === null || value === void 0 ? void 0 : value.end, minValue, maxValue, isDateUnavailable, options);
74
74
  let result = (0, $bUJMr$mergeValidation)(startValidation, endValidation);
75
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;
76
+ let strings = (0, $bUJMr$LocalizedStringDictionary).getGlobalDictionaryForPackage('@react-stately/datepicker') || $35a22f14a1f04b11$var$dictionary;
77
77
  result = (0, $bUJMr$mergeValidation)(result, {
78
78
  isInvalid: true,
79
79
  validationErrors: [
80
- strings.getStringForLocale("rangeReversed", $35a22f14a1f04b11$var$getLocale())
80
+ strings.getStringForLocale('rangeReversed', $35a22f14a1f04b11$var$getLocale())
81
81
  ],
82
82
  validationDetails: {
83
83
  ...(0, $bUJMr$VALID_VALIDITY_STATE),
@@ -90,20 +90,20 @@ function $35a22f14a1f04b11$export$80ff8fc0ae339c13(value, minValue, maxValue, is
90
90
  return result;
91
91
  }
92
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"
93
+ year: 'numeric',
94
+ month: 'numeric',
95
+ day: 'numeric',
96
+ hour: 'numeric',
97
+ minute: '2-digit',
98
+ second: '2-digit'
99
99
  };
100
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"
101
+ year: 'numeric',
102
+ month: '2-digit',
103
+ day: '2-digit',
104
+ hour: '2-digit',
105
+ minute: '2-digit',
106
+ second: '2-digit'
107
107
  };
108
108
  function $35a22f14a1f04b11$export$7e319ea407e63bc0(fieldOptions, options) {
109
109
  let defaultFieldOptions = options.shouldForceLeadingZeros ? $35a22f14a1f04b11$var$TWO_DIGIT_FIELD_OPTIONS : $35a22f14a1f04b11$var$DEFAULT_FIELD_OPTIONS;
@@ -111,27 +111,27 @@ function $35a22f14a1f04b11$export$7e319ea407e63bc0(fieldOptions, options) {
111
111
  ...defaultFieldOptions,
112
112
  ...fieldOptions
113
113
  };
114
- let granularity = options.granularity || "minute";
114
+ let granularity = options.granularity || 'minute';
115
115
  let keys = Object.keys(fieldOptions);
116
116
  var _options_maxGranularity;
117
- let startIdx = keys.indexOf((_options_maxGranularity = options.maxGranularity) !== null && _options_maxGranularity !== void 0 ? _options_maxGranularity : "year");
117
+ let startIdx = keys.indexOf((_options_maxGranularity = options.maxGranularity) !== null && _options_maxGranularity !== void 0 ? _options_maxGranularity : 'year');
118
118
  if (startIdx < 0) startIdx = 0;
119
119
  let endIdx = keys.indexOf(granularity);
120
120
  if (endIdx < 0) endIdx = 2;
121
- if (startIdx > endIdx) throw new Error("maxGranularity must be greater than granularity");
121
+ if (startIdx > endIdx) throw new Error('maxGranularity must be greater than granularity');
122
122
  let opts = keys.slice(startIdx, endIdx + 1).reduce((opts, key)=>{
123
123
  opts[key] = fieldOptions[key];
124
124
  return opts;
125
125
  }, {});
126
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";
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
131
  return opts;
132
132
  }
133
133
  function $35a22f14a1f04b11$export$c5221a78ef73c5e9(placeholderValue) {
134
- if (placeholderValue && "hour" in placeholderValue) return placeholderValue;
134
+ if (placeholderValue && 'hour' in placeholderValue) return placeholderValue;
135
135
  return new (0, $bUJMr$Time)();
136
136
  }
137
137
  function $35a22f14a1f04b11$export$61a490a80c552550(value, calendar) {
@@ -147,16 +147,16 @@ function $35a22f14a1f04b11$export$66aa2b09de4b1ea5(placeholderValue, granularity
147
147
  second: 0,
148
148
  millisecond: 0
149
149
  }), calendar);
150
- if (granularity === "year" || granularity === "month" || granularity === "day") return (0, $bUJMr$toCalendarDate)(date);
150
+ if (granularity === 'year' || granularity === 'month' || granularity === 'day') return (0, $bUJMr$toCalendarDate)(date);
151
151
  if (!timeZone) return (0, $bUJMr$toCalendarDateTime)(date);
152
152
  return date;
153
153
  }
154
154
  function $35a22f14a1f04b11$export$2440da353cedad43(v, granularity) {
155
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";
156
+ let defaultTimeZone = v && 'timeZone' in v ? v.timeZone : undefined;
157
+ let defaultGranularity = v && 'minute' in v ? 'minute' : 'day';
158
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());
159
+ if (v && granularity && !(granularity in v)) throw new Error('Invalid granularity ' + granularity + ' for value ' + v.toString());
160
160
  let [lastValue, setLastValue] = (0, $bUJMr$useState)([
161
161
  defaultGranularity,
162
162
  defaultTimeZone
@@ -176,4 +176,4 @@ function $35a22f14a1f04b11$export$2440da353cedad43(v, granularity) {
176
176
 
177
177
 
178
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
179
+ //# sourceMappingURL=utils.module.js.map
@@ -28,7 +28,7 @@ function $35a22f14a1f04b11$var$getLocale() {
28
28
  // Match browser language setting here, NOT react-aria's I18nProvider, so that we match other browser-provided
29
29
  // validation messages, which to not respect our provider's language.
30
30
  // @ts-ignore
31
- return typeof navigator !== "undefined" && (navigator.language || navigator.userLanguage) || "en-US";
31
+ return typeof navigator !== 'undefined' && (navigator.language || navigator.userLanguage) || 'en-US';
32
32
  }
33
33
  function $35a22f14a1f04b11$export$f18627323ab57ac0(value, minValue, maxValue, isDateUnavailable, options) {
34
34
  let rangeOverflow = value != null && maxValue != null && value.compare(maxValue) > 0;
@@ -38,17 +38,17 @@ function $35a22f14a1f04b11$export$f18627323ab57ac0(value, minValue, maxValue, is
38
38
  let errors = [];
39
39
  if (isInvalid) {
40
40
  let locale = $35a22f14a1f04b11$var$getLocale();
41
- let strings = (0, $bUJMr$LocalizedStringDictionary).getGlobalDictionaryForPackage("@react-stately/datepicker") || $35a22f14a1f04b11$var$dictionary;
41
+ let strings = (0, $bUJMr$LocalizedStringDictionary).getGlobalDictionaryForPackage('@react-stately/datepicker') || $35a22f14a1f04b11$var$dictionary;
42
42
  let formatter = new (0, $bUJMr$LocalizedStringFormatter)(locale, strings);
43
43
  let dateFormatter = new (0, $bUJMr$DateFormatter)(locale, $35a22f14a1f04b11$export$7e319ea407e63bc0({}, options));
44
44
  let timeZone = dateFormatter.resolvedOptions().timeZone;
45
- if (rangeUnderflow) errors.push(formatter.format("rangeUnderflow", {
45
+ if (rangeUnderflow) errors.push(formatter.format('rangeUnderflow', {
46
46
  minValue: dateFormatter.format(minValue.toDate(timeZone))
47
47
  }));
48
- if (rangeOverflow) errors.push(formatter.format("rangeOverflow", {
48
+ if (rangeOverflow) errors.push(formatter.format('rangeOverflow', {
49
49
  maxValue: dateFormatter.format(maxValue.toDate(timeZone))
50
50
  }));
51
- if (isUnavailable) errors.push(formatter.format("unavailableDate"));
51
+ if (isUnavailable) errors.push(formatter.format('unavailableDate'));
52
52
  }
53
53
  return {
54
54
  isInvalid: isInvalid,
@@ -73,11 +73,11 @@ function $35a22f14a1f04b11$export$80ff8fc0ae339c13(value, minValue, maxValue, is
73
73
  let endValidation = $35a22f14a1f04b11$export$f18627323ab57ac0(value === null || value === void 0 ? void 0 : value.end, minValue, maxValue, isDateUnavailable, options);
74
74
  let result = (0, $bUJMr$mergeValidation)(startValidation, endValidation);
75
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;
76
+ let strings = (0, $bUJMr$LocalizedStringDictionary).getGlobalDictionaryForPackage('@react-stately/datepicker') || $35a22f14a1f04b11$var$dictionary;
77
77
  result = (0, $bUJMr$mergeValidation)(result, {
78
78
  isInvalid: true,
79
79
  validationErrors: [
80
- strings.getStringForLocale("rangeReversed", $35a22f14a1f04b11$var$getLocale())
80
+ strings.getStringForLocale('rangeReversed', $35a22f14a1f04b11$var$getLocale())
81
81
  ],
82
82
  validationDetails: {
83
83
  ...(0, $bUJMr$VALID_VALIDITY_STATE),
@@ -90,20 +90,20 @@ function $35a22f14a1f04b11$export$80ff8fc0ae339c13(value, minValue, maxValue, is
90
90
  return result;
91
91
  }
92
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"
93
+ year: 'numeric',
94
+ month: 'numeric',
95
+ day: 'numeric',
96
+ hour: 'numeric',
97
+ minute: '2-digit',
98
+ second: '2-digit'
99
99
  };
100
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"
101
+ year: 'numeric',
102
+ month: '2-digit',
103
+ day: '2-digit',
104
+ hour: '2-digit',
105
+ minute: '2-digit',
106
+ second: '2-digit'
107
107
  };
108
108
  function $35a22f14a1f04b11$export$7e319ea407e63bc0(fieldOptions, options) {
109
109
  let defaultFieldOptions = options.shouldForceLeadingZeros ? $35a22f14a1f04b11$var$TWO_DIGIT_FIELD_OPTIONS : $35a22f14a1f04b11$var$DEFAULT_FIELD_OPTIONS;
@@ -111,27 +111,27 @@ function $35a22f14a1f04b11$export$7e319ea407e63bc0(fieldOptions, options) {
111
111
  ...defaultFieldOptions,
112
112
  ...fieldOptions
113
113
  };
114
- let granularity = options.granularity || "minute";
114
+ let granularity = options.granularity || 'minute';
115
115
  let keys = Object.keys(fieldOptions);
116
116
  var _options_maxGranularity;
117
- let startIdx = keys.indexOf((_options_maxGranularity = options.maxGranularity) !== null && _options_maxGranularity !== void 0 ? _options_maxGranularity : "year");
117
+ let startIdx = keys.indexOf((_options_maxGranularity = options.maxGranularity) !== null && _options_maxGranularity !== void 0 ? _options_maxGranularity : 'year');
118
118
  if (startIdx < 0) startIdx = 0;
119
119
  let endIdx = keys.indexOf(granularity);
120
120
  if (endIdx < 0) endIdx = 2;
121
- if (startIdx > endIdx) throw new Error("maxGranularity must be greater than granularity");
121
+ if (startIdx > endIdx) throw new Error('maxGranularity must be greater than granularity');
122
122
  let opts = keys.slice(startIdx, endIdx + 1).reduce((opts, key)=>{
123
123
  opts[key] = fieldOptions[key];
124
124
  return opts;
125
125
  }, {});
126
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";
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
131
  return opts;
132
132
  }
133
133
  function $35a22f14a1f04b11$export$c5221a78ef73c5e9(placeholderValue) {
134
- if (placeholderValue && "hour" in placeholderValue) return placeholderValue;
134
+ if (placeholderValue && 'hour' in placeholderValue) return placeholderValue;
135
135
  return new (0, $bUJMr$Time)();
136
136
  }
137
137
  function $35a22f14a1f04b11$export$61a490a80c552550(value, calendar) {
@@ -147,16 +147,16 @@ function $35a22f14a1f04b11$export$66aa2b09de4b1ea5(placeholderValue, granularity
147
147
  second: 0,
148
148
  millisecond: 0
149
149
  }), calendar);
150
- if (granularity === "year" || granularity === "month" || granularity === "day") return (0, $bUJMr$toCalendarDate)(date);
150
+ if (granularity === 'year' || granularity === 'month' || granularity === 'day') return (0, $bUJMr$toCalendarDate)(date);
151
151
  if (!timeZone) return (0, $bUJMr$toCalendarDateTime)(date);
152
152
  return date;
153
153
  }
154
154
  function $35a22f14a1f04b11$export$2440da353cedad43(v, granularity) {
155
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";
156
+ let defaultTimeZone = v && 'timeZone' in v ? v.timeZone : undefined;
157
+ let defaultGranularity = v && 'minute' in v ? 'minute' : 'day';
158
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());
159
+ if (v && granularity && !(granularity in v)) throw new Error('Invalid granularity ' + granularity + ' for value ' + v.toString());
160
160
  let [lastValue, setLastValue] = (0, $bUJMr$useState)([
161
161
  defaultGranularity,
162
162
  defaultTimeZone
@@ -1 +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,GAA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9E,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.module.js.map"}
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,AAA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;IAG5B,OAAO;AACT;AAEO,SAAS,0CAAgB,CAAY,EAAE,WAAwB;IACpE,6GAA6G;IAC7G,IAAI,kBAAmB,KAAK,cAAc,IAAI,EAAE,QAAQ,GAAG;IAC3D,IAAI,qBAAmC,KAAK,YAAY,IAAI,WAAW;IAEvE,yEAAyE;IACzE,IAAI,KAAK,eAAe,CAAE,CAAA,eAAe,CAAA,GACvC,MAAM,IAAI,MAAM,yBAAyB,cAAc,gBAAgB,EAAE,QAAQ;IAGnF,IAAI,CAAC,WAAW,aAAa,GAAG,CAAA,GAAA,eAAO,EAAyB;QAAC;QAAoB;KAAgB;IAErG,kEAAkE;IAClE,IAAI,KAAM,CAAA,SAAS,CAAC,EAAE,KAAK,sBAAsB,SAAS,CAAC,EAAE,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'>;\nexport interface 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.mjs.map
11
+ //# sourceMappingURL=zh-CN.module.js.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.mjs.map
11
+ //# sourceMappingURL=zh-TW.module.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/datepicker",
3
- "version": "3.9.3",
3
+ "version": "3.10.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,20 +22,20 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
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",
25
+ "@internationalized/date": "^3.5.5",
26
+ "@internationalized/string": "^3.2.3",
27
+ "@react-stately/form": "^3.0.4",
28
+ "@react-stately/overlays": "^3.6.8",
29
+ "@react-stately/utils": "^3.10.2",
30
+ "@react-types/datepicker": "^3.8.0",
31
+ "@react-types/shared": "^3.24.0",
32
32
  "@swc/helpers": "^0.5.0"
33
33
  },
34
34
  "peerDependencies": {
35
- "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
35
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
36
36
  },
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "f645f29edc1322153fd60af4640cbcab1d992dbd"
40
+ "gitHead": "86d80e3216bc32e75108831cf3a5a720bc849206"
41
41
  }