@aurigma/design-atoms-model
Version:
Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.
695 lines • 26.6 kB
JavaScript
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.");
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
import { EventObject } from "./EventObject";
import { itemNotFoundInCollection, itemBelongsCollection } from "./Utils/Exceptions";
import Enumerable from "linq";
import "linq-iterator";
import { NotImplementedException, OutOfRangeException, ArgumentException } from "./Exception";
import { CollectionChangeType } from "./ICollectionChangeEventArgs";
var origEnumerableFrom = null;
patch(Enumerable);
var Collection = /** @class */ (function () {
function Collection() {
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
this._collection = [];
this["constructor"] = function (getEnumerator) {
throw new NotImplementedException();
};
this._itemAddedEvent = new EventObject();
this._itemRemovedEvent = new EventObject();
this._itemMovedEvent = new EventObject();
this._enumerable = EnumerableFrom(this._collection);
if (args.length === 0)
return;
this.setRange(args);
}
Collection.prototype.setRange = function (items) {
this.clear();
this.addRange(items);
};
/** Adds the specified items to the end of the collection.*/
Collection.prototype.addRange = function (items) {
if (items instanceof Collection)
items = items._collection;
if (isIEnumerable(items))
items = items.toArray();
for (var i = 0; i < items.length; i++)
this.add(items[i]);
function isIEnumerable(obj) {
return "getEnumerator" in obj && "toArray" in obj;
}
};
Collection.prototype.add = function () {
var e_1, _a;
var items = [];
for (var _i = 0; _i < arguments.length; _i++) {
items[_i] = arguments[_i];
}
try {
for (var items_1 = __values(items), items_1_1 = items_1.next(); !items_1_1.done; items_1_1 = items_1.next()) {
var item = items_1_1.value;
this.insertAt(this._collection.length, item);
}
}
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; }
}
};
Collection.prototype.push = function (item) {
/// <summary>Pushes the specified item to the collection.</summary>
/// <param name="item" type="Type">The item to push.</param>
this.add(item);
return this.length;
};
/**
* Inserts the specified item into the collection at the specified index.
*/
Collection.prototype.insertAt = function (index, items) {
var e_2, _a, _b;
if (!Array.isArray(items))
items = [items];
try {
for (var items_2 = __values(items), items_2_1 = items_2.next(); !items_2_1.done; items_2_1 = items_2.next()) {
var item = items_2_1.value;
this._checkIfItemExists(item);
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (items_2_1 && !items_2_1.done && (_a = items_2.return)) _a.call(items_2);
}
finally { if (e_2) throw e_2.error; }
}
if (index < 0 || index > this._collection.length)
throw new OutOfRangeException();
(_b = this._collection).splice.apply(_b, __spread([index, 0], items));
for (var i = 0; i < items.length; i++) {
var item = items[i];
this._onItemAdded(this._collection.indexOf(item), item);
}
};
Collection.prototype.remove = function (item) {
if (!this.contains(item))
throw new ArgumentException(itemNotFoundInCollection);
return this.removeAt(this.indexOf(item));
};
/**
* Removes the item at the specified index of the collection.
*/
Collection.prototype.removeAt = function (index) {
/// <summary>Removes the item at the specified index of the collection.</summary>
/// <param name="index" type="Number">The zero-based index of the item to remove.</param>
if (index < 0 || index > this._collection.length - 1)
throw new OutOfRangeException();
var item = this._collection[index];
this._collection.splice(index, 1);
this._onItemRemoved(index, item);
return item;
};
Collection.prototype.removeRange = function (from, to) {
var prevCollection = this._collection.slice();
var deletedItems = this._collection.splice(from, to - from + 1);
for (var i = 0; i < deletedItems.length; i++) {
var item = deletedItems[i];
this._onItemRemoved(prevCollection.indexOf(item), item);
}
return deletedItems;
};
Collection.prototype.move = function (oldIndex, newIndex, supressEvent) {
if (!(typeof supressEvent == "boolean"))
supressEvent = false;
var item = this._collection[oldIndex];
if (item && oldIndex >= 0 && newIndex >= 0 && oldIndex != newIndex) {
this._collection.splice(oldIndex, 1);
this._collection.splice(newIndex, 0, item);
if (!supressEvent)
this._onItemMoved(oldIndex, newIndex);
}
return item;
};
/** Removes all items from the collection */
Collection.prototype.clear = function () {
while (this.length > 0) {
this.removeAt(this.length - 1);
}
};
Collection.prototype.replaceAt = function (item, index) {
if (index < 0 || index > this._collection.length - 1)
throw new OutOfRangeException();
this._onItemRemoved(index, this._collection[index]);
this._collection[index] = item;
this._onItemAdded(index, this._collection[index]);
};
Object.defineProperty(Collection.prototype, "length", {
get: function () {
return this._collection.length;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Collection.prototype, "empty", {
get: function () {
return this.length === 0;
},
enumerable: true,
configurable: true
});
//[index: number]: T;
Collection.prototype.get = function (index) {
return this.getItem(index);
};
Collection.prototype.set = function (index, value) {
throw new NotImplementedException();
};
Collection.prototype.getItem = function (index) {
/// <summary>Gets the item at the specified index.</summary>
/// <param name="index" type="Number">The zero-based index of the item to get.</param>
/// <value type="Type">The item at the specified index.</value>
/// <remarks><para>This property corresponds to <see cref="P:Aurigma.GraphicsMill.AjaxControls.VectorObjects.Collection`1.Item(System.Int32)">Item(Int32)</see> server-side member.</para></remarks>
return this._collection[index];
};
Collection.prototype._checkIfItemExists = function (item) {
if (this.contains(item))
throw new ArgumentException(itemBelongsCollection);
};
Collection.prototype._onItemAdded = function (index, item) {
this._itemAddedEvent.notify({ item: item, index: index, type: CollectionChangeType.Add });
};
Collection.prototype.add_itemAdded = function (h) {
this._itemAddedEvent.add(h);
};
Collection.prototype.remove_itemAdded = function (h) {
this._itemAddedEvent.remove(h);
};
Collection.prototype._onItemRemoved = function (index, item) {
this._itemRemovedEvent.notify({ item: item, index: index, type: CollectionChangeType.Remove });
};
Collection.prototype.add_itemRemoved = function (h) {
this._itemRemovedEvent.add(h);
};
Collection.prototype.remove_itemRemoved = function (h) {
this._itemRemovedEvent.remove(h);
};
Collection.prototype._onItemMoved = function (oldIndex, newIndex) {
this._itemMovedEvent.notify({ oldIndex: oldIndex, newIndex: newIndex, type: CollectionChangeType.Move });
};
Collection.prototype.add_itemMoved = function (h) {
this._itemMovedEvent.add(h);
};
Collection.prototype.remove_itemMoved = function (h) {
this._itemMovedEvent.remove(h);
};
Collection.prototype.add_collectionChanged = function (h) {
this.add_itemMoved(h);
this.add_itemRemoved(h);
this.add_itemAdded(h);
};
Collection.prototype.remove_collectionChanged = function (h) {
this.remove_itemMoved(h);
this.remove_itemRemoved(h);
this.remove_itemAdded(h);
};
//#region Iterable implementation
Collection.prototype[Symbol.iterator] = function () {
return this._collection.values();
};
//#endregion
Collection.prototype.toArray = function () {
return this._collection.slice();
};
//#region IEnumerable implementation
Collection.prototype.getEnumerator = function () {
return this._enumerable.getEnumerator();
};
Collection.prototype.traverseBreadthFirst = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).traverseBreadthFirst.apply(_a, __spread(args));
};
Collection.prototype.traverseDepthFirst = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).traverseDepthFirst.apply(_a, __spread(args));
};
Collection.prototype.flatten = function () {
return this._enumerable.flatten();
};
Collection.prototype.pairwise = function (selector) {
return this._enumerable.pairwise(selector);
};
Collection.prototype.scan = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).scan.apply(_a, __spread(args));
};
Collection.prototype.select = function (selector) {
return this._enumerable.select(selector);
};
Collection.prototype.selectMany = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).selectMany.apply(_a, __spread(args));
};
Collection.prototype.where = function (predicate) {
return this._enumerable.where(predicate);
};
Collection.prototype.choose = function (selector) {
return this._enumerable.choose(selector);
};
Collection.prototype.ofType = function (type) {
return this._enumerable.ofType(type);
};
Collection.prototype.zip = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).zip.apply(_a, __spread(args));
};
Collection.prototype.merge = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).merge.apply(_a, __spread(args));
};
Collection.prototype.join = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).join.apply(_a, __spread(args));
};
Collection.prototype.groupJoin = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).groupJoin.apply(_a, __spread(args));
};
Collection.prototype.all = function (predicate) {
return this._enumerable.all(predicate);
};
Collection.prototype.any = function (predicate) {
return this._enumerable.any(predicate);
};
Collection.prototype.isEmpty = function () {
return this._enumerable.isEmpty();
};
Collection.prototype.concat = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).concat.apply(_a, __spread(args));
};
Collection.prototype.alternate = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).alternate.apply(_a, __spread(args));
};
Collection.prototype.defaultIfEmpty = function (defaultValue) {
return this._enumerable.defaultIfEmpty(defaultValue);
};
Collection.prototype.distinct = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).distinct.apply(_a, __spread(args));
};
Collection.prototype.distinctUntilChanged = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).distinctUntilChanged.apply(_a, __spread(args));
};
Collection.prototype.except = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).except.apply(_a, __spread(args));
};
Collection.prototype.intersect = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).intersect.apply(_a, __spread(args));
};
Collection.prototype.union = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).union.apply(_a, __spread(args));
};
Collection.prototype.sequenceEqual = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).sequenceEqual.apply(_a, __spread(args));
};
Collection.prototype.orderBy = function (keySelector) {
return this._enumerable.orderBy(keySelector);
};
Collection.prototype.orderByDescending = function (keySelector) {
return this._enumerable.orderByDescending(keySelector);
};
Collection.prototype.reverse = function () {
return this._enumerable.reverse();
};
Collection.prototype.shuffle = function () {
return this._enumerable.shuffle();
};
Collection.prototype.weightedSample = function (weightSelector) {
return this._enumerable.weightedSample(weightSelector);
};
Collection.prototype.groupBy = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).groupBy.apply(_a, __spread(args));
};
Collection.prototype.partitionBy = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).partitionBy.apply(_a, __spread(args));
};
Collection.prototype.buffer = function (count) {
return this._enumerable.buffer(count);
};
Collection.prototype.aggregate = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).aggregate.apply(_a, __spread(args));
};
Collection.prototype.average = function (selector) {
return this._enumerable.average(selector);
};
Collection.prototype.count = function (predicate) {
return this._enumerable.count(predicate);
};
Collection.prototype.max = function (selector) {
return this._enumerable.max(selector);
};
Collection.prototype.min = function (selector) {
return this._enumerable.min(selector);
};
Collection.prototype.maxBy = function (keySelector) {
return this._enumerable.maxBy(keySelector);
};
Collection.prototype.minBy = function (keySelector) {
return this._enumerable.minBy(keySelector);
};
Collection.prototype.sum = function (selector) {
return this._enumerable.sum(selector);
};
Collection.prototype.elementAt = function (index) {
return this._enumerable.elementAt(index);
};
Collection.prototype.elementAtOrDefault = function (index, defaultValue) {
return this._enumerable.elementAtOrDefault(index, defaultValue);
};
Collection.prototype.first = function (predicate) {
return this._enumerable.first(predicate);
};
Collection.prototype.firstOrDefault = function (predicate, defaultValue) {
if (typeof predicate === "function")
return this._enumerable.firstOrDefault(predicate, defaultValue);
return this._enumerable.firstOrDefault(defaultValue);
};
Collection.prototype.last = function (predicate) {
return this._enumerable.last(predicate);
};
Collection.prototype.lastOrDefault = function (predicate, defaultValue) {
if (typeof predicate === "function")
return this._enumerable.lastOrDefault(predicate, defaultValue);
return this._enumerable.lastOrDefault(defaultValue);
};
Collection.prototype.single = function (predicate) {
return this._enumerable.single(predicate);
};
Collection.prototype.singleOrDefault = function (predicate, defaultValue) {
return this._enumerable.singleOrDefault(predicate, defaultValue);
};
Collection.prototype.skip = function (count) {
return this._enumerable.skip(count);
};
Collection.prototype.skipWhile = function (predicate) {
return this._enumerable.skipWhile(predicate);
};
Collection.prototype.take = function (count) {
return this._enumerable.take(count);
};
Collection.prototype.takeWhile = function (predicate) {
return this._enumerable.takeWhile(predicate);
};
Collection.prototype.takeExceptLast = function (count) {
return this._enumerable.takeExceptLast(count);
};
Collection.prototype.takeFromLast = function (count) {
return this._enumerable.takeFromLast(count);
};
Collection.prototype.indexOf = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).indexOf.apply(_a, __spread(args));
};
Collection.prototype.lastIndexOf = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).lastIndexOf.apply(_a, __spread(args));
};
Collection.prototype.asEnumerable = function () {
return this._enumerable;
};
Collection.prototype.cast = function () {
return this._enumerable.cast();
};
Collection.prototype.toLookup = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).toLookup.apply(_a, __spread(args));
};
Collection.prototype.toObject = function (keySelector, elementSelector) {
return this._enumerable.toObject(keySelector, elementSelector);
};
Collection.prototype.toDictionary = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).toDictionary.apply(_a, __spread(args));
};
Collection.prototype.toJSONString = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).toJSONString.apply(_a, __spread(args));
};
Collection.prototype.toJoinedString = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).toJoinedString.apply(_a, __spread(args));
};
Collection.prototype.doAction = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).doAction.apply(_a, __spread(args));
};
Collection.prototype.forEach = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).forEach.apply(_a, __spread(args));
};
Collection.prototype.write = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).write.apply(_a, __spread(args));
};
Collection.prototype.writeLine = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).writeLine.apply(_a, __spread(args));
};
Collection.prototype.force = function () {
return this._enumerable.force();
};
Collection.prototype.letBind = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).letBind.apply(_a, __spread(args));
};
Collection.prototype.share = function () {
return this._enumerable.share();
};
Collection.prototype.memoize = function () {
return this._enumerable.memoize();
};
Collection.prototype.catchError = function (handler) {
return this._enumerable.catchError(handler);
};
Collection.prototype.finallyAction = function (finallyAction) {
return this._enumerable.finallyAction(finallyAction);
};
Collection.prototype.log = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).log.apply(_a, __spread(args));
};
Collection.prototype.trace = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).trace.apply(_a, __spread(args));
};
Collection.prototype.insert = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).insert.apply(_a, __spread(args));
};
Collection.prototype.contains = function () {
var _a;
var args = [];
for (var _i = 0; _i < arguments.length; _i++) {
args[_i] = arguments[_i];
}
return (_a = this._enumerable).contains.apply(_a, __spread(args));
};
return Collection;
}());
export { Collection };
function patch(enumerable) {
origEnumerableFrom = Enumerable.from;
try {
enumerable.from = function (obj) {
if (obj instanceof Collection)
return obj;
return origEnumerableFrom(obj);
};
}
catch (ex) {
console.error("unable to patch Enumerable", ex);
}
}
function EnumerableFrom(enumerable) {
if (enumerable instanceof Collection)
return enumerable;
else if (origEnumerableFrom)
return origEnumerableFrom(enumerable);
return Enumerable.from(enumerable);
}
//# sourceMappingURL=Collection.js.map