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 + + + +