UNPKG

@eclipse-glsp/client

Version:

A sprotty-based client for GLSP

66 lines 3.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.KeyboardPointerPosition = 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 css_feedback_1 = require("../../../base/feedback/css-feedback"); const viewpoint_util_1 = require("../../../utils/viewpoint-util"); const model_1 = require("../../hints/model"); const constants_1 = require("./constants"); class KeyboardPointerPosition { constructor(keyboardPointer) { this.keyboardPointer = keyboardPointer; this.renderPosition = { x: 20, y: 20 }; } get centerizedRenderPosition() { return { x: this.renderPosition.x + constants_1.KeyboardPointerMetadata.CIRCLE_WIDTH / 2, y: this.renderPosition.y + constants_1.KeyboardPointerMetadata.CRICLE_HEIGHT / 2 }; } get diagramPosition() { return (0, viewpoint_util_1.getAbsolutePositionByPoint)(this.keyboardPointer.editorContextService.modelRoot, this.centerizedRenderPosition); } childrenAtDiagramPosition() { const position = this.diagramPosition; return [ this.keyboardPointer.editorContextService.modelRoot, ...(0, sprotty_1.findChildrenAtPosition)(this.keyboardPointer.editorContextService.modelRoot, position) ]; } containableParentAtDiagramPosition(elementTypeId) { const children = this.childrenAtDiagramPosition(); return this.containableParentOf(children.reverse()[0], elementTypeId); } calcRelativeRenderPosition(x, y) { return { x: this.renderPosition.x + x, y: this.renderPosition.y + y }; } containableParentOf(target, elementTypeId) { const container = (0, sprotty_1.findParentByFeature)(target, model_1.isContainable); return { container, status: this.keyboardPointer.containerManager.isCreationAllowed(container, elementTypeId) ? css_feedback_1.CursorCSS.NODE_CREATION : css_feedback_1.CursorCSS.OPERATION_NOT_ALLOWED }; } } exports.KeyboardPointerPosition = KeyboardPointerPosition; //# sourceMappingURL=keyboard-pointer-position.js.map