@elliemae/ds-tree-model 3.52.0-rc.2 → 3.52.0-rc.21
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/Node.js +2 -2
- package/dist/cjs/Node.js.map +2 -2
- package/dist/esm/Node.js +1 -1
- package/dist/esm/Node.js.map +1 -1
- package/package.json +4 -4
package/dist/cjs/Node.js
CHANGED
|
@@ -32,7 +32,7 @@ __export(Node_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(Node_exports);
|
|
34
34
|
var React = __toESM(require("react"));
|
|
35
|
-
var
|
|
35
|
+
var import_lodash_es = require("lodash-es");
|
|
36
36
|
class Node {
|
|
37
37
|
dsId;
|
|
38
38
|
childIndex;
|
|
@@ -77,7 +77,7 @@ class Node {
|
|
|
77
77
|
};
|
|
78
78
|
getCleanItem = (item) => {
|
|
79
79
|
const { subitems, ...plainItem } = item;
|
|
80
|
-
return (0,
|
|
80
|
+
return (0, import_lodash_es.cloneDeep)(plainItem);
|
|
81
81
|
};
|
|
82
82
|
// ===========================================================================
|
|
83
83
|
// READ METHODS
|
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-underscore-dangle */\n/* eslint-disable no-use-before-define */\n/* eslint-disable max-params */\nimport { cloneDeep } from 'lodash';\nimport type { DSTree } from './DSTree.js';\nimport type { NodeConstructorOptions, AnyObjectWithoutReservedKeys, Item } from './types.js';\n\nexport class Node<AppInterface extends AnyObjectWithoutReservedKeys = Record<string, unknown>> {\n dsId: string | number;\n\n childIndex: number;\n\n depth: number;\n\n plainItem: AppInterface;\n\n plainChildren: AppInterface[];\n\n parent: Node<AppInterface> | null;\n\n children: Node<AppInterface>[];\n\n private tree!: DSTree<AppInterface>;\n\n private _hash: number;\n\n constructor(item: Item<AppInterface>, { childIndex, depth, parent, tree }: NodeConstructorOptions<AppInterface>) {\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 this.children = [];\n this.plainChildren = [];\n\n // on construction, we add the children to the node\n // this will recursively happen for all children because this triggers `new Node()` recursively\n const subitems = item.subitems ?? [];\n subitems.forEach((subitem, index) => {\n this.plainChildren.push(this.getCleanItem(subitem));\n this.children.push(\n new Node<AppInterface>(subitem, {\n childIndex: index,\n depth: depth + 1,\n parent: this,\n tree,\n }),\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 += 1) {\n this.children[i].childIndex = i;\n }\n this._hash += 1;\n };\n\n getCleanItem = (item: Item<AppInterface>): AppInterface => {\n const { subitems, ...plainItem } = item;\n return cloneDeep(plainItem as AppInterface);\n };\n\n // ===========================================================================\n // READ METHODS\n // ===========================================================================\n\n get hash(): number {\n return this._hash;\n }\n\n walk = (callback: (node: Node<AppInterface>) => boolean): void => {\n const shouldContinueWalking = callback(this);\n if (shouldContinueWalking) {\n // eslint-disable-next-line no-restricted-syntax\n for (const child of this.children) {\n child.walk(callback);\n }\n }\n };\n\n walkParents = (callback: (node: Node<AppInterface>) => 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<AppInterface>) => boolean): Node<AppInterface> | null => {\n // find first node using walk\n let found: Node<AppInterface> | 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<AppInterface>) => boolean): Node<AppInterface>[] => {\n const found: Node<AppInterface>[] = [];\n this.walk((node) => {\n if (callback(node)) found.push(node);\n return true;\n });\n return found;\n };\n\n flatten = (): Node<AppInterface>[] => {\n const flattened: Node<AppInterface>[] = [];\n this.walk((node) => {\n flattened.push(node);\n return true;\n });\n return flattened;\n };\n\n getPath = (id: string | number): Node<AppInterface>[] => {\n const path: Node<AppInterface>[] = [];\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 = (): Item<AppInterface> =>\n ({\n ...this.plainItem,\n subitems: this.children?.map?.((child) => child.getJson()) ?? undefined,\n }) as Item<AppInterface>;\n\n // ===========================================================================\n // WRITE METHODS\n // ===========================================================================\n\n addNode = (node: Node<AppInterface>) => {\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;ADGvB,
|
|
4
|
+
"sourcesContent": ["/* eslint-disable no-underscore-dangle */\n/* eslint-disable no-use-before-define */\n/* eslint-disable max-params */\nimport { cloneDeep } from 'lodash-es';\nimport type { DSTree } from './DSTree.js';\nimport type { NodeConstructorOptions, AnyObjectWithoutReservedKeys, Item } from './types.js';\n\nexport class Node<AppInterface extends AnyObjectWithoutReservedKeys = Record<string, unknown>> {\n dsId: string | number;\n\n childIndex: number;\n\n depth: number;\n\n plainItem: AppInterface;\n\n plainChildren: AppInterface[];\n\n parent: Node<AppInterface> | null;\n\n children: Node<AppInterface>[];\n\n private tree!: DSTree<AppInterface>;\n\n private _hash: number;\n\n constructor(item: Item<AppInterface>, { childIndex, depth, parent, tree }: NodeConstructorOptions<AppInterface>) {\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 this.children = [];\n this.plainChildren = [];\n\n // on construction, we add the children to the node\n // this will recursively happen for all children because this triggers `new Node()` recursively\n const subitems = item.subitems ?? [];\n subitems.forEach((subitem, index) => {\n this.plainChildren.push(this.getCleanItem(subitem));\n this.children.push(\n new Node<AppInterface>(subitem, {\n childIndex: index,\n depth: depth + 1,\n parent: this,\n tree,\n }),\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 += 1) {\n this.children[i].childIndex = i;\n }\n this._hash += 1;\n };\n\n getCleanItem = (item: Item<AppInterface>): AppInterface => {\n const { subitems, ...plainItem } = item;\n return cloneDeep(plainItem as AppInterface);\n };\n\n // ===========================================================================\n // READ METHODS\n // ===========================================================================\n\n get hash(): number {\n return this._hash;\n }\n\n walk = (callback: (node: Node<AppInterface>) => boolean): void => {\n const shouldContinueWalking = callback(this);\n if (shouldContinueWalking) {\n // eslint-disable-next-line no-restricted-syntax\n for (const child of this.children) {\n child.walk(callback);\n }\n }\n };\n\n walkParents = (callback: (node: Node<AppInterface>) => 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<AppInterface>) => boolean): Node<AppInterface> | null => {\n // find first node using walk\n let found: Node<AppInterface> | 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<AppInterface>) => boolean): Node<AppInterface>[] => {\n const found: Node<AppInterface>[] = [];\n this.walk((node) => {\n if (callback(node)) found.push(node);\n return true;\n });\n return found;\n };\n\n flatten = (): Node<AppInterface>[] => {\n const flattened: Node<AppInterface>[] = [];\n this.walk((node) => {\n flattened.push(node);\n return true;\n });\n return flattened;\n };\n\n getPath = (id: string | number): Node<AppInterface>[] => {\n const path: Node<AppInterface>[] = [];\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 = (): Item<AppInterface> =>\n ({\n ...this.plainItem,\n subitems: this.children?.map?.((child) => child.getJson()) ?? undefined,\n }) as Item<AppInterface>;\n\n // ===========================================================================\n // WRITE METHODS\n // ===========================================================================\n\n addNode = (node: Node<AppInterface>) => {\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;ADGvB,uBAA0B;AAInB,MAAM,KAAkF;AAAA,EAC7F;AAAA,EAEA;AAAA,EAEA;AAAA,EAEA;AAAA,EAEA;AAAA,EAEA;AAAA,EAEA;AAAA,EAEQ;AAAA,EAEA;AAAA,EAER,YAAY,MAA0B,EAAE,YAAY,OAAO,QAAQ,KAAK,GAAyC;AAC/G,SAAK,OAAO,KAAK,YAAY,IAAI;AACjC,SAAK,aAAa;AAClB,SAAK,QAAQ;AACb,SAAK,SAAS,UAAU;AACxB,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK,WAAW,CAAC;AACjB,SAAK,gBAAgB,CAAC;AAItB,UAAM,WAAW,KAAK,YAAY,CAAC;AACnC,aAAS,QAAQ,CAAC,SAAS,UAAU;AACnC,WAAK,cAAc,KAAK,KAAK,aAAa,OAAO,CAAC;AAClD,WAAK,SAAS;AAAA,QACZ,IAAI,KAAmB,SAAS;AAAA,UAC9B,YAAY;AAAA,UACZ,OAAO,QAAQ;AAAA,UACf,QAAQ;AAAA,UACR;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAED,SAAK,YAAY,KAAK,aAAa,IAAI;AAAA,EACzC;AAAA;AAAA;AAAA;AAAA,EAMA,kBAAkB,MAAY;AAC5B,aAAS,IAAI,GAAG,IAAI,KAAK,SAAS,QAAQ,KAAK,GAAG;AAChD,WAAK,SAAS,CAAC,EAAE,aAAa;AAAA,IAChC;AACA,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,eAAe,CAAC,SAA2C;AACzD,U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K;AAAA,IAC9B,CAAC;AACD,WAAO,KAAK,QAAQ;AAAA,EACtB;AAAA,EAEA,aAAa,CAAC,OAAwB,KAAK,QAAQ,EAAE,EAAE,IAAI,CAAC,SAAS,KAAK,IAAI;AAAA,EAE9E,UAAU,OACP;AAAA,IACC,GAAG,KAAK;AAAA,IACR,UAAU,KAAK,UAAU,MAAM,CAAC,UAAU,MAAM,QAAQ,CAAC,KAAK;AAAA,EAChE;AAAA;AAAA;AAAA;AAAA,EAMF,UAAU,CAAC,SAA6B;AAEtC,UAAM,WAAW,KAAK;AACtB,QAAI,WAAW,KAAK,WAAW,KAAK,SAAS,QAAQ;AACnD,YAAM,IAAI,MAAM,oBAAoB,QAAQ,eAAe,KAAK,IAAI,cAAc,KAAK,IAAI,EAAE;AAAA,IAC/F;AAGA,SAAK,SAAS,OAAO,UAAU,GAAG,IAAI;AAGtC,SAAK,gBAAgB;AAGrB,SAAK,KAAK,CAAC,UAAU;AACnB,WAAK,KAAK,yBAAyB,KAAK;AACxC,aAAO;AAAA,IACT,CAAC;AAED,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,aAAa,MAAM;AAEjB,QAAI,CAAC,KAAK,OAAQ,OAAM,IAAI,MAAM,mCAAmC,KAAK,IAAI,EAAE;AAGhF,SAAK,OAAO,SAAS,OAAO,KAAK,YAAY,CAAC;AAG9C,SAAK,OAAO,gBAAgB;AAG5B,SAAK,KAAK,CAAC,UAAU;AACnB,WAAK,KAAK,8BAA8B,KAAK;AAC7C,aAAO;AAAA,IACT,CAAC;AAED,SAAK,SAAS;AAAA,EAChB;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/Node.js
CHANGED
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-underscore-dangle */\n/* eslint-disable no-use-before-define */\n/* eslint-disable max-params */\nimport { cloneDeep } from 'lodash';\nimport type { DSTree } from './DSTree.js';\nimport type { NodeConstructorOptions, AnyObjectWithoutReservedKeys, Item } from './types.js';\n\nexport class Node<AppInterface extends AnyObjectWithoutReservedKeys = Record<string, unknown>> {\n dsId: string | number;\n\n childIndex: number;\n\n depth: number;\n\n plainItem: AppInterface;\n\n plainChildren: AppInterface[];\n\n parent: Node<AppInterface> | null;\n\n children: Node<AppInterface>[];\n\n private tree!: DSTree<AppInterface>;\n\n private _hash: number;\n\n constructor(item: Item<AppInterface>, { childIndex, depth, parent, tree }: NodeConstructorOptions<AppInterface>) {\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 this.children = [];\n this.plainChildren = [];\n\n // on construction, we add the children to the node\n // this will recursively happen for all children because this triggers `new Node()` recursively\n const subitems = item.subitems ?? [];\n subitems.forEach((subitem, index) => {\n this.plainChildren.push(this.getCleanItem(subitem));\n this.children.push(\n new Node<AppInterface>(subitem, {\n childIndex: index,\n depth: depth + 1,\n parent: this,\n tree,\n }),\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 += 1) {\n this.children[i].childIndex = i;\n }\n this._hash += 1;\n };\n\n getCleanItem = (item: Item<AppInterface>): AppInterface => {\n const { subitems, ...plainItem } = item;\n return cloneDeep(plainItem as AppInterface);\n };\n\n // ===========================================================================\n // READ METHODS\n // ===========================================================================\n\n get hash(): number {\n return this._hash;\n }\n\n walk = (callback: (node: Node<AppInterface>) => boolean): void => {\n const shouldContinueWalking = callback(this);\n if (shouldContinueWalking) {\n // eslint-disable-next-line no-restricted-syntax\n for (const child of this.children) {\n child.walk(callback);\n }\n }\n };\n\n walkParents = (callback: (node: Node<AppInterface>) => 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<AppInterface>) => boolean): Node<AppInterface> | null => {\n // find first node using walk\n let found: Node<AppInterface> | 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<AppInterface>) => boolean): Node<AppInterface>[] => {\n const found: Node<AppInterface>[] = [];\n this.walk((node) => {\n if (callback(node)) found.push(node);\n return true;\n });\n return found;\n };\n\n flatten = (): Node<AppInterface>[] => {\n const flattened: Node<AppInterface>[] = [];\n this.walk((node) => {\n flattened.push(node);\n return true;\n });\n return flattened;\n };\n\n getPath = (id: string | number): Node<AppInterface>[] => {\n const path: Node<AppInterface>[] = [];\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 = (): Item<AppInterface> =>\n ({\n ...this.plainItem,\n subitems: this.children?.map?.((child) => child.getJson()) ?? undefined,\n }) as Item<AppInterface>;\n\n // ===========================================================================\n // WRITE METHODS\n // ===========================================================================\n\n addNode = (node: Node<AppInterface>) => {\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"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable no-underscore-dangle */\n/* eslint-disable no-use-before-define */\n/* eslint-disable max-params */\nimport { cloneDeep } from 'lodash-es';\nimport type { DSTree } from './DSTree.js';\nimport type { NodeConstructorOptions, AnyObjectWithoutReservedKeys, Item } from './types.js';\n\nexport class Node<AppInterface extends AnyObjectWithoutReservedKeys = Record<string, unknown>> {\n dsId: string | number;\n\n childIndex: number;\n\n depth: number;\n\n plainItem: AppInterface;\n\n plainChildren: AppInterface[];\n\n parent: Node<AppInterface> | null;\n\n children: Node<AppInterface>[];\n\n private tree!: DSTree<AppInterface>;\n\n private _hash: number;\n\n constructor(item: Item<AppInterface>, { childIndex, depth, parent, tree }: NodeConstructorOptions<AppInterface>) {\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 this.children = [];\n this.plainChildren = [];\n\n // on construction, we add the children to the node\n // this will recursively happen for all children because this triggers `new Node()` recursively\n const subitems = item.subitems ?? [];\n subitems.forEach((subitem, index) => {\n this.plainChildren.push(this.getCleanItem(subitem));\n this.children.push(\n new Node<AppInterface>(subitem, {\n childIndex: index,\n depth: depth + 1,\n parent: this,\n tree,\n }),\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 += 1) {\n this.children[i].childIndex = i;\n }\n this._hash += 1;\n };\n\n getCleanItem = (item: Item<AppInterface>): AppInterface => {\n const { subitems, ...plainItem } = item;\n return cloneDeep(plainItem as AppInterface);\n };\n\n // ===========================================================================\n // READ METHODS\n // ===========================================================================\n\n get hash(): number {\n return this._hash;\n }\n\n walk = (callback: (node: Node<AppInterface>) => boolean): void => {\n const shouldContinueWalking = callback(this);\n if (shouldContinueWalking) {\n // eslint-disable-next-line no-restricted-syntax\n for (const child of this.children) {\n child.walk(callback);\n }\n }\n };\n\n walkParents = (callback: (node: Node<AppInterface>) => 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<AppInterface>) => boolean): Node<AppInterface> | null => {\n // find first node using walk\n let found: Node<AppInterface> | 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<AppInterface>) => boolean): Node<AppInterface>[] => {\n const found: Node<AppInterface>[] = [];\n this.walk((node) => {\n if (callback(node)) found.push(node);\n return true;\n });\n return found;\n };\n\n flatten = (): Node<AppInterface>[] => {\n const flattened: Node<AppInterface>[] = [];\n this.walk((node) => {\n flattened.push(node);\n return true;\n });\n return flattened;\n };\n\n getPath = (id: string | number): Node<AppInterface>[] => {\n const path: Node<AppInterface>[] = [];\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 = (): Item<AppInterface> =>\n ({\n ...this.plainItem,\n subitems: this.children?.map?.((child) => child.getJson()) ?? undefined,\n }) as Item<AppInterface>;\n\n // ===========================================================================\n // WRITE METHODS\n // ===========================================================================\n\n addNode = (node: Node<AppInterface>) => {\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
5
|
"mappings": "AAAA,YAAY,WAAW;ACGvB,SAAS,iBAAiB;AAInB,MAAM,KAAkF;AAAA,EAC7F;AAAA,EAEA;AAAA,EAEA;AAAA,EAEA;AAAA,EAEA;AAAA,EAEA;AAAA,EAEA;AAAA,EAEQ;AAAA,EAEA;AAAA,EAER,YAAY,MAA0B,EAAE,YAAY,OAAO,QAAQ,KAAK,GAAyC;AAC/G,SAAK,OAAO,KAAK,YAAY,IAAI;AACjC,SAAK,aAAa;AAClB,SAAK,QAAQ;AACb,SAAK,SAAS,UAAU;AACxB,SAAK,OAAO;AACZ,SAAK,QAAQ;AACb,SAAK,WAAW,CAAC;AACjB,SAAK,gBAAgB,CAAC;AAItB,UAAM,WAAW,KAAK,YAAY,CAAC;AACnC,aAAS,QAAQ,CAAC,SAAS,UAAU;AACnC,WAAK,cAAc,KAAK,KAAK,aAAa,OAAO,CAAC;AAClD,WAAK,SAAS;AAAA,QACZ,IAAI,KAAmB,SAAS;AAAA,UAC9B,YAAY;AAAA,UACZ,OAAO,QAAQ;AAAA,UACf,QAAQ;AAAA,UACR;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAED,SAAK,YAAY,KAAK,aAAa,IAAI;AAAA,EACzC;AAAA;AAAA;AAAA;AAAA,EAMA,kBAAkB,MAAY;AAC5B,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
|
1
1
|
{
|
|
2
2
|
"name": "@elliemae/ds-tree-model",
|
|
3
|
-
"version": "3.52.0-rc.
|
|
3
|
+
"version": "3.52.0-rc.21",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "ICE MT - Dimsum - Tree Model",
|
|
6
6
|
"files": [
|
|
@@ -40,15 +40,15 @@
|
|
|
40
40
|
"typeSafety": true
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@elliemae/ds-props-helpers": "3.52.0-rc.
|
|
43
|
+
"@elliemae/ds-props-helpers": "3.52.0-rc.21"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@elliemae/pui-cli": "9.0.0-next.55",
|
|
47
47
|
"jest": "~29.7.0",
|
|
48
|
-
"@elliemae/ds-monorepo-devops": "3.52.0-rc.
|
|
48
|
+
"@elliemae/ds-monorepo-devops": "3.52.0-rc.21"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"lodash": "^4.17.21",
|
|
51
|
+
"lodash-es": "^4.17.21",
|
|
52
52
|
"react": "^18.3.1",
|
|
53
53
|
"react-dom": "^18.3.1"
|
|
54
54
|
},
|