From 8c8e1f0ffddc26c4eaebd3b92046895906a56a8d Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Fri, 11 Mar 2022 14:51:08 +0100 Subject: [PATCH] Update project load --- src/common/module.js | 16 +++++++++++++--- src/dom_components/index.js | 1 + src/dom_components/model/Component.js | 6 +++++- src/editor/model/Editor.js | 6 +++--- src/pages/index.js | 3 ++- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/common/module.js b/src/common/module.js index 518774448..a45b4006b 100644 --- a/src/common/module.js +++ b/src/common/module.js @@ -15,8 +15,10 @@ export default { return obj; }, - loadProjectData(data = {}, { all, def = [], onResult } = {}) { + loadProjectData(data = {}, { all, def = [], onResult, reset } = {}) { const key = this.storageKey; + const opts = { action: 'load' }; + const coll = all || this.getAll(); let result = data[key] || def; if (typeof result == 'string') { @@ -27,15 +29,23 @@ export default { } } + reset && result && coll.reset(null, opts); + if (onResult) { - result && onResult(result); + result && onResult(result, opts); } else if (result && result.length) { - (all || this.getAll()).reset(result); + coll.reset(result, opts); } return result; }, + clear(opts = {}) { + const { all } = this; + all && all.reset(null, opts); + return this; + }, + __getConfig(name) { const res = this.config || {}; return name ? res[name] : res; diff --git a/src/dom_components/index.js b/src/dom_components/index.js index 7674e8dd2..49ea8df0b 100644 --- a/src/dom_components/index.js +++ b/src/dom_components/index.js @@ -277,6 +277,7 @@ export default () => { load(data) { return this.loadProjectData(data, { + def: null, onResult: result => { const wrapper = this.getWrapper(); if (isArray(result)) { diff --git a/src/dom_components/model/Component.js b/src/dom_components/model/Component.js index eb6853247..316f81648 100644 --- a/src/dom_components/model/Component.js +++ b/src/dom_components/model/Component.js @@ -1677,7 +1677,11 @@ export default class Component extends Model.extend(Styleable) { const coll = this.collection; const remove = () => { coll && coll.remove(this, { ...opts, action: 'remove-component' }); - opts.root && this.components(''); + // Component without parent + if (!coll) { + this.components('', opts); + this.components().removeChildren(this, null, opts); + } }; const rmOpts = { ...opts }; [this, em].map(i => i.trigger('component:remove:before', this, remove, rmOpts)); diff --git a/src/editor/model/Editor.js b/src/editor/model/Editor.js index b50a191bb..a2e0cd462 100644 --- a/src/editor/model/Editor.js +++ b/src/editor/model/Editor.js @@ -217,8 +217,8 @@ export default class EditorModel extends Model { } if (Mod.storageKey && Mod.store && Mod.load) { - // DomComponents should be load before CSS Composer - const mth = name == 'domComponents' ? 'unshift' : 'push'; + // Components should be loaded before CSS due to reset + const mth = ['domComponents', 'pageManager'].indexOf(name) >= 0 ? 'unshift' : 'push'; this.get('storables')[mth](Mod); } @@ -629,7 +629,7 @@ export default class EditorModel extends Model { */ async load(options) { const result = await this.get('StorageManager').load(options); - this.loadData(result); + this.skip(() => this.loadData(result)); return result; } diff --git a/src/pages/index.js b/src/pages/index.js index b7fc32ccc..f69b867cb 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -98,6 +98,7 @@ export default () => { this.em = em; const pages = new Pages([], cnf); this.pages = pages; + this.all = pages; const model = new Model({ _undo: true }); this.model = model; pages.on('add', (p, c, o) => em.trigger(evPageAdd, p, o)); @@ -279,7 +280,7 @@ export default () => { }, load(data) { - return this.loadProjectData(data, { all: this.pages }); + return this.loadProjectData(data, { all: this.pages, reset: true, def: null }); }, _createId() {