@itwin/tree-widget-react 0.6.2 → 0.7.1

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 (118) hide show
  1. package/lib/cjs/TreeWidget.js +1 -1
  2. package/lib/cjs/TreeWidget.js.map +1 -1
  3. package/lib/cjs/components/IconButton.js +3 -3
  4. package/lib/cjs/components/IconButton.js.map +1 -1
  5. package/lib/cjs/components/TreeFilteringState.js +4 -4
  6. package/lib/cjs/components/TreeFilteringState.js.map +1 -1
  7. package/lib/cjs/components/TreeWidgetComponent.d.ts +1 -1
  8. package/lib/cjs/components/TreeWidgetComponent.js +5 -5
  9. package/lib/cjs/components/TreeWidgetComponent.js.map +1 -1
  10. package/lib/cjs/components/TreeWidgetComponent.scss +1 -1
  11. package/lib/cjs/components/TreeWidgetUiItemsProvider.d.ts +4 -5
  12. package/lib/cjs/components/TreeWidgetUiItemsProvider.js +19 -14
  13. package/lib/cjs/components/TreeWidgetUiItemsProvider.js.map +1 -1
  14. package/lib/cjs/components/search-bar/SearchBar.d.ts +0 -3
  15. package/lib/cjs/components/search-bar/SearchBar.js +17 -28
  16. package/lib/cjs/components/search-bar/SearchBar.js.map +1 -1
  17. package/lib/cjs/components/search-bar/SearchBar.scss +18 -34
  18. package/lib/cjs/components/search-bar/SearchBox.js +1 -1
  19. package/lib/cjs/components/search-bar/SearchBox.js.map +1 -1
  20. package/lib/cjs/components/trees/CategoriesVisibilityUtils.d.ts +4 -5
  21. package/lib/cjs/components/trees/CategoriesVisibilityUtils.js +6 -9
  22. package/lib/cjs/components/trees/CategoriesVisibilityUtils.js.map +1 -1
  23. package/lib/cjs/components/trees/IModelContentTree.js +4 -4
  24. package/lib/cjs/components/trees/IModelContentTree.js.map +1 -1
  25. package/lib/cjs/components/trees/VisibilityTreeEventHandler.d.ts +4 -5
  26. package/lib/cjs/components/trees/VisibilityTreeEventHandler.js +17 -9
  27. package/lib/cjs/components/trees/VisibilityTreeEventHandler.js.map +1 -1
  28. package/lib/cjs/components/trees/VisibilityTreeRenderer.d.ts +4 -4
  29. package/lib/cjs/components/trees/VisibilityTreeRenderer.js +2 -2
  30. package/lib/cjs/components/trees/VisibilityTreeRenderer.js.map +1 -1
  31. package/lib/cjs/components/trees/category-tree/CategoriesTree.d.ts +9 -5
  32. package/lib/cjs/components/trees/category-tree/CategoriesTree.js +7 -8
  33. package/lib/cjs/components/trees/category-tree/CategoriesTree.js.map +1 -1
  34. package/lib/cjs/components/trees/category-tree/CategoriesTreeComponent.d.ts +7 -2
  35. package/lib/cjs/components/trees/category-tree/CategoriesTreeComponent.js +64 -31
  36. package/lib/cjs/components/trees/category-tree/CategoriesTreeComponent.js.map +1 -1
  37. package/lib/cjs/components/trees/category-tree/CategoryVisibilityHandler.d.ts +9 -9
  38. package/lib/cjs/components/trees/category-tree/CategoryVisibilityHandler.js +8 -8
  39. package/lib/cjs/components/trees/category-tree/CategoryVisibilityHandler.js.map +1 -1
  40. package/lib/cjs/components/trees/models-tree/ModelsTree.d.ts +5 -7
  41. package/lib/cjs/components/trees/models-tree/ModelsTree.js +7 -7
  42. package/lib/cjs/components/trees/models-tree/ModelsTree.js.map +1 -1
  43. package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.d.ts +19 -2
  44. package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.js +108 -74
  45. package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
  46. package/lib/cjs/components/trees/models-tree/ModelsVisibilityHandler.d.ts +6 -8
  47. package/lib/cjs/components/trees/models-tree/ModelsVisibilityHandler.js.map +1 -1
  48. package/lib/cjs/components/trees/spatial-tree/SpatialTreeComponent.js +9 -7
  49. package/lib/cjs/components/trees/spatial-tree/SpatialTreeComponent.js.map +1 -1
  50. package/lib/cjs/components/utils/AutoSizer.js +4 -4
  51. package/lib/cjs/components/utils/AutoSizer.js.map +1 -1
  52. package/lib/cjs/tree-widget-react.d.ts +0 -1
  53. package/lib/cjs/tree-widget-react.js +0 -1
  54. package/lib/cjs/tree-widget-react.js.map +1 -1
  55. package/lib/cjs/types.d.ts +19 -5
  56. package/lib/cjs/types.js +4 -0
  57. package/lib/cjs/types.js.map +1 -1
  58. package/lib/esm/components/TreeWidgetComponent.d.ts +1 -1
  59. package/lib/esm/components/TreeWidgetComponent.js +1 -1
  60. package/lib/esm/components/TreeWidgetComponent.js.map +1 -1
  61. package/lib/esm/components/TreeWidgetComponent.scss +1 -1
  62. package/lib/esm/components/TreeWidgetUiItemsProvider.d.ts +4 -5
  63. package/lib/esm/components/TreeWidgetUiItemsProvider.js +13 -8
  64. package/lib/esm/components/TreeWidgetUiItemsProvider.js.map +1 -1
  65. package/lib/esm/components/search-bar/SearchBar.d.ts +0 -3
  66. package/lib/esm/components/search-bar/SearchBar.js +14 -25
  67. package/lib/esm/components/search-bar/SearchBar.js.map +1 -1
  68. package/lib/esm/components/search-bar/SearchBar.scss +18 -34
  69. package/lib/esm/components/trees/CategoriesVisibilityUtils.d.ts +4 -5
  70. package/lib/esm/components/trees/CategoriesVisibilityUtils.js +4 -7
  71. package/lib/esm/components/trees/CategoriesVisibilityUtils.js.map +1 -1
  72. package/lib/esm/components/trees/VisibilityTreeEventHandler.d.ts +4 -5
  73. package/lib/esm/components/trees/VisibilityTreeEventHandler.js +13 -5
  74. package/lib/esm/components/trees/VisibilityTreeEventHandler.js.map +1 -1
  75. package/lib/esm/components/trees/VisibilityTreeRenderer.d.ts +4 -4
  76. package/lib/esm/components/trees/VisibilityTreeRenderer.js +1 -1
  77. package/lib/esm/components/trees/VisibilityTreeRenderer.js.map +1 -1
  78. package/lib/esm/components/trees/category-tree/CategoriesTree.d.ts +9 -5
  79. package/lib/esm/components/trees/category-tree/CategoriesTree.js +2 -3
  80. package/lib/esm/components/trees/category-tree/CategoriesTree.js.map +1 -1
  81. package/lib/esm/components/trees/category-tree/CategoriesTreeComponent.d.ts +7 -2
  82. package/lib/esm/components/trees/category-tree/CategoriesTreeComponent.js +63 -30
  83. package/lib/esm/components/trees/category-tree/CategoriesTreeComponent.js.map +1 -1
  84. package/lib/esm/components/trees/category-tree/CategoryVisibilityHandler.d.ts +9 -9
  85. package/lib/esm/components/trees/category-tree/CategoryVisibilityHandler.js +4 -4
  86. package/lib/esm/components/trees/category-tree/CategoryVisibilityHandler.js.map +1 -1
  87. package/lib/esm/components/trees/models-tree/ModelsTree.d.ts +5 -7
  88. package/lib/esm/components/trees/models-tree/ModelsTree.js.map +1 -1
  89. package/lib/esm/components/trees/models-tree/ModelsTreeComponent.d.ts +19 -2
  90. package/lib/esm/components/trees/models-tree/ModelsTreeComponent.js +103 -69
  91. package/lib/esm/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
  92. package/lib/esm/components/trees/models-tree/ModelsVisibilityHandler.d.ts +6 -8
  93. package/lib/esm/components/trees/models-tree/ModelsVisibilityHandler.js.map +1 -1
  94. package/lib/esm/components/trees/spatial-tree/SpatialTreeComponent.js +4 -2
  95. package/lib/esm/components/trees/spatial-tree/SpatialTreeComponent.js.map +1 -1
  96. package/lib/esm/tree-widget-react.d.ts +0 -1
  97. package/lib/esm/tree-widget-react.js +0 -1
  98. package/lib/esm/tree-widget-react.js.map +1 -1
  99. package/lib/esm/types.d.ts +19 -5
  100. package/lib/esm/types.js +4 -0
  101. package/lib/esm/types.js.map +1 -1
  102. package/package.json +32 -40
  103. package/lib/cjs/components/header/TreeHeader.d.ts +0 -15
  104. package/lib/cjs/components/header/TreeHeader.js +0 -43
  105. package/lib/cjs/components/header/TreeHeader.js.map +0 -1
  106. package/lib/cjs/components/header/TreeHeader.scss +0 -20
  107. package/lib/cjs/components/search-bar/Popup.d.ts +0 -50
  108. package/lib/cjs/components/search-bar/Popup.js +0 -246
  109. package/lib/cjs/components/search-bar/Popup.js.map +0 -1
  110. package/lib/cjs/components/search-bar/Popup.scss +0 -316
  111. package/lib/esm/components/header/TreeHeader.d.ts +0 -15
  112. package/lib/esm/components/header/TreeHeader.js +0 -20
  113. package/lib/esm/components/header/TreeHeader.js.map +0 -1
  114. package/lib/esm/components/header/TreeHeader.scss +0 -20
  115. package/lib/esm/components/search-bar/Popup.d.ts +0 -50
  116. package/lib/esm/components/search-bar/Popup.js +0 -220
  117. package/lib/esm/components/search-bar/Popup.js.map +0 -1
  118. package/lib/esm/components/search-bar/Popup.scss +0 -316
@@ -1,5 +1,10 @@
1
1
  /// <reference types="react" />
2
2
  import "./CategoriesTree.scss";
