fix(frontend): handle clipboard fallback and markdown word export

This commit is contained in:
吉鑫升 committed 2026-07-03 16:54:16 +08:00
1 parent 195ef3ee40
commit db2f21191c
6 files changed
+86 -37

No files matched your search

+44
View File
@@ -0,0 +1,44 @@
export async function copyTextToClipboard(text: string): Promise<void> {
let clipboardError: unknown;
if (typeof navigator !== "undefined" && navigator.clipboard?.writeText) {
try {
await navigator.clipboard.writeText(text);
return;
} catch (error) {
clipboardError = error;
}
}
if (typeof document === "undefined" || !document.body) {
throw clipboardError instanceof Error
? clipboardError
: new Error("Clipboard is not available");
}
const textarea = document.createElement("textarea");
textarea.value = text;
textarea.setAttribute("readonly", "");
textarea.style.position = "fixed";
textarea.style.top = "0";
textarea.style.left = "0";
textarea.style.width = "1px";
textarea.style.height = "1px";
textarea.style.opacity = "0";
document.body.appendChild(textarea);
textarea.focus();
textarea.select();
textarea.setSelectionRange(0, textarea.value.length);
try {
const copied = document.execCommand("copy");
if (!copied) {
throw clipboardError instanceof Error
? clipboardError
: new Error("Copy command failed");
}
} finally {
textarea.remove();
}
}