@itwin/tree-widget-react 1.2.2 → 2.0.0-dev.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/CHANGELOG.md +2 -2
  2. package/README.md +1 -1
  3. package/lib/cjs/TreeWidget.d.ts +0 -1
  4. package/lib/cjs/TreeWidget.js +9 -10
  5. package/lib/cjs/TreeWidget.js.map +1 -1
  6. package/lib/cjs/components/SelectableTree.js +24 -13
  7. package/lib/cjs/components/SelectableTree.js.map +1 -1
  8. package/lib/cjs/components/TreeFilteringState.js +3 -3
  9. package/lib/cjs/components/TreeFilteringState.js.map +1 -1
  10. package/lib/cjs/components/TreeWidgetUiItemsProvider.js +7 -5
  11. package/lib/cjs/components/TreeWidgetUiItemsProvider.js.map +1 -1
  12. package/lib/cjs/components/TreeWidgetUiItemsProvider.scss +1 -1
  13. package/lib/cjs/components/tree-header/TreeHeader.js +15 -12
  14. package/lib/cjs/components/tree-header/TreeHeader.js.map +1 -1
  15. package/lib/cjs/components/tree-header/TreeHeader.scss +1 -1
  16. package/lib/cjs/components/trees/CategoriesVisibilityUtils.js +13 -8
  17. package/lib/cjs/components/trees/CategoriesVisibilityUtils.js.map +1 -1
  18. package/lib/cjs/components/trees/VisibilityTreeBase.scss +1 -1
  19. package/lib/cjs/components/trees/VisibilityTreeEventHandler.d.ts +1 -1
  20. package/lib/cjs/components/trees/VisibilityTreeEventHandler.js +18 -10
  21. package/lib/cjs/components/trees/VisibilityTreeEventHandler.js.map +1 -1
  22. package/lib/cjs/components/trees/VisibilityTreeRenderer.d.ts +20 -4
  23. package/lib/cjs/components/trees/VisibilityTreeRenderer.js +28 -10
  24. package/lib/cjs/components/trees/VisibilityTreeRenderer.js.map +1 -1
  25. package/lib/cjs/components/trees/category-tree/CategoriesTree.d.ts +7 -2
  26. package/lib/cjs/components/trees/category-tree/CategoriesTree.js +47 -30
  27. package/lib/cjs/components/trees/category-tree/CategoriesTree.js.map +1 -1
  28. package/lib/cjs/components/trees/category-tree/CategoriesTreeComponent.js +14 -10
  29. package/lib/cjs/components/trees/category-tree/CategoriesTreeComponent.js.map +1 -1
  30. package/lib/cjs/components/trees/category-tree/CategoryVisibilityHandler.js +18 -13
  31. package/lib/cjs/components/trees/category-tree/CategoryVisibilityHandler.js.map +1 -1
  32. package/lib/cjs/components/trees/common/ContextMenu.js +4 -4
  33. package/lib/cjs/components/trees/common/ContextMenu.js.map +1 -1
  34. package/lib/cjs/components/trees/common/TreeNodeRenderer.d.ts +1 -1
  35. package/lib/cjs/components/trees/common/TreeNodeRenderer.js +4 -4
  36. package/lib/cjs/components/trees/common/TreeNodeRenderer.js.map +1 -1
  37. package/lib/cjs/components/trees/common/TreeRenderer.d.ts +15 -1
  38. package/lib/cjs/components/trees/common/TreeRenderer.js +17 -7
  39. package/lib/cjs/components/trees/common/TreeRenderer.js.map +1 -1
  40. package/lib/cjs/components/trees/common/TreeRenderer.scss +7 -2
  41. package/lib/cjs/components/trees/common/Types.d.ts +8 -0
  42. package/lib/cjs/components/trees/common/Types.js +3 -3
  43. package/lib/cjs/components/trees/common/Types.js.map +1 -1
  44. package/lib/cjs/components/trees/common/UseVisibilityTreeState.d.ts +36 -0
  45. package/lib/cjs/components/trees/common/UseVisibilityTreeState.js +47 -0
  46. package/lib/cjs/components/trees/common/UseVisibilityTreeState.js.map +1 -0
  47. package/lib/cjs/components/trees/common/Utils.js +7 -5
  48. package/lib/cjs/components/trees/common/Utils.js.map +1 -1
  49. package/lib/cjs/components/trees/external-sources-tree/ExternalSources.json +1 -3
  50. package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTree.d.ts +9 -3
  51. package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTree.js +19 -7
  52. package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTree.js.map +1 -1
  53. package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js +4 -4
  54. package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js.map +1 -1
  55. package/lib/cjs/components/trees/imodel-content-tree/IModelContentTree.d.ts +9 -3
  56. package/lib/cjs/components/trees/imodel-content-tree/IModelContentTree.js +16 -12
  57. package/lib/cjs/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -1
  58. package/lib/cjs/components/trees/imodel-content-tree/IModelContentTreeComponent.js +6 -5
  59. package/lib/cjs/components/trees/imodel-content-tree/IModelContentTreeComponent.js.map +1 -1
  60. package/lib/cjs/components/trees/index.js +3 -3
  61. package/lib/cjs/components/trees/index.js.map +1 -1
  62. package/lib/cjs/components/trees/models-tree/ModelsTree.d.ts +7 -2
  63. package/lib/cjs/components/trees/models-tree/ModelsTree.js +76 -62
  64. package/lib/cjs/components/trees/models-tree/ModelsTree.js.map +1 -1
  65. package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.js +11 -18
  66. package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
  67. package/lib/cjs/components/trees/models-tree/ModelsTreeEventHandler.d.ts +9 -0
  68. package/lib/cjs/components/trees/models-tree/ModelsTreeEventHandler.js +31 -0
  69. package/lib/cjs/components/trees/models-tree/ModelsTreeEventHandler.js.map +1 -0
  70. package/lib/cjs/components/trees/models-tree/ModelsVisibilityHandler.js +125 -66
  71. package/lib/cjs/components/trees/models-tree/ModelsVisibilityHandler.js.map +1 -1
  72. package/lib/cjs/components/trees/models-tree/Utils.d.ts +4 -0
  73. package/lib/cjs/components/trees/models-tree/Utils.js +52 -58
  74. package/lib/cjs/components/trees/models-tree/Utils.js.map +1 -1
  75. package/lib/cjs/components/utils/AutoSizer.js +7 -5
  76. package/lib/cjs/components/utils/AutoSizer.js.map +1 -1
  77. package/lib/cjs/components/utils/IsPromiseLike.js +4 -4
  78. package/lib/cjs/components/utils/IsPromiseLike.js.map +1 -1
  79. package/lib/cjs/components/utils/UseTreeTransientState.js +3 -3
  80. package/lib/cjs/components/utils/UseTreeTransientState.js.map +1 -1
  81. package/lib/cjs/e2e-tests/TreeWidget.test.js +53 -0
  82. package/lib/cjs/e2e-tests/TreeWidget.test.js.map +1 -1
  83. package/lib/cjs/e2e-tests/utils.d.ts +1 -0
  84. package/lib/cjs/e2e-tests/utils.js +4 -5
  85. package/lib/cjs/e2e-tests/utils.js.map +1 -1
  86. package/lib/cjs/tree-widget-react.js +3 -3
  87. package/lib/cjs/tree-widget-react.js.map +1 -1
  88. package/lib/esm/TreeWidget.d.ts +0 -1
  89. package/lib/esm/TreeWidget.js +9 -10
  90. package/lib/esm/TreeWidget.js.map +1 -1
  91. package/lib/esm/components/SelectableTree.js +24 -13
  92. package/lib/esm/components/SelectableTree.js.map +1 -1
  93. package/lib/esm/components/TreeFilteringState.js +3 -3
  94. package/lib/esm/components/TreeFilteringState.js.map +1 -1
  95. package/lib/esm/components/TreeWidgetUiItemsProvider.js +7 -5
  96. package/lib/esm/components/TreeWidgetUiItemsProvider.js.map +1 -1
  97. package/lib/esm/components/TreeWidgetUiItemsProvider.scss +1 -1
  98. package/lib/esm/components/tree-header/TreeHeader.js +15 -12
  99. package/lib/esm/components/tree-header/TreeHeader.js.map +1 -1
  100. package/lib/esm/components/tree-header/TreeHeader.scss +1 -1
  101. package/lib/esm/components/trees/CategoriesVisibilityUtils.js +13 -8
  102. package/lib/esm/components/trees/CategoriesVisibilityUtils.js.map +1 -1
  103. package/lib/esm/components/trees/VisibilityTreeBase.scss +1 -1
  104. package/lib/esm/components/trees/VisibilityTreeEventHandler.d.ts +1 -1
  105. package/lib/esm/components/trees/VisibilityTreeEventHandler.js +18 -10
  106. package/lib/esm/components/trees/VisibilityTreeEventHandler.js.map +1 -1
  107. package/lib/esm/components/trees/VisibilityTreeRenderer.d.ts +20 -4
  108. package/lib/esm/components/trees/VisibilityTreeRenderer.js +27 -10
  109. package/lib/esm/components/trees/VisibilityTreeRenderer.js.map +1 -1
  110. package/lib/esm/components/trees/category-tree/CategoriesTree.d.ts +7 -2
  111. package/lib/esm/components/trees/category-tree/CategoriesTree.js +51 -34
  112. package/lib/esm/components/trees/category-tree/CategoriesTree.js.map +1 -1
  113. package/lib/esm/components/trees/category-tree/CategoriesTreeComponent.js +14 -10
  114. package/lib/esm/components/trees/category-tree/CategoriesTreeComponent.js.map +1 -1
  115. package/lib/esm/components/trees/category-tree/CategoryVisibilityHandler.js +18 -13
  116. package/lib/esm/components/trees/category-tree/CategoryVisibilityHandler.js.map +1 -1
  117. package/lib/esm/components/trees/common/ContextMenu.js +4 -4
  118. package/lib/esm/components/trees/common/ContextMenu.js.map +1 -1
  119. package/lib/esm/components/trees/common/TreeNodeRenderer.d.ts +1 -1
  120. package/lib/esm/components/trees/common/TreeNodeRenderer.js +4 -4
  121. package/lib/esm/components/trees/common/TreeNodeRenderer.js.map +1 -1
  122. package/lib/esm/components/trees/common/TreeRenderer.d.ts +15 -1
  123. package/lib/esm/components/trees/common/TreeRenderer.js +15 -6
  124. package/lib/esm/components/trees/common/TreeRenderer.js.map +1 -1
  125. package/lib/esm/components/trees/common/TreeRenderer.scss +7 -2
  126. package/lib/esm/components/trees/common/Types.d.ts +8 -0
  127. package/lib/esm/components/trees/common/Types.js +3 -3
  128. package/lib/esm/components/trees/common/Types.js.map +1 -1
  129. package/lib/esm/components/trees/common/UseVisibilityTreeState.d.ts +36 -0
  130. package/lib/esm/components/trees/common/UseVisibilityTreeState.js +43 -0
  131. package/lib/esm/components/trees/common/UseVisibilityTreeState.js.map +1 -0
  132. package/lib/esm/components/trees/common/Utils.js +7 -5
  133. package/lib/esm/components/trees/common/Utils.js.map +1 -1
  134. package/lib/esm/components/trees/external-sources-tree/ExternalSources.json +1 -3
  135. package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTree.d.ts +9 -3
  136. package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTree.js +22 -10
  137. package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTree.js.map +1 -1
  138. package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js +4 -4
  139. package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js.map +1 -1
  140. package/lib/esm/components/trees/imodel-content-tree/IModelContentTree.d.ts +9 -3
  141. package/lib/esm/components/trees/imodel-content-tree/IModelContentTree.js +19 -15
  142. package/lib/esm/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -1
  143. package/lib/esm/components/trees/imodel-content-tree/IModelContentTreeComponent.js +6 -5
  144. package/lib/esm/components/trees/imodel-content-tree/IModelContentTreeComponent.js.map +1 -1
  145. package/lib/esm/components/trees/index.js +3 -3
  146. package/lib/esm/components/trees/index.js.map +1 -1
  147. package/lib/esm/components/trees/models-tree/ModelsTree.d.ts +7 -2
  148. package/lib/esm/components/trees/models-tree/ModelsTree.js +80 -66
  149. package/lib/esm/components/trees/models-tree/ModelsTree.js.map +1 -1
  150. package/lib/esm/components/trees/models-tree/ModelsTreeComponent.js +12 -19
  151. package/lib/esm/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
  152. package/lib/esm/components/trees/models-tree/ModelsTreeEventHandler.d.ts +9 -0
  153. package/lib/esm/components/trees/models-tree/ModelsTreeEventHandler.js +27 -0
  154. package/lib/esm/components/trees/models-tree/ModelsTreeEventHandler.js.map +1 -0
  155. package/lib/esm/components/trees/models-tree/ModelsVisibilityHandler.js +125 -66
  156. package/lib/esm/components/trees/models-tree/ModelsVisibilityHandler.js.map +1 -1
  157. package/lib/esm/components/trees/models-tree/Utils.d.ts +4 -0
  158. package/lib/esm/components/trees/models-tree/Utils.js +50 -57
  159. package/lib/esm/components/trees/models-tree/Utils.js.map +1 -1
  160. package/lib/esm/components/utils/AutoSizer.js +7 -5
  161. package/lib/esm/components/utils/AutoSizer.js.map +1 -1
  162. package/lib/esm/components/utils/IsPromiseLike.js +4 -4
  163. package/lib/esm/components/utils/IsPromiseLike.js.map +1 -1
  164. package/lib/esm/components/utils/UseTreeTransientState.js +3 -3
  165. package/lib/esm/components/utils/UseTreeTransientState.js.map +1 -1
  166. package/lib/esm/e2e-tests/TreeWidget.test.js +54 -1
  167. package/lib/esm/e2e-tests/TreeWidget.test.js.map +1 -1
  168. package/lib/esm/e2e-tests/utils.d.ts +1 -0
  169. package/lib/esm/e2e-tests/utils.js +2 -4
  170. package/lib/esm/e2e-tests/utils.js.map +1 -1
  171. package/lib/esm/tree-widget-react.js +3 -3
  172. package/lib/esm/tree-widget-react.js.map +1 -1
  173. package/package.json +47 -46
