Skip to content

Commit

Permalink
Added capture modifier (@move.capture) support for onMove event (#56)
Browse files Browse the repository at this point in the history
* Added capture modifier support onMove event
* Added type to build project
* Add comment on `attrs`
* Added passing arguments on capture method
* Updated README.md

Co-authored-by: Max Leiter <[email protected]>
  • Loading branch information
YahorDanchanka and MaxLeiter authored Dec 27, 2022
1 parent 7c0a4fe commit 43bd3fe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ You can listen to Sortable events by adding the listeners to the `Sortable` comp
@remove="(event: Sortable.SortableEvent) => void"
@filter="(event: Sortable.SortableEvent) => void"
@move="(event: Sortable.MoveEvent, event2: Event) => void"
@move.capture="(event: Sortable.MoveEvent, event2: Event) => boolean | -1 | 1"
@clone="(event: Sortable.SortableEvent) => void"
>
```
Expand Down
7 changes: 5 additions & 2 deletions src/components/Sortable.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, PropType, watch, onUnmounted, computed } from "vue";
import { ref, PropType, watch, onUnmounted, computed, useAttrs } from "vue";
import Sortable, { SortableOptions } from "sortablejs";
import type { AutoScrollOptions } from "sortablejs/plugins";
Expand Down Expand Up @@ -63,6 +63,8 @@ const emit = defineEmits<{
(eventName: "change", evt: Sortable.SortableEvent): void;
}>();
const attrs = useAttrs()
const containerRef = ref<HTMLElement | null>(null);
const sortable = ref<Sortable | null>(null);
const getKey = computed(() => {
Expand All @@ -84,7 +86,8 @@ watch(containerRef, (newDraggable) => {
onSort: (event) => emit("sort", event),
onRemove: (event) => emit("remove", event),
onFilter: (event) => emit("filter", event),
onMove: (event, originalEvent) => emit("move", event, originalEvent),
// See https://github.com/MaxLeiter/sortablejs-vue3/pull/56 for context on `attrs`.
onMove: (event, originalEvent) => "onMoveCapture" in attrs ? (<(event: Sortable.MoveEvent, originalEvent: Event) => void>attrs.onMoveCapture)(event, originalEvent) : emit("move", event, originalEvent),
onClone: (event) => emit("clone", event),
onChange: (event) => emit("change", event),
});
Expand Down

1 comment on commit 43bd3fe

@vercel
Copy link

@vercel vercel bot commented on 43bd3fe Dec 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.