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.

72 lines 3.02 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import { Collection } from "@aurigma/design-atoms-model/Collection"; import { ArgumentNullException } from "@aurigma/design-atoms-model/Exception"; import { GroupItemHandler } from "./GroupItemHandler"; var ItemHandlersCollection = /** @class */ (function (_super) { __extends(ItemHandlersCollection, _super); function ItemHandlersCollection(layer) { var _this = _super.call(this) || this; _this._applyLayerAndCanvas = function (handler) { handler.layer = _this._layer; var 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; return _this; } /** * Inserts handlers into the collection at the specified index. */ ItemHandlersCollection.prototype.insertAt = function (index, item) { _super.prototype.insertAt.call(this, index, item); this._onHandlerAdded(item); }; ItemHandlersCollection.prototype.move = function (oldIndex, newIndex) { return _super.prototype.move.call(this, oldIndex, newIndex); }; ItemHandlersCollection.prototype.removeAt = function (index) { var item = _super.prototype.removeAt.call(this, index); if (item) this._onHandlerRemoved(item); return item; }; ItemHandlersCollection.prototype.clear = function () { for (var i = 0; i < this.length; i++) { this.getItem(i).layer = null; } _super.prototype.clear.call(this); }; ItemHandlersCollection.prototype._onHandlerAdded = function (handler) { this._applyLayerAndCanvas(handler); }; ItemHandlersCollection.prototype._onHandlerRemoved = function (handler) { var 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; }; return ItemHandlersCollection; }(Collection)); export { ItemHandlersCollection }; //# sourceMappingURL=ItemHandlersCollection.js.map