|
|
|
@ -304,70 +304,6 @@ export default () => { |
|
|
|
c.components && this.setComponents(c.components); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Do stuff after load |
|
|
|
* @param {Editor} em |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
postLoad(em) { |
|
|
|
this.handleChanges(this.getWrapper(), null, { avoidStore: 1 }); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Handle component changes |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
handleChanges(model, value, opts = {}) { |
|
|
|
const comps = model.components(); |
|
|
|
const um = em.get('UndoManager'); |
|
|
|
const handleUpdates = em.handleUpdates.bind(em); |
|
|
|
const handleChanges = this.handleChanges.bind(this); |
|
|
|
const handleChangesColl = this.handleChangesColl.bind(this); |
|
|
|
const handleRemoves = this.handleRemoves.bind(this); |
|
|
|
um && um.add(model); |
|
|
|
um && comps && um.add(comps); |
|
|
|
const evn = 'change:style change:content change:attributes change:src'; |
|
|
|
|
|
|
|
[ |
|
|
|
[model, evn, handleUpdates], |
|
|
|
[model, 'change:components', handleChangesColl], |
|
|
|
[comps, 'add', handleChanges], |
|
|
|
[comps, 'remove reset', handleRemoves], |
|
|
|
[model.get('classes'), 'add remove', handleUpdates] |
|
|
|
].forEach(els => { |
|
|
|
em.stopListening(els[0], els[1], els[2]); |
|
|
|
em.listenTo(els[0], els[1], els[2]); |
|
|
|
}); |
|
|
|
|
|
|
|
!opts.avoidStore && handleUpdates('', '', opts); |
|
|
|
comps.each(model => this.handleChanges(model, value, opts)); |
|
|
|
}, |
|
|
|
|
|
|
|
handleChangesColl(model, coll) { |
|
|
|
const um = em.get('UndoManager'); |
|
|
|
if (um && coll instanceof Backbone.Collection) { |
|
|
|
const handleChanges = this.handleChanges.bind(this); |
|
|
|
const handleRemoves = this.handleRemoves.bind(this); |
|
|
|
um.add(coll); |
|
|
|
[ |
|
|
|
[coll, 'add', handleChanges], |
|
|
|
[coll, 'remove reset', handleRemoves] |
|
|
|
].forEach(els => { |
|
|
|
em.stopListening(els[0], els[1], els[2]); |
|
|
|
em.listenTo(els[0], els[1], els[2]); |
|
|
|
}); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Triggered when some component is removed |
|
|
|
* @private |
|
|
|
* */ |
|
|
|
handleRemoves(m, value, opt) { |
|
|
|
const opts = opt || value; // in case of reset
|
|
|
|
em.handleUpdates(m, value, opts); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Load components from the passed object, if the object is empty will try to fetch them |
|
|
|
* autonomously from the selected storage |
|
|
|
|