Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a more featureful editor for the input #4

Closed
pchampin opened this issue Nov 25, 2023 · 2 comments
Closed

Add a more featureful editor for the input #4

pchampin opened this issue Nov 25, 2023 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@pchampin
Copy link
Owner

It would be nice to replace the input textarea with a more featureful editor such as Code Mirror, Ace or Monaco.

@pchampin pchampin added enhancement New feature or request help wanted Extra attention is needed labels Nov 25, 2023
@vemonet
Copy link
Contributor

vemonet commented Nov 28, 2023

I would love to see Monaco integrated. It might be a bit trickier to add, but more features, more familiar for most people, and good highlighting support

I recently had a quick try at adding Monaco to a client html/js: it is quite not well documented, but should not be too hard

Most documentation and discussions I found recommend to use require. Something like that:

require.config({ paths: { 'vs': 'https://unpkg.com/monaco-editor@latest/min/vs' }});
window.MonacoEnvironment = { getWorkerUrl: () => proxy };

let proxy = URL.createObjectURL(new Blob([`
	self.MonacoEnvironment = {
		baseUrl: 'https://unpkg.com/monaco-editor@latest/min/'
	};
	importScripts('https://unpkg.com/monaco-editor@latest/min/vs/base/worker/workerMain.js');
`], { type: 'text/javascript' }));

require(["vs/editor/editor.main"], function () {
	let editor = monaco.editor.create(document.getElementById('container'), {
		value: [
			'function x() {',
			'\tconsole.log("Hello world!");',
			'}'
		].join('\n'),
		language: 'javascript',
		theme: 'vs-dark'
	});
});

But whenever I use a require I am getting require not defined. I need to check how you are supposed to import this require in the browser, because all those examples where pretending like "it work out of the box in a HTML", but it doesn't.

That said, we can now import ESM modules inside HTML files (e.g. that's what I did with my nanopub wasm lib)

So we should not need to go through all these dirty require (this is is so ugly)

There is a nice implementation using monaco ESM module here: https://github.com/mapbox/mapbox-gl-js/blob/main/debug/standard-style.html#L68

So we can now import with import monacoLoader from 'https://cdn.jsdelivr.net/npm/@monaco-editor/loader@1.4.0/+esm'; (yeah modern JS! Not sure why they needed to add a + before esm, just to confuse people more and make sure we struggle figuring out import URLs?)

But when we try to run init the monacoLoader we get an error related to an e not defined.

@pchampin
Copy link
Owner Author

pchampin commented Dec 4, 2023

thanks a lot @vemonet for the help. We now have Monaco well integrated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants