@poolse/react-ui 3.2.0 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -6,6 +6,7 @@ var jsxRuntime = require('react/jsx-runtime');
6
6
  var react$1 = require('@poolse/react');
7
7
  var ReactMarkdown = require('react-markdown');
8
8
  var remarkGfm = require('remark-gfm');
9
+ var theme = require('@poolse/theme');
9
10
 
10
11
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
12
 
@@ -751,6 +752,31 @@ function PoolseFonts() {
751
752
  usePoolseFonts(true);
752
753
  return null;
753
754
  }
755
+
756
+ // src/layout.ts
757
+ function formatMessageTime(iso, format) {
758
+ if (!iso) return "";
759
+ const date = new Date(iso);
760
+ if (Number.isNaN(date.getTime())) return "";
761
+ if (typeof format === "function") return format(date);
762
+ if (format === "12h") {
763
+ return date.toLocaleTimeString(void 0, { hour: "numeric", minute: "2-digit", hour12: true });
764
+ }
765
+ if (format === "24h") {
766
+ return date.toLocaleTimeString(void 0, {
767
+ hour: "2-digit",
768
+ minute: "2-digit",
769
+ hourCycle: "h23"
770
+ });
771
+ }
772
+ return date.toLocaleTimeString(void 0, { hour: "2-digit", minute: "2-digit" });
773
+ }
774
+ function mentionsViewer(msg, meId) {
775
+ return meId !== null && msg.sender_id !== meId && (msg.mentions ?? []).includes(meId);
776
+ }
777
+ function renderSlot(slot, ctx, children) {
778
+ return slot && ctx ? slot({ ...ctx, children }) : children;
779
+ }
754
780
  function LiveCallBanner({ call, inCall, onJoin }) {
755
781
  const what = call.kind === "room" ? call.media === "video" ? "Video room" : "Voice room" : call.media === "video" ? "Video call in progress" : "Voice call in progress";
756
782
  const who = inCall > 0 ? `${inCall} ${call.kind === "room" ? "in the room" : "on the call"}` : call.kind === "room" ? "Starting" : "Ringing";
@@ -1642,8 +1668,12 @@ function MessageBubble({
1642
1668
  maxBodyLength = 0,
1643
1669
  markdown = false,
1644
1670
  showSenderName = false,
1671
+ onSenderPress,
1645
1672
  actionsTrigger,
1646
- showAttachments = true
1673
+ showAttachments = true,
1674
+ timeFormat,
1675
+ slots,
1676
+ slotContext
1647
1677
  }) {
1648
1678
  const isSelf = currentUserId !== null && message.sender_id === currentUserId;
1649
1679
  const [expanded, setExpanded] = react.useState(false);
@@ -1654,8 +1684,8 @@ function MessageBubble({
1654
1684
  const senderColorHex = senderColorKey ? userColor(senderColorKey) : "currentColor";
1655
1685
  const renderSenderName = showSenderName && !isSelf && (groupPosition === "first" || groupPosition === "standalone");
1656
1686
  const rawBody = message.body ?? "";
1657
- const TRIM_BUFFER = 40;
1658
- const shouldTrim = !expanded && maxBodyLength > 0 && rawBody.length > maxBodyLength + TRIM_BUFFER;
1687
+ const TRIM_BUFFER2 = 40;
1688
+ const shouldTrim = !expanded && maxBodyLength > 0 && rawBody.length > maxBodyLength + TRIM_BUFFER2;
1659
1689
  const displayBody = shouldTrim ? rawBody.slice(0, maxBodyLength).trimEnd() + "\u2026" : rawBody;
1660
1690
  const attachmentList = showAttachments && !message.deleted_at && Array.isArray(message.attachments) ? message.attachments : [];
1661
1691
  const imageAttachments = attachmentList.filter((a) => isImageContentType(a.content_type));
@@ -1664,7 +1694,7 @@ function MessageBubble({
1664
1694
  const hasVisibleBody = !message.deleted_at && rawBody.length > 0;
1665
1695
  const metaOverlay = hasAnyAttachment && imageAttachments.length > 0 && !hasVisibleBody && fileAttachments.length === 0;
1666
1696
  const jumboCount = hasVisibleBody && !hasAnyAttachment && !message.quoted_message_id ? emojiOnlyCount(rawBody) : 0;
1667
- const trimToggleVisible = shouldTrim || expanded && rawBody.length > maxBodyLength + TRIM_BUFFER;
1697
+ const trimToggleVisible = shouldTrim || expanded && rawBody.length > maxBodyLength + TRIM_BUFFER2;
1668
1698
  const inlineMeta = hasVisibleBody && jumboCount === 0 && !trimToggleVisible && (!markdown || !hasMarkdown(displayBody));
1669
1699
  const className = [
1670
1700
  "poolse-message",
@@ -1678,14 +1708,24 @@ function MessageBubble({
1678
1708
  metaOverlay ? "poolse-message--media-only" : "",
1679
1709
  jumboCount > 0 ? "poolse-message--jumbo" : ""
1680
1710
  ].filter(Boolean).join(" ");
1681
- const time = message.inserted_at ? new Date(message.inserted_at).toLocaleTimeString(void 0, {
1682
- hour: "2-digit",
1683
- minute: "2-digit"
1684
- }) : "";
1711
+ const time = formatMessageTime(message.inserted_at, timeFormat);
1685
1712
  const showQuoteCard = message.quoted_message !== void 0 && message.quoted_message !== null ? "full" : message.quoted_message_id ? "placeholder" : null;
1686
1713
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, children: [
1687
1714
  actionsTrigger,
1688
- renderSenderName && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-message__sender", style: { color: senderColorHex }, children: senderName }),
1715
+ renderSlot(
1716
+ slots?.header,
1717
+ slotContext,
1718
+ renderSenderName ? onSenderPress ? /* @__PURE__ */ jsxRuntime.jsx(
1719
+ "button",
1720
+ {
1721
+ type: "button",
1722
+ className: "poolse-message__sender poolse-message__sender--button",
1723
+ style: { color: senderColorHex },
1724
+ onClick: onSenderPress,
1725
+ children: senderName
1726
+ }
1727
+ ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-message__sender", style: { color: senderColorHex }, children: senderName }) : null
1728
+ ),
1689
1729
  showQuoteCard === "full" && /* @__PURE__ */ jsxRuntime.jsx(
1690
1730
  QuotedCard,
1691
1731
  {
@@ -1696,8 +1736,14 @@ function MessageBubble({
1696
1736
  }
1697
1737
  ),
1698
1738
  showQuoteCard === "placeholder" && /* @__PURE__ */ jsxRuntime.jsx(QuotedPlaceholder, { isSelf, quotedMessageId: message.quoted_message_id }),
1699
- imageAttachments.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(ImageMosaic, { images: imageAttachments }),
1700
- fileAttachments.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-message__files", children: fileAttachments.map((att) => /* @__PURE__ */ jsxRuntime.jsx(AttachmentPreview, { attachment: att }, att.id)) }),
1739
+ renderSlot(
1740
+ slots?.attachments,
1741
+ slotContext,
1742
+ hasAnyAttachment ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1743
+ imageAttachments.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(ImageMosaic, { images: imageAttachments }),
1744
+ fileAttachments.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-message__files", children: fileAttachments.map((att) => /* @__PURE__ */ jsxRuntime.jsx(AttachmentPreview, { attachment: att }, att.id)) })
1745
+ ] }) : null
1746
+ ),
1701
1747
  (() => {
1702
1748
  const metaContent = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1703
1749
  /* @__PURE__ */ jsxRuntime.jsx("span", { children: time }),
@@ -1754,7 +1800,7 @@ function MessageBubble({
1754
1800
  children: "Read more"
1755
1801
  }
1756
1802
  ),
1757
- !shouldTrim && expanded && rawBody.length > maxBodyLength + TRIM_BUFFER && /* @__PURE__ */ jsxRuntime.jsx(
1803
+ !shouldTrim && expanded && rawBody.length > maxBodyLength + TRIM_BUFFER2 && /* @__PURE__ */ jsxRuntime.jsx(
1758
1804
  "button",
1759
1805
  {
1760
1806
  type: "button",
@@ -1771,7 +1817,7 @@ function MessageBubble({
1771
1817
  ) : null;
1772
1818
  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";
1773
1819
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1774
- body,
1820
+ renderSlot(slots?.body, slotContext, body),
1775
1821
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: metaClass, children: metaContent })
1776
1822
  ] });
1777
1823
  })()
@@ -2059,9 +2105,12 @@ function MessageActions({
2059
2105
  onCopy,
2060
2106
  onEdit,
2061
2107
  onDelete,
2108
+ moreMenu = false,
2062
2109
  children
2063
2110
  }) {
2064
2111
  const [pickerOpen, setPickerOpen] = react.useState(false);
2112
+ const [menuOpen, setMenuOpen] = react.useState(false);
2113
+ const hasMore = !!(onCopy || onEdit || onDelete);
2065
2114
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-msg-actions", role: "toolbar", "aria-label": "Message actions", children: [
2066
2115
  onReact && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2067
2116
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -2084,12 +2133,60 @@ function MessageActions({
2084
2133
  }
2085
2134
  ) })
2086
2135
  ] }),
2087
- onReply && /* @__PURE__ */ jsxRuntime.jsx(ActionButton, { label: "Reply in thread", icon: "messages", onClick: onReply }),
2088
- onQuote && /* @__PURE__ */ jsxRuntime.jsx(ActionButton, { label: "Reply", icon: "reply", onClick: onQuote }),
2089
- onCopy && /* @__PURE__ */ jsxRuntime.jsx(ActionButton, { label: "Copy", icon: "copy", onClick: onCopy }),
2090
- onEdit && /* @__PURE__ */ jsxRuntime.jsx(ActionButton, { label: "Edit", icon: "edit", onClick: onEdit }),
2091
- onDelete && /* @__PURE__ */ jsxRuntime.jsx(ActionButton, { label: "Delete", icon: "trash", danger: true, onClick: onDelete }),
2092
- children
2136
+ moreMenu ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2137
+ onQuote && /* @__PURE__ */ jsxRuntime.jsx(ActionButton, { label: "Reply", icon: "reply", onClick: onQuote }),
2138
+ onReply && /* @__PURE__ */ jsxRuntime.jsx(ActionButton, { label: "Reply in thread", icon: "messages", onClick: onReply }),
2139
+ children,
2140
+ hasMore && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2141
+ /* @__PURE__ */ jsxRuntime.jsx(
2142
+ ActionButton,
2143
+ {
2144
+ label: "More actions",
2145
+ icon: "more-h",
2146
+ onClick: () => setMenuOpen((o) => !o),
2147
+ active: menuOpen
2148
+ }
2149
+ ),
2150
+ menuOpen && /* @__PURE__ */ jsxRuntime.jsx(
2151
+ "div",
2152
+ {
2153
+ className: "poolse-msg-actions__menu",
2154
+ role: "menu",
2155
+ onKeyDown: (e) => {
2156
+ if (e.key === "Escape") setMenuOpen(false);
2157
+ },
2158
+ children: [
2159
+ onCopy && { label: "Copy", icon: "copy", run: onCopy },
2160
+ onEdit && { label: "Edit", icon: "edit", run: onEdit },
2161
+ onDelete && { label: "Delete", icon: "trash", run: onDelete }
2162
+ ].filter((item) => !!item).map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
2163
+ "button",
2164
+ {
2165
+ type: "button",
2166
+ role: "menuitem",
2167
+ className: `poolse-msg-actions__menu-item${item.label === "Delete" ? " poolse-msg-actions__menu-item--danger" : ""}`,
2168
+ onClick: () => {
2169
+ setMenuOpen(false);
2170
+ item.run();
2171
+ },
2172
+ children: [
2173
+ /* @__PURE__ */ jsxRuntime.jsx(PoolseIcon, { name: item.icon, size: 15, label: null }),
2174
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: item.label })
2175
+ ]
2176
+ },
2177
+ item.label
2178
+ ))
2179
+ }
2180
+ )
2181
+ ] })
2182
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2183
+ onReply && /* @__PURE__ */ jsxRuntime.jsx(ActionButton, { label: "Reply in thread", icon: "messages", onClick: onReply }),
2184
+ onQuote && /* @__PURE__ */ jsxRuntime.jsx(ActionButton, { label: "Reply", icon: "reply", onClick: onQuote }),
2185
+ onCopy && /* @__PURE__ */ jsxRuntime.jsx(ActionButton, { label: "Copy", icon: "copy", onClick: onCopy }),
2186
+ onEdit && /* @__PURE__ */ jsxRuntime.jsx(ActionButton, { label: "Edit", icon: "edit", onClick: onEdit }),
2187
+ onDelete && /* @__PURE__ */ jsxRuntime.jsx(ActionButton, { label: "Delete", icon: "trash", danger: true, onClick: onDelete }),
2188
+ children
2189
+ ] })
2093
2190
  ] });
2094
2191
  }
2095
2192
  function ActionButton({
@@ -2106,6 +2203,319 @@ function ActionButton({
2106
2203
  ].filter(Boolean).join(" ");
2107
2204
  return /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: classes, "aria-label": label, title: label, onClick, children: /* @__PURE__ */ jsxRuntime.jsx(PoolseIcon, { name: icon, size: 16, label: null }) });
2108
2205
  }
2206
+ function useRowActions() {
2207
+ const [actionsOpen, setActionsOpen] = react.useState(false);
2208
+ const rowRef = react.useRef(null);
2209
+ react.useEffect(() => {
2210
+ if (!actionsOpen) return;
2211
+ const onDown = (e) => {
2212
+ const t = e.target;
2213
+ if (t instanceof Node && rowRef.current && !rowRef.current.contains(t)) {
2214
+ setActionsOpen(false);
2215
+ }
2216
+ };
2217
+ document.addEventListener("pointerdown", onDown);
2218
+ return () => document.removeEventListener("pointerdown", onDown);
2219
+ }, [actionsOpen]);
2220
+ const onRowClick = (e) => {
2221
+ if (typeof window === "undefined" || !window.matchMedia("(hover: none)").matches) return;
2222
+ const target = e.target;
2223
+ if (target.closest("a, button, input, textarea, label, select")) return;
2224
+ setActionsOpen((o) => !o);
2225
+ };
2226
+ return { actionsOpen, setActionsOpen, rowRef, onRowClick };
2227
+ }
2228
+ function InlineReactions({
2229
+ reactions,
2230
+ currentUserId,
2231
+ onAdd,
2232
+ onRemove
2233
+ }) {
2234
+ const entries = Object.entries(reactions);
2235
+ if (entries.length === 0) return null;
2236
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-reactions", children: entries.map(([emoji, users]) => {
2237
+ const mine = currentUserId !== null && currentUserId !== void 0 && users.includes(currentUserId);
2238
+ return /* @__PURE__ */ jsxRuntime.jsxs(
2239
+ "button",
2240
+ {
2241
+ type: "button",
2242
+ className: `poolse-reaction-pill${mine ? " poolse-reaction-pill--mine" : ""}`,
2243
+ onClick: () => {
2244
+ if (mine) onRemove(emoji);
2245
+ else onAdd(emoji);
2246
+ },
2247
+ "aria-pressed": mine,
2248
+ "aria-label": `${emoji} reacted by ${users.length} ${users.length === 1 ? "user" : "users"}`,
2249
+ children: [
2250
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: emoji }),
2251
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-reaction-pill__count", children: users.length })
2252
+ ]
2253
+ },
2254
+ emoji
2255
+ );
2256
+ }) });
2257
+ }
2258
+ var TRIM_BUFFER = 40;
2259
+ function FlatMessageRow({
2260
+ msg,
2261
+ meId,
2262
+ layout,
2263
+ reactions = true,
2264
+ attachments = true,
2265
+ actions = true,
2266
+ threads = true,
2267
+ quotations = true,
2268
+ readState,
2269
+ editing = false,
2270
+ onStartEdit,
2271
+ onCancelEdit,
2272
+ onSaveEdit,
2273
+ onDelete,
2274
+ onOpenThread,
2275
+ onQuote,
2276
+ labelFor,
2277
+ onQuotedClick,
2278
+ groupPosition = "standalone",
2279
+ maxBodyLength = 0,
2280
+ markdown = false,
2281
+ showAvatar = layout === "list",
2282
+ onSenderPress,
2283
+ onAvatarPress,
2284
+ timeFormat,
2285
+ slots,
2286
+ mentionsMe = false
2287
+ }) {
2288
+ const compact = layout === "compact";
2289
+ const isSelf = meId !== null && msg.sender_id === meId;
2290
+ const { profile } = react$1.useUser(msg.sender_external_id);
2291
+ const senderName = profile?.displayName ?? msg.sender_external_id ?? (msg.sender_id ? `User ${msg.sender_id.slice(0, 6)}` : "Unknown");
2292
+ const sender = {
2293
+ userId: msg.sender_id,
2294
+ externalId: msg.sender_external_id,
2295
+ displayName: senderName,
2296
+ avatarUrl: profile?.avatarUrl ?? null
2297
+ };
2298
+ const isRunStart = compact || groupPosition === "first" || groupPosition === "standalone";
2299
+ const ctx = { message: msg, isSelf, sender, layout, isRunStart };
2300
+ const reactionsHook = react$1.useReactions(reactions ? msg.id : "", {
2301
+ conversationId: msg.conversation_id,
2302
+ initialReactions: msg.reactions,
2303
+ currentUserId: meId
2304
+ });
2305
+ const { actionsOpen, rowRef, onRowClick } = useRowActions();
2306
+ const deleted = !!msg.deleted_at;
2307
+ const time = formatMessageTime(msg.inserted_at, timeFormat);
2308
+ const replyCount = msg.reply_count ?? 0;
2309
+ const showThreadLink = threads && !deleted && !msg.thread_root_id && replyCount > 0;
2310
+ const showActions = actions && !deleted && !editing;
2311
+ const timeEl = (className) => /* @__PURE__ */ jsxRuntime.jsx("time", { className, dateTime: msg.inserted_at, children: time });
2312
+ const avatarSize = compact ? "sm" : "md";
2313
+ const avatar = !showAvatar ? null : onAvatarPress && !isSelf ? /* @__PURE__ */ jsxRuntime.jsx(
2314
+ "button",
2315
+ {
2316
+ type: "button",
2317
+ className: "poolse-row__avatar-button",
2318
+ "aria-label": senderName,
2319
+ onClick: () => onAvatarPress(sender),
2320
+ children: /* @__PURE__ */ jsxRuntime.jsx(Avatar, { src: sender.avatarUrl, name: senderName, size: avatarSize })
2321
+ }
2322
+ ) : /* @__PURE__ */ jsxRuntime.jsx(Avatar, { src: sender.avatarUrl, name: senderName, size: avatarSize });
2323
+ const nameStyle = compact ? { color: userColor(msg.sender_external_id ?? msg.sender_id ?? "") } : void 0;
2324
+ const name = onSenderPress && !isSelf ? /* @__PURE__ */ jsxRuntime.jsx(
2325
+ "button",
2326
+ {
2327
+ type: "button",
2328
+ className: "poolse-row__name poolse-row__name--button",
2329
+ style: nameStyle,
2330
+ onClick: () => onSenderPress(sender),
2331
+ children: senderName
2332
+ }
2333
+ ) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-row__name", style: nameStyle, children: senderName });
2334
+ const header = compact ? name : isRunStart ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-row__header", children: [
2335
+ name,
2336
+ timeEl("poolse-row__time")
2337
+ ] }) : null;
2338
+ const quote = msg.quoted_message !== void 0 && msg.quoted_message !== null ? /* @__PURE__ */ jsxRuntime.jsx(
2339
+ QuotedCard,
2340
+ {
2341
+ quoted: msg.quoted_message,
2342
+ isSelf: false,
2343
+ ...labelFor ? { labelFor } : {},
2344
+ ...onQuotedClick ? { onClick: onQuotedClick } : {}
2345
+ }
2346
+ ) : msg.quoted_message_id ? /* @__PURE__ */ jsxRuntime.jsx(QuotedPlaceholder, { isSelf: false, quotedMessageId: msg.quoted_message_id }) : null;
2347
+ const attachmentList = attachments && !deleted && Array.isArray(msg.attachments) ? msg.attachments : [];
2348
+ const images = attachmentList.filter((a) => isImageContentType(a.content_type));
2349
+ const files = attachmentList.filter((a) => !isImageContentType(a.content_type));
2350
+ const attachmentsEl = images.length > 0 || files.length > 0 ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-row__attachments", children: [
2351
+ images.length > 0 && /* @__PURE__ */ jsxRuntime.jsx(ImageMosaic, { images }),
2352
+ files.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-message__files", children: files.map((att) => /* @__PURE__ */ jsxRuntime.jsx(AttachmentPreview, { attachment: att }, att.id)) })
2353
+ ] }) : null;
2354
+ const meta = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2355
+ msg.edited_at && !deleted ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-row__edited", children: "(edited)" }) : null,
2356
+ isSelf && readState ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-row__receipt", children: /* @__PURE__ */ jsxRuntime.jsx(
2357
+ PoolseIcon,
2358
+ {
2359
+ name: readState === "read" ? "check-double" : "check",
2360
+ size: 14,
2361
+ label: readState === "read" ? "Read" : "Sent"
2362
+ }
2363
+ ) }) : null
2364
+ ] });
2365
+ const body = editing ? (
2366
+ // `currentUserId={null}` styles the editor as a neutral card rather
2367
+ // than an own-message bubble, which would look out of place in a row.
2368
+ /* @__PURE__ */ jsxRuntime.jsx(
2369
+ EditableMessageBubble,
2370
+ {
2371
+ message: msg,
2372
+ currentUserId: null,
2373
+ editing: true,
2374
+ onSave: onSaveEdit ?? (async () => void 0),
2375
+ onCancel: onCancelEdit ?? (() => void 0)
2376
+ }
2377
+ )
2378
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
2379
+ FlatBody,
2380
+ {
2381
+ message: msg,
2382
+ markdown,
2383
+ maxBodyLength,
2384
+ hasAttachments: attachmentList.length > 0,
2385
+ meta
2386
+ }
2387
+ );
2388
+ const reactionsEl = reactions && !deleted ? /* @__PURE__ */ jsxRuntime.jsx(
2389
+ InlineReactions,
2390
+ {
2391
+ reactions: reactionsHook.reactions,
2392
+ currentUserId: meId,
2393
+ onAdd: (e) => void reactionsHook.addReaction(e),
2394
+ onRemove: (e) => void reactionsHook.removeReaction(e)
2395
+ }
2396
+ ) : null;
2397
+ const threadEl = showThreadLink ? /* @__PURE__ */ jsxRuntime.jsxs(
2398
+ "button",
2399
+ {
2400
+ type: "button",
2401
+ className: "poolse-row__thread",
2402
+ onClick: onOpenThread,
2403
+ "aria-label": `View ${replyCount} ${replyCount === 1 ? "reply" : "replies"}`,
2404
+ children: [
2405
+ /* @__PURE__ */ jsxRuntime.jsx(PoolseIcon, { name: "messages", size: 14, label: null }),
2406
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
2407
+ replyCount,
2408
+ " ",
2409
+ replyCount === 1 ? "reply" : "replies"
2410
+ ] })
2411
+ ]
2412
+ }
2413
+ ) : null;
2414
+ const toolbar = showActions ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-row__toolbar", children: /* @__PURE__ */ jsxRuntime.jsx(
2415
+ MessageActions,
2416
+ {
2417
+ moreMenu: true,
2418
+ ...reactions ? { onReact: (emoji) => void reactionsHook.addReaction(emoji) } : {},
2419
+ ...quotations && onQuote ? { onQuote } : {},
2420
+ ...threads && onOpenThread ? { onReply: onOpenThread } : {},
2421
+ ...msg.body ? {
2422
+ onCopy: () => {
2423
+ void navigator?.clipboard?.writeText(msg.body ?? "").catch(() => void 0);
2424
+ }
2425
+ } : {},
2426
+ ...isSelf && onStartEdit ? { onEdit: onStartEdit } : {},
2427
+ ...isSelf && onDelete ? { onDelete } : {}
2428
+ }
2429
+ ) }) : null;
2430
+ const content = /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-row__content", children: [
2431
+ !compact && renderSlot(slots?.header, ctx, header),
2432
+ quote,
2433
+ renderSlot(slots?.attachments, ctx, attachmentsEl),
2434
+ renderSlot(slots?.body, ctx, body),
2435
+ renderSlot(slots?.reactions, ctx, reactionsEl),
2436
+ renderSlot(slots?.thread, ctx, threadEl)
2437
+ ] });
2438
+ return /* @__PURE__ */ jsxRuntime.jsxs(
2439
+ "div",
2440
+ {
2441
+ ref: rowRef,
2442
+ className: [
2443
+ "poolse-row",
2444
+ `poolse-row--${layout}`,
2445
+ isRunStart ? "poolse-row--run-start" : "poolse-row--continued",
2446
+ isSelf ? "poolse-row--self" : "",
2447
+ mentionsMe ? "poolse-row--mention" : "",
2448
+ editing ? "poolse-row--editing" : ""
2449
+ ].filter(Boolean).join(" "),
2450
+ "data-message-id": msg.id,
2451
+ "data-actions-open": actionsOpen || void 0,
2452
+ onClick: onRowClick,
2453
+ children: [
2454
+ compact ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2455
+ timeEl("poolse-row__time"),
2456
+ avatar ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-row__avatar", children: avatar }) : null,
2457
+ renderSlot(slots?.header, ctx, header),
2458
+ content
2459
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
2460
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-row__gutter", children: isRunStart ? avatar : timeEl("poolse-row__gutter-time") }),
2461
+ content
2462
+ ] }),
2463
+ renderSlot(slots?.actions, ctx, toolbar)
2464
+ ]
2465
+ }
2466
+ );
2467
+ }
2468
+ function FlatBody({
2469
+ message,
2470
+ markdown,
2471
+ maxBodyLength,
2472
+ hasAttachments,
2473
+ meta
2474
+ }) {
2475
+ const [expanded, setExpanded] = react.useState(false);
2476
+ if (message.deleted_at) {
2477
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-message__body poolse-row__body", children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-message__body--deleted", children: "Message deleted" }) });
2478
+ }
2479
+ const raw = message.body ?? "";
2480
+ if (!raw) {
2481
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-row__meta-only", children: meta });
2482
+ }
2483
+ const long = maxBodyLength > 0 && raw.length > maxBodyLength + TRIM_BUFFER;
2484
+ const shown = long && !expanded ? raw.slice(0, maxBodyLength).trimEnd() + "\u2026" : raw;
2485
+ const jumbo = !hasAttachments && !message.quoted_message_id ? emojiOnlyCount(raw) : 0;
2486
+ const md = markdown && jumbo === 0 && hasMarkdown(shown);
2487
+ return /* @__PURE__ */ jsxRuntime.jsxs(
2488
+ "div",
2489
+ {
2490
+ className: md ? "poolse-message__body poolse-message__body--md poolse-row__body" : "poolse-message__body poolse-row__body",
2491
+ children: [
2492
+ jumbo > 0 ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-message__body--jumbo", style: { fontSize: emojiFontSize(jumbo) }, children: shown }) : md ? /* @__PURE__ */ jsxRuntime.jsx(
2493
+ ReactMarkdown__default.default,
2494
+ {
2495
+ remarkPlugins: [remarkGfm__default.default],
2496
+ components: {
2497
+ a: ({ node: _node, ...props }) => /* @__PURE__ */ jsxRuntime.jsx("a", { ...props, target: "_blank", rel: "noopener noreferrer nofollow" })
2498
+ },
2499
+ children: shown
2500
+ }
2501
+ ) : /* @__PURE__ */ jsxRuntime.jsx("span", { children: shown }),
2502
+ long && /* @__PURE__ */ jsxRuntime.jsx(
2503
+ "button",
2504
+ {
2505
+ type: "button",
2506
+ className: "poolse-message__read-more",
2507
+ onClick: (e) => {
2508
+ e.stopPropagation();
2509
+ setExpanded((x) => !x);
2510
+ },
2511
+ children: expanded ? "Show less" : "Read more"
2512
+ }
2513
+ ),
2514
+ meta
2515
+ ]
2516
+ }
2517
+ );
2518
+ }
2109
2519
  function MessageRow(props) {
2110
2520
  const callLog = react$1.callLogDisplayFor(props.msg, props.meId);
2111
2521
  if (callLog !== void 0) {
@@ -2118,6 +2528,9 @@ function MessageRow(props) {
2118
2528
  }
2119
2529
  ) : null;
2120
2530
  }
2531
+ if (props.layout === "list" || props.layout === "compact") {
2532
+ return /* @__PURE__ */ jsxRuntime.jsx(FlatMessageRow, { ...props, layout: props.layout });
2533
+ }
2121
2534
  return /* @__PURE__ */ jsxRuntime.jsx(BubbleMessageRow, { ...props });
2122
2535
  }
2123
2536
  function BubbleMessageRow({
@@ -2142,12 +2555,22 @@ function BubbleMessageRow({
2142
2555
  maxBodyLength = 0,
2143
2556
  markdown = false,
2144
2557
  showSenderName = false,
2145
- showAvatar = false
2558
+ showAvatar = false,
2559
+ onSenderPress,
2560
+ onAvatarPress,
2561
+ timeFormat,
2562
+ slots
2146
2563
  }) {
2147
- const { profile: senderProfile } = react$1.useUser(msg.sender_id);
2148
- const senderFallbackName = msg.sender_id ? `User ${msg.sender_id.slice(0, 6)}` : "Unknown";
2564
+ const { profile: senderProfile } = react$1.useUser(msg.sender_external_id);
2565
+ const senderFallbackName = msg.sender_external_id ?? (msg.sender_id ? `User ${msg.sender_id.slice(0, 6)}` : "Unknown");
2149
2566
  const senderName = senderProfile?.displayName ?? senderFallbackName;
2150
2567
  const isSelf = meId !== null && msg.sender_id === meId;
2568
+ const sender = {
2569
+ userId: msg.sender_id,
2570
+ externalId: msg.sender_external_id,
2571
+ displayName: senderName,
2572
+ avatarUrl: senderProfile?.avatarUrl ?? null
2573
+ };
2151
2574
  const reactionsHook = react$1.useReactions(reactions ? msg.id : "", {
2152
2575
  conversationId: msg.conversation_id,
2153
2576
  initialReactions: msg.reactions,
@@ -2159,24 +2582,13 @@ function BubbleMessageRow({
2159
2582
  const showThreadPill = threads && !msg.deleted_at && !msg.thread_root_id && replyCount > 0;
2160
2583
  const handleSave = onSaveEdit ?? (async () => void 0);
2161
2584
  const handleCancel = onCancelEdit ?? (() => void 0);
2162
- const [actionsOpen, setActionsOpen] = react.useState(false);
2163
- const rowRef = react.useRef(null);
2164
- react.useEffect(() => {
2165
- if (!actionsOpen) return;
2166
- const onDown = (e) => {
2167
- const t = e.target;
2168
- if (t instanceof Node && rowRef.current && !rowRef.current.contains(t)) {
2169
- setActionsOpen(false);
2170
- }
2171
- };
2172
- document.addEventListener("pointerdown", onDown);
2173
- return () => document.removeEventListener("pointerdown", onDown);
2174
- }, [actionsOpen]);
2175
- const onRowClick = (e) => {
2176
- if (typeof window === "undefined" || !window.matchMedia("(hover: none)").matches) return;
2177
- const target = e.target;
2178
- if (target.closest("a, button, input, textarea, label, select")) return;
2179
- setActionsOpen((o) => !o);
2585
+ const { actionsOpen, setActionsOpen, rowRef, onRowClick } = useRowActions();
2586
+ const slotContext = {
2587
+ message: msg,
2588
+ isSelf,
2589
+ sender,
2590
+ layout: "bubbles",
2591
+ isRunStart: groupPosition === "first" || groupPosition === "standalone"
2180
2592
  };
2181
2593
  return /* @__PURE__ */ jsxRuntime.jsxs(
2182
2594
  "div",
@@ -2214,6 +2626,7 @@ function BubbleMessageRow({
2214
2626
  groupPosition,
2215
2627
  senderName,
2216
2628
  avatarUrl: senderProfile?.avatarUrl ?? null,
2629
+ ...onAvatarPress ? { onAvatarPress: () => onAvatarPress(sender) } : {},
2217
2630
  children: /* @__PURE__ */ jsxRuntime.jsx(
2218
2631
  MessageBubble,
2219
2632
  {
@@ -2223,10 +2636,13 @@ function BubbleMessageRow({
2223
2636
  maxBodyLength,
2224
2637
  markdown,
2225
2638
  showSenderName,
2639
+ ...onSenderPress ? { onSenderPress: () => onSenderPress(sender) } : {},
2226
2640
  showAttachments: attachments,
2227
2641
  ...readState ? { readState } : {},
2228
2642
  ...labelFor ? { labelFor } : {},
2229
2643
  ...onQuotedClick ? { onQuotedClick } : {},
2644
+ ...timeFormat ? { timeFormat } : {},
2645
+ ...slots ? { slots, slotContext } : {},
2230
2646
  ...showActions ? {
2231
2647
  actionsTrigger: /* @__PURE__ */ jsxRuntime.jsx(
2232
2648
  "button",
@@ -2247,103 +2663,95 @@ function BubbleMessageRow({
2247
2663
  )
2248
2664
  }
2249
2665
  ),
2250
- showReactions && /* @__PURE__ */ jsxRuntime.jsx("div", { className: `poolse-message-row__reactions ${isSelf ? "is-self" : ""}`, children: /* @__PURE__ */ jsxRuntime.jsx(
2251
- InlineReactions,
2252
- {
2253
- reactions: reactionsHook.reactions,
2254
- currentUserId: meId,
2255
- onAdd: (e) => void reactionsHook.addReaction(e),
2256
- onRemove: (e) => void reactionsHook.removeReaction(e)
2257
- }
2258
- ) }),
2259
- showThreadPill && /* @__PURE__ */ jsxRuntime.jsxs(
2260
- "button",
2261
- {
2262
- type: "button",
2263
- className: `poolse-thread-pill ${isSelf ? "poolse-thread-pill--right" : "poolse-thread-pill--left"}`,
2264
- onClick: onOpenThread,
2265
- "aria-label": `View ${replyCount} ${replyCount === 1 ? "reply" : "replies"}`,
2266
- children: [
2267
- /* @__PURE__ */ jsxRuntime.jsx(PoolseIcon, { name: "messages", size: 12, label: null }),
2268
- /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
2269
- replyCount,
2270
- " ",
2271
- replyCount === 1 ? "reply" : "replies"
2272
- ] })
2273
- ]
2274
- }
2666
+ renderSlot(
2667
+ slots?.reactions,
2668
+ slotContext,
2669
+ showReactions ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: `poolse-message-row__reactions ${isSelf ? "is-self" : ""}`, children: /* @__PURE__ */ jsxRuntime.jsx(
2670
+ InlineReactions,
2671
+ {
2672
+ reactions: reactionsHook.reactions,
2673
+ currentUserId: meId,
2674
+ onAdd: (e) => void reactionsHook.addReaction(e),
2675
+ onRemove: (e) => void reactionsHook.removeReaction(e)
2676
+ }
2677
+ ) }) : null
2275
2678
  ),
2276
- showActions && /* @__PURE__ */ jsxRuntime.jsx(
2277
- "div",
2278
- {
2279
- className: `poolse-message-row__actions ${isSelf ? "poolse-message-row__actions--right" : "poolse-message-row__actions--left"}`,
2280
- children: /* @__PURE__ */ jsxRuntime.jsx(
2281
- MessageActions,
2282
- {
2283
- ...reactions ? {
2284
- onReact: (emoji) => {
2285
- void reactionsHook.addReaction(emoji);
2286
- }
2287
- } : {},
2288
- ...threads && onOpenThread ? { onReply: onOpenThread } : {},
2289
- ...quotations && onQuote ? { onQuote } : {},
2290
- ...msg.body ? {
2291
- onCopy: () => {
2292
- void navigator?.clipboard?.writeText(msg.body ?? "").catch(() => void 0);
2293
- }
2294
- } : {},
2295
- ...isSelf && onStartEdit ? { onEdit: onStartEdit } : {},
2296
- ...isSelf && onDelete ? { onDelete } : {}
2297
- }
2298
- )
2299
- }
2679
+ renderSlot(
2680
+ slots?.thread,
2681
+ slotContext,
2682
+ showThreadPill ? /* @__PURE__ */ jsxRuntime.jsxs(
2683
+ "button",
2684
+ {
2685
+ type: "button",
2686
+ className: `poolse-thread-pill ${isSelf ? "poolse-thread-pill--right" : "poolse-thread-pill--left"}`,
2687
+ onClick: onOpenThread,
2688
+ "aria-label": `View ${replyCount} ${replyCount === 1 ? "reply" : "replies"}`,
2689
+ children: [
2690
+ /* @__PURE__ */ jsxRuntime.jsx(PoolseIcon, { name: "messages", size: 12, label: null }),
2691
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
2692
+ replyCount,
2693
+ " ",
2694
+ replyCount === 1 ? "reply" : "replies"
2695
+ ] })
2696
+ ]
2697
+ }
2698
+ ) : null
2699
+ ),
2700
+ renderSlot(
2701
+ slots?.actions,
2702
+ slotContext,
2703
+ showActions ? /* @__PURE__ */ jsxRuntime.jsx(
2704
+ "div",
2705
+ {
2706
+ className: `poolse-message-row__actions ${isSelf ? "poolse-message-row__actions--right" : "poolse-message-row__actions--left"}`,
2707
+ children: /* @__PURE__ */ jsxRuntime.jsx(
2708
+ MessageActions,
2709
+ {
2710
+ ...reactions ? {
2711
+ onReact: (emoji) => {
2712
+ void reactionsHook.addReaction(emoji);
2713
+ }
2714
+ } : {},
2715
+ ...threads && onOpenThread ? { onReply: onOpenThread } : {},
2716
+ ...quotations && onQuote ? { onQuote } : {},
2717
+ ...msg.body ? {
2718
+ onCopy: () => {
2719
+ void navigator?.clipboard?.writeText(msg.body ?? "").catch(() => void 0);
2720
+ }
2721
+ } : {},
2722
+ ...isSelf && onStartEdit ? { onEdit: onStartEdit } : {},
2723
+ ...isSelf && onDelete ? { onDelete } : {}
2724
+ }
2725
+ )
2726
+ }
2727
+ ) : null
2300
2728
  )
2301
2729
  ]
2302
2730
  }
2303
2731
  );
2304
2732
  }
2305
- function InlineReactions({
2306
- reactions,
2307
- currentUserId,
2308
- onAdd: _onAdd,
2309
- onRemove
2310
- }) {
2311
- const entries = Object.entries(reactions);
2312
- if (entries.length === 0) return null;
2313
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-reactions", children: entries.map(([emoji, users]) => {
2314
- const mine = currentUserId !== null && currentUserId !== void 0 && users.includes(currentUserId);
2315
- return /* @__PURE__ */ jsxRuntime.jsxs(
2316
- "button",
2317
- {
2318
- type: "button",
2319
- className: `poolse-reaction-pill${mine ? " poolse-reaction-pill--mine" : ""}`,
2320
- onClick: () => {
2321
- if (mine) onRemove(emoji);
2322
- else _onAdd(emoji);
2323
- },
2324
- "aria-pressed": mine,
2325
- "aria-label": `${emoji} reacted by ${users.length} ${users.length === 1 ? "user" : "users"}`,
2326
- children: [
2327
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: emoji }),
2328
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "poolse-reaction-pill__count", children: users.length })
2329
- ]
2330
- },
2331
- emoji
2332
- );
2333
- }) });
2334
- }
2335
2733
  function BubbleWithAvatar({
2336
2734
  isSelf,
2337
2735
  showAvatar,
2338
2736
  groupPosition,
2339
2737
  senderName,
2340
2738
  avatarUrl,
2739
+ onAvatarPress,
2341
2740
  children
2342
2741
  }) {
2343
2742
  if (isSelf || !showAvatar) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
2344
2743
  const isLastOfCluster = groupPosition === "last" || groupPosition === "standalone";
2345
2744
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-bubble-shell", children: [
2346
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-bubble-shell__avatar", children: isLastOfCluster ? /* @__PURE__ */ jsxRuntime.jsx(Avatar, { src: avatarUrl, name: senderName, size: "sm" }) : null }),
2745
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-bubble-shell__avatar", children: !isLastOfCluster ? null : onAvatarPress ? /* @__PURE__ */ jsxRuntime.jsx(
2746
+ "button",
2747
+ {
2748
+ type: "button",
2749
+ className: "poolse-bubble-shell__avatar-button",
2750
+ "aria-label": senderName,
2751
+ onClick: onAvatarPress,
2752
+ children: /* @__PURE__ */ jsxRuntime.jsx(Avatar, { src: avatarUrl, name: senderName, size: "sm" })
2753
+ }
2754
+ ) : /* @__PURE__ */ jsxRuntime.jsx(Avatar, { src: avatarUrl, name: senderName, size: "sm" }) }),
2347
2755
  children
2348
2756
  ] });
2349
2757
  }
@@ -2351,7 +2759,9 @@ function ThreadView({
2351
2759
  conversationId,
2352
2760
  rootMessage,
2353
2761
  onClose,
2354
- renderMessage
2762
+ renderMessage,
2763
+ layout,
2764
+ timeFormat
2355
2765
  }) {
2356
2766
  const { me } = react$1.useMe();
2357
2767
  const {
@@ -2434,7 +2844,9 @@ function ThreadView({
2434
2844
  await edit(msg.id, body);
2435
2845
  setEditingId(null);
2436
2846
  },
2437
- onDelete: () => void deleteReply(msg.id)
2847
+ onDelete: () => void deleteReply(msg.id),
2848
+ ...layout ? { layout } : {},
2849
+ ...timeFormat ? { timeFormat } : {}
2438
2850
  }
2439
2851
  );
2440
2852
  const renderOne = renderMessage ? (msg, currentUserId) => renderMessage(msg, currentUserId) : (msg) => renderDefault(msg);
@@ -2550,16 +2962,31 @@ function ConversationView({
2550
2962
  markdown = TRUE,
2551
2963
  maxBodyLength = 200,
2552
2964
  grouping = TRUE,
2553
- groupingWindowMs = 5 * 60 * 1e3,
2965
+ groupingWindowMs,
2966
+ groupWindowMinutes,
2967
+ layout = "bubbles",
2968
+ density = "comfortable",
2969
+ showAvatars,
2970
+ timeFormat,
2971
+ slots,
2554
2972
  daySeparators = TRUE,
2555
2973
  senderLabels = "auto",
2556
2974
  avatars = "auto",
2557
2975
  onMarkedRead,
2976
+ focusMessageId = null,
2977
+ onFocusMessageNotFound,
2978
+ onSenderPress,
2979
+ onAvatarPress,
2980
+ composer = TRUE,
2981
+ readOnly = false,
2558
2982
  onCallBack,
2559
2983
  onJoinCall,
2560
2984
  currentCallId = null
2561
2985
  }) {
2562
2986
  usePoolseFonts(loadFonts);
2987
+ const showComposer = composer && !readOnly;
2988
+ const canQuote = quotations && showComposer;
2989
+ const canDrop = attachments && showComposer;
2563
2990
  const { me } = react$1.useMe();
2564
2991
  const {
2565
2992
  messages,
@@ -2567,6 +2994,7 @@ function ConversationView({
2567
2994
  error,
2568
2995
  hasMore,
2569
2996
  loadMore,
2997
+ loadUntil,
2570
2998
  send,
2571
2999
  edit,
2572
3000
  delete: deleteMsg,
@@ -2588,7 +3016,13 @@ function ConversationView({
2588
3016
  const { members } = react$1.useMembers(membersOn ? conversationId : "");
2589
3017
  const isGroupChat = members.length > 2;
2590
3018
  const showSenderLabelsResolved = senderLabels === "always" || senderLabels === "auto" && isGroupChat;
2591
- const showAvatarsResolved = avatars === "always" || avatars === "auto" && isGroupChat;
3019
+ const showAvatarsResolved = showAvatars ?? (layout === "list" ? true : layout === "compact" ? false : avatars === "always" || avatars === "auto" && isGroupChat);
3020
+ const groupWindowMs = groupWindowMinutes !== void 0 ? groupWindowMinutes * 60 * 1e3 : groupingWindowMs ?? 5 * 60 * 1e3;
3021
+ const layoutProps = {
3022
+ layout,
3023
+ ...timeFormat ? { timeFormat } : {},
3024
+ ...slots ? { slots } : {}
3025
+ };
2592
3026
  const listRef = react.useRef(null);
2593
3027
  const lastMessageIdRef = react.useRef(null);
2594
3028
  const bottomSentinelRef = react.useRef(null);
@@ -2680,6 +3114,49 @@ function ConversationView({
2680
3114
  () => messages.filter((m) => react$1.isMessageVisibleTo(m, meIdForFeed)),
2681
3115
  [messages, meIdForFeed]
2682
3116
  );
3117
+ const [pendingFocusId, setPendingFocusId] = react.useState(null);
3118
+ const [focusMissing, setFocusMissing] = react.useState(false);
3119
+ const onFocusNotFoundRef = react.useRef(onFocusMessageNotFound);
3120
+ onFocusNotFoundRef.current = onFocusMessageNotFound;
3121
+ const conversationIdRef = react.useRef(conversationId);
3122
+ conversationIdRef.current = conversationId;
3123
+ const focusMiss = react.useCallback((id) => {
3124
+ setFocusMissing(true);
3125
+ onFocusNotFoundRef.current?.(id);
3126
+ }, []);
3127
+ react.useEffect(() => {
3128
+ setPendingFocusId(null);
3129
+ setFocusMissing(false);
3130
+ if (!focusMessageId || loading) return;
3131
+ const forConversation = conversationId;
3132
+ let current = true;
3133
+ loadUntil(focusMessageId).then((found) => {
3134
+ if (!current || conversationIdRef.current !== forConversation) return;
3135
+ if (found) setPendingFocusId(focusMessageId);
3136
+ else focusMiss(focusMessageId);
3137
+ }).catch(() => {
3138
+ if (current) focusMiss(focusMessageId);
3139
+ });
3140
+ return () => {
3141
+ current = false;
3142
+ };
3143
+ }, [focusMessageId, conversationId, loading, loadUntil, focusMiss]);
3144
+ react.useEffect(() => {
3145
+ if (!pendingFocusId) return;
3146
+ const root = listRef.current;
3147
+ const el = root?.querySelector(`[data-message-id="${pendingFocusId}"]`);
3148
+ setPendingFocusId(null);
3149
+ if (!(el instanceof HTMLElement)) {
3150
+ focusMiss(pendingFocusId);
3151
+ return;
3152
+ }
3153
+ highlightRow(el);
3154
+ }, [pendingFocusId, visibleMessages, focusMiss]);
3155
+ react.useEffect(() => {
3156
+ if (!focusMissing) return;
3157
+ const t = setTimeout(() => setFocusMissing(false), 4e3);
3158
+ return () => clearTimeout(t);
3159
+ }, [focusMissing]);
2683
3160
  const receiptsVisible = react$1.receiptsOf(me).visible;
2684
3161
  const showReadState = readReceipts && receiptsVisible;
2685
3162
  const maxReadByOthers = react.useMemo(() => {
@@ -2716,33 +3193,31 @@ function ConversationView({
2716
3193
  if (!root) return;
2717
3194
  const el = root.querySelector(`[data-message-id="${id}"]`);
2718
3195
  if (!(el instanceof HTMLElement)) return;
2719
- el.scrollIntoView({ behavior: "smooth", block: "center" });
2720
- el.classList.add("poolse-message-row--highlight");
2721
- setTimeout(() => el.classList.remove("poolse-message-row--highlight"), 1600);
3196
+ highlightRow(el);
2722
3197
  };
2723
3198
  const composerRef = react.useRef(null);
2724
3199
  const [dragActive, setDragActive] = react.useState(false);
2725
3200
  const dragDepthRef = react.useRef(0);
2726
3201
  const isFileDrag = (e) => Array.from(e.dataTransfer?.types ?? []).includes("Files");
2727
3202
  const onDragEnter = (e) => {
2728
- if (!attachments || !isFileDrag(e)) return;
3203
+ if (!canDrop || !isFileDrag(e)) return;
2729
3204
  e.preventDefault();
2730
3205
  dragDepthRef.current += 1;
2731
3206
  setDragActive(true);
2732
3207
  };
2733
3208
  const onDragOver = (e) => {
2734
- if (!attachments || !isFileDrag(e)) return;
3209
+ if (!canDrop || !isFileDrag(e)) return;
2735
3210
  e.preventDefault();
2736
3211
  if (e.dataTransfer) e.dataTransfer.dropEffect = "copy";
2737
3212
  };
2738
3213
  const onDragLeave = (e) => {
2739
- if (!attachments || !isFileDrag(e)) return;
3214
+ if (!canDrop || !isFileDrag(e)) return;
2740
3215
  e.preventDefault();
2741
3216
  dragDepthRef.current = Math.max(0, dragDepthRef.current - 1);
2742
3217
  if (dragDepthRef.current === 0) setDragActive(false);
2743
3218
  };
2744
3219
  const onDrop = (e) => {
2745
- if (!attachments || !isFileDrag(e)) return;
3220
+ if (!canDrop || !isFileDrag(e)) return;
2746
3221
  e.preventDefault();
2747
3222
  dragDepthRef.current = 0;
2748
3223
  setDragActive(false);
@@ -2770,7 +3245,7 @@ function ConversationView({
2770
3245
  onTyping: signalTyping,
2771
3246
  attachments,
2772
3247
  ...labelFor ? { labelFor } : {},
2773
- ...quotations ? { replyingTo, onCancelReply: () => setReplyingTo(null) } : {}
3248
+ ...canQuote ? { replyingTo, onCancelReply: () => setReplyingTo(null) } : {}
2774
3249
  }
2775
3250
  ) : /* @__PURE__ */ jsxRuntime.jsx(
2776
3251
  MessageComposer,
@@ -2780,14 +3255,19 @@ function ConversationView({
2780
3255
  onTyping: signalTyping,
2781
3256
  attachments,
2782
3257
  ...labelFor ? { labelFor } : {},
2783
- ...quotations ? { replyingTo, onCancelReply: () => setReplyingTo(null) } : {}
3258
+ ...canQuote ? { replyingTo, onCancelReply: () => setReplyingTo(null) } : {}
2784
3259
  }
2785
3260
  );
2786
3261
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-conversation-shell", children: [
2787
3262
  /* @__PURE__ */ jsxRuntime.jsxs(
2788
3263
  "div",
2789
3264
  {
2790
- className: `poolse-conversation${dragActive ? " is-drag-active" : ""}`,
3265
+ className: [
3266
+ "poolse-conversation",
3267
+ `poolse-conversation--layout-${layout}`,
3268
+ `poolse-conversation--density-${density}`,
3269
+ dragActive ? "is-drag-active" : ""
3270
+ ].filter(Boolean).join(" "),
2791
3271
  onDragEnter,
2792
3272
  onDragOver,
2793
3273
  onDragLeave,
@@ -2816,6 +3296,7 @@ function ConversationView({
2816
3296
  ]
2817
3297
  }
2818
3298
  ),
3299
+ focusMissing && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation__status", role: "status", "aria-live": "polite", children: "That message isn't available." }),
2819
3300
  /* @__PURE__ */ jsxRuntime.jsxs(
2820
3301
  "div",
2821
3302
  {
@@ -2828,12 +3309,9 @@ function ConversationView({
2828
3309
  children: [
2829
3310
  hasMore && /* @__PURE__ */ jsxRuntime.jsx("div", { ref: topSentinelRef, "aria-hidden": "true", style: { height: 1 } }),
2830
3311
  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." }) : visibleMessages.map((msg, idx) => {
2831
- if (renderMessage) {
2832
- return /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: renderMessage(msg, me?.id ?? null) }, msg.id);
2833
- }
2834
3312
  const prev = idx > 0 ? visibleMessages[idx - 1] ?? null : null;
2835
3313
  const next = idx < visibleMessages.length - 1 ? visibleMessages[idx + 1] ?? null : null;
2836
- const groupPosition = grouping ? react$1.computeGroupPosition(msg, prev, next, groupingWindowMs) : "standalone";
3314
+ const groupPosition = grouping ? react$1.computeGroupPosition(msg, prev, next, groupWindowMs) : "standalone";
2837
3315
  const showDaySeparator = daySeparators && (prev === null || !react$1.sameDay(msg.inserted_at, prev.inserted_at));
2838
3316
  const enriched = quotations && msg.quoted_message_id && !msg.quoted_message ? (() => {
2839
3317
  const original = messages.find((m) => m.id === msg.quoted_message_id);
@@ -2852,45 +3330,58 @@ function ConversationView({
2852
3330
  })() : msg;
2853
3331
  const isSelf = me !== null && msg.sender_id === me.id;
2854
3332
  const readState = showReadState && isSelf && maxReadByOthers !== null ? maxReadByOthers >= msg.sequence ? "read" : "sent" : void 0;
3333
+ const renderDefault = () => /* @__PURE__ */ jsxRuntime.jsx(
3334
+ MessageRow,
3335
+ {
3336
+ msg: enriched,
3337
+ meId: me?.id ?? null,
3338
+ reactions,
3339
+ attachments,
3340
+ actions,
3341
+ threads,
3342
+ quotations: canQuote,
3343
+ groupPosition,
3344
+ maxBodyLength,
3345
+ markdown,
3346
+ showSenderName: showSenderLabelsResolved,
3347
+ showAvatar: showAvatarsResolved,
3348
+ ...onSenderPress ? { onSenderPress } : {},
3349
+ ...onAvatarPress ? { onAvatarPress } : {},
3350
+ ...readState ? { readState } : {},
3351
+ ...labelFor ? { labelFor } : {},
3352
+ editing: editingId === msg.id,
3353
+ ...react$1.canEditOwnMessage({
3354
+ isSelf,
3355
+ deleted: !!msg.deleted_at,
3356
+ receiptsVisible,
3357
+ readState,
3358
+ insertedAt: msg.inserted_at
3359
+ }) ? { onStartEdit: () => setEditingId(msg.id) } : {},
3360
+ onCancelEdit: () => setEditingId(null),
3361
+ onSaveEdit: async (body) => {
3362
+ await edit(msg.id, body);
3363
+ setEditingId(null);
3364
+ },
3365
+ onDelete: () => void deleteMsg(msg.id),
3366
+ onOpenThread: () => setThreadRootId(msg.id),
3367
+ onQuote: () => setReplyingTo(msg),
3368
+ onQuotedClick: scrollToOriginal,
3369
+ ...onCallBack ? { onCallBack } : {},
3370
+ ...layoutProps,
3371
+ mentionsMe: mentionsViewer(msg, me?.id ?? null)
3372
+ }
3373
+ );
3374
+ if (renderMessage) {
3375
+ return /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: renderMessage(msg, me?.id ?? null, {
3376
+ layout,
3377
+ groupPosition,
3378
+ isRunStart: layout === "compact" || groupPosition === "first" || groupPosition === "standalone",
3379
+ renderDefault
3380
+ }) }, msg.id);
3381
+ }
2855
3382
  return /* @__PURE__ */ jsxRuntime.jsxs(react.Fragment, { children: [
2856
3383
  showDaySeparator && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-day-separator", "aria-hidden": "false", children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: react$1.formatDayLabel(msg.inserted_at) }) }),
2857
- /* @__PURE__ */ jsxRuntime.jsx(
2858
- MessageRow,
2859
- {
2860
- msg: enriched,
2861
- meId: me?.id ?? null,
2862
- reactions,
2863
- attachments,
2864
- actions,
2865
- threads,
2866
- quotations,
2867
- groupPosition,
2868
- maxBodyLength,
2869
- markdown,
2870
- showSenderName: showSenderLabelsResolved,
2871
- showAvatar: showAvatarsResolved,
2872
- ...readState ? { readState } : {},
2873
- ...labelFor ? { labelFor } : {},
2874
- editing: editingId === msg.id,
2875
- ...react$1.canEditOwnMessage({
2876
- isSelf,
2877
- deleted: !!msg.deleted_at,
2878
- receiptsVisible,
2879
- readState,
2880
- insertedAt: msg.inserted_at
2881
- }) ? { onStartEdit: () => setEditingId(msg.id) } : {},
2882
- onCancelEdit: () => setEditingId(null),
2883
- onSaveEdit: async (body) => {
2884
- await edit(msg.id, body);
2885
- setEditingId(null);
2886
- },
2887
- onDelete: () => void deleteMsg(msg.id),
2888
- onOpenThread: () => setThreadRootId(msg.id),
2889
- onQuote: () => setReplyingTo(msg),
2890
- onQuotedClick: scrollToOriginal,
2891
- ...onCallBack ? { onCallBack } : {}
2892
- }
2893
- )
3384
+ renderDefault()
2894
3385
  ] }, msg.id);
2895
3386
  }),
2896
3387
  visibleStreams.map(
@@ -2906,7 +3397,8 @@ function ConversationView({
2906
3397
  markdown,
2907
3398
  showSenderName: showSenderLabelsResolved,
2908
3399
  showAvatar: showAvatarsResolved,
2909
- ...labelFor ? { labelFor } : {}
3400
+ ...labelFor ? { labelFor } : {},
3401
+ ...layoutProps
2910
3402
  }
2911
3403
  ) }, stream.id)
2912
3404
  ),
@@ -2933,7 +3425,7 @@ function ConversationView({
2933
3425
  }
2934
3426
  ),
2935
3427
  /* @__PURE__ */ jsxRuntime.jsx(TypingIndicator, { typing, ...labelFor ? { labelFor } : {} }),
2936
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation__composer-row", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation__composer-flex", children: Composer }) }),
3428
+ showComposer && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation__composer-row", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation__composer-flex", children: Composer }) }),
2937
3429
  dragActive && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation__drop-overlay", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "poolse-conversation__drop-overlay-inner", children: [
2938
3430
  /* @__PURE__ */ jsxRuntime.jsx(PoolseIcon, { name: "attachment", size: 40, label: null }),
2939
3431
  /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation__drop-overlay-title", children: "Drop files to upload" }),
@@ -2947,11 +3439,20 @@ function ConversationView({
2947
3439
  {
2948
3440
  conversationId,
2949
3441
  rootMessage: threadRoot,
2950
- onClose: () => setThreadRootId(null)
3442
+ onClose: () => setThreadRootId(null),
3443
+ layout,
3444
+ ...timeFormat ? { timeFormat } : {}
2951
3445
  }
2952
3446
  ) })
2953
3447
  ] });
2954
3448
  }
3449
+ function highlightRow(el) {
3450
+ if (typeof el.scrollIntoView === "function") {
3451
+ el.scrollIntoView({ behavior: "smooth", block: "center" });
3452
+ }
3453
+ el.classList.add("poolse-message-row--highlight");
3454
+ setTimeout(() => el.classList.remove("poolse-message-row--highlight"), 1600);
3455
+ }
2955
3456
  function JoinBanner({
2956
3457
  conversationId,
2957
3458
  meId,
@@ -3849,6 +4350,61 @@ function useElapsed(startedAt, running) {
3849
4350
  const s = String(total % 60).padStart(2, "0");
3850
4351
  return h > 0 ? `${h}:${String(m).padStart(2, "0")}:${s}` : `${m}:${s}`;
3851
4352
  }
4353
+ var ThemeContext = react.createContext(null);
4354
+ var DARK_QUERY = "(prefers-color-scheme: dark)";
4355
+ function systemScheme() {
4356
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") return "light";
4357
+ return window.matchMedia(DARK_QUERY).matches ? "dark" : "light";
4358
+ }
4359
+ function useSystemColorScheme() {
4360
+ const [scheme, setScheme] = react.useState(systemScheme);
4361
+ react.useEffect(() => {
4362
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") return;
4363
+ const mql = window.matchMedia(DARK_QUERY);
4364
+ const onChange = () => setScheme(mql.matches ? "dark" : "light");
4365
+ onChange();
4366
+ if (typeof mql.addEventListener === "function") {
4367
+ mql.addEventListener("change", onChange);
4368
+ return () => mql.removeEventListener("change", onChange);
4369
+ }
4370
+ mql.addListener(onChange);
4371
+ return () => mql.removeListener(onChange);
4372
+ }, []);
4373
+ return scheme;
4374
+ }
4375
+ function PoolseTheme({
4376
+ theme: theme$1,
4377
+ colorScheme = "system",
4378
+ className,
4379
+ style,
4380
+ children
4381
+ }) {
4382
+ const system = useSystemColorScheme();
4383
+ const scheme = colorScheme === "system" ? system : colorScheme;
4384
+ const value = react.useMemo(
4385
+ () => ({ theme: theme$1 ? theme.resolveTheme(theme$1, scheme) : null, colorScheme: scheme }),
4386
+ [theme$1, scheme]
4387
+ );
4388
+ const vars = react.useMemo(
4389
+ () => value.theme ? theme.tokensToCssVariables(value.theme) : null,
4390
+ [value.theme]
4391
+ );
4392
+ return /* @__PURE__ */ jsxRuntime.jsx(ThemeContext.Provider, { value, children: /* @__PURE__ */ jsxRuntime.jsx(
4393
+ "div",
4394
+ {
4395
+ className: className ? `poolse-theme ${className}` : "poolse-theme",
4396
+ "data-theme": scheme,
4397
+ "data-poolse-theme": value.theme?.id,
4398
+ style: vars || style ? { ...vars, ...style } : void 0,
4399
+ children
4400
+ }
4401
+ ) });
4402
+ }
4403
+ function useTheme() {
4404
+ const value = react.useContext(ThemeContext);
4405
+ const system = useSystemColorScheme();
4406
+ return value ?? { theme: null, colorScheme: system };
4407
+ }
3852
4408
  var MARK_PATHS = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
3853
4409
  /* @__PURE__ */ jsxRuntime.jsx(
3854
4410
  "path",
@@ -3957,6 +4513,26 @@ function PoolseLogo({
3957
4513
  );
3958
4514
  }
3959
4515
 
4516
+ Object.defineProperty(exports, "BUILT_IN_THEME_IDS", {
4517
+ enumerable: true,
4518
+ get: function () { return theme.BUILT_IN_THEME_IDS; }
4519
+ });
4520
+ Object.defineProperty(exports, "DEFAULT_THEME_ID", {
4521
+ enumerable: true,
4522
+ get: function () { return theme.DEFAULT_THEME_ID; }
4523
+ });
4524
+ Object.defineProperty(exports, "createTheme", {
4525
+ enumerable: true,
4526
+ get: function () { return theme.createTheme; }
4527
+ });
4528
+ Object.defineProperty(exports, "decodeTheme", {
4529
+ enumerable: true,
4530
+ get: function () { return theme.decodeTheme; }
4531
+ });
4532
+ Object.defineProperty(exports, "encodeTheme", {
4533
+ enumerable: true,
4534
+ get: function () { return theme.encodeTheme; }
4535
+ });
3960
4536
  exports.AttachmentPreview = AttachmentPreview;
3961
4537
  exports.Avatar = Avatar;
3962
4538
  exports.CallControlButton = CallControlButton;
@@ -3978,6 +4554,7 @@ exports.PoolseFonts = PoolseFonts;
3978
4554
  exports.PoolseIcon = PoolseIcon;
3979
4555
  exports.PoolseInbox = PoolseInbox;
3980
4556
  exports.PoolseLogo = PoolseLogo;
4557
+ exports.PoolseTheme = PoolseTheme;
3981
4558
  exports.ReactionPicker = ReactionPicker;
3982
4559
  exports.ReactionStrip = ReactionStrip;
3983
4560
  exports.RoomJoinBar = RoomJoinBar;
@@ -3989,5 +4566,7 @@ exports.UserName = UserName;
3989
4566
  exports.UserPickerSheet = UserPickerSheet;
3990
4567
  exports.useDisplayName = useDisplayName;
3991
4568
  exports.usePoolseFonts = usePoolseFonts;
4569
+ exports.useSystemColorScheme = useSystemColorScheme;
4570
+ exports.useTheme = useTheme;
3992
4571
  //# sourceMappingURL=index.cjs.map
3993
4572
  //# sourceMappingURL=index.cjs.map