@eclipse-glsp/vscode-integration-webview 1.1.0-RC07 → 1.1.0-RC09

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 (46) hide show
  1. package/README.md +1 -1
  2. package/lib/copy-paste-handler-provider.d.ts +1 -1
  3. package/lib/copy-paste-handler-provider.d.ts.map +1 -1
  4. package/lib/{diagram-identifer.d.ts → diagram-identifier.d.ts} +8 -2
  5. package/lib/diagram-identifier.d.ts.map +1 -0
  6. package/lib/{diagram-identifer.js → diagram-identifier.js} +11 -5
  7. package/lib/diagram-identifier.js.map +1 -0
  8. package/lib/extension-action-handler.d.ts +5 -5
  9. package/lib/extension-action-handler.d.ts.map +1 -1
  10. package/lib/extension-action-handler.js.map +1 -1
  11. package/lib/glsp-diagram-widget.d.ts +35 -0
  12. package/lib/glsp-diagram-widget.d.ts.map +1 -0
  13. package/lib/glsp-diagram-widget.js +137 -0
  14. package/lib/glsp-diagram-widget.js.map +1 -0
  15. package/lib/glsp-starter.d.ts +9 -4
  16. package/lib/glsp-starter.d.ts.map +1 -1
  17. package/lib/glsp-starter.js +24 -19
  18. package/lib/glsp-starter.js.map +1 -1
  19. package/lib/glsp-vscode-diagramserver.d.ts +10 -4
  20. package/lib/glsp-vscode-diagramserver.d.ts.map +1 -1
  21. package/lib/glsp-vscode-diagramserver.js +21 -3
  22. package/lib/glsp-vscode-diagramserver.js.map +1 -1
  23. package/lib/index.d.ts +6 -1
  24. package/lib/index.d.ts.map +1 -1
  25. package/lib/index.js +6 -1
  26. package/lib/index.js.map +1 -1
  27. package/lib/services.d.ts +24 -0
  28. package/lib/services.d.ts.map +1 -0
  29. package/lib/services.js +5 -0
  30. package/lib/services.js.map +1 -0
  31. package/package.json +14 -15
  32. package/src/copy-paste-handler-provider.ts +1 -1
  33. package/src/{diagram-identifer.ts → diagram-identifier.ts} +16 -4
  34. package/src/extension-action-handler.ts +4 -4
  35. package/src/glsp-diagram-widget.ts +136 -0
  36. package/src/glsp-starter.ts +32 -25
  37. package/src/glsp-vscode-diagramserver.ts +23 -3
  38. package/src/index.ts +6 -1
  39. package/src/services.ts +26 -0
  40. package/lib/diagram-identifer.d.ts.map +0 -1
  41. package/lib/diagram-identifer.js.map +0 -1
  42. package/lib/glsp-vscode-diagram-widget.d.ts +0 -6
  43. package/lib/glsp-vscode-diagram-widget.d.ts.map +0 -1
  44. package/lib/glsp-vscode-diagram-widget.js +0 -51
  45. package/lib/glsp-vscode-diagram-widget.js.map +0 -1
  46. package/src/glsp-vscode-diagram-widget.ts +0 -42
package/lib/index.js CHANGED
@@ -15,7 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  /********************************************************************************
18
- * Copyright (c) 2020 EclipseSource and others.
18
+ * Copyright (c) 2020-2023 EclipseSource and others.
19
19
  *
20
20
  * This program and the accompanying materials are made available under the
21
21
  * terms of the Eclipse Public License v. 2.0 which is available at
@@ -29,6 +29,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  *
30
30
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
31
31
  ********************************************************************************/
32
+ __exportStar(require("./copy-paste-handler-provider"), exports);
33
+ __exportStar(require("./diagram-identifier"), exports);
34
+ __exportStar(require("./extension-action-handler"), exports);
35
+ __exportStar(require("./glsp-diagram-widget"), exports);
32
36
  __exportStar(require("./glsp-starter"), exports);
33
37
  __exportStar(require("./glsp-vscode-diagramserver"), exports);
