@poolse/react-ui 0.2.0-alpha.7 → 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,88 @@ 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
  }) : "";
925
+ const showQuoteCard = message.quoted_message !== void 0 && message.quoted_message !== null ? "full" : message.quoted_message_id ? "placeholder" : null;
655
926
  return /* @__PURE__ */ jsxs("div", { className, children: [
656
- message.quoted_message && /* @__PURE__ */ jsx(
927
+ renderSenderName && /* @__PURE__ */ jsx("div", { className: "poolse-message__sender", style: { color: senderColorHex }, children: senderName }),
928
+ showQuoteCard === "full" && /* @__PURE__ */ jsx(
657
929
  QuotedCard,
658
930
  {
659
931
  quoted: message.quoted_message,
@@ -662,7 +934,45 @@ function MessageBubble({
662
934
  ...onQuotedClick ? { onClick: onQuotedClick } : {}
663
935
  }
664
936
  ),
665
- message.deleted_at ? /* @__PURE__ */ jsx("span", { className: "poolse-message__body--deleted", children: "[deleted]" }) : /* @__PURE__ */ jsx("span", { children: message.body ?? "" }),
937
+ showQuoteCard === "placeholder" && /* @__PURE__ */ jsx(QuotedPlaceholder, { isSelf, quotedMessageId: message.quoted_message_id }),
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
+ ] }),
666
976
  /* @__PURE__ */ jsxs("span", { className: "poolse-message__meta", children: [
667
977
  /* @__PURE__ */ jsx("span", { children: time }),
668
978
  message.edited_at ? /* @__PURE__ */ jsx("span", { children: " \xB7 edited" }) : null,
@@ -677,6 +987,22 @@ function MessageBubble({
677
987
  ] })
678
988
  ] });
679
989
  }
990
+ function QuotedPlaceholder({
991
+ isSelf,
992
+ quotedMessageId: _quotedMessageId
993
+ }) {
994
+ return /* @__PURE__ */ jsxs(
995
+ "div",
996
+ {
997
+ className: `poolse-quote poolse-quote--placeholder ${isSelf ? "poolse-quote--self" : "poolse-quote--other"}`,
998
+ "aria-label": "Quoted message",
999
+ children: [
1000
+ /* @__PURE__ */ jsx("span", { className: "poolse-quote__sender", children: "Replying to a message" }),
1001
+ /* @__PURE__ */ jsx("span", { className: "poolse-quote__body", children: "Loading preview\u2026" })
1002
+ ]
1003
+ }
1004
+ );
1005
+ }
680
1006
  function QuotedCard({
681
1007
  quoted,
682
1008
  isSelf,
@@ -854,19 +1180,53 @@ function ReactionPicker({
854
1180
  onPick,
855
1181
  onClose
856
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
+ };
857
1216
  return /* @__PURE__ */ jsx(
858
1217
  "div",
859
1218
  {
1219
+ ref: rootRef,
860
1220
  className: "poolse-reaction-picker",
861
1221
  role: "menu",
1222
+ "aria-label": "Pick a reaction",
862
1223
  style: { position: "absolute", bottom: "100%", left: 0, marginBottom: 6 },
863
- onKeyDown: (e) => {
864
- if (e.key === "Escape") onClose?.();
865
- },
1224
+ onKeyDown: onKey,
866
1225
  children: COMMON_EMOJIS.map((e) => /* @__PURE__ */ jsx(
867
1226
  "button",
868
1227
  {
869
1228
  type: "button",
1229
+ role: "menuitem",
870
1230
  className: "poolse-reaction-picker__btn",
871
1231
  onClick: () => onPick(e),
872
1232
  "aria-label": `React with ${e}`,
@@ -948,8 +1308,16 @@ function MessageRow({
948
1308
  onOpenThread,
949
1309
  onQuote,
950
1310
  labelFor,
951
- onQuotedClick
1311
+ onQuotedClick,
1312
+ groupPosition = "standalone",
1313
+ maxBodyLength = 0,
1314
+ markdown = false,
1315
+ showSenderName = false,
1316
+ showAvatar = false
952
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;
953
1321
  const isSelf = meId !== null && msg.sender_id === meId;
954
1322
  const reactionsHook = useReactions(reactions ? msg.id : "", {
955
1323
  conversationId: msg.conversation_id,
@@ -963,80 +1331,135 @@ function MessageRow({
963
1331
  const showThreadPill = threads && !msg.deleted_at && !msg.thread_root_id && replyCount > 0;
964
1332
  const handleSave = onSaveEdit ?? (async () => void 0);
965
1333
  const handleCancel = onCancelEdit ?? (() => void 0);
966
- return /* @__PURE__ */ jsxs("div", { className: `poolse-message-row ${isSelf ? "poolse-message-row--right" : ""}`, children: [
967
- editing ? /* @__PURE__ */ jsx(
968
- EditableMessageBubble,
969
- {
970
- message: msg,
971
- currentUserId: meId,
972
- ...readState ? { readState } : {},
973
- editing: true,
974
- onSave: handleSave,
975
- onCancel: handleCancel
976
- }
977
- ) : /* @__PURE__ */ jsx(
978
- MessageBubble,
979
- {
980
- message: msg,
981
- currentUserId: meId,
982
- ...readState ? { readState } : {},
983
- ...labelFor ? { labelFor } : {},
984
- ...onQuotedClick ? { onQuotedClick } : {}
985
- }
986
- ),
987
- showAttachments && /* @__PURE__ */ jsx("div", { className: `poolse-message-row__attachments ${isSelf ? "is-self" : ""}`, children: msg.attachments.map((att) => /* @__PURE__ */ jsx(AttachmentPreview, { attachment: att }, att.id)) }),
988
- showReactions && /* @__PURE__ */ jsx("div", { className: `poolse-message-row__reactions ${isSelf ? "is-self" : ""}`, children: /* @__PURE__ */ jsx(
989
- InlineReactions,
990
- {
991
- reactions: reactionsHook.reactions,
992
- currentUserId: meId,
993
- onAdd: (e) => void reactionsHook.addReaction(e),
994
- onRemove: (e) => void reactionsHook.removeReaction(e)
995
- }
996
- ) }),
997
- showThreadPill && /* @__PURE__ */ jsxs(
998
- "button",
999
- {
1000
- type: "button",
1001
- className: `poolse-thread-pill ${isSelf ? "poolse-thread-pill--right" : "poolse-thread-pill--left"}`,
1002
- onClick: onOpenThread,
1003
- "aria-label": `View ${replyCount} ${replyCount === 1 ? "reply" : "replies"}`,
1004
- children: [
1005
- /* @__PURE__ */ jsx(PoolseIcon, { name: "messages", size: 12, label: null }),
1006
- /* @__PURE__ */ jsxs("span", { children: [
1007
- replyCount,
1008
- " ",
1009
- replyCount === 1 ? "reply" : "replies"
1010
- ] })
1011
- ]
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);
1012
1342
  }
1013
- ),
1014
- showActions && /* @__PURE__ */ jsx(
1015
- "div",
1016
- {
1017
- className: `poolse-message-row__actions ${isSelf ? "poolse-message-row__actions--right" : "poolse-message-row__actions--left"}`,
1018
- children: /* @__PURE__ */ jsx(
1019
- MessageActions,
1343
+ };
1344
+ document.addEventListener("pointerdown", onDown);
1345
+ return () => document.removeEventListener("pointerdown", onDown);
1346
+ }, [actionsOpen]);
1347
+ return /* @__PURE__ */ jsxs(
1348
+ "div",
1349
+ {
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(" "),
1360
+ "data-message-id": msg.id,
1361
+ "data-actions-open": actionsOpen || void 0,
1362
+ children: [
1363
+ editing ? /* @__PURE__ */ jsx(
1364
+ EditableMessageBubble,
1020
1365
  {
1021
- ...reactions ? {
1022
- onReact: (emoji) => {
1023
- void reactionsHook.addReaction(emoji);
1366
+ message: msg,
1367
+ currentUserId: meId,
1368
+ ...readState ? { readState } : {},
1369
+ editing: true,
1370
+ onSave: handleSave,
1371
+ onCancel: handleCancel
1372
+ }
1373
+ ) : /* @__PURE__ */ jsx(
1374
+ BubbleWithAvatar,
1375
+ {
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 } : {}
1024
1393
  }
1025
- } : {},
1026
- ...threads && onOpenThread ? { onReply: onOpenThread } : {},
1027
- ...quotations && onQuote ? { onQuote } : {},
1028
- ...msg.body ? {
1029
- onCopy: () => {
1030
- void navigator?.clipboard?.writeText(msg.body ?? "").catch(() => void 0);
1394
+ )
1395
+ }
1396
+ ),
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)) }),
1398
+ showReactions && /* @__PURE__ */ jsx("div", { className: `poolse-message-row__reactions ${isSelf ? "is-self" : ""}`, children: /* @__PURE__ */ jsx(
1399
+ InlineReactions,
1400
+ {
1401
+ reactions: reactionsHook.reactions,
1402
+ currentUserId: meId,
1403
+ onAdd: (e) => void reactionsHook.addReaction(e),
1404
+ onRemove: (e) => void reactionsHook.removeReaction(e)
1405
+ }
1406
+ ) }),
1407
+ showThreadPill && /* @__PURE__ */ jsxs(
1408
+ "button",
1409
+ {
1410
+ type: "button",
1411
+ className: `poolse-thread-pill ${isSelf ? "poolse-thread-pill--right" : "poolse-thread-pill--left"}`,
1412
+ onClick: onOpenThread,
1413
+ "aria-label": `View ${replyCount} ${replyCount === 1 ? "reply" : "replies"}`,
1414
+ children: [
1415
+ /* @__PURE__ */ jsx(PoolseIcon, { name: "messages", size: 12, label: null }),
1416
+ /* @__PURE__ */ jsxs("span", { children: [
1417
+ replyCount,
1418
+ " ",
1419
+ replyCount === 1 ? "reply" : "replies"
1420
+ ] })
1421
+ ]
1422
+ }
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
+ ),
1435
+ showActions && /* @__PURE__ */ jsx(
1436
+ "div",
1437
+ {
1438
+ className: `poolse-message-row__actions ${isSelf ? "poolse-message-row__actions--right" : "poolse-message-row__actions--left"}`,
1439
+ children: /* @__PURE__ */ jsx(
1440
+ MessageActions,
1441
+ {
1442
+ ...reactions ? {
1443
+ onReact: (emoji) => {
1444
+ void reactionsHook.addReaction(emoji);
1445
+ }
1446
+ } : {},
1447
+ ...threads && onOpenThread ? { onReply: onOpenThread } : {},
1448
+ ...quotations && onQuote ? { onQuote } : {},
1449
+ ...msg.body ? {
1450
+ onCopy: () => {
1451
+ void navigator?.clipboard?.writeText(msg.body ?? "").catch(() => void 0);
1452
+ }
1453
+ } : {},
1454
+ ...isSelf && onStartEdit ? { onEdit: onStartEdit } : {},
1455
+ ...isSelf && onDelete ? { onDelete } : {}
1031
1456
  }
1032
- } : {},
1033
- ...isSelf && onStartEdit ? { onEdit: onStartEdit } : {},
1034
- ...isSelf && onDelete ? { onDelete } : {}
1457
+ )
1035
1458
  }
1036
1459
  )
1037
- }
1038
- )
1039
- ] });
1460
+ ]
1461
+ }
1462
+ );
1040
1463
  }
1041
1464
  function InlineReactions({
1042
1465
  reactions,
@@ -1068,6 +1491,21 @@ function InlineReactions({
1068
1491
  );
1069
1492
  }) });
1070
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
+ }
1071
1509
  function ThreadView({
1072
1510
  conversationId,
1073
1511
  rootMessage,
@@ -1080,6 +1518,7 @@ function ThreadView({
1080
1518
  rootMessage.id
1081
1519
  );
1082
1520
  const listRef = useRef(null);
1521
+ const closeBtnRef = useRef(null);
1083
1522
  const lastReplyIdRef = useRef(null);
1084
1523
  useEffect(() => {
1085
1524
  const tail = replies[replies.length - 1];
@@ -1089,60 +1528,158 @@ function ThreadView({
1089
1528
  const el = listRef.current;
1090
1529
  if (el) el.scrollTop = el.scrollHeight;
1091
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]);
1092
1540
  const renderOne = renderMessage ?? defaultRenderReply;
1093
- return /* @__PURE__ */ jsxs("aside", { className: "poolse-thread", "aria-label": "Thread", children: [
1094
- /* @__PURE__ */ jsxs("header", { className: "poolse-thread__header", children: [
1095
- /* @__PURE__ */ jsx("div", { className: "poolse-thread__title", children: "Thread" }),
1096
- onClose && /* @__PURE__ */ jsx(
1097
- "button",
1098
- {
1099
- type: "button",
1100
- className: "poolse-icon-btn",
1101
- onClick: onClose,
1102
- "aria-label": "Close thread",
1103
- children: /* @__PURE__ */ jsx(PoolseIcon, { name: "close", size: 18, label: null })
1104
- }
1105
- )
1106
- ] }),
1107
- /* @__PURE__ */ jsx("div", { className: "poolse-thread__root", children: /* @__PURE__ */ jsx(MessageBubble, { message: rootMessage, currentUserId: me?.id ?? null }) }),
1108
- /* @__PURE__ */ jsxs("div", { className: "poolse-thread__messages", ref: listRef, children: [
1109
- hasMore && !loading && replies.length > 0 && /* @__PURE__ */ jsx("button", { type: "button", className: "poolse-conversation__load-more", onClick: loadMore, children: "Load older replies" }),
1110
- 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." }) : (
1111
- // Same Fragment trick as ConversationView so MessageBubble
1112
- // remains the direct flex child for align-self to work.
1113
- replies.map((msg) => /* @__PURE__ */ jsx(Fragment$1, { children: renderOne(msg, me?.id ?? null) }, msg.id))
1114
- ),
1115
- error && /* @__PURE__ */ jsxs("div", { className: "poolse-conversation__empty", children: [
1116
- "Failed to load: ",
1117
- error.message
1118
- ] })
1119
- ] }),
1120
- /* @__PURE__ */ jsx(MessageComposer, { onSend: (body) => sendReply({ body }), placeholder: "Reply in thread\u2026" })
1121
- ] });
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
+ );
1122
1579
  }
1123
1580
  function defaultRenderReply(msg, currentUserId) {
1124
1581
  return /* @__PURE__ */ jsx(MessageBubble, { message: msg, currentUserId });
1125
1582
  }
1126
1583
  function TypingIndicator({ typing, labelFor }) {
1127
1584
  const ids = Array.from(typing);
1128
- if (ids.length === 0) {
1129
- return /* @__PURE__ */ jsx("div", { className: "poolse-typing", "aria-hidden": "true" });
1130
- }
1131
- const label = labelFor ?? ((id) => id.slice(0, 6));
1132
- const names = ids.slice(0, 2).map(label);
1133
- let text;
1134
- if (ids.length === 1) text = `${names[0]} is typing`;
1135
- else if (ids.length === 2) text = `${names[0]} and ${names[1]} are typing`;
1136
- else text = `${ids.length} people are typing`;
1137
- return /* @__PURE__ */ jsxs("div", { className: "poolse-typing", children: [
1138
- /* @__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: [
1139
1588
  /* @__PURE__ */ jsx("span", { className: "poolse-typing__dot" }),
1140
1589
  /* @__PURE__ */ jsx("span", { className: "poolse-typing__dot" }),
1141
1590
  /* @__PURE__ */ jsx("span", { className: "poolse-typing__dot" })
1142
1591
  ] }),
1143
- /* @__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
+ )
1144
1602
  ] });
1145
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"
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
+ );
1682
+ }
1146
1683
  var TRUE = true;
1147
1684
  function ConversationView({
1148
1685
  conversationId,
@@ -1157,6 +1694,13 @@ function ConversationView({
1157
1694
  threads = TRUE,
1158
1695
  quotations = TRUE,
1159
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",
1160
1704
  onMarkedRead
1161
1705
  }) {
1162
1706
  usePoolseFonts(loadFonts);
@@ -1174,8 +1718,12 @@ function ConversationView({
1174
1718
  } = useMessages(conversationId);
1175
1719
  const { typing, signalTyping } = useTyping(conversationId);
1176
1720
  const status = useRealtimeStatus();
1177
- const membersOn = mentions || readReceipts;
1721
+ const wantsMemberCount = senderLabels === "auto" || avatars === "auto";
1722
+ const membersOn = mentions || readReceipts || wantsMemberCount;
1178
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;
1179
1727
  const listRef = useRef(null);
1180
1728
  const lastMessageIdRef = useRef(null);
1181
1729
  const bottomSentinelRef = useRef(null);
@@ -1270,20 +1818,56 @@ function ConversationView({
1270
1818
  el.classList.add("poolse-message-row--highlight");
1271
1819
  setTimeout(() => el.classList.remove("poolse-message-row--highlight"), 1600);
1272
1820
  };
1273
- const { upload, uploading } = useAttachmentUpload();
1274
- 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;
1275
1827
  try {
1276
- const att = await upload({
1277
- body: file,
1278
- contentType: file.type || "application/octet-stream",
1279
- byteSize: file.size,
1280
- filename: file.name
1281
- });
1282
- await send({ body: "", attachment_ids: [att.id] });
1283
- } catch (err) {
1284
- 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 {
1285
1841
  }
1286
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
+ };
1287
1871
  const onSendBody = async (body, opts) => {
1288
1872
  await send({
1289
1873
  body,
@@ -1314,86 +1898,141 @@ function ConversationView({
1314
1898
  }
1315
1899
  );
1316
1900
  return /* @__PURE__ */ jsxs("div", { className: "poolse-conversation-shell", children: [
1317
- /* @__PURE__ */ jsxs("div", { className: "poolse-conversation", children: [
1318
- status !== "connected" && status !== "idle" && /* @__PURE__ */ jsxs("div", { className: "poolse-conversation__status", children: [
1319
- status === "connecting" && "Connecting\u2026",
1320
- status === "reconnecting" && "Reconnecting\u2026",
1321
- status === "closed" && "Disconnected"
1322
- ] }),
1323
- /* @__PURE__ */ jsxs("div", { className: "poolse-conversation__messages", ref: listRef, children: [
1324
- hasMore && !loading && /* @__PURE__ */ jsx("button", { type: "button", className: "poolse-conversation__load-more", onClick: loadMore, children: "Load older messages" }),
1325
- 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) => {
1326
- if (renderMessage) {
1327
- return /* @__PURE__ */ jsx(Fragment$1, { children: renderMessage(msg, me?.id ?? null) }, msg.id);
1328
- }
1329
- const enriched = quotations && msg.quoted_message_id && !msg.quoted_message ? (() => {
1330
- const original = messages.find((m) => m.id === msg.quoted_message_id);
1331
- if (!original) return msg;
1332
- return {
1333
- ...msg,
1334
- quoted_message: {
1335
- id: original.id,
1336
- sender_id: original.sender_id,
1337
- body: original.body,
1338
- deleted_at: original.deleted_at,
1339
- inserted_at: original.inserted_at
1340
- }
1341
- };
1342
- })() : msg;
1343
- const isSelf = me !== null && msg.sender_id === me.id;
1344
- const readState = readReceipts && isSelf && maxReadByOthers !== null ? maxReadByOthers >= msg.sequence ? "read" : "sent" : void 0;
1345
- return /* @__PURE__ */ jsx("div", { "data-message-id": msg.id, children: /* @__PURE__ */ jsx(
1346
- 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",
1347
1912
  {
1348
- msg: enriched,
1349
- meId: me?.id ?? null,
1350
- reactions,
1351
- attachments,
1352
- actions,
1353
- threads,
1354
- quotations,
1355
- ...readState ? { readState } : {},
1356
- ...labelFor ? { labelFor } : {},
1357
- editing: editingId === msg.id,
1358
- onStartEdit: () => setEditingId(msg.id),
1359
- onCancelEdit: () => setEditingId(null),
1360
- onSaveEdit: async (body) => {
1361
- await edit(msg.id, body);
1362
- setEditingId(null);
1363
- },
1364
- onDelete: () => void deleteMsg(msg.id),
1365
- onOpenThread: () => setThreadRootId(msg.id),
1366
- onQuote: () => setReplyingTo(msg),
1367
- onQuotedClick: scrollToOriginal
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
+ ]
1368
1922
  }
1369
- ) }, msg.id);
1370
- }),
1371
- error && /* @__PURE__ */ jsxs("div", { className: "poolse-conversation__empty", children: [
1372
- "Failed to load: ",
1373
- error.message
1374
- ] }),
1375
- /* @__PURE__ */ jsx("div", { ref: bottomSentinelRef, "aria-hidden": "true", style: { height: 1 } })
1376
- ] }),
1377
- !atBottom && newCountWhileAway > 0 && /* @__PURE__ */ jsxs(
1378
- "button",
1379
- {
1380
- type: "button",
1381
- className: "poolse-conversation__scroll-to-new",
1382
- onClick: scrollToBottom,
1383
- children: [
1384
- "\u2193 ",
1385
- newCountWhileAway,
1386
- " new ",
1387
- newCountWhileAway === 1 ? "message" : "messages"
1388
- ]
1389
- }
1390
- ),
1391
- /* @__PURE__ */ jsx(TypingIndicator, { typing, ...labelFor ? { labelFor } : {} }),
1392
- /* @__PURE__ */ jsxs("div", { className: "poolse-conversation__composer-row", children: [
1393
- attachments && /* @__PURE__ */ jsx(AttachmentPickerButton, { onPick: onPickFile, disabled: uploading }),
1394
- /* @__PURE__ */ jsx("div", { className: "poolse-conversation__composer-flex", children: Composer })
1395
- ] })
1396
- ] }),
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
+ ),
1397
2036
  threads && threadRoot && /* @__PURE__ */ jsx("div", { className: "poolse-conversation-shell__thread", children: /* @__PURE__ */ jsx(
1398
2037
  ThreadView,
1399
2038
  {
@@ -1415,10 +2054,11 @@ function AttachmentPickerButton({
1415
2054
  {
1416
2055
  ref: inputRef,
1417
2056
  type: "file",
2057
+ multiple: true,
1418
2058
  className: "poolse-attach-input",
1419
2059
  onChange: (e) => {
1420
- const f = e.target.files?.[0];
1421
- if (f) onPick(f);
2060
+ const files = Array.from(e.target.files ?? []);
2061
+ if (files.length > 0) onPick(files);
1422
2062
  e.target.value = "";
1423
2063
  }
1424
2064
  }
@@ -1430,31 +2070,13 @@ function AttachmentPickerButton({
1430
2070
  className: "poolse-attach-btn",
1431
2071
  onClick: () => inputRef.current?.click(),
1432
2072
  disabled,
1433
- "aria-label": "Attach file",
1434
- title: "Attach file",
2073
+ "aria-label": "Attach files",
2074
+ title: "Attach files",
1435
2075
  children: /* @__PURE__ */ jsx(PoolseIcon, { name: "attachment", size: 20, label: null })
1436
2076
  }
1437
2077
  )
1438
2078
  ] });
1439
2079
  }
1440
- function Avatar({ src, name, online, size = "md", className }) {
1441
- const initials = computeInitials(name);
1442
- const classes = [
1443
- "poolse-avatar",
1444
- size === "sm" ? "poolse-avatar--sm" : null,
1445
- size === "lg" ? "poolse-avatar--lg" : null,
1446
- className
1447
- ].filter(Boolean).join(" ");
1448
- return /* @__PURE__ */ jsxs("span", { className: classes, "aria-label": name ?? "avatar", role: "img", children: [
1449
- src ? /* @__PURE__ */ jsx("img", { src, alt: name ?? "" }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: initials }),
1450
- online ? /* @__PURE__ */ jsx("span", { className: "poolse-avatar__presence", "aria-hidden": "true" }) : null
1451
- ] });
1452
- }
1453
- function computeInitials(name) {
1454
- if (!name) return "?";
1455
- const parts = name.trim().split(/\s+/).slice(0, 2);
1456
- return parts.map((p) => p.charAt(0).toUpperCase()).join("").slice(0, 2) || "?";
1457
- }
1458
2080
  function ConversationList({
1459
2081
  selectedId,
1460
2082
  onSelect,
@@ -1562,19 +2184,18 @@ function MemberList({
1562
2184
  if (members.length === 0) {
1563
2185
  return /* @__PURE__ */ jsx("div", { className: "poolse-list poolse-list--placeholder", children: emptyState ?? "No members yet." });
1564
2186
  }
1565
- const label = labelFor ?? ((id) => id.slice(0, 8));
1566
2187
  return /* @__PURE__ */ jsx("ul", { className: "poolse-list", role: "list", "aria-label": "Members", children: members.map((m) => {
1567
2188
  const content = renderItem ? renderItem(m) : /* @__PURE__ */ jsx(
1568
2189
  DefaultMemberRow,
1569
2190
  {
1570
2191
  membership: m,
1571
- name: label(m.user_id),
1572
2192
  avatarUrl: avatarFor?.(m.user_id) ?? null,
1573
2193
  online: onlineUserIds?.has(m.user_id) ?? false,
1574
2194
  removable: canRemove?.(m) ?? false,
1575
2195
  onRemove: () => {
1576
2196
  void removeMember(m.user_id);
1577
- }
2197
+ },
2198
+ ...labelFor ? { labelFor } : {}
1578
2199
  }
1579
2200
  );
1580
2201
  return /* @__PURE__ */ jsx("li", { className: "poolse-list__item", children: content }, m.id);
@@ -1582,12 +2203,13 @@ function MemberList({
1582
2203
  }
1583
2204
  function DefaultMemberRow({
1584
2205
  membership,
1585
- name,
1586
2206
  avatarUrl,
1587
2207
  online,
1588
2208
  removable,
1589
- onRemove
2209
+ onRemove,
2210
+ labelFor
1590
2211
  }) {
2212
+ const name = useDisplayName(membership.user_id, labelFor);
1591
2213
  return /* @__PURE__ */ jsxs("div", { className: "poolse-member-row", children: [
1592
2214
  /* @__PURE__ */ jsx(Avatar, { src: avatarUrl, name, online, size: "md" }),
1593
2215
  /* @__PURE__ */ jsxs("div", { className: "poolse-member-row__body", children: [
@@ -1722,6 +2344,6 @@ function PoolseLogo({
1722
2344
  );
1723
2345
  }
1724
2346
 
1725
- 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 };
1726
2348
  //# sourceMappingURL=index.js.map
1727
2349
  //# sourceMappingURL=index.js.map