@itwin/tree-widget-react 4.0.0-alpha.7 → 4.0.0-alpha.8

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 (98) hide show
  1. package/lib/esm/tree-widget-react/TreeWidget.d.ts +6 -1
  2. package/lib/esm/tree-widget-react/TreeWidget.js +19 -2
  3. package/lib/esm/tree-widget-react/TreeWidget.js.map +1 -1
  4. package/lib/esm/tree-widget-react/components/TreeWidgetComponentImpl.d.ts +6 -0
  5. package/lib/esm/tree-widget-react/components/TreeWidgetComponentImpl.js +22 -23
  6. package/lib/esm/tree-widget-react/components/TreeWidgetComponentImpl.js.map +1 -1
  7. package/lib/esm/tree-widget-react/components/TreeWidgetUiItemsProvider.js +1 -1
  8. package/lib/esm/tree-widget-react/components/TreeWidgetUiItemsProvider.js.map +1 -1
  9. package/lib/esm/tree-widget-react/components/tree-header/ErrorState.js +1 -1
  10. package/lib/esm/tree-widget-react/components/tree-header/ErrorState.js.map +1 -1
  11. package/lib/esm/tree-widget-react/components/tree-header/SearchBox.d.ts +0 -1
  12. package/lib/esm/tree-widget-react/components/tree-header/SearchBox.js +3 -4
  13. package/lib/esm/tree-widget-react/components/tree-header/SearchBox.js.map +1 -1
  14. package/lib/esm/tree-widget-react/components/tree-header/WidgetHeader.css +1 -0
  15. package/lib/esm/tree-widget-react/components/tree-header/WidgetHeader.d.ts +12 -4
  16. package/lib/esm/tree-widget-react/components/tree-header/WidgetHeader.js +13 -9
  17. package/lib/esm/tree-widget-react/components/tree-header/WidgetHeader.js.map +1 -1
  18. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTree.d.ts +2 -2
  19. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTree.js +2 -2
  20. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTree.js.map +1 -1
  21. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js +3 -3
  22. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js.map +1 -1
  23. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeComponent.d.ts +1 -1
  24. package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeComponent.js.map +1 -1
  25. package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js +36 -182
  26. package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js.map +1 -1
  27. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js +7 -11
  28. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js.map +1 -1
  29. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeVisibilityHandler.js +107 -191
  30. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeVisibilityHandler.js.map +1 -1
  31. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/UseFilteredPaths.d.ts +25 -0
  32. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/UseFilteredPaths.js +133 -0
  33. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/UseFilteredPaths.js.map +1 -0
  34. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/UseIdsCache.d.ts +8 -0
  35. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/UseIdsCache.js +48 -0
  36. package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/UseIdsCache.js.map +1 -0
  37. package/lib/esm/tree-widget-react/components/trees/common/UseHierarchyVisibility.d.ts +0 -2
  38. package/lib/esm/tree-widget-react/components/trees/common/UseHierarchyVisibility.js +8 -4
  39. package/lib/esm/tree-widget-react/components/trees/common/UseHierarchyVisibility.js.map +1 -1
  40. package/lib/esm/tree-widget-react/components/trees/common/UseNodeHighlighting.js +11 -10
  41. package/lib/esm/tree-widget-react/components/trees/common/UseNodeHighlighting.js.map +1 -1
  42. package/lib/esm/tree-widget-react/components/trees/common/Utils.d.ts +5 -0
  43. package/lib/esm/tree-widget-react/components/trees/common/Utils.js +5 -0
  44. package/lib/esm/tree-widget-react/components/trees/common/Utils.js.map +1 -1
  45. package/lib/esm/tree-widget-react/components/trees/common/components/BaseTreeRenderer.d.ts +1 -1
  46. package/lib/esm/tree-widget-react/components/trees/common/components/BaseTreeRenderer.js +2 -2
  47. package/lib/esm/tree-widget-react/components/trees/common/components/BaseTreeRenderer.js.map +1 -1
  48. package/lib/esm/tree-widget-react/components/trees/common/components/Tree.d.ts +3 -3
  49. package/lib/esm/tree-widget-react/components/trees/common/components/Tree.js +11 -2
  50. package/lib/esm/tree-widget-react/components/trees/common/components/Tree.js.map +1 -1
  51. package/lib/esm/tree-widget-react/components/trees/common/components/TreeNodeVisibilityButton.d.ts +6 -4
  52. package/lib/esm/tree-widget-react/components/trees/common/components/TreeNodeVisibilityButton.js +20 -25
  53. package/lib/esm/tree-widget-react/components/trees/common/components/TreeNodeVisibilityButton.js.map +1 -1
  54. package/lib/esm/tree-widget-react/components/trees/common/components/TreeRenderer.d.ts +1 -1
  55. package/lib/esm/tree-widget-react/components/trees/common/components/TreeRenderer.js +10 -4
  56. package/lib/esm/tree-widget-react/components/trees/common/components/TreeRenderer.js.map +1 -1
  57. package/lib/esm/tree-widget-react/components/trees/common/components/UseVisibilityButtonHandler.js +6 -3
  58. package/lib/esm/tree-widget-react/components/trees/common/components/UseVisibilityButtonHandler.js.map +1 -1
  59. package/lib/esm/tree-widget-react/components/trees/common/components/VisibilityTreeRenderer.d.ts +1 -1
  60. package/lib/esm/tree-widget-react/components/trees/common/components/VisibilityTreeRenderer.js +12 -11
  61. package/lib/esm/tree-widget-react/components/trees/common/components/VisibilityTreeRenderer.js.map +1 -1
  62. package/lib/esm/tree-widget-react/components/trees/common/internal/Tooltip.d.ts +3 -11
  63. package/lib/esm/tree-widget-react/components/trees/common/internal/Tooltip.js +3 -15
  64. package/lib/esm/tree-widget-react/components/trees/common/internal/Tooltip.js.map +1 -1
  65. package/lib/esm/tree-widget-react/components/trees/common/internal/VisibilityUtils.d.ts +4 -23
  66. package/lib/esm/tree-widget-react/components/trees/common/internal/VisibilityUtils.js +33 -57
  67. package/lib/esm/tree-widget-react/components/trees/common/internal/VisibilityUtils.js.map +1 -1
  68. package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTree.d.ts +2 -2
  69. package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTree.js +8 -8
  70. package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTree.js.map +1 -1
  71. package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeComponent.d.ts +1 -1
  72. package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js.map +1 -1
  73. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.d.ts +2 -2
  74. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js +11 -11
  75. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -1
  76. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeComponent.d.ts +1 -1
  77. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeComponent.js +1 -1
  78. package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeComponent.js.map +1 -1
  79. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTree.d.ts +2 -2
  80. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTree.js +2 -2
  81. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTree.js.map +1 -1
  82. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js +6 -6
  83. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js.map +1 -1
  84. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.d.ts +1 -1
  85. package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
  86. package/lib/esm/tree-widget-react/components/trees/models-tree/UseModelsTree.js +36 -220
  87. package/lib/esm/tree-widget-react/components/trees/models-tree/UseModelsTree.js.map +1 -1
  88. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js +24 -87
  89. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
  90. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/UseFilteredPaths.d.ts +27 -0
  91. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/UseFilteredPaths.js +170 -0
  92. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/UseFilteredPaths.js.map +1 -0
  93. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/UseIdsCache.d.ts +8 -0
  94. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/UseIdsCache.js +47 -0
  95. package/lib/esm/tree-widget-react/components/trees/models-tree/internal/UseIdsCache.js.map +1 -0
  96. package/lib/public/locales/en/TreeWidget.json +4 -95
  97. package/package.json +6 -6
  98. package/lib/esm/tree-widget-react/components/tree-header/SearchBox.css +0 -8
@@ -0,0 +1,48 @@
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
@@ -0,0 +1 @@
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,G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AAE,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"]}
@@ -11,8 +11,6 @@ export interface VisibilityStatus {
11
11
  state: "visible" | "partial" | "hidden";
12
12
  /** Specifies whether visibility changing is disabled or not. */
13
13
  isDisabled?: boolean;
14
- /** Tooltip that should be displayed when hovering over the visibility checkbox. */
15
- tooltip?: string;
16
14
  }
17
15
  /**
18
16
  * Handler that can be used to determine and change visibility of instances represented by tree nodes.
@@ -4,6 +4,7 @@
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
  import { useEffect, useRef, useState } from "react";
6
6
  import { asyncScheduler, defer, distinct, EMPTY, from, lastValueFrom, mergeMap, observeOn, onErrorResumeNextWith, Subject, takeUntil, tap, throttleTime, } from "rxjs";
7
+ import { createTooltip } from "./internal/Tooltip.js";
7
8
  import { useTelemetryContext } from "./UseTelemetryContext.js";
8
9
  /** @internal */
9
10
  export function useHierarchyVisibility({ visibilityHandlerFactory, }) {
@@ -31,7 +32,7 @@ export function useHierarchyVisibility({ visibilityHandlerFactory, }) {
31
32
  const triggerCheckboxUpdate = () => {
32
33
  setState((prev) => ({
33
34
  ...prev,
34
- getCheckboxState: createStateGetter(visibilityStatusMap, calculateNodeStatus),
35
+ getVisibilityButtonState: createStateGetter(visibilityStatusMap, calculateNodeStatus),
35
36
  }));
36
37
  };
37
38
  const subscription = calculate
@@ -39,7 +40,10 @@ export function useHierarchyVisibility({ visibilityHandlerFactory, }) {
39
40
  next: (status) => {
40
41
  visibilityStatusMap.current.set(node.id, {
41
42
  node,
42
- status,
43
+ status: {
44
+ ...status,
45
+ tooltip: createTooltip(status.state),
46
+ },
43
47
  needsRefresh: false,
44
48
  });
45
49
  },
@@ -59,7 +63,7 @@ export function useHierarchyVisibility({ visibilityHandlerFactory, }) {
59
63
  return;
60
64
  }
61
65
  entry.status.state = visibilityState;
62
- entry.status.tooltip = undefined;
66
+ entry.status.tooltip = createTooltip("determining");
63
67
  triggerCheckboxUpdate();
64
68
  };
65
69
  setState({
@@ -87,7 +91,7 @@ function createStateGetter(map, calculateVisibility) {
87
91
  const entry = map.current.get(node.id);
88
92
  if (entry === undefined) {
89
93
  calculateVisibility(node);
90
- return { state: "visible", isDisabled: true };
94
+ return { state: "visible", isDisabled: true, tooltip: createTooltip("determining") };
91
95
  }
92
96
  if (entry.needsRefresh) {
93
97
  calculateVisibility(node);
@@ -1 +1 @@
1
- {"version":3,"file":"UseHierarchyVisibility.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/UseHierarchyVisibility.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EACL,cAAc,EACd,KAAK,EACL,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,aAAa,EACb,QAAQ,EACR,SAAS,EACT,qBAAqB,EACrB,OAAO,EACP,SAAS,EACT,GAAG,EACH,YAAY,GACb,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAsC/D,gBAAgB;AAChB,MAAM,UAAU,sBAAsB,CAAC,EACrC,wBAAwB,GACI;IAC5B,MAAM,mBAAmB,GAAG,MAAM,CAAC,IAAI,GAAG,EAAgG,CAAC,CAAC;IAC5I,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAiE;QACjG,wBAAwB,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;QACxE,uBAAuB,EAAE,GAAG,EAAE,GAAE,CAAC;QACjC,cAAc,EAAE,GAAG,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YACP,GAAG,KAAK;YACR,sBAAsB,EAAE,KAAK,IAAI,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,EAAE,YAAY,EAAE,SAAoB,EAAE,CAAC;YAC9F,OAAO;SACR,CAAC,CACH;QACH,CAAC,CAAC,GAAG,CAAC;AACV,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 { useEffect, useRef, useState } from \"react\";\nimport {\n asyncScheduler,\n defer,\n distinct,\n EMPTY,\n from,\n lastValueFrom,\n mergeMap,\n observeOn,\n onErrorResumeNextWith,\n Subject,\n takeUntil,\n tap,\n throttleTime,\n} from \"rxjs\";\nimport { useTelemetryContext } from \"./UseTelemetryContext.js\";\n\nimport type { Observable } from \"rxjs\";\nimport type { MutableRefObject } from \"react\";\nimport type { BeEvent, IDisposable } from \"@itwin/core-bentley\";\nimport type { HierarchyNode, PresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport type { TreeItemVisibilityButtonProps } from \"./components/TreeNodeVisibilityButton.js\";\n\n/**\n * Data structure that describes instance visibility status.\n * @beta\n */\nexport interface VisibilityStatus {\n /** Instance visibility state. */\n state: \"visible\" | \"partial\" | \"hidden\";\n /** Specifies whether visibility changing is disabled or not. */\n isDisabled?: boolean;\n /** Tooltip that should be displayed when hovering over the visibility checkbox. */\n tooltip?: string;\n}\n\n/**\n * Handler that can be used to determine and change visibility of instances represented by tree nodes.\n * @beta\n */\nexport interface HierarchyVisibilityHandler extends IDisposable {\n /** Event used to notify tree about visibility changes from outside. */\n readonly onVisibilityChange: BeEvent<() => void>;\n /** Returns current visibility status for tree node. */\n getVisibilityStatus(node: HierarchyNode): Promise<VisibilityStatus> | VisibilityStatus;\n /** Changes visibility of the instance represented by tree node. */\n changeVisibility(node: HierarchyNode, on: boolean): Promise<void>;\n}\n\ninterface UseHierarchyVisibilityProps {\n visibilityHandlerFactory: () => HierarchyVisibilityHandler;\n}\n\n/** @internal */\nexport function useHierarchyVisibility({\n visibilityHandlerFactory,\n}: UseHierarchyVisibilityProps): TreeItemVisibilityButtonProps & { triggerRefresh: () => void } {\n const visibilityStatusMap = useRef(new Map<string, { node: PresentationHierarchyNode; status: VisibilityStatus; needsRefresh: boolean }>());\n const [state, setState] = useState<TreeItemVisibilityButtonProps & { triggerRefresh: () => void }>({\n getVisibilityButtonState: () => ({ state: \"visible\", isDisabled: true }),\n onVisibilityButtonClick: () => {},\n triggerRefresh: () => {},\n });\n const { onFeatureUsed } = useTelemetryContext();\n\n useEffect(() => {\n visibilityStatusMap.current.clear();\n const handler = visibilityHandlerFactory();\n\n const visibilityChanged = new Subject<void>();\n const calculate = new Subject<PresentationHierarchyNode>();\n const calculateNodeStatus = (node: PresentationHierarchyNode) => {\n calculate.next(node);\n };\n\n const resetCache = () => {\n visibilityStatusMap.current.forEach((value) => {\n value.needsRefresh = true;\n });\n visibilityChanged.next();\n };\n\n const triggerCheckboxUpdate = () => {\n setState((prev) => ({\n ...prev,\n getCheckboxState: createStateGetter(visibilityStatusMap, calculateNodeStatus),\n }));\n };\n\n const subscription = calculate\n .pipe(\n distinct(undefined, visibilityChanged),\n observeOn(asyncScheduler),\n mergeMap((node) =>\n defer(async () => handler.getVisibilityStatus(node.nodeData)).pipe(\n tap({\n next: (status) => {\n visibilityStatusMap.current.set(node.id, {\n node,\n status,\n needsRefresh: false,\n });\n },\n }),\n takeUntil(visibilityChanged),\n onErrorResumeNextWith(EMPTY),\n ),\n ),\n throttleTime(100, undefined, { leading: false, trailing: true }),\n )\n .subscribe({\n next: () => {\n triggerCheckboxUpdate();\n },\n });\n\n const changeVisibility: TreeItemVisibilityButtonProps[\"onVisibilityButtonClick\"] = (node, visibilityState) => {\n onFeatureUsed({ featureId: \"visibility-change\", reportInteraction: true });\n // visible should become hidden, partial and hidden should become visible TODO: redo for clarity\n const on = visibilityState === \"visible\" ? false : true;\n void handler.changeVisibility(node.nodeData, on);\n const entry = visibilityStatusMap.current.get(node.id);\n if (!entry) {\n return;\n }\n entry.status.state = visibilityState;\n entry.status.tooltip = undefined;\n triggerCheckboxUpdate();\n };\n\n setState({\n onVisibilityButtonClick: changeVisibility,\n getVisibilityButtonState: createStateGetter(visibilityStatusMap, calculateNodeStatus),\n triggerRefresh: () => {\n resetCache();\n triggerCheckboxUpdate();\n },\n });\n\n const removeListener = handler.onVisibilityChange.addListener(() => {\n resetCache();\n triggerCheckboxUpdate();\n });\n\n return () => {\n subscription.unsubscribe();\n removeListener();\n handler.dispose();\n };\n }, [visibilityHandlerFactory, onFeatureUsed]);\n\n return state;\n}\n\nfunction createStateGetter(\n map: MutableRefObject<Map<string, { node: PresentationHierarchyNode; status: VisibilityStatus; needsRefresh: boolean }>>,\n calculateVisibility: (node: PresentationHierarchyNode) => void,\n): TreeItemVisibilityButtonProps[\"getVisibilityButtonState\"] {\n return (node) => {\n const entry = map.current.get(node.id);\n if (entry === undefined) {\n calculateVisibility(node);\n return { state: \"visible\", isDisabled: true };\n }\n if (entry.needsRefresh) {\n calculateVisibility(node);\n }\n\n const status = entry.status;\n return {\n state: status.state,\n tooltip: status.tooltip,\n isDisabled: status.isDisabled,\n };\n };\n}\n\n/**\n * Properties for an overridden method of a `HierarchyVisibilityHandler` implementation.\n * @beta\n */\nexport type HierarchyVisibilityHandlerOverridableMethodProps<TFunc> = TFunc extends (props: infer TProps) => infer TResult\n ? TProps & {\n /** A callback that produces the value from the original implementation. */\n readonly originalImplementation: () => TResult;\n /**\n * Reference to the hierarchy based handler.\n * @note Calling `getVisibility` or `changeVisibility` of this object invokes the overridden implementation as well.\n */\n readonly handler: HierarchyVisibilityHandler;\n }\n : never;\n\n/**\n * Function type for an overridden method of `HierarchyVisibilityHandler`.\n * @beta\n */\nexport type HierarchyVisibilityHandlerOverridableMethod<TFunc> = TFunc extends (...args: any[]) => infer TResult\n ? (props: HierarchyVisibilityHandlerOverridableMethodProps<TFunc>) => TResult\n : never;\n\n/** @internal */\nexport function createVisibilityHandlerResult<TResult, TOverrideProps>(\n handler: HierarchyVisibilityHandler,\n props: TOverrideProps,\n obs: Observable<TResult>,\n override: HierarchyVisibilityHandlerOverridableMethod<(props: TOverrideProps) => Promise<TResult>> | undefined,\n): Observable<TResult> {\n return override\n ? from(\n override({\n ...props,\n originalImplementation: async () => lastValueFrom(obs, { defaultValue: undefined as TResult }),\n handler,\n }),\n )\n : obs;\n}\n"]}
1
+ {"version":3,"file":"UseHierarchyVisibility.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/UseHierarchyVisibility.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EACL,cAAc,EACd,KAAK,EACL,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,aAAa,EACb,QAAQ,EACR,SAAS,EACT,qBAAqB,EACrB,OAAO,EACP,SAAS,EACT,GAAG,EACH,YAAY,GACb,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAoC/D,gBAAgB;AAChB,MAAM,UAAU,sBAAsB,CAAC,EACrC,wBAAwB,GACI;IAC5B,MAAM,mBAAmB,GAAG,MAAM,CAAC,IAAI,GAAG,EAA6G,CAAC,CAAC;IACzJ,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAiE;QACjG,wBAAwB,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;QACxE,uBAAuB,EAAE,GAAG,EAAE,GAAE,CAAC;QACjC,cAAc,EAAE,GAAG,EAAE,GAAE,CAAC;KACzB,CAAC,CAAC;IACH,MAAM,EAAE,aAAa,EAAE,GAA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EACxB,QAA8G;IAE9G,OAAO,QAAQ;QACb,CAAC,CAAC,IAAI,CACF,QAAQ,CAAC;YACP,GAAG,KAAK;YACR,sBAAsB,EAAE,KAAK,IAAI,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,EAAE,YAAY,EAAE,SAAoB,EAAE,CAAC;YAC9F,OAAO;SACR,CAAC,CACH;QACH,CAAC,CAAC,GAAG,CAAC;AACV,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 { useEffect, useRef, useState } from \"react\";\nimport {\n asyncScheduler,\n defer,\n distinct,\n EMPTY,\n from,\n lastValueFrom,\n mergeMap,\n observeOn,\n onErrorResumeNextWith,\n Subject,\n takeUntil,\n tap,\n throttleTime,\n} from \"rxjs\";\nimport { createTooltip } from \"./internal/Tooltip.js\";\nimport { useTelemetryContext } from \"./UseTelemetryContext.js\";\n\nimport type { Observable } from \"rxjs\";\nimport type { MutableRefObject } from \"react\";\nimport type { BeEvent, IDisposable } from \"@itwin/core-bentley\";\nimport type { HierarchyNode, PresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport type { TreeItemVisibilityButtonProps, TreeItemVisibilityButtonState } from \"./components/TreeNodeVisibilityButton.js\";\n\n/**\n * Data structure that describes instance visibility status.\n * @beta\n */\nexport interface VisibilityStatus {\n /** Instance visibility state. */\n state: \"visible\" | \"partial\" | \"hidden\";\n /** Specifies whether visibility changing is disabled or not. */\n isDisabled?: boolean;\n}\n\n/**\n * Handler that can be used to determine and change visibility of instances represented by tree nodes.\n * @beta\n */\nexport interface HierarchyVisibilityHandler extends IDisposable {\n /** Event used to notify tree about visibility changes from outside. */\n readonly onVisibilityChange: BeEvent<() => void>;\n /** Returns current visibility status for tree node. */\n getVisibilityStatus(node: HierarchyNode): Promise<VisibilityStatus> | VisibilityStatus;\n /** Changes visibility of the instance represented by tree node. */\n changeVisibility(node: HierarchyNode, on: boolean): Promise<void>;\n}\n\ninterface UseHierarchyVisibilityProps {\n visibilityHandlerFactory: () => HierarchyVisibilityHandler;\n}\n\n/** @internal */\nexport function useHierarchyVisibility({\n visibilityHandlerFactory,\n}: UseHierarchyVisibilityProps): TreeItemVisibilityButtonProps & { triggerRefresh: () => void } {\n const visibilityStatusMap = useRef(new Map<string, { node: PresentationHierarchyNode; status: TreeItemVisibilityButtonState; needsRefresh: boolean }>());\n const [state, setState] = useState<TreeItemVisibilityButtonProps & { triggerRefresh: () => void }>({\n getVisibilityButtonState: () => ({ state: \"visible\", isDisabled: true }),\n onVisibilityButtonClick: () => {},\n triggerRefresh: () => {},\n });\n const { onFeatureUsed } = useTelemetryContext();\n\n useEffect(() => {\n visibilityStatusMap.current.clear();\n const handler = visibilityHandlerFactory();\n\n const visibilityChanged = new Subject<void>();\n const calculate = new Subject<PresentationHierarchyNode>();\n const calculateNodeStatus = (node: PresentationHierarchyNode) => {\n calculate.next(node);\n };\n\n const resetCache = () => {\n visibilityStatusMap.current.forEach((value) => {\n value.needsRefresh = true;\n });\n visibilityChanged.next();\n };\n\n const triggerCheckboxUpdate = () => {\n setState((prev) => ({\n ...prev,\n getVisibilityButtonState: createStateGetter(visibilityStatusMap, calculateNodeStatus),\n }));\n };\n\n const subscription = calculate\n .pipe(\n distinct(undefined, visibilityChanged),\n observeOn(asyncScheduler),\n mergeMap((node) =>\n defer(async () => handler.getVisibilityStatus(node.nodeData)).pipe(\n tap({\n next: (status) => {\n visibilityStatusMap.current.set(node.id, {\n node,\n status: {\n ...status,\n tooltip: createTooltip(status.state),\n },\n needsRefresh: false,\n });\n },\n }),\n takeUntil(visibilityChanged),\n onErrorResumeNextWith(EMPTY),\n ),\n ),\n throttleTime(100, undefined, { leading: false, trailing: true }),\n )\n .subscribe({\n next: () => {\n triggerCheckboxUpdate();\n },\n });\n\n const changeVisibility: TreeItemVisibilityButtonProps[\"onVisibilityButtonClick\"] = (node, visibilityState) => {\n onFeatureUsed({ featureId: \"visibility-change\", reportInteraction: true });\n // visible should become hidden, partial and hidden should become visible TODO: redo for clarity\n const on = visibilityState === \"visible\" ? false : true;\n void handler.changeVisibility(node.nodeData, on);\n const entry = visibilityStatusMap.current.get(node.id);\n if (!entry) {\n return;\n }\n entry.status.state = visibilityState;\n entry.status.tooltip = createTooltip(\"determining\");\n triggerCheckboxUpdate();\n };\n\n setState({\n onVisibilityButtonClick: changeVisibility,\n getVisibilityButtonState: createStateGetter(visibilityStatusMap, calculateNodeStatus),\n triggerRefresh: () => {\n resetCache();\n triggerCheckboxUpdate();\n },\n });\n\n const removeListener = handler.onVisibilityChange.addListener(() => {\n resetCache();\n triggerCheckboxUpdate();\n });\n\n return () => {\n subscription.unsubscribe();\n removeListener();\n handler.dispose();\n };\n }, [visibilityHandlerFactory, onFeatureUsed]);\n\n return state;\n}\n\nfunction createStateGetter(\n map: MutableRefObject<Map<string, { node: PresentationHierarchyNode; status: TreeItemVisibilityButtonState; needsRefresh: boolean }>>,\n calculateVisibility: (node: PresentationHierarchyNode) => void,\n): TreeItemVisibilityButtonProps[\"getVisibilityButtonState\"] {\n return (node) => {\n const entry = map.current.get(node.id);\n if (entry === undefined) {\n calculateVisibility(node);\n return { state: \"visible\", isDisabled: true, tooltip: createTooltip(\"determining\") };\n }\n if (entry.needsRefresh) {\n calculateVisibility(node);\n }\n\n const status = entry.status;\n return {\n state: status.state,\n tooltip: status.tooltip,\n isDisabled: status.isDisabled,\n };\n };\n}\n\n/**\n * Properties for an overridden method of a `HierarchyVisibilityHandler` implementation.\n * @beta\n */\nexport type HierarchyVisibilityHandlerOverridableMethodProps<TFunc> = TFunc extends (props: infer TProps) => infer TResult\n ? TProps & {\n /** A callback that produces the value from the original implementation. */\n readonly originalImplementation: () => TResult;\n /**\n * Reference to the hierarchy based handler.\n * @note Calling `getVisibility` or `changeVisibility` of this object invokes the overridden implementation as well.\n */\n readonly handler: HierarchyVisibilityHandler;\n }\n : never;\n\n/**\n * Function type for an overridden method of `HierarchyVisibilityHandler`.\n * @beta\n */\nexport type HierarchyVisibilityHandlerOverridableMethod<TFunc> = TFunc extends (...args: any[]) => infer TResult\n ? (props: HierarchyVisibilityHandlerOverridableMethodProps<TFunc>) => TResult\n : never;\n\n/** @internal */\nexport function createVisibilityHandlerResult<TResult, TOverrideProps>(\n handler: HierarchyVisibilityHandler,\n props: TOverrideProps,\n obs: Observable<TResult>,\n override: HierarchyVisibilityHandlerOverridableMethod<(props: TOverrideProps) => Promise<TResult>> | undefined,\n): Observable<TResult> {\n return override\n ? from(\n override({\n ...props,\n originalImplementation: async () => lastValueFrom(obs, { defaultValue: undefined as TResult }),\n handler,\n }),\n )\n : obs;\n}\n"]}
@@ -3,41 +3,42 @@ import { Fragment as _Fragment, 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, useRef, useState } from "react";
6
+ import { useCallback, useEffect, useState } from "react";
7
7
  import { isPresentationHierarchyNode } from "@itwin/presentation-hierarchies-react";
8
8
  import { useLatest } from "./internal/Utils.js";
9
9
  /** @internal */
10
10
  export function useNodeHighlighting({ rootNodes, highlight }) {
11
- const state = useRef({ nodeInfoMap: new Map(), totalMatches: 0 });
11
+ const [state, setState] = useState({ nodeInfoMap: new Map(), totalMatches: 0 });
12
12
  const [activeNodeId, setActiveNodeId] = useState();
13
13
  const activeMatchIndexRef = useLatest(highlight?.activeMatchIndex);
14
14
  const activeNodeIdRef = useLatest(activeNodeId);
15
15
  const onHighlightChangedRef = useLatest(highlight?.onHighlightChanged);
16
+ const prevStateRef = useLatest(state);
16
17
  const searchText = highlight?.text;
17
18
  useEffect(() => {
18
19
  const { state: newState, activeIndex } = rootNodes && searchText
19
- ? computeHighlightState(rootNodes, searchText, state.current, activeNodeIdRef.current, activeMatchIndexRef.current)
20
+ ? computeHighlightState(rootNodes, searchText, prevStateRef.current, activeNodeIdRef.current, activeMatchIndexRef.current)
20
21
  : { state: { nodeInfoMap: new Map(), totalMatches: 0 }, activeIndex: 0 };
21
- state.current = newState;
22
+ setState(newState);
22
23
  if (newState.totalMatches === 0) {
23
24
  setActiveNodeId(undefined);
24
25
  }
25
26
  onHighlightChangedRef.current?.(newState.totalMatches === 0 ? 0 : activeIndex, newState.totalMatches);
26
- }, [rootNodes, searchText, activeNodeIdRef, activeMatchIndexRef, onHighlightChangedRef]);
27
+ }, [rootNodes, searchText, activeNodeIdRef, activeMatchIndexRef, onHighlightChangedRef, prevStateRef]);
27
28
  useEffect(() => {
28
- for (const nodeId of state.current.nodeInfoMap.keys()) {
29
- if (getNodeChunkInfo(state.current, nodeId, highlight?.activeMatchIndex)?.activeChunkIndex !== undefined) {
29
+ for (const nodeId of state.nodeInfoMap.keys()) {
30
+ if (getNodeChunkInfo(state, nodeId, highlight?.activeMatchIndex)?.activeChunkIndex !== undefined) {
30
31
  setActiveNodeId(nodeId);
31
32
  }
32
33
  }
33
- }, [highlight?.activeMatchIndex]);
34
+ }, [state, highlight?.activeMatchIndex]);
34
35
  const getLabel = useCallback((node) => {
35
- const chunkInfo = getNodeChunkInfo(state.current, node.id, highlight?.activeMatchIndex);
36
+ const chunkInfo = getNodeChunkInfo(state, node.id, highlight?.activeMatchIndex);
36
37
  if (searchText && chunkInfo) {
37
38
  return _jsx(_Fragment, { children: markChunks(node.label, chunkInfo.chunks, chunkInfo.activeChunkIndex) });
38
39
  }
39
40
  return _jsx("span", { children: node.label });
40
- }, [searchText, highlight?.activeMatchIndex]);
41
+ }, [state, searchText, highlight?.activeMatchIndex]);
41
42
  return { activeNodeId, getLabel };
42
43
  }
