@gravity-ui/graph
Version:
Modern graph editor component
265 lines (264 loc) • 10.8 kB
TypeScript
import { BaseConnection } from "../../components/canvas/connections";
import { Graph } from "../../graph";
import { Component } from "../../lib";
import { MultipleSelectionBucket } from "../../services/selection/MultipleSelectionBucket";
import { ESelectionStrategy } from "../../services/selection/types";
import { RootStore } from "../index";
import { ConnectionState, TConnection, TConnectionId } from "./ConnectionState";
import { PortState, TPortId } from "./port/Port";
import { PortsStore } from "./port/PortList";
declare module "../../graphEvents" {
interface GraphEventsDefinitions {
"connection-selection-change": (event: SelectionEvent<TConnection["id"]>) => void;
}
}
export declare class ConnectionsStore {
rootStore: RootStore;
protected graph: Graph;
$connections: import("@preact/signals-core").ReadonlySignal<ConnectionState<{
id?: TConnectionId;
sourceBlockId?: import("../..").TBlockId;
targetBlockId?: import("../..").TBlockId;
sourceAnchorId?: string;
targetAnchorId?: string;
sourcePortId?: TPortId;
targetPortId?: TPortId;
label?: string;
styles?: Partial<import("../../graphConfig").TConnectionColors> & {
dashes? /**
* @deprecated Use connectionSelectionBucket.$selectedEntities instead
* Computed signal that returns selected connections as ConnectionState instances
*/: number[];
};
dashed?: boolean;
selected?: boolean;
}>[]>;
$connectionsMap: import("@preact/signals-core").Signal<Map<TConnectionId, ConnectionState<{
id?: TConnectionId;
sourceBlockId?: import("../..").TBlockId;
targetBlockId?: import("../..").TBlockId;
sourceAnchorId?: string;
targetAnchorId?: string;
sourcePortId?: TPortId;
targetPortId?: TPortId;
label?: string;
styles?: Partial<import("../../graphConfig").TConnectionColors> & {
dashes? /**
* @deprecated Use connectionSelectionBucket.$selectedEntities instead
* Computed signal that returns selected connections as ConnectionState instances
*/: number[];
};
dashed?: boolean;
selected?: boolean;
}>>>;
/**
* Bucket for managing connection selection state
* Resolves IDs to ConnectionState instances
*/
readonly connectionSelectionBucket: MultipleSelectionBucket<string | number, ConnectionState>;
/**
* @deprecated Use connectionSelectionBucket.$selectedEntities instead
* Computed signal that returns selected connections as ConnectionState instances
*/
$selectedConnections: import("@preact/signals-core").ReadonlySignal<ConnectionState<{
id?: TConnectionId;
sourceBlockId?: import("../..").TBlockId;
targetBlockId?: import("../..").TBlockId;
sourceAnchorId?: string;
targetAnchorId?: string;
sourcePortId?: TPortId;
targetPortId?: TPortId;
label?: string;
styles?: Partial<import("../../graphConfig").TConnectionColors> & {
dashes? /**
* @deprecated Use connectionSelectionBucket.$selectedEntities instead
* Computed signal that returns selected connections as ConnectionState instances
*/: number[];
};
dashed?: boolean;
selected?: boolean;
}>[]>;
/**
* Computed signal that returns selected connections as BaseConnection GraphComponent instances
* Automatically resolves ConnectionState to BaseConnection components via getViewComponent()
* Use this when you need to work with rendered Connection components
*/
$selectedConnectionComponents: import("@preact/signals-core").ReadonlySignal<BaseConnection<import("../../components/canvas/connections").TBaseConnectionProps, import("../../components/canvas/connections").TBaseConnectionState, import("../../components/canvas/GraphComponent").GraphComponentContext, {
id?: TConnectionId;
sourceBlockId?: import("../..").TBlockId;
targetBlockId?: import("../..").TBlockId;
sourceAnchorId?: string;
targetAnchorId?: string;
sourcePortId?: TPortId;
targetPortId?: TPortId;
label?: string;
styles?: Partial<import("../../graphConfig").TConnectionColors> & {
dashes? /**
* @deprecated Use connectionSelectionBucket.$selectedEntities instead
* Computed signal that returns selected connections as ConnectionState instances
*/: number[];
};
dashed?: boolean;
selected?: boolean;
}>[]>;
protected ports: PortsStore;
constructor(rootStore: RootStore, graph: Graph);
/**
* Claim ownership of a port (for Blocks, Anchors)
* @param id Port identifier
* @param owner Component that will own this port
* @returns The port state
*/
claimPort(id: TPortId, owner: Component): PortState;
/**
* Release ownership of a port (when Block/Anchor is destroyed)
* @param id Port identifier
* @param owner Component that currently owns this port
*/
releasePort(id: TPortId, owner: Component): void;
/**
* Start observing a port (for Connections)
* @param id Port identifier
* @param observer The object that will observe this port
* @returns The port state
*/
observePort(id: TPortId, observer: unknown): PortState;
/**
* Stop observing a port (when Connection is destroyed)
* @param id Port identifier
* @param observer The object that was observing this port
*/
unobservePort(id: TPortId, observer: unknown): void;
/**
* Get a port by its ID
* @param id Port identifier
* @returns The port state if it exists
*/
getPort(id: TPortId): PortState | undefined;
/**
* Check if a port exists
* @param id Port identifier
* @returns true if port exists
*/
hasPort(id: TPortId): boolean;
/**
* Check if a port can be deleted and delete it if possible
* @param id Port identifier
*/
private checkAndDeletePort;
deletePorts(ports: TPortId[]): void;
protected setSelection(connection: ConnectionState | TConnectionId, selected: boolean, params?: {
ignoreChange: boolean;
}): boolean;
updateConnections(connections: TConnection[]): void;
setConnections(connections: TConnection[]): void;
protected getOrCreateConnection(connections: TConnection): ConnectionState<{
id?: TConnectionId;
sourceBlockId?: import("../..").TBlockId;
targetBlockId?: import("../..").TBlockId;
sourceAnchorId?: string;
targetAnchorId?: string;
sourcePortId?: TPortId;
targetPortId?: TPortId;
label?: string;
styles?: Partial<import("../../graphConfig").TConnectionColors> & {
dashes? /**
* @deprecated Use connectionSelectionBucket.$selectedEntities instead
* Computed signal that returns selected connections as ConnectionState instances
*/: number[];
};
dashed?: boolean;
selected?: boolean;
}>;
addConnection(connection: TConnection): TConnectionId;
protected notifyConnectionMapChanged(): void;
deleteConnections(connections: ConnectionState[]): void;
deleteSelectedConnections(): void;
/**
* Updates connection selection using the SelectionService
* @param ids Connection IDs to update selection for
* @param selected Whether to select or deselect
* @param strategy The selection strategy to apply
*/
setConnectionsSelection(ids: TConnectionId[], selected: boolean, strategy?: ESelectionStrategy): void;
/**
* Resets the selection for connections
*
* @returns {void}
*/
resetSelection(): void;
getConnections(ids?: TConnectionId[]): ConnectionState<{
id?: TConnectionId;
sourceBlockId?: import("../..").TBlockId;
targetBlockId?: import("../..").TBlockId;
sourceAnchorId?: string;
targetAnchorId?: string;
sourcePortId?: TPortId;
targetPortId?: TPortId;
label?: string;
styles?: Partial<import("../../graphConfig").TConnectionColors> & {
dashes? /**
* @deprecated Use connectionSelectionBucket.$selectedEntities instead
* Computed signal that returns selected connections as ConnectionState instances
*/: number[];
};
dashed?: boolean;
selected?: boolean;
}>[];
getConnectionState(id: TConnectionId): ConnectionState<{
id?: TConnectionId;
sourceBlockId?: import("../..").TBlockId;
targetBlockId?: import("../..").TBlockId;
sourceAnchorId?: string;
targetAnchorId?: string;
sourcePortId?: TPortId;
targetPortId?: TPortId;
label?: string;
styles?: Partial<import("../../graphConfig").TConnectionColors> & {
dashes? /**
* @deprecated Use connectionSelectionBucket.$selectedEntities instead
* Computed signal that returns selected connections as ConnectionState instances
*/: number[];
};
dashed?: boolean;
selected?: boolean;
}>;
getConnection(id: TConnectionId): TConnection | undefined;
getConnectionStates(ids: TConnectionId[]): ConnectionState<{
id?: TConnectionId;
sourceBlockId?: import("../..").TBlockId;
targetBlockId?: import("../..").TBlockId;
sourceAnchorId?: string;
targetAnchorId?: string;
sourcePortId?: TPortId;
targetPortId?: TPortId;
label?: string;
styles?: Partial<import("../../graphConfig").TConnectionColors> & {
dashes? /**
* @deprecated Use connectionSelectionBucket.$selectedEntities instead
* Computed signal that returns selected connections as ConnectionState instances
*/: number[];
};
dashed?: boolean;
selected?: boolean;
}>[];
toJSON(): {
id?: TConnectionId;
sourceBlockId?: import("../..").TBlockId;
targetBlockId?: import("../..").TBlockId;
sourceAnchorId?: string;
targetAnchorId?: string;
sourcePortId?: TPortId;
targetPortId?: TPortId;
label?: string;
styles?: Partial<import("../../graphConfig").TConnectionColors> & {
dashes? /**
* @deprecated Use connectionSelectionBucket.$selectedEntities instead
* Computed signal that returns selected connections as ConnectionState instances
*/: number[];
};
dashed?: boolean;
selected?: boolean;
}[];
reset(): void;
}