import { v4 as uuid } from 'uuid' ; import { UploadFunc } from '../share/var' ; import getDecorated from './decorate' ; import { isPromise } from './tool' ; function getUploadPlaceholder ( file , onImageUpload ) { const placeholder = getDecorated ( '' , 'image' , { target : `Uploading_${ uuid ( ) }` , imageUrl : '' , } ) . text ; const uploaded = new Promise ( ( resolve ) => { let isCallback = true ; const handleUploaded = ( url ) => { if ( isCallback ) { console . warn ( 'Deprecated: onImageUpload should return a Promise, callback will be removed in future' ) ; } resolve ( getDecorated ( '' , 'image' , { target : file . name , imageUrl : url , } ) . text ) ; } ; const upload = onImageUpload ( file , handleUploaded ) ; if ( isPromise ( upload ) ) { isCallback = false ; upload . then ( handleUploaded ) ; } } ) ; return { placeholder , uploaded } ; } export default getUploadPlaceholder ;