xyflow: SvelteFlow: Trigger an ongoing connection
Please describe the feature that you want to propose
Hello,
I have a use case where I would like to allow creating a new node on shortcut key pressed, and I can do this via having an event listener:
window?.addEventListener('keydown', handleKeyboardEvent)
and then updating the nodes writable like so:
const newNode: SvelteFlowNode = initSvelteFlowNode({
position: cursorPosition,
type: nodeTypeToCreateByShortcut
} as Partial<SvelteFlowNode>)
if (!validateNewNode(getCurrentGraph(), newNode)) return
sendToHistory()
nodesWritable.update((nodes) => [...nodes, newNode])
... where I also have, among other props to the SvelteFlow component:
<SvelteFlow
initialViewport={INITIAL_VIEWPORT}
viewport={viewportWritable}
nodes={nodesWritable}
edges={edgesWritable}
....
/>
This works, and the node gets created. But my other requirement is to create a connection as soon as the node is created from some handle of the node (let’s say Position.BOTTOM), such that the user will immediately have a potential connection attached to his mouse cursor as soon as the node is created, which can be turned into an edge if a successful onconnectend is fired once the user attaches the edge to a valid handle, like usual.
How to achieve this? Probably through the useSvelteFlow hook, but I have not found a function there to dynamically create a Connection there either.
Thanks in advance!
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 17 (9 by maintainers)
Ah, I know what is going on. In React Flow it is possible to connect two handles by clicking on them. This way you can simply trigger a click on the handle, then draw an edge to the mouse of the user until another handle is clicked.
I will work on making Svelte Flow feature complete this month. I will add click connections to make this possible!
It’s on my immediate to-do list - I was initially under the impression this would simply be achievable with Svelte 1.0 once reconnecting & click connecting was properly implemented. However, it turned out there is a little bit of a workaround required… Will update you very soon once I figured it out or found some improvement we can easily make on the library side.