typewriter-editor / typewriter

A rich text editor based off of Quill.js and Ultradom, and using Svelte for UI.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Change Editor API?

jacwright opened this issue · comments

We have pretty much cloned the Quill.js API, but this was just a default to get things working. We don't need to keep it.

Differences between Quill and Typewriter is that insertEmbed and insertText allow deleting text at the same time as inserting. And there is a transaction method which allows multiple edits to be collated into a single change. insertText, deleteText, etc.

Another alternative I saw with Slate.js is their changes API. Instead of insert, delete, etc. being on editor we could have them be part of a change object. Right now Delta is our change object and does not store selection. We could extend or wrap Delta with a Change and add methods for editing the contents and selection. An extreme example from Slate is:

change
  .focus()
  .selectAll()
  .delete()
  .insertText('A bit of rich text, followed by...')
  .moveToOffsets(10, 14)
  .addMark('bold')
  .collapseToEndOfBlock()
  .insertBlock({ type: 'image', isVoid: true })
  .insertBlock('paragraph')

Thoughts?

commented

The ability to chain like that is one of the great features of JS, I don't know how much work it will be. It's up to you @jacwright

A TextChange object allows chaining of changes with the ability to add them in one commit. The Editor still has most APIs that most people need for ease-of-use and uses the TextChange API. Best of both worlds. It isn't as expressive (verbose?) as Slate, which I like.