511 lines
18 KiB
JavaScript
Raw Normal View History

2024-12-10 16:39:06 +00:00
import FileIconFactory from './file-icon-factory.js';
import FileUtils from './file-utils.js';
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
import UUID from './uuid.js';
Add zip (#3075) # Description of Changes - Made a recursive function that checks if a file is a zip, then scans its contents. If the content is a zip, or an accepted file type (non-folder, size > 0), add it and repeat the check for zips - Change all convert fragment to accept application/zip - Slightly modified the input file styling to include an ID for appending the "Extracting" text - Added language translation for the "Extracting..." text - (Edit March 3) Removed recursive function, zip file inside target zip file is excluded - For decrypt function after uploading the file, i reused one webworker to handle the decryption , since in the previous code the workers are created but not detroyed for every single file, this caused a huge slow down for uploading large files due to creation of threads and thus this proposal. - Closes #2951 --- ### General - [ ✅] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [✅ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [✅ ] I have performed a self-review of my own code - [✅ ] My changes generate no new warnings ### UI Changes (if applicable) ![image](https://github.com/user-attachments/assets/ee4c6dc8-8740-45c9-8772-05fa7444ca6d) Added extracting text (for all language). ### Testing (if applicable) - [ ✅] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Ludy <Ludy87@users.noreply.github.com> Co-authored-by: reecebrowne <74901996+reecebrowne@users.noreply.github.com> Co-authored-by: Reece Browne <reece@stirling.pdf> Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Co-authored-by: swanemar <107953493+swanemar@users.noreply.github.com> Co-authored-by: stirlingbot[bot] <195170888+stirlingbot[bot]@users.noreply.github.com>
2025-03-10 08:10:35 +08:00
import { DecryptFile } from './DecryptFiles.js';
let isScriptExecuted = false;
if (!isScriptExecuted) {
isScriptExecuted = true;
2024-12-10 16:39:06 +00:00
document.addEventListener('DOMContentLoaded', function () {
document.querySelectorAll('.custom-file-chooser').forEach(setupFileInput);
});
}
let hasDroppedImage = false;
2023-06-02 20:15:10 +01:00
Add zip (#3075) # Description of Changes - Made a recursive function that checks if a file is a zip, then scans its contents. If the content is a zip, or an accepted file type (non-folder, size > 0), add it and repeat the check for zips - Change all convert fragment to accept application/zip - Slightly modified the input file styling to include an ID for appending the "Extracting" text - Added language translation for the "Extracting..." text - (Edit March 3) Removed recursive function, zip file inside target zip file is excluded - For decrypt function after uploading the file, i reused one webworker to handle the decryption , since in the previous code the workers are created but not detroyed for every single file, this caused a huge slow down for uploading large files due to creation of threads and thus this proposal. - Closes #2951 --- ### General - [ ✅] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [✅ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [✅ ] I have performed a self-review of my own code - [✅ ] My changes generate no new warnings ### UI Changes (if applicable) ![image](https://github.com/user-attachments/assets/ee4c6dc8-8740-45c9-8772-05fa7444ca6d) Added extracting text (for all language). ### Testing (if applicable) - [ ✅] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Ludy <Ludy87@users.noreply.github.com> Co-authored-by: reecebrowne <74901996+reecebrowne@users.noreply.github.com> Co-authored-by: Reece Browne <reece@stirling.pdf> Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Co-authored-by: swanemar <107953493+swanemar@users.noreply.github.com> Co-authored-by: stirlingbot[bot] <195170888+stirlingbot[bot]@users.noreply.github.com>
2025-03-10 08:10:35 +08:00
const zipTypes = [
'application/zip',
'multipart/x-zip',
'application/zip-compressed',
'application/x-zip-compressed',
];
const mimeTypes = {
"png": "image/png",
"jpg": "image/jpeg",
"jpeg": "image/jpeg",
"gif": "image/gif",
"bmp": "image/bmp",
"svg": "image/svg+xml",
"pdf": "application/pdf",
};
2023-08-02 22:49:43 +01:00
function setupFileInput(chooser) {
2024-12-10 16:39:06 +00:00
const elementId = chooser.getAttribute('data-bs-element-id');
const filesSelected = chooser.getAttribute('data-bs-files-selected');
const pdfPrompt = chooser.getAttribute('data-bs-pdf-prompt');
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
const inputContainerId = chooser.getAttribute('data-bs-element-container-id');
2385 feature request pdf multi tool to use new file input box (#3201) # Description of Changes Please provide a summary of the changes, including: - Multitool now makes use of the common file input. - deleted multitool file input - moved tool bar to floating at the bottom of the view window Closes #(2385) --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details.
2025-03-20 00:06:47 +00:00
const showUploads = chooser.getAttribute('data-bs-show-uploads') === "true";
Validation for input file (#3196) # Description of Changes Please provide a summary of the changes, including: - Added an invalid event listener for the input element, which will be triggered if the input is empty and the element is required in the form. This is a global change, where all pages using this component will have this functionality. Closes #1841 --- ## Checklist ### General - [x] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [x] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [x] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [x] I have performed a self-review of my own code - [x] My changes generate no new warnings ### Documentation - [x] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [x] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [x] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ![image](https://github.com/user-attachments/assets/c53af9fa-b933-420f-9ee3-7b4600c44ea4) ![image](https://github.com/user-attachments/assets/8da04fa1-58be-42eb-977a-c850f917c011) ![image](https://github.com/user-attachments/assets/48dcce19-68c3-4676-a6d2-28b1b0e86004) ### Testing (if applicable) - [x] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2025-04-02 18:08:14 +05:30
const noFileSelectedPrompt = chooser.getAttribute('data-bs-no-file-selected');
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
let inputContainer = document.getElementById(inputContainerId);
2385 feature request pdf multi tool to use new file input box (#3201) # Description of Changes Please provide a summary of the changes, including: - Multitool now makes use of the common file input. - deleted multitool file input - moved tool bar to floating at the bottom of the view window Closes #(2385) --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details.
2025-03-20 00:06:47 +00:00
const input = document.getElementById(elementId);
if (inputContainer.id === 'pdf-upload-input-container') {
inputContainer.querySelector('#dragAndDrop').innerHTML = window.fileInput.dragAndDropPDF;
} else if (inputContainer.id === 'image-upload-input-container') {
inputContainer.querySelector('#dragAndDrop').innerHTML = window.fileInput.dragAndDropImage;
}
let allFiles = [];
let overlay;
let dragCounter = 0;
2385 feature request pdf multi tool to use new file input box (#3201) # Description of Changes Please provide a summary of the changes, including: - Multitool now makes use of the common file input. - deleted multitool file input - moved tool bar to floating at the bottom of the view window Closes #(2385) --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details.
2025-03-20 00:06:47 +00:00
input.addEventListener('reset', (e) => {
allFiles = [];
input.value = null;
});
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
inputContainer.addEventListener('click', (e) => {
let inputBtn = document.getElementById(elementId);
inputBtn.click();
2024-12-10 16:39:06 +00:00
});
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
Validation for input file (#3196) # Description of Changes Please provide a summary of the changes, including: - Added an invalid event listener for the input element, which will be triggered if the input is empty and the element is required in the form. This is a global change, where all pages using this component will have this functionality. Closes #1841 --- ## Checklist ### General - [x] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [x] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [x] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [x] I have performed a self-review of my own code - [x] My changes generate no new warnings ### Documentation - [x] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [x] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [x] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ![image](https://github.com/user-attachments/assets/c53af9fa-b933-420f-9ee3-7b4600c44ea4) ![image](https://github.com/user-attachments/assets/8da04fa1-58be-42eb-977a-c850f917c011) ![image](https://github.com/user-attachments/assets/48dcce19-68c3-4676-a6d2-28b1b0e86004) ### Testing (if applicable) - [x] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2025-04-02 18:08:14 +05:30
// Handle form validation if the input is left empty
input.addEventListener("invalid", (e) => {
e.preventDefault();
alert(noFileSelectedPrompt);
});
const dragenterListener = function () {
dragCounter++;
if (!overlay) {
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
// Show overlay by removing display: none from pseudo elements (::before and ::after)
inputContainer.style.setProperty('--overlay-display', "''");
overlay = true;
}
};
const dragleaveListener = function () {
dragCounter--;
if (dragCounter === 0) {
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
hideOverlay();
}
};
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
function hideOverlay() {
if (!overlay) return;
inputContainer.style.setProperty('--overlay-display', 'none');
overlay = false;
}
Add zip (#3075) # Description of Changes - Made a recursive function that checks if a file is a zip, then scans its contents. If the content is a zip, or an accepted file type (non-folder, size > 0), add it and repeat the check for zips - Change all convert fragment to accept application/zip - Slightly modified the input file styling to include an ID for appending the "Extracting" text - Added language translation for the "Extracting..." text - (Edit March 3) Removed recursive function, zip file inside target zip file is excluded - For decrypt function after uploading the file, i reused one webworker to handle the decryption , since in the previous code the workers are created but not detroyed for every single file, this caused a huge slow down for uploading large files due to creation of threads and thus this proposal. - Closes #2951 --- ### General - [ ✅] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [✅ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [✅ ] I have performed a self-review of my own code - [✅ ] My changes generate no new warnings ### UI Changes (if applicable) ![image](https://github.com/user-attachments/assets/ee4c6dc8-8740-45c9-8772-05fa7444ca6d) Added extracting text (for all language). ### Testing (if applicable) - [ ✅] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Ludy <Ludy87@users.noreply.github.com> Co-authored-by: reecebrowne <74901996+reecebrowne@users.noreply.github.com> Co-authored-by: Reece Browne <reece@stirling.pdf> Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Co-authored-by: swanemar <107953493+swanemar@users.noreply.github.com> Co-authored-by: stirlingbot[bot] <195170888+stirlingbot[bot]@users.noreply.github.com>
2025-03-10 08:10:35 +08:00
const dropListener = function (e) {
e.preventDefault();
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
// Drag and Drop shall only affect the target file chooser
if (e.target !== inputContainer) {
hideOverlay();
dragCounter = 0;
return;
}
const dt = e.dataTransfer;
const files = dt.files;
const fileInput = document.getElementById(elementId);
2024-12-10 16:39:06 +00:00
if (fileInput?.hasAttribute('multiple')) {
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
pushFileListTo(files, allFiles);
} else if (fileInput) {
allFiles = [files[0]];
}
const dataTransfer = new DataTransfer();
allFiles.forEach((file) => dataTransfer.items.add(file));
fileInput.files = dataTransfer.files;
2023-07-13 22:03:23 +01:00
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
hideOverlay();
2023-07-13 22:03:23 +01:00
dragCounter = 0;
Add zip (#3075) # Description of Changes - Made a recursive function that checks if a file is a zip, then scans its contents. If the content is a zip, or an accepted file type (non-folder, size > 0), add it and repeat the check for zips - Change all convert fragment to accept application/zip - Slightly modified the input file styling to include an ID for appending the "Extracting" text - Added language translation for the "Extracting..." text - (Edit March 3) Removed recursive function, zip file inside target zip file is excluded - For decrypt function after uploading the file, i reused one webworker to handle the decryption , since in the previous code the workers are created but not detroyed for every single file, this caused a huge slow down for uploading large files due to creation of threads and thus this proposal. - Closes #2951 --- ### General - [ ✅] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [✅ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [✅ ] I have performed a self-review of my own code - [✅ ] My changes generate no new warnings ### UI Changes (if applicable) ![image](https://github.com/user-attachments/assets/ee4c6dc8-8740-45c9-8772-05fa7444ca6d) Added extracting text (for all language). ### Testing (if applicable) - [ ✅] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Ludy <Ludy87@users.noreply.github.com> Co-authored-by: reecebrowne <74901996+reecebrowne@users.noreply.github.com> Co-authored-by: Reece Browne <reece@stirling.pdf> Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Co-authored-by: swanemar <107953493+swanemar@users.noreply.github.com> Co-authored-by: stirlingbot[bot] <195170888+stirlingbot[bot]@users.noreply.github.com>
2025-03-10 08:10:35 +08:00
fileInput.dispatchEvent(new CustomEvent('change', { bubbles: true, detail: { source: 'drag-drop' } }));
};
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
function pushFileListTo(fileList, container) {
for (let file of fileList) {
container.push(file);
}
}
2024-12-10 16:39:06 +00:00
['dragenter', 'dragover', 'dragleave', 'drop'].forEach((eventName) => {
document.body.addEventListener(eventName, preventDefaults, false);
});
function preventDefaults(e) {
e.preventDefault();
e.stopPropagation();
}
2024-12-10 16:39:06 +00:00
document.body.addEventListener('dragenter', dragenterListener);
document.body.addEventListener('dragleave', dragleaveListener);
document.body.addEventListener('drop', dropListener);
2024-12-10 16:39:06 +00:00
$('#' + elementId).on('change', async function (e) {
Fix: input file overwrite in merge (#2335) * Fix input files being overwritten by newly uploaded files - Fix a bug that caused existing selected/uploaded files to be overwritten when a new input file is uploaded through input element. - Add source property to change event to differentiate between uploaded files using input element and drag/drop uploads to avoid processing drag/drop files more than once, thus avoiding file duplication (file duplication resulting from copying drop/drop files to input files on each 'change' event). * Dispatch and use file-input-change instead of change event for merging - Dispatch "file-input-change" event after each "change" event in file upload, to notify other functions/components relying on the files provided by the \<input\> element. - Use "file-input-change" instead of "change" event to display the latest version of uploaded files. # FAQ: - Why use "file-input-change" instead of "change" in merge.js? = "change" event is automatically triggered when a file is uploaded through \<input\> element which would replace all the existing selected/uploaded files including the drag/drop files. ## Example: Let's say that the user wants to upload/select the x.pdf, y.pdf and z.pdf all together: - user selects "x.pdf" -> file selected successfully. = selected files: x.pdf - user drags and drops "y.pdf" -> file dropped successfully = selected files: x.pdf, y.pdf - user selects again using \<input\> "z.pdf" -> file selected succesfully overwriting selected files. = selected files: z.pdf
2024-11-26 22:41:08 +02:00
let element = e.target;
const isDragAndDrop = e.detail?.source == 'drag-drop';
2024-12-10 16:39:06 +00:00
if (element instanceof HTMLInputElement && element.hasAttribute('multiple')) {
allFiles = isDragAndDrop ? allFiles : [...allFiles, ...element.files];
} else {
allFiles = Array.from(isDragAndDrop ? allFiles : [element.files[0]]);
}
Add zip (#3075) # Description of Changes - Made a recursive function that checks if a file is a zip, then scans its contents. If the content is a zip, or an accepted file type (non-folder, size > 0), add it and repeat the check for zips - Change all convert fragment to accept application/zip - Slightly modified the input file styling to include an ID for appending the "Extracting" text - Added language translation for the "Extracting..." text - (Edit March 3) Removed recursive function, zip file inside target zip file is excluded - For decrypt function after uploading the file, i reused one webworker to handle the decryption , since in the previous code the workers are created but not detroyed for every single file, this caused a huge slow down for uploading large files due to creation of threads and thus this proposal. - Closes #2951 --- ### General - [ ✅] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [✅ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [✅ ] I have performed a self-review of my own code - [✅ ] My changes generate no new warnings ### UI Changes (if applicable) ![image](https://github.com/user-attachments/assets/ee4c6dc8-8740-45c9-8772-05fa7444ca6d) Added extracting text (for all language). ### Testing (if applicable) - [ ✅] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Ludy <Ludy87@users.noreply.github.com> Co-authored-by: reecebrowne <74901996+reecebrowne@users.noreply.github.com> Co-authored-by: Reece Browne <reece@stirling.pdf> Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Co-authored-by: swanemar <107953493+swanemar@users.noreply.github.com> Co-authored-by: stirlingbot[bot] <195170888+stirlingbot[bot]@users.noreply.github.com>
2025-03-10 08:10:35 +08:00
Add default languages to OCR, fix compression for QPDF and embedded images (#3202) # Description of Changes This pull request includes several changes to the codebase, focusing on enhancing OCR support, improving endpoint management, and adding new functionality for PDF compression. The most important changes are detailed below. ### Enhancements to OCR support: * `Dockerfile` and `Dockerfile.fat`: Added support for multiple new OCR languages including Chinese (Simplified), German, French, and Portuguese. (Our top 5 languages including English) [[1]](diffhunk://#diff-dd2c0eb6ea5cfc6c4bd4eac30934e2d5746747af48fef6da689e85b752f39557R69-R72) [[2]](diffhunk://#diff-571631582b988e88c52c86960cc083b0b8fa63cf88f056f26e9e684195221c27L78-R81) ### Improvements to endpoint management: * [`src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java`](diffhunk://#diff-750f31f6ecbd64b025567108a33775cad339e835a04360affff82a09410b697dR51-R66): Added a new method `isGroupEnabled` to check if a group of endpoints is enabled. * [`src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java`](diffhunk://#diff-750f31f6ecbd64b025567108a33775cad339e835a04360affff82a09410b697dL179-L193): Updated endpoint groups and removed redundant qpdf endpoints. [[1]](diffhunk://#diff-750f31f6ecbd64b025567108a33775cad339e835a04360affff82a09410b697dL179-L193) [[2]](diffhunk://#diff-750f31f6ecbd64b025567108a33775cad339e835a04360affff82a09410b697dL243-L244) * [`src/main/java/stirling/software/SPDF/config/EndpointInspector.java`](diffhunk://#diff-845de13e140bb1264014539714860f044405274ad2a9481f38befdd1c1333818R1-R291): Introduced a new `EndpointInspector` class to discover and validate GET endpoints dynamically. ### New functionality for PDF compression: * [`src/main/java/stirling/software/SPDF/controller/api/misc/CompressController.java`](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805R10): Enhanced the `CompressController` to handle nested images within form XObjects, improving the accuracy of image compression in PDFs. Remove Compresses Dependency on QPDF [[1]](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805R10) [[2]](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805R28-R44) [[3]](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805L49-R61) [[4]](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805R77-R99) [[5]](diff hunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805L92-R191) Closes #(issue_number) --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: a <a>
2025-03-20 09:39:57 +00:00
const originalText = inputContainer.querySelector('#fileInputText').innerHTML;
inputContainer.querySelector('#fileInputText').innerHTML = window.fileInput.loading;
Add zip (#3075) # Description of Changes - Made a recursive function that checks if a file is a zip, then scans its contents. If the content is a zip, or an accepted file type (non-folder, size > 0), add it and repeat the check for zips - Change all convert fragment to accept application/zip - Slightly modified the input file styling to include an ID for appending the "Extracting" text - Added language translation for the "Extracting..." text - (Edit March 3) Removed recursive function, zip file inside target zip file is excluded - For decrypt function after uploading the file, i reused one webworker to handle the decryption , since in the previous code the workers are created but not detroyed for every single file, this caused a huge slow down for uploading large files due to creation of threads and thus this proposal. - Closes #2951 --- ### General - [ ✅] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [✅ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [✅ ] I have performed a self-review of my own code - [✅ ] My changes generate no new warnings ### UI Changes (if applicable) ![image](https://github.com/user-attachments/assets/ee4c6dc8-8740-45c9-8772-05fa7444ca6d) Added extracting text (for all language). ### Testing (if applicable) - [ ✅] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Ludy <Ludy87@users.noreply.github.com> Co-authored-by: reecebrowne <74901996+reecebrowne@users.noreply.github.com> Co-authored-by: Reece Browne <reece@stirling.pdf> Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Co-authored-by: swanemar <107953493+swanemar@users.noreply.github.com> Co-authored-by: stirlingbot[bot] <195170888+stirlingbot[bot]@users.noreply.github.com>
2025-03-10 08:10:35 +08:00
async function checkZipFile() {
Add default languages to OCR, fix compression for QPDF and embedded images (#3202) # Description of Changes This pull request includes several changes to the codebase, focusing on enhancing OCR support, improving endpoint management, and adding new functionality for PDF compression. The most important changes are detailed below. ### Enhancements to OCR support: * `Dockerfile` and `Dockerfile.fat`: Added support for multiple new OCR languages including Chinese (Simplified), German, French, and Portuguese. (Our top 5 languages including English) [[1]](diffhunk://#diff-dd2c0eb6ea5cfc6c4bd4eac30934e2d5746747af48fef6da689e85b752f39557R69-R72) [[2]](diffhunk://#diff-571631582b988e88c52c86960cc083b0b8fa63cf88f056f26e9e684195221c27L78-R81) ### Improvements to endpoint management: * [`src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java`](diffhunk://#diff-750f31f6ecbd64b025567108a33775cad339e835a04360affff82a09410b697dR51-R66): Added a new method `isGroupEnabled` to check if a group of endpoints is enabled. * [`src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java`](diffhunk://#diff-750f31f6ecbd64b025567108a33775cad339e835a04360affff82a09410b697dL179-L193): Updated endpoint groups and removed redundant qpdf endpoints. [[1]](diffhunk://#diff-750f31f6ecbd64b025567108a33775cad339e835a04360affff82a09410b697dL179-L193) [[2]](diffhunk://#diff-750f31f6ecbd64b025567108a33775cad339e835a04360affff82a09410b697dL243-L244) * [`src/main/java/stirling/software/SPDF/config/EndpointInspector.java`](diffhunk://#diff-845de13e140bb1264014539714860f044405274ad2a9481f38befdd1c1333818R1-R291): Introduced a new `EndpointInspector` class to discover and validate GET endpoints dynamically. ### New functionality for PDF compression: * [`src/main/java/stirling/software/SPDF/controller/api/misc/CompressController.java`](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805R10): Enhanced the `CompressController` to handle nested images within form XObjects, improving the accuracy of image compression in PDFs. Remove Compresses Dependency on QPDF [[1]](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805R10) [[2]](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805R28-R44) [[3]](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805L49-R61) [[4]](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805R77-R99) [[5]](diff hunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805L92-R191) Closes #(issue_number) --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: a <a>
2025-03-20 09:39:57 +00:00
const hasZipFiles = allFiles.some(file => zipTypes.includes(file.type));
Add default languages to OCR, fix compression for QPDF and embedded images (#3202) # Description of Changes This pull request includes several changes to the codebase, focusing on enhancing OCR support, improving endpoint management, and adding new functionality for PDF compression. The most important changes are detailed below. ### Enhancements to OCR support: * `Dockerfile` and `Dockerfile.fat`: Added support for multiple new OCR languages including Chinese (Simplified), German, French, and Portuguese. (Our top 5 languages including English) [[1]](diffhunk://#diff-dd2c0eb6ea5cfc6c4bd4eac30934e2d5746747af48fef6da689e85b752f39557R69-R72) [[2]](diffhunk://#diff-571631582b988e88c52c86960cc083b0b8fa63cf88f056f26e9e684195221c27L78-R81) ### Improvements to endpoint management: * [`src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java`](diffhunk://#diff-750f31f6ecbd64b025567108a33775cad339e835a04360affff82a09410b697dR51-R66): Added a new method `isGroupEnabled` to check if a group of endpoints is enabled. * [`src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java`](diffhunk://#diff-750f31f6ecbd64b025567108a33775cad339e835a04360affff82a09410b697dL179-L193): Updated endpoint groups and removed redundant qpdf endpoints. [[1]](diffhunk://#diff-750f31f6ecbd64b025567108a33775cad339e835a04360affff82a09410b697dL179-L193) [[2]](diffhunk://#diff-750f31f6ecbd64b025567108a33775cad339e835a04360affff82a09410b697dL243-L244) * [`src/main/java/stirling/software/SPDF/config/EndpointInspector.java`](diffhunk://#diff-845de13e140bb1264014539714860f044405274ad2a9481f38befdd1c1333818R1-R291): Introduced a new `EndpointInspector` class to discover and validate GET endpoints dynamically. ### New functionality for PDF compression: * [`src/main/java/stirling/software/SPDF/controller/api/misc/CompressController.java`](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805R10): Enhanced the `CompressController` to handle nested images within form XObjects, improving the accuracy of image compression in PDFs. Remove Compresses Dependency on QPDF [[1]](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805R10) [[2]](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805R28-R44) [[3]](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805L49-R61) [[4]](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805R77-R99) [[5]](diff hunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805L92-R191) Closes #(issue_number) --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: a <a>
2025-03-20 09:39:57 +00:00
// Only change to extractPDF message if we actually have zip files
if (hasZipFiles) {
inputContainer.querySelector('#fileInputText').innerHTML = window.fileInput.extractPDF;
}
Add zip (#3075) # Description of Changes - Made a recursive function that checks if a file is a zip, then scans its contents. If the content is a zip, or an accepted file type (non-folder, size > 0), add it and repeat the check for zips - Change all convert fragment to accept application/zip - Slightly modified the input file styling to include an ID for appending the "Extracting" text - Added language translation for the "Extracting..." text - (Edit March 3) Removed recursive function, zip file inside target zip file is excluded - For decrypt function after uploading the file, i reused one webworker to handle the decryption , since in the previous code the workers are created but not detroyed for every single file, this caused a huge slow down for uploading large files due to creation of threads and thus this proposal. - Closes #2951 --- ### General - [ ✅] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [✅ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [✅ ] I have performed a self-review of my own code - [✅ ] My changes generate no new warnings ### UI Changes (if applicable) ![image](https://github.com/user-attachments/assets/ee4c6dc8-8740-45c9-8772-05fa7444ca6d) Added extracting text (for all language). ### Testing (if applicable) - [ ✅] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Ludy <Ludy87@users.noreply.github.com> Co-authored-by: reecebrowne <74901996+reecebrowne@users.noreply.github.com> Co-authored-by: Reece Browne <reece@stirling.pdf> Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Co-authored-by: swanemar <107953493+swanemar@users.noreply.github.com> Co-authored-by: stirlingbot[bot] <195170888+stirlingbot[bot]@users.noreply.github.com>
2025-03-10 08:10:35 +08:00
const promises = allFiles.map(async (file, index) => {
try {
if (zipTypes.includes(file.type)) {
await extractZipFiles(file, element.accept);
allFiles.splice(index, 1);
}
} catch (error) {
console.error(`Error extracting ZIP file (${file.name}):`, error);
allFiles.splice(index, 1);
}
});
await Promise.all(promises);
}
Add zip (#3075) # Description of Changes - Made a recursive function that checks if a file is a zip, then scans its contents. If the content is a zip, or an accepted file type (non-folder, size > 0), add it and repeat the check for zips - Change all convert fragment to accept application/zip - Slightly modified the input file styling to include an ID for appending the "Extracting" text - Added language translation for the "Extracting..." text - (Edit March 3) Removed recursive function, zip file inside target zip file is excluded - For decrypt function after uploading the file, i reused one webworker to handle the decryption , since in the previous code the workers are created but not detroyed for every single file, this caused a huge slow down for uploading large files due to creation of threads and thus this proposal. - Closes #2951 --- ### General - [ ✅] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [✅ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [✅ ] I have performed a self-review of my own code - [✅ ] My changes generate no new warnings ### UI Changes (if applicable) ![image](https://github.com/user-attachments/assets/ee4c6dc8-8740-45c9-8772-05fa7444ca6d) Added extracting text (for all language). ### Testing (if applicable) - [ ✅] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Ludy <Ludy87@users.noreply.github.com> Co-authored-by: reecebrowne <74901996+reecebrowne@users.noreply.github.com> Co-authored-by: Reece Browne <reece@stirling.pdf> Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Co-authored-by: swanemar <107953493+swanemar@users.noreply.github.com> Co-authored-by: stirlingbot[bot] <195170888+stirlingbot[bot]@users.noreply.github.com>
2025-03-10 08:10:35 +08:00
const decryptFile = new DecryptFile();
await checkZipFile();
2024-12-10 16:39:06 +00:00
allFiles = await Promise.all(
allFiles.map(async (file) => {
let decryptedFile = file;
Add zip (#3075) # Description of Changes - Made a recursive function that checks if a file is a zip, then scans its contents. If the content is a zip, or an accepted file type (non-folder, size > 0), add it and repeat the check for zips - Change all convert fragment to accept application/zip - Slightly modified the input file styling to include an ID for appending the "Extracting" text - Added language translation for the "Extracting..." text - (Edit March 3) Removed recursive function, zip file inside target zip file is excluded - For decrypt function after uploading the file, i reused one webworker to handle the decryption , since in the previous code the workers are created but not detroyed for every single file, this caused a huge slow down for uploading large files due to creation of threads and thus this proposal. - Closes #2951 --- ### General - [ ✅] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [✅ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [✅ ] I have performed a self-review of my own code - [✅ ] My changes generate no new warnings ### UI Changes (if applicable) ![image](https://github.com/user-attachments/assets/ee4c6dc8-8740-45c9-8772-05fa7444ca6d) Added extracting text (for all language). ### Testing (if applicable) - [ ✅] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Ludy <Ludy87@users.noreply.github.com> Co-authored-by: reecebrowne <74901996+reecebrowne@users.noreply.github.com> Co-authored-by: Reece Browne <reece@stirling.pdf> Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Co-authored-by: swanemar <107953493+swanemar@users.noreply.github.com> Co-authored-by: stirlingbot[bot] <195170888+stirlingbot[bot]@users.noreply.github.com>
2025-03-10 08:10:35 +08:00
2024-12-10 16:39:06 +00:00
try {
Add zip (#3075) # Description of Changes - Made a recursive function that checks if a file is a zip, then scans its contents. If the content is a zip, or an accepted file type (non-folder, size > 0), add it and repeat the check for zips - Change all convert fragment to accept application/zip - Slightly modified the input file styling to include an ID for appending the "Extracting" text - Added language translation for the "Extracting..." text - (Edit March 3) Removed recursive function, zip file inside target zip file is excluded - For decrypt function after uploading the file, i reused one webworker to handle the decryption , since in the previous code the workers are created but not detroyed for every single file, this caused a huge slow down for uploading large files due to creation of threads and thus this proposal. - Closes #2951 --- ### General - [ ✅] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [✅ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [✅ ] I have performed a self-review of my own code - [✅ ] My changes generate no new warnings ### UI Changes (if applicable) ![image](https://github.com/user-attachments/assets/ee4c6dc8-8740-45c9-8772-05fa7444ca6d) Added extracting text (for all language). ### Testing (if applicable) - [ ✅] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Ludy <Ludy87@users.noreply.github.com> Co-authored-by: reecebrowne <74901996+reecebrowne@users.noreply.github.com> Co-authored-by: Reece Browne <reece@stirling.pdf> Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Co-authored-by: swanemar <107953493+swanemar@users.noreply.github.com> Co-authored-by: stirlingbot[bot] <195170888+stirlingbot[bot]@users.noreply.github.com>
2025-03-10 08:10:35 +08:00
const { isEncrypted, requiresPassword } = await decryptFile.checkFileEncrypted(file);
2024-12-10 16:39:06 +00:00
if (file.type === 'application/pdf' && isEncrypted) {
decryptedFile = await decryptFile.decryptFile(file, requiresPassword);
if (!decryptedFile) throw new Error('File decryption failed.');
}
decryptedFile.uniqueId = UUID.uuidv4();
return decryptedFile;
2024-12-10 16:39:06 +00:00
} catch (error) {
console.error(`Error decrypting file: ${file.name}`, error);
if (!file.uniqueId) file.uniqueId = UUID.uuidv4();
2024-12-10 16:39:06 +00:00
return file;
}
})
);
Add zip (#3075) # Description of Changes - Made a recursive function that checks if a file is a zip, then scans its contents. If the content is a zip, or an accepted file type (non-folder, size > 0), add it and repeat the check for zips - Change all convert fragment to accept application/zip - Slightly modified the input file styling to include an ID for appending the "Extracting" text - Added language translation for the "Extracting..." text - (Edit March 3) Removed recursive function, zip file inside target zip file is excluded - For decrypt function after uploading the file, i reused one webworker to handle the decryption , since in the previous code the workers are created but not detroyed for every single file, this caused a huge slow down for uploading large files due to creation of threads and thus this proposal. - Closes #2951 --- ### General - [ ✅] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [✅ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [✅ ] I have performed a self-review of my own code - [✅ ] My changes generate no new warnings ### UI Changes (if applicable) ![image](https://github.com/user-attachments/assets/ee4c6dc8-8740-45c9-8772-05fa7444ca6d) Added extracting text (for all language). ### Testing (if applicable) - [ ✅] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Ludy <Ludy87@users.noreply.github.com> Co-authored-by: reecebrowne <74901996+reecebrowne@users.noreply.github.com> Co-authored-by: Reece Browne <reece@stirling.pdf> Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Co-authored-by: swanemar <107953493+swanemar@users.noreply.github.com> Co-authored-by: stirlingbot[bot] <195170888+stirlingbot[bot]@users.noreply.github.com>
2025-03-10 08:10:35 +08:00
inputContainer.querySelector('#fileInputText').innerHTML = originalText;
Fix: input file overwrite in merge (#2335) * Fix input files being overwritten by newly uploaded files - Fix a bug that caused existing selected/uploaded files to be overwritten when a new input file is uploaded through input element. - Add source property to change event to differentiate between uploaded files using input element and drag/drop uploads to avoid processing drag/drop files more than once, thus avoiding file duplication (file duplication resulting from copying drop/drop files to input files on each 'change' event). * Dispatch and use file-input-change instead of change event for merging - Dispatch "file-input-change" event after each "change" event in file upload, to notify other functions/components relying on the files provided by the \<input\> element. - Use "file-input-change" instead of "change" event to display the latest version of uploaded files. # FAQ: - Why use "file-input-change" instead of "change" in merge.js? = "change" event is automatically triggered when a file is uploaded through \<input\> element which would replace all the existing selected/uploaded files including the drag/drop files. ## Example: Let's say that the user wants to upload/select the x.pdf, y.pdf and z.pdf all together: - user selects "x.pdf" -> file selected successfully. = selected files: x.pdf - user drags and drops "y.pdf" -> file dropped successfully = selected files: x.pdf, y.pdf - user selects again using \<input\> "z.pdf" -> file selected succesfully overwriting selected files. = selected files: z.pdf
2024-11-26 22:41:08 +02:00
if (!isDragAndDrop) {
2024-12-10 16:39:06 +00:00
let dataTransfer = toDataTransfer(allFiles);
element.files = dataTransfer.files;
Fix: input file overwrite in merge (#2335) * Fix input files being overwritten by newly uploaded files - Fix a bug that caused existing selected/uploaded files to be overwritten when a new input file is uploaded through input element. - Add source property to change event to differentiate between uploaded files using input element and drag/drop uploads to avoid processing drag/drop files more than once, thus avoiding file duplication (file duplication resulting from copying drop/drop files to input files on each 'change' event). * Dispatch and use file-input-change instead of change event for merging - Dispatch "file-input-change" event after each "change" event in file upload, to notify other functions/components relying on the files provided by the \<input\> element. - Use "file-input-change" instead of "change" event to display the latest version of uploaded files. # FAQ: - Why use "file-input-change" instead of "change" in merge.js? = "change" event is automatically triggered when a file is uploaded through \<input\> element which would replace all the existing selected/uploaded files including the drag/drop files. ## Example: Let's say that the user wants to upload/select the x.pdf, y.pdf and z.pdf all together: - user selects "x.pdf" -> file selected successfully. = selected files: x.pdf - user drags and drops "y.pdf" -> file dropped successfully = selected files: x.pdf, y.pdf - user selects again using \<input\> "z.pdf" -> file selected succesfully overwriting selected files. = selected files: z.pdf
2024-11-26 22:41:08 +02:00
}
handleFileInputChange(this);
Add zip (#3075) # Description of Changes - Made a recursive function that checks if a file is a zip, then scans its contents. If the content is a zip, or an accepted file type (non-folder, size > 0), add it and repeat the check for zips - Change all convert fragment to accept application/zip - Slightly modified the input file styling to include an ID for appending the "Extracting" text - Added language translation for the "Extracting..." text - (Edit March 3) Removed recursive function, zip file inside target zip file is excluded - For decrypt function after uploading the file, i reused one webworker to handle the decryption , since in the previous code the workers are created but not detroyed for every single file, this caused a huge slow down for uploading large files due to creation of threads and thus this proposal. - Closes #2951 --- ### General - [ ✅] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [✅ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [✅ ] I have performed a self-review of my own code - [✅ ] My changes generate no new warnings ### UI Changes (if applicable) ![image](https://github.com/user-attachments/assets/ee4c6dc8-8740-45c9-8772-05fa7444ca6d) Added extracting text (for all language). ### Testing (if applicable) - [ ✅] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Ludy <Ludy87@users.noreply.github.com> Co-authored-by: reecebrowne <74901996+reecebrowne@users.noreply.github.com> Co-authored-by: Reece Browne <reece@stirling.pdf> Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Co-authored-by: swanemar <107953493+swanemar@users.noreply.github.com> Co-authored-by: stirlingbot[bot] <195170888+stirlingbot[bot]@users.noreply.github.com>
2025-03-10 08:10:35 +08:00
this.dispatchEvent(new CustomEvent('file-input-change', { bubbles: true, detail: { elementId, allFiles } }));
2024-12-10 16:39:06 +00:00
});
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
function toDataTransfer(files) {
let dataTransfer = new DataTransfer();
2024-12-10 16:39:06 +00:00
files.forEach((file) => dataTransfer.items.add(file));
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
return dataTransfer;
}
Add zip (#3075) # Description of Changes - Made a recursive function that checks if a file is a zip, then scans its contents. If the content is a zip, or an accepted file type (non-folder, size > 0), add it and repeat the check for zips - Change all convert fragment to accept application/zip - Slightly modified the input file styling to include an ID for appending the "Extracting" text - Added language translation for the "Extracting..." text - (Edit March 3) Removed recursive function, zip file inside target zip file is excluded - For decrypt function after uploading the file, i reused one webworker to handle the decryption , since in the previous code the workers are created but not detroyed for every single file, this caused a huge slow down for uploading large files due to creation of threads and thus this proposal. - Closes #2951 --- ### General - [ ✅] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [✅ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [✅ ] I have performed a self-review of my own code - [✅ ] My changes generate no new warnings ### UI Changes (if applicable) ![image](https://github.com/user-attachments/assets/ee4c6dc8-8740-45c9-8772-05fa7444ca6d) Added extracting text (for all language). ### Testing (if applicable) - [ ✅] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Ludy <Ludy87@users.noreply.github.com> Co-authored-by: reecebrowne <74901996+reecebrowne@users.noreply.github.com> Co-authored-by: Reece Browne <reece@stirling.pdf> Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Co-authored-by: swanemar <107953493+swanemar@users.noreply.github.com> Co-authored-by: stirlingbot[bot] <195170888+stirlingbot[bot]@users.noreply.github.com>
2025-03-10 08:10:35 +08:00
async function extractZipFiles(zipFile, acceptedFileType) {
const jszip = new JSZip();
var counter = 0;
// do an overall count, then proceed to make the pdf files
await jszip.loadAsync(zipFile)
Add zip (#3075) # Description of Changes - Made a recursive function that checks if a file is a zip, then scans its contents. If the content is a zip, or an accepted file type (non-folder, size > 0), add it and repeat the check for zips - Change all convert fragment to accept application/zip - Slightly modified the input file styling to include an ID for appending the "Extracting" text - Added language translation for the "Extracting..." text - (Edit March 3) Removed recursive function, zip file inside target zip file is excluded - For decrypt function after uploading the file, i reused one webworker to handle the decryption , since in the previous code the workers are created but not detroyed for every single file, this caused a huge slow down for uploading large files due to creation of threads and thus this proposal. - Closes #2951 --- ### General - [ ✅] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [✅ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [✅ ] I have performed a self-review of my own code - [✅ ] My changes generate no new warnings ### UI Changes (if applicable) ![image](https://github.com/user-attachments/assets/ee4c6dc8-8740-45c9-8772-05fa7444ca6d) Added extracting text (for all language). ### Testing (if applicable) - [ ✅] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Ludy <Ludy87@users.noreply.github.com> Co-authored-by: reecebrowne <74901996+reecebrowne@users.noreply.github.com> Co-authored-by: Reece Browne <reece@stirling.pdf> Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Co-authored-by: swanemar <107953493+swanemar@users.noreply.github.com> Co-authored-by: stirlingbot[bot] <195170888+stirlingbot[bot]@users.noreply.github.com>
2025-03-10 08:10:35 +08:00
.then(function (zip) {
Add zip (#3075) # Description of Changes - Made a recursive function that checks if a file is a zip, then scans its contents. If the content is a zip, or an accepted file type (non-folder, size > 0), add it and repeat the check for zips - Change all convert fragment to accept application/zip - Slightly modified the input file styling to include an ID for appending the "Extracting" text - Added language translation for the "Extracting..." text - (Edit March 3) Removed recursive function, zip file inside target zip file is excluded - For decrypt function after uploading the file, i reused one webworker to handle the decryption , since in the previous code the workers are created but not detroyed for every single file, this caused a huge slow down for uploading large files due to creation of threads and thus this proposal. - Closes #2951 --- ### General - [ ✅] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [✅ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [✅ ] I have performed a self-review of my own code - [✅ ] My changes generate no new warnings ### UI Changes (if applicable) ![image](https://github.com/user-attachments/assets/ee4c6dc8-8740-45c9-8772-05fa7444ca6d) Added extracting text (for all language). ### Testing (if applicable) - [ ✅] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Ludy <Ludy87@users.noreply.github.com> Co-authored-by: reecebrowne <74901996+reecebrowne@users.noreply.github.com> Co-authored-by: Reece Browne <reece@stirling.pdf> Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Co-authored-by: swanemar <107953493+swanemar@users.noreply.github.com> Co-authored-by: stirlingbot[bot] <195170888+stirlingbot[bot]@users.noreply.github.com>
2025-03-10 08:10:35 +08:00
zip.forEach(function (relativePath, zipEntry) {
counter+=1;
})
}
)
if (counter >= 1000) {
throw Error("Maximum file reached");
}
return jszip.loadAsync(zipFile)
.then(function (zip) {
var extractionPromises = [];
Add default languages to OCR, fix compression for QPDF and embedded images (#3202) # Description of Changes This pull request includes several changes to the codebase, focusing on enhancing OCR support, improving endpoint management, and adding new functionality for PDF compression. The most important changes are detailed below. ### Enhancements to OCR support: * `Dockerfile` and `Dockerfile.fat`: Added support for multiple new OCR languages including Chinese (Simplified), German, French, and Portuguese. (Our top 5 languages including English) [[1]](diffhunk://#diff-dd2c0eb6ea5cfc6c4bd4eac30934e2d5746747af48fef6da689e85b752f39557R69-R72) [[2]](diffhunk://#diff-571631582b988e88c52c86960cc083b0b8fa63cf88f056f26e9e684195221c27L78-R81) ### Improvements to endpoint management: * [`src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java`](diffhunk://#diff-750f31f6ecbd64b025567108a33775cad339e835a04360affff82a09410b697dR51-R66): Added a new method `isGroupEnabled` to check if a group of endpoints is enabled. * [`src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java`](diffhunk://#diff-750f31f6ecbd64b025567108a33775cad339e835a04360affff82a09410b697dL179-L193): Updated endpoint groups and removed redundant qpdf endpoints. [[1]](diffhunk://#diff-750f31f6ecbd64b025567108a33775cad339e835a04360affff82a09410b697dL179-L193) [[2]](diffhunk://#diff-750f31f6ecbd64b025567108a33775cad339e835a04360affff82a09410b697dL243-L244) * [`src/main/java/stirling/software/SPDF/config/EndpointInspector.java`](diffhunk://#diff-845de13e140bb1264014539714860f044405274ad2a9481f38befdd1c1333818R1-R291): Introduced a new `EndpointInspector` class to discover and validate GET endpoints dynamically. ### New functionality for PDF compression: * [`src/main/java/stirling/software/SPDF/controller/api/misc/CompressController.java`](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805R10): Enhanced the `CompressController` to handle nested images within form XObjects, improving the accuracy of image compression in PDFs. Remove Compresses Dependency on QPDF [[1]](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805R10) [[2]](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805R28-R44) [[3]](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805L49-R61) [[4]](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805R77-R99) [[5]](diff hunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805L92-R191) Closes #(issue_number) --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: a <a>
2025-03-20 09:39:57 +00:00
zip.forEach(function (relativePath, zipEntry) {
const promise = zipEntry.async('blob').then(function (content) {
// Assuming that folders have size zero
if (content.size > 0) {
const extension = zipEntry.name.split('.').pop().toLowerCase();
const mimeType = mimeTypes[extension] || 'application/octet-stream';
Add default languages to OCR, fix compression for QPDF and embedded images (#3202) # Description of Changes This pull request includes several changes to the codebase, focusing on enhancing OCR support, improving endpoint management, and adding new functionality for PDF compression. The most important changes are detailed below. ### Enhancements to OCR support: * `Dockerfile` and `Dockerfile.fat`: Added support for multiple new OCR languages including Chinese (Simplified), German, French, and Portuguese. (Our top 5 languages including English) [[1]](diffhunk://#diff-dd2c0eb6ea5cfc6c4bd4eac30934e2d5746747af48fef6da689e85b752f39557R69-R72) [[2]](diffhunk://#diff-571631582b988e88c52c86960cc083b0b8fa63cf88f056f26e9e684195221c27L78-R81) ### Improvements to endpoint management: * [`src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java`](diffhunk://#diff-750f31f6ecbd64b025567108a33775cad339e835a04360affff82a09410b697dR51-R66): Added a new method `isGroupEnabled` to check if a group of endpoints is enabled. * [`src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java`](diffhunk://#diff-750f31f6ecbd64b025567108a33775cad339e835a04360affff82a09410b697dL179-L193): Updated endpoint groups and removed redundant qpdf endpoints. [[1]](diffhunk://#diff-750f31f6ecbd64b025567108a33775cad339e835a04360affff82a09410b697dL179-L193) [[2]](diffhunk://#diff-750f31f6ecbd64b025567108a33775cad339e835a04360affff82a09410b697dL243-L244) * [`src/main/java/stirling/software/SPDF/config/EndpointInspector.java`](diffhunk://#diff-845de13e140bb1264014539714860f044405274ad2a9481f38befdd1c1333818R1-R291): Introduced a new `EndpointInspector` class to discover and validate GET endpoints dynamically. ### New functionality for PDF compression: * [`src/main/java/stirling/software/SPDF/controller/api/misc/CompressController.java`](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805R10): Enhanced the `CompressController` to handle nested images within form XObjects, improving the accuracy of image compression in PDFs. Remove Compresses Dependency on QPDF [[1]](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805R10) [[2]](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805R28-R44) [[3]](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805L49-R61) [[4]](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805R77-R99) [[5]](diff hunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805L92-R191) Closes #(issue_number) --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: a <a>
2025-03-20 09:39:57 +00:00
// Check if we're accepting ONLY ZIP files (in which case extract everything)
// or if the file type matches the accepted type
if (zipTypes.includes(acceptedFileType) ||
acceptedFileType === '*/*' ||
Add default languages to OCR, fix compression for QPDF and embedded images (#3202) # Description of Changes This pull request includes several changes to the codebase, focusing on enhancing OCR support, improving endpoint management, and adding new functionality for PDF compression. The most important changes are detailed below. ### Enhancements to OCR support: * `Dockerfile` and `Dockerfile.fat`: Added support for multiple new OCR languages including Chinese (Simplified), German, French, and Portuguese. (Our top 5 languages including English) [[1]](diffhunk://#diff-dd2c0eb6ea5cfc6c4bd4eac30934e2d5746747af48fef6da689e85b752f39557R69-R72) [[2]](diffhunk://#diff-571631582b988e88c52c86960cc083b0b8fa63cf88f056f26e9e684195221c27L78-R81) ### Improvements to endpoint management: * [`src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java`](diffhunk://#diff-750f31f6ecbd64b025567108a33775cad339e835a04360affff82a09410b697dR51-R66): Added a new method `isGroupEnabled` to check if a group of endpoints is enabled. * [`src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java`](diffhunk://#diff-750f31f6ecbd64b025567108a33775cad339e835a04360affff82a09410b697dL179-L193): Updated endpoint groups and removed redundant qpdf endpoints. [[1]](diffhunk://#diff-750f31f6ecbd64b025567108a33775cad339e835a04360affff82a09410b697dL179-L193) [[2]](diffhunk://#diff-750f31f6ecbd64b025567108a33775cad339e835a04360affff82a09410b697dL243-L244) * [`src/main/java/stirling/software/SPDF/config/EndpointInspector.java`](diffhunk://#diff-845de13e140bb1264014539714860f044405274ad2a9481f38befdd1c1333818R1-R291): Introduced a new `EndpointInspector` class to discover and validate GET endpoints dynamically. ### New functionality for PDF compression: * [`src/main/java/stirling/software/SPDF/controller/api/misc/CompressController.java`](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805R10): Enhanced the `CompressController` to handle nested images within form XObjects, improving the accuracy of image compression in PDFs. Remove Compresses Dependency on QPDF [[1]](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805R10) [[2]](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805R28-R44) [[3]](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805L49-R61) [[4]](diffhunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805R77-R99) [[5]](diff hunk://#diff-c307589e9f958f2593c9567c5ad9d63cd03788aa4803b3017b1c13b0d0485805L92-R191) Closes #(issue_number) --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: a <a>
2025-03-20 09:39:57 +00:00
(mimeType && (mimeType.startsWith(acceptedFileType.split('/')[0]) || acceptedFileType === mimeType))) {
var file = new File([content], zipEntry.name, { type: mimeType });
file.uniqueId = UUID.uuidv4();
allFiles.push(file);
} else {
console.log(`File ${zipEntry.name} skipped. MIME type (${mimeType}) does not match accepted type (${acceptedFileType})`);
}
}
});
Add zip (#3075) # Description of Changes - Made a recursive function that checks if a file is a zip, then scans its contents. If the content is a zip, or an accepted file type (non-folder, size > 0), add it and repeat the check for zips - Change all convert fragment to accept application/zip - Slightly modified the input file styling to include an ID for appending the "Extracting" text - Added language translation for the "Extracting..." text - (Edit March 3) Removed recursive function, zip file inside target zip file is excluded - For decrypt function after uploading the file, i reused one webworker to handle the decryption , since in the previous code the workers are created but not detroyed for every single file, this caused a huge slow down for uploading large files due to creation of threads and thus this proposal. - Closes #2951 --- ### General - [ ✅] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [✅ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [✅ ] I have performed a self-review of my own code - [✅ ] My changes generate no new warnings ### UI Changes (if applicable) ![image](https://github.com/user-attachments/assets/ee4c6dc8-8740-45c9-8772-05fa7444ca6d) Added extracting text (for all language). ### Testing (if applicable) - [ ✅] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Ludy <Ludy87@users.noreply.github.com> Co-authored-by: reecebrowne <74901996+reecebrowne@users.noreply.github.com> Co-authored-by: Reece Browne <reece@stirling.pdf> Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Co-authored-by: swanemar <107953493+swanemar@users.noreply.github.com> Co-authored-by: stirlingbot[bot] <195170888+stirlingbot[bot]@users.noreply.github.com>
2025-03-10 08:10:35 +08:00
extractionPromises.push(promise);
});
Add zip (#3075) # Description of Changes - Made a recursive function that checks if a file is a zip, then scans its contents. If the content is a zip, or an accepted file type (non-folder, size > 0), add it and repeat the check for zips - Change all convert fragment to accept application/zip - Slightly modified the input file styling to include an ID for appending the "Extracting" text - Added language translation for the "Extracting..." text - (Edit March 3) Removed recursive function, zip file inside target zip file is excluded - For decrypt function after uploading the file, i reused one webworker to handle the decryption , since in the previous code the workers are created but not detroyed for every single file, this caused a huge slow down for uploading large files due to creation of threads and thus this proposal. - Closes #2951 --- ### General - [ ✅] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [✅ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [✅ ] I have performed a self-review of my own code - [✅ ] My changes generate no new warnings ### UI Changes (if applicable) ![image](https://github.com/user-attachments/assets/ee4c6dc8-8740-45c9-8772-05fa7444ca6d) Added extracting text (for all language). ### Testing (if applicable) - [ ✅] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Ludy <Ludy87@users.noreply.github.com> Co-authored-by: reecebrowne <74901996+reecebrowne@users.noreply.github.com> Co-authored-by: Reece Browne <reece@stirling.pdf> Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Co-authored-by: swanemar <107953493+swanemar@users.noreply.github.com> Co-authored-by: stirlingbot[bot] <195170888+stirlingbot[bot]@users.noreply.github.com>
2025-03-10 08:10:35 +08:00
return Promise.all(extractionPromises);
})
.catch(function (err) {
console.error("Error extracting ZIP file:", err);
throw err;
});
}
function handleFileInputChange(inputElement) {
Add zip (#3075) # Description of Changes - Made a recursive function that checks if a file is a zip, then scans its contents. If the content is a zip, or an accepted file type (non-folder, size > 0), add it and repeat the check for zips - Change all convert fragment to accept application/zip - Slightly modified the input file styling to include an ID for appending the "Extracting" text - Added language translation for the "Extracting..." text - (Edit March 3) Removed recursive function, zip file inside target zip file is excluded - For decrypt function after uploading the file, i reused one webworker to handle the decryption , since in the previous code the workers are created but not detroyed for every single file, this caused a huge slow down for uploading large files due to creation of threads and thus this proposal. - Closes #2951 --- ### General - [ ✅] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [✅ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [✅ ] I have performed a self-review of my own code - [✅ ] My changes generate no new warnings ### UI Changes (if applicable) ![image](https://github.com/user-attachments/assets/ee4c6dc8-8740-45c9-8772-05fa7444ca6d) Added extracting text (for all language). ### Testing (if applicable) - [ ✅] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Ludy <Ludy87@users.noreply.github.com> Co-authored-by: reecebrowne <74901996+reecebrowne@users.noreply.github.com> Co-authored-by: Reece Browne <reece@stirling.pdf> Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Co-authored-by: swanemar <107953493+swanemar@users.noreply.github.com> Co-authored-by: stirlingbot[bot] <195170888+stirlingbot[bot]@users.noreply.github.com>
2025-03-10 08:10:35 +08:00
const files = allFiles;
Add zip (#3075) # Description of Changes - Made a recursive function that checks if a file is a zip, then scans its contents. If the content is a zip, or an accepted file type (non-folder, size > 0), add it and repeat the check for zips - Change all convert fragment to accept application/zip - Slightly modified the input file styling to include an ID for appending the "Extracting" text - Added language translation for the "Extracting..." text - (Edit March 3) Removed recursive function, zip file inside target zip file is excluded - For decrypt function after uploading the file, i reused one webworker to handle the decryption , since in the previous code the workers are created but not detroyed for every single file, this caused a huge slow down for uploading large files due to creation of threads and thus this proposal. - Closes #2951 --- ### General - [ ✅] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [✅ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [✅ ] I have performed a self-review of my own code - [✅ ] My changes generate no new warnings ### UI Changes (if applicable) ![image](https://github.com/user-attachments/assets/ee4c6dc8-8740-45c9-8772-05fa7444ca6d) Added extracting text (for all language). ### Testing (if applicable) - [ ✅] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Ludy <Ludy87@users.noreply.github.com> Co-authored-by: reecebrowne <74901996+reecebrowne@users.noreply.github.com> Co-authored-by: Reece Browne <reece@stirling.pdf> Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Co-authored-by: swanemar <107953493+swanemar@users.noreply.github.com> Co-authored-by: stirlingbot[bot] <195170888+stirlingbot[bot]@users.noreply.github.com>
2025-03-10 08:10:35 +08:00
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
showOrHideSelectedFilesContainer(files);
Add zip (#3075) # Description of Changes - Made a recursive function that checks if a file is a zip, then scans its contents. If the content is a zip, or an accepted file type (non-folder, size > 0), add it and repeat the check for zips - Change all convert fragment to accept application/zip - Slightly modified the input file styling to include an ID for appending the "Extracting" text - Added language translation for the "Extracting..." text - (Edit March 3) Removed recursive function, zip file inside target zip file is excluded - For decrypt function after uploading the file, i reused one webworker to handle the decryption , since in the previous code the workers are created but not detroyed for every single file, this caused a huge slow down for uploading large files due to creation of threads and thus this proposal. - Closes #2951 --- ### General - [ ✅] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [✅ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [✅ ] I have performed a self-review of my own code - [✅ ] My changes generate no new warnings ### UI Changes (if applicable) ![image](https://github.com/user-attachments/assets/ee4c6dc8-8740-45c9-8772-05fa7444ca6d) Added extracting text (for all language). ### Testing (if applicable) - [ ✅] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Ludy <Ludy87@users.noreply.github.com> Co-authored-by: reecebrowne <74901996+reecebrowne@users.noreply.github.com> Co-authored-by: Reece Browne <reece@stirling.pdf> Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Co-authored-by: swanemar <107953493+swanemar@users.noreply.github.com> Co-authored-by: stirlingbot[bot] <195170888+stirlingbot[bot]@users.noreply.github.com>
2025-03-10 08:10:35 +08:00
const filesInfo = files.map((f) => {
const url = URL.createObjectURL(f);
return {
name: f.name,
size: f.size,
uniqueId: f.uniqueId,
type: f.type,
url: url,
};
});
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
2024-12-10 16:39:06 +00:00
const selectedFilesContainer = $(inputContainer).siblings('.selected-files');
selectedFilesContainer.empty();
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
filesInfo.forEach((info) => {
let fileContainerClasses = 'small-file-container d-flex flex-column justify-content-center align-items-center';
let fileContainer = document.createElement('div');
$(fileContainer).addClass(fileContainerClasses);
$(fileContainer).attr('id', info.uniqueId);
let fileIconContainer = document.createElement('div');
const isDragAndDropEnabled =
window.location.pathname.includes('add-image') || window.location.pathname.includes('sign');
Add zip (#3075) # Description of Changes - Made a recursive function that checks if a file is a zip, then scans its contents. If the content is a zip, or an accepted file type (non-folder, size > 0), add it and repeat the check for zips - Change all convert fragment to accept application/zip - Slightly modified the input file styling to include an ID for appending the "Extracting" text - Added language translation for the "Extracting..." text - (Edit March 3) Removed recursive function, zip file inside target zip file is excluded - For decrypt function after uploading the file, i reused one webworker to handle the decryption , since in the previous code the workers are created but not detroyed for every single file, this caused a huge slow down for uploading large files due to creation of threads and thus this proposal. - Closes #2951 --- ### General - [ ✅] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [✅ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [✅ ] I have performed a self-review of my own code - [✅ ] My changes generate no new warnings ### UI Changes (if applicable) ![image](https://github.com/user-attachments/assets/ee4c6dc8-8740-45c9-8772-05fa7444ca6d) Added extracting text (for all language). ### Testing (if applicable) - [ ✅] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Ludy <Ludy87@users.noreply.github.com> Co-authored-by: reecebrowne <74901996+reecebrowne@users.noreply.github.com> Co-authored-by: Reece Browne <reece@stirling.pdf> Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Co-authored-by: swanemar <107953493+swanemar@users.noreply.github.com> Co-authored-by: stirlingbot[bot] <195170888+stirlingbot[bot]@users.noreply.github.com>
2025-03-10 08:10:35 +08:00
// add image thumbnail to it
if (info.type.startsWith('image/')) {
let imgPreview = document.createElement('img');
imgPreview.src = info.url;
imgPreview.alt = 'Preview';
imgPreview.style.width = '50px';
imgPreview.style.height = '50px';
imgPreview.style.objectFit = 'cover';
$(fileIconContainer).append(imgPreview);
if (isDragAndDropEnabled) {
let dragIcon = document.createElement('div');
dragIcon.classList.add('drag-icon');
dragIcon.innerHTML =
'<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e8eaed"><path d="M360-160q-33 0-56.5-23.5T280-240q0-33 23.5-56.5T360-320q33 0 56.5 23.5T440-240q0 33-23.5 56.5T360-160Zm240 0q-33 0-56.5-23.5T520-240q0-33 23.5-56.5T600-320q33 0 56.5 23.5T680-240q0 33-23.5 56.5T600-160ZM360-400q-33 0-56.5-23.5T280-480q0-33 23.5-56.5T360-560q33 0 56.5 23.5T440-480q0 33-23.5 56.5T360-400Zm240 0q-33 0-56.5-23.5T520-480q0-33 23.5-56.5T600-560q33 0 56.5 23.5T680-480q0 33-23.5 56.5T600-400ZM360-640q-33 0-56.5-23.5T280-720q0-33 23.5-56.5T360-800q33 0 56.5 23.5T440-720q0 33-23.5 56.5T360-640Zm240 0q-33 0-56.5-23.5T520-720q0-33 23.5-56.5T600-800q33 0 56.5 23.5T680-720q0 33-23.5 56.5T600-640Z"/></svg>';
fileContainer.appendChild(dragIcon);
$(fileContainer).attr('draggable', 'true');
$(fileContainer).on('dragstart', (e) => {
e.originalEvent.dataTransfer.setData('fileUrl', info.url);
e.originalEvent.dataTransfer.setData('uniqueId', info.uniqueId);
e.originalEvent.dataTransfer.setDragImage(imgPreview, imgPreview.width / 2, imgPreview.height / 2);
});
enableImagePreviewOnClick(fileIconContainer);
} else {
$(fileContainer).removeAttr('draggable');
}
} else {
fileIconContainer = createFileIconContainer(info);
}
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
let fileInfoContainer = createFileInfoContainer(info);
if (!isDragAndDropEnabled) {
let removeBtn = document.createElement('div');
removeBtn.classList.add('remove-selected-file');
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
let removeBtnIconHTML = `<svg xmlns="http://www.w3.org/2000/svg" height="20px" viewBox="0 -960 960 960" width="20px" fill="#C02223"><path d="m339-288 141-141 141 141 51-51-141-141 141-141-51-51-141 141-141-141-51 51 141 141-141 141 51 51ZM480-96q-79 0-149-30t-122.5-82.5Q156-261 126-331T96-480q0-80 30-149.5t82.5-122Q261-804 331-834t149-30q80 0 149.5 30t122 82.5Q804-699 834-629.5T864-480q0 79-30 149t-82.5 122.5Q699-156 629.5-126T480-96Z"/></svg>`;
$(removeBtn).append(removeBtnIconHTML);
$(removeBtn).attr('data-file-id', info.uniqueId).click(removeFileListener);
$(fileContainer).append(removeBtn);
}
$(fileContainer).append(fileIconContainer, fileInfoContainer);
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
selectedFilesContainer.append(fileContainer);
});
const pageContainers = $('#box-drag-container');
pageContainers.off('dragover').on('dragover', (e) => {
e.preventDefault();
});
pageContainers.off('drop').on('drop', (e) => {
e.preventDefault();
const fileUrl = e.originalEvent.dataTransfer.getData('fileUrl');
if (fileUrl) {
const existingImages = $(e.target).find(`img[src="${fileUrl}"]`);
if (existingImages.length === 0) {
DraggableUtils.createDraggableCanvasFromUrl(fileUrl);
}
}
const overlayElement = chooser.querySelector('.drag-drop-overlay');
if (overlayElement) {
overlayElement.style.display = 'none';
}
hasDroppedImage = true;
});
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
showOrHideSelectedFilesContainer(files);
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
}
function showOrHideSelectedFilesContainer(files) {
2385 feature request pdf multi tool to use new file input box (#3201) # Description of Changes Please provide a summary of the changes, including: - Multitool now makes use of the common file input. - deleted multitool file input - moved tool bar to floating at the bottom of the view window Closes #(2385) --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details.
2025-03-20 00:06:47 +00:00
if (showUploads && files && files.length > 0) {
chooser.style.setProperty('--selected-files-display', 'flex');
} else {
chooser.style.setProperty('--selected-files-display', 'none');
}
const isDragAndDropEnabled =
(window.location.pathname.includes('add-image') || window.location.pathname.includes('sign')) &&
files.some((file) => file.type.startsWith('image/'));
if (!isDragAndDropEnabled) return;
const selectedFilesContainer = chooser.querySelector('.selected-files');
let overlayElement = chooser.querySelector('.drag-drop-overlay');
if (!overlayElement) {
selectedFilesContainer.style.position = 'relative';
overlayElement = document.createElement('div');
overlayElement.classList.add('draggable-image-overlay');
overlayElement.innerHTML = 'Drag images to add them to the page';
selectedFilesContainer.appendChild(overlayElement);
}
if (hasDroppedImage) overlayElement.style.display = files && files.length > 0 ? 'flex' : 'none';
selectedFilesContainer.addEventListener('mouseenter', () => {
overlayElement.style.display = 'none';
});
selectedFilesContainer.addEventListener('mouseleave', () => {
if (!hasDroppedImage) overlayElement.style.display = files && files.length > 0 ? 'flex' : 'none';
});
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
}
function removeFileListener(e) {
2024-12-10 16:39:06 +00:00
const fileId = e.target.getAttribute('data-file-id');
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
let inputElement = document.getElementById(elementId);
removeFileById(fileId, inputElement);
showOrHideSelectedFilesContainer(allFiles);
Add zip (#3075) # Description of Changes - Made a recursive function that checks if a file is a zip, then scans its contents. If the content is a zip, or an accepted file type (non-folder, size > 0), add it and repeat the check for zips - Change all convert fragment to accept application/zip - Slightly modified the input file styling to include an ID for appending the "Extracting" text - Added language translation for the "Extracting..." text - (Edit March 3) Removed recursive function, zip file inside target zip file is excluded - For decrypt function after uploading the file, i reused one webworker to handle the decryption , since in the previous code the workers are created but not detroyed for every single file, this caused a huge slow down for uploading large files due to creation of threads and thus this proposal. - Closes #2951 --- ### General - [ ✅] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [✅ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md) (if applicable) - [✅ ] I have performed a self-review of my own code - [✅ ] My changes generate no new warnings ### UI Changes (if applicable) ![image](https://github.com/user-attachments/assets/ee4c6dc8-8740-45c9-8772-05fa7444ca6d) Added extracting text (for all language). ### Testing (if applicable) - [ ✅] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/DeveloperGuide.md#6-testing) for more details. --------- Co-authored-by: Ludy <Ludy87@users.noreply.github.com> Co-authored-by: reecebrowne <74901996+reecebrowne@users.noreply.github.com> Co-authored-by: Reece Browne <reece@stirling.pdf> Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Co-authored-by: swanemar <107953493+swanemar@users.noreply.github.com> Co-authored-by: stirlingbot[bot] <195170888+stirlingbot[bot]@users.noreply.github.com>
2025-03-10 08:10:35 +08:00
inputElement.dispatchEvent(new CustomEvent('file-input-change', { bubbles: true }));
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
}
function removeFileById(fileId, inputElement) {
let fileContainer = document.getElementById(fileId);
fileContainer.remove();
2024-12-10 16:39:06 +00:00
allFiles = allFiles.filter((v) => v.uniqueId != fileId);
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
let dataTransfer = toDataTransfer(allFiles);
if (inputElement) inputElement.files = dataTransfer.files;
}
function createFileIconContainer(info) {
let fileIconContainer = document.createElement('div');
fileIconContainer.classList.add('file-icon');
// Add icon based on the extension
let fileExtension = FileUtils.extractFileExtension(info.name);
let fileIcon = FileIconFactory.createFileIcon(fileExtension);
$(fileIconContainer).append(fileIcon);
return fileIconContainer;
}
function createFileInfoContainer(info) {
2024-12-10 16:39:06 +00:00
let fileInfoContainer = document.createElement('div');
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
let fileInfoContainerClasses = 'file-info d-flex flex-column align-items-center justify-content-center';
$(fileInfoContainer).addClass(fileInfoContainerClasses);
2024-12-10 16:39:06 +00:00
$(fileInfoContainer).append(`<div title="${info.name}">${info.name}</div>`);
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
let fileSizeWithUnits = FileUtils.transformFileSize(info.size);
2024-12-10 16:39:06 +00:00
$(fileInfoContainer).append(`<div title="${info.size}">${fileSizeWithUnits}</div>`);
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
return fileInfoContainer;
}
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
//Listen for event of file being removed and the filter it out of the allFiles array
2024-12-10 16:39:06 +00:00
document.addEventListener('fileRemoved', function (e) {
Fix drag and drop area for file choosers by adding separate ones (#2368) * Add separate drag and drop area for file choosers - Add separate drag and drop area for file choosers ### Why? Previously, when there were multiple file choosers in the same page, if you attempted to drag and drop any files, they would be added to both file choosers as it was designed at first to handle 1 file chooser present, now that we have multiple ones, it is necessary to adapt our design to match the changing functionality. ### Can you not preserve the old overlay when there's only one file chooser present? Yes, we can, but imagine as a user, you try to drag and drop a file in one page and the fields turn into drag and drop areas then you go to another page and try to drag and drop again but you encounter the old overlay instead, as a user you might get confused and ask yourself "What changed?" or if a user is telling another user the steps to drag and drop files and he didn't know about this case, then it would still be confusing, thus consistency is preferred in this case. * Update file chooser UI * Add support for listing and removing selected files and their file icons - Selected files are listed below the file chooser in a selected files container. - Users can now remove uploaded/selected files. - Hide selected files container/box unless there are files selected/uploaded. - Add separate overlay for each drag & drop area. ## FAQ: - Why did you assign a unique id to each file? isn't the filename enough? = Because a user might upload multiple files with the same name, if the user wanted to remove one of them, how would we differentiate between them? we won't be able to unless we assign an identifier, you might argue "we remove based on the filename and size", then what if the user uploaded the same file more than once (intentionally), then we would accidentally remove all the files even though that is not what the user wanted, so going with unique ID approach would prevent this issue/problem from occurring in the first place. * Rename remove-file css class to remove-selected-file - Rename remove-file css class to remove-selected-file to avoid css conflict with remove-file in merge.css * Use input element to dispatch event on file removal Use the correct element to dispatch "file-input-change" (input element is the correct one). * Adapt file chooser UI to themes - Adapt file chooser UI to themes by adjusting their font colors and background colors. - Make text more visible in overlay by increasing the font size by 0.1rem and setting font weight to 550. * Remove extra overlay border - Removing overlay's border as it is unnecessary and only causing a double border issue on the file input container. * Remove Browse button, highlight file chooser and make it clickable - Remove browse button. - Make the entire file chooser container clickable. - Add glowing effect on hover for file chooser. - Change color of file chooser on hover. * Replace crypto.randomUUID() with UUID.uuidv4() - Replace crypto.randomUUID() with UUID.uuidv4() as crypto.randomUUID() is only supported in secured contexts such as localhost 127.0.0.1 and over HTTPS * Fix merge file removal not being reflected in file chooser - Files removed from the list in merge page would now be reflected in the file chooser's container. * Make inputElement optional in removeFileById - Make inputElement optional in removeFileById, this way we could control changing inputElements files. * Add translation support to file chooser --------- Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
2024-12-02 20:10:12 +02:00
const fileId = e.detail;
let inputElement = document.getElementById(elementId);
removeFileById(fileId, inputElement);
showOrHideSelectedFilesContainer(allFiles);
});
function enableImagePreviewOnClick(container) {
const imagePreviewModal = document.getElementById('imagePreviewModal') || createImagePreviewModal();
container.querySelectorAll('img').forEach((img) => {
if (!img.hasPreviewListener) {
img.addEventListener('mouseup', function () {
const imgElement = imagePreviewModal.querySelector('img');
imgElement.src = this.src;
imagePreviewModal.style.display = 'flex';
});
img.hasPreviewListener = true;
}
});
function createImagePreviewModal() {
const modal = document.createElement('div');
modal.id = 'imagePreviewModal';
modal.style.position = 'fixed';
modal.style.top = '0';
modal.style.left = '0';
modal.style.width = '100vw';
modal.style.height = '100vh';
modal.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
modal.style.display = 'none';
modal.style.justifyContent = 'center';
modal.style.alignItems = 'center';
modal.style.zIndex = '2000';
const imgElement = document.createElement('img');
imgElement.style.maxWidth = '90%';
imgElement.style.maxHeight = '90%';
modal.appendChild(imgElement);
document.body.appendChild(modal);
modal.addEventListener('click', () => {
modal.style.display = 'none';
});
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && modal.style.display === 'flex') {
modal.style.display = 'none';
}
});
return modal;
}
}
2023-08-02 22:49:43 +01:00
}