-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
feat(core): add experimental decorator element node and nested root node #5981
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
What are the problems you currently encounter with DecoratorNodes in your use case? In my case they are:
I believe that these problems are solvable and that they should be addressed even if this PR goes ahead. In the past I tried to do something similar to what you do in this PR (on a local branch), but I ran into a lot of complications. The 1 LexicalNode = 1 DOM node model is something that is deeply rooted from the roots of Lexical. |
I agree I have similar troubles, but the main idea behind is decorating element nodes (instead of manipulating simple DOM node). By the way, when realizing this is just a simplified nested editor, it is not so difficult to debug. The key is treat NestedRootNode and RootNode in the same manner in the core lib. |
5c832a1
to
80f8e77
Compare
Still, may I know how you would describe what specific problems this solves? |
Decorate an ElementNode. Consider things like that: https://github.com/facebook/lexical/blob/main/packages/lexical-playground/src/nodes/LayoutContainerNode.ts You have to know vanilla JS well to make a complex element node, or you can do very little stuff. Alternatively, NestedEditor is needed and there exists multiple editor states. |
I'm all for adding support for the
|
Am also dreaming of something like an ElementNode with decorate capability 🥹 Agree with most if not all reasons pointed out here, where the "simplest" is being able to just re-use existing ui components as @LvChengbin has mentioned Also nested editor situation isn't (yet) as intuitive to use imho, especially, as already mentioned, when it comes to selections, history etc. |
DecoratorElementNode
This is a VERY EARLY draft of DecoratorElementNode (#5930).
I submit this PR because I want to:
Naive Demo
Screen.Recording.2024-04-28.at.18.12.43.mov
Screen.Recording.2024-04-29.at.10.14.13.mov
Tasks to do before this PR is submitted
editor.setNestedRootElement()
, could it be better?)Tasks I don't plan to do in this PR
Since I don't have so much spare time, I plan to deal with those issues later, maybe the community can offer some help.
API Documentation Draft
DecoratorElementNode
To combine external framework and Lexical node trees, decorator element node could be an option. It offers a
decorate()
method to allow external framework to render the DOM, but the external can also have child Lexical nodes handled by Lexical.Take the
CardNode
as an example:NestedRootNode
. To use other nodes, they should be NestedRootNode's children.decorate()
method, where developers can implement a render function to be handled by external frameworks.LexicalEditor
provides ansetNestedRootElement
method. When a new HTMLElement is set, Lexical will render its children DOMs.If a DecoratorElementNode has a fixed set of children, developers are responsible to record each child's index and meaning. If it has a variable array of children, then just make sure the
onRef
's order indecorate
function maps to each child correctly.