@itwin/tree-widget-react 1.2.2 → 2.0.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 (194) hide show
  1. package/CHANGELOG.md +26 -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.d.ts +9 -1
  7. package/lib/cjs/components/SelectableTree.js +28 -17
  8. package/lib/cjs/components/SelectableTree.js.map +1 -1
  9. package/lib/cjs/components/SelectableTree.scss +0 -16
  10. package/lib/cjs/components/TreeFilteringState.js +3 -3
  11. package/lib/cjs/components/TreeFilteringState.js.map +1 -1
  12. package/lib/cjs/components/TreeSelector.d.ts +28 -0
  13. package/lib/cjs/components/TreeSelector.js +27 -0
  14. package/lib/cjs/components/TreeSelector.js.map +1 -0
  15. package/lib/cjs/components/TreeSelector.scss +27 -0
  16. package/lib/cjs/components/TreeWidgetUiItemsProvider.d.ts +9 -1
  17. package/lib/cjs/components/TreeWidgetUiItemsProvider.js +21 -14
  18. package/lib/cjs/components/TreeWidgetUiItemsProvider.js.map +1 -1
  19. package/lib/cjs/components/TreeWidgetUiItemsProvider.scss +1 -1
  20. package/lib/cjs/components/tree-header/TreeHeader.d.ts +3 -0
  21. package/lib/cjs/components/tree-header/TreeHeader.js +20 -15
  22. package/lib/cjs/components/tree-header/TreeHeader.js.map +1 -1
  23. package/lib/cjs/components/tree-header/TreeHeader.scss +29 -1
  24. package/lib/cjs/components/trees/CategoriesVisibilityUtils.js +13 -8
  25. package/lib/cjs/components/trees/CategoriesVisibilityUtils.js.map +1 -1
  26. package/lib/cjs/components/trees/VisibilityTreeBase.scss +1 -1
  27. package/lib/cjs/components/trees/VisibilityTreeEventHandler.d.ts +1 -1
  28. package/lib/cjs/components/trees/VisibilityTreeEventHandler.js +18 -10
  29. package/lib/cjs/components/trees/VisibilityTreeEventHandler.js.map +1 -1
  30. package/lib/cjs/components/trees/VisibilityTreeRenderer.d.ts +20 -4
  31. package/lib/cjs/components/trees/VisibilityTreeRenderer.js +28 -10
  32. package/lib/cjs/components/trees/VisibilityTreeRenderer.js.map +1 -1
  33. package/lib/cjs/components/trees/category-tree/CategoriesTree.d.ts +7 -2
  34. package/lib/cjs/components/trees/category-tree/CategoriesTree.js +47 -30
  35. package/lib/cjs/components/trees/category-tree/CategoriesTree.js.map +1 -1
  36. package/lib/cjs/components/trees/category-tree/CategoriesTreeComponent.js +27 -18
  37. package/lib/cjs/components/trees/category-tree/CategoriesTreeComponent.js.map +1 -1
  38. package/lib/cjs/components/trees/category-tree/CategoryVisibilityHandler.d.ts +2 -2
  39. package/lib/cjs/components/trees/category-tree/CategoryVisibilityHandler.js +18 -13
  40. package/lib/cjs/components/trees/category-tree/CategoryVisibilityHandler.js.map +1 -1
  41. package/lib/cjs/components/trees/common/ContextMenu.js +4 -4
  42. package/lib/cjs/components/trees/common/ContextMenu.js.map +1 -1
  43. package/lib/cjs/components/trees/common/TreeNodeRenderer.d.ts +1 -1
  44. package/lib/cjs/components/trees/common/TreeNodeRenderer.js +4 -4
  45. package/lib/cjs/components/trees/common/TreeNodeRenderer.js.map +1 -1
  46. package/lib/cjs/components/trees/common/TreeRenderer.d.ts +15 -1
  47. package/lib/cjs/components/trees/common/TreeRenderer.js +17 -7
  48. package/lib/cjs/components/trees/common/TreeRenderer.js.map +1 -1
  49. package/lib/cjs/components/trees/common/TreeRenderer.scss +39 -2
  50. package/lib/cjs/components/trees/common/Types.d.ts +8 -0
  51. package/lib/cjs/components/trees/common/Types.js +3 -3
  52. package/lib/cjs/components/trees/common/Types.js.map +1 -1
  53. package/lib/cjs/components/trees/common/UseVisibilityTreeState.d.ts +36 -0
  54. package/lib/cjs/components/trees/common/UseVisibilityTreeState.js +47 -0
  55. package/lib/cjs/components/trees/common/UseVisibilityTreeState.js.map +1 -0
  56. package/lib/cjs/components/trees/common/Utils.js +7 -5
  57. package/lib/cjs/components/trees/common/Utils.js.map +1 -1
  58. package/lib/cjs/components/trees/external-sources-tree/ExternalSources.json +1 -3
  59. package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTree.d.ts +9 -3
  60. package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTree.js +19 -7
  61. package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTree.js.map +1 -1
  62. package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js +4 -4
  63. package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js.map +1 -1
  64. package/lib/cjs/components/trees/imodel-content-tree/IModelContentTree.d.ts +9 -3
  65. package/lib/cjs/components/trees/imodel-content-tree/IModelContentTree.js +16 -12
  66. package/lib/cjs/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -1
  67. package/lib/cjs/components/trees/imodel-content-tree/IModelContentTreeComponent.js +6 -5
  68. package/lib/cjs/components/trees/imodel-content-tree/IModelContentTreeComponent.js.map +1 -1
  69. package/lib/cjs/components/trees/index.js +3 -3
  70. package/lib/cjs/components/trees/index.js.map +1 -1
  71. package/lib/cjs/components/trees/models-tree/ModelsTree.d.ts +7 -2
  72. package/lib/cjs/components/trees/models-tree/ModelsTree.js +76 -62
  73. package/lib/cjs/components/trees/models-tree/ModelsTree.js.map +1 -1
  74. package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.js +27 -29
  75. package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
  76. package/lib/cjs/components/trees/models-tree/ModelsTreeEventHandler.d.ts +9 -0
  77. package/lib/cjs/components/trees/models-tree/ModelsTreeEventHandler.js +31 -0
  78. package/lib/cjs/components/trees/models-tree/ModelsTreeEventHandler.js.map +1 -0
  79. package/lib/cjs/components/trees/models-tree/ModelsVisibilityHandler.js +125 -66
  80. package/lib/cjs/components/trees/models-tree/ModelsVisibilityHandler.js.map +1 -1
  81. package/lib/cjs/components/trees/models-tree/Utils.d.ts +4 -0
  82. package/lib/cjs/components/trees/models-tree/Utils.js +52 -58
  83. package/lib/cjs/components/trees/models-tree/Utils.js.map +1 -1
  84. package/lib/cjs/components/utils/AutoSizer.js +7 -5
  85. package/lib/cjs/components/utils/AutoSizer.js.map +1 -1
  86. package/lib/cjs/components/utils/IsPromiseLike.js +4 -4
  87. package/lib/cjs/components/utils/IsPromiseLike.js.map +1 -1
  88. package/lib/cjs/components/utils/UseTreeTransientState.js +3 -3
  89. package/lib/cjs/components/utils/UseTreeTransientState.js.map +1 -1
  90. package/lib/cjs/tree-widget-react.js +3 -3
  91. package/lib/cjs/tree-widget-react.js.map +1 -1
  92. package/lib/esm/TreeWidget.d.ts +0 -1
  93. package/lib/esm/TreeWidget.js +9 -10
  94. package/lib/esm/TreeWidget.js.map +1 -1
  95. package/lib/esm/components/SelectableTree.d.ts +9 -1
  96. package/lib/esm/components/SelectableTree.js +28 -17
  97. package/lib/esm/components/SelectableTree.js.map +1 -1
  98. package/lib/esm/components/SelectableTree.scss +0 -16
  99. package/lib/esm/components/TreeFilteringState.js +3 -3
  100. package/lib/esm/components/TreeFilteringState.js.map +1 -1
  101. package/lib/esm/components/TreeSelector.d.ts +28 -0
  102. package/lib/esm/components/TreeSelector.js +23 -0
  103. package/lib/esm/components/TreeSelector.js.map +1 -0
  104. package/lib/esm/components/TreeSelector.scss +27 -0
  105. package/lib/esm/components/TreeWidgetUiItemsProvider.d.ts +9 -1
  106. package/lib/esm/components/TreeWidgetUiItemsProvider.js +19 -13
  107. package/lib/esm/components/TreeWidgetUiItemsProvider.js.map +1 -1
  108. package/lib/esm/components/TreeWidgetUiItemsProvider.scss +1 -1
  109. package/lib/esm/components/tree-header/TreeHeader.d.ts +3 -0
  110. package/lib/esm/components/tree-header/TreeHeader.js +20 -15
  111. package/lib/esm/components/tree-header/TreeHeader.js.map +1 -1
  112. package/lib/esm/components/tree-header/TreeHeader.scss +29 -1
  113. package/lib/esm/components/trees/CategoriesVisibilityUtils.js +13 -8
  114. package/lib/esm/components/trees/CategoriesVisibilityUtils.js.map +1 -1
  115. package/lib/esm/components/trees/VisibilityTreeBase.scss +1 -1
  116. package/lib/esm/components/trees/VisibilityTreeEventHandler.d.ts +1 -1
  117. package/lib/esm/components/trees/VisibilityTreeEventHandler.js +18 -10
  118. package/lib/esm/components/trees/VisibilityTreeEventHandler.js.map +1 -1
  119. package/lib/esm/components/trees/VisibilityTreeRenderer.d.ts +20 -4
  120. package/lib/esm/components/trees/VisibilityTreeRenderer.js +27 -10
  121. package/lib/esm/components/trees/VisibilityTreeRenderer.js.map +1 -1
  122. package/lib/esm/components/trees/category-tree/CategoriesTree.d.ts +7 -2
  123. package/lib/esm/components/trees/category-tree/CategoriesTree.js +51 -34
  124. package/lib/esm/components/trees/category-tree/CategoriesTree.js.map +1 -1
  125. package/lib/esm/components/trees/category-tree/CategoriesTreeComponent.js +24 -18
  126. package/lib/esm/components/trees/category-tree/CategoriesTreeComponent.js.map +1 -1
  127. package/lib/esm/components/trees/category-tree/CategoryVisibilityHandler.d.ts +2 -2
  128. package/lib/esm/components/trees/category-tree/CategoryVisibilityHandler.js +18 -13
  129. package/lib/esm/components/trees/category-tree/CategoryVisibilityHandler.js.map +1 -1
  130. package/lib/esm/components/trees/common/ContextMenu.js +4 -4
  131. package/lib/esm/components/trees/common/ContextMenu.js.map +1 -1
  132. package/lib/esm/components/trees/common/TreeNodeRenderer.d.ts +1 -1
  133. package/lib/esm/components/trees/common/TreeNodeRenderer.js +4 -4
  134. package/lib/esm/components/trees/common/TreeNodeRenderer.js.map +1 -1
  135. package/lib/esm/components/trees/common/TreeRenderer.d.ts +15 -1
  136. package/lib/esm/components/trees/common/TreeRenderer.js +15 -6
  137. package/lib/esm/components/trees/common/TreeRenderer.js.map +1 -1
  138. package/lib/esm/components/trees/common/TreeRenderer.scss +39 -2
  139. package/lib/esm/components/trees/common/Types.d.ts +8 -0
  140. package/lib/esm/components/trees/common/Types.js +3 -3
  141. package/lib/esm/components/trees/common/Types.js.map +1 -1
  142. package/lib/esm/components/trees/common/UseVisibilityTreeState.d.ts +36 -0
  143. package/lib/esm/components/trees/common/UseVisibilityTreeState.js +43 -0
  144. package/lib/esm/components/trees/common/UseVisibilityTreeState.js.map +1 -0
  145. package/lib/esm/components/trees/common/Utils.js +7 -5
  146. package/lib/esm/components/trees/common/Utils.js.map +1 -1
  147. package/lib/esm/components/trees/external-sources-tree/ExternalSources.json +1 -3
  148. package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTree.d.ts +9 -3
  149. package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTree.js +22 -10
  150. package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTree.js.map +1 -1
  151. package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js +4 -4
  152. package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js.map +1 -1
  153. package/lib/esm/components/trees/imodel-content-tree/IModelContentTree.d.ts +9 -3
  154. package/lib/esm/components/trees/imodel-content-tree/IModelContentTree.js +19 -15
  155. package/lib/esm/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -1
  156. package/lib/esm/components/trees/imodel-content-tree/IModelContentTreeComponent.js +6 -5
  157. package/lib/esm/components/trees/imodel-content-tree/IModelContentTreeComponent.js.map +1 -1
  158. package/lib/esm/components/trees/index.js +3 -3
  159. package/lib/esm/components/trees/index.js.map +1 -1
  160. package/lib/esm/components/trees/models-tree/ModelsTree.d.ts +7 -2
  161. package/lib/esm/components/trees/models-tree/ModelsTree.js +80 -66
  162. package/lib/esm/components/trees/models-tree/ModelsTree.js.map +1 -1
  163. package/lib/esm/components/trees/models-tree/ModelsTreeComponent.js +25 -30
  164. package/lib/esm/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
  165. package/lib/esm/components/trees/models-tree/ModelsTreeEventHandler.d.ts +9 -0
  166. package/lib/esm/components/trees/models-tree/ModelsTreeEventHandler.js +27 -0
  167. package/lib/esm/components/trees/models-tree/ModelsTreeEventHandler.js.map +1 -0
  168. package/lib/esm/components/trees/models-tree/ModelsVisibilityHandler.js +125 -66
  169. package/lib/esm/components/trees/models-tree/ModelsVisibilityHandler.js.map +1 -1
  170. package/lib/esm/components/trees/models-tree/Utils.d.ts +4 -0
  171. package/lib/esm/components/trees/models-tree/Utils.js +50 -57
  172. package/lib/esm/components/trees/models-tree/Utils.js.map +1 -1
  173. package/lib/esm/components/utils/AutoSizer.js +7 -5
  174. package/lib/esm/components/utils/AutoSizer.js.map +1 -1
  175. package/lib/esm/components/utils/IsPromiseLike.js +4 -4
  176. package/lib/esm/components/utils/IsPromiseLike.js.map +1 -1
  177. package/lib/esm/components/utils/UseTreeTransientState.js +3 -3
  178. package/lib/esm/components/utils/UseTreeTransientState.js.map +1 -1
  179. package/lib/esm/tree-widget-react.js +3 -3
  180. package/lib/esm/tree-widget-react.js.map +1 -1
  181. package/lib/public/locales/en/TreeWidget.json +1 -0
  182. package/package.json +47 -46
  183. package/lib/cjs/e2e-tests/TreeWidget.test.d.ts +0 -2
  184. package/lib/cjs/e2e-tests/TreeWidget.test.js +0 -51
  185. package/lib/cjs/e2e-tests/TreeWidget.test.js.map +0 -1
  186. package/lib/cjs/e2e-tests/utils.d.ts +0 -9
  187. package/lib/cjs/e2e-tests/utils.js +0 -51
  188. package/lib/cjs/e2e-tests/utils.js.map +0 -1
  189. package/lib/esm/e2e-tests/TreeWidget.test.d.ts +0 -2
  190. package/lib/esm/e2e-tests/TreeWidget.test.js +0 -46
  191. package/lib/esm/e2e-tests/TreeWidget.test.js.map +0 -1
  192. package/lib/esm/e2e-tests/utils.d.ts +0 -9
  193. package/lib/esm/e2e-tests/utils.js +0 -40
  194. package/lib/esm/e2e-tests/utils.js.map +0 -1
@@ -3,12 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.VisibilityTreeNoFilteredData = exports.useVisibilityTreeFiltering = exports.VisibilityTreeNodeCheckbox = exports.createVisibilityTreeNodeRenderer = exports.createVisibilityTreeRenderer = void 0;
6
+ exports.VisibilityTreeNoFilteredData = exports.useVisibilityTreeFiltering = exports.FilterableVisibilityTreeNodeRenderer = exports.VisibilityTreeNodeCheckbox = exports.createVisibilityTreeNodeRenderer = exports.createVisibilityTreeRenderer = void 0;
7
7
  const jsx_runtime_1 = require("react/jsx-runtime");
8
8
  /*---------------------------------------------------------------------------------------------
9
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
10
- * See LICENSE.md in the project root for license terms and full copyright notice.
11
- *--------------------------------------------------------------------------------------------*/
9
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
10
+ * See LICENSE.md in the project root for license terms and full copyright notice.
11
+ *--------------------------------------------------------------------------------------------*/
12
12
  const classnames_1 = __importDefault(require("classnames"));
13
13
  const react_1 = require("react");
14
14
  const components_react_1 = require("@itwin/components-react");
@@ -16,12 +16,14 @@ const itwinui_react_1 = require("@itwin/itwinui-react");
16
16
  const presentation_components_1 = require("@itwin/presentation-components");
17
17
  const TreeRenderer_1 = require("./common/TreeRenderer");
18
18
  /**
19
- * This constant is taken from `@itwin/core-react`.
19
+ * These constants are taken from `@itwin/core-react`.
20
20
  * Defines the size in pixels of the expansion toggle.
21
21
  * It is used to keep same hierarchy nodes with children and nodes without children in the same line.
22
22
  * @note This value applies only to the leaf nodes.
23
23
  */
24
24
  const EXPANSION_TOGGLE_WIDTH = 24;
25
+ const EXPANDED_EXPANSION_TOGGLE_WIDTH = 42;
26
+ const imageLoader = new components_react_1.TreeImageLoader();
25
27
  /**
26
28
  * Creates Visibility tree renderer which renders nodes with eye checkbox.
27
29
  * @public
@@ -32,12 +34,11 @@ function createVisibilityTreeRenderer({ nodeRendererProps, ...restProps }) {
32
34
  };
33
35
  }
34
36
  exports.createVisibilityTreeRenderer = createVisibilityTreeRenderer;
35
- const imageLoader = new components_react_1.TreeImageLoader();
36
37
  /**
37
38
  * Creates node renderer which renders node with eye checkbox.
38
39
  * @public
39
40
  */
40
- function createVisibilityTreeNodeRenderer({ levelOffset = 20, disableRootNodeCollapse = false, descriptionEnabled, iconsEnabled }) {
41
+ function createVisibilityTreeNodeRenderer({ levelOffset = 20, disableRootNodeCollapse = false, descriptionEnabled, iconsEnabled, }) {
41
42
  return function VisibilityTreeNodeRenderer(treeNodeProps) {
42
43
  const nodeOffset = treeNodeProps.node.depth * levelOffset + (treeNodeProps.node.numChildren === 0 ? EXPANSION_TOGGLE_WIDTH : 0);
43
44
  return ((0, jsx_runtime_1.jsx)(components_react_1.TreeNodeRenderer, { ...treeNodeProps, node: { ...treeNodeProps.node, depth: 0, numChildren: 1 }, checkboxRenderer: (checkboxProps) => ((0, jsx_runtime_1.jsx)("div", { className: "visibility-tree-checkbox-container", style: { marginRight: `${nodeOffset}px` }, children: (0, jsx_runtime_1.jsx)(VisibilityTreeNodeCheckbox, { ...checkboxProps }) })), descriptionEnabled: descriptionEnabled, imageLoader: iconsEnabled ? imageLoader : undefined, className: (0, classnames_1.default)("with-checkbox", (treeNodeProps.node.numChildren === 0 || (disableRootNodeCollapse && treeNodeProps.node.parentId === undefined)) && "disable-expander", treeNodeProps.className) }));
@@ -49,19 +50,36 @@ exports.createVisibilityTreeNodeRenderer = createVisibilityTreeNodeRenderer;
49
50
  * @public
50
51
  */
51
52
  function VisibilityTreeNodeCheckbox(props) {
52
- return (0, jsx_runtime_1.jsx)(itwinui_react_1.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 });
53
+ return ((0, jsx_runtime_1.jsx)(itwinui_react_1.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 }));
53
54
  }
54
55
  exports.VisibilityTreeNodeCheckbox = VisibilityTreeNodeCheckbox;
56
+ /**
57
+ * Creates node renderer which renders node with eye checkbox and hierarchy level filtering actions.
58
+ * @beta
59
+ */
60
+ function FilterableVisibilityTreeNodeRenderer({ levelOffset = 20, disableRootNodeCollapse, descriptionEnabled, isEnlarged, ...restProps }) {
61
+ const expansionToggleWidth = isEnlarged ? EXPANDED_EXPANSION_TOGGLE_WIDTH : EXPANSION_TOGGLE_WIDTH;
62
+ const nodeOffset = restProps.node.depth * levelOffset + (restProps.node.numChildren === 0 ? expansionToggleWidth : 0);
63
+ return ((0, jsx_runtime_1.jsx)(presentation_components_1.PresentationTreeNodeRenderer, { ...restProps, checkboxRenderer: (checkboxProps) => ((0, jsx_runtime_1.jsx)("div", { className: "visibility-tree-checkbox-container", style: { marginRight: `${nodeOffset}px` }, children: (0, jsx_runtime_1.jsx)(VisibilityTreeNodeCheckbox, { ...checkboxProps }) })), descriptionEnabled: descriptionEnabled, imageLoader: imageLoader, className: (0, classnames_1.default)("with-checkbox", (restProps.node.numChildren === 0 || (disableRootNodeCollapse && restProps.node.parentId === undefined)) && "disable-expander") }));
64
+ }
65
+ exports.FilterableVisibilityTreeNodeRenderer = FilterableVisibilityTreeNodeRenderer;
55
66
  /**
56
67
  * Filters data provider used in supplied node loader and invokes onFilterApplied when filtering is completed.
57
68
  * @public
69
+ * @deprecated in 2.0.0. Use [[useVisibilityTree]] instead.
58
70
  */
71
+ // istanbul ignore next
59
72
  function useVisibilityTreeFiltering(nodeLoader, filterInfo, onFilterApplied) {
60
73
  const { filter, activeMatchIndex } = filterInfo ?? { filter: undefined, activeMatchIndex: undefined };
61
- const { filteredNodeLoader, isFiltering, matchesCount, nodeHighlightingProps, } = (0, presentation_components_1.useControlledPresentationTreeFiltering)({ nodeLoader, filter, activeMatchIndex });
74
+ const { filteredNodeLoader, isFiltering, matchesCount, nodeHighlightingProps } = (0, presentation_components_1.useControlledPresentationTreeFiltering)({
75
+ nodeLoader,
76
+ filter,
77
+ activeMatchIndex,
78
+ });
62
79
  (0, react_1.useEffect)(() => {
63
- if (filter && matchesCount !== undefined && filteredNodeLoader !== nodeLoader)
80
+ if (filter && matchesCount !== undefined && filteredNodeLoader !== nodeLoader) {
64
81
  onFilterApplied && onFilterApplied(filteredNodeLoader.dataProvider, matchesCount);
82
+ }
65
83
  }, [filter, matchesCount, nodeLoader, filteredNodeLoader, onFilterApplied]);
66
84
  return { filteredNodeLoader, isFiltering, nodeHighlightingProps };
67
85
  }
@@ -1 +1 @@
1
- {"version":3,"file":"VisibilityTreeRenderer.js","sourceRoot":"","sources":["../../../../src/components/trees/VisibilityTreeRenderer.tsx"],"names":[],"mappings":";;;;;;;AAAA;;;+FAG+F;AAE/F,4DAAoC;AACpC,iCAAkC;AAClC,8DAA4E;AAC5E,wDAAgD;AAChD,4EAAwF;AACxF,wDAAqD;AAQrD;;;;;GAKG;AACH,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAoClC;;;GAGG;AACH,SAAgB,4BAA4B,CAAC,EAAE,iBAAiB,EAAE,GAAG,SAAS,EAA+B;IAC3G,OAAO,SAAS,sBAAsB,CAAC,SAA4B;QACjE,OAAO,uBAAC,2BAAY,OAAK,SAAS,KAAM,SAAS,EAAE,YAAY,EAAE,gCAAgC,CAAC,iBAAiB,CAAC,GAAI,CAAC;IAC3H,CAAC,CAAC;AACJ,CAAC;AAJD,oEAIC;AAED,MAAM,WAAW,GAAG,IAAI,kCAAe,EAAE,CAAC;AAE1C;;;GAGG;AACH,SAAgB,gCAAgC,CAAC,EAAE,WAAW,GAAG,EAAE,EAAE,uBAAuB,GAAG,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAmC;IACvK,OAAO,SAAS,0BAA0B,CAAC,aAAoC;QAC7E,MAAM,UAAU,GAAG,aAAa,CAAC,IAAI,CAAC,KAAK,GAAG,WAAW,GAAG,CAAC,aAAa,CAAC,IAAI,CAAC,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAChI,OAAO,CAC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,EAAE,gBAAgB,EAAE,GAAG,UAAU,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,SAAS,EAAE,CAAC;IACtG,MAAM,EACJ,kBAAkB,EAClB,WAAW,EACX,YAAY,EACZ,qBAAqB,GACtB,GAAG,IAAA,gEAAsC,EAAC,EAAE,UAAU,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC,CAAC;IAErF,IAAA,iBAAS,EACP,GAAG,EAAE;QACH,IAAI,MAAM,IAAI,YAAY,KAAK,SAAS,IAAI,kBAAkB,KAAK,UAAU;YAC3E,eAAe,IAAI,eAAe,CAAC,kBAAkB,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;IACtF,CAAC,EACD,CAAC,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,kBAAkB,EAAE,eAAe,CAAC,CACxE,CAAC;IAEF,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,qBAAqB,EAAE,CAAC;AACpE,CAAC;AAtBD,gEAsBC;AAWD;;;GAGG;AACH,SAAgB,4BAA4B,CAAC,KAAwC;IACnF,OAAO,CACL,iCAAK,SAAS,EAAC,8BAA8B,aAC3C,iCAAM,SAAS,EAAC,qBAAqB,YAAE,KAAK,CAAC,KAAK,GAAQ,EAC1D,iCAAM,SAAS,EAAC,mBAAmB,YAAE,KAAK,CAAC,OAAO,GAAQ,IACtD,CACP,CAAC;AACJ,CAAC;AAPD,oEAOC","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,4DAAoC;AACpC,iCAAkC;AAClC,8DAA4E;AAC5E,wDAAgD;AAChD,4EAAsH;AACtH,wDAAqD;AAOrD;;;;;GAKG;AACH,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAClC,MAAM,+BAA+B,GAAG,EAAE,CAAC;AAE3C,MAAM,WAAW,GAAG,IAAI,kCAAe,EAAE,CAAC;AAyC1C;;;GAGG;AACH,SAAgB,4BAA4B,CAAC,EAAE,iBAAiB,EAAE,GAAG,SAAS,EAA+B;IAC3G,OAAO,SAAS,sBAAsB,CAAC,SAA4B;QACjE,OAAO,uBAAC,2BAAY,OAAK,SAAS,KAAM,SAAS,EAAE,YAAY,EAAE,gCAAgC,CAAC,iBAAiB,CAAC,GAAI,CAAC;IAC3H,CAAC,CAAC;AACJ,CAAC;AAJD,oEAIC;AAED;;;GAGG;AACH,SAAgB,gCAAgC,CAAC,EAC/C,WAAW,GAAG,EAAE,EAChB,uBAAuB,GAAG,KAAK,EAC/B,kBAAkB,EAClB,YAAY,GACoB;IAChC,OAAO,SAAS,0BAA0B,CAAC,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SAAS,EAAE,gBAAgB,EAAE,SAAS,EAAE,CAAC;IACtG,MAAM,EAAE,kBAAkB,EAAE,WAAW,EAAE,YAAY,EAAE,qBAAqB,EAAE,GAAG,IAAA,gEAAsC,EAAC;QACtH,UAAU;QACV,MAAM;QACN,gBAAgB;KACjB,CAAC,CAAC;IAEH,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,MAAM,IAAI,YAAY,KAAK,SAAS,IAAI,kBAAkB,KAAK,UAAU,EAAE;YAC7E,eAAe,IAAI,eAAe,CAAC,kBAAkB,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;SACnF;IACH,CAAC,EAAE,CAAC,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,kBAAkB,EAAE,eAAe,CAAC,CAAC,CAAC;IAE5E,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,qBAAqB,EAAE,CAAC;AACpE,CAAC;AAnBD,gEAmBC;AAWD;;;GAGG;AACH,SAAgB,4BAA4B,CAAC,KAAwC;IACnF,OAAO,CACL,iCAAK,SAAS,EAAC,8BAA8B,aAC3C,iCAAM,SAAS,EAAC,qBAAqB,YAAE,KAAK,CAAC,KAAK,GAAQ,EAC1D,iCAAM,SAAS,EAAC,mBAAmB,YAAE,KAAK,CAAC,OAAO,GAAQ,IACtD,CACP,CAAC;AACJ,CAAC;AAPD,oEAOC","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
@@ -6,20 +6,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.CategoryTree = exports.RULESET_CATEGORIES = void 0;
7
7
  const jsx_runtime_1 = require("react/jsx-runtime");
8
8
  /*---------------------------------------------------------------------------------------------
9
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
10
- * See LICENSE.md in the project root for license terms and full copyright notice.
11
- *--------------------------------------------------------------------------------------------*/
9
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
10
+ * See LICENSE.md in the project root for license terms and full copyright notice.
11
+ *--------------------------------------------------------------------------------------------*/
12
12
  require("../VisibilityTreeBase.scss");
13
13
  const classnames_1 = __importDefault(require("classnames"));
14
14
  const react_1 = require("react");
15
15
  const components_react_1 = require("@itwin/components-react");
16
16
  const core_frontend_1 = require("@itwin/core-frontend");
17
- const core_react_1 = require("@itwin/core-react");
18
17
  const presentation_components_1 = require("@itwin/presentation-components");
19
18
  const presentation_frontend_1 = require("@itwin/presentation-frontend");
20
19
  const TreeWidget_1 = require("../../../TreeWidget");
20
+ const TreeRenderer_1 = require("../common/TreeRenderer");
21
+ const UseVisibilityTreeState_1 = require("../common/UseVisibilityTreeState");
21
22
  const Utils_1 = require("../common/Utils");
22
- const VisibilityTreeEventHandler_1 = require("../VisibilityTreeEventHandler");
23
23
  const VisibilityTreeRenderer_1 = require("../VisibilityTreeRenderer");
24
24
  const CategoryVisibilityHandler_1 = require("./CategoryVisibilityHandler");
25
25
  const PAGING_SIZE = 20;
@@ -33,26 +33,29 @@ exports.RULESET_CATEGORIES = require("./Categories.json"); // eslint-disable-lin
33
33
  * @public
34
34
  */
35
35
  function CategoryTree(props) {
36
- const { nodeLoader } = (0, presentation_components_1.usePresentationTreeNodeLoader)({
36
+ // istanbul ignore next
37
+ const viewManager = props.viewManager ?? core_frontend_1.IModelApp.viewManager;
38
+ const { activeView, allViewports, categoryVisibilityHandler, onFilterApplied, density, hierarchyLevelConfig } = props;
39
+ const visibilityHandler = useCategoryVisibilityHandler(viewManager, props.iModel, props.categories, activeView, allViewports, categoryVisibilityHandler);
40
+ const onFilterChange = (0, react_1.useCallback)((dataProvider, matchesCount) => {
41
+ if (onFilterApplied && dataProvider && matchesCount !== undefined) {
42
+ onFilterApplied(dataProvider, matchesCount);
43
+ }
44
+ }, [onFilterApplied]);
45
+ const state = (0, UseVisibilityTreeState_1.useVisibilityTreeState)({
37
46
  imodel: props.iModel,
38
47
  ruleset: exports.RULESET_CATEGORIES,
39
48
  pagingSize: PAGING_SIZE,
49
+ visibilityHandler,
40
50
  customizeTreeNodeItem,
51
+ filterInfo: props.filterInfo,
52
+ onFilterChange,
53
+ hierarchyLevelSizeLimit: hierarchyLevelConfig?.sizeLimit,
41
54
  });
42
- const { filteredNodeLoader, isFiltering, nodeHighlightingProps } = (0, VisibilityTreeRenderer_1.useVisibilityTreeFiltering)(nodeLoader, props.filterInfo, props.onFilterApplied);
43
- // istanbul ignore next
44
- const viewManager = props.viewManager ?? core_frontend_1.IModelApp.viewManager;
45
- const { activeView, allViewports, categoryVisibilityHandler } = props;
46
- const visibilityHandler = useCategoryVisibilityHandler(viewManager, props.iModel, props.categories, activeView, allViewports, categoryVisibilityHandler);
47
55
  (0, react_1.useEffect)(() => {
48
56
  setViewType(activeView); // eslint-disable-line @typescript-eslint/no-floating-promises
49
57
  }, [activeView]);
50
- const eventHandler = (0, core_react_1.useDisposable)((0, react_1.useCallback)(() => new VisibilityTreeEventHandler_1.VisibilityTreeEventHandler({
51
- nodeLoader: filteredNodeLoader,
52
- visibilityHandler,
53
- }), [filteredNodeLoader, visibilityHandler]));
54
- const treeModel = (0, components_react_1.useTreeModel)(filteredNodeLoader.modelSource);
55
- const treeRenderer = (0, VisibilityTreeRenderer_1.createVisibilityTreeRenderer)({
58
+ const baseRendererProps = {
56
59
  contextMenuItems: props.contextMenuItems,
57
60
  nodeLabelRenderer: props.nodeLabelRenderer,
58
61
  density: props.density,
@@ -61,27 +64,41 @@ function CategoryTree(props) {
61
64
  descriptionEnabled: true,
62
65
  levelOffset: 10,
63
66
  },
64
- });
65
- const overlay = isFiltering ? (0, jsx_runtime_1.jsx)("div", { className: "filteredTreeOverlay" }) : undefined;
66
- const filterApplied = filteredNodeLoader !== nodeLoader;
67
+ };
67
68
  const noFilteredDataRenderer = (0, react_1.useCallback)(() => {
68
- return (0, jsx_runtime_1.jsx)(VisibilityTreeRenderer_1.VisibilityTreeNoFilteredData, { title: TreeWidget_1.TreeWidget.translate("categoriesTree.noCategoryFound"), message: TreeWidget_1.TreeWidget.translate("categoriesTree.noMatchingCategoryNames") });
69
+ return ((0, jsx_runtime_1.jsx)(VisibilityTreeRenderer_1.VisibilityTreeNoFilteredData, { title: TreeWidget_1.TreeWidget.translate("categoriesTree.noCategoryFound"), message: TreeWidget_1.TreeWidget.translate("categoriesTree.noMatchingCategoryNames") }));
69
70
  }, []);
70
- return ((0, jsx_runtime_1.jsxs)("div", { className: (0, classnames_1.default)("tree-widget-visibility-tree-base", "tree-widget-tree-container"), children: [(0, jsx_runtime_1.jsx)(components_react_1.ControlledTree, { nodeLoader: filteredNodeLoader, model: treeModel, selectionMode: props.selectionMode ?? components_react_1.SelectionMode.None, eventsHandler: eventHandler, treeRenderer: treeRenderer, descriptionsEnabled: true, nodeHighlightingProps: nodeHighlightingProps, noDataRenderer: filterApplied ? noFilteredDataRenderer : undefined, width: props.width, height: props.height }), overlay] }));
71
+ if (!state) {
72
+ return null;
73
+ }
74
+ const isFilterApplied = state.filteringResult?.filteredProvider !== undefined;
75
+ const overlay = state.filteringResult?.isFiltering ? (0, jsx_runtime_1.jsx)("div", { className: "filteredTreeOverlay" }) : undefined;
76
+ return ((0, jsx_runtime_1.jsxs)("div", { className: (0, classnames_1.default)("tree-widget-visibility-tree-base", "tree-widget-tree-container"), children: [(0, jsx_runtime_1.jsx)(presentation_components_1.PresentationTree, { width: props.width, height: props.height, state: state, selectionMode: props.selectionMode ?? components_react_1.SelectionMode.None, treeRenderer: hierarchyLevelConfig?.isFilteringEnabled
77
+ ? (rendererProps) => ((0, jsx_runtime_1.jsx)(TreeRenderer_1.FilterableTreeRenderer, { ...rendererProps, ...baseRendererProps, nodeLoader: state.nodeLoader, nodeRenderer: (nodeProps) => (0, jsx_runtime_1.jsx)(CategoriesTreeNodeRenderer, { ...nodeProps, density: density }) }))
78
+ : (0, VisibilityTreeRenderer_1.createVisibilityTreeRenderer)(baseRendererProps), descriptionsEnabled: true, noDataRenderer: isFilterApplied ? noFilteredDataRenderer : undefined }), overlay] }));
71
79
  }
72
80
  exports.CategoryTree = CategoryTree;
81
+ function CategoriesTreeNodeRenderer(props) {
82
+ return ((0, jsx_runtime_1.jsx)(VisibilityTreeRenderer_1.FilterableVisibilityTreeNodeRenderer, { ...props, iconsEnabled: false, descriptionEnabled: true, levelOffset: 10, isEnlarged: props.density === "enlarged" }));
83
+ }
73
84
  function useCategoryVisibilityHandler(viewManager, imodel, categories, activeView, allViewports, visibilityHandler) {
74
- const defaultVisibilityHandler = (0, core_react_1.useDisposable)((0, react_1.useCallback)(() => new CategoryVisibilityHandler_1.CategoryVisibilityHandler({ viewManager, imodel, categories, activeView, allViewports }), [viewManager, imodel, categories, activeView, allViewports]));
75
- // istanbul ignore next
76
- return visibilityHandler ?? defaultVisibilityHandler;
85
+ const [state, setState] = (0, react_1.useState)();
86
+ (0, react_1.useEffect)(() => {
87
+ if (visibilityHandler) {
88
+ return;
89
+ }
90
+ const defaultHandler = new CategoryVisibilityHandler_1.CategoryVisibilityHandler({ viewManager, imodel, categories, activeView, allViewports });
91
+ setState(defaultHandler);
92
+ return () => {
93
+ defaultHandler.dispose();
94
+ };
95
+ }, [viewManager, imodel, categories, activeView, allViewports, visibilityHandler]);
96
+ return visibilityHandler ?? state;
77
97
  }
78
98
  async function setViewType(activeView) {
79
99
  const view = activeView.view;
80
- // TODO: remove this eslint rule when tree-widget uses itwinjs-core 4.0.0 version
81
- const viewType = view.is3d() ? "3d" : "2d"; // eslint-disable-line @itwin/no-internal
100
+ const viewType = view.is3d() ? "3d" : "2d";
82
101
  await presentation_frontend_1.Presentation.presentation.vars(exports.RULESET_CATEGORIES.id).setString("ViewType", viewType);
83
102
  }
84
- const customizeTreeNodeItem = (0, Utils_1.combineTreeNodeItemCustomizations)([
85
- Utils_1.addCustomTreeNodeItemLabelRenderer,
86
- ]);
103
+ const customizeTreeNodeItem = (0, Utils_1.combineTreeNodeItemCustomizations)([Utils_1.addCustomTreeNodeItemLabelRenderer]);
87
104
  //# sourceMappingURL=CategoriesTree.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CategoriesT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,EAC3B,YAAY,EAAE,YAAY,EAC1B,mBAAmB,EAAE,IAAI,EACzB,qBAAqB,EAAE,qBAAqB,EAC5C,cAAc,EAAE,aAAa,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,SAAS,EAClE,KAAK,EAAE,KAAK,CAAC,KAAK,EAClB,MAAM,EAAE,KAAK,CAAC,MAAM,GACpB,EACD,OAAO,IACJ,CACP,CAAC;AACJ,CAAC;AA7DD,oCA6DC;AAED,SAAS,4BAA4B,CAAC,WAAwB,EAAE,MAAwB,EAAE,UAA0B,EAAE,UAAoB,EAAE,YAAsB,EAAE,iBAA6C;IAC/M,MAAM,wBAAwB,GAAG,IAAA,0BAAa,EAAC,IAAA,mBAAW,EACxD,GAAG,EAAE,CACH,IAAI,qDAAyB,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC,EAC9F,CAAC,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,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,oCAAY,CAAC,YAAY,CAAC,IAAI,CAAC,0BAAkB,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;AAC9F,CAAC;AAED,MAAM,qBAAqB,GAAG,IAAA,yCAAiC,EAAC;IAC9D,0CAAkC;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]);\n"]}
1
+ {"version":3,"file":"CategoriesTree.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoriesTree.tsx"],"names":[],"mappings":";;;;;;;AAAA;;;gGAGgG;AAEhG,sCAAoC;AACpC,4DAAoC;AACpC,iCAAyD;AACzD,8DAAwD;AACxD,wDAAiD;AACjD,4EAAkE;AAClE,wEAA4D;AAC5D,oDAAiD;AACjD,yDAAgE;AAChE,6EAA0E;AAC1E,2CAAwG;AACxG,sEAA6I;AAC7I,2EAAwE;AAOxE,MAAM,WAAW,GAAG,EAAE,CAAC;AAEvB;;;GAGG;AACU,QAAA,kBAAkB,GAAY,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,yDAAyD;AAgClI;;;GAGG;AACH,SAAgB,YAAY,CAAC,KAAwB;IACnD,uBAAuB;IACvB,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,IAAI,yBAAS,CAAC,WAAW,CAAC;IAC/D,MAAM,EAAE,UAAU,EAAE,YAAY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AAC,0CAAkC,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,11 +1,14 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.CategoriesTreeComponent = void 0;
4
7
  const jsx_runtime_1 = require("react/jsx-runtime");
5
8
  /*---------------------------------------------------------------------------------------------
6
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
7
- * See LICENSE.md in the project root for license terms and full copyright notice.
8
- *--------------------------------------------------------------------------------------------*/
9
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
10
+ * See LICENSE.md in the project root for license terms and full copyright notice.
11
+ *--------------------------------------------------------------------------------------------*/
9
12
  require("../VisibilityTreeBase.scss");
10
13
  const react_1 = require("react");
11
14
  const appui_react_1 = require("@itwin/appui-react");
@@ -19,6 +22,7 @@ const TreeFilteringState_1 = require("../../TreeFilteringState");
19
22
  const AutoSizer_1 = require("../../utils/AutoSizer");
20
23
  const CategoriesTree_1 = require("./CategoriesTree");
21
24
  const CategoryVisibilityHandler_1 = require("./CategoryVisibilityHandler");
25
+ const classnames_1 = __importDefault(require("classnames"));
22
26
  /**
23
27
  * A component that renders [[CategoriesTree]] and a header with filtering capabilities
24
28
  * and header buttons.
@@ -30,7 +34,7 @@ const CategoriesTreeComponent = (props) => {
30
34
  if (!iModel || !viewport) {
31
35
  return null;
32
36
  }
33
- return ((0, jsx_runtime_1.jsx)(CategoriesTreeComponentImpl, { ...props, iModel: iModel, viewport: viewport }));
37
+ return (0, jsx_runtime_1.jsx)(CategoriesTreeComponentImpl, { ...props, iModel: iModel, viewport: viewport });
34
38
  };
35
39
  exports.CategoriesTreeComponent = CategoriesTreeComponent;
36
40
  /**
@@ -61,22 +65,25 @@ exports.CategoriesTreeComponent.getLabel = () => TreeWidget_1.TreeWidget.transla
61
65
  function CategoriesTreeComponentImpl(props) {
62
66
  const categories = (0, CategoryVisibilityHandler_1.useCategories)(core_frontend_1.IModelApp.viewManager, props.iModel, props.viewport);
63
67
  const [filteredCategories, setFilteredCategories] = (0, react_1.useState)();
64
- const { searchOptions, filterString, onFilterApplied, filteredProvider, } = (0, TreeFilteringState_1.useTreeFilteringState)();
68
+ const { searchOptions, filterString, onFilterApplied, filteredProvider } = (0, TreeFilteringState_1.useTreeFilteringState)();
69
+ const contentClassName = (0, classnames_1.default)("tree-widget-tree-content", props.density === "enlarged" && "enlarge");
65
70
  (0, react_1.useEffect)(() => {
66
- (async () => {
67
- if (filteredProvider)
68
- setFilteredCategories((await getFilteredCategories(filteredProvider)));
69
- else
71
+ void (async () => {
72
+ if (filteredProvider) {
73
+ setFilteredCategories(await getFilteredCategories(filteredProvider));
74
+ }
75
+ else {
70
76
  setFilteredCategories(undefined);
77
+ }
71
78
  })();
72
79
  }, [filteredProvider]);
73
- return ((0, jsx_runtime_1.jsxs)("div", { className: "tree-widget-tree-with-header", children: [(0, jsx_runtime_1.jsx)(TreeHeader_1.TreeHeader, { onFilterClear: searchOptions.onFilterCancel, onFilterStart: searchOptions.onFilterStart, onSelectedChanged: searchOptions.onResultSelectedChanged, resultCount: searchOptions.matchedResultCount, selectedIndex: searchOptions.activeMatchIndex, children: props.headerButtons
80
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "tree-widget-tree-with-header", children: [(0, jsx_runtime_1.jsx)(TreeHeader_1.TreeHeader, { onFilterClear: searchOptions.onFilterCancel, onFilterStart: searchOptions.onFilterStart, onSelectedChanged: searchOptions.onResultSelectedChanged, resultCount: searchOptions.matchedResultCount, selectedIndex: searchOptions.activeMatchIndex, density: props.density, children: props.headerButtons
74
81
  ? props.headerButtons.map((btn, index) => (0, jsx_runtime_1.jsx)(react_1.Fragment, { children: btn({ viewport: props.viewport, categories, filteredCategories }) }, index))
75
82
  : [
76
- (0, jsx_runtime_1.jsx)(ShowAllButton, { viewport: props.viewport, categories: categories, filteredCategories: filteredCategories }, "show-all-btn"),
77
- (0, jsx_runtime_1.jsx)(HideAllButton, { viewport: props.viewport, categories: categories, filteredCategories: filteredCategories }, "hide-all-btn"),
78
- (0, jsx_runtime_1.jsx)(InvertAllButton, { viewport: props.viewport, categories: categories, filteredCategories: filteredCategories }, "invert-all-btn"),
79
- ] }), (0, jsx_runtime_1.jsx)("div", { className: "tree-widget-tree-content", children: (0, jsx_runtime_1.jsx)(AutoSizer_1.AutoSizer, { children: ({ width, height }) => ((0, jsx_runtime_1.jsx)(CategoriesTree_1.CategoryTree, { ...props, categories: categories, width: width, height: height, filterInfo: { filter: filterString, activeMatchIndex: searchOptions.activeMatchIndex }, onFilterApplied: onFilterApplied, activeView: props.viewport })) }) })] }));
83
+ (0, jsx_runtime_1.jsx)(ShowAllButton, { viewport: props.viewport, categories: categories, filteredCategories: filteredCategories, density: props.density }, "show-all-btn"),
84
+ (0, jsx_runtime_1.jsx)(HideAllButton, { viewport: props.viewport, categories: categories, filteredCategories: filteredCategories, density: props.density }, "hide-all-btn"),
85
+ (0, jsx_runtime_1.jsx)(InvertAllButton, { viewport: props.viewport, categories: categories, filteredCategories: filteredCategories, density: props.density }, "invert-all-btn"),
86
+ ] }), (0, jsx_runtime_1.jsx)("div", { className: contentClassName, children: (0, jsx_runtime_1.jsx)(AutoSizer_1.AutoSizer, { children: ({ width, height }) => ((0, jsx_runtime_1.jsx)(CategoriesTree_1.CategoryTree, { ...props, categories: categories, width: width, height: height, filterInfo: { filter: filterString, activeMatchIndex: searchOptions.activeMatchIndex }, onFilterApplied: onFilterApplied, activeView: props.viewport })) }) })] }));
80
87
  }
81
88
  async function getFilteredCategories(filteredProvider) {
82
89
  const filteredCategories = [];
@@ -87,19 +94,21 @@ async function getFilteredCategories(filteredProvider) {
87
94
  }
88
95
  const filteredCategoryId = CategoryVisibilityHandler_1.CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(node.key);
89
96
  const filteredSubCategoriesIds = node.hasChildren
90
- ? (await filteredProvider.getNodes(node)).filter(presentation_components_1.isPresentationTreeNodeItem).map((child) => CategoryVisibilityHandler_1.CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(child.key))
97
+ ? (await filteredProvider.getNodes(node))
98
+ .filter(presentation_components_1.isPresentationTreeNodeItem)
99
+ .map((child) => CategoryVisibilityHandler_1.CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(child.key))
91
100
  : [];
92
101
  filteredCategories.push({ categoryId: filteredCategoryId, subCategoryIds: filteredSubCategoriesIds });
93
102
  }
94
103
  return filteredCategories;
95
104
  }
96
105
  function ShowAllButton(props) {
97
- return ((0, jsx_runtime_1.jsx)(itwinui_react_1.IconButton, { size: "small", styleType: "borderless", title: TreeWidget_1.TreeWidget.translate("showAll"), onClick: () => void (0, CategoryVisibilityHandler_1.showAllCategories)((props.filteredCategories ?? props.categories).map((category) => category.categoryId), props.viewport), children: (0, jsx_runtime_1.jsx)(itwinui_icons_react_1.SvgVisibilityShow, {}) }));
106
+ return ((0, jsx_runtime_1.jsx)(itwinui_react_1.IconButton, { size: props.density === "enlarged" ? "large" : "small", styleType: "borderless", title: TreeWidget_1.TreeWidget.translate("showAll"), onClick: () => void (0, CategoryVisibilityHandler_1.showAllCategories)((props.filteredCategories ?? props.categories).map((category) => category.categoryId), props.viewport), children: (0, jsx_runtime_1.jsx)(itwinui_icons_react_1.SvgVisibilityShow, {}) }));
98
107
  }
99
108
  function HideAllButton(props) {
100
- return ((0, jsx_runtime_1.jsx)(itwinui_react_1.IconButton, { size: "small", styleType: "borderless", title: TreeWidget_1.TreeWidget.translate("hideAll"), onClick: () => void (0, CategoryVisibilityHandler_1.hideAllCategories)((props.filteredCategories ?? props.categories).map((category) => category.categoryId), props.viewport), children: (0, jsx_runtime_1.jsx)(itwinui_icons_react_1.SvgVisibilityHide, {}) }));
109
+ return ((0, jsx_runtime_1.jsx)(itwinui_react_1.IconButton, { size: props.density === "enlarged" ? "large" : "small", styleType: "borderless", title: TreeWidget_1.TreeWidget.translate("hideAll"), onClick: () => void (0, CategoryVisibilityHandler_1.hideAllCategories)((props.filteredCategories ?? props.categories).map((category) => category.categoryId), props.viewport), children: (0, jsx_runtime_1.jsx)(itwinui_icons_react_1.SvgVisibilityHide, {}) }));
101
110
  }
102
111
  function InvertAllButton(props) {
103
- return ((0, jsx_runtime_1.jsx)(itwinui_react_1.IconButton, { title: TreeWidget_1.TreeWidget.translate("invert"), size: "small", styleType: "borderless", onClick: () => void (0, CategoryVisibilityHandler_1.invertAllCategories)(props.filteredCategories ?? props.categories, props.viewport), children: (0, jsx_runtime_1.jsx)(itwinui_icons_react_1.SvgVisibilityHalf, {}) }));
112
+ return ((0, jsx_runtime_1.jsx)(itwinui_react_1.IconButton, { title: TreeWidget_1.TreeWidget.translate("invert"), size: props.density === "enlarged" ? "large" : "small", styleType: "borderless", onClick: () => void (0, CategoryVisibilityHandler_1.invertAllCategories)(props.filteredCategories ?? props.categories, props.viewport), children: (0, jsx_runtime_1.jsx)(itwinui_icons_react_1.SvgVisibilityHalf, {}) }));
104
113
  }
105
114
  //# sourceMappingURL=CategoriesTreeComponent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CategoriesTreeComponent.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoriesTreeComponent.tsx"],"names":[],"mappings":";;;;AAAA;;;+FAG+F;AAE/F,sCAAoC;AACpC,iCAAsD;AACtD,oDAAkF;AAClF,wDAAiD;AACjD,oEAAqG;AACrG,wDAAkD;AAClD,4EAA4E;AAC5E,oDAAiD;AACjD,6DAA0D;AAC1D,iEAAiE;AACjE,qDAAkD;AAClD,qDAAgD;AAChD,2EAAkJ;AAgDlJ;;;;GAIG;AACI,MAAM,uBAAuB,GAAG,CAAC,KAAmC,EAAE,EAAE;IAC7E,MAAM,MAAM,GAAG,IAAA,uCAAyB,GAAE,CAAC;IAC3C,MAAM,QAAQ,GAAG,IAAA,+BAAiB,GAAE,CAAC;IAErC,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE;QACxB,OAAO,IAAI,CAAC;KACb;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ACd,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,KAAsC;IAC3D,OAAO,CACL,uBAAC,0BAAU,IACT,IAAI,EAAC,OAAO,EACZ,SAAS,EAAC,YAAY,EACtB,KAAK,EAAE,uBAAU,CAAC,SAAS,CAAC,SAAS,CAAC,EACtC,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,IAAA,6CAAiB,EAAC,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,uBAAC,uCAAiB,KAAG,GACV,CACd,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,KAAsC;IAC7D,OAAO,CACL,uBAAC,0BAAU,IACT,KAAK,EAAE,uBAAU,CAAC,SAAS,CAAC,QAAQ,CAAC,EACrC,IAAI,EAAC,OAAO,EACZ,SAAS,EAAC,YAAY,EACtB,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,IAAA,+CAAmB,EAAC,KAAK,CAAC,kBAAkB,IAAI,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC,YAErG,uBAAC,uCAAiB,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,sCAAoC;AACpC,iCAAsD;AACtD,oDAAkF;AAClF,wDAAiD;AACjD,oEAAqG;AACrG,wDAAkD;AAClD,4EAA4E;AAC5E,oDAAiD;AACjD,6DAA0D;AAC1D,iEAAiE;AACjE,qDAAkD;AAClD,qDAAgD;AAChD,2EAAkJ;AAOlJ,4DAAoC;AAoCpC;;;;GAIG;AACI,MAAM,uBAAuB,GAAG,CAAC,KAAmC,EAAE,EAAE;IAC7E,MAAM,MAAM,GAAG,IAAA,uCAAyB,GAAE,CAAC;IAC3C,MAAM,QAAQ,GAAG,IAAA,+BAAiB,GAAE,CAAC;IAErC,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE;QACxB,OAAO,IAAI,CAAC;KACb;IAED,OAAO,uBAAC,2BAA2B,OAAK,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAI,CAAC;AACxF,CAAC,CAAC;AATW,QAAA,uBAAuB,2BASlC;AAEF;;;GAGG;AACH,+BAAuB,CAAC,aAAa,GAAG,aAAa,CAAC;AAEtD;;;GAGG;AACH,+BAAuB,CAAC,aAAa,GAAG,aAAa,CAAC;AAEtD;;;GAGG;AACH,+BAAuB,CAAC,eAAe,GAAG,eAAe,CAAC;AAE1D;;;GAGG;AACH,+BAAuB,CAAC,EAAE,GAAG,iBAAiB,CAAC;AAE/C;;;GAGG;AACH,+BAAuB,CAAC,QAAQ,GAAG,GAAG,EAAE,CAAC,uBAAU,CAAC,SAAS,CAAC,YAAY,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,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,EACtD,SAAS,EAAC,YAAY,EACtB,KAAK,EAAE,uBAAU,CAAC,SAAS,CAAC,SAAS,CAAC,EACtC,OAAO,EAAE,GAAG,EAAE,CACZ,KAAK,IAAA,6CAAiB,EACpB,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,uBAAC,uCAAiB,KAAG,GACV,CACd,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,KAAsC;IAC7D,OAAO,CACL,uBAAC,0BAAU,IACT,KAAK,EAAE,uBAAU,CAAC,SAAS,CAAC,QAAQ,CAAC,EACrC,IAAI,EAAE,KAAK,CAAC,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,EACtD,SAAS,EAAC,YAAY,EACtB,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,IAAA,+CAAmB,EAAC,KAAK,CAAC,kBAAkB,IAAI,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC,YAErG,uBAAC,uCAAiB,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\";\nimport classNames from \"classnames\";\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 const contentClassName = classNames(\"tree-widget-tree-content\", props.density === \"enlarged\" && \"enlarge\");\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 density={props.density}\n >\n {props.headerButtons\n ? props.headerButtons.map((btn, index) => <Fragment key={index}>{btn({ viewport: props.viewport, categories, filteredCategories })}</Fragment>)\n : [\n <ShowAllButton\n viewport={props.viewport}\n categories={categories}\n filteredCategories={filteredCategories}\n key=\"show-all-btn\"\n density={props.density}\n />,\n <HideAllButton\n viewport={props.viewport}\n categories={categories}\n filteredCategories={filteredCategories}\n key=\"hide-all-btn\"\n density={props.density}\n />,\n <InvertAllButton\n viewport={props.viewport}\n categories={categories}\n filteredCategories={filteredCategories}\n key=\"invert-all-btn\"\n density={props.density}\n />,\n ]}\n </TreeHeader>\n <div className={contentClassName}>\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={props.density === \"enlarged\" ? \"large\" : \"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={props.density === \"enlarged\" ? \"large\" : \"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={props.density === \"enlarged\" ? \"large\" : \"small\"}\n styleType=\"borderless\"\n onClick={() => void invertAllCategories(props.filteredCategories ?? props.categories, props.viewport)}\n >\n <SvgVisibilityHalf />\n </IconButton>\n );\n}\n"]}
@@ -44,8 +44,8 @@ export declare class CategoryVisibilityHandler implements IVisibilityHandler {
44
44
  onVisibilityChange: BeEvent<VisibilityChangeListener>;
45
45
  getVisibilityStatus(node: TreeNodeItem): VisibilityStatus;
46
46
  changeVisibility(node: TreeNodeItem, shouldDisplay: boolean): Promise<void>;
47
- getSubCategoryVisibility(id: string): "hidden" | "visible";
48
- getCategoryVisibility(id: string): "hidden" | "visible";
47
+ getSubCategoryVisibility(id: string): "visible" | "hidden";
48
+ getCategoryVisibility(id: string): "visible" | "hidden";
49
49
  getParent(key: string): CategoryInfo | undefined;
50
50
  private onDisplayStyleChanged;
51
51
  private onViewedCategoriesChanged;