@eclipse-glsp/client 1.1.0-RC01 → 1.1.0-RC03

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/lib/base/container-modules.js +37 -36
  2. package/lib/base/container-modules.js.map +1 -1
  3. package/lib/features/bounds/di.config.d.ts +20 -0
  4. package/lib/features/bounds/di.config.d.ts.map +1 -0
  5. package/lib/features/bounds/di.config.js +36 -0
  6. package/lib/features/bounds/di.config.js.map +1 -0
  7. package/lib/features/bounds/glsp-hidden-bounds-updater.d.ts +34 -0
  8. package/lib/features/bounds/glsp-hidden-bounds-updater.d.ts.map +1 -0
  9. package/lib/features/bounds/glsp-hidden-bounds-updater.js +98 -0
  10. package/lib/features/bounds/glsp-hidden-bounds-updater.js.map +1 -0
  11. package/lib/features/export/glsp-svg-exporter.d.ts +22 -0
  12. package/lib/features/export/glsp-svg-exporter.d.ts.map +1 -0
  13. package/lib/features/export/glsp-svg-exporter.js +45 -0
  14. package/lib/features/export/glsp-svg-exporter.js.map +1 -0
  15. package/lib/features/tools/change-bounds-tool.d.ts.map +1 -1
  16. package/lib/features/tools/change-bounds-tool.js +13 -10
  17. package/lib/features/tools/change-bounds-tool.js.map +1 -1
  18. package/lib/features/tools/di.config.d.ts.map +1 -1
  19. package/lib/features/tools/di.config.js +7 -1
  20. package/lib/features/tools/di.config.js.map +1 -1
  21. package/lib/features/tools/edge-edit-tool.d.ts +2 -2
  22. package/lib/features/tools/edge-edit-tool.d.ts.map +1 -1
  23. package/lib/features/tools/edge-edit-tool.js +3 -2
  24. package/lib/features/tools/edge-edit-tool.js.map +1 -1
  25. package/lib/features/tools/glsp-manhattan-edge-router.d.ts +20 -0
  26. package/lib/features/tools/glsp-manhattan-edge-router.d.ts.map +1 -0
  27. package/lib/features/tools/glsp-manhattan-edge-router.js +69 -0
  28. package/lib/features/tools/glsp-manhattan-edge-router.js.map +1 -0
  29. package/lib/utils/smodel-util.d.ts +32 -2
  30. package/lib/utils/smodel-util.d.ts.map +1 -1
  31. package/lib/utils/smodel-util.js +50 -2
  32. package/lib/utils/smodel-util.js.map +1 -1
  33. package/package.json +3 -3
  34. package/src/base/container-modules.ts +2 -2
  35. package/src/features/bounds/di.config.ts +39 -0
  36. package/src/features/bounds/glsp-hidden-bounds-updater.ts +88 -0
  37. package/src/features/export/glsp-svg-exporter.ts +50 -0
  38. package/src/features/tools/change-bounds-tool.ts +16 -13
  39. package/src/features/tools/di.config.ts +10 -2
  40. package/src/features/tools/edge-edit-tool.ts +5 -6
  41. package/src/features/tools/glsp-manhattan-edge-router.ts +57 -0
  42. package/src/utils/smodel-util.ts +60 -4
@@ -15,15 +15,17 @@
15
15
  ********************************************************************************/
16
16
  import { TriggerEdgeCreationAction, TriggerNodeCreationAction } from '@eclipse-glsp/protocol';
17
17
  import { ContainerModule, interfaces } from 'inversify';
18
- import { configureActionHandler, configureModelElement } from 'sprotty';
18
+ import { configureActionHandler, configureModelElement, ManhattanEdgeRouter } from 'sprotty';
19
19
  import { FocusStateChangedAction } from '../../base/actions/focus-change-action';
20
20
  import { TYPES } from '../../base/types';
21
+ import { GLSPSvgExporter } from '../export/glsp-svg-exporter';
21
22
  import { MARQUEE } from '../tool-feedback/marquee-tool-feedback';
22
23
  import { ChangeBoundsTool } from './change-bounds-tool';
23
24
  import { DelKeyDeleteTool, MouseDeleteTool } from './delete-tool';
24
25
  import { EdgeCreationTool } from './edge-creation-tool';
25
26
  import { EdgeEditTool } from './edge-edit-tool';
