UNPKG

@tisoap/react-flow-smart-edge

Version:

Custom React Flow Edge that never intersects with other nodes

94 lines (76 loc) 3.41 kB
import { Edge } from '@xyflow/react'; import { EdgeProps } from '@xyflow/react'; import { JSX } from 'react/jsx-runtime'; import { Node as Node_2 } from '@xyflow/react'; import { XYPosition } from '@xyflow/react'; declare type DiagonalMovement = "Always" | "Never"; declare type EdgeParams = Pick<EdgeProps, "sourceX" | "sourceY" | "targetX" | "targetY" | "sourcePosition" | "targetPosition">; export declare const getSmartEdge: <NodeDataType extends Record<string, unknown> = Record<string, unknown>>({ options, nodes, sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, }: GetSmartEdgeParams<NodeDataType>) => GetSmartEdgeReturn | Error; export declare interface GetSmartEdgeOptions { gridRatio?: number; nodePadding?: number; drawEdge?: SVGDrawFunction; generatePath?: PathFindingFunction; debug?: { enabled?: boolean; setGraphBox?: (box: { x: number; y: number; width: number; height: number; }) => void; }; } declare type GetSmartEdgeParams<NodeDataType extends Record<string, unknown> = Record<string, unknown>> = EdgeParams & { options?: GetSmartEdgeOptions; nodes: Node_2<NodeDataType>[]; }; declare interface GetSmartEdgeReturn { svgPathString: string; edgeCenterX: number; edgeCenterY: number; } export declare interface Grid { width: number; height: number; nodes: GridNode[][]; getNodeAt: (x: number, y: number) => GridNode; isWalkableAt: (x: number, y: number) => boolean; setWalkableAt: (x: number, y: number, walkable: boolean) => void; getNeighbors: (node: GridNode, diagonalMovement: DiagonalMovement) => GridNode[]; isInside: (x: number, y: number) => boolean; clone: () => Grid; } export declare interface GridNode { x: number; y: number; walkable: boolean; costFromStart?: number; heuristicCostToGoal?: number; estimatedTotalCost?: number; opened?: boolean; closed?: boolean; parent?: GridNode; } export declare const pathfindingAStarDiagonal: PathFindingFunction; /** * Takes source and target {x, y} points, together with an grid representation * of the graph, and returns an array of number tuples [x, y], representing * the full path from source to target. */ export declare type PathFindingFunction = (grid: Grid, start: XYPosition, end: XYPosition) => number[][]; export declare function SmartBezierEdge<EdgeType extends Edge = Edge, NodeType extends Node_2 = Node_2>(props: EdgeProps<EdgeType>): JSX.Element; export declare function SmartStepEdge<EdgeType extends Edge = Edge, NodeType extends Node_2 = Node_2>(props: EdgeProps<EdgeType>): JSX.Element; export declare function SmartStraightEdge<EdgeType extends Edge = Edge, NodeType extends Node_2 = Node_2>(props: EdgeProps<EdgeType>): JSX.Element; /** * Takes source and target {x, y} points, together with an array of number * tuples [x, y] representing the points along the path, and returns a string * to be used as the SVG path. */ export declare type SVGDrawFunction = (source: XYPosition, target: XYPosition, path: number[][]) => string; /** * Draws a SVG path from a list of points, using rounded lines. */ export declare const svgDrawSmoothLinePath: SVGDrawFunction; export { XYPosition } export { }