43
44
  function getNodeChunkInfo(state, nodeId, activeIndex) {
@@ -1 +1 @@
1
- {"version":3,"file":"UseNodeHighlighting.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/UseNodeHighlighting.tsx"],"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G,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACtC,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACxB,MAAM,QAAQ,GAAG,CAAC,KAAK,WAAW,CAAC;QACnC,IAAI,SAAS,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,KAAK,KAAK,CAAC,KAAK,IAAI,CAAC,QAAQ,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE;YACvF,SAAS,CAAC,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;YAC/B,SAAS;SACV;QACD,QAAQ,IAAI,CAAC,cAAc,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;QACnD,MAAM,QAAQ,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC;QACxD,SAAS,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;QACzC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;KAC7B;IACD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,CAAC;AAC1C,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 { isPresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport { useLatest } from \"./internal/Utils.js\";\n\nimport type { PresentationHierarchyNode, PresentationTreeNode } from \"@itwin/presentation-hierarchies-react\";\n\n/** @beta */\nexport interface HighlightInfo {\n text: string;\n}\n\ninterface UseNodeHighlightingProps {\n rootNodes: PresentationTreeNode[] | undefined;\n // TODO: move activeMatchIndex and onHighlightChanged to HighlightInfo when it's implemented.\n highlight?: HighlightInfo & {\n activeMatchIndex?: number;\n onHighlightChanged?: (activeMatchIndex: number, matches: number) => void;\n };\n}\n\ninterface HighlightedChunk {\n start: number;\n end: number;\n}\n\ninterface NodeChunkInfo {\n chunks: HighlightedChunk[];\n activeChunkIndex?: number;\n}\n\ninterface NodeHighlightInfo {\n startIndex: number;\n matches: HighlightedChunk[];\n}\n\ninterface HighlightState {\n nodeInfoMap: Map<string, NodeHighlightInfo>;\n totalMatches: number;\n}\n\ninterface UseNodeHighlightingResult {\n activeNodeId?: string;\n getLabel: (node: PresentationHierarchyNode) => React.ReactElement;\n}\n\n/** @internal */\nexport function useNodeHighlighting({ rootNodes, highlight }: UseNodeHighlightingProps): UseNodeHighlightingResult {\n const state = useRef<HighlightState>({ nodeInfoMap: new Map(), totalMatches: 0 });\n const [activeNodeId, setActiveNodeId] = useState<string | undefined>();\n const activeMatchIndexRef = useLatest(highlight?.activeMatchIndex);\n const activeNodeIdRef = useLatest(activeNodeId);\n const onHighlightChangedRef = useLatest(highlight?.onHighlightChanged);\n const searchText = highlight?.text;\n\n useEffect(() => {\n const { state: newState, activeIndex } =\n rootNodes && searchText\n ? computeHighlightState(rootNodes, searchText, state.current, activeNodeIdRef.current, activeMatchIndexRef.current)\n : { state: { nodeInfoMap: new Map(), totalMatches: 0 }, activeIndex: 0 };\n\n state.current = newState;\n if (newState.totalMatches === 0) {\n setActiveNodeId(undefined);\n }\n onHighlightChangedRef.current?.(newState.totalMatches === 0 ? 0 : activeIndex, newState.totalMatches);\n }, [rootNodes, searchText, activeNodeIdRef, activeMatchIndexRef, onHighlightChangedRef]);\n\n useEffect(() => {\n for (const nodeId of state.current.nodeInfoMap.keys()) {\n if (getNodeChunkInfo(state.current, nodeId, highlight?.activeMatchIndex)?.activeChunkIndex !== undefined) {\n setActiveNodeId(nodeId);\n }\n }\n }, [highlight?.activeMatchIndex]);\n\n const getLabel = useCallback(\n (node: PresentationHierarchyNode) => {\n const chunkInfo = getNodeChunkInfo(state.current, node.id, highlight?.activeMatchIndex);\n if (searchText && chunkInfo) {\n return <>{markChunks(node.label, chunkInfo.chunks, chunkInfo.activeChunkIndex)}</>;\n }\n return <span>{node.label}</span>;\n },\n [searchText, highlight?.activeMatchIndex],\n );\n\n return { activeNodeId, getLabel };\n}\n\nfunction getNodeChunkInfo(state: HighlightState, nodeId: string, activeIndex?: number): NodeChunkInfo | undefined {\n const info = state.nodeInfoMap.get(nodeId);\n if (!info) {\n return undefined;\n }\n if (activeIndex === undefined) {\n return { chunks: info.matches };\n }\n const isActive = info && activeIndex >= info.startIndex && activeIndex < info.startIndex + info.matches.length;\n return isActive ? { activeChunkIndex: activeIndex - info.startIndex, chunks: info.matches } : { chunks: info.matches };\n}\n\nfunction computeHighlightState(rootNodes: PresentationTreeNode[], searchText: string, state: HighlightState, activeNodeId?: string, activeMatchIndex?: number) {\n const newState: HighlightState = { nodeInfoMap: new Map(), totalMatches: 0 };\n let newActiveIndex = activeMatchIndex ?? 0;\n\n const computeHighlightStateRecursively = (nodes: Array<PresentationTreeNode>) => {\n nodes.forEach((node) => {\n if (!isPresentationHierarchyNode(node)) {\n return;\n }\n\n const matches = findChunks(node.label, searchText);\n newState.nodeInfoMap.set(node.id, { startIndex: newState.totalMatches, matches });\n newState.totalMatches += matches.length;\n\n if (typeof node.children !== \"boolean\") {\n computeHighlightStateRecursively(node.children);\n }\n });\n };\n\n computeHighlightStateRecursively(rootNodes);\n\n // update active index to not cause active chunk jumps when hierarchy changes\n if (activeNodeId && newActiveIndex !== 0) {\n const activeNodeInfo = getNodeChunkInfo(state, activeNodeId, activeMatchIndex);\n const updatedInfo = newState.nodeInfoMap.get(activeNodeId);\n\n if (updatedInfo && activeNodeInfo?.activeChunkIndex !== undefined) {\n newActiveIndex = updatedInfo.startIndex + activeNodeInfo.activeChunkIndex;\n }\n }\n\n return { state: newState, activeIndex: newActiveIndex };\n}\n\nfunction findChunks(text: string, searchText: string): HighlightedChunk[] {\n const chunks: HighlightedChunk[] = [];\n\n const contentText = text.toLowerCase();\n const inputText = searchText.toLowerCase();\n let index = contentText.indexOf(inputText);\n\n while (index !== -1) {\n chunks.push({ start: index, end: index + inputText.length });\n index = contentText.indexOf(inputText, index + 1);\n }\n\n return chunks;\n}\n\nfunction markChunks(text: string, chunks: HighlightedChunk[], activeChunk?: number) {\n const markedText: React.ReactElement[] = [];\n let previousIndex = 0;\n\n const { mergedChunks, newActiveIndex } = mergeChunks(chunks, activeChunk);\n\n for (let i = 0; i < mergedChunks.length; i++) {\n const { start, end } = mergedChunks[i];\n\n // add unmarked text between previous chunk and current one\n const nonMarkedText = text.substring(previousIndex, start);\n nonMarkedText.length && markedText.push(<span key={previousIndex}>{nonMarkedText}</span>);\n\n // add marked chunk text\n markedText.push(\n <mark key={start} className={i === newActiveIndex ? \"tw-active-match-highlight\" : undefined}>\n {text.substring(start, end)}\n </mark>,\n );\n previousIndex = end;\n }\n\n // add unmarked text after last chunk\n const lastNonMarkedText = text.substring(previousIndex, text.length);\n lastNonMarkedText.length && markedText.push(<span key={previousIndex}>{lastNonMarkedText}</span>);\n\n return markedText;\n}\n\nfunction mergeChunks(chunks: HighlightedChunk[], activeChunk?: number) {\n const mergedChunks: HighlightedChunk[] = [];\n let lastChunk: { isActive: boolean; info: HighlightedChunk } | undefined;\n let newActiveIndex: number | undefined;\n\n for (let i = 0; i < chunks.length; i++) {\n const chunk = chunks[i];\n const isActive = i === activeChunk;\n if (lastChunk && lastChunk.info.end === chunk.start && !isActive && !lastChunk.isActive) {\n lastChunk.info.end = chunk.end;\n continue;\n }\n isActive && (newActiveIndex = mergedChunks.length);\n const newChunk = { start: chunk.start, end: chunk.end };\n lastChunk = { isActive, info: newChunk };\n mergedChunks.push(newChunk);\n }\n return { mergedChunks, newActiveIndex };\n}\n"]}
1
+ {"version":3,"file":"UseNodeHighlighting.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/UseNodeHighlighting.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QA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EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACtC,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACxB,MAAM,QAAQ,GAAG,CAAC,KAAK,WAAW,CAAC;QACnC,IAAI,SAAS,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,KAAK,KAAK,CAAC,KAAK,IAAI,CAAC,QAAQ,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE;YACvF,SAAS,CAAC,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;YAC/B,SAAS;SACV;QACD,QAAQ,IAAI,CAAC,cAAc,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;QACnD,MAAM,QAAQ,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC;QACxD,SAAS,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;QACzC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;KAC7B;IACD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,CAAC;AAC1C,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\";\nimport { isPresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport { useLatest } from \"./internal/Utils.js\";\n\nimport type { PresentationHierarchyNode, PresentationTreeNode } from \"@itwin/presentation-hierarchies-react\";\n\n/** @beta */\nexport interface HighlightInfo {\n text: string;\n}\n\ninterface UseNodeHighlightingProps {\n rootNodes: PresentationTreeNode[] | undefined;\n // TODO: move activeMatchIndex and onHighlightChanged to HighlightInfo when it's implemented.\n highlight?: HighlightInfo & {\n activeMatchIndex?: number;\n onHighlightChanged?: (activeMatchIndex: number, matches: number) => void;\n };\n}\n\ninterface HighlightedChunk {\n start: number;\n end: number;\n}\n\ninterface NodeChunkInfo {\n chunks: HighlightedChunk[];\n activeChunkIndex?: number;\n}\n\ninterface NodeHighlightInfo {\n startIndex: number;\n matches: HighlightedChunk[];\n}\n\ninterface HighlightState {\n nodeInfoMap: Map<string, NodeHighlightInfo>;\n totalMatches: number;\n}\n\ninterface UseNodeHighlightingResult {\n activeNodeId?: string;\n getLabel: (node: PresentationHierarchyNode) => React.ReactElement;\n}\n\n/** @internal */\nexport function useNodeHighlighting({ rootNodes, highlight }: UseNodeHighlightingProps): UseNodeHighlightingResult {\n const [state, setState] = useState<HighlightState>({ nodeInfoMap: new Map(), totalMatches: 0 });\n const [activeNodeId, setActiveNodeId] = useState<string | undefined>();\n const activeMatchIndexRef = useLatest(highlight?.activeMatchIndex);\n const activeNodeIdRef = useLatest(activeNodeId);\n const onHighlightChangedRef = useLatest(highlight?.onHighlightChanged);\n const prevStateRef = useLatest(state);\n const searchText = highlight?.text;\n\n useEffect(() => {\n const { state: newState, activeIndex } =\n rootNodes && searchText\n ? computeHighlightState(rootNodes, searchText, prevStateRef.current, activeNodeIdRef.current, activeMatchIndexRef.current)\n : { state: { nodeInfoMap: new Map(), totalMatches: 0 }, activeIndex: 0 };\n\n setState(newState);\n if (newState.totalMatches === 0) {\n setActiveNodeId(undefined);\n }\n onHighlightChangedRef.current?.(newState.totalMatches === 0 ? 0 : activeIndex, newState.totalMatches);\n }, [rootNodes, searchText, activeNodeIdRef, activeMatchIndexRef, onHighlightChangedRef, prevStateRef]);\n\n useEffect(() => {\n for (const nodeId of state.nodeInfoMap.keys()) {\n if (getNodeChunkInfo(state, nodeId, highlight?.activeMatchIndex)?.activeChunkIndex !== undefined) {\n setActiveNodeId(nodeId);\n }\n }\n }, [state, highlight?.activeMatchIndex]);\n\n const getLabel = useCallback(\n (node: PresentationHierarchyNode) => {\n const chunkInfo = getNodeChunkInfo(state, node.id, highlight?.activeMatchIndex);\n if (searchText && chunkInfo) {\n return <>{markChunks(node.label, chunkInfo.chunks, chunkInfo.activeChunkIndex)}</>;\n }\n return <span>{node.label}</span>;\n },\n [state, searchText, highlight?.activeMatchIndex],\n );\n\n return { activeNodeId, getLabel };\n}\n\nfunction getNodeChunkInfo(state: HighlightState, nodeId: string, activeIndex?: number): NodeChunkInfo | undefined {\n const info = state.nodeInfoMap.get(nodeId);\n if (!info) {\n return undefined;\n }\n if (activeIndex === undefined) {\n return { chunks: info.matches };\n }\n const isActive = info && activeIndex >= info.startIndex && activeIndex < info.startIndex + info.matches.length;\n return isActive ? { activeChunkIndex: activeIndex - info.startIndex, chunks: info.matches } : { chunks: info.matches };\n}\n\nfunction computeHighlightState(rootNodes: PresentationTreeNode[], searchText: string, state: HighlightState, activeNodeId?: string, activeMatchIndex?: number) {\n const newState: HighlightState = { nodeInfoMap: new Map(), totalMatches: 0 };\n let newActiveIndex = activeMatchIndex ?? 0;\n\n const computeHighlightStateRecursively = (nodes: Array<PresentationTreeNode>) => {\n nodes.forEach((node) => {\n if (!isPresentationHierarchyNode(node)) {\n return;\n }\n\n const matches = findChunks(node.label, searchText);\n newState.nodeInfoMap.set(node.id, { startIndex: newState.totalMatches, matches });\n newState.totalMatches += matches.length;\n\n if (typeof node.children !== \"boolean\") {\n computeHighlightStateRecursively(node.children);\n }\n });\n };\n\n computeHighlightStateRecursively(rootNodes);\n\n // update active index to not cause active chunk jumps when hierarchy changes\n if (activeNodeId && newActiveIndex !== 0) {\n const activeNodeInfo = getNodeChunkInfo(state, activeNodeId, activeMatchIndex);\n const updatedInfo = newState.nodeInfoMap.get(activeNodeId);\n\n if (updatedInfo && activeNodeInfo?.activeChunkIndex !== undefined) {\n newActiveIndex = updatedInfo.startIndex + activeNodeInfo.activeChunkIndex;\n }\n }\n\n return { state: newState, activeIndex: newActiveIndex };\n}\n\nfunction findChunks(text: string, searchText: string): HighlightedChunk[] {\n const chunks: HighlightedChunk[] = [];\n\n const contentText = text.toLowerCase();\n const inputText = searchText.toLowerCase();\n let index = contentText.indexOf(inputText);\n\n while (index !== -1) {\n chunks.push({ start: index, end: index + inputText.length });\n index = contentText.indexOf(inputText, index + 1);\n }\n\n return chunks;\n}\n\nfunction markChunks(text: string, chunks: HighlightedChunk[], activeChunk?: number) {\n const markedText: React.ReactElement[] = [];\n let previousIndex = 0;\n\n const { mergedChunks, newActiveIndex } = mergeChunks(chunks, activeChunk);\n\n for (let i = 0; i < mergedChunks.length; i++) {\n const { start, end } = mergedChunks[i];\n\n // add unmarked text between previous chunk and current one\n const nonMarkedText = text.substring(previousIndex, start);\n nonMarkedText.length && markedText.push(<span key={previousIndex}>{nonMarkedText}</span>);\n\n // add marked chunk text\n markedText.push(\n <mark key={start} className={i === newActiveIndex ? \"tw-active-match-highlight\" : undefined}>\n {text.substring(start, end)}\n </mark>,\n );\n previousIndex = end;\n }\n\n // add unmarked text after last chunk\n const lastNonMarkedText = text.substring(previousIndex, text.length);\n lastNonMarkedText.length && markedText.push(<span key={previousIndex}>{lastNonMarkedText}</span>);\n\n return markedText;\n}\n\nfunction mergeChunks(chunks: HighlightedChunk[], activeChunk?: number) {\n const mergedChunks: HighlightedChunk[] = [];\n let lastChunk: { isActive: boolean; info: HighlightedChunk } | undefined;\n let newActiveIndex: number | undefined;\n\n for (let i = 0; i < chunks.length; i++) {\n const chunk = chunks[i];\n const isActive = i === activeChunk;\n if (lastChunk && lastChunk.info.end === chunk.start && !isActive && !lastChunk.isActive) {\n lastChunk.info.end = chunk.end;\n continue;\n }\n isActive && (newActiveIndex = mergedChunks.length);\n const newChunk = { start: chunk.start, end: chunk.end };\n lastChunk = { isActive, info: newChunk };\n mergedChunks.push(newChunk);\n }\n return { mergedChunks, newActiveIndex };\n}\n"]}
@@ -1,5 +1,10 @@
1
1
  import type { Viewport } from "@itwin/core-frontend";
