diff --git a/packages/xpub-edit/src/components/Editor.js b/packages/xpub-edit/src/components/Editor.js index c3f16a06e9d7da3046a94ea3fc78b88b9176851e..26c0d4ab400d237be152da27b190939489814d02 100644 --- a/packages/xpub-edit/src/components/Editor.js +++ b/packages/xpub-edit/src/components/Editor.js @@ -28,8 +28,17 @@ class Editor extends React.Component { }), attributes: { class: classnames(baseClasses.ProseMirror, classes.ProseMirror) + }, + handleDOMEvents: { + blur: this.props.onBlur ? view => { + this.props.onBlur(view.state.doc.content) + } : null } }) + + if (this.props.autoFocus) { + this.view.focus() + } } dispatchTransaction = transaction => { diff --git a/packages/xpub-edit/src/components/HtmlEditor.js b/packages/xpub-edit/src/components/HtmlEditor.js index 3adb67dc8b3e8bc56ea9b0a8f3237890e1f90796..9f6ff1456d5d854eb57265070f0712d088f9155a 100644 --- a/packages/xpub-edit/src/components/HtmlEditor.js +++ b/packages/xpub-edit/src/components/HtmlEditor.js @@ -26,7 +26,7 @@ const serializer = schema => { class HtmlEditor extends React.Component { componentWillMount () { - const { value, onChange, options } = this.props + const { value, onChange, onBlur, options } = this.props const { schema } = options const parse = parser(schema) @@ -37,6 +37,10 @@ class HtmlEditor extends React.Component { this.onChange = debounce(value => { onChange(serialize(value)) }, 1000, { maxWait: 5000 }) + + this.onBlur = value => { + onBlur(serialize(value)) + } } render () { @@ -50,6 +54,7 @@ class HtmlEditor extends React.Component { placeholderClassName={placeholderClassName} title={title} onChange={this.onChange} + onBlur={this.onBlur} /> ) }