A rich text editor based on Darft-JS for the React framework, compatible with mainstream modern browsers.
- The 2017-08-28 v0.2.9
- Some CSS weights are adjusted to reduce conflicts with other UI frameworks
- The 2017-08-28 v0.2.8
- Fixed an issue where ICONS for frameworks such as ANTD could not be displayed after the editor was introduced
- The 2017-08-24 v0.2.7
- Link insertion function optimized
- Keep the editor focused after manipulating content through the control bar component
- The 2017-08-21 v0.2.6
- Fixed inability to paste plain text
- The 2017-08-19 v0.2.5
- Supports continuous press enter to jump out of the list in list mode
- Support to copy and paste images from web pages into the editor
The online demo
Feet: margox. Making. IO/braft – edito…
- Perfect text content editing function
- Multimedia content, such as pictures, audio and video, can be inserted
- Allows you to customize the upload interface for multimedia content
- Allows image to float left and right (text wrap)
- Allows you to set the list of colors, size, and fonts available to the editor
- Allows you to customize the control buttons that need to be displayed and the order in which they are displayed
- Allows additional customization of buttons
- Multi-language support (currently supports simplified Chinese and English)
- . More features in development
The installation
#Installation using YARN
yarn add braft-editor
#Install using NPM
npm install braft-editor --saveCopy the code
#Run the dev server. -
yarn start
#Start the upload server
cd example/server
node index.js
#Go to http://localhost:5998
#Package compiled
yarn buildCopy the code
Use the sample
import React from 'react'
import ReactDOM from 'react-dom'
//Introduce the editor and editor styles
import BraftEditor from 'braft-editor'
import 'braft-editor/dist/braft.css'
class Demo extends React.Component {
state = {
content: null
}
render () {
const editorProps = {
height: 500,
initialContent: this.state.content,
onChange: this.handleChange,
onHTMLChange: this.handleHTMLChange
}
return (
<div className="demo">
<BraftEditor {.editorProps}/>
</div>)}handleChange = (content) = > {
console.log(content)
}
handleHTMLChange = (html) = > {
console.log(html)
}
}Copy the code
contentFormat [string: raw | html]
Used to specify the content formats of initialContent and onChange. Raw means using editor raw data as input and output types, and HTML means using HTML strings as input and output types. The default is RAW.
To keep the content editable, it is strongly recommended to use the RAW format and get the content in HTML format through onHTMLChange
The initial content of the editor, passed either an HTML string or a RAW string, depending on the contentFormat type
onChange [function(html|raw)]
Specifies the callback when the editor content changes
Specifies the callback to editor content when it changes, as Raw editor content
onHTMLChange [function(html)]
Specifies the callback to editor content when it changes, as HTML editor content
Specifies the control bar component. The default values are as follows:
[
'undo'.'redo'.'split'.'font-size'.'font-family'.'text-color'.'bold'.'italic'.'underline'.'strike-through'.'superscript'.'subscript'.'text-align'.'split'.'headings'.'list_ul'.'list_ol'.'blockquote'.'code'.'split'.'link'.'split'.'media'
]Copy the code
addonControls [array:[object]]
Specifies a custom control component that currently supports only splitter lines and buttons. Example:
[
{
type: 'split'
},
{
type: 'button',
text: 'Hello',
className: 'preview-button'.onClick:(a)= > console.log('Hello World!')}]Copy the code
Specifies the height of the edit area, excluding the control bar. Default is 500
language [string]
Specifies the language of the editor. Currently zh and en are supported. Zh is the default
Set the placeholder text
viewWrapper [string]
Specifies the selector string for the editor’s wrapper container (e.g. ‘#wrapper’, ‘.container’) for position adaptation of components such as drop-down menus. The default is body
Specifies a list of colors available to the editor to set text colors and text background colors. Only 6-digit hexadecimal notation is supported. The default colors are available:
[
'# 000000'.'# 333333'.'# 666666'.'# 999999'.'#cccccc'.'#ffffff'.'#61a951'.'#16a085'.'#07a9fe'.'#003ba5'.'#8e44ad'.'#f32784'.'#c0392b'.'#d35400'.'#f39c12'.'#fdda00'.'#7f8c8d'.'#2c3e50'
]Copy the code
fontSizes [array:[number]]
Specifies a list of sizes available to the editor to set the size of text content. The default size is:
[
12.14.16.18.20.24.28.30.32.36.40.48.56.64.72.96.120.144
]Copy the code
Specifies a list of fonts available to the editor to set the font for text content. The default font is available:
[
{
name: 'Araial',
family: 'Arial, Helvetica, sans-serif'
}, {
name: 'Georgia',
family: 'Georgia, serif'
}, {
name: 'Impact',
family: 'Impact, serif'
}, {
name: 'Monospace',
family: '"Courier New", Courier, monospace'
}, {
name: 'Tahoma',
family: "Tahoma, Arial, 'Hiragino Sans GB', Sans-Serif"}]Copy the code
media [object]
Configure the editor’s multimedia insertion function:
{
image: true.//The image insertion function is enabled
video: false.//The video insertion function is enabled
audio: true.//The audio insertion function is enabled
uploadFn: null //Instructions are given below
}Copy the code
Specify upload function, if not specified, can not upload video and audio, can upload pictures, but only local preview.
media.uploadFn:param [object]
When the editor calls this function, it passes in an object containing the body of the file, the progress callback, the success callback, and the failure callback:
{
file: [File Object].progress: function (progress) {
//Progress is 0 to 100
},
success: function (res) {
//Res must be an object containing the URL property of the uploaded file:
},
error: function (err) {}}Copy the code
UploadFn example:
const uploadFn = (param) = > {
const serverURL = 'http://upload-server'
const xhr = new XMLHttpRequest
const fd = new FormData(a)const successFn = (response) = > {
//Assume that the server directly returns the address after the file is uploaded
//Call param.success and pass in the uploaded file address
param.success({
url: xhr.responseText})}const progressFn = (event) = > {
//Param.progress is called when the upload progress changes
param.progress(event.loaded / event.total * 100)}const errorFn = (response) = > {
//Param.error is called when an upload error occurs
param.error({
msg: 'unable to upload.'})}xhr.upload.addEventListener("progress", progressFn, false)
xhr.addEventListener("load", successFn, false)
xhr.addEventListener("error", errorFn, false)
xhr.addEventListener("abort", errorFn, false)
fd.append('file'.param.file)
xhr.open('POST', serverURL, true)
xhr.send(fd)
}Copy the code
- Support image width modification
- Perfect multimedia insertion tools
- Extends the types of custom control components, including drop-down menus and popovers
Known issues
- Placeholder text doesn’t disappear. Placeholder text disappears when you input arbitrary text