import { D3DragEvent, SubjectPosition } from "d3-drag"; import { Selection, pointer } from "d3-selection"; import { D3ZoomEvent, ZoomBehavior, ZoomTransform } from "d3-zoom"; /** * While [`PanelPosition`](/api-reference/types/panel-position) can be used to place a * component in the corners of a container, the `Position` enum is less precise and used * primarily in relation to edges and handles. * * @public */ export declare enum Position { Left = "left", Top = "top", Right = "right", Bottom = "bottom" } export declare const oppositePosition: { left: Position; right: Position; top: Position; bottom: Position; }; /** * All positions are stored in an object with x and y coordinates. * * @public */ export type XYPosition = { x: number; y: number; }; export type XYZPosition = XYPosition & { z: number; }; export type Dimensions = { width: number; height: number; }; export type Rect = Dimensions & XYPosition; export type Box = XYPosition & { x2: number; y2: number; }; export type Transform = [number, number, number]; /** * A coordinate extent represents two points in a coordinate system: one in the top * left corner and one in the bottom right corner. It is used to represent the * bounds of nodes in the flow or the bounds of the viewport. * * @public * * @remarks Props that expect a `CoordinateExtent` usually default to `[[-∞, -∞], [+∞, +∞]]` * to represent an unbounded extent. */ export type CoordinateExtent = [[number, number], [number, number]]; /** * Using Pick with a union type (e.g. `NodeType`) will merge every property type along all union members. * See https://github.com/microsoft/TypeScript/issues/28339#issuecomment-463577347 * Note: Currently you are able to Pick properties that are not in the type without error. */ export type DistributivePick = T extends unknown ? { [P in Extract]: T[P]; } : never; /** * Framework independent node data structure. * * @inline * @typeParam NodeData - type of the node data * @typeParam NodeType - type of the node */ export type NodeBase = Record, NodeType extends string | undefined = string | undefined> = { /** Unique id of a node. */ id: string; /** * Position of a node on the pane. * @example { x: 0, y: 0 } */ position: XYPosition; /** Arbitrary data passed to a node. */ data: NodeData; /** * Only relevant for default, source, target nodeType. Controls source position. * @example 'right', 'left', 'top', 'bottom' */ sourcePosition?: Position; /** * Only relevant for default, source, target nodeType. Controls target position. * @example 'right', 'left', 'top', 'bottom' */ targetPosition?: Position; /** Whether or not the node should be visible on the canvas. */ hidden?: boolean; selected?: boolean; /** Whether or not the node is currently being dragged. */ dragging?: boolean; /** Whether or not the node is able to be dragged. */ draggable?: boolean; selectable?: boolean; connectable?: boolean; deletable?: boolean; /** * A class name that can be applied to elements inside the node that allows those elements to act * as drag handles, letting the user drag the node by clicking and dragging on those elements. */ dragHandle?: string; width?: number; height?: number; initialWidth?: number; initialHeight?: number; /** Parent node id, used for creating sub-flows. */ parentId?: string; zIndex?: number; /** * Boundary a node can be moved in. * @example 'parent' or [[0, 0], [100, 100]] */ extent?: 'parent' | CoordinateExtent | null; /** * When `true`, the parent node will automatically expand if this node is dragged to the edge of * the parent node's bounds. */ expandParent?: boolean; ariaLabel?: string; /** * Origin of the node relative to its position. * @example * [0.5, 0.5] // centers the node * [0, 0] // top left * [1, 1] // bottom right */ origin?: NodeOrigin; handles?: NodeHandle[]; measured?: { width?: number; height?: number; }; resizing?: boolean; } & (undefined extends NodeType ? { /** Type of node defined in nodeTypes */ type?: string | undefined; } : { /** Type of node defined in nodeTypes */ type: NodeType; }); export type InternalNodeBase = Omit & { measured: { width?: number; height?: number; }; internals: { positionAbsolute: XYPosition; z: number; rootParentIndex?: number; /** * Holds a reference to the original node object provided by the user. * Used as an optimization to avoid certain operations. */ userNode: NodeType; handleBounds?: NodeHandleBounds; bounds?: NodeBounds; isParent: boolean; }; }; /** * The node data structure that gets used for the custom nodes props. * * @public */ export type NodeProps = NodeType extends unknown ? Pick & Required> & { /** Whether a node is connectable or not. */ isConnectable: boolean; /** Position absolute x value. */ positionAbsoluteX: number; /** Position absolute y value. */ positionAbsoluteY: number; } : never; /** * Measured {@link HandleBounds} for a node, grouped by handle type. * Stored on `internals.handleBounds`. * * @public */ export type NodeHandleBounds = { source: HandleBounds[] | null; target: HandleBounds[] | null; }; export type InternalNodeUpdate = { id: string; nodeElement: HTMLDivElement; force?: boolean; }; export type NodeBounds = XYPosition & { width: number | null; height: number | null; }; export type NodeDragItem = { id: string; position: XYPosition; distance: XYPosition; measured: { width: number; height: number; }; internals: { positionAbsolute: XYPosition; }; } & Pick; /** * The origin of a Node determines how it is placed relative to its own coordinates. * `[0, 0]` places it at the top left corner, `[0.5, 0.5]` right in the center and * `[1, 1]` at the bottom right of its position. * * @public */ export type NodeOrigin = [number, number]; export type OnSelectionDrag = (event: MouseEvent | TouchEvent, nodes: NodeType[]) => void; /** * User-declared handle layout on {@link NodeBase.handles}. * Same fields as {@link HandleBounds} except `nodeId` (implied by the node) and optional `width`/`height`. * * @public */ export type NodeHandle = Omit & { width?: number; height?: number; }; export type Align = 'center' | 'start' | 'end'; export type NodeLookup = Map; export type ParentLookup = Map>; /** * @inline */ export type HandleType = 'source' | 'target'; /** * Measured position and size of a handle relative to the node * * @public */ export type HandleBounds = { id?: string | null; nodeId: string; x: number; y: number; position: Position; type: HandleType; width: number; height: number; }; export type HandleProps = { /** * Type of the handle. * @default "source" */ type: HandleType; /** * The position of the handle relative to the node. In a horizontal flow source handles are * typically `Position.Right` and in a vertical flow they are typically `Position.Top`. * @default Position.Top * @example Position.Top, Position.Right, Position.Bottom, Position.Left */ position: Position; /** * Should you be able to connect to/from this handle. * @default true */ isConnectable?: boolean; /** * Dictates whether a connection can start from this handle. * @default true */ isConnectableStart?: boolean; /** * Dictates whether a connection can end on this handle. * @default true */ isConnectableEnd?: boolean; /** * Called when a connection is dragged to this handle. You can use this callback to perform some * custom validation logic based on the connection target and source, for example. Where possible, * we recommend you move this logic to the `isValidConnection` prop on the main ReactFlow * component for performance reasons. * @remarks connection becomes an edge if isValidConnection returns true */ isValidConnection?: IsValidConnection; /** * Id of the handle. * @remarks optional if there is only one handle of this type */ id?: string | null; }; export type OnDraggingChange = (dragging: boolean) => void; export type OnTransformChange = (transform: Transform) => void; export type PanZoomParams = { domNode: Element; minZoom: number; maxZoom: number; viewport: Viewport; translateExtent: CoordinateExtent; onDraggingChange: OnDraggingChange; onPanZoomStart?: OnPanZoom; onPanZoom?: OnPanZoom; onPanZoomEnd?: OnPanZoom; }; export type PanZoomTransformOptions = { duration?: number; ease?: (t: number) => number; interpolate?: 'smooth' | 'linear'; }; export type OnPanZoom = (event: MouseEvent | TouchEvent | null, viewport: Viewport) => void; export type PanZoomUpdateOptions = { noWheelClassName: string; noPanClassName: string; onPaneContextMenu?: (event: MouseEvent) => void; preventScrolling: boolean; panActivationKeyPressed?: boolean; panOnScroll: boolean; panOnDrag: boolean | number[]; panOnScrollMode: PanOnScrollMode; panOnScrollSpeed: number; userSelectionActive: boolean; zoomOnPinch: boolean; zoomOnScroll: boolean; zoomOnDoubleClick: boolean; zoomActivationKeyPressed: boolean; lib: string; onTransformChange: OnTransformChange; connectionInProgress: boolean; paneDragThreshold: number; }; export type PanZoomInstance = { update: (params: PanZoomUpdateOptions) => void; destroy: () => void; getViewport: () => Viewport; setViewport: (viewport: Viewport, options?: PanZoomTransformOptions) => Promise; setViewportConstrained: (viewport: Viewport, extent: CoordinateExtent, translateExtent: CoordinateExtent) => Promise; setScaleExtent: (scaleExtent: [number, number]) => void; setTranslateExtent: (translateExtent: CoordinateExtent) => void; scaleTo: (scale: number, options?: PanZoomTransformOptions) => Promise; scaleBy: (factor: number, options?: PanZoomTransformOptions) => Promise; syncViewport: (viewport: Viewport) => void; }; /** * DOM events passed to d3-zoom filter and custom wheel handlers. */ export type D3ZoomInputEvent = WheelEvent | MouseEvent | TouchEvent; export type XYFlowZoomEvent = Omit, 'sourceEvent'> & { sourceEvent: D3ZoomInputEvent; }; /** * Flags attached to programmatic pan/zoom updates (not part of the DOM spec). */ export type XYFlowSourceEvent = D3ZoomInputEvent & { internal?: boolean; sync?: boolean; }; export declare function isPointerEvent(event: Event): event is MouseEvent | TouchEvent; export declare function isWheelEvent(event: Event): event is WheelEvent; export declare function isTouchEvent(event: Event): event is TouchEvent; export declare function isMouseEvent(event: Event): event is MouseEvent; export declare function getTouchPoint(event: MouseEvent | TouchEvent): [number, number]; export type Project = (position: XYPosition) => XYPosition; /** * This type is used to define the `onMove` handler. */ export type OnMove = (event: MouseEvent | TouchEvent | null, viewport: Viewport) => void; export type OnMoveStart = OnMove; export type OnMoveEnd = OnMove; /** * @inline */ export type ZoomInOut = (options?: ViewportHelperFunctionOptions) => Promise; /** * @inline */ export type ZoomTo = (zoomLevel: number, options?: ViewportHelperFunctionOptions) => Promise; /** * @inline */ export type GetZoom = () => number; /** * @inline */ export type GetViewport = () => Viewport; /** * The `SetViewport` function is used to set the viewport of the flow. * * @inline * @param viewport - The viewport to set. * @param options - Optional parameters to control the animation and easing of the viewport change. */ export type SetViewport = (viewport: Viewport, options?: ViewportHelperFunctionOptions) => Promise; /** * The `SetCenter` function is used to set the center of the flow viewport to a specific position * * @inline * @param x - x coordinate * @param y - y coordinate * @param options - Optional parameters to control the animation and easing of the viewport change. */ export type SetCenter = (x: number, y: number, options?: SetCenterOptions) => Promise; /** * The `FitBounds` function is used to fit the flow viewport to the bounds of the nodes. * * @inline * @param bounds - The bounds to fit the viewport to. * @param options - Optional parameters to control the animation and easing of the viewport change. */ export type FitBounds = (bounds: Rect, options?: FitBoundsOptions) => Promise; /** * The `Connection` type is the basic minimal description of an [`Edge`](/api-reference/types/edge) * between two nodes. The [`addEdge`](/api-reference/utils/add-edge) util can be used to upgrade * a `Connection` to an [`Edge`](/api-reference/types/edge). * * @public */ export type Connection = { /** The id of the node this connection originates from. */ source: string; /** The id of the node this connection terminates at. */ target: string; /** When not `null`, the id of the handle on the source node that this connection originates from. */ sourceHandle: string | null; /** When not `null`, the id of the handle on the target node that this connection terminates at. */ targetHandle: string | null; }; /** * The `NodeConnection` type is an extension of a basic [Connection](/api-reference/types/connection) that includes the `edgeId`. */ export type NodeConnection = Connection & { edgeId: string; }; export type UseNodeConnectionsParams = { /** ID of the node, filled in automatically if used inside custom node. */ id?: string; /** Gets called when a connection is established. */ onConnect?: (connections: NodeConnection[]) => void; /** Gets called when a connection is removed. */ onDisconnect?: (connections: NodeConnection[]) => void; } & ({ /** What type of handle connections do you want to observe? */ handleType: HandleType; /** Filter by handle id (this is only needed if the node has multiple handles of the same type). Requires `handleType` to be set. */ handleId?: string; } | { handleType?: HandleType; handleId?: never; }); /** * The `ConnectionMode` is used to set the mode of connection between nodes. * The `Strict` mode is the default one and only allows source to target edges. * `Loose` mode allows source to source and target to target edges as well. * * @public */ export declare enum ConnectionMode { Strict = "strict", Loose = "loose" } export type OnConnectStartParams = { nodeId: string | null; handleId: string | null; handleType: HandleType | null; }; export type OnConnectStart = (event: MouseEvent | TouchEvent, params: OnConnectStartParams) => void; export type OnConnect = (connection: Connection) => void; export type OnConnectEnd = (event: MouseEvent | TouchEvent, connectionState: FinalConnectionState>) => void; export type OnReconnect = (oldEdge: EdgeType, newConnection: Connection) => void; export type OnReconnectStart = (event: MouseEvent | TouchEvent, edge: EdgeType, handleType: HandleType) => void; export type OnReconnectEnd = (event: MouseEvent | TouchEvent, edge: EdgeType, handleType: HandleType, connectionState: FinalConnectionState>) => void; export type IsValidConnection = (edge: EdgeType | Connection) => boolean; /** * @inline */ export type FitViewParamsBase = { nodes: Map>; width: number; height: number; panZoom: PanZoomInstance; minZoom: number; maxZoom: number; }; export type PaddingUnit = 'px' | '%'; export type PaddingWithUnit = `${number}${PaddingUnit}` | number; export type Padding = PaddingWithUnit | { top?: PaddingWithUnit; right?: PaddingWithUnit; bottom?: PaddingWithUnit; left?: PaddingWithUnit; x?: PaddingWithUnit; y?: PaddingWithUnit; }; /** * @inline */ export type FitViewOptionsBase = { padding?: Padding; includeHiddenNodes?: boolean; minZoom?: number; maxZoom?: number; duration?: number; ease?: (t: number) => number; interpolate?: 'smooth' | 'linear'; nodes?: (NodeType | { id: string; })[]; }; /** * Internally, React Flow maintains a coordinate system that is independent of the * rest of the page. The `Viewport` type tells you where in that system your flow * is currently being display at and how zoomed in or out it is. * * @public * @remarks A `Transform` has the same properties as the viewport, but they represent * different things. Make sure you don't get them muddled up or things will start * to look weird! * */ export type Viewport = { x: number; y: number; zoom: number; }; export type KeyCode = string | Array; export type SnapGrid = [number, number]; /** * This enum is used to set the different modes of panning the viewport when the * user scrolls. The `Free` mode allows the user to pan in any direction by scrolling * with a device like a trackpad. The `Vertical` and `Horizontal` modes restrict * scroll panning to only the vertical or horizontal axis, respectively. * * @public */ export declare enum PanOnScrollMode { Free = "free", Vertical = "vertical", Horizontal = "horizontal" } /** * @inline */ export type ViewportHelperFunctionOptions = { duration?: number; ease?: (t: number) => number; interpolate?: 'smooth' | 'linear'; }; /** * @inline */ export type SetCenterOptions = ViewportHelperFunctionOptions & { zoom?: number; }; /** * @inline */ export type FitBoundsOptions = ViewportHelperFunctionOptions & { padding?: Padding; }; export type OnViewportChange = (viewport: Viewport) => void; export type D3ZoomInstance = ZoomBehavior; export type D3SelectionInstance = Selection; export type D3ZoomHandler = (this: Element, event: D3ZoomInputEvent, d: unknown) => void; export type UpdateNodeInternals = (nodeId: string | string[]) => void; /** * This type is mostly used to help position things on top of the flow viewport. For * example both the [``](/api-reference/components/minimap) and * [``](/api-reference/components/controls) components take a `position` * prop of this type. * * @public */ export type PanelPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right' | 'center-left' | 'center-right'; export type UseDragEvent = Omit, 'sourceEvent'> & { sourceEvent: MouseEvent | TouchEvent; }; export declare enum SelectionMode { Partial = "partial", Full = "full" } export type SelectionRect = Rect & { startX: number; startY: number; }; export type OnError = (id: string, message: string) => void; export type UpdateNodePositions = (dragItems: Map, dragging?: boolean) => void; export type PanBy = (delta: XYPosition) => Promise; export declare const initialConnection: NoConnection; export type NoConnection = { inProgress: false; isValid: null; from: null; fromHandle: null; fromPosition: null; fromNode: null; to: null; toHandle: null; toPosition: null; toNode: null; pointer: null; }; export type ConnectionInProgress = { /** Indicates whether a connection is currently in progress. */ inProgress: true; /** * If an ongoing connection is above a handle or inside the connection radius, this will be `true` * or `false`, otherwise `null`. */ isValid: boolean | null; /** Returns the xy start position in flow coordinates or `null` if no connection is in progress. */ from: XYPosition; /** Returns the start handle or `null` if no connection is in progress. */ fromHandle: HandleBounds; /** Returns the side (called position) of the start handle or `null` if no connection is in progress. */ fromPosition: Position; /** Returns the start node or `null` if no connection is in progress. */ fromNode: NodeType; /** Returns the xy end position in flow coordinates or `null` if no connection is in progress. */ to: XYPosition; /** Returns the end handle or `null` if no connection is in progress. */ toHandle: HandleBounds | null; /** Returns the side (called position) of the end handle or `null` if no connection is in progress. */ toPosition: Position; /** Returns the end node or `null` if no connection is in progress. */ toNode: NodeType | null; /** * Returns the pointer position relative to the pane, in screen coordinates, or `null` if no * connection is in progress. */ pointer: XYPosition; }; /** * The `ConnectionState` type bundles all information about an ongoing connection. * It is returned by the [`useConnection`](/api-reference/hooks/use-connection) hook. * * @public */ export type ConnectionState = ConnectionInProgress | NoConnection; export type FinalConnectionState = (Omit, 'inProgress' | 'toPosition'> & { toPosition: Position | null; }) | Omit; export type UpdateConnection = (params: ConnectionState) => void; export type ColorMode = 'light' | 'dark'; export type ConnectionLookup = Map>; export type OnBeforeDeleteBase = ({ nodes, edges }: { nodes: NodeType[]; edges: EdgeType[]; }) => Promise; /** * The `ZIndexMode` type is used to define how z-indexing is calculated for nodes and edges. * `auto` mode will automatically manage z-indexing for selections and sub flows. * `basic` mode will only manage z-indexing for selections. * `manual` mode does not apply any automatic z-indexing. * * @public */ export type ZIndexMode = 'auto' | 'basic' | 'manual'; export type EdgeBase = Record, EdgeType extends string | undefined = string | undefined> = { /** Unique id of an edge. */ id: string; /** Type of edge defined in `edgeTypes`. */ type?: EdgeType; /** Id of source node. */ source: string; /** Id of target node. */ target: string; /** Id of source handle, only needed if there are multiple handles per node. */ sourceHandle?: string | null; /** Id of target handle, only needed if there are multiple handles per node. */ targetHandle?: string | null; animated?: boolean; hidden?: boolean; deletable?: boolean; selectable?: boolean; /** Arbitrary data passed to an edge. */ data?: EdgeData; selected?: boolean; /** * Set the marker on the beginning of an edge. * @example 'arrow', 'arrowclosed' or custom marker */ markerStart?: EdgeMarkerType; /** * Set the marker on the end of an edge. * @example 'arrow', 'arrowclosed' or custom marker */ markerEnd?: EdgeMarkerType; zIndex?: number; ariaLabel?: string; /** * ReactFlow renders an invisible path around each edge to make them easier to click or tap on. * This property sets the width of that invisible path. */ interactionWidth?: number; }; export type SmoothStepPathOptions = { offset?: number; borderRadius?: number; stepPosition?: number; }; export type StepPathOptions = { offset?: number; }; export type BezierPathOptions = { curvature?: number; }; /** * @inline */ export type DefaultEdgeOptionsBase = Omit; /** * If you set the `connectionLineType` prop on your [``](/api-reference/react-flow#connection-connectionLineType) *component, it will dictate the style of connection line rendered when creating *new edges. * * @public * * @remarks If you choose to render a custom connection line component, this value will be *passed to your component as part of its [`ConnectionLineComponentProps`](/api-reference/types/connection-line-component-props). */ export declare enum ConnectionLineType { Bezier = "default", Straight = "straight", Step = "step", SmoothStep = "smoothstep", SimpleBezier = "simplebezier" } /** * Edges can optionally have markers at the start and end of an edge. The `EdgeMarker` *type is used to configure those markers! Check the docs for [`MarkerType`](/api-reference/types/marker-type) *for details on what types of edge marker are available. * * @public */ export type EdgeMarker = { type: MarkerType | `${MarkerType}`; color?: string | null; width?: number; height?: number; markerUnits?: string; orient?: string; strokeWidth?: number; }; export type EdgeMarkerType = string | EdgeMarker; /** * Edges may optionally have a marker on either end. The MarkerType type enumerates * the options available to you when configuring a given marker. * * @public */ export declare enum MarkerType { Arrow = "arrow", ArrowClosed = "arrowclosed" } export type MarkerProps = EdgeMarker & { id: string; }; /** * @inline */ export type EdgePosition = { sourceX: number; sourceY: number; targetX: number; targetY: number; sourcePosition: Position; targetPosition: Position; }; export type EdgeLookup = Map; export type EdgeToolbarBaseProps = { /** * The `x` position of the edge toolbar. */ x: number; /** * The `y` position of the edge toolbar. */ y: number; /** If `true`, edge toolbar is visible even if edge is not selected. * @default false */ isVisible?: boolean; /** * Align the vertical toolbar position relative to the passed x position. * @default "center" * @example 'left', 'center', 'right' */ alignX?: 'left' | 'center' | 'right'; /** * Align the horizontal toolbar position relative to the passed y position. * @default "center" * @example 'top', 'center', 'bottom' */ alignY?: 'top' | 'center' | 'bottom'; }; export declare const errorMessages: { error001: (lib?: string) => string; error002: () => string; error003: (nodeType: string) => string; error004: () => string; error005: () => string; error006: () => string; error007: (id: string) => string; error009: (type: string) => string; error008: (handleType: HandleType, { id, sourceHandle, targetHandle }: { id: string; sourceHandle: string | null; targetHandle: string | null; }) => string; error010: () => string; error011: (edgeType: string) => string; error012: (id: string) => string; error013: (lib?: string) => string; error014: () => string; error015: () => string; error016: (id: string) => string; }; export declare const infiniteExtent: CoordinateExtent; /** Default padding used by `fitView` / `fitBounds` when none is provided. */ export declare const defaultFitViewPadding = "5%"; export declare const elementSelectionKeys: string[]; export declare const defaultAriaLabelConfig: { 'node.a11yDescription.default': string; 'node.a11yDescription.keyboardDisabled': string; 'node.a11yDescription.ariaLiveMessage': ({ direction, x, y }: { direction: string; x: number; y: number; }) => string; 'edge.a11yDescription.default': string; 'controls.ariaLabel': string; 'controls.zoomIn.ariaLabel': string; 'controls.zoomOut.ariaLabel': string; 'controls.fitView.ariaLabel': string; 'controls.interactive.ariaLabel': string; 'minimap.ariaLabel': string; 'handle.ariaLabel': string; }; export type AriaLabelConfig = typeof defaultAriaLabelConfig; export declare function handleAttributionWarning(library: 'react' | 'svelte' | 'vue'): void; /** * Returns the key under which the connections of a node are stored in the connection lookup. * Without a handle type, the key covers all connections of the node. A handle id is only used * together with a handle type, because handle ids are only unique per handle type. * * @internal */ export declare function getConnectionLookupKey(nodeId: string, handleType?: HandleType | null, handleId?: string | null): string; /** * Returns the connections of a node, optionally filtered by handle type and handle id. * * @internal */ export declare function getConnectionsFromLookup(connectionLookup: ConnectionLookup, { nodeId, type, handleId }: { nodeId: string; type?: HandleType | null; handleId?: string | null; }): NodeConnection[]; /** * @internal */ export declare function areConnectionMapsEqual(a?: Map, b?: Map): boolean; /** * We call the callback for all connections in a that are not in b * * @internal */ export declare function handleConnectionChange(a: Map, b: Map, cb?: (diff: NodeConnection[]) => void): void; export declare function getConnectionStatus(isValid: boolean | null): "valid" | "invalid" | null; export type GetPointerPositionParams = { transform: Transform; snapGrid?: SnapGrid; snapToGrid?: boolean; containerBounds: DOMRect | null; }; export declare function getPointerPosition(event: MouseEvent | TouchEvent, { snapGrid, snapToGrid, transform, containerBounds }: GetPointerPositionParams): XYPosition & { xSnapped: number; ySnapped: number; }; export declare const getDimensions: (node: HTMLDivElement) => Dimensions; export declare const getHostForElement: (element: HTMLElement | EventTarget | null) => Document | ShadowRoot; export declare function isInputDOMNode(event: KeyboardEvent): boolean; export declare const getEventPosition: (event: MouseEvent | TouchEvent, bounds?: DOMRect) => { x: number; y: number; }; export declare const getHandleBounds: (type: "source" | "target", nodeElement: HTMLDivElement, nodeBounds: DOMRect, zoom: number, nodeId: string) => HandleBounds[] | null; export type GetBezierPathParams = { /** The `x` position of the source handle. */ sourceX: number; /** The `y` position of the source handle. */ sourceY: number; /** * The position of the source handle. * @default Position.Bottom */ sourcePosition?: Position; /** The `x` position of the target handle. */ targetX: number; /** The `y` position of the target handle. */ targetY: number; /** * The position of the target handle. * @default Position.Top */ targetPosition?: Position; /** * The curvature of the bezier edge. * @default 0.25 */ curvature?: number; }; export type GetControlWithCurvatureParams = { pos: Position; x1: number; y1: number; x2: number; y2: number; c: number; }; export declare function getBezierEdgeCenter({ sourceX, sourceY, targetX, targetY, sourceControlX, sourceControlY, targetControlX, targetControlY }: { sourceX: number; sourceY: number; targetX: number; targetY: number; sourceControlX: number; sourceControlY: number; targetControlX: number; targetControlY: number; }): [number, number, number, number]; /** * The `getBezierPath` util returns everything you need to render a bezier edge *between two nodes. * @public * @returns A path string you can use in an SVG, the `labelX` and `labelY` position (center of path) * and `offsetX`, `offsetY` between source handle and label. * - `path`: the path to use in an SVG `` element. * - `labelX`: the `x` position you can use to render a label for this edge. * - `labelY`: the `y` position you can use to render a label for this edge. * - `offsetX`: the absolute difference between the source `x` position and the `x` position of the * middle of this path. * - `offsetY`: the absolute difference between the source `y` position and the `y` position of the * middle of this path. * @example * ```js * const source = { x: 0, y: 20 }; * const target = { x: 150, y: 100 }; * * const [path, labelX, labelY, offsetX, offsetY] = getBezierPath({ * sourceX: source.x, * sourceY: source.y, * sourcePosition: Position.Right, * targetX: target.x, * targetY: target.y, * targetPosition: Position.Left, *}); *``` * * @remarks This function returns a tuple (aka a fixed-size array) to make it easier to *work with multiple edge paths at once. */ export declare function getBezierPath({ sourceX, sourceY, sourcePosition, targetX, targetY, targetPosition, curvature }: GetBezierPathParams): [path: string, labelX: number, labelY: number, offsetX: number, offsetY: number]; export type GetStraightPathParams = { /** The `x` position of the source handle. */ sourceX: number; /** The `y` position of the source handle. */ sourceY: number; /** The `x` position of the target handle. */ targetX: number; /** The `y` position of the target handle. */ targetY: number; }; /** * Calculates the straight line path between two points. * @public * @returns A path string you can use in an SVG, the `labelX` and `labelY` position (center of path) * and `offsetX`, `offsetY` between source handle and label. * * - `path`: the path to use in an SVG `` element. * - `labelX`: the `x` position you can use to render a label for this edge. * - `labelY`: the `y` position you can use to render a label for this edge. * - `offsetX`: the absolute difference between the source `x` position and the `x` position of the * middle of this path. * - `offsetY`: the absolute difference between the source `y` position and the `y` position of the * middle of this path. * @example * ```js * const source = { x: 0, y: 20 }; * const target = { x: 150, y: 100 }; * * const [path, labelX, labelY, offsetX, offsetY] = getStraightPath({ * sourceX: source.x, * sourceY: source.y, * sourcePosition: Position.Right, * targetX: target.x, * targetY: target.y, * targetPosition: Position.Left, * }); * ``` * @remarks This function returns a tuple (aka a fixed-size array) to make it easier to work with multiple edge paths at once. */ export declare function getStraightPath({ sourceX, sourceY, targetX, targetY }: GetStraightPathParams): [path: string, labelX: number, labelY: number, offsetX: number, offsetY: number]; export interface GetSmoothStepPathParams { /** The `x` position of the source handle. */ sourceX: number; /** The `y` position of the source handle. */ sourceY: number; /** * The position of the source handle. * @default Position.Bottom */ sourcePosition?: Position; /** The `x` position of the target handle. */ targetX: number; /** The `y` position of the target handle. */ targetY: number; /** * The position of the target handle. * @default Position.Top */ targetPosition?: Position; /** @default 5 */ borderRadius?: number; centerX?: number; centerY?: number; /** @default 20 */ offset?: number; /** * Controls where the bend occurs along the path. * 0 = at source, 1 = at target, 0.5 = midpoint * @default 0.5 */ stepPosition?: number; } /** * The `getSmoothStepPath` util returns everything you need to render a stepped path * between two nodes. The `borderRadius` property can be used to choose how rounded * the corners of those steps are. * @public * @returns A path string you can use in an SVG, the `labelX` and `labelY` position (center of path) * and `offsetX`, `offsetY` between source handle and label. * * - `path`: the path to use in an SVG `` element. * - `labelX`: the `x` position you can use to render a label for this edge. * - `labelY`: the `y` position you can use to render a label for this edge. * - `offsetX`: the absolute difference between the source `x` position and the `x` position of the * middle of this path. * - `offsetY`: the absolute difference between the source `y` position and the `y` position of the * middle of this path. * @example * ```js * const source = { x: 0, y: 20 }; * const target = { x: 150, y: 100 }; * * const [path, labelX, labelY, offsetX, offsetY] = getSmoothStepPath({ * sourceX: source.x, * sourceY: source.y, * sourcePosition: Position.Right, * targetX: target.x, * targetY: target.y, * targetPosition: Position.Left, * }); * ``` * @remarks This function returns a tuple (aka a fixed-size array) to make it easier to work with multiple edge paths at once. */ export declare function getSmoothStepPath({ sourceX, sourceY, sourcePosition, targetX, targetY, targetPosition, borderRadius, centerX, centerY, offset, stepPosition }: GetSmoothStepPathParams): [path: string, labelX: number, labelY: number, offsetX: number, offsetY: number]; export declare function getEdgeCenter({ sourceX, sourceY, targetX, targetY }: { sourceX: number; sourceY: number; targetX: number; targetY: number; }): [number, number, number, number]; export type GetEdgeZIndexParams = { sourceNode: InternalNodeBase; targetNode: InternalNodeBase; selected?: boolean; zIndex?: number; elevateOnSelect?: boolean; zIndexMode?: ZIndexMode; }; /** * Returns the z-index for an edge based on the node it connects and whether it is selected. * By default, edges are rendered below nodes. This behaviour is different for edges that are * connected to nodes with a parent, as they are rendered above the parent node. */ export declare function getElevatedEdgeZIndex({ sourceNode, targetNode, selected, zIndex, elevateOnSelect, zIndexMode }: GetEdgeZIndexParams): number; type IsEdgeVisibleParams = { sourceNode: InternalNodeBase; targetNode: InternalNodeBase; width: number; height: number; transform: Transform; }; export declare function isEdgeVisible({ sourceNode, targetNode, width, height, transform }: IsEdgeVisibleParams): boolean; /** * Type for a custom edge ID generator function. * @public */ export type GetEdgeId = (params: Connection | EdgeBase) => string; /** * The default edge ID generator function. Generates an ID based on the source, target, and handles. * @public * @param params - The connection or edge to generate an ID for. * @returns The generated edge ID. */ export declare const getEdgeId: ({ source, sourceHandle, target, targetHandle }: Connection | EdgeBase) => string; export type AddEdgeOptions = { /** * Custom function to generate edge IDs. If not provided, the default `getEdgeId` function is used. */ getEdgeId?: GetEdgeId; /** * Called when edge validation fails. If not provided, a default dev warning is used. */ onError?: OnError; }; /** * This util is a convenience function to add a new Edge to an array of edges. It also performs some validation to make sure you don't add an invalid edge or duplicate an existing one. * @public * @param edgeParams - Either an `Edge` or a `Connection` you want to add. * @param edges - The array of all current edges. * @param options - Optional configuration object. * @returns A new array of edges with the new edge added. * * @remarks If an edge with the same `target` and `source` already exists (and the same *`targetHandle` and `sourceHandle` if those are set), then this util won't add *a new edge even if the `id` property is different. * */ export declare const addEdge: (edgeParams: EdgeType | Connection, edges: EdgeType[], options?: AddEdgeOptions) => EdgeType[]; export type ReconnectEdgeOptions = { /** * Should the id of the old edge be replaced with the new connection id. * @default true */ shouldReplaceId?: boolean; /** * Custom function to generate edge IDs. If not provided, the default `getEdgeId` function is used. */ getEdgeId?: GetEdgeId; /** * Called when edge validation fails. If not provided, a default dev warning is used. */ onError?: OnError; }; /** * A handy utility to update an existing [`Edge`](/api-reference/types/edge) with new properties. *This searches your edge array for an edge with a matching `id` and updates its *properties with the connection you provide. * @public * @param oldEdge - The edge you want to update. * @param newConnection - The new connection you want to update the edge with. * @param edges - The array of all current edges. * @returns The updated edges array. * * @example * ```js *const onReconnect = useCallback( * (oldEdge: Edge, newConnection: Connection) => setEdges((els) => reconnectEdge(oldEdge, newConnection, els)),[]); *``` */ export declare const reconnectEdge: (oldEdge: EdgeType, newConnection: Connection, edges: EdgeType[], options?: ReconnectEdgeOptions) => EdgeType[]; export type GetEdgePositionParams = { id: string; sourceNode: InternalNodeBase; sourceHandle: string | null; targetNode: InternalNodeBase; targetHandle: string | null; connectionMode: ConnectionMode; onError?: OnError; }; export declare function getEdgePosition(params: GetEdgePositionParams): EdgePosition | null; export declare function getHandlePosition(node: InternalNodeBase, handle: HandleBounds | null, fallbackPosition?: Position, center?: boolean): XYPosition; /** * Test whether an object is usable as an Edge * @public * @remarks In TypeScript this is a type guard that will narrow the type of whatever you pass in to Edge if it returns true * @param element - The element to test * @returns A boolean indicating whether the element is an Edge */ export declare const isEdgeBase: (element: unknown) => element is EdgeType; /** * Test whether an object is usable as a Node * @public * @remarks In TypeScript this is a type guard that will narrow the type of whatever you pass in to Node if it returns true * @param element - The element to test * @returns A boolean indicating whether the element is an Node */ export declare const isNodeBase: (element: unknown) => element is NodeType; export declare const isInternalNodeBase: (element: unknown) => element is NodeType; /** * This util is used to tell you what nodes, if any, are connected to the given node * as the _target_ of an edge. * @public * @param node - The node to get the connected nodes from. * @param nodes - The array of all nodes. * @param edges - The array of all edges. * @returns An array of nodes that are connected over edges where the source is the given node. * * @example * ```ts *import { getOutgoers } from '@xyflow/react'; * *const nodes = []; *const edges = []; * *const outgoers = getOutgoers( * { id: '1', position: { x: 0, y: 0 }, data: { label: 'node' } }, * nodes, * edges, *); *``` */ export declare const getOutgoers: (node: NodeType | { id: string; }, nodes: NodeType[], edges: EdgeType[]) => NodeType[]; /** * This util is used to tell you what nodes, if any, are connected to the given node * as the _source_ of an edge. * @public * @param node - The node to get the connected nodes from. * @param nodes - The array of all nodes. * @param edges - The array of all edges. * @returns An array of nodes that are connected over edges where the target is the given node. * * @example * ```ts *import { getIncomers } from '@xyflow/react'; * *const nodes = []; *const edges = []; * *const incomers = getIncomers( * { id: '1', position: { x: 0, y: 0 }, data: { label: 'node' } }, * nodes, * edges, *); *``` */ export declare const getIncomers: (node: NodeType | { id: string; }, nodes: NodeType[], edges: EdgeType[]) => NodeType[]; export declare const getNodePositionWithOrigin: (node: NodeBase, nodeOrigin?: NodeOrigin) => XYPosition; export type GetNodesBoundsParams = { /** * Origin of the nodes: `[0, 0]` for top-left, `[0.5, 0.5]` for center. * @default [0, 0] */ nodeOrigin?: NodeOrigin; nodeLookup?: NodeLookup>; }; /** * Returns the bounding box that contains all the given nodes in an array. This can * be useful when combined with [`getViewportForBounds`](/api-reference/utils/get-viewport-for-bounds) * to calculate the correct transform to fit the given nodes in a viewport. * @public * @remarks Useful when combined with {@link getViewportForBounds} to calculate the correct transform to fit the given nodes in a viewport. * @param nodes - Nodes to calculate the bounds for. * @returns Bounding box enclosing all nodes. * * @remarks This function was previously called `getRectOfNodes` * * @example * ```js *import { getNodesBounds } from '@xyflow/react'; * *const nodes = [ * { * id: 'a', * position: { x: 0, y: 0 }, * data: { label: 'a' }, * width: 50, * height: 25, * }, * { * id: 'b', * position: { x: 100, y: 100 }, * data: { label: 'b' }, * width: 50, * height: 25, * }, *]; * *const bounds = getNodesBounds(nodes); *``` */ export declare const getNodesBounds: (nodes: (NodeType | InternalNodeBase | string)[], params?: GetNodesBoundsParams) => Rect; export type GetInternalNodesBoundsParams = { useRelativePosition?: boolean; filter?: (node: NodeType) => boolean; }; /** * Determines a bounding box that contains all given nodes in an array * @internal */ export declare const getInternalNodesBounds: (nodeLookup: Map, params?: GetInternalNodesBoundsParams) => Rect; export declare const getNodesInside: (nodes: Map>, rect: Rect, [tx, ty, tScale]?: Transform, partially?: boolean, excludeNonSelectableNodes?: boolean) => InternalNodeBase[]; /** * This utility filters an array of edges, keeping only those where either the source or target * node is present in the given array of nodes. * @public * @param nodes - Nodes you want to get the connected edges for. * @param edges - All edges. * @returns Array of edges that connect any of the given nodes with each other. * * @example * ```js *import { getConnectedEdges } from '@xyflow/react'; * *const nodes = [ * { id: 'a', position: { x: 0, y: 0 } }, * { id: 'b', position: { x: 100, y: 0 } }, *]; * *const edges = [ * { id: 'a->c', source: 'a', target: 'c' }, * { id: 'c->d', source: 'c', target: 'd' }, *]; * *const connectedEdges = getConnectedEdges(nodes, edges); * // => [{ id: 'a->c', source: 'a', target: 'c' }] *``` */ export declare const getConnectedEdges: (nodes: NodeType[], edges: EdgeType[]) => EdgeType[]; export declare function fitViewport, Options extends FitViewOptionsBase>({ nodes, width, height, panZoom, minZoom, maxZoom }: Params, options?: Omit): Promise; /** * This function calculates the next position of a node, taking into account the node's extent, parent node, and origin. * * @internal * @returns position, positionAbsolute */ export declare function calculateNodePosition({ nodeId, nextPosition, nodeLookup, nodeOrigin, nodeExtent, onError }: { nodeId: string; nextPosition: XYPosition; nodeLookup: NodeLookup>; nodeOrigin?: NodeOrigin; nodeExtent?: CoordinateExtent; onError?: OnError; }): { position: XYPosition; positionAbsolute: XYPosition; }; /** * Pass in nodes & edges to delete, get arrays of nodes and edges that actually can be deleted * @internal * @param param.nodesToRemove - The nodes to remove * @param param.edgesToRemove - The edges to remove * @param param.nodes - All nodes * @param param.edges - All edges * @param param.onBeforeDelete - Callback to check which nodes and edges can be deleted * @returns nodes: nodes that can be deleted, edges: edges that can be deleted */ export declare function getElementsToRemove({ nodesToRemove, edgesToRemove, nodes, edges, onBeforeDelete }: { nodesToRemove: Partial[]; edgesToRemove: Partial[]; nodes: NodeType[]; edges: EdgeType[]; onBeforeDelete?: OnBeforeDeleteBase; }): Promise<{ nodes: NodeType[]; edges: EdgeType[]; }>; export declare const clamp: (val: number, min?: number, max?: number) => number; export declare const clampPosition: (position: XYPosition | undefined, extent: CoordinateExtent, dimensions: Partial) => { x: number; y: number; }; export declare function clampPositionToParent(childPosition: XYPosition, childDimensions: Dimensions, parent: InternalNodeBase): { x: number; y: number; }; export declare const calcAutoPan: (pos: XYPosition, bounds: Dimensions, speed?: number, distance?: number) => number[]; export declare const getBoundsOfBoxes: (box1: Box, box2: Box) => Box; export declare const rectToBox: ({ x, y, width, height }: Rect) => Box; export declare const boxToRect: ({ x, y, x2, y2 }: Box) => Rect; export declare const nodeToRect: (node: InternalNodeBase | NodeBase, nodeOrigin?: NodeOrigin) => Rect; export declare const nodeToBox: (node: InternalNodeBase | NodeBase, nodeOrigin?: NodeOrigin) => Box; export declare const getBoundsOfRects: (rect1: Rect, rect2: Rect) => Rect; export declare const getRectsOverlappingArea: (aX: number, aY: number, aWidth: number, aHeight: number, bX: number, bY: number, bWidth: number, bHeight: number) => number; export declare const getOverlappingArea: (rectA: Rect, rectB: Rect) => number; export declare const isRectObject: (obj: unknown) => obj is Rect; export declare const isNumeric: (n: unknown) => n is number; export declare const createDevWarn: (lib: string, helpUrl: string) => OnError; export declare const snapPosition: (position: XYPosition, snapGrid?: SnapGrid) => XYPosition; export declare const pointToRendererPoint: ({ x, y }: XYPosition, [tx, ty, tScale]: Transform, snapToGrid?: boolean, snapGrid?: SnapGrid) => XYPosition; export declare const rendererPointToPoint: ({ x, y }: XYPosition, [tx, ty, tScale]: Transform) => XYPosition; /** * Returns a viewport that encloses the given bounds with padding. * @public * @remarks You can determine bounds of nodes with {@link getNodesBounds} and {@link getBoundsOfRects} * @param bounds - Bounds to fit inside viewport. * @param width - Width of the viewport. * @param height - Height of the viewport. * @param minZoom - Minimum zoom level of the resulting viewport. * @param maxZoom - Maximum zoom level of the resulting viewport. * @param padding - Padding around the bounds. * @returns A transformed {@link Viewport} that encloses the given bounds which you can pass to e.g. {@link setViewport}. * @example * const { x, y, zoom } = getViewportForBounds( * { x: 0, y: 0, width: 100, height: 100}, * 1200, 800, 0.5, 2); */ export declare const getViewportForBounds: (bounds: Rect, width: number, height: number, minZoom?: number, maxZoom?: number, padding?: Padding) => Viewport; export declare const isMacOs: () => boolean; export declare function isCoordinateExtent(extent?: CoordinateExtent | 'parent' | null): extent is CoordinateExtent; export declare function getNodeDimensions(node: { measured?: { width?: number; height?: number; }; width?: number; height?: number; initialWidth?: number; initialHeight?: number; }): { width: number; height: number; }; export declare function nodeHasDimensions(node: NodeType): boolean; /** * Convert child position to absolute position * * @internal * @param position * @param parentId * @param nodeLookup * @param nodeOrigin * @returns an internal node with an absolute position */ export declare function evaluateAbsolutePosition(position: XYPosition, dimensions: { width?: number; height?: number; } | undefined, parentId: string, nodeLookup: NodeLookup, nodeOrigin: NodeOrigin): XYPosition; export declare function areSetsEqual(a: Set, b: Set): boolean; /** * Polyfill for Promise.withResolvers until we can use it in all browsers * @internal */ export declare function withResolvers(): { promise: Promise; resolve: (value: T | PromiseLike) => void; reject: (reason?: unknown) => void; }; export declare function mergeAriaLabelConfig(partial?: Partial): AriaLabelConfig; export declare function isAttributionVisible(library: string): boolean; export declare function getMarkerId(marker: EdgeMarkerType | undefined, id?: string | null): string; export declare function createMarkerIds(edges: EdgeBase[], { id, defaultColor, defaultMarkerStart, defaultMarkerEnd }: { id?: string | null; defaultColor?: string | null; defaultMarkerStart?: EdgeMarkerType; defaultMarkerEnd?: EdgeMarkerType; }): MarkerProps[]; export declare function getNodeToolbarTransform(nodeRect: Rect, viewport: Viewport, position: Position, offset: number, align: Align): string; export declare function getEdgeToolbarTransform(x: number, y: number, zoom: number, alignX?: 'left' | 'center' | 'right', alignY?: 'top' | 'center' | 'bottom'): string; export type Optional = Pick, K> & Omit; export type ParentExpandChild = { id: string; parentId: string; rect: Rect; }; export declare function updateAbsolutePositions(nodeLookup: NodeLookup>, parentLookup: ParentLookup>, options?: UpdateNodesOptions): void; type UpdateNodesOptions = { nodeOrigin?: NodeOrigin; nodeExtent?: CoordinateExtent; elevateNodesOnSelect?: boolean; defaults?: Partial; zIndexMode?: ZIndexMode; checkEquality?: boolean; }; export declare function isManualZIndexMode(zIndexMode?: ZIndexMode): boolean; type AdoptUserNodesReturn = { nodesInitialized: boolean; hasSelectedNodes: boolean; updatedNodes: Set; }; export declare function adoptUserNodes(nodes: NodeType[], nodeLookup: NodeLookup>, parentLookup: ParentLookup>, options?: UpdateNodesOptions): AdoptUserNodesReturn; export declare function handleExpandParent(children: ParentExpandChild[], nodeLookup: NodeLookup, parentLookup: ParentLookup, nodeOrigin?: NodeOrigin): (DimensionChange | PositionChange)[]; export declare function updateNodeInternals(updates: Map, nodeLookup: NodeLookup, parentLookup: ParentLookup, domNode: HTMLElement | null, nodeOrigin?: NodeOrigin, nodeExtent?: CoordinateExtent, zIndexMode?: ZIndexMode): { changes: (DimensionChange | PositionChange)[]; updatedInternals: boolean; updatedNodes: Set; }; export declare function panBy({ delta, panZoom, transform, translateExtent, width, height }: { delta: XYPosition; panZoom: PanZoomInstance | null; transform: Transform; translateExtent: CoordinateExtent; width: number; height: number; }): Promise; export declare function updateConnectionLookup(connectionLookup: ConnectionLookup, edgeLookup: EdgeLookup, edges: EdgeBase[]): { updatedEdges: Set; }; type NodeData = Pick; export declare function shallowNodeData(a: NodeData | NodeData[] | null, b: NodeData | NodeData[] | null): boolean; export declare function changeParentNode(nodeId: string, nodeLookup: NodeLookup, parentId: string | null, nodeOrigin: NodeOrigin, updateNodeCallback: (args: { nodeId: string; parentId: string | null; x: number; y: number; }) => void): void; export type OnDrag = (event: MouseEvent | TouchEvent, dragItems: Map, node: NodeType, nodes: NodeType[]) => void; type OnNodeDrag = (e: MouseEvent | TouchEvent, node: NodeType, nodes: NodeType[]) => void | undefined; type FlowGraph = { nodes: NodeType[]; edges: EdgeType[]; }; type StoreItems = { nodes: NodeType[]; nodeLookup: Map>; edges: EdgeType[]; nodeExtent: CoordinateExtent; snapGrid: SnapGrid; snapToGrid: boolean; nodeOrigin: NodeOrigin; multiSelectionActive: boolean; domNode?: Element | null; transform: Transform; autoPanOnNodeDrag: boolean; nodesDraggable: boolean; selectNodesOnDrag: boolean; nodeDragThreshold: number; panBy: PanBy; unselectNodesAndEdges: (params?: Partial>) => void; onError?: OnError; onNodeDragStart?: OnNodeDrag; onNodeDrag?: OnNodeDrag; onNodeDragStop?: OnNodeDrag; onSelectionDragStart?: OnSelectionDrag; onSelectionDrag?: OnSelectionDrag; onSelectionDragStop?: OnSelectionDrag; updateNodePositions: UpdateNodePositions>; autoPanSpeed?: number; }; export type XYDragParams = { getStoreItems: () => StoreItems; onDragStart?: OnDrag; onDrag?: OnDrag; onDragStop?: OnDrag; onNodeMouseDown?: (id: string) => void; autoPanSpeed?: number; }; export type XYDragInstance = { update: (params: DragUpdateParams) => void; destroy: () => void; }; export type DragUpdateParams = { noDragClassName?: string; handleSelector?: string; isSelectable?: boolean; nodeId?: string; domNode: Element; }; export declare function XYDrag({ onNodeMouseDown, getStoreItems, onDragStart, onDrag, onDragStop }: XYDragParams): XYDragInstance; type OnPointerDownParams = { autoPanOnConnect: boolean; connectionMode: ConnectionMode; connectionRadius: number; domNode: HTMLDivElement | null; handleId: string | null; nodeId: string; isTarget: boolean; nodeLookup: NodeLookup>; lib: string; flowId: string | null; edgeUpdaterType?: HandleType; updateConnection: UpdateConnection>; panBy: PanBy; cancelConnection: () => void; onConnectStart?: OnConnectStart; onConnect?: OnConnect; onConnectEnd?: OnConnectEnd; isValidConnection?: IsValidConnection; onReconnectEnd?: (evt: MouseEvent | TouchEvent, connectionState: FinalConnectionState>) => void; getTransform: () => Transform; getFromHandle: () => HandleBounds | null; autoPanSpeed?: number; dragThreshold?: number; handleDomNode: Element; }; type IsValidParams = { handle: Pick | null; connectionMode: ConnectionMode; fromNodeId: string; fromHandleId: string | null; fromType: HandleType; isValidConnection?: IsValidConnection; doc: Document | ShadowRoot; lib: string; flowId: string | null; nodeLookup: NodeLookup>; }; type XYHandleInstance = { onPointerDown: (event: MouseEvent | TouchEvent, params: OnPointerDownParams) => void; isValid: (event: MouseEvent | TouchEvent, params: IsValidParams) => Result; }; type Result = { handleDomNode: Element | null; isValid: boolean; connection: Connection | null; toHandle: HandleBounds | null; }; export declare const XYHandle: XYHandleInstance; export type XYMinimapInstance = { update: (params: XYMinimapUpdate) => void; destroy: () => void; pointer: typeof pointer; }; export type XYMinimapParams = { panZoom: PanZoomInstance; domNode: Element; getTransform: () => Transform; getViewScale: () => number; }; export type XYMinimapUpdate = { translateExtent: CoordinateExtent; width: number; height: number; inversePan?: boolean; zoomStep?: number; pannable?: boolean; zoomable?: boolean; }; export declare function XYMinimap({ domNode, panZoom, getTransform, getViewScale }: XYMinimapParams): { update: ({ translateExtent, width, height, zoomStep, pannable, zoomable, inversePan }: XYMinimapUpdate) => void; destroy: () => void; pointer: typeof pointer; }; export type ZoomPanValues = { isZoomingOrPanning: boolean; prevViewport: Viewport; mouseButton: number; timerId: ReturnType | undefined; panScrollTimeout: ReturnType | undefined; isPanScrolling: boolean; pointerDrag: { isTouch: boolean; touchId: number | null; startX: number; startY: number; startTransform: ZoomTransform; thresholdCrossed: boolean; lastMove: Event | null; moveStarted: boolean; dragging: boolean; } | null; }; export declare function XYPanZoom({ domNode, minZoom, maxZoom, translateExtent, viewport, onPanZoom, onPanZoomStart, onPanZoomEnd, onDraggingChange }: PanZoomParams): PanZoomInstance; export declare const isLeftClickPan: (panOnDrag: boolean | number[]) => boolean; /** * @public * @inline */ export type ResizeParams = { x: number; y: number; width: number; height: number; }; export type ResizeParamsWithDirection = ResizeParams & { direction: number[]; }; /** * Used to determine the control line position of the NodeResizer * * @public * @inline */ export type ControlLinePosition = 'top' | 'bottom' | 'left' | 'right'; /** * Used to determine the control position of the NodeResizer * * @public * @inline */ export type ControlPosition = ControlLinePosition | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'; /** * Used to determine the variant of the resize control * * @public */ export declare enum ResizeControlVariant { Line = "line", Handle = "handle" } /** * The direction the user can resize the node. * @public * @inline */ export type ResizeControlDirection = 'horizontal' | 'vertical'; export declare const XY_RESIZER_HANDLE_POSITIONS: ControlPosition[]; export declare const XY_RESIZER_LINE_POSITIONS: ControlLinePosition[]; type OnResizeHandler = (event: ResizeDragEvent, params: Params) => Result; export type ResizeDragEvent = Omit, 'sourceEvent'> & { sourceEvent: MouseEvent | TouchEvent; }; /** * Callback to determine if node should resize * * @inline * @public */ export type ShouldResize = OnResizeHandler; export type OnResizeStart = OnResizeHandler; export type OnResize = OnResizeHandler; export type OnResizeEnd = OnResizeHandler; export type XYResizerChange = { x?: number; y?: number; width?: number; height?: number; }; export type XYResizerChildChange = { id: string; position: XYPosition; extent?: NodeBase['extent']; }; type XYResizerParams = { domNode: HTMLDivElement; nodeId: string; getStoreItems: () => { nodeLookup: NodeLookup; transform: Transform; snapGrid?: [number, number]; snapToGrid: boolean; nodeOrigin: NodeOrigin; paneDomNode: HTMLDivElement | null; }; onChange: (changes: XYResizerChange, childChanges: XYResizerChildChange[]) => void; onEnd?: (change: Required) => void; }; type XYResizerUpdateParams = { controlPosition: ControlPosition; boundaries: { minWidth: number; minHeight: number; maxWidth: number; maxHeight: number; }; keepAspectRatio: boolean; resizeDirection?: ResizeControlDirection; onResizeStart: OnResizeStart | undefined; onResize: OnResize | undefined; onResizeEnd: OnResizeEnd | undefined; shouldResize: ShouldResize | undefined; }; export type XYResizerInstance = { update: (params: XYResizerUpdateParams) => void; destroy: () => void; }; export declare function XYResizer({ domNode, nodeId, getStoreItems, onChange, onEnd }: XYResizerParams): XYResizerInstance; export type NodeChange = DimensionChange | PositionChange | SelectionChange | RemoveChange | AddChange | ReplaceChange | UpdateChange | DataChange; export type EdgeChange = SelectionChange | RemoveChange | AddChange | ReplaceChange | UpdateChange | DataChange>; export type ElementChangeType = NodeChange | EdgeChange; export type DimensionChange = { id: string; type: 'dimensions'; dimensions?: Dimensions; resizing?: boolean; setAttributes?: boolean | 'width' | 'height'; }; export type PositionChange = { id: string; type: 'position'; position?: XYPosition; positionAbsolute?: XYPosition; dragging?: boolean; }; export type SelectionChange = { id: string; type: 'select'; selected: boolean; }; export type RemoveChange = { id: string; type: 'remove'; }; export type AddChange = { id: string; item: NodeOrEdge; type: 'add'; index?: number; }; export type ReplaceChange = { id: string; item: NodeOrEdge; type: 'replace'; }; export type UpdateChange = { id: string; item: Partial; type: 'update'; }; export type DataChange> = { id: string; type: 'data'; data: Partial; replace?: false; } | { id: string; type: 'data'; data: Data; replace: true; }; /** Helper to narrow down the type of a change based on it's name */ type ChangeOfType = Extract; /** Generic apply changes function that works for both nodes and changes */ type ApplyChangesFn> = (elements: ElementType[], changes: Changeset) => ElementType[]; /** * Tracks a batch of changes to be applied to either edges or nodes * TODO: include a way to split ephemeral dimension changes to split * * @example * ```ts * const changes = new NodeChanges(); * changes.add({ id: '1', type: 'position', position: { x: 10, y: 20 } }); * const nextNodes = changes.applyTo(nodes); * ``` */ export declare class Changeset> { private applyChanges; private changeTypes; private changeMap; /** add changes are tracked separately, there can only be one per element */ private addChanges; constructor(applyChanges: ApplyChangesFn); /** * Queues a change for an element. * * @example * ```ts * changes.add(selectionChange('1', true)); * changes.add(positionChnage('1', { x: 0, y: 0 })); * ``` */ add(change: ChangeType | ChangeType[]): void; /** * Removes a specific change by object reference * * @example * ```ts * const change = { id: '1', type: 'select', selected: true }; * changes.add(change); * changes.remove(change); * ``` */ remove(change: ChangeType): void; /** * Returns all queued changes for an element. * * @example * ```ts * const elementChanges = changes.getForElement('1'); * ``` */ getForElement(elementId: string): ChangeType[]; /** * Clears every change for an element. * * @example * ```ts * changes.removeForElement('1'); * ``` */ removeForElement(elementId: string): void; /** * Clears all queued changes. * * @example * ```ts * changes.clear(); * ``` */ clear(): void; /** * Returns true if there are no queued changes. * * @example * ```ts * if (changes.isEmpty()) return; * ``` */ isEmpty(): boolean; /** * Iterates over all queued changes. * * @example * ```ts * for (const change of changes) { * console.log(change.type, change.id); * } * ``` */ [Symbol.iterator](): Iterator; /** * Returns all elements that are added by this changeset. * * @example * ```ts * const newElements = changes.getNewElements(); * ``` */ getNewElements(): ElementType[]; /** * Returns all queued changes as a flat array. * * @example * ```ts * const list = changes.toArray(); * ``` */ toArray(): ChangeType[]; /** * Returns all changes of a given type (e.g. `'position'`, `'select'`). * * @example * ```ts * const positionChanges = changes.getByType('position'); * ``` */ getByType(changeType: T): ChangeOfType[]; /** * Applies the queued changes to an elements array and returns the result. * * @example * ```ts * const nextElements = changes.applyTo(elements); * ``` */ applyTo(elements: ElementType[]): ElementType[]; } /** * Defines a batch of changes to be applied to nodes * * @example * ```ts * const changes = new NodeChanges(); * changes.add({ id: '1', type: 'position', position: { x: 10, y: 20 } }); * const nextNodes = changes.applyTo(nodes); * ``` */ export declare class NodeChangeset extends Changeset> { constructor(changes?: NodeChange[]); /** * Returns all queued changes for a node. * * @example * ```ts * const nodeChanges = changes.getForNode('1'); * ``` */ getForNode(nodeId: string): NodeChange[]; /** * Clears every change for a node. * * @example * ```ts * changes.removeForNode('1'); * ``` */ removeForNode(nodeId: string): void; /** * Returns all nodes that are added by this changeset. * * @example * ```ts * const newNodes = changes.getNewNodes(); * ``` */ getNewNodes(): NodeType[]; } /** * Defines a batch of changes to be applied to the edges * * @example * ```ts * const changes = new EdgeChanges(); * changes.add({ id: 'e1', type: 'select', selected: true }); * const nextEdges = changes.applyTo(edges); * ``` */ export declare class EdgeChangeset extends Changeset> { constructor(changes?: EdgeChange[]); /** * Returns all queued changes for an edge. * * @example * ```ts * const edgeChanges = changes.getForEdge('e1'); * ``` */ getForEdge(edgeId: string): EdgeChange[]; /** * Clears every change for an edge. * * @example * ```ts * changes.removeForEdge('e1'); * ``` */ removeForEdge(edgeId: string): void; /** * Returns all edges that are added by this changeset. * * @example * ```ts * const newEdges = changes.getNewEdges(); * ``` */ getNewEdges(): EdgeType[]; } export declare function applyNodeChanges(nodes: NodeType[], nodeChanges: Changeset>): NodeType[]; export declare function applyEdgeChanges(edges: EdgeType[], edgeChanges: Changeset>): EdgeType[]; export declare function applyEdgeChange(edge: EdgeType, change: EdgeChange): void; export declare function selectionChange(id: string, selected: boolean): SelectionChange; export declare function positionChange(id: string, position: XYPosition): PositionChange; export declare function dimensionChange(id: string, dimensions: Dimensions): DimensionChange; export declare function removeChange(id: string): RemoveChange; export declare function addChange(item: T): AddChange; export declare function replaceChange(item: T): ReplaceChange; export declare function updateChange(id: string, item: Partial): UpdateChange; export declare function dataChange>(id: string, data: Data, replace: true): DataChange; export declare function dataChange>(id: string, data: Partial, replace?: false): DataChange; export declare function getSelectionChanges(items: Map, selectedIds?: Set): SelectionChange[]; export declare function getDeselectionChanges(items: Map, deselectedIds?: Set | null): SelectionChange[]; export {}; //# sourceMappingURL=index.d.ts.map