Skip to content

Commit

Permalink
Update the Keymap module
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Nov 16, 2017
1 parent 8b9c932 commit 73b9fd9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
4 changes: 2 additions & 2 deletions dist/grapes.min.js

Large diffs are not rendered by default.

18 changes: 16 additions & 2 deletions src/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,48 @@
* var editor = grapesjs.init({...});
* ```
*
* **Available Events**
* # 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:update` - Triggered when a component is, generally, updated (moved, styled, etc.)
* * `component:update:{propertyName}` - Listen any property change
* * `component:styleUpdate` - Triggered when the style of the component is updated
* * `component:styleUpdate:{propertyName}` - Listen for a specific style property change
* * `component:selected` - New component selected
* ## Blocks
* * `block:add` - New block added
* * `block:remove` - Block removed
* ## 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:emit` - Some keymap emitted, in arguments you get keymapId, shortcutUsed, Event
* * `keymap:emit:{keymapId}` - `keymapId` emitted, in arguments you get keymapId, shortcutUsed, Event
* * `keymap:remove` - Keymap removed. The removed keyamp object is passed as an argument
* ## 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: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:error` - On any error on storage request, passes the error as an argument
* ## 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
* * `canvasScroll` - Triggered when the canvas is scrolled
* ## 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'))
* ## General
* * `canvasScroll` - Triggered when the canvas is scrolle
* * `load` - When the editor is loaded
*
* @module Editor
Expand Down
22 changes: 18 additions & 4 deletions src/keymaps/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/**
* This module allows to create shortcuts for functions and commands (via command id)
*
* You can access the module in this way
* ```js
* const keymaps = editor.Keymaps;
* ```
*
*/
import { defaults, isString } from 'underscore';

const keymaster = require('keymaster').noConflict();
Expand Down Expand Up @@ -30,20 +39,21 @@ module.exports = () => {
* @private
*/
init(opts = {}) {
config = opts;
defaults(config, configDef);
config = { ...opts, ...configDef };
this.em = config.em;
return this;
},

/**
* Add new keymap
* @param {string} id Keymap id
* @param {string} keys Keymap keys, eg. '⌘+z, ctrl+z'
* @param {string} keys Keymap keys, eg. `ctrl+a`, `⌘+z, ctrl+z`
* @param {Function|string} handler Keymap handler, might be a function
* @return {Object} Added keymap
* or just a command id as a string
* @example
* keymaps.add('ns:my-keymap', '⌘+s, ctrl+s', () => {
* // 'ns' is just a custom namespace
* keymaps.add('ns:my-keymap', '⌘+s, ctrl+s', editor => {
* console.log('do stuff');
* });
* // or
Expand All @@ -66,6 +76,7 @@ module.exports = () => {
em.trigger(`keymap:emit:${id}`, ...args);
});
em.trigger('keymap:add', keymap);
return keymap;
},


Expand All @@ -85,6 +96,9 @@ module.exports = () => {
/**
* Get all keymaps
* @return {Object}
* @example
* keymaps.getAll();
* // -> [{...}, {...}, ...];
*/
getAll() {
return keymaps;
Expand Down

0 comments on commit 73b9fd9

Please sign in to comment.