@itwin/tree-widget-react 4.0.0-alpha.3 → 4.0.0-alpha.4

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 (68) hide show
  1. package/CHANGELOG.md +34 -1
  2. package/README.md +1 -3
  3. package/lib/esm/tree-widget-react/components/TreeWidgetUiItemsProvider.js +3 -2
  4. package/lib/esm/tree-widget-react/components/TreeWidgetUiItemsProvider.js.map +1 -1
  5. package/lib/esm/tree-widget-react/components/tree-header/ErrorState.js +2 -2
  6. package/lib/esm/tree-widget-react/components/tree-header/ErrorState.js.map +1 -1
  7. package/lib/esm/tree-widget-react/components/tree-header/SearchBox.js +4 -4
  8. package/lib/esm/tree-widget-react/components/tree-header/SearchBox.js.map +1 -1
  9. package/lib/esm/tree-widget-react/components/tree-header/SelectableTree.css +1 -1
  10. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js +6 -6
  11. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js.map +1 -1
  12. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.d.ts +10 -2
  13. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js +246 -129
  14. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js.map +1 -1
  15. package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js +69 -20
  16. package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js.map +1 -1
  17. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.d.ts +54 -0
  18. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js +280 -0
  19. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js.map +1 -0
  20. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.d.ts +26 -0
  21. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.js +23 -0
  22. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.js.map +1 -0
  23. package/lib/esm/tree-widget-react/components/trees/categories-tree/{CategoriesVisibilityHandler.d.ts → internal/CategoriesVisibilityHandler.d.ts} +18 -9
  24. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js +214 -0
  25. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js.map +1 -0
  26. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.d.ts +7 -0
  27. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.js +11 -0
  28. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.js.map +1 -0
  29. package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.d.ts +0 -4
  30. package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js +1 -1
  31. package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js.map +1 -1
  32. package/lib/esm/tree-widget-react/components/trees/common/FocusedInstancesContext.d.ts +28 -4
  33. package/lib/esm/tree-widget-react/components/trees/common/FocusedInstancesContext.js +73 -2
  34. package/lib/esm/tree-widget-react/components/trees/common/FocusedInstancesContext.js.map +1 -1
  35. package/lib/esm/tree-widget-react/components/trees/common/components/Tree.d.ts +1 -1
  36. package/lib/esm/tree-widget-react/components/trees/common/components/Tree.js +3 -4
  37. package/lib/esm/tree-widget-react/components/trees/common/components/Tree.js.map +1 -1
  38. package/lib/esm/tree-widget-react/components/trees/common/components/TreeNodeVisibilityButton.css +2 -1
  39. package/lib/esm/tree-widget-react/components/trees/common/components/TreeNodeVisibilityButton.js +6 -6
  40. package/lib/esm/tree-widget-react/components/trees/common/components/TreeNodeVisibilityButton.js.map +1 -1
  41. package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTree.js +9 -9
  42. package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTree.js.map +1 -1
  43. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js +15 -15
  44. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -1
  45. package/lib/esm/tree-widget-react/components/trees/index.d.ts +1 -0
  46. package/lib/esm/tree-widget-react/components/trees/index.js +1 -0
  47. package/lib/esm/tree-widget-react/components/trees/index.js.map +1 -1
  48. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js +12 -12
  49. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js.map +1 -1
  50. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.d.ts +6 -1
  51. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.js +7 -3
  52. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
  53. package/lib/esm/tree-widget-react/components/trees/models-tree/UseModelsTree.js +11 -11
  54. package/lib/esm/tree-widget-react/components/trees/models-tree/UseModelsTree.js.map +1 -1
  55. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.js.map +1 -1
  56. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.d.ts +5 -0
  57. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js +45 -0
  58. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js.map +1 -1
  59. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.d.ts +2 -1
  60. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js +128 -38
  61. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
  62. package/lib/public/locales/en/TreeWidget.json +15 -4
  63. package/package.json +3 -6
  64. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesVisibilityHandler.js +0 -87
  65. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesVisibilityHandler.js.map +0 -1
  66. package/lib/esm/tree-widget-react/components/trees/common/FocusedInstancesContextProvider.d.ts +0 -7
  67. package/lib/esm/tree-widget-react/components/trees/common/FocusedInstancesContextProvider.js +0 -66
  68. package/lib/esm/tree-widget-react/components/trees/common/FocusedInstancesContextProvider.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): "hidden" | "visible";
19
- getCategoryVisibility(node: HierarchyNode): "hidden" | "visible";
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;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAC;AAC5G,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAa7D,gBAAgB;AAChB,MAAM,OAAO,2BAA2B;IAKtC,YAAY,KAAuC;QAiB5C,uBAAkB,GAAG,IAAI,OAAO,EAAE,CAAC;QA4L1C,gEAAgE;QACxD,0BAAqB,GAAG,GAAG,EAAE;YACnC,IAAI,CAAC,0BAA0B,EAAE,CAAC;QACpC,CAAC,CAAC;QAEF,gEAAgE;QACxD,8BAAyB,GAAG,GAAG,EAAE;YACvC,IAAI,CAAC,0BAA0B,EAAE,CAAC;QACpC,CAAC,CAAC;QApNA,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAAC,WAAW,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;QAC7E,IAAI,C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F","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,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C,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,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AAC,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 */\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,11 +1,35 @@
1
- /// <reference types="react" />
2
- import type { InstanceKey } from "@itwin/presentation-shared";
1
+ import type { PropsWithChildren } from "react";
3
2
  import type { GroupingHierarchyNode } from "@itwin/presentation-hierarchies";
4
- export interface FocusedInstancesContext {
3
+ import type { SelectionStorage } from "@itwin/presentation-hierarchies-react";
4
+ import type { InstanceKey } from "@itwin/presentation-shared";
5
+ /** @public */
6
+ interface FocusedInstancesContext {
7
+ /**
8
+ * A function, returning an async iterator of items that should be focused. The function is not set
9
+ * when instances focus mode is disabled or selection is empty.
10
+ */
5
11
  loadFocusedItems?: () => AsyncIterableIterator<InstanceKey | GroupingHierarchyNode>;
12
+ /** A flag indicating whether instances focus mode is enabled. */
6
13
  enabled: boolean;
14
+ /** Toggle enable or disable instances focus mode. */
7
15
  toggle: () => void;
8
16
  }
9
- export declare const focusedInstancesContext: import("react").Context<FocusedInstancesContext>;
17
+ /**
18
+ * A React hook for getting focused instances context. The context must be provided
19
+ * using `FocusedInstancesContextProvider`.
20
+ *
21
+ * @public
22
+ */
10
23
  export declare function useFocusedInstancesContext(): FocusedInstancesContext;
24
+ /**
25
+ * A React context provider for setting up focused instances context, which can then be acquired
26
+ * using `useFocusedInstancesContext` hook.
27
+ *
28
+ * @public
29
+ */
30
+ export declare function FocusedInstancesContextProvider({ selectionStorage, imodelKey, children, }: PropsWithChildren<{
31
+ selectionStorage: SelectionStorage;
32
+ imodelKey: string;
33
+ }>): import("react/jsx-runtime").JSX.Element;
34
+ export {};
11
35
  //# sourceMappingURL=FocusedInstancesContext.d.ts.map
@@ -1,10 +1,81 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
1
2
  /*---------------------------------------------------------------------------------------------
2
3
  * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
4
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
5
  *--------------------------------------------------------------------------------------------*/
5
- import { createContext, useContext } from "react";
6
- export const focusedInstancesContext = createContext({ enabled: false, toggle: () => { } });
6
+ import { createContext, useContext, useEffect, useState } from "react";
7
+ import { HierarchyNode } from "@itwin/presentation-hierarchies-react";
8
+ import { Selectable, Selectables } from "@itwin/unified-selection";
9
+ const focusedInstancesContext = createContext({ enabled: false, toggle: () => { } });
10
+ /**
11
+ * A React hook for getting focused instances context. The context must be provided
12
+ * using `FocusedInstancesContextProvider`.
13
+ *
14
+ * @public
15
+ */
7
16
  export function useFocusedInstancesContext() {
8
17
  return useContext(focusedInstancesContext);
9
18
  }
19
+ /**
20
+ * A React context provider for setting up focused instances context, which can then be acquired
21
+ * using `useFocusedInstancesContext` hook.
22
+ *
23
+ * @public
24
+ */
25
+ export function FocusedInstancesContextProvider({ selectionStorage, imodelKey, children, }) {
26
+ const [state, setState] = useState({
27
+ enabled: false,
28
+ toggle: () => {
29
+ setState((prev) => ({ ...prev, enabled: !prev.enabled }));
30
+ },
31
+ });
32
+ const enabled = state.enabled;
33
+ useEffect(() => {
34
+ if (!enabled) {
35
+ setState((prev) => ({ ...prev, loadFocusedItems: undefined }));
36
+ return;
37
+ }
38
+ const onSelectionChanged = () => {
39
+ const selection = selectionStorage.getSelection({ imodelKey, level: 0 });
40
+ if (Selectables.isEmpty(selection)) {
41
+ setState((prev) => ({ ...prev, loadFocusedItems: undefined }));
42
+ return;
43
+ }
44
+ const selected = [];
45
+ Selectables.forEach(selection, (selectable) => {
46
+ if (Selectable.isInstanceKey(selectable)) {
47
+ selected.push(selectable);
48
+ return;
49
+ }
50
+ if (isHierarchyNode(selectable.data) && HierarchyNode.isGroupingNode(selectable.data)) {
51
+ selected.push(selectable.data);
52
+ return;
53
+ }
54
+ selected.push(selectable.loadInstanceKeys);
55
+ });
56
+ const loadFocusedItems = async function* () {
57
+ for (const item of selected) {
58
+ if (typeof item === "function") {
59
+ yield* item();
60
+ }
61
+ else {
62
+ yield item;
63
+ }
64
+ }
65
+ };
66
+ setState((prev) => ({ ...prev, loadFocusedItems }));
67
+ };
68
+ onSelectionChanged();
69
+ return selectionStorage.selectionChangeEvent.addListener(({ imodelKey: changeImodelKey, level }) => {
70
+ if (changeImodelKey !== imodelKey || level !== 0) {
71
+ return;
72
+ }
73
+ onSelectionChanged();
74
+ });
75
+ }, [enabled, imodelKey, selectionStorage]);
76
+ return _jsx(focusedInstancesContext.Provider, { value: state, children: children });
77
+ }
78
+ function isHierarchyNode(data) {
79
+ return !!data && typeof data === "object" && "key" in data;
80
+ }
10
81
  //# sourceMappingURL=FocusedInstancesContext.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"FocusedInstancesContext.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/FocusedInstancesContext.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAWlD,MAAM,CAAC,MAAM,uBAAuB,GAAG,aAAa,CAA0B,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC,CAAC;AAEpH,MAAM,UAAU,0BAA0B;IACxC,OAAO,UAAU,CAAC,uBAAuB,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { createContext, useContext } from \"react\";\n\nimport type { InstanceKey } from \"@itwin/presentation-shared\";\nimport type { GroupingHierarchyNode } from \"@itwin/presentation-hierarchies\";\n\nexport interface FocusedInstancesContext {\n loadFocusedItems?: () => AsyncIterableIterator<InstanceKey | GroupingHierarchyNode>;\n enabled: boolean;\n toggle: () => void;\n}\n\nexport const focusedInstancesContext = createContext<FocusedInstancesContext>({ enabled: false, toggle: () => {} });\n\nexport function useFocusedInstancesContext() {\n return useContext(focusedInstancesContext);\n}\n"]}
1
+ {"version":3,"file":"FocusedInstancesContext.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/FocusedInstancesContext.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AACtE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAsBnE,MAAM,uBAAuB,GAAG,aAAa,CAA0B,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC,CAAC;AAE7G;;;;;GAKG;AACH,MAAM,UAAU,0BAA0B;IACxC,OAAO,U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AAC;AAC7D,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { createContext, useContext, useEffect, useState } from \"react\";\nimport { HierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport { Selectable, Selectables } from \"@itwin/unified-selection\";\n\nimport type { PropsWithChildren } from \"react\";\nimport type { GroupingHierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport type { SelectionStorage } from \"@itwin/presentation-hierarchies-react\";\nimport type { InstanceKey } from \"@itwin/presentation-shared\";\n\n/** @public */\ninterface FocusedInstancesContext {\n /**\n * A function, returning an async iterator of items that should be focused. The function is not set\n * when instances focus mode is disabled or selection is empty.\n */\n loadFocusedItems?: () => AsyncIterableIterator<InstanceKey | GroupingHierarchyNode>;\n\n /** A flag indicating whether instances focus mode is enabled. */\n enabled: boolean;\n\n /** Toggle enable or disable instances focus mode. */\n toggle: () => void;\n}\n\nconst focusedInstancesContext = createContext<FocusedInstancesContext>({ enabled: false, toggle: () => {} });\n\n/**\n * A React hook for getting focused instances context. The context must be provided\n * using `FocusedInstancesContextProvider`.\n *\n * @public\n */\nexport function useFocusedInstancesContext(): FocusedInstancesContext {\n return useContext(focusedInstancesContext);\n}\n\n/**\n * A React context provider for setting up focused instances context, which can then be acquired\n * using `useFocusedInstancesContext` hook.\n *\n * @public\n */\nexport function FocusedInstancesContextProvider({\n selectionStorage,\n imodelKey,\n children,\n}: PropsWithChildren<{ selectionStorage: SelectionStorage; imodelKey: string }>) {\n const [state, setState] = useState<FocusedInstancesContext>({\n enabled: false,\n toggle: () => {\n setState((prev) => ({ ...prev, enabled: !prev.enabled }));\n },\n });\n const enabled = state.enabled;\n\n useEffect(() => {\n if (!enabled) {\n setState((prev) => ({ ...prev, loadFocusedItems: undefined }));\n return;\n }\n\n const onSelectionChanged = () => {\n const selection = selectionStorage.getSelection({ imodelKey, level: 0 });\n if (Selectables.isEmpty(selection)) {\n setState((prev) => ({ ...prev, loadFocusedItems: undefined }));\n return;\n }\n\n const selected: Array<InstanceKey | GroupingHierarchyNode | (() => AsyncIterableIterator<InstanceKey>)> = [];\n Selectables.forEach(selection, (selectable) => {\n if (Selectable.isInstanceKey(selectable)) {\n selected.push(selectable);\n return;\n }\n\n if (isHierarchyNode(selectable.data) && HierarchyNode.isGroupingNode(selectable.data)) {\n selected.push(selectable.data);\n return;\n }\n\n selected.push(selectable.loadInstanceKeys);\n });\n\n const loadFocusedItems: () => AsyncIterableIterator<InstanceKey | GroupingHierarchyNode> = async function* () {\n for (const item of selected) {\n if (typeof item === \"function\") {\n yield* item();\n } else {\n yield item;\n }\n }\n };\n\n setState((prev) => ({ ...prev, loadFocusedItems }));\n };\n\n onSelectionChanged();\n return selectionStorage.selectionChangeEvent.addListener(({ imodelKey: changeImodelKey, level }) => {\n if (changeImodelKey !== imodelKey || level !== 0) {\n return;\n }\n onSelectionChanged();\n });\n }, [enabled, imodelKey, selectionStorage]);\n\n return <focusedInstancesContext.Provider value={state}>{children}</focusedInstancesContext.Provider>;\n}\n\nfunction isHierarchyNode(data: unknown): data is HierarchyNode {\n return !!data && typeof data === \"object\" && \"key\" in data;\n}\n"]}
@@ -35,7 +35,7 @@ export type TreeProps = Pick<FunctionProps<typeof useIModelTree>, "getFilteredPa
35
35
  };
