@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.
Files changed (41) hide show
  1. package/dist/components/file-preview/components/renderer-types.d.ts +4 -1
  2. package/dist/components/file-preview/components/renderer-types.d.ts.map +1 -1
  3. package/dist/components/file-preview/components/viewer/viewer-components.stories.d.ts.map +1 -1
  4. package/dist/components/file-preview/file-preview.d.ts.map +1 -1
  5. package/dist/components/file-preview/file-preview.stories.d.ts +49 -2
  6. package/dist/components/file-preview/file-preview.stories.d.ts.map +1 -1
  7. package/dist/components/file-thumbnail/components/previews/html-preview.d.ts.map +1 -1
  8. package/dist/components/file-thumbnail/components/previews/image-preview.d.ts.map +1 -1
  9. package/dist/components/file-thumbnail/components/previews/markdown-preview.d.ts.map +1 -1
  10. package/dist/components/file-thumbnail/components/previews/reveal-class-name.d.ts +4 -2
  11. package/dist/components/file-thumbnail/components/previews/reveal-class-name.d.ts.map +1 -1
  12. package/dist/components/file-thumbnail/components/previews/scaled-page.d.ts +4 -1
  13. package/dist/components/file-thumbnail/components/previews/scaled-page.d.ts.map +1 -1
  14. package/dist/components/file-thumbnail/file-thumbnail.d.ts +2 -0
  15. package/dist/components/file-thumbnail/file-thumbnail.d.ts.map +1 -1
  16. package/dist/components/file-thumbnail/file-thumbnail.stories.d.ts +76 -10
  17. package/dist/components/file-thumbnail/file-thumbnail.stories.d.ts.map +1 -1
  18. package/dist/index.css +1 -1
  19. package/dist/index.es.js +50 -33
  20. package/dist/index.es.js.map +1 -1
  21. package/package.json +15 -7
  22. package/src/__storybook__/parent-block.tsx +21 -0
  23. package/src/components/file-preview/__stories__/fixtures.ts +66 -0
  24. package/src/components/file-preview/components/renderer-types.ts +4 -1
  25. package/src/components/file-preview/components/viewer/viewer-components.stories.tsx +2 -8
  26. package/src/components/file-preview/file-preview.json +15 -0
  27. package/src/components/file-preview/file-preview.stories.tsx +378 -38
  28. package/src/components/file-preview/file-preview.tsx +7 -2
  29. package/src/components/file-thumbnail/__stories__/fixtures.ts +99 -0
  30. package/src/components/file-thumbnail/__stories__/types.ts +26 -0
  31. package/src/components/file-thumbnail/components/previews/html-preview.tsx +5 -1
  32. package/src/components/file-thumbnail/components/previews/image-preview.tsx +3 -1
  33. package/src/components/file-thumbnail/components/previews/markdown-preview.tsx +5 -1
  34. package/src/components/file-thumbnail/components/previews/reveal-class-name.ts +8 -8
  35. package/src/components/file-thumbnail/components/previews/scaled-page.tsx +6 -1
  36. package/src/components/file-thumbnail/file-thumbnail.json +17 -1
  37. package/src/components/file-thumbnail/file-thumbnail.stories.tsx +551 -84
  38. package/src/components/file-thumbnail/file-thumbnail.tsx +24 -7
  39. /package/src/components/file-thumbnail/components/shared/__tests__/{generation-queue.spec.ts → generation-queue.test.ts} +0 -0
  40. /package/src/components/file-thumbnail/hooks/__tests__/{use-object-url.spec.ts → use-object-url.test.ts} +0 -0
  41. /package/src/lib/__tests__/{file-kinds.spec.ts → file-kinds.test.ts} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swisper.ai/web-file-preview",
3
- "version": "0.0.2",
3
+ "version": "0.0.5",
4
4
  "description": "In-browser preview for PDF, Word, Excel, PowerPoint, CSV, image, audio and video files",
