## Editor Editor contains the top level API which you'll probably use to customize the editor or extend it with plugins. You get the Editor instance on init method and you can pass options via its [Configuration Object][1] ```js const editor = grapesjs.init({ // options }); ``` ## Available Events You can make use of available events in this way ```js editor.on('EVENT-NAME', (some, argument) => { // do something }) ``` ### Components - `component:add` - Triggered when a new component is added to the editor, the model is passed as an argument to the callback - `component:remove` - Triggered when a component is removed, the model is passed as an argument to the callback - `component:clone` - Triggered when a new component is added by a clone command, the model is passed as an argument to the callback - `component:update` - Triggered when a component is updated (moved, styled, etc.), the model is passed as an argument to the callback - `component:update:{propertyName}` - Listen any property change, the model is passed as an argument to the callback - `component:styleUpdate` - Triggered when the style of the component is updated, the model is passed as an argument to the callback - `component:styleUpdate:{propertyName}` - Listen for a specific style property change, the model is passed as an argument to the callback - `component:selected` - New component selected, the selected model is passed as an argument to the callback - `component:deselected` - Component deselected, the deselected model is passed as an argument to the callback - `component:toggled` - Component selection changed, toggled model is passed as an argument to the callback ### Blocks - `block:add` - New block added - `block:remove` - Block removed - `block:drag:start` - Started dragging block, model of the block is passed as an argument - `block:drag` - Dragging block, the block's model and the drag event are passed as arguments - `block:drag:stop` - Dragging of the block is stopped. As agruments for the callback you get, the dropped component model (if dropped successfully) and the model of the block ### Assets - `asset:add` - New asset added - `asset:remove` - Asset removed - `asset:upload:start` - Before the upload is started - `asset:upload:end` - After the upload is ended - `asset:upload:error` - On any error in upload, passes the error as an argument - `asset:upload:response` - On upload response, passes the result as an argument ### Keymaps - `keymap:add` - New keymap added. The new keyamp object is passed as an argument - `keymap:remove` - Keymap removed. The removed keyamp object is passed as an argument - `keymap:emit` - Some keymap emitted, in arguments you get keymapId, shortcutUsed, Event - `keymap:emit:{keymapId}` - `keymapId` emitted, in arguments you get keymapId, shortcutUsed, Event ### Style Manager - `styleManager:change` - Triggered on style property change from new selected component, the view of the property is passed as an argument to the callback - `styleManager:change:{propertyName}` - As above but for a specific style property ### Storages - `storage:start` - Before the storage request is started - `storage:start:store` - Before the store request. The object to store is passed as an argumnet (which you can edit) - `storage:start:load` - Before the load request. Items to load are passed as an argumnet (which you can edit) - `storage:load` - Triggered when something was loaded from the storage, loaded object passed as an argumnet - `storage:store` - Triggered when something is stored to the storage, stored object passed as an argumnet - `storage:end` - After the storage request is ended - `storage:end:store` - After the store request - `storage:end:load` - After the load request - `storage:error` - On any error on storage request, passes the error as an argument - `storage:error:store` - Error on store request, passes the error as an argument - `storage:error:load` - Error on load request, passes the error as an argument ### Canvas - `canvas:dragenter` - When something is dragged inside the canvas, `DataTransfer` instance passed as an argument - `canvas:dragover` - When something is dragging on canvas, `DataTransfer` instance passed as an argument - `canvas:drop` - Something is dropped in canvas, `DataTransfer` instance and the dropped model are passed as arguments - `canvas:dragend` - When a drag operation is ended, `DataTransfer` instance passed as an argument - `canvas:dragdata` - On any dataTransfer parse, `DataTransfer` instance and the `result` are passed as arguments. By changing `result.content` you're able to customize what is dropped ### Selectors - `selector:add` - Triggers when a new selector/class is created ### RTE - `rte:enable` - RTE enabled. The view, on which RTE is enabled, is passed as an argument - `rte:disable` - RTE disabled. The view, on which RTE is disabled, is passed as an argument ### Commands - `run:{commandName}` - Triggered when some command is called to run (eg. editor.runCommand('preview')) - `stop:{commandName}` - Triggered when some command is called to stop (eg. editor.stopCommand('preview')) - `run:{commandName}:before` - Triggered before the command is called - `stop:{commandName}:before` - Triggered before the command is called to stop - `abort:{commandName}` - Triggered when the command execution is aborted (`editor.on(`run:preview:before`, opts => opts.abort = 1);`) ### General - `canvasScroll` - Triggered when the canvas is scrolle - `undo` - Undo executed - `redo` - Redo executed - `load` - When the editor is loaded ## getConfig Returns configuration object ### Parameters - `prop` **[string][2]?** Property name Returns **any** Returns the configuration object or the value of the specified property ## getHtml Returns HTML built inside canvas ### Parameters - `opts` Returns **[string][2]** HTML string ## getCss Returns CSS built inside canvas ### Parameters - `opts` **[Object][3]** Options (optional, default `{}`) Returns **[string][2]** CSS string ## getJs Returns JS of all components Returns **[string][2]** JS string ## getComponents Returns components in JSON format object Returns **[Object][3]** ## setComponents Set components inside editor's canvas. This method overrides actual components ### Parameters - `components` **([Array][4]<[Object][3]> | [Object][3] \| [string][2])** HTML string or components model ### Examples ```javascript editor.setComponents('