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E,cAAc;QAChB,QAAQ,UAAU,CAAC;IACrB;IAEA,IAAI,WAAW;QACb,GAAG,CAAA,GAAA,yCAAS,EAAE,eAAe,oBAAoB;iBACjD;gBACA;QACA,aAAY,CAAC;YACX,8CAA8C;YAC9C,IAAI,UAAU,OAAO,KAAK,CAAA,GAAA,yCAAa,EAAE,IACvC,wEAAwE;YACxE,EAAE,cAAc;QAEpB;IACF;IAEA,IAAI,mBAAC,eAAe,EAAC,GAAG,CAAA,GAAA,yCAAY,EAAE;QACpC,kBAAkB;QAClB,kBAAkB;IACpB;IAEA,IAAI,CAAC,mBACH,gDAAgD;IAChD,WAAW,CAAA,GAAA,yCAAS,EAAE,iBAAiB;IAGzC,oFAAoF;IACpF,+FAA+F;IAC/F,IAAI,WAA+B;IACnC,IAAI,CAAC,uBACH,WAAW,QAAQ,UAAU,IAAI,OAAO,IAAI;IAG9C,IAAI,eAAe,CAAA,GAAA,yCAAc,EAAE,QAAQ,UAAU;IACrD,OAAO;QACL,gDAAgD;QAChD,iBAAiB,CAAA,GAAA,yCAAS,EAAE,UAAU;sBACpC;YACA,mBAAmB;QACrB;IACF;AACF","sources":["packages/react-aria/src/selection/useSelectableCollection.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 {CLEAR_FOCUS_EVENT, FOCUS_EVENT} from '../utils/constants';\n\nimport {dispatchVirtualFocus, moveVirtualFocus} from '../focus/virtualFocus';\nimport {\n  DOMAttributes,\n  FocusableElement,\n  FocusStrategy,\n  Key,\n  KeyboardDelegate,\n  KeyboardEvent,\n  RefObject\n} from '@react-types/shared';\nimport {flushSync} from 'react-dom';\nimport {FocusEvent, useEffect, useRef} from 'react';\nimport {focusSafely} from '../interactions/focusSafely';\nimport {focusWithoutScrolling} from '../utils/focusWithoutScrolling';\nimport {\n  getActiveElement,\n  getEventTarget,\n  isFocusWithin,\n  nodeContains\n} from '../utils/shadowdom/DOMFunctions';\nimport {getFocusableTreeWalker} from '../focus/FocusScope';\nimport {getInteractionModality} from '../interactions/useFocusVisible';\nimport {getItemElement, isNonContiguousSelectionModifier, useCollectionId} from './utils';\nimport {isCtrlKeyPressed} from '../utils/keyboard';\nimport {isMac} from '../utils/platform';\nimport {isTabbable} from '../utils/isFocusable';\nimport {mergeProps} from '../utils/mergeProps';\nimport {MultipleSelectionManager} from 'react-stately/useMultipleSelectionState';\nimport {scrollIntoView, scrollIntoViewport} from '../utils/scrollIntoView';\nimport {useEvent} from '../utils/useEvent';\nimport {useKeyboard} from '../interactions/useKeyboard';\nimport {useLocale} from '../i18n/I18nProvider';\nimport {useRouter} from '../utils/openLink';\nimport {useTypeSelect} from './useTypeSelect';\nimport {useUpdateLayoutEffect} from '../utils/useUpdateLayoutEffect';\n\nexport interface AriaSelectableCollectionOptions {\n  /**\n   * An interface for reading and updating multiple selection state.\n   */\n  selectionManager: MultipleSelectionManager;\n  /**\n   * A delegate object that implements behavior for keyboard focus movement.\n   */\n  keyboardDelegate: KeyboardDelegate;\n  /**\n   * The ref attached to the element representing the collection.\n   */\n  ref: RefObject<HTMLElement | null>;\n  /**\n   * Whether the collection or one of its items should be automatically focused upon render.\n   *\n   * @default false\n   */\n  autoFocus?: boolean | FocusStrategy;\n  /**\n   * Whether focus should wrap around when the end/start is reached.\n   *\n   * @default false\n   */\n  shouldFocusWrap?: boolean;\n  /**\n   * Whether the collection allows empty selection.\n   *\n   * @default false\n   */\n  disallowEmptySelection?: boolean;\n  /**\n   * Whether the collection allows the user to select all items via keyboard shortcut.\n   *\n   * @default false\n   */\n  disallowSelectAll?: boolean;\n  /**\n   * Whether pressing the Escape should clear selection in the collection or not.\n   *\n   * @default 'clearSelection'\n   */\n  escapeKeyBehavior?: 'clearSelection' | 'none';\n  /**\n   * Whether selection should occur automatically on focus.\n   *\n   * @default false\n   */\n  selectOnFocus?: boolean;\n  /**\n   * Whether typeahead is disabled.\n   *\n   * @default false\n   */\n  disallowTypeAhead?: boolean;\n  /**\n   * Whether the collection items should use virtual focus instead of being focused directly.\n   */\n  shouldUseVirtualFocus?: boolean;\n  /**\n   * Whether navigation through tab key is enabled.\n   */\n  allowsTabNavigation?: boolean;\n  /**\n   * Whether the collection items are contained in a virtual scroller.\n   */\n  isVirtualized?: boolean;\n  /**\n   * The ref attached to the scrollable body. Used to provide automatic scrolling on item focus for\n   * non-virtualized collections. If not provided, defaults to the collection ref.\n   */\n  scrollRef?: RefObject<HTMLElement | null>;\n  /**\n   * The behavior of links in the collection.\n   * - 'action': link behaves like onAction.\n   * - 'selection': link follows selection interactions (e.g. if URL drives selection).\n   * - 'override': links override all other interactions (link items are not selectable).\n   *\n   * @default 'action'\n   */\n  linkBehavior?: 'action' | 'selection' | 'override';\n  /**\n   * Which item in the collection to focus when tabbing into the collection. Overrides default\n   * roving tab index like behavior.\n   *\n   * @private\n   */\n  UNSTABLE_focusOnEntry?: 'first' | 'last';\n}\n\nexport interface SelectableCollectionAria {\n  /** Props for the collection element. */\n  collectionProps: DOMAttributes;\n}\n\n/**\n * Handles interactions with selectable collections.\n */\nexport function useSelectableCollection(\n  options: AriaSelectableCollectionOptions\n): SelectableCollectionAria {\n  let {\n    selectionManager: manager,\n    keyboardDelegate: delegate,\n    ref,\n    autoFocus = false,\n    shouldFocusWrap = false,\n    disallowEmptySelection = false,\n    disallowSelectAll = false,\n    escapeKeyBehavior = 'clearSelection',\n    selectOnFocus = manager.selectionBehavior === 'replace',\n    disallowTypeAhead = false,\n    shouldUseVirtualFocus,\n    allowsTabNavigation = false,\n    // If no scrollRef is provided, assume the collection ref is the scrollable region\n    scrollRef = ref,\n    linkBehavior = 'action',\n    UNSTABLE_focusOnEntry\n  } = options;\n  let {direction} = useLocale();\n  let router = useRouter();\n\n  const navigateToKey = (\n    e: KeyboardEvent,\n    key: Key | undefined,\n    childFocus?: FocusStrategy\n  ): boolean | void => {\n    if (key != null) {\n      if (\n        manager.isLink(key) &&\n        linkBehavior === 'selection' &&\n        selectOnFocus &&\n        !isNonContiguousSelectionModifier(e)\n      ) {\n        // Set focused key and re-render synchronously to bring item into view if needed.\n        flushSync(() => {\n          manager.setFocusedKey(key, childFocus);\n        });\n\n        let item = getItemElement(ref, key);\n        let itemProps = manager.getItemProps(key);\n        if (item) {\n          router.open(item, e, itemProps.href, itemProps.routerOptions);\n          return;\n        }\n\n        return false;\n      }\n\n      manager.setFocusedKey(key, childFocus);\n\n      if (manager.isLink(key) && linkBehavior === 'override') {\n        return false;\n      }\n\n      if (e.shiftKey && manager.selectionMode === 'multiple') {\n        manager.extendSelection(key);\n        return;\n      } else if (selectOnFocus && !isNonContiguousSelectionModifier(e)) {\n        manager.replaceSelection(key);\n        return;\n      }\n    }\n    return false;\n  };\n\n  let arrowDown = (e: KeyboardEvent) => {\n    if (delegate.getKeyBelow) {\n      let nextKey =\n        manager.focusedKey != null\n          ? delegate.getKeyBelow?.(manager.focusedKey)\n          : delegate.getFirstKey?.();\n      if (nextKey == null && shouldFocusWrap) {\n        nextKey = delegate.getFirstKey?.(manager.focusedKey);\n      }\n      if (nextKey != null) {\n        navigateToKey(e, nextKey);\n        return;\n      }\n    }\n    return false;\n  };\n\n  let arrowUp = (e: KeyboardEvent) => {\n    if (delegate.getKeyAbove) {\n      let nextKey =\n        manager.focusedKey != null\n          ? delegate.getKeyAbove?.(manager.focusedKey)\n          : delegate.getLastKey?.();\n      if (nextKey == null && shouldFocusWrap) {\n        nextKey = delegate.getLastKey?.(manager.focusedKey);\n      }\n      if (nextKey != null) {\n        navigateToKey(e, nextKey);\n        return;\n      }\n    }\n    return false;\n  };\n\n  let home = (e: KeyboardEvent) => {\n    if (delegate.getFirstKey) {\n      if (manager.focusedKey === null && e.shiftKey) {\n        return false;\n      }\n      // TODO: should Home and End also be reversed in column reverse aka Home goes to top? Or should Home always to to the \"first\" (bottom)\n      let firstKey: Key | null = delegate.getFirstKey(manager.focusedKey, isCtrlKeyPressed(e));\n      manager.setFocusedKey(firstKey);\n      if (firstKey != null) {\n        if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n          manager.extendSelection(firstKey);\n          return;\n        } else if (selectOnFocus) {\n          manager.replaceSelection(firstKey);\n          return;\n        }\n      }\n    }\n    return false;\n  };\n\n  let arrowLeft = (e: KeyboardEvent) => {\n    if (delegate.getKeyLeftOf) {\n      let nextKey: Key | undefined | null =\n        manager.focusedKey != null\n          ? delegate.getKeyLeftOf?.(manager.focusedKey)\n          : delegate.getFirstKey?.();\n      if (nextKey == null && shouldFocusWrap) {\n        nextKey =\n          direction === 'rtl'\n            ? delegate.getFirstKey?.(manager.focusedKey)\n            : delegate.getLastKey?.(manager.focusedKey);\n      }\n      if (nextKey != null) {\n        navigateToKey(e, nextKey, direction === 'rtl' ? 'first' : 'last');\n        return;\n      }\n    }\n    return false;\n  };\n\n  let arrowRight = (e: KeyboardEvent) => {\n    if (delegate.getKeyRightOf) {\n      let nextKey: Key | undefined | null =\n        manager.focusedKey != null\n          ? delegate.getKeyRightOf?.(manager.focusedKey)\n          : delegate.getFirstKey?.();\n      if (nextKey == null && shouldFocusWrap) {\n        nextKey =\n          direction === 'rtl'\n            ? delegate.getLastKey?.(manager.focusedKey)\n            : delegate.getFirstKey?.(manager.focusedKey);\n      }\n      if (nextKey != null) {\n        navigateToKey(e, nextKey, direction === 'rtl' ? 'last' : 'first');\n        return;\n      }\n    }\n    return false;\n  };\n\n  let end = (e: KeyboardEvent) => {\n    if (delegate.getLastKey) {\n      if (manager.focusedKey === null && e.shiftKey) {\n        return false;\n      }\n      let lastKey = delegate.getLastKey(manager.focusedKey, isCtrlKeyPressed(e));\n      manager.setFocusedKey(lastKey);\n      if (lastKey != null) {\n        if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n          manager.extendSelection(lastKey);\n          return;\n        } else if (selectOnFocus) {\n          manager.replaceSelection(lastKey);\n          return;\n        }\n      }\n    }\n    return false;\n  };\n\n  let pageDown = (e: KeyboardEvent) => {\n    if (delegate.getKeyPageBelow && manager.focusedKey != null) {\n      let nextKey = delegate.getKeyPageBelow(manager.focusedKey);\n      if (nextKey != null) {\n        return navigateToKey(e, nextKey);\n      }\n    }\n    return false;\n  };\n\n  let pageUp = (e: KeyboardEvent) => {\n    if (delegate.getKeyPageAbove && manager.focusedKey != null) {\n      let nextKey = delegate.getKeyPageAbove(manager.focusedKey);\n      if (nextKey != null) {\n        return navigateToKey(e, nextKey);\n      }\n    }\n    return false;\n  };\n\n  let aHandler = () => {\n    if (manager.selectionMode === 'multiple' && disallowSelectAll !== true) {\n      manager.selectAll();\n      return;\n    }\n    return false;\n  };\n\n  let escape = () => {\n    if (\n      escapeKeyBehavior === 'clearSelection' &&\n      !disallowEmptySelection &&\n      manager.selectedKeys.size !== 0\n    ) {\n      manager.clearSelection();\n      return;\n    }\n    return false;\n  };\n\n  let tab = () => {\n    if (!allowsTabNavigation && ref.current) {\n      // There may be elements that are \"tabbable\" inside a collection (e.g. in a grid cell).\n      // However, collections should be treated as a single tab stop, with arrow key navigation internally.\n      // We don't control the rendering of these, so we can't override the tabIndex to prevent tabbing.\n      // Instead, we handle the Tab key, and move focus manually to the first/last tabbable element\n      // in the collection, so that the browser default behavior will apply starting from that element\n      // rather than the currently focused one.\n\n      let walker = getFocusableTreeWalker(ref.current, {tabbable: true});\n      let next: FocusableElement | undefined = undefined;\n      let last: FocusableElement;\n      do {\n        last = walker.lastChild() as FocusableElement;\n        if (last) {\n          next = last;\n        }\n      } while (last);\n\n      // If the active element is NOT tabbable but is contained by an element that IS tabbable (aka the cell), the browser will actually move focus to\n      // the containing element. We need to special case this so that tab will move focus out of the grid instead of looping between\n      // focusing the containing cell and back to the non-tabbable child element\n      let activeElement = getActiveElement();\n      if (next && (!isFocusWithin(next) || (activeElement && !isTabbable(activeElement)))) {\n        focusWithoutScrolling(next);\n      }\n    }\n    return {shouldContinuePropagation: true, shouldPreventDefault: false};\n  };\n\n  let shiftTab = () => {\n    if (!allowsTabNavigation && ref.current) {\n      ref.current.focus();\n    }\n    return {shouldContinuePropagation: true, shouldPreventDefault: false};\n  };\n\n  let withShiftSel = (key, callback) => {\n    return {\n      [isMac() ? key + '+Shift+Alt' : key + '+Shift+Control']: callback,\n      [key + '+Shift']: callback,\n      [isMac() ? key + '+Alt' : key + '+Control']: callback,\n      [key]: callback\n    };\n  };\n  // oxlint-disable react/react-compiler\n  let {keyboardProps: repeatKeyboardProps} = useKeyboard({\n    shortcuts: {\n      ...withShiftSel('ArrowDown', arrowDown),\n      ...withShiftSel('ArrowUp', arrowUp),\n      ...withShiftSel('ArrowLeft', arrowLeft),\n      ...withShiftSel('ArrowRight', arrowRight),\n      ...withShiftSel('PageDown', pageDown),\n      ...withShiftSel('PageUp', pageUp)\n    },\n    allowRepeats: true\n  });\n  // oxlint-disable react/react-compiler\n  let {keyboardProps} = useKeyboard({\n    shortcuts: {\n      ...withShiftSel('Home', home),\n      ...withShiftSel('End', end),\n      'Mod+A': aHandler,\n      Escape: escape,\n      Tab: tab,\n      'Tab+Shift': shiftTab\n    }\n  });\n  // oxlint-enable react/react-compiler\n\n  // Store the scroll position so we can restore it later.\n  /// TODO: should this happen all the time??\n  let scrollPos = useRef({top: 0, left: 0});\n  useEvent(scrollRef, 'scroll', () => {\n    scrollPos.current = {\n      top: scrollRef.current?.scrollTop ?? 0,\n      left: scrollRef.current?.scrollLeft ?? 0\n    };\n  });\n\n  let onFocus = (e: FocusEvent) => {\n    if (manager.isFocused) {\n      // If a focus event bubbled through a portal, reset focus state.\n      if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n        manager.setFocused(false);\n      }\n      return;\n    }\n\n    // Focus events can bubble through portals. Ignore these events.\n    if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n      return;\n    }\n\n    let modality = getInteractionModality();\n    manager.setFocused(true);\n    let navigateToKey = (key: Key | undefined | null) => {\n      if (key != null) {\n        manager.setFocusedKey(key);\n        if (selectOnFocus && !manager.isSelected(key)) {\n          manager.replaceSelection(key);\n        }\n      }\n    };\n\n    // we need the \"virtual\" modality case checks here because shift tabbing from the prompt field's attachment card back into the\n    // thread is a virtual focus event (the tab handler in onKeyDown focuses the ref of the attachmentList aka TagGroup via a focus() call, hence the virtual modality)\n    if (UNSTABLE_focusOnEntry && (modality === 'keyboard' || modality === 'virtual')) {\n      // always go to the first item in the Thread when tabbing forwards/backwards into the collection\n      // since it is probably more important to the user to see the new prompt reply rather than go to the last focused key\n      navigateToKey(\n        UNSTABLE_focusOnEntry === 'first' ? delegate.getFirstKey?.() : delegate.getLastKey?.()\n      );\n    } else if (manager.focusedKey == null) {\n      // If the user hasn't yet interacted with the collection, there will be no focusedKey set.\n      // Attempt to detect whether the user is tabbing forward or backward into the collection\n      // and either focus the first or last item accordingly.\n      let relatedTarget = e.relatedTarget as Element;\n      if (\n        relatedTarget &&\n        e.currentTarget.compareDocumentPosition(relatedTarget) & Node.DOCUMENT_POSITION_FOLLOWING\n      ) {\n        navigateToKey(manager.lastSelectedKey ?? delegate.getLastKey?.());\n      } else {\n        navigateToKey(manager.firstSelectedKey ?? delegate.getFirstKey?.());\n      }\n    } else if (scrollRef.current) {\n      // Restore the scroll position to what it was before.\n      scrollRef.current.scrollTop = scrollPos.current.top;\n      scrollRef.current.scrollLeft = scrollPos.current.left;\n    }\n\n    if (manager.focusedKey != null && scrollRef.current) {\n      // Refocus and scroll the focused item into view if it exists within the scrollable region.\n      let element = getItemElement(ref, manager.focusedKey);\n      if (element instanceof HTMLElement) {\n        // This prevents a flash of focus on the first/last element in the collection, or the collection itself.\n        if (!isFocusWithin(element) && !shouldUseVirtualFocus) {\n          focusWithoutScrolling(element);\n        }\n\n        if (modality === 'keyboard' || (UNSTABLE_focusOnEntry && modality === 'virtual')) {\n          scrollIntoViewport(element, {containingElement: ref.current});\n        }\n      }\n    }\n  };\n\n  let onBlur = e => {\n    // Don't set blurred and then focused again if moving focus within the collection.\n    if (!nodeContains(e.currentTarget, e.relatedTarget as HTMLElement)) {\n      manager.setFocused(false);\n    }\n  };\n\n  // Ref to track whether the first item in the collection should be automatically focused. Specifically used for autocomplete when user types\n  // to focus the first key AFTER the collection updates.\n  // TODO: potentially expand the usage of this\n  let shouldVirtualFocusFirst = useRef(false);\n  // Add event listeners for custom virtual events. These handle updating the focused key in response to various keyboard events\n  // at the autocomplete level\n  // TODO: fix type later\n  useEvent(\n    ref,\n    FOCUS_EVENT,\n    !shouldUseVirtualFocus\n      ? undefined\n      : (e: any) => {\n          let {detail} = e;\n          e.stopPropagation();\n          manager.setFocused(true);\n          // If the user is typing forwards, autofocus the first option in the list.\n          if (detail?.focusStrategy === 'first') {\n            shouldVirtualFocusFirst.current = true;\n          }\n        }\n  );\n\n  // update active descendant\n  let firstKey = delegate.getFirstKey?.() ?? null;\n  useUpdateLayoutEffect(() => {\n    if (shouldVirtualFocusFirst.current) {\n      // If no focusable items exist in the list, make sure to clear any activedescendant that may still exist and move focus back to\n      // the original active element (e.g. the autocomplete input)\n      if (firstKey == null) {\n        let previousActiveElement = getActiveElement();\n        moveVirtualFocus(ref.current);\n        dispatchVirtualFocus(previousActiveElement!, null);\n\n        // If there wasn't a focusable key but the collection had items, then that means we aren't in an intermediate load state and all keys are disabled.\n        // Reset shouldVirtualFocusFirst so that we don't erronously autofocus an item when the collection is filtered again.\n        if (manager.collection.size > 0) {\n          shouldVirtualFocusFirst.current = false;\n        }\n      } else {\n        manager.setFocusedKey(firstKey);\n        // Only set shouldVirtualFocusFirst to false if we've successfully set the first key as the focused key\n        // If there wasn't a key to focus, we might be in a temporary loading state so we'll want to still focus the first key\n        // after the collection updates after load\n        shouldVirtualFocusFirst.current = false;\n      }\n    }\n  }, [firstKey, manager.collection.size]);\n\n  // reset focus first flag\n  useUpdateLayoutEffect(() => {\n    // If user causes the focused key to change in any other way, clear shouldVirtualFocusFirst so we don't\n    // accidentally move focus from under them. Skip this if the collection was empty because we might be in a load\n    // state and will still want to focus the first item after load\n    if (manager.collection.size > 0) {\n      shouldVirtualFocusFirst.current = false;\n    }\n  }, [manager.focusedKey]);\n\n  useEvent(\n    ref,\n    CLEAR_FOCUS_EVENT,\n    !shouldUseVirtualFocus\n      ? undefined\n      : (e: any) => {\n          e.stopPropagation();\n          manager.setFocused(false);\n          if (e.detail?.clearFocusKey) {\n            manager.setFocusedKey(null);\n          }\n        }\n  );\n\n  const autoFocusRef = useRef(autoFocus);\n  const didAutoFocusRef = useRef(false);\n  useEffect(() => {\n    if (autoFocusRef.current) {\n      let focusedKey: Key | null = null;\n\n      // Check focus strategy to determine which item to focus\n      if (autoFocus === 'first') {\n        focusedKey = delegate.getFirstKey?.() ?? null;\n      }\n      if (autoFocus === 'last') {\n        focusedKey = delegate.getLastKey?.() ?? null;\n      }\n\n      // If there are any selected keys, make the first one the new focus target\n      let selectedKeys = manager.selectedKeys;\n      if (selectedKeys.size) {\n        for (let key of selectedKeys) {\n          if (manager.canSelectItem(key)) {\n            focusedKey = key;\n            break;\n          }\n        }\n      }\n\n      manager.setFocused(true);\n      manager.setFocusedKey(focusedKey);\n\n      if (\n        focusedKey != null &&\n        selectOnFocus &&\n        !selectedKeys.size &&\n        manager.canSelectItem(focusedKey)\n      ) {\n        manager.replaceSelection(focusedKey);\n      }\n\n      // If no default focus key is selected, focus the collection itself.\n      if (focusedKey == null && !shouldUseVirtualFocus && ref.current) {\n        focusSafely(ref.current);\n      }\n\n      // Wait until the collection has items to autofocus.\n      if (manager.collection.size > 0) {\n        autoFocusRef.current = false;\n        didAutoFocusRef.current = true;\n      }\n    }\n  });\n\n  // Scroll the focused element into view when the focusedKey changes.\n  let lastFocusedKey = useRef(manager.focusedKey);\n  let raf = useRef<number | null>(null);\n  useEffect(() => {\n    if (\n      manager.isFocused &&\n      manager.focusedKey != null &&\n      (manager.focusedKey !== lastFocusedKey.current || didAutoFocusRef.current) &&\n      scrollRef.current &&\n      ref.current\n    ) {\n      let modality = getInteractionModality();\n      let element = getItemElement(ref, manager.focusedKey);\n      if (!(element instanceof HTMLElement)) {\n        // If item element wasn't found, return early (don't update autoFocusRef and lastFocusedKey).\n        // The collection may initially be empty (e.g. virtualizer), so wait until the element exists.\n        return;\n      }\n\n      if (modality === 'keyboard' || didAutoFocusRef.current) {\n        if (raf.current) {\n          cancelAnimationFrame(raf.current);\n        }\n\n        raf.current = requestAnimationFrame(() => {\n          if (scrollRef.current) {\n            scrollIntoView(scrollRef.current, element);\n            // Avoid scroll in iOS VO, since it may cause overlay to close (i.e. RAC submenu)\n            if (modality !== 'virtual') {\n              scrollIntoViewport(element, {containingElement: ref.current});\n            }\n          }\n        });\n      }\n    }\n\n    // If the focused key becomes null (e.g. the last item is deleted), focus the whole collection.\n    if (\n      !shouldUseVirtualFocus &&\n      manager.isFocused &&\n      manager.focusedKey == null &&\n      lastFocusedKey.current != null &&\n      ref.current\n    ) {\n      focusSafely(ref.current);\n    }\n\n    lastFocusedKey.current = manager.focusedKey;\n    didAutoFocusRef.current = false;\n  });\n\n  useEffect(() => {\n    return () => {\n      if (raf.current) {\n        cancelAnimationFrame(raf.current);\n      }\n    };\n  }, []);\n\n  // Intercept FocusScope restoration since virtualized collections can reuse DOM nodes.\n  useEvent(ref, 'react-aria-focus-scope-restore', e => {\n    e.preventDefault();\n    manager.setFocused(true);\n  });\n\n  let handlers = {\n    ...mergeProps(keyboardProps, repeatKeyboardProps),\n    onFocus,\n    onBlur,\n    onMouseDown(e) {\n      // Ignore events that bubbled through portals.\n      if (scrollRef.current === getEventTarget(e)) {\n        // Prevent focus going to the collection when clicking on the scrollbar.\n        e.preventDefault();\n      }\n    }\n  };\n\n  let {typeSelectProps} = useTypeSelect({\n    keyboardDelegate: delegate,\n    selectionManager: manager\n  });\n\n  if (!disallowTypeAhead) {\n    // oxlint-disable-next-line react/react-compiler\n    handlers = mergeProps(typeSelectProps, handlers);\n  }\n\n  // If nothing is focused within the collection, make the collection itself tabbable.\n  // This will be marshalled to either the first or last item depending on where focus came from.\n  let tabIndex: number | undefined = undefined;\n  if (!shouldUseVirtualFocus) {\n    tabIndex = manager.focusedKey == null ? 0 : -1;\n  }\n\n  let collectionId = useCollectionId(manager.collection);\n  return {\n    // oxlint-disable-next-line react/react-compiler\n    collectionProps: mergeProps(handlers, {\n      tabIndex,\n      'data-collection': collectionId\n    })\n  };\n}\n"],"names":[],"version":3,"file":"useSelectableCollection.mjs.map"}