@swisper.ai/web-file-preview 0.0.2 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/file-preview/components/renderer-types.d.ts +4 -1
- package/dist/components/file-preview/components/renderer-types.d.ts.map +1 -1
- package/dist/components/file-preview/components/viewer/viewer-components.stories.d.ts.map +1 -1
- package/dist/components/file-preview/file-preview.d.ts.map +1 -1
- package/dist/components/file-preview/file-preview.stories.d.ts +49 -2
- package/dist/components/file-preview/file-preview.stories.d.ts.map +1 -1
- package/dist/components/file-thumbnail/components/previews/html-preview.d.ts.map +1 -1
- package/dist/components/file-thumbnail/components/previews/image-preview.d.ts.map +1 -1
- package/dist/components/file-thumbnail/components/previews/markdown-preview.d.ts.map +1 -1
- package/dist/components/file-thumbnail/components/previews/reveal-class-name.d.ts +4 -2
- package/dist/components/file-thumbnail/components/previews/reveal-class-name.d.ts.map +1 -1
- package/dist/components/file-thumbnail/components/previews/scaled-page.d.ts +4 -1
- package/dist/components/file-thumbnail/components/previews/scaled-page.d.ts.map +1 -1
- package/dist/components/file-thumbnail/file-thumbnail.d.ts +2 -0
- package/dist/components/file-thumbnail/file-thumbnail.d.ts.map +1 -1
- package/dist/components/file-thumbnail/file-thumbnail.stories.d.ts +76 -10
- package/dist/components/file-thumbnail/file-thumbnail.stories.d.ts.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.es.js +50 -33
- package/dist/index.es.js.map +1 -1
- package/package.json +15 -7
- package/src/__storybook__/parent-block.tsx +21 -0
- package/src/components/file-preview/__stories__/fixtures.ts +66 -0
- package/src/components/file-preview/components/renderer-types.ts +4 -1
- package/src/components/file-preview/components/viewer/viewer-components.stories.tsx +2 -8
- package/src/components/file-preview/file-preview.json +15 -0
- package/src/components/file-preview/file-preview.stories.tsx +378 -38
- package/src/components/file-preview/file-preview.tsx +7 -2
- package/src/components/file-thumbnail/__stories__/fixtures.ts +99 -0
- package/src/components/file-thumbnail/__stories__/types.ts +26 -0
- package/src/components/file-thumbnail/components/previews/html-preview.tsx +5 -1
- package/src/components/file-thumbnail/components/previews/image-preview.tsx +3 -1
- package/src/components/file-thumbnail/components/previews/markdown-preview.tsx +5 -1
- package/src/components/file-thumbnail/components/previews/reveal-class-name.ts +8 -8
- package/src/components/file-thumbnail/components/previews/scaled-page.tsx +6 -1
- package/src/components/file-thumbnail/file-thumbnail.json +17 -1
- package/src/components/file-thumbnail/file-thumbnail.stories.tsx +551 -84
- package/src/components/file-thumbnail/file-thumbnail.tsx +24 -7
- /package/src/components/file-thumbnail/components/shared/__tests__/{generation-queue.spec.ts → generation-queue.test.ts} +0 -0
- /package/src/components/file-thumbnail/hooks/__tests__/{use-object-url.spec.ts → use-object-url.test.ts} +0 -0
- /package/src/lib/__tests__/{file-kinds.spec.ts → file-kinds.test.ts} +0 -0
|
@@ -63,7 +63,11 @@ export function HtmlPreview({
|
|
|
63
63
|
className,
|
|
64
64
|
}: HtmlPreviewProps) {
|
|
65
65
|
return (
|
|
66
|
-
<ScaledPage
|
|
66
|
+
<ScaledPage
|
|
67
|
+
designWidth={designWidth}
|
|
68
|
+
status={status}
|
|
69
|
+
className={cn(revealClassName, className)}
|
|
70
|
+
>
|
|
67
71
|
<iframe
|
|
68
72
|
title="Page preview"
|
|
69
73
|
tabIndex={-1}
|
|
@@ -69,13 +69,15 @@ export const ImagePreview = forwardRef<HTMLImageElement, ImagePreviewProps>(
|
|
|
69
69
|
draggable={false}
|
|
70
70
|
loading="lazy"
|
|
71
71
|
decoding="async"
|
|
72
|
+
data-slot="file-thumbnail-preview"
|
|
73
|
+
data-status={status}
|
|
72
74
|
data-testid="file-thumbnail-preview"
|
|
73
75
|
onLoad={(event: SyntheticEvent<HTMLImageElement>) => settle(event.currentTarget)}
|
|
74
76
|
onError={onError}
|
|
75
77
|
className={cn(
|
|
76
78
|
'absolute inset-0 block size-full bg-white',
|
|
77
79
|
FIT_CLASS[fit],
|
|
78
|
-
revealClassName
|
|
80
|
+
revealClassName,
|
|
79
81
|
className,
|
|
80
82
|
)}
|
|
81
83
|
/>
|
|
@@ -30,7 +30,11 @@ export function MarkdownPreview({
|
|
|
30
30
|
className,
|
|
31
31
|
}: MarkdownPreviewProps) {
|
|
32
32
|
return (
|
|
33
|
-
<ScaledPage
|
|
33
|
+
<ScaledPage
|
|
34
|
+
designWidth={DESIGN_WIDTH}
|
|
35
|
+
status={status}
|
|
36
|
+
className={cn(revealClassName, className)}
|
|
37
|
+
>
|
|
34
38
|
<div data-testid="file-thumbnail-preview">
|
|
35
39
|
<Suspense fallback={null}>
|
|
36
40
|
<MarkdownPage
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { cn } from '@swisper.ai/web-core';
|
|
2
2
|
|
|
3
|
-
import type { PreviewRevealStatus } from '../../hooks/use-preview-reveal';
|
|
4
|
-
|
|
5
3
|
/**
|
|
6
4
|
* Extend's reveal: every preview stays mounted while it loads, hidden and blurred, then
|
|
7
5
|
* fades and sharpens in once drawn. Shared so image, Markdown and HTML reveal alike.
|
|
6
|
+
*
|
|
7
|
+
* Styled from the preview's own `data-status`, so a consumer can restyle either state with the
|
|
8
|
+
* same selector (`data-[status=loaded]:opacity-90`).
|
|
8
9
|
*/
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
10
|
+
export const revealClassName = cn(
|
|
11
|
+
'transition-[opacity,filter] duration-[160ms] ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none',
|
|
12
|
+
'opacity-0 blur-sm',
|
|
13
|
+
'data-[status=loaded]:opacity-100 data-[status=loaded]:blur-none',
|
|
14
|
+
);
|
|
@@ -2,11 +2,14 @@ import { useRef, type ReactNode } from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { cn } from '@swisper.ai/web-core';
|
|
4
4
|
|
|
5
|
+
import type { PreviewRevealStatus } from '../../hooks/use-preview-reveal';
|
|
5
6
|
import { useScaleToFit } from '../../hooks/use-scale-to-fit';
|
|
6
7
|
|
|
7
8
|
interface ScaledPageProps {
|
|
8
9
|
/** The width the content is laid out at, in CSS pixels, before it is scaled to the tile. */
|
|
9
10
|
designWidth: number;
|
|
11
|
+
/** The preview's load status, exposed as `data-status` for the reveal. */
|
|
12
|
+
status: PreviewRevealStatus;
|
|
10
13
|
className?: string;
|
|
11
14
|
children: ReactNode;
|
|
12
15
|
}
|
|
@@ -15,7 +18,7 @@ interface ScaledPageProps {
|
|
|
15
18
|
* A white page laid out at `designWidth` and scaled down to the tile's width, top-left
|
|
16
19
|
* anchored, cropped at the tile's bottom - the first screen of the document in miniature.
|
|
17
20
|
*/
|
|
18
|
-
export function ScaledPage({ designWidth, className, children }: ScaledPageProps) {
|
|
21
|
+
export function ScaledPage({ designWidth, status, className, children }: ScaledPageProps) {
|
|
19
22
|
const ref = useRef<HTMLDivElement>(null);
|
|
20
23
|
const { scale, designHeight } = useScaleToFit(ref, designWidth);
|
|
21
24
|
|
|
@@ -23,6 +26,8 @@ export function ScaledPage({ designWidth, className, children }: ScaledPageProps
|
|
|
23
26
|
<div
|
|
24
27
|
ref={ref}
|
|
25
28
|
aria-hidden
|
|
29
|
+
data-slot="file-thumbnail-preview"
|
|
30
|
+
data-status={status}
|
|
26
31
|
className={cn('pointer-events-none absolute inset-0 overflow-hidden bg-white', className)}
|
|
27
32
|
>
|
|
28
33
|
<div
|
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
"$schema": "../../../../int-eslint-config/schemas/component.schema.json",
|
|
3
3
|
"component": "file-thumbnail",
|
|
4
4
|
"purpose": "A small tile standing for a file, for document lists, upload queues and attachment trays: it draws a picture of the file itself (a PDF's first page, a workbook's first sheet, rendered Markdown, …), pulses while that picture is made and loads, fades it in once drawn, and falls back to the file name otherwise. Like FilePreview it is a compound component with no fixed layout: the FileThumbnail root owns the status, and FileThumbnailLoader, FileThumbnailPreview and FileThumbnailFallback each render only in their state.",
|
|
5
|
+
"anatomy": [
|
|
6
|
+
"import {",
|
|
7
|
+
" FileThumbnail,",
|
|
8
|
+
" FileThumbnailLoader,",
|
|
9
|
+
" FileThumbnailPreview,",
|
|
10
|
+
" FileThumbnailFallback,",
|
|
11
|
+
"} from '@swisper.ai/web-file-preview';",
|
|
12
|
+
"",
|
|
13
|
+
"<FileThumbnail>",
|
|
14
|
+
" <FileThumbnailLoader />",
|
|
15
|
+
" <FileThumbnailPreview />",
|
|
16
|
+
" <FileThumbnailFallback />",
|
|
17
|
+
"</FileThumbnail>"
|
|
18
|
+
],
|
|
5
19
|
"useWhen": [
|
|
6
20
|
"Showing attached or uploaded files as a grid or row of tiles, before the user opens one in web-file-preview/file-preview",
|
|
7
21
|
"An upload queue where a file is still on its way (pass fileBlob={null} until it arrives)",
|
|
@@ -44,6 +58,8 @@
|
|
|
44
58
|
"loaded: the picture drew (an image with real pixels, or the page). It fades and un-blurs in over 160ms, instantly with prefers-reduced-motion",
|
|
45
59
|
"error: there is no way to draw the file, or it failed to download, parse or decode. For a kind with nothing to draw this is the first paint, so the fallback never flickers in after a loader. The cause is logged with console.warn",
|
|
46
60
|
"Status is on the root as data-status; data-kind is the file's kind (pdf, image, video, text, csv, spreadsheet, docx, presentation, markdown, html) or unsupported",
|
|
61
|
+
"Every part carries a data-slot: file-thumbnail, file-thumbnail-loader, file-thumbnail-preview, file-thumbnail-fallback, and file-thumbnail-fallback-label on the default file name. The root is group/file-thumbnail, so a custom child can style itself from the status (group-data-[status=error]/file-thumbnail:…)",
|
|
62
|
+
"FileThumbnailPreview carries data-status too, and its fade is styled from it: pass data-[status=loaded]:… or data-[status=loading]:… in className to restyle a state",
|
|
47
63
|
"Pass exactly one of src or fileBlob, the same value you would pass to FilePreview",
|
|
48
64
|
"Image: drawn from the file's URL, src not fetched",
|
|
49
65
|
"PDF: PDFium renders page 1 (shared with FilePreview), src fetched",
|
|
@@ -66,7 +82,7 @@
|
|
|
66
82
|
"Each engine is a lazy chunk, downloaded the first time a tile of that kind shows. At most two engine thumbnails generate at once; the rest wait, pulsing",
|
|
67
83
|
"Generated pictures (pdf, spreadsheet, presentation, docx, markdown, csv) are kept for the session by src or by the Blob, so a remounted tile shows them at once without parsing the file again; a picture that has faded in once this session does not replay the fade on remount",
|
|
68
84
|
"FileThumbnailLoader's default is a checkerboard surface whose pulse starts after 1.3s and is off with prefers-reduced-motion; children replace it, and asChild merges it onto your element",
|
|
69
|
-
"FileThumbnailFallback's default is the loader's checkerboard surface, still, with the file name truncated in the middle to keep the extension (longfilena…pdf); children replace both",
|
|
85
|
+
"FileThumbnailFallback's default is the loader's checkerboard surface, still, with the file name truncated in the middle to keep the extension (longfilena…pdf); labelClassName styles that name; children replace both",
|
|
70
86
|
"It follows FilePreviewThemeProvider through data-theme on the root, like FilePreview. The picture itself is always a white page, as the file would print",
|
|
71
87
|
"Engine WASM: PDF, spreadsheet and presentation thumbnails use the same setFilePreview*WasmSource settings as FilePreview. The Word thumbnail engine is used only here; with a strict CSP, self-host @extend-ai/react-docx/docx_wasm_bg.wasm and call setFilePreviewDocxWasmSource at startup"
|
|
72
88
|
]
|