@itwin/tree-widget-react 3.16.1 → 3.17.1

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 (142) hide show
  1. package/CHANGELOG.md +24 -2
  2. package/lib/cjs/tree-widget-react/components/SelectableTree.js.map +1 -1
  3. package/lib/cjs/tree-widget-react/components/TreeSelector.js.map +1 -1
  4. package/lib/cjs/tree-widget-react/components/TreeWidgetUiItemsProvider.js +1 -1
  5. package/lib/cjs/tree-widget-react/components/TreeWidgetUiItemsProvider.js.map +1 -1
  6. package/lib/cjs/tree-widget-react/components/tree-header/TreeHeader.js.map +1 -1
  7. package/lib/cjs/tree-widget-react/components/tree-header/TreeWithHeader.js.map +1 -1
  8. package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTree.d.ts +2 -2
  9. package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTree.js +2 -1
  10. package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTree.js.map +1 -1
  11. package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js.map +1 -1
  12. package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTreeComponent.d.ts +1 -1
  13. package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTreeComponent.js.map +1 -1
  14. package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.d.ts +13 -0
  15. package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js +92 -74
  16. package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js.map +1 -1
  17. package/lib/cjs/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.d.ts +3 -1
  18. package/lib/cjs/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js +21 -8
  19. package/lib/cjs/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js.map +1 -1
  20. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.d.ts +21 -9
  21. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js +300 -251
  22. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js.map +1 -1
  23. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.d.ts +2 -0
  24. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js +66 -107
  25. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js.map +1 -1
  26. package/lib/cjs/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js +22 -12
  27. package/lib/cjs/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js.map +1 -1
  28. package/lib/cjs/tree-widget-react/components/trees/common/UseActiveViewport.js.map +1 -1
  29. package/lib/cjs/tree-widget-react/components/trees/common/UseHierarchyVisibility.js.map +1 -1
  30. package/lib/cjs/tree-widget-react/components/trees/common/components/ProgressOverlay.js.map +1 -1
  31. package/lib/cjs/tree-widget-react/components/trees/common/components/Tree.d.ts +2 -2
  32. package/lib/cjs/tree-widget-react/components/trees/common/components/Tree.js.map +1 -1
  33. package/lib/cjs/tree-widget-react/components/trees/common/components/TreeNodeCheckbox.d.ts +1 -1
  34. package/lib/cjs/tree-widget-react/components/trees/common/components/TreeNodeCheckbox.js.map +1 -1
  35. package/lib/cjs/tree-widget-react/components/trees/common/components/TreeRenderer.d.ts +1 -1
  36. package/lib/cjs/tree-widget-react/components/trees/common/components/TreeRenderer.js +2 -2
  37. package/lib/cjs/tree-widget-react/components/trees/common/components/TreeRenderer.js.map +1 -1
  38. package/lib/cjs/tree-widget-react/components/trees/common/components/VisibilityTree.d.ts +3 -3
  39. package/lib/cjs/tree-widget-react/components/trees/common/components/VisibilityTree.js.map +1 -1
  40. package/lib/cjs/tree-widget-react/components/trees/common/components/VisibilityTreeRenderer.d.ts +1 -1
  41. package/lib/cjs/tree-widget-react/components/trees/common/components/VisibilityTreeRenderer.js.map +1 -1
  42. package/lib/cjs/tree-widget-react/components/trees/common/internal/Utils.d.ts +25 -0
  43. package/lib/cjs/tree-widget-react/components/trees/common/internal/Utils.js +83 -0
  44. package/lib/cjs/tree-widget-react/components/trees/common/internal/Utils.js.map +1 -0
  45. package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTree.d.ts +1 -1
  46. package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTree.js.map +1 -1
  47. package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js.map +1 -1
  48. package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
  49. package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.d.ts +1 -0
  50. package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js +86 -28
  51. package/lib/cjs/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js.map +1 -1
  52. package/lib/cjs/tree-widget-react/components/trees/models-tree/UseModelsTree.js +2 -1
  53. package/lib/cjs/tree-widget-react/components/trees/models-tree/UseModelsTree.js.map +1 -1
  54. package/lib/cjs/tree-widget-react/components/trees/models-tree/Utils.d.ts +5 -6
  55. package/lib/cjs/tree-widget-react/components/trees/models-tree/Utils.js +5 -17
  56. package/lib/cjs/tree-widget-react/components/trees/models-tree/Utils.js.map +1 -1
  57. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.js +5 -4
  58. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.js.map +1 -1
  59. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/FilteredTree.d.ts +7 -1
  60. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/FilteredTree.js +52 -0
  61. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/FilteredTree.js.map +1 -1
  62. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.d.ts +28 -12
  63. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js +382 -278
  64. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js.map +1 -1
  65. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeNode.d.ts +1 -1
  66. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeNode.js.map +1 -1
  67. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js +272 -139
  68. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
  69. package/lib/cjs/tree-widget-react-internal.d.ts +2 -1
  70. package/lib/cjs/tree-widget-react-internal.js +4 -1
  71. package/lib/cjs/tree-widget-react-internal.js.map +1 -1
  72. package/lib/esm/tree-widget-react/components/SelectableTree.js.map +1 -1
  73. package/lib/esm/tree-widget-react/components/TreeSelector.js.map +1 -1
  74. package/lib/esm/tree-widget-react/components/TreeWidgetUiItemsProvider.js +1 -1
  75. package/lib/esm/tree-widget-react/components/TreeWidgetUiItemsProvider.js.map +1 -1
  76. package/lib/esm/tree-widget-react/components/tree-header/TreeHeader.js.map +1 -1
  77. package/lib/esm/tree-widget-react/components/tree-header/TreeWithHeader.js.map +1 -1
  78. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTree.d.ts +2 -2
  79. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTree.js +2 -1
  80. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTree.js.map +1 -1
  81. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js.map +1 -1
  82. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeComponent.d.ts +1 -1
  83. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeComponent.js.map +1 -1
  84. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.d.ts +13 -0
  85. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js +92 -74
  86. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js.map +1 -1
  87. package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.d.ts +3 -1
  88. package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js +22 -9
  89. package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js.map +1 -1
  90. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.d.ts +21 -9
  91. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js +301 -252
  92. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js.map +1 -1
  93. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.d.ts +2 -0
  94. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js +67 -108
  95. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js.map +1 -1
  96. package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js +23 -13
  97. package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js.map +1 -1
  98. package/lib/esm/tree-widget-react/components/trees/common/UseActiveViewport.js.map +1 -1
  99. package/lib/esm/tree-widget-react/components/trees/common/UseHierarchyVisibility.js.map +1 -1
  100. package/lib/esm/tree-widget-react/components/trees/common/components/ProgressOverlay.js.map +1 -1
  101. package/lib/esm/tree-widget-react/components/trees/common/components/Tree.d.ts +2 -2
  102. package/lib/esm/tree-widget-react/components/trees/common/components/Tree.js.map +1 -1
  103. package/lib/esm/tree-widget-react/components/trees/common/components/TreeNodeCheckbox.d.ts +1 -1
  104. package/lib/esm/tree-widget-react/components/trees/common/components/TreeNodeCheckbox.js.map +1 -1
  105. package/lib/esm/tree-widget-react/components/trees/common/components/TreeRenderer.d.ts +1 -1
  106. package/lib/esm/tree-widget-react/components/trees/common/components/TreeRenderer.js +2 -2
  107. package/lib/esm/tree-widget-react/components/trees/common/components/TreeRenderer.js.map +1 -1
  108. package/lib/esm/tree-widget-react/components/trees/common/components/VisibilityTree.d.ts +3 -3
  109. package/lib/esm/tree-widget-react/components/trees/common/components/VisibilityTree.js.map +1 -1
  110. package/lib/esm/tree-widget-react/components/trees/common/components/VisibilityTreeRenderer.d.ts +1 -1
  111. package/lib/esm/tree-widget-react/components/trees/common/components/VisibilityTreeRenderer.js.map +1 -1
  112. package/lib/esm/tree-widget-react/components/trees/common/internal/Utils.d.ts +25 -0
  113. package/lib/esm/tree-widget-react/components/trees/common/internal/Utils.js +74 -0
  114. package/lib/esm/tree-widget-react/components/trees/common/internal/Utils.js.map +1 -0
  115. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTree.d.ts +1 -1
  116. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTree.js.map +1 -1
  117. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js.map +1 -1
  118. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
  119. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.d.ts +1 -0
  120. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js +83 -25
  121. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js.map +1 -1
  122. package/lib/esm/tree-widget-react/components/trees/models-tree/UseModelsTree.js +2 -1
  123. package/lib/esm/tree-widget-react/components/trees/models-tree/UseModelsTree.js.map +1 -1
  124. package/lib/esm/tree-widget-react/components/trees/models-tree/Utils.d.ts +5 -6
  125. package/lib/esm/tree-widget-react/components/trees/models-tree/Utils.js +4 -16
  126. package/lib/esm/tree-widget-react/components/trees/models-tree/Utils.js.map +1 -1
  127. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.js +4 -3
  128. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.js.map +1 -1
  129. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/FilteredTree.d.ts +7 -1
  130. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/FilteredTree.js +52 -0
  131. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/FilteredTree.js.map +1 -1
  132. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.d.ts +28 -12
  133. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js +382 -278
  134. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js.map +1 -1
  135. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeNode.d.ts +1 -1
  136. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeNode.js.map +1 -1
  137. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js +257 -124
  138. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
  139. package/lib/esm/tree-widget-react-internal.d.ts +2 -1
  140. package/lib/esm/tree-widget-react-internal.js +2 -1
  141. package/lib/esm/tree-widget-react-internal.js.map +1 -1
  142. package/package.json +1 -1
@@ -6,7 +6,9 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.CategoriesTreeIdsCache = void 0;
8
8
  exports.getClassesByView = getClassesByView;
9
+ const rxjs_1 = require("rxjs");
9
10
  const core_bentley_1 = require("@itwin/core-bentley");
11
+ const Utils_js_1 = require("../../common/internal/Utils.js");
10
12
  const ClassNameDefinitions_js_1 = require("./ClassNameDefinitions.js");
11
13
  /** @internal */
12
14
  class CategoriesTreeIdsCache {
@@ -31,311 +33,355 @@ class CategoriesTreeIdsCache {
31
33
  this.#componentName = "CategoriesTreeIdsCache";
32
34
  }
33
35
  [Symbol.dispose]() { }
34
- async *queryElementModelCategories() {
35
- const query = `
36
- SELECT this.Model.Id modelId, this.Category.Id categoryId
37
- FROM ${this.#categoryModelClass} m
38
- JOIN ${this.#categoryElementClass} this ON m.ECInstanceId = this.Model.Id
39
- WHERE m.IsPrivate = false
40
- GROUP BY modelId, categoryId
41
- `;
42
- for await (const row of this.#queryExecutor.createQueryReader({ ecsql: query }, {
43
- rowFormat: "ECSqlPropertyNames",
44
- limit: "unbounded",
45
- restartToken: `${this.#componentName}/${this.#componentId}/element-models-and-categories`,
46
- })) {
47
- yield { modelId: row.modelId, categoryId: row.categoryId };
48
- }
36
+ queryElementModelCategories() {
37
+ return (0, rxjs_1.defer)(() => {
38
+ const query = `
39
+ SELECT this.Model.Id modelId, this.Category.Id categoryId
40
+ FROM ${this.#categoryModelClass} m
41
+ JOIN ${this.#categoryElementClass} this ON m.ECInstanceId = this.Model.Id
42
+ WHERE m.IsPrivate = false
43
+ GROUP BY modelId, categoryId
44
+ `;
45
+ return this.#queryExecutor.createQueryReader({ ecsql: query }, {
46
+ rowFormat: "ECSqlPropertyNames",
47
+ limit: "unbounded",
48
+ restartToken: `${this.#componentName}/${this.#componentId}/element-models-and-categories`,
49
+ });
50
+ }).pipe((0, rxjs_1.map)((row) => {
51
+ return { modelId: row.modelId, categoryId: row.categoryId };
52
+ }));
49
53
  }
50
- async *queryCategories() {
51
- const isDefinitionContainerSupported = await this.getIsDefinitionContainerSupported();
52
- const categoriesQuery = `
53
- SELECT
54
- this.ECInstanceId id,
55
- COUNT(sc.ECInstanceId) childCount,
56
- this.Model.Id modelId,
57
- ${isDefinitionContainerSupported
58
- ? `
59
- IIF(this.Model.Id IN (SELECT dc.ECInstanceId FROM ${ClassNameDefinitions_js_1.DEFINITION_CONTAINER_CLASS} dc),
60
- true,
61
- false
62
- )`
63
- : "false"} parentDefinitionContainerExists
64
- FROM
65
- ${this.#categoryClass} this
66
- JOIN ${ClassNameDefinitions_js_1.SUB_CATEGORY_CLASS} sc ON sc.Parent.Id = this.ECInstanceId
67
- JOIN BisCore.Model m ON m.ECInstanceId = this.Model.Id
68
- WHERE
69
- NOT this.IsPrivate
70
- AND (NOT m.IsPrivate OR m.ECClassId IS (BisCore.DictionaryModel))
71
- AND EXISTS (SELECT 1 FROM ${this.#categoryElementClass} e WHERE e.Category.Id = this.ECInstanceId)
72
- GROUP BY this.ECInstanceId
73
- `;
74
- for await (const row of this.#queryExecutor.createQueryReader({ ecsql: categoriesQuery }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded", restartToken: `${this.#componentName}/${this.#componentId}/categories` })) {
75
- yield { id: row.id, modelId: row.modelId, parentDefinitionContainerExists: row.parentDefinitionContainerExists, childCount: row.childCount };
76
- }
54
+ queryCategories() {
55
+ return this.getIsDefinitionContainerSupported().pipe((0, rxjs_1.mergeMap)((isDefinitionContainerSupported) => (0, rxjs_1.defer)(() => {
56
+ const categoriesQuery = `
57
+ SELECT
58
+ this.ECInstanceId id,
59
+ COUNT(sc.ECInstanceId) childCount,
60
+ this.Model.Id modelId,
61
+ ${isDefinitionContainerSupported
62
+ ? `
63
+ IIF(this.Model.Id IN (SELECT dc.ECInstanceId FROM ${ClassNameDefinitions_js_1.DEFINITION_CONTAINER_CLASS} dc),
64
+ true,
65
+ false
66
+ )`
67
+ : "false"} parentDefinitionContainerExists,
68
+ IFNULL(
69
+ (SELECT 1 FROM ${this.#categoryElementClass} e WHERE e.Category.Id = this.ECInstanceId LIMIT 1),
70
+ 0
71
+ ) hasElements
72
+ FROM
73
+ ${this.#categoryClass} this
74
+ JOIN ${ClassNameDefinitions_js_1.SUB_CATEGORY_CLASS} sc ON sc.Parent.Id = this.ECInstanceId
75
+ JOIN BisCore.Model m ON m.ECInstanceId = this.Model.Id
76
+ WHERE
77
+ NOT this.IsPrivate
78
+ AND (NOT m.IsPrivate OR m.ECClassId IS (BisCore.DictionaryModel))
79
+ GROUP BY this.ECInstanceId
80
+ `;
81
+ return this.#queryExecutor.createQueryReader({ ecsql: categoriesQuery }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded", restartToken: `${this.#componentName}/${this.#componentId}/categories` });
82
+ }).pipe((0, rxjs_1.map)((row) => {
83
+ return {
84
+ id: row.id,
85
+ modelId: row.modelId,
86
+ parentDefinitionContainerExists: row.parentDefinitionContainerExists,
87
+ childCount: row.childCount,
88
+ hasElements: !!row.hasElements,
89
+ };
90
+ }))));
77
91
  }
78
- async queryIsDefinitionContainersSupported() {
79
- const query = `
80
- SELECT
81
- 1
82
- FROM
83
- ECDbMeta.ECSchemaDef s
84
- JOIN ECDbMeta.ECClassDef c ON c.Schema.Id = s.ECInstanceId
85
- WHERE
86
- s.Name = 'BisCore'
87
- AND c.Name = 'DefinitionContainer'
88
- `;
89
- for await (const _row of this.#queryExecutor.createQueryReader({ ecsql: query }, { restartToken: `${this.#componentName}/${this.#componentId}/is-definition-container-supported` })) {
90
- return true;
91
- }
92
- return false;
92
+ queryIsDefinitionContainersSupported() {
93
+ return (0, rxjs_1.defer)(() => {
94
+ const query = `
95
+ SELECT
96
+ 1
97
+ FROM
98
+ ECDbMeta.ECSchemaDef s
99
+ JOIN ECDbMeta.ECClassDef c ON c.Schema.Id = s.ECInstanceId
100
+ WHERE
101
+ s.Name = 'BisCore'
102
+ AND c.Name = 'DefinitionContainer'
103
+ LIMIT 1
104
+ `;
105
+ return this.#queryExecutor.createQueryReader({ ecsql: query }, { restartToken: `${this.#componentName}/${this.#componentId}/is-definition-container-supported` });
106
+ }).pipe((0, rxjs_1.toArray)(), (0, rxjs_1.map)((rows) => rows.length > 0));
93
107
  }
94
- async *queryDefinitionContainers() {
95
- // DefinitionModel ECInstanceId will always be the same as modeled DefinitionContainer ECInstanceId, if this wasn't the case, we would need to do something like:
96
- // JOIN BisCore.DefinitionModel dm ON dm.ECInstanceId = ${modelIdAccessor}
97
- // JOIN BisCore.DefinitionModelBreaksDownDefinitionContainer dr ON dr.SourceECInstanceId = dm.ECInstanceId
98
- // JOIN BisCore.DefinitionContainer dc ON dc.ECInstanceId = dr.TargetECInstanceId
99
- const DEFINITION_CONTAINERS_CTE = "DefinitionContainers";
100
- const ctes = [
101
- `
102
- ${DEFINITION_CONTAINERS_CTE}(ECInstanceId, ModelId) AS (
108
+ queryDefinitionContainers() {
109
+ return (0, rxjs_1.defer)(() => {
110
+ // DefinitionModel ECInstanceId will always be the same as modeled DefinitionContainer ECInstanceId, if this wasn't the case, we would need to do something like:
111
+ // JOIN BisCore.DefinitionModel dm ON dm.ECInstanceId = ${modelIdAccessor}
112
+ // JOIN BisCore.DefinitionModelBreaksDownDefinitionContainer dr ON dr.SourceECInstanceId = dm.ECInstanceId
113
+ // JOIN BisCore.DefinitionContainer dc ON dc.ECInstanceId = dr.TargetECInstanceId
114
+ const DEFINITION_CONTAINERS_CTE = "DefinitionContainers";
115
+ const CATEGORIES_MODELS_CTE = "CategoriesModels";
116
+ const ctes = [
117
+ `${CATEGORIES_MODELS_CTE}(ModelId, HasElements) AS (
103
118
  SELECT
104
- dc.ECInstanceId,
105
- dc.Model.Id
119
+ c.Model.Id,
120
+ IFNULL((
121
+ SELECT 1
122
+ FROM ${this.#categoryElementClass} e
123
+ WHERE e.Category.Id = c.ECInstanceId
124
+ LIMIT 1
125
+ ), 0)
106
126
  FROM
107
- ${ClassNameDefinitions_js_1.DEFINITION_CONTAINER_CLASS} dc
127
+ ${this.#categoryClass} c
108
128
  WHERE
109
- 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))
110
- AND NOT dc.IsPrivate
129
+ NOT c.IsPrivate
130
+ )`,
131
+ `
132
+ ${DEFINITION_CONTAINERS_CTE}(ECInstanceId, ModelId, HasElements) AS (
133
+ SELECT
134
+ dc.ECInstanceId,
135
+ dc.Model.Id,
136
+ c.HasElements
137
+ FROM ${ClassNameDefinitions_js_1.DEFINITION_CONTAINER_CLASS} dc
138
+ JOIN ${CATEGORIES_MODELS_CTE} c ON dc.ECInstanceId = c.ModelId
139
+ WHERE NOT dc.IsPrivate
111
140
 
112
- UNION ALL
141
+ UNION ALL
113
142
 
114
- SELECT
115
- pdc.ECInstanceId,
116
- pdc.Model.Id
117
- FROM
118
- ${DEFINITION_CONTAINERS_CTE} cdc
119
- JOIN ${ClassNameDefinitions_js_1.DEFINITION_CONTAINER_CLASS} pdc ON pdc.ECInstanceId = cdc.ModelId
120
- WHERE
121
- NOT pdc.IsPrivate
122
- )
123
- `,
124
- ];
125
- const definitionsQuery = `
126
- SELECT dc.ECInstanceId id, dc.ModelId modelId FROM ${DEFINITION_CONTAINERS_CTE} dc GROUP BY dc.ECInstanceId
127
- `;
128
- for await (const row of this.#queryExecutor.createQueryReader({ ctes, ecsql: definitionsQuery }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded", restartToken: `${this.#componentName}/${this.#componentId}/definition-containers` })) {
129
- yield { id: row.id, modelId: row.modelId };
130
- }
143
+ SELECT
144
+ pdc.ECInstanceId,
145
+ pdc.Model.Id,
146
+ cdc.HasElements
147
+ FROM
148
+ ${DEFINITION_CONTAINERS_CTE} cdc
149
+ JOIN ${ClassNameDefinitions_js_1.DEFINITION_CONTAINER_CLASS} pdc ON pdc.ECInstanceId = cdc.ModelId
150
+ WHERE NOT pdc.IsPrivate
151
+ )
152
+ `,
153
+ ];
154
+ const definitionsQuery = `
155
+ SELECT dc.ECInstanceId id, dc.ModelId modelId, MAX(dc.HasElements) hasElements FROM ${DEFINITION_CONTAINERS_CTE} dc GROUP BY dc.ECInstanceId
156
+ `;
157
+ return this.#queryExecutor.createQueryReader({ ctes, ecsql: definitionsQuery }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded", restartToken: `${this.#componentName}/${this.#componentId}/definition-containers` });
158
+ }).pipe((0, rxjs_1.map)((row) => {
159
+ return { id: row.id, modelId: row.modelId, hasElements: !!row.hasElements };
160
+ }));
131
161
  }
132
- async *queryVisibleSubCategories(categoriesInfo) {
133
- const definitionsQuery = `
134
- SELECT
135
- sc.ECInstanceId id,
136
- sc.Parent.Id categoryId
137
- FROM
138
- ${ClassNameDefinitions_js_1.SUB_CATEGORY_CLASS} sc
139
- WHERE
140
- NOT sc.IsPrivate
141
- AND sc.Parent.Id IN (${categoriesInfo.join(",")})
142
- `;
143
- for await (const row of this.#queryExecutor.createQueryReader({ ecsql: definitionsQuery }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded", restartToken: `${this.#componentName}/${this.#componentId}/visible-sub-categories` })) {
144
- yield { id: row.id, parentId: row.categoryId };
145
- }
162
+ queryVisibleSubCategories(categoriesInfo) {
163
+ return (0, rxjs_1.defer)(() => {
164
+ const definitionsQuery = `
165
+ SELECT
166
+ sc.ECInstanceId id,
167
+ sc.Parent.Id categoryId
168
+ FROM
169
+ ${ClassNameDefinitions_js_1.SUB_CATEGORY_CLASS} sc
170
+ WHERE
171
+ NOT sc.IsPrivate
172
+ AND sc.Parent.Id IN (${categoriesInfo.join(",")})
173
+ `;
174
+ return this.#queryExecutor.createQueryReader({ ecsql: definitionsQuery }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded", restartToken: `${this.#componentName}/${this.#componentId}/visible-sub-categories` });
175
+ }).pipe((0, rxjs_1.map)((row) => {
176
+ return { id: row.id, parentId: row.categoryId };
177
+ }));
146
178
  }
147
- async getModelsCategoriesInfo() {
148
- this.#modelsCategoriesInfo ??= (async () => {
149
- const allModelsCategories = new Map();
150
- for await (const queriedCategory of this.queryCategories()) {
151
- let modelCategories = allModelsCategories.get(queriedCategory.modelId);
152
- if (modelCategories === undefined) {
153
- modelCategories = { parentDefinitionContainerExists: queriedCategory.parentDefinitionContainerExists, childCategories: [] };
154
- allModelsCategories.set(queriedCategory.modelId, modelCategories);
155
- }
156
- modelCategories.childCategories.push({ id: queriedCategory.id, childCount: queriedCategory.childCount });
179
+ getModelsCategoriesInfo() {
180
+ this.#modelsCategoriesInfo ??= this.queryCategories()
181
+ .pipe((0, rxjs_1.reduce)((acc, queriedCategory) => {
182
+ let modelCategories = acc.get(queriedCategory.modelId);
183
+ if (modelCategories === undefined) {
184
+ modelCategories = { parentDefinitionContainerExists: queriedCategory.parentDefinitionContainerExists, childCategories: [] };
185
+ acc.set(queriedCategory.modelId, modelCategories);
157
186
  }
158
- return allModelsCategories;
159
- })();
187
+ modelCategories.childCategories.push({ id: queriedCategory.id, childCount: queriedCategory.childCount, hasElements: queriedCategory.hasElements });
188
+ return acc;
189
+ }, new Map()))
190
+ .pipe((0, rxjs_1.shareReplay)());
160
191
  return this.#modelsCategoriesInfo;
161
192
  }
162
- async getElementModelsCategories() {
163
- this.#elementModelsCategories ??= (async () => {
164
- const elementModelsCategories = new Map();
165
- for await (const queriedCategory of this.queryElementModelCategories()) {
166
- let modelEntry = elementModelsCategories.get(queriedCategory.modelId);
167
- if (modelEntry === undefined) {
168
- modelEntry = new Set();
169
- elementModelsCategories.set(queriedCategory.modelId, modelEntry);
170
- }
171
- modelEntry.add(queriedCategory.categoryId);
193
+ getElementModelsCategories() {
194
+ this.#elementModelsCategories ??= this.queryElementModelCategories()
195
+ .pipe((0, rxjs_1.reduce)((acc, queriedCategory) => {
196
+ let modelEntry = acc.get(queriedCategory.modelId);
197
+ if (modelEntry === undefined) {
198
+ modelEntry = new Set();
199
+ acc.set(queriedCategory.modelId, modelEntry);
172
200
  }
173
- return elementModelsCategories;
174
- })();
201
+ modelEntry.add(queriedCategory.categoryId);
202
+ return acc;
203
+ }, new Map()))
204
+ .pipe((0, rxjs_1.shareReplay)());
175
205
  return this.#elementModelsCategories;
176
206
  }
177
- async getSubCategoriesInfo() {
178
- this.#subCategoriesInfo ??= (async () => {
207
+ getSubCategoriesInfo() {
208
+ this.#subCategoriesInfo ??= this.getModelsCategoriesInfo()
209
+ .pipe((0, rxjs_1.mergeMap)((modelsCategoriesInfo) => (0, rxjs_1.from)(modelsCategoriesInfo.values())), (0, rxjs_1.reduce)((acc, modelCategoriesInfo) => {
210
+ acc.push(...modelCategoriesInfo.childCategories.filter((categoryInfo) => categoryInfo.childCount > 1).map((categoryInfo) => categoryInfo.id));
211
+ return acc;
212
+ }, new Array()), (0, rxjs_1.mergeMap)((categoriesWithMoreThanOneSubCategory) => {
179
213
  const allSubCategories = new Map();
180
- const modelsCategoriesInfo = await this.getModelsCategoriesInfo();
181
- const categoriesWithMoreThanOneSubCategory = new Array();
182
- for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {
183
- categoriesWithMoreThanOneSubCategory.push(...modelCategoriesInfo.childCategories.filter((categoryInfo) => categoryInfo.childCount > 1).map((categoryInfo) => categoryInfo.id));
184
- }
185
214
  if (categoriesWithMoreThanOneSubCategory.length === 0) {
186
- return allSubCategories;
187
- }
188
- for await (const queriedSubCategory of this.queryVisibleSubCategories(categoriesWithMoreThanOneSubCategory)) {
189
- allSubCategories.set(queriedSubCategory.id, { categoryId: queriedSubCategory.parentId });
215
+ return (0, rxjs_1.of)(allSubCategories);
190
216
  }
191
- return allSubCategories;
192
- })();
217
+ return this.queryVisibleSubCategories(categoriesWithMoreThanOneSubCategory).pipe((0, rxjs_1.reduce)((acc, queriedSubCategory) => {
218
+ const entry = acc.get(queriedSubCategory.parentId);
219
+ if (!entry) {
220
+ acc.set(queriedSubCategory.parentId, new Set([queriedSubCategory.id]));
221
+ return acc;
222
+ }
223
+ entry.add(queriedSubCategory.id);
224
+ return acc;
225
+ }, allSubCategories));
226
+ }))
227
+ .pipe((0, rxjs_1.shareReplay)());
193
228
  return this.#subCategoriesInfo;
194
229
  }
195
- async getDefinitionContainersInfo() {
196
- this.#definitionContainersInfo ??= (async () => {
230
+ getDefinitionContainersInfo() {
231
+ this.#definitionContainersInfo ??= (0, rxjs_1.forkJoin)({
232
+ isDefinitionContainerSupported: this.getIsDefinitionContainerSupported(),
233
+ modelsCategoriesInfo: this.getModelsCategoriesInfo(),
234
+ })
235
+ .pipe((0, rxjs_1.mergeMap)(({ isDefinitionContainerSupported, modelsCategoriesInfo }) => {
197
236
  const definitionContainersInfo = new Map();
198
- const [isDefinitionContainerSupported, modelsCategoriesInfo] = await Promise.all([
199
- this.getIsDefinitionContainerSupported(),
200
- this.getModelsCategoriesInfo(),
201
- ]);
202
237
  if (!isDefinitionContainerSupported || modelsCategoriesInfo.size === 0) {
203
- return definitionContainersInfo;
238
+ return (0, rxjs_1.of)(definitionContainersInfo);
204
239
  }
205
- for await (const queriedDefinitionContainer of this.queryDefinitionContainers()) {
240
+ return this.queryDefinitionContainers().pipe((0, rxjs_1.reduce)((acc, queriedDefinitionContainer) => {
206
241
  const modelCategoriesInfo = modelsCategoriesInfo.get(queriedDefinitionContainer.id);
207
- definitionContainersInfo.set(queriedDefinitionContainer.id, {
242
+ acc.set(queriedDefinitionContainer.id, {
208
243
  childCategories: modelCategoriesInfo?.childCategories ?? [],
209
244
  modelId: queriedDefinitionContainer.modelId,
210
245
  childDefinitionContainers: [],
211
246
  parentDefinitionContainerExists: false,
247
+ hasElements: queriedDefinitionContainer.hasElements,
212
248
  });
213
- }
214
- for (const [definitionContainerId, definitionContainerInfo] of definitionContainersInfo) {
215
- const parentDefinitionContainer = definitionContainersInfo.get(definitionContainerInfo.modelId);
216
- if (parentDefinitionContainer !== undefined) {
217
- parentDefinitionContainer.childDefinitionContainers.push(definitionContainerId);
218
- definitionContainerInfo.parentDefinitionContainerExists = true;
249
+ return acc;
250
+ }, definitionContainersInfo), (0, rxjs_1.map)((result) => {
251
+ for (const [definitionContainerId, definitionContainerInfo] of result) {
252
+ const parentDefinitionContainer = result.get(definitionContainerInfo.modelId);
253
+ if (parentDefinitionContainer !== undefined) {
254
+ parentDefinitionContainer.childDefinitionContainers.push({ id: definitionContainerId, hasElements: definitionContainerInfo.hasElements });
255
+ definitionContainerInfo.parentDefinitionContainerExists = true;
256
+ parentDefinitionContainer.hasElements = parentDefinitionContainer.hasElements || definitionContainerInfo.hasElements;
257
+ }
219
258
  }
220
- }
221
- return definitionContainersInfo;
222
- })();
259
+ return result;
260
+ }));
261
+ }))
262
+ .pipe((0, rxjs_1.shareReplay)());
223
263
  return this.#definitionContainersInfo;
224
264
  }
225
- async getDirectChildDefinitionContainersAndCategories(parentDefinitionContainerIds) {
226
- const definitionContainersInfo = await this.getDefinitionContainersInfo();
227
- const result = { definitionContainers: new Array(), categories: new Array() };
228
- parentDefinitionContainerIds.forEach((parentDefinitionContainerId) => {
265
+ getDirectChildDefinitionContainersAndCategories({ parentDefinitionContainerIds, includeEmpty, }) {
266
+ return this.getDefinitionContainersInfo().pipe((0, rxjs_1.mergeMap)((definitionContainersInfo) => (0, rxjs_1.from)(parentDefinitionContainerIds).pipe((0, rxjs_1.reduce)((acc, parentDefinitionContainerId) => {
229
267
  const parentDefinitionContainerInfo = definitionContainersInfo.get(parentDefinitionContainerId);
230
268
  if (parentDefinitionContainerInfo !== undefined) {
231
- result.definitionContainers.push(...parentDefinitionContainerInfo.childDefinitionContainers);
232
- result.categories.push(...parentDefinitionContainerInfo.childCategories);
269
+ acc.definitionContainers.push(...applyElementsFilter(parentDefinitionContainerInfo.childDefinitionContainers, includeEmpty).map((dc) => dc.id));
270
+ acc.categories.push(...applyElementsFilter(parentDefinitionContainerInfo.childCategories, includeEmpty));
233
271
  }
234
- });
235
- return result;
272
+ return acc;
273
+ }, { definitionContainers: new Array(), categories: new Array() }))));
236
274
  }
237
- async getCategoriesElementModels(categoryIds) {
238
- const elementModelsCategories = await this.getElementModelsCategories();
239
- const result = new Map();
240
- for (const categoryId of categoryIds) {
241
- for (const [modelId, categories] of elementModelsCategories) {
242
- if (categories.has(categoryId)) {
243
- let categoryModels = result.get(categoryId);
244
- if (!categoryModels) {
245
- categoryModels = new Array();
246
- result.set(categoryId, categoryModels);
247
- }
248
- categoryModels.push(modelId);
249
- }
275
+ getCategoriesElementModels(categoryIds) {
276
+ return this.getElementModelsCategories().pipe((0, rxjs_1.mergeMap)((elementModelsCategories) => elementModelsCategories.entries()), (0, rxjs_1.reduce)((acc, [modelId, modelCategoryIds]) => {
277
+ const sharedCategories = (0, Utils_js_1.setIntersection)(core_bentley_1.Id64.iterable(categoryIds), modelCategoryIds);
278
+ if (sharedCategories.size > 0) {
279
+ acc.set(modelId, sharedCategories);
250
280
  }
251
- }
252
- return result;
281
+ return acc;
282
+ }, new Map()));
253
283
  }
254
- async getAllContainedCategories(definitionContainerIds) {
255
- const result = new Array();
256
- const definitionContainersInfo = await this.getDefinitionContainersInfo();
257
- const indirectCategories = await Promise.all(definitionContainerIds.map(async (definitionContainerId) => {
284
+ getAllContainedCategories({ definitionContainerIds, includeEmptyCategories, }) {
285
+ return this.getDefinitionContainersInfo().pipe((0, rxjs_1.mergeMap)((definitionContainersInfo) => (0, rxjs_1.from)(definitionContainerIds).pipe((0, rxjs_1.mergeMap)((definitionContainerId) => {
258
286
  const definitionContainerInfo = definitionContainersInfo.get(definitionContainerId);
259
287
  if (definitionContainerInfo === undefined) {
260
- return [];
288
+ return (0, rxjs_1.of)({ directCategories: undefined, indirectCategories: undefined });
261
289
  }
262
- result.push(...definitionContainerInfo.childCategories.map((category) => category.id));
263
- return this.getAllContainedCategories(definitionContainerInfo.childDefinitionContainers);
264
- }));
265
- for (const categories of indirectCategories) {
266
- result.push(...categories);
267
- }
268
- return result;
290
+ const childDefinitionContainerIds = definitionContainerInfo.childDefinitionContainers.map(({ id }) => id);
291
+ return (childDefinitionContainerIds.length > 0
292
+ ? this.getAllContainedCategories({
293
+ definitionContainerIds: childDefinitionContainerIds,
294
+ includeEmptyCategories,
295
+ })
296
+ : (0, rxjs_1.of)(new Set())).pipe((0, rxjs_1.map)((indirectCategories) => {
297
+ return {
298
+ directCategories: applyElementsFilter(definitionContainerInfo.childCategories, includeEmptyCategories).map((category) => category.id),
299
+ indirectCategories,
300
+ };
301
+ }));
302
+ }), (0, rxjs_1.reduce)((acc, { directCategories, indirectCategories }) => {
303
+ directCategories?.forEach((categoryId) => acc.add(categoryId));
304
+ indirectCategories?.forEach((categoryId) => acc.add(categoryId));
305
+ return acc;
306
+ }, new Set()))));
269
307
  }
270
- async getInstanceKeyPaths(props) {
308
+ getInstanceKeyPaths(props) {
271
309
  if ("subCategoryId" in props) {
272
- const subCategoriesInfo = await this.getSubCategoriesInfo();
273
- const subCategoryInfo = subCategoriesInfo.get(props.subCategoryId);
274
- if (subCategoryInfo === undefined) {
275
- return [];
276
- }
277
- return [...(await this.getInstanceKeyPaths({ categoryId: subCategoryInfo.categoryId })), { id: props.subCategoryId, className: ClassNameDefinitions_js_1.SUB_CATEGORY_CLASS }];
310
+ return this.getSubCategoriesInfo().pipe((0, rxjs_1.mergeMap)((subCategoriesInfo) => {
311
+ let categoryOfSubCategory;
312
+ for (const [categoryId, subCategories] of subCategoriesInfo.entries()) {
313
+ if (subCategories.has(props.subCategoryId)) {
314
+ categoryOfSubCategory = categoryId;
315
+ break;
316
+ }
317
+ }
318
+ if (categoryOfSubCategory === undefined) {
319
+ return (0, rxjs_1.of)([]);
320
+ }
321
+ return this.getInstanceKeyPaths({ categoryId: categoryOfSubCategory }).pipe((0, rxjs_1.map)((pathToCategory) => [...pathToCategory, { id: props.subCategoryId, className: ClassNameDefinitions_js_1.SUB_CATEGORY_CLASS }]));
322
+ }));
278
323
  }
279
324
  if ("categoryId" in props) {
280
- const modelsCategoriesInfo = await this.getModelsCategoriesInfo();
281
- for (const [modelId, modelCategoriesInfo] of modelsCategoriesInfo) {
282
- if (modelCategoriesInfo.childCategories.find((childCategory) => childCategory.id === props.categoryId)) {
283
- if (!modelCategoriesInfo.parentDefinitionContainerExists) {
284
- return [{ id: props.categoryId, className: this.#categoryClass }];
325
+ return this.getModelsCategoriesInfo().pipe((0, rxjs_1.mergeMap)((modelsCategoriesInfo) => {
326
+ for (const [modelId, modelCategoriesInfo] of modelsCategoriesInfo) {
327
+ if (modelCategoriesInfo.childCategories.find((childCategory) => childCategory.id === props.categoryId)) {
328
+ const instanceKey = { id: props.categoryId, className: this.#categoryClass };
329
+ if (!modelCategoriesInfo.parentDefinitionContainerExists) {
330
+ return (0, rxjs_1.of)([instanceKey]);
331
+ }
332
+ return this.getInstanceKeyPaths({ definitionContainerId: modelId }).pipe((0, rxjs_1.map)((pathToDefinitionContainer) => [...pathToDefinitionContainer, instanceKey]));
285
333
  }
286
- return [...(await this.getInstanceKeyPaths({ definitionContainerId: modelId })), { id: props.categoryId, className: this.#categoryClass }];
287
334
  }
288
- }
289
- return [];
290
- }
291
- const definitionContainersInfo = await this.getDefinitionContainersInfo();
292
- const definitionContainerInfo = definitionContainersInfo.get(props.definitionContainerId);
293
- if (definitionContainerInfo === undefined) {
294
- return [];
335
+ return (0, rxjs_1.of)([]);
336
+ }));
295
337
  }
296
- if (!definitionContainerInfo.parentDefinitionContainerExists) {
297
- return [{ id: props.definitionContainerId, className: ClassNameDefinitions_js_1.DEFINITION_CONTAINER_CLASS }];
298
- }
299
- return [
300
- ...(await this.getInstanceKeyPaths({ definitionContainerId: definitionContainerInfo.modelId })),
301
- { id: props.definitionContainerId, className: ClassNameDefinitions_js_1.DEFINITION_CONTAINER_CLASS },
302
- ];
303
- }
304
- async getAllDefinitionContainersAndCategories() {
305
- const [modelsCategoriesInfo, definitionContainersInfo] = await Promise.all([this.getModelsCategoriesInfo(), this.getDefinitionContainersInfo()]);
306
- const result = { definitionContainers: [...definitionContainersInfo.keys()], categories: new Array() };
307
- for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {
308
- result.categories.push(...modelCategoriesInfo.childCategories.map((childCategory) => childCategory.id));
309
- }
310
- return result;
311
- }
312
- async getRootDefinitionContainersAndCategories() {
313
- const [modelsCategoriesInfo, definitionContainersInfo] = await Promise.all([this.getModelsCategoriesInfo(), this.getDefinitionContainersInfo()]);
314
- const result = { definitionContainers: new Array(), categories: new Array() };
315
- for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {
316
- if (!modelCategoriesInfo.parentDefinitionContainerExists) {
317
- result.categories.push(...modelCategoriesInfo.childCategories);
338
+ return this.getDefinitionContainersInfo().pipe((0, rxjs_1.mergeMap)((definitionContainersInfo) => {
339
+ const definitionContainerInfo = definitionContainersInfo.get(props.definitionContainerId);
340
+ if (definitionContainerInfo === undefined) {
341
+ return (0, rxjs_1.of)([]);
318
342
  }
319
- }
320
- for (const [definitionContainerId, definitionContainerInfo] of definitionContainersInfo) {
343
+ const instanceKey = { id: props.definitionContainerId, className: ClassNameDefinitions_js_1.DEFINITION_CONTAINER_CLASS };
321
344
  if (!definitionContainerInfo.parentDefinitionContainerExists) {
322
- result.definitionContainers.push(definitionContainerId);
345
+ return (0, rxjs_1.of)([instanceKey]);
323
346
  }
324
- }
325
- return result;
347
+ return this.getInstanceKeyPaths({ definitionContainerId: definitionContainerInfo.modelId }).pipe((0, rxjs_1.map)((pathToParentDefinitionContainer) => [...pathToParentDefinitionContainer, instanceKey]));
348
+ }));
326
349
  }
327
- async getSubCategories(categoryId) {
328
- const subCategoriesInfo = await this.getSubCategoriesInfo();
329
- const result = new Array();
330
- for (const [subCategoryId, subCategoryInfo] of subCategoriesInfo) {
331
- if (subCategoryInfo.categoryId === categoryId) {
332
- result.push(subCategoryId);
333
- }
334
- }
335
- return result;
350
+ getAllDefinitionContainersAndCategories(props) {
351
+ return (0, rxjs_1.forkJoin)({
352
+ categories: this.getModelsCategoriesInfo().pipe((0, rxjs_1.mergeMap)((modelsCategoriesInfo) => modelsCategoriesInfo.values()), (0, rxjs_1.reduce)((acc, modelCategoriesInfo) => {
353
+ applyElementsFilter(modelCategoriesInfo.childCategories, props?.includeEmpty).forEach((categoryInfo) => acc.push(categoryInfo.id));
354
+ return acc;
355
+ }, new Array())),
356
+ definitionContainers: this.getDefinitionContainersInfo().pipe((0, rxjs_1.mergeMap)((definitionContainersInfo) => definitionContainersInfo.entries()), (0, rxjs_1.reduce)((acc, [definitionContainerId, definitionContainerInfo]) => {
357
+ if (definitionContainerInfo.hasElements || !!props?.includeEmpty) {
358
+ acc.push(definitionContainerId);
359
+ }
360
+ return acc;
361
+ }, new Array())),
362
+ });
336
363
  }
337
- async getIsDefinitionContainerSupported() {
338
- this.#isDefinitionContainerSupported ??= this.queryIsDefinitionContainersSupported();
364
+ getRootDefinitionContainersAndCategories(props) {
365
+ return (0, rxjs_1.forkJoin)({
366
+ categories: this.getModelsCategoriesInfo().pipe((0, rxjs_1.mergeMap)((modelsCategoriesInfo) => modelsCategoriesInfo.values()), (0, rxjs_1.reduce)((acc, modelCategoriesInfo) => {
367
+ if (!modelCategoriesInfo.parentDefinitionContainerExists) {
368
+ applyElementsFilter(modelCategoriesInfo.childCategories, props?.includeEmpty).forEach((categoryInfo) => acc.push(categoryInfo));
369
+ }
370
+ return acc;
371
+ }, new Array())),
372
+ definitionContainers: this.getDefinitionContainersInfo().pipe((0, rxjs_1.mergeMap)((definitionContainersInfo) => definitionContainersInfo.entries()), (0, rxjs_1.reduce)((acc, [definitionContainerId, definitionContainerInfo]) => {
373
+ if (!definitionContainerInfo.parentDefinitionContainerExists && (definitionContainerInfo.hasElements || !!props?.includeEmpty)) {
374
+ acc.push(definitionContainerId);
375
+ }
376
+ return acc;
377
+ }, new Array())),
378
+ });
379
+ }
380
+ getSubCategories(categoryId) {
381
+ return this.getSubCategoriesInfo().pipe((0, rxjs_1.map)((subCategoriesInfo) => subCategoriesInfo.get(categoryId) ?? new Set()));
382
+ }
383
+ getIsDefinitionContainerSupported() {
384
+ this.#isDefinitionContainerSupported ??= this.queryIsDefinitionContainersSupported().pipe((0, rxjs_1.shareReplay)());
339
385
  return this.#isDefinitionContainerSupported;
340
386
  }
341
387
  }
@@ -346,4 +392,7 @@ function getClassesByView(viewType) {
346
392
  ? { categoryClass: "BisCore.DrawingCategory", categoryElementClass: "BisCore.GeometricElement2d", categoryModelClass: "BisCore.GeometricModel2d" }
347
393
  : { categoryClass: "BisCore.SpatialCategory", categoryElementClass: "BisCore.GeometricElement3d", categoryModelClass: "BisCore.GeometricModel3d" };
348
394
  }
395
+ function applyElementsFilter(list, includeEmpty) {
396
+ return includeEmpty ? list : list.filter(({ hasElements }) => !!hasElements);
397
+ }
349
398
  //# sourceMappingURL=CategoriesTreeIdsCache.js.map