Browse Source

fix: monaco cross origin worker loading

pull/7218/head
Pranav C 11 months ago committed by Ramesh Mane
parent
commit
7cf4fa02c9
  1. 18
      packages/nc-gui/components/monaco/Editor.vue
  2. 18
      packages/nc-gui/plugins/monaco.ts

18
packages/nc-gui/components/monaco/Editor.vue

@ -1,9 +1,13 @@
<script setup lang="ts">
import JsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker'
import EditorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker'
import TypescriptWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker'
import 'monaco-editor/esm/vs/basic-languages/javascript/javascript.contribution'
import 'monaco-editor/esm/vs/basic-languages/typescript/typescript.contribution'
import EditorWorkerUrl from 'monaco-editor/esm/vs/editor/editor.worker?worker&url'
import TsWorkerUrl from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker&url'
import JsonWorkerUrl from 'monaco-editor/esm/vs/language/json/json.worker?worker&url'
import type { editor as MonacoEditor } from 'monaco-editor'
import { deepCompare, isDrawerOrModalExist, onMounted, ref, watch } from '#imports'
import { deepCompare, isDrawerOrModalExist, onMounted, ref, watch, initWorker } from '#imports'
interface Props {
modelValue: string | Record<string, any>
@ -49,11 +53,11 @@ self.MonacoEnvironment = {
getWorker(_: any, label: string) {
switch (label) {
case 'json':
return new JsonWorker()
return initWorker(JsonWorkerUrl)
case 'typescript':
return new TypescriptWorker()
return initWorker(TsWorkerUrl)
default:
return new EditorWorker()
return initWorker(EditorWorkerUrl)
}
},
}

18
packages/nc-gui/plugins/monaco.ts

@ -1,18 +0,0 @@
import 'monaco-editor/esm/vs/basic-languages/javascript/javascript.contribution'
import 'monaco-editor/esm/vs/basic-languages/typescript/typescript.contribution'
import EditorWorkerUrl from 'monaco-editor/esm/vs/editor/editor.worker?worker&url'
import TsWorkerUrl from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker&url'
import JsonWorkerUrl from 'monaco-editor/esm/vs/language/json/json.worker?worker&url'
import { initWorker } from '#imports'
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
window.MonacoEnvironment = {
getWorker(_: string, label: string) {
if (label === 'typescript' || label === 'javascript') return initWorker(TsWorkerUrl)
if (label === 'json') return initWorker(JsonWorkerUrl)
return initWorker(EditorWorkerUrl)
},
}
Loading…
Cancel
Save