Allowing changing currentLexicalNode in HTML Paste Post-Processor Signature#1160
Allowing changing currentLexicalNode in HTML Paste Post-Processor Signature#1160
Conversation
|
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/fbopensource/lexical/88xoJUbufXoP3sgA1XWxbc5Rom1F |
|
Yeah, it seems like current API can solve all cases we've discussed. In the worst case you can always manipulate raw dom node and update it before it's converted into lexical node. I'd say this PR still has valuable change - to pass |
|
Please can I request you get together and do a tech talk on this logic please? I’d love to understand it all fully. |
Definitely - I was planning to do this since others were also interested. Will set something up for next week. |
I was thinking about this more - the argument currentLexicalNode is the domNode after it has been transformed to Lexical, This isn't available in the outer function scope, but might be useful if you wanted to make some changes to the children based on the nature of the parent LexicalNode. For instance, in the case of Lists, maybe we want to check that all immediate children are ListItemNodes if their parent is a ListNode. |
|
You should be able to access it, or is it wrong example? ul: (domNode: Node) => {
const listNode = $createListNode();
return {
node: listNode, // <-- used to set currentLexicalNode value
after: (childLexicalNodes) => {
... check "listNode" if needed ...
return childLexicalNodes;
},
};
},
|
Lol no, you're exactly right - I don't know what I was thinking. |
7f5c816 to
2996ea6
Compare
* Add code detecting and e2e tests * Add quip paste * Add github table-based code pasting
2996ea6 to
a7dfdc0
Compare
…nature (#1160) * wip * wip * add postTransform to HTML paste logic * Add code pasting support (#1159) * Add code detecting and e2e tests * Add quip paste * Add github table-based code pasting * Change post-transform API to accomodate changing the currentLexicalNode * simplify function signature in HTMl paste post-processor * rebase fixes Co-authored-by: Maksim Horbachevsky <fantactuka@gmail.com>
This changes the the "after" function to accept and return the currentLexicalNode, allowing the user to reference it or mutate it in the post-processing step, as @fantactuka suggested here:
#1153 (comment)
Now that I've written this, I'm not actually sure that we need it. I was having trouble thinking of a use case, since the transformer function itself already allows us to set the currentLexicalNode to be whatever we want. Open to comments/suggestions.