{"ast":null,"code":"import _regeneratorRuntime from \"@babel/runtime/regenerator\";\nimport _slicedToArray from \"@babel/runtime/helpers/slicedToArray\";\nimport _classCallCheck from \"@babel/runtime/helpers/classCallCheck\";\nimport _createClass from \"@babel/runtime/helpers/createClass\";\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\nimport { useControlledState } from \"@react-stately/utils\";\nimport _babelRuntimeHelpersEsmExtends from \"@babel/runtime/helpers/esm/extends\";\nimport { useCollection } from \"@react-stately/collections\";\nimport { SelectionManager, useMultipleSelectionState } from \"@react-stately/selection\";\nimport { useEffect, useMemo } from \"react\";\nvar $ed5d55e571caf578a4f08babbaa26be$var$_Symbol$iterator;\n$ed5d55e571caf578a4f08babbaa26be$var$_Symbol$iterator = Symbol.iterator;\nexport var ListCollection = function () {\n  function ListCollection(nodes) {\n    var _this = this;\n\n    _classCallCheck(this, ListCollection);\n\n    var _last;\n\n    this.keyMap = new Map();\n    this.iterable = void 0;\n    this.firstKey = void 0;\n    this.lastKey = void 0;\n    this.iterable = nodes;\n\n    var visit = function visit(node) {\n      _this.keyMap.set(node.key, node);\n\n      if (node.childNodes && node.type === 'section') {\n        for (var _iterator = _createForOfIteratorHelperLoose(node.childNodes), _step; !(_step = _iterator()).done;) {\n          var child = _step.value;\n          visit(child);\n        }\n      }\n    };\n\n    for (var _iterator2 = _createForOfIteratorHelperLoose(nodes), _step2; !(_step2 = _iterator2()).done;) {\n      var node = _step2.value;\n      visit(node);\n    }\n\n    var last;\n    var index = 0;\n\n    for (var _iterator3 = _createForOfIteratorHelperLoose(this.keyMap), _step3; !(_step3 = _iterator3()).done;) {\n      var _ref = _step3.value;\n\n      var _ref2 = _slicedToArray(_ref, 2);\n\n      var key = _ref2[0];\n      var _node = _ref2[1];\n\n      if (last) {\n        last.nextKey = key;\n        _node.prevKey = last.key;\n      } else {\n        this.firstKey = key;\n        _node.prevKey = undefined;\n      }\n\n      if (_node.type === 'item') {\n        _node.index = index++;\n      }\n\n      last = _node;\n      last.nextKey = undefined;\n    }\n\n    this.lastKey = (_last = last) == null ? void 0 : _last.key;\n  }\n\n  _createClass(ListCollection, [{\n    key: $ed5d55e571caf578a4f08babbaa26be$var$_Symbol$iterator,\n    value: _regeneratorRuntime.mark(function value() {\n      return _regeneratorRuntime.wrap(function value$(_context) {\n        while (1) {\n          switch (_context.prev = _context.next) {\n            case 0:\n              return _context.delegateYield(this.iterable, \"t0\", 1);\n\n            case 1:\n            case \"end\":\n              return _context.stop();\n          }\n        }\n      }, value, this);\n    })\n  }, {\n    key: \"getKeys\",\n    value: function getKeys() {\n      return this.keyMap.keys();\n    }\n  }, {\n    key: \"getKeyBefore\",\n    value: function getKeyBefore(key) {\n      var node = this.keyMap.get(key);\n      return node ? node.prevKey : null;\n    }\n  }, {\n    key: \"getKeyAfter\",\n    value: function getKeyAfter(key) {\n      var node = this.keyMap.get(key);\n      return node ? node.nextKey : null;\n    }\n  }, {\n    key: \"getFirstKey\",\n    value: function getFirstKey() {\n      return this.firstKey;\n    }\n  }, {\n    key: \"getLastKey\",\n    value: function getLastKey() {\n      return this.lastKey;\n    }\n  }, {\n    key: \"getItem\",\n    value: function getItem(key) {\n      return this.keyMap.get(key);\n    }\n  }, {\n    key: \"size\",\n    get: function get() {\n      return this.keyMap.size;\n    }\n  }]);\n\n  return ListCollection;\n}();\nexport function useListState(props) {\n  var filter = props.filter;\n  var selectionState = useMultipleSelectionState(props);\n  var disabledKeys = useMemo(function () {\n    return props.disabledKeys ? new Set(props.disabledKeys) : new Set();\n  }, [props.disabledKeys]);\n\n  var factory = function factory(nodes) {\n    return filter ? new ListCollection(filter(nodes)) : new ListCollection(nodes);\n  };\n\n  var collection = useCollection(props, factory, null, [filter]);\n  useEffect(function () {\n    if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {\n      selectionState.setFocusedKey(null);\n    }\n  }, [collection, selectionState.focusedKey]);\n  return {\n    collection: collection,\n    disabledKeys: disabledKeys,\n    selectionManager: new SelectionManager(collection, selectionState)\n  };\n}\nexport function useSingleSelectListState(props) {\n  var _props$defaultSelecte;\n\n  var _useControlledState = useControlledState(props.selectedKey, (_props$defaultSelecte = props.defaultSelectedKey) != null ? _props$defaultSelecte : null, props.onSelectionChange),\n      _useControlledState2 = _slicedToArray(_useControlledState, 2),\n      selectedKey = _useControlledState2[0],\n      setSelectedKey = _useControlledState2[1];\n\n  var selectedKeys = useMemo(function () {\n    return selectedKey != null ? [selectedKey] : [];\n  }, [selectedKey]);\n\n  var _useListState = useListState(_babelRuntimeHelpersEsmExtends({}, props, {\n    selectionMode: 'single',\n    disallowEmptySelection: true,\n    selectedKeys: selectedKeys,\n    onSelectionChange: function onSelectionChange(keys) {\n      var key = keys.values().next().value;\n\n      if (key === selectedKey && props.onSelectionChange) {\n        props.onSelectionChange(key);\n      }\n\n      setSelectedKey(key);\n    }\n  })),\n      collection = _useListState.collection,\n      disabledKeys = _useListState.disabledKeys,\n      selectionManager = _useListState.selectionManager;\n\n  var selectedItem = selectedKey != null ? collection.getItem(selectedKey) : null;\n  return {\n    collection: collection,\n    disabledKeys: disabledKeys,\n    selectionManager: selectionManager,\n    selectedKey: selectedKey,\n    setSelectedKey: setSelectedKey,\n    selectedItem: selectedItem\n  };\n}","map":{"version":3,"sources":["packages/@react-stately/list/src/ListCollection.ts","packages/@react-stately/list/src/useListState.ts","packages/@react-stately/list/src/useSingleSelectListState.ts"],"names":["keyMap","iterable","firstKey","lastKey","constructor","visit","node","index","last","Symbol","iterator","filter","selectionState","useMultipleSelectionState","disabledKeys","useMemo","props","factory","nodes","collection","useCollection","useEffect","selectionManager","useControlledState","selectedKeys","selectedKey","selectionMode","disallowEmptySelection","onSelectionChange","keys","key","setSelectedKey","selectedItem"],"mappings":";;;;;;;;;;;;;;;;;wDA+DIS,MAAM,CAACC,Q;AAhDJ,WAAA,cAAA;AAMLN,0BAAW,KAAXA,EAAsC;AAAA;;AAAA;;AAAA,QAAA,KAAA;;AAAA,SAL9BJ,MAK8B,GALF,IAAA,GAAA,EAKE;AAAA,SAJ9BC,QAI8B,GAAA,KAAA,CAAA;AAAA,SAH9BC,QAG8B,GAAA,KAAA,CAAA;AAAA,SAF9BC,OAE8B,GAAA,KAAA,CAAA;AACpC,SAAA,QAAA,GAAA,KAAA;;AAEA,QAAIE,KAAK,GAAIC,SAATD,KAASC,CAAAA,IAAD,EAAmB;AAC7B,MAAA,KAAA,CAAA,MAAA,CAAA,GAAA,CAAgBA,IAAI,CAApB,GAAA,EAAA,IAAA;;AAEA,UAAIA,IAAI,CAAJA,UAAAA,IAAmBA,IAAI,CAAJA,IAAAA,KAAvB,SAAA,EAAgD;AAC9C,6DAAkBA,IAAI,CAAtB,UAAA,wCAAmC;AAAA,cAAnC,KAAmC;AACjCD,UAAAA,KAAK,CAALA,KAAK,CAALA;AACD;AACF;AAPH,KAAA;;AAUA,0DAAA,KAAA,2CAAwB;AAAA,UAAxB,IAAwB;AACtBA,MAAAA,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GtFA,gBAHsF;;AAqBrH,MAAIU,YAAY,GAAGP,WAAW,IAAXA,IAAAA,GACfN,UAAU,CAAVA,OAAAA,CADeM,WACfN,CADeM,GAAnB,IAAA;AAIA,SAAO;AACLN,IAAAA,UADK,EACLA,UADK;AAELL,IAAAA,YAFK,EAELA,YAFK;AAGLQ,IAAAA,gBAHK,EAGLA,gBAHK;AAILG,IAAAA,WAJK,EAILA,WAJK;AAKLM,IAAAA,cALK,EAKLA,cALK;AAMLC,IAAAA,YAAAA,EAAAA;AANK,GAAP;AAQD","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 {Collection, Node} from '@react-types/shared';\nimport {Key} from 'react';\n\nexport class ListCollection<T> implements Collection<Node<T>> {\n  private keyMap: Map<Key, Node<T>> = new Map();\n  private iterable: Iterable<Node<T>>;\n  private firstKey: Key;\n  private lastKey: Key;\n\n  constructor(nodes: Iterable<Node<T>>) {\n    this.iterable = nodes;\n\n    let visit = (node: Node<T>) => {\n      this.keyMap.set(node.key, node);\n\n      if (node.childNodes && node.type === 'section') {\n        for (let child of node.childNodes) {\n          visit(child);\n        }\n      }\n    };\n\n    for (let node of nodes) {\n      visit(node);\n    }\n\n    let last: Node<T>;\n    let index = 0;\n    for (let [key, node] of this.keyMap) {\n      if (last) {\n        last.nextKey = key;\n        node.prevKey = last.key;\n      } else {\n        this.firstKey = key;\n        node.prevKey = undefined;\n      }\n\n      if (node.type === 'item') {\n        node.index = index++;\n      }\n\n      last = node;\n\n      // Set nextKey as undefined since this might be the last node\n      // If it isn't the last node, last.nextKey will properly set at start of new loop\n      last.nextKey = undefined;\n    }\n\n    this.lastKey = last?.key;\n  }\n\n  *[Symbol.iterator]() {\n    yield* this.iterable;\n  }\n\n  get size() {\n    return this.keyMap.size;\n  }\n\n  getKeys() {\n    return this.keyMap.keys();\n  }\n\n  getKeyBefore(key: Key) {\n    let node = this.keyMap.get(key);\n    return node ? node.prevKey : null;\n  }\n\n  getKeyAfter(key: Key) {\n    let node = this.keyMap.get(key);\n    return node ? node.nextKey : null;\n  }\n\n  getFirstKey() {\n    return this.firstKey;\n  }\n\n  getLastKey() {\n    return this.lastKey;\n  }\n\n  getItem(key: Key) {\n    return this.keyMap.get(key);\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, CollectionBase, MultipleSelection, Node} from '@react-types/shared';\nimport {Key, useEffect, useMemo} from 'react';\nimport {ListCollection} from './ListCollection';\nimport {SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {useCollection} from '@react-stately/collections';\n\nexport interface ListProps<T> extends CollectionBase<T>, MultipleSelection {\n  /** Filter function to generate a filtered list of nodes. */\n  filter?: (nodes: Iterable<Node<T>>) => Iterable<Node<T>>\n}\nexport interface ListState<T> {\n  /** A collection of items in the list. */\n  collection: Collection<Node<T>>,\n\n  /** A set of items that are disabled. */\n  disabledKeys: Set<Key>,\n\n  /** A selection manager to read and update multiple selection state. */\n  selectionManager: SelectionManager\n}\n\n/**\n * Provides state management for list-like components. Handles building a collection\n * of items from props, and manages multiple selection state.\n */\nexport function useListState<T extends object>(props: ListProps<T>): ListState<T>  {\n  let {\n    filter\n  } = props;\n\n  let selectionState = useMultipleSelectionState(props);\n  let disabledKeys = useMemo(() =>\n    props.disabledKeys ? new Set(props.disabledKeys) : new Set<Key>()\n  , [props.disabledKeys]);\n\n  let factory = nodes => filter ? new ListCollection(filter(nodes)) : new ListCollection(nodes as Iterable<Node<T>>);\n\n  let collection = useCollection(props, factory, null, [filter]);\n\n  // Reset focused key if that item is deleted from the collection.\n  useEffect(() => {\n    if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) {\n      selectionState.setFocusedKey(null);\n    }\n  }, [collection, selectionState.focusedKey]);\n\n  return {\n    collection,\n    disabledKeys,\n    selectionManager: new SelectionManager(collection, selectionState)\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 {CollectionBase, SingleSelection} from '@react-types/shared';\nimport {Key, useMemo} from 'react';\nimport {ListState, useListState} from './useListState';\nimport {Node} from '@react-types/shared';\nimport {useControlledState} from '@react-stately/utils';\n\nexport interface SingleSelectListProps<T> extends CollectionBase<T>, SingleSelection {\n  /** Filter function to generate a filtered list of nodes. */\n  filter?: (nodes: Iterable<Node<T>>) => Iterable<Node<T>>\n}\nexport interface SingleSelectListState<T> extends ListState<T> {\n  /** The key for the currently selected item. */\n  readonly selectedKey: Key,\n\n  /** Sets the selected key. */\n  setSelectedKey(key: Key): void,\n\n  /** The value of the currently selected item. */\n  readonly selectedItem: Node<T>\n}\n\n/**\n * Provides state management for list-like components with single selection.\n * Handles building a collection of items from props, and manages selection state.\n */\nexport function useSingleSelectListState<T extends object>(props: SingleSelectListProps<T>): SingleSelectListState<T>  {\n  let [selectedKey, setSelectedKey] = useControlledState(props.selectedKey, props.defaultSelectedKey ?? null, props.onSelectionChange);\n  let selectedKeys = useMemo(() => selectedKey != null ? [selectedKey] : [], [selectedKey]);\n  let {collection, disabledKeys, selectionManager} = useListState({\n    ...props,\n    selectionMode: 'single',\n    disallowEmptySelection: true,\n    selectedKeys,\n    onSelectionChange: (keys: Set<Key>) => {\n      let key = keys.values().next().value;\n\n      // Always fire onSelectionChange, even if the key is the same\n      // as the current key (useControlledState does not).\n      if (key === selectedKey && props.onSelectionChange) {\n        props.onSelectionChange(key);\n      }\n\n      setSelectedKey(key);\n    }\n  });\n\n  let selectedItem = selectedKey != null\n    ? collection.getItem(selectedKey)\n    : null;\n\n  return {\n    collection,\n    disabledKeys,\n    selectionManager,\n    selectedKey,\n    setSelectedKey,\n    selectedItem\n  };\n}\n"]},"metadata":{},"sourceType":"module"}