-
Notifications
You must be signed in to change notification settings - Fork 21
Closed
Labels
enhancementNew feature or requestNew feature or request
Milestone
Description
Follow-up to #87. At the moment, entity components are only given a small amount of data about an entity for rendering:
draftjs_exporter/draftjs_exporter/entity_state.py
Lines 48 to 58 in 764d377
props = entity_details['data'].copy() | |
props['entity'] = { | |
'type': entity_details['type'], | |
} | |
nodes = DOM.create_element() | |
for n in self.element_stack: | |
DOM.append_child(nodes, n) | |
elt = DOM.create_element(opts.element, props, nodes) |
There are a few more problems here:
- The shape of the props is different than how this is stored in the Draft.js
entityMap
. - The entity
data
is given as the top-level props, which makes it impossible to add extra props without risking overwriting the entity data (say if the entity has a field calledtype
that does something different from the entity type).
We should refactor this to something like:
props = {}
props['entity'] = entity_details
props['entity']['key'] = key
props['block'] = block
props['blocks'] = blocks
# (Potentially the `entity_range` as well?)
This way, it's easy to add arbitrary props without risking overwrites. The components get full access to the entity data, mutability, type, and key. And to the current block and blocks list, like styles, decorators, blocks.
Compared to the changes introduced in #90, this would be a breaking change, so should be considered carefully. Users of the exporter will have to rewrite their renderers slightly to use the new props shape.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request