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.

69 lines 3.06 kB
import { NotImplementedException } from "@aurigma/design-atoms-model/Exception"; import { Item } from "@aurigma/design-atoms-model/Product/Items/Item"; import { BaseItemsCommand } from "./BaseItemsCommand"; import { ItemsCommand } from "@aurigma/design-atoms-interfaces"; export class BringItemsCommand extends BaseItemsCommand { constructor(productHandler, historyArgs, args, _commandManager, _canvas) { super(productHandler, historyArgs, args); this._commandManager = _commandManager; this._canvas = _canvas; } async _executeCommandBody() { const targetItems = this._getTargetItems(this._args.items, this._args.query, this._args.queryOptions); return this.bringItems(targetItems, this._args.position); } bringItems(items, position) { if (items.length === 0) return; var surface = this._productHandler.currentSurface; if (position === "front" || position === "levelUp") { surface.containers.reverse().forEach(container => container.items.reverse().forEach(item => { if (item instanceof Item && items.includes(item)) this.bringItem(item, position, false); })); } else if (position === "bottom" || position === "levelDown") { surface.containers.forEach(container => container.items.forEach(item => { if (item instanceof Item && items.includes(item)) this.bringItem(item, position, false); })); } const itemHandlers = items.map(i => this._productHandler.getHandler(i)); this._canvas.setSelectedItemHandlers(itemHandlers); this._canvas.updateTexts(); } bringItem(item, position, needUpdate) { if (needUpdate == null) needUpdate = true; if (item.itemPermissions.allowZOrderChange) { var itemsArray = item.parentContainer.items.toArray(); var itemIndex = itemsArray.indexOf(item); var lastIndex = itemsArray.length - 1; var newIndex = (itemIndex); if (itemIndex >= 0) { switch (position) { case "front": newIndex = lastIndex; break; case "levelUp": newIndex = Math.min(itemIndex + 1, lastIndex); break; case "levelDown": newIndex = Math.max(itemIndex - 1, 0); break; case "bottom": newIndex = 0; break; } } this._commandManager.execute(ItemsCommand.moveItem, { item: item, newIndex: newIndex, needUpdate: needUpdate }); } } redo() { throw new NotImplementedException(); } undo() { throw new NotImplementedException(); } } //# sourceMappingURL=BringItemsCommand.js.map