Giter Club home page Giter Club logo

blocks-react-renderer's Introduction

Strapi logo Strapi logo

Open-source headless CMS, self-hosted or Cloud you’re in control.

The leading open-source headless CMS, 100% JavaScript/TypeScript, flexible and fully customizable.

Cloud · Try live demo · Strapi 5 (coming soon)


NPM Version Tests Strapi on Discord Strapi Nightly Release Build Status


Administration panel


Strapi Community Edition is a free and open-source headless CMS enabling you to manage any content, anywhere.

  • Self-hosted or Cloud: You can host and scale Strapi projects the way you want. You can save time by deploying to Strapi Cloud or deploy to the hosting platform you want**: AWS, Azure, Google Cloud, DigitalOcean.
  • Modern Admin Panel: Elegant, entirely customizable and a fully extensible admin panel.
  • Multi-database support: You can choose the database you prefer: PostgreSQL, MySQL, MariaDB, and SQLite.
  • Customizable: You can quickly build your logic by fully customizing APIs, routes, or plugins to fit your needs perfectly.
  • Blazing Fast and Robust: Built on top of Node.js and TypeScript, Strapi delivers reliable and solid performance.
  • Front-end Agnostic: Use any front-end framework (React, Next.js, Vue, Angular, etc.), mobile apps or even IoT.
  • Secure by default: Reusable policies, CORS, CSP, P3P, Xframe, XSS, and more.
  • Powerful CLI: Scaffold projects and APIs on the fly.

Getting Started

Read the Getting Started tutorial or follow the steps below:

⏳ Installation

Install Strapi with this Quickstart command to create a Strapi project instantly:

yarn create strapi-app my-project --quickstart

or

  • (Use npm/npx to install the Strapi project.)
npx create-strapi-app my-project --quickstart

This command generates a brand new project with the default features (authentication, permissions, content management, content type builder & file upload). The Quickstart command installs Strapi using a SQLite database which is used for prototyping in development.

Enjoy 🎉

🖐 Requirements

Complete installation requirements can be found in the documentation under Installation Requirements.

Supported operating systems:

  • Ubuntu LTS/Debian 9.x
  • CentOS/RHEL 8
  • macOS Mojave
  • Windows 10
  • Docker

(Please note that Strapi may work on other operating systems, but these are not tested nor officially supported at this time.)

Node:

Strapi only supports maintenance and LTS versions of Node.js. Please refer to the Node.js release schedule for more information. NPM versions installed by default with Node.js are supported. Generally it's recommended to use yarn over npm where possible.

Strapi Version Recommended Minimum
4.14.5 and up 20.x 18.x
4.11.0 and up 18.x 16.x
4.3.9 to 4.10.x 18.x 14.x
4.0.x to 4.3.8 16.x 14.x

Database:

Database Recommended Minimum
MySQL 8.0 5.7.8
MariaDB 10.6 10.3
PostgreSQL 14.0 11.0
SQLite 3 3

We recommend always using the latest version of Strapi stable to start your new projects.

Features

  • Content Types Builder: Build the most flexible publishing experience for your content managers, by giving them the freedom to create any page on the go with fields, components and Dynamic Zones.
  • Media Library: Upload your images, videos, audio or documents to the media library. Easily find the right asset, edit and reuse it.
  • Internationalization: The Internationalization (i18n) plugin allows Strapi users to create, manage and distribute localized content in different languages, called "locales"
  • Role Based Access Control: Create an unlimited number of custom roles and permissions for admin and end users.
  • GraphQL or REST: Consume the API using REST or GraphQL

You can unlock additional features such as SSO, Audit Logs, Review Workflows in Strapi Cloud or Strapi Enterprise.

See more on our website.

Contributing

Please read our Contributing Guide before submitting a Pull Request to the project.

Community support

For general help using Strapi, please refer to the official Strapi documentation. For additional help, you can use one of these channels to ask a question:

Migration

Follow our migration guides on the documentation to keep your projects up-to-date.

Roadmap

Check out our roadmap to get informed of the latest features released and the upcoming ones. You may also give us insights and vote for a specific feature.

Documentation

See our dedicated repository for the Strapi documentation, or view our documentation live:

Try live demo

See for yourself what's under the hood by getting access to a hosted Strapi project with sample data.

License

See the LICENSE file for licensing information.

blocks-react-renderer's People

Contributors

joshuaellis avatar remidej avatar simotae14 avatar yek-plus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

blocks-react-renderer's Issues

