@eclipse-glsp/vscode-integration-webview 1.1.0-next.ef526c6.51 → 2.0.0

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 (89) hide show
  1. package/README.md +1 -1
  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 +34 -0
  5. package/lib/default-modules.js.map +1 -0
  6. package/lib/diagram-identifier.d.ts +14 -0
  7. package/lib/diagram-identifier.d.ts.map +1 -0
  8. package/lib/{diagram-identifer.js → diagram-identifier.js} +11 -5
  9. package/lib/diagram-identifier.js.map +1 -0
  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/{glsp-vscode-diagram-widget.js → features/copyPaste/copy-paste-startup.js} +37 -32
  17. package/lib/features/copyPaste/copy-paste-startup.js.map +1 -0
  18. package/lib/{diagram-identifer.d.ts → features/default/default-module.d.ts} +4 -11
  19. package/lib/features/default/default-module.d.ts.map +1 -0
  20. package/lib/features/default/default-module.js +31 -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} +18 -11
  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/features/notification/notification-module.d.ts +18 -0
  39. package/lib/features/notification/notification-module.d.ts.map +1 -0
  40. package/lib/features/notification/notification-module.js +27 -0
  41. package/lib/features/notification/notification-module.js.map +1 -0
  42. package/lib/glsp-diagram-widget.d.ts +32 -0
  43. package/lib/glsp-diagram-widget.d.ts.map +1 -0
  44. package/lib/glsp-diagram-widget.js +89 -0
  45. package/lib/glsp-diagram-widget.js.map +1 -0
  46. package/lib/glsp-starter.d.ts +43 -9
  47. package/lib/glsp-starter.d.ts.map +1 -1
  48. package/lib/glsp-starter.js +53 -66
  49. package/lib/glsp-starter.js.map +1 -1
  50. package/lib/index.d.ts +12 -2
  51. package/lib/index.d.ts.map +1 -1
  52. package/lib/index.js +26 -16
  53. package/lib/index.js.map +1 -1
  54. package/lib/webview-glsp-client.d.ts +56 -0
  55. package/lib/webview-glsp-client.d.ts.map +1 -0
  56. package/lib/webview-glsp-client.js +103 -0
  57. package/lib/webview-glsp-client.js.map +1 -0
  58. package/package.json +15 -15
  59. package/src/default-modules.ts +34 -0
  60. package/src/{diagram-identifer.ts → diagram-identifier.ts} +16 -5
  61. package/src/features/copyPaste/copy-paste-module.ts +39 -0
  62. package/src/features/copyPaste/copy-paste-startup.ts +50 -0
  63. package/src/features/default/default-module.ts +32 -0
  64. package/src/features/default/extension-action-handler.ts +73 -0
  65. package/src/features/default/vscode-glsp-modelsource.ts +63 -0
  66. package/src/{copy-paste-handler-provider.ts → features/export/export-module.ts} +6 -8
  67. package/src/features/navigation/navigation-module.ts +22 -0
  68. package/src/features/notification/notification-module.ts +25 -0
  69. package/src/glsp-diagram-widget.ts +79 -0
  70. package/src/glsp-starter.ts +69 -85
  71. package/src/index.ts +13 -2
  72. package/src/webview-glsp-client.ts +132 -0
  73. package/lib/copy-paste-handler-provider.d.ts.map +0 -1
  74. package/lib/copy-paste-handler-provider.js.map +0 -1
  75. package/lib/diagram-identifer.d.ts.map +0 -1
  76. package/lib/diagram-identifer.js.map +0 -1
  77. package/lib/extension-action-handler.d.ts.map +0 -1
  78. package/lib/extension-action-handler.js +0 -30
  79. package/lib/extension-action-handler.js.map +0 -1
  80. package/lib/glsp-vscode-diagram-widget.d.ts +0 -6
  81. package/lib/glsp-vscode-diagram-widget.d.ts.map +0 -1
  82. package/lib/glsp-vscode-diagram-widget.js.map +0 -1
  83. package/lib/glsp-vscode-diagramserver.d.ts +0 -33
  84. package/lib/glsp-vscode-diagramserver.d.ts.map +0 -1
  85. package/lib/glsp-vscode-diagramserver.js +0 -108
  86. package/lib/glsp-vscode-diagramserver.js.map +0 -1
  87. package/src/extension-action-handler.ts +0 -46
  88. package/src/glsp-vscode-diagram-widget.ts +0 -42
  89. package/src/glsp-vscode-diagramserver.ts +0 -111
