mirror of
https://github.com/coaidev/coai.git
synced 2025-05-31 19:00:22 +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);
|
const ref = useRef(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!ref.current) return;
|
return useDraggableInput(window.document.body, handleEvent);
|
||||||
const target = ref.current as HTMLLabelElement;
|
}, []);
|
||||||
useDraggableInput(target, handleEvent);
|
|
||||||
return () => {
|
|
||||||
target.removeEventListener("dragover", () => {});
|
|
||||||
target.removeEventListener("drop", () => {});
|
|
||||||
};
|
|
||||||
}, [ref]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -113,32 +113,34 @@ export function getSelectionTextInArea(el: HTMLElement): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function useDraggableInput(
|
export function useDraggableInput(
|
||||||
target: HTMLLabelElement,
|
target: HTMLElement,
|
||||||
handleChange: (files: File[]) => void,
|
handleChange: (files: File[]) => void,
|
||||||
) {
|
) {
|
||||||
/**
|
/**
|
||||||
* Make input element draggable
|
* 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.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
});
|
}
|
||||||
target.addEventListener("drop", (e) => {
|
|
||||||
|
const drop = (e: DragEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|
||||||
const files = e.dataTransfer?.files || ([] as File[]);
|
const files = e.dataTransfer?.files || ([] as File[]);
|
||||||
if (!files.length) return;
|
if (!files.length) return;
|
||||||
handleChange(Array.from(files));
|
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 {
|
export function testNumberInputEvent(e: any): boolean {
|
||||||
|
Loading…
Reference in New Issue
Block a user