@aurigma/design-atoms
Version:
Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.
114 lines • 4.85 kB
JavaScript
import { BaseItemsCommand } from "./BaseItemsCommand";
import { NotImplementedException, ArgumentException } from "@aurigma/design-atoms-model/Exception";
import { AutoScaledTextItem, BarcodeItem, BoundedTextItem, CurvedTextItem, EllipseItem, ImageItem, LineItem, PathBoundedTextItem, PlaceholderItem, PlainTextItem, RectangleItem, ShapeItem, ArchedTextItem, ClipartItem, LayoutItem, GroupItem } from "@aurigma/design-atoms-model/Product/Items";
import { ItemType } from "@aurigma/design-atoms-interfaces";
export class CreateItemCommand extends BaseItemsCommand {
constructor(productHandler, _itemsDataApplier, historyArgs, args) {
super(productHandler, historyArgs, args);
this._itemsDataApplier = _itemsDataApplier;
}
async _executeCommandBody() {
let item;
switch (this._args.type) {
case ItemType.AutoScaledTextItem:
item = new AutoScaledTextItem();
break;
case ItemType.BarcodeItem:
item = new BarcodeItem();
break;
case ItemType.BoundedTextItem:
item = new BoundedTextItem();
break;
case ItemType.CurvedTextItem:
item = new CurvedTextItem();
break;
case ItemType.EllipseItem:
item = new EllipseItem();
break;
case ItemType.ImageItem:
item = new ImageItem();
break;
case ItemType.LineItem:
item = new LineItem();
break;
case ItemType.PathBoundedTextItem:
item = new PathBoundedTextItem();
break;
case ItemType.PlaceholderItem:
item = new PlaceholderItem();
break;
case ItemType.PlainTextItem:
item = new PlainTextItem();
break;
case ItemType.RectangleItem:
item = new RectangleItem();
break;
case ItemType.ArchedTextItem:
item = new ArchedTextItem();
break;
case ItemType.ShapeItem:
item = new ShapeItem();
break;
}
if (this._args.itemData == null)
return item;
const relativeToPrintArea = this._args.relativeToPrintArea != null ? this._args.relativeToPrintArea : true;
await this._itemsDataApplier.applyToItem(item, this._args.itemData, { changePosition: true, relativeToPrintArea: relativeToPrintArea });
return item;
}
redo() {
throw new NotImplementedException();
}
undo() {
throw new NotImplementedException();
}
}
export var ItemTypeNs;
(function (ItemTypeNs) {
ItemTypeNs.isText = (type) => [
ItemType.AutoScaledTextItem,
ItemType.BoundedTextItem,
ItemType.CurvedTextItem,
ItemType.PathBoundedTextItem,
ItemType.PlainTextItem,
ItemType.ArchedTextItem
].includes(type);
ItemTypeNs.getType = (item) => {
// Note: The order is important here!
// Most specific types must come before less specific (i.e. RectangleItem, ShapeItem)
if (item instanceof AutoScaledTextItem)
return ItemType.AutoScaledTextItem;
if (item instanceof BarcodeItem)
return ItemType.BarcodeItem;
if (item instanceof BoundedTextItem)
return ItemType.BoundedTextItem;
if (item instanceof CurvedTextItem)
return ItemType.CurvedTextItem;
if (item instanceof EllipseItem)
return ItemType.EllipseItem;
if (item instanceof ImageItem)
return ItemType.ImageItem;
if (item instanceof LineItem)
return ItemType.LineItem;
if (item instanceof PathBoundedTextItem)
return ItemType.PathBoundedTextItem;
if (item instanceof PlaceholderItem)
return ItemType.PlaceholderItem;
if (item instanceof PlainTextItem)
return ItemType.PlainTextItem;
if (item instanceof ArchedTextItem)
return ItemType.ArchedTextItem;
if (item instanceof RectangleItem)
return ItemType.RectangleItem;
if (item instanceof ShapeItem)
return ItemType.ShapeItem;
if (item instanceof LayoutItem)
return ItemType.LayoutItem;
if (item instanceof ClipartItem)
return ItemType.ClipartItem;
if (item instanceof GroupItem)
return ItemType.GroupItem;
throw new ArgumentException("ItemType: Unexpected item!");
};
})(ItemTypeNs || (ItemTypeNs = {}));
//# sourceMappingURL=CreateItemCommand.js.map