@itwin/presentation-hierarchies-react 2.0.0-alpha.5 → 2.0.0-alpha.51
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 +902 -7
- package/README.md +28 -70
- package/lib/esm/presentation-hierarchies-react/Renderers.d.ts +85 -0
- package/lib/esm/presentation-hierarchies-react/Renderers.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/Renderers.js +6 -0
- package/lib/esm/presentation-hierarchies-react/Renderers.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/TreeNode.d.ts +28 -29
- package/lib/esm/presentation-hierarchies-react/TreeNode.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/TreeNode.js +1 -7
- package/lib/esm/presentation-hierarchies-react/TreeNode.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.d.ts +7 -5
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.js +6 -6
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.d.ts +24 -0
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.js +53 -0
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.d.ts +12 -10
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.js +7 -22
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.d.ts +33 -71
- package/lib/esm/presentation-hierarchies-react/UseTree.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.js +63 -64
- package/lib/esm/presentation-hierarchies-react/UseTree.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/Utils.d.ts +8 -0
- package/lib/esm/presentation-hierarchies-react/Utils.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/Utils.js +39 -0
- package/lib/esm/presentation-hierarchies-react/Utils.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.d.ts +2 -2
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.js +31 -16
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.d.ts +24 -6
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.js +29 -33
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.d.ts +6 -29
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.js +31 -27
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts +23 -9
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.js +16 -29
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/Utils.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/Utils.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts +27 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js +74 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts +48 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.js +73 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts +133 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/{itwinui → stratakit}/LocalizationContext.js +17 -5
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts +16 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.js +42 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeAction.d.ts +45 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeAction.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeAction.js +36 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeAction.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts +30 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js +30 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.d.ts +20 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.js +29 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.d.ts +57 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js +71 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.css +25 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts +46 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js +132 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts +75 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js +193 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react.d.ts +14 -10
- package/lib/esm/presentation-hierarchies-react.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react.js +11 -9
- package/lib/esm/presentation-hierarchies-react.js.map +1 -1
- package/package.json +55 -47
- package/lib/esm/presentation-hierarchies-react/UnifiedSelectionContext.d.ts +0 -15
- package/lib/esm/presentation-hierarchies-react/UnifiedSelectionContext.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/UnifiedSelectionContext.js +0 -22
- package/lib/esm/presentation-hierarchies-react/UnifiedSelectionContext.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.d.ts +0 -21
- package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.js +0 -30
- package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.d.ts +0 -73
- package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.d.ts +0 -25
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.js +0 -40
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.d.ts +0 -23
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.js +0 -72
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.d.ts +0 -40
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js +0 -80
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.d.ts +0 -30
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.js +0 -48
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.js.map +0 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Copyright © Bentley Systems, Incorporated. All rights reserved. See LICENSE.md for license terms and full copyright notice.
|
|
4
4
|
|
|
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 [
|
|
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
7
|
## Headless UI
|
|
8
8
|
|
|
@@ -19,10 +19,7 @@ All these hooks return the same state object, which contains properties and func
|
|
|
19
19
|
|
|
20
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
21
|
|
|
22
|
-
- `rootNodes` is an array of
|
|
23
|
-
|
|
24
|
-
- A `PresentationHierarchyNode` is the primary type of node, created based on the hierarchy definition. The `isPresentationHierarchyNode` type guard utility may be used to check if a node is of this type.
|
|
25
|
-
- A `PresentationInfoNode` is a non-expandable, non-selectable informational type of node, generally created when for some reason we don't have any real nodes to show. There may be different reasons like filtered-out nodes, too large result set, a network error, etc. The `type` attribute of the node indicates that.
|
|
22
|
+
- `rootNodes` is an array of `TreeNode` and is what the component should render.
|
|
26
23
|
|
|
27
24
|
- `expandNode` function to expand or collapse a node.
|
|
28
25
|
|
|
@@ -31,7 +28,6 @@ All these hooks return the same state object, which contains properties and func
|
|
|
31
28
|
- `getNode` function to get node by its id.
|
|
32
29
|
|
|
33
30
|
- `getHierarchyLevelDetails` function to access details of a specific hierarchy level. The returned object provides access to:
|
|
34
|
-
|
|
35
31
|
- hierarchy level size limit,
|
|
36
32
|
- hierarchy level instance filter,
|
|
37
33
|
- instance keys of the nodes in the hierarchy level.
|
|
@@ -61,31 +57,12 @@ The hook takes 2 required properties:
|
|
|
61
57
|
|
|
62
58
|
```tsx
|
|
63
59
|
import { IModelConnection } from "@itwin/core-frontend";
|
|
64
|
-
import { SchemaContext } from "@itwin/ecschema-metadata";
|
|
65
|
-
import { ECSchemaRpcLocater } from "@itwin/ecschema-rpcinterface-common";
|
|
66
60
|
import { createCachingECClassHierarchyInspector } from "@itwin/presentation-shared";
|
|
67
61
|
import { createECSchemaProvider, createECSqlQueryExecutor, createIModelKey } from "@itwin/presentation-core-interop";
|
|
68
62
|
import { createLimitingECSqlQueryExecutor, createNodesQueryClauseFactory, HierarchyDefinition } from "@itwin/presentation-hierarchies";
|
|
69
63
|
|
|
70
|
-
// Not really part of the package, but we need SchemaContext to create the tree state. It's
|
|
71
|
-
// recommended to cache the schema context and reuse it across different application's components to
|
|
72
|
-
// avoid loading and storing same schemas multiple times.
|
|
73
|
-
const imodelSchemaContextsCache = new Map<string, SchemaContext>();
|
|
74
|
-
|
|
75
|
-
function getIModelSchemaContext(imodel: IModelConnection) {
|
|
76
|
-
const imodelKey = createIModelKey(imodel);
|
|
77
|
-
let context = imodelSchemaContextsCache.get(imodelKey);
|
|
78
|
-
if (!context) {
|
|
79
|
-
context = new SchemaContext();
|
|
80
|
-
context.addLocater(new ECSchemaRpcLocater(imodel.getRpcProps()));
|
|
81
|
-
imodelSchemaContextsCache.set(imodelKey, context);
|
|
82
|
-
imodel.onClose.addListener(() => imodelSchemaContextsCache.delete(imodelKey));
|
|
83
|
-
}
|
|
84
|
-
return context;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
64
|
function createIModelAccess(imodel: IModelConnection) {
|
|
88
|
-
const schemaProvider = createECSchemaProvider(
|
|
65
|
+
const schemaProvider = createECSchemaProvider(imodel.schemaContext);
|
|
89
66
|
return {
|
|
90
67
|
imodelKey: createIModelKey(imodel),
|
|
91
68
|
...schemaProvider,
|
|
@@ -125,21 +102,18 @@ The returned object contains 2 functions, that should be called by the node rend
|
|
|
125
102
|
|
|
126
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.
|
|
127
104
|
|
|
128
|
-
##
|
|
105
|
+
## StrataKit components
|
|
129
106
|
|
|
130
|
-
While the package provides a headless UI, it also delivers a set of [
|
|
107
|
+
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.
|
|
131
108
|
|
|
132
109
|
### `TreeRenderer`
|
|
133
110
|
|
|
134
|
-
The component is based on
|
|
135
|
-
|
|
136
|
-
The iTwinUI Tree component requires a `getNode` function that maps nodes to `NodeData<TNode>` objects. Our `TreeRenderer` uses `createRenderedTreeNodeData` function for this purpose, and it's available for consumers as well, in case a custom iTwinUI Tree component implementation is being written.
|
|
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.
|
|
137
112
|
|
|
138
113
|
### `TreeNodeRenderer`
|
|
139
114
|
|
|
140
|
-
The component is based on `
|
|
115
|
+
The component is based on `Tree.Item` component from StrataKit library and supports the following features:
|
|
141
116
|
|
|
142
|
-
- Rendering informational type of nodes (e.g. "No filter matches", "Too many nodes in a hierarchy level", etc.).
|
|
143
117
|
- Reporting click and key down events for use with [`useSelectionHandler` hook](#useselectionhandler-hook).
|
|
144
118
|
- Icons, selection, expand / collapse.
|
|
145
119
|
- Action buttons to clear / set hierarchy level instance filter.
|
|
@@ -148,8 +122,6 @@ The component is based on `TreeNode` component from iTwinUI library and supports
|
|
|
148
122
|
|
|
149
123
|
```tsx
|
|
150
124
|
import { IModelConnection } from "@itwin/core-frontend";
|
|
151
|
-
import { SchemaContext } from "@itwin/ecschema-metadata";
|
|
152
|
-
import { ECSchemaRpcLocater } from "@itwin/ecschema-rpcinterface-common";
|
|
153
125
|
import { createCachingECClassHierarchyInspector } from "@itwin/presentation-shared";
|
|
154
126
|
import { createECSchemaProvider, createECSqlQueryExecutor, createIModelKey } from "@itwin/presentation-core-interop";
|
|
155
127
|
import { createLimitingECSqlQueryExecutor, createNodesQueryClauseFactory, HierarchyDefinition } from "@itwin/presentation-hierarchies";
|
|
@@ -160,25 +132,8 @@ import { TreeRenderer, useIModelUnifiedSelectionTree } from "@itwin/presentation
|
|
|
160
132
|
import { createStorage, SelectionStorage } from "@itwin/unified-selection";
|
|
161
133
|
import { useEffect, useState } from "react";
|
|
162
134
|
|
|
163
|
-
// Not really part of the package, but we need SchemaContext to create the tree state. It's
|
|
164
|
-
// recommended to cache the schema context and reuse it across different application's components to
|
|
165
|
-
// avoid loading and storing same schemas multiple times.
|
|
166
|
-
const imodelSchemaContextsCache = new Map<string, SchemaContext>();
|
|
167
|
-
|
|
168
|
-
function getIModelSchemaContext(imodel: IModelConnection) {
|
|
169
|
-
const imodelKey = createIModelKey(imodel);
|
|
170
|
-
let context = imodelSchemaContextsCache.get(imodelKey);
|
|
171
|
-
if (!context) {
|
|
172
|
-
context = new SchemaContext();
|
|
173
|
-
context.addLocater(new ECSchemaRpcLocater(imodel.getRpcProps()));
|
|
174
|
-
imodelSchemaContextsCache.set(imodelKey, context);
|
|
175
|
-
imodel.onClose.addListener(() => imodelSchemaContextsCache.delete(imodelKey));
|
|
176
|
-
}
|
|
177
|
-
return context;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
135
|
function createIModelAccess(imodel: IModelConnection) {
|
|
181
|
-
const schemaProvider = createECSchemaProvider(
|
|
136
|
+
const schemaProvider = createECSchemaProvider(imodel.schemaContext);
|
|
182
137
|
return {
|
|
183
138
|
imodelKey: createIModelKey(imodel),
|
|
184
139
|
...schemaProvider,
|
|
@@ -275,7 +230,7 @@ const localizedStrings = {
|
|
|
275
230
|
unspecified: "Unspecified",
|
|
276
231
|
other: "Other",
|
|
277
232
|
|
|
278
|
-
// strings for `TreeRenderer` and `
|
|
233
|
+
// strings for `TreeRenderer` and `TreeNodeRenderer`
|
|
279
234
|
loading: "Loading...",
|
|
280
235
|
filterHierarchyLevel: "Apply hierarchy filter",
|
|
281
236
|
clearHierarchyLevelFilter: "Clear active filter",
|
|
@@ -306,28 +261,31 @@ In case the `TreeNodeRenderer` component is used within a custom tree renderer,
|
|
|
306
261
|
import { Props } from "@itwin/presentation-shared";
|
|
307
262
|
|
|
308
263
|
import { ComponentPropsWithoutRef, useCallback } from "react";
|
|
309
|
-
import { Tree } from "@
|
|
310
|
-
import {
|
|
311
|
-
|
|
312
|
-
LocalizationContextProvider,
|
|
313
|
-
RenderedTreeNode,
|
|
314
|
-
TreeNodeRenderer,
|
|
315
|
-
TreeRenderer,
|
|
316
|
-
} from "@itwin/presentation-hierarchies-react";
|
|
317
|
-
|
|
318
|
-
type TreeProps = ComponentPropsWithoutRef<typeof Tree<RenderedTreeNode>>;
|
|
264
|
+
import { Tree } from "@stratakit/bricks";
|
|
265
|
+
import { LocalizationContextProvider, TreeRenderer, useFlatTreeNodeList } from "@itwin/presentation-hierarchies-react";
|
|
266
|
+
|
|
319
267
|
type TreeRendererProps = Props<typeof TreeRenderer>;
|
|
320
268
|
|
|
321
269
|
function MyTreeRenderer({ rootNodes }: TreeRendererProps) {
|
|
322
|
-
const
|
|
323
|
-
return <TreeNodeRenderer {...nodeProps} onFilterClick={() => {}} expandNode={() => {}} />;
|
|
324
|
-
}, []);
|
|
325
|
-
|
|
326
|
-
const getNode = useCallback<TreeProps["getNode"]>((node) => createRenderedTreeNodeData(node, () => false), []);
|
|
270
|
+
const flatNodes = useFlatTreeNodeList(rootNodes);
|
|
327
271
|
|
|
328
272
|
return (
|
|
329
273
|
<LocalizationContextProvider localizedStrings={localizedStrings}>
|
|
330
|
-
<Tree
|
|
274
|
+
<Tree.Root>
|
|
275
|
+
{flatNodes.map((flatNode) =>
|
|
276
|
+
isPlaceholderNode(flatNode) ? (
|
|
277
|
+
<Tree.Item key={flatNode.id} aria-level={flatNode.level} aria-posinset={1} aria-setsize={1} label="Loading" />
|
|
278
|
+
) : (
|
|
279
|
+
<Tree.Item
|
|
280
|
+
key={flatNode.id}
|
|
281
|
+
aria-level={flatNode.level}
|
|
282
|
+
aria-posinset={flatNode.posInLevel}
|
|
283
|
+
aria-setsize={flatNode.levelSize}
|
|
284
|
+
label={flatNode.label}
|
|
285
|
+
/>
|
|
286
|
+
),
|
|
287
|
+
)}
|
|
288
|
+
</Tree.Root>
|
|
331
289
|
</LocalizationContextProvider>
|
|
332
290
|
);
|
|
333
291
|
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { GenericInstanceFilter, HierarchyNode } from "@itwin/presentation-hierarchies";
|
|
2
|
+
import { InstanceKey } from "@itwin/presentation-shared";
|
|
3
|
+
import { ErrorInfo, TreeNode } from "./TreeNode.js";
|
|
4
|
+
import { SelectionChangeType } from "./UseSelectionHandler.js";
|
|
5
|
+
/**
|
|
6
|
+
* Type definition used to render tree rendering UI component.
|
|
7
|
+
* @alpha
|
|
8
|
+
*/
|
|
9
|
+
export type TreeRendererProps = {
|
|
10
|
+
/**
|
|
11
|
+
* Array containing root tree nodes.
|
|
12
|
+
*/
|
|
13
|
+
rootNodes: TreeNode[];
|
|
14
|
+
/**
|
|
15
|
+
* A function that should be called to either expand or collapse the given node.
|
|
16
|
+
*/
|
|
17
|
+
expandNode: (nodeId: string, isExpanded: boolean) => void;
|
|
18
|
+
/**
|
|
19
|
+
* A function that should be called to select nodes in the tree.
|
|
20
|
+
* @param nodeIds Ids of the nodes that are selected.
|
|
21
|
+
* @param changeType Type of change that occurred for the selection.
|
|
22
|
+
*/
|
|
23
|
+
selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => void;
|
|
24
|
+
/** Determines whether a given node is selected. */
|
|
25
|
+
isNodeSelected: (nodeId: string) => boolean;
|
|
26
|
+
} & CommonRendererProps;
|
|
27
|
+
/**
|
|
28
|
+
* Type definition used to render root error handling UI component.
|
|
29
|
+
* @alpha
|
|
30
|
+
*/
|
|
31
|
+
export type RootErrorRendererProps = {
|
|
32
|
+
/** Object containing root error information */
|
|
33
|
+
error: ErrorInfo;
|
|
34
|
+
} & CommonRendererProps;
|
|
35
|
+
/**
|
|
36
|
+
* @alpha
|
|
37
|
+
*/
|
|
38
|
+
interface CommonRendererProps {
|
|
39
|
+
/**
|
|
40
|
+
* A function that should be called to reload the tree.
|
|
41
|
+
*/
|
|
42
|
+
reloadTree: (options?: ReloadTreeOptions) => void;
|
|
43
|
+
/** Returns hierarchy level details for a given node ID. */
|
|
44
|
+
getHierarchyLevelDetails: (nodeId: string | undefined) => HierarchyLevelDetails | undefined;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Options for doing either full or a sub tree reload.
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
interface ReloadTreeOptions {
|
|
51
|
+
/** Specifies parent node under which sub tree should be reloaded. */
|
|
52
|
+
parentNodeId: string | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Specifies how current tree state should be handled:
|
|
55
|
+
* - `keep` - try to keep current tree state (expanded/collapsed nodes, instance filters, etc.).
|
|
56
|
+
* - `discard` - do not try to keep current tree state. Tree model will be update after nodes are reloaded.
|
|
57
|
+
* - `reset` - remove subtree from the model before reloading and reload nodes ignoring cache.
|
|
58
|
+
*
|
|
59
|
+
* Defaults to `"keep"`.
|
|
60
|
+
*/
|
|
61
|
+
state?: "keep" | "discard" | "reset";
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A data structure that contains information about a single hierarchy level.
|
|
65
|
+
* @public
|
|
66
|
+
*/
|
|
67
|
+
export interface HierarchyLevelDetails {
|
|
68
|
+
/** The parent node whose hierarchy level's information is contained in this data structure */
|
|
69
|
+
hierarchyNode: HierarchyNode | undefined;
|
|
70
|
+
/** A function to get instance keys of the hierarchy level. */
|
|
71
|
+
getInstanceKeysIterator: (props?: {
|
|
72
|
+
instanceFilter?: GenericInstanceFilter;
|
|
73
|
+
hierarchyLevelSizeLimit?: number | "unbounded";
|
|
74
|
+
}) => AsyncIterableIterator<InstanceKey>;
|
|
75
|
+
/** Get the limit of how many nodes can be loaded in this hierarchy level. */
|
|
76
|
+
sizeLimit?: number | "unbounded";
|
|
77
|
+
/** Set the limit of how many nodes can be loaded in this hierarchy level. */
|
|
78
|
+
setSizeLimit: (value: undefined | number | "unbounded") => void;
|
|
79
|
+
/** Get the active instance filter applied to this hierarchy level. */
|
|
80
|
+
instanceFilter?: GenericInstanceFilter;
|
|
81
|
+
/** Set the instance filter to apply to this hierarchy level */
|
|
82
|
+
setInstanceFilter: (filter: GenericInstanceFilter | undefined) => void;
|
|
83
|
+
}
|
|
84
|
+
export {};
|
|
85
|
+
//# sourceMappingURL=Renderers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Renderers.d.ts","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/Renderers.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACvF,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;OAEG;IACH,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB;;OAEG;IACH,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,KAAK,IAAI,CAAC;IAC1D;;;;OAIG;IACH,WAAW,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,mBAAmB,KAAK,IAAI,CAAC;IAC/E,mDAAmD;IACnD,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;CAC7C,GAAG,mBAAmB,CAAC;AAExB;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,+CAA+C;IAC/C,KAAK,EAAE,SAAS,CAAC;CAClB,GAAG,mBAAmB,CAAC;AAExB;;GAEG;AACH,UAAU,mBAAmB;IAC3B;;OAEG;IACH,UAAU,EAAE,CAAC,OAAO,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAClD,2DAA2D;IAC3D,wBAAwB,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,KAAK,qBAAqB,GAAG,SAAS,CAAC;CAC7F;AAED;;;GAGG;AACH,UAAU,iBAAiB;IACzB,qEAAqE;IACrE,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAEjC;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;CACtC;AAED;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,8FAA8F;IAC9F,aAAa,EAAE,aAAa,GAAG,SAAS,CAAC;IAEzC,8DAA8D;IAC9D,uBAAuB,EAAE,CAAC,KAAK,CAAC,EAAE;QAChC,cAAc,CAAC,EAAE,qBAAqB,CAAC;QACvC,uBAAuB,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;KAChD,KAAK,qBAAqB,CAAC,WAAW,CAAC,CAAC;IAEzC,6EAA6E;IAC7E,SAAS,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IACjC,6EAA6E;IAC7E,YAAY,EAAE,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,GAAG,WAAW,KAAK,IAAI,CAAC;IAEhE,sEAAsE;IACtE,cAAc,CAAC,EAAE,qBAAqB,CAAC;IACvC,+DAA+D;IAC/D,iBAAiB,EAAE,CAAC,MAAM,EAAE,qBAAqB,GAAG,SAAS,KAAK,IAAI,CAAC;CACxE"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
export {};
|
|
6
|
+
//# sourceMappingURL=Renderers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Renderers.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/Renderers.ts"],"names":[],"mappings":"AAAA;;;gGAGgG","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 { GenericInstanceFilter, HierarchyNode } from \"@itwin/presentation-hierarchies\";\nimport { InstanceKey } from \"@itwin/presentation-shared\";\nimport { ErrorInfo, TreeNode } from \"./TreeNode.js\";\nimport { SelectionChangeType } from \"./UseSelectionHandler.js\";\n\n/**\n * Type definition used to render tree rendering UI component.\n * @alpha\n */\nexport type TreeRendererProps = {\n /**\n * Array containing root tree nodes.\n */\n rootNodes: TreeNode[];\n /**\n * A function that should be called to either expand or collapse the given node.\n */\n expandNode: (nodeId: string, isExpanded: boolean) => void;\n /**\n * A function that should be called to select nodes in the tree.\n * @param nodeIds Ids of the nodes that are selected.\n * @param changeType Type of change that occurred for the selection.\n */\n selectNodes: (nodeIds: Array<string>, changeType: SelectionChangeType) => void;\n /** Determines whether a given node is selected. */\n isNodeSelected: (nodeId: string) => boolean;\n} & CommonRendererProps;\n\n/**\n * Type definition used to render root error handling UI component.\n * @alpha\n */\nexport type RootErrorRendererProps = {\n /** Object containing root error information */\n error: ErrorInfo;\n} & CommonRendererProps;\n\n/**\n * @alpha\n */\ninterface CommonRendererProps {\n /**\n * A function that should be called to reload the tree.\n */\n reloadTree: (options?: ReloadTreeOptions) => void;\n /** Returns hierarchy level details for a given node ID. */\n getHierarchyLevelDetails: (nodeId: string | undefined) => HierarchyLevelDetails | undefined;\n}\n\n/**\n * Options for doing either full or a sub tree reload.\n * @public\n */\ninterface ReloadTreeOptions {\n /** Specifies parent node under which sub tree should be reloaded. */\n parentNodeId: string | undefined;\n\n /**\n * Specifies how current tree state should be handled:\n * - `keep` - try to keep current tree state (expanded/collapsed nodes, instance filters, etc.).\n * - `discard` - do not try to keep current tree state. Tree model will be update after nodes are reloaded.\n * - `reset` - remove subtree from the model before reloading and reload nodes ignoring cache.\n *\n * Defaults to `\"keep\"`.\n */\n state?: \"keep\" | \"discard\" | \"reset\";\n}\n\n/**\n * A data structure that contains information about a single hierarchy level.\n * @public\n */\nexport interface HierarchyLevelDetails {\n /** The parent node whose hierarchy level's information is contained in this data structure */\n hierarchyNode: HierarchyNode | undefined;\n\n /** A function to get instance keys of the hierarchy level. */\n getInstanceKeysIterator: (props?: {\n instanceFilter?: GenericInstanceFilter;\n hierarchyLevelSizeLimit?: number | \"unbounded\";\n }) => AsyncIterableIterator<InstanceKey>;\n\n /** Get the limit of how many nodes can be loaded in this hierarchy level. */\n sizeLimit?: number | \"unbounded\";\n /** Set the limit of how many nodes can be loaded in this hierarchy level. */\n setSizeLimit: (value: undefined | number | \"unbounded\") => void;\n\n /** Get the active instance filter applied to this hierarchy level. */\n instanceFilter?: GenericInstanceFilter;\n /** Set the instance filter to apply to this hierarchy level */\n setInstanceFilter: (filter: GenericInstanceFilter | undefined) => void;\n}\n"]}
|
|
@@ -1,75 +1,74 @@
|
|
|
1
1
|
import { HierarchyNode } from "@itwin/presentation-hierarchies";
|
|
2
2
|
/**
|
|
3
|
-
* A type that defines an
|
|
3
|
+
* A type that defines an node in a UI tree component, built with `useTree` hook.
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
6
|
-
export interface
|
|
6
|
+
export interface TreeNode {
|
|
7
7
|
id: string;
|
|
8
8
|
label: string;
|
|
9
|
-
children: true | Array<
|
|
9
|
+
children: true | Array<TreeNode>;
|
|
10
10
|
isExpanded: boolean;
|
|
11
11
|
isLoading: boolean;
|
|
12
12
|
isFilterable: boolean;
|
|
13
13
|
isFiltered: boolean;
|
|
14
14
|
/** UI-agnostic source of this node object. */
|
|
15
15
|
nodeData: HierarchyNode;
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
[key: string]: any;
|
|
19
|
-
};
|
|
16
|
+
/** Contains error encountered from expanding the node */
|
|
17
|
+
error?: ErrorInfo;
|
|
20
18
|
}
|
|
21
19
|
/**
|
|
22
|
-
* A type of `
|
|
20
|
+
* A type of `ErrorInfo` that is returned,
|
|
23
21
|
* when none of the child nodes match the filter.
|
|
24
22
|
*
|
|
25
23
|
* @public
|
|
26
24
|
*/
|
|
27
|
-
export interface
|
|
25
|
+
export interface NoFilterMatchesErrorInfo {
|
|
28
26
|
id: string;
|
|
29
|
-
parentNodeId: string | undefined;
|
|
30
27
|
type: "NoFilterMatches";
|
|
31
28
|
}
|
|
32
29
|
/**
|
|
33
|
-
* A type of `
|
|
30
|
+
* A type of `ErrorInfo` that is returned, when the
|
|
34
31
|
* number of child nodes exceeds the limit set on the tree nodes loader. The limit is also included
|
|
35
|
-
* on this
|
|
32
|
+
* on this error as `resultSetSizeLimit` attribute.
|
|
36
33
|
*
|
|
37
34
|
* @public
|
|
38
35
|
*/
|
|
39
|
-
export interface
|
|
36
|
+
export interface ResultSetTooLargeErrorInfo {
|
|
40
37
|
id: string;
|
|
41
|
-
parentNodeId: string | undefined;
|
|
42
38
|
type: "ResultSetTooLarge";
|
|
43
39
|
resultSetSizeLimit: number;
|
|
44
40
|
}
|
|
45
41
|
/**
|
|
46
|
-
* A type of `
|
|
47
|
-
*
|
|
42
|
+
* A type of `ErrorInfo` that contains a user-friendly message to be displayed in the UI.
|
|
43
|
+
* Created in cases like an error loading children. The
|
|
48
44
|
* renderer may offer users to re-load the children or the whole component in such cases.
|
|
49
45
|
*
|
|
50
46
|
* @public
|
|
51
47
|
*/
|
|
52
|
-
export interface
|
|
48
|
+
export interface ChildrenLoadErrorInfo {
|
|
53
49
|
id: string;
|
|
54
|
-
|
|
55
|
-
type: "Unknown";
|
|
50
|
+
type: "ChildrenLoad";
|
|
56
51
|
message: string;
|
|
57
52
|
}
|
|
58
53
|
/**
|
|
59
|
-
* A type
|
|
60
|
-
*
|
|
54
|
+
* A type of `ErrorInfo` that can be used to show/handle generic errors,
|
|
55
|
+
* that might not be directly caused by the tree components. (e.g. tree components
|
|
56
|
+
* shows hierarchy of connections to external systems and an error is show in the
|
|
57
|
+
* tree when some connections are unreachable).
|
|
61
58
|
*
|
|
62
59
|
* @public
|
|
63
60
|
*/
|
|
64
|
-
export
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
61
|
+
export interface GenericErrorInfo {
|
|
62
|
+
id: string;
|
|
63
|
+
type: "Unknown";
|
|
64
|
+
message: string;
|
|
65
|
+
additionalData?: unknown;
|
|
66
|
+
}
|
|
70
67
|
/**
|
|
71
|
-
*
|
|
68
|
+
* A collection of types that defines an error state for `TreeNode` node in a UI tree component, built
|
|
69
|
+
* with `useTree` hook.
|
|
70
|
+
*
|
|
72
71
|
* @public
|
|
73
72
|
*/
|
|
74
|
-
export
|
|
73
|
+
export type ErrorInfo = GenericErrorInfo | ResultSetTooLargeErrorInfo | NoFilterMatchesErrorInfo | ChildrenLoadErrorInfo;
|
|
75
74
|
//# sourceMappingURL=TreeNode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeNode.d.ts","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/TreeNode.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAEhE;;;GAGG;AACH,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"TreeNode.d.ts","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/TreeNode.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAEhE;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;IACjC,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,YAAY,EAAE,OAAO,CAAC;IACtB,UAAU,EAAE,OAAO,CAAC;IACpB,8CAA8C;IAC9C,QAAQ,EAAE,aAAa,CAAC;IACxB,yDAAyD;IACzD,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB;AAED;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,iBAAiB,CAAC;CACzB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,0BAA0B;IACzC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,mBAAmB,CAAC;IAC1B,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,cAAc,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,SAAS,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,gBAAgB,GAAG,0BAA0B,GAAG,wBAAwB,GAAG,qBAAqB,CAAC"}
|
|
@@ -2,11 +2,5 @@
|
|
|
2
2
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
|
|
6
|
-
* An utility function to check if a node is a `PresentationHierarchyNode`.
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
9
|
-
export function isPresentationHierarchyNode(node) {
|
|
10
|
-
return "children" in node;
|
|
11
|
-
}
|
|
5
|
+
export {};
|
|
12
6
|
//# sourceMappingURL=TreeNode.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeNode.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/TreeNode.ts"],"names":[],"mappings":"AAAA;;;gGAGgG
|
|
1
|
+
{"version":3,"file":"TreeNode.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/TreeNode.ts"],"names":[],"mappings":"AAAA;;;gGAGgG","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 { HierarchyNode } from \"@itwin/presentation-hierarchies\";\n\n/**\n * A type that defines an node in a UI tree component, built with `useTree` hook.\n * @public\n */\nexport interface TreeNode {\n id: string;\n label: string;\n children: true | Array<TreeNode>;\n isExpanded: boolean;\n isLoading: boolean;\n isFilterable: boolean;\n isFiltered: boolean;\n /** UI-agnostic source of this node object. */\n nodeData: HierarchyNode;\n /** Contains error encountered from expanding the node */\n error?: ErrorInfo;\n}\n\n/**\n * A type of `ErrorInfo` that is returned,\n * when none of the child nodes match the filter.\n *\n * @public\n */\nexport interface NoFilterMatchesErrorInfo {\n id: string;\n type: \"NoFilterMatches\";\n}\n\n/**\n * A type of `ErrorInfo` that is returned, when the\n * number of child nodes exceeds the limit set on the tree nodes loader. The limit is also included\n * on this error as `resultSetSizeLimit` attribute.\n *\n * @public\n */\nexport interface ResultSetTooLargeErrorInfo {\n id: string;\n type: \"ResultSetTooLarge\";\n resultSetSizeLimit: number;\n}\n\n/**\n * A type of `ErrorInfo` that contains a user-friendly message to be displayed in the UI.\n * Created in cases like an error loading children. The\n * renderer may offer users to re-load the children or the whole component in such cases.\n *\n * @public\n */\nexport interface ChildrenLoadErrorInfo {\n id: string;\n type: \"ChildrenLoad\";\n message: string;\n}\n\n/**\n * A type of `ErrorInfo` that can be used to show/handle generic errors,\n * that might not be directly caused by the tree components. (e.g. tree components\n * shows hierarchy of connections to external systems and an error is show in the\n * tree when some connections are unreachable).\n *\n * @public\n */\nexport interface GenericErrorInfo {\n id: string;\n type: \"Unknown\";\n message: string;\n additionalData?: unknown;\n}\n\n/**\n * A collection of types that defines an error state for `TreeNode` node in a UI tree component, built\n * with `useTree` hook.\n *\n * @public\n */\nexport type ErrorInfo = GenericErrorInfo | ResultSetTooLargeErrorInfo | NoFilterMatchesErrorInfo | ChildrenLoadErrorInfo;\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createIModelHierarchyProvider, HierarchyDefinition,
|
|
1
|
+
import { createIModelHierarchyProvider, HierarchyDefinition, HierarchySearchPath } from "@itwin/presentation-hierarchies";
|
|
2
2
|
import { Props } from "@itwin/presentation-shared";
|
|
3
3
|
import { UseUnifiedTreeSelectionProps } from "./internal/UseUnifiedSelection.js";
|
|
4
4
|
import { UseTreeProps, UseTreeResult } from "./UseTree.js";
|
|
@@ -10,16 +10,18 @@ type IModelAccess = IModelHierarchyProviderProps["imodelAccess"];
|
|
|
10
10
|
* Props for `useIModelTree` and `useIModelUnifiedSelectionTree` hooks.
|
|
11
11
|
* @public
|
|
12
12
|
*/
|
|
13
|
-
type UseIModelTreeProps = Omit<UseTreeProps, "getHierarchyProvider" | "
|
|
13
|
+
type UseIModelTreeProps = Omit<UseTreeProps, "getHierarchyProvider" | "getSearchPaths"> & Pick<IModelHierarchyProviderProps, "localizedStrings" | "imodelAccess" | "imodelChanged"> & {
|
|
14
14
|
/** Provides the hierarchy definition for the tree. */
|
|
15
15
|
getHierarchyDefinition: (props: {
|
|
16
16
|
imodelAccess: IModelAccess;
|
|
17
17
|
}) => HierarchyDefinition;
|
|
18
|
-
/** Provides paths to
|
|
19
|
-
|
|
18
|
+
/** Provides paths to target nodes. */
|
|
19
|
+
getSearchPaths?: (props: {
|
|
20
20
|
/** Object that provides access to the iModel schema and can run queries against the iModel. */
|
|
21
21
|
imodelAccess: IModelAccess;
|
|
22
|
-
|
|
22
|
+
/** Signal indicating that that the request was canceled */
|
|
23
|
+
abortSignal: AbortSignal;
|
|
24
|
+
}) => Promise<HierarchySearchPath[] | undefined>;
|
|
23
25
|
};
|
|
24
26
|
/**
|
|
25
27
|
* A React hook that creates state for a tree component whose displayed hierarchy is based on
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseIModelTree.d.ts","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseIModelTree.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,6BAA6B,EAAE,mBAAmB,EAAE,
|
|
1
|
+
{"version":3,"file":"UseIModelTree.d.ts","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseIModelTree.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,6BAA6B,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAC1H,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAW,YAAY,EAAE,aAAa,EAA2B,MAAM,cAAc,CAAC;AAE7F,cAAc;AACd,KAAK,4BAA4B,GAAG,KAAK,CAAC,OAAO,6BAA6B,CAAC,CAAC;AAEhF,cAAc;AACd,KAAK,YAAY,GAAG,4BAA4B,CAAC,cAAc,CAAC,CAAC;AAEjE;;;GAGG;AACH,KAAK,kBAAkB,GAAG,IAAI,CAAC,YAAY,EAAE,sBAAsB,GAAG,gBAAgB,CAAC,GACrF,IAAI,CAAC,4BAA4B,EAAE,kBAAkB,GAAG,cAAc,GAAG,eAAe,CAAC,GAAG;IAC1F,sDAAsD;IACtD,sBAAsB,EAAE,CAAC,KAAK,EAAE;QAAE,YAAY,EAAE,YAAY,CAAA;KAAE,KAAK,mBAAmB,CAAC;IAEvF,sCAAsC;IACtC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE;QACvB,+FAA+F;QAC/F,YAAY,EAAE,YAAY,CAAC;QAC3B,2DAA2D;QAC3D,WAAW,EAAE,WAAW,CAAC;KAC1B,KAAK,OAAO,CAAC,mBAAmB,EAAE,GAAG,SAAS,CAAC,CAAC;CAClD,CAAC;AAEJ;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,aAAa,CAMtE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,kBAAkB,GAAG,4BAA4B,GAAG,aAAa,CAMrH"}
|
|
@@ -19,10 +19,10 @@ import { useTree, useUnifiedSelectionTree } from "./UseTree.js";
|
|
|
19
19
|
* @public
|
|
20
20
|
*/
|
|
21
21
|
export function useIModelTree(props) {
|
|
22
|
-
const { imodelAccess, imodelChanged, getHierarchyDefinition,
|
|
22
|
+
const { imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths, localizedStrings, ...rest } = props;
|
|
23
23
|
return useTree({
|
|
24
24
|
...rest,
|
|
25
|
-
...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition,
|
|
25
|
+
...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths, localizedStrings }),
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
@@ -41,14 +41,14 @@ export function useIModelTree(props) {
|
|
|
41
41
|
* @public
|
|
42
42
|
*/
|
|
43
43
|
export function useIModelUnifiedSelectionTree(props) {
|
|
44
|
-
const { imodelAccess, imodelChanged, getHierarchyDefinition,
|
|
44
|
+
const { imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths, localizedStrings, ...rest } = props;
|
|
45
45
|
return useUnifiedSelectionTree({
|
|
46
46
|
...rest,
|
|
47
|
-
...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition,
|
|
47
|
+
...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths, localizedStrings }),
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
function useIModelTreeProps(props) {
|
|
51
|
-
const { imodelAccess, imodelChanged, getHierarchyDefinition,
|
|
51
|
+
const { imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths, localizedStrings } = props;
|
|
52
52
|
return {
|
|
53
53
|
getHierarchyProvider: useCallback(() => createIModelHierarchyProvider({
|
|
54
54
|
imodelAccess,
|
|
@@ -56,7 +56,7 @@ function useIModelTreeProps(props) {
|
|
|
56
56
|
hierarchyDefinition: getHierarchyDefinition({ imodelAccess }),
|
|
57
57
|
localizedStrings,
|
|
58
58
|
}), [imodelAccess, imodelChanged, getHierarchyDefinition, localizedStrings]),
|
|
59
|
-
|
|
59
|
+
getSearchPaths: useCallback(async ({ abortSignal }) => getSearchPaths?.({ imodelAccess, abortSignal }), [imodelAccess, getSearchPaths]),
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
//# sourceMappingURL=UseIModelTree.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseIModelTree.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseIModelTree.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,6BAA6B,
|
|
1
|
+
{"version":3,"file":"UseIModelTree.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseIModelTree.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,6BAA6B,EAA4C,MAAM,iCAAiC,CAAC;AAG1H,OAAO,EAAE,OAAO,EAA+B,uBAAuB,EAAE,MAAM,cAAc,CAAC;AA0B7F;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAAC,KAAyB;IACrD,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAE,cAAc,EAAE,gBAAgB,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;IACjH,OAAO,OAAO,CAAC;QACb,GAAG,IAAI;QACP,GAAG,kBAAkB,CAAC,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAE,cAAc,EAAE,gBAAgB,EAAE,CAAC;KACjH,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,6BAA6B,CAAC,KAAwD;IACpG,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAE,cAAc,EAAE,gBAAgB,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;IACjH,OAAO,uBAAuB,CAAC;QAC7B,GAAG,IAAI;QACP,GAAG,kBAAkB,CAAC,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAE,cAAc,EAAE,gBAAgB,EAAE,CAAC;KACjH,CAAC,CAAC;AACL,CAAC;AAED,SAAS,kBAAkB,CACzB,KAAoI;IAEpI,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAE,cAAc,EAAE,gBAAgB,EAAE,GAAG,KAAK,CAAC;IACxG,OAAO;QACL,oBAAoB,EAAE,WAAW,CAC/B,GAAG,EAAE,CACH,6BAA6B,CAAC;YAC5B,YAAY;YACZ,aAAa;YACb,mBAAmB,EAAE,sBAAsB,CAAC,EAAE,YAAY,EAAE,CAAC;YAC7D,gBAAgB;SACjB,CAAC,EACJ,CAAC,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAE,gBAAgB,CAAC,CACxE;QACD,cAAc,EAAE,WAAW,CACzB,KAAK,EAAE,EAAE,WAAW,EAAgC,EAAE,EAAE,CAAC,cAAc,EAAE,CAAC,EAAE,YAAY,EAAE,WAAW,EAAE,CAAC,EACxG,CAAC,YAAY,EAAE,cAAc,CAAC,CAC/B;KACF,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useCallback } from \"react\";\nimport { createIModelHierarchyProvider, HierarchyDefinition, HierarchySearchPath } from \"@itwin/presentation-hierarchies\";\nimport { Props } from \"@itwin/presentation-shared\";\nimport { UseUnifiedTreeSelectionProps } from \"./internal/UseUnifiedSelection.js\";\nimport { useTree, UseTreeProps, UseTreeResult, useUnifiedSelectionTree } 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, \"localizedStrings\" | \"imodelAccess\" | \"imodelChanged\"> & {\n /** Provides the hierarchy definition for the tree. */\n getHierarchyDefinition: (props: { imodelAccess: IModelAccess }) => HierarchyDefinition;\n\n /** Provides paths to target nodes. */\n getSearchPaths?: (props: {\n /** Object that provides access to the iModel schema and can run queries against the iModel. */\n imodelAccess: IModelAccess;\n /** Signal indicating that that the request was canceled */\n abortSignal: AbortSignal;\n }) => Promise<HierarchySearchPath[] | 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, localizedStrings, ...rest } = props;\n return useTree({\n ...rest,\n ...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths, localizedStrings }),\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, localizedStrings, ...rest } = props;\n return useUnifiedSelectionTree({\n ...rest,\n ...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths, localizedStrings }),\n });\n}\n\nfunction useIModelTreeProps(\n props: Pick<UseIModelTreeProps, \"imodelAccess\" | \"imodelChanged\" | \"getHierarchyDefinition\" | \"getSearchPaths\" | \"localizedStrings\">,\n): Pick<UseTreeProps, \"getHierarchyProvider\" | \"getSearchPaths\"> {\n const { imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths, localizedStrings } = props;\n return {\n getHierarchyProvider: useCallback(\n () =>\n createIModelHierarchyProvider({\n imodelAccess,\n imodelChanged,\n hierarchyDefinition: getHierarchyDefinition({ imodelAccess }),\n localizedStrings,\n }),\n [imodelAccess, imodelChanged, getHierarchyDefinition, localizedStrings],\n ),\n getSearchPaths: useCallback(\n async ({ abortSignal }: { abortSignal: AbortSignal }) => getSearchPaths?.({ imodelAccess, abortSignal }),\n [imodelAccess, getSearchPaths],\n ),\n };\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { TreeNode } from "./TreeNode.js";
|
|
2
|
+
/**
|
|
3
|
+
* Props for `useNodeHighlighting` hook.
|
|
4
|
+
* @alpha
|
|
5
|
+
*/
|
|
6
|
+
interface UseNodeHighlightingProps {
|
|
7
|
+
/** Text that should be highlighted */
|
|
8
|
+
highlightText?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Result of `useNodeHighlighting` hook.
|
|
12
|
+
* @alpha
|
|
13
|
+
*/
|
|
14
|
+
interface UseNodeHighlightingResult {
|
|
15
|
+
/** Function that creates highlighted node labels. */
|
|
16
|
+
getLabel: (node: TreeNode) => React.ReactElement;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A react hook that helps create highlighted node labels based on provided highlight.
|
|
20
|
+
* @alpha
|
|
21
|
+
*/
|
|
22
|
+
export declare function useNodeHighlighting({ highlightText }: UseNodeHighlightingProps): UseNodeHighlightingResult;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=UseNodeHighlighting.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UseNodeHighlighting.d.ts","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseNodeHighlighting.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC;;;GAGG;AACH,UAAU,wBAAwB;IAChC,sCAAsC;IACtC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;GAGG;AACH,UAAU,yBAAyB;IACjC,qDAAqD;IACrD,QAAQ,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,KAAK,CAAC,YAAY,CAAC;CAClD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,aAAa,EAAE,EAAE,wBAAwB,GAAG,yBAAyB,CAgD1G"}
|