@ai-matrx/design-system 0.17.0 → 0.17.1

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.
@@ -1167,6 +1167,7 @@ function useScrollPagination({
1167
1167
  const inFlightGenerationRef = useRef(null);
1168
1168
  const requestErrorRef = useRef(null);
1169
1169
  const mountedRef = useRef(false);
1170
+ const observedTopRef = useRef(/* @__PURE__ */ new WeakMap());
1170
1171
  const effectiveError = error ?? requestError;
1171
1172
  useEffect(() => {
1172
1173
  mountedRef.current = true;
@@ -1200,6 +1201,7 @@ function useScrollPagination({
1200
1201
  };
1201
1202
  useEffect(() => {
1202
1203
  intentRef.current = null;
1204
+ observedTopRef.current = /* @__PURE__ */ new WeakMap();
1203
1205
  consumedSequenceRef.current = inputSequenceRef.current;
1204
1206
  requestErrorRef.current = null;
1205
1207
  setRequestError(null);
@@ -1209,14 +1211,18 @@ function useScrollPagination({
1209
1211
  useEffect(() => {
1210
1212
  if (mode !== "scroll" || !enabled || typeof window === "undefined") return;
1211
1213
  const attachable = containers.map(resolveContainer).filter((container) => container !== null);
1212
- const setIntent = (container) => {
1214
+ const setIntent = (container, startTop) => {
1213
1215
  const current = latestRef.current;
1214
1216
  if (!isVisibleContainer(container) || current.loading || current.isFetchingNextPage || inFlightGenerationRef.current !== null) return;
1215
1217
  inputSequenceRef.current += 1;
1216
1218
  intentRef.current = {
1217
1219
  queryKey: latestRef.current.queryKey,
1218
1220
  container,
1219
- startTop: container.scrollTop,
1221
+ // The compositor can advance downward before the passive input
1222
+ // listener, while DOM/test callers can move upward before its scroll
1223
+ // notification. Either way, the lower position is the only safe
1224
+ // baseline for proving that this downward intent caused movement.
1225
+ startTop: Math.min(startTop, container.scrollTop),
1220
1226
  sequence: inputSequenceRef.current,
1221
1227
  expiresAt: Date.now() + intentTimeoutMs
1222
1228
  };
@@ -1231,9 +1237,11 @@ function useScrollPagination({
1231
1237
  void requestNextPage();
1232
1238
  };
1233
1239
  const cleanups = attachable.map((container) => {
1240
+ if (!observedTopRef.current.has(container)) observedTopRef.current.set(container, container.scrollTop);
1241
+ const lastObservedTop = () => observedTopRef.current.get(container) ?? container.scrollTop;
1234
1242
  const onWheel = (event) => {
1235
1243
  if (event.deltaY > 0 && Math.abs(event.deltaY) > Math.abs(event.deltaX)) {
1236
- setIntent(container);
1244
+ setIntent(container, lastObservedTop());
1237
1245
  }
1238
1246
  };
1239
1247
  const onTouchStart = (event) => {
@@ -1244,19 +1252,22 @@ function useScrollPagination({
1244
1252
  const touch = event.touches.item(0);
1245
1253
  const startY = Number(container.dataset.matrxPaginationTouchY);
1246
1254
  if (touch && Number.isFinite(startY) && startY - touch.clientY > 0) {
1247
- setIntent(container);
1255
+ setIntent(container, lastObservedTop());
1248
1256
  }
1249
1257
  };
1250
1258
  const onTouchEnd = () => {
1251
1259
  delete container.dataset.matrxPaginationTouchY;
1252
1260
  };
1253
1261
  const onKeyDown = (event) => {
1254
- if (isDownwardKeyboardInput(event)) setIntent(container);
1262
+ if (isDownwardKeyboardInput(event)) setIntent(container, lastObservedTop());
1255
1263
  };
1256
1264
  const onPointerDown = (event) => {
1257
- if (isNativeScrollbarPointer(event, container)) setIntent(container);
1265
+ if (isNativeScrollbarPointer(event, container)) setIntent(container, lastObservedTop());
1266
+ };
1267
+ const onScroll = () => {
1268
+ handleScroll(container);
1269
+ observedTopRef.current.set(container, container.scrollTop);
1258
1270
  };
1259
- const onScroll = () => handleScroll(container);
1260
1271
  container.addEventListener("wheel", onWheel, { passive: true });
1261
1272
  container.addEventListener("touchstart", onTouchStart, { passive: true });
1262
1273
  container.addEventListener("touchmove", onTouchMove, { passive: true });