| b69ab31 | | | 1 | /** |
| b69ab31 | | | 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| b69ab31 | | | 3 | * |
| b69ab31 | | | 4 | * This source code is licensed under the MIT license found in the |
| b69ab31 | | | 5 | * LICENSE file in the root directory of this source tree. |
| b69ab31 | | | 6 | */ |
| b69ab31 | | | 7 | |
| b69ab31 | | | 8 | import platform from './platform'; |
| b69ab31 | | | 9 | |
| b69ab31 | | | 10 | /** Copy text to the clipboard */ |
| b69ab31 | | | 11 | export function clipboardCopyText(text: string) { |
| b69ab31 | | | 12 | return platform.clipboardCopy(text); |
| b69ab31 | | | 13 | } |
| b69ab31 | | | 14 | |
| b69ab31 | | | 15 | /** |
| b69ab31 | | | 16 | * Copy text that refers to a URL to the clipboard. |
| b69ab31 | | | 17 | * If pasted into a rich text input, it will paste as text with a URL link. |
| b69ab31 | | | 18 | * If pasted into a plain text input, it will just use the text without the url. |
| b69ab31 | | | 19 | */ |
| b69ab31 | | | 20 | export function clipboardCopyLink(text: string, url: string) { |
| b69ab31 | | | 21 | return platform.clipboardCopy(text, clipboardLinkHtml(text, url)); |
| b69ab31 | | | 22 | } |
| b69ab31 | | | 23 | |
| b69ab31 | | | 24 | /** |
| b69ab31 | | | 25 | * HTML <a> tag for `text` pointing to `url`. Useful for copying rich text links. |
| b69ab31 | | | 26 | */ |
| b69ab31 | | | 27 | export function clipboardLinkHtml(text: string, url: string): string { |
| b69ab31 | | | 28 | return `<a href="${url}">${text}</a>`; |
| b69ab31 | | | 29 | } |