UNPKG

sprotty-vscode

Version:

Glue code to integrate Sprotty diagrams in VSCode extensions (extension part)

89 lines 4.23 kB
/******************************************************************************** * 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 { Action, ActionMessage } from 'sprotty-protocol'; import { SprottyDiagramIdentifier } from 'sprotty-vscode-protocol'; import * as vscode from 'vscode'; import { Messenger } from 'vscode-messenger'; import { MessageParticipant } from 'vscode-messenger-common'; export type WebviewContainer = vscode.WebviewPanel | vscode.WebviewView; export declare function isWebviewPanel(container: WebviewContainer): container is vscode.WebviewPanel; export declare function isWebviewView(container: WebviewContainer): container is vscode.WebviewView; export interface OpenDiagramOptions { diagramType?: string; reveal?: boolean; } export interface IWebviewEndpointManager { openDiagram(uri: vscode.Uri, options?: OpenDiagramOptions): Promise<WebviewEndpoint | undefined>; findActiveWebview(): WebviewEndpoint | undefined; } export interface WebviewEndpointOptions { webviewContainer: WebviewContainer; messenger: Messenger; messageParticipant: MessageParticipant; diagramServer?: ActionAcceptor; diagramServerFactory?: DiagramServerFactory; identifier?: SprottyDiagramIdentifier; } export interface ActionAcceptor { accept(action: Action): Promise<void>; } export type DiagramServerFactory = (dispatch: <A extends Action>(action: A) => Promise<void>) => ActionAcceptor; /** * Wrapper class around a webview panel or webview view. This service takes care of the communication between the webview * and the host extension. */ export declare class WebviewEndpoint { readonly webviewContainer: WebviewContainer; readonly messenger: Messenger; readonly messageParticipant: MessageParticipant; readonly diagramServer?: ActionAcceptor; diagramIdentifier?: SprottyDiagramIdentifier; protected readonly actionHandlers: Map<string, ActionHandler<any>[]>; protected readonly disposables: vscode.Disposable[]; constructor(options: WebviewEndpointOptions); private resolveWebviewReady; private readonly webviewReady; get ready(): Promise<void>; protected connect(): void; /** * Enable or disable a context variable to be used in UI contributions in the package.json file. */ protected setWebviewActiveContext(isActive: boolean): void; /** * Trigger loading of new content in the webview. The content is identified by the URI and diagram type. */ reloadContent(newIdentifier: SprottyDiagramIdentifier): Promise<void>; protected sendDiagramIdentifier(): Promise<void>; /** * Send an action to the webview to be processed by the Sprotty frontend. */ sendAction<A extends Action>(action: A | ActionMessage): Promise<void>; /** * Process an action received from the webview. */ receiveAction(message: ActionMessage): Promise<void>; /** * Add an action handler for actions that are sent or received. If one or more handlers are registered for an * action kind, the corresponding actions are sent to those handlers and are not propagated further. */ addActionHandler<A extends Action>(kind: string, handler: ActionHandler<A>): void; /** * Remove a previously registered action handler. */ removeActionHandler<A extends Action>(kind: string, handler: ActionHandler<A>): void; } export type ActionHandler<A extends Action = Action> = (action: A) => void | Promise<void>; //# sourceMappingURL=webview-endpoint.d.ts.map