Files
nodarium/app/src/lib/graph-interface/node/NodeInput.svelte
Max Richter 1ea544e765
All checks were successful
Deploy to GitHub Pages / build_site (push) Successful in 3m33s
chore: rename @nodes -> @nodarium for everything
2025-12-01 17:03:14 +01:00

47 lines
1.2 KiB
Svelte

<script lang="ts">
import type { Node, NodeInput } from "@nodarium/types";
import { Input } from "@nodarium/ui";
import type { GraphManager } from "../graph-manager.svelte";
type Props = {
node: Node;
input: NodeInput;
id: string;
elementId?: string;
graph?: GraphManager;
};
const {
node = $bindable(),
input,
id,
elementId = `input-${Math.random().toString(36).substring(7)}`,
graph,
}: Props = $props();
function getDefaultValue() {
if (node?.props?.[id] !== undefined) return node?.props?.[id] as number;
if ("value" in input && input?.value !== undefined)
return input?.value as number;
if (input.type === "boolean") return 0;
if (input.type === "float") return 0.5;
if (input.type === "integer") return 0;
if (input.type === "select") return 0;
return 0;
}
let value = $state(getDefaultValue());
$effect(() => {
if (value !== undefined && node?.props?.[id] !== value) {
node.props = { ...node.props, [id]: value };
if (graph) {
graph.save();
graph.execute();
}
}
});
</script>
<Input id="input-{elementId}" {input} bind:value />