@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
@@ -15,104 +15,81 @@
15
15
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
16
16
  ********************************************************************************/
17
17
  // based on https://github.com/eclipse-sprotty/sprotty-vscode/blob/v0.3.0/sprotty-vscode-webview/src/sprotty-starter.ts
18
- import {
19
- configureServerActions,
20
- DiagramServerProxy,
21
- ExportSvgAction,
22
- ICopyPasteHandler,
23
- NavigateToExternalTargetAction,
24
- RequestClipboardDataAction,
25
- SelectAction,
26
- SetClipboardDataAction,
27
- TYPES
28
- } from '@eclipse-glsp/client';
29
- import { Container } from 'inversify';
30
- import { CopyPasteHandlerProvider } from './copy-paste-handler-provider';
31
- import { GLSPDiagramIdentifier, isDiagramIdentifier, WebviewReadyMessage } from './diagram-identifier';
32
- import { GLSPVscodeExtensionActionHandler } from './extension-action-handler';
33
- import { GLSPDiagramWidget, GLSPDiagramWidgetFactory } from './glsp-diagram-widget';
34
- import { GLSPVscodeDiagramServer } from './glsp-vscode-diagramserver';
35
- import { GLSPStarterServices, VsCodeApi } from './services';
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' };
36
28
 
37
29
  declare function acquireVsCodeApi(): VsCodeApi;
38
30
 
39
31
  export abstract class GLSPStarter {
40
32
  protected container?: Container;
41
- protected vscodeApi: VsCodeApi;
33
+ protected messenger: Messenger;
42
34
 
43
- constructor(services: GLSPStarterServices = {}) {
44
- this.vscodeApi = services.vscodeApi ?? acquireVsCodeApi();
35
+ constructor() {
36
+ this.messenger = new Messenger(acquireVsCodeApi());
37
+ this.messenger.onNotification<GLSPDiagramIdentifier>(InitializeNotification, identifier =>
38
+ this.acceptDiagramIdentifier(identifier)
39
+ );
40
+ this.messenger.start();
45
41
  this.sendReadyMessage();
46
- this.acceptDiagramIdentifier();
47
42
  }
48
43
 
49
44
  protected sendReadyMessage(): void {
50
- this.vscodeApi.postMessage({ readyMessage: 'Sprotty Webview ready' } as WebviewReadyMessage);
45
+ this.messenger.sendNotification(WebviewReadyNotification, HOST_EXTENSION);
51
46
  }
52
47
 
53
- protected acceptDiagramIdentifier(): void {
54
- console.log('Waiting for diagram identifier...');
55
- const eventListener = (message: any): void => {
56
- if (isDiagramIdentifier(message.data)) {
57
- console.log(message);
58
- if (this.container) {
59
- const oldIdentifier = this.container.get<GLSPDiagramIdentifier>(GLSPDiagramIdentifier);
60
- const newIdentifier = message.data as GLSPDiagramIdentifier;
61
- oldIdentifier.diagramType = newIdentifier.diagramType;
62
- oldIdentifier.uri = newIdentifier.uri;
63
- const diagramWidget = this.container.get(GLSPDiagramWidget);
64
- diagramWidget.dispatchInitialActions();
65
- } else {
66
- console.log('...received...', message);
67
- const diagramIdentifier = message.data as GLSPDiagramIdentifier;
68
- this.container = this.createContainer(diagramIdentifier);
69
- this.addVscodeBindings(this.container, diagramIdentifier);
70
- if (diagramIdentifier.initializeResult) {
71
- configureServerActions(diagramIdentifier.initializeResult, diagramIdentifier.diagramType, this.container);
72
- }
73
- this.container.get(GLSPDiagramWidget);
74
- }
75
- }
76
- };
77
- window.addEventListener('message', eventListener);
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
+ }
78
61
  }
79
62
 
80
- protected abstract createContainer(diagramIdentifier: GLSPDiagramIdentifier): Container;
81
-
82
- protected addVscodeBindings(container: Container, diagramIdentifier: GLSPDiagramIdentifier): void {
83
- container.bind(VsCodeApi).toConstantValue(this.vscodeApi);
84
- container.bind(GLSPDiagramWidget).toSelf().inSingletonScope();
85
- container.bind(GLSPDiagramWidgetFactory).toFactory(context => () => context.container.get<GLSPDiagramWidget>(GLSPDiagramWidget));
86
- container.bind(GLSPDiagramIdentifier).toConstantValue(diagramIdentifier);
87
- container
88
- .bind(CopyPasteHandlerProvider)
89
- .toProvider(
90
- ctx => () =>
91
- new Promise<ICopyPasteHandler>(resolve => resolve(ctx.container.get<ICopyPasteHandler>(TYPES.ICopyPasteHandler)))
92
- );
93
- container.bind(GLSPVscodeDiagramServer).toSelf().inSingletonScope();
94
- container.bind(TYPES.ModelSource).toService(GLSPVscodeDiagramServer);
95
- container.bind(DiagramServerProxy).toService(GLSPVscodeDiagramServer);
96
-
97
- this.configureExtensionActionHandler(container, diagramIdentifier);
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
+ });
98
71
  }
