diff --git a/src/undo_manager/index.js b/src/undo_manager/index.js index 9c3f5365c..9dafbe5b9 100644 --- a/src/undo_manager/index.js +++ b/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() { diff --git a/src/utils/Sorter.js b/src/utils/Sorter.js index 212952a02..df23f6a0f 100644 --- a/src/utils/Sorter.js +++ b/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) {