@itwin/presentation-hierarchies-react 2.0.0-alpha.2 → 2.0.0-alpha.20
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 +313 -0
- package/README.md +24 -24
- 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/UseSelectionHandler.js +1 -1
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.js +1 -8
- package/lib/esm/presentation-hierarchies-react/UseTree.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/Utils.d.ts +5 -0
- package/lib/esm/presentation-hierarchies-react/Utils.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/Utils.js +23 -0
- package/lib/esm/presentation-hierarchies-react/Utils.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/internal/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/stratakit/FilterAction.d.ts +18 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FilterAction.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FilterAction.js +32 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FilterAction.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts +57 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.js +78 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/{itwinui → stratakit}/LocalizationContext.d.ts +37 -7
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/{itwinui → stratakit}/LocalizationContext.js +11 -5
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts +16 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.js +42 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts +43 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js +70 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts +45 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js +63 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts +36 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js +106 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react.d.ts +7 -7
- package/lib/esm/presentation-hierarchies-react.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react.js +7 -7
- package/lib/esm/presentation-hierarchies-react.js.map +1 -1
- package/package.json +46 -38
- 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/LocalizationContext.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButtons.d.ts +0 -12
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButtons.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButtons.js +0 -19
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButtons.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.d.ts +0 -12
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.js +0 -72
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeLevelRenderer.d.ts +0 -12
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeLevelRenderer.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeLevelRenderer.js +0 -10
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeLevelRenderer.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.d.ts +0 -42
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js +0 -56
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.d.ts +0 -30
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.js +0 -22
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.js.map +0 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { useTree } from "../UseTree.js";
|
|
2
|
+
import { ErrorNode } from "./FlatTreeNode.js";
|
|
3
|
+
/**
|
|
4
|
+
* @alpha
|
|
5
|
+
*/
|
|
6
|
+
export type RootErrorRendererProps = {
|
|
7
|
+
/** Root error to be displayed */
|
|
8
|
+
errorNode: ErrorNode;
|
|
9
|
+
} & Pick<ReturnType<typeof useTree>, "getHierarchyLevelDetails" | "reloadTree">;
|
|
10
|
+
/**
|
|
11
|
+
* A component that renders root node error state.
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export declare function RootErrorRenderer({ errorNode, getHierarchyLevelDetails, reloadTree }: RootErrorRendererProps): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
//# sourceMappingURL=RootErrorRenderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RootErrorRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/RootErrorRenderer.tsx"],"names":[],"mappings":"AAQA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG9C;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,iCAAiC;IACjC,SAAS,EAAE,SAAS,CAAC;CACtB,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,0BAA0B,GAAG,YAAY,CAAC,CAAC;AAEhF;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,SAAS,EAAE,wBAAwB,EAAE,UAAU,EAAE,EAAE,sBAAsB,2CA+B5G"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } 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 { Button, Text } from "@stratakit/bricks";
|
|
7
|
+
import { Icon } from "@stratakit/foundations";
|
|
8
|
+
import errorSvg from "@stratakit/icons/status-error.svg";
|
|
9
|
+
import { useLocalizationContext } from "./LocalizationContext.js";
|
|
10
|
+
/**
|
|
11
|
+
* A component that renders root node error state.
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export function RootErrorRenderer({ errorNode, getHierarchyLevelDetails, reloadTree }) {
|
|
16
|
+
const { localizedStrings } = useLocalizationContext();
|
|
17
|
+
if (errorNode.error.type === "ResultSetTooLarge") {
|
|
18
|
+
const onOverrideLimit = () => getHierarchyLevelDetails(undefined)?.setSizeLimit("unbounded");
|
|
19
|
+
return (_jsx(RootErrorContainer, { message: localizedStrings.rootResultLimitExceeded.replace("{{limit}}", errorNode.error.resultSetSizeLimit.toString()), actions: [
|
|
20
|
+
{
|
|
21
|
+
action: onOverrideLimit,
|
|
22
|
+
label: localizedStrings.increaseHierarchyLimitToUnlimited,
|
|
23
|
+
condition: () => true,
|
|
24
|
+
},
|
|
25
|
+
] }));
|
|
26
|
+
}
|
|
27
|
+
return (_jsx(RootErrorContainer, { message: localizedStrings.failedToCreateRootHierarchy, actions: [
|
|
28
|
+
{
|
|
29
|
+
action: () => reloadTree({ parentNodeId: undefined, state: "reset" }),
|
|
30
|
+
label: localizedStrings.retry,
|
|
31
|
+
condition: () => true,
|
|
32
|
+
},
|
|
33
|
+
] }));
|
|
34
|
+
}
|
|
35
|
+
function RootErrorContainer({ actions, message }) {
|
|
36
|
+
return (_jsxs("div", { style: { height: "100%", display: "flex", flexDirection: "column", justifyContent: "center", alignItems: "center", gap: "0.5rem" }, children: [_jsx(Icon, { href: errorSvg, size: "large" }), _jsx(Text, { variant: "body-sm", style: { textAlign: "center" }, children: message }), actions
|
|
37
|
+
?.filter(({ condition }) => condition())
|
|
38
|
+
.map((action) => {
|
|
39
|
+
return (_jsx(Button, { onClick: () => action.action(), children: action.label }, action.label));
|
|
40
|
+
})] }));
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=RootErrorRenderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RootErrorRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/RootErrorRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,QAAQ,MAAM,mCAAmC,CAAC;AAGzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAUlE;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,EAAE,SAAS,EAAE,wBAAwB,EAAE,UAAU,EAA0B;IAC3G,MAAM,EAAE,gBAAgB,EAAE,GAAG,sBAAsB,EAAE,CAAC;IAEtD,IAAI,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,mBAAmB,EAAE,CAAC;QACjD,MAAM,eAAe,GAAG,GAAG,EAAE,CAAC,wBAAwB,CAAC,SAAS,CAAC,EAAE,YAAY,CAAC,WAAW,CAAC,CAAC;QAC7F,OAAO,CACL,KAAC,kBAAkB,IACjB,OAAO,EAAE,gBAAgB,CAAC,uBAAuB,CAAC,O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AAE,YACtD,MAAM,CAAC,KAAK,IADF,MAAM,CAAC,KAAK,CAEhB,CACV,CAAC;YACJ,CAAC,CAAC,IACA,CACP,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 { Button, Text } from \"@stratakit/bricks\";\nimport { Icon } from \"@stratakit/foundations\";\nimport errorSvg from \"@stratakit/icons/status-error.svg\";\nimport { useTree } from \"../UseTree.js\";\nimport { ErrorNode } from \"./FlatTreeNode.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\n\n/**\n * @alpha\n */\nexport type RootErrorRendererProps = {\n /** Root error to be displayed */\n errorNode: ErrorNode;\n} & Pick<ReturnType<typeof useTree>, \"getHierarchyLevelDetails\" | \"reloadTree\">;\n\n/**\n * A component that renders root node error state.\n *\n * @internal\n */\nexport function RootErrorRenderer({ errorNode, getHierarchyLevelDetails, reloadTree }: RootErrorRendererProps) {\n const { localizedStrings } = useLocalizationContext();\n\n if (errorNode.error.type === \"ResultSetTooLarge\") {\n const onOverrideLimit = () => getHierarchyLevelDetails(undefined)?.setSizeLimit(\"unbounded\");\n return (\n <RootErrorContainer\n message={localizedStrings.rootResultLimitExceeded.replace(\"{{limit}}\", errorNode.error.resultSetSizeLimit.toString())}\n actions={[\n {\n action: onOverrideLimit,\n label: localizedStrings.increaseHierarchyLimitToUnlimited,\n condition: () => true,\n },\n ]}\n />\n );\n }\n\n return (\n <RootErrorContainer\n message={localizedStrings.failedToCreateRootHierarchy}\n actions={[\n {\n action: () => reloadTree({ parentNodeId: undefined, state: \"reset\" }),\n label: localizedStrings.retry,\n condition: () => true,\n },\n ]}\n />\n );\n}\n\ninterface RootErrorContainerProps {\n message: string;\n actions?: { action: () => void; label: string; condition: () => boolean }[];\n}\n\nfunction RootErrorContainer({ actions, message }: RootErrorContainerProps) {\n return (\n <div style={{ height: \"100%\", display: \"flex\", flexDirection: \"column\", justifyContent: \"center\", alignItems: \"center\", gap: \"0.5rem\" }}>\n <Icon href={errorSvg} size=\"large\" />\n <Text variant={\"body-sm\"} style={{ textAlign: \"center\" }}>\n {message}\n </Text>\n {actions\n ?.filter(({ condition }) => condition())\n .map((action) => {\n return (\n <Button key={action.label} onClick={() => action.action()}>\n {action.label}\n </Button>\n );\n })}\n </div>\n );\n}\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ReactElement } from "react";
|
|
2
|
+
import { HierarchyLevelDetails, useTree } from "../UseTree.js";
|
|
3
|
+
import { ErrorNode } from "./FlatTreeNode.js";
|
|
4
|
+
/**
|
|
5
|
+
* Interface containing error item related actions.
|
|
6
|
+
*
|
|
7
|
+
* @alpha
|
|
8
|
+
*/
|
|
9
|
+
interface TreeErrorItemProps {
|
|
10
|
+
/** A callback to reload a hierarchy level when an error occurs and `retry` button is clicked. */
|
|
11
|
+
reloadTree: (options: {
|
|
12
|
+
parentNodeId: string | undefined;
|
|
13
|
+
state: "reset";
|
|
14
|
+
}) => void;
|
|
15
|
+
/** Action to perform when the filter button is clicked for this node. */
|
|
16
|
+
onFilterClick?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;
|
|
17
|
+
/** Action to perform when an error accurs and node label is clicked in the error message */
|
|
18
|
+
scrollToElement: (errorNode: ErrorNode) => void;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Interface containing building blocks for `TreeErrorRenderer`.
|
|
22
|
+
*
|
|
23
|
+
* @alpha
|
|
24
|
+
*/
|
|
25
|
+
interface TreeErrorRendererOwnProps {
|
|
26
|
+
/** List of errors to be displayed */
|
|
27
|
+
errorList: ErrorNode[];
|
|
28
|
+
renderError?: ({ errorNode, scrollToElement }: {
|
|
29
|
+
errorNode: ErrorNode;
|
|
30
|
+
scrollToElement: () => void;
|
|
31
|
+
}) => ReactElement;
|
|
32
|
+
}
|
|
33
|
+
/** @alpha */
|
|
34
|
+
export type TreeErrorRendererProps = TreeErrorRendererOwnProps & TreeErrorItemProps & Partial<Pick<ReturnType<typeof useTree>, "getHierarchyLevelDetails">>;
|
|
35
|
+
/**
|
|
36
|
+
* A component that renders error display dropdown using the `unstable_ErrorRegion` component from `@itwin/itwinui-react`.
|
|
37
|
+
* As input, the component uses a list of `ErrorNode` objects, which are generally created using the `useErrorList` hook.
|
|
38
|
+
*
|
|
39
|
+
* @alpha
|
|
40
|
+
*/
|
|
41
|
+
export declare function TreeErrorRenderer({ errorList, reloadTree, scrollToElement, getHierarchyLevelDetails, onFilterClick, renderError }: TreeErrorRendererProps): import("react/jsx-runtime").JSX.Element;
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=TreeErrorRenderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreeErrorRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/TreeErrorRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAIrC,OAAO,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG9C;;;;GAIG;AACH,UAAU,kBAAkB;IAC1B,iGAAiG;IACjG,UAAU,EAAE,CAAC,OAAO,EAAE;QAAE,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;IACpF,yEAAyE;IACzE,aAAa,CAAC,EAAE,CAAC,qBAAqB,EAAE,qBAAqB,KAAK,IAAI,CAAC;IACvE,4FAA4F;IAC5F,eAAe,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,CAAC;CACjD;AACD;;;;GAIG;AACH,UAAU,yBAAyB;IACjC,qCAAqC;IACrC,SAAS,EAAE,SAAS,EAAE,CAAC;IAEvB,WAAW,CAAC,EAAE,CAAC,EAAE,SAAS,EAAE,eAAe,EAAE,EAAE;QAAE,SAAS,EAAE,SAAS,CAAC;QAAC,eAAe,EAAE,MAAM,IAAI,CAAA;KAAE,KAAK,YAAY,CAAC;CACvH;AAED,aAAa;AACb,MAAM,MAAM,sBAAsB,GAAG,yBAAyB,GAAG,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,0BAA0B,CAAC,CAAC,CAAC;AAE5J;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe,EAAE,wBAAwB,EAAE,aAAa,EAAE,WAAW,EAAE,EAAE,sBAAsB,2CAgFzJ"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Anchor, Text } from "@stratakit/bricks";
|
|
3
|
+
import { unstable_ErrorRegion as ErrorRegion } from "@stratakit/structures";
|
|
4
|
+
import { MAX_LIMIT_OVERRIDE } from "../internal/Utils.js";
|
|
5
|
+
import { useLocalizationContext } from "./LocalizationContext.js";
|
|
6
|
+
/**
|
|
7
|
+
* A component that renders error display dropdown using the `unstable_ErrorRegion` component from `@itwin/itwinui-react`.
|
|
8
|
+
* As input, the component uses a list of `ErrorNode` objects, which are generally created using the `useErrorList` hook.
|
|
9
|
+
*
|
|
10
|
+
* @alpha
|
|
11
|
+
*/
|
|
12
|
+
export function TreeErrorRenderer({ errorList, reloadTree, scrollToElement, getHierarchyLevelDetails, onFilterClick, renderError }) {
|
|
13
|
+
const { localizedStrings } = useLocalizationContext();
|
|
14
|
+
const errorItems = errorList.map((errorNode) => {
|
|
15
|
+
if (renderError) {
|
|
16
|
+
return renderError({ errorNode, scrollToElement: () => scrollToElement(errorNode) });
|
|
17
|
+
}
|
|
18
|
+
if (errorNode.error.type === "ResultSetTooLarge") {
|
|
19
|
+
const limit = errorNode.error.resultSetSizeLimit;
|
|
20
|
+
const onOverrideLimit = getHierarchyLevelDetails ? () => getHierarchyLevelDetails(errorNode.parent?.id)?.setSizeLimit(MAX_LIMIT_OVERRIDE) : undefined;
|
|
21
|
+
return (_jsx(ErrorItemContainer, { errorNode: errorNode, actions: [
|
|
22
|
+
{
|
|
23
|
+
action: () => {
|
|
24
|
+
onOverrideLimit?.();
|
|
25
|
+
},
|
|
26
|
+
label: localizedStrings.increaseHierarchyLimit.replace("{{limit}}", MAX_LIMIT_OVERRIDE.toString()),
|
|
27
|
+
condition: () => !!onOverrideLimit && limit < MAX_LIMIT_OVERRIDE,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
action: () => {
|
|
31
|
+
const hierarchyLevelDetails = getHierarchyLevelDetails?.(errorNode.parent?.id);
|
|
32
|
+
hierarchyLevelDetails && onFilterClick?.(hierarchyLevelDetails);
|
|
33
|
+
},
|
|
34
|
+
label: localizedStrings.increaseHierarchyLimitWithFiltering,
|
|
35
|
+
condition: () => !!onFilterClick && !!errorNode.parent?.isFilterable,
|
|
36
|
+
},
|
|
37
|
+
], message: localizedStrings.resultLimitExceeded.replace("{{limit}}", limit.toString()), scrollToElement: () => scrollToElement(errorNode) }, errorNode.error.id));
|
|
38
|
+
}
|
|
39
|
+
if (errorNode.error.type === "NoFilterMatches") {
|
|
40
|
+
return (_jsx(ErrorItemContainer, { errorNode: errorNode, actions: [
|
|
41
|
+
{
|
|
42
|
+
action: () => {
|
|
43
|
+
const hierarchyLevelDetails = getHierarchyLevelDetails?.(errorNode.parent?.id);
|
|
44
|
+
hierarchyLevelDetails && onFilterClick?.(hierarchyLevelDetails);
|
|
45
|
+
},
|
|
46
|
+
label: localizedStrings.noFilteredChildrenChangeFilter,
|
|
47
|
+
condition: () => true,
|
|
48
|
+
},
|
|
49
|
+
], message: localizedStrings.noFilteredChildren, scrollToElement: () => scrollToElement(errorNode) }, errorNode.error.id));
|
|
50
|
+
}
|
|
51
|
+
return (_jsx(ErrorItemContainer, { errorNode: errorNode, actions: [
|
|
52
|
+
{
|
|
53
|
+
action: () => reloadTree({ parentNodeId: errorNode.parent?.id, state: "reset" }),
|
|
54
|
+
label: localizedStrings.retry,
|
|
55
|
+
condition: () => true,
|
|
56
|
+
},
|
|
57
|
+
], message: localizedStrings.failedToCreateHierarchy, scrollToElement: () => scrollToElement(errorNode) }, errorNode.error.id));
|
|
58
|
+
});
|
|
59
|
+
return (_jsx(ErrorRegion.Root, { style: { width: "100%" }, label: errorList.length !== 0 ? `${errorList.length} ${localizedStrings?.issuesFound}` : undefined, items: errorItems }));
|
|
60
|
+
}
|
|
61
|
+
function ErrorItemContainer({ errorNode, message, actions, scrollToElement }) {
|
|
62
|
+
return (_jsx(ErrorRegion.Item, { message: _jsx(MessageWithLink, { linkLabel: errorNode.parent?.label, scrollToElement: scrollToElement, message: message }), messageId: errorNode.error.id, actions: _jsx("div", { style: { display: "flex", flexDirection: "column" }, children: actions
|
|
63
|
+
?.filter(({ condition }) => condition())
|
|
64
|
+
.map(({ label, action }) => (_jsx(Anchor, { onClick: action, children: label }, label))) }) }));
|
|
65
|
+
}
|
|
66
|
+
function MessageWithLink({ linkLabel, scrollToElement, message }) {
|
|
67
|
+
const splitMessage = message.split("{{node}}", 2);
|
|
68
|
+
return (_jsxs("div", { style: { display: "flex", whiteSpace: "pre", flexWrap: "wrap" }, children: [_jsx(Text, { variant: "body-sm", children: splitMessage[0] }), _jsx(Anchor, { onClick: scrollToElement, children: linkLabel }), splitMessage[1] ? _jsx(Text, { variant: "body-sm", children: splitMessage[1] }) : null] }));
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=TreeErrorRenderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreeErrorRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/TreeErrorRenderer.tsx"],"names":[],"mappings":";AAMA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,mBAAmB,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AE,CAAC,SAAS,EAAE,CAAC;iBACvC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAC1B,KAAC,MAAM,IAAa,OAAO,EAAE,MAAM,YAChC,KAAK,IADK,KAAK,CAET,CACV,CAAC,GACA,GAER,CACH,CAAC;AACJ,CAAC;AAQD,SAAS,eAAe,CAAC,EAAE,SAAS,EAAE,eAAe,EAAE,OAAO,EAAwB;IACpF,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IAClD,OAAO,CACL,eAAK,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,aAClE,KAAC,IAAI,IAAC,OAAO,EAAE,SAAS,YAAG,YAAY,CAAC,CAAC,CAAC,GAAQ,EAClD,KAAC,MAAM,IAAC,OAAO,EAAE,eAAe,YAAG,SAAS,GAAU,EACrD,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAC,IAAI,IAAC,OAAO,EAAE,SAAS,YAAG,YAAY,CAAC,CAAC,CAAC,GAAQ,CAAC,CAAC,CAAC,IAAI,IACxE,CACP,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 { ReactElement } from \"react\";\nimport { Anchor, Text } from \"@stratakit/bricks\";\nimport { unstable_ErrorRegion as ErrorRegion } from \"@stratakit/structures\";\nimport { MAX_LIMIT_OVERRIDE } from \"../internal/Utils.js\";\nimport { HierarchyLevelDetails, useTree } from \"../UseTree.js\";\nimport { ErrorNode } from \"./FlatTreeNode.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\n\n/**\n * Interface containing error item related actions.\n *\n * @alpha\n */\ninterface TreeErrorItemProps {\n /** A callback to reload a hierarchy level when an error occurs and `retry` button is clicked. */\n reloadTree: (options: { parentNodeId: string | undefined; state: \"reset\" }) => void;\n /** Action to perform when the filter button is clicked for this node. */\n onFilterClick?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;\n /** Action to perform when an error accurs and node label is clicked in the error message */\n scrollToElement: (errorNode: ErrorNode) => void;\n}\n/**\n * Interface containing building blocks for `TreeErrorRenderer`.\n *\n * @alpha\n */\ninterface TreeErrorRendererOwnProps {\n /** List of errors to be displayed */\n errorList: ErrorNode[];\n // Callback to render custom error messages. Component should be wrapped in `ErrorRegion.Item` from `@itwin/itwinui-react` package.\n renderError?: ({ errorNode, scrollToElement }: { errorNode: ErrorNode; scrollToElement: () => void }) => ReactElement;\n}\n\n/** @alpha */\nexport type TreeErrorRendererProps = TreeErrorRendererOwnProps & TreeErrorItemProps & Partial<Pick<ReturnType<typeof useTree>, \"getHierarchyLevelDetails\">>;\n\n/**\n * A component that renders error display dropdown using the `unstable_ErrorRegion` component from `@itwin/itwinui-react`.\n * As input, the component uses a list of `ErrorNode` objects, which are generally created using the `useErrorList` hook.\n *\n * @alpha\n */\nexport function TreeErrorRenderer({ errorList, reloadTree, scrollToElement, getHierarchyLevelDetails, onFilterClick, renderError }: TreeErrorRendererProps) {\n const { localizedStrings } = useLocalizationContext();\n const errorItems = errorList.map((errorNode) => {\n if (renderError) {\n return renderError({ errorNode, scrollToElement: () => scrollToElement(errorNode) });\n }\n\n if (errorNode.error.type === \"ResultSetTooLarge\") {\n const limit = errorNode.error.resultSetSizeLimit;\n const onOverrideLimit = getHierarchyLevelDetails ? () => getHierarchyLevelDetails(errorNode.parent?.id)?.setSizeLimit(MAX_LIMIT_OVERRIDE) : undefined;\n return (\n <ErrorItemContainer\n key={errorNode.error.id}\n errorNode={errorNode}\n actions={[\n {\n action: () => {\n onOverrideLimit?.();\n },\n label: localizedStrings.increaseHierarchyLimit.replace(\"{{limit}}\", MAX_LIMIT_OVERRIDE.toString()),\n condition: () => !!onOverrideLimit && limit < MAX_LIMIT_OVERRIDE,\n },\n {\n action: () => {\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(errorNode.parent?.id);\n hierarchyLevelDetails && onFilterClick?.(hierarchyLevelDetails);\n },\n label: localizedStrings.increaseHierarchyLimitWithFiltering,\n condition: () => !!onFilterClick && !!errorNode.parent?.isFilterable,\n },\n ]}\n message={localizedStrings.resultLimitExceeded.replace(\"{{limit}}\", limit.toString())}\n scrollToElement={() => scrollToElement(errorNode)}\n />\n );\n }\n if (errorNode.error.type === \"NoFilterMatches\") {\n return (\n <ErrorItemContainer\n key={errorNode.error.id}\n errorNode={errorNode}\n actions={[\n {\n action: () => {\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(errorNode.parent?.id);\n hierarchyLevelDetails && onFilterClick?.(hierarchyLevelDetails);\n },\n label: localizedStrings.noFilteredChildrenChangeFilter,\n condition: () => true,\n },\n ]}\n message={localizedStrings.noFilteredChildren}\n scrollToElement={() => scrollToElement(errorNode)}\n />\n );\n }\n return (\n <ErrorItemContainer\n key={errorNode.error.id}\n errorNode={errorNode}\n actions={[\n {\n action: () => reloadTree({ parentNodeId: errorNode.parent?.id, state: \"reset\" }),\n label: localizedStrings.retry,\n condition: () => true,\n },\n ]}\n message={localizedStrings.failedToCreateHierarchy}\n scrollToElement={() => scrollToElement(errorNode)}\n />\n );\n });\n\n return (\n <ErrorRegion.Root\n style={{ width: \"100%\" }}\n label={errorList.length !== 0 ? `${errorList.length} ${localizedStrings?.issuesFound}` : undefined}\n items={errorItems}\n />\n );\n}\n\ntype ErrorItemContainerProps = {\n errorNode: ErrorNode;\n message: string;\n actions?: { action: () => void; label: string; condition: () => boolean }[];\n} & Pick<MessageWithLinkProps, \"scrollToElement\">;\n\nfunction ErrorItemContainer({ errorNode, message, actions, scrollToElement }: ErrorItemContainerProps) {\n return (\n <ErrorRegion.Item\n message={<MessageWithLink linkLabel={errorNode.parent?.label} scrollToElement={scrollToElement} message={message} />}\n messageId={errorNode.error.id}\n actions={\n <div style={{ display: \"flex\", flexDirection: \"column\" }}>\n {actions\n ?.filter(({ condition }) => condition())\n .map(({ label, action }) => (\n <Anchor key={label} onClick={action}>\n {label}\n </Anchor>\n ))}\n </div>\n }\n />\n );\n}\n\ninterface MessageWithLinkProps {\n scrollToElement: () => void;\n message: string;\n linkLabel?: string;\n}\n\nfunction MessageWithLink({ linkLabel, scrollToElement, message }: MessageWithLinkProps) {\n const splitMessage = message.split(\"{{node}}\", 2);\n return (\n <div style={{ display: \"flex\", whiteSpace: \"pre\", flexWrap: \"wrap\" }}>\n <Text variant={\"body-sm\"}>{splitMessage[0]}</Text>\n <Anchor onClick={scrollToElement}>{linkLabel}</Anchor>\n {splitMessage[1] ? <Text variant={\"body-sm\"}>{splitMessage[1]}</Text> : null}\n </div>\n );\n}\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef, FC, PropsWithRef, ReactElement, ReactNode, RefAttributes } from "react";
|
|
2
|
+
import { Tree } from "@stratakit/structures";
|
|
3
|
+
import { PresentationHierarchyNode } from "../TreeNode.js";
|
|
4
|
+
import { useTree, UseTreeResult } from "../UseTree.js";
|
|
5
|
+
import { ErrorNode } from "./FlatTreeNode.js";
|
|
6
|
+
/** @alpha */
|
|
7
|
+
type TreeNodeProps = ComponentPropsWithoutRef<typeof Tree.Item>;
|
|
8
|
+
/** @alpha */
|
|
9
|
+
export interface TreeNodeRendererOwnProps {
|
|
10
|
+
/** Node that is rendered. */
|
|
11
|
+
node: PresentationHierarchyNode;
|
|
12
|
+
/** Returns a label for a given node. */
|
|
13
|
+
getLabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;
|
|
14
|
+
/** Returns sublabel for a given node. */
|
|
15
|
+
getSublabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;
|
|
16
|
+
/** Action to perform when the node is clicked. */
|
|
17
|
+
onNodeClick?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.MouseEvent<HTMLElement>) => void;
|
|
18
|
+
/** Action to perform when a key is pressed when the node is hovered on. */
|
|
19
|
+
onNodeKeyDown?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.KeyboardEvent<HTMLElement>) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Used to render elements between expander and label.
|
|
22
|
+
* E.g. icons, color picker, etc.
|
|
23
|
+
*/
|
|
24
|
+
getDecorations?: (node: PresentationHierarchyNode) => ReactNode;
|
|
25
|
+
/**
|
|
26
|
+
* Callback that returns actions for tree item. Must return an array of `Tree.ItemAction` elements.
|
|
27
|
+
*/
|
|
28
|
+
getActions?: (node: PresentationHierarchyNode) => ReactNode[];
|
|
29
|
+
/** Specifies if tree item has error. */
|
|
30
|
+
error?: ErrorNode;
|
|
31
|
+
}
|
|
32
|
+
/** @alpha */
|
|
33
|
+
type TreeNodeRendererProps = Pick<ReturnType<typeof useTree>, "expandNode"> & Partial<Pick<ReturnType<typeof useTree>, "getHierarchyLevelDetails">> & Omit<TreeNodeProps, "actions" | "label" | "expanded" | "unstable_decorations" | "error"> & Pick<UseTreeResult, "reloadTree"> & TreeNodeRendererOwnProps;
|
|
34
|
+
/**
|
|
35
|
+
* A component that renders given `FlatTreeNode` using the `Tree.Item` component from `@itwin/itwinui-react`. The
|
|
36
|
+
* `FlatTreeNode` objects for this renderer are generally created using the `useFlatTreeNodeList` hook.
|
|
37
|
+
*
|
|
38
|
+
* @see `TreeRenderer`
|
|
39
|
+
* @see https://itwinui.bentley.com/docs/tree
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export declare const TreeNodeRenderer: FC<PropsWithRef<TreeNodeRendererProps & RefAttributes<HTMLElement>>>;
|
|
43
|
+
export declare const PlaceholderNode: FC<PropsWithRef<Omit<TreeNodeProps, "onExpanded" | "label" | "actions" | "icon" | "error"> & RefAttributes<HTMLElement>>>;
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=TreeNodeRenderer.d.ts.map
|
|
@@ -0,0 +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,EAId,MAAM,OAAO,CAAC;AAGf,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAG9C,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;IAExH;;;OAGG;IACH,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,yBAAyB,KAAK,SAAS,CAAC;IAChE;;OAEG;IACH,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,yBAAyB,KAAK,SAAS,EAAE,CAAC;IAC9D,wCAAwC;IACxC,KAAK,CAAC,EAAE,SAAS,CAAC;CACnB;AAED,aAAa;AACb,KAAK,qBAAqB,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,YAAY,CAAC,GACzE,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,0BAA0B,CAAC,CAAC,GACrE,IAAI,CAAC,aAAa,EAAE,SAAS,GAAG,OAAO,GAAG,UAAU,GAAG,sBAAsB,GAAG,OAAO,CAAC,GACxF,IAAI,CAAC,aAAa,EAAE,YAAY,CAAC,GACjC,wBAAwB,CAAC;AAE3B;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,EAAE,EAAE,CAAC,YAAY,CAAC,qBAAqB,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC,CAkEjG,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"}
|
|
@@ -0,0 +1,63 @@
|
|
|
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 { forwardRef, memo, useCallback, useMemo, useRef, } from "react";
|
|
7
|
+
import { Spinner } from "@stratakit/bricks";
|
|
8
|
+
import refreshSvg from "@stratakit/icons/refresh.svg";
|
|
9
|
+
import { Tree } from "@stratakit/structures";
|
|
10
|
+
import { useLocalizationContext } from "./LocalizationContext.js";
|
|
11
|
+
/**
|
|
12
|
+
* A component that renders given `FlatTreeNode` using the `Tree.Item` component from `@itwin/itwinui-react`. The
|
|
13
|
+
* `FlatTreeNode` objects for this renderer are generally created using the `useFlatTreeNodeList` hook.
|
|
14
|
+
*
|
|
15
|
+
* @see `TreeRenderer`
|
|
16
|
+
* @see https://itwinui.bentley.com/docs/tree
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
export const TreeNodeRenderer = memo(forwardRef(function HierarchyNode({ node, selected, error, expandNode, onNodeClick, onNodeKeyDown, reloadTree, getLabel, getSublabel, getActions, getDecorations, ...treeItemProps }, forwardedRef) {
|
|
20
|
+
const nodeRef = useRef(null);
|
|
21
|
+
const ref = useMergedRefs(forwardedRef, nodeRef);
|
|
22
|
+
const { localizedStrings } = useLocalizationContext();
|
|
23
|
+
const label = useMemo(() => (getLabel ? getLabel(node) : node.label), [getLabel, node]);
|
|
24
|
+
const description = useMemo(() => (getSublabel ? getSublabel(node) : undefined), [getSublabel, node]);
|
|
25
|
+
const decorations = useMemo(() => getDecorations?.(node), [getDecorations, node]);
|
|
26
|
+
const actions = useMemo(() => [
|
|
27
|
+
...(error && error.error.type === "Unknown"
|
|
28
|
+
? [
|
|
29
|
+
_jsx(Tree.ItemAction, { label: localizedStrings.retry, onClick: () => reloadTree({ parentNodeId: node.id, state: "reset" }), visible: true, icon: refreshSvg }, "retry"),
|
|
30
|
+
]
|
|
31
|
+
: []),
|
|
32
|
+
...(getActions ? getActions(node) : []),
|
|
33
|
+
], [getActions, node, error, localizedStrings, reloadTree]);
|
|
34
|
+
const isDisabled = treeItemProps["aria-disabled"] === true;
|
|
35
|
+
return (_jsx(Tree.Item, { ...treeItemProps, ref: ref, label: label, description: description, selected: selected, expanded: node.isExpanded || node.children === true || node.children.length > 0 ? node.isExpanded : undefined, onExpandedChange: useCallback((isExpanded) => {
|
|
36
|
+
expandNode(node.id, isExpanded);
|
|
37
|
+
}, [node, expandNode]), onClick: useCallback((event) => {
|
|
38
|
+
!isDisabled && onNodeClick?.(node, !selected, event);
|
|
39
|
+
}, [node, isDisabled, selected, onNodeClick]), onKeyDown: useCallback((event) => {
|
|
40
|
+
// Ignore if it is called on the element inside, e.g. checkbox or expander
|
|
41
|
+
if (!isDisabled && event.target === nodeRef.current) {
|
|
42
|
+
onNodeKeyDown?.(node, !selected, event);
|
|
43
|
+
}
|
|
44
|
+
}, [onNodeKeyDown, selected, isDisabled, node]), actions: actions, unstable_decorations: decorations, error: error?.error.id }));
|
|
45
|
+
}));
|
|
46
|
+
export const PlaceholderNode = memo(forwardRef(function PlaceholderNode({ ...props }, forwardedRef) {
|
|
47
|
+
const { localizedStrings } = useLocalizationContext();
|
|
48
|
+
return _jsx(Tree.Item, { ...props, ref: forwardedRef, label: localizedStrings.loading, icon: _jsx(Spinner, { size: "small", title: localizedStrings.loading }) });
|
|
49
|
+
}));
|
|
50
|
+
function useMergedRefs(...refs) {
|
|
51
|
+
return useCallback((instance) => {
|
|
52
|
+
refs.forEach((ref) => {
|
|
53
|
+
if (typeof ref === "function") {
|
|
54
|
+
ref(instance);
|
|
55
|
+
}
|
|
56
|
+
else if (ref) {
|
|
57
|
+
ref.current = instance;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
61
|
+
[...refs]);
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=TreeNodeRenderer.js.map
|
|
@@ -0,0 +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,OAAO,EACP,MAAM,GACP,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,UAAU,MAAM,8BAA8B,CAAC;AACtD,OAA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C;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 useMemo,\n useRef,\n} from \"react\";\nimport { Spinner } from \"@stratakit/bricks\";\nimport refreshSvg from \"@stratakit/icons/refresh.svg\";\nimport { Tree } from \"@stratakit/structures\";\nimport { PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { useTree, UseTreeResult } from \"../UseTree.js\";\nimport { ErrorNode } from \"./FlatTreeNode.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.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 /** Specifies if tree item has error. */\n error?: ErrorNode;\n}\n\n/** @alpha */\ntype TreeNodeRendererProps = Pick<ReturnType<typeof useTree>, \"expandNode\"> &\n Partial<Pick<ReturnType<typeof useTree>, \"getHierarchyLevelDetails\">> &\n Omit<TreeNodeProps, \"actions\" | \"label\" | \"expanded\" | \"unstable_decorations\" | \"error\"> &\n Pick<UseTreeResult, \"reloadTree\"> &\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 TreeNodeRenderer: FC<PropsWithRef<TreeNodeRendererProps & RefAttributes<HTMLElement>>> = memo(\n forwardRef<HTMLElement, TreeNodeRendererProps>(function HierarchyNode(\n { node, selected, error, 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\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 ...(error && error.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, error, localizedStrings, reloadTree],\n );\n\n const isDisabled = treeItemProps[\"aria-disabled\"] === true;\n return (\n <Tree.Item\n {...treeItemProps}\n ref={ref}\n label={label}\n description={description}\n selected={selected}\n expanded={node.isExpanded || node.children === true || node.children.length > 0 ? node.isExpanded : undefined}\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 !isDisabled && 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={error?.error.id}\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 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"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ComponentPropsWithoutRef, ReactElement } from "react";
|
|
2
|
+
import { Tree } from "@stratakit/structures";
|
|
3
|
+
import { PresentationTreeNode } from "../TreeNode.js";
|
|
4
|
+
import { SelectionMode } from "../UseSelectionHandler.js";
|
|
5
|
+
import { useTree } from "../UseTree.js";
|
|
6
|
+
import { LocalizationContextProvider } from "./LocalizationContext.js";
|
|
7
|
+
import { RootErrorRendererProps } from "./RootErrorRenderer.js";
|
|
8
|
+
import { TreeErrorRendererProps } from "./TreeErrorRenderer.js";
|
|
9
|
+
import { TreeNodeRenderer } from "./TreeNodeRenderer.js";
|
|
10
|
+
/** @alpha */
|
|
11
|
+
export type TreeProps = ComponentPropsWithoutRef<typeof Tree.Root>;
|
|
12
|
+
/** @alpha */
|
|
13
|
+
export type TreeNodeRendererProps = ComponentPropsWithoutRef<typeof TreeNodeRenderer>;
|
|
14
|
+
/** @alpha */
|
|
15
|
+
interface TreeRendererOwnProps {
|
|
16
|
+
/** Root nodes of the tree. */
|
|
17
|
+
rootNodes: PresentationTreeNode[];
|
|
18
|
+
/** Active selection mode used by the tree. Defaults to `"single"`. */
|
|
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;
|
|
24
|
+
}
|
|
25
|
+
/** @alpha */
|
|
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>;
|
|
27
|
+
/**
|
|
28
|
+
* A component that renders a tree using the `Tree` component from `@itwin/itwinui-react`. The tree nodes
|
|
29
|
+
* are rendered using `TreeNodeRenderer` component from this package.
|
|
30
|
+
*
|
|
31
|
+
* @see https://itwinui.bentley.com/docs/tree
|
|
32
|
+
* @alpha
|
|
33
|
+
*/
|
|
34
|
+
export declare function TreeRenderer({ rootNodes, selectNodes, selectionMode, rootErrorRenderer, ...treeProps }: TreeRendererProps): import("react/jsx-runtime").JSX.Element;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=TreeRenderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreeRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/TreeRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,wBAAwB,EAAmC,YAAY,EAA2C,MAAM,OAAO,CAAC;AACzI,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAE7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAuB,MAAM,2BAA2B,CAAC;AAC/E,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAGxC,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAqB,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACnF,OAAO,EAAqB,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACnF,OAAO,EAAmB,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE1E,aAAa;AACb,MAAM,MAAM,SAAS,GAAG,wBAAwB,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC;AAEnE,aAAa;AACb,MAAM,MAAM,qBAAqB,GAAG,wBAAwB,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEtF,aAAa;AACb,UAAU,oBAAoB;IAC5B,8BAA8B;IAC9B,SAAS,EAAE,oBAAoB,EAAE,CAAC;IAClC,sEAAsE;IACtE,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,4FAA4F;IAC5F,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,sBAAsB,KAAK,YAAY,CAAC;IAChE,iGAAiG;IACjG,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,sBAAsB,KAAK,YAAY,CAAC;CACrE;AAED,aAAa;AACb,KAAK,iBAAiB,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,YAAY,CAAC,GACrE,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,aAAa,GAAG,gBAAgB,CAAC,CAAC,GAC3E,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,YAAY,GAAG,0BAA0B,CAAC,GAC3E,IAAI,CAAC,sBAAsB,EAAE,eAAe,CAAC,GAC7C,IAAI,CAAC,qBAAqB,EAAE,MAAM,GAAG,YAAY,GAAG,eAAe,GAAG,cAAc,GAAG,YAAY,GAAG,UAAU,GAAG,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"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { createElement as _createElement } from "react";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
/*---------------------------------------------------------------------------------------------
|
|
4
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
5
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
6
|
+
*--------------------------------------------------------------------------------------------*/
|
|
7
|
+
import { forwardRef, memo, useCallback, useEffect, useMemo, useRef } from "react";
|
|
8
|
+
import { Tree } from "@stratakit/structures";
|
|
9
|
+
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
10
|
+
import { useSelectionHandler } from "../UseSelectionHandler.js";
|
|
11
|
+
import { useEvent } from "../Utils.js";
|
|
12
|
+
import { isPlaceholderNode, useErrorList, useFlatTreeNodeList } from "./FlatTreeNode.js";
|
|
13
|
+
import { LocalizationContextProvider } from "./LocalizationContext.js";
|
|
14
|
+
import { RootErrorRenderer } from "./RootErrorRenderer.js";
|
|
15
|
+
import { TreeErrorRenderer } from "./TreeErrorRenderer.js";
|
|
16
|
+
import { PlaceholderNode, TreeNodeRenderer } from "./TreeNodeRenderer.js";
|
|
17
|
+
/**
|
|
18
|
+
* A component that renders a tree using the `Tree` component from `@itwin/itwinui-react`. The tree nodes
|
|
19
|
+
* are rendered using `TreeNodeRenderer` component from this package.
|
|
20
|
+
*
|
|
21
|
+
* @see https://itwinui.bentley.com/docs/tree
|
|
22
|
+
* @alpha
|
|
23
|
+
*/
|
|
24
|
+
export function TreeRenderer({ rootNodes, selectNodes, selectionMode, rootErrorRenderer, ...treeProps }) {
|
|
25
|
+
const { onNodeClick, onNodeKeyDown } = useSelectionHandler({
|
|
26
|
+
rootNodes,
|
|
27
|
+
selectNodes: selectNodes ?? noopSelectNodes,
|
|
28
|
+
selectionMode: selectionMode ?? "single",
|
|
29
|
+
});
|
|
30
|
+
const handleNodeClick = useEvent(onNodeClick);
|
|
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);
|
|
46
|
+
const hasError = useCallback((nodeId) => {
|
|
47
|
+
return errorList.find((errorNode) => errorNode.parent?.id === nodeId);
|
|
48
|
+
}, [errorList]);
|
|
49
|
+
const virtualizer = useVirtualizer({
|
|
50
|
+
count: flatNodes.length,
|
|
51
|
+
getScrollElement: () => parentRef.current,
|
|
52
|
+
getItemKey: (index) => flatNodes[index].id,
|
|
53
|
+
estimateSize: () => 28,
|
|
54
|
+
overscan: 10,
|
|
55
|
+
});
|
|
56
|
+
const items = virtualizer.getVirtualItems();
|
|
57
|
+
const scrollToElement = useCallback((errorNode) => {
|
|
58
|
+
const index = flatNodes.findIndex((flatNode) => flatNode.id === errorNode.parent?.id);
|
|
59
|
+
if (index === -1) {
|
|
60
|
+
errorNode.expandTo((nodeId) => expandNode(nodeId, true));
|
|
61
|
+
scrollToNode.current = errorNode.parent?.id;
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
virtualizer.scrollToIndex(index, { align: "end" });
|
|
65
|
+
}, [expandNode, flatNodes, virtualizer]);
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (scrollToNode.current === undefined) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const index = flatNodes.findIndex((flatNode) => flatNode.id === scrollToNode.current);
|
|
71
|
+
if (index === -1) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
virtualizer.scrollToIndex(index, { align: "end" });
|
|
75
|
+
scrollToNode.current = undefined;
|
|
76
|
+
}, [flatNodes, virtualizer]);
|
|
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 }));
|
|
89
|
+
}) }) })] }));
|
|
90
|
+
}
|
|
91
|
+
const VirtualTreeItem = memo(forwardRef(function VirtualTreeItem({ start, node, getDecorations, getActions, getLabel, getSublabel, expandNode, error, reloadTree, onNodeClick, onNodeKeyDown, ...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, expandNode: expandNode, error: error, reloadTree: reloadTree, getDecorations: getDecorations, getActions: getActions, getLabel: getLabel, getSublabel: getSublabel, onNodeClick: onNodeClick, onNodeKeyDown: onNodeKeyDown }));
|
|
104
|
+
}));
|
|
105
|
+
function noopSelectNodes() { }
|
|
106
|
+
//# sourceMappingURL=TreeRenderer.js.map
|
|
@@ -0,0 +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;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,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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,EACV,UAAU,EAAE,UAAU,EACtB,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,UAAU,EACtB,cAAc,EAAE,cAAc,EAC9B,UAAU,EAAE,UAAU,EACtB,QAAQ,EAAE,QAAQ,EAClB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,GAC5B,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 \"@stratakit/structures\";\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, expandNode, error, reloadTree, onNodeClick, onNodeKeyDown, ...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 expandNode={expandNode}\n error={error}\n reloadTree={reloadTree}\n getDecorations={getDecorations}\n getActions={getActions}\n getLabel={getLabel}\n getSublabel={getSublabel}\n onNodeClick={onNodeClick}\n onNodeKeyDown={onNodeKeyDown}\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
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
5
|
+
export { TreeNodeRenderer } from "./presentation-hierarchies-react/stratakit/TreeNodeRenderer.js";
|
|
6
|
+
export { FilterAction } from "./presentation-hierarchies-react/stratakit/FilterAction.js";
|
|
7
|
+
export { TreeRenderer } from "./presentation-hierarchies-react/stratakit/TreeRenderer.js";
|
|
8
|
+
export { TreeErrorRenderer } from "./presentation-hierarchies-react/stratakit/TreeErrorRenderer.js";
|
|
9
|
+
export { useFlatTreeNodeList, useErrorList, FlatTreeNode } from "./presentation-hierarchies-react/stratakit/FlatTreeNode.js";
|
|
10
|
+
export { LocalizationContextProvider } from "./presentation-hierarchies-react/stratakit/LocalizationContext.js";
|
|
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,gEAAgE,CAAC;AAClG,OAAO,EAAE,YAAY,EAAE,MAAM,4DAA4D,CAAC;AAC1F,OAAO,EAAE,YAAY,EAAE,MAAM,4DAA4D,CAAC;AAC1F,OAAO,EAAE,iBAAiB,EAAE,MAAM,iEAAiE,CAAC;AACpG,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,4DAA4D,CAAC;AAC7H,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"}
|
|
@@ -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
|
-
export {
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
15
|
-
export {
|
|
9
|
+
export { TreeNodeRenderer } from "./presentation-hierarchies-react/stratakit/TreeNodeRenderer.js";
|
|
10
|
+
export { FilterAction } from "./presentation-hierarchies-react/stratakit/FilterAction.js";
|
|
11
|
+
export { TreeRenderer } from "./presentation-hierarchies-react/stratakit/TreeRenderer.js";
|
|
12
|
+
export { TreeErrorRenderer } from "./presentation-hierarchies-react/stratakit/TreeErrorRenderer.js";
|
|
13
|
+
export { useFlatTreeNodeList, useErrorList } from "./presentation-hierarchies-react/stratakit/FlatTreeNode.js";
|
|
14
|
+
export { LocalizationContextProvider } from "./presentation-hierarchies-react/stratakit/LocalizationContext.js";
|
|
15
|
+
export { GenericInstanceFilter, HierarchyNode, getLogger, setLogger } from "@itwin/presentation-hierarchies";
|
|
16
16
|
//# sourceMappingURL=presentation-hierarchies-react.js.map
|