@itwin/tree-widget-react 0.10.0 → 1.0.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +331 -0
- package/README.md +146 -29
- package/lib/cjs/TreeWidget.d.ts +0 -1
- package/lib/cjs/TreeWidget.js +1 -6
- package/lib/cjs/TreeWidget.js.map +1 -1
- package/lib/cjs/components/TreeFilteringState.d.ts +3 -1
- package/lib/cjs/components/TreeFilteringState.js +19 -40
- package/lib/cjs/components/TreeFilteringState.js.map +1 -1
- package/lib/cjs/components/TreeWidgetComponent.d.ts +29 -5
- package/lib/cjs/components/TreeWidgetComponent.js +85 -29
- package/lib/cjs/components/TreeWidgetComponent.js.map +1 -1
- package/lib/cjs/components/TreeWidgetComponent.scss +4 -24
- package/lib/cjs/components/TreeWidgetUiItemsProvider.d.ts +25 -2
- package/lib/cjs/components/TreeWidgetUiItemsProvider.js +31 -46
- package/lib/cjs/components/TreeWidgetUiItemsProvider.js.map +1 -1
- package/lib/cjs/components/tree-header/TreeHeader.d.ts +26 -0
- package/lib/cjs/components/tree-header/TreeHeader.js +43 -0
- package/lib/cjs/components/tree-header/TreeHeader.js.map +1 -0
- package/lib/cjs/components/tree-header/TreeHeader.scss +69 -0
- package/lib/cjs/components/trees/CategoriesVisibilityUtils.d.ts +12 -6
- package/lib/cjs/components/trees/CategoriesVisibilityUtils.js +10 -4
- package/lib/cjs/components/trees/CategoriesVisibilityUtils.js.map +1 -1
- package/lib/cjs/components/trees/Common.d.ts +2 -2
- package/lib/cjs/components/trees/Common.js +1 -1
- package/lib/cjs/components/trees/Common.js.map +1 -1
- package/lib/cjs/components/trees/VisibilityTreeBase.scss +66 -10
- package/lib/cjs/components/trees/VisibilityTreeEventHandler.d.ts +13 -12
- package/lib/cjs/components/trees/VisibilityTreeEventHandler.js +6 -17
- package/lib/cjs/components/trees/VisibilityTreeEventHandler.js.map +1 -1
- package/lib/cjs/components/trees/VisibilityTreeRenderer.d.ts +38 -14
- package/lib/cjs/components/trees/VisibilityTreeRenderer.js +35 -41
- package/lib/cjs/components/trees/VisibilityTreeRenderer.js.map +1 -1
- package/lib/cjs/components/trees/category-tree/CategoriesTree.d.ts +12 -11
- package/lib/cjs/components/trees/category-tree/CategoriesTree.js +17 -41
- package/lib/cjs/components/trees/category-tree/CategoriesTree.js.map +1 -1
- package/lib/cjs/components/trees/category-tree/CategoriesTreeComponent.d.ts +67 -6
- package/lib/cjs/components/trees/category-tree/CategoriesTreeComponent.js +61 -72
- package/lib/cjs/components/trees/category-tree/CategoriesTreeComponent.js.map +1 -1
- package/lib/cjs/components/trees/category-tree/CategoryVisibilityHandler.d.ts +30 -8
- package/lib/cjs/components/trees/category-tree/CategoryVisibilityHandler.js +61 -34
- package/lib/cjs/components/trees/category-tree/CategoryVisibilityHandler.js.map +1 -1
- package/lib/cjs/components/trees/external-sources-tree/ExternalSources.json +230 -0
- package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTree.d.ts +27 -0
- package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTree.js +61 -0
- package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTree.js.map +1 -0
- package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTreeComponent.d.ts +20 -0
- package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js +39 -0
- package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js.map +1 -0
- package/lib/cjs/components/trees/imodel-content-tree/IModelContentTree.d.ts +30 -0
- package/lib/cjs/components/trees/imodel-content-tree/IModelContentTree.js +39 -0
- package/lib/cjs/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -0
- package/lib/cjs/components/trees/imodel-content-tree/IModelContentTreeComponent.d.ts +26 -0
- package/lib/cjs/components/trees/imodel-content-tree/IModelContentTreeComponent.js +35 -0
- package/lib/cjs/components/trees/imodel-content-tree/IModelContentTreeComponent.js.map +1 -0
- package/lib/cjs/components/trees/index.d.ts +5 -1
- package/lib/cjs/components/trees/index.js +10 -2
- package/lib/cjs/components/trees/index.js.map +1 -1
- package/lib/cjs/components/trees/models-tree/ModelsTree.d.ts +26 -18
- package/lib/cjs/components/trees/models-tree/ModelsTree.js +22 -50
- package/lib/cjs/components/trees/models-tree/ModelsTree.js.map +1 -1
- package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.d.ts +70 -2
- package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.js +68 -105
- package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
- package/lib/cjs/components/trees/models-tree/ModelsVisibilityHandler.d.ts +40 -12
- package/lib/cjs/components/trees/models-tree/ModelsVisibilityHandler.js +65 -5
- package/lib/cjs/components/trees/models-tree/ModelsVisibilityHandler.js.map +1 -1
- package/lib/cjs/components/trees/models-tree/Utils.d.ts +12 -0
- package/lib/cjs/components/trees/models-tree/Utils.js +625 -1
- package/lib/cjs/components/trees/models-tree/Utils.js.map +1 -1
- package/lib/cjs/components/utils/AutoSizer.d.ts +6 -3
- package/lib/cjs/components/utils/AutoSizer.js +9 -29
- package/lib/cjs/components/utils/AutoSizer.js.map +1 -1
- package/lib/cjs/components/utils/IsPromiseLike.d.ts +4 -1
- package/lib/cjs/components/utils/IsPromiseLike.js +6 -3
- package/lib/cjs/components/utils/IsPromiseLike.js.map +1 -1
- package/lib/cjs/tree-widget-react.d.ts +0 -1
- package/lib/cjs/tree-widget-react.js +5 -2
- package/lib/cjs/tree-widget-react.js.map +1 -1
- package/lib/esm/TreeWidget.d.ts +0 -1
- package/lib/esm/TreeWidget.js +2 -7
- package/lib/esm/TreeWidget.js.map +1 -1
- package/lib/esm/components/TreeFilteringState.d.ts +3 -1
- package/lib/esm/components/TreeFilteringState.js +17 -19
- package/lib/esm/components/TreeFilteringState.js.map +1 -1
- package/lib/esm/components/TreeWidgetComponent.d.ts +29 -5
- package/lib/esm/components/TreeWidgetComponent.js +82 -7
- package/lib/esm/components/TreeWidgetComponent.js.map +1 -1
- package/lib/esm/components/TreeWidgetComponent.scss +4 -24
- package/lib/esm/components/TreeWidgetUiItemsProvider.d.ts +25 -2
- package/lib/esm/components/TreeWidgetUiItemsProvider.js +29 -41
- package/lib/esm/components/TreeWidgetUiItemsProvider.js.map +1 -1
- package/lib/esm/components/tree-header/TreeHeader.d.ts +26 -0
- package/lib/esm/components/tree-header/TreeHeader.js +36 -0
- package/lib/esm/components/tree-header/TreeHeader.js.map +1 -0
- package/lib/esm/components/tree-header/TreeHeader.scss +69 -0
- package/lib/esm/components/trees/CategoriesVisibilityUtils.d.ts +12 -6
- package/lib/esm/components/trees/CategoriesVisibilityUtils.js +10 -4
- package/lib/esm/components/trees/CategoriesVisibilityUtils.js.map +1 -1
- package/lib/esm/components/trees/Common.d.ts +2 -2
- package/lib/esm/components/trees/Common.js +1 -1
- package/lib/esm/components/trees/Common.js.map +1 -1
- package/lib/esm/components/trees/VisibilityTreeBase.scss +66 -10
- package/lib/esm/components/trees/VisibilityTreeEventHandler.d.ts +13 -12
- package/lib/esm/components/trees/VisibilityTreeEventHandler.js +6 -17
- package/lib/esm/components/trees/VisibilityTreeEventHandler.js.map +1 -1
- package/lib/esm/components/trees/VisibilityTreeRenderer.d.ts +38 -14
- package/lib/esm/components/trees/VisibilityTreeRenderer.js +29 -19
- package/lib/esm/components/trees/VisibilityTreeRenderer.js.map +1 -1
- package/lib/esm/components/trees/category-tree/CategoriesTree.d.ts +12 -11
- package/lib/esm/components/trees/category-tree/CategoriesTree.js +16 -21
- package/lib/esm/components/trees/category-tree/CategoriesTree.js.map +1 -1
- package/lib/esm/components/trees/category-tree/CategoriesTreeComponent.d.ts +67 -6
- package/lib/esm/components/trees/category-tree/CategoriesTreeComponent.js +60 -52
- package/lib/esm/components/trees/category-tree/CategoriesTreeComponent.js.map +1 -1
- package/lib/esm/components/trees/category-tree/CategoryVisibilityHandler.d.ts +30 -8
- package/lib/esm/components/trees/category-tree/CategoryVisibilityHandler.js +57 -14
- package/lib/esm/components/trees/category-tree/CategoryVisibilityHandler.js.map +1 -1
- package/lib/esm/components/trees/external-sources-tree/ExternalSources.json +230 -0
- package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTree.d.ts +27 -0
- package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTree.js +34 -0
- package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTree.js.map +1 -0
- package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTreeComponent.d.ts +20 -0
- package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js +35 -0
- package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js.map +1 -0
- package/lib/esm/components/trees/imodel-content-tree/IModelContentTree.d.ts +30 -0
- package/lib/esm/components/trees/imodel-content-tree/IModelContentTree.js +32 -0
- package/lib/esm/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -0
- package/lib/esm/components/trees/imodel-content-tree/IModelContentTreeComponent.d.ts +26 -0
- package/lib/esm/components/trees/imodel-content-tree/IModelContentTreeComponent.js +31 -0
- package/lib/esm/components/trees/imodel-content-tree/IModelContentTreeComponent.js.map +1 -0
- package/lib/esm/components/trees/index.d.ts +5 -1
- package/lib/esm/components/trees/index.js +5 -1
- package/lib/esm/components/trees/index.js.map +1 -1
- package/lib/esm/components/trees/models-tree/ModelsTree.d.ts +26 -18
- package/lib/esm/components/trees/models-tree/ModelsTree.js +23 -32
- package/lib/esm/components/trees/models-tree/ModelsTree.js.map +1 -1
- package/lib/esm/components/trees/models-tree/ModelsTreeComponent.d.ts +70 -2
- package/lib/esm/components/trees/models-tree/ModelsTreeComponent.js +66 -84
- package/lib/esm/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
- package/lib/esm/components/trees/models-tree/ModelsVisibilityHandler.d.ts +40 -12
- package/lib/esm/components/trees/models-tree/ModelsVisibilityHandler.js +60 -5
- package/lib/esm/components/trees/models-tree/ModelsVisibilityHandler.js.map +1 -1
- package/lib/esm/components/trees/models-tree/Utils.d.ts +12 -0
- package/lib/esm/components/trees/models-tree/Utils.js +622 -0
- package/lib/esm/components/trees/models-tree/Utils.js.map +1 -1
- package/lib/esm/components/utils/AutoSizer.d.ts +6 -3
- package/lib/esm/components/utils/AutoSizer.js +9 -10
- package/lib/esm/components/utils/AutoSizer.js.map +1 -1
- package/lib/esm/components/utils/IsPromiseLike.d.ts +4 -1
- package/lib/esm/components/utils/IsPromiseLike.js +4 -1
- package/lib/esm/components/utils/IsPromiseLike.js.map +1 -1
- package/lib/esm/tree-widget-react.d.ts +0 -1
- package/lib/esm/tree-widget-react.js +0 -1
- package/lib/esm/tree-widget-react.js.map +1 -1
- package/lib/public/locales/en/TreeWidget.json +13 -4
- package/package.json +42 -47
- package/lib/cjs/components/rulesets/ClassificationSystems.json +0 -122
- package/lib/cjs/components/search-bar/SearchBar.d.ts +0 -48
- package/lib/cjs/components/search-bar/SearchBar.js +0 -86
- package/lib/cjs/components/search-bar/SearchBar.js.map +0 -1
- package/lib/cjs/components/search-bar/SearchBar.scss +0 -118
- package/lib/cjs/components/search-bar/SearchBox.d.ts +0 -70
- package/lib/cjs/components/search-bar/SearchBox.js +0 -186
- package/lib/cjs/components/search-bar/SearchBox.js.map +0 -1
- package/lib/cjs/components/search-bar/SearchBox.scss +0 -70
- package/lib/cjs/components/trees/IModelContentTree.d.ts +0 -4
- package/lib/cjs/components/trees/IModelContentTree.js +0 -50
- package/lib/cjs/components/trees/IModelContentTree.js.map +0 -1
- package/lib/cjs/components/trees/models-tree/Hierarchy.GroupedByClass.json +0 -391
- package/lib/cjs/components/trees/models-tree/Hierarchy.json +0 -386
- package/lib/cjs/components/trees/models-tree/ModelsTreeSearch.json +0 -239
- package/lib/cjs/types.d.ts +0 -44
- package/lib/cjs/types.js +0 -11
- package/lib/cjs/types.js.map +0 -1
- package/lib/esm/components/rulesets/ClassificationSystems.json +0 -122
- package/lib/esm/components/search-bar/SearchBar.d.ts +0 -48
- package/lib/esm/components/search-bar/SearchBar.js +0 -60
- package/lib/esm/components/search-bar/SearchBar.js.map +0 -1
- package/lib/esm/components/search-bar/SearchBar.scss +0 -118
- package/lib/esm/components/search-bar/SearchBox.d.ts +0 -70
- package/lib/esm/components/search-bar/SearchBox.js +0 -160
- package/lib/esm/components/search-bar/SearchBox.js.map +0 -1
- package/lib/esm/components/search-bar/SearchBox.scss +0 -70
- package/lib/esm/components/trees/IModelContentTree.d.ts +0 -4
- package/lib/esm/components/trees/IModelContentTree.js +0 -24
- package/lib/esm/components/trees/IModelContentTree.js.map +0 -1
- package/lib/esm/components/trees/models-tree/Hierarchy.GroupedByClass.json +0 -391
- package/lib/esm/components/trees/models-tree/Hierarchy.json +0 -386
- package/lib/esm/components/trees/models-tree/ModelsTreeSearch.json +0 -239
- package/lib/esm/types.d.ts +0 -44
- package/lib/esm/types.js +0 -8
- package/lib/esm/types.js.map +0 -1
- /package/lib/cjs/components/{rulesets → trees/imodel-content-tree}/IModelContent.json +0 -0
- /package/lib/esm/components/{rulesets → trees/imodel-content-tree}/IModelContent.json +0 -0
|
@@ -1,10 +1,71 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import "../VisibilityTreeBase.scss";
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
import type { TreeHeaderButtonProps } from "../../tree-header/TreeHeader";
|
|
4
|
+
import type { CategoryTreeProps } from "./CategoriesTree";
|
|
5
|
+
import type { CategoryInfo } from "./CategoryVisibilityHandler";
|
|
6
|
+
/**
|
|
7
|
+
* Props that get passed to [[CategoriesTreeComponent]] header button renderer.
|
|
8
|
+
* @see CategoriesTreeComponentProps.headerButtons
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export interface CategoriesTreeHeaderButtonProps extends TreeHeaderButtonProps {
|
|
12
|
+
/** A list of categories available in the iModel */
|
|
13
|
+
categories: CategoryInfo[];
|
|
14
|
+
/** In case the tree is filtered, a list of filtered categories. */
|
|
15
|
+
filteredCategories?: CategoryInfo[];
|
|
9
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Props for [[CategoriesTreeComponent]].
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export interface CategoriesTreeComponentProps extends Omit<CategoryTreeProps, "iModel" | "activeView" | "width" | "height" | "filterInfo" | "onFilterApplied" | "categories" | "categoryVisibilityHandler" | "viewManager"> {
|
|
22
|
+
/**
|
|
23
|
+
* Renderers of header buttons. Defaults to:
|
|
24
|
+
* ```ts
|
|
25
|
+
* [
|
|
26
|
+
* CategoriesTreeComponent.ShowAllButton,
|
|
27
|
+
* CategoriesTreeComponent.HideAllButton,
|
|
28
|
+
* CategoriesTreeComponent.InvertAllButton,
|
|
29
|
+
* ]
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
headerButtons?: Array<(props: CategoriesTreeHeaderButtonProps) => React.ReactNode>;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A component that renders [[CategoriesTree]] and a header with filtering capabilities
|
|
36
|
+
* and header buttons.
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
export declare const CategoriesTreeComponent: {
|
|
40
|
+
(props: CategoriesTreeComponentProps): JSX.Element | null;
|
|
41
|
+
/**
|
|
42
|
+
* Renders a "Show all" button that enables display of all categories and their subcategories.
|
|
43
|
+
* @public
|
|
44
|
+
*/
|
|
45
|
+
ShowAllButton: typeof ShowAllButton;
|
|
46
|
+
/**
|
|
47
|
+
* Renders a "Hide all" button that disables display of all categories.
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
HideAllButton: typeof HideAllButton;
|
|
51
|
+
/**
|
|
52
|
+
* Renders an "Invert all" button that inverts display of all categories.
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
55
|
+
InvertAllButton: typeof InvertAllButton;
|
|
56
|
+
/**
|
|
57
|
+
* Id of the component. May be used when a creating a [[TreeDefinition]] for [[TreeWidgetComponent]].
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
id: string;
|
|
61
|
+
/**
|
|
62
|
+
* Label of the component. May be used when a creating a [[TreeDefinition]] for [[TreeWidgetComponent]].
|
|
63
|
+
* @public
|
|
64
|
+
*/
|
|
65
|
+
getLabel(): string;
|
|
66
|
+
};
|
|
67
|
+
declare function ShowAllButton(props: CategoriesTreeHeaderButtonProps): JSX.Element;
|
|
68
|
+
declare function HideAllButton(props: CategoriesTreeHeaderButtonProps): JSX.Element;
|
|
69
|
+
declare function InvertAllButton(props: CategoriesTreeHeaderButtonProps): JSX.Element;
|
|
70
|
+
export {};
|
|
10
71
|
//# sourceMappingURL=CategoriesTreeComponent.d.ts.map
|
|
@@ -1,93 +1,101 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
2
|
/*---------------------------------------------------------------------------------------------
|
|
2
3
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
4
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
5
|
*--------------------------------------------------------------------------------------------*/
|
|
5
6
|
import "../VisibilityTreeBase.scss";
|
|
6
|
-
import
|
|
7
|
+
import { Fragment, useEffect, useState } from "react";
|
|
7
8
|
import { useActiveIModelConnection, useActiveViewport } from "@itwin/appui-react";
|
|
8
9
|
import { IModelApp } from "@itwin/core-frontend";
|
|
9
10
|
import { SvgVisibilityHalf, SvgVisibilityHide, SvgVisibilityShow } from "@itwin/itwinui-icons-react";
|
|
10
11
|
import { IconButton } from "@itwin/itwinui-react";
|
|
11
12
|
import { isPresentationTreeNodeItem } from "@itwin/presentation-components";
|
|
12
13
|
import { TreeWidget } from "../../../TreeWidget";
|
|
13
|
-
import {
|
|
14
|
+
import { TreeHeader } from "../../tree-header/TreeHeader";
|
|
14
15
|
import { useTreeFilteringState } from "../../TreeFilteringState";
|
|
15
16
|
import { AutoSizer } from "../../utils/AutoSizer";
|
|
16
|
-
import { enableCategory } from "../CategoriesVisibilityUtils";
|
|
17
17
|
import { CategoryTree } from "./CategoriesTree";
|
|
18
|
-
import { CategoryVisibilityHandler, useCategories } from "./CategoryVisibilityHandler";
|
|
19
|
-
|
|
18
|
+
import { CategoryVisibilityHandler, hideAllCategories, invertAllCategories, showAllCategories, useCategories } from "./CategoryVisibilityHandler";
|
|
19
|
+
/**
|
|
20
|
+
* A component that renders [[CategoriesTree]] and a header with filtering capabilities
|
|
21
|
+
* and header buttons.
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export const CategoriesTreeComponent = (props) => {
|
|
20
25
|
const iModel = useActiveIModelConnection();
|
|
21
26
|
const viewport = useActiveViewport();
|
|
22
27
|
if (!iModel || !viewport) {
|
|
23
28
|
return null;
|
|
24
29
|
}
|
|
25
|
-
return (
|
|
26
|
-
}
|
|
30
|
+
return (_jsx(CategoriesTreeComponentImpl, { ...props, iModel: iModel, viewport: viewport }));
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Renders a "Show all" button that enables display of all categories and their subcategories.
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
27
36
|
CategoriesTreeComponent.ShowAllButton = ShowAllButton;
|
|
37
|
+
/**
|
|
38
|
+
* Renders a "Hide all" button that disables display of all categories.
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
28
41
|
CategoriesTreeComponent.HideAllButton = HideAllButton;
|
|
29
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Renders an "Invert all" button that inverts display of all categories.
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
CategoriesTreeComponent.InvertAllButton = InvertAllButton;
|
|
47
|
+
/**
|
|
48
|
+
* Id of the component. May be used when a creating a [[TreeDefinition]] for [[TreeWidgetComponent]].
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
CategoriesTreeComponent.id = "categories-tree";
|
|
52
|
+
/**
|
|
53
|
+
* Label of the component. May be used when a creating a [[TreeDefinition]] for [[TreeWidgetComponent]].
|
|
54
|
+
* @public
|
|
55
|
+
*/
|
|
56
|
+
CategoriesTreeComponent.getLabel = () => TreeWidget.translate("categories");
|
|
30
57
|
function CategoriesTreeComponentImpl(props) {
|
|
31
58
|
const categories = useCategories(IModelApp.viewManager, props.iModel, props.viewport);
|
|
32
59
|
const [filteredCategories, setFilteredCategories] = useState();
|
|
33
|
-
const { searchOptions, filterString,
|
|
60
|
+
const { searchOptions, filterString, onFilterApplied, filteredProvider, } = useTreeFilteringState();
|
|
34
61
|
useEffect(() => {
|
|
35
62
|
(async () => {
|
|
36
63
|
if (filteredProvider)
|
|
37
|
-
setFilteredCategories((await getFilteredCategories(filteredProvider))
|
|
64
|
+
setFilteredCategories((await getFilteredCategories(filteredProvider)));
|
|
38
65
|
else
|
|
39
66
|
setFilteredCategories(undefined);
|
|
40
67
|
})();
|
|
41
68
|
}, [filteredProvider]);
|
|
42
|
-
return (
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
]),
|
|
50
|
-
React.createElement(AutoSizer, null, ({ width, height }) => (React.createElement(CategoryTree, { ...props, categories: categories, width: width, height: height, filterInfo: { filter: filterString, activeMatchIndex }, onFilterApplied: onFilterApplied })))));
|
|
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
|
|
70
|
+
? props.headerButtons.map((btn, index) => _jsx(Fragment, { children: btn({ viewport: props.viewport, categories, filteredCategories }) }, index))
|
|
71
|
+
: [
|
|
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 })) }) })] }));
|
|
51
76
|
}
|
|
52
77
|
async function getFilteredCategories(filteredProvider) {
|
|
78
|
+
const filteredCategories = [];
|
|
53
79
|
const nodes = await filteredProvider.getNodes();
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
80
|
+
for (const node of nodes) {
|
|
81
|
+
if (!isPresentationTreeNodeItem(node)) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const filteredCategoryId = CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(node.key);
|
|
85
|
+
const filteredSubCategoriesIds = node.hasChildren
|
|
86
|
+
? (await filteredProvider.getNodes(node)).filter(isPresentationTreeNodeItem).map((child) => CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey(child.key))
|
|
87
|
+
: [];
|
|
88
|
+
filteredCategories.push({ categoryId: filteredCategoryId, subCategoryIds: filteredSubCategoriesIds });
|
|
89
|
+
}
|
|
90
|
+
return filteredCategories;
|
|
57
91
|
}
|
|
58
92
|
function ShowAllButton(props) {
|
|
59
|
-
|
|
60
|
-
await enableCategory(IModelApp.viewManager, props.viewport.iModel, (props.filteredCategories ?? props.categories).map((category) => category.categoryId), true, true);
|
|
61
|
-
};
|
|
62
|
-
return (React.createElement(IconButton, { className: "tree-widget-header-tree-toolbar-icon", size: "small", styleType: "borderless", title: TreeWidget.translate("showAll"), onClick: showAll },
|
|
63
|
-
React.createElement(SvgVisibilityShow, null)));
|
|
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, {}) }));
|
|
64
94
|
}
|
|
65
95
|
function HideAllButton(props) {
|
|
66
|
-
|
|
67
|
-
await enableCategory(IModelApp.viewManager, props.viewport.iModel, (props.filteredCategories ?? props.categories).map((category) => category.categoryId), false, true);
|
|
68
|
-
};
|
|
69
|
-
return (React.createElement(IconButton, { className: "tree-widget-header-tree-toolbar-icon", size: "small", styleType: "borderless", title: TreeWidget.translate("hideAll"), onClick: hideAll },
|
|
70
|
-
React.createElement(SvgVisibilityHide, null)));
|
|
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, {}) }));
|
|
71
97
|
}
|
|
72
|
-
function
|
|
73
|
-
|
|
74
|
-
const ids = (props.filteredCategories ?? props.categories).map((category) => category.categoryId);
|
|
75
|
-
const enabled = [];
|
|
76
|
-
const disabled = [];
|
|
77
|
-
for (const id of ids) {
|
|
78
|
-
if (props.viewport.view.viewsCategory(id)) {
|
|
79
|
-
enabled.push(id);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
disabled.push(id);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
// Disable enabled
|
|
86
|
-
await enableCategory(IModelApp.viewManager, props.viewport.iModel, enabled, false, true);
|
|
87
|
-
// Enable disabled
|
|
88
|
-
await enableCategory(IModelApp.viewManager, props.viewport.iModel, disabled, true, true);
|
|
89
|
-
};
|
|
90
|
-
return (React.createElement(IconButton, { className: "tree-widget-header-tree-toolbar-icon", title: TreeWidget.translate("invert"), size: "small", styleType: "borderless", onClick: invert },
|
|
91
|
-
React.createElement(SvgVisibilityHalf, null)));
|
|
98
|
+
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, {}) }));
|
|
92
100
|
}
|
|
93
101
|
//# 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,OAAO,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACnD,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAE,SAAS,EAAoC,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AACrG,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAiC,0BAA0B,EAA4B,MAAM,gCAAgC,CAAC;AACrI,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAgB,yBAAyB,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAIrG,MAAM,UAAU,uBAAuB,CAAC,KAA0B;IAChE,MAAM,MAAM,GAAG,yBAAyB,EAAE,CAAC;IAC3C,MAAM,QAAQ,GAAG,iBAAiB,EAAE,CAAC;IAErC,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ,E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ACZ,SAAS,EAAC,YAAY,EACtB,OAAO,EAAE,MAAM;QAEf,oBAAC,iBAAiB,OAAG,CACV,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*--------------------------------------------------------------------------------------------*/\nimport \"../VisibilityTreeBase.scss\";\nimport React, { useEffect, useState } from \"react\";\nimport { useActiveIModelConnection, useActiveViewport } from \"@itwin/appui-react\";\nimport { IModelApp, IModelConnection, ScreenViewport } from \"@itwin/core-frontend\";\nimport { SvgVisibilityHalf, SvgVisibilityHide, SvgVisibilityShow } from \"@itwin/itwinui-icons-react\";\nimport { IconButton } from \"@itwin/itwinui-react\";\nimport { IPresentationTreeDataProvider, isPresentationTreeNodeItem, PresentationTreeNodeItem } from \"@itwin/presentation-components\";\nimport { TreeWidget } from \"../../../TreeWidget\";\nimport { SearchBar } from \"../../search-bar/SearchBar\";\nimport { useTreeFilteringState } from \"../../TreeFilteringState\";\nimport { AutoSizer } from \"../../utils/AutoSizer\";\nimport { enableCategory } from \"../CategoriesVisibilityUtils\";\nimport { CategoryTree } from \"./CategoriesTree\";\nimport { CategoryInfo, CategoryVisibilityHandler, useCategories } from \"./CategoryVisibilityHandler\";\n\nimport type { CategoriesTreeHeaderButtonProps, CategoriesTreeProps } from \"../../../types\";\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 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\n .filter((node) => isPresentationTreeNodeItem(node))\n .map((node) => CategoryVisibilityHandler.getInstanceIdFromTreeNodeKey((node as PresentationTreeNodeItem).key));\n}\n\nfunction ShowAllButton(props: CategoriesTreeHeaderButtonProps) {\n const showAll = async () => {\n await 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 size=\"small\"\n styleType=\"borderless\"\n title={TreeWidget.translate(\"showAll\")}\n onClick={showAll}\n >\n <SvgVisibilityShow />\n </IconButton>\n );\n}\n\nfunction HideAllButton(props: CategoriesTreeHeaderButtonProps) {\n const hideAll = async () => {\n await 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 size=\"small\"\n styleType=\"borderless\"\n title={TreeWidget.translate(\"hideAll\")}\n onClick={hideAll}\n >\n <SvgVisibilityHide />\n </IconButton>\n );\n}\n\nfunction InvertButton(props: CategoriesTreeHeaderButtonProps) {\n const invert = async () => {\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 await enableCategory(\n IModelApp.viewManager,\n props.viewport.iModel,\n enabled,\n false,\n true\n );\n\n // Enable disabled\n await 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 size=\"small\"\n styleType=\"borderless\"\n onClick={invert}\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;;;+FAG+F;AAE/F,OAAO,4BAA4B,CAAC;AACpC,OAAO,EAAE,Q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AQ,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 [[TreeWidgetComponent]].\n * @public\n */\nCategoriesTreeComponent.id = \"categories-tree\";\n\n/**\n * Label of the component. May be used when a creating a [[TreeDefinition]] for [[TreeWidgetComponent]].\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,8 +1,8 @@
|
|
|
1
|
-
import { TreeNodeItem } from "@itwin/components-react";
|
|
2
1
|
import { BeEvent } from "@itwin/core-bentley";
|
|
3
|
-
import { IModelConnection, ViewManager, Viewport } from "@itwin/core-frontend";
|
|
4
2
|
import { NodeKey } from "@itwin/presentation-common";
|
|
5
|
-
import {
|
|
3
|
+
import type { TreeNodeItem } from "@itwin/components-react";
|
|
4
|
+
import type { IModelConnection, ViewManager, Viewport } from "@itwin/core-frontend";
|
|
5
|
+
import type { IVisibilityHandler, VisibilityChangeListener, VisibilityStatus } from "../VisibilityTreeEventHandler";
|
|
6
6
|
/**
|
|
7
7
|
* Loads categories from viewport or uses provided list of categories.
|
|
8
8
|
* @internal
|
|
@@ -10,26 +10,33 @@ import { IVisibilityHandler, VisibilityChangeListener, VisibilityStatus } from "
|
|
|
10
10
|
export declare function useCategories(viewManager: ViewManager, imodel: IModelConnection, view?: Viewport): CategoryInfo[];
|
|
11
11
|
/**
|
|
12
12
|
* Data structure that describes category.
|
|
13
|
-
* @
|
|
13
|
+
* @public
|
|
14
14
|
*/
|
|
15
15
|
export interface CategoryInfo {
|
|
16
16
|
categoryId: string;
|
|
17
17
|
subCategoryIds?: string[];
|
|
18
18
|
}
|
|
19
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* Params for creating a [[CategoryVisibilityHandler]].
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
20
23
|
export interface CategoryVisibilityHandlerParams {
|
|
21
24
|
viewManager: ViewManager;
|
|
22
25
|
imodel: IModelConnection;
|
|
23
26
|
categories: CategoryInfo[];
|
|
24
|
-
activeView
|
|
27
|
+
activeView: Viewport;
|
|
25
28
|
allViewports?: boolean;
|
|
26
29
|
}
|
|
27
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* An [[IVisibilityHandler]] implementation that knows how to determine and change visibility of categories
|
|
32
|
+
* and subcategories.
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
28
35
|
export declare class CategoryVisibilityHandler implements IVisibilityHandler {
|
|
29
36
|
private _viewManager;
|
|
30
37
|
private _imodel;
|
|
31
38
|
private _pendingVisibilityChange;
|
|
32
|
-
private _activeView
|
|
39
|
+
private _activeView;
|
|
33
40
|
private _useAllViewports;
|
|
34
41
|
private _categories;
|
|
35
42
|
constructor(params: CategoryVisibilityHandlerParams);
|
|
@@ -47,4 +54,19 @@ export declare class CategoryVisibilityHandler implements IVisibilityHandler {
|
|
|
47
54
|
enableCategory(ids: string[], enabled: boolean, enableAllSubCategories?: boolean): Promise<void>;
|
|
48
55
|
enableSubCategory(key: string, enabled: boolean): void;
|
|
49
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Enable display of all given categories.
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
export declare function showAllCategories(categories: string[], viewport: Viewport): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Disable display of all given categories.
|
|
64
|
+
* @public
|
|
65
|
+
*/
|
|
66
|
+
export declare function hideAllCategories(categories: string[], viewport: Viewport): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Invert display of all given categories.
|
|
69
|
+
* @public
|
|
70
|
+
*/
|
|
71
|
+
export declare function invertAllCategories(categories: CategoryInfo[], viewport: Viewport): Promise<void>;
|
|
50
72
|
//# sourceMappingURL=CategoryVisibilityHandler.d.ts.map
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
import
|
|
5
|
+
import { useMemo } from "react";
|
|
6
6
|
import { useAsyncValue } from "@itwin/components-react";
|
|
7
7
|
import { BeEvent } from "@itwin/core-bentley";
|
|
8
|
+
import { IModelApp } from "@itwin/core-frontend";
|
|
8
9
|
import { NodeKey } from "@itwin/presentation-common";
|
|
9
10
|
import { isPresentationTreeNodeItem } from "@itwin/presentation-components";
|
|
10
11
|
import { enableCategory, enableSubCategory, loadCategoriesFromViewport } from "../CategoriesVisibilityUtils";
|
|
@@ -15,10 +16,14 @@ const EMPTY_CATEGORIES_ARRAY = [];
|
|
|
15
16
|
*/
|
|
16
17
|
export function useCategories(viewManager, imodel, view) {
|
|
17
18
|
const currentView = view || viewManager.getFirstOpenView();
|
|
18
|
-
const categoriesPromise =
|
|
19
|
+
const categoriesPromise = useMemo(async () => loadCategoriesFromViewport(imodel, currentView), [imodel, currentView]);
|
|
19
20
|
return useAsyncValue(categoriesPromise) ?? EMPTY_CATEGORIES_ARRAY;
|
|
20
21
|
}
|
|
21
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* An [[IVisibilityHandler]] implementation that knows how to determine and change visibility of categories
|
|
24
|
+
* and subcategories.
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
22
27
|
export class CategoryVisibilityHandler {
|
|
23
28
|
constructor(params) {
|
|
24
29
|
this.onVisibilityChange = new BeEvent();
|
|
@@ -36,16 +41,12 @@ export class CategoryVisibilityHandler {
|
|
|
36
41
|
// istanbul ignore next
|
|
37
42
|
this._useAllViewports = params.allViewports ?? false;
|
|
38
43
|
this._categories = params.categories;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
this._activeView.onViewedCategoriesChanged.addListener(this.onViewedCategoriesChanged);
|
|
42
|
-
}
|
|
44
|
+
this._activeView.onDisplayStyleChanged.addListener(this.onDisplayStyleChanged);
|
|
45
|
+
this._activeView.onViewedCategoriesChanged.addListener(this.onViewedCategoriesChanged);
|
|
43
46
|
}
|
|
44
47
|
dispose() {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
this._activeView.onViewedCategoriesChanged.removeListener(this.onViewedCategoriesChanged);
|
|
48
|
-
}
|
|
48
|
+
this._activeView.onDisplayStyleChanged.removeListener(this.onDisplayStyleChanged);
|
|
49
|
+
this._activeView.onViewedCategoriesChanged.removeListener(this.onViewedCategoriesChanged);
|
|
49
50
|
clearTimeout(this._pendingVisibilityChange);
|
|
50
51
|
}
|
|
51
52
|
getVisibilityStatus(node) {
|
|
@@ -75,14 +76,12 @@ export class CategoryVisibilityHandler {
|
|
|
75
76
|
}
|
|
76
77
|
getSubCategoryVisibility(id) {
|
|
77
78
|
const parentItem = this.getParent(id);
|
|
78
|
-
if (!parentItem
|
|
79
|
+
if (!parentItem)
|
|
79
80
|
return "hidden";
|
|
80
81
|
const isVisible = this._activeView.view.viewsCategory(parentItem.categoryId) && this._activeView.isSubCategoryVisible(id);
|
|
81
82
|
return isVisible ? "visible" : "hidden";
|
|
82
83
|
}
|
|
83
84
|
getCategoryVisibility(id) {
|
|
84
|
-
if (!this._activeView)
|
|
85
|
-
return "hidden";
|
|
86
85
|
return this._activeView.view.viewsCategory(id) ? "visible" : "hidden";
|
|
87
86
|
}
|
|
88
87
|
getParent(key) {
|
|
@@ -113,4 +112,48 @@ export class CategoryVisibilityHandler {
|
|
|
113
112
|
enableSubCategory(this._viewManager, key, enabled, this._useAllViewports);
|
|
114
113
|
}
|
|
115
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Enable display of all given categories.
|
|
117
|
+
* @public
|
|
118
|
+
*/
|
|
119
|
+
export async function showAllCategories(categories, viewport) {
|
|
120
|
+
await enableCategory(IModelApp.viewManager, viewport.iModel, categories, true, true);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Disable display of all given categories.
|
|
124
|
+
* @public
|
|
125
|
+
*/
|
|
126
|
+
export async function hideAllCategories(categories, viewport) {
|
|
127
|
+
await enableCategory(IModelApp.viewManager, viewport.iModel, categories, false, true);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Invert display of all given categories.
|
|
131
|
+
* @public
|
|
132
|
+
*/
|
|
133
|
+
export async function invertAllCategories(categories, viewport) {
|
|
134
|
+
const enabled = [];
|
|
135
|
+
const disabled = [];
|
|
136
|
+
const enabledSubCategories = [];
|
|
137
|
+
const disabledSubCategories = [];
|
|
138
|
+
for (const category of categories) {
|
|
139
|
+
if (!viewport.view.viewsCategory(category.categoryId)) {
|
|
140
|
+
disabled.push(category.categoryId);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
// 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
|
+
if (category.subCategoryIds?.some((subCategory) => !viewport.isSubCategoryVisible(subCategory))) {
|
|
145
|
+
for (const subCategory of category.subCategoryIds)
|
|
146
|
+
viewport.isSubCategoryVisible(subCategory) ? enabledSubCategories.push(subCategory) : disabledSubCategories.push(subCategory);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
enabled.push(category.categoryId);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// Disable enabled
|
|
153
|
+
enabledSubCategories.forEach((subCategory) => enableSubCategory(IModelApp.viewManager, subCategory, false, true));
|
|
154
|
+
await enableCategory(IModelApp.viewManager, viewport.iModel, enabled, false, true);
|
|
155
|
+
// Enable disabled
|
|
156
|
+
disabledSubCategories.forEach((subCategory) => enableSubCategory(IModelApp.viewManager, subCategory, true, true));
|
|
157
|
+
await enableCategory(IModelApp.viewManager, viewport.iModel, disabled, true, true);
|
|
158
|
+
}
|
|
116
159
|
//# sourceMappingURL=CategoryVisibilityHandler.js.map
|
|
@@ -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,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAgB,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,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;AAG7G,MAAM,sBAAsB,GAAmB,EAAE,CAAC;AAElD;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,WAAwB,EAAE,MAAwB,EAAE,IAAe;IAC/F,MAAM,WAAW,GAAG,IAAI,IAAI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AAC,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,OAAO,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,KAAK,CAAC,cAAc,CAAC,GAAa,EAAE,OAAgB,EAAE,sBAAsB,GAAG,IAAI;QACxF,MAAM,cAAc,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,gBAAgB,EAAE,sBAAsB,CAAC,CAAC;IACrH,CAAC;IAEM,iBAAiB,CAAC,GAAW,EAAE,OAAgB;QACpD,iBAAiB,CAAC,IAAI,CAAC,YAAY,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;IAC5E,CAAC;CACF","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 { isPresentationTreeNodeItem } from \"@itwin/presentation-components\";\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,): 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 || !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 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"]}
|
|
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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,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"]}
|