-
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
[lexical-react][lexical-dev-tools-core] Feature: Allow TreeView custom print output #6180
[lexical-react][lexical-dev-tools-core] Feature: Allow TreeView custom print output #6180
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
size-limit report 📦
|
@@ -245,9 +249,17 @@ function normalize(text: string, obfuscateText: boolean = false) { | |||
return textToPrint; | |||
} | |||
|
|||
// TODO Pass via props to allow customizability |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment may still be valid, perhaps we shouldnt delete it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR allows full customizability for the TreeView print output for any existing node or any custom node and it it does it by passing a function in through the props. Perhaps I'm missing something but what part of that comment still needs implementing?
const customPrint = customPrintNode | ||
? customPrintNode(node, obfuscateText) | ||
: undefined; | ||
if (customPrint) { | ||
return customPrint; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const customPrint = customPrintNode | |
? customPrintNode(node, obfuscateText) | |
: undefined; | |
if (customPrint) { | |
return customPrint; | |
if (customPrintNode !== undefined) { | |
return customPrintNode(node, obfuscateText); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only want the custom print output if customPrintNode(...)
produces some text, i.e. if it returns an empty string because it doesn't handle a node then the existing code below would run and we would get the built-in print output. Your suggested change would not do that but return no output. That's not what we want here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (customPrint)
isnt clear because customPrint isnt a boolean. preferably be more explicit about the comparison, such as
if (customPrint !== undefined && customPrint.length > 0) {
return customPrint;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense, done.
what are some example usecases of custom print node? |
: undefined; | ||
if (customPrint) { | ||
return customPrint; | ||
} else if ($isTextNode(node)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since the if block above returns we dont need to wrap this in an else
} else if ($isTextNode(node)) { | |
if ($isTextNode(node)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just following the existing pattern as all the following else if
blocks all return. Strictly they could all be changed to if
blocks but I think that would make the code harder to read. I'm happy to change them all to if
blocks if you prefer that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the custom print case is a seperate case from the default print so its clearer to have it in its own if block rather then lump it tgt with the default print conditions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense also, done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your speedy response.
@@ -245,9 +249,17 @@ function normalize(text: string, obfuscateText: boolean = false) { | |||
return textToPrint; | |||
} | |||
|
|||
// TODO Pass via props to allow customizability |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR allows full customizability for the TreeView print output for any existing node or any custom node and it it does it by passing a function in through the props. Perhaps I'm missing something but what part of that comment still needs implementing?
const customPrint = customPrintNode | ||
? customPrintNode(node, obfuscateText) | ||
: undefined; | ||
if (customPrint) { | ||
return customPrint; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only want the custom print output if customPrintNode(...)
produces some text, i.e. if it returns an empty string because it doesn't handle a node then the existing code below would run and we would get the built-in print output. Your suggested change would not do that but return no output. That's not what we want here.
: undefined; | ||
if (customPrint) { | ||
return customPrint; | ||
} else if ($isTextNode(node)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just following the existing pattern as all the following else if
blocks all return. Strictly they could all be changed to if
blocks but I think that would make the code harder to read. I'm happy to change them all to if
blocks if you prefer that?
The test code in the PR description above is one example where we override the existing output for a Also you can add handling of TreeView output for custom nodes, e.g. if I created a Custom |
7c18796
to
9ff18e0
Compare
9ff18e0
to
0aa4ec5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also rebased since generateContent.ts
file changed on the main branch but I made my changes in a new commit for you to review.
Hi! Thanks for contributing! I think that overall strategy here is to eventually kill TreeView (see V2 plan here #5675 (comment))... So I'm not sure it's a good idea to expand it now. @potatowagon wdyt? |
@StyleT yep totally get that and have seen that plan (and I'm excited for those changes ASAP) but there is no timing on that plan. So even if this change is only useful for a few months that would be helpful for me and hopefully others. Also given that the |
I'm not strictly against it for sure! Let's hear other opinions here |
@@ -32,6 +32,11 @@ import { | |||
|
|||
import {LexicalCommandLog} from './useLexicalCommandsLog'; | |||
|
|||
export type CustomPrintNode = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: preferably rename CustomPrintNode to CustomPrintNodeFn to not confuse this with other lexical nodes such as TextNode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
the re
the example usecases listed by @irahopkinson makes sense to me so im good to have this merge, potentially helps unblock debugging of custom nodes |
- added optional `customPrintNode` function property. If the function returns nothing then the built-in output is used. So you can customize existing output and support custom node output. - moved output of mark IDs to `printNode` so it can be customized (it didn't seem to belong where it was anyway). - made appropriate changes to flow.
0aa4ec5
to
1fb4dd6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Description
customPrintNode
function property toTreeView
.printNode
so it can be customized (it didn't seem to belong where it was anyway).Test plan
Before
Previously in the Playground the TreeView output couldn't be customized:
After
To test, I changed
packages\lexical-playground\src\plugins\TreeViewPlugin\index.tsx
to:And then the Playground displays:
Note in the TreeView the mark IDs array label is now "uids" (instead of "id").