@itwin/presentation-hierarchies-react 2.0.0-alpha.53 → 2.0.0-alpha.55
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 +58 -0
- package/README.md +23 -61
- package/lib/presentation-hierarchies-react/Renderers.d.ts +92 -0
- package/lib/presentation-hierarchies-react/Renderers.d.ts.map +1 -0
- package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/TreeNode.d.ts +33 -29
- package/lib/presentation-hierarchies-react/TreeNode.d.ts.map +1 -0
- package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/UseIModelTree.d.ts +28 -17
- package/lib/presentation-hierarchies-react/UseIModelTree.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/UseIModelTree.js +184 -0
- package/lib/presentation-hierarchies-react/UseIModelTree.js.map +1 -0
- package/lib/presentation-hierarchies-react/UseNodeHighlighting.d.ts +30 -0
- package/lib/presentation-hierarchies-react/UseNodeHighlighting.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/UseNodeHighlighting.js +58 -0
- package/lib/presentation-hierarchies-react/UseNodeHighlighting.js.map +1 -0
- package/lib/presentation-hierarchies-react/UseSelectionHandler.d.ts +25 -0
- package/lib/presentation-hierarchies-react/UseSelectionHandler.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/UseSelectionHandler.js +125 -0
- package/lib/presentation-hierarchies-react/UseSelectionHandler.js.map +1 -0
- package/lib/presentation-hierarchies-react/UseTree.d.ts +112 -0
- package/lib/presentation-hierarchies-react/UseTree.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/UseTree.js +294 -0
- package/lib/presentation-hierarchies-react/UseTree.js.map +1 -0
- package/lib/presentation-hierarchies-react/Utils.js +56 -0
- package/lib/presentation-hierarchies-react/Utils.js.map +1 -0
- package/lib/presentation-hierarchies-react/internal/DisposePolyfill.js +10 -0
- package/lib/presentation-hierarchies-react/internal/DisposePolyfill.js.map +1 -0
- package/lib/presentation-hierarchies-react/internal/LocalizedStrings.d.ts +9 -0
- package/lib/presentation-hierarchies-react/internal/LocalizedStrings.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/internal/LocalizedStrings.js +12 -0
- package/lib/presentation-hierarchies-react/internal/LocalizedStrings.js.map +1 -0
- package/lib/presentation-hierarchies-react/internal/TreeActions.js +295 -0
- package/lib/presentation-hierarchies-react/internal/TreeActions.js.map +1 -0
- package/lib/presentation-hierarchies-react/internal/TreeLoader.js +99 -0
- package/lib/presentation-hierarchies-react/internal/TreeLoader.js.map +1 -0
- package/lib/presentation-hierarchies-react/internal/TreeModel.d.ts +3 -0
- package/lib/presentation-hierarchies-react/internal/TreeModel.js +120 -0
- package/lib/presentation-hierarchies-react/internal/TreeModel.js.map +1 -0
- package/lib/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts +37 -0
- package/lib/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/internal/UseUnifiedSelection.js +142 -0
- package/lib/presentation-hierarchies-react/internal/UseUnifiedSelection.js.map +1 -0
- package/lib/presentation-hierarchies-react/internal/Utils.js +43 -0
- package/lib/presentation-hierarchies-react/internal/Utils.js.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts +38 -0
- package/lib/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js +381 -0
- package/lib/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js.map +1 -0
- package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/stratakit/FlatTreeNode.d.ts +16 -15
- package/lib/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/FlatTreeNode.js +91 -0
- package/lib/presentation-hierarchies-react/stratakit/FlatTreeNode.js.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts +24 -0
- package/lib/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/LocalizationContext.js +41 -0
- package/lib/presentation-hierarchies-react/stratakit/LocalizationContext.js.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts +27 -0
- package/lib/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/RootErrorRenderer.js +186 -0
- package/lib/presentation-hierarchies-react/stratakit/RootErrorRenderer.js.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeAction.d.ts +49 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeAction.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeAction.js +89 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeAction.js.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts +38 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js +64 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.d.ts +29 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.js +92 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.js.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.d.ts +33 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js +156 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts +18 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js +535 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts +75 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeRenderer.js +418 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeRenderer.js.map +1 -0
- package/lib/presentation-hierarchies-react.d.ts +18 -0
- package/lib/presentation-hierarchies-react.js +16 -0
- package/lib/public/locales/en/PresentationHierarchies_1.0.json +26 -0
- package/package.json +27 -21
- package/lib/esm/presentation-hierarchies-react/Renderers.d.ts +0 -85
- package/lib/esm/presentation-hierarchies-react/Renderers.d.ts.map +0 -1
- 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.d.ts.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/UseIModelTree.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.js +0 -62
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.d.ts +0 -24
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.js +0 -53
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.d.ts +0 -48
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.js +0 -83
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.d.ts +0 -94
- package/lib/esm/presentation-hierarchies-react/UseTree.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.js +0 -241
- package/lib/esm/presentation-hierarchies-react/UseTree.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/Utils.js +0 -39
- package/lib/esm/presentation-hierarchies-react/Utils.js.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/DisposePolyfill.js +0 -11
- package/lib/esm/presentation-hierarchies-react/internal/DisposePolyfill.js.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/TreeActions.js +0 -322
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.js.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/TreeLoader.js +0 -90
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.d.ts +0 -47
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.js +0 -157
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts +0 -42
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.js +0 -115
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.js.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/internal/Utils.js +0 -58
- package/lib/esm/presentation-hierarchies-react/internal/Utils.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts +0 -27
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js +0 -74
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.js +0 -73
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts +0 -138
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.js +0 -47
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts +0 -16
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.js +0 -42
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeAction.d.ts +0 -45
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeAction.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeAction.js +0 -36
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeAction.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts +0 -30
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js +0 -30
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.d.ts +0 -20
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.js +0 -29
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.d.ts +0 -57
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js +0 -71
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts +0 -46
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js +0 -133
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts +0 -75
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js +0 -193
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react.d.ts +0 -17
- package/lib/esm/presentation-hierarchies-react.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react.js +0 -18
- package/lib/esm/presentation-hierarchies-react.js.map +0 -1
- /package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/stratakit/TreeNodeRenderer.css +0 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import "./DisposePolyfill.js";
|
|
2
|
+
import { createNodeId, sameNodes } from "./Utils.js";
|
|
3
|
+
import { TreeLoader } from "./TreeLoader.js";
|
|
4
|
+
import { TreeModel } from "./TreeModel.js";
|
|
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
|
|
10
|
+
enableMapSet();
|
|
11
|
+
/** @internal */
|
|
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
|
+
};
|
|
200
|
+
function collectTreePartsUntil(untilNotifier, rootNode) {
|
|
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));
|
|
212
|
+
}
|
|
213
|
+
function addTreePartToModel(treeModel, loadedPart) {
|
|
214
|
+
if ("loadedNodes" in loadedPart) addNodesToModel(treeModel, loadedPart);
|
|
215
|
+
else addErrorToModel(treeModel, loadedPart);
|
|
216
|
+
}
|
|
217
|
+
function addErrorToModel(model, loadedPart) {
|
|
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
|
+
});
|
|
223
|
+
}
|
|
224
|
+
function addNodesToModel(model, loadedPart) {
|
|
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;
|
|
229
|
+
}
|
|
230
|
+
function addAttributes(node, oldModel) {
|
|
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;
|
|
238
|
+
}
|
|
239
|
+
function collectNodes(parentId, 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))];
|
|
246
|
+
}
|
|
247
|
+
function getNonGroupedParentId(node, nodeIdFactory) {
|
|
248
|
+
if (!node.nodeData || !HierarchyNode.isGroupingNode(node.nodeData)) return node.id;
|
|
249
|
+
if (!node.nodeData.nonGroupingAncestor) return;
|
|
250
|
+
return nodeIdFactory(node.nodeData.nonGroupingAncestor);
|
|
251
|
+
}
|
|
252
|
+
function createHierarchyLevelOptions(model, nodeId) {
|
|
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
|
+
};
|
|
266
|
+
}
|
|
267
|
+
/* c8 ignore start */
|
|
268
|
+
var NoopTreeLoader = class {
|
|
269
|
+
loadNodes() {
|
|
270
|
+
return EMPTY;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
/* c8 ignore end */
|
|
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 };
|
|
295
|
+
//# sourceMappingURL=TreeActions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreeActions.js","names":["enableMapSet","produce","buffer","debounceTime","EMPTY","groupBy","map","mergeMap","reduce","Subject","switchMap","takeUntil","tap","HierarchyNode","TreeLoader","TreeModel","createNodeId","sameNodes","Draft","Observable","GenericInstanceFilter","HierarchyProvider","ErrorInfo","SelectionChangeType","HierarchyLevelOptions","ITreeLoader","LoadedTreePart","LoadNodesOptions","TreeModelHierarchyNode","TreeModelRootNode","LoadDebouncedNodesOptions","loadOptions","onComplete","timeTracker","TimeTracker","initialRootNode","parentId","discardState","TreeActions","_loader","_nodeIdFactory","node","Pick","_currentModel","_reset","_nodeLoader","constructor","_onModelChanged","model","_onLoad","actionType","duration","_onHierarchyLimitExceeded","props","filter","limit","_onHierarchyLoadError","type","error","nodeIdFactory","seed","NoopTreeLoader","idToNode","Map","parentChildMap","rootNode","id","undefined","nodeData","createNodeLoader","subject","pipe","item","group","groupArr","returnIndex","length","forEach","member","index","Symbol","dispose","loadNodes","collectTreePartsUntil","next","newModel","parentNode","get","handleLoadedHierarchy","finish","complete","onLoadingComplete","subscribe","updateTreeModel","updater","loadedHierarchy","addHierarchyPart","setIsLoading","getLoadAction","size","loadSubTree","options","loadAction","parent","time","Promise","resolve","ignoreCache","getHierarchyLevelOptions","createHierarchyLevelOptions","getNonGroupedParentId","shouldLoadChildren","autoExpand","reloadSubTree","oldModel","currModel","expandedNodes","collectNodes","isExpanded","collapsedNodes","instanceFilter","hierarchyLevelSizeLimit","filteredNodeId","findIndex","expandedNode","collapsedNode","buildNode","addAttributes","getNode","reset","setHierarchyProvider","provider","Number","MAX_SAFE_INTEGER","nodeId","selectNodes","nodeIds","Array","changeType","expandNode","childrenAction","ReturnType","setHierarchyLimit","loadChildren","setInstanceFilter","reloadTree","parentNodeId","state","removeSubTree","untilNotifier","source","treeModel","loadedPart","addTreePartToModel","addNodesToModel","addErrorToModel","set","loadedNodes","oldNode","hierarchyLimit","isSelected","pred","currentChildren","flatMap","child","currNode","isGroupingNode","nonGroupingAncestor","modelNode","_start","_stopped","_onFinish","Date","now","elapsedTime"],"sources":["../../../src/presentation-hierarchies-react/internal/TreeActions.ts"],"sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport \"./DisposePolyfill.js\";\n\nimport { enableMapSet, produce } from \"immer\";\nimport { buffer, debounceTime, EMPTY, groupBy, map, mergeMap, reduce, Subject, switchMap, takeUntil, tap } from \"rxjs\";\nimport { HierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport { TreeLoader } from \"./TreeLoader.js\";\nimport { TreeModel } from \"./TreeModel.js\";\nimport { createNodeId, sameNodes } from \"./Utils.js\";\n\nimport type { Draft } from \"immer\";\nimport type { Observable } from \"rxjs\";\nimport type { GenericInstanceFilter, HierarchyProvider } from \"@itwin/presentation-hierarchies\";\nimport type { ErrorInfo } from \"../TreeNode.js\";\nimport type { SelectionChangeType } from \"../UseSelectionHandler.js\";\nimport type { HierarchyLevelOptions, ITreeLoader, LoadedTreePart, LoadNodesOptions } from \"./TreeLoader.js\";\nimport type { TreeModelHierarchyNode, TreeModelRootNode } from \"./TreeModel.js\";\n\nenableMapSet();\n\ninterface LoadDebouncedNodesOptions {\n loadOptions: LoadNodesOptions;\n onComplete: () => void;\n timeTracker?: TimeTracker;\n initialRootNode?: TreeModelRootNode;\n parentId?: string;\n discardState?: boolean;\n}\n\n/** @internal */\nexport class TreeActions {\n private _loader: ITreeLoader;\n private _nodeIdFactory: (node: Pick<HierarchyNode, \"key\" | \"parentKeys\">) => string;\n private _currentModel: TreeModel;\n private _reset = new Subject<void>();\n private _nodeLoader: Subject<LoadDebouncedNodesOptions>;\n\n constructor(\n private _onModelChanged: (model: TreeModel) => void,\n private _onLoad: (actionType: \"initial-load\" | \"hierarchy-level-load\" | \"reload\", duration: number) => void,\n private _onHierarchyLimitExceeded: (props: { parentId?: string; filter?: GenericInstanceFilter; limit?: number | \"unbounded\" }) => void,\n private _onHierarchyLoadError: (props: { parentId?: string; type: \"timeout\" | \"unknown\"; error: unknown }) => void,\n nodeIdFactory?: (node: Pick<HierarchyNode, \"key\" | \"parentKeys\">) => string,\n seed?: TreeModel,\n ) {\n this._loader = new NoopTreeLoader();\n this._nodeIdFactory = nodeIdFactory ?? createNodeId;\n this._currentModel = seed ?? /* c8 ignore next */ {\n idToNode: new Map(),\n parentChildMap: new Map(),\n rootNode: { id: undefined, nodeData: undefined },\n };\n\n this._nodeLoader = this.createNodeLoader();\n }\n\n private createNodeLoader() {\n const subject = new Subject<LoadDebouncedNodesOptions>();\n subject\n .pipe(\n groupBy((item) => item.parentId),\n mergeMap((group) =>\n group.pipe(\n buffer(group.pipe(debounceTime(0))),\n map((groupArr) => {\n let returnIndex = groupArr.length - 1;\n\n groupArr.forEach((member, index) => {\n if (member.discardState) {\n returnIndex = index;\n }\n });\n\n groupArr.forEach((member, index) => {\n if (index === returnIndex) {\n return;\n }\n member.timeTracker?.[Symbol.dispose];\n member.onComplete();\n });\n return groupArr[returnIndex];\n }),\n switchMap((props) =>\n this._loader.loadNodes(props.loadOptions).pipe(\n collectTreePartsUntil(this._reset, props.initialRootNode),\n tap({\n next: (newModel: TreeModel) => {\n const parentNode = props.parentId ? newModel.idToNode.get(props.parentId) : newModel.rootNode;\n this.handleLoadedHierarchy(props.parentId, newModel);\n // only report load duration if children were loaded\n if (!(parentNode && parentNode.error)) {\n props.timeTracker?.finish();\n }\n },\n complete: () => {\n this.onLoadingComplete(props.parentId);\n props.timeTracker?.[Symbol.dispose]();\n props.onComplete();\n },\n }),\n ),\n ),\n ),\n ),\n )\n .subscribe();\n\n return subject;\n }\n\n private updateTreeModel(updater: (model: Draft<TreeModel>) => void) {\n const newModel = produce(this._currentModel, updater);\n if (this._currentModel === newModel) {\n return;\n }\n\n this._currentModel = newModel;\n this._onModelChanged(this._currentModel);\n }\n\n private handleLoadedHierarchy(parentId: string | undefined, loadedHierarchy: TreeModel) {\n this.updateTreeModel((model) => {\n TreeModel.addHierarchyPart(model, parentId, loadedHierarchy);\n });\n }\n\n private onLoadingComplete(parentId: string | undefined) {\n this.updateTreeModel((model) => {\n TreeModel.setIsLoading(model, parentId, false);\n });\n }\n\n private getLoadAction(parentId: string | undefined) {\n return this._currentModel.idToNode.size === 0 ? \"initial-load\" : parentId === undefined ? \"reload\" : \"hierarchy-level-load\";\n }\n\n private loadSubTree(options: LoadNodesOptions, initialRootNode?: TreeModelRootNode, discardState?: boolean) {\n const loadAction = this.getLoadAction(options.parent.id);\n const timeTracker = new TimeTracker((time) => this._onLoad(loadAction, time));\n\n return {\n complete: new Promise<void>((resolve) => {\n this._nodeLoader.next({ loadOptions: options, onComplete: resolve, timeTracker, parentId: options.parent.id, initialRootNode, discardState });\n }),\n };\n }\n\n private loadNodes(parentId: string, ignoreCache?: boolean) {\n const parentNode = this._currentModel.idToNode.get(parentId);\n /* c8 ignore next 3 */\n if (!parentNode) {\n return { complete: Promise.resolve() };\n }\n return this.loadSubTree({\n parent: parentNode,\n getHierarchyLevelOptions: (node) => createHierarchyLevelOptions(this._currentModel, getNonGroupedParentId(node, this._nodeIdFactory)),\n shouldLoadChildren: (node) => !!node.nodeData.autoExpand,\n ignoreCache,\n });\n }\n\n private reloadSubTree(parentId: string | undefined, oldModel: TreeModel, options?: { discardState?: boolean; ignoreCache?: boolean }) {\n const currModel = this._currentModel;\n const expandedNodes = !!options?.discardState ? [] : collectNodes(parentId, oldModel, (node) => node.isExpanded === true);\n const collapsedNodes = !!options?.discardState ? [] : collectNodes(parentId, oldModel, (node) => node.isExpanded === false);\n const getHierarchyLevelOptions = (node: TreeModelRootNode | TreeModelHierarchyNode) => {\n if (!!options?.discardState) {\n return { instanceFilter: undefined, hierarchyLevelSizeLimit: undefined };\n }\n const filteredNodeId = getNonGroupedParentId(node, this._nodeIdFactory);\n return createHierarchyLevelOptions(filteredNodeId === parentId ? currModel : oldModel, filteredNodeId);\n };\n const shouldLoadChildren = (node: TreeModelHierarchyNode) => {\n if (expandedNodes.findIndex((expandedNode) => sameNodes(expandedNode.nodeData, node.nodeData)) !== -1) {\n return true;\n }\n if (collapsedNodes.findIndex((collapsedNode) => sameNodes(collapsedNode.nodeData, node.nodeData)) !== -1) {\n return false;\n }\n return !!node.nodeData.autoExpand;\n };\n const buildNode = (node: TreeModelHierarchyNode) => (!!options?.discardState || node.id === parentId ? node : addAttributes(node, oldModel));\n\n const rootNode = parentId !== undefined ? this.getNode(parentId) : currModel.rootNode;\n /* c8 ignore next 3 */\n if (!rootNode) {\n return { complete: Promise.resolve() };\n }\n\n if (parentId === undefined) {\n // cancel all ongoing requests\n this._reset.next();\n }\n\n return this.loadSubTree(\n { parent: rootNode, getHierarchyLevelOptions, shouldLoadChildren, buildNode, ignoreCache: options?.ignoreCache },\n !!options?.discardState ? undefined : { ...currModel.rootNode },\n options?.discardState,\n );\n }\n\n public reset() {\n this._reset.next();\n }\n\n public setHierarchyProvider(provider?: HierarchyProvider) {\n this._loader = provider\n ? new TreeLoader(\n provider,\n this._onHierarchyLimitExceeded,\n ({ parentId, type, error }) => {\n if (type === \"timeout\") {\n const loadAction = this.getLoadAction(parentId);\n this._onLoad(loadAction, Number.MAX_SAFE_INTEGER);\n }\n this._onHierarchyLoadError({ parentId, type, error });\n },\n this._nodeIdFactory,\n )\n : /* c8 ignore next */ new NoopTreeLoader();\n }\n\n public getNode(nodeId: string | undefined): TreeModelHierarchyNode | TreeModelRootNode | undefined {\n return TreeModel.getNode(this._currentModel, nodeId);\n }\n\n public selectNodes(nodeIds: Array<string>, changeType: SelectionChangeType) {\n this.updateTreeModel((model) => {\n TreeModel.selectNodes(model, nodeIds, changeType);\n });\n }\n\n public expandNode(nodeId: string, isExpanded: boolean) {\n let childrenAction = \"none\" as ReturnType<typeof TreeModel.expandNode>;\n this.updateTreeModel((model) => {\n childrenAction = TreeModel.expandNode(model, nodeId, isExpanded);\n });\n\n if (childrenAction === \"none\") {\n return { complete: Promise.resolve() };\n }\n\n return this.loadNodes(nodeId, childrenAction === \"reloadChildren\");\n }\n\n public setHierarchyLimit(nodeId: string | undefined, limit?: number | \"unbounded\") {\n const oldModel = this._currentModel;\n let loadChildren = false as boolean;\n this.updateTreeModel((model) => {\n loadChildren = TreeModel.setHierarchyLimit(model, nodeId, limit);\n });\n\n if (!loadChildren) {\n return { complete: Promise.resolve() };\n }\n\n return this.reloadSubTree(nodeId, oldModel);\n }\n\n public setInstanceFilter(nodeId: string | undefined, filter?: GenericInstanceFilter) {\n const oldModel = this._currentModel;\n let loadChildren = false as boolean;\n this.updateTreeModel((model) => {\n loadChildren = TreeModel.setInstanceFilter(model, nodeId, filter);\n });\n\n if (!loadChildren) {\n return { complete: Promise.resolve() };\n }\n\n return this.reloadSubTree(nodeId, oldModel);\n }\n\n public reloadTree(options?: { parentNodeId?: string; state?: \"keep\" | \"discard\" | \"reset\" }) {\n const oldModel = this._currentModel;\n this.updateTreeModel((model) => {\n TreeModel.setIsLoading(model, options?.parentNodeId, true);\n if (options?.state === \"reset\") {\n TreeModel.removeSubTree(model, options.parentNodeId);\n }\n });\n\n const discardState = options?.state === \"discard\" || options?.state === \"reset\";\n const ignoreCache = options?.state === \"reset\";\n return this.reloadSubTree(options?.parentNodeId, oldModel, { discardState, ignoreCache });\n }\n}\n\nfunction collectTreePartsUntil(untilNotifier: Observable<void>, rootNode?: TreeModelRootNode) {\n return (source: Observable<LoadedTreePart>) =>\n source.pipe(\n reduce<LoadedTreePart, TreeModel>(\n (treeModel, loadedPart) => {\n addTreePartToModel(treeModel, loadedPart);\n return treeModel;\n },\n {\n idToNode: new Map(),\n parentChildMap: new Map(),\n rootNode: rootNode ?? { id: undefined, nodeData: undefined },\n },\n ),\n takeUntil(untilNotifier),\n );\n}\n\nfunction addTreePartToModel(treeModel: TreeModel, loadedPart: LoadedTreePart) {\n if (\"loadedNodes\" in loadedPart) {\n addNodesToModel(treeModel, loadedPart);\n } else {\n addErrorToModel(treeModel, loadedPart);\n }\n}\n\nfunction addErrorToModel(model: TreeModel, loadedPart: { parent: TreeModelHierarchyNode | TreeModelRootNode; error: ErrorInfo }) {\n if (loadedPart.parent.id === undefined) {\n model.rootNode.error = loadedPart.error;\n } else {\n model.idToNode.set(loadedPart.parent.id, { ...loadedPart.parent, error: loadedPart.error });\n }\n}\n\nfunction addNodesToModel(model: TreeModel, loadedPart: { parent: TreeModelHierarchyNode | TreeModelRootNode; loadedNodes: TreeModelHierarchyNode[] }) {\n model.parentChildMap.set(\n loadedPart.parent.id,\n loadedPart.loadedNodes.map((node) => node.id),\n );\n for (const node of loadedPart.loadedNodes) {\n model.idToNode.set(node.id, node);\n }\n const parentNode = loadedPart.parent.id ? model.idToNode.get(loadedPart.parent.id) : undefined;\n if (parentNode && loadedPart.loadedNodes.length !== 0) {\n parentNode.isExpanded = true;\n }\n}\n\nfunction addAttributes(node: TreeModelHierarchyNode, oldModel: TreeModel) {\n const oldNode = oldModel.idToNode.get(node.id);\n if (oldNode) {\n node.hierarchyLimit = oldNode.hierarchyLimit;\n node.instanceFilter = oldNode.instanceFilter;\n node.isSelected = oldNode.isSelected;\n }\n return node;\n}\n\nfunction collectNodes(parentId: string | undefined, model: TreeModel, pred: (node: TreeModelHierarchyNode) => boolean): TreeModelHierarchyNode[] {\n const currentChildren = model.parentChildMap.get(parentId);\n if (!currentChildren) {\n return [];\n }\n\n if (parentId === undefined) {\n return currentChildren.flatMap((child) => collectNodes(child, model, pred));\n }\n\n const currNode = model.idToNode.get(parentId);\n if (!currNode || !pred(currNode)) {\n return [];\n }\n\n return [currNode, ...currentChildren.flatMap((child) => collectNodes(child, model, pred))];\n}\n\nfunction getNonGroupedParentId(node: TreeModelHierarchyNode | TreeModelRootNode, nodeIdFactory: (node: Pick<HierarchyNode, \"key\" | \"parentKeys\">) => string) {\n if (!node.nodeData || !HierarchyNode.isGroupingNode(node.nodeData)) {\n return node.id;\n }\n\n if (!node.nodeData.nonGroupingAncestor) {\n return undefined;\n }\n\n return nodeIdFactory(node.nodeData.nonGroupingAncestor);\n}\n\nfunction createHierarchyLevelOptions(model: TreeModel, nodeId: string | undefined): HierarchyLevelOptions {\n if (nodeId === undefined) {\n return { instanceFilter: model.rootNode.instanceFilter, hierarchyLevelSizeLimit: model.rootNode.hierarchyLimit };\n }\n\n const modelNode = model.idToNode.get(nodeId);\n if (!modelNode) {\n return { instanceFilter: undefined, hierarchyLevelSizeLimit: undefined };\n }\n return { instanceFilter: modelNode.instanceFilter, hierarchyLevelSizeLimit: modelNode.hierarchyLimit };\n}\n\n/* c8 ignore start */\nclass NoopTreeLoader implements ITreeLoader {\n public loadNodes(): Observable<LoadedTreePart> {\n return EMPTY;\n }\n}\n/* c8 ignore end */\n\nclass TimeTracker {\n private _start: number;\n private _stopped: boolean = false;\n\n constructor(private _onFinish: (time: number) => void) {\n this._start = Date.now();\n }\n\n public [Symbol.dispose]() {\n this._stopped = true;\n }\n\n public finish() {\n /* c8 ignore next 3 */\n if (this._stopped) {\n return;\n }\n\n this._stopped = true;\n const elapsedTime = Date.now() - this._start;\n this._onFinish(elapsedTime);\n }\n}\n"],"mappings":";;;;;;;;;AAsBAA,cAAc;;AAYd,IAAasC,cAAb,MAAyB;CACvB,AAAQC;CACR,AAAQC;CACR,AAAQG;CACR,AAAQC,SAAS,IAAInC,SAAe;CACpC,AAAQoC;CAERC,YACE,AAAQC,iBACR,AAAQE,SACR,AAAQG,2BACR,AAAQI,uBACRG,eACAC,MACA;EANQb;EACAE;EACAG;EACAI;AAIR,OAAKjB,UAAU,IAAIsB,gBAAgB;AACnC,OAAKrB,iBAAiBmB,iBAAiB3C;AACvC,OAAK2B,gBAAgBiB,gCAA6B;GAChDE,0BAAU,IAAIC,KAAK;GACnBC,gCAAgB,IAAID,KAAK;GACzBE,UAAU;IAAEC,IAAIC;IAAWC,UAAUD;IAAU;GAChD;AAED,OAAKtB,cAAc,KAAKwB,kBAAkB;;CAG5C,AAAQA,mBAAmB;EACzB,MAAMC,UAAU,IAAI7D,SAAoC;AACxD6D,UACGC,KACClE,SAASmE,SAASA,KAAKpC,SAAS,EAChC7B,UAAUkE,UACRA,MAAMF,KACJrE,OAAOuE,MAAMF,KAAKpE,aAAa,EAAE,CAAC,CAAC,EACnCG,KAAKoE,aAAa;GAChB,IAAIC,cAAcD,SAASE,SAAS;AAEpCF,YAASG,SAASC,QAAQC,UAAU;AAClC,QAAID,OAAOzC,aACTsC,eAAcI;KAEhB;AAEFL,YAASG,SAASC,QAAQC,UAAU;AAClC,QAAIA,UAAUJ,YACZ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D;EAAWsD,yBAAyBtD;EAAW;AAE1E,QAAO;EAAEqD,gBAAgBgD,UAAUhD;EAAgBC,yBAAyB+C,UAAUT;EAAgB;;;AAIxG,IAAMlG,iBAAN,MAA4C;CAC1C,AAAOqB,YAAwC;AAC7C,SAAO9E;;;;AAKX,IAAM8B,cAAN,MAAkB;CAChB,AAAQuI;CACR,AAAQC,WAAoB;CAE5B5H,YAAY,AAAQ6H,WAAmC;EAAnCA;AAClB,OAAKF,SAASG,KAAKC,KAAK;;CAG1B,CAAQ7F,OAAOC,WAAW;AACxB,OAAKyF,WAAW;;CAGlB,AAAOjF,SAAS;;AAEd,MAAI,KAAKiF,SACP;AAGF,OAAKA,WAAW;EAChB,MAAMI,cAAcF,KAAKC,KAAK,GAAG,KAAKJ;AACtC,OAAKE,UAAUG,YAAY"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { createNodeId } from "./Utils.js";
|
|
2
|
+
import { EMPTY, catchError, expand, filter, from, map, mergeMap, of, toArray } from "rxjs";
|
|
3
|
+
|
|
4
|
+
//#region src/presentation-hierarchies-react/internal/TreeLoader.ts
|
|
5
|
+
/** @internal */
|
|
6
|
+
var TreeLoader = class {
|
|
7
|
+
_treeNodeIdFactory;
|
|
8
|
+
constructor(_hierarchyProvider, _onHierarchyLimitExceeded, _onHierarchyLoadError, treeNodeIdFactory) {
|
|
9
|
+
this._hierarchyProvider = _hierarchyProvider;
|
|
10
|
+
this._onHierarchyLimitExceeded = _onHierarchyLimitExceeded;
|
|
11
|
+
this._onHierarchyLoadError = _onHierarchyLoadError;
|
|
12
|
+
this._treeNodeIdFactory = treeNodeIdFactory ?? createNodeId;
|
|
13
|
+
}
|
|
14
|
+
loadChildren({ parent, getHierarchyLevelOptions, buildNode, ignoreCache }) {
|
|
15
|
+
const { instanceFilter, hierarchyLevelSizeLimit } = getHierarchyLevelOptions(parent);
|
|
16
|
+
const infoNodeIdBase = `${parent.id ?? "<root>"}`;
|
|
17
|
+
const treeModelNodesFactory = createTreeModelNodesFactory({
|
|
18
|
+
buildNode,
|
|
19
|
+
treeNodeIdFactory: this._treeNodeIdFactory
|
|
20
|
+
});
|
|
21
|
+
return from(this._hierarchyProvider.getNodes({
|
|
22
|
+
parentNode: parent.nodeData,
|
|
23
|
+
hierarchyLevelSizeLimit,
|
|
24
|
+
instanceFilter,
|
|
25
|
+
ignoreCache
|
|
26
|
+
})).pipe(toArray(), map((childNodes) => {
|
|
27
|
+
return instanceFilter && childNodes.length === 0 ? {
|
|
28
|
+
parent,
|
|
29
|
+
error: {
|
|
30
|
+
id: `${infoNodeIdBase}-no-filter-matches`,
|
|
31
|
+
type: "NoFilterMatches"
|
|
32
|
+
}
|
|
33
|
+
} : {
|
|
34
|
+
parent,
|
|
35
|
+
loadedNodes: childNodes.map(treeModelNodesFactory)
|
|
36
|
+
};
|
|
37
|
+
}), catchError((err) => {
|
|
38
|
+
let hierarchyLoadErrorType = "unknown";
|
|
39
|
+
if (err instanceof Error) {
|
|
40
|
+
if (isRowsLimitError(err)) {
|
|
41
|
+
this._onHierarchyLimitExceeded({
|
|
42
|
+
parentId: parent.id,
|
|
43
|
+
filter: instanceFilter,
|
|
44
|
+
limit: err.limit
|
|
45
|
+
});
|
|
46
|
+
return of({
|
|
47
|
+
parent,
|
|
48
|
+
error: {
|
|
49
|
+
id: `${infoNodeIdBase}-${err.message}`,
|
|
50
|
+
type: "ResultSetTooLarge",
|
|
51
|
+
resultSetSizeLimit: err.limit
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (isTimeoutError(err)) hierarchyLoadErrorType = "timeout";
|
|
56
|
+
}
|
|
57
|
+
this._onHierarchyLoadError({
|
|
58
|
+
parentId: parent.id,
|
|
59
|
+
type: hierarchyLoadErrorType,
|
|
60
|
+
error: err
|
|
61
|
+
});
|
|
62
|
+
return of({
|
|
63
|
+
parent,
|
|
64
|
+
error: {
|
|
65
|
+
id: `${infoNodeIdBase}-ChildrenLoad`,
|
|
66
|
+
type: "ChildrenLoad",
|
|
67
|
+
message: "Failed to create hierarchy level"
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
loadNodes({ shouldLoadChildren, ...options }) {
|
|
73
|
+
return this.loadChildren(options).pipe(expand((loadedPart) => "loadedNodes" in loadedPart ? from(loadedPart.loadedNodes).pipe(filter((node) => shouldLoadChildren(node)), mergeMap((node) => this.loadChildren({
|
|
74
|
+
...options,
|
|
75
|
+
parent: node
|
|
76
|
+
}))) : EMPTY));
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
function createTreeModelNodesFactory({ buildNode, treeNodeIdFactory }) {
|
|
80
|
+
return (node) => {
|
|
81
|
+
const modelNode = {
|
|
82
|
+
id: treeNodeIdFactory(node),
|
|
83
|
+
children: node.children,
|
|
84
|
+
label: node.label,
|
|
85
|
+
nodeData: node
|
|
86
|
+
};
|
|
87
|
+
return buildNode ? buildNode(modelNode) : modelNode;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function isRowsLimitError(error) {
|
|
91
|
+
return "limit" in error && error.message.includes("Query rows limit of");
|
|
92
|
+
}
|
|
93
|
+
function isTimeoutError(error) {
|
|
94
|
+
return error.message.includes("query too long to execute or server is too busy");
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
//#endregion
|
|
98
|
+
export { TreeLoader };
|
|
99
|
+
//# sourceMappingURL=TreeLoader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreeLoader.js","names":["catchError","EMPTY","expand","filter","from","map","mergeMap","of","toArray","createNodeId","Observable","GenericInstanceFilter","HierarchyNode","HierarchyProvider","RowsLimitExceededError","ErrorInfo","TreeModelHierarchyNode","TreeModelRootNode","LoadedTreePart","parent","loadedNodes","error","HierarchyLevelOptions","instanceFilter","hierarchyLevelSizeLimit","LoadNodesOptions","getHierarchyLevelOptions","node","shouldLoadChildren","buildNode","ignoreCache","ITreeLoader","loadNodes","options","TreeLoader","_treeNodeIdFactory","Pick","constructor","_hierarchyProvider","_onHierarchyLimitExceeded","props","parentId","limit","_onHierarchyLoadError","type","treeNodeIdFactory","loadChildren","Omit","infoNodeIdBase","id","treeModelNodesFactory","createTreeModelNodesFactory","getNodes","parentNode","nodeData","pipe","childNodes","length","const","err","hierarchyLoadErrorType","Error","isRowsLimitError","message","resultSetSizeLimit","isTimeoutError","loadedPart","modelNode","children","label","includes"],"sources":["../../../src/presentation-hierarchies-react/internal/TreeLoader.ts"],"sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { catchError, EMPTY, expand, filter, from, map, mergeMap, of, toArray } from \"rxjs\";\nimport { createNodeId } from \"./Utils.js\";\n\nimport type { Observable } from \"rxjs\";\nimport type { GenericInstanceFilter, HierarchyNode, HierarchyProvider, RowsLimitExceededError } from \"@itwin/presentation-hierarchies\";\nimport type { ErrorInfo } from \"../TreeNode.js\";\nimport type { TreeModelHierarchyNode, TreeModelRootNode } from \"./TreeModel.js\";\n\n/** @internal */\nexport type LoadedTreePart = {\n parent: TreeModelHierarchyNode | TreeModelRootNode;\n} & (\n | {\n loadedNodes: TreeModelHierarchyNode[];\n }\n | {\n error: ErrorInfo;\n }\n);\n\n/** @internal */\nexport interface HierarchyLevelOptions {\n instanceFilter?: GenericInstanceFilter;\n hierarchyLevelSizeLimit?: number | \"unbounded\";\n}\n\n/** @internal */\nexport interface LoadNodesOptions {\n parent: TreeModelHierarchyNode | TreeModelRootNode;\n getHierarchyLevelOptions: (node: TreeModelRootNode | TreeModelHierarchyNode) => HierarchyLevelOptions;\n shouldLoadChildren: (node: TreeModelHierarchyNode) => boolean;\n buildNode?: (node: TreeModelHierarchyNode) => TreeModelHierarchyNode;\n ignoreCache?: boolean;\n}\n\n/** @internal */\nexport interface ITreeLoader {\n loadNodes(options: LoadNodesOptions): Observable<LoadedTreePart>;\n}\n\n/** @internal */\nexport class TreeLoader implements ITreeLoader {\n private _treeNodeIdFactory: (node: Pick<HierarchyNode, \"key\" | \"parentKeys\">) => string;\n\n constructor(\n private _hierarchyProvider: HierarchyProvider,\n private _onHierarchyLimitExceeded: (props: { parentId?: string; filter?: GenericInstanceFilter; limit?: number | \"unbounded\" }) => void,\n private _onHierarchyLoadError: (props: { parentId?: string; type: \"timeout\" | \"unknown\"; error: unknown }) => void,\n treeNodeIdFactory?: (node: Pick<HierarchyNode, \"key\" | \"parentKeys\">) => string,\n ) {\n this._treeNodeIdFactory = treeNodeIdFactory ?? /* c8 ignore next */ createNodeId;\n }\n\n private loadChildren({ parent, getHierarchyLevelOptions, buildNode, ignoreCache }: Omit<LoadNodesOptions, \"shouldLoadChildren\">) {\n const { instanceFilter, hierarchyLevelSizeLimit } = getHierarchyLevelOptions(parent);\n const infoNodeIdBase = `${parent.id ?? \"<root>\"}`;\n const treeModelNodesFactory = createTreeModelNodesFactory({ buildNode, treeNodeIdFactory: this._treeNodeIdFactory });\n return from(\n this._hierarchyProvider.getNodes({\n parentNode: parent.nodeData,\n hierarchyLevelSizeLimit,\n instanceFilter,\n ignoreCache,\n }),\n ).pipe(\n toArray(),\n map((childNodes): LoadedTreePart => {\n return instanceFilter && childNodes.length === 0\n ? {\n parent,\n error: {\n id: `${infoNodeIdBase}-no-filter-matches`,\n type: \"NoFilterMatches\" as const,\n },\n }\n : {\n parent,\n loadedNodes: childNodes.map(treeModelNodesFactory),\n };\n }),\n catchError((err) => {\n let hierarchyLoadErrorType: \"unknown\" | \"timeout\" = \"unknown\";\n if (err instanceof Error) {\n if (isRowsLimitError(err)) {\n this._onHierarchyLimitExceeded({ parentId: parent.id, filter: instanceFilter, limit: err.limit });\n return of({\n parent,\n error: { id: `${infoNodeIdBase}-${err.message}`, type: \"ResultSetTooLarge\" as const, resultSetSizeLimit: err.limit },\n });\n }\n if (isTimeoutError(err)) {\n hierarchyLoadErrorType = \"timeout\";\n }\n }\n\n this._onHierarchyLoadError({ parentId: parent.id, type: hierarchyLoadErrorType, error: err });\n return of({\n parent,\n error: {\n id: `${infoNodeIdBase}-ChildrenLoad`,\n type: \"ChildrenLoad\" as const,\n message: \"Failed to create hierarchy level\",\n },\n });\n }),\n );\n }\n\n public loadNodes({ shouldLoadChildren, ...options }: LoadNodesOptions) {\n return this.loadChildren(options).pipe(\n expand((loadedPart) =>\n \"loadedNodes\" in loadedPart\n ? from(loadedPart.loadedNodes).pipe(\n filter((node) => shouldLoadChildren(node)),\n mergeMap((node) => this.loadChildren({ ...options, parent: node })),\n )\n : EMPTY,\n ),\n );\n }\n}\n\nfunction createTreeModelNodesFactory({\n buildNode,\n treeNodeIdFactory,\n}: {\n buildNode?: (node: TreeModelHierarchyNode) => TreeModelHierarchyNode;\n treeNodeIdFactory: (node: Pick<HierarchyNode, \"key\" | \"parentKeys\">) => string;\n}): (node: HierarchyNode) => TreeModelHierarchyNode {\n return (node: HierarchyNode) => {\n const modelNode: TreeModelHierarchyNode = {\n id: treeNodeIdFactory(node),\n children: node.children,\n label: node.label,\n nodeData: node,\n };\n return buildNode ? buildNode(modelNode) : modelNode;\n };\n}\n\nfunction isRowsLimitError(error: Error): error is RowsLimitExceededError {\n return \"limit\" in error && error.message.includes(\"Query rows limit of\");\n}\n\nfunction isTimeoutError(error: Error) {\n return error.message.includes(\"query too long to execute or server is too busy\");\n}\n"],"mappings":";;;;;AA8CA,IAAakC,aAAb,MAA+C;CAC7C,AAAQC;CAERE,YACE,AAAQC,oBACR,AAAQC,2BACR,AAAQI,uBACRE,mBACA;EAJQP;EACAC;EACAI;AAGR,OAAKR,qBAAqBU,qBAA0CpC;;CAGtE,AAAQqC,aAAa,EAAE3B,QAAQO,0BAA0BG,WAAWC,eAA6D;EAC/H,MAAM,EAAEP,gBAAgBC,4BAA4BE,yBAAyBP,OAAO;EACpF,MAAM6B,iBAAiB,GAAG7B,OAAO8B,MAAM;EACvC,MAAMC,wBAAwB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Aa;GAAE,GAAGb;GAASd,QAAQQ;GAAM,CAAC,CACpE,CAAC,GACD1B,MAER,CAAC;;;AAIL,SAASkD,4BAA4B,EACnCtB,WACAgB,qBAIkD;AAClD,SAAQlB,SAAwB;EAC9B,MAAMwC,YAAoC;GACxClB,IAAIJ,kBAAkBlB,KAAK;GAC3ByC,UAAUzC,KAAKyC;GACfC,OAAO1C,KAAK0C;GACZf,UAAU3B;GACX;AACD,SAAOE,YAAYA,UAAUsC,UAAU,GAAGA;;;AAI9C,SAASL,iBAAiBzC,OAA+C;AACvE,QAAO,WAAWA,SAASA,MAAM0C,QAAQO,SAAS,sBAAsB;;AAG1E,SAASL,eAAe5C,OAAc;AACpC,QAAOA,MAAM0C,QAAQO,SAAS,kDAAkD"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
//#region src/presentation-hierarchies-react/internal/TreeModel.ts
|
|
2
|
+
let TreeModel;
|
|
3
|
+
(function(_TreeModel) {
|
|
4
|
+
function expandNode(model, nodeId, isExpanded) {
|
|
5
|
+
const node = model.idToNode.get(nodeId);
|
|
6
|
+
if (!node) return "none";
|
|
7
|
+
node.isExpanded = isExpanded;
|
|
8
|
+
if (!isExpanded) return "none";
|
|
9
|
+
if (node.error?.type === "ChildrenLoad") {
|
|
10
|
+
node.isLoading = true;
|
|
11
|
+
TreeModel.removeSubTree(model, nodeId);
|
|
12
|
+
return "reloadChildren";
|
|
13
|
+
}
|
|
14
|
+
if (!node.children) return "none";
|
|
15
|
+
if (!model.parentChildMap.get(node.id)) {
|
|
16
|
+
node.isLoading = true;
|
|
17
|
+
return "loadChildren";
|
|
18
|
+
}
|
|
19
|
+
return "none";
|
|
20
|
+
}
|
|
21
|
+
_TreeModel.expandNode = expandNode;
|
|
22
|
+
function addHierarchyPart(model, rootId, hierarchyPart) {
|
|
23
|
+
removeSubTree(model, rootId);
|
|
24
|
+
model.rootNode.error = hierarchyPart.rootNode.error;
|
|
25
|
+
for (const [parentId, children] of hierarchyPart.parentChildMap) model.parentChildMap.set(parentId, children);
|
|
26
|
+
for (const [nodeId, node] of hierarchyPart.idToNode) model.idToNode.set(nodeId, node);
|
|
27
|
+
const parentNode = rootId !== void 0 ? model.idToNode.get(rootId) : model.rootNode;
|
|
28
|
+
/* c8 ignore next 3*/
|
|
29
|
+
if (!parentNode) return;
|
|
30
|
+
parentNode.isLoading = false;
|
|
31
|
+
}
|
|
32
|
+
_TreeModel.addHierarchyPart = addHierarchyPart;
|
|
33
|
+
function removeSubTree(model, parentId) {
|
|
34
|
+
clearNodeError(model, parentId);
|
|
35
|
+
const currentChildren = model.parentChildMap.get(parentId);
|
|
36
|
+
if (!currentChildren) return;
|
|
37
|
+
model.parentChildMap.delete(parentId);
|
|
38
|
+
for (const childId of currentChildren) {
|
|
39
|
+
const childNode = model.idToNode.get(childId);
|
|
40
|
+
if (childNode) removeSubTree(model, childNode.id);
|
|
41
|
+
model.idToNode.delete(childId);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
_TreeModel.removeSubTree = removeSubTree;
|
|
45
|
+
function setHierarchyLimit(model, nodeId, limit) {
|
|
46
|
+
return updateForReload(model, nodeId, (node) => {
|
|
47
|
+
node.hierarchyLimit = limit;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
_TreeModel.setHierarchyLimit = setHierarchyLimit;
|
|
51
|
+
function setInstanceFilter(model, nodeId, filter) {
|
|
52
|
+
return updateForReload(model, nodeId, (node) => {
|
|
53
|
+
if (filter && node.id !== void 0) node.isExpanded = true;
|
|
54
|
+
node.instanceFilter = filter;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
_TreeModel.setInstanceFilter = setInstanceFilter;
|
|
58
|
+
function selectNodes(model, nodeIds, changeType) {
|
|
59
|
+
if (changeType === "replace") {
|
|
60
|
+
for (const [nodeId, node] of model.idToNode) node.isSelected = !!nodeIds.find((id) => id === nodeId);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
for (const nodeId of nodeIds) {
|
|
64
|
+
const modelNode = model.idToNode.get(nodeId);
|
|
65
|
+
if (!modelNode) return;
|
|
66
|
+
modelNode.isSelected = changeType === "add";
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
_TreeModel.selectNodes = selectNodes;
|
|
70
|
+
function isNodeSelected(model, nodeId) {
|
|
71
|
+
const currentNode = model.idToNode.get(nodeId);
|
|
72
|
+
return !!currentNode && !!currentNode.isSelected;
|
|
73
|
+
}
|
|
74
|
+
_TreeModel.isNodeSelected = isNodeSelected;
|
|
75
|
+
function getNode(model, nodeId) {
|
|
76
|
+
if (!nodeId) return model.rootNode;
|
|
77
|
+
return model.idToNode.get(nodeId);
|
|
78
|
+
}
|
|
79
|
+
_TreeModel.getNode = getNode;
|
|
80
|
+
function setIsLoading(model, nodeId, isLoading) {
|
|
81
|
+
if (nodeId === void 0) {
|
|
82
|
+
model.rootNode.isLoading = isLoading;
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const modelNode = model.idToNode.get(nodeId);
|
|
86
|
+
/* c8 ignore next 3*/
|
|
87
|
+
if (!modelNode) return;
|
|
88
|
+
modelNode.isLoading = isLoading;
|
|
89
|
+
}
|
|
90
|
+
_TreeModel.setIsLoading = setIsLoading;
|
|
91
|
+
})(TreeModel || (TreeModel = {}));
|
|
92
|
+
function updateForReload(model, nodeId, update) {
|
|
93
|
+
TreeModel.removeSubTree(model, nodeId);
|
|
94
|
+
if (nodeId === void 0) {
|
|
95
|
+
update(model.rootNode);
|
|
96
|
+
model.rootNode.isLoading = true;
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
const modelNode = model.idToNode.get(nodeId);
|
|
100
|
+
if (!modelNode) return false;
|
|
101
|
+
update(modelNode);
|
|
102
|
+
if (modelNode.isExpanded) {
|
|
103
|
+
modelNode.isLoading = true;
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
function clearNodeError(model, parentId) {
|
|
109
|
+
if (!parentId) {
|
|
110
|
+
model.rootNode.error = void 0;
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const node = model.idToNode.get(parentId);
|
|
114
|
+
if (!node) return;
|
|
115
|
+
node.error = void 0;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
//#endregion
|
|
119
|
+
export { TreeModel };
|
|
120
|
+
//# sourceMappingURL=TreeModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreeModel.js","names":["GenericInstanceFilter","HierarchyNode","ErrorInfo","SelectionChangeType","TreeModelRootNode","id","nodeData","hierarchyLimit","instanceFilter","isLoading","error","TreeModelHierarchyNode","label","children","isExpanded","isSelected","TreeModel","parentChildMap","Map","idToNode","rootNode","expandNode","model","nodeId","node","get","type","removeSubTree","addHierarchyPart","rootId","hierarchyPart","parentId","set","parentNode","undefined","clearNodeError","currentChildren","delete","childId","childNode","setHierarchyLimit","limit","updateForReload","setInstanceFilter","filter","selectNodes","nodeIds","Array","changeType","find","modelNode","isNodeSelected","currentNode","getNode","setIsLoading","update"],"sources":["../../../src/presentation-hierarchies-react/internal/TreeModel.ts"],"sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport type { GenericInstanceFilter, HierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport type { ErrorInfo } from \"../TreeNode.js\";\nimport type { SelectionChangeType } from \"../UseSelectionHandler.js\";\n\n/** @internal */\nexport interface TreeModelRootNode {\n id: undefined;\n nodeData: undefined;\n hierarchyLimit?: number | \"unbounded\";\n instanceFilter?: GenericInstanceFilter;\n isLoading?: boolean;\n error?: ErrorInfo;\n}\n\n/** @internal */\nexport interface TreeModelHierarchyNode {\n id: string;\n nodeData: HierarchyNode;\n label: string;\n children: boolean;\n isLoading?: boolean;\n isExpanded?: boolean;\n isSelected?: boolean;\n hierarchyLimit?: number | \"unbounded\";\n instanceFilter?: GenericInstanceFilter;\n error?: ErrorInfo;\n}\n\n/** @internal */\nexport interface TreeModel {\n parentChildMap: Map<string | undefined, string[]>;\n idToNode: Map<string, TreeModelHierarchyNode>;\n rootNode: TreeModelRootNode;\n}\n\n/** @internal */\nexport namespace TreeModel {\n export function expandNode(model: TreeModel, nodeId: string, isExpanded: boolean): \"none\" | \"loadChildren\" | \"reloadChildren\" {\n const node = model.idToNode.get(nodeId);\n if (!node) {\n return \"none\";\n }\n\n node.isExpanded = isExpanded;\n if (!isExpanded) {\n return \"none\";\n }\n\n if (node.error?.type === \"ChildrenLoad\") {\n node.isLoading = true;\n // remove subtree if there `ChildrenLoad` error info in order to attempt reloading children\n TreeModel.removeSubTree(model, nodeId);\n return \"reloadChildren\";\n }\n\n if (!node.children) {\n return \"none\";\n }\n\n const children = model.parentChildMap.get(node.id);\n if (!children) {\n node.isLoading = true;\n return \"loadChildren\";\n }\n\n return \"none\";\n }\n\n /** @internal */\n export function addHierarchyPart(model: TreeModel, rootId: string | undefined, hierarchyPart: TreeModel): void {\n removeSubTree(model, rootId);\n model.rootNode.error = hierarchyPart.rootNode.error;\n\n for (const [parentId, children] of hierarchyPart.parentChildMap) {\n model.parentChildMap.set(parentId, children);\n }\n\n for (const [nodeId, node] of hierarchyPart.idToNode) {\n model.idToNode.set(nodeId, node);\n }\n\n const parentNode = rootId !== undefined ? model.idToNode.get(rootId) : model.rootNode;\n /* c8 ignore next 3*/\n if (!parentNode) {\n return;\n }\n parentNode.isLoading = false;\n }\n\n export function removeSubTree(model: TreeModel, parentId: string | undefined): void {\n clearNodeError(model, parentId);\n const currentChildren = model.parentChildMap.get(parentId);\n if (!currentChildren) {\n return;\n }\n model.parentChildMap.delete(parentId);\n\n for (const childId of currentChildren) {\n const childNode = model.idToNode.get(childId);\n if (childNode) {\n removeSubTree(model, childNode.id);\n }\n model.idToNode.delete(childId);\n }\n }\n\n export function setHierarchyLimit(model: TreeModel, nodeId: string | undefined, limit?: number | \"unbounded\"): boolean {\n return updateForReload(model, nodeId, (node) => {\n node.hierarchyLimit = limit;\n });\n }\n\n export function setInstanceFilter(model: TreeModel, nodeId: string | undefined, filter?: GenericInstanceFilter): boolean {\n return updateForReload(model, nodeId, (node) => {\n if (filter && node.id !== undefined) {\n node.isExpanded = true;\n }\n node.instanceFilter = filter;\n });\n }\n\n export function selectNodes(model: TreeModel, nodeIds: Array<string>, changeType: SelectionChangeType) {\n if (changeType === \"replace\") {\n for (const [nodeId, node] of model.idToNode) {\n node.isSelected = !!nodeIds.find((id) => id === nodeId);\n }\n return;\n }\n for (const nodeId of nodeIds) {\n const modelNode = model.idToNode.get(nodeId);\n if (!modelNode) {\n return;\n }\n modelNode.isSelected = changeType === \"add\";\n }\n }\n\n export function isNodeSelected(model: TreeModel, nodeId: string): boolean {\n const currentNode = model.idToNode.get(nodeId);\n return !!currentNode && !!currentNode.isSelected;\n }\n\n export function getNode(model: TreeModel, nodeId: string | undefined): TreeModelHierarchyNode | TreeModelRootNode | undefined {\n if (!nodeId) {\n return model.rootNode;\n }\n return model.idToNode.get(nodeId);\n }\n\n export function setIsLoading(model: TreeModel, nodeId: string | undefined, isLoading: boolean) {\n if (nodeId === undefined) {\n model.rootNode.isLoading = isLoading;\n return;\n }\n const modelNode = model.idToNode.get(nodeId);\n /* c8 ignore next 3*/\n if (!modelNode) {\n return;\n }\n modelNode.isLoading = isLoading;\n }\n}\n\nfunction updateForReload(model: TreeModel, nodeId: string | undefined, update: (node: TreeModelHierarchyNode | TreeModelRootNode) => void) {\n TreeModel.removeSubTree(model, nodeId);\n if (nodeId === undefined) {\n update(model.rootNode);\n model.rootNode.isLoading = true;\n return true;\n }\n\n const modelNode = model.idToNode.get(nodeId);\n if (!modelNode) {\n return false;\n }\n\n update(modelNode);\n if (modelNode.isExpanded) {\n modelNode.isLoading = true;\n return true;\n }\n return false;\n}\n\nfunction clearNodeError(model: TreeModel, parentId: string | undefined) {\n if (!parentId) {\n return (model.rootNode.error = undefined);\n }\n const node = model.idToNode.get(parentId);\n if (!node) {\n return;\n }\n node.error = undefined;\n}\n"],"mappings":";;;CA0CS,SAASqB,WAAWC,OAAkBC,QAAgBT,YAAiE;EAC5H,MAAMU,OAAOF,MAAMH,SAASM,IAAIF,OAAO;AACvC,MAAI,CAACC,KACH,QAAO;AAGTA,OAAKV,aAAaA;AAClB,MAAI,CAACA,WACH,QAAO;AAGT,MAAIU,KAAKd,OAAOgB,SAAS,gBAAgB;AACvCF,QAAKf,YAAY;AAEjBO,aAAUW,cAAcL,OAAOC,OAAO;AACtC,UAAO;;AAGT,MAAI,CAACC,KAAKX,SACR,QAAO;AAIT,MAAI,CADaS,MAAML,eAAeQ,IAAID,KAAKnB,GAAG,EACnC;AACbmB,QAAKf,YAAY;AACjB,UAAO;;AAGT,SAAO;;;CAIF,SAASmB,iBAAiBN,OAAkBO,QAA4BC,eAAgC;AAC7GH,gBAAcL,OAAOO,OAAO;AAC5BP,QAAMF,SAASV,QAAQoB,cAAcV,SAASV;AAE9C,OAAK,MAAM,CAACqB,UAAUlB,aAAaiB,cAAcb,eAC/CK,OAAML,eAAee,IAAID,UAAUlB,SAAS;AAG9C,OAAK,MAAM,CAACU,QAAQC,SAASM,cAAcX,SACzCG,OAAMH,SAASa,IAAIT,QAAQC,KAAK;EAGlC,MAAMS,aAAaJ,WAAWK,SAAYZ,MAAMH,SAASM,IAAII,OAAO,GAAGP,MAAMF;;AAE7E,MAAI,CAACa,WACH;AAEFA,aAAWxB,YAAY;;;CAGlB,SAASkB,cAAcL,OAAkBS,UAAoC;AAClFI,iBAAeb,OAAOS,SAAS;EAC/B,MAAMK,kBAAkBd,MAAML,eAAeQ,IAAIM,SAAS;AAC1D,MAAI,CAACK,gBACH;AAEFd,QAAML,eAAeoB,OAAON,SAAS;AAErC,OAAK,MAAMO,WAAWF,iBAAiB;GACrC,MAAMG,YAAYjB,MAAMH,SAASM,IAAIa,QAAQ;AAC7C,OAAIC,UACFZ,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pB,OAAkBC,QAA4BgC,QAAoE;AACzIvC,WAAUW,cAAcL,OAAOC,OAAO;AACtC,KAAIA,WAAWW,QAAW;AACxBqB,SAAOjC,MAAMF,SAAS;AACtBE,QAAMF,SAASX,YAAY;AAC3B,SAAO;;CAGT,MAAMyC,YAAY5B,MAAMH,SAASM,IAAIF,OAAO;AAC5C,KAAI,CAAC2B,UACH,QAAO;AAGTK,QAAOL,UAAU;AACjB,KAAIA,UAAUpC,YAAY;AACxBoC,YAAUzC,YAAY;AACtB,SAAO;;AAET,QAAO;;AAGT,SAAS0B,eAAeb,OAAkBS,UAA8B;AACtE,KAAI,CAACA,UAAU;AACLT,QAAMF,SAASV,QAAQwB;AAA/B;;CAEF,MAAMV,OAAOF,MAAMH,SAASM,IAAIM,SAAS;AACzC,KAAI,CAACP,KACH;AAEFA,MAAKd,QAAQwB"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import "../UseSelectionHandler.js";
|
|
2
|
+
import "./TreeModel.js";
|
|
3
|
+
import { GenericNodeKey, NonGroupingHierarchyNode } from "@itwin/presentation-hierarchies";
|
|
4
|
+
import { Selectable, SelectionStorage } from "@itwin/unified-selection";
|
|
5
|
+
|
|
6
|
+
//#region src/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts
|
|
7
|
+
/** @public */
|
|
8
|
+
interface UseUnifiedTreeSelectionProps {
|
|
9
|
+
/**
|
|
10
|
+
* Identifier to distinguish this source of changes to the unified selection from another ones in the application.
|
|
11
|
+
*/
|
|
12
|
+
sourceName: string;
|
|
13
|
+
/**
|
|
14
|
+
* An optional function that allows customizing the `Selectable` object that gets created for generic hierarchy nodes. When
|
|
15
|
+
* not supplied, the `Selectable` is created using the following signature:
|
|
16
|
+
* ```ts
|
|
17
|
+
* {
|
|
18
|
+
* identifier: treeModelNodeId,
|
|
19
|
+
* data: node,
|
|
20
|
+
* async *loadInstanceKeys() {},
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @param node Hierarchy node to create a selectable for.
|
|
25
|
+
* @param treeModelNodeId ID of the hierarchy node in the internal tree model. This ID uniquely identifies the node in the whole hierarchy, as opposed to `GenericNodeKey.id` contained within the `node`, which may not be unique.
|
|
26
|
+
*/
|
|
27
|
+
createSelectableForGenericNode?: (node: NonGroupingHierarchyNode & {
|
|
28
|
+
key: GenericNodeKey;
|
|
29
|
+
}, treeModelNodeId: string) => Selectable;
|
|
30
|
+
/**
|
|
31
|
+
* Unified selection storage to use for listening, getting and changing active selection.
|
|
32
|
+
*/
|
|
33
|
+
selectionStorage: SelectionStorage;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { UseUnifiedTreeSelectionProps };
|
|
37
|
+
//# sourceMappingURL=UseUnifiedSelection.d.ts.map
|