@aurigma/design-atoms
Version:
Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.
59 lines • 2.72 kB
JavaScript
import { NotImplementedException } from "@aurigma/design-atoms-model/Exception";
import { BaseItemsCommand } from "./BaseItemsCommand";
import { ShapeItem, PlaceholderItem, ImageItem } from "@aurigma/design-atoms-model/Product/Items";
import { ItemsCommand, SelectionCommand } from "@aurigma/design-atoms-interfaces";
export class ConvertPlaceholderToItemCommand extends BaseItemsCommand {
constructor(productHandler, historyArgs, args, _commandManager) {
super(productHandler, historyArgs, args);
this._commandManager = _commandManager;
}
async _executeCommandBody() {
var _a;
const { item } = this._args;
if (item == null)
return;
if (!(item instanceof PlaceholderItem)) {
console.warn(`ConvertPlaceholderToItemCommand: item type ${item.type} is not supported`);
return;
}
let newItem;
if (item.isEmptyContent) {
const shape = new ShapeItem(item.sourcePath.clone());
shape.sourcePath = item.sourcePath.clone();
shape.sourcePathId = item.sourcePathId;
shape.transform = item.transform.clone();
shape.name = item.name;
shape.manipulationPermissions = item.manipulationPermissions.clone();
shape.visualizationPermissions = item.visualizationPermissions.clone();
shape.itemPermissions = item.itemPermissions.clone();
shape.shapePermissions = item.shapePermissions.clone();
shape.fillColor = item.fillColor;
shape.borderColor = item.borderColor;
shape.borderWidth = item.borderWidth;
newItem = shape;
}
else {
const content = item.content.clone();
content.name = item.name;
item.content = null;
content.parentPlaceholder = null;
newItem = content;
if (newItem instanceof ImageItem) {
newItem.allowedSubfolder = item.allowedSubfolder;
newItem.allowedTabs = (_a = item.allowedTabs) === null || _a === void 0 ? void 0 : _a.slice();
}
}
const selected = this._productHandler.isItemSelected(item);
await this._commandManager.execute(ItemsCommand.replaceItemCommand, { item: newItem, oldItem: item });
if (selected)
await this._commandManager.execute(SelectionCommand.selectItems, { items: [newItem] });
return newItem;
}
redo() {
throw new NotImplementedException();
}
undo() {
throw new NotImplementedException();
}
}
//# sourceMappingURL=ConvertPlaceholderToItemCommand.js.map