@itwin/tree-widget-react 3.0.0-dev.3 → 3.0.0-dev.4
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/README.md +95 -6
- package/lib/cjs/components/tree-header/TreeHeader.d.ts +10 -8
- package/lib/cjs/components/tree-header/TreeHeader.js +4 -6
- package/lib/cjs/components/tree-header/TreeHeader.js.map +1 -1
- package/lib/cjs/components/tree-header/TreeWithHeader.d.ts +13 -0
- package/lib/cjs/components/tree-header/TreeWithHeader.js +20 -0
- package/lib/cjs/components/tree-header/TreeWithHeader.js.map +1 -0
- package/lib/cjs/components/trees/categories-tree/CategoriesTree.d.ts +3 -7
- package/lib/cjs/components/trees/categories-tree/CategoriesTree.js +7 -63
- package/lib/cjs/components/trees/categories-tree/CategoriesTree.js.map +1 -1
- package/lib/cjs/components/trees/categories-tree/CategoriesTreeButtons.d.ts +9 -2
- package/lib/cjs/components/trees/categories-tree/CategoriesTreeButtons.js +24 -4
- package/lib/cjs/components/trees/categories-tree/CategoriesTreeButtons.js.map +1 -1
- package/lib/cjs/components/trees/categories-tree/CategoriesTreeComponent.d.ts +0 -1
- package/lib/cjs/components/trees/categories-tree/CategoriesTreeComponent.js +15 -18
- package/lib/cjs/components/trees/categories-tree/CategoriesTreeComponent.js.map +1 -1
- package/lib/cjs/components/trees/categories-tree/CategoriesVisibilityHandler.d.ts +1 -9
- package/lib/cjs/components/trees/categories-tree/CategoriesVisibilityHandler.js +2 -6
- package/lib/cjs/components/trees/categories-tree/CategoriesVisibilityHandler.js.map +1 -1
- package/lib/cjs/components/trees/categories-tree/UseCategoriesTree.d.ts +25 -0
- package/lib/cjs/components/trees/categories-tree/UseCategoriesTree.js +89 -0
- package/lib/cjs/components/trees/categories-tree/UseCategoriesTree.js.map +1 -0
- package/lib/cjs/components/trees/common/CategoriesVisibilityUtils.d.ts +6 -6
- package/lib/cjs/components/trees/common/CategoriesVisibilityUtils.js +32 -78
- package/lib/cjs/components/trees/common/CategoriesVisibilityUtils.js.map +1 -1
- package/lib/cjs/components/trees/common/UseTelemetryContext.d.ts +1 -1
- package/lib/cjs/components/trees/common/UseTelemetryContext.js.map +1 -1
- package/lib/cjs/components/trees/common/components/Tree.d.ts +0 -2
- package/lib/cjs/components/trees/common/components/Tree.js +5 -4
- package/lib/cjs/components/trees/common/components/Tree.js.map +1 -1
- package/lib/cjs/components/trees/common/components/VisibilityTree.d.ts +2 -3
- package/lib/cjs/components/trees/common/components/VisibilityTree.js.map +1 -1
- package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTree.d.ts +1 -1
- package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTree.js.map +1 -1
- package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js +1 -2
- package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js.map +1 -1
- package/lib/cjs/components/trees/imodel-content-tree/IModelContentTree.d.ts +1 -1
- package/lib/cjs/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -1
- package/lib/cjs/components/trees/imodel-content-tree/IModelContentTreeComponent.js +1 -2
- package/lib/cjs/components/trees/imodel-content-tree/IModelContentTreeComponent.js.map +1 -1
- package/lib/cjs/components/trees/index.d.ts +4 -0
- package/lib/cjs/components/trees/index.js +9 -1
- package/lib/cjs/components/trees/index.js.map +1 -1
- package/lib/cjs/components/trees/models-tree/ModelsTree.d.ts +4 -4
- package/lib/cjs/components/trees/models-tree/ModelsTree.js +4 -203
- package/lib/cjs/components/trees/models-tree/ModelsTree.js.map +1 -1
- package/lib/cjs/components/trees/models-tree/ModelsTreeButtons.d.ts +9 -3
- package/lib/cjs/components/trees/models-tree/ModelsTreeButtons.js +13 -3
- package/lib/cjs/components/trees/models-tree/ModelsTreeButtons.js.map +1 -1
- package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.d.ts +0 -1
- package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.js +27 -20
- package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
- package/lib/cjs/components/trees/models-tree/UseModelsTree.d.ts +29 -0
- package/lib/cjs/components/trees/models-tree/UseModelsTree.js +233 -0
- package/lib/cjs/components/trees/models-tree/UseModelsTree.js.map +1 -0
- package/lib/cjs/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js +1 -1
- package/lib/cjs/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
- package/lib/cjs/tree-widget-react.d.ts +1 -0
- package/lib/cjs/tree-widget-react.js +3 -1
- package/lib/cjs/tree-widget-react.js.map +1 -1
- package/lib/esm/components/tree-header/TreeHeader.d.ts +10 -8
- package/lib/esm/components/tree-header/TreeHeader.js +4 -6
- package/lib/esm/components/tree-header/TreeHeader.js.map +1 -1
- package/lib/esm/components/tree-header/TreeWithHeader.d.ts +13 -0
- package/lib/esm/components/tree-header/TreeWithHeader.js +13 -0
- package/lib/esm/components/tree-header/TreeWithHeader.js.map +1 -0
- package/lib/esm/components/trees/categories-tree/CategoriesTree.d.ts +3 -7
- package/lib/esm/components/trees/categories-tree/CategoriesTree.js +7 -63
- package/lib/esm/components/trees/categories-tree/CategoriesTree.js.map +1 -1
- package/lib/esm/components/trees/categories-tree/CategoriesTreeButtons.d.ts +9 -2
- package/lib/esm/components/trees/categories-tree/CategoriesTreeButtons.js +22 -4
- package/lib/esm/components/trees/categories-tree/CategoriesTreeButtons.js.map +1 -1
- package/lib/esm/components/trees/categories-tree/CategoriesTreeComponent.d.ts +0 -1
- package/lib/esm/components/trees/categories-tree/CategoriesTreeComponent.js +16 -16
- package/lib/esm/components/trees/categories-tree/CategoriesTreeComponent.js.map +1 -1
- package/lib/esm/components/trees/categories-tree/CategoriesVisibilityHandler.d.ts +1 -9
- package/lib/esm/components/trees/categories-tree/CategoriesVisibilityHandler.js +2 -6
- package/lib/esm/components/trees/categories-tree/CategoriesVisibilityHandler.js.map +1 -1
- package/lib/esm/components/trees/categories-tree/UseCategoriesTree.d.ts +25 -0
- package/lib/esm/components/trees/categories-tree/UseCategoriesTree.js +85 -0
- package/lib/esm/components/trees/categories-tree/UseCategoriesTree.js.map +1 -0
- package/lib/esm/components/trees/common/CategoriesVisibilityUtils.d.ts +6 -6
- package/lib/esm/components/trees/common/CategoriesVisibilityUtils.js +33 -79
- package/lib/esm/components/trees/common/CategoriesVisibilityUtils.js.map +1 -1
- package/lib/esm/components/trees/common/UseTelemetryContext.d.ts +1 -1
- package/lib/esm/components/trees/common/UseTelemetryContext.js.map +1 -1
- package/lib/esm/components/trees/common/components/Tree.d.ts +0 -2
- package/lib/esm/components/trees/common/components/Tree.js +5 -4
- package/lib/esm/components/trees/common/components/Tree.js.map +1 -1
- package/lib/esm/components/trees/common/components/VisibilityTree.d.ts +2 -3
- package/lib/esm/components/trees/common/components/VisibilityTree.js.map +1 -1
- package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTree.d.ts +1 -1
- package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTree.js.map +1 -1
- package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js +1 -2
- package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js.map +1 -1
- package/lib/esm/components/trees/imodel-content-tree/IModelContentTree.d.ts +1 -1
- package/lib/esm/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -1
- package/lib/esm/components/trees/imodel-content-tree/IModelContentTreeComponent.js +1 -2
- package/lib/esm/components/trees/imodel-content-tree/IModelContentTreeComponent.js.map +1 -1
- package/lib/esm/components/trees/index.d.ts +4 -0
- package/lib/esm/components/trees/index.js +4 -0
- package/lib/esm/components/trees/index.js.map +1 -1
- package/lib/esm/components/trees/models-tree/ModelsTree.d.ts +4 -4
- package/lib/esm/components/trees/models-tree/ModelsTree.js +5 -204
- package/lib/esm/components/trees/models-tree/ModelsTree.js.map +1 -1
- package/lib/esm/components/trees/models-tree/ModelsTreeButtons.d.ts +9 -3
- package/lib/esm/components/trees/models-tree/ModelsTreeButtons.js +12 -2
- package/lib/esm/components/trees/models-tree/ModelsTreeButtons.js.map +1 -1
- package/lib/esm/components/trees/models-tree/ModelsTreeComponent.d.ts +0 -1
- package/lib/esm/components/trees/models-tree/ModelsTreeComponent.js +29 -19
- package/lib/esm/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
- package/lib/esm/components/trees/models-tree/UseModelsTree.d.ts +29 -0
- package/lib/esm/components/trees/models-tree/UseModelsTree.js +229 -0
- package/lib/esm/components/trees/models-tree/UseModelsTree.js.map +1 -0
- package/lib/esm/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js +2 -2
- package/lib/esm/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
- package/lib/esm/tree-widget-react.d.ts +1 -0
- package/lib/esm/tree-widget-react.js +1 -0
- package/lib/esm/tree-widget-react.js.map +1 -1
- package/package.json +11 -15
- package/lib/cjs/components/trees/categories-tree/UseCategories.d.ts +0 -8
- package/lib/cjs/components/trees/categories-tree/UseCategories.js +0 -22
- package/lib/cjs/components/trees/categories-tree/UseCategories.js.map +0 -1
- package/lib/cjs/components/utils/AutoSizer.d.ts +0 -13
- package/lib/cjs/components/utils/AutoSizer.js +0 -21
- package/lib/cjs/components/utils/AutoSizer.js.map +0 -1
- package/lib/esm/components/trees/categories-tree/UseCategories.d.ts +0 -8
- package/lib/esm/components/trees/categories-tree/UseCategories.js +0 -18
- package/lib/esm/components/trees/categories-tree/UseCategories.js.map +0 -1
- package/lib/esm/components/utils/AutoSizer.d.ts +0 -13
- package/lib/esm/components/utils/AutoSizer.js +0 -17
- package/lib/esm/components/utils/AutoSizer.js.map +0 -1
- /package/lib/cjs/components/{trees/Tree.scss → tree-header/TreeWithHeader.scss} +0 -0
- /package/lib/esm/components/{trees/Tree.scss → tree-header/TreeWithHeader.scss} +0 -0
|
@@ -1,27 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.CategoriesTreeComponent = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
7
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
6
|
/*---------------------------------------------------------------------------------------------
|
|
9
7
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
10
8
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
11
9
|
*--------------------------------------------------------------------------------------------*/
|
|
12
|
-
require("
|
|
13
|
-
const classnames_1 = __importDefault(require("classnames"));
|
|
14
|
-
const react_1 = require("react");
|
|
10
|
+
const react_2 = require("react");
|
|
15
11
|
const appui_react_1 = require("@itwin/appui-react");
|
|
16
|
-
const core_frontend_1 = require("@itwin/core-frontend");
|
|
17
12
|
const TreeWidget_1 = require("../../../TreeWidget");
|
|
18
|
-
const
|
|
19
|
-
const AutoSizer_1 = require("../../utils/AutoSizer");
|
|
13
|
+
const TreeWithHeader_1 = require("../../tree-header/TreeWithHeader");
|
|
20
14
|
const UseFiltering_1 = require("../common/UseFiltering");
|
|
21
15
|
const UseTelemetryContext_1 = require("../common/UseTelemetryContext");
|
|
22
16
|
const CategoriesTree_1 = require("./CategoriesTree");
|
|
23
17
|
const CategoriesTreeButtons_1 = require("./CategoriesTreeButtons");
|
|
24
|
-
const UseCategories_1 = require("./UseCategories");
|
|
25
18
|
/**
|
|
26
19
|
* A component that renders `CategoriesTree` and a header with filtering capabilities and header buttons.
|
|
27
20
|
* @public
|
|
@@ -61,15 +54,19 @@ exports.CategoriesTreeComponent.id = "categories-tree-v2";
|
|
|
61
54
|
*/
|
|
62
55
|
exports.CategoriesTreeComponent.getLabel = () => TreeWidget_1.TreeWidget.translate("categoriesTree.label");
|
|
63
56
|
function CategoriesTreeComponentImpl({ iModel, viewport, headerButtons, onPerformanceMeasured, onFeatureUsed, ...treeProps }) {
|
|
64
|
-
const
|
|
57
|
+
const buttonProps = (0, CategoriesTreeButtons_1.useCategoriesTreeButtonProps)({ viewport });
|
|
65
58
|
const { filter, applyFilter, clearFilter } = (0, UseFiltering_1.useFiltering)();
|
|
66
59
|
const density = treeProps.density;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
60
|
+
const buttons = headerButtons
|
|
61
|
+
? headerButtons.map((btn, index) => (0, jsx_runtime_1.jsx)(react_2.Fragment, { children: btn({ ...buttonProps, onFeatureUsed }) }, index))
|
|
62
|
+
: [
|
|
63
|
+
(0, react_1.createElement)(CategoriesTreeButtons_1.ShowAllButton, { ...buttonProps, key: "show-all-btn", density: density, onFeatureUsed: onFeatureUsed }),
|
|
64
|
+
(0, react_1.createElement)(CategoriesTreeButtons_1.HideAllButton, { ...buttonProps, key: "hide-all-btn", density: density, onFeatureUsed: onFeatureUsed }),
|
|
65
|
+
(0, react_1.createElement)(CategoriesTreeButtons_1.InvertAllButton, { ...buttonProps, key: "invert-all-btn", density: density, onFeatureUsed: onFeatureUsed }),
|
|
66
|
+
];
|
|
67
|
+
return ((0, jsx_runtime_1.jsx)(UseTelemetryContext_1.TelemetryContextProvider, { componentIdentifier: exports.CategoriesTreeComponent.id, onFeatureUsed: onFeatureUsed, onPerformanceMeasured: onPerformanceMeasured, children: (0, jsx_runtime_1.jsx)(TreeWithHeader_1.TreeWithHeader, { buttons: buttons, density: density, filteringProps: {
|
|
68
|
+
onFilterStart: applyFilter,
|
|
69
|
+
onFilterClear: clearFilter,
|
|
70
|
+
}, children: (0, jsx_runtime_1.jsx)(CategoriesTree_1.CategoriesTree, { ...treeProps, imodel: iModel, activeView: viewport, filter: filter }) }) }));
|
|
74
71
|
}
|
|
75
72
|
//# sourceMappingURL=CategoriesTreeComponent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CategoriesTreeComponent.js","sourceRoot":"","sources":["../../../../../src/components/trees/categories-tree/CategoriesTreeComponent.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CategoriesTreeComponent.js","sourceRoot":"","sources":["../../../../../src/components/trees/categories-tree/CategoriesTreeComponent.tsx"],"names":[],"mappings":";;;;;AAAA;;;gGAGgG;AAEhG,iCAAiC;AACjC,oDAAkF;AAClF,oDAAiD;AACjD,qEAAkE;AAClE,yDAAsD;AACtD,uEAAyE;AACzE,qDAAkD;AAClD,mEAAsH;AA2BtH;;;GAGG;AACI,MAAM,uBAAuB,GAAG,CAAC,KAAmC,EAAE,EAAE;IAC7E,MAAM,MAAM,GAAG,IAAA,uCAAyB,GAAE,CAAC;IAC3C,MAAM,QAAQ,GAAG,IAAA,+BAAiB,GAAE,CAAC;IAErC,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE;QACxB,OAAO,IAAI,CAAC;KACb;IAED,OAAO,uBAAC,2BAA2B,OAAK,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAI,CAAC;AACxF,CAAC,CAAC;AATW,QAAA,uBAAuB,2BASlC;AAEF;;;GAGG;AACH,+BAAuB,CAAC,aAAa,GAAG,qCAAa,CAAC;AAEtD;;;GAGG;AACH,+BAAuB,CAAC,aAAa,GAAG,qCAAa,CAAC;AAEtD;;;GAGG;AACH,+BAAuB,CAAC,eAAe,GAAG,uCAAe,CAAC;AAE1D;;;GAGG;AACH,+BAAuB,CAAC,EAAE,GAAG,oBAAoB,CAAC;AAElD;;;GAGG;AACH,+BAAuB,CAAC,QAAQ,GAAG,GAAG,EAAE,CAAC,uBAAU,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC;AAEtF,SAAS,2BAA2B,CAAC,EACnC,MAAM,EACN,QAAQ,EACR,aAAa,EACb,qBAAqB,EACrB,aAAa,EACb,GAAG,SAAS,EAC0E;IACtF,MAAM,WAAW,GAAG,IAAA,oDAA4B,EAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC/D,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,IAAA,2BAAY,GAAE,CAAC;IAC5D,MAAM,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC;IAElC,MAAM,OAAO,GAAc,aAAa;QACtC,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,uBAAC,gBAAQ,cAAc,GAAG,CAAC,EAAE,GAAG,WAAW,EAAE,aAAa,EAAE,CAAC,IAA9C,KAAK,CAAqD,CAAC;QAC9G,CAAC,CAAC;YACE,2BAAC,qCAAa,OAAK,WAAW,EAAE,GAAG,EAAC,cAAc,EAAC,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,aAAa,GAAI;YACrG,2BAAC,qCAAa,OAAK,WAAW,EAAE,GAAG,EAAC,cAAc,EAAC,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,aAAa,GAAI;YACrG,2BAAC,uCAAe,OAAK,WAAW,EAAE,GAAG,EAAC,gBAAgB,EAAC,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,aAAa,GAAI;SAC1G,CAAC;IAEN,OAAO,CACL,uBAAC,8CAAwB,IAAC,mBAAmB,EAAE,+BAAuB,CAAC,EAAE,EAAE,aAAa,EAAE,aAAa,EAAE,qBAAqB,EAAE,qBAAqB,YACnJ,uBAAC,+BAAc,IACb,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE;gBACd,aAAa,EAAE,WAAW;gBAC1B,aAAa,EAAE,WAAW;aAC3B,YAED,uBAAC,+BAAc,OAAK,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,GAAI,GACxE,GACQ,CAC5B,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { Fragment } from \"react\";\nimport { useActiveIModelConnection, useActiveViewport } from \"@itwin/appui-react\";\nimport { TreeWidget } from \"../../../TreeWidget\";\nimport { TreeWithHeader } from \"../../tree-header/TreeWithHeader\";\nimport { useFiltering } from \"../common/UseFiltering\";\nimport { TelemetryContextProvider } from \"../common/UseTelemetryContext\";\nimport { CategoriesTree } from \"./CategoriesTree\";\nimport { HideAllButton, InvertAllButton, ShowAllButton, useCategoriesTreeButtonProps } from \"./CategoriesTreeButtons\";\n\nimport type { ComponentPropsWithoutRef, ReactNode } from \"react\";\nimport type { IModelConnection, ScreenViewport } from \"@itwin/core-frontend\";\nimport type { CategoriesTreeHeaderButtonProps } from \"./CategoriesTreeButtons\";\n\n/** @public */\ninterface CategoriesTreeComponentProps\n extends Pick<\n ComponentPropsWithoutRef<typeof CategoriesTree>,\n \"getSchemaContext\" | \"selectionStorage\" | \"density\" | \"hierarchyLevelConfig\" | \"selectionMode\"\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 onPerformanceMeasured?: (featureId: string, duration: number) => void;\n onFeatureUsed?: (feature: string) => void;\n}\n\n/**\n * A component that renders `CategoriesTree` and a header with filtering capabilities and header buttons.\n * @public\n */\nexport const CategoriesTreeComponent = (props: CategoriesTreeComponentProps) => {\n const iModel = useActiveIModelConnection();\n const viewport = useActiveViewport();\n\n if (!iModel || !viewport) {\n return null;\n }\n\n return <CategoriesTreeComponentImpl {...props} iModel={iModel} viewport={viewport} />;\n};\n\n/**\n * Renders a \"Show all\" button that enables display of all categories and their subcategories.\n * @public\n */\nCategoriesTreeComponent.ShowAllButton = ShowAllButton;\n\n/**\n * Renders a \"Hide all\" button that disables display of all categories.\n * @public\n */\nCategoriesTreeComponent.HideAllButton = HideAllButton;\n\n/**\n * Renders an \"Invert all\" button that inverts display of all categories.\n * @public\n */\nCategoriesTreeComponent.InvertAllButton = InvertAllButton;\n\n/**\n * Id of the component. May be used when a creating a `TreeDefinition` for `SelectableTree`.\n * @public\n */\nCategoriesTreeComponent.id = \"categories-tree-v2\";\n\n/**\n * Label of the component. May be used when a creating a `TreeDefinition` for `SelectableTree`.\n * @public\n */\nCategoriesTreeComponent.getLabel = () => TreeWidget.translate(\"categoriesTree.label\");\n\nfunction CategoriesTreeComponentImpl({\n iModel,\n viewport,\n headerButtons,\n onPerformanceMeasured,\n onFeatureUsed,\n ...treeProps\n}: CategoriesTreeComponentProps & { iModel: IModelConnection; viewport: ScreenViewport }) {\n const buttonProps = useCategoriesTreeButtonProps({ viewport });\n const { filter, applyFilter, clearFilter } = useFiltering();\n const density = treeProps.density;\n\n const buttons: ReactNode = headerButtons\n ? headerButtons.map((btn, index) => <Fragment key={index}>{btn({ ...buttonProps, onFeatureUsed })}</Fragment>)\n : [\n <ShowAllButton {...buttonProps} key=\"show-all-btn\" density={density} onFeatureUsed={onFeatureUsed} />,\n <HideAllButton {...buttonProps} key=\"hide-all-btn\" density={density} onFeatureUsed={onFeatureUsed} />,\n <InvertAllButton {...buttonProps} key=\"invert-all-btn\" density={density} onFeatureUsed={onFeatureUsed} />,\n ];\n\n return (\n <TelemetryContextProvider componentIdentifier={CategoriesTreeComponent.id} onFeatureUsed={onFeatureUsed} onPerformanceMeasured={onPerformanceMeasured}>\n <TreeWithHeader\n buttons={buttons}\n density={density}\n filteringProps={{\n onFilterStart: applyFilter,\n onFilterClear: clearFilter,\n }}\n >\n <CategoriesTree {...treeProps} imodel={iModel} activeView={viewport} filter={filter} />\n </TreeWithHeader>\n </TelemetryContextProvider>\n );\n}\n"]}
|
|
@@ -1,22 +1,14 @@
|
|
|
1
1
|
import { BeEvent } from "@itwin/core-bentley";
|
|
2
2
|
import { HierarchyNode } from "@itwin/presentation-hierarchies";
|
|
3
|
-
import type {
|
|
4
|
-
import type { IModelConnection, ViewManager, Viewport } from "@itwin/core-frontend";
|
|
3
|
+
import type { Viewport } from "@itwin/core-frontend";
|
|
5
4
|
import type { HierarchyVisibilityHandler, VisibilityStatus } from "../common/UseHierarchyVisibility";
|
|
6
5
|
interface CategoriesVisibilityHandlerProps {
|
|
7
|
-
viewManager: ViewManager;
|
|
8
|
-
imodel: IModelConnection;
|
|
9
|
-
categories: CategoryInfo[];
|
|
10
6
|
viewport: Viewport;
|
|
11
|
-
allViewports?: boolean;
|
|
12
7
|
}
|
|
13
8
|
/** @internal */
|
|
14
9
|
export declare class CategoriesVisibilityHandler implements HierarchyVisibilityHandler {
|
|
15
|
-
private _viewManager;
|
|
16
|
-
private _imodel;
|
|
17
10
|
private _pendingVisibilityChange;
|
|
18
11
|
private _viewport;
|
|
19
|
-
private _useAllViewports;
|
|
20
12
|
constructor(props: CategoriesVisibilityHandlerProps);
|
|
21
13
|
dispose(): void;
|
|
22
14
|
onVisibilityChange: BeEvent<import("@itwin/core-bentley").Listener>;
|
|
@@ -20,11 +20,7 @@ class CategoriesVisibilityHandler {
|
|
|
20
20
|
this.onViewedCategoriesChanged = () => {
|
|
21
21
|
this.onVisibilityChangeInternal();
|
|
22
22
|
};
|
|
23
|
-
this._viewManager = props.viewManager;
|
|
24
|
-
this._imodel = props.imodel;
|
|
25
23
|
this._viewport = props.viewport;
|
|
26
|
-
// istanbul ignore next
|
|
27
|
-
this._useAllViewports = props.allViewports ?? false;
|
|
28
24
|
this._viewport.onDisplayStyleChanged.addListener(this.onDisplayStyleChanged);
|
|
29
25
|
this._viewport.onViewedCategoriesChanged.addListener(this.onViewedCategoriesChanged);
|
|
30
26
|
}
|
|
@@ -84,10 +80,10 @@ class CategoriesVisibilityHandler {
|
|
|
84
80
|
return presentation_hierarchies_1.HierarchyNode.isInstancesNode(node) && node.key.instanceKeys.length > 0 ? node.key.instanceKeys[0].id : /* istanbul ignore next */ "";
|
|
85
81
|
}
|
|
86
82
|
async enableCategory(ids, enabled, enableAllSubCategories = true) {
|
|
87
|
-
await (0, CategoriesVisibilityUtils_1.enableCategoryDisplay)(this.
|
|
83
|
+
await (0, CategoriesVisibilityUtils_1.enableCategoryDisplay)(this._viewport, ids, enabled, enableAllSubCategories);
|
|
88
84
|
}
|
|
89
85
|
enableSubCategory(key, enabled) {
|
|
90
|
-
(0, CategoriesVisibilityUtils_1.enableSubCategoryDisplay)(this.
|
|
86
|
+
(0, CategoriesVisibilityUtils_1.enableSubCategoryDisplay)(this._viewport, key, enabled);
|
|
91
87
|
}
|
|
92
88
|
}
|
|
93
89
|
exports.CategoriesVisibilityHandler = CategoriesVisibilityHandler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CategoriesVisibilityHandler.js","sourceRoot":"","sources":["../../../../../src/components/trees/categories-tree/CategoriesVisibilityHandler.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,sDAA8C;AAC9C,8EAAgE;AAChE,mFAAsG;
|
|
1
|
+
{"version":3,"file":"CategoriesVisibilityHandler.js","sourceRoot":"","sources":["../../../../../src/components/trees/categories-tree/CategoriesVisibilityHandler.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,sDAA8C;AAC9C,8EAAgE;AAChE,mFAAsG;AAStG,gBAAgB;AAChB,MAAa,2BAA2B;IAItC,YAAY,KAAuC;QAY5C,uBAAkB,GAAG,IAAI,sBAAO,EAAE,CAAC;QAiD1C,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;QApEA,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,QAAQ,CAAC;QAChC,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAAC,WAAW,CAAC,IAAI,CAAC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IAEM,MAAM,CAAC,8BAA8B,CAAC,IAAmB;QAC9D,OAAO,wCAAa,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,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,IAAA,iDAAqB,EAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,sBAAsB,CAAC,CAAC;IACpF,CAAC;IAEM,iBAAiB,CAAC,GAAW,EAAE,OAAgB;QACpD,IAAA,oDAAwB,EAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;IACzD,CAAC;CACF;AAjGD,kEAiGC","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 { BeEvent } from \"@itwin/core-bentley\";\nimport { HierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport { enableCategoryDisplay, enableSubCategoryDisplay } from \"../common/CategoriesVisibilityUtils\";\n\nimport type { Viewport } from \"@itwin/core-frontend\";\nimport type { HierarchyVisibilityHandler, VisibilityStatus } from \"../common/UseHierarchyVisibility\";\n\ninterface CategoriesVisibilityHandlerProps {\n viewport: Viewport;\n}\n\n/** @internal */\nexport class CategoriesVisibilityHandler implements HierarchyVisibilityHandler {\n private _pendingVisibilityChange: any;\n private _viewport: Viewport;\n\n constructor(props: CategoriesVisibilityHandlerProps) {\n this._viewport = props.viewport;\n this._viewport.onDisplayStyleChanged.addListener(this.onDisplayStyleChanged);\n this._viewport.onViewedCategoriesChanged.addListener(this.onViewedCategoriesChanged);\n }\n\n public dispose() {\n this._viewport.onDisplayStyleChanged.removeListener(this.onDisplayStyleChanged);\n this._viewport.onViewedCategoriesChanged.removeListener(this.onViewedCategoriesChanged);\n clearTimeout(this._pendingVisibilityChange);\n }\n\n public onVisibilityChange = new BeEvent();\n\n /** Returns visibility status of the tree node. */\n public getVisibilityStatus(node: HierarchyNode): Promise<VisibilityStatus> | VisibilityStatus {\n if (!HierarchyNode.isInstancesNode(node)) {\n return { state: \"hidden\", isDisabled: true };\n }\n return { state: node.parentKeys.length ? this.getSubCategoryVisibility(node) : this.getCategoryVisibility(node) };\n }\n\n public async changeVisibility(node: HierarchyNode, on: boolean) {\n if (!HierarchyNode.isInstancesNode(node)) {\n return;\n }\n\n // handle subcategory visibility change\n if (node.parentKeys.length) {\n const childId = CategoriesVisibilityHandler.getInstanceIdFromHierarchyNode(node);\n const parentCategoryId = node.extendedData?.categoryId;\n\n // make sure parent category is enabled\n if (on && parentCategoryId) {\n await this.enableCategory([parentCategoryId], true, false);\n }\n\n this.enableSubCategory(childId, on);\n return;\n }\n\n const instanceId = CategoriesVisibilityHandler.getInstanceIdFromHierarchyNode(node);\n await this.enableCategory([instanceId], on, true);\n }\n\n public getSubCategoryVisibility(node: HierarchyNode) {\n const parentCategoryId = node.extendedData?.categoryId;\n if (!parentCategoryId) {\n return \"hidden\";\n }\n\n const subcategoryId = CategoriesVisibilityHandler.getInstanceIdFromHierarchyNode(node);\n const isVisible = this._viewport.view.viewsCategory(parentCategoryId) && this._viewport.isSubCategoryVisible(subcategoryId);\n return isVisible ? \"visible\" : \"hidden\";\n }\n\n public getCategoryVisibility(node: HierarchyNode) {\n const instanceId = CategoriesVisibilityHandler.getInstanceIdFromHierarchyNode(node);\n return this._viewport.view.viewsCategory(instanceId) ? \"visible\" : \"hidden\";\n }\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n private onDisplayStyleChanged = () => {\n this.onVisibilityChangeInternal();\n };\n\n // eslint-disable-next-line @typescript-eslint/naming-convention\n private onViewedCategoriesChanged = () => {\n this.onVisibilityChangeInternal();\n };\n\n private onVisibilityChangeInternal() {\n if (this._pendingVisibilityChange) {\n return;\n }\n\n this._pendingVisibilityChange = setTimeout(() => {\n this.onVisibilityChange.raiseEvent();\n this._pendingVisibilityChange = undefined;\n }, 0);\n }\n\n public static getInstanceIdFromHierarchyNode(node: HierarchyNode) {\n return HierarchyNode.isInstancesNode(node) && node.key.instanceKeys.length > 0 ? node.key.instanceKeys[0].id : /* istanbul ignore next */ \"\";\n }\n\n public async enableCategory(ids: string[], enabled: boolean, enableAllSubCategories = true) {\n await enableCategoryDisplay(this._viewport, ids, enabled, enableAllSubCategories);\n }\n\n public enableSubCategory(key: string, enabled: boolean) {\n enableSubCategoryDisplay(this._viewport, key, enabled);\n }\n}\n"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { VisibilityTree } from "../common/components/VisibilityTree";
|
|
2
|
+
import type { ComponentPropsWithoutRef } from "react";
|
|
3
|
+
import type { Viewport } from "@itwin/core-frontend";
|
|
4
|
+
import type { VisibilityTreeRenderer } from "../common/components/VisibilityTreeRenderer";
|
|
5
|
+
/** @beta */
|
|
6
|
+
type VisibilityTreeRendererProps = ComponentPropsWithoutRef<typeof VisibilityTreeRenderer>;
|
|
7
|
+
/** @beta */
|
|
8
|
+
type VisibilityTreeProps = ComponentPropsWithoutRef<typeof VisibilityTree>;
|
|
9
|
+
/** @beta */
|
|
10
|
+
interface UseCategoriesTreeProps {
|
|
11
|
+
filter: string;
|
|
12
|
+
activeView: Viewport;
|
|
13
|
+
}
|
|
14
|
+
/** @beta */
|
|
15
|
+
interface UseCategoriesTreeResult {
|
|
16
|
+
categoriesTreeProps: Pick<VisibilityTreeProps, "treeName" | "getHierarchyDefinition" | "getFilteredPaths" | "visibilityHandlerFactory" | "highlight" | "noDataMessage">;
|
|
17
|
+
rendererProps: Pick<Required<VisibilityTreeRendererProps>, "getIcon" | "getSublabel">;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Custom hook to create and manage state for the categories tree.
|
|
21
|
+
* @beta
|
|
22
|
+
*/
|
|
23
|
+
export declare function useCategoriesTree({ filter, activeView }: UseCategoriesTreeProps): UseCategoriesTreeResult;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=UseCategoriesTree.d.ts.map
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useCategoriesTree = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
/*---------------------------------------------------------------------------------------------
|
|
6
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
7
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
8
|
+
*--------------------------------------------------------------------------------------------*/
|
|
9
|
+
const react_1 = require("react");
|
|
10
|
+
const itwinui_icons_react_1 = require("@itwin/itwinui-icons-react");
|
|
11
|
+
const itwinui_react_1 = require("@itwin/itwinui-react");
|
|
12
|
+
const TreeWidget_1 = require("../../../TreeWidget");
|
|
13
|
+
const UseTelemetryContext_1 = require("../common/UseTelemetryContext");
|
|
14
|
+
const CategoriesTreeDefinition_1 = require("./CategoriesTreeDefinition");
|
|
15
|
+
const CategoriesVisibilityHandler_1 = require("./CategoriesVisibilityHandler");
|
|
16
|
+
/**
|
|
17
|
+
* Custom hook to create and manage state for the categories tree.
|
|
18
|
+
* @beta
|
|
19
|
+
*/
|
|
20
|
+
function useCategoriesTree({ filter, activeView }) {
|
|
21
|
+
const [filteringError, setFilteringError] = (0, react_1.useState)();
|
|
22
|
+
const visibilityHandlerFactory = (0, react_1.useCallback)(() => {
|
|
23
|
+
const visibilityHandler = new CategoriesVisibilityHandler_1.CategoriesVisibilityHandler({
|
|
24
|
+
viewport: activeView,
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
getVisibilityStatus: async (node) => visibilityHandler.getVisibilityStatus(node),
|
|
28
|
+
changeVisibility: async (node, on) => visibilityHandler.changeVisibility(node, on),
|
|
29
|
+
onVisibilityChange: visibilityHandler.onVisibilityChange,
|
|
30
|
+
dispose: () => visibilityHandler.dispose(),
|
|
31
|
+
};
|
|
32
|
+
}, [activeView]);
|
|
33
|
+
const { onFeatureUsed } = (0, UseTelemetryContext_1.useTelemetryContext)();
|
|
34
|
+
const getHierarchyDefinition = (0, react_1.useCallback)((props) => {
|
|
35
|
+
return new CategoriesTreeDefinition_1.CategoriesTreeDefinition({ ...props, viewType: activeView.view.is2d() ? "2d" : "3d" });
|
|
36
|
+
}, [activeView]);
|
|
37
|
+
const getFilteredPaths = (0, react_1.useMemo)(() => {
|
|
38
|
+
setFilteringError(undefined);
|
|
39
|
+
if (!filter) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
return async ({ imodelAccess }) => {
|
|
43
|
+
onFeatureUsed({ featureId: "filtering", reportInteraction: true });
|
|
44
|
+
try {
|
|
45
|
+
return await CategoriesTreeDefinition_1.CategoriesTreeDefinition.createInstanceKeyPaths({ imodelAccess, label: filter, viewType: activeView.view.is2d() ? "2d" : "3d" });
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
const newError = e instanceof Error && e.message.match(/Filter matches more than \d+ items/) ? "tooManyFilterMatches" : "unknownFilterError";
|
|
49
|
+
if (newError !== "tooManyFilterMatches") {
|
|
50
|
+
const feature = e instanceof Error && e.message.includes("query too long to execute or server is too busy") ? "error-timeout" : "error-unknown";
|
|
51
|
+
onFeatureUsed({ featureId: feature, reportInteraction: false });
|
|
52
|
+
}
|
|
53
|
+
setFilteringError(newError);
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}, [filter, activeView, onFeatureUsed]);
|
|
58
|
+
return {
|
|
59
|
+
categoriesTreeProps: {
|
|
60
|
+
treeName: "categories-tree-v2",
|
|
61
|
+
getHierarchyDefinition,
|
|
62
|
+
getFilteredPaths,
|
|
63
|
+
visibilityHandlerFactory,
|
|
64
|
+
noDataMessage: getNoDataMessage(filter, filteringError),
|
|
65
|
+
highlight: filter ? { text: filter } : undefined,
|
|
66
|
+
},
|
|
67
|
+
rendererProps: {
|
|
68
|
+
getIcon,
|
|
69
|
+
getSublabel,
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
exports.useCategoriesTree = useCategoriesTree;
|
|
74
|
+
function getNoDataMessage(filter, error) {
|
|
75
|
+
if (error) {
|
|
76
|
+
return (0, jsx_runtime_1.jsx)(itwinui_react_1.Text, { children: TreeWidget_1.TreeWidget.translate(`categoriesTree.filtering.${error}`) });
|
|
77
|
+
}
|
|
78
|
+
if (filter) {
|
|
79
|
+
return (0, jsx_runtime_1.jsx)(itwinui_react_1.Text, { children: TreeWidget_1.TreeWidget.translate("categoriesTree.filtering.noMatches", { filter }) });
|
|
80
|
+
}
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
function getIcon() {
|
|
84
|
+
return (0, jsx_runtime_1.jsx)(itwinui_icons_react_1.SvgLayers, {});
|
|
85
|
+
}
|
|
86
|
+
function getSublabel(node) {
|
|
87
|
+
return node.extendedData?.description;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=UseCategoriesTree.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UseCategoriesTree.js","sourceRoot":"","sources":["../../../../../src/components/trees/categories-tree/UseCategoriesTree.tsx"],"names":[],"mappings":";;;;AAAA;;;gGAGgG;AAEhG,iCAAuD;AACvD,oEAAuD;AACvD,wDAA4C;AAC5C,oDAAiD;AACjD,uEAAoE;AACpE,yEAAsE;AACtE,+EAA4E;AAgC5E;;;GAGG;AACH,SAAgB,iBAAiB,CAAC,EAAE,MAAM,EAAE,UAAU,EAA0B;IAC9E,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,IAAA,gBAAQ,GAA4C,C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AAK,EAAE;QACT,OAAO,uBAAC,oBAAI,cAAE,uBAAU,CAAC,SAAS,CAAC,4BAA4B,KAAK,EAAE,CAAC,GAAQ,CAAC;KACjF;IACD,IAAI,MAAM,EAAE;QACV,OAAO,uBAAC,oBAAI,cAAE,uBAAU,CAAC,SAAS,CAAC,oCAAoC,EAAE,EAAE,MAAM,EAAE,CAAC,GAAQ,CAAC;KAC9F;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,OAAO;IACd,OAAO,uBAAC,+BAAS,KAAG,CAAC;AACvB,CAAC;AAED,SAAS,WAAW,CAAC,IAA+B;IAClD,OAAO,IAAI,CAAC,YAAY,EAAE,WAAW,CAAC;AACxC,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 { useCallback, useMemo, useState } from \"react\";\nimport { SvgLayers } from \"@itwin/itwinui-icons-react\";\nimport { Text } from \"@itwin/itwinui-react\";\nimport { TreeWidget } from \"../../../TreeWidget\";\nimport { useTelemetryContext } from \"../common/UseTelemetryContext\";\nimport { CategoriesTreeDefinition } from \"./CategoriesTreeDefinition\";\nimport { CategoriesVisibilityHandler } from \"./CategoriesVisibilityHandler\";\n\nimport type { VisibilityTree } from \"../common/components/VisibilityTree\";\nimport type { ComponentPropsWithoutRef } from \"react\";\nimport type { Viewport } from \"@itwin/core-frontend\";\nimport type { HierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport type { PresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport type { VisibilityTreeRenderer } from \"../common/components/VisibilityTreeRenderer\";\n\ntype CategoriesTreeFilteringError = \"tooManyFilterMatches\" | \"unknownFilterError\";\n\n/** @beta */\ntype VisibilityTreeRendererProps = ComponentPropsWithoutRef<typeof VisibilityTreeRenderer>;\n\n/** @beta */\ntype VisibilityTreeProps = ComponentPropsWithoutRef<typeof VisibilityTree>;\n\n/** @beta */\ninterface UseCategoriesTreeProps {\n filter: string;\n activeView: Viewport;\n}\n\n/** @beta */\ninterface UseCategoriesTreeResult {\n categoriesTreeProps: Pick<\n VisibilityTreeProps,\n \"treeName\" | \"getHierarchyDefinition\" | \"getFilteredPaths\" | \"visibilityHandlerFactory\" | \"highlight\" | \"noDataMessage\"\n >;\n rendererProps: Pick<Required<VisibilityTreeRendererProps>, \"getIcon\" | \"getSublabel\">;\n}\n\n/**\n * Custom hook to create and manage state for the categories tree.\n * @beta\n */\nexport function useCategoriesTree({ filter, activeView }: UseCategoriesTreeProps): UseCategoriesTreeResult {\n const [filteringError, setFilteringError] = useState<CategoriesTreeFilteringError | undefined>();\n const visibilityHandlerFactory = useCallback(() => {\n const visibilityHandler = new CategoriesVisibilityHandler({\n viewport: activeView,\n });\n return {\n getVisibilityStatus: async (node: HierarchyNode) => visibilityHandler.getVisibilityStatus(node),\n changeVisibility: async (node: HierarchyNode, on: boolean) => visibilityHandler.changeVisibility(node, on),\n onVisibilityChange: visibilityHandler.onVisibilityChange,\n dispose: () => visibilityHandler.dispose(),\n };\n }, [activeView]);\n const { onFeatureUsed } = useTelemetryContext();\n\n const getHierarchyDefinition = useCallback<VisibilityTreeProps[\"getHierarchyDefinition\"]>(\n (props) => {\n return new CategoriesTreeDefinition({ ...props, viewType: activeView.view.is2d() ? \"2d\" : \"3d\" });\n },\n [activeView],\n );\n\n const getFilteredPaths = useMemo<VisibilityTreeProps[\"getFilteredPaths\"] | undefined>(() => {\n setFilteringError(undefined);\n if (!filter) {\n return undefined;\n }\n return async ({ imodelAccess }) => {\n onFeatureUsed({ featureId: \"filtering\", reportInteraction: true });\n try {\n return await CategoriesTreeDefinition.createInstanceKeyPaths({ imodelAccess, label: filter, viewType: activeView.view.is2d() ? \"2d\" : \"3d\" });\n } catch (e) {\n const newError = e instanceof Error && e.message.match(/Filter matches more than \\d+ items/) ? \"tooManyFilterMatches\" : \"unknownFilterError\";\n if (newError !== \"tooManyFilterMatches\") {\n const feature = e instanceof Error && e.message.includes(\"query too long to execute or server is too busy\") ? \"error-timeout\" : \"error-unknown\";\n onFeatureUsed({ featureId: feature, reportInteraction: false });\n }\n setFilteringError(newError);\n return [];\n }\n };\n }, [filter, activeView, onFeatureUsed]);\n\n return {\n categoriesTreeProps: {\n treeName: \"categories-tree-v2\",\n getHierarchyDefinition,\n getFilteredPaths,\n visibilityHandlerFactory,\n noDataMessage: getNoDataMessage(filter, filteringError),\n highlight: filter ? { text: filter } : undefined,\n },\n rendererProps: {\n getIcon,\n getSublabel,\n },\n };\n}\n\nfunction getNoDataMessage(filter: string, error?: CategoriesTreeFilteringError) {\n if (error) {\n return <Text>{TreeWidget.translate(`categoriesTree.filtering.${error}`)}</Text>;\n }\n if (filter) {\n return <Text>{TreeWidget.translate(\"categoriesTree.filtering.noMatches\", { filter })}</Text>;\n }\n return undefined;\n}\n\nfunction getIcon() {\n return <SvgLayers />;\n}\n\nfunction getSublabel(node: PresentationHierarchyNode) {\n return node.extendedData?.description;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Viewport } from "@itwin/core-frontend";
|
|
2
2
|
/**
|
|
3
3
|
* Data structure that describes category.
|
|
4
4
|
* @beta
|
|
@@ -10,20 +10,20 @@ export interface CategoryInfo {
|
|
|
10
10
|
/**
|
|
11
11
|
* Toggles visibility of categories to show or hide.
|
|
12
12
|
*/
|
|
13
|
-
export declare function toggleAllCategories(
|
|
13
|
+
export declare function toggleAllCategories(viewport: Viewport, display: boolean): Promise<void>;
|
|
14
14
|
/**
|
|
15
15
|
* Gets ids of all categories from specified imodel and viewport.
|
|
16
16
|
*/
|
|
17
|
-
export declare function getCategories(
|
|
17
|
+
export declare function getCategories(viewport: Viewport): Promise<string[]>;
|
|
18
18
|
/**
|
|
19
19
|
* Changes category display in the viewport.
|
|
20
20
|
*/
|
|
21
|
-
export declare function enableCategoryDisplay(
|
|
21
|
+
export declare function enableCategoryDisplay(viewport: Viewport, ids: string[], enabled: boolean, enableAllSubCategories?: boolean): Promise<void>;
|
|
22
22
|
/**
|
|
23
23
|
* Changes subcategory display in the viewport
|
|
24
24
|
*/
|
|
25
|
-
export declare function enableSubCategoryDisplay(
|
|
26
|
-
export declare function loadCategoriesFromViewport(
|
|
25
|
+
export declare function enableSubCategoryDisplay(viewport: Viewport, key: string, enabled: boolean): void;
|
|
26
|
+
export declare function loadCategoriesFromViewport(vp: Viewport): Promise<CategoryInfo[]>;
|
|
27
27
|
/**
|
|
28
28
|
* Enable display of all given categories.
|
|
29
29
|
* @public
|
|
@@ -10,117 +10,71 @@ const core_frontend_1 = require("@itwin/core-frontend");
|
|
|
10
10
|
/**
|
|
11
11
|
* Toggles visibility of categories to show or hide.
|
|
12
12
|
*/
|
|
13
|
-
async function toggleAllCategories(
|
|
14
|
-
|
|
15
|
-
const activeView = viewport ?? viewManager.getFirstOpenView();
|
|
16
|
-
const ids = await getCategories(imodel, activeView);
|
|
17
|
-
// istanbul ignore if
|
|
13
|
+
async function toggleAllCategories(viewport, display) {
|
|
14
|
+
const ids = await getCategories(viewport);
|
|
18
15
|
if (ids.length === 0) {
|
|
19
16
|
return;
|
|
20
17
|
}
|
|
21
|
-
await enableCategoryDisplay(
|
|
18
|
+
await enableCategoryDisplay(viewport, ids, display);
|
|
22
19
|
}
|
|
23
20
|
exports.toggleAllCategories = toggleAllCategories;
|
|
24
21
|
/**
|
|
25
22
|
* Gets ids of all categories from specified imodel and viewport.
|
|
26
23
|
*/
|
|
27
|
-
async function getCategories(
|
|
28
|
-
const categories = await loadCategoriesFromViewport(
|
|
24
|
+
async function getCategories(viewport) {
|
|
25
|
+
const categories = await loadCategoriesFromViewport(viewport);
|
|
29
26
|
return categories.map((category) => category.categoryId);
|
|
30
27
|
}
|
|
31
28
|
exports.getCategories = getCategories;
|
|
32
29
|
/**
|
|
33
30
|
* Changes category display in the viewport.
|
|
34
31
|
*/
|
|
35
|
-
async function enableCategoryDisplay(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
vp.changeCategoryDisplay(ids, enabled, enableAllSubCategories);
|
|
44
|
-
// remove category overrides per model
|
|
45
|
-
const modelsContainingOverrides = [];
|
|
46
|
-
for (const ovr of vp.perModelCategoryVisibility) {
|
|
47
|
-
// istanbul ignore else
|
|
48
|
-
if (ids.findIndex((id) => id === ovr.categoryId) !== -1) {
|
|
49
|
-
modelsContainingOverrides.push(ovr.modelId);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
vp.perModelCategoryVisibility.setOverride(modelsContainingOverrides, ids, core_frontend_1.PerModelCategoryVisibility.Override.None);
|
|
53
|
-
// changeCategoryDisplay only enables subcategories, it does not disabled them. So we must do that ourselves.
|
|
54
|
-
if (false === enabled) {
|
|
55
|
-
(await imodel.categories.getCategoryInfo(ids)).forEach((categoryInfo) => {
|
|
56
|
-
categoryInfo.subCategories.forEach((value) => enableSubCategoryDisplay(viewManager, value.id, false, forAllViewports));
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
// This property let us act on all viewports or just on the selected one, configurable by the app
|
|
62
|
-
if (forAllViewports) {
|
|
63
|
-
for (const viewport of viewManager) {
|
|
64
|
-
await updateViewport(viewport);
|
|
32
|
+
async function enableCategoryDisplay(viewport, ids, enabled, enableAllSubCategories = true) {
|
|
33
|
+
viewport.changeCategoryDisplay(ids, enabled, enableAllSubCategories);
|
|
34
|
+
// remove category overrides per model
|
|
35
|
+
const modelsContainingOverrides = [];
|
|
36
|
+
for (const ovr of viewport.perModelCategoryVisibility) {
|
|
37
|
+
// istanbul ignore else
|
|
38
|
+
if (ids.findIndex((id) => id === ovr.categoryId) !== -1) {
|
|
39
|
+
modelsContainingOverrides.push(ovr.modelId);
|
|
65
40
|
}
|
|
66
41
|
}
|
|
67
|
-
|
|
68
|
-
|
|
42
|
+
viewport.perModelCategoryVisibility.setOverride(modelsContainingOverrides, ids, core_frontend_1.PerModelCategoryVisibility.Override.None);
|
|
43
|
+
// changeCategoryDisplay only enables subcategories, it does not disabled them. So we must do that ourselves.
|
|
44
|
+
if (false === enabled) {
|
|
45
|
+
(await viewport.iModel.categories.getCategoryInfo(ids)).forEach((categoryInfo) => {
|
|
46
|
+
categoryInfo.subCategories.forEach((value) => enableSubCategoryDisplay(viewport, value.id, false));
|
|
47
|
+
});
|
|
69
48
|
}
|
|
70
49
|
}
|
|
71
50
|
exports.enableCategoryDisplay = enableCategoryDisplay;
|
|
72
51
|
/**
|
|
73
52
|
* Changes subcategory display in the viewport
|
|
74
53
|
*/
|
|
75
|
-
function enableSubCategoryDisplay(
|
|
76
|
-
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
const updateViewport = (vp) => {
|
|
80
|
-
// Only act on viewports that are both 3D or both 2D. Important if we have multiple viewports opened and we
|
|
81
|
-
// are using 'allViewports' property
|
|
82
|
-
if (viewManager.selectedView && viewManager.selectedView.view.is3d() === vp.view.is3d()) {
|
|
83
|
-
vp.changeSubCategoryDisplay(key, enabled);
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
// This property let us act on all viewports or just on the selected one, configurable by the app
|
|
87
|
-
if (forAllViewports) {
|
|
88
|
-
for (const viewport of viewManager) {
|
|
89
|
-
updateViewport(viewport);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
updateViewport(viewManager.selectedView);
|
|
94
|
-
}
|
|
54
|
+
function enableSubCategoryDisplay(viewport, key, enabled) {
|
|
55
|
+
viewport.changeSubCategoryDisplay(key, enabled);
|
|
95
56
|
}
|
|
96
57
|
exports.enableSubCategoryDisplay = enableSubCategoryDisplay;
|
|
97
|
-
async function loadCategoriesFromViewport(
|
|
98
|
-
if (!vp) {
|
|
99
|
-
return EMPTY_CATEGORIES_ARRAY;
|
|
100
|
-
}
|
|
58
|
+
async function loadCategoriesFromViewport(vp) {
|
|
101
59
|
// Query categories and add them to state
|
|
102
60
|
const selectUsedSpatialCategoryIds = "SELECT DISTINCT Category.Id as id from BisCore.GeometricElement3d WHERE Category.Id IN (SELECT ECInstanceId from BisCore.SpatialCategory)";
|
|
103
61
|
const selectUsedDrawingCategoryIds = "SELECT DISTINCT Category.Id as id from BisCore.GeometricElement2d WHERE Model.Id=? AND Category.Id IN (SELECT ECInstanceId from BisCore.DrawingCategory)";
|
|
104
62
|
const ecsql = vp.view.is3d() ? selectUsedSpatialCategoryIds : selectUsedDrawingCategoryIds;
|
|
105
63
|
const ecsql2 = `SELECT ECInstanceId as id FROM ${vp.view.is3d() ? "BisCore.SpatialCategory" : "BisCore.DrawingCategory"} WHERE ECInstanceId IN (${ecsql})`;
|
|
106
64
|
const categories = [];
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
categories.push({ categoryId: val.id, subCategoryIds: val.subCategories.size ? [...val.subCategories.keys()] : undefined });
|
|
112
|
-
});
|
|
113
|
-
}
|
|
65
|
+
const rows = await vp.iModel.createQueryReader(ecsql2, undefined, { rowFormat: core_common_1.QueryRowFormat.UseJsPropertyNames }).toArray();
|
|
66
|
+
(await vp.iModel.categories.getCategoryInfo(rows.map((row) => row.id))).forEach((val) => {
|
|
67
|
+
categories.push({ categoryId: val.id, subCategoryIds: val.subCategories.size ? [...val.subCategories.keys()] : undefined });
|
|
68
|
+
});
|
|
114
69
|
return categories;
|
|
115
70
|
}
|
|
116
71
|
exports.loadCategoriesFromViewport = loadCategoriesFromViewport;
|
|
117
|
-
const EMPTY_CATEGORIES_ARRAY = [];
|
|
118
72
|
/**
|
|
119
73
|
* Enable display of all given categories.
|
|
120
74
|
* @public
|
|
121
75
|
*/
|
|
122
76
|
async function showAllCategories(categories, viewport) {
|
|
123
|
-
await enableCategoryDisplay(
|
|
77
|
+
await enableCategoryDisplay(viewport, categories, true, true);
|
|
124
78
|
}
|
|
125
79
|
exports.showAllCategories = showAllCategories;
|
|
126
80
|
/**
|
|
@@ -128,7 +82,7 @@ exports.showAllCategories = showAllCategories;
|
|
|
128
82
|
* @public
|
|
129
83
|
*/
|
|
130
84
|
async function hideAllCategories(categories, viewport) {
|
|
131
|
-
await enableCategoryDisplay(
|
|
85
|
+
await enableCategoryDisplay(viewport, categories, false, true);
|
|
132
86
|
}
|
|
133
87
|
exports.hideAllCategories = hideAllCategories;
|
|
134
88
|
/**
|
|
@@ -156,11 +110,11 @@ async function invertAllCategories(categories, viewport) {
|
|
|
156
110
|
}
|
|
157
111
|
}
|
|
158
112
|
// Disable enabled
|
|
159
|
-
enabledSubCategories.forEach((subCategory) => enableSubCategoryDisplay(
|
|
160
|
-
await enableCategoryDisplay(
|
|
113
|
+
enabledSubCategories.forEach((subCategory) => enableSubCategoryDisplay(viewport, subCategory, false));
|
|
114
|
+
await enableCategoryDisplay(viewport, enabled, false, true);
|
|
161
115
|
// Enable disabled
|
|
162
|
-
disabledSubCategories.forEach((subCategory) => enableSubCategoryDisplay(
|
|
163
|
-
await enableCategoryDisplay(
|
|
116
|
+
disabledSubCategories.forEach((subCategory) => enableSubCategoryDisplay(viewport, subCategory, true));
|
|
117
|
+
await enableCategoryDisplay(viewport, disabled, true, true);
|
|
164
118
|
}
|
|
165
119
|
exports.invertAllCategories = invertAllCategories;
|
|
166
120
|
//# sourceMappingURL=CategoriesVisibilityUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CategoriesVisibilityUtils.js","sourceRoot":"","sources":["../../../../../src/components/trees/common/CategoriesVisibilityUtils.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,oDAAoD;AACpD,wDAA6E;AAa7E;;GAEG;AACI,KAAK,UAAU,mBAAmB,CACvC,WAAwB,EACxB,MAAwB,EACxB,OAAgB,EAChB,QAAmB,EACnB,eAAyB;IAEzB,uBAAuB;IACvB,MAAM,UAAU,GAAG,QAAQ,IAAI,WAAW,CAAC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AI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC,EAAE;YAC/F,KAAK,MAAM,WAAW,IAAI,QAAQ,CAAC,cAAc,EAAE;gBACjD,QAAQ,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;aAC/H;SACF;aAAM;YACL,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;SACnC;KACF;IAED,kBAAkB;IAClB,oBAAoB,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,wBAAwB,CAAC,yBAAS,CAAC,WAAW,EAAE,WAAW,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;IAEzH,MAAM,qBAAqB,CAAC,yBAAS,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAE1F,kBAAkB;IAClB,qBAAqB,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,wBAAwB,CAAC,yBAAS,CAAC,WAAW,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IAEzH,MAAM,qBAAqB,CAAC,yBAAS,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAC5F,CAAC;AA9BD,kDA8BC","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 { QueryRowFormat } from \"@itwin/core-common\";\nimport { IModelApp, PerModelCategoryVisibility } from \"@itwin/core-frontend\";\n\nimport type { IModelConnection, ViewManager, Viewport } from \"@itwin/core-frontend\";\n\n/**\n * Data structure that describes category.\n * @beta\n */\nexport interface CategoryInfo {\n categoryId: string;\n subCategoryIds?: string[];\n}\n\n/**\n * Toggles visibility of categories to show or hide.\n */\nexport async function toggleAllCategories(\n viewManager: ViewManager,\n imodel: IModelConnection,\n display: boolean,\n viewport?: Viewport,\n forAllViewports?: boolean,\n) {\n // istanbul ignore next\n const activeView = viewport ?? viewManager.getFirstOpenView();\n const ids = await getCategories(imodel, activeView);\n\n // istanbul ignore if\n if (ids.length === 0) {\n return;\n }\n\n await enableCategoryDisplay(viewManager, imodel, ids, display, forAllViewports ?? false);\n}\n\n/**\n * Gets ids of all categories from specified imodel and viewport.\n */\nexport async function getCategories(imodel: IModelConnection, viewport?: Viewport) {\n const categories = await loadCategoriesFromViewport(imodel, viewport);\n return categories.map((category) => category.categoryId);\n}\n\n/**\n * Changes category display in the viewport.\n */\nexport async function enableCategoryDisplay(\n viewManager: ViewManager,\n imodel: IModelConnection,\n ids: string[],\n enabled: boolean,\n forAllViewports: boolean,\n enableAllSubCategories = true,\n) {\n if (!viewManager.selectedView) {\n return;\n }\n\n const updateViewport = async (vp: Viewport) => {\n // Only act on viewports that are both 3D or both 2D. Important if we have multiple viewports opened and we\n // are using 'allViewports' property\n if (viewManager.selectedView && viewManager.selectedView.view.is3d() === vp.view.is3d()) {\n vp.changeCategoryDisplay(ids, enabled, enableAllSubCategories);\n\n // remove category overrides per model\n const modelsContainingOverrides: string[] = [];\n for (const ovr of vp.perModelCategoryVisibility) {\n // istanbul ignore else\n if (ids.findIndex((id) => id === ovr.categoryId) !== -1) {\n modelsContainingOverrides.push(ovr.modelId);\n }\n }\n vp.perModelCategoryVisibility.setOverride(modelsContainingOverrides, ids, PerModelCategoryVisibility.Override.None);\n\n // changeCategoryDisplay only enables subcategories, it does not disabled them. So we must do that ourselves.\n if (false === enabled) {\n (await imodel.categories.getCategoryInfo(ids)).forEach((categoryInfo) => {\n categoryInfo.subCategories.forEach((value) => enableSubCategoryDisplay(viewManager, value.id, false, forAllViewports));\n });\n }\n }\n };\n\n // This property let us act on all viewports or just on the selected one, configurable by the app\n if (forAllViewports) {\n for (const viewport of viewManager) {\n await updateViewport(viewport);\n }\n } else {\n await updateViewport(viewManager.selectedView);\n }\n}\n\n/**\n * Changes subcategory display in the viewport\n */\nexport function enableSubCategoryDisplay(viewManager: ViewManager, key: string, enabled: boolean, forAllViewports?: boolean) {\n if (!viewManager.selectedView) {\n return;\n }\n\n const updateViewport = (vp: Viewport) => {\n // Only act on viewports that are both 3D or both 2D. Important if we have multiple viewports opened and we\n // are using 'allViewports' property\n if (viewManager.selectedView && viewManager.selectedView.view.is3d() === vp.view.is3d()) {\n vp.changeSubCategoryDisplay(key, enabled);\n }\n };\n\n // This property let us act on all viewports or just on the selected one, configurable by the app\n if (forAllViewports) {\n for (const viewport of viewManager) {\n updateViewport(viewport);\n }\n } else {\n updateViewport(viewManager.selectedView);\n }\n}\n\nexport async function loadCategoriesFromViewport(iModel?: IModelConnection, vp?: Viewport) {\n if (!vp) {\n return EMPTY_CATEGORIES_ARRAY;\n }\n\n // Query categories and add them to state\n const selectUsedSpatialCategoryIds =\n \"SELECT DISTINCT Category.Id as id from BisCore.GeometricElement3d WHERE Category.Id IN (SELECT ECInstanceId from BisCore.SpatialCategory)\";\n const selectUsedDrawingCategoryIds =\n \"SELECT DISTINCT Category.Id as id from BisCore.GeometricElement2d WHERE Model.Id=? AND Category.Id IN (SELECT ECInstanceId from BisCore.DrawingCategory)\";\n const ecsql = vp.view.is3d() ? selectUsedSpatialCategoryIds : selectUsedDrawingCategoryIds;\n const ecsql2 = `SELECT ECInstanceId as id FROM ${vp.view.is3d() ? \"BisCore.SpatialCategory\" : \"BisCore.DrawingCategory\"} WHERE ECInstanceId IN (${ecsql})`;\n\n const categories: CategoryInfo[] = [];\n\n // istanbul ignore else\n if (iModel) {\n const rows = await iModel.createQueryReader(ecsql2, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames }).toArray();\n (await iModel.categories.getCategoryInfo(rows.map((row) => row.id))).forEach((val) => {\n categories.push({ categoryId: val.id, subCategoryIds: val.subCategories.size ? [...val.subCategories.keys()] : undefined });\n });\n }\n return categories;\n}\nconst EMPTY_CATEGORIES_ARRAY: CategoryInfo[] = [];\n\n/**\n * Enable display of all given categories.\n * @public\n */\nexport async function showAllCategories(categories: string[], viewport: Viewport) {\n await enableCategoryDisplay(IModelApp.viewManager, viewport.iModel, categories, true, true);\n}\n\n/**\n * Disable display of all given categories.\n * @public\n */\nexport async function hideAllCategories(categories: string[], viewport: Viewport) {\n await enableCategoryDisplay(IModelApp.viewManager, viewport.iModel, categories, false, true);\n}\n\n/**\n * Invert display of all given categories.\n * @public\n */\nexport async function invertAllCategories(categories: CategoryInfo[], viewport: Viewport) {\n const enabled: string[] = [];\n const disabled: string[] = [];\n const enabledSubCategories: string[] = [];\n const disabledSubCategories: string[] = [];\n\n for (const category of categories) {\n if (!viewport.view.viewsCategory(category.categoryId)) {\n disabled.push(category.categoryId);\n continue;\n }\n // First, we need to check if at least one subcategory is disabled. If it is true, then only subcategories should change display, not categories.\n if (category.subCategoryIds?.some((subCategory) => !viewport.isSubCategoryVisible(subCategory))) {\n for (const subCategory of category.subCategoryIds) {\n viewport.isSubCategoryVisible(subCategory) ? enabledSubCategories.push(subCategory) : disabledSubCategories.push(subCategory);\n }\n } else {\n enabled.push(category.categoryId);\n }\n }\n\n // Disable enabled\n enabledSubCategories.forEach((subCategory) => enableSubCategoryDisplay(IModelApp.viewManager, subCategory, false, true));\n\n await enableCategoryDisplay(IModelApp.viewManager, viewport.iModel, enabled, false, true);\n\n // Enable disabled\n disabledSubCategories.forEach((subCategory) => enableSubCategoryDisplay(IModelApp.viewManager, subCategory, true, true));\n\n await enableCategoryDisplay(IModelApp.viewManager, viewport.iModel, disabled, true, true);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CategoriesVisibilityUtils.js","sourceRoot":"","sources":["../../../../../src/components/trees/common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J,IAAI,QAAQ,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC,EAAE;YAC/F,KAAK,MAAM,WAAW,IAAI,QAAQ,CAAC,cAAc,EAAE;gBACjD,QAAQ,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;aAC/H;SACF;aAAM;YACL,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;SACnC;KACF;IAED,kBAAkB;IAClB,oBAAoB,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,wBAAwB,CAAC,QAAQ,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;IAEtG,MAAM,qBAAqB,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAE5D,kBAAkB;IAClB,qBAAqB,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,wBAAwB,CAAC,QAAQ,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC;IAEtG,MAAM,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAC9D,CAAC;AA9BD,kDA8BC","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 { QueryRowFormat } from \"@itwin/core-common\";\nimport { PerModelCategoryVisibility } from \"@itwin/core-frontend\";\n\nimport type { Viewport } from \"@itwin/core-frontend\";\n\n/**\n * Data structure that describes category.\n * @beta\n */\nexport interface CategoryInfo {\n categoryId: string;\n subCategoryIds?: string[];\n}\n\n/**\n * Toggles visibility of categories to show or hide.\n */\nexport async function toggleAllCategories(viewport: Viewport, display: boolean) {\n const ids = await getCategories(viewport);\n if (ids.length === 0) {\n return;\n }\n\n await enableCategoryDisplay(viewport, ids, display);\n}\n\n/**\n * Gets ids of all categories from specified imodel and viewport.\n */\nexport async function getCategories(viewport: Viewport) {\n const categories = await loadCategoriesFromViewport(viewport);\n return categories.map((category) => category.categoryId);\n}\n\n/**\n * Changes category display in the viewport.\n */\nexport async function enableCategoryDisplay(viewport: Viewport, ids: string[], enabled: boolean, enableAllSubCategories = true) {\n viewport.changeCategoryDisplay(ids, enabled, enableAllSubCategories);\n\n // remove category overrides per model\n const modelsContainingOverrides: string[] = [];\n for (const ovr of viewport.perModelCategoryVisibility) {\n // istanbul ignore else\n if (ids.findIndex((id) => id === ovr.categoryId) !== -1) {\n modelsContainingOverrides.push(ovr.modelId);\n }\n }\n viewport.perModelCategoryVisibility.setOverride(modelsContainingOverrides, ids, PerModelCategoryVisibility.Override.None);\n\n // changeCategoryDisplay only enables subcategories, it does not disabled them. So we must do that ourselves.\n if (false === enabled) {\n (await viewport.iModel.categories.getCategoryInfo(ids)).forEach((categoryInfo) => {\n categoryInfo.subCategories.forEach((value) => enableSubCategoryDisplay(viewport, value.id, false));\n });\n }\n}\n\n/**\n * Changes subcategory display in the viewport\n */\nexport function enableSubCategoryDisplay(viewport: Viewport, key: string, enabled: boolean) {\n viewport.changeSubCategoryDisplay(key, enabled);\n}\n\nexport async function loadCategoriesFromViewport(vp: Viewport) {\n // Query categories and add them to state\n const selectUsedSpatialCategoryIds =\n \"SELECT DISTINCT Category.Id as id from BisCore.GeometricElement3d WHERE Category.Id IN (SELECT ECInstanceId from BisCore.SpatialCategory)\";\n const selectUsedDrawingCategoryIds =\n \"SELECT DISTINCT Category.Id as id from BisCore.GeometricElement2d WHERE Model.Id=? AND Category.Id IN (SELECT ECInstanceId from BisCore.DrawingCategory)\";\n const ecsql = vp.view.is3d() ? selectUsedSpatialCategoryIds : selectUsedDrawingCategoryIds;\n const ecsql2 = `SELECT ECInstanceId as id FROM ${vp.view.is3d() ? \"BisCore.SpatialCategory\" : \"BisCore.DrawingCategory\"} WHERE ECInstanceId IN (${ecsql})`;\n\n const categories: CategoryInfo[] = [];\n\n const rows = await vp.iModel.createQueryReader(ecsql2, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames }).toArray();\n (await vp.iModel.categories.getCategoryInfo(rows.map((row) => row.id))).forEach((val) => {\n categories.push({ categoryId: val.id, subCategoryIds: val.subCategories.size ? [...val.subCategories.keys()] : undefined });\n });\n return categories;\n}\n\n/**\n * Enable display of all given categories.\n * @public\n */\nexport async function showAllCategories(categories: string[], viewport: Viewport) {\n await enableCategoryDisplay(viewport, categories, true, true);\n}\n\n/**\n * Disable display of all given categories.\n * @public\n */\nexport async function hideAllCategories(categories: string[], viewport: Viewport) {\n await enableCategoryDisplay(viewport, categories, false, true);\n}\n\n/**\n * Invert display of all given categories.\n * @public\n */\nexport async function invertAllCategories(categories: CategoryInfo[], viewport: Viewport) {\n const enabled: string[] = [];\n const disabled: string[] = [];\n const enabledSubCategories: string[] = [];\n const disabledSubCategories: string[] = [];\n\n for (const category of categories) {\n if (!viewport.view.viewsCategory(category.categoryId)) {\n disabled.push(category.categoryId);\n continue;\n }\n // First, we need to check if at least one subcategory is disabled. If it is true, then only subcategories should change display, not categories.\n if (category.subCategoryIds?.some((subCategory) => !viewport.isSubCategoryVisible(subCategory))) {\n for (const subCategory of category.subCategoryIds) {\n viewport.isSubCategoryVisible(subCategory) ? enabledSubCategories.push(subCategory) : disabledSubCategories.push(subCategory);\n }\n } else {\n enabled.push(category.categoryId);\n }\n }\n\n // Disable enabled\n enabledSubCategories.forEach((subCategory) => enableSubCategoryDisplay(viewport, subCategory, false));\n\n await enableCategoryDisplay(viewport, enabled, false, true);\n\n // Enable disabled\n disabledSubCategories.forEach((subCategory) => enableSubCategoryDisplay(viewport, subCategory, true));\n\n await enableCategoryDisplay(viewport, disabled, true, true);\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PropsWithChildren } from "react";
|
|
2
|
-
type TrackedFeatures = "visibility-change" | "hierarchy-level-filtering" | "filtering" | "hierarchy-level-size-limit-hit" | "zoom-to-node";
|
|
2
|
+
type TrackedFeatures = "visibility-change" | "hierarchy-level-filtering" | "filtering" | "hierarchy-level-size-limit-hit" | "zoom-to-node" | "error-timeout" | "error-unknown";
|
|
3
3
|
interface TelemetryContext {
|
|
4
4
|
onPerformanceMeasured: (featureId: string, duration: number) => void;
|
|
5
5
|
onFeatureUsed: (props: {
|