Repository navigation
Add node replacement system to core - #3367
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
d66b25e to
689db9c
Compare
|
Should name be more generic to allow easier extension in future? Eg if we introduce something else than replace/with options $nodeFactory/$createNode/etc |
|
I'm not sure we'd ever want to introduce $nodeFactory/$createNode as it would be such a large breaking change that it would cause a ton of churn for no real gains. |
There was a problem hiding this comment.
Thank you @trueadm! Stamping to unblock but I share the same sentiment as @fantactuka. I feel like a more generic name (just the term) would give us space to expand this in the future with further validation or other stuff without a breaking changes. I am personally for $createNote
| } | ||
|
|
||
| export function $applyNodeReplacement<N extends LexicalNode>( | ||
| node: LexicalNode, |
There was a problem hiding this comment.
| node: LexicalNode, | |
| node: N, |
This will guarantee that the return is the same or an extended node?
There was a problem hiding this comment.
They aren't the same though. The extended node is a subclass of N, not N.
|
@zurfyx I don't understand how |
I was thinking that something like |
|
|
|
This looks right. Nice work. |
|
Actually what happens if I override TextNode or something and then copy and paste into a Lexical editor that doesn't have that override? I guess we'll fallback to HTML. Maybe that's the best we can do here. |
* Add node replacement system to core * Add test * Fix missing logic * Fix prettier * Update flow types
|
@trueadm can you please post a concrete example on how to use this: E.g. I want to replace the edit: actually, I just found this in the docs and the code in the sandbox is exactly what I was looking for: https://lexical.dev/docs/concepts/node-replacement |
This PR extends on the work from #2924.
Instead of defining a proxy that the user must remember to invoke, we can instead opt nodes into replacement in their factory function
$createXNodeusing the new exported function$applyNodeReplacement. Then when defining the nodes array for editor config, we can supply an object in the form of:This should address the issues on the above PR.