diff --git a/explorer-v2/package.json b/explorer-v2/package.json
index e8e167f3..520ea877 100644
--- a/explorer-v2/package.json
+++ b/explorer-v2/package.json
@@ -26,6 +26,7 @@
"@sveltejs/adapter-static": "^3.0.2",
"@sveltejs/kit": "^2.5.17",
"@sveltejs/vite-plugin-svelte": "^3.1.1",
+ "monaco-editor": "^0.50.0",
"prettier": "^3.3.2",
"prettier-plugin-svelte": "^3.2.4",
"string-replace-loader": "^3.1.0",
diff --git a/explorer-v2/src/app.html b/explorer-v2/src/app.html
index 0dbc0988..1f09c604 100644
--- a/explorer-v2/src/app.html
+++ b/explorer-v2/src/app.html
@@ -6,7 +6,6 @@
%sveltekit.head%
-
%sveltekit.body%
diff --git a/explorer-v2/src/lib/scripts/monaco-loader.js b/explorer-v2/src/lib/scripts/monaco-loader.js
index 35ece9fe..2a15ebb6 100644
--- a/explorer-v2/src/lib/scripts/monaco-loader.js
+++ b/explorer-v2/src/lib/scripts/monaco-loader.js
@@ -17,23 +17,59 @@ async function setupMonaco() {
}
}
-function appendMonacoEditorScript() {
- return new Promise((resolve) => {
- const script = document.createElement('script');
- script.src = 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.26.1/min/vs/loader.min.js';
+async function appendMonacoEditorScript() {
+ let error = new Error();
+ const urlList = [
+ 'https://cdn.jsdelivr.net/npm/monaco-editor/dev/vs/loader.min.js',
+ 'https://unpkg.com/monaco-editor@latest/min/vs/loader.js'
+ ];
+
+ /* global MONACO_EDITOR_VERSION -- Define monaco-editor version */
+ if (typeof MONACO_EDITOR_VERSION !== 'undefined') {
+ urlList.unshift(
+ `https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/${MONACO_EDITOR_VERSION}/min/vs/loader.min.js`,
+ `https://cdn.jsdelivr.net/npm/monaco-editor@${MONACO_EDITOR_VERSION}/dev/vs/loader.min.js`,
+ `https://unpkg.com/monaco-editor/${MONACO_EDITOR_VERSION}/min/vs/loader.min.js`
+ );
+ }
+ for (const url of urlList) {
+ try {
+ return await appendScript(url);
+ } catch (e) {
+ // eslint-disable-next-line no-console -- OK
+ console.warn(`Failed to retrieve resource from ${url}`);
+ error = e;
+ }
+ }
+ throw error;
+}
+
+/** Appends a script tag. */
+function appendScript(src) {
+ const script = document.createElement('script');
+
+ return new Promise((resolve, reject) => {
+ script.src = src;
script.onload = () => {
script.onload = null;
watch();
function watch() {
+ // @ts-expect-error -- global Monaco's require
if (window.require) {
resolve(script);
+
return;
}
+
setTimeout(watch, 200);
}
};
+ script.onerror = (e) => {
+ reject(e);
+ document.head.removeChild(script);
+ };
document.head.append(script);
});
}
diff --git a/explorer-v2/vite.config.js b/explorer-v2/vite.config.js
index 0c0fdd0c..bd61e831 100644
--- a/explorer-v2/vite.config.js
+++ b/explorer-v2/vite.config.js
@@ -1,5 +1,10 @@
import { sveltekit } from '@sveltejs/kit/vite';
import { resolve } from 'path';
+import { createRequire } from 'module';
+
+const { version: MONACO_EDITOR_VERSION } = createRequire(import.meta.url)(
+ 'monaco-editor/package.json'
+);
/** @type {import('vite').UserConfig} */
const config = {
@@ -20,6 +25,9 @@ const config = {
'svelte-eslint-parser': resolve('./build-system/shim/svelte-eslint-parser.js'),
'svelte/compiler': resolve('./build-system/shim/svelte/compiler.js')
}
+ },
+ define: {
+ MONACO_EDITOR_VERSION: JSON.stringify(MONACO_EDITOR_VERSION)
}
};