Skip to content
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

Add optional config dictionary to mermaid component to be passed initialize() on mount #3164

Merged
merged 3 commits into from
Jun 6, 2024

Conversation

kyloe
Copy link
Contributor

@kyloe kyloe commented Jun 2, 2024

Added an optional parameter to ui.mermaid(), parameter is a dictionary that will be passed to the mermaid.initialize() method on mount, allowing the configuration of the mermaid engine prior to the first renderring.

This enables the adjustment of securityLevel, logLevel and other associated parameters on the engine.

Setting securityLevel to 'loose' will allow javascript call back functions to be called when nodes are clicked using mermaids 'click' syntax

A minimal example of usage would look like this

ui.add_head_html('''
    <script>
    var _mermaidClickHandler = function (e) {
        emitEvent("mermaidNodeEvent",e);
        };
    </script>
''')

ui.on('mermaidNodeEvent',(lambda e: _label.set_text(e.args)))

m = ui.mermaid('''flowchart TD;
    AAAA((XXXX));
    click AAAA href \"javascript:_mermaidClickHandler(\'I was clicked!\')\"''',config={'securityLevel':'loose'}) 

_label = ui.label('Place holder')

@falkoschindler falkoschindler self-requested a review June 2, 2024 20:13
Copy link
Contributor

@falkoschindler falkoschindler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pull request, @kyloe!

I just reviewed your code, simplified the tests a little bit, and added a documentation demo. Let's merge! 🚀

@falkoschindler falkoschindler added the enhancement New feature or request label Jun 6, 2024
@falkoschindler falkoschindler added this to the 1.4.27 milestone Jun 6, 2024
@falkoschindler falkoschindler merged commit 5fc7c44 into zauberzeug:main Jun 6, 2024
1 check passed
@kyloe
Copy link
Contributor Author

kyloe commented Jun 8, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants