@itwin/tree-widget-react 4.0.0-alpha.12 → 4.0.0-alpha.13

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 (22) hide show
  1. package/README.md +1 -11
  2. package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js +43 -18
  3. package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js.map +1 -1
  4. package/lib/esm/tree-widget-react/components/trees/classifications-tree/UseClassificationsTree.js +20 -14
  5. package/lib/esm/tree-widget-react/components/trees/classifications-tree/UseClassificationsTree.js.map +1 -1
  6. package/lib/esm/tree-widget-react/components/trees/common/internal/useTreeHooks/UseCachedVisibility.d.ts +26 -0
  7. package/lib/esm/tree-widget-react/components/trees/common/internal/useTreeHooks/UseCachedVisibility.js +20 -0
  8. package/lib/esm/tree-widget-react/components/trees/common/internal/useTreeHooks/UseCachedVisibility.js.map +1 -0
  9. package/lib/esm/tree-widget-react/components/trees/common/internal/useTreeHooks/UseIdsCache.d.ts +17 -0
  10. package/lib/esm/tree-widget-react/components/trees/{models-tree/internal → common/internal/useTreeHooks}/UseIdsCache.js +10 -11
  11. package/lib/esm/tree-widget-react/components/trees/common/internal/useTreeHooks/UseIdsCache.js.map +1 -0
  12. package/lib/esm/tree-widget-react/components/trees/models-tree/UseModelsTree.js +28 -18
  13. package/lib/esm/tree-widget-react/components/trees/models-tree/UseModelsTree.js.map +1 -1
  14. package/package.json +1 -1
  15. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/UseIdsCache.d.ts +0 -8
  16. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/UseIdsCache.js +0 -48
  17. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/UseIdsCache.js.map +0 -1
  18. package/lib/esm/tree-widget-react/components/trees/classifications-tree/internal/UseIdsCache.d.ts +0 -8
  19. package/lib/esm/tree-widget-react/components/trees/classifications-tree/internal/UseIdsCache.js +0 -45
  20. package/lib/esm/tree-widget-react/components/trees/classifications-tree/internal/UseIdsCache.js.map +0 -1
  21. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/UseIdsCache.d.ts +0 -8
  22. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/UseIdsCache.js.map +0 -1
package/README.md CHANGED
@@ -201,8 +201,6 @@ Based on the returned paths, the displayed hierarchy consists only of the target
201
201
  Use `getFilteredPaths` when you need more control over which nodes are shown. Here are some example use cases:
202
202
 
203
203
  - **Filter by known instance keys**: You already have a list of `InstanceKey` items that should remain in the tree. Pass them as `targetItems` to `createInstanceKeyPaths`.
204
- <!-- [[include: [TreeWidget.GetFilteredPathsComponentWithTargetItemsExample], tsx]] -->
205
- <!-- BEGIN EXTRACTION -->
206
204
 
207
205
  ```tsx
208
206
  type UseModelsTreeProps = Parameters<typeof useModelsTree>[0];
@@ -243,11 +241,7 @@ Use `getFilteredPaths` when you need more control over which nodes are shown. He
243
241
  }
244
242
  ```
245
243
 
246
- <!-- END EXTRACTION -->
247
-
248
244
  - **Post-process the paths created `createInstanceKeyPaths`**: Use `filter` string to generate the paths, then apply additional filtering - e.g., remove paths that are too long.
249
- <!-- [[include: [TreeWidget.GetFilteredPathsComponentWithPostProcessingExample], tsx]] -->
250
- <!-- BEGIN EXTRACTION -->
251
245
 
252
246
  ```tsx
253
247
  function CustomModelsTreeComponentWithPostProcessing({
@@ -286,11 +280,8 @@ Use `getFilteredPaths` when you need more control over which nodes are shown. He
286
280
  }
287
281
  ```
288
282
 
289
- <!-- END EXTRACTION -->
290
-
291
283
  - **Apply custom logic to generate instance keys**: Generate instance keys using custom implementation. For example: query elements that have specified filter in their user label and provide them as targetItems.
292
- <!-- [[include: [TreeWidget.GetFilteredPathsComponentWithFilterAndTargetItemsExample], tsx]] -->
293
- <!-- BEGIN EXTRACTION -->
284
+
294
285
  ```tsx
295
286
  function CustomModelsTreeComponentWithFilterAndTargetItems({
296
287
  viewport,
@@ -333,7 +324,6 @@ Use `getFilteredPaths` when you need more control over which nodes are shown. He
333
324
  );
334
325
  }
335
326
  ```
336
- <!-- END EXTRACTION -->
337
327
 
338
328
  ### Categories tree
339
329
 
@@ -3,7 +3,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
4
  * See LICENSE.md in the project root for license terms and full copyright notice.
5
5
  *--------------------------------------------------------------------------------------------*/
6
- import { useCallback, useEffect, useMemo, useState } from "react";
6
+ import { useCallback, useEffect, useMemo } from "react";
7
+ import { createECSqlQueryExecutor } from "@itwin/presentation-core-interop";
7
8
  import { Icon } from "@stratakit/foundations";
8
9
  import categorySvg from "@stratakit/icons/bis-category-3d.svg";
9
10
  import subcategorySvg from "@stratakit/icons/bis-category-subcategory.svg";
@@ -11,10 +12,12 @@ import classSvg from "@stratakit/icons/bis-class.svg";
11
12
  import definitionContainerSvg from "@stratakit/icons/bis-definitions-container.svg";
12
13
  import elementSvg from "@stratakit/icons/bis-element.svg";
13
14
  import { EmptyTreeContent, FilterUnknownError, NoFilterMatches, TooManyFilterMatches } from "../common/components/EmptyTree.js";
15
+ import { useCachedVisibility } from "../common/internal/useTreeHooks/UseCachedVisibility.js";
16
+ import { useIdsCache } from "../common/internal/useTreeHooks/UseIdsCache.js";
14
17
  import { CategoriesTreeDefinition, defaultHierarchyConfiguration } from "./CategoriesTreeDefinition.js";
18
+ import { CategoriesTreeIdsCache } from "./internal/CategoriesTreeIdsCache.js";
15
19
  import { createCategoriesTreeVisibilityHandler } from "./internal/CategoriesTreeVisibilityHandler.js";
16
20
  import { useFilteredPaths } from "./internal/UseFilteredPaths.js";
