@react-stately/calendar 3.5.1 → 3.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/types.d.ts CHANGED
@@ -9,16 +9,16 @@ interface CalendarStateBase {
9
9
  /** The date range that is currently visible in the calendar. */
10
10
  readonly visibleRange: RangeValue<CalendarDate>;
11
11
  /** The minimum allowed date that a user may select. */
12
- readonly minValue?: DateValue;
12
+ readonly minValue?: DateValue | null;
13
13
  /** The maximum allowed date that a user may select. */
14
- readonly maxValue?: DateValue;
14
+ readonly maxValue?: DateValue | null;
15
15
  /** The time zone of the dates currently being displayed. */
16
16
  readonly timeZone: string;
17
17
  /**
18
18
  * The current validation state of the selected value.
19
19
  * @deprecated Use `isValueInvalid` instead.
20
20
  */
21
- readonly validationState: ValidationState;
21
+ readonly validationState: ValidationState | null;
22
22
  /** Whether the calendar is invalid. */
23
23
  readonly isValueInvalid: boolean;
24
24
  /** The currently focused date. */
@@ -93,9 +93,9 @@ export interface CalendarState extends CalendarStateBase {
93
93
  }
94
94
  export interface RangeCalendarState extends CalendarStateBase {
95
95
  /** The currently selected date range. */
96
- readonly value: RangeValue<DateValue>;
96
+ readonly value: RangeValue<DateValue> | null;
97
97
  /** Sets the currently selected date range. */
98
- setValue(value: RangeValue<DateValue>): void;
98
+ setValue(value: RangeValue<DateValue> | null): void;
99
99
  /** Highlights the given date during selection, e.g. by hovering or dragging. */
100
100
  highlightDate(date: CalendarDate): void;
101
101
  /** The current anchor date that the user clicked on to begin range selection. */
@@ -103,7 +103,7 @@ export interface RangeCalendarState extends CalendarStateBase {
103
103
  /** Sets the anchor date that the user clicked on to begin range selection. */
104
104
  setAnchorDate(date: CalendarDate | null): void;
105
105
  /** The currently highlighted date range. */
106
- readonly highlightedRange: RangeValue<CalendarDate>;
106
+ readonly highlightedRange: RangeValue<CalendarDate> | null;
107
107
  /** Whether the user is currently dragging over the calendar. */
108
108
  readonly isDragging: boolean;
109
109
  /** S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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,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DAA6D;IAC7D,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,QAAQ,CAAC;IAC3C;;;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,CA4S/G;AChVD,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,MAAM,KAAK,QAAQ,CAAC;IAC3C;;;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"}
@@ -37,7 +37,8 @@ function $6adad0c8536fc209$export$6d095e787d2b5e1f(props) {
37
37
  createCalendar,
38
38
  resolvedOptions.calendar
39
39
  ]);
40
- let [value, setControlledValue] = (0, $cpRwL$reactstatelyutils.useControlledState)(props.value, props.defaultValue, props.onChange);
40
+ var _props_defaultValue;
41
+ let [value, setControlledValue] = (0, $cpRwL$reactstatelyutils.useControlledState)(props.value, (_props_defaultValue = props.defaultValue) !== null && _props_defaultValue !== void 0 ? _props_defaultValue : null, props.onChange);
41
42
  let calendarDateValue = (0, $cpRwL$react.useMemo)(()=>value ? (0, $cpRwL$internationalizeddate.toCalendar)((0, $cpRwL$internationalizeddate.toCalendarDate)(value), calendar) : null, [
42
43
  value,
43
44
  calendar
@@ -103,19 +104,20 @@ function $6adad0c8536fc209$export$6d095e787d2b5e1f(props) {
103
104
  }
104
105
  function setValue(newValue) {
105
106
  if (!props.isDisabled && !props.isReadOnly) {
106
- if (newValue === null) {
107
+ let localValue = newValue;
108
+ if (localValue === null) {
107
109
  setControlledValue(null);
108
110
  return;
109
111
  }
110
- newValue = (0, $4301262d71f567b9$exports.constrainValue)(newValue, minValue, maxValue);
111
- newValue = (0, $4301262d71f567b9$exports.previousAvailableDate)(newValue, startDate, isDateUnavailable);
112
- if (!newValue) return;
112
+ localValue = (0, $4301262d71f567b9$exports.constrainValue)(localValue, minValue, maxValue);
113
+ localValue = (0, $4301262d71f567b9$exports.previousAvailableDate)(localValue, startDate, isDateUnavailable);
114
+ if (!localValue) return;
113
115
  // The display calendar should not have any effect on the emitted value.
114
116
  // Emit dates in the same calendar as the original value, if any, otherwise gregorian.
115
- newValue = (0, $cpRwL$internationalizeddate.toCalendar)(newValue, (value === null || value === void 0 ? void 0 : value.calendar) || new (0, $cpRwL$internationalizeddate.GregorianCalendar)());
117
+ localValue = (0, $cpRwL$internationalizeddate.toCalendar)(localValue, (value === null || value === void 0 ? void 0 : value.calendar) || new (0, $cpRwL$internationalizeddate.GregorianCalendar)());
116
118
  // Preserve time if the input value had one.
117
- if (value && 'hour' in value) setControlledValue(value.set(newValue));
118
- else setControlledValue(newValue);
119
+ if (value && 'hour' in value) setControlledValue(value.set(localValue));
120
+ else setControlledValue(localValue);
119
121
  }
120
122
  }
121
123
  let isUnavailable = (0, $cpRwL$react.useMemo)(()=>{
@@ -137,9 +139,10 @@ function $6adad0c8536fc209$export$6d095e787d2b5e1f(props) {
137
139
  pageBehavior,
138
140
  visibleDuration
139
141
  ]);
142
+ var _props_isDisabled, _props_isReadOnly;
140
143
  return {
141
- isDisabled: props.isDisabled,
142
- isReadOnly: props.isReadOnly,
144
+ isDisabled: (_props_isDisabled = props.isDisabled) !== null && _props_isDisabled !== void 0 ? _props_isDisabled : false,
145
+ isReadOnly: (_props_isReadOnly = props.isReadOnly) !== null && _props_isReadOnly !== void 0 ? _props_isReadOnly : false,
143
146
  value: calendarDateValue,
144
147
  setValue: setValue,
145
148
  visibleRange: {
@@ -242,16 +245,16 @@ function $6adad0c8536fc209$export$6d095e787d2b5e1f(props) {
242
245
  return isFocused && focusedDate && (0, $cpRwL$internationalizeddate.isSameDay)(date, focusedDate);
243
246
  },
244
247
  isCellDisabled (date) {
245
- return props.isDisabled || date.compare(startDate) < 0 || date.compare(endDate) > 0 || this.isInvalid(date, minValue, maxValue);
248
+ return props.isDisabled || date.compare(startDate) < 0 || date.compare(endDate) > 0 || this.isInvalid(date);
246
249
  },
247
250
  isCellUnavailable (date) {
248
- return props.isDateUnavailable && props.isDateUnavailable(date);
251
+ return props.isDateUnavailable ? props.isDateUnavailable(date) : false;
249
252
  },
250
253
  isPreviousVisibleRangeInvalid () {
251
254
  let prev = startDate.subtract({
252
255
  days: 1
253
256
  });
254
- return (0, $cpRwL$internationalizeddate.isSameDay)(prev, startDate) || this.isInvalid(prev, minValue, maxValue);
257
+ return (0, $cpRwL$internationalizeddate.isSameDay)(prev, startDate) || this.isInvalid(prev);
255
258
  },
256
259
  isNextVisibleRangeInvalid () {
257
260
  // Adding may return the same date if we reached the end of time
@@ -259,7 +262,7 @@ function $6adad0c8536fc209$export$6d095e787d2b5e1f(props) {
259
262
  let next = endDate.add({
260
263
  days: 1
261
264
  });
262
- return (0, $cpRwL$internationalizeddate.isSameDay)(next, endDate) || this.isInvalid(next, minValue, maxValue);
265
+ return (0, $cpRwL$internationalizeddate.isSameDay)(next, endDate) || this.isInvalid(next);
263
266
  },
264
267
  getDatesInWeek (weekIndex, from = startDate) {
265
268
  // let date = startOfWeek(from, locale);
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAgDM,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,IAAI,UACF,MAAM,kBACN,cAAc,mBACd,kBAAkB;QAAC,QAAQ;IAAC,aAC5B,QAAQ,YACR,QAAQ,sBACR,kBAAkB,qBAClB,iBAAiB,gBACjB,eAAe,WAChB,GAAG;IACJ,IAAI,WAAW,CAAA,GAAA,oBAAM,EAAE,IAAM,eAAe,gBAAgB,QAAQ,GAAG;QAAC;QAAgB,gBAAgB,QAAQ;KAAC;IAEjH,IAAI,CAAC,OAAO,mBAAmB,GAAG,CAAA,GAAA,2CAAiB,EAAa,MAAM,KAAK,EAAE,MAAM,YAAY,EAA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AAA,sCAAQ,EAAE,MAAM,cAAc,IAAI,CAAC,SAAS,CAAC,MAAM,UAAU;QACtE;QACA;YACE,gEAAgE;YAChE,sDAAsD;YACtD,IAAI,OAAO,QAAQ,GAAG,CAAC;gBAAC,MAAM;YAAC;YAC/B,OAAO,CAAA,GAAA,sCAAQ,EAAE,MAAM,YAAY,IAAI,CAAC,SAAS,CAAC,MAAM,UAAU;QACpE;QACA,gBAAe,SAAS,EAAE,OAAO,SAAS;YACxC,wCAAwC;YACxC,IAAI,OAAO,KAAK,GAAG,CAAC;gBAAC,OAAO;YAAS;YACrC,IAAI,QAAQ,EAAE;YAEd,OAAO,CAAA,GAAA,wCAAU,EAAE,MAAM;YAEzB,mFAAmF;YACnF,sEAAsE;YACtE,IAAI,YAAY,CAAA,GAAA,yCAAW,EAAE,MAAM;YACnC,IAAK,IAAI,IAAI,GAAG,IAAI,WAAW,IAC7B,MAAM,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 DateDuration,\n DateFormatter,\n endOfMonth,\n endOfWeek,\n getDayOfWeek,\n GregorianCalendar,\n isSameDay,\n startOfMonth,\n startOfWeek,\n toCalendar,\n toCalendarDate,\n today\n} from '@internationalized/date';\nimport {CalendarProps, DateValue} 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: string) => 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/**\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 } = props;\n let calendar = useMemo(() => createCalendar(resolvedOptions.calendar), [createCalendar, resolvedOptions.calendar]);\n\n let [value, setControlledValue] = useControlledState<DateValue>(props.value, props.defaultValue, 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 [lastCalendarIdentifier, setLastCalendarIdentifier] = useState(calendar.identifier);\n if (calendar.identifier !== lastCalendarIdentifier) {\n let newFocusedDate = toCalendar(focusedDate, calendar);\n setStartDate(alignCenter(newFocusedDate, visibleDuration, locale, minValue, maxValue));\n setFocusedDate(newFocusedDate);\n setLastCalendarIdentifier(calendar.identifier);\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 if (newValue === null) {\n setControlledValue(null);\n return;\n }\n newValue = constrainValue(newValue, minValue, maxValue);\n newValue = previousAvailableDate(newValue, startDate, isDateUnavailable);\n if (!newValue) {\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 newValue = toCalendar(newValue, value?.calendar || new GregorianCalendar());\n\n // Preserve time if the input value had one.\n if (value && 'hour' in value) {\n setControlledValue(value.set(newValue));\n } else {\n setControlledValue(newValue);\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 = 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,\n isReadOnly: props.isReadOnly,\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 setValue(focusedDate);\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, minValue, maxValue);\n },\n isCellUnavailable(date) {\n return props.isDateUnavailable && props.isDateUnavailable(date);\n },\n isPreviousVisibleRangeInvalid() {\n let prev = startDate.subtract({days: 1});\n return isSameDay(prev, startDate) || this.isInvalid(prev, minValue, maxValue);\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, minValue, maxValue);\n },\n getDatesInWeek(weekIndex, from = startDate) {\n // let date = startOfWeek(from, locale);\n let date = from.add({weeks: weekIndex});\n let dates = [];\n\n date = startOfWeek(date, locale);\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);\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;;;;AA+CM,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,IAAI,UACF,MAAM,kBACN,cAAc,mBACd,kBAAkB;QAAC,QAAQ;IAAC,aAC5B,QAAQ,YACR,QAAQ,sBACR,kBAAkB,qBAClB,iBAAiB,gBACjB,eAAe,WAChB,GAAG;IACJ,IAAI,WAAW,CAAA,GAAA,oBAAM,EAAE,IAAM,eAAe,gBAAgB,QAAQ,GAAG;QAAC;QAAgB,gBAAgB,QAAQ;KAAC;QAER;IAAzG,IAAI,CAAC,OAAO,mBAAmB,GAAG,CAAA,GAAA,2CAAiB,EAAwC,MAAM,KAAK,EAAG,CAAA,sBAAA,MAAM,YAAY,cAAlB,iCAAA,sBAAsB,MAAO,MAAM,QAAQ;IACpJ,IAAI,oBAAoB,CAAA,GAAA,oBAAM,EAAE,IAAM,QAAQ,CAAA,GAAA,uCAAS,EAAE,CAAA,GAAA,2CAAa,EAAE,QAAQ,YAAY,MAAM;QAAC;QAAO;KAAS;IACnH,IAAI,WAAW,CAAA,GAAA,oBAAM,EAAE,IAAM,SAAS,cAAc,QAAQ,MAAM,QAAQ,GAAG,gBAAgB,QAAQ,EAAE;QAAC;QAAO,gBAAgB,QAAQ;KAAC;IACxI,IAAI,sBAAsB,CAAA,GAAA,oBAAM,EAAE,IAChC,MAAM,YAAY,GACd,CAAA,GAAA,wCAAa,E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KAAK,GAAG,CAAC;gBAAC,OAAO;YAAS;YACrC,IAAI,QAAiC,EAAE;YAEvC,OAAO,CAAA,GAAA,wCAAU,EAAE,MAAM;YAEzB,mFAAmF;YACnF,sEAAsE;YACtE,IAAI,YAAY,CAAA,GAAA,yCAAW,EAAE,MAAM;YACnC,IAAK,IAAI,IAAI,GAAG,IAAI,WAAW,IAC7B,MAAM,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 DateDuration,\n DateFormatter,\n endOfMonth,\n endOfWeek,\n getDayOfWeek,\n GregorianCalendar,\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: string) => 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 } = props;\n let calendar = useMemo(() => createCalendar(resolvedOptions.calendar), [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 [lastCalendarIdentifier, setLastCalendarIdentifier] = useState(calendar.identifier);\n if (calendar.identifier !== lastCalendarIdentifier) {\n let newFocusedDate = toCalendar(focusedDate, calendar);\n setStartDate(alignCenter(newFocusedDate, visibleDuration, locale, minValue, maxValue));\n setFocusedDate(newFocusedDate);\n setLastCalendarIdentifier(calendar.identifier);\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 setValue(focusedDate);\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 = startOfWeek(from, locale);\n let date = from.add({weeks: weekIndex});\n let dates: (CalendarDate | null)[] = [];\n\n date = startOfWeek(date, locale);\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);\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"}
@@ -31,7 +31,8 @@ function $131cf43a05231e1e$export$6d095e787d2b5e1f(props) {
31
31
  createCalendar,
32
32
  resolvedOptions.calendar
33
33
  ]);
34
- let [value, setControlledValue] = (0, $7G4ZY$useControlledState)(props.value, props.defaultValue, props.onChange);
34
+ var _props_defaultValue;
35
+ let [value, setControlledValue] = (0, $7G4ZY$useControlledState)(props.value, (_props_defaultValue = props.defaultValue) !== null && _props_defaultValue !== void 0 ? _props_defaultValue : null, props.onChange);
35
36
  let calendarDateValue = (0, $7G4ZY$useMemo)(()=>value ? (0, $7G4ZY$toCalendar)((0, $7G4ZY$toCalendarDate)(value), calendar) : null, [
36
37
  value,
37
38
  calendar
@@ -97,19 +98,20 @@ function $131cf43a05231e1e$export$6d095e787d2b5e1f(props) {
97
98
  }
98
99
  function setValue(newValue) {
99
100
  if (!props.isDisabled && !props.isReadOnly) {
100
- if (newValue === null) {
101
+ let localValue = newValue;
102
+ if (localValue === null) {
101
103
  setControlledValue(null);
102
104
  return;
103
105
  }
104
- newValue = (0, $f62d864046160412$export$4f5203c0d889109e)(newValue, minValue, maxValue);
105
- newValue = (0, $f62d864046160412$export$a1d3911297b952d7)(newValue, startDate, isDateUnavailable);
106
- if (!newValue) return;
106
+ localValue = (0, $f62d864046160412$export$4f5203c0d889109e)(localValue, minValue, maxValue);
107
+ localValue = (0, $f62d864046160412$export$a1d3911297b952d7)(localValue, startDate, isDateUnavailable);
108
+ if (!localValue) return;
107
109
  // The display calendar should not have any effect on the emitted value.
108
110
  // Emit dates in the same calendar as the original value, if any, otherwise gregorian.
109
- newValue = (0, $7G4ZY$toCalendar)(newValue, (value === null || value === void 0 ? void 0 : value.calendar) || new (0, $7G4ZY$GregorianCalendar)());
111
+ localValue = (0, $7G4ZY$toCalendar)(localValue, (value === null || value === void 0 ? void 0 : value.calendar) || new (0, $7G4ZY$GregorianCalendar)());
110
112
  // Preserve time if the input value had one.
111
- if (value && 'hour' in value) setControlledValue(value.set(newValue));
112
- else setControlledValue(newValue);
113
+ if (value && 'hour' in value) setControlledValue(value.set(localValue));
114
+ else setControlledValue(localValue);
113
115
  }
114
116
  }
115
117
  let isUnavailable = (0, $7G4ZY$useMemo)(()=>{
@@ -131,9 +133,10 @@ function $131cf43a05231e1e$export$6d095e787d2b5e1f(props) {
131
133
  pageBehavior,
132
134
  visibleDuration
133
135
  ]);
136
+ var _props_isDisabled, _props_isReadOnly;
134
137
  return {
135
- isDisabled: props.isDisabled,
136
- isReadOnly: props.isReadOnly,
138
+ isDisabled: (_props_isDisabled = props.isDisabled) !== null && _props_isDisabled !== void 0 ? _props_isDisabled : false,
139
+ isReadOnly: (_props_isReadOnly = props.isReadOnly) !== null && _props_isReadOnly !== void 0 ? _props_isReadOnly : false,
137
140
  value: calendarDateValue,
138
141
  setValue: setValue,
139
142
  visibleRange: {
@@ -236,16 +239,16 @@ function $131cf43a05231e1e$export$6d095e787d2b5e1f(props) {
236
239
  return isFocused && focusedDate && (0, $7G4ZY$isSameDay)(date, focusedDate);
237
240
  },
238
241
  isCellDisabled (date) {
239
- return props.isDisabled || date.compare(startDate) < 0 || date.compare(endDate) > 0 || this.isInvalid(date, minValue, maxValue);
242
+ return props.isDisabled || date.compare(startDate) < 0 || date.compare(endDate) > 0 || this.isInvalid(date);
240
243
  },
241
244
  isCellUnavailable (date) {
242
- return props.isDateUnavailable && props.isDateUnavailable(date);
245
+ return props.isDateUnavailable ? props.isDateUnavailable(date) : false;
243
246
  },
244
247
  isPreviousVisibleRangeInvalid () {
245
248
  let prev = startDate.subtract({
246
249
  days: 1
247
250
  });
248
- return (0, $7G4ZY$isSameDay)(prev, startDate) || this.isInvalid(prev, minValue, maxValue);
251
+ return (0, $7G4ZY$isSameDay)(prev, startDate) || this.isInvalid(prev);
249
252
  },
250
253
  isNextVisibleRangeInvalid () {
251
254
  // Adding may return the same date if we reached the end of time
@@ -253,7 +256,7 @@ function $131cf43a05231e1e$export$6d095e787d2b5e1f(props) {
253
256
  let next = endDate.add({
254
257
  days: 1
255
258
  });
256
- return (0, $7G4ZY$isSameDay)(next, endDate) || this.isInvalid(next, minValue, maxValue);
259
+ return (0, $7G4ZY$isSameDay)(next, endDate) || this.isInvalid(next);
257
260
  },
258
261
  getDatesInWeek (weekIndex, from = startDate) {
259
262
  // let date = startOfWeek(from, locale);
@@ -31,7 +31,8 @@ function $131cf43a05231e1e$export$6d095e787d2b5e1f(props) {
31
31
  createCalendar,
32
32
  resolvedOptions.calendar
33
33
  ]);
34
- let [value, setControlledValue] = (0, $7G4ZY$useControlledState)(props.value, props.defaultValue, props.onChange);
34
+ var _props_defaultValue;
35
+ let [value, setControlledValue] = (0, $7G4ZY$useControlledState)(props.value, (_props_defaultValue = props.defaultValue) !== null && _props_defaultValue !== void 0 ? _props_defaultValue : null, props.onChange);
35
36
  let calendarDateValue = (0, $7G4ZY$useMemo)(()=>value ? (0, $7G4ZY$toCalendar)((0, $7G4ZY$toCalendarDate)(value), calendar) : null, [
36
37
  value,
37
38
  calendar
@@ -97,19 +98,20 @@ function $131cf43a05231e1e$export$6d095e787d2b5e1f(props) {
97
98
  }
98
99
  function setValue(newValue) {
99
100
  if (!props.isDisabled && !props.isReadOnly) {
100
- if (newValue === null) {
101
+ let localValue = newValue;
102
+ if (localValue === null) {
101
103
  setControlledValue(null);
102
104
  return;
103
105
  }
104
- newValue = (0, $f62d864046160412$export$4f5203c0d889109e)(newValue, minValue, maxValue);
105
- newValue = (0, $f62d864046160412$export$a1d3911297b952d7)(newValue, startDate, isDateUnavailable);
106
- if (!newValue) return;
106
+ localValue = (0, $f62d864046160412$export$4f5203c0d889109e)(localValue, minValue, maxValue);
107
+ localValue = (0, $f62d864046160412$export$a1d3911297b952d7)(localValue, startDate, isDateUnavailable);
108
+ if (!localValue) return;
107
109
  // The display calendar should not have any effect on the emitted value.
108
110
  // Emit dates in the same calendar as the original value, if any, otherwise gregorian.
109
- newValue = (0, $7G4ZY$toCalendar)(newValue, (value === null || value === void 0 ? void 0 : value.calendar) || new (0, $7G4ZY$GregorianCalendar)());
111
+ localValue = (0, $7G4ZY$toCalendar)(localValue, (value === null || value === void 0 ? void 0 : value.calendar) || new (0, $7G4ZY$GregorianCalendar)());
110
112
  // Preserve time if the input value had one.
111
- if (value && 'hour' in value) setControlledValue(value.set(newValue));
112
- else setControlledValue(newValue);
113
+ if (value && 'hour' in value) setControlledValue(value.set(localValue));
114
+ else setControlledValue(localValue);
113
115
  }
114
116
  }
115
117
  let isUnavailable = (0, $7G4ZY$useMemo)(()=>{
@@ -131,9 +133,10 @@ function $131cf43a05231e1e$export$6d095e787d2b5e1f(props) {
131
133
  pageBehavior,
132
134
  visibleDuration
133
135
  ]);
136
+ var _props_isDisabled, _props_isReadOnly;
134
137
  return {
135
- isDisabled: props.isDisabled,
136
- isReadOnly: props.isReadOnly,
138
+ isDisabled: (_props_isDisabled = props.isDisabled) !== null && _props_isDisabled !== void 0 ? _props_isDisabled : false,
139
+ isReadOnly: (_props_isReadOnly = props.isReadOnly) !== null && _props_isReadOnly !== void 0 ? _props_isReadOnly : false,
137
140
  value: calendarDateValue,
138
141
  setValue: setValue,
139
142
  visibleRange: {
@@ -236,16 +239,16 @@ function $131cf43a05231e1e$export$6d095e787d2b5e1f(props) {
236
239
  return isFocused && focusedDate && (0, $7G4ZY$isSameDay)(date, focusedDate);
237
240
  },
238
241
  isCellDisabled (date) {
239
- return props.isDisabled || date.compare(startDate) < 0 || date.compare(endDate) > 0 || this.isInvalid(date, minValue, maxValue);
242
+ return props.isDisabled || date.compare(startDate) < 0 || date.compare(endDate) > 0 || this.isInvalid(date);
240
243
  },
241
244
  isCellUnavailable (date) {
242
- return props.isDateUnavailable && props.isDateUnavailable(date);
245
+ return props.isDateUnavailable ? props.isDateUnavailable(date) : false;
243
246
  },
244
247
  isPreviousVisibleRangeInvalid () {
245
248
  let prev = startDate.subtract({
246
249
  days: 1
247
250
  });
248
- return (0, $7G4ZY$isSameDay)(prev, startDate) || this.isInvalid(prev, minValue, maxValue);
251
+ return (0, $7G4ZY$isSameDay)(prev, startDate) || this.isInvalid(prev);
249
252
  },
250
253
  isNextVisibleRangeInvalid () {
251
254
  // Adding may return the same date if we reached the end of time
@@ -253,7 +256,7 @@ function $131cf43a05231e1e$export$6d095e787d2b5e1f(props) {
253
256
  let next = endDate.add({
254
257
  days: 1
255
258
  });
256
- return (0, $7G4ZY$isSameDay)(next, endDate) || this.isInvalid(next, minValue, maxValue);
259
+ return (0, $7G4ZY$isSameDay)(next, endDate) || this.isInvalid(next);
257
260
  },
258
261
  getDatesInWeek (weekIndex, from = startDate) {
259
262
  // let date = startOfWeek(from, locale);
@@ -1 +1 @@
1
- {"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AAgDM,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,WAChB,GAAG;IACJ,IAAI,WAAW,CAAA,GAAA,cAAM,EAAE,IAAM,eAAe,gBAAgB,QAAQ,GAAG;QAAC;QAAgB,gBAAgB,QAAQ;KAAC;IAEjH,IAAI,CAAC,OAAO,mBAAmB,GAAG,CAAA,GAAA,yBAAiB,EAAa,MAAM,KAAK,EAAE,MAAM,YAAY,EAAE,MAAM,QAAQ;IAC/G,IAAI,oBAAoB,CAAA,GAAA,cAAM,EAAE,IAAM,QAAQ,CAAA,GAAA,iBAAS,EAAE,CAAA,GAAA,qBAAa,EAAE,QAAQ,YAAY,MAAM;QAAC;QAAO;KAAS;IACnH,IAAI,WAAW,CAAA,GAAA,cAAM,EAAE,IAAM,SAAS,cAAc,QAAQ,MAAM,QAAQ,GAAG,gBAAgB,QAAQ,EAAE;QAAC;QAAO,gBAAgB,QAAQ;KAAC;IACxI,IAAI,sBAAsB,CAAA,GAAA,cAAM,EAAE,IACh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C,IAAI,QAAQ,EAAE;YAEd,OAAO,CAAA,GAAA,kBAAU,EAAE,MAAM;YAEzB,mFAAmF;YACnF,sEAAsE;YACtE,IAAI,YAAY,CAAA,GAAA,mBAAW,EAAE,MAAM;YACnC,IAAK,IAAI,IAAI,GAAG,IAAI,WAAW,IAC7B,MAAM,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,gBAAQ,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 DateDuration,\n DateFormatter,\n endOfMonth,\n endOfWeek,\n getDayOfWeek,\n GregorianCalendar,\n isSameDay,\n startOfMonth,\n startOfWeek,\n toCalendar,\n toCalendarDate,\n today\n} from '@internationalized/date';\nimport {CalendarProps, DateValue} 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: string) => 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/**\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 } = props;\n let calendar = useMemo(() => createCalendar(resolvedOptions.calendar), [createCalendar, resolvedOptions.calendar]);\n\n let [value, setControlledValue] = useControlledState<DateValue>(props.value, props.defaultValue, 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 [lastCalendarIdentifier, setLastCalendarIdentifier] = useState(calendar.identifier);\n if (calendar.identifier !== lastCalendarIdentifier) {\n let newFocusedDate = toCalendar(focusedDate, calendar);\n setStartDate(alignCenter(newFocusedDate, visibleDuration, locale, minValue, maxValue));\n setFocusedDate(newFocusedDate);\n setLastCalendarIdentifier(calendar.identifier);\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 if (newValue === null) {\n setControlledValue(null);\n return;\n }\n newValue = constrainValue(newValue, minValue, maxValue);\n newValue = previousAvailableDate(newValue, startDate, isDateUnavailable);\n if (!newValue) {\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 newValue = toCalendar(newValue, value?.calendar || new GregorianCalendar());\n\n // Preserve time if the input value had one.\n if (value && 'hour' in value) {\n setControlledValue(value.set(newValue));\n } else {\n setControlledValue(newValue);\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 = 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,\n isReadOnly: props.isReadOnly,\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 setValue(focusedDate);\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, minValue, maxValue);\n },\n isCellUnavailable(date) {\n return props.isDateUnavailable && props.isDateUnavailable(date);\n },\n isPreviousVisibleRangeInvalid() {\n let prev = startDate.subtract({days: 1});\n return isSameDay(prev, startDate) || this.isInvalid(prev, minValue, maxValue);\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, minValue, maxValue);\n },\n getDatesInWeek(weekIndex, from = startDate) {\n // let date = startOfWeek(from, locale);\n let date = from.add({weeks: weekIndex});\n let dates = [];\n\n date = startOfWeek(date, locale);\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);\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;;;;AA+CM,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,GA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,GAAA,gBAAQ,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 DateDuration,\n DateFormatter,\n endOfMonth,\n endOfWeek,\n getDayOfWeek,\n GregorianCalendar,\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: string) => 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 } = props;\n let calendar = useMemo(() => createCalendar(resolvedOptions.calendar), [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 [lastCalendarIdentifier, setLastCalendarIdentifier] = useState(calendar.identifier);\n if (calendar.identifier !== lastCalendarIdentifier) {\n let newFocusedDate = toCalendar(focusedDate, calendar);\n setStartDate(alignCenter(newFocusedDate, visibleDuration, locale, minValue, maxValue));\n setFocusedDate(newFocusedDate);\n setLastCalendarIdentifier(calendar.identifier);\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 setValue(focusedDate);\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 = startOfWeek(from, locale);\n let date = from.add({weeks: weekIndex});\n let dates: (CalendarDate | null)[] = [];\n\n date = startOfWeek(date, locale);\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);\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"}
@@ -62,9 +62,11 @@ function $e49f7b861e5e8049$export$9a987164d97ecc90(props) {
62
62
  });
63
63
  let updateAvailableRange = (date)=>{
64
64
  if (date && props.isDateUnavailable && !props.allowsNonContiguousRanges) {
65
+ const nextAvailableStartDate = $e49f7b861e5e8049$var$nextUnavailableDate(date, calendar, -1);
66
+ const nextAvailableEndDate = $e49f7b861e5e8049$var$nextUnavailableDate(date, calendar, 1);
65
67
  availableRangeRef.current = {
66
- start: $e49f7b861e5e8049$var$nextUnavailableDate(date, calendar, -1),
67
- end: $e49f7b861e5e8049$var$nextUnavailableDate(date, calendar, 1)
68
+ start: nextAvailableStartDate,
69
+ end: nextAvailableEndDate
68
70
  };
69
71
  setAvailableRange(availableRangeRef.current);
70
72
  } else {
@@ -90,13 +92,13 @@ function $e49f7b861e5e8049$export$9a987164d97ecc90(props) {
90
92
  let highlightedRange = anchorDate ? $e49f7b861e5e8049$var$makeRange(anchorDate, calendar.focusedDate) : value && $e49f7b861e5e8049$var$makeRange(value.start, value.end);
91
93
  let selectDate = (date)=>{
92
94
  if (props.isReadOnly) return;
93
- date = (0, $4301262d71f567b9$exports.constrainValue)(date, min, max);
94
- date = (0, $4301262d71f567b9$exports.previousAvailableDate)(date, calendar.visibleRange.start, props.isDateUnavailable);
95
- if (!date) return;
96
- if (!anchorDate) setAnchorDate(date);
95
+ const constrainedDate = (0, $4301262d71f567b9$exports.constrainValue)(date, min, max);
96
+ const previousAvailableConstrainedDate = (0, $4301262d71f567b9$exports.previousAvailableDate)(constrainedDate, calendar.visibleRange.start, props.isDateUnavailable);
97
+ if (!previousAvailableConstrainedDate) return;
98
+ if (!anchorDate) setAnchorDate(previousAvailableConstrainedDate);
97
99
  else {
98
- let range = $e49f7b861e5e8049$var$makeRange(anchorDate, date);
99
- setValue({
100
+ let range = $e49f7b861e5e8049$var$makeRange(anchorDate, previousAvailableConstrainedDate);
101
+ if (range) setValue({
100
102
  start: $e49f7b861e5e8049$var$convertValue(range.start, value === null || value === void 0 ? void 0 : value.start),
101
103
  end: $e49f7b861e5e8049$var$convertValue(range.end, value === null || value === void 0 ? void 0 : value.end)
102
104
  });
@@ -135,7 +137,7 @@ function $e49f7b861e5e8049$export$9a987164d97ecc90(props) {
135
137
  if (anchorDate) calendar.setFocusedDate(date);
136
138
  },
137
139
  isSelected (date) {
138
- return highlightedRange && date.compare(highlightedRange.start) >= 0 && date.compare(highlightedRange.end) <= 0 && !calendar.isCellDisabled(date) && !calendar.isCellUnavailable(date);
140
+ return Boolean(highlightedRange && date.compare(highlightedRange.start) >= 0 && date.compare(highlightedRange.end) <= 0 && !calendar.isCellDisabled(date) && !calendar.isCellUnavailable(date));
139
141
  },
140
142
  isInvalid (date) {
141
143
  var _availableRangeRef_current, _availableRangeRef_current1;
@@ -174,7 +176,6 @@ function $e49f7b861e5e8049$var$nextUnavailableDate(anchorDate, state, dir) {
174
176
  if (state.isCellUnavailable(nextDate)) return nextDate.add({
175
177
  days: -dir
176
178
  });
177
- return null;
178
179
  }
179
180
 
180
181