react-stately 3.49.0 → 3.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/exports/useTokenFieldState.cjs.map +1 -1
- package/dist/exports/useTokenFieldState.js.map +1 -1
- package/dist/exports/useTokenFieldState.mjs.map +1 -1
- package/dist/private/calendar/useCalendarState.cjs +2 -1
- package/dist/private/calendar/useCalendarState.cjs.map +1 -1
- package/dist/private/calendar/useCalendarState.js +3 -2
- package/dist/private/calendar/useCalendarState.js.map +1 -1
- package/dist/private/calendar/useCalendarState.mjs +3 -2
- package/dist/private/calendar/useCalendarState.mjs.map +1 -1
- package/dist/private/color/Color.cjs +5 -3
- package/dist/private/color/Color.cjs.map +1 -1
- package/dist/private/color/Color.js +5 -3
- package/dist/private/color/Color.js.map +1 -1
- package/dist/private/color/Color.mjs +5 -3
- package/dist/private/color/Color.mjs.map +1 -1
- package/dist/private/combobox/useComboBoxState.cjs +15 -1
- package/dist/private/combobox/useComboBoxState.cjs.map +1 -1
- package/dist/private/combobox/useComboBoxState.js +16 -2
- package/dist/private/combobox/useComboBoxState.js.map +1 -1
- package/dist/private/combobox/useComboBoxState.mjs +16 -2
- package/dist/private/combobox/useComboBoxState.mjs.map +1 -1
- package/dist/private/data/useTreeData.cjs +7 -2
- package/dist/private/data/useTreeData.cjs.map +1 -1
- package/dist/private/data/useTreeData.js +9 -2
- package/dist/private/data/useTreeData.js.map +1 -1
- package/dist/private/data/useTreeData.mjs +7 -2
- package/dist/private/data/useTreeData.mjs.map +1 -1
- package/dist/private/layout/ListLayout.cjs +4 -0
- package/dist/private/layout/ListLayout.cjs.map +1 -1
- package/dist/private/layout/ListLayout.js +4 -0
- package/dist/private/layout/ListLayout.js.map +1 -1
- package/dist/private/layout/ListLayout.mjs +4 -0
- package/dist/private/layout/ListLayout.mjs.map +1 -1
- package/dist/private/tokenfield/TokenFieldValue.cjs +45 -15
- package/dist/private/tokenfield/TokenFieldValue.cjs.map +1 -1
- package/dist/private/tokenfield/TokenFieldValue.js +45 -17
- package/dist/private/tokenfield/TokenFieldValue.js.map +1 -1
- package/dist/private/tokenfield/TokenFieldValue.mjs +46 -16
- package/dist/private/tokenfield/TokenFieldValue.mjs.map +1 -1
- package/dist/private/tooltip/useTooltipTriggerState.cjs.map +1 -1
- package/dist/private/tooltip/useTooltipTriggerState.js.map +1 -1
- package/dist/private/tooltip/useTooltipTriggerState.mjs.map +1 -1
- package/dist/private/utils/useControlledState.cjs +1 -1
- package/dist/private/utils/useControlledState.cjs.map +1 -1
- package/dist/private/utils/useControlledState.js +1 -1
- package/dist/private/utils/useControlledState.js.map +1 -1
- package/dist/private/utils/useControlledState.mjs +1 -1
- package/dist/private/utils/useControlledState.mjs.map +1 -1
- package/dist/types/exports/useTokenFieldState.d.ts +1 -1
- package/dist/types/src/collections/Item.d.ts +1 -6
- package/dist/types/src/collections/Section.d.ts +1 -6
- package/dist/types/src/table/Cell.d.ts +0 -5
- package/dist/types/src/table/Column.d.ts +0 -7
- package/dist/types/src/table/Row.d.ts +0 -6
- package/dist/types/src/table/TableBody.d.ts +1 -6
- package/dist/types/src/table/TableHeader.d.ts +1 -7
- package/dist/types/src/tokenfield/TokenFieldValue.d.ts +27 -4
- package/dist/types/src/tooltip/useTooltipTriggerState.d.ts +2 -2
- package/package.json +6 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;AAAA;;;;;;;;;;CAUC;AA6IM,SAAS,0CAA8B,OAAuB;IACnE,IAAI,gBACF,eAAe,EAAE,uBACjB,mBAAmB,UACnB,SAAS,CAAC;YAAc;eAAA,CAAA,WAAA,KAAK,EAAE,cAAP,sBAAA,WAAW,KAAK,GAAG;oBAC3C,cAAc,CAAC,OAAc,KAAK,QAAQ,EAC3C,GAAG;IAEJ,kDAAkD;IAClD,IAAI,CAAC,MAAM,SAAS,GAAG,CAAA,GAAA,eAAO,EAAoB,IAAM,UAAU,cAAc,IAAI;IACpF,IAAI,SAAC,KAAK,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K;YACvB,UAAU;mBACL,WAAW,QAAQ,CAAE,KAAK,CAAC,GAAG;mBAC9B;mBACA,WAAW,QAAQ,CAAE,KAAK,CAAC;aAC/B;QACH,CAAA,GACA;AAEJ","sources":["packages/react-stately/src/data/useTreeData.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 {Key} from '@react-types/shared';\nimport {useState} from 'react';\n\nexport interface TreeOptions<T extends object> {\n /** Initial root items in the tree. */\n initialItems?: T[];\n /** The keys for the initially selected items. */\n initialSelectedKeys?: Iterable<Key>;\n /** A function that returns a unique key for an item object. */\n getKey?: (item: T) => Key;\n /** A function that returns the children for an item object. */\n getChildren?: (item: T) => T[];\n}\n\ninterface TreeNode<T extends object> {\n /** A unique key for the tree node. */\n key: Key;\n /** The key of the parent node. */\n parentKey?: Key | null;\n /** The value object for the tree node. */\n value: T;\n /** Children of the tree node. */\n children: TreeNode<T>[] | null;\n}\n\nexport interface TreeData<T extends object> {\n /** The root nodes in the tree. */\n items: TreeNode<T>[];\n\n /** The keys of the currently selected items in the tree. */\n selectedKeys: Set<Key>;\n\n /** Sets the selected keys. */\n setSelectedKeys(keys: Set<Key>): void;\n\n /**\n * Gets a node from the tree by key.\n *\n * @param key - The key of the item to retrieve.\n */\n getItem(key: Key): TreeNode<T> | undefined;\n\n /**\n * Inserts an item into a parent node as a child.\n *\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param index - The index within the parent to insert into.\n * @param value - The value to insert.\n */\n insert(parentKey: Key | null, index: number, ...values: T[]): void;\n\n /**\n * Inserts items into the list before the item at the given key.\n *\n * @param key - The key of the item to insert before.\n * @param values - The values to insert.\n */\n insertBefore(key: Key, ...values: T[]): void;\n\n /**\n * Inserts items into the list after the item at the given key.\n *\n * @param key - The key of the item to insert after.\n * @param values - The values to insert.\n */\n insertAfter(key: Key, ...values: T[]): void;\n\n /**\n * Appends an item into a parent node as a child.\n *\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param value - The value to insert.\n */\n append(parentKey: Key | null, ...values: T[]): void;\n\n /**\n * Prepends an item into a parent node as a child.\n *\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param value - The value to insert.\n */\n prepend(parentKey: Key | null, ...value: T[]): void;\n\n /**\n * Removes an item from the tree by its key.\n *\n * @param key - The key of the item to remove.\n */\n remove(...keys: Key[]): void;\n\n /**\n * Removes all items from the tree that are currently\n * in the set of selected items.\n */\n removeSelectedItems(): void;\n\n /**\n * Moves an item within the tree.\n *\n * @param key - The key of the item to move.\n * @param toParentKey - The key of the new parent to insert into. `null` for the root.\n * @param index - The index within the new parent to insert at.\n */\n move(key: Key, toParentKey: Key | null, index: number): void;\n\n /**\n * Moves one or more items before a given key.\n *\n * @param key - The key of the item to move the items before.\n * @param keys - The keys of the items to move.\n */\n moveBefore(key: Key, keys: Iterable<Key>): void;\n\n /**\n * Moves one or more items after a given key.\n *\n * @param key - The key of the item to move the items after.\n * @param keys - The keys of the items to move.\n */\n moveAfter(key: Key, keys: Iterable<Key>): void;\n\n /**\n * Updates an item in the tree.\n *\n * @param key - The key of the item to update.\n * @param newValue - The new value for the item.\n */\n update(key: Key, newValue: T): void;\n}\n\ninterface TreeDataState<T extends object> {\n items: TreeNode<T>[];\n nodeMap: Map<Key, TreeNode<T>>;\n}\n\n/**\n * Manages state for an immutable tree data structure, and provides convenience methods to\n * update the data over time.\n */\nexport function useTreeData<T extends object>(options: TreeOptions<T>): TreeData<T> {\n let {\n initialItems = [],\n initialSelectedKeys,\n getKey = (item: any) => item.id ?? item.key,\n getChildren = (item: any) => item.children\n } = options;\n\n // We only want to compute this on initial render.\n let [tree, setItems] = useState<TreeDataState<T>>(() => buildTree(initialItems, new Map()));\n let {items, nodeMap} = tree;\n\n let [selectedKeys, setSelectedKeys] = useState(new Set<Key>(initialSelectedKeys || []));\n\n // oxlint-disable-next-line react/react-compiler\n function buildTree(\n initialItems: T[] | null = [],\n map: Map<Key, TreeNode<T>>,\n parentKey?: Key | null\n ) {\n if (initialItems == null) {\n initialItems = [];\n }\n return {\n items: initialItems.map(item => {\n let node: TreeNode<T> = {\n key: getKey(item),\n parentKey: parentKey ?? null,\n value: item,\n children: null\n };\n\n node.children = buildTree(getChildren(item), map, node.key).items;\n map.set(node.key, node);\n return node;\n }),\n nodeMap: map\n };\n }\n\n function updateTree(\n items: TreeNode<T>[],\n key: Key | null,\n update: (node: TreeNode<T>) => TreeNode<T> | null,\n originalMap: Map<Key, TreeNode<T>>\n ) {\n let node = key == null ? null : originalMap.get(key);\n if (node == null) {\n return {items, nodeMap: originalMap};\n }\n let map = new Map<Key, TreeNode<T>>(originalMap);\n\n // Create a new node. If null, then delete the node, otherwise replace.\n let newNode = update(node);\n if (newNode == null) {\n deleteNode(node, map);\n } else {\n addNode(newNode, map);\n }\n\n // Walk up the tree and update each parent to refer to the new children.\n while (node && node.parentKey) {\n let nextParent = map.get(node.parentKey)!;\n let copy: TreeNode<T> = {\n key: nextParent.key,\n parentKey: nextParent.parentKey,\n value: nextParent.value,\n children: null\n };\n\n let children = nextParent.children;\n if (newNode == null && children) {\n children = children.filter(c => c !== node);\n }\n\n copy.children =\n children?.map(child => {\n if (child === node) {\n // newNode cannot be null here due to the above filter.\n return newNode!;\n }\n\n return child;\n }) ?? null;\n\n map.set(copy.key, copy);\n\n newNode = copy;\n node = nextParent;\n }\n\n if (newNode == null) {\n items = items.filter(c => c !== node);\n }\n\n return {\n items: items.map(item => {\n if (item === node) {\n // newNode cannot be null here due to the above filter.\n return newNode!;\n }\n\n return item;\n }),\n nodeMap: map\n };\n }\n\n function addNode(node: TreeNode<T>, map: Map<Key, TreeNode<T>>) {\n map.set(node.key, node);\n if (node.children) {\n for (let child of node.children) {\n addNode(child, map);\n }\n }\n }\n\n function deleteNode(node: TreeNode<T>, map: Map<Key, TreeNode<T>>) {\n map.delete(node.key);\n if (node.children) {\n for (let child of node.children) {\n deleteNode(child, map);\n }\n }\n }\n return {\n items,\n selectedKeys,\n setSelectedKeys,\n getItem(key: Key) {\n return nodeMap.get(key);\n },\n insert(parentKey: Key | null, index: number, ...values: T[]) {\n setItems(({items, nodeMap: originalMap}) => {\n let {items: newNodes, nodeMap: newMap} = buildTree(values, new Map(originalMap), parentKey);\n\n // If parentKey is null, insert into the root.\n if (parentKey == null) {\n return {\n items: [...items.slice(0, index), ...newNodes, ...items.slice(index)],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(\n items,\n parentKey,\n parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, index),\n ...newNodes,\n ...parentNode.children!.slice(index)\n ]\n }),\n newMap\n );\n });\n },\n insertBefore(key: Key, ...values: T[]): void {\n let node = nodeMap.get(key);\n if (!node) {\n return;\n }\n\n let parentNode = nodeMap.get(node.parentKey!);\n let nodes = parentNode ? parentNode.children : items;\n let index = nodes!.indexOf(node);\n this.insert(parentNode?.key ?? null, index, ...values);\n },\n insertAfter(key: Key, ...values: T[]): void {\n let node = nodeMap.get(key);\n if (!node) {\n return;\n }\n\n let parentNode = nodeMap.get(node.parentKey!);\n let nodes = parentNode ? parentNode.children : items;\n let index = nodes!.indexOf(node);\n this.insert(parentNode?.key ?? null, index + 1, ...values);\n },\n prepend(parentKey: Key | null, ...values: T[]) {\n this.insert(parentKey, 0, ...values);\n },\n append(parentKey: Key | null, ...values: T[]) {\n if (parentKey == null) {\n this.insert(null, items.length, ...values);\n } else {\n let parentNode = nodeMap.get(parentKey);\n if (!parentNode) {\n return;\n }\n\n this.insert(parentKey, parentNode.children!.length, ...values);\n }\n },\n remove(...keys: Key[]) {\n if (keys.length === 0) {\n return;\n }\n\n let newItems = items;\n let prevMap = nodeMap;\n let newTree;\n for (let key of keys) {\n newTree = updateTree(newItems, key, () => null, prevMap);\n prevMap = newTree.nodeMap;\n newItems = newTree.items;\n }\n\n setItems(newTree);\n\n let selection = new Set(selectedKeys);\n for (let key of selectedKeys) {\n if (!newTree.nodeMap.has(key)) {\n selection.delete(key);\n }\n }\n\n setSelectedKeys(selection);\n },\n removeSelectedItems() {\n this.remove(...selectedKeys);\n },\n move(key: Key, toParentKey: Key | null, index: number) {\n setItems(({items, nodeMap: originalMap}) => {\n let node = originalMap.get(key);\n if (!node) {\n return {items, nodeMap: originalMap};\n }\n\n let {items: newItems, nodeMap: newMap} = updateTree(items, key, () => null, originalMap);\n\n const movedNode = {\n ...node,\n parentKey: toParentKey\n };\n\n // If parentKey is null, insert into the root.\n if (toParentKey == null) {\n addNode(movedNode, newMap);\n return {\n items: [...newItems.slice(0, index), movedNode, ...newItems.slice(index)],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(\n newItems,\n toParentKey,\n parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, index),\n movedNode,\n ...parentNode.children!.slice(index)\n ]\n }),\n newMap\n );\n });\n },\n moveBefore(key: Key, keys: Iterable<Key>) {\n setItems(prevState => {\n let {items, nodeMap} = prevState;\n let node = nodeMap.get(key);\n if (!node) {\n return prevState;\n }\n let toParentKey = node.parentKey ?? null;\n let parent: null | TreeNode<T> = null;\n if (toParentKey != null) {\n parent = nodeMap.get(toParentKey) ?? null;\n }\n let toIndex = parent?.children ? parent.children.indexOf(node) : items.indexOf(node);\n return moveItems(prevState, keys, parent, toIndex, updateTree, addNode);\n });\n },\n moveAfter(key: Key, keys: Iterable<Key>) {\n setItems(prevState => {\n let {items, nodeMap} = prevState;\n let node = nodeMap.get(key);\n if (!node) {\n return prevState;\n }\n let toParentKey = node.parentKey ?? null;\n let parent: null | TreeNode<T> = null;\n if (toParentKey != null) {\n parent = nodeMap.get(toParentKey) ?? null;\n }\n let toIndex = parent?.children ? parent.children.indexOf(node) : items.indexOf(node);\n toIndex++;\n return moveItems(prevState, keys, parent, toIndex, updateTree, addNode);\n });\n },\n update(oldKey: Key, newValue: T) {\n setItems(({items, nodeMap: originalMap}) =>\n updateTree(\n items,\n oldKey,\n oldNode => {\n let node: TreeNode<T> = {\n key: oldNode.key,\n parentKey: oldNode.parentKey,\n value: newValue,\n children: null\n };\n\n let tree = buildTree(getChildren(newValue), originalMap, node.key);\n node.children = tree.items;\n return node;\n },\n originalMap\n )\n );\n }\n };\n}\n\nfunction moveItems<T extends object>(\n state: TreeDataState<T>,\n keys: Iterable<Key>,\n toParent: TreeNode<T> | null,\n toIndex: number,\n updateTree: (\n items: TreeNode<T>[],\n key: Key | null,\n update: (node: TreeNode<T>) => TreeNode<T> | null,\n originalMap: Map<Key, TreeNode<T>>\n ) => TreeDataState<T>,\n addNode: (node: TreeNode<T>, map: Map<Key, TreeNode<T>>) => void\n): TreeDataState<T> {\n let {items, nodeMap} = state;\n\n let parent = toParent;\n let removeKeys = new Set(keys);\n while (parent?.parentKey != null) {\n if (removeKeys.has(parent.key)) {\n throw new Error('Cannot move an item to be a child of itself.');\n }\n parent = nodeMap.get(parent.parentKey!) ?? null;\n }\n\n let originalToIndex = toIndex;\n\n let keyArray = Array.isArray(keys) ? keys : [...keys];\n // depth first search to put keys in order\n let inOrderKeys: Map<Key, number> = new Map();\n let removedItems: Array<TreeNode<T>> = [];\n let newItems = items;\n let newMap = nodeMap;\n let i = 0;\n\n function traversal(node, {inorder, postorder}) {\n inorder?.(node);\n if (node != null) {\n for (let child of node.children ?? []) {\n traversal(child, {inorder, postorder});\n postorder?.(child);\n }\n }\n }\n\n function inorder(child) {\n // in-order so we add items as we encounter them in the tree, then we can insert them in expected order later\n if (keyArray.includes(child.key)) {\n inOrderKeys.set(child.key, i++);\n }\n }\n\n function postorder(child) {\n // remove items and update the tree from the leaves and work upwards toward the root, this way\n // we don't copy child node references from parents inadvertently\n if (keyArray.includes(child.key)) {\n removedItems.push({...newMap.get(child.key)!, parentKey: toParent?.key ?? null});\n let {items: nextItems, nodeMap: nextMap} = updateTree(\n newItems,\n child.key,\n () => null,\n newMap\n );\n newItems = nextItems;\n newMap = nextMap;\n }\n // decrement the index if the child being removed is in the target parent and before the target index\n // the root node is special, it is null, and will not have a key, however, a parentKey can still point to it\n if (\n (child.parentKey === toParent || child.parentKey === toParent?.key) &&\n keyArray.includes(child.key) &&\n (toParent?.children ? toParent.children.indexOf(child) : items.indexOf(child)) <\n originalToIndex\n ) {\n toIndex--;\n }\n }\n\n traversal({children: items}, {inorder, postorder});\n\n let inOrderItems = removedItems.sort((a, b) =>\n inOrderKeys.get(a.key)! > inOrderKeys.get(b.key)! ? 1 : -1\n );\n // If parentKey is null, insert into the root.\n if (!toParent || toParent.key == null) {\n inOrderItems.forEach(movedNode => {\n addNode(movedNode, newMap);\n });\n return {\n items: [...newItems.slice(0, toIndex), ...inOrderItems, ...newItems.slice(toIndex)],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(\n newItems,\n toParent.key,\n parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, toIndex),\n ...inOrderItems,\n ...parentNode.children!.slice(toIndex)\n ]\n }),\n newMap\n );\n}\n"],"names":[],"version":3,"file":"useTreeData.js.map"}
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;CAUC;AA6IM,SAAS,0CAA8B,OAAuB;IACnE,IAAI,gBACF,eAAe,EAAE,uBACjB,mBAAmB,UACnB,SAAS,CAAC;YAAc;eAAA,CAAA,WAAA,KAAK,EAAE,cAAP,sBAAA,WAAW,KAAK,GAAG;oBAC3C,cAAc,CAAC,OAAc,KAAK,QAAQ,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I,CAAC,YAAY,SAAS,GAAG,IAAI,MAAM;QACrC,aAAa,OAAO,CAAC,CAAA;YACnB,QAAQ,WAAW;QACrB;QACA,OAAO;YACL,OAAO;mBAAI,SAAS,KAAK,CAAC,GAAG;mBAAa;mBAAiB,SAAS,KAAK,CAAC;aAAS;YACnF,SAAS;QACX;IACF;IAEA,uDAAuD;IACvD,OAAO,WACL,UACA,SAAS,GAAG,EACZ,CAAA,aAAe,CAAA;YACb,KAAK,WAAW,GAAG;YACnB,WAAW,WAAW,SAAS;YAC/B,OAAO,WAAW,KAAK;YACvB,UAAU;mBACL,WAAW,QAAQ,CAAE,KAAK,CAAC,GAAG;mBAC9B;mBACA,WAAW,QAAQ,CAAE,KAAK,CAAC;aAC/B;QACH,CAAA,GACA;AAEJ","sources":["packages/react-stately/src/data/useTreeData.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 {Key} from '@react-types/shared';\nimport {useState} from 'react';\n\nexport interface TreeOptions<T extends object> {\n /** Initial root items in the tree. */\n initialItems?: T[];\n /** The keys for the initially selected items. */\n initialSelectedKeys?: Iterable<Key>;\n /** A function that returns a unique key for an item object. */\n getKey?: (item: T) => Key;\n /** A function that returns the children for an item object. */\n getChildren?: (item: T) => T[];\n}\n\ninterface TreeNode<T extends object> {\n /** A unique key for the tree node. */\n key: Key;\n /** The key of the parent node. */\n parentKey?: Key | null;\n /** The value object for the tree node. */\n value: T;\n /** Children of the tree node. */\n children: TreeNode<T>[] | null;\n}\n\nexport interface TreeData<T extends object> {\n /** The root nodes in the tree. */\n items: TreeNode<T>[];\n\n /** The keys of the currently selected items in the tree. */\n selectedKeys: Set<Key>;\n\n /** Sets the selected keys. */\n setSelectedKeys(keys: Set<Key>): void;\n\n /**\n * Gets a node from the tree by key.\n *\n * @param key - The key of the item to retrieve.\n */\n getItem(key: Key): TreeNode<T> | undefined;\n\n /**\n * Inserts an item into a parent node as a child.\n *\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param index - The index within the parent to insert into.\n * @param value - The value to insert.\n */\n insert(parentKey: Key | null, index: number, ...values: T[]): void;\n\n /**\n * Inserts items into the list before the item at the given key.\n *\n * @param key - The key of the item to insert before.\n * @param values - The values to insert.\n */\n insertBefore(key: Key, ...values: T[]): void;\n\n /**\n * Inserts items into the list after the item at the given key.\n *\n * @param key - The key of the item to insert after.\n * @param values - The values to insert.\n */\n insertAfter(key: Key, ...values: T[]): void;\n\n /**\n * Appends an item into a parent node as a child.\n *\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param value - The value to insert.\n */\n append(parentKey: Key | null, ...values: T[]): void;\n\n /**\n * Prepends an item into a parent node as a child.\n *\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param value - The value to insert.\n */\n prepend(parentKey: Key | null, ...value: T[]): void;\n\n /**\n * Removes an item from the tree by its key.\n *\n * @param key - The key of the item to remove.\n */\n remove(...keys: Key[]): void;\n\n /**\n * Removes all items from the tree that are currently\n * in the set of selected items.\n */\n removeSelectedItems(): void;\n\n /**\n * Moves an item within the tree.\n *\n * @param key - The key of the item to move.\n * @param toParentKey - The key of the new parent to insert into. `null` for the root.\n * @param index - The index within the new parent to insert at.\n */\n move(key: Key, toParentKey: Key | null, index: number): void;\n\n /**\n * Moves one or more items before a given key.\n *\n * @param key - The key of the item to move the items before.\n * @param keys - The keys of the items to move.\n */\n moveBefore(key: Key, keys: Iterable<Key>): void;\n\n /**\n * Moves one or more items after a given key.\n *\n * @param key - The key of the item to move the items after.\n * @param keys - The keys of the items to move.\n */\n moveAfter(key: Key, keys: Iterable<Key>): void;\n\n /**\n * Updates an item in the tree.\n *\n * @param key - The key of the item to update.\n * @param newValue - The new value for the item.\n */\n update(key: Key, newValue: T): void;\n}\n\ninterface TreeDataState<T extends object> {\n items: TreeNode<T>[];\n nodeMap: Map<Key, TreeNode<T>>;\n}\n\n/**\n * Manages state for an immutable tree data structure, and provides convenience methods to\n * update the data over time.\n */\nexport function useTreeData<T extends object>(options: TreeOptions<T>): TreeData<T> {\n let {\n initialItems = [],\n initialSelectedKeys,\n getKey = (item: any) => item.id ?? item.key,\n getChildren = (item: any) => item.children\n } = options;\n\n // We only want to compute this on initial render.\n let [tree, setItems] = useState<TreeDataState<T>>(() => buildTree(initialItems, new Map()));\n let {items, nodeMap} = tree;\n\n let [selectedKeys, setSelectedKeys] = useState(new Set<Key>(initialSelectedKeys || []));\n\n // oxlint-disable-next-line react/react-compiler\n function buildTree(\n initialItems: T[] | null = [],\n map: Map<Key, TreeNode<T>>,\n parentKey?: Key | null\n ) {\n if (initialItems == null) {\n initialItems = [];\n }\n return {\n items: initialItems.map(item => {\n let node: TreeNode<T> = {\n key: getKey(item),\n parentKey: parentKey ?? null,\n value: item,\n children: null\n };\n\n node.children = buildTree(getChildren(item), map, node.key).items;\n map.set(node.key, node);\n return node;\n }),\n nodeMap: map\n };\n }\n\n function updateTree(\n items: TreeNode<T>[],\n key: Key | null,\n update: (node: TreeNode<T>) => TreeNode<T> | null,\n originalMap: Map<Key, TreeNode<T>>\n ) {\n let node = key == null ? null : originalMap.get(key);\n if (node == null) {\n return {items, nodeMap: originalMap};\n }\n let map = new Map<Key, TreeNode<T>>(originalMap);\n\n // Create a new node. If null, then delete the node, otherwise replace.\n let newNode = update(node);\n if (newNode == null) {\n deleteNode(node, map);\n } else {\n addNode(newNode, map);\n }\n\n // Walk up the tree and update each parent to refer to the new children.\n while (node && node.parentKey) {\n let nextParent = map.get(node.parentKey)!;\n let copy: TreeNode<T> = {\n key: nextParent.key,\n parentKey: nextParent.parentKey,\n value: nextParent.value,\n children: null\n };\n\n let children = nextParent.children;\n if (newNode == null && children) {\n children = children.filter(c => c !== node);\n }\n\n copy.children =\n children?.map(child => {\n if (child === node) {\n // newNode cannot be null here due to the above filter.\n return newNode!;\n }\n\n return child;\n }) ?? null;\n\n map.set(copy.key, copy);\n\n newNode = copy;\n node = nextParent;\n }\n\n if (newNode == null) {\n items = items.filter(c => c !== node);\n }\n\n return {\n items: items.map(item => {\n if (item === node) {\n // newNode cannot be null here due to the above filter.\n return newNode!;\n }\n\n return item;\n }),\n nodeMap: map\n };\n }\n\n function addNode(node: TreeNode<T>, map: Map<Key, TreeNode<T>>) {\n map.set(node.key, node);\n if (node.children) {\n for (let child of node.children) {\n addNode(child, map);\n }\n }\n }\n\n function deleteNode(node: TreeNode<T>, map: Map<Key, TreeNode<T>>) {\n map.delete(node.key);\n if (node.children) {\n for (let child of node.children) {\n deleteNode(child, map);\n }\n }\n }\n return {\n items,\n selectedKeys,\n setSelectedKeys,\n getItem(key: Key) {\n return nodeMap.get(key);\n },\n insert(parentKey: Key | null, index: number, ...values: T[]) {\n setItems(({items, nodeMap: originalMap}) => {\n let {items: newNodes, nodeMap: newMap} = buildTree(values, new Map(originalMap), parentKey);\n\n // If parentKey is null, insert into the root.\n if (parentKey == null) {\n return {\n items: [...items.slice(0, index), ...newNodes, ...items.slice(index)],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(\n items,\n parentKey,\n parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, index),\n ...newNodes,\n ...parentNode.children!.slice(index)\n ]\n }),\n newMap\n );\n });\n },\n insertBefore(key: Key, ...values: T[]): void {\n let node = nodeMap.get(key);\n if (!node) {\n return;\n }\n\n let parentNode = nodeMap.get(node.parentKey!);\n let nodes = parentNode ? parentNode.children : items;\n let index = nodes!.indexOf(node);\n this.insert(parentNode?.key ?? null, index, ...values);\n },\n insertAfter(key: Key, ...values: T[]): void {\n let node = nodeMap.get(key);\n if (!node) {\n return;\n }\n\n let parentNode = nodeMap.get(node.parentKey!);\n let nodes = parentNode ? parentNode.children : items;\n let index = nodes!.indexOf(node);\n this.insert(parentNode?.key ?? null, index + 1, ...values);\n },\n prepend(parentKey: Key | null, ...values: T[]) {\n this.insert(parentKey, 0, ...values);\n },\n append(parentKey: Key | null, ...values: T[]) {\n if (parentKey == null) {\n this.insert(null, items.length, ...values);\n } else {\n let parentNode = nodeMap.get(parentKey);\n if (!parentNode) {\n return;\n }\n\n this.insert(parentKey, parentNode.children!.length, ...values);\n }\n },\n remove(...keys: Key[]) {\n if (keys.length === 0) {\n return;\n }\n\n let newItems = items;\n let prevMap = nodeMap;\n let newTree;\n for (let key of keys) {\n newTree = updateTree(newItems, key, () => null, prevMap);\n prevMap = newTree.nodeMap;\n newItems = newTree.items;\n }\n\n setItems(newTree);\n\n let selection = new Set(selectedKeys);\n for (let key of selectedKeys) {\n if (!newTree.nodeMap.has(key)) {\n selection.delete(key);\n }\n }\n\n setSelectedKeys(selection);\n },\n removeSelectedItems() {\n this.remove(...selectedKeys);\n },\n move(key: Key, toParentKey: Key | null, index: number) {\n setItems(({items, nodeMap: originalMap}) => {\n let current = toParentKey;\n while (current != null) {\n if (current === key) {\n throw new Error('Cannot move an item to be a child of itself.');\n }\n current = originalMap.get(current)?.parentKey ?? null;\n }\n\n let node = originalMap.get(key);\n if (!node) {\n return {items, nodeMap: originalMap};\n }\n\n let {items: newItems, nodeMap: newMap} = updateTree(items, key, () => null, originalMap);\n\n const movedNode = {\n ...node,\n parentKey: toParentKey\n };\n\n // If parentKey is null, insert into the root.\n if (toParentKey == null) {\n addNode(movedNode, newMap);\n return {\n items: [...newItems.slice(0, index), movedNode, ...newItems.slice(index)],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(\n newItems,\n toParentKey,\n parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, index),\n movedNode,\n ...parentNode.children!.slice(index)\n ]\n }),\n newMap\n );\n });\n },\n moveBefore(key: Key, keys: Iterable<Key>) {\n setItems(prevState => {\n let {items, nodeMap} = prevState;\n let node = nodeMap.get(key);\n if (!node) {\n return prevState;\n }\n let toParentKey = node.parentKey ?? null;\n let parent: null | TreeNode<T> = null;\n if (toParentKey != null) {\n parent = nodeMap.get(toParentKey) ?? null;\n }\n let toIndex = parent?.children ? parent.children.indexOf(node) : items.indexOf(node);\n return moveItems(prevState, keys, parent, toIndex, updateTree, addNode);\n });\n },\n moveAfter(key: Key, keys: Iterable<Key>) {\n setItems(prevState => {\n let {items, nodeMap} = prevState;\n let node = nodeMap.get(key);\n if (!node) {\n return prevState;\n }\n let toParentKey = node.parentKey ?? null;\n let parent: null | TreeNode<T> = null;\n if (toParentKey != null) {\n parent = nodeMap.get(toParentKey) ?? null;\n }\n let toIndex = parent?.children ? parent.children.indexOf(node) : items.indexOf(node);\n toIndex++;\n return moveItems(prevState, keys, parent, toIndex, updateTree, addNode);\n });\n },\n update(oldKey: Key, newValue: T) {\n setItems(({items, nodeMap: originalMap}) =>\n updateTree(\n items,\n oldKey,\n oldNode => {\n let node: TreeNode<T> = {\n key: oldNode.key,\n parentKey: oldNode.parentKey,\n value: newValue,\n children: null\n };\n\n let tree = buildTree(getChildren(newValue), originalMap, node.key);\n node.children = tree.items;\n return node;\n },\n originalMap\n )\n );\n }\n };\n}\n\nfunction moveItems<T extends object>(\n state: TreeDataState<T>,\n keys: Iterable<Key>,\n toParent: TreeNode<T> | null,\n toIndex: number,\n updateTree: (\n items: TreeNode<T>[],\n key: Key | null,\n update: (node: TreeNode<T>) => TreeNode<T> | null,\n originalMap: Map<Key, TreeNode<T>>\n ) => TreeDataState<T>,\n addNode: (node: TreeNode<T>, map: Map<Key, TreeNode<T>>) => void\n): TreeDataState<T> {\n let {items, nodeMap} = state;\n\n let parent = toParent;\n let removeKeys = new Set(keys);\n while (parent != null) {\n if (removeKeys.has(parent.key)) {\n throw new Error('Cannot move an item to be a child of itself.');\n }\n parent = parent.parentKey != null ? (nodeMap.get(parent.parentKey) ?? null) : null;\n }\n\n let originalToIndex = toIndex;\n\n let keyArray = Array.isArray(keys) ? keys : [...keys];\n // depth first search to put keys in order\n let inOrderKeys: Map<Key, number> = new Map();\n let removedItems: Array<TreeNode<T>> = [];\n let newItems = items;\n let newMap = nodeMap;\n let i = 0;\n\n function traversal(node, {inorder, postorder}) {\n inorder?.(node);\n if (node != null) {\n for (let child of node.children ?? []) {\n traversal(child, {inorder, postorder});\n postorder?.(child);\n }\n }\n }\n\n function inorder(child) {\n // in-order so we add items as we encounter them in the tree, then we can insert them in expected order later\n if (keyArray.includes(child.key)) {\n inOrderKeys.set(child.key, i++);\n }\n }\n\n function postorder(child) {\n // remove items and update the tree from the leaves and work upwards toward the root, this way\n // we don't copy child node references from parents inadvertently\n if (keyArray.includes(child.key)) {\n removedItems.push({...newMap.get(child.key)!, parentKey: toParent?.key ?? null});\n let {items: nextItems, nodeMap: nextMap} = updateTree(\n newItems,\n child.key,\n () => null,\n newMap\n );\n newItems = nextItems;\n newMap = nextMap;\n }\n // decrement the index if the child being removed is in the target parent and before the target index\n // the root node is special, it is null, and will not have a key, however, a parentKey can still point to it\n if (\n (child.parentKey === toParent || child.parentKey === toParent?.key) &&\n keyArray.includes(child.key) &&\n (toParent?.children ? toParent.children.indexOf(child) : items.indexOf(child)) <\n originalToIndex\n ) {\n toIndex--;\n }\n }\n\n traversal({children: items}, {inorder, postorder});\n\n let inOrderItems = removedItems.sort((a, b) =>\n inOrderKeys.get(a.key)! > inOrderKeys.get(b.key)! ? 1 : -1\n );\n // If parentKey is null, insert into the root.\n if (!toParent || toParent.key == null) {\n inOrderItems.forEach(movedNode => {\n addNode(movedNode, newMap);\n });\n return {\n items: [...newItems.slice(0, toIndex), ...inOrderItems, ...newItems.slice(toIndex)],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(\n newItems,\n toParent.key,\n parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, toIndex),\n ...inOrderItems,\n ...parentNode.children!.slice(toIndex)\n ]\n }),\n newMap\n );\n}\n"],"names":[],"version":3,"file":"useTreeData.js.map"}
|
|
@@ -163,6 +163,11 @@ function $48fd4b7af0dd022e$export$d14e1352e21f4a16(options) {
|
|
|
163
163
|
},
|
|
164
164
|
move (key, toParentKey, index) {
|
|
165
165
|
setItems(({ items: items, nodeMap: originalMap })=>{
|
|
166
|
+
let current = toParentKey;
|
|
167
|
+
while(current != null){
|
|
168
|
+
if (current === key) throw new Error('Cannot move an item to be a child of itself.');
|
|
169
|
+
current = originalMap.get(current)?.parentKey ?? null;
|
|
170
|
+
}
|
|
166
171
|
let node = originalMap.get(key);
|
|
167
172
|
if (!node) return {
|
|
168
173
|
items: items,
|
|
@@ -242,9 +247,9 @@ function $48fd4b7af0dd022e$var$moveItems(state, keys, toParent, toIndex, updateT
|
|
|
242
247
|
let { items: items, nodeMap: nodeMap } = state;
|
|
243
248
|
let parent = toParent;
|
|
244
249
|
let removeKeys = new Set(keys);
|
|
245
|
-
while(parent
|
|
250
|
+
while(parent != null){
|
|
246
251
|
if (removeKeys.has(parent.key)) throw new Error('Cannot move an item to be a child of itself.');
|
|
247
|
-
parent = nodeMap.get(parent.parentKey) ?? null;
|
|
252
|
+
parent = parent.parentKey != null ? nodeMap.get(parent.parentKey) ?? null : null;
|
|
248
253
|
}
|
|
249
254
|
let originalToIndex = toIndex;
|
|
250
255
|
let keyArray = Array.isArray(keys) ? keys : [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;AAAA;;;;;;;;;;CAUC;AA6IM,SAAS,0CAA8B,OAAuB;IACnE,IAAI,gBACF,eAAe,EAAE,uBACjB,mBAAmB,UACnB,SAAS,CAAC,OAAc,KAAK,EAAE,IAAI,KAAK,GAAG,eAC3C,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AC5G,IACE,AAAC,CAAA,MAAM,SAAS,KAAK,YAAY,MAAM,SAAS,KAAK,UAAU,GAAE,KACjE,SAAS,QAAQ,CAAC,MAAM,GAAG,KAC3B,AAAC,CAAA,UAAU,WAAW,SAAS,QAAQ,CAAC,OAAO,CAAC,SAAS,MAAM,OAAO,CAAC,MAAK,IAC1E,iBAEF;IAEJ;IAEA,UAAU;QAAC,UAAU;IAAK,GAAG;iBAAC;mBAAS;IAAS;IAEhD,IAAI,eAAe,aAAa,IAAI,CAAC,CAAC,GAAG,IACvC,YAAY,GAAG,CAAC,EAAE,GAAG,IAAK,YAAY,GAAG,CAAC,EAAE,GAAG,IAAK,IAAI;IAE1D,8CAA8C;IAC9C,IAAI,CAAC,YAAY,SAAS,GAAG,IAAI,MAAM;QACrC,aAAa,OAAO,CAAC,CAAA;YACnB,QAAQ,WAAW;QACrB;QACA,OAAO;YACL,OAAO;mBAAI,SAAS,KAAK,CAAC,GAAG;mBAAa;mBAAiB,SAAS,KAAK,CAAC;aAAS;YACnF,SAAS;QACX;IACF;IAEA,uDAAuD;IACvD,OAAO,WACL,UACA,SAAS,GAAG,EACZ,CAAA,aAAe,CAAA;YACb,KAAK,WAAW,GAAG;YACnB,WAAW,WAAW,SAAS;YAC/B,OAAO,WAAW,KAAK;YACvB,UAAU;mBACL,WAAW,QAAQ,CAAE,KAAK,CAAC,GAAG;mBAC9B;mBACA,WAAW,QAAQ,CAAE,KAAK,CAAC;aAC/B;QACH,CAAA,GACA;AAEJ","sources":["packages/react-stately/src/data/useTreeData.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 {Key} from '@react-types/shared';\nimport {useState} from 'react';\n\nexport interface TreeOptions<T extends object> {\n /** Initial root items in the tree. */\n initialItems?: T[];\n /** The keys for the initially selected items. */\n initialSelectedKeys?: Iterable<Key>;\n /** A function that returns a unique key for an item object. */\n getKey?: (item: T) => Key;\n /** A function that returns the children for an item object. */\n getChildren?: (item: T) => T[];\n}\n\ninterface TreeNode<T extends object> {\n /** A unique key for the tree node. */\n key: Key;\n /** The key of the parent node. */\n parentKey?: Key | null;\n /** The value object for the tree node. */\n value: T;\n /** Children of the tree node. */\n children: TreeNode<T>[] | null;\n}\n\nexport interface TreeData<T extends object> {\n /** The root nodes in the tree. */\n items: TreeNode<T>[];\n\n /** The keys of the currently selected items in the tree. */\n selectedKeys: Set<Key>;\n\n /** Sets the selected keys. */\n setSelectedKeys(keys: Set<Key>): void;\n\n /**\n * Gets a node from the tree by key.\n *\n * @param key - The key of the item to retrieve.\n */\n getItem(key: Key): TreeNode<T> | undefined;\n\n /**\n * Inserts an item into a parent node as a child.\n *\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param index - The index within the parent to insert into.\n * @param value - The value to insert.\n */\n insert(parentKey: Key | null, index: number, ...values: T[]): void;\n\n /**\n * Inserts items into the list before the item at the given key.\n *\n * @param key - The key of the item to insert before.\n * @param values - The values to insert.\n */\n insertBefore(key: Key, ...values: T[]): void;\n\n /**\n * Inserts items into the list after the item at the given key.\n *\n * @param key - The key of the item to insert after.\n * @param values - The values to insert.\n */\n insertAfter(key: Key, ...values: T[]): void;\n\n /**\n * Appends an item into a parent node as a child.\n *\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param value - The value to insert.\n */\n append(parentKey: Key | null, ...values: T[]): void;\n\n /**\n * Prepends an item into a parent node as a child.\n *\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param value - The value to insert.\n */\n prepend(parentKey: Key | null, ...value: T[]): void;\n\n /**\n * Removes an item from the tree by its key.\n *\n * @param key - The key of the item to remove.\n */\n remove(...keys: Key[]): void;\n\n /**\n * Removes all items from the tree that are currently\n * in the set of selected items.\n */\n removeSelectedItems(): void;\n\n /**\n * Moves an item within the tree.\n *\n * @param key - The key of the item to move.\n * @param toParentKey - The key of the new parent to insert into. `null` for the root.\n * @param index - The index within the new parent to insert at.\n */\n move(key: Key, toParentKey: Key | null, index: number): void;\n\n /**\n * Moves one or more items before a given key.\n *\n * @param key - The key of the item to move the items before.\n * @param keys - The keys of the items to move.\n */\n moveBefore(key: Key, keys: Iterable<Key>): void;\n\n /**\n * Moves one or more items after a given key.\n *\n * @param key - The key of the item to move the items after.\n * @param keys - The keys of the items to move.\n */\n moveAfter(key: Key, keys: Iterable<Key>): void;\n\n /**\n * Updates an item in the tree.\n *\n * @param key - The key of the item to update.\n * @param newValue - The new value for the item.\n */\n update(key: Key, newValue: T): void;\n}\n\ninterface TreeDataState<T extends object> {\n items: TreeNode<T>[];\n nodeMap: Map<Key, TreeNode<T>>;\n}\n\n/**\n * Manages state for an immutable tree data structure, and provides convenience methods to\n * update the data over time.\n */\nexport function useTreeData<T extends object>(options: TreeOptions<T>): TreeData<T> {\n let {\n initialItems = [],\n initialSelectedKeys,\n getKey = (item: any) => item.id ?? item.key,\n getChildren = (item: any) => item.children\n } = options;\n\n // We only want to compute this on initial render.\n let [tree, setItems] = useState<TreeDataState<T>>(() => buildTree(initialItems, new Map()));\n let {items, nodeMap} = tree;\n\n let [selectedKeys, setSelectedKeys] = useState(new Set<Key>(initialSelectedKeys || []));\n\n // oxlint-disable-next-line react/react-compiler\n function buildTree(\n initialItems: T[] | null = [],\n map: Map<Key, TreeNode<T>>,\n parentKey?: Key | null\n ) {\n if (initialItems == null) {\n initialItems = [];\n }\n return {\n items: initialItems.map(item => {\n let node: TreeNode<T> = {\n key: getKey(item),\n parentKey: parentKey ?? null,\n value: item,\n children: null\n };\n\n node.children = buildTree(getChildren(item), map, node.key).items;\n map.set(node.key, node);\n return node;\n }),\n nodeMap: map\n };\n }\n\n function updateTree(\n items: TreeNode<T>[],\n key: Key | null,\n update: (node: TreeNode<T>) => TreeNode<T> | null,\n originalMap: Map<Key, TreeNode<T>>\n ) {\n let node = key == null ? null : originalMap.get(key);\n if (node == null) {\n return {items, nodeMap: originalMap};\n }\n let map = new Map<Key, TreeNode<T>>(originalMap);\n\n // Create a new node. If null, then delete the node, otherwise replace.\n let newNode = update(node);\n if (newNode == null) {\n deleteNode(node, map);\n } else {\n addNode(newNode, map);\n }\n\n // Walk up the tree and update each parent to refer to the new children.\n while (node && node.parentKey) {\n let nextParent = map.get(node.parentKey)!;\n let copy: TreeNode<T> = {\n key: nextParent.key,\n parentKey: nextParent.parentKey,\n value: nextParent.value,\n children: null\n };\n\n let children = nextParent.children;\n if (newNode == null && children) {\n children = children.filter(c => c !== node);\n }\n\n copy.children =\n children?.map(child => {\n if (child === node) {\n // newNode cannot be null here due to the above filter.\n return newNode!;\n }\n\n return child;\n }) ?? null;\n\n map.set(copy.key, copy);\n\n newNode = copy;\n node = nextParent;\n }\n\n if (newNode == null) {\n items = items.filter(c => c !== node);\n }\n\n return {\n items: items.map(item => {\n if (item === node) {\n // newNode cannot be null here due to the above filter.\n return newNode!;\n }\n\n return item;\n }),\n nodeMap: map\n };\n }\n\n function addNode(node: TreeNode<T>, map: Map<Key, TreeNode<T>>) {\n map.set(node.key, node);\n if (node.children) {\n for (let child of node.children) {\n addNode(child, map);\n }\n }\n }\n\n function deleteNode(node: TreeNode<T>, map: Map<Key, TreeNode<T>>) {\n map.delete(node.key);\n if (node.children) {\n for (let child of node.children) {\n deleteNode(child, map);\n }\n }\n }\n return {\n items,\n selectedKeys,\n setSelectedKeys,\n getItem(key: Key) {\n return nodeMap.get(key);\n },\n insert(parentKey: Key | null, index: number, ...values: T[]) {\n setItems(({items, nodeMap: originalMap}) => {\n let {items: newNodes, nodeMap: newMap} = buildTree(values, new Map(originalMap), parentKey);\n\n // If parentKey is null, insert into the root.\n if (parentKey == null) {\n return {\n items: [...items.slice(0, index), ...newNodes, ...items.slice(index)],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(\n items,\n parentKey,\n parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, index),\n ...newNodes,\n ...parentNode.children!.slice(index)\n ]\n }),\n newMap\n );\n });\n },\n insertBefore(key: Key, ...values: T[]): void {\n let node = nodeMap.get(key);\n if (!node) {\n return;\n }\n\n let parentNode = nodeMap.get(node.parentKey!);\n let nodes = parentNode ? parentNode.children : items;\n let index = nodes!.indexOf(node);\n this.insert(parentNode?.key ?? null, index, ...values);\n },\n insertAfter(key: Key, ...values: T[]): void {\n let node = nodeMap.get(key);\n if (!node) {\n return;\n }\n\n let parentNode = nodeMap.get(node.parentKey!);\n let nodes = parentNode ? parentNode.children : items;\n let index = nodes!.indexOf(node);\n this.insert(parentNode?.key ?? null, index + 1, ...values);\n },\n prepend(parentKey: Key | null, ...values: T[]) {\n this.insert(parentKey, 0, ...values);\n },\n append(parentKey: Key | null, ...values: T[]) {\n if (parentKey == null) {\n this.insert(null, items.length, ...values);\n } else {\n let parentNode = nodeMap.get(parentKey);\n if (!parentNode) {\n return;\n }\n\n this.insert(parentKey, parentNode.children!.length, ...values);\n }\n },\n remove(...keys: Key[]) {\n if (keys.length === 0) {\n return;\n }\n\n let newItems = items;\n let prevMap = nodeMap;\n let newTree;\n for (let key of keys) {\n newTree = updateTree(newItems, key, () => null, prevMap);\n prevMap = newTree.nodeMap;\n newItems = newTree.items;\n }\n\n setItems(newTree);\n\n let selection = new Set(selectedKeys);\n for (let key of selectedKeys) {\n if (!newTree.nodeMap.has(key)) {\n selection.delete(key);\n }\n }\n\n setSelectedKeys(selection);\n },\n removeSelectedItems() {\n this.remove(...selectedKeys);\n },\n move(key: Key, toParentKey: Key | null, index: number) {\n setItems(({items, nodeMap: originalMap}) => {\n let node = originalMap.get(key);\n if (!node) {\n return {items, nodeMap: originalMap};\n }\n\n let {items: newItems, nodeMap: newMap} = updateTree(items, key, () => null, originalMap);\n\n const movedNode = {\n ...node,\n parentKey: toParentKey\n };\n\n // If parentKey is null, insert into the root.\n if (toParentKey == null) {\n addNode(movedNode, newMap);\n return {\n items: [...newItems.slice(0, index), movedNode, ...newItems.slice(index)],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(\n newItems,\n toParentKey,\n parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, index),\n movedNode,\n ...parentNode.children!.slice(index)\n ]\n }),\n newMap\n );\n });\n },\n moveBefore(key: Key, keys: Iterable<Key>) {\n setItems(prevState => {\n let {items, nodeMap} = prevState;\n let node = nodeMap.get(key);\n if (!node) {\n return prevState;\n }\n let toParentKey = node.parentKey ?? null;\n let parent: null | TreeNode<T> = null;\n if (toParentKey != null) {\n parent = nodeMap.get(toParentKey) ?? null;\n }\n let toIndex = parent?.children ? parent.children.indexOf(node) : items.indexOf(node);\n return moveItems(prevState, keys, parent, toIndex, updateTree, addNode);\n });\n },\n moveAfter(key: Key, keys: Iterable<Key>) {\n setItems(prevState => {\n let {items, nodeMap} = prevState;\n let node = nodeMap.get(key);\n if (!node) {\n return prevState;\n }\n let toParentKey = node.parentKey ?? null;\n let parent: null | TreeNode<T> = null;\n if (toParentKey != null) {\n parent = nodeMap.get(toParentKey) ?? null;\n }\n let toIndex = parent?.children ? parent.children.indexOf(node) : items.indexOf(node);\n toIndex++;\n return moveItems(prevState, keys, parent, toIndex, updateTree, addNode);\n });\n },\n update(oldKey: Key, newValue: T) {\n setItems(({items, nodeMap: originalMap}) =>\n updateTree(\n items,\n oldKey,\n oldNode => {\n let node: TreeNode<T> = {\n key: oldNode.key,\n parentKey: oldNode.parentKey,\n value: newValue,\n children: null\n };\n\n let tree = buildTree(getChildren(newValue), originalMap, node.key);\n node.children = tree.items;\n return node;\n },\n originalMap\n )\n );\n }\n };\n}\n\nfunction moveItems<T extends object>(\n state: TreeDataState<T>,\n keys: Iterable<Key>,\n toParent: TreeNode<T> | null,\n toIndex: number,\n updateTree: (\n items: TreeNode<T>[],\n key: Key | null,\n update: (node: TreeNode<T>) => TreeNode<T> | null,\n originalMap: Map<Key, TreeNode<T>>\n ) => TreeDataState<T>,\n addNode: (node: TreeNode<T>, map: Map<Key, TreeNode<T>>) => void\n): TreeDataState<T> {\n let {items, nodeMap} = state;\n\n let parent = toParent;\n let removeKeys = new Set(keys);\n while (parent?.parentKey != null) {\n if (removeKeys.has(parent.key)) {\n throw new Error('Cannot move an item to be a child of itself.');\n }\n parent = nodeMap.get(parent.parentKey!) ?? null;\n }\n\n let originalToIndex = toIndex;\n\n let keyArray = Array.isArray(keys) ? keys : [...keys];\n // depth first search to put keys in order\n let inOrderKeys: Map<Key, number> = new Map();\n let removedItems: Array<TreeNode<T>> = [];\n let newItems = items;\n let newMap = nodeMap;\n let i = 0;\n\n function traversal(node, {inorder, postorder}) {\n inorder?.(node);\n if (node != null) {\n for (let child of node.children ?? []) {\n traversal(child, {inorder, postorder});\n postorder?.(child);\n }\n }\n }\n\n function inorder(child) {\n // in-order so we add items as we encounter them in the tree, then we can insert them in expected order later\n if (keyArray.includes(child.key)) {\n inOrderKeys.set(child.key, i++);\n }\n }\n\n function postorder(child) {\n // remove items and update the tree from the leaves and work upwards toward the root, this way\n // we don't copy child node references from parents inadvertently\n if (keyArray.includes(child.key)) {\n removedItems.push({...newMap.get(child.key)!, parentKey: toParent?.key ?? null});\n let {items: nextItems, nodeMap: nextMap} = updateTree(\n newItems,\n child.key,\n () => null,\n newMap\n );\n newItems = nextItems;\n newMap = nextMap;\n }\n // decrement the index if the child being removed is in the target parent and before the target index\n // the root node is special, it is null, and will not have a key, however, a parentKey can still point to it\n if (\n (child.parentKey === toParent || child.parentKey === toParent?.key) &&\n keyArray.includes(child.key) &&\n (toParent?.children ? toParent.children.indexOf(child) : items.indexOf(child)) <\n originalToIndex\n ) {\n toIndex--;\n }\n }\n\n traversal({children: items}, {inorder, postorder});\n\n let inOrderItems = removedItems.sort((a, b) =>\n inOrderKeys.get(a.key)! > inOrderKeys.get(b.key)! ? 1 : -1\n );\n // If parentKey is null, insert into the root.\n if (!toParent || toParent.key == null) {\n inOrderItems.forEach(movedNode => {\n addNode(movedNode, newMap);\n });\n return {\n items: [...newItems.slice(0, toIndex), ...inOrderItems, ...newItems.slice(toIndex)],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(\n newItems,\n toParent.key,\n parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, toIndex),\n ...inOrderItems,\n ...parentNode.children!.slice(toIndex)\n ]\n }),\n newMap\n );\n}\n"],"names":[],"version":3,"file":"useTreeData.mjs.map"}
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;CAUC;AA6IM,SAAS,0CAA8B,OAAuB;IACnE,IAAI,gBACF,eAAe,EAAE,uBACjB,mBAAmB,UACnB,SAAS,CAAC,OAAc,KAAK,EAAE,IAAI,KAAK,GAAG,eAC3C,cAAc,CAAC,OAAc,KAAK,QAAQ,EAC3C,GAAG;IAEJ,kDAAkD;IAClD,IAAI,CAAC,MAAM,SAAS,GAAG,CAAA,GAAA,eAAO,EAAoB,IAAM,UAAU,cAAc,IAAI;IACpF,IAAI,SAAC,KAAK,WAAE,OAAO,EAAC,GAAG;IAEvB,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,eAAO,EAAE,IAAI,IAAS,uBAAuB,EAAE;IAErF,gDAAgD;IAChD,SAAS,UACP,eAA2B,EAAE,EAC7B,GAA0B,EAC1B,SAAsB;QAEtB,IAAI,gBAAgB,MAClB,eAAe,EAAE;QAEnB,OAAO;YACL,OAAO,aAAa,GAAG,CAAC,CAAA;gBACtB,IAAI,OAAoB;oBACtB,KAAK,OAAO;oBACZ,WAAW,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C,YAAY,GAAG,CAAC,EAAE,GAAG,IAAK,YAAY,GAAG,CAAC,EAAE,GAAG,IAAK,IAAI;IAE1D,8CAA8C;IAC9C,IAAI,CAAC,YAAY,SAAS,GAAG,IAAI,MAAM;QACrC,aAAa,OAAO,CAAC,CAAA;YACnB,QAAQ,WAAW;QACrB;QACA,OAAO;YACL,OAAO;mBAAI,SAAS,KAAK,CAAC,GAAG;mBAAa;mBAAiB,SAAS,KAAK,CAAC;aAAS;YACnF,SAAS;QACX;IACF;IAEA,uDAAuD;IACvD,OAAO,WACL,UACA,SAAS,GAAG,EACZ,CAAA,aAAe,CAAA;YACb,KAAK,WAAW,GAAG;YACnB,WAAW,WAAW,SAAS;YAC/B,OAAO,WAAW,KAAK;YACvB,UAAU;mBACL,WAAW,QAAQ,CAAE,KAAK,CAAC,GAAG;mBAC9B;mBACA,WAAW,QAAQ,CAAE,KAAK,CAAC;aAC/B;QACH,CAAA,GACA;AAEJ","sources":["packages/react-stately/src/data/useTreeData.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 {Key} from '@react-types/shared';\nimport {useState} from 'react';\n\nexport interface TreeOptions<T extends object> {\n /** Initial root items in the tree. */\n initialItems?: T[];\n /** The keys for the initially selected items. */\n initialSelectedKeys?: Iterable<Key>;\n /** A function that returns a unique key for an item object. */\n getKey?: (item: T) => Key;\n /** A function that returns the children for an item object. */\n getChildren?: (item: T) => T[];\n}\n\ninterface TreeNode<T extends object> {\n /** A unique key for the tree node. */\n key: Key;\n /** The key of the parent node. */\n parentKey?: Key | null;\n /** The value object for the tree node. */\n value: T;\n /** Children of the tree node. */\n children: TreeNode<T>[] | null;\n}\n\nexport interface TreeData<T extends object> {\n /** The root nodes in the tree. */\n items: TreeNode<T>[];\n\n /** The keys of the currently selected items in the tree. */\n selectedKeys: Set<Key>;\n\n /** Sets the selected keys. */\n setSelectedKeys(keys: Set<Key>): void;\n\n /**\n * Gets a node from the tree by key.\n *\n * @param key - The key of the item to retrieve.\n */\n getItem(key: Key): TreeNode<T> | undefined;\n\n /**\n * Inserts an item into a parent node as a child.\n *\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param index - The index within the parent to insert into.\n * @param value - The value to insert.\n */\n insert(parentKey: Key | null, index: number, ...values: T[]): void;\n\n /**\n * Inserts items into the list before the item at the given key.\n *\n * @param key - The key of the item to insert before.\n * @param values - The values to insert.\n */\n insertBefore(key: Key, ...values: T[]): void;\n\n /**\n * Inserts items into the list after the item at the given key.\n *\n * @param key - The key of the item to insert after.\n * @param values - The values to insert.\n */\n insertAfter(key: Key, ...values: T[]): void;\n\n /**\n * Appends an item into a parent node as a child.\n *\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param value - The value to insert.\n */\n append(parentKey: Key | null, ...values: T[]): void;\n\n /**\n * Prepends an item into a parent node as a child.\n *\n * @param parentKey - The key of the parent item to insert into. `null` for the root.\n * @param value - The value to insert.\n */\n prepend(parentKey: Key | null, ...value: T[]): void;\n\n /**\n * Removes an item from the tree by its key.\n *\n * @param key - The key of the item to remove.\n */\n remove(...keys: Key[]): void;\n\n /**\n * Removes all items from the tree that are currently\n * in the set of selected items.\n */\n removeSelectedItems(): void;\n\n /**\n * Moves an item within the tree.\n *\n * @param key - The key of the item to move.\n * @param toParentKey - The key of the new parent to insert into. `null` for the root.\n * @param index - The index within the new parent to insert at.\n */\n move(key: Key, toParentKey: Key | null, index: number): void;\n\n /**\n * Moves one or more items before a given key.\n *\n * @param key - The key of the item to move the items before.\n * @param keys - The keys of the items to move.\n */\n moveBefore(key: Key, keys: Iterable<Key>): void;\n\n /**\n * Moves one or more items after a given key.\n *\n * @param key - The key of the item to move the items after.\n * @param keys - The keys of the items to move.\n */\n moveAfter(key: Key, keys: Iterable<Key>): void;\n\n /**\n * Updates an item in the tree.\n *\n * @param key - The key of the item to update.\n * @param newValue - The new value for the item.\n */\n update(key: Key, newValue: T): void;\n}\n\ninterface TreeDataState<T extends object> {\n items: TreeNode<T>[];\n nodeMap: Map<Key, TreeNode<T>>;\n}\n\n/**\n * Manages state for an immutable tree data structure, and provides convenience methods to\n * update the data over time.\n */\nexport function useTreeData<T extends object>(options: TreeOptions<T>): TreeData<T> {\n let {\n initialItems = [],\n initialSelectedKeys,\n getKey = (item: any) => item.id ?? item.key,\n getChildren = (item: any) => item.children\n } = options;\n\n // We only want to compute this on initial render.\n let [tree, setItems] = useState<TreeDataState<T>>(() => buildTree(initialItems, new Map()));\n let {items, nodeMap} = tree;\n\n let [selectedKeys, setSelectedKeys] = useState(new Set<Key>(initialSelectedKeys || []));\n\n // oxlint-disable-next-line react/react-compiler\n function buildTree(\n initialItems: T[] | null = [],\n map: Map<Key, TreeNode<T>>,\n parentKey?: Key | null\n ) {\n if (initialItems == null) {\n initialItems = [];\n }\n return {\n items: initialItems.map(item => {\n let node: TreeNode<T> = {\n key: getKey(item),\n parentKey: parentKey ?? null,\n value: item,\n children: null\n };\n\n node.children = buildTree(getChildren(item), map, node.key).items;\n map.set(node.key, node);\n return node;\n }),\n nodeMap: map\n };\n }\n\n function updateTree(\n items: TreeNode<T>[],\n key: Key | null,\n update: (node: TreeNode<T>) => TreeNode<T> | null,\n originalMap: Map<Key, TreeNode<T>>\n ) {\n let node = key == null ? null : originalMap.get(key);\n if (node == null) {\n return {items, nodeMap: originalMap};\n }\n let map = new Map<Key, TreeNode<T>>(originalMap);\n\n // Create a new node. If null, then delete the node, otherwise replace.\n let newNode = update(node);\n if (newNode == null) {\n deleteNode(node, map);\n } else {\n addNode(newNode, map);\n }\n\n // Walk up the tree and update each parent to refer to the new children.\n while (node && node.parentKey) {\n let nextParent = map.get(node.parentKey)!;\n let copy: TreeNode<T> = {\n key: nextParent.key,\n parentKey: nextParent.parentKey,\n value: nextParent.value,\n children: null\n };\n\n let children = nextParent.children;\n if (newNode == null && children) {\n children = children.filter(c => c !== node);\n }\n\n copy.children =\n children?.map(child => {\n if (child === node) {\n // newNode cannot be null here due to the above filter.\n return newNode!;\n }\n\n return child;\n }) ?? null;\n\n map.set(copy.key, copy);\n\n newNode = copy;\n node = nextParent;\n }\n\n if (newNode == null) {\n items = items.filter(c => c !== node);\n }\n\n return {\n items: items.map(item => {\n if (item === node) {\n // newNode cannot be null here due to the above filter.\n return newNode!;\n }\n\n return item;\n }),\n nodeMap: map\n };\n }\n\n function addNode(node: TreeNode<T>, map: Map<Key, TreeNode<T>>) {\n map.set(node.key, node);\n if (node.children) {\n for (let child of node.children) {\n addNode(child, map);\n }\n }\n }\n\n function deleteNode(node: TreeNode<T>, map: Map<Key, TreeNode<T>>) {\n map.delete(node.key);\n if (node.children) {\n for (let child of node.children) {\n deleteNode(child, map);\n }\n }\n }\n return {\n items,\n selectedKeys,\n setSelectedKeys,\n getItem(key: Key) {\n return nodeMap.get(key);\n },\n insert(parentKey: Key | null, index: number, ...values: T[]) {\n setItems(({items, nodeMap: originalMap}) => {\n let {items: newNodes, nodeMap: newMap} = buildTree(values, new Map(originalMap), parentKey);\n\n // If parentKey is null, insert into the root.\n if (parentKey == null) {\n return {\n items: [...items.slice(0, index), ...newNodes, ...items.slice(index)],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(\n items,\n parentKey,\n parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, index),\n ...newNodes,\n ...parentNode.children!.slice(index)\n ]\n }),\n newMap\n );\n });\n },\n insertBefore(key: Key, ...values: T[]): void {\n let node = nodeMap.get(key);\n if (!node) {\n return;\n }\n\n let parentNode = nodeMap.get(node.parentKey!);\n let nodes = parentNode ? parentNode.children : items;\n let index = nodes!.indexOf(node);\n this.insert(parentNode?.key ?? null, index, ...values);\n },\n insertAfter(key: Key, ...values: T[]): void {\n let node = nodeMap.get(key);\n if (!node) {\n return;\n }\n\n let parentNode = nodeMap.get(node.parentKey!);\n let nodes = parentNode ? parentNode.children : items;\n let index = nodes!.indexOf(node);\n this.insert(parentNode?.key ?? null, index + 1, ...values);\n },\n prepend(parentKey: Key | null, ...values: T[]) {\n this.insert(parentKey, 0, ...values);\n },\n append(parentKey: Key | null, ...values: T[]) {\n if (parentKey == null) {\n this.insert(null, items.length, ...values);\n } else {\n let parentNode = nodeMap.get(parentKey);\n if (!parentNode) {\n return;\n }\n\n this.insert(parentKey, parentNode.children!.length, ...values);\n }\n },\n remove(...keys: Key[]) {\n if (keys.length === 0) {\n return;\n }\n\n let newItems = items;\n let prevMap = nodeMap;\n let newTree;\n for (let key of keys) {\n newTree = updateTree(newItems, key, () => null, prevMap);\n prevMap = newTree.nodeMap;\n newItems = newTree.items;\n }\n\n setItems(newTree);\n\n let selection = new Set(selectedKeys);\n for (let key of selectedKeys) {\n if (!newTree.nodeMap.has(key)) {\n selection.delete(key);\n }\n }\n\n setSelectedKeys(selection);\n },\n removeSelectedItems() {\n this.remove(...selectedKeys);\n },\n move(key: Key, toParentKey: Key | null, index: number) {\n setItems(({items, nodeMap: originalMap}) => {\n let current = toParentKey;\n while (current != null) {\n if (current === key) {\n throw new Error('Cannot move an item to be a child of itself.');\n }\n current = originalMap.get(current)?.parentKey ?? null;\n }\n\n let node = originalMap.get(key);\n if (!node) {\n return {items, nodeMap: originalMap};\n }\n\n let {items: newItems, nodeMap: newMap} = updateTree(items, key, () => null, originalMap);\n\n const movedNode = {\n ...node,\n parentKey: toParentKey\n };\n\n // If parentKey is null, insert into the root.\n if (toParentKey == null) {\n addNode(movedNode, newMap);\n return {\n items: [...newItems.slice(0, index), movedNode, ...newItems.slice(index)],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(\n newItems,\n toParentKey,\n parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, index),\n movedNode,\n ...parentNode.children!.slice(index)\n ]\n }),\n newMap\n );\n });\n },\n moveBefore(key: Key, keys: Iterable<Key>) {\n setItems(prevState => {\n let {items, nodeMap} = prevState;\n let node = nodeMap.get(key);\n if (!node) {\n return prevState;\n }\n let toParentKey = node.parentKey ?? null;\n let parent: null | TreeNode<T> = null;\n if (toParentKey != null) {\n parent = nodeMap.get(toParentKey) ?? null;\n }\n let toIndex = parent?.children ? parent.children.indexOf(node) : items.indexOf(node);\n return moveItems(prevState, keys, parent, toIndex, updateTree, addNode);\n });\n },\n moveAfter(key: Key, keys: Iterable<Key>) {\n setItems(prevState => {\n let {items, nodeMap} = prevState;\n let node = nodeMap.get(key);\n if (!node) {\n return prevState;\n }\n let toParentKey = node.parentKey ?? null;\n let parent: null | TreeNode<T> = null;\n if (toParentKey != null) {\n parent = nodeMap.get(toParentKey) ?? null;\n }\n let toIndex = parent?.children ? parent.children.indexOf(node) : items.indexOf(node);\n toIndex++;\n return moveItems(prevState, keys, parent, toIndex, updateTree, addNode);\n });\n },\n update(oldKey: Key, newValue: T) {\n setItems(({items, nodeMap: originalMap}) =>\n updateTree(\n items,\n oldKey,\n oldNode => {\n let node: TreeNode<T> = {\n key: oldNode.key,\n parentKey: oldNode.parentKey,\n value: newValue,\n children: null\n };\n\n let tree = buildTree(getChildren(newValue), originalMap, node.key);\n node.children = tree.items;\n return node;\n },\n originalMap\n )\n );\n }\n };\n}\n\nfunction moveItems<T extends object>(\n state: TreeDataState<T>,\n keys: Iterable<Key>,\n toParent: TreeNode<T> | null,\n toIndex: number,\n updateTree: (\n items: TreeNode<T>[],\n key: Key | null,\n update: (node: TreeNode<T>) => TreeNode<T> | null,\n originalMap: Map<Key, TreeNode<T>>\n ) => TreeDataState<T>,\n addNode: (node: TreeNode<T>, map: Map<Key, TreeNode<T>>) => void\n): TreeDataState<T> {\n let {items, nodeMap} = state;\n\n let parent = toParent;\n let removeKeys = new Set(keys);\n while (parent != null) {\n if (removeKeys.has(parent.key)) {\n throw new Error('Cannot move an item to be a child of itself.');\n }\n parent = parent.parentKey != null ? (nodeMap.get(parent.parentKey) ?? null) : null;\n }\n\n let originalToIndex = toIndex;\n\n let keyArray = Array.isArray(keys) ? keys : [...keys];\n // depth first search to put keys in order\n let inOrderKeys: Map<Key, number> = new Map();\n let removedItems: Array<TreeNode<T>> = [];\n let newItems = items;\n let newMap = nodeMap;\n let i = 0;\n\n function traversal(node, {inorder, postorder}) {\n inorder?.(node);\n if (node != null) {\n for (let child of node.children ?? []) {\n traversal(child, {inorder, postorder});\n postorder?.(child);\n }\n }\n }\n\n function inorder(child) {\n // in-order so we add items as we encounter them in the tree, then we can insert them in expected order later\n if (keyArray.includes(child.key)) {\n inOrderKeys.set(child.key, i++);\n }\n }\n\n function postorder(child) {\n // remove items and update the tree from the leaves and work upwards toward the root, this way\n // we don't copy child node references from parents inadvertently\n if (keyArray.includes(child.key)) {\n removedItems.push({...newMap.get(child.key)!, parentKey: toParent?.key ?? null});\n let {items: nextItems, nodeMap: nextMap} = updateTree(\n newItems,\n child.key,\n () => null,\n newMap\n );\n newItems = nextItems;\n newMap = nextMap;\n }\n // decrement the index if the child being removed is in the target parent and before the target index\n // the root node is special, it is null, and will not have a key, however, a parentKey can still point to it\n if (\n (child.parentKey === toParent || child.parentKey === toParent?.key) &&\n keyArray.includes(child.key) &&\n (toParent?.children ? toParent.children.indexOf(child) : items.indexOf(child)) <\n originalToIndex\n ) {\n toIndex--;\n }\n }\n\n traversal({children: items}, {inorder, postorder});\n\n let inOrderItems = removedItems.sort((a, b) =>\n inOrderKeys.get(a.key)! > inOrderKeys.get(b.key)! ? 1 : -1\n );\n // If parentKey is null, insert into the root.\n if (!toParent || toParent.key == null) {\n inOrderItems.forEach(movedNode => {\n addNode(movedNode, newMap);\n });\n return {\n items: [...newItems.slice(0, toIndex), ...inOrderItems, ...newItems.slice(toIndex)],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(\n newItems,\n toParent.key,\n parentNode => ({\n key: parentNode.key,\n parentKey: parentNode.parentKey,\n value: parentNode.value,\n children: [\n ...parentNode.children!.slice(0, toIndex),\n ...inOrderItems,\n ...parentNode.children!.slice(toIndex)\n ]\n }),\n newMap\n );\n}\n"],"names":[],"version":3,"file":"useTreeData.mjs.map"}
|
|
@@ -237,6 +237,10 @@ class $d474db7fa4a60716$export$cacbb3924155d68e extends (0, $4b8e6a761bc1571f$ex
|
|
|
237
237
|
return this.buildLoader(node, x, y);
|
|
238
238
|
case 'separator':
|
|
239
239
|
return this.buildItem(node, x, y);
|
|
240
|
+
// uses buildSection instead of buildItem cuz it has a child node (the trigger)
|
|
241
|
+
// that need to be processed
|
|
242
|
+
case 'submenutrigger':
|
|
243
|
+
return this.buildSection(node, x, y);
|
|
240
244
|
default:
|
|
241
245
|
throw new Error('Unsupported node type: ' + node.type);
|
|
242
246
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAuHD,MAAM,uCAAiB;AAOhB,MAAM,kDACH,CAAA,GAAA,gCAAK;IAsBb;;;GAGC,GACD,YAAY,UAA6B,CAAC,CAAC,CAAE;QAC3C,KAAK;QACL,IAAI,CAAC,OAAO,GAAG,SAAS,WAAW,SAAS,aAAa;QACzD,IAAI,CAAC,WAAW,GAAG,QAAQ,WAAW,IAAI;QAC1C,IAAI,CAAC,gBAAgB,GAAG,SAAS,oBAAoB,SAAS,sBAAsB;QACpF,IAAI,CAAC,WAAW,GAAG,SAAS,eAAe,SAAS,iBAAiB;QACrE,IAAI,CAAC,oBAAoB,GACvB,SAAS,wBAAwB,SAAS,0BAA0B;QACtE,IAAI,CAAC,UAAU,GAAG,SAAS,cAAc,SAAS,gBAAgB;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;gBACd,IAAI,cAAc,WAAW,KAAK,IAAI;gBACtC,IAAI,aAAa,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,OAAO,GAAG;gBAEvD,MAAO,cAAc,KAAM;oBACzB,IAAI,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;oBACnC,IAAI,CAAC,QAAQ,KAAK,KAAK,IAAI,aACzB;oBAGF,aAAa,IAAI,CAAC,aAAa,CAAC,eAAe;oBAC/C,aAAa,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC;gBAC3C;YACF;YACA,OACE,IAAI,CAAC,WAAW,KAAK,eACjB,IAAI,CAAA,GAAA,8BAAG,EACL,WAAW,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,sBAAsB,GAAG,GACrD,WAAW,IAAI,CAAC,CAAC,EACjB,IAAI,CAAC,sBAAsB,EAC3B,WAAW,IAAI,CAAC,MAAM,IAExB,IAAI,CAAA,GAAA,8BAAG,EACL,WAAW,IAAI,CAAC,CAAC,EACjB,WAAW,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,sBAAsB,GAAG,GACrD,WAAW,IAAI,CAAC,KAAK,EACrB,IAAI,CAAC,sBAAsB;QAErC,OACE,OAAO,WAAW,IAAI;QAGxB,OAAO,IAAI,CAAA,GAAA,oCAAS,EAAE,iBAAiB,OAAO,GAAG,GAAG,MAAM,OAAO,YAAY,EAAE;IACjF;AACF;AAEA,SAAS,8BACP,UAA+B,EAC/B,SAAqC;IAErC,MAAM,SAAoB,EAAE;IAC5B,KAAK,MAAM,QAAQ,WACjB,IAAI,UAAU,OACZ,OAAO,IAAI,CAAC;IAGhB,OAAO;AACT","sources":["packages/react-stately/src/layout/ListLayout.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 {\n Collection,\n DropTarget,\n DropTargetDelegate,\n ItemDropTarget,\n Key,\n Node,\n Orientation\n} from '@react-types/shared';\nimport {getChildNodes} from '../collections/getChildNodes';\nimport {InvalidationContext} from '../virtualizer/types';\nimport {Layout} from '../virtualizer/Layout';\nimport {LayoutInfo} from '../virtualizer/LayoutInfo';\nimport {Rect} from '../virtualizer/Rect';\nimport {Size} from '../virtualizer/Size';\n\nexport interface ListLayoutOptions {\n /**\n * The primary orientation of the items. Usually this is the direction that the collection\n * scrolls.\n *\n * @default 'vertical'\n */\n orientation?: Orientation;\n /**\n * The fixed size of a row in px with respect to the applied orientation.\n *\n * @default 48\n */\n rowSize?: number;\n /**\n * The estimated size of a row in px with respect to the applied orientation, when row sizes are\n * variable.\n */\n estimatedRowSize?: number;\n /**\n * The fixed size of a section header in px with respect to the applied orientation.\n *\n * @default 48\n */\n headingSize?: number;\n /**\n * The estimated size of a section header in px with respect to the applied orientation, when\n * heading sizes are variable.\n */\n estimatedHeadingSize?: number;\n /**\n * The fixed size of a loader element in px with respect to the applied orientation. This loader\n * is specifically for \"load more\" elements rendered when loading more rows at the root level or\n * inside nested row/sections.\n *\n * @default 48\n */\n loaderSize?: number;\n /**\n * The thickness of the drop indicator.\n *\n * @default 2\n */\n dropIndicatorThickness?: number;\n /**\n * The gap between items.\n *\n * @default 0\n */\n gap?: number;\n /**\n * The padding around the list.\n *\n * @default 0\n */\n padding?: number;\n /**\n * The fixed height of a row in px.\n *\n * @deprecated Use `rowSize` instead.\n * @default 48\n */\n rowHeight?: number;\n /**\n * The estimated height of a row, when row heights are variable.\n *\n * @deprecated Use `estimatedRowSize` instead.\n */\n estimatedRowHeight?: number;\n /**\n * The fixed height of a section header in px.\n *\n * @deprecated Use `headingSize` instead.\n * @default 48\n */\n headingHeight?: number;\n /**\n * The estimated height of a section header, when the height is variable.\n *\n * @deprecated Use `estimatedHeadingSize` instead.\n */\n estimatedHeadingHeight?: number;\n /**\n * The fixed height of a loader element in px. This loader is specifically for \"load more\"\n * elements rendered when loading more rows at the root level or inside nested row/sections.\n *\n * @deprecated Use `loaderSize` instead.\n * @default 48\n */\n loaderHeight?: number;\n}\n\n// A wrapper around LayoutInfo that supports hierarchy\nexport interface LayoutNode {\n node?: Node<unknown>;\n layoutInfo: LayoutInfo;\n children?: LayoutNode[];\n validRect: Rect;\n index?: number;\n}\n\nconst DEFAULT_HEIGHT = 48;\n\n/**\n * ListLayout is a virtualizer Layout implementation\n * that arranges its items in a stack along its applied orientation.\n * It supports both fixed and variable size items.\n */\nexport class ListLayout<T, O extends ListLayoutOptions = ListLayoutOptions>\n extends Layout<Node<T>, O>\n implements DropTargetDelegate\n{\n protected rowSize: number | null;\n protected orientation: Orientation;\n protected estimatedRowSize: number | null;\n protected headingSize: number | null;\n protected estimatedHeadingSize: number | null;\n protected loaderSize: number | null;\n protected dropIndicatorThickness: number;\n protected gap: number;\n protected padding: number;\n protected layoutNodes: Map<Key, LayoutNode>;\n protected contentSize: Size;\n protected lastCollection: Collection<Node<T>> | null;\n protected rootNodes: LayoutNode[];\n private invalidateEverything: boolean;\n /** The rectangle containing currently valid layout infos. */\n protected validRect: Rect;\n /** The rectangle of requested layout infos so far. */\n protected requestedRect: Rect;\n\n /**\n * Creates a new ListLayout with options. See the list of properties below for a description\n * of the options that can be provided.\n */\n constructor(options: ListLayoutOptions = {}) {\n super();\n this.rowSize = options?.rowSize ?? options?.rowHeight ?? null;\n this.orientation = options.orientation ?? 'vertical';\n this.estimatedRowSize = options?.estimatedRowSize ?? options?.estimatedRowHeight ?? null;\n this.headingSize = options?.headingSize ?? options?.headingHeight ?? null;\n this.estimatedHeadingSize =\n options?.estimatedHeadingSize ?? options?.estimatedHeadingHeight ?? null;\n this.loaderSize = options?.loaderSize ?? options?.loaderHeight ?? null;\n this.dropIndicatorThickness = options.dropIndicatorThickness || 2;\n this.gap = options.gap || 0;\n this.padding = options.padding || 0;\n this.layoutNodes = new Map();\n this.rootNodes = [];\n this.lastCollection = null;\n this.invalidateEverything = false;\n this.validRect = new Rect();\n this.requestedRect = new Rect();\n this.contentSize = new Size();\n }\n\n // Backward compatibility for subclassing.\n protected get collection(): Collection<Node<T>> {\n return this.virtualizer!.collection;\n }\n\n /** @deprecated Use `rowSize` instead. */\n protected get rowHeight(): number | null {\n return this.rowSize;\n }\n\n /** @deprecated Use `estimatedRowSize` instead. */\n protected get estimatedRowHeight(): number | null {\n return this.estimatedRowSize;\n }\n\n /** @deprecated Use `headingSize` instead. */\n protected get headingHeight(): number | null {\n return this.headingSize;\n }\n /** @deprecated Use `estimatedHeadingSize` instead. */\n protected get estimatedHeadingHeight(): number | null {\n return this.estimatedHeadingSize;\n }\n\n /** @deprecated Use `loaderSize` instead. */\n protected get loaderHeight(): number | null {\n return this.loaderSize;\n }\n\n getLayoutInfo(key: Key): LayoutInfo | null {\n this.ensureLayoutInfo(key);\n return this.layoutNodes.get(key)?.layoutInfo || null;\n }\n\n getVisibleLayoutInfos(rect: Rect): LayoutInfo[] {\n let offsetProperty = this.orientation === 'horizontal' ? 'x' : 'y';\n let heightProperty = this.orientation === 'horizontal' ? 'width' : 'height';\n\n // Adjust rect to keep number of visible rows consistent.\n // (only if height > 1 or width > 1 for getDropTargetFromPoint)\n if (rect[heightProperty] > 1) {\n let rowHeight = (this.rowSize ?? this.estimatedRowSize ?? DEFAULT_HEIGHT) + this.gap;\n // Clone only before mutating\n rect = rect.copy();\n let offset = Math.floor(rect[offsetProperty] / rowHeight) * rowHeight;\n let height = rect[heightProperty] + rect[offsetProperty] - offset;\n rect[offsetProperty] = offset;\n rect[heightProperty] = Math.ceil(height / rowHeight) * rowHeight;\n }\n\n // If layout hasn't yet been done for the requested rect, union the\n // new rect with the existing valid rect, and recompute.\n this.layoutIfNeeded(rect);\n\n let res: LayoutInfo[] = [];\n\n let addNodes = (nodes: LayoutNode[]) => {\n for (let node of nodes) {\n if (this.isVisible(node, rect)) {\n res.push(node.layoutInfo);\n\n if (node.children) {\n addNodes(node.children);\n }\n }\n }\n };\n\n addNodes(this.rootNodes);\n return res;\n }\n\n protected layoutIfNeeded(rect: Rect): void {\n if (!this.lastCollection) {\n return;\n }\n\n if (!this.requestedRect.containsRect(rect)) {\n this.requestedRect = this.requestedRect.union(rect);\n this.rootNodes = this.buildCollection();\n }\n\n // Ensure all of the persisted keys are available.\n for (let key of this.virtualizer!.persistedKeys) {\n if (this.ensureLayoutInfo(key)) {\n return;\n }\n }\n }\n\n private ensureLayoutInfo(key: Key) {\n // If the layout info wasn't found, it might be outside the bounds of the area that we've\n // computed layout for so far. This can happen when accessing a random key, e.g pressing Home/End.\n // Compute the full layout and try again.\n if (\n !this.layoutNodes.has(key) &&\n this.requestedRect.area < this.contentSize.area &&\n this.lastCollection\n ) {\n this.requestedRect = new Rect(0, 0, Infinity, Infinity);\n this.rootNodes = this.buildCollection();\n this.requestedRect = new Rect(0, 0, this.contentSize.width, this.contentSize.height);\n return true;\n }\n\n return false;\n }\n\n protected isVisible(node: LayoutNode, rect: Rect): boolean {\n return (\n node.layoutInfo.rect.intersects(rect) ||\n node.layoutInfo.isSticky ||\n node.layoutInfo.type === 'header' ||\n node.layoutInfo.type === 'loader' ||\n this.virtualizer!.isPersistedKey(node.layoutInfo.key)\n );\n }\n\n protected shouldInvalidateEverything(invalidationContext: InvalidationContext<O>): boolean {\n let options = invalidationContext.layoutOptions;\n return (\n invalidationContext.sizeChanged ||\n this.rowSize !== (options?.rowSize ?? options?.rowHeight ?? this.rowSize) ||\n this.orientation !== (options?.orientation ?? this.orientation) ||\n this.headingSize !== (options?.headingSize ?? options?.headingHeight ?? this.headingSize) ||\n this.loaderSize !== (options?.loaderSize ?? options?.loaderHeight ?? this.loaderSize) ||\n this.gap !== (options?.gap ?? this.gap) ||\n this.padding !== (options?.padding ?? this.padding)\n );\n }\n\n shouldInvalidateLayoutOptions(newOptions: O, oldOptions: O): boolean {\n return (\n (newOptions?.rowSize ?? newOptions?.rowHeight) !==\n (oldOptions?.rowSize ?? oldOptions?.rowHeight) ||\n newOptions.orientation !== oldOptions.orientation ||\n (newOptions?.estimatedRowSize ?? newOptions?.estimatedRowHeight) !==\n (oldOptions?.estimatedRowSize ?? oldOptions?.estimatedRowHeight) ||\n (newOptions?.headingSize ?? newOptions?.headingHeight) !==\n (oldOptions?.headingSize ?? oldOptions?.headingHeight) ||\n (newOptions?.estimatedHeadingSize ?? newOptions?.estimatedHeadingHeight) !==\n (oldOptions?.estimatedHeadingSize ?? oldOptions?.estimatedHeadingHeight) ||\n (newOptions?.loaderSize ?? newOptions?.loaderHeight) !==\n (oldOptions?.loaderSize ?? oldOptions?.loaderHeight) ||\n newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness ||\n newOptions.gap !== oldOptions.gap ||\n newOptions.padding !== oldOptions.padding\n );\n }\n\n update(invalidationContext: InvalidationContext<O>): void {\n let collection = this.virtualizer!.collection;\n\n // Reset valid rect if we will have to invalidate everything.\n // Otherwise we can reuse cached layout infos outside the current visible rect.\n this.invalidateEverything = this.shouldInvalidateEverything(invalidationContext);\n if (this.invalidateEverything) {\n this.requestedRect = this.virtualizer!.visibleRect.copy();\n this.layoutNodes.clear();\n }\n\n let options = invalidationContext.layoutOptions;\n this.rowSize = options?.rowSize ?? options?.rowHeight ?? this.rowSize;\n this.orientation = options?.orientation ?? this.orientation;\n this.estimatedRowSize =\n options?.estimatedRowSize ?? options?.estimatedRowHeight ?? this.estimatedRowSize;\n this.headingSize = options?.headingSize ?? options?.headingHeight ?? this.headingSize;\n this.estimatedHeadingSize =\n options?.estimatedHeadingSize ?? options?.estimatedHeadingHeight ?? this.estimatedHeadingSize;\n this.loaderSize = options?.loaderSize ?? options?.loaderHeight ?? this.loaderSize;\n this.dropIndicatorThickness = options?.dropIndicatorThickness ?? this.dropIndicatorThickness;\n this.gap = options?.gap ?? this.gap;\n this.padding = options?.padding ?? this.padding;\n\n this.rootNodes = this.buildCollection();\n\n // Remove deleted layout nodes\n if (this.lastCollection && collection !== this.lastCollection) {\n for (let key of this.lastCollection.getKeys()) {\n if (!collection.getItem(key)) {\n let layoutNode = this.layoutNodes.get(key);\n if (layoutNode) {\n this.layoutNodes.delete(key);\n }\n }\n }\n }\n\n this.lastCollection = collection;\n this.invalidateEverything = false;\n this.validRect = this.requestedRect.copy();\n }\n\n protected buildCollection(offset: number = this.padding): LayoutNode[] {\n let collection = this.virtualizer!.collection;\n let offsetProperty = this.orientation === 'horizontal' ? 'x' : 'y';\n let maxOffsetProperty = this.orientation === 'horizontal' ? 'maxX' : 'maxY';\n\n // filter out content nodes since we don't want them to affect the height\n // Tree specific for now, if we add content nodes to other collection items, we might need to reconsider this\n let collectionNodes = toArray(collection, node => node.type !== 'content');\n let loaderNodes = collectionNodes.filter(node => node.type === 'loader');\n let nodes: LayoutNode[] = [];\n let isEmptyOrLoading = collection?.size === 0;\n if (isEmptyOrLoading) {\n offset = 0;\n }\n\n for (let node of collectionNodes) {\n let rowHeight = (this.rowSize ?? this.estimatedRowSize ?? DEFAULT_HEIGHT) + this.gap;\n // Skip rows before the valid rectangle unless they are already cached.\n if (\n node.type === 'item' &&\n offset + rowHeight < this.requestedRect[offsetProperty] &&\n !this.isValid(node, offset)\n ) {\n offset += rowHeight;\n continue;\n }\n\n let layoutNode =\n this.orientation === 'horizontal'\n ? this.buildChild(node, offset, this.padding, null)\n : this.buildChild(node, this.padding, offset, null);\n offset = layoutNode.layoutInfo.rect[maxOffsetProperty] + this.gap;\n nodes.push(layoutNode);\n if (node.type === 'loader') {\n let index = loaderNodes.indexOf(node);\n loaderNodes.splice(index, 1);\n }\n\n // Build each loader that exists in the collection that is outside the visible rect so that they are persisted\n // at the proper estimated location. If the node.type is \"section\" then we don't do this shortcut since we have to\n // build the sections to see how tall they are.\n if (\n (node.type === 'item' || node.type === 'loader') &&\n offset > this.requestedRect[maxOffsetProperty]\n ) {\n let lastProcessedIndex = collectionNodes.indexOf(node);\n for (let loaderNode of loaderNodes) {\n let loaderNodeIndex = collectionNodes.indexOf(loaderNode);\n // Subtract by an additional 1 since we've already added the current item's height to y\n offset += (loaderNodeIndex - lastProcessedIndex - 1) * rowHeight;\n let loader =\n this.orientation === 'horizontal'\n ? this.buildChild(loaderNode, offset, this.padding, null)\n : this.buildChild(loaderNode, this.padding, offset, null);\n nodes.push(loader);\n offset = loader.layoutInfo.rect[maxOffsetProperty];\n lastProcessedIndex = loaderNodeIndex;\n }\n\n // Account for the rest of the items after the last loader spinner, subtract by 1 since we've processed the current node's height already\n offset += (collectionNodes.length - lastProcessedIndex - 1) * rowHeight;\n break;\n }\n }\n\n offset = Math.max(offset - this.gap, 0);\n offset += isEmptyOrLoading ? 0 : this.padding;\n this.contentSize =\n this.orientation === 'horizontal'\n ? new Size(offset, this.virtualizer!.size.height)\n : new Size(this.virtualizer!.size.width, offset);\n\n return nodes;\n }\n\n protected isValid(node: Node<T>, offset: number): boolean {\n let cached = this.layoutNodes.get(node.key);\n let offsetProperty = this.orientation === 'horizontal' ? 'x' : 'y';\n return (\n !this.invalidateEverything &&\n !!cached &&\n cached.node === node &&\n offset === cached.layoutInfo.rect[offsetProperty] &&\n cached.layoutInfo.rect.intersects(this.validRect) &&\n cached.validRect.containsRect(cached.layoutInfo.rect.intersection(this.requestedRect))\n );\n }\n\n protected buildChild(node: Node<T>, x: number, y: number, parentKey: Key | null): LayoutNode {\n if (this.isValid(node, this.orientation === 'horizontal' ? x : y)) {\n return this.layoutNodes.get(node.key)!;\n }\n\n let layoutNode = this.buildNode(node, x, y);\n\n layoutNode.layoutInfo.parentKey = parentKey ?? null;\n layoutNode.layoutInfo.allowOverflow = true;\n this.layoutNodes.set(node.key, layoutNode);\n return layoutNode;\n }\n\n protected buildNode(node: Node<T>, x: number, y: number): LayoutNode {\n switch (node.type) {\n case 'section':\n return this.buildSection(node, x, y);\n case 'item':\n return this.buildItem(node, x, y);\n case 'header':\n return this.buildSectionHeader(node, x, y);\n case 'loader':\n return this.buildLoader(node, x, y);\n case 'separator':\n return this.buildItem(node, x, y);\n default:\n throw new Error('Unsupported node type: ' + node.type);\n }\n }\n\n protected buildLoader(node: Node<T>, x: number, y: number): LayoutNode {\n let rect = new Rect(x, y, this.padding, 0);\n let layoutInfo = new LayoutInfo(node.type, node.key, rect);\n\n // Note that if the user provides isLoading to their sentinel during a case where they only want to render the emptyState, this will reserve\n // room for the loader alongside rendering the emptyState\n if (this.orientation === 'horizontal') {\n rect.height = this.virtualizer!.contentSize.height - this.padding - y;\n rect.width = node.props.isLoading\n ? (this.loaderSize ?? this.rowSize ?? this.estimatedRowSize ?? DEFAULT_HEIGHT)\n : 0;\n } else {\n rect.width = this.virtualizer!.contentSize.width - this.padding - x;\n rect.height = node.props.isLoading\n ? (this.loaderSize ?? this.rowSize ?? this.estimatedRowSize ?? DEFAULT_HEIGHT)\n : 0;\n }\n\n return {\n layoutInfo,\n validRect: rect.intersection(this.requestedRect)\n };\n }\n\n protected buildSection(node: Node<T>, x: number, y: number): LayoutNode {\n let collection = this.virtualizer!.collection;\n let width = this.virtualizer!.size.width - this.padding - x;\n let height = this.virtualizer!.size.height - this.padding - y;\n let rect =\n this.orientation === 'horizontal' ? new Rect(x, y, 0, height) : new Rect(x, y, width, 0);\n let layoutInfo = new LayoutInfo(node.type, node.key, rect);\n\n let offset = this.orientation === 'horizontal' ? x : y;\n let offsetProperty = this.orientation === 'horizontal' ? 'x' : 'y';\n let maxOffsetProperty = this.orientation === 'horizontal' ? 'maxX' : 'maxY';\n let heightProperty = this.orientation === 'horizontal' ? 'width' : 'height';\n\n let skipped = 0;\n let children: LayoutNode[] = [];\n for (let child of getChildNodes(node, collection)) {\n // skip if it is a content node, Tree specific for now, if we add content nodes to other collection items, we might need to reconsider this\n if (child.type === 'content') {\n continue;\n }\n\n let rowHeight = (this.rowSize ?? this.estimatedRowSize ?? DEFAULT_HEIGHT) + this.gap;\n\n // Skip rows before the valid rectangle unless they are already cached.\n if (offset + rowHeight < this.requestedRect[offsetProperty] && !this.isValid(node, offset)) {\n offset += rowHeight;\n skipped++;\n continue;\n }\n\n let layoutNode =\n this.orientation === 'horizontal'\n ? this.buildChild(child, offset, y, layoutInfo.key)\n : this.buildChild(child, x, offset, layoutInfo.key);\n offset = layoutNode.layoutInfo.rect[maxOffsetProperty] + this.gap;\n children.push(layoutNode);\n\n if (offset > this.requestedRect[maxOffsetProperty]) {\n // Estimate the remaining height for rows that we don't need to layout right now.\n offset +=\n ([...getChildNodes(node, collection)].length - (children.length + skipped)) * rowHeight;\n break;\n }\n }\n\n offset -= this.gap;\n rect[heightProperty] = offset - (this.orientation === 'horizontal' ? x : y);\n\n return {\n layoutInfo,\n children,\n validRect: layoutInfo.rect.intersection(this.requestedRect),\n node\n };\n }\n\n protected buildSectionHeader(node: Node<T>, x: number, y: number): LayoutNode {\n let widthProperty = this.orientation === 'horizontal' ? 'height' : 'width';\n let heightProperty = this.orientation === 'horizontal' ? 'width' : 'height';\n let width =\n this.virtualizer!.size[widthProperty] -\n this.padding -\n (this.orientation === 'horizontal' ? y : x);\n let rectHeight = this.headingSize;\n let isEstimated = false;\n\n // If no explicit height is available, use an estimated height.\n if (rectHeight == null) {\n // If a previous version of this layout info exists, reuse its height.\n // Mark as estimated if the size of the overall virtualizer changed,\n // or the content of the item changed.\n let previousLayoutNode = this.layoutNodes.get(node.key);\n let previousLayoutInfo = previousLayoutNode?.layoutInfo;\n if (previousLayoutInfo) {\n let curNode = this.virtualizer!.collection.getItem(node.key);\n let lastNode = this.lastCollection ? this.lastCollection.getItem(node.key) : null;\n rectHeight = previousLayoutNode!.layoutInfo.rect[heightProperty];\n isEstimated =\n width !== previousLayoutInfo.rect[widthProperty] ||\n curNode !== lastNode ||\n previousLayoutInfo.estimatedSize;\n } else {\n rectHeight = node.rendered ? this.estimatedHeadingSize : 0;\n isEstimated = true;\n }\n }\n\n if (rectHeight == null) {\n rectHeight = DEFAULT_HEIGHT;\n }\n\n let headerRect =\n this.orientation === 'horizontal'\n ? new Rect(x, y, rectHeight, width - y)\n : new Rect(x, y, width - x, rectHeight);\n let header = new LayoutInfo('header', node.key, headerRect);\n header.estimatedSize = isEstimated;\n return {\n layoutInfo: header,\n children: [],\n validRect: header.rect.intersection(this.requestedRect),\n node\n };\n }\n\n protected buildItem(node: Node<T>, x: number, y: number): LayoutNode {\n let widthProperty = this.orientation === 'horizontal' ? 'height' : 'width';\n let heightProperty = this.orientation === 'horizontal' ? 'width' : 'height';\n\n let width =\n this.virtualizer!.size[widthProperty] -\n this.padding -\n (this.orientation === 'horizontal' ? y : x);\n let rectHeight = this.rowSize;\n let isEstimated = false;\n\n // If no explicit height is available, use an estimated height.\n if (rectHeight == null) {\n // If a previous version of this layout info exists, reuse its height.\n // Mark as estimated if the size of the overall virtualizer changed,\n // or the content of the item changed.\n let previousLayoutNode = this.layoutNodes.get(node.key);\n if (previousLayoutNode) {\n rectHeight = previousLayoutNode.layoutInfo.rect[heightProperty];\n isEstimated =\n width !== previousLayoutNode.layoutInfo.rect[widthProperty] ||\n node !== previousLayoutNode.node ||\n previousLayoutNode.layoutInfo.estimatedSize;\n } else {\n rectHeight = this.estimatedRowSize;\n isEstimated = true;\n }\n }\n\n if (rectHeight == null) {\n rectHeight = DEFAULT_HEIGHT;\n }\n\n let rect =\n this.orientation === 'horizontal'\n ? new Rect(x, y, rectHeight, width)\n : new Rect(x, y, width, rectHeight);\n let layoutInfo = new LayoutInfo(node.type, node.key, rect);\n layoutInfo.estimatedSize = isEstimated;\n return {\n layoutInfo,\n children: [],\n validRect: layoutInfo.rect.intersection(this.requestedRect),\n node\n };\n }\n\n updateItemSize(key: Key, size: Size): boolean {\n let layoutNode = this.layoutNodes.get(key);\n // If no layoutInfo, item has been deleted/removed.\n if (!layoutNode) {\n return false;\n }\n\n let collection = this.virtualizer!.collection;\n let layoutInfo = layoutNode.layoutInfo;\n let offsetProperty = this.orientation === 'horizontal' ? 'x' : 'y';\n let heightProperty = this.orientation === 'horizontal' ? 'width' : 'height';\n layoutInfo.estimatedSize = false;\n if (layoutInfo.rect[heightProperty] !== size[heightProperty]) {\n // Copy layout info rather than mutating so that later caches are invalidated.\n let newLayoutInfo = layoutInfo.copy();\n newLayoutInfo.rect[heightProperty] = size[heightProperty];\n layoutNode.layoutInfo = newLayoutInfo;\n\n // Items after this layoutInfo will need to be repositioned to account for the new height.\n // Adjust the validRect so that only items above remain valid.\n this.validRect[heightProperty] = Math.min(\n this.validRect[heightProperty],\n layoutInfo.rect[offsetProperty] - this.validRect[offsetProperty]\n );\n\n // The requestedRect also needs to be adjusted to account for the height difference.\n if (layoutNode.node?.type === 'item') {\n this.requestedRect[heightProperty] +=\n newLayoutInfo.rect[heightProperty] - layoutInfo.rect[heightProperty];\n }\n\n // Invalidate layout for this layout node and all parents\n this.updateLayoutNode(key, layoutInfo, newLayoutInfo);\n\n let node = layoutInfo.parentKey != null ? collection.getItem(layoutInfo.parentKey) : null;\n while (node) {\n this.updateLayoutNode(node.key, layoutInfo, newLayoutInfo);\n node = node.parentKey != null ? collection.getItem(node.parentKey) : null;\n }\n\n return true;\n }\n\n return false;\n }\n\n private updateLayoutNode(key: Key, oldLayoutInfo: LayoutInfo, newLayoutInfo: LayoutInfo) {\n let n = this.layoutNodes.get(key);\n if (n) {\n // Invalidate by intersecting the validRect of this node with the overall validRect.\n n.validRect = n.validRect.intersection(this.validRect);\n\n // Replace layout info in LayoutNode\n if (n.layoutInfo === oldLayoutInfo) {\n n.layoutInfo = newLayoutInfo;\n }\n }\n }\n\n getContentSize(): Size {\n return this.contentSize;\n }\n\n getDropTargetFromPoint(\n x: number,\n y: number,\n isValidDropTarget: (target: DropTarget) => boolean\n ): DropTarget | null {\n x += this.virtualizer!.visibleRect.x;\n y += this.virtualizer!.visibleRect.y;\n\n // Find the closest item within on either side of the point using the gap width.\n let searchRect = new Rect(x, Math.max(0, y - this.gap), 1, Math.max(1, this.gap * 2));\n let candidates = this.getVisibleLayoutInfos(searchRect);\n let key: Key | null = null;\n let minDistance = Infinity;\n for (let candidate of candidates) {\n // Ignore items outside the search rect, e.g. persisted keys.\n if (!candidate.rect.intersects(searchRect)) {\n continue;\n }\n\n let yDist = Math.abs(candidate.rect.y - y);\n let maxYDist = Math.abs(candidate.rect.maxY - y);\n let dist = Math.min(yDist, maxYDist);\n if (dist < minDistance) {\n minDistance = dist;\n key = candidate.key;\n }\n }\n\n if (key == null || this.virtualizer!.collection.size === 0) {\n return {type: 'root'};\n }\n\n let layoutInfo = this.getLayoutInfo(key);\n if (!layoutInfo) {\n return null;\n }\n\n let rect = layoutInfo.rect;\n let target: DropTarget = {\n type: 'item',\n key: layoutInfo.key,\n dropPosition: 'on'\n };\n\n // If dropping on the item isn't accepted, try the target before or after depending on the y position.\n // Otherwise, if dropping on the item is accepted, still try the before/after positions if within 10px\n // of the top or bottom of the item.\n if (!isValidDropTarget(target)) {\n if (y <= rect.y + rect.height / 2 && isValidDropTarget({...target, dropPosition: 'before'})) {\n target.dropPosition = 'before';\n } else if (isValidDropTarget({...target, dropPosition: 'after'})) {\n target.dropPosition = 'after';\n }\n } else if (y <= rect.y + 10 && isValidDropTarget({...target, dropPosition: 'before'})) {\n target.dropPosition = 'before';\n } else if (y >= rect.maxY - 10 && isValidDropTarget({...target, dropPosition: 'after'})) {\n target.dropPosition = 'after';\n }\n\n return target;\n }\n\n getDropTargetLayoutInfo(target: ItemDropTarget): LayoutInfo {\n let layoutInfo = this.getLayoutInfo(target.key)!;\n let rect: Rect;\n if (target.dropPosition === 'before') {\n rect =\n this.orientation === 'horizontal'\n ? new Rect(\n Math.max(0, layoutInfo.rect.x - this.dropIndicatorThickness / 2),\n layoutInfo.rect.y,\n this.dropIndicatorThickness,\n layoutInfo.rect.height\n )\n : new Rect(\n layoutInfo.rect.x,\n Math.max(0, layoutInfo.rect.y - this.dropIndicatorThickness / 2),\n layoutInfo.rect.width,\n this.dropIndicatorThickness\n );\n } else if (target.dropPosition === 'after') {\n // Render after last visible descendant of the drop target.\n let targetNode = this.collection.getItem(target.key);\n if (targetNode) {\n let targetLevel = targetNode.level ?? 0;\n let currentKey = this.collection.getKeyAfter(target.key);\n\n while (currentKey != null) {\n let node = this.collection.getItem(currentKey);\n if (!node || node.level <= targetLevel) {\n break;\n }\n\n layoutInfo = this.getLayoutInfo(currentKey) || layoutInfo;\n currentKey = this.collection.getKeyAfter(currentKey);\n }\n }\n rect =\n this.orientation === 'horizontal'\n ? new Rect(\n layoutInfo.rect.maxX - this.dropIndicatorThickness / 2,\n layoutInfo.rect.y,\n this.dropIndicatorThickness,\n layoutInfo.rect.height\n )\n : new Rect(\n layoutInfo.rect.x,\n layoutInfo.rect.maxY - this.dropIndicatorThickness / 2,\n layoutInfo.rect.width,\n this.dropIndicatorThickness\n );\n } else {\n rect = layoutInfo.rect;\n }\n\n return new LayoutInfo('dropIndicator', target.key + ':' + target.dropPosition, rect);\n }\n}\n\nfunction toArray<T>(\n collection: Collection<Node<T>>,\n predicate: (node: Node<T>) => boolean\n): Node<T>[] {\n const result: Node<T>[] = [];\n for (const node of collection) {\n if (predicate(node)) {\n result.push(node);\n }\n }\n return result;\n}\n"],"names":[],"version":3,"file":"ListLayout.cjs.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAuHD,MAAM,uCAAiB;AAOhB,MAAM,kDACH,CAAA,GAAA,gCAAK;IAsBb;;;GAGC,GACD,YAAY,UAA6B,CAAC,CAAC,CAAE;QAC3C,KAAK;QACL,IAAI,CAAC,OAAO,GAAG,SAAS,WAAW,SAAS,aAAa;QACzD,IAAI,CAAC,WAAW,GAAG,QAAQ,WAAW,IAAI;QAC1C,IAAI,CAAC,gBAAgB,GAAG,SAAS,oBAAoB,SAAS,sBAAsB;QACpF,IAAI,CAAC,WAAW,GAAG,SAAS,eAAe,SAAS,iBAAiB;QACrE,IAAI,CAAC,oBAAoB,GACvB,SAAS,wBAAwB,SAAS,0BAA0B;QACtE,IAAI,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.\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 {\n Collection,\n DropTarget,\n DropTargetDelegate,\n ItemDropTarget,\n Key,\n Node,\n Orientation\n} from '@react-types/shared';\nimport {getChildNodes} from '../collections/getChildNodes';\nimport {InvalidationContext} from '../virtualizer/types';\nimport {Layout} from '../virtualizer/Layout';\nimport {LayoutInfo} from '../virtualizer/LayoutInfo';\nimport {Rect} from '../virtualizer/Rect';\nimport {Size} from '../virtualizer/Size';\n\nexport interface ListLayoutOptions {\n /**\n * The primary orientation of the items. Usually this is the direction that the collection\n * scrolls.\n *\n * @default 'vertical'\n */\n orientation?: Orientation;\n /**\n * The fixed size of a row in px with respect to the applied orientation.\n *\n * @default 48\n */\n rowSize?: number;\n /**\n * The estimated size of a row in px with respect to the applied orientation, when row sizes are\n * variable.\n */\n estimatedRowSize?: number;\n /**\n * The fixed size of a section header in px with respect to the applied orientation.\n *\n * @default 48\n */\n headingSize?: number;\n /**\n * The estimated size of a section header in px with respect to the applied orientation, when\n * heading sizes are variable.\n */\n estimatedHeadingSize?: number;\n /**\n * The fixed size of a loader element in px with respect to the applied orientation. This loader\n * is specifically for \"load more\" elements rendered when loading more rows at the root level or\n * inside nested row/sections.\n *\n * @default 48\n */\n loaderSize?: number;\n /**\n * The thickness of the drop indicator.\n *\n * @default 2\n */\n dropIndicatorThickness?: number;\n /**\n * The gap between items.\n *\n * @default 0\n */\n gap?: number;\n /**\n * The padding around the list.\n *\n * @default 0\n */\n padding?: number;\n /**\n * The fixed height of a row in px.\n *\n * @deprecated Use `rowSize` instead.\n * @default 48\n */\n rowHeight?: number;\n /**\n * The estimated height of a row, when row heights are variable.\n *\n * @deprecated Use `estimatedRowSize` instead.\n */\n estimatedRowHeight?: number;\n /**\n * The fixed height of a section header in px.\n *\n * @deprecated Use `headingSize` instead.\n * @default 48\n */\n headingHeight?: number;\n /**\n * The estimated height of a section header, when the height is variable.\n *\n * @deprecated Use `estimatedHeadingSize` instead.\n */\n estimatedHeadingHeight?: number;\n /**\n * The fixed height of a loader element in px. This loader is specifically for \"load more\"\n * elements rendered when loading more rows at the root level or inside nested row/sections.\n *\n * @deprecated Use `loaderSize` instead.\n * @default 48\n */\n loaderHeight?: number;\n}\n\n// A wrapper around LayoutInfo that supports hierarchy\nexport interface LayoutNode {\n node?: Node<unknown>;\n layoutInfo: LayoutInfo;\n children?: LayoutNode[];\n validRect: Rect;\n index?: number;\n}\n\nconst DEFAULT_HEIGHT = 48;\n\n/**\n * ListLayout is a virtualizer Layout implementation\n * that arranges its items in a stack along its applied orientation.\n * It supports both fixed and variable size items.\n */\nexport class ListLayout<T, O extends ListLayoutOptions = ListLayoutOptions>\n extends Layout<Node<T>, O>\n implements DropTargetDelegate\n{\n protected rowSize: number | null;\n protected orientation: Orientation;\n protected estimatedRowSize: number | null;\n protected headingSize: number | null;\n protected estimatedHeadingSize: number | null;\n protected loaderSize: number | null;\n protected dropIndicatorThickness: number;\n protected gap: number;\n protected padding: number;\n protected layoutNodes: Map<Key, LayoutNode>;\n protected contentSize: Size;\n protected lastCollection: Collection<Node<T>> | null;\n protected rootNodes: LayoutNode[];\n private invalidateEverything: boolean;\n /** The rectangle containing currently valid layout infos. */\n protected validRect: Rect;\n /** The rectangle of requested layout infos so far. */\n protected requestedRect: Rect;\n\n /**\n * Creates a new ListLayout with options. See the list of properties below for a description\n * of the options that can be provided.\n */\n constructor(options: ListLayoutOptions = {}) {\n super();\n this.rowSize = options?.rowSize ?? options?.rowHeight ?? null;\n this.orientation = options.orientation ?? 'vertical';\n this.estimatedRowSize = options?.estimatedRowSize ?? options?.estimatedRowHeight ?? null;\n this.headingSize = options?.headingSize ?? options?.headingHeight ?? null;\n this.estimatedHeadingSize =\n options?.estimatedHeadingSize ?? options?.estimatedHeadingHeight ?? null;\n this.loaderSize = options?.loaderSize ?? options?.loaderHeight ?? null;\n this.dropIndicatorThickness = options.dropIndicatorThickness || 2;\n this.gap = options.gap || 0;\n this.padding = options.padding || 0;\n this.layoutNodes = new Map();\n this.rootNodes = [];\n this.lastCollection = null;\n this.invalidateEverything = false;\n this.validRect = new Rect();\n this.requestedRect = new Rect();\n this.contentSize = new Size();\n }\n\n // Backward compatibility for subclassing.\n protected get collection(): Collection<Node<T>> {\n return this.virtualizer!.collection;\n }\n\n /** @deprecated Use `rowSize` instead. */\n protected get rowHeight(): number | null {\n return this.rowSize;\n }\n\n /** @deprecated Use `estimatedRowSize` instead. */\n protected get estimatedRowHeight(): number | null {\n return this.estimatedRowSize;\n }\n\n /** @deprecated Use `headingSize` instead. */\n protected get headingHeight(): number | null {\n return this.headingSize;\n }\n /** @deprecated Use `estimatedHeadingSize` instead. */\n protected get estimatedHeadingHeight(): number | null {\n return this.estimatedHeadingSize;\n }\n\n /** @deprecated Use `loaderSize` instead. */\n protected get loaderHeight(): number | null {\n return this.loaderSize;\n }\n\n getLayoutInfo(key: Key): LayoutInfo | null {\n this.ensureLayoutInfo(key);\n return this.layoutNodes.get(key)?.layoutInfo || null;\n }\n\n getVisibleLayoutInfos(rect: Rect): LayoutInfo[] {\n let offsetProperty = this.orientation === 'horizontal' ? 'x' : 'y';\n let heightProperty = this.orientation === 'horizontal' ? 'width' : 'height';\n\n // Adjust rect to keep number of visible rows consistent.\n // (only if height > 1 or width > 1 for getDropTargetFromPoint)\n if (rect[heightProperty] > 1) {\n let rowHeight = (this.rowSize ?? this.estimatedRowSize ?? DEFAULT_HEIGHT) + this.gap;\n // Clone only before mutating\n rect = rect.copy();\n let offset = Math.floor(rect[offsetProperty] / rowHeight) * rowHeight;\n let height = rect[heightProperty] + rect[offsetProperty] - offset;\n rect[offsetProperty] = offset;\n rect[heightProperty] = Math.ceil(height / rowHeight) * rowHeight;\n }\n\n // If layout hasn't yet been done for the requested rect, union the\n // new rect with the existing valid rect, and recompute.\n this.layoutIfNeeded(rect);\n\n let res: LayoutInfo[] = [];\n\n let addNodes = (nodes: LayoutNode[]) => {\n for (let node of nodes) {\n if (this.isVisible(node, rect)) {\n res.push(node.layoutInfo);\n\n if (node.children) {\n addNodes(node.children);\n }\n }\n }\n };\n\n addNodes(this.rootNodes);\n return res;\n }\n\n protected layoutIfNeeded(rect: Rect): void {\n if (!this.lastCollection) {\n return;\n }\n\n if (!this.requestedRect.containsRect(rect)) {\n this.requestedRect = this.requestedRect.union(rect);\n this.rootNodes = this.buildCollection();\n }\n\n // Ensure all of the persisted keys are available.\n for (let key of this.virtualizer!.persistedKeys) {\n if (this.ensureLayoutInfo(key)) {\n return;\n }\n }\n }\n\n private ensureLayoutInfo(key: Key) {\n // If the layout info wasn't found, it might be outside the bounds of the area that we've\n // computed layout for so far. This can happen when accessing a random key, e.g pressing Home/End.\n // Compute the full layout and try again.\n if (\n !this.layoutNodes.has(key) &&\n this.requestedRect.area < this.contentSize.area &&\n this.lastCollection\n ) {\n this.requestedRect = new Rect(0, 0, Infinity, Infinity);\n this.rootNodes = this.buildCollection();\n this.requestedRect = new Rect(0, 0, this.contentSize.width, this.contentSize.height);\n return true;\n }\n\n return false;\n }\n\n protected isVisible(node: LayoutNode, rect: Rect): boolean {\n return (\n node.layoutInfo.rect.intersects(rect) ||\n node.layoutInfo.isSticky ||\n node.layoutInfo.type === 'header' ||\n node.layoutInfo.type === 'loader' ||\n this.virtualizer!.isPersistedKey(node.layoutInfo.key)\n );\n }\n\n protected shouldInvalidateEverything(invalidationContext: InvalidationContext<O>): boolean {\n let options = invalidationContext.layoutOptions;\n return (\n invalidationContext.sizeChanged ||\n this.rowSize !== (options?.rowSize ?? options?.rowHeight ?? this.rowSize) ||\n this.orientation !== (options?.orientation ?? this.orientation) ||\n this.headingSize !== (options?.headingSize ?? options?.headingHeight ?? this.headingSize) ||\n this.loaderSize !== (options?.loaderSize ?? options?.loaderHeight ?? this.loaderSize) ||\n this.gap !== (options?.gap ?? this.gap) ||\n this.padding !== (options?.padding ?? this.padding)\n );\n }\n\n shouldInvalidateLayoutOptions(newOptions: O, oldOptions: O): boolean {\n return (\n (newOptions?.rowSize ?? newOptions?.rowHeight) !==\n (oldOptions?.rowSize ?? oldOptions?.rowHeight) ||\n newOptions.orientation !== oldOptions.orientation ||\n (newOptions?.estimatedRowSize ?? newOptions?.estimatedRowHeight) !==\n (oldOptions?.estimatedRowSize ?? oldOptions?.estimatedRowHeight) ||\n (newOptions?.headingSize ?? newOptions?.headingHeight) !==\n (oldOptions?.headingSize ?? oldOptions?.headingHeight) ||\n (newOptions?.estimatedHeadingSize ?? newOptions?.estimatedHeadingHeight) !==\n (oldOptions?.estimatedHeadingSize ?? oldOptions?.estimatedHeadingHeight) ||\n (newOptions?.loaderSize ?? newOptions?.loaderHeight) !==\n (oldOptions?.loaderSize ?? oldOptions?.loaderHeight) ||\n newOptions.dropIndicatorThickness !== oldOptions.dropIndicatorThickness ||\n newOptions.gap !== oldOptions.gap ||\n newOptions.padding !== oldOptions.padding\n );\n }\n\n update(invalidationContext: InvalidationContext<O>): void {\n let collection = this.virtualizer!.collection;\n\n // Reset valid rect if we will have to invalidate everything.\n // Otherwise we can reuse cached layout infos outside the current visible rect.\n this.invalidateEverything = this.shouldInvalidateEverything(invalidationContext);\n if (this.invalidateEverything) {\n this.requestedRect = this.virtualizer!.visibleRect.copy();\n this.layoutNodes.clear();\n }\n\n let options = invalidationContext.layoutOptions;\n this.rowSize = options?.rowSize ?? options?.rowHeight ?? this.rowSize;\n this.orientation = options?.orientation ?? this.orientation;\n this.estimatedRowSize =\n options?.estimatedRowSize ?? options?.estimatedRowHeight ?? this.estimatedRowSize;\n this.headingSize = options?.headingSize ?? options?.headingHeight ?? this.headingSize;\n this.estimatedHeadingSize =\n options?.estimatedHeadingSize ?? options?.estimatedHeadingHeight ?? this.estimatedHeadingSize;\n this.loaderSize = options?.loaderSize ?? options?.loaderHeight ?? this.loaderSize;\n this.dropIndicatorThickness = options?.dropIndicatorThickness ?? this.dropIndicatorThickness;\n this.gap = options?.gap ?? this.gap;\n this.padding = options?.padding ?? this.padding;\n\n this.rootNodes = this.buildCollection();\n\n // Remove deleted layout nodes\n if (this.lastCollection && collection !== this.lastCollection) {\n for (let key of this.lastCollection.getKeys()) {\n if (!collection.getItem(key)) {\n let layoutNode = this.layoutNodes.get(key);\n if (layoutNode) {\n this.layoutNodes.delete(key);\n }\n }\n }\n }\n\n this.lastCollection = collection;\n this.invalidateEverything = false;\n this.validRect = this.requestedRect.copy();\n }\n\n protected buildCollection(offset: number = this.padding): LayoutNode[] {\n let collection = this.virtualizer!.collection;\n let offsetProperty = this.orientation === 'horizontal' ? 'x' : 'y';\n let maxOffsetProperty = this.orientation === 'horizontal' ? 'maxX' : 'maxY';\n\n // filter out content nodes since we don't want them to affect the height\n // Tree specific for now, if we add content nodes to other collection items, we might need to reconsider this\n let collectionNodes = toArray(collection, node => node.type !== 'content');\n let loaderNodes = collectionNodes.filter(node => node.type === 'loader');\n let nodes: LayoutNode[] = [];\n let isEmptyOrLoading = collection?.size === 0;\n if (isEmptyOrLoading) {\n offset = 0;\n }\n\n for (let node of collectionNodes) {\n let rowHeight = (this.rowSize ?? this.estimatedRowSize ?? DEFAULT_HEIGHT) + this.gap;\n // Skip rows before the valid rectangle unless they are already cached.\n if (\n node.type === 'item' &&\n offset + rowHeight < this.requestedRect[offsetProperty] &&\n !this.isValid(node, offset)\n ) {\n offset += rowHeight;\n continue;\n }\n\n let layoutNode =\n this.orientation === 'horizontal'\n ? this.buildChild(node, offset, this.padding, null)\n : this.buildChild(node, this.padding, offset, null);\n offset = layoutNode.layoutInfo.rect[maxOffsetProperty] + this.gap;\n nodes.push(layoutNode);\n if (node.type === 'loader') {\n let index = loaderNodes.indexOf(node);\n loaderNodes.splice(index, 1);\n }\n\n // Build each loader that exists in the collection that is outside the visible rect so that they are persisted\n // at the proper estimated location. If the node.type is \"section\" then we don't do this shortcut since we have to\n // build the sections to see how tall they are.\n if (\n (node.type === 'item' || node.type === 'loader') &&\n offset > this.requestedRect[maxOffsetProperty]\n ) {\n let lastProcessedIndex = collectionNodes.indexOf(node);\n for (let loaderNode of loaderNodes) {\n let loaderNodeIndex = collectionNodes.indexOf(loaderNode);\n // Subtract by an additional 1 since we've already added the current item's height to y\n offset += (loaderNodeIndex - lastProcessedIndex - 1) * rowHeight;\n let loader =\n this.orientation === 'horizontal'\n ? this.buildChild(loaderNode, offset, this.padding, null)\n : this.buildChild(loaderNode, this.padding, offset, null);\n nodes.push(loader);\n offset = loader.layoutInfo.rect[maxOffsetProperty];\n lastProcessedIndex = loaderNodeIndex;\n }\n\n // Account for the rest of the items after the last loader spinner, subtract by 1 since we've processed the current node's height already\n offset += (collectionNodes.length - lastProcessedIndex - 1) * rowHeight;\n break;\n }\n }\n\n offset = Math.max(offset - this.gap, 0);\n offset += isEmptyOrLoading ? 0 : this.padding;\n this.contentSize =\n this.orientation === 'horizontal'\n ? new Size(offset, this.virtualizer!.size.height)\n : new Size(this.virtualizer!.size.width, offset);\n\n return nodes;\n }\n\n protected isValid(node: Node<T>, offset: number): boolean {\n let cached = this.layoutNodes.get(node.key);\n let offsetProperty = this.orientation === 'horizontal' ? 'x' : 'y';\n return (\n !this.invalidateEverything &&\n !!cached &&\n cached.node === node &&\n offset === cached.layoutInfo.rect[offsetProperty] &&\n cached.layoutInfo.rect.intersects(this.validRect) &&\n cached.validRect.containsRect(cached.layoutInfo.rect.intersection(this.requestedRect))\n );\n }\n\n protected buildChild(node: Node<T>, x: number, y: number, parentKey: Key | null): LayoutNode {\n if (this.isValid(node, this.orientation === 'horizontal' ? x : y)) {\n return this.layoutNodes.get(node.key)!;\n }\n\n let layoutNode = this.buildNode(node, x, y);\n\n layoutNode.layoutInfo.parentKey = parentKey ?? null;\n layoutNode.layoutInfo.allowOverflow = true;\n this.layoutNodes.set(node.key, layoutNode);\n return layoutNode;\n }\n\n protected buildNode(node: Node<T>, x: number, y: number): LayoutNode {\n switch (node.type) {\n case 'section':\n return this.buildSection(node, x, y);\n case 'item':\n return this.buildItem(node, x, y);\n case 'header':\n return this.buildSectionHeader(node, x, y);\n case 'loader':\n return this.buildLoader(node, x, y);\n case 'separator':\n return this.buildItem(node, x, y);\n // uses buildSection instead of buildItem cuz it has a child node (the trigger)\n // that need to be processed\n case 'submenutrigger':\n return this.buildSection(node, x, y);\n default:\n throw new Error('Unsupported node type: ' + node.type);\n }\n }\n\n protected buildLoader(node: Node<T>, x: number, y: number): LayoutNode {\n let rect = new Rect(x, y, this.padding, 0);\n let layoutInfo = new LayoutInfo(node.type, node.key, rect);\n\n // Note that if the user provides isLoading to their sentinel during a case where they only want to render the emptyState, this will reserve\n // room for the loader alongside rendering the emptyState\n if (this.orientation === 'horizontal') {\n rect.height = this.virtualizer!.contentSize.height - this.padding - y;\n rect.width = node.props.isLoading\n ? (this.loaderSize ?? this.rowSize ?? this.estimatedRowSize ?? DEFAULT_HEIGHT)\n : 0;\n } else {\n rect.width = this.virtualizer!.contentSize.width - this.padding - x;\n rect.height = node.props.isLoading\n ? (this.loaderSize ?? this.rowSize ?? this.estimatedRowSize ?? DEFAULT_HEIGHT)\n : 0;\n }\n\n return {\n layoutInfo,\n validRect: rect.intersection(this.requestedRect)\n };\n }\n\n protected buildSection(node: Node<T>, x: number, y: number): LayoutNode {\n let collection = this.virtualizer!.collection;\n let width = this.virtualizer!.size.width - this.padding - x;\n let height = this.virtualizer!.size.height - this.padding - y;\n let rect =\n this.orientation === 'horizontal' ? new Rect(x, y, 0, height) : new Rect(x, y, width, 0);\n let layoutInfo = new LayoutInfo(node.type, node.key, rect);\n\n let offset = this.orientation === 'horizontal' ? x : y;\n let offsetProperty = this.orientation === 'horizontal' ? 'x' : 'y';\n let maxOffsetProperty = this.orientation === 'horizontal' ? 'maxX' : 'maxY';\n let heightProperty = this.orientation === 'horizontal' ? 'width' : 'height';\n\n let skipped = 0;\n let children: LayoutNode[] = [];\n for (let child of getChildNodes(node, collection)) {\n // skip if it is a content node, Tree specific for now, if we add content nodes to other collection items, we might need to reconsider this\n if (child.type === 'content') {\n continue;\n }\n\n let rowHeight = (this.rowSize ?? this.estimatedRowSize ?? DEFAULT_HEIGHT) + this.gap;\n\n // Skip rows before the valid rectangle unless they are already cached.\n if (offset + rowHeight < this.requestedRect[offsetProperty] && !this.isValid(node, offset)) {\n offset += rowHeight;\n skipped++;\n continue;\n }\n\n let layoutNode =\n this.orientation === 'horizontal'\n ? this.buildChild(child, offset, y, layoutInfo.key)\n : this.buildChild(child, x, offset, layoutInfo.key);\n offset = layoutNode.layoutInfo.rect[maxOffsetProperty] + this.gap;\n children.push(layoutNode);\n\n if (offset > this.requestedRect[maxOffsetProperty]) {\n // Estimate the remaining height for rows that we don't need to layout right now.\n offset +=\n ([...getChildNodes(node, collection)].length - (children.length + skipped)) * rowHeight;\n break;\n }\n }\n\n offset -= this.gap;\n rect[heightProperty] = offset - (this.orientation === 'horizontal' ? x : y);\n\n return {\n layoutInfo,\n children,\n validRect: layoutInfo.rect.intersection(this.requestedRect),\n node\n };\n }\n\n protected buildSectionHeader(node: Node<T>, x: number, y: number): LayoutNode {\n let widthProperty = this.orientation === 'horizontal' ? 'height' : 'width';\n let heightProperty = this.orientation === 'horizontal' ? 'width' : 'height';\n let width =\n this.virtualizer!.size[widthProperty] -\n this.padding -\n (this.orientation === 'horizontal' ? y : x);\n let rectHeight = this.headingSize;\n let isEstimated = false;\n\n // If no explicit height is available, use an estimated height.\n if (rectHeight == null) {\n // If a previous version of this layout info exists, reuse its height.\n // Mark as estimated if the size of the overall virtualizer changed,\n // or the content of the item changed.\n let previousLayoutNode = this.layoutNodes.get(node.key);\n let previousLayoutInfo = previousLayoutNode?.layoutInfo;\n if (previousLayoutInfo) {\n let curNode = this.virtualizer!.collection.getItem(node.key);\n let lastNode = this.lastCollection ? this.lastCollection.getItem(node.key) : null;\n rectHeight = previousLayoutNode!.layoutInfo.rect[heightProperty];\n isEstimated =\n width !== previousLayoutInfo.rect[widthProperty] ||\n curNode !== lastNode ||\n previousLayoutInfo.estimatedSize;\n } else {\n rectHeight = node.rendered ? this.estimatedHeadingSize : 0;\n isEstimated = true;\n }\n }\n\n if (rectHeight == null) {\n rectHeight = DEFAULT_HEIGHT;\n }\n\n let headerRect =\n this.orientation === 'horizontal'\n ? new Rect(x, y, rectHeight, width - y)\n : new Rect(x, y, width - x, rectHeight);\n let header = new LayoutInfo('header', node.key, headerRect);\n header.estimatedSize = isEstimated;\n return {\n layoutInfo: header,\n children: [],\n validRect: header.rect.intersection(this.requestedRect),\n node\n };\n }\n\n protected buildItem(node: Node<T>, x: number, y: number): LayoutNode {\n let widthProperty = this.orientation === 'horizontal' ? 'height' : 'width';\n let heightProperty = this.orientation === 'horizontal' ? 'width' : 'height';\n\n let width =\n this.virtualizer!.size[widthProperty] -\n this.padding -\n (this.orientation === 'horizontal' ? y : x);\n let rectHeight = this.rowSize;\n let isEstimated = false;\n\n // If no explicit height is available, use an estimated height.\n if (rectHeight == null) {\n // If a previous version of this layout info exists, reuse its height.\n // Mark as estimated if the size of the overall virtualizer changed,\n // or the content of the item changed.\n let previousLayoutNode = this.layoutNodes.get(node.key);\n if (previousLayoutNode) {\n rectHeight = previousLayoutNode.layoutInfo.rect[heightProperty];\n isEstimated =\n width !== previousLayoutNode.layoutInfo.rect[widthProperty] ||\n node !== previousLayoutNode.node ||\n previousLayoutNode.layoutInfo.estimatedSize;\n } else {\n rectHeight = this.estimatedRowSize;\n isEstimated = true;\n }\n }\n\n if (rectHeight == null) {\n rectHeight = DEFAULT_HEIGHT;\n }\n\n let rect =\n this.orientation === 'horizontal'\n ? new Rect(x, y, rectHeight, width)\n : new Rect(x, y, width, rectHeight);\n let layoutInfo = new LayoutInfo(node.type, node.key, rect);\n layoutInfo.estimatedSize = isEstimated;\n return {\n layoutInfo,\n children: [],\n validRect: layoutInfo.rect.intersection(this.requestedRect),\n node\n };\n }\n\n updateItemSize(key: Key, size: Size): boolean {\n let layoutNode = this.layoutNodes.get(key);\n // If no layoutInfo, item has been deleted/removed.\n if (!layoutNode) {\n return false;\n }\n\n let collection = this.virtualizer!.collection;\n let layoutInfo = layoutNode.layoutInfo;\n let offsetProperty = this.orientation === 'horizontal' ? 'x' : 'y';\n let heightProperty = this.orientation === 'horizontal' ? 'width' : 'height';\n layoutInfo.estimatedSize = false;\n if (layoutInfo.rect[heightProperty] !== size[heightProperty]) {\n // Copy layout info rather than mutating so that later caches are invalidated.\n let newLayoutInfo = layoutInfo.copy();\n newLayoutInfo.rect[heightProperty] = size[heightProperty];\n layoutNode.layoutInfo = newLayoutInfo;\n\n // Items after this layoutInfo will need to be repositioned to account for the new height.\n // Adjust the validRect so that only items above remain valid.\n this.validRect[heightProperty] = Math.min(\n this.validRect[heightProperty],\n layoutInfo.rect[offsetProperty] - this.validRect[offsetProperty]\n );\n\n // The requestedRect also needs to be adjusted to account for the height difference.\n if (layoutNode.node?.type === 'item') {\n this.requestedRect[heightProperty] +=\n newLayoutInfo.rect[heightProperty] - layoutInfo.rect[heightProperty];\n }\n\n // Invalidate layout for this layout node and all parents\n this.updateLayoutNode(key, layoutInfo, newLayoutInfo);\n\n let node = layoutInfo.parentKey != null ? collection.getItem(layoutInfo.parentKey) : null;\n while (node) {\n this.updateLayoutNode(node.key, layoutInfo, newLayoutInfo);\n node = node.parentKey != null ? collection.getItem(node.parentKey) : null;\n }\n\n return true;\n }\n\n return false;\n }\n\n private updateLayoutNode(key: Key, oldLayoutInfo: LayoutInfo, newLayoutInfo: LayoutInfo) {\n let n = this.layoutNodes.get(key);\n if (n) {\n // Invalidate by intersecting the validRect of this node with the overall validRect.\n n.validRect = n.validRect.intersection(this.validRect);\n\n // Replace layout info in LayoutNode\n if (n.layoutInfo === oldLayoutInfo) {\n n.layoutInfo = newLayoutInfo;\n }\n }\n }\n\n getContentSize(): Size {\n return this.contentSize;\n }\n\n getDropTargetFromPoint(\n x: number,\n y: number,\n isValidDropTarget: (target: DropTarget) => boolean\n ): DropTarget | null {\n x += this.virtualizer!.visibleRect.x;\n y += this.virtualizer!.visibleRect.y;\n\n // Find the closest item within on either side of the point using the gap width.\n let searchRect = new Rect(x, Math.max(0, y - this.gap), 1, Math.max(1, this.gap * 2));\n let candidates = this.getVisibleLayoutInfos(searchRect);\n let key: Key | null = null;\n let minDistance = Infinity;\n for (let candidate of candidates) {\n // Ignore items outside the search rect, e.g. persisted keys.\n if (!candidate.rect.intersects(searchRect)) {\n continue;\n }\n\n let yDist = Math.abs(candidate.rect.y - y);\n let maxYDist = Math.abs(candidate.rect.maxY - y);\n let dist = Math.min(yDist, maxYDist);\n if (dist < minDistance) {\n minDistance = dist;\n key = candidate.key;\n }\n }\n\n if (key == null || this.virtualizer!.collection.size === 0) {\n return {type: 'root'};\n }\n\n let layoutInfo = this.getLayoutInfo(key);\n if (!layoutInfo) {\n return null;\n }\n\n let rect = layoutInfo.rect;\n let target: DropTarget = {\n type: 'item',\n key: layoutInfo.key,\n dropPosition: 'on'\n };\n\n // If dropping on the item isn't accepted, try the target before or after depending on the y position.\n // Otherwise, if dropping on the item is accepted, still try the before/after positions if within 10px\n // of the top or bottom of the item.\n if (!isValidDropTarget(target)) {\n if (y <= rect.y + rect.height / 2 && isValidDropTarget({...target, dropPosition: 'before'})) {\n target.dropPosition = 'before';\n } else if (isValidDropTarget({...target, dropPosition: 'after'})) {\n target.dropPosition = 'after';\n }\n } else if (y <= rect.y + 10 && isValidDropTarget({...target, dropPosition: 'before'})) {\n target.dropPosition = 'before';\n } else if (y >= rect.maxY - 10 && isValidDropTarget({...target, dropPosition: 'after'})) {\n target.dropPosition = 'after';\n }\n\n return target;\n }\n\n getDropTargetLayoutInfo(target: ItemDropTarget): LayoutInfo {\n let layoutInfo = this.getLayoutInfo(target.key)!;\n let rect: Rect;\n if (target.dropPosition === 'before') {\n rect =\n this.orientation === 'horizontal'\n ? new Rect(\n Math.max(0, layoutInfo.rect.x - this.dropIndicatorThickness / 2),\n layoutInfo.rect.y,\n this.dropIndicatorThickness,\n layoutInfo.rect.height\n )\n : new Rect(\n layoutInfo.rect.x,\n Math.max(0, layoutInfo.rect.y - this.dropIndicatorThickness / 2),\n layoutInfo.rect.width,\n this.dropIndicatorThickness\n );\n } else if (target.dropPosition === 'after') {\n // Render after last visible descendant of the drop target.\n let targetNode = this.collection.getItem(target.key);\n if (targetNode) {\n let targetLevel = targetNode.level ?? 0;\n let currentKey = this.collection.getKeyAfter(target.key);\n\n while (currentKey != null) {\n let node = this.collection.getItem(currentKey);\n if (!node || node.level <= targetLevel) {\n break;\n }\n\n layoutInfo = this.getLayoutInfo(currentKey) || layoutInfo;\n currentKey = this.collection.getKeyAfter(currentKey);\n }\n }\n rect =\n this.orientation === 'horizontal'\n ? new Rect(\n layoutInfo.rect.maxX - this.dropIndicatorThickness / 2,\n layoutInfo.rect.y,\n this.dropIndicatorThickness,\n layoutInfo.rect.height\n )\n : new Rect(\n layoutInfo.rect.x,\n layoutInfo.rect.maxY - this.dropIndicatorThickness / 2,\n layoutInfo.rect.width,\n this.dropIndicatorThickness\n );\n } else {\n rect = layoutInfo.rect;\n }\n\n return new LayoutInfo('dropIndicator', target.key + ':' + target.dropPosition, rect);\n }\n}\n\nfunction toArray<T>(\n collection: Collection<Node<T>>,\n predicate: (node: Node<T>) => boolean\n): Node<T>[] {\n const result: Node<T>[] = [];\n for (const node of collection) {\n if (predicate(node)) {\n result.push(node);\n }\n }\n return result;\n}\n"],"names":[],"version":3,"file":"ListLayout.cjs.map"}
|
|
@@ -223,6 +223,10 @@ class $f46b9da090161919$export$cacbb3924155d68e extends (0, $bcf18cb0a16f75f6$ex
|
|
|
223
223
|
return this.buildLoader(node, x, y);
|
|
224
224
|
case 'separator':
|
|
225
225
|
return this.buildItem(node, x, y);
|
|
226
|
+
// uses buildSection instead of buildItem cuz it has a child node (the trigger)
|
|
227
|
+
// that need to be processed
|
|
228
|
+
case 'submenutrigger':
|
|
229
|
+
return this.buildSection(node, x, y);
|
|
226
230
|
default:
|
|
227
231
|
throw new Error('Unsupported node type: ' + node.type);
|
|
228
232
|
}
|