sprotty-vscode
Version:
Glue code to integrate Sprotty diagrams in VSCode extensions (extension part)
69 lines • 3.84 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 WebviewPanelManagerOptions {
extensionUri: vscode.Uri;
messenger?: Messenger;
defaultDiagramType?: string;
supportedFileExtensions?: string[];
singleton?: boolean;
createWebviewHtml?: (identifier: SprottyDiagramIdentifier, container: WebviewContainer) => string;
configureEndpoint?: (endpoint: WebviewEndpoint) => void;
localResourceRoots?: vscode.Uri[];
}
export interface OpenPanelOptions extends OpenDiagramOptions {
preserveFocus?: boolean;
}
/**
* This class manages freestyle webview panels. In contrast to custom editor webviews or webview views,
* VS Code does not prescribe a specific lifecycle to webview panels, so this service provides a means
* to keep track of the opened diagram webviews.
*/
export declare class WebviewPanelManager implements IWebviewEndpointManager {
readonly options: WebviewPanelManagerOptions;
protected static viewCount: number;
readonly endpoints: WebviewEndpoint[];
readonly messenger: Messenger;
constructor(options: WebviewPanelManagerOptions);
/**
* Find the webview endpoint of a webview panel that is currently active.
*/
findActiveWebview(): WebviewEndpoint | undefined;
/**
* Open a webview panel for the given URI. Depending on the `singleton` option, this either replaces a
* previously opened diagram or creates a new panel.
*/
openDiagram(uri: vscode.Uri, options?: OpenPanelOptions): Promise<WebviewEndpoint | undefined>;
protected createEndpoint(identifier: SprottyDiagramIdentifier): WebviewEndpoint;
/**
* Create and configure a 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 createWebview(identifier: SprottyDiagramIdentifier): vscode.WebviewPanel;
protected createDiagramIdentifier(uri: vscode.Uri, diagramType?: string): Promise<SprottyDiagramIdentifier | undefined>;
/**
* Determine a diagram type from the given URI. The default implementation returns the `defaultDiagramType` option
* if the URI matches the `supportedFileExtensions` or no file extensions were provided. If no default diagram type
* was provided, the file extension is used instead.
*/
protected getDiagramType(uri: vscode.Uri): Promise<string | undefined> | string | undefined;
protected didCloseWebview(endpoint: WebviewEndpoint): void;
}
//# sourceMappingURL=webview-panel-manager.d.ts.map