Skip to content

Commit 8fec2bd

Browse files
Extend model submission with optional layout information (#121)
* Extend model submission with optional layout information Fixes eclipse-glsp/glsp#1616 * Upgrade next --------- Co-authored-by: Tobias Ortmayr <tortmayr@eclipsesource.com>
1 parent 95c1859 commit 8fec2bd

3 files changed

Lines changed: 15 additions & 9 deletions

File tree

packages/server/src/common/features/layout/computed-bounds-action-handler.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
1515
********************************************************************************/
1616
import { GModelRoot } from '@eclipse-glsp/graph';
17-
import { Action, ComputedBoundsAction, MaybePromise } from '@eclipse-glsp/protocol';
17+
import { Action, ComputedBoundsAction, LayoutOperation, MaybePromise } from '@eclipse-glsp/protocol';
1818
import { inject, injectable } from 'inversify';
1919
import { ActionHandler } from '../../actions/action-handler';
2020
import { applyAlignment, applyElementAndBounds, applyRoute } from '../../utils/layout-util';
@@ -39,7 +39,10 @@ export class ComputedBoundsActionHandler implements ActionHandler {
3939
const model = this.modelState.root;
4040
if (action.revision === model.revision) {
4141
this.applyBounds(model, action);
42-
return this.submissionHandler.submitModelDirectly();
42+
return this.submissionHandler.submitModelDirectly(
43+
undefined,
44+
LayoutOperation.create([], { canvasBounds: action.canvasBounds, viewport: action.viewport })
45+
);
4346
}
4447

4548
return [];

packages/server/src/common/features/model/model-submission-handler.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
Action,
1818
DirtyStateChangeReason,
1919
GModelRootSchema,
20+
LayoutOperation,
2021
MarkersReason,
2122
MaybePromise,
2223
RequestBoundsAction,
@@ -112,9 +113,10 @@ export class ModelSubmissionHandler {
112113
* to the `ActionDispatcher`, or simply returned as the result of an `ActionHandler.execute()` method.
113114
*
114115
* @param reason The optional reason that caused the model update.
116+
* @param layout The optional layout operation that carries the information for auto-layout.
115117
* @returns A list of actions to be processed in order to submit the model.
116118
*/
117-
submitModel(reason?: DirtyStateChangeReason): MaybePromise<Action[]> {
119+
submitModel(reason?: DirtyStateChangeReason, layout?: LayoutOperation): MaybePromise<Action[]> {
118120
this.modelFactory.createModel();
119121

120122
const revision = this.requestModelAction ? 0 : this.modelState.root.revision! + 1;
@@ -124,7 +126,7 @@ export class ModelSubmissionHandler {
124126
const root = this.serializeGModel();
125127
return [RequestBoundsAction.create(root), SetDirtyStateAction.create(this.commandStack.isDirty, { reason })];
126128
}
127-
return this.submitModelDirectly(reason);
129+
return this.submitModelDirectly(reason, layout);
128130
}
129131

130132
/**
@@ -139,11 +141,12 @@ export class ModelSubmissionHandler {
139141
* `ActionHandler.execute()` method.
140142
*
141143
* @param reason The optional reason that caused the model update.
144+
* @param layout The optional layout operation that carries the information for auto-layout.
142145
* @returns A list of actions to be processed in order to submit the model.
143146
*/
144-
async submitModelDirectly(reason?: DirtyStateChangeReason): Promise<Action[]> {
147+
async submitModelDirectly(reason?: DirtyStateChangeReason, layout?: LayoutOperation): Promise<Action[]> {
145148
if (this.diagramConfiguration.layoutKind === ServerLayoutKind.AUTOMATIC && this.layoutEngine) {
146-
await this.layoutEngine.layout();
149+
await this.layoutEngine.layout(layout);
147150
}
148151

149152
const root = this.serializeGModel();

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,9 @@
301301
prettier-plugin-packagejson "~2.4.6"
302302

303303
"@eclipse-glsp/protocol@next":
304-
version "2.6.0-next.6"
305-
resolved "https://registry.yarnpkg.com/@eclipse-glsp/protocol/-/protocol-2.6.0-next.6.tgz#7437694ed1e4f5ca716ba657b98af46c90abbc9a"
306-
integrity sha512-uswJrgPNb7wwRCiqyoNOkTCqdM2S+3avXuh4/vDKxyo7w05yLkblp1foEInfYIbRmqTod05K4fAtUWEkxJcg5Q==
304+
version "2.6.0-next.14"
305+
resolved "https://registry.yarnpkg.com/@eclipse-glsp/protocol/-/protocol-2.6.0-next.14.tgz#954c845feaca1484a76fc53617290bfa58ff36b9"
306+
integrity sha512-081j0/WZrUFe7/G+T2zxKRDBj0grlJ/r5pizYPP8ig7Lzq9hRqL2n1vxOoU9DUaeZcWec6MJJRm5nscomFq7IA==
307307
dependencies:
308308
sprotty-protocol "1.4.0"
309309
uuid "~10.0.0"

0 commit comments

Comments
 (0)