@@ -27,6 +27,13 @@ export const QuillEditor = defineComponent({
27
27
type : [ String , Object ] as PropType < string | Delta > ,
28
28
default : { } ,
29
29
} ,
30
+ contentType : {
31
+ type : String as PropType < 'delta' | 'html' | 'text' > ,
32
+ default : 'delta' ,
33
+ validator : ( value : string ) => {
34
+ return [ 'delta' , 'html' , 'text' ] . includes ( value )
35
+ } ,
36
+ } ,
30
37
enable : {
31
38
type : Boolean ,
32
39
default : true ,
@@ -40,7 +47,7 @@ export const QuillEditor = defineComponent({
40
47
required : false ,
41
48
} ,
42
49
theme : {
43
- type : String ,
50
+ type : String as PropType < 'snow' | 'bubble' | '' > ,
44
51
default : 'snow' ,
45
52
validator : ( value : string ) => {
46
53
return [ 'snow' , 'bubble' , '' ] . includes ( value )
@@ -96,12 +103,7 @@ export const QuillEditor = defineComponent({
96
103
// Create new instance
97
104
quill = new Quill ( editor . value , options )
98
105
// Set editor content
99
- if ( typeof props . content === 'string' ) {
100
- quill . setText ( props . content )
101
- ctx . emit ( 'update:content' , quill . getContents ( ) )
102
- } else {
103
- quill . setContents ( props . content as Delta )
104
- }
106
+ setContents ( props . content )
105
107
// Set event handlers
106
108
quill . on ( 'text-change' , handleTextChange )
107
109
quill . on ( 'selection-change' , handleSelectionChange )
@@ -150,7 +152,7 @@ export const QuillEditor = defineComponent({
150
152
source : Sources
151
153
) => {
152
154
// Update v-model:content when text changes
153
- ctx . emit ( 'update:content' , quill ?. getContents ( ) )
155
+ ctx . emit ( 'update:content' , getContents ( ) )
154
156
ctx . emit ( 'textChange' , { delta, oldContents, source } )
155
157
}
156
158
@@ -212,6 +214,33 @@ export const QuillEditor = defineComponent({
212
214
or use v-on:ready="onReady(quill)" event instead.`
213
215
}
214
216
217
+ const getContents = ( ) => {
218
+ if ( props . contentType === 'html' ) {
219
+ return getHTML ( )
220
+ } else if ( props . contentType === 'text' ) {
221
+ return getText ( )
222
+ }
223
+ return quill ?. getContents ( )
224
+ }
225
+
226
+ const setContents = ( content : string | Delta ) => {
227
+ if ( props . contentType === 'html' ) {
228
+ setHTML ( content as string )
229
+ } else if ( props . contentType === 'text' ) {
230
+ setText ( content as string )
231
+ } else {
232
+ quill ?. setContents ( content as Delta )
233
+ }
234
+ }
235
+
236
+ const getText = ( ) : string => {
237
+ return quill ?. getText ( ) ?? ''
238
+ }
239
+
240
+ const setText = ( text : string ) => {
241
+ quill ?. setText ( text )
242
+ }
243
+
215
244
const getHTML = ( ) : string => {
216
245
return quill ?. root . innerHTML ?? ''
217
246
}
@@ -232,8 +261,7 @@ export const QuillEditor = defineComponent({
232
261
( ) => props . content ,
233
262
( newContent ) => {
234
263
if ( ! quill || ! newContent || newContent === props . content ) return
235
- if ( typeof newContent === 'string' ) quill . setText ( props . content as string )
236
- else quill . setContents ( newContent as Delta )
264
+ setContents ( newContent )
237
265
}
238
266
)
239
267
@@ -249,8 +277,12 @@ export const QuillEditor = defineComponent({
249
277
getEditor,
250
278
getToolbar,
251
279
getQuill,
280
+ getContents,
281
+ setContents,
252
282
getHTML,
253
283
setHTML,
284
+ getText,
285
+ setText,
254
286
reinit,
255
287
}
256
288
} ,
0 commit comments