UNPKG

@gravity-ui/graph

Version:

Modern graph editor component

68 lines (67 loc) 2.19 kB
import { GraphMouseEvent } from "../../../../graphEvents"; import { Layer, LayerContext, LayerProps } from "../../../../services/Layer"; import { TPoint } from "../../../../utils/types/shapes"; import { Block } from "../../../canvas/blocks/Block"; /** * Events emitted by the NewBlockLayer */ declare module "../../../../graphEvents" { interface GraphEventsDefinitions { /** * Fired when block duplication starts */ "block-add-start-from-shadow": (event: CustomEvent<{ blocks: Block[]; }>) => void; /** * Fired when block duplication completes */ "block-added-from-shadow": (event: CustomEvent<{ items: Array<{ block: Block; coord: TPoint; }>; delta: TPoint; }>) => void; } } export interface NewBlockLayerProps extends LayerProps { /** * Background color for displaying the block shadow * By default, the block border color from the theme is used */ ghostBackground?: string; /** * Function to check if block duplication is allowed * @param block The block being duplicated * @returns true if duplication is allowed, false if not allowed */ isDuplicateAllowed?: (block: Block) => boolean; } export declare class NewBlockLayer extends Layer<NewBlockLayerProps, LayerContext & { canvas: HTMLCanvasElement; ctx: CanvasRenderingContext2D; }> { private copyBlocks; private initialPoint; private blockStates; private enabled; private eventAborter; constructor(props: NewBlockLayerProps); /** * Called after initialization and when the layer is reattached. * This is where we set up event subscriptions to ensure they work properly * after the layer is unmounted and reattached. */ protected afterInit(): void; protected handleMouseDown: (nativeEvent: GraphMouseEvent) => void; protected render(): void; private onStartNewBlock; private lastMouseX; private lastMouseY; private onMoveNewBlock; private onEndNewBlock; enable(): void; disable(): void; isEnabled(): boolean; }