{"ast":null,"code":"import _toConsumableArray from \"@babel/runtime/helpers/toConsumableArray\";\nimport _createClass from \"@babel/runtime/helpers/createClass\";\nimport _slicedToArray from \"@babel/runtime/helpers/slicedToArray\";\nimport _classCallCheck from \"@babel/runtime/helpers/classCallCheck\";\nimport _inherits from \"@babel/runtime/helpers/inherits\";\nimport _possibleConstructorReturn from \"@babel/runtime/helpers/possibleConstructorReturn\";\nimport _getPrototypeOf from \"@babel/runtime/helpers/getPrototypeOf\";\nimport _wrapNativeSuper from \"@babel/runtime/helpers/wrapNativeSuper\";\n\nfunction _createForOfIteratorHelperLoose(o, allowArrayLike) { var it; if (typeof Symbol === \"undefined\" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === \"number\") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError(\"Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); } it = o[Symbol.iterator](); return it.next.bind(it); }\n\nfunction _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === \"string\") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === \"Object\" && o.constructor) n = o.constructor.name; if (n === \"Map\" || n === \"Set\") return Array.from(o); if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }\n\nfunction _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }\n\nfunction _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }\n\nfunction _isNativeReflectConstruct() { if (typeof Reflect === \"undefined\" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === \"function\") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }\n\nimport { useControlledState } from \"@react-stately/utils\";\nimport { useMemo, useRef, useState } from \"react\";\n\nvar $c91e86e24f2dc9a2182dcc2674c58c$export$Selection = function (_Set) {\n  _inherits($c91e86e24f2dc9a2182dcc2674c58c$export$Selection, _Set);\n\n  var _super = _createSuper($c91e86e24f2dc9a2182dcc2674c58c$export$Selection);\n\n  function $c91e86e24f2dc9a2182dcc2674c58c$export$Selection(keys, anchorKey, currentKey) {\n    var _this;\n\n    _classCallCheck(this, $c91e86e24f2dc9a2182dcc2674c58c$export$Selection);\n\n    _this = _super.call(this, keys);\n    _this.anchorKey = void 0;\n    _this.currentKey = void 0;\n\n    if (keys instanceof $c91e86e24f2dc9a2182dcc2674c58c$export$Selection) {\n      _this.anchorKey = anchorKey || keys.anchorKey;\n      _this.currentKey = currentKey || keys.currentKey;\n    } else {\n      _this.anchorKey = anchorKey;\n      _this.currentKey = currentKey;\n    }\n\n    return _this;\n  }\n\n  return $c91e86e24f2dc9a2182dcc2674c58c$export$Selection;\n}(_wrapNativeSuper(Set));\n\nexport function useMultipleSelectionState(props) {\n  var _props$selectionMode = props.selectionMode,\n      selectionMode = _props$selectionMode === void 0 ? 'none' : _props$selectionMode,\n      disallowEmptySelection = props.disallowEmptySelection;\n  var isFocusedRef = useRef(false);\n\n  var _useState = useState(false),\n      _useState2 = _slicedToArray(_useState, 2),\n      _setFocused = _useState2[1];\n\n  var focusedKeyRef = useRef(null);\n\n  var _useState3 = useState(null),\n      _useState4 = _slicedToArray(_useState3, 2),\n      _setFocusedKey = _useState4[1];\n\n  var selectedKeysProp = useMemo(function () {\n    return $c86d35e876e048ac11515eee40c7$var$convertSelection(props.selectedKeys);\n  }, [props.selectedKeys]);\n  var defaultSelectedKeys = useMemo(function () {\n    return $c86d35e876e048ac11515eee40c7$var$convertSelection(props.defaultSelectedKeys, new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection());\n  }, [props.defaultSelectedKeys]);\n\n  var _useControlledState = useControlledState(selectedKeysProp, defaultSelectedKeys, props.onSelectionChange),\n      _useControlledState2 = _slicedToArray(_useControlledState, 2),\n      selectedKeys = _useControlledState2[0],\n      setSelectedKeys = _useControlledState2[1];\n\n  var disabledKeysProp = useMemo(function () {\n    return props.disabledKeys ? new Set(props.disabledKeys) : new Set();\n  }, [props.disabledKeys]);\n  return {\n    selectionMode: selectionMode,\n    disallowEmptySelection: disallowEmptySelection,\n\n    get isFocused() {\n      return isFocusedRef.current;\n    },\n\n    setFocused: function setFocused(f) {\n      isFocusedRef.current = f;\n\n      _setFocused(f);\n    },\n\n    get focusedKey() {\n      return focusedKeyRef.current;\n    },\n\n    setFocusedKey: function setFocusedKey(k) {\n      focusedKeyRef.current = k;\n\n      _setFocusedKey(k);\n    },\n    selectedKeys: selectedKeys,\n    setSelectedKeys: setSelectedKeys,\n    disabledKeys: disabledKeysProp\n  };\n}\n\nfunction $c86d35e876e048ac11515eee40c7$var$convertSelection(selection, defaultValue) {\n  if (!selection) {\n    return defaultValue;\n  }\n\n  return selection === 'all' ? 'all' : new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection(selection);\n}\n\nexport var SelectionManager = function () {\n  function SelectionManager(collection, state, options) {\n    _classCallCheck(this, SelectionManager);\n\n    var _options$allowsCellSe;\n\n    this.collection = void 0;\n    this.state = void 0;\n    this.allowsCellSelection = void 0;\n    this._isSelectAll = void 0;\n    this.collection = collection;\n    this.state = state;\n    this.allowsCellSelection = (_options$allowsCellSe = options == null ? void 0 : options.allowsCellSelection) != null ? _options$allowsCellSe : false;\n    this._isSelectAll = null;\n  }\n\n  _createClass(SelectionManager, [{\n    key: \"setFocused\",\n    value: function setFocused(isFocused) {\n      this.state.setFocused(isFocused);\n    }\n  }, {\n    key: \"setFocusedKey\",\n    value: function setFocusedKey(key) {\n      this.state.setFocusedKey(key);\n    }\n  }, {\n    key: \"isSelected\",\n    value: function isSelected(key) {\n      if (this.state.selectionMode === 'none') {\n        return false;\n      }\n\n      key = this.getKey(key);\n      return this.state.selectedKeys === 'all' || this.state.selectedKeys.has(key);\n    }\n  }, {\n    key: \"extendSelection\",\n    value: function extendSelection(toKey) {\n      var _this2 = this;\n\n      toKey = this.getKey(toKey);\n      this.state.setSelectedKeys(function (selectedKeys) {\n        if (selectedKeys === 'all') {\n          return new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection([toKey], toKey, toKey);\n        }\n\n        var selection = selectedKeys;\n        var anchorKey = selection.anchorKey || toKey;\n        var keys = new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection(selection, anchorKey, toKey);\n\n        for (var _iterator = _createForOfIteratorHelperLoose(_this2.getKeyRange(anchorKey, selection.currentKey || toKey)), _step; !(_step = _iterator()).done;) {\n          var key = _step.value;\n          keys.delete(key);\n        }\n\n        for (var _iterator2 = _createForOfIteratorHelperLoose(_this2.getKeyRange(toKey, anchorKey)), _step2; !(_step2 = _iterator2()).done;) {\n          var _key = _step2.value;\n\n          if (!_this2.state.disabledKeys.has(_key)) {\n            keys.add(_key);\n          }\n        }\n\n        return keys;\n      });\n    }\n  }, {\n    key: \"getKeyRange\",\n    value: function getKeyRange(from, to) {\n      var fromItem = this.collection.getItem(from);\n      var toItem = this.collection.getItem(to);\n\n      if (fromItem && toItem) {\n        if (fromItem.index <= toItem.index) {\n          return this.getKeyRangeInternal(from, to);\n        }\n\n        return this.getKeyRangeInternal(to, from);\n      }\n\n      return [];\n    }\n  }, {\n    key: \"getKeyRangeInternal\",\n    value: function getKeyRangeInternal(from, to) {\n      var keys = [];\n      var key = from;\n\n      while (key) {\n        var item = this.collection.getItem(key);\n\n        if (item && item.type === 'item' || item.type === 'cell' && this.allowsCellSelection) {\n          keys.push(key);\n        }\n\n        if (key === to) {\n          return keys;\n        }\n\n        key = this.collection.getKeyAfter(key);\n      }\n\n      return [];\n    }\n  }, {\n    key: \"getKey\",\n    value: function getKey(key) {\n      var item = this.collection.getItem(key);\n\n      if (!item) {\n        return key;\n      }\n\n      if (item.type === 'cell' && this.allowsCellSelection) {\n        return key;\n      }\n\n      while (item.type !== 'item' && item.parentKey) {\n        item = this.collection.getItem(item.parentKey);\n      }\n\n      if (!item || item.type !== 'item') {\n        return null;\n      }\n\n      return item.key;\n    }\n  }, {\n    key: \"toggleSelection\",\n    value: function toggleSelection(key) {\n      var _this3 = this;\n\n      key = this.getKey(key);\n\n      if (key == null) {\n        return;\n      }\n\n      this.state.setSelectedKeys(function (selectedKeys) {\n        var keys = new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection(selectedKeys === 'all' ? _this3.getSelectAllKeys() : selectedKeys);\n\n        if (keys.has(key)) {\n          keys.delete(key);\n        } else {\n          keys.add(key);\n          keys.anchorKey = key;\n          keys.currentKey = key;\n        }\n\n        return keys;\n      });\n    }\n  }, {\n    key: \"replaceSelection\",\n    value: function replaceSelection(key) {\n      key = this.getKey(key);\n\n      if (key == null) {\n        return;\n      }\n\n      this.state.setSelectedKeys(new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection([key], key, key));\n    }\n  }, {\n    key: \"getSelectAllKeys\",\n    value: function getSelectAllKeys() {\n      var _this4 = this;\n\n      var keys = [];\n\n      var addKeys = function addKeys(key) {\n        while (key) {\n          if (!_this4.state.disabledKeys.has(key)) {\n            var item = _this4.collection.getItem(key);\n\n            if (item.type === 'item') {\n              keys.push(key);\n            }\n\n            if (item.hasChildNodes && (_this4.allowsCellSelection || item.type !== 'item')) {\n              addKeys(_toConsumableArray(item.childNodes)[0].key);\n            }\n          }\n\n          key = _this4.collection.getKeyAfter(key);\n        }\n      };\n\n      addKeys(this.collection.getFirstKey());\n      return keys;\n    }\n  }, {\n    key: \"selectAll\",\n    value: function selectAll() {\n      if (this.selectionMode === 'multiple') {\n        this.state.setSelectedKeys('all');\n      }\n    }\n  }, {\n    key: \"clearSelection\",\n    value: function clearSelection() {\n      if (this.state.selectedKeys === 'all' || this.state.selectedKeys.size > 0) {\n        this.state.setSelectedKeys(new $c91e86e24f2dc9a2182dcc2674c58c$export$Selection());\n      }\n    }\n  }, {\n    key: \"toggleSelectAll\",\n    value: function toggleSelectAll() {\n      if (this.isSelectAll) {\n        this.clearSelection();\n      } else {\n        this.selectAll();\n      }\n    }\n  }, {\n    key: \"select\",\n    value: function select(key, e) {\n      if (this.selectionMode === 'none') {\n        return;\n      }\n\n      if (this.selectionMode === 'single') {\n        if (this.isSelected(key) && !this.disallowEmptySelection) {\n          this.toggleSelection(key);\n        } else {\n          this.replaceSelection(key);\n        }\n      } else if (e && e.shiftKey) {\n        this.extendSelection(key);\n      } else {\n        this.toggleSelection(key);\n      }\n    }\n  }, {\n    key: \"selectionMode\",\n    get: function get() {\n      return this.state.selectionMode;\n    }\n  }, {\n    key: \"disallowEmptySelection\",\n    get: function get() {\n      return this.state.disallowEmptySelection;\n    }\n  }, {\n    key: \"isFocused\",\n    get: function get() {\n      return this.state.isFocused;\n    }\n  }, {\n    key: \"focusedKey\",\n    get: function get() {\n      return this.state.focusedKey;\n    }\n  }, {\n    key: \"selectedKeys\",\n    get: function get() {\n      return this.state.selectedKeys === 'all' ? new Set(this.getSelectAllKeys()) : this.state.selectedKeys;\n    }\n  }, {\n    key: \"isEmpty\",\n    get: function get() {\n      return this.state.selectedKeys !== 'all' && this.state.selectedKeys.size === 0;\n    }\n  }, {\n    key: \"isSelectAll\",\n    get: function get() {\n      if (this.isEmpty) {\n        return false;\n      }\n\n      if (this.state.selectedKeys === 'all') {\n        return true;\n      }\n\n      if (this._isSelectAll != null) {\n        return this._isSelectAll;\n      }\n\n      var allKeys = this.getSelectAllKeys();\n      var selectedKeys = this.state.selectedKeys;\n      this._isSelectAll = allKeys.every(function (k) {\n        return selectedKeys.has(k);\n      });\n      return this._isSelectAll;\n    }\n  }, {\n    key: \"firstSelectedKey\",\n    get: function get() {\n      var _first;\n\n      var first = null;\n\n      for (var _iterator3 = _createForOfIteratorHelperLoose(this.state.selectedKeys), _step3; !(_step3 = _iterator3()).done;) {\n        var key = _step3.value;\n        var item = this.collection.getItem(key);\n\n        if (!first || (item == null ? void 0 : item.index) < first.index) {\n          first = item;\n        }\n      }\n\n      return (_first = first) == null ? void 0 : _first.key;\n    }\n  }, {\n    key: \"lastSelectedKey\",\n    get: function get() {\n      var _last;\n\n      var last = null;\n\n      for (var _iterator4 = _createForOfIteratorHelperLoose(this.state.selectedKeys), _step4; !(_step4 = _iterator4()).done;) {\n        var key = _step4.value;\n        var item = this.collection.getItem(key);\n\n        if (!last || (item == null ? void 0 : item.index) > last.index) {\n          last = item;\n        }\n      }\n\n      return (_last = last) == null ? void 0 : _last.key;\n    }\n  }]);\n\n  return SelectionManager;\n}();","map":{"version":3,"sources":["packages/@react-stately/selection/src/Selection.ts","packages/@react-stately/selection/src/useMultipleSelectionState.ts","packages/@react-stately/selection/src/SelectionManager.ts"],"names":["anchorKey","currentKey","constructor","keys","selectionMode","disallowEmptySelection","isFocusedRef","useRef","useState","focusedKeyRef","selectedKeysProp","useMemo","convertSelection","props","defaultSelectedKeys","useControlledState","disabledKeysProp","setFocused","setFocusedKey","selectedKeys","setSelectedKeys","disabledKeys","selection","collection","state","allowsCellSelection","_isSelectAll","options","key","allKeys","k","first","item","last","toKey","fromItem","toItem","addKeys","e"],"mappings":";;;;;;;;;;;;;;;;;;;;;;IAkBO,gD;;;;;AAILE,4DAAW,IAAXA,EAAW,SAAXA,EAAW,UAAXA,EAAiF;AAAA;;AAAA;;AAC/E,8BAAA,IAAA;AAD+E,UAHjFF,SAGiF,GAAA,KAAA,CAAA;AAAA,UAFjFC,UAEiF,GAAA,KAAA,CAAA;;AAE/E,QAAIE,IAAI,YAAR,gDAAA,EAA+B;AAC7B,YAAA,SAAA,GAAiBH,SAAS,IAAIG,IAAI,CAAlC,SAAA;AACA,YAAA,UAAA,GAAkBF,UAAU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A;;AACA,4DAAgB,KAAA,KAAA,CAAhB,YAAA,2CAAyC;AAAA,YAAzC,GAAyC;AACvC,YAAID,IAAI,GAAG,KAAA,UAAA,CAAA,OAAA,CAAX,GAAW,CAAX;;AACA,YAAI,CAAA,IAAA,IAAS,CAAA,IAAI,IAAJ,IAAA,GAAA,KAAA,CAAA,GAAA,IAAI,CAAJ,KAAA,IAAcC,IAAI,CAA/B,KAAA,EAAuC;AACrCA,UAAAA,IAAI,GAAJA,IAAAA;AACD;AACF;;AAED,aAAA,CAAA,KAAA,GAAA,IAAA,KAAA,IAAA,GAAA,KAAA,CAAA,GAAOA,KAAAA,CAAP,GAAA;AACD;AA/HI;;AAAA;AAAA","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 {Key} from 'react';\n\n/**\n * A Selection is a special Set containing Keys, which also has an anchor\n * and current selected key for use when range selecting.\n */\nexport class Selection extends Set<Key> {\n  anchorKey: Key;\n  currentKey: Key;\n\n  constructor(keys?: Iterable<Key> | Selection, anchorKey?: Key, currentKey?: Key) {\n    super(keys);\n    if (keys instanceof Selection) {\n      this.anchorKey = anchorKey || keys.anchorKey;\n      this.currentKey = currentKey || keys.currentKey;\n    } else {\n      this.anchorKey = anchorKey;\n      this.currentKey = currentKey;\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 {Key, useMemo, useRef, useState} from 'react';\nimport {MultipleSelection, SelectionMode} from '@react-types/shared';\nimport {MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\nimport {useControlledState} from '@react-stately/utils';\n\n/**\n * Manages state for multiple selection and focus in a collection.\n */\nexport function useMultipleSelectionState(props: MultipleSelection): MultipleSelectionState {\n  let {\n    selectionMode = 'none' as SelectionMode,\n    disallowEmptySelection\n  } = props;\n\n  // We want synchronous updates to `isFocused` and `focusedKey` after their setters are called.\n  // But we also need to trigger a react re-render. So, we have both a ref (sync) and state (async).\n  let isFocusedRef = useRef(false);\n  let [, setFocused] = useState(false);\n  let focusedKeyRef = useRef(null);\n  let [, setFocusedKey] = useState(null);\n  let selectedKeysProp = useMemo(() => convertSelection(props.selectedKeys), [props.selectedKeys]);\n  let defaultSelectedKeys = useMemo(() => convertSelection(props.defaultSelectedKeys, new Selection()), [props.defaultSelectedKeys]);\n  let [selectedKeys, setSelectedKeys] = useControlledState(\n    selectedKeysProp,\n    defaultSelectedKeys,\n    props.onSelectionChange\n  );\n  let disabledKeysProp = useMemo(() =>\n    props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n  , [props.disabledKeys]);\n\n  return {\n    selectionMode,\n    disallowEmptySelection,\n    get isFocused() {\n      return isFocusedRef.current;\n    },\n    setFocused(f) {\n      isFocusedRef.current = f;\n      setFocused(f);\n    },\n    get focusedKey() {\n      return focusedKeyRef.current;\n    },\n    setFocusedKey(k) {\n      focusedKeyRef.current = k;\n      setFocusedKey(k);\n    },\n    selectedKeys,\n    setSelectedKeys,\n    disabledKeys: disabledKeysProp\n  };\n}\n\nfunction convertSelection(selection: 'all' | Iterable<Key>, defaultValue?: Selection): 'all' | Selection {\n  if (!selection) {\n    return defaultValue;\n  }\n\n  return selection === 'all'\n    ? 'all'\n    : new Selection(selection);\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, Node, PressEvent, SelectionMode} from '@react-types/shared';\nimport {Key} from 'react';\nimport {MultipleSelectionManager, MultipleSelectionState} from './types';\nimport {Selection} from './Selection';\n\ninterface SelectionManagerOptions {\n  allowsCellSelection?: boolean\n}\n\n/**\n * An interface for reading and updating multiple selection state.\n */\nexport class SelectionManager implements MultipleSelectionManager {\n  private collection: Collection<Node<unknown>>;\n  private state: MultipleSelectionState;\n  private allowsCellSelection: boolean;\n  private _isSelectAll: boolean;\n\n  constructor(collection: Collection<Node<unknown>>, state: MultipleSelectionState, options?: SelectionManagerOptions) {\n    this.collection = collection;\n    this.state = state;\n    this.allowsCellSelection = options?.allowsCellSelection ?? false;\n    this._isSelectAll = null;\n  }\n\n  /**\n   * The type of selection that is allowed in the collection.\n   */\n  get selectionMode(): SelectionMode {\n    return this.state.selectionMode;\n  }\n\n  /**\n   * Whether the collection allows empty selection.\n   */\n  get disallowEmptySelection(): boolean {\n    return this.state.disallowEmptySelection;\n  }\n\n  /**\n   * Whether the collection is currently focused.\n   */\n  get isFocused(): boolean {\n    return this.state.isFocused;\n  }\n\n  /**\n   * Sets whether the collection is focused.\n   */\n  setFocused(isFocused: boolean) {\n    this.state.setFocused(isFocused);\n  }\n\n  /**\n   * The current focused key in the collection.\n   */\n  get focusedKey(): Key {\n    return this.state.focusedKey;\n  }\n\n  /**\n   * Sets the focused key.\n   */\n  setFocusedKey(key: Key) {\n    this.state.setFocusedKey(key);\n  }\n\n  /**\n   * The currently selected keys in the collection.\n   */\n  get selectedKeys(): Set<Key> {\n    return this.state.selectedKeys === 'all'\n      ? new Set(this.getSelectAllKeys())\n      : this.state.selectedKeys;\n  }\n\n  /**\n   * Returns whether a key is selected.\n   */\n  isSelected(key: Key) {\n    if (this.state.selectionMode === 'none') {\n      return false;\n    }\n\n    key = this.getKey(key);\n    return this.state.selectedKeys === 'all' || this.state.selectedKeys.has(key);\n  }\n\n  /**\n   * Whether the selection is empty.\n   */\n  get isEmpty(): boolean {\n    return this.state.selectedKeys !== 'all' && this.state.selectedKeys.size === 0;\n  }\n\n  /**\n   * Whether all items in the collection are selected.\n   */\n  get isSelectAll(): boolean {\n    if (this.isEmpty) {\n      return false;\n    }\n\n    if (this.state.selectedKeys === 'all') {\n      return true;\n    }\n\n    if (this._isSelectAll != null) {\n      return this._isSelectAll;\n    }\n\n    let allKeys = this.getSelectAllKeys();\n    let selectedKeys = this.state.selectedKeys;\n    this._isSelectAll = allKeys.every(k => selectedKeys.has(k));\n    return this._isSelectAll;\n  }\n\n  get firstSelectedKey(): Key | null {\n    let first: Node<unknown> | null = null;\n    for (let key of this.state.selectedKeys) {\n      let item = this.collection.getItem(key);\n      if (!first || item?.index < first.index) {\n        first = item;\n      }\n    }\n\n    return first?.key;\n  }\n\n  get lastSelectedKey(): Key | null {\n    let last: Node<unknown> | null = null;\n    for (let key of this.state.selectedKeys) {\n      let item = this.collection.getItem(key);\n      if (!last || item?.index > last.index) {\n        last = item;\n      }\n    }\n\n    return last?.key;\n  }\n\n  /**\n   * Extends the selection to the given key.\n   */\n  extendSelection(toKey: Key) {\n    toKey = this.getKey(toKey);\n    this.state.setSelectedKeys(selectedKeys => {\n      // Only select the one key if coming from a select all.\n      if (selectedKeys === 'all') {\n        return new Selection([toKey], toKey, toKey);\n      }\n\n      let selection = selectedKeys as Selection;\n      let anchorKey = selection.anchorKey || toKey;\n      let keys = new Selection(selection, anchorKey, toKey);\n      for (let key of this.getKeyRange(anchorKey, selection.currentKey || toKey)) {\n        keys.delete(key);\n      }\n\n      for (let key of this.getKeyRange(toKey, anchorKey)) {\n        if (!this.state.disabledKeys.has(key)) {\n          keys.add(key);\n        }\n      }\n\n      return keys;\n    });\n  }\n\n  private getKeyRange(from: Key, to: Key) {\n    let fromItem = this.collection.getItem(from);\n    let toItem = this.collection.getItem(to);\n    if (fromItem && toItem) {\n      if (fromItem.index <= toItem.index) {\n        return this.getKeyRangeInternal(from, to);\n      }\n\n      return this.getKeyRangeInternal(to, from);\n    }\n\n    return [];\n  }\n\n  private getKeyRangeInternal(from: Key, to: Key) {\n    let keys: Key[] = [];\n    let key = from;\n    while (key) {\n      let item = this.collection.getItem(key);\n      if (item && item.type === 'item' || (item.type === 'cell' && this.allowsCellSelection)) {\n        keys.push(key);\n      }\n\n      if (key === to) {\n        return keys;\n      }\n\n      key = this.collection.getKeyAfter(key);\n    }\n\n    return [];\n  }\n\n  private getKey(key: Key) {\n    let item = this.collection.getItem(key);\n    if (!item) {\n      // ¯\\_(ツ)_/¯\n      return key;\n    }\n\n    // If cell selection is allowed, just return the key.\n    if (item.type === 'cell' && this.allowsCellSelection) {\n      return key;\n    }\n\n    // Find a parent item to select\n    while (item.type !== 'item' && item.parentKey) {\n      item = this.collection.getItem(item.parentKey);\n    }\n\n    if (!item || item.type !== 'item') {\n      return null;\n    }\n\n    return item.key;\n  }\n\n  /**\n   * Toggles whether the given key is selected.\n   */\n  toggleSelection(key: Key) {\n    key = this.getKey(key);\n    if (key == null) {\n      return;\n    }\n\n    this.state.setSelectedKeys(selectedKeys => {\n      let keys = new Selection(selectedKeys === 'all' ? this.getSelectAllKeys() : selectedKeys);\n      if (keys.has(key)) {\n        keys.delete(key);\n        // TODO: move anchor to last selected key...\n        // Does `current` need to move here too?\n      } else {\n        keys.add(key);\n        keys.anchorKey = key;\n        keys.currentKey = key;\n      }\n\n      return keys;\n    });\n  }\n\n  /**\n   * Replaces the selection with only the given key.\n   */\n  replaceSelection(key: Key) {\n    key = this.getKey(key);\n    if (key == null) {\n      return;\n    }\n\n    this.state.setSelectedKeys(new Selection([key], key, key));\n  }\n\n  private getSelectAllKeys() {\n    let keys: Key[] = [];\n    let addKeys = (key: Key) => {\n      while (key) {\n        if (!this.state.disabledKeys.has(key)) {\n          let item = this.collection.getItem(key);\n          if (item.type === 'item') {\n            keys.push(key);\n          }\n\n          // Add child keys. If cell selection is allowed, then include item children too.\n          if (item.hasChildNodes && (this.allowsCellSelection || item.type !== 'item')) {\n            addKeys([...item.childNodes][0].key);\n          }\n        }\n\n        key = this.collection.getKeyAfter(key);\n      }\n    };\n\n    addKeys(this.collection.getFirstKey());\n    return keys;\n  }\n\n  /**\n   * Selects all items in the collection.\n   */\n  selectAll() {\n    if (this.selectionMode === 'multiple') {\n      this.state.setSelectedKeys('all');\n    }\n  }\n\n  /**\n   * Removes all keys from the selection.\n   */\n  clearSelection() {\n    if (this.state.selectedKeys === 'all' || this.state.selectedKeys.size > 0) {\n      this.state.setSelectedKeys(new Selection());\n    }\n  }\n\n  /**\n   * Toggles between select all and an empty selection.\n   */\n  toggleSelectAll() {\n    if (this.isSelectAll) {\n      this.clearSelection();\n    } else {\n      this.selectAll();\n    }\n  }\n\n  select(key: Key, e?: PressEvent | PointerEvent) {\n    if (this.selectionMode === 'none') {\n      return;\n    }\n\n    if (this.selectionMode === 'single') {\n      if (this.isSelected(key) && !this.disallowEmptySelection) {\n        this.toggleSelection(key);\n      } else {\n        this.replaceSelection(key);\n      }\n    } else if (e && e.shiftKey) {\n      this.extendSelection(key);\n    } else {\n      this.toggleSelection(key);\n    }\n  }\n}\n"]},"metadata":{},"sourceType":"module"}