From 553d0fa5259b626eb458405470e9b91b218b0081 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 00:02:54 +0000 Subject: [PATCH 1/7] feat(console): preview images, PDF, text and CSV in the page from attachments and file fields Claude-Session: https://claude.ai/code/session_01ADHkmRB34k9WUWeGpRnVNm Co-authored-by: Claude --- .../src/views/RecordAttachmentsPanel.tsx | 134 +++-- ui/packages/fields/src/index.tsx | 6 + .../fields/src/widgets/FilePreviewDialog.tsx | 529 ++++++++++++++++++ .../fields/src/widgets/ImageLightbox.tsx | 36 +- .../fields/src/widgets/delimitedText.ts | 74 +++ .../fields/src/widgets/file-affordance.tsx | 32 +- ui/packages/i18n/src/locales/ar.ts | 18 + ui/packages/i18n/src/locales/de.ts | 18 + ui/packages/i18n/src/locales/en.ts | 18 + ui/packages/i18n/src/locales/es.ts | 18 + ui/packages/i18n/src/locales/fr.ts | 18 + ui/packages/i18n/src/locales/ja.ts | 18 + ui/packages/i18n/src/locales/ko.ts | 18 + ui/packages/i18n/src/locales/pt-BR.ts | 18 + ui/packages/i18n/src/locales/ru.ts | 18 + ui/packages/i18n/src/locales/zh-Hans.ts | 18 + ui/packages/i18n/src/locales/zh-Hant.ts | 18 + ui/packages/plugin-grid/src/importParsers.ts | 65 +-- 18 files changed, 972 insertions(+), 102 deletions(-) create mode 100644 ui/packages/fields/src/widgets/FilePreviewDialog.tsx create mode 100644 ui/packages/fields/src/widgets/delimitedText.ts diff --git a/ui/packages/app-shell/src/views/RecordAttachmentsPanel.tsx b/ui/packages/app-shell/src/views/RecordAttachmentsPanel.tsx index c9f55520465..48c3c8c98ea 100644 --- a/ui/packages/app-shell/src/views/RecordAttachmentsPanel.tsx +++ b/ui/packages/app-shell/src/views/RecordAttachmentsPanel.tsx @@ -46,6 +46,7 @@ import { createAuthenticatedFetch, useAuth } from '@object-ui/auth'; import { useDisplayLocale } from '@object-ui/i18n'; import { useObjectTranslation, isPermissionError, classifyLoadError } from '@object-ui/react'; import { usePermissions } from '@object-ui/permissions'; +import { FilePreviewDialog, type FilePreviewItem } from '@object-ui/fields'; import { resolveAffordance, type ConfirmationHandler } from '@object-ui/core'; import { NATIVE_FILE_MAX_BYTES, @@ -77,6 +78,9 @@ import { RECORD_PAGE_ATTACHMENT_ROWS, recordAttachmentsCountField } from './reco * Downloads fetch a short-lived signed URL from `/storage/files/:fileId/url` * with the console's Bearer token (the endpoint requires an authenticated * session for attachments-scope files, objectstack-ai/objectstack#2970), then open it. + * A row's NAME opens the file in the page (`FilePreviewDialog`, objectstack#36442), + * which mints its link through that same door, so a reader the download refuses + * is refused the same way; the download itself stays in the row's ⋮ menu. * * The list read expands `uploaded_by` (the record page payload's attachments * part does the same), so the uploader column names whoever uploaded a row @@ -591,51 +595,85 @@ export const RecordAttachmentsPanel: React.FC = ({ [authFetch, baseUrl, friendlyError, t], ); + /** + * The signed link for a row: the one door both the download and the preview + * read through. Throws the server's code on a refusal. + */ + const signedUrlFor = React.useCallback( + async (row: AttachmentRow): Promise => { + // The stable `/files/:fileId` endpoint now requires an authenticated + // session for attachments-scope files (objectstack-ai/objectstack#2970) — an can't + // carry the Bearer token. Fetch a short-lived signed URL with auth, + // then open it (the signed URL itself needs no credentials). + const res = await authFetch( + `${baseUrl}/api/v1/storage/files/${encodeURIComponent(row.file_id)}/url`, + ); + if (!res.ok) { + let code: string | undefined; + try { + // Read BOTH error dialects, the same way the success branch below + // reads both `url` shapes. The storage service moved its error + // code from a sibling of `error` into the declared + // `{ success: false, error: { code, message } }` envelope + // (objectstack#3675); a console build is deployed independently of + // the server it talks to, so it has to keep understanding the + // older top-level `code` too. Without the nested branch the 401/403 + // downgrade silently to "Download failed (403)" and the friendly + // copy below never fires. + const body = (await res.json()) as { code?: string; error?: { code?: string } } | null; + code = body?.error?.code ?? body?.code; + } catch { + /* non-JSON body */ + } + throw Object.assign(new Error(code ?? `Download failed (${res.status})`), { code }); + } + const body = await res.json(); + // Both URL dialects, for the same independent-deploy reason as the + // error branch above: the route answered a bare `{ url }` until + // objectstack#3689 moved it into the declared + // `{ success: true, data: { url } }` envelope. + const url: string | undefined = body?.url ?? body?.data?.url; + if (!url) throw new Error('Download URL missing from response'); + return /^https?:/i.test(url) ? url : `${baseUrl}${url}`; + }, + [authFetch, baseUrl], + ); + const handleDownload = React.useCallback( async (row: AttachmentRow) => { setError(null); try { - // The stable `/files/:fileId` endpoint now requires an authenticated - // session for attachments-scope files (objectstack-ai/objectstack#2970) — an can't - // carry the Bearer token. Fetch a short-lived signed URL with auth, - // then open it (the signed URL itself needs no credentials). - const res = await authFetch( - `${baseUrl}/api/v1/storage/files/${encodeURIComponent(row.file_id)}/url`, - ); - if (!res.ok) { - let code: string | undefined; - try { - // Read BOTH error dialects, the same way the success branch below - // reads both `url` shapes. The storage service moved its error - // code from a sibling of `error` into the declared - // `{ success: false, error: { code, message } }` envelope - // (objectstack#3675); a console build is deployed independently of - // the server it talks to, so it has to keep understanding the - // older top-level `code` too. Without the nested branch the 401/403 - // downgrade silently to "Download failed (403)" and the friendly - // copy below never fires. - const body = (await res.json()) as { code?: string; error?: { code?: string } } | null; - code = body?.error?.code ?? body?.code; - } catch { - /* non-JSON body */ - } - throw Object.assign(new Error(code ?? `Download failed (${res.status})`), { code }); - } - const body = await res.json(); - // Both URL dialects, for the same independent-deploy reason as the - // error branch above: the route answered a bare `{ url }` until - // objectstack#3689 moved it into the declared - // `{ success: true, data: { url } }` envelope. - const url: string | undefined = body?.url ?? body?.data?.url; - if (!url) throw new Error('Download URL missing from response'); - const target = /^https?:/i.test(url) ? url : `${baseUrl}${url}`; + const target = await signedUrlFor(row); if (await openInNativeShell(target, row)) return; window.open(target, '_blank', 'noopener,noreferrer'); } catch (err: any) { setError(friendlyError(err)); } }, - [authFetch, baseUrl, friendlyError], + [signedUrlFor, friendlyError], + ); + + // The in-page preview (objectstack#36442): the row whose name was clicked, + // and the rows as the dialog's set, so previous / next walk the list. + const [previewIndex, setPreviewIndex] = React.useState(null); + const previewFiles: FilePreviewItem[] = rows.map((row) => ({ + id: row.file_id, + name: row.file_name || row.file_id, + mimeType: row.mime_type ?? undefined, + size: row.size ?? undefined, + })); + const previewSignedUrl = React.useCallback( + async (file: FilePreviewItem): Promise => { + const row = rows.find((r) => r.file_id === file.id); + if (!row) throw new Error(t('fields.filePreview.loadFailed')); + try { + return await signedUrlFor(row); + } catch (err) { + // The download's own copy for the download's own refusal. + throw new Error(friendlyError(err)); + } + }, + [rows, signedUrlFor, friendlyError, t], ); // Upload is offered (the header's 「+ 上传」, the empty line's 「选择文件」 and @@ -835,7 +873,7 @@ export const RecordAttachmentsPanel: React.FC = ({ ) : (
    - {rows.map((row) => { + {rows.map((row, index) => { const TypeIcon = fileTypeIcon(row.mime_type); const name = row.file_name || row.file_id; const uploader = uploaderOf(row); @@ -844,7 +882,15 @@ export const RecordAttachmentsPanel: React.FC = ({ // and uploader step aside in a narrow container (a drawer).
  • - {name} + {formatSize(row.size)} @@ -908,6 +954,20 @@ export const RecordAttachmentsPanel: React.FC = ({ if (!open) setConfirmState((s) => ({ ...s, open: false })); }} /> + {previewIndex !== null && previewIndex < rows.length && ( + !open && setPreviewIndex(null)} + onIndexChange={setPreviewIndex} + resolveUrl={previewSignedUrl} + onDownload={(_file, index) => { + const row = rows[index]; + if (row) void handleDownload(row); + }} + /> + )} { diff --git a/ui/packages/fields/src/index.tsx b/ui/packages/fields/src/index.tsx index 46b299d2317..5418213d14a 100644 --- a/ui/packages/fields/src/index.tsx +++ b/ui/packages/fields/src/index.tsx @@ -5506,6 +5506,12 @@ export * from './widgets/FileField.js'; export * from './widgets/ImageField.js'; export { ImageCropperDialog } from './widgets/ImageCropperDialog.js'; export type { ImageCropperDialogProps } from './widgets/ImageCropperDialog.js'; +// The in-page file preview a record's attachments and a file field open +// (objectstack#36442), and the delimited-text reader its CSV view shares with +// the grid's import wizard. +export { FilePreviewDialog } from './widgets/FilePreviewDialog.js'; +export type { FilePreviewDialogProps, FilePreviewItem } from './widgets/FilePreviewDialog.js'; +export { decodeSpreadsheetText, parseDelimited } from './widgets/delimitedText.js'; export * from './widgets/LocationField.js'; export * from './widgets/FormulaField.js'; export * from './widgets/SummaryField.js'; diff --git a/ui/packages/fields/src/widgets/FilePreviewDialog.tsx b/ui/packages/fields/src/widgets/FilePreviewDialog.tsx new file mode 100644 index 00000000000..92ae6b857bc --- /dev/null +++ b/ui/packages/fields/src/widgets/FilePreviewDialog.tsx @@ -0,0 +1,529 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * The console's in-page file preview: one dialog for a record's attachments + * and for a file field's value (decision objectstack#34781, option A). + * + * Four views and nothing else, with no new dependency: + * - image (PNG, JPEG, GIF, WebP, and SVG): the lightbox's own `img` element. + * ⛔ An SVG is never inlined: an `img` element runs no script. + * - PDF: an `iframe` on the browser's own viewer. On a phone the dialog + * offers the new tab instead, which hands the file to the system viewer. + * - plain text: the bytes decoded and drawn as text. + * - CSV: the same GBK-aware decode and delimited parser the grid's import + * wizard reads with (`delimitedText.ts`), drawn as a table. + * Every other type, Word, Excel, PowerPoint and HTML included, is the + * "unsupported, please download" state. ⛔ An `iframe` is only ever pointed at + * a file judged PDF, never at HTML or SVG. + * + * Past a size limit (images and PDF 20 MB; text and CSV 2 MB) the dialog draws + * "too large, please download"; text and CSV show their first 1000 lines. + * + * The preview reads the file through the SAME door as the download: the + * caller's `resolveUrl` (the attachments panel mints the signed link exactly as + * its download does) or, by default, the file's own URL — the stable storage + * endpoint, probed without following its redirect so a refusal reads as the + * download's refusal. When the browser cannot read a file in the page (a + * bucket on another origin without the CORS rule the preview needs), the + * dialog offers the new tab instead. + */ + +import * as React from 'react'; +import { + Button, + cn, + Dialog, + DialogDescription, + DialogTitle, + MobileDialogContent, + useIsMobile, +} from '@object-ui/components'; +import { useObjectTranslation } from '@object-ui/i18n'; +import { AlertTriangle, ChevronLeft, ChevronRight, Download, ExternalLink, FileX, Loader2 } from 'lucide-react'; +import { LightboxImageView } from './ImageLightbox.js'; +import { decodeSpreadsheetText, parseDelimited } from './delimitedText.js'; + +/** One file the dialog can show. A `FileValueView` satisfies it as it is. */ +export interface FilePreviewItem { + /** + * The file's stable identity (a `sys_file` id). With `url`, it is what the + * dialog remembers a resolved link by, so pass it when there is no `url`. + */ + id?: string; + /** Display name; its extension decides the view when no MIME type is known. */ + name: string; + /** Where the bytes are. Optional when the caller passes `resolveUrl`. */ + url?: string; + /** Declared MIME type; decides the view when present. */ + mimeType?: string; + /** Size in bytes, when known: a file past its limit is never fetched. */ + size?: number; +} + +export interface FilePreviewDialogProps { + files: FilePreviewItem[]; + /** Index of the file shown. Controlled, like `ImageLightbox`. */ + index: number; + open: boolean; + onOpenChange: (open: boolean) => void; + /** Called on previous / next (buttons and arrow keys). Without it the set does not move. */ + onIndexChange?: (index: number) => void; + /** + * The link the preview reads, minted by the same check as the download. + * A rejection is the refusal: its `message` is shown as it is, so pass the + * copy the download would have shown. Default: the file's own `url`. + */ + resolveUrl?: (file: FilePreviewItem, index: number) => Promise; + /** The download. Default: a link to the resolved URL with `download` set. */ + onDownload?: (file: FilePreviewItem, index: number) => void; + /** The fetch used to read text and CSV, and to probe the default URL. */ + fetchImpl?: typeof fetch; +} + +type PreviewKind = 'image' | 'pdf' | 'text' | 'csv' | 'unsupported'; + +const MB = 1024 * 1024; +const MEDIA_LIMIT_BYTES = 20 * MB; +const TEXT_LIMIT_BYTES = 2 * MB; +const TEXT_ROW_LIMIT = 1000; + +const IMAGE_TYPES = new Set(['image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/svg+xml']); +const IMAGE_EXTENSIONS = new Set(['png', 'jpg', 'jpeg', 'gif', 'webp', 'svg']); +const CSV_TYPES = new Set(['text/csv', 'application/csv', 'text/x-csv', 'text/comma-separated-values']); +/** Types a `.csv` file is commonly uploaded under besides its own. */ +const CSV_LOOSE_TYPES = new Set(['', 'text/plain', 'application/vnd.ms-excel', 'application/octet-stream']); +const TEXT_EXTENSIONS = new Set(['txt', 'log']); + +function extensionOf(name: string): string { + const dot = name.lastIndexOf('.'); + return dot < 0 ? '' : name.slice(dot + 1).toLowerCase(); +} + +/** A MIME type's essence: lower case, parameters dropped. */ +function essenceOf(mimeType?: string): string { + return (mimeType ?? '').split(';')[0]!.trim().toLowerCase(); +} + +/** + * The view a file gets. The declared type decides; the extension only fills + * in where no type is declared, except for the text views, which draw bytes as + * text and so cannot execute anything whatever the bytes are. + * + * ⛔ HTML is unsupported, never text and never framed. ⛔ PDF needs a PDF + * signal: the declared type, or the extension when nothing is declared — the + * `iframe` is the one view that hands bytes to the browser to interpret. + */ +export function filePreviewKind(file: FilePreviewItem): PreviewKind { + const type = essenceOf(file.mimeType); + const ext = extensionOf(file.name); + if (type === 'text/html' || type === 'application/xhtml+xml' || ext === 'html' || ext === 'htm') return 'unsupported'; + if (CSV_TYPES.has(type) || (ext === 'csv' && CSV_LOOSE_TYPES.has(type))) return 'csv'; + if (type === 'text/plain' || (!type && TEXT_EXTENSIONS.has(ext))) return 'text'; + if (IMAGE_TYPES.has(type) || (!type && IMAGE_EXTENSIONS.has(ext))) return 'image'; + if (type === 'application/pdf' || (!type && ext === 'pdf')) return 'pdf'; + return 'unsupported'; +} + +function limitFor(kind: PreviewKind): number { + return kind === 'text' || kind === 'csv' ? TEXT_LIMIT_BYTES : MEDIA_LIMIT_BYTES; +} + +type BodyState = + | { status: 'loading' } + | { status: 'ready'; url: string; text?: string; rows?: string[][]; truncated?: boolean } + /** Refused or failed: the message says which. */ + | { status: 'error'; message: string } + /** The browser could not read the bytes in the page (cross-origin without CORS). */ + | { status: 'blocked' } + | { status: 'tooLarge' }; + +/** An error whose message is already the copy to show. */ +class PreviewRefusal extends Error {} + +/** What a file is remembered by: primitives, never the item object (ui/AGENTS.md #10). */ +function fileKey(file: FilePreviewItem, index: number): string { + return JSON.stringify([file.id ?? null, file.url ?? null, file.id || file.url ? null : index, file.name]); +} + +function isSameOrigin(url: string): boolean { + if (typeof window === 'undefined') return false; + try { + return new URL(url, window.location.href).origin === window.location.origin; + } catch { + return false; + } +} + +/** + * Hook state for one dialog: resolves each file's URL once and remembers it, + * so previous / next and the header's buttons never mint twice. + */ +function useResolver( + resolveUrl: FilePreviewDialogProps['resolveUrl'], + fetchImpl: typeof fetch, + t: (key: string, params?: Record) => string, +) { + const cache = React.useRef(new Map>()); + return React.useCallback( + (file: FilePreviewItem, index: number): Promise => { + const key = fileKey(file, index); + const hit = cache.current.get(key); + if (hit) return hit; + const run = (async () => { + if (resolveUrl) return resolveUrl(file, index); + const url = file.url?.trim(); + if (!url) throw new PreviewRefusal(t('fields.filePreview.loadFailed')); + // The stable storage endpoint answers a refusal itself and a grant with + // a redirect to the signed link: ask it without following, so the + // answer is the download's answer and no byte moves twice. + if (isSameOrigin(url)) { + let res: Response | undefined; + try { + res = await fetchImpl(url, { redirect: 'manual', credentials: 'same-origin' }); + } catch { + res = undefined; // Unreadable here; the view itself will say so. + } + if (res) { + void res.body?.cancel().catch(() => undefined); + if (res.status === 401 || res.status === 403) throw new PreviewRefusal(t('fields.filePreview.denied')); + if (res.status >= 400) throw new PreviewRefusal(t('fields.filePreview.loadFailed')); + } + } + return url; + })(); + cache.current.set(key, run); + // A failed resolution is not remembered: the next try asks again. + run.catch(() => cache.current.delete(key)); + return run; + }, + [resolveUrl, fetchImpl, t], + ); +} + +/** Read a text or CSV file's bytes through the resolved link. */ +async function readTextBody( + url: string, + kind: 'text' | 'csv', + fetchImpl: typeof fetch, + signal: AbortSignal, + t: (key: string, params?: Record) => string, +): Promise { + let res: Response; + try { + res = await fetchImpl(url, { credentials: 'same-origin', signal }); + } catch (err) { + if (signal.aborted) throw err; + return { status: 'blocked' }; + } + if (res.status === 401 || res.status === 403) return { status: 'error', message: t('fields.filePreview.denied') }; + if (!res.ok) return { status: 'error', message: t('fields.filePreview.loadFailed') }; + const declared = Number(res.headers.get('content-length')); + if (Number.isFinite(declared) && declared > TEXT_LIMIT_BYTES) { + void res.body?.cancel().catch(() => undefined); + return { status: 'tooLarge' }; + } + const buffer = await res.arrayBuffer(); + if (buffer.byteLength > TEXT_LIMIT_BYTES) return { status: 'tooLarge' }; + const text = decodeSpreadsheetText(buffer); + if (kind === 'csv') { + const rows = parseDelimited(text, ','); + // The header row plus the first 1000 data rows. + return { status: 'ready', url, rows: rows.slice(0, TEXT_ROW_LIMIT + 1), truncated: rows.length > TEXT_ROW_LIMIT + 1 }; + } + const lines = text.split(/\r?\n/); + return { + status: 'ready', + url, + text: lines.slice(0, TEXT_ROW_LIMIT).join('\n'), + truncated: lines.length > TEXT_ROW_LIMIT, + }; +} + +/** + * A shared preview dialog for files: previous / next across `files`, download, + * open in a new tab, and one of the four views — or the "too large" or + * "unsupported" state, both of which offer the download. + */ +export function FilePreviewDialog({ + files, + index, + open, + onOpenChange, + onIndexChange, + resolveUrl, + onDownload, + fetchImpl, +}: FilePreviewDialogProps) { + const { t } = useObjectTranslation(); + const tr = t as (key: string, params?: Record) => string; + const isMobile = useIsMobile(); + const doFetch = fetchImpl ?? ((...args: Parameters) => fetch(...args)); + const resolve = useResolver(resolveUrl, doFetch, tr); + const count = files.length; + const file = files[index]; + const kind: PreviewKind = file ? filePreviewKind(file) : 'unsupported'; + const tooLargeByDeclaration = !!file && typeof file.size === 'number' && file.size > limitFor(kind); + const pdfOutside = kind === 'pdf' && isMobile; + const needsBody = open && !!file && kind !== 'unsupported' && !tooLargeByDeclaration && !pdfOutside; + + const key = file ? fileKey(file, index) : ''; + // Each answer carries the key of the file it is about, so a file never + // draws the previous file's answer while its own is on the way. + const [answer, setAnswer] = React.useState<{ key: string; state: BodyState; url?: string }>({ + key: '', + state: { status: 'loading' }, + }); + const state: BodyState = answer.key === key ? answer.state : { status: 'loading' }; + const resolvedUrl = answer.key === key ? answer.url : undefined; + const setState = React.useCallback( + (next: BodyState, url?: string) => setAnswer((prev) => ({ key, state: next, url: url ?? (prev.key === key ? prev.url : undefined) })), + [key], + ); + + React.useEffect(() => { + if (!needsBody || !file) return; + const controller = new AbortController(); + let live = true; + (async () => { + let url: string; + try { + url = await resolve(file, index); + } catch (err) { + if (!live) return; + const message = err instanceof Error && err.message ? err.message : tr('fields.filePreview.loadFailed'); + setState({ status: 'error', message }); + return; + } + if (!live) return; + if (kind === 'text' || kind === 'csv') { + try { + const next = await readTextBody(url, kind, doFetch, controller.signal, tr); + if (live) setState(next, url); + } catch { + if (live) setState({ status: 'error', message: tr('fields.filePreview.loadFailed') }, url); + } + return; + } + setState({ status: 'ready', url }, url); + })(); + return () => { + live = false; + controller.abort(); + }; + // Keyed on the file's primitives (`key`), never on the item object (ui/AGENTS.md #10); + // `doFetch` and `tr` are read through the run. + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [needsBody, key, kind, resolve, setState]); + + const go = React.useCallback( + (delta: number) => { + if (count <= 1) return; + onIndexChange?.((index + delta + count) % count); + }, + [count, index, onIndexChange], + ); + + const openInNewTab = React.useCallback(async () => { + if (!file) return; + try { + const url = resolvedUrl ?? (await resolve(file, index)); + window.open(url, '_blank', 'noopener,noreferrer'); + } catch (err) { + setState({ + status: 'error', + message: err instanceof Error && err.message ? err.message : tr('fields.filePreview.loadFailed'), + }); + } + }, [file, index, resolvedUrl, resolve, setState, tr]); + + const download = React.useCallback(async () => { + if (!file) return; + if (onDownload) { + onDownload(file, index); + return; + } + try { + const url = resolvedUrl ?? (await resolve(file, index)); + const a = document.createElement('a'); + a.href = url; + a.download = file.name; + a.target = '_blank'; + a.rel = 'noopener noreferrer'; + document.body.appendChild(a); + a.click(); + a.remove(); + } catch (err) { + setState({ + status: 'error', + message: err instanceof Error && err.message ? err.message : tr('fields.filePreview.loadFailed'), + }); + } + }, [file, index, onDownload, resolvedUrl, resolve, setState, tr]); + + const handleKeyDown = React.useCallback( + (e: React.KeyboardEvent) => { + // Stopped too: a grid row behind a portal still hears React's bubble. + if (e.key === 'ArrowRight') { + e.preventDefault(); + e.stopPropagation(); + go(1); + } else if (e.key === 'ArrowLeft') { + e.preventDefault(); + e.stopPropagation(); + go(-1); + } + }, + [go], + ); + + if (!file) return null; + + const notice = (icon: React.ReactNode, message: string, slot: string, extra?: React.ReactNode) => ( +
    + {icon} +

    {message}

    + {extra} +
    + ); + const downloadButton = ( + + ); + const newTabButton = ( + + ); + + let body: React.ReactNode; + if (kind === 'unsupported') { + body = notice(