2
2
component CodeMirror {
3
3
/* The JavaScript files of Codemirror to load, either locally or from a CDN. */
4
4
property javascripts : Array (String ) = [
5
- "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.39.0/codemirror.min.js"
5
+ "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.39.0" \
6
+ "/codemirror.min.js"
6
7
]
7
8
8
9
/* The CSS files of Codemirror to load, either locally or from a CDN. */
9
10
property styles : Array (String ) = [
10
- "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.39.0/codemirror.min.css"
11
+ "https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.39.0" \
12
+ "/codemirror.min.css"
11
13
]
12
14
13
15
/* Handler for the change event. */
14
- property onChange : Function (String , Void ) = ((value : String ) : Void => { void })
16
+ property onChange : Function (String , a ) = ((value : String ) : Void => { void })
15
17
16
18
/* The content to display until the editor is loaded. */
17
- property loadingContent : Html = Html . empty ()
19
+ property loadingContent : Html = <></>
18
20
19
21
/* Whether or not show line numbers. */
20
22
property lineNumbers : Bool = true
@@ -29,8 +31,8 @@ component CodeMirror {
29
31
property mode : String = ""
30
32
31
33
/* Loads all assets when the components mounts. */
32
- fun componentDidMount : Void {
33
- do {
34
+ fun componentDidMount : Promise ( Never , Void ) {
35
+ sequence {
34
36
AssetLoader .loadAll (AssetLoader .loadScript , javascripts )
35
37
AssetLoader .loadAll (AssetLoader .loadStyle , styles )
36
38
initializeEditor ()
@@ -48,27 +50,25 @@ component CodeMirror {
48
50
}
49
51
50
52
/* Initializes the editor for the given dom element. */
51
- fun initializeEditor () : Void {
52
- do {
53
- `
54
- (() => {
55
- if (! this .element ) { return }
56
- if (this .editor ) { return }
57
-
58
- this .editor = CodeMirror .fromTextArea (this .element , {
59
- lineNumbers: this .lineNumbers ,
60
- theme: this .theme ,
61
- mode: this .mode ,
62
- })
63
-
64
- this .editor .on (' change' , (value ) => {
65
- this .onChange (this .editor .getValue ())
66
- })
67
-
68
- this .forceUpdate ()
69
- })()
70
- `
71
- }
53
+ fun initializeEditor : Void {
54
+ `
55
+ (() => {
56
+ if (! this .element ) { return }
57
+ if (this .editor ) { return }
58
+
59
+ this .editor = CodeMirror .fromTextArea (this .element , {
60
+ lineNumbers: this .lineNumbers ,
61
+ theme: this .theme ,
62
+ mode: this .mode ,
63
+ })
64
+
65
+ this .editor .on (' change' , (value ) => {
66
+ this .onChange (this .editor .getValue ())
67
+ })
68
+
69
+ this .forceUpdate ()
70
+ })()
71
+ `
72
72
}
73
73
74
74
/* After an update, update the underlying editor instance. */
@@ -107,7 +107,7 @@ component CodeMirror {
107
107
[
108
108
<textarea :: editor ref = {saveReference }/>,
109
109
if (`this .editor `) {
110
- Html . empty ()
110
+ <></>
111
111
} else {
112
112
loadingContent
113
113
}
0 commit comments