-
-class Clipboard {
+export class Clipboard {
/**
* Constructor
* @return {boolean}
*/
containsTabularData() {
- const rtfData = this.data.getData( 'text/rtf');
+ const rtfData = this.data.getData('text/rtf');
return rtfData && rtfData.includes('\\trowd');
}
* @return {Array<File>}
*/
getImages() {
- const types = this.data.types;
- const files = this.data.files;
+ const {types} = this.data;
+ const {files} = this.data;
const images = [];
for (const type of types) {
return images;
}
+
}
-export default Clipboard;
\ No newline at end of file
+export async function copyTextToClipboard(text) {
+ if (window.isSecureContext && navigator.clipboard) {
+ await navigator.clipboard.writeText(text);
+ return;
+ }
+
+ // Backup option where we can't use the navigator.clipboard API
+ 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.body.removeChild(tempInput);
+}