@itwin/tree-widget-react 1.2.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -2
- package/README.md +1 -1
- package/lib/cjs/TreeWidget.d.ts +0 -1
- package/lib/cjs/TreeWidget.js +9 -10
- package/lib/cjs/TreeWidget.js.map +1 -1
- package/lib/cjs/components/SelectableTree.d.ts +9 -1
- package/lib/cjs/components/SelectableTree.js +28 -17
- package/lib/cjs/components/SelectableTree.js.map +1 -1
- package/lib/cjs/components/SelectableTree.scss +0 -16
- package/lib/cjs/components/TreeFilteringState.js +3 -3
- package/lib/cjs/components/TreeFilteringState.js.map +1 -1
- package/lib/cjs/components/TreeSelector.d.ts +28 -0
- package/lib/cjs/components/TreeSelector.js +27 -0
- package/lib/cjs/components/TreeSelector.js.map +1 -0
- package/lib/cjs/components/TreeSelector.scss +27 -0
- package/lib/cjs/components/TreeWidgetUiItemsProvider.d.ts +9 -1
- package/lib/cjs/components/TreeWidgetUiItemsProvider.js +21 -14
- package/lib/cjs/components/TreeWidgetUiItemsProvider.js.map +1 -1
- package/lib/cjs/components/TreeWidgetUiItemsProvider.scss +1 -1
- package/lib/cjs/components/tree-header/TreeHeader.d.ts +3 -0
- package/lib/cjs/components/tree-header/TreeHeader.js +20 -15
- package/lib/cjs/components/tree-header/TreeHeader.js.map +1 -1
- package/lib/cjs/components/tree-header/TreeHeader.scss +29 -1
- package/lib/cjs/components/trees/CategoriesVisibilityUtils.js +13 -8
- package/lib/cjs/components/trees/CategoriesVisibilityUtils.js.map +1 -1
- package/lib/cjs/components/trees/VisibilityTreeBase.scss +1 -1
- package/lib/cjs/components/trees/VisibilityTreeEventHandler.d.ts +1 -1
- package/lib/cjs/components/trees/VisibilityTreeEventHandler.js +18 -10
- package/lib/cjs/components/trees/VisibilityTreeEventHandler.js.map +1 -1
- package/lib/cjs/components/trees/VisibilityTreeRenderer.d.ts +20 -4
- package/lib/cjs/components/trees/VisibilityTreeRenderer.js +28 -10
- package/lib/cjs/components/trees/VisibilityTreeRenderer.js.map +1 -1
- package/lib/cjs/components/trees/category-tree/CategoriesTree.d.ts +7 -2
- package/lib/cjs/components/trees/category-tree/CategoriesTree.js +47 -30
- package/lib/cjs/components/trees/category-tree/CategoriesTree.js.map +1 -1
- package/lib/cjs/components/trees/category-tree/CategoriesTreeComponent.js +27 -18
- package/lib/cjs/components/trees/category-tree/CategoriesTreeComponent.js.map +1 -1
- package/lib/cjs/components/trees/category-tree/CategoryVisibilityHandler.d.ts +2 -2
- package/lib/cjs/components/trees/category-tree/CategoryVisibilityHandler.js +18 -13
- package/lib/cjs/components/trees/category-tree/CategoryVisibilityHandler.js.map +1 -1
- package/lib/cjs/components/trees/common/ContextMenu.js +4 -4
- package/lib/cjs/components/trees/common/ContextMenu.js.map +1 -1
- package/lib/cjs/components/trees/common/TreeNodeRenderer.d.ts +1 -1
- package/lib/cjs/components/trees/common/TreeNodeRenderer.js +4 -4
- package/lib/cjs/components/trees/common/TreeNodeRenderer.js.map +1 -1
- package/lib/cjs/components/trees/common/TreeRenderer.d.ts +15 -1
- package/lib/cjs/components/trees/common/TreeRenderer.js +17 -7
- package/lib/cjs/components/trees/common/TreeRenderer.js.map +1 -1
- package/lib/cjs/components/trees/common/TreeRenderer.scss +39 -2
- package/lib/cjs/components/trees/common/Types.d.ts +8 -0
- package/lib/cjs/components/trees/common/Types.js +3 -3
- package/lib/cjs/components/trees/common/Types.js.map +1 -1
- package/lib/cjs/components/trees/common/UseVisibilityTreeState.d.ts +36 -0
- package/lib/cjs/components/trees/common/UseVisibilityTreeState.js +47 -0
- package/lib/cjs/components/trees/common/UseVisibilityTreeState.js.map +1 -0
- package/lib/cjs/components/trees/common/Utils.js +7 -5
- package/lib/cjs/components/trees/common/Utils.js.map +1 -1
- package/lib/cjs/components/trees/external-sources-tree/ExternalSources.json +1 -3
- package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTree.d.ts +9 -3
- package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTree.js +19 -7
- package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTree.js.map +1 -1
- package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js +4 -4
- package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js.map +1 -1
- package/lib/cjs/components/trees/imodel-content-tree/IModelContentTree.d.ts +9 -3
- package/lib/cjs/components/trees/imodel-content-tree/IModelContentTree.js +16 -12
- package/lib/cjs/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -1
- package/lib/cjs/components/trees/imodel-content-tree/IModelContentTreeComponent.js +6 -5
- package/lib/cjs/components/trees/imodel-content-tree/IModelContentTreeComponent.js.map +1 -1
- package/lib/cjs/components/trees/index.js +3 -3
- package/lib/cjs/components/trees/index.js.map +1 -1
- package/lib/cjs/components/trees/models-tree/ModelsTree.d.ts +7 -2
- package/lib/cjs/components/trees/models-tree/ModelsTree.js +76 -62
- package/lib/cjs/components/trees/models-tree/ModelsTree.js.map +1 -1
- package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.js +27 -29
- package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
- package/lib/cjs/components/trees/models-tree/ModelsTreeEventHandler.d.ts +9 -0
- package/lib/cjs/components/trees/models-tree/ModelsTreeEventHandler.js +31 -0
- package/lib/cjs/components/trees/models-tree/ModelsTreeEventHandler.js.map +1 -0
- package/lib/cjs/components/trees/models-tree/ModelsVisibilityHandler.js +125 -66
- package/lib/cjs/components/trees/models-tree/ModelsVisibilityHandler.js.map +1 -1
- package/lib/cjs/components/trees/models-tree/Utils.d.ts +4 -0
- package/lib/cjs/components/trees/models-tree/Utils.js +52 -58
- package/lib/cjs/components/trees/models-tree/Utils.js.map +1 -1
- package/lib/cjs/components/utils/AutoSizer.js +7 -5
- package/lib/cjs/components/utils/AutoSizer.js.map +1 -1
- package/lib/cjs/components/utils/IsPromiseLike.js +4 -4
- package/lib/cjs/components/utils/IsPromiseLike.js.map +1 -1
- package/lib/cjs/components/utils/UseTreeTransientState.js +3 -3
- package/lib/cjs/components/utils/UseTreeTransientState.js.map +1 -1
- package/lib/cjs/tree-widget-react.js +3 -3
- package/lib/cjs/tree-widget-react.js.map +1 -1
- package/lib/esm/TreeWidget.d.ts +0 -1
- package/lib/esm/TreeWidget.js +9 -10
- package/lib/esm/TreeWidget.js.map +1 -1
- package/lib/esm/components/SelectableTree.d.ts +9 -1
- package/lib/esm/components/SelectableTree.js +28 -17
- package/lib/esm/components/SelectableTree.js.map +1 -1
- package/lib/esm/components/SelectableTree.scss +0 -16
- package/lib/esm/components/TreeFilteringState.js +3 -3
- package/lib/esm/components/TreeFilteringState.js.map +1 -1
- package/lib/esm/components/TreeSelector.d.ts +28 -0
- package/lib/esm/components/TreeSelector.js +23 -0
- package/lib/esm/components/TreeSelector.js.map +1 -0
- package/lib/esm/components/TreeSelector.scss +27 -0
- package/lib/esm/components/TreeWidgetUiItemsProvider.d.ts +9 -1
- package/lib/esm/components/TreeWidgetUiItemsProvider.js +19 -13
- package/lib/esm/components/TreeWidgetUiItemsProvider.js.map +1 -1
- package/lib/esm/components/TreeWidgetUiItemsProvider.scss +1 -1
- package/lib/esm/components/tree-header/TreeHeader.d.ts +3 -0
- package/lib/esm/components/tree-header/TreeHeader.js +20 -15
- package/lib/esm/components/tree-header/TreeHeader.js.map +1 -1
- package/lib/esm/components/tree-header/TreeHeader.scss +29 -1
- package/lib/esm/components/trees/CategoriesVisibilityUtils.js +13 -8
- package/lib/esm/components/trees/CategoriesVisibilityUtils.js.map +1 -1
- package/lib/esm/components/trees/VisibilityTreeBase.scss +1 -1
- package/lib/esm/components/trees/VisibilityTreeEventHandler.d.ts +1 -1
- package/lib/esm/components/trees/VisibilityTreeEventHandler.js +18 -10
- package/lib/esm/components/trees/VisibilityTreeEventHandler.js.map +1 -1
- package/lib/esm/components/trees/VisibilityTreeRenderer.d.ts +20 -4
- package/lib/esm/components/trees/VisibilityTreeRenderer.js +27 -10
- package/lib/esm/components/trees/VisibilityTreeRenderer.js.map +1 -1
- package/lib/esm/components/trees/category-tree/CategoriesTree.d.ts +7 -2
- package/lib/esm/components/trees/category-tree/CategoriesTree.js +51 -34
- package/lib/esm/components/trees/category-tree/CategoriesTree.js.map +1 -1
- package/lib/esm/components/trees/category-tree/CategoriesTreeComponent.js +24 -18
- package/lib/esm/components/trees/category-tree/CategoriesTreeComponent.js.map +1 -1
- package/lib/esm/components/trees/category-tree/CategoryVisibilityHandler.d.ts +2 -2
- package/lib/esm/components/trees/category-tree/CategoryVisibilityHandler.js +18 -13
- package/lib/esm/components/trees/category-tree/CategoryVisibilityHandler.js.map +1 -1
- package/lib/esm/components/trees/common/ContextMenu.js +4 -4
- package/lib/esm/components/trees/common/ContextMenu.js.map +1 -1
- package/lib/esm/components/trees/common/TreeNodeRenderer.d.ts +1 -1
- package/lib/esm/components/trees/common/TreeNodeRenderer.js +4 -4
- package/lib/esm/components/trees/common/TreeNodeRenderer.js.map +1 -1
- package/lib/esm/components/trees/common/TreeRenderer.d.ts +15 -1
- package/lib/esm/components/trees/common/TreeRenderer.js +15 -6
- package/lib/esm/components/trees/common/TreeRenderer.js.map +1 -1
- package/lib/esm/components/trees/common/TreeRenderer.scss +39 -2
- package/lib/esm/components/trees/common/Types.d.ts +8 -0
- package/lib/esm/components/trees/common/Types.js +3 -3
- package/lib/esm/components/trees/common/Types.js.map +1 -1
- package/lib/esm/components/trees/common/UseVisibilityTreeState.d.ts +36 -0
- package/lib/esm/components/trees/common/UseVisibilityTreeState.js +43 -0
- package/lib/esm/components/trees/common/UseVisibilityTreeState.js.map +1 -0
- package/lib/esm/components/trees/common/Utils.js +7 -5
- package/lib/esm/components/trees/common/Utils.js.map +1 -1
- package/lib/esm/components/trees/external-sources-tree/ExternalSources.json +1 -3
- package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTree.d.ts +9 -3
- package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTree.js +22 -10
- package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTree.js.map +1 -1
- package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js +4 -4
- package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js.map +1 -1
- package/lib/esm/components/trees/imodel-content-tree/IModelContentTree.d.ts +9 -3
- package/lib/esm/components/trees/imodel-content-tree/IModelContentTree.js +19 -15
- package/lib/esm/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -1
- package/lib/esm/components/trees/imodel-content-tree/IModelContentTreeComponent.js +6 -5
- package/lib/esm/components/trees/imodel-content-tree/IModelContentTreeComponent.js.map +1 -1
- package/lib/esm/components/trees/index.js +3 -3
- package/lib/esm/components/trees/index.js.map +1 -1
- package/lib/esm/components/trees/models-tree/ModelsTree.d.ts +7 -2
- package/lib/esm/components/trees/models-tree/ModelsTree.js +80 -66
- package/lib/esm/components/trees/models-tree/ModelsTree.js.map +1 -1
- package/lib/esm/components/trees/models-tree/ModelsTreeComponent.js +25 -30
- package/lib/esm/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
- package/lib/esm/components/trees/models-tree/ModelsTreeEventHandler.d.ts +9 -0
- package/lib/esm/components/trees/models-tree/ModelsTreeEventHandler.js +27 -0
- package/lib/esm/components/trees/models-tree/ModelsTreeEventHandler.js.map +1 -0
- package/lib/esm/components/trees/models-tree/ModelsVisibilityHandler.js +125 -66
- package/lib/esm/components/trees/models-tree/ModelsVisibilityHandler.js.map +1 -1
- package/lib/esm/components/trees/models-tree/Utils.d.ts +4 -0
- package/lib/esm/components/trees/models-tree/Utils.js +50 -57
- package/lib/esm/components/trees/models-tree/Utils.js.map +1 -1
- package/lib/esm/components/utils/AutoSizer.js +7 -5
- package/lib/esm/components/utils/AutoSizer.js.map +1 -1
- package/lib/esm/components/utils/IsPromiseLike.js +4 -4
- package/lib/esm/components/utils/IsPromiseLike.js.map +1 -1
- package/lib/esm/components/utils/UseTreeTransientState.js +3 -3
- package/lib/esm/components/utils/UseTreeTransientState.js.map +1 -1
- package/lib/esm/tree-widget-react.js +3 -3
- package/lib/esm/tree-widget-react.js.map +1 -1
- package/lib/public/locales/en/TreeWidget.json +1 -0
- package/package.json +47 -46
- package/lib/cjs/e2e-tests/TreeWidget.test.d.ts +0 -2
- package/lib/cjs/e2e-tests/TreeWidget.test.js +0 -51
- package/lib/cjs/e2e-tests/TreeWidget.test.js.map +0 -1
- package/lib/cjs/e2e-tests/utils.d.ts +0 -9
- package/lib/cjs/e2e-tests/utils.js +0 -51
- package/lib/cjs/e2e-tests/utils.js.map +0 -1
- package/lib/esm/e2e-tests/TreeWidget.test.d.ts +0 -2
- package/lib/esm/e2e-tests/TreeWidget.test.js +0 -46
- package/lib/esm/e2e-tests/TreeWidget.test.js.map +0 -1
- package/lib/esm/e2e-tests/utils.d.ts +0 -9
- package/lib/esm/e2e-tests/utils.js +0 -40
- package/lib/esm/e2e-tests/utils.js.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
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
|
-
*--------------------------------------------------------------------------------------------*/
|
|
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
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.invertAllCategories = exports.hideAllCategories = exports.showAllCategories = exports.CategoryVisibilityHandler = exports.useCategories = void 0;
|
|
8
8
|
const react_1 = require("react");
|
|
@@ -55,23 +55,26 @@ class CategoryVisibilityHandler {
|
|
|
55
55
|
}
|
|
56
56
|
getVisibilityStatus(node) {
|
|
57
57
|
const nodeKey = (0, presentation_components_1.isPresentationTreeNodeItem)(node) ? node.key : undefined;
|
|
58
|
-
if (!nodeKey)
|
|
58
|
+
if (!nodeKey) {
|
|
59
59
|
return { state: "hidden", isDisabled: true };
|
|
60
|
+
}
|
|
60
61
|
const instanceId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);
|
|
61
62
|
return { state: node.parentId ? this.getSubCategoryVisibility(instanceId) : this.getCategoryVisibility(instanceId) };
|
|
62
63
|
}
|
|
63
64
|
async changeVisibility(node, shouldDisplay) {
|
|
64
65
|
const nodeKey = (0, presentation_components_1.isPresentationTreeNodeItem)(node) ? node.key : undefined;
|
|
65
|
-
if (!nodeKey)
|
|
66
|
+
if (!nodeKey) {
|
|
66
67
|
return;
|
|
68
|
+
}
|
|
67
69
|
// handle subcategory visibility change
|
|
68
70
|
if (node.parentId) {
|
|
69
71
|
const childId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);
|
|
70
72
|
// istanbul ignore next
|
|
71
73
|
const parentId = this.getParent(childId)?.categoryId;
|
|
72
74
|
// make sure parent category is enabled
|
|
73
|
-
if (shouldDisplay && parentId)
|
|
75
|
+
if (shouldDisplay && parentId) {
|
|
74
76
|
await this.enableCategory([parentId], true, false);
|
|
77
|
+
}
|
|
75
78
|
this.enableSubCategory(childId, shouldDisplay);
|
|
76
79
|
return;
|
|
77
80
|
}
|
|
@@ -80,8 +83,9 @@ class CategoryVisibilityHandler {
|
|
|
80
83
|
}
|
|
81
84
|
getSubCategoryVisibility(id) {
|
|
82
85
|
const parentItem = this.getParent(id);
|
|
83
|
-
if (!parentItem)
|
|
86
|
+
if (!parentItem) {
|
|
84
87
|
return "hidden";
|
|
88
|
+
}
|
|
85
89
|
const isVisible = this._activeView.view.viewsCategory(parentItem.categoryId) && this._activeView.isSubCategoryVisible(id);
|
|
86
90
|
return isVisible ? "visible" : "hidden";
|
|
87
91
|
}
|
|
@@ -91,23 +95,23 @@ class CategoryVisibilityHandler {
|
|
|
91
95
|
getParent(key) {
|
|
92
96
|
for (const category of this._categories) {
|
|
93
97
|
// istanbul ignore else
|
|
94
|
-
if (category.subCategoryIds) {
|
|
95
|
-
|
|
96
|
-
return category;
|
|
98
|
+
if (category.subCategoryIds && category.subCategoryIds.indexOf(key) !== -1) {
|
|
99
|
+
return category;
|
|
97
100
|
}
|
|
98
101
|
}
|
|
99
102
|
return undefined;
|
|
100
103
|
}
|
|
101
104
|
onVisibilityChangeInternal() {
|
|
102
|
-
if (this._pendingVisibilityChange)
|
|
105
|
+
if (this._pendingVisibilityChange) {
|
|
103
106
|
return;
|
|
107
|
+
}
|
|
104
108
|
this._pendingVisibilityChange = setTimeout(() => {
|
|
105
109
|
this.onVisibilityChange.raiseEvent();
|
|
106
110
|
this._pendingVisibilityChange = undefined;
|
|
107
111
|
}, 0);
|
|
108
112
|
}
|
|
109
113
|
static getInstanceIdFromTreeNodeKey(nodeKey) {
|
|
110
|
-
return
|
|
114
|
+
return presentation_common_1.NodeKey.isInstancesNodeKey(nodeKey) && nodeKey.instanceKeys.length > 0 ? nodeKey.instanceKeys[0].id : /* istanbul ignore next */ "";
|
|
111
115
|
}
|
|
112
116
|
async enableCategory(ids, enabled, enableAllSubCategories = true) {
|
|
113
117
|
await (0, CategoriesVisibilityUtils_1.enableCategory)(this._viewManager, this._imodel, ids, enabled, this._useAllViewports, enableAllSubCategories);
|
|
@@ -149,8 +153,9 @@ async function invertAllCategories(categories, viewport) {
|
|
|
149
153
|
}
|
|
150
154
|
// First, we need to check if at least one subcategory is disabled. If it is true, then only subcategories should change display, not categories.
|
|
151
155
|
if (category.subCategoryIds?.some((subCategory) => !viewport.isSubCategoryVisible(subCategory))) {
|
|
152
|
-
for (const subCategory of category.subCategoryIds)
|
|
156
|
+
for (const subCategory of category.subCategoryIds) {
|
|
153
157
|
viewport.isSubCategoryVisible(subCategory) ? enabledSubCategories.push(subCategory) : disabledSubCategories.push(subCategory);
|
|
158
|
+
}
|
|
154
159
|
}
|
|
155
160
|
else {
|
|
156
161
|
enabled.push(category.categoryId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CategoryVisibilityHandler.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoryVisibilityHandler.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,iCAAgC;AAChC,8DAAwD;AACxD,sDAA8C;AAC9C,wDAAiD;AACjD,oEAAqD;AACrD,4EAA4E;AAC5E,4EAA6G;AAM7G,MAAM,sBAAsB,GAAmB,EAAE,CAAC;AAElD;;;GAGG;AACH,SAAgB,aAAa,CAAC,WAAwB,EAAE,MAAwB,EAAE,IAAe;IAC/F,MAAM,WAAW,GAAG,IAAI,IAAI,WAAW,CAAC,gBAAgB,EAAE,CAAC;IAC3D,MAAM,iBAAiB,GAAG,IAAA,eAAO,EAAC,KAAK,IAAI,EAAE,CAAC,IAAA,sDAA0B,EAAC,MAAM,EAAE,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IACtH,OAAO,IAAA,gCAAa,EAAC,iBAAiB,CAAC,IAAI,sBAAsB,CAAC;AACpE,CAAC;AAJD,sCAIC;AAuBD;;;;GAIG;AACH,MAAa,yBAAyB;IAQpC,YAAY,MAAuC;QAiB5C,uBAAkB,GAAG,IAAI,sBAAO,EAA4B,CAAC;QA2DpE,gEAAgE;QACxD,0BAAqB,GAAG,GAAG,EAAE;YACnC,IAAI,CAAC,0BAA0B,EAAE,CAAC;QACpC,CAAC,CAAC;QAEF,gEAAgE;QACxD,8BAAyB,GAAG,GAAG,EAAE;YACvC,IAAI,CAAC,0BAA0B,EAAE,CAAC;QACpC,CAAC,CAAC;QAnFA,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC;QACrC,uBAAuB;QACvB,IAAI,CAAC,gBAAgB,GAAG,MAAM,CAAC,YAAY,IAAI,KAA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KACF;IAED,kBAAkB;IAClB,oBAAoB,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,IAAA,6CAAiB,EAC7D,yBAAS,CAAC,WAAW,EACrB,WAAW,EACX,KAAK,EACL,IAAI,CACL,CAAC,CAAC;IAEH,MAAM,IAAA,0CAAc,EAClB,yBAAS,CAAC,WAAW,EACrB,QAAQ,CAAC,MAAM,EACf,OAAO,EACP,KAAK,EACL,IAAI,CACL,CAAC;IAEF,kBAAkB;IAClB,qBAAqB,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,IAAA,6CAAiB,EAC9D,yBAAS,CAAC,WAAW,EACrB,WAAW,EACX,IAAI,EACJ,IAAI,CACL,CAAC,CAAC;IAEH,MAAM,IAAA,0CAAc,EAClB,yBAAS,CAAC,WAAW,EACrB,QAAQ,CAAC,MAAM,EACf,QAAQ,EACR,IAAI,EACJ,IAAI,CACL,CAAC;AACJ,CAAC;AAnDD,kDAmDC","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 { useMemo } from \"react\";\nimport { useAsyncValue } from \"@itwin/components-react\";\nimport { BeEvent } from \"@itwin/core-bentley\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { NodeKey } from \"@itwin/presentation-common\";\nimport { isPresentationTreeNodeItem } from \"@itwin/presentation-components\";\nimport { enableCategory, enableSubCategory, loadCategoriesFromViewport } from \"../CategoriesVisibilityUtils\";\n\nimport type { TreeNodeItem } from \"@itwin/components-react\";\nimport type { IModelConnection, ViewManager, Viewport } from \"@itwin/core-frontend\";\nimport type { IVisibilityHandler, VisibilityChangeListener, VisibilityStatus } from \"../VisibilityTreeEventHandler\";\n\nconst EMPTY_CATEGORIES_ARRAY: CategoryInfo[] = [];\n\n/**\n * Loads categories from viewport or uses provided list of categories.\n * @internal\n */\nexport function useCategories(viewManager: ViewManager, imodel: IModelConnection, view?: Viewport) {\n const currentView = view || viewManager.getFirstOpenView();\n const categoriesPromise = useMemo(async () => loadCategoriesFromViewport(imodel, currentView), [imodel, currentView]);\n return useAsyncValue(categoriesPromise) ?? EMPTY_CATEGORIES_ARRAY;\n}\n\n/**\n * Data structure that describes category.\n * @public\n */\nexport interface CategoryInfo {\n categoryId: string;\n subCategoryIds?: string[];\n}\n\n/**\n * Params for creating a [[CategoryVisibilityHandler]].\n * @public\n */\nexport interface CategoryVisibilityHandlerParams {\n viewManager: ViewManager;\n imodel: IModelConnection;\n categories: CategoryInfo[];\n activeView: Viewport;\n allViewports?: boolean;\n}\n\n/**\n * An [[IVisibilityHandler]] implementation that knows how to determine and change visibility of categories\n * and subcategories.\n * @public\n */\nexport class CategoryVisibilityHandler implements IVisibilityHandler {\n private _viewManager: ViewManager;\n private _imodel: IModelConnection;\n private _pendingVisibilityChange: any | undefined;\n private _activeView: Viewport;\n private _useAllViewports: boolean;\n private _categories: CategoryInfo[];\n\n constructor(params: CategoryVisibilityHandlerParams) {\n this._viewManager = params.viewManager;\n this._imodel = params.imodel;\n this._activeView = params.activeView;\n // istanbul ignore next\n this._useAllViewports = params.allViewports ?? false;\n this._categories = params.categories;\n this._activeView.onDisplayStyleChanged.addListener(this.onDisplayStyleChanged);\n this._activeView.onViewedCategoriesChanged.addListener(this.onViewedCategoriesChanged);\n }\n\n public dispose() {\n this._activeView.onDisplayStyleChanged.removeListener(this.onDisplayStyleChanged);\n this._activeView.onViewedCategoriesChanged.removeListener(this.onViewedCategoriesChanged);\n clearTimeout(this._pendingVisibilityChange);\n }\n\n public onVisibilityChange = new BeEvent<VisibilityChangeListener>();\n\n public getVisibilityStatus(node: TreeNodeItem,): VisibilityStatus {\n const nodeKey = isPresentationTreeNodeItem(node) ? node.key : undefined;\n if (!nodeKey)\n return { state: \"hidden\", isDisabled: true };\n\n const instanceId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);\n return { state: node.parentId ? this.getSubCategoryVisibility(instanceId) : this.getCategoryVisibility(instanceId) };\n }\n\n public async changeVisibility(node: TreeNodeItem, shouldDisplay: boolean): Promise<void> {\n const nodeKey = isPresentationTreeNodeItem(node) ? node.key : undefined;\n if (!nodeKey)\n return;\n\n // handle subcategory visibility change\n if (node.parentId) {\n const childId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);\n // istanbul ignore next\n const parentId = this.getParent(childId)?.categoryId;\n\n // make sure parent category is enabled\n if (shouldDisplay && parentId)\n await this.enableCategory([parentId], true, false);\n\n this.enableSubCategory(childId, shouldDisplay);\n return;\n }\n\n const instanceId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);\n await this.enableCategory([instanceId], shouldDisplay, true);\n }\n\n public getSubCategoryVisibility(id: string) {\n const parentItem = this.getParent(id);\n if (!parentItem)\n return \"hidden\";\n\n const isVisible = this._activeView.view.viewsCategory(parentItem.categoryId) && this._activeView.isSubCategoryVisible(id);\n return isVisible ? \"visible\" : \"hidden\";\n }\n\n public getCategoryVisibility(id: string) {\n return this._activeView.view.viewsCategory(id) ? \"visible\" : \"hidden\";\n }\n\n public getParent(key: string): CategoryInfo | undefined {\n for (const category of this._categories) {\n // istanbul ignore else\n if (category.subCategoryIds) {\n if (category.subCategoryIds.indexOf(key) !== -1)\n return category;\n }\n }\n\n return undefined;\n }\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n private onDisplayStyleChanged = () => {\n this.onVisibilityChangeInternal();\n };\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n private onViewedCategoriesChanged = () => {\n this.onVisibilityChangeInternal();\n };\n\n private onVisibilityChangeInternal() {\n if (this._pendingVisibilityChange)\n return;\n\n this._pendingVisibilityChange = setTimeout(() => {\n this.onVisibilityChange.raiseEvent();\n this._pendingVisibilityChange = undefined;\n }, 0);\n }\n\n public static getInstanceIdFromTreeNodeKey(nodeKey: NodeKey) {\n return (NodeKey.isInstancesNodeKey(nodeKey) && nodeKey.instanceKeys.length > 0) ? nodeKey.instanceKeys[0].id : /* istanbul ignore next */ \"\";\n }\n\n public async enableCategory(ids: string[], enabled: boolean, enableAllSubCategories = true) {\n await enableCategory(this._viewManager, this._imodel, ids, enabled, this._useAllViewports, enableAllSubCategories);\n }\n\n public enableSubCategory(key: string, enabled: boolean) {\n enableSubCategory(this._viewManager, key, enabled, this._useAllViewports);\n }\n}\n\n/**\n * Enable display of all given categories.\n * @public\n */\nexport async function showAllCategories(categories: string[], viewport: Viewport) {\n await enableCategory(\n IModelApp.viewManager,\n viewport.iModel,\n categories,\n true,\n true\n );\n}\n\n/**\n * Disable display of all given categories.\n * @public\n */\nexport async function hideAllCategories(categories: string[], viewport: Viewport) {\n await enableCategory(\n IModelApp.viewManager,\n viewport.iModel,\n categories,\n false,\n true\n );\n}\n\n/**\n * Invert display of all given categories.\n * @public\n */\nexport async function invertAllCategories(categories: CategoryInfo[], viewport: Viewport) {\n const enabled: string[] = [];\n const disabled: string[] = [];\n const enabledSubCategories: string[] = [];\n const disabledSubCategories: string[] = [];\n\n for (const category of categories) {\n if (!viewport.view.viewsCategory(category.categoryId)) {\n disabled.push(category.categoryId);\n continue;\n }\n // First, we need to check if at least one subcategory is disabled. If it is true, then only subcategories should change display, not categories.\n if (category.subCategoryIds?.some((subCategory) => !viewport.isSubCategoryVisible(subCategory))) {\n for (const subCategory of category.subCategoryIds)\n viewport.isSubCategoryVisible(subCategory) ? enabledSubCategories.push(subCategory) : disabledSubCategories.push(subCategory);\n } else {\n enabled.push(category.categoryId);\n }\n }\n\n // Disable enabled\n enabledSubCategories.forEach((subCategory) => enableSubCategory(\n IModelApp.viewManager,\n subCategory,\n false,\n true\n ));\n\n await enableCategory(\n IModelApp.viewManager,\n viewport.iModel,\n enabled,\n false,\n true\n );\n\n // Enable disabled\n disabledSubCategories.forEach((subCategory) => enableSubCategory(\n IModelApp.viewManager,\n subCategory,\n true,\n true\n ));\n\n await enableCategory(\n IModelApp.viewManager,\n viewport.iModel,\n disabled,\n true,\n true\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CategoryVisibilityHandler.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoryVisibilityHandler.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,iCAAgC;AAChC,8DAAwD;AACxD,sDAA8C;AAC9C,wDAAiD;AACjD,oEAAqD;AACrD,4EAA4E;AAC5E,4EAA6G;AAM7G,MAAM,sBAAsB,GAAmB,EAAE,CAAC;AAElD;;;GAGG;AACH,SAAgB,aAAa,CAAC,WAAwB,EAAE,MAAwB,EAAE,IAAe;IAC/F,MAAM,WAAW,GAAG,IAAI,IAAI,WAAW,CAAC,gBAAgB,EAAE,CAAC;IAC3D,MAAM,iBAAiB,GAAG,IAAA,eAAO,EAAC,KAAK,IAAI,EAAE,CAAC,IAAA,sDAA0B,EAAC,MAAM,EAAE,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IACtH,OAAO,IAAA,gCAAa,EAAC,iBAAiB,CAAC,IAAI,sBAAsB,CAAC;AACpE,CAAC;AAJD,sCAIC;AAuBD;;;;GAIG;AACH,MAAa,yBAAyB;IAQpC,YAAY,MAAuC;QAiB5C,uBAAkB,GAAG,IAAI,sBAAO,EAA4B,CAAC;QA8DpE,gEAAgE;QACxD,0BAAqB,GAAG,GAAG,EAAE;YACnC,IAAI,CAAC,0BAA0B,EAAE,CAAC;QACpC,CAAC,CAAC;QAEF,gEAAgE;QACxD,8BAAyB,GAAG,GAAG,EAAE;YACvC,IAAI,CAAC,0BAA0B,EAAE,CAAC;QACpC,CAAC,CAAC;QAtFA,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC;QACrC,uBAAuB;QACvB,IAAI,CAAC,gB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CAAC,CAAC;aAC/H;SACF;aAAM;YACL,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;SACnC;KACF;IAED,kBAAkB;IAClB,oBAAoB,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,IAAA,6CAAiB,EAAC,yBAAS,CAAC,WAAW,EAAE,WAAW,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;IAElH,MAAM,IAAA,0CAAc,EAAC,yBAAS,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAEnF,kBAAkB;IAClB,qBAAqB,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,IAAA,6CAAiB,EAAC,yBAAS,CAAC,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IAElH,MAAM,IAAA,0CAAc,EAAC,yBAAS,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AACrF,CAAC;AA9BD,kDA8BC","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 { useMemo } from \"react\";\nimport { useAsyncValue } from \"@itwin/components-react\";\nimport { BeEvent } from \"@itwin/core-bentley\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { NodeKey } from \"@itwin/presentation-common\";\nimport { isPresentationTreeNodeItem } from \"@itwin/presentation-components\";\nimport { enableCategory, enableSubCategory, loadCategoriesFromViewport } from \"../CategoriesVisibilityUtils\";\n\nimport type { TreeNodeItem } from \"@itwin/components-react\";\nimport type { IModelConnection, ViewManager, Viewport } from \"@itwin/core-frontend\";\nimport type { IVisibilityHandler, VisibilityChangeListener, VisibilityStatus } from \"../VisibilityTreeEventHandler\";\n\nconst EMPTY_CATEGORIES_ARRAY: CategoryInfo[] = [];\n\n/**\n * Loads categories from viewport or uses provided list of categories.\n * @internal\n */\nexport function useCategories(viewManager: ViewManager, imodel: IModelConnection, view?: Viewport) {\n const currentView = view || viewManager.getFirstOpenView();\n const categoriesPromise = useMemo(async () => loadCategoriesFromViewport(imodel, currentView), [imodel, currentView]);\n return useAsyncValue(categoriesPromise) ?? EMPTY_CATEGORIES_ARRAY;\n}\n\n/**\n * Data structure that describes category.\n * @public\n */\nexport interface CategoryInfo {\n categoryId: string;\n subCategoryIds?: string[];\n}\n\n/**\n * Params for creating a [[CategoryVisibilityHandler]].\n * @public\n */\nexport interface CategoryVisibilityHandlerParams {\n viewManager: ViewManager;\n imodel: IModelConnection;\n categories: CategoryInfo[];\n activeView: Viewport;\n allViewports?: boolean;\n}\n\n/**\n * An [[IVisibilityHandler]] implementation that knows how to determine and change visibility of categories\n * and subcategories.\n * @public\n */\nexport class CategoryVisibilityHandler implements IVisibilityHandler {\n private _viewManager: ViewManager;\n private _imodel: IModelConnection;\n private _pendingVisibilityChange: any | undefined;\n private _activeView: Viewport;\n private _useAllViewports: boolean;\n private _categories: CategoryInfo[];\n\n constructor(params: CategoryVisibilityHandlerParams) {\n this._viewManager = params.viewManager;\n this._imodel = params.imodel;\n this._activeView = params.activeView;\n // istanbul ignore next\n this._useAllViewports = params.allViewports ?? false;\n this._categories = params.categories;\n this._activeView.onDisplayStyleChanged.addListener(this.onDisplayStyleChanged);\n this._activeView.onViewedCategoriesChanged.addListener(this.onViewedCategoriesChanged);\n }\n\n public dispose() {\n this._activeView.onDisplayStyleChanged.removeListener(this.onDisplayStyleChanged);\n this._activeView.onViewedCategoriesChanged.removeListener(this.onViewedCategoriesChanged);\n clearTimeout(this._pendingVisibilityChange);\n }\n\n public onVisibilityChange = new BeEvent<VisibilityChangeListener>();\n\n public getVisibilityStatus(node: TreeNodeItem): VisibilityStatus {\n const nodeKey = isPresentationTreeNodeItem(node) ? node.key : undefined;\n if (!nodeKey) {\n return { state: \"hidden\", isDisabled: true };\n }\n\n const instanceId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);\n return { state: node.parentId ? this.getSubCategoryVisibility(instanceId) : this.getCategoryVisibility(instanceId) };\n }\n\n public async changeVisibility(node: TreeNodeItem, shouldDisplay: boolean): Promise<void> {\n const nodeKey = isPresentationTreeNodeItem(node) ? node.key : undefined;\n if (!nodeKey) {\n return;\n }\n\n // handle subcategory visibility change\n if (node.parentId) {\n const childId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);\n // istanbul ignore next\n const parentId = this.getParent(childId)?.categoryId;\n\n // make sure parent category is enabled\n if (shouldDisplay && parentId) {\n await this.enableCategory([parentId], true, false);\n }\n\n this.enableSubCategory(childId, shouldDisplay);\n return;\n }\n\n const instanceId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);\n await this.enableCategory([instanceId], shouldDisplay, true);\n }\n\n public getSubCategoryVisibility(id: string) {\n const parentItem = this.getParent(id);\n if (!parentItem) {\n return \"hidden\";\n }\n\n const isVisible = this._activeView.view.viewsCategory(parentItem.categoryId) && this._activeView.isSubCategoryVisible(id);\n return isVisible ? \"visible\" : \"hidden\";\n }\n\n public getCategoryVisibility(id: string) {\n return this._activeView.view.viewsCategory(id) ? \"visible\" : \"hidden\";\n }\n\n public getParent(key: string): CategoryInfo | undefined {\n for (const category of this._categories) {\n // istanbul ignore else\n if (category.subCategoryIds && category.subCategoryIds.indexOf(key) !== -1) {\n return category;\n }\n }\n\n return undefined;\n }\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n private onDisplayStyleChanged = () => {\n this.onVisibilityChangeInternal();\n };\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n private onViewedCategoriesChanged = () => {\n this.onVisibilityChangeInternal();\n };\n\n private onVisibilityChangeInternal() {\n if (this._pendingVisibilityChange) {\n return;\n }\n\n this._pendingVisibilityChange = setTimeout(() => {\n this.onVisibilityChange.raiseEvent();\n this._pendingVisibilityChange = undefined;\n }, 0);\n }\n\n public static getInstanceIdFromTreeNodeKey(nodeKey: NodeKey) {\n return NodeKey.isInstancesNodeKey(nodeKey) && nodeKey.instanceKeys.length > 0 ? nodeKey.instanceKeys[0].id : /* istanbul ignore next */ \"\";\n }\n\n public async enableCategory(ids: string[], enabled: boolean, enableAllSubCategories = true) {\n await enableCategory(this._viewManager, this._imodel, ids, enabled, this._useAllViewports, enableAllSubCategories);\n }\n\n public enableSubCategory(key: string, enabled: boolean) {\n enableSubCategory(this._viewManager, key, enabled, this._useAllViewports);\n }\n}\n\n/**\n * Enable display of all given categories.\n * @public\n */\nexport async function showAllCategories(categories: string[], viewport: Viewport) {\n await enableCategory(IModelApp.viewManager, viewport.iModel, categories, true, true);\n}\n\n/**\n * Disable display of all given categories.\n * @public\n */\nexport async function hideAllCategories(categories: string[], viewport: Viewport) {\n await enableCategory(IModelApp.viewManager, viewport.iModel, categories, false, true);\n}\n\n/**\n * Invert display of all given categories.\n * @public\n */\nexport async function invertAllCategories(categories: CategoryInfo[], viewport: Viewport) {\n const enabled: string[] = [];\n const disabled: string[] = [];\n const enabledSubCategories: string[] = [];\n const disabledSubCategories: string[] = [];\n\n for (const category of categories) {\n if (!viewport.view.viewsCategory(category.categoryId)) {\n disabled.push(category.categoryId);\n continue;\n }\n // First, we need to check if at least one subcategory is disabled. If it is true, then only subcategories should change display, not categories.\n if (category.subCategoryIds?.some((subCategory) => !viewport.isSubCategoryVisible(subCategory))) {\n for (const subCategory of category.subCategoryIds) {\n viewport.isSubCategoryVisible(subCategory) ? enabledSubCategories.push(subCategory) : disabledSubCategories.push(subCategory);\n }\n } else {\n enabled.push(category.categoryId);\n }\n }\n\n // Disable enabled\n enabledSubCategories.forEach((subCategory) => enableSubCategory(IModelApp.viewManager, subCategory, false, true));\n\n await enableCategory(IModelApp.viewManager, viewport.iModel, enabled, false, true);\n\n // Enable disabled\n disabledSubCategories.forEach((subCategory) => enableSubCategory(IModelApp.viewManager, subCategory, true, true));\n\n await enableCategory(IModelApp.viewManager, viewport.iModel, disabled, true, true);\n}\n"]}
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useContextMenu = exports.TreeContextMenuItem = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
/*---------------------------------------------------------------------------------------------
|
|
6
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
7
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
8
|
-
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
7
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
8
|
+
*--------------------------------------------------------------------------------------------*/
|
|
9
9
|
const react_1 = require("react");
|
|
10
10
|
const core_react_1 = require("@itwin/core-react");
|
|
11
11
|
/**
|
|
@@ -13,7 +13,7 @@ const core_react_1 = require("@itwin/core-react");
|
|
|
13
13
|
* @public
|
|
14
14
|
*/
|
|
15
15
|
function TreeContextMenuItem({ id, children, title, onSelect }) {
|
|
16
|
-
return (0, jsx_runtime_1.jsx)(core_react_1.ContextMenuItem, { onSelect: onSelect, title: title, children: children }, id);
|
|
16
|
+
return ((0, jsx_runtime_1.jsx)(core_react_1.ContextMenuItem, { onSelect: onSelect, title: title, children: children }, id));
|
|
17
17
|
}
|
|
18
18
|
exports.TreeContextMenuItem = TreeContextMenuItem;
|
|
19
19
|
/** @internal */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextMenu.js","sourceRoot":"","sources":["../../../../../src/components/trees/common/ContextMenu.tsx"],"names":[],"mappings":";;;;AAAA
|
|
1
|
+
{"version":3,"file":"ContextMenu.js","sourceRoot":"","sources":["../../../../../src/components/trees/common/ContextMenu.tsx"],"names":[],"mappings":";;;;AAAA;;;gGAGgG;AAEhG,iCAA2C;AAC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ACZ,QAAQ,EAAE,KAAK,YAEd,WAAW,CAAC,KAAK,GACA,CACrB,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO;QACL,aAAa;QACb,iBAAiB;KAClB,CAAC;AACJ,CAAC;AAvCD,wCAuCC","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 { Fragment, useState } from \"react\";\nimport { ContextMenuItem, GlobalContextMenu } from \"@itwin/core-react\";\n\nimport type { MouseEvent, PropsWithChildren, ReactNode } from \"react\";\nimport type { TreeModelNode } from \"@itwin/components-react\";\n\n/**\n * Props for single context menu item.\n * @public\n */\nexport interface ContextMenuItemProps {\n node: TreeModelNode;\n}\n\n/**\n * Props for configuring tree context menu.\n * @public\n */\nexport interface TreeContextMenuProps {\n contextMenuItems?: Array<(props: ContextMenuItemProps) => ReactNode>;\n}\n\n/**\n * Props for [[TreeContextMenuItem]] component.\n * @public\n */\nexport interface TreeContextMenuItemProps {\n /** Unique id of the context menu item. */\n id: string;\n /** Description of the context menu item. */\n title?: string;\n /** Callback that is invoked when context menu item is clicked. */\n onSelect: () => void;\n}\n\n/**\n * Base component for rendering single context menu item.\n * @public\n */\nexport function TreeContextMenuItem({ id, children, title, onSelect }: PropsWithChildren<TreeContextMenuItemProps>) {\n return (\n <ContextMenuItem key={id} onSelect={onSelect} title={title}>\n {children}\n </ContextMenuItem>\n );\n}\n\ninterface ContextMenu {\n items: ReactNode[];\n position: { x: number; y: number };\n}\n\n/** @internal */\nexport function useContextMenu({ contextMenuItems }: TreeContextMenuProps) {\n const [contextMenu, setContextMenu] = useState<ContextMenu>();\n const close = () => setContextMenu(undefined);\n\n const onContextMenu = (e: MouseEvent, node: TreeModelNode) => {\n if (!contextMenuItems) {\n return;\n }\n\n setContextMenu({\n items: contextMenuItems.map((item, index) => <Fragment key={index}>{item({ node })}</Fragment>),\n position: { x: e.clientX, y: e.clientY },\n });\n };\n\n const renderContextMenu = () => {\n if (!contextMenu) {\n return null;\n }\n\n return (\n <GlobalContextMenu\n identifier=\"tree-widget-context-menu\"\n x={contextMenu.position.x}\n y={contextMenu.position.y}\n opened={true}\n onOutsideClick={close}\n onEsc={close}\n onSelect={close}\n >\n {contextMenu.items}\n </GlobalContextMenu>\n );\n };\n\n return {\n onContextMenu,\n renderContextMenu,\n };\n}\n"]}
|
|
@@ -43,7 +43,7 @@ export interface DefaultLabelRendererProps {
|
|
|
43
43
|
* Renders label for tree node.
|
|
44
44
|
* @public
|
|
45
45
|
*/
|
|
46
|
-
export declare function DefaultLabelRenderer({ label, context }: DefaultLabelRendererProps): JSX.Element;
|
|
46
|
+
export declare function DefaultLabelRenderer({ label, context }: DefaultLabelRendererProps): React.JSX.Element;
|
|
47
47
|
/** @internal */
|
|
48
48
|
export interface TreeNodeRendererContextProviderProps extends TreeNodeRendererProps {
|
|
49
49
|
node: TreeModelNode;
|
|
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TreeNodeLabelRenderer = exports.TREE_NODE_LABEL_RENDERER = exports.TreeNodeRendererContextProvider = exports.DefaultLabelRenderer = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
/*---------------------------------------------------------------------------------------------
|
|
6
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
7
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
8
|
-
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
7
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
8
|
+
*--------------------------------------------------------------------------------------------*/
|
|
9
9
|
const react_1 = require("react");
|
|
10
10
|
const components_react_1 = require("@itwin/components-react");
|
|
11
11
|
/**
|
|
@@ -19,7 +19,7 @@ function DefaultLabelRenderer({ label, context }) {
|
|
|
19
19
|
exports.DefaultLabelRenderer = DefaultLabelRenderer;
|
|
20
20
|
/** @internal */
|
|
21
21
|
function TreeNodeRendererContextProvider({ nodeLabelRenderer, node, children }) {
|
|
22
|
-
return (
|
|
22
|
+
return (0, jsx_runtime_1.jsx)(treeNodeLabelRendererContext.Provider, { value: { renderer: nodeLabelRenderer, node }, children: children });
|
|
23
23
|
}
|
|
24
24
|
exports.TreeNodeRendererContextProvider = TreeNodeRendererContextProvider;
|
|
25
25
|
/** @internal */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeNodeRenderer.js","sourceRoot":"","sources":["../../../../../src/components/trees/common/TreeNodeRenderer.tsx"],"names":[],"mappings":";;;;AAAA
|
|
1
|
+
{"version":3,"file":"TreeNodeRenderer.js","sourceRoot":"","sources":["../../../../../src/components/trees/common/TreeNodeRenderer.tsx"],"names":[],"mappings":";;;;AAAA;;;gGAGgG;AAEhG,iCAAkD;AAClD,8DAAyE;AAgDzE;;;GAGG;AACH,SAAgB,oBAAoB,CAAC,EAAE,KAAK,EAAE,OAAO,EAA6B;IAChF,MAAM,QAAQ,GAAG,IAAI,iDAA8B,EAAE,CAAC;IACtD,OAAO,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC;AAHD,oDAGC;AAQD,gBAAgB;AAChB,SAAgB,+BAA+B,CAAC,EAAE,iBAAiB,EAAE,IAAI,EAAE,QAAQ,EAAwC;IACzH,OAAO,uBAAC,4BAA4B,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,iBAAiB,EAAE,IAAI,EAAE,YAAG,QAAQ,GAAyC,CAAC;AACjJ,CAAC;AAFD,0EAEC;AAED,gBAAgB;AACH,QAAA,wBAAwB,GAAG,4BAA4B,CAAC;AAErE,gBAAgB;AAChB,MAAa,qBAAqB;IACzB,SAAS,CAAC,MAAsB,EAAE,QAAmD;QAC1F,OAAO,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,IAAI,KAAK,gCAAwB,CAAC;IACrE,CAAC;IAEM,MAAM,CAAC,MAAsB,EAAE,OAAkD;QACtF,MAAM,YAAY,GAAyB;YACzC,KAAK,EAAE,OAAO,EAAE,KAAK;YACrB,eAAe,EAAE,OAAO,EAAE,eAAe;SAC1C,CAAC;QACF,OAAO,uBAAC,aAAa,IAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAI,CAAC;IAClE,CAAC;CACF;AAZD,sDAYC;AAOD,MAAM,4BAA4B,GAAG,IAAA,qBAAa,EAA2C,SAAS,CAAC,CAAC;AAOxG,SAAS,aAAa,CAAC,EAAE,MAAM,EAAE,OAAO,EAAsB;IAC5D,MAAM,aAAa,GAAG,IAAA,kBAAU,EAAC,4BAA4B,CAAC,CAAC;IAE/D,IAAI,CAAC,aAAa,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;QAC7C,OAAO,uBAAC,oBAAoB,IAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAI,CAAC;KAClE;IAED,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,aAAa,CAAC;IACzC,OAAO,2DAAG,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,GAAI,CAAC;AAC5C,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 { createContext, useContext } from \"react\";\nimport { PrimitivePropertyValueRenderer } from \"@itwin/components-react\";\n\nimport type { ReactNode } from \"react\";\nimport type { PropertyRecord } from \"@itwin/appui-abstract\";\nimport type { IPropertyValueRenderer, PropertyValueRendererContext, TreeModelNode } from \"@itwin/components-react\";\n\n/**\n * Context for rendering label value.\n * @public\n */\nexport interface LabelRendererContext {\n /** Style that should be applied to the rendered element. */\n style?: React.CSSProperties;\n /** Callback to highlight text. */\n textHighlighter?: (text: string) => React.ReactNode;\n}\n\n/**\n * Props for custom node renderer.\n * @public\n */\nexport interface TreeNodeLabelRendererProps {\n /** Tree node to rendered label for. */\n node: TreeModelNode;\n /** Context for rendering node's label value. */\n context?: LabelRendererContext;\n}\n\n/**\n * Props for customizing node rendering.\n * @public\n */\nexport interface TreeNodeRendererProps {\n /** Custom renderer for node's label. */\n nodeLabelRenderer?: (props: TreeNodeLabelRendererProps) => ReactNode;\n}\n\n/**\n * Props for [[DefaultLabelRenderer]] component.\n * @public\n */\nexport interface DefaultLabelRendererProps {\n /** Label that should be rendered. */\n label: PropertyRecord;\n /** Context for rendering label value. */\n context?: LabelRendererContext;\n}\n\n/**\n * Renders label for tree node.\n * @public\n */\nexport function DefaultLabelRenderer({ label, context }: DefaultLabelRendererProps) {\n const renderer = new PrimitivePropertyValueRenderer();\n return renderer.render(label, context);\n}\n\n/** @internal */\nexport interface TreeNodeRendererContextProviderProps extends TreeNodeRendererProps {\n node: TreeModelNode;\n children: ReactNode;\n}\n\n/** @internal */\nexport function TreeNodeRendererContextProvider({ nodeLabelRenderer, node, children }: TreeNodeRendererContextProviderProps) {\n return <treeNodeLabelRendererContext.Provider value={{ renderer: nodeLabelRenderer, node }}>{children}</treeNodeLabelRendererContext.Provider>;\n}\n\n/** @internal */\nexport const TREE_NODE_LABEL_RENDERER = \"visibility-tree-node-label\";\n\n/** @internal */\nexport class TreeNodeLabelRenderer implements IPropertyValueRenderer {\n public canRender(record: PropertyRecord, _context?: PropertyValueRendererContext | undefined): boolean {\n return record.property.renderer?.name === TREE_NODE_LABEL_RENDERER;\n }\n\n public render(record: PropertyRecord, context?: PropertyValueRendererContext | undefined): ReactNode {\n const labelContext: LabelRendererContext = {\n style: context?.style,\n textHighlighter: context?.textHighlighter,\n };\n return <LabelRenderer record={record} context={labelContext} />;\n }\n}\n\ninterface TreeNodeLabelRendererContext {\n renderer?: (props: TreeNodeLabelRendererProps) => ReactNode;\n node: TreeModelNode;\n}\n\nconst treeNodeLabelRendererContext = createContext<TreeNodeLabelRendererContext | undefined>(undefined);\n\ninterface LabelRendererProps {\n record: PropertyRecord;\n context?: LabelRendererContext;\n}\n\nfunction LabelRenderer({ record, context }: LabelRendererProps) {\n const renderContext = useContext(treeNodeLabelRendererContext);\n\n if (!renderContext || !renderContext.renderer) {\n return <DefaultLabelRenderer label={record} context={context} />;\n }\n\n const { renderer, node } = renderContext;\n return <>{renderer({ node, context })}</>;\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import "./TreeRenderer.scss";
|
|
3
|
-
import type {
|
|
3
|
+
import type { IPresentationTreeDataProvider, PresentationTreeNodeRendererProps } from "@itwin/presentation-components";
|
|
4
|
+
import type { AbstractTreeNodeLoaderWithProvider, TreeRendererProps as ComponentsTreeRendererProps } from "@itwin/components-react";
|
|
4
5
|
import type { TreeNodeRendererProps } from "./TreeNodeRenderer";
|
|
5
6
|
import type { TreeContextMenuProps } from "./ContextMenu";
|
|
6
7
|
/**
|
|
@@ -23,4 +24,17 @@ export type TreeRendererProps = ComponentsTreeRendererProps & TreeRendererBasePr
|
|
|
23
24
|
* @public
|
|
24
25
|
*/
|
|
25
26
|
export declare function TreeRenderer({ contextMenuItems, nodeRenderer, nodeLabelRenderer, density, ...restProps }: TreeRendererProps): JSX.Element;
|
|
27
|
+
/**
|
|
28
|
+
* Props for [[FilterableTreeRenderer]] component.
|
|
29
|
+
* @beta
|
|
30
|
+
*/
|
|
31
|
+
export interface FilterableTreeRendererProps extends Omit<TreeRendererProps, "nodeLoader" | "nodeRenderer"> {
|
|
32
|
+
nodeLoader: AbstractTreeNodeLoaderWithProvider<IPresentationTreeDataProvider>;
|
|
33
|
+
nodeRenderer: (props: PresentationTreeNodeRendererProps) => React.ReactNode;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Base tree renderer for trees with enabled hierarchy level filtering.
|
|
37
|
+
* @beta
|
|
38
|
+
*/
|
|
39
|
+
export declare function FilterableTreeRenderer({ nodeRenderer, nodeLoader, ...restProps }: FilterableTreeRendererProps): JSX.Element;
|
|
26
40
|
//# sourceMappingURL=TreeRenderer.d.ts.map
|
|
@@ -3,15 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.TreeRenderer = void 0;
|
|
6
|
+
exports.FilterableTreeRenderer = exports.TreeRenderer = void 0;
|
|
7
7
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
8
|
/*---------------------------------------------------------------------------------------------
|
|
9
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
10
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
11
|
-
*--------------------------------------------------------------------------------------------*/
|
|
9
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
10
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
11
|
+
*--------------------------------------------------------------------------------------------*/
|
|
12
12
|
require("./TreeRenderer.scss");
|
|
13
13
|
const classnames_1 = __importDefault(require("classnames"));
|
|
14
14
|
const components_react_1 = require("@itwin/components-react");
|
|
15
|
+
const presentation_components_1 = require("@itwin/presentation-components");
|
|
15
16
|
const ContextMenu_1 = require("./ContextMenu");
|
|
16
17
|
const TreeNodeRenderer_1 = require("./TreeNodeRenderer");
|
|
17
18
|
/**
|
|
@@ -24,12 +25,21 @@ function TreeRenderer({ contextMenuItems, nodeRenderer, nodeLabelRenderer, densi
|
|
|
24
25
|
const className = (0, classnames_1.default)("tree-widget-tree-nodes-list", { ["enlarge"]: density === "enlarged" });
|
|
25
26
|
return ((0, jsx_runtime_1.jsxs)("div", { className: className, children: [(0, jsx_runtime_1.jsx)(components_react_1.TreeRenderer, { ...restProps, nodeRenderer: (nodeProps) => {
|
|
26
27
|
const nodeClassName = nodeProps.node.numChildren === 0 ? "without-expander" : undefined;
|
|
27
|
-
return ((0, jsx_runtime_1.jsx)(TreeNodeRenderer_1.TreeNodeRendererContextProvider, { node: nodeProps.node, nodeLabelRenderer: nodeLabelRenderer, children: nodeRenderer
|
|
28
|
-
? nodeRenderer({ ...nodeProps, onContextMenu, className: nodeClassName })
|
|
29
|
-
: (0, jsx_runtime_1.jsx)(components_react_1.TreeNodeRenderer, { ...nodeProps, onContextMenu: onContextMenu, className: nodeClassName }) }));
|
|
28
|
+
return ((0, jsx_runtime_1.jsx)(TreeNodeRenderer_1.TreeNodeRendererContextProvider, { node: nodeProps.node, nodeLabelRenderer: nodeLabelRenderer, children: nodeRenderer ? (nodeRenderer({ ...nodeProps, onContextMenu, className: nodeClassName })) : ((0, jsx_runtime_1.jsx)(components_react_1.TreeNodeRenderer, { ...nodeProps, onContextMenu: onContextMenu, className: nodeClassName })) }));
|
|
30
29
|
}, nodeHeight: nodeHeight }), renderContextMenu()] }));
|
|
31
30
|
}
|
|
32
31
|
exports.TreeRenderer = TreeRenderer;
|
|
32
|
+
/**
|
|
33
|
+
* Base tree renderer for trees with enabled hierarchy level filtering.
|
|
34
|
+
* @beta
|
|
35
|
+
*/
|
|
36
|
+
function FilterableTreeRenderer({ nodeRenderer, nodeLoader, ...restProps }) {
|
|
37
|
+
const { onClearFilterClick, onFilterClick, filterDialog } = (0, presentation_components_1.useFilterablePresentationTree)({ nodeLoader });
|
|
38
|
+
return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(TreeRenderer, { ...restProps, nodeLoader: nodeLoader, nodeRenderer: (props) => {
|
|
39
|
+
return nodeRenderer({ ...props, onClearFilterClick, onFilterClick });
|
|
40
|
+
} }), filterDialog] }));
|
|
41
|
+
}
|
|
42
|
+
exports.FilterableTreeRenderer = FilterableTreeRenderer;
|
|
33
43
|
function getNodeHeight(density, defaultHeight) {
|
|
34
44
|
switch (density) {
|
|
35
45
|
case "default":
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeRenderer.js","sourceRoot":"","sources":["../../../../../src/components/trees/common/TreeRenderer.tsx"],"names":[],"mappings":";;;;;;;AAAA
|
|
1
|
+
{"version":3,"file":"TreeRenderer.js","sourceRoot":"","sources":["../../../../../src/components/trees/common/TreeRenderer.tsx"],"names":[],"mappings":";;;;;;;AAAA;;;gGAGgG;AAEhG,+BAA6B;AAC7B,4DAAoC;AACpC,8DAAmG;AACnG,4EAA+E;AAC/E,+CAA+C;AAC/C,yDAAqE;AAuBrE;;;GAGG;AACH,SAAgB,YAAY,CAAC,EAAE,gBAAgB,EAAE,YAAY,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG,SAAS,EAAqB;IAC1H,MAAM,EAAE,aAAa,EAAE,iBAAiB,EAAE,GAAG,IAAA,4BAAc,EAAC,EAAE,gBAAgB,EAAE,CAAC,CAAC;IAElF,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,IAAI,SAAS,EAAE,SAAS,CAAC,UAAU,CAAC,CAAC;IAC7E,MAAM,SAAS,GAAG,IAAA,oBAAU,EAAC,6BAA6B,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,OAAO,KAAK,UAAU,EAAE,CAAC,CAAC;IAErG,OAAO,CACL,iCAAK,SAAS,EAAE,SAAS,aACvB,uBAAC,+BAAsB,OACjB,SAAS,EACb,YAAY,EAAE,CAAC,SAAS,EAAE,EAAE;oBAC1B,MAAM,aAAa,GAAG,SAAS,CAAC,IAAI,CAAC,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,SAAS,CAAC;oBACxF,OAAO,CACL,uBAAC,kDAA+B,IAAC,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,iBAAiB,EAAE,iBAAiB,YACxF,YAAY,CAAC,CAAC,CAAC,CACd,YAAY,CAAC,EAAE,GAAG,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC,CACxE,CAAC,CAAC,CAAC,CACF,uBAAC,mCAAgB,OAAK,SAAS,EAAE,aAAa,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,GAAI,CAC5F,GAC+B,CACnC,CAAC;gBACJ,CAAC,EACD,UAAU,EAAE,UAAU,GACtB,EACD,iBAAiB,EAAE,IAChB,CACP,CAAC;AACJ,CAAC;AA3BD,oCA2BC;AAUD;;;GAGG;AACH,SAAgB,sBAAsB,CAAC,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,SAAS,EAA+B;IAC5G,MAAM,EAAE,kBAAkB,EAAE,aAAa,EAAE,YAAY,EAAE,GAAG,IAAA,uDAA6B,EAAC,EAAE,UAAU,EAAE,CAAC,CAAC;IAE1G,OAAO,CACL,4CACE,uBAAC,YAAY,OACP,SAAS,EACb,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,CAAC,KAAK,EAAE,EAAE;oBACtB,OAAO,YAAY,CAAC,EAAE,GAAG,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,CAAC,CAAC;gBACvE,CAAC,GACD,EACD,YAAY,IACT,CACP,CAAC;AACJ,CAAC;AAfD,wDAeC;AAED,SAAS,aAAa,CAAC,OAA+B,EAAE,aAAwD;IAC9G,QAAQ,OAAO,EAAE;QACf,KAAK,SAAS;YACZ,OAAO,aAAa,CAAC;QACvB,KAAK,UAAU;YACb,OAAO,GAAG,EAAE,CAAC,EAAE,CAAC;KACnB;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 \"./TreeRenderer.scss\";\nimport classNames from \"classnames\";\nimport { TreeRenderer as ComponentsTreeRenderer, TreeNodeRenderer } from \"@itwin/components-react\";\nimport { useFilterablePresentationTree } from \"@itwin/presentation-components\";\nimport { useContextMenu } from \"./ContextMenu\";\nimport { TreeNodeRendererContextProvider } from \"./TreeNodeRenderer\";\n\nimport type { IPresentationTreeDataProvider, PresentationTreeNodeRendererProps } from \"@itwin/presentation-components\";\nimport type { AbstractTreeNodeLoaderWithProvider, TreeRendererProps as ComponentsTreeRendererProps } from \"@itwin/components-react\";\nimport type { TreeNodeRendererProps } from \"./TreeNodeRenderer\";\nimport type { TreeContextMenuProps } from \"./ContextMenu\";\n/**\n * Base props for [[TreeRenderer]] component.\n * @public\n */\nexport interface TreeRendererBaseProps extends TreeContextMenuProps, TreeNodeRendererProps {\n /**\n * Modifies the density of tree nodes. `enlarged` tree nodes have bigger height and bigger button hit boxes.\n */\n density?: \"default\" | \"enlarged\";\n}\n\n/**\n * Props for [[TreeRenderer]] component.\n * @public\n */\nexport type TreeRendererProps = ComponentsTreeRendererProps & TreeRendererBaseProps;\n\n/**\n * Base tree renderer for visibility trees.\n * @public\n */\nexport function TreeRenderer({ contextMenuItems, nodeRenderer, nodeLabelRenderer, density, ...restProps }: TreeRendererProps) {\n const { onContextMenu, renderContextMenu } = useContextMenu({ contextMenuItems });\n\n const nodeHeight = getNodeHeight(density ?? \"default\", restProps.nodeHeight);\n const className = classNames(\"tree-widget-tree-nodes-list\", { [\"enlarge\"]: density === \"enlarged\" });\n\n return (\n <div className={className}>\n <ComponentsTreeRenderer\n {...restProps}\n nodeRenderer={(nodeProps) => {\n const nodeClassName = nodeProps.node.numChildren === 0 ? \"without-expander\" : undefined;\n return (\n <TreeNodeRendererContextProvider node={nodeProps.node} nodeLabelRenderer={nodeLabelRenderer}>\n {nodeRenderer ? (\n nodeRenderer({ ...nodeProps, onContextMenu, className: nodeClassName })\n ) : (\n <TreeNodeRenderer {...nodeProps} onContextMenu={onContextMenu} className={nodeClassName} />\n )}\n </TreeNodeRendererContextProvider>\n );\n }}\n nodeHeight={nodeHeight}\n />\n {renderContextMenu()}\n </div>\n );\n}\n\n/**\n * Props for [[FilterableTreeRenderer]] component.\n * @beta\n */\nexport interface FilterableTreeRendererProps extends Omit<TreeRendererProps, \"nodeLoader\" | \"nodeRenderer\"> {\n nodeLoader: AbstractTreeNodeLoaderWithProvider<IPresentationTreeDataProvider>;\n nodeRenderer: (props: PresentationTreeNodeRendererProps) => React.ReactNode;\n}\n/**\n * Base tree renderer for trees with enabled hierarchy level filtering.\n * @beta\n */\nexport function FilterableTreeRenderer({ nodeRenderer, nodeLoader, ...restProps }: FilterableTreeRendererProps) {\n const { onClearFilterClick, onFilterClick, filterDialog } = useFilterablePresentationTree({ nodeLoader });\n\n return (\n <div>\n <TreeRenderer\n {...restProps}\n nodeLoader={nodeLoader}\n nodeRenderer={(props) => {\n return nodeRenderer({ ...props, onClearFilterClick, onFilterClick });\n }}\n />\n {filterDialog}\n </div>\n );\n}\n\nfunction getNodeHeight(density: \"default\" | \"enlarged\", defaultHeight: ComponentsTreeRendererProps[\"nodeHeight\"]) {\n switch (density) {\n case \"default\":\n return defaultHeight;\n case \"enlarged\":\n return () => 43;\n }\n}\n"]}
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
.tree-widget-tree-with-header {
|
|
7
7
|
width: 100%;
|
|
8
8
|
height: 100%;
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-direction: column;
|
|
9
11
|
|
|
10
12
|
.tree-widget-tree-header {
|
|
11
13
|
height: var(--iui-size-xl);
|
|
@@ -13,6 +15,10 @@
|
|
|
13
15
|
|
|
14
16
|
.tree-widget-tree-content {
|
|
15
17
|
height: calc(100% - var(--iui-size-xl));
|
|
18
|
+
|
|
19
|
+
&.enlarge {
|
|
20
|
+
height: calc(100% - var(--iui-size-xl) - var(--iui-size-m));
|
|
21
|
+
}
|
|
16
22
|
}
|
|
17
23
|
}
|
|
18
24
|
|
|
@@ -28,9 +34,15 @@
|
|
|
28
34
|
}
|
|
29
35
|
|
|
30
36
|
.core-tree-node {
|
|
37
|
+
> .contents {
|
|
38
|
+
.core-tree-node-icon {
|
|
39
|
+
line-height: 0;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
31
43
|
&.without-expander {
|
|
32
|
-
|
|
33
|
-
|
|
44
|
+
> .contents {
|
|
45
|
+
> .core-tree-node-icon {
|
|
34
46
|
margin-left: 5px;
|
|
35
47
|
}
|
|
36
48
|
}
|
|
@@ -40,14 +52,39 @@
|
|
|
40
52
|
&.enlarge {
|
|
41
53
|
--enlarged-node-height: calc(var(--iui-size-l) + var(--iui-size-m) + var(--iui-size-3xs));
|
|
42
54
|
--enlarged-node-icon-size: var(--iui-size-m);
|
|
55
|
+
--enlarged-node-without-expander-margin: var(--iui-size-m);
|
|
43
56
|
--enlarged-node-icon-padding: calc(var(--enlarged-node-height) - var(--enlarged-node-icon-size));
|
|
44
57
|
--enlarged-node-expander-additional-padding: calc(var(--iui-size-l) - var(--iui-size-3xs) / 2);
|
|
45
58
|
|
|
46
59
|
.core-tree-node {
|
|
60
|
+
&.without-expander {
|
|
61
|
+
margin-left: var(--enlarged-node-without-expander-margin);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
> .presentation-components-node-action-buttons {
|
|
65
|
+
height: var(--enlarged-node-height);
|
|
66
|
+
width: min-content;
|
|
67
|
+
|
|
68
|
+
.presentation-components-node-action-button {
|
|
69
|
+
height: var(--enlarged-node-height);
|
|
70
|
+
width: var(--enlarged-node-height);
|
|
71
|
+
|
|
72
|
+
svg {
|
|
73
|
+
height: var(--enlarged-node-height);
|
|
74
|
+
width: var(--enlarged-node-height);
|
|
75
|
+
padding: var(--iui-size-s);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
47
80
|
> .contents {
|
|
48
81
|
height: var(--enlarged-node-height);
|
|
49
82
|
font-size: var(--iui-font-size-2);
|
|
50
83
|
|
|
84
|
+
.core-progress-indicator {
|
|
85
|
+
margin: calc(var(--enlarged-node-icon-padding) / 2);
|
|
86
|
+
}
|
|
87
|
+
|
|
51
88
|
/* stylelint-disable-next-line selector-class-pattern */
|
|
52
89
|
.core-tree-expansionToggle {
|
|
53
90
|
> .icon {
|
|
@@ -22,6 +22,14 @@ export interface VisibilityTreeFilterInfo {
|
|
|
22
22
|
filter: string;
|
|
23
23
|
activeMatchIndex?: number;
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Configuration for hierarchy levels. Setting it implies that hierarchy level filtering will be enabled.
|
|
27
|
+
* @beta
|
|
28
|
+
*/
|
|
29
|
+
export interface HierarchyLevelConfig {
|
|
30
|
+
isFilteringEnabled: true;
|
|
31
|
+
sizeLimit?: number;
|
|
32
|
+
}
|
|
25
33
|
/**
|
|
26
34
|
* Base props for tree components.
|
|
27
35
|
* @public
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
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
|
-
*--------------------------------------------------------------------------------------------*/
|
|
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
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.ClassGroupingOption = void 0;
|
|
8
8
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Types.js","sourceRoot":"","sources":["../../../../../src/components/trees/common/Types.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"Types.js","sourceRoot":"","sources":["../../../../../src/components/trees/common/Types.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAOhG;;;GAGG;AACH,IAAY,mBAOX;AAPD,WAAY,mBAAmB;IAC7B,iCAAiC;IACjC,yDAAE,CAAA;IACF,gCAAgC;IAChC,2DAAG,CAAA;IACH,4EAA4E;IAC5E,+EAAa,CAAA;AACf,CAAC,EAPW,mBAAmB,GAAnB,2BAAmB,KAAnB,2BAAmB,QAO9B","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 { IModelConnection } from \"@itwin/core-frontend\";\nimport type { SelectionMode } from \"@itwin/components-react\";\nimport type { IPresentationTreeDataProvider } from \"@itwin/presentation-components\";\nimport type { TreeRendererBaseProps } from \"./TreeRenderer\";\n\n/**\n * An option of how class grouping should work in a component.\n * @public\n */\nexport enum ClassGroupingOption {\n /** Class grouping is disabled */\n No,\n /** Class grouping is enabled */\n Yes,\n /** Class grouping is enabled and grouping node shows grouped items count */\n YesWithCounts,\n}\n\n/**\n * Data structure that describes info used to filter visibility tree.\n * @public\n */\nexport interface VisibilityTreeFilterInfo {\n filter: string;\n activeMatchIndex?: number;\n}\n\n/**\n * Configuration for hierarchy levels. Setting it implies that hierarchy level filtering will be enabled.\n * @beta\n */\nexport interface HierarchyLevelConfig {\n isFilteringEnabled: true;\n sizeLimit?: number;\n}\n\n/**\n * Base props for tree components.\n * @public\n */\nexport interface BaseTreeProps extends TreeRendererBaseProps {\n /** An iModel to pull data from. */\n iModel: IModelConnection;\n /** Width of the component. */\n width: number;\n /** Height of the component. */\n height: number;\n /** Selection mode in the tree. */\n selectionMode?: SelectionMode;\n}\n\n/**\n * Base props for filterable tree components.\n * @public\n */\nexport interface BaseFilterableTreeProps extends BaseTreeProps {\n /** Information for tree filtering. */\n filterInfo?: VisibilityTreeFilterInfo;\n /** Callback invoked when tree is filtered. */\n onFilterApplied?: (filteredDataProvider: IPresentationTreeDataProvider, matchesCount: number) => void;\n}\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { VisibilityTreeEventHandler } from "../VisibilityTreeEventHandler";
|
|
2
|
+
import type { IModelConnection } from "@itwin/core-frontend";
|
|
3
|
+
import type { Ruleset } from "@itwin/presentation-common";
|
|
4
|
+
import type { IFilteredPresentationTreeDataProvider, UsePresentationTreeStateProps } from "@itwin/presentation-components";
|
|
5
|
+
import type { IVisibilityHandler, VisibilityTreeEventHandlerParams, VisibilityTreeSelectionPredicate } from "../VisibilityTreeEventHandler";
|
|
6
|
+
import type { VisibilityTreeFilterInfo } from "./Types";
|
|
7
|
+
/**
|
|
8
|
+
* Props for [[useVisibilityTreeState]] hook.
|
|
9
|
+
* @beta
|
|
10
|
+
*/
|
|
11
|
+
export interface UseVisibilityTreeStateProps extends Omit<UsePresentationTreeStateProps<VisibilityTreeEventHandler>, "rulesetOrId"> {
|
|
12
|
+
/** iModel to pull data from. */
|
|
13
|
+
imodel: IModelConnection;
|
|
14
|
+
/** Presentation rules to use when pulling data from iModel. */
|
|
15
|
+
ruleset: Ruleset;
|
|
16
|
+
/** Visibility handler that will be used to determine tree node visibility or change it. */
|
|
17
|
+
visibilityHandler?: IVisibilityHandler;
|
|
18
|
+
/** Info about filter that should be applied on tree. */
|
|
19
|
+
filterInfo?: VisibilityTreeFilterInfo;
|
|
20
|
+
/** Callback that is invoked when filter is applied, changed or removed. */
|
|
21
|
+
onFilterChange?: (filteredDataProvider?: IFilteredPresentationTreeDataProvider, matchesCount?: number) => void;
|
|
22
|
+
/** Callback that is used to determine if node can be selected. If not provided all nodes are selectable. */
|
|
23
|
+
selectionPredicate?: VisibilityTreeSelectionPredicate;
|
|
24
|
+
/** Factory for custom `VisibilityTreeEventHandler`. Defaults to `VisibilityTreeEventHandler`. */
|
|
25
|
+
eventHandler?: (props: VisibilityTreeEventHandlerParams) => VisibilityTreeEventHandler;
|
|
26
|
+
/** The limit for how many items should be loaded for a single hierarchy level. */
|
|
27
|
+
hierarchyLevelSizeLimit?: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Custom hook for creating visibility tree component state.
|
|
31
|
+
*
|
|
32
|
+
* @returns `undefined` on first render cycle. On all other render cycles state is initialized and valid object is returned.
|
|
33
|
+
* @beta
|
|
34
|
+
*/
|
|
35
|
+
export declare function useVisibilityTreeState({ imodel, ruleset, filterInfo, onFilterChange, visibilityHandler, selectionPredicate, eventHandler, ...props }: UseVisibilityTreeStateProps): import("@itwin/presentation-components").UsePresentationTreeStateResult<VisibilityTreeEventHandler> | undefined;
|
|
36
|
+
//# sourceMappingURL=UseVisibilityTreeState.d.ts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.useVisibilityTreeState = void 0;
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const presentation_components_1 = require("@itwin/presentation-components");
|
|
10
|
+
const VisibilityTreeEventHandler_1 = require("../VisibilityTreeEventHandler");
|
|
11
|
+
/**
|
|
12
|
+
* Custom hook for creating visibility tree component state.
|
|
13
|
+
*
|
|
14
|
+
* @returns `undefined` on first render cycle. On all other render cycles state is initialized and valid object is returned.
|
|
15
|
+
* @beta
|
|
16
|
+
*/
|
|
17
|
+
function useVisibilityTreeState({ imodel, ruleset, filterInfo, onFilterChange, visibilityHandler, selectionPredicate, eventHandler, ...props }) {
|
|
18
|
+
const eventHandlerFactory = (0, react_1.useCallback)((params) => {
|
|
19
|
+
if (!visibilityHandler) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
const eventHandlerProps = {
|
|
23
|
+
nodeLoader: params.nodeLoader,
|
|
24
|
+
visibilityHandler,
|
|
25
|
+
selectionPredicate,
|
|
26
|
+
};
|
|
27
|
+
return eventHandler ? eventHandler(eventHandlerProps) : new VisibilityTreeEventHandler_1.VisibilityTreeEventHandler(eventHandlerProps);
|
|
28
|
+
}, [visibilityHandler, selectionPredicate, eventHandler]);
|
|
29
|
+
const treeState = (0, presentation_components_1.usePresentationTreeState)({
|
|
30
|
+
...props,
|
|
31
|
+
imodel,
|
|
32
|
+
ruleset,
|
|
33
|
+
eventHandlerFactory,
|
|
34
|
+
filteringParams: filterInfo?.filter
|
|
35
|
+
? {
|
|
36
|
+
filter: filterInfo.filter,
|
|
37
|
+
activeMatchIndex: filterInfo?.activeMatchIndex,
|
|
38
|
+
}
|
|
39
|
+
: undefined,
|
|
40
|
+
});
|
|
41
|
+
(0, react_1.useEffect)(() => {
|
|
42
|
+
onFilterChange && onFilterChange(treeState?.filteringResult?.filteredProvider, treeState?.filteringResult?.matchesCount);
|
|
43
|
+
}, [treeState?.filteringResult?.matchesCount, treeState?.filteringResult?.filteredProvider, onFilterChange]);
|
|
44
|
+
return treeState;
|
|
45
|
+
}
|
|
46
|
+
exports.useVisibilityTreeState = useVisibilityTreeState;
|
|
47
|
+
//# sourceMappingURL=UseVisibilityTreeState.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UseVisibilityTreeState.js","sourceRoot":"","sources":["../../../../../src/components/trees/common/UseVisibilityTreeState.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,iCAA+C;AAC/C,4EAA0E;AAC1E,8EAA2E;AA+B3E;;;;;GAKG;AACH,SAAgB,sBAAsB,CAAC,EACrC,MAAM,EACN,OAAO,EACP,UAAU,EACV,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EACZ,GAAG,KAAK,EACoB;IAC5B,MAAM,mBAAmB,GAAG,IAAA,mBAAW,EACrC,CAAC,MAAyC,EAAE,EAAE;QAC5C,IAAI,CAAC,iBAAiB,EAAE;YACtB,OAAO,SAAS,CAAC;SAClB;QAED,MAAM,iBAAiB,GAAqC;YAC1D,UAAU,EAAE,MAAM,CAAC,UAAU;YAC7B,iBAAiB;YACjB,kBAAkB;SACnB,CAAC;QAEF,OAAO,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,IAAI,uDAA0B,CAAC,iBAAiB,CAAC,CAAC;IAC5G,CAAC,EACD,CAAC,iBAAiB,EAAE,kBAAkB,EAAE,YAAY,CAAC,CACtD,CAAC;IAEF,MAAM,SAAS,GAAG,IAAA,kDAAwB,EAAC;QACzC,GAAG,KAAK;QACR,MAAM;QACN,OAAO;QACP,mBAAmB;QACnB,eAAe,EAAE,UAAU,EAAE,MAAM;YACjC,CAAC,CAAC;gBACE,MAAM,EAAE,UAAU,CAAC,MAAM;gBACzB,gBAAgB,EAAE,UAAU,EAAE,gBAAgB;aAC/C;YACH,CAAC,CAAC,SAAS;KACd,CAAC,CAAC;IAEH,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,cAAc,IAAI,cAAc,CAAC,SAAS,EAAE,eAAe,EAAE,gBAAgB,EAAE,SAAS,EAAE,eAAe,EAAE,YAAY,CAAC,CAAC;IAC3H,CAAC,EAAE,CAAC,SAAS,EAAE,eAAe,EAAE,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,gBAAgB,EAAE,cAAc,CAAC,CAAC,CAAC;IAE7G,OAAO,SAAS,CAAC;AACnB,CAAC;AA7CD,wDA6CC","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 { useCallback, useEffect } from \"react\";\nimport { usePresentationTreeState } from \"@itwin/presentation-components\";\nimport { VisibilityTreeEventHandler } from \"../VisibilityTreeEventHandler\";\n\nimport type { IModelConnection } from \"@itwin/core-frontend\";\nimport type { Ruleset } from \"@itwin/presentation-common\";\nimport type { IFilteredPresentationTreeDataProvider, PresentationTreeEventHandlerProps, UsePresentationTreeStateProps } from \"@itwin/presentation-components\";\nimport type { IVisibilityHandler, VisibilityTreeEventHandlerParams, VisibilityTreeSelectionPredicate } from \"../VisibilityTreeEventHandler\";\nimport type { VisibilityTreeFilterInfo } from \"./Types\";\n\n/**\n * Props for [[useVisibilityTreeState]] hook.\n * @beta\n */\nexport interface UseVisibilityTreeStateProps extends Omit<UsePresentationTreeStateProps<VisibilityTreeEventHandler>, \"rulesetOrId\"> {\n /** iModel to pull data from. */\n imodel: IModelConnection;\n /** Presentation rules to use when pulling data from iModel. */\n ruleset: Ruleset;\n /** Visibility handler that will be used to determine tree node visibility or change it. */\n visibilityHandler?: IVisibilityHandler;\n /** Info about filter that should be applied on tree. */\n filterInfo?: VisibilityTreeFilterInfo;\n /** Callback that is invoked when filter is applied, changed or removed. */\n onFilterChange?: (filteredDataProvider?: IFilteredPresentationTreeDataProvider, matchesCount?: number) => void;\n /** Callback that is used to determine if node can be selected. If not provided all nodes are selectable. */\n selectionPredicate?: VisibilityTreeSelectionPredicate;\n /** Factory for custom `VisibilityTreeEventHandler`. Defaults to `VisibilityTreeEventHandler`. */\n eventHandler?: (props: VisibilityTreeEventHandlerParams) => VisibilityTreeEventHandler;\n /** The limit for how many items should be loaded for a single hierarchy level. */\n hierarchyLevelSizeLimit?: number;\n}\n\n/**\n * Custom hook for creating visibility tree component state.\n *\n * @returns `undefined` on first render cycle. On all other render cycles state is initialized and valid object is returned.\n * @beta\n */\nexport function useVisibilityTreeState({\n imodel,\n ruleset,\n filterInfo,\n onFilterChange,\n visibilityHandler,\n selectionPredicate,\n eventHandler,\n ...props\n}: UseVisibilityTreeStateProps) {\n const eventHandlerFactory = useCallback(\n (params: PresentationTreeEventHandlerProps) => {\n if (!visibilityHandler) {\n return undefined;\n }\n\n const eventHandlerProps: VisibilityTreeEventHandlerParams = {\n nodeLoader: params.nodeLoader,\n visibilityHandler,\n selectionPredicate,\n };\n\n return eventHandler ? eventHandler(eventHandlerProps) : new VisibilityTreeEventHandler(eventHandlerProps);\n },\n [visibilityHandler, selectionPredicate, eventHandler],\n );\n\n const treeState = usePresentationTreeState({\n ...props,\n imodel,\n ruleset,\n eventHandlerFactory,\n filteringParams: filterInfo?.filter\n ? {\n filter: filterInfo.filter,\n activeMatchIndex: filterInfo?.activeMatchIndex,\n }\n : undefined,\n });\n\n useEffect(() => {\n onFilterChange && onFilterChange(treeState?.filteringResult?.filteredProvider, treeState?.filteringResult?.matchesCount);\n }, [treeState?.filteringResult?.matchesCount, treeState?.filteringResult?.filteredProvider, onFilterChange]);\n\n return treeState;\n}\n"]}
|