Last active
October 1, 2020 21:04
-
-
Save ljmotta/4ec3d599c1c0ccdc8d10d83de678139a to your computer and use it in GitHub Desktop.
TodoListViewVSCode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { init } from "todo-list-view/dist/envelope"; | |
declare global { | |
export const acquireVsCodeApi: any; | |
} | |
init({ | |
container: document.body, | |
bus: acquireVsCodeApi(), | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"activationEvents": [ | |
"*" | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"contributes": { | |
"menus": { | |
"editor/context": [ | |
{ | |
"command": "kogito-tooling-examples.todo-list-view.add-item" | |
} | |
] | |
}, | |
"commands": [ | |
{ | |
"command": "kogito-tooling-examples.todo-list-view", | |
"title": "Open list", | |
"category": "TODO" | |
}, | |
{ | |
"command": "kogito-tooling-examples.todo-list-view.add-item", | |
"title": "TODO: Add item(s)" | |
}, | |
{ | |
"command": "kogito-tooling-examples.todo-list-view.mark-all-as-completed", | |
"title": "Mark all as completed", | |
"category": "TODO" | |
} | |
] | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"engines": { | |
"vscode": "^1.46.0" | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"main": "./dist/extension.js", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"publisher": "kogito-tooling-examples", | |
"name": "todo-list-view-vscode-extension", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const webviewPanel = vscode.window.createWebviewPanel(pageId, this.envelopeLocator.title, ViewColumn.Beside, { | |
retainContextWhenHidden: true, | |
enableCommandUris: true, | |
enableScripts: true, | |
localResourceRoots: [vscode.Uri.file(this.context.extensionPath)], | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as vscode from "vscode"; | |
import { TodoListChannelApi } from "../api"; | |
export class TodoListWebview { | |
constructor( | |
private readonly context: vscode.ExtensionContext, | |
private readonly envelopeLocator: { | |
targetOrigin: string; | |
title: string; | |
envelopePath: string; | |
}, | |
private readonly api: TodoListChannelApi | |
) {} | |
public open(pageId: string, opts: { onClose: () => void }) { | |
... | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const envelopeServer: EnvelopeServer<TodoListChannelApi, TodoListEnvelopeApi> = new EnvelopeServer( | |
{ postMessage: (message) => webviewPanel.webview.postMessage(message) }, | |
this.envelopeLocator.targetOrigin, | |
() => | |
envelopeServer.client.request( | |
"todoList__init", | |
{ origin: envelopeServer.origin, envelopeServerId: envelopeServer.id }, | |
{ user: "Tiago" } | |
) | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const scriptSrc = webviewPanel.webview | |
.asWebviewUri(Uri.file(this.context.asAbsolutePath(this.envelopeLocator.envelopePath))) | |
.toString(); | |
webviewPanel.webview.html = `<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<style> | |
html, body, div#envelope-app { | |
margin: 0; | |
border: 0; | |
padding: 10px; | |
} | |
</style> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
</head> | |
<body> | |
<div id="envelope-app" /> | |
<script src="${scriptSrc}"></script> | |
</body> | |
</html>`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.context.subscriptions.push( | |
webviewPanel.webview.onDidReceiveMessage( | |
(msg) => envelopeServer.receive(msg, this.api), | |
webviewPanel.webview, | |
this.context.subscriptions | |
) | |
); | |
webviewPanel.onDidDispose( | |
() => { | |
envelopeServer.stopInitPolling(); | |
opts.onClose(); | |
}, | |
webviewPanel.webview, | |
this.context.subscriptions | |
); | |
envelopeServer.startInitPolling(); | |
return envelopeServer.client; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment