@eclipse-glsp/graph 0.9.0-next.397cddd.4
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.
- package/LICENSE +642 -0
- package/README.md +8 -0
- package/lib/default-types.d.ts +3 -0
- package/lib/default-types.d.ts.map +1 -0
- package/lib/default-types.js +50 -0
- package/lib/default-types.js.map +1 -0
- package/lib/galignable.d.ts +28 -0
- package/lib/galignable.d.ts.map +1 -0
- package/lib/galignable.js +23 -0
- package/lib/galignable.js.map +1 -0
- package/lib/gbound-aware.d.ts +30 -0
- package/lib/gbound-aware.d.ts.map +1 -0
- package/lib/gbound-aware.js +34 -0
- package/lib/gbound-aware.js.map +1 -0
- package/lib/gbutton.d.ts +11 -0
- package/lib/gbutton.d.ts.map +1 -0
- package/lib/gbutton.js +39 -0
- package/lib/gbutton.js.map +1 -0
- package/lib/gcompartment.d.ts +34 -0
- package/lib/gcompartment.d.ts.map +1 -0
- package/lib/gcompartment.js +49 -0
- package/lib/gcompartment.js.map +1 -0
- package/lib/gedge-layoutable.d.ts +34 -0
- package/lib/gedge-layoutable.d.ts.map +1 -0
- package/lib/gedge-layoutable.js +20 -0
- package/lib/gedge-layoutable.js.map +1 -0
- package/lib/gedge.d.ts +46 -0
- package/lib/gedge.d.ts.map +1 -0
- package/lib/gedge.js +88 -0
- package/lib/gedge.js.map +1 -0
- package/lib/ggraph.d.ts +38 -0
- package/lib/ggraph.d.ts.map +1 -0
- package/lib/ggraph.js +51 -0
- package/lib/ggraph.js.map +1 -0
- package/lib/gissue-marker.d.ts +17 -0
- package/lib/gissue-marker.d.ts.map +1 -0
- package/lib/gissue-marker.js +48 -0
- package/lib/gissue-marker.js.map +1 -0
- package/lib/glabel.d.ts +36 -0
- package/lib/glabel.d.ts.map +1 -0
- package/lib/glabel.js +51 -0
- package/lib/glabel.js.map +1 -0
- package/lib/glayout-container.d.ts +27 -0
- package/lib/glayout-container.d.ts.map +1 -0
- package/lib/glayout-container.js +17 -0
- package/lib/glayout-container.js.map +1 -0
- package/lib/glayoutable.d.ts +29 -0
- package/lib/glayoutable.d.ts.map +1 -0
- package/lib/glayoutable.js +39 -0
- package/lib/glayoutable.js.map +1 -0
- package/lib/gmodel-element.d.ts +97 -0
- package/lib/gmodel-element.d.ts.map +1 -0
- package/lib/gmodel-element.js +161 -0
- package/lib/gmodel-element.js.map +1 -0
- package/lib/gnode.d.ts +12 -0
- package/lib/gnode.d.ts.map +1 -0
- package/lib/gnode.js +41 -0
- package/lib/gnode.js.map +1 -0
- package/lib/gport.d.ts +21 -0
- package/lib/gport.d.ts.map +1 -0
- package/lib/gport.js +31 -0
- package/lib/gport.js.map +1 -0
- package/lib/gpre-rendered-element.d.ts +31 -0
- package/lib/gpre-rendered-element.d.ts.map +1 -0
- package/lib/gpre-rendered-element.js +41 -0
- package/lib/gpre-rendered-element.js.map +1 -0
- package/lib/gshape-element.d.ts +36 -0
- package/lib/gshape-element.d.ts.map +1 -0
- package/lib/gshape-element.js +32 -0
- package/lib/gshape-element.js.map +1 -0
- package/lib/index.d.ts +33 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +45 -0
- package/lib/index.js.map +1 -0
- package/package.json +63 -0
- package/src/default-types.ts +48 -0
- package/src/galignable.ts +42 -0
- package/src/gbound-aware.ts +53 -0
- package/src/gbutton.ts +34 -0
- package/src/gcompartment.ts +47 -0
- package/src/gedge-layoutable.ts +45 -0
- package/src/gedge.ts +100 -0
- package/src/ggraph.ts +49 -0
- package/src/gissue-marker.ts +49 -0
- package/src/glabel.ts +50 -0
- package/src/glayout-container.ts +36 -0
- package/src/glayoutable.ts +57 -0
- package/src/gmodel-element.spec.ts +18 -0
- package/src/gmodel-element.ts +216 -0
- package/src/gnode.ts +34 -0
- package/src/gport.ts +26 -0
- package/src/gpre-rendered-element.ts +40 -0
- package/src/gshape-element.ts +51 -0
- package/src/index.ts +32 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2022 STMicroelectronics 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
|
+
import { Args, DefaultTypes, JsonPrimitive } from '@eclipse-glsp/protocol';
|
|
17
|
+
import { GLayoutContainer, GLayoutContainerBuilder } from './glayout-container';
|
|
18
|
+
import { GLayoutable, GLayoutableBuilder } from './glayoutable';
|
|
19
|
+
import { GShapeElement, GShapeElementBuilder } from './gshape-element';
|
|
20
|
+
|
|
21
|
+
export class GCompartment extends GShapeElement implements GLayoutContainer, GLayoutable {
|
|
22
|
+
static builder(): GCompartmentBuilder {
|
|
23
|
+
return new GCompartmentBuilder(GCompartment).type(DefaultTypes.COMPARTMENT);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
type = DefaultTypes.COMPARTMENT;
|
|
27
|
+
layout?: string;
|
|
28
|
+
layoutOptions?: Args;
|
|
29
|
+
[GLayoutContainer] = true;
|
|
30
|
+
[GLayoutable] = true;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export class GCompartmentBuilder<G extends GCompartment = GCompartment> extends GShapeElementBuilder<G> {
|
|
34
|
+
layout(layout?: string): this {
|
|
35
|
+
return GLayoutContainerBuilder.layout(this, layout);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
addLayoutOption(key: string, value: JsonPrimitive): this {
|
|
39
|
+
return GLayoutableBuilder.addLayoutOption(this, key, value);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
addLayoutOptions(layoutOptions: Args): this;
|
|
43
|
+
addLayoutOptions(layoutOptions: Map<string, JsonPrimitive>): this;
|
|
44
|
+
addLayoutOptions(layoutOptions: Args | Map<string, JsonPrimitive>): this {
|
|
45
|
+
return GLayoutableBuilder.addLayoutOptions(this, layoutOptions);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2022 STMicroelectronics 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
|
+
import { GModelElement, GModelElementBuilder } from './gmodel-element';
|
|
17
|
+
|
|
18
|
+
export type EdgeSide = 'left' | 'right' | 'top' | 'bottom' | 'on';
|
|
19
|
+
|
|
20
|
+
export class EdgePlacement extends Object {
|
|
21
|
+
rotate: boolean;
|
|
22
|
+
side: EdgeSide;
|
|
23
|
+
position: number;
|
|
24
|
+
offset: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const GEdgeLayoutable = Symbol('GEdgeLayoutable');
|
|
28
|
+
|
|
29
|
+
export interface GEdgeLayoutable {
|
|
30
|
+
edgePlacement?: EdgePlacement;
|
|
31
|
+
[GEdgeLayoutable]: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function isGEdgeLayoutable<G extends GModelElement>(element: G): element is G & GEdgeLayoutable {
|
|
35
|
+
return ((element as any)[GEdgeLayoutable] = true);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type GEdgeLayoutableBuilder<G extends GModelElement = GModelElement> = GModelElementBuilder<G & GEdgeLayoutable>;
|
|
39
|
+
|
|
40
|
+
export namespace GEdgeLayoutableBuilder {
|
|
41
|
+
export function edgePlacement<B extends GEdgeLayoutableBuilder>(builder: B, placement?: EdgePlacement): B {
|
|
42
|
+
builder['proxy'].edgePlacement = placement;
|
|
43
|
+
return builder;
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/gedge.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2022 STMicroelectronics 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
|
+
import { DefaultTypes, flatPush, MaybeArray, Point } from '@eclipse-glsp/protocol';
|
|
17
|
+
import { GModelElement, GModelElementBuilder } from './gmodel-element';
|
|
18
|
+
|
|
19
|
+
export class GEdge extends GModelElement {
|
|
20
|
+
static builder(): GEdgeBuilder {
|
|
21
|
+
return new GEdgeBuilder(GEdge).type(DefaultTypes.EDGE);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type = DefaultTypes.EDGE;
|
|
25
|
+
routingPoints: Point[] = [];
|
|
26
|
+
sourceId: string;
|
|
27
|
+
targetId: string;
|
|
28
|
+
routerKind?: string;
|
|
29
|
+
private _source: GModelElement;
|
|
30
|
+
private _target: GModelElement;
|
|
31
|
+
|
|
32
|
+
get source(): GModelElement {
|
|
33
|
+
return this._source;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
set source(value: GModelElement) {
|
|
37
|
+
this._source = value;
|
|
38
|
+
this.sourceId = value.id;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get target(): GModelElement {
|
|
42
|
+
return this._target;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
set target(value: GModelElement) {
|
|
46
|
+
this._target = value;
|
|
47
|
+
this.targetId = value.id;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export namespace GEdge {
|
|
52
|
+
export function is(object: unknown): object is GEdge {
|
|
53
|
+
return GEdge.is(object);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export class GEdgeBuilder<G extends GEdge = GEdge> extends GModelElementBuilder<G> {
|
|
58
|
+
source(source: GModelElement): this {
|
|
59
|
+
this.proxy.source = source;
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
sourceId(sourceId: string): this {
|
|
64
|
+
this.proxy.sourceId = sourceId;
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
target(target: GModelElement): this {
|
|
69
|
+
this.proxy.target = target;
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
targetId(targetId: string): this {
|
|
74
|
+
this.proxy.targetId = targetId;
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
routerKind(routerKind: string): this {
|
|
79
|
+
this.proxy.routerKind = routerKind;
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
addRoutingPoint(x: number, y: number): this;
|
|
84
|
+
addRoutingPoint(point: Point): this;
|
|
85
|
+
addRoutingPoint(xOrPoint: Point | number, y?: number): this {
|
|
86
|
+
if (typeof xOrPoint === 'object') {
|
|
87
|
+
this.proxy.routingPoints.push(xOrPoint);
|
|
88
|
+
} else if (y) {
|
|
89
|
+
this.proxy.routingPoints.push({ x: xOrPoint, y });
|
|
90
|
+
}
|
|
91
|
+
return this;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
addRoutingPoints(routingPoints: Point[]): this;
|
|
95
|
+
addRoutingPoints(...routingPoints: Point[]): this;
|
|
96
|
+
addRoutingPoints(...routingPoints: MaybeArray<Point>[]): this {
|
|
97
|
+
flatPush(this.proxy.routingPoints, routingPoints);
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
}
|
package/src/ggraph.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2022 StMicroelectronics.
|
|
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
|
+
* TS implementation of the GLSP graph definition
|
|
18
|
+
* (https://github.com/eclipse-glsp/glsp-server/tree/master/plugins/org.eclipse.glsp.graph/src-gen/org/eclipse/glsp/graph)
|
|
19
|
+
* Parts of the implementation is derived from Sprotty's SModel API
|
|
20
|
+
* (https://github.com/eclipse/sprotty/blob/master/packages/sprotty/src/base/model/smodel.ts)
|
|
21
|
+
*/
|
|
22
|
+
import { DefaultTypes as types, Dimension, ORIGIN_POINT, Point } from '@eclipse-glsp/protocol';
|
|
23
|
+
import { GBoundsAware, GBoundsAwareBuilder } from './gbound-aware';
|
|
24
|
+
import { GModelRoot, GModelRootBuilder } from './gmodel-element';
|
|
25
|
+
|
|
26
|
+
export class GGraph extends GModelRoot implements GBoundsAware {
|
|
27
|
+
static builder(): GGraphBuilder {
|
|
28
|
+
return new GGraphBuilder(GGraph);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type = types.GRAPH;
|
|
32
|
+
position: Point = ORIGIN_POINT;
|
|
33
|
+
size?: Dimension;
|
|
34
|
+
[GBoundsAware] = true;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class GGraphBuilder<G extends GGraph = GGraph> extends GModelRootBuilder<G> {
|
|
38
|
+
position(x: number, y: number): this;
|
|
39
|
+
position(position: Point): this;
|
|
40
|
+
position(positionOrX: Point | number, y?: number): this {
|
|
41
|
+
return GBoundsAwareBuilder.position(this, positionOrX, y);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
size(width: number, height: number): this;
|
|
45
|
+
size(size: Dimension): this;
|
|
46
|
+
size(sizeOrWidth: Dimension | number, height?: number): this {
|
|
47
|
+
return GBoundsAwareBuilder.size(this, sizeOrWidth, height);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2022 STMicroelectronics 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
|
+
import { DefaultTypes, flatPush, MaybeArray } from '@eclipse-glsp/protocol';
|
|
17
|
+
import { GShapeElement, GShapeElementBuilder } from './gshape-element';
|
|
18
|
+
|
|
19
|
+
export type GIssueSeverity = 'error' | 'warning' | 'info';
|
|
20
|
+
|
|
21
|
+
export class GIssue {
|
|
22
|
+
message: string;
|
|
23
|
+
severity: GIssueSeverity;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class GIssueMarker extends GShapeElement {
|
|
27
|
+
type = DefaultTypes.ISSUE_MARKER;
|
|
28
|
+
issues: GIssue[] = [];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class GIssueMarkerBuilder<G extends GIssueMarker = GIssueMarker> extends GShapeElementBuilder<G> {
|
|
32
|
+
addIssue(issue: GIssue): this;
|
|
33
|
+
addIssue(message: string, severity: GIssueSeverity): this;
|
|
34
|
+
addIssue(issueOrMessage: GIssue | string, severity?: GIssueSeverity): this {
|
|
35
|
+
if (typeof issueOrMessage === 'object') {
|
|
36
|
+
this.proxy.issues.push(issueOrMessage);
|
|
37
|
+
} else if (severity) {
|
|
38
|
+
this.proxy.issues.push({ message: issueOrMessage, severity });
|
|
39
|
+
}
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
addIssues(issues: GIssue[]): this;
|
|
44
|
+
addIssues(...issues: GIssue[]): this;
|
|
45
|
+
addIssues(...issues: MaybeArray<GIssue>[]): this {
|
|
46
|
+
flatPush(this.proxy.issues, issues);
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/glabel.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2022 STMicroelectronics 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
|
+
import { DefaultTypes, ORIGIN_POINT, Point } from '@eclipse-glsp/protocol';
|
|
17
|
+
import { GAlignable, GAlignableBuilder } from './galignable';
|
|
18
|
+
import { EdgePlacement, GEdgeLayoutable, GEdgeLayoutableBuilder } from './gedge-layoutable';
|
|
19
|
+
import { GModelElementConstructor } from './gmodel-element';
|
|
20
|
+
import { GShapeElement, GShapeElementBuilder } from './gshape-element';
|
|
21
|
+
|
|
22
|
+
export class GLabel extends GShapeElement implements GAlignable, GEdgeLayoutable {
|
|
23
|
+
static builder<G extends GLabel = GLabel>(constructor?: GModelElementConstructor<G>): GLabelBuilder {
|
|
24
|
+
return new GLabelBuilder(constructor ?? GLabel).type(DefaultTypes.LABEL);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type = DefaultTypes.LABEL;
|
|
28
|
+
text: string;
|
|
29
|
+
alignment: Point = ORIGIN_POINT;
|
|
30
|
+
edgePlacement?: EdgePlacement;
|
|
31
|
+
[GAlignable] = true;
|
|
32
|
+
[GEdgeLayoutable] = true;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class GLabelBuilder<G extends GLabel = GLabel> extends GShapeElementBuilder<G> {
|
|
36
|
+
alignment(x: number, y: number): this;
|
|
37
|
+
alignment(alignment: Point): this;
|
|
38
|
+
alignment(xOrAlign: number | Point, y?: number): this {
|
|
39
|
+
return GAlignableBuilder.alignment(this, xOrAlign, y);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
text(text: string): this {
|
|
43
|
+
this.proxy.text = text;
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
edgePlacement(placement: EdgePlacement): this {
|
|
48
|
+
return GEdgeLayoutableBuilder.edgePlacement(this, placement);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2022 STMicroelectronics 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
|
+
import { GModelElement, GModelElementBuilder } from './gmodel-element';
|
|
17
|
+
|
|
18
|
+
export const GLayoutContainer = Symbol('GLayoutContainer');
|
|
19
|
+
|
|
20
|
+
export interface GLayoutContainer {
|
|
21
|
+
layout?: string;
|
|
22
|
+
[GLayoutContainer]: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function isGLayoutContainer<G extends GModelElement>(element: G): element is G & GLayoutContainer {
|
|
26
|
+
return ((element as any)[GLayoutContainer] = true);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type GLayoutContainerBuilder = GModelElementBuilder<GModelElement & GLayoutContainer>;
|
|
30
|
+
|
|
31
|
+
export namespace GLayoutContainerBuilder {
|
|
32
|
+
export function layout<B extends GLayoutContainerBuilder>(builder: B, newLayout?: string): B {
|
|
33
|
+
builder['proxy'].layout = newLayout;
|
|
34
|
+
return builder;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2022 STMicroelectronics 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
|
+
import { Args, JsonPrimitive } from '@eclipse-glsp/protocol';
|
|
17
|
+
import { GModelElement, GModelElementBuilder } from './gmodel-element';
|
|
18
|
+
|
|
19
|
+
export const GLayoutable = Symbol('GLayoutable');
|
|
20
|
+
|
|
21
|
+
export interface GLayoutable {
|
|
22
|
+
layoutOptions?: Args;
|
|
23
|
+
[GLayoutable]: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function isGLayoutable<G extends GModelElement>(element: G): element is G & GLayoutable {
|
|
27
|
+
return ((element as any)[GLayoutable] = true);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type GLayoutableBuilder = GModelElementBuilder<GModelElement & GLayoutable>;
|
|
31
|
+
|
|
32
|
+
export namespace GLayoutableBuilder {
|
|
33
|
+
export function addLayoutOption<B extends GLayoutableBuilder>(builder: B, key: string, value: JsonPrimitive): B {
|
|
34
|
+
const proxy = builder['proxy'];
|
|
35
|
+
if (!proxy.layoutOptions) {
|
|
36
|
+
proxy.layoutOptions = {};
|
|
37
|
+
}
|
|
38
|
+
proxy.layoutOptions[key] = value;
|
|
39
|
+
return builder;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function addLayoutOptions<B extends GLayoutableBuilder>(builder: B, layoutOptions: Args | Map<string, JsonPrimitive>): B {
|
|
43
|
+
const toAssign: Args = {};
|
|
44
|
+
const proxy = builder['proxy'];
|
|
45
|
+
if (layoutOptions instanceof Map) {
|
|
46
|
+
[...layoutOptions.keys()].forEach(key => (toAssign[key] = layoutOptions.get(key)!));
|
|
47
|
+
} else {
|
|
48
|
+
Object.keys(layoutOptions).forEach(key => (toAssign[key] = layoutOptions[key]));
|
|
49
|
+
}
|
|
50
|
+
if (proxy.layoutOptions) {
|
|
51
|
+
Object.assign(proxy.layoutOptions, toAssign);
|
|
52
|
+
} else {
|
|
53
|
+
proxy.layoutOptions = toAssign;
|
|
54
|
+
}
|
|
55
|
+
return builder;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2022 STMicroelectronics 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
|
+
describe('foo', () => {
|
|
17
|
+
// Test stub
|
|
18
|
+
});
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2022 STMicroelectronics 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
|
+
import {
|
|
17
|
+
Args,
|
|
18
|
+
Bounds,
|
|
19
|
+
Dimension,
|
|
20
|
+
flatPush,
|
|
21
|
+
isSModelElementSchema,
|
|
22
|
+
isSModelRootSchema,
|
|
23
|
+
JsonPrimitive,
|
|
24
|
+
MaybeArray,
|
|
25
|
+
Point,
|
|
26
|
+
SModelElementSchema,
|
|
27
|
+
SModelRootSchema
|
|
28
|
+
} from '@eclipse-glsp/protocol';
|
|
29
|
+
import * as uuid from 'uuid';
|
|
30
|
+
export type GModelElementConstructor<G extends GModelElement = GModelElement> = new () => G;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Represents a `GModeElement` serialized as plain JSON object.
|
|
34
|
+
*/
|
|
35
|
+
export type GModelElementSchema = SModelElementSchema;
|
|
36
|
+
|
|
37
|
+
export function isGModelElementSchema(schema: any): schema is GModelElementSchema {
|
|
38
|
+
return isSModelElementSchema(schema);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Base type for all elements of the graphical model.
|
|
43
|
+
* Each model element must have a unique ID and a type that is used to look up its view.
|
|
44
|
+
*/
|
|
45
|
+
export abstract class GModelElement implements GModelElementSchema {
|
|
46
|
+
/**
|
|
47
|
+
* The `type` of a `GModelElement` has two main purposes. It is used by the GLSP client
|
|
48
|
+
* during the rendering phase to lookup the View that is responsible for rendering this element.
|
|
49
|
+
* In addition, it serves as the discriminator for serialization & deserialization of `GModeElements` and their corresponding
|
|
50
|
+
* `GModelElementSchema`. e.g. If the glsp server receives a `GModelElementSchema` (plain JSON object) the type is used to
|
|
51
|
+
* lookup and construct the corresponding `GModelElement` class.
|
|
52
|
+
*/
|
|
53
|
+
type: string;
|
|
54
|
+
/**
|
|
55
|
+
* Each model element must have a unique ID. Duplicate ids in the graphical element will result in an error during the
|
|
56
|
+
* rendering phase.
|
|
57
|
+
*/
|
|
58
|
+
id: string;
|
|
59
|
+
/**
|
|
60
|
+
* A set of css classes that should be applied to the DOM element that corresponds to this element.
|
|
61
|
+
*/
|
|
62
|
+
cssClasses: string[] = [];
|
|
63
|
+
/** A `GModelElement can have an arbitrary amount of children. This parent-child relation ship is also reflected in
|
|
64
|
+
* the corresponding DOM element i.e. DOM elements that reflect children of this element are also children
|
|
65
|
+
* of the DOM element that reflects this element.
|
|
66
|
+
*/
|
|
67
|
+
children: GModelElement[] = [];
|
|
68
|
+
/**
|
|
69
|
+
* Each `GModelElement` (apart from the root element) must have an assigned parent. Orphan elements are not allowed.
|
|
70
|
+
*/
|
|
71
|
+
parent: GModelElement;
|
|
72
|
+
/**
|
|
73
|
+
* Additional custom arguments. Can be used to transmit additional information between client & server without
|
|
74
|
+
* having to extend the model.
|
|
75
|
+
*/
|
|
76
|
+
args?: Args;
|
|
77
|
+
|
|
78
|
+
get root(): GModelRoot {
|
|
79
|
+
let current: GModelElement = this;
|
|
80
|
+
while (!(current instanceof GModelRoot)) {
|
|
81
|
+
current = current.parent;
|
|
82
|
+
}
|
|
83
|
+
return current;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* A fluent builder API that simplifies the construction of complex {@link GModelElement}s.
|
|
89
|
+
* The builder API is derived from the Java GLSP server implementation where it is used to hide the complexity
|
|
90
|
+
* of creating EMF objects. However, the API is also useful in a Typescript/Node context to declare the creation of a new
|
|
91
|
+
* {@link GModelElement} in a more concise way.
|
|
92
|
+
*/
|
|
93
|
+
export abstract class GModelElementBuilder<G extends GModelElement> {
|
|
94
|
+
protected proxy: G;
|
|
95
|
+
protected elementConstructor: GModelElementConstructor<G>;
|
|
96
|
+
|
|
97
|
+
constructor(elementConstructor: GModelElementConstructor<G>) {
|
|
98
|
+
this.elementConstructor = elementConstructor;
|
|
99
|
+
this.proxy = new elementConstructor();
|
|
100
|
+
this.proxy.cssClasses = [];
|
|
101
|
+
this.proxy.children = [];
|
|
102
|
+
this.proxy.id = uuid.v4();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
reset(): this {
|
|
106
|
+
this.proxy = new this.elementConstructor();
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
build(): G {
|
|
111
|
+
const element = new this.elementConstructor();
|
|
112
|
+
Object.assign(element, this.proxy);
|
|
113
|
+
element.children.forEach(child => (child.parent = element));
|
|
114
|
+
if (element.id === undefined) {
|
|
115
|
+
throw new Error('The `id` property of a GModelElement must not be undefined!');
|
|
116
|
+
}
|
|
117
|
+
if (element.type === undefined) {
|
|
118
|
+
throw new Error('The `type` property of a GModelElement must not be undefined!');
|
|
119
|
+
}
|
|
120
|
+
return element;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
id(id: string): this {
|
|
124
|
+
this.proxy.id = id;
|
|
125
|
+
return this;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
type(type: string): this {
|
|
129
|
+
this.proxy.type = type;
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
addCssClass(cssClass: string): this {
|
|
134
|
+
this.proxy.cssClasses.push(cssClass);
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
addCssClasses(cssClasses: string[]): this;
|
|
139
|
+
addCssClasses(...cssClasses: string[]): this;
|
|
140
|
+
addCssClasses(...cssClasses: MaybeArray<string>[]): this {
|
|
141
|
+
flatPush(this.proxy.cssClasses, cssClasses);
|
|
142
|
+
return this;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
add(child: GModelElement): this {
|
|
146
|
+
this.proxy.children.push(child);
|
|
147
|
+
return this;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
addChildren(children: GModelElement[]): this;
|
|
151
|
+
addChildren(...children: GModelElement[]): this;
|
|
152
|
+
addChildren(...children: MaybeArray<GModelElement>[]): this {
|
|
153
|
+
flatPush(this.proxy.children, children);
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
addArg(key: string, value: JsonPrimitive): this {
|
|
158
|
+
if (!this.proxy.args) {
|
|
159
|
+
this.proxy.args = {};
|
|
160
|
+
}
|
|
161
|
+
this.proxy.args[key] = value;
|
|
162
|
+
return this;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
addArgs(args: Args): this;
|
|
166
|
+
addArgs(args: Map<string, JsonPrimitive>): this;
|
|
167
|
+
addArgs(args: Args | Map<string, JsonPrimitive>): this {
|
|
168
|
+
const toAssign: Args = {};
|
|
169
|
+
if (args instanceof Map) {
|
|
170
|
+
[...args.keys()].forEach(key => (toAssign[key] = args.get(key)!));
|
|
171
|
+
} else {
|
|
172
|
+
Object.keys(args).forEach(key => (toAssign[key] = args[key]));
|
|
173
|
+
}
|
|
174
|
+
if (this.proxy.args) {
|
|
175
|
+
Object.assign(this.proxy.args, toAssign);
|
|
176
|
+
} else {
|
|
177
|
+
this.proxy.args = toAssign;
|
|
178
|
+
}
|
|
179
|
+
return this;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export type GModelRootSchema = SModelRootSchema;
|
|
184
|
+
|
|
185
|
+
export function isGModelRootSchema(schema: any): schema is GModelRootSchema {
|
|
186
|
+
return isSModelRootSchema(schema);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export class GModelRoot extends GModelElement implements SModelRootSchema {
|
|
190
|
+
static builder(): GModelRootBuilder {
|
|
191
|
+
return new GModelRootBuilder(GModelRoot);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
canvasBounds?: Bounds;
|
|
195
|
+
revision = 0;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export class GModelRootBuilder<G extends GModelRoot = GModelRoot> extends GModelElementBuilder<G> {
|
|
199
|
+
revision(revision: number): this {
|
|
200
|
+
this.proxy.revision = revision;
|
|
201
|
+
return this;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
canvasBounds(position: Point, size: Dimension): this;
|
|
205
|
+
canvasBounds(bounds: Bounds): this;
|
|
206
|
+
canvasBounds(positionOrBounds: Point | Bounds, size?: Dimension): this {
|
|
207
|
+
let bounds: Bounds;
|
|
208
|
+
if (size) {
|
|
209
|
+
bounds = { ...positionOrBounds, ...size };
|
|
210
|
+
} else {
|
|
211
|
+
bounds = positionOrBounds as Bounds;
|
|
212
|
+
}
|
|
213
|
+
this.proxy.canvasBounds = bounds;
|
|
214
|
+
return this;
|
|
215
|
+
}
|
|
216
|
+
}
|