You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature request: Please make the Playground editor embeddable in other web applications #5324
Hi,
I think TypeScript is a great language and I really like the web-based playground editor editor due to its auto-completion/Intellisense features (which also shows method documentation, etc).
Our use case: We are developing a web application where users can type their own Javascripts/Typescripts which extend the server's functionality. When the server runs these scripts, it provides an API object with defined properties and methods.
So, TypeScript would be ideal here because we can write a .d.ts definition file containing the API definition and then present a typescript editor which uses this definition file.
Then, when the users edit their scripts they would get auto-completion with IntelliSense etc.
Currently we are trying to use one of the alternatives mentioned in the above Codeplex discussion that is based on the ACE editor (e.g. the one from basarat), but there seem to be some bugs which don't allow a smooth editor experiene, and its auto-complete feature doesn't show property types, documentation etc.
Would it be possible to release the Playground editor under a license (which wouldn't need to be opensource) that allows to embed it in other application?
Thanks!
The playground is a component that we, the TypeScript team, do not own. The VSCode team would be the authority here. We use it in the playground in the website, but can not licence it for repackaging. We have gotten this request multiple times, and the playground editor with all the intellisense support is an awesome product, and personally I would love to see it in more places.
As an alternative if the repacking won't be possible I could image a variant that would also work for us, using an iframe to embed the editor (but I don't know if this also requires a license or something like that).
Now, if there were a page similar like the one above that would accept parameters in the URL fragment (or in a POST request body) containing the script content and .d.ts definitions (either the content directly or a CORS-enabled URL reference) and a destination URL, the page could allow to edit the submitted content, and if the user clicks on a Save button, the page would do a redirect to the destination URL, containing both the edited typescript and the output javascript in the URL fragment (or as POST parameters).
Edit: In case of an iframe, I think Window.postMessage() would probably also work to allow the host window send commands to the editor in an iframe e.g. to load a specific content or send back the current editor contents, without needing to do redirects or specifying the contents in URL fragments.
That variant would also work for us, because we then could use an iframe in our configuration dialog showing the typescript page. Would something like this be possible?
T18970237136 it sounds like what you really want isn't the full TS playground, but the editor (the Monaco editor) used by the playground with the TS language service so that you can embed into your site. In addition, you would like to add a .d.ts for your API. I don't see how this could be covered using the iFrame approach. I don't recommend to go down this path.
it sounds like what you really want isn't the full TS playground, but the editor (the Monaco editor) used by the playground with the TS language service so that you can embed into your site. In addition, you would like to add a .d.ts for your API.
Yes, that is what we'd want. Sorry for not being clear.
I don't see how this could be covered using the iFrame approach. I don't recommend to go down this path.
Can you elaborate on why you don't see this being covered by an iframe approach?
I thought of using an inline-frame as an alternative if repackaging of the editor code on another (foreign) site won't possible.
In that case, e.g. the typscript page (www.typescriptlang.org) could host a static HTML page similar to the playground, containing the monaco editor. Then, a HTML page from a different host could use that page in an iframe and use window.postMessage() to send commands, e.g. to initialize the editor something like
The editor HTML page then could listen to MessageEvents to receive the commands, and in case of the above command, load the (CORS-enabled) .d.ts files and show the specified content in the editor.
Then, if the surrounding page wants to get the current editor contents (because it wants to save the state) it could send some "GetState" command, and the iframe page could in turn send a message containing the current typescript and javascript contents of the editor.
This would mean the editor library files wouldn't need to be packaged by our (or some other) site but we still would be able to use the editor in an iframe to let users edit their type-/javascripts on our website.
However, I don't know how licensing would apply here and I would understand if you don't want to host such a page.
If it would be possible to repackage the monaco editor into other sites, I would prefer that approach.
I can see that you can host the Monaco editor inside an iFrame and use postMessage to work (in fact this is his how VSO embeds the Monaco editor). However I don't think this is applicable when embedding the TS Playground, which is a particular application that uses the Monaco editor. In other words the TS Playground does too much for your scenario.
We can look into the repacking or a CDN approach in roughly +1 month
Erich Gamma (@egamma) It would be a huge step in evolving of TS-related public web tools if you'd allow to embed a MonacoEditor (with intellisense and ability to load custom .d.ts) into third-party products.
Eagerly awaiting to hear any progress in this direction!
Now, I'm trying to use the editor in a HTML page, but I don't know how to do it correctly.
I checked out the vscode repository and invoked tsc in the src folder. Then I created a HTML page in that folder using the TS playground as a template:
However, when hosting the directory in IIS Express and opening the HTML file in a browser, I'm getting errors such as
GET
http://localhost:8080/vs/editor/contrib/comment/common/color.css [HTTP/1.1 404 Not Found 16ms]
GET
http://localhost:8080/vs/editor/contrib/inPlaceReplace/common/gotoError.css [HTTP/1.1 404 Not Found 13ms]
GET
http://localhost:8080/vs/editor/contrib/referenceSearch/browser/rename.css [HTTP/1.1 404 Not Found 125ms]
TypeError: Browser.isInWebWorker is not a function browserService.js:25:17
TypeError: nls.localize is not a function pluginsRegistry.js:330:30
TypeError: EditorCommon.LineTokensBinaryEncoding is undefined tokenIterator.js:7:9
Can anybody give me some pointers how to embed the editor correctly using the TS service?
Activity
mhegazy commentedon Oct 20, 2015
The playground is a component that we, the TypeScript team, do not own. The VSCode team would be the authority here. We use it in the playground in the website, but can not licence it for repackaging. We have gotten this request multiple times, and the playground editor with all the intellisense support is an awesome product, and personally I would love to see it in more places.
//CC: Erich Gamma (@egamma), he might have more comments here.
T18970237136 commentedon Oct 21, 2015
Hi Mohamed Hegazy (@mhegazy),
thanks for your reply!
As an alternative if the repacking won't be possible I could image a variant that would also work for us, using an iframe to embed the editor (but I don't know if this also requires a license or something like that).
For example: The typescript editor currently allows to submit userdefined content in the URL fragment, e.g. http://www.typescriptlang.org/Playground#src=var%20s%3A%20string%20%3D%20%22Hello%20World!%22%3B%0A%0A%0A
Now, if there were a page similar like the one above that would accept parameters in the URL fragment (or in a POST request body) containing the script content and .d.ts definitions (either the content directly or a CORS-enabled URL reference) and a destination URL, the page could allow to edit the submitted content, and if the user clicks on a Save button, the page would do a redirect to the destination URL, containing both the edited typescript and the output javascript in the URL fragment (or as POST parameters).
Edit: In case of an iframe, I think Window.postMessage() would probably also work to allow the host window send commands to the editor in an iframe e.g. to load a specific content or send back the current editor contents, without needing to do redirects or specifying the contents in URL fragments.
That variant would also work for us, because we then could use an iframe in our configuration dialog showing the typescript page. Would something like this be possible?
Thanks!
egamma commentedon Oct 22, 2015
T18970237136 it sounds like what you really want isn't the full TS playground, but the editor (the Monaco editor) used by the playground with the TS language service so that you can embed into your site. In addition, you would like to add a .d.ts for your API. I don't see how this could be covered using the iFrame approach. I don't recommend to go down this path.
My team is currently heads down working on VS Code milestone. We can look into this request in a month or so. The editor actually has API to register an additional .d.ts which isn't exposed in the playground (check out the winjs playground: http://try.buildwinjs.com/playground/)
T18970237136 commentedon Oct 22, 2015
Hi Erich Gamma (@egamma)
thanks a lot for your reply!
Yes, that is what we'd want. Sorry for not being clear.
Can you elaborate on why you don't see this being covered by an iframe approach?
I thought of using an inline-frame as an alternative if repackaging of the editor code on another (foreign) site won't possible.
In that case, e.g. the typscript page (www.typescriptlang.org) could host a static HTML page similar to the playground, containing the monaco editor. Then, a HTML page from a different host could use that page in an iframe and use window.postMessage() to send commands, e.g. to initialize the editor something like
The editor HTML page then could listen to MessageEvents to receive the commands, and in case of the above command, load the (CORS-enabled) .d.ts files and show the specified content in the editor.
Then, if the surrounding page wants to get the current editor contents (because it wants to save the state) it could send some "GetState" command, and the iframe page could in turn send a message containing the current typescript and javascript contents of the editor.
This would mean the editor library files wouldn't need to be packaged by our (or some other) site but we still would be able to use the editor in an iframe to let users edit their type-/javascripts on our website.
However, I don't know how licensing would apply here and I would understand if you don't want to host such a page.
If it would be possible to repackage the monaco editor into other sites, I would prefer that approach.
Thanks!
egamma commentedon Oct 22, 2015
I can see that you can host the Monaco editor inside an iFrame and use postMessage to work (in fact this is his how VSO embeds the Monaco editor). However I don't think this is applicable when embedding the TS Playground, which is a particular application that uses the Monaco editor. In other words the TS Playground does too much for your scenario.
We can look into the repacking or a CDN approach in roughly +1 month
T18970237136 commentedon Oct 23, 2015
OK, thank you!
Artazor commentedon Oct 25, 2015
Erich Gamma (@egamma) It would be a huge step in evolving of TS-related public web tools if you'd allow to embed a MonacoEditor (with intellisense and ability to load custom .d.ts) into third-party products.
Eagerly awaiting to hear any progress in this direction!
hiyelbaz commentedon Nov 9, 2015
+1
kgusarov commentedon Nov 9, 2015
+1
vadkart commentedon Nov 9, 2015
+1
nrshvch commentedon Nov 9, 2015
++
wonderwhy-er commentedon Nov 9, 2015
+1
FabianLauer commentedon Nov 10, 2015
+1
domotenko commentedon Nov 11, 2015
it would be great
pkotov commentedon Nov 16, 2015
+1
Artazor commentedon Nov 17, 2015
Erich Gamma (@egamma), Any news?
RyanCavanaugh commentedon Nov 18, 2015
https://github.com/Microsoft/vscode/tree/master/src/vs/editor/browser
kitsonk commentedon Nov 18, 2015
By the way, the open sourcing of the whole of VSC is totally awesome! Hopefully it will help out everyone.
Artazor commentedon Nov 19, 2015
If it is what I'm thinking about - it's awesome!
T18970237136 commentedon Nov 20, 2015
That is relly great! Thanks a lot!
Now, I'm trying to use the editor in a HTML page, but I don't know how to do it correctly.
I checked out the vscode repository and invoked tsc in the src folder. Then I created a HTML page in that folder using the TS playground as a template:
However, when hosting the directory in IIS Express and opening the HTML file in a browser, I'm getting errors such as
Can anybody give me some pointers how to embed the editor correctly using the TS service?
Thank you!
kitsonk commentedon Nov 20, 2015
Probably best asked in the VSCode repository, not here T18970237136.