1
1
import "./index.css" ;
2
2
3
- type SourceChangedEvent = { source : string } ;
4
- type DisplayChangedEvent = { kind : "prettyPrint" | "disasm" | "mermaid" } ;
5
-
6
- Promise . all ( [
3
+ await Promise . all ( [
7
4
// We're going to load the editor asynchronously so that we can get to
8
5
// first-paint faster. This works out nicely since we can use a textarea until
9
6
// this chunk is loaded.
10
7
import ( "./monacoLoader" ) . then ( async ( { default : loader } ) => {
11
8
const monaco = await loader . init ( ) ;
12
- const editor = document . getElementById ( "editor" ) as HTMLTextAreaElement ;
9
+ const editor = document . getElementById ( "editor" ) ;
13
10
const newEditor = document . createElement ( "div" ) ;
14
11
editor . replaceWith ( newEditor ) ;
15
12
@@ -21,15 +18,15 @@ Promise.all([
21
18
}
22
19
} ) ;
23
20
} ) ,
24
- import ( "./mermaid-js " ) ,
21
+ import ( "./mermaid" ) ,
25
22
// We're going to load the Ruby VM chunk asynchronously because it is pretty
26
23
// dang huge (> 40Mb). In the meantime the textarea that is holding the place
27
24
// of the actual functional one is just going to display "Loading...".
28
25
import ( "./createRuby" ) . then ( ( { default : createRuby } ) => createRuby ( ) )
29
- ] ) . then ( ( [ editor , mermaidjs , ruby ] ) => {
26
+ ] ) . then ( ( [ editor , mermaid , ruby ] ) => {
30
27
// First, grab a reference to the output element so that we can update it.
31
28
// Then, set it initially to the output represented by the source.
32
- const output = document . getElementById ( "output" ) as HTMLTextAreaElement ;
29
+ const output = document . getElementById ( "output" ) ;
33
30
output . value = ruby . prettyPrint ( editor . getValue ( ) ) ;
34
31
output . disabled = false ;
35
32
@@ -38,14 +35,14 @@ Promise.all([
38
35
let displayFunction = ruby . prettyPrint ;
39
36
40
37
// Handle a custom event here for if the display option changed.
41
- output . addEventListener ( "display-changed" , ( event : CustomEvent < DisplayChangedEvent > ) => {
38
+ output . addEventListener ( "display-changed" , ( event ) => {
42
39
displayFunction = ruby [ event . detail . kind ] ;
43
40
44
41
try {
45
42
let source = displayFunction ( editor . getValue ( ) ) ;
46
43
47
44
if ( event . detail . kind === 'mermaid' ) {
48
- mermaidjs . render ( ( ) => {
45
+ mermaid . render ( ( ) => {
49
46
output . setAttribute ( "style" , "display: none;" ) ;
50
47
51
48
return source ;
@@ -54,7 +51,7 @@ Promise.all([
54
51
output . value = source ;
55
52
output . setAttribute ( "style" , "" ) ;
56
53
57
- mermaidjs . reset ( ) ;
54
+ mermaid . reset ( ) ;
58
55
}
59
56
} catch ( error ) {
60
57
// For now, just ignoring the error. Eventually I'd like to make this mark
@@ -66,33 +63,33 @@ Promise.all([
66
63
// event information.
67
64
const toggles = document . getElementsByClassName ( "toggles" ) [ 0 ] ;
68
65
69
- toggles . querySelector ( "select" ) . addEventListener ( 'change' , ( e ) => {
70
- output . dispatchEvent ( new CustomEvent < DisplayChangedEvent > ( "display-changed" , {
71
- detail : { kind : e . target . value as DisplayChangedEvent [ "kind" ] }
66
+ toggles . querySelector ( "select" ) . addEventListener ( 'change' , ( event ) => {
67
+ output . dispatchEvent ( new CustomEvent ( "display-changed" , {
68
+ detail : { kind : event . target . value }
72
69
} ) ) ;
73
70
} ) ;
74
71
75
72
// We're going to handle updates to the source through a custom event. This
76
73
// turns out to be faster than handling the change event directly on the
77
74
// editor since it blocks updates to the UI until the event handled returns.
78
- output . addEventListener ( "source-changed" , ( event : CustomEvent < SourceChangedEvent > ) => {
75
+ output . addEventListener ( "source-changed" , ( event ) => {
79
76
// We may want to add some throttle here to avoid to much rerendering in our Graph
80
- output . dispatchEvent ( new CustomEvent < DisplayChangedEvent > ( "display-changed" , {
81
- detail : { kind : toggles . querySelector ( 'select' ) . value as DisplayChangedEvent [ "kind" ] }
77
+ output . dispatchEvent ( new CustomEvent ( "display-changed" , {
78
+ detail : { kind : toggles . querySelector ( 'select' ) . value }
82
79
} ) ) ;
83
80
} ) ;
84
81
85
82
// Attach to the editor and dispatch custom source-changed events whenever the
86
83
// value is updated in the editor.
87
84
editor . onDidChangeModelContent ( ( ) => {
88
- output . dispatchEvent ( new CustomEvent < SourceChangedEvent > ( "source-changed" , {
85
+ output . dispatchEvent ( new CustomEvent ( "source-changed" , {
89
86
detail : { source : editor . getValue ( ) }
90
87
} ) ) ;
91
88
} ) ;
92
89
93
90
// Attach to the format button to update the source whenever the button is
94
91
// clicked.
95
- const format = document . getElementById ( "format" ) as HTMLButtonElement ;
92
+ const format = document . getElementById ( "format" ) ;
96
93
format . disabled = false ;
97
94
98
95
format . addEventListener ( "click" , ( ) => {
0 commit comments