@eclipse-glsp/client 2.8.0-next.12 → 2.8.0-next.13
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/lib/base/model/glsp-model-source.d.ts +1 -1
- package/lib/base/model/glsp-model-source.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/base/model/glsp-model-source.ts +1 -1
- package/src/base/action-dispatcher.spec.ts +0 -366
- package/src/base/feedback/feedback-emitter.spec.ts +0 -176
- package/src/base/model/model-initialization-constraint.spec.ts +0 -95
- package/src/base/selection-service.spec.ts +0 -318
- package/src/default-modules.spec.ts +0 -56
- package/src/features/bounds/freeform-layout.spec.ts +0 -216
- package/src/features/bounds/hbox-layout.spec.ts +0 -170
- package/src/features/bounds/layouter-test-util.spec.ts +0 -127
- package/src/features/bounds/vbox-layout.spec.ts +0 -170
- package/src/features/change-bounds/point-position-updater.spec.ts +0 -81
- package/src/features/grid/grid-snapper.spec.ts +0 -30
- package/src/features/hints/type-hint-provider.spec.ts +0 -360
- package/src/features/layout/layout-elements-action.spec.ts +0 -426
- package/src/features/navigation/navigation-target-resolver.spec.ts +0 -56
- package/src/features/routing/sticky-manhattan-edge-router.spec.ts +0 -212
- package/src/features/tools/marquee-selection/marquee-behavior.spec.ts +0 -176
- package/src/features/validation/marker-navigator.spec.ts +0 -183
- package/src/utils/gmodel-util.spec.ts +0 -221
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Copyright (c) 2022-2023 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 { expect } from 'chai';
|
|
17
|
-
import 'mocha';
|
|
18
|
-
import 'reflect-metadata';
|
|
19
|
-
import { BoundsData, ConsoleLogger, GModelElement } from '@eclipse-glsp/sprotty';
|
|
20
|
-
import { createCompartment, createGraph, createLabel, createNode, layout, setupLayoutRegistry } from './layouter-test-util.spec';
|
|
21
|
-
|
|
22
|
-
describe('FreeFormLayouter', () => {
|
|
23
|
-
const layoutRegistry = setupLayoutRegistry();
|
|
24
|
-
const log = new ConsoleLogger();
|
|
25
|
-
const map = new Map<GModelElement, BoundsData>();
|
|
26
|
-
|
|
27
|
-
describe('issue-610', () => {
|
|
28
|
-
it('recursive hGrab/vGrab', () => {
|
|
29
|
-
/**
|
|
30
|
-
* _________________________
|
|
31
|
-
* | Category 1 |
|
|
32
|
-
* | _______________________ |
|
|
33
|
-
* || ||
|
|
34
|
-
* || ||
|
|
35
|
-
* || ||
|
|
36
|
-
* || ||
|
|
37
|
-
* ||_______________________||
|
|
38
|
-
* | _______________________ |
|
|
39
|
-
* ||_left____________right_||
|
|
40
|
-
* |_________________________|
|
|
41
|
-
*
|
|
42
|
-
* This test case checks recursive hGrab/vGrab functionality of nested compartments
|
|
43
|
-
* See also issue 610 for details and an example model https://github.com/eclipse-glsp/glsp/issues/610.
|
|
44
|
-
*/
|
|
45
|
-
const model = createGraph();
|
|
46
|
-
const category = createNode('category', 'vbox', { width: 410.0, height: 215.0 }, undefined, {
|
|
47
|
-
vGrab: false,
|
|
48
|
-
hGrab: false,
|
|
49
|
-
hAlign: 'center',
|
|
50
|
-
prefWidth: 410.0,
|
|
51
|
-
prefHeight: 215.0
|
|
52
|
-
});
|
|
53
|
-
const headerComp = createCompartment('comp:header', 'hbox');
|
|
54
|
-
headerComp.children = [createLabel('Category 1')];
|
|
55
|
-
const childContainer = createCompartment('struct', 'freeform', { hGrab: true, vGrab: true });
|
|
56
|
-
const labelContainer = createCompartment('struct', 'hbox', { hGrab: true });
|
|
57
|
-
labelContainer.children = [createLabel('left text', { hGrab: true }), createLabel('right text')];
|
|
58
|
-
category.children = [headerComp, childContainer, labelContainer];
|
|
59
|
-
|
|
60
|
-
model.add(category);
|
|
61
|
-
layout(layoutRegistry, log, map, model);
|
|
62
|
-
// check category
|
|
63
|
-
expect(map.get(category)!.bounds).to.deep.equal({ x: 0, y: 0, width: 410.0, height: 215.0 });
|
|
64
|
-
// check header compartment
|
|
65
|
-
expect(map.get(category.children[0])!.bounds).to.deep.equal({ x: 0, y: 0, width: -1, height: -1 });
|
|
66
|
-
// check child freeform compartment
|
|
67
|
-
expect(map.get(category.children[1])!.bounds).to.deep.equal({ x: 5, y: 5, width: 400.0, height: 205.0 });
|
|
68
|
-
// check label compartment
|
|
69
|
-
expect(map.get(category.children[2])!.bounds).to.deep.equal({ x: 0, y: 0, width: -1, height: -1 });
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe('issue-694', () => {
|
|
74
|
-
it('Structure compartment (hGrab=true, vGrab=true), Left-aligned label (hGrab=true), right-aligned label (hGrab=false)', () => {
|
|
75
|
-
/**
|
|
76
|
-
* _________________________
|
|
77
|
-
* | Category 2 |
|
|
78
|
-
* | _______________________ |
|
|
79
|
-
* || ||
|
|
80
|
-
* || ||
|
|
81
|
-
* || Task node ||
|
|
82
|
-
* || ||
|
|
83
|
-
* ||_______________________||
|
|
84
|
-
* | _______________________ |
|
|
85
|
-
* ||_left____________right_||
|
|
86
|
-
* |_________________________|
|
|
87
|
-
*/
|
|
88
|
-
const model = createGraph();
|
|
89
|
-
const category = createNode('category', 'vbox', { width: 500.0, height: 375.0 }, undefined, {
|
|
90
|
-
vGrab: false,
|
|
91
|
-
hGrab: false,
|
|
92
|
-
hAlign: 'center',
|
|
93
|
-
prefWidth: 500.0,
|
|
94
|
-
prefHeight: 375.0
|
|
95
|
-
});
|
|
96
|
-
const headerComp = createCompartment('comp:header', 'hbox');
|
|
97
|
-
headerComp.children = [createLabel('Category 2')];
|
|
98
|
-
const childContainer = createCompartment('struct', 'freeform', { hGrab: true, vGrab: true });
|
|
99
|
-
const childNode = createNode('task', 'hbox', undefined, { x: 170, y: 190 });
|
|
100
|
-
childNode.children = [createLabel('Task node', undefined, { x: 5.0, y: 5.0 }, { width: 25.0, height: 20.0 })];
|
|
101
|
-
childContainer.children = [childNode];
|
|
102
|
-
const labelContainer = createCompartment('struct', 'hbox', { hGrab: true });
|
|
103
|
-
labelContainer.children = [createLabel('left text', { hGrab: true }), createLabel('right text')];
|
|
104
|
-
category.children = [headerComp, childContainer, labelContainer];
|
|
105
|
-
|
|
106
|
-
model.add(category);
|
|
107
|
-
|
|
108
|
-
// layout graph
|
|
109
|
-
layout(layoutRegistry, log, map, model);
|
|
110
|
-
// check category
|
|
111
|
-
expect(map.get(category)!.bounds).to.deep.equal({ x: 0, y: 0, width: 500.0, height: 375.0 });
|
|
112
|
-
// check header compartment
|
|
113
|
-
expect(map.get(category.children[0])!.bounds).to.deep.equal({ x: 0, y: 0, width: -1, height: -1 });
|
|
114
|
-
// check child freeform compartment
|
|
115
|
-
expect(map.get(category.children[1])!.bounds).to.deep.equal({ x: 5.0, y: 5.0, width: 490.0, height: 365.0 });
|
|
116
|
-
// check child task node
|
|
117
|
-
expect(map.get(category.children[1].children[0])!.bounds).to.deep.equal({ x: 170.0, y: 190.0, width: 35.0, height: 30.0 });
|
|
118
|
-
// check label compartment
|
|
119
|
-
expect(map.get(category.children[2])!.bounds).to.deep.equal({ x: 0, y: 0, width: -1, height: -1 });
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it('Structure compartment (hGrab=true, vGrab=true)', () => {
|
|
123
|
-
/**
|
|
124
|
-
* _________________________
|
|
125
|
-
* | Category 2 |
|
|
126
|
-
* | _______________________ |
|
|
127
|
-
* || ||
|
|
128
|
-
* || Task node ||
|
|
129
|
-
* || ||
|
|
130
|
-
* || ||
|
|
131
|
-
* ||_______________________||
|
|
132
|
-
* |_________________________|
|
|
133
|
-
*/
|
|
134
|
-
const model = createGraph();
|
|
135
|
-
const category = createNode('category', 'vbox', { width: 500.0, height: 375.0 }, undefined, {
|
|
136
|
-
vGrab: false,
|
|
137
|
-
hGrab: false,
|
|
138
|
-
hAlign: 'center',
|
|
139
|
-
prefWidth: 500.0,
|
|
140
|
-
prefHeight: 375.0
|
|
141
|
-
});
|
|
142
|
-
const headerComp = createCompartment('comp:header', 'hbox');
|
|
143
|
-
headerComp.children = [createLabel('Category 2')];
|
|
144
|
-
const childContainer = createCompartment('struct', 'freeform', { hGrab: true, vGrab: true });
|
|
145
|
-
const childNode = createNode('task', 'hbox', undefined, { x: 55, y: 15 });
|
|
146
|
-
childNode.children = [createLabel('Task node', undefined, undefined, { width: 50.0, height: 35.0 })];
|
|
147
|
-
childContainer.children = [childNode];
|
|
148
|
-
category.children = [headerComp, childContainer];
|
|
149
|
-
|
|
150
|
-
model.add(category);
|
|
151
|
-
|
|
152
|
-
// layout graph
|
|
153
|
-
layout(layoutRegistry, log, map, model);
|
|
154
|
-
// check category
|
|
155
|
-
expect(map.get(category)!.bounds).to.deep.equal({ x: 0, y: 0, width: 500.0, height: 375.0 });
|
|
156
|
-
// check header compartment
|
|
157
|
-
expect(map.get(category.children[0])!.bounds).to.deep.equal({ x: 0, y: 0, width: -1, height: -1 });
|
|
158
|
-
// check child freeform compartment
|
|
159
|
-
expect(map.get(category.children[1])!.bounds).to.deep.equal({ x: 5.0, y: 5.0, width: 490.0, height: 365.0 });
|
|
160
|
-
// check child task node
|
|
161
|
-
expect(map.get(category.children[1].children[0])!.bounds).to.deep.equal({ x: 55.0, y: 15.0, width: 60.0, height: 45.0 });
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('Structure compartment (hGrab=true, vGrab=true, padding*=10)', () => {
|
|
165
|
-
/**
|
|
166
|
-
* _________________________
|
|
167
|
-
* | Category 2 |
|
|
168
|
-
* | _______________________ |
|
|
169
|
-
* || ||
|
|
170
|
-
* || Task node ||
|
|
171
|
-
* || ||
|
|
172
|
-
* || ||
|
|
173
|
-
* ||_______________________||
|
|
174
|
-
* |_________________________|
|
|
175
|
-
*/
|
|
176
|
-
const model = createGraph();
|
|
177
|
-
const category = createNode('category', 'vbox', { width: 500.0, height: 375.0 }, undefined, {
|
|
178
|
-
vGrab: false,
|
|
179
|
-
hGrab: false,
|
|
180
|
-
hAlign: 'center',
|
|
181
|
-
prefWidth: 500.0,
|
|
182
|
-
prefHeight: 375.0,
|
|
183
|
-
paddingLeft: 10,
|
|
184
|
-
paddingRight: 10,
|
|
185
|
-
paddingTop: 10,
|
|
186
|
-
paddingBottom: 10
|
|
187
|
-
});
|
|
188
|
-
const headerComp = createCompartment('comp:header', 'hbox');
|
|
189
|
-
headerComp.children = [createLabel('Category 2')];
|
|
190
|
-
const childContainer = createCompartment('struct', 'freeform', { hGrab: true, vGrab: true });
|
|
191
|
-
const childNode = createNode(
|
|
192
|
-
'task',
|
|
193
|
-
'hbox',
|
|
194
|
-
undefined,
|
|
195
|
-
{ x: 55, y: 15 },
|
|
196
|
-
{ paddingLeft: 10, paddingRight: 10, paddingTop: 10, paddingBottom: 10 }
|
|
197
|
-
);
|
|
198
|
-
childNode.children = [createLabel('Task node', undefined, undefined, { width: 50.0, height: 35.0 })];
|
|
199
|
-
childContainer.children = [childNode];
|
|
200
|
-
category.children = [headerComp, childContainer];
|
|
201
|
-
|
|
202
|
-
model.add(category);
|
|
203
|
-
|
|
204
|
-
// layout graph
|
|
205
|
-
layout(layoutRegistry, log, map, model);
|
|
206
|
-
// check category
|
|
207
|
-
expect(map.get(category)!.bounds).to.deep.equal({ x: 0, y: 0, width: 500.0, height: 375.0 });
|
|
208
|
-
// check header compartment
|
|
209
|
-
expect(map.get(category.children[0])!.bounds).to.deep.equal({ x: 0, y: 0, width: -1, height: -1 });
|
|
210
|
-
// check child freeform compartment
|
|
211
|
-
expect(map.get(category.children[1])!.bounds).to.deep.equal({ x: 10.0, y: 10.0, width: 480.0, height: 355.0 });
|
|
212
|
-
// check child task node
|
|
213
|
-
expect(map.get(category.children[1].children[0])!.bounds).to.deep.equal({ x: 55.0, y: 15.0, width: 70.0, height: 55.0 });
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
});
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Copyright (c) 2022-2026 TypeFox, 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 { expect } from 'chai';
|
|
18
|
-
import 'mocha';
|
|
19
|
-
import 'reflect-metadata';
|
|
20
|
-
import { BoundsData, ConsoleLogger, Dimension, GModelElement, GNode } from '@eclipse-glsp/sprotty';
|
|
21
|
-
import { createLabel, createNode, layout, setupLayoutRegistry } from './layouter-test-util.spec';
|
|
22
|
-
|
|
23
|
-
describe('HBoxLayouter', () => {
|
|
24
|
-
const layoutRegistry = setupLayoutRegistry();
|
|
25
|
-
const log = new ConsoleLogger();
|
|
26
|
-
const map = new Map<GModelElement, BoundsData>();
|
|
27
|
-
|
|
28
|
-
function createModel(): GNode {
|
|
29
|
-
const model = createNode('node', undefined, Dimension.EMPTY);
|
|
30
|
-
model.children = [
|
|
31
|
-
createLabel('label1', undefined, undefined, { width: 1, height: 2 }),
|
|
32
|
-
createLabel('label2', undefined, undefined, { width: 2, height: 1 }),
|
|
33
|
-
createLabel('label3', undefined, undefined, { width: 3, height: 3 })
|
|
34
|
-
];
|
|
35
|
-
model.layout = 'hbox';
|
|
36
|
-
return model;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
it('defaultParams', () => {
|
|
40
|
-
const model = createModel();
|
|
41
|
-
layout(layoutRegistry, log, map, model);
|
|
42
|
-
expect(map.get(model)!.bounds).to.deep.equal({ x: 0, y: 0, width: 18, height: 13 });
|
|
43
|
-
expect(map.get(model.children[0])!.bounds).to.deep.equal({ x: 5, y: 5.5, width: 1, height: 2 });
|
|
44
|
-
expect(map.get(model.children[1])!.bounds).to.deep.equal({ x: 7, y: 6, width: 2, height: 1 });
|
|
45
|
-
expect(map.get(model.children[2])!.bounds).to.deep.equal({ x: 10, y: 5, width: 3, height: 3 });
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('alignTop', () => {
|
|
49
|
-
const model = createModel();
|
|
50
|
-
model.layoutOptions = {
|
|
51
|
-
vAlign: 'top'
|
|
52
|
-
};
|
|
53
|
-
layout(layoutRegistry, log, map, model);
|
|
54
|
-
expect(map.get(model)!.bounds).to.deep.equal({ x: 0, y: 0, width: 18, height: 13 });
|
|
55
|
-
expect(map.get(model.children[0])!.bounds).to.deep.equal({ x: 5, y: 5, width: 1, height: 2 });
|
|
56
|
-
expect(map.get(model.children[1])!.bounds).to.deep.equal({ x: 7, y: 5, width: 2, height: 1 });
|
|
57
|
-
expect(map.get(model.children[2])!.bounds).to.deep.equal({ x: 10, y: 5, width: 3, height: 3 });
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('alignCenter', () => {
|
|
61
|
-
const model = createModel();
|
|
62
|
-
model.layoutOptions = {
|
|
63
|
-
vAlign: 'center'
|
|
64
|
-
};
|
|
65
|
-
layout(layoutRegistry, log, map, model);
|
|
66
|
-
expect(map.get(model)!.bounds).to.deep.equal({ x: 0, y: 0, width: 18, height: 13 });
|
|
67
|
-
expect(map.get(model.children[0])!.bounds).to.deep.equal({ x: 5, y: 5.5, width: 1, height: 2 });
|
|
68
|
-
expect(map.get(model.children[1])!.bounds).to.deep.equal({ x: 7, y: 6, width: 2, height: 1 });
|
|
69
|
-
expect(map.get(model.children[2])!.bounds).to.deep.equal({ x: 10, y: 5, width: 3, height: 3 });
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('alignBottom', () => {
|
|
73
|
-
const model = createModel();
|
|
74
|
-
model.layoutOptions = {
|
|
75
|
-
vAlign: 'bottom'
|
|
76
|
-
};
|
|
77
|
-
layout(layoutRegistry, log, map, model);
|
|
78
|
-
expect(map.get(model)!.bounds).to.deep.equal({ x: 0, y: 0, width: 18, height: 13 });
|
|
79
|
-
expect(map.get(model.children[0])!.bounds).to.deep.equal({ x: 5, y: 6, width: 1, height: 2 });
|
|
80
|
-
expect(map.get(model.children[1])!.bounds).to.deep.equal({ x: 7, y: 7, width: 2, height: 1 });
|
|
81
|
-
expect(map.get(model.children[2])!.bounds).to.deep.equal({ x: 10, y: 5, width: 3, height: 3 });
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('padding', () => {
|
|
85
|
-
const model = createModel();
|
|
86
|
-
model.layoutOptions = {
|
|
87
|
-
paddingTop: 7,
|
|
88
|
-
paddingBottom: 8,
|
|
89
|
-
paddingLeft: 9,
|
|
90
|
-
paddingRight: 10
|
|
91
|
-
};
|
|
92
|
-
layout(layoutRegistry, log, map, model);
|
|
93
|
-
expect(map.get(model)!.bounds).to.deep.equal({ x: 0, y: 0, width: 27, height: 18 });
|
|
94
|
-
expect(map.get(model.children[0])!.bounds).to.deep.equal({ x: 9, y: 7.5, width: 1, height: 2 });
|
|
95
|
-
expect(map.get(model.children[1])!.bounds).to.deep.equal({ x: 11, y: 8, width: 2, height: 1 });
|
|
96
|
-
expect(map.get(model.children[2])!.bounds).to.deep.equal({ x: 14, y: 7, width: 3, height: 3 });
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('hGap', () => {
|
|
100
|
-
const model = createModel();
|
|
101
|
-
model.layoutOptions = {
|
|
102
|
-
hGap: 4
|
|
103
|
-
};
|
|
104
|
-
layout(layoutRegistry, log, map, model);
|
|
105
|
-
expect(map.get(model)!.bounds).to.deep.equal({ x: 0, y: 0, width: 24, height: 13 });
|
|
106
|
-
expect(map.get(model.children[0])!.bounds).to.deep.equal({ x: 5, y: 5.5, width: 1, height: 2 });
|
|
107
|
-
expect(map.get(model.children[1])!.bounds).to.deep.equal({ x: 10, y: 6, width: 2, height: 1 });
|
|
108
|
-
expect(map.get(model.children[2])!.bounds).to.deep.equal({ x: 16, y: 5, width: 3, height: 3 });
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('paddingFactor', () => {
|
|
112
|
-
const model = createModel();
|
|
113
|
-
model.layoutOptions = {
|
|
114
|
-
paddingFactor: 2
|
|
115
|
-
};
|
|
116
|
-
layout(layoutRegistry, log, map, model);
|
|
117
|
-
expect(map.get(model)!.bounds).to.deep.equal({ x: 0, y: 0, width: 18, height: 13 });
|
|
118
|
-
expect(map.get(model.children[0])!.bounds).to.deep.equal({ x: 9, y: 8.5, width: 1, height: 2 });
|
|
119
|
-
expect(map.get(model.children[1])!.bounds).to.deep.equal({ x: 11, y: 9, width: 2, height: 1 });
|
|
120
|
-
expect(map.get(model.children[2])!.bounds).to.deep.equal({ x: 14, y: 8, width: 3, height: 3 });
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it('minWidth', () => {
|
|
124
|
-
const model = createModel();
|
|
125
|
-
model.layoutOptions = {
|
|
126
|
-
minWidth: 25
|
|
127
|
-
};
|
|
128
|
-
layout(layoutRegistry, log, map, model);
|
|
129
|
-
expect(map.get(model)!.bounds).to.deep.equal({ x: 0, y: 0, width: 25, height: 13 });
|
|
130
|
-
expect(map.get(model.children[0])!.bounds).to.deep.equal({ x: 5, y: 5.5, width: 1, height: 2 });
|
|
131
|
-
expect(map.get(model.children[1])!.bounds).to.deep.equal({ x: 7, y: 6, width: 2, height: 1 });
|
|
132
|
-
expect(map.get(model.children[2])!.bounds).to.deep.equal({ x: 10, y: 5, width: 3, height: 3 });
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('minHeight', () => {
|
|
136
|
-
const model = createModel();
|
|
137
|
-
model.layoutOptions = {
|
|
138
|
-
minHeight: 25
|
|
139
|
-
};
|
|
140
|
-
layout(layoutRegistry, log, map, model);
|
|
141
|
-
expect(map.get(model)!.bounds).to.deep.equal({ x: 0, y: 0, width: 18, height: 25 });
|
|
142
|
-
expect(map.get(model.children[0])!.bounds).to.deep.equal({ x: 5, y: 11.5, width: 1, height: 2 });
|
|
143
|
-
expect(map.get(model.children[1])!.bounds).to.deep.equal({ x: 7, y: 12, width: 2, height: 1 });
|
|
144
|
-
expect(map.get(model.children[2])!.bounds).to.deep.equal({ x: 10, y: 11, width: 3, height: 3 });
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('prefWidth', () => {
|
|
148
|
-
const model = createModel();
|
|
149
|
-
model.layoutOptions = {
|
|
150
|
-
prefWidth: 20
|
|
151
|
-
};
|
|
152
|
-
layout(layoutRegistry, log, map, model);
|
|
153
|
-
expect(map.get(model)!.bounds).to.deep.equal({ x: 0, y: 0, width: 20, height: 13 });
|
|
154
|
-
expect(map.get(model.children[0])!.bounds).to.deep.equal({ x: 5, y: 5.5, width: 1, height: 2 });
|
|
155
|
-
expect(map.get(model.children[1])!.bounds).to.deep.equal({ x: 7, y: 6, width: 2, height: 1 });
|
|
156
|
-
expect(map.get(model.children[2])!.bounds).to.deep.equal({ x: 10, y: 5, width: 3, height: 3 });
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it('prefHeight', () => {
|
|
160
|
-
const model = createModel();
|
|
161
|
-
model.layoutOptions = {
|
|
162
|
-
prefHeight: 20
|
|
163
|
-
};
|
|
164
|
-
layout(layoutRegistry, log, map, model);
|
|
165
|
-
expect(map.get(model)!.bounds).to.deep.equal({ x: 0, y: 0, width: 18, height: 20 });
|
|
166
|
-
expect(map.get(model.children[0])!.bounds).to.deep.equal({ x: 5, y: 9, width: 1, height: 2 });
|
|
167
|
-
expect(map.get(model.children[1])!.bounds).to.deep.equal({ x: 7, y: 9.5, width: 2, height: 1 });
|
|
168
|
-
expect(map.get(model.children[2])!.bounds).to.deep.equal({ x: 10, y: 8.5, width: 3, height: 3 });
|
|
169
|
-
});
|
|
170
|
-
});
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Copyright (c) 2022-2023 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 { Container } from 'inversify';
|
|
18
|
-
import 'mocha';
|
|
19
|
-
import {
|
|
20
|
-
BoundsData,
|
|
21
|
-
ConsoleLogger,
|
|
22
|
-
Dimension,
|
|
23
|
-
LayoutRegistry,
|
|
24
|
-
Point,
|
|
25
|
-
GCompartment,
|
|
26
|
-
GLabel,
|
|
27
|
-
GModelElement,
|
|
28
|
-
GNode,
|
|
29
|
-
GParentElement,
|
|
30
|
-
TYPES,
|
|
31
|
-
createFeatureSet,
|
|
32
|
-
layoutableChildFeature
|
|
33
|
-
} from '@eclipse-glsp/sprotty';
|
|
34
|
-
import { initializeDiagramContainer } from '../../default-modules';
|
|
35
|
-
import { StatefulLayouterExt } from './layouter';
|
|
36
|
-
import { GGraph } from '../../model';
|
|
37
|
-
|
|
38
|
-
export function createGraph(): GGraph {
|
|
39
|
-
return new GGraph();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function createNode(
|
|
43
|
-
type: string,
|
|
44
|
-
nodeLayout?: string,
|
|
45
|
-
size?: Dimension,
|
|
46
|
-
position?: Point,
|
|
47
|
-
layoutOptions?: { [key: string]: string | number | boolean }
|
|
48
|
-
): GNode {
|
|
49
|
-
const node = new GNode();
|
|
50
|
-
node.features = createFeatureSet(GNode.DEFAULT_FEATURES, { enable: [layoutableChildFeature] });
|
|
51
|
-
node.position = position || {
|
|
52
|
-
x: 0,
|
|
53
|
-
y: 0
|
|
54
|
-
};
|
|
55
|
-
if (size) {
|
|
56
|
-
node.size = size;
|
|
57
|
-
}
|
|
58
|
-
node.type = type;
|
|
59
|
-
if (nodeLayout) {
|
|
60
|
-
node.layout = nodeLayout;
|
|
61
|
-
}
|
|
62
|
-
node.layoutOptions = layoutOptions;
|
|
63
|
-
return node;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function createCompartment(
|
|
67
|
-
type: string,
|
|
68
|
-
compLayout: string,
|
|
69
|
-
layoutOptions?: { [key: string]: string | number | boolean }
|
|
70
|
-
): GCompartment {
|
|
71
|
-
const comp = new GCompartment();
|
|
72
|
-
comp.features = createFeatureSet(GCompartment.DEFAULT_FEATURES);
|
|
73
|
-
comp.type = type;
|
|
74
|
-
comp.layout = compLayout;
|
|
75
|
-
comp.layoutOptions = layoutOptions;
|
|
76
|
-
return comp;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function createLabel(
|
|
80
|
-
labelText: string,
|
|
81
|
-
layoutOptions?: { [key: string]: string | number | boolean },
|
|
82
|
-
position?: Point,
|
|
83
|
-
size?: Dimension
|
|
84
|
-
): GLabel {
|
|
85
|
-
const label = new GLabel();
|
|
86
|
-
label.features = createFeatureSet(GLabel.DEFAULT_FEATURES);
|
|
87
|
-
if (position) {
|
|
88
|
-
label.position = position;
|
|
89
|
-
}
|
|
90
|
-
if (size) {
|
|
91
|
-
label.size = size;
|
|
92
|
-
}
|
|
93
|
-
label.layoutOptions = layoutOptions;
|
|
94
|
-
label.text = labelText;
|
|
95
|
-
label.type = 'label';
|
|
96
|
-
return label;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export function addToMap(map: Map<GModelElement, BoundsData>, element: GModelElement): void {
|
|
100
|
-
map.set(element, {
|
|
101
|
-
bounds: (element as any).bounds,
|
|
102
|
-
boundsChanged: true,
|
|
103
|
-
alignmentChanged: true
|
|
104
|
-
});
|
|
105
|
-
if (element instanceof GParentElement) {
|
|
106
|
-
element.children.forEach(c => addToMap(map, c));
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export function layout(
|
|
111
|
-
layoutRegistry: LayoutRegistry,
|
|
112
|
-
log: ConsoleLogger,
|
|
113
|
-
map: Map<GModelElement, BoundsData>,
|
|
114
|
-
model: GNode | GGraph
|
|
115
|
-
): void {
|
|
116
|
-
map.clear();
|
|
117
|
-
addToMap(map, model);
|
|
118
|
-
const layouter = new StatefulLayouterExt(map, layoutRegistry, log);
|
|
119
|
-
layouter.layout();
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export function setupLayoutRegistry(): LayoutRegistry {
|
|
123
|
-
// Generic Test setup
|
|
124
|
-
// create client container that registers all default modules including the layoutModule
|
|
125
|
-
const layoutContainer = initializeDiagramContainer(new Container());
|
|
126
|
-
return layoutContainer.get<LayoutRegistry>(TYPES.LayoutRegistry);
|
|
127
|
-
}
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
/********************************************************************************
|
|
2
|
-
* Copyright (c) 2022-2026 TypeFox, 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 { expect } from 'chai';
|
|
18
|
-
import 'mocha';
|
|
19
|
-
import 'reflect-metadata';
|
|
20
|
-
import { BoundsData, ConsoleLogger, Dimension, GModelElement, GNode } from '@eclipse-glsp/sprotty';
|
|
21
|
-
import { createLabel, createNode, layout, setupLayoutRegistry } from './layouter-test-util.spec';
|
|
22
|
-
|
|
23
|
-
describe('VBoxLayouter', () => {
|
|
24
|
-
const layoutRegistry = setupLayoutRegistry();
|
|
25
|
-
const log = new ConsoleLogger();
|
|
26
|
-
const map = new Map<GModelElement, BoundsData>();
|
|
27
|
-
|
|
28
|
-
function createModel(): GNode {
|
|
29
|
-
const model = createNode('node', undefined, Dimension.EMPTY);
|
|
30
|
-
model.children = [
|
|
31
|
-
createLabel('label1', undefined, undefined, { width: 1, height: 2 }),
|
|
32
|
-
createLabel('label2', undefined, undefined, { width: 2, height: 1 }),
|
|
33
|
-
createLabel('label3', undefined, undefined, { width: 3, height: 3 })
|
|
34
|
-
];
|
|
35
|
-
model.layout = 'vbox';
|
|
36
|
-
return model;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
it('defaultParams', () => {
|
|
40
|
-
const model = createModel();
|
|
41
|
-
layout(layoutRegistry, log, map, model);
|
|
42
|
-
expect(map.get(model)!.bounds).to.deep.equal({ x: 0, y: 0, width: 13, height: 18 });
|
|
43
|
-
expect(map.get(model.children[0])!.bounds).to.deep.equal({ x: 6, y: 5, width: 1, height: 2 });
|
|
44
|
-
expect(map.get(model.children[1])!.bounds).to.deep.equal({ x: 5.5, y: 8, width: 2, height: 1 });
|
|
45
|
-
expect(map.get(model.children[2])!.bounds).to.deep.equal({ x: 5, y: 10, width: 3, height: 3 });
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('alignLeft', () => {
|
|
49
|
-
const model = createModel();
|
|
50
|
-
model.layoutOptions = {
|
|
51
|
-
hAlign: 'left'
|
|
52
|
-
};
|
|
53
|
-
layout(layoutRegistry, log, map, model);
|
|
54
|
-
expect(map.get(model)!.bounds).to.deep.equal({ x: 0, y: 0, width: 13, height: 18 });
|
|
55
|
-
expect(map.get(model.children[0])!.bounds).to.deep.equal({ x: 5, y: 5, width: 1, height: 2 });
|
|
56
|
-
expect(map.get(model.children[1])!.bounds).to.deep.equal({ x: 5, y: 8, width: 2, height: 1 });
|
|
57
|
-
expect(map.get(model.children[2])!.bounds).to.deep.equal({ x: 5, y: 10, width: 3, height: 3 });
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('alignCenter', () => {
|
|
61
|
-
const model = createModel();
|
|
62
|
-
model.layoutOptions = {
|
|
63
|
-
hAlign: 'center'
|
|
64
|
-
};
|
|
65
|
-
layout(layoutRegistry, log, map, model);
|
|
66
|
-
expect(map.get(model)!.bounds).to.deep.equal({ x: 0, y: 0, width: 13, height: 18 });
|
|
67
|
-
expect(map.get(model.children[0])!.bounds).to.deep.equal({ x: 6, y: 5, width: 1, height: 2 });
|
|
68
|
-
expect(map.get(model.children[1])!.bounds).to.deep.equal({ x: 5.5, y: 8, width: 2, height: 1 });
|
|
69
|
-
expect(map.get(model.children[2])!.bounds).to.deep.equal({ x: 5, y: 10, width: 3, height: 3 });
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('alignRight', () => {
|
|
73
|
-
const model = createModel();
|
|
74
|
-
model.layoutOptions = {
|
|
75
|
-
hAlign: 'right'
|
|
76
|
-
};
|
|
77
|
-
layout(layoutRegistry, log, map, model);
|
|
78
|
-
expect(map.get(model)!.bounds).to.deep.equal({ x: 0, y: 0, width: 13, height: 18 });
|
|
79
|
-
expect(map.get(model.children[0])!.bounds).to.deep.equal({ x: 7, y: 5, width: 1, height: 2 });
|
|
80
|
-
expect(map.get(model.children[1])!.bounds).to.deep.equal({ x: 6, y: 8, width: 2, height: 1 });
|
|
81
|
-
expect(map.get(model.children[2])!.bounds).to.deep.equal({ x: 5, y: 10, width: 3, height: 3 });
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('padding', () => {
|
|
85
|
-
const model = createModel();
|
|
86
|
-
model.layoutOptions = {
|
|
87
|
-
paddingTop: 7,
|
|
88
|
-
paddingBottom: 8,
|
|
89
|
-
paddingLeft: 9,
|
|
90
|
-
paddingRight: 10
|
|
91
|
-
};
|
|
92
|
-
layout(layoutRegistry, log, map, model);
|
|
93
|
-
expect(map.get(model)!.bounds).to.deep.equal({ x: 0, y: 0, width: 22, height: 23 });
|
|
94
|
-
expect(map.get(model.children[0])!.bounds).to.deep.equal({ x: 10, y: 7, width: 1, height: 2 });
|
|
95
|
-
expect(map.get(model.children[1])!.bounds).to.deep.equal({ x: 9.5, y: 10, width: 2, height: 1 });
|
|
96
|
-
expect(map.get(model.children[2])!.bounds).to.deep.equal({ x: 9, y: 12, width: 3, height: 3 });
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('vGap', () => {
|
|
100
|
-
const model = createModel();
|
|
101
|
-
model.layoutOptions = {
|
|
102
|
-
vGap: 4
|
|
103
|
-
};
|
|
104
|
-
layout(layoutRegistry, log, map, model);
|
|
105
|
-
expect(map.get(model)!.bounds).to.deep.equal({ x: 0, y: 0, width: 13, height: 24 });
|
|
106
|
-
expect(map.get(model.children[0])!.bounds).to.deep.equal({ x: 6, y: 5, width: 1, height: 2 });
|
|
107
|
-
expect(map.get(model.children[1])!.bounds).to.deep.equal({ x: 5.5, y: 11, width: 2, height: 1 });
|
|
108
|
-
expect(map.get(model.children[2])!.bounds).to.deep.equal({ x: 5, y: 16, width: 3, height: 3 });
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('paddingFactor', () => {
|
|
112
|
-
const model = createModel();
|
|
113
|
-
model.layoutOptions = {
|
|
114
|
-
paddingFactor: 2
|
|
115
|
-
};
|
|
116
|
-
layout(layoutRegistry, log, map, model);
|
|
117
|
-
expect(map.get(model)!.bounds).to.deep.equal({ x: 0, y: 0, width: 13, height: 18 });
|
|
118
|
-
expect(map.get(model.children[0])!.bounds).to.deep.equal({ x: 9, y: 9, width: 1, height: 2 });
|
|
119
|
-
expect(map.get(model.children[1])!.bounds).to.deep.equal({ x: 8.5, y: 12, width: 2, height: 1 });
|
|
120
|
-
expect(map.get(model.children[2])!.bounds).to.deep.equal({ x: 8, y: 14, width: 3, height: 3 });
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it('minWidth', () => {
|
|
124
|
-
const model = createModel();
|
|
125
|
-
model.layoutOptions = {
|
|
126
|
-
minWidth: 25
|
|
127
|
-
};
|
|
128
|
-
layout(layoutRegistry, log, map, model);
|
|
129
|
-
expect(map.get(model)!.bounds).to.deep.equal({ x: 0, y: 0, width: 25, height: 18 });
|
|
130
|
-
expect(map.get(model.children[0])!.bounds).to.deep.equal({ x: 12, y: 5, width: 1, height: 2 });
|
|
131
|
-
expect(map.get(model.children[1])!.bounds).to.deep.equal({ x: 11.5, y: 8, width: 2, height: 1 });
|
|
132
|
-
expect(map.get(model.children[2])!.bounds).to.deep.equal({ x: 11, y: 10, width: 3, height: 3 });
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('minHeight', () => {
|
|
136
|
-
const model = createModel();
|
|
137
|
-
model.layoutOptions = {
|
|
138
|
-
minHeight: 25
|
|
139
|
-
};
|
|
140
|
-
layout(layoutRegistry, log, map, model);
|
|
141
|
-
expect(map.get(model)!.bounds).to.deep.equal({ x: 0, y: 0, width: 13, height: 25 });
|
|
142
|
-
expect(map.get(model.children[0])!.bounds).to.deep.equal({ x: 6, y: 5, width: 1, height: 2 });
|
|
143
|
-
expect(map.get(model.children[1])!.bounds).to.deep.equal({ x: 5.5, y: 8, width: 2, height: 1 });
|
|
144
|
-
expect(map.get(model.children[2])!.bounds).to.deep.equal({ x: 5, y: 10, width: 3, height: 3 });
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('prefWidth', () => {
|
|
148
|
-
const model = createModel();
|
|
149
|
-
model.layoutOptions = {
|
|
150
|
-
prefWidth: 20
|
|
151
|
-
};
|
|
152
|
-
layout(layoutRegistry, log, map, model);
|
|
153
|
-
expect(map.get(model)!.bounds).to.deep.equal({ x: 0, y: 0, width: 20, height: 18 });
|
|
154
|
-
expect(map.get(model.children[0])!.bounds).to.deep.equal({ x: 9.5, y: 5, width: 1, height: 2 });
|
|
155
|
-
expect(map.get(model.children[1])!.bounds).to.deep.equal({ x: 9, y: 8, width: 2, height: 1 });
|
|
156
|
-
expect(map.get(model.children[2])!.bounds).to.deep.equal({ x: 8.5, y: 10, width: 3, height: 3 });
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it('prefHeight', () => {
|
|
160
|
-
const model = createModel();
|
|
161
|
-
model.layoutOptions = {
|
|
162
|
-
prefHeight: 20
|
|
163
|
-
};
|
|
164
|
-
layout(layoutRegistry, log, map, model);
|
|
165
|
-
expect(map.get(model)!.bounds).to.deep.equal({ x: 0, y: 0, width: 13, height: 20 });
|
|
166
|
-
expect(map.get(model.children[0])!.bounds).to.deep.equal({ x: 6, y: 5, width: 1, height: 2 });
|
|
167
|
-
expect(map.get(model.children[1])!.bounds).to.deep.equal({ x: 5.5, y: 8, width: 2, height: 1 });
|
|
168
|
-
expect(map.get(model.children[2])!.bounds).to.deep.equal({ x: 5, y: 10, width: 3, height: 3 });
|
|
169
|
-
});
|
|
170
|
-
});
|