sprotty-vscode
Version:
Glue code to integrate Sprotty diagrams in VSCode extensions (extension part)
75 lines • 4.95 kB
TypeScript
/********************************************************************************
* Copyright (c) 2022 TypeFox and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { SprottyDiagramIdentifier } from 'sprotty-vscode-protocol';
import * as vscode from 'vscode';
import { Messenger } from 'vscode-messenger';
import { IWebviewEndpointManager, OpenDiagramOptions, WebviewContainer, WebviewEndpoint } from './webview-endpoint';
export interface SprottyEditorProviderOptions {
extensionUri: vscode.Uri;
viewType: string;
messenger?: Messenger;
supportedFileExtensions?: string[];
createWebviewHtml?: (identifier: SprottyDiagramIdentifier, container: WebviewContainer) => string;
configureEndpoint?: (endpoint: WebviewEndpoint) => void;
localResourceRoots?: vscode.Uri[];
}
export type CustomDocumentChangeEvent = vscode.CustomDocumentEditEvent<vscode.CustomDocument> | vscode.CustomDocumentContentChangeEvent<vscode.CustomDocument>;
/**
* Custom editor provider for rendering diagrams. This must be registered in the package.json with a `customEditors` contribution.
* The default implementation is not able to save, revert or backup the document. If you need such functionality, implement it in
* a subclass.
*/
export declare class SprottyEditorProvider implements vscode.CustomEditorProvider, IWebviewEndpointManager {
readonly options: SprottyEditorProviderOptions;
protected static viewCount: number;
protected readonly changeEmitter: vscode.EventEmitter<CustomDocumentChangeEvent>;
get onDidChangeCustomDocument(): vscode.Event<CustomDocumentChangeEvent>;
readonly documents: SprottyDocument[];
readonly messenger: Messenger;
constructor(options: SprottyEditorProviderOptions);
/**
* Find the webview endpoint of a custom editor that is currently active.
*/
findActiveWebview(): WebviewEndpoint | undefined;
/**
* Open a custom editor for the given URI.
*/
openDiagram(uri: vscode.Uri, options?: OpenDiagramOptions): Promise<WebviewEndpoint | undefined>;
openCustomDocument(uri: vscode.Uri, openContext: vscode.CustomDocumentOpenContext, cancelToken: vscode.CancellationToken): vscode.CustomDocument | Thenable<vscode.CustomDocument>;
protected disposeDocument(document: SprottyDocument): void;
resolveCustomEditor(document: SprottyDocument, webviewPanel: vscode.WebviewPanel, cancelToken: vscode.CancellationToken): Promise<void>;
protected createEndpoint(identifier: SprottyDiagramIdentifier, webviewContainer: vscode.WebviewPanel): WebviewEndpoint;
/**
* Configure the given webview panel. The default implementation sets `localResourceRoots` to the `pack` subfolder of the extension host
* and `scriptUri` to `pack/webview.js`. Please configure your bundler to generate such an output file from the Sprotty webview frontend.
* In case you need to use different settings or change the HTML content, you can override this functionality in a subclass.
*/
protected configureWebview(document: SprottyDocument, webviewPanel: vscode.WebviewPanel, cancelToken: vscode.CancellationToken): Promise<void> | void;
protected createDiagramIdentifier(document: SprottyDocument, diagramType?: string): Promise<SprottyDiagramIdentifier | undefined>;
/**
* Determine a diagram type from the given URI. The default implementation returns the `viewType` of the custom
* editor if the URI matches the `supportedFileExtensions` or no file extensions were provided.
*/
protected getDiagramType(uri: vscode.Uri): Promise<string | undefined> | string | undefined;
saveCustomDocument(document: SprottyDocument, cancellation: vscode.CancellationToken): Promise<void>;
revertCustomDocument(document: SprottyDocument, cancelToken: vscode.CancellationToken): Promise<void>;
saveCustomDocumentAs(document: SprottyDocument, destination: vscode.Uri, cancelToken: vscode.CancellationToken): Promise<void>;
backupCustomDocument(document: SprottyDocument, context: vscode.CustomDocumentBackupContext, cancelToken: vscode.CancellationToken): Promise<vscode.CustomDocumentBackup>;
}
export interface SprottyDocument extends vscode.CustomDocument {
endpoint?: WebviewEndpoint;
}
//# sourceMappingURL=sprotty-editor-provider.d.ts.map