@itwin/presentation-hierarchies-react 2.0.0-alpha.4 → 2.0.0-alpha.40
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 +656 -7
- package/README.md +25 -27
- 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 +27 -28
- 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 +2 -0
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.js +1 -1
- 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 +52 -0
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.d.ts +3 -3
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.js +1 -8
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.d.ts +32 -70
- package/lib/esm/presentation-hierarchies-react/UseTree.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.js +48 -49
- package/lib/esm/presentation-hierarchies-react/UseTree.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/Utils.d.ts +5 -0
- package/lib/esm/presentation-hierarchies-react/Utils.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/Utils.js +23 -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 +26 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js +75 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FilterAction.d.ts +34 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FilterAction.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FilterAction.js +26 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FilterAction.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts +58 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.js +77 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts +123 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/{itwinui → stratakit}/LocalizationContext.js +15 -5
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RenameAction.d.ts +33 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RenameAction.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RenameAction.js +39 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RenameAction.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/TreeErrorRenderer.d.ts +47 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js +28 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts +51 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js +117 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts +45 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js +94 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react.d.ts +14 -9
- package/lib/esm/presentation-hierarchies-react.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react.js +11 -8
- 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 -20
- 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 -13
- 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 -46
- 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 -30
- 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
|
|
|
@@ -20,7 +20,6 @@ All these hooks return the same state object, which contains properties and func
|
|
|
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
22
|
- `rootNodes` is an array of root tree nodes and is what the component should render. There are several types of nodes:
|
|
23
|
-
|
|
24
23
|
- 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
24
|
- 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.
|
|
26
25
|
|
|
@@ -31,7 +30,6 @@ All these hooks return the same state object, which contains properties and func
|
|
|
31
30
|
- `getNode` function to get node by its id.
|
|
32
31
|
|
|
33
32
|
- `getHierarchyLevelDetails` function to access details of a specific hierarchy level. The returned object provides access to:
|
|
34
|
-
|
|
35
33
|
- hierarchy level size limit,
|
|
36
34
|
- hierarchy level instance filter,
|
|
37
35
|
- instance keys of the nodes in the hierarchy level.
|
|
@@ -125,21 +123,18 @@ The returned object contains 2 functions, that should be called by the node rend
|
|
|
125
123
|
|
|
126
124
|
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
125
|
|
|
128
|
-
##
|
|
126
|
+
## StrataKit components
|
|
129
127
|
|
|
130
|
-
While the package provides a headless UI, it also delivers a set of [
|
|
128
|
+
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
129
|
|
|
132
130
|
### `TreeRenderer`
|
|
133
131
|
|
|
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.
|
|
132
|
+
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
133
|
|
|
138
134
|
### `TreeNodeRenderer`
|
|
139
135
|
|
|
140
|
-
The component is based on `
|
|
136
|
+
The component is based on `Tree.Item` component from StrataKit library and supports the following features:
|
|
141
137
|
|
|
142
|
-
- Rendering informational type of nodes (e.g. "No filter matches", "Too many nodes in a hierarchy level", etc.).
|
|
143
138
|
- Reporting click and key down events for use with [`useSelectionHandler` hook](#useselectionhandler-hook).
|
|
144
139
|
- Icons, selection, expand / collapse.
|
|
145
140
|
- Action buttons to clear / set hierarchy level instance filter.
|
|
@@ -275,7 +270,7 @@ const localizedStrings = {
|
|
|
275
270
|
unspecified: "Unspecified",
|
|
276
271
|
other: "Other",
|
|
277
272
|
|
|
278
|
-
// strings for `TreeRenderer` and `
|
|
273
|
+
// strings for `TreeRenderer` and `TreeNodeRenderer`
|
|
279
274
|
loading: "Loading...",
|
|
280
275
|
filterHierarchyLevel: "Apply hierarchy filter",
|
|
281
276
|
clearHierarchyLevelFilter: "Clear active filter",
|
|
@@ -306,28 +301,31 @@ In case the `TreeNodeRenderer` component is used within a custom tree renderer,
|
|
|
306
301
|
import { Props } from "@itwin/presentation-shared";
|
|
307
302
|
|
|
308
303
|
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>>;
|
|
304
|
+
import { Tree } from "@stratakit/bricks";
|
|
305
|
+
import { LocalizationContextProvider, TreeRenderer, useFlatTreeNodeList } from "@itwin/presentation-hierarchies-react";
|
|
306
|
+
|
|
319
307
|
type TreeRendererProps = Props<typeof TreeRenderer>;
|
|
320
308
|
|
|
321
309
|
function MyTreeRenderer({ rootNodes }: TreeRendererProps) {
|
|
322
|
-
const
|
|
323
|
-
return <TreeNodeRenderer {...nodeProps} onFilterClick={() => {}} expandNode={() => {}} />;
|
|
324
|
-
}, []);
|
|
325
|
-
|
|
326
|
-
const getNode = useCallback<TreeProps["getNode"]>((node) => createRenderedTreeNodeData(node, () => false), []);
|
|
310
|
+
const flatNodes = useFlatTreeNodeList(rootNodes);
|
|
327
311
|
|
|
328
312
|
return (
|
|
329
313
|
<LocalizationContextProvider localizedStrings={localizedStrings}>
|
|
330
|
-
<Tree
|
|
314
|
+
<Tree.Root>
|
|
315
|
+
{flatNodes.map((flatNode) =>
|
|
316
|
+
isPlaceholderNode(flatNode) ? (
|
|
317
|
+
<Tree.Item key={flatNode.id} aria-level={flatNode.level} aria-posinset={1} aria-setsize={1} label="Loading" />
|
|
318
|
+
) : (
|
|
319
|
+
<Tree.Item
|
|
320
|
+
key={flatNode.id}
|
|
321
|
+
aria-level={flatNode.level}
|
|
322
|
+
aria-posinset={flatNode.posInLevel}
|
|
323
|
+
aria-setsize={flatNode.levelSize}
|
|
324
|
+
label={flatNode.label}
|
|
325
|
+
/>
|
|
326
|
+
),
|
|
327
|
+
)}
|
|
328
|
+
</Tree.Root>
|
|
331
329
|
</LocalizationContextProvider>
|
|
332
330
|
);
|
|
333
331
|
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { GenericInstanceFilter, HierarchyNode } from "@itwin/presentation-hierarchies";
|
|
2
|
+
import { InstanceKey } from "@itwin/presentation-shared";
|
|
3
|
+
import { ErrorInfo, PresentationHierarchyNode } 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: PresentationHierarchyNode[];
|
|
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,yBAAyB,EAAE,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;OAEG;IACH,SAAS,EAAE,yBAAyB,EAAE,CAAC;IACvC;;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, PresentationHierarchyNode } 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: PresentationHierarchyNode[];\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
6
|
export interface PresentationHierarchyNode {
|
|
7
7
|
id: string;
|
|
8
8
|
label: string;
|
|
9
|
-
children: true | Array<
|
|
9
|
+
children: true | Array<PresentationHierarchyNode>;
|
|
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 `PresentationHierarchyNode` 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,yBAAyB;IACxC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,IAAI,GAAG,KAAK,CAAC,
|
|
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,yBAAyB;IACxC,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,IAAI,GAAG,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAClD,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 PresentationHierarchyNode {\n id: string;\n label: string;\n children: true | Array<PresentationHierarchyNode>;\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 `PresentationHierarchyNode` node in a UI tree component, built\n * with `useTree` hook.\n *\n * @public\n */\nexport type ErrorInfo = GenericErrorInfo | ResultSetTooLargeErrorInfo | NoFilterMatchesErrorInfo | ChildrenLoadErrorInfo;\n"]}
|
|
@@ -19,6 +19,8 @@ type UseIModelTreeProps = Omit<UseTreeProps, "getHierarchyProvider" | "getFilter
|
|
|
19
19
|
getFilteredPaths?: (props: {
|
|
20
20
|
/** Object that provides access to the iModel schema and can run queries against the iModel. */
|
|
21
21
|
imodelAccess: IModelAccess;
|
|
22
|
+
/** Signal indicating that that the request was canceled */
|
|
23
|
+
abortSignal: AbortSignal;
|
|
22
24
|
}) => Promise<HierarchyFilteringPath[] | undefined>;
|
|
23
25
|
};
|
|
24
26
|
/**
|
|
@@ -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,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAC7H,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,kBAAkB,CAAC,GACvF,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,wCAAwC;IACxC,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE;QACzB,+FAA+F;QAC/F,YAAY,EAAE,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"UseIModelTree.d.ts","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseIModelTree.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,6BAA6B,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAC7H,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,kBAAkB,CAAC,GACvF,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,wCAAwC;IACxC,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE;QACzB,+FAA+F;QAC/F,YAAY,EAAE,YAAY,CAAC;QAC3B,2DAA2D;QAC3D,WAAW,EAAE,WAAW,CAAC;KAC1B,KAAK,OAAO,CAAC,sBAAsB,EAAE,GAAG,SAAS,CAAC,CAAC;CACrD,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"}
|
|
@@ -56,7 +56,7 @@ function useIModelTreeProps(props) {
|
|
|
56
56
|
hierarchyDefinition: getHierarchyDefinition({ imodelAccess }),
|
|
57
57
|
localizedStrings,
|
|
58
58
|
}), [imodelAccess, imodelChanged, getHierarchyDefinition, localizedStrings]),
|
|
59
|
-
getFilteredPaths: useCallback(async () => getFilteredPaths?.({ imodelAccess }), [imodelAccess, getFilteredPaths]),
|
|
59
|
+
getFilteredPaths: useCallback(async ({ abortSignal }) => getFilteredPaths?.({ imodelAccess, abortSignal }), [imodelAccess, getFilteredPaths]),
|
|
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,EAA+C,MAAM,iCAAiC,CAAC;AAG7H,OAAO,EAAE,OAAO,EAA+B,uBAAuB,EAAE,MAAM,cAAc,CAAC;
|
|
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,EAA+C,MAAM,iCAAiC,CAAC;AAG7H,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,gBAAgB,EAAE,gBAAgB,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;IACnH,OAAO,OAAO,CAAC;QACb,GAAG,IAAI;QACP,GAAG,kBAAkB,CAAC,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,CAAC;KACnH,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,6BAA6B,CAAC,KAAwD;IACpG,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;IACnH,OAAO,uBAAuB,CAAC;QAC7B,GAAG,IAAI;QACP,GAAG,kBAAkB,CAAC,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,CAAC;KACnH,CAAC,CAAC;AACL,CAAC;AAED,SAAS,kBAAkB,CACzB,KAAsI;IAEtI,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,GAAG,KAAK,CAAC;IAC1G,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,gBAAgB,EAAE,WAAW,CAC3B,KAAK,EAAE,EAAE,WAAW,EAAgC,EAAE,EAAE,CAAC,gBAAgB,EAAE,CAAC,EAAE,YAAY,EAAE,WAAW,EAAE,CAAC,EAC1G,CAAC,YAAY,EAAE,gBAAgB,CAAC,CACjC;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, HierarchyFilteringPath } 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\" | \"getFilteredPaths\"> &\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 filtered nodes. */\n getFilteredPaths?: (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<HierarchyFilteringPath[] | 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, getFilteredPaths, localizedStrings, ...rest } = props;\n return useTree({\n ...rest,\n ...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, 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, getFilteredPaths, localizedStrings, ...rest } = props;\n return useUnifiedSelectionTree({\n ...rest,\n ...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings }),\n });\n}\n\nfunction useIModelTreeProps(\n props: Pick<UseIModelTreeProps, \"imodelAccess\" | \"imodelChanged\" | \"getHierarchyDefinition\" | \"getFilteredPaths\" | \"localizedStrings\">,\n): Pick<UseTreeProps, \"getHierarchyProvider\" | \"getFilteredPaths\"> {\n const { imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, 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 getFilteredPaths: useCallback(\n async ({ abortSignal }: { abortSignal: AbortSignal }) => getFilteredPaths?.({ imodelAccess, abortSignal }),\n [imodelAccess, getFilteredPaths],\n ),\n };\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { PresentationHierarchyNode } 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: PresentationHierarchyNode) => 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":"AAMA,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAE1D;;;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,yBAAyB,KAAK,KAAK,CAAC,YAAY,CAAC;CACnE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,aAAa,EAAE,EAAE,wBAAwB,GAAG,yBAAyB,CAgD1G"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
import { useCallback } from "react";
|
|
7
|
+
/**
|
|
8
|
+
* A react hook that helps create highlighted node labels based on provided highlight.
|
|
9
|
+
* @alpha
|
|
10
|
+
*/
|
|
11
|
+
export function useNodeHighlighting({ highlightText }) {
|
|
12
|
+
const getLabel = useCallback((node) => {
|
|
13
|
+
if (!highlightText || !node.nodeData.filtering?.isFilterTarget) {
|
|
14
|
+
return _jsx("span", { children: node.label });
|
|
15
|
+
}
|
|
16
|
+
const matchedIndexes = new Array();
|
|
17
|
+
const nodeLabel = node.label.toLocaleLowerCase();
|
|
18
|
+
const searchText = highlightText.toLocaleLowerCase();
|
|
19
|
+
let fromPosition = 0;
|
|
20
|
+
// Find all occurrences of the search text in the node label
|
|
21
|
+
while (true) {
|
|
22
|
+
const foundIndex = nodeLabel.indexOf(searchText, fromPosition);
|
|
23
|
+
if (foundIndex === -1) {
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
matchedIndexes.push(foundIndex);
|
|
27
|
+
fromPosition = foundIndex + searchText.length;
|
|
28
|
+
}
|
|
29
|
+
if (matchedIndexes.length === 0) {
|
|
30
|
+
return _jsx("span", { children: node.label });
|
|
31
|
+
}
|
|
32
|
+
// Create the final label with highlighted parts
|
|
33
|
+
const finalLabel = new Array();
|
|
34
|
+
let lastAddedPosition = 0;
|
|
35
|
+
for (let i = 0; i < matchedIndexes.length; ++i) {
|
|
36
|
+
const matchedIndex = matchedIndexes[i];
|
|
37
|
+
if (matchedIndex > lastAddedPosition) {
|
|
38
|
+
finalLabel.push(_jsx("span", { children: node.label.substring(lastAddedPosition, matchedIndex) }, `normal-${i}`));
|
|
39
|
+
lastAddedPosition = matchedIndex;
|
|
40
|
+
}
|
|
41
|
+
const endingPlace = matchedIndex + highlightText.length;
|
|
42
|
+
finalLabel.push(_jsx("mark", { children: node.label.substring(lastAddedPosition, endingPlace) }, `marked-${i}`));
|
|
43
|
+
lastAddedPosition = endingPlace;
|
|
44
|
+
}
|
|
45
|
+
if (lastAddedPosition < node.label.length) {
|
|
46
|
+
finalLabel.push(_jsx("span", { children: node.label.substring(lastAddedPosition) }, `normal-${matchedIndexes.length + 1}`));
|
|
47
|
+
}
|
|
48
|
+
return _jsx(_Fragment, { children: finalLabel });
|
|
49
|
+
}, [highlightText]);
|
|
50
|
+
return { getLabel };
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=UseNodeHighlighting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UseNodeHighlighting.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseNodeHighlighting.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAqBpC;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAAE,aAAa,EAA4B;IAC7E,MAAM,QAAQ,GAAG,WAAW,CAC1B,CAAC,IAA+B,EAAE,EAAE;QAClC,IAAI,CAAC,aAAa,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,cAAc,EAAE,CAAC;YAC/D,OAAO,yBAAO,IAAI,CAAC,KAAK,GAAQ,CAAC;QACnC,CAAC;QAED,MAAM,cAAc,GAAG,IAAI,KAAK,EAAU,CAAC;QAC3C,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,iBAAiB,EAAE,CAAC;QACjD,MAAM,UAAU,GAAG,aAAa,CAAC,iBAAiB,EAAE,CAAC;QACrD,IAAI,YAAY,GAAG,CAAC,CAAC;QACrB,4DAA4D;QAC5D,OAAO,IAAI,EAAE,CAAC;YACZ,MAAM,UAAU,GAAG,SAAS,CAAC,OAAO,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;YAC/D,IAAI,UAAU,KAAK,CAAC,CAAC,EAAE,CAAC;gBACtB,MAAM;YACR,CAAC;YACD,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAChC,YAAY,GAAG,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC;QAChD,CAAC;QAED,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAChC,OAAO,yBAAO,IAAI,CAAC,KAAK,GAAQ,CAAC;QACnC,CAAC;QAED,gDAAgD;QAChD,MAAM,UAAU,GAAG,IAAI,KAAK,EAAqB,CAAC;QAClD,IAAI,iBAAiB,GAAG,CAAC,CAAC;QAC1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,cAAc,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;YAC/C,MAAM,YAAY,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC;YACvC,IAAI,YAAY,GAAG,iBAAiB,EAAE,CAAC;gBACrC,UAAU,CAAC,IAAI,CAAC,yBAA2B,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,iBAAiB,EAAE,YAAY,CAAC,IAArE,UAAU,CAAC,EAAE,CAAgE,CAAC,CAAC;gBAC1G,iBAAiB,GAAG,YAAY,CAAC;YACnC,CAAC;YACD,MAAM,WAAW,GAAG,YAAY,GAAG,aAAa,CAAC,MAAM,CAAC;YACxD,UAAU,CAAC,IAAI,CAAC,yBAA2B,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,iBAAiB,EAAE,WAAW,CAAC,IAApE,UAAU,CAAC,EAAE,CAA+D,CAAC,CAAC;YACzG,iBAAiB,GAAG,WAAW,CAAC;QAClC,CAAC;QACD,IAAI,iBAAiB,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;YAC1C,UAAU,CAAC,IAAI,CAAC,yBAAmD,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,iBAAiB,CAAC,IAA/E,UAAU,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAkD,CAAC,CAAC;QACtH,CAAC;QAED,OAAO,4BAAG,UAAU,GAAI,CAAC;IAC3B,CAAC,EACD,CAAC,aAAa,CAAC,CAChB,CAAC;IAEF,OAAO,EAAE,QAAQ,EAAE,CAAC;AACtB,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useCallback } from \"react\";\nimport { PresentationHierarchyNode } 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: PresentationHierarchyNode) => React.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: PresentationHierarchyNode) => {\n if (!highlightText || !node.nodeData.filtering?.isFilterTarget) {\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<React.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"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { TreeRendererProps } from "./Renderers.js";
|
|
1
2
|
import { PresentationHierarchyNode } from "./TreeNode.js";
|
|
2
|
-
import { useTree } from "./UseTree.js";
|
|
3
3
|
/**
|
|
4
4
|
* A union of different supported selection modes in a tree component:
|
|
5
5
|
* - `none` - no selection is allowed,
|
|
@@ -21,9 +21,9 @@ export type SelectionMode = "none" | "single" | "extended" | "multiple";
|
|
|
21
21
|
export type SelectionChangeType = "add" | "replace" | "remove";
|
|
22
22
|
/**
|
|
23
23
|
* Props for `useSelectionHandler` hook.
|
|
24
|
-
* @
|
|
24
|
+
* @alpha
|
|
25
25
|
*/
|
|
26
|
-
type UseSelectionHandlerProps = Pick<
|
|
26
|
+
type UseSelectionHandlerProps = Pick<TreeRendererProps, "selectNodes" | "rootNodes"> & {
|
|
27
27
|
/** Selection mode that the component is working in. */
|
|
28
28
|
selectionMode: SelectionMode;
|
|
29
29
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseSelectionHandler.d.ts","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseSelectionHandler.ts"],"names":[],"mappings":"AAMA,OAAO,
|
|
1
|
+
{"version":3,"file":"UseSelectionHandler.d.ts","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseSelectionHandler.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAE1D;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,QAAQ,GAAG,UAAU,GAAG,UAAU,CAAC;AAExE;;;;;;;GAOG;AACH,MAAM,MAAM,mBAAmB,GAAG,KAAK,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE/D;;;GAGG;AACH,KAAK,wBAAwB,GAAG,IAAI,CAAC,iBAAiB,EAAE,aAAa,GAAG,WAAW,CAAC,GAAG;IACrF,uDAAuD;IACvD,aAAa,EAAE,aAAa,CAAC;CAC9B,CAAC;AAEF;;;GAGG;AACH,UAAU,yBAAyB;IACjC,0EAA0E;IAC1E,WAAW,EAAE,CAAC,IAAI,EAAE,yBAAyB,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,KAAK,IAAI,CAAC;IAC9H,iFAAiF;IACjF,aAAa,EAAE,CAAC,IAAI,EAAE,yBAAyB,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;CACxH;AAOD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,GAAG,yBAAyB,CA8D9F"}
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import { useCallback, useEffect, useRef } from "react";
|
|
6
|
-
import { isPresentationHierarchyNode } from "./TreeNode.js";
|
|
7
6
|
/**
|
|
8
7
|
* A react hook that helps implement different selection modes in a tree component created using `useTree` hook.
|
|
9
8
|
* @public
|
|
@@ -16,9 +15,6 @@ export function useSelectionHandler(props) {
|
|
|
16
15
|
nodeIdToIndexMap: new Map(),
|
|
17
16
|
});
|
|
18
17
|
useEffect(() => {
|
|
19
|
-
if (!rootNodes) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
18
|
state.current = computeFlatNodeList(rootNodes);
|
|
23
19
|
}, [rootNodes]);
|
|
24
20
|
const getNodeRange = (firstId, secondId) => {
|
|
@@ -75,16 +71,13 @@ function getExtendedSelectionAction(isSelected, shiftDown, ctrlDown) {
|
|
|
75
71
|
if (ctrlDown) {
|
|
76
72
|
return { select: "node", type: isSelected ? "add" : "remove" };
|
|
77
73
|
}
|
|
78
|
-
return { select: "node", type:
|
|
74
|
+
return { select: "node", type: "replace" };
|
|
79
75
|
}
|
|
80
76
|
function computeFlatNodeList(rootNodes) {
|
|
81
77
|
const flatNodeList = [];
|
|
82
78
|
const nodeIdToIndexMap = new Map();
|
|
83
79
|
const flattenNodeRecursively = (nodes) => {
|
|
84
80
|
nodes.forEach((node) => {
|
|
85
|
-
if (!isPresentationHierarchyNode(node)) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
81
|
nodeIdToIndexMap.set(node.id, flatNodeList.length);
|
|
89
82
|
flatNodeList.push(node.id);
|
|
90
83
|
if (node.isExpanded && typeof node.children !== "boolean") {
|