export class ImagePasteHandler { private element : any ; private mutator : any ; constructor ( element , mutator ) { this . element = element ; this . mutator = mutator ; if ( ! this . mutator ) { this . mutator = function ( val ) { return val ; } ; } } start ( ) { this . element . addEventListener ( "paste" , async function ( event ) { const imagePasted = await ImagePasteHandler . handlePasteData ( event ) ; if ( imagePasted . image ) { event . preventDefault ( ) ; let text = imagePasted . image ; text = this . mutator ( text ) ; document . execCommand ( "insertHTML" , false , text ) ; return true ; } return true ; } . bind ( this ) ) ; } ; /**
     * Handle pasted data and convert to a data: URL when necessary
     */ static handlePasteData ( e ) { const orgEvent = e ; for ( let i = 0 ; i < orgEvent . clipboardData . items . length ; i ++ ) { let clipboardDataItem = orgEvent . clipboardData . items [ i ] ; if ( clipboardDataItem . kind === "file" && clipboardDataItem . type === "image/png" ) { let imageFile = clipboardDataItem . getAsFile ( ) ; let fileReader = new FileReader ( ) ; return new Promise ( function ( resolve , reject ) { fileReader . onloadend = function ( ) { resolve ( { image : fileReader . result } ) ; } ; fileReader . readAsDataURL ( imageFile ) ; } ) ; } } return new Promise ( function ( resolve ) { resolve ( { } ) ; } ) ; } } ;