This commit is contained in:
shatfield4 2024-09-19 12:07:54 -07:00
parent 9c3cef242f
commit 2b17687c8f
2 changed files with 11 additions and 7 deletions

View File

@ -161,7 +161,8 @@ export function DnDFileUploaderProvider({ workspace, children }) {
} }
export default function DnDFileUploaderWrapper({ children }) { export default function DnDFileUploaderWrapper({ children }) {
const { onDrop, ready, dragging, setDragging } = useContext(DndUploaderContext); const { onDrop, ready, dragging, setDragging } =
useContext(DndUploaderContext);
const { getRootProps, getInputProps } = useDropzone({ const { getRootProps, getInputProps } = useDropzone({
onDrop, onDrop,
disabled: !ready, disabled: !ready,

View File

@ -1,14 +1,17 @@
import { useEffect } from 'react'; import { useEffect } from "react";
export function useImagePaste(onImagePaste) { export function useImagePaste(onImagePaste) {
useEffect(() => { useEffect(() => {
const handlePaste = (e) => { const handlePaste = (e) => {
const items = e.clipboardData.items; const items = e.clipboardData.items;
for (let i = 0; i < items.length; i++) { for (let i = 0; i < items.length; i++) {
if (items[i].type.indexOf('image/') !== -1) { if (items[i].type.indexOf("image/") !== -1) {
e.preventDefault(); e.preventDefault();
const blob = items[i].getAsFile(); const blob = items[i].getAsFile();
const fileName = blob.name !== "image.png" ? blob.name : `pasted-image.${blob.type.split('/')[1]}`; const fileName =
blob.name !== "image.png"
? blob.name
: `pasted-image.${blob.type.split("/")[1]}`;
const file = new File([blob], fileName, { type: blob.type }); const file = new File([blob], fileName, { type: blob.type });
onImagePaste(file); onImagePaste(file);
break; break;
@ -16,9 +19,9 @@ export function useImagePaste(onImagePaste) {
} }
}; };
document.addEventListener('paste', handlePaste); document.addEventListener("paste", handlePaste);
return () => { return () => {
document.removeEventListener('paste', handlePaste); document.removeEventListener("paste", handlePaste);
}; };
}, [onImagePaste]); }, [onImagePaste]);
} }