From f62f5265fa605c63f21d4d936afbdf70f46438bd Mon Sep 17 00:00:00 2001 From: Z8MB1E Date: Tue, 20 Oct 2026 14:22:17 -0400 Subject: [PATCH] feat(intelligence): export mission briefings to SQF Add a briefing export dialog with a diary script and a structured text array. Convert Lexical formatting, including bold, code, underline, colors, headings, lists, and quotes, into Arma Structured Text. Scope the shared color palette to the briefing editors and render colors on the mission page. --- .../intelligence/missions/[id]/page.tsx | 5 +- src/app/(payload)/admin/importMap.js | 2 + src/collections/intelligence/Missions.ts | 32 +- .../intelligence/BriefingSqfExport.tsx | 131 ++++++ .../intelligence/LexicalRichTextEditor.tsx | 5 +- .../intelligence/LexicalRichTextToolbar.tsx | 92 +++- .../intelligence/MissionBriefingSection.tsx | 44 +- .../intelligence/SideOpNarrativeFields.tsx | 1 + src/lib/intelligence/briefingConverters.tsx | 17 + src/lib/intelligence/briefingSqf.ts | 420 ++++++++++++++++++ tests/int/briefing-sqf.int.spec.ts | 250 +++++++++++ 11 files changed, 966 insertions(+), 33 deletions(-) create mode 100644 src/components/frontend/intelligence/BriefingSqfExport.tsx create mode 100644 src/lib/intelligence/briefingConverters.tsx create mode 100644 src/lib/intelligence/briefingSqf.ts create mode 100644 tests/int/briefing-sqf.int.spec.ts diff --git a/src/app/(frontend)/intelligence/missions/[id]/page.tsx b/src/app/(frontend)/intelligence/missions/[id]/page.tsx index 5eda5a0f..8325f1bd 100644 --- a/src/app/(frontend)/intelligence/missions/[id]/page.tsx +++ b/src/app/(frontend)/intelligence/missions/[id]/page.tsx @@ -512,7 +512,10 @@ export default async function MissionDetailPage({ params }: MissionDetailPagePro missionId={mission.id} /> - + return { or }; } +/** + * Briefings are the only field that exports to Arma Structured Text, so only + * this editor gets the color palette. Keeping it field-scoped avoids offering + * colors on rich text surfaces that do not render them. + */ +const briefingDetailsEditor = lexicalEditor({ + features: ({ defaultFeatures }) => [ + ...defaultFeatures, + FixedToolbarFeature(), + TextStateFeature({ + state: { + color: Object.fromEntries( + Object.entries(BRIEFING_TEXT_COLORS).map(([key, { hex, label }]) => [ + key, + { css: { color: hex }, label }, + ]), + ), + }, + }), + PayloadAiPluginLexicalEditorFeature(), + ], +}); + export const Missions: CollectionConfig = { slug: "missions", admin: { @@ -655,6 +678,7 @@ export const Missions: CollectionConfig = { name: "details", type: "richText", required: true, + editor: briefingDetailsEditor, }, ], defaultValue: [ diff --git a/src/components/frontend/intelligence/BriefingSqfExport.tsx b/src/components/frontend/intelligence/BriefingSqfExport.tsx new file mode 100644 index 00000000..6b717912 --- /dev/null +++ b/src/components/frontend/intelligence/BriefingSqfExport.tsx @@ -0,0 +1,131 @@ +"use client"; + +import { useMemo, useState } from "react"; +import { ClipboardCopyIcon } from "lucide-react"; +import { toast } from "sonner"; +import { Button } from "@/components/ui/button"; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog"; +import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs"; +import { Textarea } from "@/components/ui/textarea"; +import { + briefingEntryHasContent, + briefingToDiarySqf, + briefingToStructuredTextSqf, + type BriefingSqfEntry, +} from "@/lib/intelligence/briefingSqf"; + +type ExportMode = "script" | "text"; + +interface BriefingSqfExportProps { + entries: BriefingSqfEntry[]; + missionName?: string | null; + /** "all" is the header button; "entry" is the icon button on one card. */ + scope?: "all" | "entry"; +} + +export function BriefingSqfExport({ entries, missionName, scope = "all" }: BriefingSqfExportProps) { + const [mode, setMode] = useState("script"); + + const exportable = useMemo(() => entries.filter(briefingEntryHasContent), [entries]); + + const preview = useMemo( + () => + mode === "script" + ? briefingToDiarySqf(exportable, { missionName }) + : briefingToStructuredTextSqf(exportable), + [exportable, missionName, mode], + ); + + const disabled = exportable.length === 0; + const count = exportable.length; + + const copy = async () => { + try { + await navigator.clipboard.writeText(preview); + toast.success(`Copied ${count} briefing ${count === 1 ? "section" : "sections"} as SQF.`, { + description: + mode === "script" + ? "Paste into the debug console or an init script." + : "Structured Text bodies for your own diary or hint code.", + }); + } catch { + toast.error("Clipboard access was blocked by the browser."); + } + }; + + return ( + + + {scope === "entry" ? ( + + ) : ( + + )} + + + + Export briefing to SQF + + {count} {count === 1 ? "section" : "sections"} + {missionName ? ` from "${missionName}"` : ""}. Bold, color, headings, lists, and quotes + are preserved where Arma 3 Structured Text supports them. + + + + setMode(value as ExportMode)}> + + Diary script + Structured text + + + +