5
5
  "keywords": [
6
6
  "react",
@@ -61,10 +61,10 @@
61
61
  "@extend-ai/react-pptx": "0.2.1",
62
62
  "@extend-ai/react-xlsx": "^0.16.4",
63
63
  "@radix-ui/react-slot": "^1.1.0",
64
- "@swisper.ai/icons": "0.0.2",
65
- "@swisper.ai/tailwind-config": "0.0.2",
66
- "@swisper.ai/ui": "0.0.2",
67
- "@swisper.ai/web-core": "0.0.2",
64
+ "@swisper.ai/icons": "0.0.3",
65
+ "@swisper.ai/tailwind-config": "0.0.3",
66
+ "@swisper.ai/ui": "0.1.2",
67
+ "@swisper.ai/web-core": "0.0.3",
68
68
  "@tanstack/react-virtual": "^3.14.5",
69
69
  "docx-preview": "^0.4.0",
70
70
  "papaparse": "^5.5.3",
@@ -74,8 +74,12 @@
74
74
  "usehooks-ts": "^3.1.1"
75
75
  },
76
76
  "devDependencies": {
77
- "@fintama/vite-config": "0.1.1",
78
- "@fintama/vitest-config": "0.1.1",
77
+ "@fintama/swisper-int-storybook-theme": "0.0.1",
78
+ "@fintama/swisper-int-vite-config": "0.0.1",
79
+ "@fintama/swisper-int-vitest-config": "0.0.1",
80
+ "@storybook/addon-a11y": "10.6.0",
81
+ "@storybook/addon-docs": "10.6.0",
82
+ "@storybook/addon-vitest": "10.6.0",
79
83
  "@storybook/react-vite": "10.6.0",
80
84
  "@swisper.ai/int-eslint-config": "0.0.1",
81
85
  "@swisper.ai/int-typescript-config": "0.0.1",
@@ -88,9 +92,11 @@
88
92
  "@types/react": "18.3.31",
89
93
  "@types/react-dom": "18.3.7",
90
94
  "@typescript/typescript6": "6.0.2",
95
+ "@vitest/browser-playwright": "4.1.11",
91
96
  "concurrently": "^9.1.2",
92
97
  "eslint": "10.9.1",
93
98
  "jsdom": "30.1.1",
99
+ "playwright": "1.63.0",
94
100
  "react": "18.3.1",
95
101
  "react-dom": "18.3.1",
96
102
  "rimraf": "^6.0.1",
@@ -121,6 +127,8 @@
121
127
  "dev:css": "tailwindcss -i ./src/index.css -o ./dist/index.css --watch",
122
128
  "lint": "eslint . --max-warnings=0",
123
129
  "test": "vitest run",
130
+ "test:unit": "vitest run --project unit",
131
+ "test:e2e": "vitest run --project storybook",
124
132
  "typecheck": "tsc --noEmit"
125
133
  }
126
134
  }
@@ -0,0 +1,21 @@
1
+ import type { ReactNode } from 'react';
2
+
3
+ import { Typography } from '@swisper.ai/ui';
4
+
5
+ export interface ParentBlockProps {
6
+ /** The parent or context exactly as the component's `<name>.json` spells it. */
7
+ parent: string;
8
+ children: ReactNode;
9
+ }
10
+
11
+ /** One block of an `Examples` story: the spec's parent name above the component in that parent. */
12
+ export function ParentBlock({ parent, children }: ParentBlockProps) {
13
+ return (
14
+ <div className="flex flex-col gap-8">
15
+ <Typography variant="caption-md" className="text-text-tertiary">
16
+ {parent}
17
+ </Typography>
18
+ {children}
19
+ </div>
20
+ );
21
+ }
@@ -0,0 +1,66 @@
1
+ // Vite serves these same-origin, so `src` is fetched without CORS concerns.
2
+ export const PDF_URL = new URL('../../../__fixtures__/quarterly-report.pdf', import.meta.url).href;
3
+ export const PRESENTATION_URL = new URL(
4
+ '../../../__fixtures__/quarterly-deck.pptx',
5
+ import.meta.url,
6
+ ).href;
7
+ export const SPREADSHEET_URL = new URL(
8
+ '../../../__fixtures__/quarterly-model.xlsx',
9
+ import.meta.url,
10
+ ).href;
11
+ export const WORD_URL = new URL('../../../__fixtures__/quarterly-report.docx', import.meta.url)
12
+ .href;
13
+ export const MARKDOWN_URL = new URL('../../../__fixtures__/quarterly-report.md', import.meta.url)
14
+ .href;
15
+ export const HTML_URL = new URL('../../../__fixtures__/quarterly-report.html', import.meta.url)
16
+ .href;
17
+ export const IMAGE_URL = new URL(
18
+ '../../../__fixtures__/quarterly-report-page-1.png',
19
+ import.meta.url,
20
+ ).href;
21
+
22
+ const INVOICE_CUSTOMERS = [
23
+ 'Alpenblick Tools',
24
+ 'Nordlicht Logistics',
25
+ '"Keller, Brunner & Partner"',
26
+ 'Seefeld Pharma',
27
+ 'Bergwerk Studio',
28
+ ];
29
+ const INVOICE_REGIONS = ['North', 'South', 'East', 'West'];
30
+
31
+ /**
32
+ * An invoice export a user picked from disk: 500 rows, so the table virtualises, and a
33
+ * quoted customer name with a comma in it.
34
+ */
35
+ export const INVOICES_CSV = new Blob(
36
+ [
37
+ 'Invoice,Customer,Region,Amount (CHF)\n' +
38
+ Array.from({ length: 500 }, (_, index) =>
39
+ [
40
+ `INV-2026-${String(index + 1).padStart(4, '0')}`,
41
+ INVOICE_CUSTOMERS[index % INVOICE_CUSTOMERS.length],
42
+ INVOICE_REGIONS[index % INVOICE_REGIONS.length],
43
+ 1200 + ((index * 137) % 9000),
44
+ ].join(','),
45
+ ).join('\n'),
46
+ ],
47
+ { type: 'text/csv' },
48
+ );
49
+
50
+ /** Right extension, wrong bytes: the renderer rejects it and the error slot shows. */
51
+ export const BROKEN_PDF = new Blob(['this is not a pdf'], { type: 'application/pdf' });
52
+
53
+ /** An image the browser cannot decode. Fails without loading a viewer engine first. */
54
+ export const BROKEN_IMAGE = new Blob(['this is not an image'], { type: 'image/png' });
55
+
56
+ /** The `src` options of the Playground. "Missing file" answers 404, so the error part shows. */
57
+ export const PLAYGROUND_SOURCES: Record<string, string> = {
58
+ PDF: PDF_URL,
59
+ PowerPoint: PRESENTATION_URL,
60
+ Excel: SPREADSHEET_URL,
61
+ Word: WORD_URL,
62
+ Markdown: MARKDOWN_URL,
63
+ HTML: HTML_URL,
64
+ Image: IMAGE_URL,
65
+ 'Missing file': '/files/missing/quarterly-report.pdf',
66
+ };
@@ -18,7 +18,10 @@ export interface FilePreviewRendererProps {
18
18
  * would split a shared chunk out of the published `index.es.js`.
19
19
  */
20
20
  theme: FilePreviewTheme;
21
- /** Already includes `invisible` until `onLoad` fires, so half-rendered content never shows. */
21
+ /**
22
+ * Already hides the root while the preview's `data-status` is `loading`, so half-rendered
23
+ * content never shows.
24
+ */
22
25
  className: string;
23
26
  /** Call once, after the file has painted. */
24
27
  onLoad: () => void;
@@ -6,7 +6,7 @@ import type { Meta, StoryObj } from '@storybook/react-vite';
6
6
  import * as React from 'react';
7
7
 
8
8
  import { AddIcon, LeftPanelOpenIcon, RemoveIcon } from '@swisper.ai/icons';
9
- import { TooltipProvider } from '@swisper.ai/ui';
9
+ import { withTooltip } from '@swisper.ai/ui';
10
10
 
11
11
  import { SheetTabs as SheetTabsComponent } from '../spreadsheet/sheet-tabs';
12
12
 
@@ -40,13 +40,7 @@ const ZOOM_PRESETS = [0.5, 0.75, 1, 1.25, 1.5, 2];
40
40
  const meta: Meta = {
41
41
  title: 'Files/FilePreview/Layout/Components',
42
42
  // `ViewerToolbar` provides this; parts shown without one need it for their tooltips.
43
- decorators: [
44
- (Story) => (
45
- <TooltipProvider>
46
- <Story />
47
- </TooltipProvider>
48
- ),
49
- ],
43
+ decorators: [withTooltip],
50
44
  };
51
45
 
52
46
  export default meta;
@@ -2,6 +2,20 @@
2
2
  "$schema": "../../../../int-eslint-config/schemas/component.schema.json",
3
3
  "component": "file-preview",
4
4
  "purpose": "Shows a file inline — PDF, image, video, plain text, CSV, Excel (.xlsx/.xlsm/.xls), Word (.docx), PowerPoint (.pptx/.ppt), Markdown and HTML — as a compound component: FilePreview downloads src (or takes fileBlob) and owns the load status, FilePreviewFile picks a renderer by extension, and the consumer composes FilePreviewLoader and FilePreviewError, because it renders no loader or error UI of its own. Only HTML is shown in an iframe, and only with sandbox=\"\".",
5
+ "anatomy": [
6
+ "import {",
7
+ " FilePreview,",
8
+ " FilePreviewFile,",
9
+ " FilePreviewError,",
10
+ " FilePreviewLoader,",
11
+ "} from '@swisper.ai/web-file-preview';",
12
+ "",
13
+ "<FilePreview>",
14
+ " <FilePreviewFile />",
15
+ " <FilePreviewError />",
16
+ " <FilePreviewLoader />",
17
+ "</FilePreview>"
18
+ ],
5
19
  "useWhen": [
6
20
  "Showing an attachment or generated document inside a chat panel, drawer or dialog without leaving the page",
7
21
  "The load and failure states must be visible to the user — every renderer reports success and failure, including a 404, a CORS refusal or a corrupt file",
@@ -55,6 +69,7 @@
55
69
  "fileName is the original file name: its last extension, matched case-insensitively, picks the renderer and decides whether the file can be previewed at all; it is also the file's accessible name",
56
70
  "onLoad is called when the renderer has shown the file; onError on a network or CORS failure, an HTTP error status, a file the renderer cannot open (corrupt PDF, undecodable image, broken workbook or deck), or once for an unsupported file type",
57
71
  "data-status on the root goes loading → loaded, or error",
72
+ "Slots: the root carries data-slot=file-preview and the group/file-preview class, the overlays data-slot=file-preview-loader and file-preview-error. FilePreviewFile hides itself from the root's state (group-data-[status=loading]/file-preview:invisible), and a className on any part can use the same selector",
58
73
  "FilePreviewFile, FilePreviewLoader and FilePreviewError throw a [web-file-preview] error when rendered outside a FilePreview",
59
74
  "FilePreviewLoader and FilePreviewError are absolute inset-0 overlays on the relative root and render only in their status; FilePreviewError's children is a render function ({ error }) => ReactNode",
60
75
  "Theme: FilePreviewThemeProvider (theme 'dark' | 'light') sets the theme of every preview below it; without one, previews are dark, matching the design tokens. Mount it once, next to wherever the host decides its colour scheme. The root carries data-theme, so the design system's theme-light: variant applies inside it, and the theme is handed to engines that paint their own colours (the spreadsheet grid). File content is never recoloured: PDF, Word and slide pages stay as authored",