UNPKG

@aurigma/design-atoms

Version:

Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.

55 lines 2.88 kB
import { BaseItemsCommand } from "./BaseItemsCommand"; import { NotImplementedException } from "@aurigma/design-atoms-model/Exception"; import { BaseTextItem, PlaceholderItem } from "@aurigma/design-atoms-model/Product/Items"; import { ItemUtils } from "../../Utils/ItemUtils"; import { ItemsCommand, SurfaceCommand } from "@aurigma/design-atoms-interfaces"; export class ChangeLayoutCommand extends BaseItemsCommand { constructor(productHandler, args, historyArgs, _commandManager) { super(productHandler, historyArgs, args); this._commandManager = _commandManager; } async _executeCommandBody() { const product = this._productHandler.product; const currentContainer = this._productHandler.userEditContainer; ; const itemsToRemove = product .getAllItems({ ignoreMockups: true }) .filter(item => { const isItemInCurrentSurface = item.parentContainer.parentComponent === this._productHandler.currentSurface; const isItemInCurrentContainer = item.parentContainer.id === currentContainer.id; const isAllowDelete = item.itemPermissions.allowRemoveOnLayoutChange; return isItemInCurrentSurface && isItemInCurrentContainer && isAllowDelete; }); const isNotInStringAndMvi = (item) => item instanceof BaseTextItem && item.placeholders.length === 0 && item.values.length === 0; const replaceItems = itemsToRemove.filter(i => i instanceof PlaceholderItem || isNotInStringAndMvi(i)); const targetItems = this._getTargetItems(this._args.items, this._args.query, this._args.queryOptions); targetItems.forEach(i => { i.fromLayout = true; i.itemPermissions.allowRemoveOnLayoutChange = true; ItemUtils.positionItemInArea(this._productHandler, i, this._args.sourceWidth, this._args.sourceHeight, true); this._commandManager.execute(SurfaceCommand.addItems, { items: [i], selectOnCanvas: false, ignoreOrderRules: true, ignoreCanvasRotate: true, createCloneName: replaceItems == null || replaceItems.find(o => o.name === i.name) == null }); }); await this._productHandler.waitUpdate(); ItemUtils.changeItemsContent(product, this._productHandler, this._commandManager, replaceItems, this._args.items, true); if (itemsToRemove.length !== 0) this._commandManager.execute(ItemsCommand.deleteItems, { items: itemsToRemove, force: true }); } redo() { throw new NotImplementedException(); } undo() { throw new NotImplementedException(); } } //# sourceMappingURL=ChangeLayoutCommand.js.map