@itwin/tree-widget-react 3.0.0-dev.3 → 3.0.0-dev.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/README.md +95 -6
  2. package/lib/cjs/components/tree-header/TreeHeader.d.ts +10 -8
  3. package/lib/cjs/components/tree-header/TreeHeader.js +4 -6
  4. package/lib/cjs/components/tree-header/TreeHeader.js.map +1 -1
  5. package/lib/cjs/components/tree-header/TreeWithHeader.d.ts +13 -0
  6. package/lib/cjs/components/tree-header/TreeWithHeader.js +20 -0
  7. package/lib/cjs/components/tree-header/TreeWithHeader.js.map +1 -0
  8. package/lib/cjs/components/trees/categories-tree/CategoriesTree.d.ts +3 -7
  9. package/lib/cjs/components/trees/categories-tree/CategoriesTree.js +7 -63
  10. package/lib/cjs/components/trees/categories-tree/CategoriesTree.js.map +1 -1
  11. package/lib/cjs/components/trees/categories-tree/CategoriesTreeButtons.d.ts +9 -2
  12. package/lib/cjs/components/trees/categories-tree/CategoriesTreeButtons.js +24 -4
  13. package/lib/cjs/components/trees/categories-tree/CategoriesTreeButtons.js.map +1 -1
  14. package/lib/cjs/components/trees/categories-tree/CategoriesTreeComponent.d.ts +0 -1
  15. package/lib/cjs/components/trees/categories-tree/CategoriesTreeComponent.js +15 -18
  16. package/lib/cjs/components/trees/categories-tree/CategoriesTreeComponent.js.map +1 -1
  17. package/lib/cjs/components/trees/categories-tree/CategoriesVisibilityHandler.d.ts +1 -9
  18. package/lib/cjs/components/trees/categories-tree/CategoriesVisibilityHandler.js +2 -6
  19. package/lib/cjs/components/trees/categories-tree/CategoriesVisibilityHandler.js.map +1 -1
  20. package/lib/cjs/components/trees/categories-tree/UseCategoriesTree.d.ts +25 -0
  21. package/lib/cjs/components/trees/categories-tree/UseCategoriesTree.js +89 -0
  22. package/lib/cjs/components/trees/categories-tree/UseCategoriesTree.js.map +1 -0
  23. package/lib/cjs/components/trees/common/CategoriesVisibilityUtils.d.ts +6 -6
  24. package/lib/cjs/components/trees/common/CategoriesVisibilityUtils.js +32 -78
  25. package/lib/cjs/components/trees/common/CategoriesVisibilityUtils.js.map +1 -1
  26. package/lib/cjs/components/trees/common/UseTelemetryContext.d.ts +1 -1
  27. package/lib/cjs/components/trees/common/UseTelemetryContext.js.map +1 -1
  28. package/lib/cjs/components/trees/common/components/Tree.d.ts +0 -2
  29. package/lib/cjs/components/trees/common/components/Tree.js +5 -4
  30. package/lib/cjs/components/trees/common/components/Tree.js.map +1 -1
  31. package/lib/cjs/components/trees/common/components/VisibilityTree.d.ts +2 -3
  32. package/lib/cjs/components/trees/common/components/VisibilityTree.js.map +1 -1
  33. package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTree.d.ts +1 -1
  34. package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTree.js.map +1 -1
  35. package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js +1 -2
  36. package/lib/cjs/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js.map +1 -1
  37. package/lib/cjs/components/trees/imodel-content-tree/IModelContentTree.d.ts +1 -1
  38. package/lib/cjs/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -1
  39. package/lib/cjs/components/trees/imodel-content-tree/IModelContentTreeComponent.js +1 -2
  40. package/lib/cjs/components/trees/imodel-content-tree/IModelContentTreeComponent.js.map +1 -1
  41. package/lib/cjs/components/trees/index.d.ts +4 -0
  42. package/lib/cjs/components/trees/index.js +9 -1
  43. package/lib/cjs/components/trees/index.js.map +1 -1
  44. package/lib/cjs/components/trees/models-tree/ModelsTree.d.ts +4 -4
  45. package/lib/cjs/components/trees/models-tree/ModelsTree.js +4 -203
  46. package/lib/cjs/components/trees/models-tree/ModelsTree.js.map +1 -1
  47. package/lib/cjs/components/trees/models-tree/ModelsTreeButtons.d.ts +9 -3
  48. package/lib/cjs/components/trees/models-tree/ModelsTreeButtons.js +13 -3
  49. package/lib/cjs/components/trees/models-tree/ModelsTreeButtons.js.map +1 -1
  50. package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.d.ts +0 -1
  51. package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.js +27 -20
  52. package/lib/cjs/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
  53. package/lib/cjs/components/trees/models-tree/UseModelsTree.d.ts +29 -0
  54. package/lib/cjs/components/trees/models-tree/UseModelsTree.js +233 -0
  55. package/lib/cjs/components/trees/models-tree/UseModelsTree.js.map +1 -0
  56. package/lib/cjs/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js +1 -1
  57. package/lib/cjs/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
  58. package/lib/cjs/tree-widget-react.d.ts +1 -0
  59. package/lib/cjs/tree-widget-react.js +3 -1
  60. package/lib/cjs/tree-widget-react.js.map +1 -1
  61. package/lib/esm/components/tree-header/TreeHeader.d.ts +10 -8
  62. package/lib/esm/components/tree-header/TreeHeader.js +4 -6
  63. package/lib/esm/components/tree-header/TreeHeader.js.map +1 -1
  64. package/lib/esm/components/tree-header/TreeWithHeader.d.ts +13 -0
  65. package/lib/esm/components/tree-header/TreeWithHeader.js +13 -0
  66. package/lib/esm/components/tree-header/TreeWithHeader.js.map +1 -0
  67. package/lib/esm/components/trees/categories-tree/CategoriesTree.d.ts +3 -7
  68. package/lib/esm/components/trees/categories-tree/CategoriesTree.js +7 -63
  69. package/lib/esm/components/trees/categories-tree/CategoriesTree.js.map +1 -1
  70. package/lib/esm/components/trees/categories-tree/CategoriesTreeButtons.d.ts +9 -2
  71. package/lib/esm/components/trees/categories-tree/CategoriesTreeButtons.js +22 -4
  72. package/lib/esm/components/trees/categories-tree/CategoriesTreeButtons.js.map +1 -1
  73. package/lib/esm/components/trees/categories-tree/CategoriesTreeComponent.d.ts +0 -1
  74. package/lib/esm/components/trees/categories-tree/CategoriesTreeComponent.js +16 -16
  75. package/lib/esm/components/trees/categories-tree/CategoriesTreeComponent.js.map +1 -1
  76. package/lib/esm/components/trees/categories-tree/CategoriesVisibilityHandler.d.ts +1 -9
  77. package/lib/esm/components/trees/categories-tree/CategoriesVisibilityHandler.js +2 -6
  78. package/lib/esm/components/trees/categories-tree/CategoriesVisibilityHandler.js.map +1 -1
  79. package/lib/esm/components/trees/categories-tree/UseCategoriesTree.d.ts +25 -0
  80. package/lib/esm/components/trees/categories-tree/UseCategoriesTree.js +85 -0
  81. package/lib/esm/components/trees/categories-tree/UseCategoriesTree.js.map +1 -0
  82. package/lib/esm/components/trees/common/CategoriesVisibilityUtils.d.ts +6 -6
  83. package/lib/esm/components/trees/common/CategoriesVisibilityUtils.js +33 -79
  84. package/lib/esm/components/trees/common/CategoriesVisibilityUtils.js.map +1 -1
  85. package/lib/esm/components/trees/common/UseTelemetryContext.d.ts +1 -1
  86. package/lib/esm/components/trees/common/UseTelemetryContext.js.map +1 -1
  87. package/lib/esm/components/trees/common/components/Tree.d.ts +0 -2
  88. package/lib/esm/components/trees/common/components/Tree.js +5 -4
  89. package/lib/esm/components/trees/common/components/Tree.js.map +1 -1
  90. package/lib/esm/components/trees/common/components/VisibilityTree.d.ts +2 -3
  91. package/lib/esm/components/trees/common/components/VisibilityTree.js.map +1 -1
  92. package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTree.d.ts +1 -1
  93. package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTree.js.map +1 -1
  94. package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js +1 -2
  95. package/lib/esm/components/trees/external-sources-tree/ExternalSourcesTreeComponent.js.map +1 -1
  96. package/lib/esm/components/trees/imodel-content-tree/IModelContentTree.d.ts +1 -1
  97. package/lib/esm/components/trees/imodel-content-tree/IModelContentTree.js.map +1 -1
  98. package/lib/esm/components/trees/imodel-content-tree/IModelContentTreeComponent.js +1 -2
  99. package/lib/esm/components/trees/imodel-content-tree/IModelContentTreeComponent.js.map +1 -1
  100. package/lib/esm/components/trees/index.d.ts +4 -0
  101. package/lib/esm/components/trees/index.js +4 -0
  102. package/lib/esm/components/trees/index.js.map +1 -1
  103. package/lib/esm/components/trees/models-tree/ModelsTree.d.ts +4 -4
  104. package/lib/esm/components/trees/models-tree/ModelsTree.js +5 -204
  105. package/lib/esm/components/trees/models-tree/ModelsTree.js.map +1 -1
  106. package/lib/esm/components/trees/models-tree/ModelsTreeButtons.d.ts +9 -3
  107. package/lib/esm/components/trees/models-tree/ModelsTreeButtons.js +12 -2
  108. package/lib/esm/components/trees/models-tree/ModelsTreeButtons.js.map +1 -1
  109. package/lib/esm/components/trees/models-tree/ModelsTreeComponent.d.ts +0 -1
  110. package/lib/esm/components/trees/models-tree/ModelsTreeComponent.js +29 -19
  111. package/lib/esm/components/trees/models-tree/ModelsTreeComponent.js.map +1 -1
  112. package/lib/esm/components/trees/models-tree/UseModelsTree.d.ts +29 -0
  113. package/lib/esm/components/trees/models-tree/UseModelsTree.js +229 -0
  114. package/lib/esm/components/trees/models-tree/UseModelsTree.js.map +1 -0
  115. package/lib/esm/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js +2 -2
  116. package/lib/esm/components/trees/models-tree/internal/ModelsTreeVisibilityHandler.js.map +1 -1
  117. package/lib/esm/tree-widget-react.d.ts +1 -0
  118. package/lib/esm/tree-widget-react.js +1 -0
  119. package/lib/esm/tree-widget-react.js.map +1 -1
  120. package/package.json +11 -15
  121. package/lib/cjs/components/trees/categories-tree/UseCategories.d.ts +0 -8
  122. package/lib/cjs/components/trees/categories-tree/UseCategories.js +0 -22
  123. package/lib/cjs/components/trees/categories-tree/UseCategories.js.map +0 -1
  124. package/lib/cjs/components/utils/AutoSizer.d.ts +0 -13
  125. package/lib/cjs/components/utils/AutoSizer.js +0 -21
  126. package/lib/cjs/components/utils/AutoSizer.js.map +0 -1
  127. package/lib/esm/components/trees/categories-tree/UseCategories.d.ts +0 -8
  128. package/lib/esm/components/trees/categories-tree/UseCategories.js +0 -18
  129. package/lib/esm/components/trees/categories-tree/UseCategories.js.map +0 -1
  130. package/lib/esm/components/utils/AutoSizer.d.ts +0 -13
  131. package/lib/esm/components/utils/AutoSizer.js +0 -17
  132. package/lib/esm/components/utils/AutoSizer.js.map +0 -1
  133. /package/lib/cjs/components/{trees/Tree.scss → tree-header/TreeWithHeader.scss} +0 -0
  134. /package/lib/esm/components/{trees/Tree.scss → tree-header/TreeWithHeader.scss} +0 -0
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useModelsTree = 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 core_frontend_1 = require("@itwin/core-frontend");
11
+ const itwinui_icons_react_1 = require("@itwin/itwinui-icons-react");
12
+ const itwinui_react_1 = require("@itwin/itwinui-react");
13
+ const presentation_core_interop_1 = require("@itwin/presentation-core-interop");
14
+ const presentation_hierarchies_1 = require("@itwin/presentation-hierarchies");
15
+ const TreeWidget_1 = require("../../../TreeWidget");
16
+ const FocusedInstancesContext_1 = require("../common/FocusedInstancesContext");
17
+ const UseIModelChangeListener_1 = require("../common/UseIModelChangeListener");
18
+ const UseTelemetryContext_1 = require("../common/UseTelemetryContext");
19
+ const ModelsTreeIdsCache_1 = require("./internal/ModelsTreeIdsCache");
20
+ const ModelsTreeVisibilityHandler_1 = require("./internal/ModelsTreeVisibilityHandler");
21
+ const ModelsTreeDefinition_1 = require("./ModelsTreeDefinition");
22
+ /**
23
+ * Custom hook to create and manage state for the models tree.
24
+ * @beta
25
+ */
26
+ function useModelsTree({ activeView, filter, hierarchyConfig, visibilityHandlerOverrides }) {
27
+ const [filteringError, setFilteringError] = (0, react_1.useState)(undefined);
28
+ const hierarchyConfiguration = (0, react_1.useMemo)(() => ({
29
+ ...ModelsTreeDefinition_1.defaultHierarchyConfiguration,
30
+ ...hierarchyConfig,
31
+ }),
32
+ // eslint-disable-next-line react-hooks/exhaustive-deps
33
+ Object.values(hierarchyConfig ?? {}));
34
+ const { onFeatureUsed } = (0, UseTelemetryContext_1.useTelemetryContext)();
35
+ const { getModelsTreeIdsCache, visibilityHandlerFactory } = useCachedVisibility(activeView, hierarchyConfiguration, visibilityHandlerOverrides);
36
+ const { loadInstanceKeys: loadFocusedInstancesKeys } = (0, FocusedInstancesContext_1.useFocusedInstancesContext)();
37
+ const getHierarchyDefinition = (0, react_1.useCallback)(({ imodelAccess }) => new ModelsTreeDefinition_1.ModelsTreeDefinition({ imodelAccess, idsCache: getModelsTreeIdsCache(), hierarchyConfig: hierarchyConfiguration }), [getModelsTreeIdsCache, hierarchyConfiguration]);
38
+ const onNodeDoubleClick = (0, react_1.useCallback)(async ({ nodeData, extendedData }) => {
39
+ if (!presentation_hierarchies_1.HierarchyNode.isInstancesNode(nodeData) || (extendedData && (extendedData.isSubject || extendedData.isModel || extendedData.isCategory))) {
40
+ return;
41
+ }
42
+ const instanceIds = nodeData.key.instanceKeys.map((instanceKey) => instanceKey.id);
43
+ await core_frontend_1.IModelApp.viewManager.selectedView?.zoomToElements(instanceIds);
44
+ onFeatureUsed({ featureId: "zoom-to-node", reportInteraction: false });
45
+ }, [onFeatureUsed]);
46
+ const getFilteredPaths = (0, react_1.useMemo)(() => {
47
+ setFilteringError(undefined);
48
+ if (loadFocusedInstancesKeys) {
49
+ return async ({ imodelAccess }) => {
50
+ try {
51
+ const targetKeys = await collectTargetKeys(loadFocusedInstancesKeys);
52
+ return await ModelsTreeDefinition_1.ModelsTreeDefinition.createInstanceKeyPaths({
53
+ imodelAccess,
54
+ idsCache: getModelsTreeIdsCache(),
55
+ keys: targetKeys,
56
+ hierarchyConfig: hierarchyConfiguration,
57
+ });
58
+ }
59
+ catch (e) {
60
+ const newError = e instanceof Error && e.message.match(/Filter matches more than \d+ items/) ? "tooManyInstancesFocused" : "unknownInstanceFocusError";
61
+ if (newError !== "tooManyInstancesFocused") {
62
+ const feature = e instanceof Error && e.message.includes("query too long to execute or server is too busy") ? "error-timeout" : "error-unknown";
63
+ onFeatureUsed({ featureId: feature, reportInteraction: false });
64
+ }
65
+ setFilteringError(newError);
66
+ return [];
67
+ }
68
+ };
69
+ }
70
+ if (filter) {
71
+ return async ({ imodelAccess }) => {
72
+ onFeatureUsed({ featureId: "filtering", reportInteraction: true });
73
+ try {
74
+ return await ModelsTreeDefinition_1.ModelsTreeDefinition.createInstanceKeyPaths({
75
+ imodelAccess,
76
+ label: filter,
77
+ idsCache: getModelsTreeIdsCache(),
78
+ hierarchyConfig: hierarchyConfiguration,
79
+ });
80
+ }
81
+ catch (e) {
82
+ const newError = e instanceof Error && e.message.match(/Filter matches more than \d+ items/) ? "tooManyFilterMatches" : "unknownFilterError";
83
+ if (newError !== "tooManyFilterMatches") {
84
+ const feature = e instanceof Error && e.message.includes("query too long to execute or server is too busy") ? "error-timeout" : "error-unknown";
85
+ onFeatureUsed({ featureId: feature, reportInteraction: false });
86
+ }
87
+ setFilteringError(newError);
88
+ return [];
89
+ }
90
+ };
91
+ }
92
+ return undefined;
93
+ }, [filter, loadFocusedInstancesKeys, getModelsTreeIdsCache, onFeatureUsed, hierarchyConfiguration]);
94
+ return {
95
+ modelsTreeProps: {
96
+ treeName: "models-tree-v2",
97
+ visibilityHandlerFactory,
98
+ getHierarchyDefinition,
99
+ getFilteredPaths,
100
+ noDataMessage: getNoDataMessage(filter, filteringError),
101
+ highlight: filter ? { text: filter } : undefined,
102
+ },
103
+ rendererProps: {
104
+ onNodeDoubleClick,
105
+ getIcon,
106
+ },
107
+ };
108
+ }
109
+ exports.useModelsTree = useModelsTree;
110
+ function getNoDataMessage(filter, error) {
111
+ if (isInstanceFocusError(error)) {
112
+ return (0, jsx_runtime_1.jsx)(InstanceFocusError, { error: error });
113
+ }
114
+ if (isFilterError(error)) {
115
+ return (0, jsx_runtime_1.jsx)(itwinui_react_1.Text, { children: TreeWidget_1.TreeWidget.translate(`modelsTree.filtering.${error}`) });
116
+ }
117
+ if (filter) {
118
+ return (0, jsx_runtime_1.jsx)(itwinui_react_1.Text, { children: TreeWidget_1.TreeWidget.translate("modelsTree.filtering.noMatches", { filter }) });
119
+ }
120
+ return undefined;
121
+ }
122
+ function isFilterError(error) {
123
+ return error === "tooManyFilterMatches" || error === "unknownFilterError";
124
+ }
125
+ function isInstanceFocusError(error) {
126
+ return error === "tooManyInstancesFocused" || error === "unknownInstanceFocusError";
127
+ }
128
+ function InstanceFocusError({ error }) {
129
+ const { toggle } = (0, FocusedInstancesContext_1.useFocusedInstancesContext)();
130
+ const localizedMessage = createLocalizedMessage(TreeWidget_1.TreeWidget.translate(`modelsTree.filtering.${error}`), () => toggle());
131
+ return (0, jsx_runtime_1.jsx)(itwinui_react_1.Text, { children: localizedMessage });
132
+ }
133
+ function getIcon(node) {
134
+ if (node.extendedData?.imageId === undefined) {
135
+ return undefined;
136
+ }
137
+ switch (node.extendedData.imageId) {
138
+ case "icon-layers":
139
+ return (0, jsx_runtime_1.jsx)(itwinui_icons_react_1.SvgLayers, {});
140
+ case "icon-item":
141
+ return (0, jsx_runtime_1.jsx)(itwinui_icons_react_1.SvgItem, {});
142
+ case "icon-ec-class":
143
+ return (0, jsx_runtime_1.jsx)(SvgClassGrouping, {});
144
+ case "icon-imodel-hollow-2":
145
+ return (0, jsx_runtime_1.jsx)(itwinui_icons_react_1.SvgImodelHollow, {});
146
+ case "icon-folder":
147
+ return (0, jsx_runtime_1.jsx)(itwinui_icons_react_1.SvgFolder, {});
148
+ case "icon-model":
149
+ return (0, jsx_runtime_1.jsx)(itwinui_icons_react_1.SvgModel, {});
150
+ }
151
+ return undefined;
152
+ }
153
+ function createVisibilityHandlerFactory(activeView, idsCacheGetter, overrides) {
154
+ return ({ imodelAccess }) => (0, ModelsTreeVisibilityHandler_1.createModelsTreeVisibilityHandler)({ viewport: activeView, idsCache: idsCacheGetter(), imodelAccess, overrides });
155
+ }
156
+ function useCachedVisibility(activeView, hierarchyConfig, overrides) {
157
+ const cacheRef = (0, react_1.useRef)();
158
+ const currentIModelRef = (0, react_1.useRef)(activeView.iModel);
159
+ const getModelsTreeIdsCache = (0, react_1.useCallback)(() => {
160
+ if (!cacheRef.current) {
161
+ cacheRef.current = new ModelsTreeIdsCache_1.ModelsTreeIdsCache((0, presentation_core_interop_1.createECSqlQueryExecutor)(currentIModelRef.current), hierarchyConfig);
162
+ }
163
+ return cacheRef.current;
164
+ }, [hierarchyConfig]);
165
+ const [visibilityHandlerFactory, setVisibilityHandlerFactory] = (0, react_1.useState)(() => createVisibilityHandlerFactory(activeView, getModelsTreeIdsCache, overrides));
166
+ (0, UseIModelChangeListener_1.useIModelChangeListener)({
167
+ imodel: activeView.iModel,
168
+ action: (0, react_1.useCallback)(() => {
169
+ cacheRef.current = undefined;
170
+ setVisibilityHandlerFactory(() => createVisibilityHandlerFactory(activeView, getModelsTreeIdsCache, overrides));
171
+ }, [activeView, getModelsTreeIdsCache, overrides]),
172
+ });
173
+ (0, react_1.useEffect)(() => {
174
+ currentIModelRef.current = activeView.iModel;
175
+ cacheRef.current = undefined;
176
+ setVisibilityHandlerFactory(() => createVisibilityHandlerFactory(activeView, getModelsTreeIdsCache, overrides));
177
+ }, [activeView, getModelsTreeIdsCache, overrides]);
178
+ return {
179
+ getModelsTreeIdsCache,
180
+ visibilityHandlerFactory,
181
+ };
182
+ }
183
+ function SvgClassGrouping() {
184
+ return ((0, jsx_runtime_1.jsx)(itwinui_react_1.Icon, { children: (0, jsx_runtime_1.jsx)("svg", { id: "Calque_1", "data-name": "Calque 1", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 16 16", children: (0, jsx_runtime_1.jsx)("path", { d: "M8.00933,0,0,3.97672V11.986L8.00933,16,16,11.93V3.97651ZM1.66173,11.27642c-.26155.03734-.59754-.26154-.76553-.69085-.168-.41066-.09334-.784.168-.82152.26154-.03734.59754.26154.76553.67219C1.99772,10.86577,1.92306,11.23909,1.66173,11.27642Zm0-3.32319c-.26155.03733-.59754-.28-.76553-.69086-.168-.42932-.09334-.80285.168-.84.26133-.03733.59754.28.76532.69086C1.99772,7.54236,1.92306,7.89723,1.66173,7.95323Zm4.31276,5.52621a.18186.18186,0,0,1-.16821-.01866L3.41657,12.15394a.94275.94275,0,0,1-.29887-.80285c.03754-.33621.22421-.52265.41108-.41066L5.9185,12.24727a.88656.88656,0,0,1,.28.80285A.5057.5057,0,0,1,5.97449,13.47944Zm0-3.37919a.18184.18184,0,0,1-.16821-.01867L3.41657,8.77475a.943.943,0,0,1-.29887-.80286c.03754-.3362.22421-.52286.41108-.42953L5.9185,8.86786a.83112.83112,0,0,1,.28.78419A.51684.51684,0,0,1,5.97449,10.10025Z" }) }) }));
185
+ }
186
+ async function collectTargetKeys(loadFocusedInstancesKeys) {
187
+ const targetKeys = [];
188
+ const groupingNodeInfos = [];
189
+ for await (const key of loadFocusedInstancesKeys()) {
190
+ if ("id" in key) {
191
+ targetKeys.push(key);
192
+ continue;
193
+ }
194
+ if (!presentation_hierarchies_1.HierarchyNodeKey.isClassGrouping(key.key)) {
195
+ targetKeys.push(...key.groupedInstanceKeys);
196
+ continue;
197
+ }
198
+ if (!key.nonGroupingAncestor || !presentation_hierarchies_1.HierarchyNodeKey.isInstances(key.nonGroupingAncestor.key)) {
199
+ continue;
200
+ }
201
+ const parentKey = key.nonGroupingAncestor.key;
202
+ const type = key.nonGroupingAncestor.extendedData?.isCategory ? "category" : "element";
203
+ const modelIds = (key.nonGroupingAncestor.extendedData?.modelIds ?? []).flatMap((ids) => ids);
204
+ const groupInfo = groupingNodeInfos.find((group) => presentation_hierarchies_1.HierarchyNodeKey.equals(group.parentKey, parentKey));
205
+ if (groupInfo) {
206
+ groupInfo.classes.push(key.key.className);
207
+ }
208
+ else {
209
+ groupingNodeInfos.push({ classes: [key.key.className], parentType: type, parentKey, modelIds });
210
+ }
211
+ }
212
+ targetKeys.push(...groupingNodeInfos.map(({ parentKey, parentType, classes, modelIds }) => ({
213
+ parent: parentType === "element"
214
+ ? { type: "element", ids: parentKey.instanceKeys.map((key) => key.id) }
215
+ : { type: "category", ids: parentKey.instanceKeys.map((key) => key.id), modelIds },
216
+ classes,
217
+ })));
218
+ return targetKeys;
219
+ }
220
+ function createLocalizedMessage(message, onClick) {
221
+ const exp = new RegExp("<link>(.*)</link>");
222
+ const match = message.match(exp);
223
+ if (!match) {
224
+ return message;
225
+ }
226
+ const [fullText, innerText] = match;
227
+ const [textBefore, textAfter] = message.split(fullText);
228
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [textBefore ? textBefore : null, (0, jsx_runtime_1.jsx)(itwinui_react_1.Anchor, { underline: true, onClick: (e) => {
229
+ e.stopPropagation();
230
+ onClick?.();
231
+ }, children: innerText }), textAfter ? textAfter : null] }));
232
+ }
233
+ //# sourceMappingURL=UseModelsTree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UseModelsTree.js","sourceRoot":"","sources":["../../../../../src/components/trees/models-tree/UseModelsTree.tsx"],"names":[],"mappings":";;;;AAAA;;;gGAGgG;AAEhG,iCAA0E;AAC1E,wDAAiD;AACjD,oEAAsG;AACtG,wDAA0D;AAC1D,gFAA4E;AAC5E,8EAAkF;AAClF,oDAAiD;AACjD,+EAA+E;AAC/E,+EAA4E;AAC5E,uEAAoE;AACpE,sEAAmE;AACnE,wFAA2F;AAC3F,iEAA6F;AAsC7F;;;GAGG;AACH,SAAgB,aAAa,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,eAAe,EAAE,0BAA0B,EAAsB;IACnH,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,IAAA,gBAAQ,EAAuC,SAAS,CAAC,CAAC;IACtG,MAAM,sBAAsB,GAAG,IAAA,eAAO,EACpC,GAAG,EAAE,CAAC,CAAC;QACL,GAAG,oDAA6B;QAChC,GAAG,eAAe;KACnB,CAAC;IACF,uDAAuD;IACvD,MAAM,CAAC,MAAM,CAAC,eAAe,IAAI,EAA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AC,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,OAAO;KACR,CAAC,CAAC,CACJ,CAAC;IACF,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,SAAS,sBAAsB,CAAC,OAAe,EAAE,OAAoB;IACnE,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,mBAAmB,CAAC,CAAC;IAC5C,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACjC,IAAI,CAAC,KAAK,EAAE;QACV,OAAO,OAAO,CAAC;KAChB;IAED,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC;IACpC,MAAM,CAAC,UAAU,EAAE,SAAS,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAExD,OAAO,CACL,6DACG,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,EAC/B,uBAAC,sBAAM,IACL,SAAS,QACT,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;oBACb,CAAC,CAAC,eAAe,EAAE,CAAC;oBACpB,OAAO,EAAE,EAAE,CAAC;gBACd,CAAC,YAEA,SAAS,GACH,EACR,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,IAC5B,CACJ,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { SvgFolder, SvgImodelHollow, SvgItem, SvgLayers, SvgModel } from \"@itwin/itwinui-icons-react\";\nimport { Anchor, Icon, Text } from \"@itwin/itwinui-react\";\nimport { createECSqlQueryExecutor } from \"@itwin/presentation-core-interop\";\nimport { HierarchyNode, HierarchyNodeKey } from \"@itwin/presentation-hierarchies\";\nimport { TreeWidget } from \"../../../TreeWidget\";\nimport { useFocusedInstancesContext } from \"../common/FocusedInstancesContext\";\nimport { useIModelChangeListener } from \"../common/UseIModelChangeListener\";\nimport { useTelemetryContext } from \"../common/UseTelemetryContext\";\nimport { ModelsTreeIdsCache } from \"./internal/ModelsTreeIdsCache\";\nimport { createModelsTreeVisibilityHandler } from \"./internal/ModelsTreeVisibilityHandler\";\nimport { defaultHierarchyConfiguration, ModelsTreeDefinition } from \"./ModelsTreeDefinition\";\n\nimport type { Id64String } from \"@itwin/core-bentley\";\nimport type { GroupingHierarchyNode, InstancesNodeKey } from \"@itwin/presentation-hierarchies\";\nimport type { InstanceKey } from \"@itwin/presentation-shared\";\nimport type { ComponentPropsWithoutRef, ReactElement } from \"react\";\nimport type { Viewport } from \"@itwin/core-frontend\";\nimport type { PresentationHierarchyNode } from \"@itwin/presentation-hierarchies-react\";\nimport type { ElementsGroupInfo, ModelsTreeHierarchyConfiguration } from \"./ModelsTreeDefinition\";\nimport type { ModelsTreeVisibilityHandlerOverrides } from \"./internal/ModelsTreeVisibilityHandler\";\nimport type { VisibilityTree } from \"../common/components/VisibilityTree\";\nimport type { VisibilityTreeRenderer } from \"../common/components/VisibilityTreeRenderer\";\n\ntype ModelsTreeFilteringError = \"tooManyFilterMatches\" | \"tooManyInstancesFocused\" | \"unknownFilterError\" | \"unknownInstanceFocusError\";\n\n/** @beta */\ntype VisibilityTreeRendererProps = ComponentPropsWithoutRef<typeof VisibilityTreeRenderer>;\n\n/** @beta */\ntype VisibilityTreeProps = ComponentPropsWithoutRef<typeof VisibilityTree>;\n\n/** @beta */\ninterface UseModelsTreeProps {\n filter?: string;\n activeView: Viewport;\n hierarchyConfig?: Partial<ModelsTreeHierarchyConfiguration>;\n visibilityHandlerOverrides?: ModelsTreeVisibilityHandlerOverrides;\n}\n\n/** @beta */\ninterface UseModelsTreeResult {\n modelsTreeProps: Pick<\n VisibilityTreeProps,\n \"treeName\" | \"getHierarchyDefinition\" | \"getFilteredPaths\" | \"visibilityHandlerFactory\" | \"highlight\" | \"noDataMessage\"\n >;\n rendererProps: Pick<Required<VisibilityTreeRendererProps>, \"getIcon\" | \"onNodeDoubleClick\">;\n}\n\n/**\n * Custom hook to create and manage state for the models tree.\n * @beta\n */\nexport function useModelsTree({ activeView, filter, hierarchyConfig, visibilityHandlerOverrides }: UseModelsTreeProps): UseModelsTreeResult {\n const [filteringError, setFilteringError] = useState<ModelsTreeFilteringError | undefined>(undefined);\n const hierarchyConfiguration = useMemo<ModelsTreeHierarchyConfiguration>(\n () => ({\n ...defaultHierarchyConfiguration,\n ...hierarchyConfig,\n }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n Object.values(hierarchyConfig ?? {}),\n );\n const { onFeatureUsed } = useTelemetryContext();\n\n const { getModelsTreeIdsCache, visibilityHandlerFactory } = useCachedVisibility(activeView, hierarchyConfiguration, visibilityHandlerOverrides);\n const { loadInstanceKeys: loadFocusedInstancesKeys } = useFocusedInstancesContext();\n\n const getHierarchyDefinition = useCallback<VisibilityTreeProps[\"getHierarchyDefinition\"]>(\n ({ imodelAccess }) => new ModelsTreeDefinition({ imodelAccess, idsCache: getModelsTreeIdsCache(), hierarchyConfig: hierarchyConfiguration }),\n [getModelsTreeIdsCache, hierarchyConfiguration],\n );\n\n const onNodeDoubleClick = useCallback(\n async ({ nodeData, extendedData }: PresentationHierarchyNode) => {\n if (!HierarchyNode.isInstancesNode(nodeData) || (extendedData && (extendedData.isSubject || extendedData.isModel || extendedData.isCategory))) {\n return;\n }\n const instanceIds = nodeData.key.instanceKeys.map((instanceKey) => instanceKey.id);\n await IModelApp.viewManager.selectedView?.zoomToElements(instanceIds);\n onFeatureUsed({ featureId: \"zoom-to-node\", reportInteraction: false });\n },\n [onFeatureUsed],\n );\n\n const getFilteredPaths = useMemo<VisibilityTreeProps[\"getFilteredPaths\"] | undefined>(() => {\n setFilteringError(undefined);\n if (loadFocusedInstancesKeys) {\n return async ({ imodelAccess }) => {\n try {\n const targetKeys = await collectTargetKeys(loadFocusedInstancesKeys);\n return await ModelsTreeDefinition.createInstanceKeyPaths({\n imodelAccess,\n idsCache: getModelsTreeIdsCache(),\n keys: targetKeys,\n hierarchyConfig: hierarchyConfiguration,\n });\n } catch (e) {\n const newError =\n e instanceof Error && e.message.match(/Filter matches more than \\d+ items/) ? \"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 (filter) {\n return async ({ imodelAccess }) => {\n onFeatureUsed({ featureId: \"filtering\", reportInteraction: true });\n try {\n return await ModelsTreeDefinition.createInstanceKeyPaths({\n imodelAccess,\n label: filter,\n idsCache: getModelsTreeIdsCache(),\n hierarchyConfig: hierarchyConfiguration,\n });\n } catch (e) {\n const newError = e instanceof Error && e.message.match(/Filter matches more than \\d+ items/) ? \"tooManyFilterMatches\" : \"unknownFilterError\";\n if (newError !== \"tooManyFilterMatches\") {\n const feature = e instanceof Error && e.message.includes(\"query too long to execute or server is too busy\") ? \"error-timeout\" : \"error-unknown\";\n onFeatureUsed({ featureId: feature, reportInteraction: false });\n }\n setFilteringError(newError);\n return [];\n }\n };\n }\n return undefined;\n }, [filter, loadFocusedInstancesKeys, getModelsTreeIdsCache, onFeatureUsed, hierarchyConfiguration]);\n\n return {\n modelsTreeProps: {\n treeName: \"models-tree-v2\",\n visibilityHandlerFactory,\n getHierarchyDefinition,\n getFilteredPaths,\n noDataMessage: getNoDataMessage(filter, filteringError),\n highlight: filter ? { text: filter } : undefined,\n },\n rendererProps: {\n onNodeDoubleClick,\n getIcon,\n },\n };\n}\n\nfunction getNoDataMessage(filter?: string, error?: ModelsTreeFilteringError) {\n if (isInstanceFocusError(error)) {\n return <InstanceFocusError error={error!} />;\n }\n if (isFilterError(error)) {\n return <Text>{TreeWidget.translate(`modelsTree.filtering.${error}`)}</Text>;\n }\n if (filter) {\n return <Text>{TreeWidget.translate(\"modelsTree.filtering.noMatches\", { filter })}</Text>;\n }\n return undefined;\n}\n\nfunction isFilterError(error: ModelsTreeFilteringError | undefined) {\n return error === \"tooManyFilterMatches\" || error === \"unknownFilterError\";\n}\n\nfunction isInstanceFocusError(error: ModelsTreeFilteringError | undefined) {\n return error === \"tooManyInstancesFocused\" || error === \"unknownInstanceFocusError\";\n}\n\nfunction InstanceFocusError({ error }: { error: ModelsTreeFilteringError }) {\n const { toggle } = useFocusedInstancesContext();\n const localizedMessage = createLocalizedMessage(TreeWidget.translate(`modelsTree.filtering.${error}`), () => toggle());\n return <Text>{localizedMessage}</Text>;\n}\n\nfunction getIcon(node: PresentationHierarchyNode): ReactElement | undefined {\n if (node.extendedData?.imageId === undefined) {\n return undefined;\n }\n\n switch (node.extendedData.imageId) {\n case \"icon-layers\":\n return <SvgLayers />;\n case \"icon-item\":\n return <SvgItem />;\n case \"icon-ec-class\":\n return <SvgClassGrouping />;\n case \"icon-imodel-hollow-2\":\n return <SvgImodelHollow />;\n case \"icon-folder\":\n return <SvgFolder />;\n case \"icon-model\":\n return <SvgModel />;\n }\n\n return undefined;\n}\n\nfunction createVisibilityHandlerFactory(\n activeView: Viewport,\n idsCacheGetter: () => ModelsTreeIdsCache,\n overrides?: ModelsTreeVisibilityHandlerOverrides,\n): VisibilityTreeProps[\"visibilityHandlerFactory\"] {\n return ({ imodelAccess }) => createModelsTreeVisibilityHandler({ viewport: activeView, idsCache: idsCacheGetter(), imodelAccess, overrides });\n}\n\nfunction useCachedVisibility(activeView: Viewport, hierarchyConfig: ModelsTreeHierarchyConfiguration, overrides?: ModelsTreeVisibilityHandlerOverrides) {\n const cacheRef = useRef<ModelsTreeIdsCache>();\n const currentIModelRef = useRef(activeView.iModel);\n\n const getModelsTreeIdsCache = useCallback(() => {\n if (!cacheRef.current) {\n cacheRef.current = new ModelsTreeIdsCache(createECSqlQueryExecutor(currentIModelRef.current), hierarchyConfig);\n }\n return cacheRef.current;\n }, [hierarchyConfig]);\n\n const [visibilityHandlerFactory, setVisibilityHandlerFactory] = useState(() => createVisibilityHandlerFactory(activeView, getModelsTreeIdsCache, overrides));\n\n useIModelChangeListener({\n imodel: activeView.iModel,\n action: useCallback(() => {\n cacheRef.current = undefined;\n setVisibilityHandlerFactory(() => createVisibilityHandlerFactory(activeView, getModelsTreeIdsCache, overrides));\n }, [activeView, getModelsTreeIdsCache, overrides]),\n });\n\n useEffect(() => {\n currentIModelRef.current = activeView.iModel;\n cacheRef.current = undefined;\n setVisibilityHandlerFactory(() => createVisibilityHandlerFactory(activeView, getModelsTreeIdsCache, overrides));\n }, [activeView, getModelsTreeIdsCache, overrides]);\n\n return {\n getModelsTreeIdsCache,\n visibilityHandlerFactory,\n };\n}\n\nfunction SvgClassGrouping() {\n return (\n <Icon>\n <svg id=\"Calque_1\" data-name=\"Calque 1\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\">\n <path d=\"M8.00933,0,0,3.97672V11.986L8.00933,16,16,11.93V3.97651ZM1.66173,11.27642c-.26155.03734-.59754-.26154-.76553-.69085-.168-.41066-.09334-.784.168-.82152.26154-.03734.59754.26154.76553.67219C1.99772,10.86577,1.92306,11.23909,1.66173,11.27642Zm0-3.32319c-.26155.03733-.59754-.28-.76553-.69086-.168-.42932-.09334-.80285.168-.84.26133-.03733.59754.28.76532.69086C1.99772,7.54236,1.92306,7.89723,1.66173,7.95323Zm4.31276,5.52621a.18186.18186,0,0,1-.16821-.01866L3.41657,12.15394a.94275.94275,0,0,1-.29887-.80285c.03754-.33621.22421-.52265.41108-.41066L5.9185,12.24727a.88656.88656,0,0,1,.28.80285A.5057.5057,0,0,1,5.97449,13.47944Zm0-3.37919a.18184.18184,0,0,1-.16821-.01867L3.41657,8.77475a.943.943,0,0,1-.29887-.80286c.03754-.3362.22421-.52286.41108-.42953L5.9185,8.86786a.83112.83112,0,0,1,.28.78419A.51684.51684,0,0,1,5.97449,10.10025Z\" />\n </svg>\n </Icon>\n );\n}\n\nasync function collectTargetKeys(loadFocusedInstancesKeys: () => AsyncIterableIterator<InstanceKey | GroupingHierarchyNode>) {\n const targetKeys: Array<InstanceKey | ElementsGroupInfo> = [];\n const groupingNodeInfos: Array<{ parentKey: InstancesNodeKey; parentType: \"element\" | \"category\"; classes: string[]; modelIds: Id64String[] }> = [];\n for await (const key of loadFocusedInstancesKeys()) {\n if (\"id\" in key) {\n targetKeys.push(key);\n continue;\n }\n\n if (!HierarchyNodeKey.isClassGrouping(key.key)) {\n targetKeys.push(...key.groupedInstanceKeys);\n continue;\n }\n\n if (!key.nonGroupingAncestor || !HierarchyNodeKey.isInstances(key.nonGroupingAncestor.key)) {\n continue;\n }\n\n const parentKey = key.nonGroupingAncestor.key;\n const type = key.nonGroupingAncestor.extendedData?.isCategory ? \"category\" : \"element\";\n const modelIds = ((key.nonGroupingAncestor.extendedData?.modelIds as Id64String[][]) ?? []).flatMap((ids) => ids);\n const groupInfo = groupingNodeInfos.find((group) => HierarchyNodeKey.equals(group.parentKey, parentKey));\n if (groupInfo) {\n groupInfo.classes.push(key.key.className);\n } else {\n groupingNodeInfos.push({ classes: [key.key.className], parentType: type, parentKey, modelIds });\n }\n }\n targetKeys.push(\n ...groupingNodeInfos.map(({ parentKey, parentType, classes, 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 classes,\n })),\n );\n return targetKeys;\n}\n\nfunction createLocalizedMessage(message: string, onClick?: () => void) {\n const exp = new RegExp(\"<link>(.*)</link>\");\n const match = message.match(exp);\n if (!match) {\n return message;\n }\n\n const [fullText, innerText] = match;\n const [textBefore, textAfter] = message.split(fullText);\n\n return (\n <>\n {textBefore ? textBefore : null}\n <Anchor\n underline\n onClick={(e) => {\n e.stopPropagation();\n onClick?.();\n }}\n >\n {innerText}\n </Anchor>\n {textAfter ? textAfter : null}\n </>\n );\n}\n"]}
@@ -699,7 +699,7 @@ async function showAllModels(models, viewport) {
699
699
  await viewport.addViewedModels(models);
700
700
  viewport.clearNeverDrawn();
701
701
  viewport.clearAlwaysDrawn();
702
- await (0, CategoriesVisibilityUtils_1.toggleAllCategories)(core_frontend_1.IModelApp.viewManager, viewport.iModel, true, viewport, false);
702
+ await (0, CategoriesVisibilityUtils_1.toggleAllCategories)(viewport, true);
703
703
  }
704
704
  exports.showAllModels = showAllModels;
705
705
  /**