@itwin/presentation-hierarchies-react 2.0.0-alpha.1 → 2.0.0-alpha.10
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 +107 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.d.ts +21 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.js +30 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.d.ts +5 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.js +1 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.d.ts +31 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.js +39 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.d.ts +18 -7
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.js +11 -11
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.d.ts +19 -18
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js +35 -11
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.d.ts +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.js +29 -3
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react.d.ts +2 -2
- package/lib/esm/presentation-hierarchies-react.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react.js +2 -2
- package/lib/esm/presentation-hierarchies-react.js.map +1 -1
- package/package.json +16 -12
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButtons.d.ts +0 -12
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButtons.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButtons.js +0 -19
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButtons.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeLevelRenderer.d.ts +0 -12
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeLevelRenderer.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeLevelRenderer.js +0 -10
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeLevelRenderer.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,99 @@
|
|
|
1
1
|
# @itwin/presentation-hierarchies-react
|
|
2
2
|
|
|
3
|
+
## 2.0.0-alpha.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#913](https://github.com/iTwin/presentation/pull/913): Removed outline showed after node expander is clicked.
|
|
8
|
+
|
|
9
|
+
## 2.0.0-alpha.9
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#906](https://github.com/iTwin/presentation/pull/906): Replaced `TreeNodeRenderer.getIcon` prop with `getDecorations` prop.
|
|
14
|
+
|
|
15
|
+
The `getIcon` prop took either an icon URI, or a `ReactElement`. The new `getDecorations` prop allows passing multiple React elements, allowing consumers to render not just the icon, but also addition components like a tag or a color swatch. Migration:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
// previously, when `getIcon` returned a `ReactElement`:
|
|
19
|
+
function myGetIcon(node: PresentationHierarchyNode): React.ReactElement {
|
|
20
|
+
// implementation...
|
|
21
|
+
}
|
|
22
|
+
<TreeNodeRenderer getIcon={myGetIcon} />
|
|
23
|
+
|
|
24
|
+
// now:
|
|
25
|
+
<TreeNodeRenderer getDecorations={myGetIcon} />
|
|
26
|
+
|
|
27
|
+
// previously, when `getIcon` returned an icon URI:
|
|
28
|
+
function myGetIconUri(node: PresentationHierarchyNode): string {
|
|
29
|
+
// implementation...
|
|
30
|
+
}
|
|
31
|
+
<TreeNodeRenderer getIcon={myGetIconUri} />
|
|
32
|
+
|
|
33
|
+
// now:
|
|
34
|
+
<TreeNodeRenderer getDecorations={(node) => <Icon href={myGetIconUri(node)} />} />
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
- [#911](https://github.com/iTwin/presentation/pull/911): Fix incorrect left padding on tree items
|
|
38
|
+
|
|
39
|
+
## 2.0.0-alpha.8
|
|
40
|
+
|
|
41
|
+
### Patch Changes
|
|
42
|
+
|
|
43
|
+
- [#903](https://github.com/iTwin/presentation/pull/903): Added `activeDescription` optional property to TreeItemAction interface, which when provided a value will display a dot above the button indicating an active state. The provided value is used to set accesible description and should explain why the action item is active.
|
|
44
|
+
- [#903](https://github.com/iTwin/presentation/pull/903): Changed `createFilterAction` function to a React hook and renamed it to `useFilterAction`.
|
|
45
|
+
|
|
46
|
+
## 2.0.0-alpha.7
|
|
47
|
+
|
|
48
|
+
### Patch Changes
|
|
49
|
+
|
|
50
|
+
- [#892](https://github.com/iTwin/presentation/pull/892): Fix focus outline for tree items not being visible on action items click.
|
|
51
|
+
- [#894](https://github.com/iTwin/presentation/pull/894): Fix `treeRenderer` property `getSublabel` not being used.
|
|
52
|
+
|
|
53
|
+
## 2.0.0-alpha.6
|
|
54
|
+
|
|
55
|
+
### Patch Changes
|
|
56
|
+
|
|
57
|
+
- [#890](https://github.com/iTwin/presentation/pull/890): Fix alpha peer dependencies to no longer have caret.
|
|
58
|
+
|
|
59
|
+
## 2.0.0-alpha.5
|
|
60
|
+
|
|
61
|
+
### Minor Changes
|
|
62
|
+
|
|
63
|
+
- [#883](https://github.com/iTwin/presentation/pull/883): Trees rendered with `TreeRenderer` will now be virtualized.
|
|
64
|
+
|
|
65
|
+
## 2.0.0-alpha.4
|
|
66
|
+
|
|
67
|
+
### Minor Changes
|
|
68
|
+
|
|
69
|
+
- [#878](https://github.com/iTwin/presentation/pull/878): Tree node renderer now uses `Tree.ItemAction`. `Show` property now takes in undefined values, values behave like this:
|
|
70
|
+
|
|
71
|
+
- `undefined` - visible on hover/focus,
|
|
72
|
+
- `true` - visible at all times,
|
|
73
|
+
- `false` - hidden at all times.
|
|
74
|
+
|
|
75
|
+
Updated peer dependencies:
|
|
76
|
+
|
|
77
|
+
- itwinui-icons to 5.0.0-alpha.3,
|
|
78
|
+
- itwinui-react to 5.0.0-alpha.6,
|
|
79
|
+
|
|
80
|
+
## 2.0.0-alpha.3
|
|
81
|
+
|
|
82
|
+
### Patch Changes
|
|
83
|
+
|
|
84
|
+
- [#870](https://github.com/iTwin/presentation/pull/870): `TreeRenderer` and `TreeNodeRenderer` now take actions as specification function array.
|
|
85
|
+
|
|
86
|
+
- `label`: Action item's label.
|
|
87
|
+
- `action`: The action performed when the button is clicked.
|
|
88
|
+
- `show` A boolean determining whether the button should be displayed.
|
|
89
|
+
- `icon`: The button's icon.
|
|
90
|
+
|
|
91
|
+
## 2.0.0-alpha.2
|
|
92
|
+
|
|
93
|
+
### Major Changes
|
|
94
|
+
|
|
95
|
+
- [#864](https://github.com/iTwin/presentation/pull/864): Add `@itwin/itwinui-icons` as optional peer dependency (only required when using iTwinUI-based tree / node renderers).
|
|
96
|
+
|
|
3
97
|
## 2.0.0-alpha.1
|
|
4
98
|
|
|
5
99
|
### Patch Changes
|
|
@@ -20,6 +114,19 @@
|
|
|
20
114
|
|
|
21
115
|
- [#847](https://github.com/iTwin/presentation/pull/847): Moving tree rendering components to a new design systems.
|
|
22
116
|
|
|
117
|
+
## 1.6.2
|
|
118
|
+
|
|
119
|
+
### Patch Changes
|
|
120
|
+
|
|
121
|
+
- [#873](https://github.com/iTwin/presentation/pull/873): Fix hierarchy level size exceeds limit info message wrapping in narrow Tree on Safari browser.
|
|
122
|
+
- [#873](https://github.com/iTwin/presentation/pull/873): Do not require two clicks to expand node with filter buttons on touch devices.
|
|
123
|
+
|
|
124
|
+
## 1.6.1
|
|
125
|
+
|
|
126
|
+
### Patch Changes
|
|
127
|
+
|
|
128
|
+
- [#866](https://github.com/iTwin/presentation/pull/866): Updated hierarchy level size exceeded info message styling in narrow tree component to avoid cutting out text.
|
|
129
|
+
|
|
23
130
|
## 1.6.0
|
|
24
131
|
|
|
25
132
|
### Minor Changes
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { PresentationTreeNode } from "../TreeNode.js";
|
|
2
|
+
/** @alpha */
|
|
3
|
+
interface PlaceholderNode {
|
|
4
|
+
id: string;
|
|
5
|
+
level: number;
|
|
6
|
+
placeholder: true;
|
|
7
|
+
}
|
|
8
|
+
/** @alpha */
|
|
9
|
+
export type FlatNode<TNode extends PresentationTreeNode = PresentationTreeNode> = {
|
|
10
|
+
level: number;
|
|
11
|
+
levelSize: number;
|
|
12
|
+
posInLevel: number;
|
|
13
|
+
} & TNode;
|
|
14
|
+
/** @alpha */
|
|
15
|
+
export type FlatTreeNode<TNode extends PresentationTreeNode = PresentationTreeNode> = FlatNode<TNode> | PlaceholderNode;
|
|
16
|
+
/** @alpha */
|
|
17
|
+
export declare function isPlaceholderNode(node: FlatTreeNode): node is PlaceholderNode;
|
|
18
|
+
/** @alpha */
|
|
19
|
+
export declare function flattenNodes(rootNodes: PresentationTreeNode[]): FlatTreeNode<PresentationTreeNode>[];
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=FlatTreeNode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FlatTreeNode.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/FlatTreeNode.ts"],"names":[],"mappings":"AAKA,OAAO,EAA+B,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAEnF,aAAa;AACb,UAAU,eAAe;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,IAAI,CAAC;CACnB;AAED,aAAa;AACb,MAAM,MAAM,QAAQ,CAAC,KAAK,SAAS,oBAAoB,GAAG,oBAAoB,IAAI;IAChF,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,GAAG,KAAK,CAAC;AAEV,aAAa;AACb,MAAM,MAAM,YAAY,CAAC,KAAK,SAAS,oBAAoB,GAAG,oBAAoB,IAAI,QAAQ,CAAC,KAAK,CAAC,GAAG,eAAe,CAAC;AAExH,aAAa;AACb,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,IAAI,eAAe,CAE7E;AAED,aAAa;AACb,wBAAgB,YAAY,CAAC,SAAS,EAAE,oBAAoB,EAAE,wCAE7D"}
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
import { isPresentationHierarchyNode } from "../TreeNode.js";
|
|
6
|
+
/** @alpha */
|
|
7
|
+
export function isPlaceholderNode(node) {
|
|
8
|
+
return "placeholder" in node;
|
|
9
|
+
}
|
|
10
|
+
/** @alpha */
|
|
11
|
+
export function flattenNodes(rootNodes) {
|
|
12
|
+
return getFlatNodes(rootNodes, 1);
|
|
13
|
+
}
|
|
14
|
+
function getFlatNodes(nodes, level) {
|
|
15
|
+
const flatNodes = [];
|
|
16
|
+
nodes.forEach((node, index) => {
|
|
17
|
+
flatNodes.push({ ...node, level, levelSize: nodes.length, posInLevel: index + 1 });
|
|
18
|
+
if (!isPresentationHierarchyNode(node) || !node.isExpanded) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (node.children !== true) {
|
|
22
|
+
const childNodes = getFlatNodes(node.children, level + 1);
|
|
23
|
+
flatNodes.push(...childNodes);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
flatNodes.push({ id: `${node.id}-children-placeholder`, level: level + 1, placeholder: true });
|
|
27
|
+
});
|
|
28
|
+
return flatNodes;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=FlatTreeNode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FlatTreeNode.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/FlatTreeNode.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,2BAA2B,EAAwB,MAAM,gBAAgB,CAAC;AAmBnF,aAAa;AACb,MAAM,UAAU,iBAAiB,CAAC,IAAkB;IAClD,OAAO,aAAa,IAAI,IAAI,CAAC;AAC/B,CAAC;AAED,aAAa;AACb,MAAM,UAAU,YAAY,CAAC,SAAiC;IAC5D,OAAO,YAAY,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;AACpC,CAAC;AAED,SAAS,YAAY,CAAC,KAA6B,EAAE,KAAa;IAChE,MAAM,SAAS,GAAmB,EAAE,CAAC;IACrC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QAC5B,SAAS,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC;QACnF,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YAC3D,OAAO;QACT,CAAC;QACD,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;YAC3B,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;YAC1D,SAAS,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,CAAC;YAC9B,OAAO;QACT,CAAC;QAED,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,GAAG,IAAI,CAAC,EAAE,uBAAuB,EAAE,KAAK,EAAE,KAAK,GAAG,CAAC,EAAE,WAAW,EAAE,IAAI,EAA4B,CAAC,CAAC;IAC3H,CAAC,CAAC,CAAC;IACH,OAAO,SAAS,CAAC;AACnB,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 { isPresentationHierarchyNode, PresentationTreeNode } from \"../TreeNode.js\";\n\n/** @alpha */\ninterface PlaceholderNode {\n id: string;\n level: number;\n placeholder: true;\n}\n\n/** @alpha */\nexport type FlatNode<TNode extends PresentationTreeNode = PresentationTreeNode> = {\n level: number;\n levelSize: number;\n posInLevel: number;\n} & TNode;\n\n/** @alpha */\nexport type FlatTreeNode<TNode extends PresentationTreeNode = PresentationTreeNode> = FlatNode<TNode> | PlaceholderNode;\n\n/** @alpha */\nexport function isPlaceholderNode(node: FlatTreeNode): node is PlaceholderNode {\n return \"placeholder\" in node;\n}\n\n/** @alpha */\nexport function flattenNodes(rootNodes: PresentationTreeNode[]) {\n return getFlatNodes(rootNodes, 1);\n}\n\nfunction getFlatNodes(nodes: PresentationTreeNode[], level: number) {\n const flatNodes: FlatTreeNode[] = [];\n nodes.forEach((node, index) => {\n flatNodes.push({ ...node, level, levelSize: nodes.length, posInLevel: index + 1 });\n if (!isPresentationHierarchyNode(node) || !node.isExpanded) {\n return;\n }\n if (node.children !== true) {\n const childNodes = getFlatNodes(node.children, level + 1);\n flatNodes.push(...childNodes);\n return;\n }\n\n flatNodes.push({ id: `${node.id}-children-placeholder`, level: level + 1, placeholder: true } satisfies PlaceholderNode);\n });\n return flatNodes;\n}\n"]}
|
|
@@ -14,6 +14,11 @@ export interface LocalizedStrings {
|
|
|
14
14
|
* Default value: `Apply filter`.
|
|
15
15
|
*/
|
|
16
16
|
filterHierarchyLevel: string;
|
|
17
|
+
/**
|
|
18
|
+
* Accesible description for applied hierarchy filter button.
|
|
19
|
+
* Default value: `Filter is applied`.
|
|
20
|
+
*/
|
|
21
|
+
filterHierarchyLevelActiveDescription: string;
|
|
17
22
|
/**
|
|
18
23
|
* Title for clear hierarchy filter button.
|
|
19
24
|
* Default value: `Clear active filter`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalizationContext.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/LocalizationContext.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAiB,iBAAiB,EAAmC,MAAM,OAAO,CAAC;AAE1F;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,yBAAyB,EAAE,MAAM,CAAC;IAClC;;;OAGG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAC3B;;;OAGG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,gCAAgC,EAAE,MAAM,CAAC;IACzC;;;OAGG;IACH,sBAAsB,EAAE,MAAM,CAAC;IAC/B;;;OAGG;IACH,mCAAmC,EAAE,MAAM,CAAC;IAC5C;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAED,gBAAgB;AAChB,MAAM,WAAW,mBAAmB;IAClC,gBAAgB,EAAE,gBAAgB,CAAC;CACpC;
|
|
1
|
+
{"version":3,"file":"LocalizationContext.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/LocalizationContext.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAiB,iBAAiB,EAAmC,MAAM,OAAO,CAAC;AAE1F;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,oBAAoB,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,qCAAqC,EAAE,MAAM,CAAC;IAC9C;;;OAGG;IACH,yBAAyB,EAAE,MAAM,CAAC;IAClC;;;OAGG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAC3B;;;OAGG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,gCAAgC,EAAE,MAAM,CAAC;IACzC;;;OAGG;IACH,sBAAsB,EAAE,MAAM,CAAC;IAC/B;;;OAGG;IACH,mCAAmC,EAAE,MAAM,CAAC;IAC5C;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAED,gBAAgB;AAChB,MAAM,WAAW,mBAAmB;IAClC,gBAAgB,EAAE,gBAAgB,CAAC;CACpC;AAiBD;;;GAGG;AACH,UAAU,gCAAgC;IACxC,gDAAgD;IAChD,gBAAgB,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC9C;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,EAAE,gBAAgB,EAAE,QAAQ,EAAE,EAAE,iBAAiB,CAAC,gCAAgC,CAAC,2CAQ9H;AAED,gBAAgB;AAChB,wBAAgB,sBAAsB,wBAErC"}
|
|
@@ -7,6 +7,7 @@ import { createContext, useContext, useEffect, useState } from "react";
|
|
|
7
7
|
const defaultLocalizedStrings = {
|
|
8
8
|
loading: "Loading...",
|
|
9
9
|
filterHierarchyLevel: "Apply filter",
|
|
10
|
+
filterHierarchyLevelActiveDescription: "Filter is applied",
|
|
10
11
|
clearHierarchyLevelFilter: "Clear active filter",
|
|
11
12
|
noFilteredChildren: "No child nodes match current filter",
|
|
12
13
|
resultLimitExceeded: "There are more items than allowed limit of {{limit}}.",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalizationContext.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/LocalizationContext.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,aAAa,EAAqB,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"LocalizationContext.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/LocalizationContext.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,aAAa,EAAqB,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAgE1F,MAAM,uBAAuB,GAAqB;IAChD,OAAO,EAAE,YAAY;IACrB,oBAAoB,EAAE,cAAc;IACpC,qCAAqC,EAAE,mBAAmB;IAC1D,yBAAyB,EAAE,qBAAqB;IAChD,kBAAkB,EAAE,qCAAqC;IACzD,mBAAmB,EAAE,uDAAuD;IAC5E,gCAAgC,EAAE,0GAA0G;IAC5I,sBAAsB,EAAE,oEAAoE;IAC5F,mCAAmC,EAAE,wEAAwE;IAC7G,KAAK,EAAE,OAAO;CACf,CAAC;AAEF,MAAM,mBAAmB,GAAG,aAAa,CAAsB,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,CAAC,CAAC;AAW9G;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CAAC,EAAE,gBAAgB,EAAE,QAAQ,EAAuD;IAC7H,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,EAAE,gBAAgB,EAAE,EAAE,GAAG,uBAAuB,EAAE,GAAG,gBAAgB,EAAE,EAAE,CAAC,CAAC;IAE9G,SAAS,CAAC,GAAG,EAAE;QACb,QAAQ,CAAC,EAAE,gBAAgB,EAAE,EAAE,GAAG,uBAAuB,EAAE,GAAG,gBAAgB,EAAE,EAAE,CAAC,CAAC;IACtF,CAAC,EAAE,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAEvB,OAAO,KAAC,mBAAmB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAAgC,CAAC;AAC/F,CAAC;AAED,gBAAgB;AAChB,MAAM,UAAU,sBAAsB;IACpC,OAAO,UAAU,CAAC,mBAAmB,CAAC,CAAC;AACzC,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 { createContext, PropsWithChildren, useContext, useEffect, useState } from \"react\";\n\n/**\n * Localized strings used in the components.\n * @public\n */\nexport interface LocalizedStrings {\n /**\n * Message displayed when nodes are loading.\n * Default value: `Loading...`.\n */\n loading: string;\n /**\n * Title for apply hierarchy filter button.\n * Default value: `Apply filter`.\n */\n filterHierarchyLevel: string;\n /**\n * Accesible description for applied hierarchy filter button.\n * Default value: `Filter is applied`.\n */\n filterHierarchyLevelActiveDescription: string;\n /**\n * Title for clear hierarchy filter button.\n * Default value: `Clear active filter`.\n */\n clearHierarchyLevelFilter: string;\n /**\n * Message displayed when no nodes matching filter are found.\n * Default value: `No child nodes match current filter`.\n */\n noFilteredChildren: string;\n /**\n * Message displayed when result limit exceeds hierarchy size limit.\n * Default value: `There are more items than allowed limit of {{limit}}.`.\n */\n resultLimitExceeded: string;\n /**\n * Message displayed when result limit exceeds hierarchy size limit and hierarchy filtering is enabled.\n * Default value: `Please provide <link>additional filtering</link> - there are more items than allowed limit of {{limit}}.`.\n */\n resultLimitExceededWithFiltering: string;\n /**\n * Message displayed when hierarchy size limit can be overridden.\n * Default value: `<link>Increase the hierarchy level size limit to {{limit}}.</link>`.\n */\n increaseHierarchyLimit: string;\n /**\n * Message displayed when hierarchy size limit can be overridden and hierarchy filtering is enabled.\n * Default value: `Or, <link>increase the hierarchy level size limit to {{limit}}.</link>`.\n */\n increaseHierarchyLimitWithFiltering: string;\n /**\n * Label for retry action.\n * Default value: `Retry`.\n */\n retry: string;\n}\n\n/** @internal */\nexport interface LocalizationContext {\n localizedStrings: LocalizedStrings;\n}\n\nconst defaultLocalizedStrings: LocalizedStrings = {\n loading: \"Loading...\",\n filterHierarchyLevel: \"Apply filter\",\n filterHierarchyLevelActiveDescription: \"Filter is applied\",\n clearHierarchyLevelFilter: \"Clear active filter\",\n noFilteredChildren: \"No child nodes match current filter\",\n resultLimitExceeded: \"There are more items than allowed limit of {{limit}}.\",\n resultLimitExceededWithFiltering: \"Please provide <link>additional filtering</link> - there are more items than allowed limit of {{limit}}.\",\n increaseHierarchyLimit: \"<link>Increase the hierarchy level size limit to {{limit}}.</link>\",\n increaseHierarchyLimitWithFiltering: \"Or, <link>increase the hierarchy level size limit to {{limit}}.</link>\",\n retry: \"Retry\",\n};\n\nconst localizationContext = createContext<LocalizationContext>({ localizedStrings: defaultLocalizedStrings });\n\n/**\n * Properties for `LocalizationContextProvider`.\n * @public\n */\ninterface LocalizationContextProviderProps {\n /** Localized strings used in the components. */\n localizedStrings?: Partial<LocalizedStrings>;\n}\n\n/**\n * Context provider for localized strings used in the components.\n * @public\n */\nexport function LocalizationContextProvider({ localizedStrings, children }: PropsWithChildren<LocalizationContextProviderProps>) {\n const [state, setState] = useState({ localizedStrings: { ...defaultLocalizedStrings, ...localizedStrings } });\n\n useEffect(() => {\n setState({ localizedStrings: { ...defaultLocalizedStrings, ...localizedStrings } });\n }, [localizedStrings]);\n\n return <localizationContext.Provider value={state}>{children}</localizationContext.Provider>;\n}\n\n/** @internal */\nexport function useLocalizationContext() {\n return useContext(localizationContext);\n}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { PresentationHierarchyNode } from "../TreeNode.js";
|
|
2
|
+
import { HierarchyLevelDetails, useTree } from "../UseTree.js";
|
|
3
|
+
/** @alpha */
|
|
4
|
+
export interface TreeItemAction {
|
|
5
|
+
label: string;
|
|
6
|
+
action: () => void;
|
|
7
|
+
icon: string;
|
|
8
|
+
/**
|
|
9
|
+
* Determines action items visibility:
|
|
10
|
+
* - `False` - action item is hidden.
|
|
11
|
+
* - `True` - action item is visible at all times.
|
|
12
|
+
* - `Undefined` - action item is visible on hover/focus.
|
|
13
|
+
*/
|
|
14
|
+
show?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Provide a value when action button is in active state to display a dot above the button.
|
|
17
|
+
* Provided text value is used to set accessible description it should descibe why the action is in active state.
|
|
18
|
+
* If left undefined the action item will be rendered normally.
|
|
19
|
+
*/
|
|
20
|
+
activeDescription?: string;
|
|
21
|
+
}
|
|
22
|
+
/** @alpha */
|
|
23
|
+
export type FilterActionProps = {
|
|
24
|
+
/** Action to perform when the filter button is clicked for this node. */
|
|
25
|
+
onFilter?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;
|
|
26
|
+
} & Partial<Pick<ReturnType<typeof useTree>, "getHierarchyLevelDetails">>;
|
|
27
|
+
/** @internal */
|
|
28
|
+
export declare function TreeActionButton({ show, label, action, icon, activeDescription }: TreeItemAction): import("react/jsx-runtime").JSX.Element;
|
|
29
|
+
/** @alpha */
|
|
30
|
+
export declare function useFilterAction({ onFilter, getHierarchyLevelDetails }: FilterActionProps): (node: PresentationHierarchyNode) => TreeItemAction;
|
|
31
|
+
//# sourceMappingURL=TreeActionButton.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreeActionButton.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeActionButton.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAK/D,aAAa;AACb,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,aAAa;AACb,MAAM,MAAM,iBAAiB,GAAG;IAC9B,yEAAyE;IACzE,QAAQ,CAAC,EAAE,CAAC,qBAAqB,EAAE,qBAAqB,KAAK,IAAI,CAAC;CACnE,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,0BAA0B,CAAC,CAAC,CAAC;AAE1E,gBAAgB;AAChB,wBAAgB,gBAAgB,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,EAAE,EAAE,cAAc,2CAUhG;AAED,aAAa;AACb,wBAAgB,eAAe,CAAC,EAAE,QAAQ,EAAE,wBAAwB,EAAE,EAAE,iBAAiB,GAAG,CAAC,IAAI,EAAE,yBAAyB,KAAK,cAAc,CAyB9I"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx as _jsx } 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 { IconButton, Tree } from "@itwin/itwinui-react/bricks";
|
|
7
|
+
import { useLocalizationContext } from "./LocalizationContext.js";
|
|
8
|
+
const filterIcon = new URL("@itwin/itwinui-icons/filter.svg", import.meta.url).href;
|
|
9
|
+
/** @internal */
|
|
10
|
+
export function TreeActionButton({ show, label, action, icon, activeDescription }) {
|
|
11
|
+
return (_jsx(Tree.ItemAction, { render: _jsx(IconButton, { dot: activeDescription, icon: icon, variant: "ghost", label: label }), label: label, icon: icon, visible: show, onClick: action }));
|
|
12
|
+
}
|
|
13
|
+
/** @alpha */
|
|
14
|
+
export function useFilterAction({ onFilter, getHierarchyLevelDetails }) {
|
|
15
|
+
const { localizedStrings } = useLocalizationContext();
|
|
16
|
+
return (node) => {
|
|
17
|
+
const handleVisibility = () => {
|
|
18
|
+
if (!onFilter || !node.isFilterable) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
if (node.isFiltered) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
label: localizedStrings.filterHierarchyLevel,
|
|
28
|
+
action: () => {
|
|
29
|
+
const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.id);
|
|
30
|
+
hierarchyLevelDetails && onFilter?.(hierarchyLevelDetails);
|
|
31
|
+
},
|
|
32
|
+
show: handleVisibility(),
|
|
33
|
+
isDropdownAction: false,
|
|
34
|
+
activeDescription: node.isFiltered ? localizedStrings.filterHierarchyLevelActiveDescription : undefined,
|
|
35
|
+
icon: filterIcon,
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=TreeActionButton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreeActionButton.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeActionButton.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAG/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,iCA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AAC,UAAU,CAAC,CAAC,CAAC,gBAAgB,CAAC,qCAAqC,CAAC,CAAC,CAAC,SAAS;YACvG,IAAI,EAAE,UAAU;SACjB,CAAC;IACJ,CAAC,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 { IconButton, Tree } from \"@itwin/itwinui-react/bricks\";\nimport { PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { HierarchyLevelDetails, useTree } from \"../UseTree.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\n\nconst filterIcon = new URL(\"@itwin/itwinui-icons/filter.svg\", import.meta.url).href;\n\n/** @alpha */\nexport interface TreeItemAction {\n label: string;\n action: () => void;\n icon: string;\n /**\n * Determines action items visibility:\n * - `False` - action item is hidden.\n * - `True` - action item is visible at all times.\n * - `Undefined` - action item is visible on hover/focus.\n */\n show?: boolean;\n /**\n * Provide a value when action button is in active state to display a dot above the button.\n * Provided text value is used to set accessible description it should descibe why the action is in active state.\n * If left undefined the action item will be rendered normally.\n */\n activeDescription?: string;\n}\n\n/** @alpha */\nexport type FilterActionProps = {\n /** Action to perform when the filter button is clicked for this node. */\n onFilter?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;\n} & Partial<Pick<ReturnType<typeof useTree>, \"getHierarchyLevelDetails\">>;\n\n/** @internal */\nexport function TreeActionButton({ show, label, action, icon, activeDescription }: TreeItemAction) {\n return (\n <Tree.ItemAction\n render={<IconButton dot={activeDescription} icon={icon} variant={\"ghost\"} label={label} />}\n label={label}\n icon={icon}\n visible={show}\n onClick={action}\n />\n );\n}\n\n/** @alpha */\nexport function useFilterAction({ onFilter, getHierarchyLevelDetails }: FilterActionProps): (node: PresentationHierarchyNode) => TreeItemAction {\n const { localizedStrings } = useLocalizationContext();\n return (node) => {\n const handleVisibility = () => {\n if (!onFilter || !node.isFilterable) {\n return false;\n }\n if (node.isFiltered) {\n return true;\n }\n return undefined;\n };\n\n return {\n label: localizedStrings.filterHierarchyLevel,\n action: () => {\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.id);\n hierarchyLevelDetails && onFilter?.(hierarchyLevelDetails);\n },\n show: handleVisibility(),\n isDropdownAction: false,\n activeDescription: node.isFiltered ? localizedStrings.filterHierarchyLevelActiveDescription : undefined,\n icon: filterIcon,\n };\n };\n}\n"]}
|
|
@@ -1,12 +1,23 @@
|
|
|
1
|
-
import { RefAttributes } from "react";
|
|
1
|
+
import { CSSProperties, ForwardRefExoticComponent, RefAttributes } from "react";
|
|
2
2
|
import { PresentationInfoNode } from "../TreeNode.js";
|
|
3
|
-
import { useTree } from "../UseTree.js";
|
|
4
|
-
import {
|
|
3
|
+
import { HierarchyLevelDetails, useTree } from "../UseTree.js";
|
|
4
|
+
import { FlatNode } from "./FlatTreeNode.js";
|
|
5
|
+
/** @alpha */
|
|
6
|
+
export interface TreeErrorItemProps {
|
|
7
|
+
/** A callback to reload a hierarchy level when an error occurs and `retry` button is clicked. */
|
|
8
|
+
reloadTree?: (options: {
|
|
9
|
+
parentNodeId: string | undefined;
|
|
10
|
+
state: "reset";
|
|
11
|
+
}) => void;
|
|
12
|
+
/** Action to perform when the filter button is clicked for this node. */
|
|
13
|
+
onFilterClick?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;
|
|
14
|
+
}
|
|
5
15
|
interface TreeErrorRendererOwnProps {
|
|
6
|
-
node: PresentationInfoNode
|
|
16
|
+
node: FlatNode<PresentationInfoNode>;
|
|
17
|
+
style?: CSSProperties;
|
|
7
18
|
}
|
|
8
|
-
type TreeErrorRendererProps = TreeErrorRendererOwnProps &
|
|
9
|
-
/** @
|
|
10
|
-
export declare const TreeErrorRenderer:
|
|
19
|
+
type TreeErrorRendererProps = TreeErrorRendererOwnProps & TreeErrorItemProps & Partial<Pick<ReturnType<typeof useTree>, "getHierarchyLevelDetails">>;
|
|
20
|
+
/** @internal */
|
|
21
|
+
export declare const TreeErrorRenderer: ForwardRefExoticComponent<TreeErrorRendererProps & RefAttributes<HTMLElement>>;
|
|
11
22
|
export {};
|
|
12
23
|
//# sourceMappingURL=TreeErrorRenderer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeErrorRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeErrorRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,
|
|
1
|
+
{"version":3,"file":"TreeErrorRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeErrorRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,EAA4B,aAAa,EAAc,yBAAyB,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAGtH,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAG7C,aAAa;AACb,MAAM,WAAW,kBAAkB;IACjC,iGAAiG;IACjG,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE;QAAE,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IACrF,yEAAyE;IACzE,aAAa,CAAC,EAAE,CAAC,qBAAqB,EAAE,qBAAqB,KAAK,IAAI,CAAC;CACxE;AAED,UAAU,yBAAyB;IACjC,IAAI,EAAE,QAAQ,CAAC,oBAAoB,CAAC,CAAC;IACrC,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB;AAED,KAAK,sBAAsB,GAAG,yBAAyB,GAAG,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,0BAA0B,CAAC,CAAC,CAAC;AAErJ,gBAAgB;AAChB,eAAO,MAAM,iBAAiB,EAAE,yBAAyB,CAAC,sBAAsB,GAAG,aAAa,CAAC,WAAW,CAAC,CAoD5G,CAAC"}
|
|
@@ -7,26 +7,26 @@ import { forwardRef } from "react";
|
|
|
7
7
|
import { Anchor, Text, Tree } from "@itwin/itwinui-react/bricks";
|
|
8
8
|
import { MAX_LIMIT_OVERRIDE } from "../internal/Utils.js";
|
|
9
9
|
import { useLocalizationContext } from "./LocalizationContext.js";
|
|
10
|
-
/** @
|
|
11
|
-
export const TreeErrorRenderer = forwardRef(({ node, getHierarchyLevelDetails, onFilterClick, reloadTree }, forwardedRef) => {
|
|
10
|
+
/** @internal */
|
|
11
|
+
export const TreeErrorRenderer = forwardRef(({ node, getHierarchyLevelDetails, onFilterClick, reloadTree, ...rest }, forwardedRef) => {
|
|
12
12
|
const { localizedStrings } = useLocalizationContext();
|
|
13
13
|
if (node.type === "ResultSetTooLarge") {
|
|
14
|
-
return (_jsx(ResultSetTooLargeNode, { ref: forwardedRef, limit: node.resultSetSizeLimit, onOverrideLimit: getHierarchyLevelDetails ? (limit) => getHierarchyLevelDetails(node.parentNodeId)?.setSizeLimit(limit) : undefined, onFilterClick: onFilterClick
|
|
14
|
+
return (_jsx(ResultSetTooLargeNode, { ...rest, ref: forwardedRef, limit: node.resultSetSizeLimit, onOverrideLimit: getHierarchyLevelDetails ? (limit) => getHierarchyLevelDetails(node.parentNodeId)?.setSizeLimit(limit) : undefined, onFilterClick: onFilterClick
|
|
15
15
|
? () => {
|
|
16
16
|
const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.parentNodeId);
|
|
17
17
|
hierarchyLevelDetails && onFilterClick(hierarchyLevelDetails);
|
|
18
18
|
}
|
|
19
|
-
: undefined }));
|
|
19
|
+
: undefined, "aria-level": node.level, "aria-posinset": node.posInLevel, "aria-setsize": node.levelSize }));
|
|
20
20
|
}
|
|
21
21
|
if (node.type === "NoFilterMatches") {
|
|
22
|
-
return _jsx(Tree.Item, { ref: forwardedRef, label: localizedStrings.noFilteredChildren, "aria-disabled": true });
|
|
22
|
+
return (_jsx(Tree.Item, { ...rest, ref: forwardedRef, "aria-level": node.level, "aria-posinset": node.posInLevel, "aria-setsize": node.levelSize, label: localizedStrings.noFilteredChildren, "aria-disabled": true }));
|
|
23
23
|
}
|
|
24
24
|
const onRetry = reloadTree ? () => reloadTree({ parentNodeId: node.parentNodeId, state: "reset" }) : undefined;
|
|
25
|
-
return _jsx(Tree.Item, { ref: forwardedRef, label: _jsx(ErrorNodeLabel, { message: node.message, onRetry: onRetry }), "aria-disabled": true });
|
|
25
|
+
return (_jsx(Tree.Item, { ...rest, ref: forwardedRef, "aria-level": node.level, "aria-posinset": node.posInLevel, "aria-setsize": node.levelSize, label: _jsx(ErrorNodeLabel, { message: node.message, onRetry: onRetry }), "aria-disabled": true }));
|
|
26
26
|
});
|
|
27
27
|
TreeErrorRenderer.displayName = "TreeErrorRenderer";
|
|
28
28
|
const ResultSetTooLargeNode = forwardRef(({ onFilterClick, onOverrideLimit, limit, ...props }, forwardedRef) => {
|
|
29
|
-
return (_jsx(Tree.Item, { ...props, ref: forwardedRef,
|
|
29
|
+
return (_jsx(Tree.Item, { ...props, ref: forwardedRef, label: _jsx(ResultSetTooLargeNodeLabel, { limit: limit, onFilterClick: onFilterClick, onOverrideLimit: onOverrideLimit }) }));
|
|
30
30
|
});
|
|
31
31
|
ResultSetTooLargeNode.displayName = "ResultSetTooLargeNode";
|
|
32
32
|
function ResultSetTooLargeNodeLabel({ onFilterClick, onOverrideLimit, limit }) {
|
|
@@ -42,7 +42,7 @@ function ResultSetTooLargeNodeLabel({ onFilterClick, onOverrideLimit, limit }) {
|
|
|
42
42
|
}
|
|
43
43
|
function ErrorNodeLabel({ message, onRetry }) {
|
|
44
44
|
const { localizedStrings } = useLocalizationContext();
|
|
45
|
-
return (_jsxs("div", { style: { display: "flex" }, children: [_jsx(Text, { children: message }), onRetry ? _jsx(Anchor, { onClick: onRetry, children: localizedStrings?.retry }) : null] }));
|
|
45
|
+
return (_jsxs("div", { style: { display: "flex" }, children: [_jsx(Text, { variant: "body-sm", children: message }), onRetry ? _jsx(Anchor, { onClick: onRetry, children: localizedStrings?.retry }) : null] }));
|
|
46
46
|
}
|
|
47
47
|
function createLocalizedMessage(message, limit, onClick) {
|
|
48
48
|
const limitStr = limit.toLocaleString(undefined, { useGrouping: true });
|
|
@@ -52,21 +52,21 @@ function createLocalizedMessage(message, limit, onClick) {
|
|
|
52
52
|
if (!match) {
|
|
53
53
|
return {
|
|
54
54
|
title: messageWithLimit,
|
|
55
|
-
element: (_jsx("div", { style: { display: "flex" }, children: _jsx(Text, { children: messageWithLimit }) })),
|
|
55
|
+
element: (_jsx("div", { style: { display: "flex" }, children: _jsx(Text, { variant: "body-sm", children: messageWithLimit }) })),
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
const [fullText, innerText] = match;
|
|
59
59
|
const [textBefore, textAfter] = messageWithLimit.split(fullText);
|
|
60
60
|
return {
|
|
61
61
|
title: messageWithLimit.replace(fullText, innerText),
|
|
62
|
-
element: (_jsxs("div", { style: { display: "flex" }, children: [textBefore ? _jsx(Text, { children: textBefore }) : null, _jsx(Anchor
|
|
62
|
+
element: (_jsxs("div", { style: { display: "flex" }, children: [textBefore ? _jsx(Text, { variant: "body-sm", children: textBefore }) : null, _jsx(Anchor
|
|
63
63
|
// underline props does not exist in v5
|
|
64
64
|
, {
|
|
65
65
|
// underline props does not exist in v5
|
|
66
66
|
onClick: (e) => {
|
|
67
67
|
e.stopPropagation();
|
|
68
68
|
onClick?.();
|
|
69
|
-
}, children: innerText }), textAfter ? _jsx(Text, { children: textAfter }) : null] })),
|
|
69
|
+
}, children: innerText }), textAfter ? _jsx(Text, { variant: "body-sm", children: textAfter }) : null] })),
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
//# sourceMappingURL=TreeErrorRenderer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeErrorRenderer.js","sourceRoot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AAE,CAAC,CAAC;IACxE,MAAM,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IAChE,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,mBAAmB,CAAC,CAAC;IAC5C,MAAM,KAAK,GAAG,gBAAgB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAE1C,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO;YACL,KAAK,EAAE,gBAAgB;YACvB,OAAO,EAAE,CACP,cAAK,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,YAC7B,KAAC,IAAI,cAAE,gBAAgB,GAAQ,GAC3B,CACP;SACF,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC;IACpC,MAAM,CAAC,UAAU,EAAE,SAAS,CAAC,GAAG,gBAAgB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAEjE,OAAO;QACL,KAAK,EAAE,gBAAgB,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC;QACpD,OAAO,EAAE,CACP,eAAK,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,aAC5B,UAAU,CAAC,CAAC,CAAC,KAAC,IAAI,cAAE,UAAU,GAAQ,CAAC,CAAC,CAAC,IAAI,EAC9C,KAAC,MAAM;gBACL,uCAAuC;;oBAAvC,uCAAuC;oBACvC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;wBACb,CAAC,CAAC,eAAe,EAAE,CAAC;wBACpB,OAAO,EAAE,EAAE,CAAC;oBACd,CAAC,YAEA,SAAS,GACH,EACR,SAAS,CAAC,CAAC,CAAC,KAAC,IAAI,cAAE,SAAS,GAAQ,CAAC,CAAC,CAAC,IAAI,IACxC,CACP;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 { ComponentPropsWithoutRef, forwardRef, RefAttributes } from \"react\";\nimport { Anchor, Text, Tree } from \"@itwin/itwinui-react/bricks\";\nimport { MAX_LIMIT_OVERRIDE } from \"../internal/Utils.js\";\nimport { PresentationInfoNode } from \"../TreeNode.js\";\nimport { useTree } from \"../UseTree.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\nimport { TreeNodeRendererOwnProps } from \"./TreeNodeRenderer.js\";\n\ninterface TreeErrorRendererOwnProps {\n node: PresentationInfoNode;\n}\n\ntype TreeErrorRendererProps = TreeErrorRendererOwnProps &\n Pick<TreeNodeRendererOwnProps, \"onFilterClick\" | \"reloadTree\"> &\n Partial<Pick<ReturnType<typeof useTree>, \"getHierarchyLevelDetails\">>;\n\n/** @alpha */\nexport const TreeErrorRenderer: React.ForwardRefExoticComponent<TreeErrorRendererProps & RefAttributes<HTMLDivElement>> = forwardRef(\n ({ node, getHierarchyLevelDetails, onFilterClick, reloadTree }, forwardedRef) => {\n const { localizedStrings } = useLocalizationContext();\n if (node.type === \"ResultSetTooLarge\") {\n return (\n <ResultSetTooLargeNode\n ref={forwardedRef}\n limit={node.resultSetSizeLimit}\n onOverrideLimit={getHierarchyLevelDetails ? (limit) => getHierarchyLevelDetails(node.parentNodeId)?.setSizeLimit(limit) : undefined}\n onFilterClick={\n onFilterClick\n ? () => {\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.parentNodeId);\n hierarchyLevelDetails && onFilterClick(hierarchyLevelDetails);\n }\n : undefined\n }\n />\n );\n }\n\n if (node.type === \"NoFilterMatches\") {\n return <Tree.Item ref={forwardedRef} label={localizedStrings.noFilteredChildren} aria-disabled={true} />;\n }\n\n const onRetry = reloadTree ? () => reloadTree({ parentNodeId: node.parentNodeId, state: \"reset\" }) : undefined;\n return <Tree.Item ref={forwardedRef} label={<ErrorNodeLabel message={node.message} onRetry={onRetry} />} aria-disabled={true} />;\n },\n);\nTreeErrorRenderer.displayName = \"TreeErrorRenderer\";\n\nconst ResultSetTooLargeNode = forwardRef<\n HTMLDivElement,\n Omit<ComponentPropsWithoutRef<typeof Tree.Item>, \"onExpanded\" | \"label\"> & ResultSetTooLargeNodeLabelProps\n>(({ onFilterClick, onOverrideLimit, limit, ...props }, forwardedRef) => {\n return (\n <Tree.Item\n {...props}\n ref={forwardedRef}\n className=\"stateless-tree-node\"\n label={<ResultSetTooLargeNodeLabel limit={limit} onFilterClick={onFilterClick} onOverrideLimit={onOverrideLimit} />}\n />\n );\n});\nResultSetTooLargeNode.displayName = \"ResultSetTooLargeNode\";\n\ninterface ResultSetTooLargeNodeLabelProps {\n limit: number;\n onFilterClick?: () => void;\n onOverrideLimit?: (limit: number) => void;\n}\n\nfunction ResultSetTooLargeNodeLabel({ onFilterClick, onOverrideLimit, limit }: ResultSetTooLargeNodeLabelProps) {\n const { localizedStrings } = useLocalizationContext();\n const supportsFiltering = !!onFilterClick;\n const supportsLimitOverride = !!onOverrideLimit && limit < MAX_LIMIT_OVERRIDE;\n\n const limitExceededMessage = createLocalizedMessage(\n supportsFiltering ? localizedStrings.resultLimitExceededWithFiltering : localizedStrings.resultLimitExceeded,\n limit,\n onFilterClick,\n );\n const increaseLimitMessage = supportsLimitOverride\n ? createLocalizedMessage(\n supportsFiltering ? localizedStrings.increaseHierarchyLimitWithFiltering : localizedStrings.increaseHierarchyLimit,\n MAX_LIMIT_OVERRIDE,\n () => onOverrideLimit(MAX_LIMIT_OVERRIDE),\n )\n : { title: \"\", element: null };\n\n const title = `${limitExceededMessage.title} ${increaseLimitMessage.title}`;\n\n return (\n <div style={{ display: \"flex\", alignItems: \"start\" }} title={title}>\n {limitExceededMessage.element}\n {increaseLimitMessage.element}\n </div>\n );\n}\n\nfunction ErrorNodeLabel({ message, onRetry }: { message: string; onRetry?: () => void }) {\n const { localizedStrings } = useLocalizationContext();\n return (\n <div style={{ display: \"flex\" }}>\n <Text>{message}</Text>\n {onRetry ? <Anchor onClick={onRetry}>{localizedStrings?.retry}</Anchor> : null}\n </div>\n );\n}\n\nfunction createLocalizedMessage(message: string, limit: number, onClick?: () => void) {\n const limitStr = limit.toLocaleString(undefined, { useGrouping: true });\n const messageWithLimit = message.replace(\"{{limit}}\", limitStr);\n const exp = new RegExp(\"<link>(.*)</link>\");\n const match = messageWithLimit.match(exp);\n\n if (!match) {\n return {\n title: messageWithLimit,\n element: (\n <div style={{ display: \"flex\" }}>\n <Text>{messageWithLimit}</Text>\n </div>\n ),\n };\n }\n\n const [fullText, innerText] = match;\n const [textBefore, textAfter] = messageWithLimit.split(fullText);\n\n return {\n title: messageWithLimit.replace(fullText, innerText),\n element: (\n <div style={{ display: \"flex\" }}>\n {textBefore ? <Text>{textBefore}</Text> : null}\n <Anchor\n // underline props does not exist in v5\n onClick={(e) => {\n e.stopPropagation();\n onClick?.();\n }}\n >\n {innerText}\n </Anchor>\n {textAfter ? <Text>{textAfter}</Text> : null}\n </div>\n ),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TreeErrorRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeErrorRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAA2C,UAAU,EAA4C,MAAM,OAAO,CAAC;AACtH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAI1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAiBlE,gBAAgB;AAChB,MAAM,CAAC,MAAM,iBAAiB,GAAmF,UAAU,CACzH,CAAC,EAAE,IAAI,EAAE,wBAAwB,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,EAAE,YAAY,EAAE,EAAE;IACvF,MAAM,EAAE,gBAAgB,EAAE,GAAG,sBAAsB,EAAE,CAAC;IACtD,IAAI,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,OAAO;YACL,KAAK,EAAE,gBAAgB;YACvB,OAAO,EAAE,CACP,cAAK,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,YAC7B,KAAC,IAAI,IAAC,OAAO,EAAE,SAAS,YAAG,gBAAgB,GAAQ,GAC/C,CACP;SACF,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC;IACpC,MAAM,CAAC,UAAU,EAAE,SAAS,CAAC,GAAG,gBAAgB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAEjE,OAAO;QACL,KAAK,EAAE,gBAAgB,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,CAAC;QACpD,OAAO,EAAE,CACP,eAAK,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,aAC5B,UAAU,CAAC,CAAC,CAAC,KAAC,IAAI,IAAC,OAAO,EAAE,SAAS,YAAG,UAAU,GAAQ,CAAC,CAAC,CAAC,IAAI,EAClE,KAAC,MAAM;gBACL,uCAAuC;;oBAAvC,uCAAuC;oBACvC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;wBACb,CAAC,CAAC,eAAe,EAAE,CAAC;wBACpB,OAAO,EAAE,EAAE,CAAC;oBACd,CAAC,YAEA,SAAS,GACH,EACR,SAAS,CAAC,CAAC,CAAC,KAAC,IAAI,IAAC,OAAO,EAAE,SAAS,YAAG,SAAS,GAAQ,CAAC,CAAC,CAAC,IAAI,IAC5D,CACP;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 { ComponentPropsWithoutRef, CSSProperties, forwardRef, ForwardRefExoticComponent, RefAttributes } from \"react\";\nimport { Anchor, Text, Tree } from \"@itwin/itwinui-react/bricks\";\nimport { MAX_LIMIT_OVERRIDE } from \"../internal/Utils.js\";\nimport { PresentationInfoNode } from \"../TreeNode.js\";\nimport { HierarchyLevelDetails, useTree } from \"../UseTree.js\";\nimport { FlatNode } from \"./FlatTreeNode.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\n\n/** @alpha */\nexport interface TreeErrorItemProps {\n /** A callback to reload a hierarchy level when an error occurs and `retry` button is clicked. */\n reloadTree?: (options: { parentNodeId: string | undefined; state: \"reset\" }) => void;\n /** Action to perform when the filter button is clicked for this node. */\n onFilterClick?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;\n}\n\ninterface TreeErrorRendererOwnProps {\n node: FlatNode<PresentationInfoNode>;\n style?: CSSProperties;\n}\n\ntype TreeErrorRendererProps = TreeErrorRendererOwnProps & TreeErrorItemProps & Partial<Pick<ReturnType<typeof useTree>, \"getHierarchyLevelDetails\">>;\n\n/** @internal */\nexport const TreeErrorRenderer: ForwardRefExoticComponent<TreeErrorRendererProps & RefAttributes<HTMLElement>> = forwardRef(\n ({ node, getHierarchyLevelDetails, onFilterClick, reloadTree, ...rest }, forwardedRef) => {\n const { localizedStrings } = useLocalizationContext();\n if (node.type === \"ResultSetTooLarge\") {\n return (\n <ResultSetTooLargeNode\n {...rest}\n ref={forwardedRef}\n limit={node.resultSetSizeLimit}\n onOverrideLimit={getHierarchyLevelDetails ? (limit) => getHierarchyLevelDetails(node.parentNodeId)?.setSizeLimit(limit) : undefined}\n onFilterClick={\n onFilterClick\n ? () => {\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.parentNodeId);\n hierarchyLevelDetails && onFilterClick(hierarchyLevelDetails);\n }\n : undefined\n }\n aria-level={node.level}\n aria-posinset={node.posInLevel}\n aria-setsize={node.levelSize}\n />\n );\n }\n\n if (node.type === \"NoFilterMatches\") {\n return (\n <Tree.Item\n {...rest}\n ref={forwardedRef}\n aria-level={node.level}\n aria-posinset={node.posInLevel}\n aria-setsize={node.levelSize}\n label={localizedStrings.noFilteredChildren}\n aria-disabled={true}\n />\n );\n }\n\n const onRetry = reloadTree ? () => reloadTree({ parentNodeId: node.parentNodeId, state: \"reset\" }) : undefined;\n return (\n <Tree.Item\n {...rest}\n ref={forwardedRef}\n aria-level={node.level}\n aria-posinset={node.posInLevel}\n aria-setsize={node.levelSize}\n label={<ErrorNodeLabel message={node.message} onRetry={onRetry} />}\n aria-disabled={true}\n />\n );\n },\n);\nTreeErrorRenderer.displayName = \"TreeErrorRenderer\";\n\nconst ResultSetTooLargeNode = forwardRef<\n HTMLElement,\n Omit<ComponentPropsWithoutRef<typeof Tree.Item>, \"onExpanded\" | \"label\"> & ResultSetTooLargeNodeLabelProps\n>(({ onFilterClick, onOverrideLimit, limit, ...props }, forwardedRef) => {\n return (\n <Tree.Item\n {...props}\n ref={forwardedRef}\n label={<ResultSetTooLargeNodeLabel limit={limit} onFilterClick={onFilterClick} onOverrideLimit={onOverrideLimit} />}\n />\n );\n});\nResultSetTooLargeNode.displayName = \"ResultSetTooLargeNode\";\n\ninterface ResultSetTooLargeNodeLabelProps {\n limit: number;\n onFilterClick?: () => void;\n onOverrideLimit?: (limit: number) => void;\n}\n\nfunction ResultSetTooLargeNodeLabel({ onFilterClick, onOverrideLimit, limit }: ResultSetTooLargeNodeLabelProps) {\n const { localizedStrings } = useLocalizationContext();\n const supportsFiltering = !!onFilterClick;\n const supportsLimitOverride = !!onOverrideLimit && limit < MAX_LIMIT_OVERRIDE;\n\n const limitExceededMessage = createLocalizedMessage(\n supportsFiltering ? localizedStrings.resultLimitExceededWithFiltering : localizedStrings.resultLimitExceeded,\n limit,\n onFilterClick,\n );\n const increaseLimitMessage = supportsLimitOverride\n ? createLocalizedMessage(\n supportsFiltering ? localizedStrings.increaseHierarchyLimitWithFiltering : localizedStrings.increaseHierarchyLimit,\n MAX_LIMIT_OVERRIDE,\n () => onOverrideLimit(MAX_LIMIT_OVERRIDE),\n )\n : { title: \"\", element: null };\n\n const title = `${limitExceededMessage.title} ${increaseLimitMessage.title}`;\n\n return (\n <div style={{ display: \"flex\", alignItems: \"start\" }} title={title}>\n {limitExceededMessage.element}\n {increaseLimitMessage.element}\n </div>\n );\n}\n\nfunction ErrorNodeLabel({ message, onRetry }: { message: string; onRetry?: () => void }) {\n const { localizedStrings } = useLocalizationContext();\n return (\n <div style={{ display: \"flex\" }}>\n <Text variant={\"body-sm\"}>{message}</Text>\n {onRetry ? <Anchor onClick={onRetry}>{localizedStrings?.retry}</Anchor> : null}\n </div>\n );\n}\n\nfunction createLocalizedMessage(message: string, limit: number, onClick?: () => void) {\n const limitStr = limit.toLocaleString(undefined, { useGrouping: true });\n const messageWithLimit = message.replace(\"{{limit}}\", limitStr);\n const exp = new RegExp(\"<link>(.*)</link>\");\n const match = messageWithLimit.match(exp);\n\n if (!match) {\n return {\n title: messageWithLimit,\n element: (\n <div style={{ display: \"flex\" }}>\n <Text variant={\"body-sm\"}>{messageWithLimit}</Text>\n </div>\n ),\n };\n }\n\n const [fullText, innerText] = match;\n const [textBefore, textAfter] = messageWithLimit.split(fullText);\n\n return {\n title: messageWithLimit.replace(fullText, innerText),\n element: (\n <div style={{ display: \"flex\" }}>\n {textBefore ? <Text variant={\"body-sm\"}>{textBefore}</Text> : null}\n <Anchor\n // underline props does not exist in v5\n onClick={(e) => {\n e.stopPropagation();\n onClick?.();\n }}\n >\n {innerText}\n </Anchor>\n {textAfter ? <Text variant={\"body-sm\"}>{textAfter}</Text> : null}\n </div>\n ),\n };\n}\n"]}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { ComponentPropsWithoutRef, ReactElement, RefAttributes } from "react";
|
|
1
|
+
import { ComponentPropsWithoutRef, ForwardRefExoticComponent, ReactElement, ReactNode, RefAttributes } from "react";
|
|
2
2
|
import { Tree } from "@itwin/itwinui-react/bricks";
|
|
3
|
-
import { PresentationHierarchyNode
|
|
4
|
-
import {
|
|
3
|
+
import { PresentationHierarchyNode } from "../TreeNode.js";
|
|
4
|
+
import { useTree } from "../UseTree.js";
|
|
5
|
+
import { FlatTreeNode } from "./FlatTreeNode.js";
|
|
6
|
+
import { TreeItemAction } from "./TreeActionButton.js";
|
|
7
|
+
import { TreeErrorItemProps } from "./TreeErrorRenderer.js";
|
|
5
8
|
/** @alpha */
|
|
6
|
-
type TreeNodeProps =
|
|
9
|
+
type TreeNodeProps = ComponentPropsWithoutRef<typeof Tree.Item>;
|
|
7
10
|
/** @alpha */
|
|
8
11
|
export interface TreeNodeRendererOwnProps {
|
|
9
12
|
/** Node that is rendered. */
|
|
10
|
-
node:
|
|
11
|
-
/** Action to perform when the filter button is clicked for this node. */
|
|
12
|
-
onFilterClick?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;
|
|
13
|
-
/** Returns an icon or icon href for a given node. */
|
|
14
|
-
getIcon?: (node: PresentationHierarchyNode) => string | ReactElement | undefined;
|
|
13
|
+
node: FlatTreeNode;
|
|
15
14
|
/** Returns a label for a given node. */
|
|
16
15
|
getLabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;
|
|
17
16
|
/** Returns sublabel for a given node. */
|
|
@@ -20,16 +19,18 @@ export interface TreeNodeRendererOwnProps {
|
|
|
20
19
|
onNodeClick?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.MouseEvent<HTMLElement, MouseEvent>) => void;
|
|
21
20
|
/** Action to perform when a key is pressed when the node is hovered on. */
|
|
22
21
|
onNodeKeyDown?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.KeyboardEvent<HTMLElement>) => void;
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
/**
|
|
23
|
+
* Actions for tree item.
|
|
24
|
+
*/
|
|
25
|
+
actions?: Array<(node: PresentationHierarchyNode) => TreeItemAction>;
|
|
26
|
+
/**
|
|
27
|
+
* Used to render elements between expander and label.
|
|
28
|
+
* E.g. icons, color picker, etc.
|
|
29
|
+
*/
|
|
30
|
+
getDecorations?: (node: PresentationHierarchyNode) => ReactNode;
|
|
30
31
|
}
|
|
31
32
|
/** @alpha */
|
|
32
|
-
type TreeNodeRendererProps = Pick<ReturnType<typeof useTree>, "expandNode"> & Partial<Pick<ReturnType<typeof useTree>, "getHierarchyLevelDetails">> & Omit<TreeNodeProps, "label" | "icon"> & TreeNodeRendererOwnProps;
|
|
33
|
+
type TreeNodeRendererProps = Pick<ReturnType<typeof useTree>, "expandNode" | "isNodeSelected"> & Partial<Pick<ReturnType<typeof useTree>, "getHierarchyLevelDetails">> & Omit<TreeNodeProps, "actions" | "aria-level" | "aria-posinset" | "aria-setsize" | "label" | "icon" | "expanded" | "selected" | "unstable_decorations"> & TreeNodeRendererOwnProps & TreeErrorItemProps;
|
|
33
34
|
/**
|
|
34
35
|
* A component that renders `RenderedTreeNode` using the `TreeNode` component from `@itwin/itwinui-react`.
|
|
35
36
|
*
|
|
@@ -37,6 +38,6 @@ type TreeNodeRendererProps = Pick<ReturnType<typeof useTree>, "expandNode"> & Pa
|
|
|
37
38
|
* @see https://itwinui.bentley.com/docs/tree
|
|
38
39
|
* @public
|
|
39
40
|
*/
|
|
40
|
-
export declare const TreeNodeRenderer:
|
|
41
|
+
export declare const TreeNodeRenderer: ForwardRefExoticComponent<TreeNodeRendererProps & RefAttributes<HTMLElement>>;
|
|
41
42
|
export {};
|
|
42
43
|
//# sourceMappingURL=TreeNodeRenderer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeNodeRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeNodeRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,
|
|
1
|
+
{"version":3,"file":"TreeNodeRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeNodeRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,EACL,wBAAwB,EAExB,yBAAyB,EAGzB,YAAY,EACZ,SAAS,EAET,aAAa,EAGd,MAAM,OAAO,CAAC;AACf,OAAO,EAAyB,IAAI,EAA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OAAO,OAAO,CAAC,EAAE,YAAY,GAAG,gBAAgB,CAAC,GAC5F,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,0BAA0B,CAAC,CAAC,GACrE,IAAI,CAAC,aAAa,EAAE,SAAS,GAAG,YAAY,GAAG,eAAe,GAAG,cAAc,GAAG,OAAO,GAAG,MAAM,GAAG,UAAU,GAAG,UAAU,GAAG,sBAAsB,CAAC,GACtJ,wBAAwB,GACxB,kBAAkB,CAAC;AAErB;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,EAAE,yBAAyB,CAAC,qBAAqB,GAAG,aAAa,CAAC,WAAW,CAAC,CA+F1G,CAAC"}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { jsx as _jsx,
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
/*---------------------------------------------------------------------------------------------
|
|
3
3
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
4
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
5
|
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
import { forwardRef, useCallback, useRef } from "react";
|
|
7
|
-
import { Spinner, Tree } from "@itwin/itwinui-react/bricks";
|
|
6
|
+
import { forwardRef, useCallback, useRef, } from "react";
|
|
7
|
+
import { DropdownMenu, Spinner, Tree } from "@itwin/itwinui-react/bricks";
|
|
8
8
|
import { isPresentationHierarchyNode } from "../TreeNode.js";
|
|
9
|
+
import { isPlaceholderNode } from "./FlatTreeNode.js";
|
|
9
10
|
import { useLocalizationContext } from "./LocalizationContext.js";
|
|
10
|
-
import {
|
|
11
|
+
import { TreeActionButton } from "./TreeActionButton.js";
|
|
11
12
|
import { TreeErrorRenderer } from "./TreeErrorRenderer.js";
|
|
13
|
+
const dropdownIcon = new URL("@itwin/itwinui-icons/more-horizontal.svg", import.meta.url).href;
|
|
12
14
|
/**
|
|
13
15
|
* A component that renders `RenderedTreeNode` using the `TreeNode` component from `@itwin/itwinui-react`.
|
|
14
16
|
*
|
|
@@ -16,14 +18,36 @@ import { TreeErrorRenderer } from "./TreeErrorRenderer.js";
|
|
|
16
18
|
* @see https://itwinui.bentley.com/docs/tree
|
|
17
19
|
* @public
|
|
18
20
|
*/
|
|
19
|
-
export const TreeNodeRenderer = forwardRef(({ node, expandNode,
|
|
21
|
+
export const TreeNodeRenderer = forwardRef(({ node, expandNode, getLabel, getSublabel, onFilterClick, onNodeClick, onNodeKeyDown, isNodeSelected, getHierarchyLevelDetails, reloadTree, actions, getDecorations, ...treeItemProps }, forwardedRef) => {
|
|
20
22
|
const nodeRef = useRef(null);
|
|
21
23
|
const ref = useMergedRefs(forwardedRef, nodeRef);
|
|
24
|
+
if (isPlaceholderNode(node)) {
|
|
25
|
+
return _jsx(PlaceholderNode, { ...treeItemProps, level: node.level, ref: ref });
|
|
26
|
+
}
|
|
22
27
|
if (!isPresentationHierarchyNode(node)) {
|
|
23
|
-
return (_jsx(TreeErrorRenderer, { node: node, getHierarchyLevelDetails: getHierarchyLevelDetails, reloadTree: reloadTree, onFilterClick: onFilterClick
|
|
28
|
+
return (_jsx(TreeErrorRenderer, { style: treeItemProps.style, ref: ref, node: node, getHierarchyLevelDetails: getHierarchyLevelDetails, reloadTree: reloadTree, onFilterClick: onFilterClick }));
|
|
24
29
|
}
|
|
25
|
-
const
|
|
26
|
-
|
|
30
|
+
const getActions = () => {
|
|
31
|
+
if (!actions || actions.length === 0) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
if (actions.length < 4) {
|
|
35
|
+
return actions.map((action, index) => {
|
|
36
|
+
const actionInfo = action(node);
|
|
37
|
+
return _jsx(TreeActionButton, { ...actionInfo }, index);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return [
|
|
41
|
+
_jsx(TreeActionButton, { ...actions[0](node) }, 0),
|
|
42
|
+
_jsx(TreeActionButton, { ...actions[1](node) }, 1),
|
|
43
|
+
_jsxs(DropdownMenu.Root, { children: [_jsx(DropdownMenu.Button, { render: _jsx(Tree.ItemAction, { icon: dropdownIcon, label: "Tree actions dropdown" }) }), _jsx(DropdownMenu.Content, { children: actions.slice(2, actions.length).map((action) => {
|
|
44
|
+
const info = action(node);
|
|
45
|
+
return _jsx(DropdownMenu.Item, { label: info.label, onClick: () => info.action() }, info.label);
|
|
46
|
+
}) })] }, 2),
|
|
47
|
+
];
|
|
48
|
+
};
|
|
49
|
+
const selected = isNodeSelected(node.id);
|
|
50
|
+
return (_jsx(Tree.Item, { ...treeItemProps, ref: ref, "aria-level": node.level, "aria-posinset": node.posInLevel, "aria-setsize": node.levelSize, label: getLabel ? getLabel(node) : node.label, description: getSublabel ? getSublabel(node) : undefined, selected: selected, expanded: node.isExpanded || node.children === true || node.children.length > 0 ? node.isExpanded : undefined, onExpandedChange: (isExpanded) => {
|
|
27
51
|
expandNode(node.id, isExpanded);
|
|
28
52
|
}, onClick: (event) => {
|
|
29
53
|
!treeItemProps["aria-disabled"] && onNodeClick?.(node, !selected, event);
|
|
@@ -32,12 +56,12 @@ export const TreeNodeRenderer = forwardRef(({ node, expandNode, getIcon, getLabe
|
|
|
32
56
|
if (!treeItemProps["aria-disabled"] && event.target === nodeRef.current) {
|
|
33
57
|
onNodeKeyDown?.(node, !selected, event);
|
|
34
58
|
}
|
|
35
|
-
},
|
|
59
|
+
}, actions: getActions(), unstable_decorations: getDecorations && getDecorations(node) }));
|
|
36
60
|
});
|
|
37
61
|
TreeNodeRenderer.displayName = "TreeNodeRenderer";
|
|
38
|
-
const PlaceholderNode = forwardRef(({ ...props }, forwardedRef) => {
|
|
62
|
+
const PlaceholderNode = forwardRef(({ level, ...props }, forwardedRef) => {
|
|
39
63
|
const { localizedStrings } = useLocalizationContext();
|
|
40
|
-
return _jsx(Tree.Item, { ...props, ref: forwardedRef, label: localizedStrings.loading, icon: _jsx(Spinner, { size: "small", title: localizedStrings.loading }) });
|
|
64
|
+
return (_jsx(Tree.Item, { ...props, "aria-level": level, "aria-posinset": 1, "aria-setsize": 1, ref: forwardedRef, label: localizedStrings.loading, icon: _jsx(Spinner, { size: "small", title: localizedStrings.loading }) }));
|
|
41
65
|
});
|
|
42
66
|
PlaceholderNode.displayName = "PlaceholderNode";
|
|
43
67
|
function useMergedRefs(...refs) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeNodeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeNodeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAA4B,UAAU,EAAiE,WAAW,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACjJ,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,2BAA2B,EAAmD,MAAM,gBAAgB,CAAC;AAE9G,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAiC3D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAA2F,UAAU,CAChI,CACE,EACE,IAAI,EACJ,UAAU,EACV,OAAO,EACP,QAAQ,EACR,aAAa,EACb,WAAW,EACX,aAAa,EACb,QAAQ,EACR,wBAAwB,EACxB,UAAU,EACV,QAAQ,EACR,eAAe,EACf,GAAG,aAAa,EACjB,EACD,YAAY,EACZ,EAAE;IACF,MAAM,OAAO,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAC7C,MAAM,GAAG,GAAG,aAAa,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAEjD,IAAI,CAAC,2BAA2B,CAAC,IAAI,CAAC,EAAE,CAAC;QACvC,OAAO,CACL,KAAC,iBAAiB,IAAC,IAAI,EAAE,IAAI,EAAE,wBAAwB,EAAE,wBAAwB,E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CAAC,CACV,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 { ComponentPropsWithoutRef, forwardRef, LegacyRef, MutableRefObject, ReactElement, Ref, RefAttributes, useCallback, useRef } from \"react\";\nimport { Spinner, Tree } from \"@itwin/itwinui-react/bricks\";\nimport { isPresentationHierarchyNode, PresentationHierarchyNode, PresentationTreeNode } from \"../TreeNode.js\";\nimport { HierarchyLevelDetails, useTree } from \"../UseTree.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\nimport { FilterActionButton } from \"./TreeActionButtons.js\";\nimport { TreeErrorRenderer } from \"./TreeErrorRenderer.js\";\n\n/** @alpha */\ntype TreeNodeProps = Omit<ComponentPropsWithoutRef<typeof Tree.Item>, \"actions\">;\n\n/** @alpha */\nexport interface TreeNodeRendererOwnProps {\n /** Node that is rendered. */\n node: PresentationTreeNode;\n /** Action to perform when the filter button is clicked for this node. */\n onFilterClick?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;\n /** Returns an icon or icon href for a given node. */\n getIcon?: (node: PresentationHierarchyNode) => string | ReactElement | undefined;\n /** Returns a label for a given node. */\n getLabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n /** Returns sublabel for a given node. */\n getSublabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n /** Action to perform when the node is clicked. */\n onNodeClick?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.MouseEvent<HTMLElement, MouseEvent>) => void;\n /** Action to perform when a key is pressed when the node is hovered on. */\n onNodeKeyDown?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.KeyboardEvent<HTMLElement>) => void;\n /** A callback to reload a hierarchy level when an error occurs and `retry` button is clicked. */\n reloadTree?: (options: { parentNodeId: string | undefined; state: \"reset\" }) => void;\n /** Renderer for additional tree items actions */\n actionsRenderer?: (node: PresentationHierarchyNode) => ReactElement;\n}\n\n/** @alpha */\ntype TreeNodeRendererProps = Pick<ReturnType<typeof useTree>, \"expandNode\"> &\n Partial<Pick<ReturnType<typeof useTree>, \"getHierarchyLevelDetails\">> &\n Omit<TreeNodeProps, \"label\" | \"icon\"> &\n TreeNodeRendererOwnProps;\n\n/**\n * A component that renders `RenderedTreeNode` using the `TreeNode` component from `@itwin/itwinui-react`.\n *\n * @see `TreeRenderer`\n * @see https://itwinui.bentley.com/docs/tree\n * @public\n */\nexport const TreeNodeRenderer: React.ForwardRefExoticComponent<TreeNodeRendererProps & RefAttributes<HTMLDivElement>> = forwardRef(\n (\n {\n node,\n expandNode,\n getIcon,\n getLabel,\n onFilterClick,\n onNodeClick,\n onNodeKeyDown,\n selected,\n getHierarchyLevelDetails,\n reloadTree,\n children,\n actionsRenderer,\n ...treeItemProps\n },\n forwardedRef,\n ) => {\n const nodeRef = useRef<HTMLDivElement>(null);\n const ref = useMergedRefs(forwardedRef, nodeRef);\n\n if (!isPresentationHierarchyNode(node)) {\n return (\n <TreeErrorRenderer node={node} getHierarchyLevelDetails={getHierarchyLevelDetails} reloadTree={reloadTree} onFilterClick={onFilterClick} ref={ref} />\n );\n }\n\n const ActionButtons = () => (\n <>\n {actionsRenderer && actionsRenderer(node)}\n <FilterActionButton node={node} onClick={onFilterClick} getHierarchyLevelDetails={getHierarchyLevelDetails} />\n </>\n );\n\n return (\n <Tree.Item\n {...treeItemProps}\n ref={ref}\n label={getLabel ? getLabel(node) : node.label}\n selected={selected}\n expanded={node.isExpanded || node.children === true || node.children.length > 0 ? node.isExpanded : undefined}\n onExpandedChange={(isExpanded) => {\n expandNode(node.id, isExpanded);\n }}\n onClick={(event) => {\n !treeItemProps[\"aria-disabled\"] && onNodeClick?.(node, !selected, event);\n }}\n onKeyDown={(event) => {\n // Ignore if it is called on the element inside, e.g. checkbox or expander\n if (!treeItemProps[\"aria-disabled\"] && event.target === nodeRef.current) {\n onNodeKeyDown?.(node, !selected, event);\n }\n }}\n icon={getIcon ? getIcon(node) : undefined}\n actions={<ActionButtons />}\n >\n {node.isExpanded && node.children === true ? <PlaceholderNode {...treeItemProps} ref={ref} /> : children}\n </Tree.Item>\n );\n },\n);\nTreeNodeRenderer.displayName = \"TreeNodeRenderer\";\n\nconst PlaceholderNode = forwardRef<HTMLDivElement, Omit<TreeNodeProps, \"onExpanded\" | \"label\">>(({ ...props }, forwardedRef) => {\n const { localizedStrings } = useLocalizationContext();\n return <Tree.Item {...props} ref={forwardedRef} label={localizedStrings.loading} icon={<Spinner size={\"small\"} title={localizedStrings.loading} />} />;\n});\nPlaceholderNode.displayName = \"PlaceholderNode\";\n\nfunction useMergedRefs<T>(...refs: ReadonlyArray<Ref<T> | LegacyRef<T> | undefined | null>) {\n return useCallback(\n (instance: T | null) => {\n refs.forEach((ref) => {\n if (typeof ref === \"function\") {\n ref(instance);\n } else if (ref) {\n (ref as MutableRefObject<T | null>).current = instance;\n }\n });\n }, // eslint-disable-next-line react-hooks/exhaustive-deps\n [...refs],\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TreeNodeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeNodeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAEL,UAAU,EAQV,WAAW,EACX,MAAM,GACP,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAAE,2BAA2B,EAA6B,MAAM,gBAAgB,CAAC;AAExF,OAAO,EAAgB,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAkB,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAsB,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE/E,MAAM,YAAY,GAAG,IAAI,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mBACF,CAAC,kBACF,CAAC,EACf,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,gBAAgB,CAAC,OAAO,EAC/B,IAAI,EAAE,KAAC,OAAO,IAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,gBAAgB,CAAC,OAAO,GAAI,GACjE,CACH,CAAC;AACJ,CAAC,CAAC,CAAC;AACH,eAAe,CAAC,WAAW,GAAG,iBAAiB,CAAC;AAEhD,SAAS,aAAa,CAAI,GAAG,IAA6D;IACxF,OAAO,WAAW,CAChB,CAAC,QAAkB,EAAE,EAAE;QACrB,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YACnB,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE,CAAC;gBAC9B,GAAG,CAAC,QAAQ,CAAC,CAAC;YAChB,CAAC;iBAAM,IAAI,GAAG,EAAE,CAAC;gBACd,GAAkC,CAAC,OAAO,GAAG,QAAQ,CAAC;YACzD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,uDAAuD;IAC1D,CAAC,GAAG,IAAI,CAAC,CACV,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 {\n ComponentPropsWithoutRef,\n forwardRef,\n ForwardRefExoticComponent,\n LegacyRef,\n MutableRefObject,\n ReactElement,\n ReactNode,\n Ref,\n RefAttributes,\n useCallback,\n useRef,\n} from \"react\";\nimport { DropdownMenu, Spinner, Tree } from \"@itwin/itwinui-react/bricks\";\nimport { isPresentationHierarchyNode, PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { useTree } from \"../UseTree.js\";\nimport { FlatTreeNode, isPlaceholderNode } from \"./FlatTreeNode.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\nimport { TreeActionButton, TreeItemAction } from \"./TreeActionButton.js\";\nimport { TreeErrorItemProps, TreeErrorRenderer } from \"./TreeErrorRenderer.js\";\n\nconst dropdownIcon = new URL(\"@itwin/itwinui-icons/more-horizontal.svg\", import.meta.url).href;\n\n/** @alpha */\ntype TreeNodeProps = ComponentPropsWithoutRef<typeof Tree.Item>;\n\n/** @alpha */\nexport interface TreeNodeRendererOwnProps {\n /** Node that is rendered. */\n node: FlatTreeNode;\n /** Returns a label for a given node. */\n getLabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n /** Returns sublabel for a given node. */\n getSublabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n /** Action to perform when the node is clicked. */\n onNodeClick?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.MouseEvent<HTMLElement, MouseEvent>) => void;\n /** Action to perform when a key is pressed when the node is hovered on. */\n onNodeKeyDown?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.KeyboardEvent<HTMLElement>) => void;\n /**\n * Actions for tree item.\n */\n actions?: Array<(node: PresentationHierarchyNode) => TreeItemAction>;\n /**\n * Used to render elements between expander and label.\n * E.g. icons, color picker, etc.\n */\n getDecorations?: (node: PresentationHierarchyNode) => ReactNode;\n}\n\n/** @alpha */\ntype TreeNodeRendererProps = Pick<ReturnType<typeof useTree>, \"expandNode\" | \"isNodeSelected\"> &\n Partial<Pick<ReturnType<typeof useTree>, \"getHierarchyLevelDetails\">> &\n Omit<TreeNodeProps, \"actions\" | \"aria-level\" | \"aria-posinset\" | \"aria-setsize\" | \"label\" | \"icon\" | \"expanded\" | \"selected\" | \"unstable_decorations\"> &\n TreeNodeRendererOwnProps &\n TreeErrorItemProps;\n\n/**\n * A component that renders `RenderedTreeNode` using the `TreeNode` component from `@itwin/itwinui-react`.\n *\n * @see `TreeRenderer`\n * @see https://itwinui.bentley.com/docs/tree\n * @public\n */\nexport const TreeNodeRenderer: ForwardRefExoticComponent<TreeNodeRendererProps & RefAttributes<HTMLElement>> = forwardRef(\n (\n {\n node,\n expandNode,\n getLabel,\n getSublabel,\n onFilterClick,\n onNodeClick,\n onNodeKeyDown,\n isNodeSelected,\n getHierarchyLevelDetails,\n reloadTree,\n actions,\n getDecorations,\n ...treeItemProps\n },\n forwardedRef,\n ) => {\n const nodeRef = useRef<HTMLElement>(null);\n const ref = useMergedRefs(forwardedRef, nodeRef);\n\n if (isPlaceholderNode(node)) {\n return <PlaceholderNode {...treeItemProps} level={node.level} ref={ref} />;\n }\n\n if (!isPresentationHierarchyNode(node)) {\n return (\n <TreeErrorRenderer\n style={treeItemProps.style}\n ref={ref}\n node={node}\n getHierarchyLevelDetails={getHierarchyLevelDetails}\n reloadTree={reloadTree}\n onFilterClick={onFilterClick}\n />\n );\n }\n\n const getActions = () => {\n if (!actions || actions.length === 0) {\n return undefined;\n }\n\n if (actions.length < 4) {\n return actions.map((action, index) => {\n const actionInfo = action(node);\n return <TreeActionButton key={index} {...actionInfo} />;\n });\n }\n\n return [\n <TreeActionButton key={0} {...actions[0](node)} />,\n <TreeActionButton key={1} {...actions[1](node)} />,\n <DropdownMenu.Root key={2}>\n <DropdownMenu.Button render={<Tree.ItemAction icon={dropdownIcon} label=\"Tree actions dropdown\" />} />\n <DropdownMenu.Content>\n {actions.slice(2, actions.length).map((action) => {\n const info = action(node);\n return <DropdownMenu.Item label={info.label} key={info.label} onClick={() => info.action()} />;\n })}\n </DropdownMenu.Content>\n </DropdownMenu.Root>,\n ];\n };\n\n const selected = isNodeSelected(node.id);\n return (\n <Tree.Item\n {...treeItemProps}\n ref={ref}\n aria-level={node.level}\n aria-posinset={node.posInLevel}\n aria-setsize={node.levelSize}\n label={getLabel ? getLabel(node) : node.label}\n description={getSublabel ? getSublabel(node) : undefined}\n selected={selected}\n expanded={node.isExpanded || node.children === true || node.children.length > 0 ? node.isExpanded : undefined}\n onExpandedChange={(isExpanded) => {\n expandNode(node.id, isExpanded);\n }}\n onClick={(event) => {\n !treeItemProps[\"aria-disabled\"] && onNodeClick?.(node, !selected, event);\n }}\n onKeyDown={(event) => {\n // Ignore if it is called on the element inside, e.g. checkbox or expander\n if (!treeItemProps[\"aria-disabled\"] && event.target === nodeRef.current) {\n onNodeKeyDown?.(node, !selected, event);\n }\n }}\n actions={getActions()}\n unstable_decorations={getDecorations && getDecorations(node)}\n />\n );\n },\n);\nTreeNodeRenderer.displayName = \"TreeNodeRenderer\";\n\nconst PlaceholderNode = forwardRef<\n HTMLDivElement,\n Omit<TreeNodeProps, \"onExpanded\" | \"label\" | \"actions\" | \"aria-level\" | \"aria-posinset\" | \"aria-setsize\" | \"icon\"> & { level: number }\n>(({ level, ...props }, forwardedRef) => {\n const { localizedStrings } = useLocalizationContext();\n return (\n <Tree.Item\n {...props}\n aria-level={level}\n aria-posinset={1}\n aria-setsize={1}\n ref={forwardedRef}\n label={localizedStrings.loading}\n icon={<Spinner size={\"small\"} title={localizedStrings.loading} />}\n />\n );\n});\nPlaceholderNode.displayName = \"PlaceholderNode\";\n\nfunction useMergedRefs<T>(...refs: ReadonlyArray<Ref<T> | LegacyRef<T> | undefined | null>) {\n return useCallback(\n (instance: T | null) => {\n refs.forEach((ref) => {\n if (typeof ref === \"function\") {\n ref(instance);\n } else if (ref) {\n (ref as MutableRefObject<T | null>).current = instance;\n }\n });\n }, // eslint-disable-next-line react-hooks/exhaustive-deps\n [...refs],\n );\n}\n"]}
|
|
@@ -25,6 +25,6 @@ type TreeRendererProps = Pick<ReturnType<typeof useTree>, "expandNode"> & Partia
|
|
|
25
25
|
* @see https://itwinui.bentley.com/docs/tree
|
|
26
26
|
* @alpha
|
|
27
27
|
*/
|
|
28
|
-
export declare function TreeRenderer({ rootNodes, expandNode, localizedStrings, selectNodes,
|
|
28
|
+
export declare function TreeRenderer({ rootNodes, expandNode, localizedStrings, selectNodes, selectionMode, ...treeProps }: TreeRendererProps): import("react/jsx-runtime").JSX.Element;
|
|
29
29
|
export {};
|
|
30
30
|
//# sourceMappingURL=TreeRenderer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,wBAAwB,
|
|
1
|
+
{"version":3,"file":"TreeRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,wBAAwB,EAAmB,MAAM,OAAO,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAEnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAuB,MAAM,2BAA2B,CAAC;AAC/E,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,aAAa;AACb,MAAM,MAAM,SAAS,GAAG,wBAAwB,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC;AAEnE,aAAa;AACb,MAAM,MAAM,qBAAqB,GAAG,wBAAwB,CAAC,OAAO,gBAAgB,CAAC,CAAC;AACtF,aAAa;AACb,UAAU,oBAAoB;IAC5B,8BAA8B;IAC9B,SAAS,EAAE,oBAAoB,EAAE,CAAC;IAClC,sEAAsE;IACtE,aAAa,CAAC,EAAE,aAAa,CAAC;CAC/B;AAED,aAAa;AACb,KAAK,iBAAiB,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,YAAY,CAAC,GACrE,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,aAAa,GAAG,gBAAgB,GAAG,0BAA0B,GAAG,YAAY,CAAC,CAAC,GACvH,IAAI,CAAC,qBAAqB,EAAE,MAAM,GAAG,YAAY,CAAC,GAClD,oBAAoB,GACpB,wBAAwB,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAE/D;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,gBAAgB,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,SAAS,EAAE,EAAE,iBAAiB,2CAgDpI"}
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createElement as _createElement } from "react";
|
|
3
|
+
/*---------------------------------------------------------------------------------------------
|
|
4
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
5
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
6
|
+
*--------------------------------------------------------------------------------------------*/
|
|
7
|
+
import { useMemo, useRef } from "react";
|
|
2
8
|
import { Tree } from "@itwin/itwinui-react/bricks";
|
|
9
|
+
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
3
10
|
import { useSelectionHandler } from "../UseSelectionHandler.js";
|
|
11
|
+
import { flattenNodes } from "./FlatTreeNode.js";
|
|
4
12
|
import { LocalizationContextProvider } from "./LocalizationContext.js";
|
|
5
|
-
import {
|
|
13
|
+
import { TreeNodeRenderer } from "./TreeNodeRenderer.js";
|
|
6
14
|
/**
|
|
7
15
|
* A component that renders a tree using the `Tree` component from `@itwin/itwinui-react`. The tree nodes
|
|
8
16
|
* are rendered using `TreeNodeRenderer` component from this package.
|
|
@@ -10,13 +18,31 @@ import { TreeLevelRenderer } from "./TreeLevelRenderer.js";
|
|
|
10
18
|
* @see https://itwinui.bentley.com/docs/tree
|
|
11
19
|
* @alpha
|
|
12
20
|
*/
|
|
13
|
-
export function TreeRenderer({ rootNodes, expandNode, localizedStrings, selectNodes,
|
|
21
|
+
export function TreeRenderer({ rootNodes, expandNode, localizedStrings, selectNodes, selectionMode, ...treeProps }) {
|
|
14
22
|
const { onNodeClick, onNodeKeyDown } = useSelectionHandler({
|
|
15
23
|
rootNodes,
|
|
16
24
|
selectNodes: selectNodes ?? noopSelectNodes,
|
|
17
25
|
selectionMode: selectionMode ?? "single",
|
|
18
26
|
});
|
|
19
|
-
|
|
27
|
+
const parentRef = useRef(null);
|
|
28
|
+
const flatNodes = useMemo(() => flattenNodes(rootNodes), [rootNodes]);
|
|
29
|
+
const virtualizer = useVirtualizer({
|
|
30
|
+
count: flatNodes.length,
|
|
31
|
+
getScrollElement: () => parentRef.current,
|
|
32
|
+
estimateSize: () => 28,
|
|
33
|
+
overscan: 5,
|
|
34
|
+
});
|
|
35
|
+
const items = virtualizer.getVirtualItems();
|
|
36
|
+
return (_jsx(LocalizationContextProvider, { localizedStrings: localizedStrings, children: _jsx("div", { style: { height: "100%", width: "100%", overflowY: "auto" }, ref: parentRef, children: _jsx(Tree.Root, { style: { height: virtualizer.getTotalSize(), minHeight: "100%", width: "100%", position: "relative" }, children: items.map((virtualizedItem) => {
|
|
37
|
+
return (_createElement(TreeNodeRenderer, { ...treeProps, ref: virtualizer.measureElement, style: {
|
|
38
|
+
position: "absolute",
|
|
39
|
+
top: 0,
|
|
40
|
+
left: 0,
|
|
41
|
+
width: "100%",
|
|
42
|
+
transform: `translateY(${virtualizedItem.start}px)`,
|
|
43
|
+
willChange: "transform",
|
|
44
|
+
}, expandNode: expandNode, onNodeClick: onNodeClick, onNodeKeyDown: onNodeKeyDown, node: flatNodes[virtualizedItem.index], key: flatNodes[virtualizedItem.index].id, "data-index": virtualizedItem.index }));
|
|
45
|
+
}) }) }) }));
|
|
20
46
|
}
|
|
21
47
|
function noopSelectNodes() { }
|
|
22
48
|
//# sourceMappingURL=TreeRenderer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeRenderer.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"TreeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeRenderer.tsx"],"names":[],"mappings":";;AAAA;;;gGAGgG;AAEhG,OAAO,EAA4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AM,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,SAAS,YAC9E,KAAC,IAAI,CAAC,IAAI,IAAC,KAAK,EAAE,EAAE,MAAM,EAAE,WAAW,CAAC,YAAY,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,YAC7G,KAAK,CAAC,GAAG,CAAC,CAAC,eAAe,EAAE,EAAE;oBAC7B,OAAO,CACL,eAAC,gBAAgB,OACX,SAAS,EACb,GAAG,EAAE,WAAW,CAAC,cAAc,EAC/B,KAAK,EAAE;4BACL,QAAQ,EAAE,UAAU;4BACpB,GAAG,EAAE,CAAC;4BACN,IAAI,EAAE,CAAC;4BACP,KAAK,EAAE,MAAM;4BACb,SAAS,EAAE,cAAc,eAAe,CAAC,KAAK,KAAK;4BACnD,UAAU,EAAE,WAAW;yBACxB,EACD,UAAU,EAAE,UAAU,EACtB,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,EAC5B,IAAI,EAAE,SAAS,CAAC,eAAe,CAAC,KAAK,CAAC,EACtC,GAAG,EAAE,SAAS,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC,EAAE,gBAC5B,eAAe,CAAC,KAAK,GACjC,CACH,CAAC;gBACJ,CAAC,CAAC,GACQ,GACR,GACsB,CAC/B,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,KAAI,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 { ComponentPropsWithoutRef, useMemo, useRef } from \"react\";\nimport { Tree } from \"@itwin/itwinui-react/bricks\";\nimport { useVirtualizer } from \"@tanstack/react-virtual\";\nimport { PresentationTreeNode } from \"../TreeNode.js\";\nimport { SelectionMode, useSelectionHandler } from \"../UseSelectionHandler.js\";\nimport { useTree } from \"../UseTree.js\";\nimport { flattenNodes } from \"./FlatTreeNode.js\";\nimport { LocalizationContextProvider } from \"./LocalizationContext.js\";\nimport { TreeNodeRenderer } from \"./TreeNodeRenderer.js\";\n\n/** @alpha */\nexport type TreeProps = ComponentPropsWithoutRef<typeof Tree.Root>;\n\n/** @alpha */\nexport type TreeNodeRendererProps = ComponentPropsWithoutRef<typeof TreeNodeRenderer>;\n/** @alpha */\ninterface TreeRendererOwnProps {\n /** Root nodes of the tree. */\n rootNodes: PresentationTreeNode[];\n /** Active selection mode used by the tree. Defaults to `\"single\"`. */\n selectionMode?: SelectionMode;\n}\n\n/** @alpha */\ntype TreeRendererProps = Pick<ReturnType<typeof useTree>, \"expandNode\"> &\n Partial<Pick<ReturnType<typeof useTree>, \"selectNodes\" | \"isNodeSelected\" | \"getHierarchyLevelDetails\" | \"reloadTree\">> &\n Omit<TreeNodeRendererProps, \"node\" | \"reloadTree\"> &\n TreeRendererOwnProps &\n ComponentPropsWithoutRef<typeof LocalizationContextProvider>;\n\n/**\n * A component that renders a tree using the `Tree` component from `@itwin/itwinui-react`. The tree nodes\n * are rendered using `TreeNodeRenderer` component from this package.\n *\n * @see https://itwinui.bentley.com/docs/tree\n * @alpha\n */\nexport function TreeRenderer({ rootNodes, expandNode, localizedStrings, selectNodes, selectionMode, ...treeProps }: TreeRendererProps) {\n const { onNodeClick, onNodeKeyDown } = useSelectionHandler({\n rootNodes,\n selectNodes: selectNodes ?? noopSelectNodes,\n selectionMode: selectionMode ?? \"single\",\n });\n const parentRef = useRef<HTMLDivElement>(null);\n const flatNodes = useMemo(() => flattenNodes(rootNodes), [rootNodes]);\n\n const virtualizer = useVirtualizer({\n count: flatNodes.length,\n getScrollElement: () => parentRef.current,\n estimateSize: () => 28,\n overscan: 5,\n });\n\n const items = virtualizer.getVirtualItems();\n\n return (\n <LocalizationContextProvider localizedStrings={localizedStrings}>\n <div style={{ height: \"100%\", width: \"100%\", overflowY: \"auto\" }} ref={parentRef}>\n <Tree.Root style={{ height: virtualizer.getTotalSize(), minHeight: \"100%\", width: \"100%\", position: \"relative\" }}>\n {items.map((virtualizedItem) => {\n return (\n <TreeNodeRenderer\n {...treeProps}\n ref={virtualizer.measureElement}\n style={{\n position: \"absolute\",\n top: 0,\n left: 0,\n width: \"100%\",\n transform: `translateY(${virtualizedItem.start}px)`,\n willChange: \"transform\",\n }}\n expandNode={expandNode}\n onNodeClick={onNodeClick}\n onNodeKeyDown={onNodeKeyDown}\n node={flatNodes[virtualizedItem.index]}\n key={flatNodes[virtualizedItem.index].id}\n data-index={virtualizedItem.index}\n />\n );\n })}\n </Tree.Root>\n </div>\n </LocalizationContextProvider>\n );\n}\n\nfunction noopSelectNodes() {}\n"]}
|
|
@@ -3,10 +3,10 @@ export { UnifiedSelectionProvider } from "./presentation-hierarchies-react/Unifi
|
|
|
3
3
|
export { useSelectionHandler } from "./presentation-hierarchies-react/UseSelectionHandler.js";
|
|
4
4
|
export { HierarchyLevelDetails, useTree, useUnifiedSelectionTree } from "./presentation-hierarchies-react/UseTree.js";
|
|
5
5
|
export { useIModelTree, useIModelUnifiedSelectionTree } from "./presentation-hierarchies-react/UseIModelTree.js";
|
|
6
|
-
export { TreeErrorRenderer } from "./presentation-hierarchies-react/itwinui/TreeErrorRenderer.js";
|
|
7
|
-
export { TreeLevelRenderer } from "./presentation-hierarchies-react/itwinui/TreeLevelRenderer.js";
|
|
8
6
|
export { TreeNodeRenderer } from "./presentation-hierarchies-react/itwinui/TreeNodeRenderer.js";
|
|
7
|
+
export { TreeItemAction, useFilterAction } from "./presentation-hierarchies-react/itwinui/TreeActionButton.js";
|
|
9
8
|
export { TreeRenderer } from "./presentation-hierarchies-react/itwinui/TreeRenderer.js";
|
|
9
|
+
export { flattenNodes, FlatTreeNode } from "./presentation-hierarchies-react/itwinui/FlatTreeNode.js";
|
|
10
10
|
export { LocalizationContextProvider } from "./presentation-hierarchies-react/itwinui/LocalizationContext.js";
|
|
11
11
|
export { GenericInstanceFilter, HierarchyNode, HierarchyProvider } from "@itwin/presentation-hierarchies";
|
|
12
12
|
export { SelectionStorage } from "@itwin/unified-selection";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presentation-hierarchies-react.d.ts","sourceRoot":"","sources":["../../src/presentation-hierarchies-react.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,2BAA2B,EAC3B,yBAAyB,EACzB,oBAAoB,EACpB,qCAAqC,EACrC,oBAAoB,EACpB,2BAA2B,GAC5B,MAAM,8CAA8C,CAAC;AACtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,6DAA6D,CAAC;AACvG,OAAO,EAAE,mBAAmB,EAAE,MAAM,yDAAyD,CAAC;AAC9F,OAAO,EAAE,qBAAqB,EAAE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6CAA6C,CAAC;AACtH,OAAO,EAAE,aAAa,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAC;AACjH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"presentation-hierarchies-react.d.ts","sourceRoot":"","sources":["../../src/presentation-hierarchies-react.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,2BAA2B,EAC3B,yBAAyB,EACzB,oBAAoB,EACpB,qCAAqC,EACrC,oBAAoB,EACpB,2BAA2B,GAC5B,MAAM,8CAA8C,CAAC;AACtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,6DAA6D,CAAC;AACvG,OAAO,EAAE,mBAAmB,EAAE,MAAM,yDAAyD,CAAC;AAC9F,OAAO,EAAE,qBAAqB,EAAE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6CAA6C,CAAC;AACtH,OAAO,EAAE,aAAa,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAC;AACjH,OAAO,EAAE,gBAAgB,EAAE,MAAM,8DAA8D,CAAC;AAChG,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,8DAA8D,CAAC;AAC/G,OAAO,EAAE,YAAY,EAAE,MAAM,0DAA0D,CAAC;AACxF,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,0DAA0D,CAAC;AACtG,OAAO,EAAE,2BAA2B,EAAE,MAAM,iEAAiE,CAAC;AAE9G,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAC1G,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -7,10 +7,10 @@ export { UnifiedSelectionProvider } from "./presentation-hierarchies-react/Unifi
|
|
|
7
7
|
export { useSelectionHandler } from "./presentation-hierarchies-react/UseSelectionHandler.js";
|
|
8
8
|
export { useTree, useUnifiedSelectionTree } from "./presentation-hierarchies-react/UseTree.js";
|
|
9
9
|
export { useIModelTree, useIModelUnifiedSelectionTree } from "./presentation-hierarchies-react/UseIModelTree.js";
|
|
10
|
-
export { TreeErrorRenderer } from "./presentation-hierarchies-react/itwinui/TreeErrorRenderer.js";
|
|
11
|
-
export { TreeLevelRenderer } from "./presentation-hierarchies-react/itwinui/TreeLevelRenderer.js";
|
|
12
10
|
export { TreeNodeRenderer } from "./presentation-hierarchies-react/itwinui/TreeNodeRenderer.js";
|
|
11
|
+
export { useFilterAction } from "./presentation-hierarchies-react/itwinui/TreeActionButton.js";
|
|
13
12
|
export { TreeRenderer } from "./presentation-hierarchies-react/itwinui/TreeRenderer.js";
|
|
13
|
+
export { flattenNodes } from "./presentation-hierarchies-react/itwinui/FlatTreeNode.js";
|
|
14
14
|
export { LocalizationContextProvider } from "./presentation-hierarchies-react/itwinui/LocalizationContext.js";
|
|
15
15
|
export { GenericInstanceFilter, HierarchyNode } from "@itwin/presentation-hierarchies";
|
|
16
16
|
//# sourceMappingURL=presentation-hierarchies-react.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presentation-hierarchies-react.js","sourceRoot":"","sources":["../../src/presentation-hierarchies-react.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAML,2BAA2B,GAC5B,MAAM,8CAA8C,CAAC;AACtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,6DAA6D,CAAC;AACvG,OAAO,EAAE,mBAAmB,EAAE,MAAM,yDAAyD,CAAC;AAC9F,OAAO,EAAyB,OAAO,EAAE,uBAAuB,EAAE,MAAM,6CAA6C,CAAC;AACtH,OAAO,EAAE,aAAa,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAC;AACjH,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"presentation-hierarchies-react.js","sourceRoot":"","sources":["../../src/presentation-hierarchies-react.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAML,2BAA2B,GAC5B,MAAM,8CAA8C,CAAC;AACtD,OAAO,EAAE,wBAAwB,EAAE,MAAM,6DAA6D,CAAC;AACvG,OAAO,EAAE,mBAAmB,EAAE,MAAM,yDAAyD,CAAC;AAC9F,OAAO,EAAyB,OAAO,EAAE,uBAAuB,EAAE,MAAM,6CAA6C,CAAC;AACtH,OAAO,EAAE,aAAa,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAC;AACjH,OAAO,EAAE,gBAAgB,EAAE,MAAM,8DAA8D,CAAC;AAChG,OAAO,EAAkB,eAAe,EAAE,MAAM,8DAA8D,CAAC;AAC/G,OAAO,EAAE,YAAY,EAAE,MAAM,0DAA0D,CAAC;AACxF,OAAO,EAAE,YAAY,EAAgB,MAAM,0DAA0D,CAAC;AACtG,OAAO,EAAE,2BAA2B,EAAE,MAAM,iEAAiE,CAAC;AAE9G,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAqB,MAAM,iCAAiC,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\nexport {\n PresentationGenericInfoNode,\n PresentationHierarchyNode,\n PresentationInfoNode,\n PresentationResultSetTooLargeInfoNode,\n PresentationTreeNode,\n isPresentationHierarchyNode,\n} from \"./presentation-hierarchies-react/TreeNode.js\";\nexport { UnifiedSelectionProvider } from \"./presentation-hierarchies-react/UnifiedSelectionContext.js\";\nexport { useSelectionHandler } from \"./presentation-hierarchies-react/UseSelectionHandler.js\";\nexport { HierarchyLevelDetails, useTree, useUnifiedSelectionTree } from \"./presentation-hierarchies-react/UseTree.js\";\nexport { useIModelTree, useIModelUnifiedSelectionTree } from \"./presentation-hierarchies-react/UseIModelTree.js\";\nexport { TreeNodeRenderer } from \"./presentation-hierarchies-react/itwinui/TreeNodeRenderer.js\";\nexport { TreeItemAction, useFilterAction } from \"./presentation-hierarchies-react/itwinui/TreeActionButton.js\";\nexport { TreeRenderer } from \"./presentation-hierarchies-react/itwinui/TreeRenderer.js\";\nexport { flattenNodes, FlatTreeNode } from \"./presentation-hierarchies-react/itwinui/FlatTreeNode.js\";\nexport { LocalizationContextProvider } from \"./presentation-hierarchies-react/itwinui/LocalizationContext.js\";\n\nexport { GenericInstanceFilter, HierarchyNode, HierarchyProvider } from \"@itwin/presentation-hierarchies\";\nexport { SelectionStorage } from \"@itwin/unified-selection\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/presentation-hierarchies-react",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.10",
|
|
4
4
|
"description": "React components based on `@itwin/presentation-hierarchies`",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -37,30 +37,35 @@
|
|
|
37
37
|
"./package.json": "./package.json"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@itwin/core-bentley": "^
|
|
41
|
-
"@itwin/itwinui-icons": "5.0.0-alpha.0",
|
|
40
|
+
"@itwin/core-bentley": "^5.0.0-dev.49",
|
|
42
41
|
"@itwin/itwinui-illustrations-react": "^2.1.0",
|
|
42
|
+
"@tanstack/react-virtual": "^3.13.0",
|
|
43
43
|
"classnames": "^2.5.1",
|
|
44
44
|
"immer": "^10.1.1",
|
|
45
45
|
"react-error-boundary": "^4.0.13",
|
|
46
46
|
"rxjs": "^7.8.1",
|
|
47
|
+
"@itwin/unified-selection": "^1.3.0",
|
|
47
48
|
"@itwin/presentation-hierarchies": "^1.4.1",
|
|
48
|
-
"@itwin/presentation-shared": "^1.2.0"
|
|
49
|
-
"@itwin/unified-selection": "^1.3.0"
|
|
49
|
+
"@itwin/presentation-shared": "^1.2.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"@itwin/itwinui-
|
|
52
|
+
"@itwin/itwinui-icons": "5.0.0-alpha.4",
|
|
53
|
+
"@itwin/itwinui-react": "5.0.0-alpha.11",
|
|
53
54
|
"react": "^17.0.0 || ^18.0.0",
|
|
54
55
|
"react-dom": "^17.0.0 || ^18.0.0"
|
|
55
56
|
},
|
|
56
57
|
"peerDependenciesMeta": {
|
|
58
|
+
"@itwin/itwinui-icons": {
|
|
59
|
+
"optional": true
|
|
60
|
+
},
|
|
57
61
|
"@itwin/itwinui-react": {
|
|
58
62
|
"optional": true
|
|
59
63
|
}
|
|
60
64
|
},
|
|
61
65
|
"devDependencies": {
|
|
62
|
-
"@itwin/build-tools": "
|
|
63
|
-
"@itwin/itwinui-
|
|
66
|
+
"@itwin/build-tools": "5.0.0-dev.67",
|
|
67
|
+
"@itwin/itwinui-icons": "5.0.0-alpha.4",
|
|
68
|
+
"@itwin/itwinui-react": "5.0.0-alpha.11",
|
|
64
69
|
"@testing-library/dom": "^10.3.2",
|
|
65
70
|
"@testing-library/react": "^16.0.0",
|
|
66
71
|
"@testing-library/user-event": "^14.5.2",
|
|
@@ -91,9 +96,8 @@
|
|
|
91
96
|
"sinon": "^18.0.0",
|
|
92
97
|
"sinon-chai": "^3.7.0",
|
|
93
98
|
"testdouble": "^3.20.2",
|
|
94
|
-
"typescript": "~5.
|
|
95
|
-
"presentation-test-utilities": "^0.0.0"
|
|
96
|
-
"presentation-build-tools": "^0.0.0"
|
|
99
|
+
"typescript": "~5.7.3",
|
|
100
|
+
"presentation-test-utilities": "^0.0.0"
|
|
97
101
|
},
|
|
98
102
|
"scripts": {
|
|
99
103
|
"build": "npm run -s build:esm",
|
|
@@ -104,7 +108,7 @@
|
|
|
104
108
|
"lint": "eslint ./src/**/*.{ts,tsx}",
|
|
105
109
|
"test:dev": "cross-env NODE_OPTIONS=\"--import presentation-test-utilities/node-hooks/ignore-styles\" mocha --enable-source-maps --config ./.mocharc.json",
|
|
106
110
|
"test": "npm run test:dev -- --parallel --jobs=4",
|
|
107
|
-
"extract-api": "betools extract-api --entry
|
|
111
|
+
"extract-api": "betools extract-api --entry=./lib/esm/presentation-hierarchies-react --apiReportFolder=./api --apiReportTempFolder=./api/temp --apiSummaryFolder=./api --includeUnexportedApis",
|
|
108
112
|
"check-internal": "node ../../scripts/checkInternal.js --apiSummary ./api/presentation-hierarchies-react.api.md",
|
|
109
113
|
"update-extractions": "node ../../scripts/updateExtractions.js --targets=./README.md",
|
|
110
114
|
"check-extractions": "node ../../scripts/updateExtractions.js --targets=./README.md --check",
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { PresentationHierarchyNode } from "../TreeNode.js";
|
|
2
|
-
import { HierarchyLevelDetails, useTree } from "../UseTree.js";
|
|
3
|
-
/** @internal */
|
|
4
|
-
export type ActionButtonProps = {
|
|
5
|
-
/** Node on which action is going to be performed */
|
|
6
|
-
node: PresentationHierarchyNode;
|
|
7
|
-
/** Action to perform when the filter button is clicked for this node. */
|
|
8
|
-
onClick?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;
|
|
9
|
-
} & Partial<Pick<ReturnType<typeof useTree>, "getHierarchyLevelDetails">>;
|
|
10
|
-
/** @internal */
|
|
11
|
-
export declare function FilterActionButton({ node, onClick, getHierarchyLevelDetails }: ActionButtonProps): import("react/jsx-runtime").JSX.Element | undefined;
|
|
12
|
-
//# sourceMappingURL=TreeActionButtons.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TreeActionButtons.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeActionButtons.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAM/D,gBAAgB;AAChB,MAAM,MAAM,iBAAiB,GAAG;IAC9B,oDAAoD;IACpD,IAAI,EAAE,yBAAyB,CAAC;IAChC,yEAAyE;IACzE,OAAO,CAAC,EAAE,CAAC,qBAAqB,EAAE,qBAAqB,KAAK,IAAI,CAAC;CAClE,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,0BAA0B,CAAC,CAAC,CAAC;AAE1E,gBAAgB;AAChB,wBAAgB,kBAAkB,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,wBAAwB,EAAE,EAAE,iBAAiB,uDAgBhG"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } 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 { IconButton } from "@itwin/itwinui-react/bricks";
|
|
7
|
-
import { useLocalizationContext } from "./LocalizationContext.js";
|
|
8
|
-
const filterIcon = new URL("@itwin/itwinui-icons/filter.svg", import.meta.url).href;
|
|
9
|
-
const activeFilterIcon = new URL("@itwin/itwinui-icons/placeholder.svg", import.meta.url).href; // Placeholder
|
|
10
|
-
/** @internal */
|
|
11
|
-
export function FilterActionButton({ node, onClick, getHierarchyLevelDetails }) {
|
|
12
|
-
const { localizedStrings } = useLocalizationContext();
|
|
13
|
-
return onClick && node.isFilterable ? (_jsx(IconButton, { variant: "ghost", className: "filtering-action-button", label: localizedStrings.filterHierarchyLevel, onClick: (e) => {
|
|
14
|
-
e.stopPropagation();
|
|
15
|
-
const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.id);
|
|
16
|
-
hierarchyLevelDetails && onClick(hierarchyLevelDetails);
|
|
17
|
-
}, icon: node.isFiltered ? activeFilterIcon : filterIcon })) : undefined;
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=TreeActionButtons.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TreeActionButtons.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeActionButtons.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAGzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,iCAAiC,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;AACpF,MAAM,gBAAgB,GAAG,IAAI,GAAG,CAAC,sCAAsC,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,cAAc;AAU9G,gBAAgB;AAChB,MAAM,UAAU,kBAAkB,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,wBAAwB,EAAqB;IAC/F,MAAM,EAAE,gBAAgB,EAAE,GAAG,sBAAsB,EAAE,CAAC;IAEtD,OAAO,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,CACpC,KAAC,UAAU,IACT,OAAO,EAAE,OAAO,EAChB,SAAS,EAAC,yBAAyB,EACnC,KAAK,EAAE,gBAAgB,CAAC,oBAAoB,EAC5C,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;YACb,CAAC,CAAC,eAAe,EAAE,CAAC;YACpB,MAAM,qBAAqB,GAAG,wBAAwB,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAClE,qBAAqB,IAAI,OAAO,CAAC,qBAAqB,CAAC,CAAC;QAC1D,CAAC,EACD,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,UAAU,GACrD,CACH,CAAC,CAAC,CAAC,SAAS,CAAC;AAChB,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 { IconButton } from \"@itwin/itwinui-react/bricks\";\nimport { PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { HierarchyLevelDetails, useTree } from \"../UseTree.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\n\nconst filterIcon = new URL(\"@itwin/itwinui-icons/filter.svg\", import.meta.url).href;\nconst activeFilterIcon = new URL(\"@itwin/itwinui-icons/placeholder.svg\", import.meta.url).href; // Placeholder\n\n/** @internal */\nexport type ActionButtonProps = {\n /** Node on which action is going to be performed */\n node: PresentationHierarchyNode;\n /** Action to perform when the filter button is clicked for this node. */\n onClick?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;\n} & Partial<Pick<ReturnType<typeof useTree>, \"getHierarchyLevelDetails\">>;\n\n/** @internal */\nexport function FilterActionButton({ node, onClick, getHierarchyLevelDetails }: ActionButtonProps) {\n const { localizedStrings } = useLocalizationContext();\n\n return onClick && node.isFilterable ? (\n <IconButton\n variant={\"ghost\"}\n className=\"filtering-action-button\"\n label={localizedStrings.filterHierarchyLevel}\n onClick={(e) => {\n e.stopPropagation();\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.id);\n hierarchyLevelDetails && onClick(hierarchyLevelDetails);\n }}\n icon={node.isFiltered ? activeFilterIcon : filterIcon}\n />\n ) : undefined;\n}\n"]}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ReactElement } from "react";
|
|
2
|
-
import { PresentationTreeNode } from "../TreeNode.js";
|
|
3
|
-
import { useTree } from "../UseTree.js";
|
|
4
|
-
import { TreeNodeRendererProps } from "./TreeRenderer.js";
|
|
5
|
-
type TreeNodesRendererProps = Omit<TreeNodeRendererProps, "node"> & Partial<Pick<ReturnType<typeof useTree>, "isNodeSelected">> & TreeLevelRendererOwnProps;
|
|
6
|
-
interface TreeLevelRendererOwnProps {
|
|
7
|
-
nodes: PresentationTreeNode[];
|
|
8
|
-
}
|
|
9
|
-
/** @alpha */
|
|
10
|
-
export declare const TreeLevelRenderer: ({ nodes, isNodeSelected, ...rest }: TreeNodesRendererProps) => ReactElement[];
|
|
11
|
-
export {};
|
|
12
|
-
//# sourceMappingURL=TreeLevelRenderer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TreeLevelRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeLevelRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AACrC,OAAO,EAA0D,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC9G,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,KAAK,sBAAsB,GAAG,IAAI,CAAC,qBAAqB,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,gBAAgB,CAAC,CAAC,GAAG,yBAAyB,CAAC;AAE5J,UAAU,yBAAyB;IACjC,KAAK,EAAE,oBAAoB,EAAE,CAAC;CAC/B;AAED,aAAa;AACb,eAAO,MAAM,iBAAiB,uCAAwC,sBAAsB,KAAG,YAAY,EAKvG,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createElement as _createElement } from "react";
|
|
3
|
-
import { isPresentationHierarchyNode } from "../TreeNode.js";
|
|
4
|
-
import { TreeNodeRenderer } from "./TreeNodeRenderer.js";
|
|
5
|
-
/** @alpha */
|
|
6
|
-
export const TreeLevelRenderer = ({ nodes, isNodeSelected, ...rest }) => nodes.map((node) => (_createElement(TreeNodeRenderer, { ...rest, node: node, key: node.id, selected: isNodeSelected?.(node.id) }, renderChildren(node) && _jsx(TreeLevelRenderer, { ...rest, nodes: node.children, isNodeSelected: isNodeSelected }))));
|
|
7
|
-
function renderChildren(node) {
|
|
8
|
-
return isPresentationHierarchyNode(node) && node.children !== true && node.isExpanded === true;
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=TreeLevelRenderer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TreeLevelRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeLevelRenderer.tsx"],"names":[],"mappings":";;AAMA,OAAO,EAAE,2BAA2B,EAAmD,MAAM,gBAAgB,CAAC;AAE9G,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AASzD,aAAa;AACb,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAAE,KAAK,EAAE,cAAc,EAAE,GAAG,IAAI,EAA0B,EAAkB,EAAE,CAC9G,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAClB,eAAC,gBAAgB,OAAK,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE,QAAQ,EAAE,cAAc,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,IACtF,cAAc,CAAC,IAAI,CAAC,IAAI,KAAC,iBAAiB,OAAK,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,cAAc,EAAE,cAAc,GAAI,CAC7F,CACpB,CAAC,CAAC;AAEL,SAAS,cAAc,CAAC,IAA0B;IAChD,OAAO,2BAA2B,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI,CAAC;AACjG,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 { ReactElement } from \"react\";\nimport { isPresentationHierarchyNode, PresentationHierarchyNode, PresentationTreeNode } from \"../TreeNode.js\";\nimport { useTree } from \"../UseTree.js\";\nimport { TreeNodeRenderer } from \"./TreeNodeRenderer.js\";\nimport { TreeNodeRendererProps } from \"./TreeRenderer.js\";\n\ntype TreeNodesRendererProps = Omit<TreeNodeRendererProps, \"node\"> & Partial<Pick<ReturnType<typeof useTree>, \"isNodeSelected\">> & TreeLevelRendererOwnProps;\n\ninterface TreeLevelRendererOwnProps {\n nodes: PresentationTreeNode[];\n}\n\n/** @alpha */\nexport const TreeLevelRenderer = ({ nodes, isNodeSelected, ...rest }: TreeNodesRendererProps): ReactElement[] =>\n nodes.map((node) => (\n <TreeNodeRenderer {...rest} node={node} key={node.id} selected={isNodeSelected?.(node.id)}>\n {renderChildren(node) && <TreeLevelRenderer {...rest} nodes={node.children} isNodeSelected={isNodeSelected} />}\n </TreeNodeRenderer>\n ));\n\nfunction renderChildren(node: PresentationTreeNode): node is PresentationHierarchyNode & { children: PresentationTreeNode[] } {\n return isPresentationHierarchyNode(node) && node.children !== true && node.isExpanded === true;\n}\n"]}
|