@poolse/react-ui 1.0.0-beta.0 → 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/dist/index.cjs +305 -55
- 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 +301 -56
- package/dist/index.js.map +1 -1
- package/dist/styles.css +228 -9
- package/package.json +5 -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,40 @@ function PoolseFonts() {
|
|
|
42
49
|
return null;
|
|
43
50
|
}
|
|
44
51
|
|
|
52
|
+
// src/listAutocomplete.ts
|
|
53
|
+
var UNORDERED_RE = /^(\s*)([-*+]) (.*)$/;
|
|
54
|
+
var ORDERED_RE = /^(\s*)(\d+)\. (.*)$/;
|
|
55
|
+
function handleListEnter(value, caret) {
|
|
56
|
+
const lineStart = value.lastIndexOf("\n", caret - 1) + 1;
|
|
57
|
+
const lineEnd = (() => {
|
|
58
|
+
const nl = value.indexOf("\n", caret);
|
|
59
|
+
return nl === -1 ? value.length : nl;
|
|
60
|
+
})();
|
|
61
|
+
const currentLine = value.slice(lineStart, lineEnd);
|
|
62
|
+
const unordered = UNORDERED_RE.exec(currentLine);
|
|
63
|
+
const ordered = ORDERED_RE.exec(currentLine);
|
|
64
|
+
const match = unordered ?? ordered;
|
|
65
|
+
if (!match) return null;
|
|
66
|
+
const indent = match[1] ?? "";
|
|
67
|
+
const marker = match[2] ?? "";
|
|
68
|
+
const content = match[3] ?? "";
|
|
69
|
+
if (content === "") {
|
|
70
|
+
const before2 = value.slice(0, lineStart);
|
|
71
|
+
const after2 = value.slice(lineEnd);
|
|
72
|
+
return { kind: "end", value: before2 + after2, caret: lineStart };
|
|
73
|
+
}
|
|
74
|
+
const nextMarker = ordered ? `${parseInt(marker, 10) + 1}.` : marker;
|
|
75
|
+
const prefix = `
|
|
76
|
+
${indent}${nextMarker} `;
|
|
77
|
+
const before = value.slice(0, caret);
|
|
78
|
+
const after = value.slice(caret);
|
|
79
|
+
return {
|
|
80
|
+
kind: "continue",
|
|
81
|
+
value: before + prefix + after,
|
|
82
|
+
caret: caret + prefix.length
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
45
86
|
// src/icons-data.ts
|
|
46
87
|
var ICONS = {
|
|
47
88
|
attachment: {
|
|
@@ -350,6 +391,17 @@ function MentionInput({
|
|
|
350
391
|
}
|
|
351
392
|
}
|
|
352
393
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
394
|
+
const ta = e.currentTarget;
|
|
395
|
+
const caret = ta.selectionStart;
|
|
396
|
+
const result = handleListEnter(value, caret);
|
|
397
|
+
if (result) {
|
|
398
|
+
e.preventDefault();
|
|
399
|
+
setValue(result.value);
|
|
400
|
+
requestAnimationFrame(() => {
|
|
401
|
+
taRef.current?.setSelectionRange(result.caret, result.caret);
|
|
402
|
+
});
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
353
405
|
e.preventDefault();
|
|
354
406
|
void submit();
|
|
355
407
|
}
|
|
@@ -446,6 +498,7 @@ function MessageComposer({
|
|
|
446
498
|
}) {
|
|
447
499
|
const [value, setValue] = react.useState("");
|
|
448
500
|
const [sending, setSending] = react.useState(false);
|
|
501
|
+
const taRef = react.useRef(null);
|
|
449
502
|
const submit = async () => {
|
|
450
503
|
const trimmed = value.trim();
|
|
451
504
|
if (!trimmed || sending) return;
|
|
@@ -459,6 +512,17 @@ function MessageComposer({
|
|
|
459
512
|
};
|
|
460
513
|
const onKeyDown = (e) => {
|
|
461
514
|
if (e.key === "Enter" && !e.shiftKey) {
|
|
515
|
+
const ta = e.currentTarget;
|
|
516
|
+
const caret = ta.selectionStart;
|
|
517
|
+
const result = handleListEnter(value, caret);
|
|
518
|
+
if (result) {
|
|
519
|
+
e.preventDefault();
|
|
520
|
+
setValue(result.value);
|
|
521
|
+
requestAnimationFrame(() => {
|
|
522
|
+
taRef.current?.setSelectionRange(result.caret, result.caret);
|
|
523
|
+
});
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
462
526
|
e.preventDefault();
|
|
463
527
|
void submit();
|
|
464
528
|
}
|
|
@@ -492,6 +556,7 @@ function MessageComposer({
|
|
|
492
556
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
493
557
|
"textarea",
|
|
494
558
|
{
|
|
559
|
+
ref: taRef,
|
|
495
560
|
className: "poolse-composer__input",
|
|
496
561
|
rows: 1,
|
|
497
562
|
value,
|
|
@@ -638,24 +703,87 @@ function formatBytes(n) {
|
|
|
638
703
|
if (n < 1024 * 1024 * 1024) return `${(n / (1024 * 1024)).toFixed(1)} MB`;
|
|
639
704
|
return `${(n / (1024 * 1024 * 1024)).toFixed(2)} GB`;
|
|
640
705
|
}
|
|
706
|
+
function Avatar({ src, name, online, size = "md", className }) {
|
|
707
|
+
const initials = computeInitials(name);
|
|
708
|
+
const classes = [
|
|
709
|
+
"poolse-avatar",
|
|
710
|
+
size === "sm" ? "poolse-avatar--sm" : null,
|
|
711
|
+
size === "lg" ? "poolse-avatar--lg" : null,
|
|
712
|
+
className
|
|
713
|
+
].filter(Boolean).join(" ");
|
|
714
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: classes, "aria-label": name ?? "avatar", role: "img", children: [
|
|
715
|
+
src ? /* @__PURE__ */ jsxRuntime.jsx("img", { src, alt: name ?? "" }) : /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", children: initials }),
|
|
716
|
+
online ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-avatar__presence", "aria-hidden": "true" }) : null
|
|
717
|
+
] });
|
|
718
|
+
}
|
|
719
|
+
function computeInitials(name) {
|
|
720
|
+
if (!name) return "?";
|
|
721
|
+
const parts = name.trim().split(/\s+/).slice(0, 2);
|
|
722
|
+
return parts.map((p) => p.charAt(0).toUpperCase()).join("").slice(0, 2) || "?";
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
// src/userColor.ts
|
|
726
|
+
var PALETTE = [
|
|
727
|
+
"#6366f1",
|
|
728
|
+
// indigo
|
|
729
|
+
"#10b981",
|
|
730
|
+
// emerald
|
|
731
|
+
"#f59e0b",
|
|
732
|
+
// amber
|
|
733
|
+
"#ec4899",
|
|
734
|
+
// rose
|
|
735
|
+
"#0ea5e9",
|
|
736
|
+
// sky
|
|
737
|
+
"#8b5cf6",
|
|
738
|
+
// violet
|
|
739
|
+
"#14b8a6",
|
|
740
|
+
// teal
|
|
741
|
+
"#d946ef"
|
|
742
|
+
// fuchsia
|
|
743
|
+
];
|
|
744
|
+
function userColor(userId) {
|
|
745
|
+
let h = 0;
|
|
746
|
+
for (let i = 0; i < userId.length; i++) {
|
|
747
|
+
h = h * 31 + userId.charCodeAt(i) | 0;
|
|
748
|
+
}
|
|
749
|
+
return PALETTE[Math.abs(h) % PALETTE.length];
|
|
750
|
+
}
|
|
641
751
|
function MessageBubble({
|
|
642
752
|
message,
|
|
643
753
|
currentUserId,
|
|
644
754
|
readState,
|
|
645
755
|
labelFor,
|
|
646
|
-
onQuotedClick
|
|
756
|
+
onQuotedClick,
|
|
757
|
+
groupPosition = "standalone",
|
|
758
|
+
maxBodyLength = 0,
|
|
759
|
+
markdown = false,
|
|
760
|
+
showSenderName = false
|
|
647
761
|
}) {
|
|
648
762
|
const isSelf = currentUserId !== null && message.sender_id === currentUserId;
|
|
763
|
+
const [expanded, setExpanded] = react.useState(false);
|
|
764
|
+
const { profile: sender } = react$1.useUser(!isSelf ? message.sender_id : null);
|
|
765
|
+
const senderFallbackName = message.sender_id ? `User ${message.sender_id.slice(0, 6)}` : "Unknown";
|
|
766
|
+
const senderName = sender?.displayName ?? senderFallbackName;
|
|
767
|
+
const senderColorHex = message.sender_id ? userColor(message.sender_id) : "currentColor";
|
|
768
|
+
const renderSenderName = showSenderName && !isSelf && (groupPosition === "first" || groupPosition === "standalone");
|
|
649
769
|
const className = [
|
|
650
770
|
"poolse-message",
|
|
651
|
-
isSelf ? "poolse-message--self" : "poolse-message--other"
|
|
771
|
+
isSelf ? "poolse-message--self" : "poolse-message--other",
|
|
772
|
+
// Group-position modifier — CSS uses it to toggle which corners
|
|
773
|
+
// get the asymmetric tail vs. fully-rounded treatment.
|
|
774
|
+
`poolse-message--${groupPosition}`
|
|
652
775
|
].join(" ");
|
|
776
|
+
const rawBody = message.body ?? "";
|
|
777
|
+
const TRIM_BUFFER = 40;
|
|
778
|
+
const shouldTrim = !expanded && maxBodyLength > 0 && rawBody.length > maxBodyLength + TRIM_BUFFER;
|
|
779
|
+
const displayBody = shouldTrim ? rawBody.slice(0, maxBodyLength).trimEnd() + "\u2026" : rawBody;
|
|
653
780
|
const time = message.inserted_at ? new Date(message.inserted_at).toLocaleTimeString(void 0, {
|
|
654
781
|
hour: "2-digit",
|
|
655
782
|
minute: "2-digit"
|
|
656
783
|
}) : "";
|
|
657
784
|
const showQuoteCard = message.quoted_message !== void 0 && message.quoted_message !== null ? "full" : message.quoted_message_id ? "placeholder" : null;
|
|
658
785
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, children: [
|
|
786
|
+
renderSenderName && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-message__sender", style: { color: senderColorHex }, children: senderName }),
|
|
659
787
|
showQuoteCard === "full" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
660
788
|
QuotedCard,
|
|
661
789
|
{
|
|
@@ -666,7 +794,44 @@ function MessageBubble({
|
|
|
666
794
|
}
|
|
667
795
|
),
|
|
668
796
|
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.
|
|
797
|
+
message.deleted_at ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-message__body--deleted", children: "[deleted]" }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-message__body", children: [
|
|
798
|
+
markdown ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
799
|
+
ReactMarkdown__default.default,
|
|
800
|
+
{
|
|
801
|
+
remarkPlugins: [remarkGfm__default.default],
|
|
802
|
+
components: {
|
|
803
|
+
// Force links to a new tab + no opener — chat content
|
|
804
|
+
// is user-supplied so security defaults matter.
|
|
805
|
+
a: ({ node: _node, ...props }) => /* @__PURE__ */ jsxRuntime.jsx("a", { ...props, target: "_blank", rel: "noopener noreferrer nofollow" })
|
|
806
|
+
},
|
|
807
|
+
children: displayBody
|
|
808
|
+
}
|
|
809
|
+
) : /* @__PURE__ */ jsxRuntime.jsx("span", { children: displayBody }),
|
|
810
|
+
shouldTrim && /* @__PURE__ */ jsxRuntime.jsx(
|
|
811
|
+
"button",
|
|
812
|
+
{
|
|
813
|
+
type: "button",
|
|
814
|
+
className: "poolse-message__read-more",
|
|
815
|
+
onClick: (e) => {
|
|
816
|
+
e.stopPropagation();
|
|
817
|
+
setExpanded(true);
|
|
818
|
+
},
|
|
819
|
+
children: "Read more"
|
|
820
|
+
}
|
|
821
|
+
),
|
|
822
|
+
!shouldTrim && expanded && rawBody.length > maxBodyLength + TRIM_BUFFER && /* @__PURE__ */ jsxRuntime.jsx(
|
|
823
|
+
"button",
|
|
824
|
+
{
|
|
825
|
+
type: "button",
|
|
826
|
+
className: "poolse-message__read-more",
|
|
827
|
+
onClick: (e) => {
|
|
828
|
+
e.stopPropagation();
|
|
829
|
+
setExpanded(false);
|
|
830
|
+
},
|
|
831
|
+
children: "Show less"
|
|
832
|
+
}
|
|
833
|
+
)
|
|
834
|
+
] }),
|
|
670
835
|
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "poolse-message__meta", children: [
|
|
671
836
|
/* @__PURE__ */ jsxRuntime.jsx("span", { children: time }),
|
|
672
837
|
message.edited_at ? /* @__PURE__ */ jsxRuntime.jsx("span", { children: " \xB7 edited" }) : null,
|
|
@@ -968,8 +1133,16 @@ function MessageRow({
|
|
|
968
1133
|
onOpenThread,
|
|
969
1134
|
onQuote,
|
|
970
1135
|
labelFor,
|
|
971
|
-
onQuotedClick
|
|
1136
|
+
onQuotedClick,
|
|
1137
|
+
groupPosition = "standalone",
|
|
1138
|
+
maxBodyLength = 0,
|
|
1139
|
+
markdown = false,
|
|
1140
|
+
showSenderName = false,
|
|
1141
|
+
showAvatar = false
|
|
972
1142
|
}) {
|
|
1143
|
+
const { profile: senderProfile } = react$1.useUser(msg.sender_id);
|
|
1144
|
+
const senderFallbackName = msg.sender_id ? `User ${msg.sender_id.slice(0, 6)}` : "Unknown";
|
|
1145
|
+
const senderName = senderProfile?.displayName ?? senderFallbackName;
|
|
973
1146
|
const isSelf = meId !== null && msg.sender_id === meId;
|
|
974
1147
|
const reactionsHook = react$1.useReactions(reactions ? msg.id : "", {
|
|
975
1148
|
conversationId: msg.conversation_id,
|
|
@@ -986,7 +1159,15 @@ function MessageRow({
|
|
|
986
1159
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
987
1160
|
"div",
|
|
988
1161
|
{
|
|
989
|
-
className:
|
|
1162
|
+
className: [
|
|
1163
|
+
"poolse-message-row",
|
|
1164
|
+
isSelf ? "poolse-message-row--right" : "",
|
|
1165
|
+
// Modifier mirrors the bubble's groupPosition so the CSS can
|
|
1166
|
+
// tighten the inter-bubble gap inside a cluster (first/middle/
|
|
1167
|
+
// last) and widen it between clusters (standalone or the
|
|
1168
|
+
// first of a new run).
|
|
1169
|
+
`poolse-message-row--${groupPosition}`
|
|
1170
|
+
].filter(Boolean).join(" "),
|
|
990
1171
|
"data-message-id": msg.id,
|
|
991
1172
|
children: [
|
|
992
1173
|
editing ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -1000,13 +1181,27 @@ function MessageRow({
|
|
|
1000
1181
|
onCancel: handleCancel
|
|
1001
1182
|
}
|
|
1002
1183
|
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
1003
|
-
|
|
1184
|
+
BubbleWithAvatar,
|
|
1004
1185
|
{
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1186
|
+
isSelf,
|
|
1187
|
+
showAvatar,
|
|
1188
|
+
groupPosition,
|
|
1189
|
+
senderName,
|
|
1190
|
+
avatarUrl: senderProfile?.avatarUrl ?? null,
|
|
1191
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1192
|
+
MessageBubble,
|
|
1193
|
+
{
|
|
1194
|
+
message: msg,
|
|
1195
|
+
currentUserId: meId,
|
|
1196
|
+
groupPosition,
|
|
1197
|
+
maxBodyLength,
|
|
1198
|
+
markdown,
|
|
1199
|
+
showSenderName,
|
|
1200
|
+
...readState ? { readState } : {},
|
|
1201
|
+
...labelFor ? { labelFor } : {},
|
|
1202
|
+
...onQuotedClick ? { onQuotedClick } : {}
|
|
1203
|
+
}
|
|
1204
|
+
)
|
|
1010
1205
|
}
|
|
1011
1206
|
),
|
|
1012
1207
|
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)) }),
|
|
@@ -1095,6 +1290,21 @@ function InlineReactions({
|
|
|
1095
1290
|
);
|
|
1096
1291
|
}) });
|
|
1097
1292
|
}
|
|
1293
|
+
function BubbleWithAvatar({
|
|
1294
|
+
isSelf,
|
|
1295
|
+
showAvatar,
|
|
1296
|
+
groupPosition,
|
|
1297
|
+
senderName,
|
|
1298
|
+
avatarUrl,
|
|
1299
|
+
children
|
|
1300
|
+
}) {
|
|
1301
|
+
if (isSelf || !showAvatar) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
|
|
1302
|
+
const isLastOfCluster = groupPosition === "last" || groupPosition === "standalone";
|
|
1303
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-bubble-shell", children: [
|
|
1304
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-bubble-shell__avatar", children: isLastOfCluster ? /* @__PURE__ */ jsxRuntime.jsx(Avatar, { src: avatarUrl, name: senderName, size: "sm" }) : null }),
|
|
1305
|
+
children
|
|
1306
|
+
] });
|
|
1307
|
+
}
|
|
1098
1308
|
function ThreadView({
|
|
1099
1309
|
conversationId,
|
|
1100
1310
|
rootMessage,
|
|
@@ -1184,6 +1394,13 @@ function ConversationView({
|
|
|
1184
1394
|
threads = TRUE,
|
|
1185
1395
|
quotations = TRUE,
|
|
1186
1396
|
readReceipts = TRUE,
|
|
1397
|
+
markdown = TRUE,
|
|
1398
|
+
maxBodyLength = 200,
|
|
1399
|
+
grouping = TRUE,
|
|
1400
|
+
groupingWindowMs = 5 * 60 * 1e3,
|
|
1401
|
+
daySeparators = TRUE,
|
|
1402
|
+
senderLabels = "auto",
|
|
1403
|
+
avatars = "auto",
|
|
1187
1404
|
onMarkedRead
|
|
1188
1405
|
}) {
|
|
1189
1406
|
usePoolseFonts(loadFonts);
|
|
@@ -1201,8 +1418,12 @@ function ConversationView({
|
|
|
1201
1418
|
} = react$1.useMessages(conversationId);
|
|
1202
1419
|
const { typing, signalTyping } = react$1.useTyping(conversationId);
|
|
1203
1420
|
const status = react$1.useRealtimeStatus();
|
|
1204
|
-
const
|
|
1421
|
+
const wantsMemberCount = senderLabels === "auto" || avatars === "auto";
|
|
1422
|
+
const membersOn = mentions || readReceipts || wantsMemberCount;
|
|
1205
1423
|
const { members } = react$1.useMembers(membersOn ? conversationId : "");
|
|
1424
|
+
const isGroupChat = members.length > 2;
|
|
1425
|
+
const showSenderLabelsResolved = senderLabels === "always" || senderLabels === "auto" && isGroupChat;
|
|
1426
|
+
const showAvatarsResolved = avatars === "always" || avatars === "auto" && isGroupChat;
|
|
1206
1427
|
const listRef = react.useRef(null);
|
|
1207
1428
|
const lastMessageIdRef = react.useRef(null);
|
|
1208
1429
|
const bottomSentinelRef = react.useRef(null);
|
|
@@ -1349,10 +1570,14 @@ function ConversationView({
|
|
|
1349
1570
|
] }),
|
|
1350
1571
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-conversation__messages", ref: listRef, children: [
|
|
1351
1572
|
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) => {
|
|
1573
|
+
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) => {
|
|
1353
1574
|
if (renderMessage) {
|
|
1354
1575
|
return /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: renderMessage(msg, me?.id ?? null) }, msg.id);
|
|
1355
1576
|
}
|
|
1577
|
+
const prev = idx > 0 ? messages[idx - 1] ?? null : null;
|
|
1578
|
+
const next = idx < messages.length - 1 ? messages[idx + 1] ?? null : null;
|
|
1579
|
+
const groupPosition = grouping ? computeGroupPosition(msg, prev, next, groupingWindowMs) : "standalone";
|
|
1580
|
+
const showDaySeparator = daySeparators && (prev === null || !sameDay(msg.inserted_at, prev.inserted_at));
|
|
1356
1581
|
const enriched = quotations && msg.quoted_message_id && !msg.quoted_message ? (() => {
|
|
1357
1582
|
const original = messages.find((m) => m.id === msg.quoted_message_id);
|
|
1358
1583
|
if (!original) return msg;
|
|
@@ -1369,32 +1594,39 @@ function ConversationView({
|
|
|
1369
1594
|
})() : msg;
|
|
1370
1595
|
const isSelf = me !== null && msg.sender_id === me.id;
|
|
1371
1596
|
const readState = readReceipts && isSelf && maxReadByOthers !== null ? maxReadByOthers >= msg.sequence ? "read" : "sent" : void 0;
|
|
1372
|
-
return /* @__PURE__ */ jsxRuntime.
|
|
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
|
-
|
|
1597
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(react.Fragment, { children: [
|
|
1598
|
+
showDaySeparator && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-day-separator", "aria-hidden": "false", children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: formatDayLabel(msg.inserted_at) }) }),
|
|
1599
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1600
|
+
MessageRow,
|
|
1601
|
+
{
|
|
1602
|
+
msg: enriched,
|
|
1603
|
+
meId: me?.id ?? null,
|
|
1604
|
+
reactions,
|
|
1605
|
+
attachments,
|
|
1606
|
+
actions,
|
|
1607
|
+
threads,
|
|
1608
|
+
quotations,
|
|
1609
|
+
groupPosition,
|
|
1610
|
+
maxBodyLength,
|
|
1611
|
+
markdown,
|
|
1612
|
+
showSenderName: showSenderLabelsResolved,
|
|
1613
|
+
showAvatar: showAvatarsResolved,
|
|
1614
|
+
...readState ? { readState } : {},
|
|
1615
|
+
...labelFor ? { labelFor } : {},
|
|
1616
|
+
editing: editingId === msg.id,
|
|
1617
|
+
onStartEdit: () => setEditingId(msg.id),
|
|
1618
|
+
onCancelEdit: () => setEditingId(null),
|
|
1619
|
+
onSaveEdit: async (body) => {
|
|
1620
|
+
await edit(msg.id, body);
|
|
1621
|
+
setEditingId(null);
|
|
1622
|
+
},
|
|
1623
|
+
onDelete: () => void deleteMsg(msg.id),
|
|
1624
|
+
onOpenThread: () => setThreadRootId(msg.id),
|
|
1625
|
+
onQuote: () => setReplyingTo(msg),
|
|
1626
|
+
onQuotedClick: scrollToOriginal
|
|
1627
|
+
}
|
|
1628
|
+
)
|
|
1629
|
+
] }, msg.id);
|
|
1398
1630
|
}),
|
|
1399
1631
|
error && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-conversation__empty", children: [
|
|
1400
1632
|
"Failed to load: ",
|
|
@@ -1465,23 +1697,41 @@ function AttachmentPickerButton({
|
|
|
1465
1697
|
)
|
|
1466
1698
|
] });
|
|
1467
1699
|
}
|
|
1468
|
-
function
|
|
1469
|
-
const
|
|
1470
|
-
const
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
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
|
-
] });
|
|
1700
|
+
function computeGroupPosition(msg, prev, next, windowMs) {
|
|
1701
|
+
const continuesPrev = sameGroup(msg, prev, windowMs);
|
|
1702
|
+
const continuesNext = sameGroup(next, msg, windowMs);
|
|
1703
|
+
if (continuesPrev && continuesNext) return "middle";
|
|
1704
|
+
if (continuesPrev) return "last";
|
|
1705
|
+
if (continuesNext) return "first";
|
|
1706
|
+
return "standalone";
|
|
1480
1707
|
}
|
|
1481
|
-
function
|
|
1482
|
-
if (!
|
|
1483
|
-
|
|
1484
|
-
|
|
1708
|
+
function sameGroup(a, b, windowMs) {
|
|
1709
|
+
if (!a || !b) return false;
|
|
1710
|
+
if (a.sender_id !== b.sender_id) return false;
|
|
1711
|
+
if (!sameDay(a.inserted_at, b.inserted_at)) return false;
|
|
1712
|
+
const ta = new Date(a.inserted_at).getTime();
|
|
1713
|
+
const tb = new Date(b.inserted_at).getTime();
|
|
1714
|
+
return Math.abs(ta - tb) <= windowMs;
|
|
1715
|
+
}
|
|
1716
|
+
function sameDay(a, b) {
|
|
1717
|
+
const da = new Date(a);
|
|
1718
|
+
const db = new Date(b);
|
|
1719
|
+
return da.getFullYear() === db.getFullYear() && da.getMonth() === db.getMonth() && da.getDate() === db.getDate();
|
|
1720
|
+
}
|
|
1721
|
+
function formatDayLabel(iso) {
|
|
1722
|
+
const d = new Date(iso);
|
|
1723
|
+
const now = /* @__PURE__ */ new Date();
|
|
1724
|
+
const startOfDay = (x) => new Date(x.getFullYear(), x.getMonth(), x.getDate()).getTime();
|
|
1725
|
+
const diffDays = Math.floor((startOfDay(now) - startOfDay(d)) / 864e5);
|
|
1726
|
+
if (diffDays === 0) return "Today";
|
|
1727
|
+
if (diffDays === 1) return "Yesterday";
|
|
1728
|
+
if (diffDays < 7) {
|
|
1729
|
+
return d.toLocaleDateString(void 0, { weekday: "long" });
|
|
1730
|
+
}
|
|
1731
|
+
if (d.getFullYear() === now.getFullYear()) {
|
|
1732
|
+
return d.toLocaleDateString(void 0, { weekday: "short", day: "numeric", month: "short" });
|
|
1733
|
+
}
|
|
1734
|
+
return d.toLocaleDateString(void 0, { day: "numeric", month: "short", year: "numeric" });
|
|
1485
1735
|
}
|
|
1486
1736
|
function ConversationList({
|
|
1487
1737
|
selectedId,
|