@poolse/react-ui 0.2.0-alpha.7 → 1.0.1-beta.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/dist/index.cjs +393 -117
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +76 -2
- package/dist/index.d.ts +76 -2
- package/dist/index.js +389 -118
- package/dist/index.js.map +1 -1
- package/dist/styles.css +228 -9
- package/package.json +6 -3
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { useMembers, useAttachmentUrl, useReactions, useMe, useThread, useMessages, useTyping, useRealtimeStatus, useAttachmentUpload, useConversations } from '@poolse/react';
|
|
2
|
+
import { useMembers, useAttachmentUrl, useUser, useReactions, useMe, useThread, useMessages, useTyping, useRealtimeStatus, useAttachmentUpload, useConversations } from '@poolse/react';
|
|
3
3
|
import { useEffect, useState, useRef, Fragment as Fragment$1, useMemo } from 'react';
|
|
4
4
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
5
|
+
import ReactMarkdown from 'react-markdown';
|
|
6
|
+
import remarkGfm from 'remark-gfm';
|
|
5
7
|
|
|
6
8
|
// src/ConversationView.tsx
|
|
7
9
|
var FONT_HREF = "https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,400;12..96,600;12..96,800&family=Hanken+Grotesk:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap";
|
|
@@ -40,6 +42,40 @@ function PoolseFonts() {
|
|
|
40
42
|
return null;
|
|
41
43
|
}
|
|
42
44
|
|
|
45
|
+
// src/listAutocomplete.ts
|
|
46
|
+
var UNORDERED_RE = /^(\s*)([-*+]) (.*)$/;
|
|
47
|
+
var ORDERED_RE = /^(\s*)(\d+)\. (.*)$/;
|
|
48
|
+
function handleListEnter(value, caret) {
|
|
49
|
+
const lineStart = value.lastIndexOf("\n", caret - 1) + 1;
|
|
50
|
+
const lineEnd = (() => {
|
|
51
|
+
const nl = value.indexOf("\n", caret);
|
|
52
|
+
return nl === -1 ? value.length : nl;
|
|
53
|
+
})();
|
|
54
|
+
const currentLine = value.slice(lineStart, lineEnd);
|
|
55
|
+
const unordered = UNORDERED_RE.exec(currentLine);
|
|
56
|
+
const ordered = ORDERED_RE.exec(currentLine);
|
|
57
|
+
const match = unordered ?? ordered;
|
|
58
|
+
if (!match) return null;
|
|
59
|
+
const indent = match[1] ?? "";
|
|
60
|
+
const marker = match[2] ?? "";
|
|
61
|
+
const content = match[3] ?? "";
|
|
62
|
+
if (content === "") {
|
|
63
|
+
const before2 = value.slice(0, lineStart);
|
|
64
|
+
const after2 = value.slice(lineEnd);
|
|
65
|
+
return { kind: "end", value: before2 + after2, caret: lineStart };
|
|
66
|
+
}
|
|
67
|
+
const nextMarker = ordered ? `${parseInt(marker, 10) + 1}.` : marker;
|
|
68
|
+
const prefix = `
|
|
69
|
+
${indent}${nextMarker} `;
|
|
70
|
+
const before = value.slice(0, caret);
|
|
71
|
+
const after = value.slice(caret);
|
|
72
|
+
return {
|
|
73
|
+
kind: "continue",
|
|
74
|
+
value: before + prefix + after,
|
|
75
|
+
caret: caret + prefix.length
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
43
79
|
// src/icons-data.ts
|
|
44
80
|
var ICONS = {
|
|
45
81
|
attachment: {
|
|
@@ -348,6 +384,17 @@ function MentionInput({
|
|
|
348
384
|
}
|
|
349
385
|
}
|
|
350
386
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
387
|
+
const ta = e.currentTarget;
|
|
388
|
+
const caret = ta.selectionStart;
|
|
389
|
+
const result = handleListEnter(value, caret);
|
|
390
|
+
if (result) {
|
|
391
|
+
e.preventDefault();
|
|
392
|
+
setValue(result.value);
|
|
393
|
+
requestAnimationFrame(() => {
|
|
394
|
+
taRef.current?.setSelectionRange(result.caret, result.caret);
|
|
395
|
+
});
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
351
398
|
e.preventDefault();
|
|
352
399
|
void submit();
|
|
353
400
|
}
|
|
@@ -444,6 +491,7 @@ function MessageComposer({
|
|
|
444
491
|
}) {
|
|
445
492
|
const [value, setValue] = useState("");
|
|
446
493
|
const [sending, setSending] = useState(false);
|
|
494
|
+
const taRef = useRef(null);
|
|
447
495
|
const submit = async () => {
|
|
448
496
|
const trimmed = value.trim();
|
|
449
497
|
if (!trimmed || sending) return;
|
|
@@ -457,6 +505,17 @@ function MessageComposer({
|
|
|
457
505
|
};
|
|
458
506
|
const onKeyDown = (e) => {
|
|
459
507
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
508
|
+
const ta = e.currentTarget;
|
|
509
|
+
const caret = ta.selectionStart;
|
|
510
|
+
const result = handleListEnter(value, caret);
|
|
511
|
+
if (result) {
|
|
512
|
+
e.preventDefault();
|
|
513
|
+
setValue(result.value);
|
|
514
|
+
requestAnimationFrame(() => {
|
|
515
|
+
taRef.current?.setSelectionRange(result.caret, result.caret);
|
|
516
|
+
});
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
460
519
|
e.preventDefault();
|
|
461
520
|
void submit();
|
|
462
521
|
}
|
|
@@ -490,6 +549,7 @@ function MessageComposer({
|
|
|
490
549
|
/* @__PURE__ */ jsx(
|
|
491
550
|
"textarea",
|
|
492
551
|
{
|
|
552
|
+
ref: taRef,
|
|
493
553
|
className: "poolse-composer__input",
|
|
494
554
|
rows: 1,
|
|
495
555
|
value,
|
|
@@ -636,24 +696,88 @@ function formatBytes(n) {
|
|
|
636
696
|
if (n < 1024 * 1024 * 1024) return `${(n / (1024 * 1024)).toFixed(1)} MB`;
|
|
637
697
|
return `${(n / (1024 * 1024 * 1024)).toFixed(2)} GB`;
|
|
638
698
|
}
|
|
699
|
+
function Avatar({ src, name, online, size = "md", className }) {
|
|
700
|
+
const initials = computeInitials(name);
|
|
701
|
+
const classes = [
|
|
702
|
+
"poolse-avatar",
|
|
703
|
+
size === "sm" ? "poolse-avatar--sm" : null,
|
|
704
|
+
size === "lg" ? "poolse-avatar--lg" : null,
|
|
705
|
+
className
|
|
706
|
+
].filter(Boolean).join(" ");
|
|
707
|
+
return /* @__PURE__ */ jsxs("span", { className: classes, "aria-label": name ?? "avatar", role: "img", children: [
|
|
708
|
+
src ? /* @__PURE__ */ jsx("img", { src, alt: name ?? "" }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: initials }),
|
|
709
|
+
online ? /* @__PURE__ */ jsx("span", { className: "poolse-avatar__presence", "aria-hidden": "true" }) : null
|
|
710
|
+
] });
|
|
711
|
+
}
|
|
712
|
+
function computeInitials(name) {
|
|
713
|
+
if (!name) return "?";
|
|
714
|
+
const parts = name.trim().split(/\s+/).slice(0, 2);
|
|
715
|
+
return parts.map((p) => p.charAt(0).toUpperCase()).join("").slice(0, 2) || "?";
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
// src/userColor.ts
|
|
719
|
+
var PALETTE = [
|
|
720
|
+
"#6366f1",
|
|
721
|
+
// indigo
|
|
722
|
+
"#10b981",
|
|
723
|
+
// emerald
|
|
724
|
+
"#f59e0b",
|
|
725
|
+
// amber
|
|
726
|
+
"#ec4899",
|
|
727
|
+
// rose
|
|
728
|
+
"#0ea5e9",
|
|
729
|
+
// sky
|
|
730
|
+
"#8b5cf6",
|
|
731
|
+
// violet
|
|
732
|
+
"#14b8a6",
|
|
733
|
+
// teal
|
|
734
|
+
"#d946ef"
|
|
735
|
+
// fuchsia
|
|
736
|
+
];
|
|
737
|
+
function userColor(userId) {
|
|
738
|
+
let h = 0;
|
|
739
|
+
for (let i = 0; i < userId.length; i++) {
|
|
740
|
+
h = h * 31 + userId.charCodeAt(i) | 0;
|
|
741
|
+
}
|
|
742
|
+
return PALETTE[Math.abs(h) % PALETTE.length];
|
|
743
|
+
}
|
|
639
744
|
function MessageBubble({
|
|
640
745
|
message,
|
|
641
746
|
currentUserId,
|
|
642
747
|
readState,
|
|
643
748
|
labelFor,
|
|
644
|
-
onQuotedClick
|
|
749
|
+
onQuotedClick,
|
|
750
|
+
groupPosition = "standalone",
|
|
751
|
+
maxBodyLength = 0,
|
|
752
|
+
markdown = false,
|
|
753
|
+
showSenderName = false
|
|
645
754
|
}) {
|
|
646
755
|
const isSelf = currentUserId !== null && message.sender_id === currentUserId;
|
|
756
|
+
const [expanded, setExpanded] = useState(false);
|
|
757
|
+
const { profile: sender } = useUser(!isSelf ? message.sender_id : null);
|
|
758
|
+
const senderFallbackName = message.sender_id ? `User ${message.sender_id.slice(0, 6)}` : "Unknown";
|
|
759
|
+
const senderName = sender?.displayName ?? senderFallbackName;
|
|
760
|
+
const senderColorHex = message.sender_id ? userColor(message.sender_id) : "currentColor";
|
|
761
|
+
const renderSenderName = showSenderName && !isSelf && (groupPosition === "first" || groupPosition === "standalone");
|
|
647
762
|
const className = [
|
|
648
763
|
"poolse-message",
|
|
649
|
-
isSelf ? "poolse-message--self" : "poolse-message--other"
|
|
764
|
+
isSelf ? "poolse-message--self" : "poolse-message--other",
|
|
765
|
+
// Group-position modifier — CSS uses it to toggle which corners
|
|
766
|
+
// get the asymmetric tail vs. fully-rounded treatment.
|
|
767
|
+
`poolse-message--${groupPosition}`
|
|
650
768
|
].join(" ");
|
|
769
|
+
const rawBody = message.body ?? "";
|
|
770
|
+
const TRIM_BUFFER = 40;
|
|
771
|
+
const shouldTrim = !expanded && maxBodyLength > 0 && rawBody.length > maxBodyLength + TRIM_BUFFER;
|
|
772
|
+
const displayBody = shouldTrim ? rawBody.slice(0, maxBodyLength).trimEnd() + "\u2026" : rawBody;
|
|
651
773
|
const time = message.inserted_at ? new Date(message.inserted_at).toLocaleTimeString(void 0, {
|
|
652
774
|
hour: "2-digit",
|
|
653
775
|
minute: "2-digit"
|
|
654
776
|
}) : "";
|
|
777
|
+
const showQuoteCard = message.quoted_message !== void 0 && message.quoted_message !== null ? "full" : message.quoted_message_id ? "placeholder" : null;
|
|
655
778
|
return /* @__PURE__ */ jsxs("div", { className, children: [
|
|
656
|
-
|
|
779
|
+
renderSenderName && /* @__PURE__ */ jsx("div", { className: "poolse-message__sender", style: { color: senderColorHex }, children: senderName }),
|
|
780
|
+
showQuoteCard === "full" && /* @__PURE__ */ jsx(
|
|
657
781
|
QuotedCard,
|
|
658
782
|
{
|
|
659
783
|
quoted: message.quoted_message,
|
|
@@ -662,7 +786,45 @@ function MessageBubble({
|
|
|
662
786
|
...onQuotedClick ? { onClick: onQuotedClick } : {}
|
|
663
787
|
}
|
|
664
788
|
),
|
|
665
|
-
|
|
789
|
+
showQuoteCard === "placeholder" && /* @__PURE__ */ jsx(QuotedPlaceholder, { isSelf, quotedMessageId: message.quoted_message_id }),
|
|
790
|
+
message.deleted_at ? /* @__PURE__ */ jsx("span", { className: "poolse-message__body--deleted", children: "[deleted]" }) : /* @__PURE__ */ jsxs("div", { className: "poolse-message__body", children: [
|
|
791
|
+
markdown ? /* @__PURE__ */ jsx(
|
|
792
|
+
ReactMarkdown,
|
|
793
|
+
{
|
|
794
|
+
remarkPlugins: [remarkGfm],
|
|
795
|
+
components: {
|
|
796
|
+
// Force links to a new tab + no opener — chat content
|
|
797
|
+
// is user-supplied so security defaults matter.
|
|
798
|
+
a: ({ node: _node, ...props }) => /* @__PURE__ */ jsx("a", { ...props, target: "_blank", rel: "noopener noreferrer nofollow" })
|
|
799
|
+
},
|
|
800
|
+
children: displayBody
|
|
801
|
+
}
|
|
802
|
+
) : /* @__PURE__ */ jsx("span", { children: displayBody }),
|
|
803
|
+
shouldTrim && /* @__PURE__ */ jsx(
|
|
804
|
+
"button",
|
|
805
|
+
{
|
|
806
|
+
type: "button",
|
|
807
|
+
className: "poolse-message__read-more",
|
|
808
|
+
onClick: (e) => {
|
|
809
|
+
e.stopPropagation();
|
|
810
|
+
setExpanded(true);
|
|
811
|
+
},
|
|
812
|
+
children: "Read more"
|
|
813
|
+
}
|
|
814
|
+
),
|
|
815
|
+
!shouldTrim && expanded && rawBody.length > maxBodyLength + TRIM_BUFFER && /* @__PURE__ */ jsx(
|
|
816
|
+
"button",
|
|
817
|
+
{
|
|
818
|
+
type: "button",
|
|
819
|
+
className: "poolse-message__read-more",
|
|
820
|
+
onClick: (e) => {
|
|
821
|
+
e.stopPropagation();
|
|
822
|
+
setExpanded(false);
|
|
823
|
+
},
|
|
824
|
+
children: "Show less"
|
|
825
|
+
}
|
|
826
|
+
)
|
|
827
|
+
] }),
|
|
666
828
|
/* @__PURE__ */ jsxs("span", { className: "poolse-message__meta", children: [
|
|
667
829
|
/* @__PURE__ */ jsx("span", { children: time }),
|
|
668
830
|
message.edited_at ? /* @__PURE__ */ jsx("span", { children: " \xB7 edited" }) : null,
|
|
@@ -677,6 +839,22 @@ function MessageBubble({
|
|
|
677
839
|
] })
|
|
678
840
|
] });
|
|
679
841
|
}
|
|
842
|
+
function QuotedPlaceholder({
|
|
843
|
+
isSelf,
|
|
844
|
+
quotedMessageId: _quotedMessageId
|
|
845
|
+
}) {
|
|
846
|
+
return /* @__PURE__ */ jsxs(
|
|
847
|
+
"div",
|
|
848
|
+
{
|
|
849
|
+
className: `poolse-quote poolse-quote--placeholder ${isSelf ? "poolse-quote--self" : "poolse-quote--other"}`,
|
|
850
|
+
"aria-label": "Quoted message",
|
|
851
|
+
children: [
|
|
852
|
+
/* @__PURE__ */ jsx("span", { className: "poolse-quote__sender", children: "Replying to a message" }),
|
|
853
|
+
/* @__PURE__ */ jsx("span", { className: "poolse-quote__body", children: "Loading preview\u2026" })
|
|
854
|
+
]
|
|
855
|
+
}
|
|
856
|
+
);
|
|
857
|
+
}
|
|
680
858
|
function QuotedCard({
|
|
681
859
|
quoted,
|
|
682
860
|
isSelf,
|
|
@@ -948,8 +1126,16 @@ function MessageRow({
|
|
|
948
1126
|
onOpenThread,
|
|
949
1127
|
onQuote,
|
|
950
1128
|
labelFor,
|
|
951
|
-
onQuotedClick
|
|
1129
|
+
onQuotedClick,
|
|
1130
|
+
groupPosition = "standalone",
|
|
1131
|
+
maxBodyLength = 0,
|
|
1132
|
+
markdown = false,
|
|
1133
|
+
showSenderName = false,
|
|
1134
|
+
showAvatar = false
|
|
952
1135
|
}) {
|
|
1136
|
+
const { profile: senderProfile } = useUser(msg.sender_id);
|
|
1137
|
+
const senderFallbackName = msg.sender_id ? `User ${msg.sender_id.slice(0, 6)}` : "Unknown";
|
|
1138
|
+
const senderName = senderProfile?.displayName ?? senderFallbackName;
|
|
953
1139
|
const isSelf = meId !== null && msg.sender_id === meId;
|
|
954
1140
|
const reactionsHook = useReactions(reactions ? msg.id : "", {
|
|
955
1141
|
conversationId: msg.conversation_id,
|
|
@@ -963,80 +1149,109 @@ function MessageRow({
|
|
|
963
1149
|
const showThreadPill = threads && !msg.deleted_at && !msg.thread_root_id && replyCount > 0;
|
|
964
1150
|
const handleSave = onSaveEdit ?? (async () => void 0);
|
|
965
1151
|
const handleCancel = onCancelEdit ?? (() => void 0);
|
|
966
|
-
return /* @__PURE__ */ jsxs(
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
message
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
currentUserId: meId,
|
|
993
|
-
onAdd: (e) => void reactionsHook.addReaction(e),
|
|
994
|
-
onRemove: (e) => void reactionsHook.removeReaction(e)
|
|
995
|
-
}
|
|
996
|
-
) }),
|
|
997
|
-
showThreadPill && /* @__PURE__ */ jsxs(
|
|
998
|
-
"button",
|
|
999
|
-
{
|
|
1000
|
-
type: "button",
|
|
1001
|
-
className: `poolse-thread-pill ${isSelf ? "poolse-thread-pill--right" : "poolse-thread-pill--left"}`,
|
|
1002
|
-
onClick: onOpenThread,
|
|
1003
|
-
"aria-label": `View ${replyCount} ${replyCount === 1 ? "reply" : "replies"}`,
|
|
1004
|
-
children: [
|
|
1005
|
-
/* @__PURE__ */ jsx(PoolseIcon, { name: "messages", size: 12, label: null }),
|
|
1006
|
-
/* @__PURE__ */ jsxs("span", { children: [
|
|
1007
|
-
replyCount,
|
|
1008
|
-
" ",
|
|
1009
|
-
replyCount === 1 ? "reply" : "replies"
|
|
1010
|
-
] })
|
|
1011
|
-
]
|
|
1012
|
-
}
|
|
1013
|
-
),
|
|
1014
|
-
showActions && /* @__PURE__ */ jsx(
|
|
1015
|
-
"div",
|
|
1016
|
-
{
|
|
1017
|
-
className: `poolse-message-row__actions ${isSelf ? "poolse-message-row__actions--right" : "poolse-message-row__actions--left"}`,
|
|
1018
|
-
children: /* @__PURE__ */ jsx(
|
|
1019
|
-
MessageActions,
|
|
1152
|
+
return /* @__PURE__ */ jsxs(
|
|
1153
|
+
"div",
|
|
1154
|
+
{
|
|
1155
|
+
className: [
|
|
1156
|
+
"poolse-message-row",
|
|
1157
|
+
isSelf ? "poolse-message-row--right" : "",
|
|
1158
|
+
// Modifier mirrors the bubble's groupPosition so the CSS can
|
|
1159
|
+
// tighten the inter-bubble gap inside a cluster (first/middle/
|
|
1160
|
+
// last) and widen it between clusters (standalone or the
|
|
1161
|
+
// first of a new run).
|
|
1162
|
+
`poolse-message-row--${groupPosition}`
|
|
1163
|
+
].filter(Boolean).join(" "),
|
|
1164
|
+
"data-message-id": msg.id,
|
|
1165
|
+
children: [
|
|
1166
|
+
editing ? /* @__PURE__ */ jsx(
|
|
1167
|
+
EditableMessageBubble,
|
|
1168
|
+
{
|
|
1169
|
+
message: msg,
|
|
1170
|
+
currentUserId: meId,
|
|
1171
|
+
...readState ? { readState } : {},
|
|
1172
|
+
editing: true,
|
|
1173
|
+
onSave: handleSave,
|
|
1174
|
+
onCancel: handleCancel
|
|
1175
|
+
}
|
|
1176
|
+
) : /* @__PURE__ */ jsx(
|
|
1177
|
+
BubbleWithAvatar,
|
|
1020
1178
|
{
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1179
|
+
isSelf,
|
|
1180
|
+
showAvatar,
|
|
1181
|
+
groupPosition,
|
|
1182
|
+
senderName,
|
|
1183
|
+
avatarUrl: senderProfile?.avatarUrl ?? null,
|
|
1184
|
+
children: /* @__PURE__ */ jsx(
|
|
1185
|
+
MessageBubble,
|
|
1186
|
+
{
|
|
1187
|
+
message: msg,
|
|
1188
|
+
currentUserId: meId,
|
|
1189
|
+
groupPosition,
|
|
1190
|
+
maxBodyLength,
|
|
1191
|
+
markdown,
|
|
1192
|
+
showSenderName,
|
|
1193
|
+
...readState ? { readState } : {},
|
|
1194
|
+
...labelFor ? { labelFor } : {},
|
|
1195
|
+
...onQuotedClick ? { onQuotedClick } : {}
|
|
1024
1196
|
}
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1197
|
+
)
|
|
1198
|
+
}
|
|
1199
|
+
),
|
|
1200
|
+
showAttachments && /* @__PURE__ */ jsx("div", { className: `poolse-message-row__attachments ${isSelf ? "is-self" : ""}`, children: msg.attachments.map((att) => /* @__PURE__ */ jsx(AttachmentPreview, { attachment: att }, att.id)) }),
|
|
1201
|
+
showReactions && /* @__PURE__ */ jsx("div", { className: `poolse-message-row__reactions ${isSelf ? "is-self" : ""}`, children: /* @__PURE__ */ jsx(
|
|
1202
|
+
InlineReactions,
|
|
1203
|
+
{
|
|
1204
|
+
reactions: reactionsHook.reactions,
|
|
1205
|
+
currentUserId: meId,
|
|
1206
|
+
onAdd: (e) => void reactionsHook.addReaction(e),
|
|
1207
|
+
onRemove: (e) => void reactionsHook.removeReaction(e)
|
|
1208
|
+
}
|
|
1209
|
+
) }),
|
|
1210
|
+
showThreadPill && /* @__PURE__ */ jsxs(
|
|
1211
|
+
"button",
|
|
1212
|
+
{
|
|
1213
|
+
type: "button",
|
|
1214
|
+
className: `poolse-thread-pill ${isSelf ? "poolse-thread-pill--right" : "poolse-thread-pill--left"}`,
|
|
1215
|
+
onClick: onOpenThread,
|
|
1216
|
+
"aria-label": `View ${replyCount} ${replyCount === 1 ? "reply" : "replies"}`,
|
|
1217
|
+
children: [
|
|
1218
|
+
/* @__PURE__ */ jsx(PoolseIcon, { name: "messages", size: 12, label: null }),
|
|
1219
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
1220
|
+
replyCount,
|
|
1221
|
+
" ",
|
|
1222
|
+
replyCount === 1 ? "reply" : "replies"
|
|
1223
|
+
] })
|
|
1224
|
+
]
|
|
1225
|
+
}
|
|
1226
|
+
),
|
|
1227
|
+
showActions && /* @__PURE__ */ jsx(
|
|
1228
|
+
"div",
|
|
1229
|
+
{
|
|
1230
|
+
className: `poolse-message-row__actions ${isSelf ? "poolse-message-row__actions--right" : "poolse-message-row__actions--left"}`,
|
|
1231
|
+
children: /* @__PURE__ */ jsx(
|
|
1232
|
+
MessageActions,
|
|
1233
|
+
{
|
|
1234
|
+
...reactions ? {
|
|
1235
|
+
onReact: (emoji) => {
|
|
1236
|
+
void reactionsHook.addReaction(emoji);
|
|
1237
|
+
}
|
|
1238
|
+
} : {},
|
|
1239
|
+
...threads && onOpenThread ? { onReply: onOpenThread } : {},
|
|
1240
|
+
...quotations && onQuote ? { onQuote } : {},
|
|
1241
|
+
...msg.body ? {
|
|
1242
|
+
onCopy: () => {
|
|
1243
|
+
void navigator?.clipboard?.writeText(msg.body ?? "").catch(() => void 0);
|
|
1244
|
+
}
|
|
1245
|
+
} : {},
|
|
1246
|
+
...isSelf && onStartEdit ? { onEdit: onStartEdit } : {},
|
|
1247
|
+
...isSelf && onDelete ? { onDelete } : {}
|
|
1031
1248
|
}
|
|
1032
|
-
|
|
1033
|
-
...isSelf && onStartEdit ? { onEdit: onStartEdit } : {},
|
|
1034
|
-
...isSelf && onDelete ? { onDelete } : {}
|
|
1249
|
+
)
|
|
1035
1250
|
}
|
|
1036
1251
|
)
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1252
|
+
]
|
|
1253
|
+
}
|
|
1254
|
+
);
|
|
1040
1255
|
}
|
|
1041
1256
|
function InlineReactions({
|
|
1042
1257
|
reactions,
|
|
@@ -1068,6 +1283,21 @@ function InlineReactions({
|
|
|
1068
1283
|
);
|
|
1069
1284
|
}) });
|
|
1070
1285
|
}
|
|
1286
|
+
function BubbleWithAvatar({
|
|
1287
|
+
isSelf,
|
|
1288
|
+
showAvatar,
|
|
1289
|
+
groupPosition,
|
|
1290
|
+
senderName,
|
|
1291
|
+
avatarUrl,
|
|
1292
|
+
children
|
|
1293
|
+
}) {
|
|
1294
|
+
if (isSelf || !showAvatar) return /* @__PURE__ */ jsx(Fragment, { children });
|
|
1295
|
+
const isLastOfCluster = groupPosition === "last" || groupPosition === "standalone";
|
|
1296
|
+
return /* @__PURE__ */ jsxs("div", { className: "poolse-bubble-shell", children: [
|
|
1297
|
+
/* @__PURE__ */ jsx("div", { className: "poolse-bubble-shell__avatar", children: isLastOfCluster ? /* @__PURE__ */ jsx(Avatar, { src: avatarUrl, name: senderName, size: "sm" }) : null }),
|
|
1298
|
+
children
|
|
1299
|
+
] });
|
|
1300
|
+
}
|
|
1071
1301
|
function ThreadView({
|
|
1072
1302
|
conversationId,
|
|
1073
1303
|
rootMessage,
|
|
@@ -1157,6 +1387,13 @@ function ConversationView({
|
|
|
1157
1387
|
threads = TRUE,
|
|
1158
1388
|
quotations = TRUE,
|
|
1159
1389
|
readReceipts = TRUE,
|
|
1390
|
+
markdown = TRUE,
|
|
1391
|
+
maxBodyLength = 200,
|
|
1392
|
+
grouping = TRUE,
|
|
1393
|
+
groupingWindowMs = 5 * 60 * 1e3,
|
|
1394
|
+
daySeparators = TRUE,
|
|
1395
|
+
senderLabels = "auto",
|
|
1396
|
+
avatars = "auto",
|
|
1160
1397
|
onMarkedRead
|
|
1161
1398
|
}) {
|
|
1162
1399
|
usePoolseFonts(loadFonts);
|
|
@@ -1174,8 +1411,12 @@ function ConversationView({
|
|
|
1174
1411
|
} = useMessages(conversationId);
|
|
1175
1412
|
const { typing, signalTyping } = useTyping(conversationId);
|
|
1176
1413
|
const status = useRealtimeStatus();
|
|
1177
|
-
const
|
|
1414
|
+
const wantsMemberCount = senderLabels === "auto" || avatars === "auto";
|
|
1415
|
+
const membersOn = mentions || readReceipts || wantsMemberCount;
|
|
1178
1416
|
const { members } = useMembers(membersOn ? conversationId : "");
|
|
1417
|
+
const isGroupChat = members.length > 2;
|
|
1418
|
+
const showSenderLabelsResolved = senderLabels === "always" || senderLabels === "auto" && isGroupChat;
|
|
1419
|
+
const showAvatarsResolved = avatars === "always" || avatars === "auto" && isGroupChat;
|
|
1179
1420
|
const listRef = useRef(null);
|
|
1180
1421
|
const lastMessageIdRef = useRef(null);
|
|
1181
1422
|
const bottomSentinelRef = useRef(null);
|
|
@@ -1322,10 +1563,14 @@ function ConversationView({
|
|
|
1322
1563
|
] }),
|
|
1323
1564
|
/* @__PURE__ */ jsxs("div", { className: "poolse-conversation__messages", ref: listRef, children: [
|
|
1324
1565
|
hasMore && !loading && /* @__PURE__ */ jsx("button", { type: "button", className: "poolse-conversation__load-more", onClick: loadMore, children: "Load older messages" }),
|
|
1325
|
-
loading && messages.length === 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-conversation__empty", children: "Loading\u2026" }) : messages.length === 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-conversation__empty", children: emptyState ?? "No messages yet." }) : messages.map((msg) => {
|
|
1566
|
+
loading && messages.length === 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-conversation__empty", children: "Loading\u2026" }) : messages.length === 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-conversation__empty", children: emptyState ?? "No messages yet." }) : messages.map((msg, idx) => {
|
|
1326
1567
|
if (renderMessage) {
|
|
1327
1568
|
return /* @__PURE__ */ jsx(Fragment$1, { children: renderMessage(msg, me?.id ?? null) }, msg.id);
|
|
1328
1569
|
}
|
|
1570
|
+
const prev = idx > 0 ? messages[idx - 1] ?? null : null;
|
|
1571
|
+
const next = idx < messages.length - 1 ? messages[idx + 1] ?? null : null;
|
|
1572
|
+
const groupPosition = grouping ? computeGroupPosition(msg, prev, next, groupingWindowMs) : "standalone";
|
|
1573
|
+
const showDaySeparator = daySeparators && (prev === null || !sameDay(msg.inserted_at, prev.inserted_at));
|
|
1329
1574
|
const enriched = quotations && msg.quoted_message_id && !msg.quoted_message ? (() => {
|
|
1330
1575
|
const original = messages.find((m) => m.id === msg.quoted_message_id);
|
|
1331
1576
|
if (!original) return msg;
|
|
@@ -1342,31 +1587,39 @@ function ConversationView({
|
|
|
1342
1587
|
})() : msg;
|
|
1343
1588
|
const isSelf = me !== null && msg.sender_id === me.id;
|
|
1344
1589
|
const readState = readReceipts && isSelf && maxReadByOthers !== null ? maxReadByOthers >= msg.sequence ? "read" : "sent" : void 0;
|
|
1345
|
-
return /* @__PURE__ */
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1590
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
1591
|
+
showDaySeparator && /* @__PURE__ */ jsx("div", { className: "poolse-day-separator", "aria-hidden": "false", children: /* @__PURE__ */ jsx("span", { children: formatDayLabel(msg.inserted_at) }) }),
|
|
1592
|
+
/* @__PURE__ */ jsx(
|
|
1593
|
+
MessageRow,
|
|
1594
|
+
{
|
|
1595
|
+
msg: enriched,
|
|
1596
|
+
meId: me?.id ?? null,
|
|
1597
|
+
reactions,
|
|
1598
|
+
attachments,
|
|
1599
|
+
actions,
|
|
1600
|
+
threads,
|
|
1601
|
+
quotations,
|
|
1602
|
+
groupPosition,
|
|
1603
|
+
maxBodyLength,
|
|
1604
|
+
markdown,
|
|
1605
|
+
showSenderName: showSenderLabelsResolved,
|
|
1606
|
+
showAvatar: showAvatarsResolved,
|
|
1607
|
+
...readState ? { readState } : {},
|
|
1608
|
+
...labelFor ? { labelFor } : {},
|
|
1609
|
+
editing: editingId === msg.id,
|
|
1610
|
+
onStartEdit: () => setEditingId(msg.id),
|
|
1611
|
+
onCancelEdit: () => setEditingId(null),
|
|
1612
|
+
onSaveEdit: async (body) => {
|
|
1613
|
+
await edit(msg.id, body);
|
|
1614
|
+
setEditingId(null);
|
|
1615
|
+
},
|
|
1616
|
+
onDelete: () => void deleteMsg(msg.id),
|
|
1617
|
+
onOpenThread: () => setThreadRootId(msg.id),
|
|
1618
|
+
onQuote: () => setReplyingTo(msg),
|
|
1619
|
+
onQuotedClick: scrollToOriginal
|
|
1620
|
+
}
|
|
1621
|
+
)
|
|
1622
|
+
] }, msg.id);
|
|
1370
1623
|
}),
|
|
1371
1624
|
error && /* @__PURE__ */ jsxs("div", { className: "poolse-conversation__empty", children: [
|
|
1372
1625
|
"Failed to load: ",
|
|
@@ -1437,23 +1690,41 @@ function AttachmentPickerButton({
|
|
|
1437
1690
|
)
|
|
1438
1691
|
] });
|
|
1439
1692
|
}
|
|
1440
|
-
function
|
|
1441
|
-
const
|
|
1442
|
-
const
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
].filter(Boolean).join(" ");
|
|
1448
|
-
return /* @__PURE__ */ jsxs("span", { className: classes, "aria-label": name ?? "avatar", role: "img", children: [
|
|
1449
|
-
src ? /* @__PURE__ */ jsx("img", { src, alt: name ?? "" }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: initials }),
|
|
1450
|
-
online ? /* @__PURE__ */ jsx("span", { className: "poolse-avatar__presence", "aria-hidden": "true" }) : null
|
|
1451
|
-
] });
|
|
1693
|
+
function computeGroupPosition(msg, prev, next, windowMs) {
|
|
1694
|
+
const continuesPrev = sameGroup(msg, prev, windowMs);
|
|
1695
|
+
const continuesNext = sameGroup(next, msg, windowMs);
|
|
1696
|
+
if (continuesPrev && continuesNext) return "middle";
|
|
1697
|
+
if (continuesPrev) return "last";
|
|
1698
|
+
if (continuesNext) return "first";
|
|
1699
|
+
return "standalone";
|
|
1452
1700
|
}
|
|
1453
|
-
function
|
|
1454
|
-
if (!
|
|
1455
|
-
|
|
1456
|
-
|
|
1701
|
+
function sameGroup(a, b, windowMs) {
|
|
1702
|
+
if (!a || !b) return false;
|
|
1703
|
+
if (a.sender_id !== b.sender_id) return false;
|
|
1704
|
+
if (!sameDay(a.inserted_at, b.inserted_at)) return false;
|
|
1705
|
+
const ta = new Date(a.inserted_at).getTime();
|
|
1706
|
+
const tb = new Date(b.inserted_at).getTime();
|
|
1707
|
+
return Math.abs(ta - tb) <= windowMs;
|
|
1708
|
+
}
|
|
1709
|
+
function sameDay(a, b) {
|
|
1710
|
+
const da = new Date(a);
|
|
1711
|
+
const db = new Date(b);
|
|
1712
|
+
return da.getFullYear() === db.getFullYear() && da.getMonth() === db.getMonth() && da.getDate() === db.getDate();
|
|
1713
|
+
}
|
|
1714
|
+
function formatDayLabel(iso) {
|
|
1715
|
+
const d = new Date(iso);
|
|
1716
|
+
const now = /* @__PURE__ */ new Date();
|
|
1717
|
+
const startOfDay = (x) => new Date(x.getFullYear(), x.getMonth(), x.getDate()).getTime();
|
|
1718
|
+
const diffDays = Math.floor((startOfDay(now) - startOfDay(d)) / 864e5);
|
|
1719
|
+
if (diffDays === 0) return "Today";
|
|
1720
|
+
if (diffDays === 1) return "Yesterday";
|
|
1721
|
+
if (diffDays < 7) {
|
|
1722
|
+
return d.toLocaleDateString(void 0, { weekday: "long" });
|
|
1723
|
+
}
|
|
1724
|
+
if (d.getFullYear() === now.getFullYear()) {
|
|
1725
|
+
return d.toLocaleDateString(void 0, { weekday: "short", day: "numeric", month: "short" });
|
|
1726
|
+
}
|
|
1727
|
+
return d.toLocaleDateString(void 0, { day: "numeric", month: "short", year: "numeric" });
|
|
1457
1728
|
}
|
|
1458
1729
|
function ConversationList({
|
|
1459
1730
|
selectedId,
|