3
- import type { CategoriesTreeProps } from "../../../types";
4
- export declare function CategoriesTreeComponent(props: CategoriesTreeProps): JSX.Element;
3
+ import type { CategoriesTreeHeaderButtonProps, CategoriesTreeProps } from "../../../types";
4
+ export declare function CategoriesTreeComponent(props: CategoriesTreeProps): JSX.Element | null;
5
+ export declare namespace CategoriesTreeComponent {
6
+ var ShowAllButton: (props: CategoriesTreeHeaderButtonProps) => JSX.Element;
7
+ var HideAllButton: (props: CategoriesTreeHeaderButtonProps) => JSX.Element;
8
+ var InvertButton: (props: CategoriesTreeHeaderButtonProps) => JSX.Element;
9
+ }
5
10
  //# sourceMappingURL=CategoriesTreeComponent.d.ts.map
@@ -31,31 +31,72 @@ const core_frontend_1 = require("@itwin/core-frontend");
31
31
  const CategoriesTree_1 = require("./CategoriesTree");
32
32
  const CategoryVisibilityHandler_1 = require("./CategoryVisibilityHandler");
33
33
  const CategoriesVisibilityUtils_1 = require("../CategoriesVisibilityUtils");
34
- const TreeHeader_1 = require("../../header/TreeHeader");
35
34
  const TreeFilteringState_1 = require("../../TreeFilteringState");
36
35
  const AutoSizer_1 = require("../../utils/AutoSizer");
