@saber2pr/vscode-webview

Vscode Webview Utils.

Usage no npm install needed!

<script type="module">
  import saber2prVscodeWebview from 'https://cdn.skypack.dev/@saber2pr/vscode-webview';
</script>

README

@saber2pr/vscode-webview

vscode webview utils.

yarn add @saber2pr/vscode-webview

Feature

import {
  callService,
  createServiceHandler,
  Pair,
} from '@saber2pr/vscode-webview'

// service type define
export type Services = {
  sayHello: Pair<any, any>
}

const handleServiceMessage = createServiceHandler<Services>({
  sayHello: () => vscode.window.showInformationMessage('Hello! Webview!'),
})

// extension.ts
webviewPanel.webview.onDidReceiveMessage(
  message => handleServiceMessage(webviewPanel, message),
  null,
  context.subscriptions
)

// web
callService<Services, 'sayHello'>('sayHello', null).then(res => {})