1 import Sortable from 'sortablejs';
2 import {Component} from './component';
7 * Can have data set on the dragged items by setting a 'data-drag-content' attribute.
8 * This attribute must contain JSON where the keys are content types and the values are
9 * the data to set on the data-transfer.
11 export class SortableList extends Component {
14 this.container = this.$el;
15 this.handleSelector = this.$opts.handleSelector;
17 const sortable = new Sortable(this.container, {
18 handle: this.handleSelector,
21 this.$emit('sort', {ids: sortable.toArray()});
23 setData(dataTransferItem, dragEl) {
24 const jsonContent = dragEl.getAttribute('data-drag-content');
26 const contentByType = JSON.parse(jsonContent);
27 for (const [type, content] of Object.entries(contentByType)) {
28 dataTransferItem.setData(type, content);
34 dragoverBubble: false,