36
+ const IconButton_1 = require("../../IconButton");
37
+ const TreeWidget_1 = require("../../../TreeWidget");
38
+ const SearchBar_1 = require("../../search-bar/SearchBar");
37
39
  function CategoriesTreeComponent(props) {
38
- const iModel = appui_react_1.useActiveIModelConnection();
39
- const viewport = appui_react_1.useActiveViewport();
40
- const { searchOptions, filterString, activeMatchIndex, onFilterApplied, filteredProvider, } = TreeFilteringState_1.useTreeFilteringState();
41
- const showAll = react_1.useCallback(async () => {
42
- if (!iModel)
43
- return;
44
- return CategoriesVisibilityUtils_1.toggleAllCategories(core_frontend_1.IModelApp.viewManager, iModel, true, undefined, true, filteredProvider ? await getFilteredCategories(filteredProvider) : undefined);
45
- }, [iModel, filteredProvider]);
46
- const hideAll = react_1.useCallback(async () => {
47
- if (!iModel)
48
- return;
49
- return CategoriesVisibilityUtils_1.toggleAllCategories(core_frontend_1.IModelApp.viewManager, iModel, false, undefined, true, filteredProvider ? await getFilteredCategories(filteredProvider) : undefined);
50
- }, [iModel, filteredProvider]);
51
- const invert = react_1.useCallback(async () => {
52
- if (!iModel || !viewport)
53
- return;
54
- const ids = filteredProvider ? await getFilteredCategories(filteredProvider) : await CategoriesVisibilityUtils_1.getCategories(iModel, viewport);
40
+ const iModel = (0, appui_react_1.useActiveIModelConnection)();
41
+ const viewport = (0, appui_react_1.useActiveViewport)();
42
+ if (!iModel || !viewport) {
43
+ return null;
44
+ }
45
+ return (react_1.default.createElement(CategoriesTreeComponentImpl, { ...props, iModel: iModel, viewport: viewport }));
46
+ }
47
+ exports.CategoriesTreeComponent = CategoriesTreeComponent;
48
+ CategoriesTreeComponent.ShowAllButton = ShowAllButton;
49
+ CategoriesTreeComponent.HideAllButton = HideAllButton;
50
+ CategoriesTreeComponent.InvertButton = InvertButton;
51
+ function CategoriesTreeComponentImpl(props) {
52
+ var _a;
53
+ const categories = (0, CategoryVisibilityHandler_1.useCategories)(core_frontend_1.IModelApp.viewManager, props.iModel, props.viewport);
54
+ const [filteredCategories, setFilteredCategories] = (0, react_1.useState)();
55
+ const { searchOptions, filterString, activeMatchIndex, onFilterApplied, filteredProvider, } = (0, TreeFilteringState_1.useTreeFilteringState)();
56
+ (0, react_1.useEffect)(() => {
57
+ (async () => {
58
+ if (filteredProvider)
59
+ setFilteredCategories((await getFilteredCategories(filteredProvider)).map((category) => ({ categoryId: category })));
60
+ else
61
+ setFilteredCategories(undefined);
62
+ })();
63
+ }, [filteredProvider]);
64
+ return (react_1.default.createElement(react_1.default.Fragment, null,
65
+ react_1.default.createElement(SearchBar_1.SearchBar, { value: "", valueChangedDelay: 500, placeholder: TreeWidget_1.TreeWidget.translate("search"), title: TreeWidget_1.TreeWidget.translate("searchForSomething"), filteringInProgress: searchOptions.isFiltering, onFilterCancel: searchOptions.onFilterCancel, onFilterClear: searchOptions.onFilterCancel, onFilterStart: searchOptions.onFilterStart, onSelectedChanged: searchOptions.onResultSelectedChanged, resultCount: (_a = searchOptions.matchedResultCount) !== null && _a !== void 0 ? _a : 0 }, props.headerButtons
66
+ ? props.headerButtons.map((btn, index) => react_1.default.createElement(react_1.default.Fragment, { key: index }, btn({ viewport: props.viewport, categories, filteredCategories })))
67
+ : [
68
+ react_1.default.createElement(ShowAllButton, { viewport: props.viewport, categories: categories, filteredCategories: filteredCategories, key: "show-all-btn" }),
69
+ react_1.default.createElement(HideAllButton, { viewport: props.viewport, categories: categories, filteredCategories: filteredCategories, key: "hide-all-btn" }),
70
+ react_1.default.createElement(InvertButton, { viewport: props.viewport, categories: categories, filteredCategories: filteredCategories, key: "invert-all-btn" }),
71
+ ]),
72
+ react_1.default.createElement(AutoSizer_1.AutoSizer, null, ({ width, height }) => (react_1.default.createElement(CategoriesTree_1.CategoryTree, { ...props, categories: categories, width: width, height: height, filterInfo: { filter: filterString, activeMatchIndex }, onFilterApplied: onFilterApplied })))));
73
+ }
74
+ async function getFilteredCategories(filteredProvider) {
75
+ const nodes = await filteredProvider.getNodes();
76
+ return nodes.map((node) => CategoryVisibilityHandler_1.CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(filteredProvider.getNodeKey(node)));
77
+ }
78
+ function ShowAllButton(props) {
79
+ const showAll = () => {
80
+ var _a;
81
+ (0, CategoriesVisibilityUtils_1.enableCategory)(core_frontend_1.IModelApp.viewManager, props.viewport.iModel, ((_a = props.filteredCategories) !== null && _a !== void 0 ? _a : props.categories).map((category) => category.categoryId), true, true);
82
+ };
83
+ return (react_1.default.createElement(IconButton_1.IconButton, { className: "tree-widget-header-tree-toolbar-icon", icon: "icon-visibility", title: TreeWidget_1.TreeWidget.translate("showAll"), onClick: showAll }));
84
+ }
85
+ function HideAllButton(props) {
86
+ const hideAll = () => {
87
+ var _a;
88
+ (0, CategoriesVisibilityUtils_1.enableCategory)(core_frontend_1.IModelApp.viewManager, props.viewport.iModel, ((_a = props.filteredCategories) !== null && _a !== void 0 ? _a : props.categories).map((category) => category.categoryId), false, true);
89
+ };
90
+ return (react_1.default.createElement(IconButton_1.IconButton, { className: "tree-widget-header-tree-toolbar-icon", icon: "icon-visibility-hide-2", title: TreeWidget_1.TreeWidget.translate("hideAll"), onClick: hideAll }));
91
+ }
92
+ function InvertButton(props) {
93
+ const invert = () => {
94
+ var _a;
95
+ const ids = ((_a = props.filteredCategories) !== null && _a !== void 0 ? _a : props.categories).map((category) => category.categoryId);
55
96
  const enabled = [];
56
97
  const disabled = [];
57
98
  for (const id of ids) {
58
- if (viewport.view.viewsCategory(id)) {
99
+ if (props.viewport.view.viewsCategory(id)) {
59
100
  enabled.push(id);
60
101
  }
61
102
  else {
@@ -63,18 +104,10 @@ function CategoriesTreeComponent(props) {
63
104
  }
64
105
  }
65
106
  // Disable enabled
66
- CategoriesVisibilityUtils_1.enableCategory(core_frontend_1.IModelApp.viewManager, iModel, enabled, false, true);
107
+ (0, CategoriesVisibilityUtils_1.enableCategory)(core_frontend_1.IModelApp.viewManager, props.viewport.iModel, enabled, false, true);
67
108
  // Enable disabled
68
- CategoriesVisibilityUtils_1.enableCategory(core_frontend_1.IModelApp.viewManager, iModel, disabled, true, true);
69
- }, [iModel, viewport, filteredProvider]);
70
- return (react_1.default.createElement(react_1.default.Fragment, null, iModel && viewport &&
71
- react_1.default.createElement(react_1.default.Fragment, null,
72
- react_1.default.createElement(TreeHeader_1.TreeHeaderComponent, { searchOptions: searchOptions, showAll: showAll, hideAll: hideAll, invert: invert }),
73
- react_1.default.createElement(AutoSizer_1.AutoSizer, null, ({ width, height }) => (react_1.default.createElement(CategoriesTree_1.CategoryTree, { ...props, iModel: iModel, width: width, height: height, filterInfo: { filter: filterString, activeMatchIndex }, onFilterApplied: onFilterApplied }))))));
74
- }
75
- exports.CategoriesTreeComponent = CategoriesTreeComponent;
76
- async function getFilteredCategories(filteredProvider) {
77
- const nodes = await filteredProvider.getNodes();
78
- return nodes.map((node) => CategoryVisibilityHandler_1.CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(filteredProvider.getNodeKey(node)));
109
+ (0, CategoriesVisibilityUtils_1.enableCategory)(core_frontend_1.IModelApp.viewManager, props.viewport.iModel, disabled, true, true);
110
+ };
111
+ return (react_1.default.createElement(IconButton_1.IconButton, { className: "tree-widget-header-tree-toolbar-icon", title: TreeWidget_1.TreeWidget.translate("invert"), icon: "icon-visibility-invert", onClick: invert }));
79
112
  }
80
113
  //# 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;AAC/F,iCAA+B;AAC/B,+CAA2C;AAC3C,oDAAkF;AAClF,wDAAiD;AACjD,qDAAgD;AAChD,2EAAwE;AACxE,4EAAkG;AAClG,wDAA8D;AAC9D,iEAAiE;AACjE,qDAAkD;AAIlD,SAAgB,uBAAuB,CAAC,KAA0B;IAChE,MAAM,MAAM,GAAG,uCAAyB,EAAE,CAAC;IAC3C,MAAM,QAAQ,GAAG,+BAAiB,EAAE,CAAC;IAErC,MAAM,EACJ,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,gBAAgB,GACjB,GAAG,0CAAqB,EAAE,CAAC;IAE5B,MAAM,OAAO,GAAG,mBAAW,CAAC,KAAK,IAAI,EAAE;QACrC,IAAI,CAAC,MAAM;YAAE,OAAO;QAEpB,OAAO,+CAAmB,CACxB,yBAAS,CAAC,WAAW,EACrB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,CAAC;QACF,kBAAkB;QAClB,0CAAc,CACZ,yBAAS,CAAC,WAAW,EACrB,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,IAAI,CACL,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAEzC,OAAO,CACL,8DACG,MAAM,IAAI,QAAQ;QACjB;YACE,8BAAC,gCAAmB,IAClB,aAAa,EAAE,aAAa,EAC5B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,GACd;YACF,8BAAC,qBAAS,QACP,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CACtB,8BAAC,6BAAY,OACP,KAAK,EACT,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,gBAAgB,EAAE,EACtD,eAAe,EAAE,eAAe,GAChC,CACH,CACS,CACX,CAEJ,CACJ,CAAC;AACJ,CAAC;AA7FD,0DA6FC;AAED,KAAK,UAAU,qBAAqB,CAAC,gBAA+C;IAClF,MAAM,KAAK,GAAG,MAAM,gBAAgB,CAAC,QAAQ,EAAE,CAAC;IAChD,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,qDAAyB,CAAC,4BAA4B,CAAC,gBAAgB,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACxH,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*--------------------------------------------------------------------------------------------*/\nimport \"./CategoriesTree.scss\";\nimport React, { useCallback } from \"react\";\nimport { useActiveIModelConnection, useActiveViewport } from \"@itwin/appui-react\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { CategoryTree } from \"./CategoriesTree\";\nimport { CategoryVisibilityHandler } from \"./CategoryVisibilityHandler\";\nimport { enableCategory, getCategories, toggleAllCategories } from \"../CategoriesVisibilityUtils\";\nimport { TreeHeaderComponent } from \"../../header/TreeHeader\";\nimport { useTreeFilteringState } from \"../../TreeFilteringState\";\nimport { AutoSizer } from \"../../utils/AutoSizer\";\nimport type { CategoriesTreeProps } from \"../../../types\";\nimport type { IPresentationTreeDataProvider } from \"@itwin/presentation-components\";\n\nexport function CategoriesTreeComponent(props: CategoriesTreeProps) {\n const iModel = useActiveIModelConnection();\n const viewport = useActiveViewport();\n\n const {\n searchOptions,\n filterString,\n activeMatchIndex,\n onFilterApplied,\n filteredProvider,\n } = useTreeFilteringState();\n\n const showAll = useCallback(async () => {\n if (!iModel) return;\n\n return toggleAllCategories(\n IModelApp.viewManager,\n iModel,\n true,\n undefined,\n true,\n filteredProvider ? await getFilteredCategories(filteredProvider) : undefined,\n );\n }, [iModel, filteredProvider]);\n\n const hideAll = useCallback(async () => {\n if (!iModel) return;\n return toggleAllCategories(\n IModelApp.viewManager,\n iModel,\n false,\n undefined,\n true,\n filteredProvider ? await getFilteredCategories(filteredProvider) : undefined,\n );\n }, [iModel, filteredProvider]);\n\n const invert = useCallback(async () => {\n if (!iModel || !viewport) return;\n const ids = filteredProvider ? await getFilteredCategories(filteredProvider) : await getCategories(iModel, viewport);\n const enabled: string[] = [];\n const disabled: string[] = [];\n for (const id of ids) {\n if (viewport.view.viewsCategory(id)) {\n enabled.push(id);\n } else {\n disabled.push(id);\n }\n }\n // Disable enabled\n enableCategory(\n IModelApp.viewManager,\n iModel,\n enabled,\n false,\n true\n );\n // Enable disabled\n enableCategory(\n IModelApp.viewManager,\n iModel,\n disabled,\n true,\n true\n );\n }, [iModel, viewport, filteredProvider]);\n\n return (\n <>\n {iModel && viewport &&\n <>\n <TreeHeaderComponent\n searchOptions={searchOptions}\n showAll={showAll}\n hideAll={hideAll}\n invert={invert}\n />\n <AutoSizer>\n {({ width, height }) => (\n <CategoryTree\n {...props}\n iModel={iModel}\n width={width}\n height={height}\n filterInfo={{ filter: filterString, activeMatchIndex }}\n onFilterApplied={onFilterApplied}\n />\n )}\n </AutoSizer>\n </>\n }\n </>\n );\n}\n\nasync function getFilteredCategories(filteredProvider: IPresentationTreeDataProvider) {\n const nodes = await filteredProvider.getNodes();\n return nodes.map((node) => CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(filteredProvider.getNodeKey(node)));\n}\n"]}
1
+ {"version":3,"file":"CategoriesTreeComponent.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoriesTreeComponent.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F,iCAA+B;AAC/B,+CAAmD;AACnD,oDAAkF;AAClF,wDAAmF;AACnF,qDAAgD;AAChD,2EAAqG;AACrG,4EAA8D;AAC9D,iEAAiE;AACjE,qDAAkD;AAGlD,iDAA8C;AAC9C,oDAAiD;AACjD,0DAAuD;AAEvD,SAAgB,uBAAuB,CAAC,KAA0B;IAChE,MAAM,MAAM,GAAG,IAAA,uCAAyB,GAAE,CAAC;IAC3C,MAAM,QAAQ,GAAG,IAAA,+BAAiB,GAAE,CAAC;IAErC,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE;QACxB,OAAO,IAAI,CAAC;KACb;IAED,OAAO,CACL,8BAAC,2BAA2B,OAAK,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAI,CAC/E,CAAC;AACJ,CAAC;AAXD,0DAWC;AAED,uBAAuB,CAAC,aAAa,GAAG,aAAa,CAAC;AACtD,uBAAuB,CAAC,aAAa,GAAG,aAAa,CAAC;AACtD,uBAAuB,CAAC,YAAY,GAAG,YAAY,CAAC;AAEpD,SAAS,2BAA2B,CAAC,KAAmF;;IACtH,MAAM,UAAU,GAAG,IAAA,yCAAa,EAAC,yBAAS,CAAC,WAAW,EAAE,KAAK,CAAC,MAAM,EAA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C;QAElG,MAAM,OAAO,GAAa,EAAE,CAAC;QAC7B,MAAM,QAAQ,GAAa,EAAE,CAAC;QAC9B,KAAK,MAAM,EAAE,IAAI,GAAG,EAAE;YACpB,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,EAAE;gBACzC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;aAClB;iBAAM;gBACL,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;aACnB;SACF;QACD,kBAAkB;QAClB,IAAA,0CAAc,EACZ,yBAAS,CAAC,WAAW,EACrB,KAAK,CAAC,QAAQ,CAAC,MAAM,EACrB,OAAO,EACP,KAAK,EACL,IAAI,CACL,CAAC;QAEF,kBAAkB;QAClB,IAAA,0CAAc,EACZ,yBAAS,CAAC,WAAW,EACrB,KAAK,CAAC,QAAQ,CAAC,MAAM,EACrB,QAAQ,EACR,IAAI,EACJ,IAAI,CACL,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,CACL,8BAAC,uBAAU,IACT,SAAS,EAAC,sCAAsC,EAChD,KAAK,EAAE,uBAAU,CAAC,SAAS,CAAC,QAAQ,CAAC,EACrC,IAAI,EAAC,wBAAwB,EAC7B,OAAO,EAAE,MAAM,GACf,CACH,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport \"./CategoriesTree.scss\";\nimport React, { useEffect, useState } from \"react\";\nimport { useActiveIModelConnection, useActiveViewport } from \"@itwin/appui-react\";\nimport { IModelApp, IModelConnection, ScreenViewport } from \"@itwin/core-frontend\";\nimport { CategoryTree } from \"./CategoriesTree\";\nimport { CategoryInfo, CategoryVisibilityHandler, useCategories } from \"./CategoryVisibilityHandler\";\nimport { enableCategory } from \"../CategoriesVisibilityUtils\";\nimport { useTreeFilteringState } from \"../../TreeFilteringState\";\nimport { AutoSizer } from \"../../utils/AutoSizer\";\nimport type { CategoriesTreeHeaderButtonProps, CategoriesTreeProps } from \"../../../types\";\nimport type { IPresentationTreeDataProvider } from \"@itwin/presentation-components\";\nimport { IconButton } from \"../../IconButton\";\nimport { TreeWidget } from \"../../../TreeWidget\";\nimport { SearchBar } from \"../../search-bar/SearchBar\";\n\nexport function CategoriesTreeComponent(props: CategoriesTreeProps) {\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\nCategoriesTreeComponent.ShowAllButton = ShowAllButton;\nCategoriesTreeComponent.HideAllButton = HideAllButton;\nCategoriesTreeComponent.InvertButton = InvertButton;\n\nfunction CategoriesTreeComponentImpl(props: CategoriesTreeProps & { 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 activeMatchIndex,\n onFilterApplied,\n filteredProvider,\n } = useTreeFilteringState();\n\n useEffect(() => {\n (async () => {\n if (filteredProvider)\n setFilteredCategories((await getFilteredCategories(filteredProvider)).map((category) => ({ categoryId: category })));\n else\n setFilteredCategories(undefined);\n })();\n }, [filteredProvider]);\n\n return (\n <>\n <SearchBar\n value=\"\"\n valueChangedDelay={500}\n placeholder={TreeWidget.translate(\"search\")}\n title={TreeWidget.translate(\"searchForSomething\")}\n filteringInProgress={searchOptions.isFiltering}\n onFilterCancel={searchOptions.onFilterCancel}\n onFilterClear={searchOptions.onFilterCancel}\n onFilterStart={searchOptions.onFilterStart}\n onSelectedChanged={searchOptions.onResultSelectedChanged}\n resultCount={searchOptions.matchedResultCount ?? 0}\n >\n {props.headerButtons\n ? props.headerButtons.map((btn, index) =>\n <React.Fragment key={index}>\n {btn({ viewport: props.viewport, categories, filteredCategories })}\n </React.Fragment>)\n : [\n <ShowAllButton viewport={props.viewport} categories={categories} filteredCategories={filteredCategories} key=\"show-all-btn\" />,\n <HideAllButton viewport={props.viewport} categories={categories} filteredCategories={filteredCategories} key=\"hide-all-btn\" />,\n <InvertButton viewport={props.viewport} categories={categories} filteredCategories={filteredCategories} key=\"invert-all-btn\" />,\n ]\n }\n </SearchBar>\n <AutoSizer>\n {({ width, height }) => (\n <CategoryTree\n {...props}\n categories={categories}\n width={width}\n height={height}\n filterInfo={{ filter: filterString, activeMatchIndex }}\n onFilterApplied={onFilterApplied}\n />\n )}\n </AutoSizer>\n </>\n );\n}\n\nasync function getFilteredCategories(filteredProvider: IPresentationTreeDataProvider) {\n const nodes = await filteredProvider.getNodes();\n return nodes.map((node) => CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(filteredProvider.getNodeKey(node)));\n}\n\nfunction ShowAllButton(props: CategoriesTreeHeaderButtonProps) {\n const showAll = () => {\n enableCategory(\n IModelApp.viewManager,\n props.viewport.iModel,\n (props.filteredCategories ?? props.categories).map((category) => category.categoryId),\n true,\n true,\n );\n };\n\n return (\n <IconButton\n className=\"tree-widget-header-tree-toolbar-icon\"\n icon=\"icon-visibility\"\n title={TreeWidget.translate(\"showAll\")}\n onClick={showAll}\n />\n );\n}\n\nfunction HideAllButton(props: CategoriesTreeHeaderButtonProps) {\n const hideAll = () => {\n enableCategory(\n IModelApp.viewManager,\n props.viewport.iModel,\n (props.filteredCategories ?? props.categories).map((category) => category.categoryId),\n false,\n true,\n );\n };\n\n return (\n <IconButton\n className=\"tree-widget-header-tree-toolbar-icon\"\n icon=\"icon-visibility-hide-2\"\n title={TreeWidget.translate(\"hideAll\")}\n onClick={hideAll}\n />\n );\n}\n\nfunction InvertButton(props: CategoriesTreeHeaderButtonProps) {\n const invert = () => {\n const ids = (props.filteredCategories ?? props.categories).map((category) => category.categoryId);\n\n const enabled: string[] = [];\n const disabled: string[] = [];\n for (const id of ids) {\n if (props.viewport.view.viewsCategory(id)) {\n enabled.push(id);\n } else {\n disabled.push(id);\n }\n }\n // Disable enabled\n enableCategory(\n IModelApp.viewManager,\n props.viewport.iModel,\n enabled,\n false,\n true\n );\n\n // Enable disabled\n enableCategory(\n IModelApp.viewManager,\n props.viewport.iModel,\n disabled,\n true,\n true\n );\n };\n\n return (\n <IconButton\n className=\"tree-widget-header-tree-toolbar-icon\"\n title={TreeWidget.translate(\"invert\")}\n icon=\"icon-visibility-invert\"\n onClick={invert}\n />\n );\n}\n"]}
@@ -1,26 +1,26 @@
1
+ import { TreeNodeItem } from "@itwin/components-react";
1
2
  import { BeEvent } from "@itwin/core-bentley";
3
+ import { IModelConnection, ViewManager, Viewport } from "@itwin/core-frontend";
2
4
  import { NodeKey } from "@itwin/presentation-common";
3
- import type { IModelConnection, ViewManager, Viewport } from "@itwin/core-frontend";
4
- import type { TreeNodeItem } from "@itwin/components-react";
5
- import type { IVisibilityHandler, VisibilityChangeListener, VisibilityStatus } from "../VisibilityTreeEventHandler";
5
+ import { IVisibilityHandler, VisibilityChangeListener, VisibilityStatus } from "../VisibilityTreeEventHandler";
6
6
  /**
7
7
  * Loads categories from viewport or uses provided list of categories.
8
8
  * @internal
9
9
  */
10
- export declare function useCategories(viewManager: ViewManager, imodel: IModelConnection, view?: Viewport): Category[];
10
+ export declare function useCategories(viewManager: ViewManager, imodel: IModelConnection, view?: Viewport): CategoryInfo[];
11
11
  /**
12
12
  * Data structure that describes category.
13
13
  * @alpha
14
14
  */
15
- export interface Category {
16
- key: string;
17
- children?: string[];
15
+ export interface CategoryInfo {
16
+ categoryId: string;
17
+ subCategoryIds?: string[];
18
18
  }
19
19
  /** @alpha */
20
20
  export interface CategoryVisibilityHandlerParams {
21
21
  viewManager: ViewManager;
22
22
  imodel: IModelConnection;
23
- categories: Category[];
23
+ categories: CategoryInfo[];
24
24
  activeView?: Viewport;
25
25
  allViewports?: boolean;
26
26
  }
@@ -39,7 +39,7 @@ export declare class CategoryVisibilityHandler implements IVisibilityHandler {
39
39
  changeVisibility(node: TreeNodeItem, nodeKey: NodeKey, shouldDisplay: boolean): Promise<void>;
40
40
  getSubCategoryVisibility(id: string): "visible" | "hidden";
41
41
  getCategoryVisibility(id: string): "visible" | "hidden";
42
- getParent(key: string): Category | undefined;
42
+ getParent(key: string): CategoryInfo | undefined;
43
43
  private onDisplayStyleChanged;
44
44
  private onViewedCategoriesChanged;
45
45
  private onVisibilityChangeInternal;
@@ -37,8 +37,8 @@ const EMPTY_CATEGORIES_ARRAY = [];
37
37
  function useCategories(viewManager, imodel, view) {
38
38
  var _a;
39
39
  const currentView = view || viewManager.getFirstOpenView();
40
- const categoriesPromise = React.useMemo(async () => CategoriesVisibilityUtils_1.loadCategoriesFromViewport(imodel, currentView), [imodel, currentView]);
41
- return (_a = components_react_1.useAsyncValue(categoriesPromise)) !== null && _a !== void 0 ? _a : EMPTY_CATEGORIES_ARRAY;
40
+ const categoriesPromise = React.useMemo(async () => (0, CategoriesVisibilityUtils_1.loadCategoriesFromViewport)(imodel, currentView), [imodel, currentView]);
41
+ return (_a = (0, components_react_1.useAsyncValue)(categoriesPromise)) !== null && _a !== void 0 ? _a : EMPTY_CATEGORIES_ARRAY;
42
42
  }
43
43
  exports.useCategories = useCategories;
44
44
  /** @alpha */
@@ -82,7 +82,7 @@ class CategoryVisibilityHandler {
82
82
  if (node.parentId) {
83
83
  const childId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);
84
84
  // istanbul ignore next
85
- const parentId = (_a = this.getParent(childId)) === null || _a === void 0 ? void 0 : _a.key;
85
+ const parentId = (_a = this.getParent(childId)) === null || _a === void 0 ? void 0 : _a.categoryId;
86
86
  // make sure parent category is enabled
87
87
  if (shouldDisplay && parentId)
88
88
  this.enableCategory([parentId], true, false);
@@ -96,7 +96,7 @@ class CategoryVisibilityHandler {
96
96
  const parentItem = this.getParent(id);
97
97
  if (!parentItem || !this._activeView)
98
98
  return "hidden";
99
- const isVisible = this._activeView.view.viewsCategory(parentItem.key) && this._activeView.isSubCategoryVisible(id);
99
+ const isVisible = this._activeView.view.viewsCategory(parentItem.categoryId) && this._activeView.isSubCategoryVisible(id);
100
100
  return isVisible ? "visible" : "hidden";
101
101
  }
102
102
  getCategoryVisibility(id) {
@@ -107,8 +107,8 @@ class CategoryVisibilityHandler {
107
107
  getParent(key) {
108
108
  for (const category of this._categories) {
109
109
  // istanbul ignore else
110
- if (category.children) {
111
- if (category.children.indexOf(key) !== -1)
110
+ if (category.subCategoryIds) {
111
+ if (category.subCategoryIds.indexOf(key) !== -1)
112
112
  return category;
113
113
  }
114
114
  }
@@ -126,10 +126,10 @@ class CategoryVisibilityHandler {
126
126
  return (presentation_common_1.NodeKey.isInstancesNodeKey(nodeKey) && nodeKey.instanceKeys.length > 0) ? nodeKey.instanceKeys[0].id : /* istanbul ignore next */ "";
127
127
  }
128
128
  enableCategory(ids, enabled, enableAllSubCategories = true) {
129
- CategoriesVisibilityUtils_1.enableCategory(this._viewManager, this._imodel, ids, enabled, this._useAllViewports, enableAllSubCategories);
129
+ (0, CategoriesVisibilityUtils_1.enableCategory)(this._viewManager, this._imodel, ids, enabled, this._useAllViewports, enableAllSubCategories);
130
130
  }
131
131
  enableSubCategory(key, enabled) {
132
- CategoriesVisibilityUtils_1.enableSubCategory(this._viewManager, key, enabled, this._useAllViewports);
132
+ (0, CategoriesVisibilityUtils_1.enableSubCategory)(this._viewManager, key, enabled, this._useAllViewports);
133
133
  }
134
134
  }
135
135
  exports.CategoryVisibilityHandler = CategoryVisibilityHandler;
@@ -1 +1 @@
1
- {"version":3,"file":"CategoryVisibilityHandler.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoryVisibilityHandler.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;;;;;;;;;;;AAE/F,6CAA+B;AAC/B,8DAAwD;AACxD,sDAA8C;AAC9C,oEAAqD;AAIrD,4EAA6G;AAE7G,MAAM,sBAAsB,GAAe,EAAE,CAAC;AAE9C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C;IACR,CAAC;IAEM,MAAM,CAAC,4BAA4B,CAAC,OAAgB;QACzD,OAAO,CAAC,6BAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,0BAA0B,CAAC,EAAE,CAAC;IAC/I,CAAC;IAEM,cAAc,CAAC,GAAa,EAAE,OAAgB,EAAE,sBAAsB,GAAG,IAAI;QAClF,0CAAc,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,gBAAgB,EAAE,sBAAsB,CAAC,CAAC;IAC/G,CAAC;IAEM,iBAAiB,CAAC,GAAW,EAAE,OAAgB;QACpD,6CAAiB,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC5E,CAAC;CACF;AAjHD,8DAiHC","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 * as React from \"react\";\nimport { useAsyncValue } from \"@itwin/components-react\";\nimport { BeEvent } from \"@itwin/core-bentley\";\nimport { NodeKey } from \"@itwin/presentation-common\";\nimport type { IModelConnection, ViewManager, Viewport } from \"@itwin/core-frontend\";\nimport type { TreeNodeItem } from \"@itwin/components-react\";\nimport type { IVisibilityHandler, VisibilityChangeListener, VisibilityStatus } from \"../VisibilityTreeEventHandler\";\nimport { enableCategory, enableSubCategory, loadCategoriesFromViewport } from \"../CategoriesVisibilityUtils\";\n\nconst EMPTY_CATEGORIES_ARRAY: Category[] = [];\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 = React.useMemo(async () => loadCategoriesFromViewport(imodel, currentView), [imodel, currentView]);\n return useAsyncValue(categoriesPromise) ?? EMPTY_CATEGORIES_ARRAY;\n}\n\n/**\n * Data structure that describes category.\n * @alpha\n */\nexport interface Category {\n key: string;\n children?: string[];\n}\n\n/** @alpha */\nexport interface CategoryVisibilityHandlerParams {\n viewManager: ViewManager;\n imodel: IModelConnection;\n categories: Category[];\n activeView?: Viewport;\n allViewports?: boolean;\n}\n\n/** @alpha */\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: Category[];\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 if (this._activeView) {\n this._activeView.onDisplayStyleChanged.addListener(this.onDisplayStyleChanged);\n this._activeView.onViewedCategoriesChanged.addListener(this.onViewedCategoriesChanged);\n }\n }\n\n public dispose() {\n if (this._activeView) {\n this._activeView.onDisplayStyleChanged.removeListener(this.onDisplayStyleChanged);\n this._activeView.onViewedCategoriesChanged.removeListener(this.onViewedCategoriesChanged);\n }\n clearTimeout(this._pendingVisibilityChange);\n }\n\n public onVisibilityChange = new BeEvent<VisibilityChangeListener>();\n\n public getVisibilityStatus(node: TreeNodeItem, nodeKey: NodeKey): VisibilityStatus {\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, nodeKey: NodeKey, shouldDisplay: boolean): Promise<void> {\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)?.key;\n\n // make sure parent category is enabled\n if (shouldDisplay && parentId)\n this.enableCategory([parentId], true, false);\n\n this.enableSubCategory(childId, shouldDisplay);\n return;\n }\n\n const instanceId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);\n this.enableCategory([instanceId], shouldDisplay, true);\n }\n\n public getSubCategoryVisibility(id: string) {\n const parentItem = this.getParent(id);\n if (!parentItem || !this._activeView)\n return \"hidden\";\n\n const isVisible = this._activeView.view.viewsCategory(parentItem.key) && this._activeView.isSubCategoryVisible(id);\n return isVisible ? \"visible\" : \"hidden\";\n }\n\n public getCategoryVisibility(id: string) {\n if (!this._activeView)\n return \"hidden\";\n return this._activeView.view.viewsCategory(id) ? \"visible\" : \"hidden\";\n }\n\n public getParent(key: string): Category | undefined {\n for (const category of this._categories) {\n // istanbul ignore else\n if (category.children) {\n if (category.children.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 enableCategory(ids: string[], enabled: boolean, enableAllSubCategories = true) {\n 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"]}
1
+ {"version":3,"file":"CategoryVisibilityHandler.js","sourceRoot":"","sources":["../../../../../src/components/trees/category-tree/CategoryVisibilityHandler.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;;;;;;;;;;;AAE/F,6CAA+B;AAC/B,8DAAsE;AACtE,sDAA8C;AAE9C,oEAAqD;AACrD,4EAA6G;AAG7G,MAAM,sBAAsB,GAAmB,EAAE,CAAC;AAElD;;;GAGG;AACH,SAAgB,aAAa,CAAC,WAAwB,EAAE,MAAwB,EAAE,IAAe;;IAC/F,MAAM,WAAW,GAAG,IAAI,IAAI,WAAW,CAAC,gBAAgB,EAAE,CAAC;IAC3D,MAAM,iBAAiB,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,IAAA,sDAA0B,EAAC,MAAM,EAAE,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;IAC5H,OAAO,MAAA,IAAA,gCAAa,EAAC,iBAAiB,CAAC,mCAAI,sBAAsB,CAAC;AACpE,CAAC;AAJD,sCAIC;AAoBD,aAAa;AACb,MAAa,yBAAyB;IAQpC,YAAY,MAAuC;;QAqB5C,uBAAkB,GAAG,IAAI,sBAAO,EAA4B,CAAC;QAqDpE,gEAAgE;QACxD,0BAAqB,GAAG,GAAG,EAAE;YACnC,IAAI,CAAC,0BAA0B,EAAE,CAAC;QACpC,CAAC,CAAC;QAEF,gEAAgE;QACxD,8BAAyB,GAAG,GAAG,EAAE;YACvC,IAAI,CAAC,0BAA0B,EAAE,CAAC;QACpC,CAAC,CAAC;QAjFA,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,WAAW,CAAC;QACvC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC;QACrC,uBAAuB;QACvB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AC,KAAK,CAAC,CAAC;oBAC7C,OAAO,QAAQ,CAAC;aACnB;SACF;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAYO,0BAA0B;QAChC,IAAI,IAAI,CAAC,wBAAwB;YAC/B,OAAO;QAET,IAAI,CAAC,wBAAwB,GAAG,UAAU,CAAC,GAAG,EAAE;YAC9C,IAAI,CAAC,kBAAkB,CAAC,UAAU,EAAE,CAAC;YACrC,IAAI,CAAC,wBAAwB,GAAG,SAAS,CAAC;QAC5C,CAAC,EAAE,CAAC,CAAC,CAAC;IACR,CAAC;IAEM,MAAM,CAAC,4BAA4B,CAAC,OAAgB;QACzD,OAAO,CAAC,6BAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,0BAA0B,CAAC,EAAE,CAAC;IAC/I,CAAC;IAEM,cAAc,CAAC,GAAa,EAAE,OAAgB,EAAE,sBAAsB,GAAG,IAAI;QAClF,IAAA,0CAAc,EAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,gBAAgB,EAAE,sBAAsB,CAAC,CAAC;IAC/G,CAAC;IAEM,iBAAiB,CAAC,GAAW,EAAE,OAAgB;QACpD,IAAA,6CAAiB,EAAC,IAAI,CAAC,YAAY,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC5E,CAAC;CACF;AAjHD,8DAiHC","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 * as React from \"react\";\nimport { TreeNodeItem, useAsyncValue } from \"@itwin/components-react\";\nimport { BeEvent } from \"@itwin/core-bentley\";\nimport { IModelConnection, ViewManager, Viewport } from \"@itwin/core-frontend\";\nimport { NodeKey } from \"@itwin/presentation-common\";\nimport { enableCategory, enableSubCategory, loadCategoriesFromViewport } from \"../CategoriesVisibilityUtils\";\nimport { 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 = React.useMemo(async () => loadCategoriesFromViewport(imodel, currentView), [imodel, currentView]);\n return useAsyncValue(categoriesPromise) ?? EMPTY_CATEGORIES_ARRAY;\n}\n\n/**\n * Data structure that describes category.\n * @alpha\n */\nexport interface CategoryInfo {\n categoryId: string;\n subCategoryIds?: string[];\n}\n\n/** @alpha */\nexport interface CategoryVisibilityHandlerParams {\n viewManager: ViewManager;\n imodel: IModelConnection;\n categories: CategoryInfo[];\n activeView?: Viewport;\n allViewports?: boolean;\n}\n\n/** @alpha */\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 if (this._activeView) {\n this._activeView.onDisplayStyleChanged.addListener(this.onDisplayStyleChanged);\n this._activeView.onViewedCategoriesChanged.addListener(this.onViewedCategoriesChanged);\n }\n }\n\n public dispose() {\n if (this._activeView) {\n this._activeView.onDisplayStyleChanged.removeListener(this.onDisplayStyleChanged);\n this._activeView.onViewedCategoriesChanged.removeListener(this.onViewedCategoriesChanged);\n }\n clearTimeout(this._pendingVisibilityChange);\n }\n\n public onVisibilityChange = new BeEvent<VisibilityChangeListener>();\n\n public getVisibilityStatus(node: TreeNodeItem, nodeKey: NodeKey): VisibilityStatus {\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, nodeKey: NodeKey, shouldDisplay: boolean): Promise<void> {\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 this.enableCategory([parentId], true, false);\n\n this.enableSubCategory(childId, shouldDisplay);\n return;\n }\n\n const instanceId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(nodeKey);\n this.enableCategory([instanceId], shouldDisplay, true);\n }\n\n public getSubCategoryVisibility(id: string) {\n const parentItem = this.getParent(id);\n if (!parentItem || !this._activeView)\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 if (!this._activeView)\n return \"hidden\";\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 enableCategory(ids: string[], enabled: boolean, enableAllSubCategories = true) {\n 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"]}
@@ -1,13 +1,11 @@
1
1
  import "./ModelsTree.scss";
2
2
  import * as React from "react";
3
3
  import { SelectionMode } from "@itwin/components-react";
4
- import { ClassGroupingOption } from "../Common";
5
- import { ModelsVisibilityHandler } from "./ModelsVisibilityHandler";
6
- import type { VisibilityTreeFilterInfo } from "../Common";
7
- import type { ModelsTreeSelectionPredicate } from "./ModelsVisibilityHandler";
8
- import type { IModelConnection, Viewport } from "@itwin/core-frontend";
9
- import type { Ruleset } from "@itwin/presentation-common";
10
- import type { IPresentationTreeDataProvider } from "@itwin/presentation-components";
4
+ import { IModelConnection, Viewport } from "@itwin/core-frontend";
5
+ import { Ruleset } from "@itwin/presentation-common";
6
+ import { IPresentationTreeDataProvider } from "@itwin/presentation-components";
7
+ import { ClassGroupingOption, VisibilityTreeFilterInfo } from "../Common";
8
+ import { ModelsTreeSelectionPredicate, ModelsVisibilityHandler } from "./ModelsVisibilityHandler";
11
9
  /** @internal */
12
10
  export declare const RULESET_MODELS: Ruleset;
13
11
  /** @internal */
@@ -48,21 +48,21 @@ const RULESET_MODELS_SEARCH = require("./ModelsTreeSearch.json"); // eslint-disa
48
48
  */
49
49
  function ModelsTree(props) {
50
50
  const { nodeLoader, onItemsRendered } = useModelsTreeNodeLoader(props);
51
- const { filteredNodeLoader, isFiltering, nodeHighlightingProps } = VisibilityTreeRenderer_1.useVisibilityTreeFiltering(nodeLoader, props.filterInfo, props.onFilterApplied);
51
+ const { filteredNodeLoader, isFiltering, nodeHighlightingProps } = (0, VisibilityTreeRenderer_1.useVisibilityTreeFiltering)(nodeLoader, props.filterInfo, props.onFilterApplied);
52
52
  const filterApplied = filteredNodeLoader !== nodeLoader;
53
53
  const { activeView, modelsVisibilityHandler, selectionPredicate } = props;
54
54
  const nodeSelectionPredicate = React.useCallback((key, node) => {
55
55
  return !selectionPredicate ? true : selectionPredicate(key, ModelsVisibilityHandler_1.ModelsVisibilityHandler.getNodeType(node, nodeLoader.dataProvider));
56
56
  }, [selectionPredicate, nodeLoader.dataProvider]);
57
57
  const visibilityHandler = useVisibilityHandler(nodeLoader.dataProvider.rulesetId, props.iModel, activeView, modelsVisibilityHandler, getFilteredDataProvider(filteredNodeLoader.dataProvider), props.enableHierarchyAutoUpdate);
58
- const eventHandler = core_react_1.useDisposable(React.useCallback(() => new VisibilityTreeEventHandler_1.VisibilityTreeEventHandler({
58
+ const eventHandler = (0, core_react_1.useDisposable)(React.useCallback(() => new VisibilityTreeEventHandler_1.VisibilityTreeEventHandler({
59
59
  nodeLoader: filteredNodeLoader,
60
60
  visibilityHandler,
61
61
  collapsedChildrenDisposalEnabled: true,
62
62
  selectionPredicate: nodeSelectionPredicate,
63
63
  }), [filteredNodeLoader, visibilityHandler, nodeSelectionPredicate]));
64
- const treeModel = components_react_1.useTreeModel(filteredNodeLoader.modelSource);
65
- const treeRenderer = VisibilityTreeRenderer_1.useVisibilityTreeRenderer(true, false);
64
+ const treeModel = (0, components_react_1.useTreeModel)(filteredNodeLoader.modelSource);
65
+ const treeRenderer = (0, VisibilityTreeRenderer_1.useVisibilityTreeRenderer)(true, false);
66
66
  const overlay = isFiltering ? React.createElement("div", { className: "filteredTreeOverlay" }) : undefined;
67
67
  // istanbul ignore next
68
68
  const noFilteredDataRenderer = React.useCallback(() => {
@@ -79,14 +79,14 @@ function useModelsTreeNodeLoader(props) {
79
79
  general: (!props.enableElementsClassGrouping) ? exports.RULESET_MODELS : /* istanbul ignore next */ exports.RULESET_MODELS_GROUPED_BY_CLASS,
80
80
  search: RULESET_MODELS_SEARCH,
81
81
  };
82
- const { nodeLoader, onItemsRendered } = presentation_components_1.usePresentationTreeNodeLoader({
82
+ const { nodeLoader, onItemsRendered } = (0, presentation_components_1.usePresentationTreeNodeLoader)({
83
83
  imodel: props.iModel,
84
84
  ruleset: rulesets.general,
85
85
  appendChildrenCountForGroupingNodes: (props.enableElementsClassGrouping === Common_1.ClassGroupingOption.YesWithCounts),
86
86
  pagingSize: PAGING_SIZE,
87
87
  enableHierarchyAutoUpdate: props.enableHierarchyAutoUpdate,
88
88
  });
89
- const { nodeLoader: searchNodeLoader, onItemsRendered: onSearchItemsRendered } = presentation_components_1.usePresentationTreeNodeLoader({
89
+ const { nodeLoader: searchNodeLoader, onItemsRendered: onSearchItemsRendered } = (0, presentation_components_1.usePresentationTreeNodeLoader)({
90
90
  imodel: props.iModel,
91
91
  ruleset: rulesets.search,
92
92
  pagingSize: PAGING_SIZE,
@@ -101,7 +101,7 @@ function useModelsTreeNodeLoader(props) {
101
101
  }
102
102
  function useVisibilityHandler(rulesetId, iModel, activeView, visibilityHandler, filteredDataProvider, hierarchyAutoUpdateEnabled) {
103
103
  const subjectModelIdsCache = React.useMemo(() => new ModelsVisibilityHandler_1.SubjectModelIdsCache(iModel), [iModel]);
104
- const defaultVisibilityHandler = core_react_1.useOptionalDisposable(React.useCallback(() => {
104
+ const defaultVisibilityHandler = (0, core_react_1.useOptionalDisposable)(React.useCallback(() => {
105
105
  if (activeView)
106
106
  return createVisibilityHandler(rulesetId, activeView, subjectModelIdsCache, hierarchyAutoUpdateEnabled);
107
107
  return undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"ModelsTree.js","sourceRoot":"","sources":["../../../../../src/components/trees/models-tree/ModelsTree.tsx"],"names":[],"mappings":";AAAA;;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C;AAC5H,CAAC,CAAC;AAEF,MAAM,sBAAsB,GAAG,CAAC,YAAmF,EAAyD,EAAE;IAC5K,MAAM,gBAAgB,GAAG,YAAqD,CAAC;IAC/E,OAAO,gBAAgB,CAAC,iBAAiB,KAAK,SAAS,IAAI,gBAAgB,CAAC,cAAc,KAAK,SAAS,IAAI,gBAAgB,CAAC,qBAAqB,KAAK,SAAS,CAAC;AACnK,CAAC,CAAC;AAEF,MAAM,uBAAuB,GAAG,CAAC,YAAmF,EAAqD,EAAE;IACzK,OAAO,sBAAsB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC;AACzE,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport \"./ModelsTree.scss\";\nimport * as React from \"react\";\nimport { ControlledTree, SelectionMode, useTreeModel } from \"@itwin/components-react\";\nimport { useDisposable, useOptionalDisposable } from \"@itwin/core-react\";\nimport { usePresentationTreeNodeLoader } from \"@itwin/presentation-components\";\nimport { TreeWidget } from \"../../../TreeWidget\";\nimport { ClassGroupingOption } from \"../Common\";\nimport { VisibilityTreeEventHandler } from \"../VisibilityTreeEventHandler\";\nimport { useVisibilityTreeFiltering, useVisibilityTreeRenderer, VisibilityTreeNoFilteredData } from \"../VisibilityTreeRenderer\";\nimport { ModelsVisibilityHandler, SubjectModelIdsCache } from \"./ModelsVisibilityHandler\";\n\nimport type { VisibilityTreeFilterInfo } from \"../Common\";\nimport type { ModelsTreeSelectionPredicate } from \"./ModelsVisibilityHandler\";\nimport type { TreeNodeItem } from \"@itwin/components-react\";\nimport type { IModelConnection, Viewport } from \"@itwin/core-frontend\";\nimport type { NodeKey, Ruleset } from \"@itwin/presentation-common\";\nimport type { IFilteredPresentationTreeDataProvider, IPresentationTreeDataProvider } from \"@itwin/presentation-components\";\n\nconst PAGING_SIZE = 20;\n\n/** @internal */\nexport const RULESET_MODELS: Ruleset = require(\"./Hierarchy.json\"); // eslint-disable-line @typescript-eslint/no-var-requires\n/** @internal */\nexport const RULESET_MODELS_GROUPED_BY_CLASS: Ruleset = require(\"./Hierarchy.GroupedByClass.json\"); // eslint-disable-line @typescript-eslint/no-var-requires\n\nconst RULESET_MODELS_SEARCH: Ruleset = require(\"./ModelsTreeSearch.json\"); // eslint-disable-line @typescript-eslint/no-var-requires\n\n/** Props for [[ModelsTree]] component\n * @public\n */\nexport interface ModelsTreeProps {\n /**\n * An IModel to pull data from\n */\n iModel: IModelConnection;\n /** Width of the component */\n width: number;\n /** Height of the component */\n height: number;\n /**\n * Selection mode in the tree\n */\n selectionMode?: SelectionMode;\n /**\n * Predicate which indicates whether node can be selected or no\n * @alpha\n */\n selectionPredicate?: ModelsTreeSelectionPredicate;\n /**\n * Active view used to determine and control visibility\n */\n activeView?: Viewport;\n /**\n * Ref to the root HTML element used by this component\n */\n rootElementRef?: React.Ref<HTMLDivElement>;\n /**\n * Information for tree filtering.\n * @alpha\n */\n filterInfo?: VisibilityTreeFilterInfo;\n /**\n * Callback invoked when tree is filtered.\n */\n onFilterApplied?: (filteredDataProvider: IPresentationTreeDataProvider, matchesCount: number) => void;\n /**\n * Should the tree group displayed element nodes by class.\n * @beta\n */\n enableElementsClassGrouping?: ClassGroupingOption;\n /**\n * Auto-update the hierarchy when data in the iModel changes.\n * @alpha\n */\n enableHierarchyAutoUpdate?: boolean;\n /**\n * Custom visibility handler.\n * @alpha\n */\n modelsVisibilityHandler?: ModelsVisibilityHandler;\n}\n\n/**\n * A tree component that shows a subject - model - category - element\n * hierarchy along with checkboxes that represent and allow changing\n * the display of those instances.\n * @public\n */\nexport function ModelsTree(props: ModelsTreeProps) {\n const { nodeLoader, onItemsRendered } = useModelsTreeNodeLoader(props);\n const { filteredNodeLoader, isFiltering, nodeHighlightingProps } = useVisibilityTreeFiltering(nodeLoader, props.filterInfo, props.onFilterApplied);\n const filterApplied = filteredNodeLoader !== nodeLoader;\n\n const { activeView, modelsVisibilityHandler, selectionPredicate } = props;\n const nodeSelectionPredicate = React.useCallback((key: NodeKey, node: TreeNodeItem) => {\n return !selectionPredicate ? true : selectionPredicate(key, ModelsVisibilityHandler.getNodeType(node, nodeLoader.dataProvider));\n }, [selectionPredicate, nodeLoader.dataProvider]);\n\n const visibilityHandler = useVisibilityHandler(\n nodeLoader.dataProvider.rulesetId,\n props.iModel,\n activeView,\n modelsVisibilityHandler,\n getFilteredDataProvider(filteredNodeLoader.dataProvider),\n props.enableHierarchyAutoUpdate);\n const eventHandler = useDisposable(React.useCallback(() => new VisibilityTreeEventHandler({\n nodeLoader: filteredNodeLoader,\n visibilityHandler,\n collapsedChildrenDisposalEnabled: true,\n selectionPredicate: nodeSelectionPredicate,\n }), [filteredNodeLoader, visibilityHandler, nodeSelectionPredicate]));\n\n const treeModel = useTreeModel(filteredNodeLoader.modelSource);\n const treeRenderer = useVisibilityTreeRenderer(true, false);\n\n const overlay = isFiltering ? <div className=\"filteredTreeOverlay\" /> : undefined;\n\n // istanbul ignore next\n const noFilteredDataRenderer = React.useCallback(() => {\n return <VisibilityTreeNoFilteredData\n title={TreeWidget.translate(\"modelTree.noModelFound\")}\n message={TreeWidget.translate(\"modelTree.noMatchingModelNames\")}\n />;\n }, []);\n\n return (\n <div className=\"tree-widget-models-tree\" ref={props.rootElementRef}>\n <ControlledTree\n nodeLoader={filteredNodeLoader}\n model={treeModel}\n selectionMode={props.selectionMode || SelectionMode.None}\n eventsHandler={eventHandler}\n treeRenderer={treeRenderer}\n nodeHighlightingProps={nodeHighlightingProps}\n noDataRenderer={filterApplied ? noFilteredDataRenderer : undefined}\n onItemsRendered={onItemsRendered}\n width={props.width}\n height={props.height}\n />\n {overlay}\n </div>\n );\n}\n\nfunction useModelsTreeNodeLoader(props: ModelsTreeProps) {\n const rulesets = {\n general: (!props.enableElementsClassGrouping) ? RULESET_MODELS : /* istanbul ignore next */ RULESET_MODELS_GROUPED_BY_CLASS,\n search: RULESET_MODELS_SEARCH,\n };\n\n const { nodeLoader, onItemsRendered } = usePresentationTreeNodeLoader({\n imodel: props.iModel,\n ruleset: rulesets.general,\n appendChildrenCountForGroupingNodes: (props.enableElementsClassGrouping === ClassGroupingOption.YesWithCounts),\n pagingSize: PAGING_SIZE,\n enableHierarchyAutoUpdate: props.enableHierarchyAutoUpdate,\n });\n const { nodeLoader: searchNodeLoader, onItemsRendered: onSearchItemsRendered } = usePresentationTreeNodeLoader({\n imodel: props.iModel,\n ruleset: rulesets.search,\n pagingSize: PAGING_SIZE,\n enableHierarchyAutoUpdate: props.enableHierarchyAutoUpdate,\n });\n\n const activeNodeLoader = props.filterInfo?.filter ? searchNodeLoader : nodeLoader;\n const activeItemsRenderedCallback = props.filterInfo?.filter ? onSearchItemsRendered : onItemsRendered;\n\n return {\n nodeLoader: activeNodeLoader,\n onItemsRendered: activeItemsRenderedCallback,\n };\n}\n\nfunction useVisibilityHandler(\n rulesetId: string,\n iModel: IModelConnection,\n activeView?: Viewport,\n visibilityHandler?: ModelsVisibilityHandler,\n filteredDataProvider?: IFilteredPresentationTreeDataProvider,\n hierarchyAutoUpdateEnabled?: boolean,\n) {\n const subjectModelIdsCache = React.useMemo(() => new SubjectModelIdsCache(iModel), [iModel]);\n const defaultVisibilityHandler = useOptionalDisposable(React.useCallback(() => {\n if (activeView)\n return createVisibilityHandler(rulesetId, activeView, subjectModelIdsCache, hierarchyAutoUpdateEnabled);\n return undefined;\n }, [rulesetId, activeView, subjectModelIdsCache, hierarchyAutoUpdateEnabled]));\n\n const handler = visibilityHandler ?? defaultVisibilityHandler;\n\n React.useEffect(() => {\n handler && handler.setFilteredDataProvider(filteredDataProvider);\n }, [handler, filteredDataProvider]);\n\n return handler;\n}\n\nconst createVisibilityHandler = (rulesetId: string, activeView: Viewport, subjectModelIdsCache: SubjectModelIdsCache, hierarchyAutoUpdateEnabled?: boolean): ModelsVisibilityHandler | undefined => {\n // istanbul ignore next\n return new ModelsVisibilityHandler({ rulesetId, viewport: activeView, hierarchyAutoUpdateEnabled, subjectModelIdsCache });\n};\n\nconst isFilteredDataProvider = (dataProvider: IPresentationTreeDataProvider | IFilteredPresentationTreeDataProvider): dataProvider is IFilteredPresentationTreeDataProvider => {\n const filteredProvider = dataProvider as IFilteredPresentationTreeDataProvider;\n return filteredProvider.nodeMatchesFilter !== undefined && filteredProvider.getActiveMatch !== undefined && filteredProvider.countFilteringResults !== undefined;\n};\n\nconst getFilteredDataProvider = (dataProvider: IPresentationTreeDataProvider | IFilteredPresentationTreeDataProvider): IFilteredPresentationTreeDataProvider | undefined => {\n return isFilteredDataProvider(dataProvider) ? dataProvider : undefined;\n};\n"]}
1
+ {"version":3,"file":"ModelsTree.js","sourceRoot":"","sources":["../../../../../src/components/trees/models-tree/ModelsTree.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;;;;;;;;;;;;;;;;;;;;;;AAE/F,6BAA2B;AAC3B,6CAA+B;AAC/B,8DAAoG;AAEpG,kDAAyE;AAEzE,4EAAqJ;AACrJ,oDAAiD;AACjD,sCAA0E;AAC1E,8EAA2E;AAC3E,sEAAgI;AAChI,uEAAwH;AAExH,MAAM,WAAW,GAAG,EAAE,CAAC;AAEvB,gBAAgB;AACH,QAAA,cAAc,GAAY,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,yDAAyD;AAC7H,gBAAgB;AACH,QAAA,+BAA+B,GAAY,OAAO,CAAC,iCAAiC,CAAC,CAAC,CAAC,yDAAyD;AAE7J,MAAM,qBAAqB,GAAY,OAAO,CAAC,yBAAyB,CAAC,CAAC,CAAC,yDAAyD;AAyDpI;;;;;GAKG;AACH,SAAgB,UAAU,CAAC,KAAsB;IAC/C,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAC;IACvE,MAAM,EAAE,kBAAkB,EAAE,WAAW,EAAE,qBAAqB,EAAE,GAAG,IAAA,mDA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AE,CAAC,SAAS,EAAE,UAAU,EAAE,oBAAoB,EAAE,0BAA0B,CAAC,CAAC,CAAC,CAAC;IAE/E,MAAM,OAAO,GAAG,iBAAiB,aAAjB,iBAAiB,cAAjB,iBAAiB,GAAI,wBAAwB,CAAC;IAE9D,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,OAAO,IAAI,OAAO,CAAC,uBAAuB,CAAC,oBAAoB,CAAC,CAAC;IACnE,CAAC,EAAE,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC;IAEpC,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,uBAAuB,GAAG,CAAC,SAAiB,EAAE,UAAoB,EAAE,oBAA0C,EAAE,0BAAoC,EAAuC,EAAE;IACjM,uBAAuB;IACvB,OAAO,IAAI,iDAAuB,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,0BAA0B,EAAE,oBAAoB,EAAE,CAAC,CAAC;AAC5H,CAAC,CAAC;AAEF,MAAM,sBAAsB,GAAG,CAAC,YAAmF,EAAyD,EAAE;IAC5K,MAAM,gBAAgB,GAAG,YAAqD,CAAC;IAC/E,OAAO,gBAAgB,CAAC,iBAAiB,KAAK,SAAS,IAAI,gBAAgB,CAAC,cAAc,KAAK,SAAS,IAAI,gBAAgB,CAAC,qBAAqB,KAAK,SAAS,CAAC;AACnK,CAAC,CAAC;AAEF,MAAM,uBAAuB,GAAG,CAAC,YAAmF,EAAqD,EAAE;IACzK,OAAO,sBAAsB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,CAAC;AACzE,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport \"./ModelsTree.scss\";\nimport * as React from \"react\";\nimport { ControlledTree, SelectionMode, TreeNodeItem, useTreeModel } from \"@itwin/components-react\";\nimport { IModelConnection, Viewport } from \"@itwin/core-frontend\";\nimport { useDisposable, useOptionalDisposable } from \"@itwin/core-react\";\nimport { NodeKey, Ruleset } from \"@itwin/presentation-common\";\nimport { IFilteredPresentationTreeDataProvider, IPresentationTreeDataProvider, usePresentationTreeNodeLoader } from \"@itwin/presentation-components\";\nimport { TreeWidget } from \"../../../TreeWidget\";\nimport { ClassGroupingOption, VisibilityTreeFilterInfo } from \"../Common\";\nimport { VisibilityTreeEventHandler } from \"../VisibilityTreeEventHandler\";\nimport { useVisibilityTreeFiltering, useVisibilityTreeRenderer, VisibilityTreeNoFilteredData } from \"../VisibilityTreeRenderer\";\nimport { ModelsTreeSelectionPredicate, ModelsVisibilityHandler, SubjectModelIdsCache } from \"./ModelsVisibilityHandler\";\n\nconst PAGING_SIZE = 20;\n\n/** @internal */\nexport const RULESET_MODELS: Ruleset = require(\"./Hierarchy.json\"); // eslint-disable-line @typescript-eslint/no-var-requires\n/** @internal */\nexport const RULESET_MODELS_GROUPED_BY_CLASS: Ruleset = require(\"./Hierarchy.GroupedByClass.json\"); // eslint-disable-line @typescript-eslint/no-var-requires\n\nconst RULESET_MODELS_SEARCH: Ruleset = require(\"./ModelsTreeSearch.json\"); // eslint-disable-line @typescript-eslint/no-var-requires\n\n/** Props for [[ModelsTree]] component\n * @public\n */\nexport interface ModelsTreeProps {\n /**\n * An IModel to pull data from\n */\n iModel: IModelConnection;\n /** Width of the component */\n width: number;\n /** Height of the component */\n height: number;\n /**\n * Selection mode in the tree\n */\n selectionMode?: SelectionMode;\n /**\n * Predicate which indicates whether node can be selected or no\n * @alpha\n */\n selectionPredicate?: ModelsTreeSelectionPredicate;\n /**\n * Active view used to determine and control visibility\n */\n activeView?: Viewport;\n /**\n * Ref to the root HTML element used by this component\n */\n rootElementRef?: React.Ref<HTMLDivElement>;\n /**\n * Information for tree filtering.\n * @alpha\n */\n filterInfo?: VisibilityTreeFilterInfo;\n /**\n * Callback invoked when tree is filtered.\n */\n onFilterApplied?: (filteredDataProvider: IPresentationTreeDataProvider, matchesCount: number) => void;\n /**\n * Should the tree group displayed element nodes by class.\n * @beta\n */\n enableElementsClassGrouping?: ClassGroupingOption;\n /**\n * Auto-update the hierarchy when data in the iModel changes.\n * @alpha\n */\n enableHierarchyAutoUpdate?: boolean;\n /**\n * Custom visibility handler.\n * @alpha\n */\n modelsVisibilityHandler?: ModelsVisibilityHandler;\n}\n\n/**\n * A tree component that shows a subject - model - category - element\n * hierarchy along with checkboxes that represent and allow changing\n * the display of those instances.\n * @public\n */\nexport function ModelsTree(props: ModelsTreeProps) {\n const { nodeLoader, onItemsRendered } = useModelsTreeNodeLoader(props);\n const { filteredNodeLoader, isFiltering, nodeHighlightingProps } = useVisibilityTreeFiltering(nodeLoader, props.filterInfo, props.onFilterApplied);\n const filterApplied = filteredNodeLoader !== nodeLoader;\n\n const { activeView, modelsVisibilityHandler, selectionPredicate } = props;\n const nodeSelectionPredicate = React.useCallback((key: NodeKey, node: TreeNodeItem) => {\n return !selectionPredicate ? true : selectionPredicate(key, ModelsVisibilityHandler.getNodeType(node, nodeLoader.dataProvider));\n }, [selectionPredicate, nodeLoader.dataProvider]);\n\n const visibilityHandler = useVisibilityHandler(\n nodeLoader.dataProvider.rulesetId,\n props.iModel,\n activeView,\n modelsVisibilityHandler,\n getFilteredDataProvider(filteredNodeLoader.dataProvider),\n props.enableHierarchyAutoUpdate);\n const eventHandler = useDisposable(React.useCallback(() => new VisibilityTreeEventHandler({\n nodeLoader: filteredNodeLoader,\n visibilityHandler,\n collapsedChildrenDisposalEnabled: true,\n selectionPredicate: nodeSelectionPredicate,\n }), [filteredNodeLoader, visibilityHandler, nodeSelectionPredicate]));\n\n const treeModel = useTreeModel(filteredNodeLoader.modelSource);\n const treeRenderer = useVisibilityTreeRenderer(true, false);\n\n const overlay = isFiltering ? <div className=\"filteredTreeOverlay\" /> : undefined;\n\n // istanbul ignore next\n const noFilteredDataRenderer = React.useCallback(() => {\n return <VisibilityTreeNoFilteredData\n title={TreeWidget.translate(\"modelTree.noModelFound\")}\n message={TreeWidget.translate(\"modelTree.noMatchingModelNames\")}\n />;\n }, []);\n\n return (\n <div className=\"tree-widget-models-tree\" ref={props.rootElementRef}>\n <ControlledTree\n nodeLoader={filteredNodeLoader}\n model={treeModel}\n selectionMode={props.selectionMode || SelectionMode.None}\n eventsHandler={eventHandler}\n treeRenderer={treeRenderer}\n nodeHighlightingProps={nodeHighlightingProps}\n noDataRenderer={filterApplied ? noFilteredDataRenderer : undefined}\n onItemsRendered={onItemsRendered}\n width={props.width}\n height={props.height}\n />\n {overlay}\n </div>\n );\n}\n\nfunction useModelsTreeNodeLoader(props: ModelsTreeProps) {\n const rulesets = {\n general: (!props.enableElementsClassGrouping) ? RULESET_MODELS : /* istanbul ignore next */ RULESET_MODELS_GROUPED_BY_CLASS,\n search: RULESET_MODELS_SEARCH,\n };\n\n const { nodeLoader, onItemsRendered } = usePresentationTreeNodeLoader({\n imodel: props.iModel,\n ruleset: rulesets.general,\n appendChildrenCountForGroupingNodes: (props.enableElementsClassGrouping === ClassGroupingOption.YesWithCounts),\n pagingSize: PAGING_SIZE,\n enableHierarchyAutoUpdate: props.enableHierarchyAutoUpdate,\n });\n const { nodeLoader: searchNodeLoader, onItemsRendered: onSearchItemsRendered } = usePresentationTreeNodeLoader({\n imodel: props.iModel,\n ruleset: rulesets.search,\n pagingSize: PAGING_SIZE,\n enableHierarchyAutoUpdate: props.enableHierarchyAutoUpdate,\n });\n\n const activeNodeLoader = props.filterInfo?.filter ? searchNodeLoader : nodeLoader;\n const activeItemsRenderedCallback = props.filterInfo?.filter ? onSearchItemsRendered : onItemsRendered;\n\n return {\n nodeLoader: activeNodeLoader,\n onItemsRendered: activeItemsRenderedCallback,\n };\n}\n\nfunction useVisibilityHandler(\n rulesetId: string,\n iModel: IModelConnection,\n activeView?: Viewport,\n visibilityHandler?: ModelsVisibilityHandler,\n filteredDataProvider?: IFilteredPresentationTreeDataProvider,\n hierarchyAutoUpdateEnabled?: boolean,\n) {\n const subjectModelIdsCache = React.useMemo(() => new SubjectModelIdsCache(iModel), [iModel]);\n const defaultVisibilityHandler = useOptionalDisposable(React.useCallback(() => {\n if (activeView)\n return createVisibilityHandler(rulesetId, activeView, subjectModelIdsCache, hierarchyAutoUpdateEnabled);\n return undefined;\n }, [rulesetId, activeView, subjectModelIdsCache, hierarchyAutoUpdateEnabled]));\n\n const handler = visibilityHandler ?? defaultVisibilityHandler;\n\n React.useEffect(() => {\n handler && handler.setFilteredDataProvider(filteredDataProvider);\n }, [handler, filteredDataProvider]);\n\n return handler;\n}\n\nconst createVisibilityHandler = (rulesetId: string, activeView: Viewport, subjectModelIdsCache: SubjectModelIdsCache, hierarchyAutoUpdateEnabled?: boolean): ModelsVisibilityHandler | undefined => {\n // istanbul ignore next\n return new ModelsVisibilityHandler({ rulesetId, viewport: activeView, hierarchyAutoUpdateEnabled, subjectModelIdsCache });\n};\n\nconst isFilteredDataProvider = (dataProvider: IPresentationTreeDataProvider | IFilteredPresentationTreeDataProvider): dataProvider is IFilteredPresentationTreeDataProvider => {\n const filteredProvider = dataProvider as IFilteredPresentationTreeDataProvider;\n return filteredProvider.nodeMatchesFilter !== undefined && filteredProvider.getActiveMatch !== undefined && filteredProvider.countFilteringResults !== undefined;\n};\n\nconst getFilteredDataProvider = (dataProvider: IPresentationTreeDataProvider | IFilteredPresentationTreeDataProvider): IFilteredPresentationTreeDataProvider | undefined => {\n return isFilteredDataProvider(dataProvider) ? dataProvider : undefined;\n};\n"]}
@@ -1,5 +1,22 @@
1
1
  /// <reference types="react" />
2
2
  import "./ModelsTree.scss";
3
- import type { ModelTreeProps } from "../../../types";
4
- export declare const ModelsTreeComponent: (props: ModelTreeProps) => JSX.Element;
3
+ import { ModelsTreeHeaderButtonProps, ModelTreeProps } from "../../../types";
4
+ export interface ModelInfo {
5
+ id: string;
6
+ isPlanProjection?: boolean;
7
+ }
8
+ export declare const ModelsTreeComponent: {
9
+ (props: ModelTreeProps): JSX.Element | null;
10
+ ShowAllButton: typeof ShowAllButton;
11
+ HideAllButton: typeof HideAllButton;
12
+ InvertButton: typeof InvertButton;
13
+ View2DButton: typeof View2DButton;
14
+ View3DButton: typeof View3DButton;
15
+ };
16
+ declare function ShowAllButton(props: ModelsTreeHeaderButtonProps): JSX.Element;
17
+ declare function HideAllButton(props: ModelsTreeHeaderButtonProps): JSX.Element;
18
+ declare function InvertButton(props: ModelsTreeHeaderButtonProps): JSX.Element;
19
+ declare function View2DButton(props: ModelsTreeHeaderButtonProps): JSX.Element;
20
+ declare function View3DButton(props: ModelsTreeHeaderButtonProps): JSX.Element;
21
+ export {};
5
22
  //# sourceMappingURL=ModelsTreeComponent.d.ts.map