@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
@@ -1,8 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
6
  import "../VisibilityTreeBase.scss";
7
7
  import { Fragment, useEffect, useState } from "react";
8
8
  import { useActiveIModelConnection, useActiveViewport } from "@itwin/appui-react";
@@ -16,6 +16,7 @@ import { useTreeFilteringState } from "../../TreeFilteringState";
16
16
  import { AutoSizer } from "../../utils/AutoSizer";
17
17
  import { CategoryTree } from "./CategoriesTree";
18
18
  import { CategoryVisibilityHandler, hideAllCategories, invertAllCategories, showAllCategories, useCategories } from "./CategoryVisibilityHandler";
19
+ import classNames from "classnames";
19
20
  /**
20
21
  * A component that renders [[CategoriesTree]] and a header with filtering capabilities
21
22
  * and header buttons.
@@ -27,7 +28,7 @@ export const CategoriesTreeComponent = (props) => {
27
28
  if (!iModel || !viewport) {
28
29
  return null;
29
30
  }
30
- return (_jsx(CategoriesTreeComponentImpl, { ...props, iModel: iModel, viewport: viewport }));
31
+ return _jsx(CategoriesTreeComponentImpl, { ...props, iModel: iModel, viewport: viewport });
31
32
  };
32
33
  /**
33
34
  * Renders a "Show all" button that enables display of all categories and their subcategories.
@@ -57,22 +58,25 @@ CategoriesTreeComponent.getLabel = () => TreeWidget.translate("categories");
57
58
  function CategoriesTreeComponentImpl(props) {
58
59
  const categories = useCategories(IModelApp.viewManager, props.iModel, props.viewport);
59
60
  const [filteredCategories, setFilteredCategories] = useState();
60
- const { searchOptions, filterString, onFilterApplied, filteredProvider, } = useTreeFilteringState();
61
+ const { searchOptions, filterString, onFilterApplied, filteredProvider } = useTreeFilteringState();
62
+ const contentClassName = classNames("tree-widget-tree-content", props.density === "enlarged" && "enlarge");
61
63
  useEffect(() => {
62
- (async () => {
63
- if (filteredProvider)
64
- setFilteredCategories((await getFilteredCategories(filteredProvider)));
65
- else
64
+ void (async () => {
65
+ if (filteredProvider) {
66
+ setFilteredCategories(await getFilteredCategories(filteredProvider));
67
+ }
68
+ else {
66
69
  setFilteredCategories(undefined);
70
+ }
67
71
  })();
68
72
  }, [filteredProvider]);
69
- return (_jsxs("div", { className: "tree-widget-tree-with-header", children: [_jsx(TreeHeader, { onFilterClear: searchOptions.onFilterCancel, onFilterStart: searchOptions.onFilterStart, onSelectedChanged: searchOptions.onResultSelectedChanged, resultCount: searchOptions.matchedResultCount, selectedIndex: searchOptions.activeMatchIndex, children: props.headerButtons
73
+ return (_jsxs("div", { className: "tree-widget-tree-with-header", children: [_jsx(TreeHeader, { onFilterClear: searchOptions.onFilterCancel, onFilterStart: searchOptions.onFilterStart, onSelectedChanged: searchOptions.onResultSelectedChanged, resultCount: searchOptions.matchedResultCount, selectedIndex: searchOptions.activeMatchIndex, density: props.density, children: props.headerButtons
70
74
  ? props.headerButtons.map((btn, index) => _jsx(Fragment, { children: btn({ viewport: props.viewport, categories, filteredCategories }) }, index))
71
75
  : [
72
- _jsx(ShowAllButton, { viewport: props.viewport, categories: categories, filteredCategories: filteredCategories }, "show-all-btn"),
73
- _jsx(HideAllButton, { viewport: props.viewport, categories: categories, filteredCategories: filteredCategories }, "hide-all-btn"),
74
- _jsx(InvertAllButton, { viewport: props.viewport, categories: categories, filteredCategories: filteredCategories }, "invert-all-btn"),
75
- ] }), _jsx("div", { className: "tree-widget-tree-content", children: _jsx(AutoSizer, { children: ({ width, height }) => (_jsx(CategoryTree, { ...props, categories: categories, width: width, height: height, filterInfo: { filter: filterString, activeMatchIndex: searchOptions.activeMatchIndex }, onFilterApplied: onFilterApplied, activeView: props.viewport })) }) })] }));
76
+ _jsx(ShowAllButton, { viewport: props.viewport, categories: categories, filteredCategories: filteredCategories, density: props.density }, "show-all-btn"),
77
+ _jsx(HideAllButton, { viewport: props.viewport, categories: categories, filteredCategories: filteredCategories, density: props.density }, "hide-all-btn"),
78
+ _jsx(InvertAllButton, { viewport: props.viewport, categories: categories, filteredCategories: filteredCategories, density: props.density }, "invert-all-btn"),
79
+ ] }), _jsx("div", { className: contentClassName, children: _jsx(AutoSizer, { children: ({ width, height }) => (_jsx(CategoryTree, { ...props, categories: categories, width: width, height: height, filterInfo: { filter: filterString, activeMatchIndex: searchOptions.activeMatchIndex }, onFilterApplied: onFilterApplied, activeView: props.viewport })) }) })] }));
76
80
  }
77
81
  async function getFilteredCategories(filteredProvider) {
78
82
  const filteredCategories = [];
@@ -83,19 +87,21 @@ async function getFilteredCategories(filteredProvider) {
83
87
  }
84
88
  const filteredCategoryId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(node.key);
85
89
  const filteredSubCategoriesIds = node.hasChildren
86
- ? (await filteredProvider.getNodes(node)).filter(isPresentationTreeNodeItem).map((child) => CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(child.key))
90
+ ? (await filteredProvider.getNodes(node))
91
+ .filter(isPresentationTreeNodeItem)
92
+ .map((child) => CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(child.key))
87
93
  : [];
88
94
  filteredCategories.push({ categoryId: filteredCategoryId, subCategoryIds: filteredSubCategoriesIds });
89
95
  }
90
96
  return filteredCategories;
91
97
  }
92
98
  function ShowAllButton(props) {
93
- return (_jsx(IconButton, { size: "small", styleType: "borderless", title: TreeWidget.translate("showAll"), onClick: () => void showAllCategories((props.filteredCategories ?? props.categories).map((category) => category.categoryId), props.viewport), children: _jsx(SvgVisibilityShow, {}) }));
99
+ return (_jsx(IconButton, { size: props.density === "enlarged" ? "large" : "small", styleType: "borderless", title: TreeWidget.translate("showAll"), onClick: () => void showAllCategories((props.filteredCategories ?? props.categories).map((category) => category.categoryId), props.viewport), children: _jsx(SvgVisibilityShow, {}) }));
94
100
  }
95
101
  function HideAllButton(props) {
96
- return (_jsx(IconButton, { size: "small", styleType: "borderless", title: TreeWidget.translate("hideAll"), onClick: () => void hideAllCategories((props.filteredCategories ?? props.categories).map((category) => category.categoryId), props.viewport), children: _jsx(SvgVisibilityHide, {}) }));
102
+ return (_jsx(IconButton, { size: props.density === "enlarged" ? "large" : "small", styleType: "borderless", title: TreeWidget.translate("hideAll"), onClick: () => void hideAllCategories((props.filteredCategories ?? props.categories).map((category) => category.categoryId), props.viewport), children: _jsx(SvgVisibilityHide, {}) }));
97
103
  }
98
104
  function InvertAllButton(props) {
99
- return (_jsx(IconButton, { title: TreeWidget.translate("invert"), size: "small", styleType: "borderless", onClick: () => void invertAllCategories(props.filteredCategories ?? props.categories, props.viewport), children: _jsx(SvgVisibilityHalf, {}) }));
105
+ return (_jsx(IconButton, { title: TreeWidget.translate("invert"), size: props.density === "enlarged" ? "large" : "small", styleType: "borderless", onClick: () => void invertAllCategories(props.filteredCategories ?? props.categories, props.viewport), children: _jsx(SvgVisibilityHalf, {}) }));
100
106
  }
101
107
  //# 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,OAAO,4BAA4B,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACrG,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,u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,EACZ,SAAS,EAAC,YAAY,EACtB,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,SAAS,CAAC,EACtC,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,iBAAiB,CAAC,CAAC,KAAK,CAAC,kBAAkB,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,YAE5I,KAAC,iBAAiB,KAAG,GACV,CACd,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,KAAsC;IAC3D,OAAO,CACL,KAAC,UAAU,IACT,IAAI,EAAC,OAAO,EACZ,SAAS,EAAC,YAAY,EACtB,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,SAAS,CAAC,EACtC,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,iBAAiB,CAAC,CAAC,KAAK,CAAC,kBAAkB,IAAI,KAAK,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC,QAAQ,CAAC,YAE5I,KAAC,iBAAiB,KAAG,GACV,CACd,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,KAAsC;IAC7D,OAAO,CACL,KAAC,UAAU,IACT,KAAK,EAAE,UAAU,CAAC,SAAS,CAAC,QAAQ,CAAC,EACrC,IAAI,EAAC,OAAO,EACZ,SAAS,EAAC,YAAY,EACtB,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,mBAAmB,CAAC,KAAK,CAAC,kBAAkB,IAAI,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC,YAErG,KAAC,iBAAiB,KAAG,GACV,CACd,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport \"../VisibilityTreeBase.scss\";\nimport { Fragment, useEffect, useState } from \"react\";\nimport { useActiveIModelConnection, useActiveViewport } from \"@itwin/appui-react\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { SvgVisibilityHalf, SvgVisibilityHide, SvgVisibilityShow } from \"@itwin/itwinui-icons-react\";\nimport { IconButton } from \"@itwin/itwinui-react\";\nimport { isPresentationTreeNodeItem } from \"@itwin/presentation-components\";\nimport { TreeWidget } from \"../../../TreeWidget\";\nimport { TreeHeader } from \"../../tree-header/TreeHeader\";\nimport { useTreeFilteringState } from \"../../TreeFilteringState\";\nimport { AutoSizer } from \"../../utils/AutoSizer\";\nimport { CategoryTree } from \"./CategoriesTree\";\nimport { CategoryVisibilityHandler, hideAllCategories, invertAllCategories, showAllCategories, useCategories } from \"./CategoryVisibilityHandler\";\n\nimport type { IModelConnection, ScreenViewport } from \"@itwin/core-frontend\";\nimport type { IPresentationTreeDataProvider } from \"@itwin/presentation-components\";\nimport type { TreeHeaderButtonProps } from \"../../tree-header/TreeHeader\";\nimport type { CategoryTreeProps } from \"./CategoriesTree\";\nimport type { CategoryInfo } from \"./CategoryVisibilityHandler\";\n\n/**\n * Props that get passed to [[CategoriesTreeComponent]] header button renderer.\n * @see CategoriesTreeComponentProps.headerButtons\n * @public\n */\nexport interface CategoriesTreeHeaderButtonProps extends TreeHeaderButtonProps {\n /** A list of categories available in the iModel */\n categories: CategoryInfo[];\n /** In case the tree is filtered, a list of filtered categories. */\n filteredCategories?: CategoryInfo[];\n}\n\n/**\n * Props for [[CategoriesTreeComponent]].\n * @public\n */\nexport interface CategoriesTreeComponentProps extends Omit<CategoryTreeProps,\n| \"iModel\"\n| \"activeView\"\n| \"width\"\n| \"height\"\n| \"filterInfo\"\n| \"onFilterApplied\"\n| \"categories\"\n| \"categoryVisibilityHandler\"\n| \"viewManager\"\n> {\n /**\n * Renderers of header buttons. Defaults to:\n * ```ts\n * [\n * CategoriesTreeComponent.ShowAllButton,\n * CategoriesTreeComponent.HideAllButton,\n * CategoriesTreeComponent.InvertAllButton,\n * ]\n * ```\n */\n headerButtons?: Array<(props: CategoriesTreeHeaderButtonProps) => React.ReactNode>;\n}\n\n/**\n * A component that renders [[CategoriesTree]] and a header with filtering capabilities\n * and header buttons.\n * @public\n */\nexport const CategoriesTreeComponent = (props: CategoriesTreeComponentProps) => {\n const iModel = useActiveIModelConnection();\n const viewport = useActiveViewport();\n\n if (!iModel || !viewport) {\n return null;\n }\n\n return (\n <CategoriesTreeComponentImpl {...props} iModel={iModel} viewport={viewport} />\n );\n};\n\n/**\n * Renders a \"Show all\" button that enables display of all categories and their subcategories.\n * @public\n */\nCategoriesTreeComponent.ShowAllButton = ShowAllButton;\n\n/**\n * Renders a \"Hide all\" button that disables display of all categories.\n * @public\n */\nCategoriesTreeComponent.HideAllButton = HideAllButton;\n\n/**\n * Renders an \"Invert all\" button that inverts display of all categories.\n * @public\n */\nCategoriesTreeComponent.InvertAllButton = InvertAllButton;\n\n/**\n * Id of the component. May be used when a creating a [[TreeDefinition]] for [[SelectableTree]].\n * @public\n */\nCategoriesTreeComponent.id = \"categories-tree\";\n\n/**\n * Label of the component. May be used when a creating a [[TreeDefinition]] for [[SelectableTree]].\n * @public\n */\nCategoriesTreeComponent.getLabel = () => TreeWidget.translate(\"categories\");\n\nfunction CategoriesTreeComponentImpl(props: CategoriesTreeComponentProps & { iModel: IModelConnection, viewport: ScreenViewport }) {\n const categories = useCategories(IModelApp.viewManager, props.iModel, props.viewport);\n const [filteredCategories, setFilteredCategories] = useState<CategoryInfo[]>();\n const {\n searchOptions,\n filterString,\n onFilterApplied,\n filteredProvider,\n } = useTreeFilteringState();\n\n useEffect(() => {\n (async () => {\n if (filteredProvider)\n setFilteredCategories((await getFilteredCategories(filteredProvider)));\n else\n setFilteredCategories(undefined);\n })();\n }, [filteredProvider]);\n\n return (\n <div className=\"tree-widget-tree-with-header\">\n <TreeHeader\n onFilterClear={searchOptions.onFilterCancel}\n onFilterStart={searchOptions.onFilterStart}\n onSelectedChanged={searchOptions.onResultSelectedChanged}\n resultCount={searchOptions.matchedResultCount}\n selectedIndex={searchOptions.activeMatchIndex}\n >\n {props.headerButtons\n ? props.headerButtons.map(\n (btn, index) =>\n <Fragment key={index}>\n {btn({ viewport: props.viewport, categories, filteredCategories })}\n </Fragment>\n )\n : [\n <ShowAllButton viewport={props.viewport} categories={categories} filteredCategories={filteredCategories} key=\"show-all-btn\" />,\n <HideAllButton viewport={props.viewport} categories={categories} filteredCategories={filteredCategories} key=\"hide-all-btn\" />,\n <InvertAllButton viewport={props.viewport} categories={categories} filteredCategories={filteredCategories} key=\"invert-all-btn\" />,\n ]\n }\n </TreeHeader>\n <div className=\"tree-widget-tree-content\">\n <AutoSizer>\n {({ width, height }) => (\n <CategoryTree\n {...props}\n categories={categories}\n width={width}\n height={height}\n filterInfo={{ filter: filterString, activeMatchIndex: searchOptions.activeMatchIndex }}\n onFilterApplied={onFilterApplied}\n activeView={props.viewport}\n />\n )}\n </AutoSizer>\n </div>\n </div>\n );\n}\n\nasync function getFilteredCategories(filteredProvider: IPresentationTreeDataProvider) {\n const filteredCategories: CategoryInfo[] = [];\n const nodes = await filteredProvider.getNodes();\n for (const node of nodes) {\n if (!isPresentationTreeNodeItem(node)) {\n continue;\n }\n const filteredCategoryId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(node.key);\n const filteredSubCategoriesIds = node.hasChildren\n ? (await filteredProvider.getNodes(node)).filter(isPresentationTreeNodeItem).map((child) => CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(child.key))\n : [];\n filteredCategories.push({ categoryId: filteredCategoryId, subCategoryIds: filteredSubCategoriesIds });\n }\n return filteredCategories;\n}\n\nfunction ShowAllButton(props: CategoriesTreeHeaderButtonProps) {\n return (\n <IconButton\n size=\"small\"\n styleType=\"borderless\"\n title={TreeWidget.translate(\"showAll\")}\n onClick={() => void showAllCategories((props.filteredCategories ?? props.categories).map((category) => category.categoryId), props.viewport)}\n >\n <SvgVisibilityShow />\n </IconButton>\n );\n}\n\nfunction HideAllButton(props: CategoriesTreeHeaderButtonProps) {\n return (\n <IconButton\n size=\"small\"\n styleType=\"borderless\"\n title={TreeWidget.translate(\"hideAll\")}\n onClick={() => void hideAllCategories((props.filteredCategories ?? props.categories).map((category) => category.categoryId), props.viewport)}\n >\n <SvgVisibilityHide />\n </IconButton>\n );\n}\n\nfunction InvertAllButton(props: CategoriesTreeHeaderButtonProps) {\n return (\n <IconButton\n title={TreeWidget.translate(\"invert\")}\n size=\"small\"\n styleType=\"borderless\"\n onClick={() => void invertAllCategories(props.filteredCategories ?? props.categories, props.viewport)}\n >\n <SvgVisibilityHalf />\n </IconButton>\n );\n}\n"]}
