@poolse/react-ui 1.0.1-beta.0 → 1.0.2

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
@@ -49,6 +49,43 @@ function PoolseFonts() {
49
49
  return null;
50
50
  }
51
51
 
52
+ // src/grouping.ts
53
+ function computeGroupPosition(msg, prev, next, windowMs) {
54
+ const continuesPrev = sameGroup(msg, prev, windowMs);
55
+ const continuesNext = sameGroup(next, msg, windowMs);
56
+ if (continuesPrev && continuesNext) return "middle";
57
+ if (continuesPrev) return "last";
58
+ if (continuesNext) return "first";
59
+ return "standalone";
60
+ }
61
+ function sameGroup(a, b, windowMs) {
62
+ if (!a || !b) return false;
63
+ if (a.sender_id !== b.sender_id) return false;
64
+ if (!sameDay(a.inserted_at, b.inserted_at)) return false;
65
+ const ta = new Date(a.inserted_at).getTime();
66
+ const tb = new Date(b.inserted_at).getTime();
67
+ return Math.abs(ta - tb) <= windowMs;
68
+ }
69
+ function sameDay(a, b) {
70
+ const da = new Date(a);
71
+ const db = new Date(b);
72
+ return da.getFullYear() === db.getFullYear() && da.getMonth() === db.getMonth() && da.getDate() === db.getDate();
73
+ }
74
+ function formatDayLabel(iso, now = /* @__PURE__ */ new Date()) {
75
+ const d = new Date(iso);
76
+ const startOfDay = (x) => new Date(x.getFullYear(), x.getMonth(), x.getDate()).getTime();
77
+ const diffDays = Math.floor((startOfDay(now) - startOfDay(d)) / 864e5);
78
+ if (diffDays === 0) return "Today";
79
+ if (diffDays === 1) return "Yesterday";
80
+ if (diffDays < 7) {
81
+ return d.toLocaleDateString(void 0, { weekday: "long" });
82
+ }
83
+ if (d.getFullYear() === now.getFullYear()) {
84
+ return d.toLocaleDateString(void 0, { weekday: "short", day: "numeric", month: "short" });
85
+ }
86
+ return d.toLocaleDateString(void 0, { day: "numeric", month: "short", year: "numeric" });
87
+ }
88
+
52
89
  // src/listAutocomplete.ts
53
90
  var UNORDERED_RE = /^(\s*)([-*+]) (.*)$/;
54
91
  var ORDERED_RE = /^(\s*)(\d+)\. (.*)$/;
@@ -287,6 +324,31 @@ function PoolseIcon({
287
324
  }
288
325
  );
289
326
  }
327
+ var MAX_NAME_CHARS = 24;
328
+ function UserName({
329
+ userId,
330
+ labelFor,
331
+ emptyFallback = "Unknown",
332
+ className
333
+ }) {
334
+ const { profile } = react$1.useUser(labelFor ? null : userId);
335
+ const name = resolveDisplayName(userId, profile?.displayName, labelFor, emptyFallback);
336
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { className, children: truncate(name) });
337
+ }
338
+ function useDisplayName(userId, labelFor, emptyFallback = "Unknown") {
339
+ const { profile } = react$1.useUser(labelFor ? null : userId);
340
+ return resolveDisplayName(userId, profile?.displayName, labelFor, emptyFallback);
341
+ }
342
+ function resolveDisplayName(userId, resolved, labelFor, emptyFallback) {
343
+ if (!userId) return emptyFallback;
344
+ if (labelFor) return labelFor(userId);
345
+ if (resolved) return resolved;
346
+ return `User ${userId.slice(0, 6)}`;
347
+ }
348
+ function truncate(s) {
349
+ if (s.length <= MAX_NAME_CHARS) return s;
350
+ return s.slice(0, MAX_NAME_CHARS - 1) + "\u2026";
351
+ }
290
352
  function MentionInput({
291
353
  conversationId,
292
354
  onSend,
@@ -452,7 +514,13 @@ function MentionInput({
452
514
  onChange,
453
515
  onKeyDown,
454
516
  placeholder,
455
- disabled: disabled || sending
517
+ disabled: disabled || sending,
518
+ "aria-label": placeholder,
519
+ role: "combobox",
520
+ "aria-expanded": Boolean(mention && filtered.length > 0),
521
+ "aria-controls": "poolse-mention-menu",
522
+ "aria-autocomplete": "list",
523
+ ...mention && filtered.length > 0 ? { "aria-activedescendant": `poolse-mention-opt-${activeIdx}` } : {}
456
524
  }
457
525
  ),
458
526
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -466,23 +534,33 @@ function MentionInput({
466
534
  }
467
535
  )
468
536
  ] }),
469
- mention && filtered.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-mention-menu", role: "listbox", "aria-label": "Members", children: filtered.map((m, i) => /* @__PURE__ */ jsxRuntime.jsx(
537
+ mention && filtered.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(
470
538
  "div",
471
539
  {
472
- role: "option",
473
- "aria-selected": i === activeIdx,
474
- className: `poolse-mention-menu__item${i === activeIdx ? " poolse-mention-menu__item--active" : ""}`,
475
- onMouseDown: (e) => {
476
- e.preventDefault();
477
- insertMention(m);
478
- },
479
- children: /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
480
- "@",
481
- label(m.user_id)
482
- ] })
483
- },
484
- m.id
485
- )) })
540
+ id: "poolse-mention-menu",
541
+ className: "poolse-mention-menu",
542
+ role: "listbox",
543
+ "aria-label": "Members",
544
+ children: filtered.map((m, i) => /* @__PURE__ */ jsxRuntime.jsxs(
545
+ "div",
546
+ {
547
+ id: `poolse-mention-opt-${i}`,
548
+ role: "option",
549
+ "aria-selected": i === activeIdx,
550
+ className: `poolse-mention-menu__item${i === activeIdx ? " poolse-mention-menu__item--active" : ""}`,
551
+ onMouseDown: (e) => {
552
+ e.preventDefault();
553
+ insertMention(m);
554
+ },
555
+ children: [
556
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: "@" }),
557
+ /* @__PURE__ */ jsxRuntime.jsx(UserName, { userId: m.user_id, ...labelFor ? { labelFor } : {} })
558
+ ]
559
+ },
560
+ m.id
561
+ ))
562
+ }
563
+ )
486
564
  ]
487
565
  }
488
566
  );
@@ -563,7 +641,8 @@ function MessageComposer({
563
641
  onChange,
564
642
  onKeyDown,
565
643
  placeholder,
566
- disabled: disabled || sending
644
+ disabled: disabled || sending,
645
+ "aria-label": placeholder
567
646
  }
568
647
  ),
569
648
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -612,6 +691,7 @@ function ReplyChip({
612
691
  function AttachmentPreview({ attachment, onClick }) {
613
692
  const isFullRow = "content_type" in attachment;
614
693
  const { url, loading, error } = react$1.useAttachmentUrl(attachment.id);
694
+ const [lightboxOpen, setLightboxOpen] = react.useState(false);
615
695
  if (loading) {
616
696
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-attachment poolse-list--placeholder", "aria-busy": "true", children: "Loading attachment\u2026" });
617
697
  }
@@ -622,29 +702,33 @@ function AttachmentPreview({ attachment, onClick }) {
622
702
  const isImage = ct.startsWith("image/");
623
703
  if (isImage) {
624
704
  const filename2 = isFullRow ? attachment.original_filename : null;
625
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-attachment", children: /* @__PURE__ */ jsxRuntime.jsx(
626
- "a",
627
- {
628
- href: url,
629
- target: "_blank",
630
- rel: "noopener noreferrer",
631
- onClick: (e) => {
632
- if (onClick) {
633
- e.preventDefault();
634
- onClick({ id: attachment.id });
635
- }
636
- },
637
- children: /* @__PURE__ */ jsxRuntime.jsx(
638
- "img",
639
- {
640
- className: "poolse-attachment__image",
641
- src: url,
642
- alt: filename2 ?? "attachment",
643
- loading: "lazy"
644
- }
645
- )
646
- }
647
- ) });
705
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-attachment", children: [
706
+ /* @__PURE__ */ jsxRuntime.jsx(
707
+ "button",
708
+ {
709
+ type: "button",
710
+ className: "poolse-attachment__image-button",
711
+ "aria-label": filename2 ? `Open ${filename2}` : "Open image",
712
+ onClick: () => {
713
+ if (onClick) {
714
+ onClick({ id: attachment.id });
715
+ return;
716
+ }
717
+ setLightboxOpen(true);
718
+ },
719
+ children: /* @__PURE__ */ jsxRuntime.jsx(
720
+ "img",
721
+ {
722
+ className: "poolse-attachment__image",
723
+ src: url,
724
+ alt: filename2 ?? "attachment",
725
+ loading: "lazy"
726
+ }
727
+ )
728
+ }
729
+ ),
730
+ lightboxOpen && /* @__PURE__ */ jsxRuntime.jsx(Lightbox, { url, filename: filename2, onClose: () => setLightboxOpen(false) })
731
+ ] });
648
732
  }
649
733
  const filename = isFullRow ? attachment.original_filename ?? "file" : "file";
650
734
  const byteSize = isFullRow ? attachment.byte_size : null;
@@ -689,6 +773,70 @@ function AttachmentPreview({ attachment, onClick }) {
689
773
  }
690
774
  ) });
691
775
  }
