npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@webiny/react-rich-text-lexical-renderer

v5.41.1

Published

[![](https://img.shields.io/npm/dw/@webiny/react-rich-textlexical-renderer.svg)](https://www.npmjs.com/package/@webiny/react-rich-text-lexical-renderer) [![](https://img.shields.io/npm/v/@webiny/react-rich-text-lexical-renderer.svg)](https://www.npmjs.com

Downloads

551

Readme

@webiny/react-rich-text-lexical-renderer

code style: prettier PRs Welcome

A React component to render lexical editor data coming from Webiny Headless CMS and Webiny Form Builder.

About

Webiny uses Lexical editor https://lexical.dev/ as a go to Rich Text Editor, with some additional plugins. To speed up the rendering of data for developers, we created this component.

Install

npm install --save @webiny/react-rich-text-lexical-renderer

Or if you prefer yarn:

yarn add @webiny/react-rich-text-lexical-renderer

Usage

Fetch your data from Headless CMS, then pass it to the component like this:

import {RichTextRenderer} from "@webiny/react-rich-text-renderer";

// Load content from Headless CMS (here we show what your content might look like).
const content = {
    root: {
        children: [
            {
                children: [
                    {
                        detail: 0,
                        format: 0,
                        mode: "normal",
                        style: "",
                        text: "A well written paragraph of text can bring so much joy!",
                        type: "text",
                        version: 1
                    }
                ],
                direction: "ltr",
                styles: [],
                format: "",
                indent: 0,
                tag: "p",
                type: "paragraph-element",
                version: 1
            }
        ],
        direction: "ltr",
        format: "",
        indent: 0,
        type: "root",
        version: 1
    }
}

// Mount the component
<RichTextLexicalRenderer value={content}/>;

Adding your custom lexical nodes for rendering

You can add custom lexical nodes for rendering your content:


class MyCustomNode extends LexicalNode {
...
}

// Mount the component
<RichTextLexicalRenderer value={content} nodes={[MyCustomNode]}/>;

Adding your custom typography theme.

You can override Webiny default typography theme that is used by lexical editor by providing your custom typography object.

Please read our docs and check our theme object on GitHub before add you custom theme.


const myTheme = {
    styles: {
        typography: {
            headings: [
                {
                    id: "custom_heading1",
                    name: "Custom Heading 1",
                    tag: "h1",
                    styles: {...headings, fontWeight: "bold", fontSize: 48}
                }]
        }
    }
}

// Mount the component
<RichTextLexicalRenderer value={content} theme={myTheme} nodes={[MyCustomNode]}/>;

Resolve the mismatch of the versions in the React v18 application

When you try to use RichTextLexicalRenderer component in React v18 application you will see this error on the screen:

React application error for mismatch of the React versions

This is because our @webiny/react-rich-text-lexical-renderer package and the React application have different versions of React. Our rich text renderer component is using v17.0.2, and the React application is using v18.x.x.

You can check which React versions are requested by various dependencies by running the following command:

  • yarn why react for yarn users.
  • npm ls react for npm users.

To resolve this problem, we need to force all dependencies to use the same version of React.

Instructions for yarn users

To force yarn to resolve dependencies across the project to the exact versions we're looking for, use the resolutions field in the root package.json file.

{
  ...
  "resolutions": {
    "react": "18.x.x"
  },
  ...
}

Once the resolutions field is defined, run yarn to apply the new config.

To learn more about the resolutions field, please check this yarn documentation article.

Instructions for npm users

The npm supports the same functionality as yarn with the overrides field name. You need to add overrides field in package.json file.

{
  ...
  "overrides": {
    "react": "^18.x.x"
  },
  ...
}

Once the overrides field is defined, run npm install to apply the new config.

To learn more about the overrides field, please check this npm documentation article.