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.

47 lines 1.9 kB
import { BaseCommand } from "../BaseCommand"; import { SelectionCommand } from "@aurigma/design-atoms-interfaces"; export class SelectFirstItemCommand extends BaseCommand { constructor(_productHandler, _commandManager, _canvas) { super(null); this._productHandler = _productHandler; this._commandManager = _commandManager; this._canvas = _canvas; this._canSelectItem = (item) => { const currentSurface = this._productHandler.currentSurface; return currentSurface != null && !item.visualizationPermissions.noShow && !item.locked && currentSurface.getBackgroundItem() != item; }; } async execute() { const currentSurface = this._productHandler.currentSurface; const currentContainer = this._productHandler.userEditContainer; if (currentSurface == null) { return; } const printAreas = currentSurface.printAreas; if (printAreas == null || printAreas.count() <= 0) { return; } const currentPrintAreaItems = currentSurface .getAllItems({ ignoreMockups: true }) .where(x => x.parentContainer == currentContainer) .toArray(); if (currentPrintAreaItems == null || currentPrintAreaItems.length <= 0) { return; } if (this._canvas == null) { return; } let itemToSelect; if (itemToSelect == null) { itemToSelect = currentPrintAreaItems.reverse().find(this._canSelectItem); } await this._canvas.waitUpdate(); if (itemToSelect != null) { this._commandManager.execute(SelectionCommand.selectItems, { items: [itemToSelect] }); } } } //# sourceMappingURL=SelectFirstItemCommand.js.map