17
- import { useIdsCache } from "./internal/UseIdsCache.js";
18
21
  /**
19
22
  * Custom hook to create and manage state for the categories tree.
20
23
  * @beta
@@ -27,7 +30,16 @@ export function useCategoriesTree({ filter, activeView, onCategoriesFiltered, em
27
30
  // eslint-disable-next-line react-hooks/exhaustive-deps
28
31
  Object.values(hierarchyConfig ?? {}));
29
32
  const viewType = activeView.view.is2d() ? "2d" : "3d";
30
- const { getCategoriesTreeIdsCache, visibilityHandlerFactory, onFilteredPathsChanged } = useCachedVisibility(activeView, hierarchyConfiguration, viewType);
33
+ const { getCache: getCategoriesTreeIdsCache } = useIdsCache({
34
+ imodel: activeView.iModel,
35
+ createCache,
36
+ cacheSpecificProps: useMemo(() => ({ viewType }), [viewType]),
37
+ });
38
+ const { visibilityHandlerFactory, onFilteredPathsChanged } = useCategoriesCachedVisibility({
39
+ activeView,
40
+ getCache: getCategoriesTreeIdsCache,
41
+ hierarchyConfig: hierarchyConfiguration,
42
+ });
31
43
  const getHierarchyDefinition = useCallback((props) => {
32
44
  return new CategoriesTreeDefinition({ ...props, viewType, idsCache: getCategoriesTreeIdsCache(), hierarchyConfig: hierarchyConfiguration });
33
45
  }, [viewType, getCategoriesTreeIdsCache, hierarchyConfiguration]);
@@ -54,21 +66,15 @@ export function useCategoriesTree({ filter, activeView, onCategoriesFiltered, em
54
66
  },
55
67
  };
56
68
  }
57
- function createVisibilityHandlerFactory(activeView, idsCacheGetter, hierarchyConfig, filteredPaths) {
58
- return ({ imodelAccess }) => createCategoriesTreeVisibilityHandler({ viewport: activeView, idsCache: idsCacheGetter(), imodelAccess, filteredPaths, hierarchyConfig });
59
- }
60
- function useCachedVisibility(activeView, hierarchyConfig, viewType) {
61
- const [filteredPaths, setFilteredPaths] = useState();
62
- const { getCache: getCategoriesTreeIdsCache } = useIdsCache(activeView.iModel, viewType, filteredPaths);
63
- const [visibilityHandlerFactory, setVisibilityHandlerFactory] = useState(() => createVisibilityHandlerFactory(activeView, getCategoriesTreeIdsCache, hierarchyConfig, filteredPaths));
64
- useEffect(() => {
65
- setVisibilityHandlerFactory(() => createVisibilityHandlerFactory(activeView, getCategoriesTreeIdsCache, hierarchyConfig, filteredPaths));
66
- }, [activeView, getCategoriesTreeIdsCache, hierarchyConfig, filteredPaths]);
67
- return {
68
- getCategoriesTreeIdsCache,
69
- visibilityHandlerFactory,
70
- onFilteredPathsChanged: useCallback((paths) => setFilteredPaths(paths), []),
71
- };
69
+ function createVisibilityHandlerFactory(props) {
70
+ const { activeView, factoryProps, idsCacheGetter, filteredPaths } = props;
71
+ return ({ imodelAccess }) => createCategoriesTreeVisibilityHandler({
72
+ viewport: activeView,
73
+ idsCache: idsCacheGetter(),
74
+ imodelAccess,
75
+ filteredPaths,
76
+ hierarchyConfig: factoryProps.hierarchyConfig,
77
+ });
72
78
  }
73
79
  function getEmptyTreeContentComponent(filter, error, emptyTreeContent) {
74
80
  if (error) {
@@ -111,4 +117,23 @@ export function CategoriesTreeIcon({ node }) {
111
117
  function getSublabel(node) {
112
118
  return node.nodeData.extendedData?.description;
113
119
  }
120
+ function useCategoriesCachedVisibility(props) {
121
+ const { activeView, getCache, hierarchyConfig } = props;
122
+ const { visibilityHandlerFactory, filteredPaths, onFilteredPathsChanged } = useCachedVisibility({
123
+ activeView,
124
+ getCache,
125
+ factoryProps: useMemo(() => ({ hierarchyConfig }), [hierarchyConfig]),
126
+ createFactory: createVisibilityHandlerFactory,
127
+ });
128
+ useEffect(() => {
129
+ getCache().clearFilteredElementsModels();
130
+ }, [filteredPaths, getCache]);
131
+ return {
132
+ visibilityHandlerFactory,
133
+ onFilteredPathsChanged,
134
+ };
135
+ }
136
+ function createCache(props) {
137
+ return new CategoriesTreeIdsCache(createECSqlQueryExecutor(props.imodel), props.specificProps.viewType);
138
+ }
114
139
  //# sourceMappingURL=UseCategoriesTree.js.map
@@ -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,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,WAAW,MAAM,sCAAsC,CAAC;AAC/D,OAAO,c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AAI,CAAC;AACjD,CAAC;AAED,YAAY;AACZ,MAAM,UAAU,kBAAkB,CAAC,EAAE,IAAI,EAAuC;IAC9E,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,KAAK,SAAS,EAAE,CAAC;QACtD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,OAAO,GAAG,GAAG,EAAE;QACnB,QAAQ,IAAI,CAAC,QAAQ,CAAC,YAAa,CAAC,OAAO,EAAE,CAAC;YAC5C,KAAK,aAAa;gBAChB,OAAO,WAAW,CAAC;YACrB,KAAK,qBAAqB;gBACxB,OAAO,cAAc,CAAC;YACxB,KAAK,2BAA2B;gBAC9B,OAAO,sBAAsB,CAAC;YAChC,KAAK,WAAW;gBACd,OAAO,UAAU,CAAC;YACpB,KAAK,eAAe;gBAClB,OAAO,QAAQ,CAAC;YAClB;gBACE,OAAO,SAAS,CAAC;QACrB,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,KAAC,IAAI,IAAC,IAAI,EAAE,OAAO,EAAE,GAAI,CAAC;AACnC,CAAC;AAED,SAAS,WAAW,CAAC,IAA+B;IAClD,OAAO,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,WAAW,CAAC;AACjD,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, useEffect, useMemo, useState } from \"react\";\nimport { Icon } from \"@stratakit/foundations\";\nimport categorySvg from \"@stratakit/icons/bis-category-3d.svg\";\nimport subcategorySvg from \"@stratakit/icons/bis-category-subcategory.svg\";\nimport classSvg from \"@stratakit/icons/bis-class.svg\";\nimport definitionContainerSvg from \"@stratakit/icons/bis-definitions-container.svg\";\nimport elementSvg from \"@stratakit/icons/bis-element.svg\";\nimport { EmptyTreeContent, FilterUnknownError, NoFilterMatches, TooManyFilterMatches } from \"../common/components/EmptyTree.js\";\nimport { CategoriesTreeDefinition, defaultHierarchyConfiguration } from \"./CategoriesTreeDefinition.js\";\nimport { createCategoriesTreeVisibilityHandler } from \"./internal/CategoriesTreeVisibilityHandler.js\";\nimport { useFilteredPaths } from \"./internal/UseFilteredPaths.js\";\nimport { useIdsCache } from \"./internal/UseIdsCache.js\";\n\nimport type { CategoriesTreeFilteringError } from \"./internal/UseFilteredPaths.js\";\nimport type { HierarchyFilteringPath } from \"@itwin/presentation-hierarchies\";\nimport type { CategoriesTreeIdsCache } from \"./internal/CategoriesTreeIdsCache.js\";\nimport type { ReactNode } from \"react\";\nimport type { Id64Array } from \"@itwin/core-bentley\";\nimport type { Viewport } from \"@itwin/core-frontend\";\nimport type { PresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport type { VisibilityTreeProps } from \"../common/components/VisibilityTree.js\";\nimport type { VisibilityTreeRendererProps } from \"../common/components/VisibilityTreeRenderer.js\";\nimport type { CategoryInfo } from \"../common/CategoriesVisibilityUtils.js\";\nimport type { CategoriesTreeHierarchyConfiguration } from \"./CategoriesTreeDefinition.js\";\n\n/** @beta */\nexport interface UseCategoriesTreeProps {\n activeView: Viewport;\n onCategoriesFiltered?: (props: { categories: CategoryInfo[] | undefined; models?: Id64Array }) => void;\n filter?: string;\n emptyTreeContent?: ReactNode;\n hierarchyConfig?: Partial<CategoriesTreeHierarchyConfiguration>;\n}\n\n/** @beta */\ninterface UseCategoriesTreeResult {\n categoriesTreeProps: Pick<\n VisibilityTreeProps,\n \"treeName\" | \"getHierarchyDefinition\" | \"getFilteredPaths\" | \"visibilityHandlerFactory\" | \"highlight\" | \"emptyTreeContent\"\n >;\n rendererProps: Required<Pick<VisibilityTreeRendererProps, \"getDecorations\" | \"getSublabel\">>;\n}\n\n/**\n * Custom hook to create and manage state for the categories tree.\n * @beta\n */\nexport function useCategoriesTree({\n filter,\n activeView,\n onCategoriesFiltered,\n emptyTreeContent,\n hierarchyConfig,\n}: UseCategoriesTreeProps): UseCategoriesTreeResult {\n const hierarchyConfiguration = useMemo<CategoriesTreeHierarchyConfiguration>(\n () => ({\n ...defaultHierarchyConfiguration,\n ...hierarchyConfig,\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n Object.values(hierarchyConfig ?? {}),\n );\n const viewType = activeView.view.is2d() ? \"2d\" : \"3d\";\n\n const { getCategoriesTreeIdsCache, visibilityHandlerFactory, onFilteredPathsChanged } = useCachedVisibility(activeView, hierarchyConfiguration, viewType);\n\n const getHierarchyDefinition = useCallback<VisibilityTreeProps[\"getHierarchyDefinition\"]>(\n (props) => {\n return new CategoriesTreeDefinition({ ...props, viewType, idsCache: getCategoriesTreeIdsCache(), hierarchyConfig: hierarchyConfiguration });\n },\n [viewType, getCategoriesTreeIdsCache, hierarchyConfiguration],\n );\n\n const { getPaths, filteringError } = useFilteredPaths({\n hierarchyConfiguration,\n filter,\n getCategoriesTreeIdsCache,\n onFilteredPathsChanged,\n viewType,\n onCategoriesFiltered,\n });\n\n return {\n categoriesTreeProps: {\n treeName: \"categories-tree-v2\",\n getHierarchyDefinition,\n getFilteredPaths: getPaths,\n visibilityHandlerFactory,\n emptyTreeContent: useMemo(() => getEmptyTreeContentComponent(filter, filteringError, emptyTreeContent), [filter, filteringError, emptyTreeContent]),\n highlight: useMemo(() => (filter ? { text: filter } : undefined), [filter]),\n },\n rendererProps: {\n getDecorations: useCallback((node) => <CategoriesTreeIcon node={node} />, []),\n getSublabel,\n },\n };\n}\n\nfunction createVisibilityHandlerFactory(\n activeView: Viewport,\n idsCacheGetter: () => CategoriesTreeIdsCache,\n hierarchyConfig: CategoriesTreeHierarchyConfiguration,\n filteredPaths?: HierarchyFilteringPath[],\n): VisibilityTreeProps[\"visibilityHandlerFactory\"] {\n return ({ imodelAccess }) =>\n createCategoriesTreeVisibilityHandler({ viewport: activeView, idsCache: idsCacheGetter(), imodelAccess, filteredPaths, hierarchyConfig });\n}\n\nfunction useCachedVisibility(activeView: Viewport, hierarchyConfig: CategoriesTreeHierarchyConfiguration, viewType: \"2d\" | \"3d\") {\n const [filteredPaths, setFilteredPaths] = useState<HierarchyFilteringPath[]>();\n const { getCache: getCategoriesTreeIdsCache } = useIdsCache(activeView.iModel, viewType, filteredPaths);\n\n const [visibilityHandlerFactory, setVisibilityHandlerFactory] = useState<VisibilityTreeProps[\"visibilityHandlerFactory\"]>(() =>\n createVisibilityHandlerFactory(activeView, getCategoriesTreeIdsCache, hierarchyConfig, filteredPaths),\n );\n\n useEffect(() => {\n setVisibilityHandlerFactory(() => createVisibilityHandlerFactory(activeView, getCategoriesTreeIdsCache, hierarchyConfig, filteredPaths));\n }, [activeView, getCategoriesTreeIdsCache, hierarchyConfig, filteredPaths]);\n\n return {\n getCategoriesTreeIdsCache,\n visibilityHandlerFactory,\n onFilteredPathsChanged: useCallback((paths: HierarchyFilteringPath[] | undefined) => setFilteredPaths(paths), []),\n };\n}\n\nfunction getEmptyTreeContentComponent(filter?: string, error?: CategoriesTreeFilteringError, emptyTreeContent?: React.ReactNode) {\n if (error) {\n if (error === \"tooManyFilterMatches\") {\n return <TooManyFilterMatches base={\"categoriesTree\"} />;\n }\n return <FilterUnknownError base={\"categoriesTree\"} />;\n }\n if (filter) {\n return <NoFilterMatches base={\"categoriesTree\"} />;\n }\n if (emptyTreeContent) {\n return emptyTreeContent;\n }\n return <EmptyTreeContent icon={categorySvg} />;\n}\n\n/** @beta */\nexport function CategoriesTreeIcon({ node }: { node: PresentationHierarchyNode }) {\n if (node.nodeData.extendedData?.imageId === undefined) {\n return undefined;\n }\n\n const getIcon = () => {\n switch (node.nodeData.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 case \"icon-item\":\n return elementSvg;\n case \"icon-ec-class\":\n return classSvg;\n default:\n return undefined;\n }\n };\n\n return <Icon href={getIcon()} />;\n}\n\nfunction getSublabel(node: PresentationHierarchyNode) {\n return node.nodeData.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,SAAS,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACxD,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,WAAW,MAAM,sCAAsC,CAAC;AAC/D,OAAO,cAAc,MAAM,+CAA+C,CAAC;AAC3E,OAAO,QAAQ,MAAM,gCAAgC,CAAC;AACtD,OAAO,sBAAsB,MAAM,gDAAgD,CAAC;AACpF,OAAO,UAAU,MAAM,kCAAkC,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AAChI,OAAO,EAAE,mBAAmB,EAAE,MAAM,wDAAwD,CAAC;AAC7F,OAAO,EAAE,WAAW,EAAE,MAAM,gDAAgD,CAAC;AAC7E,OAAO,EAAE,wBAAwB,EAAE,6BAA6B,EAAE,MAAM,+BAA+B,CAAC;AACxG,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,qCAAqC,EAAE,MAAM,+CAA+C,CAAC;AACtG,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAgClE;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAChC,MAAM,EACN,UAAU,EACV,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,GACQ;IACvB,MAAM,sBAAsB,GAAG,OAAO,CACpC,GAAG,EAAE,CAAC,CAAC;QACL,GAAG,6BAA6B;QAChC,GAAG,eAAe;KACnB,CAAC;IACF,uDAAuD;IACvD,MAAM,CAAC,MAAM,CAAC,eAAe,IAAI,E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Aa,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE9B,OAAO;QACL,wBAAwB;QACxB,sBAAsB;KACvB,CAAC;AACJ,CAAC;AAED,SAAS,WAAW,CAAC,KAAkD;IACrE,OAAO,IAAI,sBAAsB,CAAC,wBAAwB,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;AAC1G,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, useEffect, useMemo } from \"react\";\nimport { createECSqlQueryExecutor } from \"@itwin/presentation-core-interop\";\nimport { Icon } from \"@stratakit/foundations\";\nimport categorySvg from \"@stratakit/icons/bis-category-3d.svg\";\nimport subcategorySvg from \"@stratakit/icons/bis-category-subcategory.svg\";\nimport classSvg from \"@stratakit/icons/bis-class.svg\";\nimport definitionContainerSvg from \"@stratakit/icons/bis-definitions-container.svg\";\nimport elementSvg from \"@stratakit/icons/bis-element.svg\";\nimport { EmptyTreeContent, FilterUnknownError, NoFilterMatches, TooManyFilterMatches } from \"../common/components/EmptyTree.js\";\nimport { useCachedVisibility } from \"../common/internal/useTreeHooks/UseCachedVisibility.js\";\nimport { useIdsCache } from \"../common/internal/useTreeHooks/UseIdsCache.js\";\nimport { CategoriesTreeDefinition, defaultHierarchyConfiguration } from \"./CategoriesTreeDefinition.js\";\nimport { CategoriesTreeIdsCache } from \"./internal/CategoriesTreeIdsCache.js\";\nimport { createCategoriesTreeVisibilityHandler } from \"./internal/CategoriesTreeVisibilityHandler.js\";\nimport { useFilteredPaths } from \"./internal/UseFilteredPaths.js\";\n\nimport type { CreateCacheProps } from \"../common/internal/useTreeHooks/UseIdsCache.js\";\nimport type { CreateFactoryProps } from \"../common/internal/useTreeHooks/UseCachedVisibility.js\";\nimport type { CategoriesTreeFilteringError } from \"./internal/UseFilteredPaths.js\";\nimport type { ReactNode } from \"react\";\nimport type { Id64Array } from \"@itwin/core-bentley\";\nimport type { Viewport } from \"@itwin/core-frontend\";\nimport type { PresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport type { VisibilityTreeProps } from \"../common/components/VisibilityTree.js\";\nimport type { VisibilityTreeRendererProps } from \"../common/components/VisibilityTreeRenderer.js\";\nimport type { CategoryInfo } from \"../common/CategoriesVisibilityUtils.js\";\nimport type { CategoriesTreeHierarchyConfiguration } from \"./CategoriesTreeDefinition.js\";\n\n/** @beta */\nexport interface UseCategoriesTreeProps {\n activeView: Viewport;\n onCategoriesFiltered?: (props: { categories: CategoryInfo[] | undefined; models?: Id64Array }) => void;\n filter?: string;\n emptyTreeContent?: ReactNode;\n hierarchyConfig?: Partial<CategoriesTreeHierarchyConfiguration>;\n}\n\n/** @beta */\ninterface UseCategoriesTreeResult {\n categoriesTreeProps: Pick<\n VisibilityTreeProps,\n \"treeName\" | \"getHierarchyDefinition\" | \"getFilteredPaths\" | \"visibilityHandlerFactory\" | \"highlight\" | \"emptyTreeContent\"\n >;\n rendererProps: Required<Pick<VisibilityTreeRendererProps, \"getDecorations\" | \"getSublabel\">>;\n}\n\n/**\n * Custom hook to create and manage state for the categories tree.\n * @beta\n */\nexport function useCategoriesTree({\n filter,\n activeView,\n onCategoriesFiltered,\n emptyTreeContent,\n hierarchyConfig,\n}: UseCategoriesTreeProps): UseCategoriesTreeResult {\n const hierarchyConfiguration = useMemo<CategoriesTreeHierarchyConfiguration>(\n () => ({\n ...defaultHierarchyConfiguration,\n ...hierarchyConfig,\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n Object.values(hierarchyConfig ?? {}),\n );\n const viewType = activeView.view.is2d() ? \"2d\" : \"3d\";\n\n const { getCache: getCategoriesTreeIdsCache } = useIdsCache<CategoriesTreeIdsCache, { viewType: \"2d\" | \"3d\" }>({\n imodel: activeView.iModel,\n createCache,\n cacheSpecificProps: useMemo(() => ({ viewType }), [viewType]),\n });\n\n const { visibilityHandlerFactory, onFilteredPathsChanged } = useCategoriesCachedVisibility({\n activeView,\n getCache: getCategoriesTreeIdsCache,\n hierarchyConfig: hierarchyConfiguration,\n });\n\n const getHierarchyDefinition = useCallback<VisibilityTreeProps[\"getHierarchyDefinition\"]>(\n (props) => {\n return new CategoriesTreeDefinition({ ...props, viewType, idsCache: getCategoriesTreeIdsCache(), hierarchyConfig: hierarchyConfiguration });\n },\n [viewType, getCategoriesTreeIdsCache, hierarchyConfiguration],\n );\n\n const { getPaths, filteringError } = useFilteredPaths({\n hierarchyConfiguration,\n filter,\n getCategoriesTreeIdsCache,\n onFilteredPathsChanged,\n viewType,\n onCategoriesFiltered,\n });\n\n return {\n categoriesTreeProps: {\n treeName: \"categories-tree-v2\",\n getHierarchyDefinition,\n getFilteredPaths: getPaths,\n visibilityHandlerFactory,\n emptyTreeContent: useMemo(() => getEmptyTreeContentComponent(filter, filteringError, emptyTreeContent), [filter, filteringError, emptyTreeContent]),\n highlight: useMemo(() => (filter ? { text: filter } : undefined), [filter]),\n },\n rendererProps: {\n getDecorations: useCallback((node) => <CategoriesTreeIcon node={node} />, []),\n getSublabel,\n },\n };\n}\n\nfunction createVisibilityHandlerFactory(\n props: CreateFactoryProps<CategoriesTreeIdsCache, { hierarchyConfig: CategoriesTreeHierarchyConfiguration }>,\n): VisibilityTreeProps[\"visibilityHandlerFactory\"] {\n const { activeView, factoryProps, idsCacheGetter, filteredPaths } = props;\n return ({ imodelAccess }) =>\n createCategoriesTreeVisibilityHandler({\n viewport: activeView,\n idsCache: idsCacheGetter(),\n imodelAccess,\n filteredPaths,\n hierarchyConfig: factoryProps.hierarchyConfig,\n });\n}\n\nfunction getEmptyTreeContentComponent(filter?: string, error?: CategoriesTreeFilteringError, emptyTreeContent?: React.ReactNode) {\n if (error) {\n if (error === \"tooManyFilterMatches\") {\n return <TooManyFilterMatches base={\"categoriesTree\"} />;\n }\n return <FilterUnknownError base={\"categoriesTree\"} />;\n }\n if (filter) {\n return <NoFilterMatches base={\"categoriesTree\"} />;\n }\n if (emptyTreeContent) {\n return emptyTreeContent;\n }\n return <EmptyTreeContent icon={categorySvg} />;\n}\n\n/** @beta */\nexport function CategoriesTreeIcon({ node }: { node: PresentationHierarchyNode }) {\n if (node.nodeData.extendedData?.imageId === undefined) {\n return undefined;\n }\n\n const getIcon = () => {\n switch (node.nodeData.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 case \"icon-item\":\n return elementSvg;\n case \"icon-ec-class\":\n return classSvg;\n default:\n return undefined;\n }\n };\n\n return <Icon href={getIcon()} />;\n}\n\nfunction getSublabel(node: PresentationHierarchyNode) {\n return node.nodeData.extendedData?.description;\n}\n\nfunction useCategoriesCachedVisibility(props: {\n activeView: Viewport;\n getCache: () => CategoriesTreeIdsCache;\n hierarchyConfig: CategoriesTreeHierarchyConfiguration;\n}) {\n const { activeView, getCache, hierarchyConfig } = props;\n const { visibilityHandlerFactory, filteredPaths, onFilteredPathsChanged } = useCachedVisibility<\n CategoriesTreeIdsCache,\n { hierarchyConfig: CategoriesTreeHierarchyConfiguration }\n >({\n activeView,\n getCache,\n factoryProps: useMemo(() => ({ hierarchyConfig }), [hierarchyConfig]),\n createFactory: createVisibilityHandlerFactory,\n });\n\n useEffect(() => {\n getCache().clearFilteredElementsModels();\n }, [filteredPaths, getCache]);\n\n return {\n visibilityHandlerFactory,\n onFilteredPathsChanged,\n };\n}\n\nfunction createCache(props: CreateCacheProps<{ viewType: \"2d\" | \"3d\" }>) {\n return new CategoriesTreeIdsCache(createECSqlQueryExecutor(props.imodel), props.specificProps.viewType);\n}\n"]}
@@ -3,14 +3,17 @@ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
4
  * See LICENSE.md in the project root for license terms and full copyright notice.
5
5
  *--------------------------------------------------------------------------------------------*/
6
- import { useCallback, useEffect, useMemo, useState } from "react";
6
+ import { useCallback, useMemo } from "react";
7
+ import { createECSqlQueryExecutor } from "@itwin/presentation-core-interop";
7
8
  import iconBisCategory3d from "@stratakit/icons/bis-category-3d.svg";
8
9
  import { EmptyTreeContent } from "../common/components/EmptyTree.js";
10
+ import { useCachedVisibility } from "../common/internal/useTreeHooks/UseCachedVisibility.js";
11
+ import { useIdsCache } from "../common/internal/useTreeHooks/UseIdsCache.js";
9
12
  import { ClassificationsTreeComponent } from "./ClassificationsTreeComponent.js";
10
13
  import { ClassificationsTreeDefinition } from "./ClassificationsTreeDefinition.js";
11
14
  import { ClassificationsTreeIcon } from "./ClassificationsTreeIcon.js";
15
+ import { ClassificationsTreeIdsCache } from "./internal/ClassificationsTreeIdsCache.js";
12
16
  import { createClassificationsTreeVisibilityHandler } from "./internal/ClassificationsTreeVisibilityHandler.js";
13
- import { useIdsCache } from "./internal/UseIdsCache.js";
14
17
  /**
15
18
  * Custom hook to create and manage state for the categories tree.
16
19
  * @alpha
@@ -19,7 +22,17 @@ export function useClassificationsTree({ activeView, emptyTreeContent, ...rest }
19
22
  const hierarchyConfig = useMemo(() => ({ ...rest.hierarchyConfig }),
20
23
  // eslint-disable-next-line react-hooks/exhaustive-deps
21
24
  [...Object.values(rest.hierarchyConfig)]);
22
- const { getClassificationsTreeIdsCache, visibilityHandlerFactory } = useCachedVisibility(activeView, hierarchyConfig);
25
+ const { getCache: getClassificationsTreeIdsCache } = useIdsCache({
26
+ imodel: activeView.iModel,
27
+ createCache,
28
+ cacheSpecificProps: useMemo(() => ({ hierarchyConfig }), [hierarchyConfig]),
29
+ });
30
+ const { visibilityHandlerFactory } = useCachedVisibility({
31
+ activeView,
32
+ getCache: getClassificationsTreeIdsCache,
33
+ factoryProps: undefined,
34
+ createFactory: createVisibilityHandlerFactory,
35
+ });
23
36
  const getHierarchyDefinition = useCallback((props) => {
24
37
  return new ClassificationsTreeDefinition({ ...props, idsCache: getClassificationsTreeIdsCache(), hierarchyConfig });
25
38
  }, [getClassificationsTreeIdsCache, hierarchyConfig]);
@@ -35,18 +48,11 @@ export function useClassificationsTree({ activeView, emptyTreeContent, ...rest }
35
48
  },
36
49
  };
37
50
  }
38
- function createVisibilityHandlerFactory(activeView, idsCacheGetter) {
51
+ function createVisibilityHandlerFactory(props) {
52
+ const { activeView, idsCacheGetter } = props;
39
53
  return ({ imodelAccess }) => createClassificationsTreeVisibilityHandler({ viewport: activeView, idsCache: idsCacheGetter(), imodelAccess });
40
54
  }
41
- function useCachedVisibility(activeView, hierarchyConfig) {
42
- const { getCache: getClassificationsTreeIdsCache } = useIdsCache(activeView.iModel, hierarchyConfig);
43
- const [visibilityHandlerFactory, setVisibilityHandlerFactory] = useState(() => createVisibilityHandlerFactory(activeView, getClassificationsTreeIdsCache));
44
- useEffect(() => {
45
- setVisibilityHandlerFactory(() => createVisibilityHandlerFactory(activeView, getClassificationsTreeIdsCache));
46
- }, [activeView, getClassificationsTreeIdsCache]);
47
- return {
48
- getClassificationsTreeIdsCache,
49
- visibilityHandlerFactory,
50
- };
55
+ function createCache(props) {
56
+ return new ClassificationsTreeIdsCache(createECSqlQueryExecutor(props.imodel), props.specificProps.hierarchyConfig);
51
57
  }
52
58
  //# sourceMappingURL=UseClassificationsTree.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"UseClassificationsTree.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/classifications-tree/UseClassificationsTree.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,iBAAiB,MAAM,sCAAsC,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnF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,EAAE,CAAC,0CAA0C,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,cAAc,EAAE,EAAE,YAAY,EAAE,CAAC,CAAC;AAC9I,CAAC;AAED,SAAS,mBAAmB,CAAC,UAAoB,EAAE,eAA0D;IAC3G,MAAM,EAAE,QAAQ,EAAE,8BAA8B,EAAE,GAAG,WAAW,CAAC,UAAU,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACrG,MAAM,CAAC,wBAAwB,EAAE,2BAA2B,CAAC,GAAG,QAAQ,CAAkD,GAAG,EAAE,CAC7H,8BAA8B,CAAC,UAAU,EAAE,8BAA8B,CAAC,CAC3E,CAAC;IACF,SAAS,CAAC,GAAG,EAAE;QACb,2BAA2B,CAAC,GAAG,EAAE,CAAC,8BAA8B,CAAC,UAAU,EAAE,8BAA8B,CAAC,CAAC,CAAC;IAChH,CAAC,EAAE,CAAC,UAAU,EAAE,8BAA8B,CAAC,CAAC,CAAC;IACjD,OAAO;QACL,8BAA8B;QAC9B,wBAAwB;KACzB,CAAC;AACJ,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, useEffect, useMemo, useState } from \"react\";\nimport iconBisCategory3d from \"@stratakit/icons/bis-category-3d.svg\";\nimport { EmptyTreeContent } from \"../common/components/EmptyTree.js\";\nimport { ClassificationsTreeComponent } from \"./ClassificationsTreeComponent.js\";\nimport { ClassificationsTreeDefinition } from \"./ClassificationsTreeDefinition.js\";\nimport { ClassificationsTreeIcon } from \"./ClassificationsTreeIcon.js\";\nimport { createClassificationsTreeVisibilityHandler } from \"./internal/ClassificationsTreeVisibilityHandler.js\";\nimport { useIdsCache } from \"./internal/UseIdsCache.js\";\n\nimport type { ClassificationsTreeHierarchyConfiguration } from \"./ClassificationsTreeDefinition.js\";\nimport type { ReactNode } from \"react\";\nimport type { Viewport } from \"@itwin/core-frontend\";\nimport type { VisibilityTreeProps } from \"../common/components/VisibilityTree.js\";\nimport type { VisibilityTreeRendererProps } from \"../common/components/VisibilityTreeRenderer.js\";\nimport type { ClassificationsTreeIdsCache } from \"./internal/ClassificationsTreeIdsCache.js\";\n\n/** @alpha */\nexport interface UseClassificationsTreeProps {\n activeView: Viewport;\n hierarchyConfig: ClassificationsTreeHierarchyConfiguration;\n emptyTreeContent?: ReactNode;\n}\n\n/** @alpha */\ninterface UseClassificationsTreeResult {\n categoriesTreeProps: Pick<VisibilityTreeProps, \"treeName\" | \"getHierarchyDefinition\" | \"visibilityHandlerFactory\" | \"emptyTreeContent\">;\n rendererProps: Required<Pick<VisibilityTreeRendererProps, \"getDecorations\">>;\n}\n\n/**\n * Custom hook to create and manage state for the categories tree.\n * @alpha\n */\nexport function useClassificationsTree({ activeView, emptyTreeContent, ...rest }: UseClassificationsTreeProps): UseClassificationsTreeResult {\n const hierarchyConfig = useMemo(\n () => ({ ...rest.hierarchyConfig }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [...Object.values(rest.hierarchyConfig)],\n );\n const { getClassificationsTreeIdsCache, visibilityHandlerFactory } = useCachedVisibility(activeView, hierarchyConfig);\n\n const getHierarchyDefinition = useCallback<VisibilityTreeProps[\"getHierarchyDefinition\"]>(\n (props) => {\n return new ClassificationsTreeDefinition({ ...props, idsCache: getClassificationsTreeIdsCache(), hierarchyConfig });\n },\n [getClassificationsTreeIdsCache, hierarchyConfig],\n );\n\n return {\n categoriesTreeProps: {\n treeName: ClassificationsTreeComponent.id,\n getHierarchyDefinition,\n visibilityHandlerFactory,\n emptyTreeContent: emptyTreeContent ?? <EmptyTreeContent icon={iconBisCategory3d} />,\n },\n rendererProps: {\n getDecorations: useCallback((node) => <ClassificationsTreeIcon node={node} />, []),\n },\n };\n}\n\nfunction createVisibilityHandlerFactory(\n activeView: Viewport,\n idsCacheGetter: () => ClassificationsTreeIdsCache,\n): VisibilityTreeProps[\"visibilityHandlerFactory\"] {\n return ({ imodelAccess }) => createClassificationsTreeVisibilityHandler({ viewport: activeView, idsCache: idsCacheGetter(), imodelAccess });\n}\n\nfunction useCachedVisibility(activeView: Viewport, hierarchyConfig: ClassificationsTreeHierarchyConfiguration) {\n const { getCache: getClassificationsTreeIdsCache } = useIdsCache(activeView.iModel, hierarchyConfig);\n const [visibilityHandlerFactory, setVisibilityHandlerFactory] = useState<VisibilityTreeProps[\"visibilityHandlerFactory\"]>(() =>\n createVisibilityHandlerFactory(activeView, getClassificationsTreeIdsCache),\n );\n useEffect(() => {\n setVisibilityHandlerFactory(() => createVisibilityHandlerFactory(activeView, getClassificationsTreeIdsCache));\n }, [activeView, getClassificationsTreeIdsCache]);\n return {\n getClassificationsTreeIdsCache,\n visibilityHandlerFactory,\n };\n}\n"]}
