UNPKG

@gravity-ui/graph

Version:

Modern graph editor component

39 lines (38 loc) 1.03 kB
import { computed, signal } from "@preact/signals-core"; export var EAnchorType; (function (EAnchorType) { EAnchorType["IN"] = "IN"; EAnchorType["OUT"] = "OUT"; })(EAnchorType || (EAnchorType = {})); export class AnchorState { get id() { return this.$state.value.id; } get blockId() { return this.$state.value.blockId; } get state() { return this.$state.value; } constructor(block, anchor) { this.block = block; this.$state = signal(undefined); this.$selected = computed(() => this.block.store.anchorSelectionBucket.isSelected(this.id)); this.$state.value = anchor; } update(anchor) { this.$state.value = anchor; } setSelection(selected) { this.block.onAnchorSelected(this.id, selected); } setViewComponent(anchorComponent) { this.anchorView = anchorComponent; } getViewComponent() { return this.anchorView; } asTAnchor() { return this.$state.value; } }