import { Image } from '../types' ; export function formatImageLink ( name , width , height , url ) { return `![${ name }|${ width } x ${ height }](${ url })` ; } export function replaceImageUploadStatus ( raw , imageUploadToken , url ) { raw = raw . replace ( `[uploading...](${ imageUploadToken })` , url ) ; return raw ; } export function insertImageUploadStatus ( raw , cursorPosition , imageUploadToken ) { const textBeforeCursorPosition = raw . substring ( 0 , cursorPosition ) ; const textAfterCursorPosition = raw . substring ( cursorPosition , raw . length ) ; raw = `${ textBeforeCursorPosition }${ textBeforeCursorPosition . length ? '\n' : '' }[uploading...](${ imageUploadToken })${ textAfterCursorPosition . length ? '\n' : ' ' }${ textAfterCursorPosition }` ; return raw ; } export function reformatMarkdownBeforeUpload ( raw , startingCursorPosition , imagesArray , setValue ) { const result = insertImageUploadStatus ( raw , startingCursorPosition , imagesArray . length + 1 ) ; setValue ( 'raw' , result ) ; } export function reformatMarkdownAfterUpload ( raw , imagesArray , token , setValue ) { let newText = raw ; newText = replaceImageUploadStatus ( raw , token , imagesArray [ token - 1 ] . link ) ; setValue ( 'raw' , newText ) ; } export function updateImagesArray ( imagesArray , imageUrl , token , setImagesArray ) { let newArray = imagesArray ; newArray [ token ] = { link : imageUrl , done : true } ; setImagesArray ( newArray ) ; }