This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

core / web / src / lib / copy.svelte.ts
525 B 22 lines
1export const createCopyFeedback = (resetAfter = 1500) => { 2 let lastCopied = $state<string | null>(null); 3 let timer: ReturnType<typeof setTimeout> | undefined; 4 5 $effect(() => () => clearTimeout(timer)); 6 7 return { 8 get copied() { 9 return lastCopied; 10 }, 11 copy: async (label: string, value: string = label) => { 12 try { 13 await navigator.clipboard.writeText(value); 14 } catch { 15 return; 16 } 17 lastCopied = label; 18 clearTimeout(timer); 19 timer = setTimeout(() => (lastCopied = null), resetAfter); 20 } 21 }; 22};