@itwin/tree-widget-react 3.0.0-dev.1 → 3.0.0-dev.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +136 -1
- package/lib/cjs/components/SelectableTree.d.ts +12 -6
- package/lib/cjs/components/SelectableTree.js.map +1 -1
- package/lib/cjs/components/TreeSelector.d.ts +2 -2
- package/lib/cjs/components/TreeSelector.js.map +1 -1
- package/lib/cjs/components/TreeWidgetUiItemsProvider.d.ts +3 -2
- package/lib/cjs/components/TreeWidgetUiItemsProvider.js.map +1 -1
- package/lib/cjs/components/tree-header/TreeHeader.d.ts +1 -1
- package/lib/cjs/components/tree-header/TreeHeader.js.map +1 -1
- package/lib/cjs/components/trees/categories-tree/CategoriesTree.d.ts +6 -5
- package/lib/cjs/components/trees/categories-tree/CategoriesTree.js +8 -9
- package/lib/cjs/components/trees/categories-tree/CategoriesTree.js.map +1 -1
- package/lib/cjs/components/trees/categories-tree/CategoriesTreeButtons.d.ts +3 -3
- package/lib/cjs/components/trees/categories-tree/CategoriesTreeButtons.js +3 -3
- package/lib/cjs/components/trees/categories-tree/CategoriesTreeButtons.js.map +1 -1
- package/lib/cjs/components/trees/categories-tree/CategoriesTreeComponent.d.ts +4 -4
- package/lib/cjs/components/trees/categories-tree/CategoriesTreeComponent.js +7 -7
- package/lib/cjs/components/trees/categories-tree/CategoriesTreeComponent.js.map +1 -1
- package/lib/cjs/components/trees/common/CategoriesVisibilityUtils.d.ts +1 -5
- package/lib/cjs/components/trees/common/CategoriesVisibilityUtils.js +0 -5
- package/lib/cjs/components/trees/common/CategoriesVisibilityUtils.js.map +1 -1
- package/lib/cjs/components/trees/common/FocusedInstancesContext.d.ts +0 -3
- package/lib/cjs/components/trees/common/FocusedInstancesContext.js +0 -2
- package/lib/cjs/components/trees/common/FocusedInstancesContext.js.map +1 -1
- package/lib/cjs/components/trees/common/FocusedInstancesContextProvider.d.ts +0 -1
- package/lib/cjs/components/trees/common/FocusedInstancesContextProvider.js +0 -1
- package/lib/cjs/components/trees/common/FocusedInstancesContextProvider.js.map +1 -1
- package/lib/cjs/components/trees/common/UseFiltering.d.ts +0 -1
- package/lib/cjs/components/trees/common/UseFiltering.js +0 -1
- package/lib/cjs/components/trees/common/UseFiltering.js.map +1 -1
- package/lib/cjs/components/trees/common/UseHierarchiesLocalization.d.ts +0 -1
- package/lib/cjs/components/trees/common/UseHierarchiesLocalization.js +1 -1
- package/lib/cjs/components/trees/common/UseHierarchiesLocalization.js.map +1 -1
- package/lib/cjs/components/trees/common/UseHierarchyFiltering.d.ts +1 -7
- package/lib/cjs/components/trees/common/UseHierarchyFiltering.js +4 -3
- package/lib/cjs/components/trees/common/UseHierarchyFiltering.js.map +1 -1
- package/lib/cjs/components/trees/common/UseHierarchyVisibility.d.ts +15 -10
- package/lib/cjs/components/trees/common/UseHierarchyVisibility.js +20 -17
- package/lib/cjs/components/trees/common/UseHierarchyVisibility.js.map +1 -1
- package/lib/cjs/components/trees/common/UseIModelChangeListener.d.ts +0 -1
- package/lib/cjs/components/trees/common/UseIModelChangeListener.js +0 -1
- package/lib/cjs/components/trees/common/UseIModelChangeListener.js.map +1 -1
- package/lib/cjs/components/trees/common/UseMultiCheckboxHandler.d.ts +0 -1
- package/lib/cjs/components/trees/common/UseMultiCheckboxHandler.js +0 -1
- package/lib/cjs/components/trees/common/UseMultiCheckboxHandler.js.map +1 -1
- package/lib/cjs/components/trees/common/UseNodeHighlighting.d.ts +9 -5
- package/lib/cjs/components/trees/common/UseNodeHighlighting.js +15 -24
- package/lib/cjs/components/trees/common/UseNodeHighlighting.js.map +1 -1
- package/lib/cjs/components/trees/common/UseTelemetryContext.d.ts +29 -0
- package/lib/cjs/components/trees/common/UseTelemetryContext.js +49 -0
- package/lib/cjs/components/trees/common/UseTelemetryContext.js.map +1 -0
- package/lib/cjs/components/trees/common/Utils.d.ts +3 -0
- package/lib/cjs/components/trees/common/Utils.js +11 -1
- package/lib/cjs/components/trees/common/Utils.js.map +1 -1
- package/lib/cjs/components/trees/common/components/Delayed.d.ts +0 -1
- package/lib/cjs/components/trees/common/components/Delayed.js +0 -1
- package/lib/cjs/components/trees/common/components/Delayed.js.map +1 -1
- package/lib/cjs/components/trees/common/components/ProgressOverlay.d.ts +0 -1
- package/lib/cjs/components/trees/common/components/ProgressOverlay.js +0 -1
- package/lib/cjs/components/trees/common/components/ProgressOverlay.js.map +1 -1
- package/lib/cjs/components/trees/common/components/Tree.d.ts +54 -0
- package/lib/cjs/components/trees/common/components/{BaseTree.js → Tree.js} +26 -22
- package/lib/cjs/components/trees/common/components/Tree.js.map +1 -0
- package/lib/cjs/components/trees/common/components/TreeNodeCheckbox.d.ts +14 -7
- package/lib/cjs/components/trees/common/components/TreeNodeCheckbox.js.map +1 -1
- package/lib/cjs/components/trees/common/components/TreeNodeRenderer.d.ts +7 -6
- package/lib/cjs/components/trees/common/components/TreeNodeRenderer.js +1 -1
- package/lib/cjs/components/trees/common/components/TreeNodeRenderer.js.map +1 -1
- package/lib/cjs/components/trees/common/components/TreeRenderer.d.ts +13 -5
- package/lib/cjs/components/trees/common/components/TreeRenderer.js +21 -4
- package/lib/cjs/components/trees/common/components/TreeRenderer.js.map +1 -1
- package/lib/cjs/components/trees/common/components/VisibilityTree.d.ts +27 -9
- package/lib/cjs/components/trees/common/components/VisibilityTree.js +8 -23
- package/lib/cjs/components/trees/common/components/VisibilityTree.js.map +1 -1
- package/lib/cjs/components/trees/common/components/VisibilityTreeRenderer.d.ts +12 -0
- package/lib/cjs/components/trees/common/components/VisibilityTreeRenderer.js +26 -0
- package/lib/cjs/components/trees/common/components/VisibilityTreeRenderer.js.map +1 -0
- package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTree.d.ts +8 -7
- package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTree.js +7 -10
- package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTree.js.map +1 -1
- package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTreeComponent.d.ts +5 -5
- package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js +3 -3
- package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js.map +1 -1
- package/lib/cjs/components/trees/imodel-content-tree/IModelContentTree.d.ts +8 -7
- package/lib/cjs/components/trees/imodel-content-tree/IModelContentTree.js +9 -12
- package/lib/cjs/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -1
- package/lib/cjs/components/trees/imodel-content-tree/IModelContentTreeComponent.d.ts +5 -5
- package/lib/cjs/components/trees/imodel-content-tree/IModelContentTreeComponent.js +3 -3
- package/lib/cjs/components/trees/imodel-content-tree/IModelContentTreeComponent.js.map +1 -1
- package/lib/cjs/components/trees/imodel-content-tree/IModelContentTreeDefinition.js.map +1 -1
- package/lib/cjs/components/trees/index.d.ts +7 -0
- package/lib/cjs/components/trees/index.js +11 -1
- package/lib/cjs/components/trees/index.js.map +1 -1
- package/lib/cjs/components/trees/models-tree/ModelsTree.d.ts +10 -9
- package/lib/cjs/components/trees/models-tree/ModelsTree.js +19 -20
- package/lib/cjs/components/trees/models-tree/ModelsTree.js.map +1 -1
- package/lib/cjs/components/trees/models-tree/ModelsTreeButtons.d.ts +10 -5
- package/lib/cjs/components/trees/models-tree/ModelsTreeButtons.js +19 -6
- package/lib/cjs/components/trees/models-tree/ModelsTreeButtons.js.map +1 -1
- package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.d.ts +11 -5
- package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.js +15 -23
- package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
- package/lib/cjs/components/trees/models-tree/ModelsTreeDefinition.d.ts +9 -5
- package/lib/cjs/components/trees/models-tree/ModelsTreeDefinition.js.map +1 -1
- package/lib/cjs/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.d.ts +11 -3
- package/lib/cjs/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
- package/lib/cjs/tree-widget-react.d.ts +1 -1
- package/lib/cjs/tree-widget-react.js.map +1 -1
- package/lib/esm/components/SelectableTree.d.ts +12 -6
- package/lib/esm/components/SelectableTree.js.map +1 -1
- package/lib/esm/components/TreeSelector.d.ts +2 -2
- package/lib/esm/components/TreeSelector.js.map +1 -1
- package/lib/esm/components/TreeWidgetUiItemsProvider.d.ts +3 -2
- package/lib/esm/components/TreeWidgetUiItemsProvider.js.map +1 -1
- package/lib/esm/components/tree-header/TreeHeader.d.ts +1 -1
- package/lib/esm/components/tree-header/TreeHeader.js.map +1 -1
- package/lib/esm/components/trees/categories-tree/CategoriesTree.d.ts +6 -5
- package/lib/esm/components/trees/categories-tree/CategoriesTree.js +8 -9
- package/lib/esm/components/trees/categories-tree/CategoriesTree.js.map +1 -1
- package/lib/esm/components/trees/categories-tree/CategoriesTreeButtons.d.ts +3 -3
- package/lib/esm/components/trees/categories-tree/CategoriesTreeButtons.js +3 -3
- package/lib/esm/components/trees/categories-tree/CategoriesTreeButtons.js.map +1 -1
- package/lib/esm/components/trees/categories-tree/CategoriesTreeComponent.d.ts +4 -4
- package/lib/esm/components/trees/categories-tree/CategoriesTreeComponent.js +7 -7
- package/lib/esm/components/trees/categories-tree/CategoriesTreeComponent.js.map +1 -1
- package/lib/esm/components/trees/common/CategoriesVisibilityUtils.d.ts +1 -5
- package/lib/esm/components/trees/common/CategoriesVisibilityUtils.js +0 -5
- package/lib/esm/components/trees/common/CategoriesVisibilityUtils.js.map +1 -1
- package/lib/esm/components/trees/common/FocusedInstancesContext.d.ts +0 -3
- package/lib/esm/components/trees/common/FocusedInstancesContext.js +0 -2
- package/lib/esm/components/trees/common/FocusedInstancesContext.js.map +1 -1
- package/lib/esm/components/trees/common/FocusedInstancesContextProvider.d.ts +0 -1
- package/lib/esm/components/trees/common/FocusedInstancesContextProvider.js +0 -1
- package/lib/esm/components/trees/common/FocusedInstancesContextProvider.js.map +1 -1
- package/lib/esm/components/trees/common/UseFiltering.d.ts +0 -1
- package/lib/esm/components/trees/common/UseFiltering.js +0 -1
- package/lib/esm/components/trees/common/UseFiltering.js.map +1 -1
- package/lib/esm/components/trees/common/UseHierarchiesLocalization.d.ts +0 -1
- package/lib/esm/components/trees/common/UseHierarchiesLocalization.js +1 -1
- package/lib/esm/components/trees/common/UseHierarchiesLocalization.js.map +1 -1
- package/lib/esm/components/trees/common/UseHierarchyFiltering.d.ts +1 -7
- package/lib/esm/components/trees/common/UseHierarchyFiltering.js +4 -3
- package/lib/esm/components/trees/common/UseHierarchyFiltering.js.map +1 -1
- package/lib/esm/components/trees/common/UseHierarchyVisibility.d.ts +15 -10
- package/lib/esm/components/trees/common/UseHierarchyVisibility.js +20 -17
- package/lib/esm/components/trees/common/UseHierarchyVisibility.js.map +1 -1
- package/lib/esm/components/trees/common/UseIModelChangeListener.d.ts +0 -1
- package/lib/esm/components/trees/common/UseIModelChangeListener.js +0 -1
- package/lib/esm/components/trees/common/UseIModelChangeListener.js.map +1 -1
- package/lib/esm/components/trees/common/UseMultiCheckboxHandler.d.ts +0 -1
- package/lib/esm/components/trees/common/UseMultiCheckboxHandler.js +0 -1
- package/lib/esm/components/trees/common/UseMultiCheckboxHandler.js.map +1 -1
- package/lib/esm/components/trees/common/UseNodeHighlighting.d.ts +9 -5
- package/lib/esm/components/trees/common/UseNodeHighlighting.js +14 -23
- package/lib/esm/components/trees/common/UseNodeHighlighting.js.map +1 -1
- package/lib/esm/components/trees/common/UseTelemetryContext.d.ts +29 -0
- package/lib/esm/components/trees/common/UseTelemetryContext.js +43 -0
- package/lib/esm/components/trees/common/UseTelemetryContext.js.map +1 -0
- package/lib/esm/components/trees/common/Utils.d.ts +3 -0
- package/lib/esm/components/trees/common/Utils.js +9 -0
- package/lib/esm/components/trees/common/Utils.js.map +1 -1
- package/lib/esm/components/trees/common/components/Delayed.d.ts +0 -1
- package/lib/esm/components/trees/common/components/Delayed.js +0 -1
- package/lib/esm/components/trees/common/components/Delayed.js.map +1 -1
- package/lib/esm/components/trees/common/components/ProgressOverlay.d.ts +0 -1
- package/lib/esm/components/trees/common/components/ProgressOverlay.js +0 -1
- package/lib/esm/components/trees/common/components/ProgressOverlay.js.map +1 -1
- package/lib/esm/components/trees/common/components/Tree.d.ts +54 -0
- package/lib/esm/components/trees/common/components/{BaseTree.js → Tree.js} +25 -21
- package/lib/esm/components/trees/common/components/Tree.js.map +1 -0
- package/lib/esm/components/trees/common/components/TreeNodeCheckbox.d.ts +14 -7
- package/lib/esm/components/trees/common/components/TreeNodeCheckbox.js.map +1 -1
- package/lib/esm/components/trees/common/components/TreeNodeRenderer.d.ts +7 -6
- package/lib/esm/components/trees/common/components/TreeNodeRenderer.js +1 -1
- package/lib/esm/components/trees/common/components/TreeNodeRenderer.js.map +1 -1
- package/lib/esm/components/trees/common/components/TreeRenderer.d.ts +13 -5
- package/lib/esm/components/trees/common/components/TreeRenderer.js +21 -4
- package/lib/esm/components/trees/common/components/TreeRenderer.js.map +1 -1
- package/lib/esm/components/trees/common/components/VisibilityTree.d.ts +27 -9
- package/lib/esm/components/trees/common/components/VisibilityTree.js +8 -23
- package/lib/esm/components/trees/common/components/VisibilityTree.js.map +1 -1
- package/lib/esm/components/trees/common/components/VisibilityTreeRenderer.d.ts +12 -0
- package/lib/esm/components/trees/common/components/VisibilityTreeRenderer.js +22 -0
- package/lib/esm/components/trees/common/components/VisibilityTreeRenderer.js.map +1 -0
- package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTree.d.ts +8 -7
- package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTree.js +7 -10
- package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTree.js.map +1 -1
- package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTreeComponent.d.ts +5 -5
- package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js +3 -3
- package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js.map +1 -1
- package/lib/esm/components/trees/imodel-content-tree/IModelContentTree.d.ts +8 -7
- package/lib/esm/components/trees/imodel-content-tree/IModelContentTree.js +9 -12
- package/lib/esm/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -1
- package/lib/esm/components/trees/imodel-content-tree/IModelContentTreeComponent.d.ts +5 -5
- package/lib/esm/components/trees/imodel-content-tree/IModelContentTreeComponent.js +3 -3
- package/lib/esm/components/trees/imodel-content-tree/IModelContentTreeComponent.js.map +1 -1
- package/lib/esm/components/trees/imodel-content-tree/IModelContentTreeDefinition.js.map +1 -1
- package/lib/esm/components/trees/index.d.ts +7 -0
- package/lib/esm/components/trees/index.js +5 -0
- package/lib/esm/components/trees/index.js.map +1 -1
- package/lib/esm/components/trees/models-tree/ModelsTree.d.ts +10 -9
- package/lib/esm/components/trees/models-tree/ModelsTree.js +19 -20
- package/lib/esm/components/trees/models-tree/ModelsTree.js.map +1 -1
- package/lib/esm/components/trees/models-tree/ModelsTreeButtons.d.ts +10 -5
- package/lib/esm/components/trees/models-tree/ModelsTreeButtons.js +18 -6
- package/lib/esm/components/trees/models-tree/ModelsTreeButtons.js.map +1 -1
- package/lib/esm/components/trees/models-tree/ModelsTreeComponent.d.ts +11 -5
- package/lib/esm/components/trees/models-tree/ModelsTreeComponent.js +16 -24
- package/lib/esm/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
- package/lib/esm/components/trees/models-tree/ModelsTreeDefinition.d.ts +9 -5
- package/lib/esm/components/trees/models-tree/ModelsTreeDefinition.js.map +1 -1
- package/lib/esm/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.d.ts +11 -3
- package/lib/esm/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
- package/lib/esm/tree-widget-react.d.ts +1 -1
- package/lib/esm/tree-widget-react.js.map +1 -1
- package/lib/public/locales/en/TreeWidget.json +2 -1
- package/package.json +2 -2
- package/lib/cjs/components/trees/common/UseFeatureReporting.d.ts +0 -34
- package/lib/cjs/components/trees/common/UseFeatureReporting.js +0 -39
- package/lib/cjs/components/trees/common/UseFeatureReporting.js.map +0 -1
- package/lib/cjs/components/trees/common/UsePerformanceReporting.d.ts +0 -18
- package/lib/cjs/components/trees/common/UsePerformanceReporting.js +0 -25
- package/lib/cjs/components/trees/common/UsePerformanceReporting.js.map +0 -1
- package/lib/cjs/components/trees/common/components/BaseTree.d.ts +0 -34
- package/lib/cjs/components/trees/common/components/BaseTree.js.map +0 -1
- package/lib/esm/components/trees/common/UseFeatureReporting.d.ts +0 -34
- package/lib/esm/components/trees/common/UseFeatureReporting.js +0 -34
- package/lib/esm/components/trees/common/UseFeatureReporting.js.map +0 -1
- package/lib/esm/components/trees/common/UsePerformanceReporting.d.ts +0 -18
- package/lib/esm/components/trees/common/UsePerformanceReporting.js +0 -21
- package/lib/esm/components/trees/common/UsePerformanceReporting.js.map +0 -1
- package/lib/esm/components/trees/common/components/BaseTree.d.ts +0 -34
- package/lib/esm/components/trees/common/components/BaseTree.js.map +0 -1
|
@@ -7,16 +7,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
exports.useHierarchyVisibility = void 0;
|
|
8
8
|
const react_1 = require("react");
|
|
9
9
|
const rxjs_1 = require("rxjs");
|
|
10
|
-
|
|
10
|
+
const UseTelemetryContext_1 = require("./UseTelemetryContext");
|
|
11
11
|
function useHierarchyVisibility({ visibilityHandlerFactory }) {
|
|
12
|
-
const
|
|
12
|
+
const visibilityStatusMap = (0, react_1.useRef)(new Map());
|
|
13
13
|
const [state, setState] = (0, react_1.useState)({
|
|
14
14
|
getCheckboxState: () => ({ state: "off", isDisabled: true }),
|
|
15
15
|
onCheckboxClicked: () => { },
|
|
16
16
|
triggerRefresh: () => { },
|
|
17
17
|
});
|
|
18
|
+
const { onFeatureUsed } = (0, UseTelemetryContext_1.useTelemetryContext)();
|
|
18
19
|
(0, react_1.useEffect)(() => {
|
|
19
|
-
|
|
20
|
+
visibilityStatusMap.current.clear();
|
|
20
21
|
const handler = visibilityHandlerFactory();
|
|
21
22
|
const visibilityChanged = new rxjs_1.Subject();
|
|
22
23
|
const calculate = new rxjs_1.Subject();
|
|
@@ -24,7 +25,7 @@ function useHierarchyVisibility({ visibilityHandlerFactory }) {
|
|
|
24
25
|
calculate.next(node);
|
|
25
26
|
};
|
|
26
27
|
const resetCache = () => {
|
|
27
|
-
|
|
28
|
+
visibilityStatusMap.current.forEach((value) => {
|
|
28
29
|
value.needsRefresh = true;
|
|
29
30
|
});
|
|
30
31
|
visibilityChanged.next();
|
|
@@ -32,38 +33,35 @@ function useHierarchyVisibility({ visibilityHandlerFactory }) {
|
|
|
32
33
|
const triggerCheckboxUpdate = () => {
|
|
33
34
|
setState((prev) => ({
|
|
34
35
|
...prev,
|
|
35
|
-
getCheckboxState: createStateGetter(
|
|
36
|
+
getCheckboxState: createStateGetter(visibilityStatusMap, calculateNodeStatus),
|
|
36
37
|
}));
|
|
37
38
|
};
|
|
38
39
|
const subscription = calculate
|
|
39
40
|
.pipe((0, rxjs_1.distinct)(undefined, visibilityChanged), (0, rxjs_1.mergeMap)((node) => (0, rxjs_1.defer)(async () => ({ node, status: await handler.getVisibilityStatus(node.nodeData) })).pipe((0, rxjs_1.takeUntil)(visibilityChanged))))
|
|
40
41
|
.subscribe({
|
|
41
42
|
next: ({ node, status }) => {
|
|
42
|
-
|
|
43
|
+
visibilityStatusMap.current.set(node.id, {
|
|
43
44
|
node,
|
|
44
|
-
|
|
45
|
-
state: status.state === "visible" ? "on" : status.state === "partial" ? "partial" : "off",
|
|
46
|
-
tooltip: status.tooltip,
|
|
47
|
-
isDisabled: status.isDisabled,
|
|
48
|
-
},
|
|
45
|
+
status,
|
|
49
46
|
needsRefresh: false,
|
|
50
47
|
});
|
|
51
48
|
triggerCheckboxUpdate();
|
|
52
49
|
},
|
|
53
50
|
});
|
|
54
51
|
const changeVisibility = (node, checked) => {
|
|
52
|
+
onFeatureUsed({ featureId: "visibility-change", reportInteraction: true });
|
|
55
53
|
void handler.changeVisibility(node.nodeData, checked);
|
|
56
|
-
const entry =
|
|
54
|
+
const entry = visibilityStatusMap.current.get(node.id);
|
|
57
55
|
if (!entry) {
|
|
58
56
|
return;
|
|
59
57
|
}
|
|
60
|
-
entry.
|
|
61
|
-
entry.
|
|
58
|
+
entry.status.state = checked ? "visible" : "hidden";
|
|
59
|
+
entry.status.tooltip = undefined;
|
|
62
60
|
triggerCheckboxUpdate();
|
|
63
61
|
};
|
|
64
62
|
setState({
|
|
65
63
|
onCheckboxClicked: changeVisibility,
|
|
66
|
-
getCheckboxState: createStateGetter(
|
|
64
|
+
getCheckboxState: createStateGetter(visibilityStatusMap, calculateNodeStatus),
|
|
67
65
|
triggerRefresh: () => {
|
|
68
66
|
resetCache();
|
|
69
67
|
triggerCheckboxUpdate();
|
|
@@ -78,7 +76,7 @@ function useHierarchyVisibility({ visibilityHandlerFactory }) {
|
|
|
78
76
|
removeListener();
|
|
79
77
|
handler.dispose();
|
|
80
78
|
};
|
|
81
|
-
}, [visibilityHandlerFactory]);
|
|
79
|
+
}, [visibilityHandlerFactory, onFeatureUsed]);
|
|
82
80
|
return state;
|
|
83
81
|
}
|
|
84
82
|
exports.useHierarchyVisibility = useHierarchyVisibility;
|
|
@@ -92,7 +90,12 @@ function createStateGetter(map, calculateVisibility) {
|
|
|
92
90
|
if (entry.needsRefresh) {
|
|
93
91
|
calculateVisibility(node);
|
|
94
92
|
}
|
|
95
|
-
|
|
93
|
+
const status = entry.status;
|
|
94
|
+
return {
|
|
95
|
+
state: status.state === "visible" ? "on" : status.state === "hidden" ? "off" : "partial",
|
|
96
|
+
tooltip: status.tooltip,
|
|
97
|
+
isDisabled: status.isDisabled,
|
|
98
|
+
};
|
|
96
99
|
};
|
|
97
100
|
}
|
|
98
101
|
//# sourceMappingURL=UseHierarchyVisibility.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseHierarchyVisibility.js","sourceRoot":"","sources":["../../../../../src/components/trees/common/UseHierarchyVisibility.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,iCAAoD;AACpD,+BAAqE;
|
|
1
|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AAC;SAC3B;QAED,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC5B,OAAO;YACL,KAAK,EAAE,MAAM,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;YACxF,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,UAAU,EAAE,MAAM,CAAC,UAAU;SAC9B,CAAC;IACJ,CAAC,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, useRef, useState } from \"react\";\nimport { defer, distinct, mergeMap, Subject, takeUntil } from \"rxjs\";\nimport { useTelemetryContext } from \"./UseTelemetryContext\";\n\nimport type { MutableRefObject } from \"react\";\nimport type { BeEvent, IDisposable } from \"@itwin/core-bentley\";\nimport type { HierarchyNode, PresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport type { TreeCheckboxProps } from \"./components/TreeNodeCheckbox\";\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({ visibilityHandlerFactory }: UseHierarchyVisibilityProps): TreeCheckboxProps & { triggerRefresh: () => void } {\n const visibilityStatusMap = useRef(new Map<string, { node: PresentationHierarchyNode; status: VisibilityStatus; needsRefresh: boolean }>());\n const [state, setState] = useState<TreeCheckboxProps & { triggerRefresh: () => void }>({\n getCheckboxState: () => ({ state: \"off\", isDisabled: true }),\n onCheckboxClicked: () => {},\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 mergeMap((node) => defer(async () => ({ node, status: await handler.getVisibilityStatus(node.nodeData) })).pipe(takeUntil(visibilityChanged))),\n )\n .subscribe({\n next: ({ node, status }) => {\n visibilityStatusMap.current.set(node.id, {\n node,\n status,\n needsRefresh: false,\n });\n triggerCheckboxUpdate();\n },\n });\n\n const changeVisibility = (node: PresentationHierarchyNode, checked: boolean) => {\n onFeatureUsed({ featureId: \"visibility-change\", reportInteraction: true });\n void handler.changeVisibility(node.nodeData, checked);\n const entry = visibilityStatusMap.current.get(node.id);\n if (!entry) {\n return;\n }\n entry.status.state = checked ? \"visible\" : \"hidden\";\n entry.status.tooltip = undefined;\n triggerCheckboxUpdate();\n };\n\n setState({\n onCheckboxClicked: changeVisibility,\n getCheckboxState: 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): TreeCheckboxProps[\"getCheckboxState\"] {\n return (node) => {\n const entry = map.current.get(node.id);\n if (entry === undefined) {\n calculateVisibility(node);\n return { state: \"off\", isDisabled: true };\n }\n if (entry.needsRefresh) {\n calculateVisibility(node);\n }\n\n const status = entry.status;\n return {\n state: status.state === \"visible\" ? \"on\" : status.state === \"hidden\" ? \"off\" : \"partial\",\n tooltip: status.tooltip,\n isDisabled: status.isDisabled,\n };\n };\n}\n"]}
|
|
@@ -3,7 +3,6 @@ interface UseIModelChangeListenerProps {
|
|
|
3
3
|
imodel: IModelConnection;
|
|
4
4
|
action: () => void;
|
|
5
5
|
}
|
|
6
|
-
/** @internal */
|
|
7
6
|
export declare function useIModelChangeListener({ imodel, action }: UseIModelChangeListenerProps): void;
|
|
8
7
|
export {};
|
|
9
8
|
//# sourceMappingURL=UseIModelChangeListener.d.ts.map
|
|
@@ -7,7 +7,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
exports.useIModelChangeListener = void 0;
|
|
8
8
|
const react_1 = require("react");
|
|
9
9
|
const presentation_core_interop_1 = require("@itwin/presentation-core-interop");
|
|
10
|
-
/** @internal */
|
|
11
10
|
function useIModelChangeListener({ imodel, action }) {
|
|
12
11
|
(0, react_1.useEffect)(() => {
|
|
13
12
|
if (!imodel.isBriefcaseConnection()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseIModelChangeListener.js","sourceRoot":"","sources":["../../../../../src/components/trees/common/UseIModelChangeListener.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,iCAAkC;AAClC,gFAAwE;AASxE,
|
|
1
|
+
{"version":3,"file":"UseIModelChangeListener.js","sourceRoot":"","sources":["../../../../../src/components/trees/common/UseIModelChangeListener.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,iCAAkC;AAClC,gFAAwE;AASxE,SAAgB,uBAAuB,CAAC,EAAE,MAAM,EAAE,MAAM,EAAgC;IACtF,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,CAAC,MAAM,CAAC,qBAAqB,EAAE,EAAE;YACnC,OAAO;SACR;QAED,IAAA,gDAAoB,EAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC5C,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AACvB,CAAC;AARD,0DAQC","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 } from \"react\";\nimport { registerTxnListeners } from \"@itwin/presentation-core-interop\";\n\nimport type { IModelConnection } from \"@itwin/core-frontend\";\n\ninterface UseIModelChangeListenerProps {\n imodel: IModelConnection;\n action: () => void;\n}\n\nexport function useIModelChangeListener({ imodel, action }: UseIModelChangeListenerProps) {\n useEffect(() => {\n if (!imodel.isBriefcaseConnection()) {\n return;\n }\n\n registerTxnListeners(imodel.txns, action);\n }, [imodel, action]);\n}\n"]}
|
|
@@ -7,7 +7,6 @@ interface UseMultiCheckboxHandlerProps {
|
|
|
7
7
|
interface UseMultiCheckboxHandlerResult {
|
|
8
8
|
onCheckboxClicked: (node: PresentationHierarchyNode, checked: boolean) => void;
|
|
9
9
|
}
|
|
10
|
-
/** @internal */
|
|
11
10
|
export declare function useMultiCheckboxHandler({ rootNodes, isNodeSelected, onClick }: UseMultiCheckboxHandlerProps): UseMultiCheckboxHandlerResult;
|
|
12
11
|
export {};
|
|
13
12
|
//# sourceMappingURL=UseMultiCheckboxHandler.d.ts.map
|
|
@@ -7,7 +7,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
exports.useMultiCheckboxHandler = void 0;
|
|
8
8
|
const react_1 = require("react");
|
|
9
9
|
const presentation_hierarchies_react_1 = require("@itwin/presentation-hierarchies-react");
|
|
10
|
-
/** @internal */
|
|
11
10
|
function useMultiCheckboxHandler({ rootNodes, isNodeSelected, onClick }) {
|
|
12
11
|
const onCheckboxClicked = (0, react_1.useCallback)((clickedNode, checked) => {
|
|
13
12
|
if (!isNodeSelected(clickedNode.id)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseMultiCheckboxHandler.js","sourceRoot":"","sources":["../../../../../src/components/trees/common/UseMultiCheckboxHandler.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,iCAAoC;AACpC,0FAAoF;AAcpF,
|
|
1
|
+
{"version":3,"file":"UseMultiCheckboxHandler.js","sourceRoot":"","sources":["../../../../../src/components/trees/common/UseMultiCheckboxHandler.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,iCAAoC;AACpC,0FAAoF;AAcpF,SAAgB,uBAAuB,CAAC,EAAE,SAAS,EAAE,cAAc,EAAE,OAAO,EAAgC;IAC1G,MAAM,iBAAiB,GAAG,IAAA,mBAAW,EACnC,CAAC,WAAsC,EAAE,OAAgB,EAAE,EAAE;QAC3D,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,EAAE,CAAC,EAAE;YACnC,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;YAC9B,OAAO;SACR;QACD,SAAS,IAAI,mBAAmB,CAAC,SAAS,EAAE,cAAc,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC;IAChG,CAAC,EACD,CAAC,SAAS,EAAE,cAAc,EAAE,OAAO,CAAC,CACrC,CAAC;IAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC;AAC/B,CAAC;AAbD,0DAaC;AAED,SAAS,mBAAmB,CAC1B,KAAkC,EAClC,cAA2C,EAC3C,QAAmD;IAEnD,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACrB,IAAI,CAAC,IAAA,4DAA2B,EAAC,IAAI,CAAC,EAAE;YACtC,OAAO;SACR;QACD,IAAI,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;YAC3B,QAAQ,CAAC,IAAI,CAAC,CAAC;SAChB;QACD,IAAI,IAAI,CAAC,UAAU,IAAI,OAAO,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE;YACzD,mBAAmB,CAAC,IAAI,CAAC,QAAQ,EAAE,cAAc,EAAE,QAAQ,CAAC,CAAC;SAC9D;IACH,CAAC,CAAC,CAAC;AACL,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 } from \"react\";\nimport { isPresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\n\nimport type { PresentationHierarchyNode, PresentationTreeNode } from \"@itwin/presentation-hierarchies-react\";\n\ninterface UseMultiCheckboxHandlerProps {\n rootNodes: PresentationTreeNode[] | undefined;\n isNodeSelected: (nodeId: string) => boolean;\n onClick: (node: PresentationHierarchyNode, checked: boolean) => void;\n}\n\ninterface UseMultiCheckboxHandlerResult {\n onCheckboxClicked: (node: PresentationHierarchyNode, checked: boolean) => void;\n}\n\nexport function useMultiCheckboxHandler({ rootNodes, isNodeSelected, onClick }: UseMultiCheckboxHandlerProps): UseMultiCheckboxHandlerResult {\n const onCheckboxClicked = useCallback(\n (clickedNode: PresentationHierarchyNode, checked: boolean) => {\n if (!isNodeSelected(clickedNode.id)) {\n onClick(clickedNode, checked);\n return;\n }\n rootNodes && forEachSelectedNode(rootNodes, isNodeSelected, (node) => onClick(node, checked));\n },\n [rootNodes, isNodeSelected, onClick],\n );\n\n return { onCheckboxClicked };\n}\n\nfunction forEachSelectedNode(\n nodes: Array<PresentationTreeNode>,\n isNodeSelected: (nodeId: string) => boolean,\n callback: (node: PresentationHierarchyNode) => void,\n) {\n nodes.forEach((node) => {\n if (!isPresentationHierarchyNode(node)) {\n return;\n }\n if (isNodeSelected(node.id)) {\n callback(node);\n }\n if (node.isExpanded && typeof node.children !== \"boolean\") {\n forEachSelectedNode(node.children, isNodeSelected, callback);\n }\n });\n}\n"]}
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { PresentationHierarchyNode, PresentationTreeNode } from "@itwin/presentation-hierarchies-react";
|
|
3
|
+
/** @beta */
|
|
4
|
+
export interface HighlightInfo {
|
|
5
|
+
text: string;
|
|
6
|
+
}
|
|
3
7
|
interface UseNodeHighlightingProps {
|
|
4
8
|
rootNodes: PresentationTreeNode[] | undefined;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
highlight?: HighlightInfo & {
|
|
10
|
+
activeMatchIndex?: number;
|
|
11
|
+
onHighlightChanged?: (activeMatchIndex: number, matches: number) => void;
|
|
12
|
+
};
|
|
8
13
|
}
|
|
9
14
|
interface UseNodeHighlightingResult {
|
|
10
15
|
activeNodeId?: string;
|
|
11
16
|
getLabel: (node: PresentationHierarchyNode) => React.ReactElement;
|
|
12
17
|
}
|
|
13
|
-
|
|
14
|
-
export declare function useNodeHighlighting({ rootNodes, searchText, activeMatchIndex, onHighlightChanged }: UseNodeHighlightingProps): UseNodeHighlightingResult;
|
|
18
|
+
export declare function useNodeHighlighting({ rootNodes, highlight }: UseNodeHighlightingProps): UseNodeHighlightingResult;
|
|
15
19
|
export {};
|
|
16
20
|
//# sourceMappingURL=UseNodeHighlighting.d.ts.map
|
|
@@ -8,40 +8,38 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
8
8
|
*--------------------------------------------------------------------------------------------*/
|
|
9
9
|
const react_1 = require("react");
|
|
10
10
|
const presentation_hierarchies_react_1 = require("@itwin/presentation-hierarchies-react");
|
|
11
|
-
|
|
12
|
-
function useNodeHighlighting({ rootNodes,
|
|
11
|
+
const Utils_1 = require("./Utils");
|
|
12
|
+
function useNodeHighlighting({ rootNodes, highlight }) {
|
|
13
13
|
const state = (0, react_1.useRef)({ nodeInfoMap: new Map(), totalMatches: 0 });
|
|
14
14
|
const [activeNodeId, setActiveNodeId] = (0, react_1.useState)();
|
|
15
|
-
const activeMatchIndexRef = useLatest(activeMatchIndex);
|
|
16
|
-
const activeNodeIdRef = useLatest(activeNodeId);
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
setActiveNodeId(undefined);
|
|
20
|
-
index = 0;
|
|
21
|
-
}
|
|
22
|
-
onHighlightChanged?.(index, matches);
|
|
23
|
-
}, [onHighlightChanged]);
|
|
15
|
+
const activeMatchIndexRef = (0, Utils_1.useLatest)(highlight?.activeMatchIndex);
|
|
16
|
+
const activeNodeIdRef = (0, Utils_1.useLatest)(activeNodeId);
|
|
17
|
+
const onHighlightChangedRef = (0, Utils_1.useLatest)(highlight?.onHighlightChanged);
|
|
18
|
+
const searchText = highlight?.text;
|
|
24
19
|
(0, react_1.useEffect)(() => {
|
|
25
20
|
const { state: newState, activeIndex } = rootNodes && searchText
|
|
26
21
|
? computeHighlightState(rootNodes, searchText, state.current, activeNodeIdRef.current, activeMatchIndexRef.current)
|
|
27
22
|
: { state: { nodeInfoMap: new Map(), totalMatches: 0 }, activeIndex: 0 };
|
|
28
23
|
state.current = newState;
|
|
29
|
-
|
|
30
|
-
|
|
24
|
+
if (newState.totalMatches === 0) {
|
|
25
|
+
setActiveNodeId(undefined);
|
|
26
|
+
}
|
|
27
|
+
onHighlightChangedRef.current?.(newState.totalMatches === 0 ? 0 : activeIndex, newState.totalMatches);
|
|
28
|
+
}, [rootNodes, searchText, activeNodeIdRef, activeMatchIndexRef, onHighlightChangedRef]);
|
|
31
29
|
(0, react_1.useEffect)(() => {
|
|
32
30
|
for (const nodeId of state.current.nodeInfoMap.keys()) {
|
|
33
|
-
if (getNodeChunkInfo(state.current, nodeId, activeMatchIndex)?.activeChunkIndex !== undefined) {
|
|
31
|
+
if (getNodeChunkInfo(state.current, nodeId, highlight?.activeMatchIndex)?.activeChunkIndex !== undefined) {
|
|
34
32
|
setActiveNodeId(nodeId);
|
|
35
33
|
}
|
|
36
34
|
}
|
|
37
|
-
}, [activeMatchIndex]);
|
|
35
|
+
}, [highlight?.activeMatchIndex]);
|
|
38
36
|
const getLabel = (0, react_1.useCallback)((node) => {
|
|
39
|
-
const chunkInfo = getNodeChunkInfo(state.current, node.id, activeMatchIndex);
|
|
37
|
+
const chunkInfo = getNodeChunkInfo(state.current, node.id, highlight?.activeMatchIndex);
|
|
40
38
|
if (searchText && chunkInfo) {
|
|
41
39
|
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: markChunks(node.label, chunkInfo.chunks, chunkInfo.activeChunkIndex) });
|
|
42
40
|
}
|
|
43
41
|
return (0, jsx_runtime_1.jsx)("span", { children: node.label });
|
|
44
|
-
}, [searchText, activeMatchIndex]);
|
|
42
|
+
}, [searchText, highlight?.activeMatchIndex]);
|
|
45
43
|
return { activeNodeId, getLabel };
|
|
46
44
|
}
|
|
47
45
|
exports.useNodeHighlighting = useNodeHighlighting;
|
|
@@ -130,11 +128,4 @@ function mergeChunks(chunks, activeChunk) {
|
|
|
130
128
|
}
|
|
131
129
|
return { mergedChunks, newActiveIndex };
|
|
132
130
|
}
|
|
133
|
-
function useLatest(value) {
|
|
134
|
-
const ref = (0, react_1.useRef)(value);
|
|
135
|
-
(0, react_1.useEffect)(() => {
|
|
136
|
-
ref.current = value;
|
|
137
|
-
}, [value]);
|
|
138
|
-
return ref;
|
|
139
|
-
}
|
|
140
131
|
//# sourceMappingURL=UseNodeHighlighting.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseNodeHighlighting.js","sourceRoot":"","sources":["../../../../../src/components/trees/common/UseNodeHighlighting.tsx"],"names":[],"mappings":";;;;AAAA;;;gGAGgG;AAEhG,iCAAiE;AACjE,0FAAoF;AAoCpF,gBAAgB;AAChB,SAAgB,mBAAmB,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,gBAAgB,EAAE,kBAAkB,EAA4B;IAC3H,MAAM,KAAK,GAAG,IAAA,cAAM,EAAiB,EAAE,WAAW,EAAE,IAAI,GAAG,EAAE,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC,CAAC;IAClF,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,IAAA,gBAAQ,GAAsB,CAAC;IACvE,MAAM,mBAAmB,GAAG,SAAS,CAAC,gBAAgB,CAAC,CAAC;IACxD,MAAM,eAAe,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC;IAEhD,MAAM,mBAAmB,GAAG,IAAA,mBAAW,EACrC,CAAC,KAAa,EAAE,OAAe,EAAE,EAAE;QACjC,IAAI,OAAO,KAAK,CAAC,EAAE;YACjB,eAAe,CAAC,SAAS,CAAC,CAAC;YAC3B,KAAK,GAAG,CAAC,CAAC;SACX;QACD,kBAAkB,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC,EACD,CAAC,kBAAkB,CAAC,CACrB,CAAC;IAEF,IAAA,iBAAS,EAAC,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,EAA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AkC,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;AAED,SAAS,SAAS,CAAI,KAAQ;IAC5B,MAAM,GAAG,GAAG,IAAA,cAAM,EAAC,KAAK,CAAC,CAAC;IAC1B,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC;IACtB,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IAEZ,OAAO,GAAG,CAAC;AACb,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\";\n\nimport type { PresentationHierarchyNode, PresentationTreeNode } from \"@itwin/presentation-hierarchies-react\";\n\ninterface UseNodeHighlightingProps {\n rootNodes: PresentationTreeNode[] | undefined;\n searchText?: string;\n activeMatchIndex?: number;\n onHighlightChanged?: (activeMatchIndex: number, matches: number) => void;\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, searchText, activeMatchIndex, onHighlightChanged }: UseNodeHighlightingProps): UseNodeHighlightingResult {\n const state = useRef<HighlightState>({ nodeInfoMap: new Map(), totalMatches: 0 });\n const [activeNodeId, setActiveNodeId] = useState<string | undefined>();\n const activeMatchIndexRef = useLatest(activeMatchIndex);\n const activeNodeIdRef = useLatest(activeNodeId);\n\n const updateHighlightInfo = useCallback(\n (index: number, matches: number) => {\n if (matches === 0) {\n setActiveNodeId(undefined);\n index = 0;\n }\n onHighlightChanged?.(index, matches);\n },\n [onHighlightChanged],\n );\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 updateHighlightInfo(activeIndex, newState.totalMatches);\n }, [rootNodes, searchText, activeNodeIdRef, activeMatchIndexRef, updateHighlightInfo]);\n\n useEffect(() => {\n for (const nodeId of state.current.nodeInfoMap.keys()) {\n if (getNodeChunkInfo(state.current, nodeId, activeMatchIndex)?.activeChunkIndex !== undefined) {\n setActiveNodeId(nodeId);\n }\n }\n }, [activeMatchIndex]);\n\n const getLabel = useCallback(\n (node: PresentationHierarchyNode) => {\n const chunkInfo = getNodeChunkInfo(state.current, node.id, activeMatchIndex);\n if (searchText && chunkInfo) {\n return <>{markChunks(node.label, chunkInfo.chunks, chunkInfo.activeChunkIndex)}</>;\n }\n return <span>{node.label}</span>;\n },\n [searchText, 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\nfunction useLatest<T>(value: T) {\n const ref = useRef(value);\n useEffect(() => {\n ref.current = value;\n }, [value]);\n\n return ref;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"UseNodeHighlighting.js","sourceRoot":"","sources":["../../../../../src/components/trees/common/UseNodeHighlighting.tsx"],"names":[],"mappings":";;;;AAAA;;;gGAGgG;AAEhG,iCAAiE;AACjE,0FAAoF;AACpF,mCAAoC;AA2CpC,SAAgB,mBAAmB,CAAC,EAAE,SAAS,EAAE,SAAS,EAA4B;IACpF,MAAM,KAAK,GAAG,IAAA,cAAM,EAAiB,EAAE,WAAW,EAAE,IAAI,GAAG,EAAE,EAAE,YAAY,EAAE,CAAC,EAAE,CAAC,CAAC;IAClF,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,IAAA,gBAAQ,GAAsB,CAAC;IACvE,MAAM,mBAAmB,GAAG,IAAA,iBAAS,EAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;IACnE,MAAM,eAAe,GAAG,IAAA,iBAAS,EAAC,YAAY,CAAC,CAAC;IAChD,MAAM,qBAAqB,GAAG,IAAA,iBAAS,EAAC,SAAS,EAAE,kBAAkB,CAAC,CAAC;IACvE,MAAM,UAAU,GAAG,SAAS,EAAE,IAAI,CAAC;IAEnC,IAAA,iBAAS,EAAC,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,OAAO,GAAG,QAAQ,CAAC;QACzB,IAAI,QAAQ,CAAC,YAAY,KAAK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;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\";\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"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { PropsWithChildren } from "react";
|
|
2
|
+
type TrackedFeatures = "visibility-change" | "hierarchy-level-filtering" | "filtering" | "hierarchy-level-size-limit-hit" | "zoom-to-node";
|
|
3
|
+
interface TelemetryContext {
|
|
4
|
+
onPerformanceMeasured: (featureId: string, duration: number) => void;
|
|
5
|
+
onFeatureUsed: (props: {
|
|
6
|
+
featureId?: TrackedFeatures;
|
|
7
|
+
reportInteraction: boolean;
|
|
8
|
+
}) => void;
|
|
9
|
+
}
|
|
10
|
+
/** @beta */
|
|
11
|
+
export interface TelemetryContextProviderProps {
|
|
12
|
+
/** Callback that is invoked when performance of tracked feature is measured. */
|
|
13
|
+
onPerformanceMeasured?: (featureId: string, duration: number) => void;
|
|
14
|
+
/** Callback that is invoked when a tracked feature is used. */
|
|
15
|
+
onFeatureUsed?: (featureId: string) => void;
|
|
16
|
+
/** Unique identifier that is appended to feature id to help track which component used that feature. */
|
|
17
|
+
componentIdentifier: string;
|
|
18
|
+
}
|
|
19
|
+
/** @beta */
|
|
20
|
+
export declare function TelemetryContextProvider({ children, onPerformanceMeasured, onFeatureUsed, componentIdentifier, }: PropsWithChildren<TelemetryContextProviderProps>): JSX.Element;
|
|
21
|
+
export declare function useTelemetryContext(): TelemetryContext;
|
|
22
|
+
interface UseReportingActionProps<TAction> {
|
|
23
|
+
action: TAction;
|
|
24
|
+
featureId?: TrackedFeatures;
|
|
25
|
+
}
|
|
26
|
+
/** @internal */
|
|
27
|
+
export declare function useReportingAction<TAction extends (...args: any[]) => void>({ action, featureId }: UseReportingActionProps<TAction>): (...args: Parameters<TAction>) => void;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=UseTelemetryContext.d.ts.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useReportingAction = exports.useTelemetryContext = exports.TelemetryContextProvider = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
/*---------------------------------------------------------------------------------------------
|
|
6
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
7
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
8
|
+
*--------------------------------------------------------------------------------------------*/
|
|
9
|
+
const react_1 = require("react");
|
|
10
|
+
const Utils_1 = require("./Utils");
|
|
11
|
+
const telemetryContext = (0, react_1.createContext)(undefined);
|
|
12
|
+
/** @beta */
|
|
13
|
+
function TelemetryContextProvider({ children, onPerformanceMeasured, onFeatureUsed, componentIdentifier, }) {
|
|
14
|
+
const onPerformanceMeasuredRef = (0, Utils_1.useLatest)(onPerformanceMeasured);
|
|
15
|
+
const onFeatureUsedRef = (0, Utils_1.useLatest)(onFeatureUsed);
|
|
16
|
+
const contextValue = (0, react_1.useMemo)(() => {
|
|
17
|
+
return {
|
|
18
|
+
onPerformanceMeasured: (featureId, duration) => onPerformanceMeasuredRef.current?.(`${componentIdentifier}-${featureId}`, duration),
|
|
19
|
+
onFeatureUsed: ({ featureId, reportInteraction }) => {
|
|
20
|
+
if (reportInteraction !== false) {
|
|
21
|
+
onFeatureUsedRef.current?.(`use-${componentIdentifier}`);
|
|
22
|
+
}
|
|
23
|
+
if (featureId) {
|
|
24
|
+
onFeatureUsedRef.current?.(`${componentIdentifier}-${featureId}`);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}, [componentIdentifier, onPerformanceMeasuredRef, onFeatureUsedRef]);
|
|
29
|
+
return (0, jsx_runtime_1.jsx)(telemetryContext.Provider, { value: contextValue, children: children });
|
|
30
|
+
}
|
|
31
|
+
exports.TelemetryContextProvider = TelemetryContextProvider;
|
|
32
|
+
const defaultContextValue = {
|
|
33
|
+
onPerformanceMeasured: () => { },
|
|
34
|
+
onFeatureUsed: () => { },
|
|
35
|
+
};
|
|
36
|
+
function useTelemetryContext() {
|
|
37
|
+
return (0, react_1.useContext)(telemetryContext) ?? defaultContextValue;
|
|
38
|
+
}
|
|
39
|
+
exports.useTelemetryContext = useTelemetryContext;
|
|
40
|
+
/** @internal */
|
|
41
|
+
function useReportingAction({ action, featureId }) {
|
|
42
|
+
const { onFeatureUsed } = useTelemetryContext();
|
|
43
|
+
return (0, react_1.useCallback)((...args) => {
|
|
44
|
+
onFeatureUsed({ featureId, reportInteraction: true });
|
|
45
|
+
action(...args);
|
|
46
|
+
}, [action, featureId, onFeatureUsed]);
|
|
47
|
+
}
|
|
48
|
+
exports.useReportingAction = useReportingAction;
|
|
49
|
+
//# sourceMappingURL=UseTelemetryContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UseTelemetryContext.js","sourceRoot":"","sources":["../../../../../src/components/trees/common/UseTelemetryContext.tsx"],"names":[],"mappings":";;;;AAAA;;;gGAGgG;AAEhG,iCAAwE;AACxE,mCAAoC;AAWpC,MAAM,gBAAgB,GAAG,IAAA,qBAAa,EAA+B,SAAS,CAAC,CAAC;AAYhF,YAAY;AACZ,SAAgB,wBAAwB,CAAC,EACvC,QAAQ,EACR,qBAAqB,EACrB,aAAa,EACb,mBAAmB,GAC8B;IACjD,MAAM,wBAAwB,GAAG,IAAA,iBAAS,EAAC,qBAAqB,CAAC,CAAC;IAClE,MAAM,gBAAgB,GAAG,IAAA,iBAAS,EAAC,aAAa,CAAC,CAAC;IAElD,MAAM,YAAY,GAAG,IAAA,eAAO,EAAmB,GAAG,EAAE;QAClD,OAAO;YACL,qBAAqB,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,EAAE,CAAC,wBAAwB,CAAC,OAAO,EAAE,CAAC,GAAG,mBAAmB,IAAI,SAAS,EAAE,EAAE,QAAQ,CAAC;YACnI,aAAa,EAAE,CAAC,EAAE,SAAS,EAAE,iBAAiB,EAAE,EAAE,EAAE;gBAClD,IAAI,iBAAiB,KAAK,KAAK,EAAE;oBAC/B,gBAAgB,CAAC,OAAO,EAAE,CAAC,OAAO,mBAAmB,EAAE,CAAC,CAAC;iBAC1D;gBACD,IAAI,SAAS,EAAE;oBACb,gBAAgB,CAAC,OAAO,EAAE,CAAC,GAAG,mBAAmB,IAAI,SAAS,EAAE,CAAC,CAAC;iBACnE;YACH,CAAC;SACF,CAAC;IACJ,CAAC,EAAE,CAAC,mBAAmB,EAAE,wBAAwB,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAEtE,OAAO,uBAAC,gBAAgB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,YAAG,QAAQ,GAA6B,CAAC;AAChG,CAAC;AAxBD,4DAwBC;AAED,MAAM,mBAAmB,GAAqB;IAC5C,qBAAqB,EAAE,GAAG,EAAE,GAAE,CAAC;IAC/B,aAAa,EAAE,GAAG,EAAE,GAAE,CAAC;CACxB,CAAC;AAEF,SAAgB,mBAAmB;IACjC,OAAO,IAAA,kBAAU,EAAC,gBAAgB,CAAC,IAAI,mBAAmB,CAAC;AAC7D,CAAC;AAFD,kDAEC;AAOD,gBAAgB;AAChB,SAAgB,kBAAkB,CAA2C,EAAE,MAAM,EAAE,SAAS,EAAoC;IAClI,MAAM,EAAE,aAAa,EAAE,GAAG,mBAAmB,EAAE,CAAC;IAChD,OAAO,IAAA,mBAAW,EAChB,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;AATD,gDASC","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 \"./Utils\";\n\nimport type { PropsWithChildren } from \"react\";\n\ntype TrackedFeatures = \"visibility-change\" | \"hierarchy-level-filtering\" | \"filtering\" | \"hierarchy-level-size-limit-hit\" | \"zoom-to-node\";\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\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,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
import type { Id64Array } from "@itwin/core-bentley";
|
|
2
3
|
import type { IModelConnection } from "@itwin/core-frontend";
|
|
3
4
|
import type { SchemaContext } from "@itwin/ecschema-metadata";
|
|
@@ -18,4 +19,6 @@ export declare function createIModelAccess({ imodel, getSchemaContext }: {
|
|
|
18
19
|
classDerivesFrom(derivedClassFullName: string, candidateBaseClassFullName: string): boolean | Promise<boolean>;
|
|
19
20
|
getSchema(schemaName: string): Promise<import("@itwin/presentation-shared").EC.Schema | undefined>;
|
|
20
21
|
};
|
|
22
|
+
/** @internal */
|
|
23
|
+
export declare function useLatest<T>(value: T): import("react").MutableRefObject<T>;
|
|
21
24
|
//# sourceMappingURL=Utils.d.ts.map
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
5
|
*--------------------------------------------------------------------------------------------*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.createIModelAccess = exports.pushToMap = exports.parseIdsSelectorResult = exports.createIdsSelector = void 0;
|
|
7
|
+
exports.useLatest = exports.createIModelAccess = exports.pushToMap = exports.parseIdsSelectorResult = exports.createIdsSelector = void 0;
|
|
8
|
+
const react_1 = require("react");
|
|
8
9
|
const presentation_core_interop_1 = require("@itwin/presentation-core-interop");
|
|
9
10
|
const presentation_hierarchies_1 = require("@itwin/presentation-hierarchies");
|
|
10
11
|
const presentation_shared_1 = require("@itwin/presentation-shared");
|
|
@@ -52,4 +53,13 @@ function createIModelAccess({ imodel, getSchemaContext }) {
|
|
|
52
53
|
};
|
|
53
54
|
}
|
|
54
55
|
exports.createIModelAccess = createIModelAccess;
|
|
56
|
+
/** @internal */
|
|
57
|
+
function useLatest(value) {
|
|
58
|
+
const ref = (0, react_1.useRef)(value);
|
|
59
|
+
(0, react_1.useEffect)(() => {
|
|
60
|
+
ref.current = value;
|
|
61
|
+
}, [value]);
|
|
62
|
+
return ref;
|
|
63
|
+
}
|
|
64
|
+
exports.useLatest = useLatest;
|
|
55
65
|
//# sourceMappingURL=Utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../../../src/components/trees/common/Utils.ts"],"names":[],"mappings":";AAAA;;;gGAGgG;;;AAEhG,gFAAoG;AACpG,8EAAmF;AACnF,oEAAoF;AAMpF,gBAAgB;AAChB,SAAgB,iBAAiB,CAAC,GAAc;IAC9C,sHAAsH;IACtH,oCAAoC;IACpC,MAAM,MAAM,GAAG,IAAI,KAAK,EAAgB,CAAC;IACzC,KAAK,IAAI,eAAe,GAAG,CAAC,EAAE,eAAe,GAAG,GAAG,CAAC,MAAM,EAAE,eAAe,IAAI,GAAG,EAAE;QAClF,IAAI,aAAa,GAAuB,eAAe,GAAG,GAAG,CAAC;QAC9D,IAAI,aAAa,GAAG,GAAG,CAAC,MAAM,EAAE;YAC9B,aAAa,GAAG,SAAS,CAAC;SAC3B;QACD,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC,CAAC;KACxD;IACD,OAAO,cAAc,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,cAAc,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;AACzH,CAAC;AAZD,8CAYC;AAED,gBAAgB;AAChB,SAAgB,sBAAsB,CAAC,cAAmB;IACxD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE;QAClC,OAAO,EAAE,CAAC;KACX;IACD,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAA8B,EAAE,EAAE,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,KAAK,EAAc,CAAC,CAAC;AAClJ,CAAC;AALD,wDAKC;AAED,gBAAgB;AAChB,SAAgB,SAAS,CAAe,SAAiC,EAAE,GAAS,EAAE,KAAa;IACjG,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,CAAC,GAAG,EAAE;QACR,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;QAChB,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;KACzB;IACD,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACjB,CAAC;AAPD,8BAOC;AAED,gBAAgB;AAChB,SAAgB,kBAAkB,CAAC,EAAE,MAAM,EAAE,gBAAgB,EAA+F;IAC1J,MAAM,OAAO,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACzC,MAAM,cAAc,GAAG,IAAA,kDAAsB,EAAC,OAAO,CAAC,CAAC;IACvD,OAAO;QACL,GAAG,cAAc;QACjB,GAAG,IAAA,4DAAsC,EAAC,EAAE,cAAc,EAAE,CAAC;QAC7D,GAAG,IAAA,2DAAgC,EAAC,IAAA,oDAAwB,EAAC,MAAM,CAAC,EAAE,IAAI,CAAC;KAC5E,CAAC;AACJ,CAAC;AARD,gDAQC","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 { createECSchemaProvider, createECSqlQueryExecutor } from \"@itwin/presentation-core-interop\";\nimport { createLimitingECSqlQueryExecutor } from \"@itwin/presentation-hierarchies\";\nimport { createCachingECClassHierarchyInspector } from \"@itwin/presentation-shared\";\n\nimport type { Id64Array, Id64String } from \"@itwin/core-bentley\";\nimport type { IModelConnection } from \"@itwin/core-frontend\";\nimport type { SchemaContext } from \"@itwin/ecschema-metadata\";\n\n/** @internal */\nexport function createIdsSelector(ids: Id64Array): string {\n // Note: `json_array` function only accepts up to 127 arguments and we may have more `ids` than that. As a workaround,\n // we're creating an array of arrays\n const slices = new Array<Id64String[]>();\n for (let sliceStartIndex = 0; sliceStartIndex < ids.length; sliceStartIndex += 127) {\n let sliceEndIndex: number | undefined = sliceStartIndex + 127;\n if (sliceEndIndex > ids.length) {\n sliceEndIndex = undefined;\n }\n slices.push(ids.slice(sliceStartIndex, sliceEndIndex));\n }\n return `json_array(${slices.map((sliceIds) => `json_array(${sliceIds.map((id) => `'${id}'`).join(\",\")})`).join(\",\")})`;\n}\n\n/** @internal */\nexport function parseIdsSelectorResult(selectorResult: any): Id64Array {\n if (!Array.isArray(selectorResult)) {\n return [];\n }\n return selectorResult.reduce((arr, ids: Id64String | Id64String[]) => [...arr, ...(Array.isArray(ids) ? ids : [ids])], new Array<Id64String>());\n}\n\n/** @internal */\nexport function pushToMap<TKey, TValue>(targetMap: Map<TKey, Set<TValue>>, key: TKey, value: TValue) {\n let set = targetMap.get(key);\n if (!set) {\n set = new Set();\n targetMap.set(key, set);\n }\n set.add(value);\n}\n\n/** @internal */\nexport function createIModelAccess({ imodel, getSchemaContext }: { imodel: IModelConnection; getSchemaContext: (imodel: IModelConnection) => SchemaContext }) {\n const schemas = getSchemaContext(imodel);\n const schemaProvider = createECSchemaProvider(schemas);\n return {\n ...schemaProvider,\n ...createCachingECClassHierarchyInspector({ schemaProvider }),\n ...createLimitingECSqlQueryExecutor(createECSqlQueryExecutor(imodel), 1000),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../../../src/components/trees/common/Utils.ts"],"names":[],"mappings":";A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ED,gBAAgB;AAChB,SAAgB,SAAS,CAAe,SAAiC,EAAE,GAAS,EAAE,KAAa;IACjG,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,CAAC,GAAG,EAAE;QACR,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;QAChB,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;KACzB;IACD,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACjB,CAAC;AAPD,8BAOC;AAED,gBAAgB;AAChB,SAAgB,kBAAkB,CAAC,EAAE,MAAM,EAAE,gBAAgB,EAA+F;IAC1J,MAAM,OAAO,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IACzC,MAAM,cAAc,GAAG,IAAA,kDAAsB,EAAC,OAAO,CAAC,CAAC;IACvD,OAAO;QACL,GAAG,cAAc;QACjB,GAAG,IAAA,4DAAsC,EAAC,EAAE,cAAc,EAAE,CAAC;QAC7D,GAAG,IAAA,2DAAgC,EAAC,IAAA,oDAAwB,EAAC,MAAM,CAAC,EAAE,IAAI,CAAC;KAC5E,CAAC;AACJ,CAAC;AARD,gDAQC;AAED,gBAAgB;AAChB,SAAgB,SAAS,CAAI,KAAQ;IACnC,MAAM,GAAG,GAAG,IAAA,cAAM,EAAC,KAAK,CAAC,CAAC;IAC1B,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC;IACtB,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IACZ,OAAO,GAAG,CAAC;AACb,CAAC;AAND,8BAMC","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 } from \"react\";\nimport { createECSchemaProvider, createECSqlQueryExecutor } from \"@itwin/presentation-core-interop\";\nimport { createLimitingECSqlQueryExecutor } from \"@itwin/presentation-hierarchies\";\nimport { createCachingECClassHierarchyInspector } from \"@itwin/presentation-shared\";\n\nimport type { Id64Array, Id64String } from \"@itwin/core-bentley\";\nimport type { IModelConnection } from \"@itwin/core-frontend\";\nimport type { SchemaContext } from \"@itwin/ecschema-metadata\";\n\n/** @internal */\nexport function createIdsSelector(ids: Id64Array): string {\n // Note: `json_array` function only accepts up to 127 arguments and we may have more `ids` than that. As a workaround,\n // we're creating an array of arrays\n const slices = new Array<Id64String[]>();\n for (let sliceStartIndex = 0; sliceStartIndex < ids.length; sliceStartIndex += 127) {\n let sliceEndIndex: number | undefined = sliceStartIndex + 127;\n if (sliceEndIndex > ids.length) {\n sliceEndIndex = undefined;\n }\n slices.push(ids.slice(sliceStartIndex, sliceEndIndex));\n }\n return `json_array(${slices.map((sliceIds) => `json_array(${sliceIds.map((id) => `'${id}'`).join(\",\")})`).join(\",\")})`;\n}\n\n/** @internal */\nexport function parseIdsSelectorResult(selectorResult: any): Id64Array {\n if (!Array.isArray(selectorResult)) {\n return [];\n }\n return selectorResult.reduce((arr, ids: Id64String | Id64String[]) => [...arr, ...(Array.isArray(ids) ? ids : [ids])], new Array<Id64String>());\n}\n\n/** @internal */\nexport function pushToMap<TKey, TValue>(targetMap: Map<TKey, Set<TValue>>, key: TKey, value: TValue) {\n let set = targetMap.get(key);\n if (!set) {\n set = new Set();\n targetMap.set(key, set);\n }\n set.add(value);\n}\n\n/** @internal */\nexport function createIModelAccess({ imodel, getSchemaContext }: { imodel: IModelConnection; getSchemaContext: (imodel: IModelConnection) => SchemaContext }) {\n const schemas = getSchemaContext(imodel);\n const schemaProvider = createECSchemaProvider(schemas);\n return {\n ...schemaProvider,\n ...createCachingECClassHierarchyInspector({ schemaProvider }),\n ...createLimitingECSqlQueryExecutor(createECSqlQueryExecutor(imodel), 1000),\n };\n}\n\n/** @internal */\nexport function useLatest<T>(value: T) {\n const ref = useRef(value);\n useEffect(() => {\n ref.current = value;\n }, [value]);\n return ref;\n}\n"]}
|
|
@@ -7,7 +7,6 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
7
7
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
8
8
|
*--------------------------------------------------------------------------------------------*/
|
|
9
9
|
const react_1 = require("react");
|
|
10
|
-
/** @internal */
|
|
11
10
|
function Delayed({ show, children }) {
|
|
12
11
|
const [visible, setVisible] = (0, react_1.useState)(false);
|
|
13
12
|
(0, react_1.useLayoutEffect)(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Delayed.js","sourceRoot":"","sources":["../../../../../../src/components/trees/common/components/Delayed.tsx"],"names":[],"mappings":";;;;AAAA;;;gGAGgG;AAEhG,iCAAkD;AAIlD,
|
|
1
|
+
{"version":3,"file":"Delayed.js","sourceRoot":"","sources":["../../../../../../src/components/trees/common/components/Delayed.tsx"],"names":[],"mappings":";;;;AAAA;;;gGAGgG;AAEhG,iCAAkD;AAIlD,SAAgB,OAAO,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAwC;IAC9E,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC;IAE9C,IAAA,uBAAe,EAAC,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,2DAAG,QAAQ,GAAI,CAAC;AACzB,CAAC;AAtBD,0BAsBC","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"]}
|
|
@@ -8,7 +8,6 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
8
8
|
*--------------------------------------------------------------------------------------------*/
|
|
9
9
|
require("./ProgressOverlay.scss");
|
|
10
10
|
const itwinui_react_1 = require("@itwin/itwinui-react");
|
|
11
|
-
/** @internal */
|
|
12
11
|
function ProgressOverlay() {
|
|
13
12
|
return ((0, jsx_runtime_1.jsxs)("div", { className: "tw-progress-overlay-container", children: [(0, jsx_runtime_1.jsx)(itwinui_react_1.ProgressLinear, { indeterminate: true }), (0, jsx_runtime_1.jsx)("div", { className: "tw-progress-overlay-backdrop" })] }));
|
|
14
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProgressOverlay.js","sourceRoot":"","sources":["../../../../../../src/components/trees/common/components/ProgressOverlay.tsx"],"names":[],"mappings":";;;;AAAA;;;gGAGgG;AAEhG,kCAAgC;AAChC,wDAAsD;AAEtD,
|
|
1
|
+
{"version":3,"file":"ProgressOverlay.js","sourceRoot":"","sources":["../../../../../../src/components/trees/common/components/ProgressOverlay.tsx"],"names":[],"mappings":";;;;AAAA;;;gGAGgG;AAEhG,kCAAgC;AAChC,wDAAsD;AAEtD,SAAgB,eAAe;IAC7B,OAAO,CACL,iCAAK,SAAS,EAAC,+BAA+B,aAC5C,uBAAC,8BAAc,IAAC,aAAa,SAAG,EAChC,gCAAK,SAAS,EAAC,8BAA8B,GAAG,IAC5C,CACP,CAAC;AACJ,CAAC;AAPD,0CAOC","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.scss\";\nimport { ProgressLinear } from \"@itwin/itwinui-react\";\n\nexport function ProgressOverlay() {\n return (\n <div className=\"tw-progress-overlay-container\">\n <ProgressLinear indeterminate />\n <div className=\"tw-progress-overlay-backdrop\" />\n </div>\n );\n}\n"]}
|