@itwin/tree-widget-react 0.4.7 → 0.6.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.
Files changed (116) hide show
  1. package/lib/cjs/TreeWidget.js +4 -2
  2. package/lib/cjs/TreeWidget.js.map +1 -1
  3. package/lib/cjs/components/TreeWidgetUiItemsProvider.js +20 -12
  4. package/lib/cjs/components/TreeWidgetUiItemsProvider.js.map +1 -1
  5. package/lib/cjs/components/rulesets/ClassificationSystems.json +122 -0
  6. package/lib/cjs/components/rulesets/IModelContent.json +407 -407
  7. package/lib/cjs/components/trees/Common.d.ts +21 -0
  8. package/lib/cjs/components/trees/Common.js +21 -0
  9. package/lib/cjs/components/trees/Common.js.map +1 -0
  10. package/lib/cjs/components/trees/VisibilityTreeBase.scss +53 -0
  11. package/lib/cjs/components/trees/VisibilityTreeEventHandler.d.ts +67 -0
  12. package/lib/cjs/components/trees/VisibilityTreeEventHandler.js +147 -0
  13. package/lib/cjs/components/trees/VisibilityTreeEventHandler.js.map +1 -0
  14. package/lib/cjs/components/trees/VisibilityTreeRenderer.d.ts +43 -0
  15. package/lib/cjs/components/trees/VisibilityTreeRenderer.js +81 -0
  16. package/lib/cjs/components/trees/VisibilityTreeRenderer.js.map +1 -0
  17. package/lib/cjs/components/trees/category-tree/Categories.json +102 -0
  18. package/lib/cjs/components/trees/category-tree/CategoriesTree.d.ts +65 -0
  19. package/lib/cjs/components/trees/category-tree/CategoriesTree.js +121 -0
  20. package/lib/cjs/components/trees/category-tree/CategoriesTree.js.map +1 -0
  21. package/lib/{esm/components/trees → cjs/components/trees/category-tree}/CategoriesTree.scss +5 -0
  22. package/lib/cjs/components/trees/{CategoriesTree.d.ts → category-tree/CategoriesTreeComponent.d.ts} +2 -2
  23. package/lib/cjs/components/trees/{CategoriesTree.js → category-tree/CategoriesTreeComponent.js} +14 -13
  24. package/lib/cjs/components/trees/category-tree/CategoriesTreeComponent.js.map +1 -0
  25. package/lib/cjs/components/trees/category-tree/CategoryVisibilityHandler.d.ts +54 -0
  26. package/lib/cjs/components/trees/category-tree/CategoryVisibilityHandler.js +213 -0
  27. package/lib/cjs/components/trees/category-tree/CategoryVisibilityHandler.js.map +1 -0
  28. package/lib/cjs/components/trees/index.d.ts +10 -3
  29. package/lib/cjs/components/trees/index.js +13 -6
  30. package/lib/cjs/components/trees/index.js.map +1 -1
  31. package/lib/cjs/components/trees/models-tree/Hierarchy.GroupedByClass.json +392 -0
  32. package/lib/cjs/components/trees/models-tree/Hierarchy.json +387 -0
  33. package/lib/cjs/components/trees/models-tree/ModelsTree.d.ts +82 -0
  34. package/lib/cjs/components/trees/models-tree/ModelsTree.js +144 -0
  35. package/lib/cjs/components/trees/models-tree/ModelsTree.js.map +1 -0
  36. package/lib/cjs/components/trees/{ModelsTree.scss → models-tree/ModelsTree.scss} +5 -1
  37. package/lib/{esm/components/trees/ModelsTree.d.ts → cjs/components/trees/models-tree/ModelsTreeComponent.d.ts} +2 -2
  38. package/lib/cjs/components/trees/{ModelsTree.js → models-tree/ModelsTreeComponent.js} +6 -5
  39. package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.js.map +1 -0
  40. package/lib/cjs/components/trees/models-tree/ModelsTreeSearch.json +239 -0
  41. package/lib/cjs/components/trees/models-tree/ModelsVisibilityHandler.d.ts +100 -0
  42. package/lib/cjs/components/trees/models-tree/ModelsVisibilityHandler.js +477 -0
  43. package/lib/cjs/components/trees/models-tree/ModelsVisibilityHandler.js.map +1 -0
  44. package/lib/cjs/components/trees/models-tree/Utils.d.ts +10 -0
  45. package/lib/cjs/components/trees/models-tree/Utils.js +27 -0
  46. package/lib/cjs/components/trees/models-tree/Utils.js.map +1 -0
  47. package/lib/cjs/components/trees/{SpatialTree.d.ts → spatial-tree/SpatialTreeComponent.d.ts} +2 -2
  48. package/lib/cjs/components/trees/{SpatialTree.js → spatial-tree/SpatialTreeComponent.js} +2 -2
  49. package/lib/cjs/components/trees/spatial-tree/SpatialTreeComponent.js.map +1 -0
  50. package/lib/cjs/tree-widget-react.js +3 -3
  51. package/lib/cjs/tree-widget-react.js.map +1 -1
  52. package/lib/cjs/types.d.ts +7 -1
  53. package/lib/cjs/types.js +4 -0
  54. package/lib/cjs/types.js.map +1 -1
  55. package/lib/esm/TreeWidget.js +4 -2
  56. package/lib/esm/TreeWidget.js.map +1 -1
  57. package/lib/esm/components/TreeWidgetUiItemsProvider.js +17 -9
  58. package/lib/esm/components/TreeWidgetUiItemsProvider.js.map +1 -1
  59. package/lib/esm/components/rulesets/ClassificationSystems.json +122 -0
  60. package/lib/esm/components/rulesets/IModelContent.json +407 -407
  61. package/lib/esm/components/trees/Common.d.ts +21 -0
  62. package/lib/esm/components/trees/Common.js +18 -0
  63. package/lib/esm/components/trees/Common.js.map +1 -0
  64. package/lib/esm/components/trees/VisibilityTreeBase.scss +53 -0
  65. package/lib/esm/components/trees/VisibilityTreeEventHandler.d.ts +67 -0
  66. package/lib/esm/components/trees/VisibilityTreeEventHandler.js +143 -0
  67. package/lib/esm/components/trees/VisibilityTreeEventHandler.js.map +1 -0
  68. package/lib/esm/components/trees/VisibilityTreeRenderer.d.ts +43 -0
  69. package/lib/esm/components/trees/VisibilityTreeRenderer.js +54 -0
  70. package/lib/esm/components/trees/VisibilityTreeRenderer.js.map +1 -0
  71. package/lib/esm/components/trees/category-tree/Categories.json +102 -0
  72. package/lib/esm/components/trees/category-tree/CategoriesTree.d.ts +65 -0
  73. package/lib/esm/components/trees/category-tree/CategoriesTree.js +96 -0
  74. package/lib/esm/components/trees/category-tree/CategoriesTree.js.map +1 -0
  75. package/lib/{cjs/components/trees → esm/components/trees/category-tree}/CategoriesTree.scss +5 -0
  76. package/lib/esm/components/trees/{CategoriesTree.d.ts → category-tree/CategoriesTreeComponent.d.ts} +2 -2
  77. package/lib/esm/components/trees/{CategoriesTree.js → category-tree/CategoriesTreeComponent.js} +8 -7
  78. package/lib/esm/components/trees/category-tree/CategoriesTreeComponent.js.map +1 -0
  79. package/lib/esm/components/trees/category-tree/CategoryVisibilityHandler.d.ts +54 -0
  80. package/lib/esm/components/trees/category-tree/CategoryVisibilityHandler.js +188 -0
  81. package/lib/esm/components/trees/category-tree/CategoryVisibilityHandler.js.map +1 -0
  82. package/lib/esm/components/trees/index.d.ts +10 -3
  83. package/lib/esm/components/trees/index.js +13 -6
  84. package/lib/esm/components/trees/index.js.map +1 -1
  85. package/lib/esm/components/trees/models-tree/Hierarchy.GroupedByClass.json +392 -0
  86. package/lib/esm/components/trees/models-tree/Hierarchy.json +387 -0
  87. package/lib/esm/components/trees/models-tree/ModelsTree.d.ts +82 -0
  88. package/lib/esm/components/trees/models-tree/ModelsTree.js +121 -0
  89. package/lib/esm/components/trees/models-tree/ModelsTree.js.map +1 -0
  90. package/lib/esm/components/trees/{ModelsTree.scss → models-tree/ModelsTree.scss} +5 -1
  91. package/lib/{cjs/components/trees/ModelsTree.d.ts → esm/components/trees/models-tree/ModelsTreeComponent.d.ts} +2 -2
  92. package/lib/esm/components/trees/{ModelsTree.js → models-tree/ModelsTreeComponent.js} +6 -5
  93. package/lib/esm/components/trees/models-tree/ModelsTreeComponent.js.map +1 -0
  94. package/lib/esm/components/trees/models-tree/ModelsTreeSearch.json +239 -0
  95. package/lib/esm/components/trees/models-tree/ModelsVisibilityHandler.d.ts +100 -0
  96. package/lib/esm/components/trees/models-tree/ModelsVisibilityHandler.js +472 -0
  97. package/lib/esm/components/trees/models-tree/ModelsVisibilityHandler.js.map +1 -0
  98. package/lib/esm/components/trees/models-tree/Utils.d.ts +10 -0
  99. package/lib/esm/components/trees/models-tree/Utils.js +23 -0
  100. package/lib/esm/components/trees/models-tree/Utils.js.map +1 -0
  101. package/lib/esm/components/trees/{SpatialTree.d.ts → spatial-tree/SpatialTreeComponent.d.ts} +2 -2
  102. package/lib/esm/components/trees/{SpatialTree.js → spatial-tree/SpatialTreeComponent.js} +2 -2
  103. package/lib/esm/components/trees/spatial-tree/SpatialTreeComponent.js.map +1 -0
  104. package/lib/esm/tree-widget-react.js +3 -3
  105. package/lib/esm/tree-widget-react.js.map +1 -1
  106. package/lib/esm/types.d.ts +7 -1
  107. package/lib/esm/types.js +3 -1
  108. package/lib/esm/types.js.map +1 -1
  109. package/lib/public/locales/en/TreeWidget.json +39 -2
  110. package/package.json +54 -32
  111. package/lib/cjs/components/trees/CategoriesTree.js.map +0 -1
  112. package/lib/cjs/components/trees/ModelsTree.js.map +0 -1
  113. package/lib/cjs/components/trees/SpatialTree.js.map +0 -1
  114. package/lib/esm/components/trees/CategoriesTree.js.map +0 -1
  115. package/lib/esm/components/trees/ModelsTree.js.map +0 -1
  116. package/lib/esm/components/trees/SpatialTree.js.map +0 -1
@@ -0,0 +1,96 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ import "./CategoriesTree.scss";
6
+ import * as React from "react";
7
+ import { ControlledTree, SelectionMode, useTreeModel } from "@itwin/components-react";
8
+ import { IModelApp } from "@itwin/core-frontend";
9
+ import { useDisposable } from "@itwin/core-react";
10
+ import { usePresentationTreeNodeLoader } from "@itwin/presentation-components";
11
+ import { Presentation } from "@itwin/presentation-frontend";
12
+ import { TreeWidget } from "../../../TreeWidget";
13
+ import { VisibilityTreeEventHandler } from "../VisibilityTreeEventHandler";
14
+ import { useVisibilityTreeFiltering, useVisibilityTreeRenderer, VisibilityTreeNoFilteredData } from "../VisibilityTreeRenderer";
15
+ import { CategoryVisibilityHandler, loadCategoriesFromViewport, useCategories } from "./CategoryVisibilityHandler";
16
+ const PAGING_SIZE = 20;
17
+ /**
18
+ * Presentation rules used by ControlledCategoriesTree
19
+ * @internal
20
+ */
21
+ export const RULESET_CATEGORIES = require("./Categories.json"); // eslint-disable-line @typescript-eslint/no-var-requires
22
+ /**
23
+ * Tree which displays and manages categories contained in an iModel.
24
+ * @public
25
+ */
26
+ export function CategoryTree(props) {
27
+ var _a;
28
+ const { nodeLoader } = usePresentationTreeNodeLoader({
29
+ imodel: props.iModel,
30
+ ruleset: RULESET_CATEGORIES,
31
+ pagingSize: PAGING_SIZE,
32
+ });
33
+ const { filteredNodeLoader, isFiltering, nodeHighlightingProps } = useVisibilityTreeFiltering(nodeLoader, props.filterInfo, props.onFilterApplied);
34
+ // istanbul ignore next
35
+ const viewManager = (_a = props.viewManager) !== null && _a !== void 0 ? _a : IModelApp.viewManager;
36
+ const { activeView, allViewports, categoryVisibilityHandler } = props;
37
+ const currentActiveView = activeView !== null && activeView !== void 0 ? activeView : viewManager.getFirstOpenView();
38
+ const categories = useCategories(viewManager, props.iModel, currentActiveView);
39
+ const visibilityHandler = useCategoryVisibilityHandler(viewManager, props.iModel, categories, currentActiveView, allViewports, categoryVisibilityHandler);
40
+ React.useEffect(() => {
41
+ setViewType(currentActiveView); // eslint-disable-line @typescript-eslint/no-floating-promises
42
+ }, [currentActiveView]);
43
+ const eventHandler = useDisposable(React.useCallback(() => new VisibilityTreeEventHandler({
44
+ nodeLoader: filteredNodeLoader,
45
+ visibilityHandler,
46
+ collapsedChildrenDisposalEnabled: true,
47
+ }), [filteredNodeLoader, visibilityHandler]));
48
+ const treeModel = useTreeModel(filteredNodeLoader.modelSource);
49
+ const treeRenderer = useVisibilityTreeRenderer(false, true);
50
+ const overlay = isFiltering ? React.createElement("div", { className: "filteredTreeOverlay" }) : undefined;
51
+ const filterApplied = filteredNodeLoader !== nodeLoader;
52
+ const noFilteredDataRenderer = React.useCallback(() => {
53
+ return React.createElement(VisibilityTreeNoFilteredData, { title: TreeWidget.translate("categoriesTree.noCategoryFound"), message: TreeWidget.translate("categoriesTree.noMatchingCategoryNames") });
54
+ }, []);
55
+ return (React.createElement("div", { className: "tree-widget-categories-tree" },
56
+ React.createElement(ControlledTree, { nodeLoader: filteredNodeLoader, model: treeModel, selectionMode: SelectionMode.None, eventsHandler: eventHandler, treeRenderer: treeRenderer, descriptionsEnabled: true, nodeHighlightingProps: nodeHighlightingProps, noDataRenderer: filterApplied ? noFilteredDataRenderer : undefined, width: props.width, height: props.height }),
57
+ overlay));
58
+ }
59
+ function useCategoryVisibilityHandler(viewManager, imodel, categories, activeView, allViewports, visibilityHandler) {
60
+ return useDisposable(React.useCallback(() =>
61
+ // istanbul ignore next
62
+ visibilityHandler !== null && visibilityHandler !== void 0 ? visibilityHandler : new CategoryVisibilityHandler({ viewManager, imodel, categories, activeView, allViewports }), [viewManager, imodel, categories, activeView, allViewports, visibilityHandler]));
63
+ }
64
+ async function setViewType(activeView) {
65
+ if (!activeView)
66
+ return;
67
+ const view = activeView.view;
68
+ const viewType = view.is3d() ? "3d" : "2d";
69
+ await Presentation.presentation.vars(RULESET_CATEGORIES.id).setString("ViewType", viewType);
70
+ }
71
+ /**
72
+ * Toggles visibility of categories to show or hide.
73
+ * @alpha
74
+ */
75
+ export async function toggleAllCategories(viewManager, imodel, display, viewport, forAllViewports, filteredProvider) {
76
+ // istanbul ignore next
77
+ const activeView = viewport !== null && viewport !== void 0 ? viewport : viewManager.getFirstOpenView();
78
+ const ids = await getCategories(imodel, activeView, filteredProvider);
79
+ // istanbul ignore else
80
+ if (ids.length > 0) {
81
+ CategoryVisibilityHandler.enableCategory(viewManager, imodel, ids, display, forAllViewports !== null && forAllViewports !== void 0 ? forAllViewports : false);
82
+ }
83
+ }
84
+ /**
85
+ * Gets ids of all categories or categories from filtered data provider.
86
+ * @alpha
87
+ */
88
+ export async function getCategories(imodel, viewport, filteredProvider) {
89
+ if (filteredProvider) {
90
+ const nodes = await filteredProvider.getNodes();
91
+ return nodes.map((node) => CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(filteredProvider.getNodeKey(node)));
92
+ }
93
+ const categories = await loadCategoriesFromViewport(imodel, viewport);
94
+ return categories.map((category) => category.key);
95
+ }
96
+ //# sourceMappingURL=CategoriesTree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CategoriesTree.js","sourceRoot":"","sources":["../../../../../src/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ent":["/*---------------------------------------------------------------------------------------------\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 \"./CategoriesTree.scss\";\nimport * as React from \"react\";\nimport { ControlledTree, SelectionMode, useTreeModel } from \"@itwin/components-react\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { useDisposable } from \"@itwin/core-react\";\nimport { usePresentationTreeNodeLoader } from \"@itwin/presentation-components\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\nimport { TreeWidget } from \"../../../TreeWidget\";\nimport { VisibilityTreeEventHandler } from \"../VisibilityTreeEventHandler\";\nimport { useVisibilityTreeFiltering, useVisibilityTreeRenderer, VisibilityTreeNoFilteredData } from \"../VisibilityTreeRenderer\";\nimport { CategoryVisibilityHandler, loadCategoriesFromViewport, useCategories } from \"./CategoryVisibilityHandler\";\nimport type { IModelConnection, SpatialViewState, ViewManager, Viewport } from \"@itwin/core-frontend\";\nimport type { Ruleset } from \"@itwin/presentation-common\";\nimport type { IPresentationTreeDataProvider } from \"@itwin/presentation-components\";\nimport type { VisibilityTreeFilterInfo } from \"../Common\";\nimport type { Category } 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/**\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 categories = useCategories(viewManager, props.iModel, currentActiveView);\n const visibilityHandler = useCategoryVisibilityHandler(viewManager, props.iModel, 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-categories-tree\">\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: Category[], 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 const viewType = view.is3d() ? \"3d\" : \"2d\";\n await Presentation.presentation.vars(RULESET_CATEGORIES.id).setString(\"ViewType\", viewType);\n}\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, filteredProvider?: IPresentationTreeDataProvider) {\n // istanbul ignore next\n const activeView = viewport ?? viewManager.getFirstOpenView();\n const ids = await getCategories(imodel, activeView, filteredProvider);\n\n // istanbul ignore else\n if (ids.length > 0) {\n CategoryVisibilityHandler.enableCategory(viewManager, imodel, ids, display, forAllViewports ?? false);\n }\n}\n\n/**\n * Gets ids of all categories or categories from filtered data provider.\n * @alpha\n */\nexport async function getCategories(imodel: IModelConnection, viewport?: Viewport, filteredProvider?: IPresentationTreeDataProvider) {\n if (filteredProvider) {\n const nodes = await filteredProvider.getNodes();\n return nodes.map((node) => CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(filteredProvider.getNodeKey(node)));\n }\n\n const categories = await loadCategoriesFromViewport(imodel, viewport);\n return categories.map((category) => category.key);\n}\n"]}
@@ -3,6 +3,11 @@
3
3
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
  @import "~@itwin/core-react/lib/cjs/core-react/index";
6
+ @import "../VisibilityTreeBase";
7
+
8
+ .tree-widget-categories-tree {
9
+ @include tree-widget-visibility-tree-base;
10
+ }
6
11
 
7
12
  .tree-widget-category-tree-search-bar {
8
13
  margin-bottom: $uicore-s;
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import "./CategoriesTree.scss";
3
- import type { CategoriesTreeProps } from "../../types";
3
+ import type { CategoriesTreeProps } from "../../../types";
4
4
  export declare function CategoriesTreeComponent(props: CategoriesTreeProps): JSX.Element;
5
- //# sourceMappingURL=CategoriesTree.d.ts.map
5
+ //# sourceMappingURL=CategoriesTreeComponent.d.ts.map
@@ -2,14 +2,15 @@
2
2
  * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
3
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
4
  *--------------------------------------------------------------------------------------------*/
5
+ import "./CategoriesTree.scss";
5
6
  import React, { useCallback } from "react";
7
+ import { useActiveIModelConnection, useActiveViewport } from "@itwin/appui-react";
6
8
  import { IModelApp } from "@itwin/core-frontend";
7
- import { CategoryTree, getCategories, toggleAllCategories, useActiveIModelConnection, useActiveViewport } from "@itwin/appui-react";
8
- import { useTreeFilteringState } from "../TreeFilteringState";
9
- import "./CategoriesTree.scss";
10
- import { TreeHeaderComponent } from "../header/TreeHeader";
11
- import { CategoryVisibilityHandler } from "@itwin/appui-react";
12
- import { AutoSizer } from "../utils/AutoSizer";
9
+ import { CategoryTree, getCategories, toggleAllCategories } from "./CategoriesTree";
10
+ import { CategoryVisibilityHandler } from "./CategoryVisibilityHandler";
11
+ import { TreeHeaderComponent } from "../../header/TreeHeader";
12
+ import { useTreeFilteringState } from "../../TreeFilteringState";
13
+ import { AutoSizer } from "../../utils/AutoSizer";
13
14
  export function CategoriesTreeComponent(props) {
14
15
  const iModel = useActiveIModelConnection();
15
16
  const viewport = useActiveViewport();
@@ -48,4 +49,4 @@ export function CategoriesTreeComponent(props) {
48
49
  React.createElement(TreeHeaderComponent, { searchOptions: searchOptions, showAll: showAll, hideAll: hideAll, invert: invert }),
49
50
  React.createElement(AutoSizer, null, ({ width, height }) => (React.createElement(CategoryTree, { ...props, iModel: iModel, width: width, height: height, filterInfo: { filter: filterString, activeMatchIndex }, onFilterApplied: onFilterApplied }))))));
50
51
  }
51
- //# sourceMappingURL=CategoriesTree.js.map
52
+ //# sourceMappingURL=CategoriesTreeComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CategoriesTreeComponent.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoriesTreeComponent.tsx"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACpF,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGlD,MAAM,UAAU,uBAAuB,CAAC,KAA0B;IAChE,MAAM,MAAM,GAAG,yBAAyB,EAAE,CAAC;IAC3C,MAAM,QAAQ,GAAG,iBAAiB,EAAE,CAAC;IAErC,MAAM,EACJ,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,gBAAgB,GACjB,GAAG,qBAAqB,EAAE,CAAC;IAE5B,MAAM,OAAO,GAAG,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ACR,IAAI,EACJ,IAAI,CACL,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAEzC,OAAO,CACL,0CACG,MAAM,IAAI,QAAQ;QACjB;YACE,oBAAC,mBAAmB,IAClB,aAAa,EAAE,aAAa,EAC5B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,GACd;YACF,oBAAC,SAAS,QACP,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CACtB,oBAAC,YAAY,OACP,KAAK,EACT,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,gBAAgB,EAAE,EACtD,eAAe,EAAE,eAAe,GAChC,CACH,CACS,CACX,CAEJ,CACJ,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 \"./CategoriesTree.scss\";\nimport React, { useCallback } from \"react\";\nimport { useActiveIModelConnection, useActiveViewport } from \"@itwin/appui-react\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { CategoryTree, getCategories, toggleAllCategories } from \"./CategoriesTree\";\nimport { CategoryVisibilityHandler } from \"./CategoryVisibilityHandler\";\nimport { TreeHeaderComponent } from \"../../header/TreeHeader\";\nimport { useTreeFilteringState } from \"../../TreeFilteringState\";\nimport { AutoSizer } from \"../../utils/AutoSizer\";\nimport type { CategoriesTreeProps } from \"../../../types\";\n\nexport function CategoriesTreeComponent(props: CategoriesTreeProps) {\n const iModel = useActiveIModelConnection();\n const viewport = useActiveViewport();\n\n const {\n searchOptions,\n filterString,\n activeMatchIndex,\n onFilterApplied,\n filteredProvider,\n } = useTreeFilteringState();\n\n const showAll = useCallback(async () => {\n if (!iModel) return;\n\n return toggleAllCategories(\n IModelApp.viewManager,\n iModel,\n true,\n undefined,\n true,\n filteredProvider\n );\n }, [iModel, filteredProvider]);\n\n const hideAll = useCallback(async () => {\n if (!iModel) return;\n return toggleAllCategories(\n IModelApp.viewManager,\n iModel,\n false,\n undefined,\n true,\n filteredProvider\n );\n }, [iModel, filteredProvider]);\n\n const invert = useCallback(async () => {\n if (!iModel || !viewport) return;\n\n const ids = await getCategories(iModel, viewport, filteredProvider);\n const enabled: string[] = [];\n const disabled: string[] = [];\n for (const id of ids) {\n if (viewport.view.viewsCategory(id)) {\n enabled.push(id);\n } else {\n disabled.push(id);\n }\n }\n // Disable enabled\n CategoryVisibilityHandler.enableCategory(\n IModelApp.viewManager,\n iModel,\n enabled,\n false,\n true\n );\n // Enable disabled\n CategoryVisibilityHandler.enableCategory(\n IModelApp.viewManager,\n iModel,\n disabled,\n true,\n true\n );\n }, [iModel, viewport, filteredProvider]);\n\n return (\n <>\n {iModel && viewport &&\n <>\n <TreeHeaderComponent\n searchOptions={searchOptions}\n showAll={showAll}\n hideAll={hideAll}\n invert={invert}\n />\n <AutoSizer>\n {({ width, height }) => (\n <CategoryTree\n {...props}\n iModel={iModel}\n width={width}\n height={height}\n filterInfo={{ filter: filterString, activeMatchIndex }}\n onFilterApplied={onFilterApplied}\n />\n )}\n </AutoSizer>\n </>\n }\n </>\n );\n}\n"]}
@@ -0,0 +1,54 @@
1
+ import { BeEvent } from "@itwin/core-bentley";
2
+ import { NodeKey } from "@itwin/presentation-common";
3
+ import type { IModelConnection, ViewManager, Viewport } from "@itwin/core-frontend";
4
+ import type { TreeNodeItem } from "@itwin/components-react";
5
+ import type { IVisibilityHandler, VisibilityChangeListener, VisibilityStatus } from "../VisibilityTreeEventHandler";
6
+ /**
7
+ * Loads categories from viewport or uses provided list of categories.
8
+ * @internal
9
+ */
10
+ export declare function useCategories(viewManager: ViewManager, imodel: IModelConnection, view?: Viewport): Category[];
11
+ /** @internal */
12
+ export declare function loadCategoriesFromViewport(iModel?: IModelConnection, vp?: Viewport): Promise<Category[]>;
13
+ /**
14
+ * Data structure that describes category.
15
+ * @alpha
16
+ */
17
+ export interface Category {
18
+ key: string;
19
+ children?: string[];
20
+ }
21
+ /** @alpha */
22
+ export interface CategoryVisibilityHandlerParams {
23
+ viewManager: ViewManager;
24
+ imodel: IModelConnection;
25
+ categories: Category[];
26
+ activeView?: Viewport;
27
+ allViewports?: boolean;
28
+ }
29
+ /** @alpha */
30
+ export declare class CategoryVisibilityHandler implements IVisibilityHandler {
31
+ private _viewManager;
32
+ private _imodel;
33
+ private _pendingVisibilityChange;
34
+ private _activeView?;
35
+ private _useAllViewports;
36
+ private _categories;
37
+ constructor(params: CategoryVisibilityHandlerParams);
38
+ dispose(): void;
39
+ onVisibilityChange: BeEvent<VisibilityChangeListener>;
40
+ getVisibilityStatus(node: TreeNodeItem, nodeKey: NodeKey): VisibilityStatus;
41
+ changeVisibility(node: TreeNodeItem, nodeKey: NodeKey, shouldDisplay: boolean): Promise<void>;
42
+ getSubCategoryVisibility(id: string): "visible" | "hidden";
43
+ getCategoryVisibility(id: string): "visible" | "hidden";
44
+ getParent(key: string): Category | undefined;
45
+ private onDisplayStyleChanged;
46
+ private onViewedCategoriesChanged;
47
+ private onVisibilityChangeInternal;
48
+ static getInstanceIdFromTreeNodeKey(nodeKey: NodeKey): string;
49
+ /** Changes category display in the viewport */
50
+ static enableCategory(viewManager: ViewManager, imodel: IModelConnection, ids: string[], enabled: boolean, forAllViewports: boolean, enableAllSubCategories?: boolean): void;
51
+ /** Changes subcategory display in the viewport */
52
+ static enableSubCategory(viewManager: ViewManager, key: string, enabled: boolean, forAllViewports?: boolean): void;
53
+ }
54
+ //# sourceMappingURL=CategoryVisibilityHandler.d.ts.map
@@ -0,0 +1,188 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ import * as React from "react";
6
+ import { useAsyncValue } from "@itwin/components-react";
7
+ import { BeEvent } from "@itwin/core-bentley";
8
+ import { QueryRowFormat } from "@itwin/core-common";
9
+ import { PerModelCategoryVisibility } from "@itwin/core-frontend";
10
+ import { NodeKey } from "@itwin/presentation-common";
11
+ const EMPTY_CATEGORIES_ARRAY = [];
12
+ /**
13
+ * Loads categories from viewport or uses provided list of categories.
14
+ * @internal
15
+ */
16
+ export function useCategories(viewManager, imodel, view) {
17
+ var _a;
18
+ const currentView = view || viewManager.getFirstOpenView();
19
+ const categoriesPromise = React.useMemo(async () => loadCategoriesFromViewport(imodel, currentView), [imodel, currentView]);
20
+ return (_a = useAsyncValue(categoriesPromise)) !== null && _a !== void 0 ? _a : EMPTY_CATEGORIES_ARRAY;
21
+ }
22
+ /** @internal */
23
+ export async function loadCategoriesFromViewport(iModel, vp) {
24
+ if (!vp)
25
+ return EMPTY_CATEGORIES_ARRAY;
26
+ // Query categories and add them to state
27
+ const selectUsedSpatialCategoryIds = "SELECT DISTINCT Category.Id as id from BisCore.GeometricElement3d WHERE Category.Id IN (SELECT ECInstanceId from BisCore.SpatialCategory)";
28
+ const selectUsedDrawingCategoryIds = "SELECT DISTINCT Category.Id as id from BisCore.GeometricElement2d WHERE Model.Id=? AND Category.Id IN (SELECT ECInstanceId from BisCore.DrawingCategory)";
29
+ const ecsql = vp.view.is3d() ? selectUsedSpatialCategoryIds : selectUsedDrawingCategoryIds;
30
+ const ecsql2 = `SELECT ECInstanceId as id, UserLabel as label, CodeValue as code FROM ${vp.view.is3d() ? "BisCore.SpatialCategory" : "BisCore.DrawingCategory"} WHERE ECInstanceId IN (${ecsql})`;
31
+ const categories = [];
32
+ // istanbul ignore else
33
+ if (iModel) {
34
+ const rowIterator = iModel.query(ecsql2, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames });
35
+ // istanbul ignore next
36
+ for await (const row of rowIterator) {
37
+ const subCategoryIds = iModel.subcategories.getSubCategories(row.id);
38
+ categories.push({ key: row.id, children: (subCategoryIds) ? [...subCategoryIds] : undefined });
39
+ }
40
+ }
41
+ return categories;
42
+ }
43
+ /** @alpha */
44
+ export class CategoryVisibilityHandler {
45
+ constructor(params) {
46
+ var _a;
47
+ this.onVisibilityChange = new BeEvent();
48
+ // eslint-disable-next-line @typescript-eslint/naming-convention
49
+ this.onDisplayStyleChanged = () => {
50
+ this.onVisibilityChangeInternal();
51
+ };
52
+ // eslint-disable-next-line @typescript-eslint/naming-convention
53
+ this.onViewedCategoriesChanged = () => {
54
+ this.onVisibilityChangeInternal();
55
+ };
56
+ this._viewManager = params.viewManager;
57
+ this._imodel = params.imodel;
58
+ this._activeView = params.activeView;
59
+ // istanbul ignore next
60
+ this._useAllViewports = (_a = params.allViewports) !== null && _a !== void 0 ? _a : false;
61
+ this._categories = params.categories;
62
+ if (this._activeView) {
63
+ this._activeView.onDisplayStyleChanged.addListener(this.onDisplayStyleChanged);
64
+ this._activeView.onViewedCategoriesChanged.addListener(this.onViewedCategoriesChanged);
65
+ }
66
+ }
67
+ dispose() {
68
+ if (this._activeView) {
69
+ this._activeView.onDisplayStyleChanged.removeListener(this.onDisplayStyleChanged);
70
+ this._activeView.onViewedCategoriesChanged.removeListener(this.onViewedCategoriesChanged);
71
+ }
72
+ clearTimeout(this._pendingVisibilityChange);
73
+ }
74
+ getVisibilityStatus(node, nodeKey) {
75
+ const instanceId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);
76
+ return { state: node.parentId ? this.getSubCategoryVisibility(instanceId) : this.getCategoryVisibility(instanceId) };
77
+ }
78
+ async changeVisibility(node, nodeKey, shouldDisplay) {
79
+ var _a;
80
+ // handle subcategory visibility change
81
+ if (node.parentId) {
82
+ const childId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);
83
+ // istanbul ignore next
84
+ const parentId = (_a = this.getParent(childId)) === null || _a === void 0 ? void 0 : _a.key;
85
+ // make sure parent category is enabled
86
+ if (shouldDisplay && parentId)
87
+ CategoryVisibilityHandler.enableCategory(this._viewManager, this._imodel, [parentId], true, this._useAllViewports, false);
88
+ CategoryVisibilityHandler.enableSubCategory(this._viewManager, childId, shouldDisplay, this._useAllViewports);
89
+ return;
90
+ }
91
+ const instanceId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);
92
+ CategoryVisibilityHandler.enableCategory(this._viewManager, this._imodel, [instanceId], shouldDisplay, true);
93
+ }
94
+ getSubCategoryVisibility(id) {
95
+ const parentItem = this.getParent(id);
96
+ if (!parentItem || !this._activeView)
97
+ return "hidden";
98
+ const isVisible = this._activeView.view.viewsCategory(parentItem.key) && this._activeView.isSubCategoryVisible(id);
99
+ return isVisible ? "visible" : "hidden";
100
+ }
101
+ getCategoryVisibility(id) {
102
+ if (!this._activeView)
103
+ return "hidden";
104
+ return this._activeView.view.viewsCategory(id) ? "visible" : "hidden";
105
+ }
106
+ getParent(key) {
107
+ for (const category of this._categories) {
108
+ // istanbul ignore else
109
+ if (category.children) {
110
+ if (category.children.indexOf(key) !== -1)
111
+ return category;
112
+ }
113
+ }
114
+ return undefined;
115
+ }
116
+ onVisibilityChangeInternal() {
117
+ if (this._pendingVisibilityChange)
118
+ return;
119
+ this._pendingVisibilityChange = setTimeout(() => {
120
+ this.onVisibilityChange.raiseEvent();
121
+ this._pendingVisibilityChange = undefined;
122
+ }, 0);
123
+ }
124
+ static getInstanceIdFromTreeNodeKey(nodeKey) {
125
+ return (NodeKey.isInstancesNodeKey(nodeKey) && nodeKey.instanceKeys.length > 0) ? nodeKey.instanceKeys[0].id : /* istanbul ignore next */ "";
126
+ }
127
+ /** Changes category display in the viewport */
128
+ static enableCategory(viewManager, imodel, ids, enabled, forAllViewports, enableAllSubCategories = true) {
129
+ if (!viewManager.selectedView)
130
+ return;
131
+ const updateViewport = (vp) => {
132
+ // Only act on viewports that are both 3D or both 2D. Important if we have multiple viewports opened and we
133
+ // are using 'allViewports' property
134
+ if (viewManager.selectedView && viewManager.selectedView.view.is3d() === vp.view.is3d()) {
135
+ vp.changeCategoryDisplay(ids, enabled, enableAllSubCategories);
136
+ // remove category overrides per model
137
+ const modelsContainingOverrides = [];
138
+ for (const ovr of vp.perModelCategoryVisibility) {
139
+ // istanbul ignore else
140
+ if (ids.findIndex((id) => id === ovr.categoryId) !== -1)
141
+ modelsContainingOverrides.push(ovr.modelId);
142
+ }
143
+ vp.perModelCategoryVisibility.setOverride(modelsContainingOverrides, ids, PerModelCategoryVisibility.Override.None);
144
+ // changeCategoryDisplay only enables subcategories, it does not disabled them. So we must do that ourselves.
145
+ if (false === enabled) {
146
+ ids.forEach((id) => {
147
+ const subCategoryIds = imodel.subcategories.getSubCategories(id);
148
+ // istanbul ignore else
149
+ if (subCategoryIds) {
150
+ subCategoryIds.forEach((subCategoryId) => CategoryVisibilityHandler.enableSubCategory(viewManager, subCategoryId, false, forAllViewports));
151
+ }
152
+ });
153
+ }
154
+ }
155
+ };
156
+ // This property let us act on all viewports or just on the selected one, configurable by the app
157
+ if (forAllViewports) {
158
+ for (const viewport of viewManager) {
159
+ updateViewport(viewport);
160
+ }
161
+ }
162
+ else {
163
+ updateViewport(viewManager.selectedView);
164
+ }
165
+ }
166
+ /** Changes subcategory display in the viewport */
167
+ static enableSubCategory(viewManager, key, enabled, forAllViewports) {
168
+ if (!viewManager.selectedView)
169
+ return;
170
+ const updateViewport = (vp) => {
171
+ // Only act on viewports that are both 3D or both 2D. Important if we have multiple viewports opened and we
172
+ // are using 'allViewports' property
173
+ if (viewManager.selectedView && viewManager.selectedView.view.is3d() === vp.view.is3d()) {
174
+ vp.changeSubCategoryDisplay(key, enabled);
175
+ }
176
+ };
177
+ // This property let us act on all viewports or just on the selected one, configurable by the app
178
+ if (forAllViewports) {
179
+ for (const viewport of viewManager) {
180
+ updateViewport(viewport);
181
+ }
182
+ }
183
+ else {
184
+ updateViewport(viewManager.selectedView);
185
+ }
186
+ }
187
+ }
188
+ //# sourceMappingURL=CategoryVisibilityHandler.js.map
@@ -0,0 +1 @@
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,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAKrD,MAAM,sBAAsB,GAAe,EAAE,CAAC;AAE9C;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,WAAwB,EAAE,MAAwB,EAAE,IAAe;;IAC/F,MAAM,WAAW,GAAG,IAAI,IAAI,WAAW,CAAC,gBAAgB,EAAE,CAAC;IAC3D,MAAM,iBAAiB,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,0BAA0B,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAC5H,OAAO,MAAA,aAAa,CAAC,iBAAiB,CAAC,mCAAI,sBAAsB,CAAC;AACpE,CAAC;AAED,gBAAgB;AAChB,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAAC,MAAyB,EAAE,EAAa;IACvF,IAAI,CAAC,EAAE;QACL,OAAO,sBAAsB,CAAC;IAEhC,yCAAyC;IACzC,MAAM,4BAA4B,GAAG,2IAA2I,CAAC;IACjL,MAAM,4BAA4B,GAAG,0JAA0J,CAAC;IAChM,MAAM,KAAK,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,4BAA4B,C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gB,EAAE,eAAyB;QAChH,IAAI,CAAC,WAAW,CAAC,YAAY;YAC3B,OAAO;QAET,MAAM,cAAc,GAAG,CAAC,EAAY,EAAE,EAAE;YACtC,2GAA2G;YAC3G,oCAAoC;YACpC,IAAI,WAAW,CAAC,YAAY,IAAI,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE;gBACvF,EAAE,CAAC,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;aAC3C;QACH,CAAC,CAAC;QAEF,iGAAiG;QACjG,IAAI,eAAe,EAAE;YACnB,KAAK,MAAM,QAAQ,IAAI,WAAW,EAAE;gBAClC,cAAc,CAAC,QAAQ,CAAC,CAAC;aAC1B;SACF;aAAM;YACL,cAAc,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;SAC1C;IACH,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 { useAsyncValue } from \"@itwin/components-react\";\nimport { BeEvent } from \"@itwin/core-bentley\";\nimport { QueryRowFormat } from \"@itwin/core-common\";\nimport { PerModelCategoryVisibility } from \"@itwin/core-frontend\";\nimport { NodeKey } from \"@itwin/presentation-common\";\nimport type { IModelConnection, ViewManager, Viewport } from \"@itwin/core-frontend\";\nimport type { TreeNodeItem } from \"@itwin/components-react\";\nimport type { IVisibilityHandler, VisibilityChangeListener, VisibilityStatus } from \"../VisibilityTreeEventHandler\";\n\nconst EMPTY_CATEGORIES_ARRAY: Category[] = [];\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/** @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, UserLabel as label, CodeValue as code FROM ${vp.view.is3d() ? \"BisCore.SpatialCategory\" : \"BisCore.DrawingCategory\"} WHERE ECInstanceId IN (${ecsql})`;\n\n const categories: Category[] = [];\n\n // istanbul ignore else\n if (iModel) {\n const rowIterator = iModel.query(ecsql2, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames });\n // istanbul ignore next\n for await (const row of rowIterator) {\n const subCategoryIds = iModel.subcategories.getSubCategories(row.id);\n categories.push({ key: row.id, children: (subCategoryIds) ? [...subCategoryIds] : undefined });\n }\n }\n\n return categories;\n}\n\n/**\n * Data structure that describes category.\n * @alpha\n */\nexport interface Category {\n key: string;\n children?: string[];\n}\n\n/** @alpha */\nexport interface CategoryVisibilityHandlerParams {\n viewManager: ViewManager;\n imodel: IModelConnection;\n categories: Category[];\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: Category[];\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, nodeKey: NodeKey): VisibilityStatus {\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, nodeKey: NodeKey, shouldDisplay: boolean): Promise<void> {\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)?.key;\n\n // make sure parent category is enabled\n if (shouldDisplay && parentId)\n CategoryVisibilityHandler.enableCategory(this._viewManager, this._imodel, [parentId], true, this._useAllViewports, false);\n\n CategoryVisibilityHandler.enableSubCategory(this._viewManager, childId, shouldDisplay, this._useAllViewports);\n return;\n }\n\n const instanceId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);\n CategoryVisibilityHandler.enableCategory(this._viewManager, this._imodel, [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.key) && 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): Category | undefined {\n for (const category of this._categories) {\n // istanbul ignore else\n if (category.children) {\n if (category.children.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 /** Changes category display in the viewport */\n public static enableCategory(viewManager: ViewManager, imodel: IModelConnection, ids: string[], enabled: boolean, forAllViewports: boolean, enableAllSubCategories = true) {\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.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 ids.forEach((id) => {\n const subCategoryIds = imodel.subcategories.getSubCategories(id);\n // istanbul ignore else\n if (subCategoryIds) {\n subCategoryIds.forEach((subCategoryId) => CategoryVisibilityHandler.enableSubCategory(viewManager, subCategoryId, false, forAllViewports));\n }\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 updateViewport(viewport);\n }\n } else {\n updateViewport(viewManager.selectedView);\n }\n }\n\n /** Changes subcategory display in the viewport */\n public static 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"]}
@@ -1,5 +1,12 @@
1
- export * from "./ModelsTree";
2
- export * from "./CategoriesTree";
3
- export * from "./SpatialTree";
1
+ export * from "./Common";
4
2
  export * from "./IModelContentTree";
