@gravity-ui/graph
Version:
Modern graph editor component
45 lines (44 loc) • 1.25 kB
JavaScript
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.$viewComponentReady = signal(false);
this.$state.value = anchor;
}
update(anchor) {
this.$state.value = anchor;
}
setSelection(selected) {
this.block.onAnchorSelected(this.id, selected);
}
setViewComponent(anchorComponent) {
this.anchorView = anchorComponent;
this.$viewComponentReady.value = true;
}
unsetViewComponent() {
this.anchorView = undefined;
this.$viewComponentReady.value = false;
}
getViewComponent() {
return this.anchorView;
}
asTAnchor() {
return this.$state.value;
}
}