@@ -8,6 +8,10 @@ import { TextStyle } from '@tiptap/extension-text-style';
88import { Color } from '@tiptap/extension-color' ;
99import { FontFamily } from '@tiptap/extension-font-family' ;
1010import { FontSize } from './extensions/font-size' ;
11+ import i18next from 'i18next' ;
12+ import notificationsService , { ToastType } from '@/services/notifications' ;
13+ import { bytesToString } from '@/utils/bytes-to-string' ;
14+ import { MAX_INLINE_IMAGE_BYTES } from '@/constants' ;
1115
1216export const FONTS = [
1317 { label : 'Arial' , value : 'Arial, sans-serif' } ,
@@ -84,7 +88,40 @@ export const EDITOR_CONFIG = {
8488 ] ,
8589 editorProps : {
8690 attributes : {
87- class : 'focus:outline-none h-full' ,
91+ class : 'mail-content focus:outline-none h-full' ,
92+ } ,
93+ handleDrop : ( view : any , event : any , _slice : any , moved : boolean ) => {
94+ if ( moved ) return false ;
95+
96+ const files = Array . from ( event . dataTransfer ?. files ?? [ ] ) as File [ ] ;
97+ const allImages = files . filter ( ( file ) => file . type . startsWith ( 'image/' ) ) ;
98+ if ( allImages . length === 0 ) return false ;
99+
100+ event . preventDefault ( ) ;
101+
102+ const images = allImages . filter ( ( file ) => file . size <= MAX_INLINE_IMAGE_BYTES ) ;
103+ if ( images . length < allImages . length ) {
104+ notificationsService . show ( {
105+ text : i18next . t ( 'modals.composeMessageDialog.errors.inlineImageTooLarge' , {
106+ maxSize : bytesToString ( { size : MAX_INLINE_IMAGE_BYTES } ) ,
107+ } ) ,
108+ type : ToastType . Warning ,
109+ } ) ;
110+ }
111+
112+ const coords = view . posAtCoords ( { left : event . clientX , top : event . clientY } ) ;
113+ const pos = coords ?. pos ?? view . state . selection . from ;
114+
115+ images . forEach ( ( file ) => {
116+ const reader = new FileReader ( ) ;
117+ reader . onload = ( ) => {
118+ if ( typeof reader . result !== 'string' ) return ;
119+ const node = view . state . schema . nodes . image . create ( { src : reader . result } ) ;
120+ view . dispatch ( view . state . tr . insert ( pos , node ) ) ;
121+ } ;
122+ reader . readAsDataURL ( file ) ;
123+ } ) ;
124+ return true ;
88125 } ,
89126 handlePaste : ( view : any , event : any ) => {
90127 const text = event . clipboardData ?. getData ( 'text/plain' ) ;
0 commit comments