@eclipse-glsp/vscode-integration-webview 1.1.0-next.e3c23fc.57 → 1.1.0-next.e5a109d.70

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.
Files changed (80) hide show
  1. package/README.md +1 -0
  2. package/lib/default-modules.d.ts +19 -0
  3. package/lib/default-modules.d.ts.map +1 -0
  4. package/lib/default-modules.js +27 -0
  5. package/lib/default-modules.js.map +1 -0
  6. package/lib/diagram-identifier.d.ts +0 -17
  7. package/lib/diagram-identifier.d.ts.map +1 -1
  8. package/lib/diagram-identifier.js +1 -1
  9. package/lib/diagram-identifier.js.map +1 -1
  10. package/lib/{copy-paste-handler-provider.js → features/copyPaste/copy-paste-module.d.ts} +4 -6
  11. package/lib/features/copyPaste/copy-paste-module.d.ts.map +1 -0
  12. package/lib/features/copyPaste/copy-paste-module.js +28 -0
  13. package/lib/features/copyPaste/copy-paste-module.js.map +1 -0
  14. package/lib/{copy-paste-handler-provider.d.ts → features/copyPaste/copy-paste-startup.d.ts} +10 -3
  15. package/lib/features/copyPaste/copy-paste-startup.d.ts.map +1 -0
  16. package/lib/features/copyPaste/copy-paste-startup.js +56 -0
  17. package/lib/features/copyPaste/copy-paste-startup.js.map +1 -0
  18. package/lib/{services.d.ts → features/default/default-module.d.ts} +4 -10
  19. package/lib/features/default/default-module.d.ts.map +1 -0
  20. package/lib/features/default/default-module.js +30 -0
  21. package/lib/features/default/default-module.js.map +1 -0
  22. package/lib/{extension-action-handler.d.ts → features/default/extension-action-handler.d.ts} +16 -9
  23. package/lib/features/default/extension-action-handler.d.ts.map +1 -0
  24. package/lib/features/default/extension-action-handler.js +85 -0
  25. package/lib/features/default/extension-action-handler.js.map +1 -0
  26. package/lib/features/default/vscode-glsp-modelsource.d.ts +40 -0
  27. package/lib/features/default/vscode-glsp-modelsource.d.ts.map +1 -0
  28. package/lib/features/default/vscode-glsp-modelsource.js +68 -0
  29. package/lib/features/default/vscode-glsp-modelsource.js.map +1 -0
  30. package/lib/features/export/export-module.d.ts +18 -0
  31. package/lib/features/export/export-module.d.ts.map +1 -0
  32. package/lib/features/export/export-module.js +24 -0
  33. package/lib/features/export/export-module.js.map +1 -0
  34. package/lib/features/navigation/navigation-module.d.ts +18 -0
  35. package/lib/features/navigation/navigation-module.d.ts.map +1 -0
  36. package/lib/features/navigation/navigation-module.js +24 -0
  37. package/lib/features/navigation/navigation-module.js.map +1 -0
  38. package/lib/glsp-diagram-widget.d.ts +8 -11
  39. package/lib/glsp-diagram-widget.d.ts.map +1 -1
  40. package/lib/glsp-diagram-widget.js +20 -68
  41. package/lib/glsp-diagram-widget.js.map +1 -1
  42. package/lib/glsp-starter.d.ts +39 -10
  43. package/lib/glsp-starter.d.ts.map +1 -1
  44. package/lib/glsp-starter.js +44 -62
  45. package/lib/glsp-starter.js.map +1 -1
  46. package/lib/index.d.ts +8 -4
  47. package/lib/index.d.ts.map +1 -1
  48. package/lib/index.js +23 -19
  49. package/lib/index.js.map +1 -1
  50. package/lib/webview-glsp-client.d.ts +56 -0
  51. package/lib/webview-glsp-client.d.ts.map +1 -0
  52. package/lib/webview-glsp-client.js +103 -0
  53. package/lib/webview-glsp-client.js.map +1 -0
  54. package/package.json +4 -3
  55. package/src/default-modules.ts +27 -0
  56. package/src/diagram-identifier.ts +1 -2
  57. package/src/features/copyPaste/copy-paste-module.ts +39 -0
  58. package/src/features/copyPaste/copy-paste-startup.ts +50 -0
  59. package/src/features/default/default-module.ts +31 -0
  60. package/src/{extension-action-handler.ts → features/default/extension-action-handler.ts} +39 -12
  61. package/src/features/default/vscode-glsp-modelsource.ts +63 -0
  62. package/src/{services.ts → features/export/export-module.ts} +6 -10
  63. package/src/{copy-paste-handler-provider.ts → features/navigation/navigation-module.ts} +6 -8
  64. package/src/glsp-diagram-widget.ts +22 -79
  65. package/src/glsp-starter.ts +57 -80
  66. package/src/index.ts +9 -4
  67. package/src/webview-glsp-client.ts +132 -0
  68. package/lib/copy-paste-handler-provider.d.ts.map +0 -1
  69. package/lib/copy-paste-handler-provider.js.map +0 -1
  70. package/lib/extension-action-handler.d.ts.map +0 -1
  71. package/lib/extension-action-handler.js +0 -30
  72. package/lib/extension-action-handler.js.map +0 -1
  73. package/lib/glsp-vscode-diagramserver.d.ts +0 -39
  74. package/lib/glsp-vscode-diagramserver.d.ts.map +0 -1
  75. package/lib/glsp-vscode-diagramserver.js +0 -126
  76. package/lib/glsp-vscode-diagramserver.js.map +0 -1
  77. package/lib/services.d.ts.map +0 -1
  78. package/lib/services.js +0 -5
  79. package/lib/services.js.map +0 -1
  80. package/src/glsp-vscode-diagramserver.ts +0 -131
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ /********************************************************************************
3
+ * Copyright (c) 2023 EclipseSource and others.
4
+ *
5
+ * This program and the accompanying materials are made available under the
6
+ * terms of the Eclipse Public License v. 2.0 which is available at
7
+ * http://www.eclipse.org/legal/epl-2.0.
8
+ *
9
+ * This Source Code may also be made available under the following Secondary
10
+ * Licenses when the conditions for such availability set forth in the Eclipse
11
+ * Public License v. 2.0 are satisfied: GNU General Public License, version 2
12
+ * with the GNU Classpath Exception which is available at
13
+ * https://www.gnu.org/software/classpath/license.html.
14
+ *
15
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
+ ********************************************************************************/
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.WebviewGlspClient = exports.StopRequest = exports.ShutdownServerNotification = exports.DisposeClientSessionRequest = exports.InitializeClientSessionRequest = exports.InitializeServerRequest = exports.StartRequest = exports.ActionMessageNotification = void 0;
19
+ const client_1 = require("@eclipse-glsp/client");
20
+ const vscode_messenger_common_1 = require("vscode-messenger-common");
21
+ const vscode_messenger_webview_1 = require("vscode-messenger-webview");
22
+ exports.ActionMessageNotification = { method: 'actionMessage' };
23
+ exports.StartRequest = { method: 'start' };
24
+ exports.InitializeServerRequest = { method: 'initializeServer' };
25
+ exports.InitializeClientSessionRequest = { method: 'initializeClientSession' };
26
+ exports.DisposeClientSessionRequest = { method: 'disposeClientSession' };
27
+ exports.ShutdownServerNotification = { method: 'shutdownServer' };
28
+ exports.StopRequest = { method: 'stop' };
29
+ /**
30
+ * GLSP client implementation for the diagram webview. This is proxy implementation
31
+ * that communicates with the actual GLSP client running in the host extension.
32
+ * via the vscode-messenger protocol
33
+ */
34
+ class WebviewGlspClient {
35
+ get currentState() {
36
+ return this._currentState;
37
+ }
38
+ get initializeResult() {
39
+ return this._initializeResult;
40
+ }
41
+ get onServerInitialized() {
42
+ return this.onServerInitializedEmitter.event;
43
+ }
44
+ constructor(options) {
45
+ var _a;
46
+ this.toDispose = new client_1.DisposableCollection();
47
+ this.onActionMessageEmitter = new client_1.Emitter();
48
+ this._currentState = client_1.ClientState.Starting;
49
+ this.onServerInitializedEmitter = new client_1.Emitter();
50
+ this.id = options.id;
51
+ this.messenger = (_a = options.messenger) !== null && _a !== void 0 ? _a : new vscode_messenger_webview_1.Messenger();
52
+ this.toDispose.push(this.onActionMessageEmitter, this.onServerInitializedEmitter);
53
+ this.messenger.onNotification(exports.ActionMessageNotification, msg => this.onActionMessageEmitter.fire(msg));
54
+ }
55
+ async start() {
56
+ try {
57
+ this._currentState = client_1.ClientState.Starting;
58
+ await this.messenger.sendRequest(exports.StartRequest, vscode_messenger_common_1.HOST_EXTENSION);
59
+ this._currentState = client_1.ClientState.Running;
60
+ }
61
+ catch (error) {
62
+ console.error('Failed to start connection to server', error);
63
+ this._currentState = client_1.ClientState.StartFailed;
64
+ }
65
+ }
66
+ async initializeServer(params) {
67
+ if (this.initializeResult) {
68
+ return this.initializeResult;
69
+ }
70
+ const result = await this.messenger.sendRequest(exports.InitializeServerRequest, vscode_messenger_common_1.HOST_EXTENSION, params);
71
+ this._initializeResult = result;
72
+ this.onServerInitializedEmitter.fire(result);
73
+ return result;
74
+ }
75
+ initializeClientSession(params) {
76
+ return this.messenger.sendRequest(exports.InitializeClientSessionRequest, vscode_messenger_common_1.HOST_EXTENSION, params);
77
+ }
78
+ disposeClientSession(params) {
79
+ return this.messenger.sendRequest(exports.DisposeClientSessionRequest, vscode_messenger_common_1.HOST_EXTENSION, params);
80
+ }
81
+ shutdownServer() {
82
+ this.messenger.sendNotification(exports.ShutdownServerNotification, vscode_messenger_common_1.HOST_EXTENSION);
83
+ }
84
+ async stop() {
85
+ if (this._currentState === client_1.ClientState.Stopped) {
86
+ return;
87
+ }
88
+ this._currentState = client_1.ClientState.Stopping;
89
+ await this.messenger.sendRequest(exports.StopRequest, vscode_messenger_common_1.HOST_EXTENSION);
90
+ this._currentState = client_1.ClientState.Stopped;
91
+ }
92
+ sendActionMessage(message) {
93
+ this.messenger.sendNotification(exports.ActionMessageNotification, vscode_messenger_common_1.HOST_EXTENSION, message);
94
+ }
95
+ onActionMessage(handler) {
96
+ return this.onActionMessageEmitter.event(handler);
97
+ }
98
+ dispose() {
99
+ this.toDispose.dispose();
100
+ }
101
+ }
102
+ exports.WebviewGlspClient = WebviewGlspClient;
103
+ //# sourceMappingURL=webview-glsp-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webview-glsp-client.js","sourceRoot":"","sources":["../src/webview-glsp-client.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;;AAElF,iDAc8B;AAC9B,qEAAwF;AACxF,uEAAqD;AAMxC,QAAA,yBAAyB,GAAoC,EAAE,MAAM,EAAE,eAAe,EAAE,CAAC;AACzF,QAAA,YAAY,GAAiC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;AACjE,QAAA,uBAAuB,GAAwD,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAC;AAC9G,QAAA,8BAA8B,GAAyD,EAAE,MAAM,EAAE,yBAAyB,EAAE,CAAC;AAC7H,QAAA,2BAA2B,GAAsD,EAAE,MAAM,EAAE,sBAAsB,EAAE,CAAC;AACpH,QAAA,0BAA0B,GAA2B,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC;AAClF,QAAA,WAAW,GAAiC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C,CAAC;IACxF,CAAC;IAED,eAAe,CAAC,OAA6B;QACzC,OAAO,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACtD,CAAC;IAED,OAAO;QACH,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;CACJ;AAjFD,8CAiFC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eclipse-glsp/vscode-integration-webview",
3
- "version": "1.1.0-next.e3c23fc.57+e3c23fc",
3
+ "version": "1.1.0-next.e5a109d.70+e5a109d",
4
4
  "description": "Integration of a GLSP diagram in a VS Code extensions (WebView part)",
