-
-
Notifications
You must be signed in to change notification settings - Fork 816
Mermaid on_node_click
, with {handler}
drop-in approach
#4861
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
base: main
Are you sure you want to change the base?
Conversation
@falkoschindler I forgot how to do custom event arguments 😅, so it is @dataclass(**KWONLY_SLOTS)
class JsonEditorChangeEventArguments(UiEventArguments):
node: str
param: Any Of course, the user has to do due diligence and check the node whether it is valid node, since if they do |
@evnchn, thanks for taking this on. What's the outcome if that mermaid markdown is created using an f-string, won't that |
Supposedly, they need to ensure that their f-string, after substitution, gets to have a Could be some very nasty syntax to get that working. Let me assess. |
Ok so apparently for f-string, you need Syntax is a bit nasty, but i think it's better than a direct replace (cannot escape the keyword if keyword turns out to be inside Mermaid diagram) / regex (hard to grasp) |
Thanks for the proposal, @evnchn! I'm still sceptical. Consider the following diagram: ui.mermaid('''
graph LR
A[trigger] -->|event| B{handler}
''') ![]() The diamond shape looks like our new event handler, but is normal Mermaid syntax. If we want to extend the Mermaid language with a custom event handler notation, we need to find something that isn't already part of the language. This could, however, get pretty cryptic. |
@falkoschindler Can agree that the Python f-string is getting cryptic. I also pondered the possibility that someone would invoke the browser-side Mermaid content update function by means of With that, I made #4862, the diff is smaller, and I don't think it would be possible to run into collision issues unlike this PR. Marking this as draft, unless you want to switch gears back to this approach, which I think is rather unlikely. |
Motivation
@thetableman, I feel sorry for pushing back against #4845, so I spent about 2 hours to code what I think could work to let Mermaid have node click functionality, with a minimally-sketchy code change. Notably, I used string format instead of regex, so the change NiceGUI is making should be obvious and understandable to everyone.
Implementation
If we desire to add
on_node_click
for Mermaid:mermaid_click_handler_SOMEUUID
(sincethis
is not available), .{handler}
) and replace that with the actual function nameShows up clearly in the IDE as well:
Progress
Pytest pending. Documentation pending. I'm tired TBH.
Test script
Result