aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/Monaco.svelte
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes/Monaco.svelte')
-rw-r--r--src/routes/Monaco.svelte46
1 files changed, 23 insertions, 23 deletions
diff --git a/src/routes/Monaco.svelte b/src/routes/Monaco.svelte
index 295b432..8d5d2a2 100644
--- a/src/routes/Monaco.svelte
+++ b/src/routes/Monaco.svelte
@@ -6,11 +6,10 @@
// import cssWorker from 'monaco-editor/esm/vs/language/css/css.worker?worker';
// import htmlWorker from 'monaco-editor/esm/vs/language/html/html.worker?worker';
import tsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker';
- // @ts-ignore
- import wrqTypes from '@types/webextension-polyfill/namespaces/webRequest.d.ts?raw';
- // @ts-ignore
- import evTypes from '@types/webextension-polyfill/namespaces/events.d.ts?raw';
+ import typeFiles from '$lib/webext-polyfill';
import userland from './userland.d.ts?raw';
+ // import tsconf from '$lib/tsconfig.jsonc?raw';
+ // import j5 from 'json5';
let divEl: HTMLDivElement | null = $state(null);
let editor: monaco.editor.IStandaloneCodeEditor = $state(null as any);
@@ -20,8 +19,7 @@
typeDefs = `import type { UserlandBrowser } from './userland';
declare global {
/**
- * The subset of the host extension's browser type available to the extension
- * Note: We don't properly sandbox anything. You can likely easily get access to shit outside of here from the browser global.
+ * The host extension's browser type available to the extension
*/
declare const browser: UserlandBrowser;
}
@@ -85,33 +83,35 @@ declare global {
});
if (!divEl) while (!divEl) await new Promise((rs) => setTimeout(rs, 100));
for (const [_filename, contents] of Object.entries(
- (await import('./filemap.js')).default
+ (await import('./filemap.js')).default,
)) {
Monaco.languages.typescript.typescriptDefaults.addExtraLib(
- contents
+ contents,
// ,_filename
);
}
- Monaco.languages.typescript.typescriptDefaults.addExtraLib(
- evTypes,
- 'node_modules/@types/webextension-polyfill/namespaces/events.d.ts'
- );
- Monaco.languages.typescript.typescriptDefaults.addExtraLib(
- wrqTypes,
- 'node_modules/@types/webextension-polyfill/namespaces/webRequest.d.ts'
- );
- Monaco.languages.typescript.typescriptDefaults.addExtraLib(
- `export * from './namespaces/webRequest';`,
- 'node_modules/@types/webextension-polyfill/index.d.ts'
- );
+ for (const [file, contents] of Object.entries(typeFiles).filter(([name]) =>
+ name.toLowerCase().endsWith('.ts'),
+ ))
+ Monaco.languages.typescript.typescriptDefaults.addExtraLib(
+ contents,
+ file,
+ );
Monaco.languages.typescript.typescriptDefaults.addExtraLib(
userland,
- 'node_modules/@types/redirext/userland.d.ts'
+ 'node_modules/@types/redirext/userland.d.ts',
);
Monaco.languages.typescript.typescriptDefaults.addExtraLib(
typeDefs,
- 'node_modules/@types/redirext/index.d.ts'
+ 'node_modules/@types/redirext/index.d.ts',
);
+ // try {
+ // Monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
+ // ...j5.parse(tsconf).compilerOptions,
+ // moduleResolution: undefined,
+ // allowNonTsExtensions: true,
+ // });
+ // } catch (e) {}
editor = Monaco.editor.create(divEl, {
value: defaultValue,
language: 'typescript',
@@ -124,7 +124,7 @@ declare global {
const el = document.createElement('div');
el.setAttribute(
'style',
- 'display:flex;width:100vw;height:100vh;position:fixed;left:0;top:0;align-items:center;justify-content:center;text-align:center;z-index:9999;background:#23222B;'
+ 'display:flex;width:100vw;height:100vh;position:fixed;left:0;top:0;align-items:center;justify-content:center;text-align:center;z-index:9999;background:#23222B;',
);
el.textContent = 'Popped out';
document.body.appendChild(el);