@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.
389 lines • 17 kB
JavaScript
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 { RenderingType } from "../RenderingType";
import { BlendMode } from "./BlendMode";
import { ItemMask } from "../ItemMask";
import { equals, isString } from "../../Utils/Utils";
import { Property } from "../Decorators/Property";
import { ViolationSettings } from "./ViolationSettings";
import { ObjectPropertyFactory } from "../Decorators/Factory";
export class Item extends BaseItem {
constructor() {
super();
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 = () => {
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 = (t) => {
this._propertyChanged.notify(this, "transform");
};
this._onMaskChanged = (m) => {
this._propertyChanged.notify(this, "mask");
};
this._changedEvent = new EventWithAutoSenderArg(this);
this._changingEvent = new EventObject();
this.type = Item.type;
const 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());
}
_copy(source, destination, generateNewIds, appropriateParentContainer) {
super._copy(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;
}
equals(other) {
const superEq = super.equals(other);
const itemPermissionsEq = equals(this._itemPermissions, other._itemPermissions);
const visibleEq = equals(this._visible, other._visible);
const lockedEq = equals(this._locked, other._locked);
const opacityEq = equals(this._opacity, other._opacity);
const isVariableEq = equals(this._isVariable, other._isVariable);
const textWrappingModeEq = equals(this._textWrappingMode, other._textWrappingMode);
const manipulationPermissionsEq = equals(this._manipulationPermissions, other._manipulationPermissions);
const visualizationPermissionsEq = equals(this._visualizationPermissions, other._visualizationPermissions);
const frontendPermissionsEq = equals(this._frontendPermissions, other._frontendPermissions);
const transformEq = equals(this._transform, other._transform);
const violationEq = equals(this._violationSettings, other._violationSettings);
const containerNameEq = equals(this.containerName, other.containerName);
const themeBindingEq = equals(this.themeBinding, other.themeBinding);
const maskEq = equals(this._mask, other._mask);
const blendModeEq = equals(this.blendMode, other.blendMode);
const classEq = equals(this.class, other.class);
return superEq && itemPermissionsEq && visibleEq && lockedEq && opacityEq && isVariableEq && textWrappingModeEq
&& manipulationPermissionsEq && visualizationPermissionsEq && frontendPermissionsEq && transformEq
&& violationEq && containerNameEq && themeBindingEq && maskEq && blendModeEq && classEq;
}
get class() {
return this._class;
}
set class(value) {
if (this._class == value)
return;
this._class = value;
this._propertyChanged.notify(this, "class");
}
get manipulationPermissions() { return this.getManipulationPermissions(); }
set manipulationPermissions(value) { this.setManipulationPermissions(value); }
getManipulationPermissions() { return this._manipulationPermissions; }
setManipulationPermissions(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");
}
get visualizationPermissions() {
return this._visualizationPermissions;
}
set visualizationPermissions(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");
}
get itemPermissions() {
return this._itemPermissions;
}
set itemPermissions(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");
}
get frontendPermissions() {
return this._frontendPermissions;
}
set frontendPermissions(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");
}
get violationSettings() {
return this._violationSettings;
}
set violationSettings(value) {
this._setViolationSettings(value);
}
_setViolationSettings(value, 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");
}
applyPermissionsConstrain() {
if (this.isRenderTypeIsNormal)
return;
this.itemPermissions.allowOpacityChange = false;
}
_onContainerChanged() {
super._onContainerChanged();
this.applyPermissionsConstrain();
}
get parentGroupItem() {
return this._parentGroupItem;
}
set parentGroupItem(value) {
this._parentGroupItem = value;
if (value != null)
this.parentContainer = this._parentGroupItem.parentContainer;
}
get blendMode() {
return this._blendMode;
}
set blendMode(value) {
if (this._blendMode === value)
return;
this._blendMode = value;
this._propertyChanged.notify(this, "blendMode");
}
get transform() {
return this._transform;
}
set transform(value) {
this.setTransform(value);
}
setTransform(value, suppressOnChanged = false) {
if (this._transform)
this._transform.removeTransformChanged(this._onTransformChanged);
let 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");
}
get textWrappingMode() {
return this._textWrappingMode;
}
set textWrappingMode(value) {
if (this._textWrappingMode !== value) {
this._textWrappingMode = value;
this._propertyChanged.notify(this, "textWrappingMode");
}
}
get locked() {
return this._locked;
}
set locked(value) {
if (this._locked !== value) {
this._locked = value;
this._propertyChanged.notify(this, "locked");
}
}
get mask() {
return this._mask;
}
set mask(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");
}
get visible() {
return this._visible;
}
set visible(value) {
if (this._visible === value)
return;
this._visible = value;
this._propertyChanged.notify(this, "visible");
}
get opacity() {
return this._opacity;
}
set opacity(value) {
if (!Math.EqualsOfFloatNumbers(this._opacity, value)) {
this._opacity = value;
this._propertyChanged.notify(this, "opacity");
}
}
get isVariable() {
return this._isVariable;
}
set isVariable(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");
}
get fromLayout() {
return this._fromLayout;
}
set fromLayout(value) {
if (this._fromLayout === value)
return;
this._fromLayout = value;
this._propertyChanged.notify(this, "fromLayout");
}
canSetIsVariable() {
return this._canSetIsVariable();
}
_canSetIsVariable() { return false; }
_getParentContainer() {
if (this.parentContainer != null)
return this.parentContainer;
return null;
}
getSimplifiedObject(omitProperties) {
if (!Array.isArray(omitProperties) && !isString(omitProperties))
omitProperties = [];
const simplified = super.getSimplifiedObject([
"_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;
}
getItemChangedEvent() {
return this._changedEvent;
}
getItemChangingEvent() {
return this._changingEvent;
}
_getThemeBinding(themeBinding) {
return themeBinding != null ? themeBinding : this.themeBinding;
}
_applyThemeColor(colorName, theme, updateFunc) {
throw new NotImplementedException();
}
//#endregion
get isRenderTypeIsNormal() {
return this.renderingType === RenderingType.Normal;
}
get renderingType() {
return this.parentContainer instanceof SurfaceContainer ? this.parentContainer.renderingType : RenderingType.Normal;
}
}
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);
//# sourceMappingURL=Item.js.map