{"ast":null,"code":"import _classCallCheck from \"@babel/runtime/helpers/classCallCheck\";\nimport _createClass from \"@babel/runtime/helpers/createClass\";\nimport { useCollator } from \"@react-aria/i18n\";\nimport { isMac, mergeProps } from \"@react-aria/utils\";\nimport { focusSafely, getFocusableTreeWalker } from \"@react-aria/focus\";\nimport { useEffect, useRef, useMemo } from \"react\";\nimport _babelRuntimeHelpersEsmExtends from \"@babel/runtime/helpers/esm/extends\";\nexport function useTypeSelect(options) {\n  var keyboardDelegate = options.keyboardDelegate,\n      selectionManager = options.selectionManager,\n      onTypeSelect = options.onTypeSelect;\n  var state = useRef({\n    search: '',\n    timeout: null\n  }).current;\n\n  var onKeyDown = function onKeyDown(e) {\n    var character = $c78d7fa5f7d5832f9b4f97b33a679865$var$getStringForKey(e.key);\n\n    if (!character || e.ctrlKey || e.metaKey) {\n      return;\n    }\n\n    if (character === ' ' && state.search.trim().length > 0) {\n      e.preventDefault();\n      e.stopPropagation();\n    }\n\n    state.search += character;\n    var key = keyboardDelegate.getKeyForSearch(state.search, selectionManager.focusedKey);\n\n    if (key == null) {\n      key = keyboardDelegate.getKeyForSearch(state.search);\n    }\n\n    if (key != null) {\n      selectionManager.setFocusedKey(key);\n\n      if (onTypeSelect) {\n        onTypeSelect(key);\n      }\n    }\n\n    clearTimeout(state.timeout);\n    state.timeout = setTimeout(function () {\n      state.search = '';\n    }, 500);\n  };\n\n  return {\n    typeSelectProps: {\n      onKeyDownCapture: keyboardDelegate.getKeyForSearch ? onKeyDown : null\n    }\n  };\n}\n\nfunction $c78d7fa5f7d5832f9b4f97b33a679865$var$getStringForKey(key) {\n  if (key.length === 1 || !/^[A-Z]/i.test(key)) {\n    return key;\n  }\n\n  return '';\n}\n\nfunction $a9b9aa71af07c56ab1d89ca45381f4b$var$isCtrlKeyPressed(e) {\n  if (isMac()) {\n    return e.metaKey;\n  }\n\n  return e.ctrlKey;\n}\n\nexport function useSelectableCollection(options) {\n  var manager = options.selectionManager,\n      delegate = options.keyboardDelegate,\n      ref = options.ref,\n      _options$autoFocus = options.autoFocus,\n      autoFocus = _options$autoFocus === void 0 ? false : _options$autoFocus,\n      _options$shouldFocusW = options.shouldFocusWrap,\n      shouldFocusWrap = _options$shouldFocusW === void 0 ? false : _options$shouldFocusW,\n      _options$disallowEmpt = options.disallowEmptySelection,\n      disallowEmptySelection = _options$disallowEmpt === void 0 ? false : _options$disallowEmpt,\n      _options$disallowSele = options.disallowSelectAll,\n      disallowSelectAll = _options$disallowSele === void 0 ? false : _options$disallowSele,\n      _options$selectOnFocu = options.selectOnFocus,\n      selectOnFocus = _options$selectOnFocu === void 0 ? false : _options$selectOnFocu,\n      _options$disallowType = options.disallowTypeAhead,\n      disallowTypeAhead = _options$disallowType === void 0 ? false : _options$disallowType,\n      shouldUseVirtualFocus = options.shouldUseVirtualFocus;\n\n  var onKeyDown = function onKeyDown(e) {\n    if (e.altKey || !ref.current.contains(e.target)) {\n      return;\n    }\n\n    switch (e.key) {\n      case 'ArrowDown':\n        {\n          if (delegate.getKeyBelow) {\n            e.preventDefault();\n            var nextKey = manager.focusedKey != null ? delegate.getKeyBelow(manager.focusedKey) : delegate.getFirstKey();\n\n            if (nextKey != null) {\n              manager.setFocusedKey(nextKey);\n\n              if (manager.selectionMode === 'single' && selectOnFocus) {\n                manager.replaceSelection(nextKey);\n              }\n            } else if (shouldFocusWrap) {\n              var wrapKey = delegate.getFirstKey(manager.focusedKey);\n              manager.setFocusedKey(wrapKey);\n\n              if (manager.selectionMode === 'single' && selectOnFocus) {\n                manager.replaceSelection(wrapKey);\n              }\n            }\n\n            if (e.shiftKey && manager.selectionMode === 'multiple') {\n              manager.extendSelection(nextKey);\n            }\n          }\n\n          break;\n        }\n\n      case 'ArrowUp':\n        {\n          if (delegate.getKeyAbove) {\n            e.preventDefault();\n\n            var _nextKey = manager.focusedKey != null ? delegate.getKeyAbove(manager.focusedKey) : delegate.getLastKey();\n\n            if (_nextKey != null) {\n              manager.setFocusedKey(_nextKey);\n\n              if (manager.selectionMode === 'single' && selectOnFocus) {\n                manager.replaceSelection(_nextKey);\n              }\n            } else if (shouldFocusWrap) {\n              var _wrapKey = delegate.getLastKey(manager.focusedKey);\n\n              manager.setFocusedKey(_wrapKey);\n\n              if (manager.selectionMode === 'single' && selectOnFocus) {\n                manager.replaceSelection(_wrapKey);\n              }\n            }\n\n            if (e.shiftKey && manager.selectionMode === 'multiple') {\n              manager.extendSelection(_nextKey);\n            }\n          }\n\n          break;\n        }\n\n      case 'ArrowLeft':\n        {\n          if (delegate.getKeyLeftOf) {\n            e.preventDefault();\n\n            var _nextKey2 = delegate.getKeyLeftOf(manager.focusedKey);\n\n            if (_nextKey2 != null) {\n              manager.setFocusedKey(_nextKey2);\n\n              if (manager.selectionMode === 'single' && selectOnFocus) {\n                manager.replaceSelection(_nextKey2);\n              }\n            }\n\n            if (e.shiftKey && manager.selectionMode === 'multiple') {\n              manager.extendSelection(_nextKey2);\n            }\n          }\n\n          break;\n        }\n\n      case 'ArrowRight':\n        {\n          if (delegate.getKeyRightOf) {\n            e.preventDefault();\n\n            var _nextKey3 = delegate.getKeyRightOf(manager.focusedKey);\n\n            if (_nextKey3 != null) {\n              manager.setFocusedKey(_nextKey3);\n\n              if (manager.selectionMode === 'single' && selectOnFocus) {\n                manager.replaceSelection(_nextKey3);\n              }\n            }\n\n            if (e.shiftKey && manager.selectionMode === 'multiple') {\n              manager.extendSelection(_nextKey3);\n            }\n          }\n\n          break;\n        }\n\n      case 'Home':\n        if (delegate.getFirstKey) {\n          e.preventDefault();\n          var firstKey = delegate.getFirstKey(manager.focusedKey, $a9b9aa71af07c56ab1d89ca45381f4b$var$isCtrlKeyPressed(e));\n          manager.setFocusedKey(firstKey);\n\n          if (manager.selectionMode === 'single' && selectOnFocus) {\n            manager.replaceSelection(firstKey);\n          }\n\n          if ($a9b9aa71af07c56ab1d89ca45381f4b$var$isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n            manager.extendSelection(firstKey);\n          }\n        }\n\n        break;\n\n      case 'End':\n        if (delegate.getLastKey) {\n          e.preventDefault();\n          var lastKey = delegate.getLastKey(manager.focusedKey, $a9b9aa71af07c56ab1d89ca45381f4b$var$isCtrlKeyPressed(e));\n          manager.setFocusedKey(lastKey);\n\n          if (manager.selectionMode === 'single' && selectOnFocus) {\n            manager.replaceSelection(lastKey);\n          }\n\n          if ($a9b9aa71af07c56ab1d89ca45381f4b$var$isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n            manager.extendSelection(lastKey);\n          }\n        }\n\n        break;\n\n      case 'PageDown':\n        if (delegate.getKeyPageBelow) {\n          e.preventDefault();\n\n          var _nextKey4 = delegate.getKeyPageBelow(manager.focusedKey);\n\n          if (_nextKey4 != null) {\n            manager.setFocusedKey(_nextKey4);\n\n            if (e.shiftKey && manager.selectionMode === 'multiple') {\n              manager.extendSelection(_nextKey4);\n            }\n          }\n        }\n\n        break;\n\n      case 'PageUp':\n        if (delegate.getKeyPageAbove) {\n          e.preventDefault();\n\n          var _nextKey5 = delegate.getKeyPageAbove(manager.focusedKey);\n\n          if (_nextKey5 != null) {\n            manager.setFocusedKey(_nextKey5);\n\n            if (e.shiftKey && manager.selectionMode === 'multiple') {\n              manager.extendSelection(_nextKey5);\n            }\n          }\n        }\n\n        break;\n\n      case 'a':\n        if ($a9b9aa71af07c56ab1d89ca45381f4b$var$isCtrlKeyPressed(e) && manager.selectionMode === 'multiple' && disallowSelectAll !== true) {\n          e.preventDefault();\n          manager.selectAll();\n        }\n\n        break;\n\n      case 'Escape':\n        e.preventDefault();\n\n        if (!disallowEmptySelection) {\n          manager.clearSelection();\n        }\n\n        break;\n\n      case 'Tab':\n        {\n          if (e.shiftKey) {\n            ref.current.focus();\n          } else {\n            var walker = getFocusableTreeWalker(ref.current, {\n              tabbable: true\n            });\n            var next;\n            var last;\n\n            do {\n              last = walker.lastChild();\n\n              if (last) {\n                next = last;\n              }\n            } while (last);\n\n            if (next && !next.contains(document.activeElement)) {\n              next.focus();\n            }\n          }\n\n          break;\n        }\n    }\n  };\n\n  var onFocus = function onFocus(e) {\n    if (manager.isFocused) {\n      if (!e.currentTarget.contains(e.target)) {\n        manager.setFocused(false);\n      }\n\n      return;\n    }\n\n    if (!e.currentTarget.contains(e.target)) {\n      return;\n    }\n\n    manager.setFocused(true);\n\n    if (manager.focusedKey == null) {\n      var relatedTarget = e.relatedTarget;\n\n      if (relatedTarget && e.currentTarget.compareDocumentPosition(relatedTarget) & Node.DOCUMENT_POSITION_FOLLOWING) {\n        var _manager$lastSelected;\n\n        manager.setFocusedKey((_manager$lastSelected = manager.lastSelectedKey) != null ? _manager$lastSelected : delegate.getLastKey());\n      } else {\n        var _manager$firstSelecte;\n\n        manager.setFocusedKey((_manager$firstSelecte = manager.firstSelectedKey) != null ? _manager$firstSelecte : delegate.getFirstKey());\n      }\n    }\n  };\n\n  var onBlur = function onBlur(e) {\n    if (!e.currentTarget.contains(e.relatedTarget)) {\n      manager.setFocused(false);\n    }\n  };\n\n  useEffect(function () {\n    if (autoFocus) {\n      var focusedKey = null;\n\n      if (autoFocus === 'first') {\n        focusedKey = delegate.getFirstKey();\n      }\n\n      if (autoFocus === 'last') {\n        focusedKey = delegate.getLastKey();\n      }\n\n      var selectedKeys = manager.selectedKeys;\n\n      if (selectedKeys.size) {\n        focusedKey = selectedKeys.values().next().value;\n      }\n\n      manager.setFocused(true);\n      manager.setFocusedKey(focusedKey);\n\n      if (focusedKey == null && !shouldUseVirtualFocus) {\n        focusSafely(ref.current);\n      }\n    }\n  }, []);\n  var handlers = {\n    onKeyDownCapture: onKeyDown,\n    onFocus: onFocus,\n    onBlur: onBlur,\n    onMouseDown: function onMouseDown(e) {\n      e.preventDefault();\n    }\n  };\n\n  var _useTypeSelect = useTypeSelect({\n    keyboardDelegate: delegate,\n    selectionManager: manager\n  }),\n      typeSelectProps = _useTypeSelect.typeSelectProps;\n\n  if (!disallowTypeAhead) {\n    handlers = mergeProps(typeSelectProps, handlers);\n  }\n\n  var tabIndex;\n\n  if (!shouldUseVirtualFocus) {\n    tabIndex = manager.focusedKey == null ? 0 : -1;\n  }\n\n  return {\n    collectionProps: _babelRuntimeHelpersEsmExtends({}, handlers, {\n      tabIndex: tabIndex\n    })\n  };\n}\nexport function useSelectableItem(options) {\n  var manager = options.selectionManager,\n      key = options.key,\n      ref = options.ref,\n      shouldSelectOnPressUp = options.shouldSelectOnPressUp,\n      isVirtualized = options.isVirtualized,\n      shouldUseVirtualFocus = options.shouldUseVirtualFocus,\n      focus = options.focus;\n\n  var onSelect = function onSelect(e) {\n    return manager.select(key, e);\n  };\n\n  var isFocused = key === manager.focusedKey;\n  useEffect(function () {\n    if (isFocused && manager.isFocused && !shouldUseVirtualFocus && document.activeElement !== ref.current) {\n      if (focus) {\n        focus();\n      } else {\n        focusSafely(ref.current);\n      }\n    }\n  }, [ref, isFocused, manager.focusedKey, manager.isFocused, shouldUseVirtualFocus]);\n  var itemProps = {};\n\n  if (!shouldUseVirtualFocus) {\n    itemProps = {\n      tabIndex: isFocused ? 0 : -1,\n      onFocus: function onFocus(e) {\n        if (e.target === ref.current) {\n          manager.setFocusedKey(key);\n        }\n      }\n    };\n  }\n\n  if (shouldSelectOnPressUp) {\n    itemProps.onPressStart = function (e) {\n      if (e.pointerType === 'keyboard') {\n        onSelect(e);\n      }\n    };\n\n    itemProps.onPressUp = function (e) {\n      if (e.pointerType !== 'keyboard') {\n        onSelect(e);\n      }\n    };\n  } else {\n    itemProps.onPressStart = function (e) {\n      if (e.pointerType !== 'touch') {\n        onSelect(e);\n      }\n    };\n\n    itemProps.onPress = function (e) {\n      if (e.pointerType === 'touch') {\n        onSelect(e);\n      }\n    };\n  }\n\n  if (!isVirtualized) {\n    itemProps['data-key'] = key;\n  }\n\n  return {\n    itemProps: itemProps\n  };\n}\nexport var ListKeyboardDelegate = function () {\n  function ListKeyboardDelegate(collection, disabledKeys, ref, collator) {\n    _classCallCheck(this, ListKeyboardDelegate);\n\n    this.collection = void 0;\n    this.disabledKeys = void 0;\n    this.ref = void 0;\n    this.collator = void 0;\n    this.collection = collection;\n    this.disabledKeys = disabledKeys;\n    this.ref = ref;\n    this.collator = collator;\n  }\n\n  _createClass(ListKeyboardDelegate, [{\n    key: \"getKeyBelow\",\n    value: function getKeyBelow(key) {\n      key = this.collection.getKeyAfter(key);\n\n      while (key != null) {\n        var item = this.collection.getItem(key);\n\n        if (item.type === 'item' && !this.disabledKeys.has(key)) {\n          return key;\n        }\n\n        key = this.collection.getKeyAfter(key);\n      }\n    }\n  }, {\n    key: \"getKeyAbove\",\n    value: function getKeyAbove(key) {\n      key = this.collection.getKeyBefore(key);\n\n      while (key != null) {\n        var item = this.collection.getItem(key);\n\n        if (item.type === 'item' && !this.disabledKeys.has(key)) {\n          return key;\n        }\n\n        key = this.collection.getKeyBefore(key);\n      }\n    }\n  }, {\n    key: \"getFirstKey\",\n    value: function getFirstKey() {\n      var key = this.collection.getFirstKey();\n\n      while (key != null) {\n        var item = this.collection.getItem(key);\n\n        if (item.type === 'item' && !this.disabledKeys.has(key)) {\n          return key;\n        }\n\n        key = this.collection.getKeyAfter(key);\n      }\n    }\n  }, {\n    key: \"getLastKey\",\n    value: function getLastKey() {\n      var key = this.collection.getLastKey();\n\n      while (key != null) {\n        var item = this.collection.getItem(key);\n\n        if (item.type === 'item' && !this.disabledKeys.has(key)) {\n          return key;\n        }\n\n        key = this.collection.getKeyBefore(key);\n      }\n    }\n  }, {\n    key: \"getItem\",\n    value: function getItem(key) {\n      return this.ref.current.querySelector(\"[data-key=\\\"\" + key + \"\\\"]\");\n    }\n  }, {\n    key: \"getKeyPageAbove\",\n    value: function getKeyPageAbove(key) {\n      var menu = this.ref.current;\n      var item = this.getItem(key);\n\n      if (!item) {\n        return null;\n      }\n\n      var pageY = Math.max(0, item.offsetTop + item.offsetHeight - menu.offsetHeight);\n\n      while (item && item.offsetTop > pageY) {\n        key = this.getKeyAbove(key);\n        item = this.getItem(key);\n      }\n\n      return key;\n    }\n  }, {\n    key: \"getKeyPageBelow\",\n    value: function getKeyPageBelow(key) {\n      var menu = this.ref.current;\n      var item = this.getItem(key);\n\n      if (!item) {\n        return null;\n      }\n\n      var pageY = Math.min(menu.scrollHeight, item.offsetTop - item.offsetHeight + menu.offsetHeight);\n\n      while (item && item.offsetTop < pageY) {\n        key = this.getKeyBelow(key);\n        item = this.getItem(key);\n      }\n\n      return key;\n    }\n  }, {\n    key: \"getKeyForSearch\",\n    value: function getKeyForSearch(search, fromKey) {\n      if (!this.collator) {\n        return null;\n      }\n\n      var collection = this.collection;\n      var key = fromKey || this.getFirstKey();\n\n      while (key != null) {\n        var item = collection.getItem(key);\n        var substring = item.textValue.slice(0, search.length);\n\n        if (item.textValue && this.collator.compare(substring, search) === 0) {\n          return key;\n        }\n\n        key = this.getKeyBelow(key);\n      }\n\n      return null;\n    }\n  }]);\n\n  return ListKeyboardDelegate;\n}();\nexport function useSelectableList(props) {\n  var selectionManager = props.selectionManager,\n      collection = props.collection,\n      disabledKeys = props.disabledKeys,\n      ref = props.ref,\n      keyboardDelegate = props.keyboardDelegate,\n      autoFocus = props.autoFocus,\n      shouldFocusWrap = props.shouldFocusWrap,\n      isVirtualized = props.isVirtualized,\n      disallowEmptySelection = props.disallowEmptySelection,\n      _props$selectOnFocus = props.selectOnFocus,\n      selectOnFocus = _props$selectOnFocus === void 0 ? false : _props$selectOnFocus,\n      disallowTypeAhead = props.disallowTypeAhead,\n      shouldUseVirtualFocus = props.shouldUseVirtualFocus;\n  var collator = useCollator({\n    usage: 'search',\n    sensitivity: 'base'\n  });\n  var delegate = useMemo(function () {\n    return keyboardDelegate || new ListKeyboardDelegate(collection, disabledKeys, ref, collator);\n  }, [keyboardDelegate, collection, disabledKeys, ref, collator]);\n  useEffect(function () {\n    if (!isVirtualized && selectionManager.focusedKey && (ref == null ? void 0 : ref.current)) {\n      var element = ref.current.querySelector(\"[data-key=\\\"\" + selectionManager.focusedKey + \"\\\"]\");\n\n      if (element) {\n        $a09ba753e08b703267f2392f7fc8e96$var$scrollIntoView(ref.current, element);\n      }\n    }\n  }, [isVirtualized, ref, selectionManager.focusedKey]);\n\n  var _useSelectableCollect = useSelectableCollection({\n    ref: ref,\n    selectionManager: selectionManager,\n    keyboardDelegate: delegate,\n    autoFocus: autoFocus,\n    shouldFocusWrap: shouldFocusWrap,\n    disallowEmptySelection: disallowEmptySelection,\n    selectOnFocus: selectOnFocus,\n    disallowTypeAhead: disallowTypeAhead,\n    shouldUseVirtualFocus: shouldUseVirtualFocus\n  }),\n      collectionProps = _useSelectableCollect.collectionProps;\n\n  return {\n    listProps: collectionProps\n  };\n}\n\nfunction $a09ba753e08b703267f2392f7fc8e96$var$scrollIntoView(scrollView, element) {\n  var offsetX = element.offsetLeft - scrollView.offsetLeft;\n  var offsetY = element.offsetTop - scrollView.offsetTop;\n  var width = element.offsetWidth;\n  var height = element.offsetHeight;\n  var x = scrollView.scrollLeft;\n  var y = scrollView.scrollTop;\n  var maxX = x + scrollView.offsetWidth;\n  var maxY = y + scrollView.offsetHeight;\n\n  if (offsetX <= x) {\n    x = offsetX;\n  } else if (offsetX + width > maxX) {\n    x += offsetX + width - maxX;\n  }\n\n  if (offsetY <= y) {\n    y = offsetY;\n  } else if (offsetY + height > maxY) {\n    y += offsetY + height - maxY;\n  }\n\n  scrollView.scrollLeft = x;\n  scrollView.scrollTop = y;\n}","map":{"version":3,"sources":["packages/@react-aria/selection/src/useTypeSelect.ts","packages/@react-aria/selection/src/useSelectableCollection.ts","packages/@react-aria/selection/src/useSelectableItem.ts","packages/@react-aria/selection/src/ListKeyboardDelegate.ts","packages/@react-aria/selection/src/useSelectableList.ts"],"names":["onTypeSelect","state","search","timeout","onKeyDown","e","character","getStringForKey","key","keyboardDelegate","selectionManager","clearTimeout","setTimeout","typeSelectProps","onKeyDownCapture","isMac","autoFocus","shouldFocusWrap","disallowEmptySelection","disallowSelectAll","selectOnFocus","disallowTypeAhead","shouldUseVirtualFocus","ref","delegate","nextKey","manager","wrapKey","firstKey","isCtrlKeyPressed","lastKey","walker","getFocusableTreeWalker","tabbable","last","next","document","onFocus","relatedTarget","Node","onBlur","useEffect","focusedKey","selectedKeys","focusSafely","handlers","onMouseDown","mergeProps","tabIndex","collectionProps","focus","onSelect","isFocused","itemProps","collection","disabledKeys","collator","constructor","item","menu","pageY","Math","fromKey","substring","useCollator","usage","sensitivity","useMemo","element","scrollIntoView","listProps","offsetX","scrollView","offsetY","width","height","x","y","maxX","maxY"],"mappings":";;;;;;;OAyCO,SAAA,aAAA,CAAA,OAAA,EAAmE;AAAA,MACpE,gBADoE,GACxE,OADwE,CACpE,gBADoE;AAAA,MACpE,gBADoE,GACxE,OADwE,CACpE,gBADoE;AAAA,MAC/BA,YAD+B,GACxE,OADwE,CAC/BA,YAD+B;AAExE,MAAIC,KAAK,GAAG,MAAM,CAAC;AACjBC,IAAAA,MAAM,EADW,EAAA;AAEjBC,IAAAA,OAAO,EAAE;AAFQ,GAAD,CAAN,CAAZ,OAAA;;AAKA,MAAIC,SAAS,GAAIC,SAAbD,SAAaC,CAAAA,CAAD,EAAsB;AACpC,QAAIC,SAAS,GAAGC,qDAAe,CAACF,CAAC,CAAjC,GAA+B,CAA/B;;AACA,QAAI,CAAA,SAAA,IAAcA,CAAC,CAAf,OAAA,IAA2BA,CAAC,CAAhC,OAAA,EAA0C;AACxC;AAHkC;;AAUpC,QAAIC,SAAS,KAATA,GAAAA,IAAqBL,KAAK,CAALA,MAAAA,CAAAA,IAAAA,GAAAA,MAAAA,GAAzB,CAAA,EAAyD;AACvDI,MAAAA,CAAC,CAADA,cAAAA;AACAA,MAAAA,CAAC,CAADA,eAAAA;AACD;;AAEDJ,IAAAA,KAAK,CAALA,MAAAA,IAfoC,SAepCA;AAIA,QAAIO,GAAG,GAAGC,gBAAgB,CAAhBA,eAAAA,CAAiCR,KAAK,CAAtCQ,MAAAA,EAA+CC,gBAAgB,CAnBrC,UAmB1BD,CAAV;;AAGA,QAAID,GAAG,IAAP,IAAA,EAAiB;AACfA,MAAAA,GAA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,MAAAA,GAALI,IAAAA;AACD;;AAEDL,EAAAA,UAAU,CAAVA,UAAAA,GAAAA,CAAAA;AACAA,EAAAA,UAAU,CAAVA,SAAAA,GAAAA,CAAAA;AACD","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 {HTMLAttributes, Key, KeyboardEvent, useRef} from 'react';\nimport {KeyboardDelegate} from '@react-types/shared';\nimport {MultipleSelectionManager} from '@react-stately/selection';\n\ninterface TypeSelectOptions {\n  /**\n   * A delegate that returns collection item keys with respect to visual layout.\n   */\n  keyboardDelegate: KeyboardDelegate,\n  /**\n   * An interface for reading and updating multiple selection state.\n   */\n  selectionManager: MultipleSelectionManager,\n  /**\n   * Called when an item is focused by typing.\n   */\n  onTypeSelect?: (key: Key) => void\n}\n\ninterface TypeSelectAria {\n  /**\n   * Props to be spread on the owner of the options.\n   */\n  typeSelectProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Handles typeahead interactions with collections.\n */\nexport function useTypeSelect(options: TypeSelectOptions): TypeSelectAria {\n  let {keyboardDelegate, selectionManager, onTypeSelect} = options;\n  let state = useRef({\n    search: '',\n    timeout: null\n  }).current;\n\n  let onKeyDown = (e: KeyboardEvent) => {\n    let character = getStringForKey(e.key);\n    if (!character || e.ctrlKey || e.metaKey) {\n      return;\n    }\n\n    // Do not propagate the Spacebar event if it's meant to be part of the search.\n    // When we time out, the search term becomes empty, hence the check on length.\n    // Trimming is to account for the case of pressing the Spacebar more than once,\n    // which should cycle through the selection/deselection of the focused item.\n    if (character === ' ' && state.search.trim().length > 0) {\n      e.preventDefault();\n      e.stopPropagation();\n    }\n\n    state.search += character;\n\n    // Use the delegate to find a key to focus.\n    // Prioritize items after the currently focused item, falling back to searching the whole list.\n    let key = keyboardDelegate.getKeyForSearch(state.search, selectionManager.focusedKey);\n\n    // If no key found, search from the top.\n    if (key == null) {\n      key = keyboardDelegate.getKeyForSearch(state.search);\n    }\n\n    if (key != null) {\n      selectionManager.setFocusedKey(key);\n      if (onTypeSelect) {\n        onTypeSelect(key);\n      }\n    }\n\n    clearTimeout(state.timeout);\n    state.timeout = setTimeout(() => {\n      state.search = '';\n    }, 500);\n  };\n\n  return {\n    typeSelectProps: {\n      // Using a capturing listener to catch the keydown event before\n      // other hooks in order to handle the Spacebar event.\n      onKeyDownCapture: keyboardDelegate.getKeyForSearch ? onKeyDown : null\n    }\n  };\n}\n\nfunction getStringForKey(key: string) {\n  // If the key is of length 1, it is an ASCII value.\n  // Otherwise, if there are no ASCII characters in the key name,\n  // it is a Unicode character.\n  // See https://www.w3.org/TR/uievents-key/\n  if (key.length === 1 || !/^[A-Z]/i.test(key)) {\n    return key;\n  }\n\n  return '';\n}\n","/*\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 {FocusEvent, HTMLAttributes, KeyboardEvent, RefObject, useEffect} from 'react';\nimport {focusSafely, getFocusableTreeWalker} from '@react-aria/focus';\nimport {FocusStrategy, KeyboardDelegate} from '@react-types/shared';\nimport {isMac, mergeProps} from '@react-aria/utils';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {useTypeSelect} from './useTypeSelect';\n\nfunction isCtrlKeyPressed(e: KeyboardEvent) {\n  if (isMac()) {\n    return e.metaKey;\n  }\n\n  return e.ctrlKey;\n}\n\ninterface SelectableCollectionOptions {\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>,\n  /**\n   * Whether the collection or one of its items should be automatically focused upon render.\n   * @default false\n   */\n  autoFocus?: boolean | FocusStrategy,\n  /**\n   * Whether focus should wrap around when the end/start is reached.\n   * @default false\n   */\n  shouldFocusWrap?: boolean,\n  /**\n   * Whether the collection allows empty selection.\n   * @default false\n   */\n  disallowEmptySelection?: boolean,\n  /**\n   * Whether the collection allows the user to select all items via keyboard shortcut.\n   * @default false\n   */\n  disallowSelectAll?: boolean,\n  /**\n   * Whether selection should occur automatically on focus.\n   * @default false\n   */\n  selectOnFocus?: boolean,\n  /**\n   * Whether typeahead is disabled.\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\ninterface SelectableCollectionAria {\n  /** Props for the collection element. */\n  collectionProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Handles interactions with selectable collections.\n */\nexport function useSelectableCollection(options: SelectableCollectionOptions): SelectableCollectionAria {\n  let {\n    selectionManager: manager,\n    keyboardDelegate: delegate,\n    ref,\n    autoFocus = false,\n    shouldFocusWrap = false,\n    disallowEmptySelection = false,\n    disallowSelectAll = false,\n    selectOnFocus = false,\n    disallowTypeAhead = false,\n    shouldUseVirtualFocus\n  } = options;\n\n  let onKeyDown = (e: KeyboardEvent) => {\n    // Let child element (e.g. menu button) handle the event if the Alt key is pressed.\n    // Keyboard events bubble through portals. Don't handle keyboard events\n    // for elements outside the collection (e.g. menus).\n    if (e.altKey || !ref.current.contains(e.target as HTMLElement)) {\n      return;\n    }\n\n    switch (e.key) {\n      case 'ArrowDown': {\n        if (delegate.getKeyBelow) {\n          e.preventDefault();\n          let nextKey = manager.focusedKey != null\n            ? delegate.getKeyBelow(manager.focusedKey)\n            : delegate.getFirstKey();\n\n          if (nextKey != null) {\n            manager.setFocusedKey(nextKey);\n            if (manager.selectionMode === 'single' && selectOnFocus) {\n              manager.replaceSelection(nextKey);\n            }\n          } else if (shouldFocusWrap) {\n            let wrapKey = delegate.getFirstKey(manager.focusedKey);\n            manager.setFocusedKey(wrapKey);\n            if (manager.selectionMode === 'single' && selectOnFocus) {\n              manager.replaceSelection(wrapKey);\n            }\n          }\n\n          if (e.shiftKey && manager.selectionMode === 'multiple') {\n            manager.extendSelection(nextKey);\n          }\n        }\n        break;\n      }\n      case 'ArrowUp': {\n        if (delegate.getKeyAbove) {\n          e.preventDefault();\n          let nextKey = manager.focusedKey != null\n            ? delegate.getKeyAbove(manager.focusedKey)\n            : delegate.getLastKey();\n\n          if (nextKey != null) {\n            manager.setFocusedKey(nextKey);\n            if (manager.selectionMode === 'single' && selectOnFocus) {\n              manager.replaceSelection(nextKey);\n            }\n          } else if (shouldFocusWrap) {\n            let wrapKey = delegate.getLastKey(manager.focusedKey);\n            manager.setFocusedKey(wrapKey);\n            if (manager.selectionMode === 'single' && selectOnFocus) {\n              manager.replaceSelection(wrapKey);\n            }\n          }\n\n          if (e.shiftKey && manager.selectionMode === 'multiple') {\n            manager.extendSelection(nextKey);\n          }\n        }\n        break;\n      }\n      case 'ArrowLeft': {\n        if (delegate.getKeyLeftOf) {\n          e.preventDefault();\n          let nextKey = delegate.getKeyLeftOf(manager.focusedKey);\n          if (nextKey != null) {\n            manager.setFocusedKey(nextKey);\n            if (manager.selectionMode === 'single' && selectOnFocus) {\n              manager.replaceSelection(nextKey);\n            }\n          }\n          if (e.shiftKey && manager.selectionMode === 'multiple') {\n            manager.extendSelection(nextKey);\n          }\n        }\n        break;\n      }\n      case 'ArrowRight': {\n        if (delegate.getKeyRightOf) {\n          e.preventDefault();\n          let nextKey = delegate.getKeyRightOf(manager.focusedKey);\n          if (nextKey != null) {\n            manager.setFocusedKey(nextKey);\n            if (manager.selectionMode === 'single' && selectOnFocus) {\n              manager.replaceSelection(nextKey);\n            }\n          }\n          if (e.shiftKey && manager.selectionMode === 'multiple') {\n            manager.extendSelection(nextKey);\n          }\n        }\n        break;\n      }\n      case 'Home':\n        if (delegate.getFirstKey) {\n          e.preventDefault();\n          let firstKey = delegate.getFirstKey(manager.focusedKey, isCtrlKeyPressed(e));\n          manager.setFocusedKey(firstKey);\n          if (manager.selectionMode === 'single' && selectOnFocus) {\n            manager.replaceSelection(firstKey);\n          }\n          if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n            manager.extendSelection(firstKey);\n          }\n        }\n        break;\n      case 'End':\n        if (delegate.getLastKey) {\n          e.preventDefault();\n          let lastKey = delegate.getLastKey(manager.focusedKey, isCtrlKeyPressed(e));\n          manager.setFocusedKey(lastKey);\n          if (manager.selectionMode === 'single' && selectOnFocus) {\n            manager.replaceSelection(lastKey);\n          }\n          if (isCtrlKeyPressed(e) && e.shiftKey && manager.selectionMode === 'multiple') {\n            manager.extendSelection(lastKey);\n          }\n        }\n        break;\n      case 'PageDown':\n        if (delegate.getKeyPageBelow) {\n          e.preventDefault();\n          let nextKey = delegate.getKeyPageBelow(manager.focusedKey);\n          if (nextKey != null) {\n            manager.setFocusedKey(nextKey);\n            if (e.shiftKey && manager.selectionMode === 'multiple') {\n              manager.extendSelection(nextKey);\n            }\n          }\n        }\n        break;\n      case 'PageUp':\n        if (delegate.getKeyPageAbove) {\n          e.preventDefault();\n          let nextKey = delegate.getKeyPageAbove(manager.focusedKey);\n          if (nextKey != null) {\n            manager.setFocusedKey(nextKey);\n            if (e.shiftKey && manager.selectionMode === 'multiple') {\n              manager.extendSelection(nextKey);\n            }\n          }\n        }\n        break;\n      case 'a':\n        if (isCtrlKeyPressed(e) && manager.selectionMode === 'multiple' && disallowSelectAll !== true) {\n          e.preventDefault();\n          manager.selectAll();\n        }\n        break;\n      case 'Escape':\n        e.preventDefault();\n        if (!disallowEmptySelection) {\n          manager.clearSelection();\n        }\n        break;\n      case 'Tab': {\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        if (e.shiftKey) {\n          ref.current.focus();\n        } else {\n          let walker = getFocusableTreeWalker(ref.current, {tabbable: true});\n          let next: HTMLElement;\n          let last: HTMLElement;\n          do {\n            last = walker.lastChild() as HTMLElement;\n            if (last) {\n              next = last;\n            }\n          } while (last);\n\n          if (next && !next.contains(document.activeElement)) {\n            next.focus();\n          }\n        }\n        break;\n      }\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 (!e.currentTarget.contains(e.target)) {\n        manager.setFocused(false);\n      }\n\n      return;\n    }\n\n    // Focus events can bubble through portals. Ignore these events.\n    if (!e.currentTarget.contains(e.target)) {\n      return;\n    }\n\n    manager.setFocused(true);\n\n    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 (relatedTarget && (e.currentTarget.compareDocumentPosition(relatedTarget) & Node.DOCUMENT_POSITION_FOLLOWING)) {\n        manager.setFocusedKey(manager.lastSelectedKey ?? delegate.getLastKey());\n      } else {\n        manager.setFocusedKey(manager.firstSelectedKey ?? delegate.getFirstKey());\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 (!e.currentTarget.contains(e.relatedTarget as HTMLElement)) {\n      manager.setFocused(false);\n    }\n  };\n\n  useEffect(() => {\n    if (autoFocus) {\n      let focusedKey = null;\n\n      // Check focus strategy to determine which item to focus\n      if (autoFocus === 'first') {\n        focusedKey = delegate.getFirstKey();\n      } if (autoFocus === 'last') {\n        focusedKey = delegate.getLastKey();\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        focusedKey = selectedKeys.values().next().value;\n      }\n\n      manager.setFocused(true);\n      manager.setFocusedKey(focusedKey);\n\n      // If no default focus key is selected, focus the collection itself.\n      if (focusedKey == null && !shouldUseVirtualFocus) {\n        focusSafely(ref.current);\n      }\n    }\n  // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, []);\n\n  let handlers = {\n    // We use a capturing listener to ensure that the keyboard events for the collection\n    // override those of the children. For example, ArrowDown in a table should always go\n    // to the cell below, and not open a menu.\n    onKeyDownCapture: onKeyDown,\n    onFocus,\n    onBlur,\n    onMouseDown(e) {\n      // Prevent focus going to the collection when clicking on the scrollbar.\n      e.preventDefault();\n    }\n  };\n\n  let {typeSelectProps} = useTypeSelect({\n    keyboardDelegate: delegate,\n    selectionManager: manager\n  });\n\n  if (!disallowTypeAhead) {\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  // If using virtual focus, don't set a tabIndex at all so that VoiceOver on iOS 14 doesn't try\n  // to move real DOM focus to the element anyway.\n  let tabIndex: number;\n  if (!shouldUseVirtualFocus) {\n    tabIndex = manager.focusedKey == null ? 0 : -1;\n  }\n\n  return {\n    collectionProps: {\n      ...handlers,\n      tabIndex\n    }\n  };\n}\n","/*\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 {focusSafely} from '@react-aria/focus';\nimport {HTMLAttributes, Key, RefObject, useEffect} from 'react';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {PressEvent} from '@react-types/shared';\nimport {PressProps} from '@react-aria/interactions';\n\ninterface SelectableItemOptions {\n  /**\n   * An interface for reading and updating multiple selection state.\n   */\n  selectionManager: MultipleSelectionManager,\n  /**\n   * A unique key for the item.\n   */\n  key: Key,\n  /**\n   * Ref to the item.\n   */\n  ref: RefObject<HTMLElement>,\n  /**\n   * By default, selection occurs on pointer down. This can be strange if selecting an\n   * item causes the UI to disappear immediately (e.g. menus).\n   */\n  shouldSelectOnPressUp?: boolean,\n  /**\n   * Whether the option is contained in a virtual scroller.\n   */\n  isVirtualized?: boolean,\n  /**\n   * Function to focus the item.\n   */\n  focus?: () => void,\n  /**\n   * Whether the option should use virtual focus instead of being focused directly.\n   */\n  shouldUseVirtualFocus?: boolean\n}\n\ninterface SelectableItemAria {\n  /**\n   * Props to be spread on the item root node.\n   */\n  itemProps: HTMLAttributes<HTMLElement> & PressProps\n}\n\n/**\n * Handles interactions with an item in a selectable collection.\n */\nexport function useSelectableItem(options: SelectableItemOptions): SelectableItemAria {\n  let {\n    selectionManager: manager,\n    key,\n    ref,\n    shouldSelectOnPressUp,\n    isVirtualized,\n    shouldUseVirtualFocus,\n    focus\n  } = options;\n\n  let onSelect = (e: PressEvent | PointerEvent) => manager.select(key, e);\n\n  // Focus the associated DOM node when this item becomes the focusedKey\n  let isFocused = key === manager.focusedKey;\n  useEffect(() => {\n    if (isFocused && manager.isFocused && !shouldUseVirtualFocus && document.activeElement !== ref.current) {\n      if (focus) {\n        focus();\n      } else {\n        focusSafely(ref.current);\n      }\n    }\n  }, [ref, isFocused, manager.focusedKey, manager.isFocused, shouldUseVirtualFocus]);\n\n  // Set tabIndex to 0 if the element is focused, or -1 otherwise so that only the last focused\n  // item is tabbable.  If using virtual focus, don't set a tabIndex at all so that VoiceOver\n  // on iOS 14 doesn't try to move real DOM focus to the item anyway.\n  let itemProps: SelectableItemAria['itemProps'] = {};\n  if (!shouldUseVirtualFocus) {\n    itemProps = {\n      tabIndex: isFocused ? 0 : -1,\n      onFocus(e) {\n        if (e.target === ref.current) {\n          manager.setFocusedKey(key);\n        }\n      }\n    };\n  }\n\n  // By default, selection occurs on pointer down. This can be strange if selecting an\n  // item causes the UI to disappear immediately (e.g. menus).\n  // If shouldSelectOnPressUp is true, we use onPressUp instead of onPressStart.\n  // onPress requires a pointer down event on the same element as pointer up. For menus,\n  // we want to be able to have the pointer down on the trigger that opens the menu and\n  // the pointer up on the menu item rather than requiring a separate press.\n  // For keyboard events, selection still occurs on key down.\n  if (shouldSelectOnPressUp) {\n    itemProps.onPressStart = (e) => {\n      if (e.pointerType === 'keyboard') {\n        onSelect(e);\n      }\n    };\n\n    itemProps.onPressUp = (e) => {\n      if (e.pointerType !== 'keyboard') {\n        onSelect(e);\n      }\n    };\n  } else {\n    // On touch, it feels strange to select on touch down, so we special case this.\n    itemProps.onPressStart = (e) => {\n      if (e.pointerType !== 'touch') {\n        onSelect(e);\n      }\n    };\n\n    itemProps.onPress = (e) => {\n      if (e.pointerType === 'touch') {\n        onSelect(e);\n      }\n    };\n  }\n\n  if (!isVirtualized) {\n    itemProps['data-key'] = key;\n  }\n\n  return {\n    itemProps\n  };\n}\n","/*\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 {Collection, KeyboardDelegate, Node} from '@react-types/shared';\nimport {Key, RefObject} from 'react';\n\nexport class ListKeyboardDelegate<T> implements KeyboardDelegate {\n  private collection: Collection<Node<T>>;\n  private disabledKeys: Set<Key>;\n  private ref: RefObject<HTMLElement>;\n  private collator: Intl.Collator;\n\n  constructor(collection: Collection<Node<T>>, disabledKeys: Set<Key>, ref: RefObject<HTMLElement>, collator?: Intl.Collator) {\n    this.collection = collection;\n    this.disabledKeys = disabledKeys;\n    this.ref = ref;\n    this.collator = collator;\n  }\n\n  getKeyBelow(key: Key) {\n    key = this.collection.getKeyAfter(key);\n    while (key != null) {\n      let item = this.collection.getItem(key);\n      if (item.type === 'item' && !this.disabledKeys.has(key)) {\n        return key;\n      }\n\n      key = this.collection.getKeyAfter(key);\n    }\n  }\n\n  getKeyAbove(key: Key) {\n    key = this.collection.getKeyBefore(key);\n    while (key != null) {\n      let item = this.collection.getItem(key);\n      if (item.type === 'item' && !this.disabledKeys.has(key)) {\n        return key;\n      }\n\n      key = this.collection.getKeyBefore(key);\n    }\n  }\n\n  getFirstKey() {\n    let key = this.collection.getFirstKey();\n    while (key != null) {\n      let item = this.collection.getItem(key);\n      if (item.type === 'item' && !this.disabledKeys.has(key)) {\n        return key;\n      }\n\n      key = this.collection.getKeyAfter(key);\n    }\n  }\n\n  getLastKey() {\n    let key = this.collection.getLastKey();\n    while (key != null) {\n      let item = this.collection.getItem(key);\n      if (item.type === 'item' && !this.disabledKeys.has(key)) {\n        return key;\n      }\n\n      key = this.collection.getKeyBefore(key);\n    }\n  }\n\n  private getItem(key: Key): HTMLElement {\n    return this.ref.current.querySelector(`[data-key=\"${key}\"]`);\n  }\n\n  getKeyPageAbove(key: Key) {\n    let menu = this.ref.current;\n    let item = this.getItem(key);\n    if (!item) {\n      return null;\n    }\n\n    let pageY = Math.max(0, item.offsetTop + item.offsetHeight - menu.offsetHeight);\n\n    while (item && item.offsetTop > pageY) {\n      key = this.getKeyAbove(key);\n      item = this.getItem(key);\n    }\n\n    return key;\n  }\n\n  getKeyPageBelow(key: Key) {\n    let menu = this.ref.current;\n    let item = this.getItem(key);\n    if (!item) {\n      return null;\n    }\n\n    let pageY = Math.min(menu.scrollHeight, item.offsetTop - item.offsetHeight + menu.offsetHeight);\n\n    while (item && item.offsetTop < pageY) {\n      key = this.getKeyBelow(key);\n      item = this.getItem(key);\n    }\n\n    return key;\n  }\n\n  getKeyForSearch(search: string, fromKey?: Key) {\n    if (!this.collator) {\n      return null;\n    }\n\n    let collection = this.collection;\n    let key = fromKey || this.getFirstKey();\n    while (key != null) {\n      let item = collection.getItem(key);\n      let substring = item.textValue.slice(0, search.length);\n      if (item.textValue && this.collator.compare(substring, search) === 0) {\n        return key;\n      }\n\n      key = this.getKeyBelow(key);\n    }\n\n    return null;\n  }\n}\n","/*\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 {Collection, FocusStrategy, KeyboardDelegate, Node} from '@react-types/shared';\nimport {HTMLAttributes, Key, RefObject, useEffect, useMemo} from 'react';\nimport {ListKeyboardDelegate} from './ListKeyboardDelegate';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {useCollator} from '@react-aria/i18n';\nimport {useSelectableCollection} from './useSelectableCollection';\n\ninterface SelectableListOptions {\n  /**\n   * An interface for reading and updating multiple selection state.\n   */\n  selectionManager: MultipleSelectionManager,\n  /**\n   * State of the collection.\n   */\n  collection: Collection<Node<unknown>>,\n  /**\n   * The item keys that are disabled. These items cannot be selected, focused, or otherwise interacted with.\n   */\n  disabledKeys: Set<Key>,\n  /**\n   * A ref to the item.\n   */\n  ref?: RefObject<HTMLElement>,\n  /**\n   * A delegate that returns collection item keys with respect to visual layout.\n   */\n  keyboardDelegate?: KeyboardDelegate,\n  /**\n   * Whether the collection or one of its items should be automatically focused upon render.\n   * @default false\n   */\n  autoFocus?: boolean | FocusStrategy,\n  /**\n   * Whether focus should wrap around when the end/start is reached.\n   * @default false\n   */\n  shouldFocusWrap?: boolean,\n  /**\n   * Whether the option is contained in a virtual scroller.\n   */\n  isVirtualized?: boolean,\n  /**\n   * Whether the collection allows empty selection.\n   * @default false\n   */\n  disallowEmptySelection?: boolean,\n  /**\n   * Whether selection should occur automatically on focus.\n   * @default false\n   */\n  selectOnFocus?: boolean,\n  /**\n   * Whether typeahead is disabled.\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\ninterface SelectableListAria {\n  /**\n   * Props for the option element.\n   */\n  listProps: HTMLAttributes<HTMLElement>\n}\n\n/**\n * Handles interactions with a selectable list.\n */\nexport function useSelectableList(props: SelectableListOptions): SelectableListAria {\n  let {\n    selectionManager,\n    collection,\n    disabledKeys,\n    ref,\n    keyboardDelegate,\n    autoFocus,\n    shouldFocusWrap,\n    isVirtualized,\n    disallowEmptySelection,\n    selectOnFocus = false,\n    disallowTypeAhead,\n    shouldUseVirtualFocus\n  } = props;\n\n  // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).\n  // When virtualized, the layout object will be passed in as a prop and override this.\n  let collator = useCollator({usage: 'search', sensitivity: 'base'});\n  let delegate = useMemo(() => keyboardDelegate || new ListKeyboardDelegate(collection, disabledKeys, ref, collator), [keyboardDelegate, collection, disabledKeys, ref, collator]);\n\n  // If not virtualized, scroll the focused element into view when the focusedKey changes.\n  // When virtualized, Virtualizer handles this internally.\n  useEffect(() => {\n    if (!isVirtualized && selectionManager.focusedKey && ref?.current) {\n      let element = ref.current.querySelector(`[data-key=\"${selectionManager.focusedKey}\"]`) as HTMLElement;\n      if (element) {\n        scrollIntoView(ref.current, element);\n      }\n    }\n  }, [isVirtualized, ref, selectionManager.focusedKey]);\n\n  let {collectionProps} = useSelectableCollection({\n    ref,\n    selectionManager,\n    keyboardDelegate: delegate,\n    autoFocus,\n    shouldFocusWrap,\n    disallowEmptySelection,\n    selectOnFocus,\n    disallowTypeAhead,\n    shouldUseVirtualFocus\n  });\n\n  return {\n    listProps: collectionProps\n  };\n}\n\n/**\n * Scrolls `scrollView` so that `element` is visible.\n * Similar to `element.scrollIntoView({block: 'nearest'})` (not supported in Edge),\n * but doesn't affect parents above `scrollView`.\n */\nfunction scrollIntoView(scrollView: HTMLElement, element: HTMLElement) {\n  let offsetX = element.offsetLeft - scrollView.offsetLeft;\n  let offsetY = element.offsetTop - scrollView.offsetTop;\n  let width = element.offsetWidth;\n  let height = element.offsetHeight;\n  let x = scrollView.scrollLeft;\n  let y = scrollView.scrollTop;\n  let maxX = x + scrollView.offsetWidth;\n  let maxY = y + scrollView.offsetHeight;\n\n  if (offsetX <= x) {\n    x = offsetX;\n  } else if (offsetX + width > maxX) {\n    x += offsetX + width - maxX;\n  }\n  if (offsetY <= y) {\n    y = offsetY;\n  } else if (offsetY + height > maxY) {\n    y += offsetY + height - maxY;\n  }\n\n  scrollView.scrollLeft = x;\n  scrollView.scrollTop = y;\n}\n"]},"metadata":{},"sourceType":"module"}