99
72
 
100
- protected configureExtensionActionHandler(container: Container, diagramIdentifier: GLSPDiagramIdentifier): void {
101
- const extensionActionHandler = new GLSPVscodeExtensionActionHandler(this.extensionActionKinds, diagramIdentifier, this.vscodeApi);
102
- container.bind(GLSPVscodeExtensionActionHandler).toConstantValue(extensionActionHandler);
103
- container.bind(TYPES.IActionHandlerInitializer).toService(GLSPVscodeExtensionActionHandler);
73
+ /**
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
77
+ */
78
+ protected getContainerConfiguration(): ContainerConfiguration {
79
+ return [VSCODE_DEFAULT_MODULE_CONFIG];
104
80
  }
105
81
 
82
+ protected abstract createContainer(...containerConfiguration: ContainerConfiguration): Container;
83
+
106
84
  /**
107
- * All kinds of actions that should (also) be delegated to and handled by the vscode extension
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
108
89
  */
109
- protected get extensionActionKinds(): string[] {
110
- return [
111
- NavigateToExternalTargetAction.KIND,
112
- RequestClipboardDataAction.KIND,
113
- SetClipboardDataAction.KIND,
114
- SelectAction.KIND,
115
- ExportSvgAction.KIND
116
- ];
117
- }
90
+ protected addVscodeBindings?(container: Container, diagramIdentifier: GLSPDiagramIdentifier): void;
91
+ }
92
+
93
+ export function decodeURI(uri: string): string {
94
+ return decodeURIComponent(uri.replace(/\+/g, ' '));
118
95
  }
package/src/index.ts CHANGED
@@ -13,10 +13,15 @@
13
13
  *
14
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  ********************************************************************************/
16
- export * from './copy-paste-handler-provider';
16
+
17
+ export * from './default-modules';
17
18
  export * from './diagram-identifier';
18
- export * from './extension-action-handler';
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';
19
25
  export * from './glsp-diagram-widget';
20
26
  export * from './glsp-starter';