2
2
  import type { Id64Array } from "@itwin/core-bentley";
3
+ /**
4
+ * This is a logging namespace for public log messages that may be interesting to consumers.
5
+ * @internal
6
+ */
7
+ export declare const LOGGING_NAMESPACE = "TreeWidget";
3
8
  /** @beta */
4
9
  export type FunctionProps<THook extends (props: any) => any> = Parameters<THook>[0];
5
10
  /**
@@ -4,6 +4,11 @@
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
  import { showAllCategories } from "./CategoriesVisibilityUtils.js";
6
6
  import { toggleAllCategories } from "./internal/VisibilityUtils.js";
7
+ /**
8
+ * This is a logging namespace for public log messages that may be interesting to consumers.
9
+ * @internal
10
+ */
11
+ export const LOGGING_NAMESPACE = "TreeWidget";
7
12
  /**
8
13
  * Disables display of all given models.
9
14
  * @public
@@ -1 +1 @@
1
- {"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/Utils.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAGhG,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAOpE;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAAgB,EAAE,QAAkB;IACtE,QAAQ,CAAC,kBAAkB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAC7C,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,KAM7B;IACC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAC/C,MAAM,QAAQ,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;IACvC,QAAQ,CAAC,eAAe,EAAE,CAAC;IAC3B,QAAQ,CAAC,gBAAgB,EAAE,CAAC;IAC5B,IAAI,UAAU,EAAE;QACd,MAAM,iBAAiB,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;KAC/C;SAAM;QACL,MAAM,mBAAmB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;KAC3C;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,MAAiB,EAAE,QAAkB;IACzE,MAAM,eAAe,GAAG,IAAI,KAAK,EAAc,CAAC;IAChD,MAAM,YAAY,GAAG,IAAI,KAAK,EAAc,CAAC;IAC7C,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QACzB,IAAI,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;YAChC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SAC5B;aAAM;YACL,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SAC/B;IACH,CAAC,CAAC,CAAC;IACH,MAAM,QAAQ,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC;IAChD,QAAQ,CAAC,kBAAkB,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;AACnD,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,MAAgB,EAAE,MAAe,EAAE,QAAkB;IACtF,IAAI,CAAC,MAAM,EAAE;QACX,OAAO;KACR;IACD,IAAI,MAAM,EAAE;QACV,QAAQ,CAAC,kBAAkB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;KAC5C;SAAM;QACL,MAAM,QAAQ,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;KACxC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAgB,EAAE,QAAkB;IACtE,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AACrF,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 type { Viewport } from \"@itwin/core-frontend\";\nimport { showAllCategories } from \"./CategoriesVisibilityUtils.js\";\nimport { toggleAllCategories } from \"./internal/VisibilityUtils.js\";\n\nimport type { Id64Array, Id64String } from \"@itwin/core-bentley\";\n\n/** @beta */\nexport type FunctionProps<THook extends (props: any) => any> = Parameters<THook>[0];\n\n/**\n * Disables display of all given models.\n * @public\n */\nexport async function hideAllModels(models: string[], viewport: Viewport) {\n viewport.changeModelDisplay(models, false);\n}\n\n/**\n * Enables display of all given models. Also enables display of all categories and clears always and\n * never drawn lists in the viewport.\n * @public\n */\nexport async function showAll(props: {\n /** ID's of models to enable */\n models: Id64Array;\n /** ID's of categories to enable, if set to undefined, all categories will be enabled */\n categories?: Id64Array;\n viewport: Viewport;\n}) {\n const { models, categories, viewport } = props;\n await viewport.addViewedModels(models);\n viewport.clearNeverDrawn();\n viewport.clearAlwaysDrawn();\n if (categories) {\n await showAllCategories(categories, viewport);\n } else {\n await toggleAllCategories(viewport, true);\n }\n}\n\n/**\n * Inverts display of all given models.\n * @public\n */\nexport async function invertAllModels(models: Id64Array, viewport: Viewport) {\n const notViewedModels = new Array<Id64String>();\n const viewedModels = new Array<Id64String>();\n models.forEach((modelId) => {\n if (viewport.viewsModel(modelId)) {\n viewedModels.push(modelId);\n } else {\n notViewedModels.push(modelId);\n }\n });\n await viewport.addViewedModels(notViewedModels);\n viewport.changeModelDisplay(viewedModels, false);\n}\n\n/**\n * Based on the value of `enable` argument, either enables or disables display of given models.\n * @public\n */\nexport async function toggleModels(models: string[], enable: boolean, viewport: Viewport) {\n if (!models) {\n return;\n }\n if (enable) {\n viewport.changeModelDisplay(models, false);\n } else {\n await viewport.addViewedModels(models);\n }\n}\n\n/**\n * Checks if all given models are displayed in given viewport.\n * @public\n */\nexport function areAllModelsVisible(models: string[], viewport: Viewport) {\n return models.length !== 0 ? models.every((id) => viewport.viewsModel(id)) : false;\n}\n"]}
1
+ {"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/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MAAM,QAAQ,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC;IAChD,QAAQ,CAAC,kBAAkB,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;AACnD,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,MAAgB,EAAE,MAAe,EAAE,QAAkB;IACtF,IAAI,CAAC,MAAM,EAAE;QACX,OAAO;KACR;IACD,IAAI,MAAM,EAAE;QACV,QAAQ,CAAC,kBAAkB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;KAC5C;SAAM;QACL,MAAM,QAAQ,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;KACxC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAgB,EAAE,QAAkB;IACtE,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AACrF,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 type { Viewport } from \"@itwin/core-frontend\";\nimport { showAllCategories } from \"./CategoriesVisibilityUtils.js\";\nimport { toggleAllCategories } from \"./internal/VisibilityUtils.js\";\n\nimport type { Id64Array, Id64String } from \"@itwin/core-bentley\";\n\n/**\n * This is a logging namespace for public log messages that may be interesting to consumers.\n * @internal\n */\nexport const LOGGING_NAMESPACE = \"TreeWidget\";\n\n/** @beta */\nexport type FunctionProps<THook extends (props: any) => any> = Parameters<THook>[0];\n\n/**\n * Disables display of all given models.\n * @public\n */\nexport async function hideAllModels(models: string[], viewport: Viewport) {\n viewport.changeModelDisplay(models, false);\n}\n\n/**\n * Enables display of all given models. Also enables display of all categories and clears always and\n * never drawn lists in the viewport.\n * @public\n */\nexport async function showAll(props: {\n /** ID's of models to enable */\n models: Id64Array;\n /** ID's of categories to enable, if set to undefined, all categories will be enabled */\n categories?: Id64Array;\n viewport: Viewport;\n}) {\n const { models, categories, viewport } = props;\n await viewport.addViewedModels(models);\n viewport.clearNeverDrawn();\n viewport.clearAlwaysDrawn();\n if (categories) {\n await showAllCategories(categories, viewport);\n } else {\n await toggleAllCategories(viewport, true);\n }\n}\n\n/**\n * Inverts display of all given models.\n * @public\n */\nexport async function invertAllModels(models: Id64Array, viewport: Viewport) {\n const notViewedModels = new Array<Id64String>();\n const viewedModels = new Array<Id64String>();\n models.forEach((modelId) => {\n if (viewport.viewsModel(modelId)) {\n viewedModels.push(modelId);\n } else {\n notViewedModels.push(modelId);\n }\n });\n await viewport.addViewedModels(notViewedModels);\n viewport.changeModelDisplay(viewedModels, false);\n}\n\n/**\n * Based on the value of `enable` argument, either enables or disables display of given models.\n * @public\n */\nexport async function toggleModels(models: string[], enable: boolean, viewport: Viewport) {\n if (!models) {\n return;\n }\n if (enable) {\n viewport.changeModelDisplay(models, false);\n } else {\n await viewport.addViewedModels(models);\n }\n}\n\n/**\n * Checks if all given models are displayed in given viewport.\n * @public\n */\nexport function areAllModelsVisible(models: string[], viewport: Viewport) {\n return models.length !== 0 ? models.every((id) => viewport.viewsModel(id)) : false;\n}\n"]}
@@ -3,5 +3,5 @@ import { TreeRenderer as PresentationTree } from "@itwin/presentation-hierarchie
3
3
  /** @beta */
