@itwin/tree-widget-react 4.0.0-alpha.7 → 4.0.0-alpha.9
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/lib/esm/tree-widget-react/TreeWidget.d.ts +6 -1
- package/lib/esm/tree-widget-react/TreeWidget.js +19 -2
- package/lib/esm/tree-widget-react/TreeWidget.js.map +1 -1
- package/lib/esm/tree-widget-react/components/TreeWidgetComponentImpl.d.ts +6 -0
- package/lib/esm/tree-widget-react/components/TreeWidgetComponentImpl.js +22 -23
- package/lib/esm/tree-widget-react/components/TreeWidgetComponentImpl.js.map +1 -1
- package/lib/esm/tree-widget-react/components/TreeWidgetUiItemsProvider.js +1 -1
- package/lib/esm/tree-widget-react/components/TreeWidgetUiItemsProvider.js.map +1 -1
- package/lib/esm/tree-widget-react/components/tree-header/ErrorState.js +1 -1
- package/lib/esm/tree-widget-react/components/tree-header/ErrorState.js.map +1 -1
- package/lib/esm/tree-widget-react/components/tree-header/SearchBox.d.ts +0 -1
- package/lib/esm/tree-widget-react/components/tree-header/SearchBox.js +3 -4
- package/lib/esm/tree-widget-react/components/tree-header/SearchBox.js.map +1 -1
- package/lib/esm/tree-widget-react/components/tree-header/WidgetHeader.css +1 -0
- package/lib/esm/tree-widget-react/components/tree-header/WidgetHeader.d.ts +12 -4
- package/lib/esm/tree-widget-react/components/tree-header/WidgetHeader.js +13 -9
- package/lib/esm/tree-widget-react/components/tree-header/WidgetHeader.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTree.d.ts +2 -2
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTree.js +2 -2
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/CategoriesTreeButtons.js +3 -3
- 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.d.ts +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/UseCategoriesTree.js +36 -182
- 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.js +7 -11
- 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/CategoriesTreeVisibilityHandler.js +107 -191
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeVisibilityHandler.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/UseFilteredPaths.d.ts +25 -0
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/UseFilteredPaths.js +133 -0
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/UseFilteredPaths.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/UseIdsCache.d.ts +8 -0
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/UseIdsCache.js +48 -0
- package/lib/esm/tree-widget-react/components/trees/categories-tree/internal/UseIdsCache.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/common/UseHierarchyVisibility.d.ts +0 -2
- package/lib/esm/tree-widget-react/components/trees/common/UseHierarchyVisibility.js +8 -4
- package/lib/esm/tree-widget-react/components/trees/common/UseHierarchyVisibility.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/UseNodeHighlighting.js +11 -10
- package/lib/esm/tree-widget-react/components/trees/common/UseNodeHighlighting.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/Utils.d.ts +5 -0
- package/lib/esm/tree-widget-react/components/trees/common/Utils.js +5 -0
- 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.d.ts +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/BaseTreeRenderer.js +2 -2
- 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/Tree.d.ts +3 -3
- package/lib/esm/tree-widget-react/components/trees/common/components/Tree.js +11 -2
- package/lib/esm/tree-widget-react/components/trees/common/components/Tree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/TreeNodeVisibilityButton.d.ts +6 -4
- package/lib/esm/tree-widget-react/components/trees/common/components/TreeNodeVisibilityButton.js +20 -25
- package/lib/esm/tree-widget-react/components/trees/common/components/TreeNodeVisibilityButton.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/TreeRenderer.d.ts +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/TreeRenderer.js +10 -4
- package/lib/esm/tree-widget-react/components/trees/common/components/TreeRenderer.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/UseVisibilityButtonHandler.js +6 -3
- 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/VisibilityTreeRenderer.d.ts +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/components/VisibilityTreeRenderer.js +12 -11
- 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/Tooltip.d.ts +3 -11
- package/lib/esm/tree-widget-react/components/trees/common/internal/Tooltip.js +3 -15
- package/lib/esm/tree-widget-react/components/trees/common/internal/Tooltip.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/common/internal/VisibilityUtils.d.ts +4 -23
- package/lib/esm/tree-widget-react/components/trees/common/internal/VisibilityUtils.js +33 -57
- package/lib/esm/tree-widget-react/components/trees/common/internal/VisibilityUtils.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTree.d.ts +2 -2
- package/lib/esm/tree-widget-react/components/trees/external-sources-tree/ExternalSourcesTree.js +8 -8
- 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.d.ts +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/imodel-content-tree/IModelContentTree.d.ts +2 -2
- package/lib/esm/tree-widget-react/components/trees/imodel-content-tree/IModelContentTree.js +11 -11
- 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 +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/models-tree/ModelsTree.d.ts +2 -2
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTree.js +2 -2
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTree.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js +6 -6
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeButtons.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/ModelsTreeComponent.d.ts +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/UseModelsTree.js +36 -220
- 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/ModelsTreeVisibilityHandler.js +24 -87
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/UseFilteredPaths.d.ts +27 -0
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/UseFilteredPaths.js +170 -0
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/UseFilteredPaths.js.map +1 -0
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/UseIdsCache.d.ts +8 -0
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/UseIdsCache.js +47 -0
- package/lib/esm/tree-widget-react/components/trees/models-tree/internal/UseIdsCache.js.map +1 -0
- package/lib/public/locales/en/TreeWidget.json +4 -95
- package/package.json +6 -6
- package/lib/esm/tree-widget-react/components/tree-header/SearchBox.css +0 -8
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import { useEffect, useMemo, useState } from "react";
|
|
6
|
+
import { HierarchyNodeIdentifier, HierarchyNodeKey } from "@itwin/presentation-hierarchies";
|
|
7
|
+
import { useFocusedInstancesContext } from "../../common/FocusedInstancesContext.js";
|
|
8
|
+
import { GEOMETRIC_MODEL_3D_CLASS_NAME, SUBJECT_CLASS_NAME } from "../../common/internal/ClassNameDefinitions.js";
|
|
9
|
+
import { FilterLimitExceededError } from "../../common/TreeErrors.js";
|
|
10
|
+
import { useTelemetryContext } from "../../common/UseTelemetryContext.js";
|
|
11
|
+
import { ModelsTreeDefinition } from "../ModelsTreeDefinition.js";
|
|
12
|
+
/** @internal */
|
|
13
|
+
export function useFilteredPaths({ hierarchyConfiguration, filter, getFilteredPaths, getModelsTreeIdsCache, onModelsFiltered, onFilteredPathsChanged, }) {
|
|
14
|
+
const [filteringError, setFilteringError] = useState(undefined);
|
|
15
|
+
const { onFeatureUsed } = useTelemetryContext();
|
|
16
|
+
const { loadFocusedItems } = useFocusedInstancesContext();
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
setFilteringError(undefined);
|
|
19
|
+
onModelsFiltered?.(undefined);
|
|
20
|
+
// reset filtered paths if there is no filters applied. This allows to keep current filtered paths until new paths are loaded.
|
|
21
|
+
if (!loadFocusedItems && !getFilteredPaths && !filter) {
|
|
22
|
+
onFilteredPathsChanged(undefined);
|
|
23
|
+
}
|
|
24
|
+
}, [loadFocusedItems, getFilteredPaths, filter, onModelsFiltered, onFilteredPathsChanged]);
|
|
25
|
+
const getPaths = useMemo(() => {
|
|
26
|
+
const handlePaths = async (filteredPaths, classInspector) => {
|
|
27
|
+
onFilteredPathsChanged(filteredPaths);
|
|
28
|
+
if (!onModelsFiltered) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const modelIds = await getModels(filteredPaths, getModelsTreeIdsCache(), classInspector);
|
|
32
|
+
onModelsFiltered(modelIds);
|
|
33
|
+
};
|
|
34
|
+
if (loadFocusedItems) {
|
|
35
|
+
return async ({ imodelAccess }) => {
|
|
36
|
+
try {
|
|
37
|
+
const focusedItems = await collectFocusedItems(loadFocusedItems);
|
|
38
|
+
const paths = await ModelsTreeDefinition.createInstanceKeyPaths({
|
|
39
|
+
imodelAccess,
|
|
40
|
+
idsCache: getModelsTreeIdsCache(),
|
|
41
|
+
targetItems: focusedItems,
|
|
42
|
+
hierarchyConfig: hierarchyConfiguration,
|
|
43
|
+
});
|
|
44
|
+
void handlePaths(paths, imodelAccess);
|
|
45
|
+
return paths.map((path) => ("path" in path ? path : { path, options: { autoExpand: true } }));
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
const newError = e instanceof FilterLimitExceededError ? "tooManyInstancesFocused" : "unknownInstanceFocusError";
|
|
49
|
+
if (newError !== "tooManyInstancesFocused") {
|
|
50
|
+
const feature = e instanceof Error && e.message.includes("query too long to execute or server is too busy") ? "error-timeout" : "error-unknown";
|
|
51
|
+
onFeatureUsed({ featureId: feature, reportInteraction: false });
|
|
52
|
+
}
|
|
53
|
+
setFilteringError(newError);
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (getFilteredPaths) {
|
|
59
|
+
return async ({ imodelAccess }) => {
|
|
60
|
+
try {
|
|
61
|
+
const paths = await getFilteredPaths({
|
|
62
|
+
createInstanceKeyPaths: async (props) => ModelsTreeDefinition.createInstanceKeyPaths({
|
|
63
|
+
...props,
|
|
64
|
+
imodelAccess,
|
|
65
|
+
idsCache: getModelsTreeIdsCache(),
|
|
66
|
+
hierarchyConfig: hierarchyConfiguration,
|
|
67
|
+
limit: "unbounded",
|
|
68
|
+
}),
|
|
69
|
+
});
|
|
70
|
+
void handlePaths(paths, imodelAccess);
|
|
71
|
+
return paths;
|
|
72
|
+
}
|
|
73
|
+
catch (e) {
|
|
74
|
+
const newError = e instanceof FilterLimitExceededError ? "tooManyFilterMatches" : "unknownFilterError";
|
|
75
|
+
if (newError !== "tooManyFilterMatches") {
|
|
76
|
+
const feature = e instanceof Error && e.message.includes("query too long to execute or server is too busy") ? "error-timeout" : "error-unknown";
|
|
77
|
+
onFeatureUsed({ featureId: feature, reportInteraction: false });
|
|
78
|
+
}
|
|
79
|
+
setFilteringError(newError);
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (filter) {
|
|
85
|
+
return async ({ imodelAccess }) => {
|
|
86
|
+
onFeatureUsed({ featureId: "filtering", reportInteraction: true });
|
|
87
|
+
try {
|
|
88
|
+
const paths = await ModelsTreeDefinition.createInstanceKeyPaths({
|
|
89
|
+
imodelAccess,
|
|
90
|
+
label: filter,
|
|
91
|
+
idsCache: getModelsTreeIdsCache(),
|
|
92
|
+
hierarchyConfig: hierarchyConfiguration,
|
|
93
|
+
});
|
|
94
|
+
void handlePaths(paths, imodelAccess);
|
|
95
|
+
return paths.map((path) => ("path" in path ? path : { path, options: { autoExpand: true } }));
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
const newError = e instanceof FilterLimitExceededError ? "tooManyFilterMatches" : "unknownFilterError";
|
|
99
|
+
if (newError !== "tooManyFilterMatches") {
|
|
100
|
+
const feature = e instanceof Error && e.message.includes("query too long to execute or server is too busy") ? "error-timeout" : "error-unknown";
|
|
101
|
+
onFeatureUsed({ featureId: feature, reportInteraction: false });
|
|
102
|
+
}
|
|
103
|
+
setFilteringError(newError);
|
|
104
|
+
return [];
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
return undefined;
|
|
109
|
+
}, [filter, loadFocusedItems, getModelsTreeIdsCache, onFeatureUsed, getFilteredPaths, hierarchyConfiguration, onModelsFiltered, onFilteredPathsChanged]);
|
|
110
|
+
return {
|
|
111
|
+
getPaths,
|
|
112
|
+
filteringError,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
async function getModels(paths, idsCache, classInspector) {
|
|
116
|
+
if (!paths) {
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
const targetModelIds = new Set();
|
|
120
|
+
const targetSubjectIds = new Set();
|
|
121
|
+
for (const path of paths) {
|
|
122
|
+
const currPath = Array.isArray(path) ? path : path.path;
|
|
123
|
+
for (let i = 0; i < currPath.length; i++) {
|
|
124
|
+
const currStep = currPath[i];
|
|
125
|
+
if (!HierarchyNodeIdentifier.isInstanceNodeIdentifier(currStep)) {
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
// if paths end with subject need to get all models under that subject
|
|
129
|
+
if (i === currPath.length - 1 && currStep.className === SUBJECT_CLASS_NAME) {
|
|
130
|
+
targetSubjectIds.add(currStep.id);
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
// collect all the models from the filtered path
|
|
134
|
+
if (await classInspector.classDerivesFrom(currStep.className, GEOMETRIC_MODEL_3D_CLASS_NAME)) {
|
|
135
|
+
targetModelIds.add(currStep.id);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const matchingModels = await idsCache.getSubjectModelIds([...targetSubjectIds]);
|
|
140
|
+
return [...targetModelIds, ...matchingModels];
|
|
141
|
+
}
|
|
142
|
+
async function collectFocusedItems(loadFocusedItems) {
|
|
143
|
+
const focusedItems = [];
|
|
144
|
+
const groupingNodeInfos = [];
|
|
145
|
+
for await (const key of loadFocusedItems()) {
|
|
146
|
+
if ("id" in key) {
|
|
147
|
+
focusedItems.push(key);
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (!HierarchyNodeKey.isClassGrouping(key.key)) {
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
const groupingNode = key;
|
|
154
|
+
if (!groupingNode.nonGroupingAncestor || !HierarchyNodeKey.isInstances(groupingNode.nonGroupingAncestor.key)) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const parentKey = groupingNode.nonGroupingAncestor.key;
|
|
158
|
+
const type = groupingNode.nonGroupingAncestor.extendedData?.isCategory ? "category" : "element";
|
|
159
|
+
const modelIds = (groupingNode.nonGroupingAncestor.extendedData?.modelIds ?? []).flatMap((ids) => ids);
|
|
160
|
+
groupingNodeInfos.push({ groupingNode, parentType: type, parentKey, modelIds });
|
|
161
|
+
}
|
|
162
|
+
focusedItems.push(...groupingNodeInfos.map(({ parentKey, parentType, groupingNode, modelIds }) => ({
|
|
163
|
+
parent: parentType === "element"
|
|
164
|
+
? { type: "element", ids: parentKey.instanceKeys.map((key) => key.id) }
|
|
165
|
+
: { type: "category", ids: parentKey.instanceKeys.map((key) => key.id), modelIds },
|
|
166
|
+
groupingNode,
|
|
167
|
+
})));
|
|
168
|
+
return focusedItems;
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=UseFilteredPaths.js.map
|
package/lib/esm/tree-widget-react/components/trees/models-tree/internal/UseFilteredPaths.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UseFilteredPaths.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/models-tree/internal/UseFilteredPaths.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAGhG,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAC5F,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AACrF,OAAO,EAAE,6BAA6B,EAAE,kBAAkB,EAAE,MAAM,+CAA+C,CAAC;AAClH,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAWlE,gBAAgB;AAChB,MAAM,UAAU,gBAAgB,CAAC,EAC/B,sBAAsB,EACtB,MAAM,EACN,gBAAgB,EAChB,qBAAqB,EACrB,gBAAgB,EAChB,sBAAsB,GAUvB;IAIC,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,QAAQ,CAAuC,SAAS,CAAC,CAAC;IAEtG,MAAM,EAAE,aAAa,EAAE,GAAG,mBAAmB,EAAE,CAAC;IAChD,MAAM,EAAE,gBAAgB,EAAE,GAAG,0BAA0B,EAAE,CAAC;IAE1D,SAAS,CAAC,GAAG,EAAE;QACb,iBAAiB,CAAC,SAAS,CAAC,CAAC;QAC7B,gBAAgB,EAAE,CAAC,SAAS,CAAC,CAAC;QAE9B,8HAA8H;QAC9H,IAAI,CAAC,gBAAgB,IAAI,CAAC,gBAAgB,IAAI,CAAC,MAAM,EAAE;YACrD,sBAAsB,CAAC,SAAS,CAAC,CAAC;SACnC;IACH,CAAC,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,EAAE,gBAAgB,EAAE,sBAAsB,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EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC;QAC/E,MAAM,EACJ,UAAU,KAAK,SAAS;YACtB,CAAC,CAAC,EAAE,IAAI,EAAE,SAAkB,EAAE,GAAG,EAAE,SAAS,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;YAChF,CAAC,CAAC,EAAE,IAAI,EAAE,UAAmB,EAAE,GAAG,EAAE,SAAS,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE;QAC/F,YAAY;KACb,CAAC,CAAC,CACJ,CAAC;IACF,OAAO,YAAY,CAAC;AACtB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport type { Id64Array, Id64String } from \"@itwin/core-bentley\";\nimport { useEffect, useMemo, useState } from \"react\";\nimport { HierarchyNodeIdentifier, HierarchyNodeKey } from \"@itwin/presentation-hierarchies\";\nimport { useFocusedInstancesContext } from \"../../common/FocusedInstancesContext.js\";\nimport { GEOMETRIC_MODEL_3D_CLASS_NAME, SUBJECT_CLASS_NAME } from \"../../common/internal/ClassNameDefinitions.js\";\nimport { FilterLimitExceededError } from \"../../common/TreeErrors.js\";\nimport { useTelemetryContext } from \"../../common/UseTelemetryContext.js\";\nimport { ModelsTreeDefinition } from \"../ModelsTreeDefinition.js\";\n\nimport type { GroupingHierarchyNode, HierarchyFilteringPath, InstancesNodeKey } from \"@itwin/presentation-hierarchies\";\nimport type { VisibilityTreeProps } from \"../../common/components/VisibilityTree.js\";\nimport type { ECClassHierarchyInspector, InstanceKey } from \"@itwin/presentation-shared\";\nimport type { ClassGroupingHierarchyNode, ElementsGroupInfo, ModelsTreeHierarchyConfiguration } from \"../ModelsTreeDefinition.js\";\nimport type { ModelsTreeIdsCache } from \"./ModelsTreeIdsCache.js\";\n\n/** @internal */\nexport type ModelsTreeFilteringError = \"tooManyFilterMatches\" | \"tooManyInstancesFocused\" | \"unknownFilterError\" | \"unknownInstanceFocusError\";\n\n/** @internal */\nexport function useFilteredPaths({\n hierarchyConfiguration,\n filter,\n getFilteredPaths,\n getModelsTreeIdsCache,\n onModelsFiltered,\n onFilteredPathsChanged,\n}: {\n hierarchyConfiguration: ModelsTreeHierarchyConfiguration;\n filter?: string;\n getFilteredPaths?: (props: {\n createInstanceKeyPaths: (props: { targetItems: Array<InstanceKey | ElementsGroupInfo> } | { label: string }) => Promise<HierarchyFilteringPath[]>;\n }) => Promise<HierarchyFilteringPath[]>;\n getModelsTreeIdsCache: () => ModelsTreeIdsCache;\n onModelsFiltered?: (modelIds: Id64String[] | undefined) => void;\n onFilteredPathsChanged: (paths: HierarchyFilteringPath[] | undefined) => void;\n}): {\n getPaths: VisibilityTreeProps[\"getFilteredPaths\"] | undefined;\n filteringError: ModelsTreeFilteringError | undefined;\n} {\n const [filteringError, setFilteringError] = useState<ModelsTreeFilteringError | undefined>(undefined);\n\n const { onFeatureUsed } = useTelemetryContext();\n const { loadFocusedItems } = useFocusedInstancesContext();\n\n useEffect(() => {\n setFilteringError(undefined);\n onModelsFiltered?.(undefined);\n\n // reset filtered paths if there is no filters applied. This allows to keep current filtered paths until new paths are loaded.\n if (!loadFocusedItems && !getFilteredPaths && !filter) {\n onFilteredPathsChanged(undefined);\n }\n }, [loadFocusedItems, getFilteredPaths, filter, onModelsFiltered, onFilteredPathsChanged]);\n\n const getPaths = useMemo<VisibilityTreeProps[\"getFilteredPaths\"] | undefined>(() => {\n const handlePaths = async (filteredPaths: HierarchyFilteringPath[], classInspector: ECClassHierarchyInspector) => {\n onFilteredPathsChanged(filteredPaths);\n if (!onModelsFiltered) {\n return;\n }\n\n const modelIds = await getModels(filteredPaths, getModelsTreeIdsCache(), classInspector);\n onModelsFiltered(modelIds);\n };\n\n if (loadFocusedItems) {\n return async ({ imodelAccess }) => {\n try {\n const focusedItems = await collectFocusedItems(loadFocusedItems);\n const paths = await ModelsTreeDefinition.createInstanceKeyPaths({\n imodelAccess,\n idsCache: getModelsTreeIdsCache(),\n targetItems: focusedItems,\n hierarchyConfig: hierarchyConfiguration,\n });\n void handlePaths(paths, imodelAccess);\n return paths.map((path) => (\"path\" in path ? path : { path, options: { autoExpand: true } }));\n } catch (e) {\n const newError = e instanceof FilterLimitExceededError ? \"tooManyInstancesFocused\" : \"unknownInstanceFocusError\";\n if (newError !== \"tooManyInstancesFocused\") {\n const feature = e instanceof Error && e.message.includes(\"query too long to execute or server is too busy\") ? \"error-timeout\" : \"error-unknown\";\n onFeatureUsed({ featureId: feature, reportInteraction: false });\n }\n setFilteringError(newError);\n return [];\n }\n };\n }\n\n if (getFilteredPaths) {\n return async ({ imodelAccess }) => {\n try {\n const paths = await getFilteredPaths({\n createInstanceKeyPaths: async (props) =>\n ModelsTreeDefinition.createInstanceKeyPaths({\n ...props,\n imodelAccess,\n idsCache: getModelsTreeIdsCache(),\n hierarchyConfig: hierarchyConfiguration,\n limit: \"unbounded\",\n }),\n });\n void handlePaths(paths, imodelAccess);\n return paths;\n } catch (e) {\n const newError = e instanceof FilterLimitExceededError ? \"tooManyFilterMatches\" : \"unknownFilterError\";\n if (newError !== \"tooManyFilterMatches\") {\n const feature = e instanceof Error && e.message.includes(\"query too long to execute or server is too busy\") ? \"error-timeout\" : \"error-unknown\";\n onFeatureUsed({ featureId: feature, reportInteraction: false });\n }\n setFilteringError(newError);\n return [];\n }\n };\n }\n\n if (filter) {\n return async ({ imodelAccess }) => {\n onFeatureUsed({ featureId: \"filtering\", reportInteraction: true });\n try {\n const paths = await ModelsTreeDefinition.createInstanceKeyPaths({\n imodelAccess,\n label: filter,\n idsCache: getModelsTreeIdsCache(),\n hierarchyConfig: hierarchyConfiguration,\n });\n void handlePaths(paths, imodelAccess);\n return paths.map((path) => (\"path\" in path ? path : { path, options: { autoExpand: true } }));\n } catch (e) {\n const newError = e instanceof FilterLimitExceededError ? \"tooManyFilterMatches\" : \"unknownFilterError\";\n if (newError !== \"tooManyFilterMatches\") {\n const feature = e instanceof Error && e.message.includes(\"query too long to execute or server is too busy\") ? \"error-timeout\" : \"error-unknown\";\n onFeatureUsed({ featureId: feature, reportInteraction: false });\n }\n setFilteringError(newError);\n return [];\n }\n };\n }\n return undefined;\n }, [filter, loadFocusedItems, getModelsTreeIdsCache, onFeatureUsed, getFilteredPaths, hierarchyConfiguration, onModelsFiltered, onFilteredPathsChanged]);\n\n return {\n getPaths,\n filteringError,\n };\n}\n\nasync function getModels(paths: HierarchyFilteringPath[], idsCache: ModelsTreeIdsCache, classInspector: ECClassHierarchyInspector) {\n if (!paths) {\n return undefined;\n }\n\n const targetModelIds = new Set<Id64String>();\n const targetSubjectIds = new Set<Id64String>();\n for (const path of paths) {\n const currPath = Array.isArray(path) ? path : path.path;\n for (let i = 0; i < currPath.length; i++) {\n const currStep = currPath[i];\n if (!HierarchyNodeIdentifier.isInstanceNodeIdentifier(currStep)) {\n break;\n }\n\n // if paths end with subject need to get all models under that subject\n if (i === currPath.length - 1 && currStep.className === SUBJECT_CLASS_NAME) {\n targetSubjectIds.add(currStep.id);\n break;\n }\n\n // collect all the models from the filtered path\n if (await classInspector.classDerivesFrom(currStep.className, GEOMETRIC_MODEL_3D_CLASS_NAME)) {\n targetModelIds.add(currStep.id);\n }\n }\n }\n\n const matchingModels = await idsCache.getSubjectModelIds([...targetSubjectIds]);\n return [...targetModelIds, ...matchingModels];\n}\n\nasync function collectFocusedItems(loadFocusedItems: () => AsyncIterableIterator<InstanceKey | GroupingHierarchyNode>) {\n const focusedItems: Array<InstanceKey | ElementsGroupInfo> = [];\n const groupingNodeInfos: Array<{\n parentKey: InstancesNodeKey;\n parentType: \"element\" | \"category\";\n groupingNode: ClassGroupingHierarchyNode;\n modelIds: Id64Array;\n }> = [];\n for await (const key of loadFocusedItems()) {\n if (\"id\" in key) {\n focusedItems.push(key);\n continue;\n }\n\n if (!HierarchyNodeKey.isClassGrouping(key.key)) {\n continue;\n }\n\n const groupingNode = key as ClassGroupingHierarchyNode;\n if (!groupingNode.nonGroupingAncestor || !HierarchyNodeKey.isInstances(groupingNode.nonGroupingAncestor.key)) {\n continue;\n }\n\n const parentKey = groupingNode.nonGroupingAncestor.key;\n const type = groupingNode.nonGroupingAncestor.extendedData?.isCategory ? \"category\" : \"element\";\n const modelIds = ((groupingNode.nonGroupingAncestor.extendedData?.modelIds as Id64String[][]) ?? []).flatMap((ids) => ids);\n groupingNodeInfos.push({ groupingNode, parentType: type, parentKey, modelIds });\n }\n focusedItems.push(\n ...groupingNodeInfos.map(({ parentKey, parentType, groupingNode, modelIds }) => ({\n parent:\n parentType === \"element\"\n ? { type: \"element\" as const, ids: parentKey.instanceKeys.map((key) => key.id) }\n : { type: \"category\" as const, ids: parentKey.instanceKeys.map((key) => key.id), modelIds },\n groupingNode,\n })),\n );\n return focusedItems;\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ModelsTreeIdsCache } from "./ModelsTreeIdsCache.js";
|
|
2
|
+
import type { IModelConnection } from "@itwin/core-frontend";
|
|
3
|
+
import type { ModelsTreeHierarchyConfiguration } from "../ModelsTreeDefinition.js";
|
|
4
|
+
/** @internal */
|
|
5
|
+
export declare function useIdsCache(imodel: IModelConnection, hierarchyConfig: ModelsTreeHierarchyConfiguration): {
|
|
6
|
+
getCache: () => ModelsTreeIdsCache;
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=UseIdsCache.d.ts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
6
|
+
import { createECSqlQueryExecutor } from "@itwin/presentation-core-interop";
|
|
7
|
+
import { useIModelChangeListener } from "../../common/internal/UseIModelChangeListener.js";
|
|
8
|
+
import { ModelsTreeIdsCache } from "./ModelsTreeIdsCache.js";
|
|
9
|
+
/** @internal */
|
|
10
|
+
export function useIdsCache(imodel, hierarchyConfig) {
|
|
11
|
+
const cacheRef = useRef(undefined);
|
|
12
|
+
const clearCacheRef = useRef(() => {
|
|
13
|
+
cacheRef.current?.[Symbol.dispose]?.();
|
|
14
|
+
cacheRef.current = undefined;
|
|
15
|
+
});
|
|
16
|
+
const createCacheGetterRef = useRef((currImodel, currHierarchyConfig) => {
|
|
17
|
+
return () => {
|
|
18
|
+
if (cacheRef.current === undefined) {
|
|
19
|
+
cacheRef.current = new ModelsTreeIdsCache(createECSqlQueryExecutor(currImodel), currHierarchyConfig);
|
|
20
|
+
}
|
|
21
|
+
return cacheRef.current;
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
const [getCache, setCacheGetter] = useState(() => createCacheGetterRef.current(imodel, hierarchyConfig));
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
// clear cache in case it was created before `useEffect` was run first time
|
|
27
|
+
clearCacheRef.current();
|
|
28
|
+
// make sure all cache users rerender
|
|
29
|
+
setCacheGetter(() => createCacheGetterRef.current(imodel, hierarchyConfig));
|
|
30
|
+
return () => {
|
|
31
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
32
|
+
clearCacheRef.current();
|
|
33
|
+
};
|
|
34
|
+
}, [imodel, hierarchyConfig]);
|
|
35
|
+
useIModelChangeListener({
|
|
36
|
+
imodel,
|
|
37
|
+
action: useCallback(() => {
|
|
38
|
+
clearCacheRef.current();
|
|
39
|
+
// make sure all cache users rerender
|
|
40
|
+
setCacheGetter(() => createCacheGetterRef.current(imodel, hierarchyConfig));
|
|
41
|
+
}, [imodel, hierarchyConfig]),
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
getCache,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=UseIdsCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UseIdsCache.js","sourceRoot":"","sources":["../../../../../../../src/tree-widget-react/components/trees/models-tree/internal/UseIdsCache.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,uBAAuB,EAAE,MAAM,kDAAkD,CAAC;AAC3F,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAK7D,gBAAgB;AAChB,MAAM,UAAU,WAAW,CAAC,MAAwB,EAAE,eAAiD;IACrG,MAAM,QAAQ,GAAG,MAAM,CAAiC,SAAS,CAAC,CAAC;IACnE,MAAM,aAAa,GAAG,MAAM,CAAC,GAAG,EAAE;QAChC,QAAQ,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC;QACvC,QAAQ,CAAC,OAAO,GAAG,SAAS,CAAC;IAC/B,CAAC,CAAC,CAAC;IACH,MAAM,oBAAoB,GAAG,MAAM,CAAC,CAAC,UAA4B,EAAE,mBAAqD,EAAE,EAAE;QAC1H,OAAO,GAAG,EAAE;YACV,IAAI,QAAQ,CAAC,OAAO,KAAK,SAAS,EAAE;gBAClC,QAAQ,CAAC,OAAO,GAAG,IAAI,kBAAkB,CAAC,wBAAwB,CAAC,UAAU,CAAC,EAAE,mBAAmB,CAAC,CAAC;aACtG;YACD,OAAO,QAAQ,CAAC,OAAO,CAAC;QAC1B,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,QAAQ,EAAE,cAAc,CAAC,GAAG,QAAQ,CAA2B,GAAG,EAAE,CAAC,oBAAoB,CAAC,OAAO,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;IAEnI,SAAS,CAAC,GAAG,EAAE;QACb,2EAA2E;QAC3E,aAAa,CAAC,OAAO,EAAE,CAAC;QAExB,qCAAqC;QACrC,cAAc,CAAC,GAAG,EAAE,CAAC,oBAAoB,CAAC,OAAO,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;QAC5E,OAAO,GAAG,EAAE;YACV,uDAAuD;YACvD,aAAa,CAAC,OAAO,EAAE,CAAC;QAC1B,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;IAE9B,uBAAuB,CAAC;QACtB,MAAM;QACN,MAAM,EAAE,WAAW,CAAC,GAAG,EAAE;YACvB,aAAa,CAAC,OAAO,EAAE,CAAC;YACxB,qCAAqC;YACrC,cAAc,CAAC,GAAG,EAAE,CAAC,oBAAoB,CAAC,OAAO,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;QAC9E,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;KAC9B,CAAC,CAAC;IAEH,OAAO;QACL,QAAQ;KACT,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport { createECSqlQueryExecutor } from \"@itwin/presentation-core-interop\";\nimport { useIModelChangeListener } from \"../../common/internal/UseIModelChangeListener.js\";\nimport { ModelsTreeIdsCache } from \"./ModelsTreeIdsCache.js\";\n\nimport type { IModelConnection } from \"@itwin/core-frontend\";\nimport type { ModelsTreeHierarchyConfiguration } from \"../ModelsTreeDefinition.js\";\n\n/** @internal */\nexport function useIdsCache(imodel: IModelConnection, hierarchyConfig: ModelsTreeHierarchyConfiguration) {\n const cacheRef = useRef<ModelsTreeIdsCache | undefined>(undefined);\n const clearCacheRef = useRef(() => {\n cacheRef.current?.[Symbol.dispose]?.();\n cacheRef.current = undefined;\n });\n const createCacheGetterRef = useRef((currImodel: IModelConnection, currHierarchyConfig: ModelsTreeHierarchyConfiguration) => {\n return () => {\n if (cacheRef.current === undefined) {\n cacheRef.current = new ModelsTreeIdsCache(createECSqlQueryExecutor(currImodel), currHierarchyConfig);\n }\n return cacheRef.current;\n };\n });\n const [getCache, setCacheGetter] = useState<() => ModelsTreeIdsCache>(() => createCacheGetterRef.current(imodel, hierarchyConfig));\n\n useEffect(() => {\n // clear cache in case it was created before `useEffect` was run first time\n clearCacheRef.current();\n\n // make sure all cache users rerender\n setCacheGetter(() => createCacheGetterRef.current(imodel, hierarchyConfig));\n return () => {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n clearCacheRef.current();\n };\n }, [imodel, hierarchyConfig]);\n\n useIModelChangeListener({\n imodel,\n action: useCallback(() => {\n clearCacheRef.current();\n // make sure all cache users rerender\n setCacheGetter(() => createCacheGetterRef.current(imodel, hierarchyConfig));\n }, [imodel, hierarchyConfig]),\n });\n\n return {\n getCache,\n };\n}\n"]}
|
|
@@ -27,102 +27,11 @@
|
|
|
27
27
|
},
|
|
28
28
|
"visibilityTooltips": {
|
|
29
29
|
"status": {
|
|
30
|
-
"visible": "
|
|
31
|
-
"hidden": "
|
|
30
|
+
"visible": "Hide",
|
|
31
|
+
"hidden": "Show",
|
|
32
32
|
"disabled": "Disabled",
|
|
33
|
-
"partial": "
|
|
34
|
-
|
|
35
|
-
"modelsTree": {
|
|
36
|
-
"subject": {
|
|
37
|
-
"nonSpatialView": "Active view is not spatial",
|
|
38
|
-
"allModelsHidden": "All models are hidden",
|
|
39
|
-
"someModelsHidden": "Some models are hidden",
|
|
40
|
-
"allModelsVisible": "All models are visible"
|
|
41
|
-
},
|
|
42
|
-
"model": {
|
|
43
|
-
"nonSpatialView": "Active view is not spatial",
|
|
44
|
-
"hiddenThroughModelSelector": "Model display is hidden through model selector",
|
|
45
|
-
"someCategoriesHidden": "Some categories are visible and some are hidden",
|
|
46
|
-
"allCategoriesVisible": "All categories visible",
|
|
47
|
-
"allCategoriesHidden": "All categories hidden",
|
|
48
|
-
"someSubModelsVisible": "Some sub-models are visible"
|
|
49
|
-
},
|
|
50
|
-
"category": {
|
|
51
|
-
"displayedThroughPerModelOverride": "Per-model category override set to 'Show'",
|
|
52
|
-
"hiddenThroughPerModelOverride": "Per-model category override set to 'Hide'",
|
|
53
|
-
"displayedThroughCategorySelector": "Category display enabled through category selector",
|
|
54
|
-
"hiddenThroughCategorySelector": "Category display disabled through category selector",
|
|
55
|
-
"allElementsHidden": "All category elements are in the never drawn list or none of the category elements are in the exclusive always drawn list",
|
|
56
|
-
"someElementsAreHidden": "There are both visible and hidden elements in this category",
|
|
57
|
-
"allElementsVisible": "All category elements are in the always drawn list",
|
|
58
|
-
"allElementsAndSubModelsHidden": "All elements are hidden",
|
|
59
|
-
"someElementsOrSubModelsHidden": "Some elements are hidden and some are visible",
|
|
60
|
-
"hiddenThroughModel": "Model is hidden",
|
|
61
|
-
"allModeledElementsHidden": "All elements in the category are hidden",
|
|
62
|
-
"someModeledElementsHidden": "There are both visible and hidden elements in this category"
|
|
63
|
-
},
|
|
64
|
-
"element": {
|
|
65
|
-
"hiddenThroughNeverDrawnList": "Element(s) in \"never drawn\" list",
|
|
66
|
-
"displayedThroughAlwaysDrawnList": "Element(s) in \"always drawn\" list",
|
|
67
|
-
"hiddenDueToOtherElementsExclusivelyAlwaysDrawn": "Other elements in \"exclusively always drawn\" list",
|
|
68
|
-
"hiddenThroughModel": "Model is not displayed",
|
|
69
|
-
"hiddenThroughCategory": "Category is not displayed",
|
|
70
|
-
"someElementsAreHidden": "Modeled elements subModel has partial state",
|
|
71
|
-
"partialThroughSubModel": "Modeled element is hidden, but its subModel is visible",
|
|
72
|
-
"partialThroughElement": "Modeled element is visible due to override, but its subModel is hidden",
|
|
73
|
-
"partialThroughCategory": "Modeled element is visible due to category visibility, but its subModel is hidden"
|
|
74
|
-
},
|
|
75
|
-
"groupingNode": {
|
|
76
|
-
"allElementsHidden": "All elements are in the never drawn list or none of the elements are in the exclusive always drawn list",
|
|
77
|
-
"someElementsAreHidden": "There are both visible and hidden elements",
|
|
78
|
-
"allElementsVisible": "All elements are in the always drawn list",
|
|
79
|
-
"visibleThroughCategory": "All elements are visible through category",
|
|
80
|
-
"hiddenThroughCategory": "All elements are hidden through category",
|
|
81
|
-
"allElementsAndSubModelsHidden": "All elements are hidden",
|
|
82
|
-
"someElementsOrSubModelsHidden": "There are both visible and hidden elements"
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
"categoriesTree": {
|
|
86
|
-
"definitionContainer": {
|
|
87
|
-
"partialThroughCategories": "Not all categories are visible",
|
|
88
|
-
"hiddenThroughCategories": "All categories are hidden",
|
|
89
|
-
"visibleThroughCategories": "All categories are visible"
|
|
90
|
-
},
|
|
91
|
-
"subCategory": {
|
|
92
|
-
"hiddenThroughCategory": "SubCategory display disabled through category selector",
|
|
93
|
-
"hiddenThroughCategoryOverride": "SubCategory display disabled through per-model category override",
|
|
94
|
-
"visibleThroughCategoryOverride": "SubCategory display enabled through per-model category override",
|
|
95
|
-
"partialThroughSubCategory": "Some subCategories are visbile and some are hidden"
|
|
96
|
-
},
|
|
97
|
-
"category": {
|
|
98
|
-
"hiddenThroughModel": "Model is hidden",
|
|
99
|
-
"partialThroughSubCategories": "Some subCategories are visible",
|
|
100
|
-
"hiddenThroughSubCategories": "All subCategories are hidden",
|
|
101
|
-
"visibleThroughSubCategories": "All subCategories are visible",
|
|
102
|
-
"allChildrenHidden": "All subCategories and child elements are hidden",
|
|
103
|
-
"someChildrenVisible": "Some subCategories or child elements are visible and some are hidden",
|
|
104
|
-
"allChildrenVisible": "All subCategories and child elements are visible",
|
|
105
|
-
"partialThroughOverrides": "Per-model category override set to 'Show' and 'Hide'",
|
|
106
|
-
"visibleThroughOverrides": "Per-model category override set to 'Show'",
|
|
107
|
-
"hiddenThroughOverrides": "Per-model category override set to 'Hide'",
|
|
108
|
-
"visibleThroughCategorySelector": "Category display enabled through category selector",
|
|
109
|
-
"hiddenThroughCategorySelector": "Category display disabled through category selector",
|
|
110
|
-
"allElementsHidden": "All category elements are in the never drawn list or none of the category elements are in the exclusive always drawn list",
|
|
111
|
-
"someElementsHidden": "There are both visible and hidden elements in this category",
|
|
112
|
-
"allElementsVisible": "All category elements are in the always drawn list",
|
|
113
|
-
"someElementsAreHidden": "There are both visible and hidden elements in this category"
|
|
114
|
-
},
|
|
115
|
-
"element": {
|
|
116
|
-
"hiddenThroughNeverDrawnList": "Element(s) in \"never drawn\" list",
|
|
117
|
-
"displayedThroughAlwaysDrawnList": "Element(s) in \"always drawn\" list",
|
|
118
|
-
"hiddenDueToOtherElementsExclusivelyAlwaysDrawn": "Other elements in \"exclusively always drawn\" list",
|
|
119
|
-
"hiddenThroughModel": "Model is not displayed",
|
|
120
|
-
"hiddenThroughCategory": "Category is not displayed",
|
|
121
|
-
"someElementsAreHidden": "Modeled elements subModel has partial state",
|
|
122
|
-
"partialThroughSubModel": "Modeled element is hidden, but its subModel is visible",
|
|
123
|
-
"partialThroughElement": "Modeled element is visible due to override, but its subModel is hidden",
|
|
124
|
-
"partialThroughCategory": "Modeled element is visible due to category visibility, but its subModel is hidden"
|
|
125
|
-
}
|
|
33
|
+
"partial": "Show",
|
|
34
|
+
"determining": "Determining visibility..."
|
|
126
35
|
}
|
|
127
36
|
},
|
|
128
37
|
"categoriesTree": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/tree-widget-react",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.9",
|
|
4
4
|
"description": "Tree Widget React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Bentley",
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"@itwin/components-react": "^4.10.0 || ^5.0.0",
|
|
56
56
|
"@itwin/core-frontend": "^4.0.0",
|
|
57
57
|
"@itwin/ecschema-metadata": "^4.0.0",
|
|
58
|
-
"@itwin/itwinui-react": "5.0.0-alpha.
|
|
59
|
-
"@itwin/itwinui-icons": "5.0.0-alpha.
|
|
58
|
+
"@itwin/itwinui-react": "5.0.0-alpha.14",
|
|
59
|
+
"@itwin/itwinui-icons": "5.0.0-alpha.7",
|
|
60
60
|
"@itwin/presentation-components": "^5.0.0",
|
|
61
61
|
"react": "^17.0.0 || ^18.0.0",
|
|
62
62
|
"react-dom": "^17.0.0 || ^18.0.0"
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"@itwin/presentation-core-interop": "^1.3.0",
|
|
66
66
|
"@itwin/presentation-hierarchies": "^1.4.1",
|
|
67
|
-
"@itwin/presentation-hierarchies-react": "2.0.0-alpha.
|
|
67
|
+
"@itwin/presentation-hierarchies-react": "2.0.0-alpha.17",
|
|
68
68
|
"@itwin/presentation-shared": "^1.2.0",
|
|
69
69
|
"@itwin/unified-selection": "^1.3.0",
|
|
70
70
|
"classnames": "^2.5.1",
|
|
@@ -92,8 +92,8 @@
|
|
|
92
92
|
"@itwin/ecschema-rpcinterface-impl": "^4.10.2",
|
|
93
93
|
"@itwin/eslint-plugin": "^4.1.1",
|
|
94
94
|
"@itwin/imodel-components-react": "^5.0.5",
|
|
95
|
-
"@itwin/itwinui-react": "5.0.0-alpha.
|
|
96
|
-
"@itwin/itwinui-icons": "5.0.0-alpha.
|
|
95
|
+
"@itwin/itwinui-react": "5.0.0-alpha.14",
|
|
96
|
+
"@itwin/itwinui-icons": "5.0.0-alpha.7",
|
|
97
97
|
"@itwin/oidc-signin-tool": "^4.4.0",
|
|
98
98
|
"@itwin/presentation-backend": "^4.10.2",
|
|
99
99
|
"@itwin/presentation-common": "^4.10.2",
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/*---------------------------------------------------------------------------------------------
|
|
2
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
-
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
|
|
6
|
-
.tw-search-box-button {
|
|
7
|
-
margin-left: var(--iui-size-xs);
|
|
8
|
-
}
|