--- name: svelteflow-fundamentals user-invocable: false description: Use when building node-based UIs, flow diagrams, workflow editors, or interactive graphs with Svelte Flow. Covers setup, nodes, edges, controls, and interactivity. allowed-tools: - Bash - Read --- # Svelte Flow Fundamentals Build customizable node-based editors and interactive diagrams with Svelte Flow. This skill covers core concepts, setup, and common patterns for creating flow-based interfaces in Svelte applications. ## Installation ```bash # npm npm install @xyflow/svelte # pnpm pnpm add @xyflow/svelte # yarn yarn add @xyflow/svelte ``` ## Basic Setup ```svelte
``` ## Using Stores for State ```svelte

Nodes: {$nodeCount} | Edges: {$edgeCount}

``` ## Node Types ### Built-in Node Types ```svelte ``` ### Node Configuration ```typescript import { Position, type Node } from '@xyflow/svelte'; const node: Node = { id: 'unique-id', type: 'default', position: { x: 100, y: 100 }, data: { label: 'My Node', customProp: 'value' }, // Optional properties style: 'background-color: #f0f0f0;', class: 'custom-node', sourcePosition: Position.Right, targetPosition: Position.Left, draggable: true, selectable: true, connectable: true, deletable: true, hidden: false, selected: false, dragging: false, zIndex: 0, extent: 'parent', parentId: 'parent-node-id', expandParent: true, }; ``` ## Edge Types and Configuration ```svelte ``` ## Event Handling ```svelte ``` ## Plugin Components ### Background ```svelte ``` ### Controls ```svelte ``` ### MiniMap ```svelte { switch (node.type) { case 'input': return '#0041d0'; case 'output': return '#ff0072'; default: return '#1a192b'; } }} nodeStrokeWidth={3} zoomable pannable /> ``` ### Panel ```svelte

Node count: {$nodes.length}

``` ## Viewport Control with useSvelteFlow ```svelte ``` ## Node Operations ```svelte ``` ## Saving and Restoring State ```svelte ``` ## Connection Validation ```svelte ``` ## When to Use This Skill Use svelteflow-fundamentals when you need to: - Build workflow builders with Svelte - Create data pipeline visualizations - Design state machine diagrams - Build chatbot conversation flows - Create organizational charts - Build ML pipeline visualizers - Create interactive decision trees in Svelte apps ## Best Practices - Use Svelte stores for reactive flow state - Keep node components focused and reusable - Use TypeScript for type safety - Memoize expensive computations in derived stores - Use CSS variables for theming - Add keyboard shortcuts for power users - Implement undo/redo for better UX - Use fitView() on initial render ## Resources - [Svelte Flow Documentation](https://svelteflow.dev/learn) - [Svelte Flow Examples](https://svelteflow.dev/examples) - [Svelte Flow API Reference](https://svelteflow.dev/api-reference) - [xyflow GitHub](https://github.com/xyflow/xyflow)