Browse Source

Add a few operation actions

pull/4134/head
Artur Arseniev 5 years ago
parent
commit
ceb082f050
  1. 2
      src/commands/index.js
  2. 9
      src/commands/view/PasteComponent.js
  3. 2
      src/dom_components/model/Component.js

2
src/commands/index.js

@ -130,7 +130,7 @@ export default () => {
defaultCommands['tlb-clone'] = { defaultCommands['tlb-clone'] = {
run(ed) { run(ed) {
ed.runCommand('core:copy'); ed.runCommand('core:copy');
ed.runCommand('core:paste'); ed.runCommand('core:paste', { action: 'clone-component' });
}, },
}; };

9
src/commands/view/PasteComponent.js

@ -1,7 +1,7 @@
import { isArray, contains } from 'underscore'; import { isArray, contains } from 'underscore';
export default { export default {
run(ed) { run(ed, s, opts = {}) {
const em = ed.getModel(); const em = ed.getModel();
const clp = em.get('clipboard'); const clp = em.get('clipboard');
const selected = ed.getSelected(); const selected = ed.getSelected();
@ -14,15 +14,16 @@ export default {
if (!coll) return; if (!coll) return;
const at = coll.indexOf(comp) + 1; const at = coll.indexOf(comp) + 1;
const addOpts = { at, action: opts.action || 'paste-component' };
const copyable = clp.filter(cop => cop.get('copyable')); const copyable = clp.filter(cop => cop.get('copyable'));
let added; let added;
if (contains(clp, comp) && comp.get('copyable')) { if (contains(clp, comp) && comp.get('copyable')) {
added = coll.add(comp.clone(), { at }); added = coll.add(comp.clone(), addOpts);
} else { } else {
added = coll.add( added = coll.add(
copyable.map(cop => cop.clone()), copyable.map(cop => cop.clone()),
{ at } addOpts
); );
} }
@ -32,5 +33,5 @@ export default {
selected.emitUpdate(); selected.emitUpdate();
} }
} },
}; };

2
src/dom_components/model/Component.js

@ -1686,7 +1686,7 @@ export default class Component extends Model.extend(Styleable) {
const { em } = this; const { em } = this;
const coll = this.collection; const coll = this.collection;
const remove = () => { const remove = () => {
coll && coll.remove(this, opts); coll && coll.remove(this, { ...opts, action: 'remove-component' });
opts.root && this.components(''); opts.root && this.components('');
}; };
const rmOpts = { ...opts }; const rmOpts = { ...opts };

Loading…
Cancel
Save