38
+ __exportStar(require("./services"), exports);
34
39
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;kFAckF;AAClF,iDAA+B;AAC/B,8DAA4C"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;kFAckF;AAClF,gEAA8C;AAC9C,uDAAqC;AACrC,6DAA2C;AAC3C,wDAAsC;AACtC,iDAA+B;AAC/B,8DAA4C;AAC5C,6CAA2B"}
@@ -0,0 +1,24 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2022 TypeFox and others.
3
+ * Modifications: 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
+ export interface VsCodeApi {
18
+ postMessage: (message: any) => void;
19
+ }
20
+ export declare const VsCodeApi: unique symbol;
21
+ export interface GLSPStarterServices {
22
+ vscodeApi?: VsCodeApi;
23
+ }
24
+ //# sourceMappingURL=services.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,5 @@
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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"services.js","sourceRoot":"","sources":["../src/services.ts"],"names":[],"mappings":";;;AAqBa,QAAA,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,8 +1,7 @@
1
1
  {
2
2
  "name": "@eclipse-glsp/vscode-integration-webview",
3
- "version": "1.1.0-RC07",
3
+ "version": "1.1.0-RC09",
4
4
  "description": "Integration of a GLSP diagram in a VS Code extensions (WebView part)",
5
- "license": "(EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0)",
6
5
  "keywords": [
7
6
  "vscode",
8
7
  "graph",
@@ -12,13 +11,14 @@
12
11
  ],
13
12
  "homepage": "https://www.eclipse.org/glsp/",
14
13
  "bugs": "https://github.com/eclipse-glsp/glsp/issues",
15
- "author": {
16
- "name": "Eclipse GLSP"
17
- },
18
14
  "repository": {
19
15
  "type": "git",
20
16
  "url": "https://github.com/eclipse-glsp/glsp-vscode-integration.git"
21
17
  },
18
+ "license": "(EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0)",
19
+ "author": {
20
+ "name": "Eclipse GLSP"
21
+ },
22
22
  "contributors": [
23
23
  {
24
24
  "name": "Eclipse GLSP Project",
@@ -26,18 +26,13 @@
26
26
  "url": "https://projects.eclipse.org/projects/ecd.glsp"
27
27
  }
28
28
  ],
29
+ "main": "lib/index",
30
+ "types": "lib/index",
29
31
  "files": [
30
32
  "lib",
31
33
  "src",
32
34
  "css"
33
35
  ],
34
- "dependencies": {
35
- "@eclipse-glsp/client": "1.1.0-RC07",
36
- "sprotty-vscode-webview": "~0.3.1"
37
- },
38
- "devDependencies": {
39
- "reflect-metadata": "^0.1.13"
40
- },
41
36
  "scripts": {
42
37
  "build": "tsc -b",
43
38
  "clean": "rimraf lib tsconfig.tsbuildinfo ",
@@ -46,10 +41,14 @@
46
41
  "prepare": "yarn clean && yarn build",
47
42
  "watch": "tsc -w"
48
43
  },
44
+ "dependencies": {
45
+ "@eclipse-glsp/client": "1.1.0-RC09"
46
+ },
47
+ "devDependencies": {
48
+ "reflect-metadata": "^0.1.13"
49
+ },
49
50
  "publishConfig": {
50
51
  "access": "public"
51
52
  },
52
- "main": "lib/index",
53
- "types": "lib/index",
54
- "gitHead": "a1ee3f51d6de27234165d37636ac43081a378523"
53
+ "gitHead": "e60e31264c893cf01f4cbb7f80fd3648db967d25"
55
54
  }
@@ -14,7 +14,7 @@
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 { ICopyPasteHandler } from '@eclipse-glsp/client';
18
18
 
19
19
  export const CopyPasteHandlerProvider = Symbol('CopyPasteHandlerProvider');
20
20
  /**
@@ -1,5 +1,5 @@
1
1
  /********************************************************************************
2
- * Copyright (c) 2021-2022 EclipseSource and others.
2
+ * Copyright (c) 2021-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,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 { hasStringProp, InitializeResult } from '@eclipse-glsp/client';
16
+ import { AnyObject, hasStringProp, InitializeResult } from '@eclipse-glsp/client';
17
17
 
18
18
  export const GLSPDiagramIdentifier = Symbol('GLSPDiagramIdentifier');
19
19
 
@@ -26,10 +26,22 @@ export interface GLSPDiagramIdentifier {
26
26
 
27
27
  export function isDiagramIdentifier(object: any): object is GLSPDiagramIdentifier {
28
28
  return (
29
- object !== undefined &&
30
- typeof object === 'object' &&
29
+ AnyObject.is(object) && //
31
30
  hasStringProp(object, 'clientId') &&
32
31
  hasStringProp(object, 'diagramType') &&
33
32
  hasStringProp(object, 'uri')
34
33
  );
35
34
  }
35
+
36
+ // ----------------------------------
37
+ // Initial Handshake
38
+
39
+ export interface WebviewReadyMessage {
40
+ readyMessage: string;
41
+ }
42
+
43
+ export namespace WebviewReadyMessage {
44
+ export function is(object: unknown): object is WebviewReadyMessage {
45
+ return AnyObject.is(object) && hasStringProp(object, 'readyMessage');
46
+ }
47
+ }
@@ -1,5 +1,5 @@
1
1
  /********************************************************************************
2
- * Copyright (c) 2021-2022 EclipseSource and others.
2
+ * Copyright (c) 2021-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,8 +14,8 @@
14
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  ********************************************************************************/
16
16
  import { Action, ActionHandlerRegistry, IActionHandler, IActionHandlerInitializer, ICommand } from '@eclipse-glsp/client';
17
- import { SprottyDiagramIdentifier } from 'sprotty-vscode-webview';
18
- import { VsCodeApi } from 'sprotty-vscode-webview/lib/services';
17
+ import { GLSPDiagramIdentifier } from './diagram-identifier';
18
+ import { VsCodeApi } from './services';
19
19
 
20
20
  /**
21
21
  * Delegates actions that should be handled inside of the glsp vscode extension instead
@@ -25,7 +25,7 @@ import { VsCodeApi } from 'sprotty-vscode-webview/lib/services';
25
25
  export class GLSPVscodeExtensionActionHandler implements IActionHandler, IActionHandlerInitializer {
26
26
  constructor(
27
27
  protected readonly actionKinds: string[],
28
- protected readonly diagramIdentifier: SprottyDiagramIdentifier,
28
+ protected readonly diagramIdentifier: GLSPDiagramIdentifier,
29
29
  protected vscodeApi: VsCodeApi
30
30
  ) {}
31
31
 
@@ -0,0 +1,136 @@
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
+ DiagramServerProxy,
20
+ EnableToolPaletteAction,
21
+ IActionDispatcher,
22
+ ModelSource,
23
+ RequestModelAction,
24
+ RequestTypeHintsAction,
25
+ ServerStatusAction,
26
+ TYPES,
27
+ ViewerOptions
28
+ } from '@eclipse-glsp/client';
29
+ import { inject, injectable, postConstruct } from 'inversify';
30
+ import { GLSPDiagramIdentifier } from './diagram-identifier';
31
+
32
+ export const GLSPDiagramWidgetFactory = Symbol('GLSPDiagramWidgetFactory');
33
+ export type GLSPDiagramWidgetFactory = () => GLSPDiagramWidget;
34
+
35
+ @injectable()
36
+ export abstract class GLSPDiagramWidget {
37
+ @inject(GLSPDiagramIdentifier)
38
+ protected diagramIdentifier: GLSPDiagramIdentifier;
39
+ @inject(TYPES.IActionDispatcher)
40
+ readonly actionDispatcher: IActionDispatcher;
41
+ @inject(TYPES.ModelSource)
42
+ readonly modelSource: ModelSource;
43
+ @inject(TYPES.ViewerOptions)
44
+ protected viewerOptions: ViewerOptions;
45
+
46
+ protected statusIconDiv: HTMLDivElement;
47
+ protected statusMessageDiv: HTMLDivElement;
48
+
49
+ @postConstruct()
50
+ initialize(): void {
51
+ this.initializeHtml();
52
+ this.dispatchInitialActions();
53
+ }
54
+
55
+ protected initializeHtml(): void {
56
+ const containerDiv = document.getElementById(this.diagramIdentifier.clientId + '_container');
57
+ if (containerDiv) {
58
+ const svgContainer = document.createElement('div');
59
+ svgContainer.id = this.viewerOptions.baseDiv;
60
+ containerDiv.appendChild(svgContainer);
61
+
62
+ const hiddenContainer = document.createElement('div');
63
+ hiddenContainer.id = this.viewerOptions.hiddenDiv;
64
+ 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
+ }
77
+ }
78
+
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
+ }
121
+ }
122
+
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
+ }
131
+ }
132
+ }
133
+
134
+ export function decodeURI(uri: string): string {
135
+ return decodeURIComponent(uri.replace(/\+/g, ' '));
136
+ }
@@ -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,6 +14,7 @@
13
14
  *
14
15
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
16
  ********************************************************************************/
