UNPKG

drapcode-builder

Version:

Drapcode Builder Library

45 lines (39 loc) 1.53 kB
import { isArray } from "underscore"; export default { run(ed, sender, opts = {}) { let components = opts.component || ed.getSelectedAll(); components = isArray(components) ? [...components] : [components]; /* ** Do not Delete Component if it's the only main component on a page */ let parentComponent = ""; let pageComponents = ed.getComponents(); if (pageComponents && pageComponents.length == 1) { let pageComponent = ed.getSelected(); parentComponent = pageComponent ? pageComponent.parent() : ""; if (parentComponent && !parentComponent.collection) { alert( "Alert! The removal of the main component from a page is currently restricted.\n\nPlease click the Clear icon on the top bar if you like to Clear the page content." ); return this.em.logWarning( "Alert! The removal of the main component from a page is currently restricted.\n\nPlease click the Clear icon on the top bar if you like to Clear the page content.", { component: pageComponent } ); } } // It's important to deselect components first otherwise, // with undo, the component will be set with the wrong `collection` ed.select(null); components.forEach(component => { if (!component || !component.get("removable")) { return this.em.logWarning("The element is not removable", { component }); } component.remove(); }); return components; } };