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QAC3B,OAAO,OAAO,KAAK,OAAO,IAAI,OAAO;IACvC;IAEA,YAAY,GAAQ,EAAc;QAChC,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;QAC3B,OAAO,OAAO,KAAK,OAAO,IAAI,OAAO;IACvC;IAEA,cAA0B;QACxB,OAAO,IAAI,CAAC,QAAQ;IACtB;IAEA,aAAyB;QACvB,OAAO,IAAI,CAAC,OAAO;IACrB;IAEA,QAAQ,GAAQ,EAAkB;QAChC,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ;IACjC;IAEA,GAAG,GAAW,EAAkB;QAC9B,MAAM,OAAO;eAAI,IAAI,CAAC,OAAO;SAAG;QAChC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI;IAC/B;IAEA,YAAY,GAAQ,EAAqB;QACvC,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;QAC3B,OAAO,MAAM,cAAc,EAAE;IAC/B;AACF","sources":["packages/react-stately/src/list/ListCollection.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {Collection, Key, Node} from '@react-types/shared';\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 | null = null;\n  private lastKey: Key | null = null;\n  private _size: number;\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> | null = null;\n    let index = 0;\n    let size = 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      // Only count sections and items when determining size so that\n      // loaders and separators in RAC/S2 don't influence the emptyState determination\n      if (node.type === 'section' || node.type === 'item') {\n        size++;\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    this._size = size;\n    this.lastKey = last?.key ?? null;\n  }\n\n  *[Symbol.iterator](): IterableIterator<Node<T>> {\n    yield* this.iterable;\n  }\n\n  get size(): number {\n    return this._size;\n  }\n\n  getKeys(): IterableIterator<Key> {\n    return this.keyMap.keys();\n  }\n\n  getKeyBefore(key: Key): Key | null {\n    let node = this.keyMap.get(key);\n    return node ? node.prevKey ?? null : null;\n  }\n\n  getKeyAfter(key: Key): Key | null {\n    let node = this.keyMap.get(key);\n    return node ? node.nextKey ?? null : null;\n  }\n\n  getFirstKey(): Key | null {\n    return this.firstKey;\n  }\n\n  getLastKey(): Key | null {\n    return this.lastKey;\n  }\n\n  getItem(key: Key): Node<T> | null {\n    return this.keyMap.get(key) ?? null;\n  }\n\n  at(idx: number): Node<T> | null {\n    const keys = [...this.getKeys()];\n    return this.getItem(keys[idx]);\n  }\n\n  getChildren(key: Key): Iterable<Node<T>> {\n    let node = this.keyMap.get(key);\n    return node?.childNodes || [];\n  }\n}\n"],"names":[],"version":3,"file":"ListCollection.cjs.map"}