Merge pull request #3681 from xyflow/svelte-on-edge-creation

feat(svelte) added onedgecreate function
This commit is contained in:
Moritz Klack
2023-11-29 16:35:45 +01:00
committed by GitHub
8 changed files with 52 additions and 8 deletions
@@ -6,7 +6,8 @@
Background,
BackgroundVariant,
MiniMap,
MarkerType
MarkerType,
type Connection
} from '@xyflow/svelte';
import '@xyflow/svelte/dist/style.css';
@@ -143,9 +144,28 @@
}
}
]);
$: console.log('edges', $edges);
function getEdgeId(connection: Connection) {
return `edge-${connection.source}-${connection.target}}`;
}
</script>
<SvelteFlow {nodes} {edges} fitView nodeDragThreshold={2}>
<SvelteFlow
{nodes}
{edges}
fitView
nodeDragThreshold={2}
onedgecreate={(connection) => {
console.log('on edge create', connection);
return {
...connection,
id: getEdgeId(connection)
};
}}
>
<Controls />
<Background variant={BackgroundVariant.Dots} />
<MiniMap />