From 1ef52c4d7db070c290d576613f418cd0e9ca6b6a Mon Sep 17 00:00:00 2001 From: Vlad Florescu Date: Tue, 25 Jul 2017 17:34:46 +0300 Subject: [PATCH 1/4] update store when changing component attributes --- src/editor/model/Editor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/editor/model/Editor.js b/src/editor/model/Editor.js index a6f9f80b1..75252ceff 100644 --- a/src/editor/model/Editor.js +++ b/src/editor/model/Editor.js @@ -276,7 +276,7 @@ module.exports = Backbone.Model.extend({ this.stopListening(classes, 'add remove', this.componentsUpdated); this.listenTo(classes, 'add remove', this.componentsUpdated); - var evn = 'change:style change:content'; + var evn = 'change:style change:content change:attributes'; this.stopListening(model, evn, this.componentsUpdated); this.listenTo(model, evn, this.componentsUpdated); From 6e1952b62b23d66818cd530dbceae309dbdf9d62 Mon Sep 17 00:00:00 2001 From: thecodefish Date: Thu, 3 Aug 2017 14:58:59 +1200 Subject: [PATCH 2/4] Temporarily adding components via the Sorter no longer triggers add/change events Utils/Sorter will temporarily add a component to the collection in order to capture its properties, then remove it immediately. This triggers the component:add, component:remove, and change:changesCount events (and possibly others). The temporary addition/removal now includes an option flag 'temporary' which can be used in event handlers to detect this scenario. In addition, the editor.componentsUpdated handler performs the same check which prevents updating the changesCount as well as updating storage. --- src/editor/model/Editor.js | 10 ++++++++-- src/utils/Sorter.js | 4 ++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/editor/model/Editor.js b/src/editor/model/Editor.js index a6f9f80b1..431076262 100644 --- a/src/editor/model/Editor.js +++ b/src/editor/model/Editor.js @@ -161,6 +161,12 @@ module.exports = Backbone.Model.extend({ * @private * */ componentsUpdated(model, val, opt) { + var temp = opt ? opt.temporary : 0; + if (temp) { + //component has been added temporarily - do not update storage or record changes + return; + } + timedInterval && clearInterval(timedInterval); timedInterval = setTimeout(() => { var count = this.get('changesCount') + 1; @@ -281,7 +287,7 @@ module.exports = Backbone.Model.extend({ this.listenTo(model, evn, this.componentsUpdated); if(!avSt) - this.componentsUpdated(); + this.componentsUpdated(model, val, opt); }, /** @@ -310,7 +316,7 @@ module.exports = Backbone.Model.extend({ var avSt = opt ? opt.avoidStore : 0; if(!avSt) - this.componentsUpdated(); + this.componentsUpdated(model, val, opt); }, /** diff --git a/src/utils/Sorter.js b/src/utils/Sorter.js index ae4f762a2..494518436 100644 --- a/src/utils/Sorter.js +++ b/src/utils/Sorter.js @@ -283,8 +283,8 @@ module.exports = Backbone.View.extend({ if (dropContent && em) { if (!dropModel) { let comps = em.get('DomComponents').getComponents(); - let tempModel = comps.add(dropContent, {avoidUpdateStyle: 1}); - dropModel = comps.remove(tempModel); + let tempModel = comps.add(dropContent, {avoidUpdateStyle: 1, temporary: 1}); + dropModel = comps.remove(tempModel, {temporary: 1}); this.dropModel = dropModel instanceof Array ? dropModel[0] : dropModel; } return dropModel; From 61ac543cdc7e07dac27841f575c95ca8ba3799f3 Mon Sep 17 00:00:00 2001 From: Steven Gonzalez Date: Sat, 5 Aug 2017 13:17:15 -0400 Subject: [PATCH 3/4] Adding remove function to Blocks manager --- src/block_manager/index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/block_manager/index.js b/src/block_manager/index.js index a0af59eec..194145235 100644 --- a/src/block_manager/index.js +++ b/src/block_manager/index.js @@ -135,6 +135,14 @@ module.exports = () => { return view.render().el; }, + /** + * Remove block by id + * @param {string} id Block id + */ + remove(id) { + return blocks.remove(id); + }, + }; }; From b583ec89aed8e65feff429953502685e74807f9f Mon Sep 17 00:00:00 2001 From: Steven Gonzalez Date: Sat, 5 Aug 2017 14:06:31 -0400 Subject: [PATCH 4/4] Updating openAssetManager function in PropertyFileView to utilize open-assets command --- src/style_manager/view/PropertyFileView.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/style_manager/view/PropertyFileView.js b/src/style_manager/view/PropertyFileView.js index 28598bf10..df6c4bac1 100644 --- a/src/style_manager/view/PropertyFileView.js +++ b/src/style_manager/view/PropertyFileView.js @@ -120,15 +120,20 @@ module.exports = PropertyView.extend({ * */ openAssetManager(e) { var that = this; - if(this.modal && this.am){ + var em = this.em; + var editor = em ? em.get('Editor') : ''; + + if(editor) { this.modal.setTitle('Select image'); this.modal.setContent(this.am.render()); this.am.setTarget(null); - this.modal.open(); - this.am.onSelect(model => { - that.modal.close(); - that.spreadUrl(model.get('src')); - that.valueChanged(e); + editor.runCommand('open-assets', { + target: this.model, + onSelect(target) { + that.modal.close(); + that.spreadUrl(target.get('src')); + that.valueChanged(e); + } }); } },