diff --git a/src/components/admin/npc-dialogue/NodeEditDialog.tsx b/src/components/admin/npc-dialogue/NodeEditDialog.tsx index b51f6043..f4211a6f 100644 --- a/src/components/admin/npc-dialogue/NodeEditDialog.tsx +++ b/src/components/admin/npc-dialogue/NodeEditDialog.tsx @@ -1,6 +1,6 @@ "use client"; -import { useEffect, useState } from "react"; +import { useCallback, useEffect, useRef, useState } from "react"; import { XIcon } from "lucide-react"; import { @@ -64,6 +64,10 @@ const CONDITION_OP_LABELS: Record = { /** Ops that compare against a number (everything except is_true/is_false). */ const NUMERIC_OPS: DialogueCondition["op"][] = ["gte", "lte", "gt", "lt", "eq"]; +/** Max height (px) the dialogue Line box auto-grows to. Longer content scrolls + * inside the box from here; the user can still drag-resize it taller. */ +const MAX_LINE_HEIGHT_PX = 200; + /** Short readable label for a node in the target pickers, with a text snippet. */ function nodeLabel(node: DialogueNode): string { const d = node.data; @@ -139,11 +143,30 @@ export function NodeEditDialog({ node, allNodes, open, onOpenChange, onSave }: N setDraft(node?.data ?? null); }, [node?.id, open]); - if (!node || !draft) return null; - const patch = (partial: Partial) => setDraft((prev) => (prev ? { ...prev, ...partial } : prev)); + const lineRef = useRef(null); + + /** Auto-grow the line box to its content up to MAX_LINE_HEIGHT_PX so long + * lines do not scroll in a fixed-height box. The user can still drag-resize + * it taller; typing re-sizes it to fit. */ + const autoSizeLine = useCallback(() => { + const el = lineRef.current; + if (!el) return; + el.style.height = "auto"; + el.style.height = `${Math.min(el.scrollHeight, MAX_LINE_HEIGHT_PX)}px`; + }, []); + + useEffect(() => { + autoSizeLine(); + }, [draft?.body, autoSizeLine]); + + // Guard lives below every hook so their call order never changes: on the + // first render draft is still null, and returning early here would skip the + // hooks defined above it on later renders (a Rules of Hooks violation). + if (!node || !draft) return null; + const patchEffect = (partial: Partial) => patch({ effect: { type: "notify", ...draft.effect, ...partial } }); @@ -211,11 +234,15 @@ export function NodeEditDialog({ node, allNodes, open, onOpenChange, onSave }: N