Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendering custom elements #9

Open
benjick opened this issue Jun 7, 2024 · 2 comments
Open

Rendering custom elements #9

benjick opened this issue Jun 7, 2024 · 2 comments

Comments

@benjick
Copy link

benjick commented Jun 7, 2024

Hello.

Sorry, maybe this is out of scope. I'm using this renderer for other Lexical content as well (not through payload) and it works great.

But now I want to add a custom block type to Lexical, it looks like this:

{
    "detail": 0,
    "format": 0,
    "mode": "normal",
    "style": "",
    "text": "The Old Man and the Sea was published in 1952 and the author is Ernest Hemingway.",
    "type": "highlighted-text",
    "version": 1,
    "color": "yellow"
}

Is it possible to render that lexical node with this library? I tried doing it like this:

<PayloadLexicalReactRenderer
  content={JSON.parse(lexical) as PayloadLexicalReactRendererContent}
  elementRenderers={{
    ...defaultElementRenderers,
    "highlighted-text": (
      props: TextNode & {
        color: HighlightedColor;
      },
    ) => {
      return <p className={cn(colorMap[props.color])}>{props.text}</p>;
    },
  }}
/>

But I only get an error: TypeError: i is undefined

I understand if it's out of scope, wanted to check because this is the most reliable Lexical render I've found for React. Thank you for making it

@HriBB
Copy link

HriBB commented Jun 9, 2024

Same problem here ;)

I simply copy-pasted payloadLexicalReactRenderer.tsx into the project and added missing element renderers.

Also TypeScript complains, if you try to add custom elementRenderers
image

Would be cool, if we could do this.

@DaveMitten
Copy link

There is a PR up for this.

#11

Looks like there is alot of issues with the package itself and needs updating to work with payloadcms lexical editor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants