@elliemae/ds-tree-model 3.29.0-next.0 → 3.29.0-rc.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/cjs/DSTree.js.map +2 -2
- package/dist/cjs/Node.js.map +2 -2
- package/dist/cjs/useDSTree.js.map +2 -2
- package/dist/esm/DSTree.js.map +2 -2
- package/dist/esm/Node.js.map +2 -2
- package/dist/esm/useDSTree.js.map +2 -2
- package/dist/types/DSTree.d.ts +8 -8
- package/dist/types/Node.d.ts +3 -3
- package/dist/types/adapters/arraish-tree/useArraishAsDSTree.d.ts +3 -3
- package/dist/types/adapters/treeview/useTreeviewAsDSTree.d.ts +3 -3
- package/dist/types/useDSTree.d.ts +4 -4
- package/package.json +2 -2
package/dist/cjs/DSTree.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/DSTree.ts", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["import type { AddOptions, Item, MoveOptions, MutateOptions, RemoveOptions } from './types.js';\nimport { Node } from './Node.js';\n\nexport class DSTree<T extends Item> {\n private root: Node<T>;\n\n private _hash: number;\n\n private nodes: Record<string, Node<T>>;\n\n getUniqueId: (item: T) => string;\n\n constructor(item: T, options: { getUniqueId: (item: T) => string }) {\n this.getUniqueId = options.getUniqueId;\n this.root = new Node(item, { childIndex: 0, depth: 0, tree: this });\n this.nodes = {};\n this._hash = 0;\n\n // autocalculate a dictionary where dsId are keys and nodes are values\n // and add the tree link to each node\n this.root.walk((node) => {\n this.nodes[node.dsId] = node;\n return true;\n });\n }\n\n addNodeToNodesDictionary(node: Node<T>): void {\n // check that we have no repeated ids\n if (this.nodes[node.dsId]) {\n throw new Error(`DSTree: repeated dsId ${node.dsId}`);\n }\n\n this.nodes[node.dsId] = node;\n }\n\n removeNodeFromNodesDictionary(node: Node<T>): void {\n delete this.nodes[node.dsId];\n }\n\n get hash(): number {\n return this._hash;\n }\n\n getRoot = (): Node<T> => this.root;\n\n getNode = (id: string): Node<T> => this.nodes[id];\n\n getNodes = (): Record<string, Node<T>> => this.nodes;\n\n walk = (callback: (node: Node<T>) => boolean): void => {\n this.root.walk(callback);\n };\n\n walkParents = (callback: (node: Node<T>) => boolean): void => {\n this.root.walkParents(callback);\n };\n\n findNode = (callback: (node: Node<T>) => boolean): Node<T> | null => this.root.findNode(callback);\n\n findAllNodes = (callback: (node: Node<T>) => boolean): Node<T>[] => this.root.findAllNodes(callback);\n\n flatten = (): Node<T>[] => this.root.flatten();\n\n addNode = (item: T, options: AddOptions<T> = {}): Node<T> => {\n const { position, parent, callback } = options;\n const parentDefault = parent || this.root;\n const positionDefault = position ?? parentDefault.children.length;\n\n // create node and add it to the parent\n const node = new Node(item, {\n childIndex: positionDefault,\n depth: parentDefault.depth + 1,\n parent: parentDefault,\n tree: this,\n });\n this.getNode(parentDefault.dsId).addNode(node);\n\n // change hash\n this._hash += 1;\n\n // invoke the callback if present\n callback?.(node, this);\n\n return node;\n };\n\n removeNode = (id: string, options: RemoveOptions<T> = {}): Node<T> => {\n const node = this.getNode(id);\n if (!node) throw new Error(`Node with id ${id} not found`);\n\n node.removeNode();\n\n // change hash\n this._hash += 1;\n\n // invoke the callback if present\n options.callback?.(node, this);\n\n return node;\n };\n\n moveNode = (id: string, options: MoveOptions<T> = {}): Node<T> => {\n const removedNode = this.removeNode(id);\n const node = this.addNode(removedNode.getJson(), options);\n\n this._hash += 1;\n\n return node;\n };\n\n replaceNode = (id: string, item: T, options: MutateOptions<T> = {}): Node<T> => {\n const removedNode = this.removeNode(id);\n const node = this.addNode(item, { parent: removedNode.parent, position: removedNode.childIndex });\n\n this._hash += 1;\n\n // invoke the callback if present\n options.callback?.(node, this);\n\n return node;\n };\n\n getPath = (id: string): Node<T>[] => this.getRoot().getPath(id);\n\n getPathIds = (id: string)
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADCvB,kBAAqB;AAEd,MAAM,OAAuB;AAAA,EASlC,YAAY,MAAS,
|
|
4
|
+
"sourcesContent": ["import type { AddOptions, Item, MoveOptions, MutateOptions, RemoveOptions } from './types.js';\nimport { Node } from './Node.js';\n\nexport class DSTree<T extends Item> {\n private root: Node<T>;\n\n private _hash: number;\n\n private nodes: Record<string | number, Node<T>>;\n\n getUniqueId: (item: T) => string | number;\n\n constructor(item: T, options: { getUniqueId: (item: T) => string | number }) {\n this.getUniqueId = options.getUniqueId;\n this.root = new Node(item, { childIndex: 0, depth: 0, tree: this });\n this.nodes = {};\n this._hash = 0;\n\n // autocalculate a dictionary where dsId are keys and nodes are values\n // and add the tree link to each node\n this.root.walk((node) => {\n this.nodes[node.dsId] = node;\n return true;\n });\n }\n\n addNodeToNodesDictionary(node: Node<T>): void {\n // check that we have no repeated ids\n if (this.nodes[node.dsId]) {\n throw new Error(`DSTree: repeated dsId ${node.dsId}`);\n }\n\n this.nodes[node.dsId] = node;\n }\n\n removeNodeFromNodesDictionary(node: Node<T>): void {\n delete this.nodes[node.dsId];\n }\n\n get hash(): number {\n return this._hash;\n }\n\n getRoot = (): Node<T> => this.root;\n\n getNode = (id: string | number): Node<T> => this.nodes[id];\n\n getNodes = (): Record<string, Node<T>> => this.nodes;\n\n walk = (callback: (node: Node<T>) => boolean): void => {\n this.root.walk(callback);\n };\n\n walkParents = (callback: (node: Node<T>) => boolean): void => {\n this.root.walkParents(callback);\n };\n\n findNode = (callback: (node: Node<T>) => boolean): Node<T> | null => this.root.findNode(callback);\n\n findAllNodes = (callback: (node: Node<T>) => boolean): Node<T>[] => this.root.findAllNodes(callback);\n\n flatten = (): Node<T>[] => this.root.flatten();\n\n addNode = (item: T, options: AddOptions<T> = {}): Node<T> => {\n const { position, parent, callback } = options;\n const parentDefault = parent || this.root;\n const positionDefault = position ?? parentDefault.children.length;\n\n // create node and add it to the parent\n const node = new Node(item, {\n childIndex: positionDefault,\n depth: parentDefault.depth + 1,\n parent: parentDefault,\n tree: this,\n });\n this.getNode(parentDefault.dsId).addNode(node);\n\n // change hash\n this._hash += 1;\n\n // invoke the callback if present\n callback?.(node, this);\n\n return node;\n };\n\n removeNode = (id: string | number, options: RemoveOptions<T> = {}): Node<T> => {\n const node = this.getNode(id);\n if (!node) throw new Error(`Node with id ${id} not found`);\n\n node.removeNode();\n\n // change hash\n this._hash += 1;\n\n // invoke the callback if present\n options.callback?.(node, this);\n\n return node;\n };\n\n moveNode = (id: string | number, options: MoveOptions<T> = {}): Node<T> => {\n const removedNode = this.removeNode(id);\n const node = this.addNode(removedNode.getJson(), options);\n\n this._hash += 1;\n\n return node;\n };\n\n replaceNode = (id: string | number, item: T, options: MutateOptions<T> = {}): Node<T> => {\n const removedNode = this.removeNode(id);\n const node = this.addNode(item, { parent: removedNode.parent, position: removedNode.childIndex });\n\n this._hash += 1;\n\n // invoke the callback if present\n options.callback?.(node, this);\n\n return node;\n };\n\n getPath = (id: string | number): Node<T>[] => this.getRoot().getPath(id);\n\n getPathIds = (id: string | number) => this.getRoot().getPathIds(id);\n}\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADCvB,kBAAqB;AAEd,MAAM,OAAuB;AAAA,EASlC,YAAY,MAAS,SAAwD;AA+B7E,mBAAU,MAAe,KAAK;AAE9B,mBAAU,CAAC,OAAiC,KAAK,MAAM,EAAE;AAEzD,oBAAW,MAA+B,KAAK;AAE/C,gBAAO,CAAC,aAA+C;AACrD,WAAK,KAAK,KAAK,QAAQ;AAAA,IACzB;AAEA,uBAAc,CAAC,aAA+C;AAC5D,WAAK,KAAK,YAAY,QAAQ;AAAA,IAChC;AAEA,oBAAW,CAAC,aAAyD,KAAK,KAAK,SAAS,QAAQ;AAEhG,wBAAe,CAAC,aAAoD,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OAAwB,KAAK,QAAQ,EAAE,WAAW,EAAE;AA/GhE,SAAK,cAAc,QAAQ;AAC3B,SAAK,OAAO,IAAI,iBAAK,MAAM,EAAE,YAAY,GAAG,OAAO,GAAG,MAAM,KAAK,CAAC;AAClE,SAAK,QAAQ,CAAC;AACd,SAAK,QAAQ;AAIb,SAAK,KAAK,KAAK,CAAC,SAAS;AACvB,WAAK,MAAM,KAAK,IAAI,IAAI;AACxB,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAAA,EAEA,yBAAyB,MAAqB;AAE5C,QAAI,KAAK,MAAM,KAAK,IAAI,GAAG;AACzB,YAAM,IAAI,MAAM,yBAAyB,KAAK,MAAM;AAAA,IACtD;AAEA,SAAK,MAAM,KAAK,IAAI,IAAI;AAAA,EAC1B;AAAA,EAEA,8BAA8B,MAAqB;AACjD,WAAO,KAAK,MAAM,KAAK,IAAI;AAAA,EAC7B;AAAA,EAEA,IAAI,OAAe;AACjB,WAAO,KAAK;AAAA,EACd;AAoFF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/Node.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Node.ts", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable no-use-before-define */\n/* eslint-disable max-params */\nimport { cloneDeep, omit } from 'lodash';\nimport type { DSTree } from './DSTree.js';\nimport type { Item, NodeConstructorOptions } from './types.js';\n\nexport class Node<T extends Item> {\n dsId: string;\n\n plainItem: T;\n\n childIndex: number;\n\n depth: number;\n\n parent: Node<T> | null;\n\n children: Node<T>[];\n\n private tree!: DSTree<T>;\n\n private _hash: number;\n\n constructor(item: T, { childIndex, depth, parent, tree }: NodeConstructorOptions<T>) {\n this.dsId = tree.getUniqueId(item);\n this.childIndex = childIndex;\n this.depth = depth;\n this.parent = parent ?? null;\n this.tree = tree;\n this._hash = 0;\n\n this.children =\n item.subitems?.map(\n (subitem, index) => new Node(subitem as T, { childIndex: index, depth: depth + 1, parent: this, tree }),\n ) ?? [];\n\n // Save the item without the subitems\n this.plainItem = this.getCleanItem(item);\n }\n\n // ===========================================================================\n // INTERNAL METHODS\n // ===========================================================================\n\n fixChildIndexes = (): void => {\n for (let i = 0; i < this.children.length; i++) {\n this.children[i].childIndex = i;\n }\n this._hash += 1;\n };\n\n getCleanItem = (item: T): T => {\n const plainItem = omit(item, ['subitems']);\n return cloneDeep(plainItem as T);\n };\n\n // ===========================================================================\n // READ METHODS\n // ===========================================================================\n\n get hash(): number {\n return this._hash;\n }\n\n walk = (callback: (node: Node<T>) => boolean): void => {\n const shouldContinueWalking = callback(this);\n if (shouldContinueWalking) {\n for (const child of this.children) {\n child.walk(callback);\n }\n }\n };\n\n walkParents = (callback: (node: Node<T>) => boolean): void => {\n const shouldContinueWalking = callback(this);\n if (shouldContinueWalking && this.parent) {\n this.parent.walkParents(callback);\n }\n };\n\n findNode = (callback: (node: Node<T>) => boolean): Node<T> | null => {\n // find first node using walk\n let found: Node<T> | null = null;\n this.walk((node) => {\n // If we already found it, don't look anymore\n if (found) return false;\n\n // Otherwise keep looking\n if (callback(node)) found = node;\n return !found;\n });\n\n return found;\n };\n\n findAllNodes = (callback: (node: Node<T>) => boolean): Node<T>[] => {\n const found: Node<T>[] = [];\n this.walk((node) => {\n if (callback(node)) found.push(node);\n return true;\n });\n return found;\n };\n\n flatten = (): Node<T>[] => {\n const flattened: Node<T>[] = [];\n this.walk((node) => {\n flattened.push(node);\n return true;\n });\n return flattened;\n };\n\n getPath = (id: string): Node<T>[] => {\n const path: Node<T>[] = [];\n const node = this.tree.getNode(id);\n if (!node) return path;\n node.walkParents((parent) => {\n path.push(parent);\n return parent.dsId !== this.dsId;\n });\n return path.reverse();\n };\n\n getPathIds = (id: string)
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AC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,CAAC;AACD,aAAO;AAAA,IACT;AAEA,mBAAU,CAAC,
|
|
4
|
+
"sourcesContent": ["/* eslint-disable no-use-before-define */\n/* eslint-disable max-params */\nimport { cloneDeep, omit } from 'lodash';\nimport type { DSTree } from './DSTree.js';\nimport type { Item, NodeConstructorOptions } from './types.js';\n\nexport class Node<T extends Item> {\n dsId: string | number;\n\n plainItem: T;\n\n childIndex: number;\n\n depth: number;\n\n parent: Node<T> | null;\n\n children: Node<T>[];\n\n private tree!: DSTree<T>;\n\n private _hash: number;\n\n constructor(item: T, { childIndex, depth, parent, tree }: NodeConstructorOptions<T>) {\n this.dsId = tree.getUniqueId(item);\n this.childIndex = childIndex;\n this.depth = depth;\n this.parent = parent ?? null;\n this.tree = tree;\n this._hash = 0;\n\n this.children =\n item.subitems?.map(\n (subitem, index) => new Node(subitem as T, { childIndex: index, depth: depth + 1, parent: this, tree }),\n ) ?? [];\n\n // Save the item without the subitems\n this.plainItem = this.getCleanItem(item);\n }\n\n // ===========================================================================\n // INTERNAL METHODS\n // ===========================================================================\n\n fixChildIndexes = (): void => {\n for (let i = 0; i < this.children.length; i++) {\n this.children[i].childIndex = i;\n }\n this._hash += 1;\n };\n\n getCleanItem = (item: T): T => {\n const plainItem = omit(item, ['subitems']);\n return cloneDeep(plainItem as T);\n };\n\n // ===========================================================================\n // READ METHODS\n // ===========================================================================\n\n get hash(): number {\n return this._hash;\n }\n\n walk = (callback: (node: Node<T>) => boolean): void => {\n const shouldContinueWalking = callback(this);\n if (shouldContinueWalking) {\n for (const child of this.children) {\n child.walk(callback);\n }\n }\n };\n\n walkParents = (callback: (node: Node<T>) => boolean): void => {\n const shouldContinueWalking = callback(this);\n if (shouldContinueWalking && this.parent) {\n this.parent.walkParents(callback);\n }\n };\n\n findNode = (callback: (node: Node<T>) => boolean): Node<T> | null => {\n // find first node using walk\n let found: Node<T> | null = null;\n this.walk((node) => {\n // If we already found it, don't look anymore\n if (found) return false;\n\n // Otherwise keep looking\n if (callback(node)) found = node;\n return !found;\n });\n\n return found;\n };\n\n findAllNodes = (callback: (node: Node<T>) => boolean): Node<T>[] => {\n const found: Node<T>[] = [];\n this.walk((node) => {\n if (callback(node)) found.push(node);\n return true;\n });\n return found;\n };\n\n flatten = (): Node<T>[] => {\n const flattened: Node<T>[] = [];\n this.walk((node) => {\n flattened.push(node);\n return true;\n });\n return flattened;\n };\n\n getPath = (id: string | number): Node<T>[] => {\n const path: Node<T>[] = [];\n const node = this.tree.getNode(id);\n if (!node) return path;\n node.walkParents((parent) => {\n path.push(parent);\n return parent.dsId !== this.dsId;\n });\n return path.reverse();\n };\n\n getPathIds = (id: string | number) => this.getPath(id).map((node) => node.dsId);\n\n getJson = (): T => ({\n ...this.plainItem,\n subitems: this.children.map((child) => child.getJson()),\n });\n\n // ===========================================================================\n // WRITE METHODS\n // ===========================================================================\n\n addNode = (node: Node<T>) => {\n // check that the position is valid for that parent\n const position = node.childIndex;\n if (position < 0 || position > this.children.length) {\n throw new Error(`Invalid position ${position} for parent ${this.dsId} with item ${node.dsId}`);\n }\n\n // add the new node\n this.children.splice(position, 0, node);\n\n // fix the childIndex of the nodes after the new one\n this.fixChildIndexes();\n\n // add subtree of the new node to the node dictionary\n node.walk((child) => {\n this.tree.addNodeToNodesDictionary(child);\n return true;\n });\n\n this._hash += 1;\n };\n\n removeNode = () => {\n // if no parent throw error\n if (!this.parent) throw new Error(`Cannot remove root node with id ${this.dsId}`);\n\n // remove from parent\n this.parent.children.splice(this.childIndex, 1);\n\n // fix the childIndex of the nodes of the parent\n this.parent.fixChildIndexes();\n\n // remove subtree from the node dictionary\n this.walk((child) => {\n this.tree.removeNodeFromNodesDictionary(child);\n return true;\n });\n\n this._hash += 1;\n };\n}\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADEvB,oBAAgC;AAIzB,MAAM,KAAqB;AAAA,EAi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O;AACZ,SAAK,QAAQ;AAEb,SAAK,WACH,KAAK,UAAU;AAAA,MACb,CAAC,SAAS,UAAU,IAAI,KAAK,SAAc,EAAE,YAAY,OAAO,OAAO,QAAQ,GAAG,QAAQ,MAAM,KAAK,CAAC;AAAA,IACxG,KAAK,CAAC;AAGR,SAAK,YAAY,KAAK,aAAa,IAAI;AAAA,EACzC;AAAA;AAAA;AAAA;AAAA,EAsBA,IAAI,OAAe;AACjB,WAAO,KAAK;AAAA,EACd;AAiHF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/useDSTree.ts", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["import { useCallback, useMemo, useState } from 'react';\nimport { DSTree } from './DSTree.js';\nimport type { AddOptions, Item, MoveOptions, MutateOptions, RemoveOptions } from './types.js';\n\nexport const useDSTree = <T extends Item>(rootItem: T, opts: { getUniqueId: (item: T) => string }) => {\n const tree = useMemo(() => new DSTree(rootItem, opts), [opts, rootItem]);\n const [hash, setHash] = useState(tree.hash);\n\n const addNode = useCallback(\n (item: T, options?: AddOptions<T>) => {\n const cb: AddOptions<T>['callback'] = (node, treecb) => {\n options?.callback?.(node, treecb);\n setHash(treecb.hash);\n };\n return tree.addNode(item, { ...options, callback: cb });\n },\n [tree],\n );\n\n const removeNode = useCallback(\n (id: string, options?: RemoveOptions<T>) => {\n const cb: RemoveOptions<T>['callback'] = (node, treecb) => {\n options?.callback?.(node, treecb);\n setHash(treecb.hash);\n };\n return tree.removeNode(id, { ...options, callback: cb });\n },\n [tree],\n );\n\n const moveNode = useCallback(\n (id: string, options?: MoveOptions<T>) => {\n const cb: MoveOptions<T>['callback'] = (node, treecb) => {\n options?.callback?.(node, treecb);\n setHash(treecb.hash);\n };\n return tree.moveNode(id, { ...options, callback: cb });\n },\n [tree],\n );\n\n const replaceNode = useCallback(\n (id: string, item: T, options?: MutateOptions<T>) => {\n const cb: MutateOptions<T>['callback'] = (node, treecb) => {\n options?.callback?.(node, treecb);\n setHash(treecb.hash);\n };\n return tree.replaceNode(id, item, { ...options, callback: cb });\n },\n [tree],\n );\n\n return {\n hash,\n getRoot: tree.getRoot,\n getNode: tree.getNode,\n walk: tree.walk,\n walkParents: tree.walkParents,\n findNode: tree.findNode,\n findAllNodes: tree.findAllNodes,\n flatten: tree.flatten,\n addNode,\n removeNode,\n moveNode,\n replaceNode,\n getPath: tree.getPath,\n getPathIds: tree.getPathIds,\n };\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,mBAA+C;AAC/C,oBAAuB;AAGhB,MAAM,YAAY,CAAiB,UAAa,
|
|
4
|
+
"sourcesContent": ["import { useCallback, useMemo, useState } from 'react';\nimport { DSTree } from './DSTree.js';\nimport type { AddOptions, Item, MoveOptions, MutateOptions, RemoveOptions } from './types.js';\n\nexport const useDSTree = <T extends Item>(rootItem: T, opts: { getUniqueId: (item: T) => string | number }) => {\n const tree = useMemo(() => new DSTree(rootItem, opts), [opts, rootItem]);\n const [hash, setHash] = useState(tree.hash);\n\n const addNode = useCallback(\n (item: T, options?: AddOptions<T>) => {\n const cb: AddOptions<T>['callback'] = (node, treecb) => {\n options?.callback?.(node, treecb);\n setHash(treecb.hash);\n };\n return tree.addNode(item, { ...options, callback: cb });\n },\n [tree],\n );\n\n const removeNode = useCallback(\n (id: string, options?: RemoveOptions<T>) => {\n const cb: RemoveOptions<T>['callback'] = (node, treecb) => {\n options?.callback?.(node, treecb);\n setHash(treecb.hash);\n };\n return tree.removeNode(id, { ...options, callback: cb });\n },\n [tree],\n );\n\n const moveNode = useCallback(\n (id: string, options?: MoveOptions<T>) => {\n const cb: MoveOptions<T>['callback'] = (node, treecb) => {\n options?.callback?.(node, treecb);\n setHash(treecb.hash);\n };\n return tree.moveNode(id, { ...options, callback: cb });\n },\n [tree],\n );\n\n const replaceNode = useCallback(\n (id: string, item: T, options?: MutateOptions<T>) => {\n const cb: MutateOptions<T>['callback'] = (node, treecb) => {\n options?.callback?.(node, treecb);\n setHash(treecb.hash);\n };\n return tree.replaceNode(id, item, { ...options, callback: cb });\n },\n [tree],\n );\n\n return {\n hash,\n getRoot: tree.getRoot,\n getNode: tree.getNode,\n walk: tree.walk,\n walkParents: tree.walkParents,\n findNode: tree.findNode,\n findAllNodes: tree.findAllNodes,\n flatten: tree.flatten,\n addNode,\n removeNode,\n moveNode,\n replaceNode,\n getPath: tree.getPath,\n getPathIds: tree.getPathIds,\n };\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,mBAA+C;AAC/C,oBAAuB;AAGhB,MAAM,YAAY,CAAiB,UAAa,SAAwD;AAC7G,QAAM,WAAO,sBAAQ,MAAM,IAAI,qBAAO,UAAU,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC;AACvE,QAAM,CAAC,MAAM,OAAO,QAAI,uBAAS,KAAK,IAAI;AAE1C,QAAM,cAAU;AAAA,IACd,CAAC,MAAS,YAA4B;AACpC,YAAM,KAAgC,CAAC,MAAM,WAAW;AACtD,iBAAS,WAAW,MAAM,MAAM;AAChC,gBAAQ,OAAO,IAAI;AAAA,MACrB;AACA,aAAO,KAAK,QAAQ,MAAM,EAAE,GAAG,SAAS,UAAU,GAAG,CAAC;AAAA,IACxD;AAAA,IACA,CAAC,IAAI;AAAA,EACP;AAEA,QAAM,iBAAa;AAAA,IACjB,CAAC,IAAY,YAA+B;AAC1C,YAAM,KAAmC,CAAC,MAAM,WAAW;AACzD,iBAAS,WAAW,MAAM,MAAM;AAChC,gBAAQ,OAAO,IAAI;AAAA,MACrB;AACA,aAAO,KAAK,WAAW,IAAI,EAAE,GAAG,SAAS,UAAU,GAAG,CAAC;AAAA,IACzD;AAAA,IACA,CAAC,IAAI;AAAA,EACP;AAEA,QAAM,eAAW;AAAA,IACf,CAAC,IAAY,YAA6B;AACxC,YAAM,KAAiC,CAAC,MAAM,WAAW;AACvD,iBAAS,WAAW,MAAM,MAAM;AAChC,gBAAQ,OAAO,IAAI;AAAA,MACrB;AACA,aAAO,KAAK,SAAS,IAAI,EAAE,GAAG,SAAS,UAAU,GAAG,CAAC;AAAA,IACvD;AAAA,IACA,CAAC,IAAI;AAAA,EACP;AAEA,QAAM,kBAAc;AAAA,IAClB,CAAC,IAAY,MAAS,YAA+B;AACnD,YAAM,KAAmC,CAAC,MAAM,WAAW;AACzD,iBAAS,WAAW,MAAM,MAAM;AAChC,gBAAQ,OAAO,IAAI;AAAA,MACrB;AACA,aAAO,KAAK,YAAY,IAAI,MAAM,EAAE,GAAG,SAAS,UAAU,GAAG,CAAC;AAAA,IAChE;AAAA,IACA,CAAC,IAAI;AAAA,EACP;AAEA,SAAO;AAAA,IACL;AAAA,IACA,SAAS,KAAK;AAAA,IACd,SAAS,KAAK;AAAA,IACd,MAAM,KAAK;AAAA,IACX,aAAa,KAAK;AAAA,IAClB,UAAU,KAAK;AAAA,IACf,cAAc,KAAK;AAAA,IACnB,SAAS,KAAK;AAAA,IACd;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS,KAAK;AAAA,IACd,YAAY,KAAK;AAAA,EACnB;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/DSTree.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/DSTree.ts"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import type { AddOptions, Item, MoveOptions, MutateOptions, RemoveOptions } from './types.js';\nimport { Node } from './Node.js';\n\nexport class DSTree<T extends Item> {\n private root: Node<T>;\n\n private _hash: number;\n\n private nodes: Record<string, Node<T>>;\n\n getUniqueId: (item: T) => string;\n\n constructor(item: T, options: { getUniqueId: (item: T) => string }) {\n this.getUniqueId = options.getUniqueId;\n this.root = new Node(item, { childIndex: 0, depth: 0, tree: this });\n this.nodes = {};\n this._hash = 0;\n\n // autocalculate a dictionary where dsId are keys and nodes are values\n // and add the tree link to each node\n this.root.walk((node) => {\n this.nodes[node.dsId] = node;\n return true;\n });\n }\n\n addNodeToNodesDictionary(node: Node<T>): void {\n // check that we have no repeated ids\n if (this.nodes[node.dsId]) {\n throw new Error(`DSTree: repeated dsId ${node.dsId}`);\n }\n\n this.nodes[node.dsId] = node;\n }\n\n removeNodeFromNodesDictionary(node: Node<T>): void {\n delete this.nodes[node.dsId];\n }\n\n get hash(): number {\n return this._hash;\n }\n\n getRoot = (): Node<T> => this.root;\n\n getNode = (id: string): Node<T> => this.nodes[id];\n\n getNodes = (): Record<string, Node<T>> => this.nodes;\n\n walk = (callback: (node: Node<T>) => boolean): void => {\n this.root.walk(callback);\n };\n\n walkParents = (callback: (node: Node<T>) => boolean): void => {\n this.root.walkParents(callback);\n };\n\n findNode = (callback: (node: Node<T>) => boolean): Node<T> | null => this.root.findNode(callback);\n\n findAllNodes = (callback: (node: Node<T>) => boolean): Node<T>[] => this.root.findAllNodes(callback);\n\n flatten = (): Node<T>[] => this.root.flatten();\n\n addNode = (item: T, options: AddOptions<T> = {}): Node<T> => {\n const { position, parent, callback } = options;\n const parentDefault = parent || this.root;\n const positionDefault = position ?? parentDefault.children.length;\n\n // create node and add it to the parent\n const node = new Node(item, {\n childIndex: positionDefault,\n depth: parentDefault.depth + 1,\n parent: parentDefault,\n tree: this,\n });\n this.getNode(parentDefault.dsId).addNode(node);\n\n // change hash\n this._hash += 1;\n\n // invoke the callback if present\n callback?.(node, this);\n\n return node;\n };\n\n removeNode = (id: string, options: RemoveOptions<T> = {}): Node<T> => {\n const node = this.getNode(id);\n if (!node) throw new Error(`Node with id ${id} not found`);\n\n node.removeNode();\n\n // change hash\n this._hash += 1;\n\n // invoke the callback if present\n options.callback?.(node, this);\n\n return node;\n };\n\n moveNode = (id: string, options: MoveOptions<T> = {}): Node<T> => {\n const removedNode = this.removeNode(id);\n const node = this.addNode(removedNode.getJson(), options);\n\n this._hash += 1;\n\n return node;\n };\n\n replaceNode = (id: string, item: T, options: MutateOptions<T> = {}): Node<T> => {\n const removedNode = this.removeNode(id);\n const node = this.addNode(item, { parent: removedNode.parent, position: removedNode.childIndex });\n\n this._hash += 1;\n\n // invoke the callback if present\n options.callback?.(node, this);\n\n return node;\n };\n\n getPath = (id: string): Node<T>[] => this.getRoot().getPath(id);\n\n getPathIds = (id: string)
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACCvB,SAAS,YAAY;AAEd,MAAM,OAAuB;AAAA,EASlC,YAAY,MAAS,
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import type { AddOptions, Item, MoveOptions, MutateOptions, RemoveOptions } from './types.js';\nimport { Node } from './Node.js';\n\nexport class DSTree<T extends Item> {\n private root: Node<T>;\n\n private _hash: number;\n\n private nodes: Record<string | number, Node<T>>;\n\n getUniqueId: (item: T) => string | number;\n\n constructor(item: T, options: { getUniqueId: (item: T) => string | number }) {\n this.getUniqueId = options.getUniqueId;\n this.root = new Node(item, { childIndex: 0, depth: 0, tree: this });\n this.nodes = {};\n this._hash = 0;\n\n // autocalculate a dictionary where dsId are keys and nodes are values\n // and add the tree link to each node\n this.root.walk((node) => {\n this.nodes[node.dsId] = node;\n return true;\n });\n }\n\n addNodeToNodesDictionary(node: Node<T>): void {\n // check that we have no repeated ids\n if (this.nodes[node.dsId]) {\n throw new Error(`DSTree: repeated dsId ${node.dsId}`);\n }\n\n this.nodes[node.dsId] = node;\n }\n\n removeNodeFromNodesDictionary(node: Node<T>): void {\n delete this.nodes[node.dsId];\n }\n\n get hash(): number {\n return this._hash;\n }\n\n getRoot = (): Node<T> => this.root;\n\n getNode = (id: string | number): Node<T> => this.nodes[id];\n\n getNodes = (): Record<string, Node<T>> => this.nodes;\n\n walk = (callback: (node: Node<T>) => boolean): void => {\n this.root.walk(callback);\n };\n\n walkParents = (callback: (node: Node<T>) => boolean): void => {\n this.root.walkParents(callback);\n };\n\n findNode = (callback: (node: Node<T>) => boolean): Node<T> | null => this.root.findNode(callback);\n\n findAllNodes = (callback: (node: Node<T>) => boolean): Node<T>[] => this.root.findAllNodes(callback);\n\n flatten = (): Node<T>[] => this.root.flatten();\n\n addNode = (item: T, options: AddOptions<T> = {}): Node<T> => {\n const { position, parent, callback } = options;\n const parentDefault = parent || this.root;\n const positionDefault = position ?? parentDefault.children.length;\n\n // create node and add it to the parent\n const node = new Node(item, {\n childIndex: positionDefault,\n depth: parentDefault.depth + 1,\n parent: parentDefault,\n tree: this,\n });\n this.getNode(parentDefault.dsId).addNode(node);\n\n // change hash\n this._hash += 1;\n\n // invoke the callback if present\n callback?.(node, this);\n\n return node;\n };\n\n removeNode = (id: string | number, options: RemoveOptions<T> = {}): Node<T> => {\n const node = this.getNode(id);\n if (!node) throw new Error(`Node with id ${id} not found`);\n\n node.removeNode();\n\n // change hash\n this._hash += 1;\n\n // invoke the callback if present\n options.callback?.(node, this);\n\n return node;\n };\n\n moveNode = (id: string | number, options: MoveOptions<T> = {}): Node<T> => {\n const removedNode = this.removeNode(id);\n const node = this.addNode(removedNode.getJson(), options);\n\n this._hash += 1;\n\n return node;\n };\n\n replaceNode = (id: string | number, item: T, options: MutateOptions<T> = {}): Node<T> => {\n const removedNode = this.removeNode(id);\n const node = this.addNode(item, { parent: removedNode.parent, position: removedNode.childIndex });\n\n this._hash += 1;\n\n // invoke the callback if present\n options.callback?.(node, this);\n\n return node;\n };\n\n getPath = (id: string | number): Node<T>[] => this.getRoot().getPath(id);\n\n getPathIds = (id: string | number) => this.getRoot().getPathIds(id);\n}\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;AC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AAQ,GAAG,OAAO;AAExD,WAAK,SAAS;AAEd,aAAO;AAAA,IACT;AAEA,uBAAc,CAAC,IAAqB,MAAS,UAA4B,CAAC,MAAe;AACvF,YAAM,cAAc,KAAK,WAAW,EAAE;AACtC,YAAM,OAAO,KAAK,QAAQ,MAAM,EAAE,QAAQ,YAAY,QAAQ,UAAU,YAAY,WAAW,CAAC;AAEhG,WAAK,SAAS;AAGd,cAAQ,WAAW,MAAM,IAAI;AAE7B,aAAO;AAAA,IACT;AAEA,mBAAU,CAAC,OAAmC,KAAK,QAAQ,EAAE,QAAQ,EAAE;AAEvE,sBAAa,CAAC,OAAwB,KAAK,QAAQ,EAAE,WAAW,EAAE;AA/GhE,SAAK,cAAc,QAAQ;AAC3B,SAAK,OAAO,IAAI,KAAK,MAAM,EAAE,YAAY,GAAG,OAAO,GAAG,MAAM,KAAK,CAAC;AAClE,SAAK,QAAQ,CAAC;AACd,SAAK,QAAQ;AAIb,SAAK,KAAK,KAAK,CAAC,SAAS;AACvB,WAAK,MAAM,KAAK,IAAI,IAAI;AACxB,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAAA,EAEA,yBAAyB,MAAqB;AAE5C,QAAI,KAAK,MAAM,KAAK,IAAI,GAAG;AACzB,YAAM,IAAI,MAAM,yBAAyB,KAAK,MAAM;AAAA,IACtD;AAEA,SAAK,MAAM,KAAK,IAAI,IAAI;AAAA,EAC1B;AAAA,EAEA,8BAA8B,MAAqB;AACjD,WAAO,KAAK,MAAM,KAAK,IAAI;AAAA,EAC7B;AAAA,EAEA,IAAI,OAAe;AACjB,WAAO,KAAK;AAAA,EACd;AAoFF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/Node.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/Node.ts"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable no-use-before-define */\n/* eslint-disable max-params */\nimport { cloneDeep, omit } from 'lodash';\nimport type { DSTree } from './DSTree.js';\nimport type { Item, NodeConstructorOptions } from './types.js';\n\nexport class Node<T extends Item> {\n dsId: string;\n\n plainItem: T;\n\n childIndex: number;\n\n depth: number;\n\n parent: Node<T> | null;\n\n children: Node<T>[];\n\n private tree!: DSTree<T>;\n\n private _hash: number;\n\n constructor(item: T, { childIndex, depth, parent, tree }: NodeConstructorOptions<T>) {\n this.dsId = tree.getUniqueId(item);\n this.childIndex = childIndex;\n this.depth = depth;\n this.parent = parent ?? null;\n this.tree = tree;\n this._hash = 0;\n\n this.children =\n item.subitems?.map(\n (subitem, index) => new Node(subitem as T, { childIndex: index, depth: depth + 1, parent: this, tree }),\n ) ?? [];\n\n // Save the item without the subitems\n this.plainItem = this.getCleanItem(item);\n }\n\n // ===========================================================================\n // INTERNAL METHODS\n // ===========================================================================\n\n fixChildIndexes = (): void => {\n for (let i = 0; i < this.children.length; i++) {\n this.children[i].childIndex = i;\n }\n this._hash += 1;\n };\n\n getCleanItem = (item: T): T => {\n const plainItem = omit(item, ['subitems']);\n return cloneDeep(plainItem as T);\n };\n\n // ===========================================================================\n // READ METHODS\n // ===========================================================================\n\n get hash(): number {\n return this._hash;\n }\n\n walk = (callback: (node: Node<T>) => boolean): void => {\n const shouldContinueWalking = callback(this);\n if (shouldContinueWalking) {\n for (const child of this.children) {\n child.walk(callback);\n }\n }\n };\n\n walkParents = (callback: (node: Node<T>) => boolean): void => {\n const shouldContinueWalking = callback(this);\n if (shouldContinueWalking && this.parent) {\n this.parent.walkParents(callback);\n }\n };\n\n findNode = (callback: (node: Node<T>) => boolean): Node<T> | null => {\n // find first node using walk\n let found: Node<T> | null = null;\n this.walk((node) => {\n // If we already found it, don't look anymore\n if (found) return false;\n\n // Otherwise keep looking\n if (callback(node)) found = node;\n return !found;\n });\n\n return found;\n };\n\n findAllNodes = (callback: (node: Node<T>) => boolean): Node<T>[] => {\n const found: Node<T>[] = [];\n this.walk((node) => {\n if (callback(node)) found.push(node);\n return true;\n });\n return found;\n };\n\n flatten = (): Node<T>[] => {\n const flattened: Node<T>[] = [];\n this.walk((node) => {\n flattened.push(node);\n return true;\n });\n return flattened;\n };\n\n getPath = (id: string): Node<T>[] => {\n const path: Node<T>[] = [];\n const node = this.tree.getNode(id);\n if (!node) return path;\n node.walkParents((parent) => {\n path.push(parent);\n return parent.dsId !== this.dsId;\n });\n return path.reverse();\n };\n\n getPathIds = (id: string)
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACEvB,SAAS,WAAW,YAAY;AAIzB,MAAM,KAAqB;AAAA,EAiBhC,YAAY,MAAS,EAAE,YAAY,OAAO,QAAQ,KAAK,GAA8B;AAqBrF;AAAA;AAAA;AAAA,2BAAkB,MAAY;AAC5B,eAAS,IAAI,GAAG,IAAI,KAAK,SAAS,QAAQ,KAAK;AAC7C,aAAK,SAAS,CAAC,EAAE,aAAa;AAAA,MAChC;AACA,WAAK,SAAS;AAAA,IAChB;AAEA,wBAAe,CAAC,SAAe;AAC7B,YAAM,YAAY,KAAK,MAAM,CAAC,UAAU,CAAC;AACzC,aAAO,UAAU,SAAc;AAAA,IACjC;AAUA,gBAAO,CAAC,aAA+C;AACrD,YAAM,wBAAwB,SAAS,IAAI;AAC3C,UAAI,uBAAuB;AACzB,mBAAW,SAAS,KAAK,UAAU;AACjC,gBAAM,KAAK,QAAQ;AAAA,QACrB;AAAA,MACF;AAAA,IACF;AAEA,uBAAc,CAAC,aAA+C;AAC5D,YAAM,wBAAwB,SAAS,IAAI;AAC3C,UAAI,yBAAyB,KAAK,QAAQ;AACxC,aAAK,OAAO,YAAY,QAAQ;AAAA,MAClC;AAAA,IACF;AAEA,oBAAW,CAAC,aAAyD;AAEnE,UAAI,QAAwB;AAC5B,WAAK,KAAK,CAAC,SAAS;AAElB,YAAI;AAAO,iBAAO;AAGlB,YAAI,SAAS,IAAI;AAAG,kBAAQ;AAC5B,eAAO,CAAC;AAAA,MACV,CAAC;AAED,aAAO;AAAA,IACT;AAEA,wBAAe,CAAC,aAAoD;AAClE,YAAM,QAAmB,CAAC;AAC1B,WAAK,KAAK,CAAC,SAAS;AAClB,YAAI,SAAS,IAAI;AAAG,gBAAM,KAAK,IAAI;AACnC,eAAO;AAAA,MACT,CAAC;AACD,aAAO;AAAA,IACT;AAEA,mBAAU,MAAiB;AACzB,YAAM,YAAuB,CAAC;AAC9B,WAAK,KAAK,CAAC,SAAS;AAClB,kBAAU,KAAK,IAAI;AACnB,eAAO;AAAA,MACT,CAAC;AACD,aAAO;AAAA,IACT;AAEA,mBAAU,CAAC,
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable no-use-before-define */\n/* eslint-disable max-params */\nimport { cloneDeep, omit } from 'lodash';\nimport type { DSTree } from './DSTree.js';\nimport type { Item, NodeConstructorOptions } from './types.js';\n\nexport class Node<T extends Item> {\n dsId: string | number;\n\n plainItem: T;\n\n childIndex: number;\n\n depth: number;\n\n parent: Node<T> | null;\n\n children: Node<T>[];\n\n private tree!: DSTree<T>;\n\n private _hash: number;\n\n constructor(item: T, { childIndex, depth, parent, tree }: NodeConstructorOptions<T>) {\n this.dsId = tree.getUniqueId(item);\n this.childIndex = childIndex;\n this.depth = depth;\n this.parent = parent ?? null;\n this.tree = tree;\n this._hash = 0;\n\n this.children =\n item.subitems?.map(\n (subitem, index) => new Node(subitem as T, { childIndex: index, depth: depth + 1, parent: this, tree }),\n ) ?? [];\n\n // Save the item without the subitems\n this.plainItem = this.getCleanItem(item);\n }\n\n // ===========================================================================\n // INTERNAL METHODS\n // ===========================================================================\n\n fixChildIndexes = (): void => {\n for (let i = 0; i < this.children.length; i++) {\n this.children[i].childIndex = i;\n }\n this._hash += 1;\n };\n\n getCleanItem = (item: T): T => {\n const plainItem = omit(item, ['subitems']);\n return cloneDeep(plainItem as T);\n };\n\n // ===========================================================================\n // READ METHODS\n // ===========================================================================\n\n get hash(): number {\n return this._hash;\n }\n\n walk = (callback: (node: Node<T>) => boolean): void => {\n const shouldContinueWalking = callback(this);\n if (shouldContinueWalking) {\n for (const child of this.children) {\n child.walk(callback);\n }\n }\n };\n\n walkParents = (callback: (node: Node<T>) => boolean): void => {\n const shouldContinueWalking = callback(this);\n if (shouldContinueWalking && this.parent) {\n this.parent.walkParents(callback);\n }\n };\n\n findNode = (callback: (node: Node<T>) => boolean): Node<T> | null => {\n // find first node using walk\n let found: Node<T> | null = null;\n this.walk((node) => {\n // If we already found it, don't look anymore\n if (found) return false;\n\n // Otherwise keep looking\n if (callback(node)) found = node;\n return !found;\n });\n\n return found;\n };\n\n findAllNodes = (callback: (node: Node<T>) => boolean): Node<T>[] => {\n const found: Node<T>[] = [];\n this.walk((node) => {\n if (callback(node)) found.push(node);\n return true;\n });\n return found;\n };\n\n flatten = (): Node<T>[] => {\n const flattened: Node<T>[] = [];\n this.walk((node) => {\n flattened.push(node);\n return true;\n });\n return flattened;\n };\n\n getPath = (id: string | number): Node<T>[] => {\n const path: Node<T>[] = [];\n const node = this.tree.getNode(id);\n if (!node) return path;\n node.walkParents((parent) => {\n path.push(parent);\n return parent.dsId !== this.dsId;\n });\n return path.reverse();\n };\n\n getPathIds = (id: string | number) => this.getPath(id).map((node) => node.dsId);\n\n getJson = (): T => ({\n ...this.plainItem,\n subitems: this.children.map((child) => child.getJson()),\n });\n\n // ===========================================================================\n // WRITE METHODS\n // ===========================================================================\n\n addNode = (node: Node<T>) => {\n // check that the position is valid for that parent\n const position = node.childIndex;\n if (position < 0 || position > this.children.length) {\n throw new Error(`Invalid position ${position} for parent ${this.dsId} with item ${node.dsId}`);\n }\n\n // add the new node\n this.children.splice(position, 0, node);\n\n // fix the childIndex of the nodes after the new one\n this.fixChildIndexes();\n\n // add subtree of the new node to the node dictionary\n node.walk((child) => {\n this.tree.addNodeToNodesDictionary(child);\n return true;\n });\n\n this._hash += 1;\n };\n\n removeNode = () => {\n // if no parent throw error\n if (!this.parent) throw new Error(`Cannot remove root node with id ${this.dsId}`);\n\n // remove from parent\n this.parent.children.splice(this.childIndex, 1);\n\n // fix the childIndex of the nodes of the parent\n this.parent.fixChildIndexes();\n\n // remove subtree from the node dictionary\n this.walk((child) => {\n this.tree.removeNodeFromNodesDictionary(child);\n return true;\n });\n\n this._hash += 1;\n };\n}\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACEvB,SAAS,WAAW,YAAY;AAIzB,MAAM,KAAqB;AAAA,EAiBhC,YAAY,MAAS,EAAE,YAAY,OAAO,QAAQ,KAAK,GAA8B;AAqBrF;AAAA;AAAA;AAAA,2BAAkB,MAAY;AAC5B,eAAS,IAAI,GAAG,IAAI,KAAK,SAAS,QAAQ,KAAK;AAC7C,aAAK,SAAS,CAAC,EAAE,aAAa;AAAA,MAChC;AACA,WAAK,SAAS;AAAA,IAChB;AAEA,wBAAe,CAAC,SAAe;AAC7B,YAAM,YAAY,KAAK,MAAM,CAAC,UAAU,CAAC;AACzC,aAAO,UAAU,SAAc;AAAA,IACjC;AAUA,gBAAO,CAAC,aAA+C;AACrD,YAAM,wBAAwB,SAAS,IAAI;AAC3C,UAAI,uBAAuB;AACzB,mBAAW,SAAS,KAAK,UAAU;AACjC,gBAAM,KAAK,QAAQ;AAAA,QACrB;AAAA,MACF;AAAA,IACF;AAEA,uBAAc,CAAC,aAA+C;AAC5D,YAAM,wBAAwB,SAAS,IAAI;AAC3C,UAAI,yBAAyB,KAAK,QAAQ;AACxC,aAAK,OAAO,YAAY,QAAQ;AAAA,MAClC;AAAA,IACF;AAEA,oBAAW,CAAC,aAAyD;AAEnE,UAAI,QAAwB;AAC5B,WAAK,KAAK,CAAC,SAAS;AAElB,YAAI;AAAO,iBAAO;AAGlB,YAAI,SAAS,IAAI;AAAG,kBAAQ;AAC5B,eAAO,CAAC;AAAA,MACV,CAAC;AAED,aAAO;AAAA,IACT;AAEA,wBAAe,CAAC,aAAoD;AAClE,YAAM,QAAmB,CAAC;AAC1B,WA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K,OAAO,SAAS,OAAO,KAAK,YAAY,CAAC;AAG9C,WAAK,OAAO,gBAAgB;AAG5B,WAAK,KAAK,CAAC,UAAU;AACnB,aAAK,KAAK,8BAA8B,KAAK;AAC7C,eAAO;AAAA,MACT,CAAC;AAED,WAAK,SAAS;AAAA,IAChB;AAtJE,SAAK,OAAO,KAAK,YAAY,IAAI;AACjC,SAAK,aAAa;AAClB,SAAK,QAAQ;AACb,SAAK,SAAS,UAAU;AACxB,SAAK,OAAO;AACZ,SAAK,QAAQ;AAEb,SAAK,WACH,KAAK,UAAU;AAAA,MACb,CAAC,SAAS,UAAU,IAAI,KAAK,SAAc,EAAE,YAAY,OAAO,OAAO,QAAQ,GAAG,QAAQ,MAAM,KAAK,CAAC;AAAA,IACxG,KAAK,CAAC;AAGR,SAAK,YAAY,KAAK,aAAa,IAAI;AAAA,EACzC;AAAA;AAAA;AAAA;AAAA,EAsBA,IAAI,OAAe;AACjB,WAAO,KAAK;AAAA,EACd;AAiHF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/useDSTree.ts"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { useCallback, useMemo, useState } from 'react';\nimport { DSTree } from './DSTree.js';\nimport type { AddOptions, Item, MoveOptions, MutateOptions, RemoveOptions } from './types.js';\n\nexport const useDSTree = <T extends Item>(rootItem: T, opts: { getUniqueId: (item: T) => string }) => {\n const tree = useMemo(() => new DSTree(rootItem, opts), [opts, rootItem]);\n const [hash, setHash] = useState(tree.hash);\n\n const addNode = useCallback(\n (item: T, options?: AddOptions<T>) => {\n const cb: AddOptions<T>['callback'] = (node, treecb) => {\n options?.callback?.(node, treecb);\n setHash(treecb.hash);\n };\n return tree.addNode(item, { ...options, callback: cb });\n },\n [tree],\n );\n\n const removeNode = useCallback(\n (id: string, options?: RemoveOptions<T>) => {\n const cb: RemoveOptions<T>['callback'] = (node, treecb) => {\n options?.callback?.(node, treecb);\n setHash(treecb.hash);\n };\n return tree.removeNode(id, { ...options, callback: cb });\n },\n [tree],\n );\n\n const moveNode = useCallback(\n (id: string, options?: MoveOptions<T>) => {\n const cb: MoveOptions<T>['callback'] = (node, treecb) => {\n options?.callback?.(node, treecb);\n setHash(treecb.hash);\n };\n return tree.moveNode(id, { ...options, callback: cb });\n },\n [tree],\n );\n\n const replaceNode = useCallback(\n (id: string, item: T, options?: MutateOptions<T>) => {\n const cb: MutateOptions<T>['callback'] = (node, treecb) => {\n options?.callback?.(node, treecb);\n setHash(treecb.hash);\n };\n return tree.replaceNode(id, item, { ...options, callback: cb });\n },\n [tree],\n );\n\n return {\n hash,\n getRoot: tree.getRoot,\n getNode: tree.getNode,\n walk: tree.walk,\n walkParents: tree.walkParents,\n findNode: tree.findNode,\n findAllNodes: tree.findAllNodes,\n flatten: tree.flatten,\n addNode,\n removeNode,\n moveNode,\n replaceNode,\n getPath: tree.getPath,\n getPathIds: tree.getPathIds,\n };\n};\n"],
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,aAAa,SAAS,gBAAgB;AAC/C,SAAS,cAAc;AAGhB,MAAM,YAAY,CAAiB,UAAa,
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { useCallback, useMemo, useState } from 'react';\nimport { DSTree } from './DSTree.js';\nimport type { AddOptions, Item, MoveOptions, MutateOptions, RemoveOptions } from './types.js';\n\nexport const useDSTree = <T extends Item>(rootItem: T, opts: { getUniqueId: (item: T) => string | number }) => {\n const tree = useMemo(() => new DSTree(rootItem, opts), [opts, rootItem]);\n const [hash, setHash] = useState(tree.hash);\n\n const addNode = useCallback(\n (item: T, options?: AddOptions<T>) => {\n const cb: AddOptions<T>['callback'] = (node, treecb) => {\n options?.callback?.(node, treecb);\n setHash(treecb.hash);\n };\n return tree.addNode(item, { ...options, callback: cb });\n },\n [tree],\n );\n\n const removeNode = useCallback(\n (id: string, options?: RemoveOptions<T>) => {\n const cb: RemoveOptions<T>['callback'] = (node, treecb) => {\n options?.callback?.(node, treecb);\n setHash(treecb.hash);\n };\n return tree.removeNode(id, { ...options, callback: cb });\n },\n [tree],\n );\n\n const moveNode = useCallback(\n (id: string, options?: MoveOptions<T>) => {\n const cb: MoveOptions<T>['callback'] = (node, treecb) => {\n options?.callback?.(node, treecb);\n setHash(treecb.hash);\n };\n return tree.moveNode(id, { ...options, callback: cb });\n },\n [tree],\n );\n\n const replaceNode = useCallback(\n (id: string, item: T, options?: MutateOptions<T>) => {\n const cb: MutateOptions<T>['callback'] = (node, treecb) => {\n options?.callback?.(node, treecb);\n setHash(treecb.hash);\n };\n return tree.replaceNode(id, item, { ...options, callback: cb });\n },\n [tree],\n );\n\n return {\n hash,\n getRoot: tree.getRoot,\n getNode: tree.getNode,\n walk: tree.walk,\n walkParents: tree.walkParents,\n findNode: tree.findNode,\n findAllNodes: tree.findAllNodes,\n flatten: tree.flatten,\n addNode,\n removeNode,\n moveNode,\n replaceNode,\n getPath: tree.getPath,\n getPathIds: tree.getPathIds,\n };\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,aAAa,SAAS,gBAAgB;AAC/C,SAAS,cAAc;AAGhB,MAAM,YAAY,CAAiB,UAAa,SAAwD;AAC7G,QAAM,OAAO,QAAQ,MAAM,IAAI,OAAO,UAAU,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC;AACvE,QAAM,CAAC,MAAM,OAAO,IAAI,SAAS,KAAK,IAAI;AAE1C,QAAM,UAAU;AAAA,IACd,CAAC,MAAS,YAA4B;AACpC,YAAM,KAAgC,CAAC,MAAM,WAAW;AACtD,iBAAS,WAAW,MAAM,MAAM;AAChC,gBAAQ,OAAO,IAAI;AAAA,MACrB;AACA,aAAO,KAAK,QAAQ,MAAM,EAAE,GAAG,SAAS,UAAU,GAAG,CAAC;AA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@ export declare class DSTree<T extends Item> {
|
|
|
4
4
|
private root;
|
|
5
5
|
private _hash;
|
|
6
6
|
private nodes;
|
|
7
|
-
getUniqueId: (item: T) => string;
|
|
7
|
+
getUniqueId: (item: T) => string | number;
|
|
8
8
|
constructor(item: T, options: {
|
|
9
|
-
getUniqueId: (item: T) => string;
|
|
9
|
+
getUniqueId: (item: T) => string | number;
|
|
10
10
|
});
|
|
11
11
|
addNodeToNodesDictionary(node: Node<T>): void;
|
|
12
12
|
removeNodeFromNodesDictionary(node: Node<T>): void;
|
|
13
13
|
get hash(): number;
|
|
14
14
|
getRoot: () => Node<T>;
|
|
15
|
-
getNode: (id: string) => Node<T>;
|
|
15
|
+
getNode: (id: string | number) => Node<T>;
|
|
16
16
|
getNodes: () => Record<string, Node<T>>;
|
|
17
17
|
walk: (callback: (node: Node<T>) => boolean) => void;
|
|
18
18
|
walkParents: (callback: (node: Node<T>) => boolean) => void;
|
|
@@ -20,9 +20,9 @@ export declare class DSTree<T extends Item> {
|
|
|
20
20
|
findAllNodes: (callback: (node: Node<T>) => boolean) => Node<T>[];
|
|
21
21
|
flatten: () => Node<T>[];
|
|
22
22
|
addNode: (item: T, options?: AddOptions<T>) => Node<T>;
|
|
23
|
-
removeNode: (id: string, options?: RemoveOptions<T>) => Node<T>;
|
|
24
|
-
moveNode: (id: string, options?: MoveOptions<T>) => Node<T>;
|
|
25
|
-
replaceNode: (id: string, item: T, options?: MutateOptions<T>) => Node<T>;
|
|
26
|
-
getPath: (id: string) => Node<T>[];
|
|
27
|
-
getPathIds: (id: string) => string[];
|
|
23
|
+
removeNode: (id: string | number, options?: RemoveOptions<T>) => Node<T>;
|
|
24
|
+
moveNode: (id: string | number, options?: MoveOptions<T>) => Node<T>;
|
|
25
|
+
replaceNode: (id: string | number, item: T, options?: MutateOptions<T>) => Node<T>;
|
|
26
|
+
getPath: (id: string | number) => Node<T>[];
|
|
27
|
+
getPathIds: (id: string | number) => (string | number)[];
|
|
28
28
|
}
|
package/dist/types/Node.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Item, NodeConstructorOptions } from './types.js';
|
|
2
2
|
export declare class Node<T extends Item> {
|
|
3
|
-
dsId: string;
|
|
3
|
+
dsId: string | number;
|
|
4
4
|
plainItem: T;
|
|
5
5
|
childIndex: number;
|
|
6
6
|
depth: number;
|
|
@@ -17,8 +17,8 @@ export declare class Node<T extends Item> {
|
|
|
17
17
|
findNode: (callback: (node: Node<T>) => boolean) => Node<T> | null;
|
|
18
18
|
findAllNodes: (callback: (node: Node<T>) => boolean) => Node<T>[];
|
|
19
19
|
flatten: () => Node<T>[];
|
|
20
|
-
getPath: (id: string) => Node<T>[];
|
|
21
|
-
getPathIds: (id: string) => string[];
|
|
20
|
+
getPath: (id: string | number) => Node<T>[];
|
|
21
|
+
getPathIds: (id: string | number) => (string | number)[];
|
|
22
22
|
getJson: () => T;
|
|
23
23
|
addNode: (node: Node<T>) => void;
|
|
24
24
|
removeNode: () => void;
|
|
@@ -6,7 +6,7 @@ export declare const useArraishAsDSTree: <T extends object = object>(treeData: T
|
|
|
6
6
|
hash: number;
|
|
7
7
|
tree: import("../../DSTree.js").DSTree<OverloadedItem<T>>;
|
|
8
8
|
getRoot: () => import("../../Node.js").Node<OverloadedItem<T>>;
|
|
9
|
-
getNode: (id: string) => import("../../Node.js").Node<OverloadedItem<T>>;
|
|
9
|
+
getNode: (id: string | number) => import("../../Node.js").Node<OverloadedItem<T>>;
|
|
10
10
|
walk: (callback: (node: import("../../Node.js").Node<OverloadedItem<T>>) => boolean) => void;
|
|
11
11
|
walkParents: (callback: (node: import("../../Node.js").Node<OverloadedItem<T>>) => boolean) => void;
|
|
12
12
|
findNode: (callback: (node: import("../../Node.js").Node<OverloadedItem<T>>) => boolean) => import("../../Node.js").Node<OverloadedItem<T>> | null;
|
|
@@ -16,7 +16,7 @@ export declare const useArraishAsDSTree: <T extends object = object>(treeData: T
|
|
|
16
16
|
removeNode: (id: string, options?: RemoveOptions<OverloadedItem<T>> | undefined) => import("../../Node.js").Node<OverloadedItem<T>>;
|
|
17
17
|
moveNode: (id: string, options?: MoveOptions<OverloadedItem<T>> | undefined) => import("../../Node.js").Node<OverloadedItem<T>>;
|
|
18
18
|
replaceNode: (id: string, item: OverloadedItem<T>, options?: MutateOptions<OverloadedItem<T>> | undefined) => import("../../Node.js").Node<OverloadedItem<T>>;
|
|
19
|
-
getPath: (id: string) => import("../../Node.js").Node<OverloadedItem<T>>[];
|
|
20
|
-
getPathIds: (id: string) => string[];
|
|
19
|
+
getPath: (id: string | number) => import("../../Node.js").Node<OverloadedItem<T>>[];
|
|
20
|
+
getPathIds: (id: string | number) => (string | number)[];
|
|
21
21
|
getRestoredTree: () => T[];
|
|
22
22
|
};
|
|
@@ -6,7 +6,7 @@ export declare const useTreeviewAsDSTree: <T extends TreeviewItem<object> = Tree
|
|
|
6
6
|
hash: number;
|
|
7
7
|
tree: import("../../DSTree.js").DSTree<import("../../types.js").OverloadedItem<T>>;
|
|
8
8
|
getRoot: () => import("../../Node.js").Node<import("../../types.js").OverloadedItem<T>>;
|
|
9
|
-
getNode: (id: string) => import("../../Node.js").Node<import("../../types.js").OverloadedItem<T>>;
|
|
9
|
+
getNode: (id: string | number) => import("../../Node.js").Node<import("../../types.js").OverloadedItem<T>>;
|
|
10
10
|
walk: (callback: (node: import("../../Node.js").Node<import("../../types.js").OverloadedItem<T>>) => boolean) => void;
|
|
11
11
|
walkParents: (callback: (node: import("../../Node.js").Node<import("../../types.js").OverloadedItem<T>>) => boolean) => void;
|
|
12
12
|
findNode: (callback: (node: import("../../Node.js").Node<import("../../types.js").OverloadedItem<T>>) => boolean) => import("../../Node.js").Node<import("../../types.js").OverloadedItem<T>> | null;
|
|
@@ -16,8 +16,8 @@ export declare const useTreeviewAsDSTree: <T extends TreeviewItem<object> = Tree
|
|
|
16
16
|
removeNode: (id: string, options?: import("../../types.js").RemoveOptions<import("../../types.js").OverloadedItem<T>> | undefined) => import("../../Node.js").Node<import("../../types.js").OverloadedItem<T>>;
|
|
17
17
|
moveNode: (id: string, options?: import("../../types.js").MoveOptions<import("../../types.js").OverloadedItem<T>> | undefined) => import("../../Node.js").Node<import("../../types.js").OverloadedItem<T>>;
|
|
18
18
|
replaceNode: (id: string, item: import("../../types.js").OverloadedItem<T>, options?: import("../../types.js").MutateOptions<import("../../types.js").OverloadedItem<T>> | undefined) => import("../../Node.js").Node<import("../../types.js").OverloadedItem<T>>;
|
|
19
|
-
getPath: (id: string) => import("../../Node.js").Node<import("../../types.js").OverloadedItem<T>>[];
|
|
20
|
-
getPathIds: (id: string) => string[];
|
|
19
|
+
getPath: (id: string | number) => import("../../Node.js").Node<import("../../types.js").OverloadedItem<T>>[];
|
|
20
|
+
getPathIds: (id: string | number) => (string | number)[];
|
|
21
21
|
getRestoredTree: () => T[];
|
|
22
22
|
};
|
|
23
23
|
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { AddOptions, Item, MoveOptions, MutateOptions, RemoveOptions } from './types.js';
|
|
2
2
|
export declare const useDSTree: <T extends Item>(rootItem: T, opts: {
|
|
3
|
-
getUniqueId: (item: T) => string;
|
|
3
|
+
getUniqueId: (item: T) => string | number;
|
|
4
4
|
}) => {
|
|
5
5
|
hash: number;
|
|
6
6
|
getRoot: () => import("./Node.js").Node<T>;
|
|
7
|
-
getNode: (id: string) => import("./Node.js").Node<T>;
|
|
7
|
+
getNode: (id: string | number) => import("./Node.js").Node<T>;
|
|
8
8
|
walk: (callback: (node: import("./Node.js").Node<T>) => boolean) => void;
|
|
9
9
|
walkParents: (callback: (node: import("./Node.js").Node<T>) => boolean) => void;
|
|
10
10
|
findNode: (callback: (node: import("./Node.js").Node<T>) => boolean) => import("./Node.js").Node<T> | null;
|
|
@@ -14,6 +14,6 @@ export declare const useDSTree: <T extends Item>(rootItem: T, opts: {
|
|
|
14
14
|
removeNode: (id: string, options?: RemoveOptions<T> | undefined) => import("./Node.js").Node<T>;
|
|
15
15
|
moveNode: (id: string, options?: MoveOptions<T> | undefined) => import("./Node.js").Node<T>;
|
|
16
16
|
replaceNode: (id: string, item: T, options?: MutateOptions<T> | undefined) => import("./Node.js").Node<T>;
|
|
17
|
-
getPath: (id: string) => import("./Node.js").Node<T>[];
|
|
18
|
-
getPathIds: (id: string) => string[];
|
|
17
|
+
getPath: (id: string | number) => import("./Node.js").Node<T>[];
|
|
18
|
+
getPathIds: (id: string | number) => (string | number)[];
|
|
19
19
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elliemae/ds-tree-model",
|
|
3
|
-
"version": "3.29.0-
|
|
3
|
+
"version": "3.29.0-rc.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "ICE MT - Dimsum - Tree Model",
|
|
6
6
|
"files": [
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@elliemae/pui-cli": "~9.0.0-next.31",
|
|
43
|
-
"@elliemae/ds-monorepo-devops": "3.29.0-
|
|
43
|
+
"@elliemae/ds-monorepo-devops": "3.29.0-rc.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"lodash": "^4.17.21",
|