14 ms·
Facebook open sources Lexical, an extensible text editor library
- slappy7 4y agoDoes it work on Android?
- trueadm 4y agoIt does. If you get the chance to try Lexical out, please do let us know of any issues you face when using Android, as I'm sure there are some we've yet to find yet.
- hiimshort 4y agoOne quirk for you: using my samsung keyboard with swipe typing, spaces aren't added between words. Not sure at all what causes it. The only other place I have seen this happen is url input in the browser (which I believe is intentional).
- trueadm 4y agoAwesome! Thank you for this. Would you be able to upload a video or maybe add more context in a Github issue? It's really difficult getting Android right. The combination between browser + keyboard + OS version + keyboard language, it just makes it so much harder than it should be for Android. So any additional context you can provide will be a MASSIVE help. :)
- hiimshort 4y agoAdded an issue here: https://github.com/facebook/lexical/issues/1699 https://github.com/facebook/lexical/issues/1699 And, as a side note, great work on this project. I had previously built a wysiwyg system from Slate and a custom plugin system; Lexical seems like a solid progression and has some interesting ideas like using React components the way it does to facilitate editor plugins. May have to try creating a Preact wrapper so I can use it in my projects.
- netghost 4y agoWhat's your approach to Android support? Are you relying on mutation events, `beforeinput`, something else? I built a really solid android adapter (after spilling gallons of tears) for our Draft.JS fork, and might have a few tips if it's helpful.
- zurfyx 4y agoWe listen to a few typing related events and do some computation from here: keydown, input, beforeinput. Android, contrary to any other device, mostly relies on composition so Lexical makes sure to handle and flush these events accordingly. If you're curious, this is where it all starts - https://github.com/facebook/lexical/blob/main/packages/lexical/src/LexicalEvents.js https://github.com/facebook/lexical/blob/main/packages/lexic...
- dang 4y agoRelated: Lexical is now open-source (web text-editor) - https://news.ycombinator.com/item?id=31017943 https://news.ycombinator.com/item?id=31017943 - April 2022 (13 comments)
- rattray 4y agoHow does this compare to others like Monaco, Ace, etc?
- csande17 4y agoDespite the name (and the misleading-at-first-glance "demo" on the home page), Lexical appears to be a rich text editor like Quill or ProseMirror, not a code editor.
- trueadm 4y agoYou could definitely build a code editor with Lexical. There's already a lot of interest in the community to add plugins around Lexical to match that of ProseMirror. It might not be there right now, but the foundations that make it possible aren't missing.
- endisneigh 4y agoIt's worth mentioning that it seems like you need to use react with this.
- trueadm 4y agoYou don't need React. Lexical has no dependencies, so you can build bindings for your framework/library of choice. There are folks working on a SolidJS implementation right now. You could also do it with VanillaJS if you wanted too. The reason we have React bindings from the start, is because we needed these internally at Meta.
- distrill 4y agoGP may be responding to the fact that the vanilla quick start page is empty while the react one is not https://lexical.dev/docs/getting-started/quick-start https://lexical.dev/docs/getting-started/quick-start
- trueadm 4y agoYeah, we're still working on our docs. Watch this space! :)
- kingcharles 4y agoIt would seem the very first thing you would do is provide an example for vanilla JS so that everyone could get started. It is impossible to use this at all for the large proportion of the world that isn't using React as we can't even see a single example. If it's so complicated to use that it takes more than a minute of vanilla JS coding to initialize it, then I don't think I'm interested, thanks all the same.
- motoxpro 4y agoThey use it internally, why would they rebuild it in vanilla before they released it? Sounds like they are working on it even though it's of no use to them.
- Rodeoclash 4y agoHow does it compare with DraftJS?
- trueadm 4y agoI've responded to the same question https://news.ycombinator.com/item?id=31022152 https://news.ycombinator.com/item?id=31022152. :)
- johnny35 4y agoHow does this fit in with Draft.js? Is it a successor? Seems like it has to connect in some way...
- trueadm 4y agoInternally, we've been replacing Draft.js with Lexical. To be clear though, they're different projects with little API compatibility. We hope to add some docs explaining how we've approached our upgrade path in the future. To expand on this further, I'll pull this from another HN thread: Draft.js was built a long time ago when many of the concerns around making contentEditable work stemmed from patching browser-support. Today, it's nowhere near as bad. We can leverage modern events and we can try and tackle things from a different point of view. One of the core things we've tried to do is make the developer experience and performance better. DraftJS pulled in a lot of JavaScript and much of it was hard to reason with because of the lack of types. ImmutableJS just didn't scale how we would have liked it to, and from our experience, developers didn't really like using it all that much. DraftJS also had a block based approach, which quickly fell apart when you wanted to do something more complex. Not to mention compatibility with React 18+ and the countless issues with having to depend on ReactDOM for rendering when fighting with browser extensions that want to take over control of the DOM from Draft. With these things in mind, we looked at how we could keep the good ideas from Draft, Slate, ProseMirror and also invent some new ideas of our own. Lexical doesn't have any dependencies, so you can use it with Svelte or Solid (once their bindings have been created), or any other framework of your choice. Lexical also doesn't need ImmutableJS, which means the APIs are fully typed in Flow and TypeScript, reducing issues. Lexical is also around 22kb gzip+min, so it's far smaller than Draft. Typing performance in our testing is around 30-70% faster compared to Draft.
- nojs 4y agoI think it would be helpful to explicitly say that draft.js is deprecated here [1]. I was recently caught out by this, and started using draft.js without realising it’s been abandoned. 1. https://draftjs.org/ https://draftjs.org/
- 4y ago
- zaptheimpaler 4y agoWhy did Facebook need to build a text editor? Is this used somewhere in their products?
- deleted 4y ago[deleted]
- trueadm 4y agoIt's used on Facebook, Messenger, Workplace, Instagram and soon will be rolled out for WhatsApp web.
- vsroy 4y agoLet's say I'm building a stack overflow style editor (you type markdown and it gets rendered in a preview tab) -- would there be any reason to use lexical?
- trueadm 4y agoYeah, you could easily do that. We do the exactly that right now for Workplace. You could also roll with a `<textarea>` but that can be limiting if you want additional functionality further on down the line – such as mentions or inline markdown shortcuts.
- vsroy 4y agoWhen you say inline markdown shortcut, is an example of that pressing Ctrl-B on some highlighted text in order to surround it with asterisks? And is the idea of mentions that we can use Lexical to provide nice things like pop-up auto-complete of a username / automatically transform the username into a link inside of the input text?
- vsroy 4y agoAnother follow-up question: Do you think Lexical would be a good fit for a "live preview" type editor? Live preview = the editor is WYSIWYG but the storage format is Markdow Example: https://help.obsidian.md/Live+preview+update https://help.obsidian.md/Live+preview+update
- andygcook 4y agoOne of the big frustrations with DraftJS is that Facebook moved on (which is understandable), but the core repo wasn’t given control to the community, so patches and updates couldn’t be pulled in. Obviously it’s open source and could be hard forked, but that’s not ideal. I’d be curious if there are plans internally to make sure Lexical continues to be supported by Facebook and doesn’t end up with the same fate.
- trueadm 4y agoI completely understand. I can't guarantee anything, no on can in software. However, we do have a dedicated full-time team working on Lexical. DraftJS never had that, it only had a few part-time maintainers at Facebook.
- andygcook 4y agoAgreed there’s no guarantees in software, but that’s helpful context that there’s a dedicated team working on Lexical. Thanks for sharing and also for giving back to the software community by open sourcing the code. Editors are tough and every thoughtful approach like this that’s publicly available to use helps push them forward.
- lhorie 4y agoHey Dominic, good to see you :) I take you moved from the React team to this dedicated Lexical team?
- 4y ago
- melony 4y agoDo you have any support for collaborative editing such as with Yjs or Automerge?
- trueadm 4y agoYep, we have full support with Yjs. https://github.com/facebook/lexical/tree/main/packages/lexical-yjs https://github.com/facebook/lexical/tree/main/packages/lexic...
- YousefED 4y agoVery exciting! Great to see support for yjs. Does fb use yjs internally? Would love to learn more about this!
- cetra3 4y agoIs this in production on Facebook? I have not had the greatest experiences with their rich text editor, from not being able to remove styling on subsequent lines, to getting a nice little note saying that you can't edit rich text posts on mobile. Hoping lexical brings some improvements here.
- trueadm 4y agoIt is in production at Facebook. We're slowly rolling out to more surfaces, replacing our existing DraftJS implementations as we go. We've noticed a big improvement internally from doing so, both in terms of less bugs but also performance and accessibility.
- petilon 4y agoThe examples shown on the site are code editing. Which puts it in direct competition with the more established Monaco from Microsoft [1]. Competition is welcome, but the description sounds like this is more of a library than a finished product (which Monaco isn't), and if so, some examples showing how to take advantage of that would have been helpful. [1] https://microsoft.github.io/monaco-editor/ https://microsoft.github.io/monaco-editor/
- trueadm 4y agoBy the examples, do you mean the fact we are using Codesandbox embed to show code examples of the editor itself? Lexical definitely has the foundational requirements capable of building a CodeMirror or Monaco editor, but that wasn't our initial target with this library. That doesn't mean that we don't expect the community to push it that way in the future, we fully expect that. Let's see how things go, competition is healthy! :)
- petilon 4y agoMy mistake... I thought the code editor was implemented using Lexical. The real demo is here: https://lexical-playground.vercel.app/ https://lexical-playground.vercel.app/ (Edit) I think you should put this demo on the front page and the code sample on some other page. I was expecting to see the demo on the home page.
- 4y ago
- jasonshen 4y agoGot to work briefly on this project and really excited to see it reach the public! Congrats to trueadm and the whole team on this.
- deleted 4y ago[deleted]
- alephnan 4y agoThis feels half baked and confusing. More than half docs page are blank: - https://lexical.dev/docs/concepts/commands https://lexical.dev/docs/concepts/commands - https://lexical.dev/docs/getting-started/quick-start https://lexical.dev/docs/getting-started/quick-start - https://lexical.dev/docs/concepts/extending-nodes https://lexical.dev/docs/concepts/extending-nodes - https://lexical.dev/docs/concepts/editor-state https://lexical.dev/docs/concepts/editor-state - https://lexical.dev/docs/api/lexical https://lexical.dev/docs/api/lexical - https://lexical.dev/docs/api/lexical-selection https://lexical.dev/docs/api/lexical-selection - https://lexical.dev/docs/api/lexical-text https://lexical.dev/docs/api/lexical-text - https://lexical.dev/docs/api/lexical-offset https://lexical.dev/docs/api/lexical-offset > An extensible text editor library > Lexical is an extensible JavaScript web text-editor framework The terminology is also confusing. In some places its called a library. In other places it's called a framework. Then other commenters mentioned that the demo gives the impression that it is a full package editor, but is just pegging onto CodeMirror. That's clarified here? > It doesn't directly concern itself with UI components > core of Lexical is ... a DOM reconciler that takes a set of editor states, diffs the changes, and updates the DOM according to their state. > Lexical is designed for everyone. It follows best practices established in WCAG These are weird and conflated set of buzzwords. Why should something that isn't concerned with UI components be concerned with accessibility best practices? I'm building my own text editor and I thought VSCode was impressive enough. See this well written article about their text buffer reimplementation: https://code.visualstudio.com/blogs/2018/03/23/text-buffer-reimplementation https://code.visualstudio.com/blogs/2018/03/23/text-buffer-r.... Then I realized Ace.js has some even crazy magic implementation that can handle millions of LoC files without lag. Can Lexical handle 100k+ LoC? Normally I'd benchmark myself, but in this case I don't see other compelling reasons too. The author mentioned the 22kB bundle size is less than Draft.js by Facebook, but Slate.js is 10kB and much more mature. Some features that could make Lexical have "powerful features" as claimed: UNDO/REDO manager (without storing the entire state on the stack, which is just not scalable on memory), possibly implementing the Command pattern, then make easy consumption of collaborative editing such as with Operational Transform.
- acywatson 4y agoThank for the feedback - we're definitely still working on the docs. > These are weird and conflated set of buzzwords. Why should something that isn't concerned with UI components be concerned with accessibility best practices? Are they? Support for speech-to-text technologies and IME/composition input, for example, are independent of UI components. > but Slate.js is 10kB and much more mature. Is it? https://bundlephobia.com/package/slate@0.77.0 https://bundlephobia.com/package/slate@0.77.0
- shubham_sinha 4y agoHow hard it’ll be to build a notion like UX using lexical ? Have been using editorjs for same
- zurfyx 4y agoRunning your own editor with built-in plugins does not take more than a few lines of code - see the playground code https://github.com/facebook/lexical/blob/main/packages/lexical-playground/src/Editor.jsx https://github.com/facebook/lexical/blob/main/packages/lexic... We already provide most common plugins out of the box (inc. lists and tables) but if you're planning to build a feature rich interface with many custom plugins it may take somewhat longer.
- porker 4y agoI'd like to hear anyone else's experience of building a Notion like editor (or any other block based/full page editor) Something guides never cover and I am stuck on is how to let users drop "widgets" into these RTEs. Think photos and galleries, where what is displayed in the editor is not what is present in the output (the real output could be 1+ React tags with attributes set) ; tables where the edit view is a spreadsheet & so on. When I try to build these I get stuck between the representation in the RTE, the final output, and the "edit mode" in the RTE which may be in its own window.
- deleted 4y ago[deleted]
- philfreo 4y agoIs this meant to be a good drop-in rich-text/WYSIWYG editor? What is the format that it creates that you could then persist in a database? Does it just save its state in HTML or some JSON format or what?
- acywatson 4y agoThe core Lexical library is really a framework for building such editors. However, we also provide many common rich-text features out-of-the-box via separate packages, such as @lexical/rich-text. We also expose bindings for React (and hope to have them for other frameworks soon). Check out the lexical-playground package on GitHub for an example of how you can create a rich-text editor by adding plugins to the LexicalComposer component in @lexical/react.
- Thexyman 4y agoAnd how is the data saved on the BE? is it the case we can save it as JSON or HTML?
- rvnx 4y agoReally great work! Especially the time travel functionality feels very innovative. Thank you for it.
- lewisjoe 4y agoHi Dominic, thanks for open sourcing the library. I have quite a few questions though: 1. Marijn has built an awesome open source richtext library (https://prosemirror.net/ https://prosemirror.net/) which has a huge plugin ecosystem and bindings with a bunch of front-end frameworks (including React). Is there any specific motivation behind building one from scratch? 2. How is this different from Facebook's own DraftJS lib? 3. What's the story of realtime collaboration support with OT/CRDT? Prosemirror had this in mind when designing its state model and delta model, so it comes with out of the box support for realtime collaborations. Can we expect the same with Lexical? 4. What's the cross platform strategy for Lexical? If I store the editor's state as JSON on the server, how will I render it on devices and native desktop apps? We've built our own library on top of Prosemirror to power the comments and feedback sections of Zoho Writer - https://writer.zoho.com https://writer.zoho.com I'm always looking out for better approaches/alternatives in this space and I'm curious how different Lexical is. Thanks!
- zeroonetwothree 4y agoFB essentially stopped supporting DraftJS. I think they don't use it much internally anymore. This seems to be the replacement.
- zurfyx 4y agoFor 1. 2. see @trueadm's answer here - https://news.ycombinator.com/item?id=31022152 https://news.ycombinator.com/item?id=31022152 3. Lexical is not strictly tied to collaboration but its plugin system was built to be extensible enough to cater all developers needs. Collaboration is just another plugin (@lexical/yjs) and does listen and perform the conversion every time there's changes in the EditorState. This model of independent plugins that can be plugged-and-played without further ado also simplifies devX as collaboration can be added later when the application is mature without the need to rethink any of the plugins that were originally created for non-collab plain/rich text. 4. Lexical Web is just the first of many. We want to port the API and fundamentals to various others platforms, including iOS for which we are already performing the initial set of testing. Cross-platform means the API, including Node's will look alike and EditorState and node's properties will be compatible even if behind the scenes the reconciler is constrained by the toolkit available on each platform (and doesn't render or behave 100% like Web's).
- vbezhenar 4y agoCool but I’ve found two bugs in the first few seconds of using it. Not ready for production IMO.
- deleted 4y ago[deleted]
- acywatson 4y agoIt would be awesome if you'd be willing to report them on GitHub :) https://github.com/facebook/lexical/issues/new?assignees=&labels=Status%3A+Unconfirmed&template=bug_report.md&title=Bug%3A+ https://github.com/facebook/lexical/issues/new?assignees=&la...
- graycat 4y ago> Lexical is comprised of editor instances that each attach to a single content editable element. Now if I only knew what was meant by attach, content editable, and element. Then I suspect I don't know what is meant even by comprised or editor. To me: A bit is a 0 or a 1. A byte is 8 bits in a sequence where by sequence we mean the order of the bits matters. Or in terms of pure math, a byte is not a set but is an 8-tuple. A file is a sequence of bytes in a file system on a computer. A leading example of such a file system is Microsoft's NTFS -- New Technology File System. Each byte can be regarded as a character in the Roman alphabet plus the digits 0-9, some punctuation symbols, and a little more, all as in the common, old definition called ASCII (American Standard Code for Information Interchange). An editor is a computer program that reads a file, displays the bytes as in the ASCII definition, permits a user of the program to modify the bytes and then writes the sequence of bytes to a file again on the file system. Uh, what is WCAG? In what sense "minimal"? For "rich-text features and markdown", by rich-text is meant Unicode, some technique in Microsoft's program Word, D. Knuth's word processing program TeX? For "markdown", I looked that up at Google and found "Markdown is a text-to-HTML conversion tool for web writers." So, in particular Markdown is a computer program. Okay. Again, from Google, apparently React is a JavaScript library for building user interfaces. I've been a heavy user of text editors for years. The editor Kedit is my most important tool. Macros? Sure, I've written about 300 of them. Text? I've got good experience with Knuth's TeX: Wrote about 50 macros for TeX and have published applied math I wrote with TeX. Uh, for a new Web site, I have written code, 100,000 lines of text in Microsoft's Visual Basic .NET using ASP.NET and ADO.NET and some for their "platform invoke". The 100,000 lines of code runs, apparently as intended. To type in the code, I just used Kedit -- worked great. But I did nothing with React or JavaScript. After reading the OP and more, I still have no idea what Lexical is, what it is for, what it can do as an editor, why anyone would use it, etc. I write this post because in my work far and away the biggest obstacle is getting meaningful information from the available documentation. E.g., I spent all of yesterday on the question, what is a video adapter card? Such cards go for $15, $65, or $500, but what the cards are and the differences are not made at all clear. Before that, I wasted several days working with Microsoft's programs COMP and FC, intended to compare files. I gave up and wrote my own program to compare files. Before that I wasted 1+ weeks mud wrestling trying to get an HP laptop and Windows 10 to write some DVDs -- after wasting several supplies of DVDs, DVD-R, DVD+R, DVD+RW, I concluded that somehow HP or Microsoft just doesn't want people writing DVDs -- millions of bytes of documentation and several YouTube videos didn't contradict that conclusion. Another problem, Microsoft's Outlook 2003, that I used successfully for years, now won't read my email from my ISP (Internet Service Provider). I wrestled with that problem for some days and finally decided to use Thunderbird. Reading email should not be difficult -- for some years I used my own email software I'd written just with the scripting language Rexx and its way to use TCP/IP. I mention these problems because they are, in the world of computing, simple, trivial, old, etc., should be taken for granted but all of them remain. The real, original, core creative work, with some pure and applied math, for my Web site has been fast, fun, and easy, but the real problem that has nearly ruined my effort is bad documentation of the tools I must use. Now along comes Lexical where I can get no idea at all what the heck they are talking about -- to me that is an example of a big problem in computing.
- mdoms 4y agoIs this the text editor used in products like Facebook (Blue), Messenger and Instagram? Because if it is it's buggy and terrible but thanks anyway I guess.
- jzer0cool 4y agoWhere might I find docs on the output document persisted to the db? Also, reading back this data back into the editor.
- zurfyx 4y agoNo docs yet - but this code pointer for physical files (plugin) may help https://github.com/facebook/lexical/blob/main/packages/lexical-file/src/fileImportExport.js https://github.com/facebook/lexical/blob/main/packages/lexic...
- petepete 4y agoFrom a company that intentionally broke text editing on mobile to force people to install the Messenger app, I wouldn't use it even if it was great.
- stareatgoats 4y ago> a company that intentionally broke text editing Of course inclined to believe you, but do you have a source to back this up?
- thorncorona 4y agoPerhaps not intentionally broken but I still have issues with double texting on the Messenger mac/web app. iMessages also has this issues as well... Telegram, Discord, WeChat, MSN Messenger, etc. all seem to have figured out how to prevent double texts from occurring.
- rmbyrro 4y agoExcuse my ignorance, but what is a "double text"?
- dkjaudyeqooe 4y agoProbably the same text being sent twice.
- petepete 4y agohttps://github.com/facebook/draft-js/issues/1077 https://github.com/facebook/draft-js/issues/1077 _Perhaps_ it wasn't intentional, but it started happening around the time FB started forcing people to use Messenger and now you can't even access messages via the mobile website so who knows. I haven't used FB for several years now so I'm a bit out of touch.
- HL33tibCe7 4y agoThat’ll show em!
- jbverschoor 4y agoSo when do we get fbide?
- bauripalash 4y agoYou mean metaide
- jbverschoor 4y agoYes I did. > Copyright © 2022 Meta Platforms, Inc. Built with Docusaurus. I think the title also meant meta
- dabedee 4y agoThe code examples seem to not be working for me on Firefox 100.0b5 (64-bit) on Windows. I only see black rectangles.
- asxd 4y agoIt crashed after I created a code block, converted it to a quote block, and the hit ctrl+z to undo (something about a history node not being found, I think. Sorry, should have saved the output).
- zurfyx 4y agoThanks for trying it out! Mind drafting a quick issue here so that we can have a look? https://github.com/facebook/lexical/issues https://github.com/facebook/lexical/issues
- asxd 4y agoSure, just submitted a new issue. Included in the issue, but I think there might be a more general problem with how block conversion is handled (at least for quote and code block types). On firefox at least, it's pretty easy to crash this by messing with block type dropdown.
- eyelidlessness 4y agoHere I was ready to be crabby about yet another web based rich text editor, but after reading so many comments about how it’s not a good code editor—which it’s not, it’s not one at all atm—I’m kind of just crabby about the discussion being completely about something other than the topic. Y’all, I know it’s a thing in software to curmudgeon everything but can we at least curmudgeon the actual thing it actually is? Or maybe just suspend curmudgeon-ness and see if the thing is deserving of that in the first place?
- deleted 4y ago[deleted]
- manigandham 4y agoUpdated list of rich/html text editors: https://gist.github.com/manigandham/65543a0bc2bf7006a487 https://gist.github.com/manigandham/65543a0bc2bf7006a487
- tvararu 4y agoGreat job Dominic and team! :) Really neat that it has no dependencies and works with anything.
- shashanoid 4y agoWish this had LaTex support
- Vivtek 4y agoThis has exactly the same maddening maladaptations that forced me to switch browsers for a reasonably adequate Facebook "experience". JavaScript that breaks in older or less popular browsers is not something I think needs to be promulgated even outside Facebook. Disappointing.
- mlajtos 4y agoWAT? https://github.com/facebook/lexical/blob/4e57eb8d7e0ca00fe998f02b9dd3efaaef858a2e/packages/lexical-react/src/LexicalCollaborationPlugin.js#L49 https://github.com/facebook/lexical/blob/4e57eb8d7e0ca00fe99...
- zurfyx 4y agoNo idea :D https://github.com/facebook/lexical/pull/1733 https://github.com/facebook/lexical/pull/1733
- mlajtos 4y agoI thought it was some kind of crazy obscure low-level optimization black magic, but probably not. :)
- trueadm 4y agoI had to take a second pass on it. I thought I was maybe onto something when I wrote that originally. Is it a V8 perf hack? Nope, just my brain not functioning correctly at the time :P
- Thexyman 4y agoHow does Lexical compare to Slate.js?
- compiotr 4y agoI understand the API will change, but will the JSON representation in such a way that it's not safe to use currently? I don't mind a bug here and there, but it would be quite serious not to be able to use old content with a new version of the editor.