@poolse/react-ui 1.0.5 → 1.1.0

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/index.d.cts CHANGED
@@ -158,6 +158,13 @@ interface MessageBubbleProps {
158
158
  * CSS until the row is hovered.
159
159
  */
160
160
  actionsTrigger?: ReactNode;
161
+ /**
162
+ * Render the message's attachments INSIDE the bubble (WhatsApp-
163
+ * style): images mosaic at the top, file cards below, then the
164
+ * message body. Defaults to `true`. Pass `false` if you're rendering
165
+ * attachments yourself outside the bubble.
166
+ */
167
+ showAttachments?: boolean;
161
168
  }
162
169
  /**
163
170
  * One message bubble. The default renderer for `<ConversationView>` —
@@ -168,7 +175,7 @@ interface MessageBubbleProps {
168
175
  * (coral for self, surface-with-border for others), matching the
169
176
  * brand-kit chat showcase.
170
177
  */
171
- declare function MessageBubble({ message, currentUserId, readState, labelFor, onQuotedClick, groupPosition, maxBodyLength, markdown, showSenderName, actionsTrigger, }: MessageBubbleProps): react_jsx_runtime.JSX.Element;
178
+ declare function MessageBubble({ message, currentUserId, readState, labelFor, onQuotedClick, groupPosition, maxBodyLength, markdown, showSenderName, actionsTrigger, showAttachments, }: MessageBubbleProps): react_jsx_runtime.JSX.Element;
172
179
 
