4040 @image-paste =" onPaste"
4141 @dragover.prevent.stop =" draggedOver = true"
4242 @dragleave.prevent.stop =" draggedOver = false"
43- @drop.prevent.stop =" onEditorDrop" >
43+ @image- drop =" onEditorDrop" >
4444 <MenuBar v-if =" renderMenus"
4545 ref =" menubar"
4646 :editor =" tiptap"
@@ -571,29 +571,29 @@ export default {
571571 this .uploadImageFiles (e .detail .files )
572572 },
573573 onEditorDrop (e ) {
574- this .uploadImageFiles (e .dataTransfer .files )
574+ this .uploadImageFiles (e .detail .files , e . detail . position )
575575 this .draggedOver = false
576576 },
577- uploadImageFiles (files ) {
577+ uploadImageFiles (files , position = null ) {
578578 if (! files) {
579579 return
580580 }
581581 this .uploadingImages = true
582582 const uploadPromises = [... files].map ((file ) => {
583- return this .uploadImageFile (file)
583+ return this .uploadImageFile (file, position )
584584 })
585585 Promise .all (uploadPromises).then ((values ) => {
586586 this .uploadingImages = false
587587 })
588588 },
589- async uploadImageFile (file ) {
589+ async uploadImageFile (file , position = null ) {
590590 if (! IMAGE_MIMES .includes (file .type )) {
591591 showError (t (' text' , ' Image file format not supported' ))
592592 return
593593 }
594594
595595 return this .syncService .uploadImage (file).then ((response ) => {
596- this .insertAttachmentImage (response .data ? .name , response .data ? .id )
596+ this .insertAttachmentImage (response .data ? .name , response .data ? .id , position )
597597 }).catch ((error ) => {
598598 console .error (error)
599599 showError (error? .response ? .data ? .error )
@@ -610,12 +610,16 @@ export default {
610610 this .uploadingImages = false
611611 })
612612 },
613- insertAttachmentImage (name , fileId ) {
613+ insertAttachmentImage (name , fileId , position = null ) {
614614 const src = ' text://image?imageFileName=' + encodeURIComponent (name)
615615 // simply get rid of brackets to make sure link text is valid
616616 // as it does not need to be unique and matching the real file name
617617 const alt = name .replaceAll (/ [[\] ] / g , ' ' )
618- this .tiptap .chain ().setImage ({ src, alt }).focus ().run ()
618+ if (position) {
619+ this .tiptap .chain ().focus (position).setImage ({ src, alt }).focus ().run ()
620+ } else {
621+ this .tiptap .chain ().setImage ({ src, alt }).focus ().run ()
622+ }
619623 },
620624 },
621625}
0 commit comments