@tomjs/vscode-webview
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

@tomjs/vscode-webview

npm node-current (scoped) NPM jsDocs.io

English | 中文

Optimize the postMessage issue between webview page and vscode extension

Wrapped the official @types/vscode-webview and added some methods.

Install

# pnpm
pnpm add @tomjs/vscode-webview

# yarn
yarn add @tomjs/vscode-webview

# npm
npm add @tomjs/vscode-webview

Documentation

Usage

WebviewApi

getState()

Get the persistent state stored for this webview.

setState(state)

Set the persistent state stored for this webview.

postMessage(message)

Post a message to the owner of the webview

post(type, message, options)

Send message

  • type: message type
  • message: message content
  • options: configuration items

postAndReceive(type, message, options): Promise

Send and receive messages

  • type: message type
  • message: message content
  • options: configuration items

on(type, success[, fail])

Listen for messages

  • type: message type
  • success: listener success callback function
  • fail: listener error callback function

off(type)

Cancel listening for messages

  • type: message type

Important Notes

v2.0.0

Breaking Updates:

  • Export the WebviewApi class wrapped by the WebviewApi of the official @types/vscode-webview
    • The postMessage method is modified to be consistent with the method of the official WebviewApi instance
    • The original postMessage and postAndReceiveMessage method names are changed to post and postAndReceive
  • Delete the WebviewApi instances: vscodeWebview and webviewApi, which need to be manually imported and instantiated

Package Sidebar

Install

npm i @tomjs/vscode-webview

Weekly Downloads

160

Version

2.0.2

License

MIT

Unpacked Size

22.7 kB

Total Files

8

Last publish

Collaborators

  • tomgao365