@poolse/react-ui 1.0.0-beta.0 → 1.0.0-rc.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
@@ -1,7 +1,9 @@
1
1
  'use client';
2
- import { useMembers, useAttachmentUrl, useReactions, useMe, useThread, useMessages, useTyping, useRealtimeStatus, useAttachmentUpload, useConversations } from '@poolse/react';
2
+ import { useUser, useMembers, useAttachmentUrl, useReactions, useMe, useThread, useMessages, useTyping, useRealtimeStatus, useAttachmentUpload, useConversations } from '@poolse/react';
3
3
  import { useEffect, useState, useRef, Fragment as Fragment$1, useMemo } from 'react';
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
+ import ReactMarkdown from 'react-markdown';
6
+ import remarkGfm from 'remark-gfm';
5
7
 
6
8
  // src/ConversationView.tsx
7
9
  var FONT_HREF = "https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,400;12..96,600;12..96,800&family=Hanken+Grotesk:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap";
@@ -40,6 +42,77 @@ function PoolseFonts() {
40
42
  return null;
41
43
  }
42
44
 
45
+ // src/grouping.ts
46
+ function computeGroupPosition(msg, prev, next, windowMs) {
47
+ const continuesPrev = sameGroup(msg, prev, windowMs);
48
+ const continuesNext = sameGroup(next, msg, windowMs);
49
+ if (continuesPrev && continuesNext) return "middle";
50
+ if (continuesPrev) return "last";
51
+ if (continuesNext) return "first";
52
+ return "standalone";
53
+ }
54
+ function sameGroup(a, b, windowMs) {
55
+ if (!a || !b) return false;
56
+ if (a.sender_id !== b.sender_id) return false;
57
+ if (!sameDay(a.inserted_at, b.inserted_at)) return false;
58
+ const ta = new Date(a.inserted_at).getTime();
59
+ const tb = new Date(b.inserted_at).getTime();
60
+ return Math.abs(ta - tb) <= windowMs;
61
+ }
62
+ function sameDay(a, b) {
63
+ const da = new Date(a);
64
+ const db = new Date(b);
65
+ return da.getFullYear() === db.getFullYear() && da.getMonth() === db.getMonth() && da.getDate() === db.getDate();
66
+ }
67
+ function formatDayLabel(iso, now = /* @__PURE__ */ new Date()) {
68
+ const d = new Date(iso);
69
+ const startOfDay = (x) => new Date(x.getFullYear(), x.getMonth(), x.getDate()).getTime();
70
+ const diffDays = Math.floor((startOfDay(now) - startOfDay(d)) / 864e5);
71
+ if (diffDays === 0) return "Today";
72
+ if (diffDays === 1) return "Yesterday";
73
+ if (diffDays < 7) {
74
+ return d.toLocaleDateString(void 0, { weekday: "long" });
75
+ }
76
+ if (d.getFullYear() === now.getFullYear()) {
77
+ return d.toLocaleDateString(void 0, { weekday: "short", day: "numeric", month: "short" });
78
+ }
79
+ return d.toLocaleDateString(void 0, { day: "numeric", month: "short", year: "numeric" });
80
+ }
81
+
82
+ // src/listAutocomplete.ts
83
+ var UNORDERED_RE = /^(\s*)([-*+]) (.*)$/;
84
+ var ORDERED_RE = /^(\s*)(\d+)\. (.*)$/;
85
+ function handleListEnter(value, caret) {
86
+ const lineStart = value.lastIndexOf("\n", caret - 1) + 1;
87
+ const lineEnd = (() => {
88
+ const nl = value.indexOf("\n", caret);
89
+ return nl === -1 ? value.length : nl;
90
+ })();
91
+ const currentLine = value.slice(lineStart, lineEnd);
92
+ const unordered = UNORDERED_RE.exec(currentLine);
93
+ const ordered = ORDERED_RE.exec(currentLine);
94
+ const match = unordered ?? ordered;
95
+ if (!match) return null;
96
+ const indent = match[1] ?? "";
97
+ const marker = match[2] ?? "";
98
+ const content = match[3] ?? "";
99
+ if (content === "") {
100
+ const before2 = value.slice(0, lineStart);
101
+ const after2 = value.slice(lineEnd);
102
+ return { kind: "end", value: before2 + after2, caret: lineStart };
103
+ }
104
+ const nextMarker = ordered ? `${parseInt(marker, 10) + 1}.` : marker;
105
+ const prefix = `
106
+ ${indent}${nextMarker} `;
107
+ const before = value.slice(0, caret);
108
+ const after = value.slice(caret);
109
+ return {
110
+ kind: "continue",
111
+ value: before + prefix + after,
112
+ caret: caret + prefix.length
113
+ };
114
+ }
115
+
43
116
  // src/icons-data.ts
44
117
  var ICONS = {
45
118
  attachment: {
@@ -244,6 +317,31 @@ function PoolseIcon({
244
317
  }
245
318
  );
246
319
  }
320
+ var MAX_NAME_CHARS = 24;
321
+ function UserName({
322
+ userId,
323
+ labelFor,
324
+ emptyFallback = "Unknown",
325
+ className
326
+ }) {
327
+ const { profile } = useUser(labelFor ? null : userId);
328
+ const name = resolveDisplayName(userId, profile?.displayName, labelFor, emptyFallback);
329
+ return /* @__PURE__ */ jsx("span", { className, children: truncate(name) });
330
+ }
331
+ function useDisplayName(userId, labelFor, emptyFallback = "Unknown") {
332
+ const { profile } = useUser(labelFor ? null : userId);
333
+ return resolveDisplayName(userId, profile?.displayName, labelFor, emptyFallback);
334
+ }
335
+ function resolveDisplayName(userId, resolved, labelFor, emptyFallback) {
336
+ if (!userId) return emptyFallback;
337
+ if (labelFor) return labelFor(userId);
338
+ if (resolved) return resolved;
339
+ return `User ${userId.slice(0, 6)}`;
340
+ }
341
+ function truncate(s) {
342
+ if (s.length <= MAX_NAME_CHARS) return s;
343
+ return s.slice(0, MAX_NAME_CHARS - 1) + "\u2026";
344
+ }
247
345
  function MentionInput({
248
346
  conversationId,
249
347
  onSend,
@@ -348,6 +446,17 @@ function MentionInput({
348
446
  }
349
447
  }
350
448
  if (e.key === "Enter" && !e.shiftKey) {
449
+ const ta = e.currentTarget;
450
+ const caret = ta.selectionStart;
451
+ const result = handleListEnter(value, caret);
452
+ if (result) {
453
+ e.preventDefault();
454
+ setValue(result.value);
455
+ requestAnimationFrame(() => {
456
+ taRef.current?.setSelectionRange(result.caret, result.caret);
457
+ });
458
+ return;
459
+ }
351
460
  e.preventDefault();
352
461
  void submit();
353
462
  }
@@ -398,7 +507,13 @@ function MentionInput({
398
507
  onChange,
399
508
  onKeyDown,
400
509
  placeholder,
401
- disabled: disabled || sending
510
+ disabled: disabled || sending,
511
+ "aria-label": placeholder,
512
+ role: "combobox",
513
+ "aria-expanded": Boolean(mention && filtered.length > 0),
514
+ "aria-controls": "poolse-mention-menu",
515
+ "aria-autocomplete": "list",
516
+ ...mention && filtered.length > 0 ? { "aria-activedescendant": `poolse-mention-opt-${activeIdx}` } : {}
402
517
  }
403
518
  ),
404
519
  /* @__PURE__ */ jsx(
@@ -412,23 +527,33 @@ function MentionInput({
412
527
  }
413
528
  )
414
529
  ] }),
415
- mention && filtered.length > 0 && /* @__PURE__ */ jsx("div", { className: "poolse-mention-menu", role: "listbox", "aria-label": "Members", children: filtered.map((m, i) => /* @__PURE__ */ jsx(
530
+ mention && filtered.length > 0 && /* @__PURE__ */ jsx(
416
531
  "div",
417
532
  {
418
- role: "option",
419
- "aria-selected": i === activeIdx,
420
- className: `poolse-mention-menu__item${i === activeIdx ? " poolse-mention-menu__item--active" : ""}`,
421
- onMouseDown: (e) => {
422
- e.preventDefault();
423
- insertMention(m);
424
- },
425
- children: /* @__PURE__ */ jsxs("span", { children: [
426
- "@",
427
- label(m.user_id)
428
- ] })
429
- },
430
- m.id
431
- )) })
533
+ id: "poolse-mention-menu",
534
+ className: "poolse-mention-menu",
535
+ role: "listbox",
536
+ "aria-label": "Members",
537
+ children: filtered.map((m, i) => /* @__PURE__ */ jsxs(
538
+ "div",
539
+ {
540
+ id: `poolse-mention-opt-${i}`,
541
+ role: "option",
542
+ "aria-selected": i === activeIdx,
543
+ className: `poolse-mention-menu__item${i === activeIdx ? " poolse-mention-menu__item--active" : ""}`,
544
+ onMouseDown: (e) => {
545
+ e.preventDefault();
546
+ insertMention(m);
547
+ },
548
+ children: [
549
+ /* @__PURE__ */ jsx("span", { children: "@" }),
550
+ /* @__PURE__ */ jsx(UserName, { userId: m.user_id, ...labelFor ? { labelFor } : {} })
551
+ ]
552
+ },
553
+ m.id
554
+ ))
555
+ }
556
+ )
432
557
  ]
