@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.cjs CHANGED
@@ -389,24 +389,24 @@ function UploadChip({
389
389
  }
390
390
  var MAX_NAME_CHARS = 24;
391
391
  function UserName({
392
- userId,
392
+ externalId,
393
393
  labelFor,
394
394
  emptyFallback = "Unknown",
395
395
  className
396
396
  }) {
397
- const { profile } = react$1.useUser(labelFor ? null : userId);
398
- const name = resolveDisplayName(userId, profile?.displayName, labelFor, emptyFallback);
397
+ const { profile } = react$1.useUser(labelFor ? null : externalId);
398
+ const name = resolveDisplayName(externalId, profile?.displayName, labelFor, emptyFallback);
399
399
  return /* @__PURE__ */ jsxRuntime.jsx("span", { className, children: truncate(name) });
400
400
  }
401
- function useDisplayName(userId, labelFor, emptyFallback = "Unknown") {
402
- const { profile } = react$1.useUser(labelFor ? null : userId);
403
- return resolveDisplayName(userId, profile?.displayName, labelFor, emptyFallback);
401
+ function useDisplayName(externalId, labelFor, emptyFallback = "Unknown") {
402
+ const { profile } = react$1.useUser(labelFor ? null : externalId);
403
+ return resolveDisplayName(externalId, profile?.displayName, labelFor, emptyFallback);
404
404
  }
405
- function resolveDisplayName(userId, resolved, labelFor, emptyFallback) {
406
- if (!userId) return emptyFallback;
407
- if (labelFor) return labelFor(userId);
405
+ function resolveDisplayName(externalId, resolved, labelFor, emptyFallback) {
406
+ if (!externalId) return emptyFallback;
407
+ if (labelFor) return labelFor(externalId);
408
408
  if (resolved) return resolved;
409
- return `User ${userId.slice(0, 6)}`;
409
+ return externalId;
410
410
  }
411
411
  function truncate(s) {
412
412
  if (s.length <= MAX_NAME_CHARS) return s;
@@ -458,8 +458,10 @@ var MentionInput = react.forwardRef(
458
458
  });
459
459
  };
460
460
  react.useImperativeHandle(ref, () => ({ addFiles }), [addFiles, attachments]);
461
- const label = labelFor ?? ((id) => id.slice(0, 8));
462
- const filtered = mention ? members.filter((m) => label(m.user_id).toLowerCase().includes(mention.query.toLowerCase())) : [];
461
+ const label = labelFor ?? ((id) => id);
462
+ const filtered = mention ? members.filter(
463
+ (m) => label(m.external_id).toLowerCase().includes(mention.query.toLowerCase())
464
+ ) : [];
463
465
  react.useEffect(() => {
464
466
  setActiveIdx(0);
465
467
  }, [filtered.length, mention?.query]);
@@ -486,7 +488,7 @@ var MentionInput = react.forwardRef(
486
488
  };
487
489
  const insertMention = (m) => {
488
490
  if (!mention) return;
489
- const name = label(m.user_id);
491
+ const name = label(m.external_id);
490
492
  const before = value.slice(0, mention.start);
491
493
  const after = value.slice(mention.start + 1 + mention.query.length);
492
494
  const inserted = `@${name} `;
@@ -568,7 +570,7 @@ var MentionInput = react.forwardRef(
568
570
  onCancelReply();
569
571
  }
570
572
  };
571
- const replyLabel = replyingTo?.sender_id ? labelFor?.(replyingTo.sender_id) ?? `User ${replyingTo.sender_id.slice(0, 6)}` : "Unknown";
573
+ const replyLabel = replyingTo?.sender_external_id ? labelFor?.(replyingTo.sender_external_id) ?? replyingTo.sender_external_id : "Unknown";
572
574
  const canSend = !disabled && !sending && !uploading && (value.trim() !== "" || readyCount > 0);
573
575
  return /* @__PURE__ */ jsxRuntime.jsxs(
574
576
  "form",
@@ -688,7 +690,7 @@ var MentionInput = react.forwardRef(
688
690
  },
689
691
  children: [
690
692
  /* @__PURE__ */ jsxRuntime.jsx("span", { children: "@" }),
691
- /* @__PURE__ */ jsxRuntime.jsx(UserName, { userId: m.user_id, ...labelFor ? { labelFor } : {} })
693
+ /* @__PURE__ */ jsxRuntime.jsx(UserName, { externalId: m.external_id, ...labelFor ? { labelFor } : {} })
692
694
  ]
693
695
  },
694
696
  m.id
@@ -716,17 +718,10 @@ var MessageComposer = react.forwardRef(
716
718
  const taRef = react.useRef(null);
717
719
  const fileInputRef = react.useRef(null);
718
720
  useAutogrow(taRef, value);
719
- const {
720
- queue,
721
- uploadAll,
722
- cancel: cancelUpload,
723
- remove: removeUpload
724
- } = react$1.useAttachmentUpload();
721
+ const { queue, uploadAll, cancel: cancelUpload, remove: removeUpload } = react$1.useAttachmentUpload();
725
722
  const visibleUploads = queue.filter((it) => it.status !== "cancelled");
726
723
  const readyCount = queue.filter((it) => it.status === "ready").length;
727
- const uploading = queue.some(
728
- (it) => it.status === "pending" || it.status === "uploading"
729
- );
724
+ const uploading = queue.some((it) => it.status === "pending" || it.status === "uploading");
730
725
  const addFiles = (files) => {
731
726
  if (!attachments || files.length === 0) return;
732
727
  void uploadAll(
@@ -874,7 +869,7 @@ function ReplyChip({
874
869
  labelFor,
875
870
  onCancel
876
871
  }) {
877
- const senderLabel = message.sender_id ? labelFor?.(message.sender_id) ?? `User ${message.sender_id.slice(0, 6)}` : "Unknown";
872
+ const senderLabel = message.sender_external_id ? labelFor?.(message.sender_external_id) ?? message.sender_external_id : "Unknown";
878
873
  const preview = message.body ?? "";
879
874
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-composer__reply", role: "status", children: [
880
875
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-composer__reply-body", children: [
@@ -897,6 +892,24 @@ function ReplyChip({
897
892
  )
898
893
  ] });
899
894
  }
895
+ function Avatar({ src, name, online, size = "md", className }) {
896
+ const initials = computeInitials(name);
897
+ const classes = [
898
+ "poolse-avatar",
899
+ size === "sm" ? "poolse-avatar--sm" : null,
900
+ size === "lg" ? "poolse-avatar--lg" : null,
901
+ className
902
+ ].filter(Boolean).join(" ");
903
+ return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: classes, "aria-label": name ?? "avatar", role: "img", children: [
904
+ src ? /* @__PURE__ */ jsxRuntime.jsx("img", { src, alt: name ?? "" }) : /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", children: initials }),
905
+ online ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-avatar__presence", "aria-hidden": "true" }) : null
906
+ ] });
907
+ }
908
+ function computeInitials(name) {
909
+ if (!name) return "?";
910
+ const parts = name.trim().split(/\s+/).slice(0, 2);
911
+ return parts.map((p) => p.charAt(0).toUpperCase()).join("").slice(0, 2) || "?";
912
+ }
900
913
  function AttachmentPreview({ attachment, onClick }) {
901
914
  const isFullRow = "content_type" in attachment;
902
915
  const { url, loading, error } = react$1.useAttachmentUrl(attachment.id);
@@ -1060,24 +1073,6 @@ function formatBytes(n) {
1060
1073
  if (n < 1024 * 1024 * 1024) return `${(n / (1024 * 1024)).toFixed(1)} MB`;
1061
1074
  return `${(n / (1024 * 1024 * 1024)).toFixed(2)} GB`;
1062
1075
  }
1063
- function Avatar({ src, name, online, size = "md", className }) {
1064
- const initials = computeInitials(name);
1065
- const classes = [
1066
- "poolse-avatar",
1067
- size === "sm" ? "poolse-avatar--sm" : null,
1068
- size === "lg" ? "poolse-avatar--lg" : null,
1069
- className
1070
- ].filter(Boolean).join(" ");
1071
- return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: classes, "aria-label": name ?? "avatar", role: "img", children: [
1072
- src ? /* @__PURE__ */ jsxRuntime.jsx("img", { src, alt: name ?? "" }) : /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", children: initials }),
1073
- online ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-avatar__presence", "aria-hidden": "true" }) : null
1074
- ] });
1075
- }
1076
- function computeInitials(name) {
1077
- if (!name) return "?";
1078
- const parts = name.trim().split(/\s+/).slice(0, 2);
1079
- return parts.map((p) => p.charAt(0).toUpperCase()).join("").slice(0, 2) || "?";
1080
- }
1081
1076
 