[feat]: Extract plain text from blocks

A clear and concise description of what the feature is

This feature adds a method to Strapi's rich-text rendering system, enabling the extraction of plain text from rich-text content.

Why should this feature be included?

This feature is useful in various content markup scenarios. For instance, in creating FAQ sections, it's crucial to have a method that efficiently strips formatting to present clear, concise text.

Please provide an example for how this would work

The feature would work similarly to PortableText's toPlainText.
https://github.com/portabletext/toolkit/blob/main/src/toPlainText.ts

[feat]: Mark renderer with "use client" to be used in Server Components

A clear and concise description of what the feature is

Currently, if I want to use this renderer in a Server Component I would have to create a wrapper with the "use client" directive.
This feature aims for seamless usability within the next.js framework, especially with the use of the app router.

Why should this feature be included?

It makes it easier for consumers of this package since you don't have to create a wrapping boundary.

Please provide an example for how this would work

See: https://nextjs.org/docs/app/building-your-application/rendering/composition-patterns#advice-for-library-authors

[feat]: Convert to react-native

A clear and concise description of what the feature is

The feature would allow to convert blocks contents into a react / react-native readable format. I guess that much of the logic could remain close or identical as both could take advantage of the react standards, simply switching the final tags - <div> becoming <View>, <p> becoming <Text> etc.

Why should this feature be included?

One of the main advantage of using a headless editor like Strapi is the ability to serve contents not only to web apps, but also to mobile apps.

Please provide an example for how this would work

Globo made such a converter with draftJs, it worked pretty well.
https://github.com/globocom/react-native-draftjs-render

[feat]: example with graphql data

A clear and concise description of what the feature is

This is a great plugin, thank you for putting it together! I'm trying to use this in my project, but I can't figure out how to properly query the data I need from GraphQL. If I select everything possible from a "Rich text (Blocks)" component, it only works if literally every kind of content has been added. Or if I select only the most basic elements from GraphQL it will appear "broken" when, for example, italic text is entered and the text does not appear italic. (If that makes any sense lol)

Basically if you request italic text--and there isn't any--the query breaks. If you don't request italic text--and users have entered it--the query works... but you don't get the italic text. So how do I make everything optional?

Why should this feature be included?

It will get developers using GraphQL up and running much faster. In my case, I happen to be using Gatsby. It does provide an error message linking to this page, but unfortunately I don't have enough experience with GraphQL, and there is some nesting and complexity with this plugin.

Please provide an example for how this would work

Ideally there would be a GraphQL query like this:
myrichtextblocksfield { type level format image { alternativeText url } children { bold italic strikethrough text type url underline children { text type } } }

It should work whether or not supported content has been entered. Lists, bold text, underlines, images, and so on. Basically how do I create a nested type definition where everything is optional?

[feat]: blocks-vue-renderer

A clear and concise description of what the feature is

A VueJS Blocks renderer component

Why should this feature be included?

Not all front projects use React ;)

Please provide an example for how this would work

No response

[bug]: Can't import to SSG page

What version of @strapi/blocks-react-renderer are you using?

Npm Version: 10.2.4
Node Version: 20.11.1
Vers: 1.0.1
Browser: Edge
Framework: Nextjs 14 with app dir
Typescript included

What's Wrong?

Can't import to SSG generated pages due to ECMA script error

