Skip to content

feat(lab): expose transformers prop on RichTextEditor - #4416

Merged
potatowagon merged 3 commits into
meta:mainfrom
potatowagon:navi/feat/richtext-transformers
Jul 28, 2026
Merged

potatowagon merged 3 commits into
meta:mainfrom
potatowagon:navi/feat/richtext-transformers

Conversation

@potatowagon

@potatowagon potatowagon commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds a transformers?: ReadonlyArray<Transformer> prop to the experimental RichTextEditor (@astryxdesign/lab), defaulting to the standard @lexical/markdown TRANSFORMERS.

Why

The markdown transformer set was hardcoded to TRANSFORMERS. Consumers who register custom nodes via the existing nodes extension point had no way to add matching markdown transformers (for their custom node types) without forking the component.

Importantly, in Lexical the transformers array is the single source of truth for all markdown behaviour — not just shortcut typing. Verified against facebook/lexical's lexical-playground, where one PLAYGROUND_TRANSFORMERS array feeds all three markdown operations:

  • shortcut typing — registerMarkdownShortcuts(editor, PLAYGROUND_TRANSFORMERS) (MarkdownShortcutsExtension/index.ts)
  • markdown → state (import) — $convertFromMarkdownString(..., PLAYGROUND_TRANSFORMERS, ...) (ActionsPlugin/index.tsx)
  • state → markdown (export) — $convertToMarkdownString(PLAYGROUND_TRANSFORMERS, ...) (ActionsPlugin/index.tsx)

So this prop is deliberately introduced as that shared primitive. It wires shortcut typing today; the upcoming getMarkdown() / serializer APIs will read the same prop, so a consumer's custom transformers stay consistent across shortcuts, import, and export.

This is one of the general-purpose gaps identified for EPS RichTextArea → Astryx RichTextEditor parity — low-risk and additive.

How

  • New transformers prop, defaults to TRANSFORMERS. Only applied to shortcut typing when hasMarkdownShortcuts is true (the plugin already gated on that flag).
  • Spread into MarkdownShortcutPlugin ([...transformers]) since the plugin expects a mutable array while the prop is ReadonlyArray for a safer public API.
  • Imported type Transformer from @lexical/markdown.
  • JSDoc + doc.mjs spell out the single-source-of-truth intent (shortcuts / import / export) so later phases wire the same prop rather than re-hardcoding TRANSFORMERS.

Docs / stories / tests (SYNC contract)

  • RichTextEditor.doc.mjs — added transformers to the props table; clarified hasMarkdownShortcuts.
  • RichTextEditor.stories.tsx — added a CustomTransformers story (restricted markdown: bold/italic/unordered-list only).
  • RichTextEditor.test.tsx — added tests for a custom transformers array and for hasMarkdownShortcuts={false}.

Testing

  • pnpm -F @astryxdesign/lab typecheck — clean
  • eslint on changed files — clean
  • vitest run RichTextEditor.test.tsx — 18/18 passing (incl. 2 new)

human manual test

Screen.Recording.2026-07-27.at.4.13.18.PM.mov

Adds a `transformers?: ReadonlyArray<Transformer>` prop to the experimental
RichTextEditor, defaulting to the standard `@lexical/markdown` TRANSFORMERS.

Previously the markdown-shortcut transformer set was hardcoded, so consumers
who register custom nodes (via the `nodes` extension point) had no way to add
matching transformers without forking. This exposes the set as a prop, mirroring
the existing `nodes`/`plugins` extensibility pattern.

- transformers defaults to TRANSFORMERS; only applied when hasMarkdownShortcuts
- Updated RichTextEditor.doc.mjs props table
- Added CustomTransformers storybook story (restricted markdown set)
- Added unit tests (custom transformers array + shortcuts disabled)
@vercel

vercel Bot commented Jul 27, 2026

Copy link
Copy Markdown

Deployment failed with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: astryx.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 27, 2026
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Jul 27, 2026
@github-actions

github-actions Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.7KB 0B

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | View full report

