Grapesjs: Execute command on drop

Created on 20 Jul 2017  路  3Comments  路  Source: artf/grapesjs

This is not an issue, I just need some help or information, please.

I created a custom block using editor.BlockManager.add()

How can I execute a command to run some Javascript to take user input in a prompt or something to modify the content of the model before it is inserted into the canvas after the drop?

I started with some code like this:

editor.on('block:drag:stop', function(model) {});

Or should I rather create a custom domcomponent somewhere?

Any help would be appreciated!

outdated

Most helpful comment

Correct, you can use editor.on('block:drag:stop', function(model) {}); or if you want something more component specific you can create a custom Component and make use of activeOnRender property

editor.DomComponents.addType('custom-type', {
  model: {...},
  view: defaultView.extend({
     init() {
       this.listenTo(this.model, 'active', this.doStuff); // listen for active event
     },
     doStuff() {...}
  }),
});


blockManager.add('test-block', {
 label: 'Label',
 content: {
    type: 'custom-type',
    activeOnRender: 1, // <- this will trigger the active event
 },
});

All 3 comments

Correct, you can use editor.on('block:drag:stop', function(model) {}); or if you want something more component specific you can create a custom Component and make use of activeOnRender property

editor.DomComponents.addType('custom-type', {
  model: {...},
  view: defaultView.extend({
     init() {
       this.listenTo(this.model, 'active', this.doStuff); // listen for active event
     },
     doStuff() {...}
  }),
});


blockManager.add('test-block', {
 label: 'Label',
 content: {
    type: 'custom-type',
    activeOnRender: 1, // <- this will trigger the active event
 },
});

@artf

Thank you so much, you rock!

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kickbk picture kickbk  路  3Comments

Snarkly picture Snarkly  路  3Comments

krunal039 picture krunal039  路  3Comments

kawika-connell picture kawika-connell  路  3Comments

crazyxhz picture crazyxhz  路  3Comments