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C,CAAA,CAAC,EAAE,aAAa,IAAI,CAAC,CAAA,GAAA,sCAAW,EAAE,IAAI,OAAO,EAAE,EAAE,aAAa,CAAA,KAAM,MAAM,UAAU,EACvF,qBAAqB,CAAC,eAAe;IAEzC;IAEA,yCAAyC;IACzC,CAAA,GAAA,kCAAO,EAAE,KAAK,aAAa,CAAA;QACzB,IAAI,MAAM,UAAU,EAClB,EAAE,cAAc;IAEpB,GAAG;QAAC,SAAS;QAAO,SAAS;IAAI;IAEjC,OAAO;AACT","sources":["packages/react-aria/src/calendar/useRangeCalendar.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 {AriaLabelingProps, DOMProps, FocusableElement, RefObject} from '@react-types/shared';\nimport {CalendarAria, useCalendarBase} from './useCalendarBase';\nimport {DateValue, RangeCalendarState} from 'react-stately/useRangeCalendarState';\nimport {isFocusWithin, nodeContains} from '../utils/shadowdom/DOMFunctions';\nimport {RangeCalendarProps} from 'react-stately/useRangeCalendarState';\nimport {useEvent} from '../utils/useEvent';\nimport {useRef} from 'react';\n\nexport interface AriaRangeCalendarProps<T extends DateValue> extends RangeCalendarProps<T>, DOMProps, AriaLabelingProps {\n  /**\n   * Controls the behavior when a pointer is released outside the calendar or a blur occurs mid selection:\n   *\n   * - `clear`: clear the currently selected range of dates.\n   *\n   * - `reset`: reset the selection to the previously selected range of dates.\n   *\n   * - `select`: select the currently hovered range of dates.\n   * @default 'select'\n   */\n  commitBehavior?: 'clear' | 'reset' | 'select'\n}\n\n/**\n * Provides the behavior and accessibility implementation for a range calendar component.\n * A range calendar displays one or more date grids and allows users to select a contiguous range of dates.\n */\nexport function useRangeCalendar<T extends DateValue>(props: AriaRangeCalendarProps<T>, state: RangeCalendarState, ref: RefObject<FocusableElement | null>): CalendarAria {\n  let {commitBehavior = 'select', ...otherProps} = props;\n  let res = useCalendarBase(otherProps, state);\n\n  // We need to ignore virtual pointer events from VoiceOver due to these bugs.\n  // https://bugs.webkit.org/show_bug.cgi?id=222627\n  // https://bugs.webkit.org/show_bug.cgi?id=223202\n  // usePress also does this and waits for the following click event before firing.\n  // We need to match that here otherwise this will fire before the press event in\n  // useCalendarCell, causing range selection to not work properly.\n  let isVirtualClick = useRef(false);\n  let windowRef = useRef(typeof window !== 'undefined' ? window : null);\n  useEvent(windowRef, 'pointerdown', e => {\n    isVirtualClick.current = e.width === 0 && e.height === 0;\n  });\n\n  const commitBehaviorMapping = {\n    clear: () => state.clearSelection(),\n    reset: () => state.setAnchorDate(null),\n    select: () => state.selectFocusedDate()\n  };\n\n  // Execute method corresponding to `commitBehavior` when pressing or releasing a pointer outside the calendar body,\n  // except when pressing the next or previous buttons to switch months.\n  let endDragging = (e: PointerEvent) => {\n    if (isVirtualClick.current) {\n      isVirtualClick.current = false;\n      return;\n    }\n\n    state.setDragging(false);\n    if (!state.anchorDate) {\n      return;\n    }\n\n    let target = e.target as Element;\n    if (\n      ref.current &&\n      isFocusWithin(ref.current) &&\n      (!nodeContains(ref.current, target) || !target.closest('button, [role=\"button\"]'))\n    ) {\n      commitBehaviorMapping[commitBehavior]();\n    }\n  };\n\n  useEvent(windowRef, 'pointerup', endDragging);\n\n  // Also execute method corresponding to `commitBehavior` on blur,\n  // e.g. tabbing away from the calendar.\n  res.calendarProps.onBlur = e => {\n    if (!ref.current) {\n      return;\n    }\n\n    if ((!e.relatedTarget || !nodeContains(ref.current, e.relatedTarget)) && state.anchorDate) {\n      commitBehaviorMapping[commitBehavior]();\n    }\n  };\n\n  // Prevent touch scrolling while dragging\n  useEvent(ref, 'touchmove', e => {\n    if (state.isDragging) {\n      e.preventDefault();\n    }\n  }, {passive: false, capture: true});\n\n  return res;\n}\n"],"names":[],"version":3,"file":"useRangeCalendar.cjs.map"}