1
+ {"version":3,"file":"UseClassificationsTree.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/classifications-tree/UseClassificationsTree.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,iBAAiB,MAAM,sCAAsC,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wDAAwD,CAAC;AAC7F,OAAO,EAAE,WAAW,EAAE,MAAM,gDAAgD,CAAC;AAC7E,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,6BAA6B,EAAE,MAAM,oCAAoC,CAAC;AACnF,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAC;AACxF,OAAO,EAAE,0CAA0C,EAAE,MAAM,oDAAoD,CAAC;AAuBhH;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AAI,GAAI,EAAE,EAAE,CAAC;SACnF;KACF,CAAC;AACJ,CAAC;AAED,SAAS,8BAA8B,CAAC,KAAiE;IACvG,MAAM,EAAE,UAAU,EAAE,cAAc,EAAE,GAAG,KAAK,CAAC;IAC7C,OAAO,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,0CAA0C,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,cAAc,EAAE,EAAE,YAAY,EAAE,CAAC,CAAC;AAC9I,CAAC;AAED,SAAS,WAAW,CAAC,KAAwF;IAC3G,OAAO,IAAI,2BAA2B,CAAC,wBAAwB,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;AACtH,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 } from \"react\";\nimport { createECSqlQueryExecutor } from \"@itwin/presentation-core-interop\";\nimport iconBisCategory3d from \"@stratakit/icons/bis-category-3d.svg\";\nimport { EmptyTreeContent } from \"../common/components/EmptyTree.js\";\nimport { useCachedVisibility } from \"../common/internal/useTreeHooks/UseCachedVisibility.js\";\nimport { useIdsCache } from \"../common/internal/useTreeHooks/UseIdsCache.js\";\nimport { ClassificationsTreeComponent } from \"./ClassificationsTreeComponent.js\";\nimport { ClassificationsTreeDefinition } from \"./ClassificationsTreeDefinition.js\";\nimport { ClassificationsTreeIcon } from \"./ClassificationsTreeIcon.js\";\nimport { ClassificationsTreeIdsCache } from \"./internal/ClassificationsTreeIdsCache.js\";\nimport { createClassificationsTreeVisibilityHandler } from \"./internal/ClassificationsTreeVisibilityHandler.js\";\n\nimport type { CreateCacheProps } from \"../common/internal/useTreeHooks/UseIdsCache.js\";\nimport type { CreateFactoryProps } from \"../common/internal/useTreeHooks/UseCachedVisibility.js\";\nimport type { ClassificationsTreeHierarchyConfiguration } from \"./ClassificationsTreeDefinition.js\";\nimport type { ReactNode } from \"react\";\nimport type { Viewport } from \"@itwin/core-frontend\";\nimport type { VisibilityTreeProps } from \"../common/components/VisibilityTree.js\";\nimport type { VisibilityTreeRendererProps } from \"../common/components/VisibilityTreeRenderer.js\";\n\n/** @alpha */\nexport interface UseClassificationsTreeProps {\n activeView: Viewport;\n hierarchyConfig: ClassificationsTreeHierarchyConfiguration;\n emptyTreeContent?: ReactNode;\n}\n\n/** @alpha */\ninterface UseClassificationsTreeResult {\n categoriesTreeProps: Pick<VisibilityTreeProps, \"treeName\" | \"getHierarchyDefinition\" | \"visibilityHandlerFactory\" | \"emptyTreeContent\">;\n rendererProps: Required<Pick<VisibilityTreeRendererProps, \"getDecorations\">>;\n}\n\n/**\n * Custom hook to create and manage state for the categories tree.\n * @alpha\n */\nexport function useClassificationsTree({ activeView, emptyTreeContent, ...rest }: UseClassificationsTreeProps): UseClassificationsTreeResult {\n const hierarchyConfig = useMemo(\n () => ({ ...rest.hierarchyConfig }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [...Object.values(rest.hierarchyConfig)],\n );\n\n const { getCache: getClassificationsTreeIdsCache } = useIdsCache<ClassificationsTreeIdsCache, { hierarchyConfig: ClassificationsTreeHierarchyConfiguration }>(\n {\n imodel: activeView.iModel,\n createCache,\n cacheSpecificProps: useMemo(() => ({ hierarchyConfig }), [hierarchyConfig]),\n },\n );\n\n const { visibilityHandlerFactory } = useCachedVisibility<ClassificationsTreeIdsCache, undefined>({\n activeView,\n getCache: getClassificationsTreeIdsCache,\n factoryProps: undefined,\n createFactory: createVisibilityHandlerFactory,\n });\n\n const getHierarchyDefinition = useCallback<VisibilityTreeProps[\"getHierarchyDefinition\"]>(\n (props) => {\n return new ClassificationsTreeDefinition({ ...props, idsCache: getClassificationsTreeIdsCache(), hierarchyConfig });\n },\n [getClassificationsTreeIdsCache, hierarchyConfig],\n );\n\n return {\n categoriesTreeProps: {\n treeName: ClassificationsTreeComponent.id,\n getHierarchyDefinition,\n visibilityHandlerFactory,\n emptyTreeContent: emptyTreeContent ?? <EmptyTreeContent icon={iconBisCategory3d} />,\n },\n rendererProps: {\n getDecorations: useCallback((node) => <ClassificationsTreeIcon node={node} />, []),\n },\n };\n}\n\nfunction createVisibilityHandlerFactory(props: CreateFactoryProps<ClassificationsTreeIdsCache, undefined>): VisibilityTreeProps[\"visibilityHandlerFactory\"] {\n const { activeView, idsCacheGetter } = props;\n return ({ imodelAccess }) => createClassificationsTreeVisibilityHandler({ viewport: activeView, idsCache: idsCacheGetter(), imodelAccess });\n}\n\nfunction createCache(props: CreateCacheProps<{ hierarchyConfig: ClassificationsTreeHierarchyConfiguration }>) {\n return new ClassificationsTreeIdsCache(createECSqlQueryExecutor(props.imodel), props.specificProps.hierarchyConfig);\n}\n"]}
@@ -0,0 +1,26 @@
1
+ import type { Viewport } from "@itwin/core-frontend";
2
+ import type { HierarchyFilteringPath } from "@itwin/presentation-hierarchies";
3
+ import type { VisibilityTreeProps } from "../../components/VisibilityTree.js";
4
+ /** @internal */
5
+ export interface CreateFactoryProps<TCache, TFactorySpecificProps> {
6
+ activeView: Viewport;
7
+ idsCacheGetter: () => TCache;
8
+ filteredPaths: HierarchyFilteringPath[] | undefined;
9
+ factoryProps: TFactorySpecificProps;
10
+ }
11
+ /** @internal */
12
+ export interface UseCachedVisibilityProps<TCache, TFactorySpecificProps> {
13
+ activeView: Viewport;
14
+ getCache: () => TCache;
15
+ factoryProps: TFactorySpecificProps;
16
+ createFactory: (props: CreateFactoryProps<TCache, TFactorySpecificProps>) => VisibilityTreeProps["visibilityHandlerFactory"];
17
+ }
18
+ /** @internal */
19
+ export declare function useCachedVisibility<TCache, TFactorySpecificProps extends object | undefined>(props: UseCachedVisibilityProps<TCache, TFactorySpecificProps>): {
20
+ visibilityHandlerFactory: (props: {
21
+ imodelAccess: import("@itwin/presentation-shared").ECClassHierarchyInspector;
22
+ }) => import("../../UseHierarchyVisibility.js").HierarchyVisibilityHandler;
23
+ onFilteredPathsChanged: (paths: HierarchyFilteringPath[] | undefined) => void;
24
+ filteredPaths: HierarchyFilteringPath[] | undefined;
25
+ };
26
+ //# sourceMappingURL=UseCachedVisibility.d.ts.map
@@ -0,0 +1,20 @@
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 { useCallback, useEffect, useState } from "react";
6
+ /** @internal */
7
+ export function useCachedVisibility(props) {
8
+ const [filteredPaths, setFilteredPaths] = useState(undefined);
9
+ const { activeView, getCache, factoryProps, createFactory } = props;
10
+ const [visibilityHandlerFactory, setVisibilityHandlerFactory] = useState(() => createFactory({ activeView, idsCacheGetter: getCache, filteredPaths, factoryProps }));
11
+ useEffect(() => {
12
+ setVisibilityHandlerFactory(() => createFactory({ activeView, idsCacheGetter: getCache, filteredPaths, factoryProps }));
13
+ }, [activeView, getCache, factoryProps, filteredPaths, createFactory]);
14
+ return {
15
+ visibilityHandlerFactory,
16
+ onFilteredPathsChanged: useCallback((paths) => setFilteredPaths(paths), []),
17
+ filteredPaths,
18
+ };
19
+ }
20
+ //# sourceMappingURL=UseCachedVisibility.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UseCachedVisibility.js","sourceRoot":"","sources":["../../../../../../../../src/tree-widget-react/components/trees/common/internal/useTreeHooks/UseCachedVisibility.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAsBzD,gBAAgB;AAChB,MAAM,UAAU,mBAAmB,CAA2D,KAA8D;IAC1J,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAAuC,SAAS,CAAC,CAAC;IACpG,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAE,GAAG,KAAK,CAAC;IAEpE,MAAM,CAAC,wBAAwB,EAAE,2BAA2B,CAAC,GAAG,QAAQ,CAAkD,GAAG,EAAE,CAC7H,aAAa,CAAC,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC,CACrF,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,2BAA2B,CAAC,GAAG,EAAE,CAAC,aAAa,CAAC,EAAE,UAAU,EAAE,cAAc,EAAE,QAAQ,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC;IAC1H,CAAC,EAAE,CAAC,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC;IAEvE,OAAO;QACL,wBAAwB;QACxB,sBAAsB,EAAE,WAAW,CAAC,CAAC,KAA2C,EAAE,EAAE,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC;QACjH,aAAa;KACd,CAAC;AACJ,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, useEffect, useState } from \"react\";\n\nimport type { Viewport } from \"@itwin/core-frontend\";\nimport type { HierarchyFilteringPath } from \"@itwin/presentation-hierarchies\";\nimport type { VisibilityTreeProps } from \"../../components/VisibilityTree.js\";\n\n/** @internal */\nexport interface CreateFactoryProps<TCache, TFactorySpecificProps> {\n activeView: Viewport;\n idsCacheGetter: () => TCache;\n filteredPaths: HierarchyFilteringPath[] | undefined;\n factoryProps: TFactorySpecificProps;\n}\n\n/** @internal */\nexport interface UseCachedVisibilityProps<TCache, TFactorySpecificProps> {\n activeView: Viewport;\n getCache: () => TCache;\n factoryProps: TFactorySpecificProps;\n createFactory: (props: CreateFactoryProps<TCache, TFactorySpecificProps>) => VisibilityTreeProps[\"visibilityHandlerFactory\"];\n}\n\n/** @internal */\nexport function useCachedVisibility<TCache, TFactorySpecificProps extends object | undefined>(props: UseCachedVisibilityProps<TCache, TFactorySpecificProps>) {\n const [filteredPaths, setFilteredPaths] = useState<HierarchyFilteringPath[] | undefined>(undefined);\n const { activeView, getCache, factoryProps, createFactory } = props;\n\n const [visibilityHandlerFactory, setVisibilityHandlerFactory] = useState<VisibilityTreeProps[\"visibilityHandlerFactory\"]>(() =>\n createFactory({ activeView, idsCacheGetter: getCache, filteredPaths, factoryProps }),\n );\n\n useEffect(() => {\n setVisibilityHandlerFactory(() => createFactory({ activeView, idsCacheGetter: getCache, filteredPaths, factoryProps }));\n }, [activeView, getCache, factoryProps, filteredPaths, createFactory]);\n\n return {\n visibilityHandlerFactory,\n onFilteredPathsChanged: useCallback((paths: HierarchyFilteringPath[] | undefined) => setFilteredPaths(paths), []),\n filteredPaths,\n };\n}\n"]}
@@ -0,0 +1,17 @@
1
+ import type { IModelConnection } from "@itwin/core-frontend";
2
+ /** @internal */
3
+ export interface CreateCacheProps<TCacheSpecificProps> {
4
+ imodel: IModelConnection;
5
+ specificProps: TCacheSpecificProps;
6
+ }
7
+ /** @internal */
8
+ export interface UseIdsCacheProps<TCache, TCacheSpecificProps> {
9
+ imodel: IModelConnection;
10
+ createCache: (props: CreateCacheProps<TCacheSpecificProps>) => TCache;
11
+ cacheSpecificProps: TCacheSpecificProps;
12
+ }
13
+ /** @internal */
14
+ export declare function useIdsCache<TCache extends Disposable, TCacheSpecificProps extends object>(props: UseIdsCacheProps<TCache, TCacheSpecificProps>): {
15
+ getCache: () => TCache;
16
+ };
17
+ //# sourceMappingURL=UseIdsCache.d.ts.map
@@ -3,42 +3,41 @@
3
3
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
  import { useCallback, useEffect, useRef, useState } from "react";
6
- import { createECSqlQueryExecutor } from "@itwin/presentation-core-interop";
7
- import { useIModelChangeListener } from "../../common/internal/UseIModelChangeListener.js";
8
- import { ModelsTreeIdsCache } from "./ModelsTreeIdsCache.js";
6
+ import { useIModelChangeListener } from "../UseIModelChangeListener.js";
9
7
  /** @internal */
10
- export function useIdsCache(imodel, hierarchyConfig) {
8
+ export function useIdsCache(props) {
11
9
  const cacheRef = useRef(undefined);
12
10
  const clearCacheRef = useRef(() => {
13
11
  cacheRef.current?.[Symbol.dispose]?.();
14
12
  cacheRef.current = undefined;
15
13
  });
16
- const createCacheGetterRef = useRef((currImodel, currHierarchyConfig) => {
14
+ const { imodel, createCache, cacheSpecificProps } = props;
15
+ const createCacheGetterRef = useRef((currImodel, specificProps) => {
17
16
  return () => {
18
17
  if (cacheRef.current === undefined) {
19
- cacheRef.current = new ModelsTreeIdsCache(createECSqlQueryExecutor(currImodel), currHierarchyConfig);
18
+ cacheRef.current = createCache({ imodel: currImodel, specificProps });
20
19
  }
21
20
  return cacheRef.current;
22
21
  };
23
22
  });
24
- const [getCache, setCacheGetter] = useState(() => createCacheGetterRef.current(imodel, hierarchyConfig));
23
+ const [getCache, setCacheGetter] = useState(() => createCacheGetterRef.current(imodel, cacheSpecificProps));
25
24
  useEffect(() => {
26
25
  // clear cache in case it was created before `useEffect` was run first time
27
26
  clearCacheRef.current();
28
27
  // make sure all cache users rerender
29
- setCacheGetter(() => createCacheGetterRef.current(imodel, hierarchyConfig));
28
+ setCacheGetter(() => createCacheGetterRef.current(imodel, cacheSpecificProps));
30
29
  return () => {
31
30
  // eslint-disable-next-line react-hooks/exhaustive-deps
32
31
  clearCacheRef.current();
33
32
  };
34
- }, [imodel, hierarchyConfig]);
33
+ }, [imodel, cacheSpecificProps]);
35
34
  useIModelChangeListener({
36
35
  imodel,
37
36
  action: useCallback(() => {
38
37
  clearCacheRef.current();
39
38
  // make sure all cache users rerender
40
- setCacheGetter(() => createCacheGetterRef.current(imodel, hierarchyConfig));
41
- }, [imodel, hierarchyConfig]),
39
+ setCacheGetter(() => createCacheGetterRef.current(imodel, cacheSpecificProps));
40
+ }, [imodel, cacheSpecificProps]),
42
41
  });
