@itwin/tree-widget-react 3.4.2 → 3.5.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 (54) hide show
  1. package/CHANGELOG.md +10 -2
  2. package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.d.ts +10 -2
  3. package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js +246 -129
  4. package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js.map +1 -1
  5. package/lib/cjs/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js +70 -17
  6. package/lib/cjs/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js.map +1 -1
  7. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.d.ts +54 -0
  8. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js +285 -0
  9. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js.map +1 -0
  10. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.d.ts +26 -0
  11. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.js +26 -0
  12. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.js.map +1 -0
  13. package/lib/cjs/tree-widget-react/components/trees/categories-tree/{CategoriesVisibilityHandler.d.ts → internal/CategoriesVisibilityHandler.d.ts} +18 -9
  14. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js +218 -0
  15. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js.map +1 -0
  16. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.d.ts +7 -0
  17. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.js +14 -0
  18. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.js.map +1 -0
  19. package/lib/cjs/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.d.ts +0 -4
  20. package/lib/cjs/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js +1 -2
  21. package/lib/cjs/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js.map +1 -1
  22. package/lib/cjs/tree-widget-react/components/trees/common/UseHierarchyVisibility.js.map +1 -1
  23. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.d.ts +2 -1
  24. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js +3 -0
  25. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
  26. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.d.ts +10 -2
  27. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js +246 -129
  28. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js.map +1 -1
  29. package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js +72 -19
  30. package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js.map +1 -1
  31. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.d.ts +54 -0
  32. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js +280 -0
  33. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js.map +1 -0
  34. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.d.ts +26 -0
  35. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.js +23 -0
  36. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.js.map +1 -0
  37. package/lib/esm/tree-widget-react/components/trees/categories-tree/{CategoriesVisibilityHandler.d.ts → internal/CategoriesVisibilityHandler.d.ts} +18 -9
  38. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js +214 -0
  39. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js.map +1 -0
  40. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.d.ts +7 -0
  41. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.js +11 -0
  42. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.js.map +1 -0
  43. package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.d.ts +0 -4
  44. package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js +1 -1
  45. package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js.map +1 -1
  46. package/lib/esm/tree-widget-react/components/trees/common/UseHierarchyVisibility.js.map +1 -1
  47. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.d.ts +2 -1
  48. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js +3 -0
  49. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
  50. package/package.json +1 -1
  51. package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesVisibilityHandler.js +0 -91
  52. package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesVisibilityHandler.js.map +0 -1
  53. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesVisibilityHandler.js +0 -87
  54. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesVisibilityHandler.js.map +0 -1
@@ -0,0 +1,23 @@
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
+ /**
6
+ * @internal
7
+ */
8
+ export var CategoriesTreeNode;
9
+ (function (CategoriesTreeNode) {
10
+ /**
11
+ * Determines if node represents a definition container.
12
+ */
13
+ CategoriesTreeNode.isDefinitionContainerNode = (node) => node.extendedData && "isDefinitionContainer" in node.extendedData && !!node.extendedData.isDefinitionContainer;
14
+ /**
15
+ * Determines if node represents a category.
16
+ */
17
+ CategoriesTreeNode.isCategoryNode = (node) => node.extendedData && "isCategory" in node.extendedData && !!node.extendedData.isCategory;
18
+ /**
19
+ * Determines if node represents a sub-category.
20
+ */
21
+ CategoriesTreeNode.isSubCategoryNode = (node) => node.extendedData && "isSubCategory" in node.extendedData && !!node.extendedData.isSubCategory;
22
+ })(CategoriesTreeNode || (CategoriesTreeNode = {}));
23
+ //# sourceMappingURL=CategoriesTreeNode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CategoriesTreeNode.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAShG;;GAEG;AACH,MAAM,KAAW,kBAAkB,CAkBlC;AAlBD,WAAiB,kBAAkB;IACjC;;OAEG;IACU,4CAAyB,GAAG,CAAC,IAA8C,EAAE,EAAE,CAC1F,IAAI,CAAC,YAAY,IAAI,uBAAuB,IAAI,IAAI,CAAC,YAAY,IAAI,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,qBAAqB,CAAC;IAEjH;;OAEG;IACU,iCAAc,GAAG,CAAC,IAA8C,EAAE,EAAE,CAC/E,IAAI,CAAC,YAAY,IAAI,YAAY,IAAI,IAAI,CAAC,YAAY,IAAI,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC;IAE3F;;OAEG;IACU,oCAAiB,GAAG,CAAC,IAA8C,EAAE,EAAE,CAClF,IAAI,CAAC,YAAY,IAAI,eAAe,IAAI,IAAI,CAAC,YAAY,IAAI,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC;AACnG,CAAC,EAlBgB,kBAAkB,KAAlB,kBAAkB,QAkBlC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport type { HierarchyNodeKey } from \"@itwin/presentation-hierarchies\";\n\ninterface CategoriesTreeNode {\n key: HierarchyNodeKey;\n extendedData?: { [id: string]: any };\n}\n\n/**\n * @internal\n */\nexport namespace CategoriesTreeNode {\n /**\n * Determines if node represents a definition container.\n */\n export const isDefinitionContainerNode = (node: Pick<CategoriesTreeNode, \"extendedData\">) =>\n node.extendedData && \"isDefinitionContainer\" in node.extendedData && !!node.extendedData.isDefinitionContainer;\n\n /**\n * Determines if node represents a category.\n */\n export const isCategoryNode = (node: Pick<CategoriesTreeNode, \"extendedData\">) =>\n node.extendedData && \"isCategory\" in node.extendedData && !!node.extendedData.isCategory;\n\n /**\n * Determines if node represents a sub-category.\n */\n export const isSubCategoryNode = (node: Pick<CategoriesTreeNode, \"extendedData\">) =>\n node.extendedData && \"isSubCategory\" in node.extendedData && !!node.extendedData.isSubCategory;\n}\n"]}
@@ -1,28 +1,37 @@
1
1
  import { BeEvent } from "@itwin/core-bentley";
2
2
  import { HierarchyNode } from "@itwin/presentation-hierarchies";
3
3
  import type { Viewport } from "@itwin/core-frontend";
4
- import type { HierarchyVisibilityHandler, VisibilityStatus } from "../common/UseHierarchyVisibility.js";
5
- interface CategoriesVisibilityHandlerProps {
4
+ import type { HierarchyVisibilityHandler, VisibilityStatus } from "../../common/UseHierarchyVisibility.js";
5
+ import type { CategoriesTreeIdsCache } from "./CategoriesTreeIdsCache.js";
6
+ /** @internal */
7
+ export interface CategoriesVisibilityHandlerProps {
6
8
  viewport: Viewport;
9
+ idsCache: CategoriesTreeIdsCache;
7
10
  }
8
11
  /** @internal */
9
12
  export declare class CategoriesVisibilityHandler implements HierarchyVisibilityHandler {
10
13
  private _pendingVisibilityChange;
11
14
  private _viewport;
15
+ private _idsCache;
12
16
  constructor(props: CategoriesVisibilityHandlerProps);
13
17
  dispose(): void;
18
+ [Symbol.dispose](): void;
14
19
  onVisibilityChange: BeEvent<import("@itwin/core-bentley").Listener>;
15
20
  /** Returns visibility status of the tree node. */
16
- getVisibilityStatus(node: HierarchyNode): Promise<VisibilityStatus> | VisibilityStatus;
21
+ getVisibilityStatus(node: HierarchyNode): Promise<VisibilityStatus>;
17
22
  changeVisibility(node: HierarchyNode, on: boolean): Promise<void>;
18
- getSubCategoryVisibility(node: HierarchyNode): "visible" | "hidden";
19
- getCategoryVisibility(node: HierarchyNode): "visible" | "hidden";
23
+ private getSubCategoryVisibility;
24
+ private getDefinitionContainerVisibility;
25
+ private getCategoriesVisibility;
26
+ private getCategoryVisibilityFromOverrides;
27
+ private changeSubCategoryVisibility;
28
+ private changeCategoryVisibility;
29
+ private changeDefinitionContainerVisibility;
20
30
  private onDisplayStyleChanged;
21
31
  private onViewedCategoriesChanged;
22
32
  private onVisibilityChangeInternal;
23
- static getInstanceIdFromHierarchyNode(node: HierarchyNode): string;
24
- enableCategory(ids: string[], enabled: boolean, enableAllSubCategories?: boolean): Promise<void>;
25
- enableSubCategory(key: string, enabled: boolean): void;
33
+ private static getInstanceIdsFromHierarchyNode;
34
+ private changeCategoryState;
35
+ private changeSubCategoryState;
26
36
  }
27
- export {};
28
37
  //# sourceMappingURL=CategoriesVisibilityHandler.d.ts.map
@@ -0,0 +1,214 @@
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 { BeEvent } from "@itwin/core-bentley";
6
+ import { HierarchyNode } from "@itwin/presentation-hierarchies";
7
+ import { enableCategoryDisplay, enableSubCategoryDisplay } from "../../common/CategoriesVisibilityUtils.js";
8
+ import { createVisibilityStatus } from "../../common/Tooltip.js";
9
+ import { CategoriesTreeNode } from "./CategoriesTreeNode.js";
10
+ /** @internal */
11
+ export class CategoriesVisibilityHandler {
12
+ constructor(props) {
13
+ this.onVisibilityChange = new BeEvent();
14
+ // eslint-disable-next-line @typescript-eslint/naming-convention
15
+ this.onDisplayStyleChanged = () => {
16
+ this.onVisibilityChangeInternal();
17
+ };
18
+ // eslint-disable-next-line @typescript-eslint/naming-convention
19
+ this.onViewedCategoriesChanged = () => {
20
+ this.onVisibilityChangeInternal();
21
+ };
22
+ this._idsCache = props.idsCache;
23
+ this._viewport = props.viewport;
24
+ this._viewport.onDisplayStyleChanged.addListener(this.onDisplayStyleChanged);
25
+ this._viewport.onViewedCategoriesChanged.addListener(this.onViewedCategoriesChanged);
26
+ }
27
+ dispose() {
28
+ this[Symbol.dispose]();
29
+ }
30
+ [Symbol.dispose]() {
31
+ this._viewport.onDisplayStyleChanged.removeListener(this.onDisplayStyleChanged);
32
+ this._viewport.onViewedCategoriesChanged.removeListener(this.onViewedCategoriesChanged);
33
+ clearTimeout(this._pendingVisibilityChange);
34
+ }
35
+ /** Returns visibility status of the tree node. */
36
+ async getVisibilityStatus(node) {
37
+ if (!HierarchyNode.isInstancesNode(node)) {
38
+ return { state: "hidden", isDisabled: true };
39
+ }
40
+ if (CategoriesTreeNode.isSubCategoryNode(node)) {
41
+ return createVisibilityStatus(this.getSubCategoryVisibility(node));
42
+ }
43
+ if (CategoriesTreeNode.isCategoryNode(node)) {
44
+ return createVisibilityStatus(await this.getCategoriesVisibility(CategoriesVisibilityHandler.getInstanceIdsFromHierarchyNode(node)));
45
+ }
46
+ if (CategoriesTreeNode.isDefinitionContainerNode(node)) {
47
+ return createVisibilityStatus(await this.getDefinitionContainerVisibility(node));
48
+ }
49
+ return { state: "hidden", isDisabled: true };
50
+ }
51
+ async changeVisibility(node, on) {
52
+ if (!HierarchyNode.isInstancesNode(node)) {
53
+ return;
54
+ }
55
+ if (CategoriesTreeNode.isCategoryNode(node)) {
56
+ return this.changeCategoryVisibility(node, on);
57
+ }
58
+ if (CategoriesTreeNode.isSubCategoryNode(node)) {
59
+ return this.changeSubCategoryVisibility(node, on);
60
+ }
61
+ if (CategoriesTreeNode.isDefinitionContainerNode(node)) {
62
+ return this.changeDefinitionContainerVisibility(node, on);
63
+ }
64
+ }
65
+ getSubCategoryVisibility(node) {
66
+ const parentCategoryId = node.extendedData?.categoryId;
67
+ if (!parentCategoryId) {
68
+ return "hidden";
69
+ }
70
+ const categoryOverrideResult = this.getCategoryVisibilityFromOverrides(parentCategoryId);
71
+ if (categoryOverrideResult === "hidden" || categoryOverrideResult === "visible") {
72
+ return categoryOverrideResult;
73
+ }
74
+ if (!this._viewport.view.viewsCategory(parentCategoryId)) {
75
+ return "hidden";
76
+ }
77
+ const subCategoryIds = CategoriesVisibilityHandler.getInstanceIdsFromHierarchyNode(node);
78
+ let visibleCount = 0;
79
+ let hiddenCount = 0;
80
+ for (const subCategoryId of subCategoryIds) {
81
+ const isVisible = this._viewport.isSubCategoryVisible(subCategoryId);
82
+ if (isVisible) {
83
+ ++visibleCount;
84
+ }
85
+ else {
86
+ ++hiddenCount;
87
+ }
88
+ if (visibleCount > 0 && hiddenCount > 0) {
89
+ return "partial";
90
+ }
91
+ }
92
+ return visibleCount > 0 ? "visible" : "hidden";
93
+ }
94
+ async getDefinitionContainerVisibility(node) {
95
+ const childrenResult = await this._idsCache.getAllContainedCategories(CategoriesVisibilityHandler.getInstanceIdsFromHierarchyNode(node));
96
+ let hiddenCount = 0;
97
+ let visibleCount = 0;
98
+ for (const categoryId of childrenResult) {
99
+ const categoryVisibility = await this.getCategoriesVisibility([categoryId]);
100
+ if (categoryVisibility === "partial") {
101
+ return "partial";
102
+ }
103
+ if (categoryVisibility === "hidden") {
104
+ ++hiddenCount;
105
+ }
106
+ else {
107
+ ++visibleCount;
108
+ }
109
+ if (hiddenCount > 0 && visibleCount > 0) {
110
+ return "partial";
111
+ }
112
+ }
113
+ return hiddenCount > 0 ? "hidden" : "visible";
114
+ }
115
+ async getCategoriesVisibility(categoryIds) {
116
+ const overrideResult = this.getCategoryVisibilityFromOverrides(categoryIds);
117
+ if (overrideResult !== "none") {
118
+ return overrideResult;
119
+ }
120
+ let visibleCount = 0;
121
+ let hiddenCount = 0;
122
+ for (const categoryId of categoryIds) {
123
+ const isVisible = this._viewport.view.viewsCategory(categoryId);
124
+ if (isVisible) {
125
+ ++visibleCount;
126
+ }
127
+ else {
128
+ ++hiddenCount;
129
+ }
130
+ if (visibleCount > 0 && hiddenCount > 0) {
131
+ return "partial";
132
+ }
133
+ }
134
+ if (hiddenCount > 0) {
135
+ return "hidden";
136
+ }
137
+ const subCategories = (await Promise.all(categoryIds.map(async (id) => this._idsCache.getSubCategories(id)))).reduce((acc, val) => acc.concat(val), []);
138
+ let visibleSubCategoryCount = 0;
139
+ let hiddenSubCategoryCount = 0;
140
+ for (const subCategory of subCategories) {
141
+ const isVisible = this._viewport.isSubCategoryVisible(subCategory);
142
+ if (isVisible) {
143
+ ++visibleSubCategoryCount;
144
+ }
145
+ else {
146
+ ++hiddenSubCategoryCount;
147
+ }
148
+ if (hiddenSubCategoryCount > 0 && visibleSubCategoryCount > 0) {
149
+ return "partial";
150
+ }
151
+ }
152
+ return hiddenSubCategoryCount > 0 ? "hidden" : "visible";
153
+ }
154
+ getCategoryVisibilityFromOverrides(categoryIds) {
155
+ let showOverrides = 0;
156
+ let hideOverrides = 0;
157
+ for (const currentOverride of this._viewport.perModelCategoryVisibility) {
158
+ if (categoryIds.includes(currentOverride.categoryId)) {
159
+ if (currentOverride.visible) {
160
+ ++showOverrides;
161
+ }
162
+ else {
163
+ ++hideOverrides;
164
+ }
165
+ if (showOverrides > 0 && hideOverrides > 0) {
166
+ return "partial";
167
+ }
168
+ }
169
+ }
170
+ if (showOverrides === 0 && hideOverrides === 0) {
171
+ return "none";
172
+ }
173
+ return showOverrides > 0 ? "visible" : "hidden";
174
+ }
175
+ async changeSubCategoryVisibility(node, on) {
176
+ const parentCategoryId = node.extendedData?.categoryId;
177
+ // make sure parent category is enabled
178
+ if (on && parentCategoryId) {
179
+ await this.changeCategoryState([parentCategoryId], true, false);
180
+ }
181
+ const subCategoryIds = CategoriesVisibilityHandler.getInstanceIdsFromHierarchyNode(node);
182
+ subCategoryIds.forEach((id) => {
183
+ this.changeSubCategoryState(id, on);
184
+ });
185
+ }
186
+ async changeCategoryVisibility(node, on) {
187
+ const categoryIds = CategoriesVisibilityHandler.getInstanceIdsFromHierarchyNode(node);
188
+ return this.changeCategoryState(categoryIds, on, on);
189
+ }
190
+ async changeDefinitionContainerVisibility(node, on) {
191
+ const definitionContainerId = CategoriesVisibilityHandler.getInstanceIdsFromHierarchyNode(node);
192
+ const childCategories = await this._idsCache.getAllContainedCategories(definitionContainerId);
193
+ return this.changeCategoryState(childCategories, on, on);
194
+ }
195
+ onVisibilityChangeInternal() {
196
+ if (this._pendingVisibilityChange) {
197
+ return;
198
+ }
199
+ this._pendingVisibilityChange = setTimeout(() => {
200
+ this.onVisibilityChange.raiseEvent();
201
+ this._pendingVisibilityChange = undefined;
202
+ }, 0);
203
+ }
204
+ static getInstanceIdsFromHierarchyNode(node) {
205
+ return HierarchyNode.isInstancesNode(node) ? node.key.instanceKeys.map((instanceKey) => instanceKey.id) : /* istanbul ignore next */ [];
206
+ }
207
+ async changeCategoryState(ids, enabled, enableAllSubCategories) {
208
+ await enableCategoryDisplay(this._viewport, ids, enabled, enableAllSubCategories);
209
+ }
210
+ changeSubCategoryState(key, enabled) {
211
+ enableSubCategoryDisplay(this._viewport, key, enabled);
212
+ }
213
+ }
214
+ //# sourceMappingURL=CategoriesVisibilityHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CategoriesVisibilityHandler.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AA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AAC,wBAAwB,GAAG,UAAU,CAAC,GAAG,EAAE;YAC9C,IAAI,CAAC,kBAAkB,CAAC,UAAU,EAAE,CAAC;YACrC,IAAI,CAAC,wBAAwB,GAAG,SAAS,CAAC;QAC5C,CAAC,EAAE,CAAC,CAAC,CAAC;IACR,CAAC;IAEO,MAAM,CAAC,+BAA+B,CAAC,IAAmB;QAChE,OAAO,aAAa,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,0BAA0B,CAAC,EAAE,CAAC;IAC1I,CAAC;IAEO,KAAK,CAAC,mBAAmB,CAAC,GAAa,EAAE,OAAgB,EAAE,sBAA+B;QAChG,MAAM,qBAAqB,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,sBAAsB,CAAC,CAAC;IACpF,CAAC;IAEO,sBAAsB,CAAC,GAAW,EAAE,OAAgB;QAC1D,wBAAwB,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IACzD,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 { BeEvent } from \"@itwin/core-bentley\";\nimport { HierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport { enableCategoryDisplay, enableSubCategoryDisplay } from \"../../common/CategoriesVisibilityUtils.js\";\nimport { createVisibilityStatus } from \"../../common/Tooltip.js\";\nimport { CategoriesTreeNode } from \"./CategoriesTreeNode.js\";\n\nimport type { Id64Array } from \"@itwin/core-bentley\";\nimport type { Viewport } from \"@itwin/core-frontend\";\nimport type { HierarchyVisibilityHandler, VisibilityStatus } from \"../../common/UseHierarchyVisibility.js\";\nimport type { CategoriesTreeIdsCache } from \"./CategoriesTreeIdsCache.js\";\n\n/** @internal */\nexport interface CategoriesVisibilityHandlerProps {\n viewport: Viewport;\n idsCache: CategoriesTreeIdsCache;\n}\n\n/** @internal */\nexport class CategoriesVisibilityHandler implements HierarchyVisibilityHandler {\n private _pendingVisibilityChange: any;\n private _viewport: Viewport;\n private _idsCache: CategoriesTreeIdsCache;\n\n constructor(props: CategoriesVisibilityHandlerProps) {\n this._idsCache = props.idsCache;\n this._viewport = props.viewport;\n this._viewport.onDisplayStyleChanged.addListener(this.onDisplayStyleChanged);\n this._viewport.onViewedCategoriesChanged.addListener(this.onViewedCategoriesChanged);\n }\n\n public dispose() {\n this[Symbol.dispose]();\n }\n\n public [Symbol.dispose]() {\n this._viewport.onDisplayStyleChanged.removeListener(this.onDisplayStyleChanged);\n this._viewport.onViewedCategoriesChanged.removeListener(this.onViewedCategoriesChanged);\n clearTimeout(this._pendingVisibilityChange);\n }\n\n public onVisibilityChange = new BeEvent();\n\n /** Returns visibility status of the tree node. */\n public async getVisibilityStatus(node: HierarchyNode): Promise<VisibilityStatus> {\n if (!HierarchyNode.isInstancesNode(node)) {\n return { state: \"hidden\", isDisabled: true };\n }\n\n if (CategoriesTreeNode.isSubCategoryNode(node)) {\n return createVisibilityStatus(this.getSubCategoryVisibility(node));\n }\n\n if (CategoriesTreeNode.isCategoryNode(node)) {\n return createVisibilityStatus(await this.getCategoriesVisibility(CategoriesVisibilityHandler.getInstanceIdsFromHierarchyNode(node)));\n }\n\n if (CategoriesTreeNode.isDefinitionContainerNode(node)) {\n return createVisibilityStatus(await this.getDefinitionContainerVisibility(node));\n }\n\n return { state: \"hidden\", isDisabled: true };\n }\n\n public async changeVisibility(node: HierarchyNode, on: boolean) {\n if (!HierarchyNode.isInstancesNode(node)) {\n return;\n }\n\n if (CategoriesTreeNode.isCategoryNode(node)) {\n return this.changeCategoryVisibility(node, on);\n }\n\n if (CategoriesTreeNode.isSubCategoryNode(node)) {\n return this.changeSubCategoryVisibility(node, on);\n }\n\n if (CategoriesTreeNode.isDefinitionContainerNode(node)) {\n return this.changeDefinitionContainerVisibility(node, on);\n }\n }\n\n private getSubCategoryVisibility(node: HierarchyNode): VisibilityStatus[\"state\"] {\n const parentCategoryId = node.extendedData?.categoryId;\n if (!parentCategoryId) {\n return \"hidden\";\n }\n\n const categoryOverrideResult = this.getCategoryVisibilityFromOverrides(parentCategoryId);\n if (categoryOverrideResult === \"hidden\" || categoryOverrideResult === \"visible\") {\n return categoryOverrideResult;\n }\n\n if (!this._viewport.view.viewsCategory(parentCategoryId)) {\n return \"hidden\";\n }\n const subCategoryIds = CategoriesVisibilityHandler.getInstanceIdsFromHierarchyNode(node);\n let visibleCount = 0;\n let hiddenCount = 0;\n for (const subCategoryId of subCategoryIds) {\n const isVisible = this._viewport.isSubCategoryVisible(subCategoryId);\n if (isVisible) {\n ++visibleCount;\n } else {\n ++hiddenCount;\n }\n if (visibleCount > 0 && hiddenCount > 0) {\n return \"partial\";\n }\n }\n return visibleCount > 0 ? \"visible\" : \"hidden\";\n }\n\n private async getDefinitionContainerVisibility(node: HierarchyNode): Promise<VisibilityStatus[\"state\"]> {\n const childrenResult = await this._idsCache.getAllContainedCategories(CategoriesVisibilityHandler.getInstanceIdsFromHierarchyNode(node));\n let hiddenCount = 0;\n let visibleCount = 0;\n for (const categoryId of childrenResult) {\n const categoryVisibility = await this.getCategoriesVisibility([categoryId]);\n if (categoryVisibility === \"partial\") {\n return \"partial\";\n }\n\n if (categoryVisibility === \"hidden\") {\n ++hiddenCount;\n } else {\n ++visibleCount;\n }\n\n if (hiddenCount > 0 && visibleCount > 0) {\n return \"partial\";\n }\n }\n\n return hiddenCount > 0 ? \"hidden\" : \"visible\";\n }\n\n private async getCategoriesVisibility(categoryIds: Id64Array): Promise<VisibilityStatus[\"state\"]> {\n const overrideResult = this.getCategoryVisibilityFromOverrides(categoryIds);\n if (overrideResult !== \"none\") {\n return overrideResult;\n }\n let visibleCount = 0;\n let hiddenCount = 0;\n for (const categoryId of categoryIds) {\n const isVisible = this._viewport.view.viewsCategory(categoryId);\n if (isVisible) {\n ++visibleCount;\n } else {\n ++hiddenCount;\n }\n if (visibleCount > 0 && hiddenCount > 0) {\n return \"partial\";\n }\n }\n\n if (hiddenCount > 0) {\n return \"hidden\";\n }\n\n const subCategories = (await Promise.all(categoryIds.map(async (id) => this._idsCache.getSubCategories(id)))).reduce((acc, val) => acc.concat(val), []);\n let visibleSubCategoryCount = 0;\n let hiddenSubCategoryCount = 0;\n\n for (const subCategory of subCategories) {\n const isVisible = this._viewport.isSubCategoryVisible(subCategory);\n if (isVisible) {\n ++visibleSubCategoryCount;\n } else {\n ++hiddenSubCategoryCount;\n }\n if (hiddenSubCategoryCount > 0 && visibleSubCategoryCount > 0) {\n return \"partial\";\n }\n }\n\n return hiddenSubCategoryCount > 0 ? \"hidden\" : \"visible\";\n }\n\n private getCategoryVisibilityFromOverrides(categoryIds: Id64Array): VisibilityStatus[\"state\"] | \"none\" {\n let showOverrides = 0;\n let hideOverrides = 0;\n\n for (const currentOverride of this._viewport.perModelCategoryVisibility) {\n if (categoryIds.includes(currentOverride.categoryId)) {\n if (currentOverride.visible) {\n ++showOverrides;\n } else {\n ++hideOverrides;\n }\n\n if (showOverrides > 0 && hideOverrides > 0) {\n return \"partial\";\n }\n }\n }\n\n if (showOverrides === 0 && hideOverrides === 0) {\n return \"none\";\n }\n\n return showOverrides > 0 ? \"visible\" : \"hidden\";\n }\n\n private async changeSubCategoryVisibility(node: HierarchyNode, on: boolean) {\n const parentCategoryId = node.extendedData?.categoryId;\n\n // make sure parent category is enabled\n if (on && parentCategoryId) {\n await this.changeCategoryState([parentCategoryId], true, false);\n }\n\n const subCategoryIds = CategoriesVisibilityHandler.getInstanceIdsFromHierarchyNode(node);\n subCategoryIds.forEach((id) => {\n this.changeSubCategoryState(id, on);\n });\n }\n\n private async changeCategoryVisibility(node: HierarchyNode, on: boolean) {\n const categoryIds = CategoriesVisibilityHandler.getInstanceIdsFromHierarchyNode(node);\n return this.changeCategoryState(categoryIds, on, on);\n }\n\n private async changeDefinitionContainerVisibility(node: HierarchyNode, on: boolean) {\n const definitionContainerId = CategoriesVisibilityHandler.getInstanceIdsFromHierarchyNode(node);\n const childCategories = await this._idsCache.getAllContainedCategories(definitionContainerId);\n return this.changeCategoryState(childCategories, on, on);\n }\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n private onDisplayStyleChanged = () => {\n this.onVisibilityChangeInternal();\n };\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n private onViewedCategoriesChanged = () => {\n this.onVisibilityChangeInternal();\n };\n\n private onVisibilityChangeInternal() {\n if (this._pendingVisibilityChange) {\n return;\n }\n\n this._pendingVisibilityChange = setTimeout(() => {\n this.onVisibilityChange.raiseEvent();\n this._pendingVisibilityChange = undefined;\n }, 0);\n }\n\n private static getInstanceIdsFromHierarchyNode(node: HierarchyNode) {\n return HierarchyNode.isInstancesNode(node) ? node.key.instanceKeys.map((instanceKey) => instanceKey.id) : /* istanbul ignore next */ [];\n }\n\n private async changeCategoryState(ids: string[], enabled: boolean, enableAllSubCategories: boolean) {\n await enableCategoryDisplay(this._viewport, ids, enabled, enableAllSubCategories);\n }\n\n private changeSubCategoryState(key: string, enabled: boolean) {\n enableSubCategoryDisplay(this._viewport, key, enabled);\n }\n}\n"]}
@@ -0,0 +1,7 @@
1
+ /** @internal */
2
+ export declare const SUB_CATEGORY_CLASS = "BisCore.SubCategory";
3
+ /** @internal */
4
+ export declare const DEFINITION_CONTAINER_CLASS = "BisCore.DefinitionContainer";
5
+ /** @internal */
6
+ export declare const DEFINITION_ELEMENT_CLASS = "BisCore.DefinitionElement";
7
+ //# sourceMappingURL=ClassNameDefinitions.d.ts.map
@@ -0,0 +1,11 @@
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
+ /** @internal */
6
+ export const SUB_CATEGORY_CLASS = "BisCore.SubCategory";
7
+ /** @internal */
8
+ export const DEFINITION_CONTAINER_CLASS = "BisCore.DefinitionContainer";
9
+ /** @internal */
10
+ export const DEFINITION_ELEMENT_CLASS = "BisCore.DefinitionElement";
11
+ //# sourceMappingURL=ClassNameDefinitions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ClassNameDefinitions.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,gBAAgB;AAChB,MAAM,CAAC,MAAM,kBAAkB,GAAG,qBAAqB,CAAC;AAExD,gBAAgB;AAChB,MAAM,CAAC,MAAM,0BAA0B,GAAG,6BAA6B,CAAC;AAExE,gBAAgB;AAChB,MAAM,CAAC,MAAM,wBAAwB,GAAG,2BAA2B,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\n/** @internal */\nexport const SUB_CATEGORY_CLASS = \"BisCore.SubCategory\";\n\n/** @internal */\nexport const DEFINITION_CONTAINER_CLASS = \"BisCore.DefinitionContainer\";\n\n/** @internal */\nexport const DEFINITION_ELEMENT_CLASS = \"BisCore.DefinitionElement\";\n"]}
@@ -11,10 +11,6 @@ export interface CategoryInfo {
11
11
  * Toggles visibility of categories to show or hide.
12
12
  */
13
13
  export declare function toggleAllCategories(viewport: Viewport, display: boolean): Promise<void>;
14
- /**
15
- * Gets ids of all categories from specified imodel and viewport.
16
- */
17
- export declare function getCategories(viewport: Viewport): Promise<string[]>;
18
14
  /**
19
15
  * Changes category display in the viewport.
20
16
  */
@@ -17,7 +17,7 @@ export async function toggleAllCategories(viewport, display) {
17
17
  /**
18
18
  * Gets ids of all categories from specified imodel and viewport.
19
19
  */
20
- export async function getCategories(viewport) {
20
+ async function getCategories(viewport) {
21
21
  const categories = await loadCategoriesFromViewport(viewport);
22
22
  return categories.map((category) => category.categoryId);
23
23
  }
@@ -1 +1 @@
1
- {"version":3,"file":"CategoriesVisibilityUtils.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAalE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,QAAkB,EAAE,OAAgB;IAC5E,MAAM,GAAG,GAAG,MAAM,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC1C,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE;QACpB,OAAO;KACR;IAED,MAAM,qBAAqB,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;AACtD,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,QAAkB;IACpD,MAAM,UAAU,GAAG,MAAM,0BAA0B,CAAC,QAAQ,CAAC,CAAC;IAC9D,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;AAC3D,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,QAAkB,EAAE,GAAa,EAAE,OAAgB,EAAE,sBAAsB,GAAG,IAAI;IAC5H,QAAQ,CAAC,qBAAqB,CAAC,GAAG,EAAE,OAAO,EAAE,sBAAsB,CAAC,CAAC;IAErE,sCAAsC;IACtC,MAAM,yBAAyB,GAAa,EAAE,CAAC;IAC/C,KAAK,MAAM,GAAG,IAAI,QAAQ,CAAC,0BAA0B,EAAE;QACrD,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAA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,KAAK,MAAM,QAAQ,IAAI,UAAU,EAAE;QACjC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE;YACrD,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;YACnC,SAAS;SACV;QACD,iJAAiJ;QACjJ,IAAI,QAAQ,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC,EAAE;YAC/F,KAAK,MAAM,WAAW,IAAI,QAAQ,CAAC,cAAc,EAAE;gBACjD,QAAQ,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;aAC/H;SACF;aAAM;YACL,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;SACnC;KACF;IAED,kBAAkB;IAClB,oBAAoB,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,wBAAwB,CAAC,QAAQ,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;IAEtG,MAAM,qBAAqB,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAE5D,kBAAkB;IAClB,qBAAqB,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,wBAAwB,CAAC,QAAQ,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC;IAEtG,MAAM,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAC9D,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 { PerModelCategoryVisibility } from \"@itwin/core-frontend\";\n\nimport type { Viewport } from \"@itwin/core-frontend\";\n\n/**\n * Data structure that describes category.\n * @beta\n */\nexport interface CategoryInfo {\n categoryId: string;\n subCategoryIds?: string[];\n}\n\n/**\n * Toggles visibility of categories to show or hide.\n */\nexport async function toggleAllCategories(viewport: Viewport, display: boolean) {\n const ids = await getCategories(viewport);\n if (ids.length === 0) {\n return;\n }\n\n await enableCategoryDisplay(viewport, ids, display);\n}\n\n/**\n * Gets ids of all categories from specified imodel and viewport.\n */\nexport async function getCategories(viewport: Viewport) {\n const categories = await loadCategoriesFromViewport(viewport);\n return categories.map((category) => category.categoryId);\n}\n\n/**\n * Changes category display in the viewport.\n */\nexport async function enableCategoryDisplay(viewport: Viewport, ids: string[], enabled: boolean, enableAllSubCategories = true) {\n viewport.changeCategoryDisplay(ids, enabled, enableAllSubCategories);\n\n // remove category overrides per model\n const modelsContainingOverrides: string[] = [];\n for (const ovr of viewport.perModelCategoryVisibility) {\n if (ids.findIndex((id) => id === ovr.categoryId) !== -1) {\n modelsContainingOverrides.push(ovr.modelId);\n }\n }\n viewport.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 viewport.iModel.categories.getCategoryInfo(ids)).forEach((categoryInfo) => {\n categoryInfo.subCategories.forEach((value) => enableSubCategoryDisplay(viewport, value.id, false));\n });\n }\n}\n\n/**\n * Changes subcategory display in the viewport\n */\nexport function enableSubCategoryDisplay(viewport: Viewport, key: string, enabled: boolean) {\n viewport.changeSubCategoryDisplay(key, enabled);\n}\n\nexport async function loadCategoriesFromViewport(vp: Viewport) {\n // Query categories and add them to state\n const selectUsedSpatialCategoryIds =\n \"SELECT DISTINCT Category.Id as id from BisCore.GeometricElement3d WHERE Category.Id IN (SELECT ECInstanceId from BisCore.SpatialCategory)\";\n const selectUsedDrawingCategoryIds =\n \"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 const rows = await vp.iModel.createQueryReader(ecsql2, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames }).toArray();\n (await vp.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 return categories;\n}\n\n/**\n * Enable display of all given categories.\n * @public\n */\nexport async function showAllCategories(categories: string[], viewport: Viewport) {\n await enableCategoryDisplay(viewport, categories, true, true);\n}\n\n/**\n * Disable display of all given categories.\n * @public\n */\nexport async function hideAllCategories(categories: string[], viewport: Viewport) {\n await enableCategoryDisplay(viewport, categories, false, true);\n}\n\n/**\n * Invert display of all given categories.\n * @public\n */\nexport async function invertAllCategories(categories: CategoryInfo[], viewport: Viewport) {\n const enabled: string[] = [];\n const disabled: string[] = [];\n const enabledSubCategories: string[] = [];\n const disabledSubCategories: string[] = [];\n\n for (const category of categories) {\n if (!viewport.view.viewsCategory(category.categoryId)) {\n disabled.push(category.categoryId);\n continue;\n }\n // First, we need to check if at least one subcategory is disabled. If it is true, then only subcategories should change display, not categories.\n if (category.subCategoryIds?.some((subCategory) => !viewport.isSubCategoryVisible(subCategory))) {\n for (const subCategory of category.subCategoryIds) {\n viewport.isSubCategoryVisible(subCategory) ? enabledSubCategories.push(subCategory) : disabledSubCategories.push(subCategory);\n }\n } else {\n enabled.push(category.categoryId);\n }\n }\n\n // Disable enabled\n enabledSubCategories.forEach((subCategory) => enableSubCategoryDisplay(viewport, subCategory, false));\n\n await enableCategoryDisplay(viewport, enabled, false, true);\n\n // Enable disabled\n disabledSubCategories.forEach((subCategory) => enableSubCategoryDisplay(viewport, subCategory, true));\n\n await enableCategoryDisplay(viewport, disabled, true, true);\n}\n"]}
1
+ {"version":3,"file":"CategoriesVisibilityUtils.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAalE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,QAAkB,EAAE,OAAgB;IAC5E,MAAM,GAAG,GAAG,MAAM,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC1C,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE;QACpB,OAAO;KACR;IAED,MAAM,qBAAqB,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;AACtD,CAAC;AAED;;GAEG;AACH,KAAK,UAAU,aAAa,CAAC,QAAkB;IAC7C,MAAM,UAAU,GAAG,MAAM,0BAA0B,CAAC,QAAQ,CAAC,CAAC;IAC9D,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;AAC3D,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,QAAkB,EAAE,GAAa,EAAE,OAAgB,EAAE,sBAAsB,GAAG,IAAI;IAC5H,QAAQ,CAAC,qBAAqB,CAAC,GAAG,EAAE,OAAO,EAAE,sBAAsB,CAAC,CAAC;IAErE,sCAAsC;IACtC,MAAM,yBAAyB,GAAa,EAAE,CAAC;IAC/C,KAAK,MAAM,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D,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 { PerModelCategoryVisibility } from \"@itwin/core-frontend\";\n\nimport type { Viewport } from \"@itwin/core-frontend\";\n\n/**\n * Data structure that describes category.\n * @beta\n */\nexport interface CategoryInfo {\n categoryId: string;\n subCategoryIds?: string[];\n}\n\n/**\n * Toggles visibility of categories to show or hide.\n */\nexport async function toggleAllCategories(viewport: Viewport, display: boolean) {\n const ids = await getCategories(viewport);\n if (ids.length === 0) {\n return;\n }\n\n await enableCategoryDisplay(viewport, ids, display);\n}\n\n/**\n * Gets ids of all categories from specified imodel and viewport.\n */\nasync function getCategories(viewport: Viewport) {\n const categories = await loadCategoriesFromViewport(viewport);\n return categories.map((category) => category.categoryId);\n}\n\n/**\n * Changes category display in the viewport.\n */\nexport async function enableCategoryDisplay(viewport: Viewport, ids: string[], enabled: boolean, enableAllSubCategories = true) {\n viewport.changeCategoryDisplay(ids, enabled, enableAllSubCategories);\n\n // remove category overrides per model\n const modelsContainingOverrides: string[] = [];\n for (const ovr of viewport.perModelCategoryVisibility) {\n if (ids.findIndex((id) => id === ovr.categoryId) !== -1) {\n modelsContainingOverrides.push(ovr.modelId);\n }\n }\n viewport.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 viewport.iModel.categories.getCategoryInfo(ids)).forEach((categoryInfo) => {\n categoryInfo.subCategories.forEach((value) => enableSubCategoryDisplay(viewport, value.id, false));\n });\n }\n}\n\n/**\n * Changes subcategory display in the viewport\n */\nexport function enableSubCategoryDisplay(viewport: Viewport, key: string, enabled: boolean) {\n viewport.changeSubCategoryDisplay(key, enabled);\n}\n\nexport async function loadCategoriesFromViewport(vp: Viewport) {\n // Query categories and add them to state\n const selectUsedSpatialCategoryIds =\n \"SELECT DISTINCT Category.Id as id from BisCore.GeometricElement3d WHERE Category.Id IN (SELECT ECInstanceId from BisCore.SpatialCategory)\";\n const selectUsedDrawingCategoryIds =\n \"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 const rows = await vp.iModel.createQueryReader(ecsql2, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames }).toArray();\n (await vp.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 return categories;\n}\n\n/**\n * Enable display of all given categories.\n * @public\n */\nexport async function showAllCategories(categories: string[], viewport: Viewport) {\n await enableCategoryDisplay(viewport, categories, true, true);\n}\n\n/**\n * Disable display of all given categories.\n * @public\n */\nexport async function hideAllCategories(categories: string[], viewport: Viewport) {\n await enableCategoryDisplay(viewport, categories, false, true);\n}\n\n/**\n * Invert display of all given categories.\n * @public\n */\nexport async function invertAllCategories(categories: CategoryInfo[], viewport: Viewport) {\n const enabled: string[] = [];\n const disabled: string[] = [];\n const enabledSubCategories: string[] = [];\n const disabledSubCategories: string[] = [];\n\n for (const category of categories) {\n if (!viewport.view.viewsCategory(category.categoryId)) {\n disabled.push(category.categoryId);\n continue;\n }\n // First, we need to check if at least one subcategory is disabled. If it is true, then only subcategories should change display, not categories.\n if (category.subCategoryIds?.some((subCategory) => !viewport.isSubCategoryVisible(subCategory))) {\n for (const subCategory of category.subCategoryIds) {\n viewport.isSubCategoryVisible(subCategory) ? enabledSubCategories.push(subCategory) : disabledSubCategories.push(subCategory);\n }\n } else {\n enabled.push(category.categoryId);\n }\n }\n\n // Disable enabled\n enabledSubCategories.forEach((subCategory) => enableSubCategoryDisplay(viewport, subCategory, false));\n\n await enableCategoryDisplay(viewport, enabled, false, true);\n\n // Enable disabled\n disabledSubCategories.forEach((subCategory) => enableSubCategoryDisplay(viewport, subCategory, true));\n\n await enableCategoryDisplay(viewport, disabled, true, true);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"UseHierarchyVisibility.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/UseHierarchyVisibility.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EACL,cAAc,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,SAAS,EAAE,qBAAqB,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,YAAY,GAC/I,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAsC/D,MAAM,UAAU,sBAAsB,CAAC,EAAE,wBAAwB,EAA+B;IAC9F,MAAM,mBAAmB,GAAG,MAAM,CAAC,IAAI,GAAG,EAAgG,CAAC,CAAC;IAC5I,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAqD;QACrF,gBAAgB,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;QAC5D,iBAAiB,EAAE,GAAG,EAAE,GAAE,CAAC;QAC3B,cAAc,EAAE,GAAG,EAAE,GAAE,CAAC;KACzB,CAAC,CAAC;IACH,MAAM,EAAE,aAAa,EAAE,GAAG,mBA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K;YACR,sBAAsB,EAAE,KAAK,IAAI,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,EAAE,YAAY,EAAE,SAAoB,EAAE,CAAC;YAC9F,OAAO;SACR,CAAC,CACH;QACH,CAAC,CAAC,GAAG,CAAC;AACV,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useEffect, useRef, useState } from \"react\";\nimport {\n asyncScheduler, defer, distinct, EMPTY, from, lastValueFrom, mergeMap, observeOn, onErrorResumeNextWith, Subject, takeUntil, tap, throttleTime,\n} from \"rxjs\";\nimport { useTelemetryContext } from \"./UseTelemetryContext.js\";\n\nimport type { Observable } from \"rxjs\";\nimport type { MutableRefObject } from \"react\";\nimport type { BeEvent, IDisposable } from \"@itwin/core-bentley\";\nimport type { HierarchyNode, PresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport type { TreeCheckboxProps } from \"./components/TreeNodeCheckbox.js\";\n\n/**\n * Data structure that describes instance visibility status.\n * @beta\n */\nexport interface VisibilityStatus {\n /** Instance visibility state. */\n state: \"visible\" | \"partial\" | \"hidden\";\n /** Specifies whether visibility changing is disabled or not. */\n isDisabled?: boolean;\n /** Tooltip that should be displayed when hovering over the visibility checkbox. */\n tooltip?: string;\n}\n\n/**\n * Handler that can be used to determine and change visibility of instances represented by tree nodes.\n * @beta\n */\nexport interface HierarchyVisibilityHandler extends IDisposable {\n /** Event used to notify tree about visibility changes from outside. */\n readonly onVisibilityChange: BeEvent<() => void>;\n /** Returns current visibility status for tree node. */\n getVisibilityStatus(node: HierarchyNode): Promise<VisibilityStatus> | VisibilityStatus;\n /** Changes visibility of the instance represented by tree node. */\n changeVisibility(node: HierarchyNode, on: boolean): Promise<void>;\n}\n\ninterface UseHierarchyVisibilityProps {\n visibilityHandlerFactory: () => HierarchyVisibilityHandler;\n}\n\nexport function useHierarchyVisibility({ visibilityHandlerFactory }: UseHierarchyVisibilityProps): TreeCheckboxProps & { triggerRefresh: () => void } {\n const visibilityStatusMap = useRef(new Map<string, { node: PresentationHierarchyNode; status: VisibilityStatus; needsRefresh: boolean }>());\n const [state, setState] = useState<TreeCheckboxProps & { triggerRefresh: () => void }>({\n getCheckboxState: () => ({ state: \"off\", isDisabled: true }),\n onCheckboxClicked: () => {},\n triggerRefresh: () => {},\n });\n const { onFeatureUsed } = useTelemetryContext();\n\n useEffect(() => {\n visibilityStatusMap.current.clear();\n const handler = visibilityHandlerFactory();\n\n const visibilityChanged = new Subject<void>();\n const calculate = new Subject<PresentationHierarchyNode>();\n const calculateNodeStatus = (node: PresentationHierarchyNode) => {\n calculate.next(node);\n };\n\n const resetCache = () => {\n visibilityStatusMap.current.forEach((value) => {\n value.needsRefresh = true;\n });\n visibilityChanged.next();\n };\n\n const triggerCheckboxUpdate = () => {\n setState((prev) => ({\n ...prev,\n getCheckboxState: createStateGetter(visibilityStatusMap, calculateNodeStatus),\n }));\n };\n\n const subscription = calculate\n .pipe(\n distinct(undefined, visibilityChanged),\n observeOn(asyncScheduler),\n mergeMap((node) =>\n defer(async () => handler.getVisibilityStatus(node.nodeData)).pipe(\n tap({\n next: (status) => {\n visibilityStatusMap.current.set(node.id, {\n node,\n status,\n needsRefresh: false,\n });\n },\n }),\n takeUntil(visibilityChanged),\n onErrorResumeNextWith(EMPTY),\n ),\n ),\n throttleTime(100, undefined, { leading: false, trailing: true }),\n )\n .subscribe({\n next: () => {\n triggerCheckboxUpdate();\n },\n });\n\n const changeVisibility = (node: PresentationHierarchyNode, checked: boolean) => {\n onFeatureUsed({ featureId: \"visibility-change\", reportInteraction: true });\n void handler.changeVisibility(node.nodeData, checked);\n const entry = visibilityStatusMap.current.get(node.id);\n if (!entry) {\n return;\n }\n entry.status.state = checked ? \"visible\" : \"hidden\";\n entry.status.tooltip = undefined;\n triggerCheckboxUpdate();\n };\n\n setState({\n onCheckboxClicked: changeVisibility,\n getCheckboxState: createStateGetter(visibilityStatusMap, calculateNodeStatus),\n triggerRefresh: () => {\n resetCache();\n triggerCheckboxUpdate();\n },\n });\n\n const removeListener = handler.onVisibilityChange.addListener(() => {\n resetCache();\n triggerCheckboxUpdate();\n });\n\n return () => {\n subscription.unsubscribe();\n removeListener();\n handler.dispose();\n };\n }, [visibilityHandlerFactory, onFeatureUsed]);\n\n return state;\n}\n\nfunction createStateGetter(\n map: MutableRefObject<Map<string, { node: PresentationHierarchyNode; status: VisibilityStatus; needsRefresh: boolean }>>,\n calculateVisibility: (node: PresentationHierarchyNode) => void,\n): TreeCheckboxProps[\"getCheckboxState\"] {\n return (node) => {\n const entry = map.current.get(node.id);\n if (entry === undefined) {\n calculateVisibility(node);\n return { state: \"off\", isDisabled: true };\n }\n if (entry.needsRefresh) {\n calculateVisibility(node);\n }\n\n const status = entry.status;\n return {\n state: status.state === \"visible\" ? \"on\" : status.state === \"hidden\" ? \"off\" : \"partial\",\n tooltip: status.tooltip,\n isDisabled: status.isDisabled,\n };\n };\n}\n\n/**\n * Properties for an overridden method of a `HierarchyVisibilityHandler` implementation.\n * @beta\n */\nexport type HierarchyVisibilityHandlerOverridableMethodProps<TFunc> = TFunc extends (props: infer TProps) => infer TResult\n ? TProps & {\n /** A callback that produces the value from the original implementation. */\n readonly originalImplementation: () => TResult;\n /**\n * Reference to the hierarchy based handler.\n * @note Calling `getVisibility` or `changeVisibility` of this object invokes the overridden implementation as well.\n */\n readonly handler: HierarchyVisibilityHandler;\n }\n : never;\n\n/**\n * Function type for an overridden method of `HierarchyVisibilityHandler`.\n * @beta\n */\nexport type HierarchyVisibilityHandlerOverridableMethod<TFunc> = TFunc extends (...args: any[]) => infer TResult\n ? (props: HierarchyVisibilityHandlerOverridableMethodProps<TFunc>) => TResult\n : never;\n\nexport function createVisibilityHandlerResult<TResult, TOverrideProps>(\n handler: HierarchyVisibilityHandler,\n props: TOverrideProps,\n obs: Observable<TResult>,\n override: HierarchyVisibilityHandlerOverridableMethod<(props: TOverrideProps) => Promise<TResult>> | undefined,\n): Observable<TResult> {\n return override\n ? from(\n override({\n ...props,\n originalImplementation: async () => lastValueFrom(obs, { defaultValue: undefined as TResult }),\n handler,\n }),\n )\n : obs;\n}\n"]}
1
+ {"version":3,"file":"UseHierarchyVisibility.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/UseHierarchyVisibility.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EACL,cAAc,EACd,KAAK,EACL,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,aAAa,EACb,QAAQ,EACR,SAAS,EACT,qBAAqB,EACrB,OAAO,EACP,SAAS,EACT,GAAG,EACH,YAAY,GACb,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAsC/D,MAAM,UAAU,sBAAsB,CAAC,EAAE,wBAAwB,EAA+B;IAC9F,MAAM,mBAAmB,GAAG,MAAM,CAAC,IAAI,GAAG,EAAgG,CAAC,CAAC;IAC5I,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAqD;QACrF,gBAAgB,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;QAC5D,iBAAiB,EAAE,GAAG,EAAE,GAAE,CAAC;QAC3B,cAAc,EAAE,GAAG,EAAE,GAAE,CAAC;KACzB,CAAC,CAAC;IACH,MAAM,EAAE,aAAa,EAAE,GAAG,mBAAmB,EAAE,CAAC;IAEhD,SAAS,CAAC,GAAG,EAAE;QACb,mBAAmB,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACpC,MAAM,OAAO,GAAG,wBAAwB,EAAE,CAAC;QAE3C,MAAM,iBAAiB,GAAG,IAAI,OAAO,EAAQ,CAA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------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useEffect, useRef, useState } from \"react\";\nimport {\n asyncScheduler,\n defer,\n distinct,\n EMPTY,\n from,\n lastValueFrom,\n mergeMap,\n observeOn,\n onErrorResumeNextWith,\n Subject,\n takeUntil,\n tap,\n throttleTime,\n} from \"rxjs\";\nimport { useTelemetryContext } from \"./UseTelemetryContext.js\";\n\nimport type { Observable } from \"rxjs\";\nimport type { MutableRefObject } from \"react\";\nimport type { BeEvent, IDisposable } from \"@itwin/core-bentley\";\nimport type { HierarchyNode, PresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport type { TreeCheckboxProps } from \"./components/TreeNodeCheckbox.js\";\n\n/**\n * Data structure that describes instance visibility status.\n * @beta\n */\nexport interface VisibilityStatus {\n /** Instance visibility state. */\n state: \"visible\" | \"partial\" | \"hidden\";\n /** Specifies whether visibility changing is disabled or not. */\n isDisabled?: boolean;\n /** Tooltip that should be displayed when hovering over the visibility checkbox. */\n tooltip?: string;\n}\n\n/**\n * Handler that can be used to determine and change visibility of instances represented by tree nodes.\n * @beta\n */\nexport interface HierarchyVisibilityHandler extends IDisposable {\n /** Event used to notify tree about visibility changes from outside. */\n readonly onVisibilityChange: BeEvent<() => void>;\n /** Returns current visibility status for tree node. */\n getVisibilityStatus(node: HierarchyNode): Promise<VisibilityStatus> | VisibilityStatus;\n /** Changes visibility of the instance represented by tree node. */\n changeVisibility(node: HierarchyNode, on: boolean): Promise<void>;\n}\n\ninterface UseHierarchyVisibilityProps {\n visibilityHandlerFactory: () => HierarchyVisibilityHandler;\n}\n\nexport function useHierarchyVisibility({ visibilityHandlerFactory }: UseHierarchyVisibilityProps): TreeCheckboxProps & { triggerRefresh: () => void } {\n const visibilityStatusMap = useRef(new Map<string, { node: PresentationHierarchyNode; status: VisibilityStatus; needsRefresh: boolean }>());\n const [state, setState] = useState<TreeCheckboxProps & { triggerRefresh: () => void }>({\n getCheckboxState: () => ({ state: \"off\", isDisabled: true }),\n onCheckboxClicked: () => {},\n triggerRefresh: () => {},\n });\n const { onFeatureUsed } = useTelemetryContext();\n\n useEffect(() => {\n visibilityStatusMap.current.clear();\n const handler = visibilityHandlerFactory();\n\n const visibilityChanged = new Subject<void>();\n const calculate = new Subject<PresentationHierarchyNode>();\n const calculateNodeStatus = (node: PresentationHierarchyNode) => {\n calculate.next(node);\n };\n\n const resetCache = () => {\n visibilityStatusMap.current.forEach((value) => {\n value.needsRefresh = true;\n });\n visibilityChanged.next();\n };\n\n const triggerCheckboxUpdate = () => {\n setState((prev) => ({\n ...prev,\n getCheckboxState: createStateGetter(visibilityStatusMap, calculateNodeStatus),\n }));\n };\n\n const subscription = calculate\n .pipe(\n distinct(undefined, visibilityChanged),\n observeOn(asyncScheduler),\n mergeMap((node) =>\n defer(async () => handler.getVisibilityStatus(node.nodeData)).pipe(\n tap({\n next: (status) => {\n visibilityStatusMap.current.set(node.id, {\n node,\n status,\n needsRefresh: false,\n });\n },\n }),\n takeUntil(visibilityChanged),\n onErrorResumeNextWith(EMPTY),\n ),\n ),\n throttleTime(100, undefined, { leading: false, trailing: true }),\n )\n .subscribe({\n next: () => {\n triggerCheckboxUpdate();\n },\n });\n\n const changeVisibility = (node: PresentationHierarchyNode, checked: boolean) => {\n onFeatureUsed({ featureId: \"visibility-change\", reportInteraction: true });\n void handler.changeVisibility(node.nodeData, checked);\n const entry = visibilityStatusMap.current.get(node.id);\n if (!entry) {\n return;\n }\n entry.status.state = checked ? \"visible\" : \"hidden\";\n entry.status.tooltip = undefined;\n triggerCheckboxUpdate();\n };\n\n setState({\n onCheckboxClicked: changeVisibility,\n getCheckboxState: createStateGetter(visibilityStatusMap, calculateNodeStatus),\n triggerRefresh: () => {\n resetCache();\n triggerCheckboxUpdate();\n },\n });\n\n const removeListener = handler.onVisibilityChange.addListener(() => {\n resetCache();\n triggerCheckboxUpdate();\n });\n\n return () => {\n subscription.unsubscribe();\n removeListener();\n handler.dispose();\n };\n }, [visibilityHandlerFactory, onFeatureUsed]);\n\n return state;\n}\n\nfunction createStateGetter(\n map: MutableRefObject<Map<string, { node: PresentationHierarchyNode; status: VisibilityStatus; needsRefresh: boolean }>>,\n calculateVisibility: (node: PresentationHierarchyNode) => void,\n): TreeCheckboxProps[\"getCheckboxState\"] {\n return (node) => {\n const entry = map.current.get(node.id);\n if (entry === undefined) {\n calculateVisibility(node);\n return { state: \"off\", isDisabled: true };\n }\n if (entry.needsRefresh) {\n calculateVisibility(node);\n }\n\n const status = entry.status;\n return {\n state: status.state === \"visible\" ? \"on\" : status.state === \"hidden\" ? \"off\" : \"partial\",\n tooltip: status.tooltip,\n isDisabled: status.isDisabled,\n };\n };\n}\n\n/**\n * Properties for an overridden method of a `HierarchyVisibilityHandler` implementation.\n * @beta\n */\nexport type HierarchyVisibilityHandlerOverridableMethodProps<TFunc> = TFunc extends (props: infer TProps) => infer TResult\n ? TProps & {\n /** A callback that produces the value from the original implementation. */\n readonly originalImplementation: () => TResult;\n /**\n * Reference to the hierarchy based handler.\n * @note Calling `getVisibility` or `changeVisibility` of this object invokes the overridden implementation as well.\n */\n readonly handler: HierarchyVisibilityHandler;\n }\n : never;\n\n/**\n * Function type for an overridden method of `HierarchyVisibilityHandler`.\n * @beta\n */\nexport type HierarchyVisibilityHandlerOverridableMethod<TFunc> = TFunc extends (...args: any[]) => infer TResult\n ? (props: HierarchyVisibilityHandlerOverridableMethodProps<TFunc>) => TResult\n : never;\n\nexport function createVisibilityHandlerResult<TResult, TOverrideProps>(\n handler: HierarchyVisibilityHandler,\n props: TOverrideProps,\n obs: Observable<TResult>,\n override: HierarchyVisibilityHandlerOverridableMethod<(props: TOverrideProps) => Promise<TResult>> | undefined,\n): Observable<TResult> {\n return override\n ? from(\n override({\n ...props,\n originalImplementation: async () => lastValueFrom(obs, { defaultValue: undefined as TResult }),\n handler,\n }),\n )\n : obs;\n}\n"]}
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" resolution-mode="require"/>
1
2
  import type { GroupingHierarchyNode, HierarchyFilteringPath } from "@itwin/presentation-hierarchies";