@@ -1,8 +1,8 @@
1
1
  /// <reference types="react" />
2
- import type { TreeRendererBaseProps } from "./common/TreeRenderer";
3
- import type { AbstractTreeNodeLoaderWithProvider, TreeNodeRendererProps, TreeRendererProps } from "@itwin/components-react";
4
2
  import type { NodeCheckboxRenderProps } from "@itwin/core-react";
5
- import type { IPresentationTreeDataProvider } from "@itwin/presentation-components";
3
+ import type { TreeRendererBaseProps, TreeRendererProps } from "./common/TreeRenderer";
4
+ import type { AbstractTreeNodeLoaderWithProvider, TreeNodeRendererProps } from "@itwin/components-react";
5
+ import type { IPresentationTreeDataProvider, PresentationTreeNodeRendererProps } from "@itwin/presentation-components";
6
6
  import type { VisibilityTreeFilterInfo } from "./common/Types";
7
7
  /**
8
8
  * Props for visibility tree renderer.
@@ -35,6 +35,11 @@ export interface VisibilityTreeNodeRendererProps {
35
35
  * Defaults to `false`.
36
36
  */
37
37
  disableRootNodeCollapse?: boolean;
38
+ /**
39
+ * Specifies whether the nodes should be enlarged (less dense and larger content).
40
+ * Is `false` by default
41
+ */
42
+ isEnlarged?: boolean;
38
43
  }
39
44
  /**
40
45
  * Creates Visibility tree renderer which renders nodes with eye checkbox.
@@ -45,15 +50,26 @@ export declare function createVisibilityTreeRenderer({ nodeRendererProps, ...res
45
50
  * Creates node renderer which renders node with eye checkbox.
46
51
  * @public
47
52
  */
48
- export declare function createVisibilityTreeNodeRenderer({ levelOffset, disableRootNodeCollapse, descriptionEnabled, iconsEnabled }: VisibilityTreeNodeRendererProps): (treeNodeProps: TreeNodeRendererProps) => JSX.Element;
53
+ export declare function createVisibilityTreeNodeRenderer({ levelOffset, disableRootNodeCollapse, descriptionEnabled, iconsEnabled, }: VisibilityTreeNodeRendererProps): (treeNodeProps: TreeNodeRendererProps) => JSX.Element;
49
54
  /**
50
55
  * Checkbox renderer that renders an eye.
51
56
  * @public
52
57
  */
53
58
  export declare function VisibilityTreeNodeCheckbox(props: NodeCheckboxRenderProps): JSX.Element;
59
+ /**
60
+ * Props for [[FilterableVisibilityTreeNodeRenderer]].
61
+ * @beta
62
+ */
63
+ export type FilterableVisibilityTreeNodeRendererProps = Omit<PresentationTreeNodeRendererProps, "descriptionEnabled"> & VisibilityTreeNodeRendererProps;
64
+ /**
65
+ * Creates node renderer which renders node with eye checkbox and hierarchy level filtering actions.
66
+ * @beta
67
+ */
68
+ export declare function FilterableVisibilityTreeNodeRenderer({ levelOffset, disableRootNodeCollapse, descriptionEnabled, isEnlarged, ...restProps }: FilterableVisibilityTreeNodeRendererProps): JSX.Element;
54
69
  /**
55
70
  * Filters data provider used in supplied node loader and invokes onFilterApplied when filtering is completed.
56
71
  * @public
72
+ * @deprecated in 2.0.0. Use [[useVisibilityTree]] instead.
57
73
  */
58
74
  export declare function useVisibilityTreeFiltering(nodeLoader: AbstractTreeNodeLoaderWithProvider<IPresentationTreeDataProvider>, filterInfo?: VisibilityTreeFilterInfo, onFilterApplied?: (filteredDataProvider: IPresentationTreeDataProvider, matchesCount: number) => void): {
59
75
  filteredNodeLoader: AbstractTreeNodeLoaderWithProvider<IPresentationTreeDataProvider>;
@@ -1,21 +1,23 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
6
  import classNames from "classnames";
7
7
  import { useEffect } from "react";
8
8
  import { TreeImageLoader, TreeNodeRenderer } from "@itwin/components-react";
9
9
  import { Checkbox } from "@itwin/itwinui-react";
10
- import { useControlledPresentationTreeFiltering } from "@itwin/presentation-components";
10
+ import { PresentationTreeNodeRenderer, useControlledPresentationTreeFiltering } from "@itwin/presentation-components";
11
11
  import { TreeRenderer } from "./common/TreeRenderer";
12
12
  /**
13
- * This constant is taken from `@itwin/core-react`.
13
+ * These constants are taken from `@itwin/core-react`.
14
14
  * Defines the size in pixels of the expansion toggle.
15
15
  * It is used to keep same hierarchy nodes with children and nodes without children in the same line.
16
16
  * @note This value applies only to the leaf nodes.
17
17
  */
18
18
  const EXPANSION_TOGGLE_WIDTH = 24;
19
+ const EXPANDED_EXPANSION_TOGGLE_WIDTH = 42;
20
+ const imageLoader = new TreeImageLoader();
19
21
  /**
20
22
  * Creates Visibility tree renderer which renders nodes with eye checkbox.
21
23
  * @public
@@ -25,12 +27,11 @@ export function createVisibilityTreeRenderer({ nodeRendererProps, ...restProps }
25
27
  return _jsx(TreeRenderer, { ...treeProps, ...restProps, nodeRenderer: createVisibilityTreeNodeRenderer(nodeRendererProps) });
26
28
  };
27
29
  }
28
- const imageLoader = new TreeImageLoader();
29
30
  /**
30
31
  * Creates node renderer which renders node with eye checkbox.
31
32
  * @public
32
33
  */
33
- export function createVisibilityTreeNodeRenderer({ levelOffset = 20, disableRootNodeCollapse = false, descriptionEnabled, iconsEnabled }) {
34
+ export function createVisibilityTreeNodeRenderer({ levelOffset = 20, disableRootNodeCollapse = false, descriptionEnabled, iconsEnabled, }) {
34
35
  return function VisibilityTreeNodeRenderer(treeNodeProps) {
35
36
  const nodeOffset = treeNodeProps.node.depth * levelOffset + (treeNodeProps.node.numChildren === 0 ? EXPANSION_TOGGLE_WIDTH : 0);
36
37
  return (_jsx(TreeNodeRenderer, { ...treeNodeProps, node: { ...treeNodeProps.node, depth: 0, numChildren: 1 }, checkboxRenderer: (checkboxProps) => (_jsx("div", { className: "visibility-tree-checkbox-container", style: { marginRight: `${nodeOffset}px` }, children: _jsx(VisibilityTreeNodeCheckbox, { ...checkboxProps }) })), descriptionEnabled: descriptionEnabled, imageLoader: iconsEnabled ? imageLoader : undefined, className: classNames("with-checkbox", (treeNodeProps.node.numChildren === 0 || (disableRootNodeCollapse && treeNodeProps.node.parentId === undefined)) && "disable-expander", treeNodeProps.className) }));
@@ -41,18 +42,34 @@ export function createVisibilityTreeNodeRenderer({ levelOffset = 20, disableRoot
41
42
  * @public
42
43
  */
43
44
  export function VisibilityTreeNodeCheckbox(props) {
44
- return _jsx(Checkbox, { className: "visibility-tree-checkbox", variant: "eyeball", checked: props.checked, onChange: (e) => props.onChange(e.currentTarget.checked), onClick: props.onClick, disabled: props.disabled, title: props.title });
45
+ return (_jsx(Checkbox, { className: "visibility-tree-checkbox", variant: "eyeball", checked: props.checked, onChange: (e) => props.onChange(e.currentTarget.checked), onClick: props.onClick, disabled: props.disabled, title: props.title }));
46
+ }
47
+ /**
48
+ * Creates node renderer which renders node with eye checkbox and hierarchy level filtering actions.
49
+ * @beta
50
+ */
51
+ export function FilterableVisibilityTreeNodeRenderer({ levelOffset = 20, disableRootNodeCollapse, descriptionEnabled, isEnlarged, ...restProps }) {
52
+ const expansionToggleWidth = isEnlarged ? EXPANDED_EXPANSION_TOGGLE_WIDTH : EXPANSION_TOGGLE_WIDTH;
53
+ const nodeOffset = restProps.node.depth * levelOffset + (restProps.node.numChildren === 0 ? expansionToggleWidth : 0);
54
+ return (_jsx(PresentationTreeNodeRenderer, { ...restProps, checkboxRenderer: (checkboxProps) => (_jsx("div", { className: "visibility-tree-checkbox-container", style: { marginRight: `${nodeOffset}px` }, children: _jsx(VisibilityTreeNodeCheckbox, { ...checkboxProps }) })), descriptionEnabled: descriptionEnabled, imageLoader: imageLoader, className: classNames("with-checkbox", (restProps.node.numChildren === 0 || (disableRootNodeCollapse && restProps.node.parentId === undefined)) && "disable-expander") }));
45
55
  }
46
56
  /**
47
57
  * Filters data provider used in supplied node loader and invokes onFilterApplied when filtering is completed.
48
58
  * @public
59
+ * @deprecated in 2.0.0. Use [[useVisibilityTree]] instead.
49
60
  */
61
+ // istanbul ignore next
50
62
  export function useVisibilityTreeFiltering(nodeLoader, filterInfo, onFilterApplied) {
51
63
  const { filter, activeMatchIndex } = filterInfo ?? { filter: undefined, activeMatchIndex: undefined };
52
- const { filteredNodeLoader, isFiltering, matchesCount, nodeHighlightingProps, } = useControlledPresentationTreeFiltering({ nodeLoader, filter, activeMatchIndex });
64
+ const { filteredNodeLoader, isFiltering, matchesCount, nodeHighlightingProps } = useControlledPresentationTreeFiltering({
65
+ nodeLoader,
66
+ filter,
67
+ activeMatchIndex,
68
+ });
53
69
  useEffect(() => {
54
- if (filter && matchesCount !== undefined && filteredNodeLoader !== nodeLoader)
70
+ if (filter && matchesCount !== undefined && filteredNodeLoader !== nodeLoader) {
55
71
  onFilterApplied && onFilterApplied(filteredNodeLoader.dataProvider, matchesCount);
72
+ }
56
73
  }, [filter, matchesCount, nodeLoader, filteredNodeLoader, onFilterApplied]);
57
74
  return { filteredNodeLoader, isFiltering, nodeHighlightingProps };
58
75
  }
@@ -1 +1 @@
1
- {"version":3,"file":"VisibilityTreeRenderer.js","sourceRoot":"","sources":["../../../../src/components/trees/VisibilityTreeRenderer.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;AAE/F,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,sCAAsC,EAAE,MAAM,gCAAgC,CAAC;AACxF,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAQrD;;;;;GAKG;AACH,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAoClC;;;GAGG;AACH,MAAM,UAAU,4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AAM,UAAU,4BAA4B,CAAC,KAAwC;IACnF,OAAO,CACL,eAAK,SAAS,EAAC,8BAA8B,aAC3C,eAAM,SAAS,EAAC,qBAAqB,YAAE,KAAK,CAAC,KAAK,GAAQ,EAC1D,eAAM,SAAS,EAAC,mBAAmB,YAAE,KAAK,CAAC,OAAO,GAAQ,IACtD,CACP,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 classNames from \"classnames\";\nimport { useEffect } from \"react\";\nimport { TreeImageLoader, TreeNodeRenderer } from \"@itwin/components-react\";\nimport { Checkbox } from \"@itwin/itwinui-react\";\nimport { useControlledPresentationTreeFiltering } from \"@itwin/presentation-components\";\nimport { TreeRenderer } from \"./common/TreeRenderer\";\n\nimport type { TreeRendererBaseProps } from \"./common/TreeRenderer\";\nimport type { AbstractTreeNodeLoaderWithProvider, TreeNodeRendererProps, TreeRendererProps } from \"@itwin/components-react\";\nimport type { NodeCheckboxRenderProps } from \"@itwin/core-react\";\nimport type { IPresentationTreeDataProvider } from \"@itwin/presentation-components\";\nimport type { VisibilityTreeFilterInfo } from \"./common/Types\";\n\n/**\n * This constant is taken from `@itwin/core-react`.\n * Defines the size in pixels of the expansion toggle.\n * It is used to keep same hierarchy nodes with children and nodes without children in the same line.\n * @note This value applies only to the leaf nodes.\n */\nconst EXPANSION_TOGGLE_WIDTH = 24;\n\n/**\n * Props for visibility tree renderer.\n * @public\n */\nexport interface VisibilityTreeRendererProps extends TreeRendererBaseProps {\n /** Props for single node renderer. */\n nodeRendererProps: VisibilityTreeNodeRendererProps;\n}\n\n/**\n * Props for visibility tree node renderer.\n * @public\n */\nexport interface VisibilityTreeNodeRendererProps {\n /**\n * Specifies whether the icon at the left of the node label should be rendered.\n */\n iconsEnabled: boolean;\n /**\n * Specifies whether node description should be enabled.\n */\n descriptionEnabled: boolean;\n /**\n * Defines the offset in pixels of how much each hierarchy level should be offset to the right from the checkbox.\n * Defaults to `20`.\n */\n levelOffset?: number;\n /**\n * Specifies whether the root node be expanded at all times.\n * Defaults to `false`.\n */\n disableRootNodeCollapse?: boolean;\n}\n\n/**\n * Creates Visibility tree renderer which renders nodes with eye checkbox.\n * @public\n */\nexport function createVisibilityTreeRenderer({ nodeRendererProps, ...restProps }: VisibilityTreeRendererProps) {\n return function VisibilityTreeRenderer(treeProps: TreeRendererProps) {\n return <TreeRenderer {...treeProps} {...restProps} nodeRenderer={createVisibilityTreeNodeRenderer(nodeRendererProps)} />;\n };\n}\n\nconst imageLoader = new TreeImageLoader();\n\n/**\n * Creates node renderer which renders node with eye checkbox.\n * @public\n */\nexport function createVisibilityTreeNodeRenderer({ levelOffset = 20, disableRootNodeCollapse = false, descriptionEnabled, iconsEnabled }: VisibilityTreeNodeRendererProps) {\n return function VisibilityTreeNodeRenderer(treeNodeProps: TreeNodeRendererProps) {\n const nodeOffset = treeNodeProps.node.depth * levelOffset + (treeNodeProps.node.numChildren === 0 ? EXPANSION_TOGGLE_WIDTH : 0);\n return (\n <TreeNodeRenderer\n {...treeNodeProps}\n node={{ ...treeNodeProps.node, depth: 0, numChildren: 1 }} // if we want to disable TreeNodeRenderer style calculations for tree nodes, we need to override these values.\n checkboxRenderer={(checkboxProps: NodeCheckboxRenderProps) => (\n <div className=\"visibility-tree-checkbox-container\" style={{ marginRight: `${nodeOffset}px` }}>\n <VisibilityTreeNodeCheckbox {...checkboxProps} />\n </div>\n )}\n descriptionEnabled={descriptionEnabled}\n imageLoader={iconsEnabled ? imageLoader : undefined}\n className={classNames(\"with-checkbox\", (treeNodeProps.node.numChildren === 0 || (disableRootNodeCollapse && treeNodeProps.node.parentId === undefined)) && \"disable-expander\", treeNodeProps.className)}\n />\n );\n };\n}\n\n/**\n * Checkbox renderer that renders an eye.\n * @public\n */\nexport function VisibilityTreeNodeCheckbox(props: NodeCheckboxRenderProps) {\n return <Checkbox\n className=\"visibility-tree-checkbox\"\n variant=\"eyeball\"\n checked={props.checked}\n onChange={(e) => props.onChange(e.currentTarget.checked)}\n onClick={props.onClick}\n disabled={props.disabled}\n title={props.title}\n />;\n}\n\n/**\n * Filters data provider used in supplied node loader and invokes onFilterApplied when filtering is completed.\n * @public\n */\nexport function useVisibilityTreeFiltering(\n nodeLoader: AbstractTreeNodeLoaderWithProvider<IPresentationTreeDataProvider>,\n filterInfo?: VisibilityTreeFilterInfo,\n onFilterApplied?: (filteredDataProvider: IPresentationTreeDataProvider, matchesCount: number) => void,\n) {\n const { filter, activeMatchIndex } = filterInfo ?? { filter: undefined, activeMatchIndex: undefined };\n const {\n filteredNodeLoader,\n isFiltering,\n matchesCount,\n nodeHighlightingProps,\n } = useControlledPresentationTreeFiltering({ nodeLoader, filter, activeMatchIndex });\n\n useEffect(\n () => {\n if (filter && matchesCount !== undefined && filteredNodeLoader !== nodeLoader)\n onFilterApplied && onFilterApplied(filteredNodeLoader.dataProvider, matchesCount);\n },\n [filter, matchesCount, nodeLoader, filteredNodeLoader, onFilterApplied],\n );\n\n return { filteredNodeLoader, isFiltering, nodeHighlightingProps };\n}\n\n/**\n * Properties for [[VisibilityTreeNoFilteredData]] component.\n * @public\n */\nexport interface VisibilityTreeNoFilteredDataProps {\n title: string;\n message: string;\n}\n\n/**\n * Renders message that no nodes was found for filter.\n * @public\n */\nexport function VisibilityTreeNoFilteredData(props: VisibilityTreeNoFilteredDataProps) {\n return (\n <div className=\"components-tree-errormessage\">\n <span className=\"errormessage-header\">{props.title}</span>\n <span className=\"errormessage-body\">{props.message}</span>\n </div>\n );\n}\n"]}
1
+ {"version":3,"file":"VisibilityTreeRenderer.js","sourceRoot":"","sources":["../../../../src/components/trees/VisibilityTreeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAA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BAAkB,EAAE,WAAW,EAAE,qBAAqB,EAAE,CAAC;AACpE,CAAC;AAWD;;;GAGG;AACH,MAAM,UAAU,4BAA4B,CAAC,KAAwC;IACnF,OAAO,CACL,eAAK,SAAS,EAAC,8BAA8B,aAC3C,eAAM,SAAS,EAAC,qBAAqB,YAAE,KAAK,CAAC,KAAK,GAAQ,EAC1D,eAAM,SAAS,EAAC,mBAAmB,YAAE,KAAK,CAAC,OAAO,GAAQ,IACtD,CACP,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 classNames from \"classnames\";\nimport { useEffect } from \"react\";\nimport { TreeImageLoader, TreeNodeRenderer } from \"@itwin/components-react\";\nimport { Checkbox } from \"@itwin/itwinui-react\";\nimport { PresentationTreeNodeRenderer, useControlledPresentationTreeFiltering } from \"@itwin/presentation-components\";\nimport { TreeRenderer } from \"./common/TreeRenderer\";\n\nimport type { NodeCheckboxRenderProps } from \"@itwin/core-react\";\nimport type { TreeRendererBaseProps, TreeRendererProps } from \"./common/TreeRenderer\";\nimport type { AbstractTreeNodeLoaderWithProvider, TreeNodeRendererProps } from \"@itwin/components-react\";\nimport type { IPresentationTreeDataProvider, PresentationTreeNodeRendererProps } from \"@itwin/presentation-components\";\nimport type { VisibilityTreeFilterInfo } from \"./common/Types\";\n/**\n * These constants are taken from `@itwin/core-react`.\n * Defines the size in pixels of the expansion toggle.\n * It is used to keep same hierarchy nodes with children and nodes without children in the same line.\n * @note This value applies only to the leaf nodes.\n */\nconst EXPANSION_TOGGLE_WIDTH = 24;\nconst EXPANDED_EXPANSION_TOGGLE_WIDTH = 42;\n\nconst imageLoader = new TreeImageLoader();\n\n/**\n * Props for visibility tree renderer.\n * @public\n */\nexport interface VisibilityTreeRendererProps extends TreeRendererBaseProps {\n /** Props for single node renderer. */\n nodeRendererProps: VisibilityTreeNodeRendererProps;\n}\n\n/**\n * Props for visibility tree node renderer.\n * @public\n */\nexport interface VisibilityTreeNodeRendererProps {\n /**\n * Specifies whether the icon at the left of the node label should be rendered.\n */\n iconsEnabled: boolean;\n /**\n * Specifies whether node description should be enabled.\n */\n descriptionEnabled: boolean;\n /**\n * Defines the offset in pixels of how much each hierarchy level should be offset to the right from the checkbox.\n * Defaults to `20`.\n */\n levelOffset?: number;\n /**\n * Specifies whether the root node be expanded at all times.\n * Defaults to `false`.\n */\n disableRootNodeCollapse?: boolean;\n /**\n * Specifies whether the nodes should be enlarged (less dense and larger content).\n * Is `false` by default\n */\n isEnlarged?: boolean;\n}\n\n/**\n * Creates Visibility tree renderer which renders nodes with eye checkbox.\n * @public\n */\nexport function createVisibilityTreeRenderer({ nodeRendererProps, ...restProps }: VisibilityTreeRendererProps) {\n return function VisibilityTreeRenderer(treeProps: TreeRendererProps) {\n return <TreeRenderer {...treeProps} {...restProps} nodeRenderer={createVisibilityTreeNodeRenderer(nodeRendererProps)} />;\n };\n}\n\n/**\n * Creates node renderer which renders node with eye checkbox.\n * @public\n */\nexport function createVisibilityTreeNodeRenderer({\n levelOffset = 20,\n disableRootNodeCollapse = false,\n descriptionEnabled,\n iconsEnabled,\n}: VisibilityTreeNodeRendererProps) {\n return function VisibilityTreeNodeRenderer(treeNodeProps: TreeNodeRendererProps) {\n const nodeOffset = treeNodeProps.node.depth * levelOffset + (treeNodeProps.node.numChildren === 0 ? EXPANSION_TOGGLE_WIDTH : 0);\n return (\n <TreeNodeRenderer\n {...treeNodeProps}\n node={{ ...treeNodeProps.node, depth: 0, numChildren: 1 }} // if we want to disable TreeNodeRenderer style calculations for tree nodes, we need to override these values.\n checkboxRenderer={(checkboxProps: NodeCheckboxRenderProps) => (\n <div className=\"visibility-tree-checkbox-container\" style={{ marginRight: `${nodeOffset}px` }}>\n <VisibilityTreeNodeCheckbox {...checkboxProps} />\n </div>\n )}\n descriptionEnabled={descriptionEnabled}\n imageLoader={iconsEnabled ? imageLoader : undefined}\n className={classNames(\n \"with-checkbox\",\n (treeNodeProps.node.numChildren === 0 || (disableRootNodeCollapse && treeNodeProps.node.parentId === undefined)) && \"disable-expander\",\n treeNodeProps.className,\n )}\n />\n );\n };\n}\n\n/**\n * Checkbox renderer that renders an eye.\n * @public\n */\nexport function VisibilityTreeNodeCheckbox(props: NodeCheckboxRenderProps) {\n return (\n <Checkbox\n className=\"visibility-tree-checkbox\"\n variant=\"eyeball\"\n checked={props.checked}\n onChange={(e) => props.onChange(e.currentTarget.checked)}\n onClick={props.onClick}\n disabled={props.disabled}\n title={props.title}\n />\n );\n}\n\n/**\n * Props for [[FilterableVisibilityTreeNodeRenderer]].\n * @beta\n */\nexport type FilterableVisibilityTreeNodeRendererProps = Omit<PresentationTreeNodeRendererProps, \"descriptionEnabled\"> & VisibilityTreeNodeRendererProps;\n\n/**\n * Creates node renderer which renders node with eye checkbox and hierarchy level filtering actions.\n * @beta\n */\nexport function FilterableVisibilityTreeNodeRenderer({\n levelOffset = 20,\n disableRootNodeCollapse,\n descriptionEnabled,\n isEnlarged,\n ...restProps\n}: FilterableVisibilityTreeNodeRendererProps) {\n const expansionToggleWidth = isEnlarged ? EXPANDED_EXPANSION_TOGGLE_WIDTH : EXPANSION_TOGGLE_WIDTH;\n const nodeOffset = restProps.node.depth * levelOffset + (restProps.node.numChildren === 0 ? expansionToggleWidth : 0);\n\n return (\n <PresentationTreeNodeRenderer\n {...restProps}\n checkboxRenderer={(checkboxProps: NodeCheckboxRenderProps) => (\n <div className=\"visibility-tree-checkbox-container\" style={{ marginRight: `${nodeOffset}px` }}>\n <VisibilityTreeNodeCheckbox {...checkboxProps} />\n </div>\n )}\n descriptionEnabled={descriptionEnabled}\n imageLoader={imageLoader}\n className={classNames(\n \"with-checkbox\",\n (restProps.node.numChildren === 0 || (disableRootNodeCollapse && restProps.node.parentId === undefined)) && \"disable-expander\",\n )}\n />\n );\n}\n\n/**\n * Filters data provider used in supplied node loader and invokes onFilterApplied when filtering is completed.\n * @public\n * @deprecated in 2.0.0. Use [[useVisibilityTree]] instead.\n */\n// istanbul ignore next\nexport function useVisibilityTreeFiltering(\n nodeLoader: AbstractTreeNodeLoaderWithProvider<IPresentationTreeDataProvider>,\n filterInfo?: VisibilityTreeFilterInfo,\n onFilterApplied?: (filteredDataProvider: IPresentationTreeDataProvider, matchesCount: number) => void,\n) {\n const { filter, activeMatchIndex } = filterInfo ?? { filter: undefined, activeMatchIndex: undefined };\n const { filteredNodeLoader, isFiltering, matchesCount, nodeHighlightingProps } = useControlledPresentationTreeFiltering({\n nodeLoader,\n filter,\n activeMatchIndex,\n });\n\n useEffect(() => {\n if (filter && matchesCount !== undefined && filteredNodeLoader !== nodeLoader) {\n onFilterApplied && onFilterApplied(filteredNodeLoader.dataProvider, matchesCount);\n }\n }, [filter, matchesCount, nodeLoader, filteredNodeLoader, onFilterApplied]);\n\n return { filteredNodeLoader, isFiltering, nodeHighlightingProps };\n}\n\n/**\n * Properties for [[VisibilityTreeNoFilteredData]] component.\n * @public\n */\nexport interface VisibilityTreeNoFilteredDataProps {\n title: string;\n message: string;\n}\n\n/**\n * Renders message that no nodes was found for filter.\n * @public\n */\nexport function VisibilityTreeNoFilteredData(props: VisibilityTreeNoFilteredDataProps) {\n return (\n <div className=\"components-tree-errormessage\">\n <span className=\"errormessage-header\">{props.title}</span>\n <span className=\"errormessage-body\">{props.message}</span>\n </div>\n );\n}\n"]}
@@ -3,7 +3,7 @@ import "../VisibilityTreeBase.scss";
3
3
  import { CategoryVisibilityHandler } from "./CategoryVisibilityHandler";
4
4
  import type { ViewManager, Viewport } from "@itwin/core-frontend";
5
5
  import type { Ruleset } from "@itwin/presentation-common";
6
- import type { BaseFilterableTreeProps } from "../common/Types";
6
+ import type { BaseFilterableTreeProps, HierarchyLevelConfig } from "../common/Types";
7
7
  import type { CategoryInfo } from "./CategoryVisibilityHandler";
8
8
  /**
9
9
  * Presentation rules used by ControlledCategoriesTree
@@ -33,10 +33,15 @@ export interface CategoryTreeProps extends BaseFilterableTreeProps {
33
33
  * @internal
34
34
  */
35
35
  viewManager?: ViewManager;
36
+ /**
37
+ * Props for configuring hierarchy level.
38
+ * @beta
39
+ */
40
+ hierarchyLevelConfig?: HierarchyLevelConfig;
36
41
  }
37
42
  /**
38
43
  * Tree which displays and manages display of categories contained in an iModel.
39
44
  * @public
40
45
  */
41
- export declare function CategoryTree(props: CategoryTreeProps): JSX.Element;
46
+ export declare function CategoryTree(props: CategoryTreeProps): JSX.Element | null;
42
47
  //# sourceMappingURL=CategoriesTree.d.ts.map
@@ -1,20 +1,20 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
6
  import "../VisibilityTreeBase.scss";
7
7
  import classNames from "classnames";
8
- import { useCallback, useEffect } from "react";
9
- import { ControlledTree, SelectionMode, useTreeModel } from "@itwin/components-react";
8
+ import { useCallback, useEffect, useState } from "react";
9
+ import { SelectionMode } from "@itwin/components-react";
10
10
  import { IModelApp } from "@itwin/core-frontend";
11
- import { useDisposable } from "@itwin/core-react";
12
- import { usePresentationTreeNodeLoader } from "@itwin/presentation-components";
11
+ import { PresentationTree } from "@itwin/presentation-components";
13
12
  import { Presentation } from "@itwin/presentation-frontend";
14
13
  import { TreeWidget } from "../../../TreeWidget";
14
+ import { FilterableTreeRenderer } from "../common/TreeRenderer";
15
+ import { useVisibilityTreeState } from "../common/UseVisibilityTreeState";
15
16
  import { addCustomTreeNodeItemLabelRenderer, combineTreeNodeItemCustomizations } from "../common/Utils";
16
- import { VisibilityTreeEventHandler } from "../VisibilityTreeEventHandler";
17
- import { createVisibilityTreeRenderer, useVisibilityTreeFiltering, VisibilityTreeNoFilteredData } from "../VisibilityTreeRenderer";
17
+ import { createVisibilityTreeRenderer, FilterableVisibilityTreeNodeRenderer, VisibilityTreeNoFilteredData } from "../VisibilityTreeRenderer";
18
18
  import { CategoryVisibilityHandler } from "./CategoryVisibilityHandler";
19
19
  const PAGING_SIZE = 20;
20
20
  /**
@@ -27,26 +27,29 @@ export const RULESET_CATEGORIES = require("./Categories.json"); // eslint-disabl
27
27
  * @public
28
28
  */
29
29
  export function CategoryTree(props) {
30
- const { nodeLoader } = usePresentationTreeNodeLoader({
30
+ // istanbul ignore next
31
+ const viewManager = props.viewManager ?? IModelApp.viewManager;
32
+ const { activeView, allViewports, categoryVisibilityHandler, onFilterApplied, density, hierarchyLevelConfig } = props;
33
+ const visibilityHandler = useCategoryVisibilityHandler(viewManager, props.iModel, props.categories, activeView, allViewports, categoryVisibilityHandler);
34
+ const onFilterChange = useCallback((dataProvider, matchesCount) => {
35
+ if (onFilterApplied && dataProvider && matchesCount !== undefined) {
36
+ onFilterApplied(dataProvider, matchesCount);
37
+ }
38
+ }, [onFilterApplied]);
39
+ const state = useVisibilityTreeState({
31
40
  imodel: props.iModel,
32
41
  ruleset: RULESET_CATEGORIES,
33
42
  pagingSize: PAGING_SIZE,
43
+ visibilityHandler,
34
44
  customizeTreeNodeItem,
45
+ filterInfo: props.filterInfo,
46
+ onFilterChange,
47
+ hierarchyLevelSizeLimit: hierarchyLevelConfig?.sizeLimit,
35
48
  });
36
- const { filteredNodeLoader, isFiltering, nodeHighlightingProps } = useVisibilityTreeFiltering(nodeLoader, props.filterInfo, props.onFilterApplied);
37
- // istanbul ignore next
38
- const viewManager = props.viewManager ?? IModelApp.viewManager;
39
- const { activeView, allViewports, categoryVisibilityHandler } = props;
40
- const visibilityHandler = useCategoryVisibilityHandler(viewManager, props.iModel, props.categories, activeView, allViewports, categoryVisibilityHandler);
41
49
  useEffect(() => {
42
50
  setViewType(activeView); // eslint-disable-line @typescript-eslint/no-floating-promises
43
51
  }, [activeView]);
44
- const eventHandler = useDisposable(useCallback(() => new VisibilityTreeEventHandler({
45
- nodeLoader: filteredNodeLoader,
46
- visibilityHandler,
47
- }), [filteredNodeLoader, visibilityHandler]));
48
- const treeModel = useTreeModel(filteredNodeLoader.modelSource);
49
- const treeRenderer = createVisibilityTreeRenderer({
52
+ const baseRendererProps = {
50
53
  contextMenuItems: props.contextMenuItems,
51
54
  nodeLabelRenderer: props.nodeLabelRenderer,
52
55
  density: props.density,
@@ -55,26 +58,40 @@ export function CategoryTree(props) {
55
58
  descriptionEnabled: true,
56
59
  levelOffset: 10,
57
60
  },
58
- });
59
- const overlay = isFiltering ? _jsx("div", { className: "filteredTreeOverlay" }) : undefined;
60
- const filterApplied = filteredNodeLoader !== nodeLoader;
61
+ };
61
62
  const noFilteredDataRenderer = useCallback(() => {
62
- return _jsx(VisibilityTreeNoFilteredData, { title: TreeWidget.translate("categoriesTree.noCategoryFound"), message: TreeWidget.translate("categoriesTree.noMatchingCategoryNames") });
63
+ return (_jsx(VisibilityTreeNoFilteredData, { title: TreeWidget.translate("categoriesTree.noCategoryFound"), message: TreeWidget.translate("categoriesTree.noMatchingCategoryNames") }));
63
64
  }, []);
64
- return (_jsxs("div", { className: classNames("tree-widget-visibility-tree-base", "tree-widget-tree-container"), children: [_jsx(ControlledTree, { nodeLoader: filteredNodeLoader, model: treeModel, selectionMode: props.selectionMode ?? SelectionMode.None, eventsHandler: eventHandler, treeRenderer: treeRenderer, descriptionsEnabled: true, nodeHighlightingProps: nodeHighlightingProps, noDataRenderer: filterApplied ? noFilteredDataRenderer : undefined, width: props.width, height: props.height }), overlay] }));
65
+ if (!state) {
66
+ return null;
67
+ }
68
+ const isFilterApplied = state.filteringResult?.filteredProvider !== undefined;
69
+ const overlay = state.filteringResult?.isFiltering ? _jsx("div", { className: "filteredTreeOverlay" }) : undefined;
70
+ return (_jsxs("div", { className: classNames("tree-widget-visibility-tree-base", "tree-widget-tree-container"), children: [_jsx(PresentationTree, { width: props.width, height: props.height, state: state, selectionMode: props.selectionMode ?? SelectionMode.None, treeRenderer: hierarchyLevelConfig?.isFilteringEnabled
71
+ ? (rendererProps) => (_jsx(FilterableTreeRenderer, { ...rendererProps, ...baseRendererProps, nodeLoader: state.nodeLoader, nodeRenderer: (nodeProps) => _jsx(CategoriesTreeNodeRenderer, { ...nodeProps, density: density }) }))
72
+ : createVisibilityTreeRenderer(baseRendererProps), descriptionsEnabled: true, noDataRenderer: isFilterApplied ? noFilteredDataRenderer : undefined }), overlay] }));
73
+ }
74
+ function CategoriesTreeNodeRenderer(props) {
75
+ return (_jsx(FilterableVisibilityTreeNodeRenderer, { ...props, iconsEnabled: false, descriptionEnabled: true, levelOffset: 10, isEnlarged: props.density === "enlarged" }));
65
76
  }
66
77
  function useCategoryVisibilityHandler(viewManager, imodel, categories, activeView, allViewports, visibilityHandler) {
67
- const defaultVisibilityHandler = useDisposable(useCallback(() => new CategoryVisibilityHandler({ viewManager, imodel, categories, activeView, allViewports }), [viewManager, imodel, categories, activeView, allViewports]));
68
- // istanbul ignore next
69
- return visibilityHandler ?? defaultVisibilityHandler;
78
+ const [state, setState] = useState();
79
+ useEffect(() => {
80
+ if (visibilityHandler) {
81
+ return;
82
+ }
83
+ const defaultHandler = new CategoryVisibilityHandler({ viewManager, imodel, categories, activeView, allViewports });
84
+ setState(defaultHandler);
85
+ return () => {
86
+ defaultHandler.dispose();
87
+ };
88
+ }, [viewManager, imodel, categories, activeView, allViewports, visibilityHandler]);
89
+ return visibilityHandler ?? state;
70
90
  }
71
91
  async function setViewType(activeView) {
72
92
  const view = activeView.view;
73
- // TODO: remove this eslint rule when tree-widget uses itwinjs-core 4.0.0 version
74
- const viewType = view.is3d() ? "3d" : "2d"; // eslint-disable-line @itwin/no-internal
93
+ const viewType = view.is3d() ? "3d" : "2d";
75
94
  await Presentation.presentation.vars(RULESET_CATEGORIES.id).setString("ViewType", viewType);
76
95
  }
77
- const customizeTreeNodeItem = combineTreeNodeItemCustomizations([
78
- addCustomTreeNodeItemLabelRenderer,
79
- ]);
96
+ const customizeTreeNodeItem = combineTreeNodeItemCustomizations([addCustomTreeNodeItemLabelRenderer]);
80
97
  //# sourceMappingURL=CategoriesTree.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CategoriesTree.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoriesTree.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;AAE/F,OAAO,4BAA4B,CAAC;AACpC,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACtF,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,kCAAkC,EAAE,iCAAiC,EAAE,MAAM,iBAAiB,CAAC;AACxG,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,4BAA4B,EAAE,0BAA0B,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAC;AACnI,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAOxE,MAAM,WAAW,GAAG,EAAE,CAAC;AAEvB;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAY,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,yDAAyD;AA2BlI;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,KAAwB;IACnD,MAAM,EAAE,UAAU,EAAE,GAAG,6BAA6B,CAAC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AAE,UAAU,EAAE,YAAY,CAAC,CAAC,CAC7D,CAAC;IACF,uBAAuB;IACvB,OAAO,iBAAiB,IAAI,wBAAwB,CAAC;AACvD,CAAC;AAED,KAAK,UAAU,WAAW,CAAC,UAAoB;IAC7C,MAAM,IAAI,GAAG,UAAU,CAAC,IAAwB,CAAC;IACjD,iFAAiF;IACjF,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,yCAAyC;IACrF,MAAM,YAAY,CAAC,YAAY,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AAC9F,CAAC;AAED,MAAM,qBAAqB,GAAG,iCAAiC,CAAC;IAC9D,kCAAkC;CACnC,CAAC,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 \"../VisibilityTreeBase.scss\";\nimport classNames from \"classnames\";\nimport { useCallback, useEffect } from \"react\";\nimport { ControlledTree, SelectionMode, useTreeModel } from \"@itwin/components-react\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { useDisposable } from \"@itwin/core-react\";\nimport { usePresentationTreeNodeLoader } from \"@itwin/presentation-components\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\nimport { TreeWidget } from \"../../../TreeWidget\";\nimport { addCustomTreeNodeItemLabelRenderer, combineTreeNodeItemCustomizations } from \"../common/Utils\";\nimport { VisibilityTreeEventHandler } from \"../VisibilityTreeEventHandler\";\nimport { createVisibilityTreeRenderer, useVisibilityTreeFiltering, VisibilityTreeNoFilteredData } from \"../VisibilityTreeRenderer\";\nimport { CategoryVisibilityHandler } from \"./CategoryVisibilityHandler\";\n\nimport type { IModelConnection, SpatialViewState, ViewManager, Viewport } from \"@itwin/core-frontend\";\nimport type { Ruleset } from \"@itwin/presentation-common\";\nimport type { BaseFilterableTreeProps } from \"../common/Types\";\nimport type { CategoryInfo } from \"./CategoryVisibilityHandler\";\n\nconst PAGING_SIZE = 20;\n\n/**\n * Presentation rules used by ControlledCategoriesTree\n * @internal\n */\nexport const RULESET_CATEGORIES: Ruleset = require(\"./Categories.json\"); // eslint-disable-line @typescript-eslint/no-var-requires\n\n/**\n * Properties for the [[CategoryTree]] component\n * @public\n */\nexport interface CategoryTreeProps extends BaseFilterableTreeProps {\n /** Flag for accommodating all viewports */\n allViewports?: boolean;\n /** Active viewport */\n activeView: Viewport;\n /**\n * Available iModel categories\n */\n categories: CategoryInfo[];\n /**\n * Custom category visibility handler to use for testing\n * @internal\n */\n categoryVisibilityHandler?: CategoryVisibilityHandler;\n /**\n * Custom view manager to use for testing\n * @internal\n */\n viewManager?: ViewManager;\n}\n\n/**\n * Tree which displays and manages display of categories contained in an iModel.\n * @public\n */\nexport function CategoryTree(props: CategoryTreeProps) {\n const { nodeLoader } = usePresentationTreeNodeLoader({\n imodel: props.iModel,\n ruleset: RULESET_CATEGORIES,\n pagingSize: PAGING_SIZE,\n customizeTreeNodeItem,\n });\n\n const { filteredNodeLoader, isFiltering, nodeHighlightingProps } = useVisibilityTreeFiltering(nodeLoader, props.filterInfo, props.onFilterApplied);\n // istanbul ignore next\n const viewManager = props.viewManager ?? IModelApp.viewManager;\n const { activeView, allViewports, categoryVisibilityHandler } = props;\n const visibilityHandler = useCategoryVisibilityHandler(viewManager, props.iModel, props.categories, activeView, allViewports, categoryVisibilityHandler);\n\n useEffect(() => {\n setViewType(activeView); // eslint-disable-line @typescript-eslint/no-floating-promises\n }, [activeView]);\n\n const eventHandler = useDisposable(useCallback(() => new VisibilityTreeEventHandler({\n nodeLoader: filteredNodeLoader,\n visibilityHandler,\n }), [filteredNodeLoader, visibilityHandler]));\n\n const treeModel = useTreeModel(filteredNodeLoader.modelSource);\n const treeRenderer = createVisibilityTreeRenderer({\n contextMenuItems: props.contextMenuItems,\n nodeLabelRenderer: props.nodeLabelRenderer,\n density: props.density,\n nodeRendererProps: {\n iconsEnabled: false,\n descriptionEnabled: true,\n levelOffset: 10,\n },\n });\n const overlay = isFiltering ? <div className=\"filteredTreeOverlay\" /> : undefined;\n const filterApplied = filteredNodeLoader !== nodeLoader;\n\n const noFilteredDataRenderer = useCallback(() => {\n return <VisibilityTreeNoFilteredData\n title={TreeWidget.translate(\"categoriesTree.noCategoryFound\")}\n message={TreeWidget.translate(\"categoriesTree.noMatchingCategoryNames\")}\n />;\n }, []);\n\n return (\n <div className={classNames(\"tree-widget-visibility-tree-base\", \"tree-widget-tree-container\")}>\n <ControlledTree\n nodeLoader={filteredNodeLoader}\n model={treeModel}\n selectionMode={props.selectionMode ?? SelectionMode.None}\n eventsHandler={eventHandler}\n treeRenderer={treeRenderer}\n descriptionsEnabled={true}\n nodeHighlightingProps={nodeHighlightingProps}\n noDataRenderer={filterApplied ? noFilteredDataRenderer : undefined}\n width={props.width}\n height={props.height}\n />\n {overlay}\n </div>\n );\n}\n\nfunction useCategoryVisibilityHandler(viewManager: ViewManager, imodel: IModelConnection, categories: CategoryInfo[], activeView: Viewport, allViewports?: boolean, visibilityHandler?: CategoryVisibilityHandler) {\n const defaultVisibilityHandler = useDisposable(useCallback(\n () =>\n new CategoryVisibilityHandler({ viewManager, imodel, categories, activeView, allViewports }),\n [viewManager, imodel, categories, activeView, allViewports]),\n );\n // istanbul ignore next\n return visibilityHandler ?? defaultVisibilityHandler;\n}\n\nasync function setViewType(activeView: Viewport) {\n const view = activeView.view as SpatialViewState;\n // TODO: remove this eslint rule when tree-widget uses itwinjs-core 4.0.0 version\n const viewType = view.is3d() ? \"3d\" : \"2d\"; // eslint-disable-line @itwin/no-internal\n await Presentation.presentation.vars(RULESET_CATEGORIES.id).setString(\"ViewType\", viewType);\n}\n\nconst customizeTreeNodeItem = combineTreeNodeItemCustomizations([\n addCustomTreeNodeItemLabelRenderer,\n]);\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xC,CACH,CAAC;AAEJ,CAAC;AAED,SAAS,4BAA4B,CACnC,WAAwB,EACxB,MAAwB,EACxB,UAA0B,EAC1B,UAAoB,EACpB,YAAsB,EACtB,iBAA6C;IAE7C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,EAA6B,CAAC;IAEhE,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,iBAAiB,EAAE;YACrB,OAAO;SACR;QAED,MAAM,cAAc,GAAG,IAAI,yBAAyB,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,CAAC;QACpH,QAAQ,CAAC,cAAc,CAAC,CAAC;QACzB,OAAO,GAAG,EAAE;YACV,cAAc,CAAC,OAAO,EAAE,CAAC;QAC3B,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAEnF,OAAO,iBAAiB,IAAI,KAAK,CAAC;AACpC,CAAC;AAED,KAAK,UAAU,WAAW,CAAC,UAAoB;IAC7C,MAAM,IAAI,GAAG,UAAU,CAAC,IAAwB,CAAC;IACjD,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IAC3C,MAAM,YAAY,CAAC,YAAY,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AAC9F,CAAC;AAED,MAAM,qBAAqB,GAAG,iCAAiC,CAAC,CAAC,kCAAkC,CAAC,CAAC,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 \"../VisibilityTreeBase.scss\";\nimport classNames from \"classnames\";\nimport { useCallback, useEffect, useState } from \"react\";\nimport { SelectionMode } from \"@itwin/components-react\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { PresentationTree } from \"@itwin/presentation-components\";\nimport { Presentation } from \"@itwin/presentation-frontend\";\nimport { TreeWidget } from \"../../../TreeWidget\";\nimport { FilterableTreeRenderer } from \"../common/TreeRenderer\";\nimport { useVisibilityTreeState } from \"../common/UseVisibilityTreeState\";\nimport { addCustomTreeNodeItemLabelRenderer, combineTreeNodeItemCustomizations } from \"../common/Utils\";\nimport { createVisibilityTreeRenderer, FilterableVisibilityTreeNodeRenderer, VisibilityTreeNoFilteredData } from \"../VisibilityTreeRenderer\";\nimport { CategoryVisibilityHandler } from \"./CategoryVisibilityHandler\";\n\nimport type { IModelConnection, SpatialViewState, ViewManager, Viewport } from \"@itwin/core-frontend\";\nimport type { Ruleset } from \"@itwin/presentation-common\";\nimport type { IFilteredPresentationTreeDataProvider, PresentationTreeNodeRendererProps } from \"@itwin/presentation-components\";\nimport type { BaseFilterableTreeProps, HierarchyLevelConfig } from \"../common/Types\";\nimport type { CategoryInfo } from \"./CategoryVisibilityHandler\";\nconst PAGING_SIZE = 20;\n\n/**\n * Presentation rules used by ControlledCategoriesTree\n * @internal\n */\nexport const RULESET_CATEGORIES: Ruleset = require(\"./Categories.json\"); // eslint-disable-line @typescript-eslint/no-var-requires\n\n/**\n * Properties for the [[CategoryTree]] component\n * @public\n */\nexport interface CategoryTreeProps extends BaseFilterableTreeProps {\n /** Flag for accommodating all viewports */\n allViewports?: boolean;\n /** Active viewport */\n activeView: Viewport;\n /**\n * Available iModel categories\n */\n categories: CategoryInfo[];\n /**\n * Custom category visibility handler to use for testing\n * @internal\n */\n categoryVisibilityHandler?: CategoryVisibilityHandler;\n /**\n * Custom view manager to use for testing\n * @internal\n */\n viewManager?: ViewManager;\n /**\n * Props for configuring hierarchy level.\n * @beta\n */\n hierarchyLevelConfig?: HierarchyLevelConfig;\n}\n\n/**\n * Tree which displays and manages display of categories contained in an iModel.\n * @public\n */\nexport function CategoryTree(props: CategoryTreeProps) {\n // istanbul ignore next\n const viewManager = props.viewManager ?? IModelApp.viewManager;\n const { activeView, allViewports, categoryVisibilityHandler, onFilterApplied, density, hierarchyLevelConfig } = props;\n\n const visibilityHandler = useCategoryVisibilityHandler(viewManager, props.iModel, props.categories, activeView, allViewports, categoryVisibilityHandler);\n const onFilterChange = useCallback(\n (dataProvider?: IFilteredPresentationTreeDataProvider, matchesCount?: number) => {\n if (onFilterApplied && dataProvider && matchesCount !== undefined) {\n onFilterApplied(dataProvider, matchesCount);\n }\n },\n [onFilterApplied],\n );\n const state = useVisibilityTreeState({\n imodel: props.iModel,\n ruleset: RULESET_CATEGORIES,\n pagingSize: PAGING_SIZE,\n visibilityHandler,\n customizeTreeNodeItem,\n filterInfo: props.filterInfo,\n onFilterChange,\n hierarchyLevelSizeLimit: hierarchyLevelConfig?.sizeLimit,\n });\n\n useEffect(() => {\n setViewType(activeView); // eslint-disable-line @typescript-eslint/no-floating-promises\n }, [activeView]);\n\n const baseRendererProps = {\n contextMenuItems: props.contextMenuItems,\n nodeLabelRenderer: props.nodeLabelRenderer,\n density: props.density,\n nodeRendererProps: {\n iconsEnabled: false,\n descriptionEnabled: true,\n levelOffset: 10,\n },\n };\n\n const noFilteredDataRenderer = useCallback(() => {\n return (\n <VisibilityTreeNoFilteredData\n title={TreeWidget.translate(\"categoriesTree.noCategoryFound\")}\n message={TreeWidget.translate(\"categoriesTree.noMatchingCategoryNames\")}\n />\n );\n }, []);\n\n if (!state) {\n return null;\n }\n\n const isFilterApplied = state.filteringResult?.filteredProvider !== undefined;\n const overlay = state.filteringResult?.isFiltering ? <div className=\"filteredTreeOverlay\" /> : undefined;\n return (\n <div className={classNames(\"tree-widget-visibility-tree-base\", \"tree-widget-tree-container\")}>\n <PresentationTree\n width={props.width}\n height={props.height}\n state={state}\n selectionMode={props.selectionMode ?? SelectionMode.None}\n treeRenderer={\n hierarchyLevelConfig?.isFilteringEnabled\n ? (rendererProps) => (\n <FilterableTreeRenderer\n {...rendererProps}\n {...baseRendererProps}\n nodeLoader={state.nodeLoader}\n nodeRenderer={(nodeProps) => <CategoriesTreeNodeRenderer {...nodeProps} density={density} />}\n />\n )\n : createVisibilityTreeRenderer(baseRendererProps)\n }\n descriptionsEnabled={true}\n noDataRenderer={isFilterApplied ? noFilteredDataRenderer : undefined}\n />\n {overlay}\n </div>\n );\n}\n\nfunction CategoriesTreeNodeRenderer(props: PresentationTreeNodeRendererProps & { density?: \"default\" | \"enlarged\" }) {\n return (\n <FilterableVisibilityTreeNodeRenderer\n {...props}\n iconsEnabled={false}\n descriptionEnabled={true}\n levelOffset={10}\n isEnlarged={props.density === \"enlarged\"}\n />\n );\n\n}\n\nfunction useCategoryVisibilityHandler(\n viewManager: ViewManager,\n imodel: IModelConnection,\n categories: CategoryInfo[],\n activeView: Viewport,\n allViewports?: boolean,\n visibilityHandler?: CategoryVisibilityHandler,\n) {\n const [state, setState] = useState<CategoryVisibilityHandler>();\n\n useEffect(() => {\n if (visibilityHandler) {\n return;\n }\n\n const defaultHandler = new CategoryVisibilityHandler({ viewManager, imodel, categories, activeView, allViewports });\n setState(defaultHandler);\n return () => {\n defaultHandler.dispose();\n };\n }, [viewManager, imodel, categories, activeView, allViewports, visibilityHandler]);\n\n return visibilityHandler ?? state;\n}\n\nasync function setViewType(activeView: Viewport) {\n const view = activeView.view as SpatialViewState;\n const viewType = view.is3d() ? \"3d\" : \"2d\";\n await Presentation.presentation.vars(RULESET_CATEGORIES.id).setString(\"ViewType\", viewType);\n}\n\nconst customizeTreeNodeItem = combineTreeNodeItemCustomizations([addCustomTreeNodeItemLabelRenderer]);\n"]}
@@ -1,8 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
6
  import "../VisibilityTreeBase.scss";
7
7
  import { Fragment, useEffect, useState } from "react";
8
8
  import { useActiveIModelConnection, useActiveViewport } from "@itwin/appui-react";
@@ -27,7 +27,7 @@ export const CategoriesTreeComponent = (props) => {
27
27
  if (!iModel || !viewport) {
28
28
  return null;
29
29
  }
30
- return (_jsx(CategoriesTreeComponentImpl, { ...props, iModel: iModel, viewport: viewport }));
30
+ return _jsx(CategoriesTreeComponentImpl, { ...props, iModel: iModel, viewport: viewport });
31
31
  };
32
32
  /**
33
33
  * Renders a "Show all" button that enables display of all categories and their subcategories.
@@ -57,13 +57,15 @@ CategoriesTreeComponent.getLabel = () => TreeWidget.translate("categories");
57
57
  function CategoriesTreeComponentImpl(props) {
58
58
  const categories = useCategories(IModelApp.viewManager, props.iModel, props.viewport);
59
59
  const [filteredCategories, setFilteredCategories] = useState();
60
- const { searchOptions, filterString, onFilterApplied, filteredProvider, } = useTreeFilteringState();
60
+ const { searchOptions, filterString, onFilterApplied, filteredProvider } = useTreeFilteringState();
61
61
  useEffect(() => {
62
- (async () => {
63
- if (filteredProvider)
64
- setFilteredCategories((await getFilteredCategories(filteredProvider)));
65
- else
62
+ void (async () => {
63
+ if (filteredProvider) {
64
+ setFilteredCategories(await getFilteredCategories(filteredProvider));
65
+ }
66
+ else {
66
67
  setFilteredCategories(undefined);
68
+ }
67
69
  })();
68
70
  }, [filteredProvider]);
69
71
  return (_jsxs("div", { className: "tree-widget-tree-with-header", children: [_jsx(TreeHeader, { onFilterClear: searchOptions.onFilterCancel, onFilterStart: searchOptions.onFilterStart, onSelectedChanged: searchOptions.onResultSelectedChanged, resultCount: searchOptions.matchedResultCount, selectedIndex: searchOptions.activeMatchIndex, children: props.headerButtons
@@ -83,7 +85,9 @@ async function getFilteredCategories(filteredProvider) {
83
85
  }
84
86
  const filteredCategoryId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(node.key);
85
87
  const filteredSubCategoriesIds = node.hasChildren
86
- ? (await filteredProvider.getNodes(node)).filter(isPresentationTreeNodeItem).map((child) => CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(child.key))
88
+ ? (await filteredProvider.getNodes(node))
89
+ .filter(isPresentationTreeNodeItem)
90
+ .map((child) => CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(child.key))
87
91
  : [];
88
92
  filteredCategories.push({ categoryId: filteredCategoryId, subCategoryIds: filteredSubCategoriesIds });
89
93
  }
@@ -1 +1 @@
1
- {"version":3,"file":"CategoriesTreeComponent.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoriesTreeComponent.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;AAE/F,OAAO,4BAA4B,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACrG,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,yBAAyB,EAAE,iBAAiB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EAAE,CAAC,KAAK,iBAAiB,CAAC,CAAC,KAAK,CAAC,kBAAkB,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,YAE5I,KAAC,iBAAiB,KAAG,GACV,CACd,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,KAAsC;IAC3D,OAAO,CACL,KAAC,UAAU,IACT,IAAI,EAAC,OAAO,EACZ,SAAS,EAAC,YAAY,EACtB,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,SAAS,CAAC,EACtC,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,iBAAiB,CAAC,CAAC,KAAK,CAAC,kBAAkB,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,YAE5I,KAAC,iBAAiB,KAAG,GACV,CACd,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,KAAsC;IAC7D,OAAO,CACL,KAAC,UAAU,IACT,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,QAAQ,CAAC,EACrC,IAAI,EAAC,OAAO,EACZ,SAAS,EAAC,YAAY,EACtB,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,mBAAmB,CAAC,KAAK,CAAC,kBAAkB,IAAI,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC,YAErG,KAAC,iBAAiB,KAAG,GACV,CACd,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 \"../VisibilityTreeBase.scss\";\nimport { Fragment, useEffect, useState } from \"react\";\nimport { useActiveIModelConnection, useActiveViewport } from \"@itwin/appui-react\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { SvgVisibilityHalf, SvgVisibilityHide, SvgVisibilityShow } from \"@itwin/itwinui-icons-react\";\nimport { IconButton } from \"@itwin/itwinui-react\";\nimport { isPresentationTreeNodeItem } from \"@itwin/presentation-components\";\nimport { TreeWidget } from \"../../../TreeWidget\";\nimport { TreeHeader } from \"../../tree-header/TreeHeader\";\nimport { useTreeFilteringState } from \"../../TreeFilteringState\";\nimport { AutoSizer } from \"../../utils/AutoSizer\";\nimport { CategoryTree } from \"./CategoriesTree\";\nimport { CategoryVisibilityHandler, hideAllCategories, invertAllCategories, showAllCategories, useCategories } from \"./CategoryVisibilityHandler\";\n\nimport type { IModelConnection, ScreenViewport } from \"@itwin/core-frontend\";\nimport type { IPresentationTreeDataProvider } from \"@itwin/presentation-components\";\nimport type { TreeHeaderButtonProps } from \"../../tree-header/TreeHeader\";\nimport type { CategoryTreeProps } from \"./CategoriesTree\";\nimport type { CategoryInfo } from \"./CategoryVisibilityHandler\";\n\n/**\n * Props that get passed to [[CategoriesTreeComponent]] header button renderer.\n * @see CategoriesTreeComponentProps.headerButtons\n * @public\n */\nexport interface CategoriesTreeHeaderButtonProps extends TreeHeaderButtonProps {\n /** A list of categories available in the iModel */\n categories: CategoryInfo[];\n /** In case the tree is filtered, a list of filtered categories. */\n filteredCategories?: CategoryInfo[];\n}\n\n/**\n * Props for [[CategoriesTreeComponent]].\n * @public\n */\nexport interface CategoriesTreeComponentProps extends Omit<CategoryTreeProps,\n| \"iModel\"\n| \"activeView\"\n| \"width\"\n| \"height\"\n| \"filterInfo\"\n| \"onFilterApplied\"\n| \"categories\"\n| \"categoryVisibilityHandler\"\n| \"viewManager\"\n> {\n /**\n * Renderers of header buttons. Defaults to:\n * ```ts\n * [\n * CategoriesTreeComponent.ShowAllButton,\n * CategoriesTreeComponent.HideAllButton,\n * CategoriesTreeComponent.InvertAllButton,\n * ]\n * ```\n */\n headerButtons?: Array<(props: CategoriesTreeHeaderButtonProps) => React.ReactNode>;\n}\n\n/**\n * A component that renders [[CategoriesTree]] and a header with filtering capabilities\n * and header buttons.\n * @public\n */\nexport const CategoriesTreeComponent = (props: CategoriesTreeComponentProps) => {\n const iModel = useActiveIModelConnection();\n const viewport = useActiveViewport();\n\n if (!iModel || !viewport) {\n return null;\n }\n\n return (\n <CategoriesTreeComponentImpl {...props} iModel={iModel} viewport={viewport} />\n );\n};\n\n/**\n * Renders a \"Show all\" button that enables display of all categories and their subcategories.\n * @public\n */\nCategoriesTreeComponent.ShowAllButton = ShowAllButton;\n\n/**\n * Renders a \"Hide all\" button that disables display of all categories.\n * @public\n */\nCategoriesTreeComponent.HideAllButton = HideAllButton;\n\n/**\n * Renders an \"Invert all\" button that inverts display of all categories.\n * @public\n */\nCategoriesTreeComponent.InvertAllButton = InvertAllButton;\n\n/**\n * Id of the component. May be used when a creating a [[TreeDefinition]] for [[SelectableTree]].\n * @public\n */\nCategoriesTreeComponent.id = \"categories-tree\";\n\n/**\n * Label of the component. May be used when a creating a [[TreeDefinition]] for [[SelectableTree]].\n * @public\n */\nCategoriesTreeComponent.getLabel = () => TreeWidget.translate(\"categories\");\n\nfunction CategoriesTreeComponentImpl(props: CategoriesTreeComponentProps & { iModel: IModelConnection, viewport: ScreenViewport }) {\n const categories = useCategories(IModelApp.viewManager, props.iModel, props.viewport);\n const [filteredCategories, setFilteredCategories] = useState<CategoryInfo[]>();\n const {\n searchOptions,\n filterString,\n onFilterApplied,\n filteredProvider,\n } = useTreeFilteringState();\n\n useEffect(() => {\n (async () => {\n if (filteredProvider)\n setFilteredCategories((await getFilteredCategories(filteredProvider)));\n else\n setFilteredCategories(undefined);\n })();\n }, [filteredProvider]);\n\n return (\n <div className=\"tree-widget-tree-with-header\">\n <TreeHeader\n onFilterClear={searchOptions.onFilterCancel}\n onFilterStart={searchOptions.onFilterStart}\n onSelectedChanged={searchOptions.onResultSelectedChanged}\n resultCount={searchOptions.matchedResultCount}\n selectedIndex={searchOptions.activeMatchIndex}\n >\n {props.headerButtons\n ? props.headerButtons.map(\n (btn, index) =>\n <Fragment key={index}>\n {btn({ viewport: props.viewport, categories, filteredCategories })}\n </Fragment>\n )\n : [\n <ShowAllButton viewport={props.viewport} categories={categories} filteredCategories={filteredCategories} key=\"show-all-btn\" />,\n <HideAllButton viewport={props.viewport} categories={categories} filteredCategories={filteredCategories} key=\"hide-all-btn\" />,\n <InvertAllButton viewport={props.viewport} categories={categories} filteredCategories={filteredCategories} key=\"invert-all-btn\" />,\n ]\n }\n </TreeHeader>\n <div className=\"tree-widget-tree-content\">\n <AutoSizer>\n {({ width, height }) => (\n <CategoryTree\n {...props}\n categories={categories}\n width={width}\n height={height}\n filterInfo={{ filter: filterString, activeMatchIndex: searchOptions.activeMatchIndex }}\n onFilterApplied={onFilterApplied}\n activeView={props.viewport}\n />\n )}\n </AutoSizer>\n </div>\n </div>\n );\n}\n\nasync function getFilteredCategories(filteredProvider: IPresentationTreeDataProvider) {\n const filteredCategories: CategoryInfo[] = [];\n const nodes = await filteredProvider.getNodes();\n for (const node of nodes) {\n if (!isPresentationTreeNodeItem(node)) {\n continue;\n }\n const filteredCategoryId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(node.key);\n const filteredSubCategoriesIds = node.hasChildren\n ? (await filteredProvider.getNodes(node)).filter(isPresentationTreeNodeItem).map((child) => CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(child.key))\n : [];\n filteredCategories.push({ categoryId: filteredCategoryId, subCategoryIds: filteredSubCategoriesIds });\n }\n return filteredCategories;\n}\n\nfunction ShowAllButton(props: CategoriesTreeHeaderButtonProps) {\n return (\n <IconButton\n size=\"small\"\n styleType=\"borderless\"\n title={TreeWidget.translate(\"showAll\")}\n onClick={() => void showAllCategories((props.filteredCategories ?? props.categories).map((category) => category.categoryId), props.viewport)}\n >\n <SvgVisibilityShow />\n </IconButton>\n );\n}\n\nfunction HideAllButton(props: CategoriesTreeHeaderButtonProps) {\n return (\n <IconButton\n size=\"small\"\n styleType=\"borderless\"\n title={TreeWidget.translate(\"hideAll\")}\n onClick={() => void hideAllCategories((props.filteredCategories ?? props.categories).map((category) => category.categoryId), props.viewport)}\n >\n <SvgVisibilityHide />\n </IconButton>\n );\n}\n\nfunction InvertAllButton(props: CategoriesTreeHeaderButtonProps) {\n return (\n <IconButton\n title={TreeWidget.translate(\"invert\")}\n size=\"small\"\n styleType=\"borderless\"\n onClick={() => void invertAllCategories(props.filteredCategories ?? props.categories, props.viewport)}\n >\n <SvgVisibilityHalf />\n </IconButton>\n );\n}\n"]}
1
+ {"version":3,"file":"CategoriesTreeComponent.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoriesTreeComponent.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,4BAA4B,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACrG,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,aA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,CACpB,CAAC,KAAK,CAAC,kBAAkB,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,EACrF,KAAK,CAAC,QAAQ,CACf,YAGH,KAAC,iBAAiB,KAAG,GACV,CACd,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,KAAsC;IAC3D,OAAO,CACL,KAAC,UAAU,IACT,IAAI,EAAC,OAAO,EACZ,SAAS,EAAC,YAAY,EACtB,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,SAAS,CAAC,EACtC,OAAO,EAAE,GAAG,EAAE,CACZ,KAAK,iBAAiB,CACpB,CAAC,KAAK,CAAC,kBAAkB,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,EACrF,KAAK,CAAC,QAAQ,CACf,YAGH,KAAC,iBAAiB,KAAG,GACV,CACd,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,KAAsC;IAC7D,OAAO,CACL,KAAC,UAAU,IACT,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,QAAQ,CAAC,EACrC,IAAI,EAAC,OAAO,EACZ,SAAS,EAAC,YAAY,EACtB,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,mBAAmB,CAAC,KAAK,CAAC,kBAAkB,IAAI,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC,YAErG,KAAC,iBAAiB,KAAG,GACV,CACd,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 \"../VisibilityTreeBase.scss\";\nimport { Fragment, useEffect, useState } from \"react\";\nimport { useActiveIModelConnection, useActiveViewport } from \"@itwin/appui-react\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { SvgVisibilityHalf, SvgVisibilityHide, SvgVisibilityShow } from \"@itwin/itwinui-icons-react\";\nimport { IconButton } from \"@itwin/itwinui-react\";\nimport { isPresentationTreeNodeItem } from \"@itwin/presentation-components\";\nimport { TreeWidget } from \"../../../TreeWidget\";\nimport { TreeHeader } from \"../../tree-header/TreeHeader\";\nimport { useTreeFilteringState } from \"../../TreeFilteringState\";\nimport { AutoSizer } from \"../../utils/AutoSizer\";\nimport { CategoryTree } from \"./CategoriesTree\";\nimport { CategoryVisibilityHandler, hideAllCategories, invertAllCategories, showAllCategories, useCategories } from \"./CategoryVisibilityHandler\";\n\nimport type { IModelConnection, ScreenViewport } from \"@itwin/core-frontend\";\nimport type { IPresentationTreeDataProvider } from \"@itwin/presentation-components\";\nimport type { TreeHeaderButtonProps } from \"../../tree-header/TreeHeader\";\nimport type { CategoryTreeProps } from \"./CategoriesTree\";\nimport type { CategoryInfo } from \"./CategoryVisibilityHandler\";\n\n/**\n * Props that get passed to [[CategoriesTreeComponent]] header button renderer.\n * @see CategoriesTreeComponentProps.headerButtons\n * @public\n */\nexport interface CategoriesTreeHeaderButtonProps extends TreeHeaderButtonProps {\n /** A list of categories available in the iModel */\n categories: CategoryInfo[];\n /** In case the tree is filtered, a list of filtered categories. */\n filteredCategories?: CategoryInfo[];\n}\n\n/**\n * Props for [[CategoriesTreeComponent]].\n * @public\n */\nexport interface CategoriesTreeComponentProps\n extends Omit<\n CategoryTreeProps,\n \"iModel\" | \"activeView\" | \"width\" | \"height\" | \"filterInfo\" | \"onFilterApplied\" | \"categories\" | \"categoryVisibilityHandler\" | \"viewManager\"\n > {\n /**\n * Renderers of header buttons. Defaults to:\n * ```ts\n * [\n * CategoriesTreeComponent.ShowAllButton,\n * CategoriesTreeComponent.HideAllButton,\n * CategoriesTreeComponent.InvertAllButton,\n * ]\n * ```\n */\n headerButtons?: Array<(props: CategoriesTreeHeaderButtonProps) => React.ReactNode>;\n}\n\n/**\n * A component that renders [[CategoriesTree]] and a header with filtering capabilities\n * and header buttons.\n * @public\n */\nexport const CategoriesTreeComponent = (props: CategoriesTreeComponentProps) => {\n const iModel = useActiveIModelConnection();\n const viewport = useActiveViewport();\n\n if (!iModel || !viewport) {\n return null;\n }\n\n return <CategoriesTreeComponentImpl {...props} iModel={iModel} viewport={viewport} />;\n};\n\n/**\n * Renders a \"Show all\" button that enables display of all categories and their subcategories.\n * @public\n */\nCategoriesTreeComponent.ShowAllButton = ShowAllButton;\n\n/**\n * Renders a \"Hide all\" button that disables display of all categories.\n * @public\n */\nCategoriesTreeComponent.HideAllButton = HideAllButton;\n\n/**\n * Renders an \"Invert all\" button that inverts display of all categories.\n * @public\n */\nCategoriesTreeComponent.InvertAllButton = InvertAllButton;\n\n/**\n * Id of the component. May be used when a creating a [[TreeDefinition]] for [[SelectableTree]].\n * @public\n */\nCategoriesTreeComponent.id = \"categories-tree\";\n\n/**\n * Label of the component. May be used when a creating a [[TreeDefinition]] for [[SelectableTree]].\n * @public\n */\nCategoriesTreeComponent.getLabel = () => TreeWidget.translate(\"categories\");\n\nfunction CategoriesTreeComponentImpl(props: CategoriesTreeComponentProps & { iModel: IModelConnection; viewport: ScreenViewport }) {\n const categories = useCategories(IModelApp.viewManager, props.iModel, props.viewport);\n const [filteredCategories, setFilteredCategories] = useState<CategoryInfo[]>();\n const { searchOptions, filterString, onFilterApplied, filteredProvider } = useTreeFilteringState();\n\n useEffect(() => {\n void (async () => {\n if (filteredProvider) {\n setFilteredCategories(await getFilteredCategories(filteredProvider));\n } else {\n setFilteredCategories(undefined);\n }\n })();\n }, [filteredProvider]);\n\n return (\n <div className=\"tree-widget-tree-with-header\">\n <TreeHeader\n onFilterClear={searchOptions.onFilterCancel}\n onFilterStart={searchOptions.onFilterStart}\n onSelectedChanged={searchOptions.onResultSelectedChanged}\n resultCount={searchOptions.matchedResultCount}\n selectedIndex={searchOptions.activeMatchIndex}\n >\n {props.headerButtons\n ? props.headerButtons.map((btn, index) => <Fragment key={index}>{btn({ viewport: props.viewport, categories, filteredCategories })}</Fragment>)\n : [\n <ShowAllButton viewport={props.viewport} categories={categories} filteredCategories={filteredCategories} key=\"show-all-btn\" />,\n <HideAllButton viewport={props.viewport} categories={categories} filteredCategories={filteredCategories} key=\"hide-all-btn\" />,\n <InvertAllButton viewport={props.viewport} categories={categories} filteredCategories={filteredCategories} key=\"invert-all-btn\" />,\n ]}\n </TreeHeader>\n <div className=\"tree-widget-tree-content\">\n <AutoSizer>\n {({ width, height }) => (\n <CategoryTree\n {...props}\n categories={categories}\n width={width}\n height={height}\n filterInfo={{ filter: filterString, activeMatchIndex: searchOptions.activeMatchIndex }}\n onFilterApplied={onFilterApplied}\n activeView={props.viewport}\n />\n )}\n </AutoSizer>\n </div>\n </div>\n );\n}\n\nasync function getFilteredCategories(filteredProvider: IPresentationTreeDataProvider) {\n const filteredCategories: CategoryInfo[] = [];\n const nodes = await filteredProvider.getNodes();\n for (const node of nodes) {\n if (!isPresentationTreeNodeItem(node)) {\n continue;\n }\n const filteredCategoryId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(node.key);\n const filteredSubCategoriesIds = node.hasChildren\n ? (await filteredProvider.getNodes(node))\n .filter(isPresentationTreeNodeItem)\n .map((child) => CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(child.key))\n : [];\n filteredCategories.push({ categoryId: filteredCategoryId, subCategoryIds: filteredSubCategoriesIds });\n }\n return filteredCategories;\n}\n\nfunction ShowAllButton(props: CategoriesTreeHeaderButtonProps) {\n return (\n <IconButton\n size=\"small\"\n styleType=\"borderless\"\n title={TreeWidget.translate(\"showAll\")}\n onClick={() =>\n void showAllCategories(\n (props.filteredCategories ?? props.categories).map((category) => category.categoryId),\n props.viewport,\n )\n }\n >\n <SvgVisibilityShow />\n </IconButton>\n );\n}\n\nfunction HideAllButton(props: CategoriesTreeHeaderButtonProps) {\n return (\n <IconButton\n size=\"small\"\n styleType=\"borderless\"\n title={TreeWidget.translate(\"hideAll\")}\n onClick={() =>\n void hideAllCategories(\n (props.filteredCategories ?? props.categories).map((category) => category.categoryId),\n props.viewport,\n )\n }\n >\n <SvgVisibilityHide />\n </IconButton>\n );\n}\n\nfunction InvertAllButton(props: CategoriesTreeHeaderButtonProps) {\n return (\n <IconButton\n title={TreeWidget.translate(\"invert\")}\n size=\"small\"\n styleType=\"borderless\"\n onClick={() => void invertAllCategories(props.filteredCategories ?? props.categories, props.viewport)}\n >\n <SvgVisibilityHalf />\n </IconButton>\n );\n}\n"]}
@@ -1,7 +1,7 @@
1
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
- *--------------------------------------------------------------------------------------------*/
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
5
  import { useMemo } from "react";
6
6
  import { useAsyncValue } from "@itwin/components-react";
7
7
  import { BeEvent } from "@itwin/core-bentley";
@@ -51,23 +51,26 @@ export class CategoryVisibilityHandler {
51
51
  }
52
52
  getVisibilityStatus(node) {
53
53
  const nodeKey = isPresentationTreeNodeItem(node) ? node.key : undefined;
54
- if (!nodeKey)
54
+ if (!nodeKey) {
55
55
  return { state: "hidden", isDisabled: true };
56
+ }
56
57
  const instanceId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);
57
58
  return { state: node.parentId ? this.getSubCategoryVisibility(instanceId) : this.getCategoryVisibility(instanceId) };
58
59
  }
59
60
  async changeVisibility(node, shouldDisplay) {
60
61
  const nodeKey = isPresentationTreeNodeItem(node) ? node.key : undefined;
61
- if (!nodeKey)
62
+ if (!nodeKey) {
62
63
  return;
64
+ }
63
65
  // handle subcategory visibility change
64
66
  if (node.parentId) {
65
67
  const childId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);
66
68
  // istanbul ignore next
67
69
  const parentId = this.getParent(childId)?.categoryId;
68
70
  // make sure parent category is enabled
69
- if (shouldDisplay && parentId)
71
+ if (shouldDisplay && parentId) {
70
72
  await this.enableCategory([parentId], true, false);
73
+ }
71
74
  this.enableSubCategory(childId, shouldDisplay);
72
75
  return;
73
76
  }
@@ -76,8 +79,9 @@ export class CategoryVisibilityHandler {
76
79
  }
77
80
  getSubCategoryVisibility(id) {
78
81
  const parentItem = this.getParent(id);
79
- if (!parentItem)
82
+ if (!parentItem) {
80
83
  return "hidden";
84
+ }
81
85
  const isVisible = this._activeView.view.viewsCategory(parentItem.categoryId) && this._activeView.isSubCategoryVisible(id);
82
86
  return isVisible ? "visible" : "hidden";
83
87
  }
@@ -87,23 +91,23 @@ export class CategoryVisibilityHandler {
87
91
  getParent(key) {
88
92
  for (const category of this._categories) {
89
93
  // istanbul ignore else
90
- if (category.subCategoryIds) {
91
- if (category.subCategoryIds.indexOf(key) !== -1)
92
- return category;
94
+ if (category.subCategoryIds && category.subCategoryIds.indexOf(key) !== -1) {
95
+ return category;
93
96
  }
94
97
  }
95
98
  return undefined;
96
99
  }
97
100
  onVisibilityChangeInternal() {
98
- if (this._pendingVisibilityChange)
101
+ if (this._pendingVisibilityChange) {
99
102
  return;
103
+ }
100
104
  this._pendingVisibilityChange = setTimeout(() => {
101
105
  this.onVisibilityChange.raiseEvent();
102
106
  this._pendingVisibilityChange = undefined;
103
107
  }, 0);
104
108
  }
105
109
  static getInstanceIdFromTreeNodeKey(nodeKey) {
106
- return (NodeKey.isInstancesNodeKey(nodeKey) && nodeKey.instanceKeys.length > 0) ? nodeKey.instanceKeys[0].id : /* istanbul ignore next */ "";
110
+ return NodeKey.isInstancesNodeKey(nodeKey) && nodeKey.instanceKeys.length > 0 ? nodeKey.instanceKeys[0].id : /* istanbul ignore next */ "";
107
111
  }
108
112
  async enableCategory(ids, enabled, enableAllSubCategories = true) {
109
113
  await enableCategory(this._viewManager, this._imodel, ids, enabled, this._useAllViewports, enableAllSubCategories);
@@ -142,8 +146,9 @@ export async function invertAllCategories(categories, viewport) {
142
146
  }
143
147
  // First, we need to check if at least one subcategory is disabled. If it is true, then only subcategories should change display, not categories.
144
148
  if (category.subCategoryIds?.some((subCategory) => !viewport.isSubCategoryVisible(subCategory))) {
145
- for (const subCategory of category.subCategoryIds)
149
+ for (const subCategory of category.subCategoryIds) {
146
150
  viewport.isSubCategoryVisible(subCategory) ? enabledSubCategories.push(subCategory) : disabledSubCategories.push(subCategory);
151
+ }
147
152
  }
148
153
  else {
149
154
  enabled.push(category.categoryId);