@itwin/tree-widget-react 4.0.0-alpha.6 → 4.0.0-alpha.7
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 +22 -1
- package/README.md +2 -1
- package/lib/esm/tree-widget-react/TreeWidget.js +1 -1
- package/lib/esm/tree-widget-react/TreeWidget.js.map +1 -1
- package/lib/esm/tree-widget-react/components/tree-header/SearchBox.d.ts +1 -0
- package/lib/esm/tree-widget-react/components/tree-header/SearchBox.js +1 -0
- 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 +2 -0
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.d.ts +9 -2
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js +50 -4
- 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/CategoriesTreeComponent.js +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeComponent.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.d.ts +17 -3
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeDefinition.js +561 -161
- 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.d.ts +6 -2
- package/lib/esm/tree-widget-react/components/trees/categories-tree/UseCategoriesTree.js +115 -40
- 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 +30 -15
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js +192 -38
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.d.ts +18 -3
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.js +30 -3
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeNode.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeVisibilityHandler.d.ts +24 -0
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeVisibilityHandler.js +785 -0
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeVisibilityHandler.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/FilteredTree.d.ts +39 -0
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/FilteredTree.js +221 -0
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/FilteredTree.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.d.ts +5 -17
- package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js +5 -62
- package/lib/esm/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/UseHierarchyVisibility.d.ts +2 -0
- package/lib/esm/tree-widget-react/components/trees/common/UseHierarchyVisibility.js +4 -2
- package/lib/esm/tree-widget-react/components/trees/common/UseHierarchyVisibility.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/UseNodeHighlighting.d.ts +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/UseNodeHighlighting.js +2 -1
- package/lib/esm/tree-widget-react/components/trees/common/UseNodeHighlighting.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/UseTelemetryContext.d.ts +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/UseTelemetryContext.js +2 -1
- package/lib/esm/tree-widget-react/components/trees/common/UseTelemetryContext.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/Utils.d.ts +33 -23
- package/lib/esm/tree-widget-react/components/trees/common/Utils.js +60 -47
- package/lib/esm/tree-widget-react/components/trees/common/Utils.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/BaseTreeRenderer.js +3 -3
- package/lib/esm/tree-widget-react/components/trees/common/components/BaseTreeRenderer.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/Delayed.d.ts +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/components/Delayed.js +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/components/Delayed.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/ProgressOverlay.d.ts +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/components/ProgressOverlay.js +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/components/ProgressOverlay.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/Tree.css +2 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/Tree.js +4 -4
- 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/UseVisibilityButtonHandler.d.ts +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/components/UseVisibilityButtonHandler.js +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/components/UseVisibilityButtonHandler.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/VisibilityTree.js +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/VisibilityTree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/VisibilityTreeRenderer.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/internal/AlwaysAndNeverDrawnElementInfo.d.ts +44 -0
- package/lib/esm/tree-widget-react/components/trees/{models-tree → common}/internal/AlwaysAndNeverDrawnElementInfo.js +81 -31
- package/lib/esm/tree-widget-react/components/trees/common/internal/AlwaysAndNeverDrawnElementInfo.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/internal/ClassNameDefinitions.d.ts +33 -0
- package/lib/esm/tree-widget-react/components/trees/common/internal/ClassNameDefinitions.js +37 -0
- package/lib/esm/tree-widget-react/components/trees/common/internal/ClassNameDefinitions.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/internal/ModelCategoryElementsCountCache.d.ts +16 -0
- package/lib/esm/tree-widget-react/components/trees/common/internal/ModelCategoryElementsCountCache.js +72 -0
- package/lib/esm/tree-widget-react/components/trees/common/internal/ModelCategoryElementsCountCache.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/{Rxjs.d.ts → internal/Rxjs.d.ts} +9 -2
- package/lib/esm/tree-widget-react/components/trees/common/{Rxjs.js → internal/Rxjs.js} +9 -2
- package/lib/esm/tree-widget-react/components/trees/common/internal/Rxjs.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/{Tooltip.d.ts → internal/Tooltip.d.ts} +5 -1
- package/lib/esm/tree-widget-react/components/trees/common/{Tooltip.js → internal/Tooltip.js} +7 -1
- package/lib/esm/tree-widget-react/components/trees/common/internal/Tooltip.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/internal/Types.d.ts +14 -0
- package/lib/esm/tree-widget-react/components/trees/{categories-tree/internal/ClassNameDefinitions.js → common/internal/Types.js} +2 -7
- package/lib/esm/tree-widget-react/components/trees/common/internal/Types.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/internal/UseActiveViewport.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/{UseHierarchiesLocalization.d.ts → internal/UseHierarchiesLocalization.d.ts} +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/{UseHierarchiesLocalization.js → internal/UseHierarchiesLocalization.js} +6 -2
- package/lib/esm/tree-widget-react/components/trees/common/internal/UseHierarchiesLocalization.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/{UseHierarchyFiltering.d.ts → internal/UseHierarchyFiltering.d.ts} +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/{UseHierarchyFiltering.js → internal/UseHierarchyFiltering.js} +4 -3
- package/lib/esm/tree-widget-react/components/trees/common/internal/UseHierarchyFiltering.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/{UseIModelChangeListener.d.ts → internal/UseIModelChangeListener.d.ts} +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/{UseIModelChangeListener.js → internal/UseIModelChangeListener.js} +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/internal/UseIModelChangeListener.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/internal/Utils.d.ts +47 -0
- package/lib/esm/tree-widget-react/components/trees/common/internal/Utils.js +101 -0
- package/lib/esm/tree-widget-react/components/trees/common/internal/Utils.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/internal/VisibilityChangeEventListener.d.ts +20 -0
- package/lib/esm/tree-widget-react/components/trees/{models-tree → common}/internal/VisibilityChangeEventListener.js +17 -9
- package/lib/esm/tree-widget-react/components/trees/common/internal/VisibilityChangeEventListener.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/internal/VisibilityUtils.d.ts +82 -0
- package/lib/esm/tree-widget-react/components/trees/common/internal/VisibilityUtils.js +234 -0
- package/lib/esm/tree-widget-react/components/trees/common/internal/VisibilityUtils.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeDefinition.d.ts +1 -0
- package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeDefinition.js +1 -0
- package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTreeDefinition.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.d.ts +3 -1
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js +13 -9
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeComponent.d.ts +1 -1
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeComponent.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeDefinition.d.ts +13 -0
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeDefinition.js +39 -38
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTreeDefinition.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/internal/IModelContentTreeIdsCache.d.ts +5 -5
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/internal/IModelContentTreeIdsCache.js +25 -24
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/internal/IModelContentTreeIdsCache.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js +9 -5
- 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.js +1 -1
- 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/ModelsTreeDefinition.d.ts +7 -2
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js +73 -70
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeDefinition.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/UseModelsTree.js +47 -29
- 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/FilteredTree.d.ts +7 -9
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/FilteredTree.js +4 -6
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/FilteredTree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.d.ts +4 -5
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.js +54 -104
- 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 +0 -26
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js +75 -291
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
- package/lib/public/locales/en/TreeWidget.json +51 -6
- package/package.json +17 -18
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.d.ts +0 -37
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js +0 -214
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesVisibilityHandler.js.map +0 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.d.ts +0 -7
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/ClassNameDefinitions.js.map +0 -1
- package/lib/esm/tree-widget-react/components/trees/common/Rxjs.js.map +0 -1
- package/lib/esm/tree-widget-react/components/trees/common/Tooltip.js.map +0 -1
- package/lib/esm/tree-widget-react/components/trees/common/UseActiveViewport.js.map +0 -1
- package/lib/esm/tree-widget-react/components/trees/common/UseFiltering.d.ts +0 -11
- package/lib/esm/tree-widget-react/components/trees/common/UseFiltering.js +0 -24
- package/lib/esm/tree-widget-react/components/trees/common/UseFiltering.js.map +0 -1
- package/lib/esm/tree-widget-react/components/trees/common/UseHierarchiesLocalization.js.map +0 -1
- package/lib/esm/tree-widget-react/components/trees/common/UseHierarchyFiltering.js.map +0 -1
- package/lib/esm/tree-widget-react/components/trees/common/UseIModelChangeListener.js.map +0 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/Utils.d.ts +0 -7
- package/lib/esm/tree-widget-react/components/trees/models-tree/Utils.js +0 -21
- package/lib/esm/tree-widget-react/components/trees/models-tree/Utils.js.map +0 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.d.ts +0 -29
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/AlwaysAndNeverDrawnElementInfo.js.map +0 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/VisibilityChangeEventListener.d.ts +0 -12
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/VisibilityChangeEventListener.js.map +0 -1
- /package/lib/esm/tree-widget-react/components/trees/common/{UseActiveViewport.d.ts → internal/UseActiveViewport.d.ts} +0 -0
- /package/lib/esm/tree-widget-react/components/trees/common/{UseActiveViewport.js → internal/UseActiveViewport.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CategoriesVisibilityUtils.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"CategoriesVisibilityUtils.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/CategoriesVisibilityUtils.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAchG;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,UAAqB,EAAE,QAAkB;IAC/E,MAAM,qBAAqB,CAAC,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAChE,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,UAAqB,EAAE,QAAkB;IAC/E,MAAM,qBAAqB,CAAC,QAAQ,EAAE,UAAU,E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kB;IAClB,qBAAqB,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,wBAAwB,CAAC,QAAQ,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC;IAEtG,MAAM,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAC9D,CAAC","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 { enableCategoryDisplay, enableSubCategoryDisplay } from \"./internal/VisibilityUtils.js\";\n\nimport type { Id64Array, Id64String } from \"@itwin/core-bentley\";\nimport type { Viewport } from \"@itwin/core-frontend\";\n\n/**\n * Data structure that describes category.\n * @beta\n */\nexport interface CategoryInfo {\n categoryId: Id64String;\n subCategoryIds?: Id64Array;\n}\n\n/**\n * Enable display of all given categories.\n * @public\n */\nexport async function showAllCategories(categories: Id64Array, viewport: Viewport) {\n await enableCategoryDisplay(viewport, categories, true, true);\n}\n\n/**\n * Disable display of all given categories.\n * @public\n */\nexport async function hideAllCategories(categories: Id64Array, viewport: Viewport) {\n await enableCategoryDisplay(viewport, categories, false, true);\n}\n\n/**\n * Invert display of all given categories.\n * @public\n */\nexport async function invertAllCategories(categories: CategoryInfo[], viewport: Viewport) {\n const enabled = new Array<Id64String>();\n const disabled = new Array<Id64String>();\n const enabledSubCategories = new Array<Id64String>();\n const disabledSubCategories = new Array<Id64String>();\n\n for (const category of categories) {\n if (!viewport.view.viewsCategory(category.categoryId)) {\n disabled.push(category.categoryId);\n continue;\n }\n // First, we need to check if at least one subcategory is disabled. If it is true, then only subcategories should change display, not categories.\n if (category.subCategoryIds?.some((subCategory) => !viewport.isSubCategoryVisible(subCategory))) {\n for (const subCategory of category.subCategoryIds) {\n viewport.isSubCategoryVisible(subCategory) ? enabledSubCategories.push(subCategory) : disabledSubCategories.push(subCategory);\n }\n } else {\n enabled.push(category.categoryId);\n }\n }\n\n // Disable enabled\n enabledSubCategories.forEach((subCategory) => enableSubCategoryDisplay(viewport, subCategory, false));\n\n await enableCategoryDisplay(viewport, enabled, false, true);\n\n // Enable disabled\n disabledSubCategories.forEach((subCategory) => enableSubCategoryDisplay(viewport, subCategory, true));\n\n await enableCategoryDisplay(viewport, disabled, true, true);\n}\n"]}
|
|
@@ -29,6 +29,7 @@ export interface HierarchyVisibilityHandler extends IDisposable {
|
|
|
29
29
|
interface UseHierarchyVisibilityProps {
|
|
30
30
|
visibilityHandlerFactory: () => HierarchyVisibilityHandler;
|
|
31
31
|
}
|
|
32
|
+
/** @internal */
|
|
32
33
|
export declare function useHierarchyVisibility({ visibilityHandlerFactory, }: UseHierarchyVisibilityProps): TreeItemVisibilityButtonProps & {
|
|
33
34
|
triggerRefresh: () => void;
|
|
34
35
|
};
|
|
@@ -50,6 +51,7 @@ export type HierarchyVisibilityHandlerOverridableMethodProps<TFunc> = TFunc exte
|
|
|
50
51
|
* @beta
|
|
51
52
|
*/
|
|
52
53
|
export type HierarchyVisibilityHandlerOverridableMethod<TFunc> = TFunc extends (...args: any[]) => infer TResult ? (props: HierarchyVisibilityHandlerOverridableMethodProps<TFunc>) => TResult : never;
|
|
54
|
+
/** @internal */
|
|
53
55
|
export declare function createVisibilityHandlerResult<TResult, TOverrideProps>(handler: HierarchyVisibilityHandler, props: TOverrideProps, obs: Observable<TResult>, override: HierarchyVisibilityHandlerOverridableMethod<(props: TOverrideProps) => Promise<TResult>> | undefined): Observable<TResult>;
|
|
54
56
|
export {};
|
|
55
57
|
//# sourceMappingURL=UseHierarchyVisibility.d.ts.map
|
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
import { useEffect, useRef, useState } from "react";
|
|
6
6
|
import { asyncScheduler, defer, distinct, EMPTY, from, lastValueFrom, mergeMap, observeOn, onErrorResumeNextWith, Subject, takeUntil, tap, throttleTime, } from "rxjs";
|
|
7
7
|
import { useTelemetryContext } from "./UseTelemetryContext.js";
|
|
8
|
+
/** @internal */
|
|
8
9
|
export function useHierarchyVisibility({ visibilityHandlerFactory, }) {
|
|
9
10
|
const visibilityStatusMap = useRef(new Map());
|
|
10
11
|
const [state, setState] = useState({
|
|
11
|
-
getVisibilityButtonState: () => ({ state: "
|
|
12
|
+
getVisibilityButtonState: () => ({ state: "visible", isDisabled: true }),
|
|
12
13
|
onVisibilityButtonClick: () => { },
|
|
13
14
|
triggerRefresh: () => { },
|
|
14
15
|
});
|
|
@@ -86,7 +87,7 @@ function createStateGetter(map, calculateVisibility) {
|
|
|
86
87
|
const entry = map.current.get(node.id);
|
|
87
88
|
if (entry === undefined) {
|
|
88
89
|
calculateVisibility(node);
|
|
89
|
-
return { state: "
|
|
90
|
+
return { state: "visible", isDisabled: true };
|
|
90
91
|
}
|
|
91
92
|
if (entry.needsRefresh) {
|
|
92
93
|
calculateVisibility(node);
|
|
@@ -99,6 +100,7 @@ function createStateGetter(map, calculateVisibility) {
|
|
|
99
100
|
};
|
|
100
101
|
};
|
|
101
102
|
}
|
|
103
|
+
/** @internal */
|
|
102
104
|
export function createVisibilityHandlerResult(handler, props, obs, override) {
|
|
103
105
|
return override
|
|
104
106
|
? from(override({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseHierarchyVisibility.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/UseHierarchyVisibility.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EACL,cAAc,EACd,KAAK,EACL,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,aAAa,EACb,QAAQ,EACR,SAAS,EACT,qBAAqB,EACrB,OAAO,EACP,SAAS,EACT,GAAG,EACH,YAAY,GACb,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAsC/D,MAAM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,GAAG,KAAK,CAAC,MAAM,CAAC;QAC5B,OAAO;YACL,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,UAAU,EAAE,MAAM,CAAC,UAAU;SAC9B,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AA0BD,MAAM,UAAU,6BAA6B,CAC3C,OAAmC,EACnC,KAAqB,EACrB,GAAwB,EACxB,QAA8G;IAE9G,OAAO,QAAQ;QACb,CAAC,CAAC,IAAI,CACF,QAAQ,CAAC;YACP,GAAG,KAAK;YACR,sBAAsB,EAAE,KAAK,IAAI,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,EAAE,YAAY,EAAE,SAAoB,EAAE,CAAC;YAC9F,OAAO;SACR,CAAC,CACH;QACH,CAAC,CAAC,GAAG,CAAC;AACV,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, useRef, useState } from \"react\";\nimport {\n asyncScheduler,\n defer,\n distinct,\n EMPTY,\n from,\n lastValueFrom,\n mergeMap,\n observeOn,\n onErrorResumeNextWith,\n Subject,\n takeUntil,\n tap,\n throttleTime,\n} from \"rxjs\";\nimport { useTelemetryContext } from \"./UseTelemetryContext.js\";\n\nimport type { Observable } from \"rxjs\";\nimport type { MutableRefObject } from \"react\";\nimport type { BeEvent, IDisposable } from \"@itwin/core-bentley\";\nimport type { HierarchyNode, PresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport type { TreeItemVisibilityButtonProps } from \"./components/TreeNodeVisibilityButton.js\";\n\n/**\n * Data structure that describes instance visibility status.\n * @beta\n */\nexport interface VisibilityStatus {\n /** Instance visibility state. */\n state: \"visible\" | \"partial\" | \"hidden\";\n /** Specifies whether visibility changing is disabled or not. */\n isDisabled?: boolean;\n /** Tooltip that should be displayed when hovering over the visibility checkbox. */\n tooltip?: string;\n}\n\n/**\n * Handler that can be used to determine and change visibility of instances represented by tree nodes.\n * @beta\n */\nexport interface HierarchyVisibilityHandler extends IDisposable {\n /** Event used to notify tree about visibility changes from outside. */\n readonly onVisibilityChange: BeEvent<() => void>;\n /** Returns current visibility status for tree node. */\n getVisibilityStatus(node: HierarchyNode): Promise<VisibilityStatus> | VisibilityStatus;\n /** Changes visibility of the instance represented by tree node. */\n changeVisibility(node: HierarchyNode, on: boolean): Promise<void>;\n}\n\ninterface UseHierarchyVisibilityProps {\n visibilityHandlerFactory: () => HierarchyVisibilityHandler;\n}\n\nexport function useHierarchyVisibility({\n visibilityHandlerFactory,\n}: UseHierarchyVisibilityProps): TreeItemVisibilityButtonProps & { triggerRefresh: () => void } {\n const visibilityStatusMap = useRef(new Map<string, { node: PresentationHierarchyNode; status: VisibilityStatus; needsRefresh: boolean }>());\n const [state, setState] = useState<TreeItemVisibilityButtonProps & { triggerRefresh: () => void }>({\n getVisibilityButtonState: () => ({ state: \"hidden\", isDisabled: true }),\n onVisibilityButtonClick: () => {},\n triggerRefresh: () => {},\n });\n const { onFeatureUsed } = useTelemetryContext();\n\n useEffect(() => {\n visibilityStatusMap.current.clear();\n const handler = visibilityHandlerFactory();\n\n const visibilityChanged = new Subject<void>();\n const calculate = new Subject<PresentationHierarchyNode>();\n const calculateNodeStatus = (node: PresentationHierarchyNode) => {\n calculate.next(node);\n };\n\n const resetCache = () => {\n visibilityStatusMap.current.forEach((value) => {\n value.needsRefresh = true;\n });\n visibilityChanged.next();\n };\n\n const triggerCheckboxUpdate = () => {\n setState((prev) => ({\n ...prev,\n getCheckboxState: createStateGetter(visibilityStatusMap, calculateNodeStatus),\n }));\n };\n\n const subscription = calculate\n .pipe(\n distinct(undefined, visibilityChanged),\n observeOn(asyncScheduler),\n mergeMap((node) =>\n defer(async () => handler.getVisibilityStatus(node.nodeData)).pipe(\n tap({\n next: (status) => {\n visibilityStatusMap.current.set(node.id, {\n node,\n status,\n needsRefresh: false,\n });\n },\n }),\n takeUntil(visibilityChanged),\n onErrorResumeNextWith(EMPTY),\n ),\n ),\n throttleTime(100, undefined, { leading: false, trailing: true }),\n )\n .subscribe({\n next: () => {\n triggerCheckboxUpdate();\n },\n });\n\n const changeVisibility: TreeItemVisibilityButtonProps[\"onVisibilityButtonClick\"] = (node, visibilityState) => {\n onFeatureUsed({ featureId: \"visibility-change\", reportInteraction: true });\n // visible should become hidden, partial and hidden should become visible TODO: redo for clarity\n const on = visibilityState === \"visible\" ? false : true;\n void handler.changeVisibility(node.nodeData, on);\n const entry = visibilityStatusMap.current.get(node.id);\n if (!entry) {\n return;\n }\n entry.status.state = visibilityState;\n entry.status.tooltip = undefined;\n triggerCheckboxUpdate();\n };\n\n setState({\n onVisibilityButtonClick: changeVisibility,\n getVisibilityButtonState: createStateGetter(visibilityStatusMap, calculateNodeStatus),\n triggerRefresh: () => {\n resetCache();\n triggerCheckboxUpdate();\n },\n });\n\n const removeListener = handler.onVisibilityChange.addListener(() => {\n resetCache();\n triggerCheckboxUpdate();\n });\n\n return () => {\n subscription.unsubscribe();\n removeListener();\n handler.dispose();\n };\n }, [visibilityHandlerFactory, onFeatureUsed]);\n\n return state;\n}\n\nfunction createStateGetter(\n map: MutableRefObject<Map<string, { node: PresentationHierarchyNode; status: VisibilityStatus; needsRefresh: boolean }>>,\n calculateVisibility: (node: PresentationHierarchyNode) => void,\n): TreeItemVisibilityButtonProps[\"getVisibilityButtonState\"] {\n return (node) => {\n const entry = map.current.get(node.id);\n if (entry === undefined) {\n calculateVisibility(node);\n return { state: \"hidden\", isDisabled: true };\n }\n if (entry.needsRefresh) {\n calculateVisibility(node);\n }\n\n const status = entry.status;\n return {\n state: status.state,\n tooltip: status.tooltip,\n isDisabled: status.isDisabled,\n };\n };\n}\n\n/**\n * Properties for an overridden method of a `HierarchyVisibilityHandler` implementation.\n * @beta\n */\nexport type HierarchyVisibilityHandlerOverridableMethodProps<TFunc> = TFunc extends (props: infer TProps) => infer TResult\n ? TProps & {\n /** A callback that produces the value from the original implementation. */\n readonly originalImplementation: () => TResult;\n /**\n * Reference to the hierarchy based handler.\n * @note Calling `getVisibility` or `changeVisibility` of this object invokes the overridden implementation as well.\n */\n readonly handler: HierarchyVisibilityHandler;\n }\n : never;\n\n/**\n * Function type for an overridden method of `HierarchyVisibilityHandler`.\n * @beta\n */\nexport type HierarchyVisibilityHandlerOverridableMethod<TFunc> = TFunc extends (...args: any[]) => infer TResult\n ? (props: HierarchyVisibilityHandlerOverridableMethodProps<TFunc>) => TResult\n : never;\n\nexport function createVisibilityHandlerResult<TResult, TOverrideProps>(\n handler: HierarchyVisibilityHandler,\n props: TOverrideProps,\n obs: Observable<TResult>,\n override: HierarchyVisibilityHandlerOverridableMethod<(props: TOverrideProps) => Promise<TResult>> | undefined,\n): Observable<TResult> {\n return override\n ? from(\n override({\n ...props,\n originalImplementation: async () => lastValueFrom(obs, { defaultValue: undefined as TResult }),\n handler,\n }),\n )\n : obs;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"UseHierarchyVisibility.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/UseHierarchyVisibility.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpD,OAAO,EACL,cAAc,EACd,KAAK,EACL,QAAQ,EACR,KAAK,EACL,IAAI,EACJ,aAAa,EACb,QAAQ,EACR,SAAS,EACT,qBAAqB,EACrB,OAAO,EACP,SAAS,EACT,GAAG,EACH,YAAY,GACb,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAsC/D,gBAAgB;AAChB,MAAM,UAAU,sBAAsB,CAAC,EACrC,wBAAwB,GACI;IAC5B,MAAM,mBAAmB,GAAG,MAAM,CAAC,IAAI,GAAG,EAAgG,CAAC,CAAC;IAC5I,MAAM,CAAC,KAAK,EAA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C,UAAU;SAC9B,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AA0BD,gBAAgB;AAChB,MAAM,UAAU,6BAA6B,CAC3C,OAAmC,EACnC,KAAqB,EACrB,GAAwB,EACxB,QAA8G;IAE9G,OAAO,QAAQ;QACb,CAAC,CAAC,IAAI,CACF,QAAQ,CAAC;YACP,GAAG,KAAK;YACR,sBAAsB,EAAE,KAAK,IAAI,EAAE,CAAC,aAAa,CAAC,GAAG,EAAE,EAAE,YAAY,EAAE,SAAoB,EAAE,CAAC;YAC9F,OAAO;SACR,CAAC,CACH;QACH,CAAC,CAAC,GAAG,CAAC;AACV,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, useRef, useState } from \"react\";\nimport {\n asyncScheduler,\n defer,\n distinct,\n EMPTY,\n from,\n lastValueFrom,\n mergeMap,\n observeOn,\n onErrorResumeNextWith,\n Subject,\n takeUntil,\n tap,\n throttleTime,\n} from \"rxjs\";\nimport { useTelemetryContext } from \"./UseTelemetryContext.js\";\n\nimport type { Observable } from \"rxjs\";\nimport type { MutableRefObject } from \"react\";\nimport type { BeEvent, IDisposable } from \"@itwin/core-bentley\";\nimport type { HierarchyNode, PresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport type { TreeItemVisibilityButtonProps } from \"./components/TreeNodeVisibilityButton.js\";\n\n/**\n * Data structure that describes instance visibility status.\n * @beta\n */\nexport interface VisibilityStatus {\n /** Instance visibility state. */\n state: \"visible\" | \"partial\" | \"hidden\";\n /** Specifies whether visibility changing is disabled or not. */\n isDisabled?: boolean;\n /** Tooltip that should be displayed when hovering over the visibility checkbox. */\n tooltip?: string;\n}\n\n/**\n * Handler that can be used to determine and change visibility of instances represented by tree nodes.\n * @beta\n */\nexport interface HierarchyVisibilityHandler extends IDisposable {\n /** Event used to notify tree about visibility changes from outside. */\n readonly onVisibilityChange: BeEvent<() => void>;\n /** Returns current visibility status for tree node. */\n getVisibilityStatus(node: HierarchyNode): Promise<VisibilityStatus> | VisibilityStatus;\n /** Changes visibility of the instance represented by tree node. */\n changeVisibility(node: HierarchyNode, on: boolean): Promise<void>;\n}\n\ninterface UseHierarchyVisibilityProps {\n visibilityHandlerFactory: () => HierarchyVisibilityHandler;\n}\n\n/** @internal */\nexport function useHierarchyVisibility({\n visibilityHandlerFactory,\n}: UseHierarchyVisibilityProps): TreeItemVisibilityButtonProps & { triggerRefresh: () => void } {\n const visibilityStatusMap = useRef(new Map<string, { node: PresentationHierarchyNode; status: VisibilityStatus; needsRefresh: boolean }>());\n const [state, setState] = useState<TreeItemVisibilityButtonProps & { triggerRefresh: () => void }>({\n getVisibilityButtonState: () => ({ state: \"visible\", isDisabled: true }),\n onVisibilityButtonClick: () => {},\n triggerRefresh: () => {},\n });\n const { onFeatureUsed } = useTelemetryContext();\n\n useEffect(() => {\n visibilityStatusMap.current.clear();\n const handler = visibilityHandlerFactory();\n\n const visibilityChanged = new Subject<void>();\n const calculate = new Subject<PresentationHierarchyNode>();\n const calculateNodeStatus = (node: PresentationHierarchyNode) => {\n calculate.next(node);\n };\n\n const resetCache = () => {\n visibilityStatusMap.current.forEach((value) => {\n value.needsRefresh = true;\n });\n visibilityChanged.next();\n };\n\n const triggerCheckboxUpdate = () => {\n setState((prev) => ({\n ...prev,\n getCheckboxState: createStateGetter(visibilityStatusMap, calculateNodeStatus),\n }));\n };\n\n const subscription = calculate\n .pipe(\n distinct(undefined, visibilityChanged),\n observeOn(asyncScheduler),\n mergeMap((node) =>\n defer(async () => handler.getVisibilityStatus(node.nodeData)).pipe(\n tap({\n next: (status) => {\n visibilityStatusMap.current.set(node.id, {\n node,\n status,\n needsRefresh: false,\n });\n },\n }),\n takeUntil(visibilityChanged),\n onErrorResumeNextWith(EMPTY),\n ),\n ),\n throttleTime(100, undefined, { leading: false, trailing: true }),\n )\n .subscribe({\n next: () => {\n triggerCheckboxUpdate();\n },\n });\n\n const changeVisibility: TreeItemVisibilityButtonProps[\"onVisibilityButtonClick\"] = (node, visibilityState) => {\n onFeatureUsed({ featureId: \"visibility-change\", reportInteraction: true });\n // visible should become hidden, partial and hidden should become visible TODO: redo for clarity\n const on = visibilityState === \"visible\" ? false : true;\n void handler.changeVisibility(node.nodeData, on);\n const entry = visibilityStatusMap.current.get(node.id);\n if (!entry) {\n return;\n }\n entry.status.state = visibilityState;\n entry.status.tooltip = undefined;\n triggerCheckboxUpdate();\n };\n\n setState({\n onVisibilityButtonClick: changeVisibility,\n getVisibilityButtonState: createStateGetter(visibilityStatusMap, calculateNodeStatus),\n triggerRefresh: () => {\n resetCache();\n triggerCheckboxUpdate();\n },\n });\n\n const removeListener = handler.onVisibilityChange.addListener(() => {\n resetCache();\n triggerCheckboxUpdate();\n });\n\n return () => {\n subscription.unsubscribe();\n removeListener();\n handler.dispose();\n };\n }, [visibilityHandlerFactory, onFeatureUsed]);\n\n return state;\n}\n\nfunction createStateGetter(\n map: MutableRefObject<Map<string, { node: PresentationHierarchyNode; status: VisibilityStatus; needsRefresh: boolean }>>,\n calculateVisibility: (node: PresentationHierarchyNode) => void,\n): TreeItemVisibilityButtonProps[\"getVisibilityButtonState\"] {\n return (node) => {\n const entry = map.current.get(node.id);\n if (entry === undefined) {\n calculateVisibility(node);\n return { state: \"visible\", isDisabled: true };\n }\n if (entry.needsRefresh) {\n calculateVisibility(node);\n }\n\n const status = entry.status;\n return {\n state: status.state,\n tooltip: status.tooltip,\n isDisabled: status.isDisabled,\n };\n };\n}\n\n/**\n * Properties for an overridden method of a `HierarchyVisibilityHandler` implementation.\n * @beta\n */\nexport type HierarchyVisibilityHandlerOverridableMethodProps<TFunc> = TFunc extends (props: infer TProps) => infer TResult\n ? TProps & {\n /** A callback that produces the value from the original implementation. */\n readonly originalImplementation: () => TResult;\n /**\n * Reference to the hierarchy based handler.\n * @note Calling `getVisibility` or `changeVisibility` of this object invokes the overridden implementation as well.\n */\n readonly handler: HierarchyVisibilityHandler;\n }\n : never;\n\n/**\n * Function type for an overridden method of `HierarchyVisibilityHandler`.\n * @beta\n */\nexport type HierarchyVisibilityHandlerOverridableMethod<TFunc> = TFunc extends (...args: any[]) => infer TResult\n ? (props: HierarchyVisibilityHandlerOverridableMethodProps<TFunc>) => TResult\n : never;\n\n/** @internal */\nexport function createVisibilityHandlerResult<TResult, TOverrideProps>(\n handler: HierarchyVisibilityHandler,\n props: TOverrideProps,\n obs: Observable<TResult>,\n override: HierarchyVisibilityHandlerOverridableMethod<(props: TOverrideProps) => Promise<TResult>> | undefined,\n): Observable<TResult> {\n return override\n ? from(\n override({\n ...props,\n originalImplementation: async () => lastValueFrom(obs, { defaultValue: undefined as TResult }),\n handler,\n }),\n )\n : obs;\n}\n"]}
|
|
@@ -15,6 +15,7 @@ interface UseNodeHighlightingResult {
|
|
|
15
15
|
activeNodeId?: string;
|
|
16
16
|
getLabel: (node: PresentationHierarchyNode) => React.ReactElement;
|
|
17
17
|
}
|
|
18
|
+
/** @internal */
|
|
18
19
|
export declare function useNodeHighlighting({ rootNodes, highlight }: UseNodeHighlightingProps): UseNodeHighlightingResult;
|
|
19
20
|
export {};
|
|
20
21
|
//# sourceMappingURL=UseNodeHighlighting.d.ts.map
|
|
@@ -5,7 +5,8 @@ import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
|
5
5
|
*--------------------------------------------------------------------------------------------*/
|
|
6
6
|
import { useCallback, useEffect, useRef, useState } from "react";
|
|
7
7
|
import { isPresentationHierarchyNode } from "@itwin/presentation-hierarchies-react";
|
|
8
|
-
import { useLatest } from "./Utils.js";
|
|
8
|
+
import { useLatest } from "./internal/Utils.js";
|
|
9
|
+
/** @internal */
|
|
9
10
|
export function useNodeHighlighting({ rootNodes, highlight }) {
|
|
10
11
|
const state = useRef({ nodeInfoMap: new Map(), totalMatches: 0 });
|
|
11
12
|
const [activeNodeId, setActiveNodeId] = useState();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseNodeHighlighting.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/UseNodeHighlighting.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,2BAA2B,EAAE,MAAM,uCAAuC,CAAC;AACpF,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AA2CvC,MAAM,UAAU,mBAAmB,CAAC,EAAE,SAAS,EAAE,SAAS,EAA4B;IACpF,MAAM,KAAK,GAAG,MAAM,CAAiB,EAAE,WAAW,EAAE,IAAI,GAAG,EAAE,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC,CAAC;IAClF,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,EAAsB,CAAC;IACvE,MAAM,mBAAmB,GAAG,SAAS,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;IACnE,MAAM,eAAe,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC;IAChD,MAAM,qBAAqB,GAAG,SAAS,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAC;IACvE,MAAM,UAAU,GAAG,SAAS,EAAE,IAAI,CAAC;IAEnC,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,GACpC,SAAS,IAAI,UAAU;YACrB,CAAC,CAAC,qBAAqB,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,CAAC,OAAO,EAAE,eAAe,CAAC,OAAO,EAAE,mBAAmB,CAAC,OAAO,CAAC;YACnH,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,IAAI,GAAG,EAAE,EAAE,YAAY,EAAE,CAAC,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC;QAE7E,KAAK,CAAC,OAA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Y,GAAuB,EAAE,CAAC;IAC5C,IAAI,SAAoE,CAAC;IACzE,IAAI,cAAkC,CAAC;IAEvC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACtC,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACxB,MAAM,QAAQ,GAAG,CAAC,KAAK,WAAW,CAAC;QACnC,IAAI,SAAS,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,KAAK,KAAK,CAAC,KAAK,IAAI,CAAC,QAAQ,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE;YACvF,SAAS,CAAC,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;YAC/B,SAAS;SACV;QACD,QAAQ,IAAI,CAAC,cAAc,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;QACnD,MAAM,QAAQ,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC;QACxD,SAAS,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;QACzC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;KAC7B;IACD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,CAAC;AAC1C,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, useRef, useState } from \"react\";\nimport { isPresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport { useLatest } from \"./Utils.js\";\n\nimport type { PresentationHierarchyNode, PresentationTreeNode } from \"@itwin/presentation-hierarchies-react\";\n\n/** @beta */\nexport interface HighlightInfo {\n text: string;\n}\n\ninterface UseNodeHighlightingProps {\n rootNodes: PresentationTreeNode[] | undefined;\n // TODO: move activeMatchIndex and onHighlightChanged to HighlightInfo when it's implemented.\n highlight?: HighlightInfo & {\n activeMatchIndex?: number;\n onHighlightChanged?: (activeMatchIndex: number, matches: number) => void;\n };\n}\n\ninterface HighlightedChunk {\n start: number;\n end: number;\n}\n\ninterface NodeChunkInfo {\n chunks: HighlightedChunk[];\n activeChunkIndex?: number;\n}\n\ninterface NodeHighlightInfo {\n startIndex: number;\n matches: HighlightedChunk[];\n}\n\ninterface HighlightState {\n nodeInfoMap: Map<string, NodeHighlightInfo>;\n totalMatches: number;\n}\n\ninterface UseNodeHighlightingResult {\n activeNodeId?: string;\n getLabel: (node: PresentationHierarchyNode) => React.ReactElement;\n}\n\nexport function useNodeHighlighting({ rootNodes, highlight }: UseNodeHighlightingProps): UseNodeHighlightingResult {\n const state = useRef<HighlightState>({ nodeInfoMap: new Map(), totalMatches: 0 });\n const [activeNodeId, setActiveNodeId] = useState<string | undefined>();\n const activeMatchIndexRef = useLatest(highlight?.activeMatchIndex);\n const activeNodeIdRef = useLatest(activeNodeId);\n const onHighlightChangedRef = useLatest(highlight?.onHighlightChanged);\n const searchText = highlight?.text;\n\n useEffect(() => {\n const { state: newState, activeIndex } =\n rootNodes && searchText\n ? computeHighlightState(rootNodes, searchText, state.current, activeNodeIdRef.current, activeMatchIndexRef.current)\n : { state: { nodeInfoMap: new Map(), totalMatches: 0 }, activeIndex: 0 };\n\n state.current = newState;\n if (newState.totalMatches === 0) {\n setActiveNodeId(undefined);\n }\n onHighlightChangedRef.current?.(newState.totalMatches === 0 ? 0 : activeIndex, newState.totalMatches);\n }, [rootNodes, searchText, activeNodeIdRef, activeMatchIndexRef, onHighlightChangedRef]);\n\n useEffect(() => {\n for (const nodeId of state.current.nodeInfoMap.keys()) {\n if (getNodeChunkInfo(state.current, nodeId, highlight?.activeMatchIndex)?.activeChunkIndex !== undefined) {\n setActiveNodeId(nodeId);\n }\n }\n }, [highlight?.activeMatchIndex]);\n\n const getLabel = useCallback(\n (node: PresentationHierarchyNode) => {\n const chunkInfo = getNodeChunkInfo(state.current, node.id, highlight?.activeMatchIndex);\n if (searchText && chunkInfo) {\n return <>{markChunks(node.label, chunkInfo.chunks, chunkInfo.activeChunkIndex)}</>;\n }\n return <span>{node.label}</span>;\n },\n [searchText, highlight?.activeMatchIndex],\n );\n\n return { activeNodeId, getLabel };\n}\n\nfunction getNodeChunkInfo(state: HighlightState, nodeId: string, activeIndex?: number): NodeChunkInfo | undefined {\n const info = state.nodeInfoMap.get(nodeId);\n if (!info) {\n return undefined;\n }\n if (activeIndex === undefined) {\n return { chunks: info.matches };\n }\n const isActive = info && activeIndex >= info.startIndex && activeIndex < info.startIndex + info.matches.length;\n return isActive ? { activeChunkIndex: activeIndex - info.startIndex, chunks: info.matches } : { chunks: info.matches };\n}\n\nfunction computeHighlightState(rootNodes: PresentationTreeNode[], searchText: string, state: HighlightState, activeNodeId?: string, activeMatchIndex?: number) {\n const newState: HighlightState = { nodeInfoMap: new Map(), totalMatches: 0 };\n let newActiveIndex = activeMatchIndex ?? 0;\n\n const computeHighlightStateRecursively = (nodes: Array<PresentationTreeNode>) => {\n nodes.forEach((node) => {\n if (!isPresentationHierarchyNode(node)) {\n return;\n }\n\n const matches = findChunks(node.label, searchText);\n newState.nodeInfoMap.set(node.id, { startIndex: newState.totalMatches, matches });\n newState.totalMatches += matches.length;\n\n if (typeof node.children !== \"boolean\") {\n computeHighlightStateRecursively(node.children);\n }\n });\n };\n\n computeHighlightStateRecursively(rootNodes);\n\n // update active index to not cause active chunk jumps when hierarchy changes\n if (activeNodeId && newActiveIndex !== 0) {\n const activeNodeInfo = getNodeChunkInfo(state, activeNodeId, activeMatchIndex);\n const updatedInfo = newState.nodeInfoMap.get(activeNodeId);\n\n if (updatedInfo && activeNodeInfo?.activeChunkIndex !== undefined) {\n newActiveIndex = updatedInfo.startIndex + activeNodeInfo.activeChunkIndex;\n }\n }\n\n return { state: newState, activeIndex: newActiveIndex };\n}\n\nfunction findChunks(text: string, searchText: string): HighlightedChunk[] {\n const chunks: HighlightedChunk[] = [];\n\n const contentText = text.toLowerCase();\n const inputText = searchText.toLowerCase();\n let index = contentText.indexOf(inputText);\n\n while (index !== -1) {\n chunks.push({ start: index, end: index + inputText.length });\n index = contentText.indexOf(inputText, index + 1);\n }\n\n return chunks;\n}\n\nfunction markChunks(text: string, chunks: HighlightedChunk[], activeChunk?: number) {\n const markedText: React.ReactElement[] = [];\n let previousIndex = 0;\n\n const { mergedChunks, newActiveIndex } = mergeChunks(chunks, activeChunk);\n\n for (let i = 0; i < mergedChunks.length; i++) {\n const { start, end } = mergedChunks[i];\n\n // add unmarked text between previous chunk and current one\n const nonMarkedText = text.substring(previousIndex, start);\n nonMarkedText.length && markedText.push(<span key={previousIndex}>{nonMarkedText}</span>);\n\n // add marked chunk text\n markedText.push(\n <mark key={start} className={i === newActiveIndex ? \"tw-active-match-highlight\" : undefined}>\n {text.substring(start, end)}\n </mark>,\n );\n previousIndex = end;\n }\n\n // add unmarked text after last chunk\n const lastNonMarkedText = text.substring(previousIndex, text.length);\n lastNonMarkedText.length && markedText.push(<span key={previousIndex}>{lastNonMarkedText}</span>);\n\n return markedText;\n}\n\nfunction mergeChunks(chunks: HighlightedChunk[], activeChunk?: number) {\n const mergedChunks: HighlightedChunk[] = [];\n let lastChunk: { isActive: boolean; info: HighlightedChunk } | undefined;\n let newActiveIndex: number | undefined;\n\n for (let i = 0; i < chunks.length; i++) {\n const chunk = chunks[i];\n const isActive = i === activeChunk;\n if (lastChunk && lastChunk.info.end === chunk.start && !isActive && !lastChunk.isActive) {\n lastChunk.info.end = chunk.end;\n continue;\n }\n isActive && (newActiveIndex = mergedChunks.length);\n const newChunk = { start: chunk.start, end: chunk.end };\n lastChunk = { isActive, info: newChunk };\n mergedChunks.push(newChunk);\n }\n return { mergedChunks, newActiveIndex };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"UseNodeHighlighting.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common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KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACtC,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;QACxB,MAAM,QAAQ,GAAG,CAAC,KAAK,WAAW,CAAC;QACnC,IAAI,SAAS,IAAI,SAAS,CAAC,IAAI,CAAC,GAAG,KAAK,KAAK,CAAC,KAAK,IAAI,CAAC,QAAQ,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE;YACvF,SAAS,CAAC,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;YAC/B,SAAS;SACV;QACD,QAAQ,IAAI,CAAC,cAAc,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC;QACnD,MAAM,QAAQ,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,CAAC;QACxD,SAAS,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;QACzC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;KAC7B;IACD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,CAAC;AAC1C,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, useRef, useState } from \"react\";\nimport { isPresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport { useLatest } from \"./internal/Utils.js\";\n\nimport type { PresentationHierarchyNode, PresentationTreeNode } from \"@itwin/presentation-hierarchies-react\";\n\n/** @beta */\nexport interface HighlightInfo {\n text: string;\n}\n\ninterface UseNodeHighlightingProps {\n rootNodes: PresentationTreeNode[] | undefined;\n // TODO: move activeMatchIndex and onHighlightChanged to HighlightInfo when it's implemented.\n highlight?: HighlightInfo & {\n activeMatchIndex?: number;\n onHighlightChanged?: (activeMatchIndex: number, matches: number) => void;\n };\n}\n\ninterface HighlightedChunk {\n start: number;\n end: number;\n}\n\ninterface NodeChunkInfo {\n chunks: HighlightedChunk[];\n activeChunkIndex?: number;\n}\n\ninterface NodeHighlightInfo {\n startIndex: number;\n matches: HighlightedChunk[];\n}\n\ninterface HighlightState {\n nodeInfoMap: Map<string, NodeHighlightInfo>;\n totalMatches: number;\n}\n\ninterface UseNodeHighlightingResult {\n activeNodeId?: string;\n getLabel: (node: PresentationHierarchyNode) => React.ReactElement;\n}\n\n/** @internal */\nexport function useNodeHighlighting({ rootNodes, highlight }: UseNodeHighlightingProps): UseNodeHighlightingResult {\n const state = useRef<HighlightState>({ nodeInfoMap: new Map(), totalMatches: 0 });\n const [activeNodeId, setActiveNodeId] = useState<string | undefined>();\n const activeMatchIndexRef = useLatest(highlight?.activeMatchIndex);\n const activeNodeIdRef = useLatest(activeNodeId);\n const onHighlightChangedRef = useLatest(highlight?.onHighlightChanged);\n const searchText = highlight?.text;\n\n useEffect(() => {\n const { state: newState, activeIndex } =\n rootNodes && searchText\n ? computeHighlightState(rootNodes, searchText, state.current, activeNodeIdRef.current, activeMatchIndexRef.current)\n : { state: { nodeInfoMap: new Map(), totalMatches: 0 }, activeIndex: 0 };\n\n state.current = newState;\n if (newState.totalMatches === 0) {\n setActiveNodeId(undefined);\n }\n onHighlightChangedRef.current?.(newState.totalMatches === 0 ? 0 : activeIndex, newState.totalMatches);\n }, [rootNodes, searchText, activeNodeIdRef, activeMatchIndexRef, onHighlightChangedRef]);\n\n useEffect(() => {\n for (const nodeId of state.current.nodeInfoMap.keys()) {\n if (getNodeChunkInfo(state.current, nodeId, highlight?.activeMatchIndex)?.activeChunkIndex !== undefined) {\n setActiveNodeId(nodeId);\n }\n }\n }, [highlight?.activeMatchIndex]);\n\n const getLabel = useCallback(\n (node: PresentationHierarchyNode) => {\n const chunkInfo = getNodeChunkInfo(state.current, node.id, highlight?.activeMatchIndex);\n if (searchText && chunkInfo) {\n return <>{markChunks(node.label, chunkInfo.chunks, chunkInfo.activeChunkIndex)}</>;\n }\n return <span>{node.label}</span>;\n },\n [searchText, highlight?.activeMatchIndex],\n );\n\n return { activeNodeId, getLabel };\n}\n\nfunction getNodeChunkInfo(state: HighlightState, nodeId: string, activeIndex?: number): NodeChunkInfo | undefined {\n const info = state.nodeInfoMap.get(nodeId);\n if (!info) {\n return undefined;\n }\n if (activeIndex === undefined) {\n return { chunks: info.matches };\n }\n const isActive = info && activeIndex >= info.startIndex && activeIndex < info.startIndex + info.matches.length;\n return isActive ? { activeChunkIndex: activeIndex - info.startIndex, chunks: info.matches } : { chunks: info.matches };\n}\n\nfunction computeHighlightState(rootNodes: PresentationTreeNode[], searchText: string, state: HighlightState, activeNodeId?: string, activeMatchIndex?: number) {\n const newState: HighlightState = { nodeInfoMap: new Map(), totalMatches: 0 };\n let newActiveIndex = activeMatchIndex ?? 0;\n\n const computeHighlightStateRecursively = (nodes: Array<PresentationTreeNode>) => {\n nodes.forEach((node) => {\n if (!isPresentationHierarchyNode(node)) {\n return;\n }\n\n const matches = findChunks(node.label, searchText);\n newState.nodeInfoMap.set(node.id, { startIndex: newState.totalMatches, matches });\n newState.totalMatches += matches.length;\n\n if (typeof node.children !== \"boolean\") {\n computeHighlightStateRecursively(node.children);\n }\n });\n };\n\n computeHighlightStateRecursively(rootNodes);\n\n // update active index to not cause active chunk jumps when hierarchy changes\n if (activeNodeId && newActiveIndex !== 0) {\n const activeNodeInfo = getNodeChunkInfo(state, activeNodeId, activeMatchIndex);\n const updatedInfo = newState.nodeInfoMap.get(activeNodeId);\n\n if (updatedInfo && activeNodeInfo?.activeChunkIndex !== undefined) {\n newActiveIndex = updatedInfo.startIndex + activeNodeInfo.activeChunkIndex;\n }\n }\n\n return { state: newState, activeIndex: newActiveIndex };\n}\n\nfunction findChunks(text: string, searchText: string): HighlightedChunk[] {\n const chunks: HighlightedChunk[] = [];\n\n const contentText = text.toLowerCase();\n const inputText = searchText.toLowerCase();\n let index = contentText.indexOf(inputText);\n\n while (index !== -1) {\n chunks.push({ start: index, end: index + inputText.length });\n index = contentText.indexOf(inputText, index + 1);\n }\n\n return chunks;\n}\n\nfunction markChunks(text: string, chunks: HighlightedChunk[], activeChunk?: number) {\n const markedText: React.ReactElement[] = [];\n let previousIndex = 0;\n\n const { mergedChunks, newActiveIndex } = mergeChunks(chunks, activeChunk);\n\n for (let i = 0; i < mergedChunks.length; i++) {\n const { start, end } = mergedChunks[i];\n\n // add unmarked text between previous chunk and current one\n const nonMarkedText = text.substring(previousIndex, start);\n nonMarkedText.length && markedText.push(<span key={previousIndex}>{nonMarkedText}</span>);\n\n // add marked chunk text\n markedText.push(\n <mark key={start} className={i === newActiveIndex ? \"tw-active-match-highlight\" : undefined}>\n {text.substring(start, end)}\n </mark>,\n );\n previousIndex = end;\n }\n\n // add unmarked text after last chunk\n const lastNonMarkedText = text.substring(previousIndex, text.length);\n lastNonMarkedText.length && markedText.push(<span key={previousIndex}>{lastNonMarkedText}</span>);\n\n return markedText;\n}\n\nfunction mergeChunks(chunks: HighlightedChunk[], activeChunk?: number) {\n const mergedChunks: HighlightedChunk[] = [];\n let lastChunk: { isActive: boolean; info: HighlightedChunk } | undefined;\n let newActiveIndex: number | undefined;\n\n for (let i = 0; i < chunks.length; i++) {\n const chunk = chunks[i];\n const isActive = i === activeChunk;\n if (lastChunk && lastChunk.info.end === chunk.start && !isActive && !lastChunk.isActive) {\n lastChunk.info.end = chunk.end;\n continue;\n }\n isActive && (newActiveIndex = mergedChunks.length);\n const newChunk = { start: chunk.start, end: chunk.end };\n lastChunk = { isActive, info: newChunk };\n mergedChunks.push(newChunk);\n }\n return { mergedChunks, newActiveIndex };\n}\n"]}
|
|
@@ -18,6 +18,7 @@ export interface TelemetryContextProviderProps {
|
|
|
18
18
|
}
|
|
19
19
|
/** @beta */
|
|
20
20
|
export declare function TelemetryContextProvider({ children, onPerformanceMeasured, onFeatureUsed, componentIdentifier, }: PropsWithChildren<TelemetryContextProviderProps>): import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
/** @internal */
|
|
21
22
|
export declare function useTelemetryContext(): TelemetryContext;
|
|
22
23
|
interface UseReportingActionProps<TAction> {
|
|
23
24
|
action: TAction;
|
|
@@ -4,7 +4,7 @@ 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 { createContext, useCallback, useContext, useMemo } from "react";
|
|
7
|
-
import { useLatest } from "./Utils.js";
|
|
7
|
+
import { useLatest } from "./internal/Utils.js";
|
|
8
8
|
const telemetryContext = createContext(undefined);
|
|
9
9
|
/** @beta */
|
|
10
10
|
export function TelemetryContextProvider({ children, onPerformanceMeasured, onFeatureUsed, componentIdentifier, }) {
|
|
@@ -29,6 +29,7 @@ const defaultContextValue = {
|
|
|
29
29
|
onPerformanceMeasured: () => { },
|
|
30
30
|
onFeatureUsed: () => { },
|
|
31
31
|
};
|
|
32
|
+
/** @internal */
|
|
32
33
|
export function useTelemetryContext() {
|
|
33
34
|
return useContext(telemetryContext) ?? defaultContextValue;
|
|
34
35
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseTelemetryContext.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/UseTelemetryContext.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AACxE,OAAO,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"UseTelemetryContext.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/UseTelemetryContext.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,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C,OAAO,UAAU,CAAC,gBAAgB,CAAC,IAAI,mBAAmB,CAAC;AAC7D,CAAC;AAOD,gBAAgB;AAChB,MAAM,UAAU,kBAAkB,CAA2C,EAAE,MAAM,EAAE,SAAS,EAAoC;IAClI,MAAM,EAAE,aAAa,EAAE,GAAG,mBAAmB,EAAE,CAAC;IAChD,OAAO,WAAW,CAChB,CAAC,GAAG,IAAI,EAAE,EAAE;QACV,aAAa,CAAC,EAAE,SAAS,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC;QACtD,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;IAClB,CAAC,EACD,CAAC,MAAM,EAAE,SAAS,EAAE,aAAa,CAAC,CACnC,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 { createContext, useCallback, useContext, useMemo } from \"react\";\nimport { useLatest } from \"./internal/Utils.js\";\n\nimport type { PropsWithChildren } from \"react\";\n\ntype TrackedFeatures =\n | \"visibility-change\"\n | \"hierarchy-level-filtering\"\n | \"filtering\"\n | \"hierarchy-level-size-limit-hit\"\n | \"zoom-to-node\"\n | \"error-timeout\"\n | \"error-unknown\";\n\ninterface TelemetryContext {\n onPerformanceMeasured: (featureId: string, duration: number) => void;\n onFeatureUsed: (props: { featureId?: TrackedFeatures; reportInteraction: boolean }) => void;\n}\n\nconst telemetryContext = createContext<TelemetryContext | undefined>(undefined);\n\n/** @beta */\nexport interface TelemetryContextProviderProps {\n /** Callback that is invoked when performance of tracked feature is measured. */\n onPerformanceMeasured?: (featureId: string, duration: number) => void;\n /** Callback that is invoked when a tracked feature is used. */\n onFeatureUsed?: (featureId: string) => void;\n /** Unique identifier that is appended to feature id to help track which component used that feature. */\n componentIdentifier: string;\n}\n\n/** @beta */\nexport function TelemetryContextProvider({\n children,\n onPerformanceMeasured,\n onFeatureUsed,\n componentIdentifier,\n}: PropsWithChildren<TelemetryContextProviderProps>) {\n const onPerformanceMeasuredRef = useLatest(onPerformanceMeasured);\n const onFeatureUsedRef = useLatest(onFeatureUsed);\n\n const contextValue = useMemo<TelemetryContext>(() => {\n return {\n onPerformanceMeasured: (featureId, duration) => onPerformanceMeasuredRef.current?.(`${componentIdentifier}-${featureId}`, duration),\n onFeatureUsed: ({ featureId, reportInteraction }) => {\n if (reportInteraction !== false) {\n onFeatureUsedRef.current?.(`use-${componentIdentifier}`);\n }\n if (featureId) {\n onFeatureUsedRef.current?.(`${componentIdentifier}-${featureId}`);\n }\n },\n };\n }, [componentIdentifier, onPerformanceMeasuredRef, onFeatureUsedRef]);\n\n return <telemetryContext.Provider value={contextValue}>{children}</telemetryContext.Provider>;\n}\n\nconst defaultContextValue: TelemetryContext = {\n onPerformanceMeasured: () => {},\n onFeatureUsed: () => {},\n};\n\n/** @internal */\nexport function useTelemetryContext() {\n return useContext(telemetryContext) ?? defaultContextValue;\n}\n\ninterface UseReportingActionProps<TAction> {\n action: TAction;\n featureId?: TrackedFeatures;\n}\n\n/** @internal */\nexport function useReportingAction<TAction extends (...args: any[]) => void>({ action, featureId }: UseReportingActionProps<TAction>) {\n const { onFeatureUsed } = useTelemetryContext();\n return useCallback<(...args: Parameters<TAction>) => void>(\n (...args) => {\n onFeatureUsed({ featureId, reportInteraction: true });\n action(...args);\n },\n [action, featureId, onFeatureUsed],\n );\n}\n"]}
|
|
@@ -1,27 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Viewport } from "@itwin/core-frontend";
|
|
2
2
|
import type { Id64Array } from "@itwin/core-bentley";
|
|
3
|
-
import type { IModelConnection } from "@itwin/core-frontend";
|
|
4
|
-
import type { SchemaContext } from "@itwin/ecschema-metadata";
|
|
5
3
|
/** @beta */
|
|
6
4
|
export type FunctionProps<THook extends (props: any) => any> = Parameters<THook>[0];
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Disables display of all given models.
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export declare function hideAllModels(models: string[], viewport: Viewport): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Enables display of all given models. Also enables display of all categories and clears always and
|
|
12
|
+
* never drawn lists in the viewport.
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
export declare function showAll(props: {
|
|
16
|
+
/** ID's of models to enable */
|
|
17
|
+
models: Id64Array;
|
|
18
|
+
/** ID's of categories to enable, if set to undefined, all categories will be enabled */
|
|
19
|
+
categories?: Id64Array;
|
|
20
|
+
viewport: Viewport;
|
|
21
|
+
}): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Inverts display of all given models.
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export declare function invertAllModels(models: Id64Array, viewport: Viewport): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Based on the value of `enable` argument, either enables or disables display of given models.
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export declare function toggleModels(models: string[], enable: boolean, viewport: Viewport): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Checks if all given models are displayed in given viewport.
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export declare function areAllModelsVisible(models: string[], viewport: Viewport): boolean;
|
|
27
37
|
//# sourceMappingURL=Utils.d.ts.map
|
|
@@ -2,57 +2,70 @@
|
|
|
2
2
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const slices = new Array();
|
|
14
|
-
for (let sliceStartIndex = 0; sliceStartIndex < ids.length; sliceStartIndex += 127) {
|
|
15
|
-
let sliceEndIndex = sliceStartIndex + 127;
|
|
16
|
-
if (sliceEndIndex > ids.length) {
|
|
17
|
-
sliceEndIndex = undefined;
|
|
18
|
-
}
|
|
19
|
-
slices.push(ids.slice(sliceStartIndex, sliceEndIndex));
|
|
20
|
-
}
|
|
21
|
-
return `json_array(${slices.map((sliceIds) => `json_array(${sliceIds.map((id) => `'${id}'`).join(",")})`).join(",")})`;
|
|
5
|
+
import { showAllCategories } from "./CategoriesVisibilityUtils.js";
|
|
6
|
+
import { toggleAllCategories } from "./internal/VisibilityUtils.js";
|
|
7
|
+
/**
|
|
8
|
+
* Disables display of all given models.
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
export async function hideAllModels(models, viewport) {
|
|
12
|
+
viewport.changeModelDisplay(models, false);
|
|
22
13
|
}
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Enables display of all given models. Also enables display of all categories and clears always and
|
|
16
|
+
* never drawn lists in the viewport.
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export async function showAll(props) {
|
|
20
|
+
const { models, categories, viewport } = props;
|
|
21
|
+
await viewport.addViewedModels(models);
|
|
22
|
+
viewport.clearNeverDrawn();
|
|
23
|
+
viewport.clearAlwaysDrawn();
|
|
24
|
+
if (categories) {
|
|
25
|
+
await showAllCategories(categories, viewport);
|
|
27
26
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
/** @internal */
|
|
31
|
-
export function pushToMap(targetMap, key, value) {
|
|
32
|
-
let set = targetMap.get(key);
|
|
33
|
-
if (!set) {
|
|
34
|
-
set = new Set();
|
|
35
|
-
targetMap.set(key, set);
|
|
27
|
+
else {
|
|
28
|
+
await toggleAllCategories(viewport, true);
|
|
36
29
|
}
|
|
37
|
-
set.add(value);
|
|
38
30
|
}
|
|
39
|
-
/**
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Inverts display of all given models.
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
export async function invertAllModels(models, viewport) {
|
|
36
|
+
const notViewedModels = new Array();
|
|
37
|
+
const viewedModels = new Array();
|
|
38
|
+
models.forEach((modelId) => {
|
|
39
|
+
if (viewport.viewsModel(modelId)) {
|
|
40
|
+
viewedModels.push(modelId);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
notViewedModels.push(modelId);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
await viewport.addViewedModels(notViewedModels);
|
|
47
|
+
viewport.changeModelDisplay(viewedModels, false);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Based on the value of `enable` argument, either enables or disables display of given models.
|
|
51
|
+
* @public
|
|
52
|
+
*/
|
|
53
|
+
export async function toggleModels(models, enable, viewport) {
|
|
54
|
+
if (!models) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (enable) {
|
|
58
|
+
viewport.changeModelDisplay(models, false);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
await viewport.addViewedModels(models);
|
|
62
|
+
}
|
|
49
63
|
}
|
|
50
|
-
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return ref;
|
|
64
|
+
/**
|
|
65
|
+
* Checks if all given models are displayed in given viewport.
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
68
|
+
export function areAllModelsVisible(models, viewport) {
|
|
69
|
+
return models.length !== 0 ? models.every((id) => viewport.viewsModel(id)) : false;
|
|
57
70
|
}
|
|
58
71
|
//# sourceMappingURL=Utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/Utils.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;
|
|
1
|
+
{"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../../../../src/tree-widget-react/components/trees/common/Utils.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAGhG,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAOpE;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,MAAgB,EAAE,QAAkB;IACtE,QAAQ,CAAC,kBAAkB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAC7C,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,KAM7B;IACC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAC/C,MAAM,QAAQ,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;IACvC,QAAQ,CAAC,eAAe,EAAE,CAAC;IAC3B,QAAQ,CAAC,gBAAgB,EAAE,CAAC;IAC5B,IAAI,UAAU,EAAE;QACd,MAAM,iBAAiB,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;KAC/C;SAAM;QACL,MAAM,mBAAmB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;KAC3C;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,MAAiB,EAAE,QAAkB;IACzE,MAAM,eAAe,GAAG,IAAI,KAAK,EAAc,CAAC;IAChD,MAAM,YAAY,GAAG,IAAI,KAAK,EAAc,CAAC;IAC7C,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QACzB,IAAI,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;YAChC,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SAC5B;aAAM;YACL,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SAC/B;IACH,CAAC,CAAC,CAAC;IACH,MAAM,QAAQ,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC;IAChD,QAAQ,CAAC,kBAAkB,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;AACnD,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,MAAgB,EAAE,MAAe,EAAE,QAAkB;IACtF,IAAI,CAAC,MAAM,EAAE;QACX,OAAO;KACR;IACD,IAAI,MAAM,EAAE;QACV,QAAQ,CAAC,kBAAkB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;KAC5C;SAAM;QACL,MAAM,QAAQ,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;KACxC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,MAAgB,EAAE,QAAkB;IACtE,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AACrF,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport type { Viewport } from \"@itwin/core-frontend\";\nimport { showAllCategories } from \"./CategoriesVisibilityUtils.js\";\nimport { toggleAllCategories } from \"./internal/VisibilityUtils.js\";\n\nimport type { Id64Array, Id64String } from \"@itwin/core-bentley\";\n\n/** @beta */\nexport type FunctionProps<THook extends (props: any) => any> = Parameters<THook>[0];\n\n/**\n * Disables display of all given models.\n * @public\n */\nexport async function hideAllModels(models: string[], viewport: Viewport) {\n viewport.changeModelDisplay(models, false);\n}\n\n/**\n * Enables display of all given models. Also enables display of all categories and clears always and\n * never drawn lists in the viewport.\n * @public\n */\nexport async function showAll(props: {\n /** ID's of models to enable */\n models: Id64Array;\n /** ID's of categories to enable, if set to undefined, all categories will be enabled */\n categories?: Id64Array;\n viewport: Viewport;\n}) {\n const { models, categories, viewport } = props;\n await viewport.addViewedModels(models);\n viewport.clearNeverDrawn();\n viewport.clearAlwaysDrawn();\n if (categories) {\n await showAllCategories(categories, viewport);\n } else {\n await toggleAllCategories(viewport, true);\n }\n}\n\n/**\n * Inverts display of all given models.\n * @public\n */\nexport async function invertAllModels(models: Id64Array, viewport: Viewport) {\n const notViewedModels = new Array<Id64String>();\n const viewedModels = new Array<Id64String>();\n models.forEach((modelId) => {\n if (viewport.viewsModel(modelId)) {\n viewedModels.push(modelId);\n } else {\n notViewedModels.push(modelId);\n }\n });\n await viewport.addViewedModels(notViewedModels);\n viewport.changeModelDisplay(viewedModels, false);\n}\n\n/**\n * Based on the value of `enable` argument, either enables or disables display of given models.\n * @public\n */\nexport async function toggleModels(models: string[], enable: boolean, viewport: Viewport) {\n if (!models) {\n return;\n }\n if (enable) {\n viewport.changeModelDisplay(models, false);\n } else {\n await viewport.addViewedModels(models);\n }\n}\n\n/**\n * Checks if all given models are displayed in given viewport.\n * @public\n */\nexport function areAllModelsVisible(models: string[], viewport: Viewport) {\n return models.length !== 0 ? models.every((id) => viewport.viewsModel(id)) : false;\n}\n"]}
|
|
@@ -4,11 +4,11 @@ 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
|
/* eslint-disable @itwin/no-internal */
|
|
7
|
-
import {
|
|
8
|
-
import { useHierarchiesLocalization } from "../UseHierarchiesLocalization.js";
|
|
7
|
+
import { TreeRenderer as PresentationTree } from "@itwin/presentation-hierarchies-react";
|
|
8
|
+
import { useHierarchiesLocalization } from "../internal/UseHierarchiesLocalization.js";
|
|
9
9
|
/** @internal */
|
|
10
10
|
export function BaseTreeRenderer({ rootNodes, onNodeClick, expandNode, actions, ...props }) {
|
|
11
11
|
const localizedStrings = useHierarchiesLocalization();
|
|
12
|
-
return (_jsx(
|
|
12
|
+
return (_jsx(PresentationTree, { ...props, onNodeClick: onNodeClick, localizedStrings: localizedStrings, expandNode: expandNode, rootNodes: rootNodes, actions: actions }));
|
|
13
13
|
}
|
|
14
14
|
//# sourceMappingURL=BaseTreeRenderer.js.map
|
package/lib/esm/tree-widget-react/components/trees/common/components/BaseTreeRenderer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseTreeRenderer.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/common/components/BaseTreeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG,uCAAuC;AAEvC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"BaseTreeRenderer.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/common/components/BaseTreeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAChG,uCAAuC;AAEvC,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AACzF,OAAO,EAAE,0BAA0B,EAAE,MAAM,2CAA2C,CAAC;AAKvF,gBAAgB;AAChB,MAAM,UAAU,gBAAgB,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,KAAK,EAAyB;IAC/G,MAAM,gBAAgB,GAAG,0BAA0B,EAAE,CAAC;IACtD,OAAO,CACL,KAAC,gBAAgB,OACX,KAAK,EACT,WAAW,EAAE,WAAW,EACxB,gBAAgB,EAAE,gBAAgB,EAClC,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,OAAO,GAChB,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/* eslint-disable @itwin/no-internal */\n\nimport { TreeRenderer as PresentationTree } from \"@itwin/presentation-hierarchies-react\";\nimport { useHierarchiesLocalization } from \"../internal/UseHierarchiesLocalization.js\";\n\n/** @beta */\nexport type BaseTreeRendererProps = React.ComponentPropsWithoutRef<typeof PresentationTree>;\n\n/** @internal */\nexport function BaseTreeRenderer({ rootNodes, onNodeClick, expandNode, actions, ...props }: BaseTreeRendererProps) {\n const localizedStrings = useHierarchiesLocalization();\n return (\n <PresentationTree\n {...props}\n onNodeClick={onNodeClick}\n localizedStrings={localizedStrings}\n expandNode={expandNode}\n rootNodes={rootNodes}\n actions={actions}\n />\n );\n}\n"]}
|
|
@@ -4,6 +4,7 @@ import { Fragment as _Fragment, 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 { useLayoutEffect, useState } from "react";
|
|
7
|
+
/** @internal */
|
|
7
8
|
export function Delayed({ show, children }) {
|
|
8
9
|
const [visible, setVisible] = useState(false);
|
|
9
10
|
useLayoutEffect(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Delayed.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/common/components/Delayed.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAIlD,MAAM,UAAU,OAAO,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAwC;IAC9E,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAE9C,eAAe,CAAC,GAAG,EAAE;QACnB,IAAI,CAAC,IAAI,EAAE;YACT,UAAU,CAAC,KAAK,CAAC,CAAC;YAClB,OAAO;SACR;QAED,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YAC5B,UAAU,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC,EAAE,GAAG,CAAC,CAAC;QACR,OAAO,GAAG,EAAE;YACV,YAAY,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAEX,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,IAAI,CAAC;KACb;IAED,OAAO,4BAAG,QAAQ,GAAI,CAAC;AACzB,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 { useLayoutEffect, useState } from \"react\";\n\nimport type { PropsWithChildren } from \"react\";\n\nexport function Delayed({ show, children }: PropsWithChildren<{ show: boolean }>) {\n const [visible, setVisible] = useState(false);\n\n useLayoutEffect(() => {\n if (!show) {\n setVisible(false);\n return;\n }\n\n const timer = setTimeout(() => {\n setVisible(show);\n }, 250);\n return () => {\n clearTimeout(timer);\n };\n }, [show]);\n\n if (!visible) {\n return null;\n }\n\n return <>{children}</>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Delayed.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/common/components/Delayed.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAIlD,gBAAgB;AAChB,MAAM,UAAU,OAAO,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAwC;IAC9E,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAE9C,eAAe,CAAC,GAAG,EAAE;QACnB,IAAI,CAAC,IAAI,EAAE;YACT,UAAU,CAAC,KAAK,CAAC,CAAC;YAClB,OAAO;SACR;QAED,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE;YAC5B,UAAU,CAAC,IAAI,CAAC,CAAC;QACnB,CAAC,EAAE,GAAG,CAAC,CAAC;QACR,OAAO,GAAG,EAAE;YACV,YAAY,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IAEX,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,IAAI,CAAC;KACb;IAED,OAAO,4BAAG,QAAQ,GAAI,CAAC;AACzB,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 { useLayoutEffect, useState } from \"react\";\n\nimport type { PropsWithChildren } from \"react\";\n\n/** @internal */\nexport function Delayed({ show, children }: PropsWithChildren<{ show: boolean }>) {\n const [visible, setVisible] = useState(false);\n\n useLayoutEffect(() => {\n if (!show) {\n setVisible(false);\n return;\n }\n\n const timer = setTimeout(() => {\n setVisible(show);\n }, 250);\n return () => {\n clearTimeout(timer);\n };\n }, [show]);\n\n if (!visible) {\n return null;\n }\n\n return <>{children}</>;\n}\n"]}
|
|
@@ -6,6 +6,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
6
6
|
import "./ProgressOverlay.css";
|
|
7
7
|
import { ProgressBar, VisuallyHidden } from "@itwin/itwinui-react/bricks";
|
|
8
8
|
import { TreeWidget } from "../../../../TreeWidget.js";
|
|
9
|
+
/** @internal */
|
|
9
10
|
export function ProgressOverlay() {
|
|
10
11
|
return (_jsxs("div", { className: "tw-progress-overlay-container", children: [_jsx(ProgressBar, { "aria-labelledby": "tw-progress-bar", tone: "accent" }), _jsx(VisuallyHidden, { id: "tw-progress-bar", children: TreeWidget.translate("loading.filter") }), _jsx("div", { className: "tw-progress-overlay-backdrop" })] }));
|
|
11
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProgressOverlay.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/common/components/ProgressOverlay.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,uBAAuB,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAEvD,MAAM,UAAU,eAAe;IAC7B,OAAO,CACL,eAAK,SAAS,EAAC,+BAA+B,aAC5C,KAAC,WAAW,uBAAkB,iBAAiB,EAAE,IAAI,EAAE,QAAQ,GAAI,EACnE,KAAC,cAAc,IAAC,EAAE,EAAE,iBAAiB,YAAG,UAAU,CAAC,SAAS,CAAC,gBAAgB,CAAC,GAAkB,EAChG,cAAK,SAAS,EAAC,8BAA8B,GAAG,IAC5C,CACP,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 \"./ProgressOverlay.css\";\nimport { ProgressBar, VisuallyHidden } from \"@itwin/itwinui-react/bricks\";\nimport { TreeWidget } from \"../../../../TreeWidget.js\";\n\nexport function ProgressOverlay() {\n return (\n <div className=\"tw-progress-overlay-container\">\n <ProgressBar aria-labelledby={\"tw-progress-bar\"} tone={\"accent\"} />\n <VisuallyHidden id={\"tw-progress-bar\"}>{TreeWidget.translate(\"loading.filter\")}</VisuallyHidden>\n <div className=\"tw-progress-overlay-backdrop\" />\n </div>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ProgressOverlay.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/common/components/ProgressOverlay.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,uBAAuB,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAEvD,gBAAgB;AAChB,MAAM,UAAU,eAAe;IAC7B,OAAO,CACL,eAAK,SAAS,EAAC,+BAA+B,aAC5C,KAAC,WAAW,uBAAkB,iBAAiB,EAAE,IAAI,EAAE,QAAQ,GAAI,EACnE,KAAC,cAAc,IAAC,EAAE,EAAE,iBAAiB,YAAG,UAAU,CAAC,SAAS,CAAC,gBAAgB,CAAC,GAAkB,EAChG,cAAK,SAAS,EAAC,8BAA8B,GAAG,IAC5C,CACP,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 \"./ProgressOverlay.css\";\nimport { ProgressBar, VisuallyHidden } from \"@itwin/itwinui-react/bricks\";\nimport { TreeWidget } from \"../../../../TreeWidget.js\";\n\n/** @internal */\nexport function ProgressOverlay() {\n return (\n <div className=\"tw-progress-overlay-container\">\n <ProgressBar aria-labelledby={\"tw-progress-bar\"} tone={\"accent\"} />\n <VisuallyHidden id={\"tw-progress-bar\"}>{TreeWidget.translate(\"loading.filter\")}</VisuallyHidden>\n <div className=\"tw-progress-overlay-backdrop\" />\n </div>\n );\n}\n"]}
|