@gravity-ui/graph
Version:
Modern graph editor component
42 lines (41 loc) • 1.11 kB
JavaScript
import { signal } from "@preact/signals-core";
import { Group } from "../../components/canvas/groups";
import { ESelectionStrategy } from "../../utils/types/types";
export class GroupState {
constructor(store, state) {
this.store = store;
this.$state = signal({
id: "",
selected: false,
rect: {
x: 0,
y: 0,
width: 0,
height: 0,
},
component: Group,
});
this.$state.value = state;
}
get id() {
return this.$state.value.id;
}
get selected() {
return Boolean(this.$state.value.selected);
}
updateGroup(group) {
this.$state.value = {
...this.$state.value,
...group,
};
}
setSelection(selected, strategy = ESelectionStrategy.REPLACE) {
this.store.updateGroupsSelection([this.id], selected, strategy);
}
asTGroup() {
return this.$state.value;
}
static fromTGroup(store, group) {
return new GroupState(store, group);
}
}