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;gBACH,aAAa,IAAI,CAAC;gBAClB;QACJ;QAEA,KAAK,IAAI,SAAS,KAAK,UAAU,CAC/B,MAAM;IAEV;IAEA,KAAK,IAAI,QAAQ,MAAO;QACtB,IAAI,KAAK,IAAI,KAAK,UAChB,gBAAgB,IAAI,CAAC;QAEvB,MAAM;IACR;IAEA,mKAAmK;IACnK,IAAI,YAAY,CAAC;QACf,IAAI,KAAK,IAAI,KAAK,QAChB,cAAc,IAAI,CAAC;QAGrB,OAAO,GAAG,CAAC,KAAK,GAAG,EAAE;QAErB,KAAK,IAAI,SAAS,KAAK,UAAU,CAC/B,IAAI,CAAE,CAAA,MAAM,IAAI,KAAK,UAAU,iBAAiB,SAAS,CAAC,aAAa,GAAG,CAAC,KAAK,GAAG,CAAA;YACjF,IAAI,MAAM,IAAI,KAAK,QACjB,UAAU;iBAEV,0EAA0E;YAC1E,UAAU;;IAIlB;IAEA,KAAK,IAAI,QAAQ,aACf,UAAU;IAGZ,OAAO;gBACL;yBACA;uBACA;QACA,YAAY;eAAI;YAAiB;gBAAC,GAAG,IAAI;gBAAG,YAAY;YAAa;SAAE;IACzE;AACF","sources":["packages/react-stately/src/table/useTreeGridState.ts"],"sourcesContent":["/*\n * Copyright 2023 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 {CollectionBuilder} from '../collections/CollectionBuilder';\nimport {GridNode} from '../grid/GridCollection';\nimport {Key} from '@react-types/shared';\nimport {ReactElement, useMemo} from 'react';\nimport {TableCollection} from './TableCollection';\nimport {tableNestedRows} from '../flags/flags';\nimport {TableState, TableStateProps, useTableState} from './useTableState';\nimport {useControlledState} from '../utils/useControlledState';\n\nexport interface TreeGridState<T> extends Omit<TableState<T>, 'expandedKeys'> {\n /** A set of keys for items that are expanded. */\n expandedKeys: 'all' | Set<Key>;\n /** Toggles the expanded state for a row by its key. */\n toggleKey(key: Key): void;\n /** The key map containing nodes representing the collection's tree grid structure. */\n keyMap: Map<Key, GridNode<T>>;\n /** The number of leaf columns provided by the user. */\n userColumnCount: number;\n}\n\nexport interface TreeGridStateProps<T> extends Omit<TableStateProps<T>, 'collection'> {\n /** The currently expanded keys in the collection (controlled). */\n UNSTABLE_expandedKeys?: 'all' | Iterable<Key>;\n /** The initial expanded keys in the collection (uncontrolled). */\n UNSTABLE_defaultExpandedKeys?: 'all' | Iterable<Key>;\n /** Handler that is called when items are expanded or collapsed. */\n UNSTABLE_onExpandedChange?: (keys: Set<Key>) => any;\n}\n\n/**\n * Provides state management for a tree grid component. Handles building a collection of columns and\n * rows from props. In addition, it tracks and manages expanded rows, row selection, and sort order\n * changes.\n */\nexport function UNSTABLE_useTreeGridState<T extends object>(\n props: TreeGridStateProps<T>\n): TreeGridState<T> {\n let {\n selectionMode = 'none',\n showSelectionCheckboxes,\n showDragButtons,\n UNSTABLE_expandedKeys: propExpandedKeys,\n UNSTABLE_defaultExpandedKeys: propDefaultExpandedKeys,\n UNSTABLE_onExpandedChange,\n children\n } = props;\n\n if (!tableNestedRows()) {\n throw new Error('Feature flag for table nested rows must be enabled to use useTreeGridState.');\n }\n\n let [expandedKeys, setExpandedKeys] = useControlledState(\n propExpandedKeys ? convertExpanded(propExpandedKeys) : undefined,\n propDefaultExpandedKeys ? convertExpanded(propDefaultExpandedKeys) : new Set(),\n UNSTABLE_onExpandedChange\n );\n\n let context = useMemo(\n () => ({\n showSelectionCheckboxes: showSelectionCheckboxes && selectionMode !== 'none',\n showDragButtons: showDragButtons,\n selectionMode,\n columns: []\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [children, showSelectionCheckboxes, selectionMode, showDragButtons]\n );\n\n let builder = useMemo(() => new CollectionBuilder<T>(), []);\n let nodes = useMemo(\n () => builder.build({children: children as ReactElement<any>[]}, context),\n [builder, children, context]\n );\n let treeGridCollection = useMemo(() => {\n return generateTreeGridCollection<T>(nodes, {\n showSelectionCheckboxes,\n showDragButtons,\n expandedKeys\n });\n }, [nodes, showSelectionCheckboxes, showDragButtons, expandedKeys]);\n\n let onToggle = (key: Key) => {\n setExpandedKeys(toggleKey(expandedKeys, key, treeGridCollection));\n };\n\n let collection = useMemo(() => {\n return new TableCollection(treeGridCollection.tableNodes, null, context);\n }, [context, treeGridCollection.tableNodes]);\n\n let tableState = useTableState({...props, collection});\n return {\n ...tableState,\n keyMap: treeGridCollection.keyMap,\n userColumnCount: treeGridCollection.userColumnCount,\n expandedKeys,\n toggleKey: onToggle,\n treeColumn: tableState.treeColumn ?? collection.rowHeaderColumnKeys.keys().next().value ?? null\n };\n}\n\nfunction toggleKey<T>(\n currentExpandedKeys: 'all' | Set<Key>,\n key: Key,\n collection: TreeGridCollection<T>\n): Set<Key> {\n let updatedExpandedKeys: Set<Key>;\n if (currentExpandedKeys === 'all') {\n updatedExpandedKeys = new Set(\n collection.flattenedRows\n .filter(\n row =>\n row.props.UNSTABLE_childItems || row.props.children.length > collection.userColumnCount\n )\n .map(row => row.key)\n );\n updatedExpandedKeys.delete(key);\n } else {\n updatedExpandedKeys = new Set(currentExpandedKeys);\n if (updatedExpandedKeys.has(key)) {\n updatedExpandedKeys.delete(key);\n } else {\n updatedExpandedKeys.add(key);\n }\n }\n\n return updatedExpandedKeys;\n}\n\nfunction convertExpanded(expanded: 'all' | Iterable<Key>): 'all' | Set<Key> {\n if (!expanded) {\n return new Set<Key>();\n }\n\n return expanded === 'all' ? 'all' : new Set(expanded);\n}\n\ninterface TreeGridCollectionOptions {\n showSelectionCheckboxes?: boolean;\n showDragButtons?: boolean;\n expandedKeys: 'all' | Set<Key>;\n}\n\ninterface TreeGridCollection<T> {\n keyMap: Map<Key, GridNode<T>>;\n tableNodes: GridNode<T>[];\n flattenedRows: GridNode<T>[];\n userColumnCount: number;\n}\nfunction generateTreeGridCollection<T>(\n nodes,\n opts: TreeGridCollectionOptions\n): TreeGridCollection<T> {\n let {expandedKeys = new Set()} = opts;\n\n let body: GridNode<T> | null = null;\n let flattenedRows: GridNode<T>[] = [];\n let userColumnCount = 0;\n let originalColumns: GridNode<T>[] = [];\n let keyMap = new Map();\n\n let topLevelRows: GridNode<T>[] = [];\n let visit = (node: GridNode<T>) => {\n switch (node.type) {\n case 'body':\n body = node;\n keyMap.set(body.key, body);\n break;\n case 'column':\n if (!node.hasChildNodes) {\n userColumnCount++;\n }\n break;\n case 'item':\n topLevelRows.push(node);\n return;\n }\n\n for (let child of node.childNodes) {\n visit(child);\n }\n };\n\n for (let node of nodes) {\n if (node.type === 'column') {\n originalColumns.push(node);\n }\n visit(node);\n }\n\n // Update each grid node in the treegrid table with values specific to a treegrid structure. Also store a set of flattened row nodes for TableCollection to consume\n let visitNode = (node: GridNode<T>) => {\n if (node.type === 'item') {\n flattenedRows.push(node);\n }\n\n keyMap.set(node.key, node);\n\n for (let child of node.childNodes) {\n if (!(child.type === 'item' && expandedKeys !== 'all' && !expandedKeys.has(node.key))) {\n if (child.type === 'item') {\n visitNode(child);\n } else {\n // We enforce that the cells come before rows so can just reuse cell index\n visitNode(child);\n }\n }\n }\n };\n\n for (let node of topLevelRows) {\n visitNode(node as GridNode<T>);\n }\n\n return {\n keyMap,\n userColumnCount,\n flattenedRows,\n tableNodes: [...originalColumns, {...body!, childNodes: flattenedRows}]\n };\n}\n"],"names":[],"version":3,"file":"useTreeGridState.cjs.map"}