-
Notifications
You must be signed in to change notification settings - Fork 3.6k
fix(file): zero byte codegen file format + zoomable preview wrapper + mermaid errors loopback #4400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9af4e65
fix(file): zero byte codegen file format
icecrasher321 d4df32c
address comments
icecrasher321 8118035
distinguish streaming from actual empty pdf
icecrasher321 df381e0
fix mermaid diagram state mgmt
icecrasher321 133b4bd
mermaid linter errors sent back to llm
icecrasher321 45d61c1
address comments
icecrasher321 a90cb18
fix autozoom
icecrasher321 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 11 additions & 111 deletions
122
apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/image-preview.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,121 +1,21 @@ | ||
| 'use client' | ||
|
|
||
| import { memo, useEffect, useRef, useState } from 'react' | ||
| import { ZoomIn, ZoomOut } from 'lucide-react' | ||
| import { Button } from '@/components/emcn' | ||
| import { memo } from 'react' | ||
| import type { WorkspaceFileRecord } from '@/lib/uploads/contexts/workspace' | ||
|
|
||
| const ZOOM_MIN = 0.25 | ||
| const ZOOM_MAX = 4 | ||
| const ZOOM_WHEEL_SENSITIVITY = 0.005 | ||
| const ZOOM_BUTTON_FACTOR = 1.2 | ||
|
|
||
| const clampZoom = (z: number) => Math.min(Math.max(z, ZOOM_MIN), ZOOM_MAX) | ||
| import { ZoomablePreview } from './zoomable-preview' | ||
|
|
||
| export const ImagePreview = memo(function ImagePreview({ file }: { file: WorkspaceFileRecord }) { | ||
| const serveUrl = `/api/files/serve/${encodeURIComponent(file.key)}?context=workspace` | ||
| const [zoom, setZoom] = useState(1) | ||
| const [offset, setOffset] = useState({ x: 0, y: 0 }) | ||
| const isDragging = useRef(false) | ||
| const dragStart = useRef({ x: 0, y: 0 }) | ||
| const offsetAtDragStart = useRef({ x: 0, y: 0 }) | ||
| const offsetRef = useRef(offset) | ||
| offsetRef.current = offset | ||
|
|
||
| const containerRef = useRef<HTMLDivElement>(null) | ||
|
|
||
| const zoomIn = () => setZoom((z) => clampZoom(z * ZOOM_BUTTON_FACTOR)) | ||
| const zoomOut = () => setZoom((z) => clampZoom(z / ZOOM_BUTTON_FACTOR)) | ||
|
|
||
| useEffect(() => { | ||
| const el = containerRef.current | ||
| if (!el) return | ||
| const onWheel = (e: WheelEvent) => { | ||
| e.preventDefault() | ||
| if (e.ctrlKey || e.metaKey) { | ||
| setZoom((z) => clampZoom(z * Math.exp(-e.deltaY * ZOOM_WHEEL_SENSITIVITY))) | ||
| } else { | ||
| setOffset((o) => ({ x: o.x - e.deltaX, y: o.y - e.deltaY })) | ||
| } | ||
| } | ||
| el.addEventListener('wheel', onWheel, { passive: false }) | ||
| return () => el.removeEventListener('wheel', onWheel) | ||
| }, []) | ||
|
|
||
| const handleMouseDown = (e: React.MouseEvent) => { | ||
| if (e.button !== 0) return | ||
| isDragging.current = true | ||
| dragStart.current = { x: e.clientX, y: e.clientY } | ||
| offsetAtDragStart.current = offsetRef.current | ||
| if (containerRef.current) containerRef.current.style.cursor = 'grabbing' | ||
| e.preventDefault() | ||
| } | ||
|
|
||
| const handleMouseMove = (e: React.MouseEvent) => { | ||
| if (!isDragging.current) return | ||
| setOffset({ | ||
| x: offsetAtDragStart.current.x + (e.clientX - dragStart.current.x), | ||
| y: offsetAtDragStart.current.y + (e.clientY - dragStart.current.y), | ||
| }) | ||
| } | ||
|
|
||
| const handleMouseUp = () => { | ||
| isDragging.current = false | ||
| if (containerRef.current) containerRef.current.style.cursor = 'grab' | ||
| } | ||
|
|
||
| return ( | ||
| <div | ||
| ref={containerRef} | ||
| className='relative flex flex-1 cursor-grab overflow-hidden bg-[var(--surface-1)]' | ||
| onMouseDown={handleMouseDown} | ||
| onMouseMove={handleMouseMove} | ||
| onMouseUp={handleMouseUp} | ||
| onMouseLeave={handleMouseUp} | ||
| > | ||
| <div | ||
| className='pointer-events-none absolute inset-0 flex items-center justify-center' | ||
| style={{ | ||
| transform: `translate(${offset.x}px, ${offset.y}px) scale(${zoom})`, | ||
| transformOrigin: 'center center', | ||
| }} | ||
| > | ||
| <img | ||
| src={serveUrl} | ||
| alt={file.name} | ||
| className='max-h-full max-w-full select-none rounded-md object-contain' | ||
| draggable={false} | ||
| loading='eager' | ||
| /> | ||
| </div> | ||
| <div | ||
| className='absolute right-4 bottom-4 flex items-center gap-1 rounded-md border border-[var(--border)] bg-[var(--surface-2)] px-2 py-1 shadow-card' | ||
| onMouseDown={(e) => e.stopPropagation()} | ||
| > | ||
| <Button | ||
| variant='ghost' | ||
| size='sm' | ||
| onClick={zoomOut} | ||
| disabled={zoom <= ZOOM_MIN} | ||
| className='h-6 w-6 p-0' | ||
| aria-label='Zoom out' | ||
| > | ||
| <ZoomOut className='h-3.5 w-3.5' /> | ||
| </Button> | ||
| <span className='min-w-[3rem] text-center text-[11px] text-[var(--text-secondary)]'> | ||
| {Math.round(zoom * 100)}% | ||
| </span> | ||
| <Button | ||
| variant='ghost' | ||
| size='sm' | ||
| onClick={zoomIn} | ||
| disabled={zoom >= ZOOM_MAX} | ||
| className='h-6 w-6 p-0' | ||
| aria-label='Zoom in' | ||
| > | ||
| <ZoomIn className='h-3.5 w-3.5' /> | ||
| </Button> | ||
| </div> | ||
| </div> | ||
| <ZoomablePreview className='flex flex-1' contentClassName='h-full w-full'> | ||
| <img | ||
| src={serveUrl} | ||
| alt={file.name} | ||
| className='max-h-full max-w-full select-none rounded-md object-contain' | ||
| draggable={false} | ||
| loading='eager' | ||
| /> | ||
| </ZoomablePreview> | ||
| ) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.