react-stately 3.49.0 → 3.50.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","sources":["packages/react-stately/exports/useTokenFieldState.ts"],"sourcesContent":["/*\n * Copyright 2026 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\nexport {useTokenFieldState} from '../src/tokenfield/useTokenFieldState';\nexport {TokenFieldValue} from '../src/tokenfield/TokenFieldValue';\n\nexport type {TokenFieldProps, TokenFieldState} from '../src/tokenfield/useTokenFieldState';\nexport type {\n TokenFieldSegment,\n TokenSegment,\n TextSegment,\n Position,\n TokenFieldValueOptions\n} from '../src/tokenfield/TokenFieldValue';\n"],"names":[],"version":3,"file":"useTokenFieldState.cjs.map"}
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/react-stately/exports/useTokenFieldState.ts"],"sourcesContent":["/*\n * Copyright 2026 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\nexport {useTokenFieldState} from '../src/tokenfield/useTokenFieldState';\nexport {TokenFieldValue} from '../src/tokenfield/TokenFieldValue';\n\nexport type {TokenFieldProps, TokenFieldState} from '../src/tokenfield/useTokenFieldState';\nexport type {\n TokenFieldSegment,\n TokenSegment,\n TextSegment,\n Position,\n SelectedRange,\n TokenFieldValueOptions\n} from '../src/tokenfield/TokenFieldValue';\n"],"names":[],"version":3,"file":"useTokenFieldState.cjs.map"}
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/react-stately/exports/useTokenFieldState.ts"],"sourcesContent":["/*\n * Copyright 2026 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\nexport {useTokenFieldState} from '../src/tokenfield/useTokenFieldState';\nexport {TokenFieldValue} from '../src/tokenfield/TokenFieldValue';\n\nexport type {TokenFieldProps, TokenFieldState} from '../src/tokenfield/useTokenFieldState';\nexport type {\n TokenFieldSegment,\n TokenSegment,\n TextSegment,\n Position,\n TokenFieldValueOptions\n} from '../src/tokenfield/TokenFieldValue';\n"],"names":[],"version":3,"file":"useTokenFieldState.js.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/react-stately/exports/useTokenFieldState.ts"],"sourcesContent":["/*\n * Copyright 2026 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\nexport {useTokenFieldState} from '../src/tokenfield/useTokenFieldState';\nexport {TokenFieldValue} from '../src/tokenfield/TokenFieldValue';\n\nexport type {TokenFieldProps, TokenFieldState} from '../src/tokenfield/useTokenFieldState';\nexport type {\n TokenFieldSegment,\n TokenSegment,\n TextSegment,\n Position,\n SelectedRange,\n TokenFieldValueOptions\n} from '../src/tokenfield/TokenFieldValue';\n"],"names":[],"version":3,"file":"useTokenFieldState.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/react-stately/exports/useTokenFieldState.ts"],"sourcesContent":["/*\n * Copyright 2026 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\nexport {useTokenFieldState} from '../src/tokenfield/useTokenFieldState';\nexport {TokenFieldValue} from '../src/tokenfield/TokenFieldValue';\n\nexport type {TokenFieldProps, TokenFieldState} from '../src/tokenfield/useTokenFieldState';\nexport type {\n TokenFieldSegment,\n TokenSegment,\n TextSegment,\n Position,\n TokenFieldValueOptions\n} from '../src/tokenfield/TokenFieldValue';\n"],"names":[],"version":3,"file":"useTokenFieldState.mjs.map"}
1
+ {"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/react-stately/exports/useTokenFieldState.ts"],"sourcesContent":["/*\n * Copyright 2026 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\nexport {useTokenFieldState} from '../src/tokenfield/useTokenFieldState';\nexport {TokenFieldValue} from '../src/tokenfield/TokenFieldValue';\n\nexport type {TokenFieldProps, TokenFieldState} from '../src/tokenfield/useTokenFieldState';\nexport type {\n TokenFieldSegment,\n TokenSegment,\n TextSegment,\n Position,\n SelectedRange,\n TokenFieldValueOptions\n} from '../src/tokenfield/TokenFieldValue';\n"],"names":[],"version":3,"file":"useTokenFieldState.mjs.map"}
@@ -119,7 +119,8 @@ function $e247a673010dfa8e$export$6d095e787d2b5e1f(props) {
119
119
  }
120
120
  function normalizeValue(newValue) {
121
121
  let constrained = (0, $8b8d004404afcaba$exports.constrainValue)(newValue, minValue, maxValue);
122
- let prev = (0, $8b8d004404afcaba$exports.previousAvailableDate)(constrained, startDate, isDateUnavailable);
122
+ let lowerBound = minValue ?? (0, $9I0if$internationalizeddate.minDate)(constrained, startDate);
123
+ let prev = (0, $8b8d004404afcaba$exports.previousAvailableDate)(constrained, lowerBound, isDateUnavailable);
123
124
  if (!prev) return null;
124
125
  // The display calendar should not have any effect on the emitted value.
125
126
  // Emit dates in the same calendar as the original value, if any, otherwise gregorian.
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AA2FM,SAAS,0CAGd,KAAiC;IACjC,IAAI,mBAAmB,CAAA,GAAA,oBAAM,EAAE,IAAM,IAAI,CAAA,GAAA,0CAAY,EAAE,MAAM,MAAM,GAAG;QAAC,MAAM,MAAM;KAAC;IACpF,IAAI,kBAAkB,CAAA,GAAA,oBAAM,EAAE,IAAM,iBAAiB,eAAe,IAAI;QAAC;KAAiB;IAC1F,IAAI,UACF,MAAM,kBACN,cAAc,mBACd,kBAAkB;QAAC,QAAQ;IAAC,aAC5B,QAAQ,YACR,QAAQ,sBACR,kBAAkB,qBAClB,iBAAiB,gBACjB,eAAe,0BACf,gBAAgB,0BAChB,cAAc,gBACd,YAAY,EAC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AI,WAAW,IAC7B,MAAM,IAAI,CAAC;YAEf;YAEA,MAAO,MAAM,MAAM,GAAG,KAAM;gBAC1B,MAAM,IAAI,CAAC;gBACX,IAAI,WAAW,KAAK,GAAG,CAAC;oBAAC,MAAM;gBAAC;gBAChC,IAAI,CAAA,GAAA,sCAAQ,EAAE,MAAM,WAElB;gBAEF,OAAO;YACT;YAEA,8DAA8D;YAC9D,MAAO,MAAM,MAAM,GAAG,KACpB,MAAM,IAAI,CAAC;YAGb,OAAO;QACT;QACA,iBAAgB,OAAO,SAAS;YAC9B,IAAI,QAAQ,gBAAgB,CAAA,GAAA,4CAAc,EAAE,MAAM,QAAQ;YAC1D,IAAI,gBAAgB,KAAK,IAAI,gBAAgB,IAAI,EAAE;gBACjD,QAAQ,gBAAgB,KAAK,IAAI;gBACjC,IAAI,gBAAgB,IAAI,EACtB,SAAS,KAAK,IAAI,CAAC,gBAAgB,IAAI,GAAG;YAE9C;YACA,OAAO;QACT;IACF;AACF;AAEA,SAAS,mCAAa,QAAsB;IAC1C,IAAI,OAAO;QAAC,GAAG,QAAQ;IAAA;IACvB,IAAK,IAAI,OAAO,SACd,IAAI,CAAC,IAAI,GAAG;IAEd,OAAO;AACT","sources":["packages/react-stately/src/calendar/useCalendarState.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 {\n alignCenter,\n alignEnd,\n alignStart,\n constrainStart,\n constrainValue,\n isEqualDuration,\n isInvalid,\n previousAvailableDate\n} from './utils';\nimport {\n Calendar,\n CalendarDate,\n CalendarIdentifier,\n DateDuration,\n DateFormatter,\n endOfMonth,\n endOfWeek,\n getDayOfWeek,\n getWeeksInMonth,\n GregorianCalendar,\n isEqualCalendar,\n isSameDay,\n startOfMonth,\n startOfWeek,\n toCalendar,\n toCalendarDate,\n today\n} from '@internationalized/date';\nimport {\n CalendarPropsBase,\n CalendarSelectionMode,\n CalendarState,\n CalendarValueType,\n DateValue,\n MappedDateValue\n} from './types';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useState} from 'react';\nimport {ValidationState, ValueBase} from '@react-types/shared';\n\nexport interface CalendarProps<T extends DateValue, M extends CalendarSelectionMode = 'single'>\n extends\n CalendarPropsBase,\n ValueBase<CalendarValueType<T | null, M>, CalendarValueType<MappedDateValue<T>, M>> {\n /**\n * Whether single or multiple selection is enabled.\n *\n * @default 'single'\n */\n selectionMode?: M;\n /**\n * Callback that is called for each date of the calendar. If it returns true, then the date is\n * unavailable.\n */\n isDateUnavailable?: (date: DateValue) => boolean;\n}\n\nexport interface CalendarStateOptions<\n T extends DateValue = DateValue,\n M extends CalendarSelectionMode = 'single'\n> extends CalendarProps<T, M> {\n /** The locale to display and edit the value according to. */\n locale: string;\n /**\n * A function that creates a [Calendar](../internationalized/date/Calendar.html)\n * object for a given calendar identifier. Such a function may be imported from the\n * `@internationalized/date` package, or manually implemented to include support for\n * only certain calendars.\n */\n createCalendar: (name: CalendarIdentifier) => Calendar;\n /**\n * The amount of days that will be displayed at once. This affects how pagination works.\n *\n * @default { months: 1 }\n */\n visibleDuration?: DateDuration;\n /**\n * Determines the alignment of the visible months on initial render based on the current selection\n * or current date if there is no selection.\n *\n * @default 'center'\n */\n selectionAlignment?: 'start' | 'center' | 'end';\n}\n/**\n * Provides state management for a calendar component.\n * A calendar displays one or more date grids and allows users to select a single date.\n */\nexport function useCalendarState<\n T extends DateValue = DateValue,\n M extends CalendarSelectionMode = 'single'\n>(props: CalendarStateOptions<T, M>): CalendarState<M> {\n let defaultFormatter = useMemo(() => new DateFormatter(props.locale), [props.locale]);\n let resolvedOptions = useMemo(() => defaultFormatter.resolvedOptions(), [defaultFormatter]);\n let {\n locale,\n createCalendar,\n visibleDuration = {months: 1},\n minValue,\n maxValue,\n selectionAlignment,\n isDateUnavailable,\n pageBehavior = 'visible',\n selectionMode = 'single' as M,\n firstDayOfWeek,\n weeksInMonth\n } = props;\n let calendar = useMemo(\n () => createCalendar(resolvedOptions.calendar as CalendarIdentifier),\n [createCalendar, resolvedOptions.calendar]\n );\n\n let [value, setControlledValue] = useControlledState<\n T | T[] | null,\n MappedDateValue<T> | MappedDateValue<T>[] | null\n >(props.value as any, (props.defaultValue as any) ?? null, props.onChange as any);\n let calendarDateValue = useMemo(() => {\n if (Array.isArray(value)) {\n return value.map(value => toCalendar(toCalendarDate(value), calendar));\n } else {\n return value ? toCalendar(toCalendarDate(value), calendar) : null;\n }\n }, [value, calendar]);\n let timeZone = useMemo(() => {\n let val = Array.isArray(value) ? value[0] : value;\n return val && 'timeZone' in val ? val.timeZone : resolvedOptions.timeZone;\n }, [value, resolvedOptions.timeZone]);\n let focusedCalendarDate = useMemo(\n () =>\n props.focusedValue\n ? constrainValue(\n toCalendar(toCalendarDate(props.focusedValue), calendar),\n minValue,\n maxValue\n )\n : undefined,\n [props.focusedValue, calendar, minValue, maxValue]\n );\n let defaultFocusedCalendarDate = useMemo(() => {\n if (props.defaultFocusedValue) {\n return constrainValue(\n toCalendar(toCalendarDate(props.defaultFocusedValue), calendar),\n minValue,\n maxValue\n );\n }\n\n if (calendarDateValue) {\n return constrainValue(\n Array.isArray(calendarDateValue) ? calendarDateValue[0] : calendarDateValue,\n minValue,\n maxValue\n );\n }\n\n return constrainValue(toCalendar(today(timeZone), calendar), minValue, maxValue);\n }, [props.defaultFocusedValue, calendarDateValue, timeZone, calendar, minValue, maxValue]);\n let [focusedDate, setFocusedDate] = useControlledState(\n focusedCalendarDate,\n defaultFocusedCalendarDate,\n props.onFocusChange\n );\n let getStartDate = () => {\n switch (selectionAlignment) {\n case 'start':\n return alignStart(focusedDate, visibleDuration, locale, minValue, maxValue);\n case 'end':\n return alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue);\n case 'center':\n default:\n return alignCenter(focusedDate, visibleDuration, locale, minValue, maxValue);\n }\n };\n\n let [startDate, setStartDate] = useState(getStartDate);\n let [isFocused, setFocused] = useState(props.autoFocus || false);\n\n let [lastVisibleDuration, setLastVisibleDuration] = useState(visibleDuration);\n if (!isEqualDuration(visibleDuration, lastVisibleDuration)) {\n setLastVisibleDuration(visibleDuration);\n setStartDate(getStartDate());\n }\n\n let endDate = useMemo(() => {\n let duration = {...visibleDuration};\n if (duration.days) {\n duration.days--;\n } else {\n duration.days = -1;\n }\n return startDate.add(duration);\n }, [startDate, visibleDuration]);\n\n // Reset focused date and visible range when calendar changes.\n let [lastCalendar, setLastCalendar] = useState(calendar);\n if (!isEqualCalendar(calendar, lastCalendar)) {\n let newFocusedDate = toCalendar(focusedDate, calendar);\n setStartDate(alignCenter(newFocusedDate, visibleDuration, locale, minValue, maxValue));\n setFocusedDate(newFocusedDate);\n setLastCalendar(calendar);\n }\n\n if (isInvalid(focusedDate, minValue, maxValue)) {\n // If the focused date was moved to an invalid value, it can't be focused, so constrain it.\n setFocusedDate(constrainValue(focusedDate, minValue, maxValue));\n } else if (focusedDate.compare(startDate) < 0) {\n setStartDate(alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue));\n } else if (focusedDate.compare(endDate) > 0) {\n setStartDate(alignStart(focusedDate, visibleDuration, locale, minValue, maxValue));\n }\n\n // Sets focus to a specific cell date\n function focusCell(date: CalendarDate) {\n date = constrainValue(date, minValue, maxValue);\n setFocusedDate(date);\n }\n\n function normalizeValue(newValue: CalendarDate) {\n let constrained = constrainValue(newValue, minValue, maxValue);\n let prev = previousAvailableDate(constrained, startDate, isDateUnavailable);\n if (!prev) {\n return null;\n }\n\n // The display calendar should not have any effect on the emitted value.\n // Emit dates in the same calendar as the original value, if any, otherwise gregorian.\n let baseValue = Array.isArray(value) ? value[0] : value;\n let calendarValue = toCalendar(prev, baseValue?.calendar || new GregorianCalendar());\n\n // Preserve time if the input value had one.\n if (baseValue && 'hour' in baseValue) {\n return baseValue.set(calendarValue) as T;\n }\n\n return calendarValue as T;\n }\n\n function setValue(newValue: CalendarDate | CalendarDate[] | null) {\n if (!props.isDisabled && !props.isReadOnly) {\n if (newValue === null) {\n setControlledValue(selectionMode === 'multiple' ? [] : null);\n return;\n }\n\n if (Array.isArray(newValue)) {\n setControlledValue(newValue.map(normalizeValue).filter(Boolean) as any);\n } else {\n let localValue = normalizeValue(newValue);\n if (localValue) {\n setControlledValue(localValue as any);\n }\n }\n }\n }\n\n let isUnavailable = useMemo(() => {\n if (!calendarDateValue) {\n return false;\n }\n\n if (Array.isArray(calendarDateValue)) {\n return calendarDateValue.some(\n date => isDateUnavailable?.(date) || isInvalid(date, minValue, maxValue)\n );\n }\n\n return (\n isDateUnavailable?.(calendarDateValue) || isInvalid(calendarDateValue, minValue, maxValue)\n );\n }, [calendarDateValue, isDateUnavailable, minValue, maxValue]);\n let isValueInvalid = props.isInvalid || props.validationState === 'invalid' || isUnavailable;\n let validationState: ValidationState | null = isValueInvalid ? 'invalid' : null;\n\n let pageDuration = useMemo(() => {\n if (pageBehavior === 'visible') {\n return visibleDuration;\n }\n\n return unitDuration(visibleDuration);\n }, [pageBehavior, visibleDuration]);\n\n return {\n isDisabled: props.isDisabled ?? false,\n isReadOnly: props.isReadOnly ?? false,\n value: calendarDateValue as any,\n setValue: setValue as any,\n selectionMode,\n visibleDuration,\n visibleRange: {\n start: startDate,\n end: endDate\n },\n minValue,\n maxValue,\n focusedDate,\n timeZone,\n validationState,\n isValueInvalid,\n setFocusedDate(date) {\n focusCell(date);\n },\n focusNextDay() {\n focusCell(focusedDate.add({days: 1}));\n },\n focusPreviousDay() {\n focusCell(focusedDate.subtract({days: 1}));\n },\n focusNextRow() {\n if (visibleDuration.days) {\n this.focusNextPage();\n } else if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.add({weeks: 1}));\n }\n },\n focusPreviousRow() {\n if (visibleDuration.days) {\n this.focusPreviousPage();\n } else if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.subtract({weeks: 1}));\n }\n },\n focusNextPage() {\n let start = startDate.add(pageDuration);\n setFocusedDate(constrainValue(focusedDate.add(pageDuration), minValue, maxValue));\n setStartDate(\n alignStart(\n constrainStart(focusedDate, start, pageDuration, locale, minValue, maxValue),\n pageDuration,\n locale\n )\n );\n },\n focusPreviousPage() {\n let start = startDate.subtract(pageDuration);\n setFocusedDate(constrainValue(focusedDate.subtract(pageDuration), minValue, maxValue));\n setStartDate(\n alignStart(\n constrainStart(focusedDate, start, pageDuration, locale, minValue, maxValue),\n pageDuration,\n locale\n )\n );\n },\n focusSectionStart() {\n if (visibleDuration.days) {\n focusCell(startDate);\n } else if (visibleDuration.weeks) {\n focusCell(startOfWeek(focusedDate, locale));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(startOfMonth(focusedDate));\n }\n },\n focusSectionEnd() {\n if (visibleDuration.days) {\n focusCell(endDate);\n } else if (visibleDuration.weeks) {\n focusCell(endOfWeek(focusedDate, locale));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(endOfMonth(focusedDate));\n }\n },\n focusNextSection(larger) {\n if (!larger && !visibleDuration.days) {\n focusCell(focusedDate.add(unitDuration(visibleDuration)));\n return;\n }\n\n if (visibleDuration.days) {\n this.focusNextPage();\n } else if (visibleDuration.weeks) {\n focusCell(focusedDate.add({months: 1}));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.add({years: 1}));\n }\n },\n focusPreviousSection(larger) {\n if (!larger && !visibleDuration.days) {\n focusCell(focusedDate.subtract(unitDuration(visibleDuration)));\n return;\n }\n\n if (visibleDuration.days) {\n this.focusPreviousPage();\n } else if (visibleDuration.weeks) {\n focusCell(focusedDate.subtract({months: 1}));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.subtract({years: 1}));\n }\n },\n selectFocusedDate() {\n if (!(isDateUnavailable && isDateUnavailable(focusedDate))) {\n this.selectDate(focusedDate);\n }\n },\n selectDate(date) {\n if (props.isDisabled || props.isReadOnly) {\n return;\n }\n\n if (selectionMode === 'multiple' && date != null) {\n let newDate = normalizeValue(date);\n if (!newDate) {\n return;\n }\n\n let baseValue: T[] = [];\n if (Array.isArray(value)) {\n baseValue = value;\n } else if (value != null) {\n baseValue = [value];\n }\n\n let index = baseValue.findIndex(value => isSameDay(value, newDate));\n let newValue =\n index >= 0\n ? baseValue.slice(0, index).concat(baseValue.slice(index + 1))\n : [...baseValue, newDate];\n setControlledValue(newValue);\n } else {\n setValue(date);\n }\n },\n isFocused,\n setFocused,\n isInvalid(date) {\n return isInvalid(date, minValue, maxValue);\n },\n isSelected(date) {\n if (!calendarDateValue || this.isCellDisabled(date) || this.isCellUnavailable(date)) {\n return false;\n }\n return Array.isArray(calendarDateValue)\n ? calendarDateValue.some(value => isSameDay(value, date))\n : isSameDay(date, calendarDateValue);\n },\n isCellFocused(date) {\n return isFocused && focusedDate && isSameDay(date, focusedDate);\n },\n isCellDisabled(date) {\n return (\n props.isDisabled ||\n date.compare(startDate) < 0 ||\n date.compare(endDate) > 0 ||\n this.isInvalid(date)\n );\n },\n isCellUnavailable(date) {\n return props.isDateUnavailable ? props.isDateUnavailable(date) : false;\n },\n isPreviousVisibleRangeInvalid() {\n let prev = startDate.subtract({days: 1});\n return isSameDay(prev, startDate) || this.isInvalid(prev);\n },\n isNextVisibleRangeInvalid() {\n // Adding may return the same date if we reached the end of time\n // according to the calendar system (e.g. 9999-12-31).\n let next = endDate.add({days: 1});\n return isSameDay(next, endDate) || this.isInvalid(next);\n },\n getDatesInWeek(weekIndex, from = startDate) {\n let date = from.add({weeks: weekIndex});\n let dates: (CalendarDate | null)[] = [];\n\n let days = visibleDuration.days && visibleDuration.days < 7 ? visibleDuration.days : 7;\n if (days === 7) {\n date = startOfWeek(date, locale, firstDayOfWeek);\n\n // startOfWeek will clamp dates within the calendar system's valid range, which may\n // start in the middle of a week. In this case, add null placeholders.\n let dayOfWeek = getDayOfWeek(date, locale, firstDayOfWeek);\n for (let i = 0; i < dayOfWeek; i++) {\n dates.push(null);\n }\n }\n\n while (dates.length < days) {\n dates.push(date);\n let nextDate = date.add({days: 1});\n if (isSameDay(date, nextDate)) {\n // If the next day is the same, we have hit the end of the calendar system.\n break;\n }\n date = nextDate;\n }\n\n // Add null placeholders if at the end of the calendar system.\n while (dates.length < days) {\n dates.push(null);\n }\n\n return dates;\n },\n getWeeksInMonth(date = startDate) {\n let weeks = weeksInMonth || getWeeksInMonth(date, locale, firstDayOfWeek);\n if (visibleDuration.weeks || visibleDuration.days) {\n weeks = visibleDuration.weeks ?? 0;\n if (visibleDuration.days) {\n weeks += Math.ceil(visibleDuration.days / 7);\n }\n }\n return weeks;\n }\n };\n}\n\nfunction unitDuration(duration: DateDuration) {\n let unit = {...duration};\n for (let key in duration) {\n unit[key] = 1;\n }\n return unit;\n}\n"],"names":[],"version":3,"file":"useCalendarState.cjs.map"}
1
+ {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AA4FM,SAAS,0CAGd,KAAiC;IACjC,IAAI,mBAAmB,CAAA,GAAA,oBAAM,EAAE,IAAM,IAAI,CAAA,GAAA,0CAAY,EAAE,MAAM,MAAM,GAAG;QAAC,MAAM,MAAM;KAAC;IACpF,IAAI,kBAAkB,CAAA,GAAA,oBAAM,EAAE,IAAM,iBAAiB,eAAe,IAAI;QAAC;KAAiB;IAC1F,IAAI,UACF,MAAM,kBACN,cAAc,mBACd,kBAAkB;QAAC,QAAQ;IAAC,aAC5B,QAAQ,YACR,QAAQ,sBACR,kBAAkB,qBAClB,iBAAiB,gBACjB,eAAe,0BACf,gBAAgB,0BAChB,cAAc,gBACd,YAAY,EACb,GAAG;IACJ,IAAI,WAAW,CAAA,GAAA,oBAAM,EACnB,IAAM,eAAe,gBAAgB,QAAQ,GAC7C;QAA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;YAEf;YAEA,MAAO,MAAM,MAAM,GAAG,KAAM;gBAC1B,MAAM,IAAI,CAAC;gBACX,IAAI,WAAW,KAAK,GAAG,CAAC;oBAAC,MAAM;gBAAC;gBAChC,IAAI,CAAA,GAAA,sCAAQ,EAAE,MAAM,WAElB;gBAEF,OAAO;YACT;YAEA,8DAA8D;YAC9D,MAAO,MAAM,MAAM,GAAG,KACpB,MAAM,IAAI,CAAC;YAGb,OAAO;QACT;QACA,iBAAgB,OAAO,SAAS;YAC9B,IAAI,QAAQ,gBAAgB,CAAA,GAAA,4CAAc,EAAE,MAAM,QAAQ;YAC1D,IAAI,gBAAgB,KAAK,IAAI,gBAAgB,IAAI,EAAE;gBACjD,QAAQ,gBAAgB,KAAK,IAAI;gBACjC,IAAI,gBAAgB,IAAI,EACtB,SAAS,KAAK,IAAI,CAAC,gBAAgB,IAAI,GAAG;YAE9C;YACA,OAAO;QACT;IACF;AACF;AAEA,SAAS,mCAAa,QAAsB;IAC1C,IAAI,OAAO;QAAC,GAAG,QAAQ;IAAA;IACvB,IAAK,IAAI,OAAO,SACd,IAAI,CAAC,IAAI,GAAG;IAEd,OAAO;AACT","sources":["packages/react-stately/src/calendar/useCalendarState.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 {\n alignCenter,\n alignEnd,\n alignStart,\n constrainStart,\n constrainValue,\n isEqualDuration,\n isInvalid,\n previousAvailableDate\n} from './utils';\nimport {\n Calendar,\n CalendarDate,\n CalendarIdentifier,\n DateDuration,\n DateFormatter,\n endOfMonth,\n endOfWeek,\n getDayOfWeek,\n getWeeksInMonth,\n GregorianCalendar,\n isEqualCalendar,\n isSameDay,\n minDate,\n startOfMonth,\n startOfWeek,\n toCalendar,\n toCalendarDate,\n today\n} from '@internationalized/date';\nimport {\n CalendarPropsBase,\n CalendarSelectionMode,\n CalendarState,\n CalendarValueType,\n DateValue,\n MappedDateValue\n} from './types';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useState} from 'react';\nimport {ValidationState, ValueBase} from '@react-types/shared';\n\nexport interface CalendarProps<T extends DateValue, M extends CalendarSelectionMode = 'single'>\n extends\n CalendarPropsBase,\n ValueBase<CalendarValueType<T | null, M>, CalendarValueType<MappedDateValue<T>, M>> {\n /**\n * Whether single or multiple selection is enabled.\n *\n * @default 'single'\n */\n selectionMode?: M;\n /**\n * Callback that is called for each date of the calendar. If it returns true, then the date is\n * unavailable.\n */\n isDateUnavailable?: (date: DateValue) => boolean;\n}\n\nexport interface CalendarStateOptions<\n T extends DateValue = DateValue,\n M extends CalendarSelectionMode = 'single'\n> extends CalendarProps<T, M> {\n /** The locale to display and edit the value according to. */\n locale: string;\n /**\n * A function that creates a [Calendar](../internationalized/date/Calendar.html)\n * object for a given calendar identifier. Such a function may be imported from the\n * `@internationalized/date` package, or manually implemented to include support for\n * only certain calendars.\n */\n createCalendar: (name: CalendarIdentifier) => Calendar;\n /**\n * The amount of days that will be displayed at once. This affects how pagination works.\n *\n * @default { months: 1 }\n */\n visibleDuration?: DateDuration;\n /**\n * Determines the alignment of the visible months on initial render based on the current selection\n * or current date if there is no selection.\n *\n * @default 'center'\n */\n selectionAlignment?: 'start' | 'center' | 'end';\n}\n/**\n * Provides state management for a calendar component.\n * A calendar displays one or more date grids and allows users to select a single date.\n */\nexport function useCalendarState<\n T extends DateValue = DateValue,\n M extends CalendarSelectionMode = 'single'\n>(props: CalendarStateOptions<T, M>): CalendarState<M> {\n let defaultFormatter = useMemo(() => new DateFormatter(props.locale), [props.locale]);\n let resolvedOptions = useMemo(() => defaultFormatter.resolvedOptions(), [defaultFormatter]);\n let {\n locale,\n createCalendar,\n visibleDuration = {months: 1},\n minValue,\n maxValue,\n selectionAlignment,\n isDateUnavailable,\n pageBehavior = 'visible',\n selectionMode = 'single' as M,\n firstDayOfWeek,\n weeksInMonth\n } = props;\n let calendar = useMemo(\n () => createCalendar(resolvedOptions.calendar as CalendarIdentifier),\n [createCalendar, resolvedOptions.calendar]\n );\n\n let [value, setControlledValue] = useControlledState<\n T | T[] | null,\n MappedDateValue<T> | MappedDateValue<T>[] | null\n >(props.value as any, (props.defaultValue as any) ?? null, props.onChange as any);\n let calendarDateValue = useMemo(() => {\n if (Array.isArray(value)) {\n return value.map(value => toCalendar(toCalendarDate(value), calendar));\n } else {\n return value ? toCalendar(toCalendarDate(value), calendar) : null;\n }\n }, [value, calendar]);\n let timeZone = useMemo(() => {\n let val = Array.isArray(value) ? value[0] : value;\n return val && 'timeZone' in val ? val.timeZone : resolvedOptions.timeZone;\n }, [value, resolvedOptions.timeZone]);\n let focusedCalendarDate = useMemo(\n () =>\n props.focusedValue\n ? constrainValue(\n toCalendar(toCalendarDate(props.focusedValue), calendar),\n minValue,\n maxValue\n )\n : undefined,\n [props.focusedValue, calendar, minValue, maxValue]\n );\n let defaultFocusedCalendarDate = useMemo(() => {\n if (props.defaultFocusedValue) {\n return constrainValue(\n toCalendar(toCalendarDate(props.defaultFocusedValue), calendar),\n minValue,\n maxValue\n );\n }\n\n if (calendarDateValue) {\n return constrainValue(\n Array.isArray(calendarDateValue) ? calendarDateValue[0] : calendarDateValue,\n minValue,\n maxValue\n );\n }\n\n return constrainValue(toCalendar(today(timeZone), calendar), minValue, maxValue);\n }, [props.defaultFocusedValue, calendarDateValue, timeZone, calendar, minValue, maxValue]);\n let [focusedDate, setFocusedDate] = useControlledState(\n focusedCalendarDate,\n defaultFocusedCalendarDate,\n props.onFocusChange\n );\n let getStartDate = () => {\n switch (selectionAlignment) {\n case 'start':\n return alignStart(focusedDate, visibleDuration, locale, minValue, maxValue);\n case 'end':\n return alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue);\n case 'center':\n default:\n return alignCenter(focusedDate, visibleDuration, locale, minValue, maxValue);\n }\n };\n\n let [startDate, setStartDate] = useState(getStartDate);\n let [isFocused, setFocused] = useState(props.autoFocus || false);\n\n let [lastVisibleDuration, setLastVisibleDuration] = useState(visibleDuration);\n if (!isEqualDuration(visibleDuration, lastVisibleDuration)) {\n setLastVisibleDuration(visibleDuration);\n setStartDate(getStartDate());\n }\n\n let endDate = useMemo(() => {\n let duration = {...visibleDuration};\n if (duration.days) {\n duration.days--;\n } else {\n duration.days = -1;\n }\n return startDate.add(duration);\n }, [startDate, visibleDuration]);\n\n // Reset focused date and visible range when calendar changes.\n let [lastCalendar, setLastCalendar] = useState(calendar);\n if (!isEqualCalendar(calendar, lastCalendar)) {\n let newFocusedDate = toCalendar(focusedDate, calendar);\n setStartDate(alignCenter(newFocusedDate, visibleDuration, locale, minValue, maxValue));\n setFocusedDate(newFocusedDate);\n setLastCalendar(calendar);\n }\n\n if (isInvalid(focusedDate, minValue, maxValue)) {\n // If the focused date was moved to an invalid value, it can't be focused, so constrain it.\n setFocusedDate(constrainValue(focusedDate, minValue, maxValue));\n } else if (focusedDate.compare(startDate) < 0) {\n setStartDate(alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue));\n } else if (focusedDate.compare(endDate) > 0) {\n setStartDate(alignStart(focusedDate, visibleDuration, locale, minValue, maxValue));\n }\n\n // Sets focus to a specific cell date\n function focusCell(date: CalendarDate) {\n date = constrainValue(date, minValue, maxValue);\n setFocusedDate(date);\n }\n\n function normalizeValue(newValue: CalendarDate) {\n let constrained = constrainValue(newValue, minValue, maxValue);\n let lowerBound = minValue ?? minDate(constrained, startDate);\n let prev = previousAvailableDate(constrained, lowerBound, isDateUnavailable);\n if (!prev) {\n return null;\n }\n\n // The display calendar should not have any effect on the emitted value.\n // Emit dates in the same calendar as the original value, if any, otherwise gregorian.\n let baseValue = Array.isArray(value) ? value[0] : value;\n let calendarValue = toCalendar(prev, baseValue?.calendar || new GregorianCalendar());\n\n // Preserve time if the input value had one.\n if (baseValue && 'hour' in baseValue) {\n return baseValue.set(calendarValue) as T;\n }\n\n return calendarValue as T;\n }\n\n function setValue(newValue: CalendarDate | CalendarDate[] | null) {\n if (!props.isDisabled && !props.isReadOnly) {\n if (newValue === null) {\n setControlledValue(selectionMode === 'multiple' ? [] : null);\n return;\n }\n\n if (Array.isArray(newValue)) {\n setControlledValue(newValue.map(normalizeValue).filter(Boolean) as any);\n } else {\n let localValue = normalizeValue(newValue);\n if (localValue) {\n setControlledValue(localValue as any);\n }\n }\n }\n }\n\n let isUnavailable = useMemo(() => {\n if (!calendarDateValue) {\n return false;\n }\n\n if (Array.isArray(calendarDateValue)) {\n return calendarDateValue.some(\n date => isDateUnavailable?.(date) || isInvalid(date, minValue, maxValue)\n );\n }\n\n return (\n isDateUnavailable?.(calendarDateValue) || isInvalid(calendarDateValue, minValue, maxValue)\n );\n }, [calendarDateValue, isDateUnavailable, minValue, maxValue]);\n let isValueInvalid = props.isInvalid || props.validationState === 'invalid' || isUnavailable;\n let validationState: ValidationState | null = isValueInvalid ? 'invalid' : null;\n\n let pageDuration = useMemo(() => {\n if (pageBehavior === 'visible') {\n return visibleDuration;\n }\n\n return unitDuration(visibleDuration);\n }, [pageBehavior, visibleDuration]);\n\n return {\n isDisabled: props.isDisabled ?? false,\n isReadOnly: props.isReadOnly ?? false,\n value: calendarDateValue as any,\n setValue: setValue as any,\n selectionMode,\n visibleDuration,\n visibleRange: {\n start: startDate,\n end: endDate\n },\n minValue,\n maxValue,\n focusedDate,\n timeZone,\n validationState,\n isValueInvalid,\n setFocusedDate(date) {\n focusCell(date);\n },\n focusNextDay() {\n focusCell(focusedDate.add({days: 1}));\n },\n focusPreviousDay() {\n focusCell(focusedDate.subtract({days: 1}));\n },\n focusNextRow() {\n if (visibleDuration.days) {\n this.focusNextPage();\n } else if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.add({weeks: 1}));\n }\n },\n focusPreviousRow() {\n if (visibleDuration.days) {\n this.focusPreviousPage();\n } else if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.subtract({weeks: 1}));\n }\n },\n focusNextPage() {\n let start = startDate.add(pageDuration);\n setFocusedDate(constrainValue(focusedDate.add(pageDuration), minValue, maxValue));\n setStartDate(\n alignStart(\n constrainStart(focusedDate, start, pageDuration, locale, minValue, maxValue),\n pageDuration,\n locale\n )\n );\n },\n focusPreviousPage() {\n let start = startDate.subtract(pageDuration);\n setFocusedDate(constrainValue(focusedDate.subtract(pageDuration), minValue, maxValue));\n setStartDate(\n alignStart(\n constrainStart(focusedDate, start, pageDuration, locale, minValue, maxValue),\n pageDuration,\n locale\n )\n );\n },\n focusSectionStart() {\n if (visibleDuration.days) {\n focusCell(startDate);\n } else if (visibleDuration.weeks) {\n focusCell(startOfWeek(focusedDate, locale));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(startOfMonth(focusedDate));\n }\n },\n focusSectionEnd() {\n if (visibleDuration.days) {\n focusCell(endDate);\n } else if (visibleDuration.weeks) {\n focusCell(endOfWeek(focusedDate, locale));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(endOfMonth(focusedDate));\n }\n },\n focusNextSection(larger) {\n if (!larger && !visibleDuration.days) {\n focusCell(focusedDate.add(unitDuration(visibleDuration)));\n return;\n }\n\n if (visibleDuration.days) {\n this.focusNextPage();\n } else if (visibleDuration.weeks) {\n focusCell(focusedDate.add({months: 1}));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.add({years: 1}));\n }\n },\n focusPreviousSection(larger) {\n if (!larger && !visibleDuration.days) {\n focusCell(focusedDate.subtract(unitDuration(visibleDuration)));\n return;\n }\n\n if (visibleDuration.days) {\n this.focusPreviousPage();\n } else if (visibleDuration.weeks) {\n focusCell(focusedDate.subtract({months: 1}));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.subtract({years: 1}));\n }\n },\n selectFocusedDate() {\n if (!(isDateUnavailable && isDateUnavailable(focusedDate))) {\n this.selectDate(focusedDate);\n }\n },\n selectDate(date) {\n if (props.isDisabled || props.isReadOnly) {\n return;\n }\n\n if (selectionMode === 'multiple' && date != null) {\n let newDate = normalizeValue(date);\n if (!newDate) {\n return;\n }\n\n let baseValue: T[] = [];\n if (Array.isArray(value)) {\n baseValue = value;\n } else if (value != null) {\n baseValue = [value];\n }\n\n let index = baseValue.findIndex(value => isSameDay(value, newDate));\n let newValue =\n index >= 0\n ? baseValue.slice(0, index).concat(baseValue.slice(index + 1))\n : [...baseValue, newDate];\n setControlledValue(newValue);\n } else {\n setValue(date);\n }\n },\n isFocused,\n setFocused,\n isInvalid(date) {\n return isInvalid(date, minValue, maxValue);\n },\n isSelected(date) {\n if (!calendarDateValue || this.isCellDisabled(date) || this.isCellUnavailable(date)) {\n return false;\n }\n return Array.isArray(calendarDateValue)\n ? calendarDateValue.some(value => isSameDay(value, date))\n : isSameDay(date, calendarDateValue);\n },\n isCellFocused(date) {\n return isFocused && focusedDate && isSameDay(date, focusedDate);\n },\n isCellDisabled(date) {\n return (\n props.isDisabled ||\n date.compare(startDate) < 0 ||\n date.compare(endDate) > 0 ||\n this.isInvalid(date)\n );\n },\n isCellUnavailable(date) {\n return props.isDateUnavailable ? props.isDateUnavailable(date) : false;\n },\n isPreviousVisibleRangeInvalid() {\n let prev = startDate.subtract({days: 1});\n return isSameDay(prev, startDate) || this.isInvalid(prev);\n },\n isNextVisibleRangeInvalid() {\n // Adding may return the same date if we reached the end of time\n // according to the calendar system (e.g. 9999-12-31).\n let next = endDate.add({days: 1});\n return isSameDay(next, endDate) || this.isInvalid(next);\n },\n getDatesInWeek(weekIndex, from = startDate) {\n let date = from.add({weeks: weekIndex});\n let dates: (CalendarDate | null)[] = [];\n\n let days = visibleDuration.days && visibleDuration.days < 7 ? visibleDuration.days : 7;\n if (days === 7) {\n date = startOfWeek(date, locale, firstDayOfWeek);\n\n // startOfWeek will clamp dates within the calendar system's valid range, which may\n // start in the middle of a week. In this case, add null placeholders.\n let dayOfWeek = getDayOfWeek(date, locale, firstDayOfWeek);\n for (let i = 0; i < dayOfWeek; i++) {\n dates.push(null);\n }\n }\n\n while (dates.length < days) {\n dates.push(date);\n let nextDate = date.add({days: 1});\n if (isSameDay(date, nextDate)) {\n // If the next day is the same, we have hit the end of the calendar system.\n break;\n }\n date = nextDate;\n }\n\n // Add null placeholders if at the end of the calendar system.\n while (dates.length < days) {\n dates.push(null);\n }\n\n return dates;\n },\n getWeeksInMonth(date = startDate) {\n let weeks = weeksInMonth || getWeeksInMonth(date, locale, firstDayOfWeek);\n if (visibleDuration.weeks || visibleDuration.days) {\n weeks = visibleDuration.weeks ?? 0;\n if (visibleDuration.days) {\n weeks += Math.ceil(visibleDuration.days / 7);\n }\n }\n return weeks;\n }\n };\n}\n\nfunction unitDuration(duration: DateDuration) {\n let unit = {...duration};\n for (let key in duration) {\n unit[key] = 1;\n }\n return unit;\n}\n"],"names":[],"version":3,"file":"useCalendarState.cjs.map"}
@@ -1,6 +1,6 @@
1
1
  import {alignCenter as $4f2e4d26acdebef8$export$f4a51ff076cc9a09, alignEnd as $4f2e4d26acdebef8$export$530edbfc915b2b04, alignStart as $4f2e4d26acdebef8$export$144a00ba6044eb9, constrainStart as $4f2e4d26acdebef8$export$5bb865b12696a77d, constrainValue as $4f2e4d26acdebef8$export$4f5203c0d889109e, isEqualDuration as $4f2e4d26acdebef8$export$6595e603c409b4b8, isInvalid as $4f2e4d26acdebef8$export$eac50920cf2fd59a, previousAvailableDate as $4f2e4d26acdebef8$export$a1d3911297b952d7} from "./utils.js";
2
2
  import {useControlledState as $2a35a170cf8e413e$export$40bfa8c7b0832715} from "../utils/useControlledState.js";
3
- import {DateFormatter as $5WOJq$DateFormatter, toCalendar as $5WOJq$toCalendar, toCalendarDate as $5WOJq$toCalendarDate, today as $5WOJq$today, isEqualCalendar as $5WOJq$isEqualCalendar, GregorianCalendar as $5WOJq$GregorianCalendar, startOfWeek as $5WOJq$startOfWeek, startOfMonth as $5WOJq$startOfMonth, endOfWeek as $5WOJq$endOfWeek, endOfMonth as $5WOJq$endOfMonth, isSameDay as $5WOJq$isSameDay, getDayOfWeek as $5WOJq$getDayOfWeek, getWeeksInMonth as $5WOJq$getWeeksInMonth} from "@internationalized/date";
3
+ import {DateFormatter as $5WOJq$DateFormatter, toCalendar as $5WOJq$toCalendar, toCalendarDate as $5WOJq$toCalendarDate, today as $5WOJq$today, isEqualCalendar as $5WOJq$isEqualCalendar, minDate as $5WOJq$minDate, GregorianCalendar as $5WOJq$GregorianCalendar, startOfWeek as $5WOJq$startOfWeek, startOfMonth as $5WOJq$startOfMonth, endOfWeek as $5WOJq$endOfWeek, endOfMonth as $5WOJq$endOfMonth, isSameDay as $5WOJq$isSameDay, getDayOfWeek as $5WOJq$getDayOfWeek, getWeeksInMonth as $5WOJq$getWeeksInMonth} from "@internationalized/date";
4
4
  import {useMemo as $5WOJq$useMemo, useState as $5WOJq$useState} from "react";
5
5
 
6
6
  /*
@@ -114,7 +114,8 @@ function $2ff2cc7e373be77a$export$6d095e787d2b5e1f(props) {
114
114
  }
115
115
  function normalizeValue(newValue) {
116
116
  let constrained = (0, $4f2e4d26acdebef8$export$4f5203c0d889109e)(newValue, minValue, maxValue);
117
- let prev = (0, $4f2e4d26acdebef8$export$a1d3911297b952d7)(constrained, startDate, isDateUnavailable);
117
+ let lowerBound = minValue !== null && minValue !== void 0 ? minValue : (0, $5WOJq$minDate)(constrained, startDate);
118
+ let prev = (0, $4f2e4d26acdebef8$export$a1d3911297b952d7)(constrained, lowerBound, isDateUnavailable);
118
119
  if (!prev) return null;
119
120
  // The display calendar should not have any effect on the emitted value.
120
121
  // Emit dates in the same calendar as the original value, if any, otherwise gregorian.
@@ -1 +1 @@
1
- {"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AA2FM,SAAS,0CAGd,KAAiC;IACjC,IAAI,mBAAm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QAAQ;IAAA;IACvB,IAAK,IAAI,OAAO,SACd,IAAI,CAAC,IAAI,GAAG;IAEd,OAAO;AACT","sources":["packages/react-stately/src/calendar/useCalendarState.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 {\n alignCenter,\n alignEnd,\n alignStart,\n constrainStart,\n constrainValue,\n isEqualDuration,\n isInvalid,\n previousAvailableDate\n} from './utils';\nimport {\n Calendar,\n CalendarDate,\n CalendarIdentifier,\n DateDuration,\n DateFormatter,\n endOfMonth,\n endOfWeek,\n getDayOfWeek,\n getWeeksInMonth,\n GregorianCalendar,\n isEqualCalendar,\n isSameDay,\n startOfMonth,\n startOfWeek,\n toCalendar,\n toCalendarDate,\n today\n} from '@internationalized/date';\nimport {\n CalendarPropsBase,\n CalendarSelectionMode,\n CalendarState,\n CalendarValueType,\n DateValue,\n MappedDateValue\n} from './types';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useState} from 'react';\nimport {ValidationState, ValueBase} from '@react-types/shared';\n\nexport interface CalendarProps<T extends DateValue, M extends CalendarSelectionMode = 'single'>\n extends\n CalendarPropsBase,\n ValueBase<CalendarValueType<T | null, M>, CalendarValueType<MappedDateValue<T>, M>> {\n /**\n * Whether single or multiple selection is enabled.\n *\n * @default 'single'\n */\n selectionMode?: M;\n /**\n * Callback that is called for each date of the calendar. If it returns true, then the date is\n * unavailable.\n */\n isDateUnavailable?: (date: DateValue) => boolean;\n}\n\nexport interface CalendarStateOptions<\n T extends DateValue = DateValue,\n M extends CalendarSelectionMode = 'single'\n> extends CalendarProps<T, M> {\n /** The locale to display and edit the value according to. */\n locale: string;\n /**\n * A function that creates a [Calendar](../internationalized/date/Calendar.html)\n * object for a given calendar identifier. Such a function may be imported from the\n * `@internationalized/date` package, or manually implemented to include support for\n * only certain calendars.\n */\n createCalendar: (name: CalendarIdentifier) => Calendar;\n /**\n * The amount of days that will be displayed at once. This affects how pagination works.\n *\n * @default { months: 1 }\n */\n visibleDuration?: DateDuration;\n /**\n * Determines the alignment of the visible months on initial render based on the current selection\n * or current date if there is no selection.\n *\n * @default 'center'\n */\n selectionAlignment?: 'start' | 'center' | 'end';\n}\n/**\n * Provides state management for a calendar component.\n * A calendar displays one or more date grids and allows users to select a single date.\n */\nexport function useCalendarState<\n T extends DateValue = DateValue,\n M extends CalendarSelectionMode = 'single'\n>(props: CalendarStateOptions<T, M>): CalendarState<M> {\n let defaultFormatter = useMemo(() => new DateFormatter(props.locale), [props.locale]);\n let resolvedOptions = useMemo(() => defaultFormatter.resolvedOptions(), [defaultFormatter]);\n let {\n locale,\n createCalendar,\n visibleDuration = {months: 1},\n minValue,\n maxValue,\n selectionAlignment,\n isDateUnavailable,\n pageBehavior = 'visible',\n selectionMode = 'single' as M,\n firstDayOfWeek,\n weeksInMonth\n } = props;\n let calendar = useMemo(\n () => createCalendar(resolvedOptions.calendar as CalendarIdentifier),\n [createCalendar, resolvedOptions.calendar]\n );\n\n let [value, setControlledValue] = useControlledState<\n T | T[] | null,\n MappedDateValue<T> | MappedDateValue<T>[] | null\n >(props.value as any, (props.defaultValue as any) ?? null, props.onChange as any);\n let calendarDateValue = useMemo(() => {\n if (Array.isArray(value)) {\n return value.map(value => toCalendar(toCalendarDate(value), calendar));\n } else {\n return value ? toCalendar(toCalendarDate(value), calendar) : null;\n }\n }, [value, calendar]);\n let timeZone = useMemo(() => {\n let val = Array.isArray(value) ? value[0] : value;\n return val && 'timeZone' in val ? val.timeZone : resolvedOptions.timeZone;\n }, [value, resolvedOptions.timeZone]);\n let focusedCalendarDate = useMemo(\n () =>\n props.focusedValue\n ? constrainValue(\n toCalendar(toCalendarDate(props.focusedValue), calendar),\n minValue,\n maxValue\n )\n : undefined,\n [props.focusedValue, calendar, minValue, maxValue]\n );\n let defaultFocusedCalendarDate = useMemo(() => {\n if (props.defaultFocusedValue) {\n return constrainValue(\n toCalendar(toCalendarDate(props.defaultFocusedValue), calendar),\n minValue,\n maxValue\n );\n }\n\n if (calendarDateValue) {\n return constrainValue(\n Array.isArray(calendarDateValue) ? calendarDateValue[0] : calendarDateValue,\n minValue,\n maxValue\n );\n }\n\n return constrainValue(toCalendar(today(timeZone), calendar), minValue, maxValue);\n }, [props.defaultFocusedValue, calendarDateValue, timeZone, calendar, minValue, maxValue]);\n let [focusedDate, setFocusedDate] = useControlledState(\n focusedCalendarDate,\n defaultFocusedCalendarDate,\n props.onFocusChange\n );\n let getStartDate = () => {\n switch (selectionAlignment) {\n case 'start':\n return alignStart(focusedDate, visibleDuration, locale, minValue, maxValue);\n case 'end':\n return alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue);\n case 'center':\n default:\n return alignCenter(focusedDate, visibleDuration, locale, minValue, maxValue);\n }\n };\n\n let [startDate, setStartDate] = useState(getStartDate);\n let [isFocused, setFocused] = useState(props.autoFocus || false);\n\n let [lastVisibleDuration, setLastVisibleDuration] = useState(visibleDuration);\n if (!isEqualDuration(visibleDuration, lastVisibleDuration)) {\n setLastVisibleDuration(visibleDuration);\n setStartDate(getStartDate());\n }\n\n let endDate = useMemo(() => {\n let duration = {...visibleDuration};\n if (duration.days) {\n duration.days--;\n } else {\n duration.days = -1;\n }\n return startDate.add(duration);\n }, [startDate, visibleDuration]);\n\n // Reset focused date and visible range when calendar changes.\n let [lastCalendar, setLastCalendar] = useState(calendar);\n if (!isEqualCalendar(calendar, lastCalendar)) {\n let newFocusedDate = toCalendar(focusedDate, calendar);\n setStartDate(alignCenter(newFocusedDate, visibleDuration, locale, minValue, maxValue));\n setFocusedDate(newFocusedDate);\n setLastCalendar(calendar);\n }\n\n if (isInvalid(focusedDate, minValue, maxValue)) {\n // If the focused date was moved to an invalid value, it can't be focused, so constrain it.\n setFocusedDate(constrainValue(focusedDate, minValue, maxValue));\n } else if (focusedDate.compare(startDate) < 0) {\n setStartDate(alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue));\n } else if (focusedDate.compare(endDate) > 0) {\n setStartDate(alignStart(focusedDate, visibleDuration, locale, minValue, maxValue));\n }\n\n // Sets focus to a specific cell date\n function focusCell(date: CalendarDate) {\n date = constrainValue(date, minValue, maxValue);\n setFocusedDate(date);\n }\n\n function normalizeValue(newValue: CalendarDate) {\n let constrained = constrainValue(newValue, minValue, maxValue);\n let prev = previousAvailableDate(constrained, startDate, isDateUnavailable);\n if (!prev) {\n return null;\n }\n\n // The display calendar should not have any effect on the emitted value.\n // Emit dates in the same calendar as the original value, if any, otherwise gregorian.\n let baseValue = Array.isArray(value) ? value[0] : value;\n let calendarValue = toCalendar(prev, baseValue?.calendar || new GregorianCalendar());\n\n // Preserve time if the input value had one.\n if (baseValue && 'hour' in baseValue) {\n return baseValue.set(calendarValue) as T;\n }\n\n return calendarValue as T;\n }\n\n function setValue(newValue: CalendarDate | CalendarDate[] | null) {\n if (!props.isDisabled && !props.isReadOnly) {\n if (newValue === null) {\n setControlledValue(selectionMode === 'multiple' ? [] : null);\n return;\n }\n\n if (Array.isArray(newValue)) {\n setControlledValue(newValue.map(normalizeValue).filter(Boolean) as any);\n } else {\n let localValue = normalizeValue(newValue);\n if (localValue) {\n setControlledValue(localValue as any);\n }\n }\n }\n }\n\n let isUnavailable = useMemo(() => {\n if (!calendarDateValue) {\n return false;\n }\n\n if (Array.isArray(calendarDateValue)) {\n return calendarDateValue.some(\n date => isDateUnavailable?.(date) || isInvalid(date, minValue, maxValue)\n );\n }\n\n return (\n isDateUnavailable?.(calendarDateValue) || isInvalid(calendarDateValue, minValue, maxValue)\n );\n }, [calendarDateValue, isDateUnavailable, minValue, maxValue]);\n let isValueInvalid = props.isInvalid || props.validationState === 'invalid' || isUnavailable;\n let validationState: ValidationState | null = isValueInvalid ? 'invalid' : null;\n\n let pageDuration = useMemo(() => {\n if (pageBehavior === 'visible') {\n return visibleDuration;\n }\n\n return unitDuration(visibleDuration);\n }, [pageBehavior, visibleDuration]);\n\n return {\n isDisabled: props.isDisabled ?? false,\n isReadOnly: props.isReadOnly ?? false,\n value: calendarDateValue as any,\n setValue: setValue as any,\n selectionMode,\n visibleDuration,\n visibleRange: {\n start: startDate,\n end: endDate\n },\n minValue,\n maxValue,\n focusedDate,\n timeZone,\n validationState,\n isValueInvalid,\n setFocusedDate(date) {\n focusCell(date);\n },\n focusNextDay() {\n focusCell(focusedDate.add({days: 1}));\n },\n focusPreviousDay() {\n focusCell(focusedDate.subtract({days: 1}));\n },\n focusNextRow() {\n if (visibleDuration.days) {\n this.focusNextPage();\n } else if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.add({weeks: 1}));\n }\n },\n focusPreviousRow() {\n if (visibleDuration.days) {\n this.focusPreviousPage();\n } else if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.subtract({weeks: 1}));\n }\n },\n focusNextPage() {\n let start = startDate.add(pageDuration);\n setFocusedDate(constrainValue(focusedDate.add(pageDuration), minValue, maxValue));\n setStartDate(\n alignStart(\n constrainStart(focusedDate, start, pageDuration, locale, minValue, maxValue),\n pageDuration,\n locale\n )\n );\n },\n focusPreviousPage() {\n let start = startDate.subtract(pageDuration);\n setFocusedDate(constrainValue(focusedDate.subtract(pageDuration), minValue, maxValue));\n setStartDate(\n alignStart(\n constrainStart(focusedDate, start, pageDuration, locale, minValue, maxValue),\n pageDuration,\n locale\n )\n );\n },\n focusSectionStart() {\n if (visibleDuration.days) {\n focusCell(startDate);\n } else if (visibleDuration.weeks) {\n focusCell(startOfWeek(focusedDate, locale));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(startOfMonth(focusedDate));\n }\n },\n focusSectionEnd() {\n if (visibleDuration.days) {\n focusCell(endDate);\n } else if (visibleDuration.weeks) {\n focusCell(endOfWeek(focusedDate, locale));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(endOfMonth(focusedDate));\n }\n },\n focusNextSection(larger) {\n if (!larger && !visibleDuration.days) {\n focusCell(focusedDate.add(unitDuration(visibleDuration)));\n return;\n }\n\n if (visibleDuration.days) {\n this.focusNextPage();\n } else if (visibleDuration.weeks) {\n focusCell(focusedDate.add({months: 1}));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.add({years: 1}));\n }\n },\n focusPreviousSection(larger) {\n if (!larger && !visibleDuration.days) {\n focusCell(focusedDate.subtract(unitDuration(visibleDuration)));\n return;\n }\n\n if (visibleDuration.days) {\n this.focusPreviousPage();\n } else if (visibleDuration.weeks) {\n focusCell(focusedDate.subtract({months: 1}));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.subtract({years: 1}));\n }\n },\n selectFocusedDate() {\n if (!(isDateUnavailable && isDateUnavailable(focusedDate))) {\n this.selectDate(focusedDate);\n }\n },\n selectDate(date) {\n if (props.isDisabled || props.isReadOnly) {\n return;\n }\n\n if (selectionMode === 'multiple' && date != null) {\n let newDate = normalizeValue(date);\n if (!newDate) {\n return;\n }\n\n let baseValue: T[] = [];\n if (Array.isArray(value)) {\n baseValue = value;\n } else if (value != null) {\n baseValue = [value];\n }\n\n let index = baseValue.findIndex(value => isSameDay(value, newDate));\n let newValue =\n index >= 0\n ? baseValue.slice(0, index).concat(baseValue.slice(index + 1))\n : [...baseValue, newDate];\n setControlledValue(newValue);\n } else {\n setValue(date);\n }\n },\n isFocused,\n setFocused,\n isInvalid(date) {\n return isInvalid(date, minValue, maxValue);\n },\n isSelected(date) {\n if (!calendarDateValue || this.isCellDisabled(date) || this.isCellUnavailable(date)) {\n return false;\n }\n return Array.isArray(calendarDateValue)\n ? calendarDateValue.some(value => isSameDay(value, date))\n : isSameDay(date, calendarDateValue);\n },\n isCellFocused(date) {\n return isFocused && focusedDate && isSameDay(date, focusedDate);\n },\n isCellDisabled(date) {\n return (\n props.isDisabled ||\n date.compare(startDate) < 0 ||\n date.compare(endDate) > 0 ||\n this.isInvalid(date)\n );\n },\n isCellUnavailable(date) {\n return props.isDateUnavailable ? props.isDateUnavailable(date) : false;\n },\n isPreviousVisibleRangeInvalid() {\n let prev = startDate.subtract({days: 1});\n return isSameDay(prev, startDate) || this.isInvalid(prev);\n },\n isNextVisibleRangeInvalid() {\n // Adding may return the same date if we reached the end of time\n // according to the calendar system (e.g. 9999-12-31).\n let next = endDate.add({days: 1});\n return isSameDay(next, endDate) || this.isInvalid(next);\n },\n getDatesInWeek(weekIndex, from = startDate) {\n let date = from.add({weeks: weekIndex});\n let dates: (CalendarDate | null)[] = [];\n\n let days = visibleDuration.days && visibleDuration.days < 7 ? visibleDuration.days : 7;\n if (days === 7) {\n date = startOfWeek(date, locale, firstDayOfWeek);\n\n // startOfWeek will clamp dates within the calendar system's valid range, which may\n // start in the middle of a week. In this case, add null placeholders.\n let dayOfWeek = getDayOfWeek(date, locale, firstDayOfWeek);\n for (let i = 0; i < dayOfWeek; i++) {\n dates.push(null);\n }\n }\n\n while (dates.length < days) {\n dates.push(date);\n let nextDate = date.add({days: 1});\n if (isSameDay(date, nextDate)) {\n // If the next day is the same, we have hit the end of the calendar system.\n break;\n }\n date = nextDate;\n }\n\n // Add null placeholders if at the end of the calendar system.\n while (dates.length < days) {\n dates.push(null);\n }\n\n return dates;\n },\n getWeeksInMonth(date = startDate) {\n let weeks = weeksInMonth || getWeeksInMonth(date, locale, firstDayOfWeek);\n if (visibleDuration.weeks || visibleDuration.days) {\n weeks = visibleDuration.weeks ?? 0;\n if (visibleDuration.days) {\n weeks += Math.ceil(visibleDuration.days / 7);\n }\n }\n return weeks;\n }\n };\n}\n\nfunction unitDuration(duration: DateDuration) {\n let unit = {...duration};\n for (let key in duration) {\n unit[key] = 1;\n }\n return unit;\n}\n"],"names":[],"version":3,"file":"useCalendarState.js.map"}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IAAI,gBAAgB,IAAI,EACtB,SAAS,KAAK,IAAI,CAAC,gBAAgB,IAAI,GAAG;YAE9C;YACA,OAAO;QACT;IACF;AACF;AAEA,SAAS,mCAAa,QAAsB;IAC1C,IAAI,OAAO;QAAC,GAAG,QAAQ;IAAA;IACvB,IAAK,IAAI,OAAO,SACd,IAAI,CAAC,IAAI,GAAG;IAEd,OAAO;AACT","sources":["packages/react-stately/src/calendar/useCalendarState.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 {\n alignCenter,\n alignEnd,\n alignStart,\n constrainStart,\n constrainValue,\n isEqualDuration,\n isInvalid,\n previousAvailableDate\n} from './utils';\nimport {\n Calendar,\n CalendarDate,\n CalendarIdentifier,\n DateDuration,\n DateFormatter,\n endOfMonth,\n endOfWeek,\n getDayOfWeek,\n getWeeksInMonth,\n GregorianCalendar,\n isEqualCalendar,\n isSameDay,\n minDate,\n startOfMonth,\n startOfWeek,\n toCalendar,\n toCalendarDate,\n today\n} from '@internationalized/date';\nimport {\n CalendarPropsBase,\n CalendarSelectionMode,\n CalendarState,\n CalendarValueType,\n DateValue,\n MappedDateValue\n} from './types';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useState} from 'react';\nimport {ValidationState, ValueBase} from '@react-types/shared';\n\nexport interface CalendarProps<T extends DateValue, M extends CalendarSelectionMode = 'single'>\n extends\n CalendarPropsBase,\n ValueBase<CalendarValueType<T | null, M>, CalendarValueType<MappedDateValue<T>, M>> {\n /**\n * Whether single or multiple selection is enabled.\n *\n * @default 'single'\n */\n selectionMode?: M;\n /**\n * Callback that is called for each date of the calendar. If it returns true, then the date is\n * unavailable.\n */\n isDateUnavailable?: (date: DateValue) => boolean;\n}\n\nexport interface CalendarStateOptions<\n T extends DateValue = DateValue,\n M extends CalendarSelectionMode = 'single'\n> extends CalendarProps<T, M> {\n /** The locale to display and edit the value according to. */\n locale: string;\n /**\n * A function that creates a [Calendar](../internationalized/date/Calendar.html)\n * object for a given calendar identifier. Such a function may be imported from the\n * `@internationalized/date` package, or manually implemented to include support for\n * only certain calendars.\n */\n createCalendar: (name: CalendarIdentifier) => Calendar;\n /**\n * The amount of days that will be displayed at once. This affects how pagination works.\n *\n * @default { months: 1 }\n */\n visibleDuration?: DateDuration;\n /**\n * Determines the alignment of the visible months on initial render based on the current selection\n * or current date if there is no selection.\n *\n * @default 'center'\n */\n selectionAlignment?: 'start' | 'center' | 'end';\n}\n/**\n * Provides state management for a calendar component.\n * A calendar displays one or more date grids and allows users to select a single date.\n */\nexport function useCalendarState<\n T extends DateValue = DateValue,\n M extends CalendarSelectionMode = 'single'\n>(props: CalendarStateOptions<T, M>): CalendarState<M> {\n let defaultFormatter = useMemo(() => new DateFormatter(props.locale), [props.locale]);\n let resolvedOptions = useMemo(() => defaultFormatter.resolvedOptions(), [defaultFormatter]);\n let {\n locale,\n createCalendar,\n visibleDuration = {months: 1},\n minValue,\n maxValue,\n selectionAlignment,\n isDateUnavailable,\n pageBehavior = 'visible',\n selectionMode = 'single' as M,\n firstDayOfWeek,\n weeksInMonth\n } = props;\n let calendar = useMemo(\n () => createCalendar(resolvedOptions.calendar as CalendarIdentifier),\n [createCalendar, resolvedOptions.calendar]\n );\n\n let [value, setControlledValue] = useControlledState<\n T | T[] | null,\n MappedDateValue<T> | MappedDateValue<T>[] | null\n >(props.value as any, (props.defaultValue as any) ?? null, props.onChange as any);\n let calendarDateValue = useMemo(() => {\n if (Array.isArray(value)) {\n return value.map(value => toCalendar(toCalendarDate(value), calendar));\n } else {\n return value ? toCalendar(toCalendarDate(value), calendar) : null;\n }\n }, [value, calendar]);\n let timeZone = useMemo(() => {\n let val = Array.isArray(value) ? value[0] : value;\n return val && 'timeZone' in val ? val.timeZone : resolvedOptions.timeZone;\n }, [value, resolvedOptions.timeZone]);\n let focusedCalendarDate = useMemo(\n () =>\n props.focusedValue\n ? constrainValue(\n toCalendar(toCalendarDate(props.focusedValue), calendar),\n minValue,\n maxValue\n )\n : undefined,\n [props.focusedValue, calendar, minValue, maxValue]\n );\n let defaultFocusedCalendarDate = useMemo(() => {\n if (props.defaultFocusedValue) {\n return constrainValue(\n toCalendar(toCalendarDate(props.defaultFocusedValue), calendar),\n minValue,\n maxValue\n );\n }\n\n if (calendarDateValue) {\n return constrainValue(\n Array.isArray(calendarDateValue) ? calendarDateValue[0] : calendarDateValue,\n minValue,\n maxValue\n );\n }\n\n return constrainValue(toCalendar(today(timeZone), calendar), minValue, maxValue);\n }, [props.defaultFocusedValue, calendarDateValue, timeZone, calendar, minValue, maxValue]);\n let [focusedDate, setFocusedDate] = useControlledState(\n focusedCalendarDate,\n defaultFocusedCalendarDate,\n props.onFocusChange\n );\n let getStartDate = () => {\n switch (selectionAlignment) {\n case 'start':\n return alignStart(focusedDate, visibleDuration, locale, minValue, maxValue);\n case 'end':\n return alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue);\n case 'center':\n default:\n return alignCenter(focusedDate, visibleDuration, locale, minValue, maxValue);\n }\n };\n\n let [startDate, setStartDate] = useState(getStartDate);\n let [isFocused, setFocused] = useState(props.autoFocus || false);\n\n let [lastVisibleDuration, setLastVisibleDuration] = useState(visibleDuration);\n if (!isEqualDuration(visibleDuration, lastVisibleDuration)) {\n setLastVisibleDuration(visibleDuration);\n setStartDate(getStartDate());\n }\n\n let endDate = useMemo(() => {\n let duration = {...visibleDuration};\n if (duration.days) {\n duration.days--;\n } else {\n duration.days = -1;\n }\n return startDate.add(duration);\n }, [startDate, visibleDuration]);\n\n // Reset focused date and visible range when calendar changes.\n let [lastCalendar, setLastCalendar] = useState(calendar);\n if (!isEqualCalendar(calendar, lastCalendar)) {\n let newFocusedDate = toCalendar(focusedDate, calendar);\n setStartDate(alignCenter(newFocusedDate, visibleDuration, locale, minValue, maxValue));\n setFocusedDate(newFocusedDate);\n setLastCalendar(calendar);\n }\n\n if (isInvalid(focusedDate, minValue, maxValue)) {\n // If the focused date was moved to an invalid value, it can't be focused, so constrain it.\n setFocusedDate(constrainValue(focusedDate, minValue, maxValue));\n } else if (focusedDate.compare(startDate) < 0) {\n setStartDate(alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue));\n } else if (focusedDate.compare(endDate) > 0) {\n setStartDate(alignStart(focusedDate, visibleDuration, locale, minValue, maxValue));\n }\n\n // Sets focus to a specific cell date\n function focusCell(date: CalendarDate) {\n date = constrainValue(date, minValue, maxValue);\n setFocusedDate(date);\n }\n\n function normalizeValue(newValue: CalendarDate) {\n let constrained = constrainValue(newValue, minValue, maxValue);\n let lowerBound = minValue ?? minDate(constrained, startDate);\n let prev = previousAvailableDate(constrained, lowerBound, isDateUnavailable);\n if (!prev) {\n return null;\n }\n\n // The display calendar should not have any effect on the emitted value.\n // Emit dates in the same calendar as the original value, if any, otherwise gregorian.\n let baseValue = Array.isArray(value) ? value[0] : value;\n let calendarValue = toCalendar(prev, baseValue?.calendar || new GregorianCalendar());\n\n // Preserve time if the input value had one.\n if (baseValue && 'hour' in baseValue) {\n return baseValue.set(calendarValue) as T;\n }\n\n return calendarValue as T;\n }\n\n function setValue(newValue: CalendarDate | CalendarDate[] | null) {\n if (!props.isDisabled && !props.isReadOnly) {\n if (newValue === null) {\n setControlledValue(selectionMode === 'multiple' ? [] : null);\n return;\n }\n\n if (Array.isArray(newValue)) {\n setControlledValue(newValue.map(normalizeValue).filter(Boolean) as any);\n } else {\n let localValue = normalizeValue(newValue);\n if (localValue) {\n setControlledValue(localValue as any);\n }\n }\n }\n }\n\n let isUnavailable = useMemo(() => {\n if (!calendarDateValue) {\n return false;\n }\n\n if (Array.isArray(calendarDateValue)) {\n return calendarDateValue.some(\n date => isDateUnavailable?.(date) || isInvalid(date, minValue, maxValue)\n );\n }\n\n return (\n isDateUnavailable?.(calendarDateValue) || isInvalid(calendarDateValue, minValue, maxValue)\n );\n }, [calendarDateValue, isDateUnavailable, minValue, maxValue]);\n let isValueInvalid = props.isInvalid || props.validationState === 'invalid' || isUnavailable;\n let validationState: ValidationState | null = isValueInvalid ? 'invalid' : null;\n\n let pageDuration = useMemo(() => {\n if (pageBehavior === 'visible') {\n return visibleDuration;\n }\n\n return unitDuration(visibleDuration);\n }, [pageBehavior, visibleDuration]);\n\n return {\n isDisabled: props.isDisabled ?? false,\n isReadOnly: props.isReadOnly ?? false,\n value: calendarDateValue as any,\n setValue: setValue as any,\n selectionMode,\n visibleDuration,\n visibleRange: {\n start: startDate,\n end: endDate\n },\n minValue,\n maxValue,\n focusedDate,\n timeZone,\n validationState,\n isValueInvalid,\n setFocusedDate(date) {\n focusCell(date);\n },\n focusNextDay() {\n focusCell(focusedDate.add({days: 1}));\n },\n focusPreviousDay() {\n focusCell(focusedDate.subtract({days: 1}));\n },\n focusNextRow() {\n if (visibleDuration.days) {\n this.focusNextPage();\n } else if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.add({weeks: 1}));\n }\n },\n focusPreviousRow() {\n if (visibleDuration.days) {\n this.focusPreviousPage();\n } else if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.subtract({weeks: 1}));\n }\n },\n focusNextPage() {\n let start = startDate.add(pageDuration);\n setFocusedDate(constrainValue(focusedDate.add(pageDuration), minValue, maxValue));\n setStartDate(\n alignStart(\n constrainStart(focusedDate, start, pageDuration, locale, minValue, maxValue),\n pageDuration,\n locale\n )\n );\n },\n focusPreviousPage() {\n let start = startDate.subtract(pageDuration);\n setFocusedDate(constrainValue(focusedDate.subtract(pageDuration), minValue, maxValue));\n setStartDate(\n alignStart(\n constrainStart(focusedDate, start, pageDuration, locale, minValue, maxValue),\n pageDuration,\n locale\n )\n );\n },\n focusSectionStart() {\n if (visibleDuration.days) {\n focusCell(startDate);\n } else if (visibleDuration.weeks) {\n focusCell(startOfWeek(focusedDate, locale));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(startOfMonth(focusedDate));\n }\n },\n focusSectionEnd() {\n if (visibleDuration.days) {\n focusCell(endDate);\n } else if (visibleDuration.weeks) {\n focusCell(endOfWeek(focusedDate, locale));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(endOfMonth(focusedDate));\n }\n },\n focusNextSection(larger) {\n if (!larger && !visibleDuration.days) {\n focusCell(focusedDate.add(unitDuration(visibleDuration)));\n return;\n }\n\n if (visibleDuration.days) {\n this.focusNextPage();\n } else if (visibleDuration.weeks) {\n focusCell(focusedDate.add({months: 1}));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.add({years: 1}));\n }\n },\n focusPreviousSection(larger) {\n if (!larger && !visibleDuration.days) {\n focusCell(focusedDate.subtract(unitDuration(visibleDuration)));\n return;\n }\n\n if (visibleDuration.days) {\n this.focusPreviousPage();\n } else if (visibleDuration.weeks) {\n focusCell(focusedDate.subtract({months: 1}));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.subtract({years: 1}));\n }\n },\n selectFocusedDate() {\n if (!(isDateUnavailable && isDateUnavailable(focusedDate))) {\n this.selectDate(focusedDate);\n }\n },\n selectDate(date) {\n if (props.isDisabled || props.isReadOnly) {\n return;\n }\n\n if (selectionMode === 'multiple' && date != null) {\n let newDate = normalizeValue(date);\n if (!newDate) {\n return;\n }\n\n let baseValue: T[] = [];\n if (Array.isArray(value)) {\n baseValue = value;\n } else if (value != null) {\n baseValue = [value];\n }\n\n let index = baseValue.findIndex(value => isSameDay(value, newDate));\n let newValue =\n index >= 0\n ? baseValue.slice(0, index).concat(baseValue.slice(index + 1))\n : [...baseValue, newDate];\n setControlledValue(newValue);\n } else {\n setValue(date);\n }\n },\n isFocused,\n setFocused,\n isInvalid(date) {\n return isInvalid(date, minValue, maxValue);\n },\n isSelected(date) {\n if (!calendarDateValue || this.isCellDisabled(date) || this.isCellUnavailable(date)) {\n return false;\n }\n return Array.isArray(calendarDateValue)\n ? calendarDateValue.some(value => isSameDay(value, date))\n : isSameDay(date, calendarDateValue);\n },\n isCellFocused(date) {\n return isFocused && focusedDate && isSameDay(date, focusedDate);\n },\n isCellDisabled(date) {\n return (\n props.isDisabled ||\n date.compare(startDate) < 0 ||\n date.compare(endDate) > 0 ||\n this.isInvalid(date)\n );\n },\n isCellUnavailable(date) {\n return props.isDateUnavailable ? props.isDateUnavailable(date) : false;\n },\n isPreviousVisibleRangeInvalid() {\n let prev = startDate.subtract({days: 1});\n return isSameDay(prev, startDate) || this.isInvalid(prev);\n },\n isNextVisibleRangeInvalid() {\n // Adding may return the same date if we reached the end of time\n // according to the calendar system (e.g. 9999-12-31).\n let next = endDate.add({days: 1});\n return isSameDay(next, endDate) || this.isInvalid(next);\n },\n getDatesInWeek(weekIndex, from = startDate) {\n let date = from.add({weeks: weekIndex});\n let dates: (CalendarDate | null)[] = [];\n\n let days = visibleDuration.days && visibleDuration.days < 7 ? visibleDuration.days : 7;\n if (days === 7) {\n date = startOfWeek(date, locale, firstDayOfWeek);\n\n // startOfWeek will clamp dates within the calendar system's valid range, which may\n // start in the middle of a week. In this case, add null placeholders.\n let dayOfWeek = getDayOfWeek(date, locale, firstDayOfWeek);\n for (let i = 0; i < dayOfWeek; i++) {\n dates.push(null);\n }\n }\n\n while (dates.length < days) {\n dates.push(date);\n let nextDate = date.add({days: 1});\n if (isSameDay(date, nextDate)) {\n // If the next day is the same, we have hit the end of the calendar system.\n break;\n }\n date = nextDate;\n }\n\n // Add null placeholders if at the end of the calendar system.\n while (dates.length < days) {\n dates.push(null);\n }\n\n return dates;\n },\n getWeeksInMonth(date = startDate) {\n let weeks = weeksInMonth || getWeeksInMonth(date, locale, firstDayOfWeek);\n if (visibleDuration.weeks || visibleDuration.days) {\n weeks = visibleDuration.weeks ?? 0;\n if (visibleDuration.days) {\n weeks += Math.ceil(visibleDuration.days / 7);\n }\n }\n return weeks;\n }\n };\n}\n\nfunction unitDuration(duration: DateDuration) {\n let unit = {...duration};\n for (let key in duration) {\n unit[key] = 1;\n }\n return unit;\n}\n"],"names":[],"version":3,"file":"useCalendarState.js.map"}
@@ -1,6 +1,6 @@
1
1
  import {alignCenter as $dd602d3c757202f2$export$f4a51ff076cc9a09, alignEnd as $dd602d3c757202f2$export$530edbfc915b2b04, alignStart as $dd602d3c757202f2$export$144a00ba6044eb9, constrainStart as $dd602d3c757202f2$export$5bb865b12696a77d, constrainValue as $dd602d3c757202f2$export$4f5203c0d889109e, isEqualDuration as $dd602d3c757202f2$export$6595e603c409b4b8, isInvalid as $dd602d3c757202f2$export$eac50920cf2fd59a, previousAvailableDate as $dd602d3c757202f2$export$a1d3911297b952d7} from "./utils.mjs";
2
2
  import {useControlledState as $3e6197669829fe11$export$40bfa8c7b0832715} from "../utils/useControlledState.mjs";
3
- import {DateFormatter as $aoVcW$DateFormatter, toCalendar as $aoVcW$toCalendar, toCalendarDate as $aoVcW$toCalendarDate, today as $aoVcW$today, isEqualCalendar as $aoVcW$isEqualCalendar, GregorianCalendar as $aoVcW$GregorianCalendar, startOfWeek as $aoVcW$startOfWeek, startOfMonth as $aoVcW$startOfMonth, endOfWeek as $aoVcW$endOfWeek, endOfMonth as $aoVcW$endOfMonth, isSameDay as $aoVcW$isSameDay, getDayOfWeek as $aoVcW$getDayOfWeek, getWeeksInMonth as $aoVcW$getWeeksInMonth} from "@internationalized/date";
3
+ import {DateFormatter as $aoVcW$DateFormatter, toCalendar as $aoVcW$toCalendar, toCalendarDate as $aoVcW$toCalendarDate, today as $aoVcW$today, isEqualCalendar as $aoVcW$isEqualCalendar, minDate as $aoVcW$minDate, GregorianCalendar as $aoVcW$GregorianCalendar, startOfWeek as $aoVcW$startOfWeek, startOfMonth as $aoVcW$startOfMonth, endOfWeek as $aoVcW$endOfWeek, endOfMonth as $aoVcW$endOfMonth, isSameDay as $aoVcW$isSameDay, getDayOfWeek as $aoVcW$getDayOfWeek, getWeeksInMonth as $aoVcW$getWeeksInMonth} from "@internationalized/date";
4
4
  import {useMemo as $aoVcW$useMemo, useState as $aoVcW$useState} from "react";
