@itwin/presentation-hierarchies-react 2.0.0-alpha.57 → 2.0.0-alpha.58
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 +172 -36
- package/lib/presentation-hierarchies-react/UseIModelTree.d.ts +2 -2
- package/lib/presentation-hierarchies-react/UseIModelTree.js +1 -2
- package/lib/presentation-hierarchies-react/UseIModelTree.js.map +1 -1
- package/lib/presentation-hierarchies-react/UseNodeHighlighting.js +1 -2
- package/lib/presentation-hierarchies-react/UseNodeHighlighting.js.map +1 -1
- package/lib/presentation-hierarchies-react/UseSelectionHandler.d.ts +0 -2
- package/lib/presentation-hierarchies-react/UseSelectionHandler.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/UseSelectionHandler.js +1 -2
- package/lib/presentation-hierarchies-react/UseSelectionHandler.js.map +1 -1
- package/lib/presentation-hierarchies-react/UseTree.d.ts +2 -2
- package/lib/presentation-hierarchies-react/UseTree.js +1 -2
- package/lib/presentation-hierarchies-react/UseTree.js.map +1 -1
- package/lib/presentation-hierarchies-react/Utils.js +1 -1
- package/lib/presentation-hierarchies-react/Utils.js.map +1 -1
- package/lib/presentation-hierarchies-react/internal/DisposePolyfill.js +2 -2
- package/lib/presentation-hierarchies-react/internal/DisposePolyfill.js.map +1 -1
- package/lib/presentation-hierarchies-react/internal/LocalizedStrings.js +1 -1
- package/lib/presentation-hierarchies-react/internal/TreeActions.js +1 -2
- package/lib/presentation-hierarchies-react/internal/TreeActions.js.map +1 -1
- package/lib/presentation-hierarchies-react/internal/TreeLoader.js +1 -2
- package/lib/presentation-hierarchies-react/internal/TreeLoader.js.map +1 -1
- package/lib/presentation-hierarchies-react/internal/TreeModel.d.ts +0 -2
- package/lib/presentation-hierarchies-react/internal/TreeModel.js +1 -1
- package/lib/presentation-hierarchies-react/internal/TreeModel.js.map +1 -1
- package/lib/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts +0 -2
- package/lib/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/internal/UseUnifiedSelection.js +1 -2
- package/lib/presentation-hierarchies-react/internal/UseUnifiedSelection.js.map +1 -1
- package/lib/presentation-hierarchies-react/internal/Utils.js +1 -2
- package/lib/presentation-hierarchies-react/internal/Utils.js.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js +1 -2
- package/lib/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/FlatTreeNode.js +1 -2
- package/lib/presentation-hierarchies-react/stratakit/FlatTreeNode.js.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/LocalizationContext.js +1 -2
- package/lib/presentation-hierarchies-react/stratakit/LocalizationContext.js.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/RootErrorRenderer.js +1 -2
- package/lib/presentation-hierarchies-react/stratakit/RootErrorRenderer.js.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeAction.js +1 -2
- package/lib/presentation-hierarchies-react/stratakit/TreeAction.js.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js +1 -2
- package/lib/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.js +1 -2
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.js.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.d.ts +0 -2
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js +1 -2
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts +0 -4
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js +1 -2
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js.map +1 -1
- package/lib/presentation-hierarchies-react/stratakit/TreeRenderer.js +1 -2
- package/lib/presentation-hierarchies-react/stratakit/TreeRenderer.js.map +1 -1
- package/lib/presentation-hierarchies-react.js +1 -2
- package/package.json +12 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,48 @@
|
|
|
1
1
|
# @itwin/presentation-hierarchies-react
|
|
2
2
|
|
|
3
|
+
## 2.0.0-alpha.58
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [#1236](https://github.com/iTwin/presentation/pull/1236): Start using tree structure for defining hierarchy search paths.
|
|
8
|
+
|
|
9
|
+
The expected return type of `useTree` hooks' `getSearchPaths` callback prop has changed from `Promise<HierarchySearchPath[] | undefined>` to `Promise<HierarchySearchTree[] | undefined>`. The newly added `HierarchySearchTree.createFromPathsList` from `@itwin/presentation-hierarchies` can be used to do the conversion:`
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import { HierarchySearchTree } from "@itwin/presentation-hierarchies";
|
|
13
|
+
|
|
14
|
+
function MyTree() {
|
|
15
|
+
const [searchText, setSearchText] = useState("");
|
|
16
|
+
const treeProps = useIModelUnifiedSelectionTree({
|
|
17
|
+
// ...
|
|
18
|
+
getSearchPaths: useMemo<UseIModelTreeProps["getSearchPaths"]>(() => {
|
|
19
|
+
return async () => {
|
|
20
|
+
// before
|
|
21
|
+
return getSearchTargetPaths({ searchText }),
|
|
22
|
+
// after
|
|
23
|
+
return HierarchySearchTree.createFromPathsList(await getSearchTargetPaths({ searchText }));
|
|
24
|
+
};
|
|
25
|
+
}, [searchText]),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// ...
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<StrataKitTreeRenderer
|
|
32
|
+
{...treeProps.treeRendererProps}
|
|
33
|
+
// ...
|
|
34
|
+
/>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Patch Changes
|
|
40
|
+
|
|
41
|
+
- Updated dependencies:
|
|
42
|
+
- @itwin/unified-selection@1.6.9-alpha.0
|
|
43
|
+
- @itwin/presentation-hierarchies@2.0.0-alpha.13
|
|
44
|
+
- @itwin/presentation-shared@2.0.0-alpha.9
|
|
45
|
+
|
|
3
46
|
## 2.0.0-alpha.57
|
|
4
47
|
|
|
5
48
|
### Patch Changes
|
|
@@ -19,6 +62,7 @@
|
|
|
19
62
|
- [#1223](https://github.com/iTwin/presentation/pull/1223): Reworked `localization` to use `i18next`-compatible approach. Instead of passing a `localizedStrings` object into `LocalizationContextProvider`, the package now delivers an English locale JSON file and resolves strings through a `getLocalizedString` function at runtime.
|
|
20
63
|
|
|
21
64
|
**Breaking changes**
|
|
65
|
+
|
|
22
66
|
- `LocalizationContextProvider` no longer accepts a `localizedStrings` object. It now requires a `localization` prop — an object with a `getLocalizedString(key: string): string` method (compatible with `Localization` from @itwin/core-common).
|
|
23
67
|
- `LOCALIZATION_NAMESPACES` must be registered with your localization provider during app initialization to make localized strings available.
|
|
24
68
|
|
|
@@ -80,6 +124,7 @@
|
|
|
80
124
|
- [#1184](https://github.com/iTwin/presentation/pull/1184): Fixed selection handling in `StrataKitTreeRenderer`. Mouse double clicks are now correctly ignored to prevent rapid selection toggling. Keyboard selection using `Space` and `Enter` keys is working.
|
|
81
125
|
|
|
82
126
|
**Breaking changes**
|
|
127
|
+
|
|
83
128
|
- `useSelectionHandler` is no longer exported. This function is an internal implementation detail of `StrataKitTreeRenderer` and should not be used directly.
|
|
84
129
|
|
|
85
130
|
- [#1181](https://github.com/iTwin/presentation/pull/1181): **Breaking change:** Rename `PresentationHierarchyNode` to `TreeNode` for clarity.
|
|
@@ -89,6 +134,7 @@
|
|
|
89
134
|
- [#1183](https://github.com/iTwin/presentation/pull/1183): Clean up `TreeErrorRenderer` and `ErrorItemRenderer`.
|
|
90
135
|
|
|
91
136
|
**Breaking changes:**
|
|
137
|
+
|
|
92
138
|
- Replaced `useErrorList` hook with `useErrorNodes` hook that returns error nodes (`TreeNode[]`) instead of error items. The `expandTo` function became unnecessary, because expanding to error nodes is now handled internally. As a result, the whole `ErrorItem` type (result of `useErrorList`) was removed. Reacting to this, the following other breaking changes were made:
|
|
93
139
|
- Renamed `errorItem` -> `errorNode` in `ErrorItemRenderer` component and changed the type from removed `ErrorItem` to `TreeNode`.
|
|
94
140
|
- Renamed `errorList` -> `errorNodes` in `TreeErrorRenderer` component and changed the type from `ErrorItem[]` to `TreeNode[]`.
|
|
@@ -105,7 +151,10 @@
|
|
|
105
151
|
Example:
|
|
106
152
|
|
|
107
153
|
```tsx
|
|
108
|
-
import {
|
|
154
|
+
import {
|
|
155
|
+
StrataKitTreeRenderer,
|
|
156
|
+
StrataKitTreeRendererAttributes,
|
|
157
|
+
} from "@itwin/presentation-hierarchies-react";
|
|
109
158
|
|
|
110
159
|
function MyTree() {
|
|
111
160
|
const treeRef = useRef<StrataKitTreeRendererAttributes>(null);
|
|
@@ -115,7 +164,9 @@
|
|
|
115
164
|
<div className="tree-header">
|
|
116
165
|
<button
|
|
117
166
|
onClick={() => {
|
|
118
|
-
treeRef.current?.renameNode(
|
|
167
|
+
treeRef.current?.renameNode(
|
|
168
|
+
(node) => node.label === "Node to rename"
|
|
169
|
+
);
|
|
119
170
|
}}
|
|
120
171
|
>
|
|
121
172
|
Rename node
|
|
@@ -128,11 +179,13 @@
|
|
|
128
179
|
```
|
|
129
180
|
|
|
130
181
|
**Breaking changes**
|
|
182
|
+
|
|
131
183
|
- `StrataKitTreeNodeRenderer` is no longer exported.
|
|
132
184
|
- `RenameContextProvider` is no longer exported. It is not necessary when using `StrataKitTreeRenderer`.
|
|
133
185
|
- `RenameAction` now requires a `node` prop.
|
|
134
186
|
|
|
135
187
|
- [#1179](https://github.com/iTwin/presentation/pull/1179): **Breaking change:** Rename tree node action components for clarity.
|
|
188
|
+
|
|
136
189
|
- `FilterAction` -> `TreeNodeFilterAction`
|
|
137
190
|
- `RenameAction` -> `TreeNodeRenameAction`
|
|
138
191
|
|
|
@@ -143,7 +196,9 @@
|
|
|
143
196
|
```tsx
|
|
144
197
|
type TreeRendererProps = ComponentProps<typeof StrataKitTreeRenderer>;
|
|
145
198
|
|
|
146
|
-
const getEditingProps = useCallback<
|
|
199
|
+
const getEditingProps = useCallback<
|
|
200
|
+
Required<TreeRendererProps>["getEditingProps"]
|
|
201
|
+
>((node) => {
|
|
147
202
|
return {
|
|
148
203
|
onLabelChanged: (newLabel: string) => {
|
|
149
204
|
// Handle label change
|
|
@@ -153,10 +208,13 @@
|
|
|
153
208
|
};
|
|
154
209
|
}, []);
|
|
155
210
|
|
|
156
|
-
return
|
|
211
|
+
return (
|
|
212
|
+
<StrataKitTreeRenderer {...treeProps} getEditingProps={getEditingProps} />
|
|
213
|
+
);
|
|
157
214
|
```
|
|
158
215
|
|
|
159
216
|
**Breaking changes**
|
|
217
|
+
|
|
160
218
|
- `getEditingProps` callback was changed to require `onLabelChanged`. If node does not support renaming `getEditingProps` should return `undefined`.
|
|
161
219
|
|
|
162
220
|
### Patch Changes
|
|
@@ -175,6 +233,7 @@
|
|
|
175
233
|
**Breaking changes**
|
|
176
234
|
|
|
177
235
|
`StrataKitTreeNodeRenderer` props changes:
|
|
236
|
+
|
|
178
237
|
- `getMenuActions` callback changed to `menuActions` prop (type: `ReactNode[]`)
|
|
179
238
|
- `getInlineActions` callback changed to `inlineActions` prop (type: `ReactNode[]`)
|
|
180
239
|
- `getContextMenuActions` callback changed to `contextMenuActions` prop (type: `ReactNode[]`)
|
|
@@ -185,6 +244,7 @@
|
|
|
185
244
|
- `onNodeClick` and `onNodeKeyDown` callbacks removed - use `onClick` and `onKeyDown` props instead
|
|
186
245
|
|
|
187
246
|
`StrataKitTreeRenderer` props changes:
|
|
247
|
+
|
|
188
248
|
- Props previously passed to `StrataKitTreeNodeRenderer` are no longer accepted
|
|
189
249
|
- Use `getTreeItemProps` callback to provide props to specific `Tree.Item` components
|
|
190
250
|
- Use `getMenuActions`, `getInlineActions`, and `getContextMenuActions` on `StrataKitTreeRenderer` to provide actions for nodes
|
|
@@ -250,13 +310,19 @@
|
|
|
250
310
|
- [#1113](https://github.com/iTwin/presentation/pull/1113): Pass selected nodes to tree node action getters to support actions that should be applied on all selected nodes.
|
|
251
311
|
|
|
252
312
|
**Breaking changes**
|
|
313
|
+
|
|
253
314
|
- `StrataKitTreeRenderer.getInlineActions` callback receives `{ targetNode: PresentationHierarchyNode; selectedNodes: PresentationHierarchyNode[] }` props instead of `PresentationHierarchyNode`.
|
|
254
315
|
- `StrataKitTreeRenderer.getMenuActions` callback receives `{ targetNode: PresentationHierarchyNode; selectedNodes: PresentationHierarchyNode[] }` props instead of `PresentationHierarchyNode`.
|
|
255
316
|
|
|
256
317
|
Before
|
|
257
318
|
|
|
258
319
|
```tsx
|
|
259
|
-
return
|
|
320
|
+
return (
|
|
321
|
+
<StrataKitTreeRenderer
|
|
322
|
+
getInlineActions={(node) => [<InlineAction node={node} />]}
|
|
323
|
+
getMenuActions={(node) => [<MenuAction node={node} />]}
|
|
324
|
+
/>
|
|
325
|
+
);
|
|
260
326
|
```
|
|
261
327
|
|
|
262
328
|
After
|
|
@@ -264,7 +330,9 @@
|
|
|
264
330
|
```tsx
|
|
265
331
|
return (
|
|
266
332
|
<StrataKitTreeRenderer
|
|
267
|
-
getInlineActions={({ targetNode }) => [
|
|
333
|
+
getInlineActions={({ targetNode }) => [
|
|
334
|
+
<InlineAction node={targetNode} />,
|
|
335
|
+
]}
|
|
268
336
|
getMenuActions={({ targetNode }) => [<MenuAction node={targetNode} />]}
|
|
269
337
|
/>
|
|
270
338
|
);
|
|
@@ -273,6 +341,7 @@
|
|
|
273
341
|
- [#1115](https://github.com/iTwin/presentation/pull/1115): Unified tree actions handling to make it easier defining actions that could be reused in different contexts: inline, context menu and actions dropdown.
|
|
274
342
|
|
|
275
343
|
**Breaking changes**
|
|
344
|
+
|
|
276
345
|
- Removed `reserveSpace` property from `<RenameAction />` and `<FilterAction />`. These actions now automatically infer the context they're used in.
|
|
277
346
|
- Added requirement to render newly introduced `<TreeActionBase />` component instead of `<Tree.ItemAction />` when rendering custom tree actions.
|
|
278
347
|
|
|
@@ -322,6 +391,7 @@
|
|
|
322
391
|
### Major Changes
|
|
323
392
|
|
|
324
393
|
- [#1094](https://github.com/iTwin/presentation/pull/1094): Improve custom errors rendering API:
|
|
394
|
+
|
|
325
395
|
- Separated `ChildrenLoad` error from the `Unknown` error. All expected tree errors have dedicated type and `Unknown` error can be used to handle custom errors encountered outside of tree.
|
|
326
396
|
- Exposed `ErrorItemRenderer` that renders all error types supported by the tree.
|
|
327
397
|
- Updated `TreeErrorRenderer` to pass all props necessary to render `ErrorItemRenderer` into `renderError` callback.
|
|
@@ -339,7 +409,12 @@
|
|
|
339
409
|
{...errorProps}
|
|
340
410
|
renderError={(errorItemProps) => {
|
|
341
411
|
if (errorItemProps.errorItem.errorNode.error.type === "Unknown") {
|
|
342
|
-
return
|
|
412
|
+
return (
|
|
413
|
+
<ErrorRegion.Item
|
|
414
|
+
message="Custom error"
|
|
415
|
+
messageId={errorItemProps.errorItem.errorNode.id}
|
|
416
|
+
/>
|
|
417
|
+
);
|
|
343
418
|
}
|
|
344
419
|
return <ErrorItemRenderer {...errorItemProps} />;
|
|
345
420
|
}}
|
|
@@ -356,6 +431,7 @@
|
|
|
356
431
|
- [#1075](https://github.com/iTwin/presentation/pull/1075): Fix accessibility issues in `<TreeErrorRenderer />`.
|
|
357
432
|
|
|
358
433
|
This involves a few localized string changes:
|
|
434
|
+
|
|
359
435
|
- Added `issuesForTree`, defaulting to "Issues for {{tree_label}}.", used as a region landmark label for the error message container.
|
|
360
436
|
- Added `noIssuesFound`, defaulting to "No issues found.", used as a label for errors' list when there are no issues.
|
|
361
437
|
- Changed `issuesFound` to default to "{{number_of_issues}} issue(s) found.", and updated its usage to inject the number of issues found into the string instead of prefixing it before the string, which allows to place the number at any place in the string (may be a requirement for some languages). This is **a breaking change** for anyone, supplying their own localized strings.
|
|
@@ -390,13 +466,19 @@
|
|
|
390
466
|
Example usage:
|
|
391
467
|
|
|
392
468
|
```ts
|
|
393
|
-
import {
|
|
469
|
+
import {
|
|
470
|
+
StrataKitTreeRenderer,
|
|
471
|
+
useNodeHighlighting,
|
|
472
|
+
} from "@itwin/presentation-hierarchies-react";
|
|
394
473
|
|
|
395
|
-
type BaseTreeRendererProps = React.ComponentPropsWithoutRef<
|
|
474
|
+
type BaseTreeRendererProps = React.ComponentPropsWithoutRef<
|
|
475
|
+
typeof StrataKitTreeRenderer
|
|
476
|
+
>;
|
|
396
477
|
|
|
397
478
|
function MyComponent(props: BaseTreeRendererProps & { searchText: string }) {
|
|
398
479
|
// Create highlight based on searchText
|
|
399
|
-
const highlightText =
|
|
480
|
+
const highlightText =
|
|
481
|
+
props.searchText !== "" ? props.searchText : undefined;
|
|
400
482
|
const { getLabel } = useNodeHighlighting({ highlightText });
|
|
401
483
|
|
|
402
484
|
// Provide getLabel function to tree renderer
|
|
@@ -443,6 +525,7 @@
|
|
|
443
525
|
- [#1023](https://github.com/iTwin/presentation/pull/1023): Split `getActions` into `getMenuActions` & `getInlineActions` for `StrataKitTreeRenderer` and `StrataKitTreeNodeRenderer`.
|
|
444
526
|
|
|
445
527
|
Updated peer dependencies:
|
|
528
|
+
|
|
446
529
|
- @stratakit/bricks@0.3.3
|
|
447
530
|
- @stratakit/foundations@0.2.2
|
|
448
531
|
- @stratakit/structures@0.3.1
|
|
@@ -497,12 +580,14 @@
|
|
|
497
580
|
### Major Changes
|
|
498
581
|
|
|
499
582
|
- [#961](https://github.com/iTwin/presentation/pull/961): **Breaking changes** to tree state hooks `useTree`, `useUnifiedSelectionTree`, `useIModelTree`, `useIModelUnifiedSelectionTree`:
|
|
583
|
+
|
|
500
584
|
- All tree rendering props have been moved under `treeRendererProps`. The value can be passed to `<StrataKitTreeRenderer />` component.
|
|
501
585
|
- In case an error occurs while loading the root hierarchy level, instead of `treeRendererProps`, the `rootErrorRendererProps` are set, which can be passed to `<StrataKitRootErrorRenderer />` component to render the error state.
|
|
502
586
|
- The `isLoading` attribute has been renamed to `isReloading`.
|
|
503
587
|
- Errors are no longer defined as children of `PresentationHierarchyNode` and instead are now included as `error` attribute for more fluent API.
|
|
504
588
|
|
|
505
589
|
When rendering tree state, the recommended order of checks is:
|
|
590
|
+
|
|
506
591
|
1. If `rootErrorRendererProps` is defined, there was an error - render error state.
|
|
507
592
|
2. If `treeRendererProps` is not defined, the component is doing the initial load - render loading state.
|
|
508
593
|
3. If `treeRendererProps` is defined, the hierarchy is loaded - render the tree component.
|
|
@@ -541,6 +626,7 @@
|
|
|
541
626
|
### Major Changes
|
|
542
627
|
|
|
543
628
|
- [#954](https://github.com/iTwin/presentation/pull/954): Add additional requirements for types in `EC` metadata namespace, whose objects are returned by `ECSchemaProvider`.
|
|
629
|
+
|
|
544
630
|
- `EC.Schema`, `EC.Class` and `EC.Property` now all have an async `getCustomAttributes()` method that returns an `EC.CustomAttributeSet`, allowing consumers to access custom attributes of these schema items.
|
|
545
631
|
- `EC.Class` now additionally has these members:
|
|
546
632
|
- `baseClass: Promise<Class | undefined>`
|
|
@@ -581,6 +667,7 @@
|
|
|
581
667
|
### Major Changes
|
|
582
668
|
|
|
583
669
|
- [#942](https://github.com/iTwin/presentation/pull/942): Unified selection API cleanup.
|
|
670
|
+
|
|
584
671
|
- Remove deprecated `UnifiedSelectionProvider`.
|
|
585
672
|
- Make `selectionStorage` prop required for unified selection - enabled tree state hooks (`useUnifiedSelectionTree` and `useIModelUnifiedSelectionTree`).
|
|
586
673
|
|
|
@@ -593,7 +680,10 @@
|
|
|
593
680
|
Before:
|
|
594
681
|
|
|
595
682
|
```tsx
|
|
596
|
-
import {
|
|
683
|
+
import {
|
|
684
|
+
TreeNodeRenderer,
|
|
685
|
+
useFilterAction,
|
|
686
|
+
} from "@itwin/presentation-hierarchies-react";
|
|
597
687
|
|
|
598
688
|
const filterAction = useFilterAction({ onFilter, getHierarchyLevelDetails });
|
|
599
689
|
return (
|
|
@@ -607,7 +697,7 @@
|
|
|
607
697
|
icon: customIconHref,
|
|
608
698
|
}),
|
|
609
699
|
],
|
|
610
|
-
[filterAction]
|
|
700
|
+
[filterAction]
|
|
611
701
|
)}
|
|
612
702
|
/>
|
|
613
703
|
);
|
|
@@ -617,16 +707,29 @@
|
|
|
617
707
|
|
|
618
708
|
```tsx
|
|
619
709
|
import { Icon, Tree } from "@itwin/itwinui-react";
|
|
620
|
-
import {
|
|
710
|
+
import {
|
|
711
|
+
FilterAction,
|
|
712
|
+
TreeNodeRenderer,
|
|
713
|
+
} from "@itwin/presentation-hierarchies-react";
|
|
621
714
|
|
|
622
715
|
return (
|
|
623
716
|
<TreeNodeRenderer
|
|
624
717
|
getActions={useCallback(
|
|
625
718
|
(node) => [
|
|
626
|
-
<FilterAction
|
|
627
|
-
|
|
719
|
+
<FilterAction
|
|
720
|
+
key="filter"
|
|
721
|
+
node={node}
|
|
722
|
+
onFilter={onFilter}
|
|
723
|
+
getHierarchyLevelDetails={getHierarchyLevelDetails}
|
|
724
|
+
/>,
|
|
725
|
+
<Tree.ItemAction
|
|
726
|
+
key="customAction"
|
|
727
|
+
label="Custom action"
|
|
728
|
+
onClick={() => log(node.label)}
|
|
729
|
+
icon={<Icon href={customIconHref} />}
|
|
730
|
+
/>,
|
|
628
731
|
],
|
|
629
|
-
[onFilter, getHierarchyLevelDetails]
|
|
732
|
+
[onFilter, getHierarchyLevelDetails]
|
|
630
733
|
)}
|
|
631
734
|
/>
|
|
632
735
|
);
|
|
@@ -641,10 +744,10 @@
|
|
|
641
744
|
|
|
642
745
|
```ts
|
|
643
746
|
<TreeRenderer
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
747
|
+
{...treeProps}
|
|
748
|
+
errorRenderer={(errorsRendererProps) => (
|
|
749
|
+
<MyErrorRenderer {...errorsRendererProps} />
|
|
750
|
+
)}
|
|
648
751
|
/>
|
|
649
752
|
```
|
|
650
753
|
|
|
@@ -670,10 +773,10 @@
|
|
|
670
773
|
|
|
671
774
|
```ts
|
|
672
775
|
<TreeRenderer
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
776
|
+
{...treeProps}
|
|
777
|
+
rootErrorRenderer={(rootErrorRendererProps) => (
|
|
778
|
+
<MyRootErrorRenderer {...rootErrorRendererProps} />
|
|
779
|
+
)}
|
|
677
780
|
/>
|
|
678
781
|
```
|
|
679
782
|
|
|
@@ -777,11 +880,13 @@
|
|
|
777
880
|
### Minor Changes
|
|
778
881
|
|
|
779
882
|
- [#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:
|
|
883
|
+
|
|
780
884
|
- `undefined` - visible on hover/focus,
|
|
781
885
|
- `true` - visible at all times,
|
|
782
886
|
- `false` - hidden at all times.
|
|
783
887
|
|
|
784
888
|
Updated peer dependencies:
|
|
889
|
+
|
|
785
890
|
- itwinui-icons to 5.0.0-alpha.3,
|
|
786
891
|
- itwinui-react to 5.0.0-alpha.6,
|
|
787
892
|
|
|
@@ -811,6 +916,7 @@
|
|
|
811
916
|
- [#862](https://github.com/iTwin/presentation/pull/862): Update `@itwin/itwinui-react` dependency to `5.0.0-alpha.3`.
|
|
812
917
|
|
|
813
918
|
This fixes the following issues:
|
|
919
|
+
|
|
814
920
|
- nodes being selected on expand,
|
|
815
921
|
- node action buttons being rendered incorrectly.
|
|
816
922
|
|
|
@@ -820,6 +926,17 @@
|
|
|
820
926
|
|
|
821
927
|
- [#847](https://github.com/iTwin/presentation/pull/847): Moving tree rendering components to a new design systems.
|
|
822
928
|
|
|
929
|
+
## 1.9.13
|
|
930
|
+
|
|
931
|
+
### Patch Changes
|
|
932
|
+
|
|
933
|
+
- [#1242](https://github.com/iTwin/presentation/pull/1242): Bump dependencies.
|
|
934
|
+
- [#1252](https://github.com/iTwin/presentation/pull/1252): Fix tree node outline not appearing on touch devices.
|
|
935
|
+
- Updated dependencies:
|
|
936
|
+
- @itwin/presentation-hierarchies@1.7.11
|
|
937
|
+
- @itwin/presentation-shared@1.2.10
|
|
938
|
+
- @itwin/unified-selection@1.6.8
|
|
939
|
+
|
|
823
940
|
## 1.9.12
|
|
824
941
|
|
|
825
942
|
### Patch Changes
|
|
@@ -948,9 +1065,17 @@
|
|
|
948
1065
|
|
|
949
1066
|
const treeState = useUnifiedSelectionTree({
|
|
950
1067
|
selectionStorage,
|
|
951
|
-
createSelectableForGenericNode: useCallback<
|
|
952
|
-
|
|
953
|
-
|
|
1068
|
+
createSelectableForGenericNode: useCallback<
|
|
1069
|
+
NonNullable<
|
|
1070
|
+
Props<typeof useUnifiedSelectionTree>["createSelectableForGenericNode"]
|
|
1071
|
+
>
|
|
1072
|
+
>(
|
|
1073
|
+
(node, uniqueId) => ({
|
|
1074
|
+
identifier: node.key.id,
|
|
1075
|
+
data: node,
|
|
1076
|
+
async *loadInstanceKeys() {},
|
|
1077
|
+
}),
|
|
1078
|
+
[]
|
|
954
1079
|
),
|
|
955
1080
|
// ...other options
|
|
956
1081
|
});
|
|
@@ -1057,6 +1182,7 @@
|
|
|
1057
1182
|
### Minor Changes
|
|
1058
1183
|
|
|
1059
1184
|
- [#841](https://github.com/iTwin/presentation/pull/841): Changed how tree state hooks access unified selection storage.
|
|
1185
|
+
|
|
1060
1186
|
- The tree state hooks that hook into unified selection system now accept a `selectionStorage` prop. At the moment the prop is optional, but will be made required in the next major release of the package.
|
|
1061
1187
|
- The `UnifiedSelectionProvider` React context provider is now deprecated. The context is still used by tree state hooks if the selection storage is not provided through prop.
|
|
1062
1188
|
|
|
@@ -1132,7 +1258,11 @@
|
|
|
1132
1258
|
Example usage:
|
|
1133
1259
|
|
|
1134
1260
|
```tsx
|
|
1135
|
-
function MyTreeComponentInternal({
|
|
1261
|
+
function MyTreeComponentInternal({
|
|
1262
|
+
imodelAccess,
|
|
1263
|
+
}: {
|
|
1264
|
+
imodelAccess: IModelAccess;
|
|
1265
|
+
}) {
|
|
1136
1266
|
const {
|
|
1137
1267
|
rootNodes,
|
|
1138
1268
|
getNode,
|
|
@@ -1147,18 +1277,22 @@
|
|
|
1147
1277
|
async (nodeId: string, isExpanded: boolean) => {
|
|
1148
1278
|
const node = getNode(nodeId);
|
|
1149
1279
|
if (node) {
|
|
1150
|
-
console.log(
|
|
1280
|
+
console.log(
|
|
1281
|
+
`${isExpanded ? "Expanding" : "Collapsing"} node: ${node.label}`
|
|
1282
|
+
);
|
|
1151
1283
|
}
|
|
1152
1284
|
doExpandNode(nodeId, isExpanded);
|
|
1153
1285
|
},
|
|
1154
|
-
[getNode, doExpandNode]
|
|
1286
|
+
[getNode, doExpandNode]
|
|
1155
1287
|
);
|
|
1156
1288
|
|
|
1157
1289
|
// render the tree
|
|
1158
1290
|
if (!rootNodes || !rootNodes.length) {
|
|
1159
1291
|
return "No data to display";
|
|
1160
1292
|
}
|
|
1161
|
-
return
|
|
1293
|
+
return (
|
|
1294
|
+
<TreeRenderer {...state} expandNode={expandNode} rootNodes={rootNodes} />
|
|
1295
|
+
);
|
|
1162
1296
|
}
|
|
1163
1297
|
```
|
|
1164
1298
|
|
|
@@ -1312,6 +1446,7 @@
|
|
|
1312
1446
|
See "Basic example" section in README learning page for the full example.
|
|
1313
1447
|
|
|
1314
1448
|
- [#717](https://github.com/iTwin/presentation/pull/717): **BREAKING:** Add support for non-iModel-driven trees.
|
|
1449
|
+
|
|
1315
1450
|
- `useTree` and `useUnifiedSelectionTree` hooks have been changed to support non-iModel-driven trees. The hooks take a `getHierarchyProvider` prop, which returns a `HierarchyProvider`. The provider can return data from any data source.
|
|
1316
1451
|
- New `useIModelTree` and `useIModelUnifiedSelectionTree` hooks have been added to cover the most common case, where a tree is created from a iModel's data. The API of these hooks is exactly the same as of the old `useTree` and `useUnifiedSelectionTree` hooks.
|
|
1317
1452
|
|
|
@@ -1504,11 +1639,12 @@
|
|
|
1504
1639
|
const hierarchyLevelDetails = getHierarchyLevelDetails(nodeId);
|
|
1505
1640
|
someFunc(hierarchyLevelDetails);
|
|
1506
1641
|
}}
|
|
1507
|
-
|
|
1508
1642
|
// After the change
|
|
1509
1643
|
onNodeClick={(node, isSelected, event) => someFunc(node.id)}
|
|
1510
1644
|
onNodeKeyDown={(node, isSelected, event) => someFunc(node.id)}
|
|
1511
|
-
onFilterClick={(hierarchyLevelDetails) =>
|
|
1645
|
+
onFilterClick={(hierarchyLevelDetails) =>
|
|
1646
|
+
someFunc(hierarchyLevelDetails)
|
|
1647
|
+
}
|
|
1512
1648
|
/>
|
|
1513
1649
|
);
|
|
1514
1650
|
}
|
|
@@ -1541,7 +1677,7 @@
|
|
|
1541
1677
|
...props,
|
|
1542
1678
|
onHierarchyLimitExceeded: ({ nodeId, filter, limit }) => {
|
|
1543
1679
|
console.log(`Hierarchy limit of ${limit} exceeded for node ${nodeId}.`);
|
|
1544
|
-
}
|
|
1680
|
+
},
|
|
1545
1681
|
});
|
|
1546
1682
|
return <TreeRenderer {...state} />;
|
|
1547
1683
|
}
|
|
@@ -1552,7 +1688,7 @@
|
|
|
1552
1688
|
```ts
|
|
1553
1689
|
import { registerTxnListeners } from "@itwin/presentation-core-interop";
|
|
1554
1690
|
|
|
1555
|
-
function MyTree({ imodel, ...props}: Props) {
|
|
1691
|
+
function MyTree({ imodel, ...props }: Props) {
|
|
1556
1692
|
const { reloadTree, treeProps } = useTree(props);
|
|
1557
1693
|
useEffect(() => {
|
|
1558
1694
|
// listen for changes in iModel and reload tree
|
|
@@ -1578,7 +1714,7 @@
|
|
|
1578
1714
|
...props,
|
|
1579
1715
|
onPerformanceMeasured: (action, duration) => {
|
|
1580
1716
|
telemetryClient.log(`MyTree [${feature}] took ${duration} ms`);
|
|
1581
|
-
}
|
|
1717
|
+
},
|
|
1582
1718
|
});
|
|
1583
1719
|
return <TreeRenderer {...state} />;
|
|
1584
1720
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UseUnifiedTreeSelectionProps } from "./internal/UseUnifiedSelection.js";
|
|
2
2
|
import { UseTreeProps, UseTreeResult } from "./UseTree.js";
|
|
3
|
-
import { HierarchyDefinition,
|
|
3
|
+
import { HierarchyDefinition, HierarchySearchTree, createIModelHierarchyProvider } from "@itwin/presentation-hierarchies";
|
|
4
4
|
import { Props } from "@itwin/presentation-shared";
|
|
5
5
|
|
|
6
6
|
//#region src/presentation-hierarchies-react/UseIModelTree.d.ts
|
|
@@ -31,7 +31,7 @@ type UseIModelTreeProps = Omit<UseTreeProps, "getHierarchyProvider" | "getSearch
|
|
|
31
31
|
* Signal indicating that that the request was canceled
|
|
32
32
|
*/
|
|
33
33
|
abortSignal: AbortSignal;
|
|
34
|
-
}) => Promise<
|
|
34
|
+
}) => Promise<HierarchySearchTree[] | undefined>;
|
|
35
35
|
};
|
|
36
36
|
/**
|
|
37
37
|
* A React hook that creates state for a tree component whose displayed hierarchy is based on
|
|
@@ -2,7 +2,6 @@ import { useTree, useUnifiedSelectionTree } from "./UseTree.js";
|
|
|
2
2
|
import { useTranslation } from "./stratakit/LocalizationContext.js";
|
|
3
3
|
import { c } from "react-compiler-runtime";
|
|
4
4
|
import { createIModelHierarchyProvider } from "@itwin/presentation-hierarchies";
|
|
5
|
-
|
|
6
5
|
//#region src/presentation-hierarchies-react/UseIModelTree.ts
|
|
7
6
|
/**
|
|
8
7
|
* A React hook that creates state for a tree component whose displayed hierarchy is based on
|
|
@@ -178,7 +177,7 @@ function useIModelTreeProps(props) {
|
|
|
178
177
|
} else t4 = $[10];
|
|
179
178
|
return t4;
|
|
180
179
|
}
|
|
181
|
-
|
|
182
180
|
//#endregion
|
|
183
181
|
export { useIModelTree, useIModelUnifiedSelectionTree };
|
|
182
|
+
|
|
184
183
|
//# sourceMappingURL=UseIModelTree.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseIModelTree.js","names":["useCallback","createIModelHierarchyProvider","useTranslation","useTree","useUnifiedSelectionTree","HierarchyDefinition","
|
|
1
|
+
{"version":3,"file":"UseIModelTree.js","names":["useCallback","createIModelHierarchyProvider","useTranslation","useTree","useUnifiedSelectionTree","HierarchyDefinition","HierarchySearchTree","Props","UseUnifiedTreeSelectionProps","UseTreeProps","UseTreeResult","IModelHierarchyProviderProps","IModelAccess","UseIModelTreeProps","Omit","Pick","getHierarchyDefinition","props","imodelAccess","getSearchPaths","abortSignal","AbortSignal","Promise","useIModelTree","$","_c","imodelChanged","rest","t0","t1","useIModelTreeProps","t2","useIModelUnifiedSelectionTree","translate","hierarchyDefinition","localizedStrings","other","unspecified","t3","t4","getHierarchyProvider"],"sources":["../../src/presentation-hierarchies-react/UseIModelTree.ts"],"sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useCallback } from \"react\";\nimport { createIModelHierarchyProvider } from \"@itwin/presentation-hierarchies\";\nimport { useTranslation } from \"./stratakit/LocalizationContext.js\";\nimport { useTree, useUnifiedSelectionTree } from \"./UseTree.js\";\n\nimport type { HierarchyDefinition, HierarchySearchTree } from \"@itwin/presentation-hierarchies\";\nimport type { Props } from \"@itwin/presentation-shared\";\nimport type { UseUnifiedTreeSelectionProps } from \"./internal/UseUnifiedSelection.js\";\nimport type { UseTreeProps, UseTreeResult } from \"./UseTree.js\";\n\n/** @public */\ntype IModelHierarchyProviderProps = Props<typeof createIModelHierarchyProvider>;\n\n/** @public */\ntype IModelAccess = IModelHierarchyProviderProps[\"imodelAccess\"];\n\n/**\n * Props for `useIModelTree` and `useIModelUnifiedSelectionTree` hooks.\n * @public\n */\ntype UseIModelTreeProps = Omit<UseTreeProps, \"getHierarchyProvider\" | \"getSearchPaths\"> &\n Pick<IModelHierarchyProviderProps, \"imodelAccess\" | \"imodelChanged\"> & {\n /**\n * Provides the hierarchy definition for the tree.\n */\n getHierarchyDefinition: (props: { imodelAccess: IModelAccess }) => HierarchyDefinition;\n\n /**\n * Provides paths to target nodes.\n */\n getSearchPaths?: (props: {\n /**\n * Object that provides access to the iModel schema and can run queries against the iModel.\n */\n imodelAccess: IModelAccess;\n /**\n * Signal indicating that that the request was canceled\n */\n abortSignal: AbortSignal;\n }) => Promise<HierarchySearchTree[] | undefined>;\n };\n\n/**\n * A React hook that creates state for a tree component whose displayed hierarchy is based on\n * iModel data.\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useTree`\n * @see `useIModelUnifiedSelectionTree`\n * @public\n */\nexport function useIModelTree(props: UseIModelTreeProps): UseTreeResult {\n const { imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths, ...rest } = props;\n return useTree({\n ...rest,\n ...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths }),\n });\n}\n\n/**\n * A React hook that creates state for a tree component whose displayed hierarchy is based on\n * iModel data and that is integrated with unified selection through the given selection\n * storage (previously the storage was provided through the, now deprecated, `UnifiedSelectionProvider`).\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useIModelTree`\n * @see `useUnifiedSelectionTree`\n * @see `UnifiedSelectionProvider`\n * @public\n */\nexport function useIModelUnifiedSelectionTree(props: UseIModelTreeProps & UseUnifiedTreeSelectionProps): UseTreeResult {\n const { imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths, ...rest } = props;\n return useUnifiedSelectionTree({\n ...rest,\n ...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths }),\n });\n}\n\nfunction useIModelTreeProps(\n props: Pick<UseIModelTreeProps, \"imodelAccess\" | \"imodelChanged\" | \"getHierarchyDefinition\" | \"getSearchPaths\">,\n): Pick<UseTreeProps, \"getHierarchyProvider\" | \"getSearchPaths\"> {\n const { imodelAccess, imodelChanged, getHierarchyDefinition, getSearchPaths } = props;\n const translate = useTranslation();\n return {\n getHierarchyProvider: useCallback(\n () =>\n createIModelHierarchyProvider({\n imodelAccess,\n imodelChanged,\n hierarchyDefinition: getHierarchyDefinition({ imodelAccess }),\n localizedStrings: {\n other: translate(\"other\"),\n unspecified: translate(\"unspecified\"),\n },\n }),\n [imodelAccess, imodelChanged, translate, getHierarchyDefinition],\n ),\n getSearchPaths: useCallback(\n async ({ abortSignal }: { abortSignal: AbortSignal }) => getSearchPaths?.({ imodelAccess, abortSignal }),\n [imodelAccess, getSearchPaths],\n ),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AA4DA,SAAOuB,cAAAN,OAAA;CAAA,MAAAO,IAAAC,EAAA,GAAA;CAAA,IAAAT;CAAA,IAAAG;CAAA,IAAAD;CAAA,IAAAQ;CAAA,IAAAC;AAAA,KAAAH,EAAA,OAAAP,OAAA;AACL,GAAA,CAAAC,cAAAQ,eAAAV,wBAAAG,mBAAAQ,QAAyFV;AAAMO,IAAA,KAAAP;AAAAO,IAAA,KAAAR;AAAAQ,IAAA,KAAAL;AAAAK,IAAA,KAAAN;AAAAM,IAAA,KAAAE;AAAAF,IAAA,KAAAG;QAAA;AAAAX,2BAAAQ,EAAA;AAAAL,mBAAAK,EAAA;AAAAN,iBAAAM,EAAA;AAAAE,kBAAAF,EAAA;AAAAG,SAAAH,EAAA;;CAAA,IAAAI;AAAA,KAAAJ,EAAA,OAAAR,0BAAAQ,EAAA,OAAAL,kBAAAK,EAAA,OAAAN,gBAAAM,EAAA,OAAAE,eAAA;AAGvEE,OAAA;GAAAV;GAAAQ;GAAAV;GAAAG;GAAuE;AAAAK,IAAA,KAAAR;AAAAQ,IAAA,KAAAL;AAAAK,IAAA,KAAAN;AAAAM,IAAA,KAAAE;AAAAF,IAAA,MAAAI;OAAAA,MAAAJ,EAAA;CAA1F,MAAAK,KAAAC,mBAAmBF,GAAwE;CAAA,IAAAG;AAAA,KAAAP,EAAA,QAAAG,QAAAH,EAAA,QAAAK,IAAA;AAFjFE,OAAA;GAAA,GACVJ;GAAI,GACJE;GACJ;AAAAL,IAAA,MAAAG;AAAAH,IAAA,MAAAK;AAAAL,IAAA,MAAAO;OAAAA,MAAAP,EAAA;AAAA,QAHMrB,QAAQ4B,GAGb;;;;;;;;;;;;;;;;;AAkBJ,SAAOC,8BAAAf,OAAA;CAAA,MAAAO,IAAAC,EAAA,GAAA;CAAA,IAAAT;CAAA,IAAAG;CAAA,IAAAD;CAAA,IAAAQ;CAAA,IAAAC;AAAA,KAAAH,EAAA,OAAAP,OAAA;AACL,GAAA,CAAAC,cAAAQ,eAAAV,wBAAAG,mBAAAQ,QAAyFV;AAAMO,IAAA,KAAAP;AAAAO,IAAA,KAAAR;AAAAQ,IAAA,KAAAL;AAAAK,IAAA,KAAAN;AAAAM,IAAA,KAAAE;AAAAF,IAAA,KAAAG;QAAA;AAAAX,2BAAAQ,EAAA;AAAAL,mBAAAK,EAAA;AAAAN,iBAAAM,EAAA;AAAAE,kBAAAF,EAAA;AAAAG,SAAAH,EAAA;;CAAA,IAAAI;AAAA,KAAAJ,EAAA,OAAAR,0BAAAQ,EAAA,OAAAL,kBAAAK,EAAA,OAAAN,gBAAAM,EAAA,OAAAE,eAAA;AAGvEE,OAAA;GAAAV;GAAAQ;GAAAV;GAAAG;GAAuE;AAAAK,IAAA,KAAAR;AAAAQ,IAAA,KAAAL;AAAAK,IAAA,KAAAN;AAAAM,IAAA,KAAAE;AAAAF,IAAA,MAAAI;OAAAA,MAAAJ,EAAA;CAA1F,MAAAK,KAAAC,mBAAmBF,GAAwE;CAAA,IAAAG;AAAA,KAAAP,EAAA,QAAAG,QAAAH,EAAA,QAAAK,IAAA;AAFjEE,OAAA;GAAA,GAC1BJ;GAAI,GACJE;GACJ;AAAAL,IAAA,MAAAG;AAAAH,IAAA,MAAAK;AAAAL,IAAA,MAAAO;OAAAA,MAAAP,EAAA;AAAA,QAHMpB,wBAAwB2B,GAG7B;;AAGJ,SAAAD,mBAAAb,OAAA;CAAA,MAAAO,IAAAC,EAAA,GAAA;CAGE,MAAA,EAAAP,cAAAQ,eAAAV,wBAAAG,mBAAgFF;CAChF,MAAAgB,YAAkB/B,gBAAgB;CAAC,IAAA0B;AAAA,KAAAJ,EAAA,OAAAR,0BAAAQ,EAAA,OAAAN,gBAAAM,EAAA,OAAAE,iBAAAF,EAAA,OAAAS,WAAA;AAG/BL,aACE3B,8BAA8B;GAAAiB;GAAAQ;GAAAQ,qBAGPlB,uBAAuB,EAAAE,cAAgB,CAAC;GAAAiB,kBAC3C;IAAAC,OACTH,UAAU,QAAQ;IAAAI,aACZJ,UAAU,cAAa;IACtC;GACD,CAAC;AAAAT,IAAA,KAAAR;AAAAQ,IAAA,KAAAN;AAAAM,IAAA,KAAAE;AAAAF,IAAA,KAAAS;AAAAT,IAAA,KAAAI;OAAAA,MAAAJ,EAAA;CAVgB,MAAAK,KAAAD;CAYrB,IAAAG;AAAA,KAAAP,EAAA,OAAAL,kBAAAK,EAAA,OAAAN,cAAA;AAECa,OAAA,OAAAO,OAAA;GAAO,MAAA,EAAAlB,gBAAAkB;AAA6C,UAAKnB,iBAAiB;IAAAD;IAAAE;IAA6B,CAAC;;AAAAI,IAAA,KAAAL;AAAAK,IAAA,KAAAN;AAAAM,IAAA,KAAAO;OAAAA,MAAAP,EAAA;CAD1F,MAAAc,KAAAP;CAGf,IAAAQ;AAAA,KAAAf,EAAA,OAAAK,MAAAL,EAAA,OAAAc,IAAA;AAjBIC,OAAA;GAAAC,sBACiBX;GAYrBV,gBACemB;GAIjB;AAAAd,IAAA,KAAAK;AAAAL,IAAA,KAAAc;AAAAd,IAAA,MAAAe;OAAAA,MAAAf,EAAA;AAAA,QAlBMe"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { c } from "react-compiler-runtime";
|
|
2
2
|
import { HierarchyNode } from "@itwin/presentation-hierarchies";
|
|
3
3
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
4
|
-
|
|
5
4
|
//#region src/presentation-hierarchies-react/UseNodeHighlighting.tsx
|
|
6
5
|
/**
|
|
7
6
|
* A react hook that helps create highlighted node labels based on provided highlight.
|
|
@@ -52,7 +51,7 @@ function useNodeHighlighting(t0) {
|
|
|
52
51
|
} else t2 = $[3];
|
|
53
52
|
return t2;
|
|
54
53
|
}
|
|
55
|
-
|
|
56
54
|
//#endregion
|
|
57
55
|
export { useNodeHighlighting };
|
|
56
|
+
|
|
58
57
|
//# sourceMappingURL=UseNodeHighlighting.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseNodeHighlighting.js","names":["useCallback","HierarchyNode","JSX","ReactElement","TreeNode","UseNodeHighlightingProps","highlightText","UseNodeHighlightingResult","getLabel","node","useNodeHighlighting","t0","$","_c","t1","isGroupingNode","nodeData","search","isSearchTarget","label","matchedIndexes","Array","nodeLabel","toLocaleLowerCase","searchText","fromPosition","foundIndex","indexOf","push","length","finalLabel","lastAddedPosition","i","matchedIndex","substring","endingPlace","t2"],"sources":["../../src/presentation-hierarchies-react/UseNodeHighlighting.tsx"],"sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useCallback } from \"react\";\nimport { HierarchyNode } from \"@itwin/presentation-hierarchies\";\n\nimport type { JSX, ReactElement } from \"react\";\nimport type { TreeNode } from \"./TreeNode.js\";\n\n/**\n * Props for `useNodeHighlighting` hook.\n * @alpha\n */\ninterface UseNodeHighlightingProps {\n /** Text that should be highlighted */\n highlightText?: string;\n}\n\n/**\n * Result of `useNodeHighlighting` hook.\n * @alpha\n */\ninterface UseNodeHighlightingResult {\n /** Function that creates highlighted node labels. */\n getLabel: (node: TreeNode) => ReactElement;\n}\n\n/**\n * A react hook that helps create highlighted node labels based on provided highlight.\n * @alpha\n */\nexport function useNodeHighlighting({ highlightText }: UseNodeHighlightingProps): UseNodeHighlightingResult {\n const getLabel = useCallback(\n (node: TreeNode) => {\n if (!highlightText || HierarchyNode.isGroupingNode(node.nodeData) || !node.nodeData.search?.isSearchTarget) {\n return <span>{node.label}</span>;\n }\n\n const matchedIndexes = new Array<number>();\n const nodeLabel = node.label.toLocaleLowerCase();\n const searchText = highlightText.toLocaleLowerCase();\n let fromPosition = 0;\n // Find all occurrences of the search text in the node label\n while (true) {\n const foundIndex = nodeLabel.indexOf(searchText, fromPosition);\n if (foundIndex === -1) {\n break;\n }\n matchedIndexes.push(foundIndex);\n fromPosition = foundIndex + searchText.length;\n }\n\n if (matchedIndexes.length === 0) {\n return <span>{node.label}</span>;\n }\n\n // Create the final label with highlighted parts\n const finalLabel = new Array<JSX.Element>();\n let lastAddedPosition = 0;\n for (let i = 0; i < matchedIndexes.length; ++i) {\n const matchedIndex = matchedIndexes[i];\n if (matchedIndex > lastAddedPosition) {\n finalLabel.push(<span key={`normal-${i}`}>{node.label.substring(lastAddedPosition, matchedIndex)}</span>);\n lastAddedPosition = matchedIndex;\n }\n const endingPlace = matchedIndex + highlightText.length;\n finalLabel.push(<mark key={`marked-${i}`}>{node.label.substring(lastAddedPosition, endingPlace)}</mark>);\n lastAddedPosition = endingPlace;\n }\n if (lastAddedPosition < node.label.length) {\n finalLabel.push(<span key={`normal-${matchedIndexes.length + 1}`}>{node.label.substring(lastAddedPosition)}</span>);\n }\n\n return <>{finalLabel}</>;\n },\n [highlightText],\n );\n\n return { getLabel };\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"UseNodeHighlighting.js","names":["useCallback","HierarchyNode","JSX","ReactElement","TreeNode","UseNodeHighlightingProps","highlightText","UseNodeHighlightingResult","getLabel","node","useNodeHighlighting","t0","$","_c","t1","isGroupingNode","nodeData","search","isSearchTarget","label","matchedIndexes","Array","nodeLabel","toLocaleLowerCase","searchText","fromPosition","foundIndex","indexOf","push","length","finalLabel","lastAddedPosition","i","matchedIndex","substring","endingPlace","t2"],"sources":["../../src/presentation-hierarchies-react/UseNodeHighlighting.tsx"],"sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useCallback } from \"react\";\nimport { HierarchyNode } from \"@itwin/presentation-hierarchies\";\n\nimport type { JSX, ReactElement } from \"react\";\nimport type { TreeNode } from \"./TreeNode.js\";\n\n/**\n * Props for `useNodeHighlighting` hook.\n * @alpha\n */\ninterface UseNodeHighlightingProps {\n /** Text that should be highlighted */\n highlightText?: string;\n}\n\n/**\n * Result of `useNodeHighlighting` hook.\n * @alpha\n */\ninterface UseNodeHighlightingResult {\n /** Function that creates highlighted node labels. */\n getLabel: (node: TreeNode) => ReactElement;\n}\n\n/**\n * A react hook that helps create highlighted node labels based on provided highlight.\n * @alpha\n */\nexport function useNodeHighlighting({ highlightText }: UseNodeHighlightingProps): UseNodeHighlightingResult {\n const getLabel = useCallback(\n (node: TreeNode) => {\n if (!highlightText || HierarchyNode.isGroupingNode(node.nodeData) || !node.nodeData.search?.isSearchTarget) {\n return <span>{node.label}</span>;\n }\n\n const matchedIndexes = new Array<number>();\n const nodeLabel = node.label.toLocaleLowerCase();\n const searchText = highlightText.toLocaleLowerCase();\n let fromPosition = 0;\n // Find all occurrences of the search text in the node label\n while (true) {\n const foundIndex = nodeLabel.indexOf(searchText, fromPosition);\n if (foundIndex === -1) {\n break;\n }\n matchedIndexes.push(foundIndex);\n fromPosition = foundIndex + searchText.length;\n }\n\n if (matchedIndexes.length === 0) {\n return <span>{node.label}</span>;\n }\n\n // Create the final label with highlighted parts\n const finalLabel = new Array<JSX.Element>();\n let lastAddedPosition = 0;\n for (let i = 0; i < matchedIndexes.length; ++i) {\n const matchedIndex = matchedIndexes[i];\n if (matchedIndex > lastAddedPosition) {\n finalLabel.push(<span key={`normal-${i}`}>{node.label.substring(lastAddedPosition, matchedIndex)}</span>);\n lastAddedPosition = matchedIndex;\n }\n const endingPlace = matchedIndex + highlightText.length;\n finalLabel.push(<mark key={`marked-${i}`}>{node.label.substring(lastAddedPosition, endingPlace)}</mark>);\n lastAddedPosition = endingPlace;\n }\n if (lastAddedPosition < node.label.length) {\n finalLabel.push(<span key={`normal-${matchedIndexes.length + 1}`}>{node.label.substring(lastAddedPosition)}</span>);\n }\n\n return <>{finalLabel}</>;\n },\n [highlightText],\n );\n\n return { getLabel };\n}\n"],"mappings":";;;;;;;;AAiCA,SAAOU,oBAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAA6B,MAAA,EAAAP,kBAAAK;CAA2C,IAAAG;AAAA,KAAAF,EAAA,OAAAN,eAAA;AAE3EQ,QAAAL,SAAA;AACE,OAAI,CAACH,iBAAiBL,cAAac,eAAgBN,KAAIO,SAAmD,IAAtG,CAAkEP,KAAIO,SAASC,QAAuBC,eAAA,QACjG,oBAAA,QAAA,EAAA,UAAOT,KAAIU,OAAc,CAAA;GAGlC,MAAAC,iBAAuB,IAAIC,OAAe;GAC1C,MAAAC,YAAkBb,KAAIU,MAAMI,mBAAoB;GAChD,MAAAC,aAAmBlB,cAAaiB,mBAAoB;GACpD,IAAAE,eAAmB;AAEnB,UAAO,MAAI;IACT,MAAAC,aAAmBJ,UAASK,QAASH,YAAYC,aAAa;AAC9D,QAAIC,eAAe,GACjB;AAEFN,mBAAcQ,KAAMF,WAAW;AAC/BD,mBAAeC,aAAaF,WAAUK;;AAGxC,OAAIT,eAAcS,WAAY,EAAC,QACtB,oBAAA,QAAA,EAAA,UAAOpB,KAAIU,OAAc,CAAA;GAIlC,MAAAW,aAAmB,IAAIT,OAAoB;GAC3C,IAAAU,oBAAwB;AACxB,QAAA,IAAAC,IAAa,GAAGA,IAAIZ,eAAcS,QAAS,EAAEG,GAAC;IAC5C,MAAAC,eAAqBb,eAAeY;AACpC,QAAIC,eAAeF,mBAAiB;AAClCD,gBAAUF,KAAM,oBAAA,QAAA,EAAA,UAA2BnB,KAAIU,MAAMe,UAAWH,mBAAmBE,aAAY,EAAS,EAA7E,UAAUD,IAAmE,CAAC;AACzGD,yBAAoBE;;IAEtB,MAAAE,cAAoBF,eAAe3B,cAAauB;AAChDC,eAAUF,KAAM,oBAAA,QAAA,EAAA,UAA2BnB,KAAIU,MAAMe,UAAWH,mBAAmBI,YAAW,EAAS,EAA5E,UAAUH,IAAkE,CAAC;AACxGD,wBAAoBI;;AAEtB,OAAIJ,oBAAoBtB,KAAIU,MAAMU,OAChCC,YAAUF,KAAM,oBAAA,QAAA,EAAA,UAAmDnB,KAAIU,MAAMe,UAAWH,kBAAiB,EAAS,EAAvF,UAAUX,eAAcS,SAAU,IAAqD,CAAC;AACpH,UAEM,oBAAA,UAAA,EAAA,UAAGC,YAAc,CAAA;;AACzBlB,IAAA,KAAAN;AAAAM,IAAA,KAAAE;OAAAA,MAAAF,EAAA;CA1CH,MAAAJ,WAAiBM;CA4Cf,IAAAsB;AAAA,KAAAxB,EAAA,OAAAJ,UAAA;AAEK4B,OAAA,EAAA5B,UAAY;AAAAI,IAAA,KAAAJ;AAAAI,IAAA,KAAAwB;OAAAA,MAAAxB,EAAA;AAAA,QAAZwB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseSelectionHandler.d.ts","names":[],"sources":["../../src/presentation-hierarchies-react/UseSelectionHandler.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"UseSelectionHandler.d.ts","names":[],"sources":["../../src/presentation-hierarchies-react/UseSelectionHandler.ts"],"mappings":";;;AAmBA;;;;;AAUA;;KAVY,aAAA;;;;;;;;;KAUA,mBAAA"}
|