Skip to content
SprecherEast
Issue 817

feat: "Figure" block for posts and events in Payload

Back to our plan
Done
enhancementfrontendcmsmigrationpriority: medium

Numbering: epic #813; banner #814; lightbox #815; figure #816; Payload block #817; blue tone #818; content edit #819; guidelines #820. Where the text below says 01 to 07, read these numbers (01=#815, 02=#816, 03=#817, 04=#819, 05=#814, 06=#818, 07=#820).

Problem

In plain words: the floated figure from 02 is only a component. Editors still need a way to add one, with its label, short caption, long caption and numbered key, from the post or event editor in Admin, without code.

Proposed fix

Use, configure or split (docs/guidelines/components-and-content.md):

  • mediaBlock (src/platform/richtext/blockConfigs.ts) has one field, media. It is also a page-builder block (SITE_LAYOUT_BLOCKS in src/modules/site/cms/layoutBlocks.ts).
  • Adding alignment, size, label, two captions and a key list to it would give page-builder editors fields that mean nothing there. It would also switch MediaBlock into another mode (inline float with lightbox versus section image). Both are "split" signs.
  • [DECISION] a new rich-text block, figure (interface FigureBlock). mediaBlock stays as it is.

Fields:

  • media (upload → media, required). Alt text comes from the media document, as today.
  • align: select right (default) | left | none
  • size: select with the values 02 defines (default from 02's answer). Each option's admin label says the share in words.
  • label: text, optional, maxLength about 24, for example "Figure 2-9". Admin description: "Shown as a small gray label. Leave empty if the figure has no number."
  • caption: text, required, short (maxLength about 140), shown under the small figure.
  • details: rich text (the same small editor as Banner.content), optional, shown only in the lightbox: credit, source and conditions.
  • items: the numbered key. It reuses the diagramKey item shape and validation (label/text row, validateLabel, minRows/maxRows, from src/platform/richtext/editorial/diagramKeyBlockConfig.ts). Export the field definition once and use it in both blocks. Don't copy it. Give the array an admin key (the isRowCollapsed gotcha in docs/project.md). Optional: a figure without markers has no key.

Wiring:

  • Add figure to the blocks posts offer (RICH_TEXT_BLOCKS) and the blocks events offer (EVENT_RICH_TEXT_BLOCKS).
  • Add a mapper toFigureProps (plain props for 02's Figure, decision 0013), next to toDiagramKeyProps (src/platform/richtext/editorial/diagramKey.ts), reusing its trailing-empty-row rule.
  • Add a renderer in src/platform/richtext/richTextBlocks.tsx.
  • Check that the article's text column treats figure as a reading-width block (src/platform/richtext/articleColumn.ts only widens for card rows, so no change is expected).
  • Run npx payload migrate:create (SQLite; review it for data safety), then npm run generate:types and commit src/payload-types.ts.

Existing Milwaukee Street map: today it is a mediaBlock followed by a diagramKey block in the post and in event 12. Moving it is a content edit (04), not a data migration, because only two documents use it. The schema migration only adds the new block's tables. Nothing existing is rewritten, so every stored post and event renders exactly as before.

Card and link preview (owner's standing rule): a picture on a post or page also appears on its card and link preview. The figure is body content and doesn't set the card image. The post or event's own image (heroImage, and meta.image for the link preview) does. The block's admin description says so. The acceptance criteria check that both pages already have a card and link-preview image, and the issue says which one.

Live content: this PR changes no live content. Any later edit in Admin first notes the document's current version on the issue (event 12: version 34, published 2026-10-31 22:11 Central), so it can be restored from the Versions tab.

Native-first check:

  • (1) Payload's BlocksFeature is the native way to put a structured block in Lexical, so we use it, as every editorial block does.
  • (1) Payload's Lexical UploadFeature (an inline upload node) has fields per upload, but no list of numbered key rows with our validation, and no front-end float or lightbox. It would need a custom converter anyway.
  • (2) No official plugin adds a figure block.
  • Conclusion: a block config plus our existing pieces.

Acceptance criteria

  • Not done: Tests come first: failing tests for the block config (fields, defaults, required, the key's admin key, the shared validateLabel), for toFigureProps (trailing empty rows dropped, middle rows kept), and for the renderer (renders Figure with the mapped props), then the code. payload.config.test.ts and richTextBlocks.test.tsx updated.
  • Not done: The key's field definition is defined once and used by both diagramKey and figure (no jscpd clone).
  • Not done: An editor can add a Figure in a post and in an event in Admin, with alignment, size, label, short caption, long caption and key. Live Preview shows it.
  • Not done: The migration adds only the new block's tables. It is reviewed for data safety, runs on a copy of the database, and existing posts and events render unchanged (checked on the I-94 post and event 12 locally with a copy of the data, if available).
  • Not done: src/payload-types.ts is regenerated and committed, and docs/reference/content-types/ is regenerated (Knowledge sync green).
  • Not done: An axe check passes on a seeded post with a figure, and the gallery's rich-text sample (RichTextGallery.tsx) shows one.
  • Not done: Both pages (the I-94 post, event 12) have a card and link-preview image. Which image is recorded on the issue. If one is missing, a [SCOPE] issue is filed (not widened here).
  • Not done: Checked at 320, 430, 768, 1024, 1280 and 1920 px in light and dark. Keyboard: Escape closes the lightbox, focus returns, and the key is readable in it.
  • Not done: Documentation follows behavior: docs/ui/data-types.md gets a figure row (block → component), the block list in docs/guidelines/payload-cms.md names figure (a fact, not a rule), and the events note src/modules/events/README.md mentions the block if it lists event content blocks.

Files likely touched

  • src/platform/richtext/blockConfigs.ts
  • new src/platform/richtext/editorial/figureBlockConfig.ts, figure.ts (mapper) and tests
  • src/platform/richtext/editorial/diagramKeyBlockConfig.ts (export the shared key field)
  • src/platform/richtext/richTextBlocks.tsx (+ test)
  • src/migrations/ (new migration + index.ts), src/payload-types.ts
  • src/app/(frontend)/dev/gallery/RichTextGallery.tsx, blocksPostSample.ts
  • docs/ui/data-types.md, docs/guidelines/payload-cms.md, docs/reference/content-types/ (generated)

Must not touch

  • src/modules/site/cms/layoutBlocks.ts and the page-builder mediaBlock (stays as is)
  • src/platform/ui/Figure.tsx internals (02), except a prop fix found while wiring, called out in the PR
  • Live content in Admin (04)

Area

cms, frontend, migration

Priority

priority: medium


Generated by Claude Code, opens in a new tab

See it on GitHub, opens in a new tab