mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 17:30:09 +02:00
Merge pull request #18214 from calixteman/bug1900907
[Editor] Support dragging & dropping images on a pdf (bug 1900907)
This commit is contained in:
commit
c770e94e36
2 changed files with 56 additions and 8 deletions
|
@ -600,6 +600,10 @@ class AnnotationEditorUIManager {
|
||||||
|
|
||||||
#boundCut = this.cut.bind(this);
|
#boundCut = this.cut.bind(this);
|
||||||
|
|
||||||
|
#boundDragOver = this.dragOver.bind(this);
|
||||||
|
|
||||||
|
#boundDrop = this.drop.bind(this);
|
||||||
|
|
||||||
#boundPaste = this.paste.bind(this);
|
#boundPaste = this.paste.bind(this);
|
||||||
|
|
||||||
#boundKeydown = this.keydown.bind(this);
|
#boundKeydown = this.keydown.bind(this);
|
||||||
|
@ -790,6 +794,7 @@ class AnnotationEditorUIManager {
|
||||||
this._eventBus._on("scalechanging", this.#boundOnScaleChanging);
|
this._eventBus._on("scalechanging", this.#boundOnScaleChanging);
|
||||||
this._eventBus._on("rotationchanging", this.#boundOnRotationChanging);
|
this._eventBus._on("rotationchanging", this.#boundOnRotationChanging);
|
||||||
this.#addSelectionListener();
|
this.#addSelectionListener();
|
||||||
|
this.#addDragAndDropListeners();
|
||||||
this.#addKeyboardManager();
|
this.#addKeyboardManager();
|
||||||
this.#annotationStorage = pdfDocument.annotationStorage;
|
this.#annotationStorage = pdfDocument.annotationStorage;
|
||||||
this.#filterFactory = pdfDocument.filterFactory;
|
this.#filterFactory = pdfDocument.filterFactory;
|
||||||
|
@ -815,6 +820,7 @@ class AnnotationEditorUIManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
|
this.#removeDragAndDropListeners();
|
||||||
this.#removeKeyboardManager();
|
this.#removeKeyboardManager();
|
||||||
this.#removeFocusManager();
|
this.#removeFocusManager();
|
||||||
this._eventBus._off("editingaction", this.#boundOnEditingAction);
|
this._eventBus._off("editingaction", this.#boundOnEditingAction);
|
||||||
|
@ -1183,6 +1189,16 @@ class AnnotationEditorUIManager {
|
||||||
document.removeEventListener("paste", this.#boundPaste);
|
document.removeEventListener("paste", this.#boundPaste);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#addDragAndDropListeners() {
|
||||||
|
document.addEventListener("dragover", this.#boundDragOver);
|
||||||
|
document.addEventListener("drop", this.#boundDrop);
|
||||||
|
}
|
||||||
|
|
||||||
|
#removeDragAndDropListeners() {
|
||||||
|
document.removeEventListener("dragover", this.#boundDragOver);
|
||||||
|
document.removeEventListener("drop", this.#boundDrop);
|
||||||
|
}
|
||||||
|
|
||||||
addEditListeners() {
|
addEditListeners() {
|
||||||
this.#addKeyboardManager();
|
this.#addKeyboardManager();
|
||||||
this.#addCopyPasteListeners();
|
this.#addCopyPasteListeners();
|
||||||
|
@ -1193,6 +1209,34 @@ class AnnotationEditorUIManager {
|
||||||
this.#removeCopyPasteListeners();
|
this.#removeCopyPasteListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dragOver(event) {
|
||||||
|
for (const { type } of event.dataTransfer.items) {
|
||||||
|
for (const editorType of this.#editorTypes) {
|
||||||
|
if (editorType.isHandlingMimeForPasting(type)) {
|
||||||
|
event.dataTransfer.dropEffect = "copy";
|
||||||
|
event.preventDefault();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Drop callback.
|
||||||
|
* @param {DragEvent} event
|
||||||
|
*/
|
||||||
|
drop(event) {
|
||||||
|
for (const item of event.dataTransfer.items) {
|
||||||
|
for (const editorType of this.#editorTypes) {
|
||||||
|
if (editorType.isHandlingMimeForPasting(item.type)) {
|
||||||
|
editorType.paste(item, this.currentLayer);
|
||||||
|
event.preventDefault();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy callback.
|
* Copy callback.
|
||||||
* @param {ClipboardEvent} event
|
* @param {ClipboardEvent} event
|
||||||
|
|
18
web/app.js
18
web/app.js
|
@ -670,18 +670,22 @@ const PDFViewerApplication = {
|
||||||
|
|
||||||
// Enable dragging-and-dropping a new PDF file onto the viewerContainer.
|
// Enable dragging-and-dropping a new PDF file onto the viewerContainer.
|
||||||
appConfig.mainContainer.addEventListener("dragover", function (evt) {
|
appConfig.mainContainer.addEventListener("dragover", function (evt) {
|
||||||
evt.preventDefault();
|
for (const item of evt.dataTransfer.items) {
|
||||||
|
if (item.type === "application/pdf") {
|
||||||
evt.dataTransfer.dropEffect =
|
evt.dataTransfer.dropEffect =
|
||||||
evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move";
|
evt.dataTransfer.effectAllowed === "copy" ? "copy" : "move";
|
||||||
});
|
|
||||||
appConfig.mainContainer.addEventListener("drop", function (evt) {
|
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
evt.stopPropagation();
|
||||||
const { files } = evt.dataTransfer;
|
|
||||||
if (!files || files.length === 0) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
appConfig.mainContainer.addEventListener("drop", function (evt) {
|
||||||
|
if (evt.dataTransfer.files?.[0].type !== "application/pdf") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
evt.preventDefault();
|
||||||
|
evt.stopPropagation();
|
||||||
eventBus.dispatch("fileinputchange", {
|
eventBus.dispatch("fileinputchange", {
|
||||||
source: this,
|
source: this,
|
||||||
fileInput: evt.dataTransfer,
|
fileInput: evt.dataTransfer,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue