| 64 | import { readPartText } from "./message-part-text" |
| 65 | |
| 66 | async function writeClipboard(text: string): Promise<boolean> { |
| 67 | const body = typeof document === "undefined" ? undefined : document.body |
| 68 | if (body) { |
| 69 | const textarea = document.createElement("textarea") |
| 70 | textarea.value = text |
| 71 | textarea.setAttribute("readonly", "") |
| 72 | textarea.style.position = "fixed" |
| 73 | textarea.style.opacity = "0" |
| 74 | textarea.style.pointerEvents = "none" |
| 75 | body.appendChild(textarea) |
| 76 | textarea.select() |
| 77 | const copied = document.execCommand("copy") |
| 78 | body.removeChild(textarea) |
| 79 | if (copied) return true |
| 80 | } |
| 81 | |
| 82 | const clipboard = typeof navigator === "undefined" ? undefined : navigator.clipboard |
| 83 | if (!clipboard?.writeText) return false |
| 84 | return clipboard.writeText(text).then( |
| 85 | () => true, |
| 86 | () => false, |
| 87 | ) |
| 88 | } |
| 89 | |
| 90 | function ShellSubmessage(props: { text: string; animate?: boolean }) { |
| 91 | let widthRef: HTMLSpanElement | undefined |