GithubHelp home page GithubHelp logo

Support complex decorators about redraft HOT 8 CLOSED

lokiuz avatar lokiuz commented on August 16, 2024
Support complex decorators

from redraft.

Comments (8)

lokiuz avatar lokiuz commented on August 16, 2024

This is something worth looking into! Would like (thought it might be bit tricky) to handle it same way as draft does it internally as you suggested.

This would probably mean that by supporting rendering with any DraftDecoratorType it should be possible to just fallback to drafts CompositeDraftDecorator ( https://github.com/facebook/draft-js/blob/0c609d9d3671fdbbe2a290ed160a0537f846f08e/src/model/decorators/CompositeDraftDecorator.js ) to render an array of { strategy, component } decorators.

from redraft.

mxstbr avatar mxstbr commented on August 16, 2024

Yep that sounds great!

from redraft.

lokiuz avatar lokiuz commented on August 16, 2024

Guess I have a working version. 😄

Some things are still missing like contentState. It should be passed both to DecoratorComponent and the getDecorations method of the Decorator class.

Additionality it adds draft-js as a dependency and I'm not sure if that makes much sense as redraft was supposed to provide an alternative way to render draft-js raw. Either I could include a simplified CompositeDraftDecorator in redraft (with no Immutable.js etc...) or go all the way include draft-js and fix most inconsistencies with the draf-js api.

Also should probably add some test cases with a custom Decorator class passed through options.

from redraft.

mxstbr avatar mxstbr commented on August 16, 2024

Niiice!

I'd certainly prefer if it didn't include Draft as a dependency, but obviously building your own implementation of CompositeDraftDecorator is going to be a bunch harder... 🤔

from redraft.

lokiuz avatar lokiuz commented on August 16, 2024

Actually the CompositeDecorator doesn't depend much on the rest of the draft-js so implementing it in redraft was just basically swapping the List for a stub with a toArray method.

I decided to put flow types along with it to keep the differences as minimal as possible. (Might also be a good idea to add flow to the rest of the project.)

Lastly since redraft was missing ContentState to pass into getDecorations and decorator components I added an option to pass draft-js convertFromRaw into redraft options.

Still needs some tests.

from redraft.

mxstbr avatar mxstbr commented on August 16, 2024

Awesome, that's great! Can't wait for this to land, amazing work 👏

from redraft.

lokiuz avatar lokiuz commented on August 16, 2024

Added some minimal testing and shipped it in 0.9.0 🎉

from redraft.

mxstbr avatar mxstbr commented on August 16, 2024

Amazing, thank you! 🎉

from redraft.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.