springload / draftail

📝🍸 A configurable rich text editor built with Draft.js
https://www.draftail.org/
MIT License
616 stars 64 forks source link

Support advanced customisations to block rendering #169

Closed thibaudcolas closed 5 years ago

thibaudcolas commented 5 years ago

From the blocks documentation:

More advanced blocks, requiring custom React components, aren't supported at the moment. If you need this, feel free to create an issue.

What is the current behavior?

At the moment, for block types, the editor only supports customising their element, and auto-generates a CSS class so the blocks can be styled. This is very limited: it's impossible to make a block that’s not text-based, or to enhance a text editing blocks with extra UI.

What is the expected behavior?

It should be possible to use the more advanced Draft.js APIs for block rendering in conjunction with the blockType API:


Use cases

Here are specific use cases I would like those new APIs to make possible:


Implementation

Support for wrapper blocks should be straightforward. Add it to the getBlockRenderMap: https://github.com/springload/draftail/blob/bfb2b3d3eedbcf1ab1f61c25328752495b77ecb0/lib/api/behavior.js#L34-L53

Support for custom blocks should also be straightforward, overriding the blockRenderer: https://github.com/springload/draftail/blob/bfb2b3d3eedbcf1ab1f61c25328752495b77ecb0/lib/components/DraftailEditor.js#L459-L488

The use cases above should inform what configuration should be allowed for custom blocks, and what props need to be provided to them (potentially the same as given to entity components?)

thibaudcolas commented 5 years ago

171 comes with the APIs needed to do the above