Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,24 @@ When a group is dragged, you will receive the following array structure in the L
]
```

## MultiDrag Plugin
Official documentation from Sortable.js https://github.com/SortableJS/Sortable/tree/master/plugins/MultiDrag

To enable the plugin:
- Add `wire:sortable.multidrag` as the first directive in your blade template before any of the other sortable directives.
- Add options relevant to the plugin to your `wire:sortable.options` attribute.

```blade
<ul wire:sortable-multidrag wire:sortable="updateTaskOrder" wire:sortable.options="{ selectedClass: 'chosen', animation: 100 }">
@foreach ($tasks as $task)
<li wire:sortable.item="{{ $task->id }}" wire:key="task-{{ $task->id }}">
<h4>{{ $task->title }}</h4>
<button wire:sortable.handle>drag</button>
</li>
@endforeach
</ul>
```

## Building

```bash
Expand Down
3 changes: 2 additions & 1 deletion dist/livewire-sortable.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/livewire-sortable.js.map

Large diffs are not rendered by default.

18 changes: 13 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import Sortable from 'sortablejs';
import { Sortable, MultiDrag } from 'sortablejs';

window.Sortable = Sortable;

window.Livewire?.directive('sortable', ({el, directive, component}) => {
let multiDragEnabled = false;
window.Livewire?.directive('sortable-multidrag', () => {
window.Sortable.mount(new MultiDrag());
multiDragEnabled = true;
});

window.Livewire?.directive('sortable', ({ el, directive, component }) => {
// Only fire this handler on the "root" directive.
if (directive.modifiers.length > 0) {
return;
Expand All @@ -20,6 +26,7 @@ window.Livewire?.directive('sortable', ({el, directive, component}) => {
draggable: '[wire\\:sortable\\.item]',
handle: el.querySelector('[wire\\:sortable\\.handle]') ? '[wire\\:sortable\\.handle]' : null,
dataIdAttr: 'wire:sortable.item',
multiDrag: multiDragEnabled,
group: {
pull: false,
put: false,
Expand All @@ -42,9 +49,9 @@ window.Livewire?.directive('sortable', ({el, directive, component}) => {
});
});

window.Livewire?.directive('sortable-group', ({el, directive, component}) => {
window.Livewire?.directive('sortable-group', ({ el, directive, component }) => {
// Only fire this handler on the "root" group directive.
if (! directive.modifiers.includes('item-group')) {
if (!directive.modifiers.includes('item-group')) {
return;
}

Expand All @@ -60,6 +67,7 @@ window.Livewire?.directive('sortable-group', ({el, directive, component}) => {
draggable: '[wire\\:sortable-group\\.item]',
handle: el.querySelector('[wire\\:sortable-group\\.handle]') ? '[wire\\:sortable-group\\.handle]' : null,
dataIdAttr: 'wire:sortable-group.item',
multiDrag: multiDragEnabled,
group: {
pull: true,
put: true,
Expand All @@ -73,7 +81,7 @@ window.Livewire?.directive('sortable-group', ({el, directive, component}) => {
return {
order: index + 1,
value: el.getAttribute('wire:sortable-group.item-group'),
items: el.livewire_sortable.toArray().map((value, index) => {
items: el.livewire_sortable.toArray().map((value, index) => {
return {
order: index + 1,
value: value
Expand Down