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 }) {
const { onDrop, ready, dragging, setDragging } = useContext(DndUploaderContext);
const { onDrop, ready, dragging, setDragging } =
useContext(DndUploaderContext);
const { getRootProps, getInputProps } = useDropzone({
onDrop,
disabled: !ready,

View File

@ -1,14 +1,17 @@
import { useEffect } from 'react';
import { useEffect } from "react";
export function useImagePaste(onImagePaste) {
useEffect(() => {
const handlePaste = (e) => {
const items = e.clipboardData.items;
for (let i = 0; i < items.length; i++) {
if (items[i].type.indexOf('image/') !== -1) {
if (items[i].type.indexOf("image/") !== -1) {
e.preventDefault();
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 });
onImagePaste(file);
break;
@ -16,9 +19,9 @@ export function useImagePaste(onImagePaste) {
}
};
document.addEventListener('paste', handlePaste);
document.addEventListener("paste", handlePaste);
return () => {
document.removeEventListener('paste', handlePaste);
document.removeEventListener("paste", handlePaste);
};
}, [onImagePaste]);
}