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.

55 lines 1.84 kB
import { Collection } from "@aurigma/design-atoms-model/Collection"; import { ArgumentNullException } from "@aurigma/design-atoms-model/Exception"; import { GroupItemHandler } from "./GroupItemHandler"; export class ItemHandlersCollection extends Collection { constructor(layer) { super(); this._applyLayerAndCanvas = (handler) => { handler.layer = this._layer; const cv = this._layer.canvas; if (cv) handler.canvas = cv; if (handler instanceof GroupItemHandler) { handler.applyToItems(this._applyLayerAndCanvas); } }; if (!layer) throw new ArgumentNullException("layer"); this._layer = layer; } /** * Inserts handlers into the collection at the specified index. */ insertAt(index, item) { super.insertAt(index, item); this._onHandlerAdded(item); } move(oldIndex, newIndex) { return super.move(oldIndex, newIndex); } removeAt(index) { const item = super.removeAt(index); if (item) this._onHandlerRemoved(item); return item; } clear() { for (let i = 0; i < this.length; i++) { this.getItem(i).layer = null; } super.clear(); } _onHandlerAdded(handler) { this._applyLayerAndCanvas(handler); } _onHandlerRemoved(handler) { const canvas = this._layer.canvas; if (canvas && canvas.isItemHandlerSelected(handler)) canvas.removeSelectedItemHandler(handler); handler.layer = null; //tell to handler is has been removed from canvas if (canvas) handler.canvas = null; } } //# sourceMappingURL=ItemHandlersCollection.js.map