Skip to content
This repository was archived by the owner on Nov 6, 2024. It is now read-only.

Commit b67dbc0

Browse files
committed
Don't use CDN for the default files and added the ability to set the theme on attribute change.
1 parent 6427a15 commit b67dbc0

File tree

5 files changed

+17
-27
lines changed

5 files changed

+17
-27
lines changed

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
mint 0.10.0
1+
mint 0.12.0

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ component Main {
154154
"https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.39.0/theme/dracula.min.css"
155155
]
156156
onChange={onChange}
157-
value={value}
158157
theme="dracula"
158+
value={value}
159159
mode="ruby"/>
160160
}
161161
}

assets/codemirror.min.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/codemirror.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/CodeMirror.mint

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,23 @@
11
/* A component that integrates the CodeMirror editor. */
22
component CodeMirror {
33
/* The JavaScript files of Codemirror to load, either locally or from a CDN. */
4-
property javascripts : Array(String) =
5-
[
6-
"https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.39.0" \
7-
"/codemirror.min.js"
8-
]
4+
property javascripts : Array(String) = [@asset(../assets/codemirror.min.js)]
95

106
/* The CSS files of Codemirror to load, either locally or from a CDN. */
11-
property styles : Array(String) =
12-
[
13-
"https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.39.0" \
14-
"/codemirror.min.css"
15-
]
7+
property styles : Array(String) = [@asset(../assets/codemirror.min.css)]
168

179
/* Handler for the change event. */
18-
property onChange : Function(String, Promise(Never, Void)) =
19-
((value : String) : Promise(Never, Void) { next { } })
10+
property onChange : Function(String, Promise(Never, Void)) = Promise.never1
2011

2112
/* The content to display until the editor is loaded. */
2213
property loadingContent : Html = <></>
2314

2415
/* Whether or not show line numbers. */
2516
property lineNumbers : Bool = true
2617

18+
/* Wether or not the content is editable. */
19+
property readOnly : Bool = false
20+
2721
/* The number of spaces userd for indentation. */
2822
property tabSize : Number = 2
2923

@@ -36,9 +30,6 @@ component CodeMirror {
3630
/* The mode of the editor. */
3731
property mode : String = ""
3832

39-
/* Wether or not the content is editable. */
40-
property readOnly : Bool = false
41-
4233
/* Loads all assets when the components mounts. */
4334
fun componentDidMount : Promise(Never, Void) {
4435
sequence {
@@ -86,25 +77,22 @@ component CodeMirror {
8677
if (this.editor.getOption("readOnly") !== #{readOnly}) {
8778
this.editor.setOption("readOnly", #{readOnly})
8879
}
80+
81+
if (this.editor.getOption("theme") !== #{theme}) {
82+
this.editor.setOption("theme", #{theme})
83+
}
8984
}
9085
}
9186
})()
9287
`
9388
}
9489

90+
/* Styles for the editor. */
9591
style editor {
96-
display: #{display};
97-
}
98-
99-
/*
100-
Returns the content for the `display` property,
101-
to hide the textarea until it's ready.
102-
*/
103-
get display : String {
10492
if (`this.editor`) {
105-
""
93+
display: block;
10694
} else {
107-
"none"
95+
display: none;
10896
}
10997
}
11098

0 commit comments

Comments
 (0)