@itwin/tree-widget-react 3.4.1 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/CHANGELOG.md +18 -2
  2. package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.d.ts +10 -2
  3. package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js +246 -129
  4. package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js.map +1 -1
  5. package/lib/cjs/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js +70 -17
  6. package/lib/cjs/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js.map +1 -1
  7. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.d.ts +54 -0
  8. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js +285 -0
  9. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js.map +1 -0
  10. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.d.ts +26 -0
  11. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.js +26 -0
  12. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.js.map +1 -0
  13. package/lib/cjs/tree-widget-react/components/trees/categories-tree/{CategoriesVisibilityHandler.d.ts → internal/CategoriesVisibilityHandler.d.ts} +18 -9
  14. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js +218 -0
  15. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js.map +1 -0
  16. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.d.ts +7 -0
  17. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.js +14 -0
  18. package/lib/cjs/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.js.map +1 -0
  19. package/lib/cjs/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.d.ts +0 -4
  20. package/lib/cjs/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js +1 -2
  21. package/lib/cjs/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js.map +1 -1
  22. package/lib/cjs/tree-widget-react/components/trees/common/UseHierarchyVisibility.js.map +1 -1
  23. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.d.ts +5 -0
  24. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js +45 -0
  25. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js.map +1 -1
  26. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.d.ts +2 -1
  27. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js +126 -36
  28. package/lib/cjs/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
  29. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.d.ts +10 -2
  30. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js +246 -129
  31. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js.map +1 -1
  32. package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js +72 -19
  33. package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js.map +1 -1
  34. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.d.ts +54 -0
  35. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js +280 -0
  36. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js.map +1 -0
  37. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.d.ts +26 -0
  38. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.js +23 -0
  39. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.js.map +1 -0
  40. package/lib/esm/tree-widget-react/components/trees/categories-tree/{CategoriesVisibilityHandler.d.ts → internal/CategoriesVisibilityHandler.d.ts} +18 -9
  41. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js +214 -0
  42. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js.map +1 -0
  43. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.d.ts +7 -0
  44. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.js +11 -0
  45. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.js.map +1 -0
  46. package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.d.ts +0 -4
  47. package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js +1 -1
  48. package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js.map +1 -1
  49. package/lib/esm/tree-widget-react/components/trees/common/UseHierarchyVisibility.js.map +1 -1
  50. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.d.ts +5 -0
  51. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js +45 -0
  52. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js.map +1 -1
  53. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.d.ts +2 -1
  54. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js +128 -38
  55. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
  56. package/lib/public/locales/en/TreeWidget.json +15 -4
  57. package/package.json +1 -1
  58. package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesVisibilityHandler.js +0 -91
  59. package/lib/cjs/tree-widget-react/components/trees/categories-tree/CategoriesVisibilityHandler.js.map +0 -1
  60. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesVisibilityHandler.js +0 -87
  61. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesVisibilityHandler.js.map +0 -1
@@ -7,23 +7,33 @@ const jsx_runtime_1 = require("react/jsx-runtime");
7
7
  * See LICENSE.md in the project root for license terms and full copyright notice.
8
8
  *--------------------------------------------------------------------------------------------*/
9
9
  const react_1 = require("react");
10
+ const core_bentley_1 = require("@itwin/core-bentley");
10
11
  const itwinui_icons_react_1 = require("@itwin/itwinui-icons-react");
11
12
  const itwinui_react_1 = require("@itwin/itwinui-react");
13
+ const presentation_core_interop_1 = require("@itwin/presentation-core-interop");
12
14
  const presentation_hierarchies_1 = require("@itwin/presentation-hierarchies");
13
15
  const TreeWidget_js_1 = require("../../../TreeWidget.js");
14
16
  const TreeErrors_js_1 = require("../common/TreeErrors.js");
15
17
  const UseTelemetryContext_js_1 = require("../common/UseTelemetryContext.js");
16
18
  const CategoriesTreeDefinition_js_1 = require("./CategoriesTreeDefinition.js");
17
- const CategoriesVisibilityHandler_js_1 = require("./CategoriesVisibilityHandler.js");
19
+ const CategoriesTreeIdsCache_js_1 = require("./internal/CategoriesTreeIdsCache.js");
20
+ const CategoriesVisibilityHandler_js_1 = require("./internal/CategoriesVisibilityHandler.js");
21
+ const ClassNameDefinitions_js_1 = require("./internal/ClassNameDefinitions.js");
18
22
  /**
19
23
  * Custom hook to create and manage state for the categories tree.
20
24
  * @beta
21
25
  */
22
26
  function useCategoriesTree({ filter, activeView, onCategoriesFiltered }) {
23
27
  const [filteringError, setFilteringError] = (0, react_1.useState)();
28
+ const viewType = activeView.view.is2d() ? "2d" : "3d";
29
+ const iModel = activeView.iModel;
30
+ const idsCache = (0, react_1.useMemo)(() => {
31
+ return new CategoriesTreeIdsCache_js_1.CategoriesTreeIdsCache((0, presentation_core_interop_1.createECSqlQueryExecutor)(iModel), viewType);
32
+ }, [viewType, iModel]);
24
33
  const visibilityHandlerFactory = (0, react_1.useCallback)(() => {
25
34
  const visibilityHandler = new CategoriesVisibilityHandler_js_1.CategoriesVisibilityHandler({
26
35
  viewport: activeView,
36
+ idsCache,
27
37
  });
28
38
  return {
29
39
  getVisibilityStatus: async (node) => visibilityHandler.getVisibilityStatus(node),
@@ -31,11 +41,11 @@ function useCategoriesTree({ filter, activeView, onCategoriesFiltered }) {
31
41
  onVisibilityChange: visibilityHandler.onVisibilityChange,
32
42
  dispose: () => visibilityHandler.dispose(),
33
43
  };
34
- }, [activeView]);
44
+ }, [activeView, idsCache]);
35
45
  const { onFeatureUsed } = (0, UseTelemetryContext_js_1.useTelemetryContext)();
