0.15.0 • Published 2 years ago

lll-for-test v0.15.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

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:

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.

ParamRequiredTypeDescription
value-Descendant[] | stringValue.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.

ParamRequiredTypeDescription
ussOptions-IUSSOptionsUss 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[])=>voidThis function is called when user input.

IUSSOptions

ParamRequiredTypeDescription
appId✔️stringApp id
appSecret✔️stringApp secret
baseUrl✔️stringserver domain
bucketName✔️stringbucket name
downloadBaseUrl-stringIf the download server domain is difference from the upload server domain,please set downloadBaseUrl additionally.

IHrisStaffsRespDataItems

ParamRequiredTypeDescription
email✔️stringUser email
name✔️stringUser 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

0.15.0

2 years ago

0.14.0

2 years ago

0.13.0

2 years ago

0.12.0

2 years ago

0.11.0

2 years ago

0.10.0

2 years ago

0.9.0

2 years ago

0.8.0

2 years ago

0.7.0

2 years ago

0.5.0

2 years ago

0.4.1

2 years ago

0.4.0

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago