@ticketboothapp/booking 1.2.41 → 1.2.42

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ticketboothapp/booking",
3
- "version": "1.2.41",
3
+ "version": "1.2.42",
4
4
  "private": false,
5
5
  "sideEffects": [
6
6
  "**/*.css",
@@ -1408,7 +1408,6 @@ export function BookingFlow({
1408
1408
  // Detect when itinerary box becomes sticky
1409
1409
  // In viavia the scroll usually happens inside the dialog content div, not window.
1410
1410
  // On full-page partner layouts, we instead listen to window scroll (useWindowScroll = true).
1411
- const lastStickyChangeRef = useRef<number>(0);
1412
1411
  useEffect(() => {
1413
1412
  const el = itineraryRef.current;
1414
1413
  if (!el) return;
@@ -1423,56 +1422,32 @@ export function BookingFlow({
1423
1422
  return null;
1424
1423
  };
1425
1424
 
1426
- const scrollParent = findScrollParent(el);
1427
- const scrollTarget =
1428
- useWindowScroll || !scrollParent
1429
- ? (typeof window !== 'undefined' ? window : null)
1430
- : scrollParent;
1431
-
1432
- let ticking = false;
1433
- const COOLDOWN_MS = 600; // After a state change, ignore reverse changes for this long (covers 0.25s collapse animation + layout settle)
1434
- const atTopBand = 48; // px - must scroll back up past this band to expand again (wider = less oscillation at edges)
1425
+ const scrollParent = !useWindowScroll ? findScrollParent(el) : null;
1435
1426
 
1436
1427
  const updateStickyState = () => {
1437
1428
  if (!itineraryRef.current) return;
1438
1429
 
1439
1430
  const rect = itineraryRef.current.getBoundingClientRect();
1440
- const currentTop = rect.top;
1441
- const wasSticky = isItineraryStickyRef.current;
1442
-
1443
1431
  const containerTop =
1444
1432
  scrollParent && !useWindowScroll ? scrollParent.getBoundingClientRect().top : 0;
1445
1433
  const topInset = Math.max(0, flowUi?.itineraryStickyTopOffsetPx ?? 0);
1446
- const stickLine = containerTop + topInset;
1447
- const enterStickyThreshold = stickLine + 1;
1448
- const nextSticky = wasSticky
1449
- ? currentTop >= stickLine - atTopBand && currentTop <= stickLine + atTopBand
1450
- : currentTop <= enterStickyThreshold;
1451
-
1452
- if (nextSticky !== wasSticky) {
1453
- const now = Date.now();
1454
- if (now - lastStickyChangeRef.current < COOLDOWN_MS) return; // Cooldown: prevent rapid toggling
1455
-
1456
- lastStickyChangeRef.current = now;
1434
+ const nextSticky = rect.top <= containerTop + topInset + 1;
1435
+ if (nextSticky !== isItineraryStickyRef.current) {
1457
1436
  isItineraryStickyRef.current = nextSticky;
1458
1437
  setIsItinerarySticky(nextSticky);
1459
1438
  }
1460
1439
  };
1461
1440
 
1462
- const handleScroll = () => {
1463
- if (!ticking) {
1464
- window.requestAnimationFrame(() => {
1465
- updateStickyState();
1466
- ticking = false;
1467
- });
1468
- ticking = true;
1469
- }
1470
- };
1471
-
1472
- if (scrollTarget) {
1473
- scrollTarget.addEventListener('scroll', handleScroll, { passive: true });
1441
+ // Listen to both potential emitters; some embeds scroll window while the flow sits in a nested container.
1442
+ const targets: EventTarget[] = [];
1443
+ if (scrollParent) targets.push(scrollParent);
1444
+ if (typeof window !== 'undefined') targets.push(window);
1445
+ if (targets.length > 0) {
1446
+ targets.forEach((target) => target.addEventListener('scroll', updateStickyState, { passive: true }));
1474
1447
  updateStickyState();
1475
- return () => scrollTarget.removeEventListener('scroll', handleScroll);
1448
+ return () => {
1449
+ targets.forEach((target) => target.removeEventListener('scroll', updateStickyState));
1450
+ };
1476
1451
  }
1477
1452
  return undefined;
1478
1453
  }, [selectedDate, selectedAvailability, useWindowScroll, flowUi?.itineraryStickyTopOffsetPx]); // Re-check when itinerary / scroll mode / host chrome changes