zotero/chrome/content/scaffold/monaco/monaco.html

78 lines
1.9 KiB
HTML
Raw Normal View History

2021-12-29 01:32:56 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Monaco</title>
<style type="text/css">
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
</style>
</head>
<body>
<div id="container" style="width: 100%; height: 100%"></div>
<script src="resource://zotero/vs/loader.js"></script>
<script>
/**
* @param {Object} [params = {}]
* @return {Promise<void>}
*/
function loadMonaco(params = {}) {
let container = document.getElementById('container');
2021-12-29 01:32:56 +00:00
require.config({ paths: { vs: 'resource://zotero/vs' } });
2021-12-29 01:32:56 +00:00
let proxy = URL.createObjectURL(
new Blob(
[`
self.MonacoEnvironment = {
baseUrl: 'resource://zotero/'
};
importScripts('resource://zotero/vs/base/worker/workerMain.js');
`],
{ type: "text/javascript" }
)
);
window.MonacoEnvironment = { getWorkerUrl: () => proxy };
2021-12-29 01:32:56 +00:00
return new Promise(resolve => require(['vs/editor/editor.main'], function () {
globalEditor = monaco;
2021-12-29 01:32:56 +00:00
monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
target: monaco.languages.typescript.ScriptTarget.ES6,
allowNonTsExtensions: true // needed for peeking definitions from in-memory models to work
});
2021-12-29 01:32:56 +00:00
editor = monaco.editor.create(container, {
theme: 'vs-dark',
language: 'javascript',
scrollBeyondLastLine: false,
minimap: { enabled: false },
// Clicking links doesn't actually work, so disable them (for now)
links: false,
insertSpaces: false,
detectIndentation: false,
...params
});
editor.getModel().setEOL(monaco.editor.EndOfLineSequence.LF);
2021-12-29 01:32:56 +00:00
window.onresize = function () {
editor.layout();
};
resolve({ monaco, editor });
}));
}
2021-12-29 01:32:56 +00:00
</script>
</body>
</html>