mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-05-19 06:31:30 +00:00
Better standardised and fixes areas of image pasting
- 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
This commit is contained in:
parent
5491bd62a2
commit
a83a7f34f4
3 changed files with 89 additions and 28 deletions
resources/js/components
|
@ -1,6 +1,7 @@
|
|||
import MarkdownIt from "markdown-it";
|
||||
import mdTasksLists from 'markdown-it-task-lists';
|
||||
import code from '../services/code';
|
||||
import Clipboard from "../services/clipboard";
|
||||
import {debounce} from "../services/util";
|
||||
|
||||
import DrawIO from "../services/drawio";
|
||||
|
@ -215,20 +216,16 @@ class MarkdownEditor {
|
|||
|
||||
// Handle image paste
|
||||
cm.on('paste', (cm, event) => {
|
||||
const clipboardItems = event.clipboardData.items;
|
||||
if (!event.clipboardData || !clipboardItems) return;
|
||||
const clipboard = new Clipboard(event.clipboardData || event.dataTransfer);
|
||||
|
||||
// Don't handle if clipboard includes text content
|
||||
for (let clipboardItem of clipboardItems) {
|
||||
if (clipboardItem.type.includes('text/')) {
|
||||
return;
|
||||
}
|
||||
// Don't handle the event ourselves if no items exist of contains table-looking data
|
||||
if (!clipboard.hasItems() || clipboard.containsTabularData()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (let clipboardItem of clipboardItems) {
|
||||
if (clipboardItem.type.includes("image")) {
|
||||
uploadImage(clipboardItem.getAsFile());
|
||||
}
|
||||
const images = clipboard.getImages();
|
||||
for (const image of images) {
|
||||
uploadImage(image);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -246,13 +243,15 @@ class MarkdownEditor {
|
|||
});
|
||||
}
|
||||
|
||||
if (event.dataTransfer && event.dataTransfer.files && event.dataTransfer.files.length > 0) {
|
||||
const clipboard = new Clipboard(event.dataTransfer);
|
||||
if (clipboard.hasItems()) {
|
||||
const cursorPos = cm.coordsChar({left: event.pageX, top: event.pageY});
|
||||
cm.setCursor(cursorPos);
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
for (let i = 0; i < event.dataTransfer.files.length; i++) {
|
||||
uploadImage(event.dataTransfer.files[i]);
|
||||
const images = clipboard.getImages();
|
||||
for (const image of images) {
|
||||
uploadImage(image);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue