/** * Keep drag previews local and commit once on release. * Reuse live-layout drop targets and snapping so the template follows the same rules. */ import type { LayoutPaneKind, LayoutTemplate, LayoutWhenNoRoom } from "@t3tools/contracts"; import { msg, T, useGT, useMessages } from "gt-react"; import { ArrowDownIcon, ArrowRightIcon, Columns2Icon, FileDiffIcon, FilesIcon, GlobeIcon, MessageSquareIcon, Rows2Icon, SquareTerminalIcon, Trash2Icon, type LucideIcon, } from "lucide-react"; import { useEffect, useRef, useState, type CSSProperties, type KeyboardEvent, type PointerEvent as ReactPointerEvent, type ReactNode, } from "react"; import { createPortal } from "react-dom"; import { m, type MessageResolver } from "~/i18n/messages"; import { snapToPreset } from "../../layout/ColumnResizeHandle"; import { resolveLayoutDropTarget, type LayoutDropTarget } from "../../layout/layoutDrag"; import { LayoutPaneSkeleton, PaneNotchTab, type LayoutPaneSkeletonShape, } from "../../layout/PaneSkeleton"; import { LAYOUT_TEMPLATE_BOTTOM_SHARE, LAYOUT_TEMPLATE_SPLIT_SHARE, canLayoutTemplatePaneSpan, countLayoutTemplatePanes, extendLayoutTemplate, isOnlyLayoutTemplateChat, layoutTemplatePaneMeasure, removeLayoutTemplatePane, resizeLayoutTemplateColumnDivider, resizeLayoutTemplatePaneDivider, setLayoutTemplatePaneKind, setLayoutTemplatePaneShare, setLayoutTemplatePaneSpan, splitLayoutTemplatePane, type LayoutTemplatePath, } from "../../layout/layoutTemplate"; import { cn, isMacPlatform } from "../../lib/utils"; import { useAtomValue } from "@effect/atom-react"; import { shortcutLabelForCommand } from "../../keybindings"; import { primaryServerKeybindingsAtom } from "../../state/server"; import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover"; import { ContentButton } from "../ui/button"; import { Toggle, ToggleGroup } from "../ui/toggle-group"; import { Text } from "../ui/text"; import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; import { SettingsGroup } from "./SettingsGroup"; const PANE_KINDS: ReadonlyArray<{ kind: LayoutPaneKind; label: string; icon: LucideIcon; shape: LayoutPaneSkeletonShape; }> = [ { kind: "chat", label: msg("Chat"), icon: MessageSquareIcon, shape: "chat" }, { kind: "terminal", label: msg("Terminal"), icon: SquareTerminalIcon, shape: "terminal" }, { kind: "diff", label: msg("Diff"), icon: FileDiffIcon, shape: "diff" }, { kind: "files", label: msg("Files"), icon: FilesIcon, shape: "lines" }, { kind: "browser", label: msg("Browser"), icon: GlobeIcon, shape: "lines" }, ]; function paneKindMeta(kind: LayoutPaneKind) { return PANE_KINDS.find((entry) => entry.kind === kind) ?? PANE_KINDS[0]!; } /** Pen: 10px canvas padding, 6px between panes. */ const CANVAS_PADDING_PX = 10; const PANE_GAP_PX = 6; /** Pointer travel before a press on a chip becomes a drag, so a click still adds. */ const DRAG_THRESHOLD_PX = 6; /** Keyboard step for a focused divider. */ const DIVIDER_KEY_STEP = 0.05; interface Rect { left: number; top: number; width: number; height: number; } interface PaneSlot { id: string; path: LayoutTemplatePath; kind: LayoutPaneKind; /** Fractions of the canvas's inner box. */ rect: Rect; /** What the % badge shows: the pane's height in its column, else its column's width. */ badge: number | null; } type DividerSlot = | { kind: "pane"; id: string; column: number; index: number; /** The pair of panes the divider sits between, as fractions of the canvas. */ pair: Rect; share: number; } | { kind: "column"; id: string; index: number; pair: Rect; share: number }; function paneId(path: LayoutTemplatePath): string { return `${path.column}:${path.pane}`; } /** * Where each pane sits. Columns share the width; a full-width bottom pane * (the first column's last, `span: "full"`) runs under every column, and * the other columns fill the height above it. */ function layoutTemplateSlots(template: LayoutTemplate): { panes: PaneSlot[]; dividers: DividerSlot[]; } { const columns = template.columns; const first = columns[0]; const fullPane = first && columns.length > 1 && first.panes.at(-1)?.span === "full" && first.panes.length > 1 ? first.panes.at(-1)! : null; const fullHeight = fullPane?.size ?? 0; const topHeight = 1 - fullHeight; const panes: PaneSlot[] = []; const dividers: DividerSlot[] = []; let left = 0; columns.forEach((column, columnIndex) => { const isFirst = columnIndex === 0; let top = 0; const rects = column.panes.map((pane, paneIndex) => { const isFull = isFirst && fullPane !== null && paneIndex === column.panes.length - 1; if (isFull) { return { left: 0, top: topHeight, width: 1, height: fullHeight }; } // First-column panes keep their share of the whole height; other // columns divide the height above the full-width pane. const height = isFirst ? pane.size : pane.size * topHeight; const rect = { left, top, width: column.size, height }; top += height; return rect; }); column.panes.forEach((pane, paneIndex) => { const path = { column: columnIndex, pane: paneIndex }; panes.push({ id: paneId(path), path, kind: pane.kind, rect: rects[paneIndex]!, badge: column.panes.length > 1 ? pane.size : columns.length > 1 ? column.size : null, }); const next = rects[paneIndex + 1]; if (next) { const current = rects[paneIndex]!; const pairTop = current.top; const pairBottom = next.top + next.height; const pairLeft = Math.min(current.left, next.left); const pairRight = Math.max(current.left + current.width, next.left + next.width); dividers.push({ kind: "pane", id: `pane:${columnIndex}:${paneIndex}`, column: columnIndex, index: paneIndex, pair: { left: pairLeft, top: pairTop, width: pairRight - pairLeft, height: pairBottom - pairTop, }, share: pane.size / (pane.size + column.panes[paneIndex + 1]!.size), }); } }); const nextColumn = columns[columnIndex + 1]; if (nextColumn) { dividers.push({ kind: "column", id: `column:${columnIndex}`, index: columnIndex, pair: { left, top: 0, width: column.size + nextColumn.size, height: topHeight }, share: column.size / (column.size + nextColumn.size), }); } left += column.size; }); return { panes, dividers }; } /** CSS box for a fraction rect inside the padded canvas, with the pen's gap between neighbors. */ function slotStyle(rect: Rect): CSSProperties { // Half the gap on every edge that has a neighbor, none on the canvas edges. const half = PANE_GAP_PX / 2; const startX = rect.left <= 1e-6 ? 0 : half; const endX = rect.left + rect.width >= 1 - 1e-6 ? 0 : half; const startY = rect.top <= 1e-6 ? 0 : half; const endY = rect.top + rect.height >= 1 - 1e-6 ? 0 : half; return { left: `calc(${rect.left * 100}% + ${startX}px)`, top: `calc(${rect.top * 100}% + ${startY}px)`, width: `calc(${rect.width * 100}% - ${startX + endX}px)`, height: `calc(${rect.height * 100}% - ${startY + endY}px)`, }; } function percent(share: number): string { return `${Math.round(share * 100)}%`; } function dropLabel(target: LayoutDropTarget, resolve: MessageResolver = m): string { if (target.kind === "extend") { return target.edge === "bottom" ? resolve(msg("Full width", { $context: "where a dragged pane lands" })) : resolve(msg("New column", { $context: "where a dragged pane lands" })); } if (target.kind !== "side") return ""; switch (target.side) { case "left": return resolve(msg("Split left")); case "right": return resolve(msg("Split right")); case "up": return resolve(msg("Split up")); case "down": return resolve(msg("Split down")); } } function applyDrop( template: LayoutTemplate, target: LayoutDropTarget, kind: LayoutPaneKind, slots: readonly PaneSlot[], ): LayoutTemplate { if (target.kind === "extend") return extendLayoutTemplate(template, target.edge, kind); if (target.kind !== "side") return template; const slot = slots.find((candidate) => candidate.id === target.paneId); return slot ? splitLayoutTemplatePane(template, slot.path, target.side, kind) : template; } /** The part of a pane a side drop takes, as a fraction rect. */ function dropZoneRect(slot: PaneSlot, side: "left" | "right" | "up" | "down"): Rect { const share = LAYOUT_TEMPLATE_SPLIT_SHARE; const { left, top, width, height } = slot.rect; switch (side) { case "left": return { left, top, width: width * share, height }; case "right": return { left: left + width * (1 - share), top, width: width * share, height }; case "up": return { left, top, width, height: height * share }; case "down": return { left, top: top + height * (1 - share), width, height: height * share }; } } interface ChipDrag { kind: LayoutPaneKind; point: { x: number; y: number }; target: LayoutDropTarget | null; } type DividerDrag = { id: string; template: LayoutTemplate; share: number }; /** * A chip press, below the drag threshold or dragging. A drag that ended * (dropped, or Escape) is "released" until the release's click, which must * not also add a pane. */ type ChipGesture = | { readonly phase: "idle" } | { readonly phase: "pressed"; readonly kind: LayoutPaneKind; readonly x: number; readonly y: number; } | { readonly phase: "dragging"; readonly drag: ChipDrag } | { readonly phase: "released" }; export function LayoutEditor({ template, onChange, stripPreview = null, }: { template: LayoutTemplate; /** One call per finished edit: a drop, a divider release, a popover change. */ onChange: (next: LayoutTemplate) => void; /** While set, the canvas shows how the strip runs past its edges (pen Nm9FG). */ stripPreview?: LayoutWhenNoRoom | null; }) { const gt = useGT(); const messages = useMessages(); const canvasRef = useRef(null); const [chipDrag, setChipDrag] = useState(null); const [dividerDrag, setDividerDrag] = useState(null); const [openPaneId, setOpenPaneId] = useState(null); // A divider drag previews its own template; everything else shows the saved one. const shown = dividerDrag?.template ?? template; const { panes, dividers } = layoutTemplateSlots(shown); const innerRect = (): DOMRect | null => { const canvas = canvasRef.current; if (!canvas) return null; const rect = canvas.getBoundingClientRect(); return new DOMRect( rect.left + CANVAS_PADDING_PX, rect.top + CANVAS_PADDING_PX, rect.width - CANVAS_PADDING_PX * 2, rect.height - CANVAS_PADDING_PX * 2, ); }; const resolveTarget = (point: { x: number; y: number }): LayoutDropTarget | null => { const inner = innerRect(); if (!inner) return null; const toPx = (rect: Rect) => ({ left: inner.left + rect.left * inner.width, top: inner.top + rect.top * inner.height, right: inner.left + (rect.left + rect.width) * inner.width, bottom: inner.top + (rect.top + rect.height) * inner.height, }); return resolveLayoutDropTarget( point, // Template panes hold one kind each, so there is no "add as tab": // mark them companions and give them no chrome row. panes.map((slot) => ({ paneId: slot.id, rect: toPx(slot.rect), companion: true })), { left: inner.left, top: inner.top, right: inner.right, bottom: inner.bottom }, 0, ); }; // Handlers read the gesture from the ref, so a release right after a move // sees that move before it renders; the state is only what the canvas draws. const chipGesture = useRef({ phase: "idle" }); const moveChipGesture = (next: ChipGesture) => { chipGesture.current = next; setChipDrag(next.phase === "dragging" ? next.drag : null); }; // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- Own Escape and pointer capture cleanup only while a template chip is being dragged. useEffect(() => { if (chipDrag === null) return; const onKeyDown = (event: globalThis.KeyboardEvent) => { if (event.key !== "Escape") return; event.preventDefault(); // The release still clicks the chip; that click must not add a pane. chipGesture.current = { phase: "released" }; setChipDrag(null); }; window.addEventListener("keydown", onKeyDown, true); return () => window.removeEventListener("keydown", onKeyDown, true); }, [chipDrag, chipGesture]); const onChipPointerDown = (event: ReactPointerEvent, kind: LayoutPaneKind) => { if (event.button !== 0 || event.pointerType === "touch") return; moveChipGesture({ phase: "pressed", kind, x: event.clientX, y: event.clientY }); event.currentTarget.setPointerCapture(event.pointerId); }; const onChipPointerMove = (event: ReactPointerEvent) => { const gesture = chipGesture.current; if (gesture.phase !== "pressed" && gesture.phase !== "dragging") return; const point = { x: event.clientX, y: event.clientY }; if ( gesture.phase === "pressed" && Math.hypot(point.x - gesture.x, point.y - gesture.y) < DRAG_THRESHOLD_PX ) { return; } const kind = gesture.phase === "pressed" ? gesture.kind : gesture.drag.kind; moveChipGesture({ phase: "dragging", drag: { kind, point, target: resolveTarget(point) } }); }; const onChipPointerUp = (event: ReactPointerEvent) => { const gesture = chipGesture.current; if (event.currentTarget.hasPointerCapture(event.pointerId)) { event.currentTarget.releasePointerCapture(event.pointerId); } if (gesture.phase === "pressed") moveChipGesture({ phase: "idle" }); if (gesture.phase !== "dragging") return; moveChipGesture({ phase: "released" }); const { drag } = gesture; if (drag.target) { const next = applyDrop(template, drag.target, drag.kind, panes); if (next !== template) onChange(next); } }; const onChipPointerCancel = () => moveChipGesture({ phase: "idle" }); const onChipClick = (kind: LayoutPaneKind) => { if (chipGesture.current.phase === "released") { moveChipGesture({ phase: "idle" }); return; } // Without a drag (keyboard, or a plain click) the pane joins on the right. const next = extendLayoutTemplate(template, "right", kind); if (next !== template) onChange(next); }; // Divider drags. const dividerPress = useRef<{ divider: DividerSlot; drag: DividerDrag } | null>(null); const moveDividerDrag = (next: { divider: DividerSlot; drag: DividerDrag } | null) => { dividerPress.current = next; setDividerDrag(next?.drag ?? null); }; const shareFromPointer = (divider: DividerSlot, point: { x: number; y: number }) => { const inner = innerRect(); if (!inner) return null; const extent = divider.kind === "pane" ? divider.pair.height * inner.height : divider.pair.width * inner.width; const raw = divider.kind === "pane" ? (point.y - (inner.top + divider.pair.top * inner.height)) / extent : (point.x - (inner.left + divider.pair.left * inner.width)) / extent; return snapToPreset(Math.max(0, Math.min(1, raw)), extent).value; }; const resizeTo = (base: LayoutTemplate, divider: DividerSlot, share: number) => divider.kind === "pane" ? resizeLayoutTemplatePaneDivider(base, divider.column, divider.index, share) : resizeLayoutTemplateColumnDivider(base, divider.index, share); const onDividerPointerDown = (event: ReactPointerEvent, divider: DividerSlot) => { if (event.button !== 0) return; event.preventDefault(); event.currentTarget.setPointerCapture(event.pointerId); moveDividerDrag({ divider, drag: { id: divider.id, template, share: divider.share } }); }; const onDividerPointerMove = (event: ReactPointerEvent) => { const divider = dividerPress.current?.divider; if (!divider) return; const share = shareFromPointer(divider, { x: event.clientX, y: event.clientY }); if (share === null) return; const next = resizeTo(template, divider, share); const actual = layoutTemplateSlots(next).dividers.find((entry) => entry.id === divider.id)?.share ?? share; moveDividerDrag({ divider, drag: { id: divider.id, template: next, share: actual } }); }; const onDividerPointerUp = (event: ReactPointerEvent) => { const drag = dividerPress.current?.drag; if (event.currentTarget.hasPointerCapture(event.pointerId)) { event.currentTarget.releasePointerCapture(event.pointerId); } moveDividerDrag(null); if (drag && drag.template !== template) onChange(drag.template); }; const onDividerKeyDown = (event: KeyboardEvent, divider: DividerSlot) => { const back = divider.kind === "pane" ? "ArrowUp" : "ArrowLeft"; const forward = divider.kind === "pane" ? "ArrowDown" : "ArrowRight"; if (event.key !== back && event.key !== forward) return; event.preventDefault(); const step = event.key === forward ? DIVIDER_KEY_STEP : -DIVIDER_KEY_STEP; const next = resizeTo(template, divider, divider.share + step); if (next !== template) onChange(next); }; const zone = (() => { const target = chipDrag?.target; if (!target) return null; if (target.kind === "side") { const slot = panes.find((candidate) => candidate.id === target.paneId); return slot ? dropZoneRect(slot, target.side) : null; } if (target.kind !== "extend") return null; if (target.edge === "bottom") { return { left: 0, top: 1 - LAYOUT_TEMPLATE_BOTTOM_SHARE, width: 1, height: LAYOUT_TEMPLATE_BOTTOM_SHARE, }; } const width = LAYOUT_TEMPLATE_SPLIT_SHARE; return { left: target.edge === "left" ? 0 : 1 - width, top: 0, width, height: 1 }; })(); const activeDivider = dividerDrag ? (dividers.find((divider) => divider.id === dividerDrag.id) ?? null) : null; const onlyPane = countLayoutTemplatePanes(template) <= 1; return (
{stripPreview ? ( ) : (
{panes.map((slot) => ( setOpenPaneId(open ? slot.id : null)} onChange={(next) => { if (next !== template) onChange(next); }} onlyPane={onlyPane} /> ))} {dividers.map((divider) => ( onDividerPointerDown(event, divider)} onPointerMove={onDividerPointerMove} onPointerUp={onDividerPointerUp} onKeyDown={(event) => onDividerKeyDown(event, divider)} /> ))} {chipDrag ? : null} {activeDivider && dividerDrag ? ( ) : null}
)}
}> Drag in {PANE_KINDS.map(({ kind, label, icon: Icon }) => ( onChipPointerDown(event, kind)} onPointerMove={onChipPointerMove} onPointerUp={onChipPointerUp} onPointerCancel={onChipPointerCancel} onClick={() => onChipClick(kind)} /> } > {messages(label)} Drag onto the layout, or click to add it on the right ))} {chipDrag ? gt("Edges extend") : stripPreview === "always-shrink" ? gt("Columns share the window") : stripPreview ? gt("Columns keep their width") : gt("Drag dividers to resize")}
{chipDrag ? createPortal(
, document.body, ) : null}
); } /** * The strip past the canvas's edges (pen Nm9FG): new tabs continue to the * right at a readable width and the next workspace waits below. With * "Always shrink" the columns squeeze into the window instead. */ function StripPreview({ whenNoRoom }: { whenNoRoom: LayoutWhenNoRoom }) { const gt = useGT(); const shrink = whenNoRoom === "always-shrink"; const width = shrink ? 1 / 3 : 0.46; const top = 0.74; const columns: ReadonlyArray<{ label: string; badge: boolean }> = [ { label: gt("Chat"), badge: true }, { label: gt("New tab"), badge: true }, { label: gt("Next tab"), badge: shrink }, ]; return (
{columns.map((column, index) => ( ))} {shrink ? null : ( New tabs continue here )} Next workspace below
); } function PreviewPane({ label, icon: Icon, shape, badge, rect, }: { label: string; icon: LucideIcon; shape: LayoutPaneSkeletonShape; badge: number | null; rect: Rect; }) { return (
); } /** A mini pane's label in its notch tab, and its size chip. */ function PaneTab({ icon: Icon, label, badge, }: { icon: LucideIcon; label: string; badge: number | null; }) { return ( {label} {badge !== null ? ( {percent(badge)} ) : null} ); } function PreviewPill({ icon: Icon, className, style, children, }: { icon: LucideIcon; className: string; style: CSSProperties; children: ReactNode; }) { return ( {children} ); } function ChipGhost({ kind }: { kind: LayoutPaneKind }) { const messages = useMessages(); const { label, icon: Icon } = paneKindMeta(kind); return (
{messages(label)}
); } function TemplatePane({ slot, template, open, onOpenChange, onChange, onlyPane, }: { slot: PaneSlot; template: LayoutTemplate; open: boolean; onOpenChange: (open: boolean) => void; onChange: (next: LayoutTemplate) => void; onlyPane: boolean; }) { const gt = useGT(); const messages = useMessages(); const { label: kindLabel, icon: Icon, shape } = paneKindMeta(slot.kind); const label = messages(kindLabel); return ( } > onOpenChange(false)} /> ); } /** Pen d9oHx: kind, span, size, then split and remove. */ function PanePopoverBody({ path, template, onlyPane, onChange, onDone, }: { path: LayoutTemplatePath; template: LayoutTemplate; onlyPane: boolean; onChange: (next: LayoutTemplate) => void; onDone: () => void; }) { const gt = useGT(); const messages = useMessages(); const pane = template.columns[path.column]?.panes[path.pane]; const measure = layoutTemplatePaneMeasure(template, path); const [draftShare, setDraftShare] = useState(null); // The same keys that split a pane in the app (pen B4Wwa). const keybindings = useAtomValue(primaryServerKeybindingsAtom); if (!pane) return null; const onlyChat = isOnlyLayoutTemplateChat(template, path); const canRemove = !onlyPane && !onlyChat; const share = draftShare ?? measure?.share ?? 1; const remove = () => { if (!canRemove) return; onChange(removeLayoutTemplatePane(template, path)); onDone(); }; const splitRightKey = shortcutLabelForCommand(keybindings, "layout.splitRight"); const splitDownKey = shortcutLabelForCommand(keybindings, "layout.splitDown"); const split = (side: "right" | "down") => { onChange(splitLayoutTemplatePane(template, path, side, pane.kind, 0.5)); onDone(); }; const commitShare = () => { if (draftShare === null) return; onChange(setLayoutTemplatePaneShare(template, path, draftShare)); setDraftShare(null); }; const sliderStyle = { "--settings-slider-progress": `${share * 100}%`, "--settings-slider-fill-offset": `${0.5 - share}rem`, } as CSSProperties; return (
{ if (event.key !== "Backspace" && event.key !== "Delete") return; if (event.target instanceof HTMLInputElement) return; event.preventDefault(); remove(); }} > { const next = PANE_KINDS.find((entry) => entry.kind === value[0]); if (next) onChange(setLayoutTemplatePaneKind(template, path, next.kind)); }} > {PANE_KINDS.map(({ kind, label, icon: Icon }) => ( ))} {canLayoutTemplatePaneSpan(template, path) ? ( { const span = value[0]; if (span === "column" || span === "full") { onChange(setLayoutTemplatePaneSpan(template, path, span)); } }} > Under chat Full width ) : null} {measure ? (
setDraftShare(Number(event.currentTarget.value) / 100)} onPointerUp={commitShare} onKeyUp={commitShare} onBlur={commitShare} /> {percent(share)}
) : null}
split("right")} /> split("down")} />
); } function PopoverSection({ label, children }: { label: string; children: ReactNode }) { return (
{label} {children}
); } function PopoverAction({ icon: Icon, label, shortcut, destructive = false, disabled = false, onClick, }: { icon: LucideIcon; label: string; shortcut?: string; destructive?: boolean; disabled?: boolean; onClick: () => void; }) { return ( {label} {shortcut ? {shortcut} : null} ); } function TemplateDivider({ divider, active, onPointerDown, onPointerMove, onPointerUp, onKeyDown, }: { divider: DividerSlot; active: boolean; onPointerDown: (event: ReactPointerEvent) => void; onPointerMove: (event: ReactPointerEvent) => void; onPointerUp: (event: ReactPointerEvent) => void; onKeyDown: (event: KeyboardEvent) => void; }) { const gt = useGT(); const { pair, share } = divider; const horizontal = divider.kind === "pane"; // An 8px hit strip centered in the 6px gap between the pair. const style: CSSProperties = horizontal ? { left: `${pair.left * 100}%`, width: `${pair.width * 100}%`, top: `calc(${(pair.top + pair.height * share) * 100}% - 4px)`, height: 8, } : { top: `${pair.top * 100}%`, height: `${pair.height * 100}%`, left: `calc(${(pair.left + pair.width * share) * 100}% - 4px)`, width: 8, }; return (
); } /** Pen KiIZ0 "60 · 40": the pair's split while a divider drags. */ function DividerReadout({ divider, share }: { divider: DividerSlot; share: number }) { const gt = useGT(); const first = Math.round(share * 100); const { pair } = divider; const style: CSSProperties = divider.kind === "pane" ? { left: `${(pair.left + pair.width / 2) * 100}%`, top: `${(pair.top + pair.height * share) * 100}%`, } : { left: `${(pair.left + pair.width * share) * 100}%`, top: `${(pair.top + pair.height / 2) * 100}%`, }; return (
{divider.kind === "pane" ? gt("Top {share}%", { share: first }) : gt("Left {share}%", { share: first })}
); } /** * While a chip drags (pen B4Wwa): a grip on every pane side and a bar on * every extendable edge, the targeted one bright, the zone the pane would * take outlined, and a pill naming the drop. */ function DropFeedback({ panes, target, zone, }: { panes: readonly PaneSlot[]; target: LayoutDropTarget | null; zone: Rect | null; }) { const messages = useMessages(); const sides = ["left", "right", "up", "down"] as const; const gripStyle = (slot: PaneSlot, side: (typeof sides)[number]): CSSProperties => { const { left, top, width, height } = slot.rect; const centerX = `${(left + width / 2) * 100}%`; const centerY = `${(top + height / 2) * 100}%`; switch (side) { case "left": return { left: `calc(${left * 100}% + 6px)`, top: centerY, width: 4, height: 20 }; case "right": return { left: `calc(${(left + width) * 100}% - 10px)`, top: centerY, width: 4, height: 20, }; case "up": return { left: centerX, top: `calc(${top * 100}% + 22px)`, width: 20, height: 4 }; case "down": return { left: centerX, top: `calc(${(top + height) * 100}% - 10px)`, width: 20, height: 4, }; } }; const isTarget = (slot: PaneSlot, side: (typeof sides)[number]) => target?.kind === "side" && target.paneId === slot.id && target.side === side; const edgeActive = (edge: "left" | "right" | "bottom") => target?.kind === "extend" && target.edge === edge; return (
{panes.flatMap((slot) => sides.map((side) => (
)), )}
{zone && target ? (
{dropLabel(target, messages)}
) : null}
); }