@itwin/presentation-hierarchies-react 2.0.0-alpha.4 → 2.0.0-alpha.40
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 +656 -7
- package/README.md +25 -27
- package/lib/esm/presentation-hierarchies-react/Renderers.d.ts +85 -0
- package/lib/esm/presentation-hierarchies-react/Renderers.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/Renderers.js +6 -0
- package/lib/esm/presentation-hierarchies-react/Renderers.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/TreeNode.d.ts +27 -28
- package/lib/esm/presentation-hierarchies-react/TreeNode.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/TreeNode.js +1 -7
- package/lib/esm/presentation-hierarchies-react/TreeNode.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.d.ts +2 -0
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.js +1 -1
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.d.ts +24 -0
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.js +52 -0
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.d.ts +3 -3
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.js +1 -8
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.d.ts +32 -70
- package/lib/esm/presentation-hierarchies-react/UseTree.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.js +48 -49
- 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/TreeActions.d.ts +2 -2
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.js +31 -16
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.d.ts +24 -6
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.js +29 -33
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.d.ts +6 -29
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.js +31 -27
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts +23 -9
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.js +16 -29
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/Utils.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react/internal/Utils.js.map +1 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts +26 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js +75 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FilterAction.d.ts +34 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FilterAction.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FilterAction.js +26 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FilterAction.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts +58 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.js +77 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts +123 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/{itwinui → stratakit}/LocalizationContext.js +15 -5
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RenameAction.d.ts +33 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RenameAction.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RenameAction.js +39 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/RenameAction.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 +47 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js +28 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts +51 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js +117 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts +45 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts.map +1 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js +94 -0
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js.map +1 -0
- package/lib/esm/presentation-hierarchies-react.d.ts +14 -9
- package/lib/esm/presentation-hierarchies-react.d.ts.map +1 -1
- package/lib/esm/presentation-hierarchies-react.js +11 -8
- package/lib/esm/presentation-hierarchies-react.js.map +1 -1
- package/package.json +55 -47
- 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/FlatTreeNode.d.ts +0 -20
- package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.js +0 -30
- package/lib/esm/presentation-hierarchies-react/itwinui/FlatTreeNode.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/LocalizationContext.d.ts +0 -73
- 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/TreeActionButton.d.ts +0 -25
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.js +0 -40
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeActionButton.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeErrorRenderer.d.ts +0 -13
- 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/TreeNodeRenderer.d.ts +0 -46
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeNodeRenderer.js +0 -80
- 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 -30
- package/lib/esm/presentation-hierarchies-react/itwinui/TreeRenderer.js.map +0 -1
|
@@ -0,0 +1,26 @@
|
|
|
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 { memo, useCallback } from "react";
|
|
7
|
+
import filterSvg from "@stratakit/icons/filter.svg";
|
|
8
|
+
import { Tree } from "@stratakit/structures";
|
|
9
|
+
import { useLocalizationContext } from "./LocalizationContext.js";
|
|
10
|
+
/**
|
|
11
|
+
* React component that renders a filter action for a tree item.
|
|
12
|
+
* @alpha
|
|
13
|
+
*/
|
|
14
|
+
export const FilterAction = memo(function FilterAction({ node, onFilter, getHierarchyLevelDetails, reserveSpace, }) {
|
|
15
|
+
const { localizedStrings } = useLocalizationContext();
|
|
16
|
+
const { filterHierarchyLevel, filterHierarchyLevelActiveDescription } = localizedStrings;
|
|
17
|
+
const handleClick = useCallback(() => {
|
|
18
|
+
const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.id);
|
|
19
|
+
hierarchyLevelDetails && onFilter?.(hierarchyLevelDetails);
|
|
20
|
+
}, [node, getHierarchyLevelDetails, onFilter]);
|
|
21
|
+
if (!onFilter || !node.isFilterable) {
|
|
22
|
+
return reserveSpace ? _jsx(Tree.ItemAction, { label: filterHierarchyLevel, icon: filterSvg, visible: false, disabled: true }) : undefined;
|
|
23
|
+
}
|
|
24
|
+
return (_jsx(Tree.ItemAction, { label: filterHierarchyLevel, onClick: handleClick, icon: filterSvg, visible: node.isFiltered ? true : undefined, dot: node.isFiltered ? filterHierarchyLevelActiveDescription : undefined }));
|
|
25
|
+
});
|
|
26
|
+
//# sourceMappingURL=FilterAction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FilterAction.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/FilterAction.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,SAAS,MAAM,6BAA6B,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAG7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAgBlE;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,YAAY,CAAC,EACrD,IAAI,EACJ,QAAQ,EACR,wBAAwB,EACxB,YAAY,GAC4C;IACxD,MAAM,EAAE,gBAAgB,EAAE,GAAG,sBAAsB,EAAE,CAAC;IACtD,MAAM,EAAE,oBAAoB,EAAE,qCAAqC,EAAE,GAAG,gBAAgB,CAAC;IAEzF,MAAM,WAAW,GAAG,WAAW,CAAC,GAAG,EAAE;QACnC,MAAM,qBAAqB,GAAG,wBAAwB,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAClE,qBAAqB,IAAI,QAAQ,EAAE,CAAC,qBAAqB,CAAC,CAAC;IAC7D,CAAC,EAAE,CAAC,IAAI,EAAE,wBAAwB,EAAE,QAAQ,CAAC,CAAC,CAAC;IAE/C,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;QACpC,OAAO,YAAY,CAAC,CAAC,CAAC,KAAC,IAAI,CAAC,UAAU,IAAC,KAAK,EAAE,oBAAoB,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,SAAG,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/H,CAAC;IAED,OAAO,CACL,KAAC,IAAI,CAAC,UAAU,IACd,KAAK,EAAE,oBAAoB,EAC3B,OAAO,EAAE,WAAW,EACpB,IAAI,EAAE,SAAS,EACf,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,EAC3C,GAAG,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,qCAAqC,CAAC,CAAC,CAAC,SAAS,GACxE,CACH,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { memo, useCallback } from \"react\";\nimport filterSvg from \"@stratakit/icons/filter.svg\";\nimport { Tree } from \"@stratakit/structures\";\nimport { HierarchyLevelDetails, TreeRendererProps } from \"../Renderers.js\";\nimport { PresentationHierarchyNode } from \"../TreeNode.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\n\n/** @alpha */\nexport type FilterActionProps = {\n /** Action to perform when the filter button is clicked for this node. */\n onFilter?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;\n /**\n * Indicates that space for this action button should be reserved, even when the action is not available.\n * For nodes that don't support filtering, `<FilterAction reserveSpace />` renders:\n *\n * - Blank space when the action is used as an inline action. It's recommended to set this prop to keep all action buttons of the same kind vertically aligned.\n * - Disabled menu item when the action is used as a menu action.\n */\n reserveSpace?: true;\n} & Pick<TreeRendererProps, \"getHierarchyLevelDetails\">;\n\n/**\n * React component that renders a filter action for a tree item.\n * @alpha\n */\nexport const FilterAction = memo(function FilterAction({\n node,\n onFilter,\n getHierarchyLevelDetails,\n reserveSpace,\n}: FilterActionProps & { node: PresentationHierarchyNode }) {\n const { localizedStrings } = useLocalizationContext();\n const { filterHierarchyLevel, filterHierarchyLevelActiveDescription } = localizedStrings;\n\n const handleClick = useCallback(() => {\n const hierarchyLevelDetails = getHierarchyLevelDetails?.(node.id);\n hierarchyLevelDetails && onFilter?.(hierarchyLevelDetails);\n }, [node, getHierarchyLevelDetails, onFilter]);\n\n if (!onFilter || !node.isFilterable) {\n return reserveSpace ? <Tree.ItemAction label={filterHierarchyLevel} icon={filterSvg} visible={false} disabled /> : undefined;\n }\n\n return (\n <Tree.ItemAction\n label={filterHierarchyLevel}\n onClick={handleClick}\n icon={filterSvg}\n visible={node.isFiltered ? true : undefined}\n dot={node.isFiltered ? filterHierarchyLevelActiveDescription : undefined}\n />\n );\n});\n"]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { PresentationHierarchyNode } from "../TreeNode.js";
|
|
2
|
+
/**
|
|
3
|
+
* Placeholder item that is added to hierarchy as a child for a parent item while its child items are loading.
|
|
4
|
+
*
|
|
5
|
+
* @alpha
|
|
6
|
+
* */
|
|
7
|
+
interface FlatPlaceholderItem {
|
|
8
|
+
id: string;
|
|
9
|
+
level: number;
|
|
10
|
+
placeholder: true;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* An item containing `PresentationHierarchyNode` node with properties needed for a flat tree structure.
|
|
14
|
+
*
|
|
15
|
+
* @alpha
|
|
16
|
+
*/
|
|
17
|
+
export interface FlatTreeNodeItem {
|
|
18
|
+
id: string;
|
|
19
|
+
level: number;
|
|
20
|
+
levelSize: number;
|
|
21
|
+
posInLevel: number;
|
|
22
|
+
node: PresentationHierarchyNode;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* An item used to build an error message.
|
|
26
|
+
* Returned by `useErrorList`.
|
|
27
|
+
*
|
|
28
|
+
* @alpha
|
|
29
|
+
* */
|
|
30
|
+
export interface ErrorItem {
|
|
31
|
+
errorNode: PresentationHierarchyNode & Pick<Required<PresentationHierarchyNode>, "error">;
|
|
32
|
+
expandTo: (expandNode: (nodeId: string) => void) => void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* An Item describing single tree item position and its content inside tree.
|
|
36
|
+
* Returned by `useFlatTreeNodeList` hook.
|
|
37
|
+
*
|
|
38
|
+
* @alpha
|
|
39
|
+
*/
|
|
40
|
+
export type FlatTreeItem = FlatTreeNodeItem | FlatPlaceholderItem;
|
|
41
|
+
/** @alpha */
|
|
42
|
+
export declare function isPlaceholderItem(item: FlatTreeItem): item is FlatPlaceholderItem;
|
|
43
|
+
/**
|
|
44
|
+
* Used to get a list of `FlatTreeItem` objects for the given list of `PresentationHierarchyNode` objects that represent
|
|
45
|
+
* a hierarchical structure. The resulting items can be used to render the hierarchy in a flat manner, e.g. using a
|
|
46
|
+
* virtualized list.
|
|
47
|
+
*
|
|
48
|
+
* @alpha
|
|
49
|
+
*/
|
|
50
|
+
export declare function useFlatTreeItems(rootNodes: PresentationHierarchyNode[]): FlatTreeItem[];
|
|
51
|
+
/**
|
|
52
|
+
* Finds and returns all items containing errors in a given hierarchy in the form of `ErrorItem[]`.
|
|
53
|
+
*
|
|
54
|
+
* @alpha
|
|
55
|
+
*/
|
|
56
|
+
export declare function useErrorList(rootNodes: PresentationHierarchyNode[]): ErrorItem[];
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=FlatTreeNode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FlatTreeNode.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/FlatTreeNode.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAE3D;;;;KAIK;AACL,UAAU,mBAAmB;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,IAAI,CAAC;CACnB;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,yBAAyB,CAAC;CACjC;AAED;;;;;KAKK;AACL,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,yBAAyB,GAAG,IAAI,CAAC,QAAQ,CAAC,yBAAyB,CAAC,EAAE,OAAO,CAAC,CAAC;IAC1F,QAAQ,EAAE,CAAC,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,KAAK,IAAI,CAAC;CAC1D;AAED;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GAAG,gBAAgB,GAAG,mBAAmB,CAAC;AAElE,aAAa;AACb,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,IAAI,mBAAmB,CAEjF;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,yBAAyB,EAAE,kBAEtE;AAoBD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,yBAAyB,EAAE,GAAG,SAAS,EAAE,CAchF"}
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
import { useMemo } from "react";
|
|
6
|
+
/** @alpha */
|
|
7
|
+
export function isPlaceholderItem(item) {
|
|
8
|
+
return "placeholder" in item;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Used to get a list of `FlatTreeItem` objects for the given list of `PresentationHierarchyNode` objects that represent
|
|
12
|
+
* a hierarchical structure. The resulting items can be used to render the hierarchy in a flat manner, e.g. using a
|
|
13
|
+
* virtualized list.
|
|
14
|
+
*
|
|
15
|
+
* @alpha
|
|
16
|
+
*/
|
|
17
|
+
export function useFlatTreeItems(rootNodes) {
|
|
18
|
+
return useMemo(() => getFlatItems(rootNodes, 1), [rootNodes]);
|
|
19
|
+
}
|
|
20
|
+
function getFlatItems(nodes, level) {
|
|
21
|
+
const flatItems = [];
|
|
22
|
+
nodes.forEach((node, index) => {
|
|
23
|
+
flatItems.push({ node, id: node.id, level, levelSize: nodes.length, posInLevel: index + 1 });
|
|
24
|
+
if (!node.isExpanded || node.error) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (node.children !== true) {
|
|
28
|
+
const childNodes = getFlatItems(node.children, level + 1);
|
|
29
|
+
flatItems.push(...childNodes);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
flatItems.push({ id: `${node.id}-children-placeholder`, level: level + 1, placeholder: true });
|
|
33
|
+
});
|
|
34
|
+
return flatItems;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Finds and returns all items containing errors in a given hierarchy in the form of `ErrorItem[]`.
|
|
38
|
+
*
|
|
39
|
+
* @alpha
|
|
40
|
+
*/
|
|
41
|
+
export function useErrorList(rootNodes) {
|
|
42
|
+
return useMemo(() => rootNodes.flatMap((rootNode) => {
|
|
43
|
+
if (isErrorNode(rootNode)) {
|
|
44
|
+
return [{ errorNode: rootNode, expandTo: (expandNode) => expandTo(expandNode, []) }];
|
|
45
|
+
}
|
|
46
|
+
if (rootNode.children === true) {
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
return getErrorItems(rootNode, !rootNode.isExpanded ? [rootNode.id] : []);
|
|
50
|
+
}), [rootNodes]);
|
|
51
|
+
}
|
|
52
|
+
function getErrorItems(parent, path) {
|
|
53
|
+
const errorList = [];
|
|
54
|
+
if (parent.children === true) {
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
const pathToChild = [...path, ...(!parent.isExpanded ? [parent.id] : [])];
|
|
58
|
+
parent.children.forEach((node) => {
|
|
59
|
+
if (isErrorNode(node)) {
|
|
60
|
+
errorList.push({ errorNode: node, expandTo: (expandNode) => expandTo(expandNode, path) });
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (node.children !== true) {
|
|
64
|
+
const childErrorList = getErrorItems(node, pathToChild);
|
|
65
|
+
errorList.push(...childErrorList);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return errorList;
|
|
70
|
+
}
|
|
71
|
+
function expandTo(expandNode, path) {
|
|
72
|
+
path.forEach((nodeId) => expandNode(nodeId));
|
|
73
|
+
}
|
|
74
|
+
function isErrorNode(node) {
|
|
75
|
+
return node.error !== undefined;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=FlatTreeNode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FlatTreeNode.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/FlatTreeNode.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAA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C,CAAC;YAC1F,OAAO;QACT,CAAC;QAED,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;YAC3B,MAAM,cAAc,GAAG,aAAa,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;YACxD,SAAS,CAAC,IAAI,CAAC,GAAG,cAAc,CAAC,CAAC;YAClC,OAAO;QACT,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,SAAS,QAAQ,CAAC,UAAoC,EAAE,IAAc;IACpE,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED,SAAS,WAAW,CAAC,IAA+B;IAClD,OAAO,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC;AAClC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { useMemo } from \"react\";\nimport { PresentationHierarchyNode } from \"../TreeNode.js\";\n\n/**\n * Placeholder item that is added to hierarchy as a child for a parent item while its child items are loading.\n *\n * @alpha\n * */\ninterface FlatPlaceholderItem {\n id: string;\n level: number;\n placeholder: true;\n}\n\n/**\n * An item containing `PresentationHierarchyNode` node with properties needed for a flat tree structure.\n *\n * @alpha\n */\nexport interface FlatTreeNodeItem {\n id: string;\n level: number;\n levelSize: number;\n posInLevel: number;\n node: PresentationHierarchyNode;\n}\n\n/**\n * An item used to build an error message.\n * Returned by `useErrorList`.\n *\n * @alpha\n * */\nexport interface ErrorItem {\n errorNode: PresentationHierarchyNode & Pick<Required<PresentationHierarchyNode>, \"error\">;\n expandTo: (expandNode: (nodeId: string) => void) => void;\n}\n\n/**\n * An Item describing single tree item position and its content inside tree.\n * Returned by `useFlatTreeNodeList` hook.\n *\n * @alpha\n */\nexport type FlatTreeItem = FlatTreeNodeItem | FlatPlaceholderItem;\n\n/** @alpha */\nexport function isPlaceholderItem(item: FlatTreeItem): item is FlatPlaceholderItem {\n return \"placeholder\" in item;\n}\n\n/**\n * Used to get a list of `FlatTreeItem` objects for the given list of `PresentationHierarchyNode` objects that represent\n * a hierarchical structure. The resulting items can be used to render the hierarchy in a flat manner, e.g. using a\n * virtualized list.\n *\n * @alpha\n */\nexport function useFlatTreeItems(rootNodes: PresentationHierarchyNode[]) {\n return useMemo(() => getFlatItems(rootNodes, 1), [rootNodes]);\n}\n\nfunction getFlatItems(nodes: PresentationHierarchyNode[], level: number) {\n const flatItems: FlatTreeItem[] = [];\n nodes.forEach((node, index) => {\n flatItems.push({ node, id: node.id, level, levelSize: nodes.length, posInLevel: index + 1 });\n if (!node.isExpanded || node.error) {\n return;\n }\n if (node.children !== true) {\n const childNodes = getFlatItems(node.children, level + 1);\n flatItems.push(...childNodes);\n return;\n }\n\n flatItems.push({ id: `${node.id}-children-placeholder`, level: level + 1, placeholder: true } satisfies FlatPlaceholderItem);\n });\n return flatItems;\n}\n\n/**\n * Finds and returns all items containing errors in a given hierarchy in the form of `ErrorItem[]`.\n *\n * @alpha\n */\nexport function useErrorList(rootNodes: PresentationHierarchyNode[]): ErrorItem[] {\n return useMemo(\n () =>\n rootNodes.flatMap((rootNode) => {\n if (isErrorNode(rootNode)) {\n return [{ errorNode: rootNode, expandTo: (expandNode) => expandTo(expandNode, []) }];\n }\n if (rootNode.children === true) {\n return [];\n }\n return getErrorItems(rootNode, !rootNode.isExpanded ? [rootNode.id] : []);\n }),\n [rootNodes],\n );\n}\n\nfunction getErrorItems(parent: PresentationHierarchyNode, path: string[]) {\n const errorList: ErrorItem[] = [];\n\n if (parent.children === true) {\n return [];\n }\n\n const pathToChild = [...path, ...(!parent.isExpanded ? [parent.id] : [])];\n parent.children.forEach((node) => {\n if (isErrorNode(node)) {\n errorList.push({ errorNode: node, expandTo: (expandNode) => expandTo(expandNode, path) });\n return;\n }\n\n if (node.children !== true) {\n const childErrorList = getErrorItems(node, pathToChild);\n errorList.push(...childErrorList);\n return;\n }\n });\n return errorList;\n}\n\nfunction expandTo(expandNode: (nodeId: string) => void, path: string[]) {\n path.forEach((nodeId) => expandNode(nodeId));\n}\n\nfunction isErrorNode(node: PresentationHierarchyNode): node is PresentationHierarchyNode & Pick<Required<PresentationHierarchyNode>, \"error\"> {\n return node.error !== undefined;\n}\n"]}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { PropsWithChildren } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Localized strings used in the components.
|
|
4
|
+
* @public
|
|
5
|
+
*/
|
|
6
|
+
export interface LocalizedStrings {
|
|
7
|
+
/**
|
|
8
|
+
* Message displayed when nodes are loading.
|
|
9
|
+
* Default value: `Loading...`.
|
|
10
|
+
*/
|
|
11
|
+
loading: string;
|
|
12
|
+
/**
|
|
13
|
+
* Title for apply hierarchy filter button.
|
|
14
|
+
* Default value: `Apply filter`.
|
|
15
|
+
*/
|
|
16
|
+
filterHierarchyLevel: string;
|
|
17
|
+
/**
|
|
18
|
+
* Accessible description for applied hierarchy filter button.
|
|
19
|
+
* Default value: `Filter is applied`.
|
|
20
|
+
*/
|
|
21
|
+
filterHierarchyLevelActiveDescription: string;
|
|
22
|
+
/**
|
|
23
|
+
* Title for clear hierarchy filter button.
|
|
24
|
+
* Default value: `Clear active filter`.
|
|
25
|
+
*/
|
|
26
|
+
clearHierarchyLevelFilter: string;
|
|
27
|
+
/**
|
|
28
|
+
* Message displayed when no nodes matching filter are found.
|
|
29
|
+
* Default value: `No matches for current filter for {{node}}.`.
|
|
30
|
+
*/
|
|
31
|
+
noFilteredChildren: string;
|
|
32
|
+
/**
|
|
33
|
+
* Label for change filter action.
|
|
34
|
+
* Default value: `Change filter`.
|
|
35
|
+
*/
|
|
36
|
+
noFilteredChildrenChangeFilter: string;
|
|
37
|
+
/**
|
|
38
|
+
* Message displayed when hierarchy creation for a node failed.
|
|
39
|
+
* Default value: `Failed to create hierarchy for {{node}}.`.
|
|
40
|
+
*/
|
|
41
|
+
failedToCreateHierarchy: string;
|
|
42
|
+
/**
|
|
43
|
+
* Message displayed when hierarchy creation for a node failed.
|
|
44
|
+
* Default value: `Failed to load tree.`.
|
|
45
|
+
*/
|
|
46
|
+
failedToCreateRootHierarchy: string;
|
|
47
|
+
/**
|
|
48
|
+
* Message displayed when result limit exceeds hierarchy size limit.
|
|
49
|
+
* Default value: `The hierarchy for {{node}} contains {{limit}}+ items. Try using filters or increase the limit.`.
|
|
50
|
+
*/
|
|
51
|
+
resultLimitExceeded: string;
|
|
52
|
+
/**
|
|
53
|
+
* Message displayed when result limit exceeds hierarchy size limit.
|
|
54
|
+
* Default value: `The root item hierarchy contains {{limit}}+ items. Try increasing the limit.`.
|
|
55
|
+
*/
|
|
56
|
+
rootResultLimitExceeded: string;
|
|
57
|
+
/**
|
|
58
|
+
* Name for the error region landmark.
|
|
59
|
+
* Default value: `Issues for {{tree_label}}.`.
|
|
60
|
+
*/
|
|
61
|
+
issuesForTree: string;
|
|
62
|
+
/**
|
|
63
|
+
* Label displayed on the error region, when errors are detected.
|
|
64
|
+
* Default value: `{{number_of_issues}} issue(s) found.`.
|
|
65
|
+
*/
|
|
66
|
+
issuesFound: string;
|
|
67
|
+
/**
|
|
68
|
+
* Label displayed on the error region, when no issues are found.
|
|
69
|
+
* Default value: `No issues found.`.
|
|
70
|
+
*/
|
|
71
|
+
noIssuesFound: string;
|
|
72
|
+
/**
|
|
73
|
+
* Message displayed when hierarchy size limit can be overridden.
|
|
74
|
+
* Default value: `Increase limit to {{limit}}`.
|
|
75
|
+
*/
|
|
76
|
+
increaseHierarchyLimit: string;
|
|
77
|
+
/**
|
|
78
|
+
* Message displayed when hierarchy size limit can be overridden.
|
|
79
|
+
* Default value: `Remove limit`.
|
|
80
|
+
*/
|
|
81
|
+
increaseHierarchyLimitToUnlimited: string;
|
|
82
|
+
/**
|
|
83
|
+
* Message displayed when hierarchy size limit can be overridden and hierarchy filtering is enabled.
|
|
84
|
+
* Default value: `Add Filter`.
|
|
85
|
+
*/
|
|
86
|
+
increaseHierarchyLimitWithFiltering: string;
|
|
87
|
+
/**
|
|
88
|
+
* Label for retry action.
|
|
89
|
+
* Default value: `Retry`.
|
|
90
|
+
*/
|
|
91
|
+
retry: string;
|
|
92
|
+
/**
|
|
93
|
+
* Label for rename action.
|
|
94
|
+
* Default value: `Rename`.
|
|
95
|
+
*/
|
|
96
|
+
rename: string;
|
|
97
|
+
/**
|
|
98
|
+
* Label for more actions button.
|
|
99
|
+
* Default value: `More`.
|
|
100
|
+
*/
|
|
101
|
+
more: string;
|
|
102
|
+
}
|
|
103
|
+
/** @internal */
|
|
104
|
+
export interface LocalizationContext {
|
|
105
|
+
localizedStrings: LocalizedStrings;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Properties for `LocalizationContextProvider`.
|
|
109
|
+
* @public
|
|
110
|
+
*/
|
|
111
|
+
interface LocalizationContextProviderProps {
|
|
112
|
+
/** Localized strings used in the components. */
|
|
113
|
+
localizedStrings?: Partial<LocalizedStrings>;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Context provider for localized strings used in the components.
|
|
117
|
+
* @public
|
|
118
|
+
*/
|
|
119
|
+
export declare function LocalizationContextProvider({ localizedStrings, children }: PropsWithChildren<LocalizationContextProviderProps>): import("react/jsx-runtime").JSX.Element;
|
|
120
|
+
/** @internal */
|
|
121
|
+
export declare function useLocalizationContext(): LocalizationContext;
|
|
122
|
+
export {};
|
|
123
|
+
//# sourceMappingURL=LocalizationContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalizationContext.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/LocalizationContext.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAiB,iBAAiB,EAAmC,MAAM,OAAO,CAAC;AAE1F;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;O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23 @@ import { createContext, useContext, useEffect, useState } from "react";
|
|
|
7
7
|
const defaultLocalizedStrings = {
|
|
8
8
|
loading: "Loading...",
|
|
9
9
|
filterHierarchyLevel: "Apply filter",
|
|
10
|
+
filterHierarchyLevelActiveDescription: "Filter is applied",
|
|
10
11
|
clearHierarchyLevelFilter: "Clear active filter",
|
|
11
|
-
noFilteredChildren: "No
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
noFilteredChildren: "No matches for current filter for {{node}}.",
|
|
13
|
+
noFilteredChildrenChangeFilter: "Change filter",
|
|
14
|
+
failedToCreateHierarchy: "Failed to create hierarchy for {{node}}.",
|
|
15
|
+
failedToCreateRootHierarchy: "Failed to load tree.",
|
|
16
|
+
resultLimitExceeded: "The hierarchy for {{node}} contains {{limit}}+ items. Try using filters or increase the limit.",
|
|
17
|
+
rootResultLimitExceeded: "The root item hierarchy contains {{limit}}+ items. Try increasing the limit.",
|
|
18
|
+
issuesForTree: "Issues for {{tree_label}}.",
|
|
19
|
+
issuesFound: "{{number_of_issues}} issue(s) found.",
|
|
20
|
+
noIssuesFound: "No issues found.",
|
|
21
|
+
increaseHierarchyLimit: "Increase limit to {{limit}}",
|
|
22
|
+
increaseHierarchyLimitToUnlimited: "Remove limit",
|
|
23
|
+
increaseHierarchyLimitWithFiltering: "Add Filter",
|
|
16
24
|
retry: "Retry",
|
|
25
|
+
rename: "Rename",
|
|
26
|
+
more: "More",
|
|
17
27
|
};
|
|
18
28
|
const localizationContext = createContext({ localizedStrings: defaultLocalizedStrings });
|
|
19
29
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LocalizationContext.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/LocalizationContext.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,aAAa,EAAqB,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AA6G1F,M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,CAAC;AACzC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { createContext, PropsWithChildren, useContext, useEffect, useState } from \"react\";\n\n/**\n * Localized strings used in the components.\n * @public\n */\nexport interface LocalizedStrings {\n /**\n * Message displayed when nodes are loading.\n * Default value: `Loading...`.\n */\n loading: string;\n /**\n * Title for apply hierarchy filter button.\n * Default value: `Apply filter`.\n */\n filterHierarchyLevel: string;\n /**\n * Accessible description for applied hierarchy filter button.\n * Default value: `Filter is applied`.\n */\n filterHierarchyLevelActiveDescription: string;\n /**\n * Title for clear hierarchy filter button.\n * Default value: `Clear active filter`.\n */\n clearHierarchyLevelFilter: string;\n /**\n * Message displayed when no nodes matching filter are found.\n * Default value: `No matches for current filter for {{node}}.`.\n */\n noFilteredChildren: string;\n /**\n * Label for change filter action.\n * Default value: `Change filter`.\n */\n noFilteredChildrenChangeFilter: string;\n /**\n * Message displayed when hierarchy creation for a node failed.\n * Default value: `Failed to create hierarchy for {{node}}.`.\n */\n failedToCreateHierarchy: string;\n /**\n * Message displayed when hierarchy creation for a node failed.\n * Default value: `Failed to load tree.`.\n */\n failedToCreateRootHierarchy: string;\n /**\n * Message displayed when result limit exceeds hierarchy size limit.\n * Default value: `The hierarchy for {{node}} contains {{limit}}+ items. Try using filters or increase the limit.`.\n */\n resultLimitExceeded: string;\n /**\n * Message displayed when result limit exceeds hierarchy size limit.\n * Default value: `The root item hierarchy contains {{limit}}+ items. Try increasing the limit.`.\n */\n rootResultLimitExceeded: string;\n /**\n * Name for the error region landmark.\n * Default value: `Issues for {{tree_label}}.`.\n */\n issuesForTree: string;\n /**\n * Label displayed on the error region, when errors are detected.\n * Default value: `{{number_of_issues}} issue(s) found.`.\n */\n issuesFound: string;\n /**\n * Label displayed on the error region, when no issues are found.\n * Default value: `No issues found.`.\n */\n noIssuesFound: string;\n /**\n * Message displayed when hierarchy size limit can be overridden.\n * Default value: `Increase limit to {{limit}}`.\n */\n increaseHierarchyLimit: string;\n /**\n * Message displayed when hierarchy size limit can be overridden.\n * Default value: `Remove limit`.\n */\n increaseHierarchyLimitToUnlimited: string;\n /**\n * Message displayed when hierarchy size limit can be overridden and hierarchy filtering is enabled.\n * Default value: `Add Filter`.\n */\n increaseHierarchyLimitWithFiltering: string;\n /**\n * Label for retry action.\n * Default value: `Retry`.\n */\n retry: string;\n /**\n * Label for rename action.\n * Default value: `Rename`.\n */\n rename: string;\n /**\n * Label for more actions button.\n * Default value: `More`.\n */\n more: string;\n}\n\n/** @internal */\nexport interface LocalizationContext {\n localizedStrings: LocalizedStrings;\n}\n\nconst defaultLocalizedStrings: LocalizedStrings = {\n loading: \"Loading...\",\n filterHierarchyLevel: \"Apply filter\",\n filterHierarchyLevelActiveDescription: \"Filter is applied\",\n clearHierarchyLevelFilter: \"Clear active filter\",\n noFilteredChildren: \"No matches for current filter for {{node}}.\",\n noFilteredChildrenChangeFilter: \"Change filter\",\n failedToCreateHierarchy: \"Failed to create hierarchy for {{node}}.\",\n failedToCreateRootHierarchy: \"Failed to load tree.\",\n resultLimitExceeded: \"The hierarchy for {{node}} contains {{limit}}+ items. Try using filters or increase the limit.\",\n rootResultLimitExceeded: \"The root item hierarchy contains {{limit}}+ items. Try increasing the limit.\",\n issuesForTree: \"Issues for {{tree_label}}.\",\n issuesFound: \"{{number_of_issues}} issue(s) found.\",\n noIssuesFound: \"No issues found.\",\n increaseHierarchyLimit: \"Increase limit to {{limit}}\",\n increaseHierarchyLimitToUnlimited: \"Remove limit\",\n increaseHierarchyLimitWithFiltering: \"Add Filter\",\n retry: \"Retry\",\n rename: \"Rename\",\n more: \"More\",\n};\n\nconst localizationContext = createContext<LocalizationContext>({ localizedStrings: defaultLocalizedStrings });\n\n/**\n * Properties for `LocalizationContextProvider`.\n * @public\n */\ninterface LocalizationContextProviderProps {\n /** Localized strings used in the components. */\n localizedStrings?: Partial<LocalizedStrings>;\n}\n\n/**\n * Context provider for localized strings used in the components.\n * @public\n */\nexport function LocalizationContextProvider({ localizedStrings, children }: PropsWithChildren<LocalizationContextProviderProps>) {\n const [state, setState] = useState({ localizedStrings: { ...defaultLocalizedStrings, ...localizedStrings } });\n\n useEffect(() => {\n setState({ localizedStrings: { ...defaultLocalizedStrings, ...localizedStrings } });\n }, [localizedStrings]);\n\n return <localizationContext.Provider value={state}>{children}</localizationContext.Provider>;\n}\n\n/** @internal */\nexport function useLocalizationContext() {\n return useContext(localizationContext);\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { PropsWithChildren } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* @alpha
|
|
4
|
+
*/
|
|
5
|
+
interface RenameActionProps {
|
|
6
|
+
/**
|
|
7
|
+
* Indicates that space for this action button should be reserved, even when the action is not available.
|
|
8
|
+
* For nodes that don't support renaming, `<RenameAction reserveSpace />` renders:
|
|
9
|
+
*
|
|
10
|
+
* - Blank space when the action is used as an inline action. It's recommended to set this prop to keep all action buttons of the same kind vertically aligned.
|
|
11
|
+
* - Disabled menu item when the action is used as a menu action.
|
|
12
|
+
*/
|
|
13
|
+
reserveSpace?: true;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* React component that renders a rename action for a tree item.
|
|
17
|
+
* The tree component must have `getEditingProps.onLabelChanged` prop set to enable renaming functionality. When the rename is completed, the `onLabelChanged` function is called to make the actual data update.
|
|
18
|
+
* @alpha
|
|
19
|
+
*/
|
|
20
|
+
export declare const RenameAction: import("react").NamedExoticComponent<RenameActionProps>;
|
|
21
|
+
interface RenameContext {
|
|
22
|
+
isRenaming: boolean;
|
|
23
|
+
setIsRenaming: (isRenaming: boolean) => void;
|
|
24
|
+
onLabelChanged?: (newLabel: string) => void;
|
|
25
|
+
}
|
|
26
|
+
/** @internal */
|
|
27
|
+
export declare const useRenameContext: () => RenameContext | undefined;
|
|
28
|
+
/** @alpha */
|
|
29
|
+
export declare function RenameContextProvider({ onLabelChanged, children }: PropsWithChildren<{
|
|
30
|
+
onLabelChanged?: (newLabel: string) => void;
|
|
31
|
+
}>): import("react/jsx-runtime").JSX.Element;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=RenameAction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RenameAction.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/RenameAction.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAuB,iBAAiB,EAA8C,MAAM,OAAO,CAAC;AAK3G;;GAEG;AACH,UAAU,iBAAiB;IACzB;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,IAAI,CAAC;CACrB;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,yDAevB,CAAC;AAEH,UAAU,aAAa;IACrB,UAAU,EAAE,OAAO,CAAC;IACpB,aAAa,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,IAAI,CAAC;IAC7C,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7C;AAID,gBAAgB;AAChB,eAAO,MAAM,gBAAgB,iCAE5B,CAAC;AAEF,aAAa;AACb,wBAAgB,qBAAqB,CAAC,EAAE,cAAc,EAAE,QAAQ,EAAE,EAAE,iBAAiB,CAAC;IAAE,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;CAAE,CAAC,2CAKrI"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/*---------------------------------------------------------------------------------------------
|
|
3
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
+
*--------------------------------------------------------------------------------------------*/
|
|
6
|
+
import { createContext, memo, useCallback, useContext, useMemo, useState } from "react";
|
|
7
|
+
import renameSvg from "@stratakit/icons/rename.svg";
|
|
8
|
+
import { Tree } from "@stratakit/structures";
|
|
9
|
+
import { useLocalizationContext } from "./LocalizationContext.js";
|
|
10
|
+
/**
|
|
11
|
+
* React component that renders a rename action for a tree item.
|
|
12
|
+
* The tree component must have `getEditingProps.onLabelChanged` prop set to enable renaming functionality. When the rename is completed, the `onLabelChanged` function is called to make the actual data update.
|
|
13
|
+
* @alpha
|
|
14
|
+
*/
|
|
15
|
+
export const RenameAction = memo(function RenameAction({ reserveSpace }) {
|
|
16
|
+
const { localizedStrings } = useLocalizationContext();
|
|
17
|
+
const context = useRenameContext();
|
|
18
|
+
const { rename } = localizedStrings;
|
|
19
|
+
const setIsRenaming = context?.setIsRenaming;
|
|
20
|
+
const handleClick = useCallback(() => {
|
|
21
|
+
setIsRenaming?.(true);
|
|
22
|
+
}, [setIsRenaming]);
|
|
23
|
+
if (!context?.onLabelChanged) {
|
|
24
|
+
return reserveSpace ? _jsx(Tree.ItemAction, { label: rename, icon: renameSvg, visible: false, disabled: true }) : undefined;
|
|
25
|
+
}
|
|
26
|
+
return _jsx(Tree.ItemAction, { label: rename, onClick: handleClick, icon: renameSvg });
|
|
27
|
+
});
|
|
28
|
+
const renameContext = createContext(undefined);
|
|
29
|
+
/** @internal */
|
|
30
|
+
export const useRenameContext = () => {
|
|
31
|
+
return useContext(renameContext);
|
|
32
|
+
};
|
|
33
|
+
/** @alpha */
|
|
34
|
+
export function RenameContextProvider({ onLabelChanged, children }) {
|
|
35
|
+
const [isRenaming, setIsRenaming] = useState(false);
|
|
36
|
+
const value = useMemo(() => ({ isRenaming, setIsRenaming, onLabelChanged }), [isRenaming, onLabelChanged]);
|
|
37
|
+
return _jsx(renameContext.Provider, { value: value, children: children });
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=RenameAction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RenameAction.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/RenameAction.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G,GAAG,EAAE;IACnC,OAAO,UAAU,CAAC,aAAa,CAAC,CAAC;AACnC,CAAC,CAAC;AAEF,aAAa;AACb,MAAM,UAAU,qBAAqB,CAAC,EAAE,cAAc,EAAE,QAAQ,EAAsE;IACpI,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IACpD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,aAAa,EAAE,cAAc,EAAE,CAAC,EAAE,CAAC,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC;IAE3G,OAAO,KAAC,aAAa,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAAG,QAAQ,GAA0B,CAAC;AACnF,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { createContext, memo, PropsWithChildren, useCallback, useContext, useMemo, useState } from \"react\";\nimport renameSvg from \"@stratakit/icons/rename.svg\";\nimport { Tree } from \"@stratakit/structures\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\n\n/**\n * @alpha\n */\ninterface RenameActionProps {\n /**\n * Indicates that space for this action button should be reserved, even when the action is not available.\n * For nodes that don't support renaming, `<RenameAction reserveSpace />` renders:\n *\n * - Blank space when the action is used as an inline action. It's recommended to set this prop to keep all action buttons of the same kind vertically aligned.\n * - Disabled menu item when the action is used as a menu action.\n */\n reserveSpace?: true;\n}\n\n/**\n * React component that renders a rename action for a tree item.\n * The tree component must have `getEditingProps.onLabelChanged` prop set to enable renaming functionality. When the rename is completed, the `onLabelChanged` function is called to make the actual data update.\n * @alpha\n */\nexport const RenameAction = memo(function RenameAction({ reserveSpace }: RenameActionProps) {\n const { localizedStrings } = useLocalizationContext();\n const context = useRenameContext();\n const { rename } = localizedStrings;\n\n const setIsRenaming = context?.setIsRenaming;\n const handleClick = useCallback(() => {\n setIsRenaming?.(true);\n }, [setIsRenaming]);\n\n if (!context?.onLabelChanged) {\n return reserveSpace ? <Tree.ItemAction label={rename} icon={renameSvg} visible={false} disabled /> : undefined;\n }\n\n return <Tree.ItemAction label={rename} onClick={handleClick} icon={renameSvg} />;\n});\n\ninterface RenameContext {\n isRenaming: boolean;\n setIsRenaming: (isRenaming: boolean) => void;\n onLabelChanged?: (newLabel: string) => void;\n}\n\nconst renameContext = createContext<RenameContext | undefined>(undefined);\n\n/** @internal */\nexport const useRenameContext = () => {\n return useContext(renameContext);\n};\n\n/** @alpha */\nexport function RenameContextProvider({ onLabelChanged, children }: PropsWithChildren<{ onLabelChanged?: (newLabel: string) => void }>) {\n const [isRenaming, setIsRenaming] = useState(false);\n const value = useMemo(() => ({ isRenaming, setIsRenaming, onLabelChanged }), [isRenaming, onLabelChanged]);\n\n return <renameContext.Provider value={value}>{children}</renameContext.Provider>;\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { RootErrorRendererProps } from "../Renderers.js";
|
|
2
|
+
import { ErrorInfo } from "../TreeNode.js";
|
|
3
|
+
/**
|
|
4
|
+
* @alpha
|
|
5
|
+
*/
|
|
6
|
+
export type StrataKitRootErrorRendererProps = {
|
|
7
|
+
/** Root error to be displayed */
|
|
8
|
+
error: ErrorInfo;
|
|
9
|
+
} & RootErrorRendererProps;
|
|
10
|
+
/**
|
|
11
|
+
* A component that renders root node error state.
|
|
12
|
+
*
|
|
13
|
+
* @alpha
|
|
14
|
+
*/
|
|
15
|
+
export declare function StrataKitRootErrorRenderer({ error, getHierarchyLevelDetails, reloadTree }: StrataKitRootErrorRendererProps): 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,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C;;GAEG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,iCAAiC;IACjC,KAAK,EAAE,SAAS,CAAC;CAClB,GAAG,sBAAsB,CAAC;AAE3B;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,EAAE,KAAK,EAAE,wBAAwB,EAAE,UAAU,EAAE,EAAE,+BAA+B,2CA+B1H"}
|
|
@@ -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
|
+
* @alpha
|
|
14
|
+
*/
|
|
15
|
+
export function StrataKitRootErrorRenderer({ error, getHierarchyLevelDetails, reloadTree }) {
|
|
16
|
+
const { localizedStrings } = useLocalizationContext();
|
|
17
|
+
if (error.type === "ResultSetTooLarge") {
|
|
18
|
+
const onOverrideLimit = () => getHierarchyLevelDetails(undefined)?.setSizeLimit("unbounded");
|
|
19
|
+
return (_jsx(RootErrorContainer, { message: localizedStrings.rootResultLimitExceeded.replace("{{limit}}", 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,0BAA0B,CAAC,EAAE,KAAK,EAAE,wBAAwB,EAAE,UAAU,EAAmC;IACzH,MAAM,EAAE,gBAAgB,EAAE,GAAG,sBAAsB,EAAE,CAAC;IAEtD,IAAI,KAAK,CAAC,IAAI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,MAAM,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,SAAS,EAAE,CAAC;iBACvC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;gBACd,OAAO,CACL,KAAC,MAAM,IAAoB,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,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 { RootErrorRendererProps } from \"../Renderers.js\";\nimport { ErrorInfo } from \"../TreeNode.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\n\n/**\n * @alpha\n */\nexport type StrataKitRootErrorRendererProps = {\n /** Root error to be displayed */\n error: ErrorInfo;\n} & RootErrorRendererProps;\n\n/**\n * A component that renders root node error state.\n *\n * @alpha\n */\nexport function StrataKitRootErrorRenderer({ error, getHierarchyLevelDetails, reloadTree }: StrataKitRootErrorRendererProps) {\n const { localizedStrings } = useLocalizationContext();\n\n if (error.type === \"ResultSetTooLarge\") {\n const onOverrideLimit = () => getHierarchyLevelDetails(undefined)?.setSizeLimit(\"unbounded\");\n return (\n <RootErrorContainer\n message={localizedStrings.rootResultLimitExceeded.replace(\"{{limit}}\", 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,47 @@
|
|
|
1
|
+
import { ReactElement } from "react";
|
|
2
|
+
import { HierarchyLevelDetails, TreeRendererProps } from "../Renderers.js";
|
|
3
|
+
import { ErrorItemRendererProps } from "./ErrorItemRenderer.js";
|
|
4
|
+
import { ErrorItem } from "./FlatTreeNode.js";
|
|
5
|
+
/**
|
|
6
|
+
* Interface containing error item related actions.
|
|
7
|
+
*
|
|
8
|
+
* @alpha
|
|
9
|
+
*/
|
|
10
|
+
interface TreeErrorItemProps {
|
|
11
|
+
/** A callback to reload a hierarchy level when an error occurs and `retry` button is clicked. */
|
|
12
|
+
reloadTree: (options: {
|
|
13
|
+
parentNodeId: string | undefined;
|
|
14
|
+
state: "reset";
|
|
15
|
+
}) => void;
|
|
16
|
+
/** Action to perform when the filter button is clicked for this node. */
|
|
17
|
+
onFilterClick?: (hierarchyLevelDetails: HierarchyLevelDetails) => void;
|
|
18
|
+
/** Action to perform when an error occurs and node label is clicked in the error message */
|
|
19
|
+
scrollToElement: (errorNode: ErrorItem) => void;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Interface containing building blocks for `TreeErrorRenderer`.
|
|
23
|
+
*
|
|
24
|
+
* @alpha
|
|
25
|
+
*/
|
|
26
|
+
interface TreeErrorRendererOwnProps {
|
|
27
|
+
/**
|
|
28
|
+
* A user friendly display label of the tree. Should be unique within the consuming application,
|
|
29
|
+
* as it's used for creating a unique accessible label for the error region.
|
|
30
|
+
*/
|
|
31
|
+
treeLabel: string;
|
|
32
|
+
/** List of errors to be displayed */
|
|
33
|
+
errorList: ErrorItem[];
|
|
34
|
+
/** Callback to render custom error messages. Component should be wrapped in `ErrorRegion.Item` from `@itwin/itwinui-react` package. */
|
|
35
|
+
renderError?: (props: ErrorItemRendererProps) => ReactElement;
|
|
36
|
+
}
|
|
37
|
+
/** @alpha */
|
|
38
|
+
export type TreeErrorRendererProps = TreeErrorRendererOwnProps & TreeErrorItemProps & Pick<TreeRendererProps, "getHierarchyLevelDetails">;
|
|
39
|
+
/**
|
|
40
|
+
* A component that renders error display dropdown using the `unstable_ErrorRegion` component from `@itwin/itwinui-react`.
|
|
41
|
+
* As input, the component uses a list of `ErrorNode` objects, which are generally created using the `useErrorList` hook.
|
|
42
|
+
*
|
|
43
|
+
* @alpha
|
|
44
|
+
*/
|
|
45
|
+
export declare function TreeErrorRenderer({ treeLabel, errorList, reloadTree, scrollToElement, getHierarchyLevelDetails, onFilterClick, renderError, }: TreeErrorRendererProps): import("react/jsx-runtime").JSX.Element;
|
|
46
|
+
export {};
|
|
47
|
+
//# 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;AAErC,OAAO,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAqB,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACnF,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;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB,qCAAqC;IACrC,SAAS,EAAE,SAAS,EAAE,CAAC;IACvB,uIAAuI;IACvI,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,sBAAsB,KAAK,YAAY,CAAC;CAC/D;AAED,aAAa;AACb,MAAM,MAAM,sBAAsB,GAAG,yBAAyB,GAAG,kBAAkB,GAAG,IAAI,CAAC,iBAAiB,EAAE,0BAA0B,CAAC,CAAC;AAE1I;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,SAAS,EACT,SAAS,EACT,UAAU,EACV,eAAe,EACf,wBAAwB,EACxB,aAAa,EACb,WAAW,GACZ,EAAE,sBAAsB,2CA4BxB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { unstable_ErrorRegion as ErrorRegion } from "@stratakit/structures";
|
|
3
|
+
import { ErrorItemRenderer } from "./ErrorItemRenderer.js";
|
|
4
|
+
import { useLocalizationContext } from "./LocalizationContext.js";
|
|
5
|
+
/**
|
|
6
|
+
* A component that renders error display dropdown using the `unstable_ErrorRegion` component from `@itwin/itwinui-react`.
|
|
7
|
+
* As input, the component uses a list of `ErrorNode` objects, which are generally created using the `useErrorList` hook.
|
|
8
|
+
*
|
|
9
|
+
* @alpha
|
|
10
|
+
*/
|
|
11
|
+
export function TreeErrorRenderer({ treeLabel, errorList, reloadTree, scrollToElement, getHierarchyLevelDetails, onFilterClick, renderError, }) {
|
|
12
|
+
const { localizedStrings } = useLocalizationContext();
|
|
13
|
+
const errorItems = errorList.map((errorItem) => {
|
|
14
|
+
const errorRendererProps = {
|
|
15
|
+
errorItem,
|
|
16
|
+
scrollToElement: () => scrollToElement(errorItem),
|
|
17
|
+
reloadTree,
|
|
18
|
+
getHierarchyLevelDetails,
|
|
19
|
+
onFilterClick,
|
|
20
|
+
};
|
|
21
|
+
if (renderError) {
|
|
22
|
+
return renderError(errorRendererProps);
|
|
23
|
+
}
|
|
24
|
+
return _jsx(ErrorItemRenderer, { ...errorRendererProps }, errorItem.errorNode.id);
|
|
25
|
+
});
|
|
26
|
+
return (_jsx(ErrorRegion.Root, { style: { width: "100%" }, "aria-label": localizedStrings.issuesForTree.replace("{{tree_label}}", treeLabel), label: errorList.length === 0 ? localizedStrings.noIssuesFound : localizedStrings.issuesFound.replace("{{number_of_issues}}", errorList.length.toString()), items: errorItems }));
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=TreeErrorRenderer.js.map
|