feat: allow pasting files

This commit is contained in:
Maya 2025-09-10 10:50:05 +03:00
parent 1710cd038e
commit 0d87e1e064
No known key found for this signature in database
1 changed files with 30 additions and 3 deletions

View File

@ -16,6 +16,7 @@
dropping, dropping,
vertdLoaded, vertdLoaded,
locale, locale,
updateLocale,
} from "$lib/store/index.svelte"; } from "$lib/store/index.svelte";
import "$lib/css/app.scss"; import "$lib/css/app.scss";
import { browser } from "$app/environment"; import { browser } from "$app/environment";
@ -58,18 +59,39 @@
dropping.set(drag); dropping.set(drag);
}; };
const handlePaste = (e: ClipboardEvent) => {
const clipboardData = e.clipboardData;
if (!clipboardData || !clipboardData.files.length) return;
e.preventDefault();
if (page.url.pathname !== "/jpegify/") {
const oldLength = files.files.length;
files.add(clipboardData.files);
if (oldLength !== files.files.length) goto("/convert");
} else {
files.add(clipboardData.files);
}
};
onMount(() => { onMount(() => {
initAnimStores(); initAnimStores();
isMobile.set(window.innerWidth <= 768); const handleResize = () => {
window.addEventListener("resize", () => {
isMobile.set(window.innerWidth <= 768); isMobile.set(window.innerWidth <= 768);
}); };
isMobile.set(window.innerWidth <= 768); // initial page load
window.addEventListener("resize", handleResize); // handle window resize
window.addEventListener("paste", handlePaste);
effects.set(localStorage.getItem("effects") !== "false"); // defaults to true if not set effects.set(localStorage.getItem("effects") !== "false"); // defaults to true if not set
theme.set( theme.set(
(localStorage.getItem("theme") as "light" | "dark") || "light", (localStorage.getItem("theme") as "light" | "dark") || "light",
); );
updateLocale(localStorage.getItem("locale") || "en");
Settings.instance.load(); Settings.instance.load();
fetch(`${Settings.instance.settings.vertdURL}/api/version`).then( fetch(`${Settings.instance.settings.vertdURL}/api/version`).then(
@ -77,6 +99,11 @@
if (res.ok) $vertdLoaded = true; if (res.ok) $vertdLoaded = true;
}, },
); );
return () => {
window.removeEventListener("paste", handlePaste);
window.removeEventListener("resize", handleResize);
};
}); });
$effect(() => { $effect(() => {