Repository navigation
feat(lab): expose transformers prop on RichTextEditor - #4416
Merged
potatowagon merged 3 commits intoJul 28, 2026
Merged
Conversation
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)
potatowagon
requested review from
cixzhang,
ejhammond and
imdreamrunner
as code owners
July 27, 2026 04:15
|
Deployment failed with the following error: View Documentation: https://vercel.com/docs/accounts/team-members-and-roles |
Contributor
PR Analysis ReportNo new or modified components detected. Bundle Size Summary
Accessibility AuditStatus: 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
approved these changes
Jul 27, 2026
nynexman4464
left a comment
Contributor
There was a problem hiding this comment.
Approve with nits. Defaults to Lexical's TRANSFORMERS, backward compatible. Good.
- Fix before landing:
[...transformers]re-allocates each render →MarkdownShortcutPluginre-registers every re-render. UseuseMemo(() => [...transformers], [transformers]). (Confirmed React Compiler isn't running the transform anywhere in the repo — onlyeslint-plugin-react-compileris installed, notbabel-plugin-react-compiler— so this isn't auto-memoized.) - Re-export
type Transformerfrom the lab barrel. - Tests cover rendering but not shortcut behavior.
— Reviewed with Navi on behalf of Alex Rock
- 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)
Contributor
Author
|
Thanks for the review! All three nits addressed in
Local: 20/20 lab tests pass, typecheck + lint clean. |
This was referenced Jul 29, 2026
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a
transformers?: ReadonlyArray<Transformer>prop to the experimentalRichTextEditor(@astryxdesign/lab), defaulting to the standard@lexical/markdownTRANSFORMERS.Why
The markdown transformer set was hardcoded to
TRANSFORMERS. Consumers who register custom nodes via the existingnodesextension 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'slexical-playground, where onePLAYGROUND_TRANSFORMERSarray feeds all three markdown operations:registerMarkdownShortcuts(editor, PLAYGROUND_TRANSFORMERS)(MarkdownShortcutsExtension/index.ts)$convertFromMarkdownString(..., PLAYGROUND_TRANSFORMERS, ...)(ActionsPlugin/index.tsx)$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→ AstryxRichTextEditorparity — low-risk and additive.How
transformersprop, defaults toTRANSFORMERS. Only applied to shortcut typing whenhasMarkdownShortcutsis true (the plugin already gated on that flag).MarkdownShortcutPlugin([...transformers]) since the plugin expects a mutable array while the prop isReadonlyArrayfor a safer public API.type Transformerfrom@lexical/markdown.doc.mjsspell out the single-source-of-truth intent (shortcuts / import / export) so later phases wire the same prop rather than re-hardcodingTRANSFORMERS.Docs / stories / tests (SYNC contract)
RichTextEditor.doc.mjs— addedtransformersto the props table; clarifiedhasMarkdownShortcuts.RichTextEditor.stories.tsx— added aCustomTransformersstory (restricted markdown: bold/italic/unordered-list only).RichTextEditor.test.tsx— added tests for a custom transformers array and forhasMarkdownShortcuts={false}.Testing
pnpm -F @astryxdesign/lab typecheck— cleaneslinton changed files — cleanvitest run RichTextEditor.test.tsx— 18/18 passing (incl. 2 new)human manual test
Screen.Recording.2026-07-27.at.4.13.18.PM.mov