1
+ {"version":3,"file":"CategoriesTreeComponent.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoriesTreeComponent.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,4BAA4B,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACrG,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,YAAY,E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O,CACL,KAAC,UAAU,IACT,KAAK,EAAE,UAAU,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,mBAAmB,CAAC,KAAK,CAAC,kBAAkB,IAAI,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,QAAQ,CAAC,YAErG,KAAC,iBAAiB,KAAG,GACV,CACd,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport \"../VisibilityTreeBase.scss\";\nimport { Fragment, useEffect, useState } from \"react\";\nimport { useActiveIModelConnection, useActiveViewport } from \"@itwin/appui-react\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { SvgVisibilityHalf, SvgVisibilityHide, SvgVisibilityShow } from \"@itwin/itwinui-icons-react\";\nimport { IconButton } from \"@itwin/itwinui-react\";\nimport { isPresentationTreeNodeItem } from \"@itwin/presentation-components\";\nimport { TreeWidget } from \"../../../TreeWidget\";\nimport { TreeHeader } from \"../../tree-header/TreeHeader\";\nimport { useTreeFilteringState } from \"../../TreeFilteringState\";\nimport { AutoSizer } from \"../../utils/AutoSizer\";\nimport { CategoryTree } from \"./CategoriesTree\";\nimport { CategoryVisibilityHandler, hideAllCategories, invertAllCategories, showAllCategories, useCategories } from \"./CategoryVisibilityHandler\";\n\nimport type { IModelConnection, ScreenViewport } from \"@itwin/core-frontend\";\nimport type { IPresentationTreeDataProvider } from \"@itwin/presentation-components\";\nimport type { TreeHeaderButtonProps } from \"../../tree-header/TreeHeader\";\nimport type { CategoryTreeProps } from \"./CategoriesTree\";\nimport type { CategoryInfo } from \"./CategoryVisibilityHandler\";\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;
@@ -1,7 +1,7 @@
1
1
  /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
- * See LICENSE.md in the project root for license terms and full copyright notice.
4
- *--------------------------------------------------------------------------------------------*/
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
5
  import { useMemo } from "react";
6
6
  import { useAsyncValue } from "@itwin/components-react";
7
7
  import { BeEvent } from "@itwin/core-bentley";
@@ -51,23 +51,26 @@ export class CategoryVisibilityHandler {
51
51
  }
52
52
  getVisibilityStatus(node) {
53
53
  const nodeKey = isPresentationTreeNodeItem(node) ? node.key : undefined;
54
- if (!nodeKey)
54
+ if (!nodeKey) {
55
55
  return { state: "hidden", isDisabled: true };
56
+ }
56
57
  const instanceId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);
57
58
  return { state: node.parentId ? this.getSubCategoryVisibility(instanceId) : this.getCategoryVisibility(instanceId) };
58
59
  }
