share / sharedb

Realtime database backend based on Operational Transformation (OT)
Other
6.2k stars 448 forks source link

Is it possible to use just Quill deltas without Quill in ShareDB? #559

Open GermanJablo opened 2 years ago

GermanJablo commented 2 years ago

The documentation for the rich text type indicates that it is based on quilljs deltas.

However, the example in shareDB uses the Quill editor entirely, and I haven't found any examples online that don't.

I see that Quilljs is an editor with some quirks that I don't like:

I would like to know if I can create my custom editor with content-editable and connect ShareDB to it using only quill deltas instead of requiring the full quill editor. If possible, would you recommend doing it? Or will I find myself with a headache trying to solve difficulties that Quilljs has already solved?

On the other hand, if it is not possible to use rich-text type without QuillJs, then I wonder what is the advantage of using rich-text type, since from what I see when connecting quilljs to a WebSocket the RTC already works fine without needing ShareDB. Maybe I'm not understanding well.

related reading https://github.com/quilljs/quill/issues/993

alecgibson commented 2 years ago

Yes you can absolutely use the rich-text type without needing Quill. A trivial example with a plain text input might look something like:

let content = new Delta()

textArea.addEventListener('input', () => {
  const newContent = new Delta().insert(textArea.value)
  const diff = content.diff(newContent)
  content = newContent
  doc.submitOp(diff)
})

However the difficult part is dealing with rich text formatting, which is left as an exercise for the reader.