UNPKG

@assistant-ui/react

Version:

Open-source TypeScript/React library for building production-grade AI chat experiences

35 lines (34 loc) • 1.17 kB
"use client"; import { useThreadViewportStore } from "../../../context/react/ThreadViewportContext.js"; import { useIsomorphicLayoutEffect } from "../../../utils/useIsomorphicLayoutEffect.js"; import { mountTopAnchorReserve } from "./mountTopAnchorReserve.js"; import { c } from "@assistant-ui/tap/react-shim/compiler-runtime"; // src/primitives/thread/topAnchor/useTopAnchorReserve.ts /** * Mounts the top-turn-anchor reserve element against the active * `ThreadViewport` store. Call this from inside the scrollable viewport so * the reserve `<div>` is appended next to the streaming assistant message. */ const useTopAnchorReserve = (enabled) => { const $ = c(4); const threadViewportStore = useThreadViewportStore(); let t0; let t1; if ($[0] !== enabled || $[1] !== threadViewportStore) { t0 = () => { if (!enabled) return; return mountTopAnchorReserve(threadViewportStore); }; t1 = [enabled, threadViewportStore]; $[0] = enabled; $[1] = threadViewportStore; $[2] = t0; $[3] = t1; } else { t0 = $[2]; t1 = $[3]; } useIsomorphicLayoutEffect(t0, t1); }; export { useTopAnchorReserve }; //# sourceMappingURL=useTopAnchorReserve.js.map