Skip to content

Feature request: Please make the Playground editor embeddable in other web applications #5324

Closed

Description

@T18970237136

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).

Unfortunately the editor doesn't seem to have a license so that it could be used for other web applications, as discussed here: http://typescript.codeplex.com/discussions/401549

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!

Activity

  1. mhegazy commented on Oct 20, 2015

    @mhegazy
    Contributor

    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.

  2. added
    Question
    on Oct 20, 2015
  3. T18970237136 commented on Oct 21, 2015

    @T18970237136
    ContributorAuthor

    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!

  4. egamma commented on Oct 22, 2015

    @egamma
    Member

    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/)

  5. T18970237136 commented on Oct 22, 2015

    @T18970237136
    ContributorAuthor

    Hi Erich Gamma (@egamma)
    thanks a lot for your reply!

    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

    {
      "command": "ShowContent",
      "editorContent": "if (true) { var s: string = 'Hello World!'; }",
      "tsDefUrls": [
        "https://github.com/Microsoft/TypeScript/blob/master/lib/lib.core.d.ts",
        "https://example.org/myDefinition.d.ts"
      ]
    }

    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!

  6. egamma commented on Oct 22, 2015

    @egamma
    Member

    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

  7. T18970237136 commented on Oct 23, 2015

    @T18970237136
    ContributorAuthor

    OK, thank you!

  8. Artazor commented on Oct 25, 2015

    @Artazor
    Contributor

    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!

  9. hiyelbaz commented on Nov 9, 2015

    @hiyelbaz

    +1

  10. kgusarov commented on Nov 9, 2015

    @kgusarov

    +1

  11. vadkart commented on Nov 9, 2015

    @vadkart

    +1

  12. nrshvch commented on Nov 9, 2015

    @nrshvch

    ++

  13. wonderwhy-er commented on Nov 9, 2015

    @wonderwhy-er

    +1

  14. FabianLauer commented on Nov 10, 2015

    @FabianLauer

    +1

  15. domotenko commented on Nov 11, 2015

    @domotenko

    it would be great

  16. pkotov commented on Nov 16, 2015

    @pkotov

    +1

  17. Artazor commented on Nov 17, 2015

    @Artazor
    Contributor
  18. added
    Fixed
    on Nov 18, 2015
  19. kitsonk commented on Nov 18, 2015

    @kitsonk
    Contributor

    By the way, the open sourcing of the whole of VSC is totally awesome! Hopefully it will help out everyone.

  20. Artazor commented on Nov 19, 2015

    @Artazor
    Contributor

    If it is what I'm thinking about - it's awesome!

  21. T18970237136 commented on Nov 20, 2015

    @T18970237136
    ContributorAuthor

    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:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8" />
    <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
    </head>
    <body>
    <h1>Test Monaco</h1>
    
    <div id="typescriptEditor"></div>
    
    <script type="text/javascript">
            var require = {
                baseUrl: "/"
            };
    </script>
    <script type="text/javascript" src="vs/loader.js"></script>
    <script type="text/javascript" src="vs/editor/editor.main.js"></script>
    <script type="text/javascript">
    
    if (!window.console.info) {
        window.console. info = function(){}
    }
    
    (function () {
        'use strict';
    
        var domnode = document.getElementById('typescriptEditor')
        var typescriptMode = null;
    
        require(['vs/editor/editor.main'], function () {
            editorLoaded = true;
    
            Monaco.Editor.getOrCreateMode('text/typescript').then(function (mode) {
                typescriptMode = mode;
    
                var editor = Monaco.Editor.create(domnode, {
                    value: '',
                    mode: 'text/plain',
                    fontIsMonospace: true,
                    suggestOnTriggerCharacters: true,
                    showTypeScriptWarnings: false
                });
            });
    
    
        });
    
    })();
    </script>
    </body>
    </html>

    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?

    Thank you!

  22. kitsonk commented on Nov 20, 2015

    @kitsonk
    Contributor

    Probably best asked in the VSCode repository, not here T18970237136.

  23. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedQuestion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions