Skip to content

Commit

Permalink
GLSP-1429: Update to sprotty 1.3.0 (#400)
Browse files Browse the repository at this point in the history
Update to latest sprotty release
Fixes eclipse-glsp/glsp#1429
  • Loading branch information
tortmayr authored Nov 25, 2024
1 parent accf3f9 commit dd011ea
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 24 deletions.
24 changes: 17 additions & 7 deletions packages/client/src/features/export/glsp-svg-exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,41 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { ExportSvgAction, GModelRoot, RequestAction, SvgExporter } from '@eclipse-glsp/sprotty';
import {
Action,
ExportSvgAction,
ExportSvgOptions,
GModelRoot,
RequestAction,
RequestExportSvgAction,
SvgExporter
} from '@eclipse-glsp/sprotty';
import { injectable } from 'inversify';
import { v4 as uuid } from 'uuid';

@injectable()
export class GLSPSvgExporter extends SvgExporter {
override export(root: GModelRoot, request?: RequestAction<ExportSvgAction>): void {
override export(root: GModelRoot, request?: RequestExportSvgAction): void {
if (typeof document !== 'undefined') {
let svgElement = this.findSvgElement();
if (svgElement) {
svgElement = this.prepareSvgElement(svgElement, root, request);
const serializedSvg = this.createSvg(svgElement, root);
const serializedSvg = this.createSvg(svgElement, root, request?.options ?? {}, request);
const svgExport = this.getSvgExport(serializedSvg, svgElement, root, request);
// do not give request/response id here as otherwise the action is treated as an unrequested response
this.actionDispatcher.dispatch(ExportSvgAction.create(svgExport));
this.actionDispatcher.dispatch(
ExportSvgAction.create(svgExport, { responseId: request?.requestId, options: request?.options })
);
}
}
}

protected override createSvg(svgElement: SVGSVGElement, root: GModelRoot): string {
protected override createSvg(svgElement: SVGSVGElement, root: GModelRoot, options?: ExportSvgOptions, cause?: Action): string {
// createSvg requires the svg to have a non-empty id, so we generate one if necessary
const originalId = svgElement.id;
try {
svgElement.id = originalId || uuid();
return super.createSvg(svgElement, root);
return super.createSvg(svgElement, root, options, cause);
} finally {
svgElement.id = originalId;
}
Expand Down Expand Up @@ -109,7 +119,7 @@ export class GLSPSvgExporter extends SvgExporter {

protected getSvgExportStyle(svgElement: SVGElement, root: GModelRoot, request?: RequestAction<ExportSvgAction>): string | undefined {
// provide generated svg code with respective sizing for proper viewing in browser and remove undesired border
const bounds = this.getBounds(root);
const bounds = this.getBounds(root, document);
return (
`width: ${bounds.width}px !important;` +
`height: ${bounds.height}px !important;` +
Expand Down
4 changes: 2 additions & 2 deletions packages/glsp-sprotty/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"@eclipse-glsp/protocol": "2.3.0-next",
"autocompleter": "^9.1.0",
"snabbdom": "~3.5.1",
"sprotty": "1.2.0",
"sprotty-protocol": "1.2.0",
"sprotty": "1.3.0",
"sprotty-protocol": "1.3.0",
"vscode-jsonrpc": "8.2.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"watch": "tsc -w"
},
"dependencies": {
"sprotty-protocol": "1.2.0",
"sprotty-protocol": "1.3.0",
"uuid": "~10.0.0",
"vscode-jsonrpc": "8.2.0"
},
Expand Down
19 changes: 14 additions & 5 deletions packages/protocol/src/action-protocol/model-saving.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import * as sprotty from 'sprotty-protocol/lib/actions';
import { hasBooleanProp, hasStringProp } from '../utils/type-util';
import { Action, RequestAction, ResponseAction } from './base-protocol';

Expand Down Expand Up @@ -87,8 +88,9 @@ export namespace SetDirtyStateAction {
* The handler of this action is expected to retrieve the diagram SVG and should send a {@link ExportSvgAction} as response.
* Typically the {@link ExportSvgAction} is handled directly on client side.
*/
export interface RequestExportSvgAction extends RequestAction<ExportSvgAction> {
export interface RequestExportSvgAction extends RequestAction<ExportSvgAction>, sprotty.RequestExportSvgAction {
kind: typeof RequestExportSvgAction.KIND;
options?: ExportSvgOptions;
}
export namespace RequestExportSvgAction {
export const KIND = 'requestExportSvg';
Expand All @@ -97,7 +99,7 @@ export namespace RequestExportSvgAction {
return RequestAction.hasKind(object, KIND);
}

export function create(options: { requestId?: string } = {}): RequestExportSvgAction {
export function create(options: { options?: ExportSvgOptions; requestId?: string } = {}): RequestExportSvgAction {
return {
kind: KIND,
requestId: '',
Expand All @@ -106,26 +108,33 @@ export namespace RequestExportSvgAction {
}
}

/** Configuration options for the {@link RequestExportSvgAction */
export interface ExportSvgOptions extends sprotty.ExportSvgOptions {
// If set to false applied diagram styles will not be copied to the exported SVG
skipCopyStyles?: boolean;
}

/**
* The client sends an `ExportSvgAction` to indicate that the diagram, which represents the current model state,
* should be exported in SVG format. The action only provides the diagram SVG as plain string. The expected result of executing
* an `ExportSvgAction` is a new file in SVG-format on the underlying filesystem. However, other details like the target destination,
* concrete file name, file extension etc. are not specified in the protocol. So it is the responsibility of the action handler to
* process this information accordingly and export the result to the underlying filesystem.
*/
export interface ExportSvgAction extends ResponseAction {
export interface ExportSvgAction extends ResponseAction, sprotty.ExportSvgAction {
kind: typeof ExportSvgAction.KIND;
svg: string;
responseId: string;
options?: ExportSvgOptions;
}

export namespace ExportSvgAction {
export const KIND = 'exportSvg';

export function is(object: unknown): object is ExportSvgAction {
return Action.hasKind(object, KIND) && hasStringProp(object, 'svg');
}

export function create(svg: string, options: { responseId?: string } = {}): ExportSvgAction {
export function create(svg: string, options: { options?: ExportSvgOptions; responseId?: string } = {}): ExportSvgAction {
return {
kind: KIND,
svg,
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6881,21 +6881,21 @@ sprintf-js@~1.0.2:
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
integrity sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==

sprotty-protocol@1.2.0, sprotty-protocol@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/sprotty-protocol/-/sprotty-protocol-1.2.0.tgz#cfd6d637f2670a3d641997bb5add27cb1bddb57a"
integrity sha512-SHu61Qiw7bAD2nyRqdOASSihVNbeEuKI7cQx+o9EeyLpbmXKX6NTcGSVpxmWztHUIP0I6gZhKnkhF/BWo46mUQ==
sprotty-protocol@1.3.0, sprotty-protocol@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/sprotty-protocol/-/sprotty-protocol-1.3.0.tgz#78a6a69cc5eb8b94b352882a83d0f339fd828a0d"
integrity sha512-cQgKHgzVRJXbosvMsEZK4YiMSPOFhL1yYa3oLBzp9lgDL7ltYbdGCQcFqoVD6h56ObuVWyjNZu1R8YSryEkZrg==

sprotty@1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/sprotty/-/sprotty-1.2.0.tgz#6c377b36fc6d410bcb65aff0d3893076f84bc8d8"
integrity sha512-/YL1+S+pLhV+hF0Z9C4vQGuaVv9NVsDgEqRnF+vevvdbeio1w8lfGxOMKjzY7DHcVDBQoKe0kbKJXvMr3f/RsA==
sprotty@1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/sprotty/-/sprotty-1.3.0.tgz#c5ef6b3d3a6016e6c98e4d4af0a2b43cde7c417f"
integrity sha512-CFGq5po1FsQaCXx/QZjoCFYbwCrEofxAWLjxN3fJqeNmGF+CiRkHgHgXdO0OJq0o1XRgfq9ksAzYZ8Yof4Q3JA==
dependencies:
autocompleter "^9.1.2"
file-saver "^2.0.5"
inversify "~6.0.2"
snabbdom "~3.5.1"
sprotty-protocol "^1.2.0"
sprotty-protocol "^1.3.0"
tinyqueue "^2.0.3"

ssri@^10.0.0, ssri@^10.0.1:
Expand Down

0 comments on commit dd011ea

Please sign in to comment.