Replies: 3 comments 2 replies
-
Nice idea, thanks. We'll discuss it and probably include it in one of the next releases. |
Beta Was this translation helpful? Give feedback.
-
@r-Larch appreciate you sharing this. @neSpecc was this included in a recent release? Struggling to run openai api streaming directly into the editor letter by letter/word by word etc - it can/will update upon competition, but that can take anywhere from 10-20 seconds leaving the end user confused. Alternatively if this feature is not included, are there any other leads on streaming directly into editor.js via the openai api? Thanks. |
Beta Was this translation helpful? Give feedback.
-
Hi @r-Larch super appreciate your reply. I managed to get the openai api text streaming into the editor without any flickering based on your code, but have found myself exactly where you were prior to moving on - non-stop problems/bugs with editor.js, resulting in tons of additional code/plugins attempting to get the editor to work as an production ready AI text editor. While researching alternative solutions - Tiptap, Novel (based on Tiptap), Plate all look promising, and now based on your recommendation, I'll explore Slate too. Thanks again René - wish you well with your project! |
Beta Was this translation helpful? Give feedback.
-
Motivation for the change
Look at ChatGPT and how it writes answers letter by letter. It does so by using Server-sent events (SSE) where small text parts are transmitted one by one.
It would be nice to be able to render such a SSE stream into the editor without seeing it flickering all over the place.
You see the it working, without flickering, because of overwrites in BlockTools and a custom render function!
Editorjs-granular-updates.mp4
Current APIs:
Calling
editor.render({ blocks: [..] })
results in recreating all blocks in the editor, so calling it over and over again lets the editor flicker where the contents of the editor become invisible because of too much rerendering.Trying to only update or insert blocks that have changed
Doing so results in less flickering, but to update a block, it needs to be recreated and this lets the block flicker equally as in option 1.
See the example Code
How I solved it with current APIs
Thanks to the
Paragraph
,Header
,List
, andCode
block tools having aset data(value)
property it is possible to just change the block data without recreating the whole block.Sadly the
set data(value)
property is not standard API and can not be called throughBlockAPI
becauseBlockAPI
only exposes acall
method to call functions, not property setters!So I had to overwrite these tools to add a
setData(value)
method where I call the data setter to apply granular data changes.NOTE Only the aforementioned BlockTools have this setter, other BlockTools like
Table
doesn't have such a setter and it would be necessary to implement the set data functionality with a heavy overwrite and this would be difficult to maintain.See the example Code
Possible improvements for Editor API and Block API
setData(value)
method toBlockTool
interface.setBlockData(value)
method toBlockAPI
setData(value)
method.editor.render(data)
to natively perform granular update.setData(value)
method.Beta Was this translation helpful? Give feedback.
All reactions