776
+ function Lightbox({
777
+ url,
778
+ filename,
779
+ onClose
780
+ }) {
781
+ react.useEffect(() => {
782
+ const onKey = (e) => {
783
+ if (e.key === "Escape") onClose();
784
+ };
785
+ document.addEventListener("keydown", onKey);
786
+ const prev = document.body.style.overflow;
787
+ document.body.style.overflow = "hidden";
788
+ return () => {
789
+ document.removeEventListener("keydown", onKey);
790
+ document.body.style.overflow = prev;
791
+ };
792
+ }, [onClose]);
793
+ return /* @__PURE__ */ jsxRuntime.jsxs(
794
+ "div",
795
+ {
796
+ className: "poolse-lightbox",
797
+ role: "dialog",
798
+ "aria-modal": "true",
799
+ "aria-label": filename ?? "Image preview",
800
+ onClick: onClose,
801
+ children: [
802
+ /* @__PURE__ */ jsxRuntime.jsx(
803
+ "button",
804
+ {
805
+ type: "button",
806
+ className: "poolse-lightbox__close",
807
+ "aria-label": "Close",
808
+ onClick: (e) => {
809
+ e.stopPropagation();
810
+ onClose();
811
+ },
812
+ children: "\xD7"
813
+ }
814
+ ),
815
+ /* @__PURE__ */ jsxRuntime.jsx(
816
+ "img",
817
+ {
818
+ className: "poolse-lightbox__image",
819
+ src: url,
820
+ alt: filename ?? "attachment",
821
+ onClick: (e) => e.stopPropagation()
822
+ }
823
+ ),
824
+ /* @__PURE__ */ jsxRuntime.jsx(
825
+ "a",
826
+ {
827
+ className: "poolse-lightbox__download",
828
+ href: url,
829
+ download: filename ?? void 0,
830
+ target: "_blank",
831
+ rel: "noopener noreferrer",
832
+ onClick: (e) => e.stopPropagation(),
833
+ children: "Download"
834
+ }
835
+ )
836
+ ]
837
+ }
838
+ );
839
+ }
692
840
  function guessContentType(url) {
693
841
  const m = url.match(/\.([a-z0-9]+)(?:\?|#|$)/i);
694
842
  if (!m) return "application/octet-stream";
@@ -1039,19 +1187,53 @@ function ReactionPicker({
1039
1187
  onPick,
1040
1188
  onClose
1041
1189
  }) {
1190
+ const rootRef = react.useRef(null);
1191
+ react.useEffect(() => {
1192
+ const firstBtn = rootRef.current?.querySelector("button");
1193
+ if (firstBtn instanceof HTMLElement) firstBtn.focus();
1194
+ }, []);
1195
+ react.useEffect(() => {
1196
+ if (!onClose) return;
1197
+ const onPointer = (e) => {
1198
+ const t = e.target;
1199
+ if (t instanceof Node && rootRef.current && !rootRef.current.contains(t)) {
1200
+ onClose();
1201
+ }
1202
+ };
1203
+ document.addEventListener("pointerdown", onPointer, true);
1204
+ return () => document.removeEventListener("pointerdown", onPointer, true);
1205
+ }, [onClose]);
1206
+ const onKey = (e) => {
1207
+ if (e.key === "Escape") {
1208
+ e.stopPropagation();
1209
+ onClose?.();
1210
+ return;
1211
+ }
1212
+ if (e.key === "ArrowRight" || e.key === "ArrowLeft") {
1213
+ const buttons = Array.from(
1214
+ rootRef.current?.querySelectorAll("button") ?? []
1215
+ );
1216
+ const idx = buttons.findIndex((b) => b === document.activeElement);
1217
+ if (idx === -1) return;
1218
+ const nextIdx = e.key === "ArrowRight" ? (idx + 1) % buttons.length : (idx - 1 + buttons.length) % buttons.length;
1219
+ buttons[nextIdx]?.focus();
1220
+ e.preventDefault();
1221
+ }
1222
+ };
1042
1223
  return /* @__PURE__ */ jsxRuntime.jsx(
1043
1224
  "div",
1044
1225
  {
1226
+ ref: rootRef,
1045
1227
  className: "poolse-reaction-picker",
1046
1228
  role: "menu",
1229
+ "aria-label": "Pick a reaction",
1047
1230
  style: { position: "absolute", bottom: "100%", left: 0, marginBottom: 6 },
1048
- onKeyDown: (e) => {
1049
- if (e.key === "Escape") onClose?.();
1050
- },
1231
+ onKeyDown: onKey,
1051
1232
  children: COMMON_EMOJIS.map((e) => /* @__PURE__ */ jsxRuntime.jsx(
1052
1233
  "button",
1053
1234
  {
1054
1235
  type: "button",
1236
+ role: "menuitem",
1055
1237
  className: "poolse-reaction-picker__btn",
1056
1238
  onClick: () => onPick(e),
1057
1239
  "aria-label": `React with ${e}`,
@@ -1156,9 +1338,29 @@ function MessageRow({
1156
1338
  const showThreadPill = threads && !msg.deleted_at && !msg.thread_root_id && replyCount > 0;
1157
1339
  const handleSave = onSaveEdit ?? (async () => void 0);
1158
1340
  const handleCancel = onCancelEdit ?? (() => void 0);
1341
+ const [actionsOpen, setActionsOpen] = react.useState(false);
1342
+ const rowRef = react.useRef(null);
1343
+ react.useEffect(() => {
1344
+ if (!actionsOpen) return;
1345
+ const onDown = (e) => {
1346
+ const t = e.target;
1347
+ if (t instanceof Node && rowRef.current && !rowRef.current.contains(t)) {
1348
+ setActionsOpen(false);
1349
+ }
1350
+ };
1351
+ document.addEventListener("pointerdown", onDown);
1352
+ return () => document.removeEventListener("pointerdown", onDown);
1353
+ }, [actionsOpen]);
1354
+ const onRowClick = (e) => {
1355
+ if (typeof window === "undefined" || !window.matchMedia("(hover: none)").matches) return;
1356
+ const target = e.target;
1357
+ if (target.closest("a, button, input, textarea, label, select")) return;
1358
+ setActionsOpen((o) => !o);
1359
+ };
1159
1360
  return /* @__PURE__ */ jsxRuntime.jsxs(
1160
1361
  "div",
1161
1362
  {
1363
+ ref: rowRef,
1162
1364
  className: [
1163
1365
  "poolse-message-row",
1164
1366
  isSelf ? "poolse-message-row--right" : "",
@@ -1169,6 +1371,8 @@ function MessageRow({
1169
1371
  `poolse-message-row--${groupPosition}`
1170
1372
  ].filter(Boolean).join(" "),
1171
1373
  "data-message-id": msg.id,
1374
+ "data-actions-open": actionsOpen || void 0,
1375
+ onClick: onRowClick,
1172
1376
  children: [
1173
1377
  editing ? /* @__PURE__ */ jsxRuntime.jsx(
1174
1378
  EditableMessageBubble,
@@ -1317,6 +1521,7 @@ function ThreadView({
1317
1521
  rootMessage.id
1318
1522
  );
1319
1523
  const listRef = react.useRef(null);
1524
+ const closeBtnRef = react.useRef(null);
1320
1525
  const lastReplyIdRef = react.useRef(null);
1321
1526
  react.useEffect(() => {
1322
1527
  const tail = replies[replies.length - 1];
@@ -1326,60 +1531,158 @@ function ThreadView({
1326
1531
  const el = listRef.current;
1327
1532
  if (el) el.scrollTop = el.scrollHeight;
1328
1533
  }, [replies]);
1534
+ react.useEffect(() => {
1535
+ closeBtnRef.current?.focus();
1536
+ if (!onClose) return;
1537
+ const onKey = (e) => {
1538
+ if (e.key === "Escape") onClose();
1539
+ };
1540
+ document.addEventListener("keydown", onKey);
1541
+ return () => document.removeEventListener("keydown", onKey);
1542
+ }, [onClose]);
1329
1543
  const renderOne = renderMessage ?? defaultRenderReply;
1330
- return /* @__PURE__ */ jsxRuntime.jsxs("aside", { className: "poolse-thread", "aria-label": "Thread", children: [
1331
- /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "poolse-thread__header", children: [
1332
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-thread__title", children: "Thread" }),
1333
- onClose && /* @__PURE__ */ jsxRuntime.jsx(
1334
- "button",
1335
- {
1336
- type: "button",
1337
- className: "poolse-icon-btn",
1338
- onClick: onClose,
1339
- "aria-label": "Close thread",
1340
- children: /* @__PURE__ */ jsxRuntime.jsx(PoolseIcon, { name: "close", size: 18, label: null })
1341
- }
1342
- )
1343
- ] }),
1344
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-thread__root", children: /* @__PURE__ */ jsxRuntime.jsx(MessageBubble, { message: rootMessage, currentUserId: me?.id ?? null }) }),
1345
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-thread__messages", ref: listRef, children: [
1346
- hasMore && !loading && replies.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "poolse-conversation__load-more", onClick: loadMore, children: "Load older replies" }),
1347
- loading && replies.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation__empty", children: "Loading replies\u2026" }) : replies.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation__empty", children: "No replies yet \u2014 start the thread." }) : (
1348
- // Same Fragment trick as ConversationView so MessageBubble
1349
- // remains the direct flex child for align-self to work.
1350
- replies.map((msg) => /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: renderOne(msg, me?.id ?? null) }, msg.id))
1351
- ),
1352
- error && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-conversation__empty", children: [
1353
- "Failed to load: ",
1354
- error.message
1355
- ] })
1356
- ] }),
1357
- /* @__PURE__ */ jsxRuntime.jsx(MessageComposer, { onSend: (body) => sendReply({ body }), placeholder: "Reply in thread\u2026" })
1358
- ] });
1544
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1545
+ "aside",
1546
+ {
1547
+ className: "poolse-thread",
1548
+ role: "complementary",
1549
+ "aria-label": "Message thread",
1550
+ children: [
1551
+ /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "poolse-thread__header", children: [
1552
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-thread__title", children: "Thread" }),
1553
+ onClose && /* @__PURE__ */ jsxRuntime.jsx(
1554
+ "button",
1555
+ {
1556
+ ref: closeBtnRef,
1557
+ type: "button",
1558
+ className: "poolse-icon-btn",
1559
+ onClick: onClose,
1560
+ "aria-label": "Close thread",
1561
+ children: /* @__PURE__ */ jsxRuntime.jsx(PoolseIcon, { name: "close", size: 18, label: null })
1562
+ }
1563
+ )
1564
+ ] }),
1565
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-thread__root", children: /* @__PURE__ */ jsxRuntime.jsx(MessageBubble, { message: rootMessage, currentUserId: me?.id ?? null }) }),
1566
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-thread__messages", ref: listRef, children: [
1567
+ hasMore && !loading && replies.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "poolse-conversation__load-more", onClick: loadMore, children: "Load older replies" }),
1568
+ loading && replies.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation__empty", children: "Loading replies\u2026" }) : replies.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation__empty", children: "No replies yet \u2014 start the thread." }) : (
1569
+ // Same Fragment trick as ConversationView so MessageBubble
1570
+ // remains the direct flex child for align-self to work.
1571
+ replies.map((msg) => /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: renderOne(msg, me?.id ?? null) }, msg.id))
1572
+ ),
1573
+ error && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-conversation__empty", children: [
1574
+ "Failed to load: ",
1575
+ error.message
1576
+ ] })
1577
+ ] }),
1578
+ /* @__PURE__ */ jsxRuntime.jsx(MessageComposer, { onSend: (body) => sendReply({ body }), placeholder: "Reply in thread\u2026" })
1579
+ ]
1580
+ }
1581
+ );
1359
1582
  }
