@react-stately/datepicker 3.10.3 → 3.11.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.
@@ -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,8BAAA,wCAAA,kBAAoB,WAAW;IACrE,IAAI,YAAY,iBAAiB,kBAAkB;IACnD,IAAI,SAAS,EAAE;IAEf,IAAI,WAAW;QACb,IAAI,SAAS;QACb,IAAI,UAAU,CAAA,GAAA,wDAAwB,EAAE,6BAA6B,CAAC,gCAAgC;QACtG,IAAI,YAAY,IAAI,CAAA,GAAA,uDAAuB,EAAE,QAAQ;QACrD,IAAI,gBAAgB,IAAI,CAAA,GAAA,0CAAY,EAAE,QAAQ,0CAAiB,CAAC,GAAG;QACnE,IAAI,WAAW,cAAc,eAAe,GAAG,QAAQ;QAEvD,IAAI,gBACF,OAAO,IAAI,CAAC,UAAU,MAAM,CAAC,kBAAkB;YAAC,UAAU,cAAc,MAAM,CAAC,SAAS,MAAM,CAAC;QAAU;QAG3G,IAAI,eACF,OAAO,IAAI,CAAC,UAAU,MAAM,CAAC,iBAAiB;YAAC,UAA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AgB;IAC1H,IAAI,kBACF,OAAO,0CAAa,kBAAkB;IAGxC,IAAI,OAAO,CAAA,GAAA,uCAAS,EAAE,CAAA,GAAA,gCAAE,EAAE,UAAU,GAAG,CAAC;QACtC,MAAM;QACN,QAAQ;QACR,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"}
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,KAAuB,EACvB,QAAsC,EACtC,QAAsC,EACtC,iBAA0D,EAC1D,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,iBA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AAE,CAAA,eAAe,CAAA,GACvC,MAAM,IAAI,MAAM,yBAAyB,cAAc,gBAAgB,EAAE,QAAQ;IAGnF,IAAI,CAAC,WAAW,aAAa,GAAG,CAAA,GAAA,qBAAO,EAAqC;QAAC;QAAoB;KAAgB;IAEjH,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, getLocalTimeZone, 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 | null,\n minValue: DateValue | null | undefined,\n maxValue: DateValue | null | undefined,\n isDateUnavailable: ((v: DateValue) => boolean) | undefined,\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: string[] = [];\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 && minValue != null) {\n errors.push(formatter.format('rangeUnderflow', {minValue: dateFormatter.format(minValue.toDate(timeZone))}));\n }\n\n if (rangeOverflow && maxValue != null) {\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 | null> | null,\n minValue: DateValue | null | undefined,\n maxValue: DateValue | null | undefined,\n isDateUnavailable: ((v: DateValue) => boolean) | undefined,\n options: FormatterOptions\n) {\n let startValidation = getValidationResult(\n value?.start ?? null,\n minValue,\n maxValue,\n isDateUnavailable,\n options\n );\n\n let endValidation = getValidationResult(\n value?.end ?? null,\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 | null | undefined): TimeValue {\n if (placeholderValue && 'hour' in placeholderValue) {\n return placeholderValue;\n }\n\n return new Time();\n}\n\nexport function convertValue(value: DateValue | null | undefined, calendar: Calendar): DateValue | null | undefined {\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 | null | undefined, granularity: string, calendar: Calendar, timeZone: string | undefined): DateValue {\n if (placeholderValue) {\n return convertValue(placeholderValue, calendar)!;\n }\n\n let date = toCalendar(now(timeZone ?? getLocalTimeZone()).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 | null, granularity: Granularity | undefined): [Granularity, string | undefined] {\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 | undefined]>([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
@@ -1,5 +1,5 @@
1
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";
2
+ import {DateFormatter as $bUJMr$DateFormatter, Time as $bUJMr$Time, toCalendar as $bUJMr$toCalendar, now as $bUJMr$now, getLocalTimeZone as $bUJMr$getLocalTimeZone, toCalendarDate as $bUJMr$toCalendarDate, toCalendarDateTime as $bUJMr$toCalendarDateTime} from "@internationalized/date";
3
3
  import {LocalizedStringDictionary as $bUJMr$LocalizedStringDictionary, LocalizedStringFormatter as $bUJMr$LocalizedStringFormatter} from "@internationalized/string";
4
4
  import {mergeValidation as $bUJMr$mergeValidation, VALID_VALIDITY_STATE as $bUJMr$VALID_VALIDITY_STATE} from "@react-stately/form";
5
5
  import {useState as $bUJMr$useState} from "react";
@@ -42,10 +42,10 @@ function $35a22f14a1f04b11$export$f18627323ab57ac0(value, minValue, maxValue, is
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 && minValue != null) 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 && maxValue != null) errors.push(formatter.format('rangeOverflow', {
49
49
  maxValue: dateFormatter.format(maxValue.toDate(timeZone))
50
50
  }));
51
51
  if (isUnavailable) errors.push(formatter.format('unavailableDate'));
@@ -69,10 +69,12 @@ function $35a22f14a1f04b11$export$f18627323ab57ac0(value, minValue, maxValue, is
69
69
  };
70
70
  }
71
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);
72
+ var _value_start;
73
+ let startValidation = $35a22f14a1f04b11$export$f18627323ab57ac0((_value_start = value === null || value === void 0 ? void 0 : value.start) !== null && _value_start !== void 0 ? _value_start : null, minValue, maxValue, isDateUnavailable, options);
74
+ var _value_end;
75
+ let endValidation = $35a22f14a1f04b11$export$f18627323ab57ac0((_value_end = value === null || value === void 0 ? void 0 : value.end) !== null && _value_end !== void 0 ? _value_end : null, minValue, maxValue, isDateUnavailable, options);
74
76
  let result = (0, $bUJMr$mergeValidation)(startValidation, endValidation);
75
- if (value.end != null && value.start != null && value.end.compare(value.start) < 0) {
77
+ if ((value === null || value === void 0 ? void 0 : value.end) != null && value.start != null && value.end.compare(value.start) < 0) {
76
78
  let strings = (0, $bUJMr$LocalizedStringDictionary).getGlobalDictionaryForPackage('@react-stately/datepicker') || $35a22f14a1f04b11$var$dictionary;
77
79
  result = (0, $bUJMr$mergeValidation)(result, {
78
80
  isInvalid: true,
@@ -141,7 +143,7 @@ function $35a22f14a1f04b11$export$61a490a80c552550(value, calendar) {
141
143
  }
142
144
  function $35a22f14a1f04b11$export$66aa2b09de4b1ea5(placeholderValue, granularity, calendar, timeZone) {
143
145
  if (placeholderValue) return $35a22f14a1f04b11$export$61a490a80c552550(placeholderValue, calendar);
144
- let date = (0, $bUJMr$toCalendar)((0, $bUJMr$now)(timeZone).set({
146
+ let date = (0, $bUJMr$toCalendar)((0, $bUJMr$now)(timeZone !== null && timeZone !== void 0 ? timeZone : (0, $bUJMr$getLocalTimeZone)()).set({
145
147
  hour: 0,
146
148
  minute: 0,
147
149
  second: 0,
@@ -1,5 +1,5 @@
1
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";
2
+ import {DateFormatter as $bUJMr$DateFormatter, Time as $bUJMr$Time, toCalendar as $bUJMr$toCalendar, now as $bUJMr$now, getLocalTimeZone as $bUJMr$getLocalTimeZone, toCalendarDate as $bUJMr$toCalendarDate, toCalendarDateTime as $bUJMr$toCalendarDateTime} from "@internationalized/date";
3
3
  import {LocalizedStringDictionary as $bUJMr$LocalizedStringDictionary, LocalizedStringFormatter as $bUJMr$LocalizedStringFormatter} from "@internationalized/string";
4
4
  import {mergeValidation as $bUJMr$mergeValidation, VALID_VALIDITY_STATE as $bUJMr$VALID_VALIDITY_STATE} from "@react-stately/form";
5
5
  import {useState as $bUJMr$useState} from "react";
@@ -42,10 +42,10 @@ function $35a22f14a1f04b11$export$f18627323ab57ac0(value, minValue, maxValue, is
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 && minValue != null) 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 && maxValue != null) errors.push(formatter.format('rangeOverflow', {
49
49
  maxValue: dateFormatter.format(maxValue.toDate(timeZone))
50
50
  }));
51
51
  if (isUnavailable) errors.push(formatter.format('unavailableDate'));
@@ -69,10 +69,12 @@ function $35a22f14a1f04b11$export$f18627323ab57ac0(value, minValue, maxValue, is
69
69
  };
70
70
  }
71
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);
72
+ var _value_start;
73
+ let startValidation = $35a22f14a1f04b11$export$f18627323ab57ac0((_value_start = value === null || value === void 0 ? void 0 : value.start) !== null && _value_start !== void 0 ? _value_start : null, minValue, maxValue, isDateUnavailable, options);
74
+ var _value_end;
75
+ let endValidation = $35a22f14a1f04b11$export$f18627323ab57ac0((_value_end = value === null || value === void 0 ? void 0 : value.end) !== null && _value_end !== void 0 ? _value_end : null, minValue, maxValue, isDateUnavailable, options);
74
76
  let result = (0, $bUJMr$mergeValidation)(startValidation, endValidation);
75
- if (value.end != null && value.start != null && value.end.compare(value.start) < 0) {
77
+ if ((value === null || value === void 0 ? void 0 : value.end) != null && value.start != null && value.end.compare(value.start) < 0) {
76
78
  let strings = (0, $bUJMr$LocalizedStringDictionary).getGlobalDictionaryForPackage('@react-stately/datepicker') || $35a22f14a1f04b11$var$dictionary;
77
79
  result = (0, $bUJMr$mergeValidation)(result, {
78
80
  isInvalid: true,
@@ -141,7 +143,7 @@ function $35a22f14a1f04b11$export$61a490a80c552550(value, calendar) {
141
143
  }
142
144
  function $35a22f14a1f04b11$export$66aa2b09de4b1ea5(placeholderValue, granularity, calendar, timeZone) {
143
145
  if (placeholderValue) return $35a22f14a1f04b11$export$61a490a80c552550(placeholderValue, calendar);
144
- let date = (0, $bUJMr$toCalendar)((0, $bUJMr$now)(timeZone).set({
146
+ let date = (0, $bUJMr$toCalendar)((0, $bUJMr$now)(timeZone !== null && timeZone !== void 0 ? timeZone : (0, $bUJMr$getLocalTimeZone)()).set({
145
147
  hour: 0,
146
148
  minute: 0,
147
149
  second: 0,
@@ -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,GAAA,gCAAwB,EAAE,6BAA6B,CAAC,gCAAgC;QACtG,IAAI,YAAY,IAAI,CAAA,GAAA,+BAAuB,EAAE,QAAQ;QACrD,IAAI,gBAAgB,IAAI,CAAA,GAAA,oBAAY,EAAE,QAAQ,0CAAiB,CAAC,GAAG;QACnE,IAAI,W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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"}
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,KAAuB,EACvB,QAAsC,EACtC,QAAsC,EACtC,iBAA0D,EAC1D,OAAyB;IAEzB,IAAI,gBAAgB,SAAS,QAA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AEO,SAAS,0CAAgB,CAAmB,EAAE,WAAoC;IACvF,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,EAAqC;QAAC;QAAoB;KAAgB;IAEjH,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, getLocalTimeZone, 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 | null,\n minValue: DateValue | null | undefined,\n maxValue: DateValue | null | undefined,\n isDateUnavailable: ((v: DateValue) => boolean) | undefined,\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: string[] = [];\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 && minValue != null) {\n errors.push(formatter.format('rangeUnderflow', {minValue: dateFormatter.format(minValue.toDate(timeZone))}));\n }\n\n if (rangeOverflow && maxValue != null) {\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 | null> | null,\n minValue: DateValue | null | undefined,\n maxValue: DateValue | null | undefined,\n isDateUnavailable: ((v: DateValue) => boolean) | undefined,\n options: FormatterOptions\n) {\n let startValidation = getValidationResult(\n value?.start ?? null,\n minValue,\n maxValue,\n isDateUnavailable,\n options\n );\n\n let endValidation = getValidationResult(\n value?.end ?? null,\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 | null | undefined): TimeValue {\n if (placeholderValue && 'hour' in placeholderValue) {\n return placeholderValue;\n }\n\n return new Time();\n}\n\nexport function convertValue(value: DateValue | null | undefined, calendar: Calendar): DateValue | null | undefined {\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 | null | undefined, granularity: string, calendar: Calendar, timeZone: string | undefined): DateValue {\n if (placeholderValue) {\n return convertValue(placeholderValue, calendar)!;\n }\n\n let date = toCalendar(now(timeZone ?? getLocalTimeZone()).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 | null, granularity: Granularity | undefined): [Granularity, string | undefined] {\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 | undefined]>([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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/datepicker",
3
- "version": "3.10.3",
3
+ "version": "3.11.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,19 +22,20 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@internationalized/date": "^3.5.6",
26
- "@internationalized/string": "^3.2.4",
27
- "@react-stately/form": "^3.0.6",
28
- "@react-stately/overlays": "^3.6.11",
29
- "@react-stately/utils": "^3.10.4",
30
- "@react-types/datepicker": "^3.8.3",
31
- "@react-types/shared": "^3.25.0",
25
+ "@internationalized/date": "^3.6.0",
26
+ "@internationalized/string": "^3.2.5",
27
+ "@react-stately/form": "^3.1.0",
28
+ "@react-stately/overlays": "^3.6.12",
29
+ "@react-stately/utils": "^3.10.5",
30
+ "@react-types/datepicker": "^3.9.0",
31
+ "@react-types/shared": "^3.26.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 || ^19.0.0"
35
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
36
36
  },
37
37
  "publishConfig": {
38
38
  "access": "public"
39
- }
40
- }
39
+ },
40
+ "gitHead": "71f0ef23053f9e03ee7e97df736e8b083e006849"
41
+ }
@@ -12,7 +12,7 @@
12
12
 
13
13
  import {Calendar, DateFormatter, getMinimumDayInMonth, getMinimumMonthInYear, GregorianCalendar, toCalendar} from '@internationalized/date';
14
14
  import {convertValue, createPlaceholderDate, FieldOptions, FormatterOptions, getFormatOptions, getValidationResult, useDefaultProps} from './utils';
15
- import {DatePickerProps, DateValue, Granularity} from '@react-types/datepicker';
15
+ import {DatePickerProps, DateValue, Granularity, MappedDateValue} from '@react-types/datepicker';
16
16
  import {FormValidationState, useFormValidationState} from '@react-stately/form';
17
17
  import {getPlaceholder} from './placeholders';
18
18
  import {useControlledState} from '@react-stately/utils';
@@ -41,13 +41,13 @@ export interface DateSegment {
41
41
 
42
42
  export interface DateFieldState extends FormValidationState {
43
43
  /** The current field value. */
44
- value: DateValue,
44
+ value: DateValue | null,
45
45
  /** The current value, converted to a native JavaScript `Date` object. */
46
46
  dateValue: Date,
47
47
  /** The calendar system currently in use. */
48
48
  calendar: Calendar,
49
49
  /** Sets the field's value. */
50
- setValue(value: DateValue): void,
50
+ setValue(value: DateValue | null): void,
51
51
  /** A list of segments for the current value. */
52
52
  segments: DateSegment[],
53
53
  /** A date formatter configured for the current locale and format. */
@@ -56,7 +56,7 @@ export interface DateFieldState extends FormValidationState {
56
56
  * The current validation state of the date field, based on the `validationState`, `minValue`, and `maxValue` props.
57
57
  * @deprecated Use `isInvalid` instead.
58
58
  */
59
- validationState: ValidationState,
59
+ validationState: ValidationState | null,
60
60
  /** Whether the date field is invalid, based on the `isInvalid`, `minValue`, and `maxValue` props. */
61
61
  isInvalid: boolean,
62
62
  /** The granularity for the field, based on the `granularity` prop and current value. */
@@ -150,15 +150,15 @@ export function useDateFieldState<T extends DateValue = DateValue>(props: DateFi
150
150
  locale,
151
151
  createCalendar,
152
152
  hideTimeZone,
153
- isDisabled,
154
- isReadOnly,
155
- isRequired,
153
+ isDisabled = false,
154
+ isReadOnly = false,
155
+ isRequired = false,
156
156
  minValue,
157
157
  maxValue,
158
158
  isDateUnavailable
159
159
  } = props;
160
160
 
161
- let v: DateValue = (props.value || props.defaultValue || props.placeholderValue);
161
+ let v: DateValue | null = props.value || props.defaultValue || props.placeholderValue || null;
162
162
  let [granularity, defaultTimeZone] = useDefaultProps(v, props.granularity);
163
163
  let timeZone = defaultTimeZone || 'UTC';
164
164
 
@@ -170,13 +170,13 @@ export function useDateFieldState<T extends DateValue = DateValue>(props: DateFi
170
170
  let defaultFormatter = useMemo(() => new DateFormatter(locale), [locale]);
171
171
  let calendar = useMemo(() => createCalendar(defaultFormatter.resolvedOptions().calendar), [createCalendar, defaultFormatter]);
172
172
 
173
- let [value, setDate] = useControlledState<DateValue>(
173
+ let [value, setDate] = useControlledState<DateValue | null, MappedDateValue<T> | null>(
174
174
  props.value,
175
- props.defaultValue,
175
+ props.defaultValue ?? null,
176
176
  props.onChange
177
177
  );
178
178
 
179
- let calendarValue = useMemo(() => convertValue(value, calendar), [value, calendar]);
179
+ let calendarValue = useMemo(() => convertValue(value, calendar) ?? null, [value, calendar]);
180
180
 
181
181
  // We keep track of the placeholder date separately in state so that onChange is not called
182
182
  // until all segments are set. If the value === null (not undefined), then assume the component
@@ -214,7 +214,7 @@ export function useDateFieldState<T extends DateValue = DateValue>(props: DateFi
214
214
  () => props.value || props.defaultValue ? {...allSegments} : {}
215
215
  );
216
216
 
217
- let clearedSegment = useRef<string>(undefined);
217
+ let clearedSegment = useRef<string | null>(null);
218
218
 
219
219
  // Reset placeholder when calendar changes
220
220
  let lastCalendarIdentifier = useRef(calendar.identifier);
@@ -330,12 +330,12 @@ export function useDateFieldState<T extends DateValue = DateValue>(props: DateFi
330
330
 
331
331
  let validation = useFormValidationState({
332
332
  ...props,
333
- value,
333
+ value: value as MappedDateValue<T> | null,
334
334
  builtinValidation
335
335
  });
336
336
 
337
337
  let isValueInvalid = validation.displayValidation.isInvalid;
338
- let validationState: ValidationState = props.validationState || (isValueInvalid ? 'invalid' : null);
338
+ let validationState: ValidationState | null = props.validationState || (isValueInvalid ? 'invalid' : null);
339
339
 
340
340
  return {
341
341
  ...validation,
@@ -364,7 +364,7 @@ export function useDateFieldState<T extends DateValue = DateValue>(props: DateFi
364
364
  decrementPage(part) {
365
365
  adjustSegment(part, -(PAGE_STEP[part] || 1));
366
366
  },
367
- setSegment(part, v) {
367
+ setSegment(part, v: string | number) {
368
368
  markValid(part);
369
369
  setValue(setSegment(displayValue, part, v, resolvedOptions));
370
370
  },
@@ -519,9 +519,11 @@ function addSegment(value: DateValue, part: string, amount: number, options: Int
519
519
  });
520
520
  }
521
521
  }
522
+
523
+ throw new Error('Unknown segment: ' + part);
522
524
  }
523
525
 
524
- function setSegment(value: DateValue, part: string, segmentValue: number, options: Intl.ResolvedDateTimeFormatOptions) {
526
+ function setSegment(value: DateValue, part: string, segmentValue: number | string, options: Intl.ResolvedDateTimeFormatOptions) {
525
527
  switch (part) {
526
528
  case 'day':
527
529
  case 'month':
@@ -530,7 +532,7 @@ function setSegment(value: DateValue, part: string, segmentValue: number, option
530
532
  return value.set({[part]: segmentValue});
531
533
  }
532
534
 
533
- if ('hour' in value) {
535
+ if ('hour' in value && typeof segmentValue === 'number') {
534
536
  switch (part) {
535
537
  case 'dayPeriod': {
536
538
  let hours = value.hour;
@@ -559,4 +561,6 @@ function setSegment(value: DateValue, part: string, segmentValue: number, option
559
561
  return value.set({[part]: segmentValue});
560
562
  }
561
563
  }
564
+
565
+ throw new Error('Unknown segment: ' + part);
562
566
  }
@@ -11,7 +11,7 @@
11
11
  */
12
12
 
13
13
  import {CalendarDate, DateFormatter, toCalendarDate, toCalendarDateTime} from '@internationalized/date';
14
- import {DatePickerProps, DateValue, Granularity, TimeValue} from '@react-types/datepicker';
14
+ import {DatePickerProps, DateValue, Granularity, MappedDateValue, TimeValue} from '@react-types/datepicker';
15
15
  import {FieldOptions, FormatterOptions, getFormatOptions, getPlaceholderTime, getValidationResult, useDefaultProps} from './utils';
16
16
  import {FormValidationState, useFormValidationState} from '@react-stately/form';
17
17
  import {OverlayTriggerState, useOverlayTriggerState} from '@react-stately/overlays';
@@ -36,14 +36,14 @@ export interface DatePickerState extends OverlayTriggerState, FormValidationStat
36
36
  * The date portion of the value. This may be set prior to `value` if the user has
37
37
  * selected a date but has not yet selected a time.
38
38
  */
39
- dateValue: DateValue,
39
+ dateValue: DateValue | null,
40
40
  /** Sets the date portion of the value. */
41
- setDateValue(value: CalendarDate): void,
41
+ setDateValue(value: DateValue): void,
42
42
  /**
43
43
  * The time portion of the value. This may be set prior to `value` if the user has
44
44
  * selected a time but has not yet selected a date.
45
45
  */
46
- timeValue: TimeValue,
46
+ timeValue: TimeValue | null,
47
47
  /** Sets the time portion of the value. */
48
48
  setTimeValue(value: TimeValue): void,
49
49
  /** The granularity for the field, based on the `granularity` prop and current value. */
@@ -58,7 +58,7 @@ export interface DatePickerState extends OverlayTriggerState, FormValidationStat
58
58
  * The current validation state of the date picker, based on the `validationState`, `minValue`, and `maxValue` props.
59
59
  * @deprecated Use `isInvalid` instead.
60
60
  */
61
- validationState: ValidationState,
61
+ validationState: ValidationState | null,
62
62
  /** Whether the date picker is invalid, based on the `isInvalid`, `minValue`, and `maxValue` props. */
63
63
  isInvalid: boolean,
64
64
  /** Formats the selected value using the given options. */
@@ -73,16 +73,16 @@ export interface DatePickerState extends OverlayTriggerState, FormValidationStat
73
73
  */
74
74
  export function useDatePickerState<T extends DateValue = DateValue>(props: DatePickerStateOptions<T>): DatePickerState {
75
75
  let overlayState = useOverlayTriggerState(props);
76
- let [value, setValue] = useControlledState<DateValue>(props.value, props.defaultValue || null, props.onChange);
76
+ let [value, setValue] = useControlledState<DateValue | null, MappedDateValue<T> | null>(props.value, props.defaultValue || null, props.onChange);
77
77
 
78
- let v = (value || props.placeholderValue);
78
+ let v = (value || props.placeholderValue || null);
79
79
  let [granularity, defaultTimeZone] = useDefaultProps(v, props.granularity);
80
80
  let dateValue = value != null ? value.toDate(defaultTimeZone ?? 'UTC') : null;
81
81
  let hasTime = granularity === 'hour' || granularity === 'minute' || granularity === 'second';
82
82
  let shouldCloseOnSelect = props.shouldCloseOnSelect ?? true;
83
83
 
84
- let [selectedDate, setSelectedDate] = useState<DateValue>(null);
85
- let [selectedTime, setSelectedTime] = useState<TimeValue>(null);
84
+ let [selectedDate, setSelectedDate] = useState<DateValue | null>(null);
85
+ let [selectedTime, setSelectedTime] = useState<TimeValue | null>(null);
86
86
 
87
87
  if (value) {
88
88
  selectedDate = value;
@@ -117,12 +117,12 @@ export function useDatePickerState<T extends DateValue = DateValue>(props: DateP
117
117
 
118
118
  let validation = useFormValidationState({
119
119
  ...props,
120
- value,
120
+ value: value as MappedDateValue<T> | null,
121
121
  builtinValidation
122
122
  });
123
123
 
124
124
  let isValueInvalid = validation.displayValidation.isInvalid;
125
- let validationState: ValidationState = props.validationState || (isValueInvalid ? 'invalid' : null);
125
+ let validationState: ValidationState | null = props.validationState || (isValueInvalid ? 'invalid' : null);
126
126
 
127
127
  let commitValue = (date: DateValue, time: TimeValue) => {
128
128
  setValue('timeZone' in time ? time.set(toCalendarDate(date)) : toCalendarDateTime(date, time));
@@ -136,7 +136,7 @@ export function useDatePickerState<T extends DateValue = DateValue>(props: DateP
136
136
  let shouldClose = typeof shouldCloseOnSelect === 'function' ? shouldCloseOnSelect() : shouldCloseOnSelect;
137
137
  if (hasTime) {
138
138
  if (selectedTime || shouldClose) {
139
- commitValue(newValue, selectedTime || getPlaceholderTime(props.placeholderValue));
139
+ commitValue(newValue, selectedTime || getPlaceholderTime(props.defaultValue || props.placeholderValue));
140
140
  } else {
141
141
  setSelectedDate(newValue);
142
142
  }
@@ -174,7 +174,7 @@ export function useDatePickerState<T extends DateValue = DateValue>(props: DateP
174
174
  // If only the time was set and not the date, don't commit. The state will be preserved until
175
175
  // the user opens the popover again.
176
176
  if (!isOpen && !value && selectedDate && hasTime) {
177
- commitValue(selectedDate, selectedTime || getPlaceholderTime(props.placeholderValue));
177
+ commitValue(selectedDate, selectedTime || getPlaceholderTime(props.defaultValue || props.placeholderValue));
178
178
  }
179
179
 
180
180
  overlayState.setOpen(isOpen);