@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
@@ -2,16 +2,17 @@
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 { bufferTime, filter, firstValueFrom, mergeAll, mergeMap, ReplaySubject, Subject } from "rxjs";
6
5
  import { assert } from "@itwin/core-bentley";
7
6
  import { IModel } from "@itwin/core-common";
8
- import { pushToMap } from "../../common/Utils.js";
7
+ import { GEOMETRIC_MODEL_3D_CLASS_NAME, INFORMATION_PARTITION_ELEMENT_CLASS_NAME, MODEL_CLASS_NAME, SPATIAL_CATEGORY_CLASS_NAME, SUBJECT_CLASS_NAME, } from "../../common/internal/ClassNameDefinitions.js";
8
+ import { ModelCategoryElementsCountCache } from "../../common/internal/ModelCategoryElementsCountCache.js";
9
+ import { pushToMap } from "../../common/internal/Utils.js";
9
10
  /** @internal */
10
11
  export class ModelsTreeIdsCache {
11
12
  constructor(_queryExecutor, _hierarchyConfig) {
12
13
  this._queryExecutor = _queryExecutor;
13
14
  this._hierarchyConfig = _hierarchyConfig;
14
- this._categoryElementCounts = new ModelCategoryElementsCountCache(async (input) => this.queryCategoryElementCounts(input));
15
+ this._categoryElementCounts = new ModelCategoryElementsCountCache(_queryExecutor, this._hierarchyConfig.elementClassSpecification);
15
16
  this._modelKeyPaths = new Map();
16
17
  this._subjectKeyPaths = new Map();
17
18
  this._categoryKeyPaths = new Map();
@@ -26,7 +27,7 @@ export class ModelsTreeIdsCache {
26
27
  s.Parent.Id parentId,
27
28
  (
28
29
  SELECT m.ECInstanceId
29
- FROM bis.GeometricModel3d m
30
+ FROM ${GEOMETRIC_MODEL_3D_CLASS_NAME} m
30
31
  WHERE m.ECInstanceId = HexToId(json_extract(s.JsonProperties, '$.Subject.Model.TargetPartition'))
31
32
  AND NOT m.IsPrivate
32
33
  AND EXISTS (SELECT 1 FROM ${this._hierarchyConfig.elementClassSpecification} WHERE Model.Id = m.ECInstanceId)
@@ -47,8 +48,8 @@ export class ModelsTreeIdsCache {
47
48
  async *queryModels() {
48
49
  const modelsQuery = `
49
50
  SELECT p.ECInstanceId id, p.Parent.Id parentId
50
- FROM bis.InformationPartitionElement p
51
- INNER JOIN bis.GeometricModel3d m ON m.ModeledElement.Id = p.ECInstanceId
51
+ FROM ${INFORMATION_PARTITION_ELEMENT_CLASS_NAME} p
52
+ INNER JOIN ${GEOMETRIC_MODEL_3D_CLASS_NAME} m ON m.ModeledElement.Id = p.ECInstanceId
52
53
  WHERE
53
54
  NOT m.IsPrivate
54
55
  ${this._hierarchyConfig.showEmptyModels ? "" : `AND EXISTS (SELECT 1 FROM ${this._hierarchyConfig.elementClassSpecification} WHERE Model.Id = m.ECInstanceId)`}
@@ -64,13 +65,13 @@ export class ModelsTreeIdsCache {
64
65
  const result = new Map();
65
66
  for await (const subject of this.querySubjects()) {
66
67
  const subjectInfo = {
67
- parentSubject: subject.parentId,
68
+ parentSubjectId: subject.parentId,
68
69
  hideInHierarchy: subject.hideInHierarchy,
69
- childSubjects: new Set(),
70
- childModels: new Set(),
70
+ childSubjectIds: new Set(),
71
+ childModelIds: new Set(),
71
72
  };
72
73
  if (subject.targetPartitionId) {
73
- subjectInfo.childModels.add(subject.targetPartitionId);
74
+ subjectInfo.childModelIds.add(subject.targetPartitionId);
74
75
  }
75
76
  result.set(subject.id, subjectInfo);
76
77
  }
@@ -84,18 +85,18 @@ export class ModelsTreeIdsCache {
84
85
  return result;
85
86
  })(),
86
87
  ]);
87
- for (const [subjectId, { parentSubject: parentSubjectId }] of subjectInfos.entries()) {
88
+ for (const [subjectId, { parentSubjectId }] of subjectInfos.entries()) {
88
89
  if (parentSubjectId) {
89
90
  const parentSubjectInfo = subjectInfos.get(parentSubjectId);
90
91
  assert(!!parentSubjectInfo);
91
- parentSubjectInfo.childSubjects.add(subjectId);
92
+ parentSubjectInfo.childSubjectIds.add(subjectId);
92
93
  }
93
94
  }
94
95
  for (const [partitionId, subjectIds] of targetPartitionSubjects) {
95
96
  subjectIds.forEach((subjectId) => {
96
97
  const subjectInfo = subjectInfos.get(subjectId);
97
98
  assert(!!subjectInfo);
98
- subjectInfo.childModels.add(partitionId);
99
+ subjectInfo.childModelIds.add(partitionId);
99
100
  });
100
101
  }
101
102
  return subjectInfos;
@@ -108,12 +109,12 @@ export class ModelsTreeIdsCache {
108
109
  const subjectInfos = await this.getSubjectInfos();
109
110
  const parentSubjectIds = new Set();
110
111
  subjectInfos.forEach((subjectInfo, subjectId) => {
111
- if (subjectInfo.childModels.size > 0) {
112
+ if (subjectInfo.childModelIds.size > 0) {
112
113
  parentSubjectIds.add(subjectId);
113
- let currParentId = subjectInfo.parentSubject;
114
+ let currParentId = subjectInfo.parentSubjectId;
114
115
  while (currParentId) {
115
116
  parentSubjectIds.add(currParentId);
116
- currParentId = subjectInfos.get(currParentId)?.parentSubject;
117
+ currParentId = subjectInfos.get(currParentId)?.parentSubjectId;
117
118
  }
118
119
  }
119
120
  });
@@ -153,8 +154,8 @@ export class ModelsTreeIdsCache {
153
154
  if (!subjectInfo) {
154
155
  continue;
155
156
  }
156
- result.push(...subjectInfo.childModels);
157
- subjectStack.push(...subjectInfo.childSubjects);
157
+ result.push(...subjectInfo.childModelIds);
158
+ subjectStack.push(...subjectInfo.childSubjectIds);
158
159
  }
159
160
  return result;
160
161
  }
@@ -174,7 +175,7 @@ export class ModelsTreeIdsCache {
174
175
  const modelIds = new Array();
175
176
  [...parentSubjectIds, ...hiddenSubjectIds].forEach((subjectId) => {
176
177
  const subjectInfo = subjectInfos.get(subjectId);
177
- subjectInfo && modelIds.push(...subjectInfo.childModels);
178
+ subjectInfo && modelIds.push(...subjectInfo.childModelIds);
178
179
  });
179
180
  return modelIds;
180
181
  }
@@ -185,12 +186,15 @@ export class ModelsTreeIdsCache {
185
186
  const subjectInfos = await this.getSubjectInfos();
186
187
  const result = new Array();
187
188
  let currParentId = targetSubjectId;
188
- while (currParentId && currParentId !== IModel.rootSubjectId) {
189
+ while (currParentId) {
190
+ if (this._hierarchyConfig.hideRootSubject && currParentId === IModel.rootSubjectId) {
191
+ break;
192
+ }
189
193
  const parentInfo = subjectInfos.get(currParentId);
190
194
  if (!parentInfo?.hideInHierarchy) {
191
- result.push({ className: "BisCore.Subject", id: currParentId });
195
+ result.push({ className: SUBJECT_CLASS_NAME, id: currParentId });
192
196
  }
193
- currParentId = parentInfo?.parentSubject;
197
+ currParentId = parentInfo?.parentSubjectId;
194
198
  }
195
199
  return result.reverse();
196
200
  })();
@@ -199,7 +203,7 @@ export class ModelsTreeIdsCache {
199
203
  return entry;
200
204
  }
201
205
  async *queryModelElementCounts() {
202
- const query = /* sql */ `
206
+ const query = `
203
207
  SELECT Model.Id modelId, COUNT(*) elementCount
204
208
  FROM ${this._hierarchyConfig.elementClassSpecification}
205
209
  GROUP BY Model.Id
@@ -209,14 +213,15 @@ export class ModelsTreeIdsCache {
209
213
  }
210
214
  }
211
215
  async *queryModelCategories() {
212
- const query = /* sql */ `
213
- SELECT Model.Id modelId, Category.Id categoryId
214
- FROM ${this._hierarchyConfig.elementClassSpecification}
215
- WHERE Parent.Id IS NULL
216
- GROUP BY modelId, categoryId
216
+ const query = `
217
+ SELECT this.Model.Id modelId, this.Category.Id categoryId, m.IsPrivate isModelPrivate
218
+ FROM ${MODEL_CLASS_NAME} m
219
+ JOIN ${this._hierarchyConfig.elementClassSpecification} this ON m.ECInstanceId = this.Model.Id
220
+ WHERE this.Parent.Id IS NULL
221
+ GROUP BY modelId, categoryId, isModelPrivate
217
222
  `;
218
223
  for await (const row of this._queryExecutor.createQueryReader({ ecsql: query }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded" })) {
219
- yield { modelId: row.modelId, categoryId: row.categoryId };
224
+ yield { modelId: row.modelId, categoryId: row.categoryId, isModelPrivate: !!row.isModelPrivate };
220
225
  }
221
226
  }
222
227
  async *queryModeledElements() {
@@ -225,8 +230,11 @@ export class ModelsTreeIdsCache {
225
230
  pe.ECInstanceId modeledElementId,
226
231
  pe.Category.Id categoryId,
227
232
  pe.Model.Id modelId
228
- FROM BisCore.Model m
233
+ FROM ${MODEL_CLASS_NAME} m
229
234
  JOIN ${this._hierarchyConfig.elementClassSpecification} pe ON pe.ECInstanceId = m.ModeledElement.Id
235
+ WHERE
236
+ m.IsPrivate = false
237
+ AND m.ECInstanceId IN (SELECT Model.Id FROM ${this._hierarchyConfig.elementClassSpecification})
230
238
  `;
231
239
  for await (const row of this._queryExecutor.createQueryReader({ ecsql: query }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded" })) {
232
240
  yield { modelId: row.modelId, categoryId: row.categoryId, modeledElementId: row.modeledElementId };
@@ -254,13 +262,14 @@ export class ModelsTreeIdsCache {
254
262
  const modelInfos = new Map();
255
263
  await Promise.all([
256
264
  (async () => {
257
- for await (const { modelId, categoryId } of this.queryModelCategories()) {
265
+ for await (const { modelId, categoryId, isModelPrivate } of this.queryModelCategories()) {
258
266
  const entry = modelInfos.get(modelId);
259
267
  if (entry) {
260
- entry.categories.add(categoryId);
268
+ entry.categoryIds.add(categoryId);
269
+ entry.isModelPrivate = isModelPrivate;
261
270
  }
262
271
  else {
263
- modelInfos.set(modelId, { categories: new Set([categoryId]), elementCount: 0 });
272
+ modelInfos.set(modelId, { categoryIds: new Set([categoryId]), elementCount: 0, isModelPrivate });
264
273
  }
265
274
  }
266
275
  })(),
@@ -271,7 +280,7 @@ export class ModelsTreeIdsCache {
271
280
  entry.elementCount = elementCount;
272
281
  }
273
282
  else {
274
- modelInfos.set(modelId, { categories: new Set(), elementCount });
283
+ modelInfos.set(modelId, { categoryIds: new Set(), elementCount, isModelPrivate: false });
275
284
  }
276
285
  }
277
286
  })(),
@@ -280,9 +289,9 @@ export class ModelsTreeIdsCache {
280
289
  })();
281
290
  return this._modelInfos;
282
291
  }
283
- async getModelCategories(modelId) {
292
+ async getModelCategoryIds(modelId) {
284
293
  const modelInfos = await this.getModelInfos();
285
- const categories = modelInfos.get(modelId)?.categories;
294
+ const categories = modelInfos.get(modelId)?.categoryIds;
286
295
  return categories ? [...categories] : [];
287
296
  }
288
297
  async getModelElementCount(modelId) {
@@ -291,7 +300,11 @@ export class ModelsTreeIdsCache {
291
300
  }
292
301
  async hasSubModel(elementId) {
293
302
  const modelInfos = await this.getModelInfos();
294
- return modelInfos.has(elementId);
303
+ const modeledElementInfo = modelInfos.get(elementId);
304
+ if (!modeledElementInfo) {
305
+ return false;
306
+ }
307
+ return !modeledElementInfo.isModelPrivate;
295
308
  }
296
309
  async getCategoriesModeledElements(modelId, categoryIds) {
297
310
  const modelWithCategoryModeledElements = await this.getModelWithCategoryModeledElements();
@@ -311,7 +324,7 @@ export class ModelsTreeIdsCache {
311
324
  const result = new Array();
312
325
  const subjectInfos = (await this.getSubjectInfos()).entries();
313
326
  for (const [modelSubjectId, subjectInfo] of subjectInfos) {
314
- if (subjectInfo.childModels.has(modelId)) {
327
+ if (subjectInfo.childModelIds.has(modelId)) {
315
328
  const subjectPath = await this.createSubjectInstanceKeysPath(modelSubjectId);
316
329
  result.push([...subjectPath, { className: "BisCore.GeometricModel3d", id: modelId }]);
317
330
  }
@@ -322,39 +335,6 @@ export class ModelsTreeIdsCache {
322
335
  }
323
336
  return entry;
324
337
  }
325
- async queryCategoryElementCounts(input) {
326
- const reader = this._queryExecutor.createQueryReader({
327
- ctes: [
328
- /* sql */ `
329
- CategoryElements(id, modelId, categoryId) AS (
330
- SELECT ECInstanceId, Model.Id, Category.Id
331
- FROM ${this._hierarchyConfig.elementClassSpecification}
332
- WHERE
333
- Parent.Id IS NULL
334
- AND (
335
- ${input.map(({ modelId, categoryId }) => `Model.Id = ${modelId} AND Category.Id = ${categoryId}`).join(" OR ")}
336
- )
337
-
338
- UNION ALL
339
-
340
- SELECT c.ECInstanceId, p.modelId, p.categoryId
341
- FROM ${this._hierarchyConfig.elementClassSpecification} c
342
- JOIN CategoryElements p ON c.Parent.Id = p.id
343
- )
344
- `,
345
- ],
346
- ecsql: `
347
- SELECT modelId, categoryId, COUNT(id) elementsCount
348
- FROM CategoryElements
349
- GROUP BY modelId, categoryId
350
- `,
351
- }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded" });
352
- const result = new Array();
353
- for await (const row of reader) {
354
- result.push({ modelId: row.modelId, categoryId: row.categoryId, elementsCount: row.elementsCount });
355
- }
356
- return result;
357
- }
358
338
  async getCategoryElementsCount(modelId, categoryId) {
359
339
  return this._categoryElementCounts.getCategoryElementsCount(modelId, categoryId);
360
340
  }
@@ -365,7 +345,7 @@ export class ModelsTreeIdsCache {
365
345
  const result = new Set();
366
346
  const modelInfos = await this.getModelInfos();
367
347
  modelInfos?.forEach((modelInfo, modelId) => {
368
- if (modelInfo.categories.has(categoryId)) {
348
+ if (modelInfo.categoryIds.has(categoryId)) {
369
349
  result.add(modelId);
370
350
  }
371
351
  });
@@ -373,7 +353,7 @@ export class ModelsTreeIdsCache {
373
353
  for (const categoryModelId of [...result]) {
374
354
  const modelPaths = await this.createModelInstanceKeyPaths(categoryModelId);
375
355
  for (const modelPath of modelPaths) {
376
- categoryPaths.push([...modelPath, { className: "BisCore.SpatialCategory", id: categoryId }]);
356
+ categoryPaths.push([...modelPath, { className: SPATIAL_CATEGORY_CLASS_NAME, id: categoryId }]);
377
357
  }
378
358
  }
379
359
  return categoryPaths;
@@ -386,7 +366,7 @@ export class ModelsTreeIdsCache {
386
366
  function forEachChildSubject(subjectInfos, parentSubject, cb) {
387
367
  const parentSubjectInfo = typeof parentSubject === "string" ? subjectInfos.get(parentSubject) : parentSubject;
388
368
  parentSubjectInfo &&
389
- parentSubjectInfo.childSubjects.forEach((childSubjectId) => {
369
+ parentSubjectInfo.childSubjectIds.forEach((childSubjectId) => {
390
370
  const childSubjectInfo = subjectInfos.get(childSubjectId);
391
371
  if (cb(childSubjectId, childSubjectInfo) === "break") {
392
372
  return;
@@ -394,34 +374,4 @@ function forEachChildSubject(subjectInfos, parentSubject, cb) {
394
374
  forEachChildSubject(subjectInfos, childSubjectInfo, cb);
395
375
  });
396
376
  }
397
- class ModelCategoryElementsCountCache {
398
- constructor(_loader) {
399
- this._loader = _loader;
400
- this._cache = new Map();
401
- this._requestsStream = new Subject();
402
- this._subscription = this._requestsStream
403
- .pipe(bufferTime(20), filter((requests) => requests.length > 0), mergeMap(async (requests) => this._loader(requests)), mergeAll())
404
- .subscribe({
405
- next: ({ modelId, categoryId, elementsCount }) => {
406
- const subject = this._cache.get(`${modelId}${categoryId}`);
407
- assert(!!subject);
408
- subject.next(elementsCount);
409
- },
410
- });
411
- }
412
- [Symbol.dispose]() {
413
- this._subscription.unsubscribe();
414
- }
415
- async getCategoryElementsCount(modelId, categoryId) {
416
- const cacheKey = `${modelId}${categoryId}`;
417
- let result = this._cache.get(cacheKey);
418
- if (result !== undefined) {
419
- return firstValueFrom(result);
420
- }
421
- result = new ReplaySubject(1);
422
- this._cache.set(cacheKey, result);
423
- this._requestsStream.next({ modelId, categoryId });
424
- return firstValueFrom(result);
425
- }
426
- }
427
377
  //# sourceMappingURL=ModelsTreeIdsCache.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ModelsTreeIdsCache.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAGhG,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACtG,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAqBlD,gBAAgB;AAChB,MAAM,OAAO,kBAAkB;IAU7B,YACU,cAA0C,EAC1C,gBAAkD;QADlD,mBAAc,GAAd,cAAc,CAA4B;QAC1C,qBAAgB,GAAhB,gBAAgB,CAAkC;QAE1D,IAAI,CAAC,sBAAsB,GAAG,IAAI,+BAA+B,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,0BAA0B,CAAC,KAAK,CAAC,CAAC,CAAC;QAC3H,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,EAAE,CAAC;QAChC,IAAI,CAAC,gBAAgB,GAAG,IAAI,GAAG,EAAE,CAAC;QAClC,IAAI,CAAC,iBAAiB,GAAG,IAAI,GAAG,EAAE,CAAC;IACrC,CAAC;IAEM,CAAC,MA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IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,EAAE,EAAE;gBAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,OAAO,GAAG,UAAU,EAAE,CAAC,CAAC;gBAC3D,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;gBAClB,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YAC9B,CAAC;SACF,CAAC,CAAC;IACP,CAAC;IAEM,CAAC,MAAM,CAAC,OAAO,CAAC;QACrB,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC;IACnC,CAAC;IAEM,KAAK,CAAC,wBAAwB,CAAC,OAAmB,EAAE,UAAsB;QAC/E,MAAM,QAAQ,GAAG,GAAG,OAAO,GAAG,UAAU,EAAE,CAAC;QAC3C,IAAI,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACvC,IAAI,MAAM,KAAK,SAAS,EAAE;YACxB,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC;SAC/B;QAED,MAAM,GAAG,IAAI,aAAa,CAAC,CAAC,CAAC,CAAC;QAC9B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAClC,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;QACnD,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC;IAChC,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 type { Subscription } from \"rxjs\";\nimport { bufferTime, filter, firstValueFrom, mergeAll, mergeMap, ReplaySubject, Subject } from \"rxjs\";\nimport { assert } from \"@itwin/core-bentley\";\nimport { IModel } from \"@itwin/core-common\";\nimport { pushToMap } from \"../../common/Utils.js\";\n\nimport type { InstanceKey } from \"@itwin/presentation-shared\";\nimport type { ModelsTreeDefinition } from \"../ModelsTreeDefinition.js\";\nimport type { Id64Array, Id64Set, Id64String } from \"@itwin/core-bentley\";\nimport type { HierarchyNodeIdentifiersPath, LimitingECSqlQueryExecutor } from \"@itwin/presentation-hierarchies\";\n\ninterface SubjectInfo {\n parentSubject: Id64String | undefined;\n hideInHierarchy: boolean;\n childSubjects: Id64Set;\n childModels: Id64Set;\n}\n\ninterface ModelInfo {\n categories: Id64Set;\n elementCount: number;\n}\n\ntype ModelsTreeHierarchyConfiguration = ConstructorParameters<typeof ModelsTreeDefinition>[0][\"hierarchyConfig\"];\n\n/** @internal */\nexport class ModelsTreeIdsCache {\n private readonly _categoryElementCounts: ModelCategoryElementsCountCache;\n private _subjectInfos: Promise<Map<Id64String, SubjectInfo>> | undefined;\n private _parentSubjectIds: Promise<Id64Array> | undefined; // the list should contain a subject id if its node should be shown as having children\n private _modelInfos: Promise<Map<Id64String, ModelInfo>> | undefined;\n private _modelWithCategoryModeledElements: Promise<Map<Id64String, Id64Set>> | undefined;\n private _modelKeyPaths: Map<Id64String, Promise<HierarchyNodeIdentifiersPath[]>>;\n private _subjectKeyPaths: Map<Id64String, Promise<HierarchyNodeIdentifiersPath>>;\n private _categoryKeyPaths: Map<Id64String, Promise<HierarchyNodeIdentifiersPath[]>>;\n\n constructor(\n private _queryExecutor: LimitingECSqlQueryExecutor,\n private _hierarchyConfig: ModelsTreeHierarchyConfiguration,\n ) {\n this._categoryElementCounts = new ModelCategoryElementsCountCache(async (input) => this.queryCategoryElementCounts(input));\n this._modelKeyPaths = new Map();\n this._subjectKeyPaths = new Map();\n this._categoryKeyPaths = new Map();\n }\n\n public [Symbol.dispose]() {\n this._categoryElementCounts[Symbol.dispose]();\n }\n\n private async *querySubjects(): AsyncIterableIterator<{ id: Id64String; parentId?: Id64String; targetPartitionId?: Id64String; hideInHierarchy: boolean }> {\n const subjectsQuery = `\n SELECT\n s.ECInstanceId id,\n s.Parent.Id parentId,\n (\n SELECT m.ECInstanceId\n FROM bis.GeometricModel3d m\n WHERE m.ECInstanceId = HexToId(json_extract(s.JsonProperties, '$.Subject.Model.TargetPartition'))\n AND NOT m.IsPrivate\n AND EXISTS (SELECT 1 FROM ${this._hierarchyConfig.elementClassSpecification} WHERE Model.Id = m.ECInstanceId)\n ) targetPartitionId,\n CASE\n WHEN (\n json_extract(s.JsonProperties, '$.Subject.Job.Bridge') IS NOT NULL\n OR json_extract(s.JsonProperties, '$.Subject.Model.Type') = 'Hierarchy'\n ) THEN 1\n ELSE 0\n END hideInHierarchy\n FROM bis.Subject s\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: subjectsQuery }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { id: row.id, parentId: row.parentId, targetPartitionId: row.targetPartitionId, hideInHierarchy: !!row.hideInHierarchy };\n }\n }\n\n private async *queryModels(): AsyncIterableIterator<{ id: Id64String; parentId: Id64String }> {\n const modelsQuery = `\n SELECT p.ECInstanceId id, p.Parent.Id parentId\n FROM bis.InformationPartitionElement p\n INNER JOIN bis.GeometricModel3d m ON m.ModeledElement.Id = p.ECInstanceId\n WHERE\n NOT m.IsPrivate\n ${this._hierarchyConfig.showEmptyModels ? \"\" : `AND EXISTS (SELECT 1 FROM ${this._hierarchyConfig.elementClassSpecification} WHERE Model.Id = m.ECInstanceId)`}\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: modelsQuery }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { id: row.id, parentId: row.parentId };\n }\n }\n\n private async getSubjectInfos() {\n this._subjectInfos ??= (async () => {\n const [subjectInfos, targetPartitionSubjects] = await Promise.all([\n (async () => {\n const result = new Map<Id64String, SubjectInfo>();\n for await (const subject of this.querySubjects()) {\n const subjectInfo: SubjectInfo = {\n parentSubject: subject.parentId,\n hideInHierarchy: subject.hideInHierarchy,\n childSubjects: new Set(),\n childModels: new Set(),\n };\n if (subject.targetPartitionId) {\n subjectInfo.childModels.add(subject.targetPartitionId);\n }\n result.set(subject.id, subjectInfo);\n }\n return result;\n })(),\n (async () => {\n const result = new Map<Id64String, Set<Id64String>>();\n for await (const model of this.queryModels()) {\n pushToMap(result, model.id, model.parentId);\n }\n return result;\n })(),\n ]);\n\n for (const [subjectId, { parentSubject: parentSubjectId }] of subjectInfos.entries()) {\n if (parentSubjectId) {\n const parentSubjectInfo = subjectInfos.get(parentSubjectId);\n assert(!!parentSubjectInfo);\n parentSubjectInfo.childSubjects.add(subjectId);\n }\n }\n\n for (const [partitionId, subjectIds] of targetPartitionSubjects) {\n subjectIds.forEach((subjectId) => {\n const subjectInfo = subjectInfos.get(subjectId);\n assert(!!subjectInfo);\n subjectInfo.childModels.add(partitionId);\n });\n }\n\n return subjectInfos;\n })();\n return this._subjectInfos;\n }\n\n /** Returns ECInstanceIDs of Subjects that either have direct Model or at least one child Subject with a Model. */\n public async getParentSubjectIds(): Promise<Id64String[]> {\n this._parentSubjectIds ??= (async () => {\n const subjectInfos = await this.getSubjectInfos();\n const parentSubjectIds = new Set<Id64String>();\n subjectInfos.forEach((subjectInfo, subjectId) => {\n if (subjectInfo.childModels.size > 0) {\n parentSubjectIds.add(subjectId);\n let currParentId = subjectInfo.parentSubject;\n while (currParentId) {\n parentSubjectIds.add(currParentId);\n currParentId = subjectInfos.get(currParentId)?.parentSubject;\n }\n }\n });\n return [...parentSubjectIds];\n })();\n return this._parentSubjectIds;\n }\n\n /**\n * Returns child subjects of the specified parent subjects as they're displayed in the hierarchy - taking into\n * account `hideInHierarchy` flag.\n */\n public async getChildSubjectIds(parentSubjectIds: Id64String[]): Promise<Id64String[]> {\n const childSubjectIds = new Array<Id64String>();\n const subjectInfos = await this.getSubjectInfos();\n parentSubjectIds.forEach((subjectId) => {\n forEachChildSubject(subjectInfos, subjectId, (childSubjectId, childSubjectInfo) => {\n if (!childSubjectInfo.hideInHierarchy) {\n childSubjectIds.push(childSubjectId);\n return \"break\";\n }\n return \"continue\";\n });\n });\n return childSubjectIds;\n }\n\n /** Returns ECInstanceIDs of all Models under specific parent Subjects, including their child Subjects, etc. */\n public async getSubjectModelIds(subjectIds: Id64Array): Promise<Id64Array> {\n const subjectInfos = await this.getSubjectInfos();\n const subjectStack = [...subjectIds];\n const result = new Array<Id64String>();\n while (true) {\n const subjectId = subjectStack.pop();\n if (subjectId === undefined) {\n break;\n }\n const subjectInfo = subjectInfos.get(subjectId);\n if (!subjectInfo) {\n continue;\n }\n result.push(...subjectInfo.childModels);\n subjectStack.push(...subjectInfo.childSubjects);\n }\n return result;\n }\n\n /** Returns ECInstanceIDs of Models under specific parent Subjects as they are displayed in the hierarchy. */\n public async getChildSubjectModelIds(parentSubjectIds: Id64String[]): Promise<Id64String[]> {\n const subjectInfos = await this.getSubjectInfos();\n\n const hiddenSubjectIds = new Array<Id64String>();\n parentSubjectIds.forEach((subjectId) => {\n forEachChildSubject(subjectInfos, subjectId, (childSubjectId, childSubjectInfo) => {\n if (childSubjectInfo.hideInHierarchy) {\n hiddenSubjectIds.push(childSubjectId);\n return \"continue\";\n }\n return \"break\";\n });\n });\n\n const modelIds = new Array<Id64String>();\n [...parentSubjectIds, ...hiddenSubjectIds].forEach((subjectId) => {\n const subjectInfo = subjectInfos.get(subjectId);\n subjectInfo && modelIds.push(...subjectInfo.childModels);\n });\n return modelIds;\n }\n\n public async createSubjectInstanceKeysPath(targetSubjectId: Id64String): Promise<HierarchyNodeIdentifiersPath> {\n let entry = this._subjectKeyPaths.get(targetSubjectId);\n if (!entry) {\n entry = (async () => {\n const subjectInfos = await this.getSubjectInfos();\n const result = new Array<InstanceKey>();\n let currParentId: Id64String | undefined = targetSubjectId;\n while (currParentId && currParentId !== IModel.rootSubjectId) {\n const parentInfo = subjectInfos.get(currParentId);\n if (!parentInfo?.hideInHierarchy) {\n result.push({ className: \"BisCore.Subject\", id: currParentId });\n }\n currParentId = parentInfo?.parentSubject;\n }\n return result.reverse();\n })();\n this._subjectKeyPaths.set(targetSubjectId, entry);\n }\n return entry;\n }\n\n private async *queryModelElementCounts() {\n const query = /* sql */ `\n SELECT Model.Id modelId, COUNT(*) elementCount\n FROM ${this._hierarchyConfig.elementClassSpecification}\n GROUP BY Model.Id\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: query }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { modelId: row.modelId, elementCount: row.elementCount };\n }\n }\n\n private async *queryModelCategories() {\n const query = /* sql */ `\n SELECT Model.Id modelId, Category.Id categoryId\n FROM ${this._hierarchyConfig.elementClassSpecification}\n WHERE Parent.Id IS NULL\n GROUP BY modelId, categoryId\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: query }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { modelId: row.modelId, categoryId: row.categoryId };\n }\n }\n\n private async *queryModeledElements() {\n const query = `\n SELECT\n pe.ECInstanceId modeledElementId,\n pe.Category.Id categoryId,\n pe.Model.Id modelId\n FROM BisCore.Model m\n JOIN ${this._hierarchyConfig.elementClassSpecification} pe ON pe.ECInstanceId = m.ModeledElement.Id\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: query }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { modelId: row.modelId, categoryId: row.categoryId, modeledElementId: row.modeledElementId };\n }\n }\n\n private async getModelWithCategoryModeledElements() {\n this._modelWithCategoryModeledElements ??= (async () => {\n const modelWithCategoryModeledElements = new Map<Id64String, Id64Set>();\n for await (const { modelId, categoryId, modeledElementId } of this.queryModeledElements()) {\n const key = `${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 private async getModelInfos() {\n this._modelInfos ??= (async () => {\n const modelInfos = new Map<Id64String, { categories: Id64Set; elementCount: number }>();\n await Promise.all([\n (async () => {\n for await (const { modelId, categoryId } of this.queryModelCategories()) {\n const entry = modelInfos.get(modelId);\n if (entry) {\n entry.categories.add(categoryId);\n } else {\n modelInfos.set(modelId, { categories: new Set([categoryId]), elementCount: 0 });\n }\n }\n })(),\n (async () => {\n for await (const { modelId, elementCount } of this.queryModelElementCounts()) {\n const entry = modelInfos.get(modelId);\n if (entry) {\n entry.elementCount = elementCount;\n } else {\n modelInfos.set(modelId, { categories: new Set(), elementCount });\n }\n }\n })(),\n ]);\n return modelInfos;\n })();\n return this._modelInfos;\n }\n\n public async getModelCategories(modelId: Id64String): Promise<Id64Array> {\n const modelInfos = await this.getModelInfos();\n const categories = modelInfos.get(modelId)?.categories;\n return categories ? [...categories] : [];\n }\n\n public async getModelElementCount(modelId: Id64String): Promise<number> {\n const modelInfos = await this.getModelInfos();\n return modelInfos.get(modelId)?.elementCount ?? 0;\n }\n\n public async hasSubModel(elementId: Id64String): Promise<boolean> {\n const modelInfos = await this.getModelInfos();\n return modelInfos.has(elementId);\n }\n\n public async getCategoriesModeledElements(modelId: Id64String, categoryIds: Id64Array): Promise<Id64Array> {\n const modelWithCategoryModeledElements = await this.getModelWithCategoryModeledElements();\n const result = new Array<Id64String>();\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 public async createModelInstanceKeyPaths(modelId: Id64String): Promise<HierarchyNodeIdentifiersPath[]> {\n let entry = this._modelKeyPaths.get(modelId);\n if (!entry) {\n entry = (async () => {\n const result = new Array<HierarchyNodeIdentifiersPath>();\n const subjectInfos = (await this.getSubjectInfos()).entries();\n for (const [modelSubjectId, subjectInfo] of subjectInfos) {\n if (subjectInfo.childModels.has(modelId)) {\n const subjectPath = await this.createSubjectInstanceKeysPath(modelSubjectId);\n result.push([...subjectPath, { className: \"BisCore.GeometricModel3d\", id: modelId }]);\n }\n }\n return result;\n })();\n\n this._modelKeyPaths.set(modelId, entry);\n }\n return entry;\n }\n\n private async queryCategoryElementCounts(\n input: Array<{ modelId: Id64String; categoryId: Id64String }>,\n ): Promise<Array<{ modelId: number; categoryId: number; elementsCount: number }>> {\n const reader = this._queryExecutor.createQueryReader(\n {\n ctes: [\n /* sql */ `\n CategoryElements(id, modelId, categoryId) AS (\n SELECT ECInstanceId, Model.Id, Category.Id\n FROM ${this._hierarchyConfig.elementClassSpecification}\n WHERE\n Parent.Id IS NULL\n AND (\n ${input.map(({ modelId, categoryId }) => `Model.Id = ${modelId} AND Category.Id = ${categoryId}`).join(\" OR \")}\n )\n\n UNION ALL\n\n SELECT c.ECInstanceId, p.modelId, p.categoryId\n FROM ${this._hierarchyConfig.elementClassSpecification} c\n JOIN CategoryElements p ON c.Parent.Id = p.id\n )\n `,\n ],\n ecsql: `\n SELECT modelId, categoryId, COUNT(id) elementsCount\n FROM CategoryElements\n GROUP BY modelId, categoryId\n `,\n },\n { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" },\n );\n\n const result = new Array<{ modelId: number; categoryId: number; elementsCount: number }>();\n for await (const row of reader) {\n result.push({ modelId: row.modelId, categoryId: row.categoryId, elementsCount: row.elementsCount });\n }\n return result;\n }\n\n public async getCategoryElementsCount(modelId: Id64String, categoryId: Id64String): Promise<number> {\n return this._categoryElementCounts.getCategoryElementsCount(modelId, categoryId);\n }\n\n public async createCategoryInstanceKeyPaths(categoryId: Id64String): Promise<HierarchyNodeIdentifiersPath[]> {\n let entry = this._categoryKeyPaths.get(categoryId);\n if (!entry) {\n entry = (async () => {\n const result = new Set<Id64String>();\n const modelInfos = await this.getModelInfos();\n modelInfos?.forEach((modelInfo, modelId) => {\n if (modelInfo.categories.has(categoryId)) {\n result.add(modelId);\n }\n });\n\n const categoryPaths = new Array<HierarchyNodeIdentifiersPath>();\n for (const categoryModelId of [...result]) {\n const modelPaths = await this.createModelInstanceKeyPaths(categoryModelId);\n for (const modelPath of modelPaths) {\n categoryPaths.push([...modelPath, { className: \"BisCore.SpatialCategory\", id: categoryId }]);\n }\n }\n return categoryPaths;\n })();\n this._categoryKeyPaths.set(categoryId, entry);\n }\n return entry;\n }\n}\n\nfunction forEachChildSubject(\n subjectInfos: Map<Id64String, SubjectInfo>,\n parentSubject: Id64String | SubjectInfo,\n cb: (childSubjectId: Id64String, childSubjectInfo: SubjectInfo) => \"break\" | \"continue\",\n) {\n const parentSubjectInfo = typeof parentSubject === \"string\" ? subjectInfos.get(parentSubject) : parentSubject;\n parentSubjectInfo &&\n parentSubjectInfo.childSubjects.forEach((childSubjectId) => {\n const childSubjectInfo = subjectInfos.get(childSubjectId)!;\n if (cb(childSubjectId, childSubjectInfo) === \"break\") {\n return;\n }\n forEachChildSubject(subjectInfos, childSubjectInfo, cb);\n });\n}\n\nclass ModelCategoryElementsCountCache {\n private _cache = new Map<string, Subject<number>>();\n private _requestsStream = new Subject<{ modelId: Id64String; categoryId: Id64String }>();\n private _subscription: Subscription;\n\n public constructor(\n private _loader: (\n input: Array<{ modelId: Id64String; categoryId: Id64String }>,\n ) => Promise<Array<{ modelId: number; categoryId: number; elementsCount: number }>>,\n ) {\n this._subscription = this._requestsStream\n .pipe(\n bufferTime(20),\n filter((requests) => requests.length > 0),\n mergeMap(async (requests) => this._loader(requests)),\n mergeAll(),\n )\n .subscribe({\n next: ({ modelId, categoryId, elementsCount }) => {\n const subject = this._cache.get(`${modelId}${categoryId}`);\n assert(!!subject);\n subject.next(elementsCount);\n },\n });\n }\n\n public [Symbol.dispose]() {\n this._subscription.unsubscribe();\n }\n\n public async getCategoryElementsCount(modelId: Id64String, categoryId: Id64String): Promise<number> {\n const cacheKey = `${modelId}${categoryId}`;\n let result = this._cache.get(cacheKey);\n if (result !== undefined) {\n return firstValueFrom(result);\n }\n\n result = new ReplaySubject(1);\n this._cache.set(cacheKey, result);\n this._requestsStream.next({ modelId, categoryId });\n return firstValueFrom(result);\n }\n}\n"]}
1
+ {"version":3,"file":"ModelsTreeIdsCache.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EACL,6BAA6B,EAC7B,wCAAwC,EACxC,gBAAgB,EAChB,2BAA2B,EAC3B,kBAAkB,GACnB,MAAM,+CAA+C,CAAC;AACvD,OAAO,EAAE,+BAA+B,EAAE,MAAM,0DAA0D,CAAC;AAC3G,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAyB3D,gBAAgB;AAChB,MAAM,OAAO,kBAAkB;IAU7B,YACU,cAA0C,EAC1C,gBAAkD;QADlD,mBAAc,GAAd,cAAc,CAA4B;QAC1C,qBAAgB,GAAhB,gBAAgB,CAAkC;QAE1D,IAAI,CAAC,sBAAsB,GAAG,IAAI,+BAA+B,CAAC,cAAc,EAAE,IAAI,CAAC,gBAAgB,CAAC,yBAAyB,CAAC,CAAC;QACnI,IAAI,CAAC,cAAc,GAAG,IAAI,GAAG,EAAE,CAAC;QAChC,IAAI,CAAC,gBAAgB,GAAG,IAAI,GAAG,EAAE,CAAC;QAClC,IAAI,CAAC,iBAAiB,GAAG,IAAI,GAAG,EAAE,CAAC;IACrC,CAAC;IAEM,CAAC,MAAM,CAAC,OAAO,CAAC;QACrB,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;IAChD,CAAC;IAEO,KAAK,CAAC,CAAC,aAAa;QAC1B,MAAM,aAAa,GAAG;;;;;;iBAMT,6BAA6B;;;wCAGN,IAAI,CAAC,gBAAgB,CAAC,yBAAyB;;;;;;;;;;KAUlF,CAAC;QACF,IAAI,KAAK,EAAE,MAAM,GA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E,gBAAgB,EAAE,EAAE,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;AACP,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 { assert } from \"@itwin/core-bentley\";\nimport { IModel } from \"@itwin/core-common\";\nimport {\n GEOMETRIC_MODEL_3D_CLASS_NAME,\n INFORMATION_PARTITION_ELEMENT_CLASS_NAME,\n MODEL_CLASS_NAME,\n SPATIAL_CATEGORY_CLASS_NAME,\n SUBJECT_CLASS_NAME,\n} from \"../../common/internal/ClassNameDefinitions.js\";\nimport { ModelCategoryElementsCountCache } from \"../../common/internal/ModelCategoryElementsCountCache.js\";\nimport { pushToMap } from \"../../common/internal/Utils.js\";\n\nimport type { InstanceKey } from \"@itwin/presentation-shared\";\nimport type { ModelsTreeDefinition } from \"../ModelsTreeDefinition.js\";\nimport type { Id64Array, Id64Set, Id64String } from \"@itwin/core-bentley\";\nimport type { HierarchyNodeIdentifiersPath, LimitingECSqlQueryExecutor } from \"@itwin/presentation-hierarchies\";\nimport type { CategoryId, ElementId, ModelId, SubjectId } from \"../../common/internal/Types.js\";\n\ninterface SubjectInfo {\n parentSubjectId: Id64String | undefined;\n hideInHierarchy: boolean;\n childSubjectIds: Id64Set;\n childModelIds: Id64Set;\n}\n\ninterface ModelInfo {\n isModelPrivate: boolean;\n categoryIds: Id64Set;\n elementCount: number;\n}\n\ntype ModelsTreeHierarchyConfiguration = ConstructorParameters<typeof ModelsTreeDefinition>[0][\"hierarchyConfig\"];\n\ntype ModelCategoryKey = `${ModelId}-${CategoryId}`;\n\n/** @internal */\nexport class ModelsTreeIdsCache {\n private readonly _categoryElementCounts: ModelCategoryElementsCountCache;\n private _subjectInfos: Promise<Map<SubjectId, SubjectInfo>> | undefined;\n private _parentSubjectIds: Promise<Id64Array> | undefined; // the list should contain a subject id if its node should be shown as having children\n private _modelInfos: Promise<Map<ModelId, ModelInfo>> | undefined;\n private _modelWithCategoryModeledElements: Promise<Map<ModelCategoryKey, Set<ElementId>>> | undefined;\n private _modelKeyPaths: Map<ModelId, Promise<HierarchyNodeIdentifiersPath[]>>;\n private _subjectKeyPaths: Map<SubjectId, Promise<HierarchyNodeIdentifiersPath>>;\n private _categoryKeyPaths: Map<CategoryId, Promise<HierarchyNodeIdentifiersPath[]>>;\n\n constructor(\n private _queryExecutor: LimitingECSqlQueryExecutor,\n private _hierarchyConfig: ModelsTreeHierarchyConfiguration,\n ) {\n this._categoryElementCounts = new ModelCategoryElementsCountCache(_queryExecutor, this._hierarchyConfig.elementClassSpecification);\n this._modelKeyPaths = new Map();\n this._subjectKeyPaths = new Map();\n this._categoryKeyPaths = new Map();\n }\n\n public [Symbol.dispose]() {\n this._categoryElementCounts[Symbol.dispose]();\n }\n\n private async *querySubjects(): AsyncIterableIterator<{ id: SubjectId; parentId?: SubjectId; targetPartitionId?: ModelId; hideInHierarchy: boolean }> {\n const subjectsQuery = `\n SELECT\n s.ECInstanceId id,\n s.Parent.Id parentId,\n (\n SELECT m.ECInstanceId\n FROM ${GEOMETRIC_MODEL_3D_CLASS_NAME} m\n WHERE m.ECInstanceId = HexToId(json_extract(s.JsonProperties, '$.Subject.Model.TargetPartition'))\n AND NOT m.IsPrivate\n AND EXISTS (SELECT 1 FROM ${this._hierarchyConfig.elementClassSpecification} WHERE Model.Id = m.ECInstanceId)\n ) targetPartitionId,\n CASE\n WHEN (\n json_extract(s.JsonProperties, '$.Subject.Job.Bridge') IS NOT NULL\n OR json_extract(s.JsonProperties, '$.Subject.Model.Type') = 'Hierarchy'\n ) THEN 1\n ELSE 0\n END hideInHierarchy\n FROM bis.Subject s\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: subjectsQuery }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { id: row.id, parentId: row.parentId, targetPartitionId: row.targetPartitionId, hideInHierarchy: !!row.hideInHierarchy };\n }\n }\n\n private async *queryModels(): AsyncIterableIterator<{ id: ModelId; parentId: SubjectId }> {\n const modelsQuery = `\n SELECT p.ECInstanceId id, p.Parent.Id parentId\n FROM ${INFORMATION_PARTITION_ELEMENT_CLASS_NAME} p\n INNER JOIN ${GEOMETRIC_MODEL_3D_CLASS_NAME} m ON m.ModeledElement.Id = p.ECInstanceId\n WHERE\n NOT m.IsPrivate\n ${this._hierarchyConfig.showEmptyModels ? \"\" : `AND EXISTS (SELECT 1 FROM ${this._hierarchyConfig.elementClassSpecification} WHERE Model.Id = m.ECInstanceId)`}\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: modelsQuery }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { id: row.id, parentId: row.parentId };\n }\n }\n\n private async getSubjectInfos() {\n this._subjectInfos ??= (async () => {\n const [subjectInfos, targetPartitionSubjects] = await Promise.all([\n (async () => {\n const result = new Map<SubjectId, SubjectInfo>();\n for await (const subject of this.querySubjects()) {\n const subjectInfo: SubjectInfo = {\n parentSubjectId: subject.parentId,\n hideInHierarchy: subject.hideInHierarchy,\n childSubjectIds: new Set(),\n childModelIds: new Set(),\n };\n if (subject.targetPartitionId) {\n subjectInfo.childModelIds.add(subject.targetPartitionId);\n }\n result.set(subject.id, subjectInfo);\n }\n return result;\n })(),\n (async () => {\n const result = new Map<ModelId, Set<SubjectId>>();\n for await (const model of this.queryModels()) {\n pushToMap(result, model.id, model.parentId);\n }\n return result;\n })(),\n ]);\n\n for (const [subjectId, { parentSubjectId }] of subjectInfos.entries()) {\n if (parentSubjectId) {\n const parentSubjectInfo = subjectInfos.get(parentSubjectId);\n assert(!!parentSubjectInfo);\n parentSubjectInfo.childSubjectIds.add(subjectId);\n }\n }\n\n for (const [partitionId, subjectIds] of targetPartitionSubjects) {\n subjectIds.forEach((subjectId) => {\n const subjectInfo = subjectInfos.get(subjectId);\n assert(!!subjectInfo);\n subjectInfo.childModelIds.add(partitionId);\n });\n }\n\n return subjectInfos;\n })();\n return this._subjectInfos;\n }\n\n /** Returns ECInstanceIDs of Subjects that either have direct Model or at least one child Subject with a Model. */\n public async getParentSubjectIds(): Promise<Id64Array> {\n this._parentSubjectIds ??= (async () => {\n const subjectInfos = await this.getSubjectInfos();\n const parentSubjectIds = new Set<SubjectId>();\n subjectInfos.forEach((subjectInfo, subjectId) => {\n if (subjectInfo.childModelIds.size > 0) {\n parentSubjectIds.add(subjectId);\n let currParentId = subjectInfo.parentSubjectId;\n while (currParentId) {\n parentSubjectIds.add(currParentId);\n currParentId = subjectInfos.get(currParentId)?.parentSubjectId;\n }\n }\n });\n return [...parentSubjectIds];\n })();\n return this._parentSubjectIds;\n }\n\n /**\n * Returns child subjects of the specified parent subjects as they're displayed in the hierarchy - taking into\n * account `hideInHierarchy` flag.\n */\n public async getChildSubjectIds(parentSubjectIds: Id64Array): Promise<Id64Array> {\n const childSubjectIds = new Array<SubjectId>();\n const subjectInfos = await this.getSubjectInfos();\n parentSubjectIds.forEach((subjectId) => {\n forEachChildSubject(subjectInfos, subjectId, (childSubjectId, childSubjectInfo) => {\n if (!childSubjectInfo.hideInHierarchy) {\n childSubjectIds.push(childSubjectId);\n return \"break\";\n }\n return \"continue\";\n });\n });\n return childSubjectIds;\n }\n\n /** Returns ECInstanceIDs of all Models under specific parent Subjects, including their child Subjects, etc. */\n public async getSubjectModelIds(subjectIds: Id64Array): Promise<Id64Array> {\n const subjectInfos = await this.getSubjectInfos();\n const subjectStack = [...subjectIds];\n const result = new Array<ModelId>();\n while (true) {\n const subjectId = subjectStack.pop();\n if (subjectId === undefined) {\n break;\n }\n const subjectInfo = subjectInfos.get(subjectId);\n if (!subjectInfo) {\n continue;\n }\n result.push(...subjectInfo.childModelIds);\n subjectStack.push(...subjectInfo.childSubjectIds);\n }\n return result;\n }\n\n /** Returns ECInstanceIDs of Models under specific parent Subjects as they are displayed in the hierarchy. */\n public async getChildSubjectModelIds(parentSubjectIds: Id64Array): Promise<Id64Array> {\n const subjectInfos = await this.getSubjectInfos();\n\n const hiddenSubjectIds = new Array<SubjectId>();\n parentSubjectIds.forEach((subjectId) => {\n forEachChildSubject(subjectInfos, subjectId, (childSubjectId, childSubjectInfo) => {\n if (childSubjectInfo.hideInHierarchy) {\n hiddenSubjectIds.push(childSubjectId);\n return \"continue\";\n }\n return \"break\";\n });\n });\n\n const modelIds = new Array<ModelId>();\n [...parentSubjectIds, ...hiddenSubjectIds].forEach((subjectId) => {\n const subjectInfo = subjectInfos.get(subjectId);\n subjectInfo && modelIds.push(...subjectInfo.childModelIds);\n });\n return modelIds;\n }\n\n public async createSubjectInstanceKeysPath(targetSubjectId: Id64String): Promise<HierarchyNodeIdentifiersPath> {\n let entry = this._subjectKeyPaths.get(targetSubjectId);\n if (!entry) {\n entry = (async () => {\n const subjectInfos = await this.getSubjectInfos();\n const result = new Array<InstanceKey>();\n let currParentId: SubjectId | undefined = targetSubjectId;\n while (currParentId) {\n if (this._hierarchyConfig.hideRootSubject && currParentId === IModel.rootSubjectId) {\n break;\n }\n const parentInfo = subjectInfos.get(currParentId);\n if (!parentInfo?.hideInHierarchy) {\n result.push({ className: SUBJECT_CLASS_NAME, id: currParentId });\n }\n currParentId = parentInfo?.parentSubjectId;\n }\n return result.reverse();\n })();\n this._subjectKeyPaths.set(targetSubjectId, entry);\n }\n return entry;\n }\n\n private async *queryModelElementCounts(): AsyncIterableIterator<{ modelId: Id64String; elementCount: number }> {\n const query = `\n SELECT Model.Id modelId, COUNT(*) elementCount\n FROM ${this._hierarchyConfig.elementClassSpecification}\n GROUP BY Model.Id\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: query }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { modelId: row.modelId, elementCount: row.elementCount };\n }\n }\n\n private async *queryModelCategories(): AsyncIterableIterator<{ modelId: Id64String; categoryId: Id64String; isModelPrivate: boolean }> {\n const query = `\n SELECT this.Model.Id modelId, this.Category.Id categoryId, m.IsPrivate isModelPrivate\n FROM ${MODEL_CLASS_NAME} m\n JOIN ${this._hierarchyConfig.elementClassSpecification} 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({ ecsql: query }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { modelId: row.modelId, categoryId: row.categoryId, isModelPrivate: !!row.isModelPrivate };\n }\n }\n\n private async *queryModeledElements(): AsyncIterableIterator<{ modelId: Id64String; categoryId: Id64String; modeledElementId: Id64String }> {\n const query = `\n SELECT\n pe.ECInstanceId modeledElementId,\n pe.Category.Id categoryId,\n pe.Model.Id modelId\n FROM ${MODEL_CLASS_NAME} m\n JOIN ${this._hierarchyConfig.elementClassSpecification} pe ON pe.ECInstanceId = m.ModeledElement.Id\n WHERE\n m.IsPrivate = false\n AND m.ECInstanceId IN (SELECT Model.Id FROM ${this._hierarchyConfig.elementClassSpecification})\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: query }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { modelId: row.modelId, categoryId: row.categoryId, modeledElementId: row.modeledElementId };\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 private async getModelInfos() {\n this._modelInfos ??= (async () => {\n const modelInfos = new Map<ModelId, { categoryIds: Id64Set; elementCount: number; isModelPrivate: boolean }>();\n await Promise.all([\n (async () => {\n for await (const { modelId, categoryId, isModelPrivate } of this.queryModelCategories()) {\n const entry = modelInfos.get(modelId);\n if (entry) {\n entry.categoryIds.add(categoryId);\n entry.isModelPrivate = isModelPrivate;\n } else {\n modelInfos.set(modelId, { categoryIds: new Set([categoryId]), elementCount: 0, isModelPrivate });\n }\n }\n })(),\n (async () => {\n for await (const { modelId, elementCount } of this.queryModelElementCounts()) {\n const entry = modelInfos.get(modelId);\n if (entry) {\n entry.elementCount = elementCount;\n } else {\n modelInfos.set(modelId, { categoryIds: new Set(), elementCount, isModelPrivate: false });\n }\n }\n })(),\n ]);\n return modelInfos;\n })();\n return this._modelInfos;\n }\n\n public async getModelCategoryIds(modelId: Id64String): Promise<Id64Array> {\n const modelInfos = await this.getModelInfos();\n const categories = modelInfos.get(modelId)?.categoryIds;\n return categories ? [...categories] : [];\n }\n\n public async getModelElementCount(modelId: Id64String): Promise<number> {\n const modelInfos = await this.getModelInfos();\n return modelInfos.get(modelId)?.elementCount ?? 0;\n }\n\n public async hasSubModel(elementId: Id64String): Promise<boolean> {\n const modelInfos = await this.getModelInfos();\n const modeledElementInfo = modelInfos.get(elementId);\n if (!modeledElementInfo) {\n return false;\n }\n return !modeledElementInfo.isModelPrivate;\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 public async createModelInstanceKeyPaths(modelId: Id64String): Promise<HierarchyNodeIdentifiersPath[]> {\n let entry = this._modelKeyPaths.get(modelId);\n if (!entry) {\n entry = (async () => {\n const result = new Array<HierarchyNodeIdentifiersPath>();\n const subjectInfos = (await this.getSubjectInfos()).entries();\n for (const [modelSubjectId, subjectInfo] of subjectInfos) {\n if (subjectInfo.childModelIds.has(modelId)) {\n const subjectPath = await this.createSubjectInstanceKeysPath(modelSubjectId);\n result.push([...subjectPath, { className: \"BisCore.GeometricModel3d\", id: modelId }]);\n }\n }\n return result;\n })();\n\n this._modelKeyPaths.set(modelId, entry);\n }\n return entry;\n }\n\n public async getCategoryElementsCount(modelId: Id64String, categoryId: Id64String): Promise<number> {\n return this._categoryElementCounts.getCategoryElementsCount(modelId, categoryId);\n }\n\n public async createCategoryInstanceKeyPaths(categoryId: Id64String): Promise<HierarchyNodeIdentifiersPath[]> {\n let entry = this._categoryKeyPaths.get(categoryId);\n if (!entry) {\n entry = (async () => {\n const result = new Set<ModelId>();\n const modelInfos = await this.getModelInfos();\n modelInfos?.forEach((modelInfo, modelId) => {\n if (modelInfo.categoryIds.has(categoryId)) {\n result.add(modelId);\n }\n });\n\n const categoryPaths = new Array<HierarchyNodeIdentifiersPath>();\n for (const categoryModelId of [...result]) {\n const modelPaths = await this.createModelInstanceKeyPaths(categoryModelId);\n for (const modelPath of modelPaths) {\n categoryPaths.push([...modelPath, { className: SPATIAL_CATEGORY_CLASS_NAME, id: categoryId }]);\n }\n }\n return categoryPaths;\n })();\n this._categoryKeyPaths.set(categoryId, entry);\n }\n return entry;\n }\n}\n\nfunction forEachChildSubject(\n subjectInfos: Map<SubjectId, SubjectInfo>,\n parentSubject: SubjectId | SubjectInfo,\n cb: (childSubjectId: SubjectId, childSubjectInfo: SubjectInfo) => \"break\" | \"continue\",\n) {\n const parentSubjectInfo = typeof parentSubject === \"string\" ? subjectInfos.get(parentSubject) : parentSubject;\n parentSubjectInfo &&\n parentSubjectInfo.childSubjectIds.forEach((childSubjectId) => {\n const childSubjectInfo = subjectInfos.get(childSubjectId)!;\n if (cb(childSubjectId, childSubjectInfo) === \"break\") {\n return;\n }\n forEachChildSubject(subjectInfos, childSubjectInfo, cb);\n });\n}\n"]}
@@ -77,31 +77,5 @@ export interface ModelsTreeVisibilityHandlerProps {
77
77
  * @internal
78
78
  */
79
79
  export declare function createModelsTreeVisibilityHandler(props: ModelsTreeVisibilityHandlerProps): HierarchyVisibilityHandler & Disposable;
80
- /**
81
- * Enables display of all given models. Also enables display of all categories and clears always and
82
- * never drawn lists in the viewport.
83
- * @public
84
- */
85
- export declare function showAllModels(models: string[], viewport: Viewport): Promise<void>;
86
- /**
87
- * Disables display of all given models.
88
- * @public
89
- */
90
- export declare function hideAllModels(models: string[], viewport: Viewport): Promise<void>;
91
- /**
92
- * Inverts display of all given models.
93
- * @public
94
- */
95
- export declare function invertAllModels(models: string[], viewport: Viewport): Promise<void>;
96
- /**
97
- * Based on the value of `enable` argument, either enables or disables display of given models.
98
- * @public
99
- */
100
- export declare function toggleModels(models: string[], enable: boolean, viewport: Viewport): Promise<void>;
101
- /**
102
- * Checks if all given models are displayed in given viewport.
103
- * @public
104
- */
105
- export declare function areAllModelsVisible(models: string[], viewport: Viewport): boolean;
106
80
  export {};
107
81
  //# sourceMappingURL=ModelsTreeVisibilityHandler.d.ts.map