@poolse/react-ui 1.0.1 → 1.0.2

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.js CHANGED
@@ -1344,6 +1344,12 @@ function MessageRow({
1344
1344
  document.addEventListener("pointerdown", onDown);
1345
1345
  return () => document.removeEventListener("pointerdown", onDown);
1346
1346
  }, [actionsOpen]);
1347
+ const onRowClick = (e) => {
1348
+ if (typeof window === "undefined" || !window.matchMedia("(hover: none)").matches) return;
1349
+ const target = e.target;
1350
+ if (target.closest("a, button, input, textarea, label, select")) return;
1351
+ setActionsOpen((o) => !o);
1352
+ };
1347
1353
  return /* @__PURE__ */ jsxs(
1348
1354
  "div",
1349
1355
  {
@@ -1359,6 +1365,7 @@ function MessageRow({
1359
1365
  ].filter(Boolean).join(" "),
1360
1366
  "data-message-id": msg.id,
1361
1367
  "data-actions-open": actionsOpen || void 0,
1368
+ onClick: onRowClick,
1362
1369
  children: [
1363
1370
  editing ? /* @__PURE__ */ jsx(
1364
1371
  EditableMessageBubble,
@@ -1421,17 +1428,6 @@ function MessageRow({
1421
1428
  ]
1422
1429
  }
1423
1430
  ),
1424
- showActions && /* @__PURE__ */ jsx(
1425
- "button",
1426
- {
1427
- type: "button",
1428
- className: "poolse-message-row__more",
1429
- "aria-label": "Show message actions",
1430
- "aria-expanded": actionsOpen,
1431
- onClick: () => setActionsOpen((o) => !o),
1432
- children: /* @__PURE__ */ jsx(PoolseIcon, { name: "more-h", size: 16, label: null })
1433
- }
1434
- ),
1435
1431
  showActions && /* @__PURE__ */ jsx(
1436
1432
  "div",
1437
1433
  {
@@ -1727,8 +1723,32 @@ function ConversationView({
1727
1723
  const listRef = useRef(null);
1728
1724
  const lastMessageIdRef = useRef(null);
1729
1725
  const bottomSentinelRef = useRef(null);
1726
+ const topSentinelRef = useRef(null);
1727
+ const loadingMoreRef = useRef(false);
1730
1728
  const [atBottom, setAtBottom] = useState(true);
1731
1729
  const [newCountWhileAway, setNewCountWhileAway] = useState(0);
1730
+ useEffect(() => {
1731
+ const sentinel = topSentinelRef.current;
1732
+ const root = listRef.current;
1733
+ if (!sentinel || !root) return;
1734
+ if (!hasMore) return;
1735
+ const io = new IntersectionObserver(
1736
+ (entries) => {
1737
+ const entry = entries[0];
1738
+ if (!entry?.isIntersecting) return;
1739
+ if (loadingMoreRef.current) return;
1740
+ loadingMoreRef.current = true;
1741
+ void Promise.resolve(loadMore()).finally(() => {
1742
+ loadingMoreRef.current = false;
1743
+ });
1744
+ },
1745
+ // Fire when sentinel is within ~400px above the viewport — the
1746
+ // user is approaching the top of loaded history, fetch ahead.
1747
+ { root, rootMargin: "400px 0px 0px 0px", threshold: 0 }
1748
+ );
1749
+ io.observe(sentinel);
1750
+ return () => io.disconnect();
1751
+ }, [hasMore, loadMore]);
1732
1752
  useEffect(() => {
1733
1753
  const el = bottomSentinelRef.current;
1734
1754
  if (!el) return;
@@ -1931,7 +1951,7 @@ function ConversationView({
1931
1951
  "aria-live": "polite",
1932
1952
  "aria-relevant": "additions",
1933
1953
  children: [
1934
- hasMore && !loading && /* @__PURE__ */ jsx("button", { type: "button", className: "poolse-conversation__load-more", onClick: loadMore, children: "Load older messages" }),
1954
+ hasMore && /* @__PURE__ */ jsx("div", { ref: topSentinelRef, "aria-hidden": "true", style: { height: 1 } }),
1935
1955
  loading && messages.length === 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-conversation__empty", children: "Loading\u2026" }) : messages.length === 0 ? /* @__PURE__ */ jsx("div", { className: "poolse-conversation__empty", children: emptyState ?? "No messages yet." }) : messages.map((msg, idx) => {
1936
1956
  if (renderMessage) {
1937
1957
  return /* @__PURE__ */ jsx(Fragment$1, { children: renderMessage(msg, me?.id ?? null) }, msg.id);