|
@@ -31,24 +31,15 @@ export function assignIfDefined(target: Object, source: Object) {
|
31
|
31
|
* @param {string} textToCopy - Text to be copied.
|
32
|
32
|
* @returns {boolean}
|
33
|
33
|
*/
|
34
|
|
-export function copyText(textToCopy: string) {
|
35
|
|
- const fakeTextArea = document.createElement('textarea');
|
|
34
|
+export async function copyText(textToCopy: string) {
|
36
|
35
|
let result;
|
37
|
36
|
|
38
|
|
- // $FlowFixMe
|
39
|
|
- document.body.appendChild(fakeTextArea);
|
40
|
|
- fakeTextArea.value = textToCopy;
|
41
|
|
- fakeTextArea.select();
|
42
|
|
-
|
43
|
37
|
try {
|
44
|
|
- result = document.execCommand('copy');
|
|
38
|
+ result = await navigator.clipboard.writeText(textToCopy);
|
45
|
39
|
} catch (err) {
|
46
|
40
|
result = false;
|
47
|
41
|
}
|
48
|
42
|
|
49
|
|
- // $FlowFixMe
|
50
|
|
- document.body.removeChild(fakeTextArea);
|
51
|
|
-
|
52
|
43
|
return result;
|
53
|
44
|
}
|
54
|
45
|
|