@itwin/presentation-hierarchies-react 2.0.0-alpha.4 → 2.0.0-alpha.40
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 +656 -7
- package/README.md +25 -27
- package/lib/esm/presentation-hierarchies-react/Renderers.d.ts +85 -0
- package/lib/esm/presentation-hierarchies-react/Renderers.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/Renderers.js +6 -0
- package/lib/esm/presentation-hierarchies-react/Renderers.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/TreeNode.d.ts +27 -28
- package/lib/esm/presentation-hierarchies-react/TreeNode.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/TreeNode.js +1 -7
- package/lib/esm/presentation-hierarchies-react/TreeNode.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.d.ts +2 -0
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.js +1 -1
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.d.ts +24 -0
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.js +52 -0
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.d.ts +3 -3
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.js +1 -8
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.d.ts +32 -70
- package/lib/esm/presentation-hierarchies-react/UseTree.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.js +48 -49
- package/lib/esm/presentation-hierarchies-react/UseTree.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/Utils.d.ts +5 -0
- package/lib/esm/presentation-hierarchies-react/Utils.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/Utils.js +23 -0
- package/lib/esm/presentation-hierarchies-react/Utils.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.d.ts +2 -2
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.js +31 -16
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.d.ts +24 -6
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.js +29 -33
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.d.ts +6 -29
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.js +31 -27
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts +23 -9
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.js +16 -29
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/Utils.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/Utils.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts +26 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js +75 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FilterAction.d.ts +34 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FilterAction.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FilterAction.js +26 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FilterAction.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts +58 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.js +77 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts +123 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/{itwinui → stratakit}/LocalizationContext.js +15 -5
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RenameAction.d.ts +33 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RenameAction.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RenameAction.js +39 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RenameAction.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts +16 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.js +42 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts +47 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js +28 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts +51 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js +117 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts +45 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js +94 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react.d.ts +14 -9
- package/lib/esm/presentation-hierarchies-react.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react.js +11 -8
- package/lib/esm/presentation-hierarchies-react.js.map +1 -1
- package/package.json +55 -47
- package/lib/esm/presentation-hierarchies-react/UnifiedSelectionContext.d.ts +0 -15
- package/lib/esm/presentation-hierarchies-react/UnifiedSelectionContext.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/UnifiedSelectionContext.js +0 -22
- package/lib/esm/presentation-hierarchies-react/UnifiedSelectionContext.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.d.ts +0 -20
- package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.js +0 -30
- package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.d.ts +0 -73
- package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.d.ts +0 -25
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.js +0 -40
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.d.ts +0 -13
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.js +0 -72
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.d.ts +0 -46
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js +0 -80
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.d.ts +0 -30
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.js +0 -30
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.js.map +0 -1
|
@@ -7,42 +7,38 @@ export function isTreeModelHierarchyNode(node) {
|
|
|
7
7
|
return "nodeData" in node && node.nodeData !== undefined;
|
|
8
8
|
}
|
|
9
9
|
/** @internal */
|
|
10
|
-
export function isTreeModelInfoNode(node) {
|
|
11
|
-
return "type" in node && node.type !== undefined;
|
|
12
|
-
}
|
|
13
|
-
/** @internal */
|
|
14
10
|
export var TreeModel;
|
|
15
11
|
(function (TreeModel) {
|
|
16
12
|
function expandNode(model, nodeId, isExpanded) {
|
|
17
13
|
const node = model.idToNode.get(nodeId);
|
|
18
|
-
if (!node
|
|
14
|
+
if (!node) {
|
|
19
15
|
return "none";
|
|
20
16
|
}
|
|
21
17
|
node.isExpanded = isExpanded;
|
|
22
|
-
if (!isExpanded
|
|
18
|
+
if (!isExpanded) {
|
|
23
19
|
return "none";
|
|
24
20
|
}
|
|
25
|
-
|
|
26
|
-
if (!children) {
|
|
21
|
+
if (node.error?.type === "ChildrenLoad") {
|
|
27
22
|
node.isLoading = true;
|
|
28
|
-
|
|
23
|
+
// remove subtree if there `ChildrenLoad` error info in order to attempt reloading children
|
|
24
|
+
TreeModel.removeSubTree(model, nodeId);
|
|
25
|
+
return "reloadChildren";
|
|
29
26
|
}
|
|
30
|
-
if (children
|
|
27
|
+
if (!node.children) {
|
|
31
28
|
return "none";
|
|
32
29
|
}
|
|
33
|
-
const
|
|
34
|
-
if (!
|
|
35
|
-
|
|
30
|
+
const children = model.parentChildMap.get(node.id);
|
|
31
|
+
if (!children) {
|
|
32
|
+
node.isLoading = true;
|
|
33
|
+
return "loadChildren";
|
|
36
34
|
}
|
|
37
|
-
|
|
38
|
-
TreeModel.removeSubTree(model, nodeId);
|
|
39
|
-
node.isLoading = true;
|
|
40
|
-
return "reloadChildren";
|
|
35
|
+
return "none";
|
|
41
36
|
}
|
|
42
37
|
TreeModel.expandNode = expandNode;
|
|
43
38
|
/** @internal */
|
|
44
39
|
function addHierarchyPart(model, rootId, hierarchyPart) {
|
|
45
40
|
removeSubTree(model, rootId);
|
|
41
|
+
model.rootNode.error = hierarchyPart.rootNode.error;
|
|
46
42
|
for (const [parentId, children] of hierarchyPart.parentChildMap) {
|
|
47
43
|
model.parentChildMap.set(parentId, children);
|
|
48
44
|
}
|
|
@@ -51,13 +47,14 @@ export var TreeModel;
|
|
|
51
47
|
}
|
|
52
48
|
const parentNode = rootId !== undefined ? model.idToNode.get(rootId) : model.rootNode;
|
|
53
49
|
/* c8 ignore next 3*/
|
|
54
|
-
if (!parentNode
|
|
50
|
+
if (!parentNode) {
|
|
55
51
|
return;
|
|
56
52
|
}
|
|
57
53
|
parentNode.isLoading = false;
|
|
58
54
|
}
|
|
59
55
|
TreeModel.addHierarchyPart = addHierarchyPart;
|
|
60
56
|
function removeSubTree(model, parentId) {
|
|
57
|
+
clearNodeError(model, parentId);
|
|
61
58
|
const currentChildren = model.parentChildMap.get(parentId);
|
|
62
59
|
if (!currentChildren) {
|
|
63
60
|
return;
|
|
@@ -65,7 +62,7 @@ export var TreeModel;
|
|
|
65
62
|
model.parentChildMap.delete(parentId);
|
|
66
63
|
for (const childId of currentChildren) {
|
|
67
64
|
const childNode = model.idToNode.get(childId);
|
|
68
|
-
if (childNode
|
|
65
|
+
if (childNode) {
|
|
69
66
|
removeSubTree(model, childNode.id);
|
|
70
67
|
}
|
|
71
68
|
model.idToNode.delete(childId);
|
|
@@ -80,7 +77,7 @@ export var TreeModel;
|
|
|
80
77
|
TreeModel.setHierarchyLimit = setHierarchyLimit;
|
|
81
78
|
function setInstanceFilter(model, nodeId, filter) {
|
|
82
79
|
return updateForReload(model, nodeId, (node) => {
|
|
83
|
-
if (filter &&
|
|
80
|
+
if (filter && node.id !== undefined) {
|
|
84
81
|
node.isExpanded = true;
|
|
85
82
|
}
|
|
86
83
|
node.instanceFilter = filter;
|
|
@@ -90,16 +87,13 @@ export var TreeModel;
|
|
|
90
87
|
function selectNodes(model, nodeIds, changeType) {
|
|
91
88
|
if (changeType === "replace") {
|
|
92
89
|
for (const [nodeId, node] of model.idToNode) {
|
|
93
|
-
if (!isTreeModelHierarchyNode(node)) {
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
90
|
node.isSelected = !!nodeIds.find((id) => id === nodeId);
|
|
97
91
|
}
|
|
98
92
|
return;
|
|
99
93
|
}
|
|
100
94
|
for (const nodeId of nodeIds) {
|
|
101
95
|
const modelNode = model.idToNode.get(nodeId);
|
|
102
|
-
if (!modelNode
|
|
96
|
+
if (!modelNode) {
|
|
103
97
|
return;
|
|
104
98
|
}
|
|
105
99
|
modelNode.isSelected = changeType === "add";
|
|
@@ -108,7 +102,7 @@ export var TreeModel;
|
|
|
108
102
|
TreeModel.selectNodes = selectNodes;
|
|
109
103
|
function isNodeSelected(model, nodeId) {
|
|
110
104
|
const currentNode = model.idToNode.get(nodeId);
|
|
111
|
-
return !!currentNode &&
|
|
105
|
+
return !!currentNode && !!currentNode.isSelected;
|
|
112
106
|
}
|
|
113
107
|
TreeModel.isNodeSelected = isNodeSelected;
|
|
114
108
|
function getNode(model, nodeId) {
|
|
@@ -125,7 +119,7 @@ export var TreeModel;
|
|
|
125
119
|
}
|
|
126
120
|
const modelNode = model.idToNode.get(nodeId);
|
|
127
121
|
/* c8 ignore next 3*/
|
|
128
|
-
if (!modelNode
|
|
122
|
+
if (!modelNode) {
|
|
129
123
|
return;
|
|
130
124
|
}
|
|
131
125
|
modelNode.isLoading = isLoading;
|
|
@@ -140,7 +134,7 @@ function updateForReload(model, nodeId, update) {
|
|
|
140
134
|
return true;
|
|
141
135
|
}
|
|
142
136
|
const modelNode = model.idToNode.get(nodeId);
|
|
143
|
-
if (!modelNode
|
|
137
|
+
if (!modelNode) {
|
|
144
138
|
return false;
|
|
145
139
|
}
|
|
146
140
|
update(modelNode);
|
|
@@ -150,4 +144,14 @@ function updateForReload(model, nodeId, update) {
|
|
|
150
144
|
}
|
|
151
145
|
return false;
|
|
152
146
|
}
|
|
147
|
+
function clearNodeError(model, parentId) {
|
|
148
|
+
if (!parentId) {
|
|
149
|
+
return (model.rootNode.error = undefined);
|
|
150
|
+
}
|
|
151
|
+
const node = model.idToNode.get(parentId);
|
|
152
|
+
if (!node) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
node.error = undefined;
|
|
156
|
+
}
|
|
153
157
|
//# sourceMappingURL=TreeModel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeModel.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/TreeModel.ts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CAAC,SAAS,GAAG,SAAS,CAAC;YACrC,OAAO;QACT,CAAC;QACD,MAAM,SAAS,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC7C,qBAAqB;QACrB,IAAI,CAAC,SAAS,IAAI,CAAC,wBAAwB,CAAC,SAAS,CAAC,EAAE,CAAC;YACvD,OAAO;QACT,CAAC;QACD,SAAS,CAAC,SAAS,GAAG,SAAS,CAAC;IAClC,CAAC;IAXe,sBAAY,eAW3B,CAAA;AACH,CAAC,EA/HgB,SAAS,KAAT,SAAS,QA+HzB;AAED,SAAS,eAAe,CAAC,KAAgB,EAAE,MAA0B,EAAE,MAAkE;IACvI,SAAS,CAAC,aAAa,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACvC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACzB,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACvB,KAAK,CAAC,QAAQ,CAAC,SAAS,GAAG,IAAI,CAAC;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,SAAS,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC7C,IAAI,CAAC,SAAS,IAAI,CAAC,wBAAwB,CAAC,SAAS,CAAC,EAAE,CAAC;QACvD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,CAAC;IAClB,IAAI,SAAS,CAAC,UAAU,EAAE,CAAC;QACzB,SAAS,CAAC,SAAS,GAAG,IAAI,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC","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 { GenericInstanceFilter, HierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport { 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}\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}\n\n/** @internal */\nexport interface TreeModelGenericInfoNode {\n id: string;\n parentId: string | undefined;\n type: \"Unknown\";\n message: string;\n}\n\n/** @internal */\nexport interface TreeModelNoFilterMatchesInfoNode {\n id: string;\n parentId: string | undefined;\n type: \"NoFilterMatches\";\n}\n\n/** @internal */\nexport interface TreeModelResultSetTooLargeInfoNode {\n id: string;\n parentId: string | undefined;\n type: \"ResultSetTooLarge\";\n resultSetSizeLimit: number;\n}\n\n/** @internal */\nexport type TreeModelInfoNode = TreeModelGenericInfoNode | TreeModelResultSetTooLargeInfoNode | TreeModelNoFilterMatchesInfoNode;\n\n/** @internal */\nexport type TreeModelNode = TreeModelHierarchyNode | TreeModelInfoNode;\n\n/** @internal */\nexport function isTreeModelHierarchyNode(node: TreeModelHierarchyNode | TreeModelInfoNode | TreeModelRootNode): node is TreeModelHierarchyNode {\n return \"nodeData\" in node && node.nodeData !== undefined;\n}\n\n/** @internal */\nexport function isTreeModelInfoNode(node: TreeModelHierarchyNode | TreeModelInfoNode | TreeModelRootNode): node is TreeModelInfoNode {\n return \"type\" in node && node.type !== undefined;\n}\n\n/** @internal */\nexport interface TreeModel {\n parentChildMap: Map<string | undefined, string[]>;\n idToNode: Map<string, TreeModelNode>;\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 || !isTreeModelHierarchyNode(node)) {\n return \"none\";\n }\n\n node.isExpanded = isExpanded;\n if (!isExpanded || !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 if (children.length !== 1) {\n return \"none\";\n }\n\n const firstChild = TreeModel.getNode(model, children[0]);\n if (!firstChild || !isTreeModelInfoNode(firstChild) || firstChild.type !== \"Unknown\") {\n return \"none\";\n }\n\n // remove subtree if there is only one `Unknown` info node in order to attempt reloading children\n TreeModel.removeSubTree(model, nodeId);\n node.isLoading = true;\n return \"reloadChildren\";\n }\n\n /** @internal */\n export function addHierarchyPart(model: TreeModel, rootId: string | undefined, hierarchyPart: TreeModel): void {\n removeSubTree(model, rootId);\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 || isTreeModelInfoNode(parentNode)) {\n return;\n }\n parentNode.isLoading = false;\n }\n\n export function removeSubTree(model: TreeModel, parentId: string | undefined): void {\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 && isTreeModelHierarchyNode(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 && isTreeModelHierarchyNode(node)) {\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 if (!isTreeModelHierarchyNode(node)) {\n continue;\n }\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 || !isTreeModelHierarchyNode(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 && isTreeModelHierarchyNode(currentNode) && !!currentNode.isSelected;\n }\n\n export function getNode(model: TreeModel, nodeId: string | undefined): TreeModelNode | 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 || !isTreeModelHierarchyNode(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 || !isTreeModelHierarchyNode(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"]}
|
|
1
|
+
{"version":3,"file":"TreeModel.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/TreeModel.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;A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CAAC;QACzB,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACvB,KAAK,CAAC,QAAQ,CAAC,SAAS,GAAG,IAAI,CAAC;QAChC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,SAAS,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC7C,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,CAAC;IAClB,IAAI,SAAS,CAAC,UAAU,EAAE,CAAC;QACzB,SAAS,CAAC,SAAS,GAAG,IAAI,CAAC;QAC3B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,cAAc,CAAC,KAAgB,EAAE,QAA4B;IACpE,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC;IAC5C,CAAC;IACD,MAAM,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC1C,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO;IACT,CAAC;IACD,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;AACzB,CAAC","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 { GenericInstanceFilter, HierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport { ErrorInfo } from \"../TreeNode.js\";\nimport { 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 function isTreeModelHierarchyNode(node: TreeModelHierarchyNode | ErrorInfo | TreeModelRootNode): node is TreeModelHierarchyNode {\n return \"nodeData\" in node && node.nodeData !== undefined;\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"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GenericNodeKey, NonGroupingHierarchyNode } from "@itwin/presentation-hierarchies";
|
|
2
|
+
import { Selectable, SelectionStorage } from "@itwin/unified-selection";
|
|
2
3
|
import { SelectionChangeType } from "../UseSelectionHandler.js";
|
|
3
|
-
import {
|
|
4
|
+
import { TreeModelHierarchyNode, TreeModelRootNode } from "./TreeModel.js";
|
|
4
5
|
/** @internal */
|
|
5
6
|
export interface TreeSelectionOptions {
|
|
6
7
|
isNodeSelected: (nodeId: string) => boolean;
|
|
@@ -13,16 +14,29 @@ export interface UseUnifiedTreeSelectionProps {
|
|
|
13
14
|
*/
|
|
14
15
|
sourceName: string;
|
|
15
16
|
/**
|
|
16
|
-
*
|
|
17
|
+
* An optional function that allows customizing the `Selectable` object that gets created for generic hierarchy nodes. When
|
|
18
|
+
* not supplied, the `Selectable` is created using the following signature:
|
|
19
|
+
* ```ts
|
|
20
|
+
* {
|
|
21
|
+
* identifier: treeModelNodeId,
|
|
22
|
+
* data: node,
|
|
23
|
+
* async *loadInstanceKeys() {},
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
17
26
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
|
|
27
|
+
* @param node Hierarchy node to create a selectable for.
|
|
28
|
+
* @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.
|
|
29
|
+
*/
|
|
30
|
+
createSelectableForGenericNode?: (node: NonGroupingHierarchyNode & {
|
|
31
|
+
key: GenericNodeKey;
|
|
32
|
+
}, treeModelNodeId: string) => Selectable;
|
|
33
|
+
/**
|
|
34
|
+
* Unified selection storage to use for listening, getting and changing active selection.
|
|
21
35
|
*/
|
|
22
|
-
selectionStorage
|
|
36
|
+
selectionStorage: SelectionStorage;
|
|
23
37
|
}
|
|
24
38
|
/** @internal */
|
|
25
|
-
export declare function useUnifiedTreeSelection({ sourceName, selectionStorage, getTreeModelNode, }: UseUnifiedTreeSelectionProps & {
|
|
26
|
-
getTreeModelNode: (nodeId: string) =>
|
|
39
|
+
export declare function useUnifiedTreeSelection({ sourceName, selectionStorage, getTreeModelNode, createSelectableForGenericNode, }: UseUnifiedTreeSelectionProps & {
|
|
40
|
+
getTreeModelNode: (nodeId: string) => TreeModelHierarchyNode | TreeModelRootNode | undefined;
|
|
27
41
|
}): TreeSelectionOptions;
|
|
28
42
|
//# sourceMappingURL=UseUnifiedSelection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseUnifiedSelection.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/UseUnifiedSelection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"UseUnifiedSelection.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/UseUnifiedSelection.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAmC,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAE5H,OAAO,EAAE,UAAU,EAAe,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACrF,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAE3E,gBAAgB;AAChB,MAAM,WAAW,oBAAoB;IACnC,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;IAC5C,WAAW,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,mBAAmB,KAAK,IAAI,CAAC;CAChF;AAED,cAAc;AACd,MAAM,WAAW,4BAA4B;IAC3C;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;;;;;;;;;OAaG;IACH,8BAA8B,CAAC,EAAE,CAAC,IAAI,EAAE,wBAAwB,GAAG;QAAE,GAAG,EAAE,cAAc,CAAA;KAAE,EAAE,eAAe,EAAE,MAAM,KAAK,UAAU,CAAC;IAEnI;;OAEG;IACH,gBAAgB,EAAE,gBAAgB,CAAC;CACpC;AAED,gBAAgB;AAChB,wBAAgB,uBAAuB,CAAC,EACtC,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,8BAAsE,GACvE,EAAE,4BAA4B,GAAG;IAAE,gBAAgB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,sBAAsB,GAAG,iBAAiB,GAAG,SAAS,CAAA;CAAE,GAAG,oBAAoB,CAiBxJ"}
|
|
@@ -6,43 +6,36 @@ import { useEffect, useState } from "react";
|
|
|
6
6
|
import { assert } from "@itwin/core-bentley";
|
|
7
7
|
import { HierarchyNode } from "@itwin/presentation-hierarchies";
|
|
8
8
|
import { Selectables } from "@itwin/unified-selection";
|
|
9
|
-
import { useUnifiedSelectionStorage } from "../UnifiedSelectionContext.js";
|
|
10
|
-
import { isTreeModelHierarchyNode } from "./TreeModel.js";
|
|
11
9
|
/** @internal */
|
|
12
|
-
export function useUnifiedTreeSelection({ sourceName, selectionStorage, getTreeModelNode, }) {
|
|
10
|
+
export function useUnifiedTreeSelection({ sourceName, selectionStorage, getTreeModelNode, createSelectableForGenericNode = defaultCreateSelectableForGenericNode, }) {
|
|
13
11
|
const [options, setOptions] = useState(() => ({
|
|
14
12
|
isNodeSelected: /* c8 ignore next */ () => false,
|
|
15
13
|
selectNodes: /* c8 ignore next */ () => { },
|
|
16
14
|
}));
|
|
17
|
-
const deprecatedSelectionStorage = useUnifiedSelectionStorage();
|
|
18
|
-
selectionStorage ??= deprecatedSelectionStorage;
|
|
19
15
|
useEffect(() => {
|
|
20
|
-
|
|
21
|
-
// TODO: make selectionStorage prop required
|
|
22
|
-
setOptions({
|
|
23
|
-
isNodeSelected: () => false,
|
|
24
|
-
selectNodes: () => { },
|
|
25
|
-
});
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
setOptions(createOptions(sourceName, selectionStorage, getTreeModelNode));
|
|
16
|
+
setOptions(createOptions(sourceName, selectionStorage, createSelectableForGenericNode, getTreeModelNode));
|
|
29
17
|
return selectionStorage.selectionChangeEvent.addListener((args) => {
|
|
30
18
|
if (args.level > 0) {
|
|
31
19
|
return;
|
|
32
20
|
}
|
|
33
|
-
setOptions(createOptions(sourceName, selectionStorage, getTreeModelNode));
|
|
21
|
+
setOptions(createOptions(sourceName, selectionStorage, createSelectableForGenericNode, getTreeModelNode));
|
|
34
22
|
});
|
|
35
|
-
}, [selectionStorage, getTreeModelNode, sourceName]);
|
|
23
|
+
}, [selectionStorage, createSelectableForGenericNode, getTreeModelNode, sourceName]);
|
|
36
24
|
return options;
|
|
37
25
|
}
|
|
38
|
-
|
|
26
|
+
const defaultCreateSelectableForGenericNode = (node, treeModelNodeId) => ({
|
|
27
|
+
identifier: treeModelNodeId,
|
|
28
|
+
data: node,
|
|
29
|
+
async *loadInstanceKeys() { },
|
|
30
|
+
});
|
|
31
|
+
function createOptions(source, storage, createSelectableForGenericNode, getNode) {
|
|
39
32
|
return {
|
|
40
33
|
isNodeSelected: (nodeId) => {
|
|
41
34
|
const node = getNode(nodeId);
|
|
42
|
-
if (!node ||
|
|
35
|
+
if (!node || node?.id === undefined) {
|
|
43
36
|
return false;
|
|
44
37
|
}
|
|
45
|
-
return Object.entries(groupNodeSelectablesByIModelKey(node)).some(([imodelKey, nodeSelectables]) => {
|
|
38
|
+
return Object.entries(groupNodeSelectablesByIModelKey(node, createSelectableForGenericNode)).some(([imodelKey, nodeSelectables]) => {
|
|
46
39
|
const storageSelectables = storage.getSelection({ imodelKey, level: 0 });
|
|
47
40
|
return Selectables.hasAny(storageSelectables, nodeSelectables);
|
|
48
41
|
});
|
|
@@ -51,10 +44,10 @@ function createOptions(source, storage, getNode) {
|
|
|
51
44
|
const imodelSelectables = {};
|
|
52
45
|
for (const nodeId of nodeIds) {
|
|
53
46
|
const node = getNode(nodeId);
|
|
54
|
-
if (!node ||
|
|
47
|
+
if (!node || node?.id === undefined) {
|
|
55
48
|
return;
|
|
56
49
|
}
|
|
57
|
-
Object.entries(groupNodeSelectablesByIModelKey(node)).forEach(([imodelKey, nodeSelectables]) => {
|
|
50
|
+
Object.entries(groupNodeSelectablesByIModelKey(node, createSelectableForGenericNode)).forEach(([imodelKey, nodeSelectables]) => {
|
|
58
51
|
let selectablesList = imodelSelectables[imodelKey];
|
|
59
52
|
if (!selectablesList) {
|
|
60
53
|
selectablesList = [];
|
|
@@ -80,7 +73,7 @@ function createOptions(source, storage, getNode) {
|
|
|
80
73
|
},
|
|
81
74
|
};
|
|
82
75
|
}
|
|
83
|
-
function groupNodeSelectablesByIModelKey(modelNode) {
|
|
76
|
+
function groupNodeSelectablesByIModelKey(modelNode, createSelectableForGenericNode) {
|
|
84
77
|
const hierarchyNode = modelNode.nodeData;
|
|
85
78
|
if (HierarchyNode.isInstancesNode(hierarchyNode)) {
|
|
86
79
|
return groupIModelInstanceKeys(hierarchyNode.key.instanceKeys);
|
|
@@ -104,13 +97,7 @@ function groupNodeSelectablesByIModelKey(modelNode) {
|
|
|
104
97
|
assert(HierarchyNode.isGeneric(hierarchyNode));
|
|
105
98
|
return {
|
|
106
99
|
// note: generic nodes aren't associated with an imodel
|
|
107
|
-
[""]: [
|
|
108
|
-
{
|
|
109
|
-
identifier: modelNode.id,
|
|
110
|
-
data: hierarchyNode,
|
|
111
|
-
async *loadInstanceKeys() { },
|
|
112
|
-
},
|
|
113
|
-
],
|
|
100
|
+
[""]: [createSelectableForGenericNode(hierarchyNode, modelNode.id)],
|
|
114
101
|
};
|
|
115
102
|
}
|
|
116
103
|
function groupIModelInstanceKeys(instanceKeys) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseUnifiedSelection.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/UseUnifiedSelection.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAoB,MAAM,iCAAiC,CAAC;AAElF,OAAO,EAAc,WAAW,EAAoB,MAAM,0BAA0B,CAAC;AACrF,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAE3E,OAAO,EAAE,wBAAwB,EAA4D,MAAM,gBAAgB,CAAC;AAyBpH,gBAAgB;AAChB,MAAM,UAAU,uBAAuB,CAAC,EACtC,UAAU,EACV,gBAAgB,EAChB,gBAAgB,GACuG;IACvH,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAuB,GAAG,EAAE,CAAC,CAAC;QAClE,cAAc,EAAE,oBAAoB,CAAC,GAAG,EAAE,CAAC,KAAK;QAChD,WAAW,EAAE,oBAAoB,CAAC,GAAG,EAAE,GAAE,CAAC;KAC3C,CAAC,CAAC,CAAC;IAEJ,MAAM,0BAA0B,GAAG,0BAA0B,EAAE,CAAC;IAChE,gBAAgB,KAAK,0BAA0B,CAAC;IAEhD,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,4CAA4C;YAC5C,UAAU,CAAC;gBACT,cAAc,EAAE,GAAG,EAAE,CAAC,KAAK;gBAC3B,WAAW,EAAE,GAAG,EAAE,GAAE,CAAC;aACtB,CAAC,CAAC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AI,CAAC,eAAe,EAAE,CAAC;YACrB,eAAe,GAAG,EAAE,CAAC;YACrB,iBAAiB,CAAC,SAAS,CAAC,GAAG,eAAe,CAAC;QACjD,CAAC;QACD,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC1B,OAAO,iBAAiB,CAAC;IAC3B,CAAC,EACD,EAA4C,CAC7C,CAAC;AACJ,CAAC","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 { useEffect, useState } from \"react\";\nimport { assert } from \"@itwin/core-bentley\";\nimport { HierarchyNode, InstancesNodeKey } from \"@itwin/presentation-hierarchies\";\nimport { InstanceKey } from \"@itwin/presentation-shared\";\nimport { Selectable, Selectables, SelectionStorage } from \"@itwin/unified-selection\";\nimport { useUnifiedSelectionStorage } from \"../UnifiedSelectionContext.js\";\nimport { SelectionChangeType } from \"../UseSelectionHandler.js\";\nimport { isTreeModelHierarchyNode, TreeModelHierarchyNode, TreeModelNode, TreeModelRootNode } from \"./TreeModel.js\";\n\n/** @internal */\nexport interface TreeSelectionOptions {\n isNodeSelected: (nodeId: string) => boolean;\n selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => void;\n}\n\n/** @public */\nexport interface UseUnifiedTreeSelectionProps {\n /**\n * Identifier to distinguish this source of changes to the unified selection from another ones in the application.\n */\n sourceName: string;\n\n /**\n * Unified selection storage to use for listening, getting and changing active selection.\n *\n * When not specified, the deprecated unified selection React context is used to access the\n * selection storage (see `UnifiedSelectionProvider`). This prop will be made required in the\n * next major release, where the deprecated context will also be removed.\n */\n selectionStorage?: SelectionStorage;\n}\n\n/** @internal */\nexport function useUnifiedTreeSelection({\n sourceName,\n selectionStorage,\n getTreeModelNode,\n}: UseUnifiedTreeSelectionProps & { getTreeModelNode: (nodeId: string) => TreeModelNode | TreeModelRootNode | undefined }): TreeSelectionOptions {\n const [options, setOptions] = useState<TreeSelectionOptions>(() => ({\n isNodeSelected: /* c8 ignore next */ () => false,\n selectNodes: /* c8 ignore next */ () => {},\n }));\n\n const deprecatedSelectionStorage = useUnifiedSelectionStorage();\n selectionStorage ??= deprecatedSelectionStorage;\n\n useEffect(() => {\n if (!selectionStorage) {\n // TODO: make selectionStorage prop required\n setOptions({\n isNodeSelected: () => false,\n selectNodes: () => {},\n });\n return;\n }\n\n setOptions(createOptions(sourceName, selectionStorage, getTreeModelNode));\n return selectionStorage.selectionChangeEvent.addListener((args) => {\n if (args.level > 0) {\n return;\n }\n setOptions(createOptions(sourceName, selectionStorage, getTreeModelNode));\n });\n }, [selectionStorage, getTreeModelNode, sourceName]);\n\n return options;\n}\n\nfunction createOptions(\n source: string,\n storage: SelectionStorage,\n getNode: (nodeId: string) => TreeModelNode | TreeModelRootNode | undefined,\n): TreeSelectionOptions {\n return {\n isNodeSelected: (nodeId: string) => {\n const node = getNode(nodeId);\n if (!node || !isTreeModelHierarchyNode(node)) {\n return false;\n }\n return Object.entries(groupNodeSelectablesByIModelKey(node)).some(([imodelKey, nodeSelectables]) => {\n const storageSelectables = storage.getSelection({ imodelKey, level: 0 });\n return Selectables.hasAny(storageSelectables, nodeSelectables);\n });\n },\n\n selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => {\n const imodelSelectables: { [imodelKey: string]: Selectable[] } = {};\n for (const nodeId of nodeIds) {\n const node = getNode(nodeId);\n if (!node || !isTreeModelHierarchyNode(node)) {\n return;\n }\n Object.entries(groupNodeSelectablesByIModelKey(node)).forEach(([imodelKey, nodeSelectables]) => {\n let selectablesList = imodelSelectables[imodelKey];\n if (!selectablesList) {\n selectablesList = [];\n imodelSelectables[imodelKey] = selectablesList;\n }\n nodeSelectables.forEach((selectable) => selectablesList.push(selectable));\n });\n }\n Object.entries(imodelSelectables).forEach(([imodelKey, selectables]) => {\n const actionProps = { imodelKey, source, selectables, level: 0 };\n switch (changeType) {\n case \"add\":\n storage.addToSelection(actionProps);\n return;\n case \"remove\":\n storage.removeFromSelection(actionProps);\n return;\n case \"replace\":\n storage.replaceSelection(actionProps);\n return;\n }\n });\n },\n };\n}\n\nfunction groupNodeSelectablesByIModelKey(modelNode: TreeModelHierarchyNode): { [imodelKey: string]: Selectable[] } {\n const hierarchyNode = modelNode.nodeData;\n if (HierarchyNode.isInstancesNode(hierarchyNode)) {\n return groupIModelInstanceKeys(hierarchyNode.key.instanceKeys);\n }\n if (HierarchyNode.isGroupingNode(hierarchyNode)) {\n return Object.entries(groupIModelInstanceKeys(hierarchyNode.groupedInstanceKeys)).reduce(\n (imodelSelectables, [imodelKey, instanceKeys]) => ({\n ...imodelSelectables,\n [imodelKey]: [\n {\n identifier: modelNode.id,\n data: hierarchyNode,\n async *loadInstanceKeys() {\n for (const key of instanceKeys) {\n yield key;\n }\n },\n },\n ],\n }),\n {} as { [imodelKey: string]: Selectable[] },\n );\n }\n assert(HierarchyNode.isGeneric(hierarchyNode));\n return {\n // note: generic nodes aren't associated with an imodel\n [\"\"]: [\n {\n identifier: modelNode.id,\n data: hierarchyNode,\n async *loadInstanceKeys() {},\n },\n ],\n };\n}\n\nfunction groupIModelInstanceKeys(instanceKeys: InstancesNodeKey[\"instanceKeys\"]) {\n return instanceKeys.reduce(\n (imodelSelectables, key) => {\n const imodelKey = key.imodelKey ?? \"\";\n let selectablesList = imodelSelectables[imodelKey];\n if (!selectablesList) {\n selectablesList = [];\n imodelSelectables[imodelKey] = selectablesList;\n }\n selectablesList.push(key);\n return imodelSelectables;\n },\n {} as { [imodelKey: string]: InstanceKey[] },\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"UseUnifiedSelection.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/UseUnifiedSelection.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,qB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X;oBACE,UAAU,EAAE,SAAS,CAAC,EAAE;oBACxB,IAAI,EAAE,aAAa;oBACnB,KAAK,CAAC,CAAC,gBAAgB;wBACrB,KAAK,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;4BAC/B,MAAM,GAAG,CAAC;wBACZ,CAAC;oBACH,CAAC;iBACF;aACF;SACF,CAAC,EACF,EAA2C,CAC5C,CAAC;IACJ,CAAC;IACD,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC;IAC/C,OAAO;QACL,uDAAuD;QACvD,CAAC,EAAE,CAAC,EAAE,CAAC,8BAA8B,CAAC,aAAa,EAAE,SAAS,CAAC,EAAE,CAAC,CAAC;KACpE,CAAC;AACJ,CAAC;AAED,SAAS,uBAAuB,CAAC,YAA8C;IAC7E,OAAO,YAAY,CAAC,MAAM,CACxB,CAAC,iBAAiB,EAAE,GAAG,EAAE,EAAE;QACzB,MAAM,SAAS,GAAG,GAAG,CAAC,SAAS,IAAI,EAAE,CAAC;QACtC,IAAI,eAAe,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;QACnD,IAAI,CAAC,eAAe,EAAE,CAAC;YACrB,eAAe,GAAG,EAAE,CAAC;YACrB,iBAAiB,CAAC,SAAS,CAAC,GAAG,eAAe,CAAC;QACjD,CAAC;QACD,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC1B,OAAO,iBAAiB,CAAC;IAC3B,CAAC,EACD,EAA4C,CAC7C,CAAC;AACJ,CAAC","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 { useEffect, useState } from \"react\";\nimport { assert } from \"@itwin/core-bentley\";\nimport { GenericNodeKey, HierarchyNode, InstancesNodeKey, NonGroupingHierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport { InstanceKey } from \"@itwin/presentation-shared\";\nimport { Selectable, Selectables, SelectionStorage } from \"@itwin/unified-selection\";\nimport { SelectionChangeType } from \"../UseSelectionHandler.js\";\nimport { TreeModelHierarchyNode, TreeModelRootNode } from \"./TreeModel.js\";\n\n/** @internal */\nexport interface TreeSelectionOptions {\n isNodeSelected: (nodeId: string) => boolean;\n selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => void;\n}\n\n/** @public */\nexport interface UseUnifiedTreeSelectionProps {\n /**\n * Identifier to distinguish this source of changes to the unified selection from another ones in the application.\n */\n sourceName: string;\n\n /**\n * An optional function that allows customizing the `Selectable` object that gets created for generic hierarchy nodes. When\n * not supplied, the `Selectable` is created using the following signature:\n * ```ts\n * {\n * identifier: treeModelNodeId,\n * data: node,\n * async *loadInstanceKeys() {},\n * }\n * ```\n *\n * @param node Hierarchy node to create a selectable for.\n * @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.\n */\n createSelectableForGenericNode?: (node: NonGroupingHierarchyNode & { key: GenericNodeKey }, treeModelNodeId: string) => Selectable;\n\n /**\n * Unified selection storage to use for listening, getting and changing active selection.\n */\n selectionStorage: SelectionStorage;\n}\n\n/** @internal */\nexport function useUnifiedTreeSelection({\n sourceName,\n selectionStorage,\n getTreeModelNode,\n createSelectableForGenericNode = defaultCreateSelectableForGenericNode,\n}: UseUnifiedTreeSelectionProps & { getTreeModelNode: (nodeId: string) => TreeModelHierarchyNode | TreeModelRootNode | undefined }): TreeSelectionOptions {\n const [options, setOptions] = useState<TreeSelectionOptions>(() => ({\n isNodeSelected: /* c8 ignore next */ () => false,\n selectNodes: /* c8 ignore next */ () => {},\n }));\n\n useEffect(() => {\n setOptions(createOptions(sourceName, selectionStorage, createSelectableForGenericNode, getTreeModelNode));\n return selectionStorage.selectionChangeEvent.addListener((args) => {\n if (args.level > 0) {\n return;\n }\n setOptions(createOptions(sourceName, selectionStorage, createSelectableForGenericNode, getTreeModelNode));\n });\n }, [selectionStorage, createSelectableForGenericNode, getTreeModelNode, sourceName]);\n\n return options;\n}\n\nconst defaultCreateSelectableForGenericNode: NonNullable<UseUnifiedTreeSelectionProps[\"createSelectableForGenericNode\"]> = (\n node,\n treeModelNodeId,\n): Selectable => ({\n identifier: treeModelNodeId,\n data: node,\n async *loadInstanceKeys() {},\n});\n\nfunction createOptions(\n source: string,\n storage: SelectionStorage,\n createSelectableForGenericNode: NonNullable<UseUnifiedTreeSelectionProps[\"createSelectableForGenericNode\"]>,\n getNode: (nodeId: string) => TreeModelHierarchyNode | TreeModelRootNode | undefined,\n): TreeSelectionOptions {\n return {\n isNodeSelected: (nodeId: string) => {\n const node = getNode(nodeId);\n if (!node || node?.id === undefined) {\n return false;\n }\n return Object.entries(groupNodeSelectablesByIModelKey(node, createSelectableForGenericNode)).some(([imodelKey, nodeSelectables]) => {\n const storageSelectables = storage.getSelection({ imodelKey, level: 0 });\n return Selectables.hasAny(storageSelectables, nodeSelectables);\n });\n },\n\n selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => {\n const imodelSelectables: { [imodelKey: string]: Selectable[] } = {};\n for (const nodeId of nodeIds) {\n const node = getNode(nodeId);\n if (!node || node?.id === undefined) {\n return;\n }\n Object.entries(groupNodeSelectablesByIModelKey(node, createSelectableForGenericNode)).forEach(([imodelKey, nodeSelectables]) => {\n let selectablesList = imodelSelectables[imodelKey];\n if (!selectablesList) {\n selectablesList = [];\n imodelSelectables[imodelKey] = selectablesList;\n }\n nodeSelectables.forEach((selectable) => selectablesList.push(selectable));\n });\n }\n Object.entries(imodelSelectables).forEach(([imodelKey, selectables]) => {\n const actionProps = { imodelKey, source, selectables, level: 0 };\n switch (changeType) {\n case \"add\":\n storage.addToSelection(actionProps);\n return;\n case \"remove\":\n storage.removeFromSelection(actionProps);\n return;\n case \"replace\":\n storage.replaceSelection(actionProps);\n return;\n }\n });\n },\n };\n}\n\nfunction groupNodeSelectablesByIModelKey(\n modelNode: TreeModelHierarchyNode,\n createSelectableForGenericNode: NonNullable<UseUnifiedTreeSelectionProps[\"createSelectableForGenericNode\"]>,\n): { [imodelKey: string]: Selectable[] } {\n const hierarchyNode = modelNode.nodeData;\n if (HierarchyNode.isInstancesNode(hierarchyNode)) {\n return groupIModelInstanceKeys(hierarchyNode.key.instanceKeys);\n }\n if (HierarchyNode.isGroupingNode(hierarchyNode)) {\n return Object.entries(groupIModelInstanceKeys(hierarchyNode.groupedInstanceKeys)).reduce(\n (imodelSelectables, [imodelKey, instanceKeys]) => ({\n ...imodelSelectables,\n [imodelKey]: [\n {\n identifier: modelNode.id,\n data: hierarchyNode,\n async *loadInstanceKeys() {\n for (const key of instanceKeys) {\n yield key;\n }\n },\n },\n ],\n }),\n {} as { [imodelKey: string]: Selectable[] },\n );\n }\n assert(HierarchyNode.isGeneric(hierarchyNode));\n return {\n // note: generic nodes aren't associated with an imodel\n [\"\"]: [createSelectableForGenericNode(hierarchyNode, modelNode.id)],\n };\n}\n\nfunction groupIModelInstanceKeys(instanceKeys: InstancesNodeKey[\"instanceKeys\"]) {\n return instanceKeys.reduce(\n (imodelSelectables, key) => {\n const imodelKey = key.imodelKey ?? \"\";\n let selectablesList = imodelSelectables[imodelKey];\n if (!selectablesList) {\n selectablesList = [];\n imodelSelectables[imodelKey] = selectablesList;\n }\n selectablesList.push(key);\n return imodelSelectables;\n },\n {} as { [imodelKey: string]: InstanceKey[] },\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Utils.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/Utils.ts"],"names":[],"mappings":"AAKA,OAAO,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"Utils.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/Utils.ts"],"names":[],"mappings":"AAKA,OAAO,sBAAsB,CAAC;AAE9B,OAAO,EAAE,aAAa,EAAoB,MAAM,iCAAiC,CAAC;AAElF,gBAAgB;AAChB,wBAAgB,YAAY,CAAC,IAAI,EAAE,IAAI,CAAC,aAAa,EAAE,KAAK,GAAG,YAAY,CAAC,UAE3E;AAiBD,gBAAgB;AAChB,wBAAgB,SAAS,CAAC,GAAG,EAAE,aAAa,EAAE,GAAG,EAAE,aAAa,GAAG,OAAO,CAezE;AAED,gBAAgB;AAChB,eAAO,MAAM,kBAAkB,QAAQ,CAAC;AAExC;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,UAAU,EAAE,EAAE,GAAG;IAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,QAMtG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/Utils.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/internal/Utils.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,sBAAsB,CAAC;AAE9B,OAAO,EAAiB,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAElF,gBAAgB;AAChB,MAAM,UAAU,YAAY,CAAC,IAA+C;IAC1E,OAAO,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,gBAAgB,CAAC,EAAE,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC1F,CAAC;AAED,SAAS,gBAAgB,CAAC,GAAqB;IAC7C,OAAO,2BAA2B,CAAC,GAAG,CAAC,CAAC;AAC1C,CAAC;AAED,SAAS,2BAA2B,CAAC,GAAW;IAC9C,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC;SACvB,GAAG,CAAC,CAAC,CA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O,CAAC,EAAE,CAAC;IAC/B,CAAC;AACH,CAAC","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 { HierarchyNode, HierarchyNodeKey } from \"@itwin/presentation-hierarchies\";\n\n/** @internal */\nexport function createNodeId(node: Pick<HierarchyNode, \"key\" | \"parentKeys\">) {\n return [...node.parentKeys.map(serializeNodeKey), serializeNodeKey(node.key)].join(\";\");\n}\n\nfunction serializeNodeKey(key: HierarchyNodeKey): string {\n return convertObjectValuesToString(key);\n}\n\nfunction convertObjectValuesToString(obj: object): string {\n return Object.entries(obj)\n .map(([, value]) => {\n if (typeof value === \"object\") {\n return convertObjectValuesToString(value);\n }\n return String(value);\n })\n .join(\",\");\n}\n\n/** @internal */\nexport function sameNodes(lhs: HierarchyNode, rhs: HierarchyNode): boolean {\n if (HierarchyNodeKey.compare(lhs.key, rhs.key) !== 0) {\n return false;\n }\n\n if (lhs.parentKeys.length !== rhs.parentKeys.length) {\n return false;\n }\n\n for (let i = lhs.parentKeys.length - 1; i >= 0; --i) {\n if (HierarchyNodeKey.compare(lhs.parentKeys[i], rhs.parentKeys[i]) !== 0) {\n return false;\n }\n }\n return true;\n}\n\n/** @internal */\nexport const MAX_LIMIT_OVERRIDE = 10000;\n\n/**\n * A helper that disposes the given object, if it's disposable.\n *\n * The first option is to dispose using the deprecated `dispose` method if it exists on the object.\n * If not, we use the new `Symbol.dispose` method. If that doesn't exist either, the object is\n * considered as non-disposable and nothing is done with it.\n *\n * @internal\n */\nexport function safeDispose(disposable: {} | { [Symbol.dispose]: () => void } | { dispose: () => void }) {\n if (\"dispose\" in disposable) {\n disposable.dispose();\n } else if (Symbol.dispose in disposable) {\n disposable[Symbol.dispose]();\n }\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { HierarchyLevelDetails, TreeRendererProps } from "../Renderers.js";
|
|
2
|
+
import { ErrorItem } from "./FlatTreeNode.js";
|
|
3
|
+
/** @alpha */
|
|
4
|
+
export interface ErrorItemRendererProps extends Pick<TreeRendererProps, "getHierarchyLevelDetails"> {
|
|
5
|
+
errorItem: ErrorItem;
|
|
6
|
+
/** A callback to reload a hierarchy level when an error occurs and `retry` button is clicked. */
|
|
7
|
+
reloadTree: (options: {
|
|
8
|
+
parentNodeId: string | undefined;
|
|
9
|
+
state: "reset";
|
|
10
|
+
}) => void;
|
|
11
|
+
/** Action to perform when an error occurs and node label is clicked in the error message */
|
|
12
|
+
scrollToElement: (errorNode: ErrorItem) => void;
|
|
13
|
+
/** Action to perform when the filter button is clicked for this node. */
|
|
14
|
+
onFilterClick?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Renders StrataKit `<ErrorRegion.Item />` for all supported error types:
|
|
18
|
+
* - `ResultSetTooLarge` - renders `LocalizedStrings.resultLimitExceeded` message with actions to increase limit or apply filtering
|
|
19
|
+
* - `NoFilterMatches` - renders `LocalizedStrings.noFilteredChildren` message with action to change filter
|
|
20
|
+
* - `ChildrenLoad` - renders `LocalizedStrings.failedToCreateHierarchy` message with action to retry loading
|
|
21
|
+
* - `Unknown` - renders message set on error object.
|
|
22
|
+
*
|
|
23
|
+
* @alpha
|
|
24
|
+
*/
|
|
25
|
+
export declare function ErrorItemRenderer({ errorItem, getHierarchyLevelDetails, onFilterClick, reloadTree, scrollToElement }: ErrorItemRendererProps): import("react/jsx-runtime").JSX.Element;
|
|
26
|
+
//# sourceMappingURL=ErrorItemRenderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorItemRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/ErrorItemRenderer.tsx"],"names":[],"mappings":"AAQA,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAE3E,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG9C,aAAa;AACb,MAAM,WAAW,sBAAuB,SAAQ,IAAI,CAAC,iBAAiB,EAAE,0BAA0B,CAAC;IACjG,SAAS,EAAE,SAAS,CAAC;IACrB,iGAAiG;IACjG,UAAU,EAAE,CAAC,OAAO,EAAE;QAAE,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IACpF,4FAA4F;IAC5F,eAAe,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,CAAC;IAChD,yEAAyE;IACzE,aAAa,CAAC,EAAE,CAAC,qBAAqB,EAAE,qBAAqB,KAAK,IAAI,CAAC;CACxE;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,SAAS,EAAE,wBAAwB,EAAE,aAAa,EAAE,UAAU,EAAE,eAAe,EAAE,EAAE,sBAAsB,2CAqE5I"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
import { Anchor, Text } from "@stratakit/bricks";
|
|
7
|
+
import { unstable_ErrorRegion as ErrorRegion } from "@stratakit/structures";
|
|
8
|
+
import { MAX_LIMIT_OVERRIDE } from "../internal/Utils.js";
|
|
9
|
+
import { useLocalizationContext } from "./LocalizationContext.js";
|
|
10
|
+
/**
|
|
11
|
+
* Renders StrataKit `<ErrorRegion.Item />` for all supported error types:
|
|
12
|
+
* - `ResultSetTooLarge` - renders `LocalizedStrings.resultLimitExceeded` message with actions to increase limit or apply filtering
|
|
13
|
+
* - `NoFilterMatches` - renders `LocalizedStrings.noFilteredChildren` message with action to change filter
|
|
14
|
+
* - `ChildrenLoad` - renders `LocalizedStrings.failedToCreateHierarchy` message with action to retry loading
|
|
15
|
+
* - `Unknown` - renders message set on error object.
|
|
16
|
+
*
|
|
17
|
+
* @alpha
|
|
18
|
+
*/
|
|
19
|
+
export function ErrorItemRenderer({ errorItem, getHierarchyLevelDetails, onFilterClick, reloadTree, scrollToElement }) {
|
|
20
|
+
const { localizedStrings } = useLocalizationContext();
|
|
21
|
+
const { errorNode, expandTo } = errorItem;
|
|
22
|
+
if (errorNode.error.type === "ResultSetTooLarge") {
|
|
23
|
+
const limit = errorNode.error.resultSetSizeLimit;
|
|
24
|
+
const onOverrideLimit = getHierarchyLevelDetails ? () => getHierarchyLevelDetails(errorNode.id)?.setSizeLimit(MAX_LIMIT_OVERRIDE) : undefined;
|
|
25
|
+
return (_jsx(ErrorItemContainer, { errorNode: errorNode, actions: [
|
|
26
|
+
{
|
|
27
|
+
action: () => {
|
|
28
|
+
onOverrideLimit?.();
|
|
29
|
+
},
|
|
30
|
+
label: localizedStrings.increaseHierarchyLimit.replace("{{limit}}", MAX_LIMIT_OVERRIDE.toString()),
|
|
31
|
+
condition: () => !!onOverrideLimit && limit < MAX_LIMIT_OVERRIDE,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
action: () => {
|
|
35
|
+
const hierarchyLevelDetails = getHierarchyLevelDetails?.(errorNode.id);
|
|
36
|
+
hierarchyLevelDetails && onFilterClick?.(hierarchyLevelDetails);
|
|
37
|
+
},
|
|
38
|
+
label: localizedStrings.increaseHierarchyLimitWithFiltering,
|
|
39
|
+
condition: () => !!onFilterClick && !!errorNode?.isFilterable,
|
|
40
|
+
},
|
|
41
|
+
], message: localizedStrings.resultLimitExceeded.replace("{{limit}}", limit.toString()), scrollToElement: () => scrollToElement({ errorNode, expandTo }) }));
|
|
42
|
+
}
|
|
43
|
+
if (errorNode.error.type === "NoFilterMatches") {
|
|
44
|
+
return (_jsx(ErrorItemContainer, { errorNode: errorNode, actions: [
|
|
45
|
+
{
|
|
46
|
+
action: () => {
|
|
47
|
+
const hierarchyLevelDetails = getHierarchyLevelDetails?.(errorNode.id);
|
|
48
|
+
hierarchyLevelDetails && onFilterClick?.(hierarchyLevelDetails);
|
|
49
|
+
},
|
|
50
|
+
label: localizedStrings.noFilteredChildrenChangeFilter,
|
|
51
|
+
condition: () => true,
|
|
52
|
+
},
|
|
53
|
+
], message: localizedStrings.noFilteredChildren, scrollToElement: () => scrollToElement({ errorNode, expandTo }) }));
|
|
54
|
+
}
|
|
55
|
+
if (errorNode.error.type === "ChildrenLoad") {
|
|
56
|
+
return (_jsx(ErrorItemContainer, { errorNode: errorNode, actions: [
|
|
57
|
+
{
|
|
58
|
+
action: () => reloadTree({ parentNodeId: errorNode.id, state: "reset" }),
|
|
59
|
+
label: localizedStrings.retry,
|
|
60
|
+
condition: () => true,
|
|
61
|
+
},
|
|
62
|
+
], message: localizedStrings.failedToCreateHierarchy, scrollToElement: () => scrollToElement({ errorNode, expandTo }) }));
|
|
63
|
+
}
|
|
64
|
+
return _jsx(ErrorItemContainer, { errorNode: errorNode, message: errorNode.error.message, scrollToElement: () => scrollToElement({ errorNode, expandTo }) });
|
|
65
|
+
}
|
|
66
|
+
function ErrorItemContainer({ errorNode, message, actions, scrollToElement }) {
|
|
67
|
+
return (_jsx(ErrorRegion.Item, { message: _jsx(MessageWithLink, { linkLabel: errorNode.label, scrollToElement: scrollToElement, message: message }), messageId: errorNode.id, actions: actions
|
|
68
|
+
?.filter(({ condition }) => condition())
|
|
69
|
+
.map(({ label, action }) => (_jsx(Text, { variant: "body-sm", children: _jsx(Anchor, { onClick: action, render: _jsx("button", {}), children: label }) }, label))) }));
|
|
70
|
+
}
|
|
71
|
+
function MessageWithLink({ linkLabel, scrollToElement, message }) {
|
|
72
|
+
const splitMessage = message.split("{{node}}", 2);
|
|
73
|
+
return (_jsxs("div", { style: { display: "flex", whiteSpace: "pre", flexWrap: "wrap" }, children: [splitMessage[0], _jsx(Anchor, { onClick: scrollToElement, render: _jsx("button", {}), children: linkLabel }), splitMessage[1] ? splitMessage[1] : null] }));
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=ErrorItemRenderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorItemRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/ErrorItemRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,oBAAoB,IAAI,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAI1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAalE;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAAE,SAAS,EAAE,wBAAwB,EAAE,aAAa,EAAE,UAAU,EAAE,eAAe,EAA0B;IAC3I,MAAM,EAAE,gBAAgB,EAAE,GAAG,sBAAsB,EAAE,CAAC;IAEtD,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC;IAC1C,IAAI,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,mBAAmB,EAAE,CAAC;QACjD,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,kBAAkB,CAAC;QACjD,MAAM,eAAe,GAAG,wBAAwB,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,wBAAwB,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,YAAY,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC9I,OAAO,CACL,KAAC,kBAAkB,IACjB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE;gBACP;oBACE,MAAM,EAAE,GAAG,EAAE;wBACX,eAAe,EA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;aACvC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAC1B,KAAC,IAAI,IAAa,OAAO,EAAC,SAAS,YACjC,KAAC,MAAM,IAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,kBAAU,YACxC,KAAK,GACC,IAHA,KAAK,CAIT,CACR,CAAC,GACJ,CACH,CAAC;AACJ,CAAC;AAQD,SAAS,eAAe,CAAC,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAwB;IACpF,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IAClD,OAAO,CACL,eAAK,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,aACjE,YAAY,CAAC,CAAC,CAAC,EAChB,KAAC,MAAM,IAAC,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,kBAAU,YACjD,SAAS,GACH,EACR,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,IACrC,CACP,CAAC;AACJ,CAAC","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 { Anchor, Text } from \"@stratakit/bricks\";\nimport { unstable_ErrorRegion as ErrorRegion } from \"@stratakit/structures\";\nimport { MAX_LIMIT_OVERRIDE } from \"../internal/Utils.js\";\nimport { HierarchyLevelDetails, TreeRendererProps } from \"../Renderers.js\";\nimport { PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { ErrorItem } from \"./FlatTreeNode.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\n\n/** @alpha */\nexport interface ErrorItemRendererProps extends Pick<TreeRendererProps, \"getHierarchyLevelDetails\"> {\n errorItem: ErrorItem;\n /** A callback to reload a hierarchy level when an error occurs and `retry` button is clicked. */\n reloadTree: (options: { parentNodeId: string | undefined; state: \"reset\" }) => void;\n /** Action to perform when an error occurs and node label is clicked in the error message */\n scrollToElement: (errorNode: ErrorItem) => void;\n /** Action to perform when the filter button is clicked for this node. */\n onFilterClick?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;\n}\n\n/**\n * Renders StrataKit `<ErrorRegion.Item />` for all supported error types:\n * - `ResultSetTooLarge` - renders `LocalizedStrings.resultLimitExceeded` message with actions to increase limit or apply filtering\n * - `NoFilterMatches` - renders `LocalizedStrings.noFilteredChildren` message with action to change filter\n * - `ChildrenLoad` - renders `LocalizedStrings.failedToCreateHierarchy` message with action to retry loading\n * - `Unknown` - renders message set on error object.\n *\n * @alpha\n */\nexport function ErrorItemRenderer({ errorItem, getHierarchyLevelDetails, onFilterClick, reloadTree, scrollToElement }: ErrorItemRendererProps) {\n const { localizedStrings } = useLocalizationContext();\n\n const { errorNode, expandTo } = errorItem;\n if (errorNode.error.type === \"ResultSetTooLarge\") {\n const limit = errorNode.error.resultSetSizeLimit;\n const onOverrideLimit = getHierarchyLevelDetails ? () => getHierarchyLevelDetails(errorNode.id)?.setSizeLimit(MAX_LIMIT_OVERRIDE) : undefined;\n return (\n <ErrorItemContainer\n errorNode={errorNode}\n actions={[\n {\n action: () => {\n onOverrideLimit?.();\n },\n label: localizedStrings.increaseHierarchyLimit.replace(\"{{limit}}\", MAX_LIMIT_OVERRIDE.toString()),\n condition: () => !!onOverrideLimit && limit < MAX_LIMIT_OVERRIDE,\n },\n {\n action: () => {\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(errorNode.id);\n hierarchyLevelDetails && onFilterClick?.(hierarchyLevelDetails);\n },\n label: localizedStrings.increaseHierarchyLimitWithFiltering,\n condition: () => !!onFilterClick && !!errorNode?.isFilterable,\n },\n ]}\n message={localizedStrings.resultLimitExceeded.replace(\"{{limit}}\", limit.toString())}\n scrollToElement={() => scrollToElement({ errorNode, expandTo })}\n />\n );\n }\n if (errorNode.error.type === \"NoFilterMatches\") {\n return (\n <ErrorItemContainer\n errorNode={errorNode}\n actions={[\n {\n action: () => {\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(errorNode.id);\n hierarchyLevelDetails && onFilterClick?.(hierarchyLevelDetails);\n },\n label: localizedStrings.noFilteredChildrenChangeFilter,\n condition: () => true,\n },\n ]}\n message={localizedStrings.noFilteredChildren}\n scrollToElement={() => scrollToElement({ errorNode, expandTo })}\n />\n );\n }\n if (errorNode.error.type === \"ChildrenLoad\") {\n return (\n <ErrorItemContainer\n errorNode={errorNode}\n actions={[\n {\n action: () => reloadTree({ parentNodeId: errorNode.id, state: \"reset\" }),\n label: localizedStrings.retry,\n condition: () => true,\n },\n ]}\n message={localizedStrings.failedToCreateHierarchy}\n scrollToElement={() => scrollToElement({ errorNode, expandTo })}\n />\n );\n }\n\n return <ErrorItemContainer errorNode={errorNode} message={errorNode.error.message} scrollToElement={() => scrollToElement({ errorNode, expandTo })} />;\n}\n\ntype ErrorItemContainerProps = {\n errorNode: PresentationHierarchyNode;\n message: string;\n actions?: { action: () => void; label: string; condition: () => boolean }[];\n} & Pick<MessageWithLinkProps, \"scrollToElement\">;\n\nfunction ErrorItemContainer({ errorNode, message, actions, scrollToElement }: ErrorItemContainerProps) {\n return (\n <ErrorRegion.Item\n message={<MessageWithLink linkLabel={errorNode.label} scrollToElement={scrollToElement} message={message} />}\n messageId={errorNode.id}\n actions={actions\n ?.filter(({ condition }) => condition())\n .map(({ label, action }) => (\n <Text key={label} variant=\"body-sm\">\n <Anchor onClick={action} render={<button />}>\n {label}\n </Anchor>\n </Text>\n ))}\n />\n );\n}\n\ninterface MessageWithLinkProps {\n scrollToElement: () => void;\n message: string;\n linkLabel?: string;\n}\n\nfunction MessageWithLink({ linkLabel, scrollToElement, message }: MessageWithLinkProps) {\n const splitMessage = message.split(\"{{node}}\", 2);\n return (\n <div style={{ display: \"flex\", whiteSpace: \"pre\", flexWrap: \"wrap\" }}>\n {splitMessage[0]}\n <Anchor onClick={scrollToElement} render={<button />}>\n {linkLabel}\n </Anchor>\n {splitMessage[1] ? splitMessage[1] : null}\n </div>\n );\n}\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { HierarchyLevelDetails, TreeRendererProps } from "../Renderers.js";
|
|
2
|
+
import { PresentationHierarchyNode } from "../TreeNode.js";
|
|
3
|
+
/** @alpha */
|
|
4
|
+
export type FilterActionProps = {
|
|
5
|
+
/** Action to perform when the filter button is clicked for this node. */
|
|
6
|
+
onFilter?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;
|
|
7
|
+
/**
|
|
8
|
+
* Indicates that space for this action button should be reserved, even when the action is not available.
|
|
9
|
+
* For nodes that don't support filtering, `<FilterAction reserveSpace />` renders:
|
|
10
|
+
*
|
|
11
|
+
* - Blank space when the action is used as an inline action. It's recommended to set this prop to keep all action buttons of the same kind vertically aligned.
|
|
12
|
+
* - Disabled menu item when the action is used as a menu action.
|
|
13
|
+
*/
|
|
14
|
+
reserveSpace?: true;
|
|
15
|
+
} & Pick<TreeRendererProps, "getHierarchyLevelDetails">;
|
|
16
|
+
/**
|
|
17
|
+
* React component that renders a filter action for a tree item.
|
|
18
|
+
* @alpha
|
|
19
|
+
*/
|
|
20
|
+
export declare const FilterAction: import("react").NamedExoticComponent<{
|
|
21
|
+
/** Action to perform when the filter button is clicked for this node. */
|
|
22
|
+
onFilter?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Indicates that space for this action button should be reserved, even when the action is not available.
|
|
25
|
+
* For nodes that don't support filtering, `<FilterAction reserveSpace />` renders:
|
|
26
|
+
*
|
|
27
|
+
* - Blank space when the action is used as an inline action. It's recommended to set this prop to keep all action buttons of the same kind vertically aligned.
|
|
28
|
+
* - Disabled menu item when the action is used as a menu action.
|
|
29
|
+
*/
|
|
30
|
+
reserveSpace?: true;
|
|
31
|
+
} & Pick<TreeRendererProps, "getHierarchyLevelDetails"> & {
|
|
32
|
+
node: PresentationHierarchyNode;
|
|
33
|
+
}>;
|
|
34
|
+
//# sourceMappingURL=FilterAction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FilterAction.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/FilterAction.tsx"],"names":[],"mappings":"AAQA,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAG3D,aAAa;AACb,MAAM,MAAM,iBAAiB,GAAG;IAC9B,yEAAyE;IACzE,QAAQ,CAAC,EAAE,CAAC,qBAAqB,EAAE,qBAAqB,KAAK,IAAI,CAAC;IAClE;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,IAAI,CAAC;CACrB,GAAG,IAAI,CAAC,iBAAiB,EAAE,0BAA0B,CAAC,CAAC;AAExD;;;GAGG;AACH,eAAO,MAAM,YAAY;IAhBvB,yEAAyE;eAC9D,CAAC,qBAAqB,EAAE,qBAAqB,KAAK,IAAI;IACjE;;;;;;OAMG;mBACY,IAAI;;UAYU,yBAAyB;EAsBtD,CAAC"}
|