@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.
- 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 +40 -0
- package/lib/gedge.d.ts.map +1 -0
- package/lib/gedge.js +74 -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 +106 -0
- package/lib/gmodel-element.d.ts.map +1 -0
- package/lib/gmodel-element.js +165 -0
- package/lib/gmodel-element.js.map +1 -0
- package/lib/gmodel-util.d.ts +36 -0
- package/lib/gmodel-util.d.ts.map +1 -0
- package/lib/gmodel-util.js +55 -0
- package/lib/gmodel-util.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 +34 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +46 -0
- package/lib/index.js.map +1 -0
- package/package.json +61 -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 +80 -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 +218 -0
- package/src/gmodel-util.ts +58 -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 +33 -0
|
@@ -0,0 +1,218 @@
|
|
|
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
|
+
JsonPrimitive,
|
|
22
|
+
MaybeArray,
|
|
23
|
+
Point,
|
|
24
|
+
SModelElementSchema,
|
|
25
|
+
SModelRootSchema
|
|
26
|
+
} from '@eclipse-glsp/protocol';
|
|
27
|
+
import * as uuid from 'uuid';
|
|
28
|
+
|
|
29
|
+
export type GModelElementConstructor<G extends GModelElement = GModelElement> = new () => G;
|
|
30
|
+
/**
|
|
31
|
+
* Represents a `GModeElement` serialized as plain JSON object.
|
|
32
|
+
*/
|
|
33
|
+
export type GModelElementSchema = SModelElementSchema;
|
|
34
|
+
|
|
35
|
+
export namespace GModelElementSchema {
|
|
36
|
+
/**
|
|
37
|
+
* Typeguard function to check wether the given object is an {@link GModelElementSchema}.
|
|
38
|
+
* @param object The object to check.
|
|
39
|
+
* @returns A type literal indicating wether the given object is of type {@link GModelElementSchema}.
|
|
40
|
+
*/
|
|
41
|
+
export const is = SModelElementSchema.is;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Base type for all elements of the graphical model.
|
|
46
|
+
* Each model element must have a unique ID and a type that is used to look up its view.
|
|
47
|
+
*/
|
|
48
|
+
export abstract class GModelElement implements GModelElementSchema {
|
|
49
|
+
/**
|
|
50
|
+
* The `type` of a `GModelElement` has two main purposes. It is used by the GLSP client
|
|
51
|
+
* during the rendering phase to lookup the View that is responsible for rendering this element.
|
|
52
|
+
* In addition, it serves as the discriminator for serialization & deserialization of `GModeElements` and their corresponding
|
|
53
|
+
* `GModelElementSchema`. e.g. If the glsp server receives a `GModelElementSchema` (plain JSON object) the type is used to
|
|
54
|
+
* lookup and construct the corresponding `GModelElement` class.
|
|
55
|
+
*/
|
|
56
|
+
type: string;
|
|
57
|
+
/**
|
|
58
|
+
* Each model element must have a unique ID. Duplicate ids in the graphical element will result in an error during the
|
|
59
|
+
* rendering phase.
|
|
60
|
+
*/
|
|
61
|
+
id: string;
|
|
62
|
+
/**
|
|
63
|
+
* A set of css classes that should be applied to the DOM element that corresponds to this element.
|
|
64
|
+
*/
|
|
65
|
+
cssClasses: string[] = [];
|
|
66
|
+
/** A `GModelElement can have an arbitrary amount of children. This parent-child relation ship is also reflected in
|
|
67
|
+
* the corresponding DOM element i.e. DOM elements that reflect children of this element are also children
|
|
68
|
+
* of the DOM element that reflects this element.
|
|
69
|
+
*/
|
|
70
|
+
children: GModelElement[] = [];
|
|
71
|
+
/**
|
|
72
|
+
* Each `GModelElement` (apart from the root element) must have an assigned parent. Orphan elements are not allowed.
|
|
73
|
+
*/
|
|
74
|
+
parent: GModelElement;
|
|
75
|
+
/**
|
|
76
|
+
* Additional custom arguments. Can be used to transmit additional information between client & server without
|
|
77
|
+
* having to extend the model.
|
|
78
|
+
*/
|
|
79
|
+
args?: Args;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Retrieve the {@link GModelRoot} element by traversing up the parent hierachy.
|
|
83
|
+
*/
|
|
84
|
+
get root(): GModelRoot {
|
|
85
|
+
let current: GModelElement = this;
|
|
86
|
+
while (!(current instanceof GModelRoot)) {
|
|
87
|
+
current = current.parent;
|
|
88
|
+
}
|
|
89
|
+
return current;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* A fluent builder API that simplifies the construction of complex {@link GModelElement}s.
|
|
95
|
+
* The builder API is derived from the Java GLSP server implementation where it is used to hide the complexity
|
|
96
|
+
* of creating EMF objects. However, the API is also useful in a Typescript/Node context to declare the creation of a new
|
|
97
|
+
* {@link GModelElement} in a more concise way.
|
|
98
|
+
*/
|
|
99
|
+
export abstract class GModelElementBuilder<G extends GModelElement> {
|
|
100
|
+
protected proxy: G;
|
|
101
|
+
protected elementConstructor: GModelElementConstructor<G>;
|
|
102
|
+
|
|
103
|
+
constructor(elementConstructor: GModelElementConstructor<G>) {
|
|
104
|
+
this.elementConstructor = elementConstructor;
|
|
105
|
+
this.proxy = new elementConstructor();
|
|
106
|
+
this.proxy.cssClasses = [];
|
|
107
|
+
this.proxy.children = [];
|
|
108
|
+
this.proxy.id = uuid.v4();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
reset(): this {
|
|
112
|
+
this.proxy = new this.elementConstructor();
|
|
113
|
+
return this;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
build(): G {
|
|
117
|
+
const element = new this.elementConstructor();
|
|
118
|
+
Object.assign(element, this.proxy);
|
|
119
|
+
element.children.forEach(child => (child.parent = element));
|
|
120
|
+
if (element.id === undefined) {
|
|
121
|
+
throw new Error('The `id` property of a GModelElement must not be undefined!');
|
|
122
|
+
}
|
|
123
|
+
if (element.type === undefined) {
|
|
124
|
+
throw new Error('The `type` property of a GModelElement must not be undefined!');
|
|
125
|
+
}
|
|
126
|
+
return element;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
id(id: string): this {
|
|
130
|
+
this.proxy.id = id;
|
|
131
|
+
return this;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
type(type: string): this {
|
|
135
|
+
this.proxy.type = type;
|
|
136
|
+
return this;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
addCssClass(cssClass: string): this {
|
|
140
|
+
this.proxy.cssClasses.push(cssClass);
|
|
141
|
+
return this;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
addCssClasses(cssClasses: string[]): this;
|
|
145
|
+
addCssClasses(...cssClasses: string[]): this;
|
|
146
|
+
addCssClasses(...cssClasses: MaybeArray<string>[]): this {
|
|
147
|
+
flatPush(this.proxy.cssClasses, cssClasses);
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
add(child: GModelElement): this {
|
|
152
|
+
this.proxy.children.push(child);
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
addChildren(children: GModelElement[]): this;
|
|
157
|
+
addChildren(...children: GModelElement[]): this;
|
|
158
|
+
addChildren(...children: MaybeArray<GModelElement>[]): this {
|
|
159
|
+
flatPush(this.proxy.children, children);
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
addArg(key: string, value: JsonPrimitive): this {
|
|
164
|
+
if (!this.proxy.args) {
|
|
165
|
+
this.proxy.args = {};
|
|
166
|
+
}
|
|
167
|
+
this.proxy.args[key] = value;
|
|
168
|
+
return this;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
addArgs(args: Args): this;
|
|
172
|
+
addArgs(args: Map<string, JsonPrimitive>): this;
|
|
173
|
+
addArgs(args: Args | Map<string, JsonPrimitive>): this {
|
|
174
|
+
const toAssign: Args = {};
|
|
175
|
+
if (args instanceof Map) {
|
|
176
|
+
[...args.keys()].forEach(key => (toAssign[key] = args.get(key)!));
|
|
177
|
+
} else {
|
|
178
|
+
Object.keys(args).forEach(key => (toAssign[key] = args[key]));
|
|
179
|
+
}
|
|
180
|
+
if (this.proxy.args) {
|
|
181
|
+
Object.assign(this.proxy.args, toAssign);
|
|
182
|
+
} else {
|
|
183
|
+
this.proxy.args = toAssign;
|
|
184
|
+
}
|
|
185
|
+
return this;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export type GModelRootSchema = SModelRootSchema;
|
|
190
|
+
|
|
191
|
+
export class GModelRoot extends GModelElement implements SModelRootSchema {
|
|
192
|
+
static builder(): GModelRootBuilder {
|
|
193
|
+
return new GModelRootBuilder(GModelRoot);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
canvasBounds?: Bounds;
|
|
197
|
+
revision = 0;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export class GModelRootBuilder<G extends GModelRoot = GModelRoot> extends GModelElementBuilder<G> {
|
|
201
|
+
revision(revision: number): this {
|
|
202
|
+
this.proxy.revision = revision;
|
|
203
|
+
return this;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
canvasBounds(position: Point, size: Dimension): this;
|
|
207
|
+
canvasBounds(bounds: Bounds): this;
|
|
208
|
+
canvasBounds(positionOrBounds: Point | Bounds, size?: Dimension): this {
|
|
209
|
+
let bounds: Bounds;
|
|
210
|
+
if (size) {
|
|
211
|
+
bounds = { ...positionOrBounds, ...size };
|
|
212
|
+
} else {
|
|
213
|
+
bounds = positionOrBounds as Bounds;
|
|
214
|
+
}
|
|
215
|
+
this.proxy.canvasBounds = bounds;
|
|
216
|
+
return this;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
|
|
17
|
+
import { GModelElement, GModelElementConstructor } from '.';
|
|
18
|
+
|
|
19
|
+
export type Predicate<T> = (element: T) => boolean;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Returns the first element matching the search predicate starting from the given
|
|
23
|
+
* element and walking up the parent hierarchy.
|
|
24
|
+
*
|
|
25
|
+
* @param element The element to start the search from.
|
|
26
|
+
* @param searchPredicate The predicate which the element should match.
|
|
27
|
+
* @returns The first matching element or `undefined`.
|
|
28
|
+
*/
|
|
29
|
+
export function findParent(element: GModelElement, searchPredicate: Predicate<GModelElement>): GModelElement | undefined {
|
|
30
|
+
if (!element) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
if (searchPredicate(element)) {
|
|
34
|
+
return element;
|
|
35
|
+
}
|
|
36
|
+
const parent = element.parent;
|
|
37
|
+
return parent ? findParent(parent, searchPredicate) : undefined;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Returns the first parent element that is an instance of the given {@link GModelElementConstructor} starting from the given element.
|
|
42
|
+
* (recursively walking up the parent hierarchy).
|
|
43
|
+
*
|
|
44
|
+
* @param element The element to start the search from.
|
|
45
|
+
* @param constructor The queried parent class ({@link GModelElementConstructor}).
|
|
46
|
+
* @returns The first matching parent element or `undefined`.
|
|
47
|
+
*/
|
|
48
|
+
export function findParentByClass<G extends GModelElement>(
|
|
49
|
+
element: GModelElement,
|
|
50
|
+
constructor: GModelElementConstructor<G>
|
|
51
|
+
): G | undefined {
|
|
52
|
+
const predicate: Predicate<GModelElement> = element => element instanceof constructor;
|
|
53
|
+
const result = findParent(element, predicate);
|
|
54
|
+
if (result) {
|
|
55
|
+
return result as G;
|
|
56
|
+
}
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
package/src/gnode.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 { GLayoutContainer, GLayoutContainerBuilder } from './glayout-container';
|
|
18
|
+
import { GShapeElement, GShapeElementBuilder } from './gshape-element';
|
|
19
|
+
|
|
20
|
+
export class GNode extends GShapeElement implements GLayoutContainer {
|
|
21
|
+
static builder(): GNodeBuilder {
|
|
22
|
+
return new GNodeBuilder(GNode).type(DefaultTypes.NODE);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
override type = DefaultTypes.NODE;
|
|
26
|
+
layout?: string;
|
|
27
|
+
[GLayoutContainer] = true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class GNodeBuilder<G extends GNode = GNode> extends GShapeElementBuilder<G> {
|
|
31
|
+
layout(layout?: string): this {
|
|
32
|
+
return GLayoutContainerBuilder.layout(this, layout);
|
|
33
|
+
}
|
|
34
|
+
}
|
package/src/gport.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
|
|
17
|
+
import { DefaultTypes } from '@eclipse-glsp/protocol';
|
|
18
|
+
import { GShapeElement, GShapeElementBuilder } from './gshape-element';
|
|
19
|
+
|
|
20
|
+
export class GPort extends GShapeElement {
|
|
21
|
+
static builder(): GShapeElementBuilder<GPort> {
|
|
22
|
+
return new GShapeElementBuilder(GPort).type(DefaultTypes.PORT);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
override type = DefaultTypes.PORT;
|
|
26
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
|
|
17
|
+
import { GModelElement, GModelElementBuilder } from './gmodel-element';
|
|
18
|
+
import { DefaultTypes } from '@eclipse-glsp/protocol';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Pre-rendered elements contain HTML or SVG code to be transferred to the DOM. This can be useful to
|
|
22
|
+
* render complex figures or to compute the view on the server instead of the client code.
|
|
23
|
+
* Pre rendered elements are often used for the popup model that is created by a `PopupModelFactory`.
|
|
24
|
+
* A popup model is rendered when hovering over a element and for many common use cases e.g rendering a tooltip
|
|
25
|
+
* this model can be computed entirely on the server side.
|
|
26
|
+
*/
|
|
27
|
+
export class GPreRenderedElement extends GModelElement {
|
|
28
|
+
static builder(): GPreRenderedElementBuilder {
|
|
29
|
+
return new GPreRenderedElementBuilder(GPreRenderedElement).type(DefaultTypes.PRE_RENDERED);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
code: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class GPreRenderedElementBuilder<G extends GPreRenderedElement = GPreRenderedElement> extends GModelElementBuilder<G> {
|
|
36
|
+
code(code: string): this {
|
|
37
|
+
this.proxy.code = code;
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
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, Dimension, JsonPrimitive, Point } from '@eclipse-glsp/protocol';
|
|
17
|
+
import { GBoundsAware, GBoundsAwareBuilder } from './gbound-aware';
|
|
18
|
+
import { GLayoutable, GLayoutableBuilder } from './glayoutable';
|
|
19
|
+
import { GModelElement, GModelElementBuilder } from './gmodel-element';
|
|
20
|
+
|
|
21
|
+
export abstract class GShapeElement extends GModelElement implements GBoundsAware, GLayoutable {
|
|
22
|
+
layoutOptions?: Args;
|
|
23
|
+
position: Point;
|
|
24
|
+
size: Dimension;
|
|
25
|
+
[GBoundsAware] = true;
|
|
26
|
+
[GLayoutable] = true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class GShapeElementBuilder<G extends GShapeElement> extends GModelElementBuilder<G> {
|
|
30
|
+
position(x: number, y: number): this;
|
|
31
|
+
position(position: Point): this;
|
|
32
|
+
position(pointOrX: Point | number, y?: number): this {
|
|
33
|
+
return GBoundsAwareBuilder.position(this, pointOrX, y);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
size(width: number, height: number): this;
|
|
37
|
+
size(size: Dimension): this;
|
|
38
|
+
size(sizeOrWidth: Dimension | number, height?: number): this {
|
|
39
|
+
return GBoundsAwareBuilder.size(this, sizeOrWidth, height);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
addLayoutOption(key: string, value: JsonPrimitive): this {
|
|
43
|
+
return GLayoutableBuilder.addLayoutOption(this, key, value);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
addLayoutOptions(layoutOptions: Args): this;
|
|
47
|
+
addLayoutOptions(layoutOptions: Map<string, JsonPrimitive>): this;
|
|
48
|
+
addLayoutOptions(layoutOptions: Args | Map<string, JsonPrimitive>): this {
|
|
49
|
+
return GLayoutableBuilder.addLayoutOptions(this, layoutOptions);
|
|
50
|
+
}
|
|
51
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
export * from './default-types';
|
|
17
|
+
export * from './galignable';
|
|
18
|
+
export * from './gbound-aware';
|
|
19
|
+
export * from './gbutton';
|
|
20
|
+
export * from './gcompartment';
|
|
21
|
+
export * from './gedge';
|
|
22
|
+
export * from './gedge-layoutable';
|
|
23
|
+
export * from './ggraph';
|
|
24
|
+
export * from './gissue-marker';
|
|
25
|
+
export * from './glabel';
|
|
26
|
+
export * from './glayout-container';
|
|
27
|
+
export * from './glayoutable';
|
|
28
|
+
export * from './gmodel-element';
|
|
29
|
+
export * from './gmodel-util';
|
|
30
|
+
export * from './gnode';
|
|
31
|
+
export * from './gport';
|
|
32
|
+
export * from './gpre-rendered-element';
|
|
33
|
+
export * from './gshape-element';
|