@lightblues/jig 0.1.2 → 0.1.3
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/agent-chat/react.js +13 -2
- package/package.json +1 -1
package/dist/agent-chat/react.js
CHANGED
|
@@ -114,11 +114,16 @@ export function useStickToBottom(ref, deps, slack = 80) {
|
|
|
114
114
|
const lastTop = useRef(0);
|
|
115
115
|
const inputAt = useRef(-Infinity);
|
|
116
116
|
const [below, setBelow] = useState(false);
|
|
117
|
+
/**
|
|
118
|
+
* The scroller the listeners are on. A ref object never changes when its element mounts later (a panel that renders
|
|
119
|
+
* null while closed), so the layout effect re-resolves on every `deps` change and on mount, and attaching follows it.
|
|
120
|
+
*/
|
|
121
|
+
const [scroller, setScroller] = useState(null);
|
|
117
122
|
/** The reader moved up since we last looked: their input is recent, and the view is not at the end. */
|
|
118
123
|
const movedUp = (el) => el.scrollTop < lastTop.current - 1 && el.scrollHeight - el.scrollTop - el.clientHeight > 1 && now() - inputAt.current < INPUT_MS;
|
|
119
124
|
useEffect(() => {
|
|
120
125
|
const r = resolve(ref);
|
|
121
|
-
if (!r)
|
|
126
|
+
if (!r || r.el !== scroller)
|
|
122
127
|
return;
|
|
123
128
|
const { el, on } = r;
|
|
124
129
|
lastTop.current = el.scrollTop;
|
|
@@ -175,7 +180,13 @@ export function useStickToBottom(ref, deps, slack = 80) {
|
|
|
175
180
|
view.removeEventListener(t, input, { capture: true });
|
|
176
181
|
};
|
|
177
182
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
178
|
-
}, [ref, slack]);
|
|
183
|
+
}, [ref, slack, scroller]);
|
|
184
|
+
// Every render: the scroller may have mounted (or been replaced) since the last one, with `deps` unchanged.
|
|
185
|
+
useLayout(() => {
|
|
186
|
+
const el = resolve(ref)?.el ?? null;
|
|
187
|
+
if (el !== scroller)
|
|
188
|
+
setScroller(el);
|
|
189
|
+
});
|
|
179
190
|
useLayout(() => {
|
|
180
191
|
const r = resolve(ref);
|
|
181
192
|
if (!r)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightblues/jig",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Reusable parts for my apps: agent runtimes (Paseo, pi) that speak AG-UI, a thin thread-following client, one markdown renderer, and more as they prove reusable.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|