@aurigma/design-atoms
Version:
Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.
1,006 lines • 43.1 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
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 _a;
import { Utils } from "../Utils/Common";
import { WebServiceCallType } from "../Utils/Common";
import { EventWithSenderArg, EventObject } from "@aurigma/design-atoms-model/EventObject";
import { Permission } from "../Permission";
import { RectangleF, RotatedRectangleF } from "@aurigma/design-atoms-model/Math";
import { ItemHandlerData } from "./ItemHandlerData";
import { BlendMode, ManipulationPermissions, VisualizationPermissions, ItemPermissions, PlaceholderPermissions } from "@aurigma/design-atoms-model/Product/Items";
import { JsonProductSerializer } from "../Serialization/JsonProductSerializer";
import { Exception, NotImplementedException } from "@aurigma/design-atoms-model/Exception";
import { RenderingType } from "@aurigma/design-atoms-model/Product";
import { Graphics } from "../Graphics";
import { RenderState } from "./RenderState";
import { Deferred } from "../Utils/Deferred";
import Environment from "@aurigma/design-atoms-model/Utils/Environment";
import * as _ from "underscore";
import { clamp } from "../Utils/Math";
var BLEND_MODES = (_a = {},
_a[BlendMode.Normal] = "normal",
_a[BlendMode.Multiply] = "multiply",
_a[BlendMode.Screen] = "screen",
_a[BlendMode.Overlay] = "overlay",
_a[BlendMode.Darken] = "darken",
_a[BlendMode.Lighten] = "lighten",
_a[BlendMode.ColorDodge] = "color-dodge",
_a[BlendMode.ColorBurn] = "color-burn",
_a[BlendMode.HardLight] = "hard-light",
_a[BlendMode.SoftLight] = "soft-light",
_a[BlendMode.Difference] = "difference",
_a[BlendMode.Exclusion] = "exclusion",
_a[BlendMode.None] = "none",
_a);
var ItemHandler = /** @class */ (function () {
function ItemHandler(item) {
var _this = this;
this._afterUpdateCallbacks = [];
this._modelItem = null;
this._skipPropertyChanged = false;
this._skippedPropertyName = null;
this._visible = true;
this._locked = false;
this._updating = false;
this._isCurrentWebServiceCallForAll = null;
this._changeItemOnUpdate = true;
/**
* Fires when v-object's ready property sets to true.
*/
this._readyEvent = new EventWithSenderArg();
/**
* Fires when v-object was modified (after the end of an operation).
*/
this._changedEvent = new EventObject();
/**
* Fires before v-object is being modified (before the start of an operation).
*/
this._changingEvent = new EventObject();
this._itemPropertyChangedEvent = new EventWithSenderArg();
this._isDisposed = false;
this._tag = null;
this._transformOperation = null;
this._baseOnItemPropertyChanged = function (sender, propertyName) {
if (_this._skipPropertyChanged) {
_this._skippedPropertyName = propertyName;
return;
}
_this._onItemPropertyChanged(sender, propertyName);
};
this._setItem(item);
this._controlPoints = [];
this._layer = null;
this._tag = null;
//use current time to generate unique id
//use this id for matching between server and cliebt objects
this._uniqueId = this._createUniqueID();
this._callbacks = [];
this._renderState = RenderState.Hidden;
this._throttleSizeChanging = _.throttle(function () { this.raiseChanging(); }, 100);
}
Object.defineProperty(ItemHandler.prototype, "item", {
get: function () {
return this._modelItem;
},
set: function (item) {
this._setItem(item);
},
enumerable: true,
configurable: true
});
Object.defineProperty(ItemHandler.prototype, "ready", {
get: function () {
return this._isReady();
},
enumerable: true,
configurable: true
});
Object.defineProperty(ItemHandler.prototype, "isLoadingImage", {
get: function () {
return this._isLoadingImage();
},
set: function (value) {
if (this.isLoadingImage === value)
return;
this._setIsLoadingImage(value);
},
enumerable: true,
configurable: true
});
Object.defineProperty(ItemHandler.prototype, "uniqueId", {
get: function () {
return this._uniqueId;
},
set: function (v) {
// Do nothing! uniqueId should not be changed
},
enumerable: true,
configurable: true
});
Object.defineProperty(ItemHandler.prototype, "renderState", {
get: function () {
return this._renderState;
},
set: function (v) {
this._renderState = v;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ItemHandler.prototype, "parentGroupItemHandler", {
get: function () {
if (this.item.parentGroupItem != null && this.canvas != null)
return this.canvas.getItemHandler(this.item.parentGroupItem);
return null;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ItemHandler.prototype, "blendMode", {
get: function () {
return this.item.blendMode;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ItemHandler.prototype, "controlPoints", {
get: function () {
return this._controlPoints;
},
set: function (v) {
this._controlPoints = v;
this.raiseChanged();
},
enumerable: true,
configurable: true
});
Object.defineProperty(ItemHandler.prototype, "tag", {
get: function () {
return this._tag;
},
set: function (v) {
this._tag = v;
this.raiseChanged();
},
enumerable: true,
configurable: true
});
Object.defineProperty(ItemHandler.prototype, "canvas", {
get: function () {
return this._canvas;
},
set: function (value) {
if (value === this._canvas)
return;
var oldCanvas = this._canvas;
this._canvas = value;
if (this._canvas != null)
this._onAddedOnCanvas(value);
else
this._onRemovedFromCanvas(oldCanvas);
},
enumerable: true,
configurable: true
});
Object.defineProperty(ItemHandler.prototype, "layer", {
get: function () {
return this._getLayer();
},
set: function (v) {
this._layer = v;
this.quickUpdate();
},
enumerable: true,
configurable: true
});
ItemHandler.prototype._getLayer = function () {
return this._layer;
};
Object.defineProperty(ItemHandler.prototype, "index", {
get: function () {
return (this._layer != null) ? this._layer.flatItemHandlers.indexOf(this) : -1;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ItemHandler.prototype, "bounds", {
get: function () {
return new RectangleF(0, 0, 0, 0);
},
enumerable: true,
configurable: true
});
Object.defineProperty(ItemHandler.prototype, "name", {
get: function () {
return this.item.name;
},
set: function (v) {
this.item.name = v;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ItemHandler.prototype, "visible", {
get: function () {
return this._isIgnorePermissionsMode() ? this._visible : this.item.visible;
},
set: function (v) {
if (this._visible !== v) {
this._visible = v;
this._refreshState();
if (v)
this.update();
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(ItemHandler.prototype, "locked", {
get: function () {
return this._isIgnorePermissionsMode() ? this._locked : this.item.locked;
},
set: function (v) {
if (this._locked !== v) {
this._locked = v;
this._refreshState();
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(ItemHandler.prototype, "isNormalRenderingType", {
get: function () {
if (this.layer == null) {
return true;
}
return this.layer.renderingType === RenderingType.Normal;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ItemHandler.prototype, "isUpdating", {
get: function () {
return this._updating;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ItemHandler.prototype, "changeItemOnUpdate", {
get: function () {
return this._changeItemOnUpdate;
},
set: function (value) {
this._changeItemOnUpdate = value;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ItemHandler.prototype, "_colorSettings", {
get: function () {
var _a, _b, _c, _d, _e, _f, _g, _h;
return {
rgbColorProfileName: (_b = (_a = this.canvas) === null || _a === void 0 ? void 0 : _a.renderingConfigProvider.getRgbColorProfileName()) !== null && _b !== void 0 ? _b : '',
cmykColorProfileName: (_d = (_c = this.canvas) === null || _c === void 0 ? void 0 : _c.renderingConfigProvider.getCmykColorProfileName()) !== null && _d !== void 0 ? _d : '',
grayscaleColorProfileName: (_f = (_e = this.canvas) === null || _e === void 0 ? void 0 : _e.renderingConfigProvider.getGrayscaleColorProfileName()) !== null && _f !== void 0 ? _f : '',
hiResDestinationColorProfileName: (_h = (_g = this.canvas) === null || _g === void 0 ? void 0 : _g.renderingConfigProvider.getHiResDestinationColorProfileName()) !== null && _h !== void 0 ? _h : ''
};
},
enumerable: true,
configurable: true
});
Object.defineProperty(ItemHandler.prototype, "hasLayoutAncestor", {
get: function () {
var current = this;
while (current && current.parentGroupItemHandler) {
if (current.parentGroupItemHandler.getTypeName() === "LayoutItemHandler") {
return true;
}
current = current.parentGroupItemHandler;
}
return false;
},
enumerable: true,
configurable: true
});
;
ItemHandler.isGroupHandler = function (itemHandler) {
return itemHandler._isGroupHandler();
};
ItemHandler.prototype.isHighlightNeeded = function () {
return false;
};
ItemHandler.prototype.hasBlendMode = function () {
return this.item.blendMode != null && this.item.blendMode != BlendMode.None && this.item.blendMode != BlendMode.Normal;
};
ItemHandler.prototype.getPermissions = function () {
if (this._permissions == null) {
this._permissions = this._createItemHandlerPermissions();
}
return this._permissions;
};
ItemHandler.prototype.resetPermissions = function () {
this._permissions = null;
};
ItemHandler.prototype.getTypeName = function () {
return this["constructor"].typeName;
};
ItemHandler.prototype.getData = function (type) {
var data = this._createDataInstance(this);
return type === "asObject" ?
data :
JSON.stringify(data);
};
ItemHandler.prototype.updateItem = function (item) {
this._skippedPropertyName = null; // Can be buggy if several properties changed. See #7700
this._modifyItem(function (i) {
i.update(item);
});
if (this._skippedPropertyName != null) {
this._onItemPropertyChanged(this.item, this._skippedPropertyName);
if (this.canvas != null)
this.canvas.updateSelection();
}
};
ItemHandler.prototype.setData = function (v) {
//raise changed event in applyState method
if (v && v !== "") {
var data;
if (typeof v == "string")
data = JSON.parse(v);
else
data = v;
this._createDataInstance().applyState(data, this);
}
};
ItemHandler.prototype.isVisible = function () {
var _this = this;
var invisibleByParentGroup = function (item) {
var _a;
var parentGroupItem = item.parentGroupItem;
if (parentGroupItem == null)
return false;
if (!parentGroupItem.visible || parentGroupItem.visualizationPermissions.noShow)
return true;
var parentGroupHandler = (_a = _this.canvas) === null || _a === void 0 ? void 0 : _a.getItemHandler(parentGroupItem);
if (parentGroupHandler && !parentGroupHandler.isVisible())
return true;
if (parentGroupHandler && ItemHandler.isGroupHandler(parentGroupHandler) && !parentGroupHandler.isChildVisible(_this))
return true;
return invisibleByParentGroup(parentGroupItem);
};
return this.visible &&
!this.getPermissions().noShow &&
(this.layer == null || this.layer.visible) &&
!invisibleByParentGroup(this.item);
};
ItemHandler.prototype.isEmpty = function () {
return false;
};
ItemHandler.prototype.isLocked = function () {
return this.locked || this.layer != null && this.layer.locked;
};
ItemHandler.prototype.processEvent = function (e) {
};
ItemHandler.prototype.hitTest = function (point) {
throw new Error("Not implemented");
};
ItemHandler.prototype.draw = function (itemHandlerCtx, clippingPath, textureCanvas, textureCanvasCtx, memoryCanvas, memoryCanvasCtx, canvasRenderer, isMasked) {
if (itemHandlerCtx == null || this.canvas == null || this.layer == null)
return;
var sourceBlendMode = itemHandlerCtx.globalCompositeOperation;
var destBlendMode = this.hasBlendMode() ? this._convertBlendModeToGlobalOperation(this.blendMode) : sourceBlendMode;
itemHandlerCtx.globalAlpha = isMasked ? 0.2 : 1;
if (this.isNormalRenderingType) {
if (clippingPath != null) {
itemHandlerCtx.save();
Graphics.clipPath(itemHandlerCtx, clippingPath);
}
if (this.hasBlendMode())
itemHandlerCtx.globalCompositeOperation = destBlendMode;
this.drawItemHandler(itemHandlerCtx);
if (this.hasBlendMode())
itemHandlerCtx.globalCompositeOperation = sourceBlendMode;
}
else {
this._drawTexture(itemHandlerCtx, textureCanvas, textureCanvasCtx, memoryCanvas, memoryCanvasCtx, canvasRenderer, isMasked, clippingPath);
}
if (clippingPath == null)
return;
itemHandlerCtx.restore();
};
ItemHandler.prototype._drawTexture = function (itemHandlerCtx, textureCanvas, textureCanvasCtx, memoryCanvas, memoryCanvasCtx, canvasRenderer, isMasked, clippingPath) {
var _a, _b, _c, _d, _e, _f;
var scaleX = Environment.screenDpi * this.canvas.zoom / 72;
var scaleY = Environment.screenDpi * this.canvas.zoom / 72;
var width = itemHandlerCtx.canvas.width;
var height = itemHandlerCtx.canvas.height;
var textureImage = this.layer.textureImage;
if (textureImage == null) {
this.canvas.drawWaitClock(itemHandlerCtx, this.bounds.center);
return;
}
var canvasRect = new RotatedRectangleF(this.canvas.workspaceWidth / 2, this.canvas.workspaceHeight / 2, this.canvas.workspaceWidth, this.canvas.workspaceHeight);
Graphics.drawImage(textureCanvasCtx, textureImage, canvasRect, scaleX, scaleY, this.canvas.disableSmoothing);
if (clippingPath != null) {
memoryCanvasCtx.save();
Graphics.clipPath(memoryCanvasCtx, clippingPath);
}
this.drawItemHandler(memoryCanvasCtx, itemHandlerCtx);
textureCanvasCtx.restore();
textureCanvasCtx.globalCompositeOperation = "destination-in";
textureCanvasCtx.drawImage(memoryCanvas, 0, 0, width, height);
var opacity = 1;
var transparencyEnabled = (_c = (_b = (_a = this._canvas) === null || _a === void 0 ? void 0 : _a.viewerConfiguration) === null || _b === void 0 ? void 0 : _b.inactiveContainerTransparencyEnabled) !== null && _c !== void 0 ? _c : ItemHandler.DEFAULT_CONTAINER_TRANSPARENCY_ENABLED;
var transparency = (_f = (_e = (_d = this._canvas) === null || _d === void 0 ? void 0 : _d.viewerConfiguration) === null || _e === void 0 ? void 0 : _e.inactiveContainerTransparencyLevel) !== null && _f !== void 0 ? _f : ItemHandler.DEFAULT_CONTAINER_TRANSPARENCY_LEVEL;
if (transparencyEnabled && typeof transparency == "number") {
opacity = 1 - clamp(transparency, 0, 1);
}
itemHandlerCtx.restore();
itemHandlerCtx.globalAlpha = isMasked && transparencyEnabled ? opacity : 1;
itemHandlerCtx.drawImage(textureCanvas, 0, 0, width, height);
canvasRenderer.applyContextScale(itemHandlerCtx, this._canvas.workspace, this._canvas.offset);
};
ItemHandler.prototype.drawItemHandler = function (itemHandlerCtx, originalCtx) {
};
ItemHandler.prototype.quickUpdate = function () {
//do nothing by default
};
ItemHandler.prototype.update = function (beforeUpdate, afterUpdate) {
this._updateImpl(beforeUpdate, afterUpdate);
};
ItemHandler.prototype.updateAsync = function (beforeUpdate, afterUpdate) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this._updateImpl(beforeUpdate, afterUpdate)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
ItemHandler.prototype.updateForExternalCanvas = function (canvas) {
this._serverSideUpdate(null, null, null, canvas);
};
ItemHandler.prototype.updateActiveColorWebServiceCall = function (callPromise, updateForAll) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(this._activeWebServiceCall != null)) return [3 /*break*/, 2];
return [4 /*yield*/, this._activeWebServiceCall];
case 1:
_a.sent();
_a.label = 2;
case 2:
if (this._activeColorWebServiceCall != null) {
this._activeColorWebServiceCall.cancel();
if (this._isCurrentWebServiceCallForAll && !updateForAll) {
callPromise.cancel();
this._isCurrentWebServiceCallForAll = updateForAll;
this._activeColorWebServiceCall = null;
return [2 /*return*/];
}
}
if (this._handlerUpdated == null)
this._handlerUpdated = new Deferred();
this._activeColorWebServiceCall = callPromise;
this._isCurrentWebServiceCallForAll = updateForAll;
return [2 /*return*/];
}
});
});
};
ItemHandler.prototype.startTransform = function (operation) {
this._transformOperation = operation;
this._cancelWebServiceCall();
};
ItemHandler.prototype.endTransform = function (changed, resized, supressOnChanged) {
if (supressOnChanged === void 0) { supressOnChanged = false; }
this._transformOperation = null;
};
ItemHandler.prototype.waitUpdate = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(this._handlerUpdated != null)) return [3 /*break*/, 2];
return [4 /*yield*/, this._handlerUpdated.promise];
case 1:
_a.sent();
_a.label = 2;
case 2: return [2 /*return*/];
}
});
});
};
ItemHandler.prototype.beginUpdate = function () {
this._updating = true;
};
ItemHandler.prototype.endUpdate = function () {
this._updating = false;
this.updated();
var modified = false;
while (this._callbacks.length > 0) {
var callback = this._callbacks.shift();
if (typeof callback == "function") {
callback();
modified = true;
}
}
if (modified)
this.update();
};
ItemHandler.prototype.updated = function () {
this.raiseChanged();
};
ItemHandler.prototype.addReady = function (handler) {
this._readyEvent.add(handler);
};
ItemHandler.prototype.removeReady = function (handler) {
this._readyEvent.remove(handler);
};
ItemHandler.prototype.addChanging = function (handler) {
this._changingEvent.add(handler);
};
ItemHandler.prototype.removeChanging = function (handler) {
this._changingEvent.remove(handler);
};
ItemHandler.prototype.raiseChanging = function (param) {
var _a;
param = param != null ? param : this.item;
this._changingEvent.notify(param);
this.item.getItemChangingEvent().notify(this.item);
(_a = this._canvas) === null || _a === void 0 ? void 0 : _a.redraw();
};
ItemHandler.prototype.getChangingEvent = function () {
return this._changingEvent;
};
ItemHandler.prototype.addChanged = function (handler) {
this._changedEvent.add(handler);
};
ItemHandler.prototype.removeChanged = function (handler) {
this._changedEvent.remove(handler);
};
ItemHandler.prototype.raiseChanged = function () {
if (!this.isUpdating) {
this._changedEvent.notify(this);
}
};
ItemHandler.prototype.getChangedEvent = function () {
return this._changedEvent;
};
ItemHandler.prototype.addItemPropertyChanged = function (handler) {
this._itemPropertyChangedEvent.add(handler);
};
ItemHandler.prototype.removeItemPropertyChanged = function (handler) {
this._itemPropertyChangedEvent.remove(handler);
};
ItemHandler.prototype.initialize = function () {
};
ItemHandler.prototype.onSuccessResponse = function (activeCall) {
if (activeCall === void 0) { activeCall = WebServiceCallType.Item; }
if (activeCall == WebServiceCallType.Item)
this._activeWebServiceCall = null;
else if (activeCall == WebServiceCallType.Color) {
this._activeColorWebServiceCall = null;
}
if (this._activeWebServiceCall == null
&& this._activeColorWebServiceCall == null
&& this._handlerUpdated != null) {
this._handlerUpdated.resolve();
this._handlerUpdated = null;
}
};
ItemHandler.prototype.onErrorResponse = function (error, activeCall) {
if (activeCall === void 0) { activeCall = WebServiceCallType.Item; }
if (activeCall == WebServiceCallType.Item)
this._activeWebServiceCall = null;
else if (activeCall == WebServiceCallType.Color)
this._activeColorWebServiceCall = null;
this._afterUpdateCallbacks = [];
if (this._activeWebServiceCall == null
&& this._activeColorWebServiceCall == null
&& this._handlerUpdated != null) {
this._handlerUpdated.reject(error);
this._handlerUpdated = null;
}
};
ItemHandler.prototype.validateActiveColorWebServiceCall = function () {
if (this._activeColorWebServiceCall == null) {
if (this._activeWebServiceCall == null)
this._handlerUpdated = null;
return;
}
this._activeColorWebServiceCall = null;
if (this._activeWebServiceCall == null)
this._handlerUpdated = null;
};
ItemHandler.prototype.getColors = function () {
return this._getColors().filter(function (x) { return x !== null; });
};
ItemHandler.prototype.dispose = function () {
var _a;
this._unsubscribeItemEvents();
this._cancelWebServiceCall();
(_a = this._activeColorWebServiceCall) === null || _a === void 0 ? void 0 : _a.cancel();
this._activeColorWebServiceCall = null;
this._isDisposed = true;
};
ItemHandler.prototype._isReady = function () {
return true;
};
ItemHandler.prototype._getColors = function () {
return [];
};
ItemHandler.prototype._updateImpl = function (beforeUpdate, afterUpdate) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/];
});
});
};
ItemHandler.prototype.transformChanged = function () {
this.raiseChanged();
};
ItemHandler.prototype._createDataInstance = function (itemHandler) {
return new ItemHandlerData(itemHandler);
};
ItemHandler.prototype._getDataItem = function () {
var serializer = new JsonProductSerializer();
var serializedItem = serializer.serializeModelComponent(this.item);
return serializedItem;
};
ItemHandler.prototype._applyDataItem = function (item, itemHandlerData) {
var _this = this;
var serializer = new JsonProductSerializer();
var itemObj = serializer.productParser.parseItem(item);
this._modifyItem(function () { _this._setDataItem(itemObj, itemHandlerData); });
};
ItemHandler.prototype._setDataItem = function (item, itemHandlerData) {
this.item.transform = item.transform.clone();
this.setData(itemHandlerData);
};
ItemHandler.prototype._modifyItem = function (modify) {
if (typeof modify !== "function")
return;
this._skipPropertyChanged = true;
try {
modify(this.item);
}
finally {
this._skipPropertyChanged = false;
}
};
ItemHandler.prototype._refreshState = function () {
};
ItemHandler.prototype._onAddedOnCanvas = function (canvas, supressUpdate) {
if (canvas != null) {
canvas.updateTexts();
if (!supressUpdate)
this.update();
}
};
ItemHandler.prototype._onRemovedFromCanvas = function (canvas) {
this._canvas = null;
};
ItemHandler.prototype._validateBeforeCallService = function () {
return true;
};
ItemHandler.prototype._update = function (additionalArgs, beforeUpdate, afterUpdate) {
this._serverSideUpdate(additionalArgs, beforeUpdate, afterUpdate, null);
};
ItemHandler.prototype._callService = function (methodName, data, success, failure, externalCanvas) {
var canvas = externalCanvas != null ? externalCanvas : this.canvas;
if (canvas == null || !canvas.isInitialized || canvas.initialization) {
this._handlerUpdated = null;
return;
}
var layerId = (!this.isNormalRenderingType && this.layer != null) ? this.layer.uniqueId : null;
var callPromise = this._getCallService(methodName, data, success, failure, layerId, canvas);
this._updateActiveWebServiceCall(callPromise);
};
ItemHandler.prototype._updateActiveWebServiceCall = function (callPromise) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
this._cancelWebServiceCall();
this._activeWebServiceCall = callPromise;
if (this._activeColorWebServiceCall == null)
return [2 /*return*/];
this._activeColorWebServiceCall.cancel();
this._activeColorWebServiceCall = null;
return [4 /*yield*/, this._handlerUpdated.promise];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
ItemHandler.prototype._getDefaultPermissions = function () {
return {
manipulation: new ManipulationPermissions(),
visualization: new VisualizationPermissions(),
item: new ItemPermissions(),
placeholder: new PlaceholderPermissions()
};
};
ItemHandler.prototype._getItemPermissions = function () {
return {
manipulation: this.item.manipulationPermissions,
visualization: this.item.visualizationPermissions,
item: this.item.itemPermissions,
placeholder: new PlaceholderPermissions()
};
};
ItemHandler.prototype._isIgnorePermissionsMode = function () {
var _a, _b;
return (_b = (_a = this.canvas) === null || _a === void 0 ? void 0 : _a.ignorePermissionsMode) !== null && _b !== void 0 ? _b : false;
};
ItemHandler.prototype._isLoadingImage = function () {
return false;
};
ItemHandler.prototype._setIsLoadingImage = function (value) {
throw new NotImplementedException();
};
ItemHandler.prototype._dispatchReadyEvent = function () {
if (this.ready) {
this._readyEvent.notify(this);
}
};
ItemHandler.prototype._updateVisibility = function () {
//do nothing by default
};
ItemHandler.prototype._subscribeItemEvents = function () {
if (this._modelItem == null)
return;
this._modelItem.addPropertyChanged(this._baseOnItemPropertyChanged);
};
ItemHandler.prototype._unsubscribeItemEvents = function () {
if (this._modelItem == null)
return;
this._modelItem.removePropertyChanged(this._baseOnItemPropertyChanged);
};
ItemHandler.prototype._onItemPropertyChanged = function (sender, propertyName) {
switch (propertyName) {
case "locked":
case "opacity":
case "blendMode":
if (this.canvas != null) {
this.canvas.updateSelection();
this.canvas.redraw();
}
this.raiseChanged();
break;
case "transform":
if (this.canvas != null) {
this.canvas.updateSelection();
this.canvas.redraw();
}
this.transformChanged();
break;
case "visible":
this._onItemVisibilityChanged();
break;
case "manipulationPermissions":
case "visualizationPermissions":
case "itemPermissions":
case "permissions":
this._permissions = null;
this.quickUpdate();
if (this.canvas)
this.canvas.redraw();
this.raiseChanged();
this._updateVisibility();
break;
default:
}
this._itemPropertyChangedEvent.notify(this, propertyName);
};
ItemHandler.prototype._onItemVisibilityChanged = function () {
this.quickUpdate();
if (this.canvas != null) {
this.canvas.updateSelection();
this.canvas.redraw();
}
this.raiseChanged(); // ?
};
ItemHandler.prototype._getItem = function () {
return this._modelItem;
};
ItemHandler.prototype._setItem = function (item) {
this._unsubscribeItemEvents();
this._modelItem = item;
this._subscribeItemEvents();
};
ItemHandler.prototype._onValidateBeforeCallServiceFailed = function () {
this._handlerUpdated.resolve();
this._handlerUpdated = null;
};
ItemHandler.prototype._isGroupHandler = function () {
return true;
};
ItemHandler.prototype._serverSideUpdate = function (additionalArgs, beforeUpdate, afterUpdate, canvas) {
var _this = this;
var success = function (data) {
if (_this.item == null)
return;
var item = null;
if (typeof data == "object") {
item = data.item;
data = data.itemHandlerData;
}
if (item != null && _this.changeItemOnUpdate) {
_this._applyDataItem(item, data);
}
_this.setData(data);
if (_this._afterUpdateCallbacks.length === 0) {
_this.quickUpdate();
}
else {
_this._afterUpdateCallbacks.forEach(function (callback) { return callback.apply(_this); });
_this._afterUpdateCallbacks = [];
_this.quickUpdate();
_this.raiseChanged();
}
_this.onSuccessResponse();
_this.item.getItemChangedEvent().notify();
};
var failure = function (error) {
_this.onErrorResponse(error);
};
if (this.isUpdating) {
this._callbacks.push(beforeUpdate);
return;
}
if (typeof beforeUpdate == "function")
beforeUpdate();
if (afterUpdate != null)
this._afterUpdateCallbacks.push(afterUpdate);
var itemHandlerData = this._createDataInstance(this);
var data = [JSON.stringify(itemHandlerData), JSON.parse(this._getDataItem()), this._colorSettings];
if (additionalArgs != null)
data = data.concat(additionalArgs);
if (this._handlerUpdated == null)
this._handlerUpdated = new Deferred();
if (this._validateBeforeCallService()) {
this._callService("Update" + this.getTypeName(), data, success, failure, canvas);
}
else {
this._onValidateBeforeCallServiceFailed();
}
};
ItemHandler.prototype._convertBlendModeToGlobalOperation = function (blendMode) {
var value = BLEND_MODES[blendMode];
return (value != null ? value : "none");
};
ItemHandler.prototype._cancelWebServiceCall = function () {
if (this._activeWebServiceCall == null)
return;
this._activeWebServiceCall.cancel();
this._activeWebServiceCall = null;
};
ItemHandler.prototype._createItemHandlerPermissions = function () {
var permissions = !this._isIgnorePermissionsMode() ?
this._getItemPermissions() :
this._getDefaultPermissions();
var permissionOptions = {
"AllowDelete": permissions.manipulation.allowDelete,
"AllowMoveHorizontal": permissions.manipulation.allowMoveHorizontal,
"AllowMoveVertical": permissions.manipulation.allowMoveVertical,
"AllowRotate": permissions.manipulation.allowRotate,
"ResizeGrips": permissions.manipulation.resizeGrips != null
? { "Edge": permissions.manipulation.resizeGrips.edge, "Corner": permissions.manipulation.resizeGrips.corner }
: null,
"AllowDragAndDrop": permissions.manipulation.allowDragAndDrop,
"NoPrint": permissions.visualization.noPrint,
"NoShow": permissions.visualization.noShow,
"ShowDeleteToolbarButton": permissions.item.itemToolbarPermissions.showDeleteButton,
"ShowEditToolbarButton": permissions.item.itemToolbarPermissions.showEditButton,
"ShowHandleToolbarButton": permissions.item.itemToolbarPermissions.showHandleButton,
"ShowSelectToolbarButton": permissions.item.itemToolbarPermissions.showSelectButton,
"AllowEditContent": permissions.placeholder.allowEditContent,
"ShowSelectButton": permissions.placeholder.showSelectButton,
"ShowHandleButton": permissions.placeholder.showHandleButton
};
var permission = new Permission(permissionOptions, true);
return permission;
};
ItemHandler.prototype._createUniqueID = function () {
return ("vo" + new Date().getTime()) + Math.round(Math.random() * 1000);
};
ItemHandler.prototype._getCallService = function (methodName, data, success, failure, layerId, canvas) {
if (layerId === void 0) { layerId = null; }
var callPromise = Utils.makeCancelable(new Promise(function (resolve, reject) {
var _a;
var canvasData = JSON.stringify(canvas.getData(true, layerId));
var args = [canvasData];
if (data != null)
args = args.concat(data);
args = args.concat(resolve, function (error, userContext, methodName) {
reject({ error: error, userContext: userContext, methodName: methodName });
});
(_a = canvas.service)[methodName].apply(_a, __spread(args));
}));
callPromise.promise
.then(function (responseData) {
if (typeof success == "function")
success(responseData);
})
.catch(function (responseData) {
if (responseData instanceof Exception) {
console.error("Exception of type " + responseData.name + ": " + responseData.message);
return;
}
if (responseData.isCanceled)
return;
var error = responseData.error;
if (typeof failure == "function")
failure(error);
});
return callPromise;
};
ItemHandler.DEFAULT_CONTAINER_TRANSPARENCY_ENABLED = true;
ItemHandler.DEFAULT_CONTAINER_TRANSPARENCY_LEVEL = 0.8;
ItemHandler.typeName = "ItemHandler";
return ItemHandler;
}());
export { ItemHandler };
//# sourceMappingURL=ItemHandler.js.map