|
@@ -1,5 +1,7 @@
|
1
|
1
|
// @flow
|
2
|
2
|
|
|
3
|
+import clipboardCopy from 'clipboard-copy';
|
|
4
|
+
|
3
|
5
|
/**
|
4
|
6
|
* A helper function that behaves similar to Object.assign, but only reassigns a
|
5
|
7
|
* property in target if it's defined in source.
|
|
@@ -33,31 +35,11 @@ export function assignIfDefined(target: Object, source: Object) {
|
33
|
35
|
*/
|
34
|
36
|
export async function copyText(textToCopy: string) {
|
35
|
37
|
try {
|
36
|
|
- await navigator.clipboard.writeText(textToCopy);
|
|
38
|
+ await clipboardCopy(textToCopy);
|
37
|
39
|
|
38
|
40
|
return true;
|
39
|
|
- } catch (clipboardAPIError) { // The Clipboard API is not supported.
|
40
|
|
- let fakeTextArea = document.createElement('textarea');
|
41
|
|
-
|
42
|
|
- // $FlowFixMe
|
43
|
|
- fakeTextArea = document.body.appendChild(fakeTextArea);
|
44
|
|
- fakeTextArea.value = textToCopy;
|
45
|
|
- fakeTextArea.focus();
|
46
|
|
- fakeTextArea.select();
|
47
|
|
-
|
48
|
|
- let result;
|
49
|
|
-
|
50
|
|
- try {
|
51
|
|
- result = document.execCommand('copy');
|
52
|
|
- } catch (error) {
|
53
|
|
- result = false;
|
54
|
|
- }
|
55
|
|
-
|
56
|
|
- // $FlowFixMe
|
57
|
|
- document.body.removeChild(fakeTextArea);
|
58
|
|
-
|
59
|
|
-
|
60
|
|
- return result;
|
|
41
|
+ } catch (e) {
|
|
42
|
+ return false;
|
61
|
43
|
}
|
62
|
44
|
}
|
63
|
45
|
|