jerosoler / Drawflow

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

How can I prevent a specific widget from getting cleared. #330

Closed Yusufzai closed 2 years ago

Yusufzai commented 2 years ago

Let suppose I have total 6 widgets from which 5 of them are comman and 1 is global widget (like mentioned below)

global widget widget - 1 widget - 2 widget - 3 widget - 4 widget - 5

So what I want?

When I press on clear button I don't want to delete global widget (I only want to remove widget 1 - 6).

https://prnt.sc/23ptard

jerosoler commented 2 years ago

I understand that you are clearing the data with the function "clearModuleSelected".

What you can do is loop through the "editor.export" and remove only your node with the "removeNodeId" function.

Yusufzai commented 2 years ago

Thanks it worked :)

Yusufzai commented 2 years ago

Below is my code in case if anybody need it.

// On click of the clear Button

document.querySelector('.clear-data-button').addEventListener('click', function() {
    exportList = editor.export().drawflow.Home.data;
    Object.keys(exportList).map((k) => {

        getInfo = editor.getNodeFromId(k);
        getName = getInfo.name;

        // Condition to check for the widget that should not be deleted 
        // In this case it is global-widget

        if (getName === 'global-widget') {
            return;
        } else {
            editor.removeNodeId(`node-${k}`);
        }

    })
})