36
36
  /**
37
37
  * Default tree component that manages tree state and renders using supplied `treeRenderer`.
38
- * @Beta
38
+ * @beta
39
39
  */
40
40
  export declare function Tree({ getSchemaContext, hierarchyLevelSizeLimit, selectionStorage, imodelAccess: providedIModelAccess, ...props }: TreeProps): import("react/jsx-runtime").JSX.Element;
41
41
  //# sourceMappingURL=Tree.d.ts.map
@@ -8,7 +8,6 @@ import { BeEvent } from "@itwin/core-bentley";
8
8
  import { Spinner } from "@itwin/itwinui-react/bricks";
9
9
  import { SchemaMetadataContextProvider } from "@itwin/presentation-components";
10
10
  import { useIModelUnifiedSelectionTree } from "@itwin/presentation-hierarchies-react";
11
- import { UnifiedSelectionContextProvider } from "@itwin/unified-selection-react";
12
11
  import { useHierarchiesLocalization } from "../UseHierarchiesLocalization.js";
13
12
  import { useHierarchyLevelFiltering } from "../UseHierarchyFiltering.js";
14
13
  import { useIModelChangeListener } from "../UseIModelChangeListener.js";
@@ -20,7 +19,7 @@ import { EmptyTreeContent } from "./EmptyTreeContent.js";
20
19
  import { ProgressOverlay } from "./ProgressOverlay.js";
21
20
  /**
22
21
  * Default tree component that manages tree state and renders using supplied `treeRenderer`.
23
- * @Beta
22
+ * @beta
24
23
  */
25
24
  export function Tree({ getSchemaContext, hierarchyLevelSizeLimit, selectionStorage, imodelAccess: providedIModelAccess, ...props }) {
26
25
  const defaultHierarchyLevelSizeLimit = hierarchyLevelSizeLimit ?? 1000;
@@ -36,11 +35,11 @@ function TreeImpl({ imodel, imodelAccess, treeName, emptyTreeContent, getFiltere
36
35
  const { rootNodes, getNode, isLoading, selectNodes: selectNodesAction, setFormatter: _setFormatter, expandNode, ...treeProps } = useIModelUnifiedSelectionTree({
37
36
  imodelAccess,
38
37
  imodelChanged,
39
- selectionStorage,
40
38
  getHierarchyDefinition,
41
39
  getFilteredPaths,
42
40
  sourceName: treeName,
43
41
  localizedStrings,
42
+ selectionStorage,
44
43
  onPerformanceMeasured: (action, duration) => {
45
44
  if (action === "reload") {
46
45
  onReload?.();
@@ -82,7 +81,7 @@ function TreeImpl({ imodel, imodelAccess, treeName, emptyTreeContent, getFiltere
82
81
  onFilterClick: reportingOnFilterClicked,
83
82
  getLabel,
84
83
  };
85
- return (_jsx(UnifiedSelectionContextProvider, { storage: selectionStorage, children: _jsxs("div", { style: { position: "relative", height: "100%", overflow: "hidden" }, children: [_jsxs("div", { id: "tw-tree-renderer-container", style: { overflow: "auto", height: "100%" }, children: [treeRenderer(treeRendererProps), filteringDialog] }), _jsx(Delayed, { show: isLoading, children: _jsx(ProgressOverlay, {}) })] }) }));
84
+ return (_jsxs("div", { style: { position: "relative", height: "100%", overflow: "hidden" }, children: [_jsxs("div", { id: "tw-tree-renderer-container", style: { overflow: "auto", height: "100%" }, children: [treeRenderer(treeRendererProps), filteringDialog] }), _jsx(Delayed, { show: isLoading, children: _jsx(ProgressOverlay, {}) })] }));
86
85
  }
87
86
  function useSelectionPredicate({ action, predicate, getNode, }) {
88
87
  return useCallback((nodeIds, changeType) => action(nodeIds.filter((nodeId) => {