X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/baf5edd73a12e1305f147f0082f00662d50edd0a..refs/pull/5239/head:/resources/js/services/clipboard.js diff --git a/resources/js/services/clipboard.js b/resources/js/services/clipboard.js index c0b0fbfab..5f73c3020 100644 --- a/resources/js/services/clipboard.js +++ b/resources/js/services/clipboard.js @@ -1,4 +1,3 @@ - export class Clipboard { /** @@ -21,7 +20,7 @@ export class Clipboard { * @return {boolean} */ containsTabularData() { - const rtfData = this.data.getData( 'text/rtf'); + const rtfData = this.data.getData('text/rtf'); return rtfData && rtfData.includes('\\trowd'); } @@ -30,8 +29,7 @@ export class Clipboard { * @return {Array} */ getImages() { - const types = this.data.types; - const files = this.data.files; + const {types} = this.data; const images = []; for (const type of types) { @@ -41,14 +39,21 @@ export class Clipboard { } } - for (const file of files) { - if (file.type.includes('image')) { - images.push(file); - } - } + const imageFiles = this.getFiles().filter(f => f.type.includes('image')); + images.push(...imageFiles); return images; } + + /** + * Get the files included in the clipboard data. + * @return {File[]} + */ + getFiles() { + const {files} = this.data; + return [...files]; + } + } export async function copyTextToClipboard(text) { @@ -58,13 +63,11 @@ export async function copyTextToClipboard(text) { } // Backup option where we can't use the navigator.clipboard API - const tempInput = document.createElement("textarea"); - tempInput.style = "position: absolute; left: -1000px; top: -1000px;"; + const tempInput = document.createElement('textarea'); + tempInput.style = 'position: absolute; left: -1000px; top: -1000px;'; tempInput.value = text; document.body.appendChild(tempInput); tempInput.select(); - document.execCommand("copy"); + document.execCommand('copy'); document.body.removeChild(tempInput); } - -export default Clipboard; \ No newline at end of file