Skip to content

Commit b0c205a

Browse files
committed
Added the ability to share workspaces
1 parent 206eb25 commit b0c205a

File tree

4 files changed

+57
-43
lines changed

4 files changed

+57
-43
lines changed

package-lock.json

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
"worker-loader": "^2.0.0"
2929
},
3030
"dependencies": {
31+
"@types/url-parse": "^1.4.1",
3132
"fengari": "^0.1.2",
3233
"monaco-editor": "^0.14.3",
33-
"typescript-to-lua": "file:../typescript-to-lua-0.9.0.tgz"
34+
"typescript-to-lua": "file:../typescript-to-lua-0.9.0.tgz",
35+
"url-parse": "^1.4.3"
3436
}
3537
}

src/assets/styles/main.scss

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
$lua-purple: rgb(30, 40, 111);
22
$ts-blue: rgb(67, 119, 194);
3-
$body-background: #fafafa;
3+
$body-background: #1e1e1e;
44

55
@import 'fonts';
66

@@ -19,19 +19,20 @@ img {
1919

2020
#header {
2121
width: 100%;
22-
height: 100px;
22+
height: 55px;
2323
//border-bottom-left-radius: 10%;
2424
//border-bottom-right-radius: 60%;
2525
background: linear-gradient(135deg, $ts-blue, $lua-purple);
2626
//-webkit-clip-path: polygon(100% 0, 100% 70%, 80% 90%, 50% 100%, 20% 90%, 0% 70%, 0 0);
2727
//clip-path: polygon(100% 0, 100% 70%, 80% 90%, 50% 100%, 20% 90%, 0% 70%, 0 0);
2828
color: white;
29+
box-shadow: 0px 3px 5px 0px rgba(0,0,0,0.75);
2930
}
3031

3132
#logo {
3233
position: absolute;
33-
top: 20px;
34-
left: 20px;
34+
top: 5px;
35+
left: 5px;
3536

3637
.logo-element {
3738
display: inline-block;
@@ -40,16 +41,16 @@ img {
4041
}
4142

4243
#logo-ts {
43-
height: 40px;
44+
height: 30px;
4445
}
4546

4647
#logo-spacer {
47-
font-size: 40px;
48+
font-size: 30px;
4849
vertical-align: -6px;
4950
}
5051

5152
#logo-lua {
52-
height: 60px;
53+
height: 40px;
5354
}
5455
}
5556

@@ -70,31 +71,30 @@ img {
7071
}
7172

7273
#content {
73-
margin-top: 40px;
7474
}
7575

7676

7777
#example {
78-
margin-right: auto;
79-
margin-left: auto;
8078
display: flex;
8179
flex-wrap: wrap;
82-
width: 95%;
80+
width: 100%;
8381

8482
.example-element {
8583
flex: 1;
8684
height: 600px;
87-
background-color: #1e1e1e;
85+
background-color:$body-background;
8886
display: inline-block;
89-
color: #222222;
87+
color: white;
9088
overflow: hidden;
89+
border-bottom: 1px #222222 solid;
90+
border-right: 1px #222222 solid;
91+
border-left: 1px #222222 solid;
9192
}
9293

9394
#example-ts {
9495
}
9596

9697
#example-lua {
97-
margin-left: 40px;
9898
}
9999

100100
#example-controls {
@@ -105,7 +105,6 @@ img {
105105

106106
#example-output {
107107
height: 120px;
108-
margin-top: 40px;
109108
flex-basis: 100%;
110109
}
111110
}

src/index.ts

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,41 @@ import {editor} from 'monaco-editor/esm/vs/editor/editor.api';
44

55
import TSTLWorker = require('worker-loader!./tstlWorker');
66

7+
import * as URL from "url-parse";
8+
79
document.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

Comments
 (0)