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.

355 lines 21.2 kB
import { SurfaceManager, SurfaceSwitchCommand } from "../Services/SurfaceManager"; import { ArgumentException } from "@aurigma/design-atoms-model/Exception"; import { RotateProductCommand } from "./ProductCommand/RotateProductCommand"; import { ChangeBackgroundCommand } from "./ProductCommand/ChangeBackgroundCommand"; import { AddItemsCommand } from "./SurfaceCommands/AddItemsCommand"; import { DeleteItemsCommand } from "./ItemsCommands/DeleteItemsCommand"; import { SelectItemsCommand } from "./SelectionCommand/SelectItemsCommand"; import { SelectFirstItemCommand } from "./SelectionCommand/SelectFirstItemCommand"; import { ClearSelectionCommand } from "./SelectionCommand/ClearSelectionCommand"; import { CloneItemsCommand } from "./ItemsCommands/CloneItemsCommand"; import { ReplaceInterpolationPlaceholdersCommand } from "./ProductCommand/ReplaceInterpolationPlaceholders"; import { Surface } from "@aurigma/design-atoms-model/Product"; import { ApplyProductThemeCommand } from "./ProductCommand/ApplyProductThemeCommand"; import { AddContentCommand } from "./ItemsCommands/AddContentCommand"; import { AlignItemsCommand } from "./ItemsCommands/AlignItemsCommand"; import { GroupAlignCommand } from "./ItemsCommands/GroupAlignCommand"; import { BringItemsCommand } from "./ItemsCommands/BringItemsCommand"; import { MoveItemCommand } from "./ItemsCommands/MoveItemCommand"; import { DistributeItemsCommand } from "./ItemsCommands/DistributeItemsCommand"; import { CreateItemCommand } from "./ItemsCommands/CreateItemCommand"; import { EditItemsCommand } from "./ItemsCommands/EditItemsCommand"; import { SetImageMetadataCommand } from "./ItemsCommands/SetImageMetadataCommand"; import { PlaceholderContentScaleCommand } from "./ItemsCommands/PlaceholderContentScaleCommand"; import { PlaceholderContentResetCommand } from "./ItemsCommands/PlaceholderContentResetCommand"; import { ChangeBarcodeFormatCommand } from "./ItemsCommands/ChangeBarcodeFormatCommand"; import { ChangeColumnCountCommand } from "./ItemsCommands/ChangeColumnCountCommand"; import { PlaceholderContentRotateCommand } from "./ItemsCommands/PlaceholderContentRotateCommand"; import { InsertItemsIntoAreaCommand } from "./ItemsCommands/InsertItemsIntoAreaCommand"; import { ChangeLayoutCommand } from "./ItemsCommands/ChangeLayoutCommand"; import { GroupItemsCommand } from "./ItemsCommands/GroupItemsCommand"; import { UngroupItemsCommand } from "./ItemsCommands/UngroupItemsCommand"; import { ReplaceGroupItemContentCommand } from "./ItemsCommands/ReplaceGroupItemContentCommand"; import { ChangeClipartItemColorCommand } from "./ItemsCommands/ChangeClipartItemColor"; import { FillPlaceholdersCommand } from "./ProductCommand/FillPlaceholdersCommand"; import { ResizeCommand } from "./ProductCommand/ResizeCommand"; import { TranslateItemsCommand } from "./ItemsCommands/TranslateItemsCommand"; import { AlignIntoGroupCommand } from './ItemsCommands/AlignIntoGroupCommand'; import { ConvertGroupIntoLayoutCommand } from "./ItemsCommands/ConvertGroupIntoLayoutCommand"; import { ConvertLayoutIntoGroupCommand } from "./ItemsCommands/ConvertLayoutIntoGroupCommand"; import { SetImageItemCommand } from "./ItemsCommands/SetImageItemCommand"; import { ConvertItemToPlaceholderCommand } from "./ItemsCommands/ConvertItemToPlaceholderCommand"; import { ConvertPlaceholderToItemCommand } from "./ItemsCommands/ConvertPlaceholderToItemCommand"; import { SetBleedCommand } from "./SurfaceCommands/SetBleedCommand"; import { ZoomToItemsCommand } from "./ZoomCommands/ZoomToItemsCommand"; import { ZoomToSafetyLineCommand } from "./ZoomCommands/ZoomToSafetyLineCommand"; import { ZoomToSelectionCommand } from "./ZoomCommands/ZoomToSelectionCommand"; import { PlaceItemsToAreaCommand } from "./ItemsCommands/PlaceItemsToAreaCommand"; import { FixUnsupportedTextCommand } from "./ItemsCommands/FixUnsupportedTextCommand"; import { ConvertTextItemCommand } from "./ItemsCommands/ConvertTextItemCommand"; import { SelectItemsByRectCommand } from "./SelectionCommand/SelectItemsByRect"; import { TransformItemsCommand } from "./ItemsCommands/TransformCommands/TransformItemsCommand"; import { ReplaceItemCommand } from "./ItemsCommands/ReplaceItemsCommand"; import { SetSlugCommand } from "./SurfaceCommands/SetSlugCommand"; import { EditPlaceholderCommand } from "./ItemsCommands/EditPlaceholderCommand"; import { RotateItemsCommand } from "./ItemsCommands/TransformCommands/RotateItemsCommand"; import { NewTranslateItemsCommand } from "./ItemsCommands/TransformCommands/NewTranslateItemsCommand"; import { ResizeItemsCommand } from "./ItemsCommands/TransformCommands/ResizeItemsCommand"; import { MoveViewportCommand } from "./ViewerCommands/MoveViewportCommand"; import { SetZoomCommand } from "./ZoomCommands/SetZoomCommand"; import { FrontEndLogger, LogSource } from "./../Services/FrontEndLogger"; import { SelectAllItemsCommand } from "./SelectionCommand/SelectAllCommand"; var CommandManager = /** @class */ (function () { function CommandManager(_history, _productHandler, _productThemeManager, _variableItemHelper, _eventManager, _canvas, _itemsDataApplier) { this._history = _history; this._productHandler = _productHandler; this._productThemeManager = _productThemeManager; this._variableItemHelper = _variableItemHelper; this._eventManager = _eventManager; this._canvas = _canvas; this._itemsDataApplier = _itemsDataApplier; this._surfaceManager = new SurfaceManager(_productHandler); } Object.defineProperty(CommandManager.prototype, "_product", { get: function () { return this._productHandler.product; }, enumerable: true, configurable: true }); CommandManager.prototype.execute = function (name, args, historyUpdateMode) { var _a, _b; this._log(name, args); var historyArgs = { history: this._history, historyUpdateMode: historyUpdateMode }; var command; switch (name) { // TODO: Rewrite to usual commands with SurfaceManager dependency. case SurfaceSwitchCommand.switchToSurface: this._surfaceManager.switchToSurface(args.value instanceof Surface ? args.value : this._product.surfaces.get(args.value)); break; case SurfaceSwitchCommand.getNextSurface: this._surfaceManager.getNextSurface(args.spinIndex); break; case SurfaceSwitchCommand.switchSurfaceForward: this._surfaceManager.switchSurfaceForward(); break; case SurfaceSwitchCommand.switchSurfaceBackward: this._surfaceManager.switchSurfaceBackward(); break; case ProductCommand.rotateProduct: command = new RotateProductCommand(this._productHandler, historyArgs, this._product, args); break; case ProductCommand.replaceInterpolationPlaceholders: command = new ReplaceInterpolationPlaceholdersCommand(this._productHandler, historyArgs, this._product, this._canvas); break; case ProductCommand.changeBackground: command = new ChangeBackgroundCommand(this._productHandler, historyArgs, this._product, args, this, this._productThemeManager, this._canvas, this._eventManager); break; case ProductCommand.applyProductTheme: command = new ApplyProductThemeCommand(historyArgs, this._product, args, this._productThemeManager, this); break; case ProductCommand.fillPlaceholders: command = new FillPlaceholdersCommand(historyArgs, this._product, args, this); break; case ProductCommand.resize: command = new ResizeCommand(historyArgs, this._product, args, this._productHandler, this, this._canvas); break; case SurfaceCommand.addItems: command = new AddItemsCommand(this._productHandler, historyArgs, args, this._productThemeManager, this._canvas, this._variableItemHelper, this, this._eventManager); break; case SurfaceCommand.setBleed: command = new SetBleedCommand(this._productHandler, historyArgs, args, this); break; case SurfaceCommand.setSlug: command = new SetSlugCommand(this._productHandler, historyArgs, args); break; case ItemsCommand.deleteItems: command = new DeleteItemsCommand(this._productHandler, historyArgs, args, this._canvas, this.configuration, this); break; case ItemsCommand.cloneItems: command = new CloneItemsCommand(this._productHandler, historyArgs, args, this, this._variableItemHelper); break; case ItemsCommand.addContent: command = new AddContentCommand(this._productHandler, historyArgs, args, this._productThemeManager, this._eventManager); break; case ItemsCommand.alignItems: command = new AlignItemsCommand(this._productHandler, historyArgs, args, this._canvas); break; case ItemsCommand.alignIntoGroup: command = new AlignIntoGroupCommand(this._productHandler, historyArgs, args, this); break; case ItemsCommand.groupAlign: command = new GroupAlignCommand(historyArgs, args, this._canvas); break; case ItemsCommand.bringItems: command = new BringItemsCommand(this._productHandler, historyArgs, args, this, this._canvas); break; case ItemsCommand.moveItem: command = new MoveItemCommand(this._productHandler, historyArgs, args); break; case ItemsCommand.createItem: command = new CreateItemCommand(this._itemsDataApplier, historyArgs, args); break; case ItemsCommand.editItems: command = new EditItemsCommand(this._itemsDataApplier, this._productHandler, historyArgs, args); break; case ItemsCommand.setImageMetadata: command = new SetImageMetadataCommand(historyArgs, args, this._productHandler, this._product, this._variableItemHelper, this, this._eventManager); break; case ItemsCommand.setImageItem: command = new SetImageItemCommand(historyArgs, args, this); break; case ItemsCommand.placeholderContentScale: command = new PlaceholderContentScaleCommand(args, historyArgs, this._productHandler); break; case ItemsCommand.placeholderContentReset: command = new PlaceholderContentResetCommand(args, historyArgs, this._productHandler); break; case ItemsCommand.changeBarcodeFormat: command = new ChangeBarcodeFormatCommand(args, historyArgs, this._productHandler); break; case ItemsCommand.changeColumnCount: command = new ChangeColumnCountCommand(args, historyArgs, this._productHandler); break; case ItemsCommand.placeholderContentRotate: command = new PlaceholderContentRotateCommand(args, historyArgs, this._productHandler); break; case ItemsCommand.insertItemsIntoArea: command = new InsertItemsIntoAreaCommand(args, historyArgs, this._productHandler, this); break; case ItemsCommand.changeLayout: command = new ChangeLayoutCommand(args, historyArgs, this._productHandler, this._product, this); break; case ItemsCommand.groupItems: command = new GroupItemsCommand(historyArgs, args, this); break; case ItemsCommand.ungroupItems: command = new UngroupItemsCommand(historyArgs, args, this); break; case ItemsCommand.replaceGroupItemContent: command = new ReplaceGroupItemContentCommand(historyArgs, args, this._productHandler, this._product, this, this._productThemeManager, this._canvas); break; case ItemsCommand.changeClipartItemColor: command = new ChangeClipartItemColorCommand(historyArgs, args); break; case ItemsCommand.translateItems: command = new TranslateItemsCommand(historyArgs, args, this._productHandler, this._canvas); break; case ItemsCommand.convertGroupIntoLayout: command = new ConvertGroupIntoLayoutCommand(historyArgs, args, this, this._canvas); break; case ItemsCommand.convertLayoutIntoGroup: command = new ConvertLayoutIntoGroupCommand(historyArgs, args, this); break; case ItemsCommand.convertItemToPlaceholder: command = new ConvertItemToPlaceholderCommand(historyArgs, args, this._productHandler, this); break; case ItemsCommand.convertPlaceholderToItem: command = new ConvertPlaceholderToItemCommand(historyArgs, args, this._productHandler, this); break; case ItemsCommand.placeItemsToArea: command = new PlaceItemsToAreaCommand(historyArgs, args, this._productHandler, this._canvas); break; case ItemsCommand.convertTextItem: command = new ConvertTextItemCommand(historyArgs, args, this._productHandler, this); break; case ItemsCommand.transformItems: command = new TransformItemsCommand(historyArgs, args, this._productHandler); break; case ItemsCommand.rotateItems: command = new RotateItemsCommand(historyArgs, args, this); break; case ItemsCommand.newTranslateItems: command = new NewTranslateItemsCommand(historyArgs, args, this); break; case ItemsCommand.resizeItems: command = new ResizeItemsCommand(historyArgs, args, this); break; case ItemsCommand.replaceItemCommand: command = new ReplaceItemCommand(historyArgs, args, this); break; case ItemsCommand.fixUnsupportedText: command = new FixUnsupportedTextCommand(historyArgs, args, this); break; case ItemsCommand.editPlaceholder: command = new EditPlaceholderCommand(args, this._productHandler, this); break; case ItemsCommand.distributeItems: return new DistributeItemsCommand(this._canvas, this._productHandler, historyArgs, args).execute(); case SelectionCommand.selectItems: command = new SelectItemsCommand(this._productHandler, args, this._canvas); break; case SelectionCommand.selectItemsByRect: command = new SelectItemsByRectCommand(args, this._canvas, this); break; case SelectionCommand.selectAll: command = new SelectAllItemsCommand((_a = this._canvas) === null || _a === void 0 ? void 0 : _a.viewer, this); break; case SelectionCommand.selectFirst: command = new SelectFirstItemCommand(this._productHandler, this, this._canvas); break; case SelectionCommand.clearSelection: command = new ClearSelectionCommand(this._canvas); break; case ZoomCommand.zoomToItems: command = new ZoomToItemsCommand(args, this._canvas); break; case ZoomCommand.zoomToSafetyLine: command = new ZoomToSafetyLineCommand(args, this._canvas); break; case ZoomCommand.zoomToSelection: command = new ZoomToSelectionCommand(this._canvas); break; case ZoomCommand.setZoom: command = new SetZoomCommand(args, this._canvas); break; case ViewerCommand.moveViewPort: command = new MoveViewportCommand(args, (_b = this._canvas) === null || _b === void 0 ? void 0 : _b.viewer); break; default: throw new ArgumentException(); } return command === null || command === void 0 ? void 0 : command.execute(); }; CommandManager.prototype._log = function (name, args) { FrontEndLogger.debugLog("Command " + name + " is executing!", LogSource.CommandManager); }; return CommandManager; }()); export { CommandManager }; export var ProductCommand; (function (ProductCommand) { ProductCommand["rotateProduct"] = "rotateProduct"; ProductCommand["replaceInterpolationPlaceholders"] = "replaceInterpolationPlaceholders"; ProductCommand["changeBackground"] = "changeBackground"; ProductCommand["applyProductTheme"] = "applyProductTheme"; ProductCommand["fillPlaceholders"] = "fillPlaceholders"; ProductCommand["resize"] = "resize"; })(ProductCommand || (ProductCommand = {})); export var SurfaceCommand; (function (SurfaceCommand) { SurfaceCommand["addItems"] = "addItems"; SurfaceCommand["setBleed"] = "setBleed"; SurfaceCommand["setSlug"] = "setSlug"; })(SurfaceCommand || (SurfaceCommand = {})); export var ItemsCommand; (function (ItemsCommand) { ItemsCommand["deleteItems"] = "deleteItems"; ItemsCommand["cloneItems"] = "cloneItems"; ItemsCommand["addContent"] = "addContent"; ItemsCommand["alignItems"] = "alignItems"; ItemsCommand["alignIntoGroup"] = "alignIntoGroup"; ItemsCommand["groupAlign"] = "groupAlign"; ItemsCommand["bringItems"] = "bringItems"; ItemsCommand["moveItem"] = "moveItem"; ItemsCommand["createItem"] = "createItem"; ItemsCommand["editItems"] = "editItems"; ItemsCommand["setImageMetadata"] = "setImageMetadata"; ItemsCommand["setImageItem"] = "setImageItem"; ItemsCommand["placeholderContentScale"] = "placeholderContentScale"; ItemsCommand["placeholderContentReset"] = "placeholderContentReset"; ItemsCommand["placeholderContentRotate"] = "placeholderContentRotate"; ItemsCommand["changeBarcodeFormat"] = "changeBarcodeFormat"; ItemsCommand["changeColumnCount"] = "changeColumnCount"; ItemsCommand["insertItemsIntoArea"] = "insertItemsIntoArea"; ItemsCommand["changeLayout"] = "changeLayout"; ItemsCommand["groupItems"] = "groupItems"; ItemsCommand["ungroupItems"] = "ungroupItems"; ItemsCommand["replaceGroupItemContent"] = "replaceGroupItemContent"; ItemsCommand["changeClipartItemColor"] = "changeClipartItemColor"; ItemsCommand["convertGroupIntoLayout"] = "convertGroupIntoLayout"; ItemsCommand["convertLayoutIntoGroup"] = "convertLayoutIntoGroup"; ItemsCommand["translateItems"] = "translateItems"; ItemsCommand["convertItemToPlaceholder"] = "itemToPlaceholder"; ItemsCommand["convertPlaceholderToItem"] = "placeholderToItem"; ItemsCommand["placeItemsToArea"] = "placeItemsToArea"; ItemsCommand["convertTextItem"] = "convertTextItem"; ItemsCommand["transformItems"] = "transformItems"; ItemsCommand["rotateItems"] = "rotateItems"; ItemsCommand["fixUnsupportedText"] = "fixUnsupportedText"; ItemsCommand["replaceItemCommand"] = "replaceItemCommand"; ItemsCommand["editPlaceholder"] = "editPlaceholder"; ItemsCommand["distributeItems"] = "distributeItems"; ItemsCommand["newTranslateItems"] = "newTranslateItems"; ItemsCommand["resizeItems"] = "resizeItems"; })(ItemsCommand || (ItemsCommand = {})); export var SelectionCommand; (function (SelectionCommand) { SelectionCommand["clearSelection"] = "clearSelection"; SelectionCommand["selectFirst"] = "selectFirst"; SelectionCommand["selectItems"] = "selectItems"; SelectionCommand["selectItemsByRect"] = "selectItemsByRect"; SelectionCommand["selectAll"] = "selectAll"; })(SelectionCommand || (SelectionCommand = {})); export var ZoomCommand; (function (ZoomCommand) { ZoomCommand["zoomToItems"] = "zoomToItems"; ZoomCommand["zoomToSafetyLine"] = "zoomToSafetyLine"; ZoomCommand["zoomToSelection"] = "zoomToSelection"; ZoomCommand["setZoom"] = "setZoom"; })(ZoomCommand || (ZoomCommand = {})); export var ViewerCommand; (function (ViewerCommand) { ViewerCommand["moveViewPort"] = "moveViewPort"; })(ViewerCommand || (ViewerCommand = {})); //# sourceMappingURL=CommandManager.js.map