UNPKG

@eclipse-glsp/client

Version:

A sprotty-based client for GLSP

66 lines 2.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GReconnectHandle = exports.reconnectFeature = void 0; exports.isReconnectable = isReconnectable; exports.isReconnectHandle = isReconnectHandle; exports.addReconnectHandles = addReconnectHandles; exports.removeReconnectHandles = removeReconnectHandles; exports.isSourceRoutingHandle = isSourceRoutingHandle; exports.isTargetRoutingHandle = isTargetRoutingHandle; exports.createReconnectHandle = createReconnectHandle; /******************************************************************************** * Copyright (c) 2019-2023 EclipseSource 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"); exports.reconnectFeature = Symbol('reconnectFeature'); function isReconnectable(element) { return element instanceof sprotty_1.GRoutableElement && element.hasFeature(exports.reconnectFeature); } const ROUTING_HANDLE_SOURCE_INDEX = -2; function isReconnectHandle(element) { return element !== undefined && element instanceof GReconnectHandle; } function addReconnectHandles(element) { removeReconnectHandles(element); createReconnectHandle(element, 'source', ROUTING_HANDLE_SOURCE_INDEX); createReconnectHandle(element, 'target', element.routingPoints.length); } function removeReconnectHandles(element) { element.removeAll(child => child instanceof GReconnectHandle); } function isSourceRoutingHandle(edge, routingHandle) { return routingHandle.pointIndex === ROUTING_HANDLE_SOURCE_INDEX; } function isTargetRoutingHandle(edge, routingHandle) { return routingHandle.pointIndex === edge.routingPoints.length; } function createReconnectHandle(edge, kind, routingPointIndex) { const handle = new GReconnectHandle(); handle.kind = kind; handle.pointIndex = routingPointIndex; handle.type = 'routing-point'; if (kind === 'target' && edge.id === sprotty_1.edgeInProgressID) { handle.id = sprotty_1.edgeInProgressTargetHandleID; } edge.add(handle); return handle; } class GReconnectHandle extends sprotty_1.GRoutingHandle { hasFeature(feature) { return feature !== sprotty_1.selectFeature && super.hasFeature(feature); } } exports.GReconnectHandle = GReconnectHandle; //# sourceMappingURL=model.js.map