sceyt-chat-react-uikit 1.8.7-beta.14 → 1.8.7-beta.15

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/index.js CHANGED
@@ -44040,6 +44040,7 @@ function useChatController(_ref5) {
44040
44040
  var edgeRequestSequenceRef = React.useRef(0);
44041
44041
  var activeChannelIdRef = React.useRef(null);
44042
44042
  var lastScrollActivityAtRef = React.useRef(0);
44043
+ var lastMeasuredLatestEdgeRef = React.useRef(0);
44043
44044
  var jumpToLatestFrameRef = React.useRef(null);
44044
44045
  var loadPrevFrameRef = React.useRef(null);
44045
44046
  var loadNextFrameRef = React.useRef(null);
@@ -45015,7 +45016,11 @@ function useChatController(_ref5) {
45015
45016
  } else if (currentScrollTop >= latestEdgeScrollTop - PRELOAD_TRIGGER_PX) {
45016
45017
  currentScrollTop = latestEdgeScrollTop;
45017
45018
  }
45019
+ if (currentScrollTop !== container.scrollTop) {
45020
+ setScrollTop(container, currentScrollTop, 'auto');
45021
+ }
45018
45022
  var distanceFromLatest = latestEdgeScrollTop - currentScrollTop;
45023
+ lastMeasuredLatestEdgeRef.current = latestEdgeScrollTop;
45019
45024
  if (Date.now() < jumpLockUntilRef.current) {
45020
45025
  if (jumpLockModeRef.current === 'latest' && distanceFromLatest > PRELOAD_RESET_PX) {
45021
45026
  clearJumpScrollingLock();
@@ -45293,14 +45298,19 @@ function useChatController(_ref5) {
45293
45298
  }
45294
45299
  }
45295
45300
  React.useLayoutEffect(function () {
45296
- var _restoreRef$current9;
45301
+ var _lastBootKeyRef$curre, _restoreRef$current9;
45297
45302
  var container = scrollRef.current;
45298
45303
  if (!container || !messages.length) {
45299
45304
  return;
45300
45305
  }
45306
+ var rememberLatestEdge = function rememberLatestEdge() {
45307
+ lastMeasuredLatestEdgeRef.current = getLatestEdgeScrollTop(container);
45308
+ };
45309
+ var isChannelSwitch = activeChannelIdRef.current !== null && activeChannelIdRef.current !== channel.id;
45310
+ var hasCurrentBootKey = ((_lastBootKeyRef$curre = lastBootKeyRef.current) === null || _lastBootKeyRef$curre === void 0 ? void 0 : _lastBootKeyRef$curre.startsWith(channel.id + ":")) || false;
45301
45311
  if (((_restoreRef$current9 = restoreRef.current) === null || _restoreRef$current9 === void 0 ? void 0 : _restoreRef$current9.mode) === 'restore-scroll-top') {
45302
45312
  var savedScrollTop = restoreRef.current.scrollTop;
45303
- if (!lastBootKeyRef.current) {
45313
+ if (!hasCurrentBootKey) {
45304
45314
  lastBootKeyRef.current = channel.id + ":" + getMessageLocalRef(messages[0]);
45305
45315
  }
45306
45316
  restoreRef.current = null;
@@ -45308,19 +45318,27 @@ function useChatController(_ref5) {
45308
45318
  setIsViewingLatest(false);
45309
45319
  var maxScrollTop = getMaxScrollTop(container);
45310
45320
  setScrollTop(container, Math.min(savedScrollTop, maxScrollTop), 'auto');
45321
+ rememberLatestEdge();
45311
45322
  return;
45312
45323
  }
45313
- if (!lastBootKeyRef.current) {
45324
+ if (!hasCurrentBootKey) {
45314
45325
  lastBootKeyRef.current = channel.id + ":" + getMessageLocalRef(messages[0]);
45315
45326
  var preservePendingHistoryEdge = pendingEdgeCheckAfterLoadRef.current && activeEdgeIntentRef.current === 'previous';
45316
45327
  restoreRef.current = unreadScrollTo && unreadMessageId ? {
45317
45328
  mode: 'reveal-unread-separator'
45318
- } : preservePendingHistoryEdge ? null : isScrollInteractionActive() ? null : {
45329
+ } : preservePendingHistoryEdge ? null : isChannelSwitch ? {
45330
+ mode: 'to-bottom'
45331
+ } : isScrollInteractionActive() ? null : {
45319
45332
  mode: 'to-bottom'
45320
45333
  };
45321
45334
  }
45322
45335
  var restoreState = restoreRef.current;
45323
45336
  if (!restoreState) {
45337
+ var wasPinnedToPreviousLatestEdge = Math.abs(container.scrollTop - lastMeasuredLatestEdgeRef.current) <= PRELOAD_TRIGGER_PX;
45338
+ if ((viewIsAtLatestRef.current || wasPinnedToPreviousLatestEdge) && !hasNext) {
45339
+ scrollToLatestEdge(container, 'auto');
45340
+ }
45341
+ rememberLatestEdge();
45324
45342
  return;
45325
45343
  }
45326
45344
  if (restoreState.mode === 'reveal-message') {
@@ -45349,6 +45367,7 @@ function useChatController(_ref5) {
45349
45367
  jumpObserverRef.current = observer;
45350
45368
  observer.observe(target);
45351
45369
  }
45370
+ rememberLatestEdge();
45352
45371
  return;
45353
45372
  }
45354
45373
  if (restoreState.mode === 'reveal-unread-separator') {
@@ -45365,6 +45384,7 @@ function useChatController(_ref5) {
45365
45384
  } else {
45366
45385
  return;
45367
45386
  }
45387
+ rememberLatestEdge();
45368
45388
  return;
45369
45389
  }
45370
45390
  if (restoreState.mode === 'to-bottom') {
@@ -45372,6 +45392,7 @@ function useChatController(_ref5) {
45372
45392
  viewIsAtLatestRef.current = true;
45373
45393
  setIsViewingLatest(true);
45374
45394
  scrollToLatestEdge(container, 'auto');
45395
+ rememberLatestEdge();
45375
45396
  return;
45376
45397
  }
45377
45398
  if (restoreState.mode === 'to-bottom-smooth') {
@@ -45379,6 +45400,7 @@ function useChatController(_ref5) {
45379
45400
  viewIsAtLatestRef.current = true;
45380
45401
  setIsViewingLatest(true);
45381
45402
  scrollToLatestEdge(container, 'smooth');
45403
+ rememberLatestEdge();
45382
45404
  return;
45383
45405
  }
45384
45406
  if (restoreState.mode === 'preserve-anchor-window') {
@@ -45387,6 +45409,7 @@ function useChatController(_ref5) {
45387
45409
  viewIsAtLatestRef.current = true;
45388
45410
  setIsViewingLatest(true);
45389
45411
  scrollToLatestEdge(container, 'auto');
45412
+ rememberLatestEdge();
45390
45413
  return;
45391
45414
  }
45392
45415
  var anchorElement = getItemElement(container, restoreState.itemId);
@@ -45400,6 +45423,7 @@ function useChatController(_ref5) {
45400
45423
  if (offsetDelta !== 0) {
45401
45424
  setScrollTop(container, clampScrollTopToViewport(container, container.scrollTop + offsetDelta), 'auto');
45402
45425
  }
45426
+ rememberLatestEdge();
45403
45427
  return;
45404
45428
  }
45405
45429
  if (restoreState.mode === 'preserve-anchor') {
@@ -45433,8 +45457,9 @@ function useChatController(_ref5) {
45433
45457
  var nextScrollTop = clampScrollTopToViewport(container, container.scrollTop + _offsetDelta);
45434
45458
  setScrollTop(container, nextScrollTop, 'auto');
45435
45459
  }
45460
+ rememberLatestEdge();
45436
45461
  }
45437
- }, [channel.id, unreadMessageId, isActiveEdgeRequestCurrent, dispatch, messages, unreadScrollTo, clearJumpBlur, hasNextMessages, isScrollInteractionActive]);
45462
+ }, [channel.id, unreadMessageId, isActiveEdgeRequestCurrent, dispatch, messages, unreadScrollTo, clearJumpBlur, hasNext, isScrollInteractionActive]);
45438
45463
  React.useEffect(function () {
45439
45464
  if (!unreadScrollTo || !unreadMessageId || !messages.length || unreadRestoreCompletedRef.current) {
45440
45465
  return;
package/index.modern.js CHANGED
@@ -44039,6 +44039,7 @@ function useChatController(_ref5) {
44039
44039
  var edgeRequestSequenceRef = useRef(0);
44040
44040
  var activeChannelIdRef = useRef(null);
44041
44041
  var lastScrollActivityAtRef = useRef(0);
44042
+ var lastMeasuredLatestEdgeRef = useRef(0);
44042
44043
  var jumpToLatestFrameRef = useRef(null);
44043
44044
  var loadPrevFrameRef = useRef(null);
44044
44045
  var loadNextFrameRef = useRef(null);
@@ -45014,7 +45015,11 @@ function useChatController(_ref5) {
45014
45015
  } else if (currentScrollTop >= latestEdgeScrollTop - PRELOAD_TRIGGER_PX) {
45015
45016
  currentScrollTop = latestEdgeScrollTop;
45016
45017
  }
45018
+ if (currentScrollTop !== container.scrollTop) {
45019
+ setScrollTop(container, currentScrollTop, 'auto');
45020
+ }
45017
45021
  var distanceFromLatest = latestEdgeScrollTop - currentScrollTop;
45022
+ lastMeasuredLatestEdgeRef.current = latestEdgeScrollTop;
45018
45023
  if (Date.now() < jumpLockUntilRef.current) {
45019
45024
  if (jumpLockModeRef.current === 'latest' && distanceFromLatest > PRELOAD_RESET_PX) {
45020
45025
  clearJumpScrollingLock();
@@ -45292,14 +45297,19 @@ function useChatController(_ref5) {
45292
45297
  }
45293
45298
  }
45294
45299
  useLayoutEffect(function () {
45295
- var _restoreRef$current9;
45300
+ var _lastBootKeyRef$curre, _restoreRef$current9;
45296
45301
  var container = scrollRef.current;
45297
45302
  if (!container || !messages.length) {
45298
45303
  return;
45299
45304
  }
45305
+ var rememberLatestEdge = function rememberLatestEdge() {
45306
+ lastMeasuredLatestEdgeRef.current = getLatestEdgeScrollTop(container);
45307
+ };
45308
+ var isChannelSwitch = activeChannelIdRef.current !== null && activeChannelIdRef.current !== channel.id;
45309
+ var hasCurrentBootKey = ((_lastBootKeyRef$curre = lastBootKeyRef.current) === null || _lastBootKeyRef$curre === void 0 ? void 0 : _lastBootKeyRef$curre.startsWith(channel.id + ":")) || false;
45300
45310
  if (((_restoreRef$current9 = restoreRef.current) === null || _restoreRef$current9 === void 0 ? void 0 : _restoreRef$current9.mode) === 'restore-scroll-top') {
45301
45311
  var savedScrollTop = restoreRef.current.scrollTop;
45302
- if (!lastBootKeyRef.current) {
45312
+ if (!hasCurrentBootKey) {
45303
45313
  lastBootKeyRef.current = channel.id + ":" + getMessageLocalRef(messages[0]);
45304
45314
  }
45305
45315
  restoreRef.current = null;
@@ -45307,19 +45317,27 @@ function useChatController(_ref5) {
45307
45317
  setIsViewingLatest(false);
45308
45318
  var maxScrollTop = getMaxScrollTop(container);
45309
45319
  setScrollTop(container, Math.min(savedScrollTop, maxScrollTop), 'auto');
45320
+ rememberLatestEdge();
45310
45321
  return;
45311
45322
  }
45312
- if (!lastBootKeyRef.current) {
45323
+ if (!hasCurrentBootKey) {
45313
45324
  lastBootKeyRef.current = channel.id + ":" + getMessageLocalRef(messages[0]);
45314
45325
  var preservePendingHistoryEdge = pendingEdgeCheckAfterLoadRef.current && activeEdgeIntentRef.current === 'previous';
45315
45326
  restoreRef.current = unreadScrollTo && unreadMessageId ? {
45316
45327
  mode: 'reveal-unread-separator'
45317
- } : preservePendingHistoryEdge ? null : isScrollInteractionActive() ? null : {
45328
+ } : preservePendingHistoryEdge ? null : isChannelSwitch ? {
45329
+ mode: 'to-bottom'
45330
+ } : isScrollInteractionActive() ? null : {
45318
45331
  mode: 'to-bottom'
45319
45332
  };
45320
45333
  }
45321
45334
  var restoreState = restoreRef.current;
45322
45335
  if (!restoreState) {
45336
+ var wasPinnedToPreviousLatestEdge = Math.abs(container.scrollTop - lastMeasuredLatestEdgeRef.current) <= PRELOAD_TRIGGER_PX;
45337
+ if ((viewIsAtLatestRef.current || wasPinnedToPreviousLatestEdge) && !hasNext) {
45338
+ scrollToLatestEdge(container, 'auto');
45339
+ }
45340
+ rememberLatestEdge();
45323
45341
  return;
45324
45342
  }
45325
45343
  if (restoreState.mode === 'reveal-message') {
@@ -45348,6 +45366,7 @@ function useChatController(_ref5) {
45348
45366
  jumpObserverRef.current = observer;
45349
45367
  observer.observe(target);
45350
45368
  }
45369
+ rememberLatestEdge();
45351
45370
  return;
45352
45371
  }
45353
45372
  if (restoreState.mode === 'reveal-unread-separator') {
@@ -45364,6 +45383,7 @@ function useChatController(_ref5) {
45364
45383
  } else {
45365
45384
  return;
45366
45385
  }
45386
+ rememberLatestEdge();
45367
45387
  return;
45368
45388
  }
45369
45389
  if (restoreState.mode === 'to-bottom') {
@@ -45371,6 +45391,7 @@ function useChatController(_ref5) {
45371
45391
  viewIsAtLatestRef.current = true;
45372
45392
  setIsViewingLatest(true);
45373
45393
  scrollToLatestEdge(container, 'auto');
45394
+ rememberLatestEdge();
45374
45395
  return;
45375
45396
  }
45376
45397
  if (restoreState.mode === 'to-bottom-smooth') {
@@ -45378,6 +45399,7 @@ function useChatController(_ref5) {
45378
45399
  viewIsAtLatestRef.current = true;
45379
45400
  setIsViewingLatest(true);
45380
45401
  scrollToLatestEdge(container, 'smooth');
45402
+ rememberLatestEdge();
45381
45403
  return;
45382
45404
  }
45383
45405
  if (restoreState.mode === 'preserve-anchor-window') {
@@ -45386,6 +45408,7 @@ function useChatController(_ref5) {
45386
45408
  viewIsAtLatestRef.current = true;
45387
45409
  setIsViewingLatest(true);
45388
45410
  scrollToLatestEdge(container, 'auto');
45411
+ rememberLatestEdge();
45389
45412
  return;
45390
45413
  }
45391
45414
  var anchorElement = getItemElement(container, restoreState.itemId);
@@ -45399,6 +45422,7 @@ function useChatController(_ref5) {
45399
45422
  if (offsetDelta !== 0) {
45400
45423
  setScrollTop(container, clampScrollTopToViewport(container, container.scrollTop + offsetDelta), 'auto');
45401
45424
  }
45425
+ rememberLatestEdge();
45402
45426
  return;
45403
45427
  }
45404
45428
  if (restoreState.mode === 'preserve-anchor') {
@@ -45432,8 +45456,9 @@ function useChatController(_ref5) {
45432
45456
  var nextScrollTop = clampScrollTopToViewport(container, container.scrollTop + _offsetDelta);
45433
45457
  setScrollTop(container, nextScrollTop, 'auto');
45434
45458
  }
45459
+ rememberLatestEdge();
45435
45460
  }
45436
- }, [channel.id, unreadMessageId, isActiveEdgeRequestCurrent, dispatch, messages, unreadScrollTo, clearJumpBlur, hasNextMessages, isScrollInteractionActive]);
45461
+ }, [channel.id, unreadMessageId, isActiveEdgeRequestCurrent, dispatch, messages, unreadScrollTo, clearJumpBlur, hasNext, isScrollInteractionActive]);
45437
45462
  useEffect(function () {
45438
45463
  if (!unreadScrollTo || !unreadMessageId || !messages.length || unreadRestoreCompletedRef.current) {
45439
45464
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sceyt-chat-react-uikit",
3
- "version": "1.8.7-beta.14",
3
+ "version": "1.8.7-beta.15",
4
4
  "description": "Interactive React UI Components for Sceyt Chat.",
5
5
  "author": "Sceyt",
6
6
  "license": "MIT",