@itwin/presentation-hierarchies-react 2.0.0-alpha.14 → 2.0.0-alpha.16
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 +117 -0
- package/lib/esm/presentation-hierarchies-react/TreeNode.d.ts +0 -4
- package/lib/esm/presentation-hierarchies-react/TreeNode.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/TreeNode.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.js +0 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts +1 -5
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.js +0 -11
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/FilterAction.d.ts +18 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/FilterAction.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/FilterAction.js +32 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/FilterAction.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.d.ts +36 -7
- package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.js +18 -6
- package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.d.ts +15 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.js +3 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/RootErrorRenderer.d.ts +16 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/RootErrorRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/RootErrorRenderer.js +41 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/RootErrorRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.d.ts +29 -9
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.js +52 -33
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.d.ts +10 -9
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js +18 -28
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.d.ts +9 -4
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.js +43 -20
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react.d.ts +4 -4
- package/lib/esm/presentation-hierarchies-react.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react.js +4 -4
- package/lib/esm/presentation-hierarchies-react.js.map +1 -1
- package/package.json +6 -6
- package/lib/esm/presentation-hierarchies-react/UnifiedSelectionContext.d.ts +0 -15
- package/lib/esm/presentation-hierarchies-react/UnifiedSelectionContext.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/UnifiedSelectionContext.js +0 -22
- package/lib/esm/presentation-hierarchies-react/UnifiedSelectionContext.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.d.ts +0 -31
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.js +0 -40
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.js.map +0 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { ComponentPropsWithoutRef } from "react";
|
|
1
|
+
import { ComponentPropsWithoutRef, ReactElement } from "react";
|
|
2
2
|
import { Tree } from "@itwin/itwinui-react/bricks";
|
|
3
3
|
import { PresentationTreeNode } from "../TreeNode.js";
|
|
4
4
|
import { SelectionMode } from "../UseSelectionHandler.js";
|
|
5
5
|
import { useTree } from "../UseTree.js";
|
|
6
6
|
import { LocalizationContextProvider } from "./LocalizationContext.js";
|
|
7
|
-
import {
|
|
7
|
+
import { RootErrorRendererProps } from "./RootErrorRenderer.js";
|
|
8
|
+
import { TreeErrorRendererProps } from "./TreeErrorRenderer.js";
|
|
8
9
|
import { TreeNodeRenderer } from "./TreeNodeRenderer.js";
|
|
9
10
|
/** @alpha */
|
|
10
11
|
export type TreeProps = ComponentPropsWithoutRef<typeof Tree.Root>;
|
|
@@ -16,9 +17,13 @@ interface TreeRendererOwnProps {
|
|
|
16
17
|
rootNodes: PresentationTreeNode[];
|
|
17
18
|
/** Active selection mode used by the tree. Defaults to `"single"`. */
|
|
18
19
|
selectionMode?: SelectionMode;
|
|
20
|
+
/** A render function for errors' display component. Defaults to `<TreeErrorRenderer />`. */
|
|
21
|
+
errorRenderer?: (props: TreeErrorRendererProps) => ReactElement;
|
|
22
|
+
/** A render function for root errors' display component. Defaults to `<RootErrorRenderer />`. */
|
|
23
|
+
rootErrorRenderer?: (props: RootErrorRendererProps) => ReactElement;
|
|
19
24
|
}
|
|
20
25
|
/** @alpha */
|
|
21
|
-
type TreeRendererProps = Pick<ReturnType<typeof useTree>, "expandNode"> & Partial<Pick<ReturnType<typeof useTree>, "selectNodes" | "isNodeSelected"
|
|
26
|
+
type TreeRendererProps = Pick<ReturnType<typeof useTree>, "expandNode"> & Partial<Pick<ReturnType<typeof useTree>, "selectNodes" | "isNodeSelected">> & Pick<ReturnType<typeof useTree>, "reloadTree" | "getHierarchyLevelDetails"> & Pick<TreeErrorRendererProps, "onFilterClick"> & Omit<TreeNodeRendererProps, "node" | "aria-level" | "aria-posinset" | "aria-setsize" | "reloadTree" | "selected" | "error"> & TreeRendererOwnProps & ComponentPropsWithoutRef<typeof LocalizationContextProvider>;
|
|
22
27
|
/**
|
|
23
28
|
* A component that renders a tree using the `Tree` component from `@itwin/itwinui-react`. The tree nodes
|
|
24
29
|
* are rendered using `TreeNodeRenderer` component from this package.
|
|
@@ -26,6 +31,6 @@ type TreeRendererProps = Pick<ReturnType<typeof useTree>, "expandNode"> & Partia
|
|
|
26
31
|
* @see https://itwinui.bentley.com/docs/tree
|
|
27
32
|
* @alpha
|
|
28
33
|
*/
|
|
29
|
-
export declare function TreeRenderer({ rootNodes,
|
|
34
|
+
export declare function TreeRenderer({ rootNodes, selectNodes, selectionMode, rootErrorRenderer, ...treeProps }: TreeRendererProps): import("react/jsx-runtime").JSX.Element;
|
|
30
35
|
export {};
|
|
31
36
|
//# sourceMappingURL=TreeRenderer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,wBAAwB,
|
|
1
|
+
{"version":3,"file":"TreeRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,wBAAwB,EAAmC,YAAY,EAA2C,MAAM,OAAO,CAAC;AACzI,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAEnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACt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AG,OAAO,CAAC,GAC3H,oBAAoB,GACpB,wBAAwB,CAAC,OAAO,2BAA2B,CAAC,CAAC;AAE/D;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,iBAAiB,EAAE,GAAG,SAAS,EAAE,EAAE,iBAAiB,2CAwBzH"}
|
|
@@ -9,10 +9,11 @@ import { Tree } from "@itwin/itwinui-react/bricks";
|
|
|
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 { isPlaceholderNode, useErrorList, useFlatTreeNodeList } from "./FlatTreeNode.js";
|
|
13
13
|
import { LocalizationContextProvider } from "./LocalizationContext.js";
|
|
14
|
+
import { RootErrorRenderer } from "./RootErrorRenderer.js";
|
|
14
15
|
import { TreeErrorRenderer } from "./TreeErrorRenderer.js";
|
|
15
|
-
import { TreeNodeRenderer } from "./TreeNodeRenderer.js";
|
|
16
|
+
import { PlaceholderNode, TreeNodeRenderer } from "./TreeNodeRenderer.js";
|
|
16
17
|
/**
|
|
17
18
|
* A component that renders a tree using the `Tree` component from `@itwin/itwinui-react`. The tree nodes
|
|
18
19
|
* are rendered using `TreeNodeRenderer` component from this package.
|
|
@@ -20,18 +21,28 @@ import { TreeNodeRenderer } from "./TreeNodeRenderer.js";
|
|
|
20
21
|
* @see https://itwinui.bentley.com/docs/tree
|
|
21
22
|
* @alpha
|
|
22
23
|
*/
|
|
23
|
-
export function TreeRenderer({ rootNodes,
|
|
24
|
+
export function TreeRenderer({ rootNodes, selectNodes, selectionMode, rootErrorRenderer, ...treeProps }) {
|
|
24
25
|
const { onNodeClick, onNodeKeyDown } = useSelectionHandler({
|
|
25
26
|
rootNodes,
|
|
26
27
|
selectNodes: selectNodes ?? noopSelectNodes,
|
|
27
28
|
selectionMode: selectionMode ?? "single",
|
|
28
29
|
});
|
|
29
|
-
const scrollToNode = useRef(undefined);
|
|
30
|
-
const parentRef = useRef(null);
|
|
31
|
-
const flatNodes = useMemo(() => flattenNodes(rootNodes), [rootNodes]);
|
|
32
|
-
const errorList = useMemo(() => getErrors(rootNodes), [rootNodes]);
|
|
33
30
|
const handleNodeClick = useEvent(onNodeClick);
|
|
34
31
|
const handleKeyDown = useEvent(onNodeKeyDown);
|
|
32
|
+
const flatNodes = useFlatTreeNodeList(rootNodes);
|
|
33
|
+
const errorList = useErrorList(rootNodes);
|
|
34
|
+
if (flatNodes.length === 0 && errorList.length > 0) {
|
|
35
|
+
return rootErrorRenderer ? (rootErrorRenderer({
|
|
36
|
+
errorNode: errorList[0],
|
|
37
|
+
getHierarchyLevelDetails: treeProps.getHierarchyLevelDetails,
|
|
38
|
+
reloadTree: treeProps.reloadTree,
|
|
39
|
+
})) : (_jsx(RootErrorRenderer, { errorNode: errorList[0], reloadTree: treeProps.reloadTree, getHierarchyLevelDetails: treeProps.getHierarchyLevelDetails }));
|
|
40
|
+
}
|
|
41
|
+
return _jsx(TreeHierarchyRenderer, { onNodeClick: handleNodeClick, onNodeKeyDown: handleKeyDown, flatNodes: flatNodes, errorList: errorList, ...treeProps });
|
|
42
|
+
}
|
|
43
|
+
function TreeHierarchyRenderer({ flatNodes, errorList, expandNode, localizedStrings, getHierarchyLevelDetails, onFilterClick, reloadTree, isNodeSelected, errorRenderer, ...treeProps }) {
|
|
44
|
+
const scrollToNode = useRef(undefined);
|
|
45
|
+
const parentRef = useRef(null);
|
|
35
46
|
const hasError = useCallback((nodeId) => {
|
|
36
47
|
return errorList.find((errorNode) => errorNode.parent?.id === nodeId);
|
|
37
48
|
}, [errorList]);
|
|
@@ -63,21 +74,33 @@ export function TreeRenderer({ rootNodes, expandNode, localizedStrings, selectNo
|
|
|
63
74
|
virtualizer.scrollToIndex(index, { align: "end" });
|
|
64
75
|
scrollToNode.current = undefined;
|
|
65
76
|
}, [flatNodes, virtualizer]);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
77
|
+
const errorRendererProps = {
|
|
78
|
+
errorList,
|
|
79
|
+
scrollToElement,
|
|
80
|
+
getHierarchyLevelDetails,
|
|
81
|
+
onFilterClick,
|
|
82
|
+
reloadTree,
|
|
83
|
+
};
|
|
84
|
+
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) => {
|
|
85
|
+
const node = flatNodes[virtualizedItem.index];
|
|
86
|
+
const selected = isNodeSelected?.(node.id) ?? false;
|
|
87
|
+
const error = hasError(node.id);
|
|
88
|
+
return (_createElement(VirtualTreeItem, { ...treeProps, ref: virtualizer.measureElement, start: virtualizedItem.start, expandNode: expandNode, error: error, node: node, key: virtualizedItem.key, "data-index": virtualizedItem.index, reloadTree: reloadTree, selected: selected }));
|
|
70
89
|
}) }) })] }));
|
|
71
90
|
}
|
|
72
|
-
const VirtualTreeItem = memo(forwardRef(function VirtualTreeItem({ start, ...props }, forwardedRef) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
91
|
+
const VirtualTreeItem = memo(forwardRef(function VirtualTreeItem({ start, node, getDecorations, getActions, getLabel, getSublabel, ...props }, forwardedRef) {
|
|
92
|
+
const style = useMemo(() => ({
|
|
93
|
+
position: "absolute",
|
|
94
|
+
top: 0,
|
|
95
|
+
left: 0,
|
|
96
|
+
width: "100%",
|
|
97
|
+
transform: `translateY(${start}px)`,
|
|
98
|
+
willChange: "transform",
|
|
99
|
+
}), [start]);
|
|
100
|
+
if (isPlaceholderNode(node)) {
|
|
101
|
+
return _jsx(PlaceholderNode, { ...props, ref: forwardedRef, style: style, "aria-level": node.level, "aria-posinset": 1, "aria-setsize": 1 });
|
|
102
|
+
}
|
|
103
|
+
return (_jsx(TreeNodeRenderer, { ...props, ref: forwardedRef, style: style, "aria-level": node.level, "aria-posinset": node.posInLevel, "aria-setsize": node.levelSize, node: node, getDecorations: getDecorations, getActions: getActions, getLabel: getLabel, getSublabel: getSublabel }));
|
|
81
104
|
}));
|
|
82
105
|
function noopSelectNodes() { }
|
|
83
106
|
//# sourceMappingURL=TreeRenderer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeRenderer.tsx"],"names":[],"mappings":";;AAAA;;;gGAGgG;AAEhG,OAAO,EAA4B,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC5G,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EAAiB,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAE/E,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAa,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACvE,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAsB,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAuBzD;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,EAC3B,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,aAAa,EACb,wBAAwB,EACxB,aAAa,EACb,UAAU,EACV,cAAc,EACd,OAAO,EACP,cAAc,EACd,QA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CAAC;AACJ,CAAC;AAED,MAAM,eAAe,GAAG,IAAI,CAC1B,UAAU,CAAyD,SAAS,eAAe,CAAC,EAAE,KAAK,EAAE,GAAG,KAAK,EAAE,EAAE,YAAY;IAC3H,OAAO,CACL,KAAC,gBAAgB,OACX,KAAK,EACT,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC;YACL,QAAQ,EAAE,UAAU;YACpB,GAAG,EAAE,CAAC;YACN,IAAI,EAAE,CAAC;YACP,KAAK,EAAE,MAAM;YACb,SAAS,EAAE,cAAc,KAAK,KAAK;YACnC,UAAU,EAAE,WAAW;SACxB,CAAC,EACF,CAAC,KAAK,CAAC,CACR,GACD,CACH,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, forwardRef, memo, useCallback, useEffect, useMemo, useRef } from \"react\";\nimport { Tree } from \"@itwin/itwinui-react/bricks\";\nimport { useVirtualizer } from \"@tanstack/react-virtual\";\nimport { PresentationTreeNode } from \"../TreeNode.js\";\nimport { SelectionMode, useSelectionHandler } from \"../UseSelectionHandler.js\";\nimport { useTree } from \"../UseTree.js\";\nimport { useEvent } from \"../Utils.js\";\nimport { ErrorNode, flattenNodes, getErrors } from \"./FlatTreeNode.js\";\nimport { LocalizationContextProvider } from \"./LocalizationContext.js\";\nimport { TreeErrorItemProps, TreeErrorRenderer } from \"./TreeErrorRenderer.js\";\nimport { TreeNodeRenderer } from \"./TreeNodeRenderer.js\";\n\n/** @alpha */\nexport type TreeProps = ComponentPropsWithoutRef<typeof Tree.Root>;\n\n/** @alpha */\nexport type TreeNodeRendererProps = ComponentPropsWithoutRef<typeof TreeNodeRenderer>;\n/** @alpha */\ninterface TreeRendererOwnProps {\n /** Root nodes of the tree. */\n rootNodes: PresentationTreeNode[];\n /** Active selection mode used by the tree. Defaults to `\"single\"`. */\n selectionMode?: SelectionMode;\n}\n\n/** @alpha */\ntype TreeRendererProps = Pick<ReturnType<typeof useTree>, \"expandNode\"> &\n Partial<Pick<ReturnType<typeof useTree>, \"selectNodes\" | \"isNodeSelected\" | \"getHierarchyLevelDetails\" | \"reloadTree\">> &\n Pick<TreeErrorItemProps, \"onFilterClick\"> &\n Omit<TreeNodeRendererProps, \"node\" | \"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 TreeRenderer({\n rootNodes,\n expandNode,\n localizedStrings,\n selectNodes,\n selectionMode,\n getHierarchyLevelDetails,\n onFilterClick,\n reloadTree,\n isNodeSelected,\n actions,\n getDecorations,\n getLabel,\n getSublabel,\n ...treeProps\n}: TreeRendererProps) {\n const { onNodeClick, onNodeKeyDown } = useSelectionHandler({\n rootNodes,\n selectNodes: selectNodes ?? noopSelectNodes,\n selectionMode: selectionMode ?? \"single\",\n });\n const scrollToNode = useRef<string | undefined>(undefined);\n const parentRef = useRef<HTMLDivElement>(null);\n const flatNodes = useMemo(() => flattenNodes(rootNodes), [rootNodes]);\n const errorList = useMemo(() => getErrors(rootNodes), [rootNodes]);\n\n const handleNodeClick = useEvent(onNodeClick);\n const handleKeyDown = useEvent(onNodeKeyDown);\n\n const hasError = useCallback(\n (nodeId: string) => {\n return errorList.find((errorNode) => errorNode.parent?.id === nodeId);\n },\n [errorList],\n );\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: ErrorNode) => {\n const index = flatNodes.findIndex((flatNode) => flatNode.id === errorNode.parent?.id);\n if (index === -1) {\n errorNode.expandTo((nodeId) => expandNode(nodeId, true));\n scrollToNode.current = errorNode.parent?.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 return (\n <LocalizationContextProvider localizedStrings={localizedStrings}>\n <TreeErrorRenderer\n errorList={errorList}\n scrollToElement={scrollToElement}\n getHierarchyLevelDetails={getHierarchyLevelDetails}\n onFilterClick={onFilterClick}\n reloadTree={reloadTree}\n />\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 selected = isNodeSelected?.(flatNodes[virtualizedItem.index].id) ?? false;\n const error = hasError(flatNodes[virtualizedItem.index].id);\n return (\n <VirtualTreeItem\n {...treeProps}\n ref={virtualizer.measureElement}\n start={virtualizedItem.start}\n expandNode={expandNode}\n onNodeClick={handleNodeClick}\n onNodeKeyDown={handleKeyDown}\n error={error}\n node={flatNodes[virtualizedItem.index]}\n key={virtualizedItem.key}\n data-index={virtualizedItem.index}\n reloadTree={reloadTree}\n selected={selected}\n actions={actions}\n getDecorations={getDecorations}\n getLabel={getLabel}\n getSublabel={getSublabel}\n />\n );\n })}\n </Tree.Root>\n </div>\n </LocalizationContextProvider>\n );\n}\n\nconst VirtualTreeItem = memo(\n forwardRef<HTMLElement, TreeNodeRendererProps & { start: number }>(function VirtualTreeItem({ start, ...props }, forwardedRef) {\n return (\n <TreeNodeRenderer\n {...props}\n ref={forwardedRef}\n style={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 );\n }),\n);\n\nfunction noopSelectNodes() {}\n"]}
|
|
1
|
+
{"version":3,"file":"TreeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/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,6BAA6B,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,EAAiB,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAE/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,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAA0B,MAAM,wBAAwB,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAA0B,MAAM,wBAAwB,CAAC;AACnF,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AA6B1E;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,iBAAiB,EAAE,GAAG,SAAS,EAAqB;IACxH,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,GAAG,mBAAmB,CAAC;QACzD,SAAS;QACT,WAAW,EAAE,WAAW,IAAI,eAAe;QAC3C,aA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5B,IAAI,EAAE,IAAI,EACV,cAAc,EAAE,cAAc,EAC9B,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,WAAW,GACxB,CACH,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 \"@itwin/itwinui-react/bricks\";\nimport { useVirtualizer } from \"@tanstack/react-virtual\";\nimport { PresentationTreeNode } from \"../TreeNode.js\";\nimport { SelectionMode, useSelectionHandler } from \"../UseSelectionHandler.js\";\nimport { useTree } from \"../UseTree.js\";\nimport { useEvent } from \"../Utils.js\";\nimport { ErrorNode, FlatTreeNode, isPlaceholderNode, useErrorList, useFlatTreeNodeList } from \"./FlatTreeNode.js\";\nimport { LocalizationContextProvider } from \"./LocalizationContext.js\";\nimport { RootErrorRenderer, RootErrorRendererProps } from \"./RootErrorRenderer.js\";\nimport { TreeErrorRenderer, TreeErrorRendererProps } from \"./TreeErrorRenderer.js\";\nimport { PlaceholderNode, TreeNodeRenderer } from \"./TreeNodeRenderer.js\";\n\n/** @alpha */\nexport type TreeProps = ComponentPropsWithoutRef<typeof Tree.Root>;\n\n/** @alpha */\nexport type TreeNodeRendererProps = ComponentPropsWithoutRef<typeof TreeNodeRenderer>;\n\n/** @alpha */\ninterface TreeRendererOwnProps {\n /** Root nodes of the tree. */\n rootNodes: PresentationTreeNode[];\n /** Active selection mode used by the tree. Defaults to `\"single\"`. */\n selectionMode?: SelectionMode;\n /** A render function for errors' display component. Defaults to `<TreeErrorRenderer />`. */\n errorRenderer?: (props: TreeErrorRendererProps) => ReactElement;\n /** A render function for root errors' display component. Defaults to `<RootErrorRenderer />`. */\n rootErrorRenderer?: (props: RootErrorRendererProps) => ReactElement;\n}\n\n/** @alpha */\ntype TreeRendererProps = Pick<ReturnType<typeof useTree>, \"expandNode\"> &\n Partial<Pick<ReturnType<typeof useTree>, \"selectNodes\" | \"isNodeSelected\">> &\n Pick<ReturnType<typeof useTree>, \"reloadTree\" | \"getHierarchyLevelDetails\"> &\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 TreeRenderer({ rootNodes, selectNodes, selectionMode, rootErrorRenderer, ...treeProps }: TreeRendererProps) {\n const { onNodeClick, onNodeKeyDown } = useSelectionHandler({\n rootNodes,\n selectNodes: selectNodes ?? noopSelectNodes,\n selectionMode: selectionMode ?? \"single\",\n });\n const handleNodeClick = useEvent(onNodeClick);\n const handleKeyDown = useEvent(onNodeKeyDown);\n const flatNodes = useFlatTreeNodeList(rootNodes);\n const errorList = useErrorList(rootNodes);\n\n if (flatNodes.length === 0 && errorList.length > 0) {\n return rootErrorRenderer ? (\n rootErrorRenderer({\n errorNode: errorList[0],\n getHierarchyLevelDetails: treeProps.getHierarchyLevelDetails,\n reloadTree: treeProps.reloadTree,\n })\n ) : (\n <RootErrorRenderer errorNode={errorList[0]} reloadTree={treeProps.reloadTree} getHierarchyLevelDetails={treeProps.getHierarchyLevelDetails} />\n );\n }\n\n return <TreeHierarchyRenderer onNodeClick={handleNodeClick} onNodeKeyDown={handleKeyDown} flatNodes={flatNodes} errorList={errorList} {...treeProps} />;\n}\n\nfunction TreeHierarchyRenderer({\n flatNodes,\n errorList,\n expandNode,\n localizedStrings,\n getHierarchyLevelDetails,\n onFilterClick,\n reloadTree,\n isNodeSelected,\n errorRenderer,\n ...treeProps\n}: Omit<TreeRendererProps, \"rootNodes\" | \"selectionMode\" | \" selectNodes\"> & { flatNodes: FlatTreeNode[]; errorList: ErrorNode[] }) {\n const scrollToNode = useRef<string | undefined>(undefined);\n const parentRef = useRef<HTMLDivElement>(null);\n\n const hasError = useCallback(\n (nodeId: string) => {\n return errorList.find((errorNode) => errorNode.parent?.id === nodeId);\n },\n [errorList],\n );\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: ErrorNode) => {\n const index = flatNodes.findIndex((flatNode) => flatNode.id === errorNode.parent?.id);\n if (index === -1) {\n errorNode.expandTo((nodeId) => expandNode(nodeId, true));\n scrollToNode.current = errorNode.parent?.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 const error = hasError(node.id);\n return (\n <VirtualTreeItem\n {...treeProps}\n ref={virtualizer.measureElement}\n start={virtualizedItem.start}\n expandNode={expandNode}\n error={error}\n node={node}\n key={virtualizedItem.key}\n data-index={virtualizedItem.index}\n reloadTree={reloadTree}\n selected={selected}\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};\n\nconst VirtualTreeItem = memo(\n forwardRef<HTMLElement, VirtualTreeItemProps>(function VirtualTreeItem(\n { start, node, getDecorations, getActions, getLabel, getSublabel, ...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 return (\n <TreeNodeRenderer\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 getDecorations={getDecorations}\n getActions={getActions}\n getLabel={getLabel}\n getSublabel={getSublabel}\n />\n );\n }),\n);\n\nfunction noopSelectNodes() {}\n"]}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export { PresentationGenericInfoNode, PresentationHierarchyNode, PresentationInfoNode, PresentationResultSetTooLargeInfoNode, PresentationTreeNode, isPresentationHierarchyNode, } from "./presentation-hierarchies-react/TreeNode.js";
|
|
2
|
-
export { UnifiedSelectionProvider } from "./presentation-hierarchies-react/UnifiedSelectionContext.js";
|
|
3
2
|
export { useSelectionHandler } from "./presentation-hierarchies-react/UseSelectionHandler.js";
|
|
4
3
|
export { HierarchyLevelDetails, useTree, useUnifiedSelectionTree } from "./presentation-hierarchies-react/UseTree.js";
|
|
5
4
|
export { useIModelTree, useIModelUnifiedSelectionTree } from "./presentation-hierarchies-react/UseIModelTree.js";
|
|
6
5
|
export { TreeNodeRenderer } from "./presentation-hierarchies-react/itwinui/TreeNodeRenderer.js";
|
|
7
|
-
export {
|
|
6
|
+
export { FilterAction } from "./presentation-hierarchies-react/itwinui/FilterAction.js";
|
|
8
7
|
export { TreeRenderer } from "./presentation-hierarchies-react/itwinui/TreeRenderer.js";
|
|
9
|
-
export {
|
|
8
|
+
export { TreeErrorRenderer } from "./presentation-hierarchies-react/itwinui/TreeErrorRenderer.js";
|
|
9
|
+
export { useFlatTreeNodeList, useErrorList, FlatTreeNode } from "./presentation-hierarchies-react/itwinui/FlatTreeNode.js";
|
|
10
10
|
export { LocalizationContextProvider } from "./presentation-hierarchies-react/itwinui/LocalizationContext.js";
|
|
11
|
-
export { GenericInstanceFilter, HierarchyNode, HierarchyProvider } from "@itwin/presentation-hierarchies";
|
|
11
|
+
export { GenericInstanceFilter, HierarchyNode, HierarchyProvider, getLogger, setLogger } from "@itwin/presentation-hierarchies";
|
|
12
12
|
export { SelectionStorage } from "@itwin/unified-selection";
|
|
13
13
|
//# sourceMappingURL=presentation-hierarchies-react.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presentation-hierarchies-react.d.ts","sourceRoot":"","sources":["../../src/presentation-hierarchies-react.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,2BAA2B,EAC3B,yBAAyB,EACzB,oBAAoB,EACpB,qCAAqC,EACrC,oBAAoB,EACpB,2BAA2B,GAC5B,MAAM,8CAA8C,CAAC;AACtD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"presentation-hierarchies-react.d.ts","sourceRoot":"","sources":["../../src/presentation-hierarchies-react.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,2BAA2B,EAC3B,yBAAyB,EACzB,oBAAoB,EACpB,qCAAqC,EACrC,oBAAoB,EACpB,2BAA2B,GAC5B,MAAM,8CAA8C,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yDAAyD,CAAC;AAC9F,OAAO,EAAE,qBAAqB,EAAE,OAAO,EAAE,uBAAuB,EAAE,MAAM,6CAA6C,CAAC;AACtH,OAAO,EAAE,aAAa,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAC;AACjH,OAAO,EAAE,gBAAgB,EAAE,MAAM,8DAA8D,CAAC;AAChG,OAAO,EAAE,YAAY,EAAE,MAAM,0DAA0D,CAAC;AACxF,OAAO,EAAE,YAAY,EAAE,MAAM,0DAA0D,CAAC;AACxF,OAAO,EAAE,iBAAiB,EAAE,MAAM,+DAA+D,CAAC;AAClG,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,0DAA0D,CAAC;AAC3H,OAAO,EAAE,2BAA2B,EAAE,MAAM,iEAAiE,CAAC;AAE9G,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,iBAAiB,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAChI,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
export { isPresentationHierarchyNode, } from "./presentation-hierarchies-react/TreeNode.js";
|
|
6
|
-
export { UnifiedSelectionProvider } from "./presentation-hierarchies-react/UnifiedSelectionContext.js";
|
|
7
6
|
export { useSelectionHandler } from "./presentation-hierarchies-react/UseSelectionHandler.js";
|
|
8
7
|
export { useTree, useUnifiedSelectionTree } from "./presentation-hierarchies-react/UseTree.js";
|
|
9
8
|
export { useIModelTree, useIModelUnifiedSelectionTree } from "./presentation-hierarchies-react/UseIModelTree.js";
|
|
10
9
|
export { TreeNodeRenderer } from "./presentation-hierarchies-react/itwinui/TreeNodeRenderer.js";
|
|
11
|
-
export {
|
|
10
|
+
export { FilterAction } from "./presentation-hierarchies-react/itwinui/FilterAction.js";
|
|
12
11
|
export { TreeRenderer } from "./presentation-hierarchies-react/itwinui/TreeRenderer.js";
|
|
13
|
-
export {
|
|
12
|
+
export { TreeErrorRenderer } from "./presentation-hierarchies-react/itwinui/TreeErrorRenderer.js";
|
|
13
|
+
export { useFlatTreeNodeList, useErrorList } from "./presentation-hierarchies-react/itwinui/FlatTreeNode.js";
|
|
14
14
|
export { LocalizationContextProvider } from "./presentation-hierarchies-react/itwinui/LocalizationContext.js";
|
|
15
|
-
export { GenericInstanceFilter, HierarchyNode } from "@itwin/presentation-hierarchies";
|
|
15
|
+
export { GenericInstanceFilter, HierarchyNode, getLogger, setLogger } from "@itwin/presentation-hierarchies";
|
|
16
16
|
//# sourceMappingURL=presentation-hierarchies-react.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presentation-hierarchies-react.js","sourceRoot":"","sources":["../../src/presentation-hierarchies-react.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAML,2BAA2B,GAC5B,MAAM,8CAA8C,CAAC;AACtD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"presentation-hierarchies-react.js","sourceRoot":"","sources":["../../src/presentation-hierarchies-react.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAML,2BAA2B,GAC5B,MAAM,8CAA8C,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,yDAAyD,CAAC;AAC9F,OAAO,EAAyB,OAAO,EAAE,uBAAuB,EAAE,MAAM,6CAA6C,CAAC;AACtH,OAAO,EAAE,aAAa,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAC;AACjH,OAAO,EAAE,gBAAgB,EAAE,MAAM,8DAA8D,CAAC;AAChG,OAAO,EAAE,YAAY,EAAE,MAAM,0DAA0D,CAAC;AACxF,OAAO,EAAE,YAAY,EAAE,MAAM,0DAA0D,CAAC;AACxF,OAAO,EAAE,iBAAiB,EAAE,MAAM,+DAA+D,CAAC;AAClG,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAgB,MAAM,0DAA0D,CAAC;AAC3H,OAAO,EAAE,2BAA2B,EAAE,MAAM,iEAAiE,CAAC;AAE9G,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 {\n PresentationGenericInfoNode,\n PresentationHierarchyNode,\n PresentationInfoNode,\n PresentationResultSetTooLargeInfoNode,\n PresentationTreeNode,\n isPresentationHierarchyNode,\n} from \"./presentation-hierarchies-react/TreeNode.js\";\nexport { useSelectionHandler } from \"./presentation-hierarchies-react/UseSelectionHandler.js\";\nexport { HierarchyLevelDetails, useTree, useUnifiedSelectionTree } from \"./presentation-hierarchies-react/UseTree.js\";\nexport { useIModelTree, useIModelUnifiedSelectionTree } from \"./presentation-hierarchies-react/UseIModelTree.js\";\nexport { TreeNodeRenderer } from \"./presentation-hierarchies-react/itwinui/TreeNodeRenderer.js\";\nexport { FilterAction } from \"./presentation-hierarchies-react/itwinui/FilterAction.js\";\nexport { TreeRenderer } from \"./presentation-hierarchies-react/itwinui/TreeRenderer.js\";\nexport { TreeErrorRenderer } from \"./presentation-hierarchies-react/itwinui/TreeErrorRenderer.js\";\nexport { useFlatTreeNodeList, useErrorList, FlatTreeNode } from \"./presentation-hierarchies-react/itwinui/FlatTreeNode.js\";\nexport { LocalizationContextProvider } from \"./presentation-hierarchies-react/itwinui/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.16",
|
|
4
4
|
"description": "React components based on `@itwin/presentation-hierarchies`",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -44,13 +44,13 @@
|
|
|
44
44
|
"immer": "^10.1.1",
|
|
45
45
|
"react-error-boundary": "^4.0.13",
|
|
46
46
|
"rxjs": "^7.8.1",
|
|
47
|
-
"@itwin/presentation-shared": "^1.2.1",
|
|
48
47
|
"@itwin/presentation-hierarchies": "^1.4.2",
|
|
48
|
+
"@itwin/presentation-shared": "^1.2.1",
|
|
49
49
|
"@itwin/unified-selection": "^1.4.1"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"@itwin/itwinui-icons": "5.0.0-alpha.
|
|
53
|
-
"@itwin/itwinui-react": "5.0.0-alpha.
|
|
52
|
+
"@itwin/itwinui-icons": "5.0.0-alpha.7",
|
|
53
|
+
"@itwin/itwinui-react": "5.0.0-alpha.14",
|
|
54
54
|
"react": "^17.0.0 || ^18.0.0",
|
|
55
55
|
"react-dom": "^17.0.0 || ^18.0.0"
|
|
56
56
|
},
|
|
@@ -65,8 +65,8 @@
|
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@itwin/build-tools": "5.0.0-dev.67",
|
|
67
67
|
"@itwin/eslint-plugin": "5.0.0-dev.1",
|
|
68
|
-
"@itwin/itwinui-icons": "5.0.0-alpha.
|
|
69
|
-
"@itwin/itwinui-react": "5.0.0-alpha.
|
|
68
|
+
"@itwin/itwinui-icons": "5.0.0-alpha.7",
|
|
69
|
+
"@itwin/itwinui-react": "5.0.0-alpha.14",
|
|
70
70
|
"@testing-library/dom": "^10.4.0",
|
|
71
71
|
"@testing-library/react": "^16.2.0",
|
|
72
72
|
"@testing-library/user-event": "^14.6.1",
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { PropsWithChildren } from "react";
|
|
2
|
-
import { SelectionStorage } from "@itwin/unified-selection";
|
|
3
|
-
/**
|
|
4
|
-
* A React context provider that makes given selection storage available to all child components. This
|
|
5
|
-
* is a requirement for `useUnifiedSelectionTree` to work with unified selection.
|
|
6
|
-
*
|
|
7
|
-
* @public
|
|
8
|
-
* @deprecated in 1.5.0. Use `UnifiedSelectionContextProvider` from `@itwin/unified-selection-react` instead.
|
|
9
|
-
*/
|
|
10
|
-
export declare function UnifiedSelectionProvider({ storage, children }: PropsWithChildren<{
|
|
11
|
-
storage: SelectionStorage;
|
|
12
|
-
}>): import("react/jsx-runtime").JSX.Element;
|
|
13
|
-
/** @internal */
|
|
14
|
-
export declare function useUnifiedSelectionStorage(): SelectionStorage | undefined;
|
|
15
|
-
//# sourceMappingURL=UnifiedSelectionContext.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"UnifiedSelectionContext.d.ts","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UnifiedSelectionContext.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAiB,iBAAiB,EAAc,MAAM,OAAO,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAI5D;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,iBAAiB,CAAC;IAAE,OAAO,EAAE,gBAAgB,CAAA;CAAE,CAAC,2CAE/G;AAED,gBAAgB;AAChB,wBAAgB,0BAA0B,iCAEzC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
/*---------------------------------------------------------------------------------------------
|
|
3
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
-
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
import { createContext, useContext } from "react";
|
|
7
|
-
const deprecatedUnifiedSelectionContext = createContext(undefined);
|
|
8
|
-
/**
|
|
9
|
-
* A React context provider that makes given selection storage available to all child components. This
|
|
10
|
-
* is a requirement for `useUnifiedSelectionTree` to work with unified selection.
|
|
11
|
-
*
|
|
12
|
-
* @public
|
|
13
|
-
* @deprecated in 1.5.0. Use `UnifiedSelectionContextProvider` from `@itwin/unified-selection-react` instead.
|
|
14
|
-
*/
|
|
15
|
-
export function UnifiedSelectionProvider({ storage, children }) {
|
|
16
|
-
return _jsx(deprecatedUnifiedSelectionContext.Provider, { value: storage, children: children });
|
|
17
|
-
}
|
|
18
|
-
/** @internal */
|
|
19
|
-
export function useUnifiedSelectionStorage() {
|
|
20
|
-
return useContext(deprecatedUnifiedSelectionContext);
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=UnifiedSelectionContext.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"UnifiedSelectionContext.js","sourceRoot":"","sources":["../../../src/presentation-hierarchies-react/UnifiedSelectionContext.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,aAAa,EAAqB,UAAU,EAAE,MAAM,OAAO,CAAC;AAGrE,MAAM,iCAAiC,GAAG,aAAa,CAA+B,SAAS,CAAC,CAAC;AAEjG;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAoD;IAC9G,OAAO,KAAC,iCAAiC,CAAC,QAAQ,IAAC,KAAK,EAAE,OAAO,YAAG,QAAQ,GAA8C,CAAC;AAC7H,CAAC;AAED,gBAAgB;AAChB,MAAM,UAAU,0BAA0B;IACxC,OAAO,UAAU,CAAC,iCAAiC,CAAC,CAAC;AACvD,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { createContext, PropsWithChildren, useContext } from \"react\";\nimport { SelectionStorage } from \"@itwin/unified-selection\";\n\nconst deprecatedUnifiedSelectionContext = createContext<SelectionStorage | undefined>(undefined);\n\n/**\n * A React context provider that makes given selection storage available to all child components. This\n * is a requirement for `useUnifiedSelectionTree` to work with unified selection.\n *\n * @public\n * @deprecated in 1.5.0. Use `UnifiedSelectionContextProvider` from `@itwin/unified-selection-react` instead.\n */\nexport function UnifiedSelectionProvider({ storage, children }: PropsWithChildren<{ storage: SelectionStorage }>) {\n return <deprecatedUnifiedSelectionContext.Provider value={storage}>{children}</deprecatedUnifiedSelectionContext.Provider>;\n}\n\n/** @internal */\nexport function useUnifiedSelectionStorage() {\n return useContext(deprecatedUnifiedSelectionContext);\n}\n"]}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { PresentationHierarchyNode } from "../TreeNode.js";
|
|
2
|
-
import { HierarchyLevelDetails, useTree } from "../UseTree.js";
|
|
3
|
-
/** @alpha */
|
|
4
|
-
export interface TreeItemAction {
|
|
5
|
-
label: string;
|
|
6
|
-
action: () => void;
|
|
7
|
-
icon: string;
|
|
8
|
-
/**
|
|
9
|
-
* Determines action items visibility:
|
|
10
|
-
* - `False` - action item is hidden.
|
|
11
|
-
* - `True` - action item is visible at all times.
|
|
12
|
-
* - `Undefined` - action item is visible on hover/focus.
|
|
13
|
-
*/
|
|
14
|
-
show?: boolean;
|
|
15
|
-
/**
|
|
16
|
-
* Provide a value when action button is in active state to display a dot above the button.
|
|
17
|
-
* Provided text value is used to set accessible description it should descibe why the action is in active state.
|
|
18
|
-
* If left undefined the action item will be rendered normally.
|
|
19
|
-
*/
|
|
20
|
-
activeDescription?: string;
|
|
21
|
-
}
|
|
22
|
-
/** @alpha */
|
|
23
|
-
export type FilterActionProps = {
|
|
24
|
-
/** Action to perform when the filter button is clicked for this node. */
|
|
25
|
-
onFilter?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;
|
|
26
|
-
} & Partial<Pick<ReturnType<typeof useTree>, "getHierarchyLevelDetails">>;
|
|
27
|
-
/** @internal */
|
|
28
|
-
export declare function TreeActionButton({ show, label, action, icon, activeDescription }: TreeItemAction): import("react/jsx-runtime").JSX.Element;
|
|
29
|
-
/** @alpha */
|
|
30
|
-
export declare function useFilterAction({ onFilter, getHierarchyLevelDetails }: FilterActionProps): (node: PresentationHierarchyNode) => TreeItemAction;
|
|
31
|
-
//# sourceMappingURL=TreeActionButton.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TreeActionButton.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeActionButton.tsx"],"names":[],"mappings":"AAOA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAK/D,aAAa;AACb,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED,aAAa;AACb,MAAM,MAAM,iBAAiB,GAAG;IAC9B,yEAAyE;IACzE,QAAQ,CAAC,EAAE,CAAC,qBAAqB,EAAE,qBAAqB,KAAK,IAAI,CAAC;CACnE,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,0BAA0B,CAAC,CAAC,CAAC;AAE1E,gBAAgB;AAChB,wBAAgB,gBAAgB,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,EAAE,EAAE,cAAc,2CAEhG;AAED,aAAa;AACb,wBAAgB,eAAe,CAAC,EAAE,QAAQ,EAAE,wBAAwB,EAAE,EAAE,iBAAiB,GAAG,CAAC,IAAI,EAAE,yBAAyB,KAAK,cAAc,CA4B9I"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
/*---------------------------------------------------------------------------------------------
|
|
3
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
-
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
import { useCallback } from "react";
|
|
7
|
-
import { Tree } from "@itwin/itwinui-react/bricks";
|
|
8
|
-
import { useLocalizationContext } from "./LocalizationContext.js";
|
|
9
|
-
const filterSvg = new URL("@itwin/itwinui-icons/filter.svg", import.meta.url).href;
|
|
10
|
-
/** @internal */
|
|
11
|
-
export function TreeActionButton({ show, label, action, icon, activeDescription }) {
|
|
12
|
-
return _jsx(Tree.ItemAction, { label: label, dot: activeDescription, icon: icon, visible: show, onClick: action });
|
|
13
|
-
}
|
|
14
|
-
/** @alpha */
|
|
15
|
-
export function useFilterAction({ onFilter, getHierarchyLevelDetails }) {
|
|
16
|
-
const { localizedStrings } = useLocalizationContext();
|
|
17
|
-
const { filterHierarchyLevel, filterHierarchyLevelActiveDescription } = localizedStrings;
|
|
18
|
-
return useCallback((node) => {
|
|
19
|
-
const handleVisibility = () => {
|
|
20
|
-
if (!onFilter || !node.isFilterable) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
if (node.isFiltered) {
|
|
24
|
-
return true;
|
|
25
|
-
}
|
|
26
|
-
return undefined;
|
|
27
|
-
};
|
|
28
|
-
return {
|
|
29
|
-
label: filterHierarchyLevel,
|
|
30
|
-
action: () => {
|
|
31
|
-
const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.id);
|
|
32
|
-
hierarchyLevelDetails && onFilter?.(hierarchyLevelDetails);
|
|
33
|
-
},
|
|
34
|
-
show: handleVisibility(),
|
|
35
|
-
activeDescription: node.isFiltered ? filterHierarchyLevelActiveDescription : undefined,
|
|
36
|
-
icon: filterSvg,
|
|
37
|
-
};
|
|
38
|
-
}, [filterHierarchyLevel, filterHierarchyLevelActiveDescription, onFilter, getHierarchyLevelDetails]);
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=TreeActionButton.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TreeActionButton.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeActionButton.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAGnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,iCAAiC,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;AA4BnF,gBAAgB;AAChB,MAAM,UAAU,gBAAgB,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,EAAkB;IAC/F,OAAO,KAAC,IAAI,CAAC,UAAU,IAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,iBAAiB,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,GAAI,CAAC;AAC/G,CAAC;AAED,aAAa;AACb,MAAM,UAAU,eAAe,CAAC,EAAE,QAAQ,EAAE,wBAAwB,EAAqB;IACvF,MAAM,EAAE,gBAAgB,EAAE,GAAG,sBAAsB,EAAE,CAAC;IACtD,MAAM,EAAE,oBAAoB,EAAE,qCAAqC,EAAE,GAAG,gBAAgB,CAAC;IACzF,OAAO,WAAW,CAChB,CAAC,IAAI,EAAE,EAAE;QACP,MAAM,gBAAgB,GAAG,GAAG,EAAE;YAC5B,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;gBACpC,OAAO,KAAK,CAAC;YACf,CAAC;YACD,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBACpB,OAAO,IAAI,CAAC;YACd,CAAC;YACD,OAAO,SAAS,CAAC;QACnB,CAAC,CAAC;QAEF,OAAO;YACL,KAAK,EAAE,oBAAoB;YAC3B,MAAM,EAAE,GAAG,EAAE;gBACX,MAAM,qBAAqB,GAAG,wBAAwB,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBAClE,qBAAqB,IAAI,QAAQ,EAAE,CAAC,qBAAqB,CAAC,CAAC;YAC7D,CAAC;YACD,IAAI,EAAE,gBAAgB,EAAE;YACxB,iBAAiB,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,qCAAqC,CAAC,CAAC,CAAC,SAAS;YACtF,IAAI,EAAE,SAAS;SAChB,CAAC;IACJ,CAAC,EACD,CAAC,oBAAoB,EAAE,qCAAqC,EAAE,QAAQ,EAAE,wBAAwB,CAAC,CAClG,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 { Tree } from \"@itwin/itwinui-react/bricks\";\nimport { PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { HierarchyLevelDetails, useTree } from \"../UseTree.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\n\nconst filterSvg = new URL(\"@itwin/itwinui-icons/filter.svg\", import.meta.url).href;\n\n/** @alpha */\nexport interface TreeItemAction {\n label: string;\n action: () => void;\n icon: string;\n /**\n * Determines action items visibility:\n * - `False` - action item is hidden.\n * - `True` - action item is visible at all times.\n * - `Undefined` - action item is visible on hover/focus.\n */\n show?: boolean;\n /**\n * Provide a value when action button is in active state to display a dot above the button.\n * Provided text value is used to set accessible description it should descibe why the action is in active state.\n * If left undefined the action item will be rendered normally.\n */\n activeDescription?: string;\n}\n\n/** @alpha */\nexport type FilterActionProps = {\n /** Action to perform when the filter button is clicked for this node. */\n onFilter?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;\n} & Partial<Pick<ReturnType<typeof useTree>, \"getHierarchyLevelDetails\">>;\n\n/** @internal */\nexport function TreeActionButton({ show, label, action, icon, activeDescription }: TreeItemAction) {\n return <Tree.ItemAction label={label} dot={activeDescription} icon={icon} visible={show} onClick={action} />;\n}\n\n/** @alpha */\nexport function useFilterAction({ onFilter, getHierarchyLevelDetails }: FilterActionProps): (node: PresentationHierarchyNode) => TreeItemAction {\n const { localizedStrings } = useLocalizationContext();\n const { filterHierarchyLevel, filterHierarchyLevelActiveDescription } = localizedStrings;\n return useCallback(\n (node) => {\n const handleVisibility = () => {\n if (!onFilter || !node.isFilterable) {\n return false;\n }\n if (node.isFiltered) {\n return true;\n }\n return undefined;\n };\n\n return {\n label: filterHierarchyLevel,\n action: () => {\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.id);\n hierarchyLevelDetails && onFilter?.(hierarchyLevelDetails);\n },\n show: handleVisibility(),\n activeDescription: node.isFiltered ? filterHierarchyLevelActiveDescription : undefined,\n icon: filterSvg,\n };\n },\n [filterHierarchyLevel, filterHierarchyLevelActiveDescription, onFilter, getHierarchyLevelDetails],\n );\n}\n"]}
|