@ai-matrx/design-system 0.17.0 → 0.17.2

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