mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-04-21 05:26:10 +03:00
Currently fighting between sortable and tinymce mechanisms which prevent this working due to the different events stopping the drop event while needing the dragover for cursor placement.
41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
import Sortable from "sortablejs";
|
|
|
|
/**
|
|
* SortableList
|
|
*
|
|
* Can have data set on the dragged items by setting a 'data-drag-content' attribute.
|
|
* This attribute must contain JSON where the keys are content types and the values are
|
|
* the data to set on the data-transfer.
|
|
*
|
|
* @extends {Component}
|
|
*/
|
|
class SortableList {
|
|
setup() {
|
|
this.container = this.$el;
|
|
this.handleSelector = this.$opts.handleSelector;
|
|
|
|
const sortable = new Sortable(this.container, {
|
|
handle: this.handleSelector,
|
|
animation: 150,
|
|
onSort: () => {
|
|
this.$emit('sort', {ids: sortable.toArray()});
|
|
},
|
|
setData(dataTransferItem, dragEl) {
|
|
console.log('cat');
|
|
const jsonContent = dragEl.getAttribute('data-drag-content');
|
|
if (jsonContent) {
|
|
const contentByType = JSON.parse(jsonContent);
|
|
dataTransferItem.setData('bookstack/json', jsonContent);
|
|
for (const [type, content] of Object.entries(contentByType)) {
|
|
dataTransferItem.setData(type, content);
|
|
}
|
|
}
|
|
},
|
|
revertOnSpill: true,
|
|
dropBubble: true,
|
|
dragoverBubble: false,
|
|
});
|
|
}
|
|
}
|
|
|
|
export default SortableList; |