Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Draft JS to Lexical migration documentation #1641

Open
thegreatercurve opened this issue Apr 8, 2022 · 16 comments
Open

Add Draft JS to Lexical migration documentation #1641

thegreatercurve opened this issue Apr 8, 2022 · 16 comments
Labels
documentation Improvements or additions to documentation

Comments

@thegreatercurve
Copy link
Contributor

thegreatercurve commented Apr 8, 2022

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 thegreatercurve added the documentation Improvements or additions to documentation label Apr 8, 2022
@thegreatercurve thegreatercurve self-assigned this Apr 8, 2022
@carlosbaraza
Copy link

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.

@dacox
Copy link

dacox commented Apr 14, 2022

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
Copy link
Collaborator

trueadm commented Apr 15, 2022

@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
Copy link

tubbo commented Aug 9, 2022

@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
Copy link

Is there any ETA on this migration guide?

@meatnordrink
Copy link

meatnordrink commented Dec 12, 2022

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
Copy link

comp615 commented Mar 31, 2023

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
Copy link

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
Copy link

Nantris commented Apr 25, 2023

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
Copy link

Any update on this migration guide?

@KarafiziArtur
Copy link

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

@stee1house
Copy link

Any updates?

@AliHydr
Copy link

AliHydr commented Apr 26, 2024

Is this happening anytime soon?

@philipisik
Copy link

philipisik commented Jul 10, 2024

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
Copy link

lkyashu commented Jul 19, 2024

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.

@thegreatercurve thegreatercurve removed their assignment Aug 1, 2024
@lkyashu
Copy link

lkyashu commented Oct 2, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests