Skip to content

Commit 5017a77

Browse files
committed
feat(files): zoom controls for inline mermaid and images in markdown
- Add pan/zoom/fit controls to mermaid diagrams rendered inline in markdown — same experience as the standalone .mmd viewer - Wrap inline markdown images in ZoomablePreview with fit-to-container scale - Allow fit zoom to upscale small diagrams to fill the view (previously capped at 100%)
1 parent a251e45 commit 5017a77

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/preview-panel.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,14 @@ const STATIC_MARKDOWN_COMPONENTS = {
495495
),
496496
'mermaid-diagram': ({ definition }: { definition?: string }) => {
497497
const isStreaming = useContext(MermaidStreamingCtx)
498-
return <MermaidDiagram definition={definition ?? ''} isStreaming={isStreaming} />
498+
return (
499+
<MermaidDiagram
500+
definition={definition ?? ''}
501+
isStreaming={isStreaming}
502+
zoomable
503+
zoomClassName='my-4 h-[420px] rounded-lg'
504+
/>
505+
)
499506
},
500507
p: ({ children }: { children?: React.ReactNode }) => (
501508
<p className='mb-3 break-words text-[14px] text-[var(--text-primary)] leading-[1.6] last:mb-0'>
@@ -619,12 +626,15 @@ const STATIC_MARKDOWN_COMPONENTS = {
619626
img: ({ src, alt }: React.ImgHTMLAttributes<HTMLImageElement>) => {
620627
const resolvedSrc = resolveSimFileUrl(typeof src === 'string' ? src : undefined)
621628
return (
622-
<img
623-
src={resolvedSrc}
624-
alt={alt ?? ''}
625-
className='my-3 max-w-full rounded-md'
626-
loading='lazy'
627-
/>
629+
<ZoomablePreview className='my-3 h-[360px] rounded-md' initialScale='actual'>
630+
<img
631+
src={resolvedSrc}
632+
alt={alt ?? ''}
633+
className='max-h-full max-w-full select-none object-contain'
634+
draggable={false}
635+
loading='lazy'
636+
/>
637+
</ZoomablePreview>
628638
)
629639
},
630640
table: ({ children }: { children?: React.ReactNode }) => (

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/zoomable-preview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function getFitZoom(container: Size, content: Size): number {
4747

4848
const availableWidth = Math.max(1, container.width - FIT_PADDING)
4949
const availableHeight = Math.max(1, container.height - FIT_PADDING)
50-
return clampZoom(Math.min(1, availableWidth / content.width, availableHeight / content.height))
50+
return clampZoom(Math.min(availableWidth / content.width, availableHeight / content.height))
5151
}
5252

5353
function clampOffset(container: Size, content: Size, offset: Offset, zoom: number): Offset {

0 commit comments

Comments
 (0)