UNPKG

@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.

221 lines 9.8 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 __()); }; })(); 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; }; 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 { Item } from "./Item"; import { Collection } from "../../Collection"; import { GroupItemPermissions } from "./GroupItemPermissions"; import { ArgumentException } from "../../Exception"; import { arrayEquals, equals } from "../../Utils/Utils"; var GroupItem = /** @class */ (function (_super) { __extends(GroupItem, _super); function GroupItem(items) { var _this = _super.call(this) || this; _this.items = new Collection(); _this.type = GroupItem.type; _this.groupItemPermissions = new GroupItemPermissions(); _this._ignorePermissionsChange = true; _this._groupItemPermissions.allowReplaceContent = false; _this._ignorePermissionsChange = false; _this.items.add_itemAdded(function (collectionItem) { collectionItem.item.parentGroupItem = _this; _this._propertyChanged.notify(_this, "items"); }); _this.items.add_itemRemoved(function (collectionItem) { collectionItem.item.parentGroupItem = null; _this._propertyChanged.notify(_this, "items"); }); if (items != null) _this.items.addRange(items); return _this; } Object.defineProperty(GroupItem.prototype, "groupItemPermissions", { get: function () { return this._groupItemPermissions; }, set: function (value) { if (value == null) throw new ArgumentException("groupItemPermissions cannot be null"); if (equals(this._groupItemPermissions, value)) return; if (this._groupItemPermissions != null) this._groupItemPermissions.propertyChanged.remove(this._onPermissionsChanged); this._groupItemPermissions = value; this._groupItemPermissions.propertyChanged.add(this._onPermissionsChanged); this._onPermissionsChanged(); }, enumerable: true, configurable: true }); GroupItem.prototype.addItems = function (items, targetIndex) { var _a; if (targetIndex != null) items = items.reverse(); if (items == null || items.length === 0) return; if (targetIndex != null && targetIndex > -1) this.items.insertAt(targetIndex, items); else (_a = this.items).add.apply(_a, __spread(items)); }; GroupItem.prototype._onContainerChanged = function () { var _this = this; this.applyToItems(function (item) { item.parentContainer = _this.parentContainer; }); }; GroupItem.prototype.addItem = function (item, targetIndex) { if (targetIndex != null && targetIndex > -1) this.items.insertAt(targetIndex, item); else this.items.add(item); }; GroupItem.prototype.removeItems = function (items) { var e_1, _a; if (items != null && items.length > 0) 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.items.remove(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; } } }; GroupItem.prototype.getNestedItems = function (excludeGroupItems) { if (excludeGroupItems === void 0) { excludeGroupItems = false; } var allNestedItems = []; var items = __spread(this.items); while (items.length > 0) { var item = items.shift(); if (item instanceof GroupItem) { items.splice.apply(items, __spread([items.indexOf(item), 0], item.items)); if (excludeGroupItems) continue; } allNestedItems.push(item); } return allNestedItems; }; GroupItem.prototype.getSimplifiedObject = function (omitProperties) { if (omitProperties === void 0) { omitProperties = []; } var simplified = _super.prototype.getSimplifiedObject.call(this, [ "groupManipulationPermissions", "itemRemovedEvent", "groupItemPermissions", "items" ].concat(omitProperties)); simplified["items"] = this.items.toArray().map(function (item) { return item.getSimplifiedObject(); }); simplified["groupItemPermissions"] = this.groupItemPermissions.getSimplifiedObject(); return simplified; }; GroupItem.prototype._copy = function (source, destination, generateNewIds, appropriateParentContainer) { _super.prototype._copy.call(this, source, destination, generateNewIds, appropriateParentContainer); if (source.items.length <= 0) return; var items = source.items.toArray().map(function (item) { return item.clone(generateNewIds, appropriateParentContainer); }); destination.items.clear(); destination.items.addRange(items); destination.groupItemPermissions = source.groupItemPermissions.clone(); }; GroupItem.prototype.clone = function (generateNewIds, appropriateParentContainer) { if (generateNewIds === void 0) { generateNewIds = false; } if (appropriateParentContainer === void 0) { appropriateParentContainer = false; } var item = new GroupItem(); this._copy(this, item, generateNewIds, appropriateParentContainer); return item; }; GroupItem.prototype.applyPermissionsConstrain = function () { _super.prototype.applyPermissionsConstrain.call(this); this.itemPermissions.itemToolbarPermissions.showEditButton = false; this.itemPermissions.itemToolbarPermissions.showSelectButton = false; }; GroupItem.prototype.applyToItems = function (func) { this.items.forEach(func); }; Object.defineProperty(GroupItem.prototype, "manipulationPermissions", { get: function () { if (this.items.length === 0) return this.groupManipulationPermissions; var manipulationPermissions = this.groupManipulationPermissions.clone(); this.getNestedItems(true).forEach(function (item) { manipulationPermissions.allowDelete = manipulationPermissions.allowDelete && item.manipulationPermissions.allowDelete; }); Object.freeze(manipulationPermissions); return manipulationPermissions; }, set: function (value) { throw new Error("You cannot use ManipulationPermissions setter with GroupItem. Use groupManipulationPermissions setter instead"); }, enumerable: true, configurable: true }); Object.defineProperty(GroupItem.prototype, "groupManipulationPermissions", { get: function () { return _super.prototype.getManipulationPermissions.call(this); }, set: function (value) { _super.prototype.setManipulationPermissions.call(this, value); }, enumerable: true, configurable: true }); GroupItem.prototype.isChildVisible = function (child) { return true; }; GroupItem.prototype.equals = function (other) { var superEq = _super.prototype.equals.call(this, other); var groupItemPermissionsEq = equals(this.groupItemPermissions, other.groupItemPermissions); var itemsEq = arrayEquals(__spread(this.items), __spread(other.items)); return superEq && groupItemPermissionsEq && itemsEq; }; GroupItem.type = "GroupItem"; return GroupItem; }(Item)); export { GroupItem }; //# sourceMappingURL=GroupItem.js.map