Skip to content
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
23 changes: 14 additions & 9 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 All @@ -205,12 +206,16 @@
</div>

<div class="content">
{#if datum.html}
{@html datum.html}
{:else if datum.text}
<p>{datum.text}</p>
{#if $$slots.customView}
<slot name="customView" item={ datum }></slot>
{:else}
<p>{datum}</p>
{#if datum.html}
{@html datum.html}
{:else if datum.text}
<p>{datum.text}</p>
{:else}
<p>{datum}</p>
{/if}
{/if}
</div>

Expand All @@ -225,4 +230,4 @@
</div>
{/each}
</div>
</main>
</main>