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

FEAT: add click event on blocks #3506

Closed iabhiyaan closed 3 years ago

iabhiyaan commented 3 years ago
editor.on('block:click', (block) => {
  console.log(block)
})

Or Is there any way to listen for click event in block ?

YyueeiWY commented 3 years ago
    editor.on('component:selected', (some, argument) => {
      console.log(some, argument);
    })

https://grapesjs.com/docs/api/editor.html#available-events

artf commented 3 years ago

Well you can actually make use of custom render from blocks to apply custom DOM events.

blockManager.add('some-block-id', {
  // ... block definition
  render: ({ model, el }) => {
   el.addEventListener('click', () => {
     console.log('block', model)
   })
  },
});