1
1
<script setup lang="ts">
2
- import { reactive , shallowRef , computed , onMounted } from ' vue'
3
- import { javascript } from ' @codemirror/lang-javascript'
4
- import { html } from ' @codemirror/lang-html'
5
- import { json } from ' @codemirror/lang-json'
6
- import { markdown } from ' @codemirror/lang-markdown'
7
- import { oneDark } from ' @codemirror/theme-one-dark'
8
- import { Codemirror } from ' ../src'
2
+ import { reactive , shallowRef , computed , onMounted } from ' vue'
3
+ import { javascript } from ' @codemirror/lang-javascript'
4
+ import { html } from ' @codemirror/lang-html'
5
+ import { json } from ' @codemirror/lang-json'
6
+ import { markdown } from ' @codemirror/lang-markdown'
7
+ import { oneDark } from ' @codemirror/theme-one-dark'
8
+ import { Codemirror } from ' ../src'
9
9
10
- const themes: any = { oneDark }
11
- const languages: any = {
12
- javascript: javascript (),
13
- html: html (),
14
- json: json (),
15
- markdown: markdown ()
16
- }
17
-
18
- const consoleLog = console .log
19
- const code = shallowRef (` console.log('Hello World') ` )
20
- const view = shallowRef ()
21
- const state = reactive ({
22
- disabled: false ,
23
- indentWithTab: true ,
24
- tabSize: 4 ,
25
- autofocus: true ,
26
- placeholder: ' input...' ,
27
- backgroundColor: ' red' ,
28
- language: ' javascript' ,
29
- theme: ' oneDark' ,
30
- phrases: ' en-us'
31
- })
10
+ const themes: any = { oneDark }
11
+ const languages: any = {
12
+ javascript: javascript (),
13
+ html: html (),
14
+ json: json (),
15
+ markdown: markdown ()
16
+ }
32
17
33
- const handleReady = (payload : any ) => {
34
- console .log (' handleReady payload:' , payload )
35
- }
18
+ const consoleLog = console .log
19
+ const code = shallowRef (` console.log('Hello World') ` )
20
+ const view = shallowRef ()
21
+ const config = reactive ({
22
+ disabled: false ,
23
+ indentWithTab: true ,
24
+ tabSize: 4 ,
25
+ autofocus: true ,
26
+ placeholder: ' input...' ,
27
+ backgroundColor: ' red' ,
28
+ language: ' javascript' ,
29
+ theme: ' oneDark' ,
30
+ phrases: ' en-us'
31
+ })
36
32
37
- const extensions = computed (() => {
38
- const result = []
39
- result .push (languages [state .language ])
40
- if (themes [state .theme ]) {
41
- result .push (themes [state .theme ])
33
+ const handleReady = (payload : any ) => {
34
+ console .log (' handleReady payload:' , payload )
42
35
}
43
- return result
44
- })
45
36
46
- onMounted (() => {
47
- console .log (' mounted view:' , view )
48
- })
37
+ const extensions = computed (() => {
38
+ const result = []
39
+ result .push (languages [config .language ])
40
+ if (themes [config .theme ]) {
41
+ result .push (themes [config .theme ])
42
+ }
43
+ return result
44
+ })
45
+
46
+ onMounted (() => {
47
+ console .log (' mounted view:' , view )
48
+ })
49
49
50
- const germanPhrases = {
51
- // @codemirror/view
52
- ' Control character' : ' Steuerzeichen' ,
53
- // @codemirror/commands
54
- ' Selection deleted' : ' Auswahl gelöscht' ,
55
- // @codemirror/language
56
- ' Folded lines' : ' Eingeklappte Zeilen' ,
57
- ' Unfolded lines' : ' Ausgeklappte Zeilen' ,
58
- to: ' bis' ,
59
- ' folded code' : ' eingeklappter Code' ,
60
- unfold: ' ausklappen' ,
61
- ' Fold line' : ' Zeile einklappen' ,
62
- ' Unfold line' : ' Zeile ausklappen' ,
63
- // @codemirror/search
64
- ' Go to line' : ' Springe zu Zeile' ,
65
- go: ' OK' ,
66
- Find: ' Suchen' ,
67
- Replace: ' Ersetzen' ,
68
- next: ' nächste' ,
69
- previous: ' vorherige' ,
70
- all: ' alle' ,
71
- ' match case' : ' groß/klein beachten' ,
72
- ' by word' : ' ganze Wörter' ,
73
- replace: ' ersetzen' ,
74
- ' replace all' : ' alle ersetzen' ,
75
- close: ' schließen' ,
76
- ' current match' : ' aktueller Treffer' ,
77
- ' replaced $ matches' : ' $ Treffer ersetzt' ,
78
- ' replaced match on line $' : ' Treffer on Zeile $ ersetzt' ,
79
- ' on line' : ' auf Zeile' ,
80
- // @codemirror/autocomplete
81
- Completions: ' Vervollständigungen' ,
82
- // @codemirror/lint
83
- Diagnostics: ' Diagnosen' ,
84
- ' No diagnostics' : ' Keine Diagnosen'
85
- }
50
+ const germanPhrases = {
51
+ // @codemirror/view
52
+ ' Control character' : ' Steuerzeichen' ,
53
+ // @codemirror/commands
54
+ ' Selection deleted' : ' Auswahl gelöscht' ,
55
+ // @codemirror/language
56
+ ' Folded lines' : ' Eingeklappte Zeilen' ,
57
+ ' Unfolded lines' : ' Ausgeklappte Zeilen' ,
58
+ to: ' bis' ,
59
+ ' folded code' : ' eingeklappter Code' ,
60
+ unfold: ' ausklappen' ,
61
+ ' Fold line' : ' Zeile einklappen' ,
62
+ ' Unfold line' : ' Zeile ausklappen' ,
63
+ // @codemirror/search
64
+ ' Go to line' : ' Springe zu Zeile' ,
65
+ go: ' OK' ,
66
+ Find: ' Suchen' ,
67
+ Replace: ' Ersetzen' ,
68
+ next: ' nächste' ,
69
+ previous: ' vorherige' ,
70
+ all: ' alle' ,
71
+ ' match case' : ' groß/klein beachten' ,
72
+ ' by word' : ' ganze Wörter' ,
73
+ replace: ' ersetzen' ,
74
+ ' replace all' : ' alle ersetzen' ,
75
+ close: ' schließen' ,
76
+ ' current match' : ' aktueller Treffer' ,
77
+ ' replaced $ matches' : ' $ Treffer ersetzt' ,
78
+ ' replaced match on line $' : ' Treffer on Zeile $ ersetzt' ,
79
+ ' on line' : ' auf Zeile' ,
80
+ // @codemirror/autocomplete
81
+ Completions: ' Vervollständigungen' ,
82
+ // @codemirror/lint
83
+ Diagnostics: ' Diagnosen' ,
84
+ ' No diagnostics' : ' Keine Diagnosen'
85
+ }
86
86
</script >
87
87
88
88
<template >
89
89
<div class =" example" >
90
90
<div class =" toolbar" >
91
- <pre class =" state" >{{ state }}</pre >
91
+ <pre class =" state" >{{ config }}</pre >
92
92
<div class =" config" >
93
93
<p >
94
- <button @click =" state .disabled = !state .disabled" >toggle disabled</button >
94
+ <button @click =" config .disabled = !config .disabled" >toggle disabled</button >
95
95
</p >
96
96
<p >
97
- <button @click =" state .autofocus = !state .autofocus" >toggle autofocus</button >
97
+ <button @click =" config .autofocus = !config .autofocus" >toggle autofocus</button >
98
98
</p >
99
99
<p >
100
- <button @click =" state .indentWithTab = !state .indentWithTab" >toggle indentWithTab</button >
100
+ <button @click =" config .indentWithTab = !config .indentWithTab" >toggle indentWithTab</button >
101
101
</p >
102
102
<p >
103
103
<label for =" tabSize" >tabSize:</label >
104
- <input type =" range" id =" tabSize" min =" 2" max =" 10" step =" 2" v-model.number =" state .tabSize" />
104
+ <input type =" range" id =" tabSize" min =" 2" max =" 10" step =" 2" v-model.number =" config .tabSize" />
105
105
</p >
106
106
<p >
107
107
<label for =" backgroundColor" >backgroundColor:</label >
108
- <select name =" backgroundColor" id =" backgroundColor" v-model =" state .backgroundColor" >
108
+ <select name =" backgroundColor" id =" backgroundColor" v-model =" config .backgroundColor" >
109
109
<option
110
110
:value =" option"
111
111
:key =" option"
@@ -117,7 +117,7 @@ const germanPhrases = {
117
117
</p >
118
118
<p >
119
119
<label for =" language" >language:</label >
120
- <select name =" language" id =" language" v-model =" state .language" >
120
+ <select name =" language" id =" language" v-model =" config .language" >
121
121
<option
122
122
:value =" option"
123
123
:key =" option"
@@ -129,15 +129,15 @@ const germanPhrases = {
129
129
</p >
130
130
<p >
131
131
<label for =" theme" >theme:</label >
132
- <select name =" theme" id =" theme" v-model =" state .theme" >
132
+ <select name =" theme" id =" theme" v-model =" config .theme" >
133
133
<option :value =" option" :key =" option" v-for =" option in ['default', 'oneDark']" >
134
134
{{ option }}
135
135
</option >
136
136
</select >
137
137
</p >
138
138
<p >
139
139
<label for =" phrases" >phrases:</label >
140
- <select name =" phrases" id =" phrases" v-model =" state .phrases" >
140
+ <select name =" phrases" id =" phrases" v-model =" config .phrases" >
141
141
<option :value =" option" :key =" option" v-for =" option in ['en-us', 'de-de']" >
142
142
{{ option }}
143
143
</option >
@@ -150,14 +150,14 @@ const germanPhrases = {
150
150
<codemirror
151
151
class =" codemirror"
152
152
ref =" cm"
153
- :autofocus =" state .autofocus"
154
- :placeholder =" state .placeholder"
155
- :indentWithTab =" state .indentWithTab"
156
- :tabSize =" state .tabSize"
157
- :disabled =" state .disabled"
158
- :style =" { backgroundColor: state .backgroundColor }"
153
+ :autofocus =" config .autofocus"
154
+ :placeholder =" config .placeholder"
155
+ :indentWithTab =" config .indentWithTab"
156
+ :tabSize =" config .tabSize"
157
+ :disabled =" config .disabled"
158
+ :style =" { backgroundColor: config .backgroundColor }"
159
159
:extensions =" extensions"
160
- :phrases =" state .phrases === 'en-us' ? {} : germanPhrases"
160
+ :phrases =" config .phrases === 'en-us' ? {} : germanPhrases"
161
161
v-model =" code"
162
162
@ready =" handleReady"
163
163
@change =" consoleLog('change', $event)"
@@ -169,47 +169,47 @@ const germanPhrases = {
169
169
</template >
170
170
171
171
<style lang="scss">
172
- body {
173
- margin : 0 ;
174
- }
175
-
176
- .example {
177
- width : 100vw ;
178
- height : 100vh ;
179
- display : flex ;
180
- flex-direction : column ;
181
- justify-content : center ;
182
- align-items : center ;
172
+ body {
173
+ margin : 0 ;
174
+ }
183
175
184
- .toolbar {
176
+ .example {
177
+ width : 100vw ;
178
+ height : 100vh ;
185
179
display : flex ;
180
+ flex-direction : column ;
181
+ justify-content : center ;
186
182
align-items : center ;
187
- margin-bottom : 1rem ;
188
183
189
- .state {
190
- margin : 2rem 0 ;
191
- margin-right : 2rem ;
192
- padding : 2em ;
193
- border : 1px solid #ccc ;
184
+ .toolbar {
185
+ display : flex ;
186
+ align-items : center ;
187
+ margin-bottom : 1rem ;
188
+
189
+ .state {
190
+ margin : 2rem 0 ;
191
+ margin-right : 2rem ;
192
+ padding : 2em ;
193
+ border : 1px solid #ccc ;
194
+ }
194
195
}
195
- }
196
196
197
- .content {
198
- display : flex ;
199
- width : 100% ;
200
- justify-content : center ;
197
+ .content {
198
+ display : flex ;
199
+ width : 100% ;
200
+ justify-content : center ;
201
201
202
- .code {
203
- overflow : scroll ;
204
- }
202
+ .code {
203
+ overflow : scroll ;
204
+ }
205
205
206
- .code ,
207
- .codemirror .cm-editor {
208
- width : 30vw ;
209
- height : 50vh ;
210
- margin : 0 1rem ;
211
- border : 1px solid #ddd ;
206
+ .code ,
207
+ .codemirror .cm-editor {
208
+ width : 30vw ;
209
+ height : 50vh ;
210
+ margin : 0 1rem ;
211
+ border : 1px solid #ddd ;
212
+ }
212
213
}
213
214
}
214
- }
215
215
</style >
0 commit comments