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AAW;YACT,MAAM;YACN,iBAAiB,CAAC,gBAAgB;YAClC,iBAAiB,cAAc;YAC/B,gBAAgB,aAAa;QAC/B;QACA,aAAa,CAAA,GAAA,oCAAS,EAAE,YAAY;YAClC;gBACE,IAAI,CAAC,YAAY;oBACf,MAAM,cAAc,CAAC;oBACrB,MAAM,UAAU,CAAC;gBACnB;YACF;sBACA;YACA,MAAM;YACN,iBAAiB,CAAC,gBAAgB;YAClC,cAAc;YACd,gBAAgB,aAAa;YAC7B,oBACE;gBAAC,YAAY,iBAAiB;gBAAW,gBAAgB,CAAC,mBAAmB;aAAC,CAC3E,MAAM,CAAC,SACP,IAAI,CAAC,QAAQ;YAClB,gBAAe,CAAC;gBACd,0EAA0E;gBAC1E,IACE,mBAAmB,SAClB,CAAA,EAAE,WAAW,KAAK,WAAW,MAAM,UAAU,AAAD,KAC7C,cAEA,MAAM,aAAa,CAAC;YAExB;YACA,eAAc,CAAe;gBAC3B,uDAAuD;gBACvD,wCAAwC;gBACxC,gCAAgC;gBAChC,IAAI,SAAS,CAAA,GAAA,wCAAa,EAAE;gBAC5B,IAAI,kBAAkB,eAAe,2BAA2B,QAAQ;oBACtE,IAAI,uBAAuB,QACzB;wBAAA,IAAI,OAAO,iBAAiB,CAAC,EAAE,SAAS,GACtC,OAAO,qBAAqB,CAAC,EAAE,SAAS;oBAC1C,OAEA,AAAC,OAAuB,qBAAqB,CAAC,EAAE,SAAS;gBAE7D;YACF;YACA,eAAc,CAAC;gBACb,sCAAsC;gBACtC,EAAE,cAAc;YAClB;QACF;mBACA;mBACA;oBACA;oBACA;uBACA;QACA,uBACE,KAAK,OAAO,CAAC,MAAM,YAAY,CAAC,KAAK,IAAI,KAAK,KAAK,OAAO,CAAC,MAAM,YAAY,CAAC,GAAG,IAAI;mBACvF;uBACA;IACF;AACF","sources":["packages/react-aria/src/calendar/useCalendarCell.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, isEqualDay, isSameDay, isToday} from '@internationalized/date';\nimport {CalendarSelectionMode, CalendarState} from 'react-stately/useCalendarState';\nimport {DOMAttributes, RefObject} from '@react-types/shared';\nimport {focusWithoutScrolling} from '../utils/focusWithoutScrolling';\nimport {getActiveElement, getEventTarget} from '../utils/shadowdom/DOMFunctions';\nimport {getEraFormat, hookData} from './utils';\nimport {getInteractionModality} from '../interactions/useFocusVisible';\nimport {getScrollParent} from '../utils/getScrollParent';\nimport intlMessages from '../../intl/calendar/*.json';\nimport {mergeProps} from '../utils/mergeProps';\nimport {RangeCalendarState} from 'react-stately/useRangeCalendarState';\nimport {scrollIntoViewport} from '../utils/scrollIntoView';\nimport {useDateFormatter} from '../i18n/useDateFormatter';\nimport {useDeepMemo} from '../utils/useDeepMemo';\nimport {useDescription} from '../utils/useDescription';\nimport {useEffect, useMemo, useRef} from 'react';\nimport {useLocalizedStringFormatter} from '../i18n/useLocalizedStringFormatter';\nimport {usePress} from '../interactions/usePress';\n\nexport interface AriaCalendarCellProps {\n /** The date that this cell represents. */\n date: CalendarDate;\n /**\n * Whether the cell is disabled. By default, this is determined by the\n * Calendar's `minValue`, `maxValue`, and `isDisabled` props.\n */\n isDisabled?: boolean;\n\n /**\n * Whether the cell is outside of the current month.\n */\n isOutsideMonth?: boolean;\n}\n\nexport interface CalendarCellAria {\n /** Props for the grid cell element (e.g. `<td>`). */\n cellProps: DOMAttributes;\n /** Props for the button element within the cell. */\n buttonProps: DOMAttributes;\n /** Whether the cell is currently being pressed. */\n isPressed: boolean;\n /** Whether the cell is selected. */\n isSelected: boolean;\n /** Whether the cell is focused. */\n isFocused: boolean;\n /**\n * Whether the cell is disabled, according to the calendar's `minValue`, `maxValue`, and\n * `isDisabled` props. Disabled dates are not focusable, and cannot be selected by the user. They\n * are typically displayed with a dimmed appearance.\n */\n isDisabled: boolean;\n /**\n * Whether the cell is unavailable, according to the calendar's `isDateUnavailable` prop.\n * Unavailable dates remain focusable, but cannot be selected by the user. They should be\n * displayed with a visual affordance to indicate they are unavailable, such as a different color\n * or a strikethrough.\n *\n * Note that because they are focusable, unavailable dates must meet a 4.5:1 color contrast ratio,\n * [as defined by WCAG](https://www.w3.org/WAI/WCAG21/Understanding/contrast-minimum.html).\n */\n isUnavailable: boolean;\n /**\n * Whether the cell is outside the visible range of the calendar.\n * For example, dates before the first day of a month in the same week.\n */\n isOutsideVisibleRange: boolean;\n /** Whether the cell is part of an invalid selection. */\n isInvalid: boolean;\n /** The day number formatted according to the current locale. */\n formattedDate: string;\n}\n\n/**\n * Provides the behavior and accessibility implementation for a calendar cell component.\n * A calendar cell displays a date cell within a calendar grid which can be selected by the user.\n */\nexport function useCalendarCell(\n props: AriaCalendarCellProps,\n state: CalendarState<CalendarSelectionMode> | RangeCalendarState,\n ref: RefObject<HTMLElement | null>\n): CalendarCellAria {\n let {date, isDisabled} = props;\n let {errorMessageId, selectedDateDescription} = hookData.get(state)!;\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/calendar');\n let dateFormatter = useDateFormatter({\n weekday: 'long',\n day: 'numeric',\n month: 'long',\n year: 'numeric',\n era: getEraFormat(date),\n timeZone: state.timeZone\n });\n let isFocused = state.isCellFocused(date) && !props.isOutsideMonth;\n isDisabled = isDisabled || state.isCellDisabled(date) || !!props.isOutsideMonth;\n let isUnavailable = state.isCellUnavailable(date);\n let isSelectable = !isDisabled && !isUnavailable;\n let isSelected = state.isSelected(date) && isSelectable;\n let isInvalid = false;\n if (state.isValueInvalid) {\n if ('highlightedRange' in state) {\n isInvalid =\n !state.anchorDate &&\n state.highlightedRange != null &&\n date.compare(state.highlightedRange.start) >= 0 &&\n date.compare(state.highlightedRange.end) <= 0;\n } else if (Array.isArray(state.value)) {\n isInvalid = state.value.some(value => isSameDay(value, date));\n } else if (state.value) {\n isInvalid = isSameDay(state.value as CalendarDate, date);\n }\n }\n\n if (isInvalid && !isDisabled) {\n isSelected = true;\n }\n\n // For performance, reuse the same date object as before if the new date prop is the same.\n // This allows subsequent useMemo results to be reused.\n date = useDeepMemo<CalendarDate>(date, isEqualDay);\n let nativeDate = useMemo(() => date.toDate(state.timeZone), [date, state.timeZone]);\n\n // aria-label should be localize Day of week, Month, Day and Year without Time.\n let isDateToday = isToday(date, state.timeZone);\n let label = useMemo(() => {\n let label = '';\n\n // If this is a range calendar, add a description of the full selected range\n // to the first and last selected date.\n if (\n 'highlightedRange' in state &&\n state.value &&\n !state.anchorDate &&\n (isSameDay(date, state.value.start) || isSameDay(date, state.value.end))\n ) {\n label = selectedDateDescription + ', ';\n }\n\n label += dateFormatter.format(nativeDate);\n if (isDateToday) {\n // If date is today, set appropriate string depending on selected state:\n label = stringFormatter.format(isSelected ? 'todayDateSelected' : 'todayDate', {\n date: label\n });\n } else if (isSelected) {\n // If date is selected but not today:\n label = stringFormatter.format('dateSelected', {\n date: label\n });\n }\n\n if (state.minValue && isSameDay(date, state.minValue)) {\n label += ', ' + stringFormatter.format('minimumDate');\n } else if (state.maxValue && isSameDay(date, state.maxValue)) {\n label += ', ' + stringFormatter.format('maximumDate');\n }\n\n return label;\n }, [\n dateFormatter,\n nativeDate,\n stringFormatter,\n isSelected,\n isDateToday,\n date,\n state,\n selectedDateDescription\n ]);\n\n // When a cell is focused and this is a range calendar, add a prompt to help\n // screenreader users know that they are in a range selection mode.\n let rangeSelectionPrompt = '';\n if ('anchorDate' in state && isFocused && !state.isReadOnly && isSelectable) {\n // If selection has started add \"click to finish selecting range\"\n if (state.anchorDate) {\n rangeSelectionPrompt = stringFormatter.format('finishRangeSelectionPrompt');\n // Otherwise, add \"click to start selecting range\" prompt\n } else {\n rangeSelectionPrompt = stringFormatter.format('startRangeSelectionPrompt');\n }\n }\n\n let descriptionProps = useDescription(rangeSelectionPrompt);\n\n let isAnchorPressed = useRef(false);\n let isRangeBoundaryPressed = useRef(false);\n let touchDragTimerRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n let {pressProps, isPressed} = usePress({\n // When dragging to select a range, we don't want dragging over the original anchor\n // again to trigger onPressStart. Cancel presses immediately when the pointer exits.\n shouldCancelOnPointerExit: 'anchorDate' in state && !!state.anchorDate,\n preventFocusOnPress: true,\n isDisabled: !isSelectable || state.isReadOnly,\n onPressStart(e) {\n if (state.isReadOnly) {\n state.setFocusedDate(date);\n state.setFocused(true);\n return;\n }\n\n if (\n 'highlightedRange' in state &&\n !state.anchorDate &&\n (e.pointerType === 'mouse' || e.pointerType === 'touch')\n ) {\n // Allow dragging the start or end date of a range to modify it\n // rather than starting a new selection.\n // Don't allow dragging when invalid, or weird jumping behavior may occur as date ranges\n // are constrained to available dates. The user will need to select a new range in this case.\n if (state.highlightedRange && !isInvalid) {\n if (isSameDay(date, state.highlightedRange.start)) {\n state.setAnchorDate(state.highlightedRange.end);\n state.setFocusedDate(date);\n state.setFocused(true);\n state.setDragging(true);\n isRangeBoundaryPressed.current = true;\n return;\n } else if (isSameDay(date, state.highlightedRange.end)) {\n state.setAnchorDate(state.highlightedRange.start);\n state.setFocusedDate(date);\n state.setFocused(true);\n state.setDragging(true);\n isRangeBoundaryPressed.current = true;\n return;\n }\n }\n\n let startDragging = () => {\n state.setDragging(true);\n touchDragTimerRef.current = undefined;\n\n state.selectDate(date);\n state.setFocusedDate(date);\n state.setFocused(true);\n isAnchorPressed.current = true;\n };\n\n // Start selection on mouse/touch down so users can drag to select a range.\n // On touch, delay dragging to determine if the user really meant to scroll.\n if (e.pointerType === 'touch') {\n touchDragTimerRef.current = setTimeout(startDragging, 200);\n } else {\n startDragging();\n }\n }\n },\n onPressEnd() {\n isRangeBoundaryPressed.current = false;\n isAnchorPressed.current = false;\n clearTimeout(touchDragTimerRef.current);\n touchDragTimerRef.current = undefined;\n },\n onPress() {\n // For non-range selection, always select on press up.\n if (!('anchorDate' in state) && !state.isReadOnly) {\n state.selectDate(date);\n state.setFocusedDate(date);\n state.setFocused(true);\n }\n },\n onPressUp(e) {\n if (state.isReadOnly) {\n return;\n }\n\n // If the user tapped quickly, the date won't be selected yet and the\n // timer will still be in progress. In this case, select the date on touch up.\n // Timer is cleared in onPressEnd.\n if ('anchorDate' in state && touchDragTimerRef.current) {\n state.selectDate(date);\n state.setFocusedDate(date);\n state.setFocused(true);\n }\n\n if ('anchorDate' in state) {\n if (isRangeBoundaryPressed.current) {\n // When clicking on the start or end date of an already selected range,\n // start a new selection on press up to also allow dragging the date to\n // change the existing range.\n state.setAnchorDate(date);\n } else if (state.anchorDate && !isAnchorPressed.current) {\n // When releasing a drag or pressing the end date of a range, select it.\n state.selectDate(date);\n state.setFocusedDate(date);\n state.setFocused(true);\n } else if (e.pointerType === 'keyboard' && !state.anchorDate) {\n // For range selection, auto-advance the focused date by one if using keyboard.\n // This gives an indication that you're selecting a range rather than a single date.\n // For mouse, this is unnecessary because users will see the indication on hover. For screen readers,\n // there will be an announcement to \"click to finish selecting range\" (above).\n state.selectDate(date);\n state.focusNearestAvailableDate(date);\n } else if (e.pointerType === 'virtual') {\n // For screen readers, just select the date on click.\n state.selectDate(date);\n state.setFocusedDate(date);\n state.setFocused(true);\n }\n }\n }\n });\n\n let tabIndex: number | undefined = undefined;\n if (!isDisabled) {\n tabIndex = isSameDay(date, state.focusedDate) ? 0 : -1;\n }\n\n // Focus the button in the DOM when the state updates.\n useEffect(() => {\n if (isFocused && ref.current) {\n focusWithoutScrolling(ref.current);\n\n // Scroll into view if navigating with a keyboard, otherwise\n // try not to shift the view under the user's mouse/finger.\n // If in a overlay, scrollIntoViewport will only cause scrolling\n // up to the overlay scroll body to prevent overlay shifting.\n // Also only scroll into view if the cell actually got focused.\n // There are some cases where the cell might be disabled or inside,\n // an inert container and we don't want to scroll then.\n if (getInteractionModality() !== 'pointer' && getActiveElement() === ref.current) {\n scrollIntoViewport(ref.current, {containingElement: getScrollParent(ref.current)});\n }\n }\n }, [isFocused, ref]);\n\n let cellDateFormatter = useDateFormatter({\n day: 'numeric',\n timeZone: state.timeZone,\n calendar: date.calendar.identifier\n });\n\n let formattedDate = useMemo(\n () => cellDateFormatter.formatToParts(nativeDate).find(part => part.type === 'day')!.value,\n [cellDateFormatter, nativeDate]\n );\n\n return {\n cellProps: {\n role: 'gridcell',\n 'aria-disabled': !isSelectable || undefined,\n 'aria-selected': isSelected || undefined,\n 'aria-invalid': isInvalid || undefined\n },\n buttonProps: mergeProps(pressProps, {\n onFocus() {\n if (!isDisabled) {\n state.setFocusedDate(date);\n state.setFocused(true);\n }\n },\n tabIndex,\n role: 'button',\n 'aria-disabled': !isSelectable || undefined,\n 'aria-label': label,\n 'aria-invalid': isInvalid || undefined,\n 'aria-describedby':\n [isInvalid ? errorMessageId : undefined, descriptionProps['aria-describedby']]\n .filter(Boolean)\n .join(' ') || undefined,\n onPointerEnter(e) {\n // Highlight the date on hover or drag over a date when selecting a range.\n if (\n 'highlightDate' in state &&\n (e.pointerType !== 'touch' || state.isDragging) &&\n isSelectable\n ) {\n state.highlightDate(date);\n }\n },\n onPointerDown(e: PointerEvent) {\n // This is necessary on touch devices to allow dragging\n // outside the original pressed element.\n // (JSDOM does not support this)\n let target = getEventTarget(e);\n if (target instanceof HTMLElement && 'releasePointerCapture' in target) {\n if ('hasPointerCapture' in target) {\n if (target.hasPointerCapture(e.pointerId)) {\n target.releasePointerCapture(e.pointerId);\n }\n } else {\n (target as HTMLElement).releasePointerCapture(e.pointerId);\n }\n }\n },\n onContextMenu(e) {\n // Prevent context menu on long press.\n e.preventDefault();\n }\n }),\n isPressed,\n isFocused,\n isSelected,\n isDisabled,\n isUnavailable,\n isOutsideVisibleRange:\n date.compare(state.visibleRange.start) < 0 || date.compare(state.visibleRange.end) > 0,\n isInvalid,\n formattedDate\n };\n}\n"],"names":[],"version":3,"file":"useCalendarCell.cjs.map"}