@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.cjs CHANGED
@@ -1351,6 +1351,12 @@ function MessageRow({
1351
1351
  document.addEventListener("pointerdown", onDown);
1352
1352
  return () => document.removeEventListener("pointerdown", onDown);
1353
1353
  }, [actionsOpen]);
1354
+ const onRowClick = (e) => {
1355
+ if (typeof window === "undefined" || !window.matchMedia("(hover: none)").matches) return;
1356
+ const target = e.target;
1357
+ if (target.closest("a, button, input, textarea, label, select")) return;
1358
+ setActionsOpen((o) => !o);
1359
+ };
1354
1360
  return /* @__PURE__ */ jsxRuntime.jsxs(
1355
1361
  "div",
1356
1362
  {
@@ -1366,6 +1372,7 @@ function MessageRow({
1366
1372
  ].filter(Boolean).join(" "),
1367
1373
  "data-message-id": msg.id,
1368
1374
  "data-actions-open": actionsOpen || void 0,
1375
+ onClick: onRowClick,
1369
1376
  children: [
1370
1377
  editing ? /* @__PURE__ */ jsxRuntime.jsx(
1371
1378
  EditableMessageBubble,
@@ -1428,17 +1435,6 @@ function MessageRow({
1428
1435
  ]
1429
1436
  }
1430
1437
  ),
1431
- showActions && /* @__PURE__ */ jsxRuntime.jsx(
1432
- "button",
1433
- {
1434
- type: "button",
1435
- className: "poolse-message-row__more",
1436
- "aria-label": "Show message actions",
1437
- "aria-expanded": actionsOpen,
1438
- onClick: () => setActionsOpen((o) => !o),
1439
- children: /* @__PURE__ */ jsxRuntime.jsx(PoolseIcon, { name: "more-h", size: 16, label: null })
1440
- }
1441
- ),
1442
1438
  showActions && /* @__PURE__ */ jsxRuntime.jsx(
1443
1439
  "div",
1444
1440
  {
@@ -1734,8 +1730,32 @@ function ConversationView({
1734
1730
  const listRef = react.useRef(null);
1735
1731
  const lastMessageIdRef = react.useRef(null);
1736
1732
  const bottomSentinelRef = react.useRef(null);
1733
+ const topSentinelRef = react.useRef(null);
1734
+ const loadingMoreRef = react.useRef(false);
1737
1735
  const [atBottom, setAtBottom] = react.useState(true);
1738
1736
  const [newCountWhileAway, setNewCountWhileAway] = react.useState(0);
1737
+ react.useEffect(() => {
1738
+ const sentinel = topSentinelRef.current;
1739
+ const root = listRef.current;
1740
+ if (!sentinel || !root) return;
1741
+ if (!hasMore) return;
1742
+ const io = new IntersectionObserver(
1743
+ (entries) => {
1744
+ const entry = entries[0];
1745
+ if (!entry?.isIntersecting) return;
1746
+ if (loadingMoreRef.current) return;
1747
+ loadingMoreRef.current = true;
1748
+ void Promise.resolve(loadMore()).finally(() => {
1749
+ loadingMoreRef.current = false;
1750
+ });
1751
+ },
1752
+ // Fire when sentinel is within ~400px above the viewport — the
1753
+ // user is approaching the top of loaded history, fetch ahead.
1754
+ { root, rootMargin: "400px 0px 0px 0px", threshold: 0 }
1755
+ );
1756
+ io.observe(sentinel);
1757
+ return () => io.disconnect();
1758
+ }, [hasMore, loadMore]);
1739
1759
  react.useEffect(() => {
1740
1760
  const el = bottomSentinelRef.current;
1741
1761
  if (!el) return;
@@ -1938,7 +1958,7 @@ function ConversationView({
1938
1958
  "aria-live": "polite",
1939
1959
  "aria-relevant": "additions",
1940
1960
  children: [
1941
- hasMore && !loading && /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "poolse-conversation__load-more", onClick: loadMore, children: "Load older messages" }),
1961
+ hasMore && /* @__PURE__ */ jsxRuntime.jsx("div", { ref: topSentinelRef, "aria-hidden": "true", style: { height: 1 } }),
1942
1962
  loading && messages.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation__empty", children: "Loading\u2026" }) : messages.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "poolse-conversation__empty", children: emptyState ?? "No messages yet." }) : messages.map((msg, idx) => {
1943
1963
  if (renderMessage) {
1944
1964
  return /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: renderMessage(msg, me?.id ?? null) }, msg.id);