1082
1077
  // src/userColor.ts
1083
1078
  var PALETTE = [
@@ -1115,26 +1110,38 @@ function MessageBubble({
1115
1110
  maxBodyLength = 0,
1116
1111
  markdown = false,
1117
1112
  showSenderName = false,
1118
- actionsTrigger
1113
+ actionsTrigger,
1114
+ showAttachments = true
1119
1115
  }) {
1120
1116
  const isSelf = currentUserId !== null && message.sender_id === currentUserId;
1121
1117
  const [expanded, setExpanded] = react.useState(false);
1122
- const { profile: sender } = react$1.useUser(!isSelf ? message.sender_id : null);
1123
- const senderFallbackName = message.sender_id ? `User ${message.sender_id.slice(0, 6)}` : "Unknown";
1118
+ const { profile: sender } = react$1.useUser(!isSelf ? message.sender_external_id : null);
1119
+ const senderFallbackName = message.sender_external_id ?? "Unknown";
1124
1120
  const senderName = sender?.displayName ?? senderFallbackName;
1125
- const senderColorHex = message.sender_id ? userColor(message.sender_id) : "currentColor";
1121
+ const senderColorKey = message.sender_external_id ?? message.sender_id ?? "";
1122
+ const senderColorHex = senderColorKey ? userColor(senderColorKey) : "currentColor";
1126
1123
  const renderSenderName = showSenderName && !isSelf && (groupPosition === "first" || groupPosition === "standalone");
1124
+ const rawBody = message.body ?? "";
1125
+ const TRIM_BUFFER = 40;
1126
+ const shouldTrim = !expanded && maxBodyLength > 0 && rawBody.length > maxBodyLength + TRIM_BUFFER;
1127
+ const displayBody = shouldTrim ? rawBody.slice(0, maxBodyLength).trimEnd() + "\u2026" : rawBody;
1128
+ const attachmentList = showAttachments && !message.deleted_at && Array.isArray(message.attachments) ? message.attachments : [];
1129
+ const imageAttachments = attachmentList.filter((a) => isImageContentType(a.content_type));
1130
+ const fileAttachments = attachmentList.filter((a) => !isImageContentType(a.content_type));
1131
+ const hasAnyAttachment = imageAttachments.length > 0 || fileAttachments.length > 0;
1132
+ const hasVisibleBody = !message.deleted_at && rawBody.length > 0;
1133
+ const metaOverlay = hasAnyAttachment && imageAttachments.length > 0 && !hasVisibleBody && fileAttachments.length === 0;
1127
1134
  const className = [
1128
1135
  "poolse-message",
1129
1136
  isSelf ? "poolse-message--self" : "poolse-message--other",
1130
1137
  // Group-position modifier — CSS uses it to toggle which corners
1131
1138
  // get the asymmetric tail vs. fully-rounded treatment.
1132
- `poolse-message--${groupPosition}`
1133
- ].join(" ");
1134
- const rawBody = message.body ?? "";
1135
- const TRIM_BUFFER = 40;
1136
- const shouldTrim = !expanded && maxBodyLength > 0 && rawBody.length > maxBodyLength + TRIM_BUFFER;
1137
- const displayBody = shouldTrim ? rawBody.slice(0, maxBodyLength).trimEnd() + "\u2026" : rawBody;
1139
+ `poolse-message--${groupPosition}`,
1140
+ // Tells the CSS to round the image mosaic's bottom corners to
1141
+ // match the bubble's outer corner when nothing follows the media.
1142
+ hasAnyAttachment ? "poolse-message--has-media" : "",
1143
+ metaOverlay ? "poolse-message--media-only" : ""
1144
+ ].filter(Boolean).join(" ");
1138
1145
  const time = message.inserted_at ? new Date(message.inserted_at).toLocaleTimeString(void 0, {
1139
1146
  hour: "2-digit",
1140
1147
  minute: "2-digit"
@@ -1153,7 +1160,9 @@ function MessageBubble({
1153
1160
  }
1154
1161
  ),
1155
1162
  showQuoteCard === "placeholder" && /* @__PURE__ */ jsxRuntime.jsx(QuotedPlaceholder, { isSelf, quotedMessageId: message.quoted_message_id }),
1156
- message.deleted_at ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-message__body--deleted", children: "[deleted]" }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-message__body", children: [
1163
+ imageAttachments.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(ImageMosaic, { images: imageAttachments }),
1164
+ fileAttachments.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-message__files", children: fileAttachments.map((att) => /* @__PURE__ */ jsxRuntime.jsx(AttachmentPreview, { attachment: att }, att.id)) }),
1165
+ message.deleted_at ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-message__body--deleted", children: "[deleted]" }) : hasVisibleBody ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-message__body", children: [
1157
1166
  markdown ? /* @__PURE__ */ jsxRuntime.jsx(
1158
1167
  ReactMarkdown__default.default,
1159
1168
  {
@@ -1190,21 +1199,53 @@ function MessageBubble({
1190
1199
  children: "Show less"
1191
1200
  }
1192
1201
  )
1193
- ] }),
1194
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "poolse-message__meta", children: [
1195
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: time }),
1196
- message.edited_at ? /* @__PURE__ */ jsxRuntime.jsx("span", { children: " \xB7 edited" }) : null,
1197
- isSelf && readState ? /* @__PURE__ */ jsxRuntime.jsx(
1198
- PoolseIcon,
1199
- {
1200
- name: readState === "read" ? "check-double" : "check",
1201
- size: 14,
1202
- label: readState === "read" ? "Read" : "Sent"
1203
- }
1204
- ) : null
1205
- ] })
1202
+ ] }) : null,
1203
+ /* @__PURE__ */ jsxRuntime.jsxs(
1204
+ "span",
1205
+ {
1206
+ className: metaOverlay ? "poolse-message__meta poolse-message__meta--overlay" : "poolse-message__meta",
1207
+ children: [
1208
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: time }),
1209
+ message.edited_at ? /* @__PURE__ */ jsxRuntime.jsx("span", { children: " \xB7 edited" }) : null,
1210
+ isSelf && readState ? /* @__PURE__ */ jsxRuntime.jsx(
1211
+ PoolseIcon,
1212
+ {
1213
+ name: readState === "read" ? "check-double" : "check",
1214
+ size: 14,
1215
+ label: readState === "read" ? "Read" : "Sent"
1216
+ }
1217
+ ) : null
1218
+ ]
1219
+ }
1220
+ )
1206
1221
  ] });
