drag & drop memory in designer

This commit is contained in:
Jan Prochazka
2022-12-31 10:37:25 +01:00
parent 6b5d2114bf
commit b8fcbbbc93
2 changed files with 66 additions and 4 deletions

View File

@@ -0,0 +1,54 @@
<script lang="ts">
export let sourceDragColumn$;
export let targetDragColumn$;
export let settings;
let memory;
</script>
{#if settings?.allowCreateRefByDrag}
<div
class="wrapper"
draggable={!!memory}
title={memory ? 'Drag this column to other column for creating JOIN' : 'Drag column here for creating JOIN'}
on:dragstart={e => {
if (!settings?.allowCreateRefByDrag) return;
if (!memory) return;
const dragData = { ...memory };
sourceDragColumn$.set(dragData);
e.dataTransfer.setData('designer_column_drag_data', JSON.stringify(dragData));
}}
on:dragend={e => {
sourceDragColumn$.set(null);
targetDragColumn$.set(null);
}}
on:dragover={e => {
if ($sourceDragColumn$) {
e.preventDefault();
}
}}
on:drop={e => {
var data = e.dataTransfer.getData('designer_column_drag_data');
e.preventDefault();
if (!data) return;
memory = $sourceDragColumn$;
sourceDragColumn$.set(null);
targetDragColumn$.set(null);
}}
>
{#if memory}
{memory.columnName}
{:else}
Drag & drop column here
{/if}
</div>
{/if}
<style>
.wrapper {
border: 1px solid var(--theme-border);
padding: 3px;
color: var(--theme-font-2);
}
</style>