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

lll-for-test

v0.15.0

Published

## Introduction

Downloads

4

Readme

Rich Text Slate React Component

Introduction

rich-text-slate-rc provides an out-of-the-box rich text editor based on slate, and supports image uploading via uss-js-sdk.

We know that the slate editor provides powerful customization capabilities, and we can freely develop various plugins according to our own business needs, but if we repeatedly develop plugins in each project, it is a time-consuming thing.

So we wrap the rich-text-slate-rc component to support a series of operations, including:

  • redo
  • undo
  • bold
  • italic
  • underline
  • h1
  • h2
  • h3
  • alignment[left]
  • alignment[center]
  • alignment[right]
  • numbered-list
  • bulleted-list
  • strikethrough
  • image uploader
  • table[Insert Column,Remove Column,Insert Row,Remove Row,Remove Table]

Demo

Installation

  • install from npm
yarn config set registry https://npm.shopee.io
yarn add rich-text-slate-rc

Getting Started

  1. Rich text editor
import { RichEditor, encodeSlateValueToString } from 'rich-text-slate-rc'
import { Form } from 'antd'

// USS config of your project
export const USS_CONFIG = {
  appId: 'xxx',
  appSecret: 'xxx',
  baseUrl: 'https://xxx',
  bucketName: 'xxx'
}

const Com = () => {
  const [form] = Form.useForm()

  const handleFinish = values => {
    const { richText } = values
    const richTextString = encodeSlateValueToString(richText)
  }

  return (
    <Form form={form} onFinish={handleFinish}>
      <Form.Item name='richText' label='Rich Text'>
        <RichEditor ussOptions={USS_CONFIG} />
      </Form.Item>
      <Form.Item>
        <Button type='primary' htmlType='submit'>
          Save
        </Button>
      </Form.Item>
    </Form>
  )
}
  1. Display rich text
import { RichTextDisplay } from 'rich-text-slate-rc'

const Com = ({ value }) => {
  return <RichTextDisplay value={value} />
}

API

RichTextDisplay

Component for displaying rich text.

| Param | Required | Type | Description | | ----- | -------- | ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | | value | - | Descendant[] | string | Value.The type of value is same as the value property of the component Slate in react-slate.It also can accept string that encoded from Descendant[]. |

RichEditor

Component for editing rich text.

| Param | Required | Type | Description | | ------------- | -------- | --------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | ussOptions | - | IUSSOptions | Uss config, refs uss-js-sdk,USS API 文档 | | searchEmailFn | - | (config: { keyword: string }) => Promise<{ items: IHrisStaffsRespDataItems[]; [key: string]: any }> | Search email function.This function is called to filter users when we mention someone in hris. | | initialValue | - | Descendant[] | Initial value.The type of initialValue is same as the value property of the component Slate in react-slate. | | onChange | - | (value:Descendant[])=>void | This function is called when user input. |

IUSSOptions

| Param | Required | Type | Description | | --------------- | -------- | ------ | ------------------------------------------------------------------------------------------------------------------ | | appId | ✔️ | string | App id | | appSecret | ✔️ | string | App secret | | baseUrl | ✔️ | string | server domain | | bucketName | ✔️ | string | bucket name | | downloadBaseUrl | - | string | If the download server domain is difference from the upload server domain,please set downloadBaseUrl additionally. |

IHrisStaffsRespDataItems

| Param | Required | Type | Description | | ----- | -------- | ------ | ----------- | | email | ✔️ | string | User email | | name | ✔️ | string | User name |

Methods

  • encodeSlateValueToString
  • decodeStringToSlateValue
  • getText
  • getSlateMentions
  • isEmptyValue
  • serializeHtml
  • deserializeHtml

encodeSlateValueToString Encode the slate value as a string to save to the database.

decodeStringToSlateValue Decode encoded string to slate value.

getText Get plain text from slate value.

getSlateMentions Sometimes you want to get all mention email list from slate value to notify BE to send an email to the users.This function will return a list of email list.

isEmptyValue To check if slate value is empty.

serializeHtml Serialize slate value to html string.

deserializeHtml Deserialize html element to slate value.

Related Docs