|
|
|
@ -11,84 +11,10 @@ import UndoManager from 'backbone-undo'; |
|
|
|
|
|
|
|
module.exports = () => { |
|
|
|
let em; |
|
|
|
let config; |
|
|
|
let um; |
|
|
|
let config; |
|
|
|
let beforeCache; |
|
|
|
const configDef = {}; |
|
|
|
const keymaps = {}; |
|
|
|
|
|
|
|
/* |
|
|
|
const canvas = this.get('Canvas'); |
|
|
|
|
|
|
|
if (this.um) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
var cmp = this.get('DomComponents'); |
|
|
|
if(cmp && this.config.undoManager) { |
|
|
|
var that = this; |
|
|
|
this.um = new UndoManager({ |
|
|
|
register: [cmp.getComponents(), this.get('CssComposer').getAll()], |
|
|
|
track: true |
|
|
|
}); |
|
|
|
this.UndoManager = this.um; |
|
|
|
this.set('UndoManager', this.um); |
|
|
|
|
|
|
|
key('⌘+z, ctrl+z', () => { |
|
|
|
if (canvas.isInputFocused()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
that.um.undo(true); |
|
|
|
that.trigger('component:update'); |
|
|
|
}); |
|
|
|
|
|
|
|
key('⌘+shift+z, ctrl+shift+z', () => { |
|
|
|
if (canvas.isInputFocused()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
that.um.redo(true); |
|
|
|
that.trigger('component:update'); |
|
|
|
}); |
|
|
|
|
|
|
|
var beforeCache; |
|
|
|
const customUndoType = { |
|
|
|
on: function (model, value, opts) { |
|
|
|
var opt = opts || {}; |
|
|
|
if(!beforeCache){ |
|
|
|
beforeCache = model.previousAttributes(); |
|
|
|
} |
|
|
|
if (opt && opt.avoidStore) { |
|
|
|
return; |
|
|
|
} else { |
|
|
|
var obj = { |
|
|
|
object: model, |
|
|
|
before: beforeCache, |
|
|
|
after: model.toJSON() |
|
|
|
}; |
|
|
|
beforeCache = null; |
|
|
|
return obj; |
|
|
|
} |
|
|
|
}, |
|
|
|
undo: function (model, bf, af, opt) { |
|
|
|
model.set(bf); |
|
|
|
// Update also inputs inside Style Manager
|
|
|
|
that.trigger('change:selectedComponent'); |
|
|
|
}, |
|
|
|
redo: function (model, bf, af, opt) { |
|
|
|
model.set(af); |
|
|
|
// Update also inputs inside Style Manager
|
|
|
|
that.trigger('change:selectedComponent'); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
UndoManager.removeUndoType("change"); |
|
|
|
UndoManager.addUndoType("change:style", customUndoType); |
|
|
|
UndoManager.addUndoType("change:attributes", customUndoType); |
|
|
|
UndoManager.addUndoType("change:content", customUndoType); |
|
|
|
UndoManager.addUndoType("change:src", customUndoType); |
|
|
|
} |
|
|
|
*/ |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
@ -105,12 +31,6 @@ module.exports = () => { |
|
|
|
em = config.em; |
|
|
|
this.em = em; |
|
|
|
um = new UndoManager({ track: true, register: [] }); |
|
|
|
um.changeUndoType('change', { condition: false }); |
|
|
|
const updated = () => { |
|
|
|
em.trigger('change:selectedComponent'); |
|
|
|
em.trigger('change:canvasOffset'); |
|
|
|
console.log('updated'); |
|
|
|
}; |
|
|
|
const customUndoType = { |
|
|
|
on(object, value, opt = {}) { |
|
|
|
!beforeCache && (beforeCache = object.previousAttributes()); |
|
|
|
@ -130,17 +50,17 @@ module.exports = () => { |
|
|
|
|
|
|
|
undo(model, bf, af, opt) { |
|
|
|
model.set(bf); |
|
|
|
updated(); |
|
|
|
}, |
|
|
|
|
|
|
|
redo(model, bf, af, opt) { |
|
|
|
model.set(af); |
|
|
|
updated(); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
const events = ['style', 'attributes', 'content', 'src']; |
|
|
|
events.forEach(ev => um.addUndoType(`change:${ev}`, customUndoType)); |
|
|
|
um.changeUndoType('change', { condition: false }); |
|
|
|
um.on('undo redo', () => em.trigger('change:selectedComponent change:canvasOffset')); |
|
|
|
|
|
|
|
return this; |
|
|
|
}, |
|
|
|
@ -156,7 +76,7 @@ module.exports = () => { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Add an entity (Model/Collection) to track changes |
|
|
|
* Add an entity (Model/Collection) to track |
|
|
|
* @param {Model|Collection} entity Entity to track |
|
|
|
*/ |
|
|
|
add(entity) { |
|
|
|
|