feat: extended SortalbeJS events with data attribute #139
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Maybe this PR ist out of scope for
vue-draggable-plus
but I would like to see this or a similar feature in this library.It's a hassle to implement custom logic on Sortable Events, because SortableJS only works on the DOM level.
This Library works on a data level and delegates the DOM manipulation to Vue.js. It would be nice to get more data access in the emitted events on the component and in the callbacks in the composable.
vue.draggable.next implements this using a custom
change
event with references the underlying data.vue-draggable-plus
already uses a workaround to connect data to SortableEvents. Data is saved to theHTMLElement
which is dragged. This is currently only used to insert data from draggable list to another.This PR uses this method to expose the data to every SortableJs event.
To make this work for all events the data needs to be attached in the
onChoose
event, because it's triggered beforeonStart
.During
mergeOptions
the passed options are extended with an data attribute that is read from the already extendedHTMLElement
.With these changes it is much easier to implement side effects on SortableEvents.
For example showing a push notification when an element is added to a list would be possible with:
I`m open to suggestions on how this feature could be implemented in an more elegant way. This is the best I could come up with.