The body editor painted highlighted markdown in a div behind a transparent-text textarea, so the painted text and the caret were two different layout engines. Any wrap-point difference (borders, scrollbar gutters, engine rounding, trailing newlines) shifted the overlay by whole lines once content soft-wrapped, making clicks land on the wrong glyph and the document end feel unreachable. The CSS patch that preceded this reduced the drift but could not remove the class of bug. CodeMirror 6 owns text and caret together, so the failure mode is gone by construction rather than by maintenance. The body remains a markdown string, so prepareMarkdown, ::: directives, wikilinks, templates, revisions and the preview pipeline are untouched, with no data migration. - WikiMarkdownEditor: EditorView lifecycle, theme and markdown HighlightStyle bound to the app's CSS tokens, history, line wrapping, IME-safe keymap. - markdownCommands: one pure command table shared by toolbar buttons and keys. - editorChange: toolbar updates dispatch only the differing span, keeping undo granular and selections outside the edit intact. - Removes WikiEditorHighlightLayer, editorMetrics, lib/wiki/editorHighlight, useEditorHistory and the now-dead textarea selection reader. - Adds e2e proof: glyph-precise clicks across wrapped paragraphs, list items, image markdown and scrolled documents land at the exact clicked offset. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
11 KiB
AGENTS.md — Frontend Components
Parent:
../../AGENTS.md— commands, auth flow, Next.js 16 rules, deployment.
Overview
100+ client components organized by domain. The (frontend) layout renders guests LandingPage (no app shell); authed users get AppSidebar + SiteHeader + CommandPalette.
Structure
components/frontend/
auth/ 2 files LoginForm, LoginLink (returnTo via usePathname)
account/ 16 files Profile, password, preferences, Discord link
awards/ 4 files Medal/ribbon display, award dialogs
banking/ 9 files Account cards, ledger, deposit/withdraw/transfer dialogs
baseManagement/ 4 files StaffRoster, HireStaffDialog, EmploymentCard, UpgradeCard (structure page)
blocks/ 7 files AppSidebar (data in sidebarData.ts), NavCore, NavUser, XPDisplay
dashboard/ 6 files ProfileSummary, QuickStats, MissionBriefing, RecentEvents
eod/ 4 files Minefield Clearance minigame
evaluations/ 0 files EMPTY directory (placeholder — no components yet)
flappy/ 4 files Flight Simulator canvas game, leaderboard, sounds
helpdesk/ 8 files Ticket list/detail, create dialog, timeline
impersonation/ 2 files Admin impersonation banner/controls
intelligence/ 17 files Mission cards/attendance/comms, campaign/faction cards
locker/ 13 files Grid, equipment editor, loadouts, wardrobe
logistics/ 8 files Shipment cards/actions, toast notifications
market/ 10 files Listing cards, negotiation flow, NPC chat, patience meter
notifications/ 2 files Bell (polling), inbox page
personnel/ 3 files NpcDirectory, NpcCard, NpcProfile (/personnel/contacts)
profile/ 3 files Profile page components (incl. rating dialog)
projects/ 12 files Jira-like boards, releases, sprints
qualification/ 6 files Aim trainer arena/game/canvas/leaderboard, sounds
radio/ 5 files Radio Traffic game, message generator, leaderboard
realtime/ 1 file GameTickRealtime (SSE -> router.refresh)
roster/ 1 file Org chart view
session/ 1 file Session expiry UI (pairs with useSessionExpired hook)
shims/ 1 file Frontend shim renderer
storage/ 14 files Structure grid, storage dialogs, event ledger
transfers/ 7 files Assignment transfer request/decision UI
wiki/ 11 files Index, editor + toolbar, content renderer, revisions, standards dialog
+ root files: LandingPage.tsx, SiteHeader.tsx, ClientDate.tsx, PayloadButtons.tsx
Conventions
Server → Client data flow
Pages are server components that fetch via getPayload(), then pass data as props to client components. Client components receive typed props and never call Payload directly.
Item compound component
storage/ uses a compound <Item> component for grid cells with slots: <Item.Slot name="icon">, <Item.Slot name="stats">, <Item.Menu>. Attachments render as stacked badges on the grid cell; popover shows full detail on hover.
Rich-text rendering
Front-end surfaces render serialized Lexical with the shared RichTextView (src/components/frontend/RichTextView.tsx): it applies .lexical-content typography and paints saved text colours (TextStateFeature state or inline styles), both of which Payload's default JSX renderer drops. Briefings render through this component too (mission briefing sections use it directly). Editors come from ptfLexicalEditor() (src/lib/lexical/editor.ts) so every rich-text field gets the fixed toolbar + colour palette by default.
Wiki body editor
/wiki/new and the edit route render WikiMarkdownEditor (src/components/frontend/wiki/WikiMarkdownEditor.tsx), a CodeMirror 6 markdown editor over the page's plain markdown string; the body field stays markdown, so prepareMarkdown, templates, ::: directives, wikilinks and the preview pipeline are untouched. Do NOT reintroduce a mirrored overlay (a highlighted <div> behind a transparent <textarea>) or a custom textarea metrics contract: the caret and the painted text must be the same engine, otherwise soft-wrapped lines drift apart by a line or more and clicks land on the wrong glyph. Toolbar buttons, the editor keymap and tests all call the pure commands in markdownCommands.ts (built on src/lib/wiki/editorFormatting.ts), and toolbar edits dispatch only the minimal changed span (src/lib/wiki/editorChange.ts) so history stays granular.
SSE consumers
GameTickRealtimemounts in(frontend)/layout.tsxfor all authed users.ShipmentToastsmounts only for logistics-qualified users.- Both use
useGameTick()hook (customptf:game-tickevent dispatch).
Nested dialogs
Market negotiation uses MakeOfferDialog nested inside ListingCard dialog. Loadout editor uses EquipmentEditorDialog nested inside locker grid. When a parent dialog unmounts (e.g., sold listing), the child stays visible for 3.5s minimum via useNow() hook for readability before refresh.
Route anomalies
logistics/vehicles/VehiclesList.tsx is a client component placed directly in the route directory (not under components/frontend/). This is the only route with an inline component file.
Personnel (NPC directory)
/personnel/contacts— NPC directory overgame-npcs(src/components/frontend/personnel/:NpcDirectory,NpcCard);/personnel/contacts/[id]— NPC profile (faction, in-game vs generated badges, vendor listings,NpcProfile)./personnel/statistics— theater-wide NPC stats: faction distribution, in-game vs generated counts, vendor stall count, top 5 vendors by active auto listings.- Sidebar entries live in
src/components/frontend/blocks/sidebarData.ts(nav data extracted fromAppSidebar).
Tactical dossier style (Battlefield-style UI)
An approved militaristic/intel-interface style for feature surfaces. The user (Jason) likes it a lot. Reference implementation: the official campaign cards (v0.2.27):
- Component:
src/components/frontend/intelligence/CampaignCard.tsx(official variant,size="lg"; community cards keep the conventional style for contrast) - Effects CSS:
src/app/(frontend)/styles.css(.glitch-hover,.glitch-ghost,.glitch-shard-a/b/c,.glitch-soft,.glitch-soft-late,.glitch-ghost-img-a/b+ their keyframes; trust the file for current values, the list here describes intent)
The recipe (each piece is separable; use subsets, do not feel obliged to use all):
- Classification strip: full-width top bar (
bg-black/50 backdrop-blur-sm border-b border-white/15), 9pxfont-mono uppercase tracking-widest text-white/60labels at both ends (e.g.OFFICIAL // UNIT COMMANDleft, a deterministicREF ###derived from the record id right). - Corner brackets: four 1px
white/25L-marks inset from the edges (inset-2,size-3, per-corner border sides), brightening towhite/60on hover.pointer-events-none+aria-hidden. - Squared corners:
rounded-noneon the tactical surface only; sibling/secondary surfaces keeprounded-lg. The contrast is deliberate. - Military status language: squared pill (
rounded-sm) or plain colored text, uppercase relabels (e.g. Concept → Planning, In Progress → Active Deployment, Completed → Concluded). The status color renders as text (text-blue-400/text-emerald-400/text-muted-foreground); do not duplicate status in two places on one card. - Readout footer: a permanent (not hover-only) single-line bar (
border-t border-white/15 bg-black/60 py-1.5 backdrop-blur-sm), cellsflex-1separated by hairlineborder-r border-white/15, each cell afont-mono text-xs tabular-nums text-white/80value plus a 9px uppercasetext-white/50label (e.g.3 MSNS,4h 0m DURATION). No owner/DIR cell unless the user wants it. - Darkened cover imagery: image at
opacity-15(hover 25) under a heavy gradient (from-black/85 via-black/60 to-black/25) so text stays readable. - Faint grid texture: 1px white grid lines, 28px cells,
opacity-[0.04]. Constant opacity: it does NOT brighten on hover (only borders/brackets/imagery highlight). - One-shot glitch hover (only with explicit user opt-in; it is extra motion): every layer fires instantly at 0% then decays; steps-based chaos only in the first ~15-20% of the animation; title/soft text restore to readable within ~25-35%; chromatic aberration via paired cyan/rose
text-shadow; title shards are duplicated absolutely-positionedaria-hiddenspans clipped by slantedclip-pathpolygons (cyan#22d3ee, rose#f43f5e, white); image tears use two ghost<img>copies clipped to horizontal bands so pieces shift but nothing ever disappears (never animateopacity: inheriton an image, it flashes to full brightness). Image band decay may run longer (2s) than text (1s). Everything is one-shot (noinfinite) and fully disabled underprefers-reduced-motion.
Where it fits: large feature/hero cards, section headers, showcase surfaces. Where it does not: dense data UI, tables, forms, dialogs, buttons, or anything shadcn-styled (the root guide's shadcn rule still governs those). Consistency rule: within one page, secondary surfaces stay conventional so the tactical surface stands out.
Protocol: offer, demo, or default (MANDATORY)
Whenever creating a new component or refactoring an existing component's styling, ask the user whether they want to try applying the tactical dossier style to it. Concretely:
- Yes: demo similar styling on that component first (same approach as the campaign cards: build it, let the user eyeball it, iterate on tuning).
- No, or no answer: stick with the existing styling conventions (shadcn + the site's dark theme conventions). Do not apply tactical styling unasked, and do not nag: ask once, then proceed either way.
Where to look
| Task | Path |
|---|---|
| Add a new page | src/app/(frontend)/<domain>/page.tsx + create client component here |
| Add nav entry | src/components/frontend/blocks/sidebarData.ts (nav data extracted from AppSidebar) |
| Modify auth gate | src/app/(frontend)/layout.tsx (conditional renders LandingPage or shell) |
| Add SSE consumer | src/hooks/useGameTick.ts + mount in layout |
| NPC dialogue/chatter | src/lib/market/npcDialogue.ts (pure, client-safe import) |
| Minigame game rules | src/lib/aim-trainer.ts etc. — pure libs, components consume them |
| Keyboard shortcuts | src/components/command-palette/ |
| Admin custom fields | src/components/admin/ (awards designers, CollapsibleGroupField, narrative-flow, shims) |
| Render Lexical rich text | src/components/frontend/RichTextView.tsx (shared) + src/lib/lexical/ (editor factory, colour palette) |
Anti-patterns
- NEVER call
getPayload()in client components — fetch in server page, pass as props - NEVER add
useRouter().refresh()in SSE consumers without a guard — use theuseGameTick()hook - NEVER use shadcn defaults for dark theme — the admin panel's theme handles styling
- NEVER place server-side logic (hooks, Payload calls) in
"use client"files