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