|
| 1 | +<script lang="ts"> |
| 2 | + import { useDraggable, useDroppable } from "@dnd-kit-svelte/svelte"; |
| 3 | + import { app } from "$lib/app.svelte"; |
| 4 | + import Channel from "../Channel.svelte"; |
| 5 | + import SplitHeader from "./SplitHeader.svelte"; |
| 6 | +
|
| 7 | + interface Props { |
| 8 | + id: string; |
| 9 | + } |
| 10 | +
|
| 11 | + const { id }: Props = $props(); |
| 12 | +
|
| 13 | + const { ref, handleRef, isDragging } = useDraggable({ id: () => id }); |
| 14 | +
|
| 15 | + const dropCenter = useDroppable({ id: () => `${id}:center` }); |
| 16 | + const dropUp = useDroppable({ id: () => `${id}:up` }); |
| 17 | + const dropDown = useDroppable({ id: () => `${id}:down` }); |
| 18 | + const dropLeft = useDroppable({ id: () => `${id}:left` }); |
| 19 | + const dropRight = useDroppable({ id: () => `${id}:right` }); |
| 20 | +
|
| 21 | + const channel = $derived(app.channels.get(id)); |
| 22 | +</script> |
| 23 | + |
| 24 | +<div class="relative flex size-full flex-col overflow-hidden"> |
| 25 | + {#if channel} |
| 26 | + <SplitHeader {channel} {handleRef} /> |
| 27 | + {/if} |
| 28 | + |
| 29 | + <div class={["relative flex-1", isDragging.current && "opacity-50"]} {@attach ref}> |
| 30 | + {#if channel} |
| 31 | + <Channel {channel} /> |
| 32 | + {:else} |
| 33 | + <div class="text-muted-foreground flex h-full items-center justify-center"> |
| 34 | + Empty Split |
| 35 | + </div> |
| 36 | + {/if} |
| 37 | + |
| 38 | + {@render dropZone(dropCenter, "inset-0")} |
| 39 | + {@render dropZone(dropUp, "top-0 inset-x-0 h-1/3")} |
| 40 | + {@render dropZone(dropDown, "bottom-0 inset-x-0 h-1/3")} |
| 41 | + {@render dropZone(dropLeft, "left-0 inset-y-0 w-1/3")} |
| 42 | + {@render dropZone(dropRight, "right-0 inset-y-0 w-1/3")} |
| 43 | + </div> |
| 44 | +</div> |
| 45 | + |
| 46 | +{#snippet dropZone(dropper: ReturnType<typeof useDroppable>, className: string)} |
| 47 | + <div |
| 48 | + class={["absolute z-10", className, dropper.isDropTarget.current && "bg-primary/50"]} |
| 49 | + {@attach dropper.ref} |
| 50 | + ></div> |
| 51 | +{/snippet} |
0 commit comments