@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/CHANGELOG.md +10 -0
- package/README.md +30 -15
- package/dist/index.cjs +904 -274
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +106 -4
- package/dist/index.d.ts +106 -4
- package/dist/index.js +898 -276
- package/dist/index.js.map +1 -1
- package/dist/styles.css +611 -11
- package/package.json +6 -3
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(
|
|
537
|
+
mention && filtered.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(
|
|
418
538
|
"div",
|
|
419
539
|
{
|
|
420
|
-
|
|
421
|
-
"
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
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.
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
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,88 @@ 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
|
}) : "";
|
|
932
|
+
const showQuoteCard = message.quoted_message !== void 0 && message.quoted_message !== null ? "full" : message.quoted_message_id ? "placeholder" : null;
|
|
657
933
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, children: [
|
|
658
|
-
|
|
934
|
+
renderSenderName && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-message__sender", style: { color: senderColorHex }, children: senderName }),
|
|
935
|
+
showQuoteCard === "full" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
659
936
|
QuotedCard,
|
|
660
937
|
{
|
|
661
938
|
quoted: message.quoted_message,
|
|
@@ -664,7 +941,45 @@ function MessageBubble({
|
|
|
664
941
|
...onQuotedClick ? { onClick: onQuotedClick } : {}
|
|
665
942
|
}
|
|
666
943
|
),
|
|
667
|
-
|
|
944
|
+
showQuoteCard === "placeholder" && /* @__PURE__ */ jsxRuntime.jsx(QuotedPlaceholder, { isSelf, quotedMessageId: message.quoted_message_id }),
|
|
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
|
+
] }),
|
|
668
983
|
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "poolse-message__meta", children: [
|
|
669
984
|
/* @__PURE__ */ jsxRuntime.jsx("span", { children: time }),
|
|
670
985
|
message.edited_at ? /* @__PURE__ */ jsxRuntime.jsx("span", { children: " \xB7 edited" }) : null,
|
|
@@ -679,6 +994,22 @@ function MessageBubble({
|
|
|
679
994
|
] })
|
|
680
995
|
] });
|
|
681
996
|
}
|
|
997
|
+
function QuotedPlaceholder({
|
|
998
|
+
isSelf,
|
|
999
|
+
quotedMessageId: _quotedMessageId
|
|
1000
|
+
}) {
|
|
1001
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1002
|
+
"div",
|
|
1003
|
+
{
|
|
1004
|
+
className: `poolse-quote poolse-quote--placeholder ${isSelf ? "poolse-quote--self" : "poolse-quote--other"}`,
|
|
1005
|
+
"aria-label": "Quoted message",
|
|
1006
|
+
children: [
|
|
1007
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-quote__sender", children: "Replying to a message" }),
|
|
1008
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-quote__body", children: "Loading preview\u2026" })
|
|
1009
|
+
]
|
|
1010
|
+
}
|
|
1011
|
+
);
|
|
1012
|
+
}
|
|
682
1013
|
function QuotedCard({
|
|
683
1014
|
quoted,
|
|
684
1015
|
isSelf,
|
|
@@ -856,19 +1187,53 @@ function ReactionPicker({
|
|
|
856
1187
|
onPick,
|
|
857
1188
|
onClose
|
|
858
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
|
+
};
|
|
859
1223
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
860
1224
|
"div",
|
|
861
1225
|
{
|
|
1226
|
+
ref: rootRef,
|
|
862
1227
|
className: "poolse-reaction-picker",
|
|
863
1228
|
role: "menu",
|
|
1229
|
+
"aria-label": "Pick a reaction",
|
|
864
1230
|
style: { position: "absolute", bottom: "100%", left: 0, marginBottom: 6 },
|
|
865
|
-
onKeyDown:
|
|
866
|
-
if (e.key === "Escape") onClose?.();
|
|
867
|
-
},
|
|
1231
|
+
onKeyDown: onKey,
|
|
868
1232
|
children: COMMON_EMOJIS.map((e) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
869
1233
|
"button",
|
|
870
1234
|
{
|
|
871
1235
|
type: "button",
|
|
1236
|
+
role: "menuitem",
|
|
872
1237
|
className: "poolse-reaction-picker__btn",
|
|
873
1238
|
onClick: () => onPick(e),
|
|
874
1239
|
"aria-label": `React with ${e}`,
|
|
@@ -950,8 +1315,16 @@ function MessageRow({
|
|
|
950
1315
|
onOpenThread,
|
|
951
1316
|
onQuote,
|
|
952
1317
|
labelFor,
|
|
953
|
-
onQuotedClick
|
|
1318
|
+
onQuotedClick,
|
|
1319
|
+
groupPosition = "standalone",
|
|
1320
|
+
maxBodyLength = 0,
|
|
1321
|
+
markdown = false,
|
|
1322
|
+
showSenderName = false,
|
|
1323
|
+
showAvatar = false
|
|
954
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;
|
|
955
1328
|
const isSelf = meId !== null && msg.sender_id === meId;
|
|
956
1329
|
const reactionsHook = react$1.useReactions(reactions ? msg.id : "", {
|
|
957
1330
|
conversationId: msg.conversation_id,
|
|
@@ -965,80 +1338,135 @@ function MessageRow({
|
|
|
965
1338
|
const showThreadPill = threads && !msg.deleted_at && !msg.thread_root_id && replyCount > 0;
|
|
966
1339
|
const handleSave = onSaveEdit ?? (async () => void 0);
|
|
967
1340
|
const handleCancel = onCancelEdit ?? (() => void 0);
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
onSave: handleSave,
|
|
977
|
-
onCancel: handleCancel
|
|
978
|
-
}
|
|
979
|
-
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
980
|
-
MessageBubble,
|
|
981
|
-
{
|
|
982
|
-
message: msg,
|
|
983
|
-
currentUserId: meId,
|
|
984
|
-
...readState ? { readState } : {},
|
|
985
|
-
...labelFor ? { labelFor } : {},
|
|
986
|
-
...onQuotedClick ? { onQuotedClick } : {}
|
|
987
|
-
}
|
|
988
|
-
),
|
|
989
|
-
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)) }),
|
|
990
|
-
showReactions && /* @__PURE__ */ jsxRuntime.jsx("div", { className: `poolse-message-row__reactions ${isSelf ? "is-self" : ""}`, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
991
|
-
InlineReactions,
|
|
992
|
-
{
|
|
993
|
-
reactions: reactionsHook.reactions,
|
|
994
|
-
currentUserId: meId,
|
|
995
|
-
onAdd: (e) => void reactionsHook.addReaction(e),
|
|
996
|
-
onRemove: (e) => void reactionsHook.removeReaction(e)
|
|
997
|
-
}
|
|
998
|
-
) }),
|
|
999
|
-
showThreadPill && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1000
|
-
"button",
|
|
1001
|
-
{
|
|
1002
|
-
type: "button",
|
|
1003
|
-
className: `poolse-thread-pill ${isSelf ? "poolse-thread-pill--right" : "poolse-thread-pill--left"}`,
|
|
1004
|
-
onClick: onOpenThread,
|
|
1005
|
-
"aria-label": `View ${replyCount} ${replyCount === 1 ? "reply" : "replies"}`,
|
|
1006
|
-
children: [
|
|
1007
|
-
/* @__PURE__ */ jsxRuntime.jsx(PoolseIcon, { name: "messages", size: 12, label: null }),
|
|
1008
|
-
/* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
|
|
1009
|
-
replyCount,
|
|
1010
|
-
" ",
|
|
1011
|
-
replyCount === 1 ? "reply" : "replies"
|
|
1012
|
-
] })
|
|
1013
|
-
]
|
|
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);
|
|
1014
1349
|
}
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1350
|
+
};
|
|
1351
|
+
document.addEventListener("pointerdown", onDown);
|
|
1352
|
+
return () => document.removeEventListener("pointerdown", onDown);
|
|
1353
|
+
}, [actionsOpen]);
|
|
1354
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1355
|
+
"div",
|
|
1356
|
+
{
|
|
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(" "),
|
|
1367
|
+
"data-message-id": msg.id,
|
|
1368
|
+
"data-actions-open": actionsOpen || void 0,
|
|
1369
|
+
children: [
|
|
1370
|
+
editing ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1371
|
+
EditableMessageBubble,
|
|
1372
|
+
{
|
|
1373
|
+
message: msg,
|
|
1374
|
+
currentUserId: meId,
|
|
1375
|
+
...readState ? { readState } : {},
|
|
1376
|
+
editing: true,
|
|
1377
|
+
onSave: handleSave,
|
|
1378
|
+
onCancel: handleCancel
|
|
1379
|
+
}
|
|
1380
|
+
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
1381
|
+
BubbleWithAvatar,
|
|
1022
1382
|
{
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
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 } : {}
|
|
1026
1400
|
}
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1401
|
+
)
|
|
1402
|
+
}
|
|
1403
|
+
),
|
|
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)) }),
|
|
1405
|
+
showReactions && /* @__PURE__ */ jsxRuntime.jsx("div", { className: `poolse-message-row__reactions ${isSelf ? "is-self" : ""}`, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1406
|
+
InlineReactions,
|
|
1407
|
+
{
|
|
1408
|
+
reactions: reactionsHook.reactions,
|
|
1409
|
+
currentUserId: meId,
|
|
1410
|
+
onAdd: (e) => void reactionsHook.addReaction(e),
|
|
1411
|
+
onRemove: (e) => void reactionsHook.removeReaction(e)
|
|
1412
|
+
}
|
|
1413
|
+
) }),
|
|
1414
|
+
showThreadPill && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1415
|
+
"button",
|
|
1416
|
+
{
|
|
1417
|
+
type: "button",
|
|
1418
|
+
className: `poolse-thread-pill ${isSelf ? "poolse-thread-pill--right" : "poolse-thread-pill--left"}`,
|
|
1419
|
+
onClick: onOpenThread,
|
|
1420
|
+
"aria-label": `View ${replyCount} ${replyCount === 1 ? "reply" : "replies"}`,
|
|
1421
|
+
children: [
|
|
1422
|
+
/* @__PURE__ */ jsxRuntime.jsx(PoolseIcon, { name: "messages", size: 12, label: null }),
|
|
1423
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
|
|
1424
|
+
replyCount,
|
|
1425
|
+
" ",
|
|
1426
|
+
replyCount === 1 ? "reply" : "replies"
|
|
1427
|
+
] })
|
|
1428
|
+
]
|
|
1429
|
+
}
|
|
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
|
+
),
|
|
1442
|
+
showActions && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1443
|
+
"div",
|
|
1444
|
+
{
|
|
1445
|
+
className: `poolse-message-row__actions ${isSelf ? "poolse-message-row__actions--right" : "poolse-message-row__actions--left"}`,
|
|
1446
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1447
|
+
MessageActions,
|
|
1448
|
+
{
|
|
1449
|
+
...reactions ? {
|
|
1450
|
+
onReact: (emoji) => {
|
|
1451
|
+
void reactionsHook.addReaction(emoji);
|
|
1452
|
+
}
|
|
1453
|
+
} : {},
|
|
1454
|
+
...threads && onOpenThread ? { onReply: onOpenThread } : {},
|
|
1455
|
+
...quotations && onQuote ? { onQuote } : {},
|
|
1456
|
+
...msg.body ? {
|
|
1457
|
+
onCopy: () => {
|
|
1458
|
+
void navigator?.clipboard?.writeText(msg.body ?? "").catch(() => void 0);
|
|
1459
|
+
}
|
|
1460
|
+
} : {},
|
|
1461
|
+
...isSelf && onStartEdit ? { onEdit: onStartEdit } : {},
|
|
1462
|
+
...isSelf && onDelete ? { onDelete } : {}
|
|
1033
1463
|
}
|
|
1034
|
-
|
|
1035
|
-
...isSelf && onStartEdit ? { onEdit: onStartEdit } : {},
|
|
1036
|
-
...isSelf && onDelete ? { onDelete } : {}
|
|
1464
|
+
)
|
|
1037
1465
|
}
|
|
1038
1466
|
)
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1467
|
+
]
|
|
1468
|
+
}
|
|
1469
|
+
);
|
|
1042
1470
|
}
|
|
1043
1471
|
function InlineReactions({
|
|
1044
1472
|
reactions,
|
|
@@ -1070,6 +1498,21 @@ function InlineReactions({
|
|
|
1070
1498
|
);
|
|
1071
1499
|
}) });
|
|
1072
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
|
+
}
|
|
1073
1516
|
function ThreadView({
|
|
1074
1517
|
conversationId,
|
|
1075
1518
|
rootMessage,
|
|
@@ -1082,6 +1525,7 @@ function ThreadView({
|
|
|
1082
1525
|
rootMessage.id
|
|
1083
1526
|
);
|
|
1084
1527
|
const listRef = react.useRef(null);
|
|
1528
|
+
const closeBtnRef = react.useRef(null);
|
|
1085
1529
|
const lastReplyIdRef = react.useRef(null);
|
|
1086
1530
|
react.useEffect(() => {
|
|
1087
1531
|
const tail = replies[replies.length - 1];
|
|
@@ -1091,60 +1535,158 @@ function ThreadView({
|
|
|
1091
1535
|
const el = listRef.current;
|
|
1092
1536
|
if (el) el.scrollTop = el.scrollHeight;
|
|
1093
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]);
|
|
1094
1547
|
const renderOne = renderMessage ?? defaultRenderReply;
|
|
1095
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
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
|
+
);
|
|
1124
1586
|
}
|
|
1125
1587
|
function defaultRenderReply(msg, currentUserId) {
|
|
1126
1588
|
return /* @__PURE__ */ jsxRuntime.jsx(MessageBubble, { message: msg, currentUserId });
|
|
1127
1589
|
}
|
|
1128
1590
|
function TypingIndicator({ typing, labelFor }) {
|
|
1129
1591
|
const ids = Array.from(typing);
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
const label = labelFor ?? ((id) => id.slice(0, 6));
|
|
1134
|
-
const names = ids.slice(0, 2).map(label);
|
|
1135
|
-
let text;
|
|
1136
|
-
if (ids.length === 1) text = `${names[0]} is typing`;
|
|
1137
|
-
else if (ids.length === 2) text = `${names[0]} and ${names[1]} are typing`;
|
|
1138
|
-
else text = `${ids.length} people are typing`;
|
|
1139
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-typing", children: [
|
|
1140
|
-
/* @__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: [
|
|
1141
1595
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-typing__dot" }),
|
|
1142
1596
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-typing__dot" }),
|
|
1143
1597
|
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-typing__dot" })
|
|
1144
1598
|
] }),
|
|
1145
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
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
|
+
)
|
|
1146
1609
|
] });
|
|
1147
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
|
+
}
|
|
1148
1690
|
var TRUE = true;
|
|
1149
1691
|
function ConversationView({
|
|
1150
1692
|
conversationId,
|
|
@@ -1159,6 +1701,13 @@ function ConversationView({
|
|
|
1159
1701
|
threads = TRUE,
|
|
1160
1702
|
quotations = TRUE,
|
|
1161
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",
|
|
1162
1711
|
onMarkedRead
|
|
1163
1712
|
}) {
|
|
1164
1713
|
usePoolseFonts(loadFonts);
|
|
@@ -1176,8 +1725,12 @@ function ConversationView({
|
|
|
1176
1725
|
} = react$1.useMessages(conversationId);
|
|
1177
1726
|
const { typing, signalTyping } = react$1.useTyping(conversationId);
|
|
1178
1727
|
const status = react$1.useRealtimeStatus();
|
|
1179
|
-
const
|
|
1728
|
+
const wantsMemberCount = senderLabels === "auto" || avatars === "auto";
|
|
1729
|
+
const membersOn = mentions || readReceipts || wantsMemberCount;
|
|
1180
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;
|
|
1181
1734
|
const listRef = react.useRef(null);
|
|
1182
1735
|
const lastMessageIdRef = react.useRef(null);
|
|
1183
1736
|
const bottomSentinelRef = react.useRef(null);
|
|
@@ -1272,20 +1825,56 @@ function ConversationView({
|
|
|
1272
1825
|
el.classList.add("poolse-message-row--highlight");
|
|
1273
1826
|
setTimeout(() => el.classList.remove("poolse-message-row--highlight"), 1600);
|
|
1274
1827
|
};
|
|
1275
|
-
const {
|
|
1276
|
-
const
|
|
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;
|
|
1277
1834
|
try {
|
|
1278
|
-
const
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
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 {
|
|
1287
1848
|
}
|
|
1288
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
|
+
};
|
|
1289
1878
|
const onSendBody = async (body, opts) => {
|
|
1290
1879
|
await send({
|
|
1291
1880
|
body,
|
|
@@ -1316,86 +1905,141 @@ function ConversationView({
|
|
|
1316
1905
|
}
|
|
1317
1906
|
);
|
|
1318
1907
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-conversation-shell", children: [
|
|
1319
|
-
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
}
|
|
1331
|
-
const enriched = quotations && msg.quoted_message_id && !msg.quoted_message ? (() => {
|
|
1332
|
-
const original = messages.find((m) => m.id === msg.quoted_message_id);
|
|
1333
|
-
if (!original) return msg;
|
|
1334
|
-
return {
|
|
1335
|
-
...msg,
|
|
1336
|
-
quoted_message: {
|
|
1337
|
-
id: original.id,
|
|
1338
|
-
sender_id: original.sender_id,
|
|
1339
|
-
body: original.body,
|
|
1340
|
-
deleted_at: original.deleted_at,
|
|
1341
|
-
inserted_at: original.inserted_at
|
|
1342
|
-
}
|
|
1343
|
-
};
|
|
1344
|
-
})() : msg;
|
|
1345
|
-
const isSelf = me !== null && msg.sender_id === me.id;
|
|
1346
|
-
const readState = readReceipts && isSelf && maxReadByOthers !== null ? maxReadByOthers >= msg.sequence ? "read" : "sent" : void 0;
|
|
1347
|
-
return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-message-id": msg.id, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1348
|
-
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",
|
|
1349
1919
|
{
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
editing: editingId === msg.id,
|
|
1360
|
-
onStartEdit: () => setEditingId(msg.id),
|
|
1361
|
-
onCancelEdit: () => setEditingId(null),
|
|
1362
|
-
onSaveEdit: async (body) => {
|
|
1363
|
-
await edit(msg.id, body);
|
|
1364
|
-
setEditingId(null);
|
|
1365
|
-
},
|
|
1366
|
-
onDelete: () => void deleteMsg(msg.id),
|
|
1367
|
-
onOpenThread: () => setThreadRootId(msg.id),
|
|
1368
|
-
onQuote: () => setReplyingTo(msg),
|
|
1369
|
-
onQuotedClick: scrollToOriginal
|
|
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
|
+
]
|
|
1370
1929
|
}
|
|
1371
|
-
)
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
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
|
+
),
|
|
1399
2043
|
threads && threadRoot && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation-shell__thread", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1400
2044
|
ThreadView,
|
|
1401
2045
|
{
|
|
@@ -1417,10 +2061,11 @@ function AttachmentPickerButton({
|
|
|
1417
2061
|
{
|
|
1418
2062
|
ref: inputRef,
|
|
1419
2063
|
type: "file",
|
|
2064
|
+
multiple: true,
|
|
1420
2065
|
className: "poolse-attach-input",
|
|
1421
2066
|
onChange: (e) => {
|
|
1422
|
-
const
|
|
1423
|
-
if (
|
|
2067
|
+
const files = Array.from(e.target.files ?? []);
|
|
2068
|
+
if (files.length > 0) onPick(files);
|
|
1424
2069
|
e.target.value = "";
|
|
1425
2070
|
}
|
|
1426
2071
|
}
|
|
@@ -1432,31 +2077,13 @@ function AttachmentPickerButton({
|
|
|
1432
2077
|
className: "poolse-attach-btn",
|
|
1433
2078
|
onClick: () => inputRef.current?.click(),
|
|
1434
2079
|
disabled,
|
|
1435
|
-
"aria-label": "Attach
|
|
1436
|
-
title: "Attach
|
|
2080
|
+
"aria-label": "Attach files",
|
|
2081
|
+
title: "Attach files",
|
|
1437
2082
|
children: /* @__PURE__ */ jsxRuntime.jsx(PoolseIcon, { name: "attachment", size: 20, label: null })
|
|
1438
2083
|
}
|
|
1439
2084
|
)
|
|
1440
2085
|
] });
|
|
1441
2086
|
}
|
|
1442
|
-
function Avatar({ src, name, online, size = "md", className }) {
|
|
1443
|
-
const initials = computeInitials(name);
|
|
1444
|
-
const classes = [
|
|
1445
|
-
"poolse-avatar",
|
|
1446
|
-
size === "sm" ? "poolse-avatar--sm" : null,
|
|
1447
|
-
size === "lg" ? "poolse-avatar--lg" : null,
|
|
1448
|
-
className
|
|
1449
|
-
].filter(Boolean).join(" ");
|
|
1450
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: classes, "aria-label": name ?? "avatar", role: "img", children: [
|
|
1451
|
-
src ? /* @__PURE__ */ jsxRuntime.jsx("img", { src, alt: name ?? "" }) : /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", children: initials }),
|
|
1452
|
-
online ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-avatar__presence", "aria-hidden": "true" }) : null
|
|
1453
|
-
] });
|
|
1454
|
-
}
|
|
1455
|
-
function computeInitials(name) {
|
|
1456
|
-
if (!name) return "?";
|
|
1457
|
-
const parts = name.trim().split(/\s+/).slice(0, 2);
|
|
1458
|
-
return parts.map((p) => p.charAt(0).toUpperCase()).join("").slice(0, 2) || "?";
|
|
1459
|
-
}
|
|
1460
2087
|
function ConversationList({
|
|
1461
2088
|
selectedId,
|
|
1462
2089
|
onSelect,
|
|
@@ -1564,19 +2191,18 @@ function MemberList({
|
|
|
1564
2191
|
if (members.length === 0) {
|
|
1565
2192
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-list poolse-list--placeholder", children: emptyState ?? "No members yet." });
|
|
1566
2193
|
}
|
|
1567
|
-
const label = labelFor ?? ((id) => id.slice(0, 8));
|
|
1568
2194
|
return /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "poolse-list", role: "list", "aria-label": "Members", children: members.map((m) => {
|
|
1569
2195
|
const content = renderItem ? renderItem(m) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
1570
2196
|
DefaultMemberRow,
|
|
1571
2197
|
{
|
|
1572
2198
|
membership: m,
|
|
1573
|
-
name: label(m.user_id),
|
|
1574
2199
|
avatarUrl: avatarFor?.(m.user_id) ?? null,
|
|
1575
2200
|
online: onlineUserIds?.has(m.user_id) ?? false,
|
|
1576
2201
|
removable: canRemove?.(m) ?? false,
|
|
1577
2202
|
onRemove: () => {
|
|
1578
2203
|
void removeMember(m.user_id);
|
|
1579
|
-
}
|
|
2204
|
+
},
|
|
2205
|
+
...labelFor ? { labelFor } : {}
|
|
1580
2206
|
}
|
|
1581
2207
|
);
|
|
1582
2208
|
return /* @__PURE__ */ jsxRuntime.jsx("li", { className: "poolse-list__item", children: content }, m.id);
|
|
@@ -1584,12 +2210,13 @@ function MemberList({
|
|
|
1584
2210
|
}
|
|
1585
2211
|
function DefaultMemberRow({
|
|
1586
2212
|
membership,
|
|
1587
|
-
name,
|
|
1588
2213
|
avatarUrl,
|
|
1589
2214
|
online,
|
|
1590
2215
|
removable,
|
|
1591
|
-
onRemove
|
|
2216
|
+
onRemove,
|
|
2217
|
+
labelFor
|
|
1592
2218
|
}) {
|
|
2219
|
+
const name = useDisplayName(membership.user_id, labelFor);
|
|
1593
2220
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-member-row", children: [
|
|
1594
2221
|
/* @__PURE__ */ jsxRuntime.jsx(Avatar, { src: avatarUrl, name, online, size: "md" }),
|
|
1595
2222
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-member-row__body", children: [
|
|
@@ -1741,6 +2368,9 @@ exports.ReactionPicker = ReactionPicker;
|
|
|
1741
2368
|
exports.ReactionStrip = ReactionStrip;
|
|
1742
2369
|
exports.ThreadView = ThreadView;
|
|
1743
2370
|
exports.TypingIndicator = TypingIndicator;
|
|
2371
|
+
exports.UploadQueueStrip = UploadQueueStrip;
|
|
2372
|
+
exports.UserName = UserName;
|
|
2373
|
+
exports.useDisplayName = useDisplayName;
|
|
1744
2374
|
exports.usePoolseFonts = usePoolseFonts;
|
|
1745
2375
|
//# sourceMappingURL=index.cjs.map
|
|
1746
2376
|
//# sourceMappingURL=index.cjs.map
|