@eclipse-glsp/graph 0.9.0-next.0193b16.17

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 (99) hide show
  1. package/LICENSE +642 -0
  2. package/README.md +8 -0
  3. package/lib/default-types.d.ts +3 -0
  4. package/lib/default-types.d.ts.map +1 -0
  5. package/lib/default-types.js +50 -0
  6. package/lib/default-types.js.map +1 -0
  7. package/lib/galignable.d.ts +28 -0
  8. package/lib/galignable.d.ts.map +1 -0
  9. package/lib/galignable.js +23 -0
  10. package/lib/galignable.js.map +1 -0
  11. package/lib/gbound-aware.d.ts +30 -0
  12. package/lib/gbound-aware.d.ts.map +1 -0
  13. package/lib/gbound-aware.js +34 -0
  14. package/lib/gbound-aware.js.map +1 -0
  15. package/lib/gbutton.d.ts +11 -0
  16. package/lib/gbutton.d.ts.map +1 -0
  17. package/lib/gbutton.js +39 -0
  18. package/lib/gbutton.js.map +1 -0
  19. package/lib/gcompartment.d.ts +34 -0
  20. package/lib/gcompartment.d.ts.map +1 -0
  21. package/lib/gcompartment.js +49 -0
  22. package/lib/gcompartment.js.map +1 -0
  23. package/lib/gedge-layoutable.d.ts +34 -0
  24. package/lib/gedge-layoutable.d.ts.map +1 -0
  25. package/lib/gedge-layoutable.js +20 -0
  26. package/lib/gedge-layoutable.js.map +1 -0
  27. package/lib/gedge.d.ts +40 -0
  28. package/lib/gedge.d.ts.map +1 -0
  29. package/lib/gedge.js +74 -0
  30. package/lib/gedge.js.map +1 -0
  31. package/lib/ggraph.d.ts +38 -0
  32. package/lib/ggraph.d.ts.map +1 -0
  33. package/lib/ggraph.js +51 -0
  34. package/lib/ggraph.js.map +1 -0
  35. package/lib/gissue-marker.d.ts +17 -0
  36. package/lib/gissue-marker.d.ts.map +1 -0
  37. package/lib/gissue-marker.js +48 -0
  38. package/lib/gissue-marker.js.map +1 -0
  39. package/lib/glabel.d.ts +36 -0
  40. package/lib/glabel.d.ts.map +1 -0
  41. package/lib/glabel.js +51 -0
  42. package/lib/glabel.js.map +1 -0
  43. package/lib/glayout-container.d.ts +27 -0
  44. package/lib/glayout-container.d.ts.map +1 -0
  45. package/lib/glayout-container.js +17 -0
  46. package/lib/glayout-container.js.map +1 -0
  47. package/lib/glayoutable.d.ts +29 -0
  48. package/lib/glayoutable.d.ts.map +1 -0
  49. package/lib/glayoutable.js +39 -0
  50. package/lib/glayoutable.js.map +1 -0
  51. package/lib/gmodel-element.d.ts +106 -0
  52. package/lib/gmodel-element.d.ts.map +1 -0
  53. package/lib/gmodel-element.js +165 -0
  54. package/lib/gmodel-element.js.map +1 -0
  55. package/lib/gmodel-util.d.ts +36 -0
  56. package/lib/gmodel-util.d.ts.map +1 -0
  57. package/lib/gmodel-util.js +55 -0
  58. package/lib/gmodel-util.js.map +1 -0
  59. package/lib/gnode.d.ts +12 -0
  60. package/lib/gnode.d.ts.map +1 -0
  61. package/lib/gnode.js +41 -0
  62. package/lib/gnode.js.map +1 -0
  63. package/lib/gport.d.ts +21 -0
  64. package/lib/gport.d.ts.map +1 -0
  65. package/lib/gport.js +31 -0
  66. package/lib/gport.js.map +1 -0
  67. package/lib/gpre-rendered-element.d.ts +31 -0
  68. package/lib/gpre-rendered-element.d.ts.map +1 -0
  69. package/lib/gpre-rendered-element.js +41 -0
  70. package/lib/gpre-rendered-element.js.map +1 -0
  71. package/lib/gshape-element.d.ts +36 -0
  72. package/lib/gshape-element.d.ts.map +1 -0
  73. package/lib/gshape-element.js +32 -0
  74. package/lib/gshape-element.js.map +1 -0
  75. package/lib/index.d.ts +34 -0
  76. package/lib/index.d.ts.map +1 -0
  77. package/lib/index.js +46 -0
  78. package/lib/index.js.map +1 -0
  79. package/package.json +61 -0
  80. package/src/default-types.ts +48 -0
  81. package/src/galignable.ts +42 -0
  82. package/src/gbound-aware.ts +53 -0
  83. package/src/gbutton.ts +34 -0
  84. package/src/gcompartment.ts +47 -0
  85. package/src/gedge-layoutable.ts +45 -0
  86. package/src/gedge.ts +80 -0
  87. package/src/ggraph.ts +49 -0
  88. package/src/gissue-marker.ts +49 -0
  89. package/src/glabel.ts +50 -0
  90. package/src/glayout-container.ts +36 -0
  91. package/src/glayoutable.ts +57 -0
  92. package/src/gmodel-element.spec.ts +18 -0
  93. package/src/gmodel-element.ts +218 -0
  94. package/src/gmodel-util.ts +58 -0
  95. package/src/gnode.ts +34 -0
  96. package/src/gport.ts +26 -0
  97. package/src/gpre-rendered-element.ts +40 -0
  98. package/src/gshape-element.ts +51 -0
  99. package/src/index.ts +33 -0
package/src/gbutton.ts ADDED
@@ -0,0 +1,34 @@
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 } from '@eclipse-glsp/protocol';
17
+ import { GModelElementConstructor } from './gmodel-element';
18
+ import { GShapeElement, GShapeElementBuilder } from './gshape-element';
19
+
20
+ export class GButton extends GShapeElement {
21
+ static builder<G extends GButton = GButton>(constructor?: GModelElementConstructor<G>): GButtonBuilder {
22
+ return new GButtonBuilder(constructor ?? GButton).type(DefaultTypes.BUTTON_EXPAND);
23
+ }
24
+
25
+ override type = DefaultTypes.BUTTON_EXPAND;
26
+ enabled = true;
27
+ }
28
+
29
+ export class GButtonBuilder<G extends GButton = GButton> extends GShapeElementBuilder<G> {
30
+ enabled(enabled: boolean): this {
31
+ this.proxy.enabled = enabled;
32
+ return this;
33
+ }
34
+ }
@@ -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
+ override type = DefaultTypes.COMPARTMENT;
27
+ layout?: string;
28
+ override 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
+ override addLayoutOption(key: string, value: JsonPrimitive): this {
39
+ return GLayoutableBuilder.addLayoutOption(this, key, value);
40
+ }
41
+
42
+ override addLayoutOptions(layoutOptions: Args): this;
43
+ override addLayoutOptions(layoutOptions: Map<string, JsonPrimitive>): this;
44
+ override 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,80 @@
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
+ override type = DefaultTypes.EDGE;
25
+ routingPoints: Point[] = [];
26
+ sourceId: string;
27
+ targetId: string;
28
+ routerKind?: string;
29
+ }
30
+
31
+ export namespace GEdge {
32
+ export function is(object: unknown): object is GEdge {
33
+ return GEdge.is(object);
34
+ }
35
+ }
36
+
37
+ export class GEdgeBuilder<G extends GEdge = GEdge> extends GModelElementBuilder<G> {
38
+ source(source: GModelElement): this {
39
+ this.proxy.sourceId = source.id;
40
+ return this;
41
+ }
42
+
43
+ sourceId(sourceId: string): this {
44
+ this.proxy.sourceId = sourceId;
45
+ return this;
46
+ }
47
+
48
+ target(target: GModelElement): this {
49
+ this.proxy.targetId = target.id;
50
+ return this;
51
+ }
52
+
53
+ targetId(targetId: string): this {
54
+ this.proxy.targetId = targetId;
55
+ return this;
56
+ }
57
+
58
+ routerKind(routerKind: string): this {
59
+ this.proxy.routerKind = routerKind;
60
+ return this;
61
+ }
62
+
63
+ addRoutingPoint(x: number, y: number): this;
64
+ addRoutingPoint(point: Point): this;
65
+ addRoutingPoint(xOrPoint: Point | number, y?: number): this {
66
+ if (typeof xOrPoint === 'object') {
67
+ this.proxy.routingPoints.push(xOrPoint);
68
+ } else if (y) {
69
+ this.proxy.routingPoints.push({ x: xOrPoint, y });
70
+ }
71
+ return this;
72
+ }
73
+
74
+ addRoutingPoints(routingPoints: Point[]): this;
75
+ addRoutingPoints(...routingPoints: Point[]): this;
76
+ addRoutingPoints(...routingPoints: MaybeArray<Point>[]): this {
77
+ flatPush(this.proxy.routingPoints, routingPoints);
78
+ return this;
79
+ }
80
+ }
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, 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 override builder(): GGraphBuilder {
28
+ return new GGraphBuilder(GGraph);
29
+ }
30
+
31
+ override type = types.GRAPH;
32
+ position: Point = Point.ORIGIN;
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
+ override 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, 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
+ override type = DefaultTypes.LABEL;
28
+ text: string;
29
+ alignment: Point = Point.ORIGIN;
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
+ });