@itwin/presentation-hierarchies-react 2.0.0-alpha.53 → 2.0.0-alpha.55
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 +58 -0
- package/README.md +23 -61
- package/lib/presentation-hierarchies-react/Renderers.d.ts +92 -0
- package/lib/presentation-hierarchies-react/Renderers.d.ts.map +1 -0
- package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/TreeNode.d.ts +33 -29
- package/lib/presentation-hierarchies-react/TreeNode.d.ts.map +1 -0
- package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/UseIModelTree.d.ts +28 -17
- package/lib/presentation-hierarchies-react/UseIModelTree.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/UseIModelTree.js +184 -0
- package/lib/presentation-hierarchies-react/UseIModelTree.js.map +1 -0
- package/lib/presentation-hierarchies-react/UseNodeHighlighting.d.ts +30 -0
- package/lib/presentation-hierarchies-react/UseNodeHighlighting.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/UseNodeHighlighting.js +58 -0
- package/lib/presentation-hierarchies-react/UseNodeHighlighting.js.map +1 -0
- package/lib/presentation-hierarchies-react/UseSelectionHandler.d.ts +25 -0
- package/lib/presentation-hierarchies-react/UseSelectionHandler.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/UseSelectionHandler.js +125 -0
- package/lib/presentation-hierarchies-react/UseSelectionHandler.js.map +1 -0
- package/lib/presentation-hierarchies-react/UseTree.d.ts +112 -0
- package/lib/presentation-hierarchies-react/UseTree.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/UseTree.js +294 -0
- package/lib/presentation-hierarchies-react/UseTree.js.map +1 -0
- package/lib/presentation-hierarchies-react/Utils.js +56 -0
- package/lib/presentation-hierarchies-react/Utils.js.map +1 -0
- package/lib/presentation-hierarchies-react/internal/DisposePolyfill.js +10 -0
- package/lib/presentation-hierarchies-react/internal/DisposePolyfill.js.map +1 -0
- package/lib/presentation-hierarchies-react/internal/LocalizedStrings.d.ts +9 -0
- package/lib/presentation-hierarchies-react/internal/LocalizedStrings.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/internal/LocalizedStrings.js +12 -0
- package/lib/presentation-hierarchies-react/internal/LocalizedStrings.js.map +1 -0
- package/lib/presentation-hierarchies-react/internal/TreeActions.js +295 -0
- package/lib/presentation-hierarchies-react/internal/TreeActions.js.map +1 -0
- package/lib/presentation-hierarchies-react/internal/TreeLoader.js +99 -0
- package/lib/presentation-hierarchies-react/internal/TreeLoader.js.map +1 -0
- package/lib/presentation-hierarchies-react/internal/TreeModel.d.ts +3 -0
- package/lib/presentation-hierarchies-react/internal/TreeModel.js +120 -0
- package/lib/presentation-hierarchies-react/internal/TreeModel.js.map +1 -0
- package/lib/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts +37 -0
- package/lib/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/internal/UseUnifiedSelection.js +142 -0
- package/lib/presentation-hierarchies-react/internal/UseUnifiedSelection.js.map +1 -0
- package/lib/presentation-hierarchies-react/internal/Utils.js +43 -0
- package/lib/presentation-hierarchies-react/internal/Utils.js.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts +38 -0
- package/lib/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js +381 -0
- package/lib/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js.map +1 -0
- package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/stratakit/FlatTreeNode.d.ts +16 -15
- package/lib/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/FlatTreeNode.js +91 -0
- package/lib/presentation-hierarchies-react/stratakit/FlatTreeNode.js.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts +24 -0
- package/lib/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/LocalizationContext.js +41 -0
- package/lib/presentation-hierarchies-react/stratakit/LocalizationContext.js.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts +27 -0
- package/lib/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/RootErrorRenderer.js +186 -0
- package/lib/presentation-hierarchies-react/stratakit/RootErrorRenderer.js.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeAction.d.ts +49 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeAction.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeAction.js +89 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeAction.js.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts +38 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js +64 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.d.ts +29 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.js +92 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.js.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.d.ts +33 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js +156 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts +18 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js +535 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts +75 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts.map +1 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeRenderer.js +418 -0
- package/lib/presentation-hierarchies-react/stratakit/TreeRenderer.js.map +1 -0
- package/lib/presentation-hierarchies-react.d.ts +18 -0
- package/lib/presentation-hierarchies-react.js +16 -0
- package/lib/public/locales/en/PresentationHierarchies_1.0.json +26 -0
- package/package.json +27 -21
- package/lib/esm/presentation-hierarchies-react/Renderers.d.ts +0 -85
- package/lib/esm/presentation-hierarchies-react/Renderers.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/Renderers.js +0 -6
- package/lib/esm/presentation-hierarchies-react/Renderers.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/TreeNode.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/TreeNode.js +0 -6
- package/lib/esm/presentation-hierarchies-react/TreeNode.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.js +0 -62
- package/lib/esm/presentation-hierarchies-react/UseIModelTree.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.d.ts +0 -24
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.js +0 -53
- package/lib/esm/presentation-hierarchies-react/UseNodeHighlighting.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.d.ts +0 -48
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.js +0 -83
- package/lib/esm/presentation-hierarchies-react/UseSelectionHandler.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.d.ts +0 -94
- package/lib/esm/presentation-hierarchies-react/UseTree.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/UseTree.js +0 -241
- package/lib/esm/presentation-hierarchies-react/UseTree.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/Utils.d.ts +0 -8
- package/lib/esm/presentation-hierarchies-react/Utils.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/Utils.js +0 -39
- package/lib/esm/presentation-hierarchies-react/Utils.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/internal/DisposePolyfill.d.ts +0 -2
- package/lib/esm/presentation-hierarchies-react/internal/DisposePolyfill.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/internal/DisposePolyfill.js +0 -11
- package/lib/esm/presentation-hierarchies-react/internal/DisposePolyfill.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.d.ts +0 -53
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.js +0 -322
- package/lib/esm/presentation-hierarchies-react/internal/TreeActions.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.d.ts +0 -62
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.js +0 -90
- package/lib/esm/presentation-hierarchies-react/internal/TreeLoader.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.d.ts +0 -47
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.js +0 -157
- package/lib/esm/presentation-hierarchies-react/internal/TreeModel.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts +0 -42
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.js +0 -115
- package/lib/esm/presentation-hierarchies-react/internal/UseUnifiedSelection.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/internal/Utils.d.ts +0 -23
- package/lib/esm/presentation-hierarchies-react/internal/Utils.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/internal/Utils.js +0 -58
- package/lib/esm/presentation-hierarchies-react/internal/Utils.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts +0 -27
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js +0 -74
- package/lib/esm/presentation-hierarchies-react/stratakit/ErrorItemRenderer.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.js +0 -73
- package/lib/esm/presentation-hierarchies-react/stratakit/FlatTreeNode.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts +0 -138
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.js +0 -47
- package/lib/esm/presentation-hierarchies-react/stratakit/LocalizationContext.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts +0 -16
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.js +0 -42
- package/lib/esm/presentation-hierarchies-react/stratakit/RootErrorRenderer.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeAction.d.ts +0 -45
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeAction.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeAction.js +0 -36
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeAction.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts +0 -30
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js +0 -30
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeErrorRenderer.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.d.ts +0 -20
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.js +0 -29
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeFilterAction.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.d.ts +0 -57
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js +0 -71
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts +0 -46
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js +0 -133
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeNodeRenderer.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts +0 -75
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js +0 -193
- package/lib/esm/presentation-hierarchies-react/stratakit/TreeRenderer.js.map +0 -1
- package/lib/esm/presentation-hierarchies-react.d.ts +0 -17
- package/lib/esm/presentation-hierarchies-react.d.ts.map +0 -1
- package/lib/esm/presentation-hierarchies-react.js +0 -18
- package/lib/esm/presentation-hierarchies-react.js.map +0 -1
- /package/lib/{esm/presentation-hierarchies-react → presentation-hierarchies-react}/stratakit/TreeNodeRenderer.css +0 -0
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { PropsWithChildren } from "react";
|
|
2
|
-
import { TreeNode } from "../TreeNode.js";
|
|
3
|
-
import { TreeActionBaseAttributes } from "./TreeAction.js";
|
|
4
|
-
/**
|
|
5
|
-
* React component that renders a rename action for a tree item.
|
|
6
|
-
*
|
|
7
|
-
* The tree component must have `getEditingProps.onLabelChanged` prop set to enable renaming functionality. When
|
|
8
|
-
* rename is completed, the `onLabelChanged` function is called to make the actual data update.
|
|
9
|
-
*
|
|
10
|
-
* @see `getMenuActions`, `getInlineActions`, `getContextMenuActions` props of `TreeRenderer` to add this action
|
|
11
|
-
* to tree items.
|
|
12
|
-
*
|
|
13
|
-
* @alpha
|
|
14
|
-
*/
|
|
15
|
-
export declare const TreeNodeRenameAction: import("react").NamedExoticComponent<TreeActionBaseAttributes & {
|
|
16
|
-
node: TreeNode;
|
|
17
|
-
}>;
|
|
18
|
-
/** @alpha */
|
|
19
|
-
export interface TreeNodeEditingProps {
|
|
20
|
-
/**
|
|
21
|
-
* A callback that is invoked when node label is changed. Should be used together
|
|
22
|
-
* with `<TreeNodeRenameAction />` to enter label editing mode.
|
|
23
|
-
*/
|
|
24
|
-
onLabelChanged: (newLabel: string) => void;
|
|
25
|
-
labelValidationHint?: string;
|
|
26
|
-
validate?: (newLabel: string) => boolean;
|
|
27
|
-
}
|
|
28
|
-
/** @internal */
|
|
29
|
-
export interface RenameParameters {
|
|
30
|
-
nodeId: string;
|
|
31
|
-
commit: (newLabel: string) => void;
|
|
32
|
-
labelValidationHint?: string;
|
|
33
|
-
validate?: (newLabel: string) => boolean;
|
|
34
|
-
}
|
|
35
|
-
interface TreeNodeRenameContext {
|
|
36
|
-
renameParameters?: RenameParameters;
|
|
37
|
-
startRename: (node: TreeNode) => void;
|
|
38
|
-
canRename: (node: TreeNode) => boolean;
|
|
39
|
-
cancelRename: () => void;
|
|
40
|
-
}
|
|
41
|
-
/** @internal */
|
|
42
|
-
export declare const useTreeNodeRenameContext: () => TreeNodeRenameContext | undefined;
|
|
43
|
-
/** @internal */
|
|
44
|
-
export declare function TreeNodeRenameContextProvider({ value, children }: PropsWithChildren<{
|
|
45
|
-
value: TreeNodeRenameContext;
|
|
46
|
-
}>): import("react/jsx-runtime").JSX.Element;
|
|
47
|
-
/** @internal */
|
|
48
|
-
export declare function useTreeNodeRenameContextValue({ getEditingProps }: {
|
|
49
|
-
getEditingProps?: (node: TreeNode) => TreeNodeEditingProps | undefined;
|
|
50
|
-
}): {
|
|
51
|
-
renameParameters: RenameParameters | undefined;
|
|
52
|
-
cancelRename: () => void;
|
|
53
|
-
startRename: (node: TreeNode) => void;
|
|
54
|
-
canRename: (node: TreeNode) => boolean;
|
|
55
|
-
};
|
|
56
|
-
export {};
|
|
57
|
-
//# sourceMappingURL=TreeNodeRenameAction.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TreeNodeRenameAction.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAuB,iBAAiB,EAA8C,MAAM,OAAO,CAAC;AAE3G,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAkB,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAE3E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,oBAAoB;UAAwG,QAAQ;EAY/I,CAAC;AAEH,aAAa;AACb,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,cAAc,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;CAC1C;AAED,gBAAgB;AAChB,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;CAC1C;AAED,UAAU,qBAAqB;IAC7B,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,WAAW,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC;IACtC,SAAS,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,OAAO,CAAC;IACvC,YAAY,EAAE,MAAM,IAAI,CAAC;CAC1B;AAID,gBAAgB;AAChB,eAAO,MAAM,wBAAwB,yCAEpC,CAAC;AAEF,gBAAgB;AAChB,wBAAgB,6BAA6B,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,iBAAiB,CAAC;IAAE,KAAK,EAAE,qBAAqB,CAAA;CAAE,CAAC,2CAErH;AAED,gBAAgB;AAChB,wBAAgB,6BAA6B,CAAC,EAAE,eAAe,EAAE,EAAE;IAAE,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,oBAAoB,GAAG,SAAS,CAAA;CAAE;;;wBAIlI,QAAQ;sBAsBR,QAAQ;EAelB"}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
/*---------------------------------------------------------------------------------------------
|
|
3
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
4
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
5
|
-
*--------------------------------------------------------------------------------------------*/
|
|
6
|
-
import { createContext, memo, useCallback, useContext, useMemo, useState } from "react";
|
|
7
|
-
import renameSvg from "@stratakit/icons/rename.svg";
|
|
8
|
-
import { useLocalizationContext } from "./LocalizationContext.js";
|
|
9
|
-
import { TreeActionBase } from "./TreeAction.js";
|
|
10
|
-
/**
|
|
11
|
-
* React component that renders a rename action for a tree item.
|
|
12
|
-
*
|
|
13
|
-
* The tree component must have `getEditingProps.onLabelChanged` prop set to enable renaming functionality. When
|
|
14
|
-
* rename is completed, the `onLabelChanged` function is called to make the actual data update.
|
|
15
|
-
*
|
|
16
|
-
* @see `getMenuActions`, `getInlineActions`, `getContextMenuActions` props of `TreeRenderer` to add this action
|
|
17
|
-
* to tree items.
|
|
18
|
-
*
|
|
19
|
-
* @alpha
|
|
20
|
-
*/
|
|
21
|
-
export const TreeNodeRenameAction = memo(function TreeNodeRenameAction({ node, ...actionAttributes }) {
|
|
22
|
-
const { localizedStrings } = useLocalizationContext();
|
|
23
|
-
const context = useTreeNodeRenameContext();
|
|
24
|
-
const { rename } = localizedStrings;
|
|
25
|
-
const canRename = context?.canRename(node) ?? false;
|
|
26
|
-
const startRename = context?.startRename;
|
|
27
|
-
const handleClick = useCallback(() => {
|
|
28
|
-
startRename?.(node);
|
|
29
|
-
}, [startRename, node]);
|
|
30
|
-
return _jsx(TreeActionBase, { ...actionAttributes, label: rename, onClick: handleClick, icon: renameSvg, hide: !canRename });
|
|
31
|
-
});
|
|
32
|
-
const treeNodeRenameContext = createContext(undefined);
|
|
33
|
-
/** @internal */
|
|
34
|
-
export const useTreeNodeRenameContext = () => {
|
|
35
|
-
return useContext(treeNodeRenameContext);
|
|
36
|
-
};
|
|
37
|
-
/** @internal */
|
|
38
|
-
export function TreeNodeRenameContextProvider({ value, children }) {
|
|
39
|
-
return _jsx(treeNodeRenameContext.Provider, { value: value, children: children });
|
|
40
|
-
}
|
|
41
|
-
/** @internal */
|
|
42
|
-
export function useTreeNodeRenameContextValue({ getEditingProps }) {
|
|
43
|
-
const [renameParameters, setRenameParameters] = useState(undefined);
|
|
44
|
-
const startRename = useCallback((node) => {
|
|
45
|
-
const { onLabelChanged, labelValidationHint, validate } = getEditingProps?.(node) ?? {};
|
|
46
|
-
if (onLabelChanged) {
|
|
47
|
-
setRenameParameters({
|
|
48
|
-
nodeId: node.id,
|
|
49
|
-
commit: (newLabel) => {
|
|
50
|
-
onLabelChanged(newLabel);
|
|
51
|
-
setRenameParameters(undefined);
|
|
52
|
-
},
|
|
53
|
-
labelValidationHint,
|
|
54
|
-
validate,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}, [getEditingProps]);
|
|
58
|
-
const cancelRename = useCallback(() => {
|
|
59
|
-
setRenameParameters(undefined);
|
|
60
|
-
}, []);
|
|
61
|
-
const canRename = useCallback((node) => {
|
|
62
|
-
return getEditingProps?.(node)?.onLabelChanged !== undefined;
|
|
63
|
-
}, [getEditingProps]);
|
|
64
|
-
return useMemo(() => ({
|
|
65
|
-
renameParameters,
|
|
66
|
-
cancelRename,
|
|
67
|
-
startRename,
|
|
68
|
-
canRename,
|
|
69
|
-
}), [renameParameters, canRename, startRename, cancelRename]);
|
|
70
|
-
}
|
|
71
|
-
//# sourceMappingURL=TreeNodeRenameAction.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TreeNodeRenameAction.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/TreeNodeRenameAction.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,EAAE,aAAa,EAAE,IAAI,EAAqB,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC3G,OAAO,SAAS,MAAM,6BAA6B,CAAC;AAEpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,cAAc,EAA4B,MAAM,iBAAiB,CAAC;AAE3E;;;;;;;;;;GAUG;AACH,MAAM,CAA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AElG,MAAM,WAAW,GAAG,WAAW,CAC7B,CAAC,IAAc,EAAE,EAAE;QACjB,MAAM,EAAE,cAAc,EAAE,mBAAmB,EAAE,QAAQ,EAAE,GAAG,eAAe,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACxF,IAAI,cAAc,EAAE,CAAC;YACnB,mBAAmB,CAAC;gBAClB,MAAM,EAAE,IAAI,CAAC,EAAE;gBACf,MAAM,EAAE,CAAC,QAAQ,EAAE,EAAE;oBACnB,cAAc,CAAC,QAAQ,CAAC,CAAC;oBACzB,mBAAmB,CAAC,SAAS,CAAC,CAAC;gBACjC,CAAC;gBACD,mBAAmB;gBACnB,QAAQ;aACT,CAAC,CAAC;QACL,CAAC;IACH,CAAC,EACD,CAAC,eAAe,CAAC,CAClB,CAAC;IAEF,MAAM,YAAY,GAAG,WAAW,CAAC,GAAG,EAAE;QACpC,mBAAmB,CAAC,SAAS,CAAC,CAAC;IACjC,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,SAAS,GAAG,WAAW,CAC3B,CAAC,IAAc,EAAE,EAAE;QACjB,OAAO,eAAe,EAAE,CAAC,IAAI,CAAC,EAAE,cAAc,KAAK,SAAS,CAAC;IAC/D,CAAC,EACD,CAAC,eAAe,CAAC,CAClB,CAAC;IAEF,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC;QACL,gBAAgB;QAChB,YAAY;QACZ,WAAW;QACX,SAAS;KACV,CAAC,EACF,CAAC,gBAAgB,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,CAAC,CACzD,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 { createContext, memo, PropsWithChildren, useCallback, useContext, useMemo, useState } from \"react\";\nimport renameSvg from \"@stratakit/icons/rename.svg\";\nimport { TreeNode } from \"../TreeNode.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\nimport { TreeActionBase, TreeActionBaseAttributes } from \"./TreeAction.js\";\n\n/**\n * React component that renders a rename action for a tree item.\n *\n * The tree component must have `getEditingProps.onLabelChanged` prop set to enable renaming functionality. When\n * rename is completed, the `onLabelChanged` function is called to make the actual data update.\n *\n * @see `getMenuActions`, `getInlineActions`, `getContextMenuActions` props of `TreeRenderer` to add this action\n * to tree items.\n *\n * @alpha\n */\nexport const TreeNodeRenameAction = memo(function TreeNodeRenameAction({ node, ...actionAttributes }: TreeActionBaseAttributes & { node: TreeNode }) {\n const { localizedStrings } = useLocalizationContext();\n const context = useTreeNodeRenameContext();\n const { rename } = localizedStrings;\n\n const canRename = context?.canRename(node) ?? false;\n const startRename = context?.startRename;\n const handleClick = useCallback(() => {\n startRename?.(node);\n }, [startRename, node]);\n\n return <TreeActionBase {...actionAttributes} label={rename} onClick={handleClick} icon={renameSvg} hide={!canRename} />;\n});\n\n/** @alpha */\nexport interface TreeNodeEditingProps {\n /**\n * A callback that is invoked when node label is changed. Should be used together\n * with `<TreeNodeRenameAction />` to enter label editing mode.\n */\n onLabelChanged: (newLabel: string) => void;\n labelValidationHint?: string;\n validate?: (newLabel: string) => boolean;\n}\n\n/** @internal */\nexport interface RenameParameters {\n nodeId: string;\n commit: (newLabel: string) => void;\n labelValidationHint?: string;\n validate?: (newLabel: string) => boolean;\n}\n\ninterface TreeNodeRenameContext {\n renameParameters?: RenameParameters;\n startRename: (node: TreeNode) => void;\n canRename: (node: TreeNode) => boolean;\n cancelRename: () => void;\n}\n\nconst treeNodeRenameContext = createContext<TreeNodeRenameContext | undefined>(undefined);\n\n/** @internal */\nexport const useTreeNodeRenameContext = () => {\n return useContext(treeNodeRenameContext);\n};\n\n/** @internal */\nexport function TreeNodeRenameContextProvider({ value, children }: PropsWithChildren<{ value: TreeNodeRenameContext }>) {\n return <treeNodeRenameContext.Provider value={value}>{children}</treeNodeRenameContext.Provider>;\n}\n\n/** @internal */\nexport function useTreeNodeRenameContextValue({ getEditingProps }: { getEditingProps?: (node: TreeNode) => TreeNodeEditingProps | undefined }) {\n const [renameParameters, setRenameParameters] = useState<RenameParameters | undefined>(undefined);\n\n const startRename = useCallback(\n (node: TreeNode) => {\n const { onLabelChanged, labelValidationHint, validate } = getEditingProps?.(node) ?? {};\n if (onLabelChanged) {\n setRenameParameters({\n nodeId: node.id,\n commit: (newLabel) => {\n onLabelChanged(newLabel);\n setRenameParameters(undefined);\n },\n labelValidationHint,\n validate,\n });\n }\n },\n [getEditingProps],\n );\n\n const cancelRename = useCallback(() => {\n setRenameParameters(undefined);\n }, []);\n\n const canRename = useCallback(\n (node: TreeNode) => {\n return getEditingProps?.(node)?.onLabelChanged !== undefined;\n },\n [getEditingProps],\n );\n\n return useMemo(\n () => ({\n renameParameters,\n cancelRename,\n startRename,\n canRename,\n }),\n [renameParameters, canRename, startRename, cancelRename],\n );\n}\n"]}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import "./TreeNodeRenderer.css";
|
|
2
|
-
import { ComponentPropsWithoutRef, FC, PropsWithRef, ReactNode, RefAttributes } from "react";
|
|
3
|
-
import { Tree } from "@stratakit/structures";
|
|
4
|
-
import { TreeRendererProps } from "../Renderers.js";
|
|
5
|
-
import { TreeNode } from "../TreeNode.js";
|
|
6
|
-
/** @internal */
|
|
7
|
-
interface TreeNodeRendererOwnProps extends Pick<TreeRendererProps, "expandNode" | "reloadTree"> {
|
|
8
|
-
/** Node that is rendered. */
|
|
9
|
-
node: TreeNode;
|
|
10
|
-
/**
|
|
11
|
-
* Menu actions for tree item.
|
|
12
|
-
* Must be an array of `<TreeActionBase />` or `<Divider />` elements.
|
|
13
|
-
*/
|
|
14
|
-
menuActions?: ReactNode[];
|
|
15
|
-
/**
|
|
16
|
-
* Inline actions for tree item.
|
|
17
|
-
* Must be an array of `<TreeActionBase />` elements.
|
|
18
|
-
* Max 2 items.
|
|
19
|
-
*/
|
|
20
|
-
inlineActions?: ReactNode[];
|
|
21
|
-
/**
|
|
22
|
-
* Context menu actions for tree item.
|
|
23
|
-
* Must be an array of `<TreeActionBase />` or `<Divider />` elements.
|
|
24
|
-
*/
|
|
25
|
-
contextMenuActions?: ReactNode[];
|
|
26
|
-
}
|
|
27
|
-
/** @alpha */
|
|
28
|
-
export type StrataKitTreeItemProps = Omit<ComponentPropsWithoutRef<typeof Tree.Item>, "actions" | "inlineActions" | "expanded" | "onExpandedChange" | "icon" | "unstable_decorations" | "error"> & {
|
|
29
|
-
/**
|
|
30
|
-
* Used to render elements between expander and label.
|
|
31
|
-
* E.g. icons, color picker, etc.
|
|
32
|
-
*/
|
|
33
|
-
decorations?: ReactNode;
|
|
34
|
-
};
|
|
35
|
-
/** @internal */
|
|
36
|
-
export type TreeNodeRendererProps = StrataKitTreeItemProps & TreeNodeRendererOwnProps;
|
|
37
|
-
/**
|
|
38
|
-
* A component that renders given `FlatTreeNode` using the `Tree.Item` component from `@itwin/itwinui-react`. The
|
|
39
|
-
* `FlatTreeNode` objects for this renderer are generally created using the `useFlatTreeNodeList` hook.
|
|
40
|
-
*
|
|
41
|
-
* @internal
|
|
42
|
-
*/
|
|
43
|
-
export declare const StrataKitTreeNodeRenderer: FC<PropsWithRef<TreeNodeRendererProps & RefAttributes<HTMLElement>>>;
|
|
44
|
-
export declare const PlaceholderNode: FC<PropsWithRef<Pick<StrataKitTreeItemProps, "style" | "aria-level" | "aria-posinset" | "aria-setsize"> & RefAttributes<HTMLElement>>>;
|
|
45
|
-
export {};
|
|
46
|
-
//# sourceMappingURL=TreeNodeRenderer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TreeNodeRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/TreeNodeRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,wBAAwB,CAAC;AAEhC,OAAO,EAEL,wBAAwB,EACxB,EAAE,EAIF,YAAY,EACZ,SAAS,EACT,aAAa,EAO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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 "./TreeNodeRenderer.css";
|
|
7
|
-
import { cloneElement, forwardRef, isValidElement, memo, useCallback, useEffect, useId, useMemo, useRef, useState, } from "react";
|
|
8
|
-
import { Description, IconButton, Spinner, Text, TextBox } from "@stratakit/bricks";
|
|
9
|
-
import checkmarkSvg from "@stratakit/icons/checkmark.svg";
|
|
10
|
-
import dismissSvg from "@stratakit/icons/dismiss.svg";
|
|
11
|
-
import refreshSvg from "@stratakit/icons/refresh.svg";
|
|
12
|
-
import { DropdownMenu, unstable_Popover as Popover, Tree } from "@stratakit/structures";
|
|
13
|
-
import { useLocalizationContext } from "./LocalizationContext.js";
|
|
14
|
-
import { TreeActionBase } from "./TreeAction.js";
|
|
15
|
-
import { useTreeNodeRenameContext } from "./TreeNodeRenameAction.js";
|
|
16
|
-
/**
|
|
17
|
-
* A component that renders given `FlatTreeNode` using the `Tree.Item` component from `@itwin/itwinui-react`. The
|
|
18
|
-
* `FlatTreeNode` objects for this renderer are generally created using the `useFlatTreeNodeList` hook.
|
|
19
|
-
*
|
|
20
|
-
* @internal
|
|
21
|
-
*/
|
|
22
|
-
export const StrataKitTreeNodeRenderer = memo(forwardRef(function HierarchyNode(props, forwardedRef) {
|
|
23
|
-
const { node, decorations, inlineActions, menuActions, contextMenuActions, expandNode, reloadTree, ...treeItemProps } = props;
|
|
24
|
-
const { localizedStrings } = useLocalizationContext();
|
|
25
|
-
const renameContext = useTreeNodeRenameContext();
|
|
26
|
-
const [contextMenuProps, setContextMenuProps] = useState(undefined);
|
|
27
|
-
const label = treeItemProps.label ?? node.label;
|
|
28
|
-
const inlineActionItems = useMemo(() => {
|
|
29
|
-
if (node.error !== undefined && node.error.type === "ChildrenLoad") {
|
|
30
|
-
return [
|
|
31
|
-
_jsx(TreeActionBase, { label: localizedStrings.retry, onClick: () => reloadTree({ parentNodeId: node.id, state: "reset" }), visible: true, icon: refreshSvg, variant: "inline" }, "retry"),
|
|
32
|
-
];
|
|
33
|
-
}
|
|
34
|
-
if (!inlineActions) {
|
|
35
|
-
return undefined;
|
|
36
|
-
}
|
|
37
|
-
return injectActionVariant(inlineActions, "inline");
|
|
38
|
-
}, [node, inlineActions, localizedStrings.retry, reloadTree]);
|
|
39
|
-
const menuActionItems = useMemo(() => {
|
|
40
|
-
if (!menuActions) {
|
|
41
|
-
return undefined;
|
|
42
|
-
}
|
|
43
|
-
return injectActionVariant(menuActions, "default");
|
|
44
|
-
}, [menuActions]);
|
|
45
|
-
const expanded = useMemo(() => {
|
|
46
|
-
if (node.error) {
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
// this is a leaf node
|
|
50
|
-
if (node.children !== true && node.children.length === 0) {
|
|
51
|
-
return undefined;
|
|
52
|
-
}
|
|
53
|
-
return node.isExpanded;
|
|
54
|
-
}, [node]);
|
|
55
|
-
const { renameParameters, cancelRename } = renameContext ?? {};
|
|
56
|
-
const labelEditor = (_jsx(LabelEditor, { initialLabel: node.label, onChange: renameParameters?.commit, onCancel: cancelRename, labelValidationHint: renameParameters?.labelValidationHint, validate: renameParameters?.validate }));
|
|
57
|
-
return (_jsxs(_Fragment, { children: [_jsx(Popover, { content: labelEditor, placement: "bottom", open: renameParameters?.nodeId === node.id, setOpen: cancelRename, unmountOnHide: true, children: _jsx(Tree.Item, { ...treeItemProps, ref: forwardedRef, label: label, expanded: expanded, onExpandedChange: useCallback((isExpanded) => {
|
|
58
|
-
expandNode(node.id, isExpanded);
|
|
59
|
-
}, [node, expandNode]), inlineActions: inlineActionItems, actions: menuActionItems, unstable_decorations: decorations, error: node.error ? node.error.id : undefined, onContextMenu: (e) => {
|
|
60
|
-
if (treeItemProps.onContextMenu) {
|
|
61
|
-
treeItemProps.onContextMenu(e);
|
|
62
|
-
}
|
|
63
|
-
if (!contextMenuActions) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
e.preventDefault();
|
|
67
|
-
const actions = injectActionVariant(contextMenuActions, "context-menu");
|
|
68
|
-
if (actions.length === 0) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
setContextMenuProps({
|
|
72
|
-
position: {
|
|
73
|
-
x: e.clientX,
|
|
74
|
-
y: e.clientY,
|
|
75
|
-
},
|
|
76
|
-
actions,
|
|
77
|
-
});
|
|
78
|
-
} }) }), _jsxs(DropdownMenu.Provider, { open: contextMenuProps !== undefined, setOpen: (open) => {
|
|
79
|
-
if (!open) {
|
|
80
|
-
setContextMenuProps(undefined);
|
|
81
|
-
}
|
|
82
|
-
}, children: [contextMenuProps ? (_jsx(DropdownMenu.Button, { style: { position: "fixed", top: contextMenuProps.position.y, left: contextMenuProps.position.x }, render: _jsx("div", {}) })) : null, _jsx(DropdownMenu.Content, { focusable: true, autoFocus: true, children: contextMenuProps?.actions })] }, `${node.id}-${contextMenuProps?.position.x ?? ""}-${contextMenuProps?.position.y ?? ""}`)] }));
|
|
83
|
-
}));
|
|
84
|
-
export const PlaceholderNode = memo(forwardRef(function PlaceholderNode({ ...props }, forwardedRef) {
|
|
85
|
-
const { localizedStrings } = useLocalizationContext();
|
|
86
|
-
return (_jsx(Tree.Item, { ...props, ref: forwardedRef, label: localizedStrings.loading, unstable_decorations: _jsx(Spinner, { size: "small", title: localizedStrings.loading }) }));
|
|
87
|
-
}));
|
|
88
|
-
function LabelEditor({ initialLabel, labelValidationHint, onChange, onCancel, validate, }) {
|
|
89
|
-
const { localizedStrings } = useLocalizationContext();
|
|
90
|
-
const inputRef = useRef(null);
|
|
91
|
-
const [newLabelValue, setNewLabelValue] = useState(initialLabel);
|
|
92
|
-
const [hasError, setHasError] = useState(false);
|
|
93
|
-
const handleLabelChange = () => {
|
|
94
|
-
if (validate && !validate(newLabelValue)) {
|
|
95
|
-
setHasError(true);
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
if (initialLabel !== newLabelValue) {
|
|
99
|
-
onChange?.(newLabelValue);
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
onCancel?.();
|
|
103
|
-
};
|
|
104
|
-
const cancelLabelChange = () => {
|
|
105
|
-
setNewLabelValue(initialLabel);
|
|
106
|
-
onCancel?.();
|
|
107
|
-
};
|
|
108
|
-
useEffect(() => {
|
|
109
|
-
if (inputRef.current) {
|
|
110
|
-
inputRef.current.focus();
|
|
111
|
-
inputRef.current.select();
|
|
112
|
-
}
|
|
113
|
-
}, []);
|
|
114
|
-
const canRename = newLabelValue && newLabelValue !== initialLabel && !hasError;
|
|
115
|
-
const inputId = useId();
|
|
116
|
-
return (_jsxs("div", { className: "phr-node-label-editor", children: [_jsxs("div", { className: "phr-node-label-editor-input-row", children: [_jsx(TextBox.Root, { style: { width: "100%" }, className: hasError ? "with-error" : undefined, children: _jsx(TextBox.Input, { id: inputId, ref: inputRef, "aria-label": localizedStrings.newLabel, value: newLabelValue, onChange: (event) => {
|
|
117
|
-
setNewLabelValue(event.target.value);
|
|
118
|
-
setHasError(false);
|
|
119
|
-
}, onKeyUp: (event) => {
|
|
120
|
-
if (event.key === "Enter") {
|
|
121
|
-
handleLabelChange();
|
|
122
|
-
}
|
|
123
|
-
else if (event.key === "Escape") {
|
|
124
|
-
cancelLabelChange();
|
|
125
|
-
}
|
|
126
|
-
} }) }), _jsx(IconButton, { icon: dismissSvg, label: localizedStrings.cancel, onClick: cancelLabelChange }), _jsx(IconButton, { icon: checkmarkSvg, label: localizedStrings.confirm, onClick: handleLabelChange, disabled: !canRename })] }), labelValidationHint !== undefined ? (_jsx(Description, { id: inputId, tone: hasError ? "critical" : "neutral", style: { display: "flex" }, children: _jsx(Text, { variant: "caption-lg", children: labelValidationHint }) })) : undefined] }, initialLabel));
|
|
127
|
-
}
|
|
128
|
-
function injectActionVariant(actions, variant) {
|
|
129
|
-
return actions
|
|
130
|
-
.filter((action) => isValidElement(action))
|
|
131
|
-
.map((action) => cloneElement(action, { variant }));
|
|
132
|
-
}
|
|
133
|
-
//# sourceMappingURL=TreeNodeRenderer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TreeNodeRenderer.js","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/TreeNodeRenderer.tsx"],"names":[],"mappings":";AAAA;;;gGAGgG;AAEhG,OAAO,wBAAwB,CAAC;AAEhC,OAAO,EACL,YAAY,EAGZ,UAAU,EACV,cAAc,EACd,IAAI,EAIJ,WAAW,EACX,SAAS,EACT,KAAK,EACL,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACpF,OAAO,YAAY,MAAM,gCAAgC,CAAC;AAC1D,OAAO,UAAU,MAAM,8BAA8B,CAAC;AACtD,OAAO,UAAU,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,gBAAgB,IAAI,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAGxF,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,cAAc,EAA4B,MAAM,iBAAiB,CAAC;AAC3E,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAuCrE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAyE,IAAI,CACjH,UAAU,CAAqC,SAAS,aAAa,CAAC,KAAK,EAAE,YAAY;IACvF,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,aAAa,EAAE,WAAW,EAAE,kBAAkB,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,aAAa,EAAE,GAAG,KAAK,CAAC;IAC9H,MAAM,EAAE,gBAAgB,EAAE,GAAG,sBAAsB,EAAE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tB,CAAC;4BACH,CAAC,GACD,GACW,EACf,KAAC,UAAU,IAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,gBAAgB,CAAC,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAI,EAC5F,KAAC,UAAU,IAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,CAAC,SAAS,GAAI,IACjH,EACL,mBAAmB,KAAK,SAAS,CAAC,CAAC,CAAC,CACnC,KAAC,WAAW,IAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,YAC3F,KAAC,IAAI,IAAC,OAAO,EAAC,YAAY,YAAE,mBAAmB,GAAQ,GAC3C,CACf,CAAC,CAAC,CAAC,SAAS,KA5BL,YAAY,CA6BhB,CACP,CAAC;AACJ,CAAC;AAED,SAAS,mBAAmB,CAAC,OAAoB,EAAE,OAA4C;IAC7F,OAAO,OAAO;SACX,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,cAAc,CAA2B,MAAM,CAAC,CAAC;SACpE,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,YAAY,CAA2B,MAAM,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;AAClF,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\";\n\nimport {\n cloneElement,\n ComponentPropsWithoutRef,\n FC,\n forwardRef,\n isValidElement,\n memo,\n PropsWithRef,\n ReactNode,\n RefAttributes,\n useCallback,\n useEffect,\n useId,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { Description, IconButton, Spinner, Text, TextBox } from \"@stratakit/bricks\";\nimport checkmarkSvg from \"@stratakit/icons/checkmark.svg\";\nimport dismissSvg from \"@stratakit/icons/dismiss.svg\";\nimport refreshSvg from \"@stratakit/icons/refresh.svg\";\nimport { DropdownMenu, unstable_Popover as Popover, Tree } from \"@stratakit/structures\";\nimport { TreeRendererProps } from \"../Renderers.js\";\nimport { TreeNode } from \"../TreeNode.js\";\nimport { useLocalizationContext } from \"./LocalizationContext.js\";\nimport { TreeActionBase, TreeActionBaseAttributes } from \"./TreeAction.js\";\nimport { useTreeNodeRenameContext } from \"./TreeNodeRenameAction.js\";\n\n/** @internal */\ninterface TreeNodeRendererOwnProps extends Pick<TreeRendererProps, \"expandNode\" | \"reloadTree\"> {\n /** Node that is rendered. */\n node: TreeNode;\n /**\n * Menu actions for tree item.\n * Must be an array of `<TreeActionBase />` or `<Divider />` elements.\n */\n menuActions?: ReactNode[];\n /**\n * Inline actions for tree item.\n * Must be an array of `<TreeActionBase />` elements.\n * Max 2 items.\n */\n inlineActions?: ReactNode[];\n /**\n * Context menu actions for tree item.\n * Must be an array of `<TreeActionBase />` or `<Divider />` elements.\n */\n contextMenuActions?: ReactNode[];\n}\n\n/** @alpha */\nexport type StrataKitTreeItemProps = Omit<\n ComponentPropsWithoutRef<typeof Tree.Item>,\n \"actions\" | \"inlineActions\" | \"expanded\" | \"onExpandedChange\" | \"icon\" | \"unstable_decorations\" | \"error\"\n> & {\n /**\n * Used to render elements between expander and label.\n * E.g. icons, color picker, etc.\n */\n decorations?: ReactNode;\n};\n\n/** @internal */\nexport type TreeNodeRendererProps = StrataKitTreeItemProps & TreeNodeRendererOwnProps;\n\n/**\n * A component that renders given `FlatTreeNode` using the `Tree.Item` component from `@itwin/itwinui-react`. The\n * `FlatTreeNode` objects for this renderer are generally created using the `useFlatTreeNodeList` hook.\n *\n * @internal\n */\nexport const StrataKitTreeNodeRenderer: FC<PropsWithRef<TreeNodeRendererProps & RefAttributes<HTMLElement>>> = memo(\n forwardRef<HTMLElement, TreeNodeRendererProps>(function HierarchyNode(props, forwardedRef) {\n const { node, decorations, inlineActions, menuActions, contextMenuActions, expandNode, reloadTree, ...treeItemProps } = props;\n const { localizedStrings } = useLocalizationContext();\n const renameContext = useTreeNodeRenameContext();\n const [contextMenuProps, setContextMenuProps] = useState<{ position: { x: number; y: number }; actions: ReactNode[] } | undefined>(undefined);\n\n const label = treeItemProps.label ?? node.label;\n const inlineActionItems = useMemo(() => {\n if (node.error !== undefined && node.error.type === \"ChildrenLoad\") {\n return [\n <TreeActionBase\n key=\"retry\"\n label={localizedStrings.retry}\n onClick={() => reloadTree({ parentNodeId: node.id, state: \"reset\" })}\n visible={true}\n icon={refreshSvg}\n variant=\"inline\"\n />,\n ];\n }\n if (!inlineActions) {\n return undefined;\n }\n return injectActionVariant(inlineActions, \"inline\");\n }, [node, inlineActions, localizedStrings.retry, reloadTree]);\n\n const menuActionItems = useMemo(() => {\n if (!menuActions) {\n return undefined;\n }\n return injectActionVariant(menuActions, \"default\");\n }, [menuActions]);\n\n const expanded = useMemo(() => {\n if (node.error) {\n return undefined;\n }\n\n // this is a leaf node\n if (node.children !== true && node.children.length === 0) {\n return undefined;\n }\n\n return node.isExpanded;\n }, [node]);\n\n const { renameParameters, cancelRename } = renameContext ?? {};\n const labelEditor = (\n <LabelEditor\n initialLabel={node.label}\n onChange={renameParameters?.commit}\n onCancel={cancelRename}\n labelValidationHint={renameParameters?.labelValidationHint}\n validate={renameParameters?.validate}\n />\n );\n\n return (\n <>\n <Popover content={labelEditor} placement=\"bottom\" open={renameParameters?.nodeId === node.id} setOpen={cancelRename} unmountOnHide>\n <Tree.Item\n {...treeItemProps}\n ref={forwardedRef}\n label={label}\n expanded={expanded}\n onExpandedChange={useCallback(\n (isExpanded: boolean) => {\n expandNode(node.id, isExpanded);\n },\n [node, expandNode],\n )}\n inlineActions={inlineActionItems}\n actions={menuActionItems}\n unstable_decorations={decorations}\n error={node.error ? node.error.id : undefined}\n onContextMenu={(e) => {\n if (treeItemProps.onContextMenu) {\n treeItemProps.onContextMenu(e);\n }\n\n if (!contextMenuActions) {\n return;\n }\n\n e.preventDefault();\n const actions = injectActionVariant(contextMenuActions, \"context-menu\");\n if (actions.length === 0) {\n return;\n }\n\n setContextMenuProps({\n position: {\n x: e.clientX,\n y: e.clientY,\n },\n actions,\n });\n }}\n />\n </Popover>\n <DropdownMenu.Provider\n open={contextMenuProps !== undefined}\n setOpen={(open) => {\n if (!open) {\n setContextMenuProps(undefined);\n }\n }}\n key={`${node.id}-${contextMenuProps?.position.x ?? \"\"}-${contextMenuProps?.position.y ?? \"\"}`}\n >\n {contextMenuProps ? (\n <DropdownMenu.Button style={{ position: \"fixed\", top: contextMenuProps.position.y, left: contextMenuProps.position.x }} render={<div />} />\n ) : null}\n {/* `autoFocus` prop is coming from ariakit and is not native HTML `autoFocus` prop. */}\n {/* `focusable` is needed for `autoFocus` to work. StrataKit exposes only `autoFocus` and does not set `focusable` internally. */}\n {/* eslint-disable jsx-a11y/no-autofocus */}\n {/* @ts-expect-error focusable is passed through */}\n <DropdownMenu.Content focusable autoFocus={true}>\n {contextMenuProps?.actions}\n </DropdownMenu.Content>\n </DropdownMenu.Provider>\n </>\n );\n }),\n);\n\nexport const PlaceholderNode: FC<\n PropsWithRef<Pick<StrataKitTreeItemProps, \"style\" | \"aria-level\" | \"aria-posinset\" | \"aria-setsize\"> & RefAttributes<HTMLElement>>\n> = memo(\n forwardRef<HTMLElement, Pick<StrataKitTreeItemProps, \"style\" | \"aria-level\" | \"aria-posinset\" | \"aria-setsize\">>(function PlaceholderNode(\n { ...props },\n forwardedRef,\n ) {\n const { localizedStrings } = useLocalizationContext();\n return (\n <Tree.Item\n {...props}\n ref={forwardedRef}\n label={localizedStrings.loading}\n unstable_decorations={<Spinner size={\"small\"} title={localizedStrings.loading} />}\n />\n );\n }),\n);\n\nfunction LabelEditor({\n initialLabel,\n labelValidationHint,\n onChange,\n onCancel,\n validate,\n}: {\n initialLabel: string;\n labelValidationHint?: string;\n onChange?: (newLabel: string) => void;\n onCancel?: () => void;\n validate?: (newLabel: string) => boolean;\n}) {\n const { localizedStrings } = useLocalizationContext();\n const inputRef = useRef<HTMLInputElement>(null);\n const [newLabelValue, setNewLabelValue] = useState(initialLabel);\n const [hasError, setHasError] = useState<boolean>(false);\n const handleLabelChange = () => {\n if (validate && !validate(newLabelValue)) {\n setHasError(true);\n return;\n }\n\n if (initialLabel !== newLabelValue) {\n onChange?.(newLabelValue);\n return;\n }\n onCancel?.();\n };\n\n const cancelLabelChange = () => {\n setNewLabelValue(initialLabel);\n onCancel?.();\n };\n\n useEffect(() => {\n if (inputRef.current) {\n inputRef.current.focus();\n inputRef.current.select();\n }\n }, []);\n\n const canRename = newLabelValue && newLabelValue !== initialLabel && !hasError;\n const inputId = useId();\n\n return (\n <div key={initialLabel} className=\"phr-node-label-editor\">\n <div className=\"phr-node-label-editor-input-row\">\n <TextBox.Root style={{ width: \"100%\" }} className={hasError ? \"with-error\" : undefined}>\n <TextBox.Input\n id={inputId}\n ref={inputRef}\n aria-label={localizedStrings.newLabel}\n value={newLabelValue}\n onChange={(event) => {\n setNewLabelValue(event.target.value);\n setHasError(false);\n }}\n onKeyUp={(event) => {\n if (event.key === \"Enter\") {\n handleLabelChange();\n } else if (event.key === \"Escape\") {\n cancelLabelChange();\n }\n }}\n />\n </TextBox.Root>\n <IconButton icon={dismissSvg} label={localizedStrings.cancel} onClick={cancelLabelChange} />\n <IconButton icon={checkmarkSvg} label={localizedStrings.confirm} onClick={handleLabelChange} disabled={!canRename} />\n </div>\n {labelValidationHint !== undefined ? (\n <Description id={inputId} tone={hasError ? \"critical\" : \"neutral\"} style={{ display: \"flex\" }}>\n <Text variant=\"caption-lg\">{labelValidationHint}</Text>\n </Description>\n ) : undefined}\n </div>\n );\n}\n\nfunction injectActionVariant(actions: ReactNode[], variant: TreeActionBaseAttributes[\"variant\"]) {\n return actions\n .filter((action) => isValidElement<TreeActionBaseAttributes>(action))\n .map((action) => cloneElement<TreeActionBaseAttributes>(action, { variant }));\n}\n"]}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { ComponentProps, ComponentPropsWithoutRef, FC, PropsWithoutRef, ReactElement, ReactNode, RefAttributes } from "react";
|
|
2
|
-
import { Tree } from "@stratakit/structures";
|
|
3
|
-
import { TreeRendererProps } from "../Renderers.js";
|
|
4
|
-
import { TreeNode } from "../TreeNode.js";
|
|
5
|
-
import { SelectionMode } from "../UseSelectionHandler.js";
|
|
6
|
-
import { LocalizationContextProvider } from "./LocalizationContext.js";
|
|
7
|
-
import { TreeErrorRendererProps } from "./TreeErrorRenderer.js";
|
|
8
|
-
import { TreeNodeEditingProps } from "./TreeNodeRenameAction.js";
|
|
9
|
-
import { StrataKitTreeItemProps } from "./TreeNodeRenderer.js";
|
|
10
|
-
/** @alpha */
|
|
11
|
-
interface TreeRendererOwnProps {
|
|
12
|
-
id?: string;
|
|
13
|
-
/**
|
|
14
|
-
* A user friendly display label of the tree. Should be unique within the consuming application,
|
|
15
|
-
* as it's used for accessibility purposes.
|
|
16
|
-
*/
|
|
17
|
-
treeLabel: string;
|
|
18
|
-
/** Active selection mode used by the tree. Defaults to `"single"`. */
|
|
19
|
-
selectionMode?: SelectionMode;
|
|
20
|
-
/** A render function for errors' display component. Defaults to `<TreeErrorRenderer />`. */
|
|
21
|
-
errorRenderer?: (props: TreeErrorRendererProps) => ReactElement;
|
|
22
|
-
/** Props that defines if current node supports editing. */
|
|
23
|
-
getEditingProps?: (node: TreeNode) => TreeNodeEditingProps | undefined;
|
|
24
|
-
/** Custom props for the root Tree component. */
|
|
25
|
-
treeRootProps?: Partial<Omit<ComponentProps<typeof Tree.Root>, "style">>;
|
|
26
|
-
/** A callback that returns tree item props for specific node. */
|
|
27
|
-
getTreeItemProps?: (node: TreeNode) => Partial<Omit<StrataKitTreeItemProps, "selected" | "aria-level" | "aria-posinset" | "aria-setsize">>;
|
|
28
|
-
/**
|
|
29
|
-
* Callback that returns menu actions for tree item.
|
|
30
|
-
* Must return an array of `<TreeActionBase />` or `<Divider />` elements.
|
|
31
|
-
*/
|
|
32
|
-
getMenuActions?: (props: {
|
|
33
|
-
targetNode: TreeNode;
|
|
34
|
-
selectedNodes: TreeNode[];
|
|
35
|
-
}) => ReactNode[];
|
|
36
|
-
/**
|
|
37
|
-
* Callback that returns inline actions for tree item.
|
|
38
|
-
* Must return an array of `<TreeActionBase />` elements.
|
|
39
|
-
* Max 2 items.
|
|
40
|
-
*/
|
|
41
|
-
getInlineActions?: (props: {
|
|
42
|
-
targetNode: TreeNode;
|
|
43
|
-
selectedNodes: TreeNode[];
|
|
44
|
-
}) => ReactNode[];
|
|
45
|
-
/**
|
|
46
|
-
* Callback that returns actions for tree item context menu.
|
|
47
|
-
* Must return an array of `<TreeActionBase />` or `<Divider />` elements.
|
|
48
|
-
*/
|
|
49
|
-
getContextMenuActions?: (props: {
|
|
50
|
-
targetNode: TreeNode;
|
|
51
|
-
selectedNodes: TreeNode[];
|
|
52
|
-
}) => ReactNode[];
|
|
53
|
-
}
|
|
54
|
-
/** @alpha */
|
|
55
|
-
export interface StrataKitTreeRendererAttributes {
|
|
56
|
-
/**
|
|
57
|
-
* Opens rename mode for the first node that matches the given predicate. Node must be already loaded in the tree.
|
|
58
|
-
* If the node is not visible (because its parent is collapsed), all parents will be expanded to make it visible and node will be scrolled into view.
|
|
59
|
-
*
|
|
60
|
-
* Returns "node-not-found" if no node matches the predicate, "success" if rename was initiated.
|
|
61
|
-
*/
|
|
62
|
-
renameNode: (nodePredicate: (node: TreeNode) => boolean) => "node-not-found" | "success";
|
|
63
|
-
}
|
|
64
|
-
/** @alpha */
|
|
65
|
-
type StrataKitTreeRendererProps = TreeRendererProps & Pick<TreeErrorRendererProps, "filterHierarchyLevel"> & TreeRendererOwnProps & ComponentPropsWithoutRef<typeof LocalizationContextProvider>;
|
|
66
|
-
/**
|
|
67
|
-
* A component that renders a tree using the `Tree` component from `@itwin/itwinui-react`. The tree nodes
|
|
68
|
-
* are rendered using `TreeNodeRenderer` component from this package.
|
|
69
|
-
*
|
|
70
|
-
* @see https://itwinui.bentley.com/docs/tree
|
|
71
|
-
* @alpha
|
|
72
|
-
*/
|
|
73
|
-
export declare const StrataKitTreeRenderer: FC<PropsWithoutRef<StrataKitTreeRendererProps> & RefAttributes<StrataKitTreeRendererAttributes>>;
|
|
74
|
-
export {};
|
|
75
|
-
//# sourceMappingURL=TreeRenderer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TreeRenderer.d.ts","sourceRoot":"","sources":["../../../../src/presentation-hierarchies-react/stratakit/TreeRenderer.tsx"],"names":[],"mappings":"AAKA,OAAO,EACL,cAAc,EACd,wBAAwB,EAExB,EAAE,EAGF,eAAe,EACf,YAAY,EACZ,SAAS,EACT,aAAa,EAMd,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAE7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAuB,MAAM,2BAA2B,CAAC;AAG/E,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAqB,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAgE,MAAM,2BAA2B,CAAC;AAC/H,OAAO,EAAmB,sBAAsB,EAAoD,MAAM,uBAAuB,CAAC;AAElI,aAAa;AACb,UAAU,oBAAoB;IAC5B,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ;;;OAGG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB,sEAAsE;IACtE,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,4FAA4F;IAC5F,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,sBAAsB,KAAK,YAAY,CAAC;IAChE,2DAA2D;IAC3D,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