@poolse/react-ui 3.3.0 → 3.5.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 +53 -0
- package/README.md +43 -1
- package/dist/index.cjs +664 -176
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +148 -10
- package/dist/index.d.ts +148 -10
- package/dist/index.js +645 -179
- package/dist/index.js.map +1 -1
- package/dist/styles.css +388 -7
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { forwardRef, useState, useRef, useCallback, useImperativeHandle, useEffect, useMemo, Fragment as Fragment$1 } from 'react';
|
|
2
|
+
import { forwardRef, useState, useRef, useCallback, useImperativeHandle, useEffect, useMemo, createContext, Fragment as Fragment$1, useContext } from 'react';
|
|
3
3
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
4
|
-
import { useMembers, useAttachmentUpload, useMe, useConversations, useUser, useConversation, usePresence, useMessages, useTyping, useMessageStreams, useRealtimeStatus, isMessageVisibleTo, receiptsOf, computeGroupPosition, sameDay, formatDayLabel,
|
|
4
|
+
import { useMembers, useAttachmentUpload, useMe, useConversations, useUser, useConversation, usePresence, useMessages, useTyping, useMessageStreams, useRealtimeStatus, isMessageVisibleTo, receiptsOf, computeGroupPosition, sameDay, formatDayLabel, formatCallLogPreview, useLiveCall, canEditOwnMessage, callLogDisplayFor, useThread, useReactions, useAttachmentUrl } from '@poolse/react';
|
|
5
5
|
import ReactMarkdown from 'react-markdown';
|
|
6
6
|
import remarkGfm from 'remark-gfm';
|
|
7
|
+
import { resolveTheme, tokensToCssVariables } from '@poolse/theme';
|
|
8
|
+
export { BUILT_IN_THEME_IDS, DEFAULT_THEME_ID, createTheme, decodeTheme, encodeTheme } from '@poolse/theme';
|
|
7
9
|
|
|
8
10
|
// src/CallVideoGrid.tsx
|
|
9
11
|
|
|
@@ -744,6 +746,31 @@ function PoolseFonts() {
|
|
|
744
746
|
usePoolseFonts(true);
|
|
745
747
|
return null;
|
|
746
748
|
}
|
|
749
|
+
|
|
750
|
+
// src/layout.ts
|
|
751
|
+
function formatMessageTime(iso, format) {
|
|
752
|
+
if (!iso) return "";
|
|
753
|
+
const date = new Date(iso);
|
|
754
|
+
if (Number.isNaN(date.getTime())) return "";
|
|
755
|
+
if (typeof format === "function") return format(date);
|
|
756
|
+
if (format === "12h") {
|
|
757
|
+
return date.toLocaleTimeString(void 0, { hour: "numeric", minute: "2-digit", hour12: true });
|
|
758
|
+
}
|
|
759
|
+
if (format === "24h") {
|
|
760
|
+
return date.toLocaleTimeString(void 0, {
|
|
761
|
+
hour: "2-digit",
|
|
762
|
+
minute: "2-digit",
|
|
763
|
+
hourCycle: "h23"
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
return date.toLocaleTimeString(void 0, { hour: "2-digit", minute: "2-digit" });
|
|
767
|
+
}
|
|
768
|
+
function mentionsViewer(msg, meId) {
|
|
769
|
+
return meId !== null && msg.sender_id !== meId && (msg.mentions ?? []).includes(meId);
|
|
770
|
+
}
|
|
771
|
+
function renderSlot(slot, ctx, children) {
|
|
772
|
+
return slot && ctx ? slot({ ...ctx, children }) : children;
|
|
773
|
+
}
|
|
747
774
|
function LiveCallBanner({ call, inCall, onJoin }) {
|
|
748
775
|
const what = call.kind === "room" ? call.media === "video" ? "Video room" : "Voice room" : call.media === "video" ? "Video call in progress" : "Voice call in progress";
|
|
749
776
|
const who = inCall > 0 ? `${inCall} ${call.kind === "room" ? "in the room" : "on the call"}` : call.kind === "room" ? "Starting" : "Ringing";
|
|
@@ -1637,7 +1664,10 @@ function MessageBubble({
|
|
|
1637
1664
|
showSenderName = false,
|
|
1638
1665
|
onSenderPress,
|
|
1639
1666
|
actionsTrigger,
|
|
1640
|
-
showAttachments = true
|
|
1667
|
+
showAttachments = true,
|
|
1668
|
+
timeFormat,
|
|
1669
|
+
slots,
|
|
1670
|
+
slotContext
|
|
1641
1671
|
}) {
|
|
1642
1672
|
const isSelf = currentUserId !== null && message.sender_id === currentUserId;
|
|
1643
1673
|
const [expanded, setExpanded] = useState(false);
|
|
@@ -1648,8 +1678,8 @@ function MessageBubble({
|
|
|
1648
1678
|
const senderColorHex = senderColorKey ? userColor(senderColorKey) : "currentColor";
|
|
1649
1679
|
const renderSenderName = showSenderName && !isSelf && (groupPosition === "first" || groupPosition === "standalone");
|
|
1650
1680
|
const rawBody = message.body ?? "";
|
|
1651
|
-
const
|
|
1652
|
-
const shouldTrim = !expanded && maxBodyLength > 0 && rawBody.length > maxBodyLength +
|
|
1681
|
+
const TRIM_BUFFER2 = 40;
|
|
1682
|
+
const shouldTrim = !expanded && maxBodyLength > 0 && rawBody.length > maxBodyLength + TRIM_BUFFER2;
|
|
1653
1683
|
const displayBody = shouldTrim ? rawBody.slice(0, maxBodyLength).trimEnd() + "\u2026" : rawBody;
|
|
1654
1684
|
const attachmentList = showAttachments && !message.deleted_at && Array.isArray(message.attachments) ? message.attachments : [];
|
|
1655
1685
|
const imageAttachments = attachmentList.filter((a) => isImageContentType(a.content_type));
|
|
@@ -1658,7 +1688,7 @@ function MessageBubble({
|
|
|
1658
1688
|
const hasVisibleBody = !message.deleted_at && rawBody.length > 0;
|
|
1659
1689
|
const metaOverlay = hasAnyAttachment && imageAttachments.length > 0 && !hasVisibleBody && fileAttachments.length === 0;
|
|
1660
1690
|
const jumboCount = hasVisibleBody && !hasAnyAttachment && !message.quoted_message_id ? emojiOnlyCount(rawBody) : 0;
|
|
1661
|
-
const trimToggleVisible = shouldTrim || expanded && rawBody.length > maxBodyLength +
|
|
1691
|
+
const trimToggleVisible = shouldTrim || expanded && rawBody.length > maxBodyLength + TRIM_BUFFER2;
|
|
1662
1692
|
const inlineMeta = hasVisibleBody && jumboCount === 0 && !trimToggleVisible && (!markdown || !hasMarkdown(displayBody));
|
|
1663
1693
|
const className = [
|
|
1664
1694
|
"poolse-message",
|
|
@@ -1672,23 +1702,24 @@ function MessageBubble({
|
|
|
1672
1702
|
metaOverlay ? "poolse-message--media-only" : "",
|
|
1673
1703
|
jumboCount > 0 ? "poolse-message--jumbo" : ""
|
|
1674
1704
|
].filter(Boolean).join(" ");
|
|
1675
|
-
const time =
|
|
1676
|
-
hour: "2-digit",
|
|
1677
|
-
minute: "2-digit"
|
|
1678
|
-
}) : "";
|
|
1705
|
+
const time = formatMessageTime(message.inserted_at, timeFormat);
|
|
1679
1706
|
const showQuoteCard = message.quoted_message !== void 0 && message.quoted_message !== null ? "full" : message.quoted_message_id ? "placeholder" : null;
|
|
1680
1707
|
return /* @__PURE__ */ jsxs("div", { className, children: [
|
|
1681
1708
|
actionsTrigger,
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1709
|
+
renderSlot(
|
|
1710
|
+
slots?.header,
|
|
1711
|
+
slotContext,
|
|
1712
|
+
renderSenderName ? onSenderPress ? /* @__PURE__ */ jsx(
|
|
1713
|
+
"button",
|
|
1714
|
+
{
|
|
1715
|
+
type: "button",
|
|
1716
|
+
className: "poolse-message__sender poolse-message__sender--button",
|
|
1717
|
+
style: { color: senderColorHex },
|
|
1718
|
+
onClick: onSenderPress,
|
|
1719
|
+
children: senderName
|
|
1720
|
+
}
|
|
1721
|
+
) : /* @__PURE__ */ jsx("div", { className: "poolse-message__sender", style: { color: senderColorHex }, children: senderName }) : null
|
|
1722
|
+
),
|
|
1692
1723
|
showQuoteCard === "full" && /* @__PURE__ */ jsx(
|
|
1693
1724
|
QuotedCard,
|
|
1694
1725
|
{
|
|
@@ -1699,8 +1730,14 @@ function MessageBubble({
|
|
|
1699
1730
|
}
|
|
1700
1731
|
),
|
|
1701
1732
|
showQuoteCard === "placeholder" && /* @__PURE__ */ jsx(QuotedPlaceholder, { isSelf, quotedMessageId: message.quoted_message_id }),
|
|
1702
|
-
|
|
1703
|
-
|
|
1733
|
+
renderSlot(
|
|
1734
|
+
slots?.attachments,
|
|
1735
|
+
slotContext,
|
|
1736
|
+
hasAnyAttachment ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1737
|
+
imageAttachments.length > 0 && /* @__PURE__ */ jsx(ImageMosaic, { images: imageAttachments }),
|
|
1738
|
+
fileAttachments.length > 0 && /* @__PURE__ */ jsx("div", { className: "poolse-message__files", children: fileAttachments.map((att) => /* @__PURE__ */ jsx(AttachmentPreview, { attachment: att }, att.id)) })
|
|
1739
|
+
] }) : null
|
|
1740
|
+
),
|
|
1704
1741
|
(() => {
|
|
1705
1742
|
const metaContent = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1706
1743
|
/* @__PURE__ */ jsx("span", { children: time }),
|
|
@@ -1757,7 +1794,7 @@ function MessageBubble({
|
|
|
1757
1794
|
children: "Read more"
|
|
1758
1795
|
}
|
|
1759
1796
|
),
|
|
1760
|
-
!shouldTrim && expanded && rawBody.length > maxBodyLength +
|
|
1797
|
+
!shouldTrim && expanded && rawBody.length > maxBodyLength + TRIM_BUFFER2 && /* @__PURE__ */ jsx(
|
|
1761
1798
|
"button",
|
|
1762
1799
|
{
|
|
1763
1800
|
type: "button",
|
|
@@ -1774,7 +1811,7 @@ function MessageBubble({
|
|
|
1774
1811
|
) : null;
|
|
1775
1812
|
const metaClass = metaOverlay ? "poolse-message__meta poolse-message__meta--overlay" : inlineMeta ? "poolse-message__meta poolse-message__meta--inline" : "poolse-message__meta poolse-message__meta--block";
|
|
1776
1813
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1777
|
-
body,
|
|
1814
|
+
renderSlot(slots?.body, slotContext, body),
|
|
1778
1815
|
/* @__PURE__ */ jsx("span", { className: metaClass, children: metaContent })
|
|
1779
1816
|
] });
|
|
1780
1817
|
})()
|
|
@@ -2062,9 +2099,12 @@ function MessageActions({
|
|
|
2062
2099
|
onCopy,
|
|
2063
2100
|
onEdit,
|
|
2064
2101
|
onDelete,
|
|
2102
|
+
moreMenu = false,
|
|
2065
2103
|
children
|
|
2066
2104
|
}) {
|
|
2067
2105
|
const [pickerOpen, setPickerOpen] = useState(false);
|
|
2106
|
+
const [menuOpen, setMenuOpen] = useState(false);
|
|
2107
|
+
const hasMore = !!(onCopy || onEdit || onDelete);
|
|
2068
2108
|
return /* @__PURE__ */ jsxs("div", { className: "poolse-msg-actions", role: "toolbar", "aria-label": "Message actions", children: [
|
|
2069
2109
|
onReact && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2070
2110
|
/* @__PURE__ */ jsx(
|
|
@@ -2087,12 +2127,60 @@ function MessageActions({
|
|
|
2087
2127
|
}
|
|
2088
2128
|
) })
|
|
2089
2129
|
] }),
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2130
|
+
moreMenu ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2131
|
+
onQuote && /* @__PURE__ */ jsx(ActionButton, { label: "Reply", icon: "reply", onClick: onQuote }),
|
|
2132
|
+
onReply && /* @__PURE__ */ jsx(ActionButton, { label: "Reply in thread", icon: "messages", onClick: onReply }),
|
|
2133
|
+
children,
|
|
2134
|
+
hasMore && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2135
|
+
/* @__PURE__ */ jsx(
|
|
2136
|
+
ActionButton,
|
|
2137
|
+
{
|
|
2138
|
+
label: "More actions",
|
|
2139
|
+
icon: "more-h",
|
|
2140
|
+
onClick: () => setMenuOpen((o) => !o),
|
|
2141
|
+
active: menuOpen
|
|
2142
|
+
}
|
|
2143
|
+
),
|
|
2144
|
+
menuOpen && /* @__PURE__ */ jsx(
|
|
2145
|
+
"div",
|
|
2146
|
+
{
|
|
2147
|
+
className: "poolse-msg-actions__menu",
|
|
2148
|
+
role: "menu",
|
|
2149
|
+
onKeyDown: (e) => {
|
|
2150
|
+
if (e.key === "Escape") setMenuOpen(false);
|
|
2151
|
+
},
|
|
2152
|
+
children: [
|
|
2153
|
+
onCopy && { label: "Copy", icon: "copy", run: onCopy },
|
|
2154
|
+
onEdit && { label: "Edit", icon: "edit", run: onEdit },
|
|
2155
|
+
onDelete && { label: "Delete", icon: "trash", run: onDelete }
|
|
2156
|
+
].filter((item) => !!item).map((item) => /* @__PURE__ */ jsxs(
|
|
2157
|
+
"button",
|
|
2158
|
+
{
|
|
2159
|
+
type: "button",
|
|
2160
|
+
role: "menuitem",
|
|
2161
|
+
className: `poolse-msg-actions__menu-item${item.label === "Delete" ? " poolse-msg-actions__menu-item--danger" : ""}`,
|
|
2162
|
+
onClick: () => {
|
|
2163
|
+
setMenuOpen(false);
|
|
2164
|
+
item.run();
|
|
2165
|
+
},
|
|
2166
|
+
children: [
|
|
2167
|
+
/* @__PURE__ */ jsx(PoolseIcon, { name: item.icon, size: 15, label: null }),
|
|
2168
|
+
/* @__PURE__ */ jsx("span", { children: item.label })
|
|
2169
|
+
]
|
|
2170
|
+
},
|
|
2171
|
+
item.label
|
|
2172
|
+
))
|
|
2173
|
+
}
|
|
2174
|
+
)
|
|
2175
|
+
] })
|
|
2176
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2177
|
+
onReply && /* @__PURE__ */ jsx(ActionButton, { label: "Reply in thread", icon: "messages", onClick: onReply }),
|
|
2178
|
+
onQuote && /* @__PURE__ */ jsx(ActionButton, { label: "Reply", icon: "reply", onClick: onQuote }),
|
|
2179
|
+
onCopy && /* @__PURE__ */ jsx(ActionButton, { label: "Copy", icon: "copy", onClick: onCopy }),
|
|
2180
|
+
onEdit && /* @__PURE__ */ jsx(ActionButton, { label: "Edit", icon: "edit", onClick: onEdit }),
|
|
2181
|
+
onDelete && /* @__PURE__ */ jsx(ActionButton, { label: "Delete", icon: "trash", danger: true, onClick: onDelete }),
|
|
2182
|
+
children
|
|
2183
|
+
] })
|
|
2096
2184
|
] });
|
|
2097
2185
|
}
|
|
2098
2186
|
function ActionButton({
|
|
@@ -2109,6 +2197,319 @@ function ActionButton({
|
|
|
2109
2197
|
].filter(Boolean).join(" ");
|
|
2110
2198
|
return /* @__PURE__ */ jsx("button", { type: "button", className: classes, "aria-label": label, title: label, onClick, children: /* @__PURE__ */ jsx(PoolseIcon, { name: icon, size: 16, label: null }) });
|
|
2111
2199
|
}
|
|
2200
|
+
function useRowActions() {
|
|
2201
|
+
const [actionsOpen, setActionsOpen] = useState(false);
|
|
2202
|
+
const rowRef = useRef(null);
|
|
2203
|
+
useEffect(() => {
|
|
2204
|
+
if (!actionsOpen) return;
|
|
2205
|
+
const onDown = (e) => {
|
|
2206
|
+
const t = e.target;
|
|
2207
|
+
if (t instanceof Node && rowRef.current && !rowRef.current.contains(t)) {
|
|
2208
|
+
setActionsOpen(false);
|
|
2209
|
+
}
|
|
2210
|
+
};
|
|
2211
|
+
document.addEventListener("pointerdown", onDown);
|
|
2212
|
+
return () => document.removeEventListener("pointerdown", onDown);
|
|
2213
|
+
}, [actionsOpen]);
|
|
2214
|
+
const onRowClick = (e) => {
|
|
2215
|
+
if (typeof window === "undefined" || !window.matchMedia("(hover: none)").matches) return;
|
|
2216
|
+
const target = e.target;
|
|
2217
|
+
if (target.closest("a, button, input, textarea, label, select")) return;
|
|
2218
|
+
setActionsOpen((o) => !o);
|
|
2219
|
+
};
|
|
2220
|
+
return { actionsOpen, setActionsOpen, rowRef, onRowClick };
|
|
2221
|
+
}
|
|
2222
|
+
function InlineReactions({
|
|
2223
|
+
reactions,
|
|
2224
|
+
currentUserId,
|
|
2225
|
+
onAdd,
|
|
2226
|
+
onRemove
|
|
2227
|
+
}) {
|
|
2228
|
+
const entries = Object.entries(reactions);
|
|
2229
|
+
if (entries.length === 0) return null;
|
|
2230
|
+
return /* @__PURE__ */ jsx("div", { className: "poolse-reactions", children: entries.map(([emoji, users]) => {
|
|
2231
|
+
const mine = currentUserId !== null && currentUserId !== void 0 && users.includes(currentUserId);
|
|
2232
|
+
return /* @__PURE__ */ jsxs(
|
|
2233
|
+
"button",
|
|
2234
|
+
{
|
|
2235
|
+
type: "button",
|
|
2236
|
+
className: `poolse-reaction-pill${mine ? " poolse-reaction-pill--mine" : ""}`,
|
|
2237
|
+
onClick: () => {
|
|
2238
|
+
if (mine) onRemove(emoji);
|
|
2239
|
+
else onAdd(emoji);
|
|
2240
|
+
},
|
|
2241
|
+
"aria-pressed": mine,
|
|
2242
|
+
"aria-label": `${emoji} reacted by ${users.length} ${users.length === 1 ? "user" : "users"}`,
|
|
2243
|
+
children: [
|
|
2244
|
+
/* @__PURE__ */ jsx("span", { children: emoji }),
|
|
2245
|
+
/* @__PURE__ */ jsx("span", { className: "poolse-reaction-pill__count", children: users.length })
|
|
2246
|
+
]
|
|
2247
|
+
},
|
|
2248
|
+
emoji
|
|
2249
|
+
);
|
|
2250
|
+
}) });
|
|
2251
|
+
}
|
|
2252
|
+
var TRIM_BUFFER = 40;
|
|
2253
|
+
function FlatMessageRow({
|
|
2254
|
+
msg,
|
|
2255
|
+
meId,
|
|
2256
|
+
layout,
|
|
2257
|
+
reactions = true,
|
|
2258
|
+
attachments = true,
|
|
2259
|
+
actions = true,
|
|
2260
|
+
threads = true,
|
|
2261
|
+
quotations = true,
|
|
2262
|
+
readState,
|
|
2263
|
+
editing = false,
|
|
2264
|
+
onStartEdit,
|
|
2265
|
+
onCancelEdit,
|
|
2266
|
+
onSaveEdit,
|
|
2267
|
+
onDelete,
|
|
2268
|
+
onOpenThread,
|
|
2269
|
+
onQuote,
|
|
2270
|
+
labelFor,
|
|
2271
|
+
onQuotedClick,
|
|
2272
|
+
groupPosition = "standalone",
|
|
2273
|
+
maxBodyLength = 0,
|
|
2274
|
+
markdown = false,
|
|
2275
|
+
showAvatar = layout === "list",
|
|
2276
|
+
onSenderPress,
|
|
2277
|
+
onAvatarPress,
|
|
2278
|
+
timeFormat,
|
|
2279
|
+
slots,
|
|
2280
|
+
mentionsMe = false
|
|
2281
|
+
}) {
|
|
2282
|
+
const compact = layout === "compact";
|
|
2283
|
+
const isSelf = meId !== null && msg.sender_id === meId;
|
|
2284
|
+
const { profile } = useUser(msg.sender_external_id);
|
|
2285
|
+
const senderName = profile?.displayName ?? msg.sender_external_id ?? (msg.sender_id ? `User ${msg.sender_id.slice(0, 6)}` : "Unknown");
|
|
2286
|
+
const sender = {
|
|
2287
|
+
userId: msg.sender_id,
|
|
2288
|
+
externalId: msg.sender_external_id,
|
|
2289
|
+
displayName: senderName,
|
|
2290
|
+
avatarUrl: profile?.avatarUrl ?? null
|
|
2291
|
+
};
|
|
2292
|
+
const isRunStart = compact || groupPosition === "first" || groupPosition === "standalone";
|
|
2293
|
+
const ctx = { message: msg, isSelf, sender, layout, isRunStart };
|
|
2294
|
+
const reactionsHook = useReactions(reactions ? msg.id : "", {
|
|
2295
|
+
conversationId: msg.conversation_id,
|
|
2296
|
+
initialReactions: msg.reactions,
|
|
2297
|
+
currentUserId: meId
|
|
2298
|
+
});
|
|
2299
|
+
const { actionsOpen, rowRef, onRowClick } = useRowActions();
|
|
2300
|
+
const deleted = !!msg.deleted_at;
|
|
2301
|
+
const time = formatMessageTime(msg.inserted_at, timeFormat);
|
|
2302
|
+
const replyCount = msg.reply_count ?? 0;
|
|
2303
|
+
const showThreadLink = threads && !deleted && !msg.thread_root_id && replyCount > 0;
|
|
2304
|
+
const showActions = actions && !deleted && !editing;
|
|
2305
|
+
const timeEl = (className) => /* @__PURE__ */ jsx("time", { className, dateTime: msg.inserted_at, children: time });
|
|
2306
|
+
const avatarSize = compact ? "sm" : "md";
|
|
2307
|
+
const avatar = !showAvatar ? null : onAvatarPress && !isSelf ? /* @__PURE__ */ jsx(
|
|
2308
|
+
"button",
|
|
2309
|
+
{
|
|
2310
|
+
type: "button",
|
|
2311
|
+
className: "poolse-row__avatar-button",
|
|
2312
|
+
"aria-label": senderName,
|
|
2313
|
+
onClick: () => onAvatarPress(sender),
|
|
2314
|
+
children: /* @__PURE__ */ jsx(Avatar, { src: sender.avatarUrl, name: senderName, size: avatarSize })
|
|
2315
|
+
}
|
|
2316
|
+
) : /* @__PURE__ */ jsx(Avatar, { src: sender.avatarUrl, name: senderName, size: avatarSize });
|
|
2317
|
+
const nameStyle = compact ? { color: userColor(msg.sender_external_id ?? msg.sender_id ?? "") } : void 0;
|
|
2318
|
+
const name = onSenderPress && !isSelf ? /* @__PURE__ */ jsx(
|
|
2319
|
+
"button",
|
|
2320
|
+
{
|
|
2321
|
+
type: "button",
|
|
2322
|
+
className: "poolse-row__name poolse-row__name--button",
|
|
2323
|
+
style: nameStyle,
|
|
2324
|
+
onClick: () => onSenderPress(sender),
|
|
2325
|
+
children: senderName
|
|
2326
|
+
}
|
|
2327
|
+
) : /* @__PURE__ */ jsx("span", { className: "poolse-row__name", style: nameStyle, children: senderName });
|
|
2328
|
+
const header = compact ? name : isRunStart ? /* @__PURE__ */ jsxs("div", { className: "poolse-row__header", children: [
|
|
2329
|
+
name,
|
|
2330
|
+
timeEl("poolse-row__time")
|
|
2331
|
+
] }) : null;
|
|
2332
|
+
const quote = msg.quoted_message !== void 0 && msg.quoted_message !== null ? /* @__PURE__ */ jsx(
|
|
2333
|
+
QuotedCard,
|
|
2334
|
+
{
|
|
2335
|
+
quoted: msg.quoted_message,
|
|
2336
|
+
isSelf: false,
|
|
2337
|
+
...labelFor ? { labelFor } : {},
|
|
2338
|
+
...onQuotedClick ? { onClick: onQuotedClick } : {}
|
|
2339
|
+
}
|
|
2340
|
+
) : msg.quoted_message_id ? /* @__PURE__ */ jsx(QuotedPlaceholder, { isSelf: false, quotedMessageId: msg.quoted_message_id }) : null;
|
|
2341
|
+
const attachmentList = attachments && !deleted && Array.isArray(msg.attachments) ? msg.attachments : [];
|
|
2342
|
+
const images = attachmentList.filter((a) => isImageContentType(a.content_type));
|
|
2343
|
+
const files = attachmentList.filter((a) => !isImageContentType(a.content_type));
|
|
2344
|
+
const attachmentsEl = images.length > 0 || files.length > 0 ? /* @__PURE__ */ jsxs("div", { className: "poolse-row__attachments", children: [
|
|
2345
|
+
images.length > 0 && /* @__PURE__ */ jsx(ImageMosaic, { images }),
|
|
2346
|
+
files.length > 0 && /* @__PURE__ */ jsx("div", { className: "poolse-message__files", children: files.map((att) => /* @__PURE__ */ jsx(AttachmentPreview, { attachment: att }, att.id)) })
|
|
2347
|
+
] }) : null;
|
|
2348
|
+
const meta = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2349
|
+
msg.edited_at && !deleted ? /* @__PURE__ */ jsx("span", { className: "poolse-row__edited", children: "(edited)" }) : null,
|
|
2350
|
+
isSelf && readState ? /* @__PURE__ */ jsx("span", { className: "poolse-row__receipt", children: /* @__PURE__ */ jsx(
|
|
2351
|
+
PoolseIcon,
|
|
2352
|
+
{
|
|
2353
|
+
name: readState === "read" ? "check-double" : "check",
|
|
2354
|
+
size: 14,
|
|
2355
|
+
label: readState === "read" ? "Read" : "Sent"
|
|
2356
|
+
}
|
|
2357
|
+
) }) : null
|
|
2358
|
+
] });
|
|
2359
|
+
const body = editing ? (
|
|
2360
|
+
// `currentUserId={null}` styles the editor as a neutral card rather
|
|
2361
|
+
// than an own-message bubble, which would look out of place in a row.
|
|
2362
|
+
/* @__PURE__ */ jsx(
|
|
2363
|
+
EditableMessageBubble,
|
|
2364
|
+
{
|
|
2365
|
+
message: msg,
|
|
2366
|
+
currentUserId: null,
|
|
2367
|
+
editing: true,
|
|
2368
|
+
onSave: onSaveEdit ?? (async () => void 0),
|
|
2369
|
+
onCancel: onCancelEdit ?? (() => void 0)
|
|
2370
|
+
}
|
|
2371
|
+
)
|
|
2372
|
+
) : /* @__PURE__ */ jsx(
|
|
2373
|
+
FlatBody,
|
|
2374
|
+
{
|
|
2375
|
+
message: msg,
|
|
2376
|
+
markdown,
|
|
2377
|
+
maxBodyLength,
|
|
2378
|
+
hasAttachments: attachmentList.length > 0,
|
|
2379
|
+
meta
|
|
2380
|
+
}
|
|
2381
|
+
);
|
|
2382
|
+
const reactionsEl = reactions && !deleted ? /* @__PURE__ */ jsx(
|
|
2383
|
+
InlineReactions,
|
|
2384
|
+
{
|
|
2385
|
+
reactions: reactionsHook.reactions,
|
|
2386
|
+
currentUserId: meId,
|
|
2387
|
+
onAdd: (e) => void reactionsHook.addReaction(e),
|
|
2388
|
+
onRemove: (e) => void reactionsHook.removeReaction(e)
|
|
2389
|
+
}
|
|
2390
|
+
) : null;
|
|
2391
|
+
const threadEl = showThreadLink ? /* @__PURE__ */ jsxs(
|
|
2392
|
+
"button",
|
|
2393
|
+
{
|
|
2394
|
+
type: "button",
|
|
2395
|
+
className: "poolse-row__thread",
|
|
2396
|
+
onClick: onOpenThread,
|
|
2397
|
+
"aria-label": `View ${replyCount} ${replyCount === 1 ? "reply" : "replies"}`,
|
|
2398
|
+
children: [
|
|
2399
|
+
/* @__PURE__ */ jsx(PoolseIcon, { name: "messages", size: 14, label: null }),
|
|
2400
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
2401
|
+
replyCount,
|
|
2402
|
+
" ",
|
|
2403
|
+
replyCount === 1 ? "reply" : "replies"
|
|
2404
|
+
] })
|
|
2405
|
+
]
|
|
2406
|
+
}
|
|
2407
|
+
) : null;
|
|
2408
|
+
const toolbar = showActions ? /* @__PURE__ */ jsx("div", { className: "poolse-row__toolbar", children: /* @__PURE__ */ jsx(
|
|
2409
|
+
MessageActions,
|
|
2410
|
+
{
|
|
2411
|
+
moreMenu: true,
|
|
2412
|
+
...reactions ? { onReact: (emoji) => void reactionsHook.addReaction(emoji) } : {},
|
|
2413
|
+
...quotations && onQuote ? { onQuote } : {},
|
|
2414
|
+
...threads && onOpenThread ? { onReply: onOpenThread } : {},
|
|
2415
|
+
...msg.body ? {
|
|
2416
|
+
onCopy: () => {
|
|
2417
|
+
void navigator?.clipboard?.writeText(msg.body ?? "").catch(() => void 0);
|
|
2418
|
+
}
|
|
2419
|
+
} : {},
|
|
2420
|
+
...isSelf && onStartEdit ? { onEdit: onStartEdit } : {},
|
|
2421
|
+
...isSelf && onDelete ? { onDelete } : {}
|
|
2422
|
+
}
|
|
2423
|
+
) }) : null;
|
|
2424
|
+
const content = /* @__PURE__ */ jsxs("div", { className: "poolse-row__content", children: [
|
|
2425
|
+
!compact && renderSlot(slots?.header, ctx, header),
|
|
2426
|
+
quote,
|
|
2427
|
+
renderSlot(slots?.attachments, ctx, attachmentsEl),
|
|
2428
|
+
renderSlot(slots?.body, ctx, body),
|
|
2429
|
+
renderSlot(slots?.reactions, ctx, reactionsEl),
|
|
2430
|
+
renderSlot(slots?.thread, ctx, threadEl)
|
|
2431
|
+
] });
|
|
2432
|
+
return /* @__PURE__ */ jsxs(
|
|
2433
|
+
"div",
|
|
2434
|
+
{
|
|
2435
|
+
ref: rowRef,
|
|
2436
|
+
className: [
|
|
2437
|
+
"poolse-row",
|
|
2438
|
+
`poolse-row--${layout}`,
|
|
2439
|
+
isRunStart ? "poolse-row--run-start" : "poolse-row--continued",
|
|
2440
|
+
isSelf ? "poolse-row--self" : "",
|
|
2441
|
+
mentionsMe ? "poolse-row--mention" : "",
|
|
2442
|
+
editing ? "poolse-row--editing" : ""
|
|
2443
|
+
].filter(Boolean).join(" "),
|
|
2444
|
+
"data-message-id": msg.id,
|
|
2445
|
+
"data-actions-open": actionsOpen || void 0,
|
|
2446
|
+
onClick: onRowClick,
|
|
2447
|
+
children: [
|
|
2448
|
+
compact ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2449
|
+
timeEl("poolse-row__time"),
|
|
2450
|
+
avatar ? /* @__PURE__ */ jsx("span", { className: "poolse-row__avatar", children: avatar }) : null,
|
|
2451
|
+
renderSlot(slots?.header, ctx, header),
|
|
2452
|
+
content
|
|
2453
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2454
|
+
/* @__PURE__ */ jsx("div", { className: "poolse-row__gutter", children: isRunStart ? avatar : timeEl("poolse-row__gutter-time") }),
|
|
2455
|
+
content
|
|
2456
|
+
] }),
|
|
2457
|
+
renderSlot(slots?.actions, ctx, toolbar)
|
|
2458
|
+
]
|
|
2459
|
+
}
|
|
2460
|
+
);
|
|
2461
|
+
}
|
|
2462
|
+
function FlatBody({
|
|
2463
|
+
message,
|
|
2464
|
+
markdown,
|
|
2465
|
+
maxBodyLength,
|
|
2466
|
+
hasAttachments,
|
|
2467
|
+
meta
|
|
2468
|
+
}) {
|
|
2469
|
+
const [expanded, setExpanded] = useState(false);
|
|
2470
|
+
if (message.deleted_at) {
|
|
2471
|
+
return /* @__PURE__ */ jsx("div", { className: "poolse-message__body poolse-row__body", children: /* @__PURE__ */ jsx("span", { className: "poolse-message__body--deleted", children: "Message deleted" }) });
|
|
2472
|
+
}
|
|
2473
|
+
const raw = message.body ?? "";
|
|
2474
|
+
if (!raw) {
|
|
2475
|
+
return /* @__PURE__ */ jsx("div", { className: "poolse-row__meta-only", children: meta });
|
|
2476
|
+
}
|
|
2477
|
+
const long = maxBodyLength > 0 && raw.length > maxBodyLength + TRIM_BUFFER;
|
|
2478
|
+
const shown = long && !expanded ? raw.slice(0, maxBodyLength).trimEnd() + "\u2026" : raw;
|
|
2479
|
+
const jumbo = !hasAttachments && !message.quoted_message_id ? emojiOnlyCount(raw) : 0;
|
|
2480
|
+
const md = markdown && jumbo === 0 && hasMarkdown(shown);
|
|
2481
|
+
return /* @__PURE__ */ jsxs(
|
|
2482
|
+
"div",
|
|
2483
|
+
{
|
|
2484
|
+
className: md ? "poolse-message__body poolse-message__body--md poolse-row__body" : "poolse-message__body poolse-row__body",
|
|
2485
|
+
children: [
|
|
2486
|
+
jumbo > 0 ? /* @__PURE__ */ jsx("span", { className: "poolse-message__body--jumbo", style: { fontSize: emojiFontSize(jumbo) }, children: shown }) : md ? /* @__PURE__ */ jsx(
|
|
2487
|
+
ReactMarkdown,
|
|
2488
|
+
{
|
|
2489
|
+
remarkPlugins: [remarkGfm],
|
|
2490
|
+
components: {
|
|
2491
|
+
a: ({ node: _node, ...props }) => /* @__PURE__ */ jsx("a", { ...props, target: "_blank", rel: "noopener noreferrer nofollow" })
|
|
2492
|
+
},
|
|
2493
|
+
children: shown
|
|
2494
|
+
}
|
|
2495
|
+
) : /* @__PURE__ */ jsx("span", { children: shown }),
|
|
2496
|
+
long && /* @__PURE__ */ jsx(
|
|
2497
|
+
"button",
|
|
2498
|
+
{
|
|
2499
|
+
type: "button",
|
|
2500
|
+
className: "poolse-message__read-more",
|
|
2501
|
+
onClick: (e) => {
|
|
2502
|
+
e.stopPropagation();
|
|
2503
|
+
setExpanded((x) => !x);
|
|
2504
|
+
},
|
|
2505
|
+
children: expanded ? "Show less" : "Read more"
|
|
2506
|
+
}
|
|
2507
|
+
),
|
|
2508
|
+
meta
|
|
2509
|
+
]
|
|
2510
|
+
}
|
|
2511
|
+
);
|
|
2512
|
+
}
|
|
2112
2513
|
function MessageRow(props) {
|
|
2113
2514
|
const callLog = callLogDisplayFor(props.msg, props.meId);
|
|
2114
2515
|
if (callLog !== void 0) {
|
|
@@ -2121,6 +2522,9 @@ function MessageRow(props) {
|
|
|
2121
2522
|
}
|
|
2122
2523
|
) : null;
|
|
2123
2524
|
}
|
|
2525
|
+
if (props.layout === "list" || props.layout === "compact") {
|
|
2526
|
+
return /* @__PURE__ */ jsx(FlatMessageRow, { ...props, layout: props.layout });
|
|
2527
|
+
}
|
|
2124
2528
|
return /* @__PURE__ */ jsx(BubbleMessageRow, { ...props });
|
|
2125
2529
|
}
|
|
2126
2530
|
function BubbleMessageRow({
|
|
@@ -2147,7 +2551,9 @@ function BubbleMessageRow({
|
|
|
2147
2551
|
showSenderName = false,
|
|
2148
2552
|
showAvatar = false,
|
|
2149
2553
|
onSenderPress,
|
|
2150
|
-
onAvatarPress
|
|
2554
|
+
onAvatarPress,
|
|
2555
|
+
timeFormat,
|
|
2556
|
+
slots
|
|
2151
2557
|
}) {
|
|
2152
2558
|
const { profile: senderProfile } = useUser(msg.sender_external_id);
|
|
2153
2559
|
const senderFallbackName = msg.sender_external_id ?? (msg.sender_id ? `User ${msg.sender_id.slice(0, 6)}` : "Unknown");
|
|
@@ -2170,24 +2576,13 @@ function BubbleMessageRow({
|
|
|
2170
2576
|
const showThreadPill = threads && !msg.deleted_at && !msg.thread_root_id && replyCount > 0;
|
|
2171
2577
|
const handleSave = onSaveEdit ?? (async () => void 0);
|
|
2172
2578
|
const handleCancel = onCancelEdit ?? (() => void 0);
|
|
2173
|
-
const
|
|
2174
|
-
const
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
setActionsOpen(false);
|
|
2181
|
-
}
|
|
2182
|
-
};
|
|
2183
|
-
document.addEventListener("pointerdown", onDown);
|
|
2184
|
-
return () => document.removeEventListener("pointerdown", onDown);
|
|
2185
|
-
}, [actionsOpen]);
|
|
2186
|
-
const onRowClick = (e) => {
|
|
2187
|
-
if (typeof window === "undefined" || !window.matchMedia("(hover: none)").matches) return;
|
|
2188
|
-
const target = e.target;
|
|
2189
|
-
if (target.closest("a, button, input, textarea, label, select")) return;
|
|
2190
|
-
setActionsOpen((o) => !o);
|
|
2579
|
+
const { actionsOpen, setActionsOpen, rowRef, onRowClick } = useRowActions();
|
|
2580
|
+
const slotContext = {
|
|
2581
|
+
message: msg,
|
|
2582
|
+
isSelf,
|
|
2583
|
+
sender,
|
|
2584
|
+
layout: "bubbles",
|
|
2585
|
+
isRunStart: groupPosition === "first" || groupPosition === "standalone"
|
|
2191
2586
|
};
|
|
2192
2587
|
return /* @__PURE__ */ jsxs(
|
|
2193
2588
|
"div",
|
|
@@ -2240,6 +2635,8 @@ function BubbleMessageRow({
|
|
|
2240
2635
|
...readState ? { readState } : {},
|
|
2241
2636
|
...labelFor ? { labelFor } : {},
|
|
2242
2637
|
...onQuotedClick ? { onQuotedClick } : {},
|
|
2638
|
+
...timeFormat ? { timeFormat } : {},
|
|
2639
|
+
...slots ? { slots, slotContext } : {},
|
|
2243
2640
|
...showActions ? {
|
|
2244
2641
|
actionsTrigger: /* @__PURE__ */ jsx(
|
|
2245
2642
|
"button",
|
|
@@ -2260,91 +2657,73 @@ function BubbleMessageRow({
|
|
|
2260
2657
|
)
|
|
2261
2658
|
}
|
|
2262
2659
|
),
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
type: "button",
|
|
2276
|
-
className: `poolse-thread-pill ${isSelf ? "poolse-thread-pill--right" : "poolse-thread-pill--left"}`,
|
|
2277
|
-
onClick: onOpenThread,
|
|
2278
|
-
"aria-label": `View ${replyCount} ${replyCount === 1 ? "reply" : "replies"}`,
|
|
2279
|
-
children: [
|
|
2280
|
-
/* @__PURE__ */ jsx(PoolseIcon, { name: "messages", size: 12, label: null }),
|
|
2281
|
-
/* @__PURE__ */ jsxs("span", { children: [
|
|
2282
|
-
replyCount,
|
|
2283
|
-
" ",
|
|
2284
|
-
replyCount === 1 ? "reply" : "replies"
|
|
2285
|
-
] })
|
|
2286
|
-
]
|
|
2287
|
-
}
|
|
2660
|
+
renderSlot(
|
|
2661
|
+
slots?.reactions,
|
|
2662
|
+
slotContext,
|
|
2663
|
+
showReactions ? /* @__PURE__ */ jsx("div", { className: `poolse-message-row__reactions ${isSelf ? "is-self" : ""}`, children: /* @__PURE__ */ jsx(
|
|
2664
|
+
InlineReactions,
|
|
2665
|
+
{
|
|
2666
|
+
reactions: reactionsHook.reactions,
|
|
2667
|
+
currentUserId: meId,
|
|
2668
|
+
onAdd: (e) => void reactionsHook.addReaction(e),
|
|
2669
|
+
onRemove: (e) => void reactionsHook.removeReaction(e)
|
|
2670
|
+
}
|
|
2671
|
+
) }) : null
|
|
2288
2672
|
),
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2673
|
+
renderSlot(
|
|
2674
|
+
slots?.thread,
|
|
2675
|
+
slotContext,
|
|
2676
|
+
showThreadPill ? /* @__PURE__ */ jsxs(
|
|
2677
|
+
"button",
|
|
2678
|
+
{
|
|
2679
|
+
type: "button",
|
|
2680
|
+
className: `poolse-thread-pill ${isSelf ? "poolse-thread-pill--right" : "poolse-thread-pill--left"}`,
|
|
2681
|
+
onClick: onOpenThread,
|
|
2682
|
+
"aria-label": `View ${replyCount} ${replyCount === 1 ? "reply" : "replies"}`,
|
|
2683
|
+
children: [
|
|
2684
|
+
/* @__PURE__ */ jsx(PoolseIcon, { name: "messages", size: 12, label: null }),
|
|
2685
|
+
/* @__PURE__ */ jsxs("span", { children: [
|
|
2686
|
+
replyCount,
|
|
2687
|
+
" ",
|
|
2688
|
+
replyCount === 1 ? "reply" : "replies"
|
|
2689
|
+
] })
|
|
2690
|
+
]
|
|
2691
|
+
}
|
|
2692
|
+
) : null
|
|
2693
|
+
),
|
|
2694
|
+
renderSlot(
|
|
2695
|
+
slots?.actions,
|
|
2696
|
+
slotContext,
|
|
2697
|
+
showActions ? /* @__PURE__ */ jsx(
|
|
2698
|
+
"div",
|
|
2699
|
+
{
|
|
2700
|
+
className: `poolse-message-row__actions ${isSelf ? "poolse-message-row__actions--right" : "poolse-message-row__actions--left"}`,
|
|
2701
|
+
children: /* @__PURE__ */ jsx(
|
|
2702
|
+
MessageActions,
|
|
2703
|
+
{
|
|
2704
|
+
...reactions ? {
|
|
2705
|
+
onReact: (emoji) => {
|
|
2706
|
+
void reactionsHook.addReaction(emoji);
|
|
2707
|
+
}
|
|
2708
|
+
} : {},
|
|
2709
|
+
...threads && onOpenThread ? { onReply: onOpenThread } : {},
|
|
2710
|
+
...quotations && onQuote ? { onQuote } : {},
|
|
2711
|
+
...msg.body ? {
|
|
2712
|
+
onCopy: () => {
|
|
2713
|
+
void navigator?.clipboard?.writeText(msg.body ?? "").catch(() => void 0);
|
|
2714
|
+
}
|
|
2715
|
+
} : {},
|
|
2716
|
+
...isSelf && onStartEdit ? { onEdit: onStartEdit } : {},
|
|
2717
|
+
...isSelf && onDelete ? { onDelete } : {}
|
|
2718
|
+
}
|
|
2719
|
+
)
|
|
2720
|
+
}
|
|
2721
|
+
) : null
|
|
2313
2722
|
)
|
|
2314
2723
|
]
|
|
2315
2724
|
}
|
|
2316
2725
|
);
|
|
2317
2726
|
}
|
|
2318
|
-
function InlineReactions({
|
|
2319
|
-
reactions,
|
|
2320
|
-
currentUserId,
|
|
2321
|
-
onAdd: _onAdd,
|
|
2322
|
-
onRemove
|
|
2323
|
-
}) {
|
|
2324
|
-
const entries = Object.entries(reactions);
|
|
2325
|
-
if (entries.length === 0) return null;
|
|
2326
|
-
return /* @__PURE__ */ jsx("div", { className: "poolse-reactions", children: entries.map(([emoji, users]) => {
|
|
2327
|
-
const mine = currentUserId !== null && currentUserId !== void 0 && users.includes(currentUserId);
|
|
2328
|
-
return /* @__PURE__ */ jsxs(
|
|
2329
|
-
"button",
|
|
2330
|
-
{
|
|
2331
|
-
type: "button",
|
|
2332
|
-
className: `poolse-reaction-pill${mine ? " poolse-reaction-pill--mine" : ""}`,
|
|
2333
|
-
onClick: () => {
|
|
2334
|
-
if (mine) onRemove(emoji);
|
|
2335
|
-
else _onAdd(emoji);
|
|
2336
|
-
},
|
|
2337
|
-
"aria-pressed": mine,
|
|
2338
|
-
"aria-label": `${emoji} reacted by ${users.length} ${users.length === 1 ? "user" : "users"}`,
|
|
2339
|
-
children: [
|
|
2340
|
-
/* @__PURE__ */ jsx("span", { children: emoji }),
|
|
2341
|
-
/* @__PURE__ */ jsx("span", { className: "poolse-reaction-pill__count", children: users.length })
|
|
2342
|
-
]
|
|
2343
|
-
},
|
|
2344
|
-
emoji
|
|
2345
|
-
);
|
|
2346
|
-
}) });
|
|
2347
|
-
}
|
|
2348
2727
|
function BubbleWithAvatar({
|
|
2349
2728
|
isSelf,
|
|
2350
2729
|
showAvatar,
|
|
@@ -2374,7 +2753,9 @@ function ThreadView({
|
|
|
2374
2753
|
conversationId,
|
|
2375
2754
|
rootMessage,
|
|
2376
2755
|
onClose,
|
|
2377
|
-
renderMessage
|
|
2756
|
+
renderMessage,
|
|
2757
|
+
layout,
|
|
2758
|
+
timeFormat
|
|
2378
2759
|
}) {
|
|
2379
2760
|
const { me } = useMe();
|
|
2380
2761
|
const {
|
|
@@ -2457,7 +2838,9 @@ function ThreadView({
|
|
|
2457
2838
|
await edit(msg.id, body);
|
|
2458
2839
|
setEditingId(null);
|
|
2459
2840
|
},
|
|
2460
|
-
onDelete: () => void deleteReply(msg.id)
|
|
2841
|
+
onDelete: () => void deleteReply(msg.id),
|
|
2842
|
+
...layout ? { layout } : {},
|
|
2843
|
+
...timeFormat ? { timeFormat } : {}
|
|
2461
2844
|
}
|
|
2462
2845
|
);
|
|
2463
2846
|
const renderOne = renderMessage ? (msg, currentUserId) => renderMessage(msg, currentUserId) : (msg) => renderDefault(msg);
|
|
@@ -2573,7 +2956,13 @@ function ConversationView({
|
|
|
2573
2956
|
markdown = TRUE,
|
|
2574
2957
|
maxBodyLength = 200,
|
|
2575
2958
|
grouping = TRUE,
|
|
2576
|
-
groupingWindowMs
|
|
2959
|
+
groupingWindowMs,
|
|
2960
|
+
groupWindowMinutes,
|
|
2961
|
+
layout = "bubbles",
|
|
2962
|
+
density = "comfortable",
|
|
2963
|
+
showAvatars,
|
|
2964
|
+
timeFormat,
|
|
2965
|
+
slots,
|
|
2577
2966
|
daySeparators = TRUE,
|
|
2578
2967
|
senderLabels = "auto",
|
|
2579
2968
|
avatars = "auto",
|
|
@@ -2621,7 +3010,13 @@ function ConversationView({
|
|
|
2621
3010
|
const { members } = useMembers(membersOn ? conversationId : "");
|
|
2622
3011
|
const isGroupChat = members.length > 2;
|
|
2623
3012
|
const showSenderLabelsResolved = senderLabels === "always" || senderLabels === "auto" && isGroupChat;
|
|
2624
|
-
const showAvatarsResolved = avatars === "always" || avatars === "auto" && isGroupChat;
|
|
3013
|
+
const showAvatarsResolved = showAvatars ?? (layout === "list" ? true : layout === "compact" ? false : avatars === "always" || avatars === "auto" && isGroupChat);
|
|
3014
|
+
const groupWindowMs = groupWindowMinutes !== void 0 ? groupWindowMinutes * 60 * 1e3 : groupingWindowMs ?? 5 * 60 * 1e3;
|
|
3015
|
+
const layoutProps = {
|
|
3016
|
+
layout,
|
|
3017
|
+
...timeFormat ? { timeFormat } : {},
|
|
3018
|
+
...slots ? { slots } : {}
|
|
3019
|
+
};
|
|
2625
3020
|
const listRef = useRef(null);
|
|
2626
3021
|
const lastMessageIdRef = useRef(null);
|
|
2627
3022
|
const bottomSentinelRef = useRef(null);
|
|
@@ -2861,7 +3256,12 @@ function ConversationView({
|
|
|
2861
3256
|
/* @__PURE__ */ jsxs(
|
|
2862
3257
|
"div",
|
|
2863
3258
|
{
|
|
2864
|
-
className:
|
|
3259
|
+
className: [
|
|
3260
|
+
"poolse-conversation",
|
|
3261
|
+
`poolse-conversation--layout-${layout}`,
|
|
3262
|
+
`poolse-conversation--density-${density}`,
|
|
3263
|
+
dragActive ? "is-drag-active" : ""
|
|
3264
|
+
].filter(Boolean).join(" "),
|
|
2865
3265
|
onDragEnter,
|
|
2866
3266
|
onDragOver,
|
|
2867
3267
|
onDragLeave,
|
|
@@ -2903,12 +3303,9 @@ function ConversationView({
|
|
|
2903
3303
|
children: [
|
|
2904
3304
|
hasMore && /* @__PURE__ */ jsx("div", { ref: topSentinelRef, "aria-hidden": "true", style: { height: 1 } }),
|
|
2905
3305
|
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." }) : visibleMessages.map((msg, idx) => {
|
|
2906
|
-
if (renderMessage) {
|
|
2907
|
-
return /* @__PURE__ */ jsx(Fragment$1, { children: renderMessage(msg, me?.id ?? null) }, msg.id);
|
|
2908
|
-
}
|
|
2909
3306
|
const prev = idx > 0 ? visibleMessages[idx - 1] ?? null : null;
|
|
2910
3307
|
const next = idx < visibleMessages.length - 1 ? visibleMessages[idx + 1] ?? null : null;
|
|
2911
|
-
const groupPosition = grouping ? computeGroupPosition(msg, prev, next,
|
|
3308
|
+
const groupPosition = grouping ? computeGroupPosition(msg, prev, next, groupWindowMs) : "standalone";
|
|
2912
3309
|
const showDaySeparator = daySeparators && (prev === null || !sameDay(msg.inserted_at, prev.inserted_at));
|
|
2913
3310
|
const enriched = quotations && msg.quoted_message_id && !msg.quoted_message ? (() => {
|
|
2914
3311
|
const original = messages.find((m) => m.id === msg.quoted_message_id);
|
|
@@ -2927,47 +3324,58 @@ function ConversationView({
|
|
|
2927
3324
|
})() : msg;
|
|
2928
3325
|
const isSelf = me !== null && msg.sender_id === me.id;
|
|
2929
3326
|
const readState = showReadState && isSelf && maxReadByOthers !== null ? maxReadByOthers >= msg.sequence ? "read" : "sent" : void 0;
|
|
3327
|
+
const renderDefault = () => /* @__PURE__ */ jsx(
|
|
3328
|
+
MessageRow,
|
|
3329
|
+
{
|
|
3330
|
+
msg: enriched,
|
|
3331
|
+
meId: me?.id ?? null,
|
|
3332
|
+
reactions,
|
|
3333
|
+
attachments,
|
|
3334
|
+
actions,
|
|
3335
|
+
threads,
|
|
3336
|
+
quotations: canQuote,
|
|
3337
|
+
groupPosition,
|
|
3338
|
+
maxBodyLength,
|
|
3339
|
+
markdown,
|
|
3340
|
+
showSenderName: showSenderLabelsResolved,
|
|
3341
|
+
showAvatar: showAvatarsResolved,
|
|
3342
|
+
...onSenderPress ? { onSenderPress } : {},
|
|
3343
|
+
...onAvatarPress ? { onAvatarPress } : {},
|
|
3344
|
+
...readState ? { readState } : {},
|
|
3345
|
+
...labelFor ? { labelFor } : {},
|
|
3346
|
+
editing: editingId === msg.id,
|
|
3347
|
+
...canEditOwnMessage({
|
|
3348
|
+
isSelf,
|
|
3349
|
+
deleted: !!msg.deleted_at,
|
|
3350
|
+
receiptsVisible,
|
|
3351
|
+
readState,
|
|
3352
|
+
insertedAt: msg.inserted_at
|
|
3353
|
+
}) ? { onStartEdit: () => setEditingId(msg.id) } : {},
|
|
3354
|
+
onCancelEdit: () => setEditingId(null),
|
|
3355
|
+
onSaveEdit: async (body) => {
|
|
3356
|
+
await edit(msg.id, body);
|
|
3357
|
+
setEditingId(null);
|
|
3358
|
+
},
|
|
3359
|
+
onDelete: () => void deleteMsg(msg.id),
|
|
3360
|
+
onOpenThread: () => setThreadRootId(msg.id),
|
|
3361
|
+
onQuote: () => setReplyingTo(msg),
|
|
3362
|
+
onQuotedClick: scrollToOriginal,
|
|
3363
|
+
...onCallBack ? { onCallBack } : {},
|
|
3364
|
+
...layoutProps,
|
|
3365
|
+
mentionsMe: mentionsViewer(msg, me?.id ?? null)
|
|
3366
|
+
}
|
|
3367
|
+
);
|
|
3368
|
+
if (renderMessage) {
|
|
3369
|
+
return /* @__PURE__ */ jsx(Fragment$1, { children: renderMessage(msg, me?.id ?? null, {
|
|
3370
|
+
layout,
|
|
3371
|
+
groupPosition,
|
|
3372
|
+
isRunStart: layout === "compact" || groupPosition === "first" || groupPosition === "standalone",
|
|
3373
|
+
renderDefault
|
|
3374
|
+
}) }, msg.id);
|
|
3375
|
+
}
|
|
2930
3376
|
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
2931
3377
|
showDaySeparator && /* @__PURE__ */ jsx("div", { className: "poolse-day-separator", "aria-hidden": "false", children: /* @__PURE__ */ jsx("span", { children: formatDayLabel(msg.inserted_at) }) }),
|
|
2932
|
-
|
|
2933
|
-
MessageRow,
|
|
2934
|
-
{
|
|
2935
|
-
msg: enriched,
|
|
2936
|
-
meId: me?.id ?? null,
|
|
2937
|
-
reactions,
|
|
2938
|
-
attachments,
|
|
2939
|
-
actions,
|
|
2940
|
-
threads,
|
|
2941
|
-
quotations: canQuote,
|
|
2942
|
-
groupPosition,
|
|
2943
|
-
maxBodyLength,
|
|
2944
|
-
markdown,
|
|
2945
|
-
showSenderName: showSenderLabelsResolved,
|
|
2946
|
-
showAvatar: showAvatarsResolved,
|
|
2947
|
-
...onSenderPress ? { onSenderPress } : {},
|
|
2948
|
-
...onAvatarPress ? { onAvatarPress } : {},
|
|
2949
|
-
...readState ? { readState } : {},
|
|
2950
|
-
...labelFor ? { labelFor } : {},
|
|
2951
|
-
editing: editingId === msg.id,
|
|
2952
|
-
...canEditOwnMessage({
|
|
2953
|
-
isSelf,
|
|
2954
|
-
deleted: !!msg.deleted_at,
|
|
2955
|
-
receiptsVisible,
|
|
2956
|
-
readState,
|
|
2957
|
-
insertedAt: msg.inserted_at
|
|
2958
|
-
}) ? { onStartEdit: () => setEditingId(msg.id) } : {},
|
|
2959
|
-
onCancelEdit: () => setEditingId(null),
|
|
2960
|
-
onSaveEdit: async (body) => {
|
|
2961
|
-
await edit(msg.id, body);
|
|
2962
|
-
setEditingId(null);
|
|
2963
|
-
},
|
|
2964
|
-
onDelete: () => void deleteMsg(msg.id),
|
|
2965
|
-
onOpenThread: () => setThreadRootId(msg.id),
|
|
2966
|
-
onQuote: () => setReplyingTo(msg),
|
|
2967
|
-
onQuotedClick: scrollToOriginal,
|
|
2968
|
-
...onCallBack ? { onCallBack } : {}
|
|
2969
|
-
}
|
|
2970
|
-
)
|
|
3378
|
+
renderDefault()
|
|
2971
3379
|
] }, msg.id);
|
|
2972
3380
|
}),
|
|
2973
3381
|
visibleStreams.map(
|
|
@@ -2983,7 +3391,8 @@ function ConversationView({
|
|
|
2983
3391
|
markdown,
|
|
2984
3392
|
showSenderName: showSenderLabelsResolved,
|
|
2985
3393
|
showAvatar: showAvatarsResolved,
|
|
2986
|
-
...labelFor ? { labelFor } : {}
|
|
3394
|
+
...labelFor ? { labelFor } : {},
|
|
3395
|
+
...layoutProps
|
|
2987
3396
|
}
|
|
2988
3397
|
) }, stream.id)
|
|
2989
3398
|
),
|
|
@@ -3024,7 +3433,9 @@ function ConversationView({
|
|
|
3024
3433
|
{
|
|
3025
3434
|
conversationId,
|
|
3026
3435
|
rootMessage: threadRoot,
|
|
3027
|
-
onClose: () => setThreadRootId(null)
|
|
3436
|
+
onClose: () => setThreadRootId(null),
|
|
3437
|
+
layout,
|
|
3438
|
+
...timeFormat ? { timeFormat } : {}
|
|
3028
3439
|
}
|
|
3029
3440
|
) })
|
|
3030
3441
|
] });
|
|
@@ -3933,6 +4344,61 @@ function useElapsed(startedAt, running) {
|
|
|
3933
4344
|
const s = String(total % 60).padStart(2, "0");
|
|
3934
4345
|
return h > 0 ? `${h}:${String(m).padStart(2, "0")}:${s}` : `${m}:${s}`;
|
|
3935
4346
|
}
|
|
4347
|
+
var ThemeContext = createContext(null);
|
|
4348
|
+
var DARK_QUERY = "(prefers-color-scheme: dark)";
|
|
4349
|
+
function systemScheme() {
|
|
4350
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") return "light";
|
|
4351
|
+
return window.matchMedia(DARK_QUERY).matches ? "dark" : "light";
|
|
4352
|
+
}
|
|
4353
|
+
function useSystemColorScheme() {
|
|
4354
|
+
const [scheme, setScheme] = useState(systemScheme);
|
|
4355
|
+
useEffect(() => {
|
|
4356
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") return;
|
|
4357
|
+
const mql = window.matchMedia(DARK_QUERY);
|
|
4358
|
+
const onChange = () => setScheme(mql.matches ? "dark" : "light");
|
|
4359
|
+
onChange();
|
|
4360
|
+
if (typeof mql.addEventListener === "function") {
|
|
4361
|
+
mql.addEventListener("change", onChange);
|
|
4362
|
+
return () => mql.removeEventListener("change", onChange);
|
|
4363
|
+
}
|
|
4364
|
+
mql.addListener(onChange);
|
|
4365
|
+
return () => mql.removeListener(onChange);
|
|
4366
|
+
}, []);
|
|
4367
|
+
return scheme;
|
|
4368
|
+
}
|
|
4369
|
+
function PoolseTheme({
|
|
4370
|
+
theme,
|
|
4371
|
+
colorScheme = "system",
|
|
4372
|
+
className,
|
|
4373
|
+
style,
|
|
4374
|
+
children
|
|
4375
|
+
}) {
|
|
4376
|
+
const system = useSystemColorScheme();
|
|
4377
|
+
const scheme = colorScheme === "system" ? system : colorScheme;
|
|
4378
|
+
const value = useMemo(
|
|
4379
|
+
() => ({ theme: theme ? resolveTheme(theme, scheme) : null, colorScheme: scheme }),
|
|
4380
|
+
[theme, scheme]
|
|
4381
|
+
);
|
|
4382
|
+
const vars = useMemo(
|
|
4383
|
+
() => value.theme ? tokensToCssVariables(value.theme) : null,
|
|
4384
|
+
[value.theme]
|
|
4385
|
+
);
|
|
4386
|
+
return /* @__PURE__ */ jsx(ThemeContext.Provider, { value, children: /* @__PURE__ */ jsx(
|
|
4387
|
+
"div",
|
|
4388
|
+
{
|
|
4389
|
+
className: className ? `poolse-theme ${className}` : "poolse-theme",
|
|
4390
|
+
"data-theme": scheme,
|
|
4391
|
+
"data-poolse-theme": value.theme?.id,
|
|
4392
|
+
style: vars || style ? { ...vars, ...style } : void 0,
|
|
4393
|
+
children
|
|
4394
|
+
}
|
|
4395
|
+
) });
|
|
4396
|
+
}
|
|
4397
|
+
function useTheme() {
|
|
4398
|
+
const value = useContext(ThemeContext);
|
|
4399
|
+
const system = useSystemColorScheme();
|
|
4400
|
+
return value ?? { theme: null, colorScheme: system };
|
|
4401
|
+
}
|
|
3936
4402
|
var MARK_PATHS = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3937
4403
|
/* @__PURE__ */ jsx(
|
|
3938
4404
|
"path",
|
|
@@ -4041,6 +4507,6 @@ function PoolseLogo({
|
|
|
4041
4507
|
);
|
|
4042
4508
|
}
|
|
4043
4509
|
|
|
4044
|
-
export { AttachmentPreview, Avatar, CallControlButton, CallDeviceMenu, CallLogRow, CallVideoGrid, ChatHeader, ConversationList, ConversationView, EditableMessageBubble, GroupDetailsSheet, LiveCallBanner, MemberList, MentionInput, MessageActions, MessageBubble, MessageComposer, PoolseFonts, PoolseIcon, PoolseInbox, PoolseLogo, ReactionPicker, ReactionStrip, RoomJoinBar, RoomStage, ThreadView, TypingIndicator, UploadQueueStrip, UserName, UserPickerSheet, useDisplayName, usePoolseFonts };
|
|
4510
|
+
export { AttachmentPreview, Avatar, CallControlButton, CallDeviceMenu, CallLogRow, CallVideoGrid, ChatHeader, ConversationList, ConversationView, EditableMessageBubble, GroupDetailsSheet, LiveCallBanner, MemberList, MentionInput, MessageActions, MessageBubble, MessageComposer, PoolseFonts, PoolseIcon, PoolseInbox, PoolseLogo, PoolseTheme, ReactionPicker, ReactionStrip, RoomJoinBar, RoomStage, ThreadView, TypingIndicator, UploadQueueStrip, UserName, UserPickerSheet, useDisplayName, usePoolseFonts, useSystemColorScheme, useTheme };
|
|
4045
4511
|
//# sourceMappingURL=index.js.map
|
|
4046
4512
|
//# sourceMappingURL=index.js.map
|