Commit e85cb9e9 authored by zhuyangbin's avatar zhuyangbin

update

parents aa2b1558 b99b0aa3
...@@ -33,14 +33,16 @@ interface IProps { ...@@ -33,14 +33,16 @@ interface IProps {
onChange?: Function onChange?: Function
} }
const EditorDemo: React.FC<IProps> = ({ value, language = 'zh', onChange, cRef, excludeControls = excludeControlsDefault }) => { const EditorDemo: React.FC<IProps> = ({
value, language = 'zh', onChange, cRef, excludeControls = excludeControlsDefault, ...others
}) => {
// 创建一个空的editorState作为初始值 // 创建一个空的editorState作为初始值
const [editorState, setEditorState] = useState(BraftEditor.createEditorState(null)); const [editorState, setEditorState] = useState(BraftEditor.createEditorState(null));
const [percent, setPercent] = useState(0); // 进度条 const [percent, setPercent] = useState(0); // 进度条
const previewRef = useRef(null); const previewRef = useRef(null);
useEffect(() => { useEffect(() => {
if (value && typeof value === 'object') { // 不做转换 if (value && typeof value === 'object') { // 不做转换
setEditorState(value) setEditorState(value);
} else { } else {
// 使用BraftEditor.createEditorState将html字符串转换为编辑器需要的editorStat // 使用BraftEditor.createEditorState将html字符串转换为编辑器需要的editorStat
setEditorState(BraftEditor.createEditorState(value)); setEditorState(BraftEditor.createEditorState(value));
...@@ -102,12 +104,16 @@ const EditorDemo: React.FC<IProps> = ({ value, language = 'zh', onChange, cRef, ...@@ -102,12 +104,16 @@ const EditorDemo: React.FC<IProps> = ({ value, language = 'zh', onChange, cRef,
), ),
}, },
]; ];
const insertText = (text: string) => {
setEditorState(ContentUtils.insertText(editorState, text));
};
// 向外抛出数据 // 向外抛出数据
useImperativeHandle(cRef, () => { useImperativeHandle(cRef, () => {
return { return {
getHtml, getHtml,
previewMth, previewMth,
insertText,
}; };
}); });
...@@ -128,6 +134,7 @@ const EditorDemo: React.FC<IProps> = ({ value, language = 'zh', onChange, cRef, ...@@ -128,6 +134,7 @@ const EditorDemo: React.FC<IProps> = ({ value, language = 'zh', onChange, cRef,
return ( return (
<div className={styles.box}> <div className={styles.box}>
<BraftEditor <BraftEditor
{...others}
id="editor-with-color-picker" id="editor-with-color-picker"
value={editorState} value={editorState}
excludeControls={excludeControls} excludeControls={excludeControls}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment