import { Disposable, ViewKey } from "@anz-bank/vscode-sysl-model"; import { ViewModel, ViewModelDelta } from "@anz-bank/vscode-sysl-plugin"; import { URI } from "vscode-uri"; import { ViewEdit } from "./edits"; import { ViewEvent, ViewModelChangeEvent } from "./events"; import { MultiView } from "./multi/types"; /** * An abstract surface for a view to render onto. * * A view itself is also a surface, typically delegating rendering to a concrete ViewSurface. */ export interface ViewSurface extends Disposable { /** * Sets the content of the view model to {@code model}. */ setModel(model: T): Promise; /** * Modifies the content of the view model according to {@code delta}. Resolves to {@code false} * if the update cannot be applied, or {@code true} otherwise. */ updateModel(delta: D): Promise; } /** * The logical representation of a piece of custom UI presented to the user. * * All rendering instructions should go through the view's API. The particular surface that the view * renders to is an implementation detail. * * @param T The type of the view model. * @param D The type of the view model delta. */ export interface View extends ViewSurface { /** The key of the view. */ key: ViewKey; /** The model rendered by the view. */ model?: T; /** * Sets the content of the view model to {@code model}. * * If the model is changed, an {@code onDidChangeView} event will be fired. */ setModel(model: T): Promise; /** * Modifies the content of the view model according to {@code delta}. Resolves to {@code false} * if the update cannot be applied, or {@code true} otherwise. * * If the model is changed, an {@code onDidChangeView} event will be fired. */ updateModel(delta: D): Promise; } /** A view that simply delegates calls to a {@link ViewSurface}. */ export declare class SurfaceView implements View { readonly key: ViewKey; private readonly surface; model?: T; selection: T | null; constructor(key: ViewKey, surface: ViewSurface, initialModel?: T); setModel(model: T): Promise; updateModel(delta: D): Promise; dispose(): void; } /** Fake view for testing. */ export declare class FakeView implements View { readonly key: ViewKey; constructor(key: ViewKey); setModel(): Promise; updateModel(): Promise; dispose(): void; } /** * The public API for view management and subscriptions. * * Analogous to {@code vscode}'s {@code workspace} or {@code window}. A singleton instance is * exported from {@code index.ts}. */ export interface Views { /** Subscribes listener to view open events. */ onDidOpenView: (listener: (e: ViewEvent) => any) => Disposable; /** Subscribes listener to view close events. */ onDidCloseView: (listener: (e: ViewEvent) => any) => Disposable; /** Subscribes listener to view show events. */ onDidShowView: (listener: (e: ViewEvent) => any) => Disposable; /** Subscribes listener to view hide events. */ onDidHideView: (listener: (e: ViewEvent) => any) => Disposable; /** Subscribes listener to view model change events. */ onDidChangeView: (listener: (e: ViewModelChangeEvent) => any) => Disposable; acceptOpenView(view: View): void; acceptCloseView(view: View): void; acceptShowView(view: View): void; acceptHideView(view: View): void; acceptChangeView(view: View, change: D, model?: T): void; acceptOpenMultiView(docUri: URI, multiView: MultiView): void; acceptCloseMultiView(multiview: MultiView): void; getAllViews(): View[]; getViews(key: ViewKey): View[] | undefined; getMultiViews(docUri: URI): MultiView[] | undefined; openView: (key: ViewKey, model?: T) => Promise[]>; applyEdit: (edit: [ViewKey, ViewEdit[]][]) => Promise; }