43
42
  return {
44
43
  getCache,
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UseIdsCache.js","sourceRoot":"","sources":["../../../../../../../../src/tree-widget-react/components/trees/common/internal/useTreeHooks/UseIdsCache.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAiBxE,gBAAgB;AAChB,MAAM,UAAU,WAAW,CACzB,KAAoD;IAEpD,MAAM,QAAQ,GAAG,MAAM,CAAqB,SAAS,CAAC,CAAC;IACvD,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,EAAE;QAChC,QAAQ,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC;QACvC,QAAQ,CAAC,OAAO,GAAG,SAAS,CAAC;IAC/B,CAAC,CAAC,CAAC;IACH,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,kBAAkB,EAAE,GAAG,KAAK,CAAC;IAE1D,MAAM,oBAAoB,GAAG,MAAM,CAAC,CAAC,UAA4B,EAAE,aAAkC,EAAE,EAAE;QACvG,OAAO,GAAG,EAAE;YACV,IAAI,QAAQ,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;gBACnC,QAAQ,CAAC,OAAO,GAAG,WAAW,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC,CAAC;YACxE,CAAC;YACD,OAAO,QAAQ,CAAC,OAAO,CAAC;QAC1B,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,QAAQ,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAe,GAAG,EAAE,CAAC,oBAAoB,CAAC,OAAO,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;IAE1H,SAAS,CAAC,GAAG,EAAE;QACb,2EAA2E;QAC3E,aAAa,CAAC,OAAO,EAAE,CAAC;QAExB,qCAAqC;QACrC,cAAc,CAAC,GAAG,EAAE,CAAC,oBAAoB,CAAC,OAAO,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;QAC/E,OAAO,GAAG,EAAE;YACV,uDAAuD;YACvD,aAAa,CAAC,OAAO,EAAE,CAAC;QAC1B,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;IAEjC,uBAAuB,CAAC;QACtB,MAAM;QACN,MAAM,EAAE,WAAW,CAAC,GAAG,EAAE;YACvB,aAAa,CAAC,OAAO,EAAE,CAAC;YACxB,qCAAqC;YACrC,cAAc,CAAC,GAAG,EAAE,CAAC,oBAAoB,CAAC,OAAO,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;QACjF,CAAC,EAAE,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;KACjC,CAAC,CAAC;IAEH,OAAO;QACL,QAAQ;KACT,CAAC;AACJ,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, useEffect, useRef, useState } from \"react\";\nimport { useIModelChangeListener } from \"../UseIModelChangeListener.js\";\n\nimport type { IModelConnection } from \"@itwin/core-frontend\";\n\n/** @internal */\nexport interface CreateCacheProps<TCacheSpecificProps> {\n imodel: IModelConnection;\n specificProps: TCacheSpecificProps;\n}\n\n/** @internal */\nexport interface UseIdsCacheProps<TCache, TCacheSpecificProps> {\n imodel: IModelConnection;\n createCache: (props: CreateCacheProps<TCacheSpecificProps>) => TCache;\n cacheSpecificProps: TCacheSpecificProps;\n}\n\n/** @internal */\nexport function useIdsCache<TCache extends Disposable, TCacheSpecificProps extends object>(\n props: UseIdsCacheProps<TCache, TCacheSpecificProps>,\n): { getCache: () => TCache } {\n const cacheRef = useRef<TCache | undefined>(undefined);\n const clearCacheRef = useRef(() => {\n cacheRef.current?.[Symbol.dispose]?.();\n cacheRef.current = undefined;\n });\n const { imodel, createCache, cacheSpecificProps } = props;\n\n const createCacheGetterRef = useRef((currImodel: IModelConnection, specificProps: TCacheSpecificProps) => {\n return () => {\n if (cacheRef.current === undefined) {\n cacheRef.current = createCache({ imodel: currImodel, specificProps });\n }\n return cacheRef.current;\n };\n });\n\n const [getCache, setCacheGetter] = useState<() => TCache>(() => createCacheGetterRef.current(imodel, cacheSpecificProps));\n\n useEffect(() => {\n // clear cache in case it was created before `useEffect` was run first time\n clearCacheRef.current();\n\n // make sure all cache users rerender\n setCacheGetter(() => createCacheGetterRef.current(imodel, cacheSpecificProps));\n return () => {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n clearCacheRef.current();\n };\n }, [imodel, cacheSpecificProps]);\n\n useIModelChangeListener({\n imodel,\n action: useCallback(() => {\n clearCacheRef.current();\n // make sure all cache users rerender\n setCacheGetter(() => createCacheGetterRef.current(imodel, cacheSpecificProps));\n }, [imodel, cacheSpecificProps]),\n });\n\n return {\n getCache,\n };\n}\n"]}
@@ -3,7 +3,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
4
  * See LICENSE.md in the project root for license terms and full copyright notice.
5
5
  *--------------------------------------------------------------------------------------------*/
6
- import { useCallback, useEffect, useMemo, useState } from "react";
6
+ import { useCallback, useMemo } from "react";
7
+ import { createECSqlQueryExecutor } from "@itwin/presentation-core-interop";
7
8
  import { Icon } from "@stratakit/foundations";
8
9
  import categorySvg from "@stratakit/icons/bis-category-3d.svg";
9
10
  import classSvg from "@stratakit/icons/bis-class.svg";
@@ -11,10 +12,12 @@ import elementSvg from "@stratakit/icons/bis-element.svg";
11
12
  import subjectSvg from "@stratakit/icons/bis-subject.svg";
12
13
  import modelSvg from "@stratakit/icons/model-cube.svg";
13
14
  import { EmptyTreeContent, FilterUnknownError, NoFilterMatches, TooManyFilterMatches, TooManyInstancesFocused, UnknownInstanceFocusError, } from "../common/components/EmptyTree.js";
15
+ import { useCachedVisibility } from "../common/internal/useTreeHooks/UseCachedVisibility.js";
16
+ import { useIdsCache } from "../common/internal/useTreeHooks/UseIdsCache.js";
17
+ import { ModelsTreeIdsCache } from "./internal/ModelsTreeIdsCache.js";
14
18
  import { ModelsTreeNode } from "./internal/ModelsTreeNode.js";
15
19
  import { createModelsTreeVisibilityHandler } from "./internal/ModelsTreeVisibilityHandler.js";
16
20
  import { useFilteredPaths } from "./internal/UseFilteredPaths.js";
17
- import { useIdsCache } from "./internal/UseIdsCache.js";
18
21
  import { defaultHierarchyConfiguration, ModelsTreeDefinition } from "./ModelsTreeDefinition.js";
