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O;eAAI,IAAI,CAAC,IAAI;SAAC,CAAC,MAAM;IAC9B;IAEA,UAAiC;QAC/B,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI;IACzB;IAEA,aAAa,GAAQ,EAAc;QACjC,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;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;eAAI,IAAI,CAAC,IAAI;SAAC,CAAC,EAAE,EAAE;IAC5B;IAEA,aAAyB;QACvB,IAAI,OAAO;eAAI,IAAI,CAAC,IAAI;SAAC;QACzB,OAAO,IAAI,CAAC,KAAK,MAAM,GAAG,EAAE,EAAE;IAChC;IAEA,QAAQ,GAAQ,EAAsB;QACpC,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ;IACjC;IAEA,GAAG,GAAW,EAAsB;QAClC,MAAM,OAAO;eAAI,IAAI,CAAC,OAAO;SAAG;QAChC,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI;IAC/B;IAEA,YAAY,GAAQ,EAAyB;QAC3C,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;QAC3B,OAAO,MAAM,cAAc,EAAE;IAC/B;AACF","sources":["packages/react-stately/src/grid/GridCollection.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 interface IGridCollection<T> extends Collection<GridNode<T>> {\n  /** The number of columns in the grid. */\n  columnCount: number,\n  /** A list of rows in the grid. */\n  rows: GridNode<T>[]\n}\n\nexport interface GridRow<T> extends Partial<GridNode<T>> {\n  key?: Key,\n  type: string,\n  childNodes: Iterable<Node<T>>\n}\n\nexport interface GridNode<T> extends Node<T> {\n  column?: GridNode<T>,\n  /**\n   * The number of columns spanned by this cell. Use `colSpan` instead.\n   * @deprecated\n   */\n  colspan?: number,\n  /** The number of columns spanned by this cell.  */\n  colSpan?: number | null,\n  /** The column index of this cell, accounting for any colSpans. */\n  colIndex?: number | null,\n  /** The index of this node within its parent, ignoring sibling nodes that aren't of the same type. */\n  indexOfType?: number\n}\n\ninterface GridCollectionOptions<T> {\n  columnCount: number,\n  items: GridRow<T>[],\n  visitNode?: (cell: GridNode<T>) => GridNode<T>\n}\n\nexport class GridCollection<T> implements IGridCollection<T> {\n  keyMap: Map<Key, GridNode<T>> = new Map();\n  columnCount: number;\n  rows: GridNode<T>[];\n\n  constructor(opts: GridCollectionOptions<T>) {\n    this.keyMap = new Map();\n    this.columnCount = opts?.columnCount;\n    this.rows = [];\n\n    let visit = (node: GridNode<T>) => {\n      // If the node is the same object as the previous node for the same key,\n      // we can skip this node and its children. We always visit columns though,\n      // because we depend on order to build the columns array.\n      let prevNode = this.keyMap.get(node.key);\n      if (opts.visitNode) {\n        node = opts.visitNode(node);\n      }\n\n      this.keyMap.set(node.key, node);\n\n      let childKeys = new Set();\n      let last: GridNode<T> | null = null;\n      let rowHasCellWithColSpan = false;\n\n      if (node.type === 'item') {\n        for (let child of node.childNodes) {\n          if (child.props?.colSpan !== undefined) {\n            rowHasCellWithColSpan = true;\n            break;\n          }\n        }\n      }\n\n      for (let child of node.childNodes as Iterable<GridNode<T>>) {\n        if (child.type === 'cell' && rowHasCellWithColSpan) {\n          child.colspan = child.props?.colSpan;\n          child.colSpan = child.props?.colSpan;\n          child.colIndex = !last ? child.index : (last.colIndex ?? last.index) + (last.colSpan ?? 1);\n        }\n\n        if (child.type === 'cell' && child.parentKey == null) {\n          // if child is a cell parent key isn't already established by the collection, match child node to parent row\n          child.parentKey = node.key;\n        }\n        childKeys.add(child.key);\n\n        if (last) {\n          last.nextKey = child.key;\n          child.prevKey = last.key;\n        } else {\n          child.prevKey = null;\n        }\n\n        visit(child);\n        last = child;\n      }\n\n      if (last) {\n        last.nextKey = null;\n      }\n\n      // Remove deleted nodes and their children from the key map\n      if (prevNode) {\n        for (let child of prevNode.childNodes) {\n          if (!childKeys.has(child.key)) {\n            remove(child);\n          }\n        }\n      }\n    };\n\n    let remove = (node: GridNode<T>) => {\n      this.keyMap.delete(node.key);\n      for (let child of node.childNodes) {\n        if (this.keyMap.get(child.key) === child) {\n          remove(child);\n        }\n      }\n    };\n\n    let last: GridNode<T> | null = null;\n    for (let [i, node] of opts.items.entries()) {\n      let rowNode: GridNode<T> = {\n        ...node,\n        level: node.level ?? 0,\n        key: node.key ?? 'row-' + i,\n        type: node.type ?? 'row',\n        value: node.value ?? null,\n        hasChildNodes: true,\n        childNodes: [...node.childNodes],\n        rendered: node.rendered,\n        textValue: node.textValue ?? '',\n        index: node.index ?? i\n      };\n\n      if (last) {\n        last.nextKey = rowNode.key;\n        rowNode.prevKey = last.key;\n      } else {\n        rowNode.prevKey = null;\n      }\n\n      this.rows.push(rowNode);\n      visit(rowNode);\n\n      last = rowNode;\n    }\n\n    if (last) {\n      last.nextKey = null;\n    }\n  }\n\n  *[Symbol.iterator](): IterableIterator<GridNode<T>> {\n    yield* [...this.rows];\n  }\n\n  get size(): number {\n    return [...this.rows].length;\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.rows][0]?.key;\n  }\n\n  getLastKey(): Key | null {\n    let rows = [...this.rows];\n    return rows[rows.length - 1]?.key;\n  }\n\n  getItem(key: Key): GridNode<T> | null {\n    return this.keyMap.get(key) ?? null;\n  }\n\n  at(idx: number): GridNode<T> | null {\n    const keys = [...this.getKeys()];\n    return this.getItem(keys[idx]);\n  }\n\n  getChildren(key: Key): Iterable<GridNode<T>> {\n    let node = this.keyMap.get(key);\n    return node?.childNodes || [];\n  }\n}\n"],"names":[],"version":3,"file":"GridCollection.cjs.map"}