| 40 | |
| 41 | // copy text to clipboard |
| 42 | export const copyStr = (textToCopy: string) => { |
| 43 | // Navigator clipboard api needs a secure context (https) |
| 44 | if (navigator.clipboard && window.isSecureContext) { |
| 45 | navigator.clipboard.writeText(textToCopy); |
| 46 | } else { |
| 47 | // Use the 'out of viewport hidden text area' trick |
| 48 | const textArea = document.createElement('textarea'); |
| 49 | textArea.value = textToCopy; |
| 50 | // Move textarea out of the viewport so it's not visible |
| 51 | textArea.style.position = 'absolute'; |
| 52 | textArea.style.left = '-999999px'; |
| 53 | document.body.prepend(textArea); |
| 54 | textArea.select(); |
| 55 | document.execCommand('copy'); |
| 56 | } |
| 57 | }; |
| 58 | |
| 59 | /** |
| 60 | * filter out redundant fields upon sending to API |