@itwin/presentation-hierarchies-react 2.0.0-alpha.25 → 2.0.0-alpha.26
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 +53 -0
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.d.ts +2 -0
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.js +1 -1
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.d.ts +3 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.js +3 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/FilterAction.d.ts +16 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FilterAction.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/FilterAction.js +5 -11
- package/lib/esm/presentation-hierarchies-react/stratakit/FilterAction.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts +15 -13
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.js +17 -17
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/RenameAction.d.ts +14 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/RenameAction.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/RenameAction.js +2 -2
- package/lib/esm/presentation-hierarchies-react/stratakit/RenameAction.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts +9 -2
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js +12 -9
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js +16 -16
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react.d.ts +1 -1
- package/lib/esm/presentation-hierarchies-react.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react.js +1 -1
- package/lib/esm/presentation-hierarchies-react.js.map +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @itwin/presentation-hierarchies-react
|
|
2
2
|
|
|
3
|
+
## 2.0.0-alpha.26
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [#1023](https://github.com/iTwin/presentation/pull/1023): Split `getActions` into `getMenuActions` & `getInlineActions` for `StrataKitTreeRenderer` and `StrataKitTreeNodeRenderer`.
|
|
8
|
+
|
|
9
|
+
Updated peer dependencies:
|
|
10
|
+
|
|
11
|
+
- @stratakit/bricks@0.3.3
|
|
12
|
+
- @stratakit/foundations@0.2.2
|
|
13
|
+
- @stratakit/structures@0.3.1
|
|
14
|
+
|
|
15
|
+
Added `reserveSpace` property to `FilterAction` and `RenameAction`, which reserves space for the action when it is not available
|
|
16
|
+
|
|
17
|
+
### Minor Changes
|
|
18
|
+
|
|
19
|
+
- [#1007](https://github.com/iTwin/presentation/pull/1007): Renames:
|
|
20
|
+
`FlatNode` => `FlatTreeNodeItem`
|
|
21
|
+
`FlatTreeNode` => `FlatTreeItem`
|
|
22
|
+
`PlaceholderNode` => `PlaceholderItem`
|
|
23
|
+
`useFlatTreeNodeList` => `useFlatTreeItems`
|
|
24
|
+
|
|
25
|
+
Changed `FlatTreeNodeItem` (previously `FlatNode`) to have property `node: PresentationHierarchyNode` instead of extending `PresentationHierarchyNode`.
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- Updated dependencies:
|
|
30
|
+
- @itwin/presentation-hierarchies@2.0.0-alpha.2
|
|
31
|
+
|
|
3
32
|
## 2.0.0-alpha.25
|
|
4
33
|
|
|
5
34
|
### Patch Changes
|
|
@@ -365,6 +394,30 @@
|
|
|
365
394
|
|
|
366
395
|
- [#847](https://github.com/iTwin/presentation/pull/847): Moving tree rendering components to a new design systems.
|
|
367
396
|
|
|
397
|
+
## 1.7.1
|
|
398
|
+
|
|
399
|
+
### Patch Changes
|
|
400
|
+
|
|
401
|
+
- Updated dependencies:
|
|
402
|
+
- @itwin/presentation-hierarchies@1.6.1
|
|
403
|
+
|
|
404
|
+
## 1.7.0
|
|
405
|
+
|
|
406
|
+
### Minor Changes
|
|
407
|
+
|
|
408
|
+
- 64e80beaeb87e5797d8238c14fa9cd8dbfcee7c3: Added `abortSignal` to `getFilteredPaths` callback used by `UseTree` hook. This allows to cancel ongoing requests when component is unmounted or new request is started.
|
|
409
|
+
|
|
410
|
+
### Patch Changes
|
|
411
|
+
|
|
412
|
+
- Updated dependencies:
|
|
413
|
+
- @itwin/presentation-hierarchies@1.6.0
|
|
414
|
+
|
|
415
|
+
## 1.6.9
|
|
416
|
+
|
|
417
|
+
### Patch Changes
|
|
418
|
+
|
|
419
|
+
- [#1000](https://github.com/iTwin/presentation/pull/1000): Made sure `Apply filter` button becomes focused after hierarchy level filter is applied.
|
|
420
|
+
|
|
368
421
|
## 1.6.8
|
|
369
422
|
|
|
370
423
|
### Patch Changes
|
|
@@ -19,6 +19,8 @@ type UseIModelTreeProps = Omit<UseTreeProps, "getHierarchyProvider" | "getFilter
|
|
|
19
19
|
getFilteredPaths?: (props: {
|
|
20
20
|
/** Object that provides access to the iModel schema and can run queries against the iModel. */
|
|
21
21
|
imodelAccess: IModelAccess;
|
|
22
|
+
/** Signal indicating that that the request was canceled */
|
|
23
|
+
abortSignal: AbortSignal;
|
|
22
24
|
}) => Promise<HierarchyFilteringPath[] | undefined>;
|
|
23
25
|
};
|
|
24
26
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseIModelTree.d.ts","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseIModelTree.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,6BAA6B,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAC7H,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAW,YAAY,EAAE,aAAa,EAA2B,MAAM,cAAc,CAAC;AAE7F,cAAc;AACd,KAAK,4BAA4B,GAAG,KAAK,CAAC,OAAO,6BAA6B,CAAC,CAAC;AAEhF,cAAc;AACd,KAAK,YAAY,GAAG,4BAA4B,CAAC,cAAc,CAAC,CAAC;AAEjE;;;GAGG;AACH,KAAK,kBAAkB,GAAG,IAAI,CAAC,YAAY,EAAE,sBAAsB,GAAG,kBAAkB,CAAC,GACvF,IAAI,CAAC,4BAA4B,EAAE,kBAAkB,GAAG,cAAc,GAAG,eAAe,CAAC,GAAG;IAC1F,sDAAsD;IACtD,sBAAsB,EAAE,CAAC,KAAK,EAAE;QAAE,YAAY,EAAE,YAAY,CAAA;KAAE,KAAK,mBAAmB,CAAC;IAEvF,wCAAwC;IACxC,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE;QACzB,+FAA+F;QAC/F,YAAY,EAAE,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"UseIModelTree.d.ts","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseIModelTree.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,6BAA6B,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAC7H,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACnD,OAAO,EAAE,4BAA4B,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAW,YAAY,EAAE,aAAa,EAA2B,MAAM,cAAc,CAAC;AAE7F,cAAc;AACd,KAAK,4BAA4B,GAAG,KAAK,CAAC,OAAO,6BAA6B,CAAC,CAAC;AAEhF,cAAc;AACd,KAAK,YAAY,GAAG,4BAA4B,CAAC,cAAc,CAAC,CAAC;AAEjE;;;GAGG;AACH,KAAK,kBAAkB,GAAG,IAAI,CAAC,YAAY,EAAE,sBAAsB,GAAG,kBAAkB,CAAC,GACvF,IAAI,CAAC,4BAA4B,EAAE,kBAAkB,GAAG,cAAc,GAAG,eAAe,CAAC,GAAG;IAC1F,sDAAsD;IACtD,sBAAsB,EAAE,CAAC,KAAK,EAAE;QAAE,YAAY,EAAE,YAAY,CAAA;KAAE,KAAK,mBAAmB,CAAC;IAEvF,wCAAwC;IACxC,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE;QACzB,+FAA+F;QAC/F,YAAY,EAAE,YAAY,CAAC;QAC3B,2DAA2D;QAC3D,WAAW,EAAE,WAAW,CAAC;KAC1B,KAAK,OAAO,CAAC,sBAAsB,EAAE,GAAG,SAAS,CAAC,CAAC;CACrD,CAAC;AAEJ;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,aAAa,CAMtE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,kBAAkB,GAAG,4BAA4B,GAAG,aAAa,CAMrH"}
|
|
@@ -56,7 +56,7 @@ function useIModelTreeProps(props) {
|
|
|
56
56
|
hierarchyDefinition: getHierarchyDefinition({ imodelAccess }),
|
|
57
57
|
localizedStrings,
|
|
58
58
|
}), [imodelAccess, imodelChanged, getHierarchyDefinition, localizedStrings]),
|
|
59
|
-
getFilteredPaths: useCallback(async () => getFilteredPaths?.({ imodelAccess }), [imodelAccess, getFilteredPaths]),
|
|
59
|
+
getFilteredPaths: useCallback(async ({ abortSignal }) => getFilteredPaths?.({ imodelAccess, abortSignal }), [imodelAccess, getFilteredPaths]),
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
//# sourceMappingURL=UseIModelTree.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseIModelTree.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseIModelTree.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,6BAA6B,EAA+C,MAAM,iCAAiC,CAAC;AAG7H,OAAO,EAAE,OAAO,EAA+B,uBAAuB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"UseIModelTree.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseIModelTree.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,6BAA6B,EAA+C,MAAM,iCAAiC,CAAC;AAG7H,OAAO,EAAE,OAAO,EAA+B,uBAAuB,EAAE,MAAM,cAAc,CAAC;AA0B7F;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAAC,KAAyB;IACrD,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;IACnH,OAAO,OAAO,CAAC;QACb,GAAG,IAAI;QACP,GAAG,kBAAkB,CAAC,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,CAAC;KACnH,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,6BAA6B,CAAC,KAAwD;IACpG,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;IACnH,OAAO,uBAAuB,CAAC;QAC7B,GAAG,IAAI;QACP,GAAG,kBAAkB,CAAC,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,CAAC;KACnH,CAAC,CAAC;AACL,CAAC;AAED,SAAS,kBAAkB,CACzB,KAAsI;IAEtI,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,GAAG,KAAK,CAAC;IAC1G,OAAO;QACL,oBAAoB,EAAE,WAAW,CAC/B,GAAG,EAAE,CACH,6BAA6B,CAAC;YAC5B,YAAY;YACZ,aAAa;YACb,mBAAmB,EAAE,sBAAsB,CAAC,EAAE,YAAY,EAAE,CAAC;YAC7D,gBAAgB;SACjB,CAAC,EACJ,CAAC,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAE,gBAAgB,CAAC,CACxE;QACD,gBAAgB,EAAE,WAAW,CAC3B,KAAK,EAAE,EAAE,WAAW,EAAgC,EAAE,EAAE,CAAC,gBAAgB,EAAE,CAAC,EAAE,YAAY,EAAE,WAAW,EAAE,CAAC,EAC1G,CAAC,YAAY,EAAE,gBAAgB,CAAC,CACjC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useCallback } from \"react\";\nimport { createIModelHierarchyProvider, HierarchyDefinition, HierarchyFilteringPath } from \"@itwin/presentation-hierarchies\";\nimport { Props } from \"@itwin/presentation-shared\";\nimport { UseUnifiedTreeSelectionProps } from \"./internal/UseUnifiedSelection.js\";\nimport { useTree, UseTreeProps, UseTreeResult, useUnifiedSelectionTree } from \"./UseTree.js\";\n\n/** @public */\ntype IModelHierarchyProviderProps = Props<typeof createIModelHierarchyProvider>;\n\n/** @public */\ntype IModelAccess = IModelHierarchyProviderProps[\"imodelAccess\"];\n\n/**\n * Props for `useIModelTree` and `useIModelUnifiedSelectionTree` hooks.\n * @public\n */\ntype UseIModelTreeProps = Omit<UseTreeProps, \"getHierarchyProvider\" | \"getFilteredPaths\"> &\n Pick<IModelHierarchyProviderProps, \"localizedStrings\" | \"imodelAccess\" | \"imodelChanged\"> & {\n /** Provides the hierarchy definition for the tree. */\n getHierarchyDefinition: (props: { imodelAccess: IModelAccess }) => HierarchyDefinition;\n\n /** Provides paths to filtered nodes. */\n getFilteredPaths?: (props: {\n /** Object that provides access to the iModel schema and can run queries against the iModel. */\n imodelAccess: IModelAccess;\n /** Signal indicating that that the request was canceled */\n abortSignal: AbortSignal;\n }) => Promise<HierarchyFilteringPath[] | undefined>;\n };\n\n/**\n * A React hook that creates state for a tree component whose displayed hierarchy is based on\n * iModel data.\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useTree`\n * @see `useIModelUnifiedSelectionTree`\n * @public\n */\nexport function useIModelTree(props: UseIModelTreeProps): UseTreeResult {\n const { imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings, ...rest } = props;\n return useTree({\n ...rest,\n ...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings }),\n });\n}\n\n/**\n * A React hook that creates state for a tree component whose displayed hierarchy is based on\n * iModel data and that is integrated with unified selection through the given selection\n * storage (previously the storage was provided through the, now deprecated, `UnifiedSelectionProvider`).\n *\n * The hook uses `@itwin/presentation-hierarchies` package to load the hierarchy data and returns a\n * component-agnostic result which may be used to render the hierarchy using any UI framework.\n *\n * See `README.md` for an example\n *\n * @see `useIModelTree`\n * @see `useUnifiedSelectionTree`\n * @see `UnifiedSelectionProvider`\n * @public\n */\nexport function useIModelUnifiedSelectionTree(props: UseIModelTreeProps & UseUnifiedTreeSelectionProps): UseTreeResult {\n const { imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings, ...rest } = props;\n return useUnifiedSelectionTree({\n ...rest,\n ...useIModelTreeProps({ imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings }),\n });\n}\n\nfunction useIModelTreeProps(\n props: Pick<UseIModelTreeProps, \"imodelAccess\" | \"imodelChanged\" | \"getHierarchyDefinition\" | \"getFilteredPaths\" | \"localizedStrings\">,\n): Pick<UseTreeProps, \"getHierarchyProvider\" | \"getFilteredPaths\"> {\n const { imodelAccess, imodelChanged, getHierarchyDefinition, getFilteredPaths, localizedStrings } = props;\n return {\n getHierarchyProvider: useCallback(\n () =>\n createIModelHierarchyProvider({\n imodelAccess,\n imodelChanged,\n hierarchyDefinition: getHierarchyDefinition({ imodelAccess }),\n localizedStrings,\n }),\n [imodelAccess, imodelChanged, getHierarchyDefinition, localizedStrings],\n ),\n getFilteredPaths: useCallback(\n async ({ abortSignal }: { abortSignal: AbortSignal }) => getFilteredPaths?.({ imodelAccess, abortSignal }),\n [imodelAccess, getFilteredPaths],\n ),\n };\n}\n"]}
|
|
@@ -37,7 +37,9 @@ export interface UseTreeProps {
|
|
|
37
37
|
/** Provides the hierarchy provider for the tree. */
|
|
38
38
|
getHierarchyProvider: () => HierarchyProvider;
|
|
39
39
|
/** Provides paths to filtered nodes. */
|
|
40
|
-
getFilteredPaths?: (
|
|
40
|
+
getFilteredPaths?: ({ abortSignal }: {
|
|
41
|
+
abortSignal: AbortSignal;
|
|
42
|
+
}) => Promise<HierarchyFilteringPath[] | undefined>;
|
|
41
43
|
/**
|
|
42
44
|
* Callback that is called just after a certain action is finished.
|
|
43
45
|
* Can be used for performance tracking.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseTree.d.ts","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseTree.ts"],"names":[],"mappings":"AAMA,OAAO,E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sB,EAAE,sBAAsB,CAAC;CAChD,GACD;IACE,6FAA6F;IAC7F,sBAAsB,EAAE,SAAS,CAAC;IAClC;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;CACvC,CAAC"}
|
|
@@ -91,6 +91,7 @@ function useTreeInternal({ getHierarchyProvider, getFilteredPaths, onPerformance
|
|
|
91
91
|
const [isFiltering, setIsFiltering] = useState(false);
|
|
92
92
|
useEffect(() => {
|
|
93
93
|
let disposed = false;
|
|
94
|
+
const controller = new AbortController();
|
|
94
95
|
void (async () => {
|
|
95
96
|
if (!hierarchyProvider) {
|
|
96
97
|
return;
|
|
@@ -105,7 +106,7 @@ function useTreeInternal({ getHierarchyProvider, getFilteredPaths, onPerformance
|
|
|
105
106
|
setIsFiltering(true);
|
|
106
107
|
let paths;
|
|
107
108
|
try {
|
|
108
|
-
paths = await getFilteredPaths();
|
|
109
|
+
paths = await getFilteredPaths({ abortSignal: controller.signal });
|
|
109
110
|
}
|
|
110
111
|
catch {
|
|
111
112
|
}
|
|
@@ -117,6 +118,7 @@ function useTreeInternal({ getHierarchyProvider, getFilteredPaths, onPerformance
|
|
|
117
118
|
}
|
|
118
119
|
})();
|
|
119
120
|
return () => {
|
|
121
|
+
controller.abort();
|
|
120
122
|
disposed = true;
|
|
121
123
|
};
|
|
122
124
|
}, [hierarchyProvider, getFilteredPaths, actions]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UseTree.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseTree.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC1E,OAAO,EAAiD,aAAa,EAAqB,MAAM,iCAAiC,CAAC;AAElI,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,SAAS,EAA6C,MAAM,yBA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AAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,iBAAiB,IAAI,IAAI,CAAC,QAAQ;QAChH,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,cAAc;QACjC,KAAK,EAAE,IAAI,CAAC,KAAK;KAClB,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { GenericInstanceFilter, HierarchyFilteringPath, HierarchyNode, HierarchyProvider } from \"@itwin/presentation-hierarchies\";\nimport { IPrimitiveValueFormatter } from \"@itwin/presentation-shared\";\nimport { TreeActions } from \"./internal/TreeActions.js\";\nimport { TreeModel, TreeModelHierarchyNode, TreeModelRootNode } from \"./internal/TreeModel.js\";\nimport { useUnifiedTreeSelection, UseUnifiedTreeSelectionProps } from \"./internal/UseUnifiedSelection.js\";\nimport { safeDispose } from \"./internal/Utils.js\";\nimport { RootErrorRendererProps, TreeRendererProps } from \"./Renderers.js\";\nimport { PresentationHierarchyNode } from \"./TreeNode.js\";\nimport { SelectionChangeType } from \"./UseSelectionHandler.js\";\nimport { useLatest } from \"./Utils.js\";\n\n/**\n * A React hook that creates state for a tree component.\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 `useUnifiedSelectionTree`\n * @see `useIModelTree`\n * @public\n */\nexport function useTree(props: UseTreeProps): UseTreeResult {\n const { getTreeModelNode: _, ...rest } = useTreeInternal(props);\n return rest;\n}\n\n/**\n * A React hook that creates state for a tree component, that is integrated with unified selection\n * through the given selection storage (previously the storage was provided through the, now\n * 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 `useTree`\n * @see `useIModelUnifiedSelectionTree`\n * @see `UnifiedSelectionProvider`\n * @public\n */\nexport function useUnifiedSelectionTree({ sourceName, selectionStorage, ...props }: UseTreeProps & UseUnifiedTreeSelectionProps): UseTreeResult {\n const { getTreeModelNode, ...rest } = useTreeInternal(props);\n const selectionProps = useUnifiedTreeSelection({ sourceName, selectionStorage, getTreeModelNode });\n if (rest.rootErrorRendererProps === undefined && rest.treeRendererProps?.rootNodes) {\n return {\n ...rest,\n treeRendererProps: {\n ...rest.treeRendererProps,\n ...selectionProps,\n },\n };\n }\n\n return {\n ...rest,\n };\n}\n\n/** @public */\nexport interface UseTreeProps {\n /** Provides the hierarchy provider for the tree. */\n getHierarchyProvider: () => HierarchyProvider;\n /** Provides paths to filtered nodes. */\n getFilteredPaths?: () => Promise<HierarchyFilteringPath[] | undefined>;\n /**\n * Callback that is called just after a certain action is finished.\n * Can be used for performance tracking.\n */\n onPerformanceMeasured?: (action: \"initial-load\" | \"hierarchy-level-load\" | \"reload\", duration: number) => void;\n /** Action to perform when hierarchy level contains more items that the specified limit. */\n onHierarchyLimitExceeded?: (props: { parentId?: string; filter?: GenericInstanceFilter; limit?: number | \"unbounded\" }) => void;\n /** Action to perform when an error occurs while loading hierarchy. */\n onHierarchyLoadError?: (props: { parentId?: string; type: \"timeout\" | \"unknown\"; error: unknown }) => void;\n}\n\n/** @public */\nexport type UseTreeResult = {\n /**\n * Specifies whether tree is reloading or not. It is set to `false` when initial tree load is in progress to check if\n * or tree is reloading.\n */\n isReloading: boolean;\n /** Get a tree node by id */\n getNode: (nodeId: string) => PresentationHierarchyNode | undefined;\n /** Sets a formatter for the primitive values that are displayed in the hierarchy. */\n setFormatter: (formatter: IPrimitiveValueFormatter | undefined) => void;\n} & RendererProps;\n\n/**.\n * @alpha\n */\ntype RendererProps =\n | {\n /**\n * An object containing information used to render root error handling UI.\n * Use in combination with `RootErrorRenderer` or your custom implementation.\n * Defined when root nodes fail to load.\n */\n rootErrorRendererProps: RootErrorRendererProps;\n }\n | {\n /** Is undefined when rootNodes where sucessfully loaded or are in initial loading process */\n rootErrorRendererProps: undefined;\n /**\n * An object containing information used to render tree.\n * Use with `TreeRenderer` or your custom implementation.\n * Is undefined on initial loading process.\n */\n treeRendererProps?: TreeRendererProps;\n };\n\ninterface TreeState {\n model: TreeModel;\n rootNodes: Array<PresentationHierarchyNode> | undefined;\n}\n\nfunction useTreeInternal({\n getHierarchyProvider,\n getFilteredPaths,\n onPerformanceMeasured,\n onHierarchyLimitExceeded,\n onHierarchyLoadError,\n}: UseTreeProps): UseTreeResult & {\n getTreeModelNode: (nodeId: string) => TreeModelRootNode | TreeModelHierarchyNode | undefined;\n} {\n const [state, setState] = useState<TreeState>({\n model: { idToNode: new Map(), parentChildMap: new Map(), rootNode: { id: undefined, nodeData: undefined } },\n rootNodes: undefined,\n });\n const onPerformanceMeasuredRef = useLatest(onPerformanceMeasured);\n const onHierarchyLimitExceededRef = useLatest(onHierarchyLimitExceeded);\n const onHierarchyLoadErrorRef = useLatest(onHierarchyLoadError);\n\n const [actions] = useState<TreeActions>(\n () =>\n new TreeActions(\n (model) => {\n const rootNodes = model.parentChildMap.get(undefined) !== undefined ? generateTreeStructure(undefined, model) : undefined;\n setState({\n model,\n rootNodes,\n });\n },\n (actionType, duration) => onPerformanceMeasuredRef.current?.(actionType, duration),\n (props) => onHierarchyLimitExceededRef.current?.(props),\n (props) => onHierarchyLoadErrorRef.current?.(props),\n ),\n );\n const currentFormatter = useRef<IPrimitiveValueFormatter>();\n\n const [hierarchyProvider, setHierarchyProvider] = useState<HierarchyProvider | undefined>();\n useEffect(() => {\n const provider = getHierarchyProvider();\n provider.setFormatter(currentFormatter.current);\n const removeHierarchyChangedListener = provider.hierarchyChanged.addListener((hierarchyChangeArgs) => {\n const shouldDiscardState = hierarchyChangeArgs?.filterChange?.newFilter !== undefined;\n actions.reloadTree({ state: shouldDiscardState ? \"discard\" : \"keep\" });\n });\n actions.setHierarchyProvider(provider);\n setHierarchyProvider(provider);\n return () => {\n removeHierarchyChangedListener();\n actions.reset();\n safeDispose(provider);\n };\n }, [actions, getHierarchyProvider]);\n\n const [isFiltering, setIsFiltering] = useState(false);\n useEffect(() => {\n let disposed = false;\n void (async () => {\n if (!hierarchyProvider) {\n return;\n }\n\n if (!getFilteredPaths) {\n hierarchyProvider.setHierarchyFilter(undefined);\n // reload tree in case hierarchy provider does not use hierarchy filter to load initial nodes\n actions.reloadTree({ state: \"keep\" });\n setIsFiltering(false);\n return;\n }\n\n setIsFiltering(true);\n let paths: HierarchyFilteringPath[] | undefined;\n try {\n paths = await getFilteredPaths();\n } catch {\n } finally {\n if (!disposed) {\n hierarchyProvider.setHierarchyFilter(paths ? { paths } : undefined);\n setIsFiltering(false);\n }\n }\n })();\n return () => {\n disposed = true;\n };\n }, [hierarchyProvider, getFilteredPaths, actions]);\n\n const getTreeModelNode = useCallback<(nodeId: string) => TreeModelRootNode | TreeModelHierarchyNode | undefined>(\n (nodeId: string) => {\n return actions.getNode(nodeId);\n },\n [actions],\n );\n\n const getNode = useCallback(\n (nodeId: string): PresentationHierarchyNode | undefined => {\n const node = actions.getNode(nodeId);\n if (!node || node.id === undefined) {\n return undefined;\n }\n return createPresentationHierarchyNode(node, state.model);\n },\n [actions, state.model],\n );\n\n const expandNode = useCallback<TreeRendererProps[\"expandNode\"]>(\n (nodeId: string, isExpanded: boolean) => {\n actions.expandNode(nodeId, isExpanded);\n },\n [actions],\n );\n\n const reloadTree = useCallback<TreeRendererProps[\"reloadTree\"]>(\n (options) => {\n actions.reloadTree(options);\n },\n [actions],\n );\n\n const selectNodes = useCallback<TreeRendererProps[\"selectNodes\"]>(\n (nodeIds: Array<string>, changeType: SelectionChangeType) => {\n actions.selectNodes(nodeIds, changeType);\n },\n [actions],\n );\n\n const isNodeSelected = useCallback<TreeRendererProps[\"isNodeSelected\"]>((nodeId: string) => TreeModel.isNodeSelected(state.model, nodeId), [state]);\n\n const setFormatter = useCallback<UseTreeResult[\"setFormatter\"]>(\n (formatter: IPrimitiveValueFormatter | undefined) => {\n currentFormatter.current = formatter;\n /* c8 ignore next 3 */\n if (!hierarchyProvider) {\n return;\n }\n\n hierarchyProvider.setFormatter(formatter);\n },\n [hierarchyProvider],\n );\n\n const getHierarchyLevelDetails = useCallback<TreeRendererProps[\"getHierarchyLevelDetails\"]>(\n (nodeId) => {\n const node = actions.getNode(nodeId);\n if (!hierarchyProvider || !node) {\n return undefined;\n }\n const hierarchyNode = node.nodeData;\n if (hierarchyNode && HierarchyNode.isGroupingNode(hierarchyNode)) {\n return undefined;\n }\n\n return {\n hierarchyNode,\n getInstanceKeysIterator: (props) =>\n hierarchyProvider.getNodeInstanceKeys({\n parentNode: hierarchyNode,\n instanceFilter: props?.instanceFilter,\n hierarchyLevelSizeLimit: props?.hierarchyLevelSizeLimit,\n }),\n instanceFilter: node.instanceFilter,\n setInstanceFilter: (filter) => actions.setInstanceFilter(nodeId, filter),\n sizeLimit: node.hierarchyLimit,\n setSizeLimit: (value) => actions.setHierarchyLimit(nodeId, value),\n };\n },\n [actions, hierarchyProvider],\n );\n\n const renderProps: RendererProps = useMemo(() => {\n if (state.model.rootNode.error) {\n return {\n rootErrorRendererProps: {\n error: state.model.rootNode.error,\n reloadTree,\n getHierarchyLevelDetails,\n },\n };\n }\n return {\n rootErrorRendererProps: undefined,\n treeRendererProps: state.rootNodes\n ? {\n rootNodes: state.rootNodes,\n expandNode,\n selectNodes,\n isNodeSelected,\n reloadTree,\n getHierarchyLevelDetails,\n }\n : undefined,\n };\n }, [expandNode, getHierarchyLevelDetails, isNodeSelected, reloadTree, selectNodes, state.model.rootNode.error, state.rootNodes]);\n\n return {\n ...renderProps,\n isReloading: !!state.model.rootNode.isLoading || isFiltering,\n getTreeModelNode,\n getNode,\n setFormatter,\n };\n}\n\nfunction generateTreeStructure(parentNodeId: string | undefined, model: TreeModel): Array<PresentationHierarchyNode> | undefined {\n const currentChildren = model.parentChildMap.get(parentNodeId);\n if (!currentChildren) {\n return undefined;\n }\n\n return currentChildren\n .map((childId) => model.idToNode.get(childId))\n .filter((node): node is TreeModelHierarchyNode => !!node)\n .map<PresentationHierarchyNode>((node) => {\n return createPresentationHierarchyNode(node, model);\n });\n}\n\nfunction createPresentationHierarchyNode(modelNode: TreeModelHierarchyNode, model: TreeModel): PresentationHierarchyNode {\n let children: Array<PresentationHierarchyNode> | undefined;\n return {\n ...toPresentationHierarchyNodeBase(modelNode),\n get children() {\n if (!children) {\n children = generateTreeStructure(modelNode.id, model);\n }\n return children ? children : modelNode.children === true ? true : [];\n },\n };\n}\n\nfunction toPresentationHierarchyNodeBase(node: TreeModelHierarchyNode): Omit<PresentationHierarchyNode, \"children\"> {\n return {\n id: node.id,\n label: node.label,\n nodeData: node.nodeData,\n isLoading: !!node.isLoading,\n isExpanded: !!node.isExpanded,\n isFilterable: !HierarchyNode.isGroupingNode(node.nodeData) && !!node.nodeData.supportsFiltering && node.children,\n isFiltered: !!node.instanceFilter,\n error: node.error,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"UseTree.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UseTree.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC1E,OAAO,EAAiD,aAAa,EAAqB,MAAM,iCAAiC,CAAC;AAElI,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,SAAS,EAA6C,MAAM,yBAAyB,CAAC;AAC/F,OAAO,EAAE,uBAAuB,EAAgC,MAAM,mCAAmC,CAAC;AAC1G,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAIlD,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC;;;;;;;;;;;GAW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C,QAAQ,CAAC,iBAAiB,IAAI,IAAI,CAAC,QAAQ;QAChH,UAAU,EAAE,CAAC,CAAC,IAAI,CAAC,cAAc;QACjC,KAAK,EAAE,IAAI,CAAC,KAAK;KAClB,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { GenericInstanceFilter, HierarchyFilteringPath, HierarchyNode, HierarchyProvider } from \"@itwin/presentation-hierarchies\";\nimport { IPrimitiveValueFormatter } from \"@itwin/presentation-shared\";\nimport { TreeActions } from \"./internal/TreeActions.js\";\nimport { TreeModel, TreeModelHierarchyNode, TreeModelRootNode } from \"./internal/TreeModel.js\";\nimport { useUnifiedTreeSelection, UseUnifiedTreeSelectionProps } from \"./internal/UseUnifiedSelection.js\";\nimport { safeDispose } from \"./internal/Utils.js\";\nimport { RootErrorRendererProps, TreeRendererProps } from \"./Renderers.js\";\nimport { PresentationHierarchyNode } from \"./TreeNode.js\";\nimport { SelectionChangeType } from \"./UseSelectionHandler.js\";\nimport { useLatest } from \"./Utils.js\";\n\n/**\n * A React hook that creates state for a tree component.\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 `useUnifiedSelectionTree`\n * @see `useIModelTree`\n * @public\n */\nexport function useTree(props: UseTreeProps): UseTreeResult {\n const { getTreeModelNode: _, ...rest } = useTreeInternal(props);\n return rest;\n}\n\n/**\n * A React hook that creates state for a tree component, that is integrated with unified selection\n * through the given selection storage (previously the storage was provided through the, now\n * 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 `useTree`\n * @see `useIModelUnifiedSelectionTree`\n * @see `UnifiedSelectionProvider`\n * @public\n */\nexport function useUnifiedSelectionTree({ sourceName, selectionStorage, ...props }: UseTreeProps & UseUnifiedTreeSelectionProps): UseTreeResult {\n const { getTreeModelNode, ...rest } = useTreeInternal(props);\n const selectionProps = useUnifiedTreeSelection({ sourceName, selectionStorage, getTreeModelNode });\n if (rest.rootErrorRendererProps === undefined && rest.treeRendererProps?.rootNodes) {\n return {\n ...rest,\n treeRendererProps: {\n ...rest.treeRendererProps,\n ...selectionProps,\n },\n };\n }\n\n return {\n ...rest,\n };\n}\n\n/** @public */\nexport interface UseTreeProps {\n /** Provides the hierarchy provider for the tree. */\n getHierarchyProvider: () => HierarchyProvider;\n /** Provides paths to filtered nodes. */\n getFilteredPaths?: ({ abortSignal }: { abortSignal: AbortSignal }) => Promise<HierarchyFilteringPath[] | undefined>;\n /**\n * Callback that is called just after a certain action is finished.\n * Can be used for performance tracking.\n */\n onPerformanceMeasured?: (action: \"initial-load\" | \"hierarchy-level-load\" | \"reload\", duration: number) => void;\n /** Action to perform when hierarchy level contains more items that the specified limit. */\n onHierarchyLimitExceeded?: (props: { parentId?: string; filter?: GenericInstanceFilter; limit?: number | \"unbounded\" }) => void;\n /** Action to perform when an error occurs while loading hierarchy. */\n onHierarchyLoadError?: (props: { parentId?: string; type: \"timeout\" | \"unknown\"; error: unknown }) => void;\n}\n\n/** @public */\nexport type UseTreeResult = {\n /**\n * Specifies whether tree is reloading or not. It is set to `false` when initial tree load is in progress to check if\n * or tree is reloading.\n */\n isReloading: boolean;\n /** Get a tree node by id */\n getNode: (nodeId: string) => PresentationHierarchyNode | undefined;\n /** Sets a formatter for the primitive values that are displayed in the hierarchy. */\n setFormatter: (formatter: IPrimitiveValueFormatter | undefined) => void;\n} & RendererProps;\n\n/**.\n * @alpha\n */\ntype RendererProps =\n | {\n /**\n * An object containing information used to render root error handling UI.\n * Use in combination with `RootErrorRenderer` or your custom implementation.\n * Defined when root nodes fail to load.\n */\n rootErrorRendererProps: RootErrorRendererProps;\n }\n | {\n /** Is undefined when rootNodes where sucessfully loaded or are in initial loading process */\n rootErrorRendererProps: undefined;\n /**\n * An object containing information used to render tree.\n * Use with `TreeRenderer` or your custom implementation.\n * Is undefined on initial loading process.\n */\n treeRendererProps?: TreeRendererProps;\n };\n\ninterface TreeState {\n model: TreeModel;\n rootNodes: Array<PresentationHierarchyNode> | undefined;\n}\n\nfunction useTreeInternal({\n getHierarchyProvider,\n getFilteredPaths,\n onPerformanceMeasured,\n onHierarchyLimitExceeded,\n onHierarchyLoadError,\n}: UseTreeProps): UseTreeResult & {\n getTreeModelNode: (nodeId: string) => TreeModelRootNode | TreeModelHierarchyNode | undefined;\n} {\n const [state, setState] = useState<TreeState>({\n model: { idToNode: new Map(), parentChildMap: new Map(), rootNode: { id: undefined, nodeData: undefined } },\n rootNodes: undefined,\n });\n const onPerformanceMeasuredRef = useLatest(onPerformanceMeasured);\n const onHierarchyLimitExceededRef = useLatest(onHierarchyLimitExceeded);\n const onHierarchyLoadErrorRef = useLatest(onHierarchyLoadError);\n\n const [actions] = useState<TreeActions>(\n () =>\n new TreeActions(\n (model) => {\n const rootNodes = model.parentChildMap.get(undefined) !== undefined ? generateTreeStructure(undefined, model) : undefined;\n setState({\n model,\n rootNodes,\n });\n },\n (actionType, duration) => onPerformanceMeasuredRef.current?.(actionType, duration),\n (props) => onHierarchyLimitExceededRef.current?.(props),\n (props) => onHierarchyLoadErrorRef.current?.(props),\n ),\n );\n const currentFormatter = useRef<IPrimitiveValueFormatter>();\n\n const [hierarchyProvider, setHierarchyProvider] = useState<HierarchyProvider | undefined>();\n useEffect(() => {\n const provider = getHierarchyProvider();\n provider.setFormatter(currentFormatter.current);\n const removeHierarchyChangedListener = provider.hierarchyChanged.addListener((hierarchyChangeArgs) => {\n const shouldDiscardState = hierarchyChangeArgs?.filterChange?.newFilter !== undefined;\n actions.reloadTree({ state: shouldDiscardState ? \"discard\" : \"keep\" });\n });\n actions.setHierarchyProvider(provider);\n setHierarchyProvider(provider);\n return () => {\n removeHierarchyChangedListener();\n actions.reset();\n safeDispose(provider);\n };\n }, [actions, getHierarchyProvider]);\n\n const [isFiltering, setIsFiltering] = useState(false);\n useEffect(() => {\n let disposed = false;\n const controller = new AbortController();\n void (async () => {\n if (!hierarchyProvider) {\n return;\n }\n\n if (!getFilteredPaths) {\n hierarchyProvider.setHierarchyFilter(undefined);\n // reload tree in case hierarchy provider does not use hierarchy filter to load initial nodes\n actions.reloadTree({ state: \"keep\" });\n setIsFiltering(false);\n return;\n }\n\n setIsFiltering(true);\n let paths: HierarchyFilteringPath[] | undefined;\n try {\n paths = await getFilteredPaths({ abortSignal: controller.signal });\n } catch {\n } finally {\n if (!disposed) {\n hierarchyProvider.setHierarchyFilter(paths ? { paths } : undefined);\n setIsFiltering(false);\n }\n }\n })();\n return () => {\n controller.abort();\n disposed = true;\n };\n }, [hierarchyProvider, getFilteredPaths, actions]);\n\n const getTreeModelNode = useCallback<(nodeId: string) => TreeModelRootNode | TreeModelHierarchyNode | undefined>(\n (nodeId: string) => {\n return actions.getNode(nodeId);\n },\n [actions],\n );\n\n const getNode = useCallback(\n (nodeId: string): PresentationHierarchyNode | undefined => {\n const node = actions.getNode(nodeId);\n if (!node || node.id === undefined) {\n return undefined;\n }\n return createPresentationHierarchyNode(node, state.model);\n },\n [actions, state.model],\n );\n\n const expandNode = useCallback<TreeRendererProps[\"expandNode\"]>(\n (nodeId: string, isExpanded: boolean) => {\n actions.expandNode(nodeId, isExpanded);\n },\n [actions],\n );\n\n const reloadTree = useCallback<TreeRendererProps[\"reloadTree\"]>(\n (options) => {\n actions.reloadTree(options);\n },\n [actions],\n );\n\n const selectNodes = useCallback<TreeRendererProps[\"selectNodes\"]>(\n (nodeIds: Array<string>, changeType: SelectionChangeType) => {\n actions.selectNodes(nodeIds, changeType);\n },\n [actions],\n );\n\n const isNodeSelected = useCallback<TreeRendererProps[\"isNodeSelected\"]>((nodeId: string) => TreeModel.isNodeSelected(state.model, nodeId), [state]);\n\n const setFormatter = useCallback<UseTreeResult[\"setFormatter\"]>(\n (formatter: IPrimitiveValueFormatter | undefined) => {\n currentFormatter.current = formatter;\n /* c8 ignore next 3 */\n if (!hierarchyProvider) {\n return;\n }\n\n hierarchyProvider.setFormatter(formatter);\n },\n [hierarchyProvider],\n );\n\n const getHierarchyLevelDetails = useCallback<TreeRendererProps[\"getHierarchyLevelDetails\"]>(\n (nodeId) => {\n const node = actions.getNode(nodeId);\n if (!hierarchyProvider || !node) {\n return undefined;\n }\n const hierarchyNode = node.nodeData;\n if (hierarchyNode && HierarchyNode.isGroupingNode(hierarchyNode)) {\n return undefined;\n }\n\n return {\n hierarchyNode,\n getInstanceKeysIterator: (props) =>\n hierarchyProvider.getNodeInstanceKeys({\n parentNode: hierarchyNode,\n instanceFilter: props?.instanceFilter,\n hierarchyLevelSizeLimit: props?.hierarchyLevelSizeLimit,\n }),\n instanceFilter: node.instanceFilter,\n setInstanceFilter: (filter) => actions.setInstanceFilter(nodeId, filter),\n sizeLimit: node.hierarchyLimit,\n setSizeLimit: (value) => actions.setHierarchyLimit(nodeId, value),\n };\n },\n [actions, hierarchyProvider],\n );\n\n const renderProps: RendererProps = useMemo(() => {\n if (state.model.rootNode.error) {\n return {\n rootErrorRendererProps: {\n error: state.model.rootNode.error,\n reloadTree,\n getHierarchyLevelDetails,\n },\n };\n }\n return {\n rootErrorRendererProps: undefined,\n treeRendererProps: state.rootNodes\n ? {\n rootNodes: state.rootNodes,\n expandNode,\n selectNodes,\n isNodeSelected,\n reloadTree,\n getHierarchyLevelDetails,\n }\n : undefined,\n };\n }, [expandNode, getHierarchyLevelDetails, isNodeSelected, reloadTree, selectNodes, state.model.rootNode.error, state.rootNodes]);\n\n return {\n ...renderProps,\n isReloading: !!state.model.rootNode.isLoading || isFiltering,\n getTreeModelNode,\n getNode,\n setFormatter,\n };\n}\n\nfunction generateTreeStructure(parentNodeId: string | undefined, model: TreeModel): Array<PresentationHierarchyNode> | undefined {\n const currentChildren = model.parentChildMap.get(parentNodeId);\n if (!currentChildren) {\n return undefined;\n }\n\n return currentChildren\n .map((childId) => model.idToNode.get(childId))\n .filter((node): node is TreeModelHierarchyNode => !!node)\n .map<PresentationHierarchyNode>((node) => {\n return createPresentationHierarchyNode(node, model);\n });\n}\n\nfunction createPresentationHierarchyNode(modelNode: TreeModelHierarchyNode, model: TreeModel): PresentationHierarchyNode {\n let children: Array<PresentationHierarchyNode> | undefined;\n return {\n ...toPresentationHierarchyNodeBase(modelNode),\n get children() {\n if (!children) {\n children = generateTreeStructure(modelNode.id, model);\n }\n return children ? children : modelNode.children === true ? true : [];\n },\n };\n}\n\nfunction toPresentationHierarchyNodeBase(node: TreeModelHierarchyNode): Omit<PresentationHierarchyNode, \"children\"> {\n return {\n id: node.id,\n label: node.label,\n nodeData: node.nodeData,\n isLoading: !!node.isLoading,\n isExpanded: !!node.isExpanded,\n isFilterable: !HierarchyNode.isGroupingNode(node.nodeData) && !!node.nodeData.supportsFiltering && node.children,\n isFiltered: !!node.instanceFilter,\n error: node.error,\n };\n}\n"]}
|
|
@@ -4,6 +4,14 @@ import { PresentationHierarchyNode } from "../TreeNode.js";
|
|
|
4
4
|
export type FilterActionProps = {
|
|
5
5
|
/** Action to perform when the filter button is clicked for this node. */
|
|
6
6
|
onFilter?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;
|
|
7
|
+
/**
|
|
8
|
+
* Indicates that space for this action button should be reserved, even when the action is not available.
|
|
9
|
+
* For nodes that don't support filtering, `<FilterAction reserveSpace />` renders:
|
|
10
|
+
*
|
|
11
|
+
* - Blank space when the action is used as an inline action. It's recommended to set this prop to keep all action buttons of the same kind vertically aligned.
|
|
12
|
+
* - Disabled menu item when the action is used as a menu action.
|
|
13
|
+
*/
|
|
14
|
+
reserveSpace: true | undefined;
|
|
7
15
|
} & Pick<TreeRendererProps, "getHierarchyLevelDetails">;
|
|
8
16
|
/**
|
|
9
17
|
* React component that renders a filter action for a tree item.
|
|
@@ -12,6 +20,14 @@ export type FilterActionProps = {
|
|
|
12
20
|
export declare const FilterAction: import("react").NamedExoticComponent<{
|
|
13
21
|
/** Action to perform when the filter button is clicked for this node. */
|
|
14
22
|
onFilter?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;
|
|
23
|
+
/**
|
|
24
|
+
* Indicates that space for this action button should be reserved, even when the action is not available.
|
|
25
|
+
* For nodes that don't support filtering, `<FilterAction reserveSpace />` renders:
|
|
26
|
+
*
|
|
27
|
+
* - Blank space when the action is used as an inline action. It's recommended to set this prop to keep all action buttons of the same kind vertically aligned.
|
|
28
|
+
* - Disabled menu item when the action is used as a menu action.
|
|
29
|
+
*/
|
|
30
|
+
reserveSpace: true | undefined;
|
|
15
31
|
} & Pick<TreeRendererProps, "getHierarchyLevelDetails"> & {
|
|
16
32
|
node: PresentationHierarchyNode;
|
|
17
33
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FilterAction.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/FilterAction.tsx"],"names":[],"mappings":"AAQA,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAG3D,aAAa;AACb,MAAM,MAAM,iBAAiB,GAAG;IAC9B,yEAAyE;IACzE,QAAQ,CAAC,EAAE,CAAC,qBAAqB,EAAE,qBAAqB,KAAK,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"FilterAction.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/FilterAction.tsx"],"names":[],"mappings":"AAQA,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAG3D,aAAa;AACb,MAAM,MAAM,iBAAiB,GAAG;IAC9B,yEAAyE;IACzE,QAAQ,CAAC,EAAE,CAAC,qBAAqB,EAAE,qBAAqB,KAAK,IAAI,CAAC;IAClE;;;;;;OAMG;IACH,YAAY,EAAE,IAAI,GAAG,SAAS,CAAC;CAChC,GAAG,IAAI,CAAC,iBAAiB,EAAE,0BAA0B,CAAC,CAAC;AAExD;;;GAGG;AACH,eAAO,MAAM,YAAY;IAhBvB,yEAAyE;eAC9D,CAAC,qBAAqB,EAAE,qBAAqB,KAAK,IAAI;IACjE;;;;;;OAMG;kBACW,IAAI,GAAG,SAAS;;UAYD,yBAAyB;EAsBtD,CAAC"}
|
|
@@ -11,22 +11,16 @@ import { useLocalizationContext } from "./LocalizationContext.js";
|
|
|
11
11
|
* React component that renders a filter action for a tree item.
|
|
12
12
|
* @alpha
|
|
13
13
|
*/
|
|
14
|
-
export const FilterAction = memo(function FilterAction({ node, onFilter, getHierarchyLevelDetails }) {
|
|
14
|
+
export const FilterAction = memo(function FilterAction({ node, onFilter, getHierarchyLevelDetails, reserveSpace, }) {
|
|
15
15
|
const { localizedStrings } = useLocalizationContext();
|
|
16
16
|
const { filterHierarchyLevel, filterHierarchyLevelActiveDescription } = localizedStrings;
|
|
17
|
-
const shouldShow = () => {
|
|
18
|
-
if (!onFilter || !node.isFilterable) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
if (node.isFiltered) {
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
return undefined;
|
|
25
|
-
};
|
|
26
17
|
const handleClick = useCallback(() => {
|
|
27
18
|
const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.id);
|
|
28
19
|
hierarchyLevelDetails && onFilter?.(hierarchyLevelDetails);
|
|
29
20
|
}, [node, getHierarchyLevelDetails, onFilter]);
|
|
30
|
-
|
|
21
|
+
if (!onFilter || !node.isFilterable) {
|
|
22
|
+
return reserveSpace ? _jsx(Tree.ItemAction, { label: filterHierarchyLevel, icon: filterSvg, visible: false, disabled: true }) : undefined;
|
|
23
|
+
}
|
|
24
|
+
return (_jsx(Tree.ItemAction, { label: filterHierarchyLevel, onClick: handleClick, icon: filterSvg, visible: node.isFiltered ? true : undefined, dot: node.isFiltered ? filterHierarchyLevelActiveDescription : undefined }));
|
|
31
25
|
});
|
|
32
26
|
//# sourceMappingURL=FilterAction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FilterAction.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/FilterAction.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,SAAS,MAAM,6BAA6B,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAG7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"FilterAction.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/FilterAction.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,SAAS,MAAM,6BAA6B,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAG7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAgBlE;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,YAAY,CAAC,EACrD,IAAI,EACJ,QAAQ,EACR,wBAAwB,EACxB,YAAY,GAC4C;IACxD,MAAM,EAAE,gBAAgB,EAAE,GAAG,sBAAsB,EAAE,CAAC;IACtD,MAAM,EAAE,oBAAoB,EAAE,qCAAqC,EAAE,GAAG,gBAAgB,CAAC;IAEzF,MAAM,WAAW,GAAG,WAAW,CAAC,GAAG,EAAE;QACnC,MAAM,qBAAqB,GAAG,wBAAwB,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAClE,qBAAqB,IAAI,QAAQ,EAAE,CAAC,qBAAqB,CAAC,CAAC;IAC7D,CAAC,EAAE,CAAC,IAAI,EAAE,wBAAwB,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE/C,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;QACpC,OAAO,YAAY,CAAC,CAAC,CAAC,KAAC,IAAI,CAAC,UAAU,IAAC,KAAK,EAAE,oBAAoB,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,SAAG,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/H,CAAC;IAED,OAAO,CACL,KAAC,IAAI,CAAC,UAAU,IACd,KAAK,EAAE,oBAAoB,EAC3B,OAAO,EAAE,WAAW,EACpB,IAAI,EAAE,SAAS,EACf,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,EAC3C,GAAG,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,qCAAqC,CAAC,CAAC,CAAC,SAAS,GACxE,CACH,CAAC;AACJ,CAAC,CAAC,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 { memo, useCallback } from \"react\";\nimport filterSvg from \"@stratakit/icons/filter.svg\";\nimport { Tree } from \"@stratakit/structures\";\nimport { HierarchyLevelDetails, TreeRendererProps } from \"../Renderers.js\";\nimport { PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\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 /**\n * Indicates that space for this action button should be reserved, even when the action is not available.\n * For nodes that don't support filtering, `<FilterAction reserveSpace />` renders:\n *\n * - Blank space when the action is used as an inline action. It's recommended to set this prop to keep all action buttons of the same kind vertically aligned.\n * - Disabled menu item when the action is used as a menu action.\n */\n reserveSpace: true | undefined;\n} & Pick<TreeRendererProps, \"getHierarchyLevelDetails\">;\n\n/**\n * React component that renders a filter action for a tree item.\n * @alpha\n */\nexport const FilterAction = memo(function FilterAction({\n node,\n onFilter,\n getHierarchyLevelDetails,\n reserveSpace,\n}: FilterActionProps & { node: PresentationHierarchyNode }) {\n const { localizedStrings } = useLocalizationContext();\n const { filterHierarchyLevel, filterHierarchyLevelActiveDescription } = localizedStrings;\n\n const handleClick = useCallback(() => {\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.id);\n hierarchyLevelDetails && onFilter?.(hierarchyLevelDetails);\n }, [node, getHierarchyLevelDetails, onFilter]);\n\n if (!onFilter || !node.isFilterable) {\n return reserveSpace ? <Tree.ItemAction label={filterHierarchyLevel} icon={filterSvg} visible={false} disabled /> : undefined;\n }\n\n return (\n <Tree.ItemAction\n label={filterHierarchyLevel}\n onClick={handleClick}\n icon={filterSvg}\n visible={node.isFiltered ? true : undefined}\n dot={node.isFiltered ? filterHierarchyLevelActiveDescription : undefined}\n />\n );\n});\n"]}
|
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
import { PresentationHierarchyNode } from "../TreeNode.js";
|
|
2
2
|
/**
|
|
3
|
-
* Placeholder
|
|
3
|
+
* Placeholder item that is added to hierarchy as a child for a parent item while its child items are loading.
|
|
4
4
|
*
|
|
5
5
|
* @alpha
|
|
6
6
|
* */
|
|
7
|
-
interface
|
|
7
|
+
interface FlatPlaceholderItem {
|
|
8
8
|
id: string;
|
|
9
9
|
level: number;
|
|
10
10
|
placeholder: true;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
* An
|
|
13
|
+
* An item containing `PresentationHierarchyNode` node with properties needed for a flat tree structure.
|
|
14
14
|
*
|
|
15
15
|
* @alpha
|
|
16
16
|
*/
|
|
17
|
-
export
|
|
17
|
+
export interface FlatTreeNodeItem {
|
|
18
|
+
id: string;
|
|
18
19
|
level: number;
|
|
19
20
|
levelSize: number;
|
|
20
21
|
posInLevel: number;
|
|
21
|
-
|
|
22
|
+
node: PresentationHierarchyNode;
|
|
23
|
+
}
|
|
22
24
|
/**
|
|
23
|
-
*
|
|
25
|
+
* An item used to build an error message.
|
|
24
26
|
* Returned by `useErrorList`.
|
|
25
27
|
*
|
|
26
28
|
* @alpha
|
|
@@ -30,24 +32,24 @@ export interface ErrorItem {
|
|
|
30
32
|
expandTo: (expandNode: (nodeId: string) => void) => void;
|
|
31
33
|
}
|
|
32
34
|
/**
|
|
33
|
-
*
|
|
35
|
+
* An Item describing single tree item position and its content inside tree.
|
|
34
36
|
* Returned by `useFlatTreeNodeList` hook.
|
|
35
37
|
*
|
|
36
38
|
* @alpha
|
|
37
39
|
*/
|
|
38
|
-
export type
|
|
40
|
+
export type FlatTreeItem = FlatTreeNodeItem | FlatPlaceholderItem;
|
|
39
41
|
/** @alpha */
|
|
40
|
-
export declare function
|
|
42
|
+
export declare function isPlaceholderItem(item: FlatTreeItem): item is FlatPlaceholderItem;
|
|
41
43
|
/**
|
|
42
|
-
* Used to get a list of `
|
|
43
|
-
* a hierarchical structure. The resulting
|
|
44
|
+
* Used to get a list of `FlatTreeItem` objects for the given list of `PresentationHierarchyNode` objects that represent
|
|
45
|
+
* a hierarchical structure. The resulting items can be used to render the hierarchy in a flat manner, e.g. using a
|
|
44
46
|
* virtualized list.
|
|
45
47
|
*
|
|
46
48
|
* @alpha
|
|
47
49
|
*/
|
|
48
|
-
export declare function
|
|
50
|
+
export declare function useFlatTreeItems(rootNodes: PresentationHierarchyNode[]): FlatTreeItem[];
|
|
49
51
|
/**
|
|
50
|
-
* Finds and returns all
|
|
52
|
+
* Finds and returns all items containing errors in a given hierarchy in the form of `ErrorItem[]`.
|
|
51
53
|
*
|
|
52
54
|
* @alpha
|
|
53
55
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FlatTreeNode.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/FlatTreeNode.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAE3D;;;;KAIK;AACL,UAAU,
|
|
1
|
+
{"version":3,"file":"FlatTreeNode.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/FlatTreeNode.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAE3D;;;;KAIK;AACL,UAAU,mBAAmB;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,IAAI,CAAC;CACnB;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,yBAAyB,CAAC;CACjC;AAED;;;;;KAKK;AACL,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,yBAAyB,CAAC;IACrC,QAAQ,EAAE,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,KAAK,IAAI,CAAC;CAC1D;AAED;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,gBAAgB,GAAG,mBAAmB,CAAC;AAElE,aAAa;AACb,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,IAAI,mBAAmB,CAEjF;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,yBAAyB,EAAE,kBAEtE;AAoBD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,yBAAyB,EAAE,GAAG,SAAS,EAAE,CAchF"}
|
|
@@ -4,37 +4,37 @@
|
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import { useMemo } from "react";
|
|
6
6
|
/** @alpha */
|
|
7
|
-
export function
|
|
8
|
-
return "placeholder" in
|
|
7
|
+
export function isPlaceholderItem(item) {
|
|
8
|
+
return "placeholder" in item;
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
|
-
* Used to get a list of `
|
|
12
|
-
* a hierarchical structure. The resulting
|
|
11
|
+
* Used to get a list of `FlatTreeItem` objects for the given list of `PresentationHierarchyNode` objects that represent
|
|
12
|
+
* a hierarchical structure. The resulting items can be used to render the hierarchy in a flat manner, e.g. using a
|
|
13
13
|
* virtualized list.
|
|
14
14
|
*
|
|
15
15
|
* @alpha
|
|
16
16
|
*/
|
|
17
|
-
export function
|
|
18
|
-
return useMemo(() =>
|
|
17
|
+
export function useFlatTreeItems(rootNodes) {
|
|
18
|
+
return useMemo(() => getFlatItems(rootNodes, 1), [rootNodes]);
|
|
19
19
|
}
|
|
20
|
-
function
|
|
21
|
-
const
|
|
20
|
+
function getFlatItems(nodes, level) {
|
|
21
|
+
const flatItems = [];
|
|
22
22
|
nodes.forEach((node, index) => {
|
|
23
|
-
|
|
23
|
+
flatItems.push({ node, id: node.id, level, levelSize: nodes.length, posInLevel: index + 1 });
|
|
24
24
|
if (!node.isExpanded || node.error) {
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
27
|
if (node.children !== true) {
|
|
28
|
-
const childNodes =
|
|
29
|
-
|
|
28
|
+
const childNodes = getFlatItems(node.children, level + 1);
|
|
29
|
+
flatItems.push(...childNodes);
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
|
-
|
|
32
|
+
flatItems.push({ id: `${node.id}-children-placeholder`, level: level + 1, placeholder: true });
|
|
33
33
|
});
|
|
34
|
-
return
|
|
34
|
+
return flatItems;
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
|
-
* Finds and returns all
|
|
37
|
+
* Finds and returns all items containing errors in a given hierarchy in the form of `ErrorItem[]`.
|
|
38
38
|
*
|
|
39
39
|
* @alpha
|
|
40
40
|
*/
|
|
@@ -46,10 +46,10 @@ export function useErrorList(rootNodes) {
|
|
|
46
46
|
if (rootNode.children === true) {
|
|
47
47
|
return [];
|
|
48
48
|
}
|
|
49
|
-
return
|
|
49
|
+
return getErrorItems(rootNode, !rootNode.isExpanded ? [rootNode.id] : []);
|
|
50
50
|
}), [rootNodes]);
|
|
51
51
|
}
|
|
52
|
-
function
|
|
52
|
+
function getErrorItems(parent, path) {
|
|
53
53
|
const errorList = [];
|
|
54
54
|
if (parent.children === true) {
|
|
55
55
|
return [];
|
|
@@ -61,7 +61,7 @@ function getErrorNodes(parent, path) {
|
|
|
61
61
|
return;
|
|
62
62
|
}
|
|
63
63
|
if (node.children !== true) {
|
|
64
|
-
const childErrorList =
|
|
64
|
+
const childErrorList = getErrorItems(node, pathToChild);
|
|
65
65
|
errorList.push(...childErrorList);
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FlatTreeNode.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/FlatTreeNode.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"FlatTreeNode.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/FlatTreeNode.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AA8ChC,aAAa;AACb,MAAM,UAAU,iBAAiB,CAAC,IAAkB;IAClD,OAAO,aAAa,IAAI,IAAI,CAAC;AAC/B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAAsC;IACrE,OAAO,OAAO,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,SAAS,EAAE,CAAC,CAAC,EAAE,CAA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AC;AACnB,CAAC;AAED,SAAS,QAAQ,CAAC,UAAoC,EAAE,IAAc;IACpE,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;AAC/C,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 { useMemo } from \"react\";\nimport { PresentationHierarchyNode } from \"../TreeNode.js\";\n\n/**\n * Placeholder item that is added to hierarchy as a child for a parent item while its child items are loading.\n *\n * @alpha\n * */\ninterface FlatPlaceholderItem {\n id: string;\n level: number;\n placeholder: true;\n}\n\n/**\n * An item containing `PresentationHierarchyNode` node with properties needed for a flat tree structure.\n *\n * @alpha\n */\nexport interface FlatTreeNodeItem {\n id: string;\n level: number;\n levelSize: number;\n posInLevel: number;\n node: PresentationHierarchyNode;\n}\n\n/**\n * An item used to build an error message.\n * Returned by `useErrorList`.\n *\n * @alpha\n * */\nexport interface ErrorItem {\n errorNode: PresentationHierarchyNode;\n expandTo: (expandNode: (nodeId: string) => void) => void;\n}\n\n/**\n * An Item describing single tree item position and its content inside tree.\n * Returned by `useFlatTreeNodeList` hook.\n *\n * @alpha\n */\nexport type FlatTreeItem = FlatTreeNodeItem | FlatPlaceholderItem;\n\n/** @alpha */\nexport function isPlaceholderItem(item: FlatTreeItem): item is FlatPlaceholderItem {\n return \"placeholder\" in item;\n}\n\n/**\n * Used to get a list of `FlatTreeItem` objects for the given list of `PresentationHierarchyNode` objects that represent\n * a hierarchical structure. The resulting items can be used to render the hierarchy in a flat manner, e.g. using a\n * virtualized list.\n *\n * @alpha\n */\nexport function useFlatTreeItems(rootNodes: PresentationHierarchyNode[]) {\n return useMemo(() => getFlatItems(rootNodes, 1), [rootNodes]);\n}\n\nfunction getFlatItems(nodes: PresentationHierarchyNode[], level: number) {\n const flatItems: FlatTreeItem[] = [];\n nodes.forEach((node, index) => {\n flatItems.push({ node, id: node.id, level, levelSize: nodes.length, posInLevel: index + 1 });\n if (!node.isExpanded || node.error) {\n return;\n }\n if (node.children !== true) {\n const childNodes = getFlatItems(node.children, level + 1);\n flatItems.push(...childNodes);\n return;\n }\n\n flatItems.push({ id: `${node.id}-children-placeholder`, level: level + 1, placeholder: true } satisfies FlatPlaceholderItem);\n });\n return flatItems;\n}\n\n/**\n * Finds and returns all items containing errors in a given hierarchy in the form of `ErrorItem[]`.\n *\n * @alpha\n */\nexport function useErrorList(rootNodes: PresentationHierarchyNode[]): ErrorItem[] {\n return useMemo(\n () =>\n rootNodes.flatMap((rootNode) => {\n if (!!rootNode.error) {\n return [{ errorNode: rootNode, expandTo: (expandNode) => expandTo(expandNode, []) }];\n }\n if (rootNode.children === true) {\n return [];\n }\n return getErrorItems(rootNode, !rootNode.isExpanded ? [rootNode.id] : []);\n }),\n [rootNodes],\n );\n}\n\nfunction getErrorItems(parent: PresentationHierarchyNode, path: string[]) {\n const errorList: ErrorItem[] = [];\n\n if (parent.children === true) {\n return [];\n }\n\n const pathToChild = [...path, ...(!parent.isExpanded ? [parent.id] : [])];\n parent.children.forEach((node) => {\n if (!!node.error) {\n errorList.push({ errorNode: node, expandTo: (expandNode) => expandTo(expandNode, path) });\n return;\n }\n\n if (node.children !== true) {\n const childErrorList = getErrorItems(node, pathToChild);\n errorList.push(...childErrorList);\n return;\n }\n });\n return errorList;\n}\n\nfunction expandTo(expandNode: (nodeId: string) => void, path: string[]) {\n path.forEach((nodeId) => expandNode(nodeId));\n}\n"]}
|
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
import { PropsWithChildren } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* @alpha
|
|
4
|
+
*/
|
|
5
|
+
interface RenameActionProps {
|
|
6
|
+
/**
|
|
7
|
+
* Indicates that space for this action button should be reserved, even when the action is not available.
|
|
8
|
+
* For nodes that don't support renaming, `<RenameAction reserveSpace />` renders:
|
|
9
|
+
*
|
|
10
|
+
* - Blank space when the action is used as an inline action. It's recommended to set this prop to keep all action buttons of the same kind vertically aligned.
|
|
11
|
+
* - Disabled menu item when the action is used as a menu action.
|
|
12
|
+
*/
|
|
13
|
+
reserveSpace: true | undefined;
|
|
14
|
+
}
|
|
2
15
|
/**
|
|
3
16
|
* React component that renders a rename action for a tree item.
|
|
4
17
|
* @alpha
|
|
5
18
|
*/
|
|
6
|
-
export declare const RenameAction: import("react").NamedExoticComponent<
|
|
19
|
+
export declare const RenameAction: import("react").NamedExoticComponent<RenameActionProps>;
|
|
7
20
|
interface RenameContext {
|
|
8
21
|
isRenaming: boolean;
|
|
9
22
|
setIsRenaming: (isRenaming: boolean) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RenameAction.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/RenameAction.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAuB,iBAAiB,EAA8C,MAAM,OAAO,CAAC;AAK3G;;;GAGG;AACH,eAAO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"RenameAction.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/RenameAction.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAuB,iBAAiB,EAA8C,MAAM,OAAO,CAAC;AAK3G;;GAEG;AACH,UAAU,iBAAiB;IACzB;;;;;;OAMG;IACH,YAAY,EAAE,IAAI,GAAG,SAAS,CAAC;CAChC;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,yDAevB,CAAC;AAEH,UAAU,aAAa;IACrB,UAAU,EAAE,OAAO,CAAC;IACpB,aAAa,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,IAAI,CAAC;IAC7C,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7C;AAID,gBAAgB;AAChB,eAAO,MAAM,gBAAgB,iCAE5B,CAAC;AAEF,aAAa;AACb,wBAAgB,qBAAqB,CAAC,EAAE,cAAc,EAAE,QAAQ,EAAE,EAAE,iBAAiB,CAAC;IAAE,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,CAAC,2CAKrI"}
|
|
@@ -11,7 +11,7 @@ import { useLocalizationContext } from "./LocalizationContext.js";
|
|
|
11
11
|
* React component that renders a rename action for a tree item.
|
|
12
12
|
* @alpha
|
|
13
13
|
*/
|
|
14
|
-
export const RenameAction = memo(function RenameAction() {
|
|
14
|
+
export const RenameAction = memo(function RenameAction({ reserveSpace }) {
|
|
15
15
|
const { localizedStrings } = useLocalizationContext();
|
|
16
16
|
const context = useRenameContext();
|
|
17
17
|
const { rename } = localizedStrings;
|
|
@@ -20,7 +20,7 @@ export const RenameAction = memo(function RenameAction() {
|
|
|
20
20
|
setIsRenaming?.(true);
|
|
21
21
|
}, [setIsRenaming]);
|
|
22
22
|
if (!context?.onLabelChanged) {
|
|
23
|
-
return undefined;
|
|
23
|
+
return reserveSpace ? _jsx(Tree.ItemAction, { label: rename, icon: renameSvg, visible: false, disabled: true }) : undefined;
|
|
24
24
|
}
|
|
25
25
|
return _jsx(Tree.ItemAction, { label: rename, onClick: handleClick, icon: renameSvg });
|
|
26
26
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RenameAction.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/RenameAction.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,aAAa,EAAE,IAAI,EAAqB,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC3G,OAAO,SAAS,MAAM,6BAA6B,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"RenameAction.js","sourceRoot":"","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B;AAChB,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,EAAE;IACnC,OAAO,UAAU,CAAC,aAAa,CAAC,CAAC;AACnC,CAAC,CAAC;AAEF,aAAa;AACb,MAAM,UAAU,qBAAqB,CAAC,EAAE,cAAc,EAAE,QAAQ,EAAsE;IACpI,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IACpD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,aAAa,EAAE,cAAc,EAAE,CAAC,EAAE,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC;IAE3G,OAAO,KAAC,aAAa,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAA0B,CAAC;AACnF,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, memo, PropsWithChildren, useCallback, useContext, useMemo, useState } from \"react\";\nimport renameSvg from \"@stratakit/icons/rename.svg\";\nimport { Tree } from \"@stratakit/structures\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\n\n/**\n * @alpha\n */\ninterface RenameActionProps {\n /**\n * Indicates that space for this action button should be reserved, even when the action is not available.\n * For nodes that don't support renaming, `<RenameAction reserveSpace />` renders:\n *\n * - Blank space when the action is used as an inline action. It's recommended to set this prop to keep all action buttons of the same kind vertically aligned.\n * - Disabled menu item when the action is used as a menu action.\n */\n reserveSpace: true | undefined;\n}\n\n/**\n * React component that renders a rename action for a tree item.\n * @alpha\n */\nexport const RenameAction = memo(function RenameAction({ reserveSpace }: RenameActionProps) {\n const { localizedStrings } = useLocalizationContext();\n const context = useRenameContext();\n const { rename } = localizedStrings;\n\n const setIsRenaming = context?.setIsRenaming;\n const handleClick = useCallback(() => {\n setIsRenaming?.(true);\n }, [setIsRenaming]);\n\n if (!context?.onLabelChanged) {\n return reserveSpace ? <Tree.ItemAction label={rename} icon={renameSvg} visible={false} disabled /> : undefined;\n }\n\n return <Tree.ItemAction label={rename} onClick={handleClick} icon={renameSvg} />;\n});\n\ninterface RenameContext {\n isRenaming: boolean;\n setIsRenaming: (isRenaming: boolean) => void;\n onLabelChanged?: (newLabel: string) => void;\n}\n\nconst renameContext = createContext<RenameContext | undefined>(undefined);\n\n/** @internal */\nexport const useRenameContext = () => {\n return useContext(renameContext);\n};\n\n/** @alpha */\nexport function RenameContextProvider({ onLabelChanged, children }: PropsWithChildren<{ onLabelChanged?: (newLabel: string) => void }>) {\n const [isRenaming, setIsRenaming] = useState(false);\n const value = useMemo(() => ({ isRenaming, setIsRenaming, onLabelChanged }), [isRenaming, onLabelChanged]);\n\n return <renameContext.Provider value={value}>{children}</renameContext.Provider>;\n}\n"]}
|
|
@@ -22,9 +22,16 @@ export interface TreeNodeRendererOwnProps {
|
|
|
22
22
|
*/
|
|
23
23
|
getDecorations?: (node: PresentationHierarchyNode) => ReactNode;
|
|
24
24
|
/**
|
|
25
|
-
* Callback that returns actions for tree item.
|
|
25
|
+
* Callback that returns menu actions for tree item.
|
|
26
|
+
* Must return an array of `Tree.ItemAction` elements.
|
|
26
27
|
*/
|
|
27
|
-
|
|
28
|
+
getMenuActions?: (node: PresentationHierarchyNode) => ReactNode[];
|
|
29
|
+
/**
|
|
30
|
+
* Callback that returns inline actions for tree item.
|
|
31
|
+
* Must return an array of `Tree.ItemAction` elements.
|
|
32
|
+
* Max 2 items.
|
|
33
|
+
*/
|
|
34
|
+
getInlineActions?: (node: PresentationHierarchyNode) => ReactNode[];
|
|
28
35
|
}
|
|
29
36
|
/** @alpha */
|
|
30
37
|
type TreeNodeRendererProps = Pick<TreeRendererProps, "expandNode" | "reloadTree"> & Omit<TreeNodeProps, "actions" | "label" | "expanded" | "unstable_decorations" | "error"> & TreeNodeRendererOwnProps;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeNodeRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/TreeNodeRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,EACL,wBAAwB,EACxB,EAAE,EAKF,YAAY,EACZ,YAAY,EACZ,SAAS,EAET,aAAa,EAMd,MAAM,OAAO,CAAC;AAGf,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAI3D,aAAa;AACb,KAAK,aAAa,GAAG,wBAAwB,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC;AAEhE,aAAa;AACb,MAAM,WAAW,wBAAwB;IACvC,6BAA6B;IAC7B,IAAI,EAAE,yBAAyB,CAAC;IAChC,wCAAwC;IACxC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,yBAAyB,KAAK,YAAY,GAAG,SAAS,CAAC;IACzE,yCAAyC;IACzC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,yBAAyB,KAAK,YAAY,GAAG,SAAS,CAAC;IAC5E,kDAAkD;IAClD,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,yBAAyB,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;IACnH,2EAA2E;IAC3E,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,yBAAyB,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"TreeNodeRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/TreeNodeRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,EACL,wBAAwB,EACx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AI,CAAC,iBAAiB,EAAE,YAAY,GAAG,YAAY,CAAC,GAC/E,IAAI,CAAC,aAAa,EAAE,SAAS,GAAG,OAAO,GAAG,UAAU,GAAG,sBAAsB,GAAG,OAAO,CAAC,GACxF,wBAAwB,CAAC;AAE3B;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,EAAE,EAAE,CAAC,YAAY,CAAC,qBAAqB,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC,CAgH1G,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,aAAa,EAAE,YAAY,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,CAAC,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC,CAKrJ,CAAC"}
|
|
@@ -17,7 +17,7 @@ import { useRenameContext } from "./RenameAction.js";
|
|
|
17
17
|
* @see https://itwinui.bentley.com/docs/tree
|
|
18
18
|
* @public
|
|
19
19
|
*/
|
|
20
|
-
export const StrataKitTreeNodeRenderer = memo(forwardRef(function HierarchyNode({ node, selected, expandNode, onNodeClick, onNodeKeyDown, reloadTree, getLabel, getSublabel,
|
|
20
|
+
export const StrataKitTreeNodeRenderer = memo(forwardRef(function HierarchyNode({ node, selected, expandNode, onNodeClick, onNodeKeyDown, reloadTree, getLabel, getSublabel, getMenuActions, getInlineActions, getDecorations, ...treeItemProps }, forwardedRef) {
|
|
21
21
|
const nodeRef = useRef(null);
|
|
22
22
|
const ref = useMergedRefs(forwardedRef, nodeRef);
|
|
23
23
|
const { localizedStrings } = useLocalizationContext();
|
|
@@ -25,14 +25,17 @@ export const StrataKitTreeNodeRenderer = memo(forwardRef(function HierarchyNode(
|
|
|
25
25
|
const label = useMemo(() => (getLabel ? getLabel(node) : node.label), [getLabel, node]);
|
|
26
26
|
const description = useMemo(() => (getSublabel ? getSublabel(node) : undefined), [getSublabel, node]);
|
|
27
27
|
const decorations = useMemo(() => getDecorations?.(node), [getDecorations, node]);
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
const inlineActions = useMemo(() => {
|
|
29
|
+
if (node.error !== undefined && node.error.type === "Unknown") {
|
|
30
|
+
return [
|
|
31
31
|
_jsx(Tree.ItemAction, { label: localizedStrings.retry, onClick: () => reloadTree({ parentNodeId: node.id, state: "reset" }), visible: true, icon: refreshSvg }, "retry"),
|
|
32
|
-
]
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
if (!getInlineActions) {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
return getInlineActions(node);
|
|
38
|
+
}, [node, getInlineActions, localizedStrings.retry, reloadTree]);
|
|
36
39
|
const expanded = useMemo(() => {
|
|
37
40
|
if (node.error) {
|
|
38
41
|
return undefined;
|
|
@@ -62,7 +65,7 @@ export const StrataKitTreeNodeRenderer = memo(forwardRef(function HierarchyNode(
|
|
|
62
65
|
if (!isDisabled && event.target === nodeRef.current) {
|
|
63
66
|
onNodeKeyDown?.(node, !selected, event);
|
|
64
67
|
}
|
|
65
|
-
}, [onNodeKeyDown, selected, isDisabled, node]), actions:
|
|
68
|
+
}, [onNodeKeyDown, selected, isDisabled, node]), inlineActions: inlineActions, actions: useMemo(() => (node.error === undefined && getMenuActions ? getMenuActions(node) : []), [getMenuActions, node]), unstable_decorations: decorations, error: node.error ? node.error.id : undefined }));
|
|
66
69
|
}));
|
|
67
70
|
export const PlaceholderNode = memo(forwardRef(function PlaceholderNode({ ...props }, forwardedRef) {
|
|
68
71
|
const { localizedStrings } = useLocalizationContext();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeNodeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/TreeNodeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAGL,UAAU,EAEV,IAAI,EAOJ,WAAW,EACX,SAAS,EACT,OAAO,EACP,MA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C;IACb,CAAC,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC;YACrB,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YACzB,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;QAC5B,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CACL,KAAC,OAAO,CAAC,IAAI,cACX,KAAC,OAAO,CAAC,KAAK,IACZ,GAAG,EAAE,QAAQ,EACb,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,gBAAgB,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EACzD,MAAM,EAAE,iBAAiB,EACzB,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE;gBACnB,IAAI,KAAK,CAAC,GAAG,KAAK,OAAO,EAAE,CAAC;oBAC1B,iBAAiB,EAAE,CAAC;gBACtB,CAAC;qBAAM,IAAI,KAAK,CAAC,GAAG,KAAK,QAAQ,EAAE,CAAC;oBAClC,iBAAiB,EAAE,CAAC;gBACtB,CAAC;YACH,CAAC,GACD,GACW,CAChB,CAAC;AACJ,CAAC;AAED,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 FC,\n forwardRef,\n LegacyRef,\n memo,\n MutableRefObject,\n PropsWithRef,\n ReactElement,\n ReactNode,\n Ref,\n RefAttributes,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { Spinner, TextBox } from \"@stratakit/bricks\";\nimport refreshSvg from \"@stratakit/icons/refresh.svg\";\nimport { Tree } from \"@stratakit/structures\";\nimport { TreeRendererProps } from \"../Renderers.js\";\nimport { PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\nimport { useRenameContext } from \"./RenameAction.js\";\n\n/** @alpha */\ntype TreeNodeProps = ComponentPropsWithoutRef<typeof Tree.Item>;\n\n/** @alpha */\nexport interface TreeNodeRendererOwnProps {\n /** Node that is rendered. */\n node: PresentationHierarchyNode;\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>) => 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 /**\n * Used to render elements between expander and label.\n * E.g. icons, color picker, etc.\n */\n getDecorations?: (node: PresentationHierarchyNode) => ReactNode;\n /**\n * Callback that returns actions for tree item. Must return an array of `Tree.ItemAction` elements.\n */\n getActions?: (node: PresentationHierarchyNode) => ReactNode[];\n}\n\n/** @alpha */\ntype TreeNodeRendererProps = Pick<TreeRendererProps, \"expandNode\" | \"reloadTree\"> &\n Omit<TreeNodeProps, \"actions\" | \"label\" | \"expanded\" | \"unstable_decorations\" | \"error\"> &\n TreeNodeRendererOwnProps;\n\n/**\n * A component that renders given `FlatTreeNode` using the `Tree.Item` component from `@itwin/itwinui-react`. The\n * `FlatTreeNode` objects for this renderer are generally created using the `useFlatTreeNodeList` hook.\n *\n * @see `TreeRenderer`\n * @see https://itwinui.bentley.com/docs/tree\n * @public\n */\nexport const StrataKitTreeNodeRenderer: FC<PropsWithRef<TreeNodeRendererProps & RefAttributes<HTMLElement>>> = memo(\n forwardRef<HTMLElement, TreeNodeRendererProps>(function HierarchyNode(\n { node, selected, expandNode, onNodeClick, onNodeKeyDown, reloadTree, getLabel, getSublabel, getActions, getDecorations, ...treeItemProps },\n forwardedRef,\n ) {\n const nodeRef = useRef<HTMLElement>(null);\n const ref = useMergedRefs(forwardedRef, nodeRef);\n const { localizedStrings } = useLocalizationContext();\n const renameContext = useRenameContext();\n\n const label = useMemo(() => (getLabel ? getLabel(node) : node.label), [getLabel, node]);\n const description = useMemo(() => (getSublabel ? getSublabel(node) : undefined), [getSublabel, node]);\n const decorations = useMemo(() => getDecorations?.(node), [getDecorations, node]);\n const actions = useMemo(\n () => [\n ...(node.error?.type === \"Unknown\"\n ? [\n <Tree.ItemAction\n key=\"retry\"\n label={localizedStrings.retry}\n onClick={() => reloadTree({ parentNodeId: node.id, state: \"reset\" })}\n visible={true}\n icon={refreshSvg}\n />,\n ]\n : []),\n ...(getActions ? getActions(node) : []),\n ],\n [getActions, node, localizedStrings, reloadTree],\n );\n\n const expanded = useMemo(() => {\n if (node.error) {\n return undefined;\n }\n\n if (node.isExpanded || node.children === true || node.children.length > 0) {\n return node.isExpanded;\n }\n\n return undefined;\n }, [node.children, node.error, node.isExpanded]);\n\n const isDisabled = treeItemProps[\"aria-disabled\"] === true;\n\n const { onLabelChanged, setIsRenaming, isRenaming } = renameContext ?? {};\n const labelEditor = isRenaming ? (\n <LabelEditor\n initialLabel={node.label}\n onChange={(newLabel) => {\n onLabelChanged?.(newLabel);\n setIsRenaming?.(false);\n }}\n onCancel={() => {\n setIsRenaming?.(false);\n }}\n />\n ) : undefined;\n\n return (\n <Tree.Item\n {...treeItemProps}\n ref={ref}\n label={labelEditor ?? label}\n description={description}\n selected={selected}\n expanded={expanded}\n onExpandedChange={useCallback(\n (isExpanded: boolean) => {\n expandNode(node.id, isExpanded);\n },\n [node, expandNode],\n )}\n onClick={useCallback<Required<TreeNodeProps>[\"onClick\"]>(\n (event) => {\n if (isDisabled) {\n return;\n }\n\n onNodeClick?.(node, !selected, event);\n },\n [node, isDisabled, selected, onNodeClick],\n )}\n onKeyDown={useCallback<Required<TreeNodeProps>[\"onKeyDown\"]>(\n (event) => {\n // Ignore if it is called on the element inside, e.g. checkbox or expander\n if (!isDisabled && event.target === nodeRef.current) {\n onNodeKeyDown?.(node, !selected, event);\n }\n },\n [onNodeKeyDown, selected, isDisabled, node],\n )}\n actions={actions}\n unstable_decorations={decorations}\n error={node.error ? node.error.id : undefined}\n />\n );\n }),\n);\n\nexport const PlaceholderNode: FC<PropsWithRef<Omit<TreeNodeProps, \"onExpanded\" | \"label\" | \"actions\" | \"icon\" | \"error\"> & RefAttributes<HTMLElement>>> = memo(\n forwardRef<HTMLElement, Omit<TreeNodeProps, \"onExpanded\" | \"label\" | \"actions\" | \"icon\" | \"error\">>(function PlaceholderNode({ ...props }, forwardedRef) {\n const { localizedStrings } = useLocalizationContext();\n return <Tree.Item {...props} ref={forwardedRef} label={localizedStrings.loading} icon={<Spinner size={\"small\"} title={localizedStrings.loading} />} />;\n }),\n);\n\nfunction LabelEditor({ initialLabel, onChange, onCancel }: { initialLabel: string; onChange: (newLabel: string) => void; onCancel: () => void }) {\n const inputRef = useRef<HTMLInputElement>(null);\n const [newLabelValue, setNewLabelValue] = useState(initialLabel);\n const handleLabelChange = () => {\n if (initialLabel !== newLabelValue) {\n onChange(newLabelValue);\n return;\n }\n onCancel();\n };\n\n const cancelLabelChange = () => {\n setNewLabelValue(initialLabel);\n onCancel();\n };\n\n useEffect(() => {\n if (inputRef.current) {\n inputRef.current.focus();\n inputRef.current.select();\n }\n }, []);\n\n return (\n <TextBox.Root>\n <TextBox.Input\n ref={inputRef}\n value={newLabelValue}\n onChange={(event) => setNewLabelValue(event.target.value)}\n onBlur={handleLabelChange}\n onKeyDown={(event) => {\n if (event.key === \"Enter\") {\n handleLabelChange();\n } else if (event.key === \"Escape\") {\n cancelLabelChange();\n }\n }}\n />\n </TextBox.Root>\n );\n}\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/stratakit/TreeNodeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAGL,UAAU,EAEV,IAAI,EAOJ,WAAW,EACX,SAAS,EACT,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,UAAU,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAG7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAwCrD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAyE,IAAI,CACjH,UAAU,CAAqC,SAAS,aAAa,CACnE,EACE,IAAI,EACJ,QAAQ,EACR,UAAU,EACV,WAAW,EACX,aAAa,EACb,UAAU,EACV,QAAQ,EACR,WAAW,EACX,cAAc,EACd,gBAAgB,E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IAEP,OAAO,CACL,KAAC,OAAO,CAAC,IAAI,cACX,KAAC,OAAO,CAAC,KAAK,IACZ,GAAG,EAAE,QAAQ,EACb,KAAK,EAAE,aAAa,EACpB,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,gBAAgB,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EACzD,MAAM,EAAE,iBAAiB,EACzB,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE;gBACnB,IAAI,KAAK,CAAC,GAAG,KAAK,OAAO,EAAE,CAAC;oBAC1B,iBAAiB,EAAE,CAAC;gBACtB,CAAC;qBAAM,IAAI,KAAK,CAAC,GAAG,KAAK,QAAQ,EAAE,CAAC;oBAClC,iBAAiB,EAAE,CAAC;gBACtB,CAAC;YACH,CAAC,GACD,GACW,CAChB,CAAC;AACJ,CAAC;AAED,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 FC,\n forwardRef,\n LegacyRef,\n memo,\n MutableRefObject,\n PropsWithRef,\n ReactElement,\n ReactNode,\n Ref,\n RefAttributes,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { Spinner, TextBox } from \"@stratakit/bricks\";\nimport refreshSvg from \"@stratakit/icons/refresh.svg\";\nimport { Tree } from \"@stratakit/structures\";\nimport { TreeRendererProps } from \"../Renderers.js\";\nimport { PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\nimport { useRenameContext } from \"./RenameAction.js\";\n\n/** @alpha */\ntype TreeNodeProps = ComponentPropsWithoutRef<typeof Tree.Item>;\n\n/** @alpha */\nexport interface TreeNodeRendererOwnProps {\n /** Node that is rendered. */\n node: PresentationHierarchyNode;\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>) => 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 * Used to render elements between expander and label.\n * E.g. icons, color picker, etc.\n */\n getDecorations?: (node: PresentationHierarchyNode) => ReactNode;\n /**\n * Callback that returns menu actions for tree item.\n * Must return an array of `Tree.ItemAction` elements.\n */\n getMenuActions?: (node: PresentationHierarchyNode) => ReactNode[];\n /**\n * Callback that returns inline actions for tree item.\n * Must return an array of `Tree.ItemAction` elements.\n * Max 2 items.\n */\n getInlineActions?: (node: PresentationHierarchyNode) => ReactNode[];\n}\n\n/** @alpha */\ntype TreeNodeRendererProps = Pick<TreeRendererProps, \"expandNode\" | \"reloadTree\"> &\n Omit<TreeNodeProps, \"actions\" | \"label\" | \"expanded\" | \"unstable_decorations\" | \"error\"> &\n TreeNodeRendererOwnProps;\n\n/**\n * A component that renders given `FlatTreeNode` using the `Tree.Item` component from `@itwin/itwinui-react`. The\n * `FlatTreeNode` objects for this renderer are generally created using the `useFlatTreeNodeList` hook.\n *\n * @see `TreeRenderer`\n * @see https://itwinui.bentley.com/docs/tree\n * @public\n */\nexport const StrataKitTreeNodeRenderer: FC<PropsWithRef<TreeNodeRendererProps & RefAttributes<HTMLElement>>> = memo(\n forwardRef<HTMLElement, TreeNodeRendererProps>(function HierarchyNode(\n {\n node,\n selected,\n expandNode,\n onNodeClick,\n onNodeKeyDown,\n reloadTree,\n getLabel,\n getSublabel,\n getMenuActions,\n getInlineActions,\n getDecorations,\n ...treeItemProps\n },\n forwardedRef,\n ) {\n const nodeRef = useRef<HTMLElement>(null);\n const ref = useMergedRefs(forwardedRef, nodeRef);\n const { localizedStrings } = useLocalizationContext();\n const renameContext = useRenameContext();\n\n const label = useMemo(() => (getLabel ? getLabel(node) : node.label), [getLabel, node]);\n const description = useMemo(() => (getSublabel ? getSublabel(node) : undefined), [getSublabel, node]);\n const decorations = useMemo(() => getDecorations?.(node), [getDecorations, node]);\n const inlineActions = useMemo(() => {\n if (node.error !== undefined && node.error.type === \"Unknown\") {\n return [\n <Tree.ItemAction\n key=\"retry\"\n label={localizedStrings.retry}\n onClick={() => reloadTree({ parentNodeId: node.id, state: \"reset\" })}\n visible={true}\n icon={refreshSvg}\n />,\n ];\n }\n if (!getInlineActions) {\n return [];\n }\n return getInlineActions(node);\n }, [node, getInlineActions, localizedStrings.retry, reloadTree]);\n\n const expanded = useMemo(() => {\n if (node.error) {\n return undefined;\n }\n\n if (node.isExpanded || node.children === true || node.children.length > 0) {\n return node.isExpanded;\n }\n\n return undefined;\n }, [node.children, node.error, node.isExpanded]);\n\n const isDisabled = treeItemProps[\"aria-disabled\"] === true;\n\n const { onLabelChanged, setIsRenaming, isRenaming } = renameContext ?? {};\n const labelEditor = isRenaming ? (\n <LabelEditor\n initialLabel={node.label}\n onChange={(newLabel) => {\n onLabelChanged?.(newLabel);\n setIsRenaming?.(false);\n }}\n onCancel={() => {\n setIsRenaming?.(false);\n }}\n />\n ) : undefined;\n\n return (\n <Tree.Item\n {...treeItemProps}\n ref={ref}\n label={labelEditor ?? label}\n description={description}\n selected={selected}\n expanded={expanded}\n onExpandedChange={useCallback(\n (isExpanded: boolean) => {\n expandNode(node.id, isExpanded);\n },\n [node, expandNode],\n )}\n onClick={useCallback<Required<TreeNodeProps>[\"onClick\"]>(\n (event) => {\n if (isDisabled) {\n return;\n }\n\n onNodeClick?.(node, !selected, event);\n },\n [node, isDisabled, selected, onNodeClick],\n )}\n onKeyDown={useCallback<Required<TreeNodeProps>[\"onKeyDown\"]>(\n (event) => {\n // Ignore if it is called on the element inside, e.g. checkbox or expander\n if (!isDisabled && event.target === nodeRef.current) {\n onNodeKeyDown?.(node, !selected, event);\n }\n },\n [onNodeKeyDown, selected, isDisabled, node],\n )}\n inlineActions={inlineActions}\n actions={useMemo(() => (node.error === undefined && getMenuActions ? getMenuActions(node) : []), [getMenuActions, node])}\n unstable_decorations={decorations}\n error={node.error ? node.error.id : undefined}\n />\n );\n }),\n);\n\nexport const PlaceholderNode: FC<PropsWithRef<Omit<TreeNodeProps, \"onExpanded\" | \"label\" | \"actions\" | \"icon\" | \"error\"> & RefAttributes<HTMLElement>>> = memo(\n forwardRef<HTMLElement, Omit<TreeNodeProps, \"onExpanded\" | \"label\" | \"actions\" | \"icon\" | \"error\">>(function PlaceholderNode({ ...props }, forwardedRef) {\n const { localizedStrings } = useLocalizationContext();\n return <Tree.Item {...props} ref={forwardedRef} label={localizedStrings.loading} icon={<Spinner size={\"small\"} title={localizedStrings.loading} />} />;\n }),\n);\n\nfunction LabelEditor({ initialLabel, onChange, onCancel }: { initialLabel: string; onChange: (newLabel: string) => void; onCancel: () => void }) {\n const inputRef = useRef<HTMLInputElement>(null);\n const [newLabelValue, setNewLabelValue] = useState(initialLabel);\n const handleLabelChange = () => {\n if (initialLabel !== newLabelValue) {\n onChange(newLabelValue);\n return;\n }\n onCancel();\n };\n\n const cancelLabelChange = () => {\n setNewLabelValue(initialLabel);\n onCancel();\n };\n\n useEffect(() => {\n if (inputRef.current) {\n inputRef.current.focus();\n inputRef.current.select();\n }\n }, []);\n\n return (\n <TextBox.Root>\n <TextBox.Input\n ref={inputRef}\n value={newLabelValue}\n onChange={(event) => setNewLabelValue(event.target.value)}\n onBlur={handleLabelChange}\n onKeyDown={(event) => {\n if (event.key === \"Enter\") {\n handleLabelChange();\n } else if (event.key === \"Escape\") {\n cancelLabelChange();\n }\n }}\n />\n </TextBox.Root>\n );\n}\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"]}
|
|
@@ -9,7 +9,7 @@ import { Tree } from "@stratakit/structures";
|
|
|
9
9
|
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
10
10
|
import { useSelectionHandler } from "../UseSelectionHandler.js";
|
|
11
11
|
import { useEvent } from "../Utils.js";
|
|
12
|
-
import {
|
|
12
|
+
import { isPlaceholderItem, useErrorList, useFlatTreeItems } from "./FlatTreeNode.js";
|
|
13
13
|
import { LocalizationContextProvider } from "./LocalizationContext.js";
|
|
14
14
|
import { RenameContextProvider } from "./RenameAction.js";
|
|
15
15
|
import { TreeErrorRenderer } from "./TreeErrorRenderer.js";
|
|
@@ -29,38 +29,38 @@ export function StrataKitTreeRenderer({ rootNodes, selectNodes, selectionMode, e
|
|
|
29
29
|
});
|
|
30
30
|
const handleNodeClick = useEvent(onNodeClickOverride ?? onNodeClick);
|
|
31
31
|
const handleKeyDown = useEvent(onNodeKeyDownOverride ?? onNodeKeyDown);
|
|
32
|
-
const
|
|
32
|
+
const flatItems = useFlatTreeItems(rootNodes);
|
|
33
33
|
const errorList = useErrorList(rootNodes);
|
|
34
34
|
const scrollToNode = useRef(undefined);
|
|
35
35
|
const parentRef = useRef(null);
|
|
36
36
|
const virtualizer = useVirtualizer({
|
|
37
|
-
count:
|
|
37
|
+
count: flatItems.length,
|
|
38
38
|
getScrollElement: () => parentRef.current,
|
|
39
|
-
getItemKey: (index) =>
|
|
39
|
+
getItemKey: (index) => flatItems[index].id,
|
|
40
40
|
estimateSize: () => 28,
|
|
41
41
|
overscan: 10,
|
|
42
42
|
});
|
|
43
43
|
const items = virtualizer.getVirtualItems();
|
|
44
44
|
const scrollToElement = useCallback(({ errorNode, expandTo }) => {
|
|
45
|
-
const index =
|
|
45
|
+
const index = flatItems.findIndex((flatItem) => flatItem.id === errorNode.id);
|
|
46
46
|
if (index === -1) {
|
|
47
47
|
expandTo((nodeId) => expandNode(nodeId, true));
|
|
48
48
|
scrollToNode.current = errorNode.id;
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
51
|
virtualizer.scrollToIndex(index, { align: "end" });
|
|
52
|
-
}, [expandNode,
|
|
52
|
+
}, [expandNode, flatItems, virtualizer]);
|
|
53
53
|
useEffect(() => {
|
|
54
54
|
if (scrollToNode.current === undefined) {
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
|
-
const index =
|
|
57
|
+
const index = flatItems.findIndex((flatItem) => flatItem.id === scrollToNode.current);
|
|
58
58
|
if (index === -1) {
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
61
|
virtualizer.scrollToIndex(index, { align: "end" });
|
|
62
62
|
scrollToNode.current = undefined;
|
|
63
|
-
}, [
|
|
63
|
+
}, [flatItems, virtualizer]);
|
|
64
64
|
const errorRendererProps = {
|
|
65
65
|
errorList,
|
|
66
66
|
scrollToElement,
|
|
@@ -69,12 +69,12 @@ export function StrataKitTreeRenderer({ rootNodes, selectNodes, selectionMode, e
|
|
|
69
69
|
reloadTree,
|
|
70
70
|
};
|
|
71
71
|
return (_jsxs(LocalizationContextProvider, { localizedStrings: localizedStrings, children: [errorRenderer ? errorRenderer(errorRendererProps) : _jsx(TreeErrorRenderer, { ...errorRendererProps }), _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", overflow: "hidden" }, children: items.map((virtualizedItem) => {
|
|
72
|
-
const
|
|
73
|
-
const selected = isNodeSelected?.(
|
|
74
|
-
return (_createElement(VirtualTreeItem, { ...treeProps, onNodeClick: handleNodeClick, onNodeKeyDown: handleKeyDown, ref: virtualizer.measureElement, start: virtualizedItem.start, expandNode: expandNode,
|
|
72
|
+
const item = flatItems[virtualizedItem.index];
|
|
73
|
+
const selected = isNodeSelected?.(item.id) ?? false;
|
|
74
|
+
return (_createElement(VirtualTreeItem, { ...treeProps, onNodeClick: handleNodeClick, onNodeKeyDown: handleKeyDown, ref: virtualizer.measureElement, start: virtualizedItem.start, expandNode: expandNode, item: item, key: virtualizedItem.key, "data-index": virtualizedItem.index, reloadTree: reloadTree, selected: selected, getEditingProps: getEditingProps }));
|
|
75
75
|
}) }) })] }));
|
|
76
76
|
}
|
|
77
|
-
const VirtualTreeItem = memo(forwardRef(function VirtualTreeItem({ start,
|
|
77
|
+
const VirtualTreeItem = memo(forwardRef(function VirtualTreeItem({ start, item, getDecorations, getMenuActions, getInlineActions, getLabel, getSublabel, expandNode, reloadTree, onNodeClick, onNodeKeyDown, getEditingProps, ...props }, forwardedRef) {
|
|
78
78
|
const style = useMemo(() => ({
|
|
79
79
|
position: "absolute",
|
|
80
80
|
top: 0,
|
|
@@ -83,11 +83,11 @@ const VirtualTreeItem = memo(forwardRef(function VirtualTreeItem({ start, node,
|
|
|
83
83
|
transform: `translateY(${start}px)`,
|
|
84
84
|
willChange: "transform",
|
|
85
85
|
}), [start]);
|
|
86
|
-
if (
|
|
87
|
-
return _jsx(PlaceholderNode, { ...props, ref: forwardedRef, style: style, "aria-level":
|
|
86
|
+
if (isPlaceholderItem(item)) {
|
|
87
|
+
return _jsx(PlaceholderNode, { ...props, ref: forwardedRef, style: style, "aria-level": item.level, "aria-posinset": 1, "aria-setsize": 1 });
|
|
88
88
|
}
|
|
89
|
-
const editingProps = getEditingProps?.(node);
|
|
90
|
-
return (_jsx(RenameContextProvider, { onLabelChanged: editingProps?.onLabelChanged, children: _jsx(StrataKitTreeNodeRenderer, { ...props, ref: forwardedRef, style: style, "aria-level":
|
|
89
|
+
const editingProps = getEditingProps?.(item.node);
|
|
90
|
+
return (_jsx(RenameContextProvider, { onLabelChanged: editingProps?.onLabelChanged, children: _jsx(StrataKitTreeNodeRenderer, { ...props, ref: forwardedRef, style: style, "aria-level": item.level, "aria-posinset": item.posInLevel, "aria-setsize": item.levelSize, node: item.node, expandNode: expandNode, reloadTree: reloadTree, getDecorations: getDecorations, getMenuActions: getMenuActions, getInlineActions: getInlineActions, getLabel: getLabel, getSublabel: getSublabel, onNodeClick: onNodeClick, onNodeKeyDown: onNodeKeyDown }) }));
|
|
91
91
|
}));
|
|
92
92
|
function noopSelectNodes() { }
|
|
93
93
|
//# sourceMappingURL=TreeRenderer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/TreeRenderer.tsx"],"names":[],"mappings":";;AAAA;;;gGAGgG;AAEhG,OAAO,EAA2C,UAAU,EAAE,IAAI,EAAgB,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACzI,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGzD,OAAO,EAAiB,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAA2B,iBAAiB,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAClH,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CA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AAI,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, memo, ReactElement, useCallback, useEffect, useMemo, useRef } from \"react\";\nimport { Tree } from \"@stratakit/structures\";\nimport { useVirtualizer } from \"@tanstack/react-virtual\";\nimport { TreeRendererProps } from \"../Renderers.js\";\nimport { PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { SelectionMode, useSelectionHandler } from \"../UseSelectionHandler.js\";\nimport { useEvent } from \"../Utils.js\";\nimport { ErrorItem, FlatTreeNode, isPlaceholderNode, useErrorList, useFlatTreeNodeList } from \"./FlatTreeNode.js\";\nimport { LocalizationContextProvider } from \"./LocalizationContext.js\";\nimport { RenameContextProvider } from \"./RenameAction.js\";\nimport { TreeErrorRenderer, TreeErrorRendererProps } from \"./TreeErrorRenderer.js\";\nimport { PlaceholderNode, StrataKitTreeNodeRenderer } from \"./TreeNodeRenderer.js\";\n\n/** @alpha */\nexport type TreeProps = ComponentPropsWithoutRef<typeof Tree.Root>;\n\n/** @alpha */\nexport type TreeNodeRendererProps = ComponentPropsWithoutRef<typeof StrataKitTreeNodeRenderer>;\n\n/** @alpha */\ninterface TreeRendererOwnProps {\n /** Active selection mode used by the tree. Defaults to `\"single\"`. */\n selectionMode?: SelectionMode;\n /** A render function for errors' display component. Defaults to `<TreeErrorRenderer />`. */\n errorRenderer?: (props: TreeErrorRendererProps) => ReactElement;\n /** Props that defines if current node supports editing. */\n getEditingProps?: (node: PresentationHierarchyNode) => {\n /** Callback that is invoked when node label is changed. If `undefined` node label is not editable. */\n onLabelChanged?: (newLabel: string) => void;\n };\n}\n\n/** @alpha */\ntype StrataKitTreeRendererProps = TreeRendererProps &\n Pick<TreeErrorRendererProps, \"onFilterClick\"> &\n Omit<TreeNodeRendererProps, \"node\" | \"aria-level\" | \"aria-posinset\" | \"aria-setsize\" | \"reloadTree\" | \"selected\" | \"error\"> &\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 StrataKitTreeRenderer({\n rootNodes,\n selectNodes,\n selectionMode,\n expandNode,\n localizedStrings,\n getHierarchyLevelDetails,\n onFilterClick,\n reloadTree,\n isNodeSelected,\n errorRenderer,\n onNodeClick: onNodeClickOverride,\n onNodeKeyDown: onNodeKeyDownOverride,\n getEditingProps,\n ...treeProps\n}: StrataKitTreeRendererProps) {\n const { onNodeClick, onNodeKeyDown } = useSelectionHandler({\n rootNodes,\n selectNodes: selectNodes ?? noopSelectNodes,\n selectionMode: selectionMode ?? \"single\",\n });\n const handleNodeClick = useEvent(onNodeClickOverride ?? onNodeClick);\n const handleKeyDown = useEvent(onNodeKeyDownOverride ?? onNodeKeyDown);\n const flatNodes = useFlatTreeNodeList(rootNodes);\n const errorList = useErrorList(rootNodes);\n\n const scrollToNode = useRef<string | undefined>(undefined);\n const parentRef = useRef<HTMLDivElement>(null);\n\n const virtualizer = useVirtualizer({\n count: flatNodes.length,\n getScrollElement: () => parentRef.current,\n getItemKey: (index) => flatNodes[index].id,\n estimateSize: () => 28,\n overscan: 10,\n });\n\n const items = virtualizer.getVirtualItems();\n\n const scrollToElement = useCallback(\n ({ errorNode, expandTo }: ErrorItem) => {\n const index = flatNodes.findIndex((flatNode) => flatNode.id === errorNode.id);\n if (index === -1) {\n expandTo((nodeId) => expandNode(nodeId, true));\n scrollToNode.current = errorNode.id;\n return;\n }\n virtualizer.scrollToIndex(index, { align: \"end\" });\n },\n [expandNode, flatNodes, virtualizer],\n );\n\n useEffect(() => {\n if (scrollToNode.current === undefined) {\n return;\n }\n const index = flatNodes.findIndex((flatNode) => flatNode.id === scrollToNode.current);\n if (index === -1) {\n return;\n }\n virtualizer.scrollToIndex(index, { align: \"end\" });\n scrollToNode.current = undefined;\n }, [flatNodes, virtualizer]);\n\n const errorRendererProps: TreeErrorRendererProps = {\n errorList,\n scrollToElement,\n getHierarchyLevelDetails,\n onFilterClick,\n reloadTree,\n };\n\n return (\n <LocalizationContextProvider localizedStrings={localizedStrings}>\n {errorRenderer ? errorRenderer(errorRendererProps) : <TreeErrorRenderer {...errorRendererProps} />}\n <div style={{ height: \"100%\", width: \"100%\", overflowY: \"auto\" }} ref={parentRef}>\n <Tree.Root style={{ height: virtualizer.getTotalSize(), minHeight: \"100%\", width: \"100%\", position: \"relative\", overflow: \"hidden\" }}>\n {items.map((virtualizedItem) => {\n const node = flatNodes[virtualizedItem.index];\n const selected = isNodeSelected?.(node.id) ?? false;\n return (\n <VirtualTreeItem\n {...treeProps}\n onNodeClick={handleNodeClick}\n onNodeKeyDown={handleKeyDown}\n ref={virtualizer.measureElement}\n start={virtualizedItem.start}\n expandNode={expandNode}\n node={node}\n key={virtualizedItem.key}\n data-index={virtualizedItem.index}\n reloadTree={reloadTree}\n selected={selected}\n getEditingProps={getEditingProps}\n />\n );\n })}\n </Tree.Root>\n </div>\n </LocalizationContextProvider>\n );\n}\n\ntype VirtualTreeItemProps = Omit<TreeNodeRendererProps, \"node\" | \"aria-level\" | \"aria-posinset\" | \"aria-setsize\"> & {\n start: number;\n node: FlatTreeNode;\n getEditingProps?: TreeRendererOwnProps[\"getEditingProps\"];\n};\n\nconst VirtualTreeItem = memo(\n forwardRef<HTMLElement, VirtualTreeItemProps>(function VirtualTreeItem(\n { start, node, getDecorations, getActions, getLabel, getSublabel, expandNode, reloadTree, onNodeClick, onNodeKeyDown, getEditingProps, ...props },\n forwardedRef,\n ) {\n const style: CSSProperties = useMemo(\n () => ({\n position: \"absolute\",\n top: 0,\n left: 0,\n width: \"100%\",\n transform: `translateY(${start}px)`,\n willChange: \"transform\",\n }),\n [start],\n );\n\n if (isPlaceholderNode(node)) {\n return <PlaceholderNode {...props} ref={forwardedRef} style={style} aria-level={node.level} aria-posinset={1} aria-setsize={1} />;\n }\n\n const editingProps = getEditingProps?.(node);\n return (\n <RenameContextProvider onLabelChanged={editingProps?.onLabelChanged}>\n <StrataKitTreeNodeRenderer\n {...props}\n ref={forwardedRef}\n style={style}\n aria-level={node.level}\n aria-posinset={node.posInLevel}\n aria-setsize={node.levelSize}\n node={node}\n expandNode={expandNode}\n reloadTree={reloadTree}\n getDecorations={getDecorations}\n getActions={getActions}\n getLabel={getLabel}\n getSublabel={getSublabel}\n onNodeClick={onNodeClick}\n onNodeKeyDown={onNodeKeyDown}\n />\n </RenameContextProvider>\n );\n }),\n);\n\nfunction noopSelectNodes() {}\n"]}
|
|
1
|
+
{"version":3,"file":"TreeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/TreeRenderer.tsx"],"names":[],"mappings":";;AAAA;;;gGAGgG;AAEhG,OAAO,EAA2C,UAAU,EAAE,IAAI,EAAgB,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACzI,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGzD,OAAO,EAAiB,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAA2B,iBAAiB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC/G,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAA0B,MAAM,wBAAwB,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AA4BnF;;;;;;GAM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KAAK,GAAkB,OAAO,CAClC,GAAG,EAAE,CAAC,CAAC;QACL,QAAQ,EAAE,UAAU;QACpB,GAAG,EAAE,CAAC;QACN,IAAI,EAAE,CAAC;QACP,KAAK,EAAE,MAAM;QACb,SAAS,EAAE,cAAc,KAAK,KAAK;QACnC,UAAU,EAAE,WAAW;KACxB,CAAC,EACF,CAAC,KAAK,CAAC,CACR,CAAC;IAEF,IAAI,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5B,OAAO,KAAC,eAAe,OAAK,KAAK,EAAE,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,KAAK,gBAAc,IAAI,CAAC,KAAK,mBAAiB,CAAC,kBAAgB,CAAC,GAAI,CAAC;IACpI,CAAC;IAED,MAAM,YAAY,GAAG,eAAe,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClD,OAAO,CACL,KAAC,qBAAqB,IAAC,cAAc,EAAE,YAAY,EAAE,cAAc,YACjE,KAAC,yBAAyB,OACpB,KAAK,EACT,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,KAAK,gBACA,IAAI,CAAC,KAAK,mBACP,IAAI,CAAC,UAAU,kBAChB,IAAI,CAAC,SAAS,EAC5B,IAAI,EAAE,IAAI,CAAC,IAAI,EACf,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE,UAAU,EACtB,cAAc,EAAE,cAAc,EAC9B,cAAc,EAAE,cAAc,EAC9B,gBAAgB,EAAE,gBAAgB,EAClC,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,GAC5B,GACoB,CACzB,CAAC;AACJ,CAAC,CAAC,CACH,CAAC;AAEF,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, CSSProperties, forwardRef, memo, ReactElement, useCallback, useEffect, useMemo, useRef } from \"react\";\nimport { Tree } from \"@stratakit/structures\";\nimport { useVirtualizer } from \"@tanstack/react-virtual\";\nimport { TreeRendererProps } from \"../Renderers.js\";\nimport { PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { SelectionMode, useSelectionHandler } from \"../UseSelectionHandler.js\";\nimport { useEvent } from \"../Utils.js\";\nimport { ErrorItem, FlatTreeItem, isPlaceholderItem, useErrorList, useFlatTreeItems } from \"./FlatTreeNode.js\";\nimport { LocalizationContextProvider } from \"./LocalizationContext.js\";\nimport { RenameContextProvider } from \"./RenameAction.js\";\nimport { TreeErrorRenderer, TreeErrorRendererProps } from \"./TreeErrorRenderer.js\";\nimport { PlaceholderNode, StrataKitTreeNodeRenderer } from \"./TreeNodeRenderer.js\";\n\n/** @alpha */\nexport type TreeProps = ComponentPropsWithoutRef<typeof Tree.Root>;\n\n/** @alpha */\nexport type TreeNodeRendererProps = ComponentPropsWithoutRef<typeof StrataKitTreeNodeRenderer>;\n\n/** @alpha */\ninterface TreeRendererOwnProps {\n /** Active selection mode used by the tree. Defaults to `\"single\"`. */\n selectionMode?: SelectionMode;\n /** A render function for errors' display component. Defaults to `<TreeErrorRenderer />`. */\n errorRenderer?: (props: TreeErrorRendererProps) => ReactElement;\n /** Props that defines if current node supports editing. */\n getEditingProps?: (node: PresentationHierarchyNode) => {\n /** Callback that is invoked when node label is changed. If `undefined` node label is not editable. */\n onLabelChanged?: (newLabel: string) => void;\n };\n}\n\n/** @alpha */\ntype StrataKitTreeRendererProps = TreeRendererProps &\n Pick<TreeErrorRendererProps, \"onFilterClick\"> &\n Omit<TreeNodeRendererProps, \"node\" | \"aria-level\" | \"aria-posinset\" | \"aria-setsize\" | \"reloadTree\" | \"selected\" | \"error\"> &\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 StrataKitTreeRenderer({\n rootNodes,\n selectNodes,\n selectionMode,\n expandNode,\n localizedStrings,\n getHierarchyLevelDetails,\n onFilterClick,\n reloadTree,\n isNodeSelected,\n errorRenderer,\n onNodeClick: onNodeClickOverride,\n onNodeKeyDown: onNodeKeyDownOverride,\n getEditingProps,\n ...treeProps\n}: StrataKitTreeRendererProps) {\n const { onNodeClick, onNodeKeyDown } = useSelectionHandler({\n rootNodes,\n selectNodes: selectNodes ?? noopSelectNodes,\n selectionMode: selectionMode ?? \"single\",\n });\n const handleNodeClick = useEvent(onNodeClickOverride ?? onNodeClick);\n const handleKeyDown = useEvent(onNodeKeyDownOverride ?? onNodeKeyDown);\n const flatItems = useFlatTreeItems(rootNodes);\n const errorList = useErrorList(rootNodes);\n\n const scrollToNode = useRef<string | undefined>(undefined);\n const parentRef = useRef<HTMLDivElement>(null);\n\n const virtualizer = useVirtualizer({\n count: flatItems.length,\n getScrollElement: () => parentRef.current,\n getItemKey: (index) => flatItems[index].id,\n estimateSize: () => 28,\n overscan: 10,\n });\n\n const items = virtualizer.getVirtualItems();\n\n const scrollToElement = useCallback(\n ({ errorNode, expandTo }: ErrorItem) => {\n const index = flatItems.findIndex((flatItem) => flatItem.id === errorNode.id);\n if (index === -1) {\n expandTo((nodeId) => expandNode(nodeId, true));\n scrollToNode.current = errorNode.id;\n return;\n }\n virtualizer.scrollToIndex(index, { align: \"end\" });\n },\n [expandNode, flatItems, virtualizer],\n );\n\n useEffect(() => {\n if (scrollToNode.current === undefined) {\n return;\n }\n const index = flatItems.findIndex((flatItem) => flatItem.id === scrollToNode.current);\n if (index === -1) {\n return;\n }\n virtualizer.scrollToIndex(index, { align: \"end\" });\n scrollToNode.current = undefined;\n }, [flatItems, virtualizer]);\n\n const errorRendererProps: TreeErrorRendererProps = {\n errorList,\n scrollToElement,\n getHierarchyLevelDetails,\n onFilterClick,\n reloadTree,\n };\n\n return (\n <LocalizationContextProvider localizedStrings={localizedStrings}>\n {errorRenderer ? errorRenderer(errorRendererProps) : <TreeErrorRenderer {...errorRendererProps} />}\n <div style={{ height: \"100%\", width: \"100%\", overflowY: \"auto\" }} ref={parentRef}>\n <Tree.Root style={{ height: virtualizer.getTotalSize(), minHeight: \"100%\", width: \"100%\", position: \"relative\", overflow: \"hidden\" }}>\n {items.map((virtualizedItem) => {\n const item = flatItems[virtualizedItem.index];\n const selected = isNodeSelected?.(item.id) ?? false;\n return (\n <VirtualTreeItem\n {...treeProps}\n onNodeClick={handleNodeClick}\n onNodeKeyDown={handleKeyDown}\n ref={virtualizer.measureElement}\n start={virtualizedItem.start}\n expandNode={expandNode}\n item={item}\n key={virtualizedItem.key}\n data-index={virtualizedItem.index}\n reloadTree={reloadTree}\n selected={selected}\n getEditingProps={getEditingProps}\n />\n );\n })}\n </Tree.Root>\n </div>\n </LocalizationContextProvider>\n );\n}\n\ntype VirtualTreeItemProps = Omit<TreeNodeRendererProps, \"node\" | \"aria-level\" | \"aria-posinset\" | \"aria-setsize\"> & {\n start: number;\n item: FlatTreeItem;\n getEditingProps?: TreeRendererOwnProps[\"getEditingProps\"];\n};\n\nconst VirtualTreeItem = memo(\n forwardRef<HTMLElement, VirtualTreeItemProps>(function VirtualTreeItem(\n {\n start,\n item,\n getDecorations,\n getMenuActions,\n getInlineActions,\n getLabel,\n getSublabel,\n expandNode,\n reloadTree,\n onNodeClick,\n onNodeKeyDown,\n getEditingProps,\n ...props\n },\n forwardedRef,\n ) {\n const style: CSSProperties = useMemo(\n () => ({\n position: \"absolute\",\n top: 0,\n left: 0,\n width: \"100%\",\n transform: `translateY(${start}px)`,\n willChange: \"transform\",\n }),\n [start],\n );\n\n if (isPlaceholderItem(item)) {\n return <PlaceholderNode {...props} ref={forwardedRef} style={style} aria-level={item.level} aria-posinset={1} aria-setsize={1} />;\n }\n\n const editingProps = getEditingProps?.(item.node);\n return (\n <RenameContextProvider onLabelChanged={editingProps?.onLabelChanged}>\n <StrataKitTreeNodeRenderer\n {...props}\n ref={forwardedRef}\n style={style}\n aria-level={item.level}\n aria-posinset={item.posInLevel}\n aria-setsize={item.levelSize}\n node={item.node}\n expandNode={expandNode}\n reloadTree={reloadTree}\n getDecorations={getDecorations}\n getMenuActions={getMenuActions}\n getInlineActions={getInlineActions}\n getLabel={getLabel}\n getSublabel={getSublabel}\n onNodeClick={onNodeClick}\n onNodeKeyDown={onNodeKeyDown}\n />\n </RenameContextProvider>\n );\n }),\n);\n\nfunction noopSelectNodes() {}\n"]}
|
|
@@ -9,7 +9,7 @@ export { RenameAction, RenameContextProvider } from "./presentation-hierarchies-
|
|
|
9
9
|
export { StrataKitTreeRenderer } from "./presentation-hierarchies-react/stratakit/TreeRenderer.js";
|
|
10
10
|
export { StrataKitRootErrorRenderer } from "./presentation-hierarchies-react/stratakit/RootErrorRenderer.js";
|
|
11
11
|
export { TreeErrorRenderer } from "./presentation-hierarchies-react/stratakit/TreeErrorRenderer.js";
|
|
12
|
-
export {
|
|
12
|
+
export { useFlatTreeItems, useErrorList, FlatTreeItem } from "./presentation-hierarchies-react/stratakit/FlatTreeNode.js";
|
|
13
13
|
export { LocalizationContextProvider } from "./presentation-hierarchies-react/stratakit/LocalizationContext.js";
|
|
14
14
|
export { GenericInstanceFilter, HierarchyNode, HierarchyProvider, getLogger, setLogger } from "@itwin/presentation-hierarchies";
|
|
15
15
|
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,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,SAAS,EAAE,0BAA0B,EAAE,MAAM,8CAA8C,CAAC;AAClJ,OAAO,EAAE,mBAAmB,EAAE,MAAM,yDAAyD,CAAC;AAC9F,OAAO,EAAE,OAAO,EA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AAiE,CAAC;AAC7G,OAAO,EAAE,iBAAiB,EAAE,MAAM,iEAAiE,CAAC;AACpG,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,4DAA4D,CAAC;AAC1H,OAAO,EAAE,2BAA2B,EAAE,MAAM,mEAAmE,CAAC;AAEhH,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,iBAAiB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAChI,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -11,7 +11,7 @@ export { RenameAction, RenameContextProvider } from "./presentation-hierarchies-
|
|
|
11
11
|
export { StrataKitTreeRenderer } from "./presentation-hierarchies-react/stratakit/TreeRenderer.js";
|
|
12
12
|
export { StrataKitRootErrorRenderer } from "./presentation-hierarchies-react/stratakit/RootErrorRenderer.js";
|
|
13
13
|
export { TreeErrorRenderer } from "./presentation-hierarchies-react/stratakit/TreeErrorRenderer.js";
|
|
14
|
-
export {
|
|
14
|
+
export { useFlatTreeItems, useErrorList } from "./presentation-hierarchies-react/stratakit/FlatTreeNode.js";
|
|
15
15
|
export { LocalizationContextProvider } from "./presentation-hierarchies-react/stratakit/LocalizationContext.js";
|
|
16
16
|
export { GenericInstanceFilter, HierarchyNode, getLogger, setLogger } from "@itwin/presentation-hierarchies";
|
|
17
17
|
//# 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;AAGhG,OAAO,EAAE,mBAAmB,EAAE,MAAM,yDAAyD,CAAC;AAC9F,OAAO,EAAE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6CAA6C,CAAC;AAE/F,OAAO,EAAE,aAAa,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAC;AACjH,OAAO,EAAE,yBAAyB,EAAE,MAAM,gEAAgE,CAAC;AAC3G,OAAO,EAAE,YAAY,EAAE,MAAM,4DAA4D,CAAC;AAC1F,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,4DAA4D,CAAC;AACjH,OAAO,EAAE,qBAAqB,EAAE,MAAM,4DAA4D,CAAC;AACnG,OAAO,EAAE,0BAA0B,EAAE,MAAM,iEAAiE,CAAC;AAC7G,OAAO,EAAE,iBAAiB,EAAE,MAAM,iEAAiE,CAAC;AACpG,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"presentation-hierarchies-react.js","sourceRoot":"","sources":["../../src/presentation-hierarchies-react.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAGhG,OAAO,EAAE,mBAAmB,EAAE,MAAM,yDAAyD,CAAC;AAC9F,OAAO,EAAE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6CAA6C,CAAC;AAE/F,OAAO,EAAE,aAAa,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAC;AACjH,OAAO,EAAE,yBAAyB,EAAE,MAAM,gEAAgE,CAAC;AAC3G,OAAO,EAAE,YAAY,EAAE,MAAM,4DAA4D,CAAC;AAC1F,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,4DAA4D,CAAC;AACjH,OAAO,EAAE,qBAAqB,EAAE,MAAM,4DAA4D,CAAC;AACnG,OAAO,EAAE,0BAA0B,EAAE,MAAM,iEAAiE,CAAC;AAC7G,OAAO,EAAE,iBAAiB,EAAE,MAAM,iEAAiE,CAAC;AACpG,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAgB,MAAM,4DAA4D,CAAC;AAC1H,OAAO,EAAE,2BAA2B,EAAE,MAAM,mEAAmE,CAAC;AAEhH,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAqB,SAAS,EAAE,SAAS,EAAE,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 { GenericErrorInfo, PresentationHierarchyNode, ErrorInfo, ResultSetTooLargeErrorInfo } from \"./presentation-hierarchies-react/TreeNode.js\";\nexport { useSelectionHandler } from \"./presentation-hierarchies-react/UseSelectionHandler.js\";\nexport { useTree, useUnifiedSelectionTree } from \"./presentation-hierarchies-react/UseTree.js\";\nexport { HierarchyLevelDetails, TreeRendererProps } from \"./presentation-hierarchies-react/Renderers.js\";\nexport { useIModelTree, useIModelUnifiedSelectionTree } from \"./presentation-hierarchies-react/UseIModelTree.js\";\nexport { StrataKitTreeNodeRenderer } from \"./presentation-hierarchies-react/stratakit/TreeNodeRenderer.js\";\nexport { FilterAction } from \"./presentation-hierarchies-react/stratakit/FilterAction.js\";\nexport { RenameAction, RenameContextProvider } from \"./presentation-hierarchies-react/stratakit/RenameAction.js\";\nexport { StrataKitTreeRenderer } from \"./presentation-hierarchies-react/stratakit/TreeRenderer.js\";\nexport { StrataKitRootErrorRenderer } from \"./presentation-hierarchies-react/stratakit/RootErrorRenderer.js\";\nexport { TreeErrorRenderer } from \"./presentation-hierarchies-react/stratakit/TreeErrorRenderer.js\";\nexport { useFlatTreeItems, useErrorList, FlatTreeItem } from \"./presentation-hierarchies-react/stratakit/FlatTreeNode.js\";\nexport { LocalizationContextProvider } from \"./presentation-hierarchies-react/stratakit/LocalizationContext.js\";\n\nexport { GenericInstanceFilter, HierarchyNode, HierarchyProvider, getLogger, setLogger } 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.26",
|
|
4
4
|
"description": "React components based on `@itwin/presentation-hierarchies`",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -43,14 +43,14 @@
|
|
|
43
43
|
"immer": "^10.1.1",
|
|
44
44
|
"react-error-boundary": "^4.0.13",
|
|
45
45
|
"rxjs": "^7.8.1",
|
|
46
|
-
"@itwin/presentation-hierarchies": "^2.0.0-alpha.
|
|
46
|
+
"@itwin/presentation-hierarchies": "^2.0.0-alpha.2",
|
|
47
47
|
"@itwin/presentation-shared": "^2.0.0-alpha.1",
|
|
48
48
|
"@itwin/unified-selection": "^1.4.3-alpha.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@stratakit/bricks": "^0.
|
|
52
|
-
"@stratakit/foundations": "^0.
|
|
53
|
-
"@stratakit/structures": "^0.
|
|
51
|
+
"@stratakit/bricks": "^0.3.3",
|
|
52
|
+
"@stratakit/foundations": "^0.2.2",
|
|
53
|
+
"@stratakit/structures": "^0.3.1",
|
|
54
54
|
"@stratakit/icons": "^0.1.0",
|
|
55
55
|
"react": "^17.0.0 || ^18.0.0",
|
|
56
56
|
"react-dom": "^17.0.0 || ^18.0.0"
|
|
@@ -72,9 +72,9 @@
|
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@itwin/build-tools": "^5.0.0",
|
|
74
74
|
"@itwin/eslint-plugin": "5.1.0",
|
|
75
|
-
"@stratakit/bricks": "^0.
|
|
76
|
-
"@stratakit/foundations": "^0.
|
|
77
|
-
"@stratakit/structures": "^0.
|
|
75
|
+
"@stratakit/bricks": "^0.3.3",
|
|
76
|
+
"@stratakit/foundations": "^0.2.2",
|
|
77
|
+
"@stratakit/structures": "^0.3.1",
|
|
78
78
|
"@stratakit/icons": "^0.1.0",
|
|
79
79
|
"@testing-library/dom": "^10.4.0",
|
|
80
80
|
"@testing-library/react": "^16.2.0",
|