@@ -12,8 +12,8 @@ export interface IMarkdownEditor extends IProps, ICodeMirror {
1212 prefixCls ?: string ,
1313 value ?: string ,
1414 height ?: number ,
15- visble ?: boolean ,
16- visbleEditor ?: boolean ,
15+ visible ?: boolean ,
16+ visibleEditor ?: boolean ,
1717 toolbars ?: string [ ] | false ,
1818 toolbarsMode ?: IToolBarModeProps [ 'toolbarsMode' ] | false ,
1919 previewProps ?: IPreviewMarkdown [ 'previewProps' ] ;
@@ -26,34 +26,36 @@ export default class MarkdownEditor extends React.PureComponent<IMarkdownEditor,
2626 public static displayName = 'MarkdownEditor' ;
2727 public static defaultProps : IMarkdownEditor = {
2828 onChange : ( ) => null ,
29+ onBlur : ( ) => null ,
2930 prefixCls : 'md-editor' ,
3031 value : '' ,
31- visbleEditor : true ,
32- visble : true ,
32+ visibleEditor : true ,
33+ visible : true ,
3334 } ;
3435 public container ! : HTMLDivElement ;
3536 public editorClientHeight ! : number ;
3637 public preview ! : PreviewMarkdown ;
3738 public toolbarsMode ! : ToolBarMode ;
3839 public CodeMirror ! : CodeMirror ;
3940 public render ( ) {
40- const { prefixCls, className, toolbars, toolbarsMode, onChange, visble , visbleEditor , previewProps, ...codemirrorProps } = this . props ;
41+ const { prefixCls, className, toolbars, toolbarsMode, onChange, onBlur , visible : visible , visibleEditor : visibleEditor , previewProps, ...codemirrorProps } = this . props ;
4142 return (
4243 < div ref = { ( node : HTMLDivElement ) => this . container = node } >
4344 < div className = { classnames ( prefixCls , className ) } >
4445 < ToolBarMode ref = { ( mode : ToolBarMode ) => this . toolbarsMode = mode } toolbarsMode = { toolbarsMode } onClick = { this . onClickMode } />
4546 < ToolBar toolbars = { toolbars } onClick = { this . onClick } />
4647 < div className = { classnames ( `${ prefixCls } -content` ) } >
47- { visbleEditor && (
48+ { visibleEditor && (
4849 < CodeMirror
49- visbleEditor = { visbleEditor }
50+ visibleEditor = { visibleEditor }
5051 ref = { this . getInstance }
5152 { ...codemirrorProps }
5253 onChange = { this . onChange }
54+ onBlur = { this . onBlur }
5355 />
5456 ) }
5557 < PreviewMarkdown
56- visble = { visble }
58+ visible = { visible }
5759 ref = { ( pmd : PreviewMarkdown ) => this . preview = pmd }
5860 value = { this . props . value }
5961 previewProps = { previewProps }
@@ -66,8 +68,8 @@ export default class MarkdownEditor extends React.PureComponent<IMarkdownEditor,
6668
6769 public componentDidMount ( ) {
6870 if ( this . preview && this . CodeMirror ) {
69- this . props . visble ? this . preview . show ( ) : this . preview . hide ( ) ;
70- this . CodeMirror . editor . setSize ( this . props . visble ? '50%' : '100%' ) ;
71+ this . props . visible ? this . preview . show ( ) : this . preview . hide ( ) ;
72+ this . CodeMirror . editor . setSize ( this . props . visible ? '50%' : '100%' ) ;
7173 const { clientHeight } = this . CodeMirror . editor . getScrollInfo ( ) ;
7274 this . editorClientHeight = clientHeight ;
7375 window . addEventListener ( 'resize' , this . handleResize , true ) ;
@@ -79,16 +81,16 @@ export default class MarkdownEditor extends React.PureComponent<IMarkdownEditor,
7981 }
8082
8183 public handleResize = ( ) => {
82- const isfullscreen = this . toolbarsMode . state . fullscreen
83- if ( isfullscreen ) {
84- this . setEditorSize ( isfullscreen ) ;
84+ const isFullScreen = this . toolbarsMode . state . fullscreen
85+ if ( isFullScreen ) {
86+ this . setEditorSize ( isFullScreen ) ;
8587 }
8688 }
8789
8890 public componentWillReceiveProps ( nextProps : IMarkdownEditor ) {
89- if ( nextProps . visble !== this . props . visble ) {
90- nextProps . visble ? this . preview . show ( ) : this . preview . hide ( ) ;
91- this . CodeMirror . editor . setSize ( nextProps . visble ? '50%' : '100%' ) ;
91+ if ( nextProps . visible !== this . props . visible ) {
92+ nextProps . visible ? this . preview . show ( ) : this . preview . hide ( ) ;
93+ this . CodeMirror . editor . setSize ( nextProps . visible ? '50%' : '100%' ) ;
9294 }
9395 }
9496
@@ -107,28 +109,35 @@ export default class MarkdownEditor extends React.PureComponent<IMarkdownEditor,
107109 }
108110 }
109111
112+ private onBlur = ( editor : IInstance , event : Event ) => {
113+ const { onBlur } = this . props as IMarkdownEditor ;
114+ if ( onBlur ) {
115+ onBlur ( editor , event ) ;
116+ }
117+ }
118+
110119 private previewMarkdown ( ) {
111120 if ( this . preview ) {
112- this . preview . state . visble ? this . preview . hide ( ) : this . preview . show ( ) ;
113- this . toolbarsMode . updateMode ( 'preview' , ! this . preview . state . visble ) ;
114- this . CodeMirror . editor . setSize ( this . preview . state . visble ? '100%' : '50%' ) ;
121+ this . preview . state . visible ? this . preview . hide ( ) : this . preview . show ( ) ;
122+ this . toolbarsMode . updateMode ( 'preview' , ! this . preview . state . visible ) ;
123+ this . CodeMirror . editor . setSize ( this . preview . state . visible ? '100%' : '50%' ) ;
115124 }
116125 }
117126
118127 private fullScreen ( ) {
119128 const { prefixCls } = this . props ;
120129 if ( this . toolbarsMode && this . container ) {
121- const isfullscreen = ! this . toolbarsMode . state . fullscreen
122- this . toolbarsMode . updateMode ( 'fullscreen' , isfullscreen ) ;
123- this . container . className = isfullscreen ? classnames ( `${ prefixCls } -fullscreen` ) : '' ;
124- document . body . style . overflow = isfullscreen ? 'hidden' : 'initial' ;
125- this . setEditorSize ( isfullscreen ) ;
130+ const isFullScreen = ! this . toolbarsMode . state . fullscreen
131+ this . toolbarsMode . updateMode ( 'fullscreen' , isFullScreen ) ;
132+ this . container . className = isFullScreen ? classnames ( `${ prefixCls } -fullscreen` ) : '' ;
133+ document . body . style . overflow = isFullScreen ? 'hidden' : 'initial' ;
134+ this . setEditorSize ( isFullScreen ) ;
126135 }
127136 }
128137
129- private setEditorSize ( isfullscreen : boolean ) {
138+ private setEditorSize ( isFullScreen : boolean ) {
130139 const clientHeight = document . body . clientHeight ;
131- this . CodeMirror . editor . setSize ( this . preview . state . visble ? '50%' : '100%' , isfullscreen ? clientHeight - 33 : this . editorClientHeight ) ;
140+ this . CodeMirror . editor . setSize ( this . preview . state . visible ? '50%' : '100%' , isFullScreen ? clientHeight - 33 : this . editorClientHeight ) ;
132141 }
133142
134143 private onClickMode = ( type : string ) => {
0 commit comments