diff --git a/src/editor/index.tsx b/src/editor/index.tsx index 3da342c..54fa24c 100644 --- a/src/editor/index.tsx +++ b/src/editor/index.tsx @@ -485,17 +485,16 @@ class Editor extends React.Component { if (this.state.text === value) { return; } - this.setState( - { - text: value, - }, - () => { - emitter.emit(emitter.EVENT_CHANGE, value, event, typeof event === 'undefined'); - if (newSelection) { - setTimeout(() => this.setSelection(newSelection)); - } - }, - ); + this.setState({ + text: value, + }); + if (this.props.onChange) { + this.props.onChange({ text, html: this.getHtmlValue() }, event); + } + emitter.emit(emitter.EVENT_CHANGE, value, event, typeof event === 'undefined'); + if (newSelection) { + setTimeout(() => this.setSelection(newSelection)); + } if (!this.hasContentChanged) { this.hasContentChanged = true; } @@ -576,6 +575,12 @@ class Editor extends React.Component { return emitter.EVENT_VIEW_CHANGE; case 'keydown': return emitter.EVENT_KEY_DOWN; + case 'blur': + return emitter.EVENT_BLUR; + case 'focus': + return emitter.EVENT_FOCUS; + case 'scroll': + return emitter.EVENT_SCROLL; } } /** diff --git a/src/share/var.ts b/src/share/var.ts index 3ca8883..d77f0c9 100644 --- a/src/share/var.ts +++ b/src/share/var.ts @@ -2,7 +2,7 @@ import * as React from 'react'; export type UploadFunc = ((file: File) => Promise) | ((file: File, callback: (url: string) => void) => void); -export type EditorEvent = 'change' | 'fullscreen' | 'viewchange' | 'keydown'; +export type EditorEvent = 'change' | 'fullscreen' | 'viewchange' | 'keydown' | 'focus' | 'blur' | 'scroll'; export interface EditorConfig { theme?: string;