ui: Mermaid Diagrams in chat + interactive preview (#24032)

This commit is contained in:
Aleksander Grygier
2026-06-03 16:55:36 +02:00
committed by GitHub
parent 9e58d4d692
commit ee4cf705bb
19 changed files with 2851 additions and 773 deletions
@@ -0,0 +1,20 @@
<script lang="ts">
import * as Dialog from '$lib/components/ui/dialog/index.js';
import { MermaidPreview } from '$lib/components/app/content';
interface Props {
open: boolean;
svgHtml: string;
onOpenChange?: (open: boolean) => void;
}
let { open = $bindable(), svgHtml, onOpenChange }: Props = $props();
</script>
<Dialog.Root bind:open {onOpenChange}>
<Dialog.Content
class="z-999999 grid max-h-full max-w-full! grid-rows-[1fr_auto] overflow-hidden p-0 md:h-[90vh] md:max-w-[90vw]!"
>
<MermaidPreview {svgHtml} />
</Dialog.Content>
</Dialog.Root>
@@ -474,3 +474,35 @@ export { default as DialogMcpResourcesBrowser } from './DialogMcpResourcesBrowse
* ```
*/
export { default as DialogMcpResourcePreview } from './DialogMcpResourcePreview.svelte';
/**
* **DialogMermaidPreview** - Full-screen Mermaid diagram preview with zoom and pan
*
* Full-screen dialog for previewing Mermaid diagrams with interactive controls.
* Supports mouse wheel zoom, drag-to-pan, and toolbar buttons for zoom in/out,
* fit to view, and reset.
*
* **Architecture:**
* - Uses UI dialog components (`Dialog.Root`, `Dialog.Overlay`, `Dialog.Content`)
* for consistent styling, animations, and accessibility
* - CSS transform-based zoom and pan (no external dependencies)
* - Pointer events for cross-device drag support (mouse + touch)
* - Wheel events for zoom-to-cursor functionality
*
* **Features:**
* - Scroll wheel zoom centered on cursor position
* - Click and drag to pan the diagram
* - Toolbar with zoom in, zoom out, fit to view, reset controls
* - Zoom percentage indicator
* - Keyboard accessible close button
* - Dark/light theme support
*
* @example
* ```svelte
* <DialogMermaidPreview
* bind:open={showMermaidPreview}
* svgHtml={mermaidSvgContent}
* />
* ```
*/
export { default as DialogMermaidPreview } from './DialogMermaidPreview.svelte';