nodes/frontend/src/lib/components/node/NodeInput.svelte

33 lines
925 B
Svelte
Raw Normal View History

2024-03-14 16:55:11 +01:00
<script lang="ts">
import Checkbox from "$lib/elements/Checkbox.svelte";
import Float from "$lib/elements/Float.svelte";
import Integer from "$lib/elements/Integer.svelte";
import Select from "$lib/elements/Select.svelte";
import type { Node, NodeInput } from "$lib/types";
import { getGraphManager } from "../graph/context";
2024-03-14 16:55:11 +01:00
export let node: Node;
export let input: NodeInput;
export let id: string;
const graph = getGraphManager();
2024-03-14 16:55:11 +01:00
let value = node?.props?.[id] ?? input.value;
$: if (node?.props?.[id] !== value) {
node.props = { ...node.props, [id]: value };
graph.execute();
2024-03-14 16:55:11 +01:00
}
</script>
<label for="asd">{id}</label>
2024-03-14 16:55:11 +01:00
{#if input.type === "float"}
<Float bind:value />
{:else if input.type === "integer"}
<Integer bind:value />
{:else if input.type === "boolean"}
<Checkbox bind:value />
{:else if input.type === "select"}
<Select options={input.options} bind:value />
{/if}