mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-05-23 18:32:01 +00:00
Merge pull request #719 from dhenry437/fix/multi-tool-filename
Multi-tool bug with dropping files
This commit is contained in:
commit
46032b8ebb
@ -357,22 +357,29 @@
|
|||||||
{
|
{
|
||||||
"moduleName": "org.apache.pdfbox:fontbox",
|
"moduleName": "org.apache.pdfbox:fontbox",
|
||||||
"moduleUrl": "https://pdfbox.apache.org",
|
"moduleUrl": "https://pdfbox.apache.org",
|
||||||
"moduleVersion": "2.0.30",
|
"moduleVersion": "3.0.1",
|
||||||
"moduleLicense": "Apache License, Version 2.0",
|
"moduleLicense": "Apache-2.0",
|
||||||
"moduleLicenseUrl": "https://www.apache.org/licenses/LICENSE-2.0.txt"
|
"moduleLicenseUrl": "https://www.apache.org/licenses/LICENSE-2.0.txt"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"moduleName": "org.apache.pdfbox:pdfbox",
|
"moduleName": "org.apache.pdfbox:pdfbox",
|
||||||
"moduleUrl": "https://pdfbox.apache.org",
|
"moduleUrl": "https://pdfbox.apache.org",
|
||||||
"moduleVersion": "2.0.30",
|
"moduleVersion": "3.0.1",
|
||||||
"moduleLicense": "Apache License, Version 2.0",
|
"moduleLicense": "Apache-2.0",
|
||||||
|
"moduleLicenseUrl": "https://www.apache.org/licenses/LICENSE-2.0.txt"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"moduleName": "org.apache.pdfbox:pdfbox-io",
|
||||||
|
"moduleUrl": "https://pdfbox.apache.org",
|
||||||
|
"moduleVersion": "3.0.1",
|
||||||
|
"moduleLicense": "Apache-2.0",
|
||||||
"moduleLicenseUrl": "https://www.apache.org/licenses/LICENSE-2.0.txt"
|
"moduleLicenseUrl": "https://www.apache.org/licenses/LICENSE-2.0.txt"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"moduleName": "org.apache.pdfbox:xmpbox",
|
"moduleName": "org.apache.pdfbox:xmpbox",
|
||||||
"moduleUrl": "https://pdfbox.apache.org",
|
"moduleUrl": "https://pdfbox.apache.org",
|
||||||
"moduleVersion": "2.0.30",
|
"moduleVersion": "3.0.1",
|
||||||
"moduleLicense": "Apache License, Version 2.0",
|
"moduleLicense": "Apache-2.0",
|
||||||
"moduleLicenseUrl": "https://www.apache.org/licenses/LICENSE-2.0.txt"
|
"moduleLicenseUrl": "https://www.apache.org/licenses/LICENSE-2.0.txt"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -450,6 +457,12 @@
|
|||||||
"moduleLicense": "BSD 2-Clause License",
|
"moduleLicense": "BSD 2-Clause License",
|
||||||
"moduleLicenseUrl": "https://opensource.org/licenses/BSD-2-Clause"
|
"moduleLicenseUrl": "https://opensource.org/licenses/BSD-2-Clause"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"moduleName": "org.commonmark:commonmark-ext-gfm-tables",
|
||||||
|
"moduleVersion": "0.21.0",
|
||||||
|
"moduleLicense": "BSD 2-Clause License",
|
||||||
|
"moduleLicenseUrl": "https://opensource.org/licenses/BSD-2-Clause"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"moduleName": "org.eclipse.angus:angus-activation",
|
"moduleName": "org.eclipse.angus:angus-activation",
|
||||||
"moduleUrl": "https://www.eclipse.org",
|
"moduleUrl": "https://www.eclipse.org",
|
||||||
@ -506,6 +519,52 @@
|
|||||||
"moduleLicense": "Public Domain",
|
"moduleLicense": "Public Domain",
|
||||||
"moduleLicenseUrl": "http://repository.jboss.org/licenses/cc0-1.0.txt"
|
"moduleLicenseUrl": "http://repository.jboss.org/licenses/cc0-1.0.txt"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"moduleName": "org.junit.jupiter:junit-jupiter",
|
||||||
|
"moduleUrl": "https://junit.org/junit5/",
|
||||||
|
"moduleVersion": "5.10.1",
|
||||||
|
"moduleLicense": "Eclipse Public License v2.0",
|
||||||
|
"moduleLicenseUrl": "https://www.eclipse.org/legal/epl-v20.html"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"moduleName": "org.junit.jupiter:junit-jupiter-api",
|
||||||
|
"moduleUrl": "https://junit.org/junit5/",
|
||||||
|
"moduleVersion": "5.10.1",
|
||||||
|
"moduleLicense": "Eclipse Public License v2.0",
|
||||||
|
"moduleLicenseUrl": "https://www.eclipse.org/legal/epl-v20.html"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"moduleName": "org.junit.jupiter:junit-jupiter-engine",
|
||||||
|
"moduleUrl": "https://junit.org/junit5/",
|
||||||
|
"moduleVersion": "5.10.1",
|
||||||
|
"moduleLicense": "Eclipse Public License v2.0",
|
||||||
|
"moduleLicenseUrl": "https://www.eclipse.org/legal/epl-v20.html"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"moduleName": "org.junit.jupiter:junit-jupiter-params",
|
||||||
|
"moduleUrl": "https://junit.org/junit5/",
|
||||||
|
"moduleVersion": "5.10.1",
|
||||||
|
"moduleLicense": "Eclipse Public License v2.0",
|
||||||
|
"moduleLicenseUrl": "https://www.eclipse.org/legal/epl-v20.html"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"moduleName": "org.junit.platform:junit-platform-commons",
|
||||||
|
"moduleUrl": "https://junit.org/junit5/",
|
||||||
|
"moduleVersion": "1.10.1",
|
||||||
|
"moduleLicense": "Eclipse Public License v2.0",
|
||||||
|
"moduleLicenseUrl": "https://www.eclipse.org/legal/epl-v20.html"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"moduleName": "org.junit.platform:junit-platform-engine",
|
||||||
|
"moduleUrl": "https://junit.org/junit5/",
|
||||||
|
"moduleVersion": "1.10.1",
|
||||||
|
"moduleLicense": "Eclipse Public License v2.0",
|
||||||
|
"moduleLicenseUrl": "https://www.eclipse.org/legal/epl-v20.html"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"moduleName": "org.junit:junit-bom",
|
||||||
|
"moduleVersion": "5.10.1"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"moduleName": "org.latencyutils:LatencyUtils",
|
"moduleName": "org.latencyutils:LatencyUtils",
|
||||||
"moduleUrl": "http://latencyutils.github.io/LatencyUtils/",
|
"moduleUrl": "http://latencyutils.github.io/LatencyUtils/",
|
||||||
@ -513,6 +572,13 @@
|
|||||||
"moduleLicense": "Public Domain, per Creative Commons CC0",
|
"moduleLicense": "Public Domain, per Creative Commons CC0",
|
||||||
"moduleLicenseUrl": "http://creativecommons.org/publicdomain/zero/1.0/"
|
"moduleLicenseUrl": "http://creativecommons.org/publicdomain/zero/1.0/"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"moduleName": "org.opentest4j:opentest4j",
|
||||||
|
"moduleUrl": "https://github.com/ota4j-team/opentest4j",
|
||||||
|
"moduleVersion": "1.3.0",
|
||||||
|
"moduleLicense": "The Apache License, Version 2.0",
|
||||||
|
"moduleLicenseUrl": "https://www.apache.org/licenses/LICENSE-2.0.txt"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"moduleName": "org.slf4j:jul-to-slf4j",
|
"moduleName": "org.slf4j:jul-to-slf4j",
|
||||||
"moduleUrl": "http://www.slf4j.org",
|
"moduleUrl": "http://www.slf4j.org",
|
||||||
|
@ -26,6 +26,7 @@ class PdfContainer {
|
|||||||
movePageTo: this.movePageTo,
|
movePageTo: this.movePageTo,
|
||||||
addPdfs: this.addPdfs,
|
addPdfs: this.addPdfs,
|
||||||
rotateElement: this.rotateElement,
|
rotateElement: this.rotateElement,
|
||||||
|
updateFilename: this.updateFilename
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -38,7 +39,7 @@ class PdfContainer {
|
|||||||
|
|
||||||
filenameInput.onkeyup = this.updateFilename;
|
filenameInput.onkeyup = this.updateFilename;
|
||||||
filenameInput.onkeydown = this.preventIllegalChars;
|
filenameInput.onkeydown = this.preventIllegalChars;
|
||||||
filenameInput.disabled = true;
|
filenameInput.disabled = false;
|
||||||
filenameInput.innerText = "";
|
filenameInput.innerText = "";
|
||||||
downloadBtn.disabled = true;
|
downloadBtn.disabled = true;
|
||||||
}
|
}
|
||||||
@ -73,30 +74,9 @@ class PdfContainer {
|
|||||||
input.setAttribute("accept", "application/pdf");
|
input.setAttribute("accept", "application/pdf");
|
||||||
input.onchange = async(e) => {
|
input.onchange = async(e) => {
|
||||||
const files = e.target.files;
|
const files = e.target.files;
|
||||||
if (files.length > 0) {
|
|
||||||
const filenameInput = document.getElementById('filename-input');
|
|
||||||
const pagesContainer = document.getElementById('pages-container');
|
|
||||||
const downloadBtn = document.getElementById('export-button');
|
|
||||||
|
|
||||||
filenameInput.disabled = false;
|
|
||||||
|
|
||||||
if (pagesContainer.childElementCount === 0) {
|
|
||||||
filenameInput.value = "";
|
|
||||||
this.filename = null;
|
|
||||||
downloadBtn.disabled = true;
|
|
||||||
} else {
|
|
||||||
this.filename = filenameInput.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.filename === null || this.filename === undefined) {
|
|
||||||
filenameInput.value = files[0].name;
|
|
||||||
} else {
|
|
||||||
filenameInput.value = this.filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
this.addPdfsFromFiles(files, nextSiblingElement);
|
this.addPdfsFromFiles(files, nextSiblingElement);
|
||||||
|
this.updateFilename(files ? files[0].name : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
input.click();
|
input.click();
|
||||||
@ -242,12 +222,12 @@ class PdfContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
filenameInput.value = inputArr.join('');
|
filenameInput.value = inputArr.join('');
|
||||||
this.filename = filenameInput.value;
|
this.fileName = filenameInput.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!filenameInput.value.includes('.pdf')) {
|
if (!filenameInput.value.includes('.pdf')) {
|
||||||
filenameInput.value = filenameInput.value + '.pdf';
|
filenameInput.value = filenameInput.value + '.pdf';
|
||||||
this.filename = filenameInput.value;
|
this.fileName = filenameInput.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (downloadOption === 'sameWindow') {
|
if (downloadOption === 'sameWindow') {
|
||||||
@ -263,7 +243,7 @@ class PdfContainer {
|
|||||||
this.downloadLink.href = url;
|
this.downloadLink.href = url;
|
||||||
// downloadLink.download = this.fileName ? this.fileName : 'managed.pdf';
|
// downloadLink.download = this.fileName ? this.fileName : 'managed.pdf';
|
||||||
// downloadLink.download = this.fileName;
|
// downloadLink.download = this.fileName;
|
||||||
this.downloadLink.setAttribute('download', this.filename ? this.fileName : 'managed.pdf');
|
this.downloadLink.setAttribute('download', this.fileName ? this.fileName : 'managed.pdf');
|
||||||
this.downloadLink.setAttribute('target', '_blank');
|
this.downloadLink.setAttribute('target', '_blank');
|
||||||
this.downloadLink.onclick = this.setDownloadAttribute;
|
this.downloadLink.onclick = this.setDownloadAttribute;
|
||||||
this.downloadLink.click();
|
this.downloadLink.click();
|
||||||
@ -271,20 +251,23 @@ class PdfContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setDownloadAttribute() {
|
setDownloadAttribute() {
|
||||||
this.downloadLink.setAttribute("download", this.filename ? this.filename : 'managed.pdf');
|
this.downloadLink.setAttribute("download", this.fileName ? this.fileName : 'managed.pdf');
|
||||||
}
|
}
|
||||||
|
|
||||||
updateFilename() {
|
updateFilename(fileName = "") {
|
||||||
const filenameInput = document.getElementById('filename-input');
|
const filenameInput = document.getElementById('filename-input');
|
||||||
|
const pagesContainer = document.getElementById('pages-container');
|
||||||
const downloadBtn = document.getElementById('export-button');
|
const downloadBtn = document.getElementById('export-button');
|
||||||
|
|
||||||
if (filenameInput.value === "") {
|
downloadBtn.disabled = pagesContainer.childElementCount === 0
|
||||||
downloadBtn.disabled = true;
|
|
||||||
return;
|
if (!this.fileName) {
|
||||||
|
this.fileName = fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadBtn.disabled = false;
|
if (!filenameInput.value) {
|
||||||
this.filename = filenameInput.value;
|
filenameInput.value = this.fileName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
preventIllegalChars(e) {
|
preventIllegalChars(e) {
|
||||||
|
@ -1,54 +1,11 @@
|
|||||||
const addFileDragListener = (callback) => {
|
class FileDragManager {
|
||||||
let overlay;
|
overlay;
|
||||||
let dragCounter = 0;
|
dragCounter;
|
||||||
|
updateFilename;
|
||||||
|
|
||||||
const dragenterListener = function() {
|
constructor(cb = null) {
|
||||||
dragCounter++;
|
this.dragCounter = 0;
|
||||||
if (!overlay) {
|
this.setCallback(cb);
|
||||||
// Create and show the overlay
|
|
||||||
overlay = document.createElement('div');
|
|
||||||
overlay.style.position = 'fixed';
|
|
||||||
overlay.style.top = 0;
|
|
||||||
overlay.style.left = 0;
|
|
||||||
overlay.style.width = '100%';
|
|
||||||
overlay.style.height = '100%';
|
|
||||||
overlay.style.background = 'rgba(0, 0, 0, 0.5)';
|
|
||||||
overlay.style.color = '#fff';
|
|
||||||
overlay.style.zIndex = '1000';
|
|
||||||
overlay.style.display = 'flex';
|
|
||||||
overlay.style.alignItems = 'center';
|
|
||||||
overlay.style.justifyContent = 'center';
|
|
||||||
overlay.style.pointerEvents = 'none';
|
|
||||||
overlay.innerHTML = '<p>Drop files anywhere to upload</p>';
|
|
||||||
document.getElementById('content-wrap').appendChild(overlay);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const dragleaveListener = function() {
|
|
||||||
dragCounter--;
|
|
||||||
if (dragCounter === 0) {
|
|
||||||
// Hide and remove the overlay
|
|
||||||
if (overlay) {
|
|
||||||
overlay.remove();
|
|
||||||
overlay = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const dropListener = function(e) {
|
|
||||||
|
|
||||||
const dt = e.dataTransfer;
|
|
||||||
const files = dt.files;
|
|
||||||
callback(files).catch((err) => {
|
|
||||||
console.error(err);
|
|
||||||
//maybe
|
|
||||||
}).finally(() => {
|
|
||||||
if (overlay) {
|
|
||||||
overlay.remove();
|
|
||||||
overlay = null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Prevent default behavior for drag events
|
// Prevent default behavior for drag events
|
||||||
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
|
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
|
||||||
@ -60,10 +17,78 @@ const addFileDragListener = (callback) => {
|
|||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
}
|
}
|
||||||
|
|
||||||
document.body.addEventListener('dragenter', dragenterListener);
|
this.dragenterListener = this.dragenterListener.bind(this);
|
||||||
document.body.addEventListener('dragleave', dragleaveListener);
|
this.dragleaveListener = this.dragleaveListener.bind(this);
|
||||||
|
this.dropListener = this.dropListener.bind(this);
|
||||||
|
|
||||||
|
document.body.addEventListener('dragenter', this.dragenterListener);
|
||||||
|
document.body.addEventListener('dragleave', this.dragleaveListener);
|
||||||
// Add drop event listener
|
// Add drop event listener
|
||||||
document.body.addEventListener('drop', dropListener);
|
document.body.addEventListener('drop', this.dropListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default addFileDragListener;
|
setActions({ updateFilename }) {
|
||||||
|
this.updateFilename = updateFilename;
|
||||||
|
}
|
||||||
|
|
||||||
|
setCallback(cb) {
|
||||||
|
if (cb) {
|
||||||
|
this.callback = cb;
|
||||||
|
} else {
|
||||||
|
this.callback = (files) => console.warn("FileDragManager not set");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dragenterListener() {
|
||||||
|
this.dragCounter++;
|
||||||
|
if (!this.overlay) {
|
||||||
|
// Create and show the overlay
|
||||||
|
this.overlay = document.createElement('div');
|
||||||
|
this.overlay.style.position = 'fixed';
|
||||||
|
this.overlay.style.top = 0;
|
||||||
|
this.overlay.style.left = 0;
|
||||||
|
this.overlay.style.width = '100%';
|
||||||
|
this.overlay.style.height = '100%';
|
||||||
|
this.overlay.style.background = 'rgba(0, 0, 0, 0.5)';
|
||||||
|
this.overlay.style.color = '#fff';
|
||||||
|
this.overlay.style.zIndex = '1000';
|
||||||
|
this.overlay.style.display = 'flex';
|
||||||
|
this.overlay.style.alignItems = 'center';
|
||||||
|
this.overlay.style.justifyContent = 'center';
|
||||||
|
this.overlay.style.pointerEvents = 'none';
|
||||||
|
this.overlay.innerHTML = '<p>Drop files anywhere to upload</p>';
|
||||||
|
document.getElementById('content-wrap').appendChild(this.overlay);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
dragleaveListener() {
|
||||||
|
this.dragCounter--;
|
||||||
|
if (this.dragCounter === 0) {
|
||||||
|
// Hide and remove the overlay
|
||||||
|
if (this.overlay) {
|
||||||
|
this.overlay.remove();
|
||||||
|
this.overlay = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
dropListener(e) {
|
||||||
|
|
||||||
|
const dt = e.dataTransfer;
|
||||||
|
const files = dt.files;
|
||||||
|
this.callback(files).catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
//maybe
|
||||||
|
}).finally(() => {
|
||||||
|
// Hide and remove the overlay
|
||||||
|
if (this.overlay) {
|
||||||
|
this.overlay.remove();
|
||||||
|
this.overlay = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.updateFilename(files ? files[0].name : "");
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default FileDragManager;
|
||||||
|
@ -79,13 +79,14 @@
|
|||||||
import scrollDivHorizontally from "./js/multitool/horizontalScroll.js";
|
import scrollDivHorizontally from "./js/multitool/horizontalScroll.js";
|
||||||
import ImageHighlighter from "./js/multitool/ImageHighlighter.js";
|
import ImageHighlighter from "./js/multitool/ImageHighlighter.js";
|
||||||
import PdfActionsManager from './js/multitool/PdfActionsManager.js';
|
import PdfActionsManager from './js/multitool/PdfActionsManager.js';
|
||||||
import addFileInputListener from './js/multitool/fileInput.js';
|
import FileDragManager from './js/multitool/fileInput.js';
|
||||||
// enables drag and drop
|
// enables drag and drop
|
||||||
const dragDropManager = new DragDropManager('drag-container', 'pages-container');
|
const dragDropManager = new DragDropManager('drag-container', 'pages-container');
|
||||||
// enables image highlight on click
|
// enables image highlight on click
|
||||||
const imageHighlighter = new ImageHighlighter('image-highlighter');
|
const imageHighlighter = new ImageHighlighter('image-highlighter');
|
||||||
// enables the default action buttons on each pdf
|
// enables the default action buttons on each pdf
|
||||||
const pdfActionsManager = new PdfActionsManager('pages-container');
|
const pdfActionsManager = new PdfActionsManager('pages-container');
|
||||||
|
const fileDragManager = new FileDragManager();
|
||||||
|
|
||||||
// Scroll the wrapper horizontally
|
// Scroll the wrapper horizontally
|
||||||
scrollDivHorizontally('pages-container-wrapper');
|
scrollDivHorizontally('pages-container-wrapper');
|
||||||
@ -98,11 +99,11 @@
|
|||||||
dragDropManager,
|
dragDropManager,
|
||||||
imageHighlighter,
|
imageHighlighter,
|
||||||
pdfActionsManager,
|
pdfActionsManager,
|
||||||
|
fileDragManager
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
addFileInputListener(async (files) => {
|
|
||||||
pdfContainer.addPdfsFromFiles(files);
|
fileDragManager.setCallback(async (files) => pdfContainer.addPdfsFromFiles(files));
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user