Draft-js: Feature request: way to detect entity deletion

Created on 13 Sep 2019  Â·  4Comments  Â·  Source: facebook/draft-js

Feature request: It would be helpful if there were a way to detect an entity deletion as it happens.

What is the current behavior?
The only way I've been able to detect an entity deletion as it occurs is to convert both current state and updated state to raw, and compare the entityMap keys. The problem with this is the conversion can be a fairly heavy computational task for longer documents.

The documentation on ContentState#getEntityMap says that in upcoming v0.11.0 the map returned will be an Immutable ordered map of DraftEntity records. but this doesn't seem to be the case yet. This would certainly do the trick in allowing a straightforward way to compare the current entity list to the new entity list.

Another option might be for entity deletion to return an EditorChangeType along the lines of remove-entity, though then you'd still have to do the legwork of figuring out which entity was removed.

What is the expected behavior?
Some more intuitive way to detect an entity deletion as it happens.

Which versions of Draft.js, and which browser / OS are affected by this issue? Did this work in previous versions of Draft.js?
0.11.0 on MacOS 10.14

Most helpful comment

I would benefit from this feature as well! I have a list of entities scattered throughout my text that are essentially references to timestamps in an external source, and I need to detect when a reference is deleted so I can update the external source.

All 4 comments

Some sort of callback method to call when an entity is deleted would be extremely helpful to create more advanced features.
E.g. I'm currently making an editor with footnote support, where the in-text footnote numbers are rendered as entities. It would be very helpful to have a way of automatically re-ordering the numbers when a footnote is deleted.

I would benefit from this feature as well! I have a list of entities scattered throughout my text that are essentially references to timestamps in an external source, and I need to detect when a reference is deleted so I can update the external source.

Has there been any progress on this feature? I am currently working on a project that would really benefit from it.

For what it’s worth there is #2038 open about ContentState#getEntityMap returning the documented type.

Alternatively I’ve never had a need myself but it should be possible for an implementation to have their own registry of "active entities" and update that when the entities’ decorators are un-mounted on deletion?

Was this page helpful?
0 / 5 - 0 ratings