chore(examples): add updateNode

This commit is contained in:
moklick
2023-12-13 11:50:09 +01:00
parent b332b86090
commit 94e822caa8
3 changed files with 26 additions and 4 deletions
@@ -12,7 +12,8 @@
type EdgeTypes,
type Node,
type Edge,
ConnectionMode
ConnectionMode,
useSvelteFlow
} from '@xyflow/svelte';
import CustomNode from './CustomNode.svelte';
@@ -6,7 +6,9 @@
Background,
BackgroundVariant,
MiniMap,
type NodeTypes
type NodeTypes,
useSvelteFlow,
Panel
} from '@xyflow/svelte';
import CustomNode from './CustomNode.svelte';
@@ -50,6 +52,12 @@
target: '3'
}
]);
const { updateNode } = useSvelteFlow();
const updateNodePosition = () => {
updateNode('1', (node) => ({ position: { x: node.position.x + 10, y: node.position.y } }));
};
</script>
<main>
@@ -57,6 +65,8 @@
<Controls />
<Background variant={BackgroundVariant.Dots} />
<MiniMap />
<Panel><button on:click={updateNodePosition}>update node</button></Panel>
</SvelteFlow>
</main>