You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
For a current project, I need to create some custom blocks that automatically change depending on the editor's content. One such block is a table of contents, which should be updated dynamically in real time as soon as headings are added / removed / modified anywhere in the editor.
Describe the solution you'd like
It would be extremely useful to have a way to observe some changes in the editor, specifically related to some block types. For instance, an API on the editor that runs a function as soon as a block of type heading is added / removed / modified.
Describe alternatives you've considered
There are alternatives but none are ideal:
Re-implementing the heading types (or other blocks if needed) and trigger an event manually when they are updated
Putting a listener on the editor to watch for any change, which would require to traverse the entire AST to find headings and make a diff against the previous state
Showing a button to manually refresh the ToC block's content, but this requires manual user interaction
Additional context
I gave an example with headings but it could really be anything else.
I have absolutely no idea how hard such a feature would be to implement in BlockNote
The text was updated successfully, but these errors were encountered:
We'd love to work on this as I think it would unlock all sorts of interesting scenarios.
I think we should implement it with some additional requirements in mind:
metadata about the source of the change (e.g. remote update, paste, user edit (typing), if we have this info)
in the case of a remote update: who made the change (not sure if we have this)
besides add / delete / update, we also need to think about what happens when a child block of a parent block has changed
Top of head; I see two ways to implement this:
derived from prosemirror changes (listen to transactions and detect changed ranges -> transform to the API we need)
alternatively, we could iterate through all blocks in the document with nodeToBlock and see which blocks have changed. Because we cache the return value of nodeToBlock, we should be able to compare this by reference, and it might not be as "expensive" as it sounds
Is your feature request related to a problem? Please describe.
For a current project, I need to create some custom blocks that automatically change depending on the editor's content. One such block is a table of contents, which should be updated dynamically in real time as soon as headings are added / removed / modified anywhere in the editor.
Describe the solution you'd like
It would be extremely useful to have a way to observe some changes in the editor, specifically related to some block types. For instance, an API on the editor that runs a function as soon as a block of type
heading
is added / removed / modified.Describe alternatives you've considered
There are alternatives but none are ideal:
Additional context
I gave an example with headings but it could really be anything else.
I have absolutely no idea how hard such a feature would be to implement in BlockNote
The text was updated successfully, but these errors were encountered: