@jalez/react-flow-automated-layout
Version:
A React library for automated layout of nested node graphs with parent-child relationships using React Flow
63 lines (62 loc) • 2.32 kB
TypeScript
import { Edge, Node } from '@xyflow/react';
export type LayoutDirection = "DOWN" | "RIGHT" | "LEFT" | "UP";
export type LayoutAlgorithm = "layered" | "mrtree";
export interface LayoutEngine {
calculate: (nodes: Node[], edges: Edge[], options: Record<string, any>) => Promise<{
nodes: Node[];
edges: Edge[];
width?: number;
height?: number;
}>;
}
export interface ParentResizingOptions {
enabled: boolean;
padding: {
horizontal: number;
vertical: number;
};
respectHeaderHeight: boolean;
minWidth?: number;
minHeight?: number;
}
export interface LayoutContextState {
direction: LayoutDirection;
algorithm: LayoutAlgorithm;
autoLayout: boolean;
layoutInProgress: boolean;
padding: number;
nodeSpacing: number;
layerSpacing: number;
nodeWidth: number;
nodeHeight: number;
layoutHidden: boolean;
parentResizingOptions: ParentResizingOptions;
layoutEngines: Record<string, LayoutEngine>;
layoutEngineOptions: Record<string, any>;
nodeParentIdMapWithChildIdSet: Map<string, Set<string>>;
nodeIdWithNode: Map<string, Node>;
noParentKey: string;
updateNodes?: (nodes: Node[]) => void;
updateEdges?: (edges: Edge[]) => void;
setDirection: (direction: LayoutDirection) => void;
setAlgorithm: (algorithm: LayoutAlgorithm) => void;
setAutoLayout: (auto: boolean) => void;
setLayoutInProgress: (inProgress: boolean) => void;
setPadding: (padding: number) => void;
setNodeSpacing: (spacing: number) => void;
setLayerSpacing: (spacing: number) => void;
setNodeWidth: (width: number) => void;
setNodeHeight: (height: number) => void;
setLayoutHidden: (hidden: boolean) => void;
setParentResizingOptions: (options: Partial<ParentResizingOptions>) => void;
setLayoutEngineOptions: (options: Record<string, any>) => void;
applyLayout: (nodes?: Node[], edges?: Edge[]) => Promise<{
nodes: Node[];
edges: Edge[];
}> | undefined;
clearLayoutCache: () => void;
registerLayoutEngine: (name: string, engine: LayoutEngine) => void;
}
declare const LayoutContext: import("react").Context<LayoutContextState | undefined>;
export declare function useLayoutContext(): LayoutContextState;
export default LayoutContext;