@gravity-ui/graph
Version:
Modern graph editor component
48 lines (47 loc) • 2.24 kB
TypeScript
import type { Signal } from "@preact/signals-core";
import { TAnchor } from "../../components/canvas/anchors";
import { Block, TBlock } from "../../components/canvas/blocks/Block";
import { ESelectionStrategy } from "../../utils/types/types";
import { AnchorState } from "../anchor/Anchor";
import { BlockListStore } from "./BlocksList";
export type TBlockId = string | number | symbol;
export declare const IS_BLOCK_TYPE: "Block";
export declare class BlockState<T extends TBlock = TBlock> {
readonly store: BlockListStore;
static fromTBlock(store: BlockListStore, block: TBlock): BlockState<TBlock>;
$state: Signal<T>;
get id(): TBlockId;
get x(): number;
get y(): number;
get width(): number;
get height(): number;
get selected(): boolean;
readonly $anchorStates: Signal<AnchorState[]>;
readonly $geometry: import("@preact/signals-core").ReadonlySignal<{
x: number;
y: number;
width: number;
height: number;
}>;
$anchorIndexs: import("@preact/signals-core").ReadonlySignal<Map<string, number>>;
$anchors: import("@preact/signals-core").ReadonlySignal<TAnchor[]>;
$selectedAnchors: import("@preact/signals-core").ReadonlySignal<AnchorState[]>;
private blockView;
constructor(store: BlockListStore, block: T);
onAnchorSelected(anchorId: AnchorState["id"], selected: boolean): void;
getSelectedAnchor(): AnchorState;
getAnchorState(id: AnchorState["id"]): AnchorState;
updateXY(x: number, y: number, forceUpdate?: boolean): void;
setViewComponent(blockComponent: Block): void;
getViewComponent(): Block<TBlock<{}>, import("../../components/canvas/blocks/Block").TBlockProps>;
getConnections(): import("../..").ConnectionState<import("../..").TConnection>[];
setSelection(selected: boolean, strategy?: ESelectionStrategy): void;
clearAnchorsSelection(): void;
setName(newName: string): void;
updateAnchors(anchors: TAnchor[]): void;
updateBlock(block: Partial<TBlock>): void;
getAnchorById(anchorId: string): AnchorState;
asTBlock(): TBlock;
}
export declare function mapToTBlock(blockState: BlockState): TBlock;
export declare function mapToBlockId(blockState: BlockState): TBlockId;