@@ -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/lib/features/copy-paste/copy-paste-handler';
17
+ import { ExportSvgAction, FeatureModule } 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 vscodeExportModule = new FeatureModule(bind => {
21
+ bind(ExtensionActionKind).toConstantValue(ExportSvgAction.KIND);
22
+ });
@@ -0,0 +1,22 @@
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, NavigateToExternalTargetAction, navigationModule } from '@eclipse-glsp/client';
18
+ import { ExtensionActionKind } from '../default/extension-action-handler';
19
+
20
+ export const vscodeNavigationModule = new FeatureModule(bind => {
21
+ bind(ExtensionActionKind).toConstantValue(NavigateToExternalTargetAction.KIND);
22
+ }, navigationModule);
@@ -0,0 +1,25 @@
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 { EndProgressAction, FeatureModule, MessageAction, StartProgressAction, UpdateProgressAction } from '@eclipse-glsp/client';
18
+ import { ExtensionActionKind } from '../default/extension-action-handler';
19
+
20
+ export const vscodeNotificationModule = new FeatureModule(bind => {
21
+ bind(ExtensionActionKind).toConstantValue(MessageAction.KIND);
22
+ bind(ExtensionActionKind).toConstantValue(StartProgressAction.KIND);
23
+ bind(ExtensionActionKind).toConstantValue(EndProgressAction.KIND);
24
+ bind(ExtensionActionKind).toConstantValue(UpdateProgressAction.KIND);
25
+ });
@@ -0,0 +1,79 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2018 TypeFox and others.
3
+ * Modifications: (c) 2020-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
+ // based on https://github.com/eclipse-sprotty/sprotty-vscode/blob/v0.3.0/sprotty-vscode-webview/src/vscode-diagram-widget.ts
18
+ import {
19
+ DiagramLoader,
20
+ DiagramLoadingOptions,
21
+ IActionDispatcher,
22
+ IDiagramOptions,
23
+ ModelSource,
24
+ TYPES,
25
+ ViewerOptions
26
+ } from '@eclipse-glsp/client';
27
+ import { inject, injectable, postConstruct } from 'inversify';
28
+
29
+ export const GLSPDiagramWidgetFactory = Symbol('GLSPDiagramWidgetFactory');
30
+ export type GLSPDiagramWidgetFactory = () => GLSPDiagramWidget;
31
+
32
+ @injectable()
33
+ export abstract class GLSPDiagramWidget {
34
+ @inject(TYPES.IActionDispatcher)
35
+ protected actionDispatcher: IActionDispatcher;
36
+
37
+ @inject(TYPES.ModelSource)
38
+ protected modelSource: ModelSource;
39
+
40
+ @inject(TYPES.IDiagramOptions)
41
+ protected diagramOptions: IDiagramOptions;
42
+
43
+ @inject(TYPES.ViewerOptions)
44
+ protected viewerOptions: ViewerOptions;
45
+
46
+ @inject(DiagramLoader)
47
+ protected diagramLoader: DiagramLoader;
48
+
49
+ get clientId(): string {
50
+ return this.diagramOptions.clientId;
51
+ }
52
+
53
+ @postConstruct()
54
+ initialize(): void {
55
+ this.initializeHtml();
56
+ this.loadDiagram();
57
+ }
58
+
59
+ protected initializeHtml(): void {
60
+ const containerDiv = document.getElementById(this.clientId + '_container');
61
+ if (containerDiv) {
62
+ const svgContainer = document.createElement('div');
63
+ svgContainer.id = this.viewerOptions.baseDiv;
64
+ containerDiv.appendChild(svgContainer);
65
+
66
+ const hiddenContainer = document.createElement('div');
67
+ hiddenContainer.id = this.viewerOptions.hiddenDiv;
68
+ document.body.appendChild(hiddenContainer);
69
+ }
70
+ }
71
+
72
+ protected createDiagramLoadingOptions(): DiagramLoadingOptions | undefined {
73
+ return undefined;
74
+ }
75
+
76
+ loadDiagram(): Promise<void> {
77
+ return this.diagramLoader.load(this.createDiagramLoadingOptions());
78
+ }
79
+ }
@@ -1,5 +1,6 @@
1
1
  /********************************************************************************
2
- * Copyright (c) 2020-2022 EclipseSource and others.
2
+ * Copyright (c) 2018 TypeFox and others.
3
+ * Modifications: (c) 2020-2023 EclipseSource and others.
3
4
  *
4
5
  * This program and the accompanying materials are made available under the
5
6
  * terms of the Eclipse Public License v. 2.0 which is available at
@@ -13,99 +14,82 @@
13
14
  *
14
15
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
16
  ********************************************************************************/
16
- import {
17
- configureServerActions,
18
- DiagramServerProxy,
19
- ExportSvgAction,
20
- ICopyPasteHandler,
21
- NavigateToExternalTargetAction,
22
- RequestClipboardDataAction,
23
- SelectAction,
24
- SetClipboardDataAction,
25
- TYPES
26
- } from '@eclipse-glsp/client';
27
- import { Container } from 'inversify';
28
- import {
29
- SprottyDiagramIdentifier,
30
- SprottyStarter,
31
- VscodeDiagramServer,
32
- VscodeDiagramWidget,
33
- VscodeDiagramWidgetFactory
34
- } from 'sprotty-vscode-webview';
35
- import { VsCodeApi } from 'sprotty-vscode-webview/lib/services';
36
- import { CopyPasteHandlerProvider } from './copy-paste-handler-provider';
37
- import { GLSPDiagramIdentifier, isDiagramIdentifier } from './diagram-identifer';
38
- import { GLSPVscodeExtensionActionHandler } from './extension-action-handler';
39
- import { GLSPVscodeDiagramWidget } from './glsp-vscode-diagram-widget';
40
- import { GLSPVscodeDiagramServer } from './glsp-vscode-diagramserver';
17
+ // based on https://github.com/eclipse-sprotty/sprotty-vscode/blob/v0.3.0/sprotty-vscode-webview/src/sprotty-starter.ts
18
+ import { ContainerConfiguration, createDiagramOptionsModule } from '@eclipse-glsp/client';
19
+ import { Container, ContainerModule } from 'inversify';
20
+ import { HOST_EXTENSION, NotificationType } from 'vscode-messenger-common';
21
+ import { Messenger, VsCodeApi } from 'vscode-messenger-webview';
22
+ import { VSCODE_DEFAULT_MODULE_CONFIG } from './default-modules';
23
+ import { GLSPDiagramIdentifier } from './diagram-identifier';
24
+ import { GLSPDiagramWidget } from './glsp-diagram-widget';
25
+ import { WebviewGlspClient } from './webview-glsp-client';
26
+ export const WebviewReadyNotification: NotificationType<void> = { method: 'ready' };
27
+ export const InitializeNotification: NotificationType<GLSPDiagramIdentifier> = { method: 'initialize' };
41
28
 
