Browse Source

Add the possibility to preventDefault from `add` method, in Keymaps module

pull/1800/head
Artur Arseniev 7 years ago
parent
commit
f5e56d9a6e
  1. 1187
      dist/grapes.js
  2. 8
      dist/grapes.min.js
  3. 2
      dist/grapes.min.js.map
  4. 2
      package-lock.json
  5. 2
      package.json
  6. 10
      src/keymaps/index.js

1187
dist/grapes.js

File diff suppressed because it is too large

8
dist/grapes.min.js

File diff suppressed because one or more lines are too long

2
dist/grapes.min.js.map

File diff suppressed because one or more lines are too long

2
package-lock.json

@ -1,6 +1,6 @@
{
"name": "grapesjs",
"version": "0.14.52",
"version": "0.14.53",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

2
package.json

@ -1,7 +1,7 @@
{
"name": "grapesjs",
"description": "Free and Open Source Web Builder Framework",
"version": "0.14.52",
"version": "0.14.53",
"author": "Artur Arseniev",
"license": "BSD-3-Clause",
"homepage": "http://grapesjs.com",

10
src/keymaps/index.js

@ -119,6 +119,7 @@ module.exports = () => {
* @param {string} id Keymap id
* @param {string} keys Keymap keys, eg. `ctrl+a`, `⌘+z, ctrl+z`
* @param {Function|string} handler Keymap handler, might be a function
* @param {Object} [opts={}] Options
* @return {Object} Added keymap
* or just a command id as a string
* @example
@ -134,7 +135,7 @@ module.exports = () => {
* // ...
* })
*/
add(id, keys, handler) {
add(id, keys, handler, opts = {}) {
const em = this.em;
const editor = em.getEditor();
const cmd = em.get('Commands');
@ -145,9 +146,12 @@ module.exports = () => {
keymaps[id] = keymap;
keymaster(keys, (e, h) => {
// It's safer putting handlers resolution inside the callback
const opt = { event: e, h };
handler = isString(handler) ? cmd.get(handler) : handler;
!handler.avoidPrevent && canvas.getCanvasView().preventDefault(e);
typeof handler == 'object' ? handler.run(editor) : handler(editor);
opts.prevent && canvas.getCanvasView().preventDefault(e);
typeof handler == 'object'
? handler.run(editor, 0, opt)
: handler(editor, 0, opt);
const args = [id, h.shortcut, e];
em.trigger('keymap:emit', ...args);
em.trigger(`keymap:emit:${id}`, ...args);

Loading…
Cancel
Save