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Aa;YACX,oGAAoG;YACpG,2GAA2G;YAC3G,eAAe;QACjB;kBACA;sBACA;IACF;AACF","sources":["packages/react-aria/src/calendar/useCalendarGrid.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 {CalendarDate, startOfWeek, today} from '@internationalized/date';\nimport {CalendarSelectionMode, CalendarState} from 'react-stately/useCalendarState';\nimport {DOMAttributes} from '@react-types/shared';\nimport {hookData, useVisibleRangeDescription} from './utils';\nimport {mergeProps} from '../utils/mergeProps';\nimport {RangeCalendarState} from 'react-stately/useRangeCalendarState';\nimport {useDateFormatter} from '../i18n/useDateFormatter';\nimport {useKeyboard} from '../interactions/useKeyboard';\nimport {useLabels} from '../utils/useLabels';\nimport {useLocale} from '../i18n/I18nProvider';\nimport {useMemo} from 'react';\n\nexport interface AriaCalendarGridProps {\n  /**\n   * The first date displayed in the calendar grid.\n   * Defaults to the first visible date in the calendar.\n   * Override this to display multiple date grids in a calendar.\n   */\n  startDate?: CalendarDate;\n  /**\n   * The last date displayed in the calendar grid.\n   * Defaults to the last visible date in the calendar.\n   * Override this to display multiple date grids in a calendar.\n   */\n  endDate?: CalendarDate;\n  /**\n   * The style of weekday names to display in the calendar grid header,\n   * e.g. single letter, abbreviation, or full day name.\n   *\n   * @default 'narrow'\n   */\n  weekdayStyle?: 'narrow' | 'short' | 'long';\n  /**\n   * The day that starts the week.\n   */\n  firstDayOfWeek?: 'sun' | 'mon' | 'tue' | 'wed' | 'thu' | 'fri' | 'sat';\n}\n\nexport interface CalendarGridAria {\n  /** Props for the date grid element (e.g. `<table>`). */\n  gridProps: DOMAttributes;\n  /** Props for the grid header element (e.g. `<thead>`). */\n  headerProps: DOMAttributes;\n  /**\n   * A list of week day abbreviations formatted for the current locale, typically used in column\n   * headers.\n   */\n  weekDays: string[];\n  /** The number of weeks in the month. */\n  weeksInMonth: number;\n}\n\n/**\n * Provides the behavior and accessibility implementation for a calendar grid component.\n * A calendar grid displays a single grid of days within a calendar or range calendar which\n * can be keyboard navigated and selected by the user.\n */\nexport function useCalendarGrid(\n  props: AriaCalendarGridProps,\n  state: CalendarState<CalendarSelectionMode> | RangeCalendarState\n): CalendarGridAria {\n  let {\n    startDate = state.visibleRange.start,\n    endDate = state.visibleRange.end,\n    firstDayOfWeek\n  } = props;\n\n  let {direction} = useLocale();\n\n  let {keyboardProps} = useKeyboard({\n    shortcuts: {\n      End: () => {\n        state.focusSectionEnd();\n      },\n      Home: () => {\n        state.focusSectionStart();\n      },\n      Escape: () => {\n        // Cancel the selection.\n        if ('setAnchorDate' in state) {\n          state.setAnchorDate(null);\n        }\n        return false; // TODO: is this really correct? or should it return true when we cancel and only propagate if there's nothing to do\n      }\n    }\n  });\n\n  let {keyboardProps: repeatKeyboardProps} = useKeyboard({\n    shortcuts: {\n      Enter: () => {\n        state.selectFocusedDate();\n      },\n      ' ': () => {\n        state.selectFocusedDate();\n      },\n      PageUp: () => {\n        state.focusPreviousSection();\n      },\n      'Shift+PageUp': () => {\n        state.focusPreviousSection(true);\n      },\n      PageDown: () => {\n        state.focusNextSection();\n      },\n      'Shift+PageDown': () => {\n        state.focusNextSection(true);\n      },\n      ArrowLeft: () => {\n        if (direction === 'rtl') {\n          state.focusNextDay();\n        } else {\n          state.focusPreviousDay();\n        }\n      },\n      ArrowUp: () => {\n        state.focusPreviousRow();\n      },\n      ArrowRight: () => {\n        if (direction === 'rtl') {\n          state.focusPreviousDay();\n        } else {\n          state.focusNextDay();\n        }\n      },\n      ArrowDown: () => {\n        state.focusNextRow();\n      }\n    },\n    allowRepeats: true\n  });\n\n  let visibleRangeDescription = useVisibleRangeDescription(\n    startDate,\n    endDate,\n    state.timeZone,\n    true\n  );\n\n  let {ariaLabel, ariaLabelledBy} = hookData.get(state)!;\n  let labelProps = useLabels({\n    'aria-label': [ariaLabel, visibleRangeDescription].filter(Boolean).join(', '),\n    'aria-labelledby': ariaLabelledBy\n  });\n\n  let dayFormatter = useDateFormatter({\n    weekday: props.weekdayStyle || 'narrow',\n    timeZone: state.timeZone\n  });\n  let {locale} = useLocale();\n  let weekDays = useMemo(() => {\n    let isDayView = state.visibleDuration.days && state.visibleDuration.days < 7;\n    let weekStart = isDayView\n      ? startDate\n      : startOfWeek(today(state.timeZone), locale, firstDayOfWeek);\n    let days = isDayView ? state.visibleDuration.days! : 7;\n    return [...new Array(days).keys()].map(index => {\n      let date = weekStart.add({days: index});\n      let dateDay = date.toDate(state.timeZone);\n      return dayFormatter.format(dateDay);\n    });\n  }, [locale, state.timeZone, dayFormatter, firstDayOfWeek, startDate, state.visibleDuration.days]);\n  let weeksInMonth = state.getWeeksInMonth(startDate);\n\n  return {\n    gridProps: mergeProps(\n      labelProps,\n      {\n        role: 'grid',\n        'aria-readonly': state.isReadOnly || undefined,\n        'aria-disabled': state.isDisabled || undefined,\n        'aria-multiselectable':\n          'highlightedRange' in state || state.selectionMode === 'multiple' || undefined,\n        onFocus: () => state.setFocused(true),\n        onBlur: () => state.setFocused(false)\n      },\n      keyboardProps,\n      repeatKeyboardProps\n    ),\n    headerProps: {\n      // Column headers are hidden to screen readers to make navigating with a touch screen reader easier.\n      // The day names are already included in the label of each cell, so there's no need to announce them twice.\n      'aria-hidden': true\n    },\n    weekDays,\n    weeksInMonth\n  };\n}\n"],"names":[],"version":3,"file":"useCalendarGrid.cjs.map"}