@@ -63,27 +63,44 @@ export function useEmbedModal(ref: MutableRefObject<Quill | null>): ModalReturnT
63
63
64
64
const customVideoHandler = ( value : any ) : void => {
65
65
const selection = ref . current ?. getSelection ( ) ;
66
- if ( value === true ) {
66
+ if ( value === true || value . type === "video" ) {
67
67
setDialogConfig ( {
68
68
dialogType : "video" ,
69
69
config : {
70
- onSubmit : ( value : VideoFormType ) => {
71
- if ( Object . hasOwn ( value , "src" ) && ( value as videoConfigType ) . src !== undefined ) {
72
- const currentValue = value as videoConfigType ;
73
- const delta = new Delta ( )
74
- . retain ( selection ?. index ?? 0 )
75
- . delete ( selection ?. length ?? 0 )
76
- . insert (
77
- { video : currentValue } ,
78
- { width : currentValue . width , height : currentValue . height }
79
- ) ;
80
- ref . current ?. updateContents ( delta , Emitter . sources . USER ) ;
70
+ onSubmit : ( submittedValue : VideoFormType ) => {
71
+ if (
72
+ Object . hasOwn ( submittedValue , "src" ) &&
73
+ ( submittedValue as videoConfigType ) . src !== undefined
74
+ ) {
75
+ const currentValue = submittedValue as videoConfigType ;
76
+ if ( value . type === "video" ) {
77
+ const index = selection ?. index ?? 0 ;
78
+ const length = selection ?. length ?? 1 ;
79
+ const videoConfig = {
80
+ width : currentValue . width ,
81
+ height : currentValue . height
82
+ } ;
83
+ // update existing video value
84
+ const delta = new Delta ( ) . retain ( index ) . retain ( length , videoConfig ) ;
85
+ ref . current ?. updateContents ( delta , Emitter . sources . USER ) ;
86
+ } else {
87
+ // insert new video
88
+ const delta = new Delta ( )
89
+ . retain ( selection ?. index ?? 0 )
90
+ . delete ( selection ?. length ?? 0 )
91
+ . insert (
92
+ { video : currentValue } ,
93
+ { width : currentValue . width , height : currentValue . height }
94
+ ) ;
95
+ ref . current ?. updateContents ( delta , Emitter . sources . USER ) ;
96
+ }
81
97
} else {
82
- const currentValue = value as videoEmbedConfigType ;
98
+ const currentValue = submittedValue as videoEmbedConfigType ;
83
99
const res = ref . current ?. clipboard . convert ( {
84
100
html : currentValue . embedcode
85
101
} ) ;
86
102
if ( res ) {
103
+ // insert video via embed code;
87
104
const delta = new Delta ( )
88
105
. retain ( selection ?. index ?? 0 )
89
106
. delete ( selection ?. length ?? 0 )
@@ -95,7 +112,8 @@ export function useEmbedModal(ref: MutableRefObject<Quill | null>): ModalReturnT
95
112
closeDialog ( ) ;
96
113
} ,
97
114
onClose : closeDialog ,
98
- selection : ref . current ?. getSelection ( )
115
+ selection : ref . current ?. getSelection ( ) ,
116
+ defaultValue : { ...value }
99
117
}
100
118
} ) ;
101
119
openDialog ( ) ;
@@ -114,7 +132,7 @@ export function useEmbedModal(ref: MutableRefObject<Quill | null>): ModalReturnT
114
132
onSubmit : ( value : viewCodeConfigType ) => {
115
133
const newDelta = ref . current ?. clipboard . convert ( { html : value . src } ) ;
116
134
if ( newDelta ) {
117
- ref . current ?. setContents ( newDelta , Quill . sources . USER ) ;
135
+ ref . current ?. setContents ( newDelta , Emitter . sources . USER ) ;
118
136
}
119
137
closeDialog ( ) ;
120
138
} ,
@@ -142,9 +160,11 @@ export function useEmbedModal(ref: MutableRefObject<Quill | null>): ModalReturnT
142
160
width : value . width ,
143
161
height : value . height
144
162
} ;
163
+ // update existing image attribute
145
164
const imageUpdateDelta = new Delta ( ) . retain ( index ) . retain ( length , imageConfig ) ;
146
- ref . current ?. updateContents ( imageUpdateDelta ) ;
165
+ ref . current ?. updateContents ( imageUpdateDelta , Emitter . sources . USER ) ;
147
166
} else {
167
+ // upload new image
148
168
if ( selection && value . files ) {
149
169
uploadImage ( ref , selection , value ) ;
150
170
}
0 commit comments