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.

106 lines 5.16 kB
import { NotImplementedException } from "@aurigma/design-atoms-model/Exception"; import { BaseItemsCommand } from "./BaseItemsCommand"; import { HistoryUpdateMode } from "../ModelUpdateCommand"; import { PlaceholderItem, ImageItem, OverlayEffect } from "@aurigma/design-atoms-model/Product/Items"; import { ItemUtils } from "../../Utils/ItemUtils"; import { ImageEffect } from "../../ItemHandlers"; import { RgbColors } from "@aurigma/design-atoms-model"; import { ItemsCommand } from "@aurigma/design-atoms-interfaces"; export class SetImageMetadataCommand extends BaseItemsCommand { constructor(productHandler, historyArgs, args, _variableItemHelper, _commandManager, _eventManager) { super(productHandler, historyArgs, args); this._variableItemHelper = _variableItemHelper; this._commandManager = _commandManager; this._eventManager = _eventManager; } async _executeCommandBody() { return this._setImageDataList(this._args.dataList, this._args.keepLocation); } _setImageDataList(dataList, keepLocation) { this._normalizeDataList(dataList); for (let { item, imageData, tags, rotatedRectangle } of dataList) { if (item instanceof PlaceholderItem) { if (!item.contentPermissions.imagePermissions.allowKeepOverlayColor) { ItemUtils.applyOverlayEffect(item, new OverlayEffect()); } const newImage = ItemUtils.createImageContentForPlaceholder(item, imageData, this._productHandler, this._args.dpi); if (newImage instanceof ImageItem) { this._ensureImageItemName(newImage); } item.isStubContent = false; if (newImage != null && tags != null) newImage.tags = tags; this._commandManager.execute(ItemsCommand.addContent, { placeholder: item, content: newImage }, HistoryUpdateMode.NotUpdate); /* if (this._app.configuration.canvas.violationWarningButtonsEnabled && this._app.model.currentSurface.getAllItems().contains(item)) { this.showViolationWarning(item); } */ } else { const imageItem = ItemUtils.getImageItem(item); const imageItemHandler = this._productHandler.getHandler(imageItem); if (imageItem.effect !== ImageEffect.Colorize) imageItem.fillColor = RgbColors.transparent; if (!imageItem.imagePermissions.allowKeepOverlayColor) { ItemUtils.applyOverlayEffect(imageItem, new OverlayEffect()); } SetImageMetadataCommand.setDataToImage(imageData, imageItem); if (tags != null) { imageItem.tags = tags; } if (rotatedRectangle != null) { imageItemHandler.setTransformedRectangle(rotatedRectangle); } else { imageItemHandler.updateRectangle(keepLocation); } imageItemHandler.quickUpdate(); this._ensureImageItemName(imageItem); } this._eventManager.imageContentChangedEvent.notify(item); } this._productHandler.updateSelection(); } _ensureImageItemName(item) { if (item.isVariable) { item.isVariable = false; this._variableItemHelper.setVariableValue(item, true, true); } } _normalizeDataList(dataList) { const linkedIds = []; const length = dataList.length; for (let i = 0; i < length; i++) { const item = dataList[i].item; if (item instanceof PlaceholderItem && item.linkId != null && linkedIds.indexOf(item.linkId) === -1) { const linkedPlaceholders = this._productHandler.product.getAllItems({ ignoreMockups: false, flatGroupItems: true }) .filter(i => i instanceof PlaceholderItem && i.linkId === item.linkId); dataList.push(...(linkedPlaceholders.map(p => ({ item: p, imageData: dataList[i].imageData, tags: dataList[i].tags })))); linkedIds.push(item.linkId); } } } redo() { throw new NotImplementedException(); } undo() { throw new NotImplementedException(); } static setDataToImage(data, imageItem) { if (data.name != null) imageItem.displayName = data.name; imageItem.isUserImage = data.isUserImage; imageItem.source.setIdWithOrigin(data.storageId, data.origin); imageItem.source.pageIndex = data.pageIndex; imageItem.source.width = data.size.width; imageItem.source.height = data.size.height; imageItem.source.isVector = data.isVector; } } //# sourceMappingURL=SetImageMetadataCommand.js.map