21
- export * from './glsp-vscode-diagramserver';
22
- export * from './services';
27
+ 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,sBAAsB,CAAC;AAEzD,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":"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,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC;;;;GAIG;AACH,qBAAa,gCAAiC,YAAW,cAAc,EAAE,yBAAyB;IAE1F,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,MAAM,EAAE;IACxC,SAAS,CAAC,QAAQ,CAAC,iBAAiB,EAAE,qBAAqB;IAC3D,SAAS,CAAC,SAAS,EAAE,SAAS;gBAFX,WAAW,EAAE,MAAM,EAAE,EACrB,iBAAiB,EAAE,qBAAqB,EACjD,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,iBAAwC,EACjD,SAAoB;QAFX,gBAAW,GAAX,WAAW,CAAU;QACrB,sBAAiB,GAAjB,iBAAiB,CAAuB;QACjD,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,39 +0,0 @@
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
- import { Action, ActionHandlerRegistry, ActionMessage, ComputedBoundsAction, DeleteElementOperation, DiagramServerProxy, ServerStatusAction, SetEditModeAction } from '@eclipse-glsp/client';
18
- import { SelectionService } from '@eclipse-glsp/client/lib/features/select/selection-service';
19
- import { CopyPasteHandlerProvider } from './copy-paste-handler-provider';
20
- import { GLSPDiagramWidgetFactory } from './glsp-diagram-widget';
21
- import { VsCodeApi } from './services';
22
- export declare const receivedFromServerProperty = "__receivedFromServer";
23
- export declare const localDispatchProperty = "__localDispatch";
24
- export declare class GLSPVscodeDiagramServer extends DiagramServerProxy {
25
- protected selectionService: SelectionService;
26
- protected vscodeApi: VsCodeApi;
27
- protected diagramWidgetFactory: GLSPDiagramWidgetFactory;
28
- protected copyPasteHandlerProvider: CopyPasteHandlerProvider;
29
- initialize(registry: ActionHandlerRegistry): void;
30
- protected sendMessage(message: ActionMessage): void;
31
- handleLocally(action: Action): boolean;
32
- protected handleServerStateAction(status: ServerStatusAction): boolean;
33
- protected messageReceived(data: any): void;
34
- protected checkMessageOrigin(message: ActionMessage): void;
35
- protected handleComputedBounds(action: ComputedBoundsAction): boolean;
36
- protected handleDeleteElementOperation(operation: DeleteElementOperation): boolean;
37
- protected handleSetEditModeAction(action: SetEditModeAction): boolean;
38
- }
39
- //# sourceMappingURL=glsp-vscode-diagramserver.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"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,SAAS,CAAC,uBAAuB,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO;CAGxE"}
@@ -1,126 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.GLSPVscodeDiagramServer = exports.localDispatchProperty = exports.receivedFromServerProperty = void 0;
13
- /********************************************************************************
14
- * Copyright (c) 2018 TypeFox and others.
15
- * Modifications: (c) 2020-2023 EclipseSource and others.
16
- *
17
- * This program and the accompanying materials are made available under the
18
- * terms of the Eclipse Public License v. 2.0 which is available at
19
- * http://www.eclipse.org/legal/epl-2.0.
20
- *
21
- * This Source Code may also be made available under the following Secondary
22
- * Licenses when the conditions for such availability set forth in the Eclipse
23
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
24
- * with the GNU Classpath Exception which is available at
25
- * https://www.gnu.org/software/classpath/license.html.
26
- *
27
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
28
- ********************************************************************************/
29
- // based on https://github.com/eclipse-sprotty/sprotty-vscode/blob/v0.3.0/sprotty-vscode-webview/src/vscode-diagram-server.ts
30
- const client_1 = require("@eclipse-glsp/client");
31
- const selection_service_1 = require("@eclipse-glsp/client/lib/features/select/selection-service");
32
- const inversify_1 = require("inversify");
33
- const copy_paste_handler_provider_1 = require("./copy-paste-handler-provider");
34
- const glsp_diagram_widget_1 = require("./glsp-diagram-widget");
35
- const services_1 = require("./services");
36
- exports.receivedFromServerProperty = '__receivedFromServer';
37
- exports.localDispatchProperty = '__localDispatch';
38
- class GLSPVscodeDiagramServer extends client_1.DiagramServerProxy {
39
- initialize(registry) {
40
- (0, client_1.registerDefaultGLSPServerActions)(registry, this);
41
- this.clientId = this.viewerOptions.baseDiv;
42
- window.addEventListener('message', message => {
43
- if ('data' in message && client_1.ActionMessage.is(message.data)) {
44
- this.messageReceived(message.data);
45
- }
46
- });
47
- this.copyPasteHandlerProvider().then(copyPasteHandler => {
48
- document.addEventListener('copy', (e) => {
49
- copyPasteHandler.handleCopy(e);
50
- });
51
- document.addEventListener('cut', (e) => {
52
- copyPasteHandler.handleCut(e);
53
- });
54
- document.addEventListener('paste', (e) => {
55
- copyPasteHandler.handlePaste(e);
56
- });
57
- });
58
- }
59
- sendMessage(message) {
60
- this.vscodeApi.postMessage(message);
61
- }
62
- handleLocally(action) {
63
- if (client_1.SetEditModeAction.is(action)) {
64
- return this.handleSetEditModeAction(action);
65
- }
66
- if (client_1.DeleteElementOperation.is(action)) {
67
- return this.handleDeleteElementOperation(action);
68
- }
69
- return super.handleLocally(action);
70
- }
71
- handleServerStateAction(status) {
72
- this.diagramWidgetFactory().setStatus(status);
73
- return false;
74
- }
75
- messageReceived(data) {
76
- const object = typeof data === 'string' ? JSON.parse(data) : data;
77
- if (client_1.ActionMessage.is(object) && object.action) {
78
- if (!object.clientId || object.clientId === this.clientId) {
79
- this.checkMessageOrigin(object);
80
- this.logger.log(this, 'receiving', object);
81
- this.actionDispatcher.dispatch(object.action).then(() => {
82
- this.storeNewModel(object.action);
83
- });
84
- }
85
- }
86
- else {
87
- this.logger.error(this, 'received data is not an action message', object);
88
- }
89
- }
90
- checkMessageOrigin(message) {
91
- const isLocalDispatch = message[exports.localDispatchProperty] || false;
92
- if (!isLocalDispatch) {
93
- message.action[exports.receivedFromServerProperty] = true;
94
- }
95
- }
96
- handleComputedBounds(action) {
97
- return true;
98
- }
99
- handleDeleteElementOperation(operation) {
100
- if (operation.elementIds.length === 0) {
101
- operation.elementIds.push(...this.selectionService.getSelectedElementIDs());
102
- }
103
- return true;
104
- }
105
- handleSetEditModeAction(action) {
106
- return action[exports.receivedFromServerProperty] !== true;
107
- }
108
- }
109
- __decorate([
110
- (0, inversify_1.inject)(client_1.TYPES.SelectionService),
111
- __metadata("design:type", selection_service_1.SelectionService)
112
- ], GLSPVscodeDiagramServer.prototype, "selectionService", void 0);
113
- __decorate([
114
- (0, inversify_1.inject)(services_1.VsCodeApi),
115
- __metadata("design:type", Object)
116
- ], GLSPVscodeDiagramServer.prototype, "vscodeApi", void 0);
117
- __decorate([
118
- (0, inversify_1.inject)(glsp_diagram_widget_1.GLSPDiagramWidgetFactory),
119
- __metadata("design:type", Function)
120
- ], GLSPVscodeDiagramServer.prototype, "diagramWidgetFactory", void 0);
121
- __decorate([
122
- (0, inversify_1.inject)(copy_paste_handler_provider_1.CopyPasteHandlerProvider),
123
- __metadata("design:type", Function)
124
- ], GLSPVscodeDiagramServer.prototype, "copyPasteHandlerProvider", void 0);
125
- exports.GLSPVscodeDiagramServer = GLSPVscodeDiagramServer;
126
- //# sourceMappingURL=glsp-vscode-diagramserver.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"glsp-vscode-diagramserver.js","sourceRoot":"","sources":["../src/glsp-vscode-diagramserver.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;kFAekF;AAClF,6HAA6H;AAC7H,iDAW8B;AAC9B,kGAA8F;AAC9F,yCAAmC;AACnC,+EAAyE;AACzE,+DAAiE;AACjE,yCAAuC;AAC1B,QAAA,0BAA0B,GAAG,sBAAsB,CAAC;AACpD,QAAA,qBAAqB,GAAG,iBAAiB,CAAC;AAEvD,MAAa,uBAAwB,SAAQ,2BAAkB;IAalD,UAAU,CAAC,QAA+B;QAC/C,IAAA,yCAAgC,EAAC,QAAQ,E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AAO,IAAI,CAAC;IAChB,CAAC;IAES,4BAA4B,CAAC,SAAiC;QACpE,IAAI,SAAS,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE;YACnC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,gBAAgB,CAAC,qBAAqB,EAAE,CAAC,CAAC;SAC/E;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;IAES,uBAAuB,CAAC,MAAyB;QACvD,OAAQ,MAAc,CAAC,kCAA0B,CAAC,KAAK,IAAI,CAAC;IAChE,CAAC;CACJ;AA5FG;IAAC,IAAA,kBAAM,EAAC,cAAK,CAAC,gBAAgB,CAAC;8BACH,oCAAgB;iEAAC;AAE7C;IAAC,IAAA,kBAAM,EAAC,oBAAS,CAAC;;0DACa;AAE/B;IAAC,IAAA,kBAAM,EAAC,8CAAwB,CAAC;;qEACwB;AAEzD;IAAC,IAAA,kBAAM,EAAC,sDAAwB,CAAC;;yEAC4B;AAXjE,0DA6FC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"services.d.ts","sourceRoot":"","sources":["../src/services.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;kFAekF;AAElF,MAAM,WAAW,SAAS;IACtB,WAAW,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAAI,CAAC;CACvC;AAED,eAAO,MAAM,SAAS,eAAsB,CAAC;AAE7C,MAAM,WAAW,mBAAmB;IAChC,SAAS,CAAC,EAAE,SAAS,CAAC;CACzB"}
package/lib/services.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VsCodeApi = void 0;
4
- exports.VsCodeApi = Symbol('VsCodeApi');
5
- //# sourceMappingURL=services.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"services.js","sourceRoot":"","sources":["../src/services.ts"],"names":[],"mappings":";;;AAqBa,QAAA,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC"}