@react-stately/data 3.11.7-nightly.5038 → 3.11.7-nightly.5042
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/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";AAeA,6BAA6B,CAAC;IAC5B,iCAAiC;IACjC,YAAY,CAAC,EAAE,CAAC,EAAE,CAAC;IACnB,iDAAiD;IACjD,mBAAmB,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;IAC5C,8CAA8C;IAC9C,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,+DAA+D;IAC/D,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,GAAG,CAAC;IAC1B,8EAA8E;IAC9E,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAA;CAClD;AAED,0BAA0B,CAAC;IACzB,6BAA6B;IAC7B,KAAK,EAAE,CAAC,EAAE,CAAC;IAEX,4DAA4D;IAC5D,YAAY,EAAE,SAAS,CAAC;IAExB,8BAA8B;IAC9B,eAAe,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,CAAC;IAEvC,+BAA+B;IAC/B,UAAU,EAAE,MAAM,CAAC;IAEnB,4BAA4B;IAC5B,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAExC;;;OAGG;IACH,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC;IAErB;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC;IAE5C;;;;OAIG;IACH,YAAY,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,MAAM,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC;IAE7C;;;;OAIG;IACH,WAAW,CAAC,GAAG,EAAE,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AS,EAAE,GAAG,GAAG,IAAI,EAAE,GAAG,MAAM,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC;IAEpD;;;;OAIG;IACH,OAAO,CAAC,SAAS,EAAE,GAAG,GAAG,IAAI,EAAE,GAAG,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC;IAEpD;;;OAGG;IACH,MAAM,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAE7B;;;OAGG;IACH,mBAAmB,IAAI,IAAI,CAAC;IAE5B;;;;;OAKG;IACH,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAE7D;;;;OAIG;IACH,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAA;CACpC;AAED;;;GAGG;AACH,4BAA4B,CAAC,SAAS,MAAM,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAuQlF","sources":["packages/@react-stately/data/src/packages/@react-stately/data/src/useListData.ts","packages/@react-stately/data/src/packages/@react-stately/data/src/useAsyncList.ts","packages/@react-stately/data/src/packages/@react-stately/data/src/useTreeData.ts","packages/@react-stately/data/src/packages/@react-stately/data/src/index.ts","packages/@react-stately/data/src/index.ts"],"sourcesContent":[null,null,null,null,"/*\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\nexport {useAsyncList} from './useAsyncList';\nexport {useTreeData} from './useTreeData';\nexport {useListData} from './useListData';\n\nexport type {ListOptions, ListData} from './useListData';\nexport type {AsyncListOptions, AsyncListData} from './useAsyncList';\nexport type {TreeOptions, TreeData} from './useTreeData';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/dist/useTreeData.main.js
CHANGED
|
@@ -18,12 +18,16 @@ $parcel$export(module.exports, "useTreeData", () => $2d16d1aab63a81f4$export$d14
|
|
|
18
18
|
* governing permissions and limitations under the License.
|
|
19
19
|
*/
|
|
20
20
|
function $2d16d1aab63a81f4$export$d14e1352e21f4a16(options) {
|
|
21
|
-
let { initialItems: initialItems = [], initialSelectedKeys: initialSelectedKeys, getKey: getKey = (item)=>
|
|
21
|
+
let { initialItems: initialItems = [], initialSelectedKeys: initialSelectedKeys, getKey: getKey = (item)=>{
|
|
22
|
+
var _item_id;
|
|
23
|
+
return (_item_id = item.id) !== null && _item_id !== void 0 ? _item_id : item.key;
|
|
24
|
+
}, getChildren: getChildren = (item)=>item.children } = options;
|
|
22
25
|
// We only want to compute this on initial render.
|
|
23
26
|
let [tree, setItems] = (0, $aMaLn$react.useState)(()=>buildTree(initialItems, new Map()));
|
|
24
27
|
let { items: items, nodeMap: nodeMap } = tree;
|
|
25
28
|
let [selectedKeys, setSelectedKeys] = (0, $aMaLn$react.useState)(new Set(initialSelectedKeys || []));
|
|
26
29
|
function buildTree(initialItems = [], map, parentKey) {
|
|
30
|
+
if (initialItems == null) initialItems = [];
|
|
27
31
|
return {
|
|
28
32
|
items: initialItems.map((item)=>{
|
|
29
33
|
let node = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AA+GM,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,S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;oBAEA,IAAI,OAAO,UAAU,YAAY,WAAW,aAAa,KAAK,GAAG;oBACjE,KAAK,QAAQ,GAAG,KAAK,KAAK;oBAC1B,OAAO;gBACT,GAAG;QACL;IACF;AACF","sources":["packages/@react-stately/data/src/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,\n /** The value object for the tree node. */\n value: T,\n /** Children of the tree node. */\n children: TreeNode<T>[]\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 * @param key - The key of the item to retrieve.\n */\n getItem(key: Key): TreeNode<T>,\n\n /**\n * Inserts an item into a parent node as a child.\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 * @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 * @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 * @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 * @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 * @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 * @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 * Updates an item in the tree.\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\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<{items: TreeNode<T>[], nodeMap: Map<Key, TreeNode<T>>}>(() => buildTree(initialItems, new Map()));\n let {items, nodeMap} = tree;\n\n let [selectedKeys, setSelectedKeys] = useState(new Set<Key>(initialSelectedKeys || []));\n\n function buildTree(initialItems: T[] = [], map: Map<Key, TreeNode<T>>, parentKey?: Key | null) {\n return {\n items: initialItems.map(item => {\n let node: TreeNode<T> = {\n key: getKey(item),\n parentKey: parentKey,\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(items: TreeNode<T>[], key: Key, update: (node: TreeNode<T>) => TreeNode<T>, originalMap: Map<Key, TreeNode<T>>) {\n let node = originalMap.get(key);\n if (!node) {\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.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) {\n children = children.filter(c => c !== node);\n }\n\n copy.children = children.map(child => {\n if (child === node) {\n return newNode;\n }\n\n return child;\n });\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 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 for (let child of node.children) {\n addNode(child, map);\n }\n }\n\n function deleteNode(node: TreeNode<T>, map: Map<Key, TreeNode<T>>) {\n map.delete(node.key);\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, originalMap, parentKey);\n\n // If parentKey is null, insert into the root.\n if (parentKey == null) {\n return {\n items: [\n ...items.slice(0, index),\n ...newNodes,\n ...items.slice(index)\n ],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(items, parentKey, 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 }), newMap);\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, 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, 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\n const movedNode = {\n ...node,\n parentKey: toParentKey\n };\n\n // If parentKey is null, insert into the root.\n if (toParentKey == null) {\n newMap.set(movedNode.key, movedNode);\n return {items: [\n ...newItems.slice(0, index),\n movedNode,\n ...newItems.slice(index)\n ], nodeMap: newMap};\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(newItems, toParentKey, 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 }), newMap);\n });\n },\n update(oldKey: Key, newValue: T) {\n setItems(({items, nodeMap: originalMap}) => updateTree(items, oldKey, 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 }, originalMap));\n }\n };\n}\n"],"names":[],"version":3,"file":"useTreeData.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AA+GM,SAAS,0CAA8B,OAAuB;IACnE,IAAI,gBACF,eAAe,EAAE,uBACjB,mBAAmB,UACnB,SAAS,CAAC;YAAc;eAAA,CAAA,WAAA,KAAK,EAAE,cAAP,sBAAA,WAAW,KAAK,GAAG;IAAD,gBAC1C,cAAc,CAAC,OAAc,KAAK,QAAQ,EAC3C,GAAG;IAEJ,kDAAkD;IAClD,IAAI,CAAC,MAAM,SAAS,GAAG,CAAA,GAAA,qBAAO,EAA0D,IAAM,UAAU,cAAc,IAAI;IAC1H,IAAI,SAAC,KAAK,WAAE,OAAO,EAAC,GAAG;IAEvB,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,qBAAO,EAAE,IAAI,IAAS,uBAAuB,EAAE;IAErF,SAAS,UAAU,eAA2B,EAAE,EAAE,GAA0B,EAAE,SAAsB;QAClG,IAAI,gBAAgB,MAClB,eAAe,EAAE;QAEnB,OAAO;YACL,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rC,IAAI,OAAO,YAAY,GAAG,CAAC;gBAC3B,IAAI,CAAC,MACH,OAAO;2BAAC;oBAAO,SAAS;gBAAW;gBAGrC,IAAI,EAAC,OAAO,QAAQ,EAAE,SAAS,MAAM,EAAC,GAAG,WAAW,OAAO,KAAK,IAAM,MAAM;gBAG5E,MAAM,YAAY;oBAChB,GAAG,IAAI;oBACP,WAAW;gBACb;gBAEA,8CAA8C;gBAC9C,IAAI,eAAe,MAAM;oBACvB,OAAO,GAAG,CAAC,UAAU,GAAG,EAAE;oBAC1B,OAAO;wBAAC,OAAO;+BACV,SAAS,KAAK,CAAC,GAAG;4BACrB;+BACG,SAAS,KAAK,CAAC;yBACnB;wBAAE,SAAS;oBAAM;gBACpB;gBAEA,uDAAuD;gBACvD,OAAO,WAAW,UAAU,aAAa,CAAA,aAAe,CAAA;wBACtD,KAAK,WAAW,GAAG;wBACnB,WAAW,WAAW,SAAS;wBAC/B,OAAO,WAAW,KAAK;wBACvB,UAAU;+BACL,WAAW,QAAQ,CAAC,KAAK,CAAC,GAAG;4BAChC;+BACG,WAAW,QAAQ,CAAC,KAAK,CAAC;yBAC9B;oBACH,CAAA,GAAI;YACN;QACF;QACA,QAAO,MAAW,EAAE,QAAW;YAC7B,SAAS,CAAC,SAAC,KAAK,EAAE,SAAS,WAAW,EAAC,GAAK,WAAW,OAAO,QAAQ,CAAA;oBACpE,IAAI,OAAoB;wBACtB,KAAK,QAAQ,GAAG;wBAChB,WAAW,QAAQ,SAAS;wBAC5B,OAAO;wBACP,UAAU;oBACZ;oBAEA,IAAI,OAAO,UAAU,YAAY,WAAW,aAAa,KAAK,GAAG;oBACjE,KAAK,QAAQ,GAAG,KAAK,KAAK;oBAC1B,OAAO;gBACT,GAAG;QACL;IACF;AACF","sources":["packages/@react-stately/data/src/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,\n /** The value object for the tree node. */\n value: T,\n /** Children of the tree node. */\n children: TreeNode<T>[]\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 * @param key - The key of the item to retrieve.\n */\n getItem(key: Key): TreeNode<T>,\n\n /**\n * Inserts an item into a parent node as a child.\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 * @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 * @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 * @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 * @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 * @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 * @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 * Updates an item in the tree.\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\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<{items: TreeNode<T>[], nodeMap: Map<Key, TreeNode<T>>}>(() => buildTree(initialItems, new Map()));\n let {items, nodeMap} = tree;\n\n let [selectedKeys, setSelectedKeys] = useState(new Set<Key>(initialSelectedKeys || []));\n\n function buildTree(initialItems: T[] | null = [], map: Map<Key, TreeNode<T>>, parentKey?: Key | null) {\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,\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(items: TreeNode<T>[], key: Key, update: (node: TreeNode<T>) => TreeNode<T>, originalMap: Map<Key, TreeNode<T>>) {\n let node = originalMap.get(key);\n if (!node) {\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.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) {\n children = children.filter(c => c !== node);\n }\n\n copy.children = children.map(child => {\n if (child === node) {\n return newNode;\n }\n\n return child;\n });\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 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 for (let child of node.children) {\n addNode(child, map);\n }\n }\n\n function deleteNode(node: TreeNode<T>, map: Map<Key, TreeNode<T>>) {\n map.delete(node.key);\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, originalMap, parentKey);\n\n // If parentKey is null, insert into the root.\n if (parentKey == null) {\n return {\n items: [\n ...items.slice(0, index),\n ...newNodes,\n ...items.slice(index)\n ],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(items, parentKey, 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 }), newMap);\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, 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, 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\n const movedNode = {\n ...node,\n parentKey: toParentKey\n };\n\n // If parentKey is null, insert into the root.\n if (toParentKey == null) {\n newMap.set(movedNode.key, movedNode);\n return {items: [\n ...newItems.slice(0, index),\n movedNode,\n ...newItems.slice(index)\n ], nodeMap: newMap};\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(newItems, toParentKey, 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 }), newMap);\n });\n },\n update(oldKey: Key, newValue: T) {\n setItems(({items, nodeMap: originalMap}) => updateTree(items, oldKey, 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 }, originalMap));\n }\n };\n}\n"],"names":[],"version":3,"file":"useTreeData.main.js.map"}
|
package/dist/useTreeData.mjs
CHANGED
|
@@ -12,12 +12,16 @@ import {useState as $3pPTd$useState} from "react";
|
|
|
12
12
|
* governing permissions and limitations under the License.
|
|
13
13
|
*/
|
|
14
14
|
function $be2ea0343af54212$export$d14e1352e21f4a16(options) {
|
|
15
|
-
let { initialItems: initialItems = [], initialSelectedKeys: initialSelectedKeys, getKey: getKey = (item)=>
|
|
15
|
+
let { initialItems: initialItems = [], initialSelectedKeys: initialSelectedKeys, getKey: getKey = (item)=>{
|
|
16
|
+
var _item_id;
|
|
17
|
+
return (_item_id = item.id) !== null && _item_id !== void 0 ? _item_id : item.key;
|
|
18
|
+
}, getChildren: getChildren = (item)=>item.children } = options;
|
|
16
19
|
// We only want to compute this on initial render.
|
|
17
20
|
let [tree, setItems] = (0, $3pPTd$useState)(()=>buildTree(initialItems, new Map()));
|
|
18
21
|
let { items: items, nodeMap: nodeMap } = tree;
|
|
19
22
|
let [selectedKeys, setSelectedKeys] = (0, $3pPTd$useState)(new Set(initialSelectedKeys || []));
|
|
20
23
|
function buildTree(initialItems = [], map, parentKey) {
|
|
24
|
+
if (initialItems == null) initialItems = [];
|
|
21
25
|
return {
|
|
22
26
|
items: initialItems.map((item)=>{
|
|
23
27
|
let node = {
|
|
@@ -12,12 +12,16 @@ import {useState as $3pPTd$useState} from "react";
|
|
|
12
12
|
* governing permissions and limitations under the License.
|
|
13
13
|
*/
|
|
14
14
|
function $be2ea0343af54212$export$d14e1352e21f4a16(options) {
|
|
15
|
-
let { initialItems: initialItems = [], initialSelectedKeys: initialSelectedKeys, getKey: getKey = (item)=>
|
|
15
|
+
let { initialItems: initialItems = [], initialSelectedKeys: initialSelectedKeys, getKey: getKey = (item)=>{
|
|
16
|
+
var _item_id;
|
|
17
|
+
return (_item_id = item.id) !== null && _item_id !== void 0 ? _item_id : item.key;
|
|
18
|
+
}, getChildren: getChildren = (item)=>item.children } = options;
|
|
16
19
|
// We only want to compute this on initial render.
|
|
17
20
|
let [tree, setItems] = (0, $3pPTd$useState)(()=>buildTree(initialItems, new Map()));
|
|
18
21
|
let { items: items, nodeMap: nodeMap } = tree;
|
|
19
22
|
let [selectedKeys, setSelectedKeys] = (0, $3pPTd$useState)(new Set(initialSelectedKeys || []));
|
|
20
23
|
function buildTree(initialItems = [], map, parentKey) {
|
|
24
|
+
if (initialItems == null) initialItems = [];
|
|
21
25
|
return {
|
|
22
26
|
items: initialItems.map((item)=>{
|
|
23
27
|
let node = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;AAAA;;;;;;;;;;CAUC;AA+GM,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,EAA0D,IAAM,UAAU,cAAc,IAAI;IAC1H,IAAI,SAAC,KAAK,WAAE,OAAO,EAAC,GAAG;IAEvB,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,eAAO,EAAE,IAAI,IAAS,uBAAuB,EAAE;IAErF,SAAS,UAAU,eAAoB,EAAE,EAAE,GAA0B,EAAE,SAAsB;QAC3F,OAAO;YACL,OAAO,aAAa,GAAG,CAAC,CAAA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AAC;gBAC3B,IAAI,CAAC,MACH,OAAO;2BAAC;oBAAO,SAAS;gBAAW;gBAGrC,IAAI,EAAC,OAAO,QAAQ,EAAE,SAAS,MAAM,EAAC,GAAG,WAAW,OAAO,KAAK,IAAM,MAAM;gBAG5E,MAAM,YAAY;oBAChB,GAAG,IAAI;oBACP,WAAW;gBACb;gBAEA,8CAA8C;gBAC9C,IAAI,eAAe,MAAM;oBACvB,OAAO,GAAG,CAAC,UAAU,GAAG,EAAE;oBAC1B,OAAO;wBAAC,OAAO;+BACV,SAAS,KAAK,CAAC,GAAG;4BACrB;+BACG,SAAS,KAAK,CAAC;yBACnB;wBAAE,SAAS;oBAAM;gBACpB;gBAEA,uDAAuD;gBACvD,OAAO,WAAW,UAAU,aAAa,CAAA,aAAe,CAAA;wBACtD,KAAK,WAAW,GAAG;wBACnB,WAAW,WAAW,SAAS;wBAC/B,OAAO,WAAW,KAAK;wBACvB,UAAU;+BACL,WAAW,QAAQ,CAAC,KAAK,CAAC,GAAG;4BAChC;+BACG,WAAW,QAAQ,CAAC,KAAK,CAAC;yBAC9B;oBACH,CAAA,GAAI;YACN;QACF;QACA,QAAO,MAAW,EAAE,QAAW;YAC7B,SAAS,CAAC,SAAC,KAAK,EAAE,SAAS,WAAW,EAAC,GAAK,WAAW,OAAO,QAAQ,CAAA;oBACpE,IAAI,OAAoB;wBACtB,KAAK,QAAQ,GAAG;wBAChB,WAAW,QAAQ,SAAS;wBAC5B,OAAO;wBACP,UAAU;oBACZ;oBAEA,IAAI,OAAO,UAAU,YAAY,WAAW,aAAa,KAAK,GAAG;oBACjE,KAAK,QAAQ,GAAG,KAAK,KAAK;oBAC1B,OAAO;gBACT,GAAG;QACL;IACF;AACF","sources":["packages/@react-stately/data/src/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,\n /** The value object for the tree node. */\n value: T,\n /** Children of the tree node. */\n children: TreeNode<T>[]\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 * @param key - The key of the item to retrieve.\n */\n getItem(key: Key): TreeNode<T>,\n\n /**\n * Inserts an item into a parent node as a child.\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 * @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 * @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 * @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 * @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 * @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 * @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 * Updates an item in the tree.\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\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<{items: TreeNode<T>[], nodeMap: Map<Key, TreeNode<T>>}>(() => buildTree(initialItems, new Map()));\n let {items, nodeMap} = tree;\n\n let [selectedKeys, setSelectedKeys] = useState(new Set<Key>(initialSelectedKeys || []));\n\n function buildTree(initialItems: T[] = [], map: Map<Key, TreeNode<T>>, parentKey?: Key | null) {\n return {\n items: initialItems.map(item => {\n let node: TreeNode<T> = {\n key: getKey(item),\n parentKey: parentKey,\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(items: TreeNode<T>[], key: Key, update: (node: TreeNode<T>) => TreeNode<T>, originalMap: Map<Key, TreeNode<T>>) {\n let node = originalMap.get(key);\n if (!node) {\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.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) {\n children = children.filter(c => c !== node);\n }\n\n copy.children = children.map(child => {\n if (child === node) {\n return newNode;\n }\n\n return child;\n });\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 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 for (let child of node.children) {\n addNode(child, map);\n }\n }\n\n function deleteNode(node: TreeNode<T>, map: Map<Key, TreeNode<T>>) {\n map.delete(node.key);\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, originalMap, parentKey);\n\n // If parentKey is null, insert into the root.\n if (parentKey == null) {\n return {\n items: [\n ...items.slice(0, index),\n ...newNodes,\n ...items.slice(index)\n ],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(items, parentKey, 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 }), newMap);\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, 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, 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\n const movedNode = {\n ...node,\n parentKey: toParentKey\n };\n\n // If parentKey is null, insert into the root.\n if (toParentKey == null) {\n newMap.set(movedNode.key, movedNode);\n return {items: [\n ...newItems.slice(0, index),\n movedNode,\n ...newItems.slice(index)\n ], nodeMap: newMap};\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(newItems, toParentKey, 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 }), newMap);\n });\n },\n update(oldKey: Key, newValue: T) {\n setItems(({items, nodeMap: originalMap}) => updateTree(items, oldKey, 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 }, originalMap));\n }\n };\n}\n"],"names":[],"version":3,"file":"useTreeData.module.js.map"}
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;CAUC;AA+GM,SAAS,0CAA8B,OAAuB;IACnE,IAAI,gBACF,eAAe,EAAE,uBACjB,mBAAmB,UACnB,SAAS,CAAC;YAAc;eAAA,CAAA,WAAA,KAAK,EAAE,cAAP,sBAAA,WAAW,KAAK,GAAG;IAAD,gBAC1C,cAAc,CAAC,OAAc,KAAK,QAAQ,EAC3C,GAAG;IAEJ,kDAAkD;IAClD,IAAI,CAAC,MAAM,SAAS,GAAG,CAAA,GAAA,eAAO,EAA0D,IAAM,UAAU,cAAc,IAAI;IAC1H,IAAI,SAAC,KAAK,WAAE,OAAO,EAAC,GAAG;IAEvB,IAAI,CAAC,cAAc,gBAAgB,GAAG,CAAA,GAAA,eAAO,EAAE,IAAI,IAAS,uBAAuB,EAAE;IAErF,SAAS,UAAU,eAA2B,EAAE,EAAE,GAA0B,EAAE,SAAsB;QAClG,IAAI,gBAAgB,MAClB,eAAe,EAAE;QAEnB,OAAO;YACL,OAAO,aAAa,GAAG,CAAC,CAAA;gBACtB,IAAI,OAAoB;oBACtB,KAAK,OAAO;oBACZ,WAAW;oBACX,OAAO;oBACP,UAAU;gBACZ;gBAEA,KAAK,QAAQ,GAAG,UAAU,YAAY,OAAO,KAAK,KAAK,GAAG,EAAE,KAAK;gBACjE,IAAI,GAAG,CAAC,KAAK,GAAG,EAAE;gBAClB,OAAO;YACT;YACA,SAAS;QACX;IACF;IAEA,SAAS,WAAW,KAAoB,EAAE,GAAQ,EAAE,M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,GAAG,EAAE;oBAC1B,OAAO;wBAAC,OAAO;+BACV,SAAS,KAAK,CAAC,GAAG;4BACrB;+BACG,SAAS,KAAK,CAAC;yBACnB;wBAAE,SAAS;oBAAM;gBACpB;gBAEA,uDAAuD;gBACvD,OAAO,WAAW,UAAU,aAAa,CAAA,aAAe,CAAA;wBACtD,KAAK,WAAW,GAAG;wBACnB,WAAW,WAAW,SAAS;wBAC/B,OAAO,WAAW,KAAK;wBACvB,UAAU;+BACL,WAAW,QAAQ,CAAC,KAAK,CAAC,GAAG;4BAChC;+BACG,WAAW,QAAQ,CAAC,KAAK,CAAC;yBAC9B;oBACH,CAAA,GAAI;YACN;QACF;QACA,QAAO,MAAW,EAAE,QAAW;YAC7B,SAAS,CAAC,SAAC,KAAK,EAAE,SAAS,WAAW,EAAC,GAAK,WAAW,OAAO,QAAQ,CAAA;oBACpE,IAAI,OAAoB;wBACtB,KAAK,QAAQ,GAAG;wBAChB,WAAW,QAAQ,SAAS;wBAC5B,OAAO;wBACP,UAAU;oBACZ;oBAEA,IAAI,OAAO,UAAU,YAAY,WAAW,aAAa,KAAK,GAAG;oBACjE,KAAK,QAAQ,GAAG,KAAK,KAAK;oBAC1B,OAAO;gBACT,GAAG;QACL;IACF;AACF","sources":["packages/@react-stately/data/src/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,\n /** The value object for the tree node. */\n value: T,\n /** Children of the tree node. */\n children: TreeNode<T>[]\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 * @param key - The key of the item to retrieve.\n */\n getItem(key: Key): TreeNode<T>,\n\n /**\n * Inserts an item into a parent node as a child.\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 * @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 * @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 * @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 * @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 * @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 * @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 * Updates an item in the tree.\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\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<{items: TreeNode<T>[], nodeMap: Map<Key, TreeNode<T>>}>(() => buildTree(initialItems, new Map()));\n let {items, nodeMap} = tree;\n\n let [selectedKeys, setSelectedKeys] = useState(new Set<Key>(initialSelectedKeys || []));\n\n function buildTree(initialItems: T[] | null = [], map: Map<Key, TreeNode<T>>, parentKey?: Key | null) {\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,\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(items: TreeNode<T>[], key: Key, update: (node: TreeNode<T>) => TreeNode<T>, originalMap: Map<Key, TreeNode<T>>) {\n let node = originalMap.get(key);\n if (!node) {\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.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) {\n children = children.filter(c => c !== node);\n }\n\n copy.children = children.map(child => {\n if (child === node) {\n return newNode;\n }\n\n return child;\n });\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 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 for (let child of node.children) {\n addNode(child, map);\n }\n }\n\n function deleteNode(node: TreeNode<T>, map: Map<Key, TreeNode<T>>) {\n map.delete(node.key);\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, originalMap, parentKey);\n\n // If parentKey is null, insert into the root.\n if (parentKey == null) {\n return {\n items: [\n ...items.slice(0, index),\n ...newNodes,\n ...items.slice(index)\n ],\n nodeMap: newMap\n };\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(items, parentKey, 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 }), newMap);\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, 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, 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\n const movedNode = {\n ...node,\n parentKey: toParentKey\n };\n\n // If parentKey is null, insert into the root.\n if (toParentKey == null) {\n newMap.set(movedNode.key, movedNode);\n return {items: [\n ...newItems.slice(0, index),\n movedNode,\n ...newItems.slice(index)\n ], nodeMap: newMap};\n }\n\n // Otherwise, update the parent node and its ancestors.\n return updateTree(newItems, toParentKey, 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 }), newMap);\n });\n },\n update(oldKey: Key, newValue: T) {\n setItems(({items, nodeMap: originalMap}) => updateTree(items, oldKey, 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 }, originalMap));\n }\n };\n}\n"],"names":[],"version":3,"file":"useTreeData.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/data",
|
|
3
|
-
"version": "3.11.7-nightly.
|
|
3
|
+
"version": "3.11.7-nightly.5042+68403fe55",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-types/shared": "3.0.0-nightly.
|
|
25
|
+
"@react-types/shared": "3.0.0-nightly.3114+68403fe55",
|
|
26
26
|
"@swc/helpers": "^0.5.0"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "68403fe55489dce3de1b3094c957d598ad719861"
|
|
35
35
|
}
|
package/src/useTreeData.ts
CHANGED
|
@@ -123,7 +123,7 @@ export function useTreeData<T extends object>(options: TreeOptions<T>): TreeData
|
|
|
123
123
|
let {
|
|
124
124
|
initialItems = [],
|
|
125
125
|
initialSelectedKeys,
|
|
126
|
-
getKey = (item: any) => item.id
|
|
126
|
+
getKey = (item: any) => item.id ?? item.key,
|
|
127
127
|
getChildren = (item: any) => item.children
|
|
128
128
|
} = options;
|
|
129
129
|
|
|
@@ -133,7 +133,10 @@ export function useTreeData<T extends object>(options: TreeOptions<T>): TreeData
|
|
|
133
133
|
|
|
134
134
|
let [selectedKeys, setSelectedKeys] = useState(new Set<Key>(initialSelectedKeys || []));
|
|
135
135
|
|
|
136
|
-
function buildTree(initialItems: T[] = [], map: Map<Key, TreeNode<T>>, parentKey?: Key | null) {
|
|
136
|
+
function buildTree(initialItems: T[] | null = [], map: Map<Key, TreeNode<T>>, parentKey?: Key | null) {
|
|
137
|
+
if (initialItems == null) {
|
|
138
|
+
initialItems = [];
|
|
139
|
+
}
|
|
137
140
|
return {
|
|
138
141
|
items: initialItems.map(item => {
|
|
139
142
|
let node: TreeNode<T> = {
|