@itwin/presentation-hierarchies-react 2.0.0-alpha.62 → 2.0.0-alpha.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +97 -0
- package/README.md +62 -37
- package/lib/presentation-hierarchies-react/FlatTreeNode.d.ts +1 -2
- package/lib/presentation-hierarchies-react/FlatTreeNode.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/FlatTreeNode.js.map +1 -1
- package/lib/presentation-hierarchies-react/LocalizationContext.d.ts +1 -5
- package/lib/presentation-hierarchies-react/LocalizationContext.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/LocalizationContext.js.map +1 -1
- package/lib/presentation-hierarchies-react/Renderers.d.ts +0 -1
- package/lib/presentation-hierarchies-react/Renderers.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/TreeNode.d.ts +1 -2
- package/lib/presentation-hierarchies-react/TreeNode.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/UseIModelTree.d.ts +0 -1
- package/lib/presentation-hierarchies-react/UseIModelTree.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/UseIModelTree.js.map +1 -1
- package/lib/presentation-hierarchies-react/UseNodeHighlighting.d.ts +1 -4
- package/lib/presentation-hierarchies-react/UseNodeHighlighting.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/UseNodeHighlighting.js.map +1 -1
- package/lib/presentation-hierarchies-react/UseSelectionHandler.d.ts +1 -0
- package/lib/presentation-hierarchies-react/UseSelectionHandler.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/UseSelectionHandler.js.map +1 -1
- package/lib/presentation-hierarchies-react/UseTree.d.ts +4 -11
- package/lib/presentation-hierarchies-react/UseTree.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/UseTree.js +3 -2
- package/lib/presentation-hierarchies-react/UseTree.js.map +1 -1
- package/lib/presentation-hierarchies-react/Utils.js.map +1 -1
- package/lib/presentation-hierarchies-react/internal/DisposePolyfill.js.map +1 -1
- package/lib/presentation-hierarchies-react/internal/LocalizedStrings.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/internal/LocalizedStrings.js.map +1 -1
- package/lib/presentation-hierarchies-react/internal/TreeActions.js +5 -0
- package/lib/presentation-hierarchies-react/internal/TreeActions.js.map +1 -1
- package/lib/presentation-hierarchies-react/internal/TreeLoader.js +3 -0
- package/lib/presentation-hierarchies-react/internal/TreeLoader.js.map +1 -1
- package/lib/presentation-hierarchies-react/internal/TreeModel.d.ts +2 -0
- package/lib/presentation-hierarchies-react/internal/TreeModel.js.map +1 -1
- package/lib/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts +2 -1
- package/lib/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/internal/UseUnifiedSelection.js +1 -1
- package/lib/presentation-hierarchies-react/internal/UseUnifiedSelection.js.map +1 -1
- package/lib/presentation-hierarchies-react/internal/Utils.js.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts +1 -9
- package/lib/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js +53 -46
- package/lib/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts +2 -7
- package/lib/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/RootErrorRenderer.js +5 -4
- package/lib/presentation-hierarchies-react/stratakit/RootErrorRenderer.js.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeAction.d.ts +6 -4
- package/lib/presentation-hierarchies-react/stratakit/TreeAction.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeAction.js +37 -13
- package/lib/presentation-hierarchies-react/stratakit/TreeAction.js.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts +1 -7
- package/lib/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.d.ts +0 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.js.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts +3 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js +152 -140
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts +0 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeRenderer.js.map +1 -1
- package/lib/presentation-hierarchies-react-extract.d.ts +2 -1
- package/package.json +43 -35
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @itwin/presentation-hierarchies-react
|
|
2
2
|
|
|
3
|
+
## 2.0.0-alpha.64
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1469](https://github.com/iTwin/presentation/pull/1469): `TreeActionBase`: Made the `onClick` prop optional.
|
|
8
|
+
- Updated dependencies:
|
|
9
|
+
- @itwin/presentation-shared@2.0.0-alpha.12
|
|
10
|
+
- @itwin/presentation-hierarchies@2.0.0-alpha.17
|
|
11
|
+
- @itwin/unified-selection@2.0.0-alpha.0
|
|
12
|
+
|
|
13
|
+
## 2.0.0-alpha.63
|
|
14
|
+
|
|
15
|
+
### Major Changes
|
|
16
|
+
|
|
17
|
+
- [#1425](https://github.com/iTwin/presentation/pull/1425): Moved the package to use `@mui/material` and `@stratakit/mui`.
|
|
18
|
+
|
|
19
|
+
**Breaking:** Removed `@stratakit/foundations`, `@stratakit/icons` optional peer dependencies. Added `@mui/material` and `@stratakit/mui` as optional peer dependencies.
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- [#1325](https://github.com/iTwin/presentation/pull/1325): Add accessible name for tree context menu.
|
|
24
|
+
- Updated dependencies:
|
|
25
|
+
- @itwin/presentation-shared@2.0.0-alpha.11
|
|
26
|
+
- @itwin/presentation-hierarchies@2.0.0-alpha.16
|
|
27
|
+
- @itwin/unified-selection@1.8.1-alpha.0
|
|
28
|
+
|
|
3
29
|
## 2.0.0-alpha.62
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
|
@@ -971,6 +997,77 @@
|
|
|
971
997
|
|
|
972
998
|
- [#847](https://github.com/iTwin/presentation/pull/847): Moving tree rendering components to a new design systems.
|
|
973
999
|
|
|
1000
|
+
## 1.11.3
|
|
1001
|
+
|
|
1002
|
+
### Patch Changes
|
|
1003
|
+
|
|
1004
|
+
- [#1430](https://github.com/iTwin/presentation/pull/1430): Bump dependencies.
|
|
1005
|
+
- Updated dependencies:
|
|
1006
|
+
- @itwin/presentation-hierarchies@1.7.18
|
|
1007
|
+
- @itwin/presentation-shared@1.2.18
|
|
1008
|
+
- @itwin/unified-selection@1.8.3
|
|
1009
|
+
|
|
1010
|
+
## 1.11.2
|
|
1011
|
+
|
|
1012
|
+
### Patch Changes
|
|
1013
|
+
|
|
1014
|
+
- [#1400](https://github.com/iTwin/presentation/pull/1400): Bump dependencies.
|
|
1015
|
+
- Updated dependencies:
|
|
1016
|
+
- @itwin/unified-selection@1.8.2
|
|
1017
|
+
- @itwin/presentation-hierarchies@1.7.17
|
|
1018
|
+
- @itwin/presentation-shared@1.2.17
|
|
1019
|
+
|
|
1020
|
+
## 1.11.1
|
|
1021
|
+
|
|
1022
|
+
### Patch Changes
|
|
1023
|
+
|
|
1024
|
+
- [#1390](https://github.com/iTwin/presentation/pull/1390): Update `@itwin/core-*` dependencies to `^5.10.0`.
|
|
1025
|
+
- Updated dependencies:
|
|
1026
|
+
- @itwin/presentation-hierarchies@1.7.16
|
|
1027
|
+
- @itwin/presentation-shared@1.2.16
|
|
1028
|
+
- @itwin/unified-selection@1.7.6
|
|
1029
|
+
|
|
1030
|
+
## 1.11.0
|
|
1031
|
+
|
|
1032
|
+
### Minor Changes
|
|
1033
|
+
|
|
1034
|
+
- [#1387](https://github.com/iTwin/presentation/pull/1387): Added support for React version 19
|
|
1035
|
+
|
|
1036
|
+
### Patch Changes
|
|
1037
|
+
|
|
1038
|
+
- Updated dependencies:
|
|
1039
|
+
- @itwin/presentation-shared@1.2.15
|
|
1040
|
+
|
|
1041
|
+
## 1.10.4
|
|
1042
|
+
|
|
1043
|
+
### Patch Changes
|
|
1044
|
+
|
|
1045
|
+
- [#1358](https://github.com/iTwin/presentation/pull/1358): Bump dependencies.
|
|
1046
|
+
- Updated dependencies:
|
|
1047
|
+
- @itwin/presentation-hierarchies@1.7.15
|
|
1048
|
+
- @itwin/presentation-shared@1.2.14
|
|
1049
|
+
- @itwin/unified-selection@1.7.5
|
|
1050
|
+
|
|
1051
|
+
## 1.10.3
|
|
1052
|
+
|
|
1053
|
+
### Patch Changes
|
|
1054
|
+
|
|
1055
|
+
- [#1338](https://github.com/iTwin/presentation/pull/1338): Bump iTwin.js core dependencies to `^5.9.1`.
|
|
1056
|
+
- Updated dependencies:
|
|
1057
|
+
- @itwin/unified-selection@1.7.3
|
|
1058
|
+
- @itwin/presentation-hierarchies@1.7.14
|
|
1059
|
+
- @itwin/presentation-shared@1.2.13
|
|
1060
|
+
|
|
1061
|
+
## 1.10.2
|
|
1062
|
+
|
|
1063
|
+
### Patch Changes
|
|
1064
|
+
|
|
1065
|
+
- [#1313](https://github.com/iTwin/presentation/pull/1313): Bump dependencies.
|
|
1066
|
+
- Updated dependencies:
|
|
1067
|
+
- @itwin/presentation-shared@1.2.12
|
|
1068
|
+
- @itwin/unified-selection@1.7.1
|
|
1069
|
+
- @itwin/presentation-hierarchies@1.7.13
|
|
1070
|
+
|
|
974
1071
|
## 1.10.1
|
|
975
1072
|
|
|
976
1073
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -60,6 +60,9 @@ The hook takes 2 required properties:
|
|
|
60
60
|
|
|
61
61
|
- `imodelAccess` provides access to iModel's data and metadata, required to build the hierarchy. Generally, `@itwin/presentation-core-interop` and `@itwin/presentation-shared` packages are used to create this object:
|
|
62
62
|
|
|
63
|
+
<!-- [[include: [Presentation.HierarchiesReact.iModelAccess.Imports, Presentation.HierarchiesReact.iModelAccess], tsx]] -->
|
|
64
|
+
<!-- BEGIN EXTRACTION -->
|
|
65
|
+
|
|
63
66
|
```tsx
|
|
64
67
|
import { IModelConnection } from "@itwin/core-frontend";
|
|
65
68
|
import { createCachingECClassHierarchyInspector } from "@itwin/presentation-shared";
|
|
@@ -80,6 +83,8 @@ The hook takes 2 required properties:
|
|
|
80
83
|
}
|
|
81
84
|
```
|
|
82
85
|
|
|
86
|
+
<!-- END EXTRACTION -->
|
|
87
|
+
|
|
83
88
|
- `getHierarchyDefinition` is a factory function that creates a hierarchy definition, describing the hierarchy the tree component will render. The `@itwin/presentation-hierarchies` package describes the concept of hierarchy definitions [in more detail](https://github.com/iTwin/presentation/blob/master/packages/hierarchies/learning/imodel/HierarchyDefinition.md).
|
|
84
89
|
|
|
85
90
|
#### `useIModelUnifiedSelectionTree` props
|
|
@@ -99,16 +104,21 @@ The component renders a virtualized tree using the `Tree` component from `@strat
|
|
|
99
104
|
|
|
100
105
|
## Full example
|
|
101
106
|
|
|
107
|
+
<!-- [[include: [Presentation.HierarchiesReact.iModelAccess.Imports, Presentation.HierarchiesReact.SelectionStorage.Imports, Presentation.HierarchiesReact.CustomTreeExample.Imports, Presentation.HierarchiesReact.iModelAccess, Presentation.HierarchiesReact.SelectionStorage, Presentation.HierarchiesReact.CustomTreeExample], tsx]] -->
|
|
108
|
+
<!-- BEGIN EXTRACTION -->
|
|
109
|
+
|
|
102
110
|
```tsx
|
|
103
111
|
import { IModelConnection } from "@itwin/core-frontend";
|
|
104
|
-
import { createCachingECClassHierarchyInspector
|
|
112
|
+
import { createCachingECClassHierarchyInspector } from "@itwin/presentation-shared";
|
|
105
113
|
import { createECSchemaProvider, createECSqlQueryExecutor, createIModelKey } from "@itwin/presentation-core-interop";
|
|
106
|
-
import { createLimitingECSqlQueryExecutor
|
|
114
|
+
import { createLimitingECSqlQueryExecutor } from "@itwin/presentation-hierarchies";
|
|
107
115
|
|
|
108
|
-
import { useIModelUnifiedSelectionTree } from "@itwin/presentation-hierarchies-react";
|
|
109
|
-
import { StrataKitTreeRenderer, StrataKitRootErrorRenderer } from "@itwin/presentation-hierarchies-react/stratakit";
|
|
110
116
|
import { createStorage, SelectionStorage } from "@itwin/unified-selection";
|
|
117
|
+
|
|
111
118
|
import { useEffect, useState } from "react";
|
|
119
|
+
import { Props } from "@itwin/presentation-shared";
|
|
120
|
+
import { useIModelUnifiedSelectionTree } from "@itwin/presentation-hierarchies-react";
|
|
121
|
+
import { StrataKitRootErrorRenderer, StrataKitTreeRenderer } from "@itwin/presentation-hierarchies-react/stratakit";
|
|
112
122
|
|
|
113
123
|
function createIModelAccess(imodel: IModelConnection) {
|
|
114
124
|
const schemaProvider = createECSchemaProvider(imodel.schemaContext);
|
|
@@ -143,24 +153,18 @@ function MyTreeComponent({ imodel }: { imodel: IModelConnection }) {
|
|
|
143
153
|
type IModelAccess = Props<typeof useIModelUnifiedSelectionTree>["imodelAccess"];
|
|
144
154
|
|
|
145
155
|
// The hierarchy definition describes the hierarchy using ECSQL queries; here it just returns all `BisCore.PhysicalModel` instances
|
|
146
|
-
function getHierarchyDefinition(
|
|
156
|
+
function getHierarchyDefinition(): HierarchyDefinition {
|
|
147
157
|
return {
|
|
148
|
-
|
|
149
|
-
defineHierarchyLevel: async ({ instanceLabelSelectClauseFactory, nodeSelectClauseFactory }) => [
|
|
158
|
+
defineHierarchyLevel: async ({ createSelectClause }) => [
|
|
150
159
|
{
|
|
151
160
|
fullClassName: "BisCore.PhysicalModel",
|
|
152
161
|
query: {
|
|
153
162
|
ecsql: `
|
|
154
163
|
SELECT
|
|
155
|
-
${await
|
|
164
|
+
${await createSelectClause({
|
|
156
165
|
ecClassId: { selector: "this.ECClassId" },
|
|
157
166
|
ecInstanceId: { selector: "this.ECInstanceId" },
|
|
158
|
-
nodeLabel: {
|
|
159
|
-
selector: await instanceLabelSelectClauseFactory.createSelectClause({
|
|
160
|
-
classAlias: "this",
|
|
161
|
-
className: "BisCore.PhysicalModel",
|
|
162
|
-
}),
|
|
163
|
-
},
|
|
167
|
+
nodeLabel: { of: { classAlias: "this", className: "BisCore.PhysicalModel" } },
|
|
164
168
|
hasChildren: false,
|
|
165
169
|
})}
|
|
166
170
|
FROM BisCore.PhysicalModel this
|
|
@@ -189,13 +193,10 @@ function MyTreeComponentInternal({
|
|
|
189
193
|
// supply the hierarchy definition
|
|
190
194
|
getHierarchyDefinition,
|
|
191
195
|
});
|
|
192
|
-
|
|
193
196
|
if (treeProps.rootErrorRendererProps) {
|
|
194
|
-
// render error component if tree fails to load
|
|
195
197
|
return <StrataKitRootErrorRenderer {...treeProps.rootErrorRendererProps} />;
|
|
196
198
|
}
|
|
197
|
-
|
|
198
|
-
if (treeProps.isReloading || treeProps.treeRendererProps === undefined) {
|
|
199
|
+
if (!treeProps.treeRendererProps || treeProps.isReloading) {
|
|
199
200
|
return "Loading...";
|
|
200
201
|
}
|
|
201
202
|
|
|
@@ -203,25 +204,54 @@ function MyTreeComponentInternal({
|
|
|
203
204
|
}
|
|
204
205
|
```
|
|
205
206
|
|
|
207
|
+
<!-- END EXTRACTION -->
|
|
208
|
+
|
|
206
209
|
## Localization
|
|
207
210
|
|
|
208
|
-
This package delivers a locale JSON file with English strings that follows the [`i18next JSON format`](https://www.i18next.com/misc/json-format). To enable localization, register `LOCALIZATION_NAMESPACES` during initialization and wrap components in `LocalizationContextProvider
|
|
211
|
+
This package delivers a locale JSON file with English strings that follows the [`i18next JSON format`](https://www.i18next.com/misc/json-format). To enable localization, register `LOCALIZATION_NAMESPACES` during initialization and wrap components in `LocalizationContextProvider`.
|
|
212
|
+
|
|
213
|
+
Import the localization and tree APIs:
|
|
214
|
+
|
|
215
|
+
<!-- [[include: [Presentation.HierarchiesReact.Localization.Tree.Imports, Presentation.HierarchiesReact.Localization.TreeRenderer.Imports], tsx]] -->
|
|
216
|
+
<!-- BEGIN EXTRACTION -->
|
|
209
217
|
|
|
210
218
|
```tsx
|
|
211
219
|
import {
|
|
212
|
-
LocalizationContextProvider,
|
|
213
220
|
LOCALIZATION_NAMESPACES,
|
|
214
|
-
|
|
221
|
+
LocalizationContextProvider,
|
|
222
|
+
useIModelTree,
|
|
215
223
|
} from "@itwin/presentation-hierarchies-react";
|
|
216
|
-
import { StrataKitTreeRenderer } from "@itwin/presentation-hierarchies-react/stratakit";
|
|
217
224
|
|
|
218
|
-
|
|
225
|
+
import { StrataKitRootErrorRenderer, StrataKitTreeRenderer } from "@itwin/presentation-hierarchies-react/stratakit";
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
<!-- END EXTRACTION -->
|
|
229
|
+
|
|
230
|
+
Register the localization namespaces with your localization provider during application initialization:
|
|
231
|
+
|
|
232
|
+
<!-- [[include: Presentation.HierarchiesReact.Localization.RegisterNamespaces, tsx]] -->
|
|
233
|
+
<!-- BEGIN EXTRACTION -->
|
|
234
|
+
|
|
235
|
+
```tsx
|
|
236
|
+
// Register the localization namespaces delivered by the package with your localization provider
|
|
237
|
+
// (e.g. `IModelApp.localization`) during application initialization.
|
|
219
238
|
for (const namespace of LOCALIZATION_NAMESPACES) {
|
|
220
239
|
await localization.registerNamespace(namespace);
|
|
221
240
|
}
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
<!-- END EXTRACTION -->
|
|
244
|
+
|
|
245
|
+
Wrap the tree components with `LocalizationContextProvider`:
|
|
246
|
+
|
|
247
|
+
<!-- [[include: Presentation.HierarchiesReact.Localization.Tree, tsx]] -->
|
|
248
|
+
<!-- BEGIN EXTRACTION -->
|
|
222
249
|
|
|
223
|
-
|
|
224
|
-
|
|
250
|
+
```tsx
|
|
251
|
+
// Wrap the tree components with `LocalizationContextProvider`, passing the same localization provider
|
|
252
|
+
// used to register the namespaces. The provider resolves the package's localized strings at runtime.
|
|
253
|
+
type IModelAccess = Props<typeof useIModelTree>["imodelAccess"];
|
|
254
|
+
function LocalizedTree({ imodelAccess }: { imodelAccess: IModelAccess }) {
|
|
225
255
|
return (
|
|
226
256
|
<LocalizationContextProvider localization={localization}>
|
|
227
257
|
<MyTreeComponent imodelAccess={imodelAccess} />
|
|
@@ -230,22 +260,17 @@ function Tree() {
|
|
|
230
260
|
}
|
|
231
261
|
|
|
232
262
|
function MyTreeComponent({ imodelAccess }: { imodelAccess: IModelAccess }) {
|
|
233
|
-
const treeProps =
|
|
234
|
-
sourceName: "MyTreeComponent",
|
|
235
|
-
imodelAccess,
|
|
236
|
-
getHierarchyDefinition,
|
|
237
|
-
});
|
|
238
|
-
|
|
263
|
+
const treeProps = useIModelTree({ imodelAccess, getHierarchyDefinition });
|
|
239
264
|
if (treeProps.rootErrorRendererProps) {
|
|
240
|
-
return <
|
|
265
|
+
return <StrataKitRootErrorRenderer {...treeProps.rootErrorRendererProps} />;
|
|
241
266
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
return <div>Loading...</div>;
|
|
267
|
+
if (!treeProps.treeRendererProps || treeProps.isReloading) {
|
|
268
|
+
return "Loading";
|
|
245
269
|
}
|
|
246
|
-
|
|
247
|
-
return <StrataKitTreeRenderer {...treeProps.treeRendererProps} treeLabel="My Tree" />;
|
|
270
|
+
return <StrataKitTreeRenderer {...treeProps.treeRendererProps} treeLabel="Localized tree" />;
|
|
248
271
|
}
|
|
249
272
|
```
|
|
250
273
|
|
|
274
|
+
<!-- END EXTRACTION -->
|
|
275
|
+
|
|
251
276
|
`LocalizationContextProvider` accepts a `localization` prop — an object with a `getLocalizedString(key: string): string` method. It is designed to work with the `Localization` interface from `@itwin/core-common`, but a custom implementation can be used as well by providing an object with a custom `getLocalizedString` function. The provider uses it internally to resolve translation keys prefixed with localization namespace.
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { TreeNode } from "./TreeNode.js";
|
|
2
|
-
|
|
3
2
|
//#region src/presentation-hierarchies-react/FlatTreeNode.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Placeholder item that is added to hierarchy as a child for a parent item while its child items are loading.
|
|
@@ -45,5 +44,5 @@ declare function useFlatTreeItems(rootNodes: TreeNode[]): FlatTreeItem[];
|
|
|
45
44
|
*/
|
|
46
45
|
declare function useErrorNodes(rootNodes: TreeNode[]): TreeNode[];
|
|
47
46
|
//#endregion
|
|
48
|
-
export { FlatTreeItem, useErrorNodes, useFlatTreeItems };
|
|
47
|
+
export { FlatTreeItem, FlatTreeNodeItem, useErrorNodes, useFlatTreeItems };
|
|
49
48
|
//# sourceMappingURL=FlatTreeNode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FlatTreeNode.d.ts","names":[],"sources":["../../src/presentation-hierarchies-react/FlatTreeNode.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"FlatTreeNode.d.ts","names":[],"sources":["../../src/presentation-hierarchies-react/FlatTreeNode.ts"],"mappings":";;;;;;;UAcU;EACR;EACA;EACA;;;;;;;UAQe;EACf;EACA;EACA;EACA;EACA,MAAM;;;;;;;;KASI,eAAe,mBAAmB;;;;;;;;iBAc9B,iBAAiB,WAAW,aAAU;;;;;;iBAoCtC,cAAc,WAAW,aAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FlatTreeNode.js","names":["useMemo","ErrorInfo","TreeNode","FlatPlaceholderItem","id","level","placeholder","FlatTreeNodeItem","levelSize","posInLevel","node","FlatTreeItem","isPlaceholderItem","item","useFlatTreeItems","rootNodes","$","_c","t0","getFlatItems","nodes","flatItems","forEach","index","push","length","isExpanded","errors","some","isErrorBlockingExpansion","children","childNodes","useErrorNodes","flatMap","_temp","rootNode","errorNodes","isErrorNode","getErrorNodes","parent","errorList","childErrorList","error","type","isNodeExpandable"],"sources":["../../src/presentation-hierarchies-react/FlatTreeNode.ts"],"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 { useMemo } from \"react\";\n\nimport type { ErrorInfo, TreeNode } from \"./TreeNode.js\";\n\n/**\n * Placeholder item that is added to hierarchy as a child for a parent item while its child items are loading.\n *\n * @alpha\n */\ninterface FlatPlaceholderItem {\n id: string;\n level: number;\n placeholder: true;\n}\n\n/**\n * An item containing `TreeNode` node with properties needed for a flat tree structure.\n *\n * @alpha\n */\nexport interface FlatTreeNodeItem {\n id: string;\n level: number;\n levelSize: number;\n posInLevel: number;\n node: TreeNode;\n}\n\n/**\n * An Item describing single tree item position and its content inside tree.\n * Returned by `useFlatTreeNodeList` hook.\n *\n * @alpha\n */\nexport type FlatTreeItem = FlatTreeNodeItem | FlatPlaceholderItem;\n\n/** @alpha */\nexport function isPlaceholderItem(item: FlatTreeItem): item is FlatPlaceholderItem {\n return \"placeholder\" in item;\n}\n\n/**\n * Used to get a list of `FlatTreeItem` objects for the given list of `TreeNode` objects that represent\n * a hierarchical structure. The resulting items can be used to render the hierarchy in a flat manner, e.g. using a\n * virtualized list.\n *\n * @alpha\n */\nexport function useFlatTreeItems(rootNodes: TreeNode[]) {\n return useMemo(() => getFlatItems(rootNodes, 1), [rootNodes]);\n}\n\nfunction getFlatItems(nodes: TreeNode[], level: number) {\n const flatItems: FlatTreeItem[] = [];\n nodes.forEach((node, index) => {\n flatItems.push({ node, id: node.id, level, levelSize: nodes.length, posInLevel: index + 1 });\n if (!node.isExpanded) {\n return;\n }\n\n if (node.errors.some(isErrorBlockingExpansion)) {\n return;\n }\n\n if (node.children !== true) {\n const childNodes = getFlatItems(node.children, level + 1);\n flatItems.push(...childNodes);\n return;\n }\n\n flatItems.push({\n id: `${node.id}-children-placeholder`,\n level: level + 1,\n placeholder: true,\n } satisfies FlatPlaceholderItem);\n });\n return flatItems;\n}\n\n/**\n * Finds and returns all nodes containing errors in a given hierarchy.\n *\n * @alpha\n */\nexport function useErrorNodes(rootNodes: TreeNode[]): TreeNode[] {\n return useMemo(\n () =>\n rootNodes.flatMap((rootNode) => {\n const errorNodes = isErrorNode(rootNode) ? [rootNode] : [];\n if (rootNode.children === true) {\n return errorNodes;\n }\n\n if (errorNodes.length === 1 && errorNodes[0].errors.some(isErrorBlockingExpansion)) {\n return errorNodes;\n }\n errorNodes.push(...getErrorNodes(rootNode));\n return errorNodes;\n }),\n [rootNodes],\n );\n}\n\nfunction getErrorNodes(parent: TreeNode) {\n const errorList: TreeNode[] = [];\n\n if (parent.children === true) {\n return [];\n }\n\n parent.children.forEach((node) => {\n if (isErrorNode(node)) {\n errorList.push(node);\n if (node.errors.some(isErrorBlockingExpansion)) {\n return;\n }\n }\n\n if (node.children !== true) {\n const childErrorList = getErrorNodes(node);\n errorList.push(...childErrorList);\n return;\n }\n });\n return errorList;\n}\n\nfunction isErrorNode(node: TreeNode): boolean {\n return node.errors.length > 0;\n}\n\nfunction isErrorBlockingExpansion(error: ErrorInfo): boolean {\n return error.type !== \"Unknown\" || !error.isNodeExpandable;\n}\n"],"mappings":";;;AA0CA,SAAgBY,kBAAkBC,MAAiD;
|
|
1
|
+
{"version":3,"file":"FlatTreeNode.js","names":["useMemo","ErrorInfo","TreeNode","FlatPlaceholderItem","id","level","placeholder","FlatTreeNodeItem","levelSize","posInLevel","node","FlatTreeItem","isPlaceholderItem","item","useFlatTreeItems","rootNodes","$","_c","t0","getFlatItems","nodes","flatItems","forEach","index","push","length","isExpanded","errors","some","isErrorBlockingExpansion","children","childNodes","useErrorNodes","flatMap","_temp","rootNode","errorNodes","isErrorNode","getErrorNodes","parent","errorList","childErrorList","error","type","isNodeExpandable"],"sources":["../../src/presentation-hierarchies-react/FlatTreeNode.ts"],"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 { useMemo } from \"react\";\n\nimport type { ErrorInfo, TreeNode } from \"./TreeNode.js\";\n\n/**\n * Placeholder item that is added to hierarchy as a child for a parent item while its child items are loading.\n *\n * @alpha\n */\ninterface FlatPlaceholderItem {\n id: string;\n level: number;\n placeholder: true;\n}\n\n/**\n * An item containing `TreeNode` node with properties needed for a flat tree structure.\n *\n * @alpha\n */\nexport interface FlatTreeNodeItem {\n id: string;\n level: number;\n levelSize: number;\n posInLevel: number;\n node: TreeNode;\n}\n\n/**\n * An Item describing single tree item position and its content inside tree.\n * Returned by `useFlatTreeNodeList` hook.\n *\n * @alpha\n */\nexport type FlatTreeItem = FlatTreeNodeItem | FlatPlaceholderItem;\n\n/** @alpha */\nexport function isPlaceholderItem(item: FlatTreeItem): item is FlatPlaceholderItem {\n return \"placeholder\" in item;\n}\n\n/**\n * Used to get a list of `FlatTreeItem` objects for the given list of `TreeNode` objects that represent\n * a hierarchical structure. The resulting items can be used to render the hierarchy in a flat manner, e.g. using a\n * virtualized list.\n *\n * @alpha\n */\nexport function useFlatTreeItems(rootNodes: TreeNode[]) {\n return useMemo(() => getFlatItems(rootNodes, 1), [rootNodes]);\n}\n\nfunction getFlatItems(nodes: TreeNode[], level: number) {\n const flatItems: FlatTreeItem[] = [];\n nodes.forEach((node, index) => {\n flatItems.push({ node, id: node.id, level, levelSize: nodes.length, posInLevel: index + 1 });\n if (!node.isExpanded) {\n return;\n }\n\n if (node.errors.some(isErrorBlockingExpansion)) {\n return;\n }\n\n if (node.children !== true) {\n const childNodes = getFlatItems(node.children, level + 1);\n flatItems.push(...childNodes);\n return;\n }\n\n flatItems.push({\n id: `${node.id}-children-placeholder`,\n level: level + 1,\n placeholder: true,\n } satisfies FlatPlaceholderItem);\n });\n return flatItems;\n}\n\n/**\n * Finds and returns all nodes containing errors in a given hierarchy.\n *\n * @alpha\n */\nexport function useErrorNodes(rootNodes: TreeNode[]): TreeNode[] {\n return useMemo(\n () =>\n rootNodes.flatMap((rootNode) => {\n const errorNodes = isErrorNode(rootNode) ? [rootNode] : [];\n if (rootNode.children === true) {\n return errorNodes;\n }\n\n if (errorNodes.length === 1 && errorNodes[0].errors.some(isErrorBlockingExpansion)) {\n return errorNodes;\n }\n errorNodes.push(...getErrorNodes(rootNode));\n return errorNodes;\n }),\n [rootNodes],\n );\n}\n\nfunction getErrorNodes(parent: TreeNode) {\n const errorList: TreeNode[] = [];\n\n if (parent.children === true) {\n return [];\n }\n\n parent.children.forEach((node) => {\n if (isErrorNode(node)) {\n errorList.push(node);\n if (node.errors.some(isErrorBlockingExpansion)) {\n return;\n }\n }\n\n if (node.children !== true) {\n const childErrorList = getErrorNodes(node);\n errorList.push(...childErrorList);\n return;\n }\n });\n return errorList;\n}\n\nfunction isErrorNode(node: TreeNode): boolean {\n return node.errors.length > 0;\n}\n\nfunction isErrorBlockingExpansion(error: ErrorInfo): boolean {\n return error.type !== \"Unknown\" || !error.isNodeExpandable;\n}\n"],"mappings":";;;AA0CA,SAAgBY,kBAAkBC,MAAiD;CACjF,OAAO,iBAAiBA;AAC1B;;;;;;;;AASA,SAAOC,iBAAAC,WAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAAA,IAAAC;CAAA,IAAAF,EAAA,OAAAD,WAAA;EACgBG,KAAAC,aAAaJ,WAAW,CAAC;EAACC,EAAA,KAAAD;EAAAC,EAAA,KAAAE;CAAA,OAAAA,KAAAF,EAAA;CAAA,OAA1BE;AAA0B;AAGjD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B,YAAY3B,IAAI,GAAG;GACrB8B,UAAUhB,KAAKd,IAAI;GACnB,IAAIA,KAAKiB,OAAOC,KAAKC,wBAAwB,GAC3C;EAEJ;EAEA,IAAInB,KAAKoB,aAAa,MAAM;GAC1B,MAAMW,iBAAiBH,cAAc5B,IAAI;GACzC8B,UAAUhB,KAAK,GAAGiB,cAAc;GAChC;EACF;CACF,CAAC;CACD,OAAOD;AACT;AAEA,SAASH,YAAY3B,MAAyB;CAC5C,OAAOA,KAAKiB,OAAOF,SAAS;AAC9B;AAEA,SAASI,yBAAyBa,OAA2B;CAC3D,OAAOA,MAAMC,SAAS,aAAa,CAACD,MAAME;AAC5C"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { JSX, PropsWithChildren } from "react";
|
|
2
|
-
|
|
3
2
|
//#region src/presentation-hierarchies-react/LocalizationContext.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* Properties for `LocalizationContextProvider`.
|
|
@@ -15,10 +14,7 @@ interface LocalizationContextProviderProps {
|
|
|
15
14
|
* Context provider for localizing components.
|
|
16
15
|
* @public
|
|
17
16
|
*/
|
|
18
|
-
declare function LocalizationContextProvider({
|
|
19
|
-
localization,
|
|
20
|
-
children
|
|
21
|
-
}: PropsWithChildren<LocalizationContextProviderProps>): JSX.Element;
|
|
17
|
+
declare function LocalizationContextProvider({ localization, children }: PropsWithChildren<LocalizationContextProviderProps>): JSX.Element;
|
|
22
18
|
//#endregion
|
|
23
19
|
export { LocalizationContextProvider };
|
|
24
20
|
//# sourceMappingURL=LocalizationContext.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalizationContext.d.ts","names":[],"sources":["../../src/presentation-hierarchies-react/LocalizationContext.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"LocalizationContext.d.ts","names":[],"sources":["../../src/presentation-hierarchies-react/LocalizationContext.tsx"],"mappings":";;;;;;UAmBU;;EAER;IAAgB,qBAAqB;;;;;;;iBAOvB,8BACd,cACA,YACC,kBAAkB,oCAAoC,IAAI"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalizationContext.js","names":["createContext","useContext","useMemo","LOCALIZATION_NAMESPACE","JSX","PropsWithChildren","LocalizationKey","TranslateFunc","key","localizationContext","LocalizationContextProviderProps","localization","getLocalizedString","LocalizationContextProvider","t0","$","_c","children","t1","translate","t2","useTranslation"],"sources":["../../src/presentation-hierarchies-react/LocalizationContext.tsx"],"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, useContext, useMemo } from \"react\";\nimport { LOCALIZATION_NAMESPACE } from \"./internal/LocalizedStrings.js\";\n\nimport type { JSX, PropsWithChildren } from \"react\";\nimport type { LocalizationKey } from \"./internal/LocalizedStrings.js\";\n\ntype TranslateFunc = (key: LocalizationKey) => string;\n\nconst localizationContext = createContext<TranslateFunc>((key) => key);\n\n/**\n * Properties for `LocalizationContextProvider`.\n * @public\n */\ninterface LocalizationContextProviderProps {\n /** Localization object compatible with `@itwin/core-common` */\n localization: { getLocalizedString: (key: string) => string };\n}\n\n/**\n * Context provider for localizing components.\n * @public\n */\nexport function LocalizationContextProvider({\n localization,\n children,\n}: PropsWithChildren<LocalizationContextProviderProps>): JSX.Element {\n const translate = useMemo<TranslateFunc>(() => {\n return (key: LocalizationKey) => localization.getLocalizedString(`${LOCALIZATION_NAMESPACE}:${key}`);\n }, [localization]);\n return <localizationContext.Provider value={translate}>{children}</localizationContext.Provider>;\n}\n\n/** @internal */\nexport function useTranslation() {\n return useContext(localizationContext);\n}\n"],"mappings":";;;;;AAaA,MAAMS,sBAAsBT,eAA8BQ,QAAQA,
|
|
1
|
+
{"version":3,"file":"LocalizationContext.js","names":["createContext","useContext","useMemo","LOCALIZATION_NAMESPACE","JSX","PropsWithChildren","LocalizationKey","TranslateFunc","key","localizationContext","LocalizationContextProviderProps","localization","getLocalizedString","LocalizationContextProvider","t0","$","_c","children","t1","translate","t2","useTranslation"],"sources":["../../src/presentation-hierarchies-react/LocalizationContext.tsx"],"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, useContext, useMemo } from \"react\";\nimport { LOCALIZATION_NAMESPACE } from \"./internal/LocalizedStrings.js\";\n\nimport type { JSX, PropsWithChildren } from \"react\";\nimport type { LocalizationKey } from \"./internal/LocalizedStrings.js\";\n\ntype TranslateFunc = (key: LocalizationKey) => string;\n\nconst localizationContext = createContext<TranslateFunc>((key) => key);\n\n/**\n * Properties for `LocalizationContextProvider`.\n * @public\n */\ninterface LocalizationContextProviderProps {\n /** Localization object compatible with `@itwin/core-common` */\n localization: { getLocalizedString: (key: string) => string };\n}\n\n/**\n * Context provider for localizing components.\n * @public\n */\nexport function LocalizationContextProvider({\n localization,\n children,\n}: PropsWithChildren<LocalizationContextProviderProps>): JSX.Element {\n const translate = useMemo<TranslateFunc>(() => {\n return (key: LocalizationKey) => localization.getLocalizedString(`${LOCALIZATION_NAMESPACE}:${key}`);\n }, [localization]);\n return <localizationContext.Provider value={translate}>{children}</localizationContext.Provider>;\n}\n\n/** @internal */\nexport function useTranslation() {\n return useContext(localizationContext);\n}\n"],"mappings":";;;;;AAaA,MAAMS,sBAAsBT,eAA8BQ,QAAQA,GAAG;;;;;AAerE,SAAOK,4BAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAAqC,MAAA,EAAAL,cAAAM,aAAAH;CAGU,IAAAI;CAAA,IAAAH,EAAA,OAAAJ,cAAA;EAE3CO,MAAAV,QAA0BG,aAAYC,mBAAoB,GAAGT,uBAAsB,GAAIK,KAAK;EAACO,EAAA,KAAAJ;EAAAI,EAAA,KAAAG;CAAA,OAAAA,KAAAH,EAAA;CADtG,MAAAI,YACED;CACiB,IAAAE;CAAA,IAAAL,EAAA,OAAAE,YAAAF,EAAA,OAAAI,WAAA;EACZC,KAAA,oBAAA,oBAAA,UAAA;GAAqCD,OAAAA;GAAYF;EAAS,CAAA;EAA+BF,EAAA,KAAAE;EAAAF,EAAA,KAAAI;EAAAJ,EAAA,KAAAK;CAAA,OAAAA,KAAAL,EAAA;CAAA,OAAzFK;AAAyF;;AAIlG,SAAOC,iBAAA;CAAA,OACEpB,WAAWQ,mBAAmB;AAAC"}
|
|
@@ -2,7 +2,6 @@ import { ErrorInfo, TreeNode } from "./TreeNode.js";
|
|
|
2
2
|
import { SelectionChangeType } from "./UseSelectionHandler.js";
|
|
3
3
|
import { GenericInstanceFilter, HierarchyNode } from "@itwin/presentation-hierarchies";
|
|
4
4
|
import { InstanceKey } from "@itwin/presentation-shared";
|
|
5
|
-
|
|
6
5
|
//#region src/presentation-hierarchies-react/Renderers.d.ts
|
|
7
6
|
/**
|
|
8
7
|
* Type definition used to render tree rendering UI component.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Renderers.d.ts","names":[],"sources":["../../src/presentation-hierarchies-react/Renderers.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"Renderers.d.ts","names":[],"sources":["../../src/presentation-hierarchies-react/Renderers.ts"],"mappings":";;;;;;;;;KAcY;;;;EAIV,WAAW;;;;EAIX,aAAa,gBAAgB;;;;;;EAM7B,cAAc,SAAS,eAAe,YAAY;;;;EAIlD,iBAAiB;IACf;;;;;KAMQ;;;;EAIV,OAAO;IACL;;;;UAKM;;;;EAIR,aAAa,UAAU;;EAEvB,2BAA2B,+BAA+B;;;;;;UAOlD;;EAER;;;;;;;;;EAUA;;;;;;UAOe;;EAEf,eAAe;;EAGf,0BAA0B;IACxB,iBAAiB;IACjB;QACI,sBAAsB;;EAG5B;;EAEA,eAAe;;EAGf,iBAAiB;;EAEjB,oBAAoB,QAAQ"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { HierarchyNode } from "@itwin/presentation-hierarchies";
|
|
2
|
-
|
|
3
2
|
//#region src/presentation-hierarchies-react/TreeNode.d.ts
|
|
4
3
|
/**
|
|
5
4
|
* A type that defines an node in a UI tree component, built with `useTree` hook.
|
|
@@ -76,5 +75,5 @@ interface GenericErrorInfo {
|
|
|
76
75
|
*/
|
|
77
76
|
type ErrorInfo = GenericErrorInfo | ResultSetTooLargeErrorInfo | NoFilterMatchesErrorInfo | ChildrenLoadErrorInfo;
|
|
78
77
|
//#endregion
|
|
79
|
-
export { ErrorInfo, GenericErrorInfo, ResultSetTooLargeErrorInfo, TreeNode };
|
|
78
|
+
export { ChildrenLoadErrorInfo, ErrorInfo, GenericErrorInfo, NoFilterMatchesErrorInfo, ResultSetTooLargeErrorInfo, TreeNode };
|
|
80
79
|
//# sourceMappingURL=TreeNode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeNode.d.ts","names":[],"sources":["../../src/presentation-hierarchies-react/TreeNode.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"TreeNode.d.ts","names":[],"sources":["../../src/presentation-hierarchies-react/TreeNode.ts"],"mappings":";;;;;;UAWiB;EACf;EACA;EACA,iBAAiB,MAAM;EACvB;EACA;EACA;EACA;;EAEA,UAAU;;EAEV,QAAQ;;;;;;;;UASO;EACf;EACA;;;;;;;;;UAUe;EACf;EACA;EACA;;;;;;;;;UAUe;EACf;EACA;EACA;;;;;;;;;;UAWe;EACf;EACA;EACA;;EAEA;EACA;;;;;;;;KASU,YACR,mBACA,6BACA,2BACA"}
|
|
@@ -2,7 +2,6 @@ import { UseUnifiedTreeSelectionProps } from "./internal/UseUnifiedSelection.js"
|
|
|
2
2
|
import { UseTreeProps, UseTreeResult } from "./UseTree.js";
|
|
3
3
|
import { HierarchyDefinition, HierarchySearchTree, createIModelHierarchyProvider } from "@itwin/presentation-hierarchies";
|
|
4
4
|
import { Props } from "@itwin/presentation-shared";
|
|
5
|
-
|
|
6
5
|
//#region src/presentation-hierarchies-react/UseIModelTree.d.ts
|
|
7
6
|
/** @public */
|
|
8
7
|
type IModelHierarchyProviderProps = Props<typeof createIModelHierarchyProvider>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseIModelTree.d.ts","names":[],"sources":["../../src/presentation-hierarchies-react/UseIModelTree.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"UseIModelTree.d.ts","names":[],"sources":["../../src/presentation-hierarchies-react/UseIModelTree.ts"],"mappings":";;;;;;KAgBK,+BAA+B,aAAa;;KAG5C,eAAe;;;;;KAMf,qBAAqB,KAAK,2DAC7B,KAAK;;;;EAIH,yBAAyB;IAAS,cAAc;QAAmB;;;;EAKnE,kBAAkB;;;;IAIhB,cAAc;;;;IAId,aAAa;QACT,QAAQ;;;;;;;;;;;;;;;iBAgBF,cAAc,OAAO,qBAAqB;;;;;;;;;;;;;;;;iBAuB1C,8BAA8B,OAAO,qBAAqB,+BAA+B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseIModelTree.js","names":["useCallback","createIModelHierarchyProvider","useTranslation","useTree","useUnifiedSelectionTree","HierarchyDefinition","HierarchySearchTree","Props","UseUnifiedTreeSelectionProps","UseTreeProps","UseTreeResult","IModelHierarchyProviderProps","IModelAccess","UseIModelTreeProps","Omit","Pick","getHierarchyDefinition","props","imodelAccess","getSearchPaths","abortSignal","AbortSignal","Promise","useIModelTree","$","_c","imodelChanged","rest","t0","t1","useIModelTreeProps","t2","useIModelUnifiedSelectionTree","translate","hierarchyDefinition","localizedStrings","other","unspecified","t3","t4","getHierarchyProvider"],"sources":["../../src/presentation-hierarchies-react/UseIModelTree.ts"],"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 { createIModelHierarchyProvider } from \"@itwin/presentation-hierarchies\";\nimport { useTranslation } from \"./LocalizationContext.js\";\nimport { useTree, useUnifiedSelectionTree } from \"./UseTree.js\";\n\nimport type { HierarchyDefinition, HierarchySearchTree } from \"@itwin/presentation-hierarchies\";\nimport type { Props } from \"@itwin/presentation-shared\";\nimport type { UseUnifiedTreeSelectionProps } from \"./internal/UseUnifiedSelection.js\";\nimport type { UseTreeProps, UseTreeResult } from \"./UseTree.js\";\n\n/** @public */\ntype IModelHierarchyProviderProps = Props<typeof createIModelHierarchyProvider>;\n\n/** @public */\ntype IModelAccess = IModelHierarchyProviderProps[\"imodelAccess\"];\n\n/**\n * Props for `useIModelTree` and `useIModelUnifiedSelectionTree` hooks.\n * @public\n */\ntype UseIModelTreeProps = Omit<UseTreeProps, \"getHierarchyProvider\" | \"getSearchPaths\"> &\n Pick<IModelHierarchyProviderProps, \"imodelAccess\" | \"imodelChanged\"> & {\n /**\n * Provides the hierarchy definition for the tree.\n */\n getHierarchyDefinition: (props: { imodelAccess: IModelAccess }) => HierarchyDefinition;\n\n /**\n * Provides paths to target nodes.\n */\n getSearchPaths?: (props: {\n /**\n * Object that provides access to the iModel schema and can run queries against the iModel.\n */\n imodelAccess: IModelAccess;\n /**\n * Signal indicating that that the request was canceled\n */\n abortSignal: AbortSignal;\n }) => Promise<HierarchySearchTree[] | undefined>;\n };\n\n/**\n * A React hook that creates state for a tree component whose displayed hierarchy is based on\n * iModel data.\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useTree`\n * @see `useIModelUnifiedSelectionTree`\n * @public\n */\nexport function useIModelTree(props: UseIModelTreeProps): UseTreeResult {\n const { imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths, ...rest } = props;\n return useTree({\n ...rest,\n ...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths }),\n });\n}\n\n/**\n * A React hook that creates state for a tree component whose displayed hierarchy is based on\n * iModel data and that is integrated with unified selection through the given selection\n * storage (previously the storage was provided through the, now deprecated, `UnifiedSelectionProvider`).\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useIModelTree`\n * @see `useUnifiedSelectionTree`\n * @see `UnifiedSelectionProvider`\n * @public\n */\nexport function useIModelUnifiedSelectionTree(props: UseIModelTreeProps & UseUnifiedTreeSelectionProps): UseTreeResult {\n const { imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths, ...rest } = props;\n return useUnifiedSelectionTree({\n ...rest,\n ...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths }),\n });\n}\n\nfunction useIModelTreeProps(\n props: Pick<UseIModelTreeProps, \"imodelAccess\" | \"imodelChanged\" | \"getHierarchyDefinition\" | \"getSearchPaths\">,\n): Pick<UseTreeProps, \"getHierarchyProvider\" | \"getSearchPaths\"> {\n const { imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths } = props;\n const translate = useTranslation();\n return {\n getHierarchyProvider: useCallback(\n () =>\n createIModelHierarchyProvider({\n imodelAccess,\n imodelChanged,\n hierarchyDefinition: getHierarchyDefinition({ imodelAccess }),\n localizedStrings: { other: translate(\"other\"), unspecified: translate(\"unspecified\") },\n }),\n [imodelAccess, imodelChanged, translate, getHierarchyDefinition],\n ),\n getSearchPaths: useCallback(\n async ({ abortSignal }: { abortSignal: AbortSignal }) => getSearchPaths?.({ imodelAccess, abortSignal }),\n [imodelAccess, getSearchPaths],\n ),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA4DA,SAAOuB,cAAAN,OAAA;CAAA,MAAAO,IAAAC,EAAA,
|
|
1
|
+
{"version":3,"file":"UseIModelTree.js","names":["useCallback","createIModelHierarchyProvider","useTranslation","useTree","useUnifiedSelectionTree","HierarchyDefinition","HierarchySearchTree","Props","UseUnifiedTreeSelectionProps","UseTreeProps","UseTreeResult","IModelHierarchyProviderProps","IModelAccess","UseIModelTreeProps","Omit","Pick","getHierarchyDefinition","props","imodelAccess","getSearchPaths","abortSignal","AbortSignal","Promise","useIModelTree","$","_c","imodelChanged","rest","t0","t1","useIModelTreeProps","t2","useIModelUnifiedSelectionTree","translate","hierarchyDefinition","localizedStrings","other","unspecified","t3","t4","getHierarchyProvider"],"sources":["../../src/presentation-hierarchies-react/UseIModelTree.ts"],"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 { createIModelHierarchyProvider } from \"@itwin/presentation-hierarchies\";\nimport { useTranslation } from \"./LocalizationContext.js\";\nimport { useTree, useUnifiedSelectionTree } from \"./UseTree.js\";\n\nimport type { HierarchyDefinition, HierarchySearchTree } from \"@itwin/presentation-hierarchies\";\nimport type { Props } from \"@itwin/presentation-shared\";\nimport type { UseUnifiedTreeSelectionProps } from \"./internal/UseUnifiedSelection.js\";\nimport type { UseTreeProps, UseTreeResult } from \"./UseTree.js\";\n\n/** @public */\ntype IModelHierarchyProviderProps = Props<typeof createIModelHierarchyProvider>;\n\n/** @public */\ntype IModelAccess = IModelHierarchyProviderProps[\"imodelAccess\"];\n\n/**\n * Props for `useIModelTree` and `useIModelUnifiedSelectionTree` hooks.\n * @public\n */\ntype UseIModelTreeProps = Omit<UseTreeProps, \"getHierarchyProvider\" | \"getSearchPaths\"> &\n Pick<IModelHierarchyProviderProps, \"imodelAccess\" | \"imodelChanged\"> & {\n /**\n * Provides the hierarchy definition for the tree.\n */\n getHierarchyDefinition: (props: { imodelAccess: IModelAccess }) => HierarchyDefinition;\n\n /**\n * Provides paths to target nodes.\n */\n getSearchPaths?: (props: {\n /**\n * Object that provides access to the iModel schema and can run queries against the iModel.\n */\n imodelAccess: IModelAccess;\n /**\n * Signal indicating that that the request was canceled\n */\n abortSignal: AbortSignal;\n }) => Promise<HierarchySearchTree[] | undefined>;\n };\n\n/**\n * A React hook that creates state for a tree component whose displayed hierarchy is based on\n * iModel data.\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useTree`\n * @see `useIModelUnifiedSelectionTree`\n * @public\n */\nexport function useIModelTree(props: UseIModelTreeProps): UseTreeResult {\n const { imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths, ...rest } = props;\n return useTree({\n ...rest,\n ...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths }),\n });\n}\n\n/**\n * A React hook that creates state for a tree component whose displayed hierarchy is based on\n * iModel data and that is integrated with unified selection through the given selection\n * storage (previously the storage was provided through the, now deprecated, `UnifiedSelectionProvider`).\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useIModelTree`\n * @see `useUnifiedSelectionTree`\n * @see `UnifiedSelectionProvider`\n * @public\n */\nexport function useIModelUnifiedSelectionTree(props: UseIModelTreeProps & UseUnifiedTreeSelectionProps): UseTreeResult {\n const { imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths, ...rest } = props;\n return useUnifiedSelectionTree({\n ...rest,\n ...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths }),\n });\n}\n\nfunction useIModelTreeProps(\n props: Pick<UseIModelTreeProps, \"imodelAccess\" | \"imodelChanged\" | \"getHierarchyDefinition\" | \"getSearchPaths\">,\n): Pick<UseTreeProps, \"getHierarchyProvider\" | \"getSearchPaths\"> {\n const { imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths } = props;\n const translate = useTranslation();\n return {\n getHierarchyProvider: useCallback(\n () =>\n createIModelHierarchyProvider({\n imodelAccess,\n imodelChanged,\n hierarchyDefinition: getHierarchyDefinition({ imodelAccess }),\n localizedStrings: { other: translate(\"other\"), unspecified: translate(\"unspecified\") },\n }),\n [imodelAccess, imodelChanged, translate, getHierarchyDefinition],\n ),\n getSearchPaths: useCallback(\n async ({ abortSignal }: { abortSignal: AbortSignal }) => getSearchPaths?.({ imodelAccess, abortSignal }),\n [imodelAccess, getSearchPaths],\n ),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA4DA,SAAOuB,cAAAN,OAAA;CAAA,MAAAO,IAAAC,EAAA,EAAA;CAAA,IAAAT;CAAA,IAAAG;CAAA,IAAAD;CAAA,IAAAQ;CAAA,IAAAC;CAAA,IAAAH,EAAA,OAAAP,OAAA;EACL,CAAA,CAAAC,cAAAQ,eAAAV,wBAAAG,mBAAAQ,QAAyFV;EAAMO,EAAA,KAAAP;EAAAO,EAAA,KAAAR;EAAAQ,EAAA,KAAAL;EAAAK,EAAA,KAAAN;EAAAM,EAAA,KAAAE;EAAAF,EAAA,KAAAG;CAAA,OAAA;EAAAX,yBAAAQ,EAAA;EAAAL,iBAAAK,EAAA;EAAAN,eAAAM,EAAA;EAAAE,gBAAAF,EAAA;EAAAG,OAAAH,EAAA;CAAA;CAAA,IAAAI;CAAA,IAAAJ,EAAA,OAAAR,0BAAAQ,EAAA,OAAAL,kBAAAK,EAAA,OAAAN,gBAAAM,EAAA,OAAAE,eAAA;EAGvEE,KAAA;GAAAV;GAAAQ;GAAAV;GAAAG;EAAsE;EAACK,EAAA,KAAAR;EAAAQ,EAAA,KAAAL;EAAAK,EAAA,KAAAN;EAAAM,EAAA,KAAAE;EAAAF,EAAA,MAAAI;CAAA,OAAAA,KAAAJ,EAAA;CAA1F,MAAAK,KAAAC,mBAAmBF,EAAuE;CAAC,IAAAG;CAAA,IAAAP,EAAA,QAAAG,QAAAH,EAAA,QAAAK,IAAA;EAFjFE,KAAA;GAAA,GACVJ;GAAI,GACJE;EACL;EAACL,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useNodeHighlighting` hook.
|
|
@@ -22,9 +21,7 @@ interface UseNodeHighlightingResult {
|
|
|
22
21
|
* A react hook that helps create highlighted node labels based on provided highlight.
|
|
23
22
|
* @alpha
|
|
24
23
|
*/
|
|
25
|
-
declare function useNodeHighlighting({
|
|
26
|
-
highlightText
|
|
27
|
-
}: UseNodeHighlightingProps): UseNodeHighlightingResult;
|
|
24
|
+
declare function useNodeHighlighting({ highlightText }: UseNodeHighlightingProps): UseNodeHighlightingResult;
|
|
28
25
|
//#endregion
|
|
29
26
|
export { useNodeHighlighting };
|
|
30
27
|
//# sourceMappingURL=UseNodeHighlighting.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseNodeHighlighting.d.ts","names":[],"sources":["../../src/presentation-hierarchies-react/UseNodeHighlighting.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"UseNodeHighlighting.d.ts","names":[],"sources":["../../src/presentation-hierarchies-react/UseNodeHighlighting.tsx"],"mappings":";;;;;;;UAeU;;EAER;;;;;;UAOQ;;EAER,WAAW,MAAM,aAAa;;;;;;iBAOhB,sBAAsB,iBAAiB,2BAA2B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseNodeHighlighting.js","names":["useCallback","HierarchyNode","JSX","ReactElement","TreeNode","UseNodeHighlightingProps","highlightText","UseNodeHighlightingResult","getLabel","node","useNodeHighlighting","t0","$","_c","t1","isGroupingNode","nodeData","search","isSearchTarget","label","matchedIndexes","Array","nodeLabel","toLocaleLowerCase","searchText","fromPosition","foundIndex","indexOf","push","length","finalLabel","lastAddedPosition","i","matchedIndex","substring","endingPlace","t2"],"sources":["../../src/presentation-hierarchies-react/UseNodeHighlighting.tsx"],"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 { HierarchyNode } from \"@itwin/presentation-hierarchies\";\n\nimport type { JSX, ReactElement } from \"react\";\nimport type { TreeNode } from \"./TreeNode.js\";\n\n/**\n * Props for `useNodeHighlighting` hook.\n * @alpha\n */\ninterface UseNodeHighlightingProps {\n /** Text that should be highlighted */\n highlightText?: string;\n}\n\n/**\n * Result of `useNodeHighlighting` hook.\n * @alpha\n */\ninterface UseNodeHighlightingResult {\n /** Function that creates highlighted node labels. */\n getLabel: (node: TreeNode) => ReactElement;\n}\n\n/**\n * A react hook that helps create highlighted node labels based on provided highlight.\n * @alpha\n */\nexport function useNodeHighlighting({ highlightText }: UseNodeHighlightingProps): UseNodeHighlightingResult {\n const getLabel = useCallback(\n (node: TreeNode) => {\n if (!highlightText || HierarchyNode.isGroupingNode(node.nodeData) || !node.nodeData.search?.isSearchTarget) {\n return <span>{node.label}</span>;\n }\n\n const matchedIndexes = new Array<number>();\n const nodeLabel = node.label.toLocaleLowerCase();\n const searchText = highlightText.toLocaleLowerCase();\n let fromPosition = 0;\n // Find all occurrences of the search text in the node label\n while (true) {\n const foundIndex = nodeLabel.indexOf(searchText, fromPosition);\n if (foundIndex === -1) {\n break;\n }\n matchedIndexes.push(foundIndex);\n fromPosition = foundIndex + searchText.length;\n }\n\n if (matchedIndexes.length === 0) {\n return <span>{node.label}</span>;\n }\n\n // Create the final label with highlighted parts\n const finalLabel = new Array<JSX.Element>();\n let lastAddedPosition = 0;\n for (let i = 0; i < matchedIndexes.length; ++i) {\n const matchedIndex = matchedIndexes[i];\n if (matchedIndex > lastAddedPosition) {\n finalLabel.push(<span key={`normal-${i}`}>{node.label.substring(lastAddedPosition, matchedIndex)}</span>);\n lastAddedPosition = matchedIndex;\n }\n const endingPlace = matchedIndex + highlightText.length;\n finalLabel.push(<mark key={`marked-${i}`}>{node.label.substring(lastAddedPosition, endingPlace)}</mark>);\n lastAddedPosition = endingPlace;\n }\n if (lastAddedPosition < node.label.length) {\n finalLabel.push(\n <span key={`normal-${matchedIndexes.length + 1}`}>{node.label.substring(lastAddedPosition)}</span>,\n );\n }\n\n return <>{finalLabel}</>;\n },\n [highlightText],\n );\n\n return { getLabel };\n}\n"],"mappings":";;;;;;;;AAiCA,SAAOU,oBAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,
|
|
1
|
+
{"version":3,"file":"UseNodeHighlighting.js","names":["useCallback","HierarchyNode","JSX","ReactElement","TreeNode","UseNodeHighlightingProps","highlightText","UseNodeHighlightingResult","getLabel","node","useNodeHighlighting","t0","$","_c","t1","isGroupingNode","nodeData","search","isSearchTarget","label","matchedIndexes","Array","nodeLabel","toLocaleLowerCase","searchText","fromPosition","foundIndex","indexOf","push","length","finalLabel","lastAddedPosition","i","matchedIndex","substring","endingPlace","t2"],"sources":["../../src/presentation-hierarchies-react/UseNodeHighlighting.tsx"],"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 { HierarchyNode } from \"@itwin/presentation-hierarchies\";\n\nimport type { JSX, ReactElement } from \"react\";\nimport type { TreeNode } from \"./TreeNode.js\";\n\n/**\n * Props for `useNodeHighlighting` hook.\n * @alpha\n */\ninterface UseNodeHighlightingProps {\n /** Text that should be highlighted */\n highlightText?: string;\n}\n\n/**\n * Result of `useNodeHighlighting` hook.\n * @alpha\n */\ninterface UseNodeHighlightingResult {\n /** Function that creates highlighted node labels. */\n getLabel: (node: TreeNode) => ReactElement;\n}\n\n/**\n * A react hook that helps create highlighted node labels based on provided highlight.\n * @alpha\n */\nexport function useNodeHighlighting({ highlightText }: UseNodeHighlightingProps): UseNodeHighlightingResult {\n const getLabel = useCallback(\n (node: TreeNode) => {\n if (!highlightText || HierarchyNode.isGroupingNode(node.nodeData) || !node.nodeData.search?.isSearchTarget) {\n return <span>{node.label}</span>;\n }\n\n const matchedIndexes = new Array<number>();\n const nodeLabel = node.label.toLocaleLowerCase();\n const searchText = highlightText.toLocaleLowerCase();\n let fromPosition = 0;\n // Find all occurrences of the search text in the node label\n while (true) {\n const foundIndex = nodeLabel.indexOf(searchText, fromPosition);\n if (foundIndex === -1) {\n break;\n }\n matchedIndexes.push(foundIndex);\n fromPosition = foundIndex + searchText.length;\n }\n\n if (matchedIndexes.length === 0) {\n return <span>{node.label}</span>;\n }\n\n // Create the final label with highlighted parts\n const finalLabel = new Array<JSX.Element>();\n let lastAddedPosition = 0;\n for (let i = 0; i < matchedIndexes.length; ++i) {\n const matchedIndex = matchedIndexes[i];\n if (matchedIndex > lastAddedPosition) {\n finalLabel.push(<span key={`normal-${i}`}>{node.label.substring(lastAddedPosition, matchedIndex)}</span>);\n lastAddedPosition = matchedIndex;\n }\n const endingPlace = matchedIndex + highlightText.length;\n finalLabel.push(<mark key={`marked-${i}`}>{node.label.substring(lastAddedPosition, endingPlace)}</mark>);\n lastAddedPosition = endingPlace;\n }\n if (lastAddedPosition < node.label.length) {\n finalLabel.push(\n <span key={`normal-${matchedIndexes.length + 1}`}>{node.label.substring(lastAddedPosition)}</span>,\n );\n }\n\n return <>{finalLabel}</>;\n },\n [highlightText],\n );\n\n return { getLabel };\n}\n"],"mappings":";;;;;;;;AAiCA,SAAOU,oBAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,CAAA;CAA6B,MAAA,EAAAP,kBAAAK;CAA2C,IAAAG;CAAA,IAAAF,EAAA,OAAAN,eAAA;EAE3EQ,MAAAL,SAAA;GACE,IAAI,CAACH,iBAAiBL,cAAac,eAAgBN,KAAIO,QAAS,KAA5D,CAAkEP,KAAIO,SAASC,QAAuBC,gBAAA,OACjG,oBAAA,QAAA,EAAA,UAAOT,KAAIU,MAAc,CAAA;GAGlC,MAAAC,iBAAuB,IAAIC,MAAc;GACzC,MAAAC,YAAkBb,KAAIU,MAAMI,kBAAmB;GAC/C,MAAAC,aAAmBlB,cAAaiB,kBAAmB;GACnD,IAAAE,eAAmB;GAEnB,OAAO,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
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseSelectionHandler.d.ts","names":[],"sources":["../../src/presentation-hierarchies-react/UseSelectionHandler.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"UseSelectionHandler.d.ts","names":[],"sources":["../../src/presentation-hierarchies-react/UseSelectionHandler.ts"],"mappings":";;;;;;;;;;;KAmBY;;;;;;;;;KAUA"}
|