@shapediver/viewer.shared.node-tree 2.12.7 → 3.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/implementation/AbstractTreeNodeData.d.ts +13 -5
- package/dist/implementation/AbstractTreeNodeData.d.ts.map +1 -1
- package/dist/implementation/AbstractTreeNodeData.js +29 -19
- package/dist/implementation/AbstractTreeNodeData.js.map +1 -1
- package/dist/implementation/Tree.d.ts +15 -0
- package/dist/implementation/Tree.d.ts.map +1 -0
- package/dist/implementation/{AbstractTree.js → Tree.js} +26 -20
- package/dist/implementation/Tree.js.map +1 -0
- package/dist/implementation/{AbstractTreeNode.d.ts → TreeNode.d.ts} +35 -27
- package/dist/implementation/TreeNode.d.ts.map +1 -0
- package/dist/implementation/TreeNode.js +348 -0
- package/dist/implementation/TreeNode.js.map +1 -0
- package/dist/index.d.ts +9 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/interfaces/ITree.d.ts +8 -9
- package/dist/interfaces/ITree.d.ts.map +1 -1
- package/dist/interfaces/ITreeNode.d.ts +36 -23
- package/dist/interfaces/ITreeNode.d.ts.map +1 -1
- package/dist/interfaces/ITreeNode.js +1 -0
- package/dist/interfaces/ITreeNode.js.map +1 -1
- package/dist/interfaces/ITreeNodeData.d.ts +20 -10
- package/dist/interfaces/ITreeNodeData.d.ts.map +1 -1
- package/package.json +5 -7
- package/src/implementation/AbstractTreeNodeData.ts +38 -26
- package/src/implementation/{AbstractTree.ts → Tree.ts} +29 -19
- package/src/implementation/{AbstractTreeNode.ts → TreeNode.ts} +124 -96
- package/src/index.ts +12 -13
- package/src/interfaces/ITree.ts +8 -13
- package/src/interfaces/ITreeNode.ts +43 -28
- package/src/interfaces/ITreeNodeData.ts +20 -12
- package/dist/implementation/AbstractTree.d.ts +0 -14
- package/dist/implementation/AbstractTree.d.ts.map +0 -1
- package/dist/implementation/AbstractTree.js.map +0 -1
- package/dist/implementation/AbstractTreeNode.d.ts.map +0 -1
- package/dist/implementation/AbstractTreeNode.js +0 -321
- package/dist/implementation/AbstractTreeNode.js.map +0 -1
- package/dist/implementation/three/AbstractTreeNodeDataThreeJs.d.ts +0 -10
- package/dist/implementation/three/AbstractTreeNodeDataThreeJs.d.ts.map +0 -1
- package/dist/implementation/three/AbstractTreeNodeDataThreeJs.js +0 -23
- package/dist/implementation/three/AbstractTreeNodeDataThreeJs.js.map +0 -1
- package/dist/implementation/three/Tree.d.ts +0 -9
- package/dist/implementation/three/Tree.d.ts.map +0 -1
- package/dist/implementation/three/Tree.js +0 -19
- package/dist/implementation/three/Tree.js.map +0 -1
- package/dist/implementation/three/TreeNodeThreejs.d.ts +0 -13
- package/dist/implementation/three/TreeNodeThreejs.d.ts.map +0 -1
- package/dist/implementation/three/TreeNodeThreejs.js +0 -35
- package/dist/implementation/three/TreeNodeThreejs.js.map +0 -1
- package/dist/interfaces/three/ITreeNodeDataThreeJs.d.ts +0 -11
- package/dist/interfaces/three/ITreeNodeDataThreeJs.d.ts.map +0 -1
- package/dist/interfaces/three/ITreeNodeDataThreeJs.js +0 -3
- package/dist/interfaces/three/ITreeNodeDataThreeJs.js.map +0 -1
- package/dist/interfaces/three/ITreeNodeThreeJs.d.ts +0 -17
- package/dist/interfaces/three/ITreeNodeThreeJs.d.ts.map +0 -1
- package/dist/interfaces/three/ITreeNodeThreeJs.js +0 -3
- package/dist/interfaces/three/ITreeNodeThreeJs.js.map +0 -1
- package/dist/interfaces/three/ITreeThreeJs.d.ts +0 -5
- package/dist/interfaces/three/ITreeThreeJs.d.ts.map +0 -1
- package/dist/interfaces/three/ITreeThreeJs.js +0 -3
- package/dist/interfaces/three/ITreeThreeJs.js.map +0 -1
- package/src/implementation/three/AbstractTreeNodeDataThreeJs.ts +0 -12
- package/src/implementation/three/Tree.ts +0 -28
- package/src/implementation/three/TreeNodeThreeJs.ts +0 -21
- package/src/interfaces/three/ITreeNodeDataThreeJs.ts +0 -13
- package/src/interfaces/three/ITreeNodeThreeJs.ts +0 -19
- package/src/interfaces/three/ITreeThreeJs.ts +0 -4
|
@@ -1,36 +1,34 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Box, IBox } from '@shapediver/viewer.shared.math';
|
|
2
|
+
import { ITransformation, ITreeNode } from '../interfaces/ITreeNode';
|
|
3
|
+
import { ITreeNodeData } from '../interfaces/ITreeNodeData';
|
|
4
|
+
import { mat4 } from 'gl-matrix';
|
|
5
|
+
import { UuidGenerator } from '@shapediver/viewer.shared.services';
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export abstract class AbstractTreeNode<T extends ITreeNode<any, ITreeNodeData<any>>, U extends ITreeNodeData<any>> implements ITreeNode<T, U> {
|
|
9
|
-
// #region Properties (13)
|
|
10
|
-
|
|
11
|
-
readonly #uuidGenerator: UuidGenerator = UuidGenerator.instance;
|
|
12
|
-
|
|
13
|
-
readonly #children: T[] = [];
|
|
14
|
-
readonly #data: U[] = [];
|
|
15
|
-
#transformations: ITransformation[] = [];
|
|
16
|
-
|
|
17
|
-
readonly #id: string;
|
|
18
|
-
#name: string = '';
|
|
19
|
-
#version: string;
|
|
20
|
-
#parent?: T;
|
|
7
|
+
export class TreeNode implements ITreeNode {
|
|
8
|
+
// #region Properties (19)
|
|
21
9
|
|
|
22
10
|
readonly #boundingBox: IBox = new Box();
|
|
23
11
|
readonly #boundingBoxViewport: { [key: string]: IBox } = {};
|
|
24
|
-
#
|
|
25
|
-
#
|
|
12
|
+
readonly #children: ITreeNode[] = [];
|
|
13
|
+
readonly #data: ITreeNodeData[] = [];
|
|
14
|
+
readonly #id: string;
|
|
15
|
+
readonly #uuidGenerator: UuidGenerator = UuidGenerator.instance;
|
|
26
16
|
|
|
27
|
-
#visible: boolean = true;
|
|
28
|
-
#skinNode: boolean = false;
|
|
29
|
-
#bones: T[] = [];
|
|
30
17
|
#boneInverses: mat4[] = [];
|
|
18
|
+
#bones: ITreeNode[] = [];
|
|
19
|
+
#convertedObject: { [key: string]: unknown } = {};
|
|
20
|
+
#excludeViewports: string[] = [];
|
|
21
|
+
#name: string = '';
|
|
31
22
|
#originalId: string;
|
|
23
|
+
#parent?: ITreeNode;
|
|
24
|
+
#restrictViewports: string[] = [];
|
|
25
|
+
#skinNode: boolean = false;
|
|
26
|
+
#transformations: ITransformation[] = [];
|
|
27
|
+
#updateCallbackConvertedObject: ((newObj: unknown, oldObj: unknown, viewport: string) => void) | null = null;
|
|
28
|
+
#version: string;
|
|
29
|
+
#visible: boolean = true;
|
|
32
30
|
|
|
33
|
-
// #endregion Properties (
|
|
31
|
+
// #endregion Properties (19)
|
|
34
32
|
|
|
35
33
|
// #region Constructors (1)
|
|
36
34
|
|
|
@@ -44,11 +42,11 @@ export abstract class AbstractTreeNode<T extends ITreeNode<any, ITreeNodeData<an
|
|
|
44
42
|
*/
|
|
45
43
|
constructor(
|
|
46
44
|
name: string = 'node',
|
|
47
|
-
parent?:
|
|
48
|
-
data:
|
|
45
|
+
parent?: ITreeNode,
|
|
46
|
+
data: ITreeNodeData[] = [],
|
|
49
47
|
transformations: ITransformation[] = []
|
|
50
48
|
) {
|
|
51
|
-
this.#name = name.replace(/\./g,
|
|
49
|
+
this.#name = name.replace(/\./g, '_');
|
|
52
50
|
this.#parent = parent;
|
|
53
51
|
this.#data = data;
|
|
54
52
|
this.#transformations = transformations;
|
|
@@ -61,16 +59,7 @@ export abstract class AbstractTreeNode<T extends ITreeNode<any, ITreeNodeData<an
|
|
|
61
59
|
|
|
62
60
|
// #endregion Constructors (1)
|
|
63
61
|
|
|
64
|
-
// #region Public
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
public get bones(): T[] {
|
|
68
|
-
return this.#bones;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
public set bones(value: T[]) {
|
|
72
|
-
this.#bones = value;
|
|
73
|
-
}
|
|
62
|
+
// #region Public Getters And Setters (33)
|
|
74
63
|
|
|
75
64
|
public get boneInverses(): mat4[] {
|
|
76
65
|
return this.#boneInverses;
|
|
@@ -80,6 +69,14 @@ export abstract class AbstractTreeNode<T extends ITreeNode<any, ITreeNodeData<an
|
|
|
80
69
|
this.#boneInverses = value;
|
|
81
70
|
}
|
|
82
71
|
|
|
72
|
+
public get bones(): ITreeNode[] {
|
|
73
|
+
return this.#bones;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public set bones(value: ITreeNode[]) {
|
|
77
|
+
this.#bones = value;
|
|
78
|
+
}
|
|
79
|
+
|
|
83
80
|
public get boundingBox(): IBox {
|
|
84
81
|
return this.#boundingBox;
|
|
85
82
|
}
|
|
@@ -88,19 +85,19 @@ export abstract class AbstractTreeNode<T extends ITreeNode<any, ITreeNodeData<an
|
|
|
88
85
|
return this.#boundingBoxViewport;
|
|
89
86
|
}
|
|
90
87
|
|
|
91
|
-
public get children():
|
|
88
|
+
public get children(): ITreeNode[] {
|
|
92
89
|
return this.#children;
|
|
93
90
|
}
|
|
94
91
|
|
|
95
|
-
public get
|
|
96
|
-
return this.#
|
|
92
|
+
public get convertedObject(): { [key: string]: unknown } {
|
|
93
|
+
return this.#convertedObject;
|
|
97
94
|
}
|
|
98
95
|
|
|
99
|
-
public set
|
|
100
|
-
this.#
|
|
96
|
+
public set convertedObject(value: { [key: string]: unknown }) {
|
|
97
|
+
this.#convertedObject = value;
|
|
101
98
|
}
|
|
102
99
|
|
|
103
|
-
public get data():
|
|
100
|
+
public get data(): ITreeNodeData[] {
|
|
104
101
|
return this.#data;
|
|
105
102
|
}
|
|
106
103
|
|
|
@@ -126,16 +123,24 @@ export abstract class AbstractTreeNode<T extends ITreeNode<any, ITreeNodeData<an
|
|
|
126
123
|
|
|
127
124
|
public get nodeMatrix(): mat4 {
|
|
128
125
|
const matrix: mat4 = mat4.create();
|
|
129
|
-
for (
|
|
126
|
+
for (const transform of this.#transformations)
|
|
130
127
|
if (transform.id !== 'sdtf') mat4.multiply(matrix, matrix, transform.matrix);
|
|
131
128
|
return matrix;
|
|
132
129
|
}
|
|
133
130
|
|
|
134
|
-
public get
|
|
131
|
+
public get originalId(): string {
|
|
132
|
+
return this.#originalId;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
public set originalId(value: string) {
|
|
136
|
+
this.#originalId = value;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
public get parent(): ITreeNode | undefined {
|
|
135
140
|
return this.#parent;
|
|
136
141
|
}
|
|
137
142
|
|
|
138
|
-
public set parent(value:
|
|
143
|
+
public set parent(value: ITreeNode | undefined) {
|
|
139
144
|
// check if it was removed from previous parent
|
|
140
145
|
if (this.#parent)
|
|
141
146
|
this.#parent.removeChild(this);
|
|
@@ -171,6 +176,14 @@ export abstract class AbstractTreeNode<T extends ITreeNode<any, ITreeNodeData<an
|
|
|
171
176
|
this.#transformations = value;
|
|
172
177
|
}
|
|
173
178
|
|
|
179
|
+
public get updateCallbackConvertedObject(): ((newObj: unknown, oldObj: unknown, viewport: string) => void) | null {
|
|
180
|
+
return this.#updateCallbackConvertedObject;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
public set updateCallbackConvertedObject(value: ((newObj: unknown, oldObj: unknown, viewport: string) => void) | null) {
|
|
184
|
+
this.#updateCallbackConvertedObject = value;
|
|
185
|
+
}
|
|
186
|
+
|
|
174
187
|
public get version(): string {
|
|
175
188
|
return this.#version;
|
|
176
189
|
}
|
|
@@ -190,10 +203,11 @@ export abstract class AbstractTreeNode<T extends ITreeNode<any, ITreeNodeData<an
|
|
|
190
203
|
public get worldMatrix(): mat4 {
|
|
191
204
|
const matrix: mat4 = mat4.create();
|
|
192
205
|
|
|
193
|
-
for (
|
|
206
|
+
for (const transform of this.#transformations)
|
|
194
207
|
mat4.multiply(matrix, matrix, transform.matrix);
|
|
195
208
|
|
|
196
|
-
|
|
209
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
210
|
+
let node: ITreeNode = this;
|
|
197
211
|
while (node.parent) {
|
|
198
212
|
mat4.multiply(matrix, node.parent.nodeMatrix, matrix);
|
|
199
213
|
node = node.parent;
|
|
@@ -202,22 +216,22 @@ export abstract class AbstractTreeNode<T extends ITreeNode<any, ITreeNodeData<an
|
|
|
202
216
|
return matrix;
|
|
203
217
|
}
|
|
204
218
|
|
|
205
|
-
// #endregion Public
|
|
219
|
+
// #endregion Public Getters And Setters (33)
|
|
206
220
|
|
|
207
|
-
// #region Public Methods (
|
|
221
|
+
// #region Public Methods (20)
|
|
208
222
|
|
|
209
|
-
public addChild(child:
|
|
223
|
+
public addChild(child: ITreeNode): boolean {
|
|
210
224
|
if (this.hasChild(child)) return false;
|
|
211
225
|
|
|
212
226
|
this.#children.push(child);
|
|
213
227
|
if (child.parent)
|
|
214
228
|
child.parent.removeChild(child);
|
|
215
|
-
(<
|
|
229
|
+
(<ITreeNode>child.parent) = this;
|
|
216
230
|
|
|
217
231
|
return true;
|
|
218
232
|
}
|
|
219
233
|
|
|
220
|
-
public addData(data:
|
|
234
|
+
public addData(data: ITreeNodeData): boolean {
|
|
221
235
|
this.#data.push(data);
|
|
222
236
|
return true;
|
|
223
237
|
}
|
|
@@ -227,16 +241,20 @@ export abstract class AbstractTreeNode<T extends ITreeNode<any, ITreeNodeData<an
|
|
|
227
241
|
return true;
|
|
228
242
|
}
|
|
229
243
|
|
|
230
|
-
public clone():
|
|
231
|
-
const clone = new (
|
|
244
|
+
public clone(): ITreeNode {
|
|
245
|
+
const clone = new (this.constructor as new () => ITreeNode)();
|
|
246
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
247
|
+
// @ts-ignore
|
|
232
248
|
clone.name = this.name;
|
|
249
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
250
|
+
// @ts-ignore
|
|
233
251
|
clone.originalId = this.originalId;
|
|
234
252
|
clone.visible = this.visible;
|
|
235
|
-
for (
|
|
253
|
+
for (const child of this.#children)
|
|
236
254
|
clone.addChild(child.clone());
|
|
237
|
-
for (
|
|
255
|
+
for (const data of this.#data)
|
|
238
256
|
clone.data.push(data.clone());
|
|
239
|
-
for (
|
|
257
|
+
for (const transform of this.#transformations)
|
|
240
258
|
clone.addTransformation({
|
|
241
259
|
id: transform.id,
|
|
242
260
|
matrix: mat4.clone(transform.matrix)
|
|
@@ -245,16 +263,20 @@ export abstract class AbstractTreeNode<T extends ITreeNode<any, ITreeNodeData<an
|
|
|
245
263
|
return clone;
|
|
246
264
|
}
|
|
247
265
|
|
|
248
|
-
public cloneInstance():
|
|
249
|
-
const clone = new (
|
|
266
|
+
public cloneInstance(): ITreeNode {
|
|
267
|
+
const clone = new (this.constructor as new () => ITreeNode)();
|
|
268
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
269
|
+
// @ts-ignore
|
|
250
270
|
clone.name = this.name;
|
|
271
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
272
|
+
// @ts-ignore
|
|
251
273
|
clone.originalId = this.originalId;
|
|
252
274
|
clone.visible = this.visible;
|
|
253
|
-
for (
|
|
275
|
+
for (const child of this.#children)
|
|
254
276
|
clone.addChild(child.cloneInstance());
|
|
255
|
-
for (
|
|
277
|
+
for (const data of this.#data)
|
|
256
278
|
clone.data.push(data);
|
|
257
|
-
for (
|
|
279
|
+
for (const transform of this.#transformations)
|
|
258
280
|
clone.addTransformation({
|
|
259
281
|
id: transform.id,
|
|
260
282
|
matrix: mat4.clone(transform.matrix)
|
|
@@ -263,41 +285,41 @@ export abstract class AbstractTreeNode<T extends ITreeNode<any, ITreeNodeData<an
|
|
|
263
285
|
return clone;
|
|
264
286
|
}
|
|
265
287
|
|
|
266
|
-
public getChild(id: string):
|
|
288
|
+
public getChild(id: string): ITreeNode | undefined {
|
|
267
289
|
for (let i = 0; i < this.#children.length; i++)
|
|
268
290
|
if (this.#children[i].id === id)
|
|
269
291
|
return this.#children[i];
|
|
270
292
|
return;
|
|
271
293
|
}
|
|
272
294
|
|
|
273
|
-
public getData(id: string):
|
|
295
|
+
public getData(id: string): ITreeNodeData | undefined {
|
|
274
296
|
for (let i = 0; i < this.#data.length; i++)
|
|
275
297
|
if (this.#data[i].id === id)
|
|
276
298
|
return this.#data[i];
|
|
277
299
|
return;
|
|
278
300
|
}
|
|
279
301
|
|
|
280
|
-
public getNodesByName(name: string):
|
|
281
|
-
|
|
282
|
-
if (name === this.name) nodes.push(<
|
|
302
|
+
public getNodesByName(name: string): ITreeNode[] {
|
|
303
|
+
const nodes: ITreeNode[] = [];
|
|
304
|
+
if (name === this.name) nodes.push(<ITreeNode><unknown>this);
|
|
283
305
|
this.traverse((n) => {
|
|
284
306
|
if (name === n.name) nodes.push(n);
|
|
285
307
|
});
|
|
286
308
|
return nodes;
|
|
287
|
-
}
|
|
309
|
+
}
|
|
288
310
|
|
|
289
|
-
public getNodesByNameWithRegex(regex: RegExp):
|
|
290
|
-
|
|
291
|
-
if (regex.test(this.name)) nodes.push(<
|
|
311
|
+
public getNodesByNameWithRegex(regex: RegExp): ITreeNode[] {
|
|
312
|
+
const nodes: ITreeNode[] = [];
|
|
313
|
+
if (regex.test(this.name)) nodes.push(<ITreeNode><unknown>this);
|
|
292
314
|
this.traverse((n) => {
|
|
293
315
|
if (regex.test(n.name)) nodes.push(n);
|
|
294
316
|
});
|
|
295
317
|
return nodes;
|
|
296
|
-
}
|
|
318
|
+
}
|
|
297
319
|
|
|
298
320
|
public getPath(): string {
|
|
299
321
|
let path = this.name;
|
|
300
|
-
let node:
|
|
322
|
+
let node: ITreeNode | undefined = this.parent;
|
|
301
323
|
while (node) {
|
|
302
324
|
path = node.name + '.' + path;
|
|
303
325
|
node = node.parent;
|
|
@@ -312,11 +334,11 @@ export abstract class AbstractTreeNode<T extends ITreeNode<any, ITreeNodeData<an
|
|
|
312
334
|
return;
|
|
313
335
|
}
|
|
314
336
|
|
|
315
|
-
public hasChild(child:
|
|
337
|
+
public hasChild(child: ITreeNode): boolean {
|
|
316
338
|
return this.#children.includes(child);
|
|
317
339
|
}
|
|
318
340
|
|
|
319
|
-
public hasData(data:
|
|
341
|
+
public hasData(data: ITreeNodeData): boolean {
|
|
320
342
|
return this.#data.includes(data);
|
|
321
343
|
}
|
|
322
344
|
|
|
@@ -324,16 +346,16 @@ export abstract class AbstractTreeNode<T extends ITreeNode<any, ITreeNodeData<an
|
|
|
324
346
|
return this.#transformations.includes(transformation);
|
|
325
347
|
}
|
|
326
348
|
|
|
327
|
-
public removeChild(child:
|
|
349
|
+
public removeChild(child: ITreeNode): boolean {
|
|
328
350
|
const index = this.#children.indexOf(child);
|
|
329
351
|
if (index === -1) return false;
|
|
330
352
|
this.#children.splice(index, 1);
|
|
331
|
-
(<
|
|
353
|
+
(<ITreeNode | undefined>child.parent) = undefined;
|
|
332
354
|
|
|
333
355
|
return true;
|
|
334
356
|
}
|
|
335
357
|
|
|
336
|
-
public removeData(data:
|
|
358
|
+
public removeData(data: ITreeNodeData): boolean {
|
|
337
359
|
const index = this.#data.indexOf(data);
|
|
338
360
|
if (index === -1) return false;
|
|
339
361
|
this.#data.splice(index, 1);
|
|
@@ -349,33 +371,39 @@ export abstract class AbstractTreeNode<T extends ITreeNode<any, ITreeNodeData<an
|
|
|
349
371
|
return true;
|
|
350
372
|
}
|
|
351
373
|
|
|
352
|
-
public traverse(callback: (node:
|
|
353
|
-
callback(<
|
|
374
|
+
public traverse(callback: (node: ITreeNode) => void): void {
|
|
375
|
+
callback(<ITreeNode><unknown>this);
|
|
354
376
|
|
|
355
|
-
for(let i = 0; i < this.children.length; i++)
|
|
377
|
+
for (let i = 0; i < this.children.length; i++)
|
|
356
378
|
this.children[i].traverse(callback);
|
|
357
379
|
}
|
|
358
380
|
|
|
359
|
-
public traverseData(callback: (node:
|
|
360
|
-
for(let j = 0; j < this.data.length; j++)
|
|
361
|
-
callback(<
|
|
381
|
+
public traverseData(callback: (node: ITreeNodeData) => void): void {
|
|
382
|
+
for (let j = 0; j < this.data.length; j++)
|
|
383
|
+
callback(<ITreeNodeData>this.data[j]);
|
|
362
384
|
|
|
363
|
-
for(let i = 0; i < this.children.length; i++)
|
|
364
|
-
this.children[i].traverseData(<(data: ITreeNodeData
|
|
385
|
+
for (let i = 0; i < this.children.length; i++)
|
|
386
|
+
this.children[i].traverseData(<(data: ITreeNodeData) => void>callback);
|
|
365
387
|
}
|
|
366
388
|
|
|
367
|
-
public updateVersion(): void {
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
389
|
+
public updateVersion(parents: boolean = true, children: boolean = true): void {
|
|
390
|
+
if (parents === true) {
|
|
391
|
+
let node = <ITreeNode>this;
|
|
392
|
+
while (node.parent) {
|
|
393
|
+
node = node.parent;
|
|
394
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
395
|
+
// @ts-ignore
|
|
396
|
+
node.version = this.#uuidGenerator.create();
|
|
397
|
+
}
|
|
372
398
|
}
|
|
373
399
|
|
|
374
|
-
|
|
375
|
-
this.#children
|
|
400
|
+
if (children === true) {
|
|
401
|
+
for (let i = 0; i < this.#children.length; i++)
|
|
402
|
+
this.#children[i].updateVersion(parents, children);
|
|
403
|
+
}
|
|
376
404
|
|
|
377
405
|
this.#version = this.#uuidGenerator.create();
|
|
378
406
|
}
|
|
379
407
|
|
|
380
|
-
// #endregion Public Methods (
|
|
408
|
+
// #endregion Public Methods (20)
|
|
381
409
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { AbstractTreeNodeDataThreeJs } from './implementation/three/AbstractTreeNodeDataThreeJs'
|
|
1
|
+
import { AbstractTreeNodeData } from './implementation/AbstractTreeNodeData';
|
|
2
|
+
import { ITransformation, ITreeNode } from './interfaces/ITreeNode';
|
|
3
|
+
import { ITree } from './interfaces/ITree';
|
|
4
|
+
import { ITreeNodeData } from './interfaces/ITreeNodeData';
|
|
5
|
+
import { Tree } from './implementation/Tree';
|
|
6
|
+
import { TreeNode } from './implementation/TreeNode';
|
|
8
7
|
|
|
9
8
|
export {
|
|
10
|
-
|
|
11
|
-
}
|
|
9
|
+
ITree, Tree
|
|
10
|
+
};
|
|
12
11
|
|
|
13
12
|
export {
|
|
14
|
-
|
|
15
|
-
}
|
|
13
|
+
ITreeNode, TreeNode, ITransformation
|
|
14
|
+
};
|
|
16
15
|
|
|
17
16
|
export {
|
|
18
|
-
|
|
19
|
-
}
|
|
17
|
+
ITreeNodeData, AbstractTreeNodeData
|
|
18
|
+
};
|
package/src/interfaces/ITree.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { ITreeNode } from
|
|
2
|
-
import { ITreeNodeData } from "./ITreeNodeData";
|
|
1
|
+
import { ITreeNode } from './ITreeNode';
|
|
3
2
|
|
|
4
|
-
export interface ITree
|
|
3
|
+
export interface ITree {
|
|
5
4
|
// #region Properties (1)
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* The root of the tree.
|
|
9
8
|
*/
|
|
10
|
-
readonly root:
|
|
9
|
+
readonly root: ITreeNode;
|
|
11
10
|
|
|
12
11
|
// #endregion Properties (1)
|
|
13
12
|
|
|
@@ -20,8 +19,7 @@ export interface ITree<T extends ITreeNode<any, ITreeNodeData<any>>> {
|
|
|
20
19
|
* @param parent the targeted parent node
|
|
21
20
|
* @param root optional root at which the process begins, root node will be used per default
|
|
22
21
|
*/
|
|
23
|
-
addNode(node:
|
|
24
|
-
|
|
22
|
+
addNode(node: ITreeNode, parent?: ITreeNode, root?: ITreeNode): boolean;
|
|
25
23
|
/**
|
|
26
24
|
* Add the node at the corresponding path. (paths are dot separated ids)
|
|
27
25
|
*
|
|
@@ -29,8 +27,7 @@ export interface ITree<T extends ITreeNode<any, ITreeNodeData<any>>> {
|
|
|
29
27
|
* @param path the path at which the node should be added
|
|
30
28
|
* @param root optional root at which the process begins, root node will be used per default
|
|
31
29
|
*/
|
|
32
|
-
addNodeAtPath(node:
|
|
33
|
-
|
|
30
|
+
addNodeAtPath(node: ITreeNode, path?: string, root?: ITreeNode): boolean;
|
|
34
31
|
/**
|
|
35
32
|
* Get the node at the provided path.
|
|
36
33
|
*
|
|
@@ -38,23 +35,21 @@ export interface ITree<T extends ITreeNode<any, ITreeNodeData<any>>> {
|
|
|
38
35
|
* @param root
|
|
39
36
|
* @returns
|
|
40
37
|
*/
|
|
41
|
-
getNodeAtPath(path?: string, root?:
|
|
42
|
-
|
|
38
|
+
getNodeAtPath(path?: string, root?: ITreeNode): ITreeNode | null;
|
|
43
39
|
/**
|
|
44
40
|
* Remove a node from the tree.
|
|
45
41
|
*
|
|
46
42
|
* @param node the node to remove
|
|
47
43
|
* @param root optional root at which the process begins, root node will be used per default
|
|
48
44
|
*/
|
|
49
|
-
removeNode(node:
|
|
50
|
-
|
|
45
|
+
removeNode(node: ITreeNode, root?: ITreeNode): boolean;
|
|
51
46
|
/**
|
|
52
47
|
* Remove a node via the path of it.
|
|
53
48
|
*
|
|
54
49
|
* @param path the path of the node to be removed
|
|
55
50
|
* @param root optional root at which the process begins, root node will be used per default
|
|
56
51
|
*/
|
|
57
|
-
removeNodeAtPath(path: string, root?:
|
|
52
|
+
removeNodeAtPath(path: string, root?: ITreeNode): boolean;
|
|
58
53
|
|
|
59
54
|
// #endregion Public Methods (5)
|
|
60
55
|
}
|