diff --git a/examples/svelte/src/routes/examples/add-node-on-drop/Flow.svelte b/examples/svelte/src/routes/examples/add-node-on-drop/Flow.svelte index f0bd7a74..2f5378c2 100644 --- a/examples/svelte/src/routes/examples/add-node-on-drop/Flow.svelte +++ b/examples/svelte/src/routes/examples/add-node-on-drop/Flow.svelte @@ -56,11 +56,11 @@ }; nodes.push(newNode); - edges.push({ - source: connectingNodeId, - target: id, - id: `${connectingNodeId}--${id}` - }); + // edges.push({ + // source: connectingNodeId, + // target: id, + // id: `${connectingNodeId}--${id}` + // }); } }; diff --git a/examples/svelte/src/routes/examples/drag-n-drop/Flow.svelte b/examples/svelte/src/routes/examples/drag-n-drop/Flow.svelte index cb9eea2b..9fc68a5e 100644 --- a/examples/svelte/src/routes/examples/drag-n-drop/Flow.svelte +++ b/examples/svelte/src/routes/examples/drag-n-drop/Flow.svelte @@ -13,7 +13,7 @@ import '@xyflow/svelte/dist/style.css'; - const nodes = writable([ + const initialNodes = [ { id: '1', type: 'input', @@ -32,9 +32,11 @@ data: { label: 'Output Node' }, position: { x: 300, y: 150 } } - ]); + ]; - const edges = writable([ + let nodes = $state.raw(initialNodes); + + let edges = $state.raw([ { id: '1-2', type: 'default', @@ -50,7 +52,7 @@ } ]); - const svelteFlow = useSvelteFlow(); + const { screenToFlowPosition } = $derived(useSvelteFlow()); const onDragOver = (event: DragEvent) => { event.preventDefault(); @@ -68,7 +70,7 @@ } const type = event.dataTransfer.getData('application/svelteflow') || 'default'; - const position = svelteFlow.screenToFlowPosition({ + const position = screenToFlowPosition({ x: event.clientX, y: event.clientY }); @@ -79,15 +81,14 @@ data: { label: `${type} node` } }; - $nodes.push(newNode); - $nodes = $nodes; + nodes = [...nodes, newNode]; }; - $inspect($nodes); + $inspect(nodes);
- + diff --git a/examples/svelte/src/routes/examples/drag-n-drop/Sidebar.svelte b/examples/svelte/src/routes/examples/drag-n-drop/Sidebar.svelte index a143a94d..30cad2ee 100644 --- a/examples/svelte/src/routes/examples/drag-n-drop/Sidebar.svelte +++ b/examples/svelte/src/routes/examples/drag-n-drop/Sidebar.svelte @@ -10,7 +10,7 @@ event.dataTransfer.effectAllowed = 'move'; }; - const { zoomIn, zoomOut, fitView, viewport, nodes } = useSvelteFlow(); + // const { zoomIn, zoomOut, fitView, viewport, nodes } = $derived(useSvelteFlow());