Refactor & handle node lifecycle

This commit is contained in:
space-nuko
2023-04-29 16:13:35 -07:00
parent 95133df3d9
commit 59cbff1648
6 changed files with 405 additions and 243 deletions

View File

@@ -3,6 +3,8 @@ import ComboWidget from "$lib/widgets/ComboWidget.svelte";
import RangeWidget from "$lib/widgets/RangeWidget.svelte";
import TextWidget from "$lib/widgets/TextWidget.svelte";
import { type WidgetUIState } from "$lib/stores/nodeState";
import { get } from "svelte/store"
import layoutState from "$lib/stores/layoutState"
export function download(filename: string, text: string, type: string = "text/plain") {
const blob = new Blob([text], { type: type });
@@ -39,3 +41,32 @@ export function getComponentForWidgetState(item: WidgetUIState): any {
return null;
}
export function startDrag(evt: MouseEvent) {
const dragItemId: string = evt.target.dataset["dragItemId"];
const ls = get(layoutState)
if (evt.button !== 0) {
if (ls.currentSelection.length <= 1 && !ls.isMenuOpen)
ls.currentSelection = [dragItemId]
return;
}
const item = ls.allItems[dragItemId].dragItem
if (evt.ctrlKey) {
const index = ls.currentSelection.indexOf(item.id)
if (index === -1)
ls.currentSelection.push(item.id);
else
ls.currentSelection.splice(index, 1);
ls.currentSelection = ls.currentSelection;
}
else {
ls.currentSelection = [item.id]
}
layoutState.set(ls)
};
export function stopDrag(evt: MouseEvent) {
};