(code: string)
| 14 | } |
| 15 | |
| 16 | export async function copyCodeBlockToClipboard(code: string) { |
| 17 | const clipboard = navigator.clipboard; |
| 18 | if (!clipboard) { |
| 19 | throw new Error("Clipboard API is unavailable"); |
| 20 | } |
| 21 | |
| 22 | if ( |
| 23 | typeof ClipboardItem !== "undefined" && |
| 24 | typeof clipboard.write === "function" |
| 25 | ) { |
| 26 | try { |
| 27 | await clipboard.write([ |
| 28 | new ClipboardItem({ |
| 29 | "text/html": new Blob([createBuzzCodeBlockHtml(code)], { |
| 30 | type: "text/html", |
| 31 | }), |
| 32 | "text/plain": new Blob([code], { type: "text/plain" }), |
| 33 | }), |
| 34 | ]); |
| 35 | return; |
| 36 | } catch (error) { |
| 37 | console.warn("Failed to write rich code block clipboard data", error); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | await clipboard.writeText(code); |
| 42 | } |
| 43 | |
| 44 | export function getBuzzCodeBlockClipboardText( |
| 45 | clipboardData: DataTransfer | null | undefined, |
no test coverage detected