import * as vscode from 'vscode' ; export abstract class WebPanel { private disposables : vscode . Disposable [ ] = [ ] ; protected content : string ; protected resource : string ; protected webView : vscode . Webview ; protected static createOrShowInternal < T extends WebPanel > ( content , resource , viewType , title , currentPanels , localResourceRoots , fn ) { const column = vscode . window . activeTextEditor ? vscode . window . activeTextEditor . viewColumn : undefined ; const currentPanel = currentPanels . get ( resource ) ; if ( currentPanel ) { currentPanel . setContent ( content ) ; currentPanel . panel . reveal ( column ) ; return currentPanel ; } const panel = vscode . window . createWebviewPanel ( viewType , title , column || vscode . ViewColumn . One , { enableScripts : true , retainContextWhenHidden : true , localResourceRoots } ) ; const result = fn ( panel , content , resource ) ; currentPanels . set ( resource , result ) ; return result ; } protected constructor ( protected readonly panel , content , resource , currentPanels ) { this . content = content ; this . resource = resource ; this . webView = panel . webview ; this . update ( ) ; this . panel . onDidDispose ( ( ) => this . dispose ( currentPanels ) , null , this . disposables ) ; this . panel . onDidChangeViewState ( ( ) => { if ( this . panel . visible ) { this . update ( ) ; } } , null , this . disposables ) ; } public setContent ( content ) { this . content = content ; this . update ( ) ; } protected dispose < T extends WebPanel > ( currentPanels ) { currentPanels . delete ( this . resource ) ; this . panel . dispose ( ) ; while ( this . disposables . length ) { const x = this . disposables . pop ( ) ; if ( x ) { x . dispose ( ) ; } } } protected abstract update ( ) ; }