@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.
183 lines • 7.97 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 * as _ from "underscore";
import { equals } from "../../Utils/Utils";
import { Property } from "../Decorators/Property";
var ManipulationPermissions = /** @class */ (function () {
function ManipulationPermissions(defaultValue) {
var _this = this;
if (defaultValue === void 0) { defaultValue = true; }
this._allowRotateConstraint = null;
this.propertyChanged = new EventObject();
this._firePropertyChanged = function () { return _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);
}
Object.defineProperty(ManipulationPermissions.prototype, "allowDelete", {
get: function () {
return this._allowDelete;
},
set: function (value) {
if (this._allowDelete === value)
return;
this._allowDelete = value;
this.propertyChanged.notify();
},
enumerable: true,
configurable: true
});
Object.defineProperty(ManipulationPermissions.prototype, "allowMoveHorizontal", {
get: function () {
return this._allowMoveHorizontal;
},
set: function (value) {
if (this._allowMoveHorizontal === value)
return;
this._allowMoveHorizontal = value;
this.propertyChanged.notify();
},
enumerable: true,
configurable: true
});
Object.defineProperty(ManipulationPermissions.prototype, "allowMoveVertical", {
get: function () {
return this._allowMoveVertical;
},
set: function (value) {
if (this._allowMoveVertical === value)
return;
this._allowMoveVertical = value;
this.propertyChanged.notify();
},
enumerable: true,
configurable: true
});
Object.defineProperty(ManipulationPermissions.prototype, "allowMove", {
get: function () {
return this.allowMoveVertical || this.allowMoveHorizontal;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ManipulationPermissions.prototype, "allowRotateConstraint", {
set: function (value) {
var oldValue = this.allowRotate;
this._allowRotateConstraint = value;
if (this.allowRotate !== oldValue)
this.propertyChanged.notify();
},
enumerable: true,
configurable: true
});
Object.defineProperty(ManipulationPermissions.prototype, "allowRotate", {
get: function () {
return this._allowRotateConstraint != null
? this._allowRotateConstraint
: this._allowRotate;
},
set: function (value) {
if (this._allowRotate === value)
return;
this._allowRotate = value;
this.propertyChanged.notify();
},
enumerable: true,
configurable: true
});
Object.defineProperty(ManipulationPermissions.prototype, "allowDragAndDrop", {
get: function () {
return this._allowDragAndDrop;
},
set: function (value) {
if (this._allowDragAndDrop === value)
return;
this._allowDragAndDrop = value;
this.propertyChanged.fire();
},
enumerable: true,
configurable: true
});
Object.defineProperty(ManipulationPermissions.prototype, "resizeGrips", {
get: function () {
return this._resizeGrips;
},
set: function (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();
},
enumerable: true,
configurable: true
});
Object.defineProperty(ManipulationPermissions.prototype, "allowResize", {
get: function () {
return this.resizeGrips.edge || this.resizeGrips.corner.length > 0;
},
enumerable: true,
configurable: true
});
ManipulationPermissions.prototype.clone = function () {
var 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;
};
ManipulationPermissions.prototype.equals = function (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);
};
ManipulationPermissions.prototype.getSimplifiedObject = function () {
var 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;
};
ManipulationPermissions.CreateFromRaw = function (raw) {
var resizeGrips = _.extend(new ResizeGripsPermissions(true, true), raw["resizeGrips"]);
var maniplationsPermissions = _.extend(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);
return ManipulationPermissions;
}());
export { ManipulationPermissions };
//# sourceMappingURL=ManipulationPermissions.js.map