@aurigma/design-atoms
Version:
Design Atoms is a part of Customer's Canvas SDK which allows for manipulating individual design elements through your code.
456 lines • 25.5 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 __values = (this && this.__values) || function(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
import { Button, InputState } from "./../../../Input/InputManager/IInputManager";
import { NewBaseTextItemHandler, GroupItemHandler, PlaceholderItemHandler } from "./../../../ItemHandlers";
import { MultiSelectMode } from "./../../../Commands/SelectionCommand/SelectItemsCommand";
import { BaseTextItem, PlaceholderItem } from "@aurigma/design-atoms-model/Product/Items";
import { FrontEndLogger, LogSource } from "./../../../Services/FrontEndLogger";
import { CoordinatesConvertUtils } from "./../../../Utils/CoordinatesConvertUtils";
import { CoordinateSystem } from "../../../Viewer/CoordinateSystem";
import { SelectionCommand } from "@aurigma/design-atoms-interfaces";
var PointerInputHandlerHelper = /** @class */ (function () {
function PointerInputHandlerHelper(_canvas, _commandManager, _selectionHandler, _hitTestManager, _eventManager, _dndHandler, _rotateHandler) {
var _this = this;
this._canvas = _canvas;
this._commandManager = _commandManager;
this._selectionHandler = _selectionHandler;
this._hitTestManager = _hitTestManager;
this._eventManager = _eventManager;
this._dndHandler = _dndHandler;
this._rotateHandler = _rotateHandler;
this._processInPlaceEditingMouseEvent = function (params, handler, pointerOverCurrent) {
if (handler === void 0) { handler = null; }
if (pointerOverCurrent === void 0) { pointerOverCurrent = null; }
return __awaiter(_this, void 0, void 0, function () {
var item;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (handler == null) {
item = this.getItemToSelect(params.workspace, false);
if (item == null || !this._isInPlaceAvailableForItem(item))
return [2 /*return*/, false];
handler = this._canvas.handlerFactory.get(item);
}
if (pointerOverCurrent == null)
pointerOverCurrent = handler.hitTest(params.workspace).body;
this._commandManager.execute(SelectionCommand.selectItems, { items: [handler.item], multiSelectMode: MultiSelectMode.None });
return [4 /*yield*/, handler.processInPlaceEditingMouseEvent(params, pointerOverCurrent)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
};
this._contextMenuNotify = function (params) {
_this._eventManager.contextMenuEvent.fire({ pointerParams: params, items: __spread(_this._selectedItems) });
FrontEndLogger.debugLog("Context menu fired!", LogSource.InputManager);
};
this._handleRotating = function (params) {
_this._selectionHandler.rotateByPoint(_this._getRotatingArgs(params), params.state, params.startWorkspace);
_this._rotateHandler.updateView(_this._selectionHandler.selectedItemHandlers.get(0), params.workspace, params.state, _this._selectionHandler.rectangle.angle);
};
this._getRotatingArgs = function (params) {
var args = {
finished: params.state === InputState.Finished,
point: params.workspace,
rotationStep: params.shiftKey ? 15 : 90,
tolerance: params.ctrlKey ? 0 : (params.shiftKey ? 7.5 : 5)
};
return args;
};
this._handleMoving = function (params) {
var args = {
finished: params.state === InputState.Finished,
point: params.workspace
};
_this._selectionHandler.moveByPoint(args, params.state, params.ctrlKey, params.startWorkspace);
};
this._selectItemForMoving = function (params, dragOnlySelectedHandler) { return __awaiter(_this, void 0, void 0, function () {
var itemHandler, item, isManipulationAllowed, isPlaceholderEditModeEnabled, args;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if ((dragOnlySelectedHandler && !this._canvas.autoPlaceholderEditModeEnabled) || this._canvas.contentEditingPlaceholderItemHandler != null)
return [2 /*return*/];
itemHandler = this.getHandlerToSelect(params.startWorkspace, false);
item = itemHandler === null || itemHandler === void 0 ? void 0 : itemHandler.item;
if (item == null)
return [2 /*return*/];
isManipulationAllowed = !this._canvas.simpleMode && item.manipulationPermissions.allowMove;
isPlaceholderEditModeEnabled = itemHandler instanceof PlaceholderItemHandler && this._canvas.autoPlaceholderEditModeEnabled;
if (!isManipulationAllowed && !isPlaceholderEditModeEnabled)
return [2 /*return*/];
args = {
items: [item]
};
return [4 /*yield*/, this._commandManager.execute(SelectionCommand.selectItems, args)];
case 1:
_a.sent();
if (isPlaceholderEditModeEnabled)
itemHandler.editing = true;
return [2 /*return*/, item];
}
});
}); };
this._handleResizing = function (params, ht) {
if (params.state === InputState.Started)
_this._resizeStartedHitTestResult = ht;
var arbitraryResize = _this._resizeStartedHitTestResult.arbitraryResize;
if (params.shiftKey) {
if (_this._resizeStartedHitTestResult.arbitraryResize && _this._resizeStartedHitTestResult.cornerProportionalResize) {
arbitraryResize = false;
}
else if (!arbitraryResize && _this._resizeStartedHitTestResult.cornerArbitraryResize) {
arbitraryResize = true;
}
}
var args = {
arbitraryResize: arbitraryResize,
finished: params.state === InputState.Finished,
point: params.workspace,
resizeIndex: _this._resizeStartedHitTestResult.resizeIndex
};
_this._selectionHandler.resizeByPoint(args, params.state, params.startWorkspace);
if (params.state === InputState.Finished)
_this._resizeStartedHitTestResult = null;
};
}
PointerInputHandlerHelper.prototype.onPointerClick = function (params, multiselect) {
var _a;
return __awaiter(this, void 0, void 0, function () {
var _b, productPoint, hitTestResult, clickInsideSelection, shiftRightClick;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
_b = this._canvas.inPlaceEditingHandler != null;
if (!_b) return [3 /*break*/, 2];
return [4 /*yield*/, this._processInPlaceEditingMouseEvent(params, this._canvas.inPlaceEditingHandler)];
case 1:
_b = (_c.sent());
_c.label = 2;
case 2:
if (_b)
return [2 /*return*/];
productPoint = CoordinatesConvertUtils.workspaceToProduct(params.workspace, this._canvas.offset);
hitTestResult = this._selectionHandler.selectionHitTestManager.hitTest(params.workspace);
if (hitTestResult.resize || hitTestResult.rotate)
return [2 /*return*/];
clickInsideSelection = ((_a = this._selectionHandler.rectangle) === null || _a === void 0 ? void 0 : _a.contains(productPoint));
shiftRightClick = params.shiftKey && params.button === Button.Secondary;
if (shiftRightClick) {
if (clickInsideSelection)
this._contextMenuNotify(params);
return [2 /*return*/];
}
if (!clickInsideSelection) return [3 /*break*/, 4];
return [4 /*yield*/, this._processClickInsideSelection(params, multiselect)];
case 3:
_c.sent();
return [3 /*break*/, 6];
case 4: return [4 /*yield*/, this._processClickOutsideSelection(params, multiselect)];
case 5:
_c.sent();
_c.label = 6;
case 6:
if (params.button === Button.Secondary) {
this._contextMenuNotify(params);
}
return [2 /*return*/];
}
});
});
};
PointerInputHandlerHelper.prototype.onPointerMove = function (params, dragOnlySelectedHandler) {
return __awaiter(this, void 0, void 0, function () {
var _a, isIdle, hitTestResult, selectedPhItemHandler, movingItem, selectedItems;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = this._canvas.inPlaceEditingHandler != null;
if (!_a) return [3 /*break*/, 2];
return [4 /*yield*/, this._processInPlaceEditingMouseEvent(params, this._canvas.inPlaceEditingHandler)];
case 1:
_a = (_b.sent());
_b.label = 2;
case 2:
if (_a)
return [2 /*return*/];
if (this._dndHandler.isDragStarted())
return [2 /*return*/, this._dndHandler.processMove(params)];
isIdle = this._selectionHandler.isIdle;
hitTestResult = isIdle ? this._selectionHandler.selectionHitTestManager.hitTest(params.startWorkspace) : null;
selectedPhItemHandler = this._selectionHandler.currentItemHandler;
if (selectedPhItemHandler != null && selectedPhItemHandler instanceof PlaceholderItemHandler && this._canvas.autoPlaceholderEditModeEnabled && (hitTestResult === null || hitTestResult === void 0 ? void 0 : hitTestResult.drag))
selectedPhItemHandler.editing = true;
if (this._selectionHandler.isRotating || (hitTestResult === null || hitTestResult === void 0 ? void 0 : hitTestResult.rotate))
return [2 /*return*/, this._handleRotating(params)];
if (this._selectionHandler.isResizing || (hitTestResult === null || hitTestResult === void 0 ? void 0 : hitTestResult.resize))
return [2 /*return*/, this._handleResizing(params, hitTestResult)];
if (!(this._selectionHandler.isDragging || (hitTestResult === null || hitTestResult === void 0 ? void 0 : hitTestResult.drag))) return [3 /*break*/, 3];
return [2 /*return*/, this._handleMoving(params)];
case 3: return [4 /*yield*/, this._selectItemForMoving(params, dragOnlySelectedHandler)];
case 4:
movingItem = _b.sent();
if (movingItem != null)
return [2 /*return*/, this._handleMoving(params)];
_b.label = 5;
case 5:
if (params.state !== InputState.Started || this._canvas.contentEditingPlaceholderItemHandler != null)
return [2 /*return*/];
selectedItems = this._selectedItems;
if (!dragOnlySelectedHandler || (selectedItems.length === 1 && selectedItems[0] instanceof PlaceholderItem))
this._dndHandler.processMove(params);
return [2 /*return*/];
}
});
});
};
PointerInputHandlerHelper.prototype.onDoubleClick = function (params) {
return __awaiter(this, void 0, void 0, function () {
var item;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
item = this.getItemToSelect(params.workspace, false);
return [4 /*yield*/, this._processInPlaceEditingMouseEvent(params, null, true)];
case 1:
_a.sent();
this._eventManager.doubleClickEvent.fire(item);
return [2 /*return*/];
}
});
});
};
PointerInputHandlerHelper.prototype.onPointerDown = function (params) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(this._canvas.inPlaceEditingHandler != null)) return [3 /*break*/, 2];
return [4 /*yield*/, this._processInPlaceEditingMouseEvent(params, this._canvas.inPlaceEditingHandler)];
case 1:
_a.sent();
_a.label = 2;
case 2: return [2 /*return*/];
}
});
});
};
PointerInputHandlerHelper.prototype.onPointerHover = function (params) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!(this._canvas.inPlaceEditingHandler != null)) return [3 /*break*/, 2];
return [4 /*yield*/, this._processInPlaceEditingMouseEvent(params, this._canvas.inPlaceEditingHandler)];
case 1:
_a.sent();
_a.label = 2;
case 2: return [2 /*return*/];
}
});
});
};
PointerInputHandlerHelper.prototype._processClickInsideSelection = function (params, multiselect) {
return __awaiter(this, void 0, void 0, function () {
var selectedItems, isCurrentSelectionMultiple, item;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
selectedItems = this._selectedItems;
isCurrentSelectionMultiple = selectedItems.length > 1;
item = this.getItemToSelect(params.workspace, !isCurrentSelectionMultiple && params.button === Button.Primary);
if (item == null)
return [2 /*return*/];
if (!(!multiselect && selectedItems.length === 1)) return [3 /*break*/, 5];
if (!(selectedItems[0] === item)) return [3 /*break*/, 3];
if (!(params.button === Button.Primary && this._isInPlaceAvailableForItem(item))) return [3 /*break*/, 2];
return [4 /*yield*/, this._processInPlaceEditingMouseEvent(params, this._canvas.handlerFactory.get(item), true)];
case 1: return [2 /*return*/, _a.sent()];
case 2: return [3 /*break*/, 5];
case 3: return [4 /*yield*/, this._selectItems([item], MultiSelectMode.None)];
case 4:
_a.sent();
_a.label = 5;
case 5:
if (!multiselect)
return [2 /*return*/];
return [4 /*yield*/, this._selectItems([item], MultiSelectMode.Invert)];
case 6:
_a.sent();
return [2 /*return*/];
}
});
});
};
PointerInputHandlerHelper.prototype._processClickOutsideSelection = function (params, multiselect) {
return __awaiter(this, void 0, void 0, function () {
var item;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
item = this.getItemToSelect(params.workspace, false);
if (!(item == null)) return [3 /*break*/, 2];
return [4 /*yield*/, this._commandManager.execute(SelectionCommand.clearSelection)];
case 1: return [2 /*return*/, _a.sent()];
case 2: return [4 /*yield*/, this._selectItems([item], multiselect ? MultiSelectMode.Invert : MultiSelectMode.None)];
case 3:
_a.sent();
return [2 /*return*/];
}
});
});
};
PointerInputHandlerHelper.prototype.getItemToSelect = function (pt, expandGroup) {
var _a;
return (_a = this.getHandlerToSelect(pt, expandGroup)) === null || _a === void 0 ? void 0 : _a.item;
};
PointerInputHandlerHelper.prototype.getHandlerToSelect = function (pt, expandGroup) {
var _a;
var handlers = this._getHandlersByPoint(pt);
if (handlers.length === 0)
return null;
var selectedHandlers = this._selectionHandler.selectedItemHandlers;
var first = selectedHandlers.firstOrDefault();
if (expandGroup && this._selectedItems.length === 1 && handlers.includes(first) && first instanceof GroupItemHandler) {
var index = handlers.indexOf(first);
var targetHandler = (_a = handlers[index + 1]) !== null && _a !== void 0 ? _a : handlers[index];
return targetHandler;
}
var getFirstDirectChildItem = function (parent) {
var e_1, _a;
try {
for (var handlers_1 = __values(handlers), handlers_1_1 = handlers_1.next(); !handlers_1_1.done; handlers_1_1 = handlers_1.next()) {
var handler = handlers_1_1.value;
if (handler.parentGroupItemHandler == parent)
return handler;
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (handlers_1_1 && !handlers_1_1.done && (_a = handlers_1.return)) _a.call(handlers_1);
}
finally { if (e_1) throw e_1.error; }
}
return null;
};
var currentParent = first === null || first === void 0 ? void 0 : first.parentGroupItemHandler;
while (currentParent != null) {
var sibling = getFirstDirectChildItem(currentParent);
if (sibling)
return sibling;
if (handlers.includes(currentParent))
return currentParent;
currentParent = currentParent.parentGroupItemHandler;
}
return handlers[0];
};
PointerInputHandlerHelper.prototype._getHandlersByPoint = function (pt) {
return this._hitTestManager.getItemHandlersByHitTest(pt, CoordinateSystem.workspace);
};
Object.defineProperty(PointerInputHandlerHelper.prototype, "_selectedItems", {
get: function () {
return this._canvas.getSelectedItemHandlers().toArray().map(function (h) { return h.item; });
},
enumerable: true,
configurable: true
});
PointerInputHandlerHelper.prototype._getItems = function (pt) {
return this._canvas.getSelectedItemHandlers().toArray().map(function (h) { return h.item; });
};
PointerInputHandlerHelper.prototype._isInPlaceAvailableForItem = function (item) {
if (!(item instanceof BaseTextItem))
return false;
var handler = this._canvas.handlerFactory.get(item);
if (!(handler instanceof NewBaseTextItemHandler))
return false;
return handler.inPlaceEditingEnabled;
};
PointerInputHandlerHelper.prototype._selectItems = function (items, mode) {
return __awaiter(this, void 0, void 0, function () {
var selectionArgs;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
selectionArgs = {
items: items,
multiSelectMode: mode
};
return [4 /*yield*/, this._commandManager.execute(SelectionCommand.selectItems, selectionArgs)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
return PointerInputHandlerHelper;
}());
export { PointerInputHandlerHelper };
//# sourceMappingURL=PointerInputHandlerHelper.js.map