1
1
<template >
2
2
<div id =" text-editor" :class =" { fullscreen: fullscreen }" >
3
- <div class = " toolbar " v-if =" editor" >
3
+ <div v-if =" editor" class = " toolbar " >
4
4
<div class =" align-dropdown" >
5
5
<button class =" dropbtn" @click.prevent =" " >Heading ▼</button >
6
6
<div class =" dropdown-content" >
7
7
<a
8
8
v-for =" index in 6"
9
+ :key =" index"
9
10
:class =" {
10
11
active: editor.isActive('heading', {
11
12
level: index,
15
16
fontSize: 20 - index + 'px',
16
17
backgroundColor: '#555',
17
18
}"
18
- @click.prevent =" onHeadingClick(index)"
19
19
role =" button"
20
+ @click.prevent =" onHeadingClick(index)"
20
21
>
21
22
H{{ index }}
22
23
</a >
25
26
26
27
<button
27
28
v-for =" ({ slug, option, active, icon }, index) in textActions"
29
+ :key =" index"
28
30
:class =" { active: editor.isActive(active) }"
29
31
@click.prevent =" onActionClick(slug, option)"
30
32
>
33
35
34
36
<div class =" mode-toggle" >
35
37
<button
36
- @click.prevent =" toggleMode"
37
38
:class =" { active: showSourceCode }"
39
+ @click.prevent =" toggleMode"
38
40
>
39
41
<i class =" fas fa-file-code" ></i >
40
42
</button >
41
43
<button
42
- @click.prevent =" toggleFullscreen"
43
44
:class =" { active: fullscreen }"
45
+ @click.prevent =" toggleFullscreen"
44
46
>
45
47
<i v-if =" !fullscreen" class =" fas fa-expand-arrows-alt" ></i >
46
48
<i v-else class =" fas fa-compress-arrows-alt" ></i >
@@ -202,6 +204,37 @@ export default {
202
204
}
203
205
},
204
206
},
207
+ mounted () {
208
+ this .editor = new Editor ({
209
+ content: this .modelValue ,
210
+ extensions: [
211
+ StarterKit,
212
+ Underline,
213
+ Subscript,
214
+ Superscript,
215
+ CharacterCount .configure ({
216
+ limit: this .maxLimit ,
217
+ }),
218
+ TextAlign .configure ({
219
+ types: [' heading' , ' paragraph' ],
220
+ }),
221
+ ],
222
+ onUpdate : () => {
223
+ this .$emit (' update:modelValue' , this .editor .getHTML ())
224
+ },
225
+ })
226
+ document .addEventListener (
227
+ ' fullscreenchange' ,
228
+ this .handleFullscreenChange
229
+ )
230
+ },
231
+ beforeUnmount () {
232
+ this .editor .destroy ()
233
+ document .removeEventListener (
234
+ ' fullscreenchange' ,
235
+ this .handleFullscreenChange
236
+ )
237
+ },
205
238
methods: {
206
239
onActionClick (slug , option = null ) {
207
240
if (this .showSourceCode ) return
@@ -250,37 +283,6 @@ export default {
250
283
this .fullscreen = document .fullscreenElement !== null
251
284
},
252
285
},
253
- mounted () {
254
- this .editor = new Editor ({
255
- content: this .modelValue ,
256
- extensions: [
257
- StarterKit,
258
- Underline,
259
- Subscript,
260
- Superscript,
261
- CharacterCount .configure ({
262
- limit: this .maxLimit ,
263
- }),
264
- TextAlign .configure ({
265
- types: [' heading' , ' paragraph' ],
266
- }),
267
- ],
268
- onUpdate : () => {
269
- this .$emit (' update:modelValue' , this .editor .getHTML ())
270
- },
271
- })
272
- document .addEventListener (
273
- ' fullscreenchange' ,
274
- this .handleFullscreenChange
275
- )
276
- },
277
- beforeUnmount () {
278
- this .editor .destroy ()
279
- document .removeEventListener (
280
- ' fullscreenchange' ,
281
- this .handleFullscreenChange
282
- )
283
- },
284
286
}
285
287
</script >
286
288
@@ -325,6 +327,7 @@ export default {
325
327
border-radius : 2px ;
326
328
margin : 0.5em 4px ;
327
329
-webkit-appearance : none ;
330
+ appearance : none ;
328
331
cursor : pointer ;
329
332
}
330
333
@@ -346,6 +349,7 @@ export default {
346
349
border : none ;
347
350
border-radius : 2px ;
348
351
-webkit-appearance : none ;
352
+ appearance : none ;
349
353
cursor : pointer ;
350
354
}
351
355
@@ -430,6 +434,7 @@ export default {
430
434
border-radius : 2px ;
431
435
margin : 0.5em 4px ;
432
436
-webkit-appearance : none ;
437
+ appearance : none ;
433
438
cursor : pointer ;
434
439
}
435
440
0 commit comments