@swisper.ai/web-file-preview 0.0.2 → 0.0.4

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 +14 -6
  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
@@ -503,13 +503,14 @@ export const FileThumbnail = forwardRef<HTMLDivElement, FileThumbnailProps>(
503
503
  aria-label={fileName}
504
504
  aria-busy={status === 'loading' || undefined}
505
505
  title={fileName}
506
+ data-slot="file-thumbnail"
506
507
  data-testid="file-thumbnail"
507
508
  data-kind={kind ?? 'unsupported'}
508
509
  data-status={status}
509
510
  // Scopes the design system's `theme-light:` variant to this thumbnail.
510
511
  data-theme={theme}
511
512
  className={cn(
512
- 'relative size-full overflow-hidden',
513
+ 'group/file-thumbnail relative size-full overflow-hidden',
513
514
  'user-select-no',
514
515
  'rounded-[8px]',
515
516
  'bg-white',
@@ -629,6 +630,7 @@ export const FileThumbnailLoader = forwardRef<HTMLDivElement, FileThumbnailLoade
629
630
  ref={ref}
630
631
  // The root's `aria-busy` already announces the loading.
631
632
  aria-hidden
633
+ data-slot="file-thumbnail-loader"
632
634
  data-testid="file-thumbnail-loader"
633
635
  style={SURFACE_STYLE}
634
636
  className={cn(
@@ -652,21 +654,35 @@ export interface FileThumbnailFallbackProps {
652
654
  /** Replaces the default file-name label. */
653
655
  children?: ReactNode;
654
656
  className?: string;
657
+ /** Extra classes for the default file-name label. Unused once `children` replace it. */
658
+ labelClassName?: string;
659
+ }
660
+
661
+ interface FileNameLabelProps {
662
+ fileName: string;
663
+ className?: string;
655
664
  }
656
665
 
657
666
  /**
658
667
  * The file name, truncated in the middle so the extension stays visible: `longfilena…pdf`.
659
668
  * The stem keeps its trailing dot and takes the ellipsis; the extension never shrinks.
660
669
  */
661
- function FileNameLabel({ fileName }: { fileName: string }) {
670
+ function FileNameLabel({ fileName, className }: FileNameLabelProps) {
662
671
  const extensionLength = getFileExtension(fileName).length;
663
672
  const stem = extensionLength ? fileName.slice(0, -extensionLength) : fileName;
664
673
  const extension = extensionLength ? fileName.slice(-extensionLength) : '';
665
674
 
666
675
  return (
667
- <Typography variant="body-small-low" className={cn('flex min-w-0', 'text-black')}>
668
- <span className="truncate">{stem}</span>
669
- {extension && <span className="shrink-0">{extension}</span>}
676
+ // `asChild`, so the slot name is the label's own: Typography sets `data-slot` on its element.
677
+ <Typography
678
+ variant="body-small-low"
679
+ className={cn('flex min-w-0', 'text-black', className)}
680
+ asChild
681
+ >
682
+ <p data-slot="file-thumbnail-fallback-label">
683
+ <span className="truncate">{stem}</span>
684
+ {extension && <span className="shrink-0">{extension}</span>}
685
+ </p>
670
686
  </Typography>
671
687
  );
672
688
  }
@@ -677,7 +693,7 @@ function FileNameLabel({ fileName }: { fileName: string }) {
677
693
  * name, truncated in the middle so the extension stays visible (`longfilena…pdf`).
678
694
  */
679
695
  export const FileThumbnailFallback = forwardRef<HTMLDivElement, FileThumbnailFallbackProps>(
680
- ({ asChild = false, children, className }, ref) => {
696
+ ({ asChild = false, children, className, labelClassName }, ref) => {
681
697
  const { fileName, status } = useFileThumbnailContext('FileThumbnailFallback');
682
698
  const Component = asChild ? Slot : 'div';
683
699
 
@@ -688,12 +704,13 @@ export const FileThumbnailFallback = forwardRef<HTMLDivElement, FileThumbnailFal
688
704
  return (
689
705
  <Component
690
706
  ref={ref}
707
+ data-slot="file-thumbnail-fallback"
691
708
  data-testid="file-thumbnail-fallback"
692
709
  // By default the loader's surface, still, with the name on it.
693
710
  style={children === undefined ? SURFACE_STYLE : undefined}
694
711
  className={cn('absolute inset-0 flex items-center justify-center p-8', className)}
695
712
  >
696
- {children ?? <FileNameLabel fileName={fileName} />}
713
+ {children ?? <FileNameLabel fileName={fileName} className={labelClassName} />}
697
714
  </Component>
698
715
  );
699
716
  },