17
+ // based on https://github.com/eclipse-sprotty/sprotty-vscode/blob/v0.3.0/sprotty-vscode-webview/src/sprotty-starter.ts
16
18
  import {
17
19
  configureServerActions,
18
20
  DiagramServerProxy,
@@ -25,22 +27,30 @@ import {
25
27
  TYPES
26
28
  } from '@eclipse-glsp/client';
27
29
  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
30
  import { CopyPasteHandlerProvider } from './copy-paste-handler-provider';
37
- import { GLSPDiagramIdentifier, isDiagramIdentifier } from './diagram-identifer';
31
+ import { GLSPDiagramIdentifier, isDiagramIdentifier, WebviewReadyMessage } from './diagram-identifier';
38
32
  import { GLSPVscodeExtensionActionHandler } from './extension-action-handler';
39
- import { GLSPVscodeDiagramWidget } from './glsp-vscode-diagram-widget';
33
+ import { GLSPDiagramWidget, GLSPDiagramWidgetFactory } from './glsp-diagram-widget';
40
34
  import { GLSPVscodeDiagramServer } from './glsp-vscode-diagramserver';
35
+ import { GLSPStarterServices, VsCodeApi } from './services';
36
+
37
+ declare function acquireVsCodeApi(): VsCodeApi;
38
+
39
+ export abstract class GLSPStarter {
40
+ protected container?: Container;
41
+ protected vscodeApi: VsCodeApi;
42
+
43
+ constructor(services: GLSPStarterServices = {}) {
44
+ this.vscodeApi = services.vscodeApi ?? acquireVsCodeApi();
45
+ this.sendReadyMessage();
46
+ this.acceptDiagramIdentifier();
47
+ }
41
48
 
42
- export abstract class GLSPStarter extends SprottyStarter {
43
- protected override acceptDiagramIdentifier(): void {
49
+ protected sendReadyMessage(): void {
50
+ this.vscodeApi.postMessage({ readyMessage: 'Sprotty Webview ready' } as WebviewReadyMessage);
51
+ }
52
+
53
+ protected acceptDiagramIdentifier(): void {
44
54
  console.log('Waiting for diagram identifier...');
45
55
  const eventListener = (message: any): void => {
46
56
  if (isDiagramIdentifier(message.data)) {
@@ -50,8 +60,8 @@ export abstract class GLSPStarter extends SprottyStarter {
50
60
  const newIdentifier = message.data as GLSPDiagramIdentifier;
51
61
  oldIdentifier.diagramType = newIdentifier.diagramType;
52
62
  oldIdentifier.uri = newIdentifier.uri;
53
- const diagramWidget = this.container.get(VscodeDiagramWidget);
54
- diagramWidget.requestModel();
63
+ const diagramWidget = this.container.get(GLSPDiagramWidget);
64
+ diagramWidget.dispatchInitialActions();
55
65
  } else {
56
66
  console.log('...received...', message);
57
67
  const diagramIdentifier = message.data as GLSPDiagramIdentifier;
@@ -60,20 +70,19 @@ export abstract class GLSPStarter extends SprottyStarter {
60
70
  if (diagramIdentifier.initializeResult) {
61
71
  configureServerActions(diagramIdentifier.initializeResult, diagramIdentifier.diagramType, this.container);
62
72
  }
63
- this.container.get(VscodeDiagramWidget);
73
+ this.container.get(GLSPDiagramWidget);
64
74
  }
65
75
  }
66
76
  };
67
77
  window.addEventListener('message', eventListener);
68
78
  }
69
79
 
70
- protected override addVscodeBindings(container: Container, diagramIdentifier: GLSPDiagramIdentifier): void {
80
+ protected abstract createContainer(diagramIdentifier: GLSPDiagramIdentifier): Container;
81
+
82
+ protected addVscodeBindings(container: Container, diagramIdentifier: GLSPDiagramIdentifier): void {
71
83
  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));
84
+ container.bind(GLSPDiagramWidget).toSelf().inSingletonScope();
85
+ container.bind(GLSPDiagramWidgetFactory).toFactory(context => () => context.container.get<GLSPDiagramWidget>(GLSPDiagramWidget));
77
86
  container.bind(GLSPDiagramIdentifier).toConstantValue(diagramIdentifier);
78
87
  container
79
88
  .bind(CopyPasteHandlerProvider)
@@ -81,16 +90,14 @@ export abstract class GLSPStarter extends SprottyStarter {
81
90
  ctx => () =>
82
91
  new Promise<ICopyPasteHandler>(resolve => resolve(ctx.container.get<ICopyPasteHandler>(TYPES.ICopyPasteHandler)))
83
92
  );
84
- container.bind(SprottyDiagramIdentifier).toService(GLSPDiagramIdentifier);
85
93
  container.bind(GLSPVscodeDiagramServer).toSelf().inSingletonScope();
86
- container.bind(VscodeDiagramServer).toService(GLSPVscodeDiagramServer);
87
94
  container.bind(TYPES.ModelSource).toService(GLSPVscodeDiagramServer);
88
95
  container.bind(DiagramServerProxy).toService(GLSPVscodeDiagramServer);
89
96
 
90
97
  this.configureExtensionActionHandler(container, diagramIdentifier);
91
98
  }
92
99
 
93
- protected configureExtensionActionHandler(container: Container, diagramIdentifier: SprottyDiagramIdentifier): void {
100
+ protected configureExtensionActionHandler(container: Container, diagramIdentifier: GLSPDiagramIdentifier): void {
94
101
  const extensionActionHandler = new GLSPVscodeExtensionActionHandler(this.extensionActionKinds, diagramIdentifier, this.vscodeApi);
95
102
  container.bind(GLSPVscodeExtensionActionHandler).toConstantValue(extensionActionHandler);
96
103
  container.bind(TYPES.IActionHandlerInitializer).toService(GLSPVscodeExtensionActionHandler);
@@ -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,27 +14,37 @@
13
14
  *
14
15
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
16
  ********************************************************************************/
17
+ // based on https://github.com/eclipse-sprotty/sprotty-vscode/blob/v0.3.0/sprotty-vscode-webview/src/vscode-diagram-server.ts
16
18
  import {
17
19
  Action,
18
20
  ActionHandlerRegistry,
19
21
  ActionMessage,
20
22
  ComputedBoundsAction,
21
23
  DeleteElementOperation,
24
+ DiagramServerProxy,
22
25
  registerDefaultGLSPServerActions,
26
+ ServerStatusAction,
23
27
  SetEditModeAction,
24
28
  TYPES
25
29
  } from '@eclipse-glsp/client';
26
30
  import { SelectionService } from '@eclipse-glsp/client/lib/features/select/selection-service';
27
31
  import { inject } from 'inversify';
28
- import { VscodeDiagramServer } from 'sprotty-vscode-webview/lib/vscode-diagram-server';
29
32
  import { CopyPasteHandlerProvider } from './copy-paste-handler-provider';
33
+ import { GLSPDiagramWidgetFactory } from './glsp-diagram-widget';
34
+ import { VsCodeApi } from './services';
30
35
  export const receivedFromServerProperty = '__receivedFromServer';
31
36
  export const localDispatchProperty = '__localDispatch';
32
37
 
33
- export class GLSPVscodeDiagramServer extends VscodeDiagramServer {
38
+ export class GLSPVscodeDiagramServer extends DiagramServerProxy {
34
39
  @inject(TYPES.SelectionService)
35
40
  protected selectionService: SelectionService;
36
41
 
42
+ @inject(VsCodeApi)
43
+ protected vscodeApi: VsCodeApi;
44
+
45
+ @inject(GLSPDiagramWidgetFactory)
46
+ protected diagramWidgetFactory: GLSPDiagramWidgetFactory;
47
+
37
48
  @inject(CopyPasteHandlerProvider)
38
49
  protected copyPasteHandlerProvider: CopyPasteHandlerProvider;
39
50
 
@@ -62,6 +73,10 @@ export class GLSPVscodeDiagramServer extends VscodeDiagramServer {
62
73
  });
63
74
  }
64
75
 
76
+ protected sendMessage(message: ActionMessage): void {
77
+ this.vscodeApi.postMessage(message);
78
+ }
79
+
65
80
  override handleLocally(action: Action): boolean {
66
81
  if (SetEditModeAction.is(action)) {
67
82
  return this.handleSetEditModeAction(action);
@@ -72,6 +87,11 @@ export class GLSPVscodeDiagramServer extends VscodeDiagramServer {
72
87
  return super.handleLocally(action);
73
88
  }
74
89
 
90
+ protected override handleServerStateAction(status: ServerStatusAction): boolean {
91
+ this.diagramWidgetFactory().setStatus(status);
92
+ return false;
93
+ }
94
+
75
95
  protected override messageReceived(data: any): void {
76
96
  const object = typeof data === 'string' ? JSON.parse(data) : data;
77
97
  if (ActionMessage.is(object) && object.action) {
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,10 @@
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';
17
+ export * from './diagram-identifier';
18
+ export * from './extension-action-handler';
19
+ export * from './glsp-diagram-widget';
16
20
  export * from './glsp-starter';
17
21
  export * from './glsp-vscode-diagramserver';
22
+ export * from './services';
@@ -0,0 +1,26 @@
1
+ /********************************************************************************
2
+ * Copyright (c) 2022 TypeFox and others.
3
+ * Modifications: 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/services.ts
18
+ export interface VsCodeApi {
19
+ postMessage: (message: any) => void;
20
+ }
21
+
22
+ export const VsCodeApi = Symbol('VsCodeApi');
23
+
24
+ export interface GLSPStarterServices {
25
+ vscodeApi?: VsCodeApi;
26
+ }
@@ -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,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,51 +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
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.decodeURI = exports.GLSPVscodeDiagramWidget = void 0;
10
- /********************************************************************************
11
- * Copyright (c) 2020-2022 EclipseSource and others.
12
- *
13
- * This program and the accompanying materials are made available under the
14
- * terms of the Eclipse Public License v. 2.0 which is available at
15
- * http://www.eclipse.org/legal/epl-2.0.
16
- *
17
- * This Source Code may also be made available under the following Secondary
18
- * Licenses when the conditions for such availability set forth in the Eclipse
19
- * Public License v. 2.0 are satisfied: GNU General Public License, version 2
20
- * with the GNU Classpath Exception which is available at
21
- * https://www.gnu.org/software/classpath/license.html.
22
- *
23
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
24
- ********************************************************************************/
25
- const client_1 = require("@eclipse-glsp/client");
26
- const inversify_1 = require("inversify");
27
- const sprotty_vscode_webview_1 = require("sprotty-vscode-webview");
28
- let GLSPVscodeDiagramWidget = class GLSPVscodeDiagramWidget extends sprotty_vscode_webview_1.VscodeDiagramWidget {
29
- initializeSprotty() {
30
- if (this.modelSource instanceof client_1.DiagramServerProxy) {
31
- this.modelSource.clientId = this.diagramIdentifier.clientId;
32
- }
33
- this.actionDispatcher.dispatch(client_1.RequestModelAction.create({
34
- options: {
35
- sourceUri: decodeURI(this.diagramIdentifier.uri),
36
- diagramType: this.diagramIdentifier.diagramType
37
- }
38
- }));
39
- this.actionDispatcher.dispatch(client_1.RequestTypeHintsAction.create());
40
- this.actionDispatcher.dispatch(client_1.EnableToolPaletteAction.create());
41
- }
42
- };
43
- GLSPVscodeDiagramWidget = __decorate([
44
- (0, inversify_1.injectable)()
45
- ], GLSPVscodeDiagramWidget);
46
- exports.GLSPVscodeDiagramWidget = GLSPVscodeDiagramWidget;
47
- function decodeURI(uri) {
48
- return decodeURIComponent(uri.replace(/\+/g, ' '));
49
- }
50
- exports.decodeURI = decodeURI;
51
- //# sourceMappingURL=glsp-vscode-diagram-widget.js.map
@@ -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"}