433
558
  }
434
559
  );
@@ -444,6 +569,7 @@ function MessageComposer({
444
569
  }) {
445
570
  const [value, setValue] = useState("");
446
571
  const [sending, setSending] = useState(false);
572
+ const taRef = useRef(null);
447
573
  const submit = async () => {
448
574
  const trimmed = value.trim();
449
575
  if (!trimmed || sending) return;
@@ -457,6 +583,17 @@ function MessageComposer({
457
583
  };
458
584
  const onKeyDown = (e) => {
459
585
  if (e.key === "Enter" && !e.shiftKey) {
586
+ const ta = e.currentTarget;
587
+ const caret = ta.selectionStart;
588
+ const result = handleListEnter(value, caret);
589
+ if (result) {
590
+ e.preventDefault();
591
+ setValue(result.value);
592
+ requestAnimationFrame(() => {
593
+ taRef.current?.setSelectionRange(result.caret, result.caret);
594
+ });
595
+ return;
596
+ }
460
597
  e.preventDefault();
461
598
  void submit();
462
599
  }
@@ -490,13 +627,15 @@ function MessageComposer({
490
627
  /* @__PURE__ */ jsx(
491
628
  "textarea",
492
629
  {
630
+ ref: taRef,
493
631
  className: "poolse-composer__input",
494
632
  rows: 1,
495
633
  value,
496
634
  onChange,
497
635
  onKeyDown,
498
636
  placeholder,
499
- disabled: disabled || sending
637
+ disabled: disabled || sending,
638
+ "aria-label": placeholder
500
639
  }
501
640
  ),
502
641
  /* @__PURE__ */ jsx(
@@ -545,6 +684,7 @@ function ReplyChip({
545
684
  function AttachmentPreview({ attachment, onClick }) {
546
685
  const isFullRow = "content_type" in attachment;
547
686
  const { url, loading, error } = useAttachmentUrl(attachment.id);
687
+ const [lightboxOpen, setLightboxOpen] = useState(false);
548
688
  if (loading) {
549
689
  return /* @__PURE__ */ jsx("div", { className: "poolse-attachment poolse-list--placeholder", "aria-busy": "true", children: "Loading attachment\u2026" });
550
690
  }
@@ -555,29 +695,33 @@ function AttachmentPreview({ attachment, onClick }) {
555
695
  const isImage = ct.startsWith("image/");
556
696
  if (isImage) {
557
697
  const filename2 = isFullRow ? attachment.original_filename : null;
558
- return /* @__PURE__ */ jsx("div", { className: "poolse-attachment", children: /* @__PURE__ */ jsx(
559
- "a",
560
- {
561
- href: url,
562
- target: "_blank",
563
- rel: "noopener noreferrer",
564
- onClick: (e) => {
565
- if (onClick) {
566
- e.preventDefault();
567
- onClick({ id: attachment.id });
568
- }
569
- },
570
- children: /* @__PURE__ */ jsx(
571
- "img",
572
- {
573
- className: "poolse-attachment__image",
574
- src: url,
575
- alt: filename2 ?? "attachment",
576
- loading: "lazy"
577
- }
578
- )
579
- }
580
- ) });
698
+ return /* @__PURE__ */ jsxs("div", { className: "poolse-attachment", children: [
699
+ /* @__PURE__ */ jsx(
700
+ "button",
701
+ {
702
+ type: "button",
703
+ className: "poolse-attachment__image-button",
704
+ "aria-label": filename2 ? `Open ${filename2}` : "Open image",
705
+ onClick: () => {
706
+ if (onClick) {
707
+ onClick({ id: attachment.id });
708
+ return;
709
+ }
710
+ setLightboxOpen(true);
711
+ },
712
+ children: /* @__PURE__ */ jsx(
713
+ "img",
714
+ {
715
+ className: "poolse-attachment__image",
716
+ src: url,
717
+ alt: filename2 ?? "attachment",
718
+ loading: "lazy"
719
+ }
720
+ )
721
+ }
722
+ ),
723
+ lightboxOpen && /* @__PURE__ */ jsx(Lightbox, { url, filename: filename2, onClose: () => setLightboxOpen(false) })
724
+ ] });
581
725
  }
582
726
  const filename = isFullRow ? attachment.original_filename ?? "file" : "file";
583
727
  const byteSize = isFullRow ? attachment.byte_size : null;
@@ -622,6 +766,70 @@ function AttachmentPreview({ attachment, onClick }) {
622
766
  }
623
767
  ) });
624
768
  }
769
+ function Lightbox({
770
+ url,
771
+ filename,
772
+ onClose
773
+ }) {
774
+ useEffect(() => {
775
+ const onKey = (e) => {
776
+ if (e.key === "Escape") onClose();
777
+ };
778
+ document.addEventListener("keydown", onKey);
779
+ const prev = document.body.style.overflow;
780
+ document.body.style.overflow = "hidden";
781
+ return () => {
782
+ document.removeEventListener("keydown", onKey);
783
+ document.body.style.overflow = prev;
784
+ };
785
+ }, [onClose]);
786
+ return /* @__PURE__ */ jsxs(
787
+ "div",
788
+ {
789
+ className: "poolse-lightbox",
790
+ role: "dialog",
791
+ "aria-modal": "true",
792
+ "aria-label": filename ?? "Image preview",
793
+ onClick: onClose,
794
+ children: [
795
+ /* @__PURE__ */ jsx(
796
+ "button",
797
+ {
798
+ type: "button",
799
+ className: "poolse-lightbox__close",
800
+ "aria-label": "Close",
801
+ onClick: (e) => {
802
+ e.stopPropagation();
803
+ onClose();
804
+ },
805
+ children: "\xD7"
806
+ }
807
+ ),
808
+ /* @__PURE__ */ jsx(
809
+ "img",
810
+ {
811
+ className: "poolse-lightbox__image",
812
+ src: url,
813
+ alt: filename ?? "attachment",
814
+ onClick: (e) => e.stopPropagation()
815
+ }
816
+ ),
817
+ /* @__PURE__ */ jsx(
818
+ "a",
819
+ {
820
+ className: "poolse-lightbox__download",
821
+ href: url,
822
+ download: filename ?? void 0,
823
+ target: "_blank",
824
+ rel: "noopener noreferrer",
825
+ onClick: (e) => e.stopPropagation(),
826
+ children: "Download"
827
+ }
828
+ )
829
+ ]
830
+ }
831
+ );
832
+ }
625
833
  function guessContentType(url) {
626
834
  const m = url.match(/\.([a-z0-9]+)(?:\?|#|$)/i);
627
835
  if (!m) return "application/octet-stream";
@@ -636,24 +844,87 @@ function formatBytes(n) {
636
844
  if (n < 1024 * 1024 * 1024) return `${(n / (1024 * 1024)).toFixed(1)} MB`;
637
845
  return `${(n / (1024 * 1024 * 1024)).toFixed(2)} GB`;
638
846
  }
847
+ function Avatar({ src, name, online, size = "md", className }) {
848
+ const initials = computeInitials(name);
849
+ const classes = [
850
+ "poolse-avatar",
851
+ size === "sm" ? "poolse-avatar--sm" : null,
852
+ size === "lg" ? "poolse-avatar--lg" : null,
853
+ className
854
+ ].filter(Boolean).join(" ");
855
+ return /* @__PURE__ */ jsxs("span", { className: classes, "aria-label": name ?? "avatar", role: "img", children: [
856
+ src ? /* @__PURE__ */ jsx("img", { src, alt: name ?? "" }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: initials }),
857
+ online ? /* @__PURE__ */ jsx("span", { className: "poolse-avatar__presence", "aria-hidden": "true" }) : null
858
+ ] });
859
+ }
860
+ function computeInitials(name) {
861
+ if (!name) return "?";
862
+ const parts = name.trim().split(/\s+/).slice(0, 2);
863
+ return parts.map((p) => p.charAt(0).toUpperCase()).join("").slice(0, 2) || "?";
864
+ }
865
+
866
+ // src/userColor.ts
867
+ var PALETTE = [
868
+ "#6366f1",
869
+ // indigo
870
+ "#10b981",
871
+ // emerald
872
+ "#f59e0b",
873
+ // amber
874
+ "#ec4899",
875
+ // rose
876
+ "#0ea5e9",
877
+ // sky
878
+ "#8b5cf6",
879
+ // violet
880
+ "#14b8a6",
881
+ // teal
882
+ "#d946ef"
883
+ // fuchsia
884
+ ];
885
+ function userColor(userId) {
886
+ let h = 0;
887
+ for (let i = 0; i < userId.length; i++) {
888
+ h = h * 31 + userId.charCodeAt(i) | 0;
889
+ }
890
+ return PALETTE[Math.abs(h) % PALETTE.length];
891
+ }
639
892
  function MessageBubble({
640
893
  message,
641
894
  currentUserId,
642
895
  readState,
643
896
  labelFor,
644
- onQuotedClick
897
+ onQuotedClick,
898
+ groupPosition = "standalone",
899
+ maxBodyLength = 0,
900
+ markdown = false,
901
+ showSenderName = false
645
902
  }) {
646
903
  const isSelf = currentUserId !== null && message.sender_id === currentUserId;
904
+ const [expanded, setExpanded] = useState(false);
905
+ const { profile: sender } = useUser(!isSelf ? message.sender_id : null);
906
+ const senderFallbackName = message.sender_id ? `User ${message.sender_id.slice(0, 6)}` : "Unknown";
907
+ const senderName = sender?.displayName ?? senderFallbackName;
908
+ const senderColorHex = message.sender_id ? userColor(message.sender_id) : "currentColor";
909
+ const renderSenderName = showSenderName && !isSelf && (groupPosition === "first" || groupPosition === "standalone");
647
910
  const className = [
648
911
  "poolse-message",
649
- isSelf ? "poolse-message--self" : "poolse-message--other"
912
+ isSelf ? "poolse-message--self" : "poolse-message--other",
913
+ // Group-position modifier — CSS uses it to toggle which corners
914
+ // get the asymmetric tail vs. fully-rounded treatment.
915
+ `poolse-message--${groupPosition}`
650
916
  ].join(" ");
917
+ const rawBody = message.body ?? "";
918
+ const TRIM_BUFFER = 40;
919
+ const shouldTrim = !expanded && maxBodyLength > 0 && rawBody.length > maxBodyLength + TRIM_BUFFER;
920
+ const displayBody = shouldTrim ? rawBody.slice(0, maxBodyLength).trimEnd() + "\u2026" : rawBody;
651
921
  const time = message.inserted_at ? new Date(message.inserted_at).toLocaleTimeString(void 0, {
652
922
  hour: "2-digit",
653
923
  minute: "2-digit"
654
924
  }) : "";
655
925
  const showQuoteCard = message.quoted_message !== void 0 && message.quoted_message !== null ? "full" : message.quoted_message_id ? "placeholder" : null;
656
926
  return /* @__PURE__ */ jsxs("div", { className, children: [
927
+ renderSenderName && /* @__PURE__ */ jsx("div", { className: "poolse-message__sender", style: { color: senderColorHex }, children: senderName }),
657
928
  showQuoteCard === "full" && /* @__PURE__ */ jsx(
658
929
  QuotedCard,
659
930
  {
@@ -664,7 +935,44 @@ function MessageBubble({
664
935
  }
665
936
  ),
666
937
  showQuoteCard === "placeholder" && /* @__PURE__ */ jsx(QuotedPlaceholder, { isSelf, quotedMessageId: message.quoted_message_id }),
667
- message.deleted_at ? /* @__PURE__ */ jsx("span", { className: "poolse-message__body--deleted", children: "[deleted]" }) : /* @__PURE__ */ jsx("span", { children: message.body ?? "" }),
938
+ message.deleted_at ? /* @__PURE__ */ jsx("span", { className: "poolse-message__body--deleted", children: "[deleted]" }) : /* @__PURE__ */ jsxs("div", { className: "poolse-message__body", children: [
939
+ markdown ? /* @__PURE__ */ jsx(
940
+ ReactMarkdown,
941
+ {
942
+ remarkPlugins: [remarkGfm],
943
+ components: {
944
+ // Force links to a new tab + no opener — chat content
945
+ // is user-supplied so security defaults matter.
946
+ a: ({ node: _node, ...props }) => /* @__PURE__ */ jsx("a", { ...props, target: "_blank", rel: "noopener noreferrer nofollow" })
947
+ },
948
+ children: displayBody
949
+ }
950
+ ) : /* @__PURE__ */ jsx("span", { children: displayBody }),
951
+ shouldTrim && /* @__PURE__ */ jsx(
952
+ "button",
953
+ {
954
+ type: "button",
955
+ className: "poolse-message__read-more",
956
+ onClick: (e) => {
957
+ e.stopPropagation();
958
+ setExpanded(true);
959
+ },
960
+ children: "Read more"
961
+ }
962
+ ),
963
+ !shouldTrim && expanded && rawBody.length > maxBodyLength + TRIM_BUFFER && /* @__PURE__ */ jsx(
964
+ "button",
965
+ {
966
+ type: "button",
967
+ className: "poolse-message__read-more",
968
+ onClick: (e) => {
969
+ e.stopPropagation();
970
+ setExpanded(false);
971
+ },
972
+ children: "Show less"
973
+ }
974
+ )
975
+ ] }),
668
976
  /* @__PURE__ */ jsxs("span", { className: "poolse-message__meta", children: [
669
977
  /* @__PURE__ */ jsx("span", { children: time }),
670
978
  message.edited_at ? /* @__PURE__ */ jsx("span", { children: " \xB7 edited" }) : null,
@@ -872,19 +1180,53 @@ function ReactionPicker({
872
1180
  onPick,
873
1181
  onClose
874
1182
  }) {
1183
+ const rootRef = useRef(null);
1184
+ useEffect(() => {
1185
+ const firstBtn = rootRef.current?.querySelector("button");
1186
+ if (firstBtn instanceof HTMLElement) firstBtn.focus();
1187
+ }, []);
1188
+ useEffect(() => {
1189
+ if (!onClose) return;
1190
+ const onPointer = (e) => {
1191
+ const t = e.target;
1192
+ if (t instanceof Node && rootRef.current && !rootRef.current.contains(t)) {
1193
+ onClose();
1194
+ }
1195
+ };
1196
+ document.addEventListener("pointerdown", onPointer, true);
1197
+ return () => document.removeEventListener("pointerdown", onPointer, true);
1198
+ }, [onClose]);
1199
+ const onKey = (e) => {
1200
+ if (e.key === "Escape") {
1201
+ e.stopPropagation();
1202
+ onClose?.();
1203
+ return;
1204
+ }
1205
+ if (e.key === "ArrowRight" || e.key === "ArrowLeft") {
1206
+ const buttons = Array.from(
1207
+ rootRef.current?.querySelectorAll("button") ?? []
1208
+ );
1209
+ const idx = buttons.findIndex((b) => b === document.activeElement);
1210
+ if (idx === -1) return;
1211
+ const nextIdx = e.key === "ArrowRight" ? (idx + 1) % buttons.length : (idx - 1 + buttons.length) % buttons.length;
1212
+ buttons[nextIdx]?.focus();
1213
+ e.preventDefault();
1214
+ }
1215
+ };
875
1216
  return /* @__PURE__ */ jsx(
876
1217
  "div",
877
1218
  {
1219
+ ref: rootRef,
878
1220
  className: "poolse-reaction-picker",
879
1221
  role: "menu",
1222
+ "aria-label": "Pick a reaction",
880
1223
  style: { position: "absolute", bottom: "100%", left: 0, marginBottom: 6 },
881
- onKeyDown: (e) => {
882
- if (e.key === "Escape") onClose?.();
883
- },
1224
+ onKeyDown: onKey,
884
1225
  children: COMMON_EMOJIS.map((e) => /* @__PURE__ */ jsx(
885
1226
  "button",
886
1227
  {
887
1228
  type: "button",
1229
+ role: "menuitem",
888
1230
  className: "poolse-reaction-picker__btn",
889
1231
  onClick: () => onPick(e),
890
1232
  "aria-label": `React with ${e}`,
@@ -966,8 +1308,16 @@ function MessageRow({
966
1308
  onOpenThread,
967
1309
  onQuote,
968
1310
  labelFor,
969
- onQuotedClick
1311
+ onQuotedClick,
1312
+ groupPosition = "standalone",
1313
+ maxBodyLength = 0,
1314
+ markdown = false,
1315
+ showSenderName = false,
1316
+ showAvatar = false
970
1317
  }) {
1318
+ const { profile: senderProfile } = useUser(msg.sender_id);
1319
+ const senderFallbackName = msg.sender_id ? `User ${msg.sender_id.slice(0, 6)}` : "Unknown";
1320
+ const senderName = senderProfile?.displayName ?? senderFallbackName;
971
1321
  const isSelf = meId !== null && msg.sender_id === meId;
972
1322
  const reactionsHook = useReactions(reactions ? msg.id : "", {
973
1323
  conversationId: msg.conversation_id,
@@ -981,11 +1331,34 @@ function MessageRow({
981
1331
  const showThreadPill = threads && !msg.deleted_at && !msg.thread_root_id && replyCount > 0;
982
1332
  const handleSave = onSaveEdit ?? (async () => void 0);
983
1333
  const handleCancel = onCancelEdit ?? (() => void 0);
1334
+ const [actionsOpen, setActionsOpen] = useState(false);
1335
+ const rowRef = useRef(null);
1336
+ useEffect(() => {
1337
+ if (!actionsOpen) return;
1338
+ const onDown = (e) => {
1339
+ const t = e.target;
1340
+ if (t instanceof Node && rowRef.current && !rowRef.current.contains(t)) {
1341
+ setActionsOpen(false);
1342
+ }
1343
+ };
1344
+ document.addEventListener("pointerdown", onDown);
1345
+ return () => document.removeEventListener("pointerdown", onDown);
1346
+ }, [actionsOpen]);
984
1347
  return /* @__PURE__ */ jsxs(
985
1348
  "div",
986
1349
  {
987
- className: `poolse-message-row ${isSelf ? "poolse-message-row--right" : ""}`,
1350
+ ref: rowRef,
1351
+ className: [
1352
+ "poolse-message-row",
1353
+ isSelf ? "poolse-message-row--right" : "",
1354
+ // Modifier mirrors the bubble's groupPosition so the CSS can
1355
+ // tighten the inter-bubble gap inside a cluster (first/middle/
1356
+ // last) and widen it between clusters (standalone or the
1357
+ // first of a new run).
1358
+ `poolse-message-row--${groupPosition}`
1359
+ ].filter(Boolean).join(" "),
988
1360
  "data-message-id": msg.id,
1361
+ "data-actions-open": actionsOpen || void 0,
989
1362
  children: [
990
1363
  editing ? /* @__PURE__ */ jsx(
991
1364
  EditableMessageBubble,
@@ -998,13 +1371,27 @@ function MessageRow({
998
1371
  onCancel: handleCancel
999
1372
  }
1000
1373
  ) : /* @__PURE__ */ jsx(
1001
- MessageBubble,
1374
+ BubbleWithAvatar,
1002
1375
  {
1003
- message: msg,
1004
- currentUserId: meId,
1005
- ...readState ? { readState } : {},
1006
- ...labelFor ? { labelFor } : {},
1007
- ...onQuotedClick ? { onQuotedClick } : {}
1376
+ isSelf,
1377
+ showAvatar,
1378
+ groupPosition,
1379
+ senderName,
1380
+ avatarUrl: senderProfile?.avatarUrl ?? null,
1381
+ children: /* @__PURE__ */ jsx(
1382
+ MessageBubble,
1383
+ {
1384
+ message: msg,
1385
+ currentUserId: meId,
1386
+ groupPosition,
1387
+ maxBodyLength,
1388
+ markdown,
1389
+ showSenderName,
1390
+ ...readState ? { readState } : {},
1391
+ ...labelFor ? { labelFor } : {},
1392
+ ...onQuotedClick ? { onQuotedClick } : {}
1393
+ }
1394
+ )
1008
1395
  }
1009
1396
  ),
1010
1397
  showAttachments && /* @__PURE__ */ jsx("div", { className: `poolse-message-row__attachments ${isSelf ? "is-self" : ""}`, children: msg.attachments.map((att) => /* @__PURE__ */ jsx(AttachmentPreview, { attachment: att }, att.id)) }),
@@ -1034,6 +1421,17 @@ function MessageRow({
1034
1421
  ]
1035
1422
  }
1036
1423
  ),
1424
+ showActions && /* @__PURE__ */ jsx(
1425
+ "button",
1426
+ {
1427
+ type: "button",
1428
+ className: "poolse-message-row__more",
1429
+ "aria-label": "Show message actions",
1430
+ "aria-expanded": actionsOpen,
1431
+ onClick: () => setActionsOpen((o) => !o),
1432
+ children: /* @__PURE__ */ jsx(PoolseIcon, { name: "more-h", size: 16, label: null })
1433
+ }
1434
+ ),
1037
1435
  showActions && /* @__PURE__ */ jsx(
1038
1436
  "div",
1039
1437
  {
@@ -1093,6 +1491,21 @@ function InlineReactions({
1093
1491
  );
1094
1492
  }) });
1095
1493
  }
1494
+ function BubbleWithAvatar({
1495
+ isSelf,
1496
+ showAvatar,
1497
+ groupPosition,
1498
+ senderName,
1499
+ avatarUrl,
1500
+ children
1501
+ }) {
1502
+ if (isSelf || !showAvatar) return /* @__PURE__ */ jsx(Fragment, { children });
1503
+ const isLastOfCluster = groupPosition === "last" || groupPosition === "standalone";
1504
+ return /* @__PURE__ */ jsxs("div", { className: "poolse-bubble-shell", children: [
1505
+ /* @__PURE__ */ jsx("div", { className: "poolse-bubble-shell__avatar", children: isLastOfCluster ? /* @__PURE__ */ jsx(Avatar, { src: avatarUrl, name: senderName, size: "sm" }) : null }),
1506
+ children
1507
+ ] });
1508
+ }
1096
1509
  function ThreadView({
1097
1510
  conversationId,
1098
1511
  rootMessage,
@@ -1105,6 +1518,7 @@ function ThreadView({
1105
1518
  rootMessage.id
1106
1519
  );
1107
1520
  const listRef = useRef(null);
1521
+ const closeBtnRef = useRef(null);
1108
1522
  const lastReplyIdRef = useRef(null);
1109
1523
  useEffect(() => {
1110
1524
  const tail = replies[replies.length - 1];
@@ -1114,59 +1528,157 @@ function ThreadView({
1114
1528
  const el = listRef.current;
1115
1529
  if (el) el.scrollTop = el.scrollHeight;
1116
1530
  }, [replies]);
1531
+ useEffect(() => {
1532
+ closeBtnRef.current?.focus();
1533
+ if (!onClose) return;
1534
+ const onKey = (e) => {
1535
+ if (e.key === "Escape") onClose();
1536
+ };
1537
+ document.addEventListener("keydown", onKey);
1538
+ return () => document.removeEventListener("keydown", onKey);
1539
+ }, [onClose]);
1117
1540
  const renderOne = renderMessage ?? defaultRenderReply;
1118
- return /* @__PURE__ */ jsxs("aside", { className: "poolse-thread", "aria-label": "Thread", children: [
1119
- /* @__PURE__ */ jsxs("header", { className: "poolse-thread__header", children: [
1120
- /* @__PURE__ */ jsx("div", { className: "poolse-thread__title", children: "Thread" }),
1121
- onClose && /* @__PURE__ */ jsx(
1122
- "button",
1123
- {
1124
- type: "button",
1125
- className: "poolse-icon-btn",
1126
- onClick: onClose,
1127
- "aria-label": "Close thread",
1128
- children: /* @__PURE__ */ jsx(PoolseIcon, { name: "close", size: 18, label: null })
1129
- }
1130
- )
1131
- ] }),
1132
- /* @__PURE__ */ jsx("div", { className: "poolse-thread__root", children: /* @__PURE__ */ jsx(MessageBubble, { message: rootMessage, currentUserId: me?.id ?? null }) }),
1133
- /* @__PURE__ */ jsxs("div", { className: "poolse-thread__messages", ref: listRef, children: [
1134
- hasMore && !loading && replies.length > 0 && /* @__PURE__ */ jsx("button", { type: "button", className: "poolse-conversation__load-more", onClick: loadMore, children: "Load older replies" }),
1135
- loading && replies.length === 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-conversation__empty", children: "Loading replies\u2026" }) : replies.length === 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-conversation__empty", children: "No replies yet \u2014 start the thread." }) : (
1136
- // Same Fragment trick as ConversationView so MessageBubble
1137
- // remains the direct flex child for align-self to work.
1138
- replies.map((msg) => /* @__PURE__ */ jsx(Fragment$1, { children: renderOne(msg, me?.id ?? null) }, msg.id))
1139
- ),
1140
- error && /* @__PURE__ */ jsxs("div", { className: "poolse-conversation__empty", children: [
1141
- "Failed to load: ",
1142
- error.message
1143
- ] })
1144
- ] }),
1145
- /* @__PURE__ */ jsx(MessageComposer, { onSend: (body) => sendReply({ body }), placeholder: "Reply in thread\u2026" })
1146
- ] });
1541
+ return /* @__PURE__ */ jsxs(
1542
+ "aside",
1543
+ {
1544
+ className: "poolse-thread",
1545
+ role: "complementary",
1546
+ "aria-label": "Message thread",
1547
+ children: [
1548
+ /* @__PURE__ */ jsxs("header", { className: "poolse-thread__header", children: [
1549
+ /* @__PURE__ */ jsx("div", { className: "poolse-thread__title", children: "Thread" }),
1550
+ onClose && /* @__PURE__ */ jsx(
1551
+ "button",
1552
+ {
1553
+ ref: closeBtnRef,
1554
+ type: "button",
1555
+ className: "poolse-icon-btn",
1556
+ onClick: onClose,
1557
+ "aria-label": "Close thread",
1558
+ children: /* @__PURE__ */ jsx(PoolseIcon, { name: "close", size: 18, label: null })
1559
+ }
1560
+ )
1561
+ ] }),
1562
+ /* @__PURE__ */ jsx("div", { className: "poolse-thread__root", children: /* @__PURE__ */ jsx(MessageBubble, { message: rootMessage, currentUserId: me?.id ?? null }) }),
1563
+ /* @__PURE__ */ jsxs("div", { className: "poolse-thread__messages", ref: listRef, children: [
1564
+ hasMore && !loading && replies.length > 0 && /* @__PURE__ */ jsx("button", { type: "button", className: "poolse-conversation__load-more", onClick: loadMore, children: "Load older replies" }),
1565
+ loading && replies.length === 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-conversation__empty", children: "Loading replies\u2026" }) : replies.length === 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-conversation__empty", children: "No replies yet \u2014 start the thread." }) : (
1566
+ // Same Fragment trick as ConversationView so MessageBubble
1567
+ // remains the direct flex child for align-self to work.
1568
+ replies.map((msg) => /* @__PURE__ */ jsx(Fragment$1, { children: renderOne(msg, me?.id ?? null) }, msg.id))
1569
+ ),
1570
+ error && /* @__PURE__ */ jsxs("div", { className: "poolse-conversation__empty", children: [
1571
+ "Failed to load: ",
1572
+ error.message
1573
+ ] })
1574
+ ] }),
1575
+ /* @__PURE__ */ jsx(MessageComposer, { onSend: (body) => sendReply({ body }), placeholder: "Reply in thread\u2026" })
1576
+ ]
1577
+ }
1578
+ );
1147
1579
  }
1148
1580
  function defaultRenderReply(msg, currentUserId) {
1149
1581
  return /* @__PURE__ */ jsx(MessageBubble, { message: msg, currentUserId });
1150
1582
  }
1151
1583
  function TypingIndicator({ typing, labelFor }) {
1152
1584
  const ids = Array.from(typing);
1153
- if (ids.length === 0) {
1154
- return /* @__PURE__ */ jsx("div", { className: "poolse-typing", "aria-hidden": "true" });
1155
- }
1156
- const label = labelFor ?? ((id) => id.slice(0, 6));
1157
- const names = ids.slice(0, 2).map(label);
1158
- let text;
1159
- if (ids.length === 1) text = `${names[0]} is typing`;
1160
- else if (ids.length === 2) text = `${names[0]} and ${names[1]} are typing`;
1161
- else text = `${ids.length} people are typing`;
1162
- return /* @__PURE__ */ jsxs("div", { className: "poolse-typing", children: [
1163
- /* @__PURE__ */ jsxs("span", { className: "poolse-typing__dots", role: "status", "aria-live": "polite", children: [
1585
+ const isTyping = ids.length > 0;
1586
+ return /* @__PURE__ */ jsxs("div", { className: "poolse-typing", "data-typing": isTyping || void 0, children: [
1587
+ /* @__PURE__ */ jsxs("span", { className: "poolse-typing__dots", "aria-hidden": "true", children: [
1164
1588
  /* @__PURE__ */ jsx("span", { className: "poolse-typing__dot" }),
1165
1589
  /* @__PURE__ */ jsx("span", { className: "poolse-typing__dot" }),
1166
1590
  /* @__PURE__ */ jsx("span", { className: "poolse-typing__dot" })
1167
1591
  ] }),
1168
- /* @__PURE__ */ jsx("span", { className: "poolse-typing__label", children: text })
1592
+ /* @__PURE__ */ jsx(
1593
+ "span",
1594
+ {
1595
+ className: "poolse-typing__label",
1596
+ role: "status",
1597
+ "aria-live": "polite",
1598
+ "aria-atomic": "true",
1599
+ children: isTyping ? /* @__PURE__ */ jsx(TypingLabel, { ids, ...labelFor ? { labelFor } : {} }) : ""
1600
+ }
1601
+ )
1602
+ ] });
1603
+ }
1604
+ function TypingLabel({ ids, labelFor }) {
1605
+ const id1 = ids[0] ?? null;
1606
+ const id2 = ids[1] ?? null;
1607
+ const name1 = useDisplayName(id1, labelFor);
1608
+ const name2 = useDisplayName(id2, labelFor);
1609
+ if (ids.length === 1) return /* @__PURE__ */ jsxs(Fragment, { children: [
1610
+ name1,
1611
+ " is typing"
1169
1612
  ] });
1613
+ if (ids.length === 2) {
1614
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1615
+ name1,
1616
+ " and ",
1617
+ name2,
1618
+ " are typing"
1619
+ ] });
1620
+ }
1621
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
1622
+ ids.length,
1623
+ " people are typing"
1624
+ ] });
1625
+ }
1626
+ function UploadQueueStrip({ items, onCancel, onDismiss }) {
1627
+ if (items.length === 0) return null;
1628
+ return /* @__PURE__ */ jsx("div", { className: "poolse-upload-strip", role: "status", "aria-live": "polite", children: items.map((item) => /* @__PURE__ */ jsx(
1629
+ UploadChip,
1630
+ {
1631
+ item,
1632
+ onCancel: () => onCancel(item.localId),
1633
+ onDismiss: () => onDismiss(item.localId)
1634
+ },
1635
+ item.localId
1636
+ )) });
1637
+ }
1638
+ function UploadChip({
1639
+ item,
1640
+ onCancel,
1641
+ onDismiss
1642
+ }) {
1643
+ const pct = item.byteSize > 0 ? Math.min(100, Math.round(item.loaded / item.byteSize * 100)) : 0;
1644
+ const isError = item.status === "error";
1645
+ const isInFlight = item.status === "pending" || item.status === "uploading";
1646
+ return /* @__PURE__ */ jsxs(
1647
+ "div",
1648
+ {
1649
+ className: `poolse-upload-chip poolse-upload-chip--${item.status}`,
1650
+ "data-status": item.status,
1651
+ children: [
1652
+ /* @__PURE__ */ jsx("div", { className: "poolse-upload-chip__icon", "aria-hidden": "true", children: /* @__PURE__ */ jsx(PoolseIcon, { name: isError ? "attachment" : "attachment", size: 18, label: null }) }),
1653
+ /* @__PURE__ */ jsxs("div", { className: "poolse-upload-chip__body", children: [
1654
+ /* @__PURE__ */ jsx("div", { className: "poolse-upload-chip__filename", title: item.filename, children: item.filename }),
1655
+ isError ? /* @__PURE__ */ jsx("div", { className: "poolse-upload-chip__error", children: item.error?.message ?? "Upload failed" }) : /* @__PURE__ */ jsx(
1656
+ "div",
1657
+ {
1658
+ className: "poolse-upload-chip__bar",
1659
+ role: "progressbar",
1660
+ "aria-valuemin": 0,
1661
+ "aria-valuemax": 100,
1662
+ "aria-valuenow": pct,
1663
+ "aria-label": `Uploading ${item.filename}`,
1664
+ children: /* @__PURE__ */ jsx("div", { className: "poolse-upload-chip__bar-fill", style: { width: `${pct}%` } })
1665
+ }
1666
+ )
1667
+ ] }),
1668
+ /* @__PURE__ */ jsx(
1669
+ "button",
1670
+ {
1671
+ type: "button",
1672
+ className: "poolse-upload-chip__action",
1673
+ onClick: isInFlight ? onCancel : onDismiss,
1674
+ "aria-label": isInFlight ? `Cancel upload of ${item.filename}` : `Dismiss ${item.filename}`,
1675
+ title: isInFlight ? "Cancel" : "Dismiss",
1676
+ children: "\xD7"
1677
+ }
1678
+ )
1679
+ ]
1680
+ }
1681
+ );
1170
1682
  }
1171
1683
  var TRUE = true;
1172
1684
  function ConversationView({
@@ -1182,6 +1694,13 @@ function ConversationView({
1182
1694
  threads = TRUE,
1183
1695
  quotations = TRUE,
1184
1696
  readReceipts = TRUE,
1697
+ markdown = TRUE,
1698
+ maxBodyLength = 200,
1699
+ grouping = TRUE,
1700
+ groupingWindowMs = 5 * 60 * 1e3,
1701
+ daySeparators = TRUE,
1702
+ senderLabels = "auto",
1703
+ avatars = "auto",
1185
1704
  onMarkedRead
1186
1705
  }) {
1187
1706
  usePoolseFonts(loadFonts);
@@ -1199,8 +1718,12 @@ function ConversationView({
1199
1718
  } = useMessages(conversationId);
1200
1719
  const { typing, signalTyping } = useTyping(conversationId);
1201
1720
  const status = useRealtimeStatus();
1202
- const membersOn = mentions || readReceipts;
1721
+ const wantsMemberCount = senderLabels === "auto" || avatars === "auto";
1722
+ const membersOn = mentions || readReceipts || wantsMemberCount;
1203
1723
  const { members } = useMembers(membersOn ? conversationId : "");
1724
+ const isGroupChat = members.length > 2;
1725
+ const showSenderLabelsResolved = senderLabels === "always" || senderLabels === "auto" && isGroupChat;
1726
+ const showAvatarsResolved = avatars === "always" || avatars === "auto" && isGroupChat;
1204
1727
  const listRef = useRef(null);
1205
1728
  const lastMessageIdRef = useRef(null);
1206
1729
  const bottomSentinelRef = useRef(null);
@@ -1295,20 +1818,56 @@ function ConversationView({
1295
1818
  el.classList.add("poolse-message-row--highlight");
1296
1819
  setTimeout(() => el.classList.remove("poolse-message-row--highlight"), 1600);
1297
1820
  };
1298
- const { upload, uploading } = useAttachmentUpload();
1299
- const onPickFile = async (file) => {
1821
+ const { queue: uploadQueue, uploadAll, cancel: cancelUpload, remove: removeUpload, uploading } = useAttachmentUpload();
1822
+ const visibleUploads = uploadQueue.filter(
1823
+ (it) => it.status === "pending" || it.status === "uploading" || it.status === "error"
1824
+ );
1825
+ const onPickFiles = async (files) => {
1826
+ if (files.length === 0) return;
1300
1827
  try {
1301
- const att = await upload({
1302
- body: file,
1303
- contentType: file.type || "application/octet-stream",
1304
- byteSize: file.size,
1305
- filename: file.name
1306
- });
1307
- await send({ body: "", attachment_ids: [att.id] });
1308
- } catch (err) {
1309
- console.error("attachment upload failed:", err);
1828
+ const atts = await uploadAll(
1829
+ files.map((f) => ({
1830
+ body: f,
1831
+ contentType: f.type || "application/octet-stream",
1832
+ byteSize: f.size,
1833
+ filename: f.name
1834
+ }))
1835
+ );
1836
+ await send({ body: "", attachment_ids: atts.map((a) => a.id) });
1837
+ for (const it of uploadQueue) {
1838
+ if (it.status === "ready") removeUpload(it.localId);
1839
+ }
1840
+ } catch {
1310
1841
  }
1311
1842
  };
1843
+ const [dragActive, setDragActive] = useState(false);
1844
+ const dragDepthRef = useRef(0);
1845
+ const isFileDrag = (e) => Array.from(e.dataTransfer?.types ?? []).includes("Files");
1846
+ const onDragEnter = (e) => {
1847
+ if (!attachments || !isFileDrag(e)) return;
1848
+ e.preventDefault();
1849
+ dragDepthRef.current += 1;
1850
+ setDragActive(true);
1851
+ };
1852
+ const onDragOver = (e) => {
1853
+ if (!attachments || !isFileDrag(e)) return;
1854
+ e.preventDefault();
1855
+ if (e.dataTransfer) e.dataTransfer.dropEffect = "copy";
1856
+ };
1857
+ const onDragLeave = (e) => {
1858
+ if (!attachments || !isFileDrag(e)) return;
1859
+ e.preventDefault();
1860
+ dragDepthRef.current = Math.max(0, dragDepthRef.current - 1);
1861
+ if (dragDepthRef.current === 0) setDragActive(false);
1862
+ };
1863
+ const onDrop = (e) => {
1864
+ if (!attachments || !isFileDrag(e)) return;
1865
+ e.preventDefault();
1866
+ dragDepthRef.current = 0;
1867
+ setDragActive(false);
1868
+ const files = Array.from(e.dataTransfer?.files ?? []);
1869
+ if (files.length > 0) void onPickFiles(files);
1870
+ };
1312
1871
  const onSendBody = async (body, opts) => {
1313
1872
  await send({
1314
1873
  body,
@@ -1339,87 +1898,141 @@ function ConversationView({
1339
1898
  }
1340
1899
  );
1341
1900
  return /* @__PURE__ */ jsxs("div", { className: "poolse-conversation-shell", children: [
1342
- /* @__PURE__ */ jsxs("div", { className: "poolse-conversation", children: [
1343
- status !== "connected" && status !== "idle" && /* @__PURE__ */ jsxs("div", { className: "poolse-conversation__status", children: [
1344
- status === "connecting" && "Connecting\u2026",
1345
- status === "reconnecting" && "Reconnecting\u2026",
1346
- status === "closed" && "Disconnected"
1347
- ] }),
1348
- /* @__PURE__ */ jsxs("div", { className: "poolse-conversation__messages", ref: listRef, children: [
1349
- hasMore && !loading && /* @__PURE__ */ jsx("button", { type: "button", className: "poolse-conversation__load-more", onClick: loadMore, children: "Load older messages" }),
1350
- loading && messages.length === 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-conversation__empty", children: "Loading\u2026" }) : messages.length === 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-conversation__empty", children: emptyState ?? "No messages yet." }) : messages.map((msg) => {
1351
- if (renderMessage) {
1352
- return /* @__PURE__ */ jsx(Fragment$1, { children: renderMessage(msg, me?.id ?? null) }, msg.id);
1353
- }
1354
- const enriched = quotations && msg.quoted_message_id && !msg.quoted_message ? (() => {
1355
- const original = messages.find((m) => m.id === msg.quoted_message_id);
1356
- if (!original) return msg;
1357
- return {
1358
- ...msg,
1359
- quoted_message: {
1360
- id: original.id,
1361
- sender_id: original.sender_id,
1362
- body: original.body,
1363
- deleted_at: original.deleted_at,
1364
- inserted_at: original.inserted_at
1365
- }
1366
- };
1367
- })() : msg;
1368
- const isSelf = me !== null && msg.sender_id === me.id;
1369
- const readState = readReceipts && isSelf && maxReadByOthers !== null ? maxReadByOthers >= msg.sequence ? "read" : "sent" : void 0;
1370
- return /* @__PURE__ */ jsx(
1371
- MessageRow,
1901
+ /* @__PURE__ */ jsxs(
1902
+ "div",
1903
+ {
1904
+ className: `poolse-conversation${dragActive ? " is-drag-active" : ""}`,
1905
+ onDragEnter,
1906
+ onDragOver,
1907
+ onDragLeave,
1908
+ onDrop,
1909
+ children: [
1910
+ status !== "connected" && status !== "idle" && /* @__PURE__ */ jsxs(
1911
+ "div",
1372
1912
  {
1373
- msg: enriched,
1374
- meId: me?.id ?? null,
1375
- reactions,
1376
- attachments,
1377
- actions,
1378
- threads,
1379
- quotations,
1380
- ...readState ? { readState } : {},
1381
- ...labelFor ? { labelFor } : {},
1382
- editing: editingId === msg.id,
1383
- onStartEdit: () => setEditingId(msg.id),
1384
- onCancelEdit: () => setEditingId(null),
1385
- onSaveEdit: async (body) => {
1386
- await edit(msg.id, body);
1387
- setEditingId(null);
1388
- },
1389
- onDelete: () => void deleteMsg(msg.id),
1390
- onOpenThread: () => setThreadRootId(msg.id),
1391
- onQuote: () => setReplyingTo(msg),
1392
- onQuotedClick: scrollToOriginal
1393
- },
1394
- msg.id
1395
- );
1396
- }),
1397
- error && /* @__PURE__ */ jsxs("div", { className: "poolse-conversation__empty", children: [
1398
- "Failed to load: ",
1399
- error.message
1400
- ] }),
1401
- /* @__PURE__ */ jsx("div", { ref: bottomSentinelRef, "aria-hidden": "true", style: { height: 1 } })
1402
- ] }),
1403
- !atBottom && newCountWhileAway > 0 && /* @__PURE__ */ jsxs(
1404
- "button",
1405
- {
1406
- type: "button",
1407
- className: "poolse-conversation__scroll-to-new",
1408
- onClick: scrollToBottom,
1409
- children: [
1410
- "\u2193 ",
1411
- newCountWhileAway,
1412
- " new ",
1413
- newCountWhileAway === 1 ? "message" : "messages"
1414
- ]
1415
- }
1416
- ),
1417
- /* @__PURE__ */ jsx(TypingIndicator, { typing, ...labelFor ? { labelFor } : {} }),
1418
- /* @__PURE__ */ jsxs("div", { className: "poolse-conversation__composer-row", children: [
1419
- attachments && /* @__PURE__ */ jsx(AttachmentPickerButton, { onPick: onPickFile, disabled: uploading }),
1420
- /* @__PURE__ */ jsx("div", { className: "poolse-conversation__composer-flex", children: Composer })
1421
- ] })
1422
- ] }),
1913
+ className: "poolse-conversation__status",
1914
+ role: "status",
1915
+ "aria-live": "polite",
1916
+ "aria-atomic": "true",
1917
+ children: [
1918
+ status === "connecting" && "Connecting\u2026",
1919
+ status === "reconnecting" && "Reconnecting\u2026",
1920
+ status === "closed" && "Disconnected"
1921
+ ]
1922
+ }
1923
+ ),
1924
+ /* @__PURE__ */ jsxs(
1925
+ "div",
1926
+ {
1927
+ className: "poolse-conversation__messages",
1928
+ ref: listRef,
1929
+ role: "log",
1930
+ "aria-label": "Conversation messages",
1931
+ "aria-live": "polite",
1932
+ "aria-relevant": "additions",
1933
+ children: [
1934
+ hasMore && !loading && /* @__PURE__ */ jsx("button", { type: "button", className: "poolse-conversation__load-more", onClick: loadMore, children: "Load older messages" }),
1935
+ loading && messages.length === 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-conversation__empty", children: "Loading\u2026" }) : messages.length === 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-conversation__empty", children: emptyState ?? "No messages yet." }) : messages.map((msg, idx) => {
1936
+ if (renderMessage) {
1937
+ return /* @__PURE__ */ jsx(Fragment$1, { children: renderMessage(msg, me?.id ?? null) }, msg.id);
1938
+ }
1939
+ const prev = idx > 0 ? messages[idx - 1] ?? null : null;
1940
+ const next = idx < messages.length - 1 ? messages[idx + 1] ?? null : null;
1941
+ const groupPosition = grouping ? computeGroupPosition(msg, prev, next, groupingWindowMs) : "standalone";
1942
+ const showDaySeparator = daySeparators && (prev === null || !sameDay(msg.inserted_at, prev.inserted_at));
1943
+ const enriched = quotations && msg.quoted_message_id && !msg.quoted_message ? (() => {
1944
+ const original = messages.find((m) => m.id === msg.quoted_message_id);
1945
+ if (!original) return msg;
1946
+ return {
1947
+ ...msg,
1948
+ quoted_message: {
1949
+ id: original.id,
1950
+ sender_id: original.sender_id,
1951
+ body: original.body,
1952
+ deleted_at: original.deleted_at,
1953
+ inserted_at: original.inserted_at
1954
+ }
1955
+ };
1956
+ })() : msg;
1957
+ const isSelf = me !== null && msg.sender_id === me.id;
1958
+ const readState = readReceipts && isSelf && maxReadByOthers !== null ? maxReadByOthers >= msg.sequence ? "read" : "sent" : void 0;
1959
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [
1960
+ showDaySeparator && /* @__PURE__ */ jsx("div", { className: "poolse-day-separator", "aria-hidden": "false", children: /* @__PURE__ */ jsx("span", { children: formatDayLabel(msg.inserted_at) }) }),
1961
+ /* @__PURE__ */ jsx(
1962
+ MessageRow,
1963
+ {
1964
+ msg: enriched,
1965
+ meId: me?.id ?? null,
1966
+ reactions,
1967
+ attachments,
1968
+ actions,
1969
+ threads,
1970
+ quotations,
1971
+ groupPosition,
1972
+ maxBodyLength,
1973
+ markdown,
1974
+ showSenderName: showSenderLabelsResolved,
1975
+ showAvatar: showAvatarsResolved,
1976
+ ...readState ? { readState } : {},
1977
+ ...labelFor ? { labelFor } : {},
1978
+ editing: editingId === msg.id,
1979
+ onStartEdit: () => setEditingId(msg.id),
1980
+ onCancelEdit: () => setEditingId(null),
1981
+ onSaveEdit: async (body) => {
1982
+ await edit(msg.id, body);
1983
+ setEditingId(null);
1984
+ },
1985
+ onDelete: () => void deleteMsg(msg.id),
1986
+ onOpenThread: () => setThreadRootId(msg.id),
1987
+ onQuote: () => setReplyingTo(msg),
1988
+ onQuotedClick: scrollToOriginal
1989
+ }
1990
+ )
1991
+ ] }, msg.id);
1992
+ }),
1993
+ error && /* @__PURE__ */ jsxs("div", { className: "poolse-conversation__empty", children: [
1994
+ "Failed to load: ",
1995
+ error.message
1996
+ ] }),
1997
+ /* @__PURE__ */ jsx("div", { ref: bottomSentinelRef, "aria-hidden": "true", style: { height: 1 } })
1998
+ ]
1999
+ }
2000
+ ),
2001
+ !atBottom && newCountWhileAway > 0 && /* @__PURE__ */ jsxs(
2002
+ "button",
2003
+ {
2004
+ type: "button",
2005
+ className: "poolse-conversation__scroll-to-new",
2006
+ onClick: scrollToBottom,
2007
+ children: [
2008
+ "\u2193 ",
2009
+ newCountWhileAway,
2010
+ " new ",
2011
+ newCountWhileAway === 1 ? "message" : "messages"
2012
+ ]
2013
+ }
2014
+ ),
2015
+ /* @__PURE__ */ jsx(TypingIndicator, { typing, ...labelFor ? { labelFor } : {} }),
2016
+ attachments && /* @__PURE__ */ jsx(
2017
+ UploadQueueStrip,
2018
+ {
2019
+ items: visibleUploads,
2020
+ onCancel: cancelUpload,
2021
+ onDismiss: removeUpload
2022
+ }
2023
+ ),
2024
+ /* @__PURE__ */ jsxs("div", { className: "poolse-conversation__composer-row", children: [
2025
+ attachments && /* @__PURE__ */ jsx(AttachmentPickerButton, { onPick: onPickFiles, disabled: uploading }),
2026
+ /* @__PURE__ */ jsx("div", { className: "poolse-conversation__composer-flex", children: Composer })
2027
+ ] }),
2028
+ dragActive && /* @__PURE__ */ jsx("div", { className: "poolse-conversation__drop-overlay", "aria-hidden": "true", children: /* @__PURE__ */ jsxs("div", { className: "poolse-conversation__drop-overlay-inner", children: [
2029
+ /* @__PURE__ */ jsx(PoolseIcon, { name: "attachment", size: 40, label: null }),
2030
+ /* @__PURE__ */ jsx("div", { className: "poolse-conversation__drop-overlay-title", children: "Drop files to upload" }),
2031
+ /* @__PURE__ */ jsx("div", { className: "poolse-conversation__drop-overlay-hint", children: "They'll be sent in one message" })
2032
+ ] }) })
2033
+ ]
2034
+ }
2035
+ ),
1423
2036
  threads && threadRoot && /* @__PURE__ */ jsx("div", { className: "poolse-conversation-shell__thread", children: /* @__PURE__ */ jsx(
1424
2037
  ThreadView,
1425
2038
  {
@@ -1441,10 +2054,11 @@ function AttachmentPickerButton({
1441
2054
  {
1442
2055
  ref: inputRef,
1443
2056
  type: "file",
2057
+ multiple: true,
1444
2058
  className: "poolse-attach-input",
1445
2059
  onChange: (e) => {
1446
- const f = e.target.files?.[0];
1447
- if (f) onPick(f);
2060
+ const files = Array.from(e.target.files ?? []);
2061
+ if (files.length > 0) onPick(files);
1448
2062
  e.target.value = "";
1449
2063
  }
1450
2064
  }
@@ -1456,31 +2070,13 @@ function AttachmentPickerButton({
1456
2070
  className: "poolse-attach-btn",
1457
2071
  onClick: () => inputRef.current?.click(),
1458
2072
  disabled,
1459
- "aria-label": "Attach file",
1460
- title: "Attach file",
2073
+ "aria-label": "Attach files",
2074
+ title: "Attach files",
1461
2075
  children: /* @__PURE__ */ jsx(PoolseIcon, { name: "attachment", size: 20, label: null })
1462
2076
  }
1463
2077
  )
1464
2078
  ] });
1465
2079
  }
1466
- function Avatar({ src, name, online, size = "md", className }) {
1467
- const initials = computeInitials(name);
1468
- const classes = [
1469
- "poolse-avatar",
1470
- size === "sm" ? "poolse-avatar--sm" : null,
1471
- size === "lg" ? "poolse-avatar--lg" : null,
1472
- className
1473
- ].filter(Boolean).join(" ");
1474
- return /* @__PURE__ */ jsxs("span", { className: classes, "aria-label": name ?? "avatar", role: "img", children: [
1475
- src ? /* @__PURE__ */ jsx("img", { src, alt: name ?? "" }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: initials }),
1476
- online ? /* @__PURE__ */ jsx("span", { className: "poolse-avatar__presence", "aria-hidden": "true" }) : null
1477
- ] });
1478
- }
1479
- function computeInitials(name) {
1480
- if (!name) return "?";
1481
- const parts = name.trim().split(/\s+/).slice(0, 2);
1482
- return parts.map((p) => p.charAt(0).toUpperCase()).join("").slice(0, 2) || "?";
1483
- }
1484
2080
  function ConversationList({
1485
2081
  selectedId,
1486
2082
  onSelect,
@@ -1588,19 +2184,18 @@ function MemberList({
1588
2184
  if (members.length === 0) {
1589
2185
  return /* @__PURE__ */ jsx("div", { className: "poolse-list poolse-list--placeholder", children: emptyState ?? "No members yet." });
1590
2186
  }
1591
- const label = labelFor ?? ((id) => id.slice(0, 8));
1592
2187
  return /* @__PURE__ */ jsx("ul", { className: "poolse-list", role: "list", "aria-label": "Members", children: members.map((m) => {
1593
2188
  const content = renderItem ? renderItem(m) : /* @__PURE__ */ jsx(
1594
2189
  DefaultMemberRow,
1595
2190
  {
1596
2191
  membership: m,
1597
- name: label(m.user_id),
1598
2192
  avatarUrl: avatarFor?.(m.user_id) ?? null,
1599
2193
  online: onlineUserIds?.has(m.user_id) ?? false,
1600
2194
  removable: canRemove?.(m) ?? false,
1601
2195
  onRemove: () => {
1602
2196
  void removeMember(m.user_id);
1603
- }
2197
+ },
2198
+ ...labelFor ? { labelFor } : {}
1604
2199
  }
1605
2200
  );
1606
2201
  return /* @__PURE__ */ jsx("li", { className: "poolse-list__item", children: content }, m.id);
@@ -1608,12 +2203,13 @@ function MemberList({
1608
2203
  }
1609
2204
  function DefaultMemberRow({
1610
2205
  membership,
1611
- name,
1612
2206
  avatarUrl,
1613
2207
  online,
1614
2208
  removable,
1615
- onRemove
2209
+ onRemove,
2210
+ labelFor
1616
2211
  }) {
2212
+ const name = useDisplayName(membership.user_id, labelFor);
1617
2213
  return /* @__PURE__ */ jsxs("div", { className: "poolse-member-row", children: [
1618
2214
  /* @__PURE__ */ jsx(Avatar, { src: avatarUrl, name, online, size: "md" }),
1619
2215
  /* @__PURE__ */ jsxs("div", { className: "poolse-member-row__body", children: [
@@ -1748,6 +2344,6 @@ function PoolseLogo({
1748
2344
  );
1749
2345
  }
1750
2346
 
1751
- export { AttachmentPreview, Avatar, ConversationList, ConversationView, EditableMessageBubble, MemberList, MentionInput, MessageActions, MessageBubble, MessageComposer, PoolseFonts, PoolseIcon, PoolseLogo, ReactionPicker, ReactionStrip, ThreadView, TypingIndicator, usePoolseFonts };
2347
+ export { AttachmentPreview, Avatar, ConversationList, ConversationView, EditableMessageBubble, MemberList, MentionInput, MessageActions, MessageBubble, MessageComposer, PoolseFonts, PoolseIcon, PoolseLogo, ReactionPicker, ReactionStrip, ThreadView, TypingIndicator, UploadQueueStrip, UserName, useDisplayName, usePoolseFonts };
1752
2348
  //# sourceMappingURL=index.js.map
1753
2349
  //# sourceMappingURL=index.js.map