{"ast":null,"code":"import _defineProperty from \"@babel/runtime/helpers/defineProperty\";\nimport _toConsumableArray from \"@babel/runtime/helpers/toConsumableArray\";\nimport _slicedToArray from \"@babel/runtime/helpers/slicedToArray\";\nimport _classCallCheck from \"@babel/runtime/helpers/classCallCheck\";\nimport _createClass from \"@babel/runtime/helpers/createClass\";\n\nfunction ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }\n\nfunction _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }\n\nimport _regeneratorRuntime from \"@babel/runtime/regenerator\";\n\nfunction _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== \"undefined\" && o[Symbol.iterator] || o[\"@@iterator\"]; if (it) return (it = it.call(o)).next.bind(it); 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.\"); }\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 { useMemo as $2vUeM$useMemo, useEffect as $2vUeM$useEffect } from \"react\";\nimport { useMultipleSelectionState as $2vUeM$useMultipleSelectionState, SelectionManager as $2vUeM$SelectionManager } from \"@react-stately/selection\";\nimport { useCollection as $2vUeM$useCollection } from \"@react-stately/collections\";\nimport { useControlledState as $2vUeM$useControlledState } from \"@react-stately/utils\";\n\nfunction $parcel$export(e, n, v, s) {\n  Object.defineProperty(e, n, {\n    get: v,\n    set: s,\n    enumerable: true,\n    configurable: true\n  });\n}\n\nvar $22ee28165633d781$exports = {};\n$parcel$export($22ee28165633d781$exports, \"useListState\", function () {\n  return $22ee28165633d781$export$2f645645f7bca764;\n});\nvar $8b1d221864d202f1$exports = {};\n$parcel$export($8b1d221864d202f1$exports, \"ListCollection\", function () {\n  return $8b1d221864d202f1$export$d085fb9e920b5ca7;\n});\n\nvar $8b1d221864d202f1$export$d085fb9e920b5ca7 = function (_Symbol$iterator) {\n  function $8b1d221864d202f1$export$d085fb9e920b5ca7(nodes) {\n    var _this = this,\n        _last;\n\n    _classCallCheck(this, $8b1d221864d202f1$export$d085fb9e920b5ca7);\n\n    this.keyMap = new Map();\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 node2 = _step2.value;\n      visit(node2);\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 node1 = _ref2[1];\n\n      if (last) {\n        last.nextKey = key;\n        node1.prevKey = last.key;\n      } else {\n        this.firstKey = key;\n        node1.prevKey = undefined;\n      }\n\n      if (node1.type === 'item') node1.index = index++;\n      last = node1;\n      last.nextKey = undefined;\n    }\n\n    this.lastKey = (_last = last) == null ? void 0 : _last.key;\n  }\n\n  _createClass($8b1d221864d202f1$export$d085fb9e920b5ca7, [{\n    key: _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: \"size\",\n    get: function get() {\n      return this.keyMap.size;\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: \"at\",\n    value: function at(idx) {\n      var keys = _toConsumableArray(this.getKeys());\n\n      return this.getItem(keys[idx]);\n    }\n  }]);\n\n  return $8b1d221864d202f1$export$d085fb9e920b5ca7;\n}(Symbol.iterator);\n\nfunction $22ee28165633d781$export$2f645645f7bca764(props) {\n  var filter = props.filter;\n  var selectionState = $2vUeM$useMultipleSelectionState(props);\n  var disabledKeys = $2vUeM$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 $8b1d221864d202f1$export$d085fb9e920b5ca7(filter(nodes)) : new $8b1d221864d202f1$export$d085fb9e920b5ca7(nodes);\n  };\n\n  var context = $2vUeM$useMemo(function () {\n    return {\n      suppressTextValueWarning: props.suppressTextValueWarning\n    };\n  }, [props.suppressTextValueWarning]);\n  var collection = $2vUeM$useCollection(props, factory, context, [filter]);\n  $2vUeM$useEffect(function () {\n    if (selectionState.focusedKey != null && !collection.getItem(selectionState.focusedKey)) selectionState.setFocusedKey(null);\n  }, [collection, selectionState.focusedKey]);\n  return {\n    collection: collection,\n    disabledKeys: disabledKeys,\n    selectionManager: new $2vUeM$SelectionManager(collection, selectionState)\n  };\n}\n\nvar $81c60a02219e0c72$exports = {};\n$parcel$export($81c60a02219e0c72$exports, \"useSingleSelectListState\", function () {\n  return $81c60a02219e0c72$export$e7f05e985daf4b5f;\n});\n\nfunction $81c60a02219e0c72$export$e7f05e985daf4b5f(props) {\n  var _props$defaultSelecte;\n\n  var _$2vUeM$useControlled = $2vUeM$useControlledState(props.selectedKey, (_props$defaultSelecte = props.defaultSelectedKey) != null ? _props$defaultSelecte : null, props.onSelectionChange),\n      _$2vUeM$useControlled2 = _slicedToArray(_$2vUeM$useControlled, 2),\n      selectedKey = _$2vUeM$useControlled2[0],\n      setSelectedKey = _$2vUeM$useControlled2[1];\n\n  var selectedKeys = $2vUeM$useMemo(function () {\n    return selectedKey != null ? [selectedKey] : [];\n  }, [selectedKey]);\n\n  var _$22ee28165633d781$ex = $22ee28165633d781$export$2f645645f7bca764(_objectSpread(_objectSpread({}, props), {}, {\n    selectionMode: 'single',\n    disallowEmptySelection: true,\n    allowDuplicateSelectionEvents: true,\n    selectedKeys: selectedKeys,\n    onSelectionChange: function onSelectionChange(keys) {\n      var key = keys.values().next().value;\n      if (key === selectedKey && props.onSelectionChange) props.onSelectionChange(key);\n      setSelectedKey(key);\n    }\n  })),\n      collection = _$22ee28165633d781$ex.collection,\n      disabledKeys = _$22ee28165633d781$ex.disabledKeys,\n      selectionManager = _$22ee28165633d781$ex.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}\n\nexport { $22ee28165633d781$export$2f645645f7bca764 as useListState, $81c60a02219e0c72$export$e7f05e985daf4b5f as useSingleSelectListState, $8b1d221864d202f1$export$d085fb9e920b5ca7 as ListCollection };","map":{"version":3,"sources":["packages/@react-stately/list/src/useListState.ts","packages/@react-stately/list/src/ListCollection.ts","packages/@react-stately/list/src/useSingleSelectListState.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ICea,yC;qDAMC,K,EAA0B;AAAA;AAAA;;AAAA;;AANjC,SACG,MADH,GAC+B,IAAI,GAAJ,EAD/B;AAOH,SAAK,QAAL,GAAgB,KAAhB;;AAEA,QAAI,KAAK,GAAA,SAAL,KAAK,CAAI,IAAJ,EAAsB;AAC7B,MAAA,KAAI,CAAC,MAAL,CAAY,GAAZ,CAAgB,IAAI,CAAC,GAArB,EAA0B,IAA1B;;AAEA,UAAI,IAAI,CAAC,UAAL,IAAmB,IAAI,CAAC,IAAL,KAAc,SAArC;AACE,6DAAkB,IAAI,CAAC,UAAvB;AAAA,cAAS,KAAT;AACE,UAAA,KAAK,CAAC,KAAD,CAAL;AADF;AADF;AAKD,KARD;;AAUA,0DAAiB,KAAjB;AAAA,UAAS,KAAT;AACE,MAAA,KAAK,CAAC,KAAD,CAAL;AADF;;AAIA,QAAI,IAAJ;AACA,QAAI,KAAK,GAAG,CAAZ;;AACA,0DAAwB,KAAK,M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e,yC,CAA2C,K,EAA4D;AAAA;;AACrH,8BAAoC,yBAAkB,CAAC,KAAK,CAAC,WAAP,2BAAoB,KAAK,CAAC,kBAA1B,oCAAgD,IAAhD,EAAsD,KAAK,CAAC,iBAA5D,CAAtD;AAAA;AAAA,MAAK,WAAL;AAAA,MAAkB,cAAlB;;AACA,MAAI,YAAY,GAAG,cAAO,CAAA;AAAA,WAAO,WAAW,IAAI,IAAf,GAAsB,CAAC,WAAD,CAAtB,GAAsC,EAA7C;AAAA,GAAA,EAAiD,CAAC,WAAD,CAAjD,CAA1B;;AACA,8BAAmD,yCAAY,iCAC1D,KAD0D;AAE7D,IAAA,aAAa,EAAE,QAF8C;AAG7D,IAAA,sBAAsB,EAAE,IAHqC;AAI7D,IAAA,6BAA6B,EAAE,IAJ8B;kBAK7D,YAL6D;AAM7D,IAAA,iBAAiB,EAAA,2BAAG,IAAH,EAAsB;AACrC,UAAI,GAAG,GAAG,IAAI,CAAC,MAAL,GAAc,IAAd,GAAqB,KAA/B;AAIA,UAAI,GAAG,KAAK,WAAR,IAAuB,KAAK,CAAC,iBAAjC,EACE,KAAK,CAAC,iBAAN,CAAwB,GAAxB;AAGF,MAAA,cAAc,CAAC,GAAD,CAAd;AACD;AAhB4D,KAA/D;AAAA,MAAK,UAAL,yBAAK,UAAL;AAAA,MAAiB,YAAjB,yBAAe,YAAf;AAAA,MAA+B,gBAA/B,yBAA6B,gBAA7B;;AAmBA,MAAI,YAAY,GAAG,WAAW,IAAI,IAAf,GACf,UAAU,CAAC,OAAX,CAAmB,WAAnB,CADe,GAEf,IAFJ;AAIA,SAAO;gBACL,UADK;kBAEL,YAFK;sBAGL,gBAHK;iBAIL,WAJK;oBAKL,cALK;kBAML;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, CollectionBase, Node} from '@react-types/shared';\nimport {Key, useEffect, useMemo} from 'react';\nimport {ListCollection} from './ListCollection';\nimport {MultipleSelectionStateProps, SelectionManager, useMultipleSelectionState} from '@react-stately/selection';\nimport {useCollection} from '@react-stately/collections';\n\nexport interface ListProps<T> extends CollectionBase<T>, MultipleSelectionStateProps {\n  /** Filter function to generate a filtered list of nodes. */\n  filter?: (nodes: Iterable<Node<T>>) => Iterable<Node<T>>,\n  /** @private */\n  suppressTextValueWarning?: boolean\n}\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 {filter} = 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  let context = useMemo(() => ({suppressTextValueWarning: props.suppressTextValueWarning}), [props.suppressTextValueWarning]);\n\n  let collection = useCollection(props, factory, context, [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 {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  at(idx: number) {\n    const keys = [...this.getKeys()];\n    return this.getItem(keys[idx]);\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>, Omit<SingleSelection, 'disallowEmptySelection'> {\n  /** Filter function to generate a filtered list of nodes. */\n  filter?: (nodes: Iterable<Node<T>>) => Iterable<Node<T>>,\n  /** @private */\n  suppressTextValueWarning?: boolean\n}\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    allowDuplicateSelectionEvents: 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"}