@itwin/tree-widget-react 4.0.0-alpha.3 → 4.0.0-alpha.5
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 +34 -1
- package/README.md +1 -3
- package/lib/esm/tree-widget-react/components/TreeWidgetUiItemsProvider.js +3 -2
- package/lib/esm/tree-widget-react/components/TreeWidgetUiItemsProvider.js.map +1 -1
- package/lib/esm/tree-widget-react/components/tree-header/ErrorState.js +2 -2
- package/lib/esm/tree-widget-react/components/tree-header/ErrorState.js.map +1 -1
- package/lib/esm/tree-widget-react/components/tree-header/SearchBox.js +4 -4
- package/lib/esm/tree-widget-react/components/tree-header/SearchBox.js.map +1 -1
- package/lib/esm/tree-widget-react/components/tree-header/SelectableTree.css +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js +6 -6
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.d.ts +10 -2
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js +246 -129
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js +75 -25
- package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.d.ts +54 -0
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js +280 -0
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.d.ts +26 -0
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.js +23 -0
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/categories-tree/{CategoriesVisibilityHandler.d.ts → internal/CategoriesVisibilityHandler.d.ts} +18 -9
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js +214 -0
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.d.ts +7 -0
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.js +11 -0
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.d.ts +0 -4
- package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/FocusedInstancesContext.d.ts +28 -4
- package/lib/esm/tree-widget-react/components/trees/common/FocusedInstancesContext.js +73 -2
- package/lib/esm/tree-widget-react/components/trees/common/FocusedInstancesContext.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/EmptyTree.css +24 -0
- package/lib/esm/tree-widget-react/components/trees/common/components/EmptyTree.d.ts +21 -0
- package/lib/esm/tree-widget-react/components/trees/common/components/EmptyTree.js +42 -0
- package/lib/esm/tree-widget-react/components/trees/common/components/EmptyTree.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/components/Tree.d.ts +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/Tree.js +6 -7
- package/lib/esm/tree-widget-react/components/trees/common/components/Tree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/TreeNodeVisibilityButton.css +2 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/TreeNodeVisibilityButton.js +6 -6
- package/lib/esm/tree-widget-react/components/trees/common/components/TreeNodeVisibilityButton.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/TreeRenderer.js +3 -2
- package/lib/esm/tree-widget-react/components/trees/common/components/TreeRenderer.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/VisibilityTreeRenderer.js +3 -6
- package/lib/esm/tree-widget-react/components/trees/common/components/VisibilityTreeRenderer.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTree.js +10 -10
- package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js +16 -16
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/index.d.ts +1 -0
- package/lib/esm/tree-widget-react/components/trees/index.js +1 -0
- package/lib/esm/tree-widget-react/components/trees/index.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js +12 -12
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.d.ts +6 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.js +7 -3
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/UseModelsTree.js +22 -33
- package/lib/esm/tree-widget-react/components/trees/models-tree/UseModelsTree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.d.ts +5 -0
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js +45 -0
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.d.ts +2 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js +128 -38
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
- package/lib/public/locales/en/TreeWidget.json +26 -10
- package/package.json +6 -9
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesVisibilityHandler.js +0 -87
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesVisibilityHandler.js.map +0 -1
- package/lib/esm/tree-widget-react/components/trees/common/FocusedInstancesContextProvider.d.ts +0 -7
- package/lib/esm/tree-widget-react/components/trees/common/FocusedInstancesContextProvider.js +0 -66
- package/lib/esm/tree-widget-react/components/trees/common/FocusedInstancesContextProvider.js.map +0 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/EmptyTreeContent.d.ts +0 -7
- package/lib/esm/tree-widget-react/components/trees/common/components/EmptyTreeContent.js +0 -12
- package/lib/esm/tree-widget-react/components/trees/common/components/EmptyTreeContent.js.map +0 -1
|
@@ -4,16 +4,16 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
4
4
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
5
|
*--------------------------------------------------------------------------------------------*/
|
|
6
6
|
import { useEffect, useMemo, useState } from "react";
|
|
7
|
+
import toggle2DSvg from "@itwin/itwinui-icons/2d.svg";
|
|
8
|
+
import toggle3DSvg from "@itwin/itwinui-icons/3d.svg";
|
|
9
|
+
import focusModeSvg from "@itwin/itwinui-icons/cursor-click.svg";
|
|
10
|
+
import visibilityHideSvg from "@itwin/itwinui-icons/visibility-hide.svg";
|
|
11
|
+
import visibilityShowSvg from "@itwin/itwinui-icons/visibility-show.svg";
|
|
12
|
+
import visibilityInvertSvg from "@itwin/itwinui-icons/visibilty-invert.svg";
|
|
7
13
|
import { IconButton } from "@itwin/itwinui-react/bricks";
|
|
8
14
|
import { TreeWidget } from "../../../TreeWidget.js";
|
|
9
15
|
import { useFocusedInstancesContext } from "../common/FocusedInstancesContext.js";
|
|
10
16
|
import { areAllModelsVisible, hideAllModels, invertAllModels, showAllModels, toggleModels } from "./internal/ModelsTreeVisibilityHandler.js";
|
|
11
|
-
const visibilityShowIcon = new URL("@itwin/itwinui-icons/visibility-show.svg", import.meta.url).href;
|
|
12
|
-
const visibilityHideIcon = new URL("@itwin/itwinui-icons/visibility-hide.svg", import.meta.url).href;
|
|
13
|
-
const visibilityInvertIcon = new URL("@itwin/itwinui-icons/visibilty-invert.svg", import.meta.url).href;
|
|
14
|
-
const focusModeIcon = new URL("@itwin/itwinui-icons/cursor-click.svg", import.meta.url).href;
|
|
15
|
-
const toggle3DIcon = new URL("@itwin/itwinui-icons/3d.svg", import.meta.url).href;
|
|
16
|
-
const toggle2DIcon = new URL("@itwin/itwinui-icons/2d.svg", import.meta.url).href;
|
|
17
17
|
/**
|
|
18
18
|
* Custom hook that creates props required to render `ModelsTreeComponent` header button.
|
|
19
19
|
*
|
|
@@ -79,21 +79,21 @@ export function ShowAllButton(props) {
|
|
|
79
79
|
return (_jsx(IconButton, { variant: "ghost", label: TreeWidget.translate("modelsTree.buttons.showAll.tooltip"), onClick: () => {
|
|
80
80
|
props.onFeatureUsed?.("models-tree-showall");
|
|
81
81
|
void showAllModels(props.models.map((model) => model.id), props.viewport);
|
|
82
|
-
}, icon:
|
|
82
|
+
}, icon: visibilityShowSvg }));
|
|
83
83
|
}
|
|
84
84
|
/** @public */
|
|
85
85
|
export function HideAllButton(props) {
|
|
86
86
|
return (_jsx(IconButton, { variant: "ghost", label: TreeWidget.translate("modelsTree.buttons.hideAll.tooltip"), onClick: () => {
|
|
87
87
|
props.onFeatureUsed?.("models-tree-hideall");
|
|
88
88
|
void hideAllModels(props.models.map((model) => model.id), props.viewport);
|
|
89
|
-
}, icon:
|
|
89
|
+
}, icon: visibilityHideSvg }));
|
|
90
90
|
}
|
|
91
91
|
/** @public */
|
|
92
92
|
export function InvertButton(props) {
|
|
93
93
|
return (_jsx(IconButton, { variant: "ghost", label: TreeWidget.translate("modelsTree.buttons.invert.tooltip"), onClick: () => {
|
|
94
94
|
props.onFeatureUsed?.("models-tree-invert");
|
|
95
95
|
void invertAllModels(props.models.map((model) => model.id), props.viewport);
|
|
96
|
-
}, icon:
|
|
96
|
+
}, icon: visibilityInvertSvg }));
|
|
97
97
|
}
|
|
98
98
|
/** @public */
|
|
99
99
|
export function View2DButton(props) {
|
|
@@ -108,7 +108,7 @@ export function View2DButton(props) {
|
|
|
108
108
|
return (_jsx(IconButton, { variant: "ghost", label: TreeWidget.translate("modelsTree.buttons.toggle2d.tooltip"), onClick: () => {
|
|
109
109
|
props.onFeatureUsed?.("models-tree-view2d");
|
|
110
110
|
void toggleModels(models2d, is2dToggleActive, props.viewport);
|
|
111
|
-
}, "aria-disabled": models2d.length === 0, isActive: is2dToggleActive, icon:
|
|
111
|
+
}, "aria-disabled": models2d.length === 0, isActive: is2dToggleActive, icon: toggle2DSvg }));
|
|
112
112
|
}
|
|
113
113
|
/** @public */
|
|
114
114
|
export function View3DButton(props) {
|
|
@@ -123,7 +123,7 @@ export function View3DButton(props) {
|
|
|
123
123
|
return (_jsx(IconButton, { variant: "ghost", label: TreeWidget.translate("modelsTree.buttons.toggle3d.tooltip"), onClick: () => {
|
|
124
124
|
props.onFeatureUsed?.("models-tree-view3d");
|
|
125
125
|
void toggleModels(models3d, is3dToggleActive, props.viewport);
|
|
126
|
-
}, "aria-disabled": models3d.length === 0, isActive: is3dToggleActive, icon:
|
|
126
|
+
}, "aria-disabled": models3d.length === 0, isActive: is3dToggleActive, icon: toggle3DSvg }));
|
|
127
127
|
}
|
|
128
128
|
/** @public */
|
|
129
129
|
export function ToggleInstancesFocusButton({ onFeatureUsed, disabled }) {
|
|
@@ -136,6 +136,6 @@ export function ToggleInstancesFocusButton({ onFeatureUsed, disabled }) {
|
|
|
136
136
|
return (_jsx(IconButton, { variant: "ghost", label: label, onClick: () => {
|
|
137
137
|
onFeatureUsed?.("models-tree-instancesfocus");
|
|
138
138
|
toggle();
|
|
139
|
-
}, "aria-disabled": disabled, isActive: enabled, icon:
|
|
139
|
+
}, "aria-disabled": disabled, isActive: enabled, icon: focusModeSvg }));
|
|
140
140
|
}
|
|
141
141
|
//# sourceMappingURL=ModelsTreeButtons.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelsTreeButtons.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAClF,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,2CAA2C,CAAC;AAO7I,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,0CAA0C,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;AACrG,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,0CAA0C,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;AACrG,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC,2CAA2C,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;AACxG,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,uCAAuC,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;AAC7F,MAAM,YAAY,GAAG,IAAI,GAAG,CA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AAC;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 { useEffect, useMemo, useState } from \"react\";\nimport { IconButton } from \"@itwin/itwinui-react/bricks\";\nimport { TreeWidget } from \"../../../TreeWidget.js\";\nimport { useFocusedInstancesContext } from \"../common/FocusedInstancesContext.js\";\nimport { areAllModelsVisible, hideAllModels, invertAllModels, showAllModels, toggleModels } from \"./internal/ModelsTreeVisibilityHandler.js\";\n\nimport type { Id64String } from \"@itwin/core-bentley\";\nimport type { GeometricModel3dProps, ModelQueryParams } from \"@itwin/core-common\";\nimport type { IModelConnection, Viewport } from \"@itwin/core-frontend\";\nimport type { TreeToolbarButtonProps } from \"../../tree-header/SelectableTree.js\";\n\nconst visibilityShowIcon = new URL(\"@itwin/itwinui-icons/visibility-show.svg\", import.meta.url).href;\nconst visibilityHideIcon = new URL(\"@itwin/itwinui-icons/visibility-hide.svg\", import.meta.url).href;\nconst visibilityInvertIcon = new URL(\"@itwin/itwinui-icons/visibilty-invert.svg\", import.meta.url).href;\nconst focusModeIcon = new URL(\"@itwin/itwinui-icons/cursor-click.svg\", import.meta.url).href;\nconst toggle3DIcon = new URL(\"@itwin/itwinui-icons/3d.svg\", import.meta.url).href;\nconst toggle2DIcon = new URL(\"@itwin/itwinui-icons/2d.svg\", import.meta.url).href;\n\n/**\n * Information about a single Model.\n * @public\n */\nexport interface ModelInfo {\n id: string;\n isPlanProjection?: boolean;\n}\n\n/**\n * Props that get passed to `ModelsTreeComponent` header button renderer.\n * @see ModelTreeComponentProps.headerButtons\n * @public\n */\nexport interface ModelsTreeHeaderButtonProps extends TreeToolbarButtonProps {\n /** A list of models available in the iModel. */\n models: ModelInfo[];\n}\n\n/**\n * Custom hook that creates props required to render `ModelsTreeComponent` header button.\n *\n * Example:\n * ```tsx\n * const { buttonProps, onModelsFiltered } = useModelsTreeButtonProps({ imodel, viewport });\n * <TreeWithHeader\n * buttons={[\n * <ModelsTreeComponent.ShowAllButton {...buttonProps} />,\n * <ModelsTreeComponent.HideAllButton {...buttonProps} />,\n * ]}\n * >\n * <ModelsTree {...treeProps} onModelsFiltered={onModelsFiltered} />\n * </TreeWithHeader>\n * ```\n *\n *\n * @public\n */\nexport function useModelsTreeButtonProps({ imodel, viewport }: { imodel: IModelConnection; viewport: Viewport }): {\n buttonProps: Pick<ModelsTreeHeaderButtonProps, \"models\" | \"viewport\">;\n onModelsFiltered: (models: Id64String[] | undefined) => void;\n} {\n const [filteredModels, setFilteredModels] = useState<Id64String[] | undefined>();\n const models = useAvailableModels(imodel);\n const availableModels = useMemo(() => (!filteredModels ? models : models.filter((model) => filteredModels.includes(model.id))), [models, filteredModels]);\n return {\n buttonProps: {\n models: availableModels,\n viewport,\n },\n onModelsFiltered: setFilteredModels,\n };\n}\n\nfunction useAvailableModels(imodel: IModelConnection): ModelInfo[] {\n const [availableModels, setAvailableModels] = useState<ModelInfo[]>([]);\n\n useEffect(() => {\n queryModelsForHeaderActions(imodel)\n .then((modelInfos: ModelInfo[]) => {\n setAvailableModels(modelInfos);\n })\n .catch(() => {\n setAvailableModels([]);\n });\n }, [imodel]);\n\n return availableModels;\n}\n\nasync function queryModelsForHeaderActions(iModel: IModelConnection) {\n const queryParams: ModelQueryParams = {\n from: \"BisCore.GeometricModel3d\",\n where: `\n EXISTS (\n SELECT 1\n FROM BisCore.Element e\n WHERE e.ECClassId IS (BisCore.GeometricElement3d, BisCore.InformationPartitionElement)\n AND e.ECInstanceId = GeometricModel3d.ModeledElement.Id\n )\n `,\n wantPrivate: false,\n };\n\n const modelProps = await iModel.models.queryProps(queryParams);\n return modelProps.map(({ id, isPlanProjection }: GeometricModel3dProps) => ({ id, isPlanProjection })).filter(({ id }) => id) as ModelInfo[];\n}\n\n/** @public */\nexport type ModelsTreeHeaderButtonType = (props: ModelsTreeHeaderButtonProps) => React.ReactElement | null;\n\n/** @public */\nexport function ShowAllButton(props: ModelsTreeHeaderButtonProps) {\n return (\n <IconButton\n variant={\"ghost\"}\n label={TreeWidget.translate(\"modelsTree.buttons.showAll.tooltip\")}\n onClick={() => {\n props.onFeatureUsed?.(\"models-tree-showall\");\n void showAllModels(\n props.models.map((model) => model.id),\n props.viewport,\n );\n }}\n icon={visibilityShowIcon}\n />\n );\n}\n\n/** @public */\nexport function HideAllButton(props: ModelsTreeHeaderButtonProps) {\n return (\n <IconButton\n variant={\"ghost\"}\n label={TreeWidget.translate(\"modelsTree.buttons.hideAll.tooltip\")}\n onClick={() => {\n props.onFeatureUsed?.(\"models-tree-hideall\");\n void hideAllModels(\n props.models.map((model) => model.id),\n props.viewport,\n );\n }}\n icon={visibilityHideIcon}\n />\n );\n}\n\n/** @public */\nexport function InvertButton(props: ModelsTreeHeaderButtonProps) {\n return (\n <IconButton\n variant={\"ghost\"}\n label={TreeWidget.translate(\"modelsTree.buttons.invert.tooltip\")}\n onClick={() => {\n props.onFeatureUsed?.(\"models-tree-invert\");\n void invertAllModels(\n props.models.map((model) => model.id),\n props.viewport,\n );\n }}\n icon={visibilityInvertIcon}\n />\n );\n}\n\n/** @public */\nexport function View2DButton(props: ModelsTreeHeaderButtonProps) {\n const models2d = useMemo(() => {\n return props.models.filter((model) => model.isPlanProjection).map((model) => model.id);\n }, [props.models]);\n\n const [is2dToggleActive, setIs2dToggleActive] = useState(false);\n\n useEffect(() => {\n setIs2dToggleActive(areAllModelsVisible(models2d, props.viewport));\n return props.viewport.onViewedModelsChanged.addListener((vp: Viewport) => setIs2dToggleActive(areAllModelsVisible(models2d, vp)));\n }, [models2d, props.viewport]);\n\n return (\n <IconButton\n variant={\"ghost\"}\n label={TreeWidget.translate(\"modelsTree.buttons.toggle2d.tooltip\")}\n onClick={() => {\n props.onFeatureUsed?.(\"models-tree-view2d\");\n void toggleModels(models2d, is2dToggleActive, props.viewport);\n }}\n aria-disabled={models2d.length === 0}\n isActive={is2dToggleActive}\n icon={toggle2DIcon}\n />\n );\n}\n\n/** @public */\nexport function View3DButton(props: ModelsTreeHeaderButtonProps) {\n const models3d = useMemo(() => {\n return props.models.filter((model) => !model.isPlanProjection).map((model) => model.id);\n }, [props.models]);\n\n const [is3dToggleActive, setIs3dToggleActive] = useState(false);\n\n useEffect(() => {\n setIs3dToggleActive(areAllModelsVisible(models3d, props.viewport));\n return props.viewport.onViewedModelsChanged.addListener((vp: Viewport) => setIs3dToggleActive(areAllModelsVisible(models3d, vp)));\n }, [models3d, props.viewport]);\n\n return (\n <IconButton\n variant={\"ghost\"}\n label={TreeWidget.translate(\"modelsTree.buttons.toggle3d.tooltip\")}\n onClick={() => {\n props.onFeatureUsed?.(\"models-tree-view3d\");\n void toggleModels(models3d, is3dToggleActive, props.viewport);\n }}\n aria-disabled={models3d.length === 0}\n isActive={is3dToggleActive}\n icon={toggle3DIcon}\n />\n );\n}\n\n/** @public */\nexport function ToggleInstancesFocusButton({ onFeatureUsed, disabled }: { onFeatureUsed?: (feature: string) => void; disabled?: boolean }) {\n const { enabled, toggle } = useFocusedInstancesContext();\n const label = disabled\n ? TreeWidget.translate(\"modelsTree.buttons.toggleFocusMode.disabled.tooltip\")\n : enabled\n ? TreeWidget.translate(\"modelsTree.buttons.toggleFocusMode.disable.tooltip\")\n : TreeWidget.translate(\"modelsTree.buttons.toggleFocusMode.enable.tooltip\");\n return (\n <IconButton\n variant={\"ghost\"}\n label={label}\n onClick={() => {\n onFeatureUsed?.(\"models-tree-instancesfocus\");\n toggle();\n }}\n aria-disabled={disabled}\n isActive={enabled}\n icon={focusModeIcon}\n />\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ModelsTreeButtons.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,WAAW,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AAS,CAAC,mDAAmD,CAAC,CAAC;IAChF,OAAO,CACL,KAAC,UAAU,IACT,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,GAAG,EAAE;YACZ,aAAa,EAAE,CAAC,4BAA4B,CAAC,CAAC;YAC9C,MAAM,EAAE,CAAC;QACX,CAAC,mBACc,QAAQ,EACvB,QAAQ,EAAE,OAAO,EACjB,IAAI,EAAE,YAAY,GAClB,CACH,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useEffect, useMemo, useState } from \"react\";\nimport toggle2DSvg from \"@itwin/itwinui-icons/2d.svg\";\nimport toggle3DSvg from \"@itwin/itwinui-icons/3d.svg\";\nimport focusModeSvg from \"@itwin/itwinui-icons/cursor-click.svg\";\nimport visibilityHideSvg from \"@itwin/itwinui-icons/visibility-hide.svg\";\nimport visibilityShowSvg from \"@itwin/itwinui-icons/visibility-show.svg\";\nimport visibilityInvertSvg from \"@itwin/itwinui-icons/visibilty-invert.svg\";\nimport { IconButton } from \"@itwin/itwinui-react/bricks\";\nimport { TreeWidget } from \"../../../TreeWidget.js\";\nimport { useFocusedInstancesContext } from \"../common/FocusedInstancesContext.js\";\nimport { areAllModelsVisible, hideAllModels, invertAllModels, showAllModels, toggleModels } from \"./internal/ModelsTreeVisibilityHandler.js\";\n\nimport type { Id64String } from \"@itwin/core-bentley\";\nimport type { GeometricModel3dProps, ModelQueryParams } from \"@itwin/core-common\";\nimport type { IModelConnection, Viewport } from \"@itwin/core-frontend\";\nimport type { TreeToolbarButtonProps } from \"../../tree-header/SelectableTree.js\";\n\n/**\n * Information about a single Model.\n * @public\n */\nexport interface ModelInfo {\n id: string;\n isPlanProjection?: boolean;\n}\n\n/**\n * Props that get passed to `ModelsTreeComponent` header button renderer.\n * @see ModelTreeComponentProps.headerButtons\n * @public\n */\nexport interface ModelsTreeHeaderButtonProps extends TreeToolbarButtonProps {\n /** A list of models available in the iModel. */\n models: ModelInfo[];\n}\n\n/**\n * Custom hook that creates props required to render `ModelsTreeComponent` header button.\n *\n * Example:\n * ```tsx\n * const { buttonProps, onModelsFiltered } = useModelsTreeButtonProps({ imodel, viewport });\n * <TreeWithHeader\n * buttons={[\n * <ModelsTreeComponent.ShowAllButton {...buttonProps} />,\n * <ModelsTreeComponent.HideAllButton {...buttonProps} />,\n * ]}\n * >\n * <ModelsTree {...treeProps} onModelsFiltered={onModelsFiltered} />\n * </TreeWithHeader>\n * ```\n *\n *\n * @public\n */\nexport function useModelsTreeButtonProps({ imodel, viewport }: { imodel: IModelConnection; viewport: Viewport }): {\n buttonProps: Pick<ModelsTreeHeaderButtonProps, \"models\" | \"viewport\">;\n onModelsFiltered: (models: Id64String[] | undefined) => void;\n} {\n const [filteredModels, setFilteredModels] = useState<Id64String[] | undefined>();\n const models = useAvailableModels(imodel);\n const availableModels = useMemo(() => (!filteredModels ? models : models.filter((model) => filteredModels.includes(model.id))), [models, filteredModels]);\n return {\n buttonProps: {\n models: availableModels,\n viewport,\n },\n onModelsFiltered: setFilteredModels,\n };\n}\n\nfunction useAvailableModels(imodel: IModelConnection): ModelInfo[] {\n const [availableModels, setAvailableModels] = useState<ModelInfo[]>([]);\n\n useEffect(() => {\n queryModelsForHeaderActions(imodel)\n .then((modelInfos: ModelInfo[]) => {\n setAvailableModels(modelInfos);\n })\n .catch(() => {\n setAvailableModels([]);\n });\n }, [imodel]);\n\n return availableModels;\n}\n\nasync function queryModelsForHeaderActions(iModel: IModelConnection) {\n const queryParams: ModelQueryParams = {\n from: \"BisCore.GeometricModel3d\",\n where: `\n EXISTS (\n SELECT 1\n FROM BisCore.Element e\n WHERE e.ECClassId IS (BisCore.GeometricElement3d, BisCore.InformationPartitionElement)\n AND e.ECInstanceId = GeometricModel3d.ModeledElement.Id\n )\n `,\n wantPrivate: false,\n };\n\n const modelProps = await iModel.models.queryProps(queryParams);\n return modelProps.map(({ id, isPlanProjection }: GeometricModel3dProps) => ({ id, isPlanProjection })).filter(({ id }) => id) as ModelInfo[];\n}\n\n/** @public */\nexport type ModelsTreeHeaderButtonType = (props: ModelsTreeHeaderButtonProps) => React.ReactElement | null;\n\n/** @public */\nexport function ShowAllButton(props: ModelsTreeHeaderButtonProps) {\n return (\n <IconButton\n variant={\"ghost\"}\n label={TreeWidget.translate(\"modelsTree.buttons.showAll.tooltip\")}\n onClick={() => {\n props.onFeatureUsed?.(\"models-tree-showall\");\n void showAllModels(\n props.models.map((model) => model.id),\n props.viewport,\n );\n }}\n icon={visibilityShowSvg}\n />\n );\n}\n\n/** @public */\nexport function HideAllButton(props: ModelsTreeHeaderButtonProps) {\n return (\n <IconButton\n variant={\"ghost\"}\n label={TreeWidget.translate(\"modelsTree.buttons.hideAll.tooltip\")}\n onClick={() => {\n props.onFeatureUsed?.(\"models-tree-hideall\");\n void hideAllModels(\n props.models.map((model) => model.id),\n props.viewport,\n );\n }}\n icon={visibilityHideSvg}\n />\n );\n}\n\n/** @public */\nexport function InvertButton(props: ModelsTreeHeaderButtonProps) {\n return (\n <IconButton\n variant={\"ghost\"}\n label={TreeWidget.translate(\"modelsTree.buttons.invert.tooltip\")}\n onClick={() => {\n props.onFeatureUsed?.(\"models-tree-invert\");\n void invertAllModels(\n props.models.map((model) => model.id),\n props.viewport,\n );\n }}\n icon={visibilityInvertSvg}\n />\n );\n}\n\n/** @public */\nexport function View2DButton(props: ModelsTreeHeaderButtonProps) {\n const models2d = useMemo(() => {\n return props.models.filter((model) => model.isPlanProjection).map((model) => model.id);\n }, [props.models]);\n\n const [is2dToggleActive, setIs2dToggleActive] = useState(false);\n\n useEffect(() => {\n setIs2dToggleActive(areAllModelsVisible(models2d, props.viewport));\n return props.viewport.onViewedModelsChanged.addListener((vp: Viewport) => setIs2dToggleActive(areAllModelsVisible(models2d, vp)));\n }, [models2d, props.viewport]);\n\n return (\n <IconButton\n variant={\"ghost\"}\n label={TreeWidget.translate(\"modelsTree.buttons.toggle2d.tooltip\")}\n onClick={() => {\n props.onFeatureUsed?.(\"models-tree-view2d\");\n void toggleModels(models2d, is2dToggleActive, props.viewport);\n }}\n aria-disabled={models2d.length === 0}\n isActive={is2dToggleActive}\n icon={toggle2DSvg}\n />\n );\n}\n\n/** @public */\nexport function View3DButton(props: ModelsTreeHeaderButtonProps) {\n const models3d = useMemo(() => {\n return props.models.filter((model) => !model.isPlanProjection).map((model) => model.id);\n }, [props.models]);\n\n const [is3dToggleActive, setIs3dToggleActive] = useState(false);\n\n useEffect(() => {\n setIs3dToggleActive(areAllModelsVisible(models3d, props.viewport));\n return props.viewport.onViewedModelsChanged.addListener((vp: Viewport) => setIs3dToggleActive(areAllModelsVisible(models3d, vp)));\n }, [models3d, props.viewport]);\n\n return (\n <IconButton\n variant={\"ghost\"}\n label={TreeWidget.translate(\"modelsTree.buttons.toggle3d.tooltip\")}\n onClick={() => {\n props.onFeatureUsed?.(\"models-tree-view3d\");\n void toggleModels(models3d, is3dToggleActive, props.viewport);\n }}\n aria-disabled={models3d.length === 0}\n isActive={is3dToggleActive}\n icon={toggle3DSvg}\n />\n );\n}\n\n/** @public */\nexport function ToggleInstancesFocusButton({ onFeatureUsed, disabled }: { onFeatureUsed?: (feature: string) => void; disabled?: boolean }) {\n const { enabled, toggle } = useFocusedInstancesContext();\n const label = disabled\n ? TreeWidget.translate(\"modelsTree.buttons.toggleFocusMode.disabled.tooltip\")\n : enabled\n ? TreeWidget.translate(\"modelsTree.buttons.toggleFocusMode.disable.tooltip\")\n : TreeWidget.translate(\"modelsTree.buttons.toggleFocusMode.enable.tooltip\");\n return (\n <IconButton\n variant={\"ghost\"}\n label={label}\n onClick={() => {\n onFeatureUsed?.(\"models-tree-instancesfocus\");\n toggle();\n }}\n aria-disabled={disabled}\n isActive={enabled}\n icon={focusModeSvg}\n />\n );\n}\n"]}
|
|
@@ -54,7 +54,12 @@ export declare const ModelsTreeComponent: {
|
|
|
54
54
|
*/
|
|
55
55
|
View3DButton: ModelsTreeHeaderButtonType;
|
|
56
56
|
/**
|
|
57
|
-
* Renders
|
|
57
|
+
* Renders an "Instance focus" toggle button that enables/disables instances focusing mode.
|
|
58
|
+
*
|
|
59
|
+
* Requires instances focus context to be provided using `FocusedInstancesContextProvider`. The context
|
|
60
|
+
* is provided automatically, when using `ModelsTreeComponent`, but needs to be provided by consumers
|
|
61
|
+
* when rendering `ToggleInstancesFocusButton` outside of `ModelsTreeComponent`.
|
|
62
|
+
*
|
|
58
63
|
* @public
|
|
59
64
|
*/
|
|
60
65
|
ToggleInstancesFocusButton: ModelsTreeHeaderButtonType;
|
|
@@ -8,8 +8,7 @@ import { Fragment, useEffect } from "react";
|
|
|
8
8
|
import { useActiveIModelConnection } from "@itwin/appui-react";
|
|
9
9
|
import { TreeWidget } from "../../../TreeWidget.js";
|
|
10
10
|
import { SelectableTree } from "../../tree-header/SelectableTree.js";
|
|
11
|
-
import { useFocusedInstancesContext } from "../common/FocusedInstancesContext.js";
|
|
12
|
-
import { FocusedInstancesContextProvider } from "../common/FocusedInstancesContextProvider.js";
|
|
11
|
+
import { FocusedInstancesContextProvider, useFocusedInstancesContext } from "../common/FocusedInstancesContext.js";
|
|
13
12
|
import { useActiveViewport } from "../common/UseActiveViewport.js";
|
|
14
13
|
import { TelemetryContextProvider } from "../common/UseTelemetryContext.js";
|
|
15
14
|
import { ModelsTree } from "./ModelsTree.js";
|
|
@@ -54,7 +53,12 @@ ModelsTreeComponent.View2DButton = View2DButton;
|
|
|
54
53
|
*/
|
|
55
54
|
ModelsTreeComponent.View3DButton = View3DButton;
|
|
56
55
|
/**
|
|
57
|
-
* Renders
|
|
56
|
+
* Renders an "Instance focus" toggle button that enables/disables instances focusing mode.
|
|
57
|
+
*
|
|
58
|
+
* Requires instances focus context to be provided using `FocusedInstancesContextProvider`. The context
|
|
59
|
+
* is provided automatically, when using `ModelsTreeComponent`, but needs to be provided by consumers
|
|
60
|
+
* when rendering `ToggleInstancesFocusButton` outside of `ModelsTreeComponent`.
|
|
61
|
+
*
|
|
58
62
|
* @public
|
|
59
63
|
*/
|
|
60
64
|
ModelsTreeComponent.ToggleInstancesFocusButton = ToggleInstancesFocusButton;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelsTreeComponent.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.tsx"],"names":[],"mappings":";;AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,EAAE
|
|
1
|
+
{"version":3,"file":"ModelsTreeComponent.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.tsx"],"names":[],"mappings":";;AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,EAAE,+BAA+B,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AACnH,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EACL,aAAa,EACb,YAAY,EACZ,aAAa,EACb,0BAA0B,EAC1B,wBAAwB,EACxB,YAAY,EACZ,Y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BAAqB,EAAE,qBAAqB,YAC/I,KAAC,cAAc,IAAC,OAAO,EAAE,OAAO,YAC9B,KAAC,UAAU,OAAK,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,gBAAgB,GAAI,GACxG,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, useEffect } from \"react\";\nimport { useActiveIModelConnection } from \"@itwin/appui-react\";\nimport { TreeWidget } from \"../../../TreeWidget.js\";\nimport { SelectableTree } from \"../../tree-header/SelectableTree.js\";\nimport { FocusedInstancesContextProvider, useFocusedInstancesContext } from \"../common/FocusedInstancesContext.js\";\nimport { useActiveViewport } from \"../common/UseActiveViewport.js\";\nimport { TelemetryContextProvider } from \"../common/UseTelemetryContext.js\";\nimport { ModelsTree } from \"./ModelsTree.js\";\nimport {\n HideAllButton,\n InvertButton,\n ShowAllButton,\n ToggleInstancesFocusButton,\n useModelsTreeButtonProps,\n View2DButton,\n View3DButton,\n} from \"./ModelsTreeButtons.js\";\n\nimport type { ModelsTreeProps } from \"./ModelsTree.js\";\nimport type { ReactNode } from \"react\";\nimport type { IModelConnection, ScreenViewport } from \"@itwin/core-frontend\";\nimport type { ModelsTreeHeaderButtonProps, ModelsTreeHeaderButtonType } from \"./ModelsTreeButtons.js\";\n\n/** @public */\ninterface ModelsTreeComponentProps\n extends Pick<\n ModelsTreeProps,\n | \"getSchemaContext\"\n | \"selectionStorage\"\n | \"hierarchyLevelConfig\"\n | \"selectionMode\"\n | \"selectionPredicate\"\n | \"hierarchyConfig\"\n | \"visibilityHandlerOverrides\"\n | \"getFilteredPaths\"\n | \"filter\"\n | \"emptyTreeContent\"\n | \"actions\"\n > {\n /**\n * Renderers of header buttons. Defaults to:\n * ```ts\n * [\n * ModelsTreeComponent.ShowAllButton,\n * ModelsTreeComponent.HideAllButton,\n * ModelsTreeComponent.InvertButton,\n * ModelsTreeComponent.View2DButton,\n * ModelsTreeComponent.View3DButton,\n * ModelsTreeComponent.ToggleInstancesFocusButton,\n * ]\n * ```\n */\n headerButtons?: Array<(props: ModelsTreeHeaderButtonProps) => React.ReactNode>;\n onPerformanceMeasured?: (featureId: string, duration: number) => void;\n onFeatureUsed?: (feature: string) => void;\n}\n\n/**\n * A component that renders `ModelsTree` and a header with filtering capabilities\n * and header buttons.\n *\n * @public\n */\nexport const ModelsTreeComponent = (props: ModelsTreeComponentProps) => {\n const iModel = useActiveIModelConnection();\n const viewport = useActiveViewport();\n\n if (!iModel || !viewport) {\n return null;\n }\n\n return (\n <FocusedInstancesContextProvider selectionStorage={props.selectionStorage} imodelKey={iModel.key}>\n <ModelsTreeComponentImpl {...props} iModel={iModel} viewport={viewport} />\n </FocusedInstancesContextProvider>\n );\n};\n\n/**\n * Renders a \"Show all\" button that enables display of all models.\n * @public\n */\nModelsTreeComponent.ShowAllButton = ShowAllButton as ModelsTreeHeaderButtonType;\n\n/**\n * Renders a \"Hide all\" button that disables display of all models.\n * @public\n */\nModelsTreeComponent.HideAllButton = HideAllButton as ModelsTreeHeaderButtonType;\n\n/**\n * Renders an \"Invert all\" button that inverts display of all models.\n * @public\n */\nModelsTreeComponent.InvertButton = InvertButton as ModelsTreeHeaderButtonType;\n\n/**\n * Renders a \"View 2D\" button that enables display of all plan projection models and disables all others.\n * @public\n */\nModelsTreeComponent.View2DButton = View2DButton as ModelsTreeHeaderButtonType;\n\n/**\n * Renders a \"View 3D\" button that enables display of all non-plan projection models and disables all plan projection ones.\n * @public\n */\nModelsTreeComponent.View3DButton = View3DButton as ModelsTreeHeaderButtonType;\n\n/**\n * Renders an \"Instance focus\" toggle button that enables/disables instances focusing mode.\n *\n * Requires instances focus context to be provided using `FocusedInstancesContextProvider`. The context\n * is provided automatically, when using `ModelsTreeComponent`, but needs to be provided by consumers\n * when rendering `ToggleInstancesFocusButton` outside of `ModelsTreeComponent`.\n *\n * @public\n */\nModelsTreeComponent.ToggleInstancesFocusButton = ToggleInstancesFocusButton as ModelsTreeHeaderButtonType;\n\n/**\n * Id of the component. May be used when a creating a `TreeDefinition` for `SelectableTree`.\n * @public\n */\nModelsTreeComponent.id = \"models-tree-v2\";\n\n/**\n * Label of the component. May be used when a creating a `TreeDefinition` for `SelectableTree`.\n * @public\n */\nModelsTreeComponent.getLabel = () => TreeWidget.translate(\"modelsTree.label\");\n\nfunction ModelsTreeComponentImpl({\n iModel,\n viewport,\n headerButtons,\n onFeatureUsed,\n onPerformanceMeasured,\n filter,\n ...treeProps\n}: ModelsTreeComponentProps & { iModel: IModelConnection; viewport: ScreenViewport }) {\n const { buttonProps, onModelsFiltered } = useModelsTreeButtonProps({ imodel: iModel, viewport });\n const { enabled: instanceFocusEnabled, toggle: toggleInstanceFocus } = useFocusedInstancesContext();\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\" onFeatureUsed={onFeatureUsed} />,\n <HideAllButton {...buttonProps} key=\"hide-all-btn\" onFeatureUsed={onFeatureUsed} />,\n <InvertButton {...buttonProps} key=\"invert-all-btn\" onFeatureUsed={onFeatureUsed} />,\n <View2DButton {...buttonProps} key=\"view-2d-btn\" onFeatureUsed={onFeatureUsed} />,\n <View3DButton {...buttonProps} key=\"view-3d-btn\" onFeatureUsed={onFeatureUsed} />,\n <ToggleInstancesFocusButton disabled={filter !== undefined} key=\"toggle-instances-focus-btn\" onFeatureUsed={onFeatureUsed} />,\n ];\n\n useEffect(() => {\n if (instanceFocusEnabled && filter !== undefined) {\n toggleInstanceFocus();\n }\n }, [instanceFocusEnabled, filter, toggleInstanceFocus]);\n\n return (\n <TelemetryContextProvider componentIdentifier={ModelsTreeComponent.id} onFeatureUsed={onFeatureUsed} onPerformanceMeasured={onPerformanceMeasured}>\n <SelectableTree buttons={buttons}>\n <ModelsTree {...treeProps} imodel={iModel} activeView={viewport} filter={filter} onModelsFiltered={onModelsFiltered} />\n </SelectableTree>\n </TelemetryContextProvider>\n );\n}\n"]}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import { jsx as _jsx
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
/*---------------------------------------------------------------------------------------------
|
|
3
3
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
4
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
5
|
*--------------------------------------------------------------------------------------------*/
|
|
6
6
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
7
|
-
import
|
|
7
|
+
import categorySvg from "@itwin/itwinui-icons/bis-category-3d.svg";
|
|
8
|
+
import classSvg from "@itwin/itwinui-icons/bis-class.svg";
|
|
9
|
+
import elementSvg from "@itwin/itwinui-icons/bis-element.svg";
|
|
10
|
+
import subjectSvg from "@itwin/itwinui-icons/bis-subject.svg";
|
|
11
|
+
import modelSvg from "@itwin/itwinui-icons/model-cube.svg";
|
|
8
12
|
import { createECSqlQueryExecutor } from "@itwin/presentation-core-interop";
|
|
9
13
|
import { HierarchyNodeIdentifier, HierarchyNodeKey } from "@itwin/presentation-hierarchies";
|
|
10
|
-
import {
|
|
11
|
-
import { EmptyTreeContent } from "../common/components/EmptyTreeContent.js";
|
|
14
|
+
import { EmptyTreeContent, FilterUnknownError, NoFilterMatches, TooManyFilterMatches, TooManyInstancesFocused, UnknownInstanceFocusError, } from "../common/components/EmptyTree.js";
|
|
12
15
|
import { useFocusedInstancesContext } from "../common/FocusedInstancesContext.js";
|
|
13
16
|
import { FilterLimitExceededError } from "../common/TreeErrors.js";
|
|
14
17
|
import { useIModelChangeListener } from "../common/UseIModelChangeListener.js";
|
|
@@ -179,15 +182,18 @@ function getEmptyTreeContentComponent(filter, error, emptyTreeContent) {
|
|
|
179
182
|
return _jsx(InstanceFocusError, { error: error });
|
|
180
183
|
}
|
|
181
184
|
if (isFilterError(error)) {
|
|
182
|
-
|
|
185
|
+
if (error === "tooManyFilterMatches") {
|
|
186
|
+
return _jsx(TooManyFilterMatches, { base: "modelsTree" });
|
|
187
|
+
}
|
|
188
|
+
return _jsx(FilterUnknownError, { base: "modelsTree" });
|
|
183
189
|
}
|
|
184
190
|
if (filter) {
|
|
185
|
-
return _jsx(
|
|
191
|
+
return _jsx(NoFilterMatches, { base: "modelsTree" });
|
|
186
192
|
}
|
|
187
193
|
if (emptyTreeContent) {
|
|
188
194
|
return emptyTreeContent;
|
|
189
195
|
}
|
|
190
|
-
return _jsx(EmptyTreeContent, { icon:
|
|
196
|
+
return _jsx(EmptyTreeContent, { icon: modelSvg });
|
|
191
197
|
}
|
|
192
198
|
function isFilterError(error) {
|
|
193
199
|
return error === "tooManyFilterMatches" || error === "unknownFilterError";
|
|
@@ -196,30 +202,26 @@ function isInstanceFocusError(error) {
|
|
|
196
202
|
return error === "tooManyInstancesFocused" || error === "unknownInstanceFocusError";
|
|
197
203
|
}
|
|
198
204
|
function InstanceFocusError({ error }) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
205
|
+
if (error === "tooManyInstancesFocused") {
|
|
206
|
+
return _jsx(TooManyInstancesFocused, { base: "modelsTree" });
|
|
207
|
+
}
|
|
208
|
+
return _jsx(UnknownInstanceFocusError, { base: "modelsTree" });
|
|
202
209
|
}
|
|
203
|
-
const subjectIcon = new URL("@itwin/itwinui-icons/bis-subject.svg", import.meta.url).href;
|
|
204
|
-
const classIcon = new URL("@itwin/itwinui-icons/bis-class.svg", import.meta.url).href;
|
|
205
|
-
const modelIcon = new URL("@itwin/itwinui-icons/model-cube.svg", import.meta.url).href;
|
|
206
|
-
const categoryIcon = new URL("@itwin/itwinui-icons/bis-category-3d.svg", import.meta.url).href;
|
|
207
|
-
const elementIcon = new URL("@itwin/itwinui-icons/bis-element.svg", import.meta.url).href;
|
|
208
210
|
function getIcon(node) {
|
|
209
211
|
if (node.extendedData?.imageId === undefined) {
|
|
210
212
|
return undefined;
|
|
211
213
|
}
|
|
212
214
|
switch (node.extendedData.imageId) {
|
|
213
215
|
case "icon-layers":
|
|
214
|
-
return
|
|
216
|
+
return categorySvg;
|
|
215
217
|
case "icon-item":
|
|
216
|
-
return
|
|
218
|
+
return elementSvg;
|
|
217
219
|
case "icon-ec-class":
|
|
218
|
-
return
|
|
220
|
+
return classSvg;
|
|
219
221
|
case "icon-folder":
|
|
220
|
-
return
|
|
222
|
+
return subjectSvg;
|
|
221
223
|
case "icon-model":
|
|
222
|
-
return
|
|
224
|
+
return modelSvg;
|
|
223
225
|
}
|
|
224
226
|
return undefined;
|
|
225
227
|
}
|
|
@@ -287,17 +289,4 @@ async function collectFocusedItems(loadFocusedItems) {
|
|
|
287
289
|
})));
|
|
288
290
|
return focusedItems;
|
|
289
291
|
}
|
|
290
|
-
function createLocalizedMessage(message, onClick) {
|
|
291
|
-
const exp = new RegExp("<link>(.*)</link>");
|
|
292
|
-
const match = message.match(exp);
|
|
293
|
-
if (!match) {
|
|
294
|
-
return message;
|
|
295
|
-
}
|
|
296
|
-
const [fullText, innerText] = match;
|
|
297
|
-
const [textBefore, textAfter] = message.split(fullText);
|
|
298
|
-
return (_jsxs(_Fragment, { children: [textBefore ? textBefore : null, _jsx(Anchor, { onClick: (e) => {
|
|
299
|
-
e.stopPropagation();
|
|
300
|
-
onClick?.();
|
|
301
|
-
}, children: innerText }), textAfter ? textAfter : null] }));
|
|
302
|
-
}
|
|
303
292
|
//# sourceMappingURL=UseModelsTree.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseModelsTree.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/models-tree/UseModelsTree.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,O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QAAQ,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC;IACpC,MAAM,CAAC,UAAU,EAAE,SAAS,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAExD,OAAO,CACL,8BACG,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,EAC/B,KAAC,MAAM,IACL,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;oBACb,CAAC,CAAC,eAAe,EAAE,CAAC;oBACpB,OAAO,EAAE,EAAE,CAAC;gBACd,CAAC,YAEA,SAAS,GACH,EACR,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,IAC5B,CACJ,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 { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { Anchor, Text } from \"@itwin/itwinui-react/bricks\";\nimport { createECSqlQueryExecutor } from \"@itwin/presentation-core-interop\";\nimport { HierarchyNodeIdentifier, HierarchyNodeKey } from \"@itwin/presentation-hierarchies\";\nimport { TreeWidget } from \"../../../TreeWidget.js\";\nimport { EmptyTreeContent } from \"../common/components/EmptyTreeContent.js\";\nimport { useFocusedInstancesContext } from \"../common/FocusedInstancesContext.js\";\nimport { FilterLimitExceededError } from \"../common/TreeErrors.js\";\nimport { useIModelChangeListener } from \"../common/UseIModelChangeListener.js\";\nimport { useTelemetryContext } from \"../common/UseTelemetryContext.js\";\nimport { ModelsTreeIdsCache } from \"./internal/ModelsTreeIdsCache.js\";\nimport { ModelsTreeNode } from \"./internal/ModelsTreeNode.js\";\nimport { createModelsTreeVisibilityHandler } from \"./internal/ModelsTreeVisibilityHandler.js\";\nimport { defaultHierarchyConfiguration, ModelsTreeDefinition } from \"./ModelsTreeDefinition.js\";\n\nimport type { ReactNode } from \"react\";\nimport type { GroupingHierarchyNode, HierarchyFilteringPath, InstancesNodeKey } from \"@itwin/presentation-hierarchies\";\nimport type { Id64String } from \"@itwin/core-bentley\";\nimport type { ECClassHierarchyInspector, InstanceKey } from \"@itwin/presentation-shared\";\nimport type { Viewport } from \"@itwin/core-frontend\";\nimport type { PresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport type { ClassGroupingHierarchyNode, ElementsGroupInfo, ModelsTreeHierarchyConfiguration } from \"./ModelsTreeDefinition.js\";\nimport type { ModelsTreeVisibilityHandlerOverrides } from \"./internal/ModelsTreeVisibilityHandler.js\";\nimport type { VisibilityTreeProps } from \"../common/components/VisibilityTree.js\";\nimport type { VisibilityTreeRendererProps } from \"../common/components/VisibilityTreeRenderer.js\";\n\ntype ModelsTreeFilteringError = \"tooManyFilterMatches\" | \"tooManyInstancesFocused\" | \"unknownFilterError\" | \"unknownInstanceFocusError\";\n\n/** @beta */\nexport interface UseModelsTreeProps {\n filter?: string;\n activeView: Viewport;\n hierarchyConfig?: Partial<ModelsTreeHierarchyConfiguration>;\n visibilityHandlerOverrides?: ModelsTreeVisibilityHandlerOverrides;\n getFilteredPaths?: (props: {\n createInstanceKeyPaths: (props: { targetItems: Array<InstanceKey | ElementsGroupInfo> } | { label: string }) => Promise<HierarchyFilteringPath[]>;\n }) => Promise<HierarchyFilteringPath[]>;\n onModelsFiltered?: (modelIds: Id64String[] | undefined) => void;\n /**\n * An optional predicate to allow or prohibit selection of a node.\n * When not supplied, all nodes are selectable.\n */\n selectionPredicate?: (props: { node: PresentationHierarchyNode; type: \"subject\" | \"model\" | \"category\" | \"element\" | \"elements-class-group\" }) => boolean;\n emptyTreeContent?: ReactNode;\n}\n\n/** @beta */\ninterface UseModelsTreeResult {\n modelsTreeProps: Pick<\n VisibilityTreeProps,\n \"treeName\" | \"getHierarchyDefinition\" | \"getFilteredPaths\" | \"visibilityHandlerFactory\" | \"highlight\" | \"emptyTreeContent\" | \"selectionPredicate\"\n >;\n rendererProps: Required<Pick<VisibilityTreeRendererProps, \"getIcon\">>;\n}\n\n/**\n * Custom hook to create and manage state for the models tree.\n * @beta\n */\nexport function useModelsTree({\n activeView,\n filter,\n hierarchyConfig,\n visibilityHandlerOverrides,\n getFilteredPaths,\n onModelsFiltered,\n selectionPredicate: nodeTypeSelectionPredicate,\n emptyTreeContent,\n}: UseModelsTreeProps): UseModelsTreeResult {\n const [filteringError, setFilteringError] = useState<ModelsTreeFilteringError | undefined>(undefined);\n const hierarchyConfiguration = useMemo<ModelsTreeHierarchyConfiguration>(\n () => ({\n ...defaultHierarchyConfiguration,\n ...hierarchyConfig,\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n Object.values(hierarchyConfig ?? {}),\n );\n const { onFeatureUsed } = useTelemetryContext();\n\n const { getModelsTreeIdsCache, visibilityHandlerFactory, onFilteredPathsChanged } = useCachedVisibility(\n activeView,\n hierarchyConfiguration,\n visibilityHandlerOverrides,\n );\n const { loadFocusedItems } = useFocusedInstancesContext();\n\n const getHierarchyDefinition = useCallback<VisibilityTreeProps[\"getHierarchyDefinition\"]>(\n ({ imodelAccess }) => new ModelsTreeDefinition({ imodelAccess, idsCache: getModelsTreeIdsCache(), hierarchyConfig: hierarchyConfiguration }),\n [getModelsTreeIdsCache, hierarchyConfiguration],\n );\n\n const getPaths = useMemo<VisibilityTreeProps[\"getFilteredPaths\"] | undefined>(() => {\n setFilteringError(undefined);\n onModelsFiltered?.(undefined);\n\n // reset filtered paths if there is no filters applied. This allows to keep current filtered paths until new paths are loaded.\n if (!loadFocusedItems && !getFilteredPaths && !filter) {\n onFilteredPathsChanged(undefined);\n }\n\n const handlePaths = async (filteredPaths: HierarchyFilteringPath[], classInspector: ECClassHierarchyInspector) => {\n onFilteredPathsChanged(filteredPaths);\n if (!onModelsFiltered) {\n return;\n }\n\n const modelIds = await getModels(filteredPaths, getModelsTreeIdsCache(), classInspector);\n onModelsFiltered(modelIds);\n };\n\n if (loadFocusedItems) {\n return async ({ imodelAccess }) => {\n try {\n const focusedItems = await collectFocusedItems(loadFocusedItems);\n const paths = await ModelsTreeDefinition.createInstanceKeyPaths({\n imodelAccess,\n idsCache: getModelsTreeIdsCache(),\n targetItems: focusedItems,\n hierarchyConfig: hierarchyConfiguration,\n });\n void handlePaths(paths, imodelAccess);\n return paths.map((path) => (\"path\" in path ? path : { path, options: { autoExpand: true } }));\n } catch (e) {\n const newError = e instanceof FilterLimitExceededError ? \"tooManyInstancesFocused\" : \"unknownInstanceFocusError\";\n if (newError !== \"tooManyInstancesFocused\") {\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 }\n\n if (getFilteredPaths) {\n return async ({ imodelAccess }) => {\n try {\n const paths = await getFilteredPaths({\n createInstanceKeyPaths: async (props) =>\n ModelsTreeDefinition.createInstanceKeyPaths({\n ...props,\n imodelAccess,\n idsCache: getModelsTreeIdsCache(),\n hierarchyConfig: hierarchyConfiguration,\n limit: \"unbounded\",\n }),\n });\n void handlePaths(paths, imodelAccess);\n return paths;\n } catch (e) {\n const newError = e instanceof FilterLimitExceededError ? \"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 }\n\n if (filter) {\n return async ({ imodelAccess }) => {\n onFeatureUsed({ featureId: \"filtering\", reportInteraction: true });\n try {\n const paths = await ModelsTreeDefinition.createInstanceKeyPaths({\n imodelAccess,\n label: filter,\n idsCache: getModelsTreeIdsCache(),\n hierarchyConfig: hierarchyConfiguration,\n });\n void handlePaths(paths, imodelAccess);\n return paths.map((path) => (\"path\" in path ? path : { path, options: { autoExpand: true } }));\n } catch (e) {\n const newError = e instanceof FilterLimitExceededError ? \"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 }\n return undefined;\n }, [filter, loadFocusedItems, getModelsTreeIdsCache, onFeatureUsed, getFilteredPaths, hierarchyConfiguration, onModelsFiltered, onFilteredPathsChanged]);\n\n const nodeSelectionPredicate = useCallback<NonNullable<VisibilityTreeProps[\"selectionPredicate\"]>>(\n (node) => {\n if (!nodeTypeSelectionPredicate) {\n return true;\n }\n return nodeTypeSelectionPredicate({ node, type: ModelsTreeNode.getType(node.nodeData) });\n },\n [nodeTypeSelectionPredicate],\n );\n\n // TODO: add double click logic\n return {\n modelsTreeProps: {\n treeName: \"models-tree-v2\",\n visibilityHandlerFactory,\n getHierarchyDefinition,\n getFilteredPaths: getPaths,\n emptyTreeContent: getEmptyTreeContentComponent(filter, filteringError, emptyTreeContent),\n highlight: filter ? { text: filter } : undefined,\n selectionPredicate: nodeSelectionPredicate,\n },\n rendererProps: {\n // onDoubleClick,\n getIcon,\n },\n };\n}\n\nasync function getModels(paths: HierarchyFilteringPath[], idsCache: ModelsTreeIdsCache, classInspector: ECClassHierarchyInspector) {\n if (!paths) {\n return undefined;\n }\n\n const targetModels = new Set<Id64String>();\n const targetSubjects = new Set<Id64String>();\n for (const path of paths) {\n const currPath = Array.isArray(path) ? path : path.path;\n for (let i = 0; i < currPath.length; i++) {\n const currStep = currPath[i];\n if (!HierarchyNodeIdentifier.isInstanceNodeIdentifier(currStep)) {\n break;\n }\n\n // if paths end with subject need to get all models under that subject\n if (i === currPath.length - 1 && currStep.className === \"BisCore.Subject\") {\n targetSubjects.add(currStep.id);\n break;\n }\n\n // collect all the models from the filtered path\n if (await classInspector.classDerivesFrom(currStep.className, \"BisCore.GeometricModel3d\")) {\n targetModels.add(currStep.id);\n }\n }\n }\n\n const matchingModels = await idsCache.getSubjectModelIds([...targetSubjects]);\n return [...targetModels, ...matchingModels];\n}\n\nfunction getEmptyTreeContentComponent(filter?: string, error?: ModelsTreeFilteringError, emptyTreeContent?: React.ReactNode) {\n if (isInstanceFocusError(error)) {\n return <InstanceFocusError error={error!} />;\n }\n if (isFilterError(error)) {\n return <Text>{TreeWidget.translate(`modelsTree.filtering.${error}`)}</Text>;\n }\n if (filter) {\n return <Text>{TreeWidget.translate(\"modelsTree.filtering.noMatches\", { filter })}</Text>;\n }\n if (emptyTreeContent) {\n return emptyTreeContent;\n }\n return <EmptyTreeContent icon={modelIcon} />;\n}\n\nfunction isFilterError(error: ModelsTreeFilteringError | undefined) {\n return error === \"tooManyFilterMatches\" || error === \"unknownFilterError\";\n}\n\nfunction isInstanceFocusError(error: ModelsTreeFilteringError | undefined) {\n return error === \"tooManyInstancesFocused\" || error === \"unknownInstanceFocusError\";\n}\n\nfunction InstanceFocusError({ error }: { error: ModelsTreeFilteringError }) {\n const { toggle } = useFocusedInstancesContext();\n const localizedMessage = createLocalizedMessage(TreeWidget.translate(`modelsTree.filtering.${error}`), () => toggle());\n return <Text>{localizedMessage}</Text>;\n}\n\nconst subjectIcon = new URL(\"@itwin/itwinui-icons/bis-subject.svg\", import.meta.url).href;\nconst classIcon = new URL(\"@itwin/itwinui-icons/bis-class.svg\", import.meta.url).href;\nconst modelIcon = new URL(\"@itwin/itwinui-icons/model-cube.svg\", import.meta.url).href;\nconst categoryIcon = new URL(\"@itwin/itwinui-icons/bis-category-3d.svg\", import.meta.url).href;\nconst elementIcon = new URL(\"@itwin/itwinui-icons/bis-element.svg\", import.meta.url).href;\n\nfunction getIcon(node: PresentationHierarchyNode): string | undefined {\n if (node.extendedData?.imageId === undefined) {\n return undefined;\n }\n\n switch (node.extendedData.imageId) {\n case \"icon-layers\":\n return categoryIcon;\n case \"icon-item\":\n return elementIcon;\n case \"icon-ec-class\":\n return classIcon;\n case \"icon-folder\":\n return subjectIcon;\n case \"icon-model\":\n return modelIcon;\n }\n\n return undefined;\n}\n\nfunction createVisibilityHandlerFactory(\n activeView: Viewport,\n idsCacheGetter: () => ModelsTreeIdsCache,\n overrides?: ModelsTreeVisibilityHandlerOverrides,\n filteredPaths?: HierarchyFilteringPath[],\n): VisibilityTreeProps[\"visibilityHandlerFactory\"] {\n return ({ imodelAccess }) => createModelsTreeVisibilityHandler({ viewport: activeView, idsCache: idsCacheGetter(), imodelAccess, overrides, filteredPaths });\n}\n\nfunction useCachedVisibility(activeView: Viewport, hierarchyConfig: ModelsTreeHierarchyConfiguration, overrides?: ModelsTreeVisibilityHandlerOverrides) {\n const cacheRef = useRef<ModelsTreeIdsCache>();\n const currentIModelRef = useRef(activeView.iModel);\n\n const resetModelsTreeIdsCache = () => {\n cacheRef.current?.[Symbol.dispose]();\n cacheRef.current = undefined;\n };\n const getModelsTreeIdsCache = useCallback(() => {\n if (!cacheRef.current) {\n cacheRef.current = new ModelsTreeIdsCache(createECSqlQueryExecutor(currentIModelRef.current), hierarchyConfig);\n }\n return cacheRef.current;\n }, [hierarchyConfig]);\n\n const [filteredPaths, setFilteredPaths] = useState<HierarchyFilteringPath[]>();\n const [visibilityHandlerFactory, setVisibilityHandlerFactory] = useState<VisibilityTreeProps[\"visibilityHandlerFactory\"]>(() =>\n createVisibilityHandlerFactory(activeView, getModelsTreeIdsCache, overrides, filteredPaths),\n );\n\n useIModelChangeListener({\n imodel: activeView.iModel,\n action: useCallback(() => {\n resetModelsTreeIdsCache();\n setVisibilityHandlerFactory(() => createVisibilityHandlerFactory(activeView, getModelsTreeIdsCache, overrides, filteredPaths));\n }, [activeView, getModelsTreeIdsCache, overrides, filteredPaths]),\n });\n\n useEffect(() => {\n currentIModelRef.current = activeView.iModel;\n setVisibilityHandlerFactory(() => createVisibilityHandlerFactory(activeView, getModelsTreeIdsCache, overrides, filteredPaths));\n return () => resetModelsTreeIdsCache();\n }, [activeView, getModelsTreeIdsCache, overrides, filteredPaths]);\n\n return {\n getModelsTreeIdsCache,\n visibilityHandlerFactory,\n onFilteredPathsChanged: useCallback((paths: HierarchyFilteringPath[] | undefined) => setFilteredPaths(paths), []),\n };\n}\n\nasync function collectFocusedItems(loadFocusedItems: () => AsyncIterableIterator<InstanceKey | GroupingHierarchyNode>) {\n const focusedItems: Array<InstanceKey | ElementsGroupInfo> = [];\n const groupingNodeInfos: Array<{\n parentKey: InstancesNodeKey;\n parentType: \"element\" | \"category\";\n groupingNode: ClassGroupingHierarchyNode;\n modelIds: Id64String[];\n }> = [];\n for await (const key of loadFocusedItems()) {\n if (\"id\" in key) {\n focusedItems.push(key);\n continue;\n }\n\n if (!HierarchyNodeKey.isClassGrouping(key.key)) {\n continue;\n }\n\n const groupingNode = key as ClassGroupingHierarchyNode;\n if (!groupingNode.nonGroupingAncestor || !HierarchyNodeKey.isInstances(groupingNode.nonGroupingAncestor.key)) {\n continue;\n }\n\n const parentKey = groupingNode.nonGroupingAncestor.key;\n const type = groupingNode.nonGroupingAncestor.extendedData?.isCategory ? \"category\" : \"element\";\n const modelIds = ((groupingNode.nonGroupingAncestor.extendedData?.modelIds as Id64String[][]) ?? []).flatMap((ids) => ids);\n groupingNodeInfos.push({ groupingNode, parentType: type, parentKey, modelIds });\n }\n focusedItems.push(\n ...groupingNodeInfos.map(({ parentKey, parentType, groupingNode, modelIds }) => ({\n parent:\n parentType === \"element\"\n ? { type: \"element\" as const, ids: parentKey.instanceKeys.map((key) => key.id) }\n : { type: \"category\" as const, ids: parentKey.instanceKeys.map((key) => key.id), modelIds },\n groupingNode,\n })),\n );\n return focusedItems;\n}\n\nfunction createLocalizedMessage(message: string, onClick?: () => void) {\n const exp = new RegExp(\"<link>(.*)</link>\");\n const match = message.match(exp);\n if (!match) {\n return message;\n }\n\n const [fullText, innerText] = match;\n const [textBefore, textAfter] = message.split(fullText);\n\n return (\n <>\n {textBefore ? textBefore : null}\n <Anchor\n onClick={(e) => {\n e.stopPropagation();\n onClick?.();\n }}\n >\n {innerText}\n </Anchor>\n {textAfter ? textAfter : null}\n </>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"UseModelsTree.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/models-tree/UseModelsTree.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC1E,OAAO,WAAW,MAAM,0CAA0C,CAAC;AACnE,OAAO,QAAQ,MAAM,oCAAoC,CAAC;AAC1D,OAAO,UAAU,MAAM,sCAAsC,CAAC;AAC9D,OAAO,UAAU,MAAM,sCAAsC,CAAC;AAC9D,OAAO,QAAQ,MAAM,qCAAqC,CAAC;AAC3D,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAC5F,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,uBAAuB,EACvB,yBAAyB,GAC1B,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAClF,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,iCAAiC,EAAE,MAAM,2CAA2C,CAAC;AAC9F,OAAO,EAAE,6BAA6B,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AA0ChG;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,EA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,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;QAC3H,iBAAiB,CAAC,IAAI,CAAC,EAAE,YAAY,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC;KACjF;IACD,YAAY,CAAC,IAAI,CACf,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC;QAC/E,MAAM,EACJ,UAAU,KAAK,SAAS;YACtB,CAAC,CAAC,EAAE,IAAI,EAAE,SAAkB,EAAE,GAAG,EAAE,SAAS,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;YAChF,CAAC,CAAC,EAAE,IAAI,EAAE,UAAmB,EAAE,GAAG,EAAE,SAAS,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE;QAC/F,YAAY;KACb,CAAC,CAAC,CACJ,CAAC;IACF,OAAO,YAAY,CAAC;AACtB,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, useEffect, useMemo, useRef, useState } from \"react\";\nimport categorySvg from \"@itwin/itwinui-icons/bis-category-3d.svg\";\nimport classSvg from \"@itwin/itwinui-icons/bis-class.svg\";\nimport elementSvg from \"@itwin/itwinui-icons/bis-element.svg\";\nimport subjectSvg from \"@itwin/itwinui-icons/bis-subject.svg\";\nimport modelSvg from \"@itwin/itwinui-icons/model-cube.svg\";\nimport { createECSqlQueryExecutor } from \"@itwin/presentation-core-interop\";\nimport { HierarchyNodeIdentifier, HierarchyNodeKey } from \"@itwin/presentation-hierarchies\";\nimport {\n EmptyTreeContent,\n FilterUnknownError,\n NoFilterMatches,\n TooManyFilterMatches,\n TooManyInstancesFocused,\n UnknownInstanceFocusError,\n} from \"../common/components/EmptyTree.js\";\nimport { useFocusedInstancesContext } from \"../common/FocusedInstancesContext.js\";\nimport { FilterLimitExceededError } from \"../common/TreeErrors.js\";\nimport { useIModelChangeListener } from \"../common/UseIModelChangeListener.js\";\nimport { useTelemetryContext } from \"../common/UseTelemetryContext.js\";\nimport { ModelsTreeIdsCache } from \"./internal/ModelsTreeIdsCache.js\";\nimport { ModelsTreeNode } from \"./internal/ModelsTreeNode.js\";\nimport { createModelsTreeVisibilityHandler } from \"./internal/ModelsTreeVisibilityHandler.js\";\nimport { defaultHierarchyConfiguration, ModelsTreeDefinition } from \"./ModelsTreeDefinition.js\";\n\nimport type { ReactNode } from \"react\";\nimport type { GroupingHierarchyNode, HierarchyFilteringPath, InstancesNodeKey } from \"@itwin/presentation-hierarchies\";\nimport type { Id64String } from \"@itwin/core-bentley\";\nimport type { ECClassHierarchyInspector, InstanceKey } from \"@itwin/presentation-shared\";\nimport type { Viewport } from \"@itwin/core-frontend\";\nimport type { PresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport type { ClassGroupingHierarchyNode, ElementsGroupInfo, ModelsTreeHierarchyConfiguration } from \"./ModelsTreeDefinition.js\";\nimport type { ModelsTreeVisibilityHandlerOverrides } from \"./internal/ModelsTreeVisibilityHandler.js\";\nimport type { VisibilityTreeProps } from \"../common/components/VisibilityTree.js\";\nimport type { VisibilityTreeRendererProps } from \"../common/components/VisibilityTreeRenderer.js\";\n\ntype ModelsTreeFilteringError = \"tooManyFilterMatches\" | \"tooManyInstancesFocused\" | \"unknownFilterError\" | \"unknownInstanceFocusError\";\n\n/** @beta */\nexport interface UseModelsTreeProps {\n filter?: string;\n activeView: Viewport;\n hierarchyConfig?: Partial<ModelsTreeHierarchyConfiguration>;\n visibilityHandlerOverrides?: ModelsTreeVisibilityHandlerOverrides;\n getFilteredPaths?: (props: {\n createInstanceKeyPaths: (props: { targetItems: Array<InstanceKey | ElementsGroupInfo> } | { label: string }) => Promise<HierarchyFilteringPath[]>;\n }) => Promise<HierarchyFilteringPath[]>;\n onModelsFiltered?: (modelIds: Id64String[] | undefined) => void;\n /**\n * An optional predicate to allow or prohibit selection of a node.\n * When not supplied, all nodes are selectable.\n */\n selectionPredicate?: (props: { node: PresentationHierarchyNode; type: \"subject\" | \"model\" | \"category\" | \"element\" | \"elements-class-group\" }) => boolean;\n emptyTreeContent?: ReactNode;\n}\n\n/** @beta */\ninterface UseModelsTreeResult {\n modelsTreeProps: Pick<\n VisibilityTreeProps,\n \"treeName\" | \"getHierarchyDefinition\" | \"getFilteredPaths\" | \"visibilityHandlerFactory\" | \"highlight\" | \"emptyTreeContent\" | \"selectionPredicate\"\n >;\n rendererProps: Required<Pick<VisibilityTreeRendererProps, \"getIcon\">>;\n}\n\n/**\n * Custom hook to create and manage state for the models tree.\n * @beta\n */\nexport function useModelsTree({\n activeView,\n filter,\n hierarchyConfig,\n visibilityHandlerOverrides,\n getFilteredPaths,\n onModelsFiltered,\n selectionPredicate: nodeTypeSelectionPredicate,\n emptyTreeContent,\n}: UseModelsTreeProps): UseModelsTreeResult {\n const [filteringError, setFilteringError] = useState<ModelsTreeFilteringError | undefined>(undefined);\n const hierarchyConfiguration = useMemo<ModelsTreeHierarchyConfiguration>(\n () => ({\n ...defaultHierarchyConfiguration,\n ...hierarchyConfig,\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n Object.values(hierarchyConfig ?? {}),\n );\n const { onFeatureUsed } = useTelemetryContext();\n\n const { getModelsTreeIdsCache, visibilityHandlerFactory, onFilteredPathsChanged } = useCachedVisibility(\n activeView,\n hierarchyConfiguration,\n visibilityHandlerOverrides,\n );\n const { loadFocusedItems } = useFocusedInstancesContext();\n\n const getHierarchyDefinition = useCallback<VisibilityTreeProps[\"getHierarchyDefinition\"]>(\n ({ imodelAccess }) => new ModelsTreeDefinition({ imodelAccess, idsCache: getModelsTreeIdsCache(), hierarchyConfig: hierarchyConfiguration }),\n [getModelsTreeIdsCache, hierarchyConfiguration],\n );\n\n const getPaths = useMemo<VisibilityTreeProps[\"getFilteredPaths\"] | undefined>(() => {\n setFilteringError(undefined);\n onModelsFiltered?.(undefined);\n\n // reset filtered paths if there is no filters applied. This allows to keep current filtered paths until new paths are loaded.\n if (!loadFocusedItems && !getFilteredPaths && !filter) {\n onFilteredPathsChanged(undefined);\n }\n\n const handlePaths = async (filteredPaths: HierarchyFilteringPath[], classInspector: ECClassHierarchyInspector) => {\n onFilteredPathsChanged(filteredPaths);\n if (!onModelsFiltered) {\n return;\n }\n\n const modelIds = await getModels(filteredPaths, getModelsTreeIdsCache(), classInspector);\n onModelsFiltered(modelIds);\n };\n\n if (loadFocusedItems) {\n return async ({ imodelAccess }) => {\n try {\n const focusedItems = await collectFocusedItems(loadFocusedItems);\n const paths = await ModelsTreeDefinition.createInstanceKeyPaths({\n imodelAccess,\n idsCache: getModelsTreeIdsCache(),\n targetItems: focusedItems,\n hierarchyConfig: hierarchyConfiguration,\n });\n void handlePaths(paths, imodelAccess);\n return paths.map((path) => (\"path\" in path ? path : { path, options: { autoExpand: true } }));\n } catch (e) {\n const newError = e instanceof FilterLimitExceededError ? \"tooManyInstancesFocused\" : \"unknownInstanceFocusError\";\n if (newError !== \"tooManyInstancesFocused\") {\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 }\n\n if (getFilteredPaths) {\n return async ({ imodelAccess }) => {\n try {\n const paths = await getFilteredPaths({\n createInstanceKeyPaths: async (props) =>\n ModelsTreeDefinition.createInstanceKeyPaths({\n ...props,\n imodelAccess,\n idsCache: getModelsTreeIdsCache(),\n hierarchyConfig: hierarchyConfiguration,\n limit: \"unbounded\",\n }),\n });\n void handlePaths(paths, imodelAccess);\n return paths;\n } catch (e) {\n const newError = e instanceof FilterLimitExceededError ? \"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 }\n\n if (filter) {\n return async ({ imodelAccess }) => {\n onFeatureUsed({ featureId: \"filtering\", reportInteraction: true });\n try {\n const paths = await ModelsTreeDefinition.createInstanceKeyPaths({\n imodelAccess,\n label: filter,\n idsCache: getModelsTreeIdsCache(),\n hierarchyConfig: hierarchyConfiguration,\n });\n void handlePaths(paths, imodelAccess);\n return paths.map((path) => (\"path\" in path ? path : { path, options: { autoExpand: true } }));\n } catch (e) {\n const newError = e instanceof FilterLimitExceededError ? \"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 }\n return undefined;\n }, [filter, loadFocusedItems, getModelsTreeIdsCache, onFeatureUsed, getFilteredPaths, hierarchyConfiguration, onModelsFiltered, onFilteredPathsChanged]);\n\n const nodeSelectionPredicate = useCallback<NonNullable<VisibilityTreeProps[\"selectionPredicate\"]>>(\n (node) => {\n if (!nodeTypeSelectionPredicate) {\n return true;\n }\n return nodeTypeSelectionPredicate({ node, type: ModelsTreeNode.getType(node.nodeData) });\n },\n [nodeTypeSelectionPredicate],\n );\n\n // TODO: add double click logic\n return {\n modelsTreeProps: {\n treeName: \"models-tree-v2\",\n visibilityHandlerFactory,\n getHierarchyDefinition,\n getFilteredPaths: getPaths,\n emptyTreeContent: getEmptyTreeContentComponent(filter, filteringError, emptyTreeContent),\n highlight: filter ? { text: filter } : undefined,\n selectionPredicate: nodeSelectionPredicate,\n },\n rendererProps: {\n // onDoubleClick,\n getIcon,\n },\n };\n}\n\nasync function getModels(paths: HierarchyFilteringPath[], idsCache: ModelsTreeIdsCache, classInspector: ECClassHierarchyInspector) {\n if (!paths) {\n return undefined;\n }\n\n const targetModels = new Set<Id64String>();\n const targetSubjects = new Set<Id64String>();\n for (const path of paths) {\n const currPath = Array.isArray(path) ? path : path.path;\n for (let i = 0; i < currPath.length; i++) {\n const currStep = currPath[i];\n if (!HierarchyNodeIdentifier.isInstanceNodeIdentifier(currStep)) {\n break;\n }\n\n // if paths end with subject need to get all models under that subject\n if (i === currPath.length - 1 && currStep.className === \"BisCore.Subject\") {\n targetSubjects.add(currStep.id);\n break;\n }\n\n // collect all the models from the filtered path\n if (await classInspector.classDerivesFrom(currStep.className, \"BisCore.GeometricModel3d\")) {\n targetModels.add(currStep.id);\n }\n }\n }\n\n const matchingModels = await idsCache.getSubjectModelIds([...targetSubjects]);\n return [...targetModels, ...matchingModels];\n}\n\nfunction getEmptyTreeContentComponent(filter?: string, error?: ModelsTreeFilteringError, emptyTreeContent?: React.ReactNode) {\n if (isInstanceFocusError(error)) {\n return <InstanceFocusError error={error!} />;\n }\n if (isFilterError(error)) {\n if (error === \"tooManyFilterMatches\") {\n return <TooManyFilterMatches base={\"modelsTree\"} />;\n }\n return <FilterUnknownError base={\"modelsTree\"} />;\n }\n if (filter) {\n return <NoFilterMatches base={\"modelsTree\"} />;\n }\n if (emptyTreeContent) {\n return emptyTreeContent;\n }\n return <EmptyTreeContent icon={modelSvg} />;\n}\n\nfunction isFilterError(error: ModelsTreeFilteringError | undefined) {\n return error === \"tooManyFilterMatches\" || error === \"unknownFilterError\";\n}\n\nfunction isInstanceFocusError(error: ModelsTreeFilteringError | undefined) {\n return error === \"tooManyInstancesFocused\" || error === \"unknownInstanceFocusError\";\n}\n\nfunction InstanceFocusError({ error }: { error: ModelsTreeFilteringError }) {\n if (error === \"tooManyInstancesFocused\") {\n return <TooManyInstancesFocused base={\"modelsTree\"} />;\n }\n return <UnknownInstanceFocusError base={\"modelsTree\"} />;\n}\n\nfunction getIcon(node: PresentationHierarchyNode): string | undefined {\n if (node.extendedData?.imageId === undefined) {\n return undefined;\n }\n\n switch (node.extendedData.imageId) {\n case \"icon-layers\":\n return categorySvg;\n case \"icon-item\":\n return elementSvg;\n case \"icon-ec-class\":\n return classSvg;\n case \"icon-folder\":\n return subjectSvg;\n case \"icon-model\":\n return modelSvg;\n }\n\n return undefined;\n}\n\nfunction createVisibilityHandlerFactory(\n activeView: Viewport,\n idsCacheGetter: () => ModelsTreeIdsCache,\n overrides?: ModelsTreeVisibilityHandlerOverrides,\n filteredPaths?: HierarchyFilteringPath[],\n): VisibilityTreeProps[\"visibilityHandlerFactory\"] {\n return ({ imodelAccess }) => createModelsTreeVisibilityHandler({ viewport: activeView, idsCache: idsCacheGetter(), imodelAccess, overrides, filteredPaths });\n}\n\nfunction useCachedVisibility(activeView: Viewport, hierarchyConfig: ModelsTreeHierarchyConfiguration, overrides?: ModelsTreeVisibilityHandlerOverrides) {\n const cacheRef = useRef<ModelsTreeIdsCache>();\n const currentIModelRef = useRef(activeView.iModel);\n\n const resetModelsTreeIdsCache = () => {\n cacheRef.current?.[Symbol.dispose]();\n cacheRef.current = undefined;\n };\n const getModelsTreeIdsCache = useCallback(() => {\n if (!cacheRef.current) {\n cacheRef.current = new ModelsTreeIdsCache(createECSqlQueryExecutor(currentIModelRef.current), hierarchyConfig);\n }\n return cacheRef.current;\n }, [hierarchyConfig]);\n\n const [filteredPaths, setFilteredPaths] = useState<HierarchyFilteringPath[]>();\n const [visibilityHandlerFactory, setVisibilityHandlerFactory] = useState<VisibilityTreeProps[\"visibilityHandlerFactory\"]>(() =>\n createVisibilityHandlerFactory(activeView, getModelsTreeIdsCache, overrides, filteredPaths),\n );\n\n useIModelChangeListener({\n imodel: activeView.iModel,\n action: useCallback(() => {\n resetModelsTreeIdsCache();\n setVisibilityHandlerFactory(() => createVisibilityHandlerFactory(activeView, getModelsTreeIdsCache, overrides, filteredPaths));\n }, [activeView, getModelsTreeIdsCache, overrides, filteredPaths]),\n });\n\n useEffect(() => {\n currentIModelRef.current = activeView.iModel;\n setVisibilityHandlerFactory(() => createVisibilityHandlerFactory(activeView, getModelsTreeIdsCache, overrides, filteredPaths));\n return () => resetModelsTreeIdsCache();\n }, [activeView, getModelsTreeIdsCache, overrides, filteredPaths]);\n\n return {\n getModelsTreeIdsCache,\n visibilityHandlerFactory,\n onFilteredPathsChanged: useCallback((paths: HierarchyFilteringPath[] | undefined) => setFilteredPaths(paths), []),\n };\n}\n\nasync function collectFocusedItems(loadFocusedItems: () => AsyncIterableIterator<InstanceKey | GroupingHierarchyNode>) {\n const focusedItems: Array<InstanceKey | ElementsGroupInfo> = [];\n const groupingNodeInfos: Array<{\n parentKey: InstancesNodeKey;\n parentType: \"element\" | \"category\";\n groupingNode: ClassGroupingHierarchyNode;\n modelIds: Id64String[];\n }> = [];\n for await (const key of loadFocusedItems()) {\n if (\"id\" in key) {\n focusedItems.push(key);\n continue;\n }\n\n if (!HierarchyNodeKey.isClassGrouping(key.key)) {\n continue;\n }\n\n const groupingNode = key as ClassGroupingHierarchyNode;\n if (!groupingNode.nonGroupingAncestor || !HierarchyNodeKey.isInstances(groupingNode.nonGroupingAncestor.key)) {\n continue;\n }\n\n const parentKey = groupingNode.nonGroupingAncestor.key;\n const type = groupingNode.nonGroupingAncestor.extendedData?.isCategory ? \"category\" : \"element\";\n const modelIds = ((groupingNode.nonGroupingAncestor.extendedData?.modelIds as Id64String[][]) ?? []).flatMap((ids) => ids);\n groupingNodeInfos.push({ groupingNode, parentType: type, parentKey, modelIds });\n }\n focusedItems.push(\n ...groupingNodeInfos.map(({ parentKey, parentType, groupingNode, modelIds }) => ({\n parent:\n parentType === \"element\"\n ? { type: \"element\" as const, ids: parentKey.instanceKeys.map((key) => key.id) }\n : { type: \"category\" as const, ids: parentKey.instanceKeys.map((key) => key.id), modelIds },\n groupingNode,\n })),\n );\n return focusedItems;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AlwaysAndNeverDrawnElementInfo.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EACL,eAAe,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,gBAAgB,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAC7I,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,GAChC,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAmBlD,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,CAAC;AAE3C,MAAM,OAAO,8BAA8B;IAUzC,YAA6B,SAAmB;QAAnB,cAAS,GAAT,SAAS,CAAU;QANxC,oBAAe,GAAG,IAAI,OAAO,EAAQ,CAAC;QAGtC,cAAS,GAAG,IAAI,OAAO,EAAW,CAAC;QACnC,iBAAY,GAAG,IAAI,OAAO,EAAQ,CAAC;QAGzC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,0BAA0B,CAAC;YAClD,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,oBAAoB;YAC1C,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW;YACxC,EAAE,EAAE,aAAa;SAClB,CAAC,CAAC;QACH,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,0BAA0B,CAAC;YACjD,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,mBAAmB;YACzC,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,SA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AAG,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;aAC/B;YACD,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC;YAChD,OAAO,KAAK,CAAC;QACf,CAAC,EAAE,IAAI,GAAG,EAAwC,CAAC,CACpD,CAAC;IACJ,CAAC;IAEO,gBAAgB,CAAC,UAAqB,EAAE,SAAiB;QAC/D,MAAM,QAAQ,GAAG,wBAAwB,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACjE,MAAM,MAAM,GAAG,QAAQ,CAAC,iBAAiB,CACvC;YACE,IAAI,EAAE;gBACJ;;;;;;;;;;;;;;;;;;;;SAoBD;aACA;YACD,KAAK,EAAE;;;;OAIR;YACC,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;SACjD,EACD;YACE,YAAY,EAAE,+BAA+B,SAAS,EAAE;SACzD,CACF,CAAC;QAEF,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;IAC3H,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 {\n BehaviorSubject, debounceTime, EMPTY, filter, first, from, fromEventPattern, map, merge, reduce, scan, share, shareReplay, startWith, Subject,\n switchMap, take, takeUntil, tap,\n} from \"rxjs\";\nimport { createECSqlQueryExecutor } from \"@itwin/presentation-core-interop\";\nimport { pushToMap } from \"../../common/Utils.js\";\n\nimport type { Observable, Subscription } from \"rxjs\";\nimport type { Viewport } from \"@itwin/core-frontend\";\nimport type { BeEvent, Id64Array, Id64Set, Id64String, IDisposable } from \"@itwin/core-bentley\";\n\ninterface ElementInfo {\n elementId: Id64String;\n modelId: Id64String;\n categoryId: Id64String;\n}\n\ntype CacheEntry = Map<Id64String, Map<Id64String, Id64Set>>;\n\nexport interface AlwaysOrNeverDrawnElementsQueryProps {\n modelId: Id64String;\n categoryId?: Id64String;\n}\n\nexport const SET_CHANGE_DEBOUNCE_TIME = 20;\n\nexport class AlwaysAndNeverDrawnElementInfo implements IDisposable {\n private _subscriptions: Subscription[];\n private _alwaysDrawn: Observable<CacheEntry>;\n private _neverDrawn: Observable<CacheEntry>;\n private _disposeSubject = new Subject<void>();\n\n private _suppressors: Observable<number>;\n private _suppress = new Subject<boolean>();\n private _forceUpdate = new Subject<void>();\n\n constructor(private readonly _viewport: Viewport) {\n this._alwaysDrawn = this.createCacheEntryObservable({\n event: this._viewport.onAlwaysDrawnChanged,\n getSet: () => this._viewport.alwaysDrawn,\n id: \"alwaysDrawn\",\n });\n this._neverDrawn = this.createCacheEntryObservable({\n event: this._viewport.onNeverDrawnChanged,\n getSet: () => this._viewport.neverDrawn,\n id: \"neverDrawn\",\n });\n this._suppressors = this._suppress.pipe(\n scan((acc, suppress) => acc + (suppress ? 1 : -1), 0),\n startWith(0),\n shareReplay(1),\n );\n this._subscriptions = [\n this._alwaysDrawn.subscribe(),\n this._neverDrawn.subscribe(),\n this._suppressors.pipe(filter((suppressors) => suppressors === 0)).subscribe({\n next: () => this._forceUpdate.next(),\n }),\n ];\n }\n\n public suppressChangeEvents() {\n this._suppress.next(true);\n }\n\n public resumeChangeEvents() {\n this._suppress.next(false);\n }\n\n public getElements({ setType, modelId, categoryId }: { setType: \"always\" | \"never\" } & AlwaysOrNeverDrawnElementsQueryProps): Observable<Id64Set> {\n const cache = setType === \"always\" ? this._alwaysDrawn : this._neverDrawn;\n const getElements = categoryId\n ? (entry: CacheEntry | undefined) => {\n return entry?.get(modelId)?.get(categoryId) ?? new Set();\n }\n : (entry: CacheEntry | undefined) => {\n const modelEntry = entry?.get(modelId);\n const elements = new Set<Id64String>();\n for (const set of modelEntry?.values() ?? []) {\n set.forEach((id) => elements.add(id));\n }\n return elements;\n };\n\n return cache.pipe(map(getElements));\n }\n\n private createCacheEntryObservable(props: { event: BeEvent<() => void>; getSet(): Id64Set | undefined; id: string }) {\n const event = props.event;\n const resultSubject = new BehaviorSubject<CacheEntry | undefined>(undefined);\n\n const obs = merge(\n fromEventPattern(\n (handler) => event.addListener(handler),\n (handler) => event.removeListener(handler),\n ),\n this._forceUpdate,\n ).pipe(\n // Fire the observable once at the beginning\n startWith(undefined),\n // Stop listening to events when dispose() is called\n takeUntil(this._disposeSubject),\n // Reset result subject as soon as a new event is emitted.\n // This will make newly subscribed observers wait for the debounce period to pass\n // instead of consuming the cached value which at this point becomes invalid.\n tap(() => resultSubject.next(undefined)),\n // Check if cache updates are not suppressed.\n switchMap(() =>\n this._suppressors.pipe(\n filter((suppressors) => suppressors === 0),\n take(1),\n ),\n ),\n debounceTime(SET_CHANGE_DEBOUNCE_TIME),\n // Cancel pending request if dispose() is called.\n takeUntil(this._disposeSubject),\n // If multiple requests are sent at once, preserve only the result of the newest.\n switchMap(() => this.queryAlwaysOrNeverDrawnElementInfo(props.getSet(), props.id)),\n // Share the result by using a subject which always emits the saved result.\n share({\n connector: () => resultSubject,\n resetOnRefCountZero: false,\n }),\n // Wait until the result is available.\n first((x): x is CacheEntry => !!x),\n );\n return obs;\n }\n\n public dispose(): void {\n this._subscriptions.forEach((x) => x.unsubscribe());\n this._subscriptions = [];\n this._disposeSubject.next();\n }\n\n private queryAlwaysOrNeverDrawnElementInfo(set: Id64Set | undefined, requestId: string): Observable<CacheEntry> {\n const elementInfo = set?.size ? this.queryElementInfo([...set], requestId) : EMPTY;\n return elementInfo.pipe(\n reduce((state, val) => {\n let entry = state.get(val.modelId);\n if (!entry) {\n entry = new Map();\n state.set(val.modelId, entry);\n }\n pushToMap(entry, val.categoryId, val.elementId);\n return state;\n }, new Map<Id64String, Map<Id64String, Id64Set>>()),\n );\n }\n\n private queryElementInfo(elementIds: Id64Array, requestId: string): Observable<ElementInfo> {\n const executor = createECSqlQueryExecutor(this._viewport.iModel);\n const reader = executor.createQueryReader(\n {\n ctes: [\n `\n ElementInfo(elementId, modelId, categoryId, parentId) AS (\n SELECT\n ECInstanceId elementId,\n Model.Id modelId,\n Category.Id categoryId,\n Parent.Id parentId\n FROM bis.GeometricElement3d\n WHERE InVirtualSet(?, ECInstanceId)\n\n UNION ALL\n\n SELECT\n e.elementId,\n e.modelId,\n p.Category.Id categoryId,\n p.Parent.Id parentId\n FROM bis.GeometricElement3d p\n JOIN ElementInfo e ON p.ECInstanceId = e.parentId\n )\n `,\n ],\n ecsql: `\n SELECT elementId, modelId, categoryId\n FROM ElementInfo\n WHERE parentId IS NULL\n `,\n bindings: [{ type: \"idset\", value: elementIds }],\n },\n {\n restartToken: `ModelsTreeVisibilityHandler/${requestId}`,\n },\n );\n\n return from(reader).pipe(map((row) => ({ elementId: row.elementId, modelId: row.modelId, categoryId: row.categoryId })));\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"AlwaysAndNeverDrawnElementInfo.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EACL,eAAe,EACf,YAAY,EACZ,KAAK,EACL,MAAM,EACN,KAAK,EACL,IAAI,EACJ,gBAAgB,EAChB,GAAG,EACH,KAAK,EACL,MAAM,EACN,IAAI,EACJ,KAAK,EACL,WAAW,EACX,SAAS,EACT,OAAO,EACP,SAAS,EACT,IAAI,EACJ,SAAS,EACT,GAAG,GACJ,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,SAAS,EAAE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E,CAAC;SACjD,EACD;YACE,YAAY,EAAE,+BAA+B,SAAS,EAAE;SACzD,CACF,CAAC;QAEF,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;IAC3H,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 {\n BehaviorSubject,\n debounceTime,\n EMPTY,\n filter,\n first,\n from,\n fromEventPattern,\n map,\n merge,\n reduce,\n scan,\n share,\n shareReplay,\n startWith,\n Subject,\n switchMap,\n take,\n takeUntil,\n tap,\n} from \"rxjs\";\nimport { createECSqlQueryExecutor } from \"@itwin/presentation-core-interop\";\nimport { pushToMap } from \"../../common/Utils.js\";\n\nimport type { Observable, Subscription } from \"rxjs\";\nimport type { Viewport } from \"@itwin/core-frontend\";\nimport type { BeEvent, Id64Array, Id64Set, Id64String, IDisposable } from \"@itwin/core-bentley\";\n\ninterface ElementInfo {\n elementId: Id64String;\n modelId: Id64String;\n categoryId: Id64String;\n}\n\ntype CacheEntry = Map<Id64String, Map<Id64String, Id64Set>>;\n\nexport interface AlwaysOrNeverDrawnElementsQueryProps {\n modelId: Id64String;\n categoryId?: Id64String;\n}\n\nexport const SET_CHANGE_DEBOUNCE_TIME = 20;\n\nexport class AlwaysAndNeverDrawnElementInfo implements IDisposable {\n private _subscriptions: Subscription[];\n private _alwaysDrawn: Observable<CacheEntry>;\n private _neverDrawn: Observable<CacheEntry>;\n private _disposeSubject = new Subject<void>();\n\n private _suppressors: Observable<number>;\n private _suppress = new Subject<boolean>();\n private _forceUpdate = new Subject<void>();\n\n constructor(private readonly _viewport: Viewport) {\n this._alwaysDrawn = this.createCacheEntryObservable({\n event: this._viewport.onAlwaysDrawnChanged,\n getSet: () => this._viewport.alwaysDrawn,\n id: \"alwaysDrawn\",\n });\n this._neverDrawn = this.createCacheEntryObservable({\n event: this._viewport.onNeverDrawnChanged,\n getSet: () => this._viewport.neverDrawn,\n id: \"neverDrawn\",\n });\n this._suppressors = this._suppress.pipe(\n scan((acc, suppress) => acc + (suppress ? 1 : -1), 0),\n startWith(0),\n shareReplay(1),\n );\n this._subscriptions = [\n this._alwaysDrawn.subscribe(),\n this._neverDrawn.subscribe(),\n this._suppressors.pipe(filter((suppressors) => suppressors === 0)).subscribe({\n next: () => this._forceUpdate.next(),\n }),\n ];\n }\n\n public suppressChangeEvents() {\n this._suppress.next(true);\n }\n\n public resumeChangeEvents() {\n this._suppress.next(false);\n }\n\n public getElements({ setType, modelId, categoryId }: { setType: \"always\" | \"never\" } & AlwaysOrNeverDrawnElementsQueryProps): Observable<Id64Set> {\n const cache = setType === \"always\" ? this._alwaysDrawn : this._neverDrawn;\n const getElements = categoryId\n ? (entry: CacheEntry | undefined) => {\n return entry?.get(modelId)?.get(categoryId) ?? new Set();\n }\n : (entry: CacheEntry | undefined) => {\n const modelEntry = entry?.get(modelId);\n const elements = new Set<Id64String>();\n for (const set of modelEntry?.values() ?? []) {\n set.forEach((id) => elements.add(id));\n }\n return elements;\n };\n\n return cache.pipe(map(getElements));\n }\n\n private createCacheEntryObservable(props: { event: BeEvent<() => void>; getSet(): Id64Set | undefined; id: string }) {\n const event = props.event;\n const resultSubject = new BehaviorSubject<CacheEntry | undefined>(undefined);\n\n const obs = merge(\n fromEventPattern(\n (handler) => event.addListener(handler),\n (handler) => event.removeListener(handler),\n ),\n this._forceUpdate,\n ).pipe(\n // Fire the observable once at the beginning\n startWith(undefined),\n // Stop listening to events when dispose() is called\n takeUntil(this._disposeSubject),\n // Reset result subject as soon as a new event is emitted.\n // This will make newly subscribed observers wait for the debounce period to pass\n // instead of consuming the cached value which at this point becomes invalid.\n tap(() => resultSubject.next(undefined)),\n // Check if cache updates are not suppressed.\n switchMap(() =>\n this._suppressors.pipe(\n filter((suppressors) => suppressors === 0),\n take(1),\n ),\n ),\n debounceTime(SET_CHANGE_DEBOUNCE_TIME),\n // Cancel pending request if dispose() is called.\n takeUntil(this._disposeSubject),\n // If multiple requests are sent at once, preserve only the result of the newest.\n switchMap(() => this.queryAlwaysOrNeverDrawnElementInfo(props.getSet(), props.id)),\n // Share the result by using a subject which always emits the saved result.\n share({\n connector: () => resultSubject,\n resetOnRefCountZero: false,\n }),\n // Wait until the result is available.\n first((x): x is CacheEntry => !!x),\n );\n return obs;\n }\n\n public dispose(): void {\n this._subscriptions.forEach((x) => x.unsubscribe());\n this._subscriptions = [];\n this._disposeSubject.next();\n }\n\n private queryAlwaysOrNeverDrawnElementInfo(set: Id64Set | undefined, requestId: string): Observable<CacheEntry> {\n const elementInfo = set?.size ? this.queryElementInfo([...set], requestId) : EMPTY;\n return elementInfo.pipe(\n reduce((state, val) => {\n let entry = state.get(val.modelId);\n if (!entry) {\n entry = new Map();\n state.set(val.modelId, entry);\n }\n pushToMap(entry, val.categoryId, val.elementId);\n return state;\n }, new Map<Id64String, Map<Id64String, Id64Set>>()),\n );\n }\n\n private queryElementInfo(elementIds: Id64Array, requestId: string): Observable<ElementInfo> {\n const executor = createECSqlQueryExecutor(this._viewport.iModel);\n const reader = executor.createQueryReader(\n {\n ctes: [\n `\n ElementInfo(elementId, modelId, categoryId, parentId) AS (\n SELECT\n ECInstanceId elementId,\n Model.Id modelId,\n Category.Id categoryId,\n Parent.Id parentId\n FROM bis.GeometricElement3d\n WHERE InVirtualSet(?, ECInstanceId)\n\n UNION ALL\n\n SELECT\n e.elementId,\n e.modelId,\n p.Category.Id categoryId,\n p.Parent.Id parentId\n FROM bis.GeometricElement3d p\n JOIN ElementInfo e ON p.ECInstanceId = e.parentId\n )\n `,\n ],\n ecsql: `\n SELECT elementId, modelId, categoryId\n FROM ElementInfo\n WHERE parentId IS NULL\n `,\n bindings: [{ type: \"idset\", value: elementIds }],\n },\n {\n restartToken: `ModelsTreeVisibilityHandler/${requestId}`,\n },\n );\n\n return from(reader).pipe(map((row) => ({ elementId: row.elementId, modelId: row.modelId, categoryId: row.categoryId })));\n }\n}\n"]}
|
package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export declare class ModelsTreeIdsCache {
|
|
|
10
10
|
private _subjectInfos;
|
|
11
11
|
private _parentSubjectIds;
|
|
12
12
|
private _modelInfos;
|
|
13
|
+
private _modelWithCategoryModeledElements;
|
|
13
14
|
private _modelKeyPaths;
|
|
14
15
|
private _subjectKeyPaths;
|
|
15
16
|
private _categoryKeyPaths;
|
|
@@ -32,9 +33,13 @@ export declare class ModelsTreeIdsCache {
|
|
|
32
33
|
createSubjectInstanceKeysPath(targetSubjectId: Id64String): Promise<HierarchyNodeIdentifiersPath>;
|
|
33
34
|
private queryModelElementCounts;
|
|
34
35
|
private queryModelCategories;
|
|
36
|
+
private queryModeledElements;
|
|
37
|
+
private getModelWithCategoryModeledElements;
|
|
35
38
|
private getModelInfos;
|
|
36
39
|
getModelCategories(modelId: Id64String): Promise<Id64Array>;
|
|
37
40
|
getModelElementCount(modelId: Id64String): Promise<number>;
|
|
41
|
+
hasSubModel(elementId: Id64String): Promise<boolean>;
|
|
42
|
+
getCategoriesModeledElements(modelId: Id64String, categoryIds: Id64Array): Promise<Id64Array>;
|
|
38
43
|
createModelInstanceKeyPaths(modelId: Id64String): Promise<HierarchyNodeIdentifiersPath[]>;
|
|
39
44
|
private queryCategoryElementCounts;
|
|
40
45
|
getCategoryElementsCount(modelId: Id64String, categoryId: Id64String): Promise<number>;
|