Skip to content
This repository has been archived by the owner on Feb 13, 2023. It is now read-only.

Commit

Permalink
feat(core): Mutate item position on drag end (#1143)
Browse files Browse the repository at this point in the history
  • Loading branch information
derpdead authored Nov 25, 2021
1 parent db910ba commit 6936873
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export default {
type: OPTION_STATES.MOVE,
value: index,
});
this.setSortedOptions(items.map(item => item.fieldKey));
this.onScopeValueChange({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
:index="index"
:item="item"
@remove-item="onRemoveItem"
@swap="onSwapItems">
@swap="onSwapItems"
@drag-end="onDragEndItem">
<template #item>
<slot
name="item"
Expand Down Expand Up @@ -236,6 +237,18 @@ export default {
event.preventDefault();
},
onDragEndItem(index) {
const optionKey = this.optionKey || 'id';
const newItemId = this.localItems[index][optionKey];
const oldItemIndex = this.items.findIndex(item => item[optionKey] === newItemId);
if (index !== oldItemIndex) {
this.$emit('move-item', {
index,
items: this.localItems,
});
}
},
onRemoveItem(item) {
this.$emit('remove-item', item);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ export default {
});
this.$emit('remove-item', this.item);
} else {
this.$emit('drag-end', this.index);
}
this.__setState({
Expand Down

0 comments on commit 6936873

Please sign in to comment.