facebook / lexical

Lexical is an extensible text editor framework that provides excellent reliability, accessibility and performance.
https://lexical.dev
MIT License
19.9k stars 1.69k forks source link

Add Draft JS to Lexical migration documentation #1641

Open thegreatercurve opened 2 years ago

thegreatercurve commented 2 years ago

Following @trueadm announcement tweet, we had a few questions about how users could migrate from DraftJS to Lexical. The APIs are fairly incompatible, but providing some guidance on how best to migrate could help drive adoption.

carlosbaraza commented 2 years ago

It'd be nice to know how Facebook would approach this migration. Two things I can think of that would be really useful:

dacox commented 2 years ago

Following @trueadm announcement tweet, we had a few questions about how users could migrate from DraftJS to Lexical. The APIs are fairly incompatible, but providing some guidance on how best to migrate could help drive adoption.

@thegreatercurve Can you clarify - are they "fairly compatible", or actually "fairly incompatible"? The surface level onChange API looks similar, but I'm worried about entities, etc.

trueadm commented 2 years ago

@dacox Unfortunately, Lexical and Draft are not compatible when comparing the data models of both. Lexical has a tree structure that represents its state, which can be seen as like a DOM-like structure. Draft has a block + entities based structure, which is based on offsets. It's possible to build functions can that convert from Draft format to Lexical format, but in many cases where custom functionality as been built in Draft – it will have to be re-written for Lexical.

The other key difference is that Lexical isn't based on React, like Draft is. Lexical has its own reconciler and although you can use Lexical's DecorateNode to render React into a Lexical node, these are constrained to being non-text based – and we mark them as contenteditable="false" to ensure this is the case. It was always a bad design to "fight" Lexical for selection. So instead, some things can be ported to be custom nodes that extend Lexical's DecoratorNode, others will need to extend ElementNode and TextNode.

We'll look into writing a comprehensive set of guides around these concepts and hopefully this can help the folks out there migrate from Draft! :)

tubbo commented 2 years ago

@trueadm If that's true, could one convert to html first and then import that html into lexical? We persist the draftjs format in our DB so if we wanted to move to lexical, rewriting everything by hand just wouldn't be an option. There are tools for the conversion process on both sides, so at least for more simple jobs I think this could work out.

jlombardo-tableau commented 2 years ago

Is there any ETA on this migration guide?

meatnordrink commented 1 year ago

We'll look into writing a comprehensive set of guides around these concepts and hopefully this can help the folks out there migrate from Draft! :)

I think that, even if "migration" will basically mean re-writing everything, just having a section in the docs that recaps the info available in this thread (whether migrating is possible, why/why not, where and how the APIs differ) would be helpful, at the very least for people considering whether to even try switching to Lexical from draft-js.

comp615 commented 1 year ago

A library to convert from a Draft state to Lexical state.

Carlos' assessment seems spot on and wanted to add a +1. Although you obviously have to rewrite the plugins, having a skeleton data state migrator would be extremely helpful in enabling people to update to Lexical from Draft (instead of going through markdown or something more complex / lossy). It's hard to figure out how we'd go about getting onto Lexical right now since we store the raw DraftJS JSON.

alfaproject commented 1 year ago

We also persist the blocks in our database so a migration isn't exactly easy right now. If there was a way to convert from blocks and to blocks then we could at least have an easier migration path. Does anyone know if anyone made utility functions for that?

Nantris commented 1 year ago

Any update on this? Having the DraftJS community start to use Lexical would be a huge boon for adoption and accelerate open source contributions.

You can see here that DraftJS is the second most used editor after Quill, and having all of those users enter the ecosystem would be fantastic.

karismatic-megafauna commented 1 year ago

Any update on this migration guide?

KarafiziArtur commented 1 year ago

It will be nice to have the migration also for our team

stee1house commented 10 months ago

Any updates?

AliHydr commented 6 months ago

Is this happening anytime soon?

philipisik commented 4 months ago

A little bit late to the party, but in case you are looking to migrate off of draft.js, we at Tiptap have a library for migrating draft.js content into Tiptap: https://github.com/ueberdosis/draft-js-to-tiptap

lkyashu commented 4 months ago

Is there any update on this ticket. Either of the option mentioned below by @carlosbaraza would do the trick to allow developers and business with guided adoption and finally take the decision to make the switch.

It'd be nice to know how Facebook would approach this migration. Two things I can think of that would be really useful:

  • A library to convert from a Draft state to Lexical state.
  • A migration guide to create a plugin from a custom Draft plugin.
lkyashu commented 1 month ago

Here is a script that works for migrating draftjs Data (block and entity) to lexical content. It handles the basic headers, lists and inline style mapping while keeping the formatting offset and combination (using bit operations). It might not be perfect (open for suggestions) and also does not handle any custom mapping or all the formats but might be a good place to start.

https://playcode.io/2029423 - hope this helps for now at the very least to explore the editor.