Browse Source

Add getGroupedStack to UndoManager

pull/4134/head
Artur Arseniev 5 years ago
parent
commit
bc9853b5aa
  1. 41
      src/undo_manager/index.js
  2. 4
      src/utils/Sorter.js

41
src/undo_manager/index.js

@ -25,7 +25,7 @@
*/ */
import UndoManager from 'backbone-undo'; import UndoManager from 'backbone-undo';
import { isArray, isBoolean, isEmpty } from 'underscore'; import { isArray, isBoolean, isEmpty, unique } from 'underscore';
export default () => { export default () => {
let em; let em;
@ -316,24 +316,39 @@ export default () => {
this.start(); this.start();
}, },
__getStackRead() { getGroupedStack() {
const result = {}; const result = {};
const stack = this.getStack();
const createItem = item => { const createItem = item => {
const { type, after, before, object } = item.attributes; const { type, after, before, object, options = {} } = item.attributes;
return { return { type, after, before, object, options };
type,
after,
before,
object,
};
}; };
this.getStack().forEach(item => { stack.forEach(item => {
const index = item.get('magicFusionIndex'); const index = item.get('magicFusionIndex');
const value = createItem(item); const value = createItem(item);
if (!result[index]) result[index] = [value];
else result[index].push(value); if (!result[index]) {
result[index] = [value];
} else {
result[index].push(value);
}
});
return Object.keys(result).map(index => {
const actions = result[index];
return {
// index: stack.models.indexOf(actions[0]),
index,
actions,
labels: unique(
actions.reduce((res, item) => {
const label = item.options?.action;
label && res.push(label);
return res;
}, [])
),
};
}); });
return Object.keys(result).map(i => result[i]);
}, },
getPointer() { getPointer() {

4
src/utils/Sorter.js

@ -1064,7 +1064,7 @@ export default Backbone.View.extend({
let modelToDrop, created; let modelToDrop, created;
if (targetCollection && droppable && draggable) { if (targetCollection && droppable && draggable) {
const opts = { at: index, undoContext: 'move-component' }; const opts = { at: index, action: 'move-component' };
if (!dropContent) { if (!dropContent) {
const srcIndex = srcModel.index(); const srcIndex = srcModel.index();
@ -1077,7 +1077,7 @@ export default Backbone.View.extend({
} else { } else {
modelToDrop = isFunction(dropContent) ? dropContent() : dropContent; modelToDrop = isFunction(dropContent) ? dropContent() : dropContent;
opts.avoidUpdateStyle = true; opts.avoidUpdateStyle = true;
opts.undoContext = 'add-component'; opts.action = 'add-component';
} }
if (modelToDrop) { if (modelToDrop) {

Loading…
Cancel
Save