UNPKG

@nodeject/ui-components

Version:

UI library for non-trivial components

146 lines (145 loc) 4.6 kB
/// <reference types="react" /> export declare enum LayoutStyle { Org = 0, List = 1 } export declare type CreateTreeNode = { data: { layoutStyle: LayoutStyle; parent: string; [key: string]: any; }; }; export declare type TreeNode = { data: { id: string; layoutStyle: LayoutStyle; parent: string; [key: string]: any; }; }; export interface NodeProps { actions?: UseDndTreeActionsProps; isActive: boolean; isNew: boolean; isDraggedNode: boolean; treeMode: TreeMode; node: TreeNode; onNodeClicked: (nodeId: string) => void; treeOptions?: TreeOptions; DragHandle: React.FC<DragHandleWrapperProps>; } export declare type TreeNodeUnflattened = TreeNode & { children: TreeNodeUnflattened[]; }; export declare type TreeNodesUnflattened = TreeNodeUnflattened[]; export declare type TreeNodes = TreeNode[]; export declare type TreeBranch = { id: string; children?: TreeBranch[]; }; export declare type TreeData = { nodes: TreeNodes; }; export declare type TreeDataUnflattened = { nodes: TreeNodesUnflattened; }; export interface NodeWrapperProps { actions: UseDndTreeActionsProps; isNew: boolean; treeOptions?: TreeOptions; treeMode: TreeMode; expanded?: boolean; node: TreeNodeUnflattened; isChildOfOrg: boolean; isFirstChild: boolean; isLastChild: boolean; isList: boolean; hasParent: boolean; hasChildren: boolean; } export declare type AddChildNodeServerFn = (args: { component: string; newComponent?: string; data?: any; }) => Promise<void>; export declare type DeleteNodeServerFn = (nodeId: string) => Promise<void>; export declare type InsertSiblingBeforeServerFn = (args: { component: string; newComponent?: string; data?: any; }) => Promise<void>; export declare type InsertSiblingAfterServerFn = (args: { component: string; newComponent?: string; data?: any; }) => Promise<void>; export declare type InsertParentServerFn = (args: { component: string; newComponent?: string; data?: any; }) => Promise<void>; export declare type MoveNodeServerFn = (args: { nodeKey: string; index: number; parentKey: string; }) => Promise<void>; export declare type CreateNewNodeFn = (args: CreateTreeNode) => TreeNode; export declare type AddChildNodeFn = (nodeId: string) => void; export declare type DeleteNodeFn = (nodeId: string) => void; export declare type InsertSiblingBeforeFn = (beforeNodeId: string) => void; export declare type InsertSiblingAfterFn = (afterNodeId: string) => void; export declare type InsertParentFn = (nodeId: string) => void; export declare type MoveNodeFn = (args: { droppedNode: TreeNodeUnflattened; parentContainerNode: TreeNodeUnflattened; index: number; }) => void; export declare type SetNodeDraggingIdFn = (nodeId: string) => void; export declare type SaveNewNodeFn = (data: any) => Promise<void>; export interface DnDTreesActionsProps { addChildNode?: AddChildNodeServerFn; createNewNode?: CreateNewNodeFn; deleteNode?: DeleteNodeServerFn; insertSiblingBefore?: InsertSiblingBeforeServerFn; insertParent?: InsertParentServerFn; insertSiblingAfter?: InsertSiblingAfterServerFn; moveNode?: MoveNodeServerFn; setNodeDraggingId?: SetNodeDraggingIdFn; } export interface UseDndTreeActionsProps { collapseNode: (nodeId: string) => void; expandNode: (nodeId: string) => void; toggleNode: (nodeId: string) => void; addChildNode: AddChildNodeFn; createNewNode: CreateNewNodeFn; deleteNode: DeleteNodeFn; insertSiblingBefore: InsertSiblingBeforeFn; insertParent: InsertParentFn; insertSiblingAfter: InsertSiblingAfterFn; moveNode: MoveNodeFn; saveNewNode: SaveNewNodeFn; setNodeDraggingId: SetNodeDraggingIdFn; } export declare type TreeOptions = { canExpandCollapse?: boolean; canEditTreeStructure?: boolean; }; export declare type TreeMode = 'view' | 'dragdrop'; export interface DnDTreesProps { actions?: DnDTreesActionsProps; treeData: TreeData; components: { TreeMenu?: React.FC<any>; Node: React.FC<NodeProps>; }; treeMode: TreeMode; treeOptions?: TreeOptions; onNodeClicked?: (nodeId: string) => void; activeNode?: string; } export interface DragHandleWrapperProps { isDraggedNode: boolean; nodeId: string; handle?: JSX.Element; }