fix(copyText) use a helper library

It does a more elaborate way of textarea copying, hopefully it's more reliable.
pull/8731/head jitsi-meet_5583
Saúl Ibarra Corretgé 4 years ago committed by Дамян Минков
parent eeb5abbbe8
commit 5c46b03251
  1. 5
      package-lock.json
  2. 1
      package.json
  3. 28
      react/features/base/util/helpers.js

5
package-lock.json generated

@ -5858,6 +5858,11 @@
"resolved": "https://registry.npmjs.org/cli-width/-/cli-width-2.2.0.tgz",
"integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk="
},
"clipboard-copy": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/clipboard-copy/-/clipboard-copy-4.0.1.tgz",
"integrity": "sha512-wOlqdqziE/NNTUJsfSgXmBMIrYmfd5V0HCGsR8uAKHcg+h9NENWINcfRjtWGU77wDHC8B8ijV4hMTGYbrKovng=="
},
"cliui": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/cliui/-/cliui-3.2.0.tgz",

@ -41,6 +41,7 @@
"amplitude-js": "7.3.3",
"base64-js": "1.3.1",
"bc-css-flags": "3.0.0",
"clipboard-copy": "4.0.1",
"dropbox": "4.0.9",
"focus-visible": "5.1.0",
"i18n-iso-countries": "3.7.8",

@ -1,5 +1,7 @@
// @flow
import clipboardCopy from 'clipboard-copy';
/**
* A helper function that behaves similar to Object.assign, but only reassigns a
* property in target if it's defined in source.
@ -33,31 +35,11 @@ export function assignIfDefined(target: Object, source: Object) {
*/
export async function copyText(textToCopy: string) {
try {
await navigator.clipboard.writeText(textToCopy);
await clipboardCopy(textToCopy);
return true;
} catch (clipboardAPIError) { // The Clipboard API is not supported.
let fakeTextArea = document.createElement('textarea');
// $FlowFixMe
fakeTextArea = document.body.appendChild(fakeTextArea);
fakeTextArea.value = textToCopy;
fakeTextArea.focus();
fakeTextArea.select();
let result;
try {
result = document.execCommand('copy');
} catch (error) {
result = false;
}
// $FlowFixMe
document.body.removeChild(fakeTextArea);
return result;
} catch (e) {
return false;
}
}

Loading…
Cancel
Save