Browse Source

Add a few operation actions

pull/4134/head
Artur Arseniev 4 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'] = {
run(ed) {
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';
export default {
run(ed) {
run(ed, s, opts = {}) {
const em = ed.getModel();
const clp = em.get('clipboard');
const selected = ed.getSelected();
@ -14,15 +14,16 @@ export default {
if (!coll) return;
const at = coll.indexOf(comp) + 1;
const addOpts = { at, action: opts.action || 'paste-component' };
const copyable = clp.filter(cop => cop.get('copyable'));
let added;
if (contains(clp, comp) && comp.get('copyable')) {
added = coll.add(comp.clone(), { at });
added = coll.add(comp.clone(), addOpts);
} else {
added = coll.add(
copyable.map(cop => cop.clone()),
{ at }
addOpts
);
}
@ -32,5 +33,5 @@ export default {
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 coll = this.collection;
const remove = () => {
coll && coll.remove(this, opts);
coll && coll.remove(this, { ...opts, action: 'remove-component' });
opts.root && this.components('');
};
const rmOpts = { ...opts };

Loading…
Cancel
Save