2
3
  import type { HierarchyVisibilityHandler, HierarchyVisibilityHandlerOverridableMethod, VisibilityStatus } from "../../common/UseHierarchyVisibility.js";
3
4
  import type { ModelsTreeIdsCache } from "./ModelsTreeIdsCache.js";
@@ -75,7 +76,7 @@ export interface ModelsTreeVisibilityHandlerProps {
75
76
  * Creates an instance if `ModelsTreeVisibilityHandler`.
76
77
  * @internal
77
78
  */
78
- export declare function createModelsTreeVisibilityHandler(props: ModelsTreeVisibilityHandlerProps): HierarchyVisibilityHandler;
79
+ export declare function createModelsTreeVisibilityHandler(props: ModelsTreeVisibilityHandlerProps): HierarchyVisibilityHandler & Disposable;
79
80
  /**
80
81
  * Enables display of all given models. Also enables display of all categories and clears always and
81
82
  * never drawn lists in the viewport.
@@ -66,6 +66,9 @@ class ModelsTreeVisibilityHandlerImpl {
66
66
  return toVoidPromise(changeObservable);
67
67
  }
68
68
  dispose() {
69
+ this[Symbol.dispose]();
70
+ }
71
+ [Symbol.dispose]() {
69
72
  this._eventListener.dispose();
70
73
  this._alwaysAndNeverDrawnElements.dispose();
71
74
  this._subscriptions.forEach((x) => x.unsubscribe());