@@ -22,13 +22,14 @@ import { toolbarOptions, ToolbarOptions } from './options'
2222
2323export type Module = { name : string ; module : unknown ; options ?: object }
2424
25+ type ContentPropType = string | Delta | undefined | null
26+
2527export const QuillEditor = defineComponent ( {
2628 name : 'QuillEditor' ,
2729 inheritAttrs : false ,
2830 props : {
2931 content : {
30- type : [ String , Object ] as PropType < string | Delta > ,
31- default : ( ) => { } ,
32+ type : [ String , Object ] as PropType < ContentPropType > ,
3233 } ,
3334 contentType : {
3435 type : String as PropType < 'delta' | 'html' | 'text' > ,
@@ -185,8 +186,8 @@ export const QuillEditor = defineComponent({
185186 )
186187 }
187188
188- const maybeClone = ( delta : Delta | string ) => {
189- return typeof delta === 'object' ? delta . slice ( ) : delta
189+ const maybeClone = ( delta : ContentPropType ) => {
190+ return typeof delta === 'object' && delta ? delta . slice ( ) : delta
190191 }
191192
192193 const deltaHasValuesOtherThanRetain = ( delta : Delta ) : boolean => {
@@ -197,13 +198,18 @@ export const QuillEditor = defineComponent({
197198
198199 // Doesn't need reactivity, but does need to be cloned to avoid deep mutations always registering as equal
199200 let internalModel : typeof props . content
200- const internalModelEquals = ( against : Delta | String | undefined ) => {
201+ const internalModelEquals = ( against : ContentPropType ) => {
201202 if ( typeof internalModel === typeof against ) {
202203 if ( against === internalModel ) {
203204 return true
204205 }
205206 // Ref/Proxy does not support instanceof, so do a loose check
206- if ( typeof against === 'object' && typeof internalModel === 'object' ) {
207+ if (
208+ typeof against === 'object' &&
209+ against &&
210+ typeof internalModel === 'object' &&
211+ internalModel
212+ ) {
207213 return ! deltaHasValuesOtherThanRetain (
208214 internalModel . diff ( against as Delta )
209215 )
@@ -297,15 +303,20 @@ export const QuillEditor = defineComponent({
297303 return quill ?. getContents ( index , length )
298304 }
299305
300- const setContents = ( content : string | Delta , source : Sources = 'api' ) => {
306+ const setContents = ( content : ContentPropType , source : Sources = 'api' ) => {
307+ const normalizedContent = ! content
308+ ? props . contentType === 'delta'
309+ ? new Delta ( )
310+ : ''
311+ : content
301312 if ( props . contentType === 'html' ) {
302- setHTML ( content as string )
313+ setHTML ( normalizedContent as string )
303314 } else if ( props . contentType === 'text' ) {
304- setText ( content as string , source )
315+ setText ( normalizedContent as string , source )
305316 } else {
306- quill ?. setContents ( content as Delta , source )
317+ quill ?. setContents ( normalizedContent as Delta , source )
307318 }
308- internalModel = maybeClone ( content )
319+ internalModel = maybeClone ( normalizedContent )
309320 }
310321
311322 const getText = ( index ?: number , length ?: number ) : string => {
0 commit comments