1207
1222
  }
1223
+ function isImageContentType(ct) {
1224
+ return typeof ct === "string" && ct.toLowerCase().startsWith("image/");
1225
+ }
1226
+ function ImageMosaic({ images }) {
1227
+ const total = images.length;
1228
+ const visible = images.slice(0, 4);
1229
+ const layout = Math.min(total, 4);
1230
+ const overflow = Math.max(0, total - 4);
1231
+ return /* @__PURE__ */ jsxRuntime.jsx(
1232
+ "div",
1233
+ {
1234
+ className: `poolse-message__media poolse-message__media--n${layout}`,
1235
+ "aria-label": total === 1 ? "Image" : `${total} images`,
1236
+ children: visible.map((att, i) => {
1237
+ const isOverflowTile = i === visible.length - 1 && overflow > 0;
1238
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-message__media-tile", children: [
1239
+ /* @__PURE__ */ jsxRuntime.jsx(AttachmentPreview, { attachment: att }),
1240
+ isOverflowTile && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-message__media-overflow", "aria-hidden": "true", children: [
1241
+ "+",
1242
+ overflow
1243
+ ] })
1244
+ ] }, att.id);
1245
+ })
1246
+ }
1247
+ );
1248
+ }
1208
1249
  function QuotedPlaceholder({
1209
1250
  isSelf,
1210
1251
  quotedMessageId: _quotedMessageId
@@ -1227,7 +1268,7 @@ function QuotedCard({
1227
1268
  labelFor,
1228
1269
  onClick
1229
1270
  }) {
1230
- const senderLabel = quoted.sender_id ? labelFor?.(quoted.sender_id) ?? `User ${quoted.sender_id.slice(0, 6)}` : "Unknown";
1271
+ const senderLabel = quoted.sender_external_id ? labelFor?.(quoted.sender_external_id) ?? quoted.sender_external_id : "Unknown";
1231
1272
  const isDeleted = !!quoted.deleted_at;
1232
1273
  const handleClick = onClick ? () => onClick(quoted.id) : void 0;
1233
1274
  return /* @__PURE__ */ jsxRuntime.jsxs(
@@ -1542,7 +1583,6 @@ function MessageRow({
1542
1583
  currentUserId: meId
1543
1584
  });
1544
1585
  const showReactions = reactions && !msg.deleted_at;
1545
- const showAttachments = attachments && Array.isArray(msg.attachments) && msg.attachments.length > 0;
1546
1586
  const showActions = actions && !msg.deleted_at && !editing;
1547
1587
  const replyCount = msg.reply_count ?? 0;
1548
1588
  const showThreadPill = threads && !msg.deleted_at && !msg.thread_root_id && replyCount > 0;
@@ -1612,6 +1652,7 @@ function MessageRow({
1612
1652
  maxBodyLength,
1613
1653
  markdown,
1614
1654
  showSenderName,
1655
+ showAttachments: attachments,
1615
1656
  ...readState ? { readState } : {},
1616
1657
  ...labelFor ? { labelFor } : {},
1617
1658
  ...onQuotedClick ? { onQuotedClick } : {},
@@ -1635,7 +1676,6 @@ function MessageRow({
1635
1676
  )
1636
1677
  }
1637
1678
  ),
1638
- showAttachments && /* @__PURE__ */ jsxRuntime.jsx("div", { className: `poolse-message-row__attachments ${isSelf ? "is-self" : ""}`, children: msg.attachments.map((att) => /* @__PURE__ */ jsxRuntime.jsx(AttachmentPreview, { attachment: att }, att.id)) }),
1639
1679
  showReactions && /* @__PURE__ */ jsxRuntime.jsx("div", { className: `poolse-message-row__reactions ${isSelf ? "is-self" : ""}`, children: /* @__PURE__ */ jsxRuntime.jsx(
1640
1680
  InlineReactions,
1641
1681
  {
@@ -1894,19 +1934,13 @@ function TypingIndicator({ typing, labelFor }) {
1894
1934
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-typing__dot" }),
1895
1935
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-typing__dot" })
1896
1936
  ] }),
1897
- /* @__PURE__ */ jsxRuntime.jsx(
1898
- "span",
1899
- {
1900
- className: "poolse-typing__label",
1901
- role: "status",
1902
- "aria-live": "polite",
1903
- "aria-atomic": "true",
1904
- children: isTyping ? /* @__PURE__ */ jsxRuntime.jsx(TypingLabel, { ids, ...labelFor ? { labelFor } : {} }) : ""
1905
- }
1906
- )
1937
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-typing__label", role: "status", "aria-live": "polite", "aria-atomic": "true", children: isTyping ? /* @__PURE__ */ jsxRuntime.jsx(TypingLabel, { ids, ...labelFor ? { labelFor } : {} }) : "" })
1907
1938
  ] });
1908
1939
  }
1909
- function TypingLabel({ ids, labelFor }) {
1940
+ function TypingLabel({
1941
+ ids,
1942
+ labelFor
1943
+ }) {
1910
1944
  const id1 = ids[0] ?? null;
1911
1945
  const id2 = ids[1] ?? null;
1912
1946
  const name1 = useDisplayName(id1, labelFor);
@@ -2204,6 +2238,7 @@ function ConversationView({
2204
2238
  quoted_message: {
2205
2239
  id: original.id,
2206
2240
  sender_id: original.sender_id,
2241
+ sender_external_id: original.sender_external_id,
2207
2242
  body: original.body,
2208
2243
  deleted_at: original.deleted_at,
2209
2244
  inserted_at: original.inserted_at
@@ -2377,16 +2412,16 @@ function MemberList({
2377
2412
  conversationId,
2378
2413
  labelFor,
2379
2414
  avatarFor,
2380
- onlineUserIds,
2415
+ onlineExternalIds,
2381
2416
  canRemove,
2382
2417
  renderItem,
2383
2418
  emptyState
2384
2419
  }) {
2385
2420
  const { members, loading, error, removeMember } = react$1.useMembers(conversationId);
2386
2421
  const { online: presenceOnline } = react$1.usePresence(
2387
- onlineUserIds === void 0 ? conversationId : ""
2422
+ onlineExternalIds === void 0 ? conversationId : ""
2388
2423
  );
2389
- const effectiveOnline = onlineUserIds ?? presenceOnline;
2424
+ const effectiveOnline = onlineExternalIds ?? presenceOnline;
2390
2425
  if (loading && members.length === 0) {
2391
2426
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-list poolse-list--placeholder", children: "Loading members\u2026" });
2392
2427
  }
@@ -2404,11 +2439,11 @@ function MemberList({
2404
2439
  DefaultMemberRow,
2405
2440
  {
2406
2441
  membership: m,
2407
- avatarUrl: avatarFor?.(m.user_id) ?? null,
2408
- online: effectiveOnline.has(m.user_id),
2442
+ avatarUrl: avatarFor?.(m.external_id) ?? null,
2443
+ online: effectiveOnline.has(m.external_id),
2409
2444
  removable: canRemove?.(m) ?? false,
2410
2445
  onRemove: () => {
2411
- void removeMember(m.user_id);
2446
+ void removeMember(m.external_id);
2412
2447
  },
2413
2448
  ...labelFor ? { labelFor } : {}
2414
2449
  }
@@ -2424,7 +2459,7 @@ function DefaultMemberRow({
2424
2459
  onRemove,
2425
2460
  labelFor
2426
2461
  }) {
2427
- const name = useDisplayName(membership.user_id, labelFor);
2462
+ const name = useDisplayName(membership.external_id, labelFor);
2428
2463
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-member-row", children: [
2429
2464
  /* @__PURE__ */ jsxRuntime.jsx(Avatar, { src: avatarUrl, name, online, size: "md" }),
2430
2465
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-member-row__body", children: [