Skip to content

Conversation

xaya1001
Copy link

@xaya1001 xaya1001 commented Jul 3, 2025

Summary

This PR introduces support for rendering Mermaid.js diagrams, allowing users to create and view flowcharts, sequence diagrams, and more directly within their notes. This enhancement significantly expands the capabilities of Flatnotes as a technical documentation and note-taking tool.

Features

  • Mermaid Diagram Rendering: Code blocks with the language identifier mermaid are now automatically rendered as interactive SVG diagrams.
  • Interactive Viewer (InteractiveMermaid.vue): A new, self-contained Vue component that provides:
    • Zooming, panning, and view reset controls.
    • A fullscreen mode for immersive viewing.
    • A "Copy Source" button for convenience.
  • Automatic Theming: Diagrams seamlessly adapt to the application's light and dark themes. The component listens for theme changes and re-renders diagrams on the fly.
  • Robust Rendering Logic: The implementation handles rendering errors and provides clear feedback to the user without disrupting the rest of the note.

Implementation Details

  • Dependency: Adds the mermaid library to package.json.
  • Rendering Module (mermaidRenderer.js): A new utility module is responsible for finding Mermaid code blocks and mounting the InteractiveMermaid.vue component. This approach ensures proper Vue lifecycle management and cleanup.
  • Component Integration: ToastEditor.vue and ToastViewer.vue are updated to utilize the new renderer, enabling diagram support in both the live preview and the final note view.
  • Styling: New styles are added to toastui-editor-overrides.scss to support the interactive controls, fullscreen mode, and theming of the Mermaid viewer.

This feature is designed to be modular and minimally invasive to the core application logic. Looking forward to your feedback!


This feature was developed with the assistance of Gemini 2.5 Pro. Please let me know if any changes are needed. Thank you!

image

Dark Theme:
image

Error:
image

@xaya1001
Copy link
Author

xaya1001 commented Jul 3, 2025

#161 #143

@xaya1001
Copy link
Author

xaya1001 commented Jul 4, 2025

My fork has other features like Git sync and S3 uploader.
client/git-integration/GIT_INTEGRATION_GUIDE.md

Refactor the Mermaid diagram component for improved interactivity, performance, and styling.

- **`InteractiveMermaid.vue`**:
    - Implemented a more robust fullscreen mode with a backdrop and dedicated close button.
    - Migrated controls to a data-driven structure for better extensibility.
    - Unified SVG rendering and introduced loading/empty states for better user feedback.
    - Refined panning and zooming mechanisms for smoother interaction.
- **`ToastEditor.vue`**: Optimized Mermaid rendering to occur only when the preview tab is actively selected, improving editor performance.
- **`ToastViewer.vue`**: Streamlined component lifecycle by removing unnecessary watchers and unmount hooks.
- **`mermaidRenderer.js`**: Simplified cleanup logic for Mermaid component instances.
- **`toastui-editor-overrides.scss`**: Updated styles to support the new fullscreen behavior, loading indicators, and overall visual consistency of Mermaid diagrams.
@xaya1001 xaya1001 marked this pull request as draft July 6, 2025 15:46
…t selection

- Fixes a production-only fullscreen rendering crash by rendering the SVG only once and using CSS transforms to toggle the fullscreen view.
- Prevents unexpected page scrolling on fullscreen exit by saving and restoring the window\'s scroll position.
- Enables text selection in complex diagrams (using `foreignObject`) and error messages by refining the click-and-drag panning logic.
@xaya1001 xaya1001 marked this pull request as ready for review July 8, 2025 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant