Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.8k
improvement(files): fit-width previews and chip-chrome viewer controls#5002
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
62d12a0
improvement(files): fit-width previews and chip-chrome viewer controls
waleedlatif1 53d0c67
improvement(files): debounce PDF panel-resize re-rasterisation
waleedlatif1 8aea876
fix(files): don't let a zero-width first measurement consume the imme…
waleedlatif1 6a33064
improvement(files): module cleanup — dedupe media previews, debounce …
waleedlatif1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
24 changes: 20 additions & 4 deletions
24 apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/docx-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
74 changes: 30 additions & 44 deletions
74 apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/file-viewer.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
42 changes: 35 additions & 7 deletions
42 apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/pdf-viewer.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 |
|---|---|---|
| @@ -28,8 +28,8 @@ const PDF_ZOOM_MIN = 0.5 | ||
| const PDF_ZOOM_MAX = 3 | ||
| const PDF_ZOOM_DEFAULT = 1 | ||
| const PDF_ZOOM_STEP = 1.25 | ||
| const PDF_PAGE_MAX_WIDTH = 816 | ||
| const PDF_VIEWER_PADDING = 24 | ||
| const PDF_RESIZE_DEBOUNCE_MS = 150 | ||
| export type PdfDocumentSource = | ||
| | { kind: 'url'; url: string } | ||
| @@ -66,25 +66,53 @@ export const PdfViewerCore = memo(function PdfViewerCore({ source, filename }: P | ||
| const [loadError, setLoadError] = useState<string | null>(null) | ||
| const sourceValue = source.kind === 'url' ? source.url : source.buffer | ||
| /** | ||
| * The buffer copy (`slice(0)`) is load-bearing: pdf.js transfers — and | ||
| * detaches — the ArrayBuffer it receives to its worker, so handing over the | ||
| * caller's buffer would leave it unusable on the next render or remount. | ||
| */ | ||
| const file = useMemo( | ||
| () => (source.kind === 'url' ? source.url : { data: new Uint8Array(source.buffer.slice(0)) }), | ||
| [sourceValue] | ||
| ) | ||
| /** | ||
| * The first non-zero measurement applies immediately so the document renders | ||
| * without delay (a hidden container reports zero width and must not consume | ||
| * the immediate slot); subsequent ones (panel-divider drags) are debounced | ||
| * because every pageWidth change makes pdf.js re-rasterise all page canvases | ||
| * — per-tick updates during a drag would re-render the whole document | ||
| * continuously. | ||
| */ | ||
| useEffect(() => { | ||
| const container = containerRef.current | ||
| if (!container) return | ||
| let hasMeasured = false | ||
| let debounce: ReturnType<typeof setTimeout> | undefined | ||
| const observer = new ResizeObserver(([entry]) => { | ||
| setContainerWidth(entry.contentRect.width) | ||
| const { width } = entry.contentRect | ||
| if (!hasMeasured) { | ||
| if (width <= 0) return | ||
| hasMeasured = true | ||
| setContainerWidth(width) | ||
| return | ||
| } | ||
| clearTimeout(debounce) | ||
| debounce = setTimeout(() => setContainerWidth(width), PDF_RESIZE_DEBOUNCE_MS) | ||
| }) | ||
| observer.observe(container) | ||
| return () => observer.disconnect() | ||
| return () => { | ||
| clearTimeout(debounce) | ||
| observer.disconnect() | ||
| } | ||
| }, []) | ||
| const pageWidth = | ||
| containerWidth > 0 | ||
| ? Math.min(containerWidth - 2 * PDF_VIEWER_PADDING, PDF_PAGE_MAX_WIDTH) | ||
| : undefined | ||
| /** | ||
| * 100% zoom fits the page to the panel width (pdf.js re-renders the canvas | ||
| * at the target width, so upscaling past the page's natural print size | ||
| * stays crisp). Matches the DOCX preview's fit-to-width semantics. | ||
| */ | ||
| const pageWidth = containerWidth > 0 ? containerWidth - 2 * PDF_VIEWER_PADDING : undefined | ||
| pageWidthRef.current = pageWidth | ||
waleedlatif1 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| const applyZoomAt = useCallback((next: number, anchorX: number, anchorY: number) => { | ||
66 changes: 16 additions & 50 deletions
66 apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/preview-toolbar.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
21 changes: 7 additions & 14 deletions
21 apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/xlsx-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
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.