|
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 |
| - } |
| 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 | +}) |
17 | 32 |
|
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 |
| - }) |
| 33 | +const handleReady = (payload: any) => { |
| 34 | + console.log('handleReady payload:', payload) |
| 35 | +} |
31 | 36 |
|
32 |
| - const handleReady = (payload: any) => { |
33 |
| - console.log('handleReady payload:', payload) |
| 37 | +const extensions = computed(() => { |
| 38 | + const result = [] |
| 39 | + result.push(languages[state.language]) |
| 40 | + if (themes[state.theme]) { |
| 41 | + result.push(themes[state.theme]) |
34 | 42 | }
|
| 43 | + return result |
| 44 | +}) |
35 | 45 |
|
36 |
| - const extensions = computed(() => { |
37 |
| - const result = [] |
38 |
| - result.push(languages[state.language]) |
39 |
| - if (themes[state.theme]) { |
40 |
| - result.push(themes[state.theme]) |
41 |
| - } |
42 |
| - return result |
43 |
| - }) |
| 46 | +onMounted(() => { |
| 47 | + console.log('mounted view:', view) |
| 48 | +}) |
44 | 49 |
|
45 |
| - onMounted(() => { |
46 |
| - console.log('mounted view:', view) |
47 |
| - }) |
| 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 | +} |
48 | 86 | </script>
|
49 | 87 |
|
50 | 88 | <template>
|
|
97 | 135 | </option>
|
98 | 136 | </select>
|
99 | 137 | </p>
|
| 138 | + <p> |
| 139 | + <label for="phrases">phrases:</label> |
| 140 | + <select name="phrases" id="phrases" v-model="state.phrases"> |
| 141 | + <option :value="option" :key="option" v-for="option in ['en-us', 'de-de']"> |
| 142 | + {{ option }} |
| 143 | + </option> |
| 144 | + </select> |
| 145 | + </p> |
100 | 146 | </div>
|
101 | 147 | </div>
|
102 | 148 | <div class="content">
|
|
111 | 157 | :disabled="state.disabled"
|
112 | 158 | :style="{ backgroundColor: state.backgroundColor }"
|
113 | 159 | :extensions="extensions"
|
| 160 | + :phrases="state.phrases === 'en-us' ? {} : germanPhrases" |
114 | 161 | v-model="code"
|
115 | 162 | @ready="handleReady"
|
116 | 163 | @change="consoleLog('change', $event)"
|
|
122 | 169 | </template>
|
123 | 170 |
|
124 | 171 | <style lang="scss">
|
125 |
| - body { |
126 |
| - margin: 0; |
127 |
| - } |
| 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; |
128 | 183 |
|
129 |
| - .example { |
130 |
| - width: 100vw; |
131 |
| - height: 100vh; |
| 184 | + .toolbar { |
132 | 185 | display: flex;
|
133 |
| - flex-direction: column; |
134 |
| - justify-content: center; |
135 | 186 | align-items: center;
|
| 187 | + margin-bottom: 1rem; |
136 | 188 |
|
137 |
| - .toolbar { |
138 |
| - display: flex; |
139 |
| - align-items: center; |
140 |
| - margin-bottom: 1rem; |
141 |
| -
|
142 |
| - .state { |
143 |
| - margin: 2rem 0; |
144 |
| - margin-right: 2rem; |
145 |
| - padding: 2em; |
146 |
| - border: 1px solid #ccc; |
147 |
| - } |
| 189 | + .state { |
| 190 | + margin: 2rem 0; |
| 191 | + margin-right: 2rem; |
| 192 | + padding: 2em; |
| 193 | + border: 1px solid #ccc; |
148 | 194 | }
|
| 195 | + } |
149 | 196 |
|
150 |
| - .content { |
151 |
| - display: flex; |
152 |
| - width: 100%; |
153 |
| - justify-content: center; |
| 197 | + .content { |
| 198 | + display: flex; |
| 199 | + width: 100%; |
| 200 | + justify-content: center; |
154 | 201 |
|
155 |
| - .code { |
156 |
| - overflow: scroll; |
157 |
| - } |
| 202 | + .code { |
| 203 | + overflow: scroll; |
| 204 | + } |
158 | 205 |
|
159 |
| - .code, |
160 |
| - .codemirror .cm-editor { |
161 |
| - width: 30vw; |
162 |
| - height: 50vh; |
163 |
| - margin: 0 1rem; |
164 |
| - border: 1px solid #ddd; |
165 |
| - } |
| 206 | + .code, |
| 207 | + .codemirror .cm-editor { |
| 208 | + width: 30vw; |
| 209 | + height: 50vh; |
| 210 | + margin: 0 1rem; |
| 211 | + border: 1px solid #ddd; |
166 | 212 | }
|
167 | 213 | }
|
| 214 | +} |
168 | 215 | </style>
|
0 commit comments