import type { Node } from '@milkdown/prose' ; import type { Uploader } from './upload' ; const readImageAsBase64 = ( file ) : Promise < { alt : string ; src : string ; } > => { return new Promise ( ( resolve ) => { const reader = new FileReader ( ) ; reader . addEventListener ( 'load' , ( ) => { resolve ( { alt : file . name , src : reader . result as string , } ) ; } , false ) ; reader . readAsDataURL ( file ) ; } ) ; } ; export const defaultUploader = async ( files , schema ) => { const imgs = [ ] ; for ( let i = 0 ; i < files . length ; i ++ ) { const file = files . item ( i ) ; if ( ! file ) { continue ; } if ( ! file . type . includes ( 'image' ) ) { continue ; } imgs . push ( file ) ; } const { image } = schema . nodes ; const data = await Promise . all ( imgs . map ( ( img ) => readImageAsBase64 ( img ) ) ) ; return data . map ( ( { alt , src } ) => image . createAndFill ( { src , alt } ) as Node ) ; } ;