@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.
142 lines • 5.98 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 { EventObject } from "../../EventObject";
import { ResizeGripsPermissions } from "./ResizeGripsPermissions";
import { equals } from "../../Utils/Utils";
import { Property } from "../Decorators/Property";
export class ManipulationPermissions {
get allowDelete() {
return this._allowDelete;
}
set allowDelete(value) {
if (this._allowDelete === value)
return;
this._allowDelete = value;
this.propertyChanged.notify();
}
get allowMoveHorizontal() {
return this._allowMoveHorizontal;
}
set allowMoveHorizontal(value) {
if (this._allowMoveHorizontal === value)
return;
this._allowMoveHorizontal = value;
this.propertyChanged.notify();
}
get allowMoveVertical() {
return this._allowMoveVertical;
}
set allowMoveVertical(value) {
if (this._allowMoveVertical === value)
return;
this._allowMoveVertical = value;
this.propertyChanged.notify();
}
get allowMove() {
return this.allowMoveVertical || this.allowMoveHorizontal;
}
set allowRotateConstraint(value) {
const oldValue = this.allowRotate;
this._allowRotateConstraint = value;
if (this.allowRotate !== oldValue)
this.propertyChanged.notify();
}
get allowRotate() {
return this._allowRotateConstraint != null
? this._allowRotateConstraint
: this._allowRotate;
}
set allowRotate(value) {
if (this._allowRotate === value)
return;
this._allowRotate = value;
this.propertyChanged.notify();
}
get allowDragAndDrop() {
return this._allowDragAndDrop;
}
set allowDragAndDrop(value) {
if (this._allowDragAndDrop === value)
return;
this._allowDragAndDrop = value;
this.propertyChanged.fire();
}
get resizeGrips() {
return this._resizeGrips;
}
set resizeGrips(value) {
if (this.resizeGrips != null && this.resizeGrips.propertyChanged != null) {
this.resizeGrips.propertyChanged.remove(this._firePropertyChanged);
}
this._resizeGrips = value;
if (this.resizeGrips.propertyChanged != null) {
this.resizeGrips.propertyChanged.add(this._firePropertyChanged);
}
this.propertyChanged.notify();
}
get allowResize() {
return this.resizeGrips.edge || this.resizeGrips.corner.length > 0;
}
constructor(defaultValue = true) {
this._allowRotateConstraint = null;
this.propertyChanged = new EventObject();
this._firePropertyChanged = () => this.propertyChanged.notify();
this.type = ManipulationPermissions.type;
this.allowDelete = defaultValue;
this.allowMoveHorizontal = defaultValue;
this.allowMoveVertical = defaultValue;
this.allowRotate = defaultValue;
this.allowDragAndDrop = defaultValue;
this.resizeGrips = new ResizeGripsPermissions(defaultValue, defaultValue);
}
clone() {
const clone = new ManipulationPermissions();
clone.allowDelete = this.allowDelete;
clone.allowDragAndDrop = this.allowDragAndDrop;
clone.allowMoveHorizontal = this.allowMoveHorizontal;
clone.allowMoveVertical = this.allowMoveVertical;
clone.allowRotate = this.allowRotate;
clone.allowRotateConstraint = this.allowRotateConstraint;
clone.resizeGrips = this.resizeGrips.clone();
return clone;
}
equals(p) {
return this.allowDelete === p.allowDelete &&
this.allowDragAndDrop === p.allowDragAndDrop &&
this.allowMoveHorizontal === p.allowMoveHorizontal &&
this.allowMoveVertical === p.allowMoveVertical &&
this.allowRotate === p.allowRotate &&
this.allowRotateConstraint === p.allowRotateConstraint &&
equals(this.resizeGrips, p.resizeGrips);
}
getSimplifiedObject() {
const result = {};
result["allowDelete"] = this.allowDelete;
result["resizeGrips"] = this.resizeGrips.getSimplifiedObject();
result["allowMoveHorizontal"] = this.allowMoveHorizontal;
result["allowMoveVertical"] = this.allowMoveVertical;
result["allowRotate"] = this.allowRotate;
result["allowDragAndDrop"] = this.allowDragAndDrop;
return result;
}
static CreateFromRaw(raw) {
const resizeGrips = Object.assign(new ResizeGripsPermissions(true, true), raw["resizeGrips"]);
const maniplationsPermissions = Object.assign(new ManipulationPermissions(), raw);
maniplationsPermissions.resizeGrips = resizeGrips;
return maniplationsPermissions;
}
}
ManipulationPermissions.type = "ManipulationPermissions";
__decorate([
Property({ ignore: true }),
__metadata("design:type", Boolean),
__metadata("design:paramtypes", [Boolean])
], ManipulationPermissions.prototype, "allowRotateConstraint", null);
//# sourceMappingURL=ManipulationPermissions.js.map