@itwin/presentation-hierarchies-react 2.0.0-alpha.52 → 2.0.0-alpha.54
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/CHANGELOG.md +33 -0
- package/lib/esm/presentation-hierarchies-react/Renderers.d.ts +62 -55
- package/lib/esm/presentation-hierarchies-react/Renderers.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/TreeNode.d.ts +33 -29
- package/lib/esm/presentation-hierarchies-react/TreeNode.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.d.ts +27 -16
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.js +181 -54
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.d.ts +12 -6
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.js +54 -49
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.d.ts +7 -30
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.js +116 -74
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.d.ts +67 -54
- package/lib/esm/presentation-hierarchies-react/UseTree.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.js +283 -226
- package/lib/esm/presentation-hierarchies-react/UseTree.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/Utils.js +44 -27
- package/lib/esm/presentation-hierarchies-react/Utils.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/DisposePolyfill.js +6 -7
- package/lib/esm/presentation-hierarchies-react/internal/DisposePolyfill.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.js +271 -298
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.js +91 -82
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.d.ts +3 -47
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.js +114 -151
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts +32 -37
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.js +128 -101
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/Utils.js +29 -44
- package/lib/esm/presentation-hierarchies-react/internal/Utils.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts +24 -13
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js +344 -67
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts +16 -15
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.js +78 -60
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts +122 -117
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.js +59 -38
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts +16 -5
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.js +161 -35
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeAction.d.ts +21 -17
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeAction.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeAction.js +84 -31
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeAction.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts +22 -14
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js +61 -26
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.d.ts +15 -6
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.js +75 -25
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.d.ts +16 -40
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js +140 -61
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts +14 -42
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js +489 -121
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts +58 -55
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js +412 -181
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react.d.ts +17 -17
- package/lib/esm/presentation-hierarchies-react.js +15 -18
- package/package.json +17 -14
- package/lib/esm/presentation-hierarchies-react/Renderers.js +0 -6
- package/lib/esm/presentation-hierarchies-react/Renderers.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/TreeNode.js +0 -6
- package/lib/esm/presentation-hierarchies-react/TreeNode.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/Utils.d.ts +0 -8
- package/lib/esm/presentation-hierarchies-react/Utils.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/internal/DisposePolyfill.d.ts +0 -2
- package/lib/esm/presentation-hierarchies-react/internal/DisposePolyfill.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.d.ts +0 -53
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.d.ts +0 -62
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/internal/Utils.d.ts +0 -23
- package/lib/esm/presentation-hierarchies-react/internal/Utils.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react.js.map +0 -1
|
@@ -1,322 +1,295 @@
|
|
|
1
|
-
/*---------------------------------------------------------------------------------------------
|
|
2
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
-
*--------------------------------------------------------------------------------------------*/
|
|
5
1
|
import "./DisposePolyfill.js";
|
|
6
|
-
import {
|
|
7
|
-
import { buffer, debounceTime, EMPTY, groupBy, map, mergeMap, reduce, Subject, switchMap, takeUntil, tap } from "rxjs";
|
|
8
|
-
import { HierarchyNode } from "@itwin/presentation-hierarchies";
|
|
2
|
+
import { createNodeId, sameNodes } from "./Utils.js";
|
|
9
3
|
import { TreeLoader } from "./TreeLoader.js";
|
|
10
4
|
import { TreeModel } from "./TreeModel.js";
|
|
11
|
-
import {
|
|
5
|
+
import { HierarchyNode } from "@itwin/presentation-hierarchies";
|
|
6
|
+
import { enableMapSet, produce } from "immer";
|
|
7
|
+
import { EMPTY, Subject, buffer, debounceTime, groupBy, map, mergeMap, reduce, switchMap, takeUntil, tap } from "rxjs";
|
|
8
|
+
|
|
9
|
+
//#region src/presentation-hierarchies-react/internal/TreeActions.ts
|
|
12
10
|
enableMapSet();
|
|
13
11
|
/** @internal */
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
reloadTree(options) {
|
|
204
|
-
const oldModel = this._currentModel;
|
|
205
|
-
this.updateTreeModel((model) => {
|
|
206
|
-
TreeModel.setIsLoading(model, options?.parentNodeId, true);
|
|
207
|
-
if (options?.state === "reset") {
|
|
208
|
-
TreeModel.removeSubTree(model, options?.parentNodeId);
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
const discardState = options?.state === "discard" || options?.state === "reset";
|
|
212
|
-
const ignoreCache = options?.state === "reset";
|
|
213
|
-
return this.reloadSubTree(options?.parentNodeId, oldModel, { discardState, ignoreCache });
|
|
214
|
-
}
|
|
215
|
-
}
|
|
12
|
+
var TreeActions = class {
|
|
13
|
+
_loader;
|
|
14
|
+
_nodeIdFactory;
|
|
15
|
+
_currentModel;
|
|
16
|
+
_reset = new Subject();
|
|
17
|
+
_nodeLoader;
|
|
18
|
+
constructor(_onModelChanged, _onLoad, _onHierarchyLimitExceeded, _onHierarchyLoadError, nodeIdFactory, seed) {
|
|
19
|
+
this._onModelChanged = _onModelChanged;
|
|
20
|
+
this._onLoad = _onLoad;
|
|
21
|
+
this._onHierarchyLimitExceeded = _onHierarchyLimitExceeded;
|
|
22
|
+
this._onHierarchyLoadError = _onHierarchyLoadError;
|
|
23
|
+
this._loader = new NoopTreeLoader();
|
|
24
|
+
this._nodeIdFactory = nodeIdFactory ?? createNodeId;
|
|
25
|
+
this._currentModel = seed ?? ( /* c8 ignore next */ {
|
|
26
|
+
idToNode: /* @__PURE__ */ new Map(),
|
|
27
|
+
parentChildMap: /* @__PURE__ */ new Map(),
|
|
28
|
+
rootNode: {
|
|
29
|
+
id: void 0,
|
|
30
|
+
nodeData: void 0
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
this._nodeLoader = this.createNodeLoader();
|
|
34
|
+
}
|
|
35
|
+
createNodeLoader() {
|
|
36
|
+
const subject = new Subject();
|
|
37
|
+
subject.pipe(groupBy((item) => item.parentId), mergeMap((group) => group.pipe(buffer(group.pipe(debounceTime(0))), map((groupArr) => {
|
|
38
|
+
let returnIndex = groupArr.length - 1;
|
|
39
|
+
groupArr.forEach((member, index) => {
|
|
40
|
+
if (member.discardState) returnIndex = index;
|
|
41
|
+
});
|
|
42
|
+
groupArr.forEach((member, index) => {
|
|
43
|
+
if (index === returnIndex) return;
|
|
44
|
+
member.timeTracker?.[Symbol.dispose];
|
|
45
|
+
member.onComplete();
|
|
46
|
+
});
|
|
47
|
+
return groupArr[returnIndex];
|
|
48
|
+
}), switchMap((props) => this._loader.loadNodes(props.loadOptions).pipe(collectTreePartsUntil(this._reset, props.initialRootNode), tap({
|
|
49
|
+
next: (newModel) => {
|
|
50
|
+
const parentNode = props.parentId ? newModel.idToNode.get(props.parentId) : newModel.rootNode;
|
|
51
|
+
this.handleLoadedHierarchy(props.parentId, newModel);
|
|
52
|
+
if (!(parentNode && parentNode.error)) props.timeTracker?.finish();
|
|
53
|
+
},
|
|
54
|
+
complete: () => {
|
|
55
|
+
this.onLoadingComplete(props.parentId);
|
|
56
|
+
props.timeTracker?.[Symbol.dispose]();
|
|
57
|
+
props.onComplete();
|
|
58
|
+
}
|
|
59
|
+
})))))).subscribe();
|
|
60
|
+
return subject;
|
|
61
|
+
}
|
|
62
|
+
updateTreeModel(updater) {
|
|
63
|
+
const newModel = produce(this._currentModel, updater);
|
|
64
|
+
if (this._currentModel === newModel) return;
|
|
65
|
+
this._currentModel = newModel;
|
|
66
|
+
this._onModelChanged(this._currentModel);
|
|
67
|
+
}
|
|
68
|
+
handleLoadedHierarchy(parentId, loadedHierarchy) {
|
|
69
|
+
this.updateTreeModel((model) => {
|
|
70
|
+
TreeModel.addHierarchyPart(model, parentId, loadedHierarchy);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
onLoadingComplete(parentId) {
|
|
74
|
+
this.updateTreeModel((model) => {
|
|
75
|
+
TreeModel.setIsLoading(model, parentId, false);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
getLoadAction(parentId) {
|
|
79
|
+
return this._currentModel.idToNode.size === 0 ? "initial-load" : parentId === void 0 ? "reload" : "hierarchy-level-load";
|
|
80
|
+
}
|
|
81
|
+
loadSubTree(options, initialRootNode, discardState) {
|
|
82
|
+
const loadAction = this.getLoadAction(options.parent.id);
|
|
83
|
+
const timeTracker = new TimeTracker((time) => this._onLoad(loadAction, time));
|
|
84
|
+
return { complete: new Promise((resolve) => {
|
|
85
|
+
this._nodeLoader.next({
|
|
86
|
+
loadOptions: options,
|
|
87
|
+
onComplete: resolve,
|
|
88
|
+
timeTracker,
|
|
89
|
+
parentId: options.parent.id,
|
|
90
|
+
initialRootNode,
|
|
91
|
+
discardState
|
|
92
|
+
});
|
|
93
|
+
}) };
|
|
94
|
+
}
|
|
95
|
+
loadNodes(parentId, ignoreCache) {
|
|
96
|
+
const parentNode = this._currentModel.idToNode.get(parentId);
|
|
97
|
+
/* c8 ignore next 3 */
|
|
98
|
+
if (!parentNode) return { complete: Promise.resolve() };
|
|
99
|
+
return this.loadSubTree({
|
|
100
|
+
parent: parentNode,
|
|
101
|
+
getHierarchyLevelOptions: (node) => createHierarchyLevelOptions(this._currentModel, getNonGroupedParentId(node, this._nodeIdFactory)),
|
|
102
|
+
shouldLoadChildren: (node) => !!node.nodeData.autoExpand,
|
|
103
|
+
ignoreCache
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
reloadSubTree(parentId, oldModel, options) {
|
|
107
|
+
const currModel = this._currentModel;
|
|
108
|
+
const expandedNodes = !!options?.discardState ? [] : collectNodes(parentId, oldModel, (node) => node.isExpanded === true);
|
|
109
|
+
const collapsedNodes = !!options?.discardState ? [] : collectNodes(parentId, oldModel, (node) => node.isExpanded === false);
|
|
110
|
+
const getHierarchyLevelOptions = (node) => {
|
|
111
|
+
if (!!options?.discardState) return {
|
|
112
|
+
instanceFilter: void 0,
|
|
113
|
+
hierarchyLevelSizeLimit: void 0
|
|
114
|
+
};
|
|
115
|
+
const filteredNodeId = getNonGroupedParentId(node, this._nodeIdFactory);
|
|
116
|
+
return createHierarchyLevelOptions(filteredNodeId === parentId ? currModel : oldModel, filteredNodeId);
|
|
117
|
+
};
|
|
118
|
+
const shouldLoadChildren = (node) => {
|
|
119
|
+
if (expandedNodes.findIndex((expandedNode) => sameNodes(expandedNode.nodeData, node.nodeData)) !== -1) return true;
|
|
120
|
+
if (collapsedNodes.findIndex((collapsedNode) => sameNodes(collapsedNode.nodeData, node.nodeData)) !== -1) return false;
|
|
121
|
+
return !!node.nodeData.autoExpand;
|
|
122
|
+
};
|
|
123
|
+
const buildNode = (node) => !!options?.discardState || node.id === parentId ? node : addAttributes(node, oldModel);
|
|
124
|
+
const rootNode = parentId !== void 0 ? this.getNode(parentId) : currModel.rootNode;
|
|
125
|
+
/* c8 ignore next 3 */
|
|
126
|
+
if (!rootNode) return { complete: Promise.resolve() };
|
|
127
|
+
if (parentId === void 0) this._reset.next();
|
|
128
|
+
return this.loadSubTree({
|
|
129
|
+
parent: rootNode,
|
|
130
|
+
getHierarchyLevelOptions,
|
|
131
|
+
shouldLoadChildren,
|
|
132
|
+
buildNode,
|
|
133
|
+
ignoreCache: options?.ignoreCache
|
|
134
|
+
}, !!options?.discardState ? void 0 : { ...currModel.rootNode }, options?.discardState);
|
|
135
|
+
}
|
|
136
|
+
reset() {
|
|
137
|
+
this._reset.next();
|
|
138
|
+
}
|
|
139
|
+
setHierarchyProvider(provider) {
|
|
140
|
+
this._loader = provider ? new TreeLoader(provider, this._onHierarchyLimitExceeded, ({ parentId, type, error }) => {
|
|
141
|
+
if (type === "timeout") {
|
|
142
|
+
const loadAction = this.getLoadAction(parentId);
|
|
143
|
+
this._onLoad(loadAction, Number.MAX_SAFE_INTEGER);
|
|
144
|
+
}
|
|
145
|
+
this._onHierarchyLoadError({
|
|
146
|
+
parentId,
|
|
147
|
+
type,
|
|
148
|
+
error
|
|
149
|
+
});
|
|
150
|
+
}, this._nodeIdFactory) : new NoopTreeLoader();
|
|
151
|
+
}
|
|
152
|
+
getNode(nodeId) {
|
|
153
|
+
return TreeModel.getNode(this._currentModel, nodeId);
|
|
154
|
+
}
|
|
155
|
+
selectNodes(nodeIds, changeType) {
|
|
156
|
+
this.updateTreeModel((model) => {
|
|
157
|
+
TreeModel.selectNodes(model, nodeIds, changeType);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
expandNode(nodeId, isExpanded) {
|
|
161
|
+
let childrenAction = "none";
|
|
162
|
+
this.updateTreeModel((model) => {
|
|
163
|
+
childrenAction = TreeModel.expandNode(model, nodeId, isExpanded);
|
|
164
|
+
});
|
|
165
|
+
if (childrenAction === "none") return { complete: Promise.resolve() };
|
|
166
|
+
return this.loadNodes(nodeId, childrenAction === "reloadChildren");
|
|
167
|
+
}
|
|
168
|
+
setHierarchyLimit(nodeId, limit) {
|
|
169
|
+
const oldModel = this._currentModel;
|
|
170
|
+
let loadChildren = false;
|
|
171
|
+
this.updateTreeModel((model) => {
|
|
172
|
+
loadChildren = TreeModel.setHierarchyLimit(model, nodeId, limit);
|
|
173
|
+
});
|
|
174
|
+
if (!loadChildren) return { complete: Promise.resolve() };
|
|
175
|
+
return this.reloadSubTree(nodeId, oldModel);
|
|
176
|
+
}
|
|
177
|
+
setInstanceFilter(nodeId, filter) {
|
|
178
|
+
const oldModel = this._currentModel;
|
|
179
|
+
let loadChildren = false;
|
|
180
|
+
this.updateTreeModel((model) => {
|
|
181
|
+
loadChildren = TreeModel.setInstanceFilter(model, nodeId, filter);
|
|
182
|
+
});
|
|
183
|
+
if (!loadChildren) return { complete: Promise.resolve() };
|
|
184
|
+
return this.reloadSubTree(nodeId, oldModel);
|
|
185
|
+
}
|
|
186
|
+
reloadTree(options) {
|
|
187
|
+
const oldModel = this._currentModel;
|
|
188
|
+
this.updateTreeModel((model) => {
|
|
189
|
+
TreeModel.setIsLoading(model, options?.parentNodeId, true);
|
|
190
|
+
if (options?.state === "reset") TreeModel.removeSubTree(model, options.parentNodeId);
|
|
191
|
+
});
|
|
192
|
+
const discardState = options?.state === "discard" || options?.state === "reset";
|
|
193
|
+
const ignoreCache = options?.state === "reset";
|
|
194
|
+
return this.reloadSubTree(options?.parentNodeId, oldModel, {
|
|
195
|
+
discardState,
|
|
196
|
+
ignoreCache
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
};
|
|
216
200
|
function collectTreePartsUntil(untilNotifier, rootNode) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
201
|
+
return (source) => source.pipe(reduce((treeModel, loadedPart) => {
|
|
202
|
+
addTreePartToModel(treeModel, loadedPart);
|
|
203
|
+
return treeModel;
|
|
204
|
+
}, {
|
|
205
|
+
idToNode: /* @__PURE__ */ new Map(),
|
|
206
|
+
parentChildMap: /* @__PURE__ */ new Map(),
|
|
207
|
+
rootNode: rootNode ?? {
|
|
208
|
+
id: void 0,
|
|
209
|
+
nodeData: void 0
|
|
210
|
+
}
|
|
211
|
+
}), takeUntil(untilNotifier));
|
|
225
212
|
}
|
|
226
213
|
function addTreePartToModel(treeModel, loadedPart) {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
else {
|
|
231
|
-
addErrorToModel(treeModel, loadedPart);
|
|
232
|
-
}
|
|
214
|
+
if ("loadedNodes" in loadedPart) addNodesToModel(treeModel, loadedPart);
|
|
215
|
+
else addErrorToModel(treeModel, loadedPart);
|
|
233
216
|
}
|
|
234
217
|
function addErrorToModel(model, loadedPart) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
}
|
|
218
|
+
if (loadedPart.parent.id === void 0) model.rootNode.error = loadedPart.error;
|
|
219
|
+
else model.idToNode.set(loadedPart.parent.id, {
|
|
220
|
+
...loadedPart.parent,
|
|
221
|
+
error: loadedPart.error
|
|
222
|
+
});
|
|
241
223
|
}
|
|
242
224
|
function addNodesToModel(model, loadedPart) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
const parentNode = loadedPart.parent.id ? model.idToNode.get(loadedPart.parent.id) : undefined;
|
|
248
|
-
if (parentNode && loadedPart.loadedNodes.length !== 0) {
|
|
249
|
-
parentNode.isExpanded = true;
|
|
250
|
-
}
|
|
225
|
+
model.parentChildMap.set(loadedPart.parent.id, loadedPart.loadedNodes.map((node) => node.id));
|
|
226
|
+
for (const node of loadedPart.loadedNodes) model.idToNode.set(node.id, node);
|
|
227
|
+
const parentNode = loadedPart.parent.id ? model.idToNode.get(loadedPart.parent.id) : void 0;
|
|
228
|
+
if (parentNode && loadedPart.loadedNodes.length !== 0) parentNode.isExpanded = true;
|
|
251
229
|
}
|
|
252
230
|
function addAttributes(node, oldModel) {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
231
|
+
const oldNode = oldModel.idToNode.get(node.id);
|
|
232
|
+
if (oldNode) {
|
|
233
|
+
node.hierarchyLimit = oldNode.hierarchyLimit;
|
|
234
|
+
node.instanceFilter = oldNode.instanceFilter;
|
|
235
|
+
node.isSelected = oldNode.isSelected;
|
|
236
|
+
}
|
|
237
|
+
return node;
|
|
260
238
|
}
|
|
261
239
|
function collectNodes(parentId, model, pred) {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}
|
|
269
|
-
const currNode = model.idToNode.get(parentId);
|
|
270
|
-
if (!currNode || !pred(currNode)) {
|
|
271
|
-
return [];
|
|
272
|
-
}
|
|
273
|
-
return [currNode, ...currentChildren.flatMap((child) => collectNodes(child, model, pred))];
|
|
240
|
+
const currentChildren = model.parentChildMap.get(parentId);
|
|
241
|
+
if (!currentChildren) return [];
|
|
242
|
+
if (parentId === void 0) return currentChildren.flatMap((child) => collectNodes(child, model, pred));
|
|
243
|
+
const currNode = model.idToNode.get(parentId);
|
|
244
|
+
if (!currNode || !pred(currNode)) return [];
|
|
245
|
+
return [currNode, ...currentChildren.flatMap((child) => collectNodes(child, model, pred))];
|
|
274
246
|
}
|
|
275
247
|
function getNonGroupedParentId(node, nodeIdFactory) {
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
if (!node.nodeData.nonGroupingAncestor) {
|
|
280
|
-
return undefined;
|
|
281
|
-
}
|
|
282
|
-
return nodeIdFactory(node.nodeData.nonGroupingAncestor);
|
|
248
|
+
if (!node.nodeData || !HierarchyNode.isGroupingNode(node.nodeData)) return node.id;
|
|
249
|
+
if (!node.nodeData.nonGroupingAncestor) return;
|
|
250
|
+
return nodeIdFactory(node.nodeData.nonGroupingAncestor);
|
|
283
251
|
}
|
|
284
252
|
function createHierarchyLevelOptions(model, nodeId) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
253
|
+
if (nodeId === void 0) return {
|
|
254
|
+
instanceFilter: model.rootNode.instanceFilter,
|
|
255
|
+
hierarchyLevelSizeLimit: model.rootNode.hierarchyLimit
|
|
256
|
+
};
|
|
257
|
+
const modelNode = model.idToNode.get(nodeId);
|
|
258
|
+
if (!modelNode) return {
|
|
259
|
+
instanceFilter: void 0,
|
|
260
|
+
hierarchyLevelSizeLimit: void 0
|
|
261
|
+
};
|
|
262
|
+
return {
|
|
263
|
+
instanceFilter: modelNode.instanceFilter,
|
|
264
|
+
hierarchyLevelSizeLimit: modelNode.hierarchyLimit
|
|
265
|
+
};
|
|
293
266
|
}
|
|
294
267
|
/* c8 ignore start */
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
}
|
|
268
|
+
var NoopTreeLoader = class {
|
|
269
|
+
loadNodes() {
|
|
270
|
+
return EMPTY;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
300
273
|
/* c8 ignore end */
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
}
|
|
274
|
+
var TimeTracker = class {
|
|
275
|
+
_start;
|
|
276
|
+
_stopped = false;
|
|
277
|
+
constructor(_onFinish) {
|
|
278
|
+
this._onFinish = _onFinish;
|
|
279
|
+
this._start = Date.now();
|
|
280
|
+
}
|
|
281
|
+
[Symbol.dispose]() {
|
|
282
|
+
this._stopped = true;
|
|
283
|
+
}
|
|
284
|
+
finish() {
|
|
285
|
+
/* c8 ignore next 3 */
|
|
286
|
+
if (this._stopped) return;
|
|
287
|
+
this._stopped = true;
|
|
288
|
+
const elapsedTime = Date.now() - this._start;
|
|
289
|
+
this._onFinish(elapsedTime);
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
//#endregion
|
|
294
|
+
export { TreeActions };
|
|
322
295
|
//# sourceMappingURL=TreeActions.js.map
|