Draft-js: DraftEntityType needs to be loosened

Created on 13 Dec 2016  路  6Comments  路  Source: facebook/draft-js

From the doc that introduces Entities, it said

type: A string that indicates what kind of entity it is, e.g. 'LINK', 'MENTION', 'PHOTO'

But in the source code, the type of an Entity is limited to LINK, TOKEN, PHOTO or IMAGE, as seen in src/stubs/ComposedEntityType.js.

So my questions:

  • Is the entity type supposed to be customizable?
  • I'm considering using Flow in my projects, will a custom entity type, say VIDEO, break Flow's type checking?
  • What's the difference between PHOTO and IMAGE? I didn't find any explanations on that.
documentation question

All 6 comments

Agreed. Not only does it appear that you can specify any custom entity type you want, it seems like this is what you're supposed to do, that it is the primary identifier of what your entity is. The Draft JS Plugins project uses custom ones (e.g. sticker, emoji).

I came to the same conclusion. Typing is "broken" but implementation works as intended when I use custom type.

I have a FONT_COLOR entity type.
I want my colors to be dynamic and not predefined (for the later, inline styles would be sufficient), so I need to store selected color data.

So I think it is a doc & typing issue.

Same issue here, I have to add // $FlowFixMe to be able to use what I want for entity type. I guess DraftEntityType should be changed to string.

yep. This flowtype is wrong imo, will bring this up :+1:

Thanks for raising this! Loosening the Flow type here seems reasonable to me, so going to merge @juliankrispel's PR :)

This change is mentioned in the release notes for 0.10.5 but it seems like it did not make it into the release.

@niveditc

Was this page helpful?
0 / 5 - 0 ratings