4
4
  export type BaseTreeRendererProps = React.ComponentPropsWithoutRef<typeof PresentationTree>;
5
5
  /** @internal */
6
- export declare function BaseTreeRenderer({ rootNodes, onNodeClick, expandNode, actions, ...props }: BaseTreeRendererProps): import("react/jsx-runtime").JSX.Element;
6
+ export declare function BaseTreeRenderer({ rootNodes, expandNode, getActions, ...props }: BaseTreeRendererProps): import("react/jsx-runtime").JSX.Element;
7
7
  //# sourceMappingURL=BaseTreeRenderer.d.ts.map
@@ -7,8 +7,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
7
7
  import { TreeRenderer as PresentationTree } from "@itwin/presentation-hierarchies-react";
8
8
  import { useHierarchiesLocalization } from "../internal/UseHierarchiesLocalization.js";
9
9
  /** @internal */
10
- export function BaseTreeRenderer({ rootNodes, onNodeClick, expandNode, actions, ...props }) {
10
+ export function BaseTreeRenderer({ rootNodes, expandNode, getActions, ...props }) {
11
11
  const localizedStrings = useHierarchiesLocalization();
12
- return (_jsx(PresentationTree, { ...props, onNodeClick: onNodeClick, localizedStrings: localizedStrings, expandNode: expandNode, rootNodes: rootNodes, actions: actions }));
12
+ return _jsx(PresentationTree, { ...props, localizedStrings: localizedStrings, expandNode: expandNode, rootNodes: rootNodes, getActions: getActions });
13
13
  }
14
14
  //# sourceMappingURL=BaseTreeRenderer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BaseTreeRenderer.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/common/components/BaseTreeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG,uCAAuC;AAEvC,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AACzF,OAAO,EAAE,0BAA0B,EAAE,MAAM,2CAA2C,CAAC;AAKvF,gBAAgB;AAChB,MAAM,UAAU,gBAAgB,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,KAAK,EAAyB;IAC/G,MAAM,gBAAgB,GAAG,0BAA0B,EAAE,CAAC;IACtD,OAAO,CACL,KAAC,gBAAgB,OACX,KAAK,EACT,WAAW,EAAE,WAAW,EACxB,gBAAgB,EAAE,gBAAgB,EAClC,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,OAAO,GAChB,CACH,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/* eslint-disable @itwin/no-internal */\n\nimport { TreeRenderer as PresentationTree } from \"@itwin/presentation-hierarchies-react\";\nimport { useHierarchiesLocalization } from \"../internal/UseHierarchiesLocalization.js\";\n\n/** @beta */\nexport type BaseTreeRendererProps = React.ComponentPropsWithoutRef<typeof PresentationTree>;\n\n/** @internal */\nexport function BaseTreeRenderer({ rootNodes, onNodeClick, expandNode, actions, ...props }: BaseTreeRendererProps) {\n const localizedStrings = useHierarchiesLocalization();\n return (\n <PresentationTree\n {...props}\n onNodeClick={onNodeClick}\n localizedStrings={localizedStrings}\n expandNode={expandNode}\n rootNodes={rootNodes}\n actions={actions}\n />\n );\n}\n"]}
1
+ {"version":3,"file":"BaseTreeRenderer.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/common/components/BaseTreeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG,uCAAuC;AAEvC,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AACzF,OAAO,EAAE,0BAA0B,EAAE,MAAM,2CAA2C,CAAC;AAKvF,gBAAgB;AAChB,MAAM,UAAU,gBAAgB,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,KAAK,EAAyB;IACrG,MAAM,gBAAgB,GAAG,0BAA0B,EAAE,CAAC;IACtD,OAAO,KAAC,gBAAgB,OAAK,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,GAAI,CAAC;AACnJ,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/* eslint-disable @itwin/no-internal */\n\nimport { TreeRenderer as PresentationTree } from \"@itwin/presentation-hierarchies-react\";\nimport { useHierarchiesLocalization } from \"../internal/UseHierarchiesLocalization.js\";\n\n/** @beta */\nexport type BaseTreeRendererProps = React.ComponentPropsWithoutRef<typeof PresentationTree>;\n\n/** @internal */\nexport function BaseTreeRenderer({ rootNodes, expandNode, getActions, ...props }: BaseTreeRendererProps) {\n const localizedStrings = useHierarchiesLocalization();\n return <PresentationTree {...props} localizedStrings={localizedStrings} expandNode={expandNode} rootNodes={rootNodes} getActions={getActions} />;\n}\n"]}
@@ -1,10 +1,10 @@
1
1
  import "./Tree.css";
2
- import type { BaseTreeRendererProps } from "./BaseTreeRenderer.js";
3
- import type { FunctionProps } from "../Utils.js";
4
2
  import type { ReactNode } from "react";
5
3
  import type { IModelConnection } from "@itwin/core-frontend";
6
4
  import type { SchemaContext } from "@itwin/ecschema-metadata";
7
5
  import type { PresentationHierarchyNode, SelectionStorage, useIModelTree, useSelectionHandler } from "@itwin/presentation-hierarchies-react";
6
+ import type { FunctionProps } from "../Utils.js";
7
+ import type { BaseTreeRendererProps } from "./BaseTreeRenderer.js";
8
8
  import type { HighlightInfo } from "../UseNodeHighlighting.js";
9
9
  /** @beta */
10
10
  export type TreeProps = Pick<FunctionProps<typeof useIModelTree>, "getFilteredPaths" | "getHierarchyDefinition"> & Partial<Pick<FunctionProps<typeof useSelectionHandler>, "selectionMode">> & {
@@ -22,7 +22,7 @@ export type TreeProps = Pick<FunctionProps<typeof useIModelTree>, "getFilteredPa
22
22
  */
23
23
  selectionPredicate?: (node: PresentationHierarchyNode) => boolean;
24
24
  /** Tree renderer that should be used to render tree data. */
25
- treeRenderer: (treeProps: Required<Pick<BaseTreeRendererProps, "rootNodes" | "expandNode" | "getLabel" | "onFilterClick" | "selectNodes" | "selectionMode" | "isNodeSelected" | "getHierarchyLevelDetails" | "getLabel">>) => ReactNode;
25
+ treeRenderer: (treeProps: Required<Pick<BaseTreeRendererProps, "rootNodes" | "reloadTree" | "expandNode" | "getLabel" | "onFilterClick" | "selectNodes" | "selectionMode" | "isNodeSelected" | "getHierarchyLevelDetails" | "getLabel">>) => ReactNode;
26
26
  /** Custom iModel access that is stored outside tree component. If not provided it new iModel access will be created using `imodel` prop. */
27
27
  imodelAccess?: FunctionProps<typeof useIModelTree>["imodelAccess"];
28
28
  /** Size limit that should be applied on each hierarchy level. Default to `1000`. */
@@ -8,12 +8,14 @@ import { useCallback, useMemo, useState } from "react";
8
8
  import { BeEvent } from "@itwin/core-bentley";
9
9
  import { SchemaMetadataContextProvider } from "@itwin/presentation-components";
10
10
  import { useIModelUnifiedSelectionTree } from "@itwin/presentation-hierarchies-react";
11
+ import { TreeWidget } from "../../../../TreeWidget.js";
11
12
  import { useHierarchiesLocalization } from "../internal/UseHierarchiesLocalization.js";
12
13
  import { useHierarchyLevelFiltering } from "../internal/UseHierarchyFiltering.js";
13
14
  import { useIModelChangeListener } from "../internal/UseIModelChangeListener.js";
14
15
  import { createIModelAccess } from "../internal/Utils.js";
15
16
  import { useNodeHighlighting } from "../UseNodeHighlighting.js";
16
17
  import { useReportingAction, useTelemetryContext } from "../UseTelemetryContext.js";
18
+ import { LOGGING_NAMESPACE } from "../Utils.js";
17
19
  import { Delayed } from "./Delayed.js";
18
20
  import { EmptyTreeContent } from "./EmptyTree.js";
19
21
  import { ProgressOverlay } from "./ProgressOverlay.js";
@@ -25,8 +27,9 @@ import { SkeletonTree } from "./SkeletonTree.js";
25
27
  export function Tree({ getSchemaContext, hierarchyLevelSizeLimit, selectionStorage, imodelAccess: providedIModelAccess, ...props }) {
26
28
  const defaultHierarchyLevelSizeLimit = hierarchyLevelSizeLimit ?? 1000;
27
29
  const imodelAccess = useMemo(() => {
30
+ TreeWidget.logger.logInfo(`${LOGGING_NAMESPACE}.${props.treeName}`, `iModel changed, now using ${providedIModelAccess ? "provided imodel access" : `"${props.imodel.name}"`}`);
28
31
  return providedIModelAccess ?? createIModelAccess({ getSchemaContext, imodel: props.imodel });
29
- }, [providedIModelAccess, getSchemaContext, props.imodel]);
32
+ }, [providedIModelAccess, getSchemaContext, props.imodel, props.treeName]);
30
33
  return (_jsx(SchemaMetadataContextProvider, { imodel: props.imodel, schemaContextProvider: getSchemaContext, children: _jsx(TreeImpl, { ...props, selectionStorage: selectionStorage, imodelAccess: imodelAccess, defaultHierarchyLevelSizeLimit: defaultHierarchyLevelSizeLimit }) }));
31
34
  }
32
35
  function TreeImpl({ imodel, imodelAccess, treeName, emptyTreeContent, getFilteredPaths, defaultHierarchyLevelSizeLimit, getHierarchyDefinition, selectionPredicate, selectionMode, onReload, treeRenderer, selectionStorage, highlight, }) {
@@ -54,7 +57,13 @@ function TreeImpl({ imodel, imodelAccess, treeName, emptyTreeContent, getFiltere
54
57
  onFeatureUsed({ featureId: `error-${type}`, reportInteraction: false });
55
58
  },
56
59
  });
