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.

51 lines 2.97 kB
import { NotImplementedException } from "@aurigma/design-atoms-model/Exception"; import { BaseItemsCommand } from "./BaseItemsCommand"; import { BaseTextItem } from "@aurigma/design-atoms-model/Product/Items"; import { ItemUtils } from "../../Utils/ItemUtils"; import { ProductCommand, SelectionCommand } from "@aurigma/design-atoms-interfaces"; export class ReplaceGroupItemContentCommand extends BaseItemsCommand { constructor(productHandler, historyArgs, args, //private _product: Product, _commandManager, _productThemeManager, _canvas) { super(productHandler, historyArgs, args); this._commandManager = _commandManager; this._productThemeManager = _productThemeManager; this._canvas = _canvas; } async _executeCommandBody() { const { targetGroupItem, newItems } = this._args; if (targetGroupItem == null || newItems == null || newItems.length < 1) return; const relativeToPrintArea = false; const targetGroupItemHandler = this._productHandler.getHandler(targetGroupItem); const targetRectangle = targetGroupItemHandler.getTransformedRectangle(relativeToPrintArea); const oldItems = targetGroupItem.items.toArray(); const product = this._productHandler.product; ItemUtils.changeItemsContent(product, this._productHandler, this._commandManager, oldItems, newItems, false); targetGroupItem.items.clear(); targetGroupItem.addItems(newItems); const baseTextItems = targetGroupItem.getNestedItems(true).filter(item => item instanceof BaseTextItem); if (baseTextItems.length > 0) await ItemUtils.waitForItemsUpdated(baseTextItems, this._canvas); const updatedRectangleBounds = targetGroupItemHandler.getTransformedRectangle(relativeToPrintArea).bounds; ItemUtils.positionItemInArea(this._productHandler, targetGroupItem, updatedRectangleBounds.width, updatedRectangleBounds.height, true, targetRectangle, updatedRectangleBounds.center, relativeToPrintArea); if (this._productThemeManager.currentProductTheme != null) this._updateAppliedProductTheme(); if (targetRectangle.angle !== 0) { if (baseTextItems.length > 0) await ItemUtils.waitForItemsUpdated(baseTextItems, this._canvas); ItemUtils.rotateItems(this._productHandler, [targetGroupItem], targetRectangle.center, targetRectangle.angle); } this._commandManager.execute(SelectionCommand.selectItems, { items: [targetGroupItem] }); } _updateAppliedProductTheme() { this._commandManager.execute(ProductCommand.applyProductTheme, { theme: this._productThemeManager.currentProductTheme }); } redo() { throw new NotImplementedException(); } undo() { throw new NotImplementedException(); } } //# sourceMappingURL=ReplaceGroupItemContentCommand.js.map