retejs / rete

JavaScript framework for visual programming
https://retejs.org
MIT License
10.17k stars 653 forks source link

Couldn't create node at mouse position on drop #495

Closed unclexo closed 3 years ago

unclexo commented 4 years ago

First of all, tons of thanks for creating such a great tool.

I'm having a problem while creating node on drop. What I want to do is create node exactly where my cursor is at on the editor while dropping. But it is not being created at the mouse position. I'm using the following code snippet:

const { x, y } = editor.view.area.mouse

const component = new SomeComponent();
const textNode = await component.createNode()
textNode.position = [x, y]
editor.addNode(textNode)
Ibrahimvse commented 3 years ago
        // force update the mouse position
        editor.view.area.pointermove(e as any as PointerEvent);
        const { x, y } = editor.view.area.mouse
unclexo commented 3 years ago

@Ibrahimvse it works! Thanks a lot!