jerosoler / Drawflow

Simple flow library 🖥️🖱️
https://jerosoler.github.io/Drawflow/
MIT License
4.64k stars 722 forks source link

Drawflow keeps moving after releasing mouse outside #237

Closed dollarunderscore closed 3 years ago

dollarunderscore commented 3 years ago

If you click in the drawflow container and move the mouse outside the container and then move the mouse back into the container, the container content is moved although the mouse is not clicked anymore.

To reproduce the issue:

  1. go to the demo page https://jerosoler.github.io/Drawflow/
  2. click in the drawflow container and move mouse to the left outside
  3. release the mouse
  4. move the mouse back into the container

=> container content is moving with the mouse when not clicked

dollarunderscore commented 3 years ago

moving the drawflow container with the mouse is core functionality and should work. and i have exactly the same issue in my project.

jerosoler commented 3 years ago

Hello @dollarunderscore

You can prevent the behavior like this:

 editor.start();
          document.addEventListener('mousemove', function(e) {
              if(e.target.closest(".parent-drawflow") === null) {
                editor.dragEnd(e);
              }
          });

Even I like the normal way better. You can use this method.

dollarunderscore commented 3 years ago

Thanks for the answer, the dragEnd has helped me a lot. i have optimized the code a bit so that it is only executed on the "mouseleave" event.

With jQuery (change this.drawfow to your drawflow instance):

$("#drawflow").on("mouseleave", (event) => {
    this.drawflow.dragEnd(event.originalEvent);
});