diff --git a/src/dom_components/view/ComponentsView.js b/src/dom_components/view/ComponentsView.js index e1158fd30..fd92caa9a 100644 --- a/src/dom_components/view/ComponentsView.js +++ b/src/dom_components/view/ComponentsView.js @@ -11,19 +11,24 @@ module.exports = Backbone.View.extend({ this.listenTo(coll, 'remove', this.removeChildren); }, - removeChildren(removed) { + removeChildren(removed, coll, opts = {}) { const em = this.config.em; const view = removed.view; - const temp = removed.opt.temporary; + const tempComp = removed.opt.temporary; + const tempRemove = opts.temporary; if (!view) return; view.remove.apply(view); const children = view.childrenView; children && children.stopListening(); - removed.components().forEach(this.removeChildren.bind(this)); - !temp && removed.removed(); - if (em) { - // Remove all related CSS rules + removed.components().forEach(it => this.removeChildren(it, coll, opts)); + + if (em && !tempRemove) { + // Remove the component from the global list const id = removed.getId(); + const domc = em.get('DomComponents'); + delete domc.componentsById[id]; + + // Remove all related CSS rules const allRules = em.get('CssComposer').getAll(); allRules.remove( allRules.filter( @@ -31,15 +36,14 @@ module.exports = Backbone.View.extend({ ) ); - // Remove the component from the global list - const domc = em.get('DomComponents'); - delete domc.componentsById[id]; - - removed.get('style-signature') && - em - .get('Commands') - .run('core:component-style-clear', { target: removed }); - !temp && em.trigger('component:remove', removed); + if (!tempComp) { + const cm = em.get('Commands'); + const hasSign = removed.get('style-signature'); + const optStyle = { target: removed }; + hasSign && cm.run('core:component-style-clear', optStyle); + removed.removed(); + em.trigger('component:remove', removed); + } } }, diff --git a/src/utils/Sorter.js b/src/utils/Sorter.js index 75d62210e..12362a946 100644 --- a/src/utils/Sorter.js +++ b/src/utils/Sorter.js @@ -320,10 +320,9 @@ module.exports = Backbone.View.extend({ const opts = { avoidStore: 1, avoidChildren: 1, - avoidUpdateStyle: 1, - temporary: 1 + avoidUpdateStyle: 1 }; - let tempModel = comps.add(dropContent, opts); + let tempModel = comps.add(dropContent, { ...opts, temporary: 1 }); dropModel = comps.remove(tempModel, opts); this.dropModel = dropModel instanceof Array ? dropModel[0] : dropModel; } @@ -995,7 +994,7 @@ module.exports = Backbone.View.extend({ modelTemp = targetCollection.add({}, { ...opts }); if (model) { - modelToDrop = model.collection.remove(model); + modelToDrop = model.collection.remove(model, { temporary: 1 }); } } else { modelToDrop = dropContent;