add transaction event

This commit is contained in:
Philipp Kühn
2019-05-31 12:00:45 +02:00
parent b54a341dec
commit 2c86db883b
2 changed files with 10 additions and 1 deletions

View File

@@ -29,7 +29,7 @@ export default class Collaboration extends Extension {
} }
}, this.options.debounce) }, this.options.debounce)
this.editor.on('update', ({ state }) => { this.editor.on('transaction', ({ state }) => {
this.getSendableSteps(state) this.getSendableSteps(state)
}) })
} }

View File

@@ -40,6 +40,7 @@ export default class Editor extends Emitter {
dropCursor: {}, dropCursor: {},
parseOptions: {}, parseOptions: {},
onInit: () => {}, onInit: () => {},
onTransaction: () => {},
onUpdate: () => {}, onUpdate: () => {},
onFocus: () => {}, onFocus: () => {},
onBlur: () => {}, onBlur: () => {},
@@ -49,6 +50,7 @@ export default class Editor extends Emitter {
this.events = [ this.events = [
'init', 'init',
'transaction',
'update', 'update',
'focus', 'focus',
'blur', 'blur',
@@ -311,6 +313,13 @@ export default class Editor extends Emitter {
this.view.updateState(newState) this.view.updateState(newState)
this.setActiveNodesAndMarks() this.setActiveNodesAndMarks()
this.emit('transaction', {
getHTML: this.getHTML.bind(this),
getJSON: this.getJSON.bind(this),
state: this.state,
transaction,
})
if (!transaction.docChanged) { if (!transaction.docChanged) {
return return
} }