26
27
  import { EnableDefaultToolsOnFocusLossHandler } from './enable-default-tools-on-focus-loss';
28
+ import { GSLPManhattanEdgeRouter } from './glsp-manhattan-edge-router';
27
29
  import { MarqueeMouseTool } from './marquee-mouse-tool';
28
30
  import { MarqueeTool } from './marquee-tool';
29
31
  import { MarqueeNode } from './model';
@@ -34,7 +36,7 @@ import { MarqueeView } from './view';
34
36
  * Registers the default tools of GLSP (node and edge creation, changing bounds, edge editing, deletion)
35
37
  * and adds the marquee selection tool.
36
38
  */
37
- export const toolsModule = new ContainerModule((bind, _unbind, isBound) => {
39
+ export const toolsModule = new ContainerModule((bind, _unbind, isBound, rebind) => {
38
40
  // Register default tools
39
41
  bind(TYPES.IDefaultTool).to(ChangeBoundsTool);
40
42
  bind(TYPES.IDefaultTool).to(EdgeEditTool);
@@ -50,6 +52,12 @@ export const toolsModule = new ContainerModule((bind, _unbind, isBound) => {
50
52
  configureMarqueeTool({ bind, isBound });
51
53
  configureActionHandler({ bind, isBound }, TriggerNodeCreationAction.KIND, NodeCreationTool);
52
54
  configureActionHandler({ bind, isBound }, TriggerEdgeCreationAction.KIND, EdgeCreationTool);
55
+
56
+ bind(GLSPSvgExporter).toSelf().inSingletonScope();
57
+ rebind(TYPES.SvgExporter).toService(GLSPSvgExporter);
58
+
59
+ bind(GSLPManhattanEdgeRouter).toSelf().inSingletonScope();
60
+ rebind(ManhattanEdgeRouter).toService(GSLPManhattanEdgeRouter);
53
61
  });
54
62
 
55
63
  export function configureMarqueeTool(context: { bind: interfaces.Bind; isBound: interfaces.IsBound }): void {
@@ -31,7 +31,7 @@ import {
31
31
  } from 'sprotty';
32
32
  import { DragAwareMouseListener } from '../../base/drag-aware-mouse-listener';
33
33
  import { TYPES } from '../../base/types';
34
- import { isRoutable, isRoutingHandle } from '../../utils/smodel-util';
34
+ import { calcElementAndRoutingPoints, isRoutable, isRoutingHandle } from '../../utils/smodel-util';
35
35
  import { isReconnectable, isReconnectHandle, isSourceRoutingHandle, isTargetRoutingHandle, SReconnectHandle } from '../reconnect/model';
36
36
  import { SelectionListener, SelectionService } from '../select/selection-service';
37
37
  import { DrawFeedbackEdgeAction, feedbackEdgeId, RemoveFeedbackEdgeAction } from '../tool-feedback/creation-tool-feedback';
@@ -53,7 +53,7 @@ export class EdgeEditTool extends BaseGLSPTool {
53
53
 
54
54
  @inject(TYPES.SelectionService) protected selectionService: SelectionService;
55
55
  @inject(AnchorComputerRegistry) protected anchorRegistry: AnchorComputerRegistry;
56
- @inject(EdgeRouterRegistry) @optional() protected edgeRouterRegistry?: EdgeRouterRegistry;
56
+ @inject(EdgeRouterRegistry) @optional() readonly edgeRouterRegistry?: EdgeRouterRegistry;
57
57
  @inject(TYPES.ISnapper) @optional() readonly snapper?: ISnapper;
58
58
 
59
59
  protected feedbackEdgeSourceMovingListener: FeedbackEdgeSourceMovingMouseListener;
@@ -237,16 +237,15 @@ class EdgeEditListener extends DragAwareMouseListener implements SelectionListen
237
237
  // reroute actions
238
238
  const latestEdge = target.index.getById(this.edge.id);
239
239
  if (latestEdge && isRoutable(latestEdge)) {
240
- result.push(
241
- ChangeRoutingPointsOperation.create([{ elementId: latestEdge.id, newRoutingPoints: latestEdge.routingPoints }])
242
- );
240
+ const newRoutingPoints = calcElementAndRoutingPoints(latestEdge, this.tool.edgeRouterRegistry);
241
+ result.push(ChangeRoutingPointsOperation.create([newRoutingPoints]));
243
242
  this.routingHandle = undefined;
244
243
  }
245
244
  }
246
245
  return result;
247
246
  }
248
247
 
249
- override mouseOver(target: SModelElement, event: MouseEvent): Action[] {
248
+ override mouseOver(target: SModelElement, _event: MouseEvent): Action[] {
250
249
  if (this.edge && this.isReconnecting()) {
251
250
  const currentTarget = findParentByFeature(target, isConnectable);
252
251
  if (!this.newConnectable || currentTarget !== this.newConnectable) {
@@ -0,0 +1,57 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2022 EclipseSource and others.
3
+ *
4
+ * This program and the accompanying materials are made available under the
5
+ * terms of the Eclipse Public License v. 2.0 which is available at
6
+ * http://www.eclipse.org/legal/epl-2.0.
7
+ *
8
+ * This Source Code may also be made available under the following Secondary
9
+ * Licenses when the conditions for such availability set forth in the Eclipse
10
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ * with the GNU Classpath Exception which is available at
12
+ * https://www.gnu.org/software/classpath/license.html.
13
+ *
14
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ ********************************************************************************/
16
+
17
+ import { almostEquals } from '@eclipse-glsp/protocol';
18
+ import { ManhattanEdgeRouter, ResolvedHandleMove, SRoutableElement } from 'sprotty';
19
+
20
+ export class GSLPManhattanEdgeRouter extends ManhattanEdgeRouter {
21
+ protected override applyInnerHandleMoves(edge: SRoutableElement, moves: ResolvedHandleMove[]): void {
22
+ const route = this.route(edge);
23
+ const routingPoints = edge.routingPoints;
24
+ const minimalPointDistance = this.getOptions(edge).minimalPointDistance;
25
+ moves.forEach(move => {
26
+ const handle = move.handle;
27
+ const index = handle.pointIndex;
28
+ const correctedX = this.correctX(routingPoints, index, move.toPosition.x, minimalPointDistance);
29
+ const correctedY = this.correctY(routingPoints, index, move.toPosition.y, minimalPointDistance);
30
+ switch (handle.kind) {
31
+ case 'manhattan-50%':
32
+ if (index < 0) {
33
+ if (routingPoints.length === 0) {
34
+ routingPoints.push({ x: correctedX, y: correctedY });
35
+ move.handle.pointIndex = 0;
36
+ }
37
+ else if (almostEquals(route[0].x, route[1].x)) { this.alignX(routingPoints, 0, correctedX); }
38
+ else { this.alignY(routingPoints, 0, correctedY); }
39
+ } else if (index < routingPoints.length - 1) {
40
+ if (almostEquals(routingPoints[index].x, routingPoints[index + 1].x)) {
41
+ this.alignX(routingPoints, index, correctedX);
42
+ this.alignX(routingPoints, index + 1, correctedX);
43
+ } else {
44
+ this.alignY(routingPoints, index, correctedY);
45
+ this.alignY(routingPoints, index + 1, correctedY);
46
+ }
47
+ } else {
48
+ if (almostEquals(route[route.length - 2].x, route[route.length - 1].x)) {
49
+ this.alignX(routingPoints, routingPoints.length - 1, correctedX);
50
+ }
51
+ else { this.alignY(routingPoints, routingPoints.length - 1, correctedY); }
52
+ }
53
+ break;
54
+ }
55
+ });
56
+ }
57
+ }
@@ -13,14 +13,18 @@
13
13
  *
14
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  ********************************************************************************/
16
- import { distinctAdd, ElementAndBounds, ElementAndRoutingPoints, remove, SModelElementSchema, TypeGuard } from '@eclipse-glsp/protocol';
16
+ import {
17
+ distinctAdd, ElementAndBounds, ElementAndRoutingPoints, Point, remove, SModelElementSchema,
18
+ TypeGuard
19
+ } from '@eclipse-glsp/protocol';
17
20
  import {
18
21
  BoundsAware,
22
+ EdgeRouterRegistry,
19
23
  isBoundsAware,
20
24
  isMoveable,
21
25
  isSelectable,
22
- isSelected,
23
- ModelIndexImpl,
26
+ isSelected, ModelIndexImpl,
27
+ RoutedPoint,
24
28
  Selectable,
25
29
  SModelElement,
26
30
  SRoutableElement,
@@ -214,7 +218,7 @@ export function toElementAndBounds(element: BoundsAwareModelElement): ElementAnd
214
218
 
215
219
  /**
216
220
  * Helper function to translate a given {@link SRoutableElement} into its corresponding
217
- * {@ElementAndRoutingPoints ElementAndBounds} representation.
221
+ * {@link ElementAndRoutingPoints} representation.
218
222
  * @param element The element to translate.
219
223
  * @returns The corresponding {@link ElementAndRoutingPoints} for the given element.
220
224
  */
@@ -225,6 +229,57 @@ export function toElementAndRoutingPoints(element: SRoutableElement): ElementAnd
225
229
  };
226
230
  }
227
231
 
232
+ /** Pure routing point data kinds. */
233
+ export const ROUTING_POINT_KINDS = ['linear', 'bezier-junction'];
234
+
235
+ /** Pure route data kinds. */
236
+ export const ROUTE_KINDS = [...ROUTING_POINT_KINDS, 'source', 'target'];
237
+
238
+ /**
239
+ * Helper function to calculate the {@link ElementAndRoutingPoints} for a given {@link SRoutableElement}.
240
+ * If client layout is activated, i.e., the edge routing registry is given and has a router for the element, then the routing
241
+ * points from the calculated route are used, otherwise we use the already specified routing points of the {@link SRoutableElement}.
242
+ * @param element The element to translate.
243
+ * @param routerRegistry the edge router registry.
244
+ * @returns The corresponding {@link ElementAndRoutingPoints} for the given element.
245
+ */
246
+ export function calcElementAndRoutingPoints(element: SRoutableElement, routerRegistry?: EdgeRouterRegistry): ElementAndRoutingPoints {
247
+ const newRoutingPoints = routerRegistry ? calcRoute(element, routerRegistry, ROUTING_POINT_KINDS) : element.routingPoints;
248
+ return { elementId: element.id, newRoutingPoints };
249
+ }
250
+
251
+ /**
252
+ * Helper function to calculate the route for a given {@link SRoutableElement}.
253
+ * If client layout is activated, i.e., the edge routing registry is given and has a router for the element, then the points
254
+ * from the calculated route are used, otherwise we use the already specified routing points of the {@link SRoutableElement}.
255
+ * @param element The element to translate.
256
+ * @param routerRegistry the edge router registry.
257
+ * @returns The corresponding route for the given element.
258
+ */
259
+ export function calcElementAndRoute(element: SRoutableElement, routerRegistry?: EdgeRouterRegistry): ElementAndRoutingPoints {
260
+ let route: Point[] | undefined = routerRegistry ? calcRoute(element, routerRegistry, ROUTE_KINDS) : undefined;
261
+ if (!route) {
262
+ // add source and target to the routing points
263
+ route = [...element.routingPoints];
264
+ route.splice(0, 0, element.source?.position || Point.ORIGIN);
265
+ route.push(element.target?.position || Point.ORIGIN);
266
+ }
267
+ return { elementId: element.id, newRoutingPoints: route };
268
+ }
269
+
270
+ /**
271
+ * Helper function to calculate the route for a given {@link SRoutableElement}.
272
+ * @param element The element to translate.
273
+ * @param routerRegistry the edge router registry.
274
+ * @param pointKinds the routing point kinds that should be considered.
275
+ * @returns The corresponding route for the given element.
276
+ */
277
+ export function calcRoute(element: SRoutableElement, routerRegistry: EdgeRouterRegistry, pointKinds?: string[]): RoutedPoint[] | undefined {
278
+ return routerRegistry?.get(element.routerKind).route(element)
279
+ .filter((point, idx, fullRoute) => idx === fullRoute.findIndex(otherPoint => otherPoint.x === point.x && otherPoint.y === point.y))
280
+ .filter(point => !pointKinds || pointKinds.includes(point.kind));
281
+ }
282
+
228
283
  /**
229
284
  * Checks if the model is compatible with the passed type string.
230
285
  * (either has the same type or a subtype of this type)
@@ -247,3 +302,4 @@ export function getElementTypeId(input: SModelElement | SModelElementSchema | st
247
302
  return (input as any)['type'] as string;
248
303
  }
249
304
  }
305
+