@ -113,11 +113,6 @@ By changing `result.content` you're able to customize what is dropped
* `modal:open` - Modal is opened
* `modal:close` - Modal is closed
### Parser
* `parse:html` - On HTML parse, an object containing the input and the output of the parser is passed as an argument
* `parse:css` - On CSS parse, an object containing the input and the output of the parser is passed as an argument
### Commands
* `run:{commandName}` - Triggered when some command is called to run (eg. editor.runCommand('preview'))
@ -128,9 +123,17 @@ By changing `result.content` you're able to customize what is dropped
* `run` - Triggered on run of any command. The id and the result are passed as arguments to the callback
* `stop` - Triggered on stop of any command. The id and the result are passed as arguments to the callback
### Devices
Check the [Devices][2] module.
### Parser
Check the [Parser][3] module.
### Pages
Check the [Pages][2] module.
Check the [Pages][4 ] module.
### General
@ -146,7 +149,7 @@ Returns configuration object
### Parameters
* `prop` ** [string][3 ]?** Property name
* `prop` ** [string][5 ]?** Property name
Returns **any** Returns the configuration object or
the value of the specified property
@ -157,11 +160,12 @@ Returns HTML built inside canvas
### Parameters
* `opts` ** [Object][4 ]** Options (optional, default `{}` )
* `opts` ** [Object][6 ]** Options (optional, default `{}` )
* `opts.cleanId` * *[Boolean][5]** Remove unnecessary IDs (eg. those created automatically) (optional, default `false` )
* `opts.component` * *Component?** Return the HTML of a specific Component
* `opts.cleanId` * *[Boolean][7]** Remove unnecessary IDs (eg. those created automatically) (optional, default `false` )
Returns ** [string][3 ]** HTML string
Returns ** [string][5 ]** HTML string
## getCss
@ -169,17 +173,25 @@ Returns CSS built inside canvas
### Parameters
* `opts` ** [Object][4 ]** Options (optional, default `{}` )
* `opts` ** [Object][6 ]** Options (optional, default `{}` )
* `opts.avoidProtected` * *[Boolean][5]** Don't include protected CSS (optional, default `false` )
* `opts.component` * *Component?** Return the CSS of a specific Component
* `opts.json` * *[Boolean][7]** Return an array of CssRules instead of the CSS string (optional, default `false` )
* `opts.avoidProtected` * *[Boolean][7]** Don't include protected CSS (optional, default `false` )
Returns ** [string][3]** CSS string
Returns ** ([String][5] | [Array][8]\<CssRule>)** CSS string or array of CssRules
## getJs
Returns JS of all components
Returns ** [string][3]** JS string
### Parameters
* `opts` ** [Object][6]** Options (optional, default `{}` )
* `opts.component` * *Component?** Get the JS of a specific component
Returns ** [String][5]** JS string
## getComponents
@ -199,8 +211,8 @@ Set components inside editor's canvas. This method overrides actual components
### Parameters
* `components` ** ([Array][6]< [Object][4]> | [Object][4] | [string][3 ])** HTML string or components model
* `opt` ** [Object][4]** the options object to be used by the \[setComponents][em#setComponents][7 ] method (optional, default `{}` )
* `components` ** ([Array][8]< [Object][6]> | [Object][6] | [string][5 ])** HTML string or components model
* `opt` ** [Object][6]** the options object to be used by the \[setComponents][em#setComponents][9 ] method (optional, default `{}` )
### Examples
@ -222,10 +234,10 @@ Add components
### Parameters
* `components` ** ([Array][6]< [Object][4]> | [Object][4] | [string][3 ])** HTML string or components model
* `opts` ** [Object][4 ]** Options
* `components` ** ([Array][8]< [Object][6]> | [Object][6] | [string][5 ])** HTML string or components model
* `opts` ** [Object][6 ]** Options
* `opts.avoidUpdateStyle` * *[Boolean][5 ]** If the HTML string contains styles,
* `opts.avoidUpdateStyle` * *[Boolean][7 ]** If the HTML string contains styles,
by default, they will be created and, if already exist, updated. When this option
is true, styles already created will not be updated. (optional, default `false` )
@ -241,13 +253,13 @@ editor.addComponents({
});
```
Returns ** [Array][6 ]\<Component>**
Returns ** [Array][8 ]\<Component>**
## getStyle
Returns style in JSON format object
Returns ** [Object][4 ]**
Returns ** [Object][6 ]**
## setStyle
@ -255,8 +267,8 @@ Set style inside editor's canvas. This method overrides actual style
### Parameters
* `style` ** ([Array][6]< [Object][4]> | [Object][4] | [string][3 ])** CSS string or style model
* `opt` ** [Object][4]** the options object to be used by the \[setStyle][em#setStyle][8] method (optional, default `{}` )
* `style` ** ([Array][8]< [Object][6]> | [Object][6] | [string][5 ])** CSS string or style model
* `opt` (optional, default `{}` )
### Examples
@ -264,13 +276,30 @@ Set style inside editor's canvas. This method overrides actual style
editor.setStyle('.cls{color: red}');
//or
editor.setStyle({
selectors: ['cls']
selectors: ['cls'],
style: { color: 'red' }
});
```
Returns **this**
## addStyle
Add styles to the editor
### Parameters
* `style` ** ([Array][8]< [Object][6]> | [Object][6] | [string][5])** CSS string or style model
* `opts` (optional, default `{}` )
### Examples
```javascript
editor.addStyle('.cls{color: red}');
```
Returns ** [Array][8]\<CssRule>** Array of created CssRule instances
## getSelected
Returns the last selected component, if there is one
@ -281,7 +310,7 @@ Returns **Model**
Returns an array of all selected components
Returns ** [Array][6 ]**
Returns ** [Array][8 ]**
## getSelectedToStyle
@ -299,10 +328,10 @@ Select a component
### Parameters
* `el` ** (Component | [HTMLElement][9 ])** Component to select
* `opts` ** [Object][4 ]?** Options
* `el` ** (Component | [HTMLElement][10 ])** Component to select
* `opts` ** [Object][6 ]?** Options
* `opts.scroll` * *[Boolean][5 ]?** Scroll canvas to the selected element
* `opts.scroll` * *[Boolean][7 ]?** Scroll canvas to the selected element
### Examples
@ -321,7 +350,7 @@ Add component to selection
### Parameters
* `el` ** (Component | [HTMLElement][9] | [Array][6 ])** Component to select
* `el` ** (Component | [HTMLElement][10] | [Array][8 ])** Component to select
### Examples
@ -337,7 +366,7 @@ Remove component from selection
### Parameters
* `el` ** (Component | [HTMLElement][9] | [Array][6 ])** Component to select
* `el` ** (Component | [HTMLElement][10] | [Array][8 ])** Component to select
### Examples
@ -353,7 +382,7 @@ Toggle component selection
### Parameters
* `el` ** (Component | [HTMLElement][9] | [Array][6 ])** Component to select
* `el` ** (Component | [HTMLElement][10] | [Array][8 ])** Component to select
### Examples
@ -363,6 +392,21 @@ editor.selectToggle(model);
Returns **this**
## getEditing
Returns, if active, the Component enabled in rich text editing mode.
### Examples
```javascript
const textComp = editor.getEditing();
if (textComp) {
console.log('HTML: ', textComp.toHTML());
}
```
Returns ** (Component | null)**
## setDevice
Set device to the editor. If the device exists it will
@ -370,7 +414,7 @@ change the canvas to the proper width
### Parameters
* `name` ** [string][3 ]** Name of the device
* `name` ** [string][5 ]** Name of the device
### Examples
@ -392,7 +436,7 @@ console.log(device);
// 'Tablet'
```
Returns ** [string][3 ]** Device name
Returns ** [string][5 ]** Device name
## runCommand
@ -400,8 +444,8 @@ Execute command
### Parameters
* `id` ** [string][3 ]** Command ID
* `options` ** [Object][4 ]** Custom options (optional, default `{}` )
* `id` ** [string][5 ]** Command ID
* `options` ** [Object][6 ]** Custom options (optional, default `{}` )
### Examples
@ -417,8 +461,8 @@ Stop the command if stop method was provided
### Parameters
* `id` ** [string][3 ]** Command ID
* `options` ** [Object][4 ]** Custom options (optional, default `{}` )
* `id` ** [string][5 ]** Command ID
* `options` ** [Object][6 ]** Custom options (optional, default `{}` )
### Examples
@ -434,9 +478,22 @@ Store data to the current storage
### Parameters
* `clb` ** [Function][10 ]** Callback function
* `clb` ** [Function][11 ]** Callback function
Returns ** [Object][4]** Stored data
Returns ** [Object][6]** Stored data
## storeData
Get the JSON data object, which could be stored and loaded back with `editor.loadData(json)`
### Examples
```javascript
console.log(editor.storeData());
// { pages: [...], styles: [...], ... }
```
Returns ** [Object][6]**
## load
@ -444,23 +501,39 @@ Load data from the current storage
### Parameters
* `clb` ** [Function][10 ]** Callback function
* `clb` ** [Function][11 ]** Callback function
Returns ** [Object][4]** Stored data
Returns ** [Object][6]** Stored data
## loadData
Load data from the JSON data object
### Parameters
* `data` ** [Object][6]** Data to load
### Examples
```javascript
editor.loadData({ pages: [...], styles: [...], ... })
```
Returns ** [Object][6]** Loaded object
## getContainer
Returns container element. The one which was indicated as 'container'
on init method
Returns ** [HTMLElement][9]**
Returns ** [HTMLElement][10 ]**
## getDirtyCount
Return the count of changes made to the content and not yet stored.
This count resets at any `store()`
Returns ** [number][11]**
Returns ** [number][12 ]**
## refresh
@ -473,9 +546,9 @@ refresh you'll get misleading position of tools
### Parameters
* `opts`
* `options` ** [Object][4 ]?** Options
* `options` ** [Object][6 ]?** Options
* `options.tools` * *[Boolean][5 ]** Update the position of tools (eg. rich text editor, component highlighter, etc.) (optional, default `false` )
* `options.tools` * *[Boolean][7 ]** Update the position of tools (eg. rich text editor, component highlighter, etc.) (optional, default `false` )
## setCustomRte
@ -483,7 +556,7 @@ Replace the built-in Rich Text Editor with a custom one.
### Parameters
* `obj` ** [Object][4 ]** Custom RTE Interface
* `obj` ** [Object][6 ]** Custom RTE Interface
### Examples
@ -523,7 +596,7 @@ custom parser, pass `null` as the argument
### Parameters
* `parser` ** ([Function][10 ] | null)** Parser function
* `parser` ** ([Function][11 ] | null)** Parser function
### Examples
@ -545,11 +618,11 @@ Returns **this**
## setDragMode
Change the global drag mode of components.
To get more about this feature read: [https://github.com/artf/grapesjs/issues/1936][12 ]
To get more about this feature read: [https://github.com/artf/grapesjs/issues/1936][13 ]
### Parameters
* `value` ** [String][3 ]** Drag mode, options: 'absolute' | 'translate'
* `value` ** [String][5 ]** Drag mode, options: 'absolute' | 'translate'
Returns **this**
@ -560,10 +633,10 @@ Trigger event log message
### Parameters
* `msg` **any** Message to log
* `opts` ** [Object][4 ]** Custom options (optional, default `{}` )
* `opts` ** [Object][6 ]** Custom options (optional, default `{}` )
* `opts.ns` * *[String][3 ]** Namespace of the log (eg. to use in plugins) (optional, default `''` )
* `opts.level` * *[String][3 ]** Level of the log, `debug` , `info` , `warning` , `error` (optional, default `'debug'` )
* `opts.ns` * *[String][5 ]** Namespace of the log (eg. to use in plugins) (optional, default `''` )
* `opts.level` * *[String][5 ]** Level of the log, `debug` , `info` , `warning` , `error` (optional, default `'debug'` )
### Examples
@ -585,11 +658,11 @@ Translate label
### Parameters
* `args` ** ...any**
* `key` ** [String][3 ]** Label to translate
* `opts` ** [Object][4 ]?** Options for the translation
* `key` ** [String][5 ]** Label to translate
* `opts` ** [Object][6 ]?** Options for the translation
* `opts.params` * *[Object][4 ]?** Params for the translation
* `opts.noWarn` * *[Boolean][5 ]?** Avoid warnings in case of missing resources
* `opts.params` * *[Object][6 ]?** Params for the translation
* `opts.noWarn` * *[Boolean][7 ]?** Avoid warnings in case of missing resources
### Examples
@ -601,7 +674,7 @@ editor.t('msg2', { params: { test: 'hello' } });
editor.t('msg2', { params: { test: 'hello' }, l: 'it' });
```
Returns ** [String][3 ]**
Returns ** [String][5 ]**
## on
@ -609,8 +682,8 @@ Attach event
### Parameters
* `event` ** [string][3 ]** Event name
* `callback` ** [Function][10 ]** Callback function
* `event` ** [string][5 ]** Event name
* `callback` ** [Function][11 ]** Callback function
Returns **this**
@ -620,8 +693,8 @@ Attach event and detach it after the first run
### Parameters
* `event` ** [string][3 ]** Event name
* `callback` ** [Function][10 ]** Callback function
* `event` ** [string][5 ]** Event name
* `callback` ** [Function][11 ]** Callback function
Returns **this**
@ -631,8 +704,8 @@ Detach event
### Parameters
* `event` ** [string][3 ]** Event name
* `callback` ** [Function][10 ]** Callback function
* `event` ** [string][5 ]** Event name
* `callback` ** [Function][11 ]** Callback function
Returns **this**
@ -642,7 +715,7 @@ Trigger event
### Parameters
* `event` ** [string][3 ]** Event to trigger
* `event` ** [string][5 ]** Event to trigger
Returns **this**
@ -654,28 +727,50 @@ Destroy the editor
Render editor
Returns ** [HTMLElement][9]**
Returns ** [HTMLElement][10]**
## html
Print safe HTML by using ES6 tagged template strings.
### Parameters
* `literals` ** [Array][8]< [String][5]>**
* `substs` ** [Array][8]< [String][5]>**
### Examples
```javascript
const unsafeStr = '< script > ... . < / script > ';
const safeStr = '< b > Hello< / b > ';
// Use `$${var}` to avoid escaping
const strHtml = editor.html`Escaped ${unsafeStr}, unescaped $${safeStr}`;
```
Returns ** [String][5]**
[1]: https://github.com/artf/grapesjs/blob/master/src/editor/config/config.js
[2]: /api/pages.html
[2]: /api/device_manager.html
[3]: /api/parser.html
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[4]: /api/pages.html
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
[7]: em#setComponents
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
[8]: em#setStyle
[9]: em#setComponents
[9]: https://developer.mozilla.org/docs/Web/HTML/Element
[10 ]: https://developer.mozilla.org/docs/Web/HTML/Element
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
[11 ]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function
[11 ]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
[12 ]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
[12 ]: https://github.com/artf/grapesjs/issues/1936
[13 ]: https://github.com/artf/grapesjs/issues/1936