mirror of https://github.com/artf/grapesjs.git
10 changed files with 66 additions and 41 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,38 @@ |
|||
--- |
|||
title: Commands |
|||
--- |
|||
|
|||
# Commands |
|||
|
|||
A basic command in GrapesJS it's a simple function, but you will see in this guide how powerfull they can be. The main goal of the Command module is to centralize functions and be easily reused across the editor. Another big advantage of using commands is the ability to track them, extend or even interrupt beside some conditions. |
|||
|
|||
::: warning |
|||
This guide is referring to GrapesJS v0.14.59 or higher |
|||
::: |
|||
|
|||
[[toc]] |
|||
|
|||
|
|||
## Basic configuration |
|||
|
|||
You can create your commands already from initialization by passing them in the `commands.defaults` options: |
|||
|
|||
```js |
|||
const editor = grapesjs.init({ |
|||
... |
|||
commands: { |
|||
defaults: [ |
|||
{ |
|||
// id and run are mandatory in this case |
|||
id: 'my-command-id', |
|||
run() { |
|||
alert('This is my command'); |
|||
}, |
|||
}, { |
|||
id: '...', |
|||
// ... |
|||
} |
|||
], |
|||
} |
|||
}); |
|||
``` |
|||
@ -1,31 +1,10 @@ |
|||
module.exports = { |
|||
ESCAPE_KEY: 27, |
|||
|
|||
stylePrefix: 'com-', |
|||
|
|||
// Default array of commands
|
|||
defaults: [], |
|||
|
|||
// If true, stateful commands (with `run` and `stop` methods) can't be runned multiple times.
|
|||
// So, if the command is already active, running it again will not execute the `run` method
|
|||
strict: 1, |
|||
|
|||
// Editor model
|
|||
// @deprecated
|
|||
em: null, |
|||
|
|||
// If true center new first-level components
|
|||
// @deprecated
|
|||
firstCentered: true, |
|||
|
|||
// If true the new component will created with 'height', else 'min-height'
|
|||
// @deprecated
|
|||
newFixedH: false, |
|||
|
|||
// Minimum height (in px) of new component
|
|||
// @deprecated
|
|||
minComponentH: 50, |
|||
|
|||
// Minimum width (in px) of component on creation
|
|||
// @deprecated
|
|||
minComponentW: 50 |
|||
strict: 1 |
|||
}; |
|||
|
|||
Loading…
Reference in new issue