GrapesJS / grapesjs

Free and Open source Web Builder Framework. Next generation tool for building templates without coding
https://grapesjs.com
BSD 3-Clause "New" or "Revised" License
22.4k stars 4.06k forks source link

Command running multiple times #1127

Closed milapshah15 closed 6 years ago

milapshah15 commented 6 years ago

Hello Folks,

I need your help.I created a custom button on the commands Panel to publish the site created from Grapes.When i click on it, it executes the command 2 times and I am not sure why

Here is my code snippet.Any help would be really appreciated.

        //Get the default plugin set for all the blocks
        plugins: ['gjs-preset-webpage'],
        pluginsOpts: {
            'gjs-preset-webpage': { /* options */ }
        },

        //Commands
        commands: {
            defaults: [{
                id: 'publishContent',
                run: function (editor, senderBtn) {
                    publish(editor.getHtml(), editor.getCss());
                },
                stop: function (editor, senderBtn) {},
            }],
        },

    });

//Manipulate existing panels var panelManager = editor.Panels;

    //get Panel Object
    var panelObj = panelManager.getPanel('options');

    //publish button to publish the website
    var publishButton = panelManager.addButton('options', {
        id: 'publish',
        className: 'fa fa-upload',
        command: 'publishContent',
        attributes: {
            title: 'Publish Site'
        },
        active: false,
    });`

Warm regards Milap

milapshah15 commented 6 years ago

@artf Can you please help on this.

shareefhiasat commented 6 years ago

@milapshah15 please check @artf response and my response here

https://github.com/artf/grapesjs/issues/625

milapshah15 commented 6 years ago

@shareefhiasat if you see my code, I guess that issue is different than what I am facing.Moreover, I see that I face the issue when I load website-preset plugin

artf commented 6 years ago

@milapshah15 can't reproduce it, are you able to provide a simple live demo of the issue?

milapshah15 commented 6 years ago

@artf I ended up blocking the executing by setting/resetting a flag.

Closing this issue.

Warm regards Milap

medhadj commented 6 years ago

@artf

var p1 = new Promise(function(resolve, reject) {

                                editor.runCommand('cmd-1');
                                resolve("Succès !");
                                // ou
                                // reject("Erreur !");
                            });

                            p1.then((valeur) => {
                                setTimeout(function(){editor.runCommand('cmd-2'); }, 3000);

                                console.log(valeur); // Succès !

                            }, (raison) => {
                                console.log(raison); // Erreur !
                            });
lock[bot] commented 5 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.