From c27127c5e4826d371b6369e78a8329d126312090 Mon Sep 17 00:00:00 2001 From: Alex | Kronox Date: Mon, 24 Aug 2026 15:40:36 +0200 Subject: [PATCH 1/3] add view only mode --- .../webEditor/src/startUpAgent/LoadDefaultUiExtensions.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/webEditor/src/startUpAgent/LoadDefaultUiExtensions.ts b/frontend/webEditor/src/startUpAgent/LoadDefaultUiExtensions.ts index 07ed36fb..b6b9ccd1 100644 --- a/frontend/webEditor/src/startUpAgent/LoadDefaultUiExtensions.ts +++ b/frontend/webEditor/src/startUpAgent/LoadDefaultUiExtensions.ts @@ -11,8 +11,10 @@ export class LoadDefaultUiExtensionsStartUpAgent implements IStartUpAgent { ) {} public run() { + const urlParams = new URLSearchParams(window.location.search); + const viewOnly = urlParams.get("viewOnly") === "true"; const uiVisibilityActions = this.defaultUiElements.map((e) => - SetUIExtensionVisibilityAction.create({ extensionId: e.id(), visible: true }), + SetUIExtensionVisibilityAction.create({ extensionId: e.id(), visible: !viewOnly }), ); this.actionDispatcher.dispatchAll(uiVisibilityActions); } From be666dc50cb71393446116d8c3c5ef17743b0ebe Mon Sep 17 00:00:00 2001 From: Alexander Vogt Date: Fri, 11 Sep 2026 13:24:21 +0200 Subject: [PATCH 2/3] disable keys and most mouse events in embed mode --- .../src/keyListeners/EditModeAwareKeyTool.ts | 27 +++++++++++++++++ .../keyListeners/EditModeAwareMouseTool.ts | 29 +++++++++++++++++++ .../webEditor/src/keyListeners/di.config.ts | 7 ++++- frontend/webEditor/src/settings/editorMode.ts | 12 ++++++-- .../startUpAgent/LoadDefaultUiExtensions.ts | 4 +-- 5 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 frontend/webEditor/src/keyListeners/EditModeAwareKeyTool.ts create mode 100644 frontend/webEditor/src/keyListeners/EditModeAwareMouseTool.ts diff --git a/frontend/webEditor/src/keyListeners/EditModeAwareKeyTool.ts b/frontend/webEditor/src/keyListeners/EditModeAwareKeyTool.ts new file mode 100644 index 00000000..9c08c133 --- /dev/null +++ b/frontend/webEditor/src/keyListeners/EditModeAwareKeyTool.ts @@ -0,0 +1,27 @@ +import { inject, injectable, multiInject, optional } from "inversify"; +import { KeyListener, KeyTool, SModelRootImpl, TYPES } from "sprotty"; +import { SETTINGS } from "../settings/Settings"; +import { EditorModeController } from "../settings/editorMode"; + +@injectable() +export class EditModeAwareKeyTool extends KeyTool { + constructor( + @inject(SETTINGS.Mode) + private readonly editorModeController: EditorModeController, + @multiInject(TYPES.KeyListener) @optional() keyListeners: KeyListener[] = [], + ) { + super(keyListeners); + } + + protected handleEvent( + methodName: K, + model: SModelRootImpl, + event: KeyboardEvent, + ): void { + if (this.editorModeController.get() === "embed") { + event.preventDefault(); + return; + } + super.handleEvent(methodName, model, event); + } +} diff --git a/frontend/webEditor/src/keyListeners/EditModeAwareMouseTool.ts b/frontend/webEditor/src/keyListeners/EditModeAwareMouseTool.ts new file mode 100644 index 00000000..512a9294 --- /dev/null +++ b/frontend/webEditor/src/keyListeners/EditModeAwareMouseTool.ts @@ -0,0 +1,29 @@ +import { inject, injectable, multiInject, optional } from "inversify"; +import { MouseEventKind, MouseListener, MouseTool, SModelRootImpl, TYPES } from "sprotty"; +import { SETTINGS } from "../settings/Settings"; +import { EditorModeController } from "../settings/editorMode"; + +@injectable() +export class EditModeAwareMouseTool extends MouseTool { + constructor( + @inject(SETTINGS.Mode) + private readonly editorModeController: EditorModeController, + @multiInject(TYPES.MouseListener) @optional() mouseListeners: MouseListener[] = [], + ) { + super(mouseListeners); + } + + protected handleEvent(methodName: MouseEventKind, model: SModelRootImpl, event: MouseEvent): void { + if (this.editorModeController.get() === "embed") { + const target = this.getTargetElement(model, event); + let eventShouldBeExecuted = false; + if (target?.id.startsWith("root")) eventShouldBeExecuted = true; + if (target?.type.startsWith("port") && methodName === "doubleClick") eventShouldBeExecuted = true; + if (!eventShouldBeExecuted) { + event.preventDefault(); + return; + } + } + super.handleEvent(methodName, model, event); + } +} diff --git a/frontend/webEditor/src/keyListeners/di.config.ts b/frontend/webEditor/src/keyListeners/di.config.ts index 355f85e0..991c135d 100644 --- a/frontend/webEditor/src/keyListeners/di.config.ts +++ b/frontend/webEditor/src/keyListeners/di.config.ts @@ -1,9 +1,11 @@ import { ContainerModule } from "inversify"; import { DeleteKeyListener } from "./deleteKeyListener"; -import { CenterKeyboardListener, configureCommand, TYPES } from "sprotty"; +import { CenterKeyboardListener, configureCommand, KeyTool, MouseTool, TYPES } from "sprotty"; import { CopyPasteKeyListener, PasteElementsCommand } from "./copyPasteKeyListener"; import { SerializeKeyListener } from "./serializeKeyListener"; import { FitToScreenKeyListener } from "./fitToScreenKeyListener"; +import { EditModeAwareKeyTool } from "./EditModeAwareKeyTool"; +import { EditModeAwareMouseTool } from "./EditModeAwareMouseTool"; export const keyListenerModule = new ContainerModule((bind, unbind, isBound, rebind) => { bind(DeleteKeyListener).toSelf().inSingletonScope(); @@ -17,4 +19,7 @@ export const keyListenerModule = new ContainerModule((bind, unbind, isBound, reb bind(FitToScreenKeyListener).toSelf().inSingletonScope(); rebind(CenterKeyboardListener).toService(FitToScreenKeyListener); + + rebind(KeyTool).to(EditModeAwareKeyTool).inSingletonScope(); + rebind(MouseTool).to(EditModeAwareMouseTool).inSingletonScope(); }); diff --git a/frontend/webEditor/src/settings/editorMode.ts b/frontend/webEditor/src/settings/editorMode.ts index db4a19f0..1ca3c0dc 100644 --- a/frontend/webEditor/src/settings/editorMode.ts +++ b/frontend/webEditor/src/settings/editorMode.ts @@ -1,16 +1,24 @@ import { SettingsValue } from "./SettingsValue"; -export type EditorMode = "edit" | "view"; +export type EditorMode = "edit" | "view" | "embed"; export class EditorModeController extends SettingsValue { constructor() { - super("edit"); + super(new URLSearchParams(window.location.search).get("embed") === "true" ? "embed" : "edit"); } setDefault(): void { this.set("edit"); } + set(newValue: EditorMode): void { + // changing it is not allowed in embed mode + if (this.get() === "embed") { + return; + } + super.set(newValue); + } + isReadOnly(): boolean { return this.get() !== "edit"; } diff --git a/frontend/webEditor/src/startUpAgent/LoadDefaultUiExtensions.ts b/frontend/webEditor/src/startUpAgent/LoadDefaultUiExtensions.ts index b6b9ccd1..677a5b20 100644 --- a/frontend/webEditor/src/startUpAgent/LoadDefaultUiExtensions.ts +++ b/frontend/webEditor/src/startUpAgent/LoadDefaultUiExtensions.ts @@ -12,9 +12,9 @@ export class LoadDefaultUiExtensionsStartUpAgent implements IStartUpAgent { public run() { const urlParams = new URLSearchParams(window.location.search); - const viewOnly = urlParams.get("viewOnly") === "true"; + const embedMode = urlParams.get("embed") === "true"; const uiVisibilityActions = this.defaultUiElements.map((e) => - SetUIExtensionVisibilityAction.create({ extensionId: e.id(), visible: !viewOnly }), + SetUIExtensionVisibilityAction.create({ extensionId: e.id(), visible: !embedMode }), ); this.actionDispatcher.dispatchAll(uiVisibilityActions); } From f20d52e031647995d73b34a3da5f7dc0f915352d Mon Sep 17 00:00:00 2001 From: Alexander Vogt Date: Thu, 17 Sep 2026 10:05:24 +0200 Subject: [PATCH 3/3] fix annotations not showing --- frontend/webEditor/src/keyListeners/EditModeAwareMouseTool.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/webEditor/src/keyListeners/EditModeAwareMouseTool.ts b/frontend/webEditor/src/keyListeners/EditModeAwareMouseTool.ts index 512a9294..45061759 100644 --- a/frontend/webEditor/src/keyListeners/EditModeAwareMouseTool.ts +++ b/frontend/webEditor/src/keyListeners/EditModeAwareMouseTool.ts @@ -19,6 +19,7 @@ export class EditModeAwareMouseTool extends MouseTool { let eventShouldBeExecuted = false; if (target?.id.startsWith("root")) eventShouldBeExecuted = true; if (target?.type.startsWith("port") && methodName === "doubleClick") eventShouldBeExecuted = true; + if (methodName === "mouseMove") eventShouldBeExecuted = true; if (!eventShouldBeExecuted) { event.preventDefault(); return;