1360
1583
  function defaultRenderReply(msg, currentUserId) {
1361
1584
  return /* @__PURE__ */ jsxRuntime.jsx(MessageBubble, { message: msg, currentUserId });
1362
1585
  }
1363
1586
  function TypingIndicator({ typing, labelFor }) {
1364
1587
  const ids = Array.from(typing);
1365
- if (ids.length === 0) {
1366
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-typing", "aria-hidden": "true" });
1367
- }
1368
- const label = labelFor ?? ((id) => id.slice(0, 6));
1369
- const names = ids.slice(0, 2).map(label);
1370
- let text;
1371
- if (ids.length === 1) text = `${names[0]} is typing`;
1372
- else if (ids.length === 2) text = `${names[0]} and ${names[1]} are typing`;
1373
- else text = `${ids.length} people are typing`;
1374
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-typing", children: [
1375
- /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "poolse-typing__dots", role: "status", "aria-live": "polite", children: [
1588
+ const isTyping = ids.length > 0;
1589
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-typing", "data-typing": isTyping || void 0, children: [
1590
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "poolse-typing__dots", "aria-hidden": "true", children: [
1376
1591
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-typing__dot" }),
1377
1592
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-typing__dot" }),
1378
1593
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-typing__dot" })
1379
1594
  ] }),
1380
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-typing__label", children: text })
1595
+ /* @__PURE__ */ jsxRuntime.jsx(
1596
+ "span",
1597
+ {
1598
+ className: "poolse-typing__label",
1599
+ role: "status",
1600
+ "aria-live": "polite",
1601
+ "aria-atomic": "true",
1602
+ children: isTyping ? /* @__PURE__ */ jsxRuntime.jsx(TypingLabel, { ids, ...labelFor ? { labelFor } : {} }) : ""
1603
+ }
1604
+ )
1381
1605
  ] });
1382
1606
  }
1607
+ function TypingLabel({ ids, labelFor }) {
1608
+ const id1 = ids[0] ?? null;
1609
+ const id2 = ids[1] ?? null;
1610
+ const name1 = useDisplayName(id1, labelFor);
1611
+ const name2 = useDisplayName(id2, labelFor);
1612
+ if (ids.length === 1) return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1613
+ name1,
1614
+ " is typing"
1615
+ ] });
1616
+ if (ids.length === 2) {
1617
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1618
+ name1,
1619
+ " and ",
1620
+ name2,
1621
+ " are typing"
1622
+ ] });
1623
+ }
1624
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1625
+ ids.length,
1626
+ " people are typing"
1627
+ ] });
1628
+ }
1629
+ function UploadQueueStrip({ items, onCancel, onDismiss }) {
1630
+ if (items.length === 0) return null;
1631
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-upload-strip", role: "status", "aria-live": "polite", children: items.map((item) => /* @__PURE__ */ jsxRuntime.jsx(
1632
+ UploadChip,
1633
+ {
1634
+ item,
1635
+ onCancel: () => onCancel(item.localId),
1636
+ onDismiss: () => onDismiss(item.localId)
1637
+ },
1638
+ item.localId
1639
+ )) });
1640
+ }
1641
+ function UploadChip({
1642
+ item,
1643
+ onCancel,
1644
+ onDismiss
1645
+ }) {
1646
+ const pct = item.byteSize > 0 ? Math.min(100, Math.round(item.loaded / item.byteSize * 100)) : 0;
1647
+ const isError = item.status === "error";
1648
+ const isInFlight = item.status === "pending" || item.status === "uploading";
1649
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1650
+ "div",
1651
+ {
1652
+ className: `poolse-upload-chip poolse-upload-chip--${item.status}`,
1653
+ "data-status": item.status,
1654
+ children: [
1655
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-upload-chip__icon", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx(PoolseIcon, { name: isError ? "attachment" : "attachment", size: 18, label: null }) }),
1656
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-upload-chip__body", children: [
1657
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-upload-chip__filename", title: item.filename, children: item.filename }),
1658
+ isError ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-upload-chip__error", children: item.error?.message ?? "Upload failed" }) : /* @__PURE__ */ jsxRuntime.jsx(
1659
+ "div",
1660
+ {
1661
+ className: "poolse-upload-chip__bar",
1662
+ role: "progressbar",
1663
+ "aria-valuemin": 0,
1664
+ "aria-valuemax": 100,
1665
+ "aria-valuenow": pct,
1666
+ "aria-label": `Uploading ${item.filename}`,
1667
+ children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-upload-chip__bar-fill", style: { width: `${pct}%` } })
1668
+ }
1669
+ )
1670
+ ] }),
1671
+ /* @__PURE__ */ jsxRuntime.jsx(
1672
+ "button",
1673
+ {
1674
+ type: "button",
1675
+ className: "poolse-upload-chip__action",
1676
+ onClick: isInFlight ? onCancel : onDismiss,
1677
+ "aria-label": isInFlight ? `Cancel upload of ${item.filename}` : `Dismiss ${item.filename}`,
1678
+ title: isInFlight ? "Cancel" : "Dismiss",
1679
+ children: "\xD7"
1680
+ }
1681
+ )
1682
+ ]
1683
+ }
1684
+ );
1685
+ }
1383
1686
  var TRUE = true;
