Commit e85cb9e9 authored by zhuyangbin's avatar zhuyangbin

update

parents aa2b1558 b99b0aa3
......@@ -33,14 +33,16 @@ interface IProps {
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作为初始值
const [editorState, setEditorState] = useState(BraftEditor.createEditorState(null));
const [percent, setPercent] = useState(0); // 进度条
const previewRef = useRef(null);
useEffect(() => {
if (value && typeof value === 'object') { // 不做转换
setEditorState(value)
if (value && typeof value === 'object') { // 不做转换
setEditorState(value);
} else {
// 使用BraftEditor.createEditorState将html字符串转换为编辑器需要的editorStat
setEditorState(BraftEditor.createEditorState(value));
......@@ -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, () => {
return {
getHtml,
previewMth,
insertText,
};
});
......@@ -128,6 +134,7 @@ const EditorDemo: React.FC<IProps> = ({ value, language = 'zh', onChange, cRef,
return (
<div className={styles.box}>
<BraftEditor
{...others}
id="editor-with-color-picker"
value={editorState}
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