grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

[Question] Any/Trigger event when any block is dropped inside canvas?

Open faizansaiyed opened this issue 9 years ago • 6 comments

Hey, How can I trigger some event when any new block or content inside canvas is updated? Something like editor.onCanvasUpdate()

Thanks!

faizansaiyed avatar Nov 28 '17 13:11 faizansaiyed

Hi @fsaiyedOB,

I've been able to accomplish this with the component:update event listed here: https://github.com/artf/grapesjs/wiki/API-Editor#available-events

My code looks something like

editor.on("component:update", function() {
  // do stuff here
});

ryandeba avatar Nov 28 '17 14:11 ryandeba

When I asked to find out when the canvas is dirty to provide an indicator, @artf told me:

editor.on('change:changesCount', (editorModel, changes) => {
  
    if (changes) {
  // do something with changes 
    } else {
     // do something else with no changes 
    }
  });
  

duskhacker avatar Nov 29 '17 01:11 duskhacker

I'd add also a block specific event

editor.on('block:drag:stop', model => console.log('dropped ', model))

artf avatar Nov 30 '17 12:11 artf

@artf what about doing this only for specific blocks?

ghost avatar Oct 30 '18 19:10 ghost

@chrisrobbins85kw I'd put some check (eg. some attribute/property) inside the callback

artf avatar Nov 02 '18 16:11 artf

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.

lock[bot] avatar Nov 02 '19 17:11 lock[bot]