mirror of
https://github.com/Ku6epXBOCTuK/easy-png-tools.git
synced 2026-11-13 17:08:20 +00:00
feat: upload source by ctrl+v and dropzone
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
type ToolSchema,
|
||||
} from "$lib/registry-schema";
|
||||
import { downloadZip } from "$lib/zip";
|
||||
import { onMount } from "svelte";
|
||||
import { SvelteSet } from "svelte/reactivity";
|
||||
|
||||
interface Props {
|
||||
@@ -235,6 +236,25 @@
|
||||
init();
|
||||
});
|
||||
|
||||
onMount(() => {
|
||||
if (inputMode !== "image") return;
|
||||
function onPaste(e: ClipboardEvent) {
|
||||
const target = e.target as HTMLElement | null;
|
||||
if (target?.closest("input, textarea, [contenteditable]")) return;
|
||||
for (const item of e.clipboardData?.items ?? []) {
|
||||
if (item.kind !== "file" || !item.type.startsWith("image/")) continue;
|
||||
const file = item.getAsFile();
|
||||
if (file) {
|
||||
e.preventDefault();
|
||||
void handleFile(file);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
window.addEventListener("paste", onPaste);
|
||||
return () => window.removeEventListener("paste", onPaste);
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
if (!started) return;
|
||||
if (inputMode === "image" && !source) return;
|
||||
|
||||
Reference in New Issue
Block a user