feat(richtext-lexical): add custom component support to LinkJSXConverter and UploadJSXConverter#15577
Open
tobiasvdorp wants to merge 2 commits intopayloadcms:mainfrom
Conversation
…ter and UploadJSXConverter Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Summary
Adds support for passing custom
LinkComponentandImageComponentintoLinkJSXConverterandUploadJSXConverter, so Next.js apps (and other frameworks) can use their ownLinkandImagewithout copying the full converter logic into their project.Problem
LinkJSXConverterhardcodes<a>with no option for a custom link component (e.g.next/link).UploadJSXConverterhardcodes<a>and<img>with no option fornext/imageor other framework components.Changes
LinkJSXConverter— Added optionalLinkComponentprop:<a>for bothautolinkandlinknodeshref,rel,target, andchildreninternalDocToHrefcontinues working as beforeUploadJSXConverter— Converted from static object to function with optional parameters:ImageComponent— Custom component for<img>elements (images without sizes + fallback inside<picture>)LinkComponent— Custom component for non-image file linksbuildFullUrl— Transforms upload paths into absolute URLs (e.g. for CDN/cloud storage)UploadJSXConverter()with no arguments produces identical behavior to beforeUploadJSXConverteras an object (...UploadJSXConverter) must update to...UploadJSXConverter()defaultConverters.ts— Updated to call...UploadJSXConverter().Documentation — Added a "Custom Components" section to
docs/rich-text/converting-jsx.mdxwith Next.js examples forLinkComponent,ImageComponent, andbuildFullUrl.Example usage
Test plan
LinkJSXConverter({})still works (noLinkComponent) — renders<a>LinkJSXConverter({ LinkComponent: ... })renders the custom component for both autolink and link nodesUploadJSXConverter()with no args produces same output as beforeUploadJSXConverter({ ImageComponent, LinkComponent, buildFullUrl })uses custom components and URL transformationdefaultJSXConvertersstill works unchanged for consumersbuildFullUrlis applied to both the main image URL and all size URLs inside<picture>