@eclipse-glsp/client
Version:
A sprotty-based client for GLSP
129 lines • 6.31 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);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.KeyboardPointer = void 0;
/********************************************************************************
* Copyright (c) 2023-2024 Business Informatics Group (TU Wien) and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
const sprotty_1 = require("@eclipse-glsp/sprotty");
const inversify_1 = require("inversify");
const editor_context_service_1 = require("../../../base/editor-context-service");
const css_feedback_1 = require("../../../base/feedback/css-feedback");
const ui_extension_1 = require("../../../base/ui-extension/ui-extension");
const container_manager_1 = require("../../tools/node-creation/container-manager");
const action_1 = require("../keyboard-grid/action");
const actions_1 = require("./actions");
const constants_1 = require("./constants");
const keyboard_pointer_listener_1 = require("./keyboard-pointer-listener");
const keyboard_pointer_position_1 = require("./keyboard-pointer-position");
let KeyboardPointer = class KeyboardPointer extends ui_extension_1.GLSPAbstractUIExtension {
constructor(actionDispatcher) {
super();
this.actionDispatcher = actionDispatcher;
this._triggerAction = {
elementTypeId: 'task:automated',
kind: 'triggerNodeCreation'
};
this.position = new keyboard_pointer_position_1.KeyboardPointerPosition(this);
this.keyListener = new keyboard_pointer_listener_1.KeyboardPointerKeyboardListener(this, actionDispatcher);
}
get triggerAction() {
return this._triggerAction;
}
get isVisible() {
var _a;
return ((_a = this.containerElement) === null || _a === void 0 ? void 0 : _a.style.visibility) === 'visible';
}
get getPosition() {
return this.position;
}
get getKeyListener() {
return this.keyListener;
}
id() {
return constants_1.KeyboardPointerMetadata.ID;
}
containerClass() {
return constants_1.KeyboardPointerMetadata.ID;
}
initializeContents(containerElement) {
containerElement.style.position = 'absolute';
containerElement.style.height = `${constants_1.KeyboardPointerMetadata.CRICLE_HEIGHT}px`;
containerElement.style.width = `${constants_1.KeyboardPointerMetadata.CIRCLE_WIDTH}px`;
containerElement.style.borderRadius = '100%';
}
onBeforeShow(containerElement, root, ...selectedElementIds) {
this.render();
}
handle(action) {
if (sprotty_1.TriggerNodeCreationAction.is(action)) {
this._triggerAction = action;
}
else if (actions_1.SetKeyboardPointerRenderPositionAction.is(action)) {
this.position.renderPosition = { x: action.x, y: action.y };
this.render();
}
else if (action_1.KeyboardGridCellSelectedAction.is(action) && action.options.originId === constants_1.KeyboardPointerMetadata.ID) {
this.position.renderPosition = action.options.centerCellPosition;
this.render();
}
}
render() {
if (this.containerElement !== undefined) {
const { x, y } = this.position.renderPosition;
this.containerElement.style.left = `${x}px`;
this.containerElement.style.top = `${y}px`;
const { status } = this.position.containableParentAtDiagramPosition(this._triggerAction.elementTypeId);
this.containerElement.style.borderStyle = 'solid';
this.containerElement.style.borderWidth = 'thick';
switch (status) {
case css_feedback_1.CursorCSS.NODE_CREATION: {
this.containerElement.style.borderColor = 'green';
break;
}
case css_feedback_1.CursorCSS.OPERATION_NOT_ALLOWED: {
this.containerElement.style.borderColor = 'red';
break;
}
}
}
}
};
exports.KeyboardPointer = KeyboardPointer;
__decorate([
(0, inversify_1.inject)(editor_context_service_1.EditorContextService),
__metadata("design:type", editor_context_service_1.EditorContextService)
], KeyboardPointer.prototype, "editorContextService", void 0);
__decorate([
(0, inversify_1.inject)(sprotty_1.TYPES.IContainerManager),
__metadata("design:type", container_manager_1.ContainerManager)
], KeyboardPointer.prototype, "containerManager", void 0);
exports.KeyboardPointer = KeyboardPointer = __decorate([
(0, inversify_1.injectable)(),
__param(0, (0, inversify_1.inject)(sprotty_1.TYPES.IActionDispatcher)),
__metadata("design:paramtypes", [Object])
], KeyboardPointer);
//# sourceMappingURL=keyboard-pointer.js.map