3
+ export * from "./VisibilityTreeEventHandler";
4
+ export * from "./VisibilityTreeRenderer";
5
+ export * from "./category-tree/CategoriesTree";
6
+ export * from "./category-tree/CategoriesTreeComponent";
7
+ export * from "./category-tree/CategoryVisibilityHandler";
8
+ export * from "./models-tree/ModelsTree";
9
+ export * from "./models-tree/ModelsTreeComponent";
10
+ export * from "./models-tree/ModelsVisibilityHandler";
11
+ export * from "./spatial-tree/SpatialTreeComponent";
5
12
  //# sourceMappingURL=index.d.ts.map
@@ -1,9 +1,16 @@
1
1
  /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
- * See LICENSE.md in the project root for license terms and full copyright notice.
4
- *--------------------------------------------------------------------------------------------*/
5
- export * from "./ModelsTree";
6
- export * from "./CategoriesTree";
7
- export * from "./SpatialTree";
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ export * from "./Common";
8
6
  export * from "./IModelContentTree";
7
+ export * from "./VisibilityTreeEventHandler";
8
+ export * from "./VisibilityTreeRenderer";
9
+ export * from "./category-tree/CategoriesTree";
10
+ export * from "./category-tree/CategoriesTreeComponent";
11
+ export * from "./category-tree/CategoryVisibilityHandler";
12
+ export * from "./models-tree/ModelsTree";
13
+ export * from "./models-tree/ModelsTreeComponent";
14
+ export * from "./models-tree/ModelsVisibilityHandler";
15
+ export * from "./spatial-tree/SpatialTreeComponent";
9
16
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/trees/index.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,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\nexport * from \"./ModelsTree\";\nexport * from \"./CategoriesTree\";\nexport * from \"./SpatialTree\";\nexport * from \"./IModelContentTree\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/trees/index.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AACzC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,yCAAyC,CAAC;AACxD,cAAc,2CAA2C,CAAC;AAC1D,cAAc,0BAA0B,CAAC;AACzC,cAAc,mCAAmC,CAAC;AAClD,cAAc,uCAAuC,CAAC;AACtD,cAAc,qCAAqC,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\nexport * from \"./Common\";\nexport * from \"./IModelContentTree\";\nexport * from \"./VisibilityTreeEventHandler\";\nexport * from \"./VisibilityTreeRenderer\";\nexport * from \"./category-tree/CategoriesTree\";\nexport * from \"./category-tree/CategoriesTreeComponent\";\nexport * from \"./category-tree/CategoryVisibilityHandler\";\nexport * from \"./models-tree/ModelsTree\";\nexport * from \"./models-tree/ModelsTreeComponent\";\nexport * from \"./models-tree/ModelsVisibilityHandler\";\nexport * from \"./spatial-tree/SpatialTreeComponent\";\n"]}