@@ -27,6 +27,13 @@ export const QuillEditor = defineComponent({
2727 type : [ String , Object ] as PropType < string | Delta > ,
2828 default : { } ,
2929 } ,
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+ } ,
3037 enable : {
3138 type : Boolean ,
3239 default : true ,
@@ -40,7 +47,7 @@ export const QuillEditor = defineComponent({
4047 required : false ,
4148 } ,
4249 theme : {
43- type : String ,
50+ type : String as PropType < 'snow' | 'bubble' | '' > ,
4451 default : 'snow' ,
4552 validator : ( value : string ) => {
4653 return [ 'snow' , 'bubble' , '' ] . includes ( value )
@@ -96,12 +103,7 @@ export const QuillEditor = defineComponent({
96103 // Create new instance
97104 quill = new Quill ( editor . value , options )
98105 // 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 )
105107 // Set event handlers
106108 quill . on ( 'text-change' , handleTextChange )
107109 quill . on ( 'selection-change' , handleSelectionChange )
@@ -150,7 +152,7 @@ export const QuillEditor = defineComponent({
150152 source : Sources
151153 ) => {
152154 // Update v-model:content when text changes
153- ctx . emit ( 'update:content' , quill ?. getContents ( ) )
155+ ctx . emit ( 'update:content' , getContents ( ) )
154156 ctx . emit ( 'textChange' , { delta, oldContents, source } )
155157 }
156158
@@ -212,6 +214,33 @@ export const QuillEditor = defineComponent({
212214 or use v-on:ready="onReady(quill)" event instead.`
213215 }
214216
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+
215244 const getHTML = ( ) : string => {
216245 return quill ?. root . innerHTML ?? ''
217246 }
@@ -232,8 +261,7 @@ export const QuillEditor = defineComponent({
232261 ( ) => props . content ,
233262 ( newContent ) => {
234263 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 )
237265 }
238266 )
239267
@@ -249,8 +277,12 @@ export const QuillEditor = defineComponent({
249277 getEditor,
250278 getToolbar,
251279 getQuill,
280+ getContents,
281+ setContents,
252282 getHTML,
253283 setHTML,
284+ getText,
285+ setText,
254286 reinit,
255287 }
256288 } ,
0 commit comments