… ops

Spell out that the transformers prop is the intended single source of truth
for all three Lexical markdown operations — shortcut typing (wired now),
markdown->state import, and state->markdown export (getMarkdown / serializer
APIs in later phases) — matching the lexical-playground reference where one
PLAYGROUND_TRANSFORMERS array feeds registerMarkdownShortcuts,
$convertFromMarkdownString, and $convertToMarkdownString.

Docs-only (JSDoc + doc.mjs); no behaviour change.

@nynexman4464 nynexman4464 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve with nits. Defaults to Lexical's TRANSFORMERS, backward compatible. Good.

  • Fix before landing: [...transformers] re-allocates each render → MarkdownShortcutPlugin re-registers every re-render. Use useMemo(() => [...transformers], [transformers]). (Confirmed React Compiler isn't running the transform anywhere in the repo — only eslint-plugin-react-compiler is installed, not babel-plugin-react-compiler — so this isn't auto-memoized.)
  • Re-export type Transformer from the lab barrel.
  • Tests cover rendering but not shortcut behavior.

— Reviewed with Navi on behalf of Alex Rock

@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Jul 27, 2026
- Memoize transformers array so MarkdownShortcutPlugin doesn't re-register every render
- Re-export type Transformer from the lab barrel
- Add shortcut-behavior tests (markdown -> heading conversion, empty transformers no-op)
@potatowagon

Copy link
Copy Markdown
Contributor Author

Thanks for the review! All three nits addressed in ce887f5:

  1. Re-registration — MarkdownShortcutPlugin now takes a useMemo(() => [...transformers], [transformers]) value instead of a fresh [...transformers] per render, so it no longer re-registers on every re-render. (Confirmed the same as your note — no babel-plugin-react-compiler in the tree, so nothing was auto-memoizing this.)
  2. Barrel export — type Transformer is now re-exported from @astryxdesign/lab (via RichTextEditor/index.ts and the top-level barrel), so consumers can type custom transformer arrays without reaching into @lexical/markdown.
  3. Shortcut behavior — added two behavioral tests: the default TRANSFORMERS convert # Title into a heading node, and an empty transformers array leaves it as a plain # Title paragraph. Drives $convertFromMarkdownString through the mounted editor since jsdom can't dispatch the live keystrokes.

Local: 20/20 lab tests pass, typecheck + lint clean.

@potatowagon
potatowagon merged commit faa200a into meta:main Jul 28, 2026
17 of 18 checks passed
potatowagon added a commit to potatowagon/astryx that referenced this pull request Jul 30, 2026
Adds `getMarkdown()` to the RichTextEditorRef handle. Serializes the current
content to a Markdown string via $convertToMarkdownString, run inside a read
context.

Honors the same `transformers` the editor is configured with (the prop added
in meta#4416), so custom transformers round-trip to Markdown — mirroring the
Lexical playground, where one transformer array feeds shortcut typing, import,
and export. The bridge now receives the memoized transformers array.

`@lexical/markdown` is a subpackage (built dist), so this adds no top-level
`lexical` value import — keeping the sandbox build safe.

- Extended RichTextEditorRef + EditorRefBridge
- Updated doc.mjs ref best-practice note
- Added getMarkdown() button to the ImperativeRef storybook story
- Added 3 unit tests (plain text, heading with default transformers, and
  custom empty-transformers set proving the prop is honored)

Depends on the merged ref API (meta#4417) and transformers prop (meta#4416).
potatowagon added a commit that referenced this pull request Jul 30, 2026
* feat(lab): add getMarkdown() to RichTextEditor imperative ref

Adds `getMarkdown()` to the RichTextEditorRef handle. Serializes the current
content to a Markdown string via $convertToMarkdownString, run inside a read
context.

Honors the same `transformers` the editor is configured with (the prop added
in #4416), so custom transformers round-trip to Markdown — mirroring the
Lexical playground, where one transformer array feeds shortcut typing, import,
and export. The bridge now receives the memoized transformers array.

`@lexical/markdown` is a subpackage (built dist), so this adds no top-level
`lexical` value import — keeping the sandbox build safe.

- Extended RichTextEditorRef + EditorRefBridge
- Updated doc.mjs ref best-practice note
- Added getMarkdown() button to the ImperativeRef storybook story
- Added 3 unit tests (plain text, heading with default transformers, and
  custom empty-transformers set proving the prop is honored)

Depends on the merged ref API (#4417) and transformers prop (#4416).

* chore: re-trigger CI/Vercel deployment
potatowagon added a commit to potatowagon/astryx that referenced this pull request Jul 31, 2026
Adds two headless helpers to the RichTextEditor surface:
  - markdownToEditorStateJSON(markdown, opts?) -> serialized EditorState JSON
    (drop-in for the editor's `defaultValue`)
  - editorStateJSONToMarkdown(json, opts?)      -> Markdown string

Unlike the ref's getMarkdown(), these need NO mounted editor — they spin up a
headless Lexical editor (@lexical/headless) and run
$convertFromMarkdownString / $convertToMarkdownString. Useful for producing a
`defaultValue` from Markdown on the server, or serializing saved state to
Markdown off-screen.

Both accept the same { transformers, nodes } the editor uses, so custom
transformers/nodes round-trip consistently (mirrors the transformers-as-single-
source-of-truth model from meta#4416).

- Extracted DEFAULT_NODES into a shared editorNodes.ts (used by the editor and
  the serializers so both register the same nodes).
- Added @lexical/headless as a new OPTIONAL peer dep.
- `lexical` imports stay type-only (no top-level value import) — sandbox-safe.
- Exported from RichTextEditor/index.ts + lab barrel.
- Updated doc.mjs usage notes; added 5 unit tests (heading parse, round-trip,
  custom empty-transformers, defaultValue consumption).
potatowagon added a commit that referenced this pull request Jul 31, 2026
…#4544)

* feat(lab): add standalone Markdown <-> EditorState serializers

Adds two headless helpers to the RichTextEditor surface:
  - markdownToEditorStateJSON(markdown, opts?) -> serialized EditorState JSON
    (drop-in for the editor's `defaultValue`)
  - editorStateJSONToMarkdown(json, opts?)      -> Markdown string

Unlike the ref's getMarkdown(), these need NO mounted editor — they spin up a
headless Lexical editor (@lexical/headless) and run
$convertFromMarkdownString / $convertToMarkdownString. Useful for producing a
`defaultValue` from Markdown on the server, or serializing saved state to
Markdown off-screen.

Both accept the same { transformers, nodes } the editor uses, so custom
transformers/nodes round-trip consistently (mirrors the transformers-as-single-
source-of-truth model from #4416).

- Extracted DEFAULT_NODES into a shared editorNodes.ts (used by the editor and
  the serializers so both register the same nodes).
- Added @lexical/headless as a new OPTIONAL peer dep.
- `lexical` imports stay type-only (no top-level value import) — sandbox-safe.
- Exported from RichTextEditor/index.ts + lab barrel.
- Updated doc.mjs usage notes; added 5 unit tests (heading parse, round-trip,
  custom empty-transformers, defaultValue consumption).

* feat(storybook): add Markdown serializers playground for RichTextEditor

* fix(storybook): resolve @lexical/headless for Markdown serializers playground

The Markdown serializers playground story imports markdownToEditorStateJSON /
editorStateJSONToMarkdown from @astryxdesign/lab, whose markdownSerializers
module imports createHeadlessEditor from @lexical/headless. Because the lab is
aliased to its TS source in the storybook Vite config and @lexical/headless is
declared as an OPTIONAL peer of the lab, Vite's optional-peer-dep resolver
stubbed the module with a throwing shim ("does not provide an export named
'createHeadlessEditor'").

Declare @lexical/headless and @lexical/markdown as direct devDependencies of
the storybook app so Vite pre-bundles the real packages and resolves the
serializer imports to them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants