import { useCallback, ClipboardEventHandler } from 'react'; import { getDataTransferFiles } from '../utils/dom'; export const useFilePasteHandler = (onPaste: (file: File[]) => void): ClipboardEventHandler => useCallback( (evt) => { const files = getDataTransferFiles(evt.clipboardData); if (files) { // [Gitea #132] An image copied from a web page arrives with a // text/html `…` fragment and a text/plain URL beside // the bitmap. Only the file is wanted — stop the editor's own // HTML/text insertion so nothing else lands in the composer. evt.preventDefault(); onPaste(files); } }, [onPaste], );