mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 16:51:38 +10:00
fix: add copy fallback
This commit is contained in:
@ -34,18 +34,23 @@ export function useCopyToClipboard(): [CopiedValue, CopyFn] {
|
|||||||
/**
|
/**
|
||||||
* Handle copying values to the clipboard using the ClipboardItem API.
|
* Handle copying values to the clipboard using the ClipboardItem API.
|
||||||
*
|
*
|
||||||
* Allows us to copy async values for Safari. Does not work in FireFox.
|
* Works in all browsers except FireFox.
|
||||||
*
|
*
|
||||||
* https://caniuse.com/mdn-api_clipboarditem
|
* https://caniuse.com/mdn-api_clipboarditem
|
||||||
*/
|
*/
|
||||||
const handleClipboardApiCopy = async (value: CopyValue, blobType = 'text/plain') => {
|
const handleClipboardApiCopy = async (value: CopyValue, blobType = 'text/plain') => {
|
||||||
|
try {
|
||||||
await navigator.clipboard.write([new ClipboardItem({ [blobType]: value })]);
|
await navigator.clipboard.write([new ClipboardItem({ [blobType]: value })]);
|
||||||
|
} catch (e) {
|
||||||
|
// Fallback to attempt.
|
||||||
|
await handleWriteTextCopy(value);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle copying values to the clipboard using `writeText`.
|
* Handle copying values to the clipboard using `writeText`.
|
||||||
*
|
*
|
||||||
* Will not work in Safari for async values.
|
* Works in all browsers except Safari for async values.
|
||||||
*/
|
*/
|
||||||
const handleWriteTextCopy = async (value: CopyValue) => {
|
const handleWriteTextCopy = async (value: CopyValue) => {
|
||||||
await navigator.clipboard.writeText(await value);
|
await navigator.clipboard.writeText(await value);
|
||||||
|
|||||||
Reference in New Issue
Block a user