feat(npc-dialogue): taller flow canvas plus expand-to-screen toggle
Raise the default editor height from h-96 to 60vh (min 28rem) and add an Expand/Shrink toolbar toggle that floats the whole editor over the document form, filling the viewport right of the admin sidebar via the shell's --nav-width/--app-header-height vars. Esc collapses it unless the node dialog or context menu is open.
This commit is contained in:
parent
78dc4945f7
commit
0cadd1e062
2 changed files with 54 additions and 3 deletions
|
|
@ -61,6 +61,26 @@
|
|||
}
|
||||
}
|
||||
|
||||
/* NPC dialogue editor: "expand" mode floats the whole editor (toolbar +
|
||||
canvas) over the document form, filling the viewport to the right of the
|
||||
admin sidebar. Offsets ride the admin shell's own CSS vars so the overlay
|
||||
tracks the sidebar width and header height; z-index stays below the
|
||||
status toasts (--z-status: 40) and Radix dialogs (z-50). */
|
||||
.npc-dialogue-editor--expanded {
|
||||
position: fixed;
|
||||
top: var(--app-header-height);
|
||||
left: var(--nav-width);
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: calc(var(--z-modal) - 1);
|
||||
|
||||
/* Small breakpoint: --nav-width becomes 100vw (off-canvas nav), which would
|
||||
push the overlay off screen. */
|
||||
@media (max-width: 1024px) {
|
||||
left: 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Tech Tree: dark thin scrollbars for the panel and its dropdowns. */
|
||||
.tech-tree-scroll {
|
||||
scrollbar-width: thin;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import {
|
|||
useNodesState,
|
||||
} from "@xyflow/react";
|
||||
import "@xyflow/react/dist/style.css";
|
||||
import { Maximize2, Minimize2 } from "lucide-react";
|
||||
|
||||
import { useField } from "@payloadcms/ui";
|
||||
|
||||
|
|
@ -66,6 +67,7 @@ export function NpcDialogueEditor() {
|
|||
const [nodes, setNodes, onNodesChange] = useNodesState(initial.nodes as Node[]);
|
||||
const [editingNodeId, setEditingNodeId] = useState<string | null>(null);
|
||||
const [contextMenu, setContextMenu] = useState<ContextMenu>(null);
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
|
||||
const lastSerialized = useRef<string>("");
|
||||
const menuRef = useRef<HTMLDivElement | null>(null);
|
||||
|
|
@ -224,11 +226,26 @@ export function NpcDialogueEditor() {
|
|||
};
|
||||
}, [contextMenu, closeMenu]);
|
||||
|
||||
// Escape collapses the expanded editor, but only when nothing is layered
|
||||
// on top of it (the node dialog or the context menu claim the key first).
|
||||
useEffect(() => {
|
||||
if (!expanded) return;
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape" && !contextMenu && editingNodeId === null) setExpanded(false);
|
||||
};
|
||||
window.addEventListener("keydown", onKey);
|
||||
return () => window.removeEventListener("keydown", onKey);
|
||||
}, [expanded, contextMenu, editingNodeId]);
|
||||
|
||||
const buttonClass =
|
||||
"px-2 py-1 text-[10px] font-medium rounded border transition-colors cursor-pointer";
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-2 w-full">
|
||||
<div
|
||||
className={`flex flex-col gap-2 w-full${
|
||||
expanded ? " npc-dialogue-editor--expanded bg-zinc-950 p-3" : ""
|
||||
}`}
|
||||
>
|
||||
<div className="flex flex-wrap items-center gap-1 px-2 py-1.5 bg-zinc-900 rounded-t-md border border-zinc-700">
|
||||
<span className="text-[9px] uppercase tracking-wider text-zinc-500 font-semibold mr-1">
|
||||
Nodes
|
||||
|
|
@ -273,6 +290,16 @@ export function NpcDialogueEditor() {
|
|||
<span className="ml-auto text-[10px] text-zinc-500">
|
||||
{nodes.length} node{nodes.length !== 1 ? "s" : ""}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
title={expanded ? "Shrink editor (Esc)" : "Expand editor to fill the screen"}
|
||||
aria-pressed={expanded}
|
||||
onClick={() => setExpanded((v) => !v)}
|
||||
className={`${buttonClass} inline-flex items-center gap-1 bg-zinc-800 border-zinc-600 text-zinc-300 hover:bg-zinc-700`}
|
||||
>
|
||||
{expanded ? <Minimize2 size={12} /> : <Maximize2 size={12} />}
|
||||
{expanded ? "Shrink" : "Expand"}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{!validation.valid && (
|
||||
|
|
@ -281,7 +308,11 @@ export function NpcDialogueEditor() {
|
|||
</div>
|
||||
)}
|
||||
|
||||
<div className="npc-dialogue-flow h-96 border border-zinc-700 rounded-b-md overflow-hidden bg-zinc-950">
|
||||
<div
|
||||
className={`npc-dialogue-flow border border-zinc-700 overflow-hidden bg-zinc-950 ${
|
||||
expanded ? "flex-1 min-h-0 rounded-md" : "h-[60vh] min-h-[28rem] rounded-b-md"
|
||||
}`}
|
||||
>
|
||||
<ReactFlow
|
||||
nodes={nodes}
|
||||
edges={syncedEdges}
|
||||
|
|
@ -326,7 +357,7 @@ export function NpcDialogueEditor() {
|
|||
<p className="text-[10px] text-zinc-500">
|
||||
Click a node to edit. Right-click to delete. Drag from a node's right handle onto
|
||||
another node to connect them (a choice node gains a new choice; dialogue and event nodes
|
||||
re-point their continuation).
|
||||
re-point their continuation). Use Expand to fill the screen (Esc to shrink).
|
||||
</p>
|
||||
|
||||
{contextMenu && (
|
||||
|
|
|
|||
Loading…
Reference in a new issue