mirror of
https://github.com/zotero/zotero.git
synced 2026-10-08 03:08:19 +00:00
113 lines
No EOL
2.8 KiB
HTML
113 lines
No EOL
2.8 KiB
HTML
<!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;
|
|
}
|
|
.monaco-editor .empty-editor-overlay {
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
right: 0;
|
|
padding: 0 64px;
|
|
color: #ffffff8c; /* dark fill-secondary */
|
|
font-size: 12px;
|
|
line-height: 1.5;
|
|
pointer-events: none;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div id="container" style="width: 100%; height: 100%"></div>
|
|
|
|
<script src="resource://zotero/vs/loader.js"></script>
|
|
<script>
|
|
/**
|
|
* @param {Object} [params = {}]
|
|
* @param {string} [params.emptyOverlayMessage] Optional content for the empty overlay
|
|
* @return {Promise<void>}
|
|
*/
|
|
function loadMonaco(params = {}) {
|
|
let container = document.getElementById('container');
|
|
|
|
require.config({ paths: { vs: 'resource://zotero/vs' } });
|
|
|
|
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 };
|
|
|
|
return new Promise(resolve => require(['vs/editor/editor.main'], function () {
|
|
globalEditor = monaco;
|
|
|
|
monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
|
|
allowNonTsExtensions: true // needed for peeking definitions from in-memory models to work
|
|
});
|
|
|
|
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);
|
|
|
|
|
|
// Display overlay message when editor is empty, if specified
|
|
if (params.emptyOverlayMessage) {
|
|
let overlayNode = document.createElement('div');
|
|
overlayNode.className = 'empty-editor-overlay';
|
|
|
|
overlayNode.innerText = params.emptyOverlayMessage;
|
|
let overlayWidget = {
|
|
getId: () => `empty-editor-overlay`,
|
|
getDomNode: () => overlayNode,
|
|
getPosition: () => null
|
|
};
|
|
editor.addOverlayWidget(overlayWidget);
|
|
|
|
function update() {
|
|
let overlayShown = editor.getModel().getValue() === "";
|
|
overlayNode.style.display = overlayShown ? '' : 'none';
|
|
}
|
|
|
|
overlayNode.addEventListener('click', () => editor.focus());
|
|
editor.onDidChangeModelContent(update)
|
|
update();
|
|
}
|
|
|
|
window.onresize = function () {
|
|
editor.layout();
|
|
};
|
|
|
|
resolve({ monaco, editor });
|
|
}));
|
|
}
|
|
</script>
|
|
|
|
</body>
|
|
</html> |