@itwin/presentation-hierarchies-react 2.0.0-alpha.6 → 2.0.0-alpha.7
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 +7 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.js +4 -4
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.css +14 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.d.ts +1 -0
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js +3 -2
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @itwin/presentation-hierarchies-react
|
|
2
2
|
|
|
3
|
+
## 2.0.0-alpha.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#892](https://github.com/iTwin/presentation/pull/892): Fix focus outline for tree items not being visible on action items click.
|
|
8
|
+
- [#894](https://github.com/iTwin/presentation/pull/894): Fix `treeRenderer` property `getSublabel` not being used.
|
|
9
|
+
|
|
3
10
|
## 2.0.0-alpha.6
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
|
@@ -42,7 +42,7 @@ function ResultSetTooLargeNodeLabel({ onFilterClick, onOverrideLimit, limit }) {
|
|
|
42
42
|
}
|
|
43
43
|
function ErrorNodeLabel({ message, onRetry }) {
|
|
44
44
|
const { localizedStrings } = useLocalizationContext();
|
|
45
|
-
return (_jsxs("div", { style: { display: "flex" }, children: [_jsx(Text, { children: message }), onRetry ? _jsx(Anchor, { onClick: onRetry, children: localizedStrings?.retry }) : null] }));
|
|
45
|
+
return (_jsxs("div", { style: { display: "flex" }, children: [_jsx(Text, { variant: "body-sm", children: message }), onRetry ? _jsx(Anchor, { onClick: onRetry, children: localizedStrings?.retry }) : null] }));
|
|
46
46
|
}
|
|
47
47
|
function createLocalizedMessage(message, limit, onClick) {
|
|
48
48
|
const limitStr = limit.toLocaleString(undefined, { useGrouping: true });
|
|
@@ -52,21 +52,21 @@ function createLocalizedMessage(message, limit, onClick) {
|
|
|
52
52
|
if (!match) {
|
|
53
53
|
return {
|
|
54
54
|
title: messageWithLimit,
|
|
55
|
-
element: (_jsx("div", { style: { display: "flex" }, children: _jsx(Text, { children: messageWithLimit }) })),
|
|
55
|
+
element: (_jsx("div", { style: { display: "flex" }, children: _jsx(Text, { variant: "body-sm", children: messageWithLimit }) })),
|
|
56
56
|
};
|
|
57
57
|
}
|
|
58
58
|
const [fullText, innerText] = match;
|
|
59
59
|
const [textBefore, textAfter] = messageWithLimit.split(fullText);
|
|
60
60
|
return {
|
|
61
61
|
title: messageWithLimit.replace(fullText, innerText),
|
|
62
|
-
element: (_jsxs("div", { style: { display: "flex" }, children: [textBefore ? _jsx(Text, { children: textBefore }) : null, _jsx(Anchor
|
|
62
|
+
element: (_jsxs("div", { style: { display: "flex" }, children: [textBefore ? _jsx(Text, { variant: "body-sm", children: textBefore }) : null, _jsx(Anchor
|
|
63
63
|
// underline props does not exist in v5
|
|
64
64
|
, {
|
|
65
65
|
// underline props does not exist in v5
|
|
66
66
|
onClick: (e) => {
|
|
67
67
|
e.stopPropagation();
|
|
68
68
|
onClick?.();
|
|
69
|
-
}, children: innerText }), textAfter ? _jsx(Text, { children: textAfter }) : null] })),
|
|
69
|
+
}, children: innerText }), textAfter ? _jsx(Text, { variant: "body-sm", children: textAfter }) : null] })),
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
//# sourceMappingURL=TreeErrorRenderer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeErrorRenderer.js","sourceRoot":"","sources":["../../../../src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pB,OAAO,EAAE,EAAE,CAAC;oBACd,CAAC,YAEA,SAAS,GACH,EACR,SAAS,CAAC,CAAC,CAAC,KAAC,IAAI,cAAE,SAAS,GAAQ,CAAC,CAAC,CAAC,IAAI,IACxC,CACP;KACF,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { ComponentPropsWithoutRef, CSSProperties, forwardRef, ForwardRefExoticComponent, RefAttributes } from \"react\";\nimport { Anchor, Text, Tree } from \"@itwin/itwinui-react/bricks\";\nimport { MAX_LIMIT_OVERRIDE } from \"../internal/Utils.js\";\nimport { PresentationInfoNode } from \"../TreeNode.js\";\nimport { HierarchyLevelDetails, useTree } from \"../UseTree.js\";\nimport { FlatNode } from \"./FlatTreeNode.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\n\n/** @alpha */\nexport interface TreeErrorItemProps {\n /** A callback to reload a hierarchy level when an error occurs and `retry` button is clicked. */\n reloadTree?: (options: { parentNodeId: string | undefined; state: \"reset\" }) => void;\n /** Action to perform when the filter button is clicked for this node. */\n onFilterClick?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;\n}\n\ninterface TreeErrorRendererOwnProps {\n node: FlatNode<PresentationInfoNode>;\n style?: CSSProperties;\n}\n\ntype TreeErrorRendererProps = TreeErrorRendererOwnProps & TreeErrorItemProps & Partial<Pick<ReturnType<typeof useTree>, \"getHierarchyLevelDetails\">>;\n\n/** @internal */\nexport const TreeErrorRenderer: ForwardRefExoticComponent<TreeErrorRendererProps & RefAttributes<HTMLElement>> = forwardRef(\n ({ node, getHierarchyLevelDetails, onFilterClick, reloadTree, ...rest }, forwardedRef) => {\n const { localizedStrings } = useLocalizationContext();\n if (node.type === \"ResultSetTooLarge\") {\n return (\n <ResultSetTooLargeNode\n {...rest}\n ref={forwardedRef}\n limit={node.resultSetSizeLimit}\n onOverrideLimit={getHierarchyLevelDetails ? (limit) => getHierarchyLevelDetails(node.parentNodeId)?.setSizeLimit(limit) : undefined}\n onFilterClick={\n onFilterClick\n ? () => {\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.parentNodeId);\n hierarchyLevelDetails && onFilterClick(hierarchyLevelDetails);\n }\n : undefined\n }\n aria-level={node.level}\n aria-posinset={node.posInLevel}\n aria-setsize={node.levelSize}\n />\n );\n }\n\n if (node.type === \"NoFilterMatches\") {\n return (\n <Tree.Item\n {...rest}\n ref={forwardedRef}\n aria-level={node.level}\n aria-posinset={node.posInLevel}\n aria-setsize={node.levelSize}\n label={localizedStrings.noFilteredChildren}\n aria-disabled={true}\n />\n );\n }\n\n const onRetry = reloadTree ? () => reloadTree({ parentNodeId: node.parentNodeId, state: \"reset\" }) : undefined;\n return (\n <Tree.Item\n {...rest}\n ref={forwardedRef}\n aria-level={node.level}\n aria-posinset={node.posInLevel}\n aria-setsize={node.levelSize}\n label={<ErrorNodeLabel message={node.message} onRetry={onRetry} />}\n aria-disabled={true}\n />\n );\n },\n);\nTreeErrorRenderer.displayName = \"TreeErrorRenderer\";\n\nconst ResultSetTooLargeNode = forwardRef<\n HTMLElement,\n Omit<ComponentPropsWithoutRef<typeof Tree.Item>, \"onExpanded\" | \"label\"> & ResultSetTooLargeNodeLabelProps\n>(({ onFilterClick, onOverrideLimit, limit, ...props }, forwardedRef) => {\n return (\n <Tree.Item\n {...props}\n ref={forwardedRef}\n label={<ResultSetTooLargeNodeLabel limit={limit} onFilterClick={onFilterClick} onOverrideLimit={onOverrideLimit} />}\n />\n );\n});\nResultSetTooLargeNode.displayName = \"ResultSetTooLargeNode\";\n\ninterface ResultSetTooLargeNodeLabelProps {\n limit: number;\n onFilterClick?: () => void;\n onOverrideLimit?: (limit: number) => void;\n}\n\nfunction ResultSetTooLargeNodeLabel({ onFilterClick, onOverrideLimit, limit }: ResultSetTooLargeNodeLabelProps) {\n const { localizedStrings } = useLocalizationContext();\n const supportsFiltering = !!onFilterClick;\n const supportsLimitOverride = !!onOverrideLimit && limit < MAX_LIMIT_OVERRIDE;\n\n const limitExceededMessage = createLocalizedMessage(\n supportsFiltering ? localizedStrings.resultLimitExceededWithFiltering : localizedStrings.resultLimitExceeded,\n limit,\n onFilterClick,\n );\n const increaseLimitMessage = supportsLimitOverride\n ? createLocalizedMessage(\n supportsFiltering ? localizedStrings.increaseHierarchyLimitWithFiltering : localizedStrings.increaseHierarchyLimit,\n MAX_LIMIT_OVERRIDE,\n () => onOverrideLimit(MAX_LIMIT_OVERRIDE),\n )\n : { title: \"\", element: null };\n\n const title = `${limitExceededMessage.title} ${increaseLimitMessage.title}`;\n\n return (\n <div style={{ display: \"flex\", alignItems: \"start\" }} title={title}>\n {limitExceededMessage.element}\n {increaseLimitMessage.element}\n </div>\n );\n}\n\nfunction ErrorNodeLabel({ message, onRetry }: { message: string; onRetry?: () => void }) {\n const { localizedStrings } = useLocalizationContext();\n return (\n <div style={{ display: \"flex\" }}>\n <Text>{message}</Text>\n {onRetry ? <Anchor onClick={onRetry}>{localizedStrings?.retry}</Anchor> : null}\n </div>\n );\n}\n\nfunction createLocalizedMessage(message: string, limit: number, onClick?: () => void) {\n const limitStr = limit.toLocaleString(undefined, { useGrouping: true });\n const messageWithLimit = message.replace(\"{{limit}}\", limitStr);\n const exp = new RegExp(\"<link>(.*)</link>\");\n const match = messageWithLimit.match(exp);\n\n if (!match) {\n return {\n title: messageWithLimit,\n element: (\n <div style={{ display: \"flex\" }}>\n <Text>{messageWithLimit}</Text>\n </div>\n ),\n };\n }\n\n const [fullText, innerText] = match;\n const [textBefore, textAfter] = messageWithLimit.split(fullText);\n\n return {\n title: messageWithLimit.replace(fullText, innerText),\n element: (\n <div style={{ display: \"flex\" }}>\n {textBefore ? <Text>{textBefore}</Text> : null}\n <Anchor\n // underline props does not exist in v5\n onClick={(e) => {\n e.stopPropagation();\n onClick?.();\n }}\n >\n {innerText}\n </Anchor>\n {textAfter ? <Text>{textAfter}</Text> : null}\n </div>\n ),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TreeErrorRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeErrorRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAA2C,UAAU,EAA4C,MAAM,OAAO,CAAC;AACtH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAI1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAiBlE,gBAAgB;AAChB,MAAM,CAAC,MAAM,iBAAiB,GAAmF,UAAU,CACzH,CAAC,EAAE,IAAI,EAAE,wBAAwB,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,EAAE,YAAY,EAAE,EAAE;IACvF,MAAM,EAAE,gBAAgB,EAAE,GAAG,sBAAsB,EAAE,CAAC;IACtD,IAAI,IAAI,CAAC,IAAI,KAAK,mBAAmB,EAAE,CAAC;QACtC,OAAO,CACL,KAAC,qBAAqB,OAChB,IAAI,EACR,GAAG,EAAE,YAAY,EACjB,KAAK,EAAE,IAAI,CAAC,kBAAkB,EAC9B,eAAe,EAAE,wBAAwB,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,wBAAwB,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,EACnI,aAAa,EACX,aAAa;gBACX,CAAC,CAAC,GAAG,EAAE;oBACH,MAAM,qBAAqB,GAAG,wBAAwB,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;oBAC5E,qBAAqB,IAAI,aAAa,CAAC,qBAAqB,CAAC,CAAC;gBAChE,CAAC;gBACH,CAAC,CAAC,SAAS,gBAEH,IAAI,CAAC,KAAK,mBACP,IAAI,C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AAG,UAAU,GAAQ,CAAC,CAAC,CAAC,IAAI,EAClE,KAAC,MAAM;gBACL,uCAAuC;;oBAAvC,uCAAuC;oBACvC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;wBACb,CAAC,CAAC,eAAe,EAAE,CAAC;wBACpB,OAAO,EAAE,EAAE,CAAC;oBACd,CAAC,YAEA,SAAS,GACH,EACR,SAAS,CAAC,CAAC,CAAC,KAAC,IAAI,IAAC,OAAO,EAAE,SAAS,YAAG,SAAS,GAAQ,CAAC,CAAC,CAAC,IAAI,IAC5D,CACP;KACF,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { ComponentPropsWithoutRef, CSSProperties, forwardRef, ForwardRefExoticComponent, RefAttributes } from \"react\";\nimport { Anchor, Text, Tree } from \"@itwin/itwinui-react/bricks\";\nimport { MAX_LIMIT_OVERRIDE } from \"../internal/Utils.js\";\nimport { PresentationInfoNode } from \"../TreeNode.js\";\nimport { HierarchyLevelDetails, useTree } from \"../UseTree.js\";\nimport { FlatNode } from \"./FlatTreeNode.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\n\n/** @alpha */\nexport interface TreeErrorItemProps {\n /** A callback to reload a hierarchy level when an error occurs and `retry` button is clicked. */\n reloadTree?: (options: { parentNodeId: string | undefined; state: \"reset\" }) => void;\n /** Action to perform when the filter button is clicked for this node. */\n onFilterClick?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;\n}\n\ninterface TreeErrorRendererOwnProps {\n node: FlatNode<PresentationInfoNode>;\n style?: CSSProperties;\n}\n\ntype TreeErrorRendererProps = TreeErrorRendererOwnProps & TreeErrorItemProps & Partial<Pick<ReturnType<typeof useTree>, \"getHierarchyLevelDetails\">>;\n\n/** @internal */\nexport const TreeErrorRenderer: ForwardRefExoticComponent<TreeErrorRendererProps & RefAttributes<HTMLElement>> = forwardRef(\n ({ node, getHierarchyLevelDetails, onFilterClick, reloadTree, ...rest }, forwardedRef) => {\n const { localizedStrings } = useLocalizationContext();\n if (node.type === \"ResultSetTooLarge\") {\n return (\n <ResultSetTooLargeNode\n {...rest}\n ref={forwardedRef}\n limit={node.resultSetSizeLimit}\n onOverrideLimit={getHierarchyLevelDetails ? (limit) => getHierarchyLevelDetails(node.parentNodeId)?.setSizeLimit(limit) : undefined}\n onFilterClick={\n onFilterClick\n ? () => {\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.parentNodeId);\n hierarchyLevelDetails && onFilterClick(hierarchyLevelDetails);\n }\n : undefined\n }\n aria-level={node.level}\n aria-posinset={node.posInLevel}\n aria-setsize={node.levelSize}\n />\n );\n }\n\n if (node.type === \"NoFilterMatches\") {\n return (\n <Tree.Item\n {...rest}\n ref={forwardedRef}\n aria-level={node.level}\n aria-posinset={node.posInLevel}\n aria-setsize={node.levelSize}\n label={localizedStrings.noFilteredChildren}\n aria-disabled={true}\n />\n );\n }\n\n const onRetry = reloadTree ? () => reloadTree({ parentNodeId: node.parentNodeId, state: \"reset\" }) : undefined;\n return (\n <Tree.Item\n {...rest}\n ref={forwardedRef}\n aria-level={node.level}\n aria-posinset={node.posInLevel}\n aria-setsize={node.levelSize}\n label={<ErrorNodeLabel message={node.message} onRetry={onRetry} />}\n aria-disabled={true}\n />\n );\n },\n);\nTreeErrorRenderer.displayName = \"TreeErrorRenderer\";\n\nconst ResultSetTooLargeNode = forwardRef<\n HTMLElement,\n Omit<ComponentPropsWithoutRef<typeof Tree.Item>, \"onExpanded\" | \"label\"> & ResultSetTooLargeNodeLabelProps\n>(({ onFilterClick, onOverrideLimit, limit, ...props }, forwardedRef) => {\n return (\n <Tree.Item\n {...props}\n ref={forwardedRef}\n label={<ResultSetTooLargeNodeLabel limit={limit} onFilterClick={onFilterClick} onOverrideLimit={onOverrideLimit} />}\n />\n );\n});\nResultSetTooLargeNode.displayName = \"ResultSetTooLargeNode\";\n\ninterface ResultSetTooLargeNodeLabelProps {\n limit: number;\n onFilterClick?: () => void;\n onOverrideLimit?: (limit: number) => void;\n}\n\nfunction ResultSetTooLargeNodeLabel({ onFilterClick, onOverrideLimit, limit }: ResultSetTooLargeNodeLabelProps) {\n const { localizedStrings } = useLocalizationContext();\n const supportsFiltering = !!onFilterClick;\n const supportsLimitOverride = !!onOverrideLimit && limit < MAX_LIMIT_OVERRIDE;\n\n const limitExceededMessage = createLocalizedMessage(\n supportsFiltering ? localizedStrings.resultLimitExceededWithFiltering : localizedStrings.resultLimitExceeded,\n limit,\n onFilterClick,\n );\n const increaseLimitMessage = supportsLimitOverride\n ? createLocalizedMessage(\n supportsFiltering ? localizedStrings.increaseHierarchyLimitWithFiltering : localizedStrings.increaseHierarchyLimit,\n MAX_LIMIT_OVERRIDE,\n () => onOverrideLimit(MAX_LIMIT_OVERRIDE),\n )\n : { title: \"\", element: null };\n\n const title = `${limitExceededMessage.title} ${increaseLimitMessage.title}`;\n\n return (\n <div style={{ display: \"flex\", alignItems: \"start\" }} title={title}>\n {limitExceededMessage.element}\n {increaseLimitMessage.element}\n </div>\n );\n}\n\nfunction ErrorNodeLabel({ message, onRetry }: { message: string; onRetry?: () => void }) {\n const { localizedStrings } = useLocalizationContext();\n return (\n <div style={{ display: \"flex\" }}>\n <Text variant={\"body-sm\"}>{message}</Text>\n {onRetry ? <Anchor onClick={onRetry}>{localizedStrings?.retry}</Anchor> : null}\n </div>\n );\n}\n\nfunction createLocalizedMessage(message: string, limit: number, onClick?: () => void) {\n const limitStr = limit.toLocaleString(undefined, { useGrouping: true });\n const messageWithLimit = message.replace(\"{{limit}}\", limitStr);\n const exp = new RegExp(\"<link>(.*)</link>\");\n const match = messageWithLimit.match(exp);\n\n if (!match) {\n return {\n title: messageWithLimit,\n element: (\n <div style={{ display: \"flex\" }}>\n <Text variant={\"body-sm\"}>{messageWithLimit}</Text>\n </div>\n ),\n };\n }\n\n const [fullText, innerText] = match;\n const [textBefore, textAfter] = messageWithLimit.split(fullText);\n\n return {\n title: messageWithLimit.replace(fullText, innerText),\n element: (\n <div style={{ display: \"flex\" }}>\n {textBefore ? <Text variant={\"body-sm\"}>{textBefore}</Text> : null}\n <Anchor\n // underline props does not exist in v5\n onClick={(e) => {\n e.stopPropagation();\n onClick?.();\n }}\n >\n {innerText}\n </Anchor>\n {textAfter ? <Text variant={\"body-sm\"}>{textAfter}</Text> : null}\n </div>\n ),\n };\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
|
|
6
|
+
.presentation-hierarchies-node:focus-within::before {
|
|
7
|
+
content: "";
|
|
8
|
+
z-index: 1;
|
|
9
|
+
pointer-events: none;
|
|
10
|
+
outline: 2px solid var(--ids-color-border-accent-strong);
|
|
11
|
+
outline-offset: -1px;
|
|
12
|
+
position: absolute;
|
|
13
|
+
inset: 0px;
|
|
14
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeNodeRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeNodeRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,EACL,wBAAwB,EAExB,yBAAyB,EAGzB,YAAY,EAEZ,aAAa,EAGd,MAAM,OAAO,CAAC;AACf,OAAO,EAAyB,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAA+B,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AACxF,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,YAAY,EAAqB,MAAM,mBAAmB,CAAC;AAEpE,OAAO,EAAoB,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAA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C,EAAE,CAAC,IAAI,EAAE,yBAAyB,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,KAAK,IAAI,CAAC;IAC/H,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;IACxH;;OAEG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC,IAAI,EAAE,yBAAyB,KAAK,cAAc,CAAC,CAAC;CACtE;AAED,aAAa;AACb,KAAK,qBAAqB,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,YAAY,GAAG,gBAAgB,CAAC,GAC5F,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,EAAE,0BAA0B,CAAC,CAAC,GACrE,IAAI,CAAC,aAAa,EAAE,SAAS,GAAG,YAAY,GAAG,eAAe,GAAG,cAAc,GAAG,OAAO,GAAG,MAAM,GAAG,UAAU,GAAG,UAAU,CAAC,GAC7H,wBAAwB,GACxB,kBAAkB,CAAC;AAErB;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,EAAE,yBAAyB,CAAC,qBAAqB,GAAG,aAAa,CAAC,WAAW,CAAC,CAoG1G,CAAC"}
|
|
@@ -3,6 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
4
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
5
|
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
import "./TreeNodeRenderer.css";
|
|
6
7
|
import { forwardRef, useCallback, useRef, } from "react";
|
|
7
8
|
import { DropdownMenu, Spinner, Tree } from "@itwin/itwinui-react/bricks";
|
|
8
9
|
import { isPresentationHierarchyNode } from "../TreeNode.js";
|
|
@@ -18,7 +19,7 @@ const dropdownIcon = new URL("@itwin/itwinui-icons/more-horizontal.svg", import.
|
|
|
18
19
|
* @see https://itwinui.bentley.com/docs/tree
|
|
19
20
|
* @public
|
|
20
21
|
*/
|
|
21
|
-
export const TreeNodeRenderer = forwardRef(({ node, expandNode, getIcon, getLabel, onFilterClick, onNodeClick, onNodeKeyDown, isNodeSelected, getHierarchyLevelDetails, reloadTree, actions, ...treeItemProps }, forwardedRef) => {
|
|
22
|
+
export const TreeNodeRenderer = forwardRef(({ node, expandNode, getIcon, getLabel, getSublabel, onFilterClick, onNodeClick, onNodeKeyDown, isNodeSelected, getHierarchyLevelDetails, reloadTree, actions, ...treeItemProps }, forwardedRef) => {
|
|
22
23
|
const nodeRef = useRef(null);
|
|
23
24
|
const ref = useMergedRefs(forwardedRef, nodeRef);
|
|
24
25
|
if (isPlaceholderNode(node)) {
|
|
@@ -47,7 +48,7 @@ export const TreeNodeRenderer = forwardRef(({ node, expandNode, getIcon, getLabe
|
|
|
47
48
|
];
|
|
48
49
|
};
|
|
49
50
|
const selected = isNodeSelected(node.id);
|
|
50
|
-
return (_jsx(Tree.Item, { ...treeItemProps, ref: ref, "aria-level": node.level, "aria-posinset": node.posInLevel, "aria-setsize": node.levelSize, label: getLabel ? getLabel(node) : node.label, selected: selected, expanded: node.isExpanded || node.children === true || node.children.length > 0 ? node.isExpanded : undefined, onExpandedChange: (isExpanded) => {
|
|
51
|
+
return (_jsx(Tree.Item, { ...treeItemProps, className: "presentation-hierarchies-node", ref: ref, "aria-level": node.level, "aria-posinset": node.posInLevel, "aria-setsize": node.levelSize, label: getLabel ? getLabel(node) : node.label, description: getSublabel ? getSublabel(node) : undefined, selected: selected, expanded: node.isExpanded || node.children === true || node.children.length > 0 ? node.isExpanded : undefined, onExpandedChange: (isExpanded) => {
|
|
51
52
|
expandNode(node.id, isExpanded);
|
|
52
53
|
}, onClick: (event) => {
|
|
53
54
|
!treeItemProps["aria-disabled"] && onNodeClick?.(node, !selected, event);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TreeNodeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeNodeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAEL,UAAU,EAOV,WAAW,EACX,MAAM,GACP,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAAE,2BAA2B,EAA6B,MAAM,gBAAgB,CAAC;AAExF,OAAO,EAAgB,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAkB,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAsB,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE/E,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,0CAA0C,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;AAgC/F;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAkF,UAAU,CACvH,CACE,EACE,IAAI,EACJ,UAAU,EACV,OAAO,EACP,QAAQ,EACR,aAAa,EACb,WAAW,EACX,aAAa,EACb,cAAc,EACd,wBAAwB,EACxB,UAAU,EACV,OAAO,EACP,GAAG,aAAa,EACjB,EACD,YAAY,EACZ,EAAE;IACF,MAAM,OAAO,GAAG,MAAM,CAAc,IAAI,CAAC,CAAC;IAC1C,MAAM,GAAG,GAAG,aAAa,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAEjD,IAAI,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5B,OAAO,KAAC,eAAe,OAAK,aAAa,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,GAA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IAAI,CAAC,CACV,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport {\n ComponentPropsWithoutRef,\n forwardRef,\n ForwardRefExoticComponent,\n LegacyRef,\n MutableRefObject,\n ReactElement,\n Ref,\n RefAttributes,\n useCallback,\n useRef,\n} from \"react\";\nimport { DropdownMenu, Spinner, Tree } from \"@itwin/itwinui-react/bricks\";\nimport { isPresentationHierarchyNode, PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { useTree } from \"../UseTree.js\";\nimport { FlatTreeNode, isPlaceholderNode } from \"./FlatTreeNode.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\nimport { TreeActionButton, TreeItemAction } from \"./TreeActionButton.js\";\nimport { TreeErrorItemProps, TreeErrorRenderer } from \"./TreeErrorRenderer.js\";\n\nconst dropdownIcon = new URL(\"@itwin/itwinui-icons/more-horizontal.svg\", import.meta.url).href;\n\n/** @alpha */\ntype TreeNodeProps = ComponentPropsWithoutRef<typeof Tree.Item>;\n\n/** @alpha */\nexport interface TreeNodeRendererOwnProps {\n /** Node that is rendered. */\n node: FlatTreeNode;\n /** Returns an icon or icon href for a given node. */\n getIcon?: (node: PresentationHierarchyNode) => string | ReactElement | undefined;\n /** Returns a label for a given node. */\n getLabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n /** Returns sublabel for a given node. */\n getSublabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n /** Action to perform when the node is clicked. */\n onNodeClick?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.MouseEvent<HTMLElement, MouseEvent>) => void;\n /** Action to perform when a key is pressed when the node is hovered on. */\n onNodeKeyDown?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.KeyboardEvent<HTMLElement>) => void;\n /**\n * Actions for tree item.\n */\n actions?: Array<(node: PresentationHierarchyNode) => TreeItemAction>;\n}\n\n/** @alpha */\ntype TreeNodeRendererProps = Pick<ReturnType<typeof useTree>, \"expandNode\" | \"isNodeSelected\"> &\n Partial<Pick<ReturnType<typeof useTree>, \"getHierarchyLevelDetails\">> &\n Omit<TreeNodeProps, \"actions\" | \"aria-level\" | \"aria-posinset\" | \"aria-setsize\" | \"label\" | \"icon\" | \"expanded\" | \"selected\"> &\n TreeNodeRendererOwnProps &\n TreeErrorItemProps;\n\n/**\n * A component that renders `RenderedTreeNode` using the `TreeNode` component from `@itwin/itwinui-react`.\n *\n * @see `TreeRenderer`\n * @see https://itwinui.bentley.com/docs/tree\n * @public\n */\nexport const TreeNodeRenderer: ForwardRefExoticComponent<TreeNodeRendererProps & RefAttributes<HTMLElement>> = forwardRef(\n (\n {\n node,\n expandNode,\n getIcon,\n getLabel,\n onFilterClick,\n onNodeClick,\n onNodeKeyDown,\n isNodeSelected,\n getHierarchyLevelDetails,\n reloadTree,\n actions,\n ...treeItemProps\n },\n forwardedRef,\n ) => {\n const nodeRef = useRef<HTMLElement>(null);\n const ref = useMergedRefs(forwardedRef, nodeRef);\n\n if (isPlaceholderNode(node)) {\n return <PlaceholderNode {...treeItemProps} level={node.level} ref={ref} />;\n }\n\n if (!isPresentationHierarchyNode(node)) {\n return (\n <TreeErrorRenderer\n style={treeItemProps.style}\n ref={ref}\n node={node}\n getHierarchyLevelDetails={getHierarchyLevelDetails}\n reloadTree={reloadTree}\n onFilterClick={onFilterClick}\n />\n );\n }\n\n const getActions = () => {\n if (!actions || actions.length === 0) {\n return undefined;\n }\n\n if (actions.length < 4) {\n return actions.map((action, index) => {\n const actionInfo = action(node);\n return <TreeActionButton key={index} {...actionInfo} />;\n });\n }\n\n return [\n <TreeActionButton key={0} {...actions[0](node)} />,\n <TreeActionButton key={1} {...actions[1](node)} />,\n <DropdownMenu.Root key={2}>\n <DropdownMenu.Button render={<Tree.ItemAction icon={dropdownIcon} label=\"Tree actions dropdown\" />} />\n <DropdownMenu.Content>\n {actions.slice(2, actions.length).map((action) => {\n const info = action(node);\n return (\n <DropdownMenu.Item key={info.label} onClick={() => info.action()}>\n {info.label}\n </DropdownMenu.Item>\n );\n })}\n </DropdownMenu.Content>\n </DropdownMenu.Root>,\n ];\n };\n\n const selected = isNodeSelected(node.id);\n return (\n <Tree.Item\n {...treeItemProps}\n ref={ref}\n aria-level={node.level}\n aria-posinset={node.posInLevel}\n aria-setsize={node.levelSize}\n label={getLabel ? getLabel(node) : node.label}\n selected={selected}\n expanded={node.isExpanded || node.children === true || node.children.length > 0 ? node.isExpanded : undefined}\n onExpandedChange={(isExpanded) => {\n expandNode(node.id, isExpanded);\n }}\n onClick={(event) => {\n !treeItemProps[\"aria-disabled\"] && onNodeClick?.(node, !selected, event);\n }}\n onKeyDown={(event) => {\n // Ignore if it is called on the element inside, e.g. checkbox or expander\n if (!treeItemProps[\"aria-disabled\"] && event.target === nodeRef.current) {\n onNodeKeyDown?.(node, !selected, event);\n }\n }}\n icon={getIcon ? getIcon(node) : undefined}\n actions={getActions()}\n />\n );\n },\n);\nTreeNodeRenderer.displayName = \"TreeNodeRenderer\";\n\nconst PlaceholderNode = forwardRef<\n HTMLDivElement,\n Omit<TreeNodeProps, \"onExpanded\" | \"label\" | \"actions\" | \"aria-level\" | \"aria-posinset\" | \"aria-setsize\" | \"icon\"> & { level: number }\n>(({ level, ...props }, forwardedRef) => {\n const { localizedStrings } = useLocalizationContext();\n return (\n <Tree.Item\n {...props}\n aria-level={level}\n aria-posinset={1}\n aria-setsize={1}\n ref={forwardedRef}\n label={localizedStrings.loading}\n icon={<Spinner size={\"small\"} title={localizedStrings.loading} />}\n />\n );\n});\nPlaceholderNode.displayName = \"PlaceholderNode\";\n\nfunction useMergedRefs<T>(...refs: ReadonlyArray<Ref<T> | LegacyRef<T> | undefined | null>) {\n return useCallback(\n (instance: T | null) => {\n refs.forEach((ref) => {\n if (typeof ref === \"function\") {\n ref(instance);\n } else if (ref) {\n (ref as MutableRefObject<T | null>).current = instance;\n }\n });\n }, // eslint-disable-next-line react-hooks/exhaustive-deps\n [...refs],\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TreeNodeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/itwinui/TreeNodeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,wBAAwB,CAAC;AAChC,OAAO,EAEL,UAAU,EAOV,WAAW,EACX,MAAM,GACP,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAAE,2BAA2B,EAA6B,MAAM,gBAAgB,CAAC;AAExF,OAAO,EAAgB,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAkB,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAsB,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE/E,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,0CAA0C,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;AAgC/F;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAkF,UAAU,CACvH,CACE,EACE,IAAI,EACJ,UAAU,EACV,OAAO,EACP,QAAQ,EACR,WAAW,EACX,aAAa,EACb,WAAW,EACX,aAAa,EACb,cAAc,EACd,wBAAwB,EACxB,UAAU,EACV,OAAO,EACP,GAAG,aAAa,EACjB,EACD,YAAY,EACZ,EAAE;IACF,MAAM,OAAO,GAAG,MAAM,CAAc,IAAI,CAAC,CAAC;IAC1C,MAAM,GAAG,GAAG,aAAa,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAEjD,IAAI,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAC;QAC5B,OAAO,KAAC,eAAe,OAAK,aAAa,EAAE,KAAK,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B,CAAC;iBAAM,IAAI,GAAG,EAAE,CAAC;gBACd,GAAkC,CAAC,OAAO,GAAG,QAAQ,CAAC;YACzD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,uDAAuD;IAC1D,CAAC,GAAG,IAAI,CAAC,CACV,CAAC;AACJ,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport \"./TreeNodeRenderer.css\";\nimport {\n ComponentPropsWithoutRef,\n forwardRef,\n ForwardRefExoticComponent,\n LegacyRef,\n MutableRefObject,\n ReactElement,\n Ref,\n RefAttributes,\n useCallback,\n useRef,\n} from \"react\";\nimport { DropdownMenu, Spinner, Tree } from \"@itwin/itwinui-react/bricks\";\nimport { isPresentationHierarchyNode, PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { useTree } from \"../UseTree.js\";\nimport { FlatTreeNode, isPlaceholderNode } from \"./FlatTreeNode.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\nimport { TreeActionButton, TreeItemAction } from \"./TreeActionButton.js\";\nimport { TreeErrorItemProps, TreeErrorRenderer } from \"./TreeErrorRenderer.js\";\n\nconst dropdownIcon = new URL(\"@itwin/itwinui-icons/more-horizontal.svg\", import.meta.url).href;\n\n/** @alpha */\ntype TreeNodeProps = ComponentPropsWithoutRef<typeof Tree.Item>;\n\n/** @alpha */\nexport interface TreeNodeRendererOwnProps {\n /** Node that is rendered. */\n node: FlatTreeNode;\n /** Returns an icon or icon href for a given node. */\n getIcon?: (node: PresentationHierarchyNode) => string | ReactElement | undefined;\n /** Returns a label for a given node. */\n getLabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n /** Returns sublabel for a given node. */\n getSublabel?: (node: PresentationHierarchyNode) => ReactElement | undefined;\n /** Action to perform when the node is clicked. */\n onNodeClick?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.MouseEvent<HTMLElement, MouseEvent>) => void;\n /** Action to perform when a key is pressed when the node is hovered on. */\n onNodeKeyDown?: (node: PresentationHierarchyNode, isSelected: boolean, event: React.KeyboardEvent<HTMLElement>) => void;\n /**\n * Actions for tree item.\n */\n actions?: Array<(node: PresentationHierarchyNode) => TreeItemAction>;\n}\n\n/** @alpha */\ntype TreeNodeRendererProps = Pick<ReturnType<typeof useTree>, \"expandNode\" | \"isNodeSelected\"> &\n Partial<Pick<ReturnType<typeof useTree>, \"getHierarchyLevelDetails\">> &\n Omit<TreeNodeProps, \"actions\" | \"aria-level\" | \"aria-posinset\" | \"aria-setsize\" | \"label\" | \"icon\" | \"expanded\" | \"selected\"> &\n TreeNodeRendererOwnProps &\n TreeErrorItemProps;\n\n/**\n * A component that renders `RenderedTreeNode` using the `TreeNode` component from `@itwin/itwinui-react`.\n *\n * @see `TreeRenderer`\n * @see https://itwinui.bentley.com/docs/tree\n * @public\n */\nexport const TreeNodeRenderer: ForwardRefExoticComponent<TreeNodeRendererProps & RefAttributes<HTMLElement>> = forwardRef(\n (\n {\n node,\n expandNode,\n getIcon,\n getLabel,\n getSublabel,\n onFilterClick,\n onNodeClick,\n onNodeKeyDown,\n isNodeSelected,\n getHierarchyLevelDetails,\n reloadTree,\n actions,\n ...treeItemProps\n },\n forwardedRef,\n ) => {\n const nodeRef = useRef<HTMLElement>(null);\n const ref = useMergedRefs(forwardedRef, nodeRef);\n\n if (isPlaceholderNode(node)) {\n return <PlaceholderNode {...treeItemProps} level={node.level} ref={ref} />;\n }\n\n if (!isPresentationHierarchyNode(node)) {\n return (\n <TreeErrorRenderer\n style={treeItemProps.style}\n ref={ref}\n node={node}\n getHierarchyLevelDetails={getHierarchyLevelDetails}\n reloadTree={reloadTree}\n onFilterClick={onFilterClick}\n />\n );\n }\n\n const getActions = () => {\n if (!actions || actions.length === 0) {\n return undefined;\n }\n\n if (actions.length < 4) {\n return actions.map((action, index) => {\n const actionInfo = action(node);\n return <TreeActionButton key={index} {...actionInfo} />;\n });\n }\n\n return [\n <TreeActionButton key={0} {...actions[0](node)} />,\n <TreeActionButton key={1} {...actions[1](node)} />,\n <DropdownMenu.Root key={2}>\n <DropdownMenu.Button render={<Tree.ItemAction icon={dropdownIcon} label=\"Tree actions dropdown\" />} />\n <DropdownMenu.Content>\n {actions.slice(2, actions.length).map((action) => {\n const info = action(node);\n return (\n <DropdownMenu.Item key={info.label} onClick={() => info.action()}>\n {info.label}\n </DropdownMenu.Item>\n );\n })}\n </DropdownMenu.Content>\n </DropdownMenu.Root>,\n ];\n };\n\n const selected = isNodeSelected(node.id);\n return (\n <Tree.Item\n {...treeItemProps}\n className={\"presentation-hierarchies-node\"}\n ref={ref}\n aria-level={node.level}\n aria-posinset={node.posInLevel}\n aria-setsize={node.levelSize}\n label={getLabel ? getLabel(node) : node.label}\n description={getSublabel ? getSublabel(node) : undefined}\n selected={selected}\n expanded={node.isExpanded || node.children === true || node.children.length > 0 ? node.isExpanded : undefined}\n onExpandedChange={(isExpanded) => {\n expandNode(node.id, isExpanded);\n }}\n onClick={(event) => {\n !treeItemProps[\"aria-disabled\"] && onNodeClick?.(node, !selected, event);\n }}\n onKeyDown={(event) => {\n // Ignore if it is called on the element inside, e.g. checkbox or expander\n if (!treeItemProps[\"aria-disabled\"] && event.target === nodeRef.current) {\n onNodeKeyDown?.(node, !selected, event);\n }\n }}\n icon={getIcon ? getIcon(node) : undefined}\n actions={getActions()}\n />\n );\n },\n);\nTreeNodeRenderer.displayName = \"TreeNodeRenderer\";\n\nconst PlaceholderNode = forwardRef<\n HTMLDivElement,\n Omit<TreeNodeProps, \"onExpanded\" | \"label\" | \"actions\" | \"aria-level\" | \"aria-posinset\" | \"aria-setsize\" | \"icon\"> & { level: number }\n>(({ level, ...props }, forwardedRef) => {\n const { localizedStrings } = useLocalizationContext();\n return (\n <Tree.Item\n {...props}\n aria-level={level}\n aria-posinset={1}\n aria-setsize={1}\n ref={forwardedRef}\n label={localizedStrings.loading}\n icon={<Spinner size={\"small\"} title={localizedStrings.loading} />}\n />\n );\n});\nPlaceholderNode.displayName = \"PlaceholderNode\";\n\nfunction useMergedRefs<T>(...refs: ReadonlyArray<Ref<T> | LegacyRef<T> | undefined | null>) {\n return useCallback(\n (instance: T | null) => {\n refs.forEach((ref) => {\n if (typeof ref === \"function\") {\n ref(instance);\n } else if (ref) {\n (ref as MutableRefObject<T | null>).current = instance;\n }\n });\n }, // eslint-disable-next-line react-hooks/exhaustive-deps\n [...refs],\n );\n}\n"]}
|
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.7",
|
|
4
4
|
"description": "React components based on `@itwin/presentation-hierarchies`",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -45,12 +45,12 @@
|
|
|
45
45
|
"react-error-boundary": "^4.0.13",
|
|
46
46
|
"rxjs": "^7.8.1",
|
|
47
47
|
"@itwin/presentation-hierarchies": "^1.4.1",
|
|
48
|
-
"@itwin/
|
|
49
|
-
"@itwin/
|
|
48
|
+
"@itwin/unified-selection": "^1.3.0",
|
|
49
|
+
"@itwin/presentation-shared": "^1.2.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"@itwin/itwinui-icons": "5.0.0-alpha.4",
|
|
53
|
-
"@itwin/itwinui-react": "5.0.0-alpha.
|
|
53
|
+
"@itwin/itwinui-react": "5.0.0-alpha.8",
|
|
54
54
|
"react": "^17.0.0 || ^18.0.0",
|
|
55
55
|
"react-dom": "^17.0.0 || ^18.0.0"
|
|
56
56
|
},
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@itwin/build-tools": "5.0.0-dev.67",
|
|
67
67
|
"@itwin/itwinui-icons": "5.0.0-alpha.4",
|
|
68
|
-
"@itwin/itwinui-react": "5.0.0-alpha.
|
|
68
|
+
"@itwin/itwinui-react": "5.0.0-alpha.8",
|
|
69
69
|
"@testing-library/dom": "^10.3.2",
|
|
70
70
|
"@testing-library/react": "^16.0.0",
|
|
71
71
|
"@testing-library/user-event": "^14.5.2",
|