Replace text format in DOMConversions with childConversion#1154
Replace text format in DOMConversions with childConversion#1154
Conversation
There was a problem hiding this comment.
Like I mentioned in #1153, I think that we should at least consider the ability to have transform-like functions. This can potentially grow to many edge cases, not sure if we want to introduce a separate hook for every one of these. Haven't thought too much about it though, maybe it's already the most correct approach
68d9c15 to
018bb4d
Compare
|
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/fbopensource/lexical/7GSjfmz5djcMVxqfr77ppNfN6pnU |
|
New u: (domNode: Node) => {
return {
node: null,
after: (lexicalNodes) => {
for (let i = 0; i < lexicalNodes.length; i++) {
if ($isTextNode(lexicalNodes[i])) {
lexicalNodes[i].toggleFormat('underline');
}
}
return lexicalNodes;
},
};
}, |
Technically, it will, but in cases where the TextNodes are not direct children of the tag applying the formatting, we’d miss them. You’d have to visit every node in the subtree, not just the direct children. One example is: <u><a>Hello</a></u> In this case. I was thinking forChild is more convenient and performant than traversing the entire subtree after the transformation is complete. |
|
Ah, got it! I think I was confused by the name, assuming it's only for immediate child nodes. Maybe can adjust it to reflect functionality ul: {
node: LexicalNode,
after(Array<LexicalNode>) => Array<LexicalNode>, <-- post process immediate children, returned value used as children
forChild(LexicalNode) => void <-- recurse into tree, returned value ignored
}Maybe other folks have ideas, or it can be merged as is too |
Yea I used to call it "childConversion", which is also not obvious. I really hate the term "conversion" for some reason. Hopefully some documentation will help. I am going to leave this open for a bit to give others a chance to weigh in, for sure. |
There was a problem hiding this comment.
I think this one should actually be italic for em instead of underline
332b0f2 to
8424b31
Compare
* replace text format in DOMConversions with childConversion * rename child transform API * remove unncessary dom Nodde argument * fix formatting for em tag * fix lint error
Instead of having a format property that just applies formatting to all children of the node, this allows the user to specify a function that applies to all children of the specified DOM node type.
Closes #948