@uiw/copy-to-clipboard
Advanced tools
Comparing version 1.0.6 to 1.0.7
/*! | ||
* @uiw/copy-to-clipboard v1.0.6 | ||
* @uiw/copy-to-clipboard v1.0.7 | ||
* Copy to clipboard. | ||
@@ -14,5 +14,6 @@ * | ||
function copyTextToClipboard(text, cb) { | ||
const textArea = document.createElement('textarea'); | ||
// | ||
// *** This styling is an extra step which is likely not required. *** | ||
// | ||
// https://github.com/w3c/clipboard-apis/blob/master/explainer.adoc#writing-to-the-clipboard | ||
// | ||
@@ -31,23 +32,12 @@ // Why is it here? To ensure: | ||
// Place in top-left corner of screen regardless of scroll position. | ||
textArea.style = { | ||
position: 'fixed', | ||
top: '-100px', | ||
left: 0, | ||
// Ensure it has a small width and height. Setting to 1px / 1em | ||
// doesn't work as this gives a negative w/h on some browsers. | ||
width: '2em', | ||
height: '2em', | ||
// We don't need padding, reducing the size if it does flash render. | ||
padding: 0, | ||
// Clean up any borders. | ||
border: 'none', | ||
outline: 'none', | ||
boxShadow: 'none', | ||
// Avoid flash of white box if rendered for any reason. | ||
background: 'transparent', | ||
const el = document.createElement('textarea'); | ||
el.value = text; | ||
el.setAttribute('readonly', ''); | ||
el.style = { | ||
position: 'absolute', | ||
left: '-9999px', | ||
}; | ||
textArea.value = text; | ||
document.body.appendChild(textArea); | ||
textArea.select(); | ||
document.body.appendChild(el); | ||
const selected = document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false; | ||
el.select(); | ||
try { | ||
@@ -58,7 +48,12 @@ const successful = document.execCommand('copy'); | ||
} catch (err) { | ||
cb && cb(false); | ||
// console.log('Oops, unable to copy'); | ||
} | ||
document.body.removeChild(textArea); | ||
document.body.removeChild(el); | ||
if (selected) { | ||
document.getSelection().removeAllRanges(); | ||
document.getSelection().addRange(selected); | ||
} | ||
} | ||
module.exports = copyTextToClipboard; |
/*! | ||
* @uiw/copy-to-clipboard v1.0.6 | ||
* @uiw/copy-to-clipboard v1.0.7 | ||
* Copy to clipboard. | ||
@@ -12,5 +12,6 @@ * | ||
function copyTextToClipboard(text, cb) { | ||
const textArea = document.createElement('textarea'); | ||
// | ||
// *** This styling is an extra step which is likely not required. *** | ||
// | ||
// https://github.com/w3c/clipboard-apis/blob/master/explainer.adoc#writing-to-the-clipboard | ||
// | ||
@@ -29,23 +30,12 @@ // Why is it here? To ensure: | ||
// Place in top-left corner of screen regardless of scroll position. | ||
textArea.style = { | ||
position: 'fixed', | ||
top: '-100px', | ||
left: 0, | ||
// Ensure it has a small width and height. Setting to 1px / 1em | ||
// doesn't work as this gives a negative w/h on some browsers. | ||
width: '2em', | ||
height: '2em', | ||
// We don't need padding, reducing the size if it does flash render. | ||
padding: 0, | ||
// Clean up any borders. | ||
border: 'none', | ||
outline: 'none', | ||
boxShadow: 'none', | ||
// Avoid flash of white box if rendered for any reason. | ||
background: 'transparent', | ||
const el = document.createElement('textarea'); | ||
el.value = text; | ||
el.setAttribute('readonly', ''); | ||
el.style = { | ||
position: 'absolute', | ||
left: '-9999px', | ||
}; | ||
textArea.value = text; | ||
document.body.appendChild(textArea); | ||
textArea.select(); | ||
document.body.appendChild(el); | ||
const selected = document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false; | ||
el.select(); | ||
try { | ||
@@ -56,7 +46,12 @@ const successful = document.execCommand('copy'); | ||
} catch (err) { | ||
cb && cb(false); | ||
// console.log('Oops, unable to copy'); | ||
} | ||
document.body.removeChild(textArea); | ||
document.body.removeChild(el); | ||
if (selected) { | ||
document.getSelection().removeAllRanges(); | ||
document.getSelection().addRange(selected); | ||
} | ||
} | ||
export default copyTextToClipboard; |
/*! | ||
* @uiw/copy-to-clipboard v1.0.6 | ||
* @uiw/copy-to-clipboard v1.0.7 | ||
* Copy to clipboard. | ||
@@ -18,5 +18,6 @@ * | ||
function copyTextToClipboard(text, cb) { | ||
const textArea = document.createElement('textarea'); | ||
// | ||
// *** This styling is an extra step which is likely not required. *** | ||
// | ||
// https://github.com/w3c/clipboard-apis/blob/master/explainer.adoc#writing-to-the-clipboard | ||
// | ||
@@ -35,23 +36,12 @@ // Why is it here? To ensure: | ||
// Place in top-left corner of screen regardless of scroll position. | ||
textArea.style = { | ||
position: 'fixed', | ||
top: '-100px', | ||
left: 0, | ||
// Ensure it has a small width and height. Setting to 1px / 1em | ||
// doesn't work as this gives a negative w/h on some browsers. | ||
width: '2em', | ||
height: '2em', | ||
// We don't need padding, reducing the size if it does flash render. | ||
padding: 0, | ||
// Clean up any borders. | ||
border: 'none', | ||
outline: 'none', | ||
boxShadow: 'none', | ||
// Avoid flash of white box if rendered for any reason. | ||
background: 'transparent', | ||
const el = document.createElement('textarea'); | ||
el.value = text; | ||
el.setAttribute('readonly', ''); | ||
el.style = { | ||
position: 'absolute', | ||
left: '-9999px', | ||
}; | ||
textArea.value = text; | ||
document.body.appendChild(textArea); | ||
textArea.select(); | ||
document.body.appendChild(el); | ||
const selected = document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false; | ||
el.select(); | ||
try { | ||
@@ -62,5 +52,10 @@ const successful = document.execCommand('copy'); | ||
} catch (err) { | ||
cb && cb(false); | ||
// console.log('Oops, unable to copy'); | ||
} | ||
document.body.removeChild(textArea); | ||
document.body.removeChild(el); | ||
if (selected) { | ||
document.getSelection().removeAllRanges(); | ||
document.getSelection().addRange(selected); | ||
} | ||
} | ||
@@ -67,0 +62,0 @@ |
{ | ||
"name": "@uiw/copy-to-clipboard", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "Copy to clipboard.", | ||
@@ -5,0 +5,0 @@ "main": "dist/copy-to-clipboard.cjs.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8940
196