mirror of
				https://github.com/BookStackApp/BookStack.git
				synced 2025-11-04 13:31:45 +03:00 
			
		
		
		
	Cannot get working in chrome reliably due to conflicting handling of events and drag+drop API. Getting attachment drop working breaks other parts of TinyMCE. Implementing current work as should still work for MD editor and within FireFox. Related to #1460
		
			
				
	
	
		
			39 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			39 lines
		
	
	
		
			1.2 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) {
 | 
						|
                const jsonContent = dragEl.getAttribute('data-drag-content');
 | 
						|
                if (jsonContent) {
 | 
						|
                    const contentByType = JSON.parse(jsonContent);
 | 
						|
                    for (const [type, content] of Object.entries(contentByType)) {
 | 
						|
                        dataTransferItem.setData(type, content);
 | 
						|
                    }
 | 
						|
                }
 | 
						|
            },
 | 
						|
            revertOnSpill: true,
 | 
						|
            dropBubble: true,
 | 
						|
            dragoverBubble: false,
 | 
						|
        });
 | 
						|
    }
 | 
						|
}
 | 
						|
 | 
						|
export default SortableList; |