From 310a9f5d28c06786007d2d53f772837f04a6dbfe Mon Sep 17 00:00:00 2001 From: Martin Fleck Date: Sun, 10 Mar 2024 12:42:20 +0100 Subject: [PATCH] Apply PR feedback: Properly re-export fixed Sprotty classes --- .../routing/glsp-bezier-edge-router.ts | 32 ------- .../routing/glsp-manhattan-edge-router.ts | 22 +---- .../routing/glsp-polyline-edge-router.ts | 32 ------- packages/client/src/features/routing/index.ts | 1 - .../src/features/routing/routing-module.ts | 8 +- packages/glsp-sprotty/src/index.ts | 1 + packages/glsp-sprotty/src/re-exports.ts | 22 ++++- packages/glsp-sprotty/src/routing-override.ts | 88 +++++++++++++++++++ 8 files changed, 112 insertions(+), 94 deletions(-) delete mode 100644 packages/client/src/features/routing/glsp-bezier-edge-router.ts delete mode 100644 packages/client/src/features/routing/glsp-polyline-edge-router.ts create mode 100644 packages/glsp-sprotty/src/routing-override.ts diff --git a/packages/client/src/features/routing/glsp-bezier-edge-router.ts b/packages/client/src/features/routing/glsp-bezier-edge-router.ts deleted file mode 100644 index 9ee41249..00000000 --- a/packages/client/src/features/routing/glsp-bezier-edge-router.ts +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2024 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 - ********************************************************************************/ -import { BezierEdgeRouter, GConnectableElement, GParentElement, GRoutableElement, Point } from '@eclipse-glsp/sprotty'; -import { injectable } from 'inversify'; - -@injectable() -export class GLSPBezierEdgeRouter extends BezierEdgeRouter { - override getTranslatedAnchor( - connectable: GConnectableElement, - refPoint: Point, - refContainer: GParentElement, - edge: GRoutableElement, - anchorCorrection?: number | undefined - ): Point { - // users may define all kinds of anchors and anchor computers, we want to make sure we return a valid one in any case - const anchor = super.getTranslatedAnchor(connectable, refPoint, refContainer, edge, anchorCorrection); - return Point.isValid(anchor) ? anchor : refPoint; - } -} diff --git a/packages/client/src/features/routing/glsp-manhattan-edge-router.ts b/packages/client/src/features/routing/glsp-manhattan-edge-router.ts index 62b2c8fa..390c5982 100644 --- a/packages/client/src/features/routing/glsp-manhattan-edge-router.ts +++ b/packages/client/src/features/routing/glsp-manhattan-edge-router.ts @@ -14,15 +14,7 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ -import { - GConnectableElement, - GParentElement, - GRoutableElement, - ManhattanEdgeRouter, - Point, - ResolvedHandleMove, - almostEquals -} from '@eclipse-glsp/sprotty'; +import { GRoutableElement, ManhattanEdgeRouter, ResolvedHandleMove, almostEquals } from '@eclipse-glsp/sprotty'; export class GLSPManhattanEdgeRouter extends ManhattanEdgeRouter { protected override applyInnerHandleMoves(edge: GRoutableElement, moves: ResolvedHandleMove[]): void { @@ -64,16 +56,4 @@ export class GLSPManhattanEdgeRouter extends ManhattanEdgeRouter { } }); } - - override getTranslatedAnchor( - connectable: GConnectableElement, - refPoint: Point, - refContainer: GParentElement, - edge: GRoutableElement, - anchorCorrection?: number | undefined - ): Point { - // users may define all kinds of anchors and anchor computers, we want to make sure we return a valid one in any case - const anchor = super.getTranslatedAnchor(connectable, refPoint, refContainer, edge, anchorCorrection); - return Point.isValid(anchor) ? anchor : refPoint; - } } diff --git a/packages/client/src/features/routing/glsp-polyline-edge-router.ts b/packages/client/src/features/routing/glsp-polyline-edge-router.ts deleted file mode 100644 index 97a83c5e..00000000 --- a/packages/client/src/features/routing/glsp-polyline-edge-router.ts +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************** - * Copyright (c) 2024 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 - ********************************************************************************/ -import { GConnectableElement, GParentElement, GRoutableElement, Point, PolylineEdgeRouter } from '@eclipse-glsp/sprotty'; -import { injectable } from 'inversify'; - -@injectable() -export class GLSPPolylineEdgeRouter extends PolylineEdgeRouter { - override getTranslatedAnchor( - connectable: GConnectableElement, - refPoint: Point, - refContainer: GParentElement, - edge: GRoutableElement, - anchorCorrection?: number | undefined - ): Point { - // users may define all kinds of anchors and anchor computers, we want to make sure we return a valid one in any case - const anchor = super.getTranslatedAnchor(connectable, refPoint, refContainer, edge, anchorCorrection); - return Point.isValid(anchor) ? anchor : refPoint; - } -} diff --git a/packages/client/src/features/routing/index.ts b/packages/client/src/features/routing/index.ts index b8acc9e7..452038f5 100644 --- a/packages/client/src/features/routing/index.ts +++ b/packages/client/src/features/routing/index.ts @@ -14,5 +14,4 @@ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 ********************************************************************************/ export * from './glsp-manhattan-edge-router'; -export * from './glsp-polyline-edge-router'; export * from './routing-module'; diff --git a/packages/client/src/features/routing/routing-module.ts b/packages/client/src/features/routing/routing-module.ts index 18e46a57..7fb859c7 100644 --- a/packages/client/src/features/routing/routing-module.ts +++ b/packages/client/src/features/routing/routing-module.ts @@ -17,6 +17,7 @@ import { AddRemoveBezierSegmentCommand, AnchorComputerRegistry, BezierDiamondAnchor, + BezierEdgeRouter, BezierEllipseAnchor, BezierRectangleAnchor, DiamondAnchor, @@ -26,14 +27,13 @@ import { ManhattanDiamondAnchor, ManhattanEllipticAnchor, ManhattanRectangularAnchor, + PolylineEdgeRouter, RectangleAnchor, TYPES, bindAsService, configureCommand } from '@eclipse-glsp/sprotty'; import { GLSPManhattanEdgeRouter } from './glsp-manhattan-edge-router'; -import { GLSPPolylineEdgeRouter } from './glsp-polyline-edge-router'; -import { GLSPBezierEdgeRouter } from './glsp-bezier-edge-router'; export const routingModule = new FeatureModule((bind, unbind, isBound, rebind) => { const context = { bind, unbind, isBound, rebind }; @@ -45,12 +45,12 @@ export const routingModule = new FeatureModule((bind, unbind, isBound, rebind) = bindAsService(context, TYPES.IAnchorComputer, ManhattanRectangularAnchor); bindAsService(context, TYPES.IAnchorComputer, ManhattanDiamondAnchor); - bindAsService(context, TYPES.IEdgeRouter, GLSPPolylineEdgeRouter); + bindAsService(context, TYPES.IEdgeRouter, PolylineEdgeRouter); bindAsService(context, TYPES.IAnchorComputer, EllipseAnchor); bindAsService(context, TYPES.IAnchorComputer, RectangleAnchor); bindAsService(context, TYPES.IAnchorComputer, DiamondAnchor); - bindAsService(context, TYPES.IEdgeRouter, GLSPBezierEdgeRouter); + bindAsService(context, TYPES.IEdgeRouter, BezierEdgeRouter); bindAsService(context, TYPES.IAnchorComputer, BezierEllipseAnchor); bindAsService(context, TYPES.IAnchorComputer, BezierRectangleAnchor); bindAsService(context, TYPES.IAnchorComputer, BezierDiamondAnchor); diff --git a/packages/glsp-sprotty/src/index.ts b/packages/glsp-sprotty/src/index.ts index f24046c9..9d5b71ba 100644 --- a/packages/glsp-sprotty/src/index.ts +++ b/packages/glsp-sprotty/src/index.ts @@ -16,4 +16,5 @@ export * from './action-override'; export * from './feature-modules'; export * from './re-exports'; +export * from './routing-override'; export * from './types'; diff --git a/packages/glsp-sprotty/src/re-exports.ts b/packages/glsp-sprotty/src/re-exports.ts index af6027f5..2ce6fd98 100644 --- a/packages/glsp-sprotty/src/re-exports.ts +++ b/packages/glsp-sprotty/src/re-exports.ts @@ -192,12 +192,26 @@ export * from 'sprotty/lib/features/open/open'; export * from 'sprotty/lib/features/projection/model'; export * from 'sprotty/lib/features/projection/views'; -export * from 'sprotty/lib/features/routing/abstract-edge-router'; +export { + DefaultAnchors, + LinearRouteOptions, + Side, + AbstractEdgeRouter as SprottyAbstractEdgeRouter +} from 'sprotty/lib/features/routing/abstract-edge-router'; export * from 'sprotty/lib/features/routing/anchor'; export * from 'sprotty/lib/features/routing/bezier-anchors'; -export * from 'sprotty/lib/features/routing/bezier-edge-router'; +export { + AddRemoveBezierSegmentAction, + AddRemoveBezierSegmentCommand, + BezierMouseListener, + BezierEdgeRouter as SprottyBezierEdgeRouter +} from 'sprotty/lib/features/routing/bezier-edge-router'; export * from 'sprotty/lib/features/routing/manhattan-anchors'; -export * from 'sprotty/lib/features/routing/manhattan-edge-router'; +export { + ManhattanRouterOptions, + ManhattanEdgeRouter as SprottyManhattanEdgeRouter +} from 'sprotty/lib/features/routing/manhattan-edge-router'; + // Alias SModel types export { Connectable, @@ -214,7 +228,7 @@ export { isConnectable } from 'sprotty/lib/features/routing/model'; export * from 'sprotty/lib/features/routing/polyline-anchors'; -export * from 'sprotty/lib/features/routing/polyline-edge-router'; +export { PolylineRouteOptions, PolylineEdgeRouter as SprottyPolylineEdgeRouter } from 'sprotty/lib/features/routing/polyline-edge-router'; export * from 'sprotty/lib/features/routing/routing'; export * from 'sprotty/lib/features/routing/views'; diff --git a/packages/glsp-sprotty/src/routing-override.ts b/packages/glsp-sprotty/src/routing-override.ts new file mode 100644 index 00000000..8bde30cb --- /dev/null +++ b/packages/glsp-sprotty/src/routing-override.ts @@ -0,0 +1,88 @@ +/******************************************************************************** + * Copyright (c) 2024 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 + ********************************************************************************/ + +import { Point } from '@eclipse-glsp/protocol'; +import { injectable } from 'inversify'; +import { + SConnectableElementImpl, + SParentElementImpl, + SRoutableElementImpl, + AbstractEdgeRouter as SprottyAbstractEdgeRouter, + BezierEdgeRouter as SprottyBezierEdgeRouter, + ManhattanEdgeRouter as SprottyManhattanEdgeRouter, + PolylineEdgeRouter as SprottyPolylineEdgeRouter +} from 'sprotty'; +import { GConnectableElement, GParentElement, GRoutableElement } from './re-exports'; + +@injectable() +export abstract class AbstractEdgeRouter extends SprottyAbstractEdgeRouter { + override getTranslatedAnchor( + connectable: SConnectableElementImpl, + refPoint: Point, + refContainer: SParentElementImpl, + edge: SRoutableElementImpl, + anchorCorrection?: number | undefined + ): Point { + // users may define all kinds of anchors and anchor computers, we want to make sure we return a valid one in any case + const anchor = super.getTranslatedAnchor(connectable, refPoint, refContainer, edge, anchorCorrection); + return Point.isValid(anchor) ? anchor : refPoint; + } +} + +@injectable() +export class PolylineEdgeRouter extends SprottyPolylineEdgeRouter { + override getTranslatedAnchor( + connectable: GConnectableElement, + refPoint: Point, + refContainer: GParentElement, + edge: GRoutableElement, + anchorCorrection?: number | undefined + ): Point { + // users may define all kinds of anchors and anchor computers, we want to make sure we return a valid one in any case + const anchor = super.getTranslatedAnchor(connectable, refPoint, refContainer, edge, anchorCorrection); + return Point.isValid(anchor) ? anchor : refPoint; + } +} + +@injectable() +export class ManhattanEdgeRouter extends SprottyManhattanEdgeRouter { + override getTranslatedAnchor( + connectable: GConnectableElement, + refPoint: Point, + refContainer: GParentElement, + edge: GRoutableElement, + anchorCorrection?: number | undefined + ): Point { + // users may define all kinds of anchors and anchor computers, we want to make sure we return a valid one in any case + const anchor = super.getTranslatedAnchor(connectable, refPoint, refContainer, edge, anchorCorrection); + return Point.isValid(anchor) ? anchor : refPoint; + } +} + +@injectable() +export class BezierEdgeRouter extends SprottyBezierEdgeRouter { + override getTranslatedAnchor( + connectable: GConnectableElement, + refPoint: Point, + refContainer: GParentElement, + edge: GRoutableElement, + anchorCorrection?: number | undefined + ): Point { + // users may define all kinds of anchors and anchor computers, we want to make sure we return a valid one in any case + const anchor = super.getTranslatedAnchor(connectable, refPoint, refContainer, edge, anchorCorrection); + return Point.isValid(anchor) ? anchor : refPoint; + } +}