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.36k stars 4.05k forks source link

[Bug] editor.Panels.addPanel duplicate buttons #2621

Closed yuzhva closed 4 years ago

yuzhva commented 4 years ago

While creating a custom plugin, in case, when editor.Panels.addPanel is using inside plugin function - buttons are duplicated.

Example: https://jsfiddle.net/kncdah8b/

Buttons are not duplicated:

Currently, I'm using the next trick to avoid the duplications:

function gjsPlugin(editor) {
  editor.on('load', () => {
    editor.Panels.addPanel({
      id: 'custom-panel',
      el: '.custom-panel',
      buttons: [
        {
          id: 'PANEL_ACTION.EXPT',
          className: 'fa fa-code',
          command: 'export-template',
          attributes: { title: 'View code' }
        }
      ]
    });
  });
}
yuzhva commented 4 years ago

Closing the issue, as I found the other solution:

const panelCustom = editor.Panels.addPanel({
    id: 'panel__custom',
    el: '.panel__custom'
  });

const panelCustomButtons = panelCustom.get('buttons');
panelCustomButtons.add(topBarButtonsCenter);

But the issue with editor.Panels.addPanel({ buttons: [] }); still exist (=

artf commented 4 years ago

Thanks @YUzhva for the report and the solution. I'll try to check this out

hellocaio commented 4 years ago

Same here, I tested the panels example (Getting started) in the docs too and keep getting duplicate buttons. @yuzhva solution works, thanks :)

FaisalShaikhHA commented 1 year ago

Hi, @artf facing the same issue and @yuzhva solution not working for me as well. I am adding panels from (Getting started) docs but with different names. Screenshot on 2022-11-19 at 12_44_11

Adarshsingh2k commented 6 months ago

did any one find any resolution for this ug in react