grapesjs_codeapps
Version:
Free and Open Source Web Builder Framework/SC Modification
131 lines (86 loc) • 2.25 kB
Markdown
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
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
```js
const keymaps = editor.Keymaps;
```
- [getConfig][1]
- [add][2]
- [get][3]
- [getAll][4]
- [remove][5]
Get module configurations
Returns **[Object][6]** Configuration object
Add new keymap
- `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
```javascript
// 'ns' is just a custom namespace
keymaps.add('ns:my-keymap', '⌘+j, ⌘+u, ctrl+j, alt+u', editor => {
console.log('do stuff');
});
// or
keymaps.add('ns:my-keymap', '⌘+s, ctrl+s', 'some-gjs-command');
// listen to events
editor.on('keymap:emit', (id, shortcut, e) => {
// ...
})
```
Returns **[Object][6]** Added keymap
or just a command id as a string
Get the keymap by id
- `id` **[string][7]** Keymap id
```javascript
keymaps.get('ns:my-keymap');
// -> {keys, handler};
```
Returns **[Object][6]** Keymap object
Get all keymaps
```javascript
keymaps.getAll();
// -> {id1: {}, id2: {}};
```
Returns **[Object][6]**
Remove the keymap by id
- `id` **[string][7]** Keymap id
```javascript
keymaps.remove('ns:my-keymap');
// -> {keys, handler};
```
Returns **[Object][6]** Removed keymap
[]:
[]:
[]:
[]:
[]:
[]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function