Free and Open source Web Builder Framework. Next generation tool for building templates without coding
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

36 lines
890 B

import { isArray, contains } from 'underscore';
export default {
run(ed) {
const em = ed.getModel();
const clp = em.get('clipboard');
const selected = ed.getSelected();
if (clp && selected) {
ed.getSelectedAll().forEach(comp => {
if (!comp) return;
const coll = comp.collection;
if (!coll) return;
const at = coll.indexOf(comp) + 1;
const copyable = clp.filter(cop => cop.get('copyable'));
let added;
if (contains(clp, comp) && comp.get('copyable')) {
added = coll.add(comp.clone(), { at });
} else {
added = coll.add(
copyable.map(cop => cop.clone()),
{ at }
);
}
added = isArray(added) ? added : [added];
added.forEach(add => ed.trigger('component:paste', add));
});
selected.emitUpdate();
}
}
};