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

react-block-text

v0.0.23

Published

A block text editor for React

Downloads

185

Readme

React Block Text

npm version PRs

A block text editor for React.

This is an open-source clone of the famous Notion.so editor. Although not entirely feature complete, it comes with some basic blocks and offers a similar UI.

Project status: In-development beta. The API will be stable starting with v1.

Demo

See it live in your browser!

Installation

npm install --save react-block-text
yarn add react-block-text

Note for ViteJs users

You might need to add globalThis to your app.

Usage

import { useState } from 'react'
import ReactBlockText, { headerPlugin, imagePlugin, listPlugin, quotePlugin, todoPlugin } from 'react-block-text'

const plugins = [
  ...headerPlugin(),
  ...todoPlugin(),
  ...listPlugin(),
  ...quotePlugin(),
  ...imagePlugin({
    onSubmitFile: /* See image plugin section */,
    onSubmitUrl: /* ... */,
    getUrl: /* ... */,
    maxFileSize: '5 MB', /* Optional, displayed in the file upload dialog */
  }),
]

function Editor() {
  const [value, setValue] = useState('')

  return (
    <ReactBlockText
      value={value}
      onChange={setValue}
      plugins={plugins}
    />
  )
}

Note for multiple instances in SPA

When implementing multiple instances of the editor on separate pages in a SPA, you might need to set the key prop in order to make in work when transitioning pages:

<ReactBlockText
  key={someUniqueKey}
  // ...
/>

Options

type ReactBlockTextProps = {
  // The data for the editor
  value?: string
  // An array of plugin
  plugins?: ReactBlockTextPlugins
  // Enable read only mode
  readOnly?: boolean
  // Padding top of the editor
  paddingTop?: number
  // Padding bottom of the editor
  paddingBottom?: number
  // Padding left of the editor
  paddingLeft?: number
  // Padding right of the editor
  paddingRight?: number
  // The primary color for selection, drag and drop, and buttons
  primaryColor?: string | null | undefined
  // The default text color, to align with your design-system
  textColor?: string | null | undefined
  // Called when the value changes
  onChange?: (value: string) => void
  // Called when the user saves the editor with cmd/ctrl+s
  onSave?: () => void
}

Plugins

Header

Adds support for 3 types of headers.

Todo

Adds support for todo lists with checkboxes.

List

Adds support for ordered and unordered lists.

Quote

Adds support for block quotes.

Image

Adds support for images.

Three functions are required for the plugin to work:

type ReactBlockTextImagePluginSubmitter = () => {
  progress: number  // Between 0 and 1
  imageKey?: string // The reference to the image once it's uploaded
  isError?: boolean // If true, the upload failed and an error will be displayed in the editor
}

function onSubmitFile(file: File): Promise<ReactBlockTextImagePluginSubmitter>
function onSubmitUrl(file: File): Promise<ReactBlockTextImagePluginSubmitter>
function getUrl(imageKey: string): Promise<string>

The returned promises should resolve to a function that returns the progress of the upload as a number between 0 and 1 and eventually a imageKey corresponding to the image on your server. Using S3 or Firebase storage this is typically the storage path of the image. This ReactBlockTextImagePluginSubmitter function will be called periodically to update the progress of the upload and save the imageKey into the value prop.

getUrl should return the url of the image on your server based on the imageKey. Of course you can set imageKey directly to the URL and make getUrl an identity function.

For a Firebase example, see the demo files.

Community plugins

Create your own plugin based on the template provided by this repository and I'll add it here!

License

MIT

This project is not affiliated with Notion Labs, Inc.