42
- export abstract class GLSPStarter extends SprottyStarter {
43
- protected override acceptDiagramIdentifier(): void {
44
- console.log('Waiting for diagram identifier...');
45
- const eventListener = (message: any): void => {
46
- if (isDiagramIdentifier(message.data)) {
47
- console.log(message);
48
- if (this.container) {
49
- const oldIdentifier = this.container.get<GLSPDiagramIdentifier>(GLSPDiagramIdentifier);
50
- const newIdentifier = message.data as GLSPDiagramIdentifier;
51
- oldIdentifier.diagramType = newIdentifier.diagramType;
52
- oldIdentifier.uri = newIdentifier.uri;
53
- const diagramWidget = this.container.get(VscodeDiagramWidget);
54
- diagramWidget.requestModel();
55
- } else {
56
- console.log('...received...', message);
57
- const diagramIdentifier = message.data as GLSPDiagramIdentifier;
58
- this.container = this.createContainer(diagramIdentifier);
59
- this.addVscodeBindings(this.container, diagramIdentifier);
60
- if (diagramIdentifier.initializeResult) {
61
- configureServerActions(diagramIdentifier.initializeResult, diagramIdentifier.diagramType, this.container);
62
- }
63
- this.container.get(VscodeDiagramWidget);
64
- }
65
- }
66
- };
67
- window.addEventListener('message', eventListener);
29
+ declare function acquireVsCodeApi(): VsCodeApi;
30
+
31
+ export abstract class GLSPStarter {
32
+ protected container?: Container;
33
+ protected messenger: Messenger;
34
+
35
+ constructor() {
36
+ this.messenger = new Messenger(acquireVsCodeApi());
37
+ this.messenger.onNotification<GLSPDiagramIdentifier>(InitializeNotification, identifier =>
38
+ this.acceptDiagramIdentifier(identifier)
39
+ );
40
+ this.messenger.start();
41
+ this.sendReadyMessage();
68
42
  }
69
43
 
70
- protected override addVscodeBindings(container: Container, diagramIdentifier: GLSPDiagramIdentifier): void {
71
- container.bind(VsCodeApi).toConstantValue(this.vscodeApi);
72
- container.bind(GLSPVscodeDiagramWidget).toSelf().inSingletonScope();
73
- container.bind(VscodeDiagramWidget).toService(GLSPVscodeDiagramWidget);
74
- container
75
- .bind(VscodeDiagramWidgetFactory)
76
- .toFactory(context => () => context.container.get<GLSPVscodeDiagramWidget>(GLSPVscodeDiagramWidget));
77
- container.bind(GLSPDiagramIdentifier).toConstantValue(diagramIdentifier);
78
- container
79
- .bind(CopyPasteHandlerProvider)
80
- .toProvider(
81
- ctx => () =>
82
- new Promise<ICopyPasteHandler>(resolve => resolve(ctx.container.get<ICopyPasteHandler>(TYPES.ICopyPasteHandler)))
83
- );
84
- container.bind(SprottyDiagramIdentifier).toService(GLSPDiagramIdentifier);
85
- container.bind(GLSPVscodeDiagramServer).toSelf().inSingletonScope();
86
- container.bind(VscodeDiagramServer).toService(GLSPVscodeDiagramServer);
87
- container.bind(TYPES.ModelSource).toService(GLSPVscodeDiagramServer);
88
- container.bind(DiagramServerProxy).toService(GLSPVscodeDiagramServer);
44
+ protected sendReadyMessage(): void {
45
+ this.messenger.sendNotification(WebviewReadyNotification, HOST_EXTENSION);
46
+ }
89
47
 
90
- this.configureExtensionActionHandler(container, diagramIdentifier);
48
+ protected acceptDiagramIdentifier(identifier: GLSPDiagramIdentifier): void {
49
+ if (this.container) {
50
+ const oldIdentifier = this.container.get<GLSPDiagramIdentifier>(GLSPDiagramIdentifier);
51
+ oldIdentifier.diagramType = identifier.diagramType;
52
+ oldIdentifier.uri = identifier.uri;
53
+ const diagramWidget = this.container.get(GLSPDiagramWidget);
54
+ diagramWidget.loadDiagram();
55
+ } else {
56
+ const diagramModule = this.createDiagramOptionsModule(identifier);
57
+ this.container = this.createContainer(diagramModule, ...this.getContainerConfiguration());
58
+ this.addVscodeBindings?.(this.container, identifier);
59
+ this.container.get(GLSPDiagramWidget);
60
+ }
91
61
  }
92
62
 
93
- protected configureExtensionActionHandler(container: Container, diagramIdentifier: SprottyDiagramIdentifier): void {
94
- const extensionActionHandler = new GLSPVscodeExtensionActionHandler(this.extensionActionKinds, diagramIdentifier, this.vscodeApi);
95
- container.bind(GLSPVscodeExtensionActionHandler).toConstantValue(extensionActionHandler);
96
- container.bind(TYPES.IActionHandlerInitializer).toService(GLSPVscodeExtensionActionHandler);
63
+ protected createDiagramOptionsModule(identifier: GLSPDiagramIdentifier): ContainerModule {
64
+ const glspClient = new WebviewGlspClient({ id: identifier.diagramType, messenger: this.messenger });
65
+ return createDiagramOptionsModule({
66
+ clientId: identifier.clientId,
67
+ diagramType: identifier.diagramType,
68
+ glspClientProvider: async () => glspClient,
69
+ sourceUri: decodeURIComponent(identifier.uri)
70
+ });
97
71
  }
98
72
 
99
73
  /**
100
- * All kinds of actions that should (also) be delegated to and handled by the vscode extension
74
+ * Retrieves additional {@link ContainerConfiguration} for the diagram container.
75
+ * Typically this composes a set of vscode specific customization modules.
76
+ * @returns the container configuration
101
77
  */
102
- protected get extensionActionKinds(): string[] {
103
- return [
104
- NavigateToExternalTargetAction.KIND,
105
- RequestClipboardDataAction.KIND,
106
- SetClipboardDataAction.KIND,
107
- SelectAction.KIND,
108
- ExportSvgAction.KIND
109
- ];
78
+ protected getContainerConfiguration(): ContainerConfiguration {
79
+ return [VSCODE_DEFAULT_MODULE_CONFIG];
110
80
  }
81
+
82
+ protected abstract createContainer(...containerConfiguration: ContainerConfiguration): Container;
83
+
84
+ /**
85
+ * Optional hook that can be implemented to customize diagram container bindings before it's used
86
+ * to instantiate the diagram services
87
+ * @param container The diagram container
88
+ * @param diagramIdentifier The diagram identfier
89
+ */
90
+ protected addVscodeBindings?(container: Container, diagramIdentifier: GLSPDiagramIdentifier): void;
91
+ }
92
+
93
+ export function decodeURI(uri: string): string {
94
+ return decodeURIComponent(uri.replace(/\+/g, ' '));
111
95
  }
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /********************************************************************************
2
- * Copyright (c) 2020 EclipseSource and others.
2
+ * Copyright (c) 2020-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
@@ -13,5 +13,16 @@
13
13
  *
14
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  ********************************************************************************/
16
+
17
+ export * from './default-modules';
18
+ export * from './diagram-identifier';
19
+ export * from './features/copyPaste/copy-paste-module';
20
+ export * from './features/copyPaste/copy-paste-startup';
21
+ export * from './features/default/default-module';
22
+ export * from './features/default/vscode-glsp-modelsource';
23
+ export * from './features/export/export-module';
24
+ export * from './features/navigation/navigation-module';
25
+ export * from './features/notification/notification-module';
26
+ export * from './glsp-diagram-widget';
16
27
  export * from './glsp-starter';
17
- export * from './glsp-vscode-diagramserver';
28
+ export * from './webview-glsp-client';
@@ -0,0 +1,132 @@
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
+ Action,
19
+ ActionMessage,
20
+ ActionMessageHandler,
21
+ ClientState,
22
+ Disposable,
23
+ DisposableCollection,
24
+ DisposeClientSessionParameters,
25
+ Emitter,
26
+ Event,
27
+ GLSPClient,
28
+ InitializeClientSessionParameters,
29
+ InitializeParameters,
30
+ InitializeResult
31
+ } from '@eclipse-glsp/client';
32
+ import { HOST_EXTENSION, NotificationType, RequestType } from 'vscode-messenger-common';
33
+ import { Messenger } from 'vscode-messenger-webview';
34
+
35
+ export interface WebviewGlspClientOptions extends GLSPClient.Options {
36
+ messenger?: Messenger;
37
+ }
38
+
39
+ export const ActionMessageNotification: NotificationType<ActionMessage> = { method: 'actionMessage' };
40
+ export const StartRequest: RequestType<undefined, void> = { method: 'start' };
41
+ export const InitializeServerRequest: RequestType<InitializeParameters, InitializeResult> = { method: 'initializeServer' };
42
+ export const InitializeClientSessionRequest: RequestType<InitializeClientSessionParameters, void> = { method: 'initializeClientSession' };
43
+ export const DisposeClientSessionRequest: RequestType<DisposeClientSessionParameters, void> = { method: 'disposeClientSession' };
44
+ export const ShutdownServerNotification: NotificationType<void> = { method: 'shutdownServer' };
45
+ export const StopRequest: RequestType<undefined, void> = { method: 'stop' };
46
+ /**
47
+ * GLSP client implementation for the diagram webview. This is proxy implementation
48
+ * that communicates with the actual GLSP client running in the host extension.
49
+ * via the vscode-messenger protocol
50
+ */
51
+ export class WebviewGlspClient implements GLSPClient, Disposable {
52
+ readonly id: string;
53
+ protected messenger: Messenger;
54
+ protected toDispose = new DisposableCollection();
55
+ protected onActionMessageEmitter = new Emitter<ActionMessage>();
56
+
57
+ protected _currentState: ClientState = ClientState.Starting;
58
+ get currentState(): ClientState {
59
+ return this._currentState;
60
+ }
61
+
62
+ protected _initializeResult?: InitializeResult;
63
+ get initializeResult(): InitializeResult | undefined {
64
+ return this._initializeResult;
65
+ }
66
+
67
+ protected onServerInitializedEmitter = new Emitter<InitializeResult>();
68
+ get onServerInitialized(): Event<InitializeResult> {
69
+ return this.onServerInitializedEmitter.event;
70
+ }
71
+
72
+ constructor(options: WebviewGlspClientOptions) {
73
+ this.id = options.id;
74
+ this.messenger = options.messenger ?? new Messenger();
75
+ this.toDispose.push(this.onActionMessageEmitter, this.onServerInitializedEmitter);
76
+ this.messenger.onNotification<ActionMessage>(ActionMessageNotification, msg => this.onActionMessageEmitter.fire(msg));
77
+ }
78
+
79
+ async start(): Promise<void> {
80
+ try {
81
+ this._currentState = ClientState.Starting;
82
+ await this.messenger.sendRequest(StartRequest, HOST_EXTENSION);
83
+ this._currentState = ClientState.Running;
84
+ } catch (error) {
85
+ console.error('Failed to start connection to server', error);
86
+ this._currentState = ClientState.StartFailed;
87
+ }
88
+ }
89
+
90
+ async initializeServer(params: InitializeParameters): Promise<InitializeResult> {
91
+ if (this.initializeResult) {
92
+ return this.initializeResult;
93
+ }
94
+ const result = await this.messenger.sendRequest(InitializeServerRequest, HOST_EXTENSION, params);
95
+ this._initializeResult = result;
96
+ this.onServerInitializedEmitter.fire(result);
97
+ return result;
98
+ }
99
+
100
+ initializeClientSession(params: InitializeClientSessionParameters): Promise<void> {
101
+ return this.messenger.sendRequest(InitializeClientSessionRequest, HOST_EXTENSION, params);
102
+ }
103
+
104
+ disposeClientSession(params: DisposeClientSessionParameters): Promise<void> {
105
+ return this.messenger.sendRequest(DisposeClientSessionRequest, HOST_EXTENSION, params);
106
+ }
107
+
108
+ shutdownServer(): void {
109
+ this.messenger.sendNotification(ShutdownServerNotification, HOST_EXTENSION);
110
+ }
111
+
112
+ async stop(): Promise<void> {
113
+ if (this._currentState === ClientState.Stopped) {
114
+ return;
115
+ }
116
+ this._currentState = ClientState.Stopping;
117
+ await this.messenger.sendRequest(StopRequest, HOST_EXTENSION);
118
+ this._currentState = ClientState.Stopped;
119
+ }
120
+
121
+ sendActionMessage(message: ActionMessage<Action>): void {
122
+ this.messenger.sendNotification(ActionMessageNotification, HOST_EXTENSION, message);
123
+ }
124
+
125
+ onActionMessage(handler: ActionMessageHandler): Disposable {
126
+ return this.onActionMessageEmitter.event(handler);
127
+ }
128
+
129
+ dispose(): void {
130
+ this.toDispose.dispose();
131
+ }
132
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"copy-paste-handler-provider.d.ts","sourceRoot":"","sources":["../src/copy-paste-handler-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAElF,OAAO,EAAE,iBAAiB,EAAE,MAAM,iEAAiE,CAAC;AAEpG,eAAO,MAAM,wBAAwB,eAAqC,CAAC;AAC3E;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAAG,MAAM,OAAO,CAAC,iBAAiB,CAAC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"copy-paste-handler-provider.js","sourceRoot":"","sources":["../src/copy-paste-handler-provider.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;kFAckF;;;AAIrE,QAAA,wBAAwB,GAAG,MAAM,CAAC,0BAA0B,CAAC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"diagram-identifer.d.ts","sourceRoot":"","sources":["../src/diagram-identifer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAClF,OAAO,EAAiB,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAEvE,eAAO,MAAM,qBAAqB,eAAkC,CAAC;AAErE,MAAM,WAAW,qBAAqB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;CACvC;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,GAAG,GAAG,MAAM,IAAI,qBAAqB,CAQhF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"diagram-identifer.js","sourceRoot":"","sources":["../src/diagram-identifer.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;kFAckF;AAClF,iDAAuE;AAE1D,QAAA,qBAAqB,GAAG,MAAM,CAAC,uBAAuB,CAAC,CAAC;AASrE,SAAgB,mBAAmB,CAAC,MAAW;IAC3C,OAAO,CACH,MAAM,KAAK,SAAS;QACpB,OAAO,MAAM,KAAK,QAAQ;QAC1B,IAAA,sBAAa,EAAC,MAAM,EAAE,UAAU,CAAC;QACjC,IAAA,sBAAa,EAAC,MAAM,EAAE,aAAa,CAAC;QACpC,IAAA,sBAAa,EAAC,MAAM,EAAE,KAAK,CAAC,CAC/B,CAAC;AACN,CAAC;AARD,kDAQC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"extension-action-handler.d.ts","sourceRoot":"","sources":["../src/extension-action-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAClF,OAAO,EAAE,MAAM,EAAE,qBAAqB,EAAE,cAAc,EAAE,yBAAyB,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC1H,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AAEhE;;;;GAIG;AACH,qBAAa,gCAAiC,YAAW,cAAc,EAAE,yBAAyB;IAE1F,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE;IACxC,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,wBAAwB;IAC9D,SAAS,CAAC,SAAS,EAAE,SAAS;gBAFX,WAAW,EAAE,MAAM,EAAE,EACrB,iBAAiB,EAAE,wBAAwB,EACpD,SAAS,EAAE,SAAS;IAGlC,UAAU,CAAC,QAAQ,EAAE,qBAAqB,GAAG,IAAI;IAIjD,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,QAAQ;CAUnD"}
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GLSPVscodeExtensionActionHandler = void 0;
4
- /**
5
- * Delegates actions that should be handled inside of the glsp vscode extension instead
6
- * of the webview. This enables the implementation of action handlers that require access
7
- * to the vscode API and/or node backend.
8
- */
9
- class GLSPVscodeExtensionActionHandler {
10
- constructor(actionKinds, diagramIdentifier, vscodeApi) {
11
- this.actionKinds = actionKinds;
12
- this.diagramIdentifier = diagramIdentifier;
13
- this.vscodeApi = vscodeApi;
14
- }
15
- initialize(registry) {
16
- this.actionKinds.forEach(kind => registry.register(kind, this));
17
- }
18
- handle(action) {
19
- if (this.actionKinds.includes(action.kind)) {
20
- const message = {
21
- clientId: this.diagramIdentifier.clientId,
22
- action,
23
- __localDispatch: true
24
- };
25
- this.vscodeApi.postMessage(message);
26
- }
27
- }
28
- }
29
- exports.GLSPVscodeExtensionActionHandler = GLSPVscodeExtensionActionHandler;
30
- //# sourceMappingURL=extension-action-handler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extension-action-handler.js","sourceRoot":"","sources":["../src/extension-action-handler.ts"],"names":[],"mappings":";;;AAmBA;;;;GAIG;AACH,MAAa,gCAAgC;IACzC,YACuB,WAAqB,EACrB,iBAA2C,EACpD,SAAoB;QAFX,gBAAW,GAAX,WAAW,CAAU;QACrB,sBAAiB,GAAjB,iBAAiB,CAA0B;QACpD,cAAS,GAAT,SAAS,CAAW;IAC/B,CAAC;IAEJ,UAAU,CAAC,QAA+B;QACtC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IACpE,CAAC;IAED,MAAM,CAAC,MAAc;QACjB,IAAI,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;YACxC,MAAM,OAAO,GAAG;gBACZ,QAAQ,EAAE,IAAI,CAAC,iBAAiB,CAAC,QAAQ;gBACzC,MAAM;gBACN,eAAe,EAAE,IAAI;aACxB,CAAC;YACF,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;SACvC;IACL,CAAC;CACJ;AArBD,4EAqBC"}
@@ -1,6 +0,0 @@
1
- import { VscodeDiagramWidget } from 'sprotty-vscode-webview';
2
- export declare abstract class GLSPVscodeDiagramWidget extends VscodeDiagramWidget {
3
- protected initializeSprotty(): void;
4
- }
5
- export declare function decodeURI(uri: string): string;
6
- //# sourceMappingURL=glsp-vscode-diagram-widget.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"glsp-vscode-diagram-widget.d.ts","sourceRoot":"","sources":["../src/glsp-vscode-diagram-widget.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D,8BACsB,uBAAwB,SAAQ,mBAAmB;cAClD,iBAAiB,IAAI,IAAI;CAgB/C;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"glsp-vscode-diagram-widget.js","sourceRoot":"","sources":["../src/glsp-vscode-diagram-widget.ts"],"names":[],"mappings":";;;;;;;;;AAAA;;;;;;;;;;;;;;kFAckF;AAClF,iDAA+H;AAC/H,yCAAuC;AACvC,mEAA6D;AAGtD,IAAe,uBAAuB,GAAtC,MAAe,uBAAwB,SAAQ,4CAAmB;IAClD,iBAAiB;QAChC,IAAI,IAAI,CAAC,WAAW,YAAY,2BAAkB,EAAE;YAChD,IAAI,CAAC,WAAW,CAAC,QAAQ,GAAG,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC;SAC/D;QACD,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAC1B,2BAAkB,CAAC,MAAM,CAAC;YACtB,OAAO,EAAE;gBACL,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC;gBAChD,WAAW,EAAE,IAAI,CAAC,iBAAiB,CAAC,WAAW;aAClD;SACJ,CAAC,CACL,CAAC;QAEF,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,+BAAsB,CAAC,MAAM,EAAE,CAAC,CAAC;QAChE,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,gCAAuB,CAAC,MAAM,EAAE,CAAC,CAAC;IACrE,CAAC;CACJ,CAAA;AAjBqB,uBAAuB;IAD5C,IAAA,sBAAU,GAAE;GACS,uBAAuB,CAiB5C;AAjBqB,0DAAuB;AAmB7C,SAAgB,SAAS,CAAC,GAAW;IACjC,OAAO,kBAAkB,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;AACvD,CAAC;AAFD,8BAEC"}
@@ -1,33 +0,0 @@
1
- /********************************************************************************
2
- * Copyright (c) 2020-2022 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, ActionHandlerRegistry, ActionMessage, ComputedBoundsAction, DeleteElementOperation, SetEditModeAction } from '@eclipse-glsp/client';
17
- import { SelectionService } from '@eclipse-glsp/client/lib/features/select/selection-service';
18
- import { VscodeDiagramServer } from 'sprotty-vscode-webview/lib/vscode-diagram-server';
19
- import { CopyPasteHandlerProvider } from './copy-paste-handler-provider';
20
- export declare const receivedFromServerProperty = "__receivedFromServer";
21
- export declare const localDispatchProperty = "__localDispatch";
22
- export declare class GLSPVscodeDiagramServer extends VscodeDiagramServer {
23
- protected selectionService: SelectionService;
24
- protected copyPasteHandlerProvider: CopyPasteHandlerProvider;
25
- initialize(registry: ActionHandlerRegistry): void;
26
- handleLocally(action: Action): boolean;
27
- protected messageReceived(data: any): void;
28
- protected checkMessageOrigin(message: ActionMessage): void;
29
- protected handleComputedBounds(action: ComputedBoundsAction): boolean;
30
- protected handleDeleteElementOperation(operation: DeleteElementOperation): boolean;
31
- protected handleSetEditModeAction(action: SetEditModeAction): boolean;
32
- }
33
- //# sourceMappingURL=glsp-vscode-diagramserver.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"glsp-vscode-diagramserver.d.ts","sourceRoot":"","sources":["../src/glsp-vscode-diagramserver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;kFAckF;AAClF,OAAO,EACH,MAAM,EACN,qBAAqB,EACrB,aAAa,EACb,oBAAoB,EACpB,sBAAsB,EAEtB,iBAAiB,EAEpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,4DAA4D,CAAC;AAE9F,OAAO,EAAE,mBAAmB,EAAE,MAAM,kDAAkD,CAAC;AACvF,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,eAAO,MAAM,0BAA0B,yBAAyB,CAAC;AACjE,eAAO,MAAM,qBAAqB,oBAAoB,CAAC;AAEvD,qBAAa,uBAAwB,SAAQ,mBAAmB;IAE5D,SAAS,CAAC,gBAAgB,EAAE,gBAAgB,CAAC;IAG7C,SAAS,CAAC,wBAAwB,EAAE,wBAAwB,CAAC;IAEpD,UAAU,CAAC,QAAQ,EAAE,qBAAqB,GAAG,IAAI;IAyBjD,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;cAU5B,eAAe,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI;IAenD,SAAS,CAAC,kBAAkB,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI;cAOvC,oBAAoB,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO;IAI9E,SAAS,CAAC,4BAA4B,CAAC,SAAS,EAAE,sBAAsB,GAAG,OAAO;IAOlF,SAAS,CAAC,uBAAuB,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO;CAGxE"}