36
46
  const getHierarchyDefinition = (0, react_1.useCallback)((props) => {
37
- return new CategoriesTreeDefinition_js_1.CategoriesTreeDefinition({ ...props, viewType: activeView.view.is2d() ? "2d" : "3d" });
38
- }, [activeView]);
47
+ return new CategoriesTreeDefinition_js_1.CategoriesTreeDefinition({ ...props, viewType, idsCache });
48
+ }, [viewType, idsCache]);
39
49
  const getFilteredPaths = (0, react_1.useMemo)(() => {
40
50
  setFilteringError(undefined);
41
51
  onCategoriesFiltered?.(undefined);
@@ -45,8 +55,8 @@ function useCategoriesTree({ filter, activeView, onCategoriesFiltered }) {
45
55
  return async ({ imodelAccess }) => {
46
56
  onFeatureUsed({ featureId: "filtering", reportInteraction: true });
47
57
  try {
48
- const paths = await CategoriesTreeDefinition_js_1.CategoriesTreeDefinition.createInstanceKeyPaths({ imodelAccess, label: filter, viewType: activeView.view.is2d() ? "2d" : "3d" });
49
- onCategoriesFiltered?.(getCategories(paths));
58
+ const paths = await CategoriesTreeDefinition_js_1.CategoriesTreeDefinition.createInstanceKeyPaths({ imodelAccess, label: filter, viewType, idsCache });
59
+ onCategoriesFiltered?.(await getCategoriesFromPaths(paths, idsCache));
50
60
  return paths;
51
61
  }
52
62
  catch (e) {
@@ -59,7 +69,7 @@ function useCategoriesTree({ filter, activeView, onCategoriesFiltered }) {
59
69
  return [];
60
70
  }
61
71
  };
62
- }, [filter, activeView, onFeatureUsed, onCategoriesFiltered]);
72
+ }, [filter, viewType, onFeatureUsed, onCategoriesFiltered, idsCache]);
63
73
  return {
64
74
  categoriesTreeProps: {
65
75
  treeName: "categories-tree-v2",
@@ -76,22 +86,48 @@ function useCategoriesTree({ filter, activeView, onCategoriesFiltered }) {
76
86
  };
77
87
  }
78
88
  exports.useCategoriesTree = useCategoriesTree;
79
- function getCategories(paths) {
89
+ async function getCategoriesFromPaths(paths, idsCache) {
80
90
  if (!paths) {
81
91
  return undefined;
82
92
  }
83
93
  const categories = new Map();
84
94
  for (const path of paths) {
85
- const currPath = Array.isArray(path) ? path : path.path;
86
- const [category, subCategory] = currPath;
87
- if (!presentation_hierarchies_1.HierarchyNodeIdentifier.isInstanceNodeIdentifier(category)) {
95
+ const currPath = presentation_hierarchies_1.HierarchyFilteringPath.normalize(path).path;
96
+ if (currPath.length === 0) {
88
97
  continue;
89
98
  }
90
- if (!categories.has(category.id)) {
91
- categories.set(category.id, []);
99
+ let category;
100
+ let subCategory;
101
+ const lastNode = currPath[currPath.length - 1];
102
+ if (!presentation_hierarchies_1.HierarchyNodeIdentifier.isInstanceNodeIdentifier(lastNode)) {
103
+ continue;
104
+ }
105
+ if (lastNode.className === ClassNameDefinitions_js_1.DEFINITION_CONTAINER_CLASS) {
106
+ const definitionContainerCategories = await idsCache.getAllContainedCategories([lastNode.id]);
107
+ for (const categoryId of definitionContainerCategories) {
108
+ const value = categories.get(categoryId);
109
+ if (value === undefined) {
110
+ categories.set(categoryId, []);
111
+ }
112
+ }
113
+ continue;
114
+ }
115
+ if (lastNode.className === ClassNameDefinitions_js_1.SUB_CATEGORY_CLASS) {
116
+ const secondToLastNode = currPath.length > 1 ? currPath[currPath.length - 2] : undefined;
117
+ (0, core_bentley_1.assert)(secondToLastNode !== undefined && presentation_hierarchies_1.HierarchyNodeIdentifier.isInstanceNodeIdentifier(secondToLastNode));
118
+ subCategory = lastNode;
119
+ category = secondToLastNode;
120
+ }
121
+ else {
122
+ category = lastNode;
92
123
  }
93
- if (subCategory && presentation_hierarchies_1.HierarchyNodeIdentifier.isInstanceNodeIdentifier(subCategory)) {
94
- categories.get(category.id).push(subCategory.id);
124
+ let entry = categories.get(category.id);
125
+ if (entry === undefined) {
126
+ entry = [];
127
+ categories.set(category.id, entry);
128
+ }
129
+ if (subCategory) {
130
+ entry.push(subCategory.id);
95
131
  }
96
132
  }
97
133
  return [...categories.entries()].map(([categoryId, subCategoryIds]) => ({
@@ -108,8 +144,25 @@ function getNoDataMessage(filter, error) {
108
144
  }
109
145
  return undefined;
110
146
  }
111
- function getIcon() {
112
- return (0, jsx_runtime_1.jsx)(itwinui_icons_react_1.SvgLayers, {});
147
+ function SvgLayersIsolate() {
148
+ return ((0, jsx_runtime_1.jsxs)("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 16 16", children: [(0, jsx_runtime_1.jsxs)("g", { children: [(0, jsx_runtime_1.jsx)("path", { d: "M13,3.4938L6.5,0L0,3.4938l6.5,3.4938L13,3.4938z" }), (0, jsx_runtime_1.jsx)("polygon", { points: "6.5,8.21 7,7.94 7,9.24 6.5,9.51 0,6.01 1.22,5.36 " }), (0, jsx_runtime_1.jsx)("polygon", { points: "13,6.01 11.16,7 8.74,7 11.78,5.36 " }), (0, jsx_runtime_1.jsx)("polygon", { points: "7,10.37 7,11.67 6.5,11.94 0,8.45 1.22,7.8 6.5,10.64 " })] }), (0, jsx_runtime_1.jsxs)("g", { transform: "translate(-1-1)", children: [(0, jsx_runtime_1.jsx)("path", { d: "M9,13.5714h3.4286V17H9V13.5714z" }), (0, jsx_runtime_1.jsx)("path", { d: "M9,9v3.4286h3.4286V9H9z M11.8571,11.8571H9.5714V9.5714h2.2857V11.8571z" }), (0, jsx_runtime_1.jsx)("path", { d: "M13.5714,9v3.4286H17V9H13.5714 M16.4286,11.8571h-2.2857V9.5714h2.2857V11.8571" }), (0, jsx_runtime_1.jsx)("path", { d: "M13.5714,13.5714V17H17v-3.4286H13.5714z M16.4286,16.4286h-2.2857v-2.2857h2.2857V16.4286z" })] })] }));
149
+ }
150
+ function SvgBisDefinitionContainer() {
151
+ return ((0, jsx_runtime_1.jsx)("svg", { xmlns: "http://www.w3.org/2000/svg", style: { color: "#7d7d7d" }, viewBox: "0 0 16 16", children: (0, jsx_runtime_1.jsx)("path", { fill: "currentColor", fillRule: "evenodd", d: "M7.748 1.726a.5.5 0 0 1 .504 0L13.008 4.5 8 7.421l-5.008-2.92 4.756-2.775ZM2.5 5.37v2.342l2 1.166V6.537l-2-1.166Zm3 1.75v2.342l2 1.167V8.287l-2-1.166Zm3 1.166v2.342l2-1.166V7.12l-2 1.166Zm3-1.75V8.88l2-1.166V5.37l-2 1.166Zm0 3.5 2-1.166v2.055a.5.5 0 0 1-.248.432L11.5 12.379v-2.342Zm-3 1.75 2-1.167v2.343l-2 1.167v-2.343Zm-3-1.167 2 1.167v2.342l-2-1.166V10.62Zm-3-1.75 2 1.167v2.342l-1.752-1.021a.5.5 0 0 1-.248-.432V8.87ZM8.756.863a1.5 1.5 0 0 0-1.512 0l-5 2.917A1.5 1.5 0 0 0 1.5 5.074v5.852a1.5 1.5 0 0 0 .744 1.295l5 2.917a1.5 1.5 0 0 0 1.512 0l5-2.917a1.5 1.5 0 0 0 .744-1.295V5.074a1.5 1.5 0 0 0-.744-1.295l-5-2.917Z", clipRule: "evenodd" }) }));
152
+ }
153
+ function getIcon(node) {
154
+ if (node.extendedData?.imageId === undefined) {
155
+ return undefined;
156
+ }
157
+ switch (node.extendedData.imageId) {
158
+ case "icon-layers":
159
+ return (0, jsx_runtime_1.jsx)(itwinui_icons_react_1.SvgLayers, {});
160
+ case "icon-layers-isolate":
161
+ return (0, jsx_runtime_1.jsx)(SvgLayersIsolate, {});
162
+ case "icon-definition-container":
163
+ return (0, jsx_runtime_1.jsx)(SvgBisDefinitionContainer, {});
164
+ }
165
+ return undefined;
113
166
  }
114
167
  function getSublabel(node) {
115
168
  return node.extendedData?.description;
@@ -1 +1 @@
1
- {"version":3,"file":"UseCategoriesTree.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.tsx"],"names":[],"mappings":";;;;AAAA;;;gGAGgG;AAEhG,iCAAuD;AACvD,oEAAuD;AACvD,wDAA4C;AAC5C,8EAA0E;AAC1E,0DAAoD;AACpD,2DAAmE;AACnE,6EAAuE;AACvE,+EAAyE;AACzE,qFAA+E;AA6B/E;;;GAGG;AACH,SAAgB,iBAAiB,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,oBAAoB,EAA0B;IACpG,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,IAAA,gBAAQ,GAA4C,CAAC;IACjG,MAAM,wBAAwB,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE;QAChD,MAAM,iBAAiB,GAAG,IAAI,4DAA2B,CAAC;YACxD,QAAQ,EAAE,UAAU;SACrB,CAAC,CAAC;QACH,OAAO;YACL,mBAAmB,EAAE,KAAK,EAAE,IAAmB,EAAE,EAAE,CAAC,iBAAiB,CAAC,mBAAmB,CAAC,IAAI,CAAC;YAC/F,gBAAgB,EAAE,KAAK,EAAE,IAAmB,EAAE,EAAW,EAAE,EAAE,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,IAAI,EAAE,EAAE,CAAC;YAC1G,kBAAkB,EAAE,iBAAiB,CAAC,kBAAkB;YACxD,OAAO,EAAE,GAAG,EAAE,CAAC,iBAAiB,CAAC,OAAO,EAAE;SAC3C,CAAC;IACJ,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;IACjB,MAAM,EAAE,aAAa,EAAE,GAAG,IAAA,4CAAmB,GAAE,CAAC;IAEhD,MAAM,sBAAsB,GAAG,IAAA,mBAAW,EACxC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I,WAAW,IAAI,kDAAuB,CAAC,wBAAwB,CAAC,WAAW,CAAC,EAAE;YAChF,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAE,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;SACnD;KACF;IAED,OAAO,CAAC,GAAG,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,EAAE,cAAc,CAAC,EAAE,EAAE,CAAC,CAAC;QACtE,UAAU;QACV,cAAc,EAAE,cAAc,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,cAAc;KACzE,CAAC,CAAC,CAAC;AACN,CAAC;AAED,SAAS,gBAAgB,CAAC,MAAc,EAAE,KAAoC;IAC5E,IAAI,KAAK,EAAE;QACT,OAAO,uBAAC,oBAAI,cAAE,0BAAU,CAAC,SAAS,CAAC,4BAA4B,KAAK,EAAE,CAAC,GAAQ,CAAC;KACjF;IACD,IAAI,MAAM,EAAE;QACV,OAAO,uBAAC,oBAAI,cAAE,0BAAU,CAAC,SAAS,CAAC,oCAAoC,EAAE,EAAE,MAAM,EAAE,CAAC,GAAQ,CAAC;KAC9F;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,OAAO;IACd,OAAO,uBAAC,+BAAS,KAAG,CAAC;AACvB,CAAC;AAED,SAAS,WAAW,CAAC,IAA+B;IAClD,OAAO,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC;AACxC,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 { useCallback, useMemo, useState } from \"react\";\nimport { SvgLayers } from \"@itwin/itwinui-icons-react\";\nimport { Text } from \"@itwin/itwinui-react\";\nimport { HierarchyNodeIdentifier } from \"@itwin/presentation-hierarchies\";\nimport { TreeWidget } from \"../../../TreeWidget.js\";\nimport { FilterLimitExceededError } from \"../common/TreeErrors.js\";\nimport { useTelemetryContext } from \"../common/UseTelemetryContext.js\";\nimport { CategoriesTreeDefinition } from \"./CategoriesTreeDefinition.js\";\nimport { CategoriesVisibilityHandler } from \"./CategoriesVisibilityHandler.js\";\n\nimport type { HierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport type { VisibilityTreeProps } from \"../common/components/VisibilityTree.js\";\nimport type { Viewport } from \"@itwin/core-frontend\";\nimport type { PresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport type { VisibilityTreeRendererProps } from \"../common/components/VisibilityTreeRenderer.js\";\nimport type { Id64String } from \"@itwin/core-bentley\";\nimport type { CategoryInfo } from \"../common/CategoriesVisibilityUtils.js\";\n\ntype CategoriesTreeFilteringError = \"tooManyFilterMatches\" | \"unknownFilterError\";\ntype HierarchyFilteringPaths = Awaited<ReturnType<Required<VisibilityTreeProps>[\"getFilteredPaths\"]>>;\n\n/** @beta */\nexport interface UseCategoriesTreeProps {\n filter: string;\n activeView: Viewport;\n onCategoriesFiltered?: (categories: CategoryInfo[] | undefined) => void;\n}\n\n/** @beta */\ninterface UseCategoriesTreeResult {\n categoriesTreeProps: Pick<\n VisibilityTreeProps,\n \"treeName\" | \"getHierarchyDefinition\" | \"getFilteredPaths\" | \"visibilityHandlerFactory\" | \"highlight\" | \"noDataMessage\"\n >;\n rendererProps: Required<Pick<VisibilityTreeRendererProps, \"getIcon\" | \"getSublabel\">>;\n}\n\n/**\n * Custom hook to create and manage state for the categories tree.\n * @beta\n */\nexport function useCategoriesTree({ filter, activeView, onCategoriesFiltered }: UseCategoriesTreeProps): UseCategoriesTreeResult {\n const [filteringError, setFilteringError] = useState<CategoriesTreeFilteringError | undefined>();\n const visibilityHandlerFactory = useCallback(() => {\n const visibilityHandler = new CategoriesVisibilityHandler({\n viewport: activeView,\n });\n return {\n getVisibilityStatus: async (node: HierarchyNode) => visibilityHandler.getVisibilityStatus(node),\n changeVisibility: async (node: HierarchyNode, on: boolean) => visibilityHandler.changeVisibility(node, on),\n onVisibilityChange: visibilityHandler.onVisibilityChange,\n dispose: () => visibilityHandler.dispose(),\n };\n }, [activeView]);\n const { onFeatureUsed } = useTelemetryContext();\n\n const getHierarchyDefinition = useCallback<VisibilityTreeProps[\"getHierarchyDefinition\"]>(\n (props) => {\n return new CategoriesTreeDefinition({ ...props, viewType: activeView.view.is2d() ? \"2d\" : \"3d\" });\n },\n [activeView],\n );\n\n const getFilteredPaths = useMemo<VisibilityTreeProps[\"getFilteredPaths\"] | undefined>(() => {\n setFilteringError(undefined);\n onCategoriesFiltered?.(undefined);\n if (!filter) {\n return undefined;\n }\n return async ({ imodelAccess }) => {\n onFeatureUsed({ featureId: \"filtering\", reportInteraction: true });\n try {\n const paths = await CategoriesTreeDefinition.createInstanceKeyPaths({ imodelAccess, label: filter, viewType: activeView.view.is2d() ? \"2d\" : \"3d\" });\n onCategoriesFiltered?.(getCategories(paths));\n return paths;\n } catch (e) {\n const newError = e instanceof FilterLimitExceededError ? \"tooManyFilterMatches\" : \"unknownFilterError\";\n if (newError !== \"tooManyFilterMatches\") {\n const feature = e instanceof Error && e.message.includes(\"query too long to execute or server is too busy\") ? \"error-timeout\" : \"error-unknown\";\n onFeatureUsed({ featureId: feature, reportInteraction: false });\n }\n setFilteringError(newError);\n return [];\n }\n };\n }, [filter, activeView, onFeatureUsed, onCategoriesFiltered]);\n\n return {\n categoriesTreeProps: {\n treeName: \"categories-tree-v2\",\n getHierarchyDefinition,\n getFilteredPaths,\n visibilityHandlerFactory,\n noDataMessage: getNoDataMessage(filter, filteringError),\n highlight: filter ? { text: filter } : undefined,\n },\n rendererProps: {\n getIcon,\n getSublabel,\n },\n };\n}\n\nfunction getCategories(paths: HierarchyFilteringPaths): CategoryInfo[] | undefined {\n if (!paths) {\n return undefined;\n }\n\n const categories = new Map<Id64String, Id64String[]>();\n for (const path of paths) {\n const currPath = Array.isArray(path) ? path : path.path;\n const [category, subCategory] = currPath;\n\n if (!HierarchyNodeIdentifier.isInstanceNodeIdentifier(category)) {\n continue;\n }\n\n if (!categories.has(category.id)) {\n categories.set(category.id, []);\n }\n\n if (subCategory && HierarchyNodeIdentifier.isInstanceNodeIdentifier(subCategory)) {\n categories.get(category.id)!.push(subCategory.id);\n }\n }\n\n return [...categories.entries()].map(([categoryId, subCategoryIds]) => ({\n categoryId,\n subCategoryIds: subCategoryIds.length === 0 ? undefined : subCategoryIds,\n }));\n}\n\nfunction getNoDataMessage(filter: string, error?: CategoriesTreeFilteringError) {\n if (error) {\n return <Text>{TreeWidget.translate(`categoriesTree.filtering.${error}`)}</Text>;\n }\n if (filter) {\n return <Text>{TreeWidget.translate(\"categoriesTree.filtering.noMatches\", { filter })}</Text>;\n }\n return undefined;\n}\n\nfunction getIcon() {\n return <SvgLayers />;\n}\n\nfunction getSublabel(node: PresentationHierarchyNode) {\n return node.extendedData?.description;\n}\n"]}
1
+ {"version":3,"file":"UseCategoriesTree.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.tsx"],"names":[],"mappings":";;;;AAAA;;;gGAGgG;AAEhG,iCAAuD;AACvD,sDAA6C;AAC7C,oEAAuD;AACvD,wDAA4C;AAC5C,gFAA4E;AAC5E,8EAAkG;AAClG,0DAAoD;AACpD,2DAAmE;AACnE,6EAAuE;AACvE,+EAAyE;AACzE,oFAA8E;AAC9E,8FAAwF;AACxF,gFAAoG;AA8BpG;;;GAGG;AACH,SAAgB,iBAAiB,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,oBAAoB,EAA0B;IACpG,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,IAAA,gBAAQ,GAA4C,CAAC;IAEjG,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IACtD,MAAM,MAAM,GAAG,UAAU,CAAC,M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A+B;IAClD,OAAO,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC;AACxC,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 { useCallback, useMemo, useState } from \"react\";\nimport { assert } from \"@itwin/core-bentley\";\nimport { SvgLayers } from \"@itwin/itwinui-icons-react\";\nimport { Text } from \"@itwin/itwinui-react\";\nimport { createECSqlQueryExecutor } from \"@itwin/presentation-core-interop\";\nimport { HierarchyFilteringPath, HierarchyNodeIdentifier } from \"@itwin/presentation-hierarchies\";\nimport { TreeWidget } from \"../../../TreeWidget.js\";\nimport { FilterLimitExceededError } from \"../common/TreeErrors.js\";\nimport { useTelemetryContext } from \"../common/UseTelemetryContext.js\";\nimport { CategoriesTreeDefinition } from \"./CategoriesTreeDefinition.js\";\nimport { CategoriesTreeIdsCache } from \"./internal/CategoriesTreeIdsCache.js\";\nimport { CategoriesVisibilityHandler } from \"./internal/CategoriesVisibilityHandler.js\";\nimport { DEFINITION_CONTAINER_CLASS, SUB_CATEGORY_CLASS } from \"./internal/ClassNameDefinitions.js\";\n\nimport type { Id64String } from \"@itwin/core-bentley\";\nimport type { ReactElement } from \"react\";\nimport type { HierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport type { VisibilityTreeProps } from \"../common/components/VisibilityTree.js\";\nimport type { Viewport } from \"@itwin/core-frontend\";\nimport type { PresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport type { VisibilityTreeRendererProps } from \"../common/components/VisibilityTreeRenderer.js\";\nimport type { CategoryInfo } from \"../common/CategoriesVisibilityUtils.js\";\n\ntype CategoriesTreeFilteringError = \"tooManyFilterMatches\" | \"unknownFilterError\";\ntype HierarchyFilteringPaths = Awaited<ReturnType<Required<VisibilityTreeProps>[\"getFilteredPaths\"]>>;\n\n/** @beta */\nexport interface UseCategoriesTreeProps {\n filter: string;\n activeView: Viewport;\n onCategoriesFiltered?: (categories: CategoryInfo[] | undefined) => void;\n}\n\n/** @beta */\ninterface UseCategoriesTreeResult {\n categoriesTreeProps: Pick<\n VisibilityTreeProps,\n \"treeName\" | \"getHierarchyDefinition\" | \"getFilteredPaths\" | \"visibilityHandlerFactory\" | \"highlight\" | \"noDataMessage\"\n >;\n rendererProps: Required<Pick<VisibilityTreeRendererProps, \"getIcon\" | \"getSublabel\">>;\n}\n\n/**\n * Custom hook to create and manage state for the categories tree.\n * @beta\n */\nexport function useCategoriesTree({ filter, activeView, onCategoriesFiltered }: UseCategoriesTreeProps): UseCategoriesTreeResult {\n const [filteringError, setFilteringError] = useState<CategoriesTreeFilteringError | undefined>();\n\n const viewType = activeView.view.is2d() ? \"2d\" : \"3d\";\n const iModel = activeView.iModel;\n\n const idsCache = useMemo(() => {\n return new CategoriesTreeIdsCache(createECSqlQueryExecutor(iModel), viewType);\n }, [viewType, iModel]);\n\n const visibilityHandlerFactory = useCallback(() => {\n const visibilityHandler = new CategoriesVisibilityHandler({\n viewport: activeView,\n idsCache,\n });\n return {\n getVisibilityStatus: async (node: HierarchyNode) => visibilityHandler.getVisibilityStatus(node),\n changeVisibility: async (node: HierarchyNode, on: boolean) => visibilityHandler.changeVisibility(node, on),\n onVisibilityChange: visibilityHandler.onVisibilityChange,\n dispose: () => visibilityHandler.dispose(),\n };\n }, [activeView, idsCache]);\n const { onFeatureUsed } = useTelemetryContext();\n\n const getHierarchyDefinition = useCallback<VisibilityTreeProps[\"getHierarchyDefinition\"]>(\n (props) => {\n return new CategoriesTreeDefinition({ ...props, viewType, idsCache });\n },\n [viewType, idsCache],\n );\n\n const getFilteredPaths = useMemo<VisibilityTreeProps[\"getFilteredPaths\"] | undefined>(() => {\n setFilteringError(undefined);\n onCategoriesFiltered?.(undefined);\n if (!filter) {\n return undefined;\n }\n return async ({ imodelAccess }) => {\n onFeatureUsed({ featureId: \"filtering\", reportInteraction: true });\n try {\n const paths = await CategoriesTreeDefinition.createInstanceKeyPaths({ imodelAccess, label: filter, viewType, idsCache });\n onCategoriesFiltered?.(await getCategoriesFromPaths(paths, idsCache));\n return paths;\n } catch (e) {\n const newError = e instanceof FilterLimitExceededError ? \"tooManyFilterMatches\" : \"unknownFilterError\";\n if (newError !== \"tooManyFilterMatches\") {\n const feature = e instanceof Error && e.message.includes(\"query too long to execute or server is too busy\") ? \"error-timeout\" : \"error-unknown\";\n onFeatureUsed({ featureId: feature, reportInteraction: false });\n }\n setFilteringError(newError);\n return [];\n }\n };\n }, [filter, viewType, onFeatureUsed, onCategoriesFiltered, idsCache]);\n\n return {\n categoriesTreeProps: {\n treeName: \"categories-tree-v2\",\n getHierarchyDefinition,\n getFilteredPaths,\n visibilityHandlerFactory,\n noDataMessage: getNoDataMessage(filter, filteringError),\n highlight: filter ? { text: filter } : undefined,\n },\n rendererProps: {\n getIcon,\n getSublabel,\n },\n };\n}\n\nasync function getCategoriesFromPaths(paths: HierarchyFilteringPaths, idsCache: CategoriesTreeIdsCache): Promise<CategoryInfo[] | undefined> {\n if (!paths) {\n return undefined;\n }\n\n const categories = new Map<Id64String, Id64String[]>();\n for (const path of paths) {\n const currPath = HierarchyFilteringPath.normalize(path).path;\n if (currPath.length === 0) {\n continue;\n }\n\n let category: HierarchyNodeIdentifier;\n let subCategory: HierarchyNodeIdentifier | undefined;\n const lastNode = currPath[currPath.length - 1];\n\n if (!HierarchyNodeIdentifier.isInstanceNodeIdentifier(lastNode)) {\n continue;\n }\n\n if (lastNode.className === DEFINITION_CONTAINER_CLASS) {\n const definitionContainerCategories = await idsCache.getAllContainedCategories([lastNode.id]);\n for (const categoryId of definitionContainerCategories) {\n const value = categories.get(categoryId);\n if (value === undefined) {\n categories.set(categoryId, []);\n }\n }\n continue;\n }\n\n if (lastNode.className === SUB_CATEGORY_CLASS) {\n const secondToLastNode = currPath.length > 1 ? currPath[currPath.length - 2] : undefined;\n assert(secondToLastNode !== undefined && HierarchyNodeIdentifier.isInstanceNodeIdentifier(secondToLastNode));\n\n subCategory = lastNode;\n category = secondToLastNode;\n } else {\n category = lastNode;\n }\n\n let entry = categories.get(category.id);\n if (entry === undefined) {\n entry = [];\n categories.set(category.id, entry);\n }\n\n if (subCategory) {\n entry.push(subCategory.id);\n }\n }\n\n return [...categories.entries()].map(([categoryId, subCategoryIds]) => ({\n categoryId,\n subCategoryIds: subCategoryIds.length === 0 ? undefined : subCategoryIds,\n }));\n}\n\nfunction getNoDataMessage(filter: string, error?: CategoriesTreeFilteringError) {\n if (error) {\n return <Text>{TreeWidget.translate(`categoriesTree.filtering.${error}`)}</Text>;\n }\n if (filter) {\n return <Text>{TreeWidget.translate(\"categoriesTree.filtering.noMatches\", { filter })}</Text>;\n }\n return undefined;\n}\n\nfunction SvgLayersIsolate() {\n return (\n <svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\">\n <g>\n <path d=\"M13,3.4938L6.5,0L0,3.4938l6.5,3.4938L13,3.4938z\" />\n <polygon points=\"6.5,8.21 7,7.94 7,9.24 6.5,9.51 0,6.01 1.22,5.36 \" />\n <polygon points=\"13,6.01 11.16,7 8.74,7 11.78,5.36 \" />\n <polygon points=\"7,10.37 7,11.67 6.5,11.94 0,8.45 1.22,7.8 6.5,10.64 \" />\n </g>\n <g transform=\"translate(-1-1)\">\n <path d=\"M9,13.5714h3.4286V17H9V13.5714z\" />\n <path d=\"M9,9v3.4286h3.4286V9H9z M11.8571,11.8571H9.5714V9.5714h2.2857V11.8571z\" />\n <path d=\"M13.5714,9v3.4286H17V9H13.5714 M16.4286,11.8571h-2.2857V9.5714h2.2857V11.8571\" />\n <path d=\"M13.5714,13.5714V17H17v-3.4286H13.5714z M16.4286,16.4286h-2.2857v-2.2857h2.2857V16.4286z\" />\n </g>\n </svg>\n );\n}\n\nfunction SvgBisDefinitionContainer() {\n return (\n <svg xmlns=\"http://www.w3.org/2000/svg\" style={{ color: \"#7d7d7d\" }} viewBox=\"0 0 16 16\">\n <path\n fill=\"currentColor\"\n fillRule=\"evenodd\"\n d=\"M7.748 1.726a.5.5 0 0 1 .504 0L13.008 4.5 8 7.421l-5.008-2.92 4.756-2.775ZM2.5 5.37v2.342l2 1.166V6.537l-2-1.166Zm3 1.75v2.342l2 1.167V8.287l-2-1.166Zm3 1.166v2.342l2-1.166V7.12l-2 1.166Zm3-1.75V8.88l2-1.166V5.37l-2 1.166Zm0 3.5 2-1.166v2.055a.5.5 0 0 1-.248.432L11.5 12.379v-2.342Zm-3 1.75 2-1.167v2.343l-2 1.167v-2.343Zm-3-1.167 2 1.167v2.342l-2-1.166V10.62Zm-3-1.75 2 1.167v2.342l-1.752-1.021a.5.5 0 0 1-.248-.432V8.87ZM8.756.863a1.5 1.5 0 0 0-1.512 0l-5 2.917A1.5 1.5 0 0 0 1.5 5.074v5.852a1.5 1.5 0 0 0 .744 1.295l5 2.917a1.5 1.5 0 0 0 1.512 0l5-2.917a1.5 1.5 0 0 0 .744-1.295V5.074a1.5 1.5 0 0 0-.744-1.295l-5-2.917Z\"\n clipRule=\"evenodd\"\n />\n </svg>\n );\n}\n\nfunction getIcon(node: PresentationHierarchyNode): ReactElement | undefined {\n if (node.extendedData?.imageId === undefined) {\n return undefined;\n }\n\n switch (node.extendedData.imageId) {\n case \"icon-layers\":\n return <SvgLayers />;\n case \"icon-layers-isolate\":\n return <SvgLayersIsolate />;\n case \"icon-definition-container\":\n return <SvgBisDefinitionContainer />;\n }\n\n return undefined;\n}\n\nfunction getSublabel(node: PresentationHierarchyNode) {\n return node.extendedData?.description;\n}\n"]}
@@ -0,0 +1,54 @@
1
+ import type { Id64Array, Id64String } from "@itwin/core-bentley";
2
+ import type { LimitingECSqlQueryExecutor } from "@itwin/presentation-hierarchies";
3
+ import type { InstanceKey } from "@itwin/presentation-shared";
4
+ interface CategoryInfo {
5
+ id: Id64String;
6
+ childCount: number;
7
+ }
8
+ /** @internal */
9
+ export declare class CategoriesTreeIdsCache {
10
+ private _queryExecutor;
11
+ private _definitionContainersInfo;
12
+ private _modelsCategoriesInfo;
13
+ private _subCategoriesInfo;
14
+ private _categoryClass;
15
+ private _categoryElementClass;
16
+ private _isDefinitionContainerSupported;
17
+ constructor(_queryExecutor: LimitingECSqlQueryExecutor, viewType: "3d" | "2d");
18
+ private queryCategories;
19
+ private queryIsDefinitionContainersSupported;
20
+ private queryDefinitionContainers;
21
+ private queryVisibleSubCategories;
22
+ private getModelsCategoriesInfo;
23
+ private getSubCategoriesInfo;
24
+ private getDefinitionContainersInfo;
25
+ getDirectChildDefinitionContainersAndCategories(parentDefinitionContainerIds: Id64Array): Promise<{
26
+ categories: CategoryInfo[];
27
+ definitionContainers: Id64Array;
28
+ }>;
29
+ getAllContainedCategories(definitionContainerIds: Id64Array): Promise<Id64Array>;
30
+ getInstanceKeyPaths(props: {
31
+ categoryId: Id64String;
32
+ } | {
33
+ definitionContainerId: Id64String;
34
+ } | {
35
+ subCategoryId: Id64String;
36
+ }): Promise<InstanceKey[]>;
37
+ getAllDefinitionContainersAndCategories(): Promise<{
38
+ categories: Id64Array;
39
+ definitionContainers: Id64Array;
40
+ }>;
41
+ getRootDefinitionContainersAndCategories(): Promise<{
42
+ categories: CategoryInfo[];
43
+ definitionContainers: Id64Array;
44
+ }>;
45
+ getSubCategories(categoryId: Id64String): Promise<Id64Array>;
46
+ getIsDefinitionContainerSupported(): Promise<boolean>;
47
+ }
48
+ /** @internal */
49
+ export declare function getClassesByView(viewType: "2d" | "3d"): {
50
+ categoryClass: string;
51
+ categoryElementClass: string;
52
+ };
53
+ export {};
54
+ //# sourceMappingURL=CategoriesTreeIdsCache.d.ts.map
@@ -0,0 +1,285 @@
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.getClassesByView = exports.CategoriesTreeIdsCache = void 0;
8
+ const ClassNameDefinitions_js_1 = require("./ClassNameDefinitions.js");
9
+ /** @internal */
10
+ class CategoriesTreeIdsCache {
11
+ constructor(_queryExecutor, viewType) {
12
+ this._queryExecutor = _queryExecutor;
13
+ const { categoryClass, categoryElementClass } = getClassesByView(viewType);
14
+ this._categoryClass = categoryClass;
15
+ this._categoryElementClass = categoryElementClass;
16
+ }
17
+ async *queryCategories() {
18
+ const isDefinitionContainerSupported = await this.getIsDefinitionContainerSupported();
19
+ const categoriesQuery = `
20
+ SELECT
21
+ this.ECInstanceId id,
22
+ COUNT(sc.ECInstanceId) childCount,
23
+ this.Model.Id modelId,
24
+ ${isDefinitionContainerSupported
25
+ ? `
26
+ IIF(this.Model.Id IN (SELECT dc.ECInstanceId FROM ${ClassNameDefinitions_js_1.DEFINITION_CONTAINER_CLASS} dc),
27
+ true,
28
+ false
29
+ )`
30
+ : "false"} parentDefinitionContainerExists
31
+ FROM
32
+ ${this._categoryClass} this
33
+ JOIN ${ClassNameDefinitions_js_1.SUB_CATEGORY_CLASS} sc ON sc.Parent.Id = this.ECInstanceId
34
+ JOIN BisCore.Model m ON m.ECInstanceId = this.Model.Id
35
+ WHERE
36
+ NOT this.IsPrivate
37
+ AND (NOT m.IsPrivate OR m.ECClassId IS (BisCore.DictionaryModel))
38
+ AND EXISTS (SELECT 1 FROM ${this._categoryElementClass} e WHERE e.Category.Id = this.ECInstanceId)
39
+ GROUP BY this.ECInstanceId
40
+ `;
41
+ for await (const row of this._queryExecutor.createQueryReader({ ecsql: categoriesQuery }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded" })) {
42
+ yield { id: row.id, modelId: row.modelId, parentDefinitionContainerExists: row.parentDefinitionContainerExists, childCount: row.childCount };
43
+ }
44
+ }
45
+ async queryIsDefinitionContainersSupported() {
46
+ const query = `
47
+ SELECT
48
+ 1
49
+ FROM
50
+ ECDbMeta.ECSchemaDef s
51
+ JOIN ECDbMeta.ECClassDef c ON c.Schema.Id = s.ECInstanceId
52
+ WHERE
53
+ s.Name = 'BisCore'
54
+ AND c.Name = 'DefinitionContainer'
55
+ `;
56
+ for await (const _row of this._queryExecutor.createQueryReader({ ecsql: query })) {
57
+ return true;
58
+ }
59
+ return false;
60
+ }
61
+ async *queryDefinitionContainers() {
62
+ // DefinitionModel ECInstanceId will always be the same as modeled DefinitionContainer ECInstanceId, if this wasn't the case, we would need to do something like:
63
+ // JOIN BisCore.DefinitionModel dm ON dm.ECInstanceId = ${modelIdAccessor}
64
+ // JOIN BisCore.DefinitionModelBreaksDownDefinitionContainer dr ON dr.SourceECInstanceId = dm.ECInstanceId
65
+ // JOIN BisCore.DefinitionContainer dc ON dc.ECInstanceId = dr.TargetECInstanceId
66
+ const DEFINITION_CONTAINERS_CTE = "DefinitionContainers";
67
+ const ctes = [
68
+ `
69
+ ${DEFINITION_CONTAINERS_CTE}(ECInstanceId, ModelId) AS (
70
+ SELECT
71
+ dc.ECInstanceId,
72
+ dc.Model.Id
73
+ FROM
74
+ ${ClassNameDefinitions_js_1.DEFINITION_CONTAINER_CLASS} dc
75
+ WHERE
76
+ dc.ECInstanceId IN (SELECT c.Model.Id FROM ${this._categoryClass} c WHERE NOT c.IsPrivate)
77
+ AND NOT dc.IsPrivate
78
+
79
+ UNION ALL
80
+
81
+ SELECT
82
+ pdc.ECInstanceId,
83
+ pdc.Model.Id
84
+ FROM
85
+ ${DEFINITION_CONTAINERS_CTE} cdc
86
+ JOIN ${ClassNameDefinitions_js_1.DEFINITION_CONTAINER_CLASS} pdc ON pdc.ECInstanceId = cdc.ModelId
87
+ WHERE
88
+ NOT pdc.IsPrivate
89
+ )
90
+ `,
91
+ ];
92
+ const definitionsQuery = `
93
+ SELECT dc.ECInstanceId id, dc.ModelId modelId FROM ${DEFINITION_CONTAINERS_CTE} dc GROUP BY dc.ECInstanceId
94
+ `;
95
+ for await (const row of this._queryExecutor.createQueryReader({ ctes, ecsql: definitionsQuery }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded" })) {
96
+ yield { id: row.id, modelId: row.modelId };
97
+ }
98
+ }
99
+ async *queryVisibleSubCategories(categoriesInfo) {
100
+ const definitionsQuery = `
101
+ SELECT
102
+ sc.ECInstanceId id,
103
+ sc.Parent.Id categoryId
104
+ FROM
105
+ ${ClassNameDefinitions_js_1.SUB_CATEGORY_CLASS} sc
106
+ WHERE
107
+ NOT sc.IsPrivate
108
+ AND sc.Parent.Id IN (${categoriesInfo.join(",")})
109
+ `;
110
+ for await (const row of this._queryExecutor.createQueryReader({ ecsql: definitionsQuery }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded" })) {
111
+ yield { id: row.id, parentId: row.categoryId };
112
+ }
113
+ }
114
+ async getModelsCategoriesInfo() {
115
+ this._modelsCategoriesInfo ??= (async () => {
116
+ const allModelsCategories = new Map();
117
+ for await (const queriedCategory of this.queryCategories()) {
118
+ let modelCategories = allModelsCategories.get(queriedCategory.modelId);
119
+ if (modelCategories === undefined) {
120
+ modelCategories = { parentDefinitionContainerExists: queriedCategory.parentDefinitionContainerExists, childCategories: [] };
121
+ allModelsCategories.set(queriedCategory.modelId, modelCategories);
122
+ }
123
+ modelCategories.childCategories.push({ id: queriedCategory.id, childCount: queriedCategory.childCount });
124
+ }
125
+ return allModelsCategories;
126
+ })();
127
+ return this._modelsCategoriesInfo;
128
+ }
129
+ async getSubCategoriesInfo() {
130
+ this._subCategoriesInfo ??= (async () => {
131
+ const allSubCategories = new Map();
132
+ const modelsCategoriesInfo = await this.getModelsCategoriesInfo();
133
+ const categoriesWithMoreThanOneSubCategory = new Array();
134
+ for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {
135
+ categoriesWithMoreThanOneSubCategory.push(...modelCategoriesInfo.childCategories.filter((categoryInfo) => categoryInfo.childCount > 1).map((categoryInfo) => categoryInfo.id));
136
+ }
137
+ if (categoriesWithMoreThanOneSubCategory.length === 0) {
138
+ return allSubCategories;
139
+ }
140
+ for await (const queriedSubCategory of this.queryVisibleSubCategories(categoriesWithMoreThanOneSubCategory)) {
141
+ allSubCategories.set(queriedSubCategory.id, { categoryId: queriedSubCategory.parentId });
142
+ }
143
+ return allSubCategories;
144
+ })();
145
+ return this._subCategoriesInfo;
146
+ }
147
+ async getDefinitionContainersInfo() {
148
+ this._definitionContainersInfo ??= (async () => {
149
+ const definitionContainersInfo = new Map();
150
+ const [isDefinitionContainerSupported, modelsCategoriesInfo] = await Promise.all([
151
+ this.getIsDefinitionContainerSupported(),
152
+ this.getModelsCategoriesInfo(),
153
+ ]);
154
+ if (!isDefinitionContainerSupported || modelsCategoriesInfo.size === 0) {
155
+ return definitionContainersInfo;
156
+ }
157
+ for await (const queriedDefinitionContainer of this.queryDefinitionContainers()) {
158
+ const modelCategoriesInfo = modelsCategoriesInfo.get(queriedDefinitionContainer.id);
159
+ definitionContainersInfo.set(queriedDefinitionContainer.id, {
160
+ childCategories: modelCategoriesInfo?.childCategories ?? [],
161
+ modelId: queriedDefinitionContainer.modelId,
162
+ childDefinitionContainers: [],
163
+ parentDefinitionContainerExists: false,
164
+ });
165
+ }
166
+ for (const [definitionContainerId, definitionContainerInfo] of definitionContainersInfo) {
167
+ const parentDefinitionContainer = definitionContainersInfo.get(definitionContainerInfo.modelId);
168
+ if (parentDefinitionContainer !== undefined) {
169
+ parentDefinitionContainer.childDefinitionContainers.push(definitionContainerId);
170
+ definitionContainerInfo.parentDefinitionContainerExists = true;
171
+ }
172
+ }
173
+ return definitionContainersInfo;
174
+ })();
175
+ return this._definitionContainersInfo;
176
+ }
177
+ async getDirectChildDefinitionContainersAndCategories(parentDefinitionContainerIds) {
178
+ const definitionContainersInfo = await this.getDefinitionContainersInfo();
179
+ const result = { definitionContainers: new Array(), categories: new Array() };
180
+ parentDefinitionContainerIds.forEach((parentDefinitionContainerId) => {
181
+ const parentDefinitionContainerInfo = definitionContainersInfo.get(parentDefinitionContainerId);
182
+ if (parentDefinitionContainerInfo !== undefined) {
183
+ result.definitionContainers.push(...parentDefinitionContainerInfo.childDefinitionContainers);
184
+ result.categories.push(...parentDefinitionContainerInfo.childCategories);
185
+ }
186
+ });
187
+ return result;
188
+ }
189
+ async getAllContainedCategories(definitionContainerIds) {
190
+ const result = new Array();
191
+ const definitionContainersInfo = await this.getDefinitionContainersInfo();
192
+ const indirectCategories = await Promise.all(definitionContainerIds.map(async (definitionContainerId) => {
193
+ const definitionContainerInfo = definitionContainersInfo.get(definitionContainerId);
194
+ if (definitionContainerInfo === undefined) {
195
+ return [];
196
+ }
197
+ result.push(...definitionContainerInfo.childCategories.map((category) => category.id));
198
+ return this.getAllContainedCategories(definitionContainerInfo.childDefinitionContainers);
199
+ }));
200
+ for (const categories of indirectCategories) {
201
+ result.push(...categories);
202
+ }
203
+ return result;
204
+ }
205
+ async getInstanceKeyPaths(props) {
206
+ if ("subCategoryId" in props) {
207
+ const subCategoriesInfo = await this.getSubCategoriesInfo();
208
+ const subCategoryInfo = subCategoriesInfo.get(props.subCategoryId);
209
+ if (subCategoryInfo === undefined) {
210
+ return [];
211
+ }
212
+ return [...(await this.getInstanceKeyPaths({ categoryId: subCategoryInfo.categoryId })), { id: props.subCategoryId, className: ClassNameDefinitions_js_1.SUB_CATEGORY_CLASS }];
213
+ }
214
+ if ("categoryId" in props) {
215
+ const modelsCategoriesInfo = await this.getModelsCategoriesInfo();
216
+ for (const [modelId, modelCategoriesInfo] of modelsCategoriesInfo) {
217
+ if (modelCategoriesInfo.childCategories.find((childCategory) => childCategory.id === props.categoryId)) {
218
+ if (!modelCategoriesInfo.parentDefinitionContainerExists) {
219
+ return [{ id: props.categoryId, className: this._categoryClass }];
220
+ }
221
+ return [...(await this.getInstanceKeyPaths({ definitionContainerId: modelId })), { id: props.categoryId, className: this._categoryClass }];
222
+ }
223
+ }
224
+ return [];
225
+ }
226
+ const definitionContainersInfo = await this.getDefinitionContainersInfo();
227
+ const definitionContainerInfo = definitionContainersInfo.get(props.definitionContainerId);
228
+ if (definitionContainerInfo === undefined) {
229
+ return [];
230
+ }
231
+ if (!definitionContainerInfo.parentDefinitionContainerExists) {
232
+ return [{ id: props.definitionContainerId, className: ClassNameDefinitions_js_1.DEFINITION_CONTAINER_CLASS }];
233
+ }
234
+ return [
235
+ ...(await this.getInstanceKeyPaths({ definitionContainerId: definitionContainerInfo.modelId })),
236
+ { id: props.definitionContainerId, className: ClassNameDefinitions_js_1.DEFINITION_CONTAINER_CLASS },
237
+ ];
238
+ }
239
+ async getAllDefinitionContainersAndCategories() {
240
+ const [modelsCategoriesInfo, definitionContainersInfo] = await Promise.all([this.getModelsCategoriesInfo(), this.getDefinitionContainersInfo()]);
241
+ const result = { definitionContainers: [...definitionContainersInfo.keys()], categories: new Array() };
242
+ for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {
243
+ result.categories.push(...modelCategoriesInfo.childCategories.map((childCategory) => childCategory.id));
244
+ }
245
+ return result;
246
+ }
247
+ async getRootDefinitionContainersAndCategories() {
248
+ const [modelsCategoriesInfo, definitionContainersInfo] = await Promise.all([this.getModelsCategoriesInfo(), this.getDefinitionContainersInfo()]);
249
+ const result = { definitionContainers: new Array(), categories: new Array() };
250
+ for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {
251
+ if (!modelCategoriesInfo.parentDefinitionContainerExists) {
252
+ result.categories.push(...modelCategoriesInfo.childCategories);
253
+ }
254
+ }
255
+ for (const [definitionContainerId, definitionContainerInfo] of definitionContainersInfo) {
256
+ if (!definitionContainerInfo.parentDefinitionContainerExists) {
257
+ result.definitionContainers.push(definitionContainerId);
258
+ }
259
+ }
260
+ return result;
261
+ }
262
+ async getSubCategories(categoryId) {
263
+ const subCategoriesInfo = await this.getSubCategoriesInfo();
264
+ const result = new Array();
265
+ for (const [subCategoryId, subCategoryInfo] of subCategoriesInfo) {
266
+ if (subCategoryInfo.categoryId === categoryId) {
267
+ result.push(subCategoryId);
268
+ }
269
+ }
270
+ return result;
271
+ }
272
+ async getIsDefinitionContainerSupported() {
273
+ this._isDefinitionContainerSupported ??= this.queryIsDefinitionContainersSupported();
274
+ return this._isDefinitionContainerSupported;
275
+ }
276
+ }
277
+ exports.CategoriesTreeIdsCache = CategoriesTreeIdsCache;
278
+ /** @internal */
279
+ function getClassesByView(viewType) {
280
+ return viewType === "2d"
281
+ ? { categoryClass: "BisCore.DrawingCategory", categoryElementClass: "BisCore.GeometricElement2d" }
282
+ : { categoryClass: "BisCore.SpatialCategory", categoryElementClass: "BisCore.GeometricElement3d" };
283
+ }
284
+ exports.getClassesByView = getClassesByView;
285
+ //# sourceMappingURL=CategoriesTreeIdsCache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CategoriesTreeIdsCache.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,uEAA2F;AA2B3F,gBAAgB;AAChB,MAAa,sBAAsB;IAQjC,YACU,cAA0C,EAClD,QAAqB;QADb,mBAAc,GAAd,cAAc,CAA4B;QAGlD,MAAM,EAAE,aAAa,EAAE,oBAAoB,EAAE,GAAG,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QAC3E,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;QACpC,IAAI,CAAC,qBAAqB,GAAG,oBAAoB,CAAC;IACpD,CAAC;IAEO,KAAK,CAAC,CAAC,eAAe;QAM5B,MAAM,8BAA8B,GAAG,MAAM,IAAI,CAAC,iCAAiC,EAAE,CAAC;QACtF,MAAM,eAAe,GAAG;;;;;UAMlB,8BAA8B;YAC5B,CAAC,CAAC;gEACkD,oDAA0B;;;cAG5E;YACF,CAAC,CAAC,OACN;;UAEE,IAAI,CAAC,cAAc;eACd,4CAAkB;;;;;oCAKG,IAAI,CAAC,qBAAqB;;KAEzD,CAAC;QACF,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC,EAAE,KAAK,EAAE,eAAe,EAAE,EAAE,EAAE,SAAS,EAAE,oBAAoB,EAAE,KAAK,EAAE,WAAW,EAA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,4BAA4B,EAAE,CAAC;AACvG,CAAC;AAJD,4CAIC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { DEFINITION_CONTAINER_CLASS, SUB_CATEGORY_CLASS } from \"./ClassNameDefinitions.js\";\n\nimport type { Id64Array, Id64String } from \"@itwin/core-bentley\";\nimport type { LimitingECSqlQueryExecutor } from \"@itwin/presentation-hierarchies\";\nimport type { InstanceKey } from \"@itwin/presentation-shared\";\n\ninterface DefinitionContainerInfo {\n modelId: Id64String;\n parentDefinitionContainerExists: boolean;\n childCategories: CategoryInfo[];\n childDefinitionContainers: Id64Array;\n}\n\ninterface CategoriesInfo {\n childCategories: CategoryInfo[];\n parentDefinitionContainerExists: boolean;\n}\n\ninterface CategoryInfo {\n id: Id64String;\n childCount: number;\n}\n\ninterface SubCategoryInfo {\n categoryId: Id64String;\n}\n\n/** @internal */\nexport class CategoriesTreeIdsCache {\n private _definitionContainersInfo: Promise<Map<Id64String, DefinitionContainerInfo>> | undefined;\n private _modelsCategoriesInfo: Promise<Map<Id64String, CategoriesInfo>> | undefined;\n private _subCategoriesInfo: Promise<Map<Id64String, SubCategoryInfo>> | undefined;\n private _categoryClass: string;\n private _categoryElementClass: string;\n private _isDefinitionContainerSupported: Promise<boolean> | undefined;\n\n constructor(\n private _queryExecutor: LimitingECSqlQueryExecutor,\n viewType: \"3d\" | \"2d\",\n ) {\n const { categoryClass, categoryElementClass } = getClassesByView(viewType);\n this._categoryClass = categoryClass;\n this._categoryElementClass = categoryElementClass;\n }\n\n private async *queryCategories(): AsyncIterableIterator<{\n id: Id64String;\n modelId: Id64String;\n parentDefinitionContainerExists: boolean;\n childCount: number;\n }> {\n const isDefinitionContainerSupported = await this.getIsDefinitionContainerSupported();\n const categoriesQuery = `\n SELECT\n this.ECInstanceId id,\n COUNT(sc.ECInstanceId) childCount,\n this.Model.Id modelId,\n ${\n isDefinitionContainerSupported\n ? `\n IIF(this.Model.Id IN (SELECT dc.ECInstanceId FROM ${DEFINITION_CONTAINER_CLASS} dc),\n true,\n false\n )`\n : \"false\"\n } parentDefinitionContainerExists\n FROM\n ${this._categoryClass} this\n JOIN ${SUB_CATEGORY_CLASS} sc ON sc.Parent.Id = this.ECInstanceId\n JOIN BisCore.Model m ON m.ECInstanceId = this.Model.Id\n WHERE\n NOT this.IsPrivate\n AND (NOT m.IsPrivate OR m.ECClassId IS (BisCore.DictionaryModel))\n AND EXISTS (SELECT 1 FROM ${this._categoryElementClass} e WHERE e.Category.Id = this.ECInstanceId)\n GROUP BY this.ECInstanceId\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: categoriesQuery }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { id: row.id, modelId: row.modelId, parentDefinitionContainerExists: row.parentDefinitionContainerExists, childCount: row.childCount };\n }\n }\n\n private async queryIsDefinitionContainersSupported(): Promise<boolean> {\n const query = `\n SELECT\n 1\n FROM\n ECDbMeta.ECSchemaDef s\n JOIN ECDbMeta.ECClassDef c ON c.Schema.Id = s.ECInstanceId\n WHERE\n s.Name = 'BisCore'\n AND c.Name = 'DefinitionContainer'\n `;\n\n for await (const _row of this._queryExecutor.createQueryReader({ ecsql: query })) {\n return true;\n }\n return false;\n }\n\n private async *queryDefinitionContainers(): AsyncIterableIterator<{ id: Id64String; modelId: Id64String }> {\n // DefinitionModel ECInstanceId will always be the same as modeled DefinitionContainer ECInstanceId, if this wasn't the case, we would need to do something like:\n // JOIN BisCore.DefinitionModel dm ON dm.ECInstanceId = ${modelIdAccessor}\n // JOIN BisCore.DefinitionModelBreaksDownDefinitionContainer dr ON dr.SourceECInstanceId = dm.ECInstanceId\n // JOIN BisCore.DefinitionContainer dc ON dc.ECInstanceId = dr.TargetECInstanceId\n const DEFINITION_CONTAINERS_CTE = \"DefinitionContainers\";\n const ctes = [\n `\n ${DEFINITION_CONTAINERS_CTE}(ECInstanceId, ModelId) AS (\n SELECT\n dc.ECInstanceId,\n dc.Model.Id\n FROM\n ${DEFINITION_CONTAINER_CLASS} dc\n WHERE\n dc.ECInstanceId IN (SELECT c.Model.Id FROM ${this._categoryClass} c WHERE NOT c.IsPrivate)\n AND NOT dc.IsPrivate\n\n UNION ALL\n\n SELECT\n pdc.ECInstanceId,\n pdc.Model.Id\n FROM\n ${DEFINITION_CONTAINERS_CTE} cdc\n JOIN ${DEFINITION_CONTAINER_CLASS} pdc ON pdc.ECInstanceId = cdc.ModelId\n WHERE\n NOT pdc.IsPrivate\n )\n `,\n ];\n const definitionsQuery = `\n SELECT dc.ECInstanceId id, dc.ModelId modelId FROM ${DEFINITION_CONTAINERS_CTE} dc GROUP BY dc.ECInstanceId\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ctes, ecsql: definitionsQuery }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { id: row.id, modelId: row.modelId };\n }\n }\n\n private async *queryVisibleSubCategories(categoriesInfo: Id64Array): AsyncIterableIterator<{ id: Id64String; parentId: Id64String }> {\n const definitionsQuery = `\n SELECT\n sc.ECInstanceId id,\n sc.Parent.Id categoryId\n FROM\n ${SUB_CATEGORY_CLASS} sc\n WHERE\n NOT sc.IsPrivate\n AND sc.Parent.Id IN (${categoriesInfo.join(\",\")})\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: definitionsQuery }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { id: row.id, parentId: row.categoryId };\n }\n }\n\n private async getModelsCategoriesInfo() {\n this._modelsCategoriesInfo ??= (async () => {\n const allModelsCategories = new Map<Id64String, CategoriesInfo>();\n for await (const queriedCategory of this.queryCategories()) {\n let modelCategories = allModelsCategories.get(queriedCategory.modelId);\n if (modelCategories === undefined) {\n modelCategories = { parentDefinitionContainerExists: queriedCategory.parentDefinitionContainerExists, childCategories: [] };\n allModelsCategories.set(queriedCategory.modelId, modelCategories);\n }\n modelCategories.childCategories.push({ id: queriedCategory.id, childCount: queriedCategory.childCount });\n }\n return allModelsCategories;\n })();\n return this._modelsCategoriesInfo;\n }\n\n private async getSubCategoriesInfo() {\n this._subCategoriesInfo ??= (async () => {\n const allSubCategories = new Map<Id64String, SubCategoryInfo>();\n const modelsCategoriesInfo = await this.getModelsCategoriesInfo();\n const categoriesWithMoreThanOneSubCategory = new Array<Id64String>();\n for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {\n categoriesWithMoreThanOneSubCategory.push(\n ...modelCategoriesInfo.childCategories.filter((categoryInfo) => categoryInfo.childCount > 1).map((categoryInfo) => categoryInfo.id),\n );\n }\n\n if (categoriesWithMoreThanOneSubCategory.length === 0) {\n return allSubCategories;\n }\n\n for await (const queriedSubCategory of this.queryVisibleSubCategories(categoriesWithMoreThanOneSubCategory)) {\n allSubCategories.set(queriedSubCategory.id, { categoryId: queriedSubCategory.parentId });\n }\n return allSubCategories;\n })();\n return this._subCategoriesInfo;\n }\n\n private async getDefinitionContainersInfo() {\n this._definitionContainersInfo ??= (async () => {\n const definitionContainersInfo = new Map<Id64String, DefinitionContainerInfo>();\n const [isDefinitionContainerSupported, modelsCategoriesInfo] = await Promise.all([\n this.getIsDefinitionContainerSupported(),\n this.getModelsCategoriesInfo(),\n ]);\n if (!isDefinitionContainerSupported || modelsCategoriesInfo.size === 0) {\n return definitionContainersInfo;\n }\n\n for await (const queriedDefinitionContainer of this.queryDefinitionContainers()) {\n const modelCategoriesInfo = modelsCategoriesInfo.get(queriedDefinitionContainer.id);\n\n definitionContainersInfo.set(queriedDefinitionContainer.id, {\n childCategories: modelCategoriesInfo?.childCategories ?? [],\n modelId: queriedDefinitionContainer.modelId,\n childDefinitionContainers: [],\n parentDefinitionContainerExists: false,\n });\n }\n\n for (const [definitionContainerId, definitionContainerInfo] of definitionContainersInfo) {\n const parentDefinitionContainer = definitionContainersInfo.get(definitionContainerInfo.modelId);\n if (parentDefinitionContainer !== undefined) {\n parentDefinitionContainer.childDefinitionContainers.push(definitionContainerId);\n definitionContainerInfo.parentDefinitionContainerExists = true;\n }\n }\n\n return definitionContainersInfo;\n })();\n return this._definitionContainersInfo;\n }\n\n public async getDirectChildDefinitionContainersAndCategories(\n parentDefinitionContainerIds: Id64Array,\n ): Promise<{ categories: CategoryInfo[]; definitionContainers: Id64Array }> {\n const definitionContainersInfo = await this.getDefinitionContainersInfo();\n\n const result = { definitionContainers: new Array<Id64String>(), categories: new Array<CategoryInfo>() };\n\n parentDefinitionContainerIds.forEach((parentDefinitionContainerId) => {\n const parentDefinitionContainerInfo = definitionContainersInfo.get(parentDefinitionContainerId);\n if (parentDefinitionContainerInfo !== undefined) {\n result.definitionContainers.push(...parentDefinitionContainerInfo.childDefinitionContainers);\n result.categories.push(...parentDefinitionContainerInfo.childCategories);\n }\n });\n return result;\n }\n\n public async getAllContainedCategories(definitionContainerIds: Id64Array): Promise<Id64Array> {\n const result = new Array<Id64String>();\n\n const definitionContainersInfo = await this.getDefinitionContainersInfo();\n const indirectCategories = await Promise.all(\n definitionContainerIds.map(async (definitionContainerId) => {\n const definitionContainerInfo = definitionContainersInfo.get(definitionContainerId);\n if (definitionContainerInfo === undefined) {\n return [];\n }\n result.push(...definitionContainerInfo.childCategories.map((category) => category.id));\n return this.getAllContainedCategories(definitionContainerInfo.childDefinitionContainers);\n }),\n );\n for (const categories of indirectCategories) {\n result.push(...categories);\n }\n\n return result;\n }\n\n public async getInstanceKeyPaths(\n props: { categoryId: Id64String } | { definitionContainerId: Id64String } | { subCategoryId: Id64String },\n ): Promise<InstanceKey[]> {\n if (\"subCategoryId\" in props) {\n const subCategoriesInfo = await this.getSubCategoriesInfo();\n const subCategoryInfo = subCategoriesInfo.get(props.subCategoryId);\n if (subCategoryInfo === undefined) {\n return [];\n }\n return [...(await this.getInstanceKeyPaths({ categoryId: subCategoryInfo.categoryId })), { id: props.subCategoryId, className: SUB_CATEGORY_CLASS }];\n }\n\n if (\"categoryId\" in props) {\n const modelsCategoriesInfo = await this.getModelsCategoriesInfo();\n for (const [modelId, modelCategoriesInfo] of modelsCategoriesInfo) {\n if (modelCategoriesInfo.childCategories.find((childCategory) => childCategory.id === props.categoryId)) {\n if (!modelCategoriesInfo.parentDefinitionContainerExists) {\n return [{ id: props.categoryId, className: this._categoryClass }];\n }\n\n return [...(await this.getInstanceKeyPaths({ definitionContainerId: modelId })), { id: props.categoryId, className: this._categoryClass }];\n }\n }\n return [];\n }\n\n const definitionContainersInfo = await this.getDefinitionContainersInfo();\n const definitionContainerInfo = definitionContainersInfo.get(props.definitionContainerId);\n if (definitionContainerInfo === undefined) {\n return [];\n }\n\n if (!definitionContainerInfo.parentDefinitionContainerExists) {\n return [{ id: props.definitionContainerId, className: DEFINITION_CONTAINER_CLASS }];\n }\n\n return [\n ...(await this.getInstanceKeyPaths({ definitionContainerId: definitionContainerInfo.modelId })),\n { id: props.definitionContainerId, className: DEFINITION_CONTAINER_CLASS },\n ];\n }\n\n public async getAllDefinitionContainersAndCategories(): Promise<{ categories: Id64Array; definitionContainers: Id64Array }> {\n const [modelsCategoriesInfo, definitionContainersInfo] = await Promise.all([this.getModelsCategoriesInfo(), this.getDefinitionContainersInfo()]);\n const result = { definitionContainers: [...definitionContainersInfo.keys()], categories: new Array<Id64String>() };\n for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {\n result.categories.push(...modelCategoriesInfo.childCategories.map((childCategory) => childCategory.id));\n }\n\n return result;\n }\n\n public async getRootDefinitionContainersAndCategories(): Promise<{ categories: CategoryInfo[]; definitionContainers: Id64Array }> {\n const [modelsCategoriesInfo, definitionContainersInfo] = await Promise.all([this.getModelsCategoriesInfo(), this.getDefinitionContainersInfo()]);\n const result = { definitionContainers: new Array<Id64String>(), categories: new Array<CategoryInfo>() };\n for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {\n if (!modelCategoriesInfo.parentDefinitionContainerExists) {\n result.categories.push(...modelCategoriesInfo.childCategories);\n }\n }\n\n for (const [definitionContainerId, definitionContainerInfo] of definitionContainersInfo) {\n if (!definitionContainerInfo.parentDefinitionContainerExists) {\n result.definitionContainers.push(definitionContainerId);\n }\n }\n return result;\n }\n\n public async getSubCategories(categoryId: Id64String): Promise<Id64Array> {\n const subCategoriesInfo = await this.getSubCategoriesInfo();\n const result = new Array<Id64String>();\n for (const [subCategoryId, subCategoryInfo] of subCategoriesInfo) {\n if (subCategoryInfo.categoryId === categoryId) {\n result.push(subCategoryId);\n }\n }\n return result;\n }\n\n public async getIsDefinitionContainerSupported(): Promise<boolean> {\n this._isDefinitionContainerSupported ??= this.queryIsDefinitionContainersSupported();\n return this._isDefinitionContainerSupported;\n }\n}\n\n/** @internal */\nexport function getClassesByView(viewType: \"2d\" | \"3d\") {\n return viewType === \"2d\"\n ? { categoryClass: \"BisCore.DrawingCategory\", categoryElementClass: \"BisCore.GeometricElement2d\" }\n : { categoryClass: \"BisCore.SpatialCategory\", categoryElementClass: \"BisCore.GeometricElement3d\" };\n}\n"]}
@@ -0,0 +1,26 @@
1
+ import type { HierarchyNodeKey } from "@itwin/presentation-hierarchies";
2
+ interface CategoriesTreeNode {
3
+ key: HierarchyNodeKey;
4
+ extendedData?: {
5
+ [id: string]: any;
6
+ };
7
+ }
8
+ /**
9
+ * @internal
10
+ */
11
+ export declare namespace CategoriesTreeNode {
12
+ /**
13
+ * Determines if node represents a definition container.
14
+ */
15
+ const isDefinitionContainerNode: (node: Pick<CategoriesTreeNode, "extendedData">) => boolean | undefined;
16
+ /**
17
+ * Determines if node represents a category.
18
+ */
19
+ const isCategoryNode: (node: Pick<CategoriesTreeNode, "extendedData">) => boolean | undefined;
20
+ /**
21
+ * Determines if node represents a sub-category.
22
+ */
23
+ const isSubCategoryNode: (node: Pick<CategoriesTreeNode, "extendedData">) => boolean | undefined;
24
+ }
25
+ export {};
26
+ //# sourceMappingURL=CategoriesTreeNode.d.ts.map