Skip to content

feat: add mermaid diagram rendering to FileViewer markdown preview with zoom modal#182

Open
Kabochar wants to merge 3 commits into
agegr:mainfrom
Kabochar:feat/fileviewer-mermaid
Open

feat: add mermaid diagram rendering to FileViewer markdown preview with zoom modal#182
Kabochar wants to merge 3 commits into
agegr:mainfrom
Kabochar:feat/fileviewer-mermaid

Conversation

@Kabochar

Copy link
Copy Markdown
Contributor

改动:

  1. FileViewer markdown 预览支持 mermaid 渲染 — 将 MermaidBlock 和 CodeBlock 从 MarkdownBody 提取为共享组件。FileViewer 的 markdown 预览现在以和聊天消息一致的方式渲染 mermaid 图表,包括预览模式和一致的代码块样式。

  2. Mermaid 缩放弹窗 — 点击已渲染的 mermaid SVG 打开全屏缩放弹窗,支持:

    • 滚轮缩放 (无上限) 和拖拽平移
    • 打开时自动适配屏幕 (auto-scale to fill viewport)
    • 重置按钮、Escape / 点击背景关闭
    • 页面滚动锁定和移动端 touch-action

测试覆盖:

  • 5 个单元测试 (MermaidBlock.test.mjs),覆盖 SSR 初始状态、流式模式和渲染边界情况

文件变更:

components/MermaidBlock.tsx — 新增共享组件 (从 MarkdownBody 提取)
components/MermaidBlock.test.mjs — 5 个单测
components/MarkdownBody.tsx — 重构: 提取 mermaid/code block 逻辑
components/FileViewer.tsx — 在 markdown 预览中使用 MermaidBlock
app/globals.css — 缩放弹窗样式

Kabochar and others added 3 commits July 21, 2026 18:52
Extract MermaidBlock and CodeBlock from MarkdownBody into a shared component. Use them in FileViewer's TextFileViewer markdown preview so mermaid diagrams render the same way as in chat messages.

- MermaidBlock defaults to preview mode (no manual toggle needed)

- Non-mermaid code blocks use CodeBlock for consistent styling

- Streaming messages still fall back to source view via isStreaming

- 5 unit tests covering SSR initial state, streaming, and edge cases
Click a rendered mermaid SVG to open a full-screen zoom modal with:

- Wheel zoom (no upper bound) and drag-to-pan

- Fit-to-screen on open (auto-scale to fill viewport)

- Reset button, Escape / backdrop-click to close

- Body scroll lock and mobile-friendly touch-action
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