mirror of
https://github.com/coaidev/coai.git
synced 2025-05-29 18:00:14 +09:00
feat: support full screen file upload on file uploader
This commit is contained in:
parent
6f3a8cbcc9
commit
d9e5c2f89c
@ -260,14 +260,8 @@ function FileInput({ id, loading, className, handleEvent }: FileInputProps) {
|
||||
const ref = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!ref.current) return;
|
||||
const target = ref.current as HTMLLabelElement;
|
||||
useDraggableInput(target, handleEvent);
|
||||
return () => {
|
||||
target.removeEventListener("dragover", () => {});
|
||||
target.removeEventListener("drop", () => {});
|
||||
};
|
||||
}, [ref]);
|
||||
return useDraggableInput(window.document.body, handleEvent);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
@ -113,32 +113,34 @@ export function getSelectionTextInArea(el: HTMLElement): string {
|
||||
}
|
||||
|
||||
export function useDraggableInput(
|
||||
target: HTMLLabelElement,
|
||||
target: HTMLElement,
|
||||
handleChange: (files: File[]) => void,
|
||||
) {
|
||||
/**
|
||||
* Make input element draggable
|
||||
* @param t i18n function
|
||||
* @param toast Toast function
|
||||
* @param target Input element
|
||||
* @param handleChange Handle change function
|
||||
* @example
|
||||
* const input = document.getElementById("input") as HTMLLabelElement;
|
||||
* useDraggableInput(t, toast, input, handleChange);
|
||||
*/
|
||||
|
||||
target.addEventListener("dragover", (e) => {
|
||||
const dragOver = (e: DragEvent) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
});
|
||||
target.addEventListener("drop", (e) => {
|
||||
}
|
||||
|
||||
const drop = (e: DragEvent) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
const files = e.dataTransfer?.files || ([] as File[]);
|
||||
if (!files.length) return;
|
||||
handleChange(Array.from(files));
|
||||
});
|
||||
}
|
||||
|
||||
target.addEventListener("dragover", dragOver);
|
||||
target.addEventListener("drop", drop);
|
||||
|
||||
return () => {
|
||||
target.removeEventListener("dragover", dragOver);
|
||||
target.removeEventListener("drop", drop);
|
||||
}
|
||||
}
|
||||
|
||||
export function testNumberInputEvent(e: any): boolean {
|
||||
|
Loading…
Reference in New Issue
Block a user