@@ -7127,6 +7127,129 @@ declare module 'vscode' {
71277127 deserializeWebviewPanel ( webviewPanel : WebviewPanel , state : T ) : Thenable < void > ;
71287128 }
71297129
7130+ /**
7131+ * A webview based view.
7132+ */
7133+ export interface WebviewView {
7134+ /**
7135+ * Identifies the type of the webview view, such as `'hexEditor.dataView'`.
7136+ */
7137+ readonly viewType : string ;
7138+
7139+ /**
7140+ * The underlying webview for the view.
7141+ */
7142+ readonly webview : Webview ;
7143+
7144+ /**
7145+ * View title displayed in the UI.
7146+ *
7147+ * The view title is initially taken from the extension `package.json` contribution.
7148+ */
7149+ title ?: string ;
7150+
7151+ /**
7152+ * Human-readable string which is rendered less prominently in the title.
7153+ */
7154+ description ?: string ;
7155+
7156+ /**
7157+ * Event fired when the view is disposed.
7158+ *
7159+ * Views are disposed when they are explicitly hidden by a user (this happens when a user
7160+ * right clicks in a view and unchecks the webview view).
7161+ *
7162+ * Trying to use the view after it has been disposed throws an exception.
7163+ */
7164+ readonly onDidDispose : Event < void > ;
7165+
7166+ /**
7167+ * Tracks if the webview is currently visible.
7168+ *
7169+ * Views are visible when they are on the screen and expanded.
7170+ */
7171+ readonly visible : boolean ;
7172+
7173+ /**
7174+ * Event fired when the visibility of the view changes.
7175+ *
7176+ * Actions that trigger a visibility change:
7177+ *
7178+ * - The view is collapsed or expanded.
7179+ * - The user switches to a different view group in the sidebar or panel.
7180+ *
7181+ * Note that hiding a view using the context menu instead disposes of the view and fires `onDidDispose`.
7182+ */
7183+ readonly onDidChangeVisibility : Event < void > ;
7184+
7185+ /**
7186+ * Reveal the view in the UI.
7187+ *
7188+ * If the view is collapsed, this will expand it.
7189+ *
7190+ * @param preserveFocus When `true` the view will not take focus.
7191+ */
7192+ show ( preserveFocus ?: boolean ) : void ;
7193+ }
7194+
7195+ /**
7196+ * Additional information the webview view being resolved.
7197+ *
7198+ * @param T Type of the webview's state.
7199+ */
7200+ interface WebviewViewResolveContext < T = unknown > {
7201+ /**
7202+ * Persisted state from the webview content.
7203+ *
7204+ * To save resources, VS Code normally deallocates webview documents (the iframe content) that are not visible.
7205+ * For example, when the user collapse a view or switches to another top level activity in the sidebar, the
7206+ * `WebviewView` itself is kept alive but the webview's underlying document is deallocated. It is recreated when
7207+ * the view becomes visible again.
7208+ *
7209+ * You can prevent this behavior by setting `retainContextWhenHidden` in the `WebviewOptions`. However this
7210+ * increases resource usage and should be avoided wherever possible. Instead, you can use persisted state to
7211+ * save off a webview's state so that it can be quickly recreated as needed.
7212+ *
7213+ * To save off a persisted state, inside the webview call `acquireVsCodeApi().setState()` with
7214+ * any json serializable object. To restore the state again, call `getState()`. For example:
7215+ *
7216+ * ```js
7217+ * // Within the webview
7218+ * const vscode = acquireVsCodeApi();
7219+ *
7220+ * // Get existing state
7221+ * const oldState = vscode.getState() || { value: 0 };
7222+ *
7223+ * // Update state
7224+ * setState({ value: oldState.value + 1 })
7225+ * ```
7226+ *
7227+ * VS Code ensures that the persisted state is saved correctly when a webview is hidden and across
7228+ * editor restarts.
7229+ */
7230+ readonly state : T | undefined ;
7231+ }
7232+
7233+ /**
7234+ * Provider for creating `WebviewView` elements.
7235+ */
7236+ export interface WebviewViewProvider {
7237+ /**
7238+ * Revolves a webview view.
7239+ *
7240+ * `resolveWebviewView` is called when a view first becomes visible. This may happen when the view is
7241+ * first loaded or when the user hides and then shows a view again.
7242+ *
7243+ * @param webviewView Webview view to restore. The provider should take ownership of this view. The
7244+ * provider must set the webview's `.html` and hook up all webview events it is interested in.
7245+ * @param context Additional metadata about the view being resolved.
7246+ * @param token Cancellation token indicating that the view being provided is no longer needed.
7247+ *
7248+ * @return Optional thenable indicating that the view has been fully resolved.
7249+ */
7250+ resolveWebviewView ( webviewView : WebviewView , context : WebviewViewResolveContext , token : CancellationToken ) : Thenable < void > | void ;
7251+ }
7252+
71307253 /**
71317254 * Provider for text based custom editors.
71327255 *
@@ -8280,6 +8403,40 @@ declare module 'vscode' {
82808403 */
82818404 export function registerWebviewPanelSerializer ( viewType : string , serializer : WebviewPanelSerializer ) : Disposable ;
82828405
8406+ /**
8407+ * Register a new provider for webview views.
8408+ *
8409+ * @param viewId Unique id of the view. This should match the `id` from the
8410+ * `views` contribution in the package.json.
8411+ * @param provider Provider for the webview views.
8412+ *
8413+ * @return Disposable that unregisters the provider.
8414+ */
8415+ export function registerWebviewViewProvider ( viewId : string , provider : WebviewViewProvider , options ?: {
8416+ /**
8417+ * Content settings for the webview created for this view.
8418+ */
8419+ readonly webviewOptions ?: {
8420+ /**
8421+ * Controls if the webview element itself (iframe) is kept around even when the view
8422+ * is no longer visible.
8423+ *
8424+ * Normally the webview's html context is created when the view becomes visible
8425+ * and destroyed when it is hidden. Extensions that have complex state
8426+ * or UI can set the `retainContextWhenHidden` to make VS Code keep the webview
8427+ * context around, even when the webview moves to a background tab. When a webview using
8428+ * `retainContextWhenHidden` becomes hidden, its scripts and other dynamic content are suspended.
8429+ * When the view becomes visible again, the context is automatically restored
8430+ * in the exact same state it was in originally. You cannot send messages to a
8431+ * hidden webview, even with `retainContextWhenHidden` enabled.
8432+ *
8433+ * `retainContextWhenHidden` has a high memory overhead and should only be used if
8434+ * your view's context cannot be quickly saved and restored.
8435+ */
8436+ readonly retainContextWhenHidden ?: boolean ;
8437+ } ;
8438+ } ) : Disposable ;
8439+
82838440 /**
82848441 * Register a provider for custom editors for the `viewType` contributed by the `customEditors` extension point.
82858442 *
0 commit comments