Free and Open source Web Builder Framework. Next generation tool for building templates without coding
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

1.8 KiB

Commands

You can customize the initial state of the module from the editor initialization, by passing the following Configuration Object

const editor = grapesjs.init({
 commands: {
   // options
 }
})

Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance

const commands = editor.Commands;

add

Add new command to the collection

Parameters

  • id string Command's ID
  • command (Object | Function) Object representing your command, By passing just a function it's intended as a stateless command (just like passing an object with only run method).

Examples

commands.add('myCommand', {
	run(editor, sender) {
		alert('Hello world!');
	},
	stop(editor, sender) {
	},
});
// As a function
commands.add('myCommand2', editor => { ... });

Returns this

get

Get command by ID

Parameters

Examples

var myCommand = commands.get('myCommand');
myCommand.run();

Returns Object Object representing the command

has

Check if command exists

Parameters

Returns Boolean