11import classnames from 'classnames' ;
22import * as React from "react" ;
3+ import { IInstance } from './common/codemirror' ;
34import { IProps } from './common/props' ;
45import CodeMirror , { ICodeMirror } from './components/CodeMirror' ;
56import ToolBar from './components/ToolBar' ;
67import './index.less' ;
78
8- export interface IMarkdownEditorProps extends IProps , ICodeMirror {
9+ export interface IMarkdownEditor extends IProps , ICodeMirror {
910 prefixCls ?: string ,
1011 value ?: string ,
1112 height ?: number ,
@@ -17,9 +18,10 @@ interface IMarkdownEditorState {
1718 editor ?: CodeMirror ;
1819}
1920
20- export default class MarkdownEditor extends React . PureComponent < IMarkdownEditorProps , IMarkdownEditorState , { } > {
21+ export default class MarkdownEditor extends React . PureComponent < IMarkdownEditor , IMarkdownEditorState , { } > {
2122 public static displayName = 'MarkdownEditor' ;
22- public static defaultProps : IMarkdownEditorProps = {
23+ public static defaultProps : IMarkdownEditor = {
24+ onChange : ( ) => null ,
2325 prefixCls : 'md-editor' ,
2426 value : '' ,
2527 } ;
@@ -45,9 +47,11 @@ export default class MarkdownEditor extends React.PureComponent<IMarkdownEditorP
4547 this . CodeMirror = editor ;
4648 }
4749 }
48- private onChange = ( ) => {
49- // private onChange = (editor: CodeMirror, editorChange: CodeMirror.EditorChange) => {
50- // console.log('test', editor, editorChange);
50+ private onChange = ( editor : IInstance , data : CodeMirror . EditorChange , value : string ) => {
51+ const { onChange } = this . props as IMarkdownEditor ;
52+ if ( onChange ) {
53+ onChange ( editor , data , value ) ;
54+ }
5155 }
5256 private onClick = ( type : string ) => {
5357 const selection = this . CodeMirror . editor . getSelection ( ) ;
0 commit comments