@@ -4,33 +4,41 @@ import {editor} from 'monaco-editor/esm/vs/editor/editor.api';
44
55import TSTLWorker = require( 'worker-loader!./tstlWorker' ) ;
66
7+ import * as URL from "url-parse" ;
8+
79document . addEventListener ( 'DOMContentLoaded' , ( ) => {
810 const container = document . getElementById ( 'example-ts' ) ;
911 const exampleLua = document . getElementById ( 'example-lua' ) ;
1012
11- if ( container && exampleLua ) {
12- let tsEditor = editor . create ( container , {
13- value :
14- `class Greeter {
15- greeting: string;
16- constructor(message: string) {
17- this.greeting = message;
13+ let example = `class Greeter {
14+ greeting: string;
15+ constructor(message: string) {
16+ this.greeting = message;
17+ }
18+ greet() {
19+ return "Hello, " + this.greeting;
20+ }
1821 }
19- greet() {
20- return "Hello, " + this.greeting;
22+
23+ let greeter = new Greeter("world");
24+
25+ let button = document.createElement('button');
26+ button.textContent = "Say Hello";
27+ button.onclick = function() {
28+ alert(greeter.greet());
29+ }
30+
31+ document.body.appendChild(button);
32+ ` ;
33+
34+ let windowUrl = new URL ( window . location . href , window . location , true ) ;
35+ if ( windowUrl . query . src ) {
36+ example = decodeURIComponent ( windowUrl . query . src ) ;
2137 }
22- }
23-
24- let greeter = new Greeter("world");
25-
26- let button = document.createElement('button');
27- button.textContent = "Say Hello";
28- button.onclick = function() {
29- alert(greeter.greet());
30- }
3138
32- document.body.appendChild(button);
33- ` ,
39+ if ( container && exampleLua ) {
40+ let tsEditor = editor . create ( container , {
41+ value : example ,
3442 language : 'typescript' ,
3543 minimap : { enabled : false } ,
3644 theme : 'vs-dark' ,
@@ -52,12 +60,15 @@ document.body.appendChild(button);
5260 const tstlWorker = new ( TSTLWorker as any ) ( ) ;
5361 tstlWorker . postMessage ( { tsStr : tsEditor . getValue ( ) } ) ;
5462
55- let timerVar : NodeJS . Timeout ;
63+ let timerVar : any ;
5664
5765 tsEditor . onDidChangeModelContent ( ( e => {
5866 clearInterval ( timerVar ) ;
5967 // wait one second before submitting work
60- timerVar = setTimeout ( ( ) => tstlWorker . postMessage ( { tsStr : tsEditor . getValue ( ) } ) , 500 ) ;
68+ timerVar = setTimeout ( ( ) => {
69+ tstlWorker . postMessage ( { tsStr : tsEditor . getValue ( ) } ) ;
70+ history . pushState ( null , "" , "/?src=" + encodeURIComponent ( tsEditor . getValue ( ) ) ) ;
71+ } , 500 ) ;
6172 } ) )
6273
6374 tstlWorker . onmessage = ( event : MessageEvent ) => {
0 commit comments