173
180
  interface EditableMessageBubbleProps {
174
181
  message: Message;
@@ -409,9 +416,11 @@ interface UploadQueueStripProps {
409
416
  onDismiss: (localId: string) => void;
410
417
  }
411
418
  /**
412
- * Strip of pending / uploading / errored attachments shown above the
413
- * composer. Ready items aren't included — they get cleared by the
414
- * parent once the send completes.
419
+ * Strip of staged attachments shown above the composer — pending,
420
+ * uploading, ready (waiting for the user to hit send), or errored.
421
+ * Ready chips are the user's signal that "these will go out when I
422
+ * press send" — the composer parent sweeps them out only after the
423
+ * send completes successfully.
415
424
  */
416
425
  declare function UploadQueueStrip({ items, onCancel, onDismiss }: UploadQueueStripProps): react_jsx_runtime.JSX.Element | null;
417
426
 
package/dist/index.d.ts CHANGED
@@ -158,6 +158,13 @@ interface MessageBubbleProps {
158
158
  * CSS until the row is hovered.
159
159
  */
160
160
  actionsTrigger?: ReactNode;
161
+ /**
162
+ * Render the message's attachments INSIDE the bubble (WhatsApp-
163
+ * style): images mosaic at the top, file cards below, then the
164
+ * message body. Defaults to `true`. Pass `false` if you're rendering
165
+ * attachments yourself outside the bubble.
166
+ */
167
+ showAttachments?: boolean;
161
168
  }
162
169
  /**
163
170
  * One message bubble. The default renderer for `<ConversationView>` —
@@ -168,7 +175,7 @@ interface MessageBubbleProps {
168
175
  * (coral for self, surface-with-border for others), matching the
169
176
  * brand-kit chat showcase.
170
177
  */
171
- declare function MessageBubble({ message, currentUserId, readState, labelFor, onQuotedClick, groupPosition, maxBodyLength, markdown, showSenderName, actionsTrigger, }: MessageBubbleProps): react_jsx_runtime.JSX.Element;
178
+ declare function MessageBubble({ message, currentUserId, readState, labelFor, onQuotedClick, groupPosition, maxBodyLength, markdown, showSenderName, actionsTrigger, showAttachments, }: MessageBubbleProps): react_jsx_runtime.JSX.Element;
172
179
 
173
180
  interface EditableMessageBubbleProps {
174
181
  message: Message;
@@ -409,9 +416,11 @@ interface UploadQueueStripProps {
409
416
  onDismiss: (localId: string) => void;
410
417
  }
411
418
  /**
412
- * Strip of pending / uploading / errored attachments shown above the
413
- * composer. Ready items aren't included — they get cleared by the
414
- * parent once the send completes.
419
+ * Strip of staged attachments shown above the composer — pending,
420
+ * uploading, ready (waiting for the user to hit send), or errored.
421
+ * Ready chips are the user's signal that "these will go out when I
422
+ * press send" — the composer parent sweeps them out only after the
423
+ * send completes successfully.
415
424
  */
416
425
  declare function UploadQueueStrip({ items, onCancel, onDismiss }: UploadQueueStripProps): react_jsx_runtime.JSX.Element | null;
417
426
 
package/dist/index.js CHANGED
@@ -336,6 +336,7 @@ function UploadChip({
336
336
  }) {
337
337
  const pct = item.byteSize > 0 ? Math.min(100, Math.round(item.loaded / item.byteSize * 100)) : 0;
338
338
  const isError = item.status === "error";
339
+ const isReady = item.status === "ready";
339
340
  const isInFlight = item.status === "pending" || item.status === "uploading";
340
341
  return /* @__PURE__ */ jsxs(
341
342
  "div",
@@ -343,10 +344,15 @@ function UploadChip({
343
344
  className: `poolse-upload-chip poolse-upload-chip--${item.status}`,
344
345
  "data-status": item.status,
345
346
  children: [
346
- /* @__PURE__ */ jsx("div", { className: "poolse-upload-chip__icon", "aria-hidden": "true", children: /* @__PURE__ */ jsx(PoolseIcon, { name: isError ? "attachment" : "attachment", size: 18, label: null }) }),
347
+ /* @__PURE__ */ jsx("div", { className: "poolse-upload-chip__icon", "aria-hidden": "true", children: /* @__PURE__ */ jsx(PoolseIcon, { name: isReady ? "check" : "attachment", size: 18, label: null }) }),
347
348
  /* @__PURE__ */ jsxs("div", { className: "poolse-upload-chip__body", children: [
348
349
  /* @__PURE__ */ jsx("div", { className: "poolse-upload-chip__filename", title: item.filename, children: item.filename }),
349
- isError ? /* @__PURE__ */ jsx("div", { className: "poolse-upload-chip__error", children: item.error?.message ?? "Upload failed" }) : /* @__PURE__ */ jsx(
350
+ isError ? /* @__PURE__ */ jsx("div", { className: "poolse-upload-chip__error", children: item.error?.message ?? "Upload failed" }) : isReady ? (
351
+ // No progress bar once the upload is done — the chip itself
352
+ // is the "staged, waiting on send" signal. A short caption
353
+ // makes that explicit for screen-readers + glance-readers.
354
+ /* @__PURE__ */ jsx("div", { className: "poolse-upload-chip__ready-label", children: "Ready to send" })
355
+ ) : /* @__PURE__ */ jsx(
350
356
  "div",
351
357
  {
352
358
  className: "poolse-upload-chip__bar",
@@ -365,8 +371,8 @@ function UploadChip({
365
371
  type: "button",
366
372
  className: "poolse-upload-chip__action",
367
373
  onClick: isInFlight ? onCancel : onDismiss,
368
- "aria-label": isInFlight ? `Cancel upload of ${item.filename}` : `Dismiss ${item.filename}`,
369
- title: isInFlight ? "Cancel" : "Dismiss",
374
+ "aria-label": isInFlight ? `Cancel upload of ${item.filename}` : isReady ? `Remove ${item.filename}` : `Dismiss ${item.filename}`,
375
+ title: isInFlight ? "Cancel" : isReady ? "Remove" : "Dismiss",
370
376
  children: "\xD7"
371
377
  }
372
378
  )
@@ -429,9 +435,7 @@ var MentionInput = forwardRef(
429
435
  const fileInputRef = useRef(null);
430
436
  useAutogrow(taRef, value);
431
437
  const { queue, uploadAll, cancel: cancelUpload, remove: removeUpload } = useAttachmentUpload();
432
- const visibleUploads = queue.filter(
433
- (it) => it.status === "pending" || it.status === "uploading" || it.status === "error"
434
- );
438
+ const visibleUploads = queue.filter((it) => it.status !== "cancelled");
435
439
  const readyCount = queue.filter((it) => it.status === "ready").length;
436
440
  const uploading = queue.some((it) => it.status === "pending" || it.status === "uploading");
437
441
  const addFiles = (files) => {
@@ -705,19 +709,10 @@ var MessageComposer = forwardRef(
705
709
  const taRef = useRef(null);
706
710
  const fileInputRef = useRef(null);
707
711
  useAutogrow(taRef, value);
708
- const {
709
- queue,
710
- uploadAll,
711
- cancel: cancelUpload,
712
- remove: removeUpload
713
- } = useAttachmentUpload();
714
- const visibleUploads = queue.filter(
715
- (it) => it.status === "pending" || it.status === "uploading" || it.status === "error"
716
- );
712
+ const { queue, uploadAll, cancel: cancelUpload, remove: removeUpload } = useAttachmentUpload();
713
+ const visibleUploads = queue.filter((it) => it.status !== "cancelled");
717
714
  const readyCount = queue.filter((it) => it.status === "ready").length;
718
- const uploading = queue.some(
719
- (it) => it.status === "pending" || it.status === "uploading"
720
- );
715
+ const uploading = queue.some((it) => it.status === "pending" || it.status === "uploading");
721
716
  const addFiles = (files) => {
722
717
  if (!attachments || files.length === 0) return;
723
718
  void uploadAll(
@@ -888,6 +883,24 @@ function ReplyChip({
888
883
  )
889
884
  ] });
890
885
  }
886
+ function Avatar({ src, name, online, size = "md", className }) {
887
+ const initials = computeInitials(name);
888
+ const classes = [
889
+ "poolse-avatar",
890
+ size === "sm" ? "poolse-avatar--sm" : null,
891
+ size === "lg" ? "poolse-avatar--lg" : null,
892
+ className
893
+ ].filter(Boolean).join(" ");
894
+ return /* @__PURE__ */ jsxs("span", { className: classes, "aria-label": name ?? "avatar", role: "img", children: [
895
+ src ? /* @__PURE__ */ jsx("img", { src, alt: name ?? "" }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: initials }),
896
+ online ? /* @__PURE__ */ jsx("span", { className: "poolse-avatar__presence", "aria-hidden": "true" }) : null
897
+ ] });
898
+ }
899
+ function computeInitials(name) {
900
+ if (!name) return "?";
901
+ const parts = name.trim().split(/\s+/).slice(0, 2);
902
+ return parts.map((p) => p.charAt(0).toUpperCase()).join("").slice(0, 2) || "?";
903
+ }
891
904
  function AttachmentPreview({ attachment, onClick }) {
892
905
  const isFullRow = "content_type" in attachment;
893
906
  const { url, loading, error } = useAttachmentUrl(attachment.id);
@@ -1051,24 +1064,6 @@ function formatBytes(n) {
1051
1064
  if (n < 1024 * 1024 * 1024) return `${(n / (1024 * 1024)).toFixed(1)} MB`;
1052
1065
  return `${(n / (1024 * 1024 * 1024)).toFixed(2)} GB`;
1053
1066
  }
1054
- function Avatar({ src, name, online, size = "md", className }) {
1055
- const initials = computeInitials(name);
1056
- const classes = [
1057
- "poolse-avatar",
1058
- size === "sm" ? "poolse-avatar--sm" : null,
1059
- size === "lg" ? "poolse-avatar--lg" : null,
1060
- className
1061
- ].filter(Boolean).join(" ");
1062
- return /* @__PURE__ */ jsxs("span", { className: classes, "aria-label": name ?? "avatar", role: "img", children: [
1063
- src ? /* @__PURE__ */ jsx("img", { src, alt: name ?? "" }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: initials }),
1064
- online ? /* @__PURE__ */ jsx("span", { className: "poolse-avatar__presence", "aria-hidden": "true" }) : null
1065
- ] });
1066
- }
1067
- function computeInitials(name) {
1068
- if (!name) return "?";
1069
- const parts = name.trim().split(/\s+/).slice(0, 2);
1070
- return parts.map((p) => p.charAt(0).toUpperCase()).join("").slice(0, 2) || "?";
1071
- }
1072
1067
 
1073
1068
  // src/userColor.ts
1074
1069
  var PALETTE = [
@@ -1106,7 +1101,8 @@ function MessageBubble({
1106
1101
  maxBodyLength = 0,
1107
1102
  markdown = false,
1108
1103
  showSenderName = false,
1109
- actionsTrigger
1104
+ actionsTrigger,
1105
+ showAttachments = true
1110
1106
  }) {
1111
1107
  const isSelf = currentUserId !== null && message.sender_id === currentUserId;
1112
1108
  const [expanded, setExpanded] = useState(false);
@@ -1115,17 +1111,27 @@ function MessageBubble({
1115
1111
  const senderName = sender?.displayName ?? senderFallbackName;
1116
1112
  const senderColorHex = message.sender_id ? userColor(message.sender_id) : "currentColor";
1117
1113
  const renderSenderName = showSenderName && !isSelf && (groupPosition === "first" || groupPosition === "standalone");
1114
+ const rawBody = message.body ?? "";
1115
+ const TRIM_BUFFER = 40;
1116
+ const shouldTrim = !expanded && maxBodyLength > 0 && rawBody.length > maxBodyLength + TRIM_BUFFER;
1117
+ const displayBody = shouldTrim ? rawBody.slice(0, maxBodyLength).trimEnd() + "\u2026" : rawBody;
1118
+ const attachmentList = showAttachments && !message.deleted_at && Array.isArray(message.attachments) ? message.attachments : [];
1119
+ const imageAttachments = attachmentList.filter((a) => isImageContentType(a.content_type));
1120
+ const fileAttachments = attachmentList.filter((a) => !isImageContentType(a.content_type));
1121
+ const hasAnyAttachment = imageAttachments.length > 0 || fileAttachments.length > 0;
1122
+ const hasVisibleBody = !message.deleted_at && rawBody.length > 0;
1123
+ const metaOverlay = hasAnyAttachment && imageAttachments.length > 0 && !hasVisibleBody && fileAttachments.length === 0;
1118
1124
  const className = [
1119
1125
  "poolse-message",
1120
1126
  isSelf ? "poolse-message--self" : "poolse-message--other",
1121
1127
  // Group-position modifier — CSS uses it to toggle which corners
1122
1128
  // get the asymmetric tail vs. fully-rounded treatment.
1123
- `poolse-message--${groupPosition}`
1124
- ].join(" ");
1125
- const rawBody = message.body ?? "";
1126
- const TRIM_BUFFER = 40;
1127
- const shouldTrim = !expanded && maxBodyLength > 0 && rawBody.length > maxBodyLength + TRIM_BUFFER;
1128
- const displayBody = shouldTrim ? rawBody.slice(0, maxBodyLength).trimEnd() + "\u2026" : rawBody;
1129
+ `poolse-message--${groupPosition}`,
1130
+ // Tells the CSS to round the image mosaic's bottom corners to
1131
+ // match the bubble's outer corner when nothing follows the media.
1132
+ hasAnyAttachment ? "poolse-message--has-media" : "",
1133
+ metaOverlay ? "poolse-message--media-only" : ""
1134
+ ].filter(Boolean).join(" ");
1129
1135
  const time = message.inserted_at ? new Date(message.inserted_at).toLocaleTimeString(void 0, {
1130
1136
  hour: "2-digit",
1131
1137
  minute: "2-digit"
@@ -1144,7 +1150,9 @@ function MessageBubble({
1144
1150
  }
1145
1151
  ),
1146
1152
  showQuoteCard === "placeholder" && /* @__PURE__ */ jsx(QuotedPlaceholder, { isSelf, quotedMessageId: message.quoted_message_id }),
1147
- message.deleted_at ? /* @__PURE__ */ jsx("span", { className: "poolse-message__body--deleted", children: "[deleted]" }) : /* @__PURE__ */ jsxs("div", { className: "poolse-message__body", children: [
1153
+ imageAttachments.length > 0 && /* @__PURE__ */ jsx(ImageMosaic, { images: imageAttachments }),
1154
+ fileAttachments.length > 0 && /* @__PURE__ */ jsx("div", { className: "poolse-message__files", children: fileAttachments.map((att) => /* @__PURE__ */ jsx(AttachmentPreview, { attachment: att }, att.id)) }),
1155
+ message.deleted_at ? /* @__PURE__ */ jsx("span", { className: "poolse-message__body--deleted", children: "[deleted]" }) : hasVisibleBody ? /* @__PURE__ */ jsxs("div", { className: "poolse-message__body", children: [
1148
1156
  markdown ? /* @__PURE__ */ jsx(
1149
1157
  ReactMarkdown,
1150
1158
  {
@@ -1181,21 +1189,53 @@ function MessageBubble({
1181
1189
  children: "Show less"
1182
1190
  }
1183
1191
  )
1184
- ] }),
1185
- /* @__PURE__ */ jsxs("span", { className: "poolse-message__meta", children: [
1186
- /* @__PURE__ */ jsx("span", { children: time }),
1187
- message.edited_at ? /* @__PURE__ */ jsx("span", { children: " \xB7 edited" }) : null,
1188
- isSelf && readState ? /* @__PURE__ */ jsx(
1189
- PoolseIcon,
1190
- {
1191
- name: readState === "read" ? "check-double" : "check",
1192
- size: 14,
1193
- label: readState === "read" ? "Read" : "Sent"
1194
- }
1195
- ) : null
1196
- ] })
1192
+ ] }) : null,
1193
+ /* @__PURE__ */ jsxs(
1194
+ "span",
1195
+ {
1196
+ className: metaOverlay ? "poolse-message__meta poolse-message__meta--overlay" : "poolse-message__meta",
1197
+ children: [
1198
+ /* @__PURE__ */ jsx("span", { children: time }),
1199
+ message.edited_at ? /* @__PURE__ */ jsx("span", { children: " \xB7 edited" }) : null,
1200
+ isSelf && readState ? /* @__PURE__ */ jsx(
1201
+ PoolseIcon,
1202
+ {
1203
+ name: readState === "read" ? "check-double" : "check",
1204
+ size: 14,
1205
+ label: readState === "read" ? "Read" : "Sent"
1206
+ }
1207
+ ) : null
1208
+ ]
1209
+ }
1210
+ )
1197
1211
  ] });
1198
1212
  }
1213
+ function isImageContentType(ct) {
1214
+ return typeof ct === "string" && ct.toLowerCase().startsWith("image/");
1215
+ }
1216
+ function ImageMosaic({ images }) {
1217
+ const total = images.length;
1218
+ const visible = images.slice(0, 4);
1219
+ const layout = Math.min(total, 4);
1220
+ const overflow = Math.max(0, total - 4);
1221
+ return /* @__PURE__ */ jsx(
1222
+ "div",
1223
+ {
1224
+ className: `poolse-message__media poolse-message__media--n${layout}`,
1225
+ "aria-label": total === 1 ? "Image" : `${total} images`,
1226
+ children: visible.map((att, i) => {
1227
+ const isOverflowTile = i === visible.length - 1 && overflow > 0;
1228
+ return /* @__PURE__ */ jsxs("div", { className: "poolse-message__media-tile", children: [
1229
+ /* @__PURE__ */ jsx(AttachmentPreview, { attachment: att }),
1230
+ isOverflowTile && /* @__PURE__ */ jsxs("div", { className: "poolse-message__media-overflow", "aria-hidden": "true", children: [
1231
+ "+",
1232
+ overflow
1233
+ ] })
1234
+ ] }, att.id);
1235
+ })
1236
+ }
1237
+ );
1238
+ }
1199
1239
  function QuotedPlaceholder({
1200
1240
  isSelf,
1201
1241
  quotedMessageId: _quotedMessageId
@@ -1533,7 +1573,6 @@ function MessageRow({
1533
1573
  currentUserId: meId
1534
1574
  });
1535
1575
  const showReactions = reactions && !msg.deleted_at;
1536
- const showAttachments = attachments && Array.isArray(msg.attachments) && msg.attachments.length > 0;
1537
1576
  const showActions = actions && !msg.deleted_at && !editing;
1538
1577
  const replyCount = msg.reply_count ?? 0;
1539
1578
  const showThreadPill = threads && !msg.deleted_at && !msg.thread_root_id && replyCount > 0;
@@ -1603,6 +1642,7 @@ function MessageRow({
1603
1642
  maxBodyLength,
1604
1643
  markdown,
1605
1644
  showSenderName,
1645
+ showAttachments: attachments,
1606
1646
  ...readState ? { readState } : {},
1607
1647
  ...labelFor ? { labelFor } : {},
1608
1648
  ...onQuotedClick ? { onQuotedClick } : {},
@@ -1626,7 +1666,6 @@ function MessageRow({
1626
1666
  )
1627
1667
  }
1628
1668
  ),
1629
- showAttachments && /* @__PURE__ */ jsx("div", { className: `poolse-message-row__attachments ${isSelf ? "is-self" : ""}`, children: msg.attachments.map((att) => /* @__PURE__ */ jsx(AttachmentPreview, { attachment: att }, att.id)) }),
1630
1669
  showReactions && /* @__PURE__ */ jsx("div", { className: `poolse-message-row__reactions ${isSelf ? "is-self" : ""}`, children: /* @__PURE__ */ jsx(
1631
1670
  InlineReactions,
1632
1671
  {
@@ -1885,16 +1924,7 @@ function TypingIndicator({ typing, labelFor }) {
1885
1924
  /* @__PURE__ */ jsx("span", { className: "poolse-typing__dot" }),
1886
1925
  /* @__PURE__ */ jsx("span", { className: "poolse-typing__dot" })
1887
1926
  ] }),
1888
- /* @__PURE__ */ jsx(
1889
- "span",
1890
- {
1891
- className: "poolse-typing__label",
1892
- role: "status",
1893
- "aria-live": "polite",
1894
- "aria-atomic": "true",
1895
- children: isTyping ? /* @__PURE__ */ jsx(TypingLabel, { ids, ...labelFor ? { labelFor } : {} }) : ""
1896
- }
1897
- )
1927
+ /* @__PURE__ */ jsx("span", { className: "poolse-typing__label", role: "status", "aria-live": "polite", "aria-atomic": "true", children: isTyping ? /* @__PURE__ */ jsx(TypingLabel, { ids, ...labelFor ? { labelFor } : {} }) : "" })
1898
1928
  ] });
1899
1929
  }
1900
1930
  function TypingLabel({ ids, labelFor }) {
@@ -2374,9 +2404,7 @@ function MemberList({
2374
2404
  emptyState
2375
2405
  }) {
2376
2406
  const { members, loading, error, removeMember } = useMembers(conversationId);
2377
- const { online: presenceOnline } = usePresence(
2378
- onlineUserIds === void 0 ? conversationId : ""
2379
- );
2407
+ const { online: presenceOnline } = usePresence(onlineUserIds === void 0 ? conversationId : "");
2380
2408
  const effectiveOnline = onlineUserIds ?? presenceOnline;
2381
2409
  if (loading && members.length === 0) {
2382
2410
  return /* @__PURE__ */ jsx("div", { className: "poolse-list poolse-list--placeholder", children: "Loading members\u2026" });