slatejsx
1.0.0
npm install slatejsxhttp://seditor.open.heyphp.com
import SEditor from 'slatejsx' ;
import 'slatejsx/dist/index.css' ;
import { useState } from 'react' ;
const config = [
{
"type" : "paragraph" ,
"title" : "h1" ,
"children" : [
{
"text" : ""
}
]
}
]
const [ value , setValue ] = useState ( config )
// 上传图片的回调,示例中将图片转为base64写入json,如果需要存到云存储可以改写此方法
const onUploadImage = ( file , callback ) => {
const reader = new FileReader ( ) ;
reader . addEventListener ( 'load' , ( ) => {
const url = reader . result ;
callback ( url )
} ) ;
reader . readAsDataURL ( file ) ;
}
function App ( ) {
return (
< SEditor
value = { value }
plugins = { [ ] }
readOnly = { false }
param = { { onUploadImage } }
onChange = { v => setValue ( v ) }
/>
) ;
}
export default App ; | 參數 | 類型 | 說明 |
|---|---|---|
| value | array | 參考slatejs官方文檔,初始化可以使用示例中的結構體 |
| onChange | function | 數據變化時候的回調,可以參考上文示例 |
| plugins | array | 額外的插件,如果需要新增新的編輯器功能,可以通過這個參數傳入 |
| readOnly | boolean | 只讀,如果為true,則沒有工具欄且不可編輯 |
| param | {} | 額外參數,參數會寫入到useSlate()的實體上 |