./node_modules/@strapi/blocks-react-renderer/dist/BlocksRenderer.mjs/proxy.js` Specified module format (CommonJs) is not matching the module format of the source code (EcmaScript Modules) The CommonJs module format was specified in the package.json that is affecting this source file or by using an special extension, but Ecmascript import/export syntax is used in the source code. The module was automatically converted to an EcmaScript module, but that is in conflict with the specified module format. Either change the "type" field in the package.json or replace EcmaScript import/export syntax with CommonJs syntas in the source file. In some cases EcmaScript import/export syntax is added by an transform and isn't actually part of the source code. In these cases revisit transformation options to inject the correct syntax.

To Reproduce

Nextjs 14, with App dir usage.

'/blogs' page that loads resources, Blog Posts in this case, uses the Blocks Renderer fine, no errors as it's a client side component.

SSG page based on the returned items from the API '/articles' endpoint from strapi, using Id as the uid.

Generates the pages when not using BlocksRenderer, just simply applying JSON.stringify has no errors. But when importing the BlockRenderer we run into the above error.

Expected Behaviour

BlocksRenderer doesn't have an import error here, and works similar to how it does on CSR.

Production pipeline with omit-dev failed due to postinstall "husky install"

Hi dear contributors!

I have some problems with this line of code.

"postinstall": "husky install",

The main problem happened when running typical build command ( for example in nextjs, for example in docker, some pipelines ) , for which dependencies under "dependencies" block typically is required, but devDependencies should be is not required (omit=dev)
So husky is not installed for omit=dev, but docker tried to run postinstall command and pipeline failing

image

So there are a some possible solutions:

  1. Add condition to postinstall script to run husky only if it installed
    "scripts": {
    "postinstall": "if [ -d node_modules/husky ]; then husky install; fi"
    }

  2. Using prepare script for husky, which will be automatically called before npm publish
    "scripts": {
    "prepare": "husky install"
    }

  3. Install all the dependencies using npm install (without omit dev).
    Is not the best practice as devDependencies will be installed for builld

  4. Add husky to dependencies package json section which can be ok only as fast temporary fix

Rich Text Block Editor in Next.js 13 is not working

Strapi Version: 4.0
Operating System: Linux
Database: PostgresDB
Node Version: 18.17.1
NPM Version: 9.6.7
Yarn Version: 4.0.0

Hi. I have added a single type that consists of Rich Text Block Editor components. Now I am working on getting and rendering those data in my Next.js project. I use @strapi/blocks-react-renderer but it’s not working. Probably, because I have Next.js 13 version and without Typescript.
Could you help me?
What should I use to render those data?

[bug]: Cannot install package

What version of @strapi/blocks-react-renderer are you using?

  • npm v10.5.0
  • node v20.12.1

What's Wrong?

npm i @strapi/blocks-react-renderer
npm ERR! code 127
npm ERR! path ###/node_modules/@strapi/blocks-react-renderer
npm ERR! command failed
npm ERR! command sh -c husky install
npm ERR! sh: husky: command not found

To Reproduce

  • npm init -y
  • npm i @strapi/blocks-react-renderer

Expected Behaviour

I expect to be able to install the package without installing husky.

[bug]: Module '"@strapi/blocks-react-renderer"' has no exported member 'BlocksContent'

What version of @strapi/blocks-react-renderer are you using?

  • Nextjs 14.0.4
  • Nodejs lts/iron (20.10.x)
  • React 18+
  • @strapi/blocks-react-renderer@latest (1.0.0-beta.0)

What's Wrong?

VSCode returning that the module isn't exporting any type BlocksContent as shown on the readme

To Reproduce

Paste the following import into a project with the plugin installed :

import {
  BlocksRenderer,
  type BlocksContent,
} from '@strapi/blocks-react-renderer'

Expected Behaviour

The module should export a usable type I guess?

[feat]: Vanilla JS library

A clear and concise description of what the feature is

Hey!
It's good to have this lib, but why it's for React?
Since there is no docs available for Blocks how should we use it in other frameworks?

Why should this feature be included?

Plain JS should be also supported

Please provide an example for how this would work

No response

[bug]: Cannot render in server component context

What version of @strapi/blocks-react-renderer are you using?

npm: 9.8.1
node: 20.9.0
react: 18.2.0
next: 14.1.4
@strapi/blocks-react-renderer: 1.0.1
browser: any

What's Wrong?

I have a use case where I need to send the HTML on nodemailer. Strapi sends the result as JSON so I'm getting the HTML by using renderToStaticMarkup(<BlocksRenderer content={blocks}/>).
Unfortunately when I do this in Next 14 in a server action it throws an error.

To Reproduce

I made this codesandbox with a reproduction of the bug

Expected Behaviour

I expect to be able to render the BlocksRenderer component in the context of the server so that I can in turn use it to render the static markup.
I suspect that it has to do with the fact that BlocksRenderer has 'use client' and so Next 14 is probably skipping rendering in the context of the server. I don't wish to introduce a breaking change so I suggest making something like BlocksRendererPure without the 'use client' and the current BlocksRenderer expose as the BlocksRendererPure wrapped in a wrapper with the 'use client'.
If help is needed for a merge request let me know and I'll submit a fix according to whatever the package owner decides is the best way to fix this.

[bug]: Paragraphs in blocks do not respect new lines

What version of @strapi/blocks-react-renderer are you using?

strapi/blocks-react-renderer": "^1.0.0-beta.0"
"react": "18.2.0"
"strapi": "4.15.4"

What's Wrong?

currently Strapi splits all Text (ie paragraph) blocks after a line break into separate p tags.

Also the line breaks themselves are just empty stings which is annoying to deal with when they are sitting in their own (now empty) p tag.

Shouldnt all the parts of a paragraph be children of the "paragraph" block instead of creating their own new paragraph?

To Reproduce

create a new RichText field
image

Gives you the output

[
  {
    type: "paragraph",
    children: [
      {
        type: "text",
        text: "Hi",
      },
    ],
  },
  {
    type: "paragraph",
    children: [
      {
        type: "text",
        text: "",
      },
    ],
  },
  {
    type: "paragraph",
    children: [
      {
        type: "text",
        text: "This is a line of text followed by a line break",
      },
    ],
  },
  {
    type: "paragraph",
    children: [
      {
        type: "text",
        text: "",
      },
    ],
  },
  {
    type: "paragraph",
    children: [
      {
        type: "text",
        text: "Here is a double one",
      },
    ],
  },
  {
    type: "paragraph",
    children: [
      {
        type: "text",
        text: "",
      },
    ],
  },
  {
    type: "paragraph",
    children: [
      {
        type: "text",
        text: "",
      },
    ],
  },
  {
    type: "paragraph",
    children: [
      {
        type: "text",
        text: "The end",
      },
    ],
  },
]

Expected Behaviour

Expected would be something like this:

[
  {
    type: "paragraph",
    children: [
      {
        type: "text",
        text: "Hi",
      },
      {
        type: "text",
        text: "&nbsp;",
      },
      {
        type: "text",
        text: "This is a line of text followed by a line break",
      },
      {
        type: "text",
        text: "&nbsp;",
      },
      {
        type: "text",
        text: "The end",
      },
    ],
  },
]

[feat]: The blocks-react-renderer npm package is used to render the content configured in the Rich text (Blocks) rich text edit box. Only the content has no format.

A clear and concise description of what the feature is

Hello, I am trying to use strapi to provide interface services to the front-end application in the content management backend.

The Rich text (Blocks) component of the strapi cms content management backend is configured with a rich text editing box. After editing the content in Rich text (Blocks), how can the front-end webpage obtain the data through the interface and restore it to a 1:1 ratio?

I used the blocks-react-renderer npm package, but only the content has no format. I hope that after writing the formatted content in Rich text (Blocks) in the strapi cms content management backend, the front-end interface requests the corresponding content and inserts it directly. , the displayed content and style can be consistent with those during editing, without the front-end website having to handle it by itself. This is too cumbersome and not open source enough.

Why should this feature be included?

It is expected that after writing the formatted content in the rich text (Blocks) of the strapi cms content management backend, the front-end interface requests the corresponding content and inserts it directly. The displayed content and style can be consistent with those during editing, without the need for a front-end It would be too cumbersome for the website to handle it on its own and not open source enough.

Please provide an example for how this would work

No response

[bug]: Links seem to be nested into paragraphs or not being parsed

What version of @strapi/blocks-react-renderer are you using?

1.0.0

What's Wrong?

In the documentation/readme it mentions the difference between a link and paragraph. In the meanwhile I get a link nested in a paragraph while the blocks renderer doesn't seem to find this particular element at all.

Strapi 14.15.5

Response:

 {
      "type":"paragraph",
      "children":[
         {
            "text":"",
            "type":"text"
         },
         {
            "type":"link",
            "url":"https://test.com",
            "children":[
               {
                  "type":"text",
                  "text":"Read more",
                  "bold":true
               }
            ]
         },
         {
            "text":"",
            "type":"text"
         }
      ]
   },
   {
      "type":"paragraph",
      "children":[
         {
            "type":"text",
            "text":"Another part of a text"
         }
      ]
   }

BlocksRenderer:

 <StrapiRichContentEditor
      content={content}
      blocks={{
        paragraph: ({ ...props }) => (
          <Paragraph {...props} theme={theme} />
        ),
        heading: ({ ...props }) => (
          <Heading {...props} theme={theme} />
        ),
        link: ({ children, url }) => {
          return (
            <Link
              href={url || "#"}
              label={children}
              className={classNames("w-full text-sm inline", {
                "text-white": isBlack,
                "text-screen-black": isWhite,
                underline: true,
              })}
              description={""}
            />
          );
        },
      }}
    />

To Reproduce

This is how it looks like in the Rich Text Blocks.
Screenshot

Expected Behaviour

I would expect the renderer to catch the correct type based on nested elements or at least catch a link.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.