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; }, }; };