From e43e6d18b99e7c41baf2c9d744998e11ebfb11a7 Mon Sep 17 00:00:00 2001 From: Stirling-PDF-Bot Date: Wed, 17 Jan 2024 23:52:12 +0000 Subject: [PATCH 1/4] Update 3rd Party Licenses --- .../resources/static/3rdPartyLicenses.json | 78 +++++++++++++++++-- 1 file changed, 72 insertions(+), 6 deletions(-) diff --git a/src/main/resources/static/3rdPartyLicenses.json b/src/main/resources/static/3rdPartyLicenses.json index 88263b1d..699be591 100644 --- a/src/main/resources/static/3rdPartyLicenses.json +++ b/src/main/resources/static/3rdPartyLicenses.json @@ -357,22 +357,29 @@ { "moduleName": "org.apache.pdfbox:fontbox", "moduleUrl": "https://pdfbox.apache.org", - "moduleVersion": "2.0.30", - "moduleLicense": "Apache License, Version 2.0", + "moduleVersion": "3.0.1", + "moduleLicense": "Apache-2.0", "moduleLicenseUrl": "https://www.apache.org/licenses/LICENSE-2.0.txt" }, { "moduleName": "org.apache.pdfbox:pdfbox", "moduleUrl": "https://pdfbox.apache.org", - "moduleVersion": "2.0.30", - "moduleLicense": "Apache License, Version 2.0", + "moduleVersion": "3.0.1", + "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" }, { "moduleName": "org.apache.pdfbox:xmpbox", "moduleUrl": "https://pdfbox.apache.org", - "moduleVersion": "2.0.30", - "moduleLicense": "Apache License, Version 2.0", + "moduleVersion": "3.0.1", + "moduleLicense": "Apache-2.0", "moduleLicenseUrl": "https://www.apache.org/licenses/LICENSE-2.0.txt" }, { @@ -450,6 +457,12 @@ "moduleLicense": "BSD 2-Clause License", "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", "moduleUrl": "https://www.eclipse.org", @@ -506,6 +519,52 @@ "moduleLicense": "Public Domain", "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", "moduleUrl": "http://latencyutils.github.io/LatencyUtils/", @@ -513,6 +572,13 @@ "moduleLicense": "Public Domain, per Creative Commons CC0", "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", "moduleUrl": "http://www.slf4j.org", From 18d289d3b7d6c1f4ecf57be383f125df3385cace Mon Sep 17 00:00:00 2001 From: Dan Henry Date: Thu, 18 Jan 2024 12:07:02 +1100 Subject: [PATCH 2/4] Move filename input logic to its own function --- .../static/js/multitool/PdfContainer.js | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/main/resources/static/js/multitool/PdfContainer.js b/src/main/resources/static/js/multitool/PdfContainer.js index 4a53c961..4ae7f434 100644 --- a/src/main/resources/static/js/multitool/PdfContainer.js +++ b/src/main/resources/static/js/multitool/PdfContainer.js @@ -74,26 +74,7 @@ class PdfContainer { input.onchange = async(e) => { 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; - } - + updateFilenameInput() } this.addPdfsFromFiles(files, nextSiblingElement); @@ -102,6 +83,28 @@ class PdfContainer { input.click(); } + updateFilenameInput() { + 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; + } + } + async addPdfsFromFiles(files, nextSiblingElement) { this.fileName = files[0].name; for (var i=0; i < files.length; i++) { @@ -275,7 +278,7 @@ class PdfContainer { } updateFilename() { - const filenameInput = document.getElementById('filename-input'); + const filenameInput = document.getElementById('filename-input'); const downloadBtn = document.getElementById('export-button'); if (filenameInput.value === "") { From 1bd17eded6c1c25c4b2caa2fad731b92668aaeb4 Mon Sep 17 00:00:00 2001 From: Dan Henry Date: Thu, 18 Jan 2024 12:08:32 +1100 Subject: [PATCH 3/4] call updateFilenameInput on file drop --- src/main/resources/static/js/multitool/fileInput.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/resources/static/js/multitool/fileInput.js b/src/main/resources/static/js/multitool/fileInput.js index 1a76bd48..fa64d47b 100644 --- a/src/main/resources/static/js/multitool/fileInput.js +++ b/src/main/resources/static/js/multitool/fileInput.js @@ -1,3 +1,5 @@ +import PdfContainer from "./PdfContainer"; + const addFileDragListener = (callback) => { let overlay; let dragCounter = 0; @@ -43,10 +45,14 @@ const addFileDragListener = (callback) => { console.error(err); //maybe }).finally(() => { + // Hide and remove the overlay if (overlay) { overlay.remove(); overlay = null; } + + // Enable/disable filename input + PdfContainer.updateFilenameInput() }); }; From a5165b04cd48d70ee161203a62daf2b933e7f17d Mon Sep 17 00:00:00 2001 From: sbplat <71648843+sbplat@users.noreply.github.com> Date: Thu, 18 Jan 2024 01:08:31 -0500 Subject: [PATCH 4/4] fix(multi-tool): refactor fileInput.js into a class, fix filename variable typos, and update updateFilename logic for dropping files --- .../security/UserAuthenticationFilter.java | 2 +- .../api/SplitPdfBySectionsController.java | 4 +- .../static/js/multitool/PdfContainer.js | 60 +++------ .../static/js/multitool/fileInput.js | 121 ++++++++++-------- src/main/resources/templates/multi-tool.html | 13 +- 5 files changed, 100 insertions(+), 100 deletions(-) diff --git a/src/main/java/stirling/software/SPDF/config/security/UserAuthenticationFilter.java b/src/main/java/stirling/software/SPDF/config/security/UserAuthenticationFilter.java index 61b209de..47423eb6 100644 --- a/src/main/java/stirling/software/SPDF/config/security/UserAuthenticationFilter.java +++ b/src/main/java/stirling/software/SPDF/config/security/UserAuthenticationFilter.java @@ -115,4 +115,4 @@ public class UserAuthenticationFilter extends OncePerRequestFilter { return false; } -} \ No newline at end of file +} diff --git a/src/main/java/stirling/software/SPDF/controller/api/SplitPdfBySectionsController.java b/src/main/java/stirling/software/SPDF/controller/api/SplitPdfBySectionsController.java index de3e5a4b..90418169 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/SplitPdfBySectionsController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/SplitPdfBySectionsController.java @@ -121,8 +121,8 @@ public class SplitPdfBySectionsController { subDoc, subPage, AppendMode.APPEND, true, true)) { // Set clipping area and position float translateX = -subPageWidth * i; - - //float translateY = height - subPageHeight * (verticalDivisions - j); + + // float translateY = height - subPageHeight * (verticalDivisions - j); float translateY = -subPageHeight * (verticalDivisions - 1 - j); contentStream.saveGraphicsState(); diff --git a/src/main/resources/static/js/multitool/PdfContainer.js b/src/main/resources/static/js/multitool/PdfContainer.js index 4ae7f434..7ff2e945 100644 --- a/src/main/resources/static/js/multitool/PdfContainer.js +++ b/src/main/resources/static/js/multitool/PdfContainer.js @@ -26,6 +26,7 @@ class PdfContainer { movePageTo: this.movePageTo, addPdfs: this.addPdfs, rotateElement: this.rotateElement, + updateFilename: this.updateFilename }) }) @@ -38,7 +39,7 @@ class PdfContainer { filenameInput.onkeyup = this.updateFilename; filenameInput.onkeydown = this.preventIllegalChars; - filenameInput.disabled = true; + filenameInput.disabled = false; filenameInput.innerText = ""; downloadBtn.disabled = true; } @@ -59,7 +60,7 @@ class PdfContainer { const vector = (endIndex !== -1 && startIndex > endIndex) ? 0-width : width; - + this.pagesContainerWrapper.scroll({ left: this.pagesContainerWrapper.scrollLeft + vector, }) @@ -73,38 +74,14 @@ class PdfContainer { input.setAttribute("accept", "application/pdf"); input.onchange = async(e) => { const files = e.target.files; - if (files.length > 0) { - updateFilenameInput() - } this.addPdfsFromFiles(files, nextSiblingElement); + this.updateFilename(files ? files[0].name : ""); } input.click(); } - updateFilenameInput() { - 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; - } - } - async addPdfsFromFiles(files, nextSiblingElement) { this.fileName = files[0].name; for (var i=0; i < files.length; i++) { @@ -200,7 +177,7 @@ class PdfContainer { return pdfDoc; } - + rotateAll(deg) { for (var i=0; i { - let overlay; - let dragCounter = 0; + constructor(cb = null) { + this.dragCounter = 0; + this.setCallback(cb); - const dragenterListener = function() { - dragCounter++; - if (!overlay) { + // Prevent default behavior for drag events + ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => { + document.body.addEventListener(eventName, preventDefaults, false); + }); + + function preventDefaults(e) { + e.preventDefault(); + e.stopPropagation(); + } + + this.dragenterListener = this.dragenterListener.bind(this); + 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 + document.body.addEventListener('drop', this.dropListener); + } + + 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 - 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 = '

Drop files anywhere to upload

'; - document.getElementById('content-wrap').appendChild(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 = '

Drop files anywhere to upload

'; + document.getElementById('content-wrap').appendChild(this.overlay); } }; - const dragleaveListener = function() { - dragCounter--; - if (dragCounter === 0) { + dragleaveListener() { + this.dragCounter--; + if (this.dragCounter === 0) { // Hide and remove the overlay - if (overlay) { - overlay.remove(); - overlay = null; + if (this.overlay) { + this.overlay.remove(); + this.overlay = null; } } }; - const dropListener = function(e) { + dropListener(e) { const dt = e.dataTransfer; const files = dt.files; - callback(files).catch((err) => { + this.callback(files).catch((err) => { console.error(err); //maybe }).finally(() => { // Hide and remove the overlay - if (overlay) { - overlay.remove(); - overlay = null; + if (this.overlay) { + this.overlay.remove(); + this.overlay = null; } - // Enable/disable filename input - PdfContainer.updateFilenameInput() + this.updateFilename(files ? files[0].name : ""); }); }; - - // Prevent default behavior for drag events - ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => { - document.body.addEventListener(eventName, preventDefaults, false); - }); - - function preventDefaults(e) { - e.preventDefault(); - e.stopPropagation(); - } - - document.body.addEventListener('dragenter', dragenterListener); - document.body.addEventListener('dragleave', dragleaveListener); - // Add drop event listener - document.body.addEventListener('drop', dropListener); } -export default addFileDragListener; \ No newline at end of file +export default FileDragManager; diff --git a/src/main/resources/templates/multi-tool.html b/src/main/resources/templates/multi-tool.html index d602cbe9..d49b7f83 100644 --- a/src/main/resources/templates/multi-tool.html +++ b/src/main/resources/templates/multi-tool.html @@ -49,7 +49,7 @@ - +