59
60
  async changeVisibility(node, shouldDisplay) {
60
61
  const nodeKey = isPresentationTreeNodeItem(node) ? node.key : undefined;
61
- if (!nodeKey)
62
+ if (!nodeKey) {
62
63
  return;
64
+ }
63
65
  // handle subcategory visibility change
64
66
  if (node.parentId) {
65
67
  const childId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);
66
68
  // istanbul ignore next
67
69
  const parentId = this.getParent(childId)?.categoryId;
68
70
  // make sure parent category is enabled
69
- if (shouldDisplay && parentId)
71
+ if (shouldDisplay && parentId) {
70
72
  await this.enableCategory([parentId], true, false);
73
+ }
71
74
  this.enableSubCategory(childId, shouldDisplay);
72
75
  return;
73
76
  }
@@ -76,8 +79,9 @@ export class CategoryVisibilityHandler {
76
79
  }
77
80
  getSubCategoryVisibility(id) {
78
81
  const parentItem = this.getParent(id);
79
- if (!parentItem)
82
+ if (!parentItem) {
80
83
  return "hidden";
84
+ }
81
85
  const isVisible = this._activeView.view.viewsCategory(parentItem.categoryId) && this._activeView.isSubCategoryVisible(id);
82
86
  return isVisible ? "visible" : "hidden";
83
87
  }
@@ -87,23 +91,23 @@ export class CategoryVisibilityHandler {
87
91
  getParent(key) {
88
92
  for (const category of this._categories) {
89
93
  // istanbul ignore else
90
- if (category.subCategoryIds) {
91
- if (category.subCategoryIds.indexOf(key) !== -1)
92
- return category;
94
+ if (category.subCategoryIds && category.subCategoryIds.indexOf(key) !== -1) {
95
+ return category;
93
96
  }
94
97
  }
95
98
  return undefined;
96
99
  }
97
100
  onVisibilityChangeInternal() {
98
- if (this._pendingVisibilityChange)
101
+ if (this._pendingVisibilityChange) {
99
102
  return;
103
+ }
100
104
  this._pendingVisibilityChange = setTimeout(() => {
101
105
  this.onVisibilityChange.raiseEvent();
102
106
  this._pendingVisibilityChange = undefined;
103
107
  }, 0);
104
108
  }
105
109
  static getInstanceIdFromTreeNodeKey(nodeKey) {
106
- return (NodeKey.isInstancesNodeKey(nodeKey) && nodeKey.instanceKeys.length > 0) ? nodeKey.instanceKeys[0].id : /* istanbul ignore next */ "";
110
+ return NodeKey.isInstancesNodeKey(nodeKey) && nodeKey.instanceKeys.length > 0 ? nodeKey.instanceKeys[0].id : /* istanbul ignore next */ "";
107
111
  }
108
112
  async enableCategory(ids, enabled, enableAllSubCategories = true) {
109
113
  await enableCategory(this._viewManager, this._imodel, ids, enabled, this._useAllViewports, enableAllSubCategories);
@@ -142,8 +146,9 @@ export async function invertAllCategories(categories, viewport) {
142
146
  }
143
147
  // First, we need to check if at least one subcategory is disabled. If it is true, then only subcategories should change display, not categories.
144
148
  if (category.subCategoryIds?.some((subCategory) => !viewport.isSubCategoryVisible(subCategory))) {
145
- for (const subCategory of category.subCategoryIds)
149
+ for (const subCategory of category.subCategoryIds) {
146
150
  viewport.isSubCategoryVisible(subCategory) ? enabledSubCategories.push(subCategory) : disabledSubCategories.push(subCategory);
151
+ }
147
152
  }
148
153
  else {
149
154
  enabled.push(category.categoryId);
@@ -1 +1 @@
1
- {"version":3,"file":"CategoryVisibilityHandler.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoryVisibilityHandler.tsx"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAM7G,MAAM,sBAAsB,GAAmB,EAAE,CAAC;AAElD;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,WAAwB,EAAE,MAAwB,EAAE,IAAe;IAC/F,MAAM,WAAW,GAAG,IAAI,IAAI,WAAW,CAAC,gBAAgB,EAAE,CAAC;IAC3D,MAAM,iBAAiB,GAAG,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,0BAA0B,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IACtH,OAAO,aAAa,CAAC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,QAAQ,CAAC,UAAU,CAAC,EAAE;YACrD,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;YACnC,SAAS;SACV;QACD,iJAAiJ;QACjJ,IAAI,QAAQ,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC,EAAE;YAC/F,KAAK,MAAM,WAAW,IAAI,QAAQ,CAAC,cAAc;gBAC/C,QAAQ,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;SACjI;aAAM;YACL,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;SACnC;KACF;IAED,kBAAkB;IAClB,oBAAoB,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,iBAAiB,CAC7D,SAAS,CAAC,WAAW,EACrB,WAAW,EACX,KAAK,EACL,IAAI,CACL,CAAC,CAAC;IAEH,MAAM,cAAc,CAClB,SAAS,CAAC,WAAW,EACrB,QAAQ,CAAC,MAAM,EACf,OAAO,EACP,KAAK,EACL,IAAI,CACL,CAAC;IAEF,kBAAkB;IAClB,qBAAqB,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,iBAAiB,CAC9D,SAAS,CAAC,WAAW,EACrB,WAAW,EACX,IAAI,EACJ,IAAI,CACL,CAAC,CAAC;IAEH,MAAM,cAAc,CAClB,SAAS,CAAC,WAAW,EACrB,QAAQ,CAAC,MAAM,EACf,QAAQ,EACR,IAAI,EACJ,IAAI,CACL,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 { useMemo } from \"react\";\nimport { useAsyncValue } from \"@itwin/components-react\";\nimport { BeEvent } from \"@itwin/core-bentley\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { NodeKey } from \"@itwin/presentation-common\";\nimport { isPresentationTreeNodeItem } from \"@itwin/presentation-components\";\nimport { enableCategory, enableSubCategory, loadCategoriesFromViewport } from \"../CategoriesVisibilityUtils\";\n\nimport type { TreeNodeItem } from \"@itwin/components-react\";\nimport type { IModelConnection, ViewManager, Viewport } from \"@itwin/core-frontend\";\nimport type { IVisibilityHandler, VisibilityChangeListener, VisibilityStatus } from \"../VisibilityTreeEventHandler\";\n\nconst EMPTY_CATEGORIES_ARRAY: CategoryInfo[] = [];\n\n/**\n * Loads categories from viewport or uses provided list of categories.\n * @internal\n */\nexport function useCategories(viewManager: ViewManager, imodel: IModelConnection, view?: Viewport) {\n const currentView = view || viewManager.getFirstOpenView();\n const categoriesPromise = useMemo(async () => loadCategoriesFromViewport(imodel, currentView), [imodel, currentView]);\n return useAsyncValue(categoriesPromise) ?? EMPTY_CATEGORIES_ARRAY;\n}\n\n/**\n * Data structure that describes category.\n * @public\n */\nexport interface CategoryInfo {\n categoryId: string;\n subCategoryIds?: string[];\n}\n\n/**\n * Params for creating a [[CategoryVisibilityHandler]].\n * @public\n */\nexport interface CategoryVisibilityHandlerParams {\n viewManager: ViewManager;\n imodel: IModelConnection;\n categories: CategoryInfo[];\n activeView: Viewport;\n allViewports?: boolean;\n}\n\n/**\n * An [[IVisibilityHandler]] implementation that knows how to determine and change visibility of categories\n * and subcategories.\n * @public\n */\nexport class CategoryVisibilityHandler implements IVisibilityHandler {\n private _viewManager: ViewManager;\n private _imodel: IModelConnection;\n private _pendingVisibilityChange: any | undefined;\n private _activeView: Viewport;\n private _useAllViewports: boolean;\n private _categories: CategoryInfo[];\n\n constructor(params: CategoryVisibilityHandlerParams) {\n this._viewManager = params.viewManager;\n this._imodel = params.imodel;\n this._activeView = params.activeView;\n // istanbul ignore next\n this._useAllViewports = params.allViewports ?? false;\n this._categories = params.categories;\n this._activeView.onDisplayStyleChanged.addListener(this.onDisplayStyleChanged);\n this._activeView.onViewedCategoriesChanged.addListener(this.onViewedCategoriesChanged);\n }\n\n public dispose() {\n this._activeView.onDisplayStyleChanged.removeListener(this.onDisplayStyleChanged);\n this._activeView.onViewedCategoriesChanged.removeListener(this.onViewedCategoriesChanged);\n clearTimeout(this._pendingVisibilityChange);\n }\n\n public onVisibilityChange = new BeEvent<VisibilityChangeListener>();\n\n public getVisibilityStatus(node: TreeNodeItem,): VisibilityStatus {\n const nodeKey = isPresentationTreeNodeItem(node) ? node.key : undefined;\n if (!nodeKey)\n return { state: \"hidden\", isDisabled: true };\n\n const instanceId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);\n return { state: node.parentId ? this.getSubCategoryVisibility(instanceId) : this.getCategoryVisibility(instanceId) };\n }\n\n public async changeVisibility(node: TreeNodeItem, shouldDisplay: boolean): Promise<void> {\n const nodeKey = isPresentationTreeNodeItem(node) ? node.key : undefined;\n if (!nodeKey)\n return;\n\n // handle subcategory visibility change\n if (node.parentId) {\n const childId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);\n // istanbul ignore next\n const parentId = this.getParent(childId)?.categoryId;\n\n // make sure parent category is enabled\n if (shouldDisplay && parentId)\n await this.enableCategory([parentId], true, false);\n\n this.enableSubCategory(childId, shouldDisplay);\n return;\n }\n\n const instanceId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);\n await this.enableCategory([instanceId], shouldDisplay, true);\n }\n\n public getSubCategoryVisibility(id: string) {\n const parentItem = this.getParent(id);\n if (!parentItem)\n return \"hidden\";\n\n const isVisible = this._activeView.view.viewsCategory(parentItem.categoryId) && this._activeView.isSubCategoryVisible(id);\n return isVisible ? \"visible\" : \"hidden\";\n }\n\n public getCategoryVisibility(id: string) {\n return this._activeView.view.viewsCategory(id) ? \"visible\" : \"hidden\";\n }\n\n public getParent(key: string): CategoryInfo | undefined {\n for (const category of this._categories) {\n // istanbul ignore else\n if (category.subCategoryIds) {\n if (category.subCategoryIds.indexOf(key) !== -1)\n return category;\n }\n }\n\n return undefined;\n }\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n private onDisplayStyleChanged = () => {\n this.onVisibilityChangeInternal();\n };\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n private onViewedCategoriesChanged = () => {\n this.onVisibilityChangeInternal();\n };\n\n private onVisibilityChangeInternal() {\n if (this._pendingVisibilityChange)\n return;\n\n this._pendingVisibilityChange = setTimeout(() => {\n this.onVisibilityChange.raiseEvent();\n this._pendingVisibilityChange = undefined;\n }, 0);\n }\n\n public static getInstanceIdFromTreeNodeKey(nodeKey: NodeKey) {\n return (NodeKey.isInstancesNodeKey(nodeKey) && nodeKey.instanceKeys.length > 0) ? nodeKey.instanceKeys[0].id : /* istanbul ignore next */ \"\";\n }\n\n public async enableCategory(ids: string[], enabled: boolean, enableAllSubCategories = true) {\n await enableCategory(this._viewManager, this._imodel, ids, enabled, this._useAllViewports, enableAllSubCategories);\n }\n\n public enableSubCategory(key: string, enabled: boolean) {\n enableSubCategory(this._viewManager, key, enabled, this._useAllViewports);\n }\n}\n\n/**\n * Enable display of all given categories.\n * @public\n */\nexport async function showAllCategories(categories: string[], viewport: Viewport) {\n await enableCategory(\n IModelApp.viewManager,\n viewport.iModel,\n categories,\n true,\n true\n );\n}\n\n/**\n * Disable display of all given categories.\n * @public\n */\nexport async function hideAllCategories(categories: string[], viewport: Viewport) {\n await enableCategory(\n IModelApp.viewManager,\n viewport.iModel,\n categories,\n false,\n true\n );\n}\n\n/**\n * Invert display of all given categories.\n * @public\n */\nexport async function invertAllCategories(categories: CategoryInfo[], viewport: Viewport) {\n const enabled: string[] = [];\n const disabled: string[] = [];\n const enabledSubCategories: string[] = [];\n const disabledSubCategories: string[] = [];\n\n for (const category of categories) {\n if (!viewport.view.viewsCategory(category.categoryId)) {\n disabled.push(category.categoryId);\n continue;\n }\n // First, we need to check if at least one subcategory is disabled. If it is true, then only subcategories should change display, not categories.\n if (category.subCategoryIds?.some((subCategory) => !viewport.isSubCategoryVisible(subCategory))) {\n for (const subCategory of category.subCategoryIds)\n viewport.isSubCategoryVisible(subCategory) ? enabledSubCategories.push(subCategory) : disabledSubCategories.push(subCategory);\n } else {\n enabled.push(category.categoryId);\n }\n }\n\n // Disable enabled\n enabledSubCategories.forEach((subCategory) => enableSubCategory(\n IModelApp.viewManager,\n subCategory,\n false,\n true\n ));\n\n await enableCategory(\n IModelApp.viewManager,\n viewport.iModel,\n enabled,\n false,\n true\n );\n\n // Enable disabled\n disabledSubCategories.forEach((subCategory) => enableSubCategory(\n IModelApp.viewManager,\n subCategory,\n true,\n true\n ));\n\n await enableCategory(\n IModelApp.viewManager,\n viewport.iModel,\n disabled,\n true,\n true\n );\n}\n"]}
1
+ {"version":3,"file":"CategoryVisibilityHandler.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoryVisibilityHandler.tsx"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AACrD,OAAO,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAM7G,MAAM,sBAAsB,GAAmB,EAAE,CAAC;AAElD;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,WAAwB,EAAE,MAAwB,EAAE,IAAe;IAC/F,MAAM,WAAW,GAAG,IAAI,IAAI,WAAW,CAAC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,IAAI,CAAC,CAAC,CAAC;IAElH,MAAM,cAAc,CAAC,SAAS,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AACrF,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useMemo } from \"react\";\nimport { useAsyncValue } from \"@itwin/components-react\";\nimport { BeEvent } from \"@itwin/core-bentley\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { NodeKey } from \"@itwin/presentation-common\";\nimport { isPresentationTreeNodeItem } from \"@itwin/presentation-components\";\nimport { enableCategory, enableSubCategory, loadCategoriesFromViewport } from \"../CategoriesVisibilityUtils\";\n\nimport type { TreeNodeItem } from \"@itwin/components-react\";\nimport type { IModelConnection, ViewManager, Viewport } from \"@itwin/core-frontend\";\nimport type { IVisibilityHandler, VisibilityChangeListener, VisibilityStatus } from \"../VisibilityTreeEventHandler\";\n\nconst EMPTY_CATEGORIES_ARRAY: CategoryInfo[] = [];\n\n/**\n * Loads categories from viewport or uses provided list of categories.\n * @internal\n */\nexport function useCategories(viewManager: ViewManager, imodel: IModelConnection, view?: Viewport) {\n const currentView = view || viewManager.getFirstOpenView();\n const categoriesPromise = useMemo(async () => loadCategoriesFromViewport(imodel, currentView), [imodel, currentView]);\n return useAsyncValue(categoriesPromise) ?? EMPTY_CATEGORIES_ARRAY;\n}\n\n/**\n * Data structure that describes category.\n * @public\n */\nexport interface CategoryInfo {\n categoryId: string;\n subCategoryIds?: string[];\n}\n\n/**\n * Params for creating a [[CategoryVisibilityHandler]].\n * @public\n */\nexport interface CategoryVisibilityHandlerParams {\n viewManager: ViewManager;\n imodel: IModelConnection;\n categories: CategoryInfo[];\n activeView: Viewport;\n allViewports?: boolean;\n}\n\n/**\n * An [[IVisibilityHandler]] implementation that knows how to determine and change visibility of categories\n * and subcategories.\n * @public\n */\nexport class CategoryVisibilityHandler implements IVisibilityHandler {\n private _viewManager: ViewManager;\n private _imodel: IModelConnection;\n private _pendingVisibilityChange: any | undefined;\n private _activeView: Viewport;\n private _useAllViewports: boolean;\n private _categories: CategoryInfo[];\n\n constructor(params: CategoryVisibilityHandlerParams) {\n this._viewManager = params.viewManager;\n this._imodel = params.imodel;\n this._activeView = params.activeView;\n // istanbul ignore next\n this._useAllViewports = params.allViewports ?? false;\n this._categories = params.categories;\n this._activeView.onDisplayStyleChanged.addListener(this.onDisplayStyleChanged);\n this._activeView.onViewedCategoriesChanged.addListener(this.onViewedCategoriesChanged);\n }\n\n public dispose() {\n this._activeView.onDisplayStyleChanged.removeListener(this.onDisplayStyleChanged);\n this._activeView.onViewedCategoriesChanged.removeListener(this.onViewedCategoriesChanged);\n clearTimeout(this._pendingVisibilityChange);\n }\n\n public onVisibilityChange = new BeEvent<VisibilityChangeListener>();\n\n public getVisibilityStatus(node: TreeNodeItem): VisibilityStatus {\n const nodeKey = isPresentationTreeNodeItem(node) ? node.key : undefined;\n if (!nodeKey) {\n return { state: \"hidden\", isDisabled: true };\n }\n\n const instanceId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);\n return { state: node.parentId ? this.getSubCategoryVisibility(instanceId) : this.getCategoryVisibility(instanceId) };\n }\n\n public async changeVisibility(node: TreeNodeItem, shouldDisplay: boolean): Promise<void> {\n const nodeKey = isPresentationTreeNodeItem(node) ? node.key : undefined;\n if (!nodeKey) {\n return;\n }\n\n // handle subcategory visibility change\n if (node.parentId) {\n const childId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);\n // istanbul ignore next\n const parentId = this.getParent(childId)?.categoryId;\n\n // make sure parent category is enabled\n if (shouldDisplay && parentId) {\n await this.enableCategory([parentId], true, false);\n }\n\n this.enableSubCategory(childId, shouldDisplay);\n return;\n }\n\n const instanceId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);\n await this.enableCategory([instanceId], shouldDisplay, true);\n }\n\n public getSubCategoryVisibility(id: string) {\n const parentItem = this.getParent(id);\n if (!parentItem) {\n return \"hidden\";\n }\n\n const isVisible = this._activeView.view.viewsCategory(parentItem.categoryId) && this._activeView.isSubCategoryVisible(id);\n return isVisible ? \"visible\" : \"hidden\";\n }\n\n public getCategoryVisibility(id: string) {\n return this._activeView.view.viewsCategory(id) ? \"visible\" : \"hidden\";\n }\n\n public getParent(key: string): CategoryInfo | undefined {\n for (const category of this._categories) {\n // istanbul ignore else\n if (category.subCategoryIds && category.subCategoryIds.indexOf(key) !== -1) {\n return category;\n }\n }\n\n return undefined;\n }\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n private onDisplayStyleChanged = () => {\n this.onVisibilityChangeInternal();\n };\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n private onViewedCategoriesChanged = () => {\n this.onVisibilityChangeInternal();\n };\n\n private onVisibilityChangeInternal() {\n if (this._pendingVisibilityChange) {\n return;\n }\n\n this._pendingVisibilityChange = setTimeout(() => {\n this.onVisibilityChange.raiseEvent();\n this._pendingVisibilityChange = undefined;\n }, 0);\n }\n\n public static getInstanceIdFromTreeNodeKey(nodeKey: NodeKey) {\n return NodeKey.isInstancesNodeKey(nodeKey) && nodeKey.instanceKeys.length > 0 ? nodeKey.instanceKeys[0].id : /* istanbul ignore next */ \"\";\n }\n\n public async enableCategory(ids: string[], enabled: boolean, enableAllSubCategories = true) {\n await enableCategory(this._viewManager, this._imodel, ids, enabled, this._useAllViewports, enableAllSubCategories);\n }\n\n public enableSubCategory(key: string, enabled: boolean) {\n enableSubCategory(this._viewManager, key, enabled, this._useAllViewports);\n }\n}\n\n/**\n * Enable display of all given categories.\n * @public\n */\nexport async function showAllCategories(categories: string[], viewport: Viewport) {\n await enableCategory(IModelApp.viewManager, viewport.iModel, categories, true, true);\n}\n\n/**\n * Disable display of all given categories.\n * @public\n */\nexport async function hideAllCategories(categories: string[], viewport: Viewport) {\n await enableCategory(IModelApp.viewManager, viewport.iModel, categories, false, true);\n}\n\n/**\n * Invert display of all given categories.\n * @public\n */\nexport async function invertAllCategories(categories: CategoryInfo[], viewport: Viewport) {\n const enabled: string[] = [];\n const disabled: string[] = [];\n const enabledSubCategories: string[] = [];\n const disabledSubCategories: string[] = [];\n\n for (const category of categories) {\n if (!viewport.view.viewsCategory(category.categoryId)) {\n disabled.push(category.categoryId);\n continue;\n }\n // First, we need to check if at least one subcategory is disabled. If it is true, then only subcategories should change display, not categories.\n if (category.subCategoryIds?.some((subCategory) => !viewport.isSubCategoryVisible(subCategory))) {\n for (const subCategory of category.subCategoryIds) {\n viewport.isSubCategoryVisible(subCategory) ? enabledSubCategories.push(subCategory) : disabledSubCategories.push(subCategory);\n }\n } else {\n enabled.push(category.categoryId);\n }\n }\n\n // Disable enabled\n enabledSubCategories.forEach((subCategory) => enableSubCategory(IModelApp.viewManager, subCategory, false, true));\n\n await enableCategory(IModelApp.viewManager, viewport.iModel, enabled, false, true);\n\n // Enable disabled\n disabledSubCategories.forEach((subCategory) => enableSubCategory(IModelApp.viewManager, subCategory, true, true));\n\n await enableCategory(IModelApp.viewManager, viewport.iModel, disabled, true, true);\n}\n"]}
@@ -1,8 +1,8 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
6
  import { Fragment, useState } from "react";
7
7
  import { ContextMenuItem, GlobalContextMenu } from "@itwin/core-react";
8
8
  /**
@@ -10,7 +10,7 @@ import { ContextMenuItem, GlobalContextMenu } from "@itwin/core-react";
10
10
  * @public
11
11
  */
12
12
  export function TreeContextMenuItem({ id, children, title, onSelect }) {
13
- return _jsx(ContextMenuItem, { onSelect: onSelect, title: title, children: children }, id);
13
+ return (_jsx(ContextMenuItem, { onSelect: onSelect, title: title, children: children }, id));
14
14
  }
15
15
  /** @internal */
16
16
  export function useContextMenu({ contextMenuItems }) {
@@ -1 +1 @@
1
- {"version":3,"file":"ContextMenu.js","sourceRoot":"","sources":["../../../../../src/components/trees/common/ContextMenu.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAkCvE;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAA+C;IAChH,OAAO,KAAC,eAAe,IAErB,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,KAAK,YAEX,QAAQ,IAJJ,EAAE,CAKS,CAAC;AACrB,CAAC;AAOD,gBAAgB;AAChB,MAAM,UAAU,cAAc,CAAC,EAAE,gBAAgB,EAAwB;IACvE,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,EAAe,CAAC;IAC9D,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IAE9C,MAAM,aAAa,GAAG,CAAC,CAAa,EAAE,IAAmB,EAAE,EAAE;QAC3D,IAAI,CAAC,gBAAgB,EAAE;YACrB,OAAO;SACR;QAED,cAAc,CAAC;YACb,KAAK,EAAE,gBAAgB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,KAAC,QAAQ,cAAc,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,IAAtB,KAAK,CAA6B,CAAC;YAC/F,QAAQ,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE;SACzC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,MAAM,iBAAiB,GAAG,GAAG,EAAE;QAC7B,IAAI,CAAC,WAAW,EAAE;YAChB,OAAO,IAAI,CAAC;SACb;QAED,OAAO,CACL,KAAC,iBAAiB,IAChB,UAAU,EAAC,0BAA0B,EACrC,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC,EACzB,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC,EACzB,MAAM,EAAE,IAAI,EACZ,cAAc,EAAE,KAAK,EACrB,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,KAAK,YAEd,WAAW,CAAC,KAAK,GACA,CACrB,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO;QACL,aAAa;QACb,iBAAiB;KAClB,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 { Fragment, useState } from \"react\";\nimport { ContextMenuItem, GlobalContextMenu } from \"@itwin/core-react\";\n\nimport type { MouseEvent, PropsWithChildren, ReactNode } from \"react\";\nimport type { TreeModelNode } from \"@itwin/components-react\";\n\n/**\n * Props for single context menu item.\n * @public\n */\nexport interface ContextMenuItemProps {\n node: TreeModelNode;\n}\n\n/**\n * Props for configuring tree context menu.\n * @public\n */\nexport interface TreeContextMenuProps {\n contextMenuItems?: Array<(props: ContextMenuItemProps) => ReactNode>;\n}\n\n/**\n * Props for [[TreeContextMenuItem]] component.\n * @public\n */\nexport interface TreeContextMenuItemProps {\n /** Unique id of the context menu item. */\n id: string;\n /** Description of the context menu item. */\n title?: string;\n /** Callback that is invoked when context menu item is clicked. */\n onSelect: () => void;\n}\n\n/**\n * Base component for rendering single context menu item.\n * @public\n */\nexport function TreeContextMenuItem({ id, children, title, onSelect }: PropsWithChildren<TreeContextMenuItemProps>) {\n return <ContextMenuItem\n key={id}\n onSelect={onSelect}\n title={title}\n >\n {children}\n </ContextMenuItem>;\n}\n\ninterface ContextMenu {\n items: ReactNode[];\n position: {x: number, y: number};\n}\n\n/** @internal */\nexport function useContextMenu({ contextMenuItems }: TreeContextMenuProps) {\n const [contextMenu, setContextMenu] = useState<ContextMenu>();\n const close = () => setContextMenu(undefined);\n\n const onContextMenu = (e: MouseEvent, node: TreeModelNode) => {\n if (!contextMenuItems) {\n return;\n }\n\n setContextMenu({\n items: contextMenuItems.map((item, index) => <Fragment key={index}>{item({ node })}</Fragment>),\n position: { x: e.clientX, y: e.clientY },\n });\n };\n\n const renderContextMenu = () => {\n if (!contextMenu) {\n return null;\n }\n\n return (\n <GlobalContextMenu\n identifier=\"tree-widget-context-menu\"\n x={contextMenu.position.x}\n y={contextMenu.position.y}\n opened={true}\n onOutsideClick={close}\n onEsc={close}\n onSelect={close}\n >\n {contextMenu.items}\n </GlobalContextMenu>\n );\n };\n\n return {\n onContextMenu,\n renderContextMenu,\n };\n}\n"]}
1
+ {"version":3,"file":"ContextMenu.js","sourceRoot":"","sources":["../../../../../src/components/trees/common/ContextMenu.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAkCvE;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAA+C;IAChH,OAAO,CACL,KAAC,eAAe,IAAU,QAAQ,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,YACvD,QAAQ,IADW,EAAE,CAEN,CACnB,CAAC;AACJ,CAAC;AAOD,gBAAgB;AAChB,MAAM,UAAU,cAAc,CAAC,EAAE,gBAAgB,EAAwB;IACvE,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,EAAe,CAAC;IAC9D,MAAM,KAAK,GAAG,GAAG,EAAE,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IAE9C,MAAM,aAAa,GAAG,CAAC,CAAa,EAAE,IAAmB,EAAE,EAAE;QAC3D,IAAI,CAAC,gBAAgB,EAAE;YACrB,OAAO;SACR;QAED,cAAc,CAAC;YACb,KAAK,EAAE,gBAAgB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,KAAC,QAAQ,cAAc,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,IAAtB,KAAK,CAA6B,CAAC;YAC/F,QAAQ,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE;SACzC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,MAAM,iBAAiB,GAAG,GAAG,EAAE;QAC7B,IAAI,CAAC,WAAW,EAAE;YAChB,OAAO,IAAI,CAAC;SACb;QAED,OAAO,CACL,KAAC,iBAAiB,IAChB,UAAU,EAAC,0BAA0B,EACrC,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC,EACzB,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC,EACzB,MAAM,EAAE,IAAI,EACZ,cAAc,EAAE,KAAK,EACrB,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,KAAK,YAEd,WAAW,CAAC,KAAK,GACA,CACrB,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO;QACL,aAAa;QACb,iBAAiB;KAClB,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 { Fragment, useState } from \"react\";\nimport { ContextMenuItem, GlobalContextMenu } from \"@itwin/core-react\";\n\nimport type { MouseEvent, PropsWithChildren, ReactNode } from \"react\";\nimport type { TreeModelNode } from \"@itwin/components-react\";\n\n/**\n * Props for single context menu item.\n * @public\n */\nexport interface ContextMenuItemProps {\n node: TreeModelNode;\n}\n\n/**\n * Props for configuring tree context menu.\n * @public\n */\nexport interface TreeContextMenuProps {\n contextMenuItems?: Array<(props: ContextMenuItemProps) => ReactNode>;\n}\n\n/**\n * Props for [[TreeContextMenuItem]] component.\n * @public\n */\nexport interface TreeContextMenuItemProps {\n /** Unique id of the context menu item. */\n id: string;\n /** Description of the context menu item. */\n title?: string;\n /** Callback that is invoked when context menu item is clicked. */\n onSelect: () => void;\n}\n\n/**\n * Base component for rendering single context menu item.\n * @public\n */\nexport function TreeContextMenuItem({ id, children, title, onSelect }: PropsWithChildren<TreeContextMenuItemProps>) {\n return (\n <ContextMenuItem key={id} onSelect={onSelect} title={title}>\n {children}\n </ContextMenuItem>\n );\n}\n\ninterface ContextMenu {\n items: ReactNode[];\n position: { x: number; y: number };\n}\n\n/** @internal */\nexport function useContextMenu({ contextMenuItems }: TreeContextMenuProps) {\n const [contextMenu, setContextMenu] = useState<ContextMenu>();\n const close = () => setContextMenu(undefined);\n\n const onContextMenu = (e: MouseEvent, node: TreeModelNode) => {\n if (!contextMenuItems) {\n return;\n }\n\n setContextMenu({\n items: contextMenuItems.map((item, index) => <Fragment key={index}>{item({ node })}</Fragment>),\n position: { x: e.clientX, y: e.clientY },\n });\n };\n\n const renderContextMenu = () => {\n if (!contextMenu) {\n return null;\n }\n\n return (\n <GlobalContextMenu\n identifier=\"tree-widget-context-menu\"\n x={contextMenu.position.x}\n y={contextMenu.position.y}\n opened={true}\n onOutsideClick={close}\n onEsc={close}\n onSelect={close}\n >\n {contextMenu.items}\n </GlobalContextMenu>\n );\n };\n\n return {\n onContextMenu,\n renderContextMenu,\n };\n}\n"]}
@@ -43,7 +43,7 @@ export interface DefaultLabelRendererProps {
43
43
  * Renders label for tree node.
44
44
  * @public
45
45
  */
46
- export declare function DefaultLabelRenderer({ label, context }: DefaultLabelRendererProps): JSX.Element;
46
+ export declare function DefaultLabelRenderer({ label, context }: DefaultLabelRendererProps): React.JSX.Element;
47
47
  /** @internal */
48
48
  export interface TreeNodeRendererContextProviderProps extends TreeNodeRendererProps {
49
49
  node: TreeModelNode;
@@ -1,8 +1,8 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
6
  import { createContext, useContext } from "react";
7
7
  import { PrimitivePropertyValueRenderer } from "@itwin/components-react";
8
8
  /**
@@ -15,7 +15,7 @@ export function DefaultLabelRenderer({ label, context }) {
15
15
  }
16
16
  /** @internal */
17
17
  export function TreeNodeRendererContextProvider({ nodeLabelRenderer, node, children }) {
18
- return (_jsx(treeNodeLabelRendererContext.Provider, { value: { renderer: nodeLabelRenderer, node }, children: children }));
18
+ return _jsx(treeNodeLabelRendererContext.Provider, { value: { renderer: nodeLabelRenderer, node }, children: children });
19
19
  }
20
20
  /** @internal */
21
21
  export const TREE_NODE_LABEL_RENDERER = "visibility-tree-node-label";
@@ -1 +1 @@
1
- {"version":3,"file":"TreeNodeRenderer.js","sourceRoot":"","sources":["../../../../../src/components/trees/common/TreeNodeRenderer.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,8BAA8B,EAAE,MAAM,yBAAyB,CAAC;AAkDzE;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,EAAE,KAAK,EAAE,OAAO,EAA6B;IAChF,MAAM,QAAQ,GAAG,IAAI,8BAA8B,EAAE,CAAC;IACtD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,IAAI,EAAE,OAAO,EAAE,CAAC,GAAI,CAAC;AAC5C,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 { createContext, useContext } from \"react\";\nimport { PrimitivePropertyValueRenderer } from \"@itwin/components-react\";\n\nimport type { ReactNode } from \"react\";\nimport type { PropertyRecord } from \"@itwin/appui-abstract\";\nimport type {\n IPropertyValueRenderer, PropertyValueRendererContext, TreeModelNode,\n} from \"@itwin/components-react\";\n\n/**\n * Context for rendering label value.\n * @public\n */\nexport interface LabelRendererContext {\n /** Style that should be applied to the rendered element. */\n style?: React.CSSProperties;\n /** Callback to highlight text. */\n textHighlighter?: (text: string) => React.ReactNode;\n}\n\n/**\n * Props for custom node renderer.\n * @public\n */\nexport interface TreeNodeLabelRendererProps {\n /** Tree node to rendered label for. */\n node: TreeModelNode;\n /** Context for rendering node's label value. */\n context?: LabelRendererContext;\n}\n\n/**\n * Props for customizing node rendering.\n * @public\n */\nexport interface TreeNodeRendererProps {\n /** Custom renderer for node's label. */\n nodeLabelRenderer?: (props: TreeNodeLabelRendererProps) => ReactNode;\n}\n\n/**\n * Props for [[DefaultLabelRenderer]] component.\n * @public\n */\nexport interface DefaultLabelRendererProps {\n /** Label that should be rendered. */\n label: PropertyRecord;\n /** Context for rendering label value. */\n context?: LabelRendererContext;\n}\n\n/**\n * Renders label for tree node.\n * @public\n */\nexport function DefaultLabelRenderer({ label, context }: DefaultLabelRendererProps) {\n const renderer = new PrimitivePropertyValueRenderer();\n return renderer.render(label, context);\n}\n\n/** @internal */\nexport interface TreeNodeRendererContextProviderProps extends TreeNodeRendererProps {\n node: TreeModelNode;\n children: ReactNode;\n}\n\n/** @internal */\nexport function TreeNodeRendererContextProvider({ nodeLabelRenderer, node, children }: TreeNodeRendererContextProviderProps) {\n return (\n <treeNodeLabelRendererContext.Provider value={{ renderer: nodeLabelRenderer, node }}>\n {children}\n </treeNodeLabelRendererContext.Provider>\n );\n}\n\n/** @internal */\nexport const TREE_NODE_LABEL_RENDERER = \"visibility-tree-node-label\";\n\n/** @internal */\nexport class TreeNodeLabelRenderer implements IPropertyValueRenderer {\n public canRender(record: PropertyRecord, _context?: PropertyValueRendererContext | undefined): boolean {\n return record.property.renderer?.name === TREE_NODE_LABEL_RENDERER;\n }\n\n public render(record: PropertyRecord, context?: PropertyValueRendererContext | undefined): ReactNode {\n const labelContext: LabelRendererContext = {\n style: context?.style,\n textHighlighter: context?.textHighlighter,\n };\n return <LabelRenderer record={record} context={labelContext} />;\n }\n}\n\ninterface TreeNodeLabelRendererContext {\n renderer?: (props: TreeNodeLabelRendererProps) => ReactNode;\n node: TreeModelNode;\n}\n\nconst treeNodeLabelRendererContext = createContext<TreeNodeLabelRendererContext | undefined>(undefined);\n\ninterface LabelRendererProps {\n record: PropertyRecord;\n context?: LabelRendererContext;\n}\n\nfunction LabelRenderer({ record, context }: LabelRendererProps) {\n const renderContext = useContext(treeNodeLabelRendererContext);\n\n if (!renderContext || !renderContext.renderer) {\n return <DefaultLabelRenderer label={record} context={context} />;\n }\n\n const { renderer, node } = renderContext;\n return <>{renderer({ node, context })}</>;\n}\n"]}
1
+ {"version":3,"file":"TreeNodeRenderer.js","sourceRoot":"","sources":["../../../../../src/components/trees/common/TreeNodeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,8BAA8B,EAAE,MAAM,yBAAyB,CAAC;AAgDzE;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAAC,EAAE,KAAK,EAAE,OAAO,EAA6B;IAChF,MAAM,QAAQ,GAAG,IAAI,8BAA8B,EAAE,CAAC;IACtD,OAAO,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC;AAQD,gB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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 { createContext, useContext } from \"react\";\nimport { PrimitivePropertyValueRenderer } from \"@itwin/components-react\";\n\nimport type { ReactNode } from \"react\";\nimport type { PropertyRecord } from \"@itwin/appui-abstract\";\nimport type { IPropertyValueRenderer, PropertyValueRendererContext, TreeModelNode } from \"@itwin/components-react\";\n\n/**\n * Context for rendering label value.\n * @public\n */\nexport interface LabelRendererContext {\n /** Style that should be applied to the rendered element. */\n style?: React.CSSProperties;\n /** Callback to highlight text. */\n textHighlighter?: (text: string) => React.ReactNode;\n}\n\n/**\n * Props for custom node renderer.\n * @public\n */\nexport interface TreeNodeLabelRendererProps {\n /** Tree node to rendered label for. */\n node: TreeModelNode;\n /** Context for rendering node's label value. */\n context?: LabelRendererContext;\n}\n\n/**\n * Props for customizing node rendering.\n * @public\n */\nexport interface TreeNodeRendererProps {\n /** Custom renderer for node's label. */\n nodeLabelRenderer?: (props: TreeNodeLabelRendererProps) => ReactNode;\n}\n\n/**\n * Props for [[DefaultLabelRenderer]] component.\n * @public\n */\nexport interface DefaultLabelRendererProps {\n /** Label that should be rendered. */\n label: PropertyRecord;\n /** Context for rendering label value. */\n context?: LabelRendererContext;\n}\n\n/**\n * Renders label for tree node.\n * @public\n */\nexport function DefaultLabelRenderer({ label, context }: DefaultLabelRendererProps) {\n const renderer = new PrimitivePropertyValueRenderer();\n return renderer.render(label, context);\n}\n\n/** @internal */\nexport interface TreeNodeRendererContextProviderProps extends TreeNodeRendererProps {\n node: TreeModelNode;\n children: ReactNode;\n}\n\n/** @internal */\nexport function TreeNodeRendererContextProvider({ nodeLabelRenderer, node, children }: TreeNodeRendererContextProviderProps) {\n return <treeNodeLabelRendererContext.Provider value={{ renderer: nodeLabelRenderer, node }}>{children}</treeNodeLabelRendererContext.Provider>;\n}\n\n/** @internal */\nexport const TREE_NODE_LABEL_RENDERER = \"visibility-tree-node-label\";\n\n/** @internal */\nexport class TreeNodeLabelRenderer implements IPropertyValueRenderer {\n public canRender(record: PropertyRecord, _context?: PropertyValueRendererContext | undefined): boolean {\n return record.property.renderer?.name === TREE_NODE_LABEL_RENDERER;\n }\n\n public render(record: PropertyRecord, context?: PropertyValueRendererContext | undefined): ReactNode {\n const labelContext: LabelRendererContext = {\n style: context?.style,\n textHighlighter: context?.textHighlighter,\n };\n return <LabelRenderer record={record} context={labelContext} />;\n }\n}\n\ninterface TreeNodeLabelRendererContext {\n renderer?: (props: TreeNodeLabelRendererProps) => ReactNode;\n node: TreeModelNode;\n}\n\nconst treeNodeLabelRendererContext = createContext<TreeNodeLabelRendererContext | undefined>(undefined);\n\ninterface LabelRendererProps {\n record: PropertyRecord;\n context?: LabelRendererContext;\n}\n\nfunction LabelRenderer({ record, context }: LabelRendererProps) {\n const renderContext = useContext(treeNodeLabelRendererContext);\n\n if (!renderContext || !renderContext.renderer) {\n return <DefaultLabelRenderer label={record} context={context} />;\n }\n\n const { renderer, node } = renderContext;\n return <>{renderer({ node, context })}</>;\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import "./TreeRenderer.scss";
3
- import type { TreeRendererProps as ComponentsTreeRendererProps } from "@itwin/components-react";
3
+ import type { IPresentationTreeDataProvider, PresentationTreeNodeRendererProps } from "@itwin/presentation-components";
4
+ import type { AbstractTreeNodeLoaderWithProvider, TreeRendererProps as ComponentsTreeRendererProps } from "@itwin/components-react";
4
5
  import type { TreeNodeRendererProps } from "./TreeNodeRenderer";
5
6
  import type { TreeContextMenuProps } from "./ContextMenu";
6
7
  /**
@@ -23,4 +24,17 @@ export type TreeRendererProps = ComponentsTreeRendererProps & TreeRendererBasePr
23
24
  * @public
24
25
  */
25
26
  export declare function TreeRenderer({ contextMenuItems, nodeRenderer, nodeLabelRenderer, density, ...restProps }: TreeRendererProps): JSX.Element;
27
+ /**
28
+ * Props for [[FilterableTreeRenderer]] component.
29
+ * @beta
30
+ */
31
+ export interface FilterableTreeRendererProps extends Omit<TreeRendererProps, "nodeLoader" | "nodeRenderer"> {
32
+ nodeLoader: AbstractTreeNodeLoaderWithProvider<IPresentationTreeDataProvider>;
33
+ nodeRenderer: (props: PresentationTreeNodeRendererProps) => React.ReactNode;
34
+ }
35
+ /**
36
+ * Base tree renderer for trees with enabled hierarchy level filtering.
37
+ * @beta
38
+ */
39
+ export declare function FilterableTreeRenderer({ nodeRenderer, nodeLoader, ...restProps }: FilterableTreeRendererProps): JSX.Element;
26
40
  //# sourceMappingURL=TreeRenderer.d.ts.map
@@ -1,11 +1,12 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
6
  import "./TreeRenderer.scss";
7
7
  import classNames from "classnames";
8
8
  import { TreeRenderer as ComponentsTreeRenderer, TreeNodeRenderer } from "@itwin/components-react";
9
+ import { useFilterablePresentationTree } from "@itwin/presentation-components";
9
10
  import { useContextMenu } from "./ContextMenu";
10
11
  import { TreeNodeRendererContextProvider } from "./TreeNodeRenderer";
11
12
  /**
@@ -18,11 +19,19 @@ export function TreeRenderer({ contextMenuItems, nodeRenderer, nodeLabelRenderer
18
19
  const className = classNames("tree-widget-tree-nodes-list", { ["enlarge"]: density === "enlarged" });
19
20
  return (_jsxs("div", { className: className, children: [_jsx(ComponentsTreeRenderer, { ...restProps, nodeRenderer: (nodeProps) => {
20
21
  const nodeClassName = nodeProps.node.numChildren === 0 ? "without-expander" : undefined;
21
- return (_jsx(TreeNodeRendererContextProvider, { node: nodeProps.node, nodeLabelRenderer: nodeLabelRenderer, children: nodeRenderer
22
- ? nodeRenderer({ ...nodeProps, onContextMenu, className: nodeClassName })
23
- : _jsx(TreeNodeRenderer, { ...nodeProps, onContextMenu: onContextMenu, className: nodeClassName }) }));
22
+ return (_jsx(TreeNodeRendererContextProvider, { node: nodeProps.node, nodeLabelRenderer: nodeLabelRenderer, children: nodeRenderer ? (nodeRenderer({ ...nodeProps, onContextMenu, className: nodeClassName })) : (_jsx(TreeNodeRenderer, { ...nodeProps, onContextMenu: onContextMenu, className: nodeClassName })) }));
24
23
  }, nodeHeight: nodeHeight }), renderContextMenu()] }));
25
24
  }
25
+ /**
26
+ * Base tree renderer for trees with enabled hierarchy level filtering.
27
+ * @beta
28
+ */
29
+ export function FilterableTreeRenderer({ nodeRenderer, nodeLoader, ...restProps }) {
30
+ const { onClearFilterClick, onFilterClick, filterDialog } = useFilterablePresentationTree({ nodeLoader });
31
+ return (_jsxs("div", { children: [_jsx(TreeRenderer, { ...restProps, nodeLoader: nodeLoader, nodeRenderer: (props) => {
32
+ return nodeRenderer({ ...props, onClearFilterClick, onFilterClick });
33
+ } }), filterDialog] }));
34
+ }
26
35
  function getNodeHeight(density, defaultHeight) {
27
36
  switch (density) {
28
37
  case "default":
@@ -1 +1 @@
1
- {"version":3,"file":"TreeRenderer.js","sourceRoot":"","sources":["../../../../../src/components/trees/common/TreeRenderer.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;AAE/F,OAAO,qBAAqB,CAAC;AAC7B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,YAAY,IAAI,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACnG,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC;AAuBrE;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,EAAE,gBAAgB,EAAE,YAAY,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG,SAAS,EAAqB;IAC1H,MAAM,EAAE,aAAa,EAAE,iBAAiB,EAAE,GAAG,cAAc,CAAC,EAAE,gBAAgB,EAAE,CAAC,CAAC;IAElF,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,IAAI,SAAS,EAAE,SAAS,CAAC,UAAU,CAAC,CAAC;IAC7E,MAAM,SAAS,GAAG,UAAU,CAAC,6BAA6B,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,OAAO,KAAK,UAAU,EAAE,CAAC,CAAC;IAErG,OAAO,CACL,eAAK,SAAS,EAAE,SAAS,aACvB,KAAC,sBAAsB,OACjB,SAAS,EACb,YAAY,EAAE,CAAC,SAAS,EAAE,EAAE;oBAC1B,MAAM,aAAa,GAAG,SAAS,CAAC,IAAI,CAAC,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,SAAS,CAAC;oBACxF,OAAO,CACL,KAAC,+BAA+B,IAAC,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,iBAAiB,EAAE,iBAAiB,YACxF,YAAY;4BACX,CAAC,CAAC,YAAY,CAAC,EAAE,GAAG,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC;4BACzE,CAAC,CAAC,KAAC,gBAAgB,OAAK,SAAS,EAAE,aAAa,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,GAAI,GAC/D,CACnC,CAAC;gBACJ,CAAC,EAED,UAAU,EAAE,UAAU,GACtB,EACD,iBAAiB,EAAE,IAChB,CACP,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,OAA+B,EAAE,aAAwD;IAC9G,QAAQ,OAAO,EAAE;QACf,KAAK,SAAS;YACZ,OAAO,aAAa,CAAC;QACvB,KAAK,UAAU;YACb,OAAO,GAAG,EAAE,CAAC,EAAE,CAAC;KACnB;AACH,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 \"./TreeRenderer.scss\";\nimport classNames from \"classnames\";\nimport { TreeRenderer as ComponentsTreeRenderer, TreeNodeRenderer } from \"@itwin/components-react\";\nimport { useContextMenu } from \"./ContextMenu\";\nimport { TreeNodeRendererContextProvider } from \"./TreeNodeRenderer\";\n\nimport type { TreeRendererProps as ComponentsTreeRendererProps } from \"@itwin/components-react\";\nimport type { TreeNodeRendererProps } from \"./TreeNodeRenderer\";\nimport type { TreeContextMenuProps } from \"./ContextMenu\";\n\n/**\n * Base props for [[TreeRenderer]] component.\n * @public\n */\nexport interface TreeRendererBaseProps extends TreeContextMenuProps, TreeNodeRendererProps {\n /**\n * Modifies the density of tree nodes. `enlarged` tree nodes have bigger height and bigger button hit boxes.\n */\n density?: \"default\" | \"enlarged\";\n}\n\n/**\n * Props for [[TreeRenderer]] component.\n * @public\n */\nexport type TreeRendererProps = ComponentsTreeRendererProps & TreeRendererBaseProps;\n\n/**\n * Base tree renderer for visibility trees.\n * @public\n */\nexport function TreeRenderer({ contextMenuItems, nodeRenderer, nodeLabelRenderer, density, ...restProps }: TreeRendererProps) {\n const { onContextMenu, renderContextMenu } = useContextMenu({ contextMenuItems });\n\n const nodeHeight = getNodeHeight(density ?? \"default\", restProps.nodeHeight);\n const className = classNames(\"tree-widget-tree-nodes-list\", { [\"enlarge\"]: density === \"enlarged\" });\n\n return (\n <div className={className}>\n <ComponentsTreeRenderer\n {...restProps}\n nodeRenderer={(nodeProps) => {\n const nodeClassName = nodeProps.node.numChildren === 0 ? \"without-expander\" : undefined;\n return (\n <TreeNodeRendererContextProvider node={nodeProps.node} nodeLabelRenderer={nodeLabelRenderer}>\n {nodeRenderer\n ? nodeRenderer({ ...nodeProps, onContextMenu, className: nodeClassName })\n : <TreeNodeRenderer {...nodeProps} onContextMenu={onContextMenu} className={nodeClassName} />}\n </TreeNodeRendererContextProvider>\n );\n }\n }\n nodeHeight={nodeHeight}\n />\n {renderContextMenu()}\n </div>\n );\n}\n\nfunction getNodeHeight(density: \"default\" | \"enlarged\", defaultHeight: ComponentsTreeRendererProps[\"nodeHeight\"]) {\n switch (density) {\n case \"default\":\n return defaultHeight;\n case \"enlarged\":\n return () => 43;\n }\n}\n"]}
1
+ {"version":3,"file":"TreeRenderer.js","sourceRoot":"","sources":["../../../../../src/components/trees/common/TreeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,qBAAqB,CAAC;AAC7B,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,YAAY,IAAI,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACnG,OAAO,EAAE,6BAA6B,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,+BAA+B,EAAE,MAAM,oBAAoB,CAAC;AAuBrE;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,EAAE,gBAAgB,EAAE,YAAY,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG,SAAS,EAAqB;IAC1H,MAAM,EAAE,aAAa,EAAE,iBAAiB,EAAE,GAAG,cAAc,CAAC,EAAE,gBAAgB,EAAE,CAAC,CAAC;IAElF,MAAM,UAAU,GAAG,aAAa,CAAC,OAAO,IAAI,SAAS,EAAE,SAAS,CAAC,UAAU,CAAC,CAAC;IAC7E,MAAM,SAAS,GAAG,UAAU,CAAC,6BAA6B,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,OAAO,KAAK,UAAU,EAAE,CAAC,CAAC;IAErG,OAAO,CACL,eAAK,SAAS,EAAE,SAAS,aACvB,KAAC,sBAAsB,OACjB,SAAS,EACb,YAAY,EAAE,CAAC,SAAS,EAAE,EAAE;oBAC1B,MAAM,aAAa,GAAG,SAAS,CAAC,IAAI,CAAC,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,SAAS,CAAC;oBACxF,OAAO,CACL,KAAC,+BAA+B,IAAC,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,iBAAiB,EAAE,iBAAiB,YACxF,YAAY,CAAC,CAAC,CAAC,CACd,YAAY,CAAC,EAAE,GAAG,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,CAAC,CACxE,CAAC,CAAC,CAAC,CACF,KAAC,gBAAgB,OAAK,SAAS,EAAE,aAAa,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,GAAI,CAC5F,GAC+B,CACnC,CAAC;gBACJ,CAAC,EACD,UAAU,EAAE,UAAU,GACtB,EACD,iBAAiB,EAAE,IAChB,CACP,CAAC;AACJ,CAAC;AAUD;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,SAAS,EAA+B;IAC5G,MAAM,EAAE,kBAAkB,EAAE,aAAa,EAAE,YAAY,EAAE,GAAG,6BAA6B,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC;IAE1G,OAAO,CACL,0BACE,KAAC,YAAY,OACP,SAAS,EACb,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,CAAC,KAAK,EAAE,EAAE;oBACtB,OAAO,YAAY,CAAC,EAAE,GAAG,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,CAAC,CAAC;gBACvE,CAAC,GACD,EACD,YAAY,IACT,CACP,CAAC;AACJ,CAAC;AAED,SAAS,aAAa,CAAC,OAA+B,EAAE,aAAwD;IAC9G,QAAQ,OAAO,EAAE;QACf,KAAK,SAAS;YACZ,OAAO,aAAa,CAAC;QACvB,KAAK,UAAU;YACb,OAAO,GAAG,EAAE,CAAC,EAAE,CAAC;KACnB;AACH,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 \"./TreeRenderer.scss\";\nimport classNames from \"classnames\";\nimport { TreeRenderer as ComponentsTreeRenderer, TreeNodeRenderer } from \"@itwin/components-react\";\nimport { useFilterablePresentationTree } from \"@itwin/presentation-components\";\nimport { useContextMenu } from \"./ContextMenu\";\nimport { TreeNodeRendererContextProvider } from \"./TreeNodeRenderer\";\n\nimport type { IPresentationTreeDataProvider, PresentationTreeNodeRendererProps } from \"@itwin/presentation-components\";\nimport type { AbstractTreeNodeLoaderWithProvider, TreeRendererProps as ComponentsTreeRendererProps } from \"@itwin/components-react\";\nimport type { TreeNodeRendererProps } from \"./TreeNodeRenderer\";\nimport type { TreeContextMenuProps } from \"./ContextMenu\";\n/**\n * Base props for [[TreeRenderer]] component.\n * @public\n */\nexport interface TreeRendererBaseProps extends TreeContextMenuProps, TreeNodeRendererProps {\n /**\n * Modifies the density of tree nodes. `enlarged` tree nodes have bigger height and bigger button hit boxes.\n */\n density?: \"default\" | \"enlarged\";\n}\n\n/**\n * Props for [[TreeRenderer]] component.\n * @public\n */\nexport type TreeRendererProps = ComponentsTreeRendererProps & TreeRendererBaseProps;\n\n/**\n * Base tree renderer for visibility trees.\n * @public\n */\nexport function TreeRenderer({ contextMenuItems, nodeRenderer, nodeLabelRenderer, density, ...restProps }: TreeRendererProps) {\n const { onContextMenu, renderContextMenu } = useContextMenu({ contextMenuItems });\n\n const nodeHeight = getNodeHeight(density ?? \"default\", restProps.nodeHeight);\n const className = classNames(\"tree-widget-tree-nodes-list\", { [\"enlarge\"]: density === \"enlarged\" });\n\n return (\n <div className={className}>\n <ComponentsTreeRenderer\n {...restProps}\n nodeRenderer={(nodeProps) => {\n const nodeClassName = nodeProps.node.numChildren === 0 ? \"without-expander\" : undefined;\n return (\n <TreeNodeRendererContextProvider node={nodeProps.node} nodeLabelRenderer={nodeLabelRenderer}>\n {nodeRenderer ? (\n nodeRenderer({ ...nodeProps, onContextMenu, className: nodeClassName })\n ) : (\n <TreeNodeRenderer {...nodeProps} onContextMenu={onContextMenu} className={nodeClassName} />\n )}\n </TreeNodeRendererContextProvider>\n );\n }}\n nodeHeight={nodeHeight}\n />\n {renderContextMenu()}\n </div>\n );\n}\n\n/**\n * Props for [[FilterableTreeRenderer]] component.\n * @beta\n */\nexport interface FilterableTreeRendererProps extends Omit<TreeRendererProps, \"nodeLoader\" | \"nodeRenderer\"> {\n nodeLoader: AbstractTreeNodeLoaderWithProvider<IPresentationTreeDataProvider>;\n nodeRenderer: (props: PresentationTreeNodeRendererProps) => React.ReactNode;\n}\n/**\n * Base tree renderer for trees with enabled hierarchy level filtering.\n * @beta\n */\nexport function FilterableTreeRenderer({ nodeRenderer, nodeLoader, ...restProps }: FilterableTreeRendererProps) {\n const { onClearFilterClick, onFilterClick, filterDialog } = useFilterablePresentationTree({ nodeLoader });\n\n return (\n <div>\n <TreeRenderer\n {...restProps}\n nodeLoader={nodeLoader}\n nodeRenderer={(props) => {\n return nodeRenderer({ ...props, onClearFilterClick, onFilterClick });\n }}\n />\n {filterDialog}\n </div>\n );\n}\n\nfunction getNodeHeight(density: \"default\" | \"enlarged\", defaultHeight: ComponentsTreeRendererProps[\"nodeHeight\"]) {\n switch (density) {\n case \"default\":\n return defaultHeight;\n case \"enlarged\":\n return () => 43;\n }\n}\n"]}