Browse Source

Update project load

pull/4223/head
Artur Arseniev 4 years ago
parent
commit
8c8e1f0ffd
  1. 16
      src/common/module.js
  2. 1
      src/dom_components/index.js
  3. 6
      src/dom_components/model/Component.js
  4. 6
      src/editor/model/Editor.js
  5. 3
      src/pages/index.js

16
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;

1
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)) {

6
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));

6
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;
}

3
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() {

Loading…
Cancel
Save