Browse Source

Make init always via pages

pull/4223/head
Artur Arseniev 4 years ago
parent
commit
448d8e689b
  1. 2
      src/common/module.js
  2. 15
      src/dom_components/index.js
  3. 29
      src/editor/model/Editor.js
  4. 1
      src/pages/index.js

2
src/common/module.js

@ -28,7 +28,7 @@ export default {
}
if (onResult) {
onResult(result);
result && onResult(result);
} else if (result && result.length) {
(all || this.getAll()).reset(result);
}

15
src/dom_components/index.js

@ -272,21 +272,9 @@ export default () => {
em.listenTo(selected, 'remove', (sel, c, opts) => this.selectRemove(selected.getComponent(sel), opts));
}
if (em.get('hasPages')) {
c.components = '';
}
return this;
},
/**
* On load callback
* @private
*/
onLoad() {
c.components && this.setComponents(c.components, { silent: 1 });
},
load(data) {
return this.loadProjectData(data, {
onResult: result => {
@ -303,8 +291,7 @@ export default () => {
},
store() {
if (this.em.get('hasPages')) return {};
return this.getProjectData(this.getWrapper());
return {};
},
/**

29
src/editor/model/Editor.js

@ -1,4 +1,4 @@
import { isUndefined, isFunction, isArray, contains, toArray, keys, bindAll } from 'underscore';
import { isUndefined, isArray, contains, toArray, keys, bindAll } from 'underscore';
import Backbone from 'backbone';
import $ from 'utils/cash-dom';
import Extender from 'utils/extender';
@ -66,21 +66,23 @@ export default class EditorModel extends Model {
};
}
initialize(c = {}) {
this.config = c;
this.set('Config', c);
initialize(conf = {}) {
this.config = conf;
const { config } = this;
this.set('Config', config);
this.set('modules', []);
this.set('toLoad', []);
this.set('storables', []);
this.set('selected', new Selected());
this.set('dmode', c.dragMode);
this.set('hasPages', !!c.pageManager);
const el = c.el;
const log = c.log;
this.set('dmode', config.dragMode);
const { el, log } = config;
const toLog = log === true ? keys(logs) : isArray(log) ? log : [];
bindAll(this, 'initBaseColorPicker');
if (el && c.fromElement) this.config.components = el.innerHTML;
if (el && config.fromElement) {
config.components = el.innerHTML;
}
this.attrsOrig = el
? toArray(el.attributes).reduce((res, next) => {
res[next.nodeName] = next.nodeValue;
@ -88,6 +90,11 @@ export default class EditorModel extends Model {
}, {})
: '';
// Move components to pages
if (config.components && !config.pageManager) {
config.pageManager = { pages: [{ component: config.components }] };
}
// Load modules
deps.forEach(name => this.loadModule(name));
this.on('change:componentHovered', this.componentHovered, this);
@ -202,15 +209,13 @@ export default class EditorModel extends Model {
const name = Mod.name.charAt(0).toLowerCase() + Mod.name.slice(1);
const cfgParent = !isUndefined(config[name]) ? config[name] : config[Mod.name];
const cfg = cfgParent === true ? {} : cfgParent || {};
const sm = this.get('StorageManager');
cfg.pStylePrefix = config.pStylePrefix || '';
if (!isUndefined(cfgParent) && !cfgParent) {
cfg._disable = 1;
}
if (Mod.storageKey && Mod.store && Mod.load && sm) {
cfg.stm = sm;
if (Mod.storageKey && Mod.store && Mod.load) {
// DomComponents should be load before CSS Composer
const mth = name == 'domComponents' ? 'unshift' : 'push';
this.get('storables')[mth](Mod);

1
src/pages/index.js

@ -275,7 +275,6 @@ export default () => {
},
store() {
if (!this.em.get('hasPages')) return {};
return this.getProjectData();
},

Loading…
Cancel
Save