0
0
Fork 0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-04-18 18:38:44 +00:00

Added prevention of nested chapters on sort

This commit is contained in:
Dan Brown 2023-01-27 17:39:51 +00:00
parent b649738718
commit 87e371ffde
No known key found for this signature in database
GPG key ID: 46D9F943C24A2EF9

View file

@ -260,7 +260,8 @@ export class BookSort extends Component {
animation: 150, animation: 150,
fallbackOnBody: true, fallbackOnBody: true,
swapThreshold: 0.65, swapThreshold: 0.65,
onSort: () => { onSort: (event) => {
this.ensureNoNestedChapters()
this.updateMapInput(); this.updateMapInput();
this.updateMoveActionStateForAll(); this.updateMoveActionStateForAll();
}, },
@ -273,6 +274,20 @@ export class BookSort extends Component {
} }
} }
/**
* Handle nested chapters by moving them to the parent book.
* Needed since sorting with multi-sort only checks group rules based on the active item,
* not all in group, therefore need to manually check after a sort.
* Must be done before updating the map input.
*/
ensureNoNestedChapters() {
const nestedChapters = this.container.querySelectorAll('[data-type="chapter"] [data-type="chapter"]');
for (const chapter of nestedChapters) {
const parentChapter = chapter.parentElement.closest('[data-type="chapter"]');
parentChapter.insertAdjacentElement('afterend', chapter);
}
}
/** /**
* Update the input with our sort data. * Update the input with our sort data.
*/ */