@itwin/tree-widget-react 4.0.0-alpha.6 → 4.0.0-alpha.7

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 (159) hide show
  1. package/CHANGELOG.md +22 -1
  2. package/README.md +2 -1
  3. package/lib/esm/tree-widget-react/TreeWidget.js +1 -1
  4. package/lib/esm/tree-widget-react/TreeWidget.js.map +1 -1
  5. package/lib/esm/tree-widget-react/components/tree-header/SearchBox.d.ts +1 -0
  6. package/lib/esm/tree-widget-react/components/tree-header/SearchBox.js +1 -0
  7. package/lib/esm/tree-widget-react/components/tree-header/SearchBox.js.map +1 -1
  8. package/lib/esm/tree-widget-react/components/tree-header/SelectableTree.css +2 -0
  9. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.d.ts +9 -2
  10. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js +50 -4
  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/CategoriesTreeComponent.js +1 -1
  13. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeComponent.js.map +1 -1
  14. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.d.ts +17 -3
  15. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js +561 -161
  16. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js.map +1 -1
  17. package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.d.ts +6 -2
  18. package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js +115 -40
  19. package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js.map +1 -1
  20. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.d.ts +30 -15
  21. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js +192 -38
  22. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js.map +1 -1
  23. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.d.ts +18 -3
  24. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.js +30 -3
  25. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.js.map +1 -1
  26. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeVisibilityHandler.d.ts +24 -0
  27. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeVisibilityHandler.js +785 -0
  28. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeVisibilityHandler.js.map +1 -0
  29. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/FilteredTree.d.ts +39 -0
  30. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/FilteredTree.js +221 -0
  31. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/FilteredTree.js.map +1 -0
  32. package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.d.ts +5 -17
  33. package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js +5 -62
  34. package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js.map +1 -1
  35. package/lib/esm/tree-widget-react/components/trees/common/UseHierarchyVisibility.d.ts +2 -0
  36. package/lib/esm/tree-widget-react/components/trees/common/UseHierarchyVisibility.js +4 -2
  37. package/lib/esm/tree-widget-react/components/trees/common/UseHierarchyVisibility.js.map +1 -1
  38. package/lib/esm/tree-widget-react/components/trees/common/UseNodeHighlighting.d.ts +1 -0
  39. package/lib/esm/tree-widget-react/components/trees/common/UseNodeHighlighting.js +2 -1
  40. package/lib/esm/tree-widget-react/components/trees/common/UseNodeHighlighting.js.map +1 -1
  41. package/lib/esm/tree-widget-react/components/trees/common/UseTelemetryContext.d.ts +1 -0
  42. package/lib/esm/tree-widget-react/components/trees/common/UseTelemetryContext.js +2 -1
  43. package/lib/esm/tree-widget-react/components/trees/common/UseTelemetryContext.js.map +1 -1
  44. package/lib/esm/tree-widget-react/components/trees/common/Utils.d.ts +33 -23
  45. package/lib/esm/tree-widget-react/components/trees/common/Utils.js +60 -47
  46. package/lib/esm/tree-widget-react/components/trees/common/Utils.js.map +1 -1
  47. package/lib/esm/tree-widget-react/components/trees/common/components/BaseTreeRenderer.js +3 -3
  48. package/lib/esm/tree-widget-react/components/trees/common/components/BaseTreeRenderer.js.map +1 -1
  49. package/lib/esm/tree-widget-react/components/trees/common/components/Delayed.d.ts +1 -0
  50. package/lib/esm/tree-widget-react/components/trees/common/components/Delayed.js +1 -0
  51. package/lib/esm/tree-widget-react/components/trees/common/components/Delayed.js.map +1 -1
  52. package/lib/esm/tree-widget-react/components/trees/common/components/ProgressOverlay.d.ts +1 -0
  53. package/lib/esm/tree-widget-react/components/trees/common/components/ProgressOverlay.js +1 -0
  54. package/lib/esm/tree-widget-react/components/trees/common/components/ProgressOverlay.js.map +1 -1
  55. package/lib/esm/tree-widget-react/components/trees/common/components/Tree.css +2 -1
  56. package/lib/esm/tree-widget-react/components/trees/common/components/Tree.js +4 -4
  57. package/lib/esm/tree-widget-react/components/trees/common/components/Tree.js.map +1 -1
  58. package/lib/esm/tree-widget-react/components/trees/common/components/UseVisibilityButtonHandler.d.ts +1 -0
  59. package/lib/esm/tree-widget-react/components/trees/common/components/UseVisibilityButtonHandler.js +1 -0
  60. package/lib/esm/tree-widget-react/components/trees/common/components/UseVisibilityButtonHandler.js.map +1 -1
  61. package/lib/esm/tree-widget-react/components/trees/common/components/VisibilityTree.js +1 -1
  62. package/lib/esm/tree-widget-react/components/trees/common/components/VisibilityTree.js.map +1 -1
  63. package/lib/esm/tree-widget-react/components/trees/common/components/VisibilityTreeRenderer.js.map +1 -1
  64. package/lib/esm/tree-widget-react/components/trees/common/internal/AlwaysAndNeverDrawnElementInfo.d.ts +44 -0
  65. package/lib/esm/tree-widget-react/components/trees/{models-tree → common}/internal/AlwaysAndNeverDrawnElementInfo.js +81 -31
  66. package/lib/esm/tree-widget-react/components/trees/common/internal/AlwaysAndNeverDrawnElementInfo.js.map +1 -0
  67. package/lib/esm/tree-widget-react/components/trees/common/internal/ClassNameDefinitions.d.ts +33 -0
  68. package/lib/esm/tree-widget-react/components/trees/common/internal/ClassNameDefinitions.js +37 -0
  69. package/lib/esm/tree-widget-react/components/trees/common/internal/ClassNameDefinitions.js.map +1 -0
  70. package/lib/esm/tree-widget-react/components/trees/common/internal/ModelCategoryElementsCountCache.d.ts +16 -0
  71. package/lib/esm/tree-widget-react/components/trees/common/internal/ModelCategoryElementsCountCache.js +72 -0
  72. package/lib/esm/tree-widget-react/components/trees/common/internal/ModelCategoryElementsCountCache.js.map +1 -0
  73. package/lib/esm/tree-widget-react/components/trees/common/{Rxjs.d.ts → internal/Rxjs.d.ts} +9 -2
  74. package/lib/esm/tree-widget-react/components/trees/common/{Rxjs.js → internal/Rxjs.js} +9 -2
  75. package/lib/esm/tree-widget-react/components/trees/common/internal/Rxjs.js.map +1 -0
  76. package/lib/esm/tree-widget-react/components/trees/common/{Tooltip.d.ts → internal/Tooltip.d.ts} +5 -1
  77. package/lib/esm/tree-widget-react/components/trees/common/{Tooltip.js → internal/Tooltip.js} +7 -1
  78. package/lib/esm/tree-widget-react/components/trees/common/internal/Tooltip.js.map +1 -0
  79. package/lib/esm/tree-widget-react/components/trees/common/internal/Types.d.ts +14 -0
  80. package/lib/esm/tree-widget-react/components/trees/{categories-tree/internal/ClassNameDefinitions.js → common/internal/Types.js} +2 -7
  81. package/lib/esm/tree-widget-react/components/trees/common/internal/Types.js.map +1 -0
  82. package/lib/esm/tree-widget-react/components/trees/common/internal/UseActiveViewport.js.map +1 -0
  83. package/lib/esm/tree-widget-react/components/trees/common/{UseHierarchiesLocalization.d.ts → internal/UseHierarchiesLocalization.d.ts} +1 -0
  84. package/lib/esm/tree-widget-react/components/trees/common/{UseHierarchiesLocalization.js → internal/UseHierarchiesLocalization.js} +6 -2
  85. package/lib/esm/tree-widget-react/components/trees/common/internal/UseHierarchiesLocalization.js.map +1 -0
  86. package/lib/esm/tree-widget-react/components/trees/common/{UseHierarchyFiltering.d.ts → internal/UseHierarchyFiltering.d.ts} +1 -0
  87. package/lib/esm/tree-widget-react/components/trees/common/{UseHierarchyFiltering.js → internal/UseHierarchyFiltering.js} +4 -3
  88. package/lib/esm/tree-widget-react/components/trees/common/internal/UseHierarchyFiltering.js.map +1 -0
  89. package/lib/esm/tree-widget-react/components/trees/common/{UseIModelChangeListener.d.ts → internal/UseIModelChangeListener.d.ts} +1 -0
  90. package/lib/esm/tree-widget-react/components/trees/common/{UseIModelChangeListener.js → internal/UseIModelChangeListener.js} +1 -0
  91. package/lib/esm/tree-widget-react/components/trees/common/internal/UseIModelChangeListener.js.map +1 -0
  92. package/lib/esm/tree-widget-react/components/trees/common/internal/Utils.d.ts +47 -0
  93. package/lib/esm/tree-widget-react/components/trees/common/internal/Utils.js +101 -0
  94. package/lib/esm/tree-widget-react/components/trees/common/internal/Utils.js.map +1 -0
  95. package/lib/esm/tree-widget-react/components/trees/common/internal/VisibilityChangeEventListener.d.ts +20 -0
  96. package/lib/esm/tree-widget-react/components/trees/{models-tree → common}/internal/VisibilityChangeEventListener.js +17 -9
  97. package/lib/esm/tree-widget-react/components/trees/common/internal/VisibilityChangeEventListener.js.map +1 -0
  98. package/lib/esm/tree-widget-react/components/trees/common/internal/VisibilityUtils.d.ts +82 -0
  99. package/lib/esm/tree-widget-react/components/trees/common/internal/VisibilityUtils.js +234 -0
  100. package/lib/esm/tree-widget-react/components/trees/common/internal/VisibilityUtils.js.map +1 -0
  101. package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTree.js.map +1 -1
  102. package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js.map +1 -1
  103. package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeDefinition.d.ts +1 -0
  104. package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeDefinition.js +1 -0
  105. package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeDefinition.js.map +1 -1
  106. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.d.ts +3 -1
  107. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js +13 -9
  108. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -1
  109. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeComponent.d.ts +1 -1
  110. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeComponent.js.map +1 -1
  111. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeDefinition.d.ts +13 -0
  112. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeDefinition.js +39 -38
  113. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeDefinition.js.map +1 -1
  114. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/internal/IModelContentTreeIdsCache.d.ts +5 -5
  115. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/internal/IModelContentTreeIdsCache.js +25 -24
  116. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/internal/IModelContentTreeIdsCache.js.map +1 -1
  117. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js +9 -5
  118. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js.map +1 -1
  119. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.js +1 -1
  120. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
  121. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.d.ts +7 -2
  122. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js +73 -70
  123. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js.map +1 -1
  124. package/lib/esm/tree-widget-react/components/trees/models-tree/UseModelsTree.js +47 -29
  125. package/lib/esm/tree-widget-react/components/trees/models-tree/UseModelsTree.js.map +1 -1
  126. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/FilteredTree.d.ts +7 -9
  127. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/FilteredTree.js +4 -6
  128. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/FilteredTree.js.map +1 -1
  129. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.d.ts +4 -5
  130. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js +54 -104
  131. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js.map +1 -1
  132. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.d.ts +0 -26
  133. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js +75 -291
  134. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
  135. package/lib/public/locales/en/TreeWidget.json +51 -6
  136. package/package.json +17 -18
  137. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.d.ts +0 -37
  138. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js +0 -214
  139. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js.map +0 -1
  140. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.d.ts +0 -7
  141. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.js.map +0 -1
  142. package/lib/esm/tree-widget-react/components/trees/common/Rxjs.js.map +0 -1
  143. package/lib/esm/tree-widget-react/components/trees/common/Tooltip.js.map +0 -1
  144. package/lib/esm/tree-widget-react/components/trees/common/UseActiveViewport.js.map +0 -1
  145. package/lib/esm/tree-widget-react/components/trees/common/UseFiltering.d.ts +0 -11
  146. package/lib/esm/tree-widget-react/components/trees/common/UseFiltering.js +0 -24
  147. package/lib/esm/tree-widget-react/components/trees/common/UseFiltering.js.map +0 -1
  148. package/lib/esm/tree-widget-react/components/trees/common/UseHierarchiesLocalization.js.map +0 -1
  149. package/lib/esm/tree-widget-react/components/trees/common/UseHierarchyFiltering.js.map +0 -1
  150. package/lib/esm/tree-widget-react/components/trees/common/UseIModelChangeListener.js.map +0 -1
  151. package/lib/esm/tree-widget-react/components/trees/models-tree/Utils.d.ts +0 -7
  152. package/lib/esm/tree-widget-react/components/trees/models-tree/Utils.js +0 -21
  153. package/lib/esm/tree-widget-react/components/trees/models-tree/Utils.js.map +0 -1
  154. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.d.ts +0 -29
  155. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.js.map +0 -1
  156. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/VisibilityChangeEventListener.d.ts +0 -12
  157. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/VisibilityChangeEventListener.js.map +0 -1
  158. /package/lib/esm/tree-widget-react/components/trees/common/{UseActiveViewport.d.ts → internal/UseActiveViewport.d.ts} +0 -0
  159. /package/lib/esm/tree-widget-react/components/trees/common/{UseActiveViewport.js → internal/UseActiveViewport.js} +0 -0
@@ -1,31 +1,51 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import type { CategoryId, DefinitionContainerId, ModelId, SubCategoryId } from "../../common/internal/Types.js";
1
3
  import type { Id64Array, Id64String } from "@itwin/core-bentley";
2
4
  import type { LimitingECSqlQueryExecutor } from "@itwin/presentation-hierarchies";
3
5
  import type { InstanceKey } from "@itwin/presentation-shared";
4
- interface CategoryInfo {
5
- id: Id64String;
6
- childCount: number;
6
+ /** @internal */
7
+ export interface CategoryInfo {
8
+ id: CategoryId;
9
+ subCategoryChildCount: number;
7
10
  }
8
11
  /** @internal */
9
- export declare class CategoriesTreeIdsCache {
12
+ export declare class CategoriesTreeIdsCache implements Disposable {
10
13
  private _queryExecutor;
11
14
  private _definitionContainersInfo;
12
15
  private _modelsCategoriesInfo;
16
+ private _elementModelsCategories;
13
17
  private _subCategoriesInfo;
18
+ private readonly _categoryElementCounts;
19
+ private _modelWithCategoryModeledElements;
14
20
  private _categoryClass;
15
21
  private _categoryElementClass;
22
+ private _categoryModelClass;
16
23
  private _isDefinitionContainerSupported;
24
+ private _filteredElementsModels;
17
25
  constructor(_queryExecutor: LimitingECSqlQueryExecutor, viewType: "3d" | "2d");
26
+ [Symbol.dispose](): void;
27
+ private queryFilteredElementsModels;
28
+ getFilteredElementsModels(filteredElementIds: Id64Array): Promise<Map<string, string>>;
29
+ clearFilteredElementsModels(): void;
30
+ private queryElementModelCategories;
18
31
  private queryCategories;
19
32
  private queryIsDefinitionContainersSupported;
20
33
  private queryDefinitionContainers;
21
34
  private queryVisibleSubCategories;
22
35
  private getModelsCategoriesInfo;
36
+ private getElementModelsCategories;
37
+ private queryModeledElements;
38
+ private getModelWithCategoryModeledElements;
39
+ getCategoriesModeledElements(modelId: Id64String, categoryIds: Id64Array): Promise<Id64Array>;
23
40
  private getSubCategoriesInfo;
24
41
  private getDefinitionContainersInfo;
25
42
  getDirectChildDefinitionContainersAndCategories(parentDefinitionContainerIds: Id64Array): Promise<{
26
43
  categories: CategoryInfo[];
27
- definitionContainers: Id64Array;
44
+ definitionContainers: Array<DefinitionContainerId>;
28
45
  }>;
46
+ getCategoriesElementModels(categoryIds: Id64Array, includeSubModels?: boolean): Promise<Map<CategoryId, Array<ModelId>>>;
47
+ getModelCategoryIds(modelId: Id64String): Promise<Id64Array>;
48
+ hasSubModel(elementId: Id64String): Promise<boolean>;
29
49
  getAllContainedCategories(definitionContainerIds: Id64Array): Promise<Id64Array>;
30
50
  getInstanceKeyPaths(props: {
31
51
  categoryId: Id64String;
@@ -34,21 +54,16 @@ export declare class CategoriesTreeIdsCache {
34
54
  } | {
35
55
  subCategoryId: Id64String;
36
56
  }): Promise<InstanceKey[]>;
57
+ getCategoryElementsCount(modelId: Id64String, categoryId: Id64String): Promise<number>;
37
58
  getAllDefinitionContainersAndCategories(): Promise<{
38
- categories: Id64Array;
39
- definitionContainers: Id64Array;
59
+ categories: Array<CategoryId>;
60
+ definitionContainers: Array<DefinitionContainerId>;
40
61
  }>;
41
62
  getRootDefinitionContainersAndCategories(): Promise<{
42
63
  categories: CategoryInfo[];
43
- definitionContainers: Id64Array;
64
+ definitionContainers: Array<DefinitionContainerId>;
44
65
  }>;
45
- getSubCategories(categoryId: Id64String): Promise<Id64Array>;
66
+ getSubCategories(categoryIds: Id64Array): Promise<Map<CategoryId, Array<SubCategoryId>>>;
46
67
  getIsDefinitionContainerSupported(): Promise<boolean>;
47
68
  }
48
- /** @internal */
49
- export declare function getClassesByView(viewType: "2d" | "3d"): {
50
- categoryClass: string;
51
- categoryElementClass: string;
52
- };
53
- export {};
54
69
  //# sourceMappingURL=CategoriesTreeIdsCache.d.ts.map
@@ -2,41 +2,91 @@
2
2
  * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
3
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
4
  *--------------------------------------------------------------------------------------------*/
5
- import { DEFINITION_CONTAINER_CLASS, SUB_CATEGORY_CLASS } from "./ClassNameDefinitions.js";
5
+ import { DEFINITION_CONTAINER_CLASS_NAME, MODEL_CLASS_NAME, SUB_CATEGORY_CLASS_NAME } from "../../common/internal/ClassNameDefinitions.js";
6
+ import { ModelCategoryElementsCountCache } from "../../common/internal/ModelCategoryElementsCountCache.js";
7
+ import { getClassesByView, getDistinctMapValues } from "../../common/internal/Utils.js";
6
8
  /** @internal */
7
9
  export class CategoriesTreeIdsCache {
8
10
  constructor(_queryExecutor, viewType) {
9
11
  this._queryExecutor = _queryExecutor;
10
- const { categoryClass, categoryElementClass } = getClassesByView(viewType);
12
+ const { categoryClass, elementClass, modelClass } = getClassesByView(viewType);
11
13
  this._categoryClass = categoryClass;
12
- this._categoryElementClass = categoryElementClass;
14
+ this._categoryElementClass = elementClass;
15
+ this._categoryModelClass = modelClass;
16
+ this._categoryElementCounts = new ModelCategoryElementsCountCache(_queryExecutor, elementClass);
17
+ }
18
+ [Symbol.dispose]() {
19
+ this._categoryElementCounts[Symbol.dispose]();
20
+ }
21
+ async *queryFilteredElementsModels(filteredElementIds) {
22
+ const query = `
23
+ SELECT Model.Id modelId, ECInstanceId id
24
+ FROM ${this._categoryElementClass}
25
+ WHERE ECInstanceId IN (${filteredElementIds.join(", ")})
26
+ `;
27
+ for await (const row of this._queryExecutor.createQueryReader({ ecsql: query }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded" })) {
28
+ yield { modelId: row.modelId, id: row.id };
29
+ }
30
+ }
31
+ async getFilteredElementsModels(filteredElementIds) {
32
+ if (filteredElementIds.length === 0) {
33
+ return new Map();
34
+ }
35
+ this._filteredElementsModels ??= (async () => {
36
+ const filteredElementsModels = new Map();
37
+ for await (const { modelId, id } of this.queryFilteredElementsModels(filteredElementIds)) {
38
+ filteredElementsModels.set(id, modelId);
39
+ }
40
+ return filteredElementsModels;
41
+ })();
42
+ return this._filteredElementsModels;
43
+ }
44
+ clearFilteredElementsModels() {
45
+ this._filteredElementsModels = undefined;
46
+ }
47
+ async *queryElementModelCategories() {
48
+ const query = `
49
+ SELECT this.Model.Id modelId, this.Category.Id categoryId, m.IsPrivate isModelPrivate
50
+ FROM ${this._categoryModelClass} m
51
+ JOIN ${this._categoryElementClass} this ON m.ECInstanceId = this.Model.Id
52
+ WHERE this.Parent.Id IS NULL
53
+ GROUP BY modelId, categoryId, isModelPrivate
54
+ `;
55
+ for await (const row of this._queryExecutor.createQueryReader({ ecsql: query }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded", restartToken: "tree-widget/categories-tree/element-models-and-categories-query" })) {
56
+ yield { modelId: row.modelId, categoryId: row.categoryId, isModelPrivate: !!row.isModelPrivate };
57
+ }
13
58
  }
14
59
  async *queryCategories() {
15
60
  const isDefinitionContainerSupported = await this.getIsDefinitionContainerSupported();
16
61
  const categoriesQuery = `
17
62
  SELECT
18
63
  this.ECInstanceId id,
19
- COUNT(sc.ECInstanceId) childCount,
64
+ COUNT(sc.ECInstanceId) subCategoryChildCount,
20
65
  this.Model.Id modelId,
21
66
  ${isDefinitionContainerSupported
22
67
  ? `
23
- IIF(this.Model.Id IN (SELECT dc.ECInstanceId FROM ${DEFINITION_CONTAINER_CLASS} dc),
68
+ IIF(this.Model.Id IN (SELECT dc.ECInstanceId FROM ${DEFINITION_CONTAINER_CLASS_NAME} dc),
24
69
  true,
25
70
  false
26
71
  )`
27
72
  : "false"} parentDefinitionContainerExists
28
73
  FROM
29
74
  ${this._categoryClass} this
30
- JOIN ${SUB_CATEGORY_CLASS} sc ON sc.Parent.Id = this.ECInstanceId
31
- JOIN BisCore.Model m ON m.ECInstanceId = this.Model.Id
75
+ JOIN ${SUB_CATEGORY_CLASS_NAME} sc ON sc.Parent.Id = this.ECInstanceId
76
+ JOIN ${MODEL_CLASS_NAME} m ON m.ECInstanceId = this.Model.Id
32
77
  WHERE
33
78
  NOT this.IsPrivate
34
79
  AND (NOT m.IsPrivate OR m.ECClassId IS (BisCore.DictionaryModel))
35
80
  AND EXISTS (SELECT 1 FROM ${this._categoryElementClass} e WHERE e.Category.Id = this.ECInstanceId)
36
81
  GROUP BY this.ECInstanceId
37
82
  `;
38
- for await (const row of this._queryExecutor.createQueryReader({ ecsql: categoriesQuery }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded" })) {
39
- yield { id: row.id, modelId: row.modelId, parentDefinitionContainerExists: row.parentDefinitionContainerExists, childCount: row.childCount };
83
+ for await (const row of this._queryExecutor.createQueryReader({ ecsql: categoriesQuery }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded", restartToken: "tree-widget/categories-tree/categories-query" })) {
84
+ yield {
85
+ id: row.id,
86
+ modelId: row.modelId,
87
+ parentDefinitionContainerExists: row.parentDefinitionContainerExists,
88
+ subCategoryChildCount: row.subCategoryChildCount,
89
+ };
40
90
  }
41
91
  }
42
92
  async queryIsDefinitionContainersSupported() {
@@ -50,7 +100,7 @@ export class CategoriesTreeIdsCache {
50
100
  s.Name = 'BisCore'
51
101
  AND c.Name = 'DefinitionContainer'
52
102
  `;
53
- for await (const _row of this._queryExecutor.createQueryReader({ ecsql: query })) {
103
+ for await (const _row of this._queryExecutor.createQueryReader({ ecsql: query }, { restartToken: "tree-widget/categories-tree/is-definition-container-supported-query" })) {
54
104
  return true;
55
105
  }
56
106
  return false;
@@ -68,9 +118,9 @@ export class CategoriesTreeIdsCache {
68
118
  dc.ECInstanceId,
69
119
  dc.Model.Id
70
120
  FROM
71
- ${DEFINITION_CONTAINER_CLASS} dc
121
+ ${DEFINITION_CONTAINER_CLASS_NAME} dc
72
122
  WHERE
73
- dc.ECInstanceId IN (SELECT c.Model.Id FROM ${this._categoryClass} c WHERE NOT c.IsPrivate)
123
+ dc.ECInstanceId IN (SELECT c.Model.Id FROM ${this._categoryClass} c WHERE NOT c.IsPrivate AND EXISTS (SELECT 1 FROM ${this._categoryElementClass} e WHERE e.Category.Id = c.ECInstanceId))
74
124
  AND NOT dc.IsPrivate
75
125
 
76
126
  UNION ALL
@@ -80,7 +130,7 @@ export class CategoriesTreeIdsCache {
80
130
  pdc.Model.Id
81
131
  FROM
82
132
  ${DEFINITION_CONTAINERS_CTE} cdc
83
- JOIN ${DEFINITION_CONTAINER_CLASS} pdc ON pdc.ECInstanceId = cdc.ModelId
133
+ JOIN ${DEFINITION_CONTAINER_CLASS_NAME} pdc ON pdc.ECInstanceId = cdc.ModelId
84
134
  WHERE
85
135
  NOT pdc.IsPrivate
86
136
  )
@@ -89,22 +139,22 @@ export class CategoriesTreeIdsCache {
89
139
  const definitionsQuery = `
90
140
  SELECT dc.ECInstanceId id, dc.ModelId modelId FROM ${DEFINITION_CONTAINERS_CTE} dc GROUP BY dc.ECInstanceId
91
141
  `;
92
- for await (const row of this._queryExecutor.createQueryReader({ ctes, ecsql: definitionsQuery }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded" })) {
142
+ for await (const row of this._queryExecutor.createQueryReader({ ctes, ecsql: definitionsQuery }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded", restartToken: "tree-widget/categories-tree/definition-containers-query" })) {
93
143
  yield { id: row.id, modelId: row.modelId };
94
144
  }
95
145
  }
96
- async *queryVisibleSubCategories(categoriesInfo) {
146
+ async *queryVisibleSubCategories(categoryIds) {
97
147
  const definitionsQuery = `
98
148
  SELECT
99
149
  sc.ECInstanceId id,
100
150
  sc.Parent.Id categoryId
101
151
  FROM
102
- ${SUB_CATEGORY_CLASS} sc
152
+ ${SUB_CATEGORY_CLASS_NAME} sc
103
153
  WHERE
104
154
  NOT sc.IsPrivate
105
- AND sc.Parent.Id IN (${categoriesInfo.join(",")})
155
+ AND sc.Parent.Id IN (${categoryIds.join(",")})
106
156
  `;
107
- for await (const row of this._queryExecutor.createQueryReader({ ecsql: definitionsQuery }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded" })) {
157
+ for await (const row of this._queryExecutor.createQueryReader({ ecsql: definitionsQuery }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded", restartToken: "tree-widget/categories-tree/sub-categories-query" })) {
108
158
  yield { id: row.id, parentId: row.categoryId };
109
159
  }
110
160
  }
@@ -117,19 +167,90 @@ export class CategoriesTreeIdsCache {
117
167
  modelCategories = { parentDefinitionContainerExists: queriedCategory.parentDefinitionContainerExists, childCategories: [] };
118
168
  allModelsCategories.set(queriedCategory.modelId, modelCategories);
119
169
  }
120
- modelCategories.childCategories.push({ id: queriedCategory.id, childCount: queriedCategory.childCount });
170
+ modelCategories.childCategories.push({ id: queriedCategory.id, subCategoryChildCount: queriedCategory.subCategoryChildCount });
121
171
  }
122
172
  return allModelsCategories;
123
173
  })();
124
174
  return this._modelsCategoriesInfo;
125
175
  }
176
+ async getElementModelsCategories() {
177
+ this._elementModelsCategories ??= (async () => {
178
+ const [modelCategories, modelWithCategoryModeledElements] = await Promise.all([
179
+ (async () => {
180
+ const elementModelsCategories = new Map();
181
+ for await (const queriedCategory of this.queryElementModelCategories()) {
182
+ let modelEntry = elementModelsCategories.get(queriedCategory.modelId);
183
+ if (modelEntry === undefined) {
184
+ modelEntry = { categoryIds: new Set(), isModelPrivate: queriedCategory.isModelPrivate };
185
+ elementModelsCategories.set(queriedCategory.modelId, modelEntry);
186
+ }
187
+ modelEntry.categoryIds.add(queriedCategory.categoryId);
188
+ }
189
+ return elementModelsCategories;
190
+ })(),
191
+ this.getModelWithCategoryModeledElements(),
192
+ ]);
193
+ const result = new Map();
194
+ const subModels = getDistinctMapValues(modelWithCategoryModeledElements);
195
+ for (const [modelId, modelEntry] of modelCategories) {
196
+ const isSubModel = subModels.has(modelId);
197
+ result.set(modelId, { categoryIds: modelEntry.categoryIds, isSubModel, isModelPrivate: modelEntry.isModelPrivate });
198
+ }
199
+ return result;
200
+ })();
201
+ return this._elementModelsCategories;
202
+ }
203
+ async *queryModeledElements() {
204
+ const query = `
205
+ SELECT
206
+ pe.ECInstanceId modeledElementId,
207
+ pe.Category.Id categoryId,
208
+ pe.Model.Id modelId
209
+ FROM ${this._categoryModelClass} m
210
+ JOIN ${this._categoryElementClass} pe ON pe.ECInstanceId = m.ModeledElement.Id
211
+ WHERE
212
+ m.IsPrivate = false
213
+ AND m.ECInstanceId IN (SELECT Model.Id FROM ${this._categoryElementClass})
214
+ `;
215
+ for await (const row of this._queryExecutor.createQueryReader({ ecsql: query }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded", restartToken: "tree-widget/categories-tree/modeled-elements-query" })) {
216
+ yield { modelId: row.modelId, categoryId: row.categoryId, modeledElementId: row.modeledElementId, rootCategoryId: row.rootCategoryId };
217
+ }
218
+ }
219
+ async getModelWithCategoryModeledElements() {
220
+ this._modelWithCategoryModeledElements ??= (async () => {
221
+ const modelWithCategoryModeledElements = new Map();
222
+ for await (const { modelId, categoryId, modeledElementId } of this.queryModeledElements()) {
223
+ const key = `${modelId}-${categoryId}`;
224
+ const entry = modelWithCategoryModeledElements.get(key);
225
+ if (entry === undefined) {
226
+ modelWithCategoryModeledElements.set(key, new Set([modeledElementId]));
227
+ }
228
+ else {
229
+ entry.add(modeledElementId);
230
+ }
231
+ }
232
+ return modelWithCategoryModeledElements;
233
+ })();
234
+ return this._modelWithCategoryModeledElements;
235
+ }
236
+ async getCategoriesModeledElements(modelId, categoryIds) {
237
+ const modelWithCategoryModeledElements = await this.getModelWithCategoryModeledElements();
238
+ const result = new Array();
239
+ for (const categoryId of categoryIds) {
240
+ const entry = modelWithCategoryModeledElements.get(`${modelId}-${categoryId}`);
241
+ if (entry !== undefined) {
242
+ result.push(...entry);
243
+ }
244
+ }
245
+ return result;
246
+ }
126
247
  async getSubCategoriesInfo() {
127
248
  this._subCategoriesInfo ??= (async () => {
128
249
  const allSubCategories = new Map();
129
250
  const modelsCategoriesInfo = await this.getModelsCategoriesInfo();
130
251
  const categoriesWithMoreThanOneSubCategory = new Array();
131
252
  for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {
132
- categoriesWithMoreThanOneSubCategory.push(...modelCategoriesInfo.childCategories.filter((categoryInfo) => categoryInfo.childCount > 1).map((categoryInfo) => categoryInfo.id));
253
+ categoriesWithMoreThanOneSubCategory.push(...modelCategoriesInfo.childCategories.filter((categoryInfo) => categoryInfo.subCategoryChildCount > 1).map((categoryInfo) => categoryInfo.id));
133
254
  }
134
255
  if (categoriesWithMoreThanOneSubCategory.length === 0) {
135
256
  return allSubCategories;
@@ -156,14 +277,14 @@ export class CategoriesTreeIdsCache {
156
277
  definitionContainersInfo.set(queriedDefinitionContainer.id, {
157
278
  childCategories: modelCategoriesInfo?.childCategories ?? [],
158
279
  modelId: queriedDefinitionContainer.modelId,
159
- childDefinitionContainers: [],
280
+ childDefinitionContainerIds: [],
160
281
  parentDefinitionContainerExists: false,
161
282
  });
162
283
  }
163
284
  for (const [definitionContainerId, definitionContainerInfo] of definitionContainersInfo) {
164
285
  const parentDefinitionContainer = definitionContainersInfo.get(definitionContainerInfo.modelId);
165
286
  if (parentDefinitionContainer !== undefined) {
166
- parentDefinitionContainer.childDefinitionContainers.push(definitionContainerId);
287
+ parentDefinitionContainer.childDefinitionContainerIds.push(definitionContainerId);
167
288
  definitionContainerInfo.parentDefinitionContainerExists = true;
168
289
  }
169
290
  }
@@ -177,12 +298,41 @@ export class CategoriesTreeIdsCache {
177
298
  parentDefinitionContainerIds.forEach((parentDefinitionContainerId) => {
178
299
  const parentDefinitionContainerInfo = definitionContainersInfo.get(parentDefinitionContainerId);
179
300
  if (parentDefinitionContainerInfo !== undefined) {
180
- result.definitionContainers.push(...parentDefinitionContainerInfo.childDefinitionContainers);
301
+ result.definitionContainers.push(...parentDefinitionContainerInfo.childDefinitionContainerIds);
181
302
  result.categories.push(...parentDefinitionContainerInfo.childCategories);
182
303
  }
183
304
  });
184
305
  return result;
185
306
  }
307
+ async getCategoriesElementModels(categoryIds, includeSubModels) {
308
+ const elementModelsCategories = await this.getElementModelsCategories();
309
+ const result = new Map();
310
+ for (const categoryId of categoryIds) {
311
+ for (const [modelId, { categoryIds: categories, isSubModel }] of elementModelsCategories) {
312
+ if ((includeSubModels || !isSubModel) && categories.has(categoryId)) {
313
+ let categoryModels = result.get(categoryId);
314
+ if (!categoryModels) {
315
+ categoryModels = new Array();
316
+ result.set(categoryId, categoryModels);
317
+ }
318
+ categoryModels.push(modelId);
319
+ }
320
+ }
321
+ }
322
+ return result;
323
+ }
324
+ async getModelCategoryIds(modelId) {
325
+ const elementModelsCategories = await this.getElementModelsCategories();
326
+ return [...(elementModelsCategories.get(modelId)?.categoryIds ?? [])];
327
+ }
328
+ async hasSubModel(elementId) {
329
+ const elementModelsCategories = await this.getElementModelsCategories();
330
+ const modeledElementInfo = elementModelsCategories.get(elementId);
331
+ if (!modeledElementInfo) {
332
+ return false;
333
+ }
334
+ return !modeledElementInfo.isModelPrivate;
335
+ }
186
336
  async getAllContainedCategories(definitionContainerIds) {
187
337
  const result = new Array();
188
338
  const definitionContainersInfo = await this.getDefinitionContainersInfo();
@@ -192,7 +342,7 @@ export class CategoriesTreeIdsCache {
192
342
  return [];
193
343
  }
194
344
  result.push(...definitionContainerInfo.childCategories.map((category) => category.id));
195
- return this.getAllContainedCategories(definitionContainerInfo.childDefinitionContainers);
345
+ return this.getAllContainedCategories(definitionContainerInfo.childDefinitionContainerIds);
196
346
  }));
197
347
  for (const categories of indirectCategories) {
198
348
  result.push(...categories);
@@ -206,7 +356,7 @@ export class CategoriesTreeIdsCache {
206
356
  if (subCategoryInfo === undefined) {
207
357
  return [];
208
358
  }
209
- return [...(await this.getInstanceKeyPaths({ categoryId: subCategoryInfo.categoryId })), { id: props.subCategoryId, className: SUB_CATEGORY_CLASS }];
359
+ return [...(await this.getInstanceKeyPaths({ categoryId: subCategoryInfo.categoryId })), { id: props.subCategoryId, className: SUB_CATEGORY_CLASS_NAME }];
210
360
  }
211
361
  if ("categoryId" in props) {
212
362
  const modelsCategoriesInfo = await this.getModelsCategoriesInfo();
@@ -226,13 +376,16 @@ export class CategoriesTreeIdsCache {
226
376
  return [];
227
377
  }
228
378
  if (!definitionContainerInfo.parentDefinitionContainerExists) {
229
- return [{ id: props.definitionContainerId, className: DEFINITION_CONTAINER_CLASS }];
379
+ return [{ id: props.definitionContainerId, className: DEFINITION_CONTAINER_CLASS_NAME }];
230
380
  }
231
381
  return [
232
382
  ...(await this.getInstanceKeyPaths({ definitionContainerId: definitionContainerInfo.modelId })),
233
- { id: props.definitionContainerId, className: DEFINITION_CONTAINER_CLASS },
383
+ { id: props.definitionContainerId, className: DEFINITION_CONTAINER_CLASS_NAME },
234
384
  ];
235
385
  }
386
+ async getCategoryElementsCount(modelId, categoryId) {
387
+ return this._categoryElementCounts.getCategoryElementsCount(modelId, categoryId);
388
+ }
236
389
  async getAllDefinitionContainersAndCategories() {
237
390
  const [modelsCategoriesInfo, definitionContainersInfo] = await Promise.all([this.getModelsCategoriesInfo(), this.getDefinitionContainersInfo()]);
238
391
  const result = { definitionContainers: [...definitionContainersInfo.keys()], categories: new Array() };
@@ -256,12 +409,19 @@ export class CategoriesTreeIdsCache {
256
409
  }
257
410
  return result;
258
411
  }
259
- async getSubCategories(categoryId) {
412
+ async getSubCategories(categoryIds) {
260
413
  const subCategoriesInfo = await this.getSubCategoriesInfo();
261
- const result = new Array();
262
- for (const [subCategoryId, subCategoryInfo] of subCategoriesInfo) {
263
- if (subCategoryInfo.categoryId === categoryId) {
264
- result.push(subCategoryId);
414
+ const result = new Map();
415
+ for (const categoryId of categoryIds) {
416
+ for (const [subCategoryId, subCategoryInfo] of subCategoriesInfo) {
417
+ if (subCategoryInfo.categoryId === categoryId) {
418
+ let categoryEntry = result.get(categoryId);
419
+ if (!categoryEntry) {
420
+ categoryEntry = [];
421
+ result.set(categoryId, categoryEntry);
422
+ }
423
+ categoryEntry.push(subCategoryId);
424
+ }
265
425
  }
266
426
  }
267
427
  return result;
@@ -271,10 +431,4 @@ export class CategoriesTreeIdsCache {
271
431
  return this._isDefinitionContainerSupported;
272
432
  }
273
433
  }
274
- /** @internal */
275
- export function getClassesByView(viewType) {
276
- return viewType === "2d"
277
- ? { categoryClass: "BisCore.DrawingCategory", categoryElementClass: "BisCore.GeometricElement2d" }
278
- : { categoryClass: "BisCore.SpatialCategory", categoryElementClass: "BisCore.GeometricElement3d" };
279
- }
280
434
  //# sourceMappingURL=CategoriesTreeIdsCache.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CategoriesTreeIdsCache.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AA2B3F,gBAAgB;AAChB,MAAM,OAAO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UAAsB;QAClD,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC5D,MAAM,MAAM,GAAG,IAAI,KAAK,EAAc,CAAC;QACvC,KAAK,MAAM,CAAC,aAAa,EAAE,eAAe,CAAC,IAAI,iBAAiB,EAAE;YAChE,IAAI,eAAe,CAAC,UAAU,KAAK,UAAU,EAAE;gBAC7C,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;aAC5B;SACF;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAEM,KAAK,CAAC,iCAAiC;QAC5C,IAAI,CAAC,+BAA+B,KAAK,IAAI,CAAC,oCAAoC,EAAE,CAAC;QACrF,OAAO,IAAI,CAAC,+BAA+B,CAAC;IAC9C,CAAC;CACF;AAED,gBAAgB;AAChB,MAAM,UAAU,gBAAgB,CAAC,QAAqB;IACpD,OAAO,QAAQ,KAAK,IAAI;QACtB,CAAC,CAAC,EAAE,aAAa,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,4BAA4B,EAAE;QAClG,CAAC,CAAC,EAAE,aAAa,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,4BAA4B,EAAE,CAAC;AACvG,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 { DEFINITION_CONTAINER_CLASS, SUB_CATEGORY_CLASS } from \"./ClassNameDefinitions.js\";\n\nimport type { Id64Array, Id64String } from \"@itwin/core-bentley\";\nimport type { LimitingECSqlQueryExecutor } from \"@itwin/presentation-hierarchies\";\nimport type { InstanceKey } from \"@itwin/presentation-shared\";\n\ninterface DefinitionContainerInfo {\n modelId: Id64String;\n parentDefinitionContainerExists: boolean;\n childCategories: CategoryInfo[];\n childDefinitionContainers: Id64Array;\n}\n\ninterface CategoriesInfo {\n childCategories: CategoryInfo[];\n parentDefinitionContainerExists: boolean;\n}\n\ninterface CategoryInfo {\n id: Id64String;\n childCount: number;\n}\n\ninterface SubCategoryInfo {\n categoryId: Id64String;\n}\n\n/** @internal */\nexport class CategoriesTreeIdsCache {\n private _definitionContainersInfo: Promise<Map<Id64String, DefinitionContainerInfo>> | undefined;\n private _modelsCategoriesInfo: Promise<Map<Id64String, CategoriesInfo>> | undefined;\n private _subCategoriesInfo: Promise<Map<Id64String, SubCategoryInfo>> | undefined;\n private _categoryClass: string;\n private _categoryElementClass: string;\n private _isDefinitionContainerSupported: Promise<boolean> | undefined;\n\n constructor(\n private _queryExecutor: LimitingECSqlQueryExecutor,\n viewType: \"3d\" | \"2d\",\n ) {\n const { categoryClass, categoryElementClass } = getClassesByView(viewType);\n this._categoryClass = categoryClass;\n this._categoryElementClass = categoryElementClass;\n }\n\n private async *queryCategories(): AsyncIterableIterator<{\n id: Id64String;\n modelId: Id64String;\n parentDefinitionContainerExists: boolean;\n childCount: number;\n }> {\n const isDefinitionContainerSupported = await this.getIsDefinitionContainerSupported();\n const categoriesQuery = `\n SELECT\n this.ECInstanceId id,\n COUNT(sc.ECInstanceId) childCount,\n this.Model.Id modelId,\n ${\n isDefinitionContainerSupported\n ? `\n IIF(this.Model.Id IN (SELECT dc.ECInstanceId FROM ${DEFINITION_CONTAINER_CLASS} dc),\n true,\n false\n )`\n : \"false\"\n } parentDefinitionContainerExists\n FROM\n ${this._categoryClass} this\n JOIN ${SUB_CATEGORY_CLASS} sc ON sc.Parent.Id = this.ECInstanceId\n JOIN BisCore.Model m ON m.ECInstanceId = this.Model.Id\n WHERE\n NOT this.IsPrivate\n AND (NOT m.IsPrivate OR m.ECClassId IS (BisCore.DictionaryModel))\n AND EXISTS (SELECT 1 FROM ${this._categoryElementClass} e WHERE e.Category.Id = this.ECInstanceId)\n GROUP BY this.ECInstanceId\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: categoriesQuery }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { id: row.id, modelId: row.modelId, parentDefinitionContainerExists: row.parentDefinitionContainerExists, childCount: row.childCount };\n }\n }\n\n private async queryIsDefinitionContainersSupported(): Promise<boolean> {\n const query = `\n SELECT\n 1\n FROM\n ECDbMeta.ECSchemaDef s\n JOIN ECDbMeta.ECClassDef c ON c.Schema.Id = s.ECInstanceId\n WHERE\n s.Name = 'BisCore'\n AND c.Name = 'DefinitionContainer'\n `;\n\n for await (const _row of this._queryExecutor.createQueryReader({ ecsql: query })) {\n return true;\n }\n return false;\n }\n\n private async *queryDefinitionContainers(): AsyncIterableIterator<{ id: Id64String; modelId: Id64String }> {\n // DefinitionModel ECInstanceId will always be the same as modeled DefinitionContainer ECInstanceId, if this wasn't the case, we would need to do something like:\n // JOIN BisCore.DefinitionModel dm ON dm.ECInstanceId = ${modelIdAccessor}\n // JOIN BisCore.DefinitionModelBreaksDownDefinitionContainer dr ON dr.SourceECInstanceId = dm.ECInstanceId\n // JOIN BisCore.DefinitionContainer dc ON dc.ECInstanceId = dr.TargetECInstanceId\n const DEFINITION_CONTAINERS_CTE = \"DefinitionContainers\";\n const ctes = [\n `\n ${DEFINITION_CONTAINERS_CTE}(ECInstanceId, ModelId) AS (\n SELECT\n dc.ECInstanceId,\n dc.Model.Id\n FROM\n ${DEFINITION_CONTAINER_CLASS} dc\n WHERE\n dc.ECInstanceId IN (SELECT c.Model.Id FROM ${this._categoryClass} c WHERE NOT c.IsPrivate)\n AND NOT dc.IsPrivate\n\n UNION ALL\n\n SELECT\n pdc.ECInstanceId,\n pdc.Model.Id\n FROM\n ${DEFINITION_CONTAINERS_CTE} cdc\n JOIN ${DEFINITION_CONTAINER_CLASS} pdc ON pdc.ECInstanceId = cdc.ModelId\n WHERE\n NOT pdc.IsPrivate\n )\n `,\n ];\n const definitionsQuery = `\n SELECT dc.ECInstanceId id, dc.ModelId modelId FROM ${DEFINITION_CONTAINERS_CTE} dc GROUP BY dc.ECInstanceId\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ctes, ecsql: definitionsQuery }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { id: row.id, modelId: row.modelId };\n }\n }\n\n private async *queryVisibleSubCategories(categoriesInfo: Id64Array): AsyncIterableIterator<{ id: Id64String; parentId: Id64String }> {\n const definitionsQuery = `\n SELECT\n sc.ECInstanceId id,\n sc.Parent.Id categoryId\n FROM\n ${SUB_CATEGORY_CLASS} sc\n WHERE\n NOT sc.IsPrivate\n AND sc.Parent.Id IN (${categoriesInfo.join(\",\")})\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: definitionsQuery }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { id: row.id, parentId: row.categoryId };\n }\n }\n\n private async getModelsCategoriesInfo() {\n this._modelsCategoriesInfo ??= (async () => {\n const allModelsCategories = new Map<Id64String, CategoriesInfo>();\n for await (const queriedCategory of this.queryCategories()) {\n let modelCategories = allModelsCategories.get(queriedCategory.modelId);\n if (modelCategories === undefined) {\n modelCategories = { parentDefinitionContainerExists: queriedCategory.parentDefinitionContainerExists, childCategories: [] };\n allModelsCategories.set(queriedCategory.modelId, modelCategories);\n }\n modelCategories.childCategories.push({ id: queriedCategory.id, childCount: queriedCategory.childCount });\n }\n return allModelsCategories;\n })();\n return this._modelsCategoriesInfo;\n }\n\n private async getSubCategoriesInfo() {\n this._subCategoriesInfo ??= (async () => {\n const allSubCategories = new Map<Id64String, SubCategoryInfo>();\n const modelsCategoriesInfo = await this.getModelsCategoriesInfo();\n const categoriesWithMoreThanOneSubCategory = new Array<Id64String>();\n for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {\n categoriesWithMoreThanOneSubCategory.push(\n ...modelCategoriesInfo.childCategories.filter((categoryInfo) => categoryInfo.childCount > 1).map((categoryInfo) => categoryInfo.id),\n );\n }\n\n if (categoriesWithMoreThanOneSubCategory.length === 0) {\n return allSubCategories;\n }\n\n for await (const queriedSubCategory of this.queryVisibleSubCategories(categoriesWithMoreThanOneSubCategory)) {\n allSubCategories.set(queriedSubCategory.id, { categoryId: queriedSubCategory.parentId });\n }\n return allSubCategories;\n })();\n return this._subCategoriesInfo;\n }\n\n private async getDefinitionContainersInfo() {\n this._definitionContainersInfo ??= (async () => {\n const definitionContainersInfo = new Map<Id64String, DefinitionContainerInfo>();\n const [isDefinitionContainerSupported, modelsCategoriesInfo] = await Promise.all([\n this.getIsDefinitionContainerSupported(),\n this.getModelsCategoriesInfo(),\n ]);\n if (!isDefinitionContainerSupported || modelsCategoriesInfo.size === 0) {\n return definitionContainersInfo;\n }\n\n for await (const queriedDefinitionContainer of this.queryDefinitionContainers()) {\n const modelCategoriesInfo = modelsCategoriesInfo.get(queriedDefinitionContainer.id);\n\n definitionContainersInfo.set(queriedDefinitionContainer.id, {\n childCategories: modelCategoriesInfo?.childCategories ?? [],\n modelId: queriedDefinitionContainer.modelId,\n childDefinitionContainers: [],\n parentDefinitionContainerExists: false,\n });\n }\n\n for (const [definitionContainerId, definitionContainerInfo] of definitionContainersInfo) {\n const parentDefinitionContainer = definitionContainersInfo.get(definitionContainerInfo.modelId);\n if (parentDefinitionContainer !== undefined) {\n parentDefinitionContainer.childDefinitionContainers.push(definitionContainerId);\n definitionContainerInfo.parentDefinitionContainerExists = true;\n }\n }\n\n return definitionContainersInfo;\n })();\n return this._definitionContainersInfo;\n }\n\n public async getDirectChildDefinitionContainersAndCategories(\n parentDefinitionContainerIds: Id64Array,\n ): Promise<{ categories: CategoryInfo[]; definitionContainers: Id64Array }> {\n const definitionContainersInfo = await this.getDefinitionContainersInfo();\n\n const result = { definitionContainers: new Array<Id64String>(), categories: new Array<CategoryInfo>() };\n\n parentDefinitionContainerIds.forEach((parentDefinitionContainerId) => {\n const parentDefinitionContainerInfo = definitionContainersInfo.get(parentDefinitionContainerId);\n if (parentDefinitionContainerInfo !== undefined) {\n result.definitionContainers.push(...parentDefinitionContainerInfo.childDefinitionContainers);\n result.categories.push(...parentDefinitionContainerInfo.childCategories);\n }\n });\n return result;\n }\n\n public async getAllContainedCategories(definitionContainerIds: Id64Array): Promise<Id64Array> {\n const result = new Array<Id64String>();\n\n const definitionContainersInfo = await this.getDefinitionContainersInfo();\n const indirectCategories = await Promise.all(\n definitionContainerIds.map(async (definitionContainerId) => {\n const definitionContainerInfo = definitionContainersInfo.get(definitionContainerId);\n if (definitionContainerInfo === undefined) {\n return [];\n }\n result.push(...definitionContainerInfo.childCategories.map((category) => category.id));\n return this.getAllContainedCategories(definitionContainerInfo.childDefinitionContainers);\n }),\n );\n for (const categories of indirectCategories) {\n result.push(...categories);\n }\n\n return result;\n }\n\n public async getInstanceKeyPaths(\n props: { categoryId: Id64String } | { definitionContainerId: Id64String } | { subCategoryId: Id64String },\n ): Promise<InstanceKey[]> {\n if (\"subCategoryId\" in props) {\n const subCategoriesInfo = await this.getSubCategoriesInfo();\n const subCategoryInfo = subCategoriesInfo.get(props.subCategoryId);\n if (subCategoryInfo === undefined) {\n return [];\n }\n return [...(await this.getInstanceKeyPaths({ categoryId: subCategoryInfo.categoryId })), { id: props.subCategoryId, className: SUB_CATEGORY_CLASS }];\n }\n\n if (\"categoryId\" in props) {\n const modelsCategoriesInfo = await this.getModelsCategoriesInfo();\n for (const [modelId, modelCategoriesInfo] of modelsCategoriesInfo) {\n if (modelCategoriesInfo.childCategories.find((childCategory) => childCategory.id === props.categoryId)) {\n if (!modelCategoriesInfo.parentDefinitionContainerExists) {\n return [{ id: props.categoryId, className: this._categoryClass }];\n }\n\n return [...(await this.getInstanceKeyPaths({ definitionContainerId: modelId })), { id: props.categoryId, className: this._categoryClass }];\n }\n }\n return [];\n }\n\n const definitionContainersInfo = await this.getDefinitionContainersInfo();\n const definitionContainerInfo = definitionContainersInfo.get(props.definitionContainerId);\n if (definitionContainerInfo === undefined) {\n return [];\n }\n\n if (!definitionContainerInfo.parentDefinitionContainerExists) {\n return [{ id: props.definitionContainerId, className: DEFINITION_CONTAINER_CLASS }];\n }\n\n return [\n ...(await this.getInstanceKeyPaths({ definitionContainerId: definitionContainerInfo.modelId })),\n { id: props.definitionContainerId, className: DEFINITION_CONTAINER_CLASS },\n ];\n }\n\n public async getAllDefinitionContainersAndCategories(): Promise<{ categories: Id64Array; definitionContainers: Id64Array }> {\n const [modelsCategoriesInfo, definitionContainersInfo] = await Promise.all([this.getModelsCategoriesInfo(), this.getDefinitionContainersInfo()]);\n const result = { definitionContainers: [...definitionContainersInfo.keys()], categories: new Array<Id64String>() };\n for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {\n result.categories.push(...modelCategoriesInfo.childCategories.map((childCategory) => childCategory.id));\n }\n\n return result;\n }\n\n public async getRootDefinitionContainersAndCategories(): Promise<{ categories: CategoryInfo[]; definitionContainers: Id64Array }> {\n const [modelsCategoriesInfo, definitionContainersInfo] = await Promise.all([this.getModelsCategoriesInfo(), this.getDefinitionContainersInfo()]);\n const result = { definitionContainers: new Array<Id64String>(), categories: new Array<CategoryInfo>() };\n for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {\n if (!modelCategoriesInfo.parentDefinitionContainerExists) {\n result.categories.push(...modelCategoriesInfo.childCategories);\n }\n }\n\n for (const [definitionContainerId, definitionContainerInfo] of definitionContainersInfo) {\n if (!definitionContainerInfo.parentDefinitionContainerExists) {\n result.definitionContainers.push(definitionContainerId);\n }\n }\n return result;\n }\n\n public async getSubCategories(categoryId: Id64String): Promise<Id64Array> {\n const subCategoriesInfo = await this.getSubCategoriesInfo();\n const result = new Array<Id64String>();\n for (const [subCategoryId, subCategoryInfo] of subCategoriesInfo) {\n if (subCategoryInfo.categoryId === categoryId) {\n result.push(subCategoryId);\n }\n }\n return result;\n }\n\n public async getIsDefinitionContainerSupported(): Promise<boolean> {\n this._isDefinitionContainerSupported ??= this.queryIsDefinitionContainersSupported();\n return this._isDefinitionContainerSupported;\n }\n}\n\n/** @internal */\nexport function getClassesByView(viewType: \"2d\" | \"3d\") {\n return viewType === \"2d\"\n ? { categoryClass: \"BisCore.DrawingCategory\", categoryElementClass: \"BisCore.GeometricElement2d\" }\n : { categoryClass: \"BisCore.SpatialCategory\", categoryElementClass: \"BisCore.GeometricElement3d\" };\n}\n"]}
1
+ {"version":3,"file":"CategoriesTreeIdsCache.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,+BAA+B,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,+CAA+C,CAAC;AAC3I,OAAO,EAAE,+BAA+B,EAAE,MAAM,0DAA0D,CAAC;AAC3G,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AA+BxF,gBAAgB;AAChB,MAAM,OAAO,sBAAsB;IAajC,YACU,cAA0C,EAClD,QAAqB;QADb,mBAAc,GAAd,cAAc,CAA4B;QAGlD,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QAC/E,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;QACpC,IAAI,CAAC,qBAAqB,GAAG,YAAY,CAAC;QAC1C,IAAI,CAAC,mBAAmB,GAAG,UAAU,CAAC;QACtC,IAAI,CAAC,sBAAsB,GAAG,IAAI,+BAA+B,CAAC,cAAc,EAAE,YAAY,CAAC,CAAC;IAClG,CAAC;IAEM,CAAC,MAAM,CAAC,OAAO,CAAC;QACrB,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;IAChD,CAAC;IAEO,KAAK,CAAC,CAAC,2BAA2B,CAAC,kBAA6B;QAItE,MAAM,KAAK,GAAG;;aAEL,IAAI,CAAC,qBAAqB;+BACR,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC;KACvD,CAAC;QACF,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC,EAAE,KAAK,EAAE,KAAK,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C;iBACnC;aACF;SACF;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAEM,KAAK,CAAC,iCAAiC;QAC5C,IAAI,CAAC,+BAA+B,KAAK,IAAI,CAAC,oCAAoC,EAAE,CAAC;QACrF,OAAO,IAAI,CAAC,+BAA+B,CAAC;IAC9C,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 { DEFINITION_CONTAINER_CLASS_NAME, MODEL_CLASS_NAME, SUB_CATEGORY_CLASS_NAME } from \"../../common/internal/ClassNameDefinitions.js\";\nimport { ModelCategoryElementsCountCache } from \"../../common/internal/ModelCategoryElementsCountCache.js\";\nimport { getClassesByView, getDistinctMapValues } from \"../../common/internal/Utils.js\";\n\nimport type { CategoryId, DefinitionContainerId, ElementId, ModelId, SubCategoryId } from \"../../common/internal/Types.js\";\nimport type { Id64Array, Id64Set, Id64String } from \"@itwin/core-bentley\";\nimport type { LimitingECSqlQueryExecutor } from \"@itwin/presentation-hierarchies\";\nimport type { InstanceKey } from \"@itwin/presentation-shared\";\n\ninterface DefinitionContainerInfo {\n modelId: Id64String;\n parentDefinitionContainerExists: boolean;\n childCategories: CategoryInfo[];\n childDefinitionContainerIds: Id64Array;\n}\n\ninterface CategoriesInfo {\n childCategories: CategoryInfo[];\n parentDefinitionContainerExists: boolean;\n}\n\n/** @internal */\nexport interface CategoryInfo {\n id: CategoryId;\n subCategoryChildCount: number;\n}\n\ninterface SubCategoryInfo {\n categoryId: Id64String;\n}\n\ntype ModelCategoryKey = `${ModelId}-${CategoryId}`;\n\n/** @internal */\nexport class CategoriesTreeIdsCache implements Disposable {\n private _definitionContainersInfo: Promise<Map<DefinitionContainerId, DefinitionContainerInfo>> | undefined;\n private _modelsCategoriesInfo: Promise<Map<ModelId, CategoriesInfo>> | undefined;\n private _elementModelsCategories: Promise<Map<ModelId, { categoryIds: Id64Set; isSubModel: boolean; isModelPrivate: boolean }>> | undefined;\n private _subCategoriesInfo: Promise<Map<SubCategoryId, SubCategoryInfo>> | undefined;\n private readonly _categoryElementCounts: ModelCategoryElementsCountCache;\n private _modelWithCategoryModeledElements: Promise<Map<ModelCategoryKey, Set<ElementId>>> | undefined;\n private _categoryClass: string;\n private _categoryElementClass: string;\n private _categoryModelClass: string;\n private _isDefinitionContainerSupported: Promise<boolean> | undefined;\n private _filteredElementsModels: Promise<Map<ElementId, ModelId>> | undefined;\n\n constructor(\n private _queryExecutor: LimitingECSqlQueryExecutor,\n viewType: \"3d\" | \"2d\",\n ) {\n const { categoryClass, elementClass, modelClass } = getClassesByView(viewType);\n this._categoryClass = categoryClass;\n this._categoryElementClass = elementClass;\n this._categoryModelClass = modelClass;\n this._categoryElementCounts = new ModelCategoryElementsCountCache(_queryExecutor, elementClass);\n }\n\n public [Symbol.dispose]() {\n this._categoryElementCounts[Symbol.dispose]();\n }\n\n private async *queryFilteredElementsModels(filteredElementIds: Id64Array): AsyncIterableIterator<{\n modelId: Id64String;\n id: ElementId;\n }> {\n const query = `\n SELECT Model.Id modelId, ECInstanceId id\n FROM ${this._categoryElementClass}\n WHERE ECInstanceId IN (${filteredElementIds.join(\", \")})\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: query }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { modelId: row.modelId, id: row.id };\n }\n }\n\n public async getFilteredElementsModels(filteredElementIds: Id64Array) {\n if (filteredElementIds.length === 0) {\n return new Map<ElementId, ModelId>();\n }\n\n this._filteredElementsModels ??= (async () => {\n const filteredElementsModels = new Map();\n for await (const { modelId, id } of this.queryFilteredElementsModels(filteredElementIds)) {\n filteredElementsModels.set(id, modelId);\n }\n return filteredElementsModels;\n })();\n return this._filteredElementsModels;\n }\n\n public clearFilteredElementsModels() {\n this._filteredElementsModels = undefined;\n }\n\n private async *queryElementModelCategories(): AsyncIterableIterator<{\n modelId: Id64String;\n categoryId: Id64String;\n isModelPrivate: boolean;\n }> {\n const query = `\n SELECT this.Model.Id modelId, this.Category.Id categoryId, m.IsPrivate isModelPrivate\n FROM ${this._categoryModelClass} m\n JOIN ${this._categoryElementClass} this ON m.ECInstanceId = this.Model.Id\n WHERE this.Parent.Id IS NULL\n GROUP BY modelId, categoryId, isModelPrivate\n `;\n for await (const row of this._queryExecutor.createQueryReader(\n { ecsql: query },\n { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\", restartToken: \"tree-widget/categories-tree/element-models-and-categories-query\" },\n )) {\n yield { modelId: row.modelId, categoryId: row.categoryId, isModelPrivate: !!row.isModelPrivate };\n }\n }\n\n private async *queryCategories(): AsyncIterableIterator<{\n id: CategoryId;\n modelId: Id64String;\n parentDefinitionContainerExists: boolean;\n subCategoryChildCount: number;\n }> {\n const isDefinitionContainerSupported = await this.getIsDefinitionContainerSupported();\n const categoriesQuery = `\n SELECT\n this.ECInstanceId id,\n COUNT(sc.ECInstanceId) subCategoryChildCount,\n this.Model.Id modelId,\n ${\n isDefinitionContainerSupported\n ? `\n IIF(this.Model.Id IN (SELECT dc.ECInstanceId FROM ${DEFINITION_CONTAINER_CLASS_NAME} dc),\n true,\n false\n )`\n : \"false\"\n } parentDefinitionContainerExists\n FROM\n ${this._categoryClass} this\n JOIN ${SUB_CATEGORY_CLASS_NAME} sc ON sc.Parent.Id = this.ECInstanceId\n JOIN ${MODEL_CLASS_NAME} m ON m.ECInstanceId = this.Model.Id\n WHERE\n NOT this.IsPrivate\n AND (NOT m.IsPrivate OR m.ECClassId IS (BisCore.DictionaryModel))\n AND EXISTS (SELECT 1 FROM ${this._categoryElementClass} e WHERE e.Category.Id = this.ECInstanceId)\n GROUP BY this.ECInstanceId\n `;\n for await (const row of this._queryExecutor.createQueryReader(\n { ecsql: categoriesQuery },\n { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\", restartToken: \"tree-widget/categories-tree/categories-query\" },\n )) {\n yield {\n id: row.id,\n modelId: row.modelId,\n parentDefinitionContainerExists: row.parentDefinitionContainerExists,\n subCategoryChildCount: row.subCategoryChildCount,\n };\n }\n }\n\n private async queryIsDefinitionContainersSupported(): Promise<boolean> {\n const query = `\n SELECT\n 1\n FROM\n ECDbMeta.ECSchemaDef s\n JOIN ECDbMeta.ECClassDef c ON c.Schema.Id = s.ECInstanceId\n WHERE\n s.Name = 'BisCore'\n AND c.Name = 'DefinitionContainer'\n `;\n\n for await (const _row of this._queryExecutor.createQueryReader(\n { ecsql: query },\n { restartToken: \"tree-widget/categories-tree/is-definition-container-supported-query\" },\n )) {\n return true;\n }\n return false;\n }\n\n private async *queryDefinitionContainers(): AsyncIterableIterator<{ id: DefinitionContainerId; modelId: Id64String }> {\n // DefinitionModel ECInstanceId will always be the same as modeled DefinitionContainer ECInstanceId, if this wasn't the case, we would need to do something like:\n // JOIN BisCore.DefinitionModel dm ON dm.ECInstanceId = ${modelIdAccessor}\n // JOIN BisCore.DefinitionModelBreaksDownDefinitionContainer dr ON dr.SourceECInstanceId = dm.ECInstanceId\n // JOIN BisCore.DefinitionContainer dc ON dc.ECInstanceId = dr.TargetECInstanceId\n const DEFINITION_CONTAINERS_CTE = \"DefinitionContainers\";\n const ctes = [\n `\n ${DEFINITION_CONTAINERS_CTE}(ECInstanceId, ModelId) AS (\n SELECT\n dc.ECInstanceId,\n dc.Model.Id\n FROM\n ${DEFINITION_CONTAINER_CLASS_NAME} dc\n WHERE\n dc.ECInstanceId IN (SELECT c.Model.Id FROM ${this._categoryClass} c WHERE NOT c.IsPrivate AND EXISTS (SELECT 1 FROM ${this._categoryElementClass} e WHERE e.Category.Id = c.ECInstanceId))\n AND NOT dc.IsPrivate\n\n UNION ALL\n\n SELECT\n pdc.ECInstanceId,\n pdc.Model.Id\n FROM\n ${DEFINITION_CONTAINERS_CTE} cdc\n JOIN ${DEFINITION_CONTAINER_CLASS_NAME} pdc ON pdc.ECInstanceId = cdc.ModelId\n WHERE\n NOT pdc.IsPrivate\n )\n `,\n ];\n const definitionsQuery = `\n SELECT dc.ECInstanceId id, dc.ModelId modelId FROM ${DEFINITION_CONTAINERS_CTE} dc GROUP BY dc.ECInstanceId\n `;\n for await (const row of this._queryExecutor.createQueryReader(\n { ctes, ecsql: definitionsQuery },\n { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\", restartToken: \"tree-widget/categories-tree/definition-containers-query\" },\n )) {\n yield { id: row.id, modelId: row.modelId };\n }\n }\n\n private async *queryVisibleSubCategories(categoryIds: Id64Array): AsyncIterableIterator<{ id: SubCategoryId; parentId: CategoryId }> {\n const definitionsQuery = `\n SELECT\n sc.ECInstanceId id,\n sc.Parent.Id categoryId\n FROM\n ${SUB_CATEGORY_CLASS_NAME} sc\n WHERE\n NOT sc.IsPrivate\n AND sc.Parent.Id IN (${categoryIds.join(\",\")})\n `;\n for await (const row of this._queryExecutor.createQueryReader(\n { ecsql: definitionsQuery },\n { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\", restartToken: \"tree-widget/categories-tree/sub-categories-query\" },\n )) {\n yield { id: row.id, parentId: row.categoryId };\n }\n }\n\n private async getModelsCategoriesInfo() {\n this._modelsCategoriesInfo ??= (async () => {\n const allModelsCategories = new Map<ModelId, CategoriesInfo>();\n for await (const queriedCategory of this.queryCategories()) {\n let modelCategories = allModelsCategories.get(queriedCategory.modelId);\n if (modelCategories === undefined) {\n modelCategories = { parentDefinitionContainerExists: queriedCategory.parentDefinitionContainerExists, childCategories: [] };\n allModelsCategories.set(queriedCategory.modelId, modelCategories);\n }\n modelCategories.childCategories.push({ id: queriedCategory.id, subCategoryChildCount: queriedCategory.subCategoryChildCount });\n }\n return allModelsCategories;\n })();\n return this._modelsCategoriesInfo;\n }\n\n private async getElementModelsCategories() {\n this._elementModelsCategories ??= (async () => {\n const [modelCategories, modelWithCategoryModeledElements] = await Promise.all([\n (async () => {\n const elementModelsCategories = new Map<ModelId, { categoryIds: Id64Set; isModelPrivate: boolean }>();\n for await (const queriedCategory of this.queryElementModelCategories()) {\n let modelEntry = elementModelsCategories.get(queriedCategory.modelId);\n if (modelEntry === undefined) {\n modelEntry = { categoryIds: new Set(), isModelPrivate: queriedCategory.isModelPrivate };\n elementModelsCategories.set(queriedCategory.modelId, modelEntry);\n }\n modelEntry.categoryIds.add(queriedCategory.categoryId);\n }\n return elementModelsCategories;\n })(),\n this.getModelWithCategoryModeledElements(),\n ]);\n const result = new Map<ModelId, { categoryIds: Set<CategoryId>; isSubModel: boolean; isModelPrivate: boolean }>();\n const subModels = getDistinctMapValues(modelWithCategoryModeledElements);\n for (const [modelId, modelEntry] of modelCategories) {\n const isSubModel = subModels.has(modelId);\n result.set(modelId, { categoryIds: modelEntry.categoryIds, isSubModel, isModelPrivate: modelEntry.isModelPrivate });\n }\n return result;\n })();\n return this._elementModelsCategories;\n }\n\n private async *queryModeledElements(): AsyncIterableIterator<{\n modelId: Id64String;\n modeledElementId: Id64String;\n categoryId: Id64String;\n rootCategoryId: Id64String;\n }> {\n const query = `\n SELECT\n pe.ECInstanceId modeledElementId,\n pe.Category.Id categoryId,\n pe.Model.Id modelId\n FROM ${this._categoryModelClass} m\n JOIN ${this._categoryElementClass} pe ON pe.ECInstanceId = m.ModeledElement.Id\n WHERE\n m.IsPrivate = false\n AND m.ECInstanceId IN (SELECT Model.Id FROM ${this._categoryElementClass})\n `;\n for await (const row of this._queryExecutor.createQueryReader(\n { ecsql: query },\n { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\", restartToken: \"tree-widget/categories-tree/modeled-elements-query\" },\n )) {\n yield { modelId: row.modelId, categoryId: row.categoryId, modeledElementId: row.modeledElementId, rootCategoryId: row.rootCategoryId };\n }\n }\n\n private async getModelWithCategoryModeledElements() {\n this._modelWithCategoryModeledElements ??= (async () => {\n const modelWithCategoryModeledElements = new Map<ModelCategoryKey, Set<ElementId>>();\n for await (const { modelId, categoryId, modeledElementId } of this.queryModeledElements()) {\n const key: ModelCategoryKey = `${modelId}-${categoryId}`;\n const entry = modelWithCategoryModeledElements.get(key);\n if (entry === undefined) {\n modelWithCategoryModeledElements.set(key, new Set([modeledElementId]));\n } else {\n entry.add(modeledElementId);\n }\n }\n return modelWithCategoryModeledElements;\n })();\n return this._modelWithCategoryModeledElements;\n }\n\n public async getCategoriesModeledElements(modelId: Id64String, categoryIds: Id64Array): Promise<Id64Array> {\n const modelWithCategoryModeledElements = await this.getModelWithCategoryModeledElements();\n const result = new Array<ElementId>();\n for (const categoryId of categoryIds) {\n const entry = modelWithCategoryModeledElements.get(`${modelId}-${categoryId}`);\n if (entry !== undefined) {\n result.push(...entry);\n }\n }\n return result;\n }\n\n private async getSubCategoriesInfo() {\n this._subCategoriesInfo ??= (async () => {\n const allSubCategories = new Map<SubCategoryId, SubCategoryInfo>();\n const modelsCategoriesInfo = await this.getModelsCategoriesInfo();\n const categoriesWithMoreThanOneSubCategory = new Array<CategoryId>();\n for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {\n categoriesWithMoreThanOneSubCategory.push(\n ...modelCategoriesInfo.childCategories.filter((categoryInfo) => categoryInfo.subCategoryChildCount > 1).map((categoryInfo) => categoryInfo.id),\n );\n }\n\n if (categoriesWithMoreThanOneSubCategory.length === 0) {\n return allSubCategories;\n }\n\n for await (const queriedSubCategory of this.queryVisibleSubCategories(categoriesWithMoreThanOneSubCategory)) {\n allSubCategories.set(queriedSubCategory.id, { categoryId: queriedSubCategory.parentId });\n }\n return allSubCategories;\n })();\n return this._subCategoriesInfo;\n }\n\n private async getDefinitionContainersInfo() {\n this._definitionContainersInfo ??= (async () => {\n const definitionContainersInfo = new Map<DefinitionContainerId, DefinitionContainerInfo>();\n const [isDefinitionContainerSupported, modelsCategoriesInfo] = await Promise.all([\n this.getIsDefinitionContainerSupported(),\n this.getModelsCategoriesInfo(),\n ]);\n if (!isDefinitionContainerSupported || modelsCategoriesInfo.size === 0) {\n return definitionContainersInfo;\n }\n\n for await (const queriedDefinitionContainer of this.queryDefinitionContainers()) {\n const modelCategoriesInfo = modelsCategoriesInfo.get(queriedDefinitionContainer.id);\n\n definitionContainersInfo.set(queriedDefinitionContainer.id, {\n childCategories: modelCategoriesInfo?.childCategories ?? [],\n modelId: queriedDefinitionContainer.modelId,\n childDefinitionContainerIds: [],\n parentDefinitionContainerExists: false,\n });\n }\n\n for (const [definitionContainerId, definitionContainerInfo] of definitionContainersInfo) {\n const parentDefinitionContainer = definitionContainersInfo.get(definitionContainerInfo.modelId);\n if (parentDefinitionContainer !== undefined) {\n parentDefinitionContainer.childDefinitionContainerIds.push(definitionContainerId);\n definitionContainerInfo.parentDefinitionContainerExists = true;\n }\n }\n\n return definitionContainersInfo;\n })();\n return this._definitionContainersInfo;\n }\n\n public async getDirectChildDefinitionContainersAndCategories(\n parentDefinitionContainerIds: Id64Array,\n ): Promise<{ categories: CategoryInfo[]; definitionContainers: Array<DefinitionContainerId> }> {\n const definitionContainersInfo = await this.getDefinitionContainersInfo();\n\n const result = { definitionContainers: new Array<DefinitionContainerId>(), categories: new Array<CategoryInfo>() };\n\n parentDefinitionContainerIds.forEach((parentDefinitionContainerId) => {\n const parentDefinitionContainerInfo = definitionContainersInfo.get(parentDefinitionContainerId);\n if (parentDefinitionContainerInfo !== undefined) {\n result.definitionContainers.push(...parentDefinitionContainerInfo.childDefinitionContainerIds);\n result.categories.push(...parentDefinitionContainerInfo.childCategories);\n }\n });\n return result;\n }\n\n public async getCategoriesElementModels(categoryIds: Id64Array, includeSubModels?: boolean): Promise<Map<CategoryId, Array<ModelId>>> {\n const elementModelsCategories = await this.getElementModelsCategories();\n const result = new Map<CategoryId, Array<ModelId>>();\n for (const categoryId of categoryIds) {\n for (const [modelId, { categoryIds: categories, isSubModel }] of elementModelsCategories) {\n if ((includeSubModels || !isSubModel) && categories.has(categoryId)) {\n let categoryModels = result.get(categoryId);\n if (!categoryModels) {\n categoryModels = new Array<ModelId>();\n result.set(categoryId, categoryModels);\n }\n categoryModels.push(modelId);\n }\n }\n }\n return result;\n }\n\n public async getModelCategoryIds(modelId: Id64String): Promise<Id64Array> {\n const elementModelsCategories = await this.getElementModelsCategories();\n return [...(elementModelsCategories.get(modelId)?.categoryIds ?? [])];\n }\n\n public async hasSubModel(elementId: Id64String): Promise<boolean> {\n const elementModelsCategories = await this.getElementModelsCategories();\n const modeledElementInfo = elementModelsCategories.get(elementId);\n if (!modeledElementInfo) {\n return false;\n }\n return !modeledElementInfo.isModelPrivate;\n }\n\n public async getAllContainedCategories(definitionContainerIds: Id64Array): Promise<Id64Array> {\n const result = new Array<CategoryId>();\n\n const definitionContainersInfo = await this.getDefinitionContainersInfo();\n const indirectCategories = await Promise.all(\n definitionContainerIds.map(async (definitionContainerId) => {\n const definitionContainerInfo = definitionContainersInfo.get(definitionContainerId);\n if (definitionContainerInfo === undefined) {\n return [];\n }\n result.push(...definitionContainerInfo.childCategories.map((category) => category.id));\n return this.getAllContainedCategories(definitionContainerInfo.childDefinitionContainerIds);\n }),\n );\n for (const categories of indirectCategories) {\n result.push(...categories);\n }\n\n return result;\n }\n\n public async getInstanceKeyPaths(\n props: { categoryId: Id64String } | { definitionContainerId: Id64String } | { subCategoryId: Id64String },\n ): Promise<InstanceKey[]> {\n if (\"subCategoryId\" in props) {\n const subCategoriesInfo = await this.getSubCategoriesInfo();\n const subCategoryInfo = subCategoriesInfo.get(props.subCategoryId);\n if (subCategoryInfo === undefined) {\n return [];\n }\n return [...(await this.getInstanceKeyPaths({ categoryId: subCategoryInfo.categoryId })), { id: props.subCategoryId, className: SUB_CATEGORY_CLASS_NAME }];\n }\n\n if (\"categoryId\" in props) {\n const modelsCategoriesInfo = await this.getModelsCategoriesInfo();\n for (const [modelId, modelCategoriesInfo] of modelsCategoriesInfo) {\n if (modelCategoriesInfo.childCategories.find((childCategory) => childCategory.id === props.categoryId)) {\n if (!modelCategoriesInfo.parentDefinitionContainerExists) {\n return [{ id: props.categoryId, className: this._categoryClass }];\n }\n\n return [...(await this.getInstanceKeyPaths({ definitionContainerId: modelId })), { id: props.categoryId, className: this._categoryClass }];\n }\n }\n return [];\n }\n\n const definitionContainersInfo = await this.getDefinitionContainersInfo();\n const definitionContainerInfo = definitionContainersInfo.get(props.definitionContainerId);\n if (definitionContainerInfo === undefined) {\n return [];\n }\n\n if (!definitionContainerInfo.parentDefinitionContainerExists) {\n return [{ id: props.definitionContainerId, className: DEFINITION_CONTAINER_CLASS_NAME }];\n }\n\n return [\n ...(await this.getInstanceKeyPaths({ definitionContainerId: definitionContainerInfo.modelId })),\n { id: props.definitionContainerId, className: DEFINITION_CONTAINER_CLASS_NAME },\n ];\n }\n\n public async getCategoryElementsCount(modelId: Id64String, categoryId: Id64String): Promise<number> {\n return this._categoryElementCounts.getCategoryElementsCount(modelId, categoryId);\n }\n\n public async getAllDefinitionContainersAndCategories(): Promise<{ categories: Array<CategoryId>; definitionContainers: Array<DefinitionContainerId> }> {\n const [modelsCategoriesInfo, definitionContainersInfo] = await Promise.all([this.getModelsCategoriesInfo(), this.getDefinitionContainersInfo()]);\n const result = { definitionContainers: [...definitionContainersInfo.keys()], categories: new Array<Id64String>() };\n for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {\n result.categories.push(...modelCategoriesInfo.childCategories.map((childCategory) => childCategory.id));\n }\n\n return result;\n }\n\n public async getRootDefinitionContainersAndCategories(): Promise<{ categories: CategoryInfo[]; definitionContainers: Array<DefinitionContainerId> }> {\n const [modelsCategoriesInfo, definitionContainersInfo] = await Promise.all([this.getModelsCategoriesInfo(), this.getDefinitionContainersInfo()]);\n const result = { definitionContainers: new Array<Id64String>(), categories: new Array<CategoryInfo>() };\n for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {\n if (!modelCategoriesInfo.parentDefinitionContainerExists) {\n result.categories.push(...modelCategoriesInfo.childCategories);\n }\n }\n\n for (const [definitionContainerId, definitionContainerInfo] of definitionContainersInfo) {\n if (!definitionContainerInfo.parentDefinitionContainerExists) {\n result.definitionContainers.push(definitionContainerId);\n }\n }\n return result;\n }\n\n public async getSubCategories(categoryIds: Id64Array): Promise<Map<CategoryId, Array<SubCategoryId>>> {\n const subCategoriesInfo = await this.getSubCategoriesInfo();\n const result = new Map<CategoryId, Array<SubCategoryId>>();\n for (const categoryId of categoryIds) {\n for (const [subCategoryId, subCategoryInfo] of subCategoriesInfo) {\n if (subCategoryInfo.categoryId === categoryId) {\n let categoryEntry = result.get(categoryId);\n if (!categoryEntry) {\n categoryEntry = [];\n result.set(categoryId, categoryEntry);\n }\n categoryEntry.push(subCategoryId);\n }\n }\n }\n\n return result;\n }\n\n public async getIsDefinitionContainerSupported(): Promise<boolean> {\n this._isDefinitionContainerSupported ??= this.queryIsDefinitionContainersSupported();\n return this._isDefinitionContainerSupported;\n }\n}\n"]}