@openpeepshq/react 0.8.4 → 0.8.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.
@@ -10,6 +10,7 @@ const attachmentsOf = (post) => {
10
10
  };
11
11
  const isImage = (att) => att.type === 'image' || att.meta?.mimetype?.startsWith('image/');
12
12
  const isVideo = (att) => att.type === 'video' || att.meta?.mimetype?.startsWith('video/');
13
+ const isAudio = (att) => isAudioAttachment(att);
13
14
  export function Attachments({ post }) {
14
15
  const { enabled: staticRender } = useStaticRender();
15
16
  const attachments = attachmentsOf(post);
@@ -24,7 +25,7 @@ export function Attachments({ post }) {
24
25
  return (_jsx("div", { className: "bg-surface mt-2 w-full overflow-hidden rounded-md", children: _jsx("video", { src: inline.url, poster: inline.previewUrl ?? undefined, controls: true, playsInline: true, preload: "metadata", className: "max-h-[70vh] w-full" }) }));
25
26
  }
26
27
  if (inline) {
27
- return (_jsx("div", { className: "mt-2", children: _jsx(AudioAttachment, { src: inline.url, label: inline.filename ?? inline.description, size: inline.meta?.size }) }));
28
+ return (_jsx("div", { className: "mt-2", children: _jsx(AudioAttachment, { src: inline.url, previewUrl: inline.previewUrl ?? undefined, label: inline.filename ?? inline.description, size: inline.meta?.size }) }));
28
29
  }
29
30
  const indexed = attachments.map((att, idx) => ({ att, idx }));
30
31
  const single = indexed.length === 1;
@@ -43,7 +44,7 @@ export function Attachments({ post }) {
43
44
  ? 'max-h-[600px] w-full object-contain'
44
45
  : 'h-full w-full object-cover';
45
46
  return (_jsxs(_Fragment, { children: [_jsx("div", { className: `mt-2 w-full gap-1 overflow-hidden rounded-md ${cols} ${height}`, children: indexed.map(({ att, idx }) => {
46
- const tile = (_jsx(_Fragment, { children: isImage(att) && (att.previewUrl || att.url) ? (_jsx("img", { src: att.previewUrl ?? att.url ?? '', alt: att.description ?? `attachment ${idx + 1}`, className: mediaClass })) : isVideo(att) && (att.previewUrl || att.url) ? (_jsxs("div", { className: "relative h-full w-full", children: [_jsx("img", { src: att.previewUrl ?? att.url ?? '', alt: att.description ?? `attachment ${idx + 1}`, className: mediaClass }), _jsx(VideoPlayOverlay, { video: true })] })) : (_jsxs("div", { className: "text-muted-foreground flex min-h-24 w-full flex-col items-center justify-center gap-1 p-4 text-center text-xs", children: [_jsx("span", { className: "text-foreground break-all font-medium", children: att.filename ?? att.description ?? `Attachment ${idx + 1}` }), att.meta?.mimetype ? (_jsx("span", { className: "uppercase", children: att.meta.mimetype })) : null] })) }));
47
+ const tile = (_jsx(_Fragment, { children: isImage(att) && (att.previewUrl || att.url) ? (_jsx("img", { src: att.previewUrl ?? att.url ?? '', alt: att.description ?? `attachment ${idx + 1}`, className: mediaClass })) : isVideo(att) && (att.previewUrl || att.url) ? (_jsxs("div", { className: "relative h-full w-full", children: [_jsx("img", { src: att.previewUrl ?? att.url ?? '', alt: att.description ?? `attachment ${idx + 1}`, className: mediaClass }), _jsx(VideoPlayOverlay, { video: true })] })) : isAudio(att) && att.previewUrl ? (_jsxs("div", { className: "relative h-full w-full", children: [_jsx("img", { src: att.previewUrl, alt: att.description ?? `attachment ${idx + 1}`, className: mediaClass }), _jsx(VideoPlayOverlay, { video: true })] })) : (_jsxs("div", { className: "text-muted-foreground flex min-h-24 w-full flex-col items-center justify-center gap-1 p-4 text-center text-xs", children: [_jsx("span", { className: "text-foreground break-all font-medium", children: att.filename ?? att.description ?? `Attachment ${idx + 1}` }), att.meta?.mimetype ? (_jsx("span", { className: "uppercase", children: att.meta.mimetype })) : null] })) }));
47
48
  if (staticRender) {
48
49
  return (_jsx("div", { className: `${tileClass} bg-surface overflow-hidden`, children: tile }, `${att.url ?? idx}-${idx}`));
49
50
  }
@@ -2,6 +2,8 @@ import type { MediaAttachmentData } from '@openpeepshq/common/types';
2
2
  export declare const isAudioAttachment: (att: Pick<MediaAttachmentData, "type" | "meta">) => boolean;
3
3
  export interface AudioAttachmentProps {
4
4
  src?: string;
5
+ /** Waveform/thumbnail image rendered above the controls when available. */
6
+ previewUrl?: string;
5
7
  /** File name shown above the controls. */
6
8
  label?: string;
7
9
  /** Byte size, shown next to the file name when known. */
@@ -10,4 +12,4 @@ export interface AudioAttachmentProps {
10
12
  reserveEnd?: boolean;
11
13
  className?: string;
12
14
  }
13
- export declare const AudioAttachment: ({ src, label, size, reserveEnd, className, }: AudioAttachmentProps) => import("react/jsx-runtime").JSX.Element;
15
+ export declare const AudioAttachment: ({ src, previewUrl, label, size, reserveEnd, className, }: AudioAttachmentProps) => import("react/jsx-runtime").JSX.Element;
@@ -25,7 +25,7 @@ const formatBytes = (bytes) => {
25
25
  const mb = bytes / (1024 * 1024);
26
26
  return `${mb >= 10 ? Math.round(mb) : mb.toFixed(1)} MB`;
27
27
  };
28
- export const AudioAttachment = ({ src, label, size, reserveEnd = false, className = '', }) => {
28
+ export const AudioAttachment = ({ src, previewUrl, label, size, reserveEnd = false, className = '', }) => {
29
29
  const t = useT();
30
30
  const audioRef = useRef(null);
31
31
  const [playing, setPlaying] = useState(false);
@@ -89,5 +89,5 @@ export const AudioAttachment = ({ src, label, size, reserveEnd = false, classNam
89
89
  setCurrent(value);
90
90
  };
91
91
  const canPlay = !!src;
92
- return (_jsxs("div", { role: "group", "aria-label": label ? `${playerLabel}: ${label}` : playerLabel, className: `border-border bg-surface flex w-full flex-col gap-1.5 rounded-md border px-3 py-2 ${className}`, onClick: (e) => e.stopPropagation(), children: [_jsxs("div", { className: `flex flex-col gap-1.5 ${reserveEnd ? 'pr-12' : ''}`, children: [label || fileSize ? (_jsxs("div", { className: "flex items-baseline justify-between gap-3", children: [label ? (_jsx("p", { className: "min-w-0 truncate text-sm font-medium", children: label })) : (_jsx("span", {})), fileSize ? (_jsx("span", { className: "text-muted-foreground shrink-0 text-xs", children: fileSize })) : null] })) : null, _jsxs("div", { className: "flex items-center gap-2", children: [_jsx("button", { type: "button", title: playing ? pauseLabel : playLabel, "aria-label": playing ? pauseLabel : playLabel, disabled: !canPlay, onClick: togglePlay, className: "bg-primary text-primary-foreground flex size-8 shrink-0 items-center justify-center rounded-full disabled:opacity-50", children: playing ? (_jsx(Pause, { className: "size-3.5", "aria-hidden": "true" })) : (_jsx(Play, { className: "size-3.5 translate-x-px", "aria-hidden": "true" })) }), _jsx("span", { className: "text-muted-foreground w-12 shrink-0 text-xs tabular-nums", children: elapsed }), _jsx("input", { type: "range", min: 0, max: duration || 0, step: 0.1, value: Math.min(current, duration || 0), disabled: !canPlay || duration <= 0, "aria-label": seekLabel, onChange: (e) => seek(Number(e.target.value)), className: "accent-primary h-1 min-w-0 flex-1" }), _jsx("span", { className: "text-muted-foreground w-12 shrink-0 text-right text-xs tabular-nums", title: lengthLabel, children: length })] })] }), src ? (_jsx("audio", { ref: audioRef, src: src, preload: "metadata", className: "sr-only" })) : null] }));
92
+ return (_jsxs("div", { role: "group", "aria-label": label ? `${playerLabel}: ${label}` : playerLabel, className: `border-border bg-surface flex w-full flex-col gap-1.5 rounded-md border px-3 py-2 ${className}`, onClick: (e) => e.stopPropagation(), children: [_jsxs("div", { className: `flex flex-col gap-1.5 ${reserveEnd ? 'pr-12' : ''}`, children: [previewUrl ? (_jsx("img", { src: previewUrl, alt: "", className: "bg-muted h-40 w-full rounded-md object-cover" })) : null, label || fileSize ? (_jsxs("div", { className: "flex items-baseline justify-between gap-3", children: [label ? (_jsx("p", { className: "min-w-0 truncate text-sm font-medium", children: label })) : (_jsx("span", {})), fileSize ? (_jsx("span", { className: "text-muted-foreground shrink-0 text-xs", children: fileSize })) : null] })) : null, _jsxs("div", { className: "flex items-center gap-2", children: [_jsx("button", { type: "button", title: playing ? pauseLabel : playLabel, "aria-label": playing ? pauseLabel : playLabel, disabled: !canPlay, onClick: togglePlay, className: "bg-primary text-primary-foreground flex size-8 shrink-0 items-center justify-center rounded-full disabled:opacity-50", children: playing ? (_jsx(Pause, { className: "size-3.5", "aria-hidden": "true" })) : (_jsx(Play, { className: "size-3.5 translate-x-px", "aria-hidden": "true" })) }), _jsx("span", { className: "text-muted-foreground w-12 shrink-0 text-xs tabular-nums", children: elapsed }), _jsx("input", { type: "range", min: 0, max: duration || 0, step: 0.1, value: Math.min(current, duration || 0), disabled: !canPlay || duration <= 0, "aria-label": seekLabel, onChange: (e) => seek(Number(e.target.value)), className: "accent-primary h-1 min-w-0 flex-1" }), _jsx("span", { className: "text-muted-foreground w-12 shrink-0 text-right text-xs tabular-nums", title: lengthLabel, children: length })] })] }), src ? (_jsx("audio", { ref: audioRef, src: src, preload: "metadata", className: "sr-only" })) : null] }));
93
93
  };
@@ -37,7 +37,7 @@ export function GalleryModal({ attachments, initialIndex = 0, onClose, }) {
37
37
  stop(e);
38
38
  onClose();
39
39
  }, children: [attachments.length > 1 ? (_jsxs("button", { type: "button", title: prevLabel, "aria-label": prevLabel, className: "rounded-button absolute left-2 top-1/2 z-50 -translate-y-1/2 bg-white/15 p-4 text-xl font-bold shadow-xl md:left-4", onClick: prev, children: [_jsx("span", { "aria-hidden": "true", children: "\u2190" }), _jsx("span", { className: "sr-only", children: prevLabel })] })) : null, _jsx("div", { className: "max-h-[90vh] max-w-[90vw] overflow-auto p-4", onClick: (e) => e.stopPropagation(), children: attachment.type === 'video' ||
40
- attachment.meta?.mimetype?.startsWith('video/') ? (_jsx(VideoPlayer, { attachment: attachment, className: "max-h-[85vh] max-w-full" }, attachment.url)) : isAudioAttachment(attachment) ? (_jsx(AudioAttachment, { src: attachment.url, label: attachment.filename ?? attachment.description, size: attachment.meta?.size, className: "w-full min-w-[280px] max-w-lg" }, attachment.url)) : attachment.type === 'image' ||
40
+ attachment.meta?.mimetype?.startsWith('video/') ? (_jsx(VideoPlayer, { attachment: attachment, className: "max-h-[85vh] max-w-full" }, attachment.url)) : isAudioAttachment(attachment) ? (_jsx(AudioAttachment, { src: attachment.url, previewUrl: attachment.previewUrl ?? undefined, label: attachment.filename ?? attachment.description, size: attachment.meta?.size, className: "w-full min-w-[280px] max-w-lg" }, attachment.url)) : attachment.type === 'image' ||
41
41
  attachment.meta?.mimetype?.startsWith('image/') ? (_jsx("img", { src: attachment.url ?? attachment.previewUrl ?? '', alt: attachment.description ?? '', className: "max-h-[85vh] max-w-full object-contain" })) : (_jsxs("div", { className: "bg-surface space-y-3 rounded-md p-6 text-center", children: [_jsx("p", { className: "font-medium", children: attachment.filename ?? attachment.description ?? 'Document' }), attachment.url ? (_jsx("a", { href: attachment.url, target: "_blank", rel: "noreferrer", className: "text-primary underline", children: t('posts.gallery.openDocument', {
42
42
  defaultValue: 'Open file',
43
43
  }) })) : null] })) }), attachments.length > 1 ? (_jsxs("button", { type: "button", title: nextLabel, "aria-label": nextLabel, className: "rounded-button absolute right-2 top-1/2 z-50 -translate-y-1/2 bg-white/15 p-4 text-xl font-bold shadow-xl md:right-4", onClick: next, children: [_jsx("span", { "aria-hidden": "true", children: "\u2192" }), _jsx("span", { className: "sr-only", children: nextLabel })] })) : null, _jsxs("button", { type: "button", title: closeLabel, "aria-label": closeLabel, className: "rounded-button bg-primary text-primary-foreground fixed right-4 top-4 z-50 px-3 py-2 text-lg font-bold shadow-xl", onClick: (e) => {
@@ -72,7 +72,11 @@ export function NewPostModal({ visibility: initialVisibility, group, initialCont
72
72
  const selectComposerType = (next) => {
73
73
  if (next === composerType)
74
74
  return;
75
- setContent(draftContent(next));
75
+ const stored = draftContent(next);
76
+ // The note body and poll question share one field. When the destination
77
+ // has no stored draft, keep the current text so note -> poll carries the
78
+ // typed note over as the poll question instead of erasing it.
79
+ setContent(stored || content);
76
80
  setComposerType(next);
77
81
  };
78
82
  // Persist the active draft so note/poll content survives a modal close,
@@ -89,7 +89,7 @@ export const FullResource = ({ post }) => {
89
89
  if (resource.resourceKind === 'audio' && playerVisible) {
90
90
  const audioAtt = resource.attachments?.find((a) => attachmentMediaKind(a) === 'audio');
91
91
  if (audioAtt?.url) {
92
- return (_jsx(ResourceCard, { post: post, showDescription: false, inGroup: !!post.group, preview: _jsx(AudioAttachment, { src: audioAtt.url, label: audioAtt.filename ?? audioAtt.description, size: audioAtt.meta?.size }) }));
92
+ return (_jsx(ResourceCard, { post: post, showDescription: false, inGroup: !!post.group, preview: _jsx(AudioAttachment, { src: audioAtt.url, previewUrl: audioAtt.previewUrl ?? undefined, label: audioAtt.filename ?? audioAtt.description, size: audioAtt.meta?.size }) }));
93
93
  }
94
94
  }
95
95
  // All kinds: ResourceCard with click overlay
@@ -127,6 +127,15 @@ export const ResourceCard = ({ post, layout = 'card', preview, showDescription =
127
127
  const fileAtt = attachments.find((att) => attachmentMediaKind(att) === 'file' ||
128
128
  attachmentMediaKind(att) === 'video' ||
129
129
  attachmentMediaKind(att) === 'audio');
130
+ // File resources show their filename (with extension) so users can tell
131
+ // what they're about to download; other kinds show the size.
132
+ if (resource.resourceKind === 'file') {
133
+ const size = fileAtt?.meta?.size;
134
+ const filename = fileAtt?.filename;
135
+ if (filename && size)
136
+ return `${filename} · ${formatSize(size)}`;
137
+ return filename ?? (size ? formatSize(size) : null);
138
+ }
130
139
  const size = fileAtt?.meta?.size;
131
140
  if (size)
132
141
  return formatSize(size);
@@ -40,6 +40,23 @@ const resourcePost = (tags) => ({
40
40
  tags,
41
41
  },
42
42
  });
43
+ const filePost = () => ({
44
+ id: 'post-file',
45
+ type: 'resource',
46
+ data: {
47
+ type: 'resource',
48
+ title: 'Quarterly report',
49
+ resourceKind: 'file',
50
+ attachments: [
51
+ {
52
+ type: 'file',
53
+ url: 'https://cdn.example.com/report.pdf',
54
+ filename: 'report.pdf',
55
+ meta: { size: 2500000, mimetype: 'application/pdf' },
56
+ },
57
+ ],
58
+ },
59
+ });
43
60
  describe('ResourceCard', () => {
44
61
  let root;
45
62
  let container;
@@ -72,4 +89,15 @@ describe('ResourceCard', () => {
72
89
  hashtag: 'juneteenth',
73
90
  });
74
91
  });
92
+ it('shows the filename with its extension for a file resource', async () => {
93
+ container = document.createElement('div');
94
+ document.body.appendChild(container);
95
+ root = createRoot(container);
96
+ await act(async () => {
97
+ root?.render(createElement(ResourceCard, { post: filePost() }));
98
+ });
99
+ // filename + extension, followed by the formatted size
100
+ expect(container.textContent).toContain('report.pdf');
101
+ expect(container.textContent).toContain('2.4 MB');
102
+ });
75
103
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpeepshq/react",
3
- "version": "0.8.4",
3
+ "version": "0.8.5",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -52,9 +52,9 @@
52
52
  "simple-icons": "^16.31.0",
53
53
  "uuidv7": "^1.0.2",
54
54
  "@openpeepshq/client": "^0.2.1",
55
- "@openpeepshq/common": "^0.4.0",
56
55
  "@openpeepshq/greenscreen": "^0.2.1",
57
- "@openpeepshq/react-ui": "^0.4.1"
56
+ "@openpeepshq/react-ui": "^0.4.1",
57
+ "@openpeepshq/common": "^0.4.0"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "react": "^18.3.0 || ^19.0.0",
@@ -21,6 +21,7 @@ const isImage = (att: MediaAttachmentData) =>
21
21
  att.type === 'image' || att.meta?.mimetype?.startsWith('image/');
22
22
  const isVideo = (att: MediaAttachmentData) =>
23
23
  att.type === 'video' || att.meta?.mimetype?.startsWith('video/');
24
+ const isAudio = (att: MediaAttachmentData) => isAudioAttachment(att);
24
25
 
25
26
  export function Attachments({ post }: AttachmentsProps) {
26
27
  const { enabled: staticRender } = useStaticRender();
@@ -55,6 +56,7 @@ export function Attachments({ post }: AttachmentsProps) {
55
56
  <div className="mt-2">
56
57
  <AudioAttachment
57
58
  src={inline.url}
59
+ previewUrl={inline.previewUrl ?? undefined}
58
60
  label={inline.filename ?? inline.description}
59
61
  size={inline.meta?.size}
60
62
  />
@@ -102,6 +104,15 @@ export function Attachments({ post }: AttachmentsProps) {
102
104
  />
103
105
  <VideoPlayOverlay video />
104
106
  </div>
107
+ ) : isAudio(att) && att.previewUrl ? (
108
+ <div className="relative h-full w-full">
109
+ <img
110
+ src={att.previewUrl}
111
+ alt={att.description ?? `attachment ${idx + 1}`}
112
+ className={mediaClass}
113
+ />
114
+ <VideoPlayOverlay video />
115
+ </div>
105
116
  ) : (
106
117
  <div className="text-muted-foreground flex min-h-24 w-full flex-col items-center justify-center gap-1 p-4 text-center text-xs">
107
118
  <span className="text-foreground break-all font-medium">
@@ -10,6 +10,8 @@ export const isAudioAttachment = (
10
10
 
11
11
  export interface AudioAttachmentProps {
12
12
  src?: string;
13
+ /** Waveform/thumbnail image rendered above the controls when available. */
14
+ previewUrl?: string;
13
15
  /** File name shown above the controls. */
14
16
  label?: string;
15
17
  /** Byte size, shown next to the file name when known. */
@@ -43,6 +45,7 @@ const formatBytes = (bytes?: number): string | undefined => {
43
45
 
44
46
  export const AudioAttachment = ({
45
47
  src,
48
+ previewUrl,
46
49
  label,
47
50
  size,
48
51
  reserveEnd = false,
@@ -122,6 +125,13 @@ export const AudioAttachment = ({
122
125
  onClick={(e) => e.stopPropagation()}
123
126
  >
124
127
  <div className={`flex flex-col gap-1.5 ${reserveEnd ? 'pr-12' : ''}`}>
128
+ {previewUrl ? (
129
+ <img
130
+ src={previewUrl}
131
+ alt=""
132
+ className="bg-muted h-40 w-full rounded-md object-cover"
133
+ />
134
+ ) : null}
125
135
  {label || fileSize ? (
126
136
  <div className="flex items-baseline justify-between gap-3">
127
137
  {label ? (
@@ -86,6 +86,7 @@ export function GalleryModal({
86
86
  <AudioAttachment
87
87
  key={attachment.url}
88
88
  src={attachment.url}
89
+ previewUrl={attachment.previewUrl ?? undefined}
89
90
  label={attachment.filename ?? attachment.description}
90
91
  size={attachment.meta?.size}
91
92
  className="w-full min-w-[280px] max-w-lg"
@@ -135,7 +135,11 @@ export function NewPostModal({
135
135
 
136
136
  const selectComposerType = (next: ComposerType) => {
137
137
  if (next === composerType) return;
138
- setContent(draftContent(next));
138
+ const stored = draftContent(next);
139
+ // The note body and poll question share one field. When the destination
140
+ // has no stored draft, keep the current text so note -> poll carries the
141
+ // typed note over as the poll question instead of erasing it.
142
+ setContent(stored || content);
139
143
  setComposerType(next);
140
144
  };
141
145
 
@@ -123,6 +123,7 @@ export const FullResource = ({ post }: FullResourceProps) => {
123
123
  preview={
124
124
  <AudioAttachment
125
125
  src={audioAtt.url}
126
+ previewUrl={audioAtt.previewUrl ?? undefined}
126
127
  label={audioAtt.filename ?? audioAtt.description}
127
128
  size={audioAtt.meta?.size}
128
129
  />
@@ -257,6 +257,14 @@ export const ResourceCard = ({
257
257
  attachmentMediaKind(att) === 'video' ||
258
258
  attachmentMediaKind(att) === 'audio',
259
259
  );
260
+ // File resources show their filename (with extension) so users can tell
261
+ // what they're about to download; other kinds show the size.
262
+ if (resource.resourceKind === 'file') {
263
+ const size = fileAtt?.meta?.size;
264
+ const filename = fileAtt?.filename;
265
+ if (filename && size) return `${filename} · ${formatSize(size)}`;
266
+ return filename ?? (size ? formatSize(size) : null);
267
+ }
260
268
  const size = fileAtt?.meta?.size;
261
269
  if (size) return formatSize(size);
262
270
  return null;