@aurigma/design-atoms
Version:
Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.
42 lines • 2.14 kB
JavaScript
import { BaseItemsCommand } from "./BaseItemsCommand";
import { NotImplementedException } from "@aurigma/design-atoms-model/Exception";
import { ItemUtils } from "../../Utils/ItemUtils";
import { SelectionCommand, SurfaceCommand } from "@aurigma/design-atoms-interfaces";
export class InsertItemsIntoAreaCommand extends BaseItemsCommand {
constructor(productHandler, args, historyArgs, _commandManager) {
super(productHandler, historyArgs, args);
this._commandManager = _commandManager;
}
async _executeCommandBody() {
const { items, selectOnCanvas } = this._args;
await Promise.all(items.map((i) => {
ItemUtils.positionItemInArea(this._productHandler, i, this._args.sourceWidth, this._args.sourceHeight, false);
return this._commandManager.execute(SurfaceCommand.addItems, {
items: [i],
selectOnCanvas: false,
ignoreOrderRules: true,
ignoreCanvasRotate: false
});
}));
//TODO: После фикса проблемы с обновлением всей коллекции itemHandlers при добавлении одного item-а
const angle = this._productHandler.contentAngle;
if (angle > 0) {
await this._productHandler.waitUpdate();
const targetContainer = this._productHandler.userEditContainer;
const printArea = this._productHandler.userEditPrintArea;
const region = targetContainer.region;
const targetAreaBounds = (region != null) ? region : printArea.bounds;
const rotateCenter = targetAreaBounds.center;
ItemUtils.rotateItems(this._productHandler, items, rotateCenter, -angle);
}
if (selectOnCanvas)
this._commandManager.execute(SelectionCommand.selectItems, { items: items.filter(item => !item.locked) });
}
redo() {
throw new NotImplementedException();
}
undo() {
throw new NotImplementedException();
}
}
//# sourceMappingURL=InsertItemsIntoAreaCommand.js.map