mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
vscode-notebook-renderer: init (#45731)
* vscode-notebook-renderer: init * fixup! bad username link
This commit is contained in:
parent
b878c634d6
commit
dedd90e20c
49
types/vscode-notebook-renderer/index.d.ts
vendored
Normal file
49
types/vscode-notebook-renderer/index.d.ts
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
// Type definitions for non-npm package vscode-notebook-renderer 1.47
|
||||
// Project: https://github.com/microsoft/vscode-docs/blob/notebook/api/extension-guides/notebook.md
|
||||
// Definitions by: Connor Peet <https://github.com/connor4312>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// Minimum TypeScript Version: 3.0
|
||||
|
||||
// todo: update "Project" link above to docs site, once it becomes available
|
||||
|
||||
export interface Disposable {
|
||||
dispose(): void;
|
||||
}
|
||||
|
||||
export interface VSCodeEvent<T> {
|
||||
(listener: (e: T) => any, thisArgs?: any, disposables?: Disposable[]): Disposable;
|
||||
}
|
||||
|
||||
export interface NotebookRendererApi<T> {
|
||||
setState(value: T): void;
|
||||
getState(): T | undefined;
|
||||
|
||||
/**
|
||||
* Sends a message to the renderer extension code. Can be received in
|
||||
* the `onDidReceiveMessage` event in `NotebookCommunication`.
|
||||
*/
|
||||
postMessage(msg: unknown): void;
|
||||
|
||||
/**
|
||||
* Fired before an output is destroyed, with its output ID, or undefined if
|
||||
* all cells are about to unmount.
|
||||
*/
|
||||
onWillDestroyOutput: VSCodeEvent<{ outputId: string } | undefined>;
|
||||
|
||||
/**
|
||||
* Fired when an output is rendered. The `outputId` provided is the same
|
||||
* as the one given in `NotebookOutputRenderer.render` in the extension
|
||||
* API, and `onWillDestroyOutput`.
|
||||
*/
|
||||
onDidCreateOutput: VSCodeEvent<{ element: HTMLElement; outputId: string }>;
|
||||
|
||||
/**
|
||||
* Called when the renderer uses `postMessage` on the NotebookCommunication
|
||||
* instance for this renderer.
|
||||
*/
|
||||
onDidReceiveMessage: VSCodeEvent<any>;
|
||||
}
|
||||
|
||||
declare global {
|
||||
function acquireNotebookRendererApi(rendererId: string): NotebookRendererApi<any>;
|
||||
}
|
||||
24
types/vscode-notebook-renderer/tsconfig.json
Normal file
24
types/vscode-notebook-renderer/tsconfig.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"DOM"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"vscode-notebook-renderer-tests.ts"
|
||||
]
|
||||
}
|
||||
6
types/vscode-notebook-renderer/tslint.json
Normal file
6
types/vscode-notebook-renderer/tslint.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"npm-naming": false
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
import { NotebookRendererApi } from 'vscode-notebook-renderer';
|
||||
|
||||
const notebookApi: NotebookRendererApi<{ cool: boolean }> = acquireNotebookRendererApi('myRendererId');
|
||||
|
||||
const prevState = notebookApi.getState();
|
||||
|
||||
// $ExpectError
|
||||
prevState.cool;
|
||||
|
||||
if (prevState) {
|
||||
console.log('cool?', prevState.cool);
|
||||
}
|
||||
|
||||
notebookApi.setState({ cool: true });
|
||||
|
||||
const listener = notebookApi.onDidCreateOutput(({ element, outputId }) => {
|
||||
// $ExpectType string
|
||||
outputId;
|
||||
// $ExpectType HTMLElement
|
||||
element;
|
||||
});
|
||||
|
||||
listener.dispose();
|
||||
|
||||
notebookApi.onDidReceiveMessage(msg => {
|
||||
// $ExpectType any
|
||||
msg;
|
||||
|
||||
notebookApi.postMessage(msg);
|
||||
});
|
||||
|
||||
notebookApi.onWillDestroyOutput(evt => {
|
||||
// $ExpectType { outputId: string; } | undefined
|
||||
evt;
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user