UNPKG

@gravity-ui/graph

Version:

Modern graph editor component

58 lines (57 loc) 2.59 kB
import { GraphComponent } from "../../../components/canvas/GraphComponent"; import { Graph } from "../../../graph"; import { Component } from "../../../lib"; import { TPoint } from "../../../utils/types/shapes"; import { RootStore } from "../../index"; import { PortState, TPortId } from "./Port"; export declare class PortsStore { rootStore: RootStore; protected graph: Graph; $ports: import("@preact/signals-core").ReadonlySignal<PortState<unknown>[]>; $portsMap: import("@preact/signals-core").Signal<Map<TPortId, PortState<unknown>>>; constructor(rootStore: RootStore, graph: Graph); createPort(id: TPortId, component: Component): PortState; getPort(id: TPortId): PortState | undefined; getOrCreatePort(id: TPortId, component?: Component): PortState; deletePort(id: TPortId): boolean; deletePorts(ids: TPortId[]): void; clearPorts(): void; protected notifyPortMapChanged: (() => void) & { cancel: () => void; flush: () => void; isScheduled: () => boolean; }; getPortsByComponent(component: GraphComponent): PortState[]; ownPort(port: PortState, component: GraphComponent): void; unownPort(port: PortState, component: GraphComponent): void; reset(): void; /** * Find the nearest port at given world coordinates * First finds components under cursor, then checks their ports * * @param point World coordinates to search from * @param searchRadius Maximum search radius in pixels (default: 0 - exact match) * @param filter Optional filter function to validate ports * @returns Nearest port within radius, or undefined if none found * * @example * ```typescript * const port = portsStore.findPortAtPoint( * { x: 100, y: 200 }, * 30, * (port) => !port.lookup && port.owner !== undefined * ); * ``` */ findPortAtPoint(point: TPoint, searchRadius?: number, filter?: (port: PortState) => boolean): PortState | undefined; /** * Find the nearest port at given world coordinates for a specific component * * @param component Component to search in * @param point World coordinates to search from * @param searchRadius Maximum search radius in pixels (default: 0 - exact match) * @param filter Optional filter function to validate ports * @returns Nearest port within radius, or undefined if none found */ findPortAtPointByComponent(component: GraphComponent, point: TPoint, searchRadius?: number, filter?: (port: PortState) => boolean): PortState | undefined; }