diff --git a/packages/client/src/features/export/glsp-svg-exporter.ts b/packages/client/src/features/export/glsp-svg-exporter.ts index 86d61d61..849bbb13 100644 --- a/packages/client/src/features/export/glsp-svg-exporter.ts +++ b/packages/client/src/features/export/glsp-svg-exporter.ts @@ -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): 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; } @@ -109,7 +119,7 @@ export class GLSPSvgExporter extends SvgExporter { protected getSvgExportStyle(svgElement: SVGElement, root: GModelRoot, request?: RequestAction): 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;` + diff --git a/packages/glsp-sprotty/package.json b/packages/glsp-sprotty/package.json index 4d0a3530..8d2d22c0 100644 --- a/packages/glsp-sprotty/package.json +++ b/packages/glsp-sprotty/package.json @@ -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": { diff --git a/packages/protocol/package.json b/packages/protocol/package.json index e8c6828f..c7a87e76 100644 --- a/packages/protocol/package.json +++ b/packages/protocol/package.json @@ -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" }, diff --git a/packages/protocol/src/action-protocol/model-saving.ts b/packages/protocol/src/action-protocol/model-saving.ts index 6d225fa5..cb5ae635 100644 --- a/packages/protocol/src/action-protocol/model-saving.ts +++ b/packages/protocol/src/action-protocol/model-saving.ts @@ -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'; @@ -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 { +export interface RequestExportSvgAction extends RequestAction, sprotty.RequestExportSvgAction { kind: typeof RequestExportSvgAction.KIND; + options?: ExportSvgOptions; } export namespace RequestExportSvgAction { export const KIND = 'requestExportSvg'; @@ -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: '', @@ -106,6 +108,12 @@ 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 @@ -113,11 +121,12 @@ export namespace RequestExportSvgAction { * 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'; @@ -125,7 +134,7 @@ export namespace 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, diff --git a/yarn.lock b/yarn.lock index 5bb3d037..0062d906 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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: