diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index 501d464ec..20205abee 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -66,6 +66,7 @@ module.exports = { ['/api/css_composer', 'CSS Composer'], ['/api/modal_dialog', 'Modal'], ['/api/rich_text_editor', 'Rich Text Editor'], + ['/api/keymaps', 'Keymaps'], ], '/': [ '', diff --git a/docs/api.js b/docs/api.js index d06807768..d60d356ed 100644 --- a/docs/api.js +++ b/docs/api.js @@ -17,10 +17,9 @@ const cmds = [ // ['selector_manager/index.js', 'selector_manager.md'], // ['css_composer/index.js', 'css_composer.md'], // ['modal_dialog/index.js', 'modal_dialog.md'], - ['rich_text_editor/index.js', 'rich_text_editor.md'], - /* - ['rich_text_editor/index.js', 'rich_text_editor.md'], + // ['rich_text_editor/index.js', 'rich_text_editor.md'], ['keymaps/index.js', 'keymaps.md'], + /* ['undo_manager/index.js', 'undo_manager.md'],*/ ].map(entry => `${binRoot}documentation build ${srcRoot}/${entry[0]} -o ${docRoot}/api/${entry[1]} -f md --shallow --markdown-toc false`) diff --git a/docs/api/keymaps.md b/docs/api/keymaps.md index e5887df02..d19e6bdac 100644 --- a/docs/api/keymaps.md +++ b/docs/api/keymaps.md @@ -1,20 +1,41 @@ -## isString +## Keymaps -This module allows to create shortcuts for functions and commands (via command id) +You can customize the initial state of the module from the editor initialization -You can access the module in this way +```js +const editor = grapesjs.init({ + keymaps: { + // Object of keymaps + defaults: { + 'your-namespace:keymap-name' { + keys: '⌘+z, ctrl+z', + handler: 'some-command-id' + }, + ... + } + } +}) +``` + +Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance ```js const keymaps = editor.Keymaps; ``` +- [getConfig][1] +- [add][2] +- [get][3] +- [getAll][4] +- [remove][5] + ## getConfig Get module configurations -Returns **[Object][1]** Configuration object +Returns **[Object][6]** Configuration object ## add @@ -22,9 +43,9 @@ Add new keymap ### Parameters -- `id` **[string][2]** Keymap id -- `keys` **[string][2]** Keymap keys, eg. `ctrl+a`, `⌘+z, ctrl+z` -- `handler` **([Function][3] \| [string][2])** Keymap handler, might be a function +- `id` **[string][7]** Keymap id +- `keys` **[string][7]** Keymap keys, eg. `ctrl+a`, `⌘+z, ctrl+z` +- `handler` **([Function][8] \| [string][7])** Keymap handler, might be a function ### Examples @@ -42,7 +63,7 @@ editor.on('keymap:emit', (id, shortcut, e) => { }) ``` -Returns **[Object][1]** Added keymap +Returns **[Object][6]** Added keymap or just a command id as a string ## get @@ -51,7 +72,7 @@ Get the keymap by id ### Parameters -- `id` **[string][2]** Keymap id +- `id` **[string][7]** Keymap id ### Examples @@ -60,7 +81,7 @@ keymaps.get('ns:my-keymap'); // -> {keys, handler}; ``` -Returns **[Object][1]** Keymap object +Returns **[Object][6]** Keymap object ## getAll @@ -73,7 +94,7 @@ keymaps.getAll(); // -> {id1: {}, id2: {}}; ``` -Returns **[Object][1]** +Returns **[Object][6]** ## remove @@ -81,7 +102,7 @@ Remove the keymap by id ### Parameters -- `id` **[string][2]** Keymap id +- `id` **[string][7]** Keymap id ### Examples @@ -90,10 +111,20 @@ keymaps.remove('ns:my-keymap'); // -> {keys, handler}; ``` -Returns **[Object][1]** Removed keymap +Returns **[Object][6]** Removed keymap + +[1]: #getconfig + +[2]: #add + +[3]: #get + +[4]: #getAll + +[5]: #remove -[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object +[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object -[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String +[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String -[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function +[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function diff --git a/src/keymaps/index.js b/src/keymaps/index.js index 32ae7b9dd..7b677275a 100644 --- a/src/keymaps/index.js +++ b/src/keymaps/index.js @@ -1,12 +1,35 @@ /** - * This module allows to create shortcuts for functions and commands (via command id) + * You can customize the initial state of the module from the editor initialization + * ```js + * const editor = grapesjs.init({ + * keymaps: { + * // Object of keymaps + * defaults: { + * 'your-namespace:keymap-name' { + * keys: '⌘+z, ctrl+z', + * handler: 'some-command-id' + * }, + * ... + * } + * } + * }) + * ``` + * + * Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance * - * You can access the module in this way * ```js * const keymaps = editor.Keymaps; * ``` * + * * [getConfig](#getconfig) + * * [add](#add) + * * [get](#get) + * * [getAll](#getAll) + * * [remove](#remove) + * + * @module Keymaps */ + import { isString } from 'underscore'; const keymaster = require('keymaster');