1
0
Fork 0
polaris-task-force/src/lib/lexical/richTextConverters.ts
Z8MB1E 34c0d5681f fix(rich-text): render full lexical formatting incl. colours across all fields
RichText authored in the admin panel was rendered as plain text on the
public site: headings/lists/quotes were flattened by Tailwind preflight
(no @tailwindcss/typography installed), and Payload's default JSX
converter ignored text colours.

- src/lib/lexical: shared editor factory (ptfLexicalEditor) + shared
  colour palette (textState) + colour converter (richTextConverters)
- RichTextView: canonical .lexical-content renderer (colour-aware),
  swapped into every frontend render site
- All rich-text editors route through the factory, so every field
  inherits the coloured editor (incl. the previously-unedited ones)
- .lexical-content CSS extended with checklist/table/heading rules,
  wrapped in @layer components so per-page utilities still override;
  dropped the now-dead per-page prose hacks
- Remove the now-dead briefingConverters in favour of the shared
  converter; add tests/int/rich-text-view.int.spec.ts
2026-11-18 13:10:26 -05:00

23 lines
1,001 B
TypeScript

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