19
22
  /**
20
23
  * Custom hook to create and manage state for the models tree.
@@ -27,7 +30,17 @@ export function useModelsTree({ activeView, filter, hierarchyConfig, visibilityH
27
30
  }),
28
31
  // eslint-disable-next-line react-hooks/exhaustive-deps
29
32
  Object.values(hierarchyConfig ?? {}));
30
- const { getModelsTreeIdsCache, visibilityHandlerFactory, onFilteredPathsChanged } = useCachedVisibility(activeView, hierarchyConfiguration, visibilityHandlerOverrides);
33
+ const { getCache: getModelsTreeIdsCache } = useIdsCache({
34
+ imodel: activeView.iModel,
35
+ createCache,
36
+ cacheSpecificProps: useMemo(() => ({ hierarchyConfig: hierarchyConfiguration }), [hierarchyConfiguration]),
37
+ });
38
+ const { visibilityHandlerFactory, onFilteredPathsChanged } = useCachedVisibility({
39
+ activeView,
40
+ createFactory: createVisibilityHandlerFactory,
41
+ factoryProps: useMemo(() => ({ overrides: visibilityHandlerOverrides }), [visibilityHandlerOverrides]),
42
+ getCache: getModelsTreeIdsCache,
43
+ });
31
44
  const getHierarchyDefinition = useCallback(({ imodelAccess }) => new ModelsTreeDefinition({ imodelAccess, idsCache: getModelsTreeIdsCache(), hierarchyConfig: hierarchyConfiguration }), [getModelsTreeIdsCache, hierarchyConfiguration]);
32
45
  const { getPaths, filteringError } = useFilteredPaths({
33
46
  hierarchyConfiguration,
@@ -60,21 +73,15 @@ export function useModelsTree({ activeView, filter, hierarchyConfig, visibilityH
60
73
  },
61
74
  };
62
75
  }
63
- function createVisibilityHandlerFactory(activeView, idsCacheGetter, overrides, filteredPaths) {
64
- return ({ imodelAccess }) => createModelsTreeVisibilityHandler({ viewport: activeView, idsCache: idsCacheGetter(), imodelAccess, overrides, filteredPaths });
65
- }
66
- function useCachedVisibility(activeView, hierarchyConfig, overrides) {
67
- const { getCache: getModelsTreeIdsCache } = useIdsCache(activeView.iModel, hierarchyConfig);
68
- const [filteredPaths, setFilteredPaths] = useState();
69
- const [visibilityHandlerFactory, setVisibilityHandlerFactory] = useState(() => createVisibilityHandlerFactory(activeView, getModelsTreeIdsCache, overrides, filteredPaths));
70
- useEffect(() => {
71
- setVisibilityHandlerFactory(() => createVisibilityHandlerFactory(activeView, getModelsTreeIdsCache, overrides, filteredPaths));
72
- }, [activeView, getModelsTreeIdsCache, overrides, filteredPaths]);
73
- return {
74
- getModelsTreeIdsCache,
75
- visibilityHandlerFactory,
76
- onFilteredPathsChanged: useCallback((paths) => setFilteredPaths(paths), []),
77
- };
76
+ function createVisibilityHandlerFactory(props) {
77
+ const { activeView, idsCacheGetter, filteredPaths, factoryProps } = props;
78
+ return ({ imodelAccess }) => createModelsTreeVisibilityHandler({
79
+ viewport: activeView,
80
+ idsCache: idsCacheGetter(),
81
+ imodelAccess,
82
+ overrides: factoryProps.overrides,
83
+ filteredPaths,
84
+ });
78
85
  }
79
86
  function getEmptyTreeContentComponent(filter, error, emptyTreeContent) {
80
87
  if (isInstanceFocusError(error)) {
@@ -129,4 +136,7 @@ export function ModelsTreeIcon({ node }) {
129
136
  };
130
137
  return _jsx(Icon, { href: getIcon() });
131
138
  }
139
+ function createCache(props) {
140
+ return new ModelsTreeIdsCache(createECSqlQueryExecutor(props.imodel), props.specificProps.hierarchyConfig);
141
+ }
132
142
  //# sourceMappingURL=UseModelsTree.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"UseModelsTree.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/models-tree/UseModelsTree.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,WAAW,MAAM,sCAAsC,CAAC;AAC/D,OAAO,QAAQ,MAAM,gCAAgC,CAAC;AACtD,OAAO,UAAU,MAAM,kCAAkC,CAAC;AAC1D,OAAO,UAAU,MAAM,kCAAkC,CAAC;AAC1D,OAAO,QAAQ,MAAM,iCAAiC,CAAC;AACvD,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,iCAAiC,EAAE,MAAM,2CAA2C,CAAC;AAC9F,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,6BAA6B,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAqEhG;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,EAC5B,UAAU,EACV,MAAM,EACN,eAAe,EACf,0BAA0B,EAC1B,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAAE,0BAA0B,EAC9C,gBAAgB,GACG;IACnB,MAAM,sBAAsB,GAAG,OAAO,CACpC,GAAG,EAAE,CAAC,CAAC;QACL,GAAG,6BAA6B;QAChC,GAAG,eAAe;KACnB,CAAC;IACF,uDAAuD;IACvD,MAAM,CAA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ACD,OAAO,KAAC,yBAAyB,IAAC,IAAI,EAAE,YAAY,GAAI,CAAC;AAC3D,CAAC;AAED,YAAY;AACZ,MAAM,UAAU,cAAc,CAAC,EAAE,IAAI,EAAuC;IAC1E,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,KAAK,SAAS,EAAE,CAAC;QACtD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,OAAO,GAAG,GAAG,EAAE;QACnB,QAAQ,IAAI,CAAC,QAAQ,CAAC,YAAa,CAAC,OAAO,EAAE,CAAC;YAC5C,KAAK,aAAa;gBAChB,OAAO,WAAW,CAAC;YACrB,KAAK,WAAW;gBACd,OAAO,UAAU,CAAC;YACpB,KAAK,eAAe;gBAClB,OAAO,QAAQ,CAAC;YAClB,KAAK,aAAa;gBAChB,OAAO,UAAU,CAAC;YACpB,KAAK,YAAY;gBACf,OAAO,QAAQ,CAAC;YAClB;gBACE,OAAO,SAAS,CAAC;QACrB,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,KAAC,IAAI,IAAC,IAAI,EAAE,OAAO,EAAE,GAAI,CAAC;AACnC,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, useEffect, useMemo, useState } from \"react\";\nimport { Icon } from \"@stratakit/foundations\";\nimport categorySvg from \"@stratakit/icons/bis-category-3d.svg\";\nimport classSvg from \"@stratakit/icons/bis-class.svg\";\nimport elementSvg from \"@stratakit/icons/bis-element.svg\";\nimport subjectSvg from \"@stratakit/icons/bis-subject.svg\";\nimport modelSvg from \"@stratakit/icons/model-cube.svg\";\nimport {\n EmptyTreeContent,\n FilterUnknownError,\n NoFilterMatches,\n TooManyFilterMatches,\n TooManyInstancesFocused,\n UnknownInstanceFocusError,\n} from \"../common/components/EmptyTree.js\";\nimport { ModelsTreeNode } from \"./internal/ModelsTreeNode.js\";\nimport { createModelsTreeVisibilityHandler } from \"./internal/ModelsTreeVisibilityHandler.js\";\nimport { useFilteredPaths } from \"./internal/UseFilteredPaths.js\";\nimport { useIdsCache } from \"./internal/UseIdsCache.js\";\nimport { defaultHierarchyConfiguration, ModelsTreeDefinition } from \"./ModelsTreeDefinition.js\";\n\nimport type { ModelsTreeIdsCache } from \"./internal/ModelsTreeIdsCache.js\";\nimport type { ReactNode } from \"react\";\nimport type { HierarchyFilteringPath } from \"@itwin/presentation-hierarchies\";\nimport type { Id64String } from \"@itwin/core-bentley\";\nimport type { InstanceKey } from \"@itwin/presentation-shared\";\nimport type { Viewport } from \"@itwin/core-frontend\";\nimport type { PresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport type { ElementsGroupInfo, ModelsTreeHierarchyConfiguration } from \"./ModelsTreeDefinition.js\";\nimport type { ModelsTreeVisibilityHandlerOverrides } from \"./internal/ModelsTreeVisibilityHandler.js\";\nimport type { VisibilityTreeProps } from \"../common/components/VisibilityTree.js\";\nimport type { VisibilityTreeRendererProps } from \"../common/components/VisibilityTreeRenderer.js\";\nimport type { ModelsTreeFilteringError } from \"./internal/UseFilteredPaths.js\";\n\n/** @beta */\nexport interface UseModelsTreeProps {\n /**\n * Optional search string used to filter tree nodes by label, as well as highlight matching substrings in the tree.\n * Nodes that do not contain this string in their label will be filtered out.\n *\n * If `getFilteredPaths` function is provided, it will take precedence and automatic filtering by this string will not be applied.\n * Instead, the string will be supplied to the given `getFilteredPaths` function for consumers to apply the filtering.\n */\n filter?: string;\n activeView: Viewport;\n hierarchyConfig?: Partial<ModelsTreeHierarchyConfiguration>;\n visibilityHandlerOverrides?: ModelsTreeVisibilityHandlerOverrides;\n /**\n * Optional function for applying custom filtering on the hierarchy. Use it when you want full control over which nodes should be displayed, based on more complex logic or known instance keys.\n *\n * When defined, this function takes precedence over filtering by `filter` string. If both are supplied, the `filter` is provided as an argument to `getFilteredPaths`.\n *\n * @param props Parameters provided when `getFilteredPaths` is called:\n * - `createInstanceKeyPaths`: Helper function to create filter paths.\n * - `filter`: The filter string which would otherwise be used for default filtering.\n *\n * **Example use cases:**\n * - You have a list of `InstanceKey` items, which you want to use for filtering the hierarchy.\n * - You want to create filter paths based on node label, but also apply some extra conditions (for example exclude paths with sub-models).\n * - You want to construct custom filtered paths. For example: create a filter path for each geometric element which has a parent element.\n *\n * @note Paths returned by `createInstanceKeyPaths` will not have `autoExpand` flag set. If you want nodes to be expanded, iterate over the paths and\n * set `autoExpand: true` manually.\n */\n getFilteredPaths?: (props: {\n /** A function that creates filtering paths based on provided target instance keys or node label. */\n createInstanceKeyPaths: (props: { targetItems: Array<InstanceKey | ElementsGroupInfo> } | { label: string }) => Promise<HierarchyFilteringPath[]>;\n /** Filter which would be used to create filter paths if `getFilteredPaths` wouldn't be provided. */\n filter?: string;\n }) => Promise<HierarchyFilteringPath[]>;\n onModelsFiltered?: (modelIds: Id64String[] | undefined) => void;\n /**\n * An optional predicate to allow or prohibit selection of a node.\n * When not supplied, all nodes are selectable.\n */\n selectionPredicate?: (props: { node: PresentationHierarchyNode; type: \"subject\" | \"model\" | \"category\" | \"element\" | \"elements-class-group\" }) => boolean;\n emptyTreeContent?: ReactNode;\n}\n\n/** @beta */\ninterface UseModelsTreeResult {\n modelsTreeProps: Pick<\n VisibilityTreeProps,\n \"treeName\" | \"getHierarchyDefinition\" | \"getFilteredPaths\" | \"visibilityHandlerFactory\" | \"highlight\" | \"emptyTreeContent\" | \"selectionPredicate\"\n >;\n rendererProps: Required<Pick<VisibilityTreeRendererProps, \"getDecorations\">>;\n}\n\n/**\n * Custom hook to create and manage state for the models tree.\n * @beta\n */\nexport function useModelsTree({\n activeView,\n filter,\n hierarchyConfig,\n visibilityHandlerOverrides,\n getFilteredPaths,\n onModelsFiltered,\n selectionPredicate: nodeTypeSelectionPredicate,\n emptyTreeContent,\n}: UseModelsTreeProps): UseModelsTreeResult {\n const hierarchyConfiguration = useMemo<ModelsTreeHierarchyConfiguration>(\n () => ({\n ...defaultHierarchyConfiguration,\n ...hierarchyConfig,\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n Object.values(hierarchyConfig ?? {}),\n );\n\n const { getModelsTreeIdsCache, visibilityHandlerFactory, onFilteredPathsChanged } = useCachedVisibility(\n activeView,\n hierarchyConfiguration,\n visibilityHandlerOverrides,\n );\n\n const getHierarchyDefinition = useCallback<VisibilityTreeProps[\"getHierarchyDefinition\"]>(\n ({ imodelAccess }) => new ModelsTreeDefinition({ imodelAccess, idsCache: getModelsTreeIdsCache(), hierarchyConfig: hierarchyConfiguration }),\n [getModelsTreeIdsCache, hierarchyConfiguration],\n );\n\n const { getPaths, filteringError } = useFilteredPaths({\n hierarchyConfiguration,\n filter,\n getFilteredPaths,\n getModelsTreeIdsCache,\n onFilteredPathsChanged,\n onModelsFiltered,\n });\n\n const nodeSelectionPredicate = useCallback<NonNullable<VisibilityTreeProps[\"selectionPredicate\"]>>(\n (node) => {\n if (!nodeTypeSelectionPredicate) {\n return true;\n }\n return nodeTypeSelectionPredicate({ node, type: ModelsTreeNode.getType(node.nodeData) });\n },\n [nodeTypeSelectionPredicate],\n );\n\n // TODO: add double click logic\n return {\n modelsTreeProps: {\n treeName: \"models-tree-v2\",\n visibilityHandlerFactory,\n getHierarchyDefinition,\n getFilteredPaths: getPaths,\n emptyTreeContent: useMemo(() => getEmptyTreeContentComponent(filter, filteringError, emptyTreeContent), [filter, filteringError, emptyTreeContent]),\n highlight: useMemo(() => (filter ? { text: filter } : undefined), [filter]),\n selectionPredicate: nodeSelectionPredicate,\n },\n rendererProps: {\n // onDoubleClick,\n getDecorations: useCallback((node) => <ModelsTreeIcon node={node} />, []),\n },\n };\n}\n\nfunction createVisibilityHandlerFactory(\n activeView: Viewport,\n idsCacheGetter: () => ModelsTreeIdsCache,\n overrides?: ModelsTreeVisibilityHandlerOverrides,\n filteredPaths?: HierarchyFilteringPath[],\n): VisibilityTreeProps[\"visibilityHandlerFactory\"] {\n return ({ imodelAccess }) => createModelsTreeVisibilityHandler({ viewport: activeView, idsCache: idsCacheGetter(), imodelAccess, overrides, filteredPaths });\n}\n\nfunction useCachedVisibility(activeView: Viewport, hierarchyConfig: ModelsTreeHierarchyConfiguration, overrides?: ModelsTreeVisibilityHandlerOverrides) {\n const { getCache: getModelsTreeIdsCache } = useIdsCache(activeView.iModel, hierarchyConfig);\n const [filteredPaths, setFilteredPaths] = useState<HierarchyFilteringPath[]>();\n const [visibilityHandlerFactory, setVisibilityHandlerFactory] = useState<VisibilityTreeProps[\"visibilityHandlerFactory\"]>(() =>\n createVisibilityHandlerFactory(activeView, getModelsTreeIdsCache, overrides, filteredPaths),\n );\n\n useEffect(() => {\n setVisibilityHandlerFactory(() => createVisibilityHandlerFactory(activeView, getModelsTreeIdsCache, overrides, filteredPaths));\n }, [activeView, getModelsTreeIdsCache, overrides, filteredPaths]);\n\n return {\n getModelsTreeIdsCache,\n visibilityHandlerFactory,\n onFilteredPathsChanged: useCallback((paths: HierarchyFilteringPath[] | undefined) => setFilteredPaths(paths), []),\n };\n}\n\nfunction getEmptyTreeContentComponent(filter?: string, error?: ModelsTreeFilteringError, emptyTreeContent?: React.ReactNode) {\n if (isInstanceFocusError(error)) {\n return <InstanceFocusError error={error} />;\n }\n if (isFilterError(error)) {\n if (error === \"tooManyFilterMatches\") {\n return <TooManyFilterMatches base={\"modelsTree\"} />;\n }\n return <FilterUnknownError base={\"modelsTree\"} />;\n }\n if (filter) {\n return <NoFilterMatches base={\"modelsTree\"} />;\n }\n if (emptyTreeContent) {\n return emptyTreeContent;\n }\n return <EmptyTreeContent icon={modelSvg} />;\n}\n\nfunction isFilterError(error: ModelsTreeFilteringError | undefined) {\n return error === \"tooManyFilterMatches\" || error === \"unknownFilterError\";\n}\n\nfunction isInstanceFocusError(error: ModelsTreeFilteringError | undefined): error is \"tooManyInstancesFocused\" | \"unknownInstanceFocusError\" {\n return error === \"tooManyInstancesFocused\" || error === \"unknownInstanceFocusError\";\n}\n\nfunction InstanceFocusError({ error }: { error: ModelsTreeFilteringError }) {\n if (error === \"tooManyInstancesFocused\") {\n return <TooManyInstancesFocused base={\"modelsTree\"} />;\n }\n return <UnknownInstanceFocusError base={\"modelsTree\"} />;\n}\n\n/** @beta */\nexport function ModelsTreeIcon({ node }: { node: PresentationHierarchyNode }) {\n if (node.nodeData.extendedData?.imageId === undefined) {\n return undefined;\n }\n\n const getIcon = () => {\n switch (node.nodeData.extendedData!.imageId) {\n case \"icon-layers\":\n return categorySvg;\n case \"icon-item\":\n return elementSvg;\n case \"icon-ec-class\":\n return classSvg;\n case \"icon-folder\":\n return subjectSvg;\n case \"icon-model\":\n return modelSvg;\n default:\n return undefined;\n }\n };\n\n return <Icon href={getIcon()} />;\n}\n"]}
1
+ {"version":3,"file":"UseModelsTree.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/models-tree/UseModelsTree.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,WAAW,MAAM,sCAAsC,CAAC;AAC/D,OAAO,QAAQ,MAAM,gCAAgC,CAAC;AACtD,OAAO,UAAU,MAAM,kCAAkC,CAAC;AAC1D,OAAO,UAAU,MAAM,kCAAkC,CAAC;AAC1D,OAAO,QAAQ,MAAM,iCAAiC,CAAC;AACvD,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,wDAAwD,CAAC;AAC7F,OAAO,EAAE,WAAW,EAAE,MAAM,gDAAgD,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC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yBAAyB,IAAI,KAAK,KAAK,2BAA2B,CAAC;AACtF,CAAC;AAED,SAAS,kBAAkB,CAAC,EAAE,KAAK,EAAuC;IACxE,IAAI,KAAK,KAAK,yBAAyB,EAAE,CAAC;QACxC,OAAO,KAAC,uBAAuB,IAAC,IAAI,EAAE,YAAY,GAAI,CAAC;IACzD,CAAC;IACD,OAAO,KAAC,yBAAyB,IAAC,IAAI,EAAE,YAAY,GAAI,CAAC;AAC3D,CAAC;AAED,YAAY;AACZ,MAAM,UAAU,cAAc,CAAC,EAAE,IAAI,EAAuC;IAC1E,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,KAAK,SAAS,EAAE,CAAC;QACtD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,OAAO,GAAG,GAAG,EAAE;QACnB,QAAQ,IAAI,CAAC,QAAQ,CAAC,YAAa,CAAC,OAAO,EAAE,CAAC;YAC5C,KAAK,aAAa;gBAChB,OAAO,WAAW,CAAC;YACrB,KAAK,WAAW;gBACd,OAAO,UAAU,CAAC;YACpB,KAAK,eAAe;gBAClB,OAAO,QAAQ,CAAC;YAClB,KAAK,aAAa;gBAChB,OAAO,UAAU,CAAC;YACpB,KAAK,YAAY;gBACf,OAAO,QAAQ,CAAC;YAClB;gBACE,OAAO,SAAS,CAAC;QACrB,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,KAAC,IAAI,IAAC,IAAI,EAAE,OAAO,EAAE,GAAI,CAAC;AACnC,CAAC;AAED,SAAS,WAAW,CAAC,KAA8E;IACjG,OAAO,IAAI,kBAAkB,CAAC,wBAAwB,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;AAC7G,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 } from \"react\";\nimport { createECSqlQueryExecutor } from \"@itwin/presentation-core-interop\";\nimport { Icon } from \"@stratakit/foundations\";\nimport categorySvg from \"@stratakit/icons/bis-category-3d.svg\";\nimport classSvg from \"@stratakit/icons/bis-class.svg\";\nimport elementSvg from \"@stratakit/icons/bis-element.svg\";\nimport subjectSvg from \"@stratakit/icons/bis-subject.svg\";\nimport modelSvg from \"@stratakit/icons/model-cube.svg\";\nimport {\n EmptyTreeContent,\n FilterUnknownError,\n NoFilterMatches,\n TooManyFilterMatches,\n TooManyInstancesFocused,\n UnknownInstanceFocusError,\n} from \"../common/components/EmptyTree.js\";\nimport { useCachedVisibility } from \"../common/internal/useTreeHooks/UseCachedVisibility.js\";\nimport { useIdsCache } from \"../common/internal/useTreeHooks/UseIdsCache.js\";\nimport { ModelsTreeIdsCache } from \"./internal/ModelsTreeIdsCache.js\";\nimport { ModelsTreeNode } from \"./internal/ModelsTreeNode.js\";\nimport { createModelsTreeVisibilityHandler } from \"./internal/ModelsTreeVisibilityHandler.js\";\nimport { useFilteredPaths } from \"./internal/UseFilteredPaths.js\";\nimport { defaultHierarchyConfiguration, ModelsTreeDefinition } from \"./ModelsTreeDefinition.js\";\n\nimport type { CreateCacheProps } from \"../common/internal/useTreeHooks/UseIdsCache.js\";\nimport type { CreateFactoryProps } from \"../common/internal/useTreeHooks/UseCachedVisibility.js\";\nimport type { ReactNode } from \"react\";\nimport type { HierarchyFilteringPath } from \"@itwin/presentation-hierarchies\";\nimport type { Id64String } from \"@itwin/core-bentley\";\nimport type { InstanceKey } from \"@itwin/presentation-shared\";\nimport type { Viewport } from \"@itwin/core-frontend\";\nimport type { PresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport type { ElementsGroupInfo, ModelsTreeHierarchyConfiguration } from \"./ModelsTreeDefinition.js\";\nimport type { ModelsTreeVisibilityHandlerOverrides } from \"./internal/ModelsTreeVisibilityHandler.js\";\nimport type { VisibilityTreeProps } from \"../common/components/VisibilityTree.js\";\nimport type { VisibilityTreeRendererProps } from \"../common/components/VisibilityTreeRenderer.js\";\nimport type { ModelsTreeFilteringError } from \"./internal/UseFilteredPaths.js\";\n\n/** @beta */\nexport interface UseModelsTreeProps {\n /**\n * Optional search string used to filter tree nodes by label, as well as highlight matching substrings in the tree.\n * Nodes that do not contain this string in their label will be filtered out.\n *\n * If `getFilteredPaths` function is provided, it will take precedence and automatic filtering by this string will not be applied.\n * Instead, the string will be supplied to the given `getFilteredPaths` function for consumers to apply the filtering.\n */\n filter?: string;\n activeView: Viewport;\n hierarchyConfig?: Partial<ModelsTreeHierarchyConfiguration>;\n visibilityHandlerOverrides?: ModelsTreeVisibilityHandlerOverrides;\n /**\n * Optional function for applying custom filtering on the hierarchy. Use it when you want full control over which nodes should be displayed, based on more complex logic or known instance keys.\n *\n * When defined, this function takes precedence over filtering by `filter` string. If both are supplied, the `filter` is provided as an argument to `getFilteredPaths`.\n *\n * @param props Parameters provided when `getFilteredPaths` is called:\n * - `createInstanceKeyPaths`: Helper function to create filter paths.\n * - `filter`: The filter string which would otherwise be used for default filtering.\n *\n * **Example use cases:**\n * - You have a list of `InstanceKey` items, which you want to use for filtering the hierarchy.\n * - You want to create filter paths based on node label, but also apply some extra conditions (for example exclude paths with sub-models).\n * - You want to construct custom filtered paths. For example: create a filter path for each geometric element which has a parent element.\n *\n * @note Paths returned by `createInstanceKeyPaths` will not have `autoExpand` flag set. If you want nodes to be expanded, iterate over the paths and\n * set `autoExpand: true` manually.\n */\n getFilteredPaths?: (props: {\n /** A function that creates filtering paths based on provided target instance keys or node label. */\n createInstanceKeyPaths: (props: { targetItems: Array<InstanceKey | ElementsGroupInfo> } | { label: string }) => Promise<HierarchyFilteringPath[]>;\n /** Filter which would be used to create filter paths if `getFilteredPaths` wouldn't be provided. */\n filter?: string;\n }) => Promise<HierarchyFilteringPath[]>;\n onModelsFiltered?: (modelIds: Id64String[] | undefined) => void;\n /**\n * An optional predicate to allow or prohibit selection of a node.\n * When not supplied, all nodes are selectable.\n */\n selectionPredicate?: (props: { node: PresentationHierarchyNode; type: \"subject\" | \"model\" | \"category\" | \"element\" | \"elements-class-group\" }) => boolean;\n emptyTreeContent?: ReactNode;\n}\n\n/** @beta */\ninterface UseModelsTreeResult {\n modelsTreeProps: Pick<\n VisibilityTreeProps,\n \"treeName\" | \"getHierarchyDefinition\" | \"getFilteredPaths\" | \"visibilityHandlerFactory\" | \"highlight\" | \"emptyTreeContent\" | \"selectionPredicate\"\n >;\n rendererProps: Required<Pick<VisibilityTreeRendererProps, \"getDecorations\">>;\n}\n\n/**\n * Custom hook to create and manage state for the models tree.\n * @beta\n */\nexport function useModelsTree({\n activeView,\n filter,\n hierarchyConfig,\n visibilityHandlerOverrides,\n getFilteredPaths,\n onModelsFiltered,\n selectionPredicate: nodeTypeSelectionPredicate,\n emptyTreeContent,\n}: UseModelsTreeProps): UseModelsTreeResult {\n const hierarchyConfiguration = useMemo<ModelsTreeHierarchyConfiguration>(\n () => ({\n ...defaultHierarchyConfiguration,\n ...hierarchyConfig,\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n Object.values(hierarchyConfig ?? {}),\n );\n const { getCache: getModelsTreeIdsCache } = useIdsCache<ModelsTreeIdsCache, { hierarchyConfig: ModelsTreeHierarchyConfiguration }>({\n imodel: activeView.iModel,\n createCache,\n cacheSpecificProps: useMemo(() => ({ hierarchyConfig: hierarchyConfiguration }), [hierarchyConfiguration]),\n });\n\n const { visibilityHandlerFactory, onFilteredPathsChanged } = useCachedVisibility<ModelsTreeIdsCache, { overrides?: ModelsTreeVisibilityHandlerOverrides }>({\n activeView,\n createFactory: createVisibilityHandlerFactory,\n factoryProps: useMemo(() => ({ overrides: visibilityHandlerOverrides }), [visibilityHandlerOverrides]),\n getCache: getModelsTreeIdsCache,\n });\n\n const getHierarchyDefinition = useCallback<VisibilityTreeProps[\"getHierarchyDefinition\"]>(\n ({ imodelAccess }) => new ModelsTreeDefinition({ imodelAccess, idsCache: getModelsTreeIdsCache(), hierarchyConfig: hierarchyConfiguration }),\n [getModelsTreeIdsCache, hierarchyConfiguration],\n );\n\n const { getPaths, filteringError } = useFilteredPaths({\n hierarchyConfiguration,\n filter,\n getFilteredPaths,\n getModelsTreeIdsCache,\n onFilteredPathsChanged,\n onModelsFiltered,\n });\n\n const nodeSelectionPredicate = useCallback<NonNullable<VisibilityTreeProps[\"selectionPredicate\"]>>(\n (node) => {\n if (!nodeTypeSelectionPredicate) {\n return true;\n }\n return nodeTypeSelectionPredicate({ node, type: ModelsTreeNode.getType(node.nodeData) });\n },\n [nodeTypeSelectionPredicate],\n );\n\n // TODO: add double click logic\n return {\n modelsTreeProps: {\n treeName: \"models-tree-v2\",\n visibilityHandlerFactory,\n getHierarchyDefinition,\n getFilteredPaths: getPaths,\n emptyTreeContent: useMemo(() => getEmptyTreeContentComponent(filter, filteringError, emptyTreeContent), [filter, filteringError, emptyTreeContent]),\n highlight: useMemo(() => (filter ? { text: filter } : undefined), [filter]),\n selectionPredicate: nodeSelectionPredicate,\n },\n rendererProps: {\n // onDoubleClick,\n getDecorations: useCallback((node) => <ModelsTreeIcon node={node} />, []),\n },\n };\n}\n\nfunction createVisibilityHandlerFactory(\n props: CreateFactoryProps<ModelsTreeIdsCache, { overrides?: ModelsTreeVisibilityHandlerOverrides }>,\n): VisibilityTreeProps[\"visibilityHandlerFactory\"] {\n const { activeView, idsCacheGetter, filteredPaths, factoryProps } = props;\n return ({ imodelAccess }) =>\n createModelsTreeVisibilityHandler({\n viewport: activeView,\n idsCache: idsCacheGetter(),\n imodelAccess,\n overrides: factoryProps.overrides,\n filteredPaths,\n });\n}\n\nfunction getEmptyTreeContentComponent(filter?: string, error?: ModelsTreeFilteringError, emptyTreeContent?: React.ReactNode) {\n if (isInstanceFocusError(error)) {\n return <InstanceFocusError error={error} />;\n }\n if (isFilterError(error)) {\n if (error === \"tooManyFilterMatches\") {\n return <TooManyFilterMatches base={\"modelsTree\"} />;\n }\n return <FilterUnknownError base={\"modelsTree\"} />;\n }\n if (filter) {\n return <NoFilterMatches base={\"modelsTree\"} />;\n }\n if (emptyTreeContent) {\n return emptyTreeContent;\n }\n return <EmptyTreeContent icon={modelSvg} />;\n}\n\nfunction isFilterError(error: ModelsTreeFilteringError | undefined) {\n return error === \"tooManyFilterMatches\" || error === \"unknownFilterError\";\n}\n\nfunction isInstanceFocusError(error: ModelsTreeFilteringError | undefined): error is \"tooManyInstancesFocused\" | \"unknownInstanceFocusError\" {\n return error === \"tooManyInstancesFocused\" || error === \"unknownInstanceFocusError\";\n}\n\nfunction InstanceFocusError({ error }: { error: ModelsTreeFilteringError }) {\n if (error === \"tooManyInstancesFocused\") {\n return <TooManyInstancesFocused base={\"modelsTree\"} />;\n }\n return <UnknownInstanceFocusError base={\"modelsTree\"} />;\n}\n\n/** @beta */\nexport function ModelsTreeIcon({ node }: { node: PresentationHierarchyNode }) {\n if (node.nodeData.extendedData?.imageId === undefined) {\n return undefined;\n }\n\n const getIcon = () => {\n switch (node.nodeData.extendedData!.imageId) {\n case \"icon-layers\":\n return categorySvg;\n case \"icon-item\":\n return elementSvg;\n case \"icon-ec-class\":\n return classSvg;\n case \"icon-folder\":\n return subjectSvg;\n case \"icon-model\":\n return modelSvg;\n default:\n return undefined;\n }\n };\n\n return <Icon href={getIcon()} />;\n}\n\nfunction createCache(props: CreateCacheProps<{ hierarchyConfig: ModelsTreeHierarchyConfiguration }>) {\n return new ModelsTreeIdsCache(createECSqlQueryExecutor(props.imodel), props.specificProps.hierarchyConfig);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/tree-widget-react",
3
- "version": "4.0.0-alpha.12",
3
+ "version": "4.0.0-alpha.13",
4
4
  "description": "Tree Widget React",
5
5
  "keywords": [
6
6
  "Bentley",
@@ -1,8 +0,0 @@
1
- import { CategoriesTreeIdsCache } from "./CategoriesTreeIdsCache.js";
2
- import type { IModelConnection } from "@itwin/core-frontend";
3
- import type { HierarchyFilteringPath } from "@itwin/presentation-hierarchies";
4
- /** @internal */
5
- export declare function useIdsCache(imodel: IModelConnection, viewType: "2d" | "3d", filteredPaths?: HierarchyFilteringPath[]): {
6
- getCache: () => CategoriesTreeIdsCache;
7
- };
8
- //# sourceMappingURL=UseIdsCache.d.ts.map
@@ -1,48 +0,0 @@
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 { useCallback, useEffect, useRef, useState } from "react";
6
- import { createECSqlQueryExecutor } from "@itwin/presentation-core-interop";
7
- import { useIModelChangeListener } from "../../common/internal/UseIModelChangeListener.js";
8
- import { CategoriesTreeIdsCache } from "./CategoriesTreeIdsCache.js";
9
- /** @internal */
10
- export function useIdsCache(imodel, viewType, filteredPaths) {
11
- const cacheRef = useRef(undefined);
12
- const clearCacheRef = useRef(() => () => {
13
- cacheRef.current?.[Symbol.dispose]?.();
14
- cacheRef.current = undefined;
15
- });
16
- const createCacheGetterRef = useRef((currImodel, currViewType) => () => {
17
- if (cacheRef.current === undefined) {
18
- cacheRef.current = new CategoriesTreeIdsCache(createECSqlQueryExecutor(currImodel), currViewType);
19
- }
20
- return cacheRef.current;
21
- });
22
- const [getCache, setCacheGetter] = useState(() => createCacheGetterRef.current(imodel, viewType));
23
- useEffect(() => {
24
- // clear cache in case it was created before `useEffect` was run first time
25
- clearCacheRef.current();
26
- // make sure all cache users rerender
27
- setCacheGetter(() => createCacheGetterRef.current(imodel, viewType));
28
- return () => {
29
- // eslint-disable-next-line react-hooks/exhaustive-deps
30
- clearCacheRef.current();
31
- };
32
- }, [imodel, viewType]);
33
- useEffect(() => {
34
- cacheRef.current?.clearFilteredElementsModels();
35
- }, [filteredPaths]);
36
- useIModelChangeListener({
37
- imodel,
38
- action: useCallback(() => {
39
- clearCacheRef.current();
40
- // make sure all cache users rerender
41
- setCacheGetter(() => createCacheGetterRef.current(imodel, viewType));
42
- }, [imodel, viewType]),
43
- });
44
- return {
45
- getCache,
46
- };
47
- }
48
- //# sourceMappingURL=UseIdsCache.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"UseIdsCache.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/categories-tree/internal/UseIdsCache.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,uBAAuB,EAAE,MAAM,kDAAkD,CAAC;AAC3F,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAKrE,gBAAgB;AAChB,MAAM,UAAU,WAAW,CAAC,MAAwB,EAAE,QAAqB,EAAE,aAAwC;IACnH,MAAM,QAAQ,GAAG,MAAM,CAAqC,SAAS,CAAC,CAAC;IACvE,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE;QACtC,QAAQ,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC;QACvC,QAAQ,CAAC,OAAO,GAAG,SAAS,CAAC;IAC/B,CAAC,CAAC,CAAC;IACH,MAAM,oBAAoB,GAAG,MAAM,CAAC,CAAC,UAA4B,EAAE,YAAyB,EAAE,EAAE,CAAC,GAAG,EAAE;QACpG,IAAI,QAAQ,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;YACnC,QAAQ,CAAC,OAAO,GAAG,IAAI,sBAAsB,CAAC,wBAAwB,CAAC,UAAU,CAAC,EAAE,YAAY,CAAC,CAAC;QACpG,CAAC;QACD,OAAO,QAAQ,CAAC,OAAO,CAAC;IAC1B,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,QAAQ,EAAE,cAAc,CAAC,GAAG,QAAQ,CAA+B,GAAG,EAAE,CAAC,oBAAoB,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IAEhI,SAAS,CAAC,GAAG,EAAE;QACb,2EAA2E;QAC3E,aAAa,CAAC,OAAO,EAAE,CAAC;QAExB,qCAAqC;QACrC,cAAc,CAAC,GAAG,EAAE,CAAC,oBAAoB,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;QACrE,OAAO,GAAG,EAAE;YACV,uDAAuD;YACvD,aAAa,CAAC,OAAO,EAAE,CAAC;QAC1B,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IAEvB,SAAS,CAAC,GAAG,EAAE;QACb,QAAQ,CAAC,OAAO,EAAE,2BAA2B,EAAE,CAAC;IAClD,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;IAEpB,uBAAuB,CAAC;QACtB,MAAM;QACN,MAAM,EAAE,WAAW,CAAC,GAAG,EAAE;YACvB,aAAa,CAAC,OAAO,EAAE,CAAC;YACxB,qCAAqC;YACrC,cAAc,CAAC,GAAG,EAAE,CAAC,oBAAoB,CAAC,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;QACvE,CAAC,EAAE,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;KACvB,CAAC,CAAC;IAEH,OAAO;QACL,QAAQ;KACT,CAAC;AACJ,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, useEffect, useRef, useState } from \"react\";\nimport { createECSqlQueryExecutor } from \"@itwin/presentation-core-interop\";\nimport { useIModelChangeListener } from \"../../common/internal/UseIModelChangeListener.js\";\nimport { CategoriesTreeIdsCache } from \"./CategoriesTreeIdsCache.js\";\n\nimport type { IModelConnection } from \"@itwin/core-frontend\";\nimport type { HierarchyFilteringPath } from \"@itwin/presentation-hierarchies\";\n\n/** @internal */\nexport function useIdsCache(imodel: IModelConnection, viewType: \"2d\" | \"3d\", filteredPaths?: HierarchyFilteringPath[]) {\n const cacheRef = useRef<CategoriesTreeIdsCache | undefined>(undefined);\n const clearCacheRef = useRef(() => () => {\n cacheRef.current?.[Symbol.dispose]?.();\n cacheRef.current = undefined;\n });\n const createCacheGetterRef = useRef((currImodel: IModelConnection, currViewType: \"2d\" | \"3d\") => () => {\n if (cacheRef.current === undefined) {\n cacheRef.current = new CategoriesTreeIdsCache(createECSqlQueryExecutor(currImodel), currViewType);\n }\n return cacheRef.current;\n });\n const [getCache, setCacheGetter] = useState<() => CategoriesTreeIdsCache>(() => createCacheGetterRef.current(imodel, viewType));\n\n useEffect(() => {\n // clear cache in case it was created before `useEffect` was run first time\n clearCacheRef.current();\n\n // make sure all cache users rerender\n setCacheGetter(() => createCacheGetterRef.current(imodel, viewType));\n return () => {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n clearCacheRef.current();\n };\n }, [imodel, viewType]);\n\n useEffect(() => {\n cacheRef.current?.clearFilteredElementsModels();\n }, [filteredPaths]);\n\n useIModelChangeListener({\n imodel,\n action: useCallback(() => {\n clearCacheRef.current();\n // make sure all cache users rerender\n setCacheGetter(() => createCacheGetterRef.current(imodel, viewType));\n }, [imodel, viewType]),\n });\n\n return {\n getCache,\n };\n}\n"]}
@@ -1,8 +0,0 @@
1
- import { ClassificationsTreeIdsCache } from "./ClassificationsTreeIdsCache.js";
2
- import type { IModelConnection } from "@itwin/core-frontend";
3
- import type { ClassificationsTreeHierarchyConfiguration } from "../ClassificationsTreeDefinition.js";
4
- /** @internal */
5
- export declare function useIdsCache(imodel: IModelConnection, hierarchyConfig: ClassificationsTreeHierarchyConfiguration): {
6
- getCache: () => ClassificationsTreeIdsCache;
7
- };
8
- //# sourceMappingURL=UseIdsCache.d.ts.map
@@ -1,45 +0,0 @@
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 { useCallback, useEffect, useRef, useState } from "react";
6
- import { createECSqlQueryExecutor } from "@itwin/presentation-core-interop";
7
- import { useIModelChangeListener } from "../../common/internal/UseIModelChangeListener.js";
8
- import { ClassificationsTreeIdsCache } from "./ClassificationsTreeIdsCache.js";
9
- /** @internal */
10
- export function useIdsCache(imodel, hierarchyConfig) {
11
- const cacheRef = useRef(undefined);
12
- const clearCacheRef = useRef(() => () => {
13
- cacheRef.current?.[Symbol.dispose]?.();
14
- cacheRef.current = undefined;
15
- });
16
- const createCacheGetterRef = useRef((currIModel, currHierarchyConfig) => () => {
17
- if (cacheRef.current === undefined) {
18
- cacheRef.current = new ClassificationsTreeIdsCache(createECSqlQueryExecutor(currIModel), currHierarchyConfig);
19
- }
20
- return cacheRef.current;
21
- });
22
- const [getCache, setCacheGetter] = useState(() => createCacheGetterRef.current(imodel, hierarchyConfig));
23
- useEffect(() => {
24
- // clear cache in case it was created before `useEffect` was run first time
25
- clearCacheRef.current();
26
- // make sure all cache users rerender
27
- setCacheGetter(() => createCacheGetterRef.current(imodel, hierarchyConfig));
28
- return () => {
29
- // eslint-disable-next-line react-hooks/exhaustive-deps
30
- clearCacheRef.current();
31
- };
32
- }, [imodel, hierarchyConfig]);
33
- useIModelChangeListener({
34
- imodel,
35
- action: useCallback(() => {
36
- clearCacheRef.current();
37
- // make sure all cache users rerender
38
- setCacheGetter(() => createCacheGetterRef.current(imodel, hierarchyConfig));
39
- }, [imodel, hierarchyConfig]),
40
- });
41
- return {
42
- getCache,
43
- };
44
- }
45
- //# sourceMappingURL=UseIdsCache.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"UseIdsCache.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/classifications-tree/internal/UseIdsCache.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE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AC;QAC5E,OAAO,GAAG,EAAE;YACV,uDAAuD;YACvD,aAAa,CAAC,OAAO,EAAE,CAAC;QAC1B,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;IAE9B,uBAAuB,CAAC;QACtB,MAAM;QACN,MAAM,EAAE,WAAW,CAAC,GAAG,EAAE;YACvB,aAAa,CAAC,OAAO,EAAE,CAAC;YACxB,qCAAqC;YACrC,cAAc,CAAC,GAAG,EAAE,CAAC,oBAAoB,CAAC,OAAO,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;QAC9E,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;KAC9B,CAAC,CAAC;IAEH,OAAO;QACL,QAAQ;KACT,CAAC;AACJ,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, useEffect, useRef, useState } from \"react\";\nimport { createECSqlQueryExecutor } from \"@itwin/presentation-core-interop\";\nimport { useIModelChangeListener } from \"../../common/internal/UseIModelChangeListener.js\";\nimport { ClassificationsTreeIdsCache } from \"./ClassificationsTreeIdsCache.js\";\n\nimport type { IModelConnection } from \"@itwin/core-frontend\";\nimport type { ClassificationsTreeHierarchyConfiguration } from \"../ClassificationsTreeDefinition.js\";\n\n/** @internal */\nexport function useIdsCache(imodel: IModelConnection, hierarchyConfig: ClassificationsTreeHierarchyConfiguration) {\n const cacheRef = useRef<ClassificationsTreeIdsCache | undefined>(undefined);\n const clearCacheRef = useRef(() => () => {\n cacheRef.current?.[Symbol.dispose]?.();\n cacheRef.current = undefined;\n });\n const createCacheGetterRef = useRef((currIModel: IModelConnection, currHierarchyConfig: ClassificationsTreeHierarchyConfiguration) => () => {\n if (cacheRef.current === undefined) {\n cacheRef.current = new ClassificationsTreeIdsCache(createECSqlQueryExecutor(currIModel), currHierarchyConfig);\n }\n return cacheRef.current;\n });\n const [getCache, setCacheGetter] = useState<() => ClassificationsTreeIdsCache>(() => createCacheGetterRef.current(imodel, hierarchyConfig));\n\n useEffect(() => {\n // clear cache in case it was created before `useEffect` was run first time\n clearCacheRef.current();\n\n // make sure all cache users rerender\n setCacheGetter(() => createCacheGetterRef.current(imodel, hierarchyConfig));\n return () => {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n clearCacheRef.current();\n };\n }, [imodel, hierarchyConfig]);\n\n useIModelChangeListener({\n imodel,\n action: useCallback(() => {\n clearCacheRef.current();\n // make sure all cache users rerender\n setCacheGetter(() => createCacheGetterRef.current(imodel, hierarchyConfig));\n }, [imodel, hierarchyConfig]),\n });\n\n return {\n getCache,\n };\n}\n"]}
@@ -1,8 +0,0 @@
1
- import { ModelsTreeIdsCache } from "./ModelsTreeIdsCache.js";
2
- import type { IModelConnection } from "@itwin/core-frontend";
3
- import type { ModelsTreeHierarchyConfiguration } from "../ModelsTreeDefinition.js";
4
- /** @internal */
5
- export declare function useIdsCache(imodel: IModelConnection, hierarchyConfig: ModelsTreeHierarchyConfiguration): {
6
- getCache: () => ModelsTreeIdsCache;
7
- };
8
- //# sourceMappingURL=UseIdsCache.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"UseIdsCache.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/models-tree/internal/UseIdsCache.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,uBAAuB,EAAE,MAAM,kDAAkD,CAAC;AAC3F,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAK7D,gBAAgB;AAChB,MAAM,UAAU,WAAW,CAAC,MAAwB,EAAE,eAA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,cAAc,CAAC,GAAG,EAAE,CAAC,oBAAoB,CAAC,OAAO,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;QAC9E,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;KAC9B,CAAC,CAAC;IAEH,OAAO;QACL,QAAQ;KACT,CAAC;AACJ,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, useEffect, useRef, useState } from \"react\";\nimport { createECSqlQueryExecutor } from \"@itwin/presentation-core-interop\";\nimport { useIModelChangeListener } from \"../../common/internal/UseIModelChangeListener.js\";\nimport { ModelsTreeIdsCache } from \"./ModelsTreeIdsCache.js\";\n\nimport type { IModelConnection } from \"@itwin/core-frontend\";\nimport type { ModelsTreeHierarchyConfiguration } from \"../ModelsTreeDefinition.js\";\n\n/** @internal */\nexport function useIdsCache(imodel: IModelConnection, hierarchyConfig: ModelsTreeHierarchyConfiguration) {\n const cacheRef = useRef<ModelsTreeIdsCache | undefined>(undefined);\n const clearCacheRef = useRef(() => {\n cacheRef.current?.[Symbol.dispose]?.();\n cacheRef.current = undefined;\n });\n const createCacheGetterRef = useRef((currImodel: IModelConnection, currHierarchyConfig: ModelsTreeHierarchyConfiguration) => {\n return () => {\n if (cacheRef.current === undefined) {\n cacheRef.current = new ModelsTreeIdsCache(createECSqlQueryExecutor(currImodel), currHierarchyConfig);\n }\n return cacheRef.current;\n };\n });\n const [getCache, setCacheGetter] = useState<() => ModelsTreeIdsCache>(() => createCacheGetterRef.current(imodel, hierarchyConfig));\n\n useEffect(() => {\n // clear cache in case it was created before `useEffect` was run first time\n clearCacheRef.current();\n\n // make sure all cache users rerender\n setCacheGetter(() => createCacheGetterRef.current(imodel, hierarchyConfig));\n return () => {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n clearCacheRef.current();\n };\n }, [imodel, hierarchyConfig]);\n\n useIModelChangeListener({\n imodel,\n action: useCallback(() => {\n clearCacheRef.current();\n // make sure all cache users rerender\n setCacheGetter(() => createCacheGetterRef.current(imodel, hierarchyConfig));\n }, [imodel, hierarchyConfig]),\n });\n\n return {\n getCache,\n };\n}\n"]}