Using the Monaco Editor in a browser without VSCode
Now that VS Code is open source, it also means that the Monaco Editor is open source (at-least to some extent).
I would really like to use this editor in my own web application for editing TypeScript files. The only problem is I can't find any documentation about how to do this. I know its possible because the editor is on TypeScript Playground and a few other places.
As far as I can tell, the open sourcing of VS Code is the first time the source code of the Monaco editor has been made public. Also, I think that the VS Code repository is the primary source of the Monaco editor (someone from Microsoft please confirm?).
So far, there have been many questions about using the Monaco Editor on Stack Overflow and other forums, but I have yet to see an official reply from Microsoft.
Can someone please provide some documentation on using the Monaco Editor in a web site, or perhaps release the source code of TypeScript Playground (There is nothing to hide now that we have the Monaco source in the VS Code repository).
Currently, the only thing keeping me from using TypeScript as a JavaScript replacement is the fact that I can't easily use the Monaco Editor inside of my web application. I'm currently using the ACE Editor with a Tern plugin I created. I don't want to go through all of the work of creating full Intellisense support for TypeScript inside of ACE because its a significant undertaking- Instead I'd rather contribute to the Monaco editor and use it as a replacement for ACE (and replace JavaScript with TypeScript).
+1 for this. Doing proper context code completion in CodeMirror and Ace is a nightmare. An open source editor that had good hooks to this kind of thing would be gold. We just need some docs on using it ;)
@sevin7676 you are correct that the Monaco editor is contained in the vscode repository and we are working on making the Monaco Editor more easy to consume independent of VS Code.
+1 making some docs on Monaco editor. So far this editor beats both codemirror and ace :)
This is almost same as #815
I'm eagerly awaiting this also. Don't forget to close this UserVoice suggestion when it's complete. https://visualstudio.uservoice.com/forums/293070-visual-studio-code/suggestions/7782546-release-monaco-javascript-code-editor
+1, the other options like codemirror or ace does not even come close compared with typescript playground
+1 Waiting for this!
+1 Any news on this? I'm waiting for this so I can embed the editor on our product's config page where the user can edit custom TypeScripts that are run on a server and provide our API definition. Thanks!
It is still on our backlog but it didn't make the cut for the GA milestone, sorry.
I've been using code mirror to bootstrap http://alm.tools/. Would like to integrate Monaco when it becomes available. I have time. It's a labor of love 🌹
fyi @Microsoft/vscode
+1 The editor at the typescriptlang playground is amazing! Especially the speed, intellisense, and VS look-and-feel.
Been working a lot with other code editors that offer intellisense, but none come close to Monaco. Eagerly waiting :)
Thanks for keeping us updated, @egamma
+1 yes please
:+1:
While we wait for official documentation... This HTML hosts the editor (in TypeScript mode) when served from the 'out' directory VSC builds to:
<!DOCTYPE html>
<html>
<head>
<title>VSC Editor</title>
<style>
html, body { height: 100%; margin: 0; }
.box { display: flex; flex-flow: column; height: 100%; }
.box .row { flex: 0 1 auto; }
.box .row.content { flex: 1 1 auto; }
</style>
</head>
<body>
<div class='box'>
<div class='row content' id="editor"></div>
</div>
<script type="text/javascript" src="vs/loader.js"></script>
<script type="text/javascript">
'use strict';
(function () {
require(['vs/editor/editor.main', 'vs/base/browser/ui/aria/aria'], function (main, aria) {
aria.setARIAContainer(document.body);
var editor = Monaco.Editor.create(document.getElementById('editor'), {
value: 'var foo = \'bar\';',
mode: 'text/typescript'
});
window.addEventListener('resize', function () {
editor.layout();
});
});
})();
</script>
</body>
</html>
I managed to get the editor working using something similar to darrinm's solution but I still haven't figured out how to add extra libraries to the auto completion system. The azure-based playgrounds out there seem to have a way to include code libraries but the API seems different for the version in VS Code and I haven't been able to figure it out yet :(
:+1:
@egamma do you have a rough date on when this might be available?
+1 please make it possible
+1 ,I think that this feature will bring closer to this project many people who don't use vs code yet