X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/2f6ff0734773c4ac009de699a2661971fd585b22..623ccd4cfa5c9a283c5ac52ac89a8685f80d1628:/resources/js/components/sortable-list.js diff --git a/resources/js/components/sortable-list.js b/resources/js/components/sortable-list.js index d2b39ff95..0af0e11c9 100644 --- a/resources/js/components/sortable-list.js +++ b/resources/js/components/sortable-list.js @@ -2,6 +2,11 @@ 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 { @@ -14,7 +19,19 @@ class SortableList { 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, }); } }