2021-09-16 15:28:44 +02:00
|
|
|
<script>
|
2021-09-16 16:08:42 +02:00
|
|
|
import Indicator from "./Indicator.svelte"
|
2021-09-21 09:36:02 +02:00
|
|
|
import { Sides } from "./DNDHandler.svelte"
|
2021-09-16 16:08:42 +02:00
|
|
|
|
|
|
|
export let dropInfo
|
2021-09-16 15:28:44 +02:00
|
|
|
export let zIndex
|
2021-09-16 16:08:42 +02:00
|
|
|
export let color
|
|
|
|
export let transition
|
2021-09-16 15:28:44 +02:00
|
|
|
|
2021-09-21 09:36:02 +02:00
|
|
|
$: dimensions = getDimensions(dropInfo)
|
2021-09-20 16:35:27 +02:00
|
|
|
$: prefix = dropInfo?.mode === "above" ? "Before" : "After"
|
2021-09-16 16:08:42 +02:00
|
|
|
$: text = `${prefix} ${dropInfo?.name}`
|
2021-09-21 09:36:02 +02:00
|
|
|
$: renderKey = `${dropInfo?.target}-${dropInfo?.side}`
|
2021-09-16 15:28:44 +02:00
|
|
|
|
2021-09-21 09:36:02 +02:00
|
|
|
const getDimensions = info => {
|
|
|
|
const { bounds, side } = info ?? {}
|
|
|
|
if (!bounds || !side) {
|
2021-09-16 15:28:44 +02:00
|
|
|
return null
|
|
|
|
}
|
2021-10-06 14:59:25 +02:00
|
|
|
|
|
|
|
// Get preview offset
|
|
|
|
const root = document.getElementById("clip-root")
|
|
|
|
const rootBounds = root.getBoundingClientRect()
|
|
|
|
|
|
|
|
// Subtract preview offset from bounds
|
|
|
|
let { left, top, width, height } = bounds
|
|
|
|
left -= rootBounds.left
|
|
|
|
top -= rootBounds.top
|
|
|
|
|
|
|
|
// Determine position
|
2021-09-21 09:36:02 +02:00
|
|
|
if (side === Sides.Top || side === Sides.Bottom) {
|
|
|
|
return {
|
|
|
|
top: side === Sides.Top ? top - 4 : top + height,
|
|
|
|
left: left - 2,
|
|
|
|
width: width + 4,
|
|
|
|
height: 0,
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
top: top - 2,
|
|
|
|
left: side === Sides.Left ? left - 4 : left + width,
|
|
|
|
width: 0,
|
|
|
|
height: height + 4,
|
|
|
|
}
|
2021-09-16 16:08:42 +02:00
|
|
|
}
|
2021-09-16 15:28:44 +02:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2021-09-21 09:36:02 +02:00
|
|
|
{#key renderKey}
|
2021-09-20 09:26:44 +02:00
|
|
|
{#if dimensions && dropInfo?.mode !== "inside"}
|
2021-09-16 16:08:42 +02:00
|
|
|
<Indicator
|
2021-09-21 09:36:02 +02:00
|
|
|
left={Math.round(dimensions.left)}
|
|
|
|
top={Math.round(dimensions.top)}
|
2021-09-16 16:08:42 +02:00
|
|
|
width={dimensions.width}
|
2021-09-21 09:36:02 +02:00
|
|
|
height={dimensions.height}
|
2021-09-16 16:08:42 +02:00
|
|
|
{text}
|
|
|
|
{zIndex}
|
|
|
|
{color}
|
|
|
|
{transition}
|
2021-09-21 09:36:02 +02:00
|
|
|
alignRight={dropInfo?.side === Sides.Right}
|
2021-09-16 17:02:45 +02:00
|
|
|
line
|
2021-09-16 16:08:42 +02:00
|
|
|
/>
|
|
|
|
{/if}
|
|
|
|
{/key}
|