@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.
481 lines • 21.4 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 __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { BaseItem } from "./BaseItem";
import { SurfaceContainer } from "../Container";
import { ManipulationPermissions } from "./ManipulationPermissions";
import { VisualizationPermissions } from "./VisualizationPermissions";
import { ItemPermissions } from "./ItemPermissions";
import { FrontendPermissions } from "./FrontEndPermissions";
import { ArgumentException, InvalidOperationException, NotImplementedException } from "../../Exception";
import { EventObject, EventWithAutoSenderArg } from "../../EventObject";
import * as Math from "../../Math/index";
import { Transform } from "../../Math/Transform";
import { WrappingMode } from "./WrappingMode";
import { ThemeBinding } from "./ThemeBinding";
import * as _ from "underscore";
import { RenderingType } from "../RenderingType";
import { BlendMode } from "./BlendMode";
import { ItemMask } from "../ItemMask";
import { equals } from "../../Utils/Utils";
import { Property } from "../Decorators/Property";
import { ViolationSettings } from "./ViolationSettings";
import { ObjectPropertyFactory } from "../Decorators/Factory";
var Item = /** @class */ (function (_super) {
__extends(Item, _super);
function Item() {
var _this = _super.call(this) || this;
_this._visible = true;
_this._locked = false;
_this._opacity = 1.0;
_this._fromLayout = false;
_this._textWrappingMode = WrappingMode.None;
_this._isVariable = false;
_this._blendMode = BlendMode.Normal;
_this._ignorePermissionsChange = false;
_this._mask = null;
_this._class = null;
_this._onPermissionsChanged = function () {
if (_this._ignorePermissionsChange)
return;
_this._ignorePermissionsChange = true;
_this.applyPermissionsConstrain();
_this._ignorePermissionsChange = false;
_this._propertyChanged.notify(_this, "permissions");
};
_this._parentGroupItem = null;
_this.themeBinding = new ThemeBinding();
_this._onTransformChanged = function (t) {
_this._propertyChanged.notify(_this, "transform");
};
_this._onMaskChanged = function (m) {
_this._propertyChanged.notify(_this, "mask");
};
_this._changedEvent = new EventWithAutoSenderArg(_this);
_this._changingEvent = new EventObject();
_this.type = Item.type;
var itemPermissions = new ItemPermissions();
itemPermissions.allowRemoveOnLayoutChange = false;
_this.itemPermissions = itemPermissions;
_this.setManipulationPermissions(new ManipulationPermissions());
_this.visualizationPermissions = new VisualizationPermissions();
_this.frontendPermissions = new FrontendPermissions();
_this._setViolationSettings(new ViolationSettings(), true);
_this.setTransform(new Transform());
return _this;
}
Item.prototype._copy = function (source, destination, generateNewIds, appropriateParentContainer) {
_super.prototype._copy.call(this, source, destination, generateNewIds, appropriateParentContainer);
destination.itemPermissions = source._itemPermissions.clone();
destination.visible = source._visible;
destination.locked = source._locked;
destination.opacity = source._opacity;
destination.isVariable = source._isVariable;
destination.textWrappingMode = source._textWrappingMode;
destination.setManipulationPermissions(source._manipulationPermissions.clone());
destination.visualizationPermissions = source._visualizationPermissions.clone();
destination.frontendPermissions = source._frontendPermissions.clone();
destination.violationSettings = source._violationSettings.clone();
destination.transform = source._transform.clone();
destination.containerName = source.containerName;
destination.themeBinding = source.themeBinding.clone();
destination.mask = source.mask != null ? source.mask.clone() : null;
destination.blendMode = source.blendMode;
destination.class = source.class;
};
Item.prototype.equals = function (other) {
var superEq = _super.prototype.equals.call(this, other);
var itemPermissionsEq = equals(this._itemPermissions, other._itemPermissions);
var visibleEq = equals(this._visible, other._visible);
var lockedEq = equals(this._locked, other._locked);
var opacityEq = equals(this._opacity, other._opacity);
var isVariableEq = equals(this._isVariable, other._isVariable);
var textWrappingModeEq = equals(this._textWrappingMode, other._textWrappingMode);
var manipulationPermissionsEq = equals(this._manipulationPermissions, other._manipulationPermissions);
var visualizationPermissionsEq = equals(this._visualizationPermissions, other._visualizationPermissions);
var frontendPermissionsEq = equals(this._frontendPermissions, other._frontendPermissions);
var transformEq = equals(this._transform, other._transform);
var violationEq = equals(this._violationSettings, other._violationSettings);
var containerNameEq = equals(this.containerName, other.containerName);
var themeBindingEq = equals(this.themeBinding, other.themeBinding);
var maskEq = equals(this._mask, other._mask);
var blendModeEq = equals(this.blendMode, other.blendMode);
var classEq = equals(this.class, other.class);
return superEq && itemPermissionsEq && visibleEq && lockedEq && opacityEq && isVariableEq && textWrappingModeEq
&& manipulationPermissionsEq && visualizationPermissionsEq && frontendPermissionsEq && transformEq
&& violationEq && containerNameEq && themeBindingEq && maskEq && blendModeEq && classEq;
};
Object.defineProperty(Item.prototype, "class", {
get: function () {
return this._class;
},
set: function (value) {
if (this._class == value)
return;
this._class = value;
this._propertyChanged.notify(this, "class");
},
enumerable: true,
configurable: true
});
Object.defineProperty(Item.prototype, "manipulationPermissions", {
get: function () { return this.getManipulationPermissions(); },
set: function (value) { this.setManipulationPermissions(value); },
enumerable: true,
configurable: true
});
Item.prototype.getManipulationPermissions = function () { return this._manipulationPermissions; };
Item.prototype.setManipulationPermissions = function (value) {
if (value == null)
throw new ArgumentException("manipulationPermissions cannot be null");
if (equals(this._manipulationPermissions, value))
return;
if (this._manipulationPermissions != null)
this._manipulationPermissions.propertyChanged.remove(this._onPermissionsChanged);
this._manipulationPermissions = value;
this.applyPermissionsConstrain();
this._manipulationPermissions.propertyChanged.add(this._onPermissionsChanged);
this._propertyChanged.notify(this, "manipulationPermissions");
};
Object.defineProperty(Item.prototype, "visualizationPermissions", {
get: function () {
return this._visualizationPermissions;
},
set: function (value) {
if (value == null)
throw new ArgumentException("visualizationPermissions cannot be null");
if (equals(this._visualizationPermissions, value))
return;
if (this._visualizationPermissions != null)
this._visualizationPermissions.propertyChanged.remove(this._onPermissionsChanged);
this._visualizationPermissions = value;
this.applyPermissionsConstrain();
this._visualizationPermissions.propertyChanged.add(this._onPermissionsChanged);
this._propertyChanged.notify(this, "visualizationPermissions");
},
enumerable: true,
configurable: true
});
Object.defineProperty(Item.prototype, "itemPermissions", {
get: function () {
return this._itemPermissions;
},
set: function (value) {
if (value == null)
throw new ArgumentException("itemPermissions cannot be null");
if (equals(this._itemPermissions, value))
return;
if (this._itemPermissions != null)
this._itemPermissions.propertyChanged.remove(this._onPermissionsChanged);
this._itemPermissions = value;
this.applyPermissionsConstrain();
this._itemPermissions.propertyChanged.add(this._onPermissionsChanged);
this._propertyChanged.notify(this, "itemPermissions");
},
enumerable: true,
configurable: true
});
Object.defineProperty(Item.prototype, "frontendPermissions", {
get: function () {
return this._frontendPermissions;
},
set: function (value) {
if (value == null)
throw new ArgumentException("frontendPermissions cannot be null");
if (equals(this._frontendPermissions, value))
return;
if (this._frontendPermissions != null)
this._frontendPermissions.propertyChanged.remove(this._onPermissionsChanged);
this._frontendPermissions = value;
this.applyPermissionsConstrain();
this._frontendPermissions.propertyChanged.add(this._onPermissionsChanged);
this._propertyChanged.notify(this, "frontendPermissions");
},
enumerable: true,
configurable: true
});
Object.defineProperty(Item.prototype, "violationSettings", {
get: function () {
return this._violationSettings;
},
set: function (value) {
this._setViolationSettings(value);
},
enumerable: true,
configurable: true
});
Item.prototype._setViolationSettings = function (value, skipTypeCheck) {
if (skipTypeCheck === void 0) { skipTypeCheck = false; }
if (value == null)
throw new ArgumentException("violationSettings cannot be null");
if (equals(this._violationSettings, value))
return;
if (this._violationSettings != null)
this._violationSettings.removePropertyChanged(this._onPermissionsChanged);
this._violationSettings = value;
this.applyPermissionsConstrain();
this._violationSettings.addPropertyChanged(this._onPermissionsChanged);
this._propertyChanged.notify(this, "violationSettings");
};
Item.prototype.applyPermissionsConstrain = function () {
if (this.isRenderTypeIsNormal)
return;
this.itemPermissions.allowOpacityChange = false;
};
Item.prototype._onContainerChanged = function () {
_super.prototype._onContainerChanged.call(this);
this.applyPermissionsConstrain();
};
Object.defineProperty(Item.prototype, "parentGroupItem", {
get: function () {
return this._parentGroupItem;
},
set: function (value) {
this._parentGroupItem = value;
if (value != null)
this.parentContainer = this._parentGroupItem.parentContainer;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Item.prototype, "blendMode", {
get: function () {
return this._blendMode;
},
set: function (value) {
if (this._blendMode === value)
return;
this._blendMode = value;
this._propertyChanged.notify(this, "blendMode");
},
enumerable: true,
configurable: true
});
Object.defineProperty(Item.prototype, "transform", {
get: function () {
return this._transform;
},
set: function (value) {
this.setTransform(value);
},
enumerable: true,
configurable: true
});
Item.prototype.setTransform = function (value, suppressOnChanged) {
if (suppressOnChanged === void 0) { suppressOnChanged = false; }
if (this._transform)
this._transform.removeTransformChanged(this._onTransformChanged);
var changed = false;
if (!Transform.isEqual(this._transform, value)) {
this._transform = value;
changed = true;
}
if (this._transform)
this._transform.addTransformChanged(this._onTransformChanged);
if (!suppressOnChanged && changed)
this._propertyChanged.notify(this, "transform");
};
Object.defineProperty(Item.prototype, "textWrappingMode", {
get: function () {
return this._textWrappingMode;
},
set: function (value) {
if (this._textWrappingMode !== value) {
this._textWrappingMode = value;
this._propertyChanged.notify(this, "textWrappingMode");
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(Item.prototype, "locked", {
get: function () {
return this._locked;
},
set: function (value) {
if (this._locked !== value) {
this._locked = value;
this._propertyChanged.notify(this, "locked");
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(Item.prototype, "mask", {
get: function () {
return this._mask;
},
set: function (value) {
if (equals(this.mask, value))
return;
if (this._mask != null)
this._mask.removeMaskChanged(this._onMaskChanged);
this._mask = value;
if (this._mask != null)
this._mask.addMaskChanged(this._onMaskChanged);
this._propertyChanged.notify(this, "mask");
},
enumerable: true,
configurable: true
});
Object.defineProperty(Item.prototype, "visible", {
get: function () {
return this._visible;
},
set: function (value) {
if (this._visible === value)
return;
this._visible = value;
this._propertyChanged.notify(this, "visible");
},
enumerable: true,
configurable: true
});
Object.defineProperty(Item.prototype, "opacity", {
get: function () {
return this._opacity;
},
set: function (value) {
if (!Math.EqualsOfFloatNumbers(this._opacity, value)) {
this._opacity = value;
this._propertyChanged.notify(this, "opacity");
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(Item.prototype, "isVariable", {
get: function () {
return this._isVariable;
},
set: function (value) {
if (this._isVariable === value)
return;
if (!this._canSetIsVariable()) {
throw new InvalidOperationException("Unable to set isVariable on item of type '" + this.type + "'");
}
this._isVariable = value;
this._propertyChanged.notify(this, "isVariable");
},
enumerable: true,
configurable: true
});
Object.defineProperty(Item.prototype, "fromLayout", {
get: function () {
return this._fromLayout;
},
set: function (value) {
if (this._fromLayout === value)
return;
this._fromLayout = value;
this._propertyChanged.notify(this, "fromLayout");
},
enumerable: true,
configurable: true
});
Item.prototype.canSetIsVariable = function () {
return this._canSetIsVariable();
};
Item.prototype._canSetIsVariable = function () { return false; };
Item.prototype._getParentContainer = function () {
if (this.parentContainer != null)
return this.parentContainer;
return null;
};
Item.prototype.getSimplifiedObject = function (omitProperties) {
if (!_.isArray(omitProperties) && !_.isString(omitProperties))
omitProperties = [];
var simplified = _super.prototype.getSimplifiedObject.call(this, [
"_changedEvent",
"_changingEvent",
"manipulationPermissions",
"itemPermissions",
"visualizationPermissions",
"frontendPermissions",
"renderingType",
"isRenderTypeIsNormal",
"parentGroupItem"
].concat(omitProperties));
simplified["manipulationPermissions"] = this.manipulationPermissions.getSimplifiedObject();
simplified["itemPermissions"] = this.itemPermissions.getSimplifiedObject();
simplified["visualizationPermissions"] = this.visualizationPermissions.getSimplifiedObject();
simplified["frontendPermissions"] = this.frontendPermissions.getSimplifiedObject();
simplified["mask"] = this.mask != null ? this.mask.getSimplifiedObject() : null;
return simplified;
};
Item.prototype.getItemChangedEvent = function () {
return this._changedEvent;
};
Item.prototype.getItemChangingEvent = function () {
return this._changingEvent;
};
Item.prototype._getThemeBinding = function (themeBinding) {
return themeBinding != null ? themeBinding : this.themeBinding;
};
Item.prototype._applyThemeColor = function (colorName, theme, updateFunc) {
throw new NotImplementedException();
};
Object.defineProperty(Item.prototype, "isRenderTypeIsNormal", {
//#endregion
get: function () {
return this.renderingType === RenderingType.Normal;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Item.prototype, "renderingType", {
get: function () {
return this.parentContainer instanceof SurfaceContainer ? this.parentContainer.renderingType : RenderingType.Normal;
},
enumerable: true,
configurable: true
});
Item.type = "item";
__decorate([
Property({ displayName: "Class" }),
__metadata("design:type", String),
__metadata("design:paramtypes", [String])
], Item.prototype, "class", null);
__decorate([
Property({ enumObject: BlendMode, displayName: "Blend mode" }),
__metadata("design:type", String),
__metadata("design:paramtypes", [String])
], Item.prototype, "blendMode", null);
__decorate([
Property({ enumObject: WrappingMode }),
__metadata("design:type", Number),
__metadata("design:paramtypes", [Number])
], Item.prototype, "textWrappingMode", null);
__decorate([
Property({ displayName: "Locked" }),
__metadata("design:type", Boolean),
__metadata("design:paramtypes", [Boolean])
], Item.prototype, "locked", null);
__decorate([
Property({ factory: new ObjectPropertyFactory(ItemMask) }),
__metadata("design:type", ItemMask),
__metadata("design:paramtypes", [ItemMask])
], Item.prototype, "mask", null);
return Item;
}(BaseItem));
export { Item };
//# sourceMappingURL=Item.js.map