aico-image-editor
Version:
Combine multiple image into and create single combined image
31 lines (30 loc) • 978 B
JavaScript
/**
* SortCommand for undo and redo sorting
*/
export class SortCommand {
constructor(sortable,oldSortArray, newSortArray) {
this.sortable = sortable;
this.sortable = sortableCanvas;
this.oldSortArray = oldSortArray;
this.newSortArray = newSortArray;
}
execute() {
sortable.sort(this.newSortArray);// this is to sort layers as per new array
sortableCanvas.sort(this.newSortArray);
// this is to sort objects from layers as per the new array reverse
window.dispatchEvent(new CustomEvent('sort-objects-from-layer', {
detail: {
layersSortingEndArray: this.newSortArray.slice().reverse(),
}
}))
}
undo() {
sortable.sort(this.oldSortArray);
sortableCanvas.sort(this.oldSortArray);
window.dispatchEvent(new CustomEvent('sort-objects-from-layer', {
detail: {
layersSortingEndArray: this.oldSortArray.slice().reverse(),
}
}))
}
}