57
- useIModelChangeListener({ imodel, action: useCallback(() => imodelChanged.raiseEvent(), [imodelChanged]) });
60
+ useIModelChangeListener({
61
+ imodel,
62
+ action: useCallback(() => {
63
+ TreeWidget.logger.logTrace(`${LOGGING_NAMESPACE}.${treeName}`, `iModel data changed`);
64
+ imodelChanged.raiseEvent();
65
+ }, [imodelChanged, treeName]),
66
+ });
58
67
  const selectNodes = useSelectionPredicate({
59
68
  action: useReportingAction({ action: selectNodesAction }),
60
69
  predicate: selectionPredicate,
@@ -1 +1 @@
1
- {"version":3,"file":"Tree.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/common/components/Tree.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,YAAY,CAAC;AACpB,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,EAAE,6BAA6B,EAAE,MAAM,uCAAuC,CAAC;AACtF,OAAO,EAAE,0BAA0B,EAAE,MAAM,2CAA2C,CAAC;A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B,aAC1E,YAAY,CAAC,iBAAiB,CAAC,EAC/B,eAAe,IACZ,EACN,KAAC,OAAO,IAAC,IAAI,EAAE,SAAS,YACtB,KAAC,eAAe,KAAG,GACX,IACN,CACP,CAAC;AACJ,CAAC;AAED,SAAS,qBAAqB,CAAC,EAC7B,MAAM,EACN,SAAS,EACT,OAAO,GAKR;IACC,OAAO,WAAW,CAChB,CAAC,OAAO,EAAE,UAAU,EAAE,EAAE,CACtB,MAAM,CACJ,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE;QACxB,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7B,OAAO,IAAI,IAAI,CAAC,CAAC,SAAS,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;IACjD,CAAC,CAAC,EACF,UAAU,CACX,EACH,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,CAC7B,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 \"./Tree.css\";\nimport { useCallback, useMemo, useState } from \"react\";\nimport { BeEvent } from \"@itwin/core-bentley\";\nimport { SchemaMetadataContextProvider } from \"@itwin/presentation-components\";\nimport { useIModelUnifiedSelectionTree } from \"@itwin/presentation-hierarchies-react\";\nimport { useHierarchiesLocalization } from \"../internal/UseHierarchiesLocalization.js\";\nimport { useHierarchyLevelFiltering } from \"../internal/UseHierarchyFiltering.js\";\nimport { useIModelChangeListener } from \"../internal/UseIModelChangeListener.js\";\nimport { createIModelAccess } from \"../internal/Utils.js\";\nimport { useNodeHighlighting } from \"../UseNodeHighlighting.js\";\nimport { useReportingAction, useTelemetryContext } from \"../UseTelemetryContext.js\";\nimport { Delayed } from \"./Delayed.js\";\nimport { EmptyTreeContent } from \"./EmptyTree.js\";\nimport { ProgressOverlay } from \"./ProgressOverlay.js\";\nimport { SkeletonTree } from \"./SkeletonTree.js\";\n\nimport type { BaseTreeRendererProps } from \"./BaseTreeRenderer.js\";\nimport type { MarkRequired } from \"@itwin/core-bentley\";\nimport type { FunctionProps } from \"../Utils.js\";\nimport type { ReactNode } from \"react\";\nimport type { IModelConnection } from \"@itwin/core-frontend\";\nimport type { SchemaContext } from \"@itwin/ecschema-metadata\";\nimport type { PresentationHierarchyNode, SelectionStorage, useIModelTree, useSelectionHandler } from \"@itwin/presentation-hierarchies-react\";\nimport type { HighlightInfo } from \"../UseNodeHighlighting.js\";\n\n/** @beta */\nexport type TreeProps = Pick<FunctionProps<typeof useIModelTree>, \"getFilteredPaths\" | \"getHierarchyDefinition\"> &\n Partial<Pick<FunctionProps<typeof useSelectionHandler>, \"selectionMode\">> & {\n /** iModel connection that should be used to pull data from. */\n imodel: IModelConnection;\n /** Callback for getting `SchemaContext` for specific iModel. */\n getSchemaContext: (imodel: IModelConnection) => SchemaContext;\n /** Unique tree component name that will be used as unified selection change event source when selecting node. */\n treeName: string;\n /** Unified selection storage that should be used by tree to handle tree selection changes. */\n selectionStorage: SelectionStorage;\n /**\n * An optional predicate to allow or prohibit selection of a node.\n * When not supplied, all nodes are selectable.\n */\n selectionPredicate?: (node: PresentationHierarchyNode) => boolean;\n /** Tree renderer that should be used to render tree data. */\n treeRenderer: (\n treeProps: Required<\n Pick<\n BaseTreeRendererProps,\n | \"rootNodes\"\n | \"expandNode\"\n | \"getLabel\"\n | \"onFilterClick\"\n | \"selectNodes\"\n | \"selectionMode\"\n | \"isNodeSelected\"\n | \"getHierarchyLevelDetails\"\n | \"getLabel\"\n >\n >,\n ) => ReactNode;\n /** Custom iModel access that is stored outside tree component. If not provided it new iModel access will be created using `imodel` prop. */\n imodelAccess?: FunctionProps<typeof useIModelTree>[\"imodelAccess\"];\n /** Size limit that should be applied on each hierarchy level. Default to `1000`. */\n hierarchyLevelSizeLimit?: number;\n /** Component that should be renderer if there are no tree nodes. */\n emptyTreeContent?: ReactNode;\n /** Callback that this invoked when tree reloads. */\n onReload?: () => void;\n /** Options for highlighting node labels. */\n highlight?: HighlightInfo;\n };\n\n/**\n * Default tree component that manages tree state and renders using supplied `treeRenderer`.\n * @beta\n */\nexport function Tree({ getSchemaContext, hierarchyLevelSizeLimit, selectionStorage, imodelAccess: providedIModelAccess, ...props }: TreeProps) {\n const defaultHierarchyLevelSizeLimit = hierarchyLevelSizeLimit ?? 1000;\n\n const imodelAccess = useMemo(() => {\n return providedIModelAccess ?? createIModelAccess({ getSchemaContext, imodel: props.imodel });\n }, [providedIModelAccess, getSchemaContext, props.imodel]);\n\n return (\n <SchemaMetadataContextProvider imodel={props.imodel} schemaContextProvider={getSchemaContext}>\n <TreeImpl {...props} selectionStorage={selectionStorage} imodelAccess={imodelAccess} defaultHierarchyLevelSizeLimit={defaultHierarchyLevelSizeLimit} />\n </SchemaMetadataContextProvider>\n );\n}\n\nfunction TreeImpl({\n imodel,\n imodelAccess,\n treeName,\n emptyTreeContent,\n getFilteredPaths,\n defaultHierarchyLevelSizeLimit,\n getHierarchyDefinition,\n selectionPredicate,\n selectionMode,\n onReload,\n treeRenderer,\n selectionStorage,\n highlight,\n}: MarkRequired<Omit<TreeProps, \"getSchemaContext\">, \"imodelAccess\"> & { defaultHierarchyLevelSizeLimit: number }) {\n const localizedStrings = useHierarchiesLocalization();\n const { onFeatureUsed, onPerformanceMeasured } = useTelemetryContext();\n const [imodelChanged] = useState(new BeEvent<() => void>());\n const {\n rootNodes,\n getNode,\n isLoading,\n selectNodes: selectNodesAction,\n setFormatter: _setFormatter,\n expandNode,\n ...treeProps\n } = useIModelUnifiedSelectionTree({\n imodelAccess,\n imodelChanged,\n getHierarchyDefinition,\n getFilteredPaths,\n sourceName: treeName,\n localizedStrings,\n selectionStorage,\n onPerformanceMeasured: (action, duration) => {\n if (action === \"reload\") {\n onReload?.();\n }\n onPerformanceMeasured(action, duration);\n },\n onHierarchyLimitExceeded: () => onFeatureUsed({ featureId: \"hierarchy-level-size-limit-hit\", reportInteraction: false }),\n onHierarchyLoadError: ({ type, error }) => {\n // eslint-disable-next-line no-console\n console.error(error);\n onFeatureUsed({ featureId: `error-${type}`, reportInteraction: false });\n },\n });\n useIModelChangeListener({ imodel, action: useCallback(() => imodelChanged.raiseEvent(), [imodelChanged]) });\n\n const selectNodes = useSelectionPredicate({\n action: useReportingAction({ action: selectNodesAction }),\n predicate: selectionPredicate,\n getNode,\n });\n const { filteringDialog, onFilterClick } = useHierarchyLevelFiltering({\n imodel,\n defaultHierarchyLevelSizeLimit,\n });\n const reportingExpandNode = useReportingAction({ action: expandNode });\n const reportingOnFilterClicked = useReportingAction({ action: onFilterClick });\n const { getLabel } = useNodeHighlighting({ rootNodes, highlight });\n\n if (rootNodes === undefined) {\n return <SkeletonTree />;\n }\n\n if (rootNodes.length === 0 && !isLoading) {\n return <>{emptyTreeContent ? emptyTreeContent : <EmptyTreeContent />}</>;\n }\n\n const treeRendererProps: FunctionProps<TreeProps[\"treeRenderer\"]> = {\n ...treeProps,\n rootNodes,\n selectionMode: selectionMode ?? \"single\",\n selectNodes,\n expandNode: reportingExpandNode,\n onFilterClick: reportingOnFilterClicked,\n getLabel,\n };\n\n return (\n <div style={{ position: \"relative\", height: \"100%\", overflow: \"hidden\" }}>\n <div className={\"tw-tree-renderer-container\"} id=\"tw-tree-renderer-container\">\n {treeRenderer(treeRendererProps)}\n {filteringDialog}\n </div>\n <Delayed show={isLoading}>\n <ProgressOverlay />\n </Delayed>\n </div>\n );\n}\n\nfunction useSelectionPredicate({\n action,\n predicate,\n getNode,\n}: {\n action: (...args: any[]) => void;\n predicate?: (node: PresentationHierarchyNode) => boolean;\n getNode: (nodeId: string) => PresentationHierarchyNode | undefined;\n}): ReturnType<typeof useIModelUnifiedSelectionTree>[\"selectNodes\"] {\n return useCallback(\n (nodeIds, changeType) =>\n action(\n nodeIds.filter((nodeId) => {\n const node = getNode(nodeId);\n return node && (!predicate || predicate(node));\n }),\n changeType,\n ),\n [action, getNode, predicate],\n );\n}\n"]}
1
+ {"version":3,"file":"Tree.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/common/components/Tree.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,YAAY,CAAC;AACpB,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,EAAE,6BAA6B,EAAE,MAAM,uCAAuC,CAAC;AACtF,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,0BAA0B,EAAE,MAAM,2CAA2C,CAAC;AACvF,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAClF,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AACjF,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AACpF,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAyDjD;;;GAGG;AACH,MAAM,UAAU,IAAI,CAAC,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,YAAY,EAAE,oBAAoB,EAAE,GAAG,KAAK,EAAa;IAC3I,MAAM,8BAA8B,GAAG,uBAAuB,IAAI,IAAI,CAAC;IAEvE,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,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE;QACxB,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7B,OAAO,IAAI,IAAI,CAAC,CAAC,SAAS,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;IACjD,CAAC,CAAC,EACF,UAAU,CACX,EACH,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,CAC7B,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 \"./Tree.css\";\nimport { useCallback, useMemo, useState } from \"react\";\nimport { BeEvent } from \"@itwin/core-bentley\";\nimport { SchemaMetadataContextProvider } from \"@itwin/presentation-components\";\nimport { useIModelUnifiedSelectionTree } from \"@itwin/presentation-hierarchies-react\";\nimport { TreeWidget } from \"../../../../TreeWidget.js\";\nimport { useHierarchiesLocalization } from \"../internal/UseHierarchiesLocalization.js\";\nimport { useHierarchyLevelFiltering } from \"../internal/UseHierarchyFiltering.js\";\nimport { useIModelChangeListener } from \"../internal/UseIModelChangeListener.js\";\nimport { createIModelAccess } from \"../internal/Utils.js\";\nimport { useNodeHighlighting } from \"../UseNodeHighlighting.js\";\nimport { useReportingAction, useTelemetryContext } from \"../UseTelemetryContext.js\";\nimport { LOGGING_NAMESPACE } from \"../Utils.js\";\nimport { Delayed } from \"./Delayed.js\";\nimport { EmptyTreeContent } from \"./EmptyTree.js\";\nimport { ProgressOverlay } from \"./ProgressOverlay.js\";\nimport { SkeletonTree } from \"./SkeletonTree.js\";\n\nimport type { ReactNode } from \"react\";\nimport type { MarkRequired } from \"@itwin/core-bentley\";\nimport type { IModelConnection } from \"@itwin/core-frontend\";\nimport type { SchemaContext } from \"@itwin/ecschema-metadata\";\nimport type { PresentationHierarchyNode, SelectionStorage, useIModelTree, useSelectionHandler } from \"@itwin/presentation-hierarchies-react\";\nimport type { FunctionProps } from \"../Utils.js\";\nimport type { BaseTreeRendererProps } from \"./BaseTreeRenderer.js\";\nimport type { HighlightInfo } from \"../UseNodeHighlighting.js\";\n\n/** @beta */\nexport type TreeProps = Pick<FunctionProps<typeof useIModelTree>, \"getFilteredPaths\" | \"getHierarchyDefinition\"> &\n Partial<Pick<FunctionProps<typeof useSelectionHandler>, \"selectionMode\">> & {\n /** iModel connection that should be used to pull data from. */\n imodel: IModelConnection;\n /** Callback for getting `SchemaContext` for specific iModel. */\n getSchemaContext: (imodel: IModelConnection) => SchemaContext;\n /** Unique tree component name that will be used as unified selection change event source when selecting node. */\n treeName: string;\n /** Unified selection storage that should be used by tree to handle tree selection changes. */\n selectionStorage: SelectionStorage;\n /**\n * An optional predicate to allow or prohibit selection of a node.\n * When not supplied, all nodes are selectable.\n */\n selectionPredicate?: (node: PresentationHierarchyNode) => boolean;\n /** Tree renderer that should be used to render tree data. */\n treeRenderer: (\n treeProps: Required<\n Pick<\n BaseTreeRendererProps,\n | \"rootNodes\"\n | \"reloadTree\"\n | \"expandNode\"\n | \"getLabel\"\n | \"onFilterClick\"\n | \"selectNodes\"\n | \"selectionMode\"\n | \"isNodeSelected\"\n | \"getHierarchyLevelDetails\"\n | \"getLabel\"\n >\n >,\n ) => ReactNode;\n /** Custom iModel access that is stored outside tree component. If not provided it new iModel access will be created using `imodel` prop. */\n imodelAccess?: FunctionProps<typeof useIModelTree>[\"imodelAccess\"];\n /** Size limit that should be applied on each hierarchy level. Default to `1000`. */\n hierarchyLevelSizeLimit?: number;\n /** Component that should be renderer if there are no tree nodes. */\n emptyTreeContent?: ReactNode;\n /** Callback that this invoked when tree reloads. */\n onReload?: () => void;\n /** Options for highlighting node labels. */\n highlight?: HighlightInfo;\n };\n\n/**\n * Default tree component that manages tree state and renders using supplied `treeRenderer`.\n * @beta\n */\nexport function Tree({ getSchemaContext, hierarchyLevelSizeLimit, selectionStorage, imodelAccess: providedIModelAccess, ...props }: TreeProps) {\n const defaultHierarchyLevelSizeLimit = hierarchyLevelSizeLimit ?? 1000;\n\n const imodelAccess = useMemo(() => {\n TreeWidget.logger.logInfo(\n `${LOGGING_NAMESPACE}.${props.treeName}`,\n `iModel changed, now using ${providedIModelAccess ? \"provided imodel access\" : `\"${props.imodel.name}\"`}`,\n );\n return providedIModelAccess ?? createIModelAccess({ getSchemaContext, imodel: props.imodel });\n }, [providedIModelAccess, getSchemaContext, props.imodel, props.treeName]);\n\n return (\n <SchemaMetadataContextProvider imodel={props.imodel} schemaContextProvider={getSchemaContext}>\n <TreeImpl {...props} selectionStorage={selectionStorage} imodelAccess={imodelAccess} defaultHierarchyLevelSizeLimit={defaultHierarchyLevelSizeLimit} />\n </SchemaMetadataContextProvider>\n );\n}\n\nfunction TreeImpl({\n imodel,\n imodelAccess,\n treeName,\n emptyTreeContent,\n getFilteredPaths,\n defaultHierarchyLevelSizeLimit,\n getHierarchyDefinition,\n selectionPredicate,\n selectionMode,\n onReload,\n treeRenderer,\n selectionStorage,\n highlight,\n}: MarkRequired<Omit<TreeProps, \"getSchemaContext\">, \"imodelAccess\"> & { defaultHierarchyLevelSizeLimit: number }) {\n const localizedStrings = useHierarchiesLocalization();\n const { onFeatureUsed, onPerformanceMeasured } = useTelemetryContext();\n const [imodelChanged] = useState(new BeEvent<() => void>());\n const {\n rootNodes,\n getNode,\n isLoading,\n selectNodes: selectNodesAction,\n setFormatter: _setFormatter,\n expandNode,\n ...treeProps\n } = useIModelUnifiedSelectionTree({\n imodelAccess,\n imodelChanged,\n getHierarchyDefinition,\n getFilteredPaths,\n sourceName: treeName,\n localizedStrings,\n selectionStorage,\n onPerformanceMeasured: (action, duration) => {\n if (action === \"reload\") {\n onReload?.();\n }\n onPerformanceMeasured(action, duration);\n },\n onHierarchyLimitExceeded: () => onFeatureUsed({ featureId: \"hierarchy-level-size-limit-hit\", reportInteraction: false }),\n onHierarchyLoadError: ({ type, error }) => {\n // eslint-disable-next-line no-console\n console.error(error);\n onFeatureUsed({ featureId: `error-${type}`, reportInteraction: false });\n },\n });\n useIModelChangeListener({\n imodel,\n action: useCallback(() => {\n TreeWidget.logger.logTrace(`${LOGGING_NAMESPACE}.${treeName}`, `iModel data changed`);\n imodelChanged.raiseEvent();\n }, [imodelChanged, treeName]),\n });\n\n const selectNodes = useSelectionPredicate({\n action: useReportingAction({ action: selectNodesAction }),\n predicate: selectionPredicate,\n getNode,\n });\n const { filteringDialog, onFilterClick } = useHierarchyLevelFiltering({\n imodel,\n defaultHierarchyLevelSizeLimit,\n });\n const reportingExpandNode = useReportingAction({ action: expandNode });\n const reportingOnFilterClicked = useReportingAction({ action: onFilterClick });\n const { getLabel } = useNodeHighlighting({ rootNodes, highlight });\n\n if (rootNodes === undefined) {\n return <SkeletonTree />;\n }\n\n if (rootNodes.length === 0 && !isLoading) {\n return <>{emptyTreeContent ? emptyTreeContent : <EmptyTreeContent />}</>;\n }\n\n const treeRendererProps: FunctionProps<TreeProps[\"treeRenderer\"]> = {\n ...treeProps,\n rootNodes,\n selectionMode: selectionMode ?? \"single\",\n selectNodes,\n expandNode: reportingExpandNode,\n onFilterClick: reportingOnFilterClicked,\n getLabel,\n };\n\n return (\n <div style={{ position: \"relative\", height: \"100%\", overflow: \"hidden\" }}>\n <div className={\"tw-tree-renderer-container\"} id=\"tw-tree-renderer-container\">\n {treeRenderer(treeRendererProps)}\n {filteringDialog}\n </div>\n <Delayed show={isLoading}>\n <ProgressOverlay />\n </Delayed>\n </div>\n );\n}\n\nfunction useSelectionPredicate({\n action,\n predicate,\n getNode,\n}: {\n action: (...args: any[]) => void;\n predicate?: (node: PresentationHierarchyNode) => boolean;\n getNode: (nodeId: string) => PresentationHierarchyNode | undefined;\n}): ReturnType<typeof useIModelUnifiedSelectionTree>[\"selectNodes\"] {\n return useCallback(\n (nodeIds, changeType) =>\n action(\n nodeIds.filter((nodeId) => {\n const node = getNode(nodeId);\n return node && (!predicate || predicate(node));\n }),\n changeType,\n ),\n [action, getNode, predicate],\n );\n}\n"]}
@@ -1,10 +1,11 @@
1
+ /// <reference types="react" />
1
2
  import "./TreeNodeVisibilityButton.css";
2
- import type { PresentationHierarchyNode, TreeItemAction } from "@itwin/presentation-hierarchies-react";
3
+ import type { PresentationHierarchyNode } from "@itwin/presentation-hierarchies-react";
3
4
  /**
4
5
  * Data structure that describes tree node checkbox state.
5
6
  * @beta
6
7
  */
7
- interface TreeItemVisibilityButtonState {
8
+ export interface TreeItemVisibilityButtonState {
8
9
  state: "visible" | "partial" | "hidden";
9
10
  isDisabled?: boolean;
10
11
  tooltip?: string;
@@ -17,6 +18,7 @@ export interface TreeItemVisibilityButtonProps {
17
18
  getVisibilityButtonState: (node: PresentationHierarchyNode) => TreeItemVisibilityButtonState;
18
19
  }
19
20
  /** @internal */
20
- export declare function createVisibilityAction({ getVisibilityButtonState, onVisibilityButtonClick, }: TreeItemVisibilityButtonProps): (node: PresentationHierarchyNode) => TreeItemAction;
21
- export {};
21
+ export declare const VisibilityAction: import("react").NamedExoticComponent<TreeItemVisibilityButtonProps & {
22
+ node: PresentationHierarchyNode;
23
+ }>;
22
24
  //# sourceMappingURL=TreeNodeVisibilityButton.d.ts.map
@@ -1,33 +1,28 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
1
2
  /*---------------------------------------------------------------------------------------------
2
3
  * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
4
  * See LICENSE.md in the project root for license terms and full copyright notice.
4
5
  *--------------------------------------------------------------------------------------------*/
5
6
  import "./TreeNodeVisibilityButton.css";
6
- const visibilityHideSvg = new URL("@itwin/itwinui-icons/visibility-hide.svg", import.meta.url).href;
7
- const visibilityPartialSvg = new URL("@itwin/itwinui-icons/visibility-partial.svg", import.meta.url).href;
8
- const visibilityShowSvg = new URL("@itwin/itwinui-icons/visibility-show.svg", import.meta.url).href;
7
+ import { memo } from "react";
8
+ import visibilityHideSvg from "@itwin/itwinui-icons/visibility-hide.svg";
9
+ import visibilityPartialSvg from "@itwin/itwinui-icons/visibility-partial.svg";
10
+ import visibilityShowSvg from "@itwin/itwinui-icons/visibility-show.svg";
11
+ import { Tree } from "@itwin/itwinui-react/bricks";
12
+ import { createTooltip } from "../internal/Tooltip.js";
9
13
  /** @internal */
10
- export function createVisibilityAction({ getVisibilityButtonState, onVisibilityButtonClick, }) {
11
- return (node) => {
12
- const state = getVisibilityButtonState(node);
13
- const getIcon = () => {
14
- switch (state.state) {
15
- case "visible":
16
- return visibilityShowSvg;
17
- case "hidden":
18
- return visibilityHideSvg;
19
- case "partial":
20
- return visibilityPartialSvg;
21
- }
22
- };
23
- return {
24
- label: state.tooltip ?? "Determining visibility...",
25
- action: () => {
26
- onVisibilityButtonClick(node, state.state);
27
- },
28
- show: state.state !== "visible" ? true : undefined,
29
- icon: getIcon(),
30
- };
14
+ export const VisibilityAction = memo(function VisibilityAction({ getVisibilityButtonState, onVisibilityButtonClick, node, }) {
15
+ const state = getVisibilityButtonState(node);
16
+ const getIcon = () => {
17
+ switch (state.state) {
18
+ case "visible":
19
+ return visibilityShowSvg;
20
+ case "hidden":
21
+ return visibilityHideSvg;
22
+ case "partial":
23
+ return visibilityPartialSvg;
24
+ }
31
25
  };
32
- }
26
+ return (_jsx(Tree.ItemAction, { label: state.tooltip ?? createTooltip(state.state), onClick: () => onVisibilityButtonClick(node, state.state), visible: state.state !== "visible" ? true : undefined, icon: getIcon() }));
27
+ });
33
28
  //# sourceMappingURL=TreeNodeVisibilityButton.js.map