@elliemae/ds-tree-model 3.45.0-rc.0 → 3.45.0-rc.2
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 +17 -12
- package/dist/cjs/Node.js.map +2 -2
- package/dist/cjs/adapters/arraish-tree/fromTreeishArrayToDSTree.js.map +2 -2
- package/dist/cjs/react-desc-prop-types.js.map +2 -2
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/typescript-testing/typescript-use-ds-tree-valid.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 +18 -13
- package/dist/esm/Node.js.map +2 -2
- package/dist/esm/adapters/arraish-tree/fromTreeishArrayToDSTree.js.map +2 -2
- package/dist/esm/react-desc-prop-types.js.map +2 -2
- package/dist/esm/typescript-testing/typescript-use-ds-tree-valid.js.map +2 -2
- package/dist/esm/useDSTree.js.map +2 -2
- package/dist/types/DSTree.d.ts +4 -4
- package/dist/types/Node.d.ts +6 -5
- package/dist/types/react-desc-prop-types.d.ts +10 -8
- package/dist/types/types.d.ts +2 -7
- package/dist/types/useDSTree.d.ts +3 -3
- package/package.json +3 -3
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": ["/* eslint-disable no-underscore-dangle */\nimport type {\n AddOptions,\n AnyObjectWithoutReservedKeys,\n MoveOptions,\n MutateOptions,\n RemoveOptions,\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;
|
|
4
|
+
"sourcesContent": ["/* eslint-disable no-underscore-dangle */\nimport type {\n AddOptions,\n AnyObjectWithoutReservedKeys,\n MoveOptions,\n MutateOptions,\n RemoveOptions,\n Item,\n} from './types.js';\nimport { Node } from './Node.js';\n\nexport class DSTree<AppInterface extends AnyObjectWithoutReservedKeys = Record<string, unknown>> {\n private root: Node<AppInterface>;\n\n private _hash: number;\n\n private nodes: Record<string | number, Node<AppInterface>>;\n\n getUniqueId: (item: Item<AppInterface>) => string | number;\n\n constructor(item: Item<AppInterface>, options: { getUniqueId: (item: Item<AppInterface>) => string | number }) {\n this.getUniqueId = options.getUniqueId;\n this.root = new Node<AppInterface>(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<AppInterface>): 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<AppInterface>): void {\n delete this.nodes[node.dsId];\n }\n\n get hash(): number {\n return this._hash;\n }\n\n getRoot = (): Node<AppInterface> => this.root;\n\n getNode = (id: string | number): Node<AppInterface> => this.nodes[id];\n\n getNodes = (): Record<string, Node<AppInterface>> => this.nodes;\n\n walk = (callback: (node: Node<AppInterface>) => boolean): void => {\n this.root.walk(callback);\n };\n\n walkParents = (callback: (node: Node<AppInterface>) => boolean): void => {\n this.root.walkParents(callback);\n };\n\n findNode = (callback: (node: Node<AppInterface>) => boolean): Node<AppInterface> | null =>\n this.root.findNode(callback);\n\n findAllNodes = (callback: (node: Node<AppInterface>) => boolean): Node<AppInterface>[] =>\n this.root.findAllNodes(callback);\n\n flatten = (): Node<AppInterface>[] => this.root.flatten();\n\n addNode = (item: Item<AppInterface>, options: AddOptions<AppInterface> = {}): Node<AppInterface> => {\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<AppInterface>(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<AppInterface> = {}): Node<AppInterface> => {\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<AppInterface> = {}): Node<AppInterface> => {\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 = (\n id: string | number,\n item: Item<AppInterface>,\n options: MutateOptions<AppInterface> = {},\n ): Node<AppInterface> => {\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<AppInterface>[] => 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;ADSvB,kBAAqB;AAEd,MAAM,OAAoF;AAAA,EAS/F,YAAY,MAA0B,SAAyE;AA+B/G,mBAAU,MAA0B,KAAK;AAEzC,mBAAU,CAAC,OAA4C,KAAK,MAAM,EAAE;AAEpE,oBAAW,MAA0C,KAAK;AAE1D,gBAAO,CAAC,aAA0D;AAChE,WAAK,KAAK,KAAK,QAAQ;AAAA,IACzB;AAEA,uBAAc,CAAC,aAA0D;AACvE,WAAK,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,IAAI;AAE7B,aAAO;AAAA,IACT;AAEA,mBAAU,CAAC,OAA8C,KAAK,QAAQ,EAAE,QAAQ,EAAE;AAElF,sBAAa,CAAC,OAAwB,KAAK,QAAQ,EAAE,WAAW,EAAE;AArHhE,SAAK,cAAc,QAAQ;AAC3B,SAAK,OAAO,IAAI,iBAAmB,MAAM,EAAE,YAAY,GAAG,OAAO,GAAG,MAAM,KAAK,CAAC;AAChF,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,MAAgC;AAEvD,QAAI,KAAK,MAAM,KAAK,IAAI,GAAG;AACzB,YAAM,IAAI,MAAM,yBAAyB,KAAK,IAAI,EAAE;AAAA,IACtD;AAEA,SAAK,MAAM,KAAK,IAAI,IAAI;AAAA,EAC1B;AAAA,EAEA,8BAA8B,MAAgC;AAC5D,WAAO,KAAK,MAAM,KAAK,IAAI;AAAA,EAC7B;AAAA,EAEA,IAAI,OAAe;AACjB,WAAO,KAAK;AAAA,EACd;AA0FF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/Node.js
CHANGED
|
@@ -45,7 +45,7 @@ class Node {
|
|
|
45
45
|
this._hash += 1;
|
|
46
46
|
};
|
|
47
47
|
this.getCleanItem = (item) => {
|
|
48
|
-
const plainItem =
|
|
48
|
+
const { subitems, ...plainItem } = item;
|
|
49
49
|
return (0, import_lodash.cloneDeep)(plainItem);
|
|
50
50
|
};
|
|
51
51
|
this.walk = (callback) => {
|
|
@@ -128,22 +128,27 @@ class Node {
|
|
|
128
128
|
});
|
|
129
129
|
this._hash += 1;
|
|
130
130
|
};
|
|
131
|
-
|
|
132
|
-
this.dsId = tree.getUniqueId(itemCasted);
|
|
131
|
+
this.dsId = tree.getUniqueId(item);
|
|
133
132
|
this.childIndex = childIndex;
|
|
134
133
|
this.depth = depth;
|
|
135
134
|
this.parent = parent ?? null;
|
|
136
135
|
this.tree = tree;
|
|
137
136
|
this._hash = 0;
|
|
138
|
-
this.children =
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
137
|
+
this.children = [];
|
|
138
|
+
this.plainChildren = [];
|
|
139
|
+
const subitems = item.subitems ?? [];
|
|
140
|
+
subitems.forEach((subitem, index) => {
|
|
141
|
+
this.plainChildren.push(this.getCleanItem(subitem));
|
|
142
|
+
this.children.push(
|
|
143
|
+
new Node(subitem, {
|
|
144
|
+
childIndex: index,
|
|
145
|
+
depth: depth + 1,
|
|
146
|
+
parent: this,
|
|
147
|
+
tree
|
|
148
|
+
})
|
|
149
|
+
);
|
|
150
|
+
});
|
|
151
|
+
this.plainItem = this.getCleanItem(item);
|
|
147
152
|
}
|
|
148
153
|
// ===========================================================================
|
|
149
154
|
// 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
|
|
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';\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": ";;;;;;;;;;;;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AA,IAChB;AAnKE,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,EAsBA,IAAI,OAAe;AACjB,WAAO,KAAK;AAAA,EACd;AAmHF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/adapters/arraish-tree/fromTreeishArrayToDSTree.ts", "../../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable max-statements */\nimport { DSTree } from '../../DSTree.js';\nimport type { OverloadedItem } from '../../types.js';\n\n// we don't really need a 100% sure unique id, since we prepend a string that is most likely unique already\n// we just need to reduce the risk of collisions\n// we avoid depending on a library for this:\nconst unsecureUuid = () =>\n 'xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {\n const r = Math.random() * 16 || 0;\n // eslint-disable-next-line no-bitwise\n const v = c === 'x' ? r : r & 0x3 || 0x8;\n return v.toString(16);\n });\n\n/*\n * @param {Object} args\n * @param {Function} args.callback - a function that will be called for each node in the treeish data-structure\n * @param {Object} args.node - the node that is being currently visited\n * @param {Object} args.opts - an object that holds the opinions of the caller on how to walk the treeish data-structure\n * @param {Function} args.opts.getChildren - a function that given a node returns an array of children\n * @returns {void}\n */\nconst walkTreeish = <T extends object>({\n callback,\n node,\n opts,\n}: {\n callback: (node: T) => void;\n node: T;\n opts?: {\n getChildren: (node: T) => T[];\n };\n}): void => {\n callback(node);\n const children = opts?.getChildren(node);\n if (Array.isArray(children) && children.length > 0) {\n for (let i = 0; i < children.length; i += 1) {\n walkTreeish<T>({ callback, node: children[i], opts });\n }\n }\n};\n\n/*\n * a function that given a treeish array and some options returns a DSTree datastructure that compltely preserves the treeish array\n * but still allows to use the full power of the DSTree datastructure\n * NOTE: This create a deep clone of the treeish array, so it's not suitable for large trees and will not preserve any reference to the original treeish array\n * @param {Array} treeish - an array of items that rapresents a tree, this will be used to create a DSTree datastructure\n * @param {Object} opts - an object that governs how the treeish array will be converted to a DSTree datastructure\n * @param {Function} opts.getChildrenKey - a function that given a node returns the key used to access the node children\n * @param {Function} opts.getUniqueId - a function that given a node returns a unique string used to identify the node\n * @returns {DSTree} - a DSTree datastructure\n */\nexport const fromTreeishArrayToDSTree = <T extends object = object>(args: {\n treeish: T[];\n opts: {\n getChildrenKey: (node: T) => keyof T;\n getUniqueId: (item: T) => string;\n };\n}): DSTree<OverloadedItem<T>> => {\n // we use crypto to generate a unique id for the root, this is important for reduce the risk of collisions with any user provided id\n const rootId = `_autogenerated-ds-pseudoRoot-${unsecureUuid()}`;\n const { opts, treeish } = args;\n const { getUniqueId, getChildrenKey } = opts;\n\n // a DSTree compatible datastructure has the following characteristics:\n // - it has a \"subitems\" property that contains an array of children\n // - it has a property that holds a unique string used to identify the node (accessed via the getUniqueId function)\n // - it is in an object format\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADCvB,oBAAuB;AAMvB,MAAM,eAAe,MACnB,uCAAuC,QAAQ,SAAS,CAAC,MAAM;AAC7D,QAAM,IAAI,KAAK,OAAO,IAAI,MAAM;AAEhC,QAAM,IAAI,MAAM,MAAM,IAAI,IAAI,KAAO;AACrC,SAAO,EAAE,SAAS,EAAE;AACtB,CAAC;AAUH,MAAM,cAAc,CAAmB;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AACF,MAMY;AACV,WAAS,IAAI;AACb,QAAM,WAAW,MAAM,YAAY,IAAI;AACvC,MAAI,MAAM,QAAQ,QAAQ,KAAK,SAAS,SAAS,GAAG;AAClD,aAAS,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK,GAAG;AAC3C,kBAAe,EAAE,UAAU,MAAM,SAAS,CAAC,GAAG,KAAK,CAAC;AAAA,IACtD;AAAA,EACF;AACF;AAYO,MAAM,2BAA2B,CAA4B,SAMnC;AAE/B,QAAM,SAAS,gCAAgC,aAAa,CAAC;AAC7D,QAAM,EAAE,MAAM,QAAQ,IAAI;AAC1B,QAAM,EAAE,aAAa,eAAe,IAAI;
|
|
4
|
+
"sourcesContent": ["/* eslint-disable max-statements */\nimport { DSTree } from '../../DSTree.js';\nimport type { OverloadedItem } from '../../types.js';\n\n// we don't really need a 100% sure unique id, since we prepend a string that is most likely unique already\n// we just need to reduce the risk of collisions\n// we avoid depending on a library for this:\nconst unsecureUuid = () =>\n 'xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {\n const r = Math.random() * 16 || 0;\n // eslint-disable-next-line no-bitwise\n const v = c === 'x' ? r : r & 0x3 || 0x8;\n return v.toString(16);\n });\n\n/*\n * @param {Object} args\n * @param {Function} args.callback - a function that will be called for each node in the treeish data-structure\n * @param {Object} args.node - the node that is being currently visited\n * @param {Object} args.opts - an object that holds the opinions of the caller on how to walk the treeish data-structure\n * @param {Function} args.opts.getChildren - a function that given a node returns an array of children\n * @returns {void}\n */\nconst walkTreeish = <T extends object>({\n callback,\n node,\n opts,\n}: {\n callback: (node: T) => void;\n node: T;\n opts?: {\n getChildren: (node: T) => T[];\n };\n}): void => {\n callback(node);\n const children = opts?.getChildren(node);\n if (Array.isArray(children) && children.length > 0) {\n for (let i = 0; i < children.length; i += 1) {\n walkTreeish<T>({ callback, node: children[i], opts });\n }\n }\n};\n\n/*\n * a function that given a treeish array and some options returns a DSTree datastructure that compltely preserves the treeish array\n * but still allows to use the full power of the DSTree datastructure\n * NOTE: This create a deep clone of the treeish array, so it's not suitable for large trees and will not preserve any reference to the original treeish array\n * @param {Array} treeish - an array of items that rapresents a tree, this will be used to create a DSTree datastructure\n * @param {Object} opts - an object that governs how the treeish array will be converted to a DSTree datastructure\n * @param {Function} opts.getChildrenKey - a function that given a node returns the key used to access the node children\n * @param {Function} opts.getUniqueId - a function that given a node returns a unique string used to identify the node\n * @returns {DSTree} - a DSTree datastructure\n */\nexport const fromTreeishArrayToDSTree = <T extends object = object>(args: {\n treeish: T[];\n opts: {\n getChildrenKey: (node: T) => keyof T;\n getUniqueId: (item: T) => string;\n };\n}): DSTree<OverloadedItem<T>> => {\n // we use crypto to generate a unique id for the root, this is important for reduce the risk of collisions with any user provided id\n const rootId = `_autogenerated-ds-pseudoRoot-${unsecureUuid()}`;\n const { opts, treeish } = args;\n const { getUniqueId, getChildrenKey } = opts;\n\n // a DSTree compatible datastructure has the following characteristics:\n // - it has a \"subitems\" property that contains an array of children\n // - it has a property that holds a unique string used to identify the node (accessed via the getUniqueId function)\n // - it is in an object format\n const pseudoRoot: OverloadedItem<T> = {\n id: rootId,\n subitems: structuredClone(treeish) as unknown as OverloadedItem<T>[],\n originalNodeData: {} as T,\n };\n // we now create an over-charged getChildren function\n // this is because we mutate the object every step during the walk\n // this function is going to receive the OverloadedItem<T> each step\n const overloadedGetChildren = (node: OverloadedItem<T>) => node.subitems;\n const overloadedGetUniqueId = (node: OverloadedItem<T>) => node.id;\n // we now create a \"callback\" function that will be used when walking the pseudoRoot object.\n // this callback will mutate the pseudoRoot object, making sure that after the mutation it will be compatible with the DSTree datastructure\n // we can't really make an assumption that the subitems key isn't somehow already part of the data from the user,\n // so to avoid any collision we will create an extra-level of nesting, in this layer only 3 properties will be allowed:\n // - id: a unique string used to identify the node, this is already a requirement from the treeish datastructure provided by the user\n // - subitems: an array of children\n // - original: the original data provided by the user\n // we remove the original tree rapresentation from the node, we only want one source of truth for the tree\n // if we don't remove this, when operating the DSTree we would have to somehow also propagate the changes to the original tree\n // the way this is intended to be used is instead to convert back and forth between the DSTree and the treeish array\n // the conversion will restore the treeish structure with the updated tree after operating on the DSTree\n const callback = (node: OverloadedItem<T>) => {\n // we skip the root node\n if (node.id === rootId) return;\n // we safe-keep the original data provided by the user\n const originalNodeData = structuredClone(node) as unknown as T;\n // we now mutate the node, making it compatible with the DSTree datastructure\n // first we clean all the properties\n Object.keys(node).forEach((key) => {\n delete node[key];\n });\n // we now add the properties that are required by the DSTree datastructure\n const overloadedNode = node as unknown as OverloadedItem<T>;\n const childrenKey = getChildrenKey(originalNodeData);\n overloadedNode.id = getUniqueId(originalNodeData);\n overloadedNode.subitems = originalNodeData[childrenKey] as OverloadedItem<T>[];\n delete originalNodeData[childrenKey];\n overloadedNode.originalNodeData = originalNodeData;\n };\n // we now walk the pseudoRoot object, mutating it in the process\n // @ts-expect-error this is an extremely opinionated algorithm that was built as a one-off, we are not spending time to make it typesafe\n walkTreeish<OverloadedItem<T>>({ callback, node: pseudoRoot, opts: { getChildren: overloadedGetChildren } });\n\n // we know that pseudoRoot is an item after we have walked and mutated it, so we can safely cast it\n return new DSTree<OverloadedItem<T>>(pseudoRoot, { getUniqueId: overloadedGetUniqueId });\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADCvB,oBAAuB;AAMvB,MAAM,eAAe,MACnB,uCAAuC,QAAQ,SAAS,CAAC,MAAM;AAC7D,QAAM,IAAI,KAAK,OAAO,IAAI,MAAM;AAEhC,QAAM,I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a,sBAAsB,CAAC;AACzF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/react-desc-prop-types.ts", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["import { PropTypes, type ValidationMap } from '@elliemae/ds-props-helpers';\nimport type { Node } from './Node.js';\nimport type {\n AddOptions,\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,8BAA8C;
|
|
4
|
+
"sourcesContent": ["import { PropTypes, type ValidationMap } from '@elliemae/ds-props-helpers';\nimport type { Node } from './Node.js';\nimport type {\n AddOptions,\n AnyObjectWithoutReservedKeys as AnyObjectWithoutReservedKeysToRexport,\n Item as ItemToRexport,\n MoveOptions,\n MutateOptions,\n RemoveOptions\n} from './types.js';\n\nexport declare namespace UseDSTreeT {\n export type AnyObjectWithoutReservedKeys = AnyObjectWithoutReservedKeysToRexport;\n export type Item<AppInterface extends AnyObjectWithoutReservedKeys = Record<string, unknown>> =\n ItemToRexport<AppInterface>;\n\n export type TreeNode<AppInterface extends AnyObjectWithoutReservedKeysToRexport = Record<string, unknown>> =\n Node<AppInterface>;\n export type TreeItem<AppInterface extends AnyObjectWithoutReservedKeysToRexport = Record<string, unknown>> =\n Item<AppInterface>;\n export type FirstParameter<AppInterface extends AnyObjectWithoutReservedKeysToRexport = Record<string, unknown>> =\n TreeItem<AppInterface>;\n\n export type SecondParameter<AppInterface extends AnyObjectWithoutReservedKeysToRexport = Record<string, unknown>> = {\n getUniqueId: (item: TreeItem<AppInterface>) => string | number;\n };\n\n export interface OutputT<AppInterface extends AnyObjectWithoutReservedKeysToRexport = Record<string, unknown>> {\n hash: number;\n getRoot: () => Node<AppInterface>;\n getNode: (id: string | number) => Node<AppInterface>;\n walk: (callback: (node: Node<AppInterface>) => boolean) => void;\n walkParents: (callback: (node: Node<AppInterface>) => boolean) => void;\n findNode: (callback: (node: Node<AppInterface>) => boolean) => Node<AppInterface> | null;\n findAllNodes: (callback: (node: Node<AppInterface>) => boolean) => Node<AppInterface>[];\n flatten: () => Node<AppInterface>[];\n addNode: (item: ItemToRexport<AppInterface>, options?: AddOptions<AppInterface>) => Node<AppInterface>;\n removeNode: (id: string | number, options?: RemoveOptions<AppInterface>) => Node<AppInterface>;\n moveNode: (id: string | number, options?: MoveOptions<AppInterface>) => Node<AppInterface>;\n replaceNode: (\n id: string | number,\n item: ItemToRexport<AppInterface>,\n options?: MutateOptions<AppInterface>,\n ) => Node<AppInterface>;\n getPath: (id: string | number) => Node<AppInterface>[];\n getPathIds: (id: string | number) => (string | number)[];\n }\n}\n\nconst itemShape = {\n dsId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).description('Id of the root item.'),\n label: PropTypes.string.description('Item label.'),\n '[key]': PropTypes.string.description('Any custom key you want to add to the item.'),\n};\n\nexport const UseDSTreePropTypes = {\n rootItem: PropTypes.shape({\n ...itemShape,\n subitems: PropTypes.arrayOf(PropTypes.shape(itemShape)).description(\n 'Array of subitems. Each subitem can also have subitems.',\n ),\n }).description('First parameter.').isRequired,\n opts: PropTypes.shape({\n getUniqueId: PropTypes.func\n .signature('(item) => string | number')\n .description('Callback to get the id of each item.').isRequired,\n }).description('Second parameter.').isRequired,\n} as ValidationMap<unknown>;\n\nexport const UseDSTreeReturnType = {\n hash: PropTypes.number.description('Tree hash value.'),\n getRoot: PropTypes.func.signature('() => rootItem').description('Callback to get the root item.'),\n getNode: PropTypes.func.signature('(id: string | number) => item').description('Callback to get an item by id.'),\n walk: PropTypes.func\n .signature('(callback: (item: FirstParameter) => boolean) => void')\n .description('Callback applied to each item to determine whether to continue walking or not.'),\n walkParents: PropTypes.func\n .signature('(callback: (item: FirstParameter) => boolean) => void')\n .description(\"Callback applied to each item to determine whether to continue walking the item's parents or not.\"),\n findNode: PropTypes.func\n .signature('(callback: (item: FirstParameter) => boolean) => FirstParameter | null')\n .description('Callback to find an item that matches the condition.'),\n findAllNodes: PropTypes.func\n .signature('(callback: (item: FirstParameter) => boolean) => FirstParameter[]')\n .description('Callback to find all the items that matches the condition.'),\n flatten: PropTypes.func.signature('() => item[]').description('Returns an array of hte tree items.'),\n addNode: PropTypes.func\n .signature('(item: FirstParameter, options?: AddOptions<FirstParameter> | undefined) => FirstParameter')\n .description('Adds an item to the tree.'),\n removeNode: PropTypes.func\n .signature('(id: string, options?: RemoveOptions<FirstParameter> | undefined) => FirstParameter')\n .description('Removes an item from the tree.'),\n moveNode: PropTypes.func\n .signature('(id: string, options?: MoveOptions<FirstParameter> | undefined) => FirstParameter')\n .description('Move an item within the tree.'),\n replaceNode: PropTypes.func\n .signature(\n 'id: string, item: FirstParameter, options?: MutateOptions<FirstParameter> | undefined) => FirstParameter',\n )\n .description('Replace a noe within the tree.'),\n getPath: PropTypes.func\n .signature('(id: string | number) => FirstParameter[]')\n .description(\"Get the path to an item given the item's id.\"),\n getPathIds: PropTypes.func\n .signature('(id: string | number) => (string | number)[]')\n .description(\"Get the path ids to an item given the item's id.\"),\n} as ValidationMap<unknown>;\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,8BAA8C;AAiD9C,MAAM,YAAY;AAAA,EAChB,MAAM,kCAAU,UAAU,CAAC,kCAAU,QAAQ,kCAAU,MAAM,CAAC,EAAE,YAAY,sBAAsB;AAAA,EAClG,OAAO,kCAAU,OAAO,YAAY,aAAa;AAAA,EACjD,SAAS,kCAAU,OAAO,YAAY,6CAA6C;AACrF;AAEO,MAAM,qBAAqB;AAAA,EAChC,UAAU,kCAAU,MAAM;AAAA,IACxB,GAAG;AAAA,IACH,UAAU,kCAAU,QAAQ,kCAAU,MAAM,SAAS,CAAC,EAA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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/types.ts", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["import type { DSTree } from './DSTree.js';\nimport type { Node } from './Node.js';\n\nexport type AnyObjectWithoutReservedKeys = Omit<Record<string, unknown>, '
|
|
4
|
+
"sourcesContent": ["import type { DSTree } from './DSTree.js';\nimport type { Node } from './Node.js';\n\nexport type AnyObjectWithoutReservedKeys = Omit<Record<string, unknown>, 'subitems'>;\n\nexport type Item<AppInterface extends AnyObjectWithoutReservedKeys = Record<string, unknown>> = AppInterface & {\n // this is not forced, this is \"optional\" in the model itself, but it's the standard way to identify a node in dimsum components\n // the tree-model itself doesn't care about this, but do add a .dsId to the node (and not to the .plainItem) based on getUniqueId\n // dsId: string | number;\n subitems?: Item<AppInterface>[] | ReadonlyArray<Item<AppInterface>>;\n};\n\nexport interface NodeConstructorOptions<AppInterface extends AnyObjectWithoutReservedKeys = Record<string, unknown>> {\n childIndex: number;\n depth: number;\n tree: DSTree<AppInterface>;\n parent?: Node<AppInterface> | null;\n}\n\nexport interface AddOptions<AppInterface extends AnyObjectWithoutReservedKeys = Record<string, unknown>> {\n position?: number;\n parent?: Node<AppInterface> | null;\n callback?: (node: Node<AppInterface>, tree: DSTree<AppInterface>) => void;\n}\n\nexport interface RemoveOptions<AppInterface extends AnyObjectWithoutReservedKeys = Record<string, unknown>> {\n callback?: (node: Node<AppInterface>, tree: DSTree<AppInterface>) => void;\n}\n\nexport interface MoveOptions<AppInterface extends AnyObjectWithoutReservedKeys = Record<string, unknown>> {\n position?: number;\n parent?: Node<AppInterface>;\n callback?: (node: Node<AppInterface>, tree: DSTree<AppInterface>) => void;\n}\n\nexport interface MutateOptions<AppInterface extends AnyObjectWithoutReservedKeys = Record<string, unknown>> {\n callback?: (node: Node<AppInterface>, tree: DSTree<AppInterface>) => void;\n}\nexport interface OverloadedItem<AppTypedItem extends object = object> extends Item {\n id: string;\n subitems: OverloadedItem<AppTypedItem>[] | ReadonlyArray<OverloadedItem<AppTypedItem>>;\n originalNodeData: AppTypedItem;\n}\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;ACAA,YAAuB;",
|
|
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/typescript-testing/typescript-use-ds-tree-valid.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable @typescript-eslint/no-unused-vars, no-unused-vars */\nimport { useDSTree } from '../index.js';\nimport type { UseDSTreeT } from '../index.js';\n\n// for the sake of this API, it's important that the app devs can pass their own interface for the item\ntype AppItemT = {\n zipcode: number;\n createdAt?: string;\n likesIceCream?: boolean;\n};\n\n// test we expose the namespace and the namespace follows our deliverable conventions\ntype AppTypedItem = UseDSTreeT.TreeItem<AppItemT>;\n\nconst testPropsInferedFirstParameter = {\n dsId: '_root',\n zipcode: 4444,\n subitems: [{ dsId: 'sub_item_id1', zipcode: 4444 }],\n};\n\nconst testExplicitDefinitionFirstParameter: AppTypedItem = {\n dsId: '_root',\n zipcode: 4444,\n subitems: [{ dsId: 'sub_item_id1', zipcode: 4444 }],\n};\n\nconst testExplicitAsDefinitionFirstParameter = {\n dsId: '_root',\n zipcode: 4444,\n subitems: [{ dsId: 'sub_item_id1', zipcode: 4444, createdAt: '2021-01-01', likesIceCream: true }],\n} as AppTypedItem;\n\nconst testDefinitionAsConstFirstParameter = {\n dsId: '_root',\n zipcode: 4444,\n subitems: [{ dsId: 'sub_item_id1', zipcode: 4444 }],\n} as const;\n\nconst testPropsInferedSecondParameter = {\n getUniqueId: (item: AppTypedItem) => item.dsId,\n};\nconst testPropsExplicitSecondParameter: UseDSTreeT.SecondParameter<AppTypedItem> = {\n getUniqueId: (item) => item.dsId,\n};\n\nconst testPropsExplicitAsSecondParameter = {\n getUniqueId: (item: AppTypedItem) => item.dsId,\n} as UseDSTreeT.SecondParameter<AppTypedItem>;\n\nconst testDefinitionAsConstSecondParameter = {\n getUniqueId: (item: AppTypedItem) => item.dsId,\n} as const;\n\n// this is an helper to be able to check the type of the output of getPathIds\ntype IdsArrayTypeChecker = (string | number)[];\nconst ExampleUsageComponent = () => {\n const {\n addNode,\n findAllNodes,\n findNode,\n flatten,\n getNode,\n getPath,\n getPathIds,\n getRoot,\n hash,\n moveNode,\n removeNode,\n replaceNode,\n walk,\n walkParents,\n } = useDSTree<AppItemT>(testExplicitDefinitionFirstParameter, testPropsExplicitSecondParameter);\n addNode({ dsId: 'sub_item_id2', zipcode: 4444 });\n findAllNodes((node) => node.plainItem.zipcode === 4444);\n findNode((node) => node.plainItem.zipcode === 4444);\n const nodes = flatten() as UseDSTreeT.TreeNode<AppItemT>[];\n\n const newlyAddedNode = getNode('sub_item_id2') as UseDSTreeT.TreeNode<AppItemT>;\n const path = getPath('sub_item_id2') as UseDSTreeT.TreeNode<AppItemT>[];\n const pathIds = getPathIds('sub_item_id2') as IdsArrayTypeChecker;\n const root = getRoot() as UseDSTreeT.TreeNode<AppItemT>;\n moveNode('sub_item_id1', { position: 0, parent: newlyAddedNode });\n removeNode('sub_item_id1');\n replaceNode('sub_item_id2', { dsId: 'sub_item_id2', zipcode: 4433 });\n walk((node) => node.plainItem.zipcode === 4433);\n walkParents((node) => node.plainItem.zipcode === 4433);\n\n const outputExplicitAs = useDSTree<AppItemT>(\n testExplicitAsDefinitionFirstParameter,\n testPropsExplicitAsSecondParameter,\n );\n const outputConst = useDSTree<AppItemT>(testDefinitionAsConstFirstParameter, testDefinitionAsConstSecondParameter);\n\n const outputInfered = useDSTree<AppItemT>(testPropsInferedFirstParameter, testPropsInferedSecondParameter);\n\n return null;\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA,YAAuB;ACCvB,eAA0B;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable @typescript-eslint/no-unused-vars, no-unused-vars */\nimport { useDSTree } from '../index.js';\nimport type { UseDSTreeT } from '../index.js';\n\n// for the sake of this API, it's important that the app devs can pass their own interface for the item\ntype AppItemT = {\n dsId: string;\n zipcode: number;\n createdAt?: string;\n likesIceCream?: boolean;\n};\n\n// test we expose the namespace and the namespace follows our deliverable conventions\ntype AppTypedItem = UseDSTreeT.TreeItem<AppItemT>;\n\nconst testPropsInferedFirstParameter = {\n dsId: '_root',\n zipcode: 4444,\n subitems: [{ dsId: 'sub_item_id1', zipcode: 4444 }],\n};\n\nconst testExplicitDefinitionFirstParameter: AppTypedItem = {\n dsId: '_root',\n zipcode: 4444,\n subitems: [{ dsId: 'sub_item_id1', zipcode: 4444 }],\n};\n\nconst testExplicitAsDefinitionFirstParameter = {\n dsId: '_root',\n zipcode: 4444,\n subitems: [{ dsId: 'sub_item_id1', zipcode: 4444, createdAt: '2021-01-01', likesIceCream: true }],\n} as AppTypedItem;\n\nconst testDefinitionAsConstFirstParameter = {\n dsId: '_root',\n zipcode: 4444,\n subitems: [{ dsId: 'sub_item_id1', zipcode: 4444 }],\n} as const;\n\nconst testPropsInferedSecondParameter = {\n getUniqueId: (item: AppTypedItem) => item.dsId,\n};\nconst testPropsExplicitSecondParameter: UseDSTreeT.SecondParameter<AppTypedItem> = {\n getUniqueId: (item) => item.dsId,\n};\n\nconst testPropsExplicitAsSecondParameter = {\n getUniqueId: (item: AppTypedItem) => item.dsId,\n} as UseDSTreeT.SecondParameter<AppTypedItem>;\n\nconst testDefinitionAsConstSecondParameter = {\n getUniqueId: (item: AppTypedItem) => item.dsId,\n} as const;\n\n// this is an helper to be able to check the type of the output of getPathIds\ntype IdsArrayTypeChecker = (string | number)[];\nconst ExampleUsageComponent = () => {\n const {\n addNode,\n findAllNodes,\n findNode,\n flatten,\n getNode,\n getPath,\n getPathIds,\n getRoot,\n hash,\n moveNode,\n removeNode,\n replaceNode,\n walk,\n walkParents,\n } = useDSTree<AppItemT>(testExplicitDefinitionFirstParameter, testPropsExplicitSecondParameter);\n addNode({ dsId: 'sub_item_id2', zipcode: 4444 });\n findAllNodes((node) => node.plainItem.zipcode === 4444);\n findNode((node) => node.plainItem.zipcode === 4444);\n const nodes = flatten() as UseDSTreeT.TreeNode<AppItemT>[];\n\n const newlyAddedNode = getNode('sub_item_id2') as UseDSTreeT.TreeNode<AppItemT>;\n const path = getPath('sub_item_id2') as UseDSTreeT.TreeNode<AppItemT>[];\n const pathIds = getPathIds('sub_item_id2') as IdsArrayTypeChecker;\n const root = getRoot() as UseDSTreeT.TreeNode<AppItemT>;\n moveNode('sub_item_id1', { position: 0, parent: newlyAddedNode });\n removeNode('sub_item_id1');\n replaceNode('sub_item_id2', { dsId: 'sub_item_id2', zipcode: 4433 });\n walk((node) => node.plainItem.zipcode === 4433);\n walkParents((node) => node.plainItem.zipcode === 4433);\n\n const outputExplicitAs = useDSTree<AppItemT>(\n testExplicitAsDefinitionFirstParameter,\n testPropsExplicitAsSecondParameter,\n );\n const outputConst = useDSTree<AppItemT>(testDefinitionAsConstFirstParameter, testDefinitionAsConstSecondParameter);\n\n const outputInfered = useDSTree<AppItemT>(testPropsInferedFirstParameter, testPropsInferedSecondParameter);\n\n return null;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA,YAAuB;ACCvB,eAA0B;AAc1B,MAAM,iCAAiC;AAAA,EACrC,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU,CAAC,EAAE,MAAM,gBAAgB,SAAS,KAAK,CAAC;AACpD;AAEA,MAAM,uCAAqD;AAAA,EACzD,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU,CAAC,EAAE,MAAM,gBAAgB,SAAS,KAAK,CAAC;AACpD;AAEA,MAAM,yCAAyC;AAAA,EAC7C,MAAM;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KAAK,UAAU,YAAY,IAAI;AAErD,QAAM,uBAAmB;AAAA,IACvB;AAAA,IACA;AAAA,EACF;AACA,QAAM,kBAAc,oBAAoB,qCAAqC,oCAAoC;AAEjH,QAAM,oBAAgB,oBAAoB,gCAAgC,+BAA+B;AAEzG,SAAO;AACT;",
|
|
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 { describe } from '@elliemae/ds-props-helpers';\nimport { useCallback, useMemo, useState } from 'react';\nimport { DSTree } from './DSTree.js';\nimport type {\n AddOptions,\n MoveOptions,\n MutateOptions,\n RemoveOptions,\n AnyObjectWithoutReservedKeys,\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,8BAAyB;AACzB,mBAA+C;AAC/C,oBAAuB;AASvB,mCAAyE;AAElE,MAAM,YAAY,CACvB,UACA,SACG;AACH,QAAM,WAAO,sBAAQ,MAAM,IAAI,qBAAqB,UAAU,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC;AACrF,QAAM,CAAC,MAAM,OAAO,QAAI,uBAAS,KAAK,IAAI;AAE1C,QAAM,cAAU;AAAA,IACd,CAAC,
|
|
4
|
+
"sourcesContent": ["import { describe } from '@elliemae/ds-props-helpers';\nimport { useCallback, useMemo, useState } from 'react';\nimport { DSTree } from './DSTree.js';\nimport type {\n AddOptions,\n MoveOptions,\n MutateOptions,\n RemoveOptions,\n AnyObjectWithoutReservedKeys,\n Item,\n} from './types.js';\nimport { UseDSTreePropTypes, UseDSTreeReturnType, type UseDSTreeT } from './react-desc-prop-types.js';\n\nexport const useDSTree = <AppInterface extends AnyObjectWithoutReservedKeys = Record<string, unknown>>(\n rootItem: Item<AppInterface>,\n opts: UseDSTreeT.SecondParameter<AppInterface>,\n) => {\n const tree = useMemo(() => new DSTree<AppInterface>(rootItem, opts), [opts, rootItem]);\n const [hash, setHash] = useState(tree.hash);\n\n const addNode = useCallback(\n (item: Item<AppInterface>, options?: AddOptions<AppInterface>) => {\n const cb: AddOptions<AppInterface>['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<AppInterface>) => {\n const cb: RemoveOptions<AppInterface>['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<AppInterface>) => {\n const cb: MoveOptions<AppInterface>['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: Item<AppInterface>, options?: MutateOptions<AppInterface>) => {\n const cb: MutateOptions<AppInterface>['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 } as UseDSTreeT.OutputT<AppInterface>;\n};\n\nuseDSTree.displayName = 'useDSTree';\nexport const UseDSTreeWithSchema = describe(useDSTree);\nUseDSTreeWithSchema.propTypes = UseDSTreePropTypes;\nUseDSTreeWithSchema.returnType = UseDSTreeReturnType;\n", "import * as React from 'react';\nexport {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AAC,MAAM,WAAW;AACpE,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;AAEA,UAAU,cAAc;AACjB,MAAM,0BAAsB,kCAAS,SAAS;AACrD,oBAAoB,YAAY;AAChC,oBAAoB,aAAa;",
|
|
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", "/* eslint-disable no-underscore-dangle */\nimport type {\n AddOptions,\n AnyObjectWithoutReservedKeys,\n MoveOptions,\n MutateOptions,\n RemoveOptions,\n
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable no-underscore-dangle */\nimport type {\n AddOptions,\n AnyObjectWithoutReservedKeys,\n MoveOptions,\n MutateOptions,\n RemoveOptions,\n Item,\n} from './types.js';\nimport { Node } from './Node.js';\n\nexport class DSTree<AppInterface extends AnyObjectWithoutReservedKeys = Record<string, unknown>> {\n private root: Node<AppInterface>;\n\n private _hash: number;\n\n private nodes: Record<string | number, Node<AppInterface>>;\n\n getUniqueId: (item: Item<AppInterface>) => string | number;\n\n constructor(item: Item<AppInterface>, options: { getUniqueId: (item: Item<AppInterface>) => string | number }) {\n this.getUniqueId = options.getUniqueId;\n this.root = new Node<AppInterface>(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<AppInterface>): 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<AppInterface>): void {\n delete this.nodes[node.dsId];\n }\n\n get hash(): number {\n return this._hash;\n }\n\n getRoot = (): Node<AppInterface> => this.root;\n\n getNode = (id: string | number): Node<AppInterface> => this.nodes[id];\n\n getNodes = (): Record<string, Node<AppInterface>> => this.nodes;\n\n walk = (callback: (node: Node<AppInterface>) => boolean): void => {\n this.root.walk(callback);\n };\n\n walkParents = (callback: (node: Node<AppInterface>) => boolean): void => {\n this.root.walkParents(callback);\n };\n\n findNode = (callback: (node: Node<AppInterface>) => boolean): Node<AppInterface> | null =>\n this.root.findNode(callback);\n\n findAllNodes = (callback: (node: Node<AppInterface>) => boolean): Node<AppInterface>[] =>\n this.root.findAllNodes(callback);\n\n flatten = (): Node<AppInterface>[] => this.root.flatten();\n\n addNode = (item: Item<AppInterface>, options: AddOptions<AppInterface> = {}): Node<AppInterface> => {\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<AppInterface>(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<AppInterface> = {}): Node<AppInterface> => {\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<AppInterface> = {}): Node<AppInterface> => {\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 = (\n id: string | number,\n item: Item<AppInterface>,\n options: MutateOptions<AppInterface> = {},\n ): Node<AppInterface> => {\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<AppInterface>[] => this.getRoot().getPath(id);\n\n getPathIds = (id: string | number) => this.getRoot().getPathIds(id);\n}\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACSvB,SAAS,YAAY;AAEd,MAAM,OAAoF;AAAA,EAS/F,YAAY,MAA0B,SAAyE;AA+B/G,mBAAU,MAA0B,KAAK;AAEzC,mBAAU,CAAC,OAA4C,KAAK,MAAM,EAAE;AAEpE,oBAAW,MAA0C,KAAK;AAE1D,gBAAO,CAAC,aAA0D;AAChE,WAAK,KAAK,KAAK,QAAQ;AAAA,IACzB;AAEA,uBAAc,CAAC,aAA0D;AACvE,WAAK,KAAK,YAAY,QAAQ;AAAA,IAChC;AAEA,oBAAW,CAAC,aACV,KAAK,KAAK,SAAS,QAAQ;AAE7B,wBAAe,CAAC,aACd,KAAK,KAAK,aAAa,QAAQ;AAEjC,mBAAU,MAA4B,KAAK,KAAK,QAAQ;AAExD,mBAAU,CAAC,MAA0B,UAAoC,CAAC,MAA0B;AAClG,YAAM,EAAE,UAAU,QAAQ,SAAS,IAAI;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ChF,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,MAAgC;AAEvD,QAAI,KAAK,MAAM,KAAK,IAAI,GAAG;AACzB,YAAM,IAAI,MAAM,yBAAyB,KAAK,IAAI,EAAE;AAAA,IACtD;AAEA,SAAK,MAAM,KAAK,IAAI,IAAI;AAAA,EAC1B;AAAA,EAEA,8BAA8B,MAAgC;AAC5D,WAAO,KAAK,MAAM,KAAK,IAAI;AAAA,EAC7B;AAAA,EAEA,IAAI,OAAe;AACjB,WAAO,KAAK;AAAA,EACd;AA0FF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/Node.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { cloneDeep
|
|
2
|
+
import { cloneDeep } from "lodash";
|
|
3
3
|
class Node {
|
|
4
4
|
constructor(item, { childIndex, depth, parent, tree }) {
|
|
5
5
|
// ===========================================================================
|
|
@@ -12,7 +12,7 @@ class Node {
|
|
|
12
12
|
this._hash += 1;
|
|
13
13
|
};
|
|
14
14
|
this.getCleanItem = (item) => {
|
|
15
|
-
const plainItem =
|
|
15
|
+
const { subitems, ...plainItem } = item;
|
|
16
16
|
return cloneDeep(plainItem);
|
|
17
17
|
};
|
|
18
18
|
this.walk = (callback) => {
|
|
@@ -95,22 +95,27 @@ class Node {
|
|
|
95
95
|
});
|
|
96
96
|
this._hash += 1;
|
|
97
97
|
};
|
|
98
|
-
|
|
99
|
-
this.dsId = tree.getUniqueId(itemCasted);
|
|
98
|
+
this.dsId = tree.getUniqueId(item);
|
|
100
99
|
this.childIndex = childIndex;
|
|
101
100
|
this.depth = depth;
|
|
102
101
|
this.parent = parent ?? null;
|
|
103
102
|
this.tree = tree;
|
|
104
103
|
this._hash = 0;
|
|
105
|
-
this.children =
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
104
|
+
this.children = [];
|
|
105
|
+
this.plainChildren = [];
|
|
106
|
+
const subitems = item.subitems ?? [];
|
|
107
|
+
subitems.forEach((subitem, index) => {
|
|
108
|
+
this.plainChildren.push(this.getCleanItem(subitem));
|
|
109
|
+
this.children.push(
|
|
110
|
+
new Node(subitem, {
|
|
111
|
+
childIndex: index,
|
|
112
|
+
depth: depth + 1,
|
|
113
|
+
parent: this,
|
|
114
|
+
tree
|
|
115
|
+
})
|
|
116
|
+
);
|
|
117
|
+
});
|
|
118
|
+
this.plainItem = this.getCleanItem(item);
|
|
114
119
|
}
|
|
115
120
|
// ===========================================================================
|
|
116
121
|
// READ METHODS
|
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
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACGvB,SAAS,
|
|
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"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACGvB,SAAS,iBAAiB;AAInB,MAAM,KAAkF;AAAA,EAmB7F,YAAY,MAA0B,EAAE,YAAY,OAAO,QAAQ,KAAK,GAAyC;AAgCjH;AAA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,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,EAsBA,IAAI,OAAe;AACjB,WAAO,KAAK;AAAA,EACd;AAmHF;",
|
|
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/adapters/arraish-tree/fromTreeishArrayToDSTree.ts"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-statements */\nimport { DSTree } from '../../DSTree.js';\nimport type { OverloadedItem } from '../../types.js';\n\n// we don't really need a 100% sure unique id, since we prepend a string that is most likely unique already\n// we just need to reduce the risk of collisions\n// we avoid depending on a library for this:\nconst unsecureUuid = () =>\n 'xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {\n const r = Math.random() * 16 || 0;\n // eslint-disable-next-line no-bitwise\n const v = c === 'x' ? r : r & 0x3 || 0x8;\n return v.toString(16);\n });\n\n/*\n * @param {Object} args\n * @param {Function} args.callback - a function that will be called for each node in the treeish data-structure\n * @param {Object} args.node - the node that is being currently visited\n * @param {Object} args.opts - an object that holds the opinions of the caller on how to walk the treeish data-structure\n * @param {Function} args.opts.getChildren - a function that given a node returns an array of children\n * @returns {void}\n */\nconst walkTreeish = <T extends object>({\n callback,\n node,\n opts,\n}: {\n callback: (node: T) => void;\n node: T;\n opts?: {\n getChildren: (node: T) => T[];\n };\n}): void => {\n callback(node);\n const children = opts?.getChildren(node);\n if (Array.isArray(children) && children.length > 0) {\n for (let i = 0; i < children.length; i += 1) {\n walkTreeish<T>({ callback, node: children[i], opts });\n }\n }\n};\n\n/*\n * a function that given a treeish array and some options returns a DSTree datastructure that compltely preserves the treeish array\n * but still allows to use the full power of the DSTree datastructure\n * NOTE: This create a deep clone of the treeish array, so it's not suitable for large trees and will not preserve any reference to the original treeish array\n * @param {Array} treeish - an array of items that rapresents a tree, this will be used to create a DSTree datastructure\n * @param {Object} opts - an object that governs how the treeish array will be converted to a DSTree datastructure\n * @param {Function} opts.getChildrenKey - a function that given a node returns the key used to access the node children\n * @param {Function} opts.getUniqueId - a function that given a node returns a unique string used to identify the node\n * @returns {DSTree} - a DSTree datastructure\n */\nexport const fromTreeishArrayToDSTree = <T extends object = object>(args: {\n treeish: T[];\n opts: {\n getChildrenKey: (node: T) => keyof T;\n getUniqueId: (item: T) => string;\n };\n}): DSTree<OverloadedItem<T>> => {\n // we use crypto to generate a unique id for the root, this is important for reduce the risk of collisions with any user provided id\n const rootId = `_autogenerated-ds-pseudoRoot-${unsecureUuid()}`;\n const { opts, treeish } = args;\n const { getUniqueId, getChildrenKey } = opts;\n\n // a DSTree compatible datastructure has the following characteristics:\n // - it has a \"subitems\" property that contains an array of children\n // - it has a property that holds a unique string used to identify the node (accessed via the getUniqueId function)\n // - it is in an object format\n
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACCvB,SAAS,cAAc;AAMvB,MAAM,eAAe,MACnB,uCAAuC,QAAQ,SAAS,CAAC,MAAM;AAC7D,QAAM,IAAI,KAAK,OAAO,IAAI,MAAM;AAEhC,QAAM,IAAI,MAAM,MAAM,IAAI,IAAI,KAAO;AACrC,SAAO,EAAE,SAAS,EAAE;AACtB,CAAC;AAUH,MAAM,cAAc,CAAmB;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AACF,MAMY;AACV,WAAS,IAAI;AACb,QAAM,WAAW,MAAM,YAAY,IAAI;AACvC,MAAI,MAAM,QAAQ,QAAQ,KAAK,SAAS,SAAS,GAAG;AAClD,aAAS,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK,GAAG;AAC3C,kBAAe,EAAE,UAAU,MAAM,SAAS,CAAC,GAAG,KAAK,CAAC;AAAA,IACtD;AAAA,EACF;AACF;AAYO,MAAM,2BAA2B,CAA4B,SAMnC;AAE/B,QAAM,SAAS,gCAAgC,aAAa,CAAC;AAC7D,QAAM,EAAE,MAAM,QAAQ,IAAI;AAC1B,QAAM,EAAE,aAAa,eAAe,IAAI;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-statements */\nimport { DSTree } from '../../DSTree.js';\nimport type { OverloadedItem } from '../../types.js';\n\n// we don't really need a 100% sure unique id, since we prepend a string that is most likely unique already\n// we just need to reduce the risk of collisions\n// we avoid depending on a library for this:\nconst unsecureUuid = () =>\n 'xxxxxxxx-xxxx-xxxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {\n const r = Math.random() * 16 || 0;\n // eslint-disable-next-line no-bitwise\n const v = c === 'x' ? r : r & 0x3 || 0x8;\n return v.toString(16);\n });\n\n/*\n * @param {Object} args\n * @param {Function} args.callback - a function that will be called for each node in the treeish data-structure\n * @param {Object} args.node - the node that is being currently visited\n * @param {Object} args.opts - an object that holds the opinions of the caller on how to walk the treeish data-structure\n * @param {Function} args.opts.getChildren - a function that given a node returns an array of children\n * @returns {void}\n */\nconst walkTreeish = <T extends object>({\n callback,\n node,\n opts,\n}: {\n callback: (node: T) => void;\n node: T;\n opts?: {\n getChildren: (node: T) => T[];\n };\n}): void => {\n callback(node);\n const children = opts?.getChildren(node);\n if (Array.isArray(children) && children.length > 0) {\n for (let i = 0; i < children.length; i += 1) {\n walkTreeish<T>({ callback, node: children[i], opts });\n }\n }\n};\n\n/*\n * a function that given a treeish array and some options returns a DSTree datastructure that compltely preserves the treeish array\n * but still allows to use the full power of the DSTree datastructure\n * NOTE: This create a deep clone of the treeish array, so it's not suitable for large trees and will not preserve any reference to the original treeish array\n * @param {Array} treeish - an array of items that rapresents a tree, this will be used to create a DSTree datastructure\n * @param {Object} opts - an object that governs how the treeish array will be converted to a DSTree datastructure\n * @param {Function} opts.getChildrenKey - a function that given a node returns the key used to access the node children\n * @param {Function} opts.getUniqueId - a function that given a node returns a unique string used to identify the node\n * @returns {DSTree} - a DSTree datastructure\n */\nexport const fromTreeishArrayToDSTree = <T extends object = object>(args: {\n treeish: T[];\n opts: {\n getChildrenKey: (node: T) => keyof T;\n getUniqueId: (item: T) => string;\n };\n}): DSTree<OverloadedItem<T>> => {\n // we use crypto to generate a unique id for the root, this is important for reduce the risk of collisions with any user provided id\n const rootId = `_autogenerated-ds-pseudoRoot-${unsecureUuid()}`;\n const { opts, treeish } = args;\n const { getUniqueId, getChildrenKey } = opts;\n\n // a DSTree compatible datastructure has the following characteristics:\n // - it has a \"subitems\" property that contains an array of children\n // - it has a property that holds a unique string used to identify the node (accessed via the getUniqueId function)\n // - it is in an object format\n const pseudoRoot: OverloadedItem<T> = {\n id: rootId,\n subitems: structuredClone(treeish) as unknown as OverloadedItem<T>[],\n originalNodeData: {} as T,\n };\n // we now create an over-charged getChildren function\n // this is because we mutate the object every step during the walk\n // this function is going to receive the OverloadedItem<T> each step\n const overloadedGetChildren = (node: OverloadedItem<T>) => node.subitems;\n const overloadedGetUniqueId = (node: OverloadedItem<T>) => node.id;\n // we now create a \"callback\" function that will be used when walking the pseudoRoot object.\n // this callback will mutate the pseudoRoot object, making sure that after the mutation it will be compatible with the DSTree datastructure\n // we can't really make an assumption that the subitems key isn't somehow already part of the data from the user,\n // so to avoid any collision we will create an extra-level of nesting, in this layer only 3 properties will be allowed:\n // - id: a unique string used to identify the node, this is already a requirement from the treeish datastructure provided by the user\n // - subitems: an array of children\n // - original: the original data provided by the user\n // we remove the original tree rapresentation from the node, we only want one source of truth for the tree\n // if we don't remove this, when operating the DSTree we would have to somehow also propagate the changes to the original tree\n // the way this is intended to be used is instead to convert back and forth between the DSTree and the treeish array\n // the conversion will restore the treeish structure with the updated tree after operating on the DSTree\n const callback = (node: OverloadedItem<T>) => {\n // we skip the root node\n if (node.id === rootId) return;\n // we safe-keep the original data provided by the user\n const originalNodeData = structuredClone(node) as unknown as T;\n // we now mutate the node, making it compatible with the DSTree datastructure\n // first we clean all the properties\n Object.keys(node).forEach((key) => {\n delete node[key];\n });\n // we now add the properties that are required by the DSTree datastructure\n const overloadedNode = node as unknown as OverloadedItem<T>;\n const childrenKey = getChildrenKey(originalNodeData);\n overloadedNode.id = getUniqueId(originalNodeData);\n overloadedNode.subitems = originalNodeData[childrenKey] as OverloadedItem<T>[];\n delete originalNodeData[childrenKey];\n overloadedNode.originalNodeData = originalNodeData;\n };\n // we now walk the pseudoRoot object, mutating it in the process\n // @ts-expect-error this is an extremely opinionated algorithm that was built as a one-off, we are not spending time to make it typesafe\n walkTreeish<OverloadedItem<T>>({ callback, node: pseudoRoot, opts: { getChildren: overloadedGetChildren } });\n\n // we know that pseudoRoot is an item after we have walked and mutated it, so we can safely cast it\n return new DSTree<OverloadedItem<T>>(pseudoRoot, { getUniqueId: overloadedGetUniqueId });\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACCvB,SAAS,cAAc;AAMvB,MAAM,eAAe,MACnB,uCAAuC,QAAQ,SAAS,CAAC,MAAM;AAC7D,QAAM,IAAI,KAAK,OAAO,IAAI,MAAM;AAEhC,QAAM,IAAI,MAAM,MAAM,IAAI,IAAI,KAAO;AACrC,SAAO,EAAE,SAAS,EAAE;AACtB,CAAC;AAUH,MAAM,cAAc,CAAmB;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AACF,MAMY;AACV,WAAS,IAAI;AACb,QAAM,WAAW,MAAM,YAAY,IAAI;AACvC,MAAI,MAAM,QAAQ,QAAQ,KAAK,SAAS,SAAS,GAAG;AAClD,aAAS,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK,GAAG;AAC3C,kBAAe,EAAE,UAAU,MAAM,SAAS,CAAC,GAAG,KAAK,CAAC;AAAA,IACtD;AAAA,EACF;AACF;AAYO,MAAM,2BAA2B,CAA4B,SAMnC;AAE/B,QAAM,SAAS,gCAAgC,aAAa,CAAC;AAC7D,QAAM,EAAE,MAAM,QAAQ,IAAI;AAC1B,QAAM,EAAE,aAAa,eAAe,IAAI;AAMxC,QAAM,aAAgC;AAAA,IACpC,IAAI;AAAA,IACJ,UAAU,gBAAgB,OAAO;AAAA,IACjC,kBAAkB,CAAC;AAAA,EACrB;AAIA,QAAM,wBAAwB,CAAC,SAA4B,KAAK;AAChE,QAAM,wBAAwB,CAAC,SAA4B,KAAK;AAYhE,QAAM,WAAW,CAAC,SAA4B;AAE5C,QAAI,KAAK,OAAO,OAAQ;AAExB,UAAM,mBAAmB,gBAAgB,IAAI;AAG7C,WAAO,KAAK,IAAI,EAAE,QAAQ,CAAC,QAAQ;AACjC,aAAO,KAAK,GAAG;AAAA,IACjB,CAAC;AAED,UAAM,iBAAiB;AACvB,UAAM,cAAc,eAAe,gBAAgB;AACnD,mBAAe,KAAK,YAAY,gBAAgB;AAChD,mBAAe,WAAW,iBAAiB,WAAW;AACtD,WAAO,iBAAiB,WAAW;AACnC,mBAAe,mBAAmB;AAAA,EACpC;AAGA,cAA+B,EAAE,UAAU,MAAM,YAAY,MAAM,EAAE,aAAa,sBAAsB,EAAE,CAAC;AAG3G,SAAO,IAAI,OAA0B,YAAY,EAAE,aAAa,sBAAsB,CAAC;AACzF;",
|
|
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/react-desc-prop-types.ts"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { PropTypes, type ValidationMap } from '@elliemae/ds-props-helpers';\nimport type { Node } from './Node.js';\nimport type {\n AddOptions,\n
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,iBAAqC;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { PropTypes, type ValidationMap } from '@elliemae/ds-props-helpers';\nimport type { Node } from './Node.js';\nimport type {\n AddOptions,\n AnyObjectWithoutReservedKeys as AnyObjectWithoutReservedKeysToRexport,\n Item as ItemToRexport,\n MoveOptions,\n MutateOptions,\n RemoveOptions\n} from './types.js';\n\nexport declare namespace UseDSTreeT {\n export type AnyObjectWithoutReservedKeys = AnyObjectWithoutReservedKeysToRexport;\n export type Item<AppInterface extends AnyObjectWithoutReservedKeys = Record<string, unknown>> =\n ItemToRexport<AppInterface>;\n\n export type TreeNode<AppInterface extends AnyObjectWithoutReservedKeysToRexport = Record<string, unknown>> =\n Node<AppInterface>;\n export type TreeItem<AppInterface extends AnyObjectWithoutReservedKeysToRexport = Record<string, unknown>> =\n Item<AppInterface>;\n export type FirstParameter<AppInterface extends AnyObjectWithoutReservedKeysToRexport = Record<string, unknown>> =\n TreeItem<AppInterface>;\n\n export type SecondParameter<AppInterface extends AnyObjectWithoutReservedKeysToRexport = Record<string, unknown>> = {\n getUniqueId: (item: TreeItem<AppInterface>) => string | number;\n };\n\n export interface OutputT<AppInterface extends AnyObjectWithoutReservedKeysToRexport = Record<string, unknown>> {\n hash: number;\n getRoot: () => Node<AppInterface>;\n getNode: (id: string | number) => Node<AppInterface>;\n walk: (callback: (node: Node<AppInterface>) => boolean) => void;\n walkParents: (callback: (node: Node<AppInterface>) => boolean) => void;\n findNode: (callback: (node: Node<AppInterface>) => boolean) => Node<AppInterface> | null;\n findAllNodes: (callback: (node: Node<AppInterface>) => boolean) => Node<AppInterface>[];\n flatten: () => Node<AppInterface>[];\n addNode: (item: ItemToRexport<AppInterface>, options?: AddOptions<AppInterface>) => Node<AppInterface>;\n removeNode: (id: string | number, options?: RemoveOptions<AppInterface>) => Node<AppInterface>;\n moveNode: (id: string | number, options?: MoveOptions<AppInterface>) => Node<AppInterface>;\n replaceNode: (\n id: string | number,\n item: ItemToRexport<AppInterface>,\n options?: MutateOptions<AppInterface>,\n ) => Node<AppInterface>;\n getPath: (id: string | number) => Node<AppInterface>[];\n getPathIds: (id: string | number) => (string | number)[];\n }\n}\n\nconst itemShape = {\n dsId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).description('Id of the root item.'),\n label: PropTypes.string.description('Item label.'),\n '[key]': PropTypes.string.description('Any custom key you want to add to the item.'),\n};\n\nexport const UseDSTreePropTypes = {\n rootItem: PropTypes.shape({\n ...itemShape,\n subitems: PropTypes.arrayOf(PropTypes.shape(itemShape)).description(\n 'Array of subitems. Each subitem can also have subitems.',\n ),\n }).description('First parameter.').isRequired,\n opts: PropTypes.shape({\n getUniqueId: PropTypes.func\n .signature('(item) => string | number')\n .description('Callback to get the id of each item.').isRequired,\n }).description('Second parameter.').isRequired,\n} as ValidationMap<unknown>;\n\nexport const UseDSTreeReturnType = {\n hash: PropTypes.number.description('Tree hash value.'),\n getRoot: PropTypes.func.signature('() => rootItem').description('Callback to get the root item.'),\n getNode: PropTypes.func.signature('(id: string | number) => item').description('Callback to get an item by id.'),\n walk: PropTypes.func\n .signature('(callback: (item: FirstParameter) => boolean) => void')\n .description('Callback applied to each item to determine whether to continue walking or not.'),\n walkParents: PropTypes.func\n .signature('(callback: (item: FirstParameter) => boolean) => void')\n .description(\"Callback applied to each item to determine whether to continue walking the item's parents or not.\"),\n findNode: PropTypes.func\n .signature('(callback: (item: FirstParameter) => boolean) => FirstParameter | null')\n .description('Callback to find an item that matches the condition.'),\n findAllNodes: PropTypes.func\n .signature('(callback: (item: FirstParameter) => boolean) => FirstParameter[]')\n .description('Callback to find all the items that matches the condition.'),\n flatten: PropTypes.func.signature('() => item[]').description('Returns an array of hte tree items.'),\n addNode: PropTypes.func\n .signature('(item: FirstParameter, options?: AddOptions<FirstParameter> | undefined) => FirstParameter')\n .description('Adds an item to the tree.'),\n removeNode: PropTypes.func\n .signature('(id: string, options?: RemoveOptions<FirstParameter> | undefined) => FirstParameter')\n .description('Removes an item from the tree.'),\n moveNode: PropTypes.func\n .signature('(id: string, options?: MoveOptions<FirstParameter> | undefined) => FirstParameter')\n .description('Move an item within the tree.'),\n replaceNode: PropTypes.func\n .signature(\n 'id: string, item: FirstParameter, options?: MutateOptions<FirstParameter> | undefined) => FirstParameter',\n )\n .description('Replace a noe within the tree.'),\n getPath: PropTypes.func\n .signature('(id: string | number) => FirstParameter[]')\n .description(\"Get the path to an item given the item's id.\"),\n getPathIds: PropTypes.func\n .signature('(id: string | number) => (string | number)[]')\n .description(\"Get the path ids to an item given the item's id.\"),\n} as ValidationMap<unknown>;\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,iBAAqC;AAiD9C,MAAM,YAAY;AAAA,EAChB,MAAM,UAAU,UAAU,CAAC,UAAU,QAAQ,UAAU,MAAM,CAAC,EAAE,YAAY,sBAAsB;AAAA,EAClG,OAAO,UAAU,OAAO,YAAY,aAAa;AAAA,EACjD,SAAS,UAAU,OAAO,YAAY,6CAA6C;AACrF;AAEO,MAAM,qBAAqB;AAAA,EAChC,UAAU,UAAU,MAAM;AAAA,IACxB,GAAG;AAAA,IACH,UAAU,UAAU,QAAQ,UAAU,MAAM,SAAS,CAAC,EAAE;AAAA,MACtD;AAAA,IACF;AAAA,EACF,CAAC,EAAE,YAAY,kBAAkB,EAAE;AAAA,EACnC,MAAM,UAAU,MAAM;AAAA,IACpB,aAAa,UAAU,KACpB,UAAU,2BAA2B,EACrC,YAAY,sCAAsC,EAAE;AAAA,EACzD,CAAC,EAAE,YAAY,mBAAmB,EAAE;AACtC;AAEO,MAAM,sBAAsB;AAAA,EACjC,MAAM,UAAU,OAAO,YAAY,kBAAkB;AAAA,EACrD,SAAS,UAAU,KAAK,UAAU,gBAAgB,EAAE,YAAY,gCAAgC;AAAA,EAChG,SAAS,UAAU,KAAK,UAAU,+BAA+B,EAAE,YAAY,gCAAgC;AAAA,EAC/G,MAAM,UAAU,KACb,UAAU,uDAAuD,EACjE,YAAY,gFAAgF;AAAA,EAC/F,aAAa,UAAU,KACpB,UAAU,uDAAuD,EACjE,YAAY,mGAAmG;AAAA,EAClH,UAAU,UAAU,KACjB,UAAU,wEAAwE,EAClF,YAAY,sDAAsD;AAAA,EACrE,cAAc,UAAU,KACrB,UAAU,mEAAmE,EAC7E,YAAY,4DAA4D;AAAA,EAC3E,SAAS,UAAU,KAAK,UAAU,cAAc,EAAE,YAAY,qCAAqC;AAAA,EACnG,SAAS,UAAU,KAChB,UAAU,4FAA4F,EACtG,YAAY,2BAA2B;AAAA,EAC1C,YAAY,UAAU,KACnB,UAAU,qFAAqF,EAC/F,YAAY,gCAAgC;AAAA,EAC/C,UAAU,UAAU,KACjB,UAAU,mFAAmF,EAC7F,YAAY,+BAA+B;AAAA,EAC9C,aAAa,UAAU,KACpB;AAAA,IACC;AAAA,EACF,EACC,YAAY,gCAAgC;AAAA,EAC/C,SAAS,UAAU,KAChB,UAAU,2CAA2C,EACrD,YAAY,8CAA8C;AAAA,EAC7D,YAAY,UAAU,KACnB,UAAU,8CAA8C,EACxD,YAAY,kDAAkD;AACnE;",
|
|
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/typescript-testing/typescript-use-ds-tree-valid.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable @typescript-eslint/no-unused-vars, no-unused-vars */\nimport { useDSTree } from '../index.js';\nimport type { UseDSTreeT } from '../index.js';\n\n// for the sake of this API, it's important that the app devs can pass their own interface for the item\ntype AppItemT = {\n zipcode: number;\n createdAt?: string;\n likesIceCream?: boolean;\n};\n\n// test we expose the namespace and the namespace follows our deliverable conventions\ntype AppTypedItem = UseDSTreeT.TreeItem<AppItemT>;\n\nconst testPropsInferedFirstParameter = {\n dsId: '_root',\n zipcode: 4444,\n subitems: [{ dsId: 'sub_item_id1', zipcode: 4444 }],\n};\n\nconst testExplicitDefinitionFirstParameter: AppTypedItem = {\n dsId: '_root',\n zipcode: 4444,\n subitems: [{ dsId: 'sub_item_id1', zipcode: 4444 }],\n};\n\nconst testExplicitAsDefinitionFirstParameter = {\n dsId: '_root',\n zipcode: 4444,\n subitems: [{ dsId: 'sub_item_id1', zipcode: 4444, createdAt: '2021-01-01', likesIceCream: true }],\n} as AppTypedItem;\n\nconst testDefinitionAsConstFirstParameter = {\n dsId: '_root',\n zipcode: 4444,\n subitems: [{ dsId: 'sub_item_id1', zipcode: 4444 }],\n} as const;\n\nconst testPropsInferedSecondParameter = {\n getUniqueId: (item: AppTypedItem) => item.dsId,\n};\nconst testPropsExplicitSecondParameter: UseDSTreeT.SecondParameter<AppTypedItem> = {\n getUniqueId: (item) => item.dsId,\n};\n\nconst testPropsExplicitAsSecondParameter = {\n getUniqueId: (item: AppTypedItem) => item.dsId,\n} as UseDSTreeT.SecondParameter<AppTypedItem>;\n\nconst testDefinitionAsConstSecondParameter = {\n getUniqueId: (item: AppTypedItem) => item.dsId,\n} as const;\n\n// this is an helper to be able to check the type of the output of getPathIds\ntype IdsArrayTypeChecker = (string | number)[];\nconst ExampleUsageComponent = () => {\n const {\n addNode,\n findAllNodes,\n findNode,\n flatten,\n getNode,\n getPath,\n getPathIds,\n getRoot,\n hash,\n moveNode,\n removeNode,\n replaceNode,\n walk,\n walkParents,\n } = useDSTree<AppItemT>(testExplicitDefinitionFirstParameter, testPropsExplicitSecondParameter);\n addNode({ dsId: 'sub_item_id2', zipcode: 4444 });\n findAllNodes((node) => node.plainItem.zipcode === 4444);\n findNode((node) => node.plainItem.zipcode === 4444);\n const nodes = flatten() as UseDSTreeT.TreeNode<AppItemT>[];\n\n const newlyAddedNode = getNode('sub_item_id2') as UseDSTreeT.TreeNode<AppItemT>;\n const path = getPath('sub_item_id2') as UseDSTreeT.TreeNode<AppItemT>[];\n const pathIds = getPathIds('sub_item_id2') as IdsArrayTypeChecker;\n const root = getRoot() as UseDSTreeT.TreeNode<AppItemT>;\n moveNode('sub_item_id1', { position: 0, parent: newlyAddedNode });\n removeNode('sub_item_id1');\n replaceNode('sub_item_id2', { dsId: 'sub_item_id2', zipcode: 4433 });\n walk((node) => node.plainItem.zipcode === 4433);\n walkParents((node) => node.plainItem.zipcode === 4433);\n\n const outputExplicitAs = useDSTree<AppItemT>(\n testExplicitAsDefinitionFirstParameter,\n testPropsExplicitAsSecondParameter,\n );\n const outputConst = useDSTree<AppItemT>(testDefinitionAsConstFirstParameter, testDefinitionAsConstSecondParameter);\n\n const outputInfered = useDSTree<AppItemT>(testPropsInferedFirstParameter, testPropsInferedSecondParameter);\n\n return null;\n};\n"],
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACCvB,SAAS,iBAAiB;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable @typescript-eslint/no-unused-vars, no-unused-vars */\nimport { useDSTree } from '../index.js';\nimport type { UseDSTreeT } from '../index.js';\n\n// for the sake of this API, it's important that the app devs can pass their own interface for the item\ntype AppItemT = {\n dsId: string;\n zipcode: number;\n createdAt?: string;\n likesIceCream?: boolean;\n};\n\n// test we expose the namespace and the namespace follows our deliverable conventions\ntype AppTypedItem = UseDSTreeT.TreeItem<AppItemT>;\n\nconst testPropsInferedFirstParameter = {\n dsId: '_root',\n zipcode: 4444,\n subitems: [{ dsId: 'sub_item_id1', zipcode: 4444 }],\n};\n\nconst testExplicitDefinitionFirstParameter: AppTypedItem = {\n dsId: '_root',\n zipcode: 4444,\n subitems: [{ dsId: 'sub_item_id1', zipcode: 4444 }],\n};\n\nconst testExplicitAsDefinitionFirstParameter = {\n dsId: '_root',\n zipcode: 4444,\n subitems: [{ dsId: 'sub_item_id1', zipcode: 4444, createdAt: '2021-01-01', likesIceCream: true }],\n} as AppTypedItem;\n\nconst testDefinitionAsConstFirstParameter = {\n dsId: '_root',\n zipcode: 4444,\n subitems: [{ dsId: 'sub_item_id1', zipcode: 4444 }],\n} as const;\n\nconst testPropsInferedSecondParameter = {\n getUniqueId: (item: AppTypedItem) => item.dsId,\n};\nconst testPropsExplicitSecondParameter: UseDSTreeT.SecondParameter<AppTypedItem> = {\n getUniqueId: (item) => item.dsId,\n};\n\nconst testPropsExplicitAsSecondParameter = {\n getUniqueId: (item: AppTypedItem) => item.dsId,\n} as UseDSTreeT.SecondParameter<AppTypedItem>;\n\nconst testDefinitionAsConstSecondParameter = {\n getUniqueId: (item: AppTypedItem) => item.dsId,\n} as const;\n\n// this is an helper to be able to check the type of the output of getPathIds\ntype IdsArrayTypeChecker = (string | number)[];\nconst ExampleUsageComponent = () => {\n const {\n addNode,\n findAllNodes,\n findNode,\n flatten,\n getNode,\n getPath,\n getPathIds,\n getRoot,\n hash,\n moveNode,\n removeNode,\n replaceNode,\n walk,\n walkParents,\n } = useDSTree<AppItemT>(testExplicitDefinitionFirstParameter, testPropsExplicitSecondParameter);\n addNode({ dsId: 'sub_item_id2', zipcode: 4444 });\n findAllNodes((node) => node.plainItem.zipcode === 4444);\n findNode((node) => node.plainItem.zipcode === 4444);\n const nodes = flatten() as UseDSTreeT.TreeNode<AppItemT>[];\n\n const newlyAddedNode = getNode('sub_item_id2') as UseDSTreeT.TreeNode<AppItemT>;\n const path = getPath('sub_item_id2') as UseDSTreeT.TreeNode<AppItemT>[];\n const pathIds = getPathIds('sub_item_id2') as IdsArrayTypeChecker;\n const root = getRoot() as UseDSTreeT.TreeNode<AppItemT>;\n moveNode('sub_item_id1', { position: 0, parent: newlyAddedNode });\n removeNode('sub_item_id1');\n replaceNode('sub_item_id2', { dsId: 'sub_item_id2', zipcode: 4433 });\n walk((node) => node.plainItem.zipcode === 4433);\n walkParents((node) => node.plainItem.zipcode === 4433);\n\n const outputExplicitAs = useDSTree<AppItemT>(\n testExplicitAsDefinitionFirstParameter,\n testPropsExplicitAsSecondParameter,\n );\n const outputConst = useDSTree<AppItemT>(testDefinitionAsConstFirstParameter, testDefinitionAsConstSecondParameter);\n\n const outputInfered = useDSTree<AppItemT>(testPropsInferedFirstParameter, testPropsInferedSecondParameter);\n\n return null;\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACCvB,SAAS,iBAAiB;AAc1B,MAAM,iCAAiC;AAAA,EACrC,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU,CAAC,EAAE,MAAM,gBAAgB,SAAS,KAAK,CAAC;AACpD;AAEA,MAAM,uCAAqD;AAAA,EACzD,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU,CAAC,EAAE,MAAM,gBAAgB,SAAS,KAAK,CAAC;AACpD;AAEA,MAAM,yCAAyC;AAAA,EAC7C,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU,CAAC,EAAE,MAAM,gBAAgB,SAAS,MAAM,WAAW,cAAc,eAAe,KAAK,CAAC;AAClG;AAEA,MAAM,sCAAsC;AAAA,EAC1C,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU,CAAC,EAAE,MAAM,gBAAgB,SAAS,KAAK,CAAC;AACpD;AAEA,MAAM,kCAAkC;AAAA,EACtC,aAAa,CAAC,SAAuB,KAAK;AAC5C;AACA,MAAM,mCAA6E;AAAA,EACjF,aAAa,CAAC,SAAS,KAAK;AAC9B;AAEA,MAAM,qCAAqC;AAAA,EACzC,aAAa,CAAC,SAAuB,KAAK;AAC5C;AAEA,MAAM,uCAAuC;AAAA,EAC3C,aAAa,CAAC,SAAuB,KAAK;AAC5C;AAIA,MAAM,wBAAwB,MAAM;AAClC,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,UAAoB,sCAAsC,gCAAgC;AAC9F,UAAQ,EAAE,MAAM,gBAAgB,SAAS,KAAK,CAAC;AAC/C,eAAa,CAAC,SAAS,KAAK,UAAU,YAAY,IAAI;AACtD,WAAS,CAAC,SAAS,KAAK,UAAU,YAAY,IAAI;AAClD,QAAM,QAAQ,QAAQ;AAEtB,QAAM,iBAAiB,QAAQ,cAAc;AAC7C,QAAM,OAAO,QAAQ,cAAc;AACnC,QAAM,UAAU,WAAW,cAAc;AACzC,QAAM,OAAO,QAAQ;AACrB,WAAS,gBAAgB,EAAE,UAAU,GAAG,QAAQ,eAAe,CAAC;AAChE,aAAW,cAAc;AACzB,cAAY,gBAAgB,EAAE,MAAM,gBAAgB,SAAS,KAAK,CAAC;AACnE,OAAK,CAAC,SAAS,KAAK,UAAU,YAAY,IAAI;AAC9C,cAAY,CAAC,SAAS,KAAK,UAAU,YAAY,IAAI;AAErD,QAAM,mBAAmB;AAAA,IACvB;AAAA,IACA;AAAA,EACF;AACA,QAAM,cAAc,UAAoB,qCAAqC,oCAAoC;AAEjH,QAAM,gBAAgB,UAAoB,gCAAgC,+BAA+B;AAEzG,SAAO;AACT;",
|
|
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 { describe } from '@elliemae/ds-props-helpers';\nimport { useCallback, useMemo, useState } from 'react';\nimport { DSTree } from './DSTree.js';\nimport type {\n AddOptions,\n MoveOptions,\n MutateOptions,\n RemoveOptions,\n AnyObjectWithoutReservedKeys,\n
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,gBAAgB;AACzB,SAAS,aAAa,SAAS,gBAAgB;AAC/C,SAAS,cAAc;AASvB,SAAS,oBAAoB,2BAA4C;AAElE,MAAM,YAAY,CACvB,UACA,SACG;AACH,QAAM,OAAO,QAAQ,MAAM,IAAI,OAAqB,UAAU,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC;AACrF,QAAM,CAAC,MAAM,OAAO,IAAI,SAAS,KAAK,IAAI;AAE1C,QAAM,UAAU;AAAA,IACd,CAAC,
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { describe } from '@elliemae/ds-props-helpers';\nimport { useCallback, useMemo, useState } from 'react';\nimport { DSTree } from './DSTree.js';\nimport type {\n AddOptions,\n MoveOptions,\n MutateOptions,\n RemoveOptions,\n AnyObjectWithoutReservedKeys,\n Item,\n} from './types.js';\nimport { UseDSTreePropTypes, UseDSTreeReturnType, type UseDSTreeT } from './react-desc-prop-types.js';\n\nexport const useDSTree = <AppInterface extends AnyObjectWithoutReservedKeys = Record<string, unknown>>(\n rootItem: Item<AppInterface>,\n opts: UseDSTreeT.SecondParameter<AppInterface>,\n) => {\n const tree = useMemo(() => new DSTree<AppInterface>(rootItem, opts), [opts, rootItem]);\n const [hash, setHash] = useState(tree.hash);\n\n const addNode = useCallback(\n (item: Item<AppInterface>, options?: AddOptions<AppInterface>) => {\n const cb: AddOptions<AppInterface>['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<AppInterface>) => {\n const cb: RemoveOptions<AppInterface>['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<AppInterface>) => {\n const cb: MoveOptions<AppInterface>['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: Item<AppInterface>, options?: MutateOptions<AppInterface>) => {\n const cb: MutateOptions<AppInterface>['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 } as UseDSTreeT.OutputT<AppInterface>;\n};\n\nuseDSTree.displayName = 'useDSTree';\nexport const UseDSTreeWithSchema = describe(useDSTree);\nUseDSTreeWithSchema.propTypes = UseDSTreePropTypes;\nUseDSTreeWithSchema.returnType = UseDSTreeReturnType;\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,gBAAgB;AACzB,SAAS,aAAa,SAAS,gBAAgB;AAC/C,SAAS,cAAc;AASvB,SAAS,oBAAoB,2BAA4C;AAElE,MAAM,YAAY,CACvB,UACA,SACG;AACH,QAAM,OAAO,QAAQ,MAAM,IAAI,OAAqB,UAAU,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC;AACrF,QAAM,CAAC,MAAM,OAAO,IAAI,SAAS,KAAK,IAAI;AAE1C,QAAM,UAAU;AAAA,IACd,CAAC,MAA0B,YAAuC;AAChE,YAAM,KAA2C,CAAC,MAAM,WAAW;AACjE,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,aAAa;AAAA,IACjB,CAAC,IAAY,YAA0C;AACrD,YAAM,KAA8C,CAAC,MAAM,WAAW;AACpE,iBAAS,WAAW,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MutateOptions, RemoveOptions,
|
|
1
|
+
import type { AddOptions, AnyObjectWithoutReservedKeys, MoveOptions, MutateOptions, RemoveOptions, Item } from './types.js';
|
|
2
2
|
import { Node } from './Node.js';
|
|
3
3
|
export declare class DSTree<AppInterface extends AnyObjectWithoutReservedKeys = Record<string, unknown>> {
|
|
4
4
|
private root;
|
|
5
5
|
private _hash;
|
|
6
6
|
private nodes;
|
|
7
7
|
getUniqueId: (item: Item<AppInterface>) => string | number;
|
|
8
|
-
constructor(item:
|
|
8
|
+
constructor(item: Item<AppInterface>, options: {
|
|
9
9
|
getUniqueId: (item: Item<AppInterface>) => string | number;
|
|
10
10
|
});
|
|
11
11
|
addNodeToNodesDictionary(node: Node<AppInterface>): void;
|
|
@@ -19,10 +19,10 @@ export declare class DSTree<AppInterface extends AnyObjectWithoutReservedKeys =
|
|
|
19
19
|
findNode: (callback: (node: Node<AppInterface>) => boolean) => Node<AppInterface> | null;
|
|
20
20
|
findAllNodes: (callback: (node: Node<AppInterface>) => boolean) => Node<AppInterface>[];
|
|
21
21
|
flatten: () => Node<AppInterface>[];
|
|
22
|
-
addNode: (item:
|
|
22
|
+
addNode: (item: Item<AppInterface>, options?: AddOptions<AppInterface>) => Node<AppInterface>;
|
|
23
23
|
removeNode: (id: string | number, options?: RemoveOptions<AppInterface>) => Node<AppInterface>;
|
|
24
24
|
moveNode: (id: string | number, options?: MoveOptions<AppInterface>) => Node<AppInterface>;
|
|
25
|
-
replaceNode: (id: string | number, item:
|
|
25
|
+
replaceNode: (id: string | number, item: Item<AppInterface>, options?: MutateOptions<AppInterface>) => Node<AppInterface>;
|
|
26
26
|
getPath: (id: string | number) => Node<AppInterface>[];
|
|
27
27
|
getPathIds: (id: string | number) => (string | number)[];
|
|
28
28
|
}
|
package/dist/types/Node.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import type { NodeConstructorOptions, AnyObjectWithoutReservedKeys,
|
|
1
|
+
import type { NodeConstructorOptions, AnyObjectWithoutReservedKeys, Item } from './types.js';
|
|
2
2
|
export declare class Node<AppInterface extends AnyObjectWithoutReservedKeys = Record<string, unknown>> {
|
|
3
3
|
dsId: string | number;
|
|
4
4
|
childIndex: number;
|
|
5
5
|
depth: number;
|
|
6
|
-
plainItem:
|
|
6
|
+
plainItem: AppInterface;
|
|
7
|
+
plainChildren: AppInterface[];
|
|
7
8
|
parent: Node<AppInterface> | null;
|
|
8
9
|
children: Node<AppInterface>[];
|
|
9
10
|
private tree;
|
|
10
11
|
private _hash;
|
|
11
|
-
constructor(item:
|
|
12
|
+
constructor(item: Item<AppInterface>, { childIndex, depth, parent, tree }: NodeConstructorOptions<AppInterface>);
|
|
12
13
|
fixChildIndexes: () => void;
|
|
13
|
-
getCleanItem: (item: Item<AppInterface>) =>
|
|
14
|
+
getCleanItem: (item: Item<AppInterface>) => AppInterface;
|
|
14
15
|
get hash(): number;
|
|
15
16
|
walk: (callback: (node: Node<AppInterface>) => boolean) => void;
|
|
16
17
|
walkParents: (callback: (node: Node<AppInterface>) => boolean) => void;
|
|
@@ -19,7 +20,7 @@ export declare class Node<AppInterface extends AnyObjectWithoutReservedKeys = Re
|
|
|
19
20
|
flatten: () => Node<AppInterface>[];
|
|
20
21
|
getPath: (id: string | number) => Node<AppInterface>[];
|
|
21
22
|
getPathIds: (id: string | number) => (string | number)[];
|
|
22
|
-
getJson: () =>
|
|
23
|
+
getJson: () => Item<AppInterface>;
|
|
23
24
|
addNode: (node: Node<AppInterface>) => void;
|
|
24
25
|
removeNode: () => void;
|
|
25
26
|
}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { type ValidationMap } from '@elliemae/ds-props-helpers';
|
|
2
2
|
import type { Node } from './Node.js';
|
|
3
|
-
import type { AddOptions,
|
|
3
|
+
import type { AddOptions, AnyObjectWithoutReservedKeys as AnyObjectWithoutReservedKeysToRexport, Item as ItemToRexport, MoveOptions, MutateOptions, RemoveOptions } from './types.js';
|
|
4
4
|
export declare namespace UseDSTreeT {
|
|
5
|
-
type
|
|
6
|
-
type
|
|
7
|
-
type
|
|
8
|
-
type
|
|
5
|
+
type AnyObjectWithoutReservedKeys = AnyObjectWithoutReservedKeysToRexport;
|
|
6
|
+
type Item<AppInterface extends AnyObjectWithoutReservedKeys = Record<string, unknown>> = ItemToRexport<AppInterface>;
|
|
7
|
+
type TreeNode<AppInterface extends AnyObjectWithoutReservedKeysToRexport = Record<string, unknown>> = Node<AppInterface>;
|
|
8
|
+
type TreeItem<AppInterface extends AnyObjectWithoutReservedKeysToRexport = Record<string, unknown>> = Item<AppInterface>;
|
|
9
|
+
type FirstParameter<AppInterface extends AnyObjectWithoutReservedKeysToRexport = Record<string, unknown>> = TreeItem<AppInterface>;
|
|
10
|
+
type SecondParameter<AppInterface extends AnyObjectWithoutReservedKeysToRexport = Record<string, unknown>> = {
|
|
9
11
|
getUniqueId: (item: TreeItem<AppInterface>) => string | number;
|
|
10
12
|
};
|
|
11
|
-
interface OutputT<AppInterface extends
|
|
13
|
+
interface OutputT<AppInterface extends AnyObjectWithoutReservedKeysToRexport = Record<string, unknown>> {
|
|
12
14
|
hash: number;
|
|
13
15
|
getRoot: () => Node<AppInterface>;
|
|
14
16
|
getNode: (id: string | number) => Node<AppInterface>;
|
|
@@ -17,10 +19,10 @@ export declare namespace UseDSTreeT {
|
|
|
17
19
|
findNode: (callback: (node: Node<AppInterface>) => boolean) => Node<AppInterface> | null;
|
|
18
20
|
findAllNodes: (callback: (node: Node<AppInterface>) => boolean) => Node<AppInterface>[];
|
|
19
21
|
flatten: () => Node<AppInterface>[];
|
|
20
|
-
addNode: (item:
|
|
22
|
+
addNode: (item: ItemToRexport<AppInterface>, options?: AddOptions<AppInterface>) => Node<AppInterface>;
|
|
21
23
|
removeNode: (id: string | number, options?: RemoveOptions<AppInterface>) => Node<AppInterface>;
|
|
22
24
|
moveNode: (id: string | number, options?: MoveOptions<AppInterface>) => Node<AppInterface>;
|
|
23
|
-
replaceNode: (id: string | number, item:
|
|
25
|
+
replaceNode: (id: string | number, item: ItemToRexport<AppInterface>, options?: MutateOptions<AppInterface>) => Node<AppInterface>;
|
|
24
26
|
getPath: (id: string | number) => Node<AppInterface>[];
|
|
25
27
|
getPathIds: (id: string | number) => (string | number)[];
|
|
26
28
|
}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import type { DSTree } from './DSTree.js';
|
|
2
2
|
import type { Node } from './Node.js';
|
|
3
|
-
export type AnyObjectWithoutReservedKeys = Omit<Record<string, unknown>, '
|
|
4
|
-
export type
|
|
5
|
-
dsId: string | number;
|
|
6
|
-
subitems?: JSONThatCanContrusctATree<AppInterface>[] | ReadonlyArray<JSONThatCanContrusctATree<AppInterface>>;
|
|
7
|
-
};
|
|
8
|
-
export type Item<AppInterface extends AnyObjectWithoutReservedKeys = Record<string, unknown>> = Omit<AppInterface, 'dsId' | 'subitems'> & {
|
|
9
|
-
dsId: string | number;
|
|
3
|
+
export type AnyObjectWithoutReservedKeys = Omit<Record<string, unknown>, 'subitems'>;
|
|
4
|
+
export type Item<AppInterface extends AnyObjectWithoutReservedKeys = Record<string, unknown>> = AppInterface & {
|
|
10
5
|
subitems?: Item<AppInterface>[] | ReadonlyArray<Item<AppInterface>>;
|
|
11
6
|
};
|
|
12
7
|
export interface NodeConstructorOptions<AppInterface extends AnyObjectWithoutReservedKeys = Record<string, unknown>> {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { AnyObjectWithoutReservedKeys,
|
|
1
|
+
import type { AnyObjectWithoutReservedKeys, Item } from './types.js';
|
|
2
2
|
import { type UseDSTreeT } from './react-desc-prop-types.js';
|
|
3
3
|
export declare const useDSTree: {
|
|
4
|
-
<AppInterface extends AnyObjectWithoutReservedKeys = Record<string, unknown>>(rootItem:
|
|
4
|
+
<AppInterface extends AnyObjectWithoutReservedKeys = Record<string, unknown>>(rootItem: Item<AppInterface>, opts: UseDSTreeT.SecondParameter<AppInterface>): UseDSTreeT.OutputT<AppInterface>;
|
|
5
5
|
displayName: string;
|
|
6
6
|
};
|
|
7
|
-
export declare const UseDSTreeWithSchema: import("@elliemae/ds-props-helpers/dist/types/propTypes/types.js").DocumentedReactComponent<
|
|
7
|
+
export declare const UseDSTreeWithSchema: import("@elliemae/ds-props-helpers/dist/types/propTypes/types.js").DocumentedReactComponent<Item<AnyObjectWithoutReservedKeys>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elliemae/ds-tree-model",
|
|
3
|
-
"version": "3.45.0-rc.
|
|
3
|
+
"version": "3.45.0-rc.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "ICE MT - Dimsum - Tree Model",
|
|
6
6
|
"files": [
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
"typeSafety": true
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@elliemae/ds-props-helpers": "3.45.0-rc.
|
|
43
|
+
"@elliemae/ds-props-helpers": "3.45.0-rc.2"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@elliemae/pui-cli": "9.0.0-next.50",
|
|
47
|
-
"@elliemae/ds-monorepo-devops": "3.45.0-rc.
|
|
47
|
+
"@elliemae/ds-monorepo-devops": "3.45.0-rc.2"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"lodash": "^4.17.21",
|