import { AfterViewInit } from '@angular/core' ; import { MessageService } from '../@shared' ; import { MONACO_THEMES } from './monaco-editor.themes' ; export class MonacoEditorBase implements AfterViewInit { constructor ( public messageService ) { } ngAfterViewInit ( ) { if ( this . messageService . isEditorLoaded ) { const editor = fn . get ( win , 'monaco/editor' ) ; if ( editor ) this . messageService . editorReadyUp ( ) ; } else { if ( this . messageService . isEditorLoading ) return ; this . messageService . isEditorLoading = true ; /**==================== electron ignore sta ====================*/ const loaderScript = document . createElement ( 'script' ) ; loaderScript . type = 'text/javascript' ; loaderScript . src = 'https://cdn.staticfile.org/monaco-editor/0.15.0/min/vs/loader.js' ; loaderScript . addEventListener ( 'load' , ( ) => { win . require . config ( { paths : { 'vs' : 'https://cdn.staticfile.org/monaco-editor/0.15.0/min/vs' } } ) ; win . MonacoEnvironment = { getWorkerUrl : function ( workerId , label ) { return `data:text/javascript;charset=utf-8,${ encodeURIComponent ( `
              self.MonacoEnvironment = {
                baseUrl: 'https://cdn.staticfile.org/monaco-editor/0.15.0/min/'
              };
              importScripts('https://cdn.staticfile.org/monaco-editor/0.15.0/min/vs/base/worker/workerMain.js');` ) }` ; } } ; win . require ( [ 'vs/editor/editor.main' ] , ( ) => { this . defineEditorThemes ( ) ; this . messageService . editorReadyUp ( ) ; this . messageService . isEditorLoaded = true ; this . messageService . isEditorLoading = false ; } ) ; } ) ; document . body . appendChild ( loaderScript ) ; } } defineEditorThemes ( ) { fn . forIn ( MONACO_THEMES , ( themeName , themeDetail ) => win . monaco . editor . defineTheme ( themeName , themeDetail ) ) ; } }