Skip to content

feat(web): mermaid diagram lightbox / maximize on click #737

@heavygee

Description

@heavygee

Summary

Mermaid diagrams render inline in assistant markdown (#567) but cannot be opened full-screen or zoomed. Chat images already use a lightbox (#715, polish in #723). Operators expect the same affordance for diagrams: tap/click to maximize, especially on mobile.

Problem

MermaidDiagram (web/src/components/assistant-ui/mermaid-diagram.tsx) renders SVG via dangerouslySetInnerHTML with horizontal scroll only. There is no cursor-zoom-in, no modal viewer, and no way to inspect dense flowcharts on a phone.

Related work

PR What it ships
#567 Inline mermaid render in chat
#715 Shared ImagePreview (zoom/pan/full-screen) for attachments
#723 Lightbox interaction polish (backdrop dismiss, propagation)
#509 Tool-result inline images + lightbox (not mermaid)

Proposal

1. Per-diagram maximize (required)

  • Wrap each rendered [data-mermaid-diagram] block in a clickable surface (cursor-zoom-in, keyboard: Enter/Space).
  • On activate: open modal/sheet reusing ImagePreview interaction model (pinch/wheel zoom, pan, backdrop close) OR a thin shared MediaLightbox shell used by images + mermaid.
  • Prefer re-render from source at larger size: store data-mermaid-source (escaped) on the container; modal calls mermaid.render() again rather than scaling rasterized inline SVG only.
  • Preserve theme (data-theme light/dark) in modal render.

2. Per-message "all diagrams" view (nice-to-have, can be follow-up)

  • When an assistant message contains N > 1 mermaid blocks, show a compact control (e.g. "View N diagrams") in the message chrome or on first diagram.
  • Opens scrollable full-screen gallery; each item uses the same viewer as (1).

3. Accessibility

  • Focus trap in modal; Escape closes.
  • aria-label on diagram trigger: "Open diagram full screen".

Acceptance criteria

  • Click/tap a rendered mermaid diagram in chat → full-screen (or near full-screen) viewer opens.
  • Viewer supports zoom in/out and pan (parity with image lightbox gestures where platform allows).
  • Backdrop click and Escape dismiss viewer; click on diagram does not bubble to message actions (#723 pattern).
  • Failed mermaid fallback (data-rendered="false") is not clickable.
  • Dark/light theme matches app theme in modal.
  • No regression to inline render or horizontal scroll for small diagrams.
  • (Optional follow-up) Messages with multiple diagrams expose "view all" entry point.

Implementation notes

  • Touch points: mermaid-diagram.tsx, possibly extract shared viewer from web/src/components/ImagePreview.tsx.
  • Tests: extend mermaid-diagram.test.tsx for click opens viewer; optional live test for re-render in modal.
  • Security: keep securityLevel: 'strict' on mermaid init; modal must not execute arbitrary HTML from model output beyond mermaid SVG.

Non-goals

  • Export to PNG/SVG download (separate enhancement).
  • Editing mermaid source in viewer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions