Your response has been recorded. Thank you!
@@ -122,8 +122,8 @@ export function SurveyForm({
{fields.map((field, index) => {
if (field.blockType === "message") {
return field.message ? (
-
-
+
+
) : null;
}
diff --git a/src/components/frontend/techTree/TechDetailDialog.tsx b/src/components/frontend/techTree/TechDetailDialog.tsx
index 7d0b5162..a3f3be02 100644
--- a/src/components/frontend/techTree/TechDetailDialog.tsx
+++ b/src/components/frontend/techTree/TechDetailDialog.tsx
@@ -1,6 +1,6 @@
"use client";
-import { RichText } from "@payloadcms/richtext-lexical/react";
+import { RichTextView } from "@/components/frontend/RichTextView";
import React from "react";
import { Badge } from "@/components/ui/badge";
@@ -56,7 +56,7 @@ export function TechDetailDialog({
{detail.description ? (
-
+
) : null}
diff --git a/src/lib/intelligence/briefingConverters.tsx b/src/lib/intelligence/briefingConverters.tsx
deleted file mode 100644
index 8d0a3ed9..00000000
--- a/src/lib/intelligence/briefingConverters.tsx
+++ /dev/null
@@ -1,17 +0,0 @@
-import type { JSXConvertersFunction } from "@payloadcms/richtext-lexical/react";
-import { briefingTextColor } from "./briefingSqf";
-
-/**
- * Payload's default text converter ignores both TextStateFeature state and the
- * inline `style` string, so briefing colors would silently disappear on the
- * page. Wrap the default converter in a colored span when the node has one.
- */
-export const briefingConverters: JSXConvertersFunction = ({ defaultConverters }) => ({
- ...defaultConverters,
- text: (args) => {
- const base = defaultConverters.text;
- const rendered = typeof base === "function" ? base(args) : null;
- const color = briefingTextColor(args.node);
- return color && rendered !== null ?
{rendered} : rendered;
- },
-});
diff --git a/src/lib/lexical/editor.ts b/src/lib/lexical/editor.ts
new file mode 100644
index 00000000..69bf6c5c
--- /dev/null
+++ b/src/lib/lexical/editor.ts
@@ -0,0 +1,22 @@
+/**
+ * The single factory behind every rich-text editor in the app. Use it for the global
+ * payload.config `editor` and for any field-scoped editor, so "full formatting including
+ * colours" is guaranteed everywhere instead of being assembled per-field by hand.
+ *
+ * Bundled features: Payload defaults + fixed toolbar + the shared text-colour palette
+ * (TextStateFeature) + the AI writing assistant (@ai-stack/payloadcms).
+ */
+import { PayloadAiPluginLexicalEditorFeature } from "@ai-stack/payloadcms";
+import { FixedToolbarFeature, lexicalEditor, TextStateFeature } from "@payloadcms/richtext-lexical";
+import { PTF_TEXT_STATE_CONFIG } from "./textState";
+
+export function ptfLexicalEditor() {
+ return lexicalEditor({
+ features: ({ defaultFeatures }) => [
+ ...defaultFeatures,
+ FixedToolbarFeature(),
+ TextStateFeature(PTF_TEXT_STATE_CONFIG),
+ PayloadAiPluginLexicalEditorFeature(),
+ ],
+ });
+}
diff --git a/src/lib/lexical/richTextConverters.ts b/src/lib/lexical/richTextConverters.ts
new file mode 100644
index 00000000..deb81651
--- /dev/null
+++ b/src/lib/lexical/richTextConverters.ts
@@ -0,0 +1,23 @@
+import { createElement } from "react";
+import type { JSXConvertersFunction } from "@payloadcms/richtext-lexical/react";
+import { resolveLexicalTextColor } from "./textState";
+
+/**
+ * Shared front-end colour converter for serialized Lexical.
+ *
+ * Payload's default text converter ignores both TextStateFeature state (`$: { color }`) and
+ * inline `style` colours, so authored colours would silently vanish on the public site. This
+ * wraps the default output in a styled span when a resolvable colour is present. Used by
+ * `RichTextView` on every field, including mission briefings.
+ */
+export const richTextConverters: JSXConvertersFunction = ({ defaultConverters }) => {
+ const base = defaultConverters.text;
+ return {
+ ...defaultConverters,
+ text: (args) => {
+ const rendered = typeof base === "function" ? base(args) : null;
+ const color = resolveLexicalTextColor(args.node);
+ return color ? createElement("span", { style: { color } }, rendered) : rendered;
+ },
+ };
+};
diff --git a/src/lib/lexical/textState.ts b/src/lib/lexical/textState.ts
new file mode 100644
index 00000000..ef42b9a3
--- /dev/null
+++ b/src/lib/lexical/textState.ts
@@ -0,0 +1,34 @@
+/**
+ * Shared colour support for every Lexical rich-text field.
+ *
+ * The palette originated as the Arma briefing colour set (its keys are persisted inside
+ * mission briefing JSON), which is why the source of truth lives in lib/intelligence/briefingSqf.
+ * Re-exported here so any rich-text surface edits AND renders the same palette: a colour picked
+ * in one field survives export to the front-end render path instead of silently dropping.
+ */
+import { BRIEFING_TEXT_COLORS, briefingTextColor } from "@/lib/intelligence/briefingSqf";
+
+/**
+ * Config passed to TextStateFeature so admin editors get the colour dropdown.
+ * Kept as data (not inline at each editor) so every lexicalEditor built through
+ * ptfLexicalEditor shares identical state keys.
+ */
+export const PTF_TEXT_STATE_CONFIG: {
+ state: { color: Record
};
+} = {
+ state: {
+ color: Object.fromEntries(
+ Object.entries(BRIEFING_TEXT_COLORS).map(([key, { hex, label }]) => [
+ key,
+ { css: { color: hex }, label },
+ ]),
+ ),
+ },
+};
+
+/**
+ * Resolve a serialized Lexical text node to its display colour: inline `style` strings first
+ * (e.g. pasted colours), then the TextStateFeature state key, then named colours.
+ * Returns null when the node carries no colour.
+ */
+export const resolveLexicalTextColor = briefingTextColor;
diff --git a/src/payload.config.ts b/src/payload.config.ts
index 67d275b4..ec886f12 100644
--- a/src/payload.config.ts
+++ b/src/payload.config.ts
@@ -1,6 +1,6 @@
import { migrations } from "./migrations";
import { postgresAdapter } from "@payloadcms/db-postgres";
-import { FixedToolbarFeature, lexicalEditor } from "@payloadcms/richtext-lexical";
+import { ptfLexicalEditor } from "@/lib/lexical/editor";
import { nodemailerAdapter } from "@payloadcms/email-nodemailer";
import path from "path";
import { buildConfig, formatLabels } from "payload";
@@ -112,7 +112,7 @@ import { PromotionNominations } from "@/collections/users/PromotionNominations";
import { LeadershipTransfers } from "@/collections/users/LeadershipTransfers";
import { requirePermission } from "@/utils/access-control/hasPermission";
import { scopedAdminPageAccess } from "@/utils/access-control/divisionAccess";
-import { payloadAiPlugin, PayloadAiPluginLexicalEditorFeature } from "@ai-stack/payloadcms";
+import { payloadAiPlugin } from "@ai-stack/payloadcms";
import type { SeedPromptFunction } from "@ai-stack/payloadcms/types";
import { mcpPlugin } from "@payloadcms/plugin-mcp";
import { formBuilderPlugin } from "@payloadcms/plugin-form-builder";
@@ -511,11 +511,7 @@ export default buildConfig({
},
globals: [GameRules, Shims, MinigameRules, DiscordPresence],
collections: scopedCollections,
- editor: lexicalEditor({
- features: ({ defaultFeatures }) => {
- return [...defaultFeatures, FixedToolbarFeature(), PayloadAiPluginLexicalEditorFeature()];
- },
- }),
+ editor: ptfLexicalEditor(),
secret: process.env.PAYLOAD_SECRET || "",
typescript: {
outputFile: path.resolve(dirname, "payload-types.ts"),
diff --git a/tests/int/briefing-sqf.int.spec.ts b/tests/int/briefing-sqf.int.spec.ts
index 386057c9..5444a858 100644
--- a/tests/int/briefing-sqf.int.spec.ts
+++ b/tests/int/briefing-sqf.int.spec.ts
@@ -2,7 +2,7 @@ import { createElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { RichText } from "@payloadcms/richtext-lexical/react";
import { describe, expect, it } from "vitest";
-import { briefingConverters } from "@/lib/intelligence/briefingConverters";
+import { richTextConverters } from "@/lib/lexical/richTextConverters";
import {
briefingEntryHasContent,
briefingEntryToStructuredText,
@@ -209,7 +209,7 @@ describe("briefing Structured Text conversion", () => {
};
const html = renderToStaticMarkup(
- createElement(RichText, { data: data as never, converters: briefingConverters }),
+ createElement(RichText, { data: data as never, converters: richTextConverters }),
);
expect(html).toMatch(/Red alert<\/strong><\/span>/);
diff --git a/tests/int/rich-text-view.int.spec.ts b/tests/int/rich-text-view.int.spec.ts
new file mode 100644
index 00000000..9ef8deaf
--- /dev/null
+++ b/tests/int/rich-text-view.int.spec.ts
@@ -0,0 +1,93 @@
+import { describe, expect, it } from "vitest";
+import { createElement } from "react";
+import { renderToStaticMarkup } from "react-dom/server";
+import { RichTextView } from "@/components/frontend/RichTextView";
+
+/**
+ * Guards the shared Lexical front-end render path: the .lexical-content typography hook,
+ * every structural node type, and author-chosen colours (inline `style`, top-level `color`,
+ * or TextStateFeature `$` state) must survive into rendered HTML. Payload's default JSX
+ * converters drop the colour keys, so this component exists only for that; if it ever regresses
+ * to plain , colours silently disappear on every field again.
+ */
+
+const richText = (nodes: unknown[]) => ({ root: { type: "root", children: nodes } });
+const paragraph = (...children: unknown[]) => ({ type: "paragraph", children });
+const heading = (tag: string, text: string) => ({ type: "heading", tag, children: [{ type: "text", text }] });
+// Payload's default JSX converter derives the marker class from `listType`
+const bullet = (tag: "ul" | "ol", listType: string, ...items: string[]) => ({
+ type: "list",
+ tag,
+ listType,
+ children: items.map((t) => ({ type: "listitem", value: 1, children: [{ type: "text", text: t }] })),
+});
+const quote = (...children: unknown[]) => ({ type: "quote", children });
+
+const describeRender = (doc: unknown) => renderToStaticMarkup(createElement(RichTextView, { data: doc as never }));
+
+describe("RichTextView shared render path", () => {
+ it("applies .lexical-content exactly once and drops the default payload-richtext wrapper", () => {
+ const html = describeRender(richText([paragraph({ type: "text", text: "hi" })]));
+ expect(html).toContain('class="lexical-content"');
+ expect(html.match(/lexical-content/g)).toHaveLength(1);
+ expect(html).not.toContain("payload-richtext");
+ });
+
+ it("keeps structural elements intact instead of flattening them to spans", () => {
+ const html = describeRender(
+ richText([
+ heading("h2", "Title"),
+ paragraph(
+ { type: "text", format: 1, text: "strong bit" },
+ { type: "text", format: 2, text: " italic" },
+ ),
+ bullet("ul", "bullet", "alpha", "beta"),
+ bullet("ol", "number", "one"),
+ quote(paragraph({ type: "text", text: "cited" })),
+ { type: "horizontalrule" },
+ ]),
+ );
+ for (const fragment of [
+ "Title
",
+ "strong bit",
+ " italic",
+ "",
+ "
",
+ ]) {
+ expect(html).toContain(fragment);
+ }
+ });
+
+ it("renders the colour stored as an inline style string on a text node", () => {
+ const html = describeRender(richText([paragraph({ type: "text", style: "color:#4ade80;", text: "green" })]));
+ expect(html).toContain('style="color:#4ade80"');
+ });
+
+ it("maps palette keys from `$` state and `color` to the shared briefing hexes", () => {
+ for (const node of [
+ { type: "text", $: { color: "blue" }, text: "s" },
+ { type: "text", color: "blue", text: "c" },
+ ]) {
+ const html = describeRender(richText([paragraph(node)]));
+ expect(html).toContain('style="color:#60a5fa"');
+ }
+ });
+
+ it("leaves uncoloured and unknown-colour nodes without an injected style span", () => {
+ const html = describeRender(
+ richText([
+ paragraph(
+ { type: "text", format: 1, text: "plain strong" },
+ { type: "text", style: "color:magenta;", text: " not-in-palette" },
+ ),
+ ]),
+ );
+ expect(html).not.toMatch(/style=/);
+ // magenta is a named colour outside our palette and must be dropped rather than emitted raw
+ expect(html).toContain("not-in-palette");
+ });
+});