Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
braft-editor
Advanced tools
# 使用yarn安装
yarn add braft-editor
# 使用npm安装
npm install braft-editor --save
# 运行dev-server
yarn start
open http://localhost:5998
# 打包编译
yarn build
import React from 'react'
import ReactDOM from 'react-dom'
// 引入编辑器以及编辑器样式
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)
}
}
用于指定initialContent和onChange的内容格式,raw表示使用编辑器原始数据作为输入和输出类型, html表示使用HTML字符串作为输入和输入类型,默认为raw。
为了保证内容的可编辑性,强烈建议使用raw格式,并通过onHTMLChange获取HTML格式的内容
编辑器的初始内容,根据contentFormat类型传入html字符串或者raw字符串
指定编辑器内容发生变化时候的回调
指定编辑器内容发生变化时候的回调,参数为Raw格式的编辑器内容
指定编辑器内容发生变化时候的回调,参数为HTML格式的编辑器内容
指定控制栏组件,默认值如下:
[
'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'
]
指定自定义控制组件,目前仅支持分割线和按钮。 示例:
[
{
type: 'split'
},
{
type: 'button',
text: 'Hello',
className: 'preview-button',
onClick: () => console.log('Hello World!')
}
]
指定编辑区域的高度,不包括控制栏,默认是500
指定编辑器的语言,目前支持zh和en,默认zh
指定编辑器可用的颜色列表,用于设定文本颜色和文本背景颜色,只支持6位16进制写法,默认可用颜色:
[
'#000000', '#333333', '#666666', '#999999', '#cccccc', '#ffffff',
'#61a951', '#16a085', '#07a9fe', '#003ba5', '#8e44ad', '#f32784',
'#c0392b', '#d35400', '#f39c12', '#fdda00', '#7f8c8d', '#2c3e50'
]
指定编辑器可用的字号列表,用于设定文本内容的字号,默认可用字号:
[
12, 14, 16, 18, 20, 24,
28, 30, 32, 36, 40, 48,
56, 64, 72, 96, 120, 144
]
指定编辑器可用的字体列表,用于设定文本内容的字体,默认可用字体:
[
{
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"
}
]
配置编辑器的多媒体插入功能:
{
image: true, // 开启图片插入功能
video: false, // 开启视频插入功能
audio: true, // 开启音频插入功能
uploadFn: null // 说明见下文
}
指定上传函数,未指定时无法上传视频和音频,可上传图片,但只限本地预览。
编辑器在调用该函数时,会传入一个包含文件体、进度回调、成功回调和失败回调的对象作为参数:
{
file: [File Object],
progress: function (progress) {
// progress为0到100
},
success: function (res) {
// res须为一个包含已上传文件url属性的对象:
},
error: function (err) {
}
}
uploadFn示例:
const uploadFn = (param) => {
const serverURL = 'http://upload-server'
const xhr = new XMLHttpRequest
const fd = new FormData()
const successFn = (response) => {
// 假设服务端直接返回文件上传后的地址
// 上传成功后调用param.success并传入上传后的文件地址
param.success({
url: xhr.responseText
})
}
const progressFn = (event) => {
// 上传进度发生变化时调用param.progress
param.progress(event.loaded / event.total * 100)
}
const errorFn = (response) => {
// 上传发生错误时调用param.error
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)
}
FAQs
Rich Text Editor Based On Draft.js
The npm package braft-editor receives a total of 2,528 weekly downloads. As such, braft-editor popularity was classified as popular.
We found that braft-editor demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.