@aurigma/design-atoms
Version:
Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.
144 lines • 5.85 kB
JavaScript
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 __());
};
})();
var __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
import { Collection } from "@aurigma/design-atoms-model/Collection";
import { itemBelongsCollection } from "@aurigma/design-atoms-model/Utils/Exceptions";
import { ArgumentException } from "@aurigma/design-atoms-model/Exception";
var LayerCollection = /** @class */ (function (_super) {
__extends(LayerCollection, _super);
function LayerCollection(_canvas) {
var _this = _super.call(this) || this;
_this._canvas = _canvas;
return _this;
}
LayerCollection.prototype.getLayerById = function (id) {
for (var i = 0, imax = this.length; i < imax; i++) {
var layer = this.getItem(i);
if (layer.uniqueId == id) {
return layer;
}
}
return null;
};
LayerCollection.prototype.getLayerByContainerId = function (id) {
for (var i = 0, imax = this.length; i < imax; i++) {
var layer = this.getItem(i);
if (layer.container.id == id) {
return layer;
}
}
return null;
};
LayerCollection.prototype.getLayersByName = function (name) {
/// <summary>Search layers with the specified name.</summary>
/// <param name="name" type="String">The name to search layers.</param>
/// <returns type="Array">An array of layers contained in this collection and match the specified name.</returns>
/// <remarks><para>This method corresponds to <see cref="M:Aurigma.GraphicsMill.AjaxControls.VectorObjects.LayerCollection.GetLayersByName(System.String)">LayerCollection.GetLayersByName(String)</see> server-side member.</para></remarks>
var ll = [];
for (var i = 0; i < this.length; i++) {
if (this.getItem(i).name == name) {
ll.push(this.getItem(i));
}
}
return ll;
};
LayerCollection.prototype.getItemHandlersByName = function (name) {
var ol = [];
for (var i = 0; i < this.length; i++) {
var l = this.getItem(i);
for (var j = 0; j < l.itemHandlers.length; j++) {
if (l.itemHandlers.getItem(j).name === name) {
ol.push(l.itemHandlers.getItem(j));
}
}
}
return ol;
};
LayerCollection.prototype.removeRange = function (from, to) {
var removeHandler = function (args) {
this._onLayerRemoved(args.item, args.index);
}.bind(this);
try {
this.add_itemRemoved(removeHandler);
return _super.prototype.removeRange.call(this, from, to);
}
finally {
this.remove_itemRemoved(removeHandler);
}
};
LayerCollection.prototype.insertAt = function (index, items) {
var e_1, _a;
if (!Array.isArray(items))
items = [items];
try {
for (var items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
var layer_1 = items_1_1.value;
if (this.contains(layer_1))
throw new ArgumentException(itemBelongsCollection);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (items_1_1 && !items_1_1.done && (_a = items_1.return)) _a.call(items_1);
}
finally { if (e_1) throw e_1.error; }
}
_super.prototype.insertAt.call(this, index, items);
for (var i = 0; i < items.length; i++) {
var layer = items[i];
this._onLayerAdded(layer);
}
};
LayerCollection.prototype.move = function (oldIndex, newIndex) {
var item = _super.prototype.move.call(this, oldIndex, newIndex);
return item;
};
LayerCollection.prototype.clear = function () {
var e_2, _a;
try {
for (var _b = __values(this), _c = _b.next(); !_c.done; _c = _b.next()) {
var removingLayer = _c.value;
removingLayer.dispose();
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_2) throw e_2.error; }
}
_super.prototype.clear.call(this);
};
LayerCollection.prototype._onLayerAdded = function (layer) {
if (this._canvas) {
layer.canvas = this._canvas;
layer.onLayerAdded();
}
};
return LayerCollection;
}(Collection));
export { LayerCollection };
//# sourceMappingURL=LayerCollection.js.map