Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract objectKey param #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions DragDropList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

export let data = [];
export let removesItems = false;
export let objectKey = 'id';

let ghost;
let grabbed;
Expand Down Expand Up @@ -177,12 +178,12 @@
on:touchmove={function(ev) {ev.stopPropagation(); drag(ev.touches[0].clientY);}}
on:mouseup={function(ev) {ev.stopPropagation(); release(ev);}}
on:touchend={function(ev) {ev.stopPropagation(); release(ev.touches[0]);}}>
{#each data as datum, i (datum.id ? datum.id : JSON.stringify(datum))}
{#each data as datum, i (datum[objectKey] ? datum[objectKey] : JSON.stringify(datum))}
<div
id={(grabbed && (datum.id ? datum.id : JSON.stringify(datum)) == grabbed.dataset.id) ? "grabbed" : ""}
id={(grabbed && (datum[objectKey] ? datum[objectKey] : JSON.stringify(datum)) == grabbed.dataset.id) ? "grabbed" : ""}
class="item"
data-index={i}
data-id={(datum.id ? datum.id : JSON.stringify(datum))}
data-id={(datum[objectKey] ? datum[objectKey] : JSON.stringify(datum))}
data-grabY="0"
on:mousedown={function(ev) {grab(ev.clientY, this);}}
on:touchstart={function(ev) {grab(ev.touches[0].clientY, this);}}
Expand Down Expand Up @@ -225,4 +226,4 @@
</div>
{/each}
</div>
</main>
</main>