@itwin/tree-widget-react 0.9.0 → 0.10.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/lib/cjs/TreeWidget.js +1 -1
- package/lib/cjs/TreeWidget.js.map +1 -1
- package/lib/cjs/components/TreeWidgetUiItemsProvider.js +11 -18
- package/lib/cjs/components/TreeWidgetUiItemsProvider.js.map +1 -1
- package/lib/cjs/components/trees/CategoriesVisibilityUtils.js +2 -2
- package/lib/cjs/components/trees/CategoriesVisibilityUtils.js.map +1 -1
- package/lib/cjs/components/trees/VisibilityTreeEventHandler.js +1 -2
- package/lib/cjs/components/trees/VisibilityTreeEventHandler.js.map +1 -1
- package/lib/cjs/components/trees/VisibilityTreeRenderer.js +1 -1
- package/lib/cjs/components/trees/VisibilityTreeRenderer.js.map +1 -1
- package/lib/cjs/components/trees/category-tree/CategoriesTree.js +3 -4
- package/lib/cjs/components/trees/category-tree/CategoriesTree.js.map +1 -1
- package/lib/cjs/components/trees/category-tree/CategoriesTreeComponent.js +4 -8
- package/lib/cjs/components/trees/category-tree/CategoriesTreeComponent.js.map +1 -1
- package/lib/cjs/components/trees/category-tree/CategoryVisibilityHandler.js +3 -6
- package/lib/cjs/components/trees/category-tree/CategoryVisibilityHandler.js.map +1 -1
- package/lib/cjs/components/trees/models-tree/ModelsTree.js +3 -4
- package/lib/cjs/components/trees/models-tree/ModelsTree.js.map +1 -1
- package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.js +2 -4
- package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
- package/lib/cjs/components/trees/models-tree/ModelsVisibilityHandler.js +2 -4
- package/lib/cjs/components/trees/models-tree/ModelsVisibilityHandler.js.map +1 -1
- package/lib/esm/TreeWidget.js +1 -1
- package/lib/esm/TreeWidget.js.map +1 -1
- package/lib/esm/components/TreeWidgetUiItemsProvider.js +11 -18
- package/lib/esm/components/TreeWidgetUiItemsProvider.js.map +1 -1
- package/lib/esm/components/trees/CategoriesVisibilityUtils.js +2 -2
- package/lib/esm/components/trees/CategoriesVisibilityUtils.js.map +1 -1
- package/lib/esm/components/trees/VisibilityTreeEventHandler.js +1 -2
- package/lib/esm/components/trees/VisibilityTreeEventHandler.js.map +1 -1
- package/lib/esm/components/trees/VisibilityTreeRenderer.js +1 -1
- package/lib/esm/components/trees/VisibilityTreeRenderer.js.map +1 -1
- package/lib/esm/components/trees/category-tree/CategoriesTree.js +3 -4
- package/lib/esm/components/trees/category-tree/CategoriesTree.js.map +1 -1
- package/lib/esm/components/trees/category-tree/CategoriesTreeComponent.js +4 -8
- package/lib/esm/components/trees/category-tree/CategoriesTreeComponent.js.map +1 -1
- package/lib/esm/components/trees/category-tree/CategoryVisibilityHandler.js +3 -6
- package/lib/esm/components/trees/category-tree/CategoryVisibilityHandler.js.map +1 -1
- package/lib/esm/components/trees/models-tree/ModelsTree.js +3 -4
- package/lib/esm/components/trees/models-tree/ModelsTree.js.map +1 -1
- package/lib/esm/components/trees/models-tree/ModelsTreeComponent.js +2 -4
- package/lib/esm/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
- package/lib/esm/components/trees/models-tree/ModelsVisibilityHandler.js +2 -4
- package/lib/esm/components/trees/models-tree/ModelsVisibilityHandler.js.map +1 -1
- package/package.json +20 -20
package/lib/cjs/TreeWidget.js
CHANGED
|
@@ -20,7 +20,7 @@ class TreeWidget {
|
|
|
20
20
|
if (this._initialized)
|
|
21
21
|
return;
|
|
22
22
|
TreeWidget._initialized = true;
|
|
23
|
-
TreeWidget._i18n = i18n
|
|
23
|
+
TreeWidget._i18n = i18n ?? core_frontend_1.IModelApp.localization;
|
|
24
24
|
return TreeWidget._i18n.registerNamespace(TreeWidget.i18nNamespace);
|
|
25
25
|
}
|
|
26
26
|
/** Unregisters the TreeWidget internationalization service namespace */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeWidget.js","sourceRoot":"","sources":["../../src/TreeWidget.ts"],"names":[],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kDAAkD;IAC3C,MAAM,KAAK,aAAa;QAC7B,OAAO,YAAY,CAAC;IACtB,CAAC;IAEM,MAAM,KAAK,WAAW;QAC3B,OAAO,mBAAmB,CAAC;IAC7B,CAAC;IAED;OACG;IACI,MAAM,CAAC,SAAS,CACrB,GAAsB,EACtB,OAA6B;QAE7B,MAAM,SAAS,GAAG,GAAG,UAAU,CAAC,aAAa,IAAI,GAAG,EAAE,CAAC;QACvD,OAAO,UAAU,CAAC,IAAI,CAAC,kBAAkB,CACvC,SAAS,EACT,OAAO,CACR,CAAC;IACJ,CAAC;IAEM,MAAM,CAAC,cAAc,CAAC,GAAQ;QACnC,MAAM,SAAS,GAAG,IAAA,6BAAY,EAAC,GAAG,CAAC,CAAC;QACpC,MAAM,QAAQ,GACZ,UAAU,CAAC,WAAW,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QAC9D,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AA/DD,gCA+DC","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 { getClassName, UiError } from \"@itwin/appui-abstract\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport type { Localization } from \"@itwin/core-common\";\nimport type { LocalizationOptions } from \"@itwin/core-i18n\";\n\n/**\n * Entry point for static initialization required by various components used in the package.\n * @public\n */\nexport class TreeWidget {\n private static _i18n?: Localization;\n private static _initialized?: boolean;\n\n /**\n * Called by IModelApp to initialize the Tree Widget\n * @param i18n - The internationalization service created by the IModelApp.\n */\n public static async initialize(i18n?: Localization): Promise<void> {\n if (this._initialized) return;\n\n TreeWidget._initialized = true;\n TreeWidget._i18n = i18n ?? IModelApp.localization;\n\n return TreeWidget._i18n.registerNamespace(TreeWidget.i18nNamespace);\n }\n\n /** Unregisters the TreeWidget internationalization service namespace */\n public static terminate() {\n if (TreeWidget._i18n)\n TreeWidget._i18n.unregisterNamespace(TreeWidget.i18nNamespace); // eslint-disable-line @itwin/no-internal\n TreeWidget._i18n = undefined;\n TreeWidget._initialized = false;\n }\n\n /** The internationalization service created by the IModelApp. */\n public static get i18n(): Localization {\n if (!TreeWidget._i18n)\n throw new UiError(\n TreeWidget.loggerCategory(this),\n \"TreeWidget not initialized\"\n );\n return TreeWidget._i18n;\n }\n\n /** The internationalization service namespace. */\n public static get i18nNamespace(): string {\n return \"TreeWidget\";\n }\n\n public static get packageName(): string {\n return \"tree-widget-react\";\n }\n\n /** Calls i18n.translateWithNamespace with the \"TreeWidget\" namespace. Do NOT include the namespace in the key.\n */\n public static translate(\n key: string | string[],\n options?: LocalizationOptions\n ): string {\n const stringKey = `${TreeWidget.i18nNamespace}:${key}`;\n return TreeWidget.i18n.getLocalizedString(\n stringKey,\n options\n );\n }\n\n public static loggerCategory(obj: any): string {\n const className = getClassName(obj);\n const category =\n TreeWidget.packageName + (className ? `.${className}` : \"\");\n return category;\n }\n}\n"]}
|
|
@@ -24,40 +24,33 @@ class TreeWidgetUiItemsProvider {
|
|
|
24
24
|
this.id = "TreeWidgetUiItemsProvider";
|
|
25
25
|
}
|
|
26
26
|
provideWidgets(_stageId, stageUsage, location, section) {
|
|
27
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
28
27
|
const widgets = [];
|
|
29
|
-
const preferredLocation =
|
|
30
|
-
const preferredPanelSection =
|
|
28
|
+
const preferredLocation = this._treeWidgetOptions?.defaultPanelLocation ?? appui_react_1.StagePanelLocation.Right;
|
|
29
|
+
const preferredPanelSection = this._treeWidgetOptions?.defaultPanelSection ?? appui_react_1.StagePanelSection.Start;
|
|
31
30
|
if (location === preferredLocation &&
|
|
32
31
|
section === preferredPanelSection &&
|
|
33
32
|
stageUsage === appui_react_1.StageUsage.General) {
|
|
34
33
|
const trees = [];
|
|
35
|
-
if (!
|
|
34
|
+
if (!this._treeWidgetOptions?.hideTrees?.modelsTree) {
|
|
36
35
|
trees.push({
|
|
37
36
|
label: TreeWidget_1.TreeWidget.translate("models"),
|
|
38
37
|
id: types_1.ModelsTreeId,
|
|
39
|
-
render: () => {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
? Common_1.ClassGroupingOption.YesWithCounts
|
|
43
|
-
: Common_1.ClassGroupingOption.No, ...(_b = this._treeWidgetOptions) === null || _b === void 0 ? void 0 : _b.modelsTreeProps }));
|
|
44
|
-
},
|
|
38
|
+
render: () => (react_1.default.createElement(ModelsTreeComponent_1.ModelsTreeComponent, { enableElementsClassGrouping: this._treeWidgetOptions?.enableElementsClassGrouping
|
|
39
|
+
? Common_1.ClassGroupingOption.YesWithCounts
|
|
40
|
+
: Common_1.ClassGroupingOption.No, ...this._treeWidgetOptions?.modelsTreeProps })),
|
|
45
41
|
});
|
|
46
42
|
}
|
|
47
|
-
if (!
|
|
43
|
+
if (!this._treeWidgetOptions?.hideTrees?.categoriesTree) {
|
|
48
44
|
trees.push({
|
|
49
45
|
label: TreeWidget_1.TreeWidget.translate("categories"),
|
|
50
46
|
id: types_1.CategoriesTreeId,
|
|
51
|
-
render: () => {
|
|
52
|
-
var _a;
|
|
53
|
-
return (react_1.default.createElement(CategoriesTreeComponent_1.CategoriesTreeComponent, { ...(_a = this._treeWidgetOptions) === null || _a === void 0 ? void 0 : _a.categoriesTreeProps }));
|
|
54
|
-
},
|
|
47
|
+
render: () => (react_1.default.createElement(CategoriesTreeComponent_1.CategoriesTreeComponent, { ...this._treeWidgetOptions?.categoriesTreeProps })),
|
|
55
48
|
});
|
|
56
49
|
}
|
|
57
|
-
if (
|
|
50
|
+
if (this._treeWidgetOptions?.additionalTrees) {
|
|
58
51
|
trees.push(...this._treeWidgetOptions.additionalTrees);
|
|
59
52
|
}
|
|
60
|
-
if (
|
|
53
|
+
if (this._treeWidgetOptions?.defaultTreeId && trees.length !== 0) {
|
|
61
54
|
// Adding the defaultTree to first index
|
|
62
55
|
const { defaultTreeId } = this._treeWidgetOptions;
|
|
63
56
|
const extractedDefaultTree = trees.filter((tree) => tree.id === defaultTreeId)[0];
|
|
@@ -69,7 +62,7 @@ class TreeWidgetUiItemsProvider {
|
|
|
69
62
|
label: TreeWidget_1.TreeWidget.translate("treeview"),
|
|
70
63
|
content: react_1.default.createElement(TreeWidgetComponent_1.TreeWidgetComponent, { trees: trees }),
|
|
71
64
|
icon: "icon-hierarchy-tree",
|
|
72
|
-
priority:
|
|
65
|
+
priority: this._treeWidgetOptions?.defaultTreeWidgetPriority,
|
|
73
66
|
});
|
|
74
67
|
}
|
|
75
68
|
return widgets;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeWidgetUiItemsProvider.js","sourceRoot":"","sources":["../../../src/components/TreeWidgetUiItemsProvider.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F,uCAAuC;;;;;;AAEvC,kDAA0B;AAC1B,oDAAgH;AAEhH,8CAA2C;AAC3C,oCAA6E;AAC7E,2FAAwF;AACxF,2CAAqD;AACrD,iFAA8E;AAC9E,+DAA4D;AAE/C,QAAA,YAAY,GAAG,yBAAyB,CAAC;AACtD,MAAa,yBAAyB;IAGpC,YAAoB,kBAAsC;QAAtC,uBAAkB,GAAlB,kBAAkB,CAAoB;QAF1C,OAAE,GAAG,2BAA2B,CAAC;IAEa,CAAC;IAExD,cAAc,CACnB,QAAgB,EAChB,UAAkB,EAClB,QAA4B,EAC5B,OAA2B
|
|
1
|
+
{"version":3,"file":"TreeWidgetUiItemsProvider.js","sourceRoot":"","sources":["../../../src/components/TreeWidgetUiItemsProvider.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F,uCAAuC;;;;;;AAEvC,kDAA0B;AAC1B,oDAAgH;AAEhH,8CAA2C;AAC3C,oCAA6E;AAC7E,2FAAwF;AACxF,2CAAqD;AACrD,iFAA8E;AAC9E,+DAA4D;AAE/C,QAAA,YAAY,GAAG,yBAA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E,CAAC,CACZ,8BAAC,iDAAuB,OAAK,IAAI,CAAC,kBAAkB,EAAE,mBAAmB,GAAI,CAC9E;iBACF,CAAC,CAAC;aACJ;YAED,IAAI,IAAI,CAAC,kBAAkB,EAAE,eAAe,EAAE;gBAC5C,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,kBAAkB,CAAC,eAAe,CAAC,CAAC;aACxD;YAED,IAAI,IAAI,CAAC,kBAAkB,EAAE,aAAa,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE;gBAChE,wCAAwC;gBACxC,MAAM,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC,kBAAkB,CAAC;gBAClD,MAAM,oBAAoB,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;gBAClF,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC;gBAClD,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;aAC1C;YAED,OAAO,CAAC,IAAI,CAAC;gBACX,EAAE,EAAE,oBAAY;gBAChB,KAAK,EAAE,uBAAU,CAAC,SAAS,CAAC,UAAU,CAAC;gBACvC,OAAO,EAAE,8BAAC,yCAAmB,IAAC,KAAK,EAAE,KAAK,GAAI;gBAC9C,IAAI,EAAE,qBAAqB;gBAC3B,QAAQ,EAAE,IAAI,CAAC,kBAAkB,EAAE,yBAAyB;aAC7D,CAAC,CAAC;SACJ;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAvED,8DAuEC","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/* eslint-disable react/display-name */\n\nimport React from \"react\";\nimport { StagePanelLocation, StagePanelSection, StageUsage, UiItemsProvider, Widget } from \"@itwin/appui-react\";\nimport { SelectableContentDefinition } from \"@itwin/components-react\";\nimport { TreeWidget } from \"../TreeWidget\";\nimport { CategoriesTreeId, ModelsTreeId, TreeWidgetOptions } from \"../types\";\nimport { CategoriesTreeComponent } from \"./trees/category-tree/CategoriesTreeComponent\";\nimport { ClassGroupingOption } from \"./trees/Common\";\nimport { ModelsTreeComponent } from \"./trees/models-tree/ModelsTreeComponent\";\nimport { TreeWidgetComponent } from \"./TreeWidgetComponent\";\n\nexport const TreeWidgetId = \"tree-widget-react:trees\";\nexport class TreeWidgetUiItemsProvider implements UiItemsProvider {\n public readonly id = \"TreeWidgetUiItemsProvider\";\n\n constructor(private _treeWidgetOptions?: TreeWidgetOptions) { }\n\n public provideWidgets(\n _stageId: string,\n stageUsage: string,\n location: StagePanelLocation,\n section?: StagePanelSection\n ): ReadonlyArray<Widget> {\n const widgets: Widget[] = [];\n const preferredLocation = this._treeWidgetOptions?.defaultPanelLocation ?? StagePanelLocation.Right;\n const preferredPanelSection = this._treeWidgetOptions?.defaultPanelSection ?? StagePanelSection.Start;\n if (\n location === preferredLocation &&\n section === preferredPanelSection &&\n stageUsage === StageUsage.General\n ) {\n const trees: SelectableContentDefinition[] = [];\n\n if (!this._treeWidgetOptions?.hideTrees?.modelsTree) {\n trees.push({\n label: TreeWidget.translate(\"models\"),\n id: ModelsTreeId,\n render: () => (\n <ModelsTreeComponent\n enableElementsClassGrouping={\n this._treeWidgetOptions?.enableElementsClassGrouping\n ? ClassGroupingOption.YesWithCounts\n : ClassGroupingOption.No\n }\n {...this._treeWidgetOptions?.modelsTreeProps}\n />\n ),\n });\n }\n\n if (!this._treeWidgetOptions?.hideTrees?.categoriesTree) {\n trees.push({\n label: TreeWidget.translate(\"categories\"),\n id: CategoriesTreeId,\n render: () => (\n <CategoriesTreeComponent {...this._treeWidgetOptions?.categoriesTreeProps} />\n ),\n });\n }\n\n if (this._treeWidgetOptions?.additionalTrees) {\n trees.push(...this._treeWidgetOptions.additionalTrees);\n }\n\n if (this._treeWidgetOptions?.defaultTreeId && trees.length !== 0) {\n // Adding the defaultTree to first index\n const { defaultTreeId } = this._treeWidgetOptions;\n const extractedDefaultTree = trees.filter((tree) => tree.id === defaultTreeId)[0];\n const index = trees.indexOf(extractedDefaultTree);\n trees.unshift(trees.splice(index, 1)[0]);\n }\n\n widgets.push({\n id: TreeWidgetId,\n label: TreeWidget.translate(\"treeview\"),\n content: <TreeWidgetComponent trees={trees} />,\n icon: \"icon-hierarchy-tree\",\n priority: this._treeWidgetOptions?.defaultTreeWidgetPriority,\n });\n }\n\n return widgets;\n }\n}\n"]}
|
|
@@ -14,12 +14,12 @@ const EMPTY_CATEGORIES_ARRAY = [];
|
|
|
14
14
|
*/
|
|
15
15
|
async function toggleAllCategories(viewManager, imodel, display, viewport, forAllViewports) {
|
|
16
16
|
// istanbul ignore next
|
|
17
|
-
const activeView = viewport
|
|
17
|
+
const activeView = viewport ?? viewManager.getFirstOpenView();
|
|
18
18
|
const ids = await getCategories(imodel, activeView);
|
|
19
19
|
// istanbul ignore if
|
|
20
20
|
if (ids.length === 0)
|
|
21
21
|
return;
|
|
22
|
-
await enableCategory(viewManager, imodel, ids, display, forAllViewports
|
|
22
|
+
await enableCategory(viewManager, imodel, ids, display, forAllViewports ?? false);
|
|
23
23
|
}
|
|
24
24
|
exports.toggleAllCategories = toggleAllCategories;
|
|
25
25
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CategoriesVisibilityUtils.js","sourceRoot":"","sources":["../../../../src/components/trees/CategoriesVisibilityUtils.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,oDAAoD;AACpD,wDAA2G;AAG3G,MAAM,sBAAsB,GAAmB,EAAE,CAAC;AAElD;;;GAGG;AACI,KAAK,UAAU,mBAAmB,CAAC,WAAwB,EAAE,MAAwB,EAAE,OAAgB,EAAE,QAAmB,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AAM,EAAE;QACV,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,EAAE,4BAAc,CAAC,kBAAkB,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;QAC3H,CAAC,MAAM,MAAM,CAAC,UAAU,CAAC,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACnF,UAAU,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,GAAG,CAAC,EAAE,EAAE,cAAc,EAAE,GAAG,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC;QAC9H,CAAC,CAAC,CAAC;KACJ;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AApBD,gEAoBC","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 { QueryRowFormat } from \"@itwin/core-common\";\nimport { IModelConnection, PerModelCategoryVisibility, ViewManager, Viewport } from \"@itwin/core-frontend\";\nimport { CategoryInfo } from \"./category-tree/CategoryVisibilityHandler\";\n\nconst EMPTY_CATEGORIES_ARRAY: CategoryInfo[] = [];\n\n/**\n * Toggles visibility of categories to show or hide.\n * @alpha\n */\nexport async function toggleAllCategories(viewManager: ViewManager, imodel: IModelConnection, display: boolean, viewport?: Viewport, forAllViewports?: boolean) {\n // istanbul ignore next\n const activeView = viewport ?? viewManager.getFirstOpenView();\n const ids = await getCategories(imodel, activeView);\n\n // istanbul ignore if\n if (ids.length === 0)\n return;\n\n await enableCategory(viewManager, imodel, ids, display, forAllViewports ?? false);\n}\n\n/**\n * Gets ids of all categories from specified imodel and viewport.\n * @alpha\n */\nexport async function getCategories(imodel: IModelConnection, viewport?: Viewport) {\n const categories = await loadCategoriesFromViewport(imodel, viewport);\n return categories.map((category) => category.categoryId);\n}\n\n/** Changes category display in the viewport */\nexport async function enableCategory(viewManager: ViewManager, imodel: IModelConnection, ids: string[], enabled: boolean, forAllViewports: boolean, enableAllSubCategories = true) {\n if (!viewManager.selectedView)\n return;\n\n const updateViewport = async (vp: Viewport) => {\n // Only act on viewports that are both 3D or both 2D. Important if we have multiple viewports opened and we\n // are using 'allViewports' property\n if (viewManager.selectedView && viewManager.selectedView.view.is3d() === vp.view.is3d()) {\n vp.changeCategoryDisplay(ids, enabled, enableAllSubCategories);\n\n // remove category overrides per model\n const modelsContainingOverrides: string[] = [];\n for (const ovr of vp.perModelCategoryVisibility) {\n // istanbul ignore else\n if (ids.findIndex((id) => id === ovr.categoryId) !== -1)\n modelsContainingOverrides.push(ovr.modelId);\n }\n vp.perModelCategoryVisibility.setOverride(modelsContainingOverrides, ids, PerModelCategoryVisibility.Override.None);\n\n // changeCategoryDisplay only enables subcategories, it does not disabled them. So we must do that ourselves.\n if (false === enabled) {\n (await imodel.categories.getCategoryInfo(ids)).forEach((categoryInfo) => {\n categoryInfo.subCategories.forEach((value) => enableSubCategory(viewManager, value.id, false, forAllViewports));\n });\n }\n }\n };\n\n // This property let us act on all viewports or just on the selected one, configurable by the app\n if (forAllViewports) {\n for (const viewport of viewManager) {\n await updateViewport(viewport);\n }\n } else {\n await updateViewport(viewManager.selectedView);\n }\n}\n\n/** Changes subcategory display in the viewport */\nexport function enableSubCategory(viewManager: ViewManager, key: string, enabled: boolean, forAllViewports?: boolean) {\n if (!viewManager.selectedView)\n return;\n\n const updateViewport = (vp: Viewport) => {\n // Only act on viewports that are both 3D or both 2D. Important if we have multiple viewports opened and we\n // are using 'allViewports' property\n if (viewManager.selectedView && viewManager.selectedView.view.is3d() === vp.view.is3d()) {\n vp.changeSubCategoryDisplay(key, enabled);\n }\n };\n\n // This property let us act on all viewports or just on the selected one, configurable by the app\n if (forAllViewports) {\n for (const viewport of viewManager) {\n updateViewport(viewport);\n }\n } else {\n updateViewport(viewManager.selectedView);\n }\n}\n\n/** @internal */\nexport async function loadCategoriesFromViewport(iModel?: IModelConnection, vp?: Viewport) {\n if (!vp)\n return EMPTY_CATEGORIES_ARRAY;\n\n // Query categories and add them to state\n const selectUsedSpatialCategoryIds = \"SELECT DISTINCT Category.Id as id from BisCore.GeometricElement3d WHERE Category.Id IN (SELECT ECInstanceId from BisCore.SpatialCategory)\";\n const selectUsedDrawingCategoryIds = \"SELECT DISTINCT Category.Id as id from BisCore.GeometricElement2d WHERE Model.Id=? AND Category.Id IN (SELECT ECInstanceId from BisCore.DrawingCategory)\";\n const ecsql = vp.view.is3d() ? selectUsedSpatialCategoryIds : selectUsedDrawingCategoryIds;\n const ecsql2 = `SELECT ECInstanceId as id FROM ${vp.view.is3d() ? \"BisCore.SpatialCategory\" : \"BisCore.DrawingCategory\"} WHERE ECInstanceId IN (${ecsql})`;\n\n const categories: CategoryInfo[] = [];\n\n // istanbul ignore else\n if (iModel) {\n const rows = await iModel.createQueryReader(ecsql2, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames }).toArray();\n (await iModel.categories.getCategoryInfo(rows.map((row) => row.id))).forEach((val) => {\n categories.push({ categoryId: val.id, subCategoryIds: val.subCategories.size ? [...val.subCategories.keys()] : undefined });\n });\n }\n return categories;\n}\n"]}
|
|
@@ -138,10 +138,9 @@ class VisibilityTreeEventHandler extends presentation_components_1.UnifiedSelect
|
|
|
138
138
|
return nodeStates;
|
|
139
139
|
}
|
|
140
140
|
async getNodeCheckBoxInfo(node, visibilityStatus) {
|
|
141
|
-
var _a;
|
|
142
141
|
if (!this._visibilityHandler)
|
|
143
142
|
return { ...node.checkbox, isVisible: false };
|
|
144
|
-
const result =
|
|
143
|
+
const result = visibilityStatus?.get(node.id) ?? this._visibilityHandler.getVisibilityStatus(node.item);
|
|
145
144
|
if ((0, IsPromiseLike_1.isPromiseLike)(result))
|
|
146
145
|
return this.createCheckboxInfo(await result);
|
|
147
146
|
return this.createCheckboxInfo(result);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VisibilityTreeEventHandler.js","sourceRoot":"","sources":["../../../../src/components/trees/VisibilityTreeEventHandler.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,+BAAkC;AAClC,0DAAuD;AACvD,wDAAqD;AACrD,qDAAkD;AAClD,+DAA4D;AAM5D,kDAAkD;AAClD,4EAA0H;AAC1H,0DAAuD;AA2CvD;;;GAGG;AACH,MAAa,0BAA2B,SAAQ,0DAAgC;IAM9E,YAAY,MAAwC;QAClD,KAAK,CAAC,MAAM,CAAC,CAAC;QAJR,eAAU,GAAG,IAAI,KAAK,EAAc,CAAC;QAK3C,IAAI,CAAC,kBAAkB,GAAG,MAAM,CAAC,iBAAiB,CAAC;QACnD,IAAI,CAAC,mBAAmB,GAAG,MAAM,CAAC,kBAAkB,CAAC;QACrD,IAAI,CAAC,qBAAqB,GAAG,KAAK,CAAC;QAEnC,IAAI,IAAI,CAAC,kBAAkB,EAAE;YAC3B,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,kBAAkB,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,gBAAgB,EAAE,EAAE;gBAC9G,IAAI,IAAI,CAAC,qBAAqB;oBAC5B,OAAO;gBACT,KAAK,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;YACxD,CAAC,CAAC,CAAC,CAAC;SACL;QAED,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,EAAE,EAAE;YACtF,KAAK,IAAI,CAAC,gBAAgB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C/C,OAAO,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAEO,kBAAkB,CAAC,MAAwB;QACjD,OAAO;YACL,KAAK,EAAE,8BAA8B,CAAC,MAAM,CAAC;YAC7C,UAAU,EAAE,MAAM,CAAC,UAAU,IAAI,KAAK;YACtC,SAAS,EAAE,IAAI;YACf,OAAO,EAAE,MAAM,CAAC,OAAO;SACxB,CAAC;IACJ,CAAC;CACF;AAnKD,gEAmKC;AAED,MAAM,8BAA8B,GAAG,CAAC,MAAwB,EAAE,EAAE;IAClE,QAAQ,MAAM,CAAC,KAAK,EAAE;QACpB,KAAK,SAAS;YACZ,OAAO,0BAAa,CAAC,EAAE,CAAC;QAC1B,uBAAuB;QACvB,KAAK,SAAS;YACZ,OAAO,0BAAa,CAAC,OAAO,CAAC;QAC/B,KAAK,QAAQ,CAAC;QACd;YACE,OAAO,0BAAa,CAAC,GAAG,CAAC;KAC5B;AACH,CAAC,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/** @packageDocumentation\n * @module IModelComponents\n */\n\nimport { Observable } from \"rxjs\";\nimport { EMPTY } from \"rxjs/internal/observable/empty\";\nimport { from } from \"rxjs/internal/observable/from\";\nimport { map } from \"rxjs/internal/operators/map\";\nimport { mergeMap } from \"rxjs/internal/operators/mergeMap\";\nimport {\n CheckBoxInfo, CheckboxStateChange, TreeCheckboxStateChangeEventArgs, TreeModelNode, TreeNodeItem, TreeSelectionChange,\n TreeSelectionModificationEventArgs, TreeSelectionReplacementEventArgs,\n} from \"@itwin/components-react\";\nimport { BeEvent, IDisposable } from \"@itwin/core-bentley\";\nimport { CheckBoxState } from \"@itwin/core-react\";\nimport { UnifiedSelectionTreeEventHandler, UnifiedSelectionTreeEventHandlerParams } from \"@itwin/presentation-components\";\nimport { isPromiseLike } from \"../utils/IsPromiseLike\";\n\n/**\n * Data structure that describes instance visibility status.\n * @alpha\n */\nexport interface VisibilityStatus {\n state: \"visible\" | \"partial\" | \"hidden\";\n isDisabled?: boolean;\n tooltip?: string;\n}\n\n/**\n * Type definition of visibility change event listener.\n * @alpha\n */\nexport type VisibilityChangeListener = (nodeIds?: string[], visibilityStatus?: Map<string, VisibilityStatus>) => void;\n\n/**\n * Visibility handler used to change or get visibility of instances represented by the tree node.\n * @alpha\n */\nexport interface IVisibilityHandler extends IDisposable {\n getVisibilityStatus(node: TreeNodeItem): VisibilityStatus | Promise<VisibilityStatus>;\n changeVisibility(node: TreeNodeItem, shouldDisplay: boolean): Promise<void>;\n onVisibilityChange: BeEvent<VisibilityChangeListener>;\n}\n\n/**\n * Type definition of predicate used to decide if node can be selected.\n * @alpha\n */\nexport type VisibilityTreeSelectionPredicate = (node: TreeNodeItem) => boolean;\n\n/**\n * Parameters for [[VisibilityTreeEventHandler]]\n * @alpha\n */\nexport interface VisibilityTreeEventHandlerParams extends UnifiedSelectionTreeEventHandlerParams {\n visibilityHandler: IVisibilityHandler | undefined;\n selectionPredicate?: VisibilityTreeSelectionPredicate;\n}\n\n/**\n * Base event handler for visibility tree.\n * @alpha\n */\nexport class VisibilityTreeEventHandler extends UnifiedSelectionTreeEventHandler {\n private _visibilityHandler: IVisibilityHandler | undefined;\n private _selectionPredicate?: VisibilityTreeSelectionPredicate;\n private _listeners = new Array<() => void>();\n private _isChangingVisibility: boolean;\n\n constructor(params: VisibilityTreeEventHandlerParams) {\n super(params);\n this._visibilityHandler = params.visibilityHandler;\n this._selectionPredicate = params.selectionPredicate;\n this._isChangingVisibility = false;\n\n if (this._visibilityHandler) {\n this._listeners.push(this._visibilityHandler.onVisibilityChange.addListener(async (nodeIds, visibilityStatus) => {\n if (this._isChangingVisibility)\n return;\n void this.updateCheckboxes(nodeIds, visibilityStatus);\n }));\n }\n\n this._listeners.push(this.modelSource.onModelChanged.addListener(async ([_, changes]) => {\n void this.updateCheckboxes([...changes.addedNodeIds, ...changes.modifiedNodeIds]);\n }));\n this.updateCheckboxes(); // eslint-disable-line @typescript-eslint/no-floating-promises\n }\n\n public override dispose() {\n super.dispose();\n this._listeners.forEach((disposeFunc) => disposeFunc());\n }\n\n private filterSelectionItems(items: TreeNodeItem[]) {\n // istanbul ignore if\n if (!this._selectionPredicate)\n return items;\n\n return items.filter((item) => this._selectionPredicate!(item));\n }\n\n public override onSelectionModified({ modifications }: TreeSelectionModificationEventArgs) {\n const filteredModification = new Observable<TreeSelectionChange>((subscriber) => modifications.subscribe(subscriber)).pipe(\n map(({ selectedNodeItems, deselectedNodeItems }) => {\n return {\n selectedNodeItems: this.filterSelectionItems(selectedNodeItems),\n deselectedNodeItems: this.filterSelectionItems(deselectedNodeItems),\n };\n }),\n );\n return super.onSelectionModified({ modifications: filteredModification });\n }\n\n public override onSelectionReplaced({ replacements }: TreeSelectionReplacementEventArgs) {\n const filteredReplacements = new Observable<{ selectedNodeItems: TreeNodeItem[] }>((subscriber) => replacements.subscribe(subscriber)).pipe(\n map(({ selectedNodeItems }) => {\n return {\n selectedNodeItems: this.filterSelectionItems(selectedNodeItems),\n };\n }),\n );\n return super.onSelectionReplaced({ replacements: filteredReplacements });\n }\n\n public override onCheckboxStateChanged(event: TreeCheckboxStateChangeEventArgs) {\n const handleStateChanged = () => {\n this._isChangingVisibility = false;\n void this.updateCheckboxes();\n };\n // istanbul ignore if\n if (!this._visibilityHandler)\n return undefined;\n\n // eslint-disable-next-line deprecation/deprecation\n from(event.stateChanges)\n .pipe(\n // eslint-disable-next-line deprecation/deprecation\n mergeMap((changes) => this.changeVisibility(changes)),\n )\n // eslint-disable-next-line deprecation/deprecation\n .subscribe({\n complete: handleStateChanged,\n error: handleStateChanged,\n });\n return undefined;\n }\n\n private changeVisibility(changes: CheckboxStateChange[]) {\n // eslint-disable-next-line deprecation/deprecation\n return from(changes)\n .pipe(\n // eslint-disable-next-line deprecation/deprecation\n mergeMap(({ nodeItem, newState }) => {\n // istanbul ignore if\n if (!this._visibilityHandler)\n return EMPTY;\n this._isChangingVisibility = true;\n // eslint-disable-next-line deprecation/deprecation\n return from(this._visibilityHandler.changeVisibility(nodeItem, newState === CheckBoxState.On));\n }, 1),\n );\n }\n\n private async updateCheckboxes(affectedNodes?: string[], visibilityStatus?: Map<string, VisibilityStatus>) {\n const changes = await (affectedNodes ? this.collectAffectedNodesCheckboxInfos(affectedNodes, visibilityStatus) : this.collectAllNodesCheckboxInfos(visibilityStatus));\n this.updateModel(changes);\n }\n\n private updateModel(changes: Map<string, CheckBoxInfo>) {\n this.modelSource.modifyModel((model) => {\n for (const [nodeId, checkboxInfo] of changes) {\n const node = model.getNode(nodeId);\n // istanbul ignore if\n if (!node)\n continue;\n\n node.checkbox.isDisabled = checkboxInfo.isDisabled;\n node.checkbox.isVisible = checkboxInfo.isVisible;\n node.checkbox.state = checkboxInfo.state;\n node.checkbox.tooltip = checkboxInfo.tooltip;\n }\n });\n }\n\n private async collectAffectedNodesCheckboxInfos(affectedNodes: string[], visibilityStatus?: Map<string, VisibilityStatus>) {\n const nodeStates = new Map<string, CheckBoxInfo>();\n if (affectedNodes.length === 0)\n return nodeStates;\n\n await Promise.all(affectedNodes.map(async (nodeId) => {\n const node = this.modelSource.getModel().getNode(nodeId);\n // istanbul ignore else\n if (node)\n nodeStates.set(nodeId, await this.getNodeCheckBoxInfo(node, visibilityStatus));\n }));\n return nodeStates;\n }\n\n private async collectAllNodesCheckboxInfos(visibilityStatus?: Map<string, VisibilityStatus>) {\n const nodeStates = new Map<string, CheckBoxInfo>();\n for (const node of this.modelSource.getModel().iterateTreeModelNodes()) {\n nodeStates.set(node.id, await this.getNodeCheckBoxInfo(node, visibilityStatus));\n }\n return nodeStates;\n }\n\n private async getNodeCheckBoxInfo(node: TreeModelNode, visibilityStatus?: Map<string, VisibilityStatus>): Promise<CheckBoxInfo> {\n if (!this._visibilityHandler)\n return { ...node.checkbox, isVisible: false };\n\n const result = visibilityStatus?.get(node.id) ?? this._visibilityHandler.getVisibilityStatus(node.item);\n\n if (isPromiseLike(result))\n return this.createCheckboxInfo(await result);\n return this.createCheckboxInfo(result);\n }\n\n private createCheckboxInfo(status: VisibilityStatus): CheckBoxInfo {\n return {\n state: visibilityStateToCheckboxState(status),\n isDisabled: status.isDisabled || false,\n isVisible: true,\n tooltip: status.tooltip,\n };\n }\n}\n\nconst visibilityStateToCheckboxState = (status: VisibilityStatus) => {\n switch (status.state) {\n case \"visible\":\n return CheckBoxState.On;\n // istanbul ignore next\n case \"partial\":\n return CheckBoxState.Partial;\n case \"hidden\":\n default:\n return CheckBoxState.Off;\n }\n};\n"]}
|
|
1
|
+
{"version":3,"file":"VisibilityTreeEventHandler.js","sourceRoot":"","sources":["../../../../src/components/trees/VisibilityTreeEventHandler.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,+BAAkC;AAClC,0DAAuD;AACvD,wDAAqD;AACrD,qDAAkD;AAClD,+DAA4D;AAM5D,kDAAkD;AAClD,4EAA0H;AAC1H,0DAAuD;AA2CvD;;;GAGG;AACH,MAAa,0BAA2B,SAAQ,0DAAgC;IAM9E,YAAY,MAAwC;QAClD,KAAK,CAAC,MAAM,CAAC,CAAC;QAJR,eAAU,GAAG,IAAI,KAAK,EAAc,CAAC;QAK3C,IAAI,CAAC,kBAAkB,GAAG,MAAM,CAAC,iBAAiB,CAAC;QACnD,IAAI,CAAC,mBAAmB,GAAG,MAAM,CAAC,kBAAkB,CAAC;QACrD,IAAI,CAAC,qBAAqB,GAAG,KAAK,CAAC;QAEnC,IAAI,IAAI,CAAC,kBAAkB,EAAE;YAC3B,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,kBAAkB,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,gBAAgB,EAAE,EAAE;gBAC9G,IAAI,IAAI,CAAC,qBAAqB;oBAC5B,OAAO;gBACT,KAAK,IAAI,CAAC,gBAAgB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AAI,CAAC,EAAE,CAAC,IAAI,IAAI,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAExG,IAAI,IAAA,6BAAa,EAAC,MAAM,CAAC;YACvB,OAAO,IAAI,CAAC,kBAAkB,CAAC,MAAM,MAAM,CAAC,CAAC;QAC/C,OAAO,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAEO,kBAAkB,CAAC,MAAwB;QACjD,OAAO;YACL,KAAK,EAAE,8BAA8B,CAAC,MAAM,CAAC;YAC7C,UAAU,EAAE,MAAM,CAAC,UAAU,IAAI,KAAK;YACtC,SAAS,EAAE,IAAI;YACf,OAAO,EAAE,MAAM,CAAC,OAAO;SACxB,CAAC;IACJ,CAAC;CACF;AAnKD,gEAmKC;AAED,MAAM,8BAA8B,GAAG,CAAC,MAAwB,EAAE,EAAE;IAClE,QAAQ,MAAM,CAAC,KAAK,EAAE;QACpB,KAAK,SAAS;YACZ,OAAO,0BAAa,CAAC,EAAE,CAAC;QAC1B,uBAAuB;QACvB,KAAK,SAAS;YACZ,OAAO,0BAAa,CAAC,OAAO,CAAC;QAC/B,KAAK,QAAQ,CAAC;QACd;YACE,OAAO,0BAAa,CAAC,GAAG,CAAC;KAC5B;AACH,CAAC,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/** @packageDocumentation\n * @module IModelComponents\n */\n\nimport { Observable } from \"rxjs\";\nimport { EMPTY } from \"rxjs/internal/observable/empty\";\nimport { from } from \"rxjs/internal/observable/from\";\nimport { map } from \"rxjs/internal/operators/map\";\nimport { mergeMap } from \"rxjs/internal/operators/mergeMap\";\nimport {\n CheckBoxInfo, CheckboxStateChange, TreeCheckboxStateChangeEventArgs, TreeModelNode, TreeNodeItem, TreeSelectionChange,\n TreeSelectionModificationEventArgs, TreeSelectionReplacementEventArgs,\n} from \"@itwin/components-react\";\nimport { BeEvent, IDisposable } from \"@itwin/core-bentley\";\nimport { CheckBoxState } from \"@itwin/core-react\";\nimport { UnifiedSelectionTreeEventHandler, UnifiedSelectionTreeEventHandlerParams } from \"@itwin/presentation-components\";\nimport { isPromiseLike } from \"../utils/IsPromiseLike\";\n\n/**\n * Data structure that describes instance visibility status.\n * @alpha\n */\nexport interface VisibilityStatus {\n state: \"visible\" | \"partial\" | \"hidden\";\n isDisabled?: boolean;\n tooltip?: string;\n}\n\n/**\n * Type definition of visibility change event listener.\n * @alpha\n */\nexport type VisibilityChangeListener = (nodeIds?: string[], visibilityStatus?: Map<string, VisibilityStatus>) => void;\n\n/**\n * Visibility handler used to change or get visibility of instances represented by the tree node.\n * @alpha\n */\nexport interface IVisibilityHandler extends IDisposable {\n getVisibilityStatus(node: TreeNodeItem): VisibilityStatus | Promise<VisibilityStatus>;\n changeVisibility(node: TreeNodeItem, shouldDisplay: boolean): Promise<void>;\n onVisibilityChange: BeEvent<VisibilityChangeListener>;\n}\n\n/**\n * Type definition of predicate used to decide if node can be selected.\n * @alpha\n */\nexport type VisibilityTreeSelectionPredicate = (node: TreeNodeItem) => boolean;\n\n/**\n * Parameters for [[VisibilityTreeEventHandler]]\n * @alpha\n */\nexport interface VisibilityTreeEventHandlerParams extends UnifiedSelectionTreeEventHandlerParams {\n visibilityHandler: IVisibilityHandler | undefined;\n selectionPredicate?: VisibilityTreeSelectionPredicate;\n}\n\n/**\n * Base event handler for visibility tree.\n * @alpha\n */\nexport class VisibilityTreeEventHandler extends UnifiedSelectionTreeEventHandler {\n private _visibilityHandler: IVisibilityHandler | undefined;\n private _selectionPredicate?: VisibilityTreeSelectionPredicate;\n private _listeners = new Array<() => void>();\n private _isChangingVisibility: boolean;\n\n constructor(params: VisibilityTreeEventHandlerParams) {\n super(params);\n this._visibilityHandler = params.visibilityHandler;\n this._selectionPredicate = params.selectionPredicate;\n this._isChangingVisibility = false;\n\n if (this._visibilityHandler) {\n this._listeners.push(this._visibilityHandler.onVisibilityChange.addListener(async (nodeIds, visibilityStatus) => {\n if (this._isChangingVisibility)\n return;\n void this.updateCheckboxes(nodeIds, visibilityStatus);\n }));\n }\n\n this._listeners.push(this.modelSource.onModelChanged.addListener(async ([_, changes]) => {\n void this.updateCheckboxes([...changes.addedNodeIds, ...changes.modifiedNodeIds]);\n }));\n this.updateCheckboxes(); // eslint-disable-line @typescript-eslint/no-floating-promises\n }\n\n public override dispose() {\n super.dispose();\n this._listeners.forEach((disposeFunc) => disposeFunc());\n }\n\n private filterSelectionItems(items: TreeNodeItem[]) {\n // istanbul ignore if\n if (!this._selectionPredicate)\n return items;\n\n return items.filter((item) => this._selectionPredicate!(item));\n }\n\n public override onSelectionModified({ modifications }: TreeSelectionModificationEventArgs) {\n const filteredModification = new Observable<TreeSelectionChange>((subscriber) => modifications.subscribe(subscriber)).pipe(\n map(({ selectedNodeItems, deselectedNodeItems }) => {\n return {\n selectedNodeItems: this.filterSelectionItems(selectedNodeItems),\n deselectedNodeItems: this.filterSelectionItems(deselectedNodeItems),\n };\n }),\n );\n return super.onSelectionModified({ modifications: filteredModification });\n }\n\n public override onSelectionReplaced({ replacements }: TreeSelectionReplacementEventArgs) {\n const filteredReplacements = new Observable<{ selectedNodeItems: TreeNodeItem[] }>((subscriber) => replacements.subscribe(subscriber)).pipe(\n map(({ selectedNodeItems }) => {\n return {\n selectedNodeItems: this.filterSelectionItems(selectedNodeItems),\n };\n }),\n );\n return super.onSelectionReplaced({ replacements: filteredReplacements });\n }\n\n public override onCheckboxStateChanged(event: TreeCheckboxStateChangeEventArgs) {\n const handleStateChanged = () => {\n this._isChangingVisibility = false;\n void this.updateCheckboxes();\n };\n // istanbul ignore if\n if (!this._visibilityHandler)\n return undefined;\n\n // eslint-disable-next-line deprecation/deprecation\n from(event.stateChanges)\n .pipe(\n // eslint-disable-next-line deprecation/deprecation\n mergeMap((changes) => this.changeVisibility(changes)),\n )\n // eslint-disable-next-line deprecation/deprecation\n .subscribe({\n complete: handleStateChanged,\n error: handleStateChanged,\n });\n return undefined;\n }\n\n private changeVisibility(changes: CheckboxStateChange[]) {\n // eslint-disable-next-line deprecation/deprecation\n return from(changes)\n .pipe(\n // eslint-disable-next-line deprecation/deprecation\n mergeMap(({ nodeItem, newState }) => {\n // istanbul ignore if\n if (!this._visibilityHandler)\n return EMPTY;\n this._isChangingVisibility = true;\n // eslint-disable-next-line deprecation/deprecation\n return from(this._visibilityHandler.changeVisibility(nodeItem, newState === CheckBoxState.On));\n }, 1),\n );\n }\n\n private async updateCheckboxes(affectedNodes?: string[], visibilityStatus?: Map<string, VisibilityStatus>) {\n const changes = await (affectedNodes ? this.collectAffectedNodesCheckboxInfos(affectedNodes, visibilityStatus) : this.collectAllNodesCheckboxInfos(visibilityStatus));\n this.updateModel(changes);\n }\n\n private updateModel(changes: Map<string, CheckBoxInfo>) {\n this.modelSource.modifyModel((model) => {\n for (const [nodeId, checkboxInfo] of changes) {\n const node = model.getNode(nodeId);\n // istanbul ignore if\n if (!node)\n continue;\n\n node.checkbox.isDisabled = checkboxInfo.isDisabled;\n node.checkbox.isVisible = checkboxInfo.isVisible;\n node.checkbox.state = checkboxInfo.state;\n node.checkbox.tooltip = checkboxInfo.tooltip;\n }\n });\n }\n\n private async collectAffectedNodesCheckboxInfos(affectedNodes: string[], visibilityStatus?: Map<string, VisibilityStatus>) {\n const nodeStates = new Map<string, CheckBoxInfo>();\n if (affectedNodes.length === 0)\n return nodeStates;\n\n await Promise.all(affectedNodes.map(async (nodeId) => {\n const node = this.modelSource.getModel().getNode(nodeId);\n // istanbul ignore else\n if (node)\n nodeStates.set(nodeId, await this.getNodeCheckBoxInfo(node, visibilityStatus));\n }));\n return nodeStates;\n }\n\n private async collectAllNodesCheckboxInfos(visibilityStatus?: Map<string, VisibilityStatus>) {\n const nodeStates = new Map<string, CheckBoxInfo>();\n for (const node of this.modelSource.getModel().iterateTreeModelNodes()) {\n nodeStates.set(node.id, await this.getNodeCheckBoxInfo(node, visibilityStatus));\n }\n return nodeStates;\n }\n\n private async getNodeCheckBoxInfo(node: TreeModelNode, visibilityStatus?: Map<string, VisibilityStatus>): Promise<CheckBoxInfo> {\n if (!this._visibilityHandler)\n return { ...node.checkbox, isVisible: false };\n\n const result = visibilityStatus?.get(node.id) ?? this._visibilityHandler.getVisibilityStatus(node.item);\n\n if (isPromiseLike(result))\n return this.createCheckboxInfo(await result);\n return this.createCheckboxInfo(result);\n }\n\n private createCheckboxInfo(status: VisibilityStatus): CheckBoxInfo {\n return {\n state: visibilityStateToCheckboxState(status),\n isDisabled: status.isDisabled || false,\n isVisible: true,\n tooltip: status.tooltip,\n };\n }\n}\n\nconst visibilityStateToCheckboxState = (status: VisibilityStatus) => {\n switch (status.state) {\n case \"visible\":\n return CheckBoxState.On;\n // istanbul ignore next\n case \"partial\":\n return CheckBoxState.Partial;\n case \"hidden\":\n default:\n return CheckBoxState.Off;\n }\n};\n"]}
|
|
@@ -59,7 +59,7 @@ exports.visibilityTreeNodeCheckboxRenderer = visibilityTreeNodeCheckboxRenderer;
|
|
|
59
59
|
* @alpha
|
|
60
60
|
*/
|
|
61
61
|
const useVisibilityTreeFiltering = (nodeLoader, filterInfo, onFilterApplied) => {
|
|
62
|
-
const { filter, activeMatchIndex } = filterInfo
|
|
62
|
+
const { filter, activeMatchIndex } = filterInfo ?? { filter: undefined, activeMatchIndex: undefined };
|
|
63
63
|
const { filteredNodeLoader, isFiltering, matchesCount, nodeHighlightingProps, } = (0, presentation_components_1.useControlledPresentationTreeFiltering)({ nodeLoader, filter, activeMatchIndex });
|
|
64
64
|
React.useEffect(() => {
|
|
65
65
|
if (filter && matchesCount !== undefined && filteredNodeLoader !== nodeLoader)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VisibilityTreeRenderer.js","sourceRoot":"","sources":["../../../../src/components/trees/VisibilityTreeRenderer.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;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AAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAC7D,QAAQ,EAAE,KAAK,CAAC,QAAQ,EACxB,KAAK,EAAE,KAAK,CAAC,KAAK,GAClB,CACH,CAAC;AATW,QAAA,kCAAkC,sCAS7C;AAEF;;;GAGG;AACI,MAAM,0BAA0B,GAAG,CACxC,UAA6E,EAC7E,UAAqC,EACrC,eAAqG,EACrG,EAAE;IACF,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"VisibilityTreeRenderer.js","sourceRoot":"","sources":["../../../../src/components/trees/VisibilityTreeRenderer.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;;;;;;;;;;;AAE/F,6CAA+B;AAC/B,8DAEiC;AAEjC,wDAAgD;AAChD,4EAAuH;AAGvH;;;GAGG;AACI,MAAM,yBAAyB,GAAG,CAAC,YAAqB,EAAE,mBAA4B,EAAE,EAAE;IAC/F,uDAAuD;IACvD,MAAM,YAAY,GAAG,KAAK,CAAC,WAAW,CAAC,IAAA,wCAAgC,EAAC,YAAY,EAAE,mBAAmB,CAAC,EAAE,CAAC,YAAY,EAAE,mBAAmB,CAAC,CAAC,CAAC;IACjJ,OAAO,KAAK,CAAC,WAAW,CAAC,CAAC,KAAwB,EAAE,EAAE,CAAC,CACrD,oBAAC,+BAAY,OACP,KAAK,EACT,YAAY,EAAE,YAAY,GAC1B,CACH,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;AACrB,CAAC,CAAC;AATW,QAAA,yBAAyB,6BASpC;AAEF,MAAM,WAAW,GAAG,IAAI,kCAAe,EAAE,CAAC;AAC1C;;;GAGG;AACI,MAAM,gCAAgC,GAAG,CAAC,YAAqB,EAAE,kBAA2B,EAAE,EAAE;IACrG,OAAO,CAAC,KAA4B,EAAE,EAAE,CAAC,EAAE,yCAAyC;IAClF,oBAAC,mCAAgB,OACX,KAAK,EACT,gBAAgB,EAAE,0CAAkC,E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kB,EAAE,eAAe,CAAC,CACxE,CAAC;IAEF,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,qBAAqB,EAAE,CAAC;AACpE,CAAC,CAAC;AAtBW,QAAA,0BAA0B,8BAsBrC;AAWF;;;GAGG;AACH,SAAgB,4BAA4B,CAAC,KAAwC;IACnF,OAAO,CACL,6BAAK,SAAS,EAAC,8BAA8B;QAC3C,8BAAM,SAAS,EAAC,qBAAqB,IAAE,KAAK,CAAC,KAAK,CAAQ;QAC1D,8BAAM,SAAS,EAAC,mBAAmB,IAAE,KAAK,CAAC,OAAO,CAAQ,CACtD,CACP,CAAC;AACJ,CAAC;AAPD,oEAOC","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 * as React from \"react\";\nimport {\n AbstractTreeNodeLoaderWithProvider, TreeImageLoader, TreeNodeRenderer, TreeNodeRendererProps, TreeRenderer, TreeRendererProps,\n} from \"@itwin/components-react\";\nimport { NodeCheckboxRenderProps } from \"@itwin/core-react\";\nimport { Checkbox } from \"@itwin/itwinui-react\";\nimport { IPresentationTreeDataProvider, useControlledPresentationTreeFiltering } from \"@itwin/presentation-components\";\nimport { VisibilityTreeFilterInfo } from \"./Common\";\n\n/**\n * Creates Visibility tree renderer which renders nodes with eye checkbox.\n * @alpha\n */\nexport const useVisibilityTreeRenderer = (iconsEnabled: boolean, descriptionsEnabled: boolean) => {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const nodeRenderer = React.useCallback(createVisibilityTreeNodeRenderer(iconsEnabled, descriptionsEnabled), [iconsEnabled, descriptionsEnabled]);\n return React.useCallback((props: TreeRendererProps) => (\n <TreeRenderer\n {...props}\n nodeRenderer={nodeRenderer}\n />\n ), [nodeRenderer]);\n};\n\nconst imageLoader = new TreeImageLoader();\n/**\n * Creates node renderer which renders node with eye checkbox.\n * @alpha\n */\nexport const createVisibilityTreeNodeRenderer = (iconsEnabled: boolean, descriptionEnabled: boolean) => {\n return (props: TreeNodeRendererProps) => ( // eslint-disable-line react/display-name\n <TreeNodeRenderer\n {...props}\n checkboxRenderer={visibilityTreeNodeCheckboxRenderer}\n descriptionEnabled={descriptionEnabled}\n imageLoader={iconsEnabled ? imageLoader : undefined}\n className=\"with-checkbox\"\n />\n );\n};\n\n/**\n * Checkbox renderer that renders an eye.\n * @alpha\n */\nexport const visibilityTreeNodeCheckboxRenderer = (props: NodeCheckboxRenderProps) => (\n <Checkbox\n className=\"visibility-tree-checkbox\"\n variant=\"eyeball\"\n checked={props.checked}\n onChange={(e) => { props.onChange(e.currentTarget.checked); }}\n disabled={props.disabled}\n title={props.title}\n />\n);\n\n/**\n * Filters data provider used in supplied node loader and invokes onFilterApplied when filtering is completed.\n * @alpha\n */\nexport const useVisibilityTreeFiltering = (\n nodeLoader: AbstractTreeNodeLoaderWithProvider<IPresentationTreeDataProvider>,\n filterInfo?: VisibilityTreeFilterInfo,\n onFilterApplied?: (filteredDataProvider: IPresentationTreeDataProvider, matchesCount: number) => void,\n) => {\n const { filter, activeMatchIndex } = filterInfo ?? { filter: undefined, activeMatchIndex: undefined };\n const {\n filteredNodeLoader,\n isFiltering,\n matchesCount,\n nodeHighlightingProps,\n } = useControlledPresentationTreeFiltering({ nodeLoader, filter, activeMatchIndex });\n\n React.useEffect(\n () => {\n if (filter && matchesCount !== undefined && filteredNodeLoader !== nodeLoader)\n onFilterApplied && onFilterApplied(filteredNodeLoader.dataProvider, matchesCount);\n },\n [filter, matchesCount, nodeLoader, filteredNodeLoader, onFilterApplied],\n );\n\n return { filteredNodeLoader, isFiltering, nodeHighlightingProps };\n};\n\n/**\n * Properties for [[VisibilityTreeNoFilteredData]] component.\n * @alpha\n */\nexport interface VisibilityTreeNoFilteredDataProps {\n title: string;\n message: string;\n}\n\n/**\n * Renders message that no nodes was found for filter.\n * @alpha\n */\nexport function VisibilityTreeNoFilteredData(props: VisibilityTreeNoFilteredDataProps) {\n return (\n <div className=\"components-tree-errormessage\">\n <span className=\"errormessage-header\">{props.title}</span>\n <span className=\"errormessage-body\">{props.message}</span>\n </div>\n );\n}\n"]}
|
|
@@ -46,7 +46,6 @@ exports.RULESET_CATEGORIES = require("./Categories.json"); // eslint-disable-lin
|
|
|
46
46
|
* @public
|
|
47
47
|
*/
|
|
48
48
|
function CategoryTree(props) {
|
|
49
|
-
var _a;
|
|
50
49
|
const { nodeLoader } = (0, presentation_components_1.usePresentationTreeNodeLoader)({
|
|
51
50
|
imodel: props.iModel,
|
|
52
51
|
ruleset: exports.RULESET_CATEGORIES,
|
|
@@ -54,9 +53,9 @@ function CategoryTree(props) {
|
|
|
54
53
|
});
|
|
55
54
|
const { filteredNodeLoader, isFiltering, nodeHighlightingProps } = (0, VisibilityTreeRenderer_1.useVisibilityTreeFiltering)(nodeLoader, props.filterInfo, props.onFilterApplied);
|
|
56
55
|
// istanbul ignore next
|
|
57
|
-
const viewManager =
|
|
56
|
+
const viewManager = props.viewManager ?? core_frontend_1.IModelApp.viewManager;
|
|
58
57
|
const { activeView, allViewports, categoryVisibilityHandler } = props;
|
|
59
|
-
const currentActiveView = activeView
|
|
58
|
+
const currentActiveView = activeView ?? viewManager.getFirstOpenView();
|
|
60
59
|
const visibilityHandler = useCategoryVisibilityHandler(viewManager, props.iModel, props.categories, currentActiveView, allViewports, categoryVisibilityHandler);
|
|
61
60
|
React.useEffect(() => {
|
|
62
61
|
setViewType(currentActiveView); // eslint-disable-line @typescript-eslint/no-floating-promises
|
|
@@ -81,7 +80,7 @@ exports.CategoryTree = CategoryTree;
|
|
|
81
80
|
function useCategoryVisibilityHandler(viewManager, imodel, categories, activeView, allViewports, visibilityHandler) {
|
|
82
81
|
return (0, core_react_1.useDisposable)(React.useCallback(() =>
|
|
83
82
|
// istanbul ignore next
|
|
84
|
-
visibilityHandler
|
|
83
|
+
visibilityHandler ?? new CategoryVisibilityHandler_1.CategoryVisibilityHandler({ viewManager, imodel, categories, activeView, allViewports }), [viewManager, imodel, categories, activeView, allViewports, visibilityHandler]));
|
|
85
84
|
}
|
|
86
85
|
async function setViewType(activeView) {
|
|
87
86
|
if (!activeView)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CategoriesTree.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoriesTree.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;;;;;;;;;;;AAE/F,sCAAoC;AACpC,6CAA+B;AAC/B,8DAAsF;AACtF,wDAA4G;AAC5G,kDAAkD;AAElD,4EAA8G;AAC9G,wEAA4D;AAC5D,oDAAiD;AAEjD,8EAA2E;AAC3E,sEAAgI;AAChI,2EAAsF;AAEtF,MAAM,WAAW,GAAG,EAAE,CAAC;AAEvB;;;GAGG;AACU,QAAA,kBAAkB,GAAY,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,yDAAyD;AA6ClI;;;GAGG;AACH,SAAgB,YAAY,CAAC,KAAwB
|
|
1
|
+
{"version":3,"file":"CategoriesTree.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoriesTree.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;;;;;;;;;;;AAE/F,sCAAoC;AACpC,6CAA+B;AAC/B,8DAAsF;AACtF,wDAA4G;AAC5G,kDAAkD;AAElD,4EAA8G;AAC9G,wEAA4D;AAC5D,oDAAiD;AAEjD,8EAA2E;AAC3E,sEAAgI;AAChI,2EAAsF;AAEtF,MAAM,WAAW,GAAG,EAAE,CAAC;AAEvB;;;GAGG;AACU,QAAA,kBAAkB,GAAY,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,yDAAyD;AA6ClI;;;GAGG;AACH,SAAgB,YAAY,CAAC,KAAwB;IACnD,MAAM,EAAE,UAAU,EAAE,GAAG,IAAA,uDAA6B,EAAC;QACnD,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,OAAO,EAAE,0BAAkB;Q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AI,CAAC,UAAU;QACb,OAAO;IAET,MAAM,IAAI,GAAG,UAAU,CAAC,IAAwB,CAAC;IACjD,iFAAiF;IACjF,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,yCAAyC;IACrF,MAAM,oCAAY,CAAC,YAAY,CAAC,IAAI,CAAC,0BAAkB,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AAC9F,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 \"../VisibilityTreeBase.scss\";\nimport * as React from \"react\";\nimport { ControlledTree, SelectionMode, useTreeModel } from \"@itwin/components-react\";\nimport { IModelApp, IModelConnection, SpatialViewState, ViewManager, Viewport } from \"@itwin/core-frontend\";\nimport { useDisposable } from \"@itwin/core-react\";\nimport { Ruleset } from \"@itwin/presentation-common\";\nimport { IPresentationTreeDataProvider, usePresentationTreeNodeLoader } from \"@itwin/presentation-components\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\nimport { TreeWidget } from \"../../../TreeWidget\";\nimport { VisibilityTreeFilterInfo } from \"../Common\";\nimport { VisibilityTreeEventHandler } from \"../VisibilityTreeEventHandler\";\nimport { useVisibilityTreeFiltering, useVisibilityTreeRenderer, VisibilityTreeNoFilteredData } from \"../VisibilityTreeRenderer\";\nimport { CategoryInfo, CategoryVisibilityHandler } from \"./CategoryVisibilityHandler\";\n\nconst PAGING_SIZE = 20;\n\n/**\n * Presentation rules used by ControlledCategoriesTree\n * @internal\n */\nexport const RULESET_CATEGORIES: Ruleset = require(\"./Categories.json\"); // eslint-disable-line @typescript-eslint/no-var-requires\n\n/**\n * Properties for the [[CategoryTree]] component\n * @public\n */\nexport interface CategoryTreeProps {\n /** Flag for accommodating all viewports */\n allViewports?: boolean;\n /** Active viewport */\n activeView?: Viewport;\n /**\n * An IModel to pull data from\n */\n iModel: IModelConnection;\n /** Width of the component */\n width: number;\n /** Height of the component */\n height: number;\n /**\n * Information for tree filtering.\n * @alpha\n */\n filterInfo?: VisibilityTreeFilterInfo;\n /**\n * Callback invoked when tree is filtered.\n */\n onFilterApplied?: (filteredDataProvider: IPresentationTreeDataProvider, matchesCount: number) => void;\n /**\n * Custom category visibility handler to use for testing\n * @internal\n */\n categoryVisibilityHandler?: CategoryVisibilityHandler;\n /**\n * Custom view manager to use for testing\n * @internal\n */\n viewManager?: ViewManager;\n\n /**\n * Available iModel categories\n */\n categories: CategoryInfo[];\n}\n\n/**\n * Tree which displays and manages categories contained in an iModel.\n * @public\n */\nexport function CategoryTree(props: CategoryTreeProps) {\n const { nodeLoader } = usePresentationTreeNodeLoader({\n imodel: props.iModel,\n ruleset: RULESET_CATEGORIES,\n pagingSize: PAGING_SIZE,\n });\n\n const { filteredNodeLoader, isFiltering, nodeHighlightingProps } = useVisibilityTreeFiltering(nodeLoader, props.filterInfo, props.onFilterApplied);\n // istanbul ignore next\n const viewManager = props.viewManager ?? IModelApp.viewManager;\n const { activeView, allViewports, categoryVisibilityHandler } = props;\n const currentActiveView = activeView ?? viewManager.getFirstOpenView();\n const visibilityHandler = useCategoryVisibilityHandler(viewManager, props.iModel, props.categories, currentActiveView, allViewports, categoryVisibilityHandler);\n\n React.useEffect(() => {\n setViewType(currentActiveView); // eslint-disable-line @typescript-eslint/no-floating-promises\n }, [currentActiveView]);\n\n const eventHandler = useDisposable(React.useCallback(() => new VisibilityTreeEventHandler({\n nodeLoader: filteredNodeLoader,\n visibilityHandler,\n collapsedChildrenDisposalEnabled: true,\n }), [filteredNodeLoader, visibilityHandler]));\n\n const treeModel = useTreeModel(filteredNodeLoader.modelSource);\n const treeRenderer = useVisibilityTreeRenderer(false, true);\n const overlay = isFiltering ? <div className=\"filteredTreeOverlay\" /> : undefined;\n const filterApplied = filteredNodeLoader !== nodeLoader;\n\n const noFilteredDataRenderer = React.useCallback(() => {\n return <VisibilityTreeNoFilteredData\n title={TreeWidget.translate(\"categoriesTree.noCategoryFound\")}\n message={TreeWidget.translate(\"categoriesTree.noMatchingCategoryNames\")}\n />;\n }, []);\n\n return (\n <div className=\"tree-widget-visibility-tree-base\">\n <ControlledTree\n nodeLoader={filteredNodeLoader}\n model={treeModel}\n selectionMode={SelectionMode.None}\n eventsHandler={eventHandler}\n treeRenderer={treeRenderer}\n descriptionsEnabled={true}\n nodeHighlightingProps={nodeHighlightingProps}\n noDataRenderer={filterApplied ? noFilteredDataRenderer : undefined}\n width={props.width}\n height={props.height}\n />\n {overlay}\n </div>\n );\n}\n\nfunction useCategoryVisibilityHandler(viewManager: ViewManager, imodel: IModelConnection, categories: CategoryInfo[], activeView?: Viewport, allViewports?: boolean, visibilityHandler?: CategoryVisibilityHandler) {\n return useDisposable(React.useCallback(\n () =>\n // istanbul ignore next\n visibilityHandler ?? new CategoryVisibilityHandler({ viewManager, imodel, categories, activeView, allViewports }),\n [viewManager, imodel, categories, activeView, allViewports, visibilityHandler]),\n );\n}\n\nasync function setViewType(activeView?: Viewport) {\n if (!activeView)\n return;\n\n const view = activeView.view as SpatialViewState;\n // TODO: remove this eslint rule when tree-widget uses itwinjs-core 4.0.0 version\n const viewType = view.is3d() ? \"3d\" : \"2d\"; // eslint-disable-line @itwin/no-internal\n await Presentation.presentation.vars(RULESET_CATEGORIES.id).setString(\"ViewType\", viewType);\n}\n"]}
|
|
@@ -51,7 +51,6 @@ CategoriesTreeComponent.ShowAllButton = ShowAllButton;
|
|
|
51
51
|
CategoriesTreeComponent.HideAllButton = HideAllButton;
|
|
52
52
|
CategoriesTreeComponent.InvertButton = InvertButton;
|
|
53
53
|
function CategoriesTreeComponentImpl(props) {
|
|
54
|
-
var _a;
|
|
55
54
|
const categories = (0, CategoryVisibilityHandler_1.useCategories)(core_frontend_1.IModelApp.viewManager, props.iModel, props.viewport);
|
|
56
55
|
const [filteredCategories, setFilteredCategories] = (0, react_1.useState)();
|
|
57
56
|
const { searchOptions, filterString, activeMatchIndex, onFilterApplied, filteredProvider, } = (0, TreeFilteringState_1.useTreeFilteringState)();
|
|
@@ -64,7 +63,7 @@ function CategoriesTreeComponentImpl(props) {
|
|
|
64
63
|
})();
|
|
65
64
|
}, [filteredProvider]);
|
|
66
65
|
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
67
|
-
react_1.default.createElement(SearchBar_1.SearchBar, { value: "", valueChangedDelay: 500, placeholder: TreeWidget_1.TreeWidget.translate("search"), title: TreeWidget_1.TreeWidget.translate("searchForSomething"), filteringInProgress: searchOptions.isFiltering, onFilterClear: searchOptions.onFilterCancel, onFilterStart: searchOptions.onFilterStart, onSelectedChanged: searchOptions.onResultSelectedChanged, resultCount:
|
|
66
|
+
react_1.default.createElement(SearchBar_1.SearchBar, { value: "", valueChangedDelay: 500, placeholder: TreeWidget_1.TreeWidget.translate("search"), title: TreeWidget_1.TreeWidget.translate("searchForSomething"), filteringInProgress: searchOptions.isFiltering, onFilterClear: searchOptions.onFilterCancel, onFilterStart: searchOptions.onFilterStart, onSelectedChanged: searchOptions.onResultSelectedChanged, resultCount: searchOptions.matchedResultCount ?? 0 }, props.headerButtons
|
|
68
67
|
? props.headerButtons.map((btn, index) => react_1.default.createElement(react_1.default.Fragment, { key: index }, btn({ viewport: props.viewport, categories, filteredCategories })))
|
|
69
68
|
: [
|
|
70
69
|
react_1.default.createElement(ShowAllButton, { viewport: props.viewport, categories: categories, filteredCategories: filteredCategories, key: "show-all-btn" }),
|
|
@@ -81,24 +80,21 @@ async function getFilteredCategories(filteredProvider) {
|
|
|
81
80
|
}
|
|
82
81
|
function ShowAllButton(props) {
|
|
83
82
|
const showAll = async () => {
|
|
84
|
-
|
|
85
|
-
await (0, CategoriesVisibilityUtils_1.enableCategory)(core_frontend_1.IModelApp.viewManager, props.viewport.iModel, ((_a = props.filteredCategories) !== null && _a !== void 0 ? _a : props.categories).map((category) => category.categoryId), true, true);
|
|
83
|
+
await (0, CategoriesVisibilityUtils_1.enableCategory)(core_frontend_1.IModelApp.viewManager, props.viewport.iModel, (props.filteredCategories ?? props.categories).map((category) => category.categoryId), true, true);
|
|
86
84
|
};
|
|
87
85
|
return (react_1.default.createElement(itwinui_react_1.IconButton, { className: "tree-widget-header-tree-toolbar-icon", size: "small", styleType: "borderless", title: TreeWidget_1.TreeWidget.translate("showAll"), onClick: showAll },
|
|
88
86
|
react_1.default.createElement(itwinui_icons_react_1.SvgVisibilityShow, null)));
|
|
89
87
|
}
|
|
90
88
|
function HideAllButton(props) {
|
|
91
89
|
const hideAll = async () => {
|
|
92
|
-
|
|
93
|
-
await (0, CategoriesVisibilityUtils_1.enableCategory)(core_frontend_1.IModelApp.viewManager, props.viewport.iModel, ((_a = props.filteredCategories) !== null && _a !== void 0 ? _a : props.categories).map((category) => category.categoryId), false, true);
|
|
90
|
+
await (0, CategoriesVisibilityUtils_1.enableCategory)(core_frontend_1.IModelApp.viewManager, props.viewport.iModel, (props.filteredCategories ?? props.categories).map((category) => category.categoryId), false, true);
|
|
94
91
|
};
|
|
95
92
|
return (react_1.default.createElement(itwinui_react_1.IconButton, { className: "tree-widget-header-tree-toolbar-icon", size: "small", styleType: "borderless", title: TreeWidget_1.TreeWidget.translate("hideAll"), onClick: hideAll },
|
|
96
93
|
react_1.default.createElement(itwinui_icons_react_1.SvgVisibilityHide, null)));
|
|
97
94
|
}
|
|
98
95
|
function InvertButton(props) {
|
|
99
96
|
const invert = async () => {
|
|
100
|
-
|
|
101
|
-
const ids = ((_a = props.filteredCategories) !== null && _a !== void 0 ? _a : props.categories).map((category) => category.categoryId);
|
|
97
|
+
const ids = (props.filteredCategories ?? props.categories).map((category) => category.categoryId);
|
|
102
98
|
const enabled = [];
|
|
103
99
|
const disabled = [];
|
|
104
100
|
for (const id of ids) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CategoriesTreeComponent.js","sourceRoot":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AAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,EAAE;gBACzC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;aAClB;iBAAM;gBACL,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;aACnB;SACF;QACD,kBAAkB;QAClB,MAAM,IAAA,0CAAc,EAClB,yBAAS,CAAC,WAAW,EACrB,KAAK,CAAC,QAAQ,CAAC,MAAM,EACrB,OAAO,EACP,KAAK,EACL,IAAI,CACL,CAAC;QAEF,kBAAkB;QAClB,MAAM,IAAA,0CAAc,EAClB,yBAAS,CAAC,WAAW,EACrB,KAAK,CAAC,QAAQ,CAAC,MAAM,EACrB,QAAQ,EACR,IAAI,EACJ,IAAI,CACL,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,CACL,8BAAC,0BAAU,IACT,SAAS,EAAC,sCAAsC,EAChD,KAAK,EAAE,uBAAU,CAAC,SAAS,CAAC,QAAQ,CAAC,EACrC,IAAI,EAAC,OAAO,EACZ,SAAS,EAAC,YAAY,EACtB,OAAO,EAAE,MAAM;QAEf,8BAAC,uCAAiB,OAAG,CACV,CACd,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*--------------------------------------------------------------------------------------------*/\nimport \"../VisibilityTreeBase.scss\";\nimport React, { useEffect, useState } from \"react\";\nimport { useActiveIModelConnection, useActiveViewport } from \"@itwin/appui-react\";\nimport { IModelApp, IModelConnection, ScreenViewport } from \"@itwin/core-frontend\";\nimport { SvgVisibilityHalf, SvgVisibilityHide, SvgVisibilityShow } from \"@itwin/itwinui-icons-react\";\nimport { IconButton } from \"@itwin/itwinui-react\";\nimport { IPresentationTreeDataProvider, isPresentationTreeNodeItem, PresentationTreeNodeItem } from \"@itwin/presentation-components\";\nimport { TreeWidget } from \"../../../TreeWidget\";\nimport { SearchBar } from \"../../search-bar/SearchBar\";\nimport { useTreeFilteringState } from \"../../TreeFilteringState\";\nimport { AutoSizer } from \"../../utils/AutoSizer\";\nimport { enableCategory } from \"../CategoriesVisibilityUtils\";\nimport { CategoryTree } from \"./CategoriesTree\";\nimport { CategoryInfo, CategoryVisibilityHandler, useCategories } from \"./CategoryVisibilityHandler\";\n\nimport type { CategoriesTreeHeaderButtonProps, CategoriesTreeProps } from \"../../../types\";\n\nexport function CategoriesTreeComponent(props: CategoriesTreeProps) {\n const iModel = useActiveIModelConnection();\n const viewport = useActiveViewport();\n\n if (!iModel || !viewport) {\n return null;\n }\n\n return (\n <CategoriesTreeComponentImpl {...props} iModel={iModel} viewport={viewport} />\n );\n}\n\nCategoriesTreeComponent.ShowAllButton = ShowAllButton;\nCategoriesTreeComponent.HideAllButton = HideAllButton;\nCategoriesTreeComponent.InvertButton = InvertButton;\n\nfunction CategoriesTreeComponentImpl(props: CategoriesTreeProps & { iModel: IModelConnection, viewport: ScreenViewport }) {\n const categories = useCategories(IModelApp.viewManager, props.iModel, props.viewport);\n const [filteredCategories, setFilteredCategories] = useState<CategoryInfo[]>();\n const {\n searchOptions,\n filterString,\n activeMatchIndex,\n onFilterApplied,\n filteredProvider,\n } = useTreeFilteringState();\n\n useEffect(() => {\n (async () => {\n if (filteredProvider)\n setFilteredCategories((await getFilteredCategories(filteredProvider)).map((category) => ({ categoryId: category })));\n else\n setFilteredCategories(undefined);\n })();\n }, [filteredProvider]);\n\n return (\n <>\n <SearchBar\n value=\"\"\n valueChangedDelay={500}\n placeholder={TreeWidget.translate(\"search\")}\n title={TreeWidget.translate(\"searchForSomething\")}\n filteringInProgress={searchOptions.isFiltering}\n onFilterClear={searchOptions.onFilterCancel}\n onFilterStart={searchOptions.onFilterStart}\n onSelectedChanged={searchOptions.onResultSelectedChanged}\n resultCount={searchOptions.matchedResultCount ?? 0}\n >\n {props.headerButtons\n ? props.headerButtons.map((btn, index) =>\n <React.Fragment key={index}>\n {btn({ viewport: props.viewport, categories, filteredCategories })}\n </React.Fragment>)\n : [\n <ShowAllButton viewport={props.viewport} categories={categories} filteredCategories={filteredCategories} key=\"show-all-btn\" />,\n <HideAllButton viewport={props.viewport} categories={categories} filteredCategories={filteredCategories} key=\"hide-all-btn\" />,\n <InvertButton viewport={props.viewport} categories={categories} filteredCategories={filteredCategories} key=\"invert-all-btn\" />,\n ]\n }\n </SearchBar>\n <AutoSizer>\n {({ width, height }) => (\n <CategoryTree\n {...props}\n categories={categories}\n width={width}\n height={height}\n filterInfo={{ filter: filterString, activeMatchIndex }}\n onFilterApplied={onFilterApplied}\n />\n )}\n </AutoSizer>\n </>\n );\n}\n\nasync function getFilteredCategories(filteredProvider: IPresentationTreeDataProvider) {\n const nodes = await filteredProvider.getNodes();\n return nodes\n .filter((node) => isPresentationTreeNodeItem(node))\n .map((node) => CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey((node as PresentationTreeNodeItem).key));\n}\n\nfunction ShowAllButton(props: CategoriesTreeHeaderButtonProps) {\n const showAll = async () => {\n await enableCategory(\n IModelApp.viewManager,\n props.viewport.iModel,\n (props.filteredCategories ?? props.categories).map((category) => category.categoryId),\n true,\n true,\n );\n };\n\n return (\n <IconButton\n className=\"tree-widget-header-tree-toolbar-icon\"\n size=\"small\"\n styleType=\"borderless\"\n title={TreeWidget.translate(\"showAll\")}\n onClick={showAll}\n >\n <SvgVisibilityShow />\n </IconButton>\n );\n}\n\nfunction HideAllButton(props: CategoriesTreeHeaderButtonProps) {\n const hideAll = async () => {\n await enableCategory(\n IModelApp.viewManager,\n props.viewport.iModel,\n (props.filteredCategories ?? props.categories).map((category) => category.categoryId),\n false,\n true,\n );\n };\n\n return (\n <IconButton\n className=\"tree-widget-header-tree-toolbar-icon\"\n size=\"small\"\n styleType=\"borderless\"\n title={TreeWidget.translate(\"hideAll\")}\n onClick={hideAll}\n >\n <SvgVisibilityHide />\n </IconButton>\n );\n}\n\nfunction InvertButton(props: CategoriesTreeHeaderButtonProps) {\n const invert = async () => {\n const ids = (props.filteredCategories ?? props.categories).map((category) => category.categoryId);\n\n const enabled: string[] = [];\n const disabled: string[] = [];\n for (const id of ids) {\n if (props.viewport.view.viewsCategory(id)) {\n enabled.push(id);\n } else {\n disabled.push(id);\n }\n }\n // Disable enabled\n await enableCategory(\n IModelApp.viewManager,\n props.viewport.iModel,\n enabled,\n false,\n true\n );\n\n // Enable disabled\n await enableCategory(\n IModelApp.viewManager,\n props.viewport.iModel,\n disabled,\n true,\n true\n );\n };\n\n return (\n <IconButton\n className=\"tree-widget-header-tree-toolbar-icon\"\n title={TreeWidget.translate(\"invert\")}\n size=\"small\"\n styleType=\"borderless\"\n onClick={invert}\n >\n <SvgVisibilityHalf />\n </IconButton>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CategoriesTreeComponent.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoriesTreeComponent.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,sCAAoC;AACpC,+CAAmD;AACnD,oDAAkF;AAClF,wDAAmF;AACnF,oEAAqG;AACrG,wDAAkD;AAClD,4EAAqI;AACrI,oDAAiD;AACjD,0DAAuD;AACvD,iEAAiE;AACjE,qDAAkD;AAClD,4EAA8D;AAC9D,qDAAgD;AAChD,2EAAqG;AAIrG,SAAgB,uBAAuB,CAAC,KAA0B;IAChE,MAAM,MAAM,GAAG,IAAA,uCAAyB,GAAE,CAAC;IAC3C,MAAM,QAAQ,GAAG,IAAA,+BAAiB,GAAE,CAAC;IAErC,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE;QACxB,OAAO,IAAI,CAAC;KACb;IAED,OAAO,CACL,8BAAC,2BAA2B,OAAK,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAI,CAC/E,CAAC;AACJ,CAAC;AAXD,0DAWC;AAED,uBAAuB,CAAC,aAAa,GAAG,aAAa,CAAC;AACtD,uBAAuB,CAAC,aAAa,GA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C,OAAO,EAAE,OAAO;QAEhB,8BAAC,uCAAiB,OAAG,CACV,CACd,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CAAC,KAAsC;IAC1D,MAAM,MAAM,GAAG,KAAK,IAAI,EAAE;QACxB,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,kBAAkB,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;QAElG,MAAM,OAAO,GAAa,EAAE,CAAC;QAC7B,MAAM,QAAQ,GAAa,EAAE,CAAC;QAC9B,KAAK,MAAM,EAAE,IAAI,GAAG,EAAE;YACpB,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,EAAE;gBACzC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;aAClB;iBAAM;gBACL,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;aACnB;SACF;QACD,kBAAkB;QAClB,MAAM,IAAA,0CAAc,EAClB,yBAAS,CAAC,WAAW,EACrB,KAAK,CAAC,QAAQ,CAAC,MAAM,EACrB,OAAO,EACP,KAAK,EACL,IAAI,CACL,CAAC;QAEF,kBAAkB;QAClB,MAAM,IAAA,0CAAc,EAClB,yBAAS,CAAC,WAAW,EACrB,KAAK,CAAC,QAAQ,CAAC,MAAM,EACrB,QAAQ,EACR,IAAI,EACJ,IAAI,CACL,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,CACL,8BAAC,0BAAU,IACT,SAAS,EAAC,sCAAsC,EAChD,KAAK,EAAE,uBAAU,CAAC,SAAS,CAAC,QAAQ,CAAC,EACrC,IAAI,EAAC,OAAO,EACZ,SAAS,EAAC,YAAY,EACtB,OAAO,EAAE,MAAM;QAEf,8BAAC,uCAAiB,OAAG,CACV,CACd,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*--------------------------------------------------------------------------------------------*/\nimport \"../VisibilityTreeBase.scss\";\nimport React, { useEffect, useState } from \"react\";\nimport { useActiveIModelConnection, useActiveViewport } from \"@itwin/appui-react\";\nimport { IModelApp, IModelConnection, ScreenViewport } from \"@itwin/core-frontend\";\nimport { SvgVisibilityHalf, SvgVisibilityHide, SvgVisibilityShow } from \"@itwin/itwinui-icons-react\";\nimport { IconButton } from \"@itwin/itwinui-react\";\nimport { IPresentationTreeDataProvider, isPresentationTreeNodeItem, PresentationTreeNodeItem } from \"@itwin/presentation-components\";\nimport { TreeWidget } from \"../../../TreeWidget\";\nimport { SearchBar } from \"../../search-bar/SearchBar\";\nimport { useTreeFilteringState } from \"../../TreeFilteringState\";\nimport { AutoSizer } from \"../../utils/AutoSizer\";\nimport { enableCategory } from \"../CategoriesVisibilityUtils\";\nimport { CategoryTree } from \"./CategoriesTree\";\nimport { CategoryInfo, CategoryVisibilityHandler, useCategories } from \"./CategoryVisibilityHandler\";\n\nimport type { CategoriesTreeHeaderButtonProps, CategoriesTreeProps } from \"../../../types\";\n\nexport function CategoriesTreeComponent(props: CategoriesTreeProps) {\n const iModel = useActiveIModelConnection();\n const viewport = useActiveViewport();\n\n if (!iModel || !viewport) {\n return null;\n }\n\n return (\n <CategoriesTreeComponentImpl {...props} iModel={iModel} viewport={viewport} />\n );\n}\n\nCategoriesTreeComponent.ShowAllButton = ShowAllButton;\nCategoriesTreeComponent.HideAllButton = HideAllButton;\nCategoriesTreeComponent.InvertButton = InvertButton;\n\nfunction CategoriesTreeComponentImpl(props: CategoriesTreeProps & { iModel: IModelConnection, viewport: ScreenViewport }) {\n const categories = useCategories(IModelApp.viewManager, props.iModel, props.viewport);\n const [filteredCategories, setFilteredCategories] = useState<CategoryInfo[]>();\n const {\n searchOptions,\n filterString,\n activeMatchIndex,\n onFilterApplied,\n filteredProvider,\n } = useTreeFilteringState();\n\n useEffect(() => {\n (async () => {\n if (filteredProvider)\n setFilteredCategories((await getFilteredCategories(filteredProvider)).map((category) => ({ categoryId: category })));\n else\n setFilteredCategories(undefined);\n })();\n }, [filteredProvider]);\n\n return (\n <>\n <SearchBar\n value=\"\"\n valueChangedDelay={500}\n placeholder={TreeWidget.translate(\"search\")}\n title={TreeWidget.translate(\"searchForSomething\")}\n filteringInProgress={searchOptions.isFiltering}\n onFilterClear={searchOptions.onFilterCancel}\n onFilterStart={searchOptions.onFilterStart}\n onSelectedChanged={searchOptions.onResultSelectedChanged}\n resultCount={searchOptions.matchedResultCount ?? 0}\n >\n {props.headerButtons\n ? props.headerButtons.map((btn, index) =>\n <React.Fragment key={index}>\n {btn({ viewport: props.viewport, categories, filteredCategories })}\n </React.Fragment>)\n : [\n <ShowAllButton viewport={props.viewport} categories={categories} filteredCategories={filteredCategories} key=\"show-all-btn\" />,\n <HideAllButton viewport={props.viewport} categories={categories} filteredCategories={filteredCategories} key=\"hide-all-btn\" />,\n <InvertButton viewport={props.viewport} categories={categories} filteredCategories={filteredCategories} key=\"invert-all-btn\" />,\n ]\n }\n </SearchBar>\n <AutoSizer>\n {({ width, height }) => (\n <CategoryTree\n {...props}\n categories={categories}\n width={width}\n height={height}\n filterInfo={{ filter: filterString, activeMatchIndex }}\n onFilterApplied={onFilterApplied}\n />\n )}\n </AutoSizer>\n </>\n );\n}\n\nasync function getFilteredCategories(filteredProvider: IPresentationTreeDataProvider) {\n const nodes = await filteredProvider.getNodes();\n return nodes\n .filter((node) => isPresentationTreeNodeItem(node))\n .map((node) => CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey((node as PresentationTreeNodeItem).key));\n}\n\nfunction ShowAllButton(props: CategoriesTreeHeaderButtonProps) {\n const showAll = async () => {\n await enableCategory(\n IModelApp.viewManager,\n props.viewport.iModel,\n (props.filteredCategories ?? props.categories).map((category) => category.categoryId),\n true,\n true,\n );\n };\n\n return (\n <IconButton\n className=\"tree-widget-header-tree-toolbar-icon\"\n size=\"small\"\n styleType=\"borderless\"\n title={TreeWidget.translate(\"showAll\")}\n onClick={showAll}\n >\n <SvgVisibilityShow />\n </IconButton>\n );\n}\n\nfunction HideAllButton(props: CategoriesTreeHeaderButtonProps) {\n const hideAll = async () => {\n await enableCategory(\n IModelApp.viewManager,\n props.viewport.iModel,\n (props.filteredCategories ?? props.categories).map((category) => category.categoryId),\n false,\n true,\n );\n };\n\n return (\n <IconButton\n className=\"tree-widget-header-tree-toolbar-icon\"\n size=\"small\"\n styleType=\"borderless\"\n title={TreeWidget.translate(\"hideAll\")}\n onClick={hideAll}\n >\n <SvgVisibilityHide />\n </IconButton>\n );\n}\n\nfunction InvertButton(props: CategoriesTreeHeaderButtonProps) {\n const invert = async () => {\n const ids = (props.filteredCategories ?? props.categories).map((category) => category.categoryId);\n\n const enabled: string[] = [];\n const disabled: string[] = [];\n for (const id of ids) {\n if (props.viewport.view.viewsCategory(id)) {\n enabled.push(id);\n } else {\n disabled.push(id);\n }\n }\n // Disable enabled\n await enableCategory(\n IModelApp.viewManager,\n props.viewport.iModel,\n enabled,\n false,\n true\n );\n\n // Enable disabled\n await enableCategory(\n IModelApp.viewManager,\n props.viewport.iModel,\n disabled,\n true,\n true\n );\n };\n\n return (\n <IconButton\n className=\"tree-widget-header-tree-toolbar-icon\"\n title={TreeWidget.translate(\"invert\")}\n size=\"small\"\n styleType=\"borderless\"\n onClick={invert}\n >\n <SvgVisibilityHalf />\n </IconButton>\n );\n}\n"]}
|
|
@@ -36,16 +36,14 @@ const EMPTY_CATEGORIES_ARRAY = [];
|
|
|
36
36
|
* @internal
|
|
37
37
|
*/
|
|
38
38
|
function useCategories(viewManager, imodel, view) {
|
|
39
|
-
var _a;
|
|
40
39
|
const currentView = view || viewManager.getFirstOpenView();
|
|
41
40
|
const categoriesPromise = React.useMemo(async () => (0, CategoriesVisibilityUtils_1.loadCategoriesFromViewport)(imodel, currentView), [imodel, currentView]);
|
|
42
|
-
return (
|
|
41
|
+
return (0, components_react_1.useAsyncValue)(categoriesPromise) ?? EMPTY_CATEGORIES_ARRAY;
|
|
43
42
|
}
|
|
44
43
|
exports.useCategories = useCategories;
|
|
45
44
|
/** @alpha */
|
|
46
45
|
class CategoryVisibilityHandler {
|
|
47
46
|
constructor(params) {
|
|
48
|
-
var _a;
|
|
49
47
|
this.onVisibilityChange = new core_bentley_1.BeEvent();
|
|
50
48
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
51
49
|
this.onDisplayStyleChanged = () => {
|
|
@@ -59,7 +57,7 @@ class CategoryVisibilityHandler {
|
|
|
59
57
|
this._imodel = params.imodel;
|
|
60
58
|
this._activeView = params.activeView;
|
|
61
59
|
// istanbul ignore next
|
|
62
|
-
this._useAllViewports =
|
|
60
|
+
this._useAllViewports = params.allViewports ?? false;
|
|
63
61
|
this._categories = params.categories;
|
|
64
62
|
if (this._activeView) {
|
|
65
63
|
this._activeView.onDisplayStyleChanged.addListener(this.onDisplayStyleChanged);
|
|
@@ -81,7 +79,6 @@ class CategoryVisibilityHandler {
|
|
|
81
79
|
return { state: node.parentId ? this.getSubCategoryVisibility(instanceId) : this.getCategoryVisibility(instanceId) };
|
|
82
80
|
}
|
|
83
81
|
async changeVisibility(node, shouldDisplay) {
|
|
84
|
-
var _a;
|
|
85
82
|
const nodeKey = (0, presentation_components_1.isPresentationTreeNodeItem)(node) ? node.key : undefined;
|
|
86
83
|
if (!nodeKey)
|
|
87
84
|
return;
|
|
@@ -89,7 +86,7 @@ class CategoryVisibilityHandler {
|
|
|
89
86
|
if (node.parentId) {
|
|
90
87
|
const childId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);
|
|
91
88
|
// istanbul ignore next
|
|
92
|
-
const parentId =
|
|
89
|
+
const parentId = this.getParent(childId)?.categoryId;
|
|
93
90
|
// make sure parent category is enabled
|
|
94
91
|
if (shouldDisplay && parentId)
|
|
95
92
|
await this.enableCategory([parentId], true, false);
|