@gravity-ui/graph
Version:
Modern graph editor component
93 lines (92 loc) • 4.33 kB
TypeScript
import { BaseConnection, TBaseConnectionProps, TBaseConnectionState } from "../../components/canvas/connections";
import { TGraphLayerContext } from "../../components/canvas/layers/graphLayer/GraphLayer";
import { TConnectionColors } from "../../graphConfig";
import { ESelectionStrategy, ISelectionBucket } from "../../services/selection/types";
import { TBlockId } from "../block/Block";
import { ConnectionsStore } from "./ConnectionList";
import { TPortId } from "./port/Port";
export declare const IS_CONNECTION_TYPE: "Connection";
export type TConnectionId = string | number;
export type TConnectionBlockPoint = {};
export type TConnectionPortPoint = {};
export type TConnection = {
id?: TConnectionId;
sourceBlockId?: TBlockId;
targetBlockId?: TBlockId;
sourceAnchorId?: string;
targetAnchorId?: string;
sourcePortId?: TPortId;
targetPortId?: TPortId;
label?: string;
styles?: Partial<TConnectionColors> & {
dashes?: number[];
};
dashed?: boolean;
selected?: boolean;
} & (TConnectionBlockPoint | TConnectionPortPoint);
export declare class ConnectionState<T extends TConnection = TConnection> {
store: ConnectionsStore;
private readonly connectionSelectionBucket;
$state: import("@preact/signals-core").Signal<T>;
private isDestroyed;
get id(): TConnectionId;
get sourceBlockId(): TBlockId;
get sourceAnchorId(): string;
get targetBlockId(): TBlockId;
get targetAnchorId(): string;
$sourcePortId: import("@preact/signals-core").ReadonlySignal<TPortId>;
$targetPortId: import("@preact/signals-core").ReadonlySignal<TPortId>;
readonly $sourcePortState: import("@preact/signals-core").ReadonlySignal<import("./port/Port").PortState>;
readonly $targetPortState: import("@preact/signals-core").ReadonlySignal<import("./port/Port").PortState>;
readonly $sourcePort: import("@preact/signals-core").ReadonlySignal<import("./port/Port").TPort>;
readonly $targetPort: import("@preact/signals-core").ReadonlySignal<import("./port/Port").TPort>;
readonly $sourceBlock: import("@preact/signals-core").ReadonlySignal<import("../block/Block").BlockState<any>>;
readonly $targetBlock: import("@preact/signals-core").ReadonlySignal<import("../block/Block").BlockState<any>>;
$geometry: import("@preact/signals-core").ReadonlySignal<import("./port/Port").TPort[]>;
/**
* Computed signal that reactively determines if this connection is selected
* by checking if its ID exists in the selection bucket
*/
readonly $selected: import("@preact/signals-core").ReadonlySignal<boolean>;
static getConnectionId(connection: TConnection): TConnectionId;
private viewComponent;
constructor(store: ConnectionsStore, connectionState: T, connectionSelectionBucket: ISelectionBucket<string | number>);
/**
* Sets the view component for this connection state
* @param viewComponent - The BaseConnection component instance
* @returns {void}
*/
setViewComponent<P extends TBaseConnectionProps, S extends TBaseConnectionState, C extends TGraphLayerContext>(viewComponent: BaseConnection<P, S, C, T>): void;
/**
* Gets the view component associated with this connection state.
* @returns The BaseConnection view component or undefined if not set.
*/
getViewComponent(): BaseConnection<TBaseConnectionProps, TBaseConnectionState, TGraphLayerContext, T>;
/**
* Checks if the connection is currently selected.
* @returns True if the connection is selected, false otherwise.
*/
isSelected(): boolean;
setSelection(selected: boolean, strategy?: ESelectionStrategy): void;
/**
* @deprecated Use `toJSON` instead.
* @returns {TConnection} A deep copy of the connection data
*/
asTConnection(): TConnection;
/**
* Converts the connection state to a plain JSON object
* @returns {TConnection} A deep copy of the connection data
*/
toJSON(): TConnection;
/**
* Updates the connection with new data
* @param connection - Partial connection data to update
* @returns {void}
*/
updateConnection(connection: Partial<TConnection>): void;
/**
* Clean up port observers when connection is destroyed
* @returns {void}
*/
destroy(): void;
}