@itwin/tree-widget-react 0.9.0-dev.5 → 0.10.0-dev.1
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 +31 -31
|
@@ -18,40 +18,33 @@ export class TreeWidgetUiItemsProvider {
|
|
|
18
18
|
this.id = "TreeWidgetUiItemsProvider";
|
|
19
19
|
}
|
|
20
20
|
provideWidgets(_stageId, stageUsage, location, section) {
|
|
21
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
22
21
|
const widgets = [];
|
|
23
|
-
const preferredLocation =
|
|
24
|
-
const preferredPanelSection =
|
|
22
|
+
const preferredLocation = this._treeWidgetOptions?.defaultPanelLocation ?? StagePanelLocation.Right;
|
|
23
|
+
const preferredPanelSection = this._treeWidgetOptions?.defaultPanelSection ?? StagePanelSection.Start;
|
|
25
24
|
if (location === preferredLocation &&
|
|
26
25
|
section === preferredPanelSection &&
|
|
27
26
|
stageUsage === StageUsage.General) {
|
|
28
27
|
const trees = [];
|
|
29
|
-
if (!
|
|
28
|
+
if (!this._treeWidgetOptions?.hideTrees?.modelsTree) {
|
|
30
29
|
trees.push({
|
|
31
30
|
label: TreeWidget.translate("models"),
|
|
32
31
|
id: ModelsTreeId,
|
|
33
|
-
render: () => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
? ClassGroupingOption.YesWithCounts
|
|
37
|
-
: ClassGroupingOption.No, ...(_b = this._treeWidgetOptions) === null || _b === void 0 ? void 0 : _b.modelsTreeProps }));
|
|
38
|
-
},
|
|
32
|
+
render: () => (React.createElement(ModelsTreeComponent, { enableElementsClassGrouping: this._treeWidgetOptions?.enableElementsClassGrouping
|
|
33
|
+
? ClassGroupingOption.YesWithCounts
|
|
34
|
+
: ClassGroupingOption.No, ...this._treeWidgetOptions?.modelsTreeProps })),
|
|
39
35
|
});
|
|
40
36
|
}
|
|
41
|
-
if (!
|
|
37
|
+
if (!this._treeWidgetOptions?.hideTrees?.categoriesTree) {
|
|
42
38
|
trees.push({
|
|
43
39
|
label: TreeWidget.translate("categories"),
|
|
44
40
|
id: CategoriesTreeId,
|
|
45
|
-
render: () => {
|
|
46
|
-
var _a;
|
|
47
|
-
return (React.createElement(CategoriesTreeComponent, { ...(_a = this._treeWidgetOptions) === null || _a === void 0 ? void 0 : _a.categoriesTreeProps }));
|
|
48
|
-
},
|
|
41
|
+
render: () => (React.createElement(CategoriesTreeComponent, { ...this._treeWidgetOptions?.categoriesTreeProps })),
|
|
49
42
|
});
|
|
50
43
|
}
|
|
51
|
-
if (
|
|
44
|
+
if (this._treeWidgetOptions?.additionalTrees) {
|
|
52
45
|
trees.push(...this._treeWidgetOptions.additionalTrees);
|
|
53
46
|
}
|
|
54
|
-
if (
|
|
47
|
+
if (this._treeWidgetOptions?.defaultTreeId && trees.length !== 0) {
|
|
55
48
|
// Adding the defaultTree to first index
|
|
56
49
|
const { defaultTreeId } = this._treeWidgetOptions;
|
|
57
50
|
const extractedDefaultTree = trees.filter((tree) => tree.id === defaultTreeId)[0];
|
|
@@ -63,7 +56,7 @@ export class TreeWidgetUiItemsProvider {
|
|
|
63
56
|
label: TreeWidget.translate("treeview"),
|
|
64
57
|
content: React.createElement(TreeWidgetComponent, { trees: trees }),
|
|
65
58
|
icon: "icon-hierarchy-tree",
|
|
66
|
-
priority:
|
|
59
|
+
priority: this._treeWidgetOptions?.defaultTreeWidgetPriority,
|
|
67
60
|
});
|
|
68
61
|
}
|
|
69
62
|
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,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,UAAU,EAA2B,MAAM,oBAAoB,CAAC;AAEhH,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAqB,MAAM,UAAU,CAAC;AAC7E,OAAO,EAAE,uBAAuB,EAAE,MAAM,+CAA+C,CAAC;AACxF,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAC9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,MAAM,CAAC,MAAM,YAAY,GAAG,yBAAyB,CAAC;AACtD,MAAM,OAAO,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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AAO,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,YAAY;gBAChB,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,UAAU,CAAC;gBACvC,OAAO,EAAE,oBAAC,mBAAmB,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","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"]}
|
|
@@ -11,12 +11,12 @@ const EMPTY_CATEGORIES_ARRAY = [];
|
|
|
11
11
|
*/
|
|
12
12
|
export async function toggleAllCategories(viewManager, imodel, display, viewport, forAllViewports) {
|
|
13
13
|
// istanbul ignore next
|
|
14
|
-
const activeView = viewport
|
|
14
|
+
const activeView = viewport ?? viewManager.getFirstOpenView();
|
|
15
15
|
const ids = await getCategories(imodel, activeView);
|
|
16
16
|
// istanbul ignore if
|
|
17
17
|
if (ids.length === 0)
|
|
18
18
|
return;
|
|
19
|
-
await enableCategory(viewManager, imodel, ids, display, forAllViewports
|
|
19
|
+
await enableCategory(viewManager, imodel, ids, display, forAllViewports ?? false);
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Gets ids of all categories from specified imodel and viewport.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CategoriesVisibilityUtils.js","sourceRoot":"","sources":["../../../../src/components/trees/CategoriesVisibilityUtils.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAoB,0BAA0B,EAAyB,MAAM,sBAAsB,CAAC;AAG3G,MAAM,sBAAsB,GAAmB,EAAE,CAAC;AAElD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,WAAwB,EAAE,MAAwB,EAAE,OAAgB,EAAE,QAAmB,EAAE,eAAyB;IAC5J,uBAAuB;IACvB,MAAM,UAAU,GAAG,QAAQ,
|
|
1
|
+
{"version":3,"file":"CategoriesVisibilityUtils.js","sourceRoot":"","sources":["../../../../src/components/trees/CategoriesVisibilityUtils.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAoB,0BAA0B,EAAyB,MAAM,sBAAsB,CAAC;AAG3G,MAAM,sBAAsB,GAAmB,EAAE,CAAC;AAElD;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,WAAwB,EAAE,MAAwB,EAAE,OAAgB,EAAE,QAAmB,EAAE,eAAyB;IAC5J,uBAAuB;IACvB,MAAM,UAAU,GAAG,QAAQ,IAAI,WAAW,CAAC,gBAA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C,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","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"]}
|
|
@@ -135,10 +135,9 @@ export class VisibilityTreeEventHandler extends UnifiedSelectionTreeEventHandler
|
|
|
135
135
|
return nodeStates;
|
|
136
136
|
}
|
|
137
137
|
async getNodeCheckBoxInfo(node, visibilityStatus) {
|
|
138
|
-
var _a;
|
|
139
138
|
if (!this._visibilityHandler)
|
|
140
139
|
return { ...node.checkbox, isVisible: false };
|
|
141
|
-
const result =
|
|
140
|
+
const result = visibilityStatus?.get(node.id) ?? this._visibilityHandler.getVisibilityStatus(node.item);
|
|
142
141
|
if (isPromiseLike(result))
|
|
143
142
|
return this.createCheckboxInfo(await result);
|
|
144
143
|
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,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,GAAG,EAAE,MAAM,6BAA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E,MAAM,CAAC,OAAO;SACxB,CAAC;IACJ,CAAC;CACF;AAED,MAAM,8BAA8B,GAAG,CAAC,MAAwB,EAAE,EAAE;IAClE,QAAQ,MAAM,CAAC,KAAK,EAAE;QACpB,KAAK,SAAS;YACZ,OAAO,aAAa,CAAC,EAAE,CAAC;QAC1B,uBAAuB;QACvB,KAAK,SAAS;YACZ,OAAO,aAAa,CAAC,OAAO,CAAC;QAC/B,KAAK,QAAQ,CAAC;QACd;YACE,OAAO,aAAa,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,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,GAAG,EAAE,MAAM,6BAA6B,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAM5D,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,gCAAgC,EAA0C,MAAM,gCAAgC,CAAC;AAC1H,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AA2CvD;;;GAGG;AACH,MAAM,OAAO,0BAA2B,SAAQ,gCAAgC;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,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EAAE,CAAC,IAAI,IAAI,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAExG,IAAI,aAAa,CAAC,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;AAED,MAAM,8BAA8B,GAAG,CAAC,MAAwB,EAAE,EAAE;IAClE,QAAQ,MAAM,CAAC,KAAK,EAAE;QACpB,KAAK,SAAS;YACZ,OAAO,aAAa,CAAC,EAAE,CAAC;QAC1B,uBAAuB;QACvB,KAAK,SAAS;YACZ,OAAO,aAAa,CAAC,OAAO,CAAC;QAC/B,KAAK,QAAQ,CAAC;QACd;YACE,OAAO,aAAa,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"]}
|
|
@@ -34,7 +34,7 @@ export const visibilityTreeNodeCheckboxRenderer = (props) => (React.createElemen
|
|
|
34
34
|
* @alpha
|
|
35
35
|
*/
|
|
36
36
|
export const useVisibilityTreeFiltering = (nodeLoader, filterInfo, onFilterApplied) => {
|
|
37
|
-
const { filter, activeMatchIndex } = filterInfo
|
|
37
|
+
const { filter, activeMatchIndex } = filterInfo ?? { filter: undefined, activeMatchIndex: undefined };
|
|
38
38
|
const { filteredNodeLoader, isFiltering, matchesCount, nodeHighlightingProps, } = useControlledPresentationTreeFiltering({ nodeLoader, filter, activeMatchIndex });
|
|
39
39
|
React.useEffect(() => {
|
|
40
40
|
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;AAE/F,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAC+B,eAAe,E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,eAAe,IAAI,eAAe,CAAC,kBAAkB,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;IACtF,CAAC,EACD,CAAC,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,kBAAkB,EAAE,eAAe,CAAC,CACxE,CAAC;IAEF,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,qBAAqB,EAAE,CAAC;AACpE,CAAC,CAAC;AAWF;;;GAGG;AACH,MAAM,UAAU,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","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"]}
|
|
@@ -24,7 +24,6 @@ export const RULESET_CATEGORIES = require("./Categories.json"); // eslint-disabl
|
|
|
24
24
|
* @public
|
|
25
25
|
*/
|
|
26
26
|
export function CategoryTree(props) {
|
|
27
|
-
var _a;
|
|
28
27
|
const { nodeLoader } = usePresentationTreeNodeLoader({
|
|
29
28
|
imodel: props.iModel,
|
|
30
29
|
ruleset: RULESET_CATEGORIES,
|
|
@@ -32,9 +31,9 @@ export function CategoryTree(props) {
|
|
|
32
31
|
});
|
|
33
32
|
const { filteredNodeLoader, isFiltering, nodeHighlightingProps } = useVisibilityTreeFiltering(nodeLoader, props.filterInfo, props.onFilterApplied);
|
|
34
33
|
// istanbul ignore next
|
|
35
|
-
const viewManager =
|
|
34
|
+
const viewManager = props.viewManager ?? IModelApp.viewManager;
|
|
36
35
|
const { activeView, allViewports, categoryVisibilityHandler } = props;
|
|
37
|
-
const currentActiveView = activeView
|
|
36
|
+
const currentActiveView = activeView ?? viewManager.getFirstOpenView();
|
|
38
37
|
const visibilityHandler = useCategoryVisibilityHandler(viewManager, props.iModel, props.categories, currentActiveView, allViewports, categoryVisibilityHandler);
|
|
39
38
|
React.useEffect(() => {
|
|
40
39
|
setViewType(currentActiveView); // eslint-disable-line @typescript-eslint/no-floating-promises
|
|
@@ -58,7 +57,7 @@ export function CategoryTree(props) {
|
|
|
58
57
|
function useCategoryVisibilityHandler(viewManager, imodel, categories, activeView, allViewports, visibilityHandler) {
|
|
59
58
|
return useDisposable(React.useCallback(() =>
|
|
60
59
|
// istanbul ignore next
|
|
61
|
-
visibilityHandler
|
|
60
|
+
visibilityHandler ?? new CategoryVisibilityHandler({ viewManager, imodel, categories, activeView, allViewports }), [viewManager, imodel, categories, activeView, allViewports, visibilityHandler]));
|
|
62
61
|
}
|
|
63
62
|
async function setViewType(activeView) {
|
|
64
63
|
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,OAAO,4BAA4B,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACtF,OAAO,EAAE,SAAS,EAA6D,MAAM,sBAAsB,CAAC;AAC5G,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EAAiC,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAC9G,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,0BAA0B,EAAE,yBAAyB,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAC;AAChI,OAAO,EAAgB,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAEtF,MAAM,WAAW,GAAG,EAAE,CAAC;AAEvB;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAY,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,yDAAyD;AA6ClI;;;GAGG;AACH,MAAM,UAAU,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,OAAO,4BAA4B,CAAC;AACpC,OAAO,KAAK,KAAK,MAAM,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SAAS,EAChB,aAAa,EAAE,aAAa,CAAC,IAAI,EACjC,aAAa,EAAE,YAAY,EAC3B,YAAY,EAAE,YAAY,EAC1B,mBAAmB,EAAE,IAAI,EACzB,qBAAqB,EAAE,qBAAqB,EAC5C,cAAc,EAAE,aAAa,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,SAAS,EAClE,KAAK,EAAE,KAAK,CAAC,KAAK,EAClB,MAAM,EAAE,KAAK,CAAC,MAAM,GACpB;QACD,OAAO,CACJ,CACP,CAAC;AACJ,CAAC;AAED,SAAS,4BAA4B,CAAC,WAAwB,EAAE,MAAwB,EAAE,UAA0B,EAAE,UAAqB,EAAE,YAAsB,EAAE,iBAA6C;IAChN,OAAO,aAAa,CAAC,KAAK,CAAC,WAAW,CACpC,GAAG,EAAE;IACH,uBAAuB;IACvB,iBAAiB,IAAI,IAAI,yBAAyB,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,EACnH,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,iBAAiB,CAAC,CAAC,CAChF,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,WAAW,CAAC,UAAqB;IAC9C,IAAI,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,YAAY,CAAC,YAAY,CAAC,IAAI,CAAC,kBAAkB,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"]}
|
|
@@ -28,7 +28,6 @@ CategoriesTreeComponent.ShowAllButton = ShowAllButton;
|
|
|
28
28
|
CategoriesTreeComponent.HideAllButton = HideAllButton;
|
|
29
29
|
CategoriesTreeComponent.InvertButton = InvertButton;
|
|
30
30
|
function CategoriesTreeComponentImpl(props) {
|
|
31
|
-
var _a;
|
|
32
31
|
const categories = useCategories(IModelApp.viewManager, props.iModel, props.viewport);
|
|
33
32
|
const [filteredCategories, setFilteredCategories] = useState();
|
|
34
33
|
const { searchOptions, filterString, activeMatchIndex, onFilterApplied, filteredProvider, } = useTreeFilteringState();
|
|
@@ -41,7 +40,7 @@ function CategoriesTreeComponentImpl(props) {
|
|
|
41
40
|
})();
|
|
42
41
|
}, [filteredProvider]);
|
|
43
42
|
return (React.createElement(React.Fragment, null,
|
|
44
|
-
React.createElement(SearchBar, { value: "", valueChangedDelay: 500, placeholder: TreeWidget.translate("search"), title: TreeWidget.translate("searchForSomething"), filteringInProgress: searchOptions.isFiltering, onFilterClear: searchOptions.onFilterCancel, onFilterStart: searchOptions.onFilterStart, onSelectedChanged: searchOptions.onResultSelectedChanged, resultCount:
|
|
43
|
+
React.createElement(SearchBar, { value: "", valueChangedDelay: 500, placeholder: TreeWidget.translate("search"), title: TreeWidget.translate("searchForSomething"), filteringInProgress: searchOptions.isFiltering, onFilterClear: searchOptions.onFilterCancel, onFilterStart: searchOptions.onFilterStart, onSelectedChanged: searchOptions.onResultSelectedChanged, resultCount: searchOptions.matchedResultCount ?? 0 }, props.headerButtons
|
|
45
44
|
? props.headerButtons.map((btn, index) => React.createElement(React.Fragment, { key: index }, btn({ viewport: props.viewport, categories, filteredCategories })))
|
|
46
45
|
: [
|
|
47
46
|
React.createElement(ShowAllButton, { viewport: props.viewport, categories: categories, filteredCategories: filteredCategories, key: "show-all-btn" }),
|
|
@@ -58,24 +57,21 @@ async function getFilteredCategories(filteredProvider) {
|
|
|
58
57
|
}
|
|
59
58
|
function ShowAllButton(props) {
|
|
60
59
|
const showAll = async () => {
|
|
61
|
-
|
|
62
|
-
await enableCategory(IModelApp.viewManager, props.viewport.iModel, ((_a = props.filteredCategories) !== null && _a !== void 0 ? _a : props.categories).map((category) => category.categoryId), true, true);
|
|
60
|
+
await enableCategory(IModelApp.viewManager, props.viewport.iModel, (props.filteredCategories ?? props.categories).map((category) => category.categoryId), true, true);
|
|
63
61
|
};
|
|
64
62
|
return (React.createElement(IconButton, { className: "tree-widget-header-tree-toolbar-icon", size: "small", styleType: "borderless", title: TreeWidget.translate("showAll"), onClick: showAll },
|
|
65
63
|
React.createElement(SvgVisibilityShow, null)));
|
|
66
64
|
}
|
|
67
65
|
function HideAllButton(props) {
|
|
68
66
|
const hideAll = async () => {
|
|
69
|
-
|
|
70
|
-
await enableCategory(IModelApp.viewManager, props.viewport.iModel, ((_a = props.filteredCategories) !== null && _a !== void 0 ? _a : props.categories).map((category) => category.categoryId), false, true);
|
|
67
|
+
await enableCategory(IModelApp.viewManager, props.viewport.iModel, (props.filteredCategories ?? props.categories).map((category) => category.categoryId), false, true);
|
|
71
68
|
};
|
|
72
69
|
return (React.createElement(IconButton, { className: "tree-widget-header-tree-toolbar-icon", size: "small", styleType: "borderless", title: TreeWidget.translate("hideAll"), onClick: hideAll },
|
|
73
70
|
React.createElement(SvgVisibilityHide, null)));
|
|
74
71
|
}
|
|
75
72
|
function InvertButton(props) {
|
|
76
73
|
const invert = async () => {
|
|
77
|
-
|
|
78
|
-
const ids = ((_a = props.filteredCategories) !== null && _a !== void 0 ? _a : props.categories).map((category) => category.categoryId);
|
|
74
|
+
const ids = (props.filteredCategories ?? props.categories).map((category) => category.categoryId);
|
|
79
75
|
const enabled = [];
|
|
80
76
|
const disabled = [];
|
|
81
77
|
for (const id of ids) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CategoriesTreeComponent.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoriesTreeComponent.tsx"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,SAAS,EAAoC,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACrG,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAiC,0BAA0B,EAA4B,MAAM,gCAAgC,CAAC;AACrI,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAgB,yBAAyB,EAAE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WAAW,EACrB,KAAK,CAAC,QAAQ,CAAC,MAAM,EACrB,QAAQ,EACR,IAAI,EACJ,IAAI,CACL,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,CACL,oBAAC,UAAU,IACT,SAAS,EAAC,sCAAsC,EAChD,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,QAAQ,CAAC,EACrC,IAAI,EAAC,OAAO,EACZ,SAAS,EAAC,YAAY,EACtB,OAAO,EAAE,MAAM;QAEf,oBAAC,iBAAiB,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,OAAO,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,SAAS,EAAoC,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACrG,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAiC,0BAA0B,EAA4B,MAAM,gCAAgC,CAAC;AACrI,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAgB,yBAAyB,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAIrG,MAAM,UAAU,uBAAuB,CAAC,KAA0B;IAChE,MAAM,MAAM,GAAG,yBAAyB,EAAE,CAAC;IAC3C,MAAM,QAAQ,GAAG,iBAAiB,EAAE,CAAC;IAErC,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE;QACxB,OAAO,IAAI,CAAC;KACb;IAED,OAAO,CACL,oBAAC,2BAA2B,OAAK,KAAK,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V,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"]}
|
|
@@ -14,15 +14,13 @@ const EMPTY_CATEGORIES_ARRAY = [];
|
|
|
14
14
|
* @internal
|
|
15
15
|
*/
|
|
16
16
|
export function useCategories(viewManager, imodel, view) {
|
|
17
|
-
var _a;
|
|
18
17
|
const currentView = view || viewManager.getFirstOpenView();
|
|
19
18
|
const categoriesPromise = React.useMemo(async () => loadCategoriesFromViewport(imodel, currentView), [imodel, currentView]);
|
|
20
|
-
return
|
|
19
|
+
return useAsyncValue(categoriesPromise) ?? EMPTY_CATEGORIES_ARRAY;
|
|
21
20
|
}
|
|
22
21
|
/** @alpha */
|
|
23
22
|
export class CategoryVisibilityHandler {
|
|
24
23
|
constructor(params) {
|
|
25
|
-
var _a;
|
|
26
24
|
this.onVisibilityChange = new BeEvent();
|
|
27
25
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
28
26
|
this.onDisplayStyleChanged = () => {
|
|
@@ -36,7 +34,7 @@ export class CategoryVisibilityHandler {
|
|
|
36
34
|
this._imodel = params.imodel;
|
|
37
35
|
this._activeView = params.activeView;
|
|
38
36
|
// istanbul ignore next
|
|
39
|
-
this._useAllViewports =
|
|
37
|
+
this._useAllViewports = params.allViewports ?? false;
|
|
40
38
|
this._categories = params.categories;
|
|
41
39
|
if (this._activeView) {
|
|
42
40
|
this._activeView.onDisplayStyleChanged.addListener(this.onDisplayStyleChanged);
|
|
@@ -58,7 +56,6 @@ export class CategoryVisibilityHandler {
|
|
|
58
56
|
return { state: node.parentId ? this.getSubCategoryVisibility(instanceId) : this.getCategoryVisibility(instanceId) };
|
|
59
57
|
}
|
|
60
58
|
async changeVisibility(node, shouldDisplay) {
|
|
61
|
-
var _a;
|
|
62
59
|
const nodeKey = isPresentationTreeNodeItem(node) ? node.key : undefined;
|
|
63
60
|
if (!nodeKey)
|
|
64
61
|
return;
|
|
@@ -66,7 +63,7 @@ export class CategoryVisibilityHandler {
|
|
|
66
63
|
if (node.parentId) {
|
|
67
64
|
const childId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);
|
|
68
65
|
// istanbul ignore next
|
|
69
|
-
const parentId =
|
|
66
|
+
const parentId = this.getParent(childId)?.categoryId;
|
|
70
67
|
// make sure parent category is enabled
|
|
71
68
|
if (shouldDisplay && parentId)
|
|
72
69
|
await this.enableCategory([parentId], true, false);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CategoryVisibilityH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I,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,gBAAgB,EAAE,sBAAsB,CAAC,CAAC;IACrH,CAAC;IAEM,iBAAiB,CAAC,GAAW,EAAE,OAAgB;QACpD,iBAAiB,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC5E,CAAC;CACF","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 { TreeNodeItem, useAsyncValue } from \"@itwin/components-react\";\nimport { BeEvent } from \"@itwin/core-bentley\";\nimport { IModelConnection, ViewManager, Viewport } from \"@itwin/core-frontend\";\nimport { NodeKey } from \"@itwin/presentation-common\";\nimport { isPresentationTreeNodeItem } from \"@itwin/presentation-components\";\nimport { enableCategory, enableSubCategory, loadCategoriesFromViewport } from \"../CategoriesVisibilityUtils\";\nimport { 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 = React.useMemo(async () => loadCategoriesFromViewport(imodel, currentView), [imodel, currentView]);\n return useAsyncValue(categoriesPromise) ?? EMPTY_CATEGORIES_ARRAY;\n}\n\n/**\n * Data structure that describes category.\n * @alpha\n */\nexport interface CategoryInfo {\n categoryId: string;\n subCategoryIds?: string[];\n}\n\n/** @alpha */\nexport interface CategoryVisibilityHandlerParams {\n viewManager: ViewManager;\n imodel: IModelConnection;\n categories: CategoryInfo[];\n activeView?: Viewport;\n allViewports?: boolean;\n}\n\n/** @alpha */\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 if (this._activeView) {\n this._activeView.onDisplayStyleChanged.addListener(this.onDisplayStyleChanged);\n this._activeView.onViewedCategoriesChanged.addListener(this.onViewedCategoriesChanged);\n }\n }\n\n public dispose() {\n if (this._activeView) {\n this._activeView.onDisplayStyleChanged.removeListener(this.onDisplayStyleChanged);\n this._activeView.onViewedCategoriesChanged.removeListener(this.onViewedCategoriesChanged);\n }\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 || !this._activeView)\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 if (!this._activeView)\n return \"hidden\";\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"]}
|
|
1
|
+
{"version":3,"file":"CategoryVisibilityHandler.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoryVisibilityHandler.tsx"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,KAAK,KAAK,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ACpD,iBAAiB,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC5E,CAAC;CACF","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 { TreeNodeItem, useAsyncValue } from \"@itwin/components-react\";\nimport { BeEvent } from \"@itwin/core-bentley\";\nimport { IModelConnection, ViewManager, Viewport } from \"@itwin/core-frontend\";\nimport { NodeKey } from \"@itwin/presentation-common\";\nimport { isPresentationTreeNodeItem } from \"@itwin/presentation-components\";\nimport { enableCategory, enableSubCategory, loadCategoriesFromViewport } from \"../CategoriesVisibilityUtils\";\nimport { 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 = React.useMemo(async () => loadCategoriesFromViewport(imodel, currentView), [imodel, currentView]);\n return useAsyncValue(categoriesPromise) ?? EMPTY_CATEGORIES_ARRAY;\n}\n\n/**\n * Data structure that describes category.\n * @alpha\n */\nexport interface CategoryInfo {\n categoryId: string;\n subCategoryIds?: string[];\n}\n\n/** @alpha */\nexport interface CategoryVisibilityHandlerParams {\n viewManager: ViewManager;\n imodel: IModelConnection;\n categories: CategoryInfo[];\n activeView?: Viewport;\n allViewports?: boolean;\n}\n\n/** @alpha */\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 if (this._activeView) {\n this._activeView.onDisplayStyleChanged.addListener(this.onDisplayStyleChanged);\n this._activeView.onViewedCategoriesChanged.addListener(this.onViewedCategoriesChanged);\n }\n }\n\n public dispose() {\n if (this._activeView) {\n this._activeView.onDisplayStyleChanged.removeListener(this.onDisplayStyleChanged);\n this._activeView.onViewedCategoriesChanged.removeListener(this.onViewedCategoriesChanged);\n }\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 || !this._activeView)\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 if (!this._activeView)\n return \"hidden\";\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"]}
|