import { TextEditor , Uri , ViewColumn } from "vscode" ; import { DocumentContentManagerInterface } from "./documentContentManagerInterface" ; import { HtmlPreview , SourceType } from "../util/htmlPreview" ; export class MermaidDocumentContentManager implements DocumentContentManagerInterface { private _editor : TextEditor ; public constructor ( editor ) { this . _editor = editor ; return this ; } public editor ( ) { return this . _editor ; } public async createContentSnippet ( ) { let editor = this . _editor ; if ( ! editor || ! editor . document ) { return HtmlPreview . errorSnippet ( this . getWindowErrorMessage ( ) ) ; } let previewSnippet = this . generatePreviewSnippet ( editor ) ; if ( ! previewSnippet || previewSnippet . length <= 0 ) { return HtmlPreview . errorSnippet ( this . getErrorMessage ( ) ) ; } console . info ( "previewSnippet = " + previewSnippet ) ; return previewSnippet ; } public sendPreviewCommand ( previewUri , displayColumn ) { return HtmlPreview . sendPreviewCommand ( previewUri , displayColumn ) ; } private getErrorMessage ( ) { return `Active editor doesn't show a Mermaid document - no properties to preview.` ; } private getWindowErrorMessage ( ) { return `No Active editor - no properties to preview.` ; } private MermaidSampleFullSnippet ( properties ) { return HtmlPreview . createRemoteSource ( SourceType . CUSTOM_MERMAID_SAMPLE , properties ) ; } private getSelectedCSSProperity ( editor ) { if ( ! editor || ! editor . document ) { return HtmlPreview . errorSnippet ( this . getWindowErrorMessage ( ) ) ; } return editor . document . getText ( ) ; } private generatePreviewSnippet ( editor ) { if ( ! editor ) { return HtmlPreview . errorSnippet ( this . getWindowErrorMessage ( ) ) ; } var cssProperty = this . getSelectedCSSProperity ( editor ) ; if ( ! cssProperty || cssProperty . length <= 0 ) { return HtmlPreview . errorSnippet ( this . getErrorMessage ( ) ) ; } return this . MermaidSampleFullSnippet ( cssProperty ) ; } }