File tree Expand file tree Collapse file tree 2 files changed +26
-7
lines changed Expand file tree Collapse file tree 2 files changed +26
-7
lines changed Original file line number Diff line number Diff line change 3
3
</template >
4
4
5
5
<script setup lang="ts">
6
+ import type { ModeSpec , ModeSpecOptions } from ' codemirror'
6
7
import { ref , onMounted , watchEffect , inject } from ' vue'
7
8
import { debounce } from ' ../utils'
8
9
import CodeMirror from ' ./codemirror'
9
10
10
11
export interface Props {
11
- mode? : string
12
+ mode? : string | ModeSpec < ModeSpecOptions >
12
13
value? : string
13
14
readonly? : boolean
14
15
}
Original file line number Diff line number Diff line change 1
1
<script setup lang="ts">
2
2
import FileSelector from ' ./FileSelector.vue'
3
- import CodeMirror from ' ../codemirror/CodeMirror.vue'
3
+ import CodeMirror , { type Props } from ' ../codemirror/CodeMirror.vue'
4
4
import Message from ' ../Message.vue'
5
5
import { debounce } from ' ../utils'
6
6
import { computed , inject } from ' vue'
7
7
import { Store } from ' ../store'
8
8
9
9
const store = inject (' store' ) as Store
10
10
11
+ const modes: Record <string , Props [' mode' ]> = {
12
+ css: ' css' ,
13
+ html: ' htmlmixed' ,
14
+ js: {
15
+ name: ' javascript' ,
16
+ },
17
+ json: {
18
+ name: ' javascript' ,
19
+ json: true ,
20
+ },
21
+ ts: {
22
+ name: ' javascript' ,
23
+ typescript: true ,
24
+ },
25
+ vue: ' htmlmixed' ,
26
+ }
27
+
11
28
const onChange = debounce ((code : string ) => {
12
29
store .state .activeFile .code = code
13
30
}, 250 )
14
31
15
32
const activeMode = computed (() => {
16
33
const { filename } = store .state .activeFile
17
- return filename .endsWith (' .vue' ) || filename .endsWith (' .html' )
18
- ? ' htmlmixed'
19
- : filename .endsWith (' .css' )
20
- ? ' css'
21
- : ' javascript'
34
+
35
+ const mode = modes [filename .split (' .' ).pop ()! ]
36
+
37
+ return filename .lastIndexOf (' .' ) !== - 1 && mode
38
+ ? mode
39
+ : modes .js
22
40
})
23
41
</script >
24
42
You can’t perform that action at this time.
0 commit comments