@react-stately/calendar 3.8.4 → 3.9.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.
package/dist/types.d.ts CHANGED
@@ -124,7 +124,10 @@ export interface CalendarStateOptions<T extends DateValue = DateValue> extends C
124
124
  * @default {months: 1}
125
125
  */
126
126
  visibleDuration?: DateDuration;
127
- /** Determines how to align the initial selection relative to the visible date range. */
127
+ /**
128
+ * Determines the alignment of the visible months on initial render based on the current selection or current date if there is no selection.
129
+ * @default 'center'
130
+ */
128
131
  selectionAlignment?: 'start' | 'center' | 'end';
129
132
  }
130
133
  /**
@@ -147,6 +150,11 @@ export interface RangeCalendarStateOptions<T extends DateValue = DateValue> exte
147
150
  * @default {months: 1}
148
151
  */
149
152
  visibleDuration?: DateDuration;
153
+ /**
154
+ * Determines the alignment of the visible months on initial render based on the current selection or current date if there is no selection.
155
+ * @default 'center'
156
+ */
157
+ selectionAlignment?: 'start' | 'center' | 'end';
150
158
  }
151
159
  /**
152
160
  * Provides state management for a range calendar component.
@@ -1 +1 @@
1
- {"mappings":";;;ACgBA;IACE,wCAAwC;IACxC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,oDAAoD;IACpD,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,gEAAgE;IAChE,QAAQ,CAAC,YAAY,EAAE,WAAW,YAAY,CAAC,CAAC;IAChD,uDAAuD;IACvD,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;IACrC,uDAAuD;IACvD,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;IACrC,4DAA4D;IAC5D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,eAAe,EAAE,eAAe,GAAG,IAAI,CAAC;IACjD,uCAAuC;IACvC,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC;IACjC,kC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AAc,EAAE,CAAC,IAAI,EAAE,kBAAkB,KAAK,QAAQ,CAAC;IACvD;;;OAGG;IACH,eAAe,CAAC,EAAE,YAAY,CAAC;IAC/B,wFAAwF;IACxF,kBAAkB,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAA;CAChD;AACD;;;GAGG;AACH,iCAAiC,CAAC,SAAS,SAAS,GAAG,SAAS,EAAE,KAAK,EAAE,qBAAqB,CAAC,CAAC,GAAG,aAAa,CA8S/G;ACpVD,2CAA2C,CAAC,SAAS,SAAS,GAAG,SAAS,CAAE,SAAQ,mBAAmB,CAAC,CAAC;IACvG,6DAA6D;IAC7D,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,cAAc,EAAE,CAAC,IAAI,EAAE,kBAAkB,KAAK,QAAQ,CAAC;IACvD;;;OAGG;IACH,eAAe,CAAC,EAAE,YAAY,CAAA;CAC/B;AAED;;;GAGG;AACH,sCAAsC,CAAC,SAAS,SAAS,GAAG,SAAS,EAAE,KAAK,EAAE,0BAA0B,CAAC,CAAC,GAAG,kBAAkB,CA2I9H","sources":["packages/@react-stately/calendar/src/packages/@react-stately/calendar/src/utils.ts","packages/@react-stately/calendar/src/packages/@react-stately/calendar/src/types.ts","packages/@react-stately/calendar/src/packages/@react-stately/calendar/src/useCalendarState.ts","packages/@react-stately/calendar/src/packages/@react-stately/calendar/src/useRangeCalendarState.ts","packages/@react-stately/calendar/src/packages/@react-stately/calendar/src/index.ts","packages/@react-stately/calendar/src/index.ts"],"sourcesContent":[null,null,null,null,null,"/*\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\nexport {useCalendarState} from './useCalendarState';\nexport {useRangeCalendarState} from './useRangeCalendarState';\n\nexport type {CalendarStateOptions} from './useCalendarState';\nexport type {RangeCalendarStateOptions} from './useRangeCalendarState';\nexport type {CalendarState, RangeCalendarState} from './types'; \n"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";;;ACgBA;IACE,wCAAwC;IACxC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,oDAAoD;IACpD,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,gEAAgE;IAChE,QAAQ,CAAC,YAAY,EAAE,WAAW,YAAY,CAAC,CAAC;IAChD,uDAAuD;IACvD,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;IACrC,uDAAuD;IACvD,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;IACrC,4DAA4D;IAC5D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,eAAe,EAAE,eAAe,GAAG,IAAI,CAAC;IACjD,uCAAuC;IACvC,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC;IACjC,kCAAkC;IAClC,QAAQ,CAAC,WAAW,EAAE,YAAY,CAAC;IACnC,6BAA6B;IAC7B,cAAc,CAAC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;IAC1C,6CAA6C;IAC7C,YAAY,IAAI,IAAI,CAAC;IACrB,iDAAiD;IACjD,gBAAgB,IAAI,IAAI,CAAC;IACzB,gEAAgE;IAChE,YAAY,IAAI,IAAI,CAAC;IACrB,wEAAwE;IACxE,gBAAgB,IAAI,IAAI,CAAC;IACzB,0FAA0F;IAC1F,aAAa,IAAI,IAAI,CAAC;IACtB,kGAAkG;IAClG,iBAAiB,IAAI,IAAI,CAAC;IAC1B,qGAAqG;IACrG,iBAAiB,IAAI,IAAI,CAAC;IAC1B,uGAAuG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AE,CAAC,IAAI,EAAE,kBAAkB,KAAK,QAAQ,CAAC;IACvD;;;OAGG;IACH,eAAe,CAAC,EAAE,YAAY,CAAC;IAC/B;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAA;CAChD;AAED;;;GAGG;AACH,sCAAsC,CAAC,SAAS,SAAS,GAAG,SAAS,EAAE,KAAK,EAAE,0BAA0B,CAAC,CAAC,GAAG,kBAAkB,CAoJ9H","sources":["packages/@react-stately/calendar/src/packages/@react-stately/calendar/src/utils.ts","packages/@react-stately/calendar/src/packages/@react-stately/calendar/src/types.ts","packages/@react-stately/calendar/src/packages/@react-stately/calendar/src/useCalendarState.ts","packages/@react-stately/calendar/src/packages/@react-stately/calendar/src/useRangeCalendarState.ts","packages/@react-stately/calendar/src/packages/@react-stately/calendar/src/index.ts","packages/@react-stately/calendar/src/index.ts"],"sourcesContent":[null,null,null,null,null,"/*\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\nexport {useCalendarState} from './useCalendarState';\nexport {useRangeCalendarState} from './useRangeCalendarState';\n\nexport type {CalendarStateOptions} from './useCalendarState';\nexport type {RangeCalendarStateOptions} from './useRangeCalendarState';\nexport type {CalendarState, RangeCalendarState} from './types'; \n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAiDM,SAAS,0CAAkD,KAA8B;IAC9F,IAAI,mBAAmB,CAAA,GAAA,oBAAM,EAAE,IAAM,IAAI,CAAA,GAAA,0CAA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M,IAAI,CAAC;YAGb,MAAO,MAAM,MAAM,GAAG,EAAG;gBACvB,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,EACpB,MAAM,IAAI,CAAC;YAGb,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/calendar/src/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 {alignCenter, alignEnd, alignStart, constrainStart, constrainValue, isInvalid, previousAvailableDate} from './utils';\nimport {\n Calendar,\n CalendarDate,\n CalendarIdentifier,\n DateDuration,\n DateFormatter,\n endOfMonth,\n endOfWeek,\n getDayOfWeek,\n GregorianCalendar,\n isEqualCalendar,\n isSameDay,\n startOfMonth,\n startOfWeek,\n toCalendar,\n toCalendarDate,\n today\n} from '@internationalized/date';\nimport {CalendarProps, DateValue, MappedDateValue} from '@react-types/calendar';\nimport {CalendarState} from './types';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useState} from 'react';\nimport {ValidationState} from '@react-types/shared';\n\nexport interface CalendarStateOptions<T extends DateValue = DateValue> extends CalendarProps<T> {\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 * @default {months: 1}\n */\n visibleDuration?: DateDuration,\n /** Determines how to align the initial selection relative to the visible date range. */\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<T extends DateValue = DateValue>(props: CalendarStateOptions<T>): CalendarState {\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 firstDayOfWeek\n } = props;\n let calendar = useMemo(() => createCalendar(resolvedOptions.calendar as CalendarIdentifier), [createCalendar, resolvedOptions.calendar]);\n\n let [value, setControlledValue] = useControlledState<DateValue | null, MappedDateValue<T>>(props.value!, props.defaultValue ?? null!, props.onChange);\n let calendarDateValue = useMemo(() => value ? toCalendar(toCalendarDate(value), calendar) : null, [value, calendar]);\n let timeZone = useMemo(() => value && 'timeZone' in value ? value.timeZone : resolvedOptions.timeZone, [value, resolvedOptions.timeZone]);\n let focusedCalendarDate = useMemo(() => (\n props.focusedValue\n ? constrainValue(toCalendar(toCalendarDate(props.focusedValue), calendar), minValue, maxValue)\n : undefined\n ), [props.focusedValue, calendar, minValue, maxValue]);\n let defaultFocusedCalendarDate = useMemo(() => (\n constrainValue(\n props.defaultFocusedValue\n ? toCalendar(toCalendarDate(props.defaultFocusedValue), calendar)\n : calendarDateValue || toCalendar(today(timeZone), calendar),\n minValue,\n maxValue\n )\n ), [props.defaultFocusedValue, calendarDateValue, timeZone, calendar, minValue, maxValue]);\n let [focusedDate, setFocusedDate] = useControlledState(focusedCalendarDate, defaultFocusedCalendarDate, props.onFocusChange);\n let [startDate, setStartDate] = useState(() => {\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 let [isFocused, setFocused] = useState(props.autoFocus || false);\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 setValue(newValue: CalendarDate | null) {\n if (!props.isDisabled && !props.isReadOnly) {\n let localValue = newValue;\n if (localValue === null) {\n setControlledValue(null);\n return;\n }\n localValue = constrainValue(localValue, minValue, maxValue);\n localValue = previousAvailableDate(localValue, startDate, isDateUnavailable);\n if (!localValue) {\n return;\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 localValue = toCalendar(localValue, value?.calendar || new GregorianCalendar());\n\n // Preserve time if the input value had one.\n if (value && 'hour' in value) {\n setControlledValue(value.set(localValue));\n } else {\n setControlledValue(localValue);\n }\n }\n }\n\n let isUnavailable = useMemo(() => {\n if (!calendarDateValue) {\n return false;\n }\n\n if (isDateUnavailable && isDateUnavailable(calendarDateValue)) {\n return true;\n }\n\n return isInvalid(calendarDateValue, minValue, maxValue);\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,\n setValue,\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 setFocused(true);\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 setValue(focusedDate);\n }\n },\n selectDate(date) {\n setValue(date);\n },\n isFocused,\n setFocused,\n isInvalid(date) {\n return isInvalid(date, minValue, maxValue);\n },\n isSelected(date) {\n return calendarDateValue != null && isSameDay(date, calendarDateValue) && !this.isCellDisabled(date) && !this.isCellUnavailable(date);\n },\n isCellFocused(date) {\n return isFocused && focusedDate && isSameDay(date, focusedDate);\n },\n isCellDisabled(date) {\n return props.isDisabled || date.compare(startDate) < 0 || date.compare(endDate) > 0 || this.isInvalid(date);\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 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 while (dates.length < 7) {\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 < 7) {\n dates.push(null);\n }\n\n return dates;\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.main.js.map"}
1
+ {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAoDM,SAAS,0CAAkD,KAA8B;IAC9F,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,I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,CAAA,GAAA,sCAAQ,EAAE,MAAM,WAElB;gBAEF,OAAO;YACT;YAEA,8DAA8D;YAC9D,MAAO,MAAM,MAAM,GAAG,EACpB,MAAM,IAAI,CAAC;YAGb,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/calendar/src/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 {alignCenter, alignEnd, alignStart, constrainStart, constrainValue, isInvalid, previousAvailableDate} from './utils';\nimport {\n Calendar,\n CalendarDate,\n CalendarIdentifier,\n DateDuration,\n DateFormatter,\n endOfMonth,\n endOfWeek,\n getDayOfWeek,\n GregorianCalendar,\n isEqualCalendar,\n isSameDay,\n startOfMonth,\n startOfWeek,\n toCalendar,\n toCalendarDate,\n today\n} from '@internationalized/date';\nimport {CalendarProps, DateValue, MappedDateValue} from '@react-types/calendar';\nimport {CalendarState} from './types';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useState} from 'react';\nimport {ValidationState} from '@react-types/shared';\n\nexport interface CalendarStateOptions<T extends DateValue = DateValue> extends CalendarProps<T> {\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 * @default {months: 1}\n */\n visibleDuration?: DateDuration,\n /** \n * Determines the alignment of the visible months on initial render based on the current selection or current date if there is no selection. \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<T extends DateValue = DateValue>(props: CalendarStateOptions<T>): CalendarState {\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 firstDayOfWeek\n } = props;\n let calendar = useMemo(() => createCalendar(resolvedOptions.calendar as CalendarIdentifier), [createCalendar, resolvedOptions.calendar]);\n\n let [value, setControlledValue] = useControlledState<DateValue | null, MappedDateValue<T>>(props.value!, props.defaultValue ?? null!, props.onChange);\n let calendarDateValue = useMemo(() => value ? toCalendar(toCalendarDate(value), calendar) : null, [value, calendar]);\n let timeZone = useMemo(() => value && 'timeZone' in value ? value.timeZone : resolvedOptions.timeZone, [value, resolvedOptions.timeZone]);\n let focusedCalendarDate = useMemo(() => (\n props.focusedValue\n ? constrainValue(toCalendar(toCalendarDate(props.focusedValue), calendar), minValue, maxValue)\n : undefined\n ), [props.focusedValue, calendar, minValue, maxValue]);\n let defaultFocusedCalendarDate = useMemo(() => (\n constrainValue(\n props.defaultFocusedValue\n ? toCalendar(toCalendarDate(props.defaultFocusedValue), calendar)\n : calendarDateValue || toCalendar(today(timeZone), calendar),\n minValue,\n maxValue\n )\n ), [props.defaultFocusedValue, calendarDateValue, timeZone, calendar, minValue, maxValue]);\n let [focusedDate, setFocusedDate] = useControlledState(focusedCalendarDate, defaultFocusedCalendarDate, props.onFocusChange);\n let [startDate, setStartDate] = useState(() => {\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 let [isFocused, setFocused] = useState(props.autoFocus || false);\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 setValue(newValue: CalendarDate | null) {\n if (!props.isDisabled && !props.isReadOnly) {\n let localValue = newValue;\n if (localValue === null) {\n setControlledValue(null);\n return;\n }\n localValue = constrainValue(localValue, minValue, maxValue);\n localValue = previousAvailableDate(localValue, startDate, isDateUnavailable);\n if (!localValue) {\n return;\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 localValue = toCalendar(localValue, value?.calendar || new GregorianCalendar());\n\n // Preserve time if the input value had one.\n if (value && 'hour' in value) {\n setControlledValue(value.set(localValue));\n } else {\n setControlledValue(localValue);\n }\n }\n }\n\n let isUnavailable = useMemo(() => {\n if (!calendarDateValue) {\n return false;\n }\n\n if (isDateUnavailable && isDateUnavailable(calendarDateValue)) {\n return true;\n }\n\n return isInvalid(calendarDateValue, minValue, maxValue);\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,\n setValue,\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 setFocused(true);\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 setValue(focusedDate);\n }\n },\n selectDate(date) {\n setValue(date);\n },\n isFocused,\n setFocused,\n isInvalid(date) {\n return isInvalid(date, minValue, maxValue);\n },\n isSelected(date) {\n return calendarDateValue != null && isSameDay(date, calendarDateValue) && !this.isCellDisabled(date) && !this.isCellUnavailable(date);\n },\n isCellFocused(date) {\n return isFocused && focusedDate && isSameDay(date, focusedDate);\n },\n isCellDisabled(date) {\n return props.isDisabled || date.compare(startDate) < 0 || date.compare(endDate) > 0 || this.isInvalid(date);\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 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 while (dates.length < 7) {\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 < 7) {\n dates.push(null);\n }\n\n return dates;\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.main.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AAiDM,SAAS,0CAAkD,KAA8B;IAC9F,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,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AC;YAGb,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/calendar/src/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 {alignCenter, alignEnd, alignStart, constrainStart, constrainValue, isInvalid, previousAvailableDate} from './utils';\nimport {\n Calendar,\n CalendarDate,\n CalendarIdentifier,\n DateDuration,\n DateFormatter,\n endOfMonth,\n endOfWeek,\n getDayOfWeek,\n GregorianCalendar,\n isEqualCalendar,\n isSameDay,\n startOfMonth,\n startOfWeek,\n toCalendar,\n toCalendarDate,\n today\n} from '@internationalized/date';\nimport {CalendarProps, DateValue, MappedDateValue} from '@react-types/calendar';\nimport {CalendarState} from './types';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useState} from 'react';\nimport {ValidationState} from '@react-types/shared';\n\nexport interface CalendarStateOptions<T extends DateValue = DateValue> extends CalendarProps<T> {\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 * @default {months: 1}\n */\n visibleDuration?: DateDuration,\n /** Determines how to align the initial selection relative to the visible date range. */\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<T extends DateValue = DateValue>(props: CalendarStateOptions<T>): CalendarState {\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 firstDayOfWeek\n } = props;\n let calendar = useMemo(() => createCalendar(resolvedOptions.calendar as CalendarIdentifier), [createCalendar, resolvedOptions.calendar]);\n\n let [value, setControlledValue] = useControlledState<DateValue | null, MappedDateValue<T>>(props.value!, props.defaultValue ?? null!, props.onChange);\n let calendarDateValue = useMemo(() => value ? toCalendar(toCalendarDate(value), calendar) : null, [value, calendar]);\n let timeZone = useMemo(() => value && 'timeZone' in value ? value.timeZone : resolvedOptions.timeZone, [value, resolvedOptions.timeZone]);\n let focusedCalendarDate = useMemo(() => (\n props.focusedValue\n ? constrainValue(toCalendar(toCalendarDate(props.focusedValue), calendar), minValue, maxValue)\n : undefined\n ), [props.focusedValue, calendar, minValue, maxValue]);\n let defaultFocusedCalendarDate = useMemo(() => (\n constrainValue(\n props.defaultFocusedValue\n ? toCalendar(toCalendarDate(props.defaultFocusedValue), calendar)\n : calendarDateValue || toCalendar(today(timeZone), calendar),\n minValue,\n maxValue\n )\n ), [props.defaultFocusedValue, calendarDateValue, timeZone, calendar, minValue, maxValue]);\n let [focusedDate, setFocusedDate] = useControlledState(focusedCalendarDate, defaultFocusedCalendarDate, props.onFocusChange);\n let [startDate, setStartDate] = useState(() => {\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 let [isFocused, setFocused] = useState(props.autoFocus || false);\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 setValue(newValue: CalendarDate | null) {\n if (!props.isDisabled && !props.isReadOnly) {\n let localValue = newValue;\n if (localValue === null) {\n setControlledValue(null);\n return;\n }\n localValue = constrainValue(localValue, minValue, maxValue);\n localValue = previousAvailableDate(localValue, startDate, isDateUnavailable);\n if (!localValue) {\n return;\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 localValue = toCalendar(localValue, value?.calendar || new GregorianCalendar());\n\n // Preserve time if the input value had one.\n if (value && 'hour' in value) {\n setControlledValue(value.set(localValue));\n } else {\n setControlledValue(localValue);\n }\n }\n }\n\n let isUnavailable = useMemo(() => {\n if (!calendarDateValue) {\n return false;\n }\n\n if (isDateUnavailable && isDateUnavailable(calendarDateValue)) {\n return true;\n }\n\n return isInvalid(calendarDateValue, minValue, maxValue);\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,\n setValue,\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 setFocused(true);\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 setValue(focusedDate);\n }\n },\n selectDate(date) {\n setValue(date);\n },\n isFocused,\n setFocused,\n isInvalid(date) {\n return isInvalid(date, minValue, maxValue);\n },\n isSelected(date) {\n return calendarDateValue != null && isSameDay(date, calendarDateValue) && !this.isCellDisabled(date) && !this.isCellUnavailable(date);\n },\n isCellFocused(date) {\n return isFocused && focusedDate && isSameDay(date, focusedDate);\n },\n isCellDisabled(date) {\n return props.isDisabled || date.compare(startDate) < 0 || date.compare(endDate) > 0 || this.isInvalid(date);\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 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 while (dates.length < 7) {\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 < 7) {\n dates.push(null);\n }\n\n return dates;\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.module.js.map"}
1
+ {"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AAoDM,SAAS,0CAAkD,KAA8B;IAC9F,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,2BACf,cAAc,EACf,GAAG;IACJ,IAAI,WAAW,CAAA,GAAA,cAAM,EAAE,IAAM,eAAe,gBAAgB,QAAQ,GAAyB;QAAC;QAAgB,gBAAgB,QAAQ;KAAC;QAE9B;IAAz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T","sources":["packages/@react-stately/calendar/src/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 {alignCenter, alignEnd, alignStart, constrainStart, constrainValue, isInvalid, previousAvailableDate} from './utils';\nimport {\n Calendar,\n CalendarDate,\n CalendarIdentifier,\n DateDuration,\n DateFormatter,\n endOfMonth,\n endOfWeek,\n getDayOfWeek,\n GregorianCalendar,\n isEqualCalendar,\n isSameDay,\n startOfMonth,\n startOfWeek,\n toCalendar,\n toCalendarDate,\n today\n} from '@internationalized/date';\nimport {CalendarProps, DateValue, MappedDateValue} from '@react-types/calendar';\nimport {CalendarState} from './types';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useState} from 'react';\nimport {ValidationState} from '@react-types/shared';\n\nexport interface CalendarStateOptions<T extends DateValue = DateValue> extends CalendarProps<T> {\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 * @default {months: 1}\n */\n visibleDuration?: DateDuration,\n /** \n * Determines the alignment of the visible months on initial render based on the current selection or current date if there is no selection. \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<T extends DateValue = DateValue>(props: CalendarStateOptions<T>): CalendarState {\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 firstDayOfWeek\n } = props;\n let calendar = useMemo(() => createCalendar(resolvedOptions.calendar as CalendarIdentifier), [createCalendar, resolvedOptions.calendar]);\n\n let [value, setControlledValue] = useControlledState<DateValue | null, MappedDateValue<T>>(props.value!, props.defaultValue ?? null!, props.onChange);\n let calendarDateValue = useMemo(() => value ? toCalendar(toCalendarDate(value), calendar) : null, [value, calendar]);\n let timeZone = useMemo(() => value && 'timeZone' in value ? value.timeZone : resolvedOptions.timeZone, [value, resolvedOptions.timeZone]);\n let focusedCalendarDate = useMemo(() => (\n props.focusedValue\n ? constrainValue(toCalendar(toCalendarDate(props.focusedValue), calendar), minValue, maxValue)\n : undefined\n ), [props.focusedValue, calendar, minValue, maxValue]);\n let defaultFocusedCalendarDate = useMemo(() => (\n constrainValue(\n props.defaultFocusedValue\n ? toCalendar(toCalendarDate(props.defaultFocusedValue), calendar)\n : calendarDateValue || toCalendar(today(timeZone), calendar),\n minValue,\n maxValue\n )\n ), [props.defaultFocusedValue, calendarDateValue, timeZone, calendar, minValue, maxValue]);\n let [focusedDate, setFocusedDate] = useControlledState(focusedCalendarDate, defaultFocusedCalendarDate, props.onFocusChange);\n let [startDate, setStartDate] = useState(() => {\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 let [isFocused, setFocused] = useState(props.autoFocus || false);\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 setValue(newValue: CalendarDate | null) {\n if (!props.isDisabled && !props.isReadOnly) {\n let localValue = newValue;\n if (localValue === null) {\n setControlledValue(null);\n return;\n }\n localValue = constrainValue(localValue, minValue, maxValue);\n localValue = previousAvailableDate(localValue, startDate, isDateUnavailable);\n if (!localValue) {\n return;\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 localValue = toCalendar(localValue, value?.calendar || new GregorianCalendar());\n\n // Preserve time if the input value had one.\n if (value && 'hour' in value) {\n setControlledValue(value.set(localValue));\n } else {\n setControlledValue(localValue);\n }\n }\n }\n\n let isUnavailable = useMemo(() => {\n if (!calendarDateValue) {\n return false;\n }\n\n if (isDateUnavailable && isDateUnavailable(calendarDateValue)) {\n return true;\n }\n\n return isInvalid(calendarDateValue, minValue, maxValue);\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,\n setValue,\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 setFocused(true);\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 setValue(focusedDate);\n }\n },\n selectDate(date) {\n setValue(date);\n },\n isFocused,\n setFocused,\n isInvalid(date) {\n return isInvalid(date, minValue, maxValue);\n },\n isSelected(date) {\n return calendarDateValue != null && isSameDay(date, calendarDateValue) && !this.isCellDisabled(date) && !this.isCellUnavailable(date);\n },\n isCellFocused(date) {\n return isFocused && focusedDate && isSameDay(date, focusedDate);\n },\n isCellDisabled(date) {\n return props.isDisabled || date.compare(startDate) < 0 || date.compare(endDate) > 0 || this.isInvalid(date);\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 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 while (dates.length < 7) {\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 < 7) {\n dates.push(null);\n }\n\n return dates;\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.module.js.map"}
@@ -58,7 +58,7 @@ function $e49f7b861e5e8049$export$9a987164d97ecc90(props) {
58
58
  visibleDuration: visibleDuration,
59
59
  minValue: min,
60
60
  maxValue: max,
61
- selectionAlignment: alignment
61
+ selectionAlignment: props.selectionAlignment || alignment
62
62
  });
63
63
  let updateAvailableRange = (date)=>{
64
64
  if (date && props.isDateUnavailable && !props.allowsNonContiguousRanges) {
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAgCM,SAAS,0CAAuD,KAAmC;IACxG,IAAI,EAAC,OAAO,SAAS,gBAAE,YAAY,YAAE,QAAQ,kBAAE,cAAc,UAAE,MAAM,mBAAE,kBAAkB;QAAC,QAAQ;IAAC,aAAG,QAAQ,YAAE,QAAQ,EAAE,GAAG,eAAc,GAAG;IAC9I,IAAI,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,2CAAiB,EACvC,WACA,gBAAgB,MAChB;IAGF,IAAI,CAAC,YAAY,mBAAmB,GAAG,CAAA,GAAA,qBAAO,EAAuB;IACrE,IAAI,YAAgC;IACpC,IAAI,SAAS,MAAM,KAAK,IAAI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UAAU,CAAA,qBAAA,+BAAA,SAAU,QAAQ,KAAI,IAAI,CAAA,GAAA,8CAAgB;IAE1E,4CAA4C;IAC5C,IAAI,YAAY,UAAU,UACxB,OAAO,SAAS,GAAG,CAAC;IAGtB,OAAO;AACT;AAEA,SAAS,0CAAoB,UAAwB,EAAE,KAAoB,EAAE,GAAW;IACtF,IAAI,WAAW,WAAW,GAAG,CAAC;QAAC,MAAM;IAAG;IACxC,MACE,AAAC,CAAA,MAAM,IAAI,SAAS,OAAO,CAAC,MAAM,YAAY,CAAC,KAAK,KAAK,IAAI,SAAS,OAAO,CAAC,MAAM,YAAY,CAAC,GAAG,KAAK,CAAA,KACzG,CAAC,MAAM,iBAAiB,CAAC,UAEzB,WAAW,SAAS,GAAG,CAAC;QAAC,MAAM;IAAG;IAGpC,IAAI,MAAM,iBAAiB,CAAC,WAC1B,OAAO,SAAS,GAAG,CAAC;QAAC,MAAM,CAAC;IAAG;AAGnC","sources":["packages/@react-stately/calendar/src/useRangeCalendarState.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 {alignCenter, constrainValue, isInvalid, previousAvailableDate} from './utils';\nimport {Calendar, CalendarDate, CalendarIdentifier, DateDuration, GregorianCalendar, isEqualDay, maxDate, minDate, toCalendar, toCalendarDate} from '@internationalized/date';\nimport {CalendarState, RangeCalendarState} from './types';\nimport {DateValue, MappedDateValue, RangeCalendarProps} from '@react-types/calendar';\nimport {RangeValue, ValidationState} from '@react-types/shared';\nimport {useCalendarState} from './useCalendarState';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useRef, useState} from 'react';\n\nexport interface RangeCalendarStateOptions<T extends DateValue = DateValue> extends RangeCalendarProps<T> {\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 * @default {months: 1}\n */\n visibleDuration?: DateDuration\n}\n\n/**\n * Provides state management for a range calendar component.\n * A range calendar displays one or more date grids and allows users to select a contiguous range of dates.\n */\nexport function useRangeCalendarState<T extends DateValue = DateValue>(props: RangeCalendarStateOptions<T>): RangeCalendarState {\n let {value: valueProp, defaultValue, onChange, createCalendar, locale, visibleDuration = {months: 1}, minValue, maxValue, ...calendarProps} = props;\n let [value, setValue] = useControlledState<RangeValue<T> | null, RangeValue<MappedDateValue<T>>>(\n valueProp!,\n defaultValue || null!,\n onChange\n );\n\n let [anchorDate, setAnchorDateState] = useState<CalendarDate | null>(null);\n let alignment: 'center' | 'start' = 'center';\n if (value && value.start && value.end) {\n let start = alignCenter(toCalendarDate(value.start), visibleDuration, locale, minValue, maxValue);\n let end = start.add(visibleDuration).subtract({days: 1});\n\n if (value.end.compare(end) > 0) {\n alignment = 'start';\n }\n }\n\n // Available range must be stored in a ref so we have access to the updated version immediately in `isInvalid`.\n let availableRangeRef = useRef<Partial<RangeValue<DateValue>> | null>(null);\n let [availableRange, setAvailableRange] = useState<Partial<RangeValue<DateValue>>|null>(null);\n let min = useMemo(() => maxDate(minValue, availableRange?.start), [minValue, availableRange]);\n let max = useMemo(() => minDate(maxValue, availableRange?.end), [maxValue, availableRange]);\n\n let calendar = useCalendarState({\n ...calendarProps,\n value: value && value.start,\n createCalendar,\n locale,\n visibleDuration,\n minValue: min,\n maxValue: max,\n selectionAlignment: alignment\n });\n\n let updateAvailableRange = (date) => {\n if (date && props.isDateUnavailable && !props.allowsNonContiguousRanges) {\n const nextAvailableStartDate = nextUnavailableDate(date, calendar, -1);\n const nextAvailableEndDate = nextUnavailableDate(date, calendar, 1);\n availableRangeRef.current = {\n start: nextAvailableStartDate,\n end: nextAvailableEndDate\n };\n setAvailableRange(availableRangeRef.current);\n } else {\n availableRangeRef.current = null;\n setAvailableRange(null);\n }\n };\n\n // If the visible range changes, we need to update the available range.\n let [lastVisibleRange, setLastVisibleRange] = useState(calendar.visibleRange);\n if (!isEqualDay(calendar.visibleRange.start, lastVisibleRange.start) || !isEqualDay(calendar.visibleRange.end, lastVisibleRange.end)) {\n updateAvailableRange(anchorDate);\n setLastVisibleRange(calendar.visibleRange);\n }\n\n let setAnchorDate = (date: CalendarDate | null) => {\n if (date) {\n setAnchorDateState(date);\n updateAvailableRange(date);\n } else {\n setAnchorDateState(null);\n updateAvailableRange(null);\n }\n };\n\n let highlightedRange = anchorDate ? makeRange(anchorDate, calendar.focusedDate) : value && makeRange(value.start, value.end);\n let selectDate = (date: CalendarDate) => {\n if (props.isReadOnly) {\n return;\n }\n\n const constrainedDate = constrainValue(date, min, max);\n const previousAvailableConstrainedDate = previousAvailableDate(constrainedDate, calendar.visibleRange.start, props.isDateUnavailable);\n if (!previousAvailableConstrainedDate) {\n return;\n }\n\n if (!anchorDate) {\n setAnchorDate(previousAvailableConstrainedDate);\n } else {\n let range = makeRange(anchorDate, previousAvailableConstrainedDate);\n if (range) {\n setValue({\n start: convertValue(range.start, value?.start) as T,\n end: convertValue(range.end, value?.end) as T\n });\n }\n setAnchorDate(null);\n }\n };\n\n let [isDragging, setDragging] = useState(false);\n\n let {isDateUnavailable} = props;\n let isInvalidSelection = useMemo(() => {\n if (!value || anchorDate) {\n return false;\n }\n\n if (isDateUnavailable && (isDateUnavailable(value.start) || isDateUnavailable(value.end))) {\n return true;\n }\n\n return isInvalid(value.start, minValue, maxValue) || isInvalid(value.end, minValue, maxValue);\n }, [isDateUnavailable, value, anchorDate, minValue, maxValue]);\n\n let isValueInvalid = props.isInvalid || props.validationState === 'invalid' || isInvalidSelection;\n let validationState: ValidationState | null = isValueInvalid ? 'invalid' : null;\n\n return {\n ...calendar,\n value,\n setValue,\n anchorDate,\n setAnchorDate,\n highlightedRange,\n validationState,\n isValueInvalid,\n selectFocusedDate() {\n selectDate(calendar.focusedDate);\n },\n selectDate,\n highlightDate(date) {\n if (anchorDate) {\n calendar.setFocusedDate(date);\n }\n },\n isSelected(date) {\n return Boolean(highlightedRange && date.compare(highlightedRange.start) >= 0 && date.compare(highlightedRange.end) <= 0 && !calendar.isCellDisabled(date) && !calendar.isCellUnavailable(date));\n },\n isInvalid(date) {\n return calendar.isInvalid(date) || isInvalid(date, availableRangeRef.current?.start, availableRangeRef.current?.end);\n },\n isDragging,\n setDragging\n };\n}\n\nfunction makeRange(start: DateValue, end: DateValue): RangeValue<CalendarDate> | null {\n if (!start || !end) {\n return null;\n }\n\n if (end.compare(start) < 0) {\n [start, end] = [end, start];\n }\n\n return {start: toCalendarDate(start), end: toCalendarDate(end)};\n}\n\nfunction convertValue(newValue: CalendarDate, oldValue?: DateValue): DateValue {\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 newValue = toCalendar(newValue, oldValue?.calendar || new GregorianCalendar());\n\n // Preserve time if the input value had one.\n if (oldValue && 'hour' in oldValue) {\n return oldValue.set(newValue);\n }\n\n return newValue;\n}\n\nfunction nextUnavailableDate(anchorDate: CalendarDate, state: CalendarState, dir: number): CalendarDate | undefined {\n let nextDate = anchorDate.add({days: dir});\n while (\n (dir < 0 ? nextDate.compare(state.visibleRange.start) >= 0 : nextDate.compare(state.visibleRange.end) <= 0) &&\n !state.isCellUnavailable(nextDate)\n ) {\n nextDate = nextDate.add({days: dir});\n }\n\n if (state.isCellUnavailable(nextDate)) {\n return nextDate.add({days: -dir});\n }\n\n}\n"],"names":[],"version":3,"file":"useRangeCalendarState.main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;AAA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B,OAAO,cAAzB,kDAAA,4BAA2B,GAAG;QACrH;oBACA;qBACA;IACF;AACF;AAEA,SAAS,gCAAU,KAAgB,EAAE,GAAc;IACjD,IAAI,CAAC,SAAS,CAAC,KACb,OAAO;IAGT,IAAI,IAAI,OAAO,CAAC,SAAS,GACvB,CAAC,OAAO,IAAI,GAAG;QAAC;QAAK;KAAM;IAG7B,OAAO;QAAC,OAAO,CAAA,GAAA,2CAAa,EAAE;QAAQ,KAAK,CAAA,GAAA,2CAAa,EAAE;IAAI;AAChE;AAEA,SAAS,mCAAa,QAAsB,EAAE,QAAoB;IAChE,wEAAwE;IACxE,sFAAsF;IACtF,WAAW,CAAA,GAAA,uCAAS,EAAE,UAAU,CAAA,qBAAA,+BAAA,SAAU,QAAQ,KAAI,IAAI,CAAA,GAAA,8CAAgB;IAE1E,4CAA4C;IAC5C,IAAI,YAAY,UAAU,UACxB,OAAO,SAAS,GAAG,CAAC;IAGtB,OAAO;AACT;AAEA,SAAS,0CAAoB,UAAwB,EAAE,KAAoB,EAAE,GAAW;IACtF,IAAI,WAAW,WAAW,GAAG,CAAC;QAAC,MAAM;IAAG;IACxC,MACE,AAAC,CAAA,MAAM,IAAI,SAAS,OAAO,CAAC,MAAM,YAAY,CAAC,KAAK,KAAK,IAAI,SAAS,OAAO,CAAC,MAAM,YAAY,CAAC,GAAG,KAAK,CAAA,KACzG,CAAC,MAAM,iBAAiB,CAAC,UAEzB,WAAW,SAAS,GAAG,CAAC;QAAC,MAAM;IAAG;IAGpC,IAAI,MAAM,iBAAiB,CAAC,WAC1B,OAAO,SAAS,GAAG,CAAC;QAAC,MAAM,CAAC;IAAG;AAGnC","sources":["packages/@react-stately/calendar/src/useRangeCalendarState.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 {alignCenter, constrainValue, isInvalid, previousAvailableDate} from './utils';\nimport {Calendar, CalendarDate, CalendarIdentifier, DateDuration, GregorianCalendar, isEqualDay, maxDate, minDate, toCalendar, toCalendarDate} from '@internationalized/date';\nimport {CalendarState, RangeCalendarState} from './types';\nimport {DateValue, MappedDateValue, RangeCalendarProps} from '@react-types/calendar';\nimport {RangeValue, ValidationState} from '@react-types/shared';\nimport {useCalendarState} from './useCalendarState';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useRef, useState} from 'react';\n\nexport interface RangeCalendarStateOptions<T extends DateValue = DateValue> extends RangeCalendarProps<T> {\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 * @default {months: 1}\n */\n visibleDuration?: DateDuration,\n /** \n * Determines the alignment of the visible months on initial render based on the current selection or current date if there is no selection. \n * @default 'center'\n */\n selectionAlignment?: 'start' | 'center' | 'end'\n}\n\n/**\n * Provides state management for a range calendar component.\n * A range calendar displays one or more date grids and allows users to select a contiguous range of dates.\n */\nexport function useRangeCalendarState<T extends DateValue = DateValue>(props: RangeCalendarStateOptions<T>): RangeCalendarState {\n let {\n value: valueProp,\n defaultValue,\n onChange,\n createCalendar,\n locale,\n visibleDuration = {months: 1},\n minValue,\n maxValue,\n ...calendarProps} = props;\n let [value, setValue] = useControlledState<RangeValue<T> | null, RangeValue<MappedDateValue<T>>>(\n valueProp!,\n defaultValue || null!,\n onChange\n );\n\n let [anchorDate, setAnchorDateState] = useState<CalendarDate | null>(null);\n let alignment: 'center' | 'start' = 'center';\n if (value && value.start && value.end) {\n let start = alignCenter(toCalendarDate(value.start), visibleDuration, locale, minValue, maxValue);\n let end = start.add(visibleDuration).subtract({days: 1});\n\n if (value.end.compare(end) > 0) {\n alignment = 'start';\n }\n }\n\n // Available range must be stored in a ref so we have access to the updated version immediately in `isInvalid`.\n let availableRangeRef = useRef<Partial<RangeValue<DateValue>> | null>(null);\n let [availableRange, setAvailableRange] = useState<Partial<RangeValue<DateValue>>|null>(null);\n let min = useMemo(() => maxDate(minValue, availableRange?.start), [minValue, availableRange]);\n let max = useMemo(() => minDate(maxValue, availableRange?.end), [maxValue, availableRange]);\n\n let calendar = useCalendarState({\n ...calendarProps,\n value: value && value.start,\n createCalendar,\n locale,\n visibleDuration,\n minValue: min,\n maxValue: max,\n selectionAlignment: props.selectionAlignment || alignment\n });\n\n let updateAvailableRange = (date) => {\n if (date && props.isDateUnavailable && !props.allowsNonContiguousRanges) {\n const nextAvailableStartDate = nextUnavailableDate(date, calendar, -1);\n const nextAvailableEndDate = nextUnavailableDate(date, calendar, 1);\n availableRangeRef.current = {\n start: nextAvailableStartDate,\n end: nextAvailableEndDate\n };\n setAvailableRange(availableRangeRef.current);\n } else {\n availableRangeRef.current = null;\n setAvailableRange(null);\n }\n };\n\n // If the visible range changes, we need to update the available range.\n let [lastVisibleRange, setLastVisibleRange] = useState(calendar.visibleRange);\n if (!isEqualDay(calendar.visibleRange.start, lastVisibleRange.start) || !isEqualDay(calendar.visibleRange.end, lastVisibleRange.end)) {\n updateAvailableRange(anchorDate);\n setLastVisibleRange(calendar.visibleRange);\n }\n\n let setAnchorDate = (date: CalendarDate | null) => {\n if (date) {\n setAnchorDateState(date);\n updateAvailableRange(date);\n } else {\n setAnchorDateState(null);\n updateAvailableRange(null);\n }\n };\n\n let highlightedRange = anchorDate ? makeRange(anchorDate, calendar.focusedDate) : value && makeRange(value.start, value.end);\n let selectDate = (date: CalendarDate) => {\n if (props.isReadOnly) {\n return;\n }\n\n const constrainedDate = constrainValue(date, min, max);\n const previousAvailableConstrainedDate = previousAvailableDate(constrainedDate, calendar.visibleRange.start, props.isDateUnavailable);\n if (!previousAvailableConstrainedDate) {\n return;\n }\n\n if (!anchorDate) {\n setAnchorDate(previousAvailableConstrainedDate);\n } else {\n let range = makeRange(anchorDate, previousAvailableConstrainedDate);\n if (range) {\n setValue({\n start: convertValue(range.start, value?.start) as T,\n end: convertValue(range.end, value?.end) as T\n });\n }\n setAnchorDate(null);\n }\n };\n\n let [isDragging, setDragging] = useState(false);\n\n let {isDateUnavailable} = props;\n let isInvalidSelection = useMemo(() => {\n if (!value || anchorDate) {\n return false;\n }\n\n if (isDateUnavailable && (isDateUnavailable(value.start) || isDateUnavailable(value.end))) {\n return true;\n }\n\n return isInvalid(value.start, minValue, maxValue) || isInvalid(value.end, minValue, maxValue);\n }, [isDateUnavailable, value, anchorDate, minValue, maxValue]);\n\n let isValueInvalid = props.isInvalid || props.validationState === 'invalid' || isInvalidSelection;\n let validationState: ValidationState | null = isValueInvalid ? 'invalid' : null;\n\n return {\n ...calendar,\n value,\n setValue,\n anchorDate,\n setAnchorDate,\n highlightedRange,\n validationState,\n isValueInvalid,\n selectFocusedDate() {\n selectDate(calendar.focusedDate);\n },\n selectDate,\n highlightDate(date) {\n if (anchorDate) {\n calendar.setFocusedDate(date);\n }\n },\n isSelected(date) {\n return Boolean(highlightedRange && date.compare(highlightedRange.start) >= 0 && date.compare(highlightedRange.end) <= 0 && !calendar.isCellDisabled(date) && !calendar.isCellUnavailable(date));\n },\n isInvalid(date) {\n return calendar.isInvalid(date) || isInvalid(date, availableRangeRef.current?.start, availableRangeRef.current?.end);\n },\n isDragging,\n setDragging\n };\n}\n\nfunction makeRange(start: DateValue, end: DateValue): RangeValue<CalendarDate> | null {\n if (!start || !end) {\n return null;\n }\n\n if (end.compare(start) < 0) {\n [start, end] = [end, start];\n }\n\n return {start: toCalendarDate(start), end: toCalendarDate(end)};\n}\n\nfunction convertValue(newValue: CalendarDate, oldValue?: DateValue): DateValue {\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 newValue = toCalendar(newValue, oldValue?.calendar || new GregorianCalendar());\n\n // Preserve time if the input value had one.\n if (oldValue && 'hour' in oldValue) {\n return oldValue.set(newValue);\n }\n\n return newValue;\n}\n\nfunction nextUnavailableDate(anchorDate: CalendarDate, state: CalendarState, dir: number): CalendarDate | undefined {\n let nextDate = anchorDate.add({days: dir});\n while (\n (dir < 0 ? nextDate.compare(state.visibleRange.start) >= 0 : nextDate.compare(state.visibleRange.end) <= 0) &&\n !state.isCellUnavailable(nextDate)\n ) {\n nextDate = nextDate.add({days: dir});\n }\n\n if (state.isCellUnavailable(nextDate)) {\n return nextDate.add({days: -dir});\n }\n\n}\n"],"names":[],"version":3,"file":"useRangeCalendarState.main.js.map"}
@@ -52,7 +52,7 @@ function $9a36b6ba2fb1a7c5$export$9a987164d97ecc90(props) {
52
52
  visibleDuration: visibleDuration,
53
53
  minValue: min,
54
54
  maxValue: max,
55
- selectionAlignment: alignment
55
+ selectionAlignment: props.selectionAlignment || alignment
56
56
  });
57
57
  let updateAvailableRange = (date)=>{
58
58
  if (date && props.isDateUnavailable && !props.allowsNonContiguousRanges) {
@@ -52,7 +52,7 @@ function $9a36b6ba2fb1a7c5$export$9a987164d97ecc90(props) {
52
52
  visibleDuration: visibleDuration,
53
53
  minValue: min,
54
54
  maxValue: max,
55
- selectionAlignment: alignment
55
+ selectionAlignment: props.selectionAlignment || alignment
56
56
  });
57
57
  let updateAvailableRange = (date)=>{
58
58
  if (date && props.isDateUnavailable && !props.allowsNonContiguousRanges) {
@@ -1 +1 @@
1
- {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAgCM,SAAS,0CAAuD,KAAmC;IACxG,IAAI,EAAC,OAAO,SAAS,gBAAE,YAAY,YAAE,QAAQ,kBAAE,cAAc,UAAE,MAAM,mBAAE,kBAAkB;QAAC,QAAQ;IAAC,aAAG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AAI,GAAG;QAAC;QAAK;KAAM;IAG7B,OAAO;QAAC,OAAO,CAAA,GAAA,qBAAa,EAAE;QAAQ,KAAK,CAAA,GAAA,qBAAa,EAAE;IAAI;AAChE;AAEA,SAAS,mCAAa,QAAsB,EAAE,QAAoB;IAChE,wEAAwE;IACxE,sFAAsF;IACtF,WAAW,CAAA,GAAA,iBAAS,EAAE,UAAU,CAAA,qBAAA,+BAAA,SAAU,QAAQ,KAAI,IAAI,CAAA,GAAA,wBAAgB;IAE1E,4CAA4C;IAC5C,IAAI,YAAY,UAAU,UACxB,OAAO,SAAS,GAAG,CAAC;IAGtB,OAAO;AACT;AAEA,SAAS,0CAAoB,UAAwB,EAAE,KAAoB,EAAE,GAAW;IACtF,IAAI,WAAW,WAAW,GAAG,CAAC;QAAC,MAAM;IAAG;IACxC,MACE,AAAC,CAAA,MAAM,IAAI,SAAS,OAAO,CAAC,MAAM,YAAY,CAAC,KAAK,KAAK,IAAI,SAAS,OAAO,CAAC,MAAM,YAAY,CAAC,GAAG,KAAK,CAAA,KACzG,CAAC,MAAM,iBAAiB,CAAC,UAEzB,WAAW,SAAS,GAAG,CAAC;QAAC,MAAM;IAAG;IAGpC,IAAI,MAAM,iBAAiB,CAAC,WAC1B,OAAO,SAAS,GAAG,CAAC;QAAC,MAAM,CAAC;IAAG;AAGnC","sources":["packages/@react-stately/calendar/src/useRangeCalendarState.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 {alignCenter, constrainValue, isInvalid, previousAvailableDate} from './utils';\nimport {Calendar, CalendarDate, CalendarIdentifier, DateDuration, GregorianCalendar, isEqualDay, maxDate, minDate, toCalendar, toCalendarDate} from '@internationalized/date';\nimport {CalendarState, RangeCalendarState} from './types';\nimport {DateValue, MappedDateValue, RangeCalendarProps} from '@react-types/calendar';\nimport {RangeValue, ValidationState} from '@react-types/shared';\nimport {useCalendarState} from './useCalendarState';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useRef, useState} from 'react';\n\nexport interface RangeCalendarStateOptions<T extends DateValue = DateValue> extends RangeCalendarProps<T> {\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 * @default {months: 1}\n */\n visibleDuration?: DateDuration\n}\n\n/**\n * Provides state management for a range calendar component.\n * A range calendar displays one or more date grids and allows users to select a contiguous range of dates.\n */\nexport function useRangeCalendarState<T extends DateValue = DateValue>(props: RangeCalendarStateOptions<T>): RangeCalendarState {\n let {value: valueProp, defaultValue, onChange, createCalendar, locale, visibleDuration = {months: 1}, minValue, maxValue, ...calendarProps} = props;\n let [value, setValue] = useControlledState<RangeValue<T> | null, RangeValue<MappedDateValue<T>>>(\n valueProp!,\n defaultValue || null!,\n onChange\n );\n\n let [anchorDate, setAnchorDateState] = useState<CalendarDate | null>(null);\n let alignment: 'center' | 'start' = 'center';\n if (value && value.start && value.end) {\n let start = alignCenter(toCalendarDate(value.start), visibleDuration, locale, minValue, maxValue);\n let end = start.add(visibleDuration).subtract({days: 1});\n\n if (value.end.compare(end) > 0) {\n alignment = 'start';\n }\n }\n\n // Available range must be stored in a ref so we have access to the updated version immediately in `isInvalid`.\n let availableRangeRef = useRef<Partial<RangeValue<DateValue>> | null>(null);\n let [availableRange, setAvailableRange] = useState<Partial<RangeValue<DateValue>>|null>(null);\n let min = useMemo(() => maxDate(minValue, availableRange?.start), [minValue, availableRange]);\n let max = useMemo(() => minDate(maxValue, availableRange?.end), [maxValue, availableRange]);\n\n let calendar = useCalendarState({\n ...calendarProps,\n value: value && value.start,\n createCalendar,\n locale,\n visibleDuration,\n minValue: min,\n maxValue: max,\n selectionAlignment: alignment\n });\n\n let updateAvailableRange = (date) => {\n if (date && props.isDateUnavailable && !props.allowsNonContiguousRanges) {\n const nextAvailableStartDate = nextUnavailableDate(date, calendar, -1);\n const nextAvailableEndDate = nextUnavailableDate(date, calendar, 1);\n availableRangeRef.current = {\n start: nextAvailableStartDate,\n end: nextAvailableEndDate\n };\n setAvailableRange(availableRangeRef.current);\n } else {\n availableRangeRef.current = null;\n setAvailableRange(null);\n }\n };\n\n // If the visible range changes, we need to update the available range.\n let [lastVisibleRange, setLastVisibleRange] = useState(calendar.visibleRange);\n if (!isEqualDay(calendar.visibleRange.start, lastVisibleRange.start) || !isEqualDay(calendar.visibleRange.end, lastVisibleRange.end)) {\n updateAvailableRange(anchorDate);\n setLastVisibleRange(calendar.visibleRange);\n }\n\n let setAnchorDate = (date: CalendarDate | null) => {\n if (date) {\n setAnchorDateState(date);\n updateAvailableRange(date);\n } else {\n setAnchorDateState(null);\n updateAvailableRange(null);\n }\n };\n\n let highlightedRange = anchorDate ? makeRange(anchorDate, calendar.focusedDate) : value && makeRange(value.start, value.end);\n let selectDate = (date: CalendarDate) => {\n if (props.isReadOnly) {\n return;\n }\n\n const constrainedDate = constrainValue(date, min, max);\n const previousAvailableConstrainedDate = previousAvailableDate(constrainedDate, calendar.visibleRange.start, props.isDateUnavailable);\n if (!previousAvailableConstrainedDate) {\n return;\n }\n\n if (!anchorDate) {\n setAnchorDate(previousAvailableConstrainedDate);\n } else {\n let range = makeRange(anchorDate, previousAvailableConstrainedDate);\n if (range) {\n setValue({\n start: convertValue(range.start, value?.start) as T,\n end: convertValue(range.end, value?.end) as T\n });\n }\n setAnchorDate(null);\n }\n };\n\n let [isDragging, setDragging] = useState(false);\n\n let {isDateUnavailable} = props;\n let isInvalidSelection = useMemo(() => {\n if (!value || anchorDate) {\n return false;\n }\n\n if (isDateUnavailable && (isDateUnavailable(value.start) || isDateUnavailable(value.end))) {\n return true;\n }\n\n return isInvalid(value.start, minValue, maxValue) || isInvalid(value.end, minValue, maxValue);\n }, [isDateUnavailable, value, anchorDate, minValue, maxValue]);\n\n let isValueInvalid = props.isInvalid || props.validationState === 'invalid' || isInvalidSelection;\n let validationState: ValidationState | null = isValueInvalid ? 'invalid' : null;\n\n return {\n ...calendar,\n value,\n setValue,\n anchorDate,\n setAnchorDate,\n highlightedRange,\n validationState,\n isValueInvalid,\n selectFocusedDate() {\n selectDate(calendar.focusedDate);\n },\n selectDate,\n highlightDate(date) {\n if (anchorDate) {\n calendar.setFocusedDate(date);\n }\n },\n isSelected(date) {\n return Boolean(highlightedRange && date.compare(highlightedRange.start) >= 0 && date.compare(highlightedRange.end) <= 0 && !calendar.isCellDisabled(date) && !calendar.isCellUnavailable(date));\n },\n isInvalid(date) {\n return calendar.isInvalid(date) || isInvalid(date, availableRangeRef.current?.start, availableRangeRef.current?.end);\n },\n isDragging,\n setDragging\n };\n}\n\nfunction makeRange(start: DateValue, end: DateValue): RangeValue<CalendarDate> | null {\n if (!start || !end) {\n return null;\n }\n\n if (end.compare(start) < 0) {\n [start, end] = [end, start];\n }\n\n return {start: toCalendarDate(start), end: toCalendarDate(end)};\n}\n\nfunction convertValue(newValue: CalendarDate, oldValue?: DateValue): DateValue {\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 newValue = toCalendar(newValue, oldValue?.calendar || new GregorianCalendar());\n\n // Preserve time if the input value had one.\n if (oldValue && 'hour' in oldValue) {\n return oldValue.set(newValue);\n }\n\n return newValue;\n}\n\nfunction nextUnavailableDate(anchorDate: CalendarDate, state: CalendarState, dir: number): CalendarDate | undefined {\n let nextDate = anchorDate.add({days: dir});\n while (\n (dir < 0 ? nextDate.compare(state.visibleRange.start) >= 0 : nextDate.compare(state.visibleRange.end) <= 0) &&\n !state.isCellUnavailable(nextDate)\n ) {\n nextDate = nextDate.add({days: dir});\n }\n\n if (state.isCellUnavailable(nextDate)) {\n return nextDate.add({days: -dir});\n }\n\n}\n"],"names":[],"version":3,"file":"useRangeCalendarState.module.js.map"}
1
+ {"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAqCM,SAAS,0CAAuD,KAAmC;IACxG,IAAI,EACF,OAAO,SAAS,gBAChB,YAAY,YACZ,QAAQ,kBACR,cAAc,UACd,MAAM,mBACN,kBAAkB;QAAC,QAAQ;IAAC,aAC5B,QAAQ,YACR,QAAQ,EACR,GAAG,eAAc,GAAG;IACtB,IAAI,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,yBAAiB,EACvC,WACA,gBAAgB,MAChB;IAGF,IAAI,CAAC,YAAY,mBAAmB,GAAG,CAAA,GAAA,eAAO,EAAuB;IACrE,IAAI,YAAgC;IACpC,IAAI,SAAS,MAAM,KAAK,IAAI,MAAM,GAAG,EAAE;QACrC,IAAI,QAAQ,CAAA,GAAA,yCAAU,EAAE,CAAA,GAAA,qBAAa,EAAE,MAAM,KAAK,GAAG,iBAAiB,QAAQ,UAAU;QACxF,IAAI,MAAM,MAAM,GAAG,CAAC,iBAAiB,QAAQ,CAAC;YAAC,MAAM;QAAC;QAEtD,IAAI,MAAM,GAAG,CAAC,OAAO,CAAC,OAAO,GAC3B,YAAY;IAEhB;IAEA,+GAA+G;IAC/G,IAAI,oBAAoB,CAAA,GAAA,aAAK,EAAyC;IACtE,IAAI,CAAC,gBAAgB,kBAAkB,GAAG,CAAA,GAAA,eAAO,EAAuC;IACxF,IAAI,MAAM,CAAA,GAAA,cAAM,EAAE,IAAM,CAAA,GAAA,cAAM,EAAE,UAAU,2BAAA,qCAAA,eAAgB,KAAK,GAAG;QAAC;QAAU;KAAe;IAC5F,IAAI,MAAM,CAAA,GAAA,cAAM,EAAE,IAAM,CAAA,GA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G;AAGnC","sources":["packages/@react-stately/calendar/src/useRangeCalendarState.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 {alignCenter, constrainValue, isInvalid, previousAvailableDate} from './utils';\nimport {Calendar, CalendarDate, CalendarIdentifier, DateDuration, GregorianCalendar, isEqualDay, maxDate, minDate, toCalendar, toCalendarDate} from '@internationalized/date';\nimport {CalendarState, RangeCalendarState} from './types';\nimport {DateValue, MappedDateValue, RangeCalendarProps} from '@react-types/calendar';\nimport {RangeValue, ValidationState} from '@react-types/shared';\nimport {useCalendarState} from './useCalendarState';\nimport {useControlledState} from '@react-stately/utils';\nimport {useMemo, useRef, useState} from 'react';\n\nexport interface RangeCalendarStateOptions<T extends DateValue = DateValue> extends RangeCalendarProps<T> {\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 * @default {months: 1}\n */\n visibleDuration?: DateDuration,\n /** \n * Determines the alignment of the visible months on initial render based on the current selection or current date if there is no selection. \n * @default 'center'\n */\n selectionAlignment?: 'start' | 'center' | 'end'\n}\n\n/**\n * Provides state management for a range calendar component.\n * A range calendar displays one or more date grids and allows users to select a contiguous range of dates.\n */\nexport function useRangeCalendarState<T extends DateValue = DateValue>(props: RangeCalendarStateOptions<T>): RangeCalendarState {\n let {\n value: valueProp,\n defaultValue,\n onChange,\n createCalendar,\n locale,\n visibleDuration = {months: 1},\n minValue,\n maxValue,\n ...calendarProps} = props;\n let [value, setValue] = useControlledState<RangeValue<T> | null, RangeValue<MappedDateValue<T>>>(\n valueProp!,\n defaultValue || null!,\n onChange\n );\n\n let [anchorDate, setAnchorDateState] = useState<CalendarDate | null>(null);\n let alignment: 'center' | 'start' = 'center';\n if (value && value.start && value.end) {\n let start = alignCenter(toCalendarDate(value.start), visibleDuration, locale, minValue, maxValue);\n let end = start.add(visibleDuration).subtract({days: 1});\n\n if (value.end.compare(end) > 0) {\n alignment = 'start';\n }\n }\n\n // Available range must be stored in a ref so we have access to the updated version immediately in `isInvalid`.\n let availableRangeRef = useRef<Partial<RangeValue<DateValue>> | null>(null);\n let [availableRange, setAvailableRange] = useState<Partial<RangeValue<DateValue>>|null>(null);\n let min = useMemo(() => maxDate(minValue, availableRange?.start), [minValue, availableRange]);\n let max = useMemo(() => minDate(maxValue, availableRange?.end), [maxValue, availableRange]);\n\n let calendar = useCalendarState({\n ...calendarProps,\n value: value && value.start,\n createCalendar,\n locale,\n visibleDuration,\n minValue: min,\n maxValue: max,\n selectionAlignment: props.selectionAlignment || alignment\n });\n\n let updateAvailableRange = (date) => {\n if (date && props.isDateUnavailable && !props.allowsNonContiguousRanges) {\n const nextAvailableStartDate = nextUnavailableDate(date, calendar, -1);\n const nextAvailableEndDate = nextUnavailableDate(date, calendar, 1);\n availableRangeRef.current = {\n start: nextAvailableStartDate,\n end: nextAvailableEndDate\n };\n setAvailableRange(availableRangeRef.current);\n } else {\n availableRangeRef.current = null;\n setAvailableRange(null);\n }\n };\n\n // If the visible range changes, we need to update the available range.\n let [lastVisibleRange, setLastVisibleRange] = useState(calendar.visibleRange);\n if (!isEqualDay(calendar.visibleRange.start, lastVisibleRange.start) || !isEqualDay(calendar.visibleRange.end, lastVisibleRange.end)) {\n updateAvailableRange(anchorDate);\n setLastVisibleRange(calendar.visibleRange);\n }\n\n let setAnchorDate = (date: CalendarDate | null) => {\n if (date) {\n setAnchorDateState(date);\n updateAvailableRange(date);\n } else {\n setAnchorDateState(null);\n updateAvailableRange(null);\n }\n };\n\n let highlightedRange = anchorDate ? makeRange(anchorDate, calendar.focusedDate) : value && makeRange(value.start, value.end);\n let selectDate = (date: CalendarDate) => {\n if (props.isReadOnly) {\n return;\n }\n\n const constrainedDate = constrainValue(date, min, max);\n const previousAvailableConstrainedDate = previousAvailableDate(constrainedDate, calendar.visibleRange.start, props.isDateUnavailable);\n if (!previousAvailableConstrainedDate) {\n return;\n }\n\n if (!anchorDate) {\n setAnchorDate(previousAvailableConstrainedDate);\n } else {\n let range = makeRange(anchorDate, previousAvailableConstrainedDate);\n if (range) {\n setValue({\n start: convertValue(range.start, value?.start) as T,\n end: convertValue(range.end, value?.end) as T\n });\n }\n setAnchorDate(null);\n }\n };\n\n let [isDragging, setDragging] = useState(false);\n\n let {isDateUnavailable} = props;\n let isInvalidSelection = useMemo(() => {\n if (!value || anchorDate) {\n return false;\n }\n\n if (isDateUnavailable && (isDateUnavailable(value.start) || isDateUnavailable(value.end))) {\n return true;\n }\n\n return isInvalid(value.start, minValue, maxValue) || isInvalid(value.end, minValue, maxValue);\n }, [isDateUnavailable, value, anchorDate, minValue, maxValue]);\n\n let isValueInvalid = props.isInvalid || props.validationState === 'invalid' || isInvalidSelection;\n let validationState: ValidationState | null = isValueInvalid ? 'invalid' : null;\n\n return {\n ...calendar,\n value,\n setValue,\n anchorDate,\n setAnchorDate,\n highlightedRange,\n validationState,\n isValueInvalid,\n selectFocusedDate() {\n selectDate(calendar.focusedDate);\n },\n selectDate,\n highlightDate(date) {\n if (anchorDate) {\n calendar.setFocusedDate(date);\n }\n },\n isSelected(date) {\n return Boolean(highlightedRange && date.compare(highlightedRange.start) >= 0 && date.compare(highlightedRange.end) <= 0 && !calendar.isCellDisabled(date) && !calendar.isCellUnavailable(date));\n },\n isInvalid(date) {\n return calendar.isInvalid(date) || isInvalid(date, availableRangeRef.current?.start, availableRangeRef.current?.end);\n },\n isDragging,\n setDragging\n };\n}\n\nfunction makeRange(start: DateValue, end: DateValue): RangeValue<CalendarDate> | null {\n if (!start || !end) {\n return null;\n }\n\n if (end.compare(start) < 0) {\n [start, end] = [end, start];\n }\n\n return {start: toCalendarDate(start), end: toCalendarDate(end)};\n}\n\nfunction convertValue(newValue: CalendarDate, oldValue?: DateValue): DateValue {\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 newValue = toCalendar(newValue, oldValue?.calendar || new GregorianCalendar());\n\n // Preserve time if the input value had one.\n if (oldValue && 'hour' in oldValue) {\n return oldValue.set(newValue);\n }\n\n return newValue;\n}\n\nfunction nextUnavailableDate(anchorDate: CalendarDate, state: CalendarState, dir: number): CalendarDate | undefined {\n let nextDate = anchorDate.add({days: dir});\n while (\n (dir < 0 ? nextDate.compare(state.visibleRange.start) >= 0 : nextDate.compare(state.visibleRange.end) <= 0) &&\n !state.isCellUnavailable(nextDate)\n ) {\n nextDate = nextDate.add({days: dir});\n }\n\n if (state.isCellUnavailable(nextDate)) {\n return nextDate.add({days: -dir});\n }\n\n}\n"],"names":[],"version":3,"file":"useRangeCalendarState.module.js.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/calendar",
3
- "version": "3.8.4",
3
+ "version": "3.9.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -26,10 +26,10 @@
26
26
  "url": "https://github.com/adobe/react-spectrum"
27
27
  },
28
28
  "dependencies": {
29
- "@internationalized/date": "^3.9.0",
29
+ "@internationalized/date": "^3.10.0",
30
30
  "@react-stately/utils": "^3.10.8",
31
- "@react-types/calendar": "^3.7.4",
32
- "@react-types/shared": "^3.32.0",
31
+ "@react-types/calendar": "^3.8.0",
32
+ "@react-types/shared": "^3.32.1",
33
33
  "@swc/helpers": "^0.5.0"
34
34
  },
35
35
  "peerDependencies": {
@@ -38,5 +38,5 @@
38
38
  "publishConfig": {
39
39
  "access": "public"
40
40
  },
41
- "gitHead": "2c58ed3ddd9be9100af9b1d0cfd137fcdc95ba2d"
41
+ "gitHead": "0bda51183baa23306342af32a82012ea0fe0f2dc"
42
42
  }
@@ -50,7 +50,10 @@ export interface CalendarStateOptions<T extends DateValue = DateValue> extends C
50
50
  * @default {months: 1}
51
51
  */
52
52
  visibleDuration?: DateDuration,
53
- /** Determines how to align the initial selection relative to the visible date range. */
53
+ /**
54
+ * Determines the alignment of the visible months on initial render based on the current selection or current date if there is no selection.
55
+ * @default 'center'
56
+ */
54
57
  selectionAlignment?: 'start' | 'center' | 'end'
55
58
  }
56
59
  /**
@@ -33,7 +33,12 @@ export interface RangeCalendarStateOptions<T extends DateValue = DateValue> exte
33
33
  * The amount of days that will be displayed at once. This affects how pagination works.
34
34
  * @default {months: 1}
35
35
  */
36
- visibleDuration?: DateDuration
36
+ visibleDuration?: DateDuration,
37
+ /**
38
+ * Determines the alignment of the visible months on initial render based on the current selection or current date if there is no selection.
39
+ * @default 'center'
40
+ */
41
+ selectionAlignment?: 'start' | 'center' | 'end'
37
42
  }
38
43
 
39
44
  /**
@@ -41,7 +46,16 @@ export interface RangeCalendarStateOptions<T extends DateValue = DateValue> exte
41
46
  * A range calendar displays one or more date grids and allows users to select a contiguous range of dates.
42
47
  */
43
48
  export function useRangeCalendarState<T extends DateValue = DateValue>(props: RangeCalendarStateOptions<T>): RangeCalendarState {
44
- let {value: valueProp, defaultValue, onChange, createCalendar, locale, visibleDuration = {months: 1}, minValue, maxValue, ...calendarProps} = props;
49
+ let {
50
+ value: valueProp,
51
+ defaultValue,
52
+ onChange,
53
+ createCalendar,
54
+ locale,
55
+ visibleDuration = {months: 1},
56
+ minValue,
57
+ maxValue,
58
+ ...calendarProps} = props;
45
59
  let [value, setValue] = useControlledState<RangeValue<T> | null, RangeValue<MappedDateValue<T>>>(
46
60
  valueProp!,
47
61
  defaultValue || null!,
@@ -73,7 +87,7 @@ export function useRangeCalendarState<T extends DateValue = DateValue>(props: Ra
73
87
  visibleDuration,
74
88
  minValue: min,
75
89
  maxValue: max,
76
- selectionAlignment: alignment
90
+ selectionAlignment: props.selectionAlignment || alignment
77
91
  });
78
92
 
79
93
  let updateAvailableRange = (date) => {