implement quill binding for y-text

This commit is contained in:
Kevin Jahns
2018-02-26 02:18:39 +01:00
parent da748a78f4
commit 248d08be30
17 changed files with 713 additions and 1090 deletions

View File

@@ -0,0 +1,37 @@
import Binding from './Binding.js'
function typeObserver (event) {
const quill = this.target
quill.update('yjs')
this._mutualExclude(function () {
quill.updateContents(event.delta, 'yjs')
quill.update('yjs') // ignore applied changes
})
}
function quillObserver (delta) {
this._mutualExclude(() => {
this.type.applyDelta(delta.ops)
})
}
export default class QuillBinding extends Binding {
constructor (textType, quillInstance) {
// Binding handles textType as this.type and quillInstance as this.target
super(textType, quillInstance)
// set initial value
quillInstance.setContents(textType.toDelta(), 'yjs')
// Observers are handled by this class
this._typeObserver = typeObserver.bind(this)
this._quillObserver = quillObserver.bind(this)
textType.observe(this._typeObserver)
quillInstance.on('text-change', this._quillObserver)
}
destroy () {
// Remove everything that is handled by this class
this.type.unobserve(this._typeObserver)
this.target.unobserve(this._quillObserver)
super.destroy()
}
}