@aurigma/design-atoms
Version:
Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.
42 lines • 1.91 kB
JavaScript
import { BaseItemsCommand } from "./BaseItemsCommand";
import { NotImplementedException, ArgumentException } from "@aurigma/design-atoms-model/Exception";
import { LayoutItem } from "@aurigma/design-atoms-model/Product/Items";
import { ItemsCommand } from "@aurigma/design-atoms-interfaces";
export class ReplaceItemCommand extends BaseItemsCommand {
constructor(productHandler, historyArgs, args, _commandManager) {
super(productHandler, historyArgs, args);
this._commandManager = _commandManager;
}
async _executeCommandBody() {
var _a;
const { item, oldItem } = this._args;
if (item == null || oldItem == null)
throw new ArgumentException("ReplaceItemsCommand: item and oldItem must be not null!");
const parentGroup = oldItem.parentGroupItem;
const parentContainer = oldItem.parentContainer;
const parentCollection = (_a = (parentGroup !== null && parentGroup !== void 0 ? parentGroup : parentContainer)) === null || _a === void 0 ? void 0 : _a.items;
if (parentCollection == null)
return;
const layoutOrderIndex = parentGroup instanceof LayoutItem ? parentGroup.getItemOrderIndex(oldItem) : null;
const index = parentCollection.indexOf(oldItem);
await this._commandManager.execute(ItemsCommand.deleteItems, {
items: [oldItem],
autoParentGroupDelete: false,
autoUngroup: false,
force: true
});
if (parentGroup instanceof LayoutItem) {
parentGroup.addItem(item, index, layoutOrderIndex);
}
else {
parentCollection.insertAt(index, item);
}
}
redo() {
throw new NotImplementedException();
}
undo() {
throw new NotImplementedException();
}
}
//# sourceMappingURL=ReplaceItemsCommand.js.map