1384
1687
  function ConversationView({
1385
1688
  conversationId,
@@ -1427,8 +1730,32 @@ function ConversationView({
1427
1730
  const listRef = react.useRef(null);
1428
1731
  const lastMessageIdRef = react.useRef(null);
1429
1732
  const bottomSentinelRef = react.useRef(null);
1733
+ const topSentinelRef = react.useRef(null);
1734
+ const loadingMoreRef = react.useRef(false);
1430
1735
  const [atBottom, setAtBottom] = react.useState(true);
1431
1736
  const [newCountWhileAway, setNewCountWhileAway] = react.useState(0);
1737
+ react.useEffect(() => {
1738
+ const sentinel = topSentinelRef.current;
1739
+ const root = listRef.current;
1740
+ if (!sentinel || !root) return;
1741
+ if (!hasMore) return;
1742
+ const io = new IntersectionObserver(
1743
+ (entries) => {
1744
+ const entry = entries[0];
1745
+ if (!entry?.isIntersecting) return;
1746
+ if (loadingMoreRef.current) return;
1747
+ loadingMoreRef.current = true;
1748
+ void Promise.resolve(loadMore()).finally(() => {
1749
+ loadingMoreRef.current = false;
1750
+ });
1751
+ },
1752
+ // Fire when sentinel is within ~400px above the viewport — the
1753
+ // user is approaching the top of loaded history, fetch ahead.
1754
+ { root, rootMargin: "400px 0px 0px 0px", threshold: 0 }
1755
+ );
1756
+ io.observe(sentinel);
1757
+ return () => io.disconnect();
1758
+ }, [hasMore, loadMore]);
1432
1759
  react.useEffect(() => {
1433
1760
  const el = bottomSentinelRef.current;
1434
1761
  if (!el) return;
@@ -1518,20 +1845,56 @@ function ConversationView({
1518
1845
  el.classList.add("poolse-message-row--highlight");
1519
1846
  setTimeout(() => el.classList.remove("poolse-message-row--highlight"), 1600);
1520
1847
  };
1521
- const { upload, uploading } = react$1.useAttachmentUpload();
1522
- const onPickFile = async (file) => {
1848
+ const { queue: uploadQueue, uploadAll, cancel: cancelUpload, remove: removeUpload, uploading } = react$1.useAttachmentUpload();
1849
+ const visibleUploads = uploadQueue.filter(
1850
+ (it) => it.status === "pending" || it.status === "uploading" || it.status === "error"
1851
+ );
1852
+ const onPickFiles = async (files) => {
1853
+ if (files.length === 0) return;
1523
1854
  try {
1524
- const att = await upload({
1525
- body: file,
1526
- contentType: file.type || "application/octet-stream",
1527
- byteSize: file.size,
1528
- filename: file.name
1529
- });
1530
- await send({ body: "", attachment_ids: [att.id] });
1531
- } catch (err) {
1532
- console.error("attachment upload failed:", err);
1855
+ const atts = await uploadAll(
1856
+ files.map((f) => ({
1857
+ body: f,
1858
+ contentType: f.type || "application/octet-stream",
1859
+ byteSize: f.size,
1860
+ filename: f.name
1861
+ }))
1862
+ );
1863
+ await send({ body: "", attachment_ids: atts.map((a) => a.id) });
1864
+ for (const it of uploadQueue) {
1865
+ if (it.status === "ready") removeUpload(it.localId);
1866
+ }
1867
+ } catch {
1533
1868
  }
1534
1869
  };
1870
+ const [dragActive, setDragActive] = react.useState(false);
1871
+ const dragDepthRef = react.useRef(0);
1872
+ const isFileDrag = (e) => Array.from(e.dataTransfer?.types ?? []).includes("Files");
1873
+ const onDragEnter = (e) => {
1874
+ if (!attachments || !isFileDrag(e)) return;
1875
+ e.preventDefault();
1876
+ dragDepthRef.current += 1;
1877
+ setDragActive(true);
1878
+ };
1879
+ const onDragOver = (e) => {
1880
+ if (!attachments || !isFileDrag(e)) return;
1881
+ e.preventDefault();
1882
+ if (e.dataTransfer) e.dataTransfer.dropEffect = "copy";
1883
+ };
1884
+ const onDragLeave = (e) => {
1885
+ if (!attachments || !isFileDrag(e)) return;
1886
+ e.preventDefault();
1887
+ dragDepthRef.current = Math.max(0, dragDepthRef.current - 1);
1888
+ if (dragDepthRef.current === 0) setDragActive(false);
1889
+ };
1890
+ const onDrop = (e) => {
1891
+ if (!attachments || !isFileDrag(e)) return;
1892
+ e.preventDefault();
1893
+ dragDepthRef.current = 0;
1894
+ setDragActive(false);
1895
+ const files = Array.from(e.dataTransfer?.files ?? []);
1896
+ if (files.length > 0) void onPickFiles(files);
1897
+ };
1535
1898
  const onSendBody = async (body, opts) => {
1536
1899
  await send({
1537
1900
  body,
@@ -1562,98 +1925,141 @@ function ConversationView({
1562
1925
  }
1563
1926
  );
1564
1927
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-conversation-shell", children: [
1565
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-conversation", children: [
1566
- status !== "connected" && status !== "idle" && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-conversation__status", children: [
1567
- status === "connecting" && "Connecting\u2026",
1568
- status === "reconnecting" && "Reconnecting\u2026",
1569
- status === "closed" && "Disconnected"
1570
- ] }),
1571
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-conversation__messages", ref: listRef, children: [
1572
- hasMore && !loading && /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "poolse-conversation__load-more", onClick: loadMore, children: "Load older messages" }),
1573
- loading && messages.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation__empty", children: "Loading\u2026" }) : messages.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation__empty", children: emptyState ?? "No messages yet." }) : messages.map((msg, idx) => {
1574
- if (renderMessage) {
1575
- return /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: renderMessage(msg, me?.id ?? null) }, msg.id);
1576
- }
1577
- const prev = idx > 0 ? messages[idx - 1] ?? null : null;
1578
- const next = idx < messages.length - 1 ? messages[idx + 1] ?? null : null;
1579
- const groupPosition = grouping ? computeGroupPosition(msg, prev, next, groupingWindowMs) : "standalone";
1580
- const showDaySeparator = daySeparators && (prev === null || !sameDay(msg.inserted_at, prev.inserted_at));
1581
- const enriched = quotations && msg.quoted_message_id && !msg.quoted_message ? (() => {
1582
- const original = messages.find((m) => m.id === msg.quoted_message_id);
1583
- if (!original) return msg;
1584
- return {
1585
- ...msg,
1586
- quoted_message: {
1587
- id: original.id,
1588
- sender_id: original.sender_id,
1589
- body: original.body,
1590
- deleted_at: original.deleted_at,
1591
- inserted_at: original.inserted_at
1592
- }
1593
- };
1594
- })() : msg;
1595
- const isSelf = me !== null && msg.sender_id === me.id;
1596
- const readState = readReceipts && isSelf && maxReadByOthers !== null ? maxReadByOthers >= msg.sequence ? "read" : "sent" : void 0;
1597
- return /* @__PURE__ */ jsxRuntime.jsxs(react.Fragment, { children: [
1598
- showDaySeparator && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-day-separator", "aria-hidden": "false", children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: formatDayLabel(msg.inserted_at) }) }),
1599
- /* @__PURE__ */ jsxRuntime.jsx(
1600
- MessageRow,
1601
- {
1602
- msg: enriched,
1603
- meId: me?.id ?? null,
1604
- reactions,
1605
- attachments,
1606
- actions,
1607
- threads,
1608
- quotations,
1609
- groupPosition,
1610
- maxBodyLength,
1611
- markdown,
1612
- showSenderName: showSenderLabelsResolved,
1613
- showAvatar: showAvatarsResolved,
1614
- ...readState ? { readState } : {},
1615
- ...labelFor ? { labelFor } : {},
1616
- editing: editingId === msg.id,
1617
- onStartEdit: () => setEditingId(msg.id),
1618
- onCancelEdit: () => setEditingId(null),
1619
- onSaveEdit: async (body) => {
1620
- await edit(msg.id, body);
1621
- setEditingId(null);
1622
- },
1623
- onDelete: () => void deleteMsg(msg.id),
1624
- onOpenThread: () => setThreadRootId(msg.id),
1625
- onQuote: () => setReplyingTo(msg),
1626
- onQuotedClick: scrollToOriginal
1627
- }
1628
- )
1629
- ] }, msg.id);
1630
- }),
1631
- error && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-conversation__empty", children: [
1632
- "Failed to load: ",
1633
- error.message
1634
- ] }),
1635
- /* @__PURE__ */ jsxRuntime.jsx("div", { ref: bottomSentinelRef, "aria-hidden": "true", style: { height: 1 } })
1636
- ] }),
1637
- !atBottom && newCountWhileAway > 0 && /* @__PURE__ */ jsxRuntime.jsxs(
1638
- "button",
1639
- {
1640
- type: "button",
1641
- className: "poolse-conversation__scroll-to-new",
1642
- onClick: scrollToBottom,
1643
- children: [
1644
- "\u2193 ",
1645
- newCountWhileAway,
1646
- " new ",
1647
- newCountWhileAway === 1 ? "message" : "messages"
1648
- ]
1649
- }
1650
- ),
1651
- /* @__PURE__ */ jsxRuntime.jsx(TypingIndicator, { typing, ...labelFor ? { labelFor } : {} }),
1652
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-conversation__composer-row", children: [
1653
- attachments && /* @__PURE__ */ jsxRuntime.jsx(AttachmentPickerButton, { onPick: onPickFile, disabled: uploading }),
1654
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation__composer-flex", children: Composer })
1655
- ] })
1656
- ] }),
1928
+ /* @__PURE__ */ jsxRuntime.jsxs(
1929
+ "div",
1930
+ {
1931
+ className: `poolse-conversation${dragActive ? " is-drag-active" : ""}`,
1932
+ onDragEnter,
1933
+ onDragOver,
1934
+ onDragLeave,
1935
+ onDrop,
1936
+ children: [
1937
+ status !== "connected" && status !== "idle" && /* @__PURE__ */ jsxRuntime.jsxs(
1938
+ "div",
1939
+ {
1940
+ className: "poolse-conversation__status",
1941
+ role: "status",
1942
+ "aria-live": "polite",
1943
+ "aria-atomic": "true",
1944
+ children: [
1945
+ status === "connecting" && "Connecting\u2026",
1946
+ status === "reconnecting" && "Reconnecting\u2026",
1947
+ status === "closed" && "Disconnected"
1948
+ ]
1949
+ }
1950
+ ),
1951
+ /* @__PURE__ */ jsxRuntime.jsxs(
1952
+ "div",
1953
+ {
1954
+ className: "poolse-conversation__messages",
1955
+ ref: listRef,
1956
+ role: "log",
1957
+ "aria-label": "Conversation messages",
1958
+ "aria-live": "polite",
1959
+ "aria-relevant": "additions",
1960
+ children: [
1961
+ hasMore && /* @__PURE__ */ jsxRuntime.jsx("div", { ref: topSentinelRef, "aria-hidden": "true", style: { height: 1 } }),
1962
+ loading && messages.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation__empty", children: "Loading\u2026" }) : messages.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation__empty", children: emptyState ?? "No messages yet." }) : messages.map((msg, idx) => {
1963
+ if (renderMessage) {
1964
+ return /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: renderMessage(msg, me?.id ?? null) }, msg.id);
1965
+ }
1966
+ const prev = idx > 0 ? messages[idx - 1] ?? null : null;
1967
+ const next = idx < messages.length - 1 ? messages[idx + 1] ?? null : null;
1968
+ const groupPosition = grouping ? computeGroupPosition(msg, prev, next, groupingWindowMs) : "standalone";
1969
+ const showDaySeparator = daySeparators && (prev === null || !sameDay(msg.inserted_at, prev.inserted_at));
1970
+ const enriched = quotations && msg.quoted_message_id && !msg.quoted_message ? (() => {
1971
+ const original = messages.find((m) => m.id === msg.quoted_message_id);
1972
+ if (!original) return msg;
1973
+ return {
1974
+ ...msg,
1975
+ quoted_message: {
1976
+ id: original.id,
1977
+ sender_id: original.sender_id,
1978
+ body: original.body,
1979
+ deleted_at: original.deleted_at,
1980
+ inserted_at: original.inserted_at
1981
+ }
1982
+ };
1983
+ })() : msg;
1984
+ const isSelf = me !== null && msg.sender_id === me.id;
1985
+ const readState = readReceipts && isSelf && maxReadByOthers !== null ? maxReadByOthers >= msg.sequence ? "read" : "sent" : void 0;
1986
+ return /* @__PURE__ */ jsxRuntime.jsxs(react.Fragment, { children: [
1987
+ showDaySeparator && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-day-separator", "aria-hidden": "false", children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: formatDayLabel(msg.inserted_at) }) }),
1988
+ /* @__PURE__ */ jsxRuntime.jsx(
1989
+ MessageRow,
1990
+ {
1991
+ msg: enriched,
1992
+ meId: me?.id ?? null,
1993
+ reactions,
1994
+ attachments,
1995
+ actions,
1996
+ threads,
1997
+ quotations,
1998
+ groupPosition,
1999
+ maxBodyLength,
2000
+ markdown,
2001
+ showSenderName: showSenderLabelsResolved,
2002
+ showAvatar: showAvatarsResolved,
2003
+ ...readState ? { readState } : {},
2004
+ ...labelFor ? { labelFor } : {},
2005
+ editing: editingId === msg.id,
2006
+ onStartEdit: () => setEditingId(msg.id),
2007
+ onCancelEdit: () => setEditingId(null),
2008
+ onSaveEdit: async (body) => {
2009
+ await edit(msg.id, body);
2010
+ setEditingId(null);
2011
+ },
2012
+ onDelete: () => void deleteMsg(msg.id),
2013
+ onOpenThread: () => setThreadRootId(msg.id),
2014
+ onQuote: () => setReplyingTo(msg),
2015
+ onQuotedClick: scrollToOriginal
2016
+ }
2017
+ )
2018
+ ] }, msg.id);
2019
+ }),
2020
+ error && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-conversation__empty", children: [
2021
+ "Failed to load: ",
2022
+ error.message
2023
+ ] }),
2024
+ /* @__PURE__ */ jsxRuntime.jsx("div", { ref: bottomSentinelRef, "aria-hidden": "true", style: { height: 1 } })
2025
+ ]
2026
+ }
2027
+ ),
2028
+ !atBottom && newCountWhileAway > 0 && /* @__PURE__ */ jsxRuntime.jsxs(
2029
+ "button",
2030
+ {
2031
+ type: "button",
2032
+ className: "poolse-conversation__scroll-to-new",
2033
+ onClick: scrollToBottom,
2034
+ children: [
2035
+ "\u2193 ",
2036
+ newCountWhileAway,
2037
+ " new ",
2038
+ newCountWhileAway === 1 ? "message" : "messages"
2039
+ ]
2040
+ }
2041
+ ),
2042
+ /* @__PURE__ */ jsxRuntime.jsx(TypingIndicator, { typing, ...labelFor ? { labelFor } : {} }),
2043
+ attachments && /* @__PURE__ */ jsxRuntime.jsx(
2044
+ UploadQueueStrip,
2045
+ {
2046
+ items: visibleUploads,
2047
+ onCancel: cancelUpload,
2048
+ onDismiss: removeUpload
2049
+ }
2050
+ ),
2051
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-conversation__composer-row", children: [
2052
+ attachments && /* @__PURE__ */ jsxRuntime.jsx(AttachmentPickerButton, { onPick: onPickFiles, disabled: uploading }),
2053
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation__composer-flex", children: Composer })
2054
+ ] }),
2055
+ dragActive && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation__drop-overlay", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-conversation__drop-overlay-inner", children: [
2056
+ /* @__PURE__ */ jsxRuntime.jsx(PoolseIcon, { name: "attachment", size: 40, label: null }),
2057
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation__drop-overlay-title", children: "Drop files to upload" }),
2058
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation__drop-overlay-hint", children: "They'll be sent in one message" })
2059
+ ] }) })
2060
+ ]
2061
+ }
2062
+ ),
1657
2063
  threads && threadRoot && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation-shell__thread", children: /* @__PURE__ */ jsxRuntime.jsx(
