Browse Source

Create `core:copy` and `core:paste`, commands and keymaps

pull/663/head
Artur Arseniev 9 years ago
parent
commit
c4c472ea32
  1. 22
      src/commands/index.js
  2. 8
      src/commands/view/SelectComponent.js
  3. 1
      src/editor/index.js
  4. 1
      src/grapesjs/index.js
  5. 8
      src/keymaps/index.js

22
src/commands/index.js

@ -41,6 +41,7 @@
import { isFunction } from 'underscore';
module.exports = () => {
let em;
var c = {},
commands = {},
defaultCommands = {},
@ -78,7 +79,7 @@ module.exports = () => {
if (!(name in c))
c[name] = defaults[name];
}
em = c.em;
var ppfx = c.pStylePrefix;
if(ppfx)
c.stylePrefix = ppfx + c.stylePrefix;
@ -206,6 +207,25 @@ module.exports = () => {
e.DomComponents.clear();
e.CssComposer.clear();
};
defaultCommands['core:copy'] = ed => {
const em = ed.getModel();
const model = ed.getSelected();
if (model && model.get('copyable') && !ed.Canvas.isInputFocused()) {
em.set('clipboard', model);
}
};
defaultCommands['core:paste'] = ed => {
const em = ed.getModel();
const clp = em.get('clipboard');
const model = ed.getSelected();
const coll = model && model.collection;
if (coll && clp && !ed.Canvas.isInputFocused()) {
const at = coll.indexOf(model) + 1;
coll.add(clp.clone(), { at });
}
};
if(c.em)
c.model = c.em.get('Canvas');

8
src/commands/view/SelectComponent.js

@ -11,8 +11,7 @@ const $ = Backbone.$;
module.exports = {
init(o) {
bindAll(this, 'onHover', 'onOut', 'onClick', 'onKeyPress',
'copyComp', 'pasteComp', 'onFrameScroll');
bindAll(this, 'onHover', 'onOut', 'onClick', 'onKeyPress', 'onFrameScroll');
},
@ -20,7 +19,6 @@ module.exports = {
this.frameOff = this.canvasOff = this.adjScroll = null;
var config = this.config.em.get('Config');
this.startSelectComponent();
this.toggleClipboard(config.copyPaste);
var em = this.config.em;
showOffsets = 1;
@ -35,6 +33,7 @@ module.exports = {
* @private
*/
toggleClipboard(active) {
/*
var en = active || 0;
if(en){
key('⌘+c, ctrl+c', this.copyComp);
@ -42,7 +41,7 @@ module.exports = {
}else{
key.unbind('⌘+c, ctrl+c');
key.unbind('⌘+v, ctrl+v');
}
}*/
},
/**
@ -580,7 +579,6 @@ module.exports = {
this.stopSelectComponent();
!opts.preserveSelected && em.setSelected(null);
this.clean();
this.toggleClipboard();
this.hideBadge();
this.hideFixedElementOffset();
this.canvas.getToolbarEl().style.display = 'none';

1
src/editor/index.js

@ -60,7 +60,6 @@
* @param {string|Array<Object>} [config.components=''] HTML string or object of components
* @param {string|Array<Object>} [config.style=''] CSS string or object of rules
* @param {Boolean} [config.fromElement=false] If true, will fetch HTML and CSS from selected container
* @param {Boolean} [config.copyPaste=true] Enable/Disable the possibility to copy(ctrl + c) & paste(ctrl + v) components
* @param {Boolean} [config.undoManager=true] Enable/Disable undo manager
* @param {Boolean} [config.autorender=true] If true renders editor on init
* @param {Boolean} [config.noticeOnUnload=true] Enable/Disable alert message before unload the page

1
src/grapesjs/index.js

@ -26,7 +26,6 @@ module.exports = (() => {
* @param {Object|string} config.components='' HTML string or Component model in JSON format
* @param {Object|string} config.style='' CSS string or CSS model in JSON format
* @param {Boolean} [config.fromElement=false] If true, will fetch HTML and CSS from selected container
* @param {Boolean} [config.copyPaste=true] Enable/Disable the possibility to copy(ctrl+c) & paste(ctrl+v) components
* @param {Boolean} [config.undoManager=true] Enable/Disable undo manager
* @param {Array} [config.plugins=[]] Array of plugins to execute on start
* @return {grapesjs.Editor} GrapesJS editor instance

8
src/keymaps/index.js

@ -24,6 +24,14 @@ module.exports = () => {
'core:redo': {
keys: '⌘+shift+z, ctrl+shift+z',
handler: 'core:redo',
},
'core:copy': {
keys: '⌘+c, ctrl+c',
handler: 'core:copy',
},
'core:paste': {
keys: '⌘+v, ctrl+v',
handler: 'core:paste',
}
}
};

Loading…
Cancel
Save