jerosoler / Drawflow

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

prevent the deletion of certain nodes #826

Open TheoCtla opened 4 months ago

TheoCtla commented 4 months ago

I'd like to know if there's a function to prevent certain nodes from being deleted, I've tried it myself but it didn't work. Thanks

TheoCtla commented 4 months ago

Or if you can give me the name of the function that deletes the nodes, so that I can override it.

jerosoler commented 4 months ago

View this:

TheoCtla commented 4 months ago

Thanks, so it'll be good if i override the function "RemoveNodeId" ?

jerosoler commented 4 months ago

Yes, no problem!

TheoCtla commented 4 months ago

I've tried overriding the "RemoveNodeId" function but it doesn't work. I'd like to remove the deletion of two nodes in particular, do you have any advice?

jerosoler commented 4 months ago

For example by class.

    editor.removeNodeId = function(id) {
        const node = editor.getNodeFromId(id.slice(5));
        if(node.class === "nodelete")  {
            return;
        }
        this.removeConnectionNodeId(id);
        let moduleName = this.getModuleFromNodeId(id.slice(5));
        if (this.module === moduleName) {
            this.container.querySelector(`#${id}`).remove();
        }

        delete this.drawflow.drawflow[moduleName].data[id.slice(5)];
        this.dispatch('nodeRemoved', id.slice(5));
    }
    editor.start();
    editor.addNode("item", 1, 1, 700, 400, "nodelete", {}, 'A');
    editor.addNode("item", 1, 1, 900, 700, "item", {}, 'B');
    editor.addNode("item", 1, 1, 500, 550, "nodelete", {}, 'C');