-
Notifications
You must be signed in to change notification settings - Fork 29.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add proposed webview view API #104601
Merged
Merged
Add proposed webview view API #104601
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f5e898f
Add proposed webview view API
mjbvz 02311f2
Use proper activation event
mjbvz abb8c62
Transparent background
mjbvz a0bc12b
Fix resize observer
mjbvz 8f465e1
Adding documentation
mjbvz 95179f9
Move webview view to new directory under workbench
mjbvz 8de75cf
Remove resolver
mjbvz 2a1fd61
Use enum in more places
mjbvz f548364
Hook up title and visible properties for webview views
mjbvz 83c68bd
Remove test view
mjbvz 0a9d8b8
Prefer Thenable
mjbvz 00e2d19
Add unknown view type error to collector
mjbvz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2048,4 +2048,116 @@ declare module 'vscode' { | |
notebook: NotebookDocument | undefined; | ||
} | ||
//#endregion | ||
|
||
|
||
//#region https://github.com/microsoft/vscode/issues/46585 | ||
|
||
/** | ||
* A webview based view. | ||
*/ | ||
export interface WebviewView { | ||
/** | ||
* Identifies the type of the webview view, such as `'hexEditor.dataView'`. | ||
*/ | ||
readonly viewType: string; | ||
|
||
/** | ||
* The underlying webview for the view. | ||
*/ | ||
readonly webview: Webview; | ||
|
||
/** | ||
* Event fired when the view is disposed. | ||
* | ||
* Views are disposed of in a few cases: | ||
* | ||
* - When a view is collapsed and `retainContextWhenHidden` has not been set. | ||
* - When a view is hidden by a user. | ||
* | ||
* Trying to use the view after it has been disposed throws an exception. | ||
*/ | ||
readonly onDidDispose: Event<void>; | ||
|
||
/** | ||
* Tracks if the webview is currently visible. | ||
* | ||
* Views are visible when they are on the screen and expanded. | ||
*/ | ||
readonly visible: boolean; | ||
|
||
/** | ||
* Event fired when the visibility of the view changes | ||
*/ | ||
readonly onDidChangeVisibility: Event<void>; | ||
} | ||
|
||
interface WebviewViewResolveContext<T = unknown> { | ||
/** | ||
* Persisted state from the webview content. | ||
* | ||
* To save resources, VS Code normally deallocates webview views that are not visible. For example, if the user | ||
* collapse a view or switching to another top level activity, the underlying webview document is deallocates. | ||
* | ||
* You can prevent this behavior by setting `retainContextWhenHidden` in the `WebviewOptions`. However this | ||
* increases resource usage and should be avoided wherever possible. Instead, you can use persisted state to | ||
* save off a webview's state so that it can be quickly recreated as needed. | ||
* | ||
* To save off a persisted state, inside the webview call `acquireVsCodeApi().setState()` with | ||
* any json serializable object. To restore the state again, call `getState()`. For example: | ||
* | ||
* ```js | ||
* // Within the webview | ||
* const vscode = acquireVsCodeApi(); | ||
* | ||
* // Get existing state | ||
* const oldState = vscode.getState() || { value: 0 }; | ||
* | ||
* // Update state | ||
* setState({ value: oldState.value + 1 }) | ||
* ``` | ||
* | ||
* VS Code ensures that the persisted state is saved correctly when a webview is hidden and across | ||
* editor restarts. | ||
*/ | ||
readonly state: T | undefined; | ||
} | ||
|
||
/** | ||
* Provider for creating `WebviewView` elements. | ||
*/ | ||
export interface WebviewViewProvider { | ||
/** | ||
* Revolves a webview view. | ||
* | ||
* `resolveWebviewView` is called when a view first becomes visible. This may happen when the view is | ||
* first loaded or when the user hides and then shows a view again. | ||
* | ||
* @param webviewView Webview panel to restore. The serializer should take ownership of this panel. The | ||
* provider must set the webview's `.html` and hook up all webview events it is interested in. | ||
* @param context Additional metadata about the view being resolved. | ||
* @param token Cancellation token indicating that the view being provided is no longer needed. | ||
* | ||
* @return Optional promise indicating that the view has been fully resolved. | ||
*/ | ||
resolveWebviewView(webviewView: WebviewView, context: WebviewViewResolveContext, token: CancellationToken): Promise<void> | void; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Return |
||
} | ||
|
||
namespace window { | ||
/** | ||
* Register a new provider for webview views. | ||
* | ||
* @param viewId Unique id of the view. This should match the `id` from the | ||
* `views` contribution in the package.json. | ||
* @param provider Provider for the webview views. | ||
* | ||
* @return Disposable that unregisters the provider. | ||
*/ | ||
export function registerWebviewViewProvider(viewId: string, provider: WebviewViewProvider, options?: { | ||
/** | ||
* Content settings for the webview created for this view. | ||
*/ | ||
readonly webviewOptions?: WebviewPanelOptions; | ||
}): Disposable; | ||
} | ||
//#endregion | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this won't be merged ;-)