Browse Source

Make init always via pages

pull/4223/head
Artur Arseniev 5 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) { if (onResult) {
onResult(result); result && onResult(result);
} else if (result && result.length) { } else if (result && result.length) {
(all || this.getAll()).reset(result); (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)); em.listenTo(selected, 'remove', (sel, c, opts) => this.selectRemove(selected.getComponent(sel), opts));
} }
if (em.get('hasPages')) {
c.components = '';
}
return this; return this;
}, },
/**
* On load callback
* @private
*/
onLoad() {
c.components && this.setComponents(c.components, { silent: 1 });
},
load(data) { load(data) {
return this.loadProjectData(data, { return this.loadProjectData(data, {
onResult: result => { onResult: result => {
@ -303,8 +291,7 @@ export default () => {
}, },
store() { store() {
if (this.em.get('hasPages')) return {}; return {};
return this.getProjectData(this.getWrapper());
}, },
/** /**

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

1
src/pages/index.js

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

Loading…
Cancel
Save