@aurigma/design-atoms
Version:
Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.
675 lines • 33.9 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
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;
};
import * as _ from "underscore";
import { Collection } from "@aurigma/design-atoms-model/Collection";
import { RotatedRectangleF, RectangleF, EqualsOfFloatNumbers } from "@aurigma/design-atoms-model/Math";
import { LayoutItem, ManipulationPermissions, ResizeMode } from "@aurigma/design-atoms-model/Product/Items";
import { arrayReferenceEquals } from "@aurigma/design-atoms-model/Utils/Utils";
import { EventObject } from "@aurigma/design-atoms-model/EventObject";
import { ArgumentException } from "@aurigma/design-atoms-model/Exception";
import { SelectionRectangleHandler } from "./SelectionRectangleHandler";
import { SelectionHitTestManager } from "../SelectionHitTestManager";
import { BaseRectangleItemHandler, PlaceholderItemHandler, GroupItemHandler, LineItemHandler, NewBaseTextItemHandler } from "../../ItemHandlers";
import { InputState } from "../../Input/InputManager/IInputManager";
import { SelectionProcessModifier } from "./SelectionProcessModifier";
import { FrontEndLogger, LogSource } from "../FrontEndLogger";
import { HistoryUpdateMode } from "../../Commands/ModelUpdateCommand";
import { getRotatedRectangleWithBorder } from "../../Utils/Math";
import { ItemsCommand } from "@aurigma/design-atoms-interfaces";
var SelectionHandler = /** @class */ (function () {
function SelectionHandler(hitTestManager, _canvas, _snapLinesHandler, _interactiveZonesHandler) {
var _this = this;
this._canvas = _canvas;
this._snapLinesHandler = _snapLinesHandler;
this._interactiveZonesHandler = _interactiveZonesHandler;
this._itemHandlers = new Collection();
this._parentSelectionRectangle = null;
this._multipleSelectionEnabled = true;
this._enabled = true;
this._skipUpdate = false;
this._locked = false;
this._state = SelectionState.Idle;
this._ignoreSimpleMode = false;
this._manipulationPermissions = new ManipulationPermissions();
this._resizeIndex = null;
this._setRectangle = function (rect) {
_this._rectangle = rect;
};
this._updatePermissions = function () {
var result = new ManipulationPermissions();
var isPlaceholderEditing = _this._canvas.contentEditingPlaceholderItemHandler != null;
if (isPlaceholderEditing) {
_this._manipulationPermissions = _this._canvas.contentEditingPlaceholderItemHandler.content.item.manipulationPermissions;
return;
}
if (!_this._ignoreSimpleMode && _this._canvas.simpleMode) {
_this._manipulationPermissions = new ManipulationPermissions(false);
return;
}
var handlers = _this._itemHandlers.selectMany(function (h) { return h instanceof GroupItemHandler ? h.getNestedItemHandlers(false, false, true) : [h]; })
.ofType(BaseRectangleItemHandler);
handlers.forEach(function (handler) {
var _a, _b, _c, _d;
var perms = handler.item.manipulationPermissions;
result.allowDelete = result.allowDelete && perms.allowDelete;
result.allowDragAndDrop = result.allowDragAndDrop && perms.allowDragAndDrop;
result.allowMoveHorizontal = result.allowMoveHorizontal && perms.allowMoveHorizontal;
result.allowMoveVertical = result.allowMoveVertical && perms.allowMoveVertical;
result.allowRotate = result.allowRotate && perms.allowRotate;
result.resizeGrips.edge = result.resizeGrips.edge && perms.resizeGrips.edge;
result.resizeGrips.corner = _.intersection(perms.resizeGrips.corner, result.resizeGrips.corner);
var selectionAngle = (_d = (_b = (_a = _this._rectangle) === null || _a === void 0 ? void 0 : _a.angle) !== null && _b !== void 0 ? _b : (_c = _this._parentSelectionRectangle) === null || _c === void 0 ? void 0 : _c.angle) !== null && _d !== void 0 ? _d : 0;
if (EqualsOfFloatNumbers((selectionAngle - handler.angle) % 90, 0) == false) {
result.resizeGrips.edge = false;
result.resizeGrips.setCornerArbitrary(false);
}
});
_this._manipulationPermissions = result;
};
this._selectionChanged = new EventObject();
this._onSelectionItemHandlersChanged = function () {
var _a;
if (!_this._itemHandlers.contains(_this._currentItemHandler)) {
if (_this._currentItemHandler instanceof PlaceholderItemHandler)
_this._currentItemHandler.removeIsEditingChanged(_this._updatePermissions);
_this._currentItemHandler = _this._itemHandlers.lastOrDefault();
_this._updateParentItemHandler((_a = _this._currentItemHandler) === null || _a === void 0 ? void 0 : _a.parentGroupItemHandler);
if (_this._currentItemHandler instanceof PlaceholderItemHandler)
_this._currentItemHandler.addIsEditingChanged(_this._updatePermissions);
_this._currentItemChangedEvent.notify(_this._currentItemHandler);
}
_this._update();
_this._updatePermissions();
_this._selectionChanged.notify();
};
this._onParentHandlerPropertyChanged = function (sender, property) {
if (property == "sourceRectangle")
_this._updateParentSelectionRectangle();
};
this._selectionRectangleChanged = function (args) {
FrontEndLogger.debugLog("Selection changed: " + args.rectangle.toString() + " is" + (args.finished ? "" : " not") + " finished.", LogSource.SelectionHandler);
_this._rectangle = args.rectangle;
_this._rectangleSigns = { x: args.rectangle.width < 0 ? -1 : 1, y: args.rectangle.height < 0 ? -1 : 1 };
if (args.finished) {
_this._rectangle.width = Math.abs(_this._rectangle.width);
_this._rectangle.height = Math.abs(_this._rectangle.height);
_this._canvas.updateTexts();
}
_this._updateParentSelectionRectangle();
_this._selectionChanged.notify();
};
this._selectionStateChanged = function (state) {
_this._state = state;
};
this._selectionAngleChanged = function (args) {
var cmdArgs = __assign(__assign({}, args), { items: _this._items, finished: args.finished });
_this._canvas.viewer.commandManager.execute(ItemsCommand.rotateItems, cmdArgs, _this._getHistoryUpdateMode(args.finished));
};
this._selectionMoved = function (args) {
var cmdArgs = {
delta: args.delta,
items: _this._items,
finished: args.finished
};
_this._canvas.viewer.commandManager.execute(ItemsCommand.newTranslateItems, cmdArgs, _this._getHistoryUpdateMode(args.finished));
};
this._selectionResized = function (args) {
var cmdArgs = __assign({ items: _this._items, finished: args.finished }, args);
_this._canvas.viewer.commandManager.execute(ItemsCommand.resizeItems, cmdArgs, _this._getHistoryUpdateMode(args.finished));
};
this._onItemHandlersItemAdded = function (data) {
data.item.addChanged(_this._onSelectedItemHandlerChanged);
};
this._onItemHandlersItemRemoved = function (data) {
data.item.removeChanged(_this._onSelectedItemHandlerChanged);
};
this._onSelectedItemHandlerChanged = function (handler) {
_this._updatePermissions();
_this._update();
};
this.addSelectedItemHandlersChanged = function (handler) {
_this._itemHandlers.add_collectionChanged(handler);
};
this.removeSelectedItemHandlersChanged = function (handler) {
_this._itemHandlers.remove_collectionChanged(handler);
};
this._currentItemChangedEvent = new EventObject();
this._selectionHitTestManager = new SelectionHitTestManager(this, hitTestManager);
this._selectionProcessModifier = new SelectionProcessModifier(this, _canvas, _snapLinesHandler);
this._selectionRectangleHandler = new SelectionRectangleHandler(this._selectionProcessModifier);
this._itemHandlers.add_collectionChanged(this._onSelectionItemHandlersChanged);
this._itemHandlers.add_itemAdded(this._onItemHandlersItemAdded);
this._itemHandlers.add_itemRemoved(this._onItemHandlersItemRemoved);
this._selectionRectangleHandler.addRectangleChanged(this._selectionRectangleChanged);
this._selectionRectangleHandler.addRectangleAngleChanged(this._selectionAngleChanged);
this._selectionRectangleHandler.addRectangleMoved(this._selectionMoved);
this._selectionRectangleHandler.addRectangleResized(this._selectionResized);
this._selectionRectangleHandler.addStateChanged(this._selectionStateChanged);
}
Object.defineProperty(SelectionHandler.prototype, "enabled", {
get: function () { return this._enabled; },
enumerable: true,
configurable: true
});
Object.defineProperty(SelectionHandler.prototype, "selectedItemHandlers", {
get: function () { return this._itemHandlers; },
enumerable: true,
configurable: true
});
Object.defineProperty(SelectionHandler.prototype, "currentItemHandler", {
get: function () { return this._currentItemHandler; },
enumerable: true,
configurable: true
});
Object.defineProperty(SelectionHandler.prototype, "selectionHitTestManager", {
get: function () { return this._selectionHitTestManager; },
enumerable: true,
configurable: true
});
Object.defineProperty(SelectionHandler.prototype, "locked", {
get: function () { return this._locked; },
enumerable: true,
configurable: true
});
Object.defineProperty(SelectionHandler.prototype, "border", {
get: function () { return this._border; },
enumerable: true,
configurable: true
});
Object.defineProperty(SelectionHandler.prototype, "rectangle", {
get: function () { return this._rectangle; },
enumerable: true,
configurable: true
});
Object.defineProperty(SelectionHandler.prototype, "parentRectangle", {
get: function () { return this._parentSelectionRectangle; },
enumerable: true,
configurable: true
});
Object.defineProperty(SelectionHandler.prototype, "region", {
get: function () { return this._region; },
enumerable: true,
configurable: true
});
Object.defineProperty(SelectionHandler.prototype, "resizeIndex", {
get: function () { return this._resizeIndex; },
enumerable: true,
configurable: true
});
Object.defineProperty(SelectionHandler.prototype, "ignoreSimpleMode", {
set: function (value) {
if (this._ignoreSimpleMode === value)
return;
this._ignoreSimpleMode = value;
this._updatePermissions();
},
enumerable: true,
configurable: true
});
Object.defineProperty(SelectionHandler.prototype, "multipleSelectionEnabled", {
get: function () {
return this._multipleSelectionEnabled
&& !this.selectedItemHandlers.any(function (itemHandler) { return itemHandler.item.parentGroupItem instanceof LayoutItem; });
},
set: function (value) {
this._multipleSelectionEnabled = value;
},
enumerable: true,
configurable: true
});
SelectionHandler.prototype.lock = function (saveSelectedItems) {
if (saveSelectedItems === void 0) { saveSelectedItems = false; }
this._locked = true;
if (!saveSelectedItems)
this._itemHandlers.clear();
this._canvas.onSelectionLocked();
//this._canvas.hideSelection();
this._canvas.redraw();
};
/*redrawHighlight(){
//this._drawHighlight();
}*/
SelectionHandler.prototype.unlock = function () {
this._locked = false;
this._canvas.redraw();
};
SelectionHandler.prototype.enable = function () {
this._update();
this._enabled = true;
};
SelectionHandler.prototype.disable = function () {
this._enabled = false;
//this._canvas.hideSelection();
};
SelectionHandler.prototype.rotateByPoint = function (args, state, startPoint) {
if (startPoint === void 0) { startPoint = null; }
if (!this.manipulationPermissions.allowRotate)
return;
if (state === InputState.Started) {
if (startPoint == null)
throw new ArgumentException("SelectionHandler.updateRotation: startPoint cannot be null!");
this._selectionProcessModifier.ignoreSnapLines = false;
this._selectionRectangleHandler.startRotatingByPoint(startPoint, this.rectangle);
}
try {
this._selectionRectangleHandler.updateRotatingByPoint(args);
}
finally {
if (state === InputState.Finished)
this._notifyItemHandlersChanged();
}
};
SelectionHandler.prototype.moveByPoint = function (args, state, ignoreSnapLines, startPoint) {
if (startPoint === void 0) { startPoint = null; }
var _a;
var perms = this.manipulationPermissions;
if (!perms.allowMove)
return;
if (args.allowMoveHorizontal == null)
args.allowMoveHorizontal = perms.allowMoveHorizontal;
if (args.allowMoveVertical == null)
args.allowMoveVertical = perms.allowMoveVertical;
if (state === InputState.Started) {
if (startPoint == null)
throw new ArgumentException("SelectionHandler.updateMoving: startPoint cannot be null!");
this._selectionProcessModifier.ignoreSnapLines = ignoreSnapLines;
this._selectionRectangleHandler.startMovingByPoint(startPoint, this.rectangle);
if (!ignoreSnapLines)
this._fillSnapData();
}
try {
this._selectionRectangleHandler.updateMovingByPoint(args);
}
finally {
if (state === InputState.Finished) {
this._notifyItemHandlersChanged();
this._snapLinesHandler.clearSnapData();
(_a = this._canvas) === null || _a === void 0 ? void 0 : _a.redraw();
}
}
};
SelectionHandler.prototype.resizeByPoint = function (args, state, startPoint) {
if (startPoint === void 0) { startPoint = null; }
var _a;
if (!this.manipulationPermissions.allowResize)
return;
if (state === InputState.Started) {
if (startPoint == null)
throw new ArgumentException("SelectionHandler.updateResizing: startPoint cannot be null!");
this._resizeIndex = args.resizeIndex;
this._selectionProcessModifier.ignoreSnapLines = false;
this._selectionRectangleHandler.startResizingByPoint(startPoint, this.rectangle, args.resizeIndex, this._allowNegativeResize, this.selectedItemHandlers.toArray());
this._fillSnapData();
}
try {
this._selectionRectangleHandler.updateResizingByPoint(args, this._itemHandlers.toArray());
}
finally {
if (state === InputState.Finished) {
this._resizeIndex = null;
this._notifyItemHandlersChanged();
this._snapLinesHandler.clearSnapData();
(_a = this._canvas) === null || _a === void 0 ? void 0 : _a.redraw();
}
}
};
SelectionHandler.prototype._notifyItemHandlersChanged = function () {
this._itemHandlers.forEach(function (x) { return x.item.getItemChangedEvent().fire(); });
};
SelectionHandler.prototype.move = function (args, state) {
var perms = this.manipulationPermissions;
if (!perms.allowMove)
return;
if (args.allowMoveHorizontal == null)
args.allowMoveHorizontal = perms.allowMoveHorizontal;
if (args.allowMoveVertical == null)
args.allowMoveVertical = perms.allowMoveVertical;
if (state === InputState.Started && this._state === SelectionState.Idle) {
this._selectionProcessModifier.ignoreSnapLines = true;
this._selectionRectangleHandler.startMove(this.rectangle);
}
this._selectionRectangleHandler.move(args);
};
SelectionHandler.prototype.isItemHandlerSelected = function (itemHandler) {
return this._itemHandlers.contains(itemHandler);
};
SelectionHandler.prototype.isOnlyThisItemHandlerSelected = function (itemHandler) {
return this.isItemHandlerSelected(itemHandler) && this._itemHandlers.length === 1;
};
SelectionHandler.prototype.setSelectedItemHandlers = function (itemHandlers, dontClean) {
if (dontClean === void 0) { dontClean = false; }
if (!_.isArray(itemHandlers) || this._locked || arrayReferenceEquals(itemHandlers, this._itemHandlers.toArray()))
return;
if (!dontClean)
this.clearSelectedItemHandlers();
this._cancelEditMode();
if (!this.multipleSelectionEnabled)
itemHandlers = [itemHandlers[0]];
this._itemHandlers.addRange(itemHandlers);
};
SelectionHandler.prototype._cancelEditMode = function () {
var _a;
(_a = this._itemHandlers) === null || _a === void 0 ? void 0 : _a.ofType(PlaceholderItemHandler).forEach(function (p) { return p.editing = false; });
};
SelectionHandler.prototype.clearSelectedItemHandlers = function () {
this._cancelEditMode();
this._itemHandlers.clear();
this._updateParentSelectionRectangle();
};
SelectionHandler.prototype.addSelectedItemHandler = function (itemHandler) {
if (!this.multipleSelectionEnabled && this._itemHandlers.length > 0)
this._itemHandlers.clear();
this.setSelectedItemHandlers([itemHandler], true);
};
SelectionHandler.prototype.removeSelectedItemHandler = function (itemHandler) {
if (!this._itemHandlers.contains(itemHandler))
return;
this._itemHandlers.remove(itemHandler);
};
SelectionHandler.prototype.update = function (force) {
if (force === void 0) { force = false; }
if (force || this._state === SelectionState.Idle)
this._update();
};
SelectionHandler.prototype._update = function () {
if (this._skipUpdate)
return;
if (this._itemHandlers.length === 0) {
this._setRectangle(null);
this._border = null;
this._region = null;
return;
}
var itemHandler = this._itemHandlers.getItem(0);
var margin = itemHandler.getBorderMargin();
if (this._itemHandlers.length === 1) {
this._setRectangle(this._itemHandlers.get(0).getSelectionRectangle());
this._border = { left: margin, top: margin, right: margin, bottom: margin };
}
else {
var bounds = itemHandler.getSelectionRectangle().bounds;
var left = bounds.left, top = bounds.top, right = bounds.right, bottom = bounds.bottom;
var border = { left: margin, top: margin, right: margin, bottom: margin };
for (var i = 1; i < this._itemHandlers.length; i++) {
itemHandler = this._itemHandlers.getItem(i);
margin = itemHandler.getBorderMargin();
bounds = itemHandler.getSelectionRectangle().bounds;
if (bounds.left - margin < left - border.left) {
left = bounds.left;
border.left = margin;
}
if (bounds.top - margin < top - border.top) {
top = bounds.top;
border.top = margin;
}
if (bounds.right + margin > right + border.right) {
right = bounds.right;
border.right = margin;
}
if (bounds.bottom + margin > bottom + border.bottom) {
bottom = bounds.bottom;
border.bottom = margin;
}
}
this._setRectangle(RotatedRectangleF.FromLTRB(left, top, right, bottom));
this._border = border;
}
this._updateParentSelectionRectangle();
this._region = this._getRegion();
this._canvas.redraw();
};
SelectionHandler.prototype._updateParentSelectionRectangle = function () {
var _a;
var parentGroupItem = null;
var parentGroupItemHandler;
if ((_a = this._itemHandlers) === null || _a === void 0 ? void 0 : _a.any()) {
parentGroupItem = this._itemHandlers.getItem(0).item.parentGroupItem;
parentGroupItemHandler = parentGroupItem && this._canvas.handlerFactory.get(parentGroupItem);
}
if (parentGroupItem == null || parentGroupItemHandler == null || parentGroupItemHandler.isEmpty()) {
this._parentSelectionRectangle = null;
return;
}
var parentGroupItemSelectionRectangle = parentGroupItemHandler.getSelectionRectangle();
this._parentSelectionRectangle = parentGroupItemSelectionRectangle;
};
SelectionHandler.prototype._getRegion = function () {
var rectangle = null;
if (this._canvas.constrainedMarginEnabled && this._canvas.margin > 0) {
var margin = this._canvas.margin;
rectangle = new RectangleF(margin, margin, this._canvas.workspaceWidth - margin, this._canvas.workspaceHeight - margin);
}
this._itemHandlers
.where(function (i) { var _a; return ((_a = i.layer) === null || _a === void 0 ? void 0 : _a.region) != null; })
.select(function (i) { return i.layer.region; })
.distinct()
.forEach(function (region) {
rectangle = rectangle != null ? RectangleF.intersect(rectangle, region) : region;
});
return rectangle;
};
SelectionHandler.prototype.getSelectionDrawingParams = function () {
var _a, _b;
var isOnlyOneLine = false;
var isLineInSelection = false;
var isPlaceholderEditing = false;
var currentItemHandler = null;
if (this._itemHandlers.length === 1) {
currentItemHandler = this._itemHandlers.getItem(0);
isOnlyOneLine = currentItemHandler instanceof LineItemHandler;
isPlaceholderEditing = currentItemHandler instanceof PlaceholderItemHandler && currentItemHandler.editing;
}
else {
isLineInSelection = this._itemHandlers.any(function (i) { return i instanceof LineItemHandler; });
}
var isPlaceholderWithCoverModeEditing = isPlaceholderEditing && currentItemHandler.item.isCoverMode;
var isFitMode = !!currentItemHandler && currentItemHandler.item.contentResizeMode === ResizeMode.Fit;
var isTextEditing = (currentItemHandler instanceof NewBaseTextItemHandler) && currentItemHandler.isInEdit;
var prms = this.manipulationPermissions;
return {
rotate: this.allowManipulation && prms.allowRotate && !isPlaceholderWithCoverModeEditing && !isTextEditing && !isFitMode,
resize: this.allowManipulation && ((_b = (_a = prms.resizeGrips.corner) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : false) && !isOnlyOneLine && !isTextEditing,
arbitraryWidthResize: this.allowManipulation && prms.resizeGrips.edge && !isLineInSelection && !isPlaceholderWithCoverModeEditing && !isTextEditing,
arbitraryHeightResize: this.allowManipulation && prms.resizeGrips.edge && !isOnlyOneLine && !isLineInSelection && !isPlaceholderWithCoverModeEditing && !isTextEditing
};
};
SelectionHandler.prototype.getHighlightRectangles = function () {
var _a;
var result = [];
if (this._itemHandlers == null || this._itemHandlers.length == 0)
return result;
var highlightOpts = { includeChildren: true, includeParent: false };
if (this._itemHandlers.length > 1)
this._itemHandlers.forEach(function (x) { return result.push.apply(result, __spread(x.getHighlightRectangles(highlightOpts))); });
else {
var current = this._itemHandlers.get(0);
var needToHighlight = current instanceof NewBaseTextItemHandler
? current.isHighlightNeeded() && ((_a = this._canvas.textEditor) === null || _a === void 0 ? void 0 : _a.highlightInEditingModeEnabled)
: current.isHighlightNeeded();
if (needToHighlight) {
highlightOpts.includeParent = false;
result.push.apply(result, __spread(current.getHighlightRectangles(highlightOpts)));
}
}
return result;
};
Object.defineProperty(SelectionHandler.prototype, "visibleRectangle", {
get: function () {
return this._getVisibleSelectionRectangle(this._rectangle);
},
enumerable: true,
configurable: true
});
Object.defineProperty(SelectionHandler.prototype, "rectangleSigns", {
get: function () {
return this._rectangleSigns;
},
enumerable: true,
configurable: true
});
SelectionHandler.prototype._getVisibleSelectionRectangle = function (rectangle) {
if (rectangle == null)
return null;
var r = rectangle.clone();
r.width = Math.abs(r.width);
r.height = Math.abs(r.height);
if (this._border != null) {
var angle = r.angle;
r = RotatedRectangleF.fromRectangleF(r.toRectangleF().getExpanded(this._border));
r.angle = angle;
}
return r;
};
Object.defineProperty(SelectionHandler.prototype, "manipulationPermissions", {
get: function () {
return this._manipulationPermissions;
},
enumerable: true,
configurable: true
});
Object.defineProperty(SelectionHandler.prototype, "allowManipulation", {
get: function () {
return this._canvas != null && (!this._canvas.simpleMode || this._canvas.contentEditingPlaceholderItemHandler != null);
},
enumerable: true,
configurable: true
});
Object.defineProperty(SelectionHandler.prototype, "allowMove", {
get: function () {
return this.manipulationPermissions.allowMove && this.allowManipulation;
},
enumerable: true,
configurable: true
});
Object.defineProperty(SelectionHandler.prototype, "_allowNegativeResize", {
get: function () {
return !this._itemHandlers.any(function (i) { return !i.allowNegativeResize; });
},
enumerable: true,
configurable: true
});
SelectionHandler.prototype.addOnSelectionChanged = function (handler) { this._selectionChanged.add(handler); };
SelectionHandler.prototype.removeOnSelectionChanged = function (handler) { this._selectionChanged.remove(handler); };
SelectionHandler.prototype._updateParentItemHandler = function (parentHandler) {
if (this._parentItemHandler == parentHandler)
return;
if (this._parentItemHandler != null) {
this._parentItemHandler.item.removePropertyChanged(this._onParentHandlerPropertyChanged);
}
this._parentItemHandler = parentHandler;
if (this._parentItemHandler != null) {
this._parentItemHandler.item.addPropertyChanged(this._onParentHandlerPropertyChanged);
}
};
SelectionHandler.prototype._getHistoryUpdateMode = function (finished) {
return finished ? HistoryUpdateMode.ForceUpdate : HistoryUpdateMode.NotUpdate;
};
Object.defineProperty(SelectionHandler.prototype, "_items", {
get: function () {
if (this._canvas.contentEditingPlaceholderItemHandler != null)
return [this._canvas.contentEditingPlaceholderItemHandler.item.content];
return this._itemHandlers.select(function (i) { return i.item; }).toArray();
},
enumerable: true,
configurable: true
});
SelectionHandler.prototype._fillSnapData = function () {
var interactiveZonesBounds = this._interactiveZonesHandler.getSnapLines();
var rectWithBorder = getRotatedRectangleWithBorder(this.rectangle, this.border);
this._snapLinesHandler.fillSnapData(this.rectangle, this._selectionProcessModifier.getRectWithFrames(this.rectangle), rectWithBorder != null ? rectWithBorder.bounds : null, this._region, interactiveZonesBounds, this._canvas, this._state === SelectionState.Drag);
};
SelectionHandler.prototype.dispose = function () {
this._itemHandlers.remove_collectionChanged(this._onSelectionItemHandlersChanged);
if (this._currentItemHandler instanceof PlaceholderItemHandler)
this._currentItemHandler.removeIsEditingChanged(this._updatePermissions);
};
SelectionHandler.prototype.addCurrentItemChanged = function (listener) { this._currentItemChangedEvent.add(listener); };
SelectionHandler.prototype.removeCurrentItemChanged = function (listener) { this._currentItemChangedEvent.remove(listener); };
Object.defineProperty(SelectionHandler.prototype, "isIdle", {
get: function () { return this._state === SelectionState.Idle; },
enumerable: true,
configurable: true
});
Object.defineProperty(SelectionHandler.prototype, "isResizing", {
get: function () { return this._state === SelectionState.Resize; },
enumerable: true,
configurable: true
});
Object.defineProperty(SelectionHandler.prototype, "isRotating", {
get: function () { return this._state === SelectionState.Rotate; },
enumerable: true,
configurable: true
});
Object.defineProperty(SelectionHandler.prototype, "isDragging", {
get: function () { return this._state === SelectionState.Drag; },
enumerable: true,
configurable: true
});
//gripses values for multipli (choosing resize strategy)
SelectionHandler.cw = [0, -1, 1, 1, -1, -1, 0, 1, 0];
SelectionHandler.ch = [0, -1, -1, 1, 1, 0, -1, 0, 1];
return SelectionHandler;
}());
export { SelectionHandler };
export var SelectionState;
(function (SelectionState) {
SelectionState[SelectionState["Idle"] = 0] = "Idle";
SelectionState[SelectionState["Select"] = 1] = "Select";
SelectionState[SelectionState["Drag"] = 2] = "Drag";
SelectionState[SelectionState["Resize"] = 3] = "Resize";
SelectionState[SelectionState["Rotate"] = 4] = "Rotate";
})(SelectionState || (SelectionState = {}));
var ResizeHelper = /** @class */ (function () {
function ResizeHelper() {
}
ResizeHelper.isLeftResizeGrip = function (index) {
return index === 1 || index === 4 || index === 5;
};
ResizeHelper.isTopResizeGrip = function (index) {
return index === 1 || index === 2 || index === 6;
};
ResizeHelper.isRightResizeGrip = function (index) {
return index === 2 || index === 3 || index === 7;
};
ResizeHelper.isBottomResizeGrip = function (index) {
return index === 3 || index === 4 || index === 8;
};
ResizeHelper.isCornerResizeGrip = function (index) {
return index === 1 || index === 2 || index === 3 || index === 4;
};
ResizeHelper.isEdgeResizeGrip = function (index) {
return index === 5 || index === 6 || index === 7 || index === 8;
};
return ResizeHelper;
}());
export { ResizeHelper };
//# sourceMappingURL=SelectionHandler.js.map