5
5
 
6
6
  /*
@@ -113,7 +113,8 @@ function $ea0ea6e62ae0d7ca$export$6d095e787d2b5e1f(props) {
113
113
  }
114
114
  function normalizeValue(newValue) {
115
115
  let constrained = (0, $dd602d3c757202f2$export$4f5203c0d889109e)(newValue, minValue, maxValue);
116
- let prev = (0, $dd602d3c757202f2$export$a1d3911297b952d7)(constrained, startDate, isDateUnavailable);
116
+ let lowerBound = minValue ?? (0, $aoVcW$minDate)(constrained, startDate);
117
+ let prev = (0, $dd602d3c757202f2$export$a1d3911297b952d7)(constrained, lowerBound, isDateUnavailable);
117
118
  if (!prev) return null;
118
119
  // The display calendar should not have any effect on the emitted value.
119
120
  // Emit dates in the same calendar as the original value, if any, otherwise gregorian.
@@ -1 +1 @@
1
- {"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AA2FM,SAAS,0CAGd,KAAiC;IACjC,IAAI,mBAAmB,CAAA,GAAA,cAAM,EAAE,IAAM,IAAI,CAAA,GAAA,oBAAY,EAAE,MAAM,MAAM,GAAG;QAAC,MAAM,MAAM;KAAC;IACpF,IAAI,kBAAkB,CAAA,GAAA,cAAM,EAAE,IAAM,iBAAiB,eAAe,IAAI;QAAC;KAAiB;IAC1F,IAAI,UACF,MAAM,kBACN,cAAc,mBACd,kBAAkB;QAAC,QAAQ;IAAC,aAC5B,QAAQ,YACR,QAAQ,sBACR,kBAAkB,qBAClB,iBAAiB,gBACjB,eAAe,0BACf,gBAAgB,0BAChB,cAAc,gBACd,YAAY,EACb,GAAG;IACJ,IAAI,WAAW,CAAA,GAAA,cAAM,EACnB,IAAM,eAAe,gBAAgB,QAAQ,GAC7C;QAAC;QAAgB,gBAAgB,QAAQ;KAAC;IAG5C,IAAI,CAAC,OA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C;gBAChC,IAAI,CAAA,GAAA,gBAAQ,EAAE,MAAM,WAElB;gBAEF,OAAO;YACT;YAEA,8DAA8D;YAC9D,MAAO,MAAM,MAAM,GAAG,KACpB,MAAM,IAAI,CAAC;YAGb,OAAO;QACT;QACA,iBAAgB,OAAO,SAAS;YAC9B,IAAI,QAAQ,gBAAgB,CAAA,GAAA,sBAAc,EAAE,MAAM,QAAQ;YAC1D,IAAI,gBAAgB,KAAK,IAAI,gBAAgB,IAAI,EAAE;gBACjD,QAAQ,gBAAgB,KAAK,IAAI;gBACjC,IAAI,gBAAgB,IAAI,EACtB,SAAS,KAAK,IAAI,CAAC,gBAAgB,IAAI,GAAG;YAE9C;YACA,OAAO;QACT;IACF;AACF;AAEA,SAAS,mCAAa,QAAsB;IAC1C,IAAI,OAAO;QAAC,GAAG,QAAQ;IAAA;IACvB,IAAK,IAAI,OAAO,SACd,IAAI,CAAC,IAAI,GAAG;IAEd,OAAO;AACT","sources":["packages/react-stately/src/calendar/useCalendarState.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 {\n alignCenter,\n alignEnd,\n alignStart,\n constrainStart,\n constrainValue,\n isEqualDuration,\n isInvalid,\n previousAvailableDate\n} from './utils';\nimport {\n Calendar,\n CalendarDate,\n CalendarIdentifier,\n DateDuration,\n DateFormatter,\n endOfMonth,\n endOfWeek,\n getDayOfWeek,\n getWeeksInMonth,\n GregorianCalendar,\n isEqualCalendar,\n isSameDay,\n startOfMonth,\n startOfWeek,\n toCalendar,\n toCalendarDate,\n today\n} from '@internationalized/date';\nimport {\n CalendarPropsBase,\n CalendarSelectionMode,\n CalendarState,\n CalendarValueType,\n DateValue,\n MappedDateValue\n} from './types';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useState} from 'react';\nimport {ValidationState, ValueBase} from '@react-types/shared';\n\nexport interface CalendarProps<T extends DateValue, M extends CalendarSelectionMode = 'single'>\n extends\n CalendarPropsBase,\n ValueBase<CalendarValueType<T | null, M>, CalendarValueType<MappedDateValue<T>, M>> {\n /**\n * Whether single or multiple selection is enabled.\n *\n * @default 'single'\n */\n selectionMode?: M;\n /**\n * Callback that is called for each date of the calendar. If it returns true, then the date is\n * unavailable.\n */\n isDateUnavailable?: (date: DateValue) => boolean;\n}\n\nexport interface CalendarStateOptions<\n T extends DateValue = DateValue,\n M extends CalendarSelectionMode = 'single'\n> extends CalendarProps<T, M> {\n /** The locale to display and edit the value according to. */\n locale: string;\n /**\n * A function that creates a [Calendar](../internationalized/date/Calendar.html)\n * object for a given calendar identifier. Such a function may be imported from the\n * `@internationalized/date` package, or manually implemented to include support for\n * only certain calendars.\n */\n createCalendar: (name: CalendarIdentifier) => Calendar;\n /**\n * The amount of days that will be displayed at once. This affects how pagination works.\n *\n * @default { months: 1 }\n */\n visibleDuration?: DateDuration;\n /**\n * Determines the alignment of the visible months on initial render based on the current selection\n * or current date if there is no selection.\n *\n * @default 'center'\n */\n selectionAlignment?: 'start' | 'center' | 'end';\n}\n/**\n * Provides state management for a calendar component.\n * A calendar displays one or more date grids and allows users to select a single date.\n */\nexport function useCalendarState<\n T extends DateValue = DateValue,\n M extends CalendarSelectionMode = 'single'\n>(props: CalendarStateOptions<T, M>): CalendarState<M> {\n let defaultFormatter = useMemo(() => new DateFormatter(props.locale), [props.locale]);\n let resolvedOptions = useMemo(() => defaultFormatter.resolvedOptions(), [defaultFormatter]);\n let {\n locale,\n createCalendar,\n visibleDuration = {months: 1},\n minValue,\n maxValue,\n selectionAlignment,\n isDateUnavailable,\n pageBehavior = 'visible',\n selectionMode = 'single' as M,\n firstDayOfWeek,\n weeksInMonth\n } = props;\n let calendar = useMemo(\n () => createCalendar(resolvedOptions.calendar as CalendarIdentifier),\n [createCalendar, resolvedOptions.calendar]\n );\n\n let [value, setControlledValue] = useControlledState<\n T | T[] | null,\n MappedDateValue<T> | MappedDateValue<T>[] | null\n >(props.value as any, (props.defaultValue as any) ?? null, props.onChange as any);\n let calendarDateValue = useMemo(() => {\n if (Array.isArray(value)) {\n return value.map(value => toCalendar(toCalendarDate(value), calendar));\n } else {\n return value ? toCalendar(toCalendarDate(value), calendar) : null;\n }\n }, [value, calendar]);\n let timeZone = useMemo(() => {\n let val = Array.isArray(value) ? value[0] : value;\n return val && 'timeZone' in val ? val.timeZone : resolvedOptions.timeZone;\n }, [value, resolvedOptions.timeZone]);\n let focusedCalendarDate = useMemo(\n () =>\n props.focusedValue\n ? constrainValue(\n toCalendar(toCalendarDate(props.focusedValue), calendar),\n minValue,\n maxValue\n )\n : undefined,\n [props.focusedValue, calendar, minValue, maxValue]\n );\n let defaultFocusedCalendarDate = useMemo(() => {\n if (props.defaultFocusedValue) {\n return constrainValue(\n toCalendar(toCalendarDate(props.defaultFocusedValue), calendar),\n minValue,\n maxValue\n );\n }\n\n if (calendarDateValue) {\n return constrainValue(\n Array.isArray(calendarDateValue) ? calendarDateValue[0] : calendarDateValue,\n minValue,\n maxValue\n );\n }\n\n return constrainValue(toCalendar(today(timeZone), calendar), minValue, maxValue);\n }, [props.defaultFocusedValue, calendarDateValue, timeZone, calendar, minValue, maxValue]);\n let [focusedDate, setFocusedDate] = useControlledState(\n focusedCalendarDate,\n defaultFocusedCalendarDate,\n props.onFocusChange\n );\n let getStartDate = () => {\n switch (selectionAlignment) {\n case 'start':\n return alignStart(focusedDate, visibleDuration, locale, minValue, maxValue);\n case 'end':\n return alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue);\n case 'center':\n default:\n return alignCenter(focusedDate, visibleDuration, locale, minValue, maxValue);\n }\n };\n\n let [startDate, setStartDate] = useState(getStartDate);\n let [isFocused, setFocused] = useState(props.autoFocus || false);\n\n let [lastVisibleDuration, setLastVisibleDuration] = useState(visibleDuration);\n if (!isEqualDuration(visibleDuration, lastVisibleDuration)) {\n setLastVisibleDuration(visibleDuration);\n setStartDate(getStartDate());\n }\n\n let endDate = useMemo(() => {\n let duration = {...visibleDuration};\n if (duration.days) {\n duration.days--;\n } else {\n duration.days = -1;\n }\n return startDate.add(duration);\n }, [startDate, visibleDuration]);\n\n // Reset focused date and visible range when calendar changes.\n let [lastCalendar, setLastCalendar] = useState(calendar);\n if (!isEqualCalendar(calendar, lastCalendar)) {\n let newFocusedDate = toCalendar(focusedDate, calendar);\n setStartDate(alignCenter(newFocusedDate, visibleDuration, locale, minValue, maxValue));\n setFocusedDate(newFocusedDate);\n setLastCalendar(calendar);\n }\n\n if (isInvalid(focusedDate, minValue, maxValue)) {\n // If the focused date was moved to an invalid value, it can't be focused, so constrain it.\n setFocusedDate(constrainValue(focusedDate, minValue, maxValue));\n } else if (focusedDate.compare(startDate) < 0) {\n setStartDate(alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue));\n } else if (focusedDate.compare(endDate) > 0) {\n setStartDate(alignStart(focusedDate, visibleDuration, locale, minValue, maxValue));\n }\n\n // Sets focus to a specific cell date\n function focusCell(date: CalendarDate) {\n date = constrainValue(date, minValue, maxValue);\n setFocusedDate(date);\n }\n\n function normalizeValue(newValue: CalendarDate) {\n let constrained = constrainValue(newValue, minValue, maxValue);\n let prev = previousAvailableDate(constrained, startDate, isDateUnavailable);\n if (!prev) {\n return null;\n }\n\n // The display calendar should not have any effect on the emitted value.\n // Emit dates in the same calendar as the original value, if any, otherwise gregorian.\n let baseValue = Array.isArray(value) ? value[0] : value;\n let calendarValue = toCalendar(prev, baseValue?.calendar || new GregorianCalendar());\n\n // Preserve time if the input value had one.\n if (baseValue && 'hour' in baseValue) {\n return baseValue.set(calendarValue) as T;\n }\n\n return calendarValue as T;\n }\n\n function setValue(newValue: CalendarDate | CalendarDate[] | null) {\n if (!props.isDisabled && !props.isReadOnly) {\n if (newValue === null) {\n setControlledValue(selectionMode === 'multiple' ? [] : null);\n return;\n }\n\n if (Array.isArray(newValue)) {\n setControlledValue(newValue.map(normalizeValue).filter(Boolean) as any);\n } else {\n let localValue = normalizeValue(newValue);\n if (localValue) {\n setControlledValue(localValue as any);\n }\n }\n }\n }\n\n let isUnavailable = useMemo(() => {\n if (!calendarDateValue) {\n return false;\n }\n\n if (Array.isArray(calendarDateValue)) {\n return calendarDateValue.some(\n date => isDateUnavailable?.(date) || isInvalid(date, minValue, maxValue)\n );\n }\n\n return (\n isDateUnavailable?.(calendarDateValue) || isInvalid(calendarDateValue, minValue, maxValue)\n );\n }, [calendarDateValue, isDateUnavailable, minValue, maxValue]);\n let isValueInvalid = props.isInvalid || props.validationState === 'invalid' || isUnavailable;\n let validationState: ValidationState | null = isValueInvalid ? 'invalid' : null;\n\n let pageDuration = useMemo(() => {\n if (pageBehavior === 'visible') {\n return visibleDuration;\n }\n\n return unitDuration(visibleDuration);\n }, [pageBehavior, visibleDuration]);\n\n return {\n isDisabled: props.isDisabled ?? false,\n isReadOnly: props.isReadOnly ?? false,\n value: calendarDateValue as any,\n setValue: setValue as any,\n selectionMode,\n visibleDuration,\n visibleRange: {\n start: startDate,\n end: endDate\n },\n minValue,\n maxValue,\n focusedDate,\n timeZone,\n validationState,\n isValueInvalid,\n setFocusedDate(date) {\n focusCell(date);\n },\n focusNextDay() {\n focusCell(focusedDate.add({days: 1}));\n },\n focusPreviousDay() {\n focusCell(focusedDate.subtract({days: 1}));\n },\n focusNextRow() {\n if (visibleDuration.days) {\n this.focusNextPage();\n } else if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.add({weeks: 1}));\n }\n },\n focusPreviousRow() {\n if (visibleDuration.days) {\n this.focusPreviousPage();\n } else if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.subtract({weeks: 1}));\n }\n },\n focusNextPage() {\n let start = startDate.add(pageDuration);\n setFocusedDate(constrainValue(focusedDate.add(pageDuration), minValue, maxValue));\n setStartDate(\n alignStart(\n constrainStart(focusedDate, start, pageDuration, locale, minValue, maxValue),\n pageDuration,\n locale\n )\n );\n },\n focusPreviousPage() {\n let start = startDate.subtract(pageDuration);\n setFocusedDate(constrainValue(focusedDate.subtract(pageDuration), minValue, maxValue));\n setStartDate(\n alignStart(\n constrainStart(focusedDate, start, pageDuration, locale, minValue, maxValue),\n pageDuration,\n locale\n )\n );\n },\n focusSectionStart() {\n if (visibleDuration.days) {\n focusCell(startDate);\n } else if (visibleDuration.weeks) {\n focusCell(startOfWeek(focusedDate, locale));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(startOfMonth(focusedDate));\n }\n },\n focusSectionEnd() {\n if (visibleDuration.days) {\n focusCell(endDate);\n } else if (visibleDuration.weeks) {\n focusCell(endOfWeek(focusedDate, locale));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(endOfMonth(focusedDate));\n }\n },\n focusNextSection(larger) {\n if (!larger && !visibleDuration.days) {\n focusCell(focusedDate.add(unitDuration(visibleDuration)));\n return;\n }\n\n if (visibleDuration.days) {\n this.focusNextPage();\n } else if (visibleDuration.weeks) {\n focusCell(focusedDate.add({months: 1}));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.add({years: 1}));\n }\n },\n focusPreviousSection(larger) {\n if (!larger && !visibleDuration.days) {\n focusCell(focusedDate.subtract(unitDuration(visibleDuration)));\n return;\n }\n\n if (visibleDuration.days) {\n this.focusPreviousPage();\n } else if (visibleDuration.weeks) {\n focusCell(focusedDate.subtract({months: 1}));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.subtract({years: 1}));\n }\n },\n selectFocusedDate() {\n if (!(isDateUnavailable && isDateUnavailable(focusedDate))) {\n this.selectDate(focusedDate);\n }\n },\n selectDate(date) {\n if (props.isDisabled || props.isReadOnly) {\n return;\n }\n\n if (selectionMode === 'multiple' && date != null) {\n let newDate = normalizeValue(date);\n if (!newDate) {\n return;\n }\n\n let baseValue: T[] = [];\n if (Array.isArray(value)) {\n baseValue = value;\n } else if (value != null) {\n baseValue = [value];\n }\n\n let index = baseValue.findIndex(value => isSameDay(value, newDate));\n let newValue =\n index >= 0\n ? baseValue.slice(0, index).concat(baseValue.slice(index + 1))\n : [...baseValue, newDate];\n setControlledValue(newValue);\n } else {\n setValue(date);\n }\n },\n isFocused,\n setFocused,\n isInvalid(date) {\n return isInvalid(date, minValue, maxValue);\n },\n isSelected(date) {\n if (!calendarDateValue || this.isCellDisabled(date) || this.isCellUnavailable(date)) {\n return false;\n }\n return Array.isArray(calendarDateValue)\n ? calendarDateValue.some(value => isSameDay(value, date))\n : isSameDay(date, calendarDateValue);\n },\n isCellFocused(date) {\n return isFocused && focusedDate && isSameDay(date, focusedDate);\n },\n isCellDisabled(date) {\n return (\n props.isDisabled ||\n date.compare(startDate) < 0 ||\n date.compare(endDate) > 0 ||\n this.isInvalid(date)\n );\n },\n isCellUnavailable(date) {\n return props.isDateUnavailable ? props.isDateUnavailable(date) : false;\n },\n isPreviousVisibleRangeInvalid() {\n let prev = startDate.subtract({days: 1});\n return isSameDay(prev, startDate) || this.isInvalid(prev);\n },\n isNextVisibleRangeInvalid() {\n // Adding may return the same date if we reached the end of time\n // according to the calendar system (e.g. 9999-12-31).\n let next = endDate.add({days: 1});\n return isSameDay(next, endDate) || this.isInvalid(next);\n },\n getDatesInWeek(weekIndex, from = startDate) {\n let date = from.add({weeks: weekIndex});\n let dates: (CalendarDate | null)[] = [];\n\n let days = visibleDuration.days && visibleDuration.days < 7 ? visibleDuration.days : 7;\n if (days === 7) {\n date = startOfWeek(date, locale, firstDayOfWeek);\n\n // startOfWeek will clamp dates within the calendar system's valid range, which may\n // start in the middle of a week. In this case, add null placeholders.\n let dayOfWeek = getDayOfWeek(date, locale, firstDayOfWeek);\n for (let i = 0; i < dayOfWeek; i++) {\n dates.push(null);\n }\n }\n\n while (dates.length < days) {\n dates.push(date);\n let nextDate = date.add({days: 1});\n if (isSameDay(date, nextDate)) {\n // If the next day is the same, we have hit the end of the calendar system.\n break;\n }\n date = nextDate;\n }\n\n // Add null placeholders if at the end of the calendar system.\n while (dates.length < days) {\n dates.push(null);\n }\n\n return dates;\n },\n getWeeksInMonth(date = startDate) {\n let weeks = weeksInMonth || getWeeksInMonth(date, locale, firstDayOfWeek);\n if (visibleDuration.weeks || visibleDuration.days) {\n weeks = visibleDuration.weeks ?? 0;\n if (visibleDuration.days) {\n weeks += Math.ceil(visibleDuration.days / 7);\n }\n }\n return weeks;\n }\n };\n}\n\nfunction unitDuration(duration: DateDuration) {\n let unit = {...duration};\n for (let key in duration) {\n unit[key] = 1;\n }\n return unit;\n}\n"],"names":[],"version":3,"file":"useCalendarState.mjs.map"}
1
+ {"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AA4FM,SAAS,0CAGd,KAAiC;IACjC,IAAI,mBAAmB,CAAA,GAAA,cAAM,EAAE,IAAM,IAAI,CAAA,GAAA,oBAAY,EAAE,MAAM,MAAM,GAAG;QAAC,MAAM,MAAM;KAAC;IACpF,IAAI,kBAAkB,CAAA,GAAA,cAAM,EAAE,IAAM,iBAAiB,eAAe,IAAI;QAAC;KAAiB;IAC1F,IAAI,UACF,MAAM,kBACN,cAAc,mBACd,kBAAkB;QAAC,QAAQ;IAAC,aAC5B,QAAQ,YACR,QAAQ,sBACR,kBAAkB,qBAClB,iBAAiB,gBACjB,eAAe,0BACf,gBAAgB,0BAChB,cAAc,gBACd,YAAY,EACb,GAAG;IACJ,IAAI,WAAW,CAAA,GAAA,cAAM,EACnB,IAAM,eAAe,gBAAgB,QAAQ,GAC7C;QAAC;QAAgB,gBAAgB,QAAQ;KAAC;IAG5C,IAAI,CAAC,OAAO,mBAAmB,GAAG,CAAA,GAAA,yCAAiB,EAGjD,MAAM,KAAK,EAAS,AAAC,MAAM,YAAY,IAAY,MAAM,MAAM,QAAQ;IACzE,IA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,OAAO;YACT;YAEA,8DAA8D;YAC9D,MAAO,MAAM,MAAM,GAAG,KACpB,MAAM,IAAI,CAAC;YAGb,OAAO;QACT;QACA,iBAAgB,OAAO,SAAS;YAC9B,IAAI,QAAQ,gBAAgB,CAAA,GAAA,sBAAc,EAAE,MAAM,QAAQ;YAC1D,IAAI,gBAAgB,KAAK,IAAI,gBAAgB,IAAI,EAAE;gBACjD,QAAQ,gBAAgB,KAAK,IAAI;gBACjC,IAAI,gBAAgB,IAAI,EACtB,SAAS,KAAK,IAAI,CAAC,gBAAgB,IAAI,GAAG;YAE9C;YACA,OAAO;QACT;IACF;AACF;AAEA,SAAS,mCAAa,QAAsB;IAC1C,IAAI,OAAO;QAAC,GAAG,QAAQ;IAAA;IACvB,IAAK,IAAI,OAAO,SACd,IAAI,CAAC,IAAI,GAAG;IAEd,OAAO;AACT","sources":["packages/react-stately/src/calendar/useCalendarState.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 {\n alignCenter,\n alignEnd,\n alignStart,\n constrainStart,\n constrainValue,\n isEqualDuration,\n isInvalid,\n previousAvailableDate\n} from './utils';\nimport {\n Calendar,\n CalendarDate,\n CalendarIdentifier,\n DateDuration,\n DateFormatter,\n endOfMonth,\n endOfWeek,\n getDayOfWeek,\n getWeeksInMonth,\n GregorianCalendar,\n isEqualCalendar,\n isSameDay,\n minDate,\n startOfMonth,\n startOfWeek,\n toCalendar,\n toCalendarDate,\n today\n} from '@internationalized/date';\nimport {\n CalendarPropsBase,\n CalendarSelectionMode,\n CalendarState,\n CalendarValueType,\n DateValue,\n MappedDateValue\n} from './types';\nimport {useControlledState} from '../utils/useControlledState';\nimport {useMemo, useState} from 'react';\nimport {ValidationState, ValueBase} from '@react-types/shared';\n\nexport interface CalendarProps<T extends DateValue, M extends CalendarSelectionMode = 'single'>\n extends\n CalendarPropsBase,\n ValueBase<CalendarValueType<T | null, M>, CalendarValueType<MappedDateValue<T>, M>> {\n /**\n * Whether single or multiple selection is enabled.\n *\n * @default 'single'\n */\n selectionMode?: M;\n /**\n * Callback that is called for each date of the calendar. If it returns true, then the date is\n * unavailable.\n */\n isDateUnavailable?: (date: DateValue) => boolean;\n}\n\nexport interface CalendarStateOptions<\n T extends DateValue = DateValue,\n M extends CalendarSelectionMode = 'single'\n> extends CalendarProps<T, M> {\n /** The locale to display and edit the value according to. */\n locale: string;\n /**\n * A function that creates a [Calendar](../internationalized/date/Calendar.html)\n * object for a given calendar identifier. Such a function may be imported from the\n * `@internationalized/date` package, or manually implemented to include support for\n * only certain calendars.\n */\n createCalendar: (name: CalendarIdentifier) => Calendar;\n /**\n * The amount of days that will be displayed at once. This affects how pagination works.\n *\n * @default { months: 1 }\n */\n visibleDuration?: DateDuration;\n /**\n * Determines the alignment of the visible months on initial render based on the current selection\n * or current date if there is no selection.\n *\n * @default 'center'\n */\n selectionAlignment?: 'start' | 'center' | 'end';\n}\n/**\n * Provides state management for a calendar component.\n * A calendar displays one or more date grids and allows users to select a single date.\n */\nexport function useCalendarState<\n T extends DateValue = DateValue,\n M extends CalendarSelectionMode = 'single'\n>(props: CalendarStateOptions<T, M>): CalendarState<M> {\n let defaultFormatter = useMemo(() => new DateFormatter(props.locale), [props.locale]);\n let resolvedOptions = useMemo(() => defaultFormatter.resolvedOptions(), [defaultFormatter]);\n let {\n locale,\n createCalendar,\n visibleDuration = {months: 1},\n minValue,\n maxValue,\n selectionAlignment,\n isDateUnavailable,\n pageBehavior = 'visible',\n selectionMode = 'single' as M,\n firstDayOfWeek,\n weeksInMonth\n } = props;\n let calendar = useMemo(\n () => createCalendar(resolvedOptions.calendar as CalendarIdentifier),\n [createCalendar, resolvedOptions.calendar]\n );\n\n let [value, setControlledValue] = useControlledState<\n T | T[] | null,\n MappedDateValue<T> | MappedDateValue<T>[] | null\n >(props.value as any, (props.defaultValue as any) ?? null, props.onChange as any);\n let calendarDateValue = useMemo(() => {\n if (Array.isArray(value)) {\n return value.map(value => toCalendar(toCalendarDate(value), calendar));\n } else {\n return value ? toCalendar(toCalendarDate(value), calendar) : null;\n }\n }, [value, calendar]);\n let timeZone = useMemo(() => {\n let val = Array.isArray(value) ? value[0] : value;\n return val && 'timeZone' in val ? val.timeZone : resolvedOptions.timeZone;\n }, [value, resolvedOptions.timeZone]);\n let focusedCalendarDate = useMemo(\n () =>\n props.focusedValue\n ? constrainValue(\n toCalendar(toCalendarDate(props.focusedValue), calendar),\n minValue,\n maxValue\n )\n : undefined,\n [props.focusedValue, calendar, minValue, maxValue]\n );\n let defaultFocusedCalendarDate = useMemo(() => {\n if (props.defaultFocusedValue) {\n return constrainValue(\n toCalendar(toCalendarDate(props.defaultFocusedValue), calendar),\n minValue,\n maxValue\n );\n }\n\n if (calendarDateValue) {\n return constrainValue(\n Array.isArray(calendarDateValue) ? calendarDateValue[0] : calendarDateValue,\n minValue,\n maxValue\n );\n }\n\n return constrainValue(toCalendar(today(timeZone), calendar), minValue, maxValue);\n }, [props.defaultFocusedValue, calendarDateValue, timeZone, calendar, minValue, maxValue]);\n let [focusedDate, setFocusedDate] = useControlledState(\n focusedCalendarDate,\n defaultFocusedCalendarDate,\n props.onFocusChange\n );\n let getStartDate = () => {\n switch (selectionAlignment) {\n case 'start':\n return alignStart(focusedDate, visibleDuration, locale, minValue, maxValue);\n case 'end':\n return alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue);\n case 'center':\n default:\n return alignCenter(focusedDate, visibleDuration, locale, minValue, maxValue);\n }\n };\n\n let [startDate, setStartDate] = useState(getStartDate);\n let [isFocused, setFocused] = useState(props.autoFocus || false);\n\n let [lastVisibleDuration, setLastVisibleDuration] = useState(visibleDuration);\n if (!isEqualDuration(visibleDuration, lastVisibleDuration)) {\n setLastVisibleDuration(visibleDuration);\n setStartDate(getStartDate());\n }\n\n let endDate = useMemo(() => {\n let duration = {...visibleDuration};\n if (duration.days) {\n duration.days--;\n } else {\n duration.days = -1;\n }\n return startDate.add(duration);\n }, [startDate, visibleDuration]);\n\n // Reset focused date and visible range when calendar changes.\n let [lastCalendar, setLastCalendar] = useState(calendar);\n if (!isEqualCalendar(calendar, lastCalendar)) {\n let newFocusedDate = toCalendar(focusedDate, calendar);\n setStartDate(alignCenter(newFocusedDate, visibleDuration, locale, minValue, maxValue));\n setFocusedDate(newFocusedDate);\n setLastCalendar(calendar);\n }\n\n if (isInvalid(focusedDate, minValue, maxValue)) {\n // If the focused date was moved to an invalid value, it can't be focused, so constrain it.\n setFocusedDate(constrainValue(focusedDate, minValue, maxValue));\n } else if (focusedDate.compare(startDate) < 0) {\n setStartDate(alignEnd(focusedDate, visibleDuration, locale, minValue, maxValue));\n } else if (focusedDate.compare(endDate) > 0) {\n setStartDate(alignStart(focusedDate, visibleDuration, locale, minValue, maxValue));\n }\n\n // Sets focus to a specific cell date\n function focusCell(date: CalendarDate) {\n date = constrainValue(date, minValue, maxValue);\n setFocusedDate(date);\n }\n\n function normalizeValue(newValue: CalendarDate) {\n let constrained = constrainValue(newValue, minValue, maxValue);\n let lowerBound = minValue ?? minDate(constrained, startDate);\n let prev = previousAvailableDate(constrained, lowerBound, isDateUnavailable);\n if (!prev) {\n return null;\n }\n\n // The display calendar should not have any effect on the emitted value.\n // Emit dates in the same calendar as the original value, if any, otherwise gregorian.\n let baseValue = Array.isArray(value) ? value[0] : value;\n let calendarValue = toCalendar(prev, baseValue?.calendar || new GregorianCalendar());\n\n // Preserve time if the input value had one.\n if (baseValue && 'hour' in baseValue) {\n return baseValue.set(calendarValue) as T;\n }\n\n return calendarValue as T;\n }\n\n function setValue(newValue: CalendarDate | CalendarDate[] | null) {\n if (!props.isDisabled && !props.isReadOnly) {\n if (newValue === null) {\n setControlledValue(selectionMode === 'multiple' ? [] : null);\n return;\n }\n\n if (Array.isArray(newValue)) {\n setControlledValue(newValue.map(normalizeValue).filter(Boolean) as any);\n } else {\n let localValue = normalizeValue(newValue);\n if (localValue) {\n setControlledValue(localValue as any);\n }\n }\n }\n }\n\n let isUnavailable = useMemo(() => {\n if (!calendarDateValue) {\n return false;\n }\n\n if (Array.isArray(calendarDateValue)) {\n return calendarDateValue.some(\n date => isDateUnavailable?.(date) || isInvalid(date, minValue, maxValue)\n );\n }\n\n return (\n isDateUnavailable?.(calendarDateValue) || isInvalid(calendarDateValue, minValue, maxValue)\n );\n }, [calendarDateValue, isDateUnavailable, minValue, maxValue]);\n let isValueInvalid = props.isInvalid || props.validationState === 'invalid' || isUnavailable;\n let validationState: ValidationState | null = isValueInvalid ? 'invalid' : null;\n\n let pageDuration = useMemo(() => {\n if (pageBehavior === 'visible') {\n return visibleDuration;\n }\n\n return unitDuration(visibleDuration);\n }, [pageBehavior, visibleDuration]);\n\n return {\n isDisabled: props.isDisabled ?? false,\n isReadOnly: props.isReadOnly ?? false,\n value: calendarDateValue as any,\n setValue: setValue as any,\n selectionMode,\n visibleDuration,\n visibleRange: {\n start: startDate,\n end: endDate\n },\n minValue,\n maxValue,\n focusedDate,\n timeZone,\n validationState,\n isValueInvalid,\n setFocusedDate(date) {\n focusCell(date);\n },\n focusNextDay() {\n focusCell(focusedDate.add({days: 1}));\n },\n focusPreviousDay() {\n focusCell(focusedDate.subtract({days: 1}));\n },\n focusNextRow() {\n if (visibleDuration.days) {\n this.focusNextPage();\n } else if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.add({weeks: 1}));\n }\n },\n focusPreviousRow() {\n if (visibleDuration.days) {\n this.focusPreviousPage();\n } else if (visibleDuration.weeks || visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.subtract({weeks: 1}));\n }\n },\n focusNextPage() {\n let start = startDate.add(pageDuration);\n setFocusedDate(constrainValue(focusedDate.add(pageDuration), minValue, maxValue));\n setStartDate(\n alignStart(\n constrainStart(focusedDate, start, pageDuration, locale, minValue, maxValue),\n pageDuration,\n locale\n )\n );\n },\n focusPreviousPage() {\n let start = startDate.subtract(pageDuration);\n setFocusedDate(constrainValue(focusedDate.subtract(pageDuration), minValue, maxValue));\n setStartDate(\n alignStart(\n constrainStart(focusedDate, start, pageDuration, locale, minValue, maxValue),\n pageDuration,\n locale\n )\n );\n },\n focusSectionStart() {\n if (visibleDuration.days) {\n focusCell(startDate);\n } else if (visibleDuration.weeks) {\n focusCell(startOfWeek(focusedDate, locale));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(startOfMonth(focusedDate));\n }\n },\n focusSectionEnd() {\n if (visibleDuration.days) {\n focusCell(endDate);\n } else if (visibleDuration.weeks) {\n focusCell(endOfWeek(focusedDate, locale));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(endOfMonth(focusedDate));\n }\n },\n focusNextSection(larger) {\n if (!larger && !visibleDuration.days) {\n focusCell(focusedDate.add(unitDuration(visibleDuration)));\n return;\n }\n\n if (visibleDuration.days) {\n this.focusNextPage();\n } else if (visibleDuration.weeks) {\n focusCell(focusedDate.add({months: 1}));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.add({years: 1}));\n }\n },\n focusPreviousSection(larger) {\n if (!larger && !visibleDuration.days) {\n focusCell(focusedDate.subtract(unitDuration(visibleDuration)));\n return;\n }\n\n if (visibleDuration.days) {\n this.focusPreviousPage();\n } else if (visibleDuration.weeks) {\n focusCell(focusedDate.subtract({months: 1}));\n } else if (visibleDuration.months || visibleDuration.years) {\n focusCell(focusedDate.subtract({years: 1}));\n }\n },\n selectFocusedDate() {\n if (!(isDateUnavailable && isDateUnavailable(focusedDate))) {\n this.selectDate(focusedDate);\n }\n },\n selectDate(date) {\n if (props.isDisabled || props.isReadOnly) {\n return;\n }\n\n if (selectionMode === 'multiple' && date != null) {\n let newDate = normalizeValue(date);\n if (!newDate) {\n return;\n }\n\n let baseValue: T[] = [];\n if (Array.isArray(value)) {\n baseValue = value;\n } else if (value != null) {\n baseValue = [value];\n }\n\n let index = baseValue.findIndex(value => isSameDay(value, newDate));\n let newValue =\n index >= 0\n ? baseValue.slice(0, index).concat(baseValue.slice(index + 1))\n : [...baseValue, newDate];\n setControlledValue(newValue);\n } else {\n setValue(date);\n }\n },\n isFocused,\n setFocused,\n isInvalid(date) {\n return isInvalid(date, minValue, maxValue);\n },\n isSelected(date) {\n if (!calendarDateValue || this.isCellDisabled(date) || this.isCellUnavailable(date)) {\n return false;\n }\n return Array.isArray(calendarDateValue)\n ? calendarDateValue.some(value => isSameDay(value, date))\n : isSameDay(date, calendarDateValue);\n },\n isCellFocused(date) {\n return isFocused && focusedDate && isSameDay(date, focusedDate);\n },\n isCellDisabled(date) {\n return (\n props.isDisabled ||\n date.compare(startDate) < 0 ||\n date.compare(endDate) > 0 ||\n this.isInvalid(date)\n );\n },\n isCellUnavailable(date) {\n return props.isDateUnavailable ? props.isDateUnavailable(date) : false;\n },\n isPreviousVisibleRangeInvalid() {\n let prev = startDate.subtract({days: 1});\n return isSameDay(prev, startDate) || this.isInvalid(prev);\n },\n isNextVisibleRangeInvalid() {\n // Adding may return the same date if we reached the end of time\n // according to the calendar system (e.g. 9999-12-31).\n let next = endDate.add({days: 1});\n return isSameDay(next, endDate) || this.isInvalid(next);\n },\n getDatesInWeek(weekIndex, from = startDate) {\n let date = from.add({weeks: weekIndex});\n let dates: (CalendarDate | null)[] = [];\n\n let days = visibleDuration.days && visibleDuration.days < 7 ? visibleDuration.days : 7;\n if (days === 7) {\n date = startOfWeek(date, locale, firstDayOfWeek);\n\n // startOfWeek will clamp dates within the calendar system's valid range, which may\n // start in the middle of a week. In this case, add null placeholders.\n let dayOfWeek = getDayOfWeek(date, locale, firstDayOfWeek);\n for (let i = 0; i < dayOfWeek; i++) {\n dates.push(null);\n }\n }\n\n while (dates.length < days) {\n dates.push(date);\n let nextDate = date.add({days: 1});\n if (isSameDay(date, nextDate)) {\n // If the next day is the same, we have hit the end of the calendar system.\n break;\n }\n date = nextDate;\n }\n\n // Add null placeholders if at the end of the calendar system.\n while (dates.length < days) {\n dates.push(null);\n }\n\n return dates;\n },\n getWeeksInMonth(date = startDate) {\n let weeks = weeksInMonth || getWeeksInMonth(date, locale, firstDayOfWeek);\n if (visibleDuration.weeks || visibleDuration.days) {\n weeks = visibleDuration.weeks ?? 0;\n if (visibleDuration.days) {\n weeks += Math.ceil(visibleDuration.days / 7);\n }\n }\n return weeks;\n }\n };\n}\n\nfunction unitDuration(duration: DateDuration) {\n let unit = {...duration};\n for (let key in duration) {\n unit[key] = 1;\n }\n return unit;\n}\n"],"names":[],"version":3,"file":"useCalendarState.mjs.map"}
@@ -14,7 +14,33 @@ $parcel$export(module.exports, "TokenFieldValue", function () { return $8b1d61ca
14
14
  * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
15
15
  * OF ANY KIND, either express or implied. See the License for the specific language
16
16
  * governing permissions and limitations under the License.
17
- */ var $8b1d61ca9a986fd4$var$Direction = /*#__PURE__*/ function(Direction) {
17
+ */ class $8b1d61ca9a986fd4$export$939a711fc6327372 {
18
+ /**
19
+ * Creates a new selection range. If only a single position is provided, the selection is
20
+ * collapsed.
21
+ */ constructor(anchor, current = anchor){
22
+ this.anchor = anchor;
23
+ this.current = current;
24
+ }
25
+ /** Whether the selection is collapsed to a single caret position. */ get isCollapsed() {
26
+ return this.anchor.index === this.current.index && this.anchor.offset === this.current.offset;
27
+ }
28
+ /** The side of the selection closest to the start of the value. */ get start() {
29
+ return $8b1d61ca9a986fd4$var$compare(this.anchor, this.current) < 0 ? this.anchor : this.current;
30
+ }
31
+ /** The side of the selection closest to the end of the value. */ get end() {
32
+ return $8b1d61ca9a986fd4$var$compare(this.anchor, this.current) < 0 ? this.current : this.anchor;
33
+ }
34
+ /** Returns whether this selection is equal to another. */ isEqual(other) {
35
+ if (this === other) return true;
36
+ return this.anchor.index === other.anchor.index && this.anchor.offset === other.anchor.offset && this.current.index === other.current.index && this.current.offset === other.current.offset;
37
+ }
38
+ }
39
+ function $8b1d61ca9a986fd4$var$compare(a, b) {
40
+ if (a.index === b.index) return a.offset - b.offset;
41
+ return a.index - b.index;
42
+ }
43
+ var $8b1d61ca9a986fd4$var$Direction = /*#__PURE__*/ function(Direction) {
18
44
  Direction[Direction["Forward"] = 1] = "Forward";
19
45
  Direction[Direction["Backward"] = -1] = "Backward";
20
46
  return Direction;
@@ -23,34 +49,39 @@ class $8b1d61ca9a986fd4$export$f3decd0c2cd2fe2e {
23
49
  static{
24
50
  this.Direction = $8b1d61ca9a986fd4$var$Direction;
25
51
  }
52
+ static{
53
+ this.SelectedRange = $8b1d61ca9a986fd4$export$939a711fc6327372;
54
+ }
26
55
  /** Create a new list with the given segments. */ constructor(tokens, options){
27
- /** The caret position. */ this.caretPosition = {
28
- index: 0,
29
- offset: 0
30
- };
31
56
  // Linked list representing the undo/redo history.
32
57
  this.previous = null;
33
58
  this.next = null;
34
59
  this.isCoalescing = true;
35
60
  this.segments = tokens;
36
- this.caretPosition = options?.caretPosition ?? {
61
+ this.selectedRange = options?.selectedRange ?? new $8b1d61ca9a986fd4$export$939a711fc6327372({
37
62
  index: 0,
38
63
  offset: 0
39
- };
64
+ });
40
65
  }
41
66
  createFieldValue(segments) {
42
67
  const Constructor = this.constructor;
43
68
  return new Constructor(segments);
44
69
  }
45
- /** Create a new list with the caret position set to the given position. */ withCaretPosition(caretPosition) {
46
- if (this.caretPosition.index === caretPosition.index && this.caretPosition.offset === caretPosition.offset) return this;
70
+ get caretPosition() {
71
+ return this.selectedRange.current;
72
+ }
73
+ /** Create a new list with the caret position set to the given position. */ withSelectedRange(selectedRange) {
74
+ if (this.selectedRange.isEqual(selectedRange)) return this;
47
75
  let result = this.createFieldValue(this.segments);
48
- result.caretPosition = caretPosition;
76
+ result.selectedRange = selectedRange;
49
77
  result.previous = this.previous;
50
78
  result.next = this.next;
51
79
  result.isCoalescing = this.isCoalescing;
52
80
  return result;
53
81
  }
82
+ withCaretPosition(position) {
83
+ return this.withSelectedRange(new $8b1d61ca9a986fd4$export$939a711fc6327372(position));
84
+ }
54
85
  splitSegment(segment, offset) {
55
86
  if (!segment) {
56
87
  let empty = this.createTextSegment('');
@@ -125,14 +156,14 @@ class $8b1d61ca9a986fd4$export$f3decd0c2cd2fe2e {
125
156
  ]);
126
157
  $8b1d61ca9a986fd4$var$appendSegments(newSegments, this.segments.slice(end.index + 1));
127
158
  let segments = this.createFieldValue(newSegments);
128
- segments.caretPosition = caret;
159
+ segments.selectedRange = new $8b1d61ca9a986fd4$export$939a711fc6327372(caret);
129
160
  segments.isCoalescing = coalesce;
130
161
  if (this.isCoalescing && coalesce && this.previous) {
131
162
  segments.previous = this.previous;
132
163
  segments.previous.next = segments;
133
164
  } else {
134
165
  segments.previous = this;
135
- this.caretPosition = end;
166
+ this.selectedRange = new $8b1d61ca9a986fd4$export$939a711fc6327372(start, end);
136
167
  this.next = segments;
137
168
  }
138
169
  return segments;
@@ -199,14 +230,13 @@ class $8b1d61ca9a986fd4$export$f3decd0c2cd2fe2e {
199
230
  /** Delete text at a position using a segmenter. */ delete(position, segmenter, direction, coalesce = true) {
200
231
  let boundary = this.findBoundaryWithSegmenter(position, segmenter, direction);
201
232
  if (boundary) return this.replaceRange(direction === -1 ? boundary : position, direction === -1 ? position : boundary, '', coalesce);
202
- this.caretPosition = position;
203
- return this;
233
+ return this.withSelectedRange(new $8b1d61ca9a986fd4$export$939a711fc6327372(position));
204
234
  }
205
235
  /** Delete text to the next or previous line break. */ deleteLine(position, direction, coalesce = true) {
206
236
  if (this.segments.length === 0) return this;
207
237
  let boundary = this.findLineBoundary(position, direction);
208
238
  if (boundary) return this.replaceRange(direction === -1 ? boundary : position, direction === -1 ? position : boundary, '', coalesce);
209
- return this;
239
+ return this.withSelectedRange(new $8b1d61ca9a986fd4$export$939a711fc6327372(position));
210
240
  }
211
241
  /** Create a new list containing a subset of the segments. */ slice(start, end) {
212
242
  start = this.clampPosition(start);