| 58 | } |
| 59 | |
| 60 | public static async copyOnce(text: string): Promise<void> { |
| 61 | /** |
| 62 | * Copy on the fly using the native `navigator` API -- useful in cases where it's inefficient to use Clipboard.js |
| 63 | * as it requires maintaining the text in memory before copying is triggered via a listener. |
| 64 | * |
| 65 | * Note that in Firefox and Safari this method will only work if part of a user action callback (e.g. button.onClick) |
| 66 | */ |
| 67 | try { |
| 68 | await navigator.clipboard.writeText(text); |
| 69 | DPClipboard.onSuccess(); |
| 70 | } catch (e) { |
| 71 | console.error("Error copying to clipboard: ", e); |
| 72 | } |
| 73 | } |
| 74 | } |