@gravity-ui/graph
Version:
Modern graph editor component
172 lines (171 loc) • 9.43 kB
TypeScript
import { TGraphSettingsConfig } from "../../../store";
import { EAnchorType } from "../../../store/anchor/Anchor";
import { BlockState, TBlockId } from "../../../store/block/Block";
import { TMeasureTextOptions } from "../../../utils/functions/text";
import { TTExtRect } from "../../../utils/renderers/text";
import { TPoint, TRect } from "../../../utils/types/shapes";
import { GraphComponent } from "../GraphComponent";
import { TAnchor } from "../anchors";
import { GraphLayer, TGraphLayerContext } from "../layers/graphLayer/GraphLayer";
import { BlockController } from "./controllers/BlockController";
export type TBlockSettings = {
/** Phantom blocks are blocks whose dimensions and position
* are not taken into account when calculating the usable rect. */
phantom?: boolean;
};
export declare function isTBlock(block: unknown): block is TBlock;
export type TBlock<T extends Record<string, unknown> = {}> = {
id: TBlockId;
is: string;
x: number;
y: number;
group?: string;
width: number;
height: number;
selected: boolean;
name: string;
anchors: TAnchor[];
settings?: TBlockSettings;
meta?: T;
};
export type TBlockProps = {
id: TBlockId;
font: string;
};
declare module "../../../graphEvents" {
interface GraphEventsDefinitions {
"block-drag-start": (event: CustomEvent<{
nativeEvent: MouseEvent;
block: TBlock;
}>) => void;
"block-drag": (event: CustomEvent<{
nativeEvent: MouseEvent;
block: TBlock;
x: number;
y: number;
}>) => void;
"block-drag-end": (event: CustomEvent<{
nativeEvent: MouseEvent;
block: TBlock;
}>) => void;
}
}
export type BlockViewState = {
zIndex: number;
order: number;
};
export declare class Block<T extends TBlock = TBlock, Props extends TBlockProps = TBlockProps> extends GraphComponent<Props, T, TGraphLayerContext> {
static IS: "Block";
readonly isBlock = true;
context: TGraphLayerContext;
state: T;
props: Props;
connectedState: BlockState<T>;
protected lastDragEvent?: MouseEvent;
protected startDragCoords: number[];
protected shouldRenderText: boolean;
protected shouldRenderHtml: boolean;
protected raised: boolean;
protected hidden: boolean;
protected currentState(): T;
protected blockController: BlockController;
$viewState: import("@preact/signals-core").Signal<BlockViewState>;
constructor(props: Props, parent: GraphLayer);
isRendered(): boolean;
protected updateViewState(params: Partial<BlockViewState>): void;
getGeometry(): TRect;
getConfigFlag<K extends keyof TGraphSettingsConfig>(flagPath: K): number | boolean | typeof import("../../..").Component | import("../../..").ECanChangeBlockGeometry | "vertical" | "horizontal" | Record<string, {
new (props: TBlockProps, parent: GraphLayer): Block<TBlock, TBlockProps>;
IS: "Block";
create<Props_1 extends import("../../../lib/CoreComponent").CoreComponentProps, Context extends import("../../../lib/CoreComponent").CoreComponentContext>(this: Constructor<import("../../../lib").CoreComponent<Props_1, Context>>, props?: Props_1, options?: {
readonly key?: string;
readonly ref?: ((inst: any) => void) | string;
}): import("../../../lib/CoreComponent").ComponentDescriptor<Props_1, Context>;
mount<Props_1 extends import("../../../lib/CoreComponent").CoreComponentProps, Context extends import("../../../lib/CoreComponent").CoreComponentContext>(Component: Constructor<import("../../../lib").CoreComponent<Props_1, Context>>, props?: Props_1): import("../../../lib").CoreComponent<Props_1, Context>;
unmount(instance: any): void;
}> | {
new (props: import("../connections").TConnectionProps, parent: import("../connections/BlockConnections").BlockConnections): import("../connections").BlockConnection<import("../../..").TConnection>;
create<Props_1 extends import("../../../lib/CoreComponent").CoreComponentProps, Context extends import("../../../lib/CoreComponent").CoreComponentContext>(this: Constructor<import("../../../lib").CoreComponent<Props_1, Context>>, props?: Props_1, options?: {
readonly key?: string;
readonly ref?: ((inst: any) => void) | string;
}): import("../../../lib/CoreComponent").ComponentDescriptor<Props_1, Context>;
mount<Props_1 extends import("../../../lib/CoreComponent").CoreComponentProps, Context extends import("../../../lib/CoreComponent").CoreComponentContext>(Component: Constructor<import("../../../lib").CoreComponent<Props_1, Context>>, props?: Props_1): import("../../../lib").CoreComponent<Props_1, Context>;
unmount(instance: any): void;
};
protected subscribe(id: TBlockId): void[];
protected getNextState(): T;
protected didIterate(): void;
protected calcZIndex(): number;
protected raiseBlock(): void;
protected stateChanged(nextState: T): void;
getRenderIndex(): number;
updatePosition(x: number, y: number, silent?: boolean): void;
handleEvent(event: CustomEvent): void;
protected onDragStart(event: MouseEvent): void;
protected onDragUpdate(event: MouseEvent): void;
protected calcNextDragPosition(x: number, y: number): number[];
protected applyNextPosition(x: number, y: number): void;
protected onDragEnd(event: MouseEvent): void;
updateHitBox: (geometry: TRect, force?: boolean) => void;
getConnectionAnchorPosition(anchor: TAnchor): {
x: number;
y: number;
};
getAnchorPosition(anchor: TAnchor): TPoint;
getConnectionPoint(direction: "in" | "out"): TPoint;
protected renderAnchor(anchor: TAnchor, getPosition: (anchor: TAnchor) => TPoint): import("../../../lib/CoreComponent").ComponentDescriptor<{
zIndex: number;
size: number;
lineWidth: number;
getPosition: (anchor: TAnchor) => TPoint;
id: string;
blockId: TBlockId;
type: EAnchorType | string;
index?: number;
}, import("../GraphComponent").GraphComponentContext>;
protected isAnchorsAllowed(): number | boolean | "" | typeof import("../../..").Component | import("../../..").ECanChangeBlockGeometry | "vertical" | "horizontal" | Record<string, {
new (props: TBlockProps, parent: GraphLayer): Block<TBlock, TBlockProps>;
IS: "Block";
create<Props_1 extends import("../../../lib/CoreComponent").CoreComponentProps, Context extends import("../../../lib/CoreComponent").CoreComponentContext>(this: Constructor<import("../../../lib").CoreComponent<Props_1, Context>>, props?: Props_1, options?: {
readonly key?: string;
readonly ref?: ((inst: any) => void) | string;
}): import("../../../lib/CoreComponent").ComponentDescriptor<Props_1, Context>;
mount<Props_1 extends import("../../../lib/CoreComponent").CoreComponentProps, Context extends import("../../../lib/CoreComponent").CoreComponentContext>(Component: Constructor<import("../../../lib").CoreComponent<Props_1, Context>>, props?: Props_1): import("../../../lib").CoreComponent<Props_1, Context>;
unmount(instance: any): void;
}> | {
new (props: import("../connections").TConnectionProps, parent: import("../connections/BlockConnections").BlockConnections): import("../connections").BlockConnection<import("../../..").TConnection>;
create<Props_1 extends import("../../../lib/CoreComponent").CoreComponentProps, Context extends import("../../../lib/CoreComponent").CoreComponentContext>(this: Constructor<import("../../../lib").CoreComponent<Props_1, Context>>, props?: Props_1, options?: {
readonly key?: string;
readonly ref?: ((inst: any) => void) | string;
}): import("../../../lib/CoreComponent").ComponentDescriptor<Props_1, Context>;
mount<Props_1 extends import("../../../lib/CoreComponent").CoreComponentProps, Context extends import("../../../lib/CoreComponent").CoreComponentContext>(Component: Constructor<import("../../../lib").CoreComponent<Props_1, Context>>, props?: Props_1): import("../../../lib").CoreComponent<Props_1, Context>;
unmount(instance: any): void;
};
protected binderGetAnchorPosition: (anchor: TAnchor) => {
x: number;
y: number;
};
protected updateChildren(): import("../../../lib/CoreComponent").ComponentDescriptor<{
zIndex: number;
size: number;
lineWidth: number;
getPosition: (anchor: TAnchor) => TPoint;
id: string;
blockId: TBlockId;
type: EAnchorType | string;
index?: number;
}, import("../GraphComponent").GraphComponentContext>[];
protected willRender(): void;
protected renderStroke(color: string): void;
protected getContentRect(): TRect;
protected renderText(text: string, ctx?: CanvasRenderingContext2D, { rect, renderParams }?: {
rect: TTExtRect;
renderParams: TMeasureTextOptions;
}): void;
renderMinimalisticBlock(ctx: CanvasRenderingContext2D): void;
protected renderBody(ctx: CanvasRenderingContext2D): void;
renderSchematicView(ctx: CanvasRenderingContext2D): void;
setHiddenBlock(hidden: boolean): void;
renderDetailedView(ctx: CanvasRenderingContext2D): void;
protected render(): void;
}