## $ Editor class contains the top level API which you'll probably use to custom the editor or extend it with plugins. You get the Editor instance on init method ```js var editor = grapesjs.init({...}); ``` # Available Events ## 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 ### Parameters - `config` **[Object][1]** Configurations - `config.container` **[string][2]** ='' Selector for the editor container, eg. '#myEditor' - `config.components` **([string][2] \| [Array][3]<[Object][1]>)** HTML string or object of components (optional, default `''`) - `config.style` **([string][2] \| [Array][3]<[Object][1]>)** CSS string or object of rules (optional, default `''`) - `config.fromElement` **[Boolean][4]** If true, will fetch HTML and CSS from selected container (optional, default `false`) - `config.undoManager` **[Boolean][4]** Enable/Disable undo manager (optional, default `true`) - `config.autorender` **[Boolean][4]** If true renders editor on init (optional, default `true`) - `config.noticeOnUnload` **[Boolean][4]** Enable/Disable alert message before unload the page (optional, default `true`) - `config.height` **[string][2]** Height for the editor container (optional, default `'900px'`) - `config.width` **[string][2]** Width for the editor container (optional, default `'100%'`) - `config.storage` **[Object][1]** Storage manager configuration, see the relative documentation (optional, default `{}`) - `config.styleManager` **[Object][1]** Style manager configuration, see the relative documentation (optional, default `{}`) - `config.commands` **[Object][1]** Commands configuration, see the relative documentation (optional, default `{}`) - `config.domComponents` **[Object][1]** Components configuration, see the relative documentation (optional, default `{}`) - `config.panels` **[Object][1]** Panels configuration, see the relative documentation (optional, default `{}`) - `config.showDevices` **[Object][1]** If true render a select of available devices inside style manager panel (optional, default `true`) - `config.keepEmptyTextNodes` **[Boolean][4]** If false, removes empty text nodes when parsed (unless they contain a space) (optional, default `false`) - `config.defaultCommand` **[string][2]** Command to execute when no other command is running (optional, default `'select-comp'`) - `config.plugins` **[Array][3]** Array of plugins to execute on start (optional, default `[]`) - `config.pluginsOpts` **[Object][1]** Custom options for plugins (optional, default `{}`) ### Examples ```javascript var editor = grapesjs.init({ container : '#gjs', components: '