diff --git a/components/braftEditor/index.tsx b/components/braftEditor/index.tsx index e4a9a065e6be847f2f51f01d71a1e388bb0121b5..173e9e5e44af6d78d1f3b5aa3399b8a2d8de643f 100644 --- a/components/braftEditor/index.tsx +++ b/components/braftEditor/index.tsx @@ -33,14 +33,16 @@ interface IProps { onChange?: Function } -const EditorDemo: React.FC = ({ value, language = 'zh', onChange, cRef, excludeControls = excludeControlsDefault }) => { +const EditorDemo: React.FC = ({ + 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 = ({ 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 = ({ value, language = 'zh', onChange, cRef, return (