stream-chat 10.1.1 → 10.2.0

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.
@@ -215,6 +215,12 @@ export type PaginatorState<T> = {
215
215
  hasMoreHead: boolean;
216
216
  hasMoreTail: boolean;
217
217
  isLoading: boolean;
218
+ /**
219
+ * The direction of the running query while it loads a page at an edge of the loaded items
220
+ * (`toHead()`, `toTail()`). `undefined` while no query runs, and for a query that loads no such
221
+ * page: a first page, a refresh, or a page at a query shape the caller gives (a jump).
222
+ */
223
+ loadingDirection?: PaginationDirection;
218
224
  items: T[] | undefined;
219
225
  lastQueryError?: Error;
220
226
  cursor?: PaginatorCursor;
@@ -443,6 +449,8 @@ export declare abstract class BasePaginator<T, Q, R = PaginationQueryReturnValue
443
449
  get hasMoreHead(): boolean;
444
450
  get hasResults(): boolean;
445
451
  get isLoading(): boolean;
452
+ /** See {@link PaginatorState.loadingDirection}. */
453
+ get loadingDirection(): PaginationDirection | undefined;
446
454
  /**
447
455
  * True once a query has run or a non-empty interval was loaded without one (`setItems`, or a
448
456
  * subclass calling `recordLoadedIntervalQueryShape`). Cleared by `resetState`.
@@ -666,6 +666,12 @@ export declare class MessageIntervalPaginator extends BasePaginator<LocalMessage
666
666
  clearMessageFocusSignal: ({ token }?: {
667
667
  token?: number;
668
668
  }) => void;
669
+ /**
670
+ * Also drops the focus signal of an earlier jump. Whatever claims the active interval decides what
671
+ * is shown, so the earlier target must not be scrolled to or highlighted there. A jump claims
672
+ * before it emits its own signal, so it keeps that one.
673
+ */
674
+ protected claimActiveInterval(): number;
669
675
  clearStateAndCache(): void;
670
676
  /**
671
677
  * Partial truncation for `channel.truncated` with a `truncated_at`: drops every loaded message
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stream-chat",
3
- "version": "10.1.1",
3
+ "version": "10.2.0",
4
4
  "description": "JS SDK for the Stream Chat API",
5
5
  "homepage": "https://getstream.io/chat/",
6
6
  "author": {
@@ -280,6 +280,12 @@ export type PaginatorState<T> = {
280
280
  hasMoreHead: boolean;
281
281
  hasMoreTail: boolean;
282
282
  isLoading: boolean;
283
+ /**
284
+ * The direction of the running query while it loads a page at an edge of the loaded items
285
+ * (`toHead()`, `toTail()`). `undefined` while no query runs, and for a query that loads no such
286
+ * page: a first page, a refresh, or a page at a query shape the caller gives (a jump).
287
+ */
288
+ loadingDirection?: PaginationDirection;
283
289
  items: T[] | undefined;
284
290
  lastQueryError?: Error;
285
291
  cursor?: PaginatorCursor;
@@ -606,6 +612,12 @@ export abstract class BasePaginator<T, Q, R = PaginationQueryReturnValue<T>> {
606
612
  cursor: this.config.initialCursor,
607
613
  offset: this.config.initialOffset ?? 0,
608
614
  });
615
+ // A query has a loading direction only while it loads: every path that ends a query clears it.
616
+ this.state.addPreprocessor((next) => {
617
+ if (!next.isLoading && next.loadingDirection !== undefined) {
618
+ next.loadingDirection = undefined;
619
+ }
620
+ });
609
621
  // Called directly: `onChanged` fires on changes, not on the initial build.
610
622
  this.rebuildStatePublishThrottles(this.config.stateThrottleMs);
611
623
  this.intervalViews = new StateStore<PaginatorIntervalViews<T>>({
@@ -645,6 +657,11 @@ export abstract class BasePaginator<T, Q, R = PaginationQueryReturnValue<T>> {
645
657
  return this.state.getLatestValue().isLoading;
646
658
  }
647
659
 
660
+ /** See {@link PaginatorState.loadingDirection}. */
661
+ get loadingDirection() {
662
+ return this.state.getLatestValue().loadingDirection;
663
+ }
664
+
648
665
  /**
649
666
  * True once a query has run or a non-empty interval was loaded without one (`setItems`, or a
650
667
  * subclass calling `recordLoadedIntervalQueryShape`). Cleared by `resetState`.
@@ -678,6 +695,7 @@ export abstract class BasePaginator<T, Q, R = PaginationQueryReturnValue<T>> {
678
695
  hasMoreHead: true,
679
696
  hasMoreTail: true,
680
697
  isLoading: false,
698
+ loadingDirection: undefined,
681
699
  items: undefined,
682
700
  lastQueryError: undefined,
683
701
  cursor: this.config.initialCursor,
@@ -3180,8 +3198,13 @@ export abstract class BasePaginator<T, Q, R = PaginationQueryReturnValue<T>> {
3180
3198
  }
3181
3199
  } else if (!silent) {
3182
3200
  // A next page, or a refresh keeping the items: loading shows without blanking the list, and
3183
- // the page merges into the loaded intervals in `placeQueryPage`.
3184
- this.state.partialNext({ isLoading: true });
3201
+ // the page merges into the loaded intervals in `placeQueryPage`. Only a next page loads at an
3202
+ // edge of the loaded items; a page at the caller's shape has no known place.
3203
+ const loadsAtEdge = !isFirstPage && !forcedQueryShape;
3204
+ this.state.partialNext({
3205
+ isLoading: true,
3206
+ loadingDirection: loadsAtEdge ? direction : undefined,
3207
+ });
3185
3208
  }
3186
3209
 
3187
3210
  // a page at the caller's shape has no known place relative to the active interval
@@ -1862,6 +1862,16 @@ export class MessageIntervalPaginator extends BasePaginator<
1862
1862
  this.messageFocusSignal.next({ signal: null });
1863
1863
  };
1864
1864
 
1865
+ /**
1866
+ * Also drops the focus signal of an earlier jump. Whatever claims the active interval decides what
1867
+ * is shown, so the earlier target must not be scrolled to or highlighted there. A jump claims
1868
+ * before it emits its own signal, so it keeps that one.
1869
+ */
1870
+ protected override claimActiveInterval(): number {
1871
+ this.clearMessageFocusSignal();
1872
+ return super.claimActiveInterval();
1873
+ }
1874
+
1865
1875
  clearStateAndCache() {
1866
1876
  this.resetState();
1867
1877
  this._itemIndex.clear();