|
|
|
@ -4,11 +4,21 @@ |
|
|
|
|
|
|
|
|
|
let has_success: boolean = false; |
|
|
|
|
|
|
|
|
|
const tauri_platform = import.meta.env.TAURI_PLATFORM; |
|
|
|
|
const setClipboard = async (text: string) => { |
|
|
|
|
if (tauri_platform) { |
|
|
|
|
// TODO: this won't work for tauri platform. |
|
|
|
|
// const { writeText } = await import("@tauri-apps/api/clipboard"); |
|
|
|
|
// await writeText(text); |
|
|
|
|
} else { |
|
|
|
|
navigator.clipboard.writeText(text); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const on_click = (e) => { |
|
|
|
|
has_success = true; |
|
|
|
|
setTimeout(() => (has_success = false), 2_000); |
|
|
|
|
|
|
|
|
|
navigator.clipboard.writeText(value); |
|
|
|
|
setClipboard(value); |
|
|
|
|
}; |
|
|
|
|
</script> |
|
|
|
|
|
|
|
|
@ -22,9 +32,10 @@ |
|
|
|
|
disabled |
|
|
|
|
readonly |
|
|
|
|
/> |
|
|
|
|
{#if !tauri_platform} |
|
|
|
|
<button |
|
|
|
|
on:click={on_click} |
|
|
|
|
class="absolute end-2 top-1/2 -translate-y-1/2 bg-gray-50 shadow-none text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-lg p-2 inline-flex items-center justify-center" |
|
|
|
|
class="absolute inset-y-0 right-0 p-3 flex items-center text-sm leading-5 bg-transparent shadow-none" |
|
|
|
|
> |
|
|
|
|
<span id="default-icon" class:hidden={has_success}> |
|
|
|
|
<svg |
|
|
|
@ -61,5 +72,6 @@ |
|
|
|
|
</svg> |
|
|
|
|
</span> |
|
|
|
|
</button> |
|
|
|
|
{/if} |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|