1
0
Fork 0
polaris-task-force/src/components/frontend/intelligence/BriefingSqfExport.tsx
Z8MB1E f62f5265fa 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.
2026-10-20 14:22:17 -04:00

131 lines
4 KiB
TypeScript

"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<ExportMode>("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 (
<Dialog>
<DialogTrigger asChild>
{scope === "entry" ? (
<Button
variant="ghost"
size="icon"
className="size-7 shrink-0"
disabled={disabled}
title="Export this briefing entry as SQF"
aria-label="Export this briefing entry as SQF"
>
<ClipboardCopyIcon className="size-3.5" />
</Button>
) : (
<Button
variant="outline"
size="sm"
className="h-7 gap-1.5 px-2 text-xs"
disabled={disabled}
title="Copy this briefing as Arma 3 Structured Text"
>
<ClipboardCopyIcon className="size-3.5" />
SQF
</Button>
)}
</DialogTrigger>
<DialogContent className="sm:max-w-3xl">
<DialogHeader>
<DialogTitle>Export briefing to SQF</DialogTitle>
<DialogDescription>
{count} {count === 1 ? "section" : "sections"}
{missionName ? ` from "${missionName}"` : ""}. Bold, color, headings, lists, and quotes
are preserved where Arma 3 Structured Text supports them.
</DialogDescription>
</DialogHeader>
<Tabs value={mode} onValueChange={(value) => setMode(value as ExportMode)}>
<TabsList>
<TabsTrigger value="script">Diary script</TabsTrigger>
<TabsTrigger value="text">Structured text</TabsTrigger>
</TabsList>
</Tabs>
<Textarea
readOnly
value={preview}
spellCheck={false}
wrap="off"
aria-label="SQF preview"
className="h-72 resize-none font-mono text-xs leading-relaxed"
/>
<p className="text-xs text-muted-foreground">
Italic, strikethrough, subscript, and superscript have no Structured Text equivalent and
export as plain text. Images and links become readable placeholders.
</p>
<DialogFooter>
<Button onClick={() => void copy()}>
<ClipboardCopyIcon className="size-4" />
Copy SQF
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}