A Svelte 5 flow/node editor library with typed port connections.
raw, processed) with connection validationpnpm add kaykay
Package registry: kaykay on npm
Check out the help page for a complete working example!
MyNode.svelte
<script lang="ts">
import { Handle, type NodeProps } from 'kaykay';
let { data }: NodeProps<{ label: string }> = $props();
</script>
<div class="my-node">
<span>{data.label}</span>
<Handle id="in" type="input" port="data" position="left" />
<Handle id="out" type="output" port="data" position="right" />
</div>
+page.svelte
<script lang="ts">
import { Canvas, type FlowNode } from 'kaykay';
import MyNode from './MyNode.svelte';
const nodeTypes = { custom: MyNode };
const nodes: FlowNode[] = [
{ id: '1', type: 'custom', position: { x: 0, y: 0 }, data: { label: 'Hello' } },
];
</script>
<Canvas {nodes} {nodeTypes} />
Bind the Canvas instance and convert browser drop coordinates into canvas coordinates:
<script lang="ts">
import { Canvas, type FlowNode } from 'kaykay';
let canvasRef: ReturnType<typeof Canvas> | undefined;
function handleDrop(event: DragEvent) {
event.preventDefault();
const position = canvasRef?.clientToCanvas(event.clientX, event.clientY);
if (!position) return;
const node: FlowNode = {
id: crypto.randomUUID(),
type: 'custom',
position,
data: { label: 'Dropped node' }
};
canvasRef?.getFlow().addNode(node);
}
</script>
<div ondragover={(event) => event.preventDefault()} ondrop={handleDrop}>
<Canvas bind:this={canvasRef} {nodes} {edges} {nodeTypes} />
</div>
pnpm install
pnpm dev
Then open http://localhost:5173 to see:
/ with installation and feature overview/playground with custom nodes and full demoHandles have a port prop that defines what types of connections they accept:
<!-- Only connects to handles with port="raw" -->
<Handle id="in" type="input" port="raw" />
<!-- Accepts multiple port types -->
<Handle id="in" type="input" port="data" accept={["raw", "processed"]} />
MIT