@itwin/presentation-hierarchies-react 2.0.0-alpha.57 → 2.0.0-alpha.59
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 +184 -36
- package/README.md +46 -57
- package/lib/presentation-hierarchies-react/{stratakit/FlatTreeNode.d.ts → FlatTreeNode.d.ts} +2 -2
- package/lib/presentation-hierarchies-react/FlatTreeNode.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/{stratakit/FlatTreeNode.js → FlatTreeNode.js} +2 -3
- package/lib/presentation-hierarchies-react/FlatTreeNode.js.map +1 -0
- package/lib/presentation-hierarchies-react/{stratakit/LocalizationContext.d.ts → LocalizationContext.d.ts} +1 -1
- package/lib/presentation-hierarchies-react/LocalizationContext.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/{stratakit/LocalizationContext.js → LocalizationContext.js} +3 -4
- package/lib/presentation-hierarchies-react/LocalizationContext.js.map +1 -0
- package/lib/presentation-hierarchies-react/UseIModelTree.d.ts +2 -2
- package/lib/presentation-hierarchies-react/UseIModelTree.js +2 -3
- package/lib/presentation-hierarchies-react/UseIModelTree.js.map +1 -1
- package/lib/presentation-hierarchies-react/UseNodeHighlighting.js +1 -2
- package/lib/presentation-hierarchies-react/UseNodeHighlighting.js.map +1 -1
- package/lib/presentation-hierarchies-react/UseSelectionHandler.d.ts +0 -2
- package/lib/presentation-hierarchies-react/UseSelectionHandler.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/UseSelectionHandler.js +1 -2
- package/lib/presentation-hierarchies-react/UseSelectionHandler.js.map +1 -1
- package/lib/presentation-hierarchies-react/UseTree.d.ts +2 -2
- package/lib/presentation-hierarchies-react/UseTree.js +1 -2
- package/lib/presentation-hierarchies-react/UseTree.js.map +1 -1
- package/lib/presentation-hierarchies-react/Utils.js +1 -1
- package/lib/presentation-hierarchies-react/Utils.js.map +1 -1
- package/lib/presentation-hierarchies-react/internal/DisposePolyfill.js +2 -2
- package/lib/presentation-hierarchies-react/internal/DisposePolyfill.js.map +1 -1
- package/lib/presentation-hierarchies-react/internal/LocalizedStrings.js +1 -1
- package/lib/presentation-hierarchies-react/internal/TreeActions.js +1 -2
- package/lib/presentation-hierarchies-react/internal/TreeActions.js.map +1 -1
- package/lib/presentation-hierarchies-react/internal/TreeLoader.js +1 -2
- package/lib/presentation-hierarchies-react/internal/TreeLoader.js.map +1 -1
- package/lib/presentation-hierarchies-react/internal/TreeModel.d.ts +0 -2
- package/lib/presentation-hierarchies-react/internal/TreeModel.js +1 -1
- package/lib/presentation-hierarchies-react/internal/TreeModel.js.map +1 -1
- package/lib/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts +0 -2
- package/lib/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/internal/UseUnifiedSelection.js +1 -2
- package/lib/presentation-hierarchies-react/internal/UseUnifiedSelection.js.map +1 -1
- package/lib/presentation-hierarchies-react/internal/Utils.js +1 -2
- package/lib/presentation-hierarchies-react/internal/Utils.js.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts +1 -1
- package/lib/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js +2 -3
- package/lib/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/RootErrorRenderer.js +2 -3
- package/lib/presentation-hierarchies-react/stratakit/RootErrorRenderer.js.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeAction.js +1 -2
- package/lib/presentation-hierarchies-react/stratakit/TreeAction.js.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js +2 -3
- package/lib/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.js +2 -3
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.js.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.d.ts +0 -2
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js +2 -3
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts +0 -4
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js +2 -3
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeRenderer.js +2 -3
- package/lib/presentation-hierarchies-react/stratakit/TreeRenderer.js.map +1 -1
- package/lib/presentation-hierarchies-react-extract.d.ts +17 -0
- package/lib/presentation-hierarchies-react-extract.js +16 -0
- package/lib/presentation-hierarchies-react-stratakit.d.ts +8 -0
- package/lib/presentation-hierarchies-react-stratakit.js +8 -0
- package/lib/presentation-hierarchies-react.d.ts +3 -10
- package/lib/presentation-hierarchies-react.js +3 -11
- package/package.json +20 -13
- package/lib/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts.map +0 -1
- package/lib/presentation-hierarchies-react/stratakit/FlatTreeNode.js.map +0 -1
- package/lib/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts.map +0 -1
- package/lib/presentation-hierarchies-react/stratakit/LocalizationContext.js.map +0 -1
package/README.md
CHANGED
|
@@ -4,6 +4,15 @@ Copyright © Bentley Systems, Incorporated. All rights reserved. See LICENSE.md
|
|
|
4
4
|
|
|
5
5
|
The `@itwin/presentation-hierarchies-react` package provides APIs for building a headless UI for rendering tree components based on data in an [iTwin.js iModel](https://www.itwinjs.org/learning/imodels/#imodel-overview). In addition, it delivers a set of [StrataKit](https://www.npmjs.com/package/@stratakit/bricks)-based components for rendering the tree.
|
|
6
6
|
|
|
7
|
+
## Entry points
|
|
8
|
+
|
|
9
|
+
Because StrataKit packages are optional peer dependencies, the package exposes two entry points:
|
|
10
|
+
|
|
11
|
+
| Entry point | Requires StrataKit peer dependencies | Description |
|
|
12
|
+
| ------------------------------------------------- | ------------------------------------ | ----------------------------------------------------------------------------------------------------------------- |
|
|
13
|
+
| `@itwin/presentation-hierarchies-react` | ❌ | Core API - headless hooks and utilities, including localization helpers. |
|
|
14
|
+
| `@itwin/presentation-hierarchies-react/stratakit` | ✔️ | StrataKit-based components and actions (`StrataKitTreeRenderer`, `TreeNodeFilterAction`, `TreeNodeRenameAction`). |
|
|
15
|
+
|
|
7
16
|
## Headless UI
|
|
8
17
|
|
|
9
18
|
### Tree state hooks
|
|
@@ -15,26 +24,22 @@ The package provides different flavors of the same hook for creating and managin
|
|
|
15
24
|
| Supported data source | any | iModel | any | iModel |
|
|
16
25
|
| Integration with [Unified Selection](https://www.itwinjs.org/presentation/unified-selection/) system | ❌ | ❌ | ✔️ | ✔️ |
|
|
17
26
|
|
|
18
|
-
All these hooks return
|
|
19
|
-
|
|
20
|
-
- `isLoading` is a boolean indicating whether the root tree nodes are being loaded. Set to `true` on initial load and on reload (e.g. when iModel data changes).
|
|
21
|
-
|
|
22
|
-
- `rootNodes` is an array of `TreeNode` and is what the component should render.
|
|
23
|
-
|
|
24
|
-
- `expandNode` function to expand or collapse a node.
|
|
27
|
+
All these hooks return a `UseTreeResult` object with top-level properties and two optional renderer prop bags:
|
|
25
28
|
|
|
26
|
-
- `
|
|
29
|
+
- `isReloading` is a boolean that is `true` while the tree is being reloaded (does not apply to the initial load).
|
|
27
30
|
|
|
28
|
-
- `getNode` function to get node by its id.
|
|
31
|
+
- `getNode` function to get a tree node by its id.
|
|
29
32
|
|
|
30
|
-
- `
|
|
31
|
-
- hierarchy level size limit,
|
|
32
|
-
- hierarchy level instance filter,
|
|
33
|
-
- instance keys of the nodes in the hierarchy level.
|
|
33
|
+
- `setFormatter` function to set the active node label formatter.
|
|
34
34
|
|
|
35
|
-
- `
|
|
35
|
+
- `rootErrorRendererProps` is defined (and `treeRendererProps` is `undefined`) when root nodes fail to load. Pass it directly to `StrataKitRootErrorRenderer` or use it to build a custom error UI.
|
|
36
36
|
|
|
37
|
-
- `
|
|
37
|
+
- `treeRendererProps` is defined once root nodes have loaded successfully. It is `undefined` during the initial load. Pass it directly to `StrataKitTreeRenderer` or use it to build a custom tree renderer. It contains:
|
|
38
|
+
- `rootNodes` — array of `TreeNode` items to render.
|
|
39
|
+
- `expandNode` — function to expand or collapse a node.
|
|
40
|
+
- `isNodeSelected` and `selectNodes` — functions to inspect and change tree selection.
|
|
41
|
+
- `getHierarchyLevelDetails` — function to get details of a specific hierarchy level (size limit, instance filter, instance key iterator).
|
|
42
|
+
- `reloadTree` — function to reload part of the tree, optionally keeping its state.
|
|
38
43
|
|
|
39
44
|
#### `useTree` props
|
|
40
45
|
|
|
@@ -84,39 +89,13 @@ In addition to [props required by `useIModelTree`](#useimodeltree-props), the ho
|
|
|
84
89
|
- `selectionStorage` - unified selection storage used across different app's components, allowing them all to share selection state.
|
|
85
90
|
- `sourceName` - a string that distinguishes selection changes being made by different components. The value should be unique for each component.
|
|
86
91
|
|
|
87
|
-
### `useSelectionHandler` hook
|
|
88
|
-
|
|
89
|
-
This is a React hook that helps implement different selection modes in a tree, whose state is managed through one of the [tree state hooks](#tree-state-hooks).
|
|
90
|
-
|
|
91
|
-
It takes 3 required properties:
|
|
92
|
-
|
|
93
|
-
- `rootNodes` and `selectNodes` are the corresponding properties from the tree state object, created using one of the [tree state hooks](#tree-state-hooks).
|
|
94
|
-
|
|
95
|
-
- `selectionMode` is a string that defines the selection mode. It can be one of the following values:
|
|
96
|
-
- `none` - no selection is allowed,
|
|
97
|
-
- `single` - only one node can be selected at a time,
|
|
98
|
-
- `extended` - multiple nodes can be selected using shift and ctrl keys,
|
|
99
|
-
- `multiple` - multiple nodes can be selected without using shift or ctrl keys.
|
|
100
|
-
|
|
101
|
-
The returned object contains 2 functions, that should be called by the node renderer: `onNodeClick` and `onNodeKeyDown`.
|
|
102
|
-
|
|
103
|
-
Our [tree renderer implementation](#treerenderer) calls this hook and passes the callbacks to the [node renderer](#treenoderenderer), so there's no need to use it unless implementing a custom tree renderer.
|
|
104
|
-
|
|
105
92
|
## StrataKit components
|
|
106
93
|
|
|
107
94
|
While the package provides a headless UI, it also delivers a set of [StrataKit](https://www.npmjs.com/package/@stratakit/bricks)-based components for rendering the tree, which should cover majority of use cases. Consumers using the below components are required to provide compatible `@stratakit/bricks`/`@stratakit/icons`/`@stratakit/foundations` packages, which are optional peer dependencies to this package.
|
|
108
95
|
|
|
109
|
-
### `
|
|
110
|
-
|
|
111
|
-
The component is based on StrataKit `Tree` component and uses our [`TreeNodeRenderer`](#treenoderenderer) to render the nodes. In addition, it makes use of the [`useSelectionHandler` hook](#useselectionhandler-hook) to add selection modes' support.
|
|
112
|
-
|
|
113
|
-
### `TreeNodeRenderer`
|
|
96
|
+
### `StrataKitTreeRenderer`
|
|
114
97
|
|
|
115
|
-
The component
|
|
116
|
-
|
|
117
|
-
- Reporting click and key down events for use with [`useSelectionHandler` hook](#useselectionhandler-hook).
|
|
118
|
-
- Icons, selection, expand / collapse.
|
|
119
|
-
- Action buttons to clear / set hierarchy level instance filter.
|
|
98
|
+
The component renders a virtualized tree using the `Tree` component from `@stratakit/structures`. It handles node selection modes, error display, and virtualized scrolling. It accepts a required `treeLabel` prop (used for accessibility) and spreads `treeRendererProps` returned by the tree state hooks.
|
|
120
99
|
|
|
121
100
|
## Full example
|
|
122
101
|
|
|
@@ -128,7 +107,8 @@ import { createLimitingECSqlQueryExecutor, createNodesQueryClauseFactory, Hierar
|
|
|
128
107
|
|
|
129
108
|
import { createBisInstanceLabelSelectClauseFactory, Props } from "@itwin/presentation-shared";
|
|
130
109
|
|
|
131
|
-
import {
|
|
110
|
+
import { useIModelUnifiedSelectionTree } from "@itwin/presentation-hierarchies-react";
|
|
111
|
+
import { StrataKitTreeRenderer, StrataKitRootErrorRenderer } from "@itwin/presentation-hierarchies-react/stratakit";
|
|
132
112
|
import { createStorage, SelectionStorage } from "@itwin/unified-selection";
|
|
133
113
|
import { useEffect, useState } from "react";
|
|
134
114
|
|
|
@@ -195,7 +175,7 @@ function getHierarchyDefinition({ imodelAccess }: { imodelAccess: IModelAccess }
|
|
|
195
175
|
|
|
196
176
|
/** Internal component that creates and renders tree state. */
|
|
197
177
|
function MyTreeComponentInternal({ imodelAccess, selectionStorage }: { imodelAccess: IModelAccess; selectionStorage: SelectionStorage }) {
|
|
198
|
-
const
|
|
178
|
+
const treeProps = useIModelUnifiedSelectionTree({
|
|
199
179
|
// the unified selection storage used by all app components let them share selection state
|
|
200
180
|
selectionStorage,
|
|
201
181
|
// the source name is used to distinguish selection changes being made by different components
|
|
@@ -205,10 +185,17 @@ function MyTreeComponentInternal({ imodelAccess, selectionStorage }: { imodelAcc
|
|
|
205
185
|
// supply the hierarchy definition
|
|
206
186
|
getHierarchyDefinition,
|
|
207
187
|
});
|
|
208
|
-
|
|
188
|
+
|
|
189
|
+
if (treeProps.rootErrorRendererProps) {
|
|
190
|
+
// render error component if tree fails to load
|
|
191
|
+
return <StrataKitRootErrorRenderer {...treeProps.rootErrorRendererProps} />;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (treeProps.isReloading || treeProps.treeRendererProps === undefined) {
|
|
209
195
|
return "Loading...";
|
|
210
196
|
}
|
|
211
|
-
|
|
197
|
+
|
|
198
|
+
return <StrataKitTreeRenderer {...treeProps.treeRendererProps} treeLabel="My Tree" />;
|
|
212
199
|
}
|
|
213
200
|
```
|
|
214
201
|
|
|
@@ -217,12 +204,8 @@ function MyTreeComponentInternal({ imodelAccess, selectionStorage }: { imodelAcc
|
|
|
217
204
|
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`:
|
|
218
205
|
|
|
219
206
|
```tsx
|
|
220
|
-
import {
|
|
221
|
-
|
|
222
|
-
LOCALIZATION_NAMESPACES,
|
|
223
|
-
StrataKitTreeRenderer,
|
|
224
|
-
useIModelUnifiedSelectionTree,
|
|
225
|
-
} from "@itwin/presentation-hierarchies-react";
|
|
207
|
+
import { LocalizationContextProvider, LOCALIZATION_NAMESPACES, useIModelUnifiedSelectionTree } from "@itwin/presentation-hierarchies-react";
|
|
208
|
+
import { StrataKitTreeRenderer } from "@itwin/presentation-hierarchies-react/stratakit";
|
|
226
209
|
|
|
227
210
|
// Register localization namespaces with `i18next` based localization provider.
|
|
228
211
|
for (const namespace of LOCALIZATION_NAMESPACES) {
|
|
@@ -239,15 +222,21 @@ function Tree() {
|
|
|
239
222
|
}
|
|
240
223
|
|
|
241
224
|
function MyTreeComponent({ imodelAccess }: { imodelAccess: IModelAccess }) {
|
|
242
|
-
const
|
|
225
|
+
const treeProps = useIModelUnifiedSelectionTree({
|
|
243
226
|
sourceName: "MyTreeComponent",
|
|
244
227
|
imodelAccess,
|
|
245
228
|
getHierarchyDefinition,
|
|
246
229
|
});
|
|
247
|
-
|
|
248
|
-
|
|
230
|
+
|
|
231
|
+
if (treeProps.rootErrorRendererProps) {
|
|
232
|
+
return <div>Error</div>;
|
|
249
233
|
}
|
|
250
|
-
|
|
234
|
+
|
|
235
|
+
if (treeProps.isReloading || treeProps.treeRendererProps === undefined) {
|
|
236
|
+
return <div>Loading...</div>;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return <StrataKitTreeRenderer {...treeProps.treeRendererProps} treeLabel="My Tree" />;
|
|
251
240
|
}
|
|
252
241
|
```
|
|
253
242
|
|
package/lib/presentation-hierarchies-react/{stratakit/FlatTreeNode.d.ts → FlatTreeNode.d.ts}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { TreeNode } from "
|
|
1
|
+
import { TreeNode } from "./TreeNode.js";
|
|
2
2
|
|
|
3
|
-
//#region src/presentation-hierarchies-react/
|
|
3
|
+
//#region src/presentation-hierarchies-react/FlatTreeNode.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Placeholder item that is added to hierarchy as a child for a parent item while its child items are loading.
|
|
6
6
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FlatTreeNode.d.ts","names":[],"sources":["../../src/presentation-hierarchies-react/FlatTreeNode.ts"],"mappings":";;;;;AAO8C;;;UAOpC,mBAAA;EACR,EAAA;EACA,KAAA;EACA,WAAA;AAAA;;AAQF;;;;UAAiB,gBAAA;EACf,EAAA;EACA,KAAA;EACA,SAAA;EACA,UAAA;EACA,IAAA,EAAM,QAAA;AAAA;;AASR;;;;;KAAY,YAAA,GAAe,gBAAA,GAAmB,mBAAA;;;;;;;AA8C9C;iBAhCgB,gBAAA,CAAiB,SAAA,EAAW,QAAA,KAAU,YAAA;;;;;;iBAgCtC,aAAA,CAAc,SAAA,EAAW,QAAA,KAAa,KAAA,CAAM,QAAA,GAAW,IAAA,CAAK,QAAA,CAAS,QAAA"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { c } from "react-compiler-runtime";
|
|
2
|
-
|
|
3
|
-
//#region src/presentation-hierarchies-react/stratakit/FlatTreeNode.ts
|
|
2
|
+
//#region src/presentation-hierarchies-react/FlatTreeNode.ts
|
|
4
3
|
/** @alpha */
|
|
5
4
|
function isPlaceholderItem(item) {
|
|
6
5
|
return "placeholder" in item;
|
|
@@ -88,7 +87,7 @@ function getErrorNodes(parent) {
|
|
|
88
87
|
function isErrorNode(node) {
|
|
89
88
|
return node.error !== void 0;
|
|
90
89
|
}
|
|
91
|
-
|
|
92
90
|
//#endregion
|
|
93
91
|
export { isPlaceholderItem, useErrorNodes, useFlatTreeItems };
|
|
92
|
+
|
|
94
93
|
//# sourceMappingURL=FlatTreeNode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FlatTreeNode.js","names":["useMemo","TreeNode","FlatPlaceholderItem","id","level","placeholder","FlatTreeNodeItem","levelSize","posInLevel","node","FlatTreeItem","isPlaceholderItem","item","useFlatTreeItems","rootNodes","$","_c","t0","getFlatItems","nodes","flatItems","forEach","index","push","length","isExpanded","error","type","isNodeExpandable","children","childNodes","useErrorNodes","flatMap","_temp","rootNode","errors","isErrorNode","getErrorNodes","parent","errorList","ReturnType","childErrorList","Pick","Required","undefined"],"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 { 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.error && (node.error.type !== \"Unknown\" || !node.error.isNodeExpandable)) {\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({ id: `${node.id}-children-placeholder`, level: level + 1, placeholder: true } 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[]): Array<TreeNode & Pick<Required<TreeNode>, \"error\">> {\n return useMemo(\n () =>\n rootNodes.flatMap((rootNode) => {\n const errors = isErrorNode(rootNode) ? [rootNode] : [];\n if (rootNode.children === true) {\n return errors;\n }\n\n if (errors.length === 1 && (rootNode.error?.type !== \"Unknown\" || !rootNode.error.isNodeExpandable)) {\n return errors;\n }\n errors.push(...getErrorNodes(rootNode));\n return errors;\n }),\n [rootNodes],\n );\n}\n\nfunction getErrorNodes(parent: TreeNode) {\n const errorList: ReturnType<typeof useErrorNodes> = [];\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.error.type !== \"Unknown\" || !node.error.isNodeExpandable) {\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): node is TreeNode & Pick<Required<TreeNode>, \"error\"> {\n return node.error !== undefined;\n}\n"],"mappings":";;;AA0CA,SAAgBW,kBAAkBC,MAAiD;AACjF,QAAO,iBAAiBA;;;;;;;;;AAU1B,SAAOC,iBAAAC,WAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAA,IAAAC;AAAA,KAAAF,EAAA,OAAAD,WAAA;AACgBG,OAAAC,aAAaJ,WAAW,EAAE;AAAAC,IAAA,KAAAD;AAAAC,IAAA,KAAAE;OAAAA,MAAAF,EAAA;AAAA,QAA1BE;;AAGvB,SAASC,aAAaC,OAAmBf,OAAe;CACtD,MAAMgB,YAA4B,EAAE;AACpCD,OAAME,SAASZ,MAAMa,UAAU;AAC7BF,YAAUG,KAAK;GAAEd;GAAMN,IAAIM,KAAKN;GAAIC;GAAOG,WAAWY,MAAMK;GAAQhB,YAAYc,QAAQ;GAAG,CAAC;AAC5F,MAAI,CAACb,KAAKgB,WACR;AAGF,MAAIhB,KAAKiB,UAAUjB,KAAKiB,MAAMC,SAAS,aAAa,CAAClB,KAAKiB,MAAME,kBAC9D;AAGF,MAAInB,KAAKoB,aAAa,MAAM;GAC1B,MAAMC,aAAaZ,aAAaT,KAAKoB,UAAUzB,QAAQ,EAAE;AACzDgB,aAAUG,KAAK,GAAGO,WAAW;AAC7B;;AAGFV,YAAUG,KAAK;GAAEpB,IAAI,GAAGM,KAAKN,GAAE;GAAyBC,OAAOA,QAAQ;GAAGC,aAAa;GAAM,CAA+B;GAC5H;AACF,QAAOe;;;;;;;AAQT,SAAOW,cAAAjB,WAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAA,IAAAC;AAAA,KAAAF,EAAA,OAAAD,WAAA;AAGDG,OAAAH,UAASkB,QAASC,MAWhB;AAAAlB,IAAA,KAAAD;AAAAC,IAAA,KAAAE;OAAAA,MAAAF,EAAA;AAAA,QAXFE;;AAHC,SAAAgB,MAAAC,UAAA;CAIC,MAAAC,SAAeC,YAAYF,SAA2B,GAAvC,CAAyBA,SAAc,GAAvC,EAAuC;AACtD,KAAIA,SAAQL,aAAc,KAAI,QACrBM;AAGT,KAAIA,OAAMX,WAAY,MAAMU,SAAQR,OAAYC,SAAK,aAAzB,CAAuCO,SAAQR,MAAME,kBAAkB,QAC1FO;AAETA,QAAMZ,KAAK,GAAIc,cAAcH,SAAS,CAAC;AAAA,QAChCC;;AAMf,SAASE,cAAcC,QAAkB;CACvC,MAAMC,YAA8C,EAAE;AAEtD,KAAID,OAAOT,aAAa,KACtB,QAAO,EAAE;AAGXS,QAAOT,SAASR,SAASZ,SAAS;AAChC,MAAI2B,YAAY3B,KAAK,EAAE;AACrB8B,aAAUhB,KAAKd,KAAK;AACpB,OAAIA,KAAKiB,MAAMC,SAAS,aAAa,CAAClB,KAAKiB,MAAME,iBAC/C;;AAIJ,MAAInB,KAAKoB,aAAa,MAAM;GAC1B,MAAMY,iBAAiBJ,cAAc5B,KAAK;AAC1C8B,aAAUhB,KAAK,GAAGkB,eAAe;AACjC;;GAEF;AACF,QAAOF;;AAGT,SAASH,YAAY3B,MAAsE;AACzF,QAAOA,KAAKiB,UAAUkB,KAAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { JSX, PropsWithChildren } from "react";
|
|
2
2
|
|
|
3
|
-
//#region src/presentation-hierarchies-react/
|
|
3
|
+
//#region src/presentation-hierarchies-react/LocalizationContext.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Properties for `LocalizationContextProvider`.
|
|
6
6
|
* @public
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalizationContext.d.ts","names":[],"sources":["../../src/presentation-hierarchies-react/LocalizationContext.tsx"],"mappings":";;;AAW0C;;;;AAAA,UAQhC,gCAAA;EAGN;EADF,YAAA;IACE,kBAAA,GAAqB,GAAA;EAAA;AAAA;;;;;iBAQT,2BAAA,CAAA;EAA8B,YAAA;EAAc;AAAA,GAAY,iBAAA,CAAkB,gCAAA,IAAoC,GAAA,CAAI,OAAA"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { LOCALIZATION_NAMESPACE } from "
|
|
1
|
+
import { LOCALIZATION_NAMESPACE } from "./internal/LocalizedStrings.js";
|
|
2
2
|
import { c } from "react-compiler-runtime";
|
|
3
3
|
import { createContext, useContext } from "react";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
5
|
-
|
|
6
|
-
//#region src/presentation-hierarchies-react/stratakit/LocalizationContext.tsx
|
|
5
|
+
//#region src/presentation-hierarchies-react/LocalizationContext.tsx
|
|
7
6
|
const localizationContext = createContext((key) => key);
|
|
8
7
|
/**
|
|
9
8
|
* Context provider for localizing components.
|
|
@@ -35,7 +34,7 @@ function LocalizationContextProvider(t0) {
|
|
|
35
34
|
function useTranslation() {
|
|
36
35
|
return useContext(localizationContext);
|
|
37
36
|
}
|
|
38
|
-
|
|
39
37
|
//#endregion
|
|
40
38
|
export { LocalizationContextProvider, useTranslation };
|
|
39
|
+
|
|
41
40
|
//# sourceMappingURL=LocalizationContext.js.map
|
|
@@ -0,0 +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: {\n getLocalizedString: (key: string) => string;\n };\n}\n\n/**\n * Context provider for localizing components.\n * @public\n */\nexport function LocalizationContextProvider({ localization, children }: 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,IAAI;;;;;AAiBtE,SAAOK,4BAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAqC,MAAA,EAAAL,cAAAM,aAAAH;CAA+E,IAAAI;AAAA,KAAAH,EAAA,OAAAJ,cAAA;AAEhHO,QAAAV,QAA0BG,aAAYC,mBAAoB,GAAGT,uBAAsB,GAAIK,MAAM;AAAAO,IAAA,KAAAJ;AAAAI,IAAA,KAAAG;OAAAA,MAAAH,EAAA;CADtG,MAAAI,YACED;CACiB,IAAAE;AAAA,KAAAL,EAAA,OAAAE,YAAAF,EAAA,OAAAI,WAAA;AACZC,OAAA,oBAAA,oBAAA,UAAA;GAAqCD,OAAAA;GAAYF;GAAwC,CAAA;AAAAF,IAAA,KAAAE;AAAAF,IAAA,KAAAI;AAAAJ,IAAA,KAAAK;OAAAA,MAAAL,EAAA;AAAA,QAAzFK;;;AAIT,SAAOC,iBAAA;AAAA,QACEpB,WAAWQ,oBAAoB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UseUnifiedTreeSelectionProps } from "./internal/UseUnifiedSelection.js";
|
|
2
2
|
import { UseTreeProps, UseTreeResult } from "./UseTree.js";
|
|
3
|
-
import { HierarchyDefinition,
|
|
3
|
+
import { HierarchyDefinition, HierarchySearchTree, createIModelHierarchyProvider } from "@itwin/presentation-hierarchies";
|
|
4
4
|
import { Props } from "@itwin/presentation-shared";
|
|
5
5
|
|
|
6
6
|
//#region src/presentation-hierarchies-react/UseIModelTree.d.ts
|
|
@@ -31,7 +31,7 @@ type UseIModelTreeProps = Omit<UseTreeProps, "getHierarchyProvider" | "getSearch
|
|
|
31
31
|
* Signal indicating that that the request was canceled
|
|
32
32
|
*/
|
|
33
33
|
abortSignal: AbortSignal;
|
|
34
|
-
}) => Promise<
|
|
34
|
+
}) => Promise<HierarchySearchTree[] | undefined>;
|
|
35
35
|
};
|
|
36
36
|
/**
|
|
37
37
|
* A React hook that creates state for a tree component whose displayed hierarchy is based on
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { useTree, useUnifiedSelectionTree } from "./UseTree.js";
|
|
2
|
-
import { useTranslation } from "./
|
|
2
|
+
import { useTranslation } from "./LocalizationContext.js";
|
|
3
3
|
import { c } from "react-compiler-runtime";
|
|
4
4
|
import { createIModelHierarchyProvider } from "@itwin/presentation-hierarchies";
|
|
5
|
-
|
|
6
5
|
//#region src/presentation-hierarchies-react/UseIModelTree.ts
|
|
7
6
|
/**
|
|
8
7
|
* A React hook that creates state for a tree component whose displayed hierarchy is based on
|
|
@@ -178,7 +177,7 @@ function useIModelTreeProps(props) {
|
|
|
178
177
|
} else t4 = $[10];
|
|
179
178
|
return t4;
|
|
180
179
|
}
|
|
181
|
-
|
|
182
180
|
//#endregion
|
|
183
181
|
export { useIModelTree, useIModelUnifiedSelectionTree };
|
|
182
|
+
|
|
184
183
|
//# sourceMappingURL=UseIModelTree.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseIModelTree.js","names":["useCallback","createIModelHierarchyProvider","useTranslation","useTree","useUnifiedSelectionTree","HierarchyDefinition","
|
|
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: {\n other: translate(\"other\"),\n unspecified: translate(\"unspecified\"),\n },\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":"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"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { c } from "react-compiler-runtime";
|
|
2
2
|
import { HierarchyNode } from "@itwin/presentation-hierarchies";
|
|
3
3
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
4
|
-
|
|
5
4
|
//#region src/presentation-hierarchies-react/UseNodeHighlighting.tsx
|
|
6
5
|
/**
|
|
7
6
|
* A react hook that helps create highlighted node labels based on provided highlight.
|
|
@@ -52,7 +51,7 @@ function useNodeHighlighting(t0) {
|
|
|
52
51
|
} else t2 = $[3];
|
|
53
52
|
return t2;
|
|
54
53
|
}
|
|
55
|
-
|
|
56
54
|
//#endregion
|
|
57
55
|
export { useNodeHighlighting };
|
|
56
|
+
|
|
58
57
|
//# sourceMappingURL=UseNodeHighlighting.js.map
|
|
@@ -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(<span key={`normal-${matchedIndexes.length + 1}`}>{node.label.substring(lastAddedPosition)}</span>);\n }\n\n return <>{finalLabel}</>;\n },\n [highlightText],\n );\n\n return { getLabel };\n}\n"],"mappings":"
|
|
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(<span key={`normal-${matchedIndexes.length + 1}`}>{node.label.substring(lastAddedPosition)}</span>);\n }\n\n return <>{finalLabel}</>;\n },\n [highlightText],\n );\n\n return { getLabel };\n}\n"],"mappings":";;;;;;;;AAiCA,SAAOU,oBAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAA6B,MAAA,EAAAP,kBAAAK;CAA2C,IAAAG;AAAA,KAAAF,EAAA,OAAAN,eAAA;AAE3EQ,QAAAL,SAAA;AACE,OAAI,CAACH,iBAAiBL,cAAac,eAAgBN,KAAIO,SAAmD,IAAtG,CAAkEP,KAAIO,SAASC,QAAuBC,eAAA,QACjG,oBAAA,QAAA,EAAA,UAAOT,KAAIU,OAAc,CAAA;GAGlC,MAAAC,iBAAuB,IAAIC,OAAe;GAC1C,MAAAC,YAAkBb,KAAIU,MAAMI,mBAAoB;GAChD,MAAAC,aAAmBlB,cAAaiB,mBAAoB;GACpD,IAAAE,eAAmB;AAEnB,UAAO,MAAI;IACT,MAAAC,aAAmBJ,UAASK,QAASH,YAAYC,aAAa;AAC9D,QAAIC,eAAe,GACjB;AAEFN,mBAAcQ,KAAMF,WAAW;AAC/BD,mBAAeC,aAAaF,WAAUK;;AAGxC,OAAIT,eAAcS,WAAY,EAAC,QACtB,oBAAA,QAAA,EAAA,UAAOpB,KAAIU,OAAc,CAAA;GAIlC,MAAAW,aAAmB,IAAIT,OAAoB;GAC3C,IAAAU,oBAAwB;AACxB,QAAA,IAAAC,IAAa,GAAGA,IAAIZ,eAAcS,QAAS,EAAEG,GAAC;IAC5C,MAAAC,eAAqBb,eAAeY;AACpC,QAAIC,eAAeF,mBAAiB;AAClCD,gBAAUF,KAAM,oBAAA,QAAA,EAAA,UAA2BnB,KAAIU,MAAMe,UAAWH,mBAAmBE,aAAY,EAAS,EAA7E,UAAUD,IAAmE,CAAC;AACzGD,yBAAoBE;;IAEtB,MAAAE,cAAoBF,eAAe3B,cAAauB;AAChDC,eAAUF,KAAM,oBAAA,QAAA,EAAA,UAA2BnB,KAAIU,MAAMe,UAAWH,mBAAmBI,YAAW,EAAS,EAA5E,UAAUH,IAAkE,CAAC;AACxGD,wBAAoBI;;AAEtB,OAAIJ,oBAAoBtB,KAAIU,MAAMU,OAChCC,YAAUF,KAAM,oBAAA,QAAA,EAAA,UAAmDnB,KAAIU,MAAMe,UAAWH,kBAAiB,EAAS,EAAvF,UAAUX,eAAcS,SAAU,IAAqD,CAAC;AACpH,UAEM,oBAAA,UAAA,EAAA,UAAGC,YAAc,CAAA;;AACzBlB,IAAA,KAAAN;AAAAM,IAAA,KAAAE;OAAAA,MAAAF,EAAA;CA1CH,MAAAJ,WAAiBM;CA4Cf,IAAAsB;AAAA,KAAAxB,EAAA,OAAAJ,UAAA;AAEK4B,OAAA,EAAA5B,UAAY;AAAAI,IAAA,KAAAJ;AAAAI,IAAA,KAAAwB;OAAAA,MAAAxB,EAAA;AAAA,QAAZwB"}
|
|
@@ -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":";;;AAmBA;;;;;AAUA;;KAVY,aAAA;;;;;;;;;KAUA,mBAAA"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { c } from "react-compiler-runtime";
|
|
2
2
|
import { useEffect, useRef } from "react";
|
|
3
|
-
|
|
4
3
|
//#region src/presentation-hierarchies-react/UseSelectionHandler.ts
|
|
5
4
|
/**
|
|
6
5
|
* A react hook that helps implement different selection modes in a tree component created using `useTree` hook.
|
|
@@ -119,7 +118,7 @@ function computeFlatNodeList(rootNodes) {
|
|
|
119
118
|
nodeIdToIndexMap
|
|
120
119
|
};
|
|
121
120
|
}
|
|
122
|
-
|
|
123
121
|
//#endregion
|
|
124
122
|
export { useSelectionHandler };
|
|
123
|
+
|
|
125
124
|
//# sourceMappingURL=UseSelectionHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseSelectionHandler.js","names":["useCallback","useEffect","useRef","TreeRendererProps","TreeNode","SelectionMode","SelectionChangeType","UseSelectionHandlerProps","Pick","selectionMode","UseSelectionHandlerResult","handleNodeSelect","props","nodeId","isSelected","shiftDown","ctrlDown","FlatTreeState","flatNodeList","Array","nodeIdToIndexMap","Map","useSelectionHandler","$","_c","rootNodes","selectNodes","previousSelectionRef","undefined","t0","Symbol","for","state","t1","t2","current","computeFlatNodeList","t3","firstId","secondId","getIndex","get","firstIndex","secondIndex","startingIndex","Math","min","endIndex","max","slice","getNodeRange","t4","t5","nodeId_0","selection","getSelectionAction","type","nodes","select","length","SelectionAction","getExtendedSelectionAction","flattenNodeRecursively","forEach","node","set","id","push","isExpanded","children"],"sources":["../../src/presentation-hierarchies-react/UseSelectionHandler.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, useEffect, useRef } from \"react\";\n\nimport type { TreeRendererProps } from \"./Renderers.js\";\nimport type { TreeNode } from \"./TreeNode.js\";\n\n/**\n * A union of different supported selection modes in a tree component:\n * - `none` - no selection is allowed,\n * - `single` - only one node can be selected at a time,\n * - `extended` - multiple nodes can be selected using shift and ctrl keys,\n * - `multiple` - multiple nodes can be selected without using shift or ctrl keys.\n *\n * @public\n */\nexport type SelectionMode = \"none\" | \"single\" | \"extended\" | \"multiple\";\n\n/**\n * Type of selection change.\n * - `add` - a node was added to the selection,\n * - `replace` - a selected node was replaced with a different one,\n * - `remove` - a node was removed from the selection.\n *\n * @public\n */\nexport type SelectionChangeType = \"add\" | \"replace\" | \"remove\";\n\n/**\n * Props for `useSelectionHandler` hook.\n * @alpha\n */\ntype UseSelectionHandlerProps = Pick<TreeRendererProps, \"selectNodes\" | \"rootNodes\"> & {\n /**\n * Selection mode that the component is working in.\n */\n selectionMode: SelectionMode;\n};\n\n/**\n * Result of `useSelectionHandler` hook.\n * @internal\n */\ninterface UseSelectionHandlerResult {\n /** Updates nodes selection based on current node state and modifier keys used. */\n handleNodeSelect: (props: { nodeId: string; isSelected: boolean; shiftDown: boolean; ctrlDown: boolean }) => void;\n}\n\ninterface FlatTreeState {\n flatNodeList: Array<string>;\n nodeIdToIndexMap: Map<string, number>;\n}\n\n/**\n * A react hook that helps implement different selection modes in a tree component created using `useTree` hook.\n * @internal\n */\nexport function useSelectionHandler(props: UseSelectionHandlerProps): UseSelectionHandlerResult {\n const { rootNodes, selectionMode, selectNodes } = props;\n const previousSelectionRef = useRef<string | undefined>(undefined);\n const state = useRef<FlatTreeState>({\n flatNodeList: [],\n nodeIdToIndexMap: new Map(),\n });\n\n useEffect(() => {\n state.current = computeFlatNodeList(rootNodes);\n }, [rootNodes]);\n\n const getNodeRange = (firstId?: string, secondId?: string) => {\n const getIndex = (nodeId?: string) => {\n return nodeId ? state.current.nodeIdToIndexMap.get(nodeId) : 0;\n };\n const firstIndex = getIndex(firstId);\n const secondIndex = getIndex(secondId);\n if (firstIndex === undefined || secondIndex === undefined) {\n return [];\n }\n\n const startingIndex = Math.min(firstIndex, secondIndex);\n const endIndex = Math.max(firstIndex, secondIndex);\n return state.current.flatNodeList.slice(startingIndex, endIndex + 1);\n };\n\n const handleNodeSelect = useCallback<UseSelectionHandlerResult[\"handleNodeSelect\"]>(\n ({ nodeId, isSelected, shiftDown, ctrlDown }) => {\n const selection = getSelectionAction(selectionMode, isSelected, shiftDown, ctrlDown);\n if (selection.type === \"disabled\") {\n return;\n }\n\n const nodes = selection.select === \"range\" ? getNodeRange(previousSelectionRef.current, nodeId) : [nodeId];\n if (!nodes.length) {\n return;\n }\n\n selection.select !== \"range\" && (previousSelectionRef.current = nodeId);\n selectNodes(nodes, selection.type);\n },\n [selectionMode, selectNodes],\n );\n\n return { handleNodeSelect };\n}\n\ninterface SelectionAction {\n select: \"node\" | \"range\";\n type: SelectionChangeType | \"disabled\";\n}\n\nfunction getSelectionAction(selectionMode: SelectionMode, isSelected: boolean, shiftDown: boolean, ctrlDown: boolean): SelectionAction {\n switch (selectionMode) {\n case \"none\":\n return { select: \"node\", type: \"disabled\" };\n case \"single\":\n return { select: \"node\", type: isSelected ? \"remove\" : \"replace\" };\n case \"multiple\":\n return { select: \"node\", type: isSelected ? \"remove\" : \"add\" };\n case \"extended\":\n return getExtendedSelectionAction(isSelected, shiftDown, ctrlDown);\n }\n}\n\nfunction getExtendedSelectionAction(isSelected: boolean, shiftDown: boolean, ctrlDown: boolean): SelectionAction {\n if (shiftDown) {\n return { select: \"range\", type: \"replace\" };\n }\n if (ctrlDown) {\n return { select: \"node\", type: isSelected ? \"remove\" : \"add\" };\n }\n return { select: \"node\", type: \"replace\" };\n}\n\nfunction computeFlatNodeList(rootNodes: Array<TreeNode>): FlatTreeState {\n const flatNodeList: Array<string> = [];\n const nodeIdToIndexMap: Map<string, number> = new Map();\n\n const flattenNodeRecursively = (nodes: Array<TreeNode>) => {\n nodes.forEach((node) => {\n nodeIdToIndexMap.set(node.id, flatNodeList.length);\n flatNodeList.push(node.id);\n if (node.isExpanded && typeof node.children !== \"boolean\") {\n flattenNodeRecursively(node.children);\n }\n });\n };\n\n flattenNodeRecursively(rootNodes);\n return { flatNodeList, nodeIdToIndexMap };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"UseSelectionHandler.js","names":["useCallback","useEffect","useRef","TreeRendererProps","TreeNode","SelectionMode","SelectionChangeType","UseSelectionHandlerProps","Pick","selectionMode","UseSelectionHandlerResult","handleNodeSelect","props","nodeId","isSelected","shiftDown","ctrlDown","FlatTreeState","flatNodeList","Array","nodeIdToIndexMap","Map","useSelectionHandler","$","_c","rootNodes","selectNodes","previousSelectionRef","undefined","t0","Symbol","for","state","t1","t2","current","computeFlatNodeList","t3","firstId","secondId","getIndex","get","firstIndex","secondIndex","startingIndex","Math","min","endIndex","max","slice","getNodeRange","t4","t5","nodeId_0","selection","getSelectionAction","type","nodes","select","length","SelectionAction","getExtendedSelectionAction","flattenNodeRecursively","forEach","node","set","id","push","isExpanded","children"],"sources":["../../src/presentation-hierarchies-react/UseSelectionHandler.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, useEffect, useRef } from \"react\";\n\nimport type { TreeRendererProps } from \"./Renderers.js\";\nimport type { TreeNode } from \"./TreeNode.js\";\n\n/**\n * A union of different supported selection modes in a tree component:\n * - `none` - no selection is allowed,\n * - `single` - only one node can be selected at a time,\n * - `extended` - multiple nodes can be selected using shift and ctrl keys,\n * - `multiple` - multiple nodes can be selected without using shift or ctrl keys.\n *\n * @public\n */\nexport type SelectionMode = \"none\" | \"single\" | \"extended\" | \"multiple\";\n\n/**\n * Type of selection change.\n * - `add` - a node was added to the selection,\n * - `replace` - a selected node was replaced with a different one,\n * - `remove` - a node was removed from the selection.\n *\n * @public\n */\nexport type SelectionChangeType = \"add\" | \"replace\" | \"remove\";\n\n/**\n * Props for `useSelectionHandler` hook.\n * @alpha\n */\ntype UseSelectionHandlerProps = Pick<TreeRendererProps, \"selectNodes\" | \"rootNodes\"> & {\n /**\n * Selection mode that the component is working in.\n */\n selectionMode: SelectionMode;\n};\n\n/**\n * Result of `useSelectionHandler` hook.\n * @internal\n */\ninterface UseSelectionHandlerResult {\n /** Updates nodes selection based on current node state and modifier keys used. */\n handleNodeSelect: (props: { nodeId: string; isSelected: boolean; shiftDown: boolean; ctrlDown: boolean }) => void;\n}\n\ninterface FlatTreeState {\n flatNodeList: Array<string>;\n nodeIdToIndexMap: Map<string, number>;\n}\n\n/**\n * A react hook that helps implement different selection modes in a tree component created using `useTree` hook.\n * @internal\n */\nexport function useSelectionHandler(props: UseSelectionHandlerProps): UseSelectionHandlerResult {\n const { rootNodes, selectionMode, selectNodes } = props;\n const previousSelectionRef = useRef<string | undefined>(undefined);\n const state = useRef<FlatTreeState>({\n flatNodeList: [],\n nodeIdToIndexMap: new Map(),\n });\n\n useEffect(() => {\n state.current = computeFlatNodeList(rootNodes);\n }, [rootNodes]);\n\n const getNodeRange = (firstId?: string, secondId?: string) => {\n const getIndex = (nodeId?: string) => {\n return nodeId ? state.current.nodeIdToIndexMap.get(nodeId) : 0;\n };\n const firstIndex = getIndex(firstId);\n const secondIndex = getIndex(secondId);\n if (firstIndex === undefined || secondIndex === undefined) {\n return [];\n }\n\n const startingIndex = Math.min(firstIndex, secondIndex);\n const endIndex = Math.max(firstIndex, secondIndex);\n return state.current.flatNodeList.slice(startingIndex, endIndex + 1);\n };\n\n const handleNodeSelect = useCallback<UseSelectionHandlerResult[\"handleNodeSelect\"]>(\n ({ nodeId, isSelected, shiftDown, ctrlDown }) => {\n const selection = getSelectionAction(selectionMode, isSelected, shiftDown, ctrlDown);\n if (selection.type === \"disabled\") {\n return;\n }\n\n const nodes = selection.select === \"range\" ? getNodeRange(previousSelectionRef.current, nodeId) : [nodeId];\n if (!nodes.length) {\n return;\n }\n\n selection.select !== \"range\" && (previousSelectionRef.current = nodeId);\n selectNodes(nodes, selection.type);\n },\n [selectionMode, selectNodes],\n );\n\n return { handleNodeSelect };\n}\n\ninterface SelectionAction {\n select: \"node\" | \"range\";\n type: SelectionChangeType | \"disabled\";\n}\n\nfunction getSelectionAction(selectionMode: SelectionMode, isSelected: boolean, shiftDown: boolean, ctrlDown: boolean): SelectionAction {\n switch (selectionMode) {\n case \"none\":\n return { select: \"node\", type: \"disabled\" };\n case \"single\":\n return { select: \"node\", type: isSelected ? \"remove\" : \"replace\" };\n case \"multiple\":\n return { select: \"node\", type: isSelected ? \"remove\" : \"add\" };\n case \"extended\":\n return getExtendedSelectionAction(isSelected, shiftDown, ctrlDown);\n }\n}\n\nfunction getExtendedSelectionAction(isSelected: boolean, shiftDown: boolean, ctrlDown: boolean): SelectionAction {\n if (shiftDown) {\n return { select: \"range\", type: \"replace\" };\n }\n if (ctrlDown) {\n return { select: \"node\", type: isSelected ? \"remove\" : \"add\" };\n }\n return { select: \"node\", type: \"replace\" };\n}\n\nfunction computeFlatNodeList(rootNodes: Array<TreeNode>): FlatTreeState {\n const flatNodeList: Array<string> = [];\n const nodeIdToIndexMap: Map<string, number> = new Map();\n\n const flattenNodeRecursively = (nodes: Array<TreeNode>) => {\n nodes.forEach((node) => {\n nodeIdToIndexMap.set(node.id, flatNodeList.length);\n flatNodeList.push(node.id);\n if (node.isExpanded && typeof node.children !== \"boolean\") {\n flattenNodeRecursively(node.children);\n }\n });\n };\n\n flattenNodeRecursively(rootNodes);\n return { flatNodeList, nodeIdToIndexMap };\n}\n"],"mappings":"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"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ErrorInfo, TreeNode } from "./TreeNode.js";
|
|
2
2
|
import { RootErrorRendererProps, TreeRendererProps } from "./Renderers.js";
|
|
3
3
|
import { UseUnifiedTreeSelectionProps } from "./internal/UseUnifiedSelection.js";
|
|
4
|
-
import { GenericInstanceFilter, HierarchyNode, HierarchyProvider,
|
|
4
|
+
import { GenericInstanceFilter, HierarchyNode, HierarchyProvider, HierarchySearchTree } from "@itwin/presentation-hierarchies";
|
|
5
5
|
import { IPrimitiveValueFormatter } from "@itwin/presentation-shared";
|
|
6
6
|
|
|
7
7
|
//#region src/presentation-hierarchies-react/UseTree.d.ts
|
|
@@ -48,7 +48,7 @@ interface UseTreeProps {
|
|
|
48
48
|
abortSignal
|
|
49
49
|
}: {
|
|
50
50
|
abortSignal: AbortSignal;
|
|
51
|
-
}) => Promise<
|
|
51
|
+
}) => Promise<HierarchySearchTree[] | undefined>;
|
|
52
52
|
/**
|
|
53
53
|
* Callback that is called just after a certain action is finished.
|
|
54
54
|
* Can be used for performance tracking.
|
|
@@ -6,7 +6,6 @@ import { useLatest } from "./Utils.js";
|
|
|
6
6
|
import { c } from "react-compiler-runtime";
|
|
7
7
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
8
8
|
import { HierarchyNode } from "@itwin/presentation-hierarchies";
|
|
9
|
-
|
|
10
9
|
//#region src/presentation-hierarchies-react/UseTree.ts
|
|
11
10
|
/**
|
|
12
11
|
* A React hook that creates state for a tree component.
|
|
@@ -292,7 +291,7 @@ function createTreeNode(modelNode, model, getTreeNodeError) {
|
|
|
292
291
|
}
|
|
293
292
|
};
|
|
294
293
|
}
|
|
295
|
-
|
|
296
294
|
//#endregion
|
|
297
295
|
export { useTree, useUnifiedSelectionTree };
|
|
296
|
+
|
|
298
297
|
//# sourceMappingURL=UseTree.js.map
|