jerosoler / Drawflow

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

Event :: moduleRemoved (Not working) #211

Closed shailesh345 closed 3 years ago

shailesh345 commented 3 years ago
editor.on('moduleRemoved', function(name) {
  console.log(name);
})

List of available events:

Event Return Description
nodeCreated id id of Node
nodeRemoved id id of Node
nodeSelected id id of Node
nodeUnselected true Unselect node
nodeMoved id id of Node
connectionStart { output_id, output_class } id of nodes and ouput selected
connectionCancel true Connection Cancel
connectionCreated { output_id, input_id, output_class, input_class } id's of nodes and ouput/input selected
connectionRemoved { output_id, input_id, output_class, input_class } id's of nodes and ouput/input selected
connectionSelected { output_id, input_id, output_class, input_class } id's of nodes and ouput/input selected
connectionUnselected true Unselect connection
addReroute id id of Node output
removeReroute id id of Node output
rerouteMoved id id of Node output
moduleCreated name name of Module
moduleChanged name name of Module
moduleRemoved name name of Module
click event Click event
clickEnd event Once the click changes have been made
contextmenu event Click second button mouse event
mouseMove { x, y } Position
keydown event Keydown event
zoom zoom_level Level of zoom
translate { x, y } Position translate editor
import import Finish import
export data Data export


jerosoler commented 3 years ago

Hello I just tested and it works. Complete html example.

Are you listening to the event before deleting the module?

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Drawflow</title>
    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/gh/jerosoler/Drawflow/dist/drawflow.min.css"
    />

    <script src="https://unpkg.com/drawflow@0.0.45/dist/drawflow.min.js"></script>
    <script src="minimap-drawflow.js"></script>
    <style>
      #drawflow {
        position: relative;
        width: 800px;
        height: 800px;
        border: 1px solid red;
      }
      </style>
  </head>
  <body>

    <div id="drawflow"></div>
    <div><div id="minimap"></div></div>
    <script>
          var id = document.getElementById("drawflow");
          const editor = new Drawflow(id);

          editor.start();

          editor.on('moduleRemoved', function(name) {
            alert(name);
          })

          editor.addModule('Other');
          editor.removeModule('Other');
    </script>
  </body>
</html>