Browse Source

Add getGroupedStack to UndoManager

pull/4134/head
Artur Arseniev 4 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 { isArray, isBoolean, isEmpty } from 'underscore';
import { isArray, isBoolean, isEmpty, unique } from 'underscore';
export default () => {
let em;
@ -316,24 +316,39 @@ export default () => {
this.start();
},
__getStackRead() {
getGroupedStack() {
const result = {};
const stack = this.getStack();
const createItem = item => {
const { type, after, before, object } = item.attributes;
return {
type,
after,
before,
object,
};
const { type, after, before, object, options = {} } = item.attributes;
return { type, after, before, object, options };
};
this.getStack().forEach(item => {
stack.forEach(item => {
const index = item.get('magicFusionIndex');
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() {

4
src/utils/Sorter.js

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

Loading…
Cancel
Save