1658
2064
  ThreadView,
1659
2065
  {
@@ -1675,10 +2081,11 @@ function AttachmentPickerButton({
1675
2081
  {
1676
2082
  ref: inputRef,
1677
2083
  type: "file",
2084
+ multiple: true,
1678
2085
  className: "poolse-attach-input",
1679
2086
  onChange: (e) => {
1680
- const f = e.target.files?.[0];
1681
- if (f) onPick(f);
2087
+ const files = Array.from(e.target.files ?? []);
2088
+ if (files.length > 0) onPick(files);
1682
2089
  e.target.value = "";
1683
2090
  }
1684
2091
  }
@@ -1690,49 +2097,13 @@ function AttachmentPickerButton({
1690
2097
  className: "poolse-attach-btn",
1691
2098
  onClick: () => inputRef.current?.click(),
1692
2099
  disabled,
1693
- "aria-label": "Attach file",
1694
- title: "Attach file",
2100
+ "aria-label": "Attach files",
2101
+ title: "Attach files",
1695
2102
  children: /* @__PURE__ */ jsxRuntime.jsx(PoolseIcon, { name: "attachment", size: 20, label: null })
1696
2103
  }
1697
2104
  )
1698
2105
  ] });
1699
2106
  }
1700
- function computeGroupPosition(msg, prev, next, windowMs) {
1701
- const continuesPrev = sameGroup(msg, prev, windowMs);
1702
- const continuesNext = sameGroup(next, msg, windowMs);
1703
- if (continuesPrev && continuesNext) return "middle";
1704
- if (continuesPrev) return "last";
1705
- if (continuesNext) return "first";
1706
- return "standalone";
1707
- }
1708
- function sameGroup(a, b, windowMs) {
1709
- if (!a || !b) return false;
1710
- if (a.sender_id !== b.sender_id) return false;
1711
- if (!sameDay(a.inserted_at, b.inserted_at)) return false;
1712
- const ta = new Date(a.inserted_at).getTime();
1713
- const tb = new Date(b.inserted_at).getTime();
1714
- return Math.abs(ta - tb) <= windowMs;
1715
- }
1716
- function sameDay(a, b) {
1717
- const da = new Date(a);
1718
- const db = new Date(b);
1719
- return da.getFullYear() === db.getFullYear() && da.getMonth() === db.getMonth() && da.getDate() === db.getDate();
1720
- }
1721
- function formatDayLabel(iso) {
1722
- const d = new Date(iso);
1723
- const now = /* @__PURE__ */ new Date();
1724
- const startOfDay = (x) => new Date(x.getFullYear(), x.getMonth(), x.getDate()).getTime();
1725
- const diffDays = Math.floor((startOfDay(now) - startOfDay(d)) / 864e5);
1726
- if (diffDays === 0) return "Today";
1727
- if (diffDays === 1) return "Yesterday";
1728
- if (diffDays < 7) {
1729
- return d.toLocaleDateString(void 0, { weekday: "long" });
1730
- }
1731
- if (d.getFullYear() === now.getFullYear()) {
1732
- return d.toLocaleDateString(void 0, { weekday: "short", day: "numeric", month: "short" });
1733
- }
1734
- return d.toLocaleDateString(void 0, { day: "numeric", month: "short", year: "numeric" });
1735
- }
1736
2107
  function ConversationList({
1737
2108
  selectedId,
1738
2109
  onSelect,
@@ -1828,6 +2199,10 @@ function MemberList({
1828
2199
  emptyState
1829
2200
  }) {
1830
2201
  const { members, loading, error, removeMember } = react$1.useMembers(conversationId);
2202
+ const { online: presenceOnline } = react$1.usePresence(
2203
+ onlineUserIds === void 0 ? conversationId : ""
2204
+ );
2205
+ const effectiveOnline = onlineUserIds ?? presenceOnline;
1831
2206
  if (loading && members.length === 0) {
1832
2207
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-list poolse-list--placeholder", children: "Loading members\u2026" });
1833
2208
  }
@@ -1840,19 +2215,18 @@ function MemberList({
1840
2215
  if (members.length === 0) {
1841
2216
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-list poolse-list--placeholder", children: emptyState ?? "No members yet." });
1842
2217
  }
1843
- const label = labelFor ?? ((id) => id.slice(0, 8));
1844
2218
  return /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "poolse-list", role: "list", "aria-label": "Members", children: members.map((m) => {
1845
2219
  const content = renderItem ? renderItem(m) : /* @__PURE__ */ jsxRuntime.jsx(
1846
2220
  DefaultMemberRow,
1847
2221
  {
1848
2222
  membership: m,
1849
- name: label(m.user_id),
1850
2223
  avatarUrl: avatarFor?.(m.user_id) ?? null,
1851
- online: onlineUserIds?.has(m.user_id) ?? false,
2224
+ online: effectiveOnline.has(m.user_id),
1852
2225
  removable: canRemove?.(m) ?? false,
1853
2226
  onRemove: () => {
1854
2227
  void removeMember(m.user_id);
1855
- }
2228
+ },
2229
+ ...labelFor ? { labelFor } : {}
1856
2230
  }
1857
2231
  );
1858
2232
  return /* @__PURE__ */ jsxRuntime.jsx("li", { className: "poolse-list__item", children: content }, m.id);
@@ -1860,12 +2234,13 @@ function MemberList({
1860
2234
  }
1861
2235
  function DefaultMemberRow({
1862
2236
  membership,
1863
- name,
1864
2237
  avatarUrl,
1865
2238
  online,
1866
2239
  removable,
1867
- onRemove
2240
+ onRemove,
2241
+ labelFor
1868
2242
  }) {
2243
+ const name = useDisplayName(membership.user_id, labelFor);
1869
2244
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-member-row", children: [
1870
2245
  /* @__PURE__ */ jsxRuntime.jsx(Avatar, { src: avatarUrl, name, online, size: "md" }),
1871
2246
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-member-row__body", children: [
@@ -2017,6 +2392,9 @@ exports.ReactionPicker = ReactionPicker;
2017
2392
  exports.ReactionStrip = ReactionStrip;
2018
2393
  exports.ThreadView = ThreadView;
2019
2394
  exports.TypingIndicator = TypingIndicator;
2395
+ exports.UploadQueueStrip = UploadQueueStrip;
2396
+ exports.UserName = UserName;
2397
+ exports.useDisplayName = useDisplayName;
2020
2398
  exports.usePoolseFonts = usePoolseFonts;
2021
2399
  //# sourceMappingURL=index.cjs.map
2022
2400
  //# sourceMappingURL=index.cjs.map