@shapediver/viewer.shared.node-tree 1.15.7 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{AbstractTreeNodeData.d.ts → implementation/AbstractTreeNodeData.d.ts} +1 -1
- package/dist/implementation/AbstractTreeNodeData.d.ts.map +1 -0
- package/dist/{AbstractTreeNodeData.js → implementation/AbstractTreeNodeData.js} +0 -0
- package/dist/implementation/AbstractTreeNodeData.js.map +1 -0
- package/dist/implementation/Tree.d.ts +13 -0
- package/dist/implementation/Tree.d.ts.map +1 -0
- package/dist/{Tree.js → implementation/Tree.js} +17 -54
- package/dist/implementation/Tree.js.map +1 -0
- package/dist/implementation/TreeNode.d.ts +57 -0
- package/dist/implementation/TreeNode.d.ts.map +1 -0
- package/dist/{TreeNode.js → implementation/TreeNode.js} +91 -96
- package/dist/implementation/TreeNode.js.map +1 -0
- package/dist/index.d.ts +7 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/{Tree.d.ts → interfaces/ITree.d.ts} +16 -22
- package/dist/interfaces/ITree.d.ts.map +1 -0
- package/dist/interfaces/ITree.js +3 -0
- package/dist/interfaces/ITree.js.map +1 -0
- package/dist/interfaces/ITreeNode.d.ts +115 -0
- package/dist/interfaces/ITreeNode.d.ts.map +1 -0
- package/dist/interfaces/ITreeNode.js +3 -0
- package/dist/interfaces/ITreeNode.js.map +1 -0
- package/package.json +12 -9
- package/src/implementation/AbstractTreeNodeData.ts +62 -0
- package/src/implementation/Tree.ts +120 -0
- package/src/implementation/TreeNode.ts +321 -0
- package/src/index.ts +21 -0
- package/src/interfaces/ISDObject.ts +11 -0
- package/src/interfaces/ITree.ts +56 -0
- package/src/interfaces/ITreeNode.ts +150 -0
- package/src/interfaces/ITreeNodeData.ts +6 -0
- package/tsconfig.json +17 -0
- package/dist/AbstractTreeNodeData.d.ts.map +0 -1
- package/dist/AbstractTreeNodeData.js.map +0 -1
- package/dist/Tree.d.ts.map +0 -1
- package/dist/Tree.js.map +0 -1
- package/dist/TreeNode.d.ts +0 -93
- package/dist/TreeNode.d.ts.map +0 -1
- package/dist/TreeNode.js.map +0 -1
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @ignore
|
|
6
|
-
* Management of the main tree node.
|
|
7
|
-
*/
|
|
8
|
-
constructor();
|
|
9
|
-
get root(): TreeNode;
|
|
1
|
+
import { ITreeNode } from "./ITreeNode";
|
|
2
|
+
export interface ITree {
|
|
3
|
+
readonly root: ITreeNode;
|
|
10
4
|
/**
|
|
11
5
|
* Add the node as a child of the corresponding parent node.
|
|
12
6
|
*
|
|
@@ -14,7 +8,7 @@ export declare class Tree {
|
|
|
14
8
|
* @param parent the targeted parent node
|
|
15
9
|
* @param root optional root at which the process begins, root node will be used per default
|
|
16
10
|
*/
|
|
17
|
-
addNode(node:
|
|
11
|
+
addNode(node: ITreeNode, parent?: ITreeNode, root?: ITreeNode): boolean;
|
|
18
12
|
/**
|
|
19
13
|
* Add the node at the corresponding path. (paths are dot separated ids)
|
|
20
14
|
*
|
|
@@ -22,28 +16,28 @@ export declare class Tree {
|
|
|
22
16
|
* @param path the path at which the node should be added
|
|
23
17
|
* @param root optional root at which the process begins, root node will be used per default
|
|
24
18
|
*/
|
|
25
|
-
addNodeAtPath(node:
|
|
19
|
+
addNodeAtPath(node: ITreeNode, path?: string, root?: ITreeNode): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Get the node at the provided path.
|
|
22
|
+
*
|
|
23
|
+
* @param path
|
|
24
|
+
* @param root
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
getNodeAtPath(path?: string, root?: ITreeNode): ITreeNode | null;
|
|
26
28
|
/**
|
|
27
29
|
* Remove a node from the tree.
|
|
28
30
|
*
|
|
29
31
|
* @param node the node to remove
|
|
30
32
|
* @param root optional root at which the process begins, root node will be used per default
|
|
31
33
|
*/
|
|
32
|
-
removeNode(node:
|
|
34
|
+
removeNode(node: ITreeNode, root?: ITreeNode): boolean;
|
|
33
35
|
/**
|
|
34
36
|
* Remove a node via the path of it.
|
|
35
37
|
*
|
|
36
38
|
* @param path the path of the node to be removed
|
|
37
39
|
* @param root optional root at which the process begins, root node will be used per default
|
|
38
40
|
*/
|
|
39
|
-
removeNodeAtPath(path: string, root?:
|
|
40
|
-
/**
|
|
41
|
-
* Get the node at the provided path.
|
|
42
|
-
*
|
|
43
|
-
* @param path
|
|
44
|
-
* @param root
|
|
45
|
-
* @returns
|
|
46
|
-
*/
|
|
47
|
-
getNodeAtPath(path?: string, root?: TreeNode): TreeNode | null;
|
|
41
|
+
removeNodeAtPath(path: string, root?: ITreeNode): boolean;
|
|
48
42
|
}
|
|
49
|
-
//# sourceMappingURL=
|
|
43
|
+
//# sourceMappingURL=ITree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ITree.d.ts","sourceRoot":"","sources":["../../src/interfaces/ITree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,MAAM,WAAW,KAAK;IAGlB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAMzB;;;;;;OAMG;IACH,OAAO,CAAC,IAAI,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC;IAExE;;;;;;OAMG;IACH,aAAa,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC;IAEzE;;;;;;OAMG;IACH,aAAa,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,IAAI,CAAC;IAEjE;;;;;OAKG;IACH,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC;IAEvD;;;;;OAKG;IACH,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC;CAG7D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ITree.js","sourceRoot":"","sources":["../../src/interfaces/ITree.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { mat4 } from 'gl-matrix';
|
|
2
|
+
import { IBox } from '@shapediver/viewer.shared.math';
|
|
3
|
+
import { ITreeNodeData } from './ITreeNodeData';
|
|
4
|
+
import { ISDObject } from './ISDObject';
|
|
5
|
+
export interface ITransformation {
|
|
6
|
+
id: string;
|
|
7
|
+
matrix: mat4;
|
|
8
|
+
}
|
|
9
|
+
export interface ITreeNode {
|
|
10
|
+
readonly children: ITreeNode[];
|
|
11
|
+
readonly data: ITreeNodeData[];
|
|
12
|
+
readonly id: string;
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly version: string;
|
|
15
|
+
readonly parent?: ITreeNode;
|
|
16
|
+
readonly nodeMatrix: mat4;
|
|
17
|
+
readonly worldMatrix: mat4;
|
|
18
|
+
readonly boundingBox: IBox;
|
|
19
|
+
readonly transformedNodes: {
|
|
20
|
+
[key: string]: ISDObject;
|
|
21
|
+
};
|
|
22
|
+
excludeViewports: string[];
|
|
23
|
+
restrictViewports: string[];
|
|
24
|
+
transformations: ITransformation[];
|
|
25
|
+
visible: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Add a child to the children of this node.
|
|
28
|
+
*
|
|
29
|
+
* @param child the child to add
|
|
30
|
+
*/
|
|
31
|
+
addChild(child: ITreeNode): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Add a data item to node.
|
|
34
|
+
*
|
|
35
|
+
* @param data the data to add
|
|
36
|
+
*/
|
|
37
|
+
addData(data: ITreeNodeData): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Add a transformation to this node.
|
|
40
|
+
*
|
|
41
|
+
* @param transformation the transformation to add
|
|
42
|
+
*/
|
|
43
|
+
addTransformation(transformation: ITransformation): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Clones this node and all its children.
|
|
46
|
+
*/
|
|
47
|
+
clone(): ITreeNode;
|
|
48
|
+
/**
|
|
49
|
+
* Clones this node and all its children.
|
|
50
|
+
*/
|
|
51
|
+
cloneInstance(): ITreeNode;
|
|
52
|
+
/**
|
|
53
|
+
* Returns the child with the specified id
|
|
54
|
+
*/
|
|
55
|
+
getChild(id: string): ITreeNode | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Returns the data item with the specified id
|
|
58
|
+
*/
|
|
59
|
+
getData(id: string): ITreeNodeData | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Returns the transformation with the specified id
|
|
62
|
+
*/
|
|
63
|
+
getTransformation(id: string): ITransformation | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Return the path to this node.
|
|
66
|
+
*/
|
|
67
|
+
getPath(): string;
|
|
68
|
+
/**
|
|
69
|
+
* Check for existence of a child from the children of this node.
|
|
70
|
+
*
|
|
71
|
+
* @param child the child to check
|
|
72
|
+
*/
|
|
73
|
+
hasChild(child: ITreeNode): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Check for existence of a data item of this node.
|
|
76
|
+
*
|
|
77
|
+
* @param data the data item to check
|
|
78
|
+
*/
|
|
79
|
+
hasData(data: ITreeNodeData): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Check for existence of a transformation of this node.
|
|
82
|
+
*
|
|
83
|
+
* @param data the transformation to check
|
|
84
|
+
*/
|
|
85
|
+
hasTransformation(transformation: ITransformation): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Remove a child from the children of this node.
|
|
88
|
+
*
|
|
89
|
+
* @param child the child to remove
|
|
90
|
+
*/
|
|
91
|
+
removeChild(child: ITreeNode): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Remove a data item from this node.
|
|
94
|
+
*
|
|
95
|
+
* @param data the data to remove
|
|
96
|
+
*/
|
|
97
|
+
removeData(data: ITreeNodeData): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* Remove a transformation from this node.
|
|
100
|
+
*
|
|
101
|
+
* @param transformation the transformation to remove
|
|
102
|
+
*/
|
|
103
|
+
removeTransformation(transformation: ITransformation): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Traverse this node and all it's children and executes the callback for all of them
|
|
106
|
+
*
|
|
107
|
+
* @param callback
|
|
108
|
+
*/
|
|
109
|
+
traverse(callback: (node: ITreeNode) => void): void;
|
|
110
|
+
/**
|
|
111
|
+
* Update the version
|
|
112
|
+
*/
|
|
113
|
+
updateVersion(): void;
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=ITreeNode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ITreeNode.d.ts","sourceRoot":"","sources":["../../src/interfaces/ITreeNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,gCAAgC,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC,MAAM,WAAW,eAAe;IAG5B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,IAAI,CAAA;CAGf;AAED,MAAM,WAAW,SAAS;IAGtB,QAAQ,CAAC,QAAQ,EAAE,SAAS,EAAE,CAAC;IAC/B,QAAQ,CAAC,IAAI,EAAE,aAAa,EAAE,CAAC;IAE/B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC;IAE5B,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC;IAE3B,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC;IAC3B,QAAQ,CAAC,gBAAgB,EAAE;QACvB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;KAC3B,CAAC;IAEF,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAE5B,eAAe,EAAE,eAAe,EAAE,CAAC;IACnC,OAAO,EAAE,OAAO,CAAC;IAMjB;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC;IAEpC;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC;IAEtC;;;;OAIG;IACH,iBAAiB,CAAC,cAAc,EAAE,eAAe,GAAG,OAAO,CAAC;IAE5D;;OAEG;IACH,KAAK,IAAI,SAAS,CAAC;IAEnB;;OAEG;IACH,aAAa,IAAI,SAAS,CAAC;IAE3B;;MAEE;IACF,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;IAE5C;;MAEE;IACF,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAAC;IAE/C;;MAEE;IACF,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAAC;IAE3D;;OAEG;IACH,OAAO,IAAI,MAAM,CAAC;IAElB;;;;OAIG;IACH,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC;IAEpC;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC;IAEtC;;;;OAIG;IACH,iBAAiB,CAAC,cAAc,EAAE,eAAe,GAAG,OAAO,CAAC;IAE5D;;;;OAIG;IACH,WAAW,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC;IAEvC;;;;OAIG;IACH,UAAU,CAAC,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC;IAEzC;;;;OAIG;IACH,oBAAoB,CAAC,cAAc,EAAE,eAAe,GAAG,OAAO,CAAC;IAE/D;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,SAAS,KAAK,IAAI,GAAG,IAAI,CAAC;IAEpD;;OAEG;IACH,aAAa,IAAI,IAAI,CAAC;CAGzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ITreeNode.js","sourceRoot":"","sources":["../../src/interfaces/ITreeNode.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapediver/viewer.shared.node-tree",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "Michael Oppitz <michael@shapediver.com>",
|
|
@@ -10,7 +10,11 @@
|
|
|
10
10
|
"test": "__tests__"
|
|
11
11
|
},
|
|
12
12
|
"files": [
|
|
13
|
-
"dist"
|
|
13
|
+
"dist",
|
|
14
|
+
"src",
|
|
15
|
+
"package.json",
|
|
16
|
+
"README.md",
|
|
17
|
+
"tsconfig.json"
|
|
14
18
|
],
|
|
15
19
|
"publishConfig": {
|
|
16
20
|
"access": "public"
|
|
@@ -20,11 +24,10 @@
|
|
|
20
24
|
"url": "git+https://github.com/shapediver/Viewer.git"
|
|
21
25
|
},
|
|
22
26
|
"scripts": {
|
|
23
|
-
"test": "bash ../../scripts/test.sh",
|
|
24
27
|
"check": "tsc --noEmit",
|
|
25
|
-
"build": "bash ../../scripts/build.sh",
|
|
26
|
-
"build-watch": "bash ../../scripts/build-watch.sh",
|
|
27
|
-
"build-dep": "bash ../../scripts/build-dep.sh"
|
|
28
|
+
"build": "bash ../../scripts/building/build.sh",
|
|
29
|
+
"build-watch": "bash ../../scripts/building/build-watch.sh",
|
|
30
|
+
"build-dep": "bash ../../scripts/building/build-dep.sh"
|
|
28
31
|
},
|
|
29
32
|
"bugs": {
|
|
30
33
|
"url": "https://github.com/shapediver/Viewer/issues"
|
|
@@ -36,10 +39,10 @@
|
|
|
36
39
|
"testEnvironment": "node"
|
|
37
40
|
},
|
|
38
41
|
"dependencies": {
|
|
39
|
-
"@shapediver/viewer.shared.math": "
|
|
40
|
-
"@shapediver/viewer.shared.services": "
|
|
42
|
+
"@shapediver/viewer.shared.math": "2.0.0",
|
|
43
|
+
"@shapediver/viewer.shared.services": "2.0.0",
|
|
41
44
|
"gl-matrix": "3.3.0",
|
|
42
45
|
"tsyringe": "^4.5.0"
|
|
43
46
|
},
|
|
44
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "bb53f1f23dcf3b1d76e786bdc8eb20e485c029f2"
|
|
45
48
|
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { container } from 'tsyringe'
|
|
2
|
+
import { UuidGenerator, EventEngine, EVENTTYPE } from '@shapediver/viewer.shared.services'
|
|
3
|
+
|
|
4
|
+
import { ITreeNodeData } from '../interfaces/ITreeNodeData'
|
|
5
|
+
|
|
6
|
+
export abstract class AbstractTreeNodeData implements ITreeNodeData {
|
|
7
|
+
// #region Properties (3)
|
|
8
|
+
|
|
9
|
+
#version: string;
|
|
10
|
+
|
|
11
|
+
readonly #id: string;
|
|
12
|
+
readonly #uuidGenerator: UuidGenerator = <UuidGenerator>container.resolve(UuidGenerator);
|
|
13
|
+
readonly #eventEngine: EventEngine = <EventEngine>container.resolve(EventEngine);
|
|
14
|
+
|
|
15
|
+
// #endregion Properties (3)
|
|
16
|
+
|
|
17
|
+
// #region Constructors (1)
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Creates a tree node data object.
|
|
21
|
+
*
|
|
22
|
+
* @param id Id of this data object
|
|
23
|
+
*/
|
|
24
|
+
constructor(id?: string) {
|
|
25
|
+
this.#id = id || this.#uuidGenerator.create();
|
|
26
|
+
this.#version = this.#uuidGenerator.create();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// #endregion Constructors (1)
|
|
30
|
+
|
|
31
|
+
// #region Public Accessors (2)
|
|
32
|
+
|
|
33
|
+
public get id(): string {
|
|
34
|
+
return this.#id;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public get version(): string {
|
|
38
|
+
return this.#version;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// #endregion Public Accessors (2)
|
|
42
|
+
|
|
43
|
+
// #region Public Methods (1)
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Update the version
|
|
47
|
+
*/
|
|
48
|
+
public updateVersion(): void {
|
|
49
|
+
this.#version = this.#uuidGenerator.create();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// #endregion Public Methods (1)
|
|
53
|
+
|
|
54
|
+
// #region Public Abstract Methods (1)
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Clones the tree node data.
|
|
58
|
+
*/
|
|
59
|
+
public abstract clone(): ITreeNodeData;
|
|
60
|
+
|
|
61
|
+
// #endregion Public Abstract Methods (1)
|
|
62
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { singleton } from 'tsyringe'
|
|
2
|
+
import { ITree } from '../interfaces/ITree';
|
|
3
|
+
import { ITreeNode } from '../interfaces/ITreeNode';
|
|
4
|
+
|
|
5
|
+
import { TreeNode } from './TreeNode'
|
|
6
|
+
|
|
7
|
+
@singleton()
|
|
8
|
+
export class Tree implements ITree {
|
|
9
|
+
// #region Properties (1)
|
|
10
|
+
|
|
11
|
+
readonly #root = new TreeNode('root');
|
|
12
|
+
|
|
13
|
+
// #endregion Properties (1)
|
|
14
|
+
|
|
15
|
+
// #region Constructors (1)
|
|
16
|
+
|
|
17
|
+
constructor() { }
|
|
18
|
+
|
|
19
|
+
// #endregion Constructors (1)
|
|
20
|
+
|
|
21
|
+
// #region Public Accessors (1)
|
|
22
|
+
|
|
23
|
+
public get root(): ITreeNode {
|
|
24
|
+
return this.#root;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// #endregion Public Accessors (1)
|
|
28
|
+
|
|
29
|
+
// #region Public Methods (6)
|
|
30
|
+
|
|
31
|
+
public addNode(node: ITreeNode, parent: ITreeNode = this.#root, root: ITreeNode = this.#root): boolean {
|
|
32
|
+
if (root === parent) {
|
|
33
|
+
root.addChild(node);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
for (let i = 0; i < root.children.length; i++) {
|
|
38
|
+
const child = root.children[i];
|
|
39
|
+
if (child && this.addNode(node, parent, child)) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public addNodeAtPath(node: ITreeNode, path: string = this.root.getPath(), root: ITreeNode = this.#root): boolean {
|
|
47
|
+
if (root.name === path) {
|
|
48
|
+
root.addChild(node);
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const pathStart = path.substr(0, path.indexOf('.'));
|
|
53
|
+
if (root.name === pathStart) {
|
|
54
|
+
const shortenedPath = path.substr(pathStart.length + 1, path.length);
|
|
55
|
+
|
|
56
|
+
for (let i = 0; i < root.children.length; i++) {
|
|
57
|
+
const child = root.children[i];
|
|
58
|
+
if (child && this.addNodeAtPath(node, shortenedPath, child)) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public getNodeAtPath(path: string = this.root.getPath(), root: ITreeNode = this.#root): ITreeNode | null {
|
|
67
|
+
if (root.name === path)
|
|
68
|
+
return root;
|
|
69
|
+
|
|
70
|
+
const pathStart = path.substr(0, path.indexOf('.'));
|
|
71
|
+
if (root.name === pathStart) {
|
|
72
|
+
const shortenedPath = path.substr(pathStart.length + 1, path.length);
|
|
73
|
+
|
|
74
|
+
for (let i = 0; i < root.children.length; i++) {
|
|
75
|
+
const child = root.children[i];
|
|
76
|
+
const res = this.getNodeAtPath(shortenedPath, child);
|
|
77
|
+
if(res) return res;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public removeNode(node: ITreeNode, root: ITreeNode = this.#root): boolean {
|
|
84
|
+
if (root.hasChild(node)) {
|
|
85
|
+
root.removeChild(node);
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
for (let i = 0; i < root.children.length; i++) {
|
|
90
|
+
const child = root.children[i];
|
|
91
|
+
if (child && this.removeNode(node, child)) {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public removeNodeAtPath(path: string, root: ITreeNode = this.#root): boolean {
|
|
100
|
+
if (root.name === path) {
|
|
101
|
+
root.parent?.removeChild(root);
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const pathStart = path.substr(0, path.indexOf('.'));
|
|
106
|
+
if (root.name === pathStart) {
|
|
107
|
+
const shortenedPath = path.substr(pathStart.length + 1, path.length);
|
|
108
|
+
|
|
109
|
+
for (let i = 0; i < root.children.length; i++) {
|
|
110
|
+
const child = root.children[i];
|
|
111
|
+
if (child && this.removeNodeAtPath(shortenedPath, child)) {
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// #endregion Public Methods (6)
|
|
120
|
+
}
|