5
5
  "keywords": [
6
6
  "vscode",
@@ -42,7 +42,8 @@
42
42
  "watch": "tsc -w"
43
43
  },
44
44
  "dependencies": {
45
- "@eclipse-glsp/client": "next"
45
+ "@eclipse-glsp/client": "next",
46
+ "vscode-messenger-webview": "^0.4.5"
46
47
  },
47
48
  "devDependencies": {
48
49
  "reflect-metadata": "^0.1.13"
@@ -50,5 +51,5 @@
50
51
  "publishConfig": {
51
52
  "access": "public"
52
53
  },
53
- "gitHead": "e3c23fc733d533d348aed257544446409b95192d"
54
+ "gitHead": "e5a109d5721e55b0a67a4193b1742014c16d3414"
54
55
  }
@@ -0,0 +1,27 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2023 EclipseSource 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 { ModuleConfiguration } from '@eclipse-glsp/client';
18
+ import { vscodeCopyPasteModule } from './features/copyPaste/copy-paste-module';
19
+ import { vscodeDefaultModule } from './features/default/default-module';
20
+ import { vscodeExportModule } from './features/export/export-module';
21
+ import { vscodeNavigationModule } from './features/navigation/navigation-module';
22
+
23
+ export const VSCODE_DEFAULT_MODULES = [vscodeDefaultModule, vscodeCopyPasteModule, vscodeExportModule, vscodeNavigationModule] as const;
24
+
25
+ export const VSCODE_DEFAULT_MODULE_CONFIG: ModuleConfiguration = {
26
+ add: [...VSCODE_DEFAULT_MODULES]
27
+ };
@@ -13,7 +13,7 @@
13
13
  *
14
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  ********************************************************************************/
16
- import { AnyObject, hasStringProp, InitializeResult } from '@eclipse-glsp/client';
16
+ import { AnyObject, hasStringProp } from '@eclipse-glsp/client';
17
17
 
18
18
  export const GLSPDiagramIdentifier = Symbol('GLSPDiagramIdentifier');
19
19
 
@@ -21,7 +21,6 @@ export interface GLSPDiagramIdentifier {
21
21
  clientId: string;
22
22
  diagramType: string;
23
23
  uri: string;
24
- initializeResult?: InitializeResult;
25
24
  }
26
25
 
27
26
  export function isDiagramIdentifier(object: any): object is GLSPDiagramIdentifier {
@@ -0,0 +1,39 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2023 EclipseSource 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 {
18
+ FeatureModule,
19
+ ICopyPasteHandler,
20
+ RequestClipboardDataAction,
21
+ SetClipboardDataAction,
22
+ TYPES,
23
+ bindAsService,
24
+ copyPasteModule
25
+ } from '@eclipse-glsp/client';
26
+ import { ExtensionActionKind } from '../default/extension-action-handler';
27
+ import { CopyPasteHandlerProvider, CopyPasteStartup } from './copy-paste-startup';
28
+
29
+ export const vscodeCopyPasteModule = new FeatureModule(
30
+ bind => {
31
+ bind(CopyPasteHandlerProvider).toProvider(
32
+ ctx => () => new Promise<ICopyPasteHandler>(resolve => resolve(ctx.container.get<ICopyPasteHandler>(TYPES.ICopyPasteHandler)))
33
+ );
34
+ bindAsService(bind, TYPES.IDiagramStartup, CopyPasteStartup);
35
+ bind(ExtensionActionKind).toConstantValue(RequestClipboardDataAction.KIND);
36
+ bind(ExtensionActionKind).toConstantValue(SetClipboardDataAction.KIND);
37
+ },
38
+ { requires: copyPasteModule }
39
+ );
@@ -0,0 +1,50 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2023 EclipseSource 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 { ICopyPasteHandler, IDiagramStartup, MaybePromise } from '@eclipse-glsp/client';
18
+ import { inject, injectable } from 'inversify';
19
+
20
+ export const CopyPasteHandlerProvider = Symbol('CopyPasteHandlerProvider');
21
+ /**
22
+ * Service identifier and type definition to bind the {@link ICopyPasteHandler} to an provider.
23
+ * This enables asynchronous injections and can be used to bypass circular dependency issues.
24
+ */
25
+ export type CopyPasteHandlerProvider = () => Promise<ICopyPasteHandler>;
26
+
27
+ /**
28
+ * Startup service to hook up the copy&paste event handler
29
+ */
30
+ @injectable()
31
+ export class CopyPasteStartup implements IDiagramStartup {
32
+ @inject(CopyPasteHandlerProvider)
33
+ protected copyPasteHandlerProvider: CopyPasteHandlerProvider;
34
+
35
+ preInitialize(): MaybePromise<void> {
36
+ this.copyPasteHandlerProvider().then(copyPasteHandler => {
37
+ document.addEventListener('copy', (e: ClipboardEvent) => {
38
+ copyPasteHandler.handleCopy(e);
39
+ });
40
+
41
+ document.addEventListener('cut', (e: ClipboardEvent) => {
42
+ copyPasteHandler.handleCut(e);
43
+ });
44
+
45
+ document.addEventListener('paste', (e: ClipboardEvent) => {
46
+ copyPasteHandler.handlePaste(e);
47
+ });
48
+ });
49
+ }
50
+ }
@@ -0,0 +1,31 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2023 EclipseSource 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 { FeatureModule, GLSPModelSource, TYPES, bindAsService, defaultModule } from '@eclipse-glsp/client';
18
+ import { GLSPDiagramWidget, GLSPDiagramWidgetFactory } from '../../glsp-diagram-widget';
19
+ import { HostExtensionActionHandler } from './extension-action-handler';
20
+ import { VsCodeGLSPModelSource } from './vscode-glsp-modelsource';
21
+
22
+ export const vscodeDefaultModule = new FeatureModule(
23
+ (bind, _unbind, _isBound, rebind) => {
24
+ bind(GLSPDiagramWidget).toSelf().inSingletonScope();
25
+ bind(GLSPDiagramWidgetFactory).toFactory(context => () => context.container.get<GLSPDiagramWidget>(GLSPDiagramWidget));
26
+ bind(VsCodeGLSPModelSource).toSelf().inSingletonScope();
27
+ rebind(GLSPModelSource).toService(VsCodeGLSPModelSource);
28
+ bindAsService(bind, TYPES.IActionHandlerInitializer, HostExtensionActionHandler);
29
+ },
30
+ { requires: defaultModule }
31
+ );
@@ -13,21 +13,48 @@
13
13
  *
14
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  ********************************************************************************/
16
- import { Action, ActionHandlerRegistry, IActionHandler, IActionHandlerInitializer, ICommand } from '@eclipse-glsp/client';
17
- import { GLSPDiagramIdentifier } from './diagram-identifier';
18
- import { VsCodeApi } from './services';
16
+ import {
17
+ Action,
18
+ ActionHandlerRegistry,
19
+ GLSPClient,
20
+ IActionHandler,
21
+ IActionHandlerInitializer,
22
+ ICommand,
23
+ IDiagramOptions,
24
+ TYPES
25
+ } from '@eclipse-glsp/client';
26
+ import { inject, injectable, multiInject, optional, postConstruct } from 'inversify';
19
27
 
20
28
  /**
21
- * Delegates actions that should be handled inside of the glsp vscode extension instead
29
+ * Service identifier to define action kinds that should be delegated to the vscode extension.
30
+ *
31
+ * Usage:
32
+ * ```ts
33
+ * bind(ExtensionActionKind).toConstantValue(SomeAction.KIND)
34
+ * ```
35
+ */
36
+ export const ExtensionActionKind = Symbol('ExtensionActionKind');
37
+
38
+ /**
39
+ * Delegates actions that should be handled inside of the glsp host extension instead
22
40
  * of the webview. This enables the implementation of action handlers that require access
23
41
  * to the vscode API and/or node backend.
24
42
  */
25
- export class GLSPVscodeExtensionActionHandler implements IActionHandler, IActionHandlerInitializer {
26
- constructor(
27
- protected readonly actionKinds: string[],
28
- protected readonly diagramIdentifier: GLSPDiagramIdentifier,
29
- protected vscodeApi: VsCodeApi
30
- ) {}
43
+ @injectable()
44
+ export class HostExtensionActionHandler implements IActionHandler, IActionHandlerInitializer {
45
+ @multiInject(ExtensionActionKind)
46
+ @optional()
47
+ protected actionKinds: string[] = [];
48
+
49
+ @inject(TYPES.IDiagramOptions)
50
+ protected diagramOptions: IDiagramOptions;
51
+
52
+ protected glspClient?: GLSPClient;
53
+
54
+ @postConstruct()
55
+ protected postConstruct(): void {
56
+ this.diagramOptions.glspClientProvider().then(glspClient => (this.glspClient = glspClient));
57
+ }
31
58
 
32
59
  initialize(registry: ActionHandlerRegistry): void {
33
60
  this.actionKinds.forEach(kind => registry.register(kind, this));
@@ -36,11 +63,11 @@ export class GLSPVscodeExtensionActionHandler implements IActionHandler, IAction
36
63
  handle(action: Action): void | Action | ICommand {
37
64
  if (this.actionKinds.includes(action.kind)) {
38
65
  const message = {
39
- clientId: this.diagramIdentifier.clientId,
66
+ clientId: this.diagramOptions.clientId,
40
67
  action,
41
68
  __localDispatch: true
42
69
  };
43
- this.vscodeApi.postMessage(message);
70
+ this.glspClient?.sendActionMessage(message);
44
71
  }
45
72
  }
46
73
  }
@@ -0,0 +1,63 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2023 EclipseSource 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 { Action, ActionMessage, GLSPModelSource, ServerAction } from '@eclipse-glsp/client';
17
+ import { injectable } from 'inversify';
18
+
19
+ /**
20
+ * A helper interface that allows the webview to mark actions that have been received directly from the vscode extension
21
+ * (i.e. they are not forwarded to the GLSP Server).
22
+ */
23
+ export interface ExtensionAction extends Action {
24
+ __localDispatch: true;
25
+ }
26
+
27
+ export namespace ExtensionAction {
28
+ export function is(object: unknown): object is ExtensionAction {
29
+ return Action.is(object) && '__localDispatch' in object && object.__localDispatch === true;
30
+ }
31
+
32
+ /**
33
+ * Mark the given action as {@link ServerAction} by attaching the "_receivedFromServer" property
34
+ * @param action The action that should be marked as server action
35
+ */
36
+ export function mark(action: Action): void {
37
+ (action as ExtensionAction).__localDispatch = true;
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Customization of the default {@link GLSPModelSource} for the vscode integration.
43
+ * Also takes locally dispatched actions (i.e. actions that are originating from or intended for the host extension) into consideration.
44
+ */
45
+ @injectable()
46
+ export class VsCodeGLSPModelSource extends GLSPModelSource {
47
+ protected override messageReceived(message: ActionMessage): void {
48
+ if (this.clientId !== message.clientId) {
49
+ return;
50
+ }
51
+ this.checkMessageOrigin(message);
52
+ const action = message.action;
53
+ this.logger.log(this, 'receiving', action);
54
+ this.actionDispatcher.dispatch(action);
55
+ }
56
+
57
+ protected checkMessageOrigin(message: ActionMessage): void {
58
+ const isLocalDispatch = (message as any)['__localDispatch'] ?? false;
59
+ if (!isLocalDispatch) {
60
+ ServerAction.mark(message.action);
61
+ }
62
+ }
63
+ }
@@ -1,6 +1,5 @@
1
1
  /********************************************************************************
2
- * Copyright (c) 2022 TypeFox and others.
3
- * Modifications: 2023 EclipseSource and others.
2
+ * Copyright (c) 2023 EclipseSource and others.
4
3
  *
5
4
  * This program and the accompanying materials are made available under the
6
5
  * terms of the Eclipse Public License v. 2.0 which is available at
@@ -14,13 +13,10 @@
14
13
  *
15
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
15
  ********************************************************************************/
17
- // based on https://github.com/eclipse-sprotty/sprotty-vscode/blob/v0.3.0/sprotty-vscode-webview/src/services.ts
18
- export interface VsCodeApi {
19
- postMessage: (message: any) => void;
20
- }
21
16
 
22
- export const VsCodeApi = Symbol('VsCodeApi');
17
+ import { ExportSvgAction, FeatureModule } from '@eclipse-glsp/client';
18
+ import { ExtensionActionKind } from '../default/extension-action-handler';
23
19
 
24
- export interface GLSPStarterServices {
25
- vscodeApi?: VsCodeApi;
26
- }
20
+ export const vscodeExportModule = new FeatureModule(bind => {
21
+ bind(ExtensionActionKind).toConstantValue(ExportSvgAction.KIND);
22
+ });
@@ -1,5 +1,5 @@
1
1
  /********************************************************************************
2
- * Copyright (c) 2022 EclipseSource and others.
2
+ * Copyright (c) 2023 EclipseSource and others.
3
3
  *
4
4
  * This program and the accompanying materials are made available under the
5
5
  * terms of the Eclipse Public License v. 2.0 which is available at
@@ -14,11 +14,9 @@
14
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  ********************************************************************************/
16
16
 
17
- import { ICopyPasteHandler } from '@eclipse-glsp/client';
17
+ import { FeatureModule, NavigateToExternalTargetAction, navigationModule } from '@eclipse-glsp/client';
18
+ import { ExtensionActionKind } from '../default/extension-action-handler';
18
19
 
19
- export const CopyPasteHandlerProvider = Symbol('CopyPasteHandlerProvider');
20
- /**
21
- * Service identifier and type definition to bind the {@link ICopyPasteHandler} to an provider.
22
- * This enables asynchronous injections and can be used to bypass circular dependency issues.
23
- */
24
- export type CopyPasteHandlerProvider = () => Promise<ICopyPasteHandler>;
20
+ export const vscodeNavigationModule = new FeatureModule(bind => {
21
+ bind(ExtensionActionKind).toConstantValue(NavigateToExternalTargetAction.KIND);
22
+ }, navigationModule);
@@ -16,44 +16,48 @@
16
16
  ********************************************************************************/
17
17
  // based on https://github.com/eclipse-sprotty/sprotty-vscode/blob/v0.3.0/sprotty-vscode-webview/src/vscode-diagram-widget.ts
18
18
  import {
19
- DiagramServerProxy,
20
- EnableToolPaletteAction,
19
+ DiagramLoader,
20
+ DiagramLoadingOptions,
21
21
  IActionDispatcher,
22
+ IDiagramOptions,
22
23
  ModelSource,
23
- RequestModelAction,
24
- RequestTypeHintsAction,
25
- ServerStatusAction,
26
24
  TYPES,
27
25
  ViewerOptions
28
26
  } from '@eclipse-glsp/client';
29
27
  import { inject, injectable, postConstruct } from 'inversify';
30
- import { GLSPDiagramIdentifier } from './diagram-identifier';
31
28
 
32
29
  export const GLSPDiagramWidgetFactory = Symbol('GLSPDiagramWidgetFactory');
33
30
  export type GLSPDiagramWidgetFactory = () => GLSPDiagramWidget;
34
31
 
35
32
  @injectable()
36
33
  export abstract class GLSPDiagramWidget {
37
- @inject(GLSPDiagramIdentifier)
38
- protected diagramIdentifier: GLSPDiagramIdentifier;
39
34
  @inject(TYPES.IActionDispatcher)
40
- readonly actionDispatcher: IActionDispatcher;
35
+ protected actionDispatcher: IActionDispatcher;
36
+
41
37
  @inject(TYPES.ModelSource)
42
- readonly modelSource: ModelSource;
38
+ protected modelSource: ModelSource;
39
+
40
+ @inject(TYPES.IDiagramOptions)
41
+ protected diagramOptions: IDiagramOptions;
42
+
43
43
  @inject(TYPES.ViewerOptions)
44
44
  protected viewerOptions: ViewerOptions;
45
45
 
46
- protected statusIconDiv: HTMLDivElement;
47
- protected statusMessageDiv: HTMLDivElement;
46
+ @inject(DiagramLoader)
47
+ protected diagramLoader: DiagramLoader;
48
+
49
+ get clientId(): string {
50
+ return this.diagramOptions.clientId;
51
+ }
48
52
 
49
53
  @postConstruct()
50
54
  initialize(): void {
51
55
  this.initializeHtml();
52
- this.dispatchInitialActions();
56
+ this.loadDiagram();
53
57
  }
54
58
 
55
59
  protected initializeHtml(): void {
56
- const containerDiv = document.getElementById(this.diagramIdentifier.clientId + '_container');
60
+ const containerDiv = document.getElementById(this.clientId + '_container');
57
61
  if (containerDiv) {
58
62
  const svgContainer = document.createElement('div');
59
63
  svgContainer.id = this.viewerOptions.baseDiv;
@@ -62,75 +66,14 @@ export abstract class GLSPDiagramWidget {
62
66
  const hiddenContainer = document.createElement('div');
63
67
  hiddenContainer.id = this.viewerOptions.hiddenDiv;
64
68
  document.body.appendChild(hiddenContainer);
65
-
66
- const statusDiv = document.createElement('div');
67
- statusDiv.setAttribute('class', 'sprotty-status');
68
- containerDiv.appendChild(statusDiv);
69
-
70
- this.statusIconDiv = document.createElement('div');
71
- statusDiv.appendChild(this.statusIconDiv);
72
-
73
- this.statusMessageDiv = document.createElement('div');
74
- this.statusMessageDiv.setAttribute('class', 'sprotty-status-message');
75
- statusDiv.appendChild(this.statusMessageDiv);
76
69
  }
77
70
  }
78
71
 
79
- dispatchInitialActions(): void {
80
- if (this.modelSource instanceof DiagramServerProxy) {
81
- this.modelSource.clientId = this.diagramIdentifier.clientId;
82
- }
83
- this.actionDispatcher.dispatch(
84
- RequestModelAction.create({
85
- options: {
86
- sourceUri: decodeURI(this.diagramIdentifier.uri),
87
- diagramType: this.diagramIdentifier.diagramType
88
- }
89
- })
90
- );
91
-
92
- this.actionDispatcher.dispatch(RequestTypeHintsAction.create());
93
- this.actionDispatcher.dispatch(EnableToolPaletteAction.create());
94
- }
95
-
96
- setStatus(status: ServerStatusAction): void {
97
- this.statusMessageDiv.textContent = status.message;
98
- this.removeClasses(this.statusMessageDiv, 1);
99
- this.statusMessageDiv.classList.add(status.severity.toLowerCase());
100
- this.removeClasses(this.statusIconDiv, 0);
101
- const classes = this.statusIconDiv.classList;
102
- classes.add(status.severity.toLowerCase());
103
- switch (status.severity) {
104
- case 'FATAL':
105
- classes.add('fa');
106
- classes.add('fa-times-circle');
107
- break;
108
- case 'ERROR':
109
- classes.add('fa');
110
- classes.add('fa-exclamation-circle');
111
- break;
112
- case 'WARNING':
113
- classes.add('fa');
114
- classes.add('fa-exclamation-circle');
115
- break;
116
- case 'INFO':
117
- classes.add('fa');
118
- classes.add('fa-info-circle');
119
- break;
120
- }
72
+ protected createDiagramLoadingOptions(): DiagramLoadingOptions | undefined {
73
+ return undefined;
121
74
  }
122
75
 
123
- protected removeClasses(element: Element, keep: number): void {
124
- const classes = element.classList;
125
- while (classes.length > keep) {
126
- const item = classes.item(classes.length - 1);
127
- if (item) {
128
- classes.remove(item);
129
- }
130
- }
76
+ loadDiagram(): Promise<void> {
77
+ return this.diagramLoader.load(this.createDiagramLoadingOptions());
131
78
  }
132
79
  }
133
-
134
- export function decodeURI(uri: string): string {
135
- return decodeURIComponent(uri.replace(/\+/g, ' '));
136
- }