@vantageos/mosaic-blocks 0.5.18-alpha → 0.5.19-alpha

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
@@ -46,7 +46,7 @@ function _interopNamespace(e) {
46
46
  var React28__namespace = /*#__PURE__*/_interopNamespace(React28);
47
47
 
48
48
  // src/version.ts
49
- var version = "0.5.18-alpha";
49
+ var version = "0.5.19-alpha";
50
50
  function Placeholder({ label = "mosaic-blocks placeholder" }) {
51
51
  return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-mosaic-block": "placeholder", children: label });
52
52
  }
@@ -11483,7 +11483,8 @@ var chatThreadRootVariants = classVarianceAuthority.cva([
11483
11483
  "relative flex min-h-0 flex-1 flex-col overflow-y-auto"
11484
11484
  ]);
11485
11485
  var chatThreadContentVariants = classVarianceAuthority.cva([
11486
- "mx-auto flex w-full max-w-2xl flex-col gap-4 px-4 py-6 sm:px-6"
11486
+ "mx-auto flex w-full max-w-2xl flex-col gap-4 px-4 py-6 sm:px-6",
11487
+ "[&>*]:[content-visibility:auto] [&>*]:[contain-intrinsic-size:auto_4rem]"
11487
11488
  ]);
11488
11489
  var chatThreadScrollButtonVariants = classVarianceAuthority.cva([
11489
11490
  "absolute bottom-4 left-1/2 -translate-x-1/2 inline-flex size-9",
@@ -11497,6 +11498,7 @@ var BOTTOM_THRESHOLD_PX = 24;
11497
11498
  function isNearBottom(element) {
11498
11499
  return element.scrollHeight - element.scrollTop - element.clientHeight <= BOTTOM_THRESHOLD_PX;
11499
11500
  }
11501
+ var NAVIGATION_KEYS = /* @__PURE__ */ new Set(["ArrowUp", "ArrowDown", "PageUp", "PageDown", "Home", "End"]);
11500
11502
  function MosaicChatThread({
11501
11503
  children,
11502
11504
  scrollToBottomLabel,
@@ -11528,6 +11530,37 @@ function MosaicChatThread({
11528
11530
  isAtBottomRef.current = true;
11529
11531
  setIsAtBottom(true);
11530
11532
  }
11533
+ function disengageBottomAnchor() {
11534
+ isAtBottomRef.current = false;
11535
+ setIsAtBottom(false);
11536
+ }
11537
+ function handleKeyDown(event) {
11538
+ if (NAVIGATION_KEYS.has(event.key)) {
11539
+ disengageBottomAnchor();
11540
+ }
11541
+ }
11542
+ React28.useEffect(() => {
11543
+ function handleSelectionChange() {
11544
+ const container = containerRef.current;
11545
+ if (!container) {
11546
+ return;
11547
+ }
11548
+ const selection = document.getSelection();
11549
+ if (!selection || selection.isCollapsed || selection.rangeCount === 0) {
11550
+ return;
11551
+ }
11552
+ const { anchorNode, focusNode } = selection;
11553
+ const touchesThread = anchorNode !== null && container.contains(anchorNode) || focusNode !== null && container.contains(focusNode);
11554
+ if (touchesThread) {
11555
+ isAtBottomRef.current = false;
11556
+ setIsAtBottom(false);
11557
+ }
11558
+ }
11559
+ document.addEventListener("selectionchange", handleSelectionChange);
11560
+ return () => {
11561
+ document.removeEventListener("selectionchange", handleSelectionChange);
11562
+ };
11563
+ }, []);
11531
11564
  React28.useLayoutEffect(() => {
11532
11565
  const element = containerRef.current;
11533
11566
  if (element && isAtBottomRef.current) {
@@ -11541,6 +11574,7 @@ function MosaicChatThread({
11541
11574
  "data-slot": "chat-thread",
11542
11575
  role: "log",
11543
11576
  onScroll: handleScroll,
11577
+ onKeyDown: handleKeyDown,
11544
11578
  className: cn73(chatThreadRootVariants(), className),
11545
11579
  children: [
11546
11580
  /* @__PURE__ */ jsxRuntime.jsx("div", { "data-slot": "chat-thread-content", className: chatThreadContentVariants(), children }),