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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/CHANGELOG.md +34 -1
  2. package/README.md +1 -3
  3. package/lib/esm/tree-widget-react/components/TreeWidgetUiItemsProvider.js +3 -2
  4. package/lib/esm/tree-widget-react/components/TreeWidgetUiItemsProvider.js.map +1 -1
  5. package/lib/esm/tree-widget-react/components/tree-header/ErrorState.js +2 -2
  6. package/lib/esm/tree-widget-react/components/tree-header/ErrorState.js.map +1 -1
  7. package/lib/esm/tree-widget-react/components/tree-header/SearchBox.js +4 -4
  8. package/lib/esm/tree-widget-react/components/tree-header/SearchBox.js.map +1 -1
  9. package/lib/esm/tree-widget-react/components/tree-header/SelectableTree.css +1 -1
  10. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js +6 -6
  11. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js.map +1 -1
  12. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.d.ts +10 -2
  13. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js +246 -129
  14. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js.map +1 -1
  15. package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js +69 -20
  16. package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js.map +1 -1
  17. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.d.ts +54 -0
  18. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js +280 -0
  19. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js.map +1 -0
  20. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.d.ts +26 -0
  21. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.js +23 -0
  22. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.js.map +1 -0
  23. package/lib/esm/tree-widget-react/components/trees/categories-tree/{CategoriesVisibilityHandler.d.ts → internal/CategoriesVisibilityHandler.d.ts} +18 -9
  24. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js +214 -0
  25. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js.map +1 -0
  26. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.d.ts +7 -0
  27. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.js +11 -0
  28. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.js.map +1 -0
  29. package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.d.ts +0 -4
  30. package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js +1 -1
  31. package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js.map +1 -1
  32. package/lib/esm/tree-widget-react/components/trees/common/FocusedInstancesContext.d.ts +28 -4
  33. package/lib/esm/tree-widget-react/components/trees/common/FocusedInstancesContext.js +73 -2
  34. package/lib/esm/tree-widget-react/components/trees/common/FocusedInstancesContext.js.map +1 -1
  35. package/lib/esm/tree-widget-react/components/trees/common/components/Tree.d.ts +1 -1
  36. package/lib/esm/tree-widget-react/components/trees/common/components/Tree.js +3 -4
  37. package/lib/esm/tree-widget-react/components/trees/common/components/Tree.js.map +1 -1
  38. package/lib/esm/tree-widget-react/components/trees/common/components/TreeNodeVisibilityButton.css +2 -1
  39. package/lib/esm/tree-widget-react/components/trees/common/components/TreeNodeVisibilityButton.js +6 -6
  40. package/lib/esm/tree-widget-react/components/trees/common/components/TreeNodeVisibilityButton.js.map +1 -1
  41. package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTree.js +9 -9
  42. package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTree.js.map +1 -1
  43. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js +15 -15
  44. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -1
  45. package/lib/esm/tree-widget-react/components/trees/index.d.ts +1 -0
  46. package/lib/esm/tree-widget-react/components/trees/index.js +1 -0
  47. package/lib/esm/tree-widget-react/components/trees/index.js.map +1 -1
  48. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js +12 -12
  49. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js.map +1 -1
  50. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.d.ts +6 -1
  51. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.js +7 -3
  52. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
  53. package/lib/esm/tree-widget-react/components/trees/models-tree/UseModelsTree.js +11 -11
  54. package/lib/esm/tree-widget-react/components/trees/models-tree/UseModelsTree.js.map +1 -1
  55. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.js.map +1 -1
  56. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.d.ts +5 -0
  57. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js +45 -0
  58. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js.map +1 -1
  59. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.d.ts +2 -1
  60. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js +128 -38
  61. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
  62. package/lib/public/locales/en/TreeWidget.json +15 -4
  63. package/package.json +3 -6
  64. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesVisibilityHandler.js +0 -87
  65. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesVisibilityHandler.js.map +0 -1
  66. package/lib/esm/tree-widget-react/components/trees/common/FocusedInstancesContextProvider.d.ts +0 -7
  67. package/lib/esm/tree-widget-react/components/trees/common/FocusedInstancesContextProvider.js +0 -66
  68. package/lib/esm/tree-widget-react/components/trees/common/FocusedInstancesContextProvider.js.map +0 -1
@@ -4,23 +4,36 @@ import { jsx as _jsx } from "react/jsx-runtime";
4
4
  * See LICENSE.md in the project root for license terms and full copyright notice.
5
5
  *--------------------------------------------------------------------------------------------*/
6
6
  import { useCallback, useMemo, useState } from "react";
7
+ import { assert } from "@itwin/core-bentley";
8
+ import categorySvg from "@itwin/itwinui-icons/bis-category-3d.svg";
9
+ import subcategorySvg from "@itwin/itwinui-icons/bis-category-subcategory.svg";
10
+ import definitionContainerSvg from "@itwin/itwinui-icons/bis-definitions-container.svg";
7
11
  import { Text } from "@itwin/itwinui-react/bricks";
8
- import { HierarchyNodeIdentifier } from "@itwin/presentation-hierarchies";
12
+ import { createECSqlQueryExecutor } from "@itwin/presentation-core-interop";
13
+ import { HierarchyFilteringPath, HierarchyNodeIdentifier } from "@itwin/presentation-hierarchies";
9
14
  import { TreeWidget } from "../../../TreeWidget.js";
10
15
  import { EmptyTreeContent } from "../common/components/EmptyTreeContent.js";
11
16
  import { FilterLimitExceededError } from "../common/TreeErrors.js";
12
17
  import { useTelemetryContext } from "../common/UseTelemetryContext.js";
13
18
  import { CategoriesTreeDefinition } from "./CategoriesTreeDefinition.js";
14
- import { CategoriesVisibilityHandler } from "./CategoriesVisibilityHandler.js";
19
+ import { CategoriesTreeIdsCache } from "./internal/CategoriesTreeIdsCache.js";
20
+ import { CategoriesVisibilityHandler } from "./internal/CategoriesVisibilityHandler.js";
21
+ import { DEFINITION_CONTAINER_CLASS, SUB_CATEGORY_CLASS } from "./internal/ClassNameDefinitions.js";
15
22
  /**
16
23
  * Custom hook to create and manage state for the categories tree.
17
24
  * @beta
18
25
  */
19
26
  export function useCategoriesTree({ filter, activeView, onCategoriesFiltered, emptyTreeContent }) {
20
27
  const [filteringError, setFilteringError] = useState();
28
+ const viewType = activeView.view.is2d() ? "2d" : "3d";
29
+ const iModel = activeView.iModel;
30
+ const idsCache = useMemo(() => {
31
+ return new CategoriesTreeIdsCache(createECSqlQueryExecutor(iModel), viewType);
32
+ }, [viewType, iModel]);
21
33
  const visibilityHandlerFactory = useCallback(() => {
22
34
  const visibilityHandler = new CategoriesVisibilityHandler({
23
35
  viewport: activeView,
36
+ idsCache,
24
37
  });
25
38
  return {
26
39
  getVisibilityStatus: async (node) => visibilityHandler.getVisibilityStatus(node),
@@ -28,11 +41,11 @@ export function useCategoriesTree({ filter, activeView, onCategoriesFiltered, em
28
41
  onVisibilityChange: visibilityHandler.onVisibilityChange,
29
42
  dispose: () => visibilityHandler.dispose(),
30
43
  };
31
- }, [activeView]);
44
+ }, [activeView, idsCache]);
32
45
  const { onFeatureUsed } = useTelemetryContext();
33
46
  const getHierarchyDefinition = useCallback((props) => {
34
- return new CategoriesTreeDefinition({ ...props, viewType: activeView.view.is2d() ? "2d" : "3d" });
35
- }, [activeView]);
47
+ return new CategoriesTreeDefinition({ ...props, viewType, idsCache });
48
+ }, [viewType, idsCache]);
36
49
  const getFilteredPaths = useMemo(() => {
37
50
  setFilteringError(undefined);
38
51
  onCategoriesFiltered?.(undefined);
@@ -42,8 +55,8 @@ export function useCategoriesTree({ filter, activeView, onCategoriesFiltered, em
42
55
  return async ({ imodelAccess }) => {
43
56
  onFeatureUsed({ featureId: "filtering", reportInteraction: true });
44
57
  try {
45
- const paths = await CategoriesTreeDefinition.createInstanceKeyPaths({ imodelAccess, label: filter, viewType: activeView.view.is2d() ? "2d" : "3d" });
46
- onCategoriesFiltered?.(getCategories(paths));
58
+ const paths = await CategoriesTreeDefinition.createInstanceKeyPaths({ imodelAccess, label: filter, viewType, idsCache });
59
+ onCategoriesFiltered?.(await getCategoriesFromPaths(paths, idsCache));
47
60
  return paths;
48
61
  }
49
62
  catch (e) {
@@ -56,7 +69,7 @@ export function useCategoriesTree({ filter, activeView, onCategoriesFiltered, em
56
69
  return [];
57
70
  }
58
71
  };
59
- }, [filter, activeView, onFeatureUsed, onCategoriesFiltered]);
72
+ }, [filter, viewType, onFeatureUsed, onCategoriesFiltered, idsCache]);
60
73
  return {
61
74
  categoriesTreeProps: {
62
75
  treeName: "categories-tree-v2",
@@ -72,22 +85,48 @@ export function useCategoriesTree({ filter, activeView, onCategoriesFiltered, em
72
85
  },
73
86
  };
74
87
  }
75
- function getCategories(paths) {
88
+ async function getCategoriesFromPaths(paths, idsCache) {
76
89
  if (!paths) {
77
90
  return undefined;
78
91
  }
79
92
  const categories = new Map();
80
93
  for (const path of paths) {
81
- const currPath = Array.isArray(path) ? path : path.path;
82
- const [category, subCategory] = currPath;
83
- if (!HierarchyNodeIdentifier.isInstanceNodeIdentifier(category)) {
94
+ const currPath = HierarchyFilteringPath.normalize(path).path;
95
+ if (currPath.length === 0) {
84
96
  continue;
85
97
  }
86
- if (!categories.has(category.id)) {
87
- categories.set(category.id, []);
98
+ let category;
99
+ let subCategory;
100
+ const lastNode = currPath[currPath.length - 1];
101
+ if (!HierarchyNodeIdentifier.isInstanceNodeIdentifier(lastNode)) {
102
+ continue;
103
+ }
104
+ if (lastNode.className === DEFINITION_CONTAINER_CLASS) {
105
+ const definitionContainerCategories = await idsCache.getAllContainedCategories([lastNode.id]);
106
+ for (const categoryId of definitionContainerCategories) {
107
+ const value = categories.get(categoryId);
108
+ if (value === undefined) {
109
+ categories.set(categoryId, []);
110
+ }
111
+ }
112
+ continue;
113
+ }
114
+ if (lastNode.className === SUB_CATEGORY_CLASS) {
115
+ const secondToLastNode = currPath.length > 1 ? currPath[currPath.length - 2] : undefined;
116
+ assert(secondToLastNode !== undefined && HierarchyNodeIdentifier.isInstanceNodeIdentifier(secondToLastNode));
117
+ subCategory = lastNode;
118
+ category = secondToLastNode;
88
119
  }
89
- if (subCategory && HierarchyNodeIdentifier.isInstanceNodeIdentifier(subCategory)) {
90
- categories.get(category.id).push(subCategory.id);
120
+ else {
121
+ category = lastNode;
122
+ }
123
+ let entry = categories.get(category.id);
124
+ if (entry === undefined) {
125
+ entry = [];
126
+ categories.set(category.id, entry);
127
+ }
128
+ if (subCategory) {
129
+ entry.push(subCategory.id);
91
130
  }
92
131
  }
93
132
  return [...categories.entries()].map(([categoryId, subCategoryIds]) => ({
@@ -105,11 +144,21 @@ function getEmptyTreeContentComponent(filter, error, emptyTreeContent) {
105
144
  if (emptyTreeContent) {
106
145
  return emptyTreeContent;
107
146
  }
108
- return _jsx(EmptyTreeContent, { icon: categoryIcon });
147
+ return _jsx(EmptyTreeContent, { icon: categorySvg });
109
148
  }
110
- const categoryIcon = new URL("@itwin/itwinui-icons/bis-category-3d.svg", import.meta.url).href;
111
- function getIcon() {
112
- return categoryIcon;
149
+ function getIcon(node) {
150
+ if (node.extendedData?.imageId === undefined) {
151
+ return undefined;
152
+ }
153
+ switch (node.extendedData.imageId) {
154
+ case "icon-layers":
155
+ return categorySvg;
156
+ case "icon-layers-isolate":
157
+ return subcategorySvg;
158
+ case "icon-definition-container":
159
+ return definitionContainerSvg;
160
+ }
161
+ return undefined;
113
162
  }
114
163
  function getSublabel(node) {
115
164
  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,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MA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AW,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,4BAA4B,CAAC,MAAe,EAAE,KAAoC,EAAE,gBAAkC;IAC7H,IAAI,KAAK,EAAE;QACT,OAAO,KAAC,IAAI,cAAE,UAAU,CAAC,SAAS,CAAC,4BAA4B,KAAK,EAAE,CAAC,GAAQ,CAAC;KACjF;IACD,IAAI,MAAM,EAAE;QACV,OAAO,KAAC,IAAI,cAAE,UAAU,CAAC,SAAS,CAAC,oCAAoC,EAAE,EAAE,MAAM,EAAE,CAAC,GAAQ,CAAC;KAC9F;IACD,IAAI,gBAAgB,EAAE;QACpB,OAAO,gBAAgB,CAAC;KACzB;IACD,OAAO,KAAC,gBAAgB,IAAC,IAAI,EAAE,YAAY,GAAI,CAAC;AAClD,CAAC;AAED,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,0CAA0C,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;AAC/F,SAAS,OAAO;IACd,OAAO,YAAY,CAAC;AACtB,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 { Text } from \"@itwin/itwinui-react/bricks\";\nimport { HierarchyNodeIdentifier } from \"@itwin/presentation-hierarchies\";\nimport { TreeWidget } from \"../../../TreeWidget.js\";\nimport { EmptyTreeContent } from \"../common/components/EmptyTreeContent.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 { ReactNode } 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 { 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 activeView: Viewport;\n onCategoriesFiltered?: (categories: CategoryInfo[] | undefined) => void;\n filter?: string;\n emptyTreeContent?: ReactNode;\n}\n\n/** @beta */\ninterface UseCategoriesTreeResult {\n categoriesTreeProps: Pick<\n VisibilityTreeProps,\n \"treeName\" | \"getHierarchyDefinition\" | \"getFilteredPaths\" | \"visibilityHandlerFactory\" | \"highlight\" | \"emptyTreeContent\"\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, emptyTreeContent }: 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 emptyTreeContent: getEmptyTreeContentComponent(filter, filteringError, emptyTreeContent),\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 getEmptyTreeContentComponent(filter?: string, error?: CategoriesTreeFilteringError, emptyTreeContent?: React.ReactNode) {\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 if (emptyTreeContent) {\n return emptyTreeContent;\n }\n return <EmptyTreeContent icon={categoryIcon} />;\n}\n\nconst categoryIcon = new URL(\"@itwin/itwinui-icons/bis-category-3d.svg\", import.meta.url).href;\nfunction getIcon() {\n return categoryIcon;\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,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,WAAW,MAAM,0CAA0C,CAAC;AACnE,OAAO,cAAc,MAAM,mDAAmD,CAAC;AAC/E,OAAO,sBAAs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,OAAO,EAAE;QACjC,KAAK,aAAa;YAChB,OAAO,WAAW,CAAC;QACrB,KAAK,qBAAqB;YACxB,OAAO,cAAc,CAAC;QACxB,KAAK,2BAA2B;YAC9B,OAAO,sBAAsB,CAAC;KACjC;IAED,OAAO,SAAS,CAAC;AACnB,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 { assert } from \"@itwin/core-bentley\";\nimport categorySvg from \"@itwin/itwinui-icons/bis-category-3d.svg\";\nimport subcategorySvg from \"@itwin/itwinui-icons/bis-category-subcategory.svg\";\nimport definitionContainerSvg from \"@itwin/itwinui-icons/bis-definitions-container.svg\";\nimport { Text } from \"@itwin/itwinui-react/bricks\";\nimport { createECSqlQueryExecutor } from \"@itwin/presentation-core-interop\";\nimport { HierarchyFilteringPath, HierarchyNodeIdentifier } from \"@itwin/presentation-hierarchies\";\nimport { TreeWidget } from \"../../../TreeWidget.js\";\nimport { EmptyTreeContent } from \"../common/components/EmptyTreeContent.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 { ReactNode } from \"react\";\nimport type { Id64String } from \"@itwin/core-bentley\";\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 activeView: Viewport;\n onCategoriesFiltered?: (categories: CategoryInfo[] | undefined) => void;\n filter?: string;\n emptyTreeContent?: ReactNode;\n}\n\n/** @beta */\ninterface UseCategoriesTreeResult {\n categoriesTreeProps: Pick<\n VisibilityTreeProps,\n \"treeName\" | \"getHierarchyDefinition\" | \"getFilteredPaths\" | \"visibilityHandlerFactory\" | \"highlight\" | \"emptyTreeContent\"\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, emptyTreeContent }: 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 emptyTreeContent: getEmptyTreeContentComponent(filter, filteringError, emptyTreeContent),\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 getEmptyTreeContentComponent(filter?: string, error?: CategoriesTreeFilteringError, emptyTreeContent?: React.ReactNode) {\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 if (emptyTreeContent) {\n return emptyTreeContent;\n }\n return <EmptyTreeContent icon={categorySvg} />;\n}\n\n\nfunction getIcon(node: PresentationHierarchyNode): string | undefined {\n if (node.extendedData?.imageId === undefined) {\n return undefined;\n }\n\n switch (node.extendedData.imageId) {\n case \"icon-layers\":\n return categorySvg;\n case \"icon-layers-isolate\":\n return subcategorySvg;\n case \"icon-definition-container\":\n return definitionContainerSvg;\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,280 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ import { DEFINITION_CONTAINER_CLASS, SUB_CATEGORY_CLASS } from "./ClassNameDefinitions.js";
6
+ /** @internal */
7
+ export class CategoriesTreeIdsCache {
8
+ constructor(_queryExecutor, viewType) {
9
+ this._queryExecutor = _queryExecutor;
10
+ const { categoryClass, categoryElementClass } = getClassesByView(viewType);
11
+ this._categoryClass = categoryClass;
12
+ this._categoryElementClass = categoryElementClass;
13
+ }
14
+ async *queryCategories() {
15
+ const isDefinitionContainerSupported = await this.getIsDefinitionContainerSupported();
16
+ const categoriesQuery = `
17
+ SELECT
18
+ this.ECInstanceId id,
19
+ COUNT(sc.ECInstanceId) childCount,
20
+ this.Model.Id modelId,
21
+ ${isDefinitionContainerSupported
22
+ ? `
23
+ IIF(this.Model.Id IN (SELECT dc.ECInstanceId FROM ${DEFINITION_CONTAINER_CLASS} dc),
24
+ true,
25
+ false
26
+ )`
27
+ : "false"} parentDefinitionContainerExists
28
+ FROM
29
+ ${this._categoryClass} this
30
+ JOIN ${SUB_CATEGORY_CLASS} sc ON sc.Parent.Id = this.ECInstanceId
31
+ JOIN BisCore.Model m ON m.ECInstanceId = this.Model.Id
32
+ WHERE
33
+ NOT this.IsPrivate
34
+ AND (NOT m.IsPrivate OR m.ECClassId IS (BisCore.DictionaryModel))
35
+ AND EXISTS (SELECT 1 FROM ${this._categoryElementClass} e WHERE e.Category.Id = this.ECInstanceId)
36
+ GROUP BY this.ECInstanceId
37
+ `;
38
+ for await (const row of this._queryExecutor.createQueryReader({ ecsql: categoriesQuery }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded" })) {
39
+ yield { id: row.id, modelId: row.modelId, parentDefinitionContainerExists: row.parentDefinitionContainerExists, childCount: row.childCount };
40
+ }
41
+ }
42
+ async queryIsDefinitionContainersSupported() {
43
+ const query = `
44
+ SELECT
45
+ 1
46
+ FROM
47
+ ECDbMeta.ECSchemaDef s
48
+ JOIN ECDbMeta.ECClassDef c ON c.Schema.Id = s.ECInstanceId
49
+ WHERE
50
+ s.Name = 'BisCore'
51
+ AND c.Name = 'DefinitionContainer'
52
+ `;
53
+ for await (const _row of this._queryExecutor.createQueryReader({ ecsql: query })) {
54
+ return true;
55
+ }
56
+ return false;
57
+ }
58
+ async *queryDefinitionContainers() {
59
+ // DefinitionModel ECInstanceId will always be the same as modeled DefinitionContainer ECInstanceId, if this wasn't the case, we would need to do something like:
60
+ // JOIN BisCore.DefinitionModel dm ON dm.ECInstanceId = ${modelIdAccessor}
61
+ // JOIN BisCore.DefinitionModelBreaksDownDefinitionContainer dr ON dr.SourceECInstanceId = dm.ECInstanceId
62
+ // JOIN BisCore.DefinitionContainer dc ON dc.ECInstanceId = dr.TargetECInstanceId
63
+ const DEFINITION_CONTAINERS_CTE = "DefinitionContainers";
64
+ const ctes = [
65
+ `
66
+ ${DEFINITION_CONTAINERS_CTE}(ECInstanceId, ModelId) AS (
67
+ SELECT
68
+ dc.ECInstanceId,
69
+ dc.Model.Id
70
+ FROM
71
+ ${DEFINITION_CONTAINER_CLASS} dc
72
+ WHERE
73
+ dc.ECInstanceId IN (SELECT c.Model.Id FROM ${this._categoryClass} c WHERE NOT c.IsPrivate)
74
+ AND NOT dc.IsPrivate
75
+
76
+ UNION ALL
77
+
78
+ SELECT
79
+ pdc.ECInstanceId,
80
+ pdc.Model.Id
81
+ FROM
82
+ ${DEFINITION_CONTAINERS_CTE} cdc
83
+ JOIN ${DEFINITION_CONTAINER_CLASS} pdc ON pdc.ECInstanceId = cdc.ModelId
84
+ WHERE
85
+ NOT pdc.IsPrivate
86
+ )
87
+ `,
88
+ ];
89
+ const definitionsQuery = `
90
+ SELECT dc.ECInstanceId id, dc.ModelId modelId FROM ${DEFINITION_CONTAINERS_CTE} dc GROUP BY dc.ECInstanceId
91
+ `;
92
+ for await (const row of this._queryExecutor.createQueryReader({ ctes, ecsql: definitionsQuery }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded" })) {
93
+ yield { id: row.id, modelId: row.modelId };
94
+ }
95
+ }
96
+ async *queryVisibleSubCategories(categoriesInfo) {
97
+ const definitionsQuery = `
98
+ SELECT
99
+ sc.ECInstanceId id,
100
+ sc.Parent.Id categoryId
101
+ FROM
102
+ ${SUB_CATEGORY_CLASS} sc
103
+ WHERE
104
+ NOT sc.IsPrivate
105
+ AND sc.Parent.Id IN (${categoriesInfo.join(",")})
106
+ `;
107
+ for await (const row of this._queryExecutor.createQueryReader({ ecsql: definitionsQuery }, { rowFormat: "ECSqlPropertyNames", limit: "unbounded" })) {
108
+ yield { id: row.id, parentId: row.categoryId };
109
+ }
110
+ }
111
+ async getModelsCategoriesInfo() {
112
+ this._modelsCategoriesInfo ??= (async () => {
113
+ const allModelsCategories = new Map();
114
+ for await (const queriedCategory of this.queryCategories()) {
115
+ let modelCategories = allModelsCategories.get(queriedCategory.modelId);
116
+ if (modelCategories === undefined) {
117
+ modelCategories = { parentDefinitionContainerExists: queriedCategory.parentDefinitionContainerExists, childCategories: [] };
118
+ allModelsCategories.set(queriedCategory.modelId, modelCategories);
119
+ }
120
+ modelCategories.childCategories.push({ id: queriedCategory.id, childCount: queriedCategory.childCount });
121
+ }
122
+ return allModelsCategories;
123
+ })();
124
+ return this._modelsCategoriesInfo;
125
+ }
126
+ async getSubCategoriesInfo() {
127
+ this._subCategoriesInfo ??= (async () => {
128
+ const allSubCategories = new Map();
129
+ const modelsCategoriesInfo = await this.getModelsCategoriesInfo();
130
+ const categoriesWithMoreThanOneSubCategory = new Array();
131
+ for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {
132
+ categoriesWithMoreThanOneSubCategory.push(...modelCategoriesInfo.childCategories.filter((categoryInfo) => categoryInfo.childCount > 1).map((categoryInfo) => categoryInfo.id));
133
+ }
134
+ if (categoriesWithMoreThanOneSubCategory.length === 0) {
135
+ return allSubCategories;
136
+ }
137
+ for await (const queriedSubCategory of this.queryVisibleSubCategories(categoriesWithMoreThanOneSubCategory)) {
138
+ allSubCategories.set(queriedSubCategory.id, { categoryId: queriedSubCategory.parentId });
139
+ }
140
+ return allSubCategories;
141
+ })();
142
+ return this._subCategoriesInfo;
143
+ }
144
+ async getDefinitionContainersInfo() {
145
+ this._definitionContainersInfo ??= (async () => {
146
+ const definitionContainersInfo = new Map();
147
+ const [isDefinitionContainerSupported, modelsCategoriesInfo] = await Promise.all([
148
+ this.getIsDefinitionContainerSupported(),
149
+ this.getModelsCategoriesInfo(),
150
+ ]);
151
+ if (!isDefinitionContainerSupported || modelsCategoriesInfo.size === 0) {
152
+ return definitionContainersInfo;
153
+ }
154
+ for await (const queriedDefinitionContainer of this.queryDefinitionContainers()) {
155
+ const modelCategoriesInfo = modelsCategoriesInfo.get(queriedDefinitionContainer.id);
156
+ definitionContainersInfo.set(queriedDefinitionContainer.id, {
157
+ childCategories: modelCategoriesInfo?.childCategories ?? [],
158
+ modelId: queriedDefinitionContainer.modelId,
159
+ childDefinitionContainers: [],
160
+ parentDefinitionContainerExists: false,
161
+ });
162
+ }
163
+ for (const [definitionContainerId, definitionContainerInfo] of definitionContainersInfo) {
164
+ const parentDefinitionContainer = definitionContainersInfo.get(definitionContainerInfo.modelId);
165
+ if (parentDefinitionContainer !== undefined) {
166
+ parentDefinitionContainer.childDefinitionContainers.push(definitionContainerId);
167
+ definitionContainerInfo.parentDefinitionContainerExists = true;
168
+ }
169
+ }
170
+ return definitionContainersInfo;
171
+ })();
172
+ return this._definitionContainersInfo;
173
+ }
174
+ async getDirectChildDefinitionContainersAndCategories(parentDefinitionContainerIds) {
175
+ const definitionContainersInfo = await this.getDefinitionContainersInfo();
176
+ const result = { definitionContainers: new Array(), categories: new Array() };
177
+ parentDefinitionContainerIds.forEach((parentDefinitionContainerId) => {
178
+ const parentDefinitionContainerInfo = definitionContainersInfo.get(parentDefinitionContainerId);
179
+ if (parentDefinitionContainerInfo !== undefined) {
180
+ result.definitionContainers.push(...parentDefinitionContainerInfo.childDefinitionContainers);
181
+ result.categories.push(...parentDefinitionContainerInfo.childCategories);
182
+ }
183
+ });
184
+ return result;
185
+ }
186
+ async getAllContainedCategories(definitionContainerIds) {
187
+ const result = new Array();
188
+ const definitionContainersInfo = await this.getDefinitionContainersInfo();
189
+ const indirectCategories = await Promise.all(definitionContainerIds.map(async (definitionContainerId) => {
190
+ const definitionContainerInfo = definitionContainersInfo.get(definitionContainerId);
191
+ if (definitionContainerInfo === undefined) {
192
+ return [];
193
+ }
194
+ result.push(...definitionContainerInfo.childCategories.map((category) => category.id));
195
+ return this.getAllContainedCategories(definitionContainerInfo.childDefinitionContainers);
196
+ }));
197
+ for (const categories of indirectCategories) {
198
+ result.push(...categories);
199
+ }
200
+ return result;
201
+ }
202
+ async getInstanceKeyPaths(props) {
203
+ if ("subCategoryId" in props) {
204
+ const subCategoriesInfo = await this.getSubCategoriesInfo();
205
+ const subCategoryInfo = subCategoriesInfo.get(props.subCategoryId);
206
+ if (subCategoryInfo === undefined) {
207
+ return [];
208
+ }
209
+ return [...(await this.getInstanceKeyPaths({ categoryId: subCategoryInfo.categoryId })), { id: props.subCategoryId, className: SUB_CATEGORY_CLASS }];
210
+ }
211
+ if ("categoryId" in props) {
212
+ const modelsCategoriesInfo = await this.getModelsCategoriesInfo();
213
+ for (const [modelId, modelCategoriesInfo] of modelsCategoriesInfo) {
214
+ if (modelCategoriesInfo.childCategories.find((childCategory) => childCategory.id === props.categoryId)) {
215
+ if (!modelCategoriesInfo.parentDefinitionContainerExists) {
216
+ return [{ id: props.categoryId, className: this._categoryClass }];
217
+ }
218
+ return [...(await this.getInstanceKeyPaths({ definitionContainerId: modelId })), { id: props.categoryId, className: this._categoryClass }];
219
+ }
220
+ }
221
+ return [];
222
+ }
223
+ const definitionContainersInfo = await this.getDefinitionContainersInfo();
224
+ const definitionContainerInfo = definitionContainersInfo.get(props.definitionContainerId);
225
+ if (definitionContainerInfo === undefined) {
226
+ return [];
227
+ }
228
+ if (!definitionContainerInfo.parentDefinitionContainerExists) {
229
+ return [{ id: props.definitionContainerId, className: DEFINITION_CONTAINER_CLASS }];
230
+ }
231
+ return [
232
+ ...(await this.getInstanceKeyPaths({ definitionContainerId: definitionContainerInfo.modelId })),
233
+ { id: props.definitionContainerId, className: DEFINITION_CONTAINER_CLASS },
234
+ ];
235
+ }
236
+ async getAllDefinitionContainersAndCategories() {
237
+ const [modelsCategoriesInfo, definitionContainersInfo] = await Promise.all([this.getModelsCategoriesInfo(), this.getDefinitionContainersInfo()]);
238
+ const result = { definitionContainers: [...definitionContainersInfo.keys()], categories: new Array() };
239
+ for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {
240
+ result.categories.push(...modelCategoriesInfo.childCategories.map((childCategory) => childCategory.id));
241
+ }
242
+ return result;
243
+ }
244
+ async getRootDefinitionContainersAndCategories() {
245
+ const [modelsCategoriesInfo, definitionContainersInfo] = await Promise.all([this.getModelsCategoriesInfo(), this.getDefinitionContainersInfo()]);
246
+ const result = { definitionContainers: new Array(), categories: new Array() };
247
+ for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {
248
+ if (!modelCategoriesInfo.parentDefinitionContainerExists) {
249
+ result.categories.push(...modelCategoriesInfo.childCategories);
250
+ }
251
+ }
252
+ for (const [definitionContainerId, definitionContainerInfo] of definitionContainersInfo) {
253
+ if (!definitionContainerInfo.parentDefinitionContainerExists) {
254
+ result.definitionContainers.push(definitionContainerId);
255
+ }
256
+ }
257
+ return result;
258
+ }
259
+ async getSubCategories(categoryId) {
260
+ const subCategoriesInfo = await this.getSubCategoriesInfo();
261
+ const result = new Array();
262
+ for (const [subCategoryId, subCategoryInfo] of subCategoriesInfo) {
263
+ if (subCategoryInfo.categoryId === categoryId) {
264
+ result.push(subCategoryId);
265
+ }
266
+ }
267
+ return result;
268
+ }
269
+ async getIsDefinitionContainerSupported() {
270
+ this._isDefinitionContainerSupported ??= this.queryIsDefinitionContainersSupported();
271
+ return this._isDefinitionContainerSupported;
272
+ }
273
+ }
274
+ /** @internal */
275
+ export function getClassesByView(viewType) {
276
+ return viewType === "2d"
277
+ ? { categoryClass: "BisCore.DrawingCategory", categoryElementClass: "BisCore.GeometricElement2d" }
278
+ : { categoryClass: "BisCore.SpatialCategory", categoryElementClass: "BisCore.GeometricElement3d" };
279
+ }
280
+ //# 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,OAAO,EAAE,0BAA0B,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AA2B3F,gBAAgB;AAChB,MAAM,OAAO,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,0BAA0B;;;cAG5E;YACF,CAAC,CAAC,OACN;;UAEE,IAAI,CAAC,cAAc;eACd,kBAAkB;;;;;oCAKG,IAAI,CAAC,qBAAqB;;KAEzD,CAAC;QACF,IAAI,KAAK,EAAE,MAAM,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC,EAAE,KAAK,EAAE,eAAe,EAA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CAAC,EAAE,aAAa,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,4BAA4B,EAAE,CAAC;AACvG,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { DEFINITION_CONTAINER_CLASS, SUB_CATEGORY_CLASS } from \"./ClassNameDefinitions.js\";\n\nimport type { Id64Array, Id64String } from \"@itwin/core-bentley\";\nimport type { LimitingECSqlQueryExecutor } from \"@itwin/presentation-hierarchies\";\nimport type { InstanceKey } from \"@itwin/presentation-shared\";\n\ninterface DefinitionContainerInfo {\n modelId: Id64String;\n parentDefinitionContainerExists: boolean;\n childCategories: CategoryInfo[];\n childDefinitionContainers: Id64Array;\n}\n\ninterface CategoriesInfo {\n childCategories: CategoryInfo[];\n parentDefinitionContainerExists: boolean;\n}\n\ninterface CategoryInfo {\n id: Id64String;\n childCount: number;\n}\n\ninterface SubCategoryInfo {\n categoryId: Id64String;\n}\n\n/** @internal */\nexport class CategoriesTreeIdsCache {\n private _definitionContainersInfo: Promise<Map<Id64String, DefinitionContainerInfo>> | undefined;\n private _modelsCategoriesInfo: Promise<Map<Id64String, CategoriesInfo>> | undefined;\n private _subCategoriesInfo: Promise<Map<Id64String, SubCategoryInfo>> | undefined;\n private _categoryClass: string;\n private _categoryElementClass: string;\n private _isDefinitionContainerSupported: Promise<boolean> | undefined;\n\n constructor(\n private _queryExecutor: LimitingECSqlQueryExecutor,\n viewType: \"3d\" | \"2d\",\n ) {\n const { categoryClass, categoryElementClass } = getClassesByView(viewType);\n this._categoryClass = categoryClass;\n this._categoryElementClass = categoryElementClass;\n }\n\n private async *queryCategories(): AsyncIterableIterator<{\n id: Id64String;\n modelId: Id64String;\n parentDefinitionContainerExists: boolean;\n childCount: number;\n }> {\n const isDefinitionContainerSupported = await this.getIsDefinitionContainerSupported();\n const categoriesQuery = `\n SELECT\n this.ECInstanceId id,\n COUNT(sc.ECInstanceId) childCount,\n this.Model.Id modelId,\n ${\n isDefinitionContainerSupported\n ? `\n IIF(this.Model.Id IN (SELECT dc.ECInstanceId FROM ${DEFINITION_CONTAINER_CLASS} dc),\n true,\n false\n )`\n : \"false\"\n } parentDefinitionContainerExists\n FROM\n ${this._categoryClass} this\n JOIN ${SUB_CATEGORY_CLASS} sc ON sc.Parent.Id = this.ECInstanceId\n JOIN BisCore.Model m ON m.ECInstanceId = this.Model.Id\n WHERE\n NOT this.IsPrivate\n AND (NOT m.IsPrivate OR m.ECClassId IS (BisCore.DictionaryModel))\n AND EXISTS (SELECT 1 FROM ${this._categoryElementClass} e WHERE e.Category.Id = this.ECInstanceId)\n GROUP BY this.ECInstanceId\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: categoriesQuery }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { id: row.id, modelId: row.modelId, parentDefinitionContainerExists: row.parentDefinitionContainerExists, childCount: row.childCount };\n }\n }\n\n private async queryIsDefinitionContainersSupported(): Promise<boolean> {\n const query = `\n SELECT\n 1\n FROM\n ECDbMeta.ECSchemaDef s\n JOIN ECDbMeta.ECClassDef c ON c.Schema.Id = s.ECInstanceId\n WHERE\n s.Name = 'BisCore'\n AND c.Name = 'DefinitionContainer'\n `;\n\n for await (const _row of this._queryExecutor.createQueryReader({ ecsql: query })) {\n return true;\n }\n return false;\n }\n\n private async *queryDefinitionContainers(): AsyncIterableIterator<{ id: Id64String; modelId: Id64String }> {\n // DefinitionModel ECInstanceId will always be the same as modeled DefinitionContainer ECInstanceId, if this wasn't the case, we would need to do something like:\n // JOIN BisCore.DefinitionModel dm ON dm.ECInstanceId = ${modelIdAccessor}\n // JOIN BisCore.DefinitionModelBreaksDownDefinitionContainer dr ON dr.SourceECInstanceId = dm.ECInstanceId\n // JOIN BisCore.DefinitionContainer dc ON dc.ECInstanceId = dr.TargetECInstanceId\n const DEFINITION_CONTAINERS_CTE = \"DefinitionContainers\";\n const ctes = [\n `\n ${DEFINITION_CONTAINERS_CTE}(ECInstanceId, ModelId) AS (\n SELECT\n dc.ECInstanceId,\n dc.Model.Id\n FROM\n ${DEFINITION_CONTAINER_CLASS} dc\n WHERE\n dc.ECInstanceId IN (SELECT c.Model.Id FROM ${this._categoryClass} c WHERE NOT c.IsPrivate)\n AND NOT dc.IsPrivate\n\n UNION ALL\n\n SELECT\n pdc.ECInstanceId,\n pdc.Model.Id\n FROM\n ${DEFINITION_CONTAINERS_CTE} cdc\n JOIN ${DEFINITION_CONTAINER_CLASS} pdc ON pdc.ECInstanceId = cdc.ModelId\n WHERE\n NOT pdc.IsPrivate\n )\n `,\n ];\n const definitionsQuery = `\n SELECT dc.ECInstanceId id, dc.ModelId modelId FROM ${DEFINITION_CONTAINERS_CTE} dc GROUP BY dc.ECInstanceId\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ctes, ecsql: definitionsQuery }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { id: row.id, modelId: row.modelId };\n }\n }\n\n private async *queryVisibleSubCategories(categoriesInfo: Id64Array): AsyncIterableIterator<{ id: Id64String; parentId: Id64String }> {\n const definitionsQuery = `\n SELECT\n sc.ECInstanceId id,\n sc.Parent.Id categoryId\n FROM\n ${SUB_CATEGORY_CLASS} sc\n WHERE\n NOT sc.IsPrivate\n AND sc.Parent.Id IN (${categoriesInfo.join(\",\")})\n `;\n for await (const row of this._queryExecutor.createQueryReader({ ecsql: definitionsQuery }, { rowFormat: \"ECSqlPropertyNames\", limit: \"unbounded\" })) {\n yield { id: row.id, parentId: row.categoryId };\n }\n }\n\n private async getModelsCategoriesInfo() {\n this._modelsCategoriesInfo ??= (async () => {\n const allModelsCategories = new Map<Id64String, CategoriesInfo>();\n for await (const queriedCategory of this.queryCategories()) {\n let modelCategories = allModelsCategories.get(queriedCategory.modelId);\n if (modelCategories === undefined) {\n modelCategories = { parentDefinitionContainerExists: queriedCategory.parentDefinitionContainerExists, childCategories: [] };\n allModelsCategories.set(queriedCategory.modelId, modelCategories);\n }\n modelCategories.childCategories.push({ id: queriedCategory.id, childCount: queriedCategory.childCount });\n }\n return allModelsCategories;\n })();\n return this._modelsCategoriesInfo;\n }\n\n private async getSubCategoriesInfo() {\n this._subCategoriesInfo ??= (async () => {\n const allSubCategories = new Map<Id64String, SubCategoryInfo>();\n const modelsCategoriesInfo = await this.getModelsCategoriesInfo();\n const categoriesWithMoreThanOneSubCategory = new Array<Id64String>();\n for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {\n categoriesWithMoreThanOneSubCategory.push(\n ...modelCategoriesInfo.childCategories.filter((categoryInfo) => categoryInfo.childCount > 1).map((categoryInfo) => categoryInfo.id),\n );\n }\n\n if (categoriesWithMoreThanOneSubCategory.length === 0) {\n return allSubCategories;\n }\n\n for await (const queriedSubCategory of this.queryVisibleSubCategories(categoriesWithMoreThanOneSubCategory)) {\n allSubCategories.set(queriedSubCategory.id, { categoryId: queriedSubCategory.parentId });\n }\n return allSubCategories;\n })();\n return this._subCategoriesInfo;\n }\n\n private async getDefinitionContainersInfo() {\n this._definitionContainersInfo ??= (async () => {\n const definitionContainersInfo = new Map<Id64String, DefinitionContainerInfo>();\n const [isDefinitionContainerSupported, modelsCategoriesInfo] = await Promise.all([\n this.getIsDefinitionContainerSupported(),\n this.getModelsCategoriesInfo(),\n ]);\n if (!isDefinitionContainerSupported || modelsCategoriesInfo.size === 0) {\n return definitionContainersInfo;\n }\n\n for await (const queriedDefinitionContainer of this.queryDefinitionContainers()) {\n const modelCategoriesInfo = modelsCategoriesInfo.get(queriedDefinitionContainer.id);\n\n definitionContainersInfo.set(queriedDefinitionContainer.id, {\n childCategories: modelCategoriesInfo?.childCategories ?? [],\n modelId: queriedDefinitionContainer.modelId,\n childDefinitionContainers: [],\n parentDefinitionContainerExists: false,\n });\n }\n\n for (const [definitionContainerId, definitionContainerInfo] of definitionContainersInfo) {\n const parentDefinitionContainer = definitionContainersInfo.get(definitionContainerInfo.modelId);\n if (parentDefinitionContainer !== undefined) {\n parentDefinitionContainer.childDefinitionContainers.push(definitionContainerId);\n definitionContainerInfo.parentDefinitionContainerExists = true;\n }\n }\n\n return definitionContainersInfo;\n })();\n return this._definitionContainersInfo;\n }\n\n public async getDirectChildDefinitionContainersAndCategories(\n parentDefinitionContainerIds: Id64Array,\n ): Promise<{ categories: CategoryInfo[]; definitionContainers: Id64Array }> {\n const definitionContainersInfo = await this.getDefinitionContainersInfo();\n\n const result = { definitionContainers: new Array<Id64String>(), categories: new Array<CategoryInfo>() };\n\n parentDefinitionContainerIds.forEach((parentDefinitionContainerId) => {\n const parentDefinitionContainerInfo = definitionContainersInfo.get(parentDefinitionContainerId);\n if (parentDefinitionContainerInfo !== undefined) {\n result.definitionContainers.push(...parentDefinitionContainerInfo.childDefinitionContainers);\n result.categories.push(...parentDefinitionContainerInfo.childCategories);\n }\n });\n return result;\n }\n\n public async getAllContainedCategories(definitionContainerIds: Id64Array): Promise<Id64Array> {\n const result = new Array<Id64String>();\n\n const definitionContainersInfo = await this.getDefinitionContainersInfo();\n const indirectCategories = await Promise.all(\n definitionContainerIds.map(async (definitionContainerId) => {\n const definitionContainerInfo = definitionContainersInfo.get(definitionContainerId);\n if (definitionContainerInfo === undefined) {\n return [];\n }\n result.push(...definitionContainerInfo.childCategories.map((category) => category.id));\n return this.getAllContainedCategories(definitionContainerInfo.childDefinitionContainers);\n }),\n );\n for (const categories of indirectCategories) {\n result.push(...categories);\n }\n\n return result;\n }\n\n public async getInstanceKeyPaths(\n props: { categoryId: Id64String } | { definitionContainerId: Id64String } | { subCategoryId: Id64String },\n ): Promise<InstanceKey[]> {\n if (\"subCategoryId\" in props) {\n const subCategoriesInfo = await this.getSubCategoriesInfo();\n const subCategoryInfo = subCategoriesInfo.get(props.subCategoryId);\n if (subCategoryInfo === undefined) {\n return [];\n }\n return [...(await this.getInstanceKeyPaths({ categoryId: subCategoryInfo.categoryId })), { id: props.subCategoryId, className: SUB_CATEGORY_CLASS }];\n }\n\n if (\"categoryId\" in props) {\n const modelsCategoriesInfo = await this.getModelsCategoriesInfo();\n for (const [modelId, modelCategoriesInfo] of modelsCategoriesInfo) {\n if (modelCategoriesInfo.childCategories.find((childCategory) => childCategory.id === props.categoryId)) {\n if (!modelCategoriesInfo.parentDefinitionContainerExists) {\n return [{ id: props.categoryId, className: this._categoryClass }];\n }\n\n return [...(await this.getInstanceKeyPaths({ definitionContainerId: modelId })), { id: props.categoryId, className: this._categoryClass }];\n }\n }\n return [];\n }\n\n const definitionContainersInfo = await this.getDefinitionContainersInfo();\n const definitionContainerInfo = definitionContainersInfo.get(props.definitionContainerId);\n if (definitionContainerInfo === undefined) {\n return [];\n }\n\n if (!definitionContainerInfo.parentDefinitionContainerExists) {\n return [{ id: props.definitionContainerId, className: DEFINITION_CONTAINER_CLASS }];\n }\n\n return [\n ...(await this.getInstanceKeyPaths({ definitionContainerId: definitionContainerInfo.modelId })),\n { id: props.definitionContainerId, className: DEFINITION_CONTAINER_CLASS },\n ];\n }\n\n public async getAllDefinitionContainersAndCategories(): Promise<{ categories: Id64Array; definitionContainers: Id64Array }> {\n const [modelsCategoriesInfo, definitionContainersInfo] = await Promise.all([this.getModelsCategoriesInfo(), this.getDefinitionContainersInfo()]);\n const result = { definitionContainers: [...definitionContainersInfo.keys()], categories: new Array<Id64String>() };\n for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {\n result.categories.push(...modelCategoriesInfo.childCategories.map((childCategory) => childCategory.id));\n }\n\n return result;\n }\n\n public async getRootDefinitionContainersAndCategories(): Promise<{ categories: CategoryInfo[]; definitionContainers: Id64Array }> {\n const [modelsCategoriesInfo, definitionContainersInfo] = await Promise.all([this.getModelsCategoriesInfo(), this.getDefinitionContainersInfo()]);\n const result = { definitionContainers: new Array<Id64String>(), categories: new Array<CategoryInfo>() };\n for (const modelCategoriesInfo of modelsCategoriesInfo.values()) {\n if (!modelCategoriesInfo.parentDefinitionContainerExists) {\n result.categories.push(...modelCategoriesInfo.childCategories);\n }\n }\n\n for (const [definitionContainerId, definitionContainerInfo] of definitionContainersInfo) {\n if (!definitionContainerInfo.parentDefinitionContainerExists) {\n result.definitionContainers.push(definitionContainerId);\n }\n }\n return result;\n }\n\n public async getSubCategories(categoryId: Id64String): Promise<Id64Array> {\n const subCategoriesInfo = await this.getSubCategoriesInfo();\n const result = new Array<Id64String>();\n for (const [subCategoryId, subCategoryInfo] of subCategoriesInfo) {\n if (subCategoryInfo.categoryId === categoryId) {\n result.push(subCategoryId);\n }\n }\n return result;\n }\n\n public async getIsDefinitionContainerSupported(): Promise<boolean> {\n this._isDefinitionContainerSupported ??= this.queryIsDefinitionContainersSupported();\n return this._isDefinitionContainerSupported;\n }\n}\n\n/** @internal */\nexport function getClassesByView(viewType: \"2d\" | \"3d\") {\n return viewType === \"2d\"\n ? { categoryClass: \"BisCore.DrawingCategory\", categoryElementClass: \"BisCore.GeometricElement2d\" }\n : { categoryClass: \"BisCore.SpatialCategory\", categoryElementClass: \"BisCore.GeometricElement3d\" };\n}\n"]}
@@ -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