@poolse/react-ui 1.0.6 → 2.0.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.js CHANGED
@@ -382,24 +382,24 @@ function UploadChip({
382
382
  }
383
383
  var MAX_NAME_CHARS = 24;
384
384
  function UserName({
385
- userId,
385
+ externalId,
386
386
  labelFor,
387
387
  emptyFallback = "Unknown",
388
388
  className
389
389
  }) {
390
- const { profile } = useUser(labelFor ? null : userId);
391
- const name = resolveDisplayName(userId, profile?.displayName, labelFor, emptyFallback);
390
+ const { profile } = useUser(labelFor ? null : externalId);
391
+ const name = resolveDisplayName(externalId, profile?.displayName, labelFor, emptyFallback);
392
392
  return /* @__PURE__ */ jsx("span", { className, children: truncate(name) });
393
393
  }
394
- function useDisplayName(userId, labelFor, emptyFallback = "Unknown") {
395
- const { profile } = useUser(labelFor ? null : userId);
396
- return resolveDisplayName(userId, profile?.displayName, labelFor, emptyFallback);
394
+ function useDisplayName(externalId, labelFor, emptyFallback = "Unknown") {
395
+ const { profile } = useUser(labelFor ? null : externalId);
396
+ return resolveDisplayName(externalId, profile?.displayName, labelFor, emptyFallback);
397
397
  }
398
- function resolveDisplayName(userId, resolved, labelFor, emptyFallback) {
399
- if (!userId) return emptyFallback;
400
- if (labelFor) return labelFor(userId);
398
+ function resolveDisplayName(externalId, resolved, labelFor, emptyFallback) {
399
+ if (!externalId) return emptyFallback;
400
+ if (labelFor) return labelFor(externalId);
401
401
  if (resolved) return resolved;
402
- return `User ${userId.slice(0, 6)}`;
402
+ return externalId;
403
403
  }
404
404
  function truncate(s) {
405
405
  if (s.length <= MAX_NAME_CHARS) return s;
@@ -451,8 +451,10 @@ var MentionInput = forwardRef(
451
451
  });
452
452
  };
453
453
  useImperativeHandle(ref, () => ({ addFiles }), [addFiles, attachments]);
454
- const label = labelFor ?? ((id) => id.slice(0, 8));
455
- const filtered = mention ? members.filter((m) => label(m.user_id).toLowerCase().includes(mention.query.toLowerCase())) : [];
454
+ const label = labelFor ?? ((id) => id);
455
+ const filtered = mention ? members.filter(
456
+ (m) => label(m.external_id).toLowerCase().includes(mention.query.toLowerCase())
457
+ ) : [];
456
458
  useEffect(() => {
457
459
  setActiveIdx(0);
458
460
  }, [filtered.length, mention?.query]);
@@ -479,7 +481,7 @@ var MentionInput = forwardRef(
479
481
  };
480
482
  const insertMention = (m) => {
481
483
  if (!mention) return;
482
- const name = label(m.user_id);
484
+ const name = label(m.external_id);
483
485
  const before = value.slice(0, mention.start);
484
486
  const after = value.slice(mention.start + 1 + mention.query.length);
485
487
  const inserted = `@${name} `;
@@ -561,7 +563,7 @@ var MentionInput = forwardRef(
561
563
  onCancelReply();
562
564
  }
563
565
  };
564
- const replyLabel = replyingTo?.sender_id ? labelFor?.(replyingTo.sender_id) ?? `User ${replyingTo.sender_id.slice(0, 6)}` : "Unknown";
566
+ const replyLabel = replyingTo?.sender_external_id ? labelFor?.(replyingTo.sender_external_id) ?? replyingTo.sender_external_id : "Unknown";
565
567
  const canSend = !disabled && !sending && !uploading && (value.trim() !== "" || readyCount > 0);
566
568
  return /* @__PURE__ */ jsxs(
567
569
  "form",
@@ -681,7 +683,7 @@ var MentionInput = forwardRef(
681
683
  },
682
684
  children: [
683
685
  /* @__PURE__ */ jsx("span", { children: "@" }),
684
- /* @__PURE__ */ jsx(UserName, { userId: m.user_id, ...labelFor ? { labelFor } : {} })
686
+ /* @__PURE__ */ jsx(UserName, { externalId: m.external_id, ...labelFor ? { labelFor } : {} })
685
687
  ]
686
688
  },
687
689
  m.id
@@ -709,17 +711,10 @@ var MessageComposer = forwardRef(
709
711
  const taRef = useRef(null);
710
712
  const fileInputRef = useRef(null);
711
713
  useAutogrow(taRef, value);
712
- const {
713
- queue,
714
- uploadAll,
715
- cancel: cancelUpload,
716
- remove: removeUpload
717
- } = useAttachmentUpload();
714
+ const { queue, uploadAll, cancel: cancelUpload, remove: removeUpload } = useAttachmentUpload();
718
715
  const visibleUploads = queue.filter((it) => it.status !== "cancelled");
719
716
  const readyCount = queue.filter((it) => it.status === "ready").length;
720
- const uploading = queue.some(
721
- (it) => it.status === "pending" || it.status === "uploading"
722
- );
717
+ const uploading = queue.some((it) => it.status === "pending" || it.status === "uploading");
723
718
  const addFiles = (files) => {
724
719
  if (!attachments || files.length === 0) return;
725
720
  void uploadAll(
@@ -867,7 +862,7 @@ function ReplyChip({
867
862
  labelFor,
868
863
  onCancel
869
864
  }) {
870
- const senderLabel = message.sender_id ? labelFor?.(message.sender_id) ?? `User ${message.sender_id.slice(0, 6)}` : "Unknown";
865
+ const senderLabel = message.sender_external_id ? labelFor?.(message.sender_external_id) ?? message.sender_external_id : "Unknown";
871
866
  const preview = message.body ?? "";
872
867
  return /* @__PURE__ */ jsxs("div", { className: "poolse-composer__reply", role: "status", children: [
873
868
  /* @__PURE__ */ jsxs("div", { className: "poolse-composer__reply-body", children: [
@@ -890,6 +885,24 @@ function ReplyChip({
890
885
  )
891
886
  ] });
892
887
  }
888
+ function Avatar({ src, name, online, size = "md", className }) {
889
+ const initials = computeInitials(name);
890
+ const classes = [
891
+ "poolse-avatar",
892
+ size === "sm" ? "poolse-avatar--sm" : null,
893
+ size === "lg" ? "poolse-avatar--lg" : null,
894
+ className
895
+ ].filter(Boolean).join(" ");
896
+ return /* @__PURE__ */ jsxs("span", { className: classes, "aria-label": name ?? "avatar", role: "img", children: [
897
+ src ? /* @__PURE__ */ jsx("img", { src, alt: name ?? "" }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: initials }),
898
+ online ? /* @__PURE__ */ jsx("span", { className: "poolse-avatar__presence", "aria-hidden": "true" }) : null
899
+ ] });
900
+ }
901
+ function computeInitials(name) {
902
+ if (!name) return "?";
903
+ const parts = name.trim().split(/\s+/).slice(0, 2);
904
+ return parts.map((p) => p.charAt(0).toUpperCase()).join("").slice(0, 2) || "?";
905
+ }
893
906
  function AttachmentPreview({ attachment, onClick }) {
894
907
  const isFullRow = "content_type" in attachment;
895
908
  const { url, loading, error } = useAttachmentUrl(attachment.id);
@@ -1053,24 +1066,6 @@ function formatBytes(n) {
1053
1066
  if (n < 1024 * 1024 * 1024) return `${(n / (1024 * 1024)).toFixed(1)} MB`;
1054
1067
  return `${(n / (1024 * 1024 * 1024)).toFixed(2)} GB`;
1055
1068
  }
1056
- function Avatar({ src, name, online, size = "md", className }) {
1057
- const initials = computeInitials(name);
1058
- const classes = [
1059
- "poolse-avatar",
1060
- size === "sm" ? "poolse-avatar--sm" : null,
1061
- size === "lg" ? "poolse-avatar--lg" : null,
1062
- className
1063
- ].filter(Boolean).join(" ");
1064
- return /* @__PURE__ */ jsxs("span", { className: classes, "aria-label": name ?? "avatar", role: "img", children: [
1065
- src ? /* @__PURE__ */ jsx("img", { src, alt: name ?? "" }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: initials }),
1066
- online ? /* @__PURE__ */ jsx("span", { className: "poolse-avatar__presence", "aria-hidden": "true" }) : null
1067
- ] });
1068
- }
1069
- function computeInitials(name) {
1070
- if (!name) return "?";
1071
- const parts = name.trim().split(/\s+/).slice(0, 2);
1072
- return parts.map((p) => p.charAt(0).toUpperCase()).join("").slice(0, 2) || "?";
1073
- }
1074
1069
 
1075
1070
  // src/userColor.ts
1076
1071
  var PALETTE = [
@@ -1108,26 +1103,38 @@ function MessageBubble({
1108
1103
  maxBodyLength = 0,
1109
1104
  markdown = false,
1110
1105
  showSenderName = false,
1111
- actionsTrigger
1106
+ actionsTrigger,
1107
+ showAttachments = true
1112
1108
  }) {
1113
1109
  const isSelf = currentUserId !== null && message.sender_id === currentUserId;
1114
1110
  const [expanded, setExpanded] = useState(false);
1115
- const { profile: sender } = useUser(!isSelf ? message.sender_id : null);
1116
- const senderFallbackName = message.sender_id ? `User ${message.sender_id.slice(0, 6)}` : "Unknown";
1111
+ const { profile: sender } = useUser(!isSelf ? message.sender_external_id : null);
1112
+ const senderFallbackName = message.sender_external_id ?? "Unknown";
1117
1113
  const senderName = sender?.displayName ?? senderFallbackName;
1118
- const senderColorHex = message.sender_id ? userColor(message.sender_id) : "currentColor";
1114
+ const senderColorKey = message.sender_external_id ?? message.sender_id ?? "";
1115
+ const senderColorHex = senderColorKey ? userColor(senderColorKey) : "currentColor";
1119
1116
  const renderSenderName = showSenderName && !isSelf && (groupPosition === "first" || groupPosition === "standalone");
1117
+ const rawBody = message.body ?? "";
1118
+ const TRIM_BUFFER = 40;
1119
+ const shouldTrim = !expanded && maxBodyLength > 0 && rawBody.length > maxBodyLength + TRIM_BUFFER;
1120
+ const displayBody = shouldTrim ? rawBody.slice(0, maxBodyLength).trimEnd() + "\u2026" : rawBody;
1121
+ const attachmentList = showAttachments && !message.deleted_at && Array.isArray(message.attachments) ? message.attachments : [];
1122
+ const imageAttachments = attachmentList.filter((a) => isImageContentType(a.content_type));
1123
+ const fileAttachments = attachmentList.filter((a) => !isImageContentType(a.content_type));
1124
+ const hasAnyAttachment = imageAttachments.length > 0 || fileAttachments.length > 0;
1125
+ const hasVisibleBody = !message.deleted_at && rawBody.length > 0;
1126
+ const metaOverlay = hasAnyAttachment && imageAttachments.length > 0 && !hasVisibleBody && fileAttachments.length === 0;
1120
1127
  const className = [
1121
1128
  "poolse-message",
1122
1129
  isSelf ? "poolse-message--self" : "poolse-message--other",
1123
1130
  // Group-position modifier — CSS uses it to toggle which corners
1124
1131
  // get the asymmetric tail vs. fully-rounded treatment.
1125
- `poolse-message--${groupPosition}`
1126
- ].join(" ");
1127
- const rawBody = message.body ?? "";
1128
- const TRIM_BUFFER = 40;
1129
- const shouldTrim = !expanded && maxBodyLength > 0 && rawBody.length > maxBodyLength + TRIM_BUFFER;
1130
- const displayBody = shouldTrim ? rawBody.slice(0, maxBodyLength).trimEnd() + "\u2026" : rawBody;
1132
+ `poolse-message--${groupPosition}`,
1133
+ // Tells the CSS to round the image mosaic's bottom corners to
1134
+ // match the bubble's outer corner when nothing follows the media.
1135
+ hasAnyAttachment ? "poolse-message--has-media" : "",
1136
+ metaOverlay ? "poolse-message--media-only" : ""
1137
+ ].filter(Boolean).join(" ");
1131
1138
  const time = message.inserted_at ? new Date(message.inserted_at).toLocaleTimeString(void 0, {
1132
1139
  hour: "2-digit",
1133
1140
  minute: "2-digit"
@@ -1146,7 +1153,9 @@ function MessageBubble({
1146
1153
  }
1147
1154
  ),
1148
1155
  showQuoteCard === "placeholder" && /* @__PURE__ */ jsx(QuotedPlaceholder, { isSelf, quotedMessageId: message.quoted_message_id }),
1149
- message.deleted_at ? /* @__PURE__ */ jsx("span", { className: "poolse-message__body--deleted", children: "[deleted]" }) : /* @__PURE__ */ jsxs("div", { className: "poolse-message__body", children: [
1156
+ imageAttachments.length > 0 && /* @__PURE__ */ jsx(ImageMosaic, { images: imageAttachments }),
1157
+ fileAttachments.length > 0 && /* @__PURE__ */ jsx("div", { className: "poolse-message__files", children: fileAttachments.map((att) => /* @__PURE__ */ jsx(AttachmentPreview, { attachment: att }, att.id)) }),
1158
+ message.deleted_at ? /* @__PURE__ */ jsx("span", { className: "poolse-message__body--deleted", children: "[deleted]" }) : hasVisibleBody ? /* @__PURE__ */ jsxs("div", { className: "poolse-message__body", children: [
1150
1159
  markdown ? /* @__PURE__ */ jsx(
1151
1160
  ReactMarkdown,
1152
1161
  {
@@ -1183,21 +1192,53 @@ function MessageBubble({
1183
1192
  children: "Show less"
1184
1193
  }
1185
1194
  )
1186
- ] }),
1187
- /* @__PURE__ */ jsxs("span", { className: "poolse-message__meta", children: [
1188
- /* @__PURE__ */ jsx("span", { children: time }),
1189
- message.edited_at ? /* @__PURE__ */ jsx("span", { children: " \xB7 edited" }) : null,
1190
- isSelf && readState ? /* @__PURE__ */ jsx(
1191
- PoolseIcon,
1192
- {
1193
- name: readState === "read" ? "check-double" : "check",
1194
- size: 14,
1195
- label: readState === "read" ? "Read" : "Sent"
1196
- }
1197
- ) : null
1198
- ] })
1195
+ ] }) : null,
1196
+ /* @__PURE__ */ jsxs(
1197
+ "span",
1198
+ {
1199
+ className: metaOverlay ? "poolse-message__meta poolse-message__meta--overlay" : "poolse-message__meta",
1200
+ children: [
1201
+ /* @__PURE__ */ jsx("span", { children: time }),
1202
+ message.edited_at ? /* @__PURE__ */ jsx("span", { children: " \xB7 edited" }) : null,
1203
+ isSelf && readState ? /* @__PURE__ */ jsx(
1204
+ PoolseIcon,
1205
+ {
1206
+ name: readState === "read" ? "check-double" : "check",
1207
+ size: 14,
1208
+ label: readState === "read" ? "Read" : "Sent"
1209
+ }
1210
+ ) : null
1211
+ ]
1212
+ }
1213
+ )
1199
1214
  ] });
1200
1215
  }
1216
+ function isImageContentType(ct) {
1217
+ return typeof ct === "string" && ct.toLowerCase().startsWith("image/");
1218
+ }
1219
+ function ImageMosaic({ images }) {
1220
+ const total = images.length;
1221
+ const visible = images.slice(0, 4);
1222
+ const layout = Math.min(total, 4);
1223
+ const overflow = Math.max(0, total - 4);
1224
+ return /* @__PURE__ */ jsx(
1225
+ "div",
1226
+ {
1227
+ className: `poolse-message__media poolse-message__media--n${layout}`,
1228
+ "aria-label": total === 1 ? "Image" : `${total} images`,
1229
+ children: visible.map((att, i) => {
1230
+ const isOverflowTile = i === visible.length - 1 && overflow > 0;
1231
+ return /* @__PURE__ */ jsxs("div", { className: "poolse-message__media-tile", children: [
1232
+ /* @__PURE__ */ jsx(AttachmentPreview, { attachment: att }),
1233
+ isOverflowTile && /* @__PURE__ */ jsxs("div", { className: "poolse-message__media-overflow", "aria-hidden": "true", children: [
1234
+ "+",
1235
+ overflow
1236
+ ] })
1237
+ ] }, att.id);
1238
+ })
1239
+ }
1240
+ );
1241
+ }
1201
1242
  function QuotedPlaceholder({
1202
1243
  isSelf,
1203
1244
  quotedMessageId: _quotedMessageId
@@ -1220,7 +1261,7 @@ function QuotedCard({
1220
1261
  labelFor,
1221
1262
  onClick
1222
1263
  }) {
1223
- const senderLabel = quoted.sender_id ? labelFor?.(quoted.sender_id) ?? `User ${quoted.sender_id.slice(0, 6)}` : "Unknown";
1264
+ const senderLabel = quoted.sender_external_id ? labelFor?.(quoted.sender_external_id) ?? quoted.sender_external_id : "Unknown";
1224
1265
  const isDeleted = !!quoted.deleted_at;
1225
1266
  const handleClick = onClick ? () => onClick(quoted.id) : void 0;
1226
1267
  return /* @__PURE__ */ jsxs(
@@ -1535,7 +1576,6 @@ function MessageRow({
1535
1576
  currentUserId: meId
1536
1577
  });
1537
1578
  const showReactions = reactions && !msg.deleted_at;
1538
- const showAttachments = attachments && Array.isArray(msg.attachments) && msg.attachments.length > 0;
1539
1579
  const showActions = actions && !msg.deleted_at && !editing;
1540
1580
  const replyCount = msg.reply_count ?? 0;
1541
1581
  const showThreadPill = threads && !msg.deleted_at && !msg.thread_root_id && replyCount > 0;
@@ -1605,6 +1645,7 @@ function MessageRow({
1605
1645
  maxBodyLength,
1606
1646
  markdown,
1607
1647
  showSenderName,
1648
+ showAttachments: attachments,
1608
1649
  ...readState ? { readState } : {},
1609
1650
  ...labelFor ? { labelFor } : {},
1610
1651
  ...onQuotedClick ? { onQuotedClick } : {},
@@ -1628,7 +1669,6 @@ function MessageRow({
1628
1669
  )
1629
1670
  }
1630
1671
  ),
1631
- showAttachments && /* @__PURE__ */ jsx("div", { className: `poolse-message-row__attachments ${isSelf ? "is-self" : ""}`, children: msg.attachments.map((att) => /* @__PURE__ */ jsx(AttachmentPreview, { attachment: att }, att.id)) }),
1632
1672
  showReactions && /* @__PURE__ */ jsx("div", { className: `poolse-message-row__reactions ${isSelf ? "is-self" : ""}`, children: /* @__PURE__ */ jsx(
1633
1673
  InlineReactions,
1634
1674
  {
@@ -1887,19 +1927,13 @@ function TypingIndicator({ typing, labelFor }) {
1887
1927
  /* @__PURE__ */ jsx("span", { className: "poolse-typing__dot" }),
1888
1928
  /* @__PURE__ */ jsx("span", { className: "poolse-typing__dot" })
1889
1929
  ] }),
1890
- /* @__PURE__ */ jsx(
1891
- "span",
1892
- {
1893
- className: "poolse-typing__label",
1894
- role: "status",
1895
- "aria-live": "polite",
1896
- "aria-atomic": "true",
1897
- children: isTyping ? /* @__PURE__ */ jsx(TypingLabel, { ids, ...labelFor ? { labelFor } : {} }) : ""
1898
- }
1899
- )
1930
+ /* @__PURE__ */ jsx("span", { className: "poolse-typing__label", role: "status", "aria-live": "polite", "aria-atomic": "true", children: isTyping ? /* @__PURE__ */ jsx(TypingLabel, { ids, ...labelFor ? { labelFor } : {} }) : "" })
1900
1931
  ] });
1901
1932
  }
1902
- function TypingLabel({ ids, labelFor }) {
1933
+ function TypingLabel({
1934
+ ids,
1935
+ labelFor
1936
+ }) {
1903
1937
  const id1 = ids[0] ?? null;
1904
1938
  const id2 = ids[1] ?? null;
1905
1939
  const name1 = useDisplayName(id1, labelFor);
@@ -2197,6 +2231,7 @@ function ConversationView({
2197
2231
  quoted_message: {
2198
2232
  id: original.id,
2199
2233
  sender_id: original.sender_id,
2234
+ sender_external_id: original.sender_external_id,
2200
2235
  body: original.body,
2201
2236
  deleted_at: original.deleted_at,
2202
2237
  inserted_at: original.inserted_at
@@ -2370,16 +2405,16 @@ function MemberList({
2370
2405
  conversationId,
2371
2406
  labelFor,
2372
2407
  avatarFor,
2373
- onlineUserIds,
2408
+ onlineExternalIds,
2374
2409
  canRemove,
2375
2410
  renderItem,
2376
2411
  emptyState
2377
2412
  }) {
2378
2413
  const { members, loading, error, removeMember } = useMembers(conversationId);
2379
2414
  const { online: presenceOnline } = usePresence(
2380
- onlineUserIds === void 0 ? conversationId : ""
2415
+ onlineExternalIds === void 0 ? conversationId : ""
2381
2416
  );
2382
- const effectiveOnline = onlineUserIds ?? presenceOnline;
2417
+ const effectiveOnline = onlineExternalIds ?? presenceOnline;
2383
2418
  if (loading && members.length === 0) {
2384
2419
  return /* @__PURE__ */ jsx("div", { className: "poolse-list poolse-list--placeholder", children: "Loading members\u2026" });
2385
2420
  }
@@ -2397,11 +2432,11 @@ function MemberList({
2397
2432
  DefaultMemberRow,
2398
2433
  {
2399
2434
  membership: m,
2400
- avatarUrl: avatarFor?.(m.user_id) ?? null,
2401
- online: effectiveOnline.has(m.user_id),
2435
+ avatarUrl: avatarFor?.(m.external_id) ?? null,
2436
+ online: effectiveOnline.has(m.external_id),
2402
2437
  removable: canRemove?.(m) ?? false,
2403
2438
  onRemove: () => {
2404
- void removeMember(m.user_id);
2439
+ void removeMember(m.external_id);
2405
2440
  },
2406
2441
  ...labelFor ? { labelFor } : {}
2407
2442
  }
@@ -2417,7 +2452,7 @@ function DefaultMemberRow({
2417
2452
  onRemove,
2418
2453
  labelFor
2419
2454
  }) {
2420
- const name = useDisplayName(membership.user_id, labelFor);
2455
+ const name = useDisplayName(membership.external_id, labelFor);
2421
2456
  return /* @__PURE__ */ jsxs("div", { className: "poolse-member-row", children: [
2422
2457
  /* @__PURE__ */ jsx(Avatar, { src: avatarUrl, name, online, size: "md" }),
2423
2458
  /* @__PURE__ */ jsxs("div", { className: "poolse-member-row__body", children: [