mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-16 19:33:11 +02:00
2926 bug undo feature of multitool delete your upload file (#3101)
# Description of Changes Please provide a summary of the changes, including: - What was changed Added support for single page and multi page undo/redo drag and drop in multitool removed selecting pages from undo/redo stack - Why the change was made Drag and drop was not supported fully with undo/redo functionality Closes #(2926) --- ## [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 performed a self-review of my code - [X] My changes generate no new warnings ### Documentation ### UI Changes I Will start a demo in PR so people can try the new functionality [numberedpages.pdf](https://github.com/user-attachments/files/19043978/numberedpages.pdf) Please feel free to use this PDF to aid with trying out the new functionality ### 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.
This commit is contained in:
@@ -34,12 +34,10 @@ export class AddFilesCommand extends Command {
|
||||
|
||||
if (this.pagesContainer.childElementCount === 0) {
|
||||
const filenameInput = document.getElementById('filename-input');
|
||||
const filenameParagraph = document.getElementById('filename');
|
||||
const downloadBtn = document.getElementById('export-button');
|
||||
|
||||
filenameInput.disabled = true;
|
||||
filenameInput.value = '';
|
||||
filenameParagraph.innerText = '';
|
||||
downloadBtn.disabled = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import {Command} from './command.js';
|
||||
|
||||
export class CommandSequence extends Command {
|
||||
constructor(commands) {
|
||||
super();
|
||||
this.commands = commands;
|
||||
|
||||
}
|
||||
execute() {
|
||||
this.commands.forEach((command) => command.execute())
|
||||
}
|
||||
|
||||
undo() {
|
||||
this.commands.slice().reverse().forEach((command) => command.undo())
|
||||
}
|
||||
|
||||
redo() {
|
||||
this.execute();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import {Command} from './command.js';
|
||||
|
||||
export class AbstractMovePageCommand extends Command {
|
||||
export class MovePageCommand extends Command {
|
||||
constructor(startElement, endElement, pagesContainer, pagesContainerWrapper, scrollTo = false) {
|
||||
super();
|
||||
|
||||
@@ -16,7 +16,6 @@ export class AbstractMovePageCommand extends Command {
|
||||
this.scrollTo = scrollTo;
|
||||
this.pagesContainerWrapper = pagesContainerWrapper;
|
||||
}
|
||||
|
||||
execute() {
|
||||
// Check & remove page number elements here too if they exist because Firefox doesn't fire the relevant event on page move.
|
||||
const pageNumberElement = this.startElement.querySelector('.page-number');
|
||||
@@ -42,51 +41,11 @@ export class AbstractMovePageCommand extends Command {
|
||||
}
|
||||
|
||||
undo() {
|
||||
// Requires overriding in child classes
|
||||
}
|
||||
|
||||
redo() {
|
||||
this.execute();
|
||||
}
|
||||
}
|
||||
|
||||
export class MovePageUpCommand extends AbstractMovePageCommand {
|
||||
constructor(startElement, endElement, pagesContainer, pagesContainerWrapper, scrollTo = false) {
|
||||
super(startElement, endElement, pagesContainer, pagesContainerWrapper, scrollTo);
|
||||
}
|
||||
|
||||
undo() {
|
||||
if (this.endElement) {
|
||||
this.pagesContainer.removeChild(this.endElement);
|
||||
this.startElement.insertAdjacentElement('beforebegin', this.endElement);
|
||||
}
|
||||
|
||||
if (this.scrollTo) {
|
||||
const {width} = this.startElement.getBoundingClientRect();
|
||||
const vector = this.endIndex === -1 || this.startIndex <= this.endIndex ? 0 - width : width;
|
||||
|
||||
this.pagesContainerWrapper.scroll({
|
||||
left: this.pagesContainerWrapper.scrollLeft - vector,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
redo() {
|
||||
this.execute();
|
||||
}
|
||||
}
|
||||
|
||||
export class MovePageDownCommand extends AbstractMovePageCommand {
|
||||
constructor(startElement, endElement, pagesContainer, pagesContainerWrapper, scrollTo = false) {
|
||||
super(startElement, endElement, pagesContainer, pagesContainerWrapper, scrollTo);
|
||||
}
|
||||
|
||||
undo() {
|
||||
let previousElement = this.startElement.previousSibling;
|
||||
|
||||
if (this.startElement) {
|
||||
this.pagesContainer.removeChild(this.startElement);
|
||||
previousElement.insertAdjacentElement('beforebegin', this.startElement);
|
||||
let previousNeighbour = Array.from(this.pagesContainer.childNodes)[this.startIndex];
|
||||
previousNeighbour?.insertAdjacentElement('beforebegin', this.startElement)
|
||||
?? this.pagesContainer.append(this.startElement);
|
||||
}
|
||||
|
||||
if (this.scrollTo) {
|
||||
|
||||
Reference in New Issue
Block a user