Files
chatkit/dist/react/hooks.d.ts
T
CatoandClaude b53f8e615a fix(thread): following never scrolls the page up, and --ck-follow-gap (#88)
On bitbaum /hire/ at 390x844 the contact box (a ChatThread, a receipt link
and the Composer) sits mid-page and the document owns the scroll. The
reader's first message pinned the end of the thread to the bottom of the
viewport, which scrolled the page UP by about 300px and pushed the composer
they were typing in below the fold.

What a consumer gets:
- When the document owns the scroll, following only moves the page down:
  with the end of the thread already on screen, nothing moves. A thread or
  panel that scrolls itself is unchanged, and the jump button still goes to
  the latest turn in either direction, because the reader asked.
- --ck-follow-gap (a length, default 0) on the thread's wrapper or any
  ancestor leaves that much room under the latest turn when the page
  follows, so a composer under the thread stays in view. The browser
  resolves it (rem, em, px, calc); unset, negative or invalid is 0.
- While the reader has sent nothing on a page, nothing moves, as before.

How it is checked: test/browser-scroll.mjs gains a mid-page fixture
(demo/scroll.html?owner=page&greeting&below) at 390 and 1280px. With the
composer mid-screen the first message does not scroll the page up and the
composer stays on screen; as the thread grows past the foot of the screen
the page follows and leaves the end at 0px, 10rem, 6em, 90px and (invalid)
0px above the bottom of the viewport, within 2px. Both checks fail on the
previous code; every existing scroll case passes unchanged.

Claude-Session: https://claude.ai/code/session_019MDtmsSWTTpVpe4wh3v1sb

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-12 10:30:35 +01:00

58 lines
3.0 KiB
TypeScript

import { type DependencyList, type RefObject } from "react";
/**
* Copy + a checkmark that resets. Failures are swallowed on purpose (insecure
* origin, denied permission): the text stays selectable, so a failed copy
* blocks nothing — `copied` simply never flips.
*/
export declare function useClipboard(resetMs?: number): {
copied: boolean;
copy: (text: string) => void;
};
/**
* Follow the thread until the reader scrolls up. The scroll owner may be the
* thread, a bounded ancestor, or the document (a conversation embedded in a
* case page). Never scroll other ancestors as a side effect of following.
* `grew` counts new user turns: an arriving assistant turn is not permission
* to take the reader away from an older answer.
*
* A greeting on a page is not a conversation yet. While the document owns the
* scroll and the reader has sent nothing (`grew` is 0), the thread neither
* moves the page nor offers a way back down: a contact box at the foot of a
* long page opened that page at the box, past everything above it (bitbaum
* /hire/ and /builders/, 2026-11-12). The first turn the reader sends starts
* the following.
*
* When the document owns the scroll, following only ever moves the page DOWN,
* to bring the end of the thread into view, plus `--ck-follow-gap` (a length
* on the thread's wrapper, default 0) so what the host puts under the thread
* stays in view too. The jump button may move either way: the reader asked.
*/
export declare function useStickToBottom(changes: DependencyList, grew: number): {
scrollRef: RefObject<HTMLDivElement | null>;
endRef: RefObject<HTMLDivElement | null>;
following: boolean;
pageScroll: boolean;
onScroll: () => void;
jumpToBottom: () => void;
};
/**
* Publishes the VISUAL viewport height as `--ck-viewport-height`.
*
* `100dvh` does not shrink when the Android soft keyboard opens; only
* `visualViewport` does. A chat column sized `100dvh` keeps its height while
* the keyboard covers the bottom of it, so the composer ends up behind the
* keyboard (orangecat `ViewportHeightSync`, #1094). Rounded down: sub-pixel
* heights leave a 1px seam under the composer on some devices.
*/
export declare function useViewportHeight(target?: RefObject<HTMLElement | null>, enabled?: boolean): void;
/** Grow a textarea to its content up to `max` px, keyed on the VALUE so a
* prefill, a dictated transcript or the clear after send resize it too.
*
* An EMPTY box is always one line. Chromium counts the placeholder in
* `scrollHeight`, so a box measured while it was narrow — mid-transition,
* inside a sheet still opening — read its wrapped placeholder as content and
* locked at `max` with nothing typed: half a phone screen of blank composer
* (Loki, 2026-10-09). And the box re-measures when its WIDTH changes, since a
* width measured once is wrong after the layout settles or the phone turns. */
export declare function useAutoGrow(ref: RefObject<HTMLTextAreaElement | null>, value: string, max?: number): void;
//# sourceMappingURL=hooks.d.ts.map