a83a7f34f4
- Extracted logic to get images from paste/drop event into own file to align usage in both events for both editors. - Fixed non-ability to drag+drop into WYSIWYG editor. - Updated check for table data to look for table specific rich-text instead of just any text since some the old check was too general and was preventing some legitimate image paste events. Tested on Chrome and FireFox on Ubuntu. Attempted to test on Safari via browserstack but environment was unreliable and could not access folders to test drag/drop of files. Relates to #1651 and #1697
54 lines
No EOL
1.2 KiB
JavaScript
54 lines
No EOL
1.2 KiB
JavaScript
|
|
class Clipboard {
|
|
|
|
/**
|
|
* Constructor
|
|
* @param {DataTransfer} clipboardData
|
|
*/
|
|
constructor(clipboardData) {
|
|
this.data = clipboardData;
|
|
}
|
|
|
|
/**
|
|
* Check if the clipboard has any items.
|
|
*/
|
|
hasItems() {
|
|
return Boolean(this.data) && Boolean(this.data.types) && this.data.types.length > 0;
|
|
}
|
|
|
|
/**
|
|
* Check if the given event has tabular-looking data in the clipboard.
|
|
* @return {boolean}
|
|
*/
|
|
containsTabularData() {
|
|
const rtfData = this.data.getData( 'text/rtf');
|
|
return rtfData && rtfData.includes('\\trowd');
|
|
}
|
|
|
|
/**
|
|
* Get the images that are in the clipboard data.
|
|
* @return {Array<File>}
|
|
*/
|
|
getImages() {
|
|
const types = this.data.types;
|
|
const files = this.data.files;
|
|
const images = [];
|
|
|
|
for (const type of types) {
|
|
if (type.includes('image')) {
|
|
const item = this.data.getData(type);
|
|
images.push(item.getAsFile());
|
|
}
|
|
}
|
|
|
|
for (const file of files) {
|
|
if (file.type.includes('image')) {
|
|
images.push(file);
|
|
}
|
|
}
|
|
|
|
return images;
|
|
}
|
|
}
|
|
|
|
export default Clipboard; |