2023-08-22 21:57:53 -04:00
|
|
|
<script lang="ts">
|
|
|
|
|
import { Handle, Position } from "@xyflow/svelte";
|
2023-08-30 13:43:52 -04:00
|
|
|
import { removeNode, nodes, INPUTNAMES, OUTPUTNAMES, selectedFilter } from "./stores.js";
|
2023-08-22 21:57:53 -04:00
|
|
|
|
2023-08-29 11:36:57 -04:00
|
|
|
export let data = { ext: "", nodeType: "", name: "", inputs: [], outputs: [] };
|
2023-08-24 23:17:49 -04:00
|
|
|
export let id;
|
|
|
|
|
|
2023-08-30 13:43:52 -04:00
|
|
|
$: isSelected = $selectedFilter && $nodes[$selectedFilter] && $nodes[$selectedFilter].id === id;
|
|
|
|
|
|
2023-08-24 23:17:49 -04:00
|
|
|
function remove() {
|
|
|
|
|
removeNode(id);
|
|
|
|
|
}
|
2023-08-29 11:36:57 -04:00
|
|
|
|
|
|
|
|
function changeFile() {
|
|
|
|
|
const newFile = OUTPUTNAMES.find((n) => n.name === data.name);
|
|
|
|
|
data.inputs = [...newFile.inputs];
|
|
|
|
|
data.outputs = [...newFile.outputs];
|
|
|
|
|
data.ext = newFile.ext;
|
|
|
|
|
data = data;
|
|
|
|
|
|
|
|
|
|
// hack to deselect node and apply changes on chrome
|
|
|
|
|
$nodes.find(n => n.id === id).selected = false;
|
|
|
|
|
$nodes = $nodes
|
|
|
|
|
}
|
2023-08-22 21:57:53 -04:00
|
|
|
</script>
|
|
|
|
|
|
2023-08-30 13:43:52 -04:00
|
|
|
<div class="node {data.nodeType} {isSelected ? 'selected' : ''}">
|
2023-08-24 23:17:49 -04:00
|
|
|
<div class="head">
|
|
|
|
|
<div class="node-type">{data.nodeType}</div>
|
2023-08-25 14:03:32 -04:00
|
|
|
{#if data.nodeType != "output"}
|
|
|
|
|
<button on:click={remove}>X</button>
|
|
|
|
|
{/if}
|
2023-08-24 23:17:49 -04:00
|
|
|
</div>
|
|
|
|
|
<div class="body">
|
|
|
|
|
{#if data.nodeType == "input"}
|
|
|
|
|
<select bind:value={data.name}>
|
2023-08-29 11:36:57 -04:00
|
|
|
{#each INPUTNAMES as inp}
|
|
|
|
|
<option value={inp.name}>{inp.name}</option>
|
|
|
|
|
{/each}
|
|
|
|
|
</select>
|
|
|
|
|
{:else if data.nodeType == "output"}
|
|
|
|
|
<select bind:value={data.name} on:change={changeFile}>
|
|
|
|
|
{#each OUTPUTNAMES as out}
|
|
|
|
|
<option value={out.name}>{out.name}</option>
|
|
|
|
|
{/each}
|
2023-08-24 23:17:49 -04:00
|
|
|
</select>
|
|
|
|
|
{:else}
|
|
|
|
|
{data.name}
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
2023-08-22 21:57:53 -04:00
|
|
|
</div>
|
|
|
|
|
{#each data.inputs as inp, index}
|
2023-08-24 23:17:49 -04:00
|
|
|
<Handle
|
|
|
|
|
type="target"
|
|
|
|
|
position={Position.Left}
|
|
|
|
|
id={inp + "_" + index}
|
|
|
|
|
class="handle {inp}"
|
2023-08-29 13:44:47 -04:00
|
|
|
style="top: {index * 12 + 4}px; left: -13px;">{inp}</Handle
|
2023-08-24 23:17:49 -04:00
|
|
|
>
|
2023-08-22 21:57:53 -04:00
|
|
|
{/each}
|
|
|
|
|
{#each data.outputs as out, index}
|
2023-08-24 23:17:49 -04:00
|
|
|
<Handle
|
|
|
|
|
type="source"
|
|
|
|
|
id={out + "_" + index}
|
|
|
|
|
position={Position.Right}
|
|
|
|
|
class="handle {out}"
|
2023-08-29 13:44:47 -04:00
|
|
|
style="top: {index * 12 + 4}px; right: -13px; left: auto;">{out}</Handle
|
2023-08-24 23:17:49 -04:00
|
|
|
>
|
2023-08-22 21:57:53 -04:00
|
|
|
{/each}
|
2023-08-24 23:17:49 -04:00
|
|
|
|
2023-08-23 18:10:28 -04:00
|
|
|
<style>
|
2023-08-24 23:17:49 -04:00
|
|
|
:global(:root) {
|
2023-08-29 13:44:47 -04:00
|
|
|
--edge-stroke-default: var(--b1) !important;
|
|
|
|
|
--edge-stroke: var(--b1) !important;
|
2023-08-24 23:17:49 -04:00
|
|
|
--edge-color: var(--b1) !important;
|
|
|
|
|
--edge-color-selected: black;
|
|
|
|
|
}
|
|
|
|
|
:global(.svelte-flow__node) {
|
|
|
|
|
box-shadow: 2px 2px 0px var(--b2);
|
2023-08-29 13:44:47 -04:00
|
|
|
background-color: #fff;
|
2023-08-24 23:17:49 -04:00
|
|
|
}
|
|
|
|
|
:global(.svelte-flow__node.selected) {
|
|
|
|
|
outline: 1px solid var(--b1) !important;
|
|
|
|
|
}
|
|
|
|
|
:global(.handle) {
|
|
|
|
|
width: 10px !important;
|
|
|
|
|
height: 10px !important;
|
|
|
|
|
border: 1px solid var(--b1) !important;
|
|
|
|
|
border-radius: 0px !important;
|
|
|
|
|
background-color: white !important;
|
|
|
|
|
font-size: 10px;
|
|
|
|
|
line-height: 6px;
|
2023-08-29 13:44:47 -04:00
|
|
|
text-align: center;
|
2023-08-24 23:17:49 -04:00
|
|
|
}
|
|
|
|
|
:global(.handle.a) {
|
|
|
|
|
/* border: 1px solid var(--b2) !important; */
|
|
|
|
|
}
|
|
|
|
|
.node {
|
|
|
|
|
padding: 5px;
|
|
|
|
|
}
|
2023-08-30 13:43:52 -04:00
|
|
|
.selected {
|
|
|
|
|
outline: 2px solid var(--b1);
|
|
|
|
|
background-color: var(--b2);
|
|
|
|
|
}
|
2023-08-24 23:17:49 -04:00
|
|
|
.head {
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
align-items: center;
|
|
|
|
|
margin-bottom: 5px;
|
|
|
|
|
}
|
|
|
|
|
.head button {
|
|
|
|
|
font-size: 10px;
|
|
|
|
|
line-height: 8px;
|
|
|
|
|
padding: 2px 2px;
|
|
|
|
|
margin-left: 10px;
|
|
|
|
|
}
|
|
|
|
|
.node-type {
|
|
|
|
|
font-size: 0.8em;
|
|
|
|
|
color: #999;
|
|
|
|
|
}
|
|
|
|
|
.node.input {
|
|
|
|
|
}
|
|
|
|
|
.node.filter {
|
|
|
|
|
}
|
|
|
|
|
.node.output {
|
|
|
|
|
}
|
2023-08-23 18:10:28 -04:00
|
|
|
</style>
|