@ticketboothapp/booking 1.2.39 → 1.2.40

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.39",
3
+ "version": "1.2.40",
4
4
  "private": false,
5
5
  "sideEffects": [
6
6
  "**/*.css",
@@ -1444,53 +1444,65 @@ export function BookingFlow({
1444
1444
  : null;
1445
1445
  const scrollTarget = scrollParent ?? (typeof window !== 'undefined' ? window : null);
1446
1446
 
1447
- let ticking = false;
1448
1447
  const COOLDOWN_MS = 600; // After a state change, ignore reverse changes for this long (covers 0.25s collapse animation + layout settle)
1449
- const atTopBand = 48; // px - must scroll back up past this band to expand again (wider = less oscillation at edges)
1448
+ const setStickyState = (nextSticky: boolean) => {
1449
+ const wasSticky = isItineraryStickyRef.current;
1450
+ if (nextSticky === wasSticky) return;
1451
+ const now = Date.now();
1452
+ if (now - lastStickyChangeRef.current < COOLDOWN_MS) return;
1453
+ lastStickyChangeRef.current = now;
1454
+ isItineraryStickyRef.current = nextSticky;
1455
+ setIsItinerarySticky(nextSticky);
1456
+ };
1457
+
1458
+ const topInset = Math.max(0, flowUi?.itineraryStickyTopOffsetPx ?? 0);
1459
+
1460
+ // Primary path: IntersectionObserver sentinel is reliable across nested scroll containers.
1461
+ if (typeof window !== 'undefined' && 'IntersectionObserver' in window) {
1462
+ const sentinel = document.createElement('div');
1463
+ sentinel.setAttribute('data-itinerary-sticky-sentinel', 'true');
1464
+ sentinel.style.height = '1px';
1465
+ sentinel.style.margin = '0';
1466
+ sentinel.style.padding = '0';
1467
+ sentinel.style.pointerEvents = 'none';
1468
+ el.parentElement?.insertBefore(sentinel, el);
1469
+
1470
+ const observer = new IntersectionObserver(
1471
+ (entries) => {
1472
+ const entry = entries[0];
1473
+ // When sentinel leaves the visible root area (adjusted by top inset), itinerary is sticky.
1474
+ setStickyState(!entry.isIntersecting);
1475
+ },
1476
+ {
1477
+ root: scrollParent,
1478
+ rootMargin: `${-topInset}px 0px 0px 0px`,
1479
+ threshold: 0,
1480
+ },
1481
+ );
1482
+
1483
+ observer.observe(sentinel);
1484
+ return () => {
1485
+ observer.disconnect();
1486
+ sentinel.remove();
1487
+ };
1488
+ }
1450
1489
 
1490
+ // Fallback path for environments without IntersectionObserver.
1451
1491
  const updateStickyState = () => {
1452
1492
  if (!itineraryRef.current) return;
1453
-
1454
1493
  const rect = itineraryRef.current.getBoundingClientRect();
1455
- const currentTop = rect.top;
1456
- const wasSticky = isItineraryStickyRef.current;
1457
-
1458
1494
  const containerTop =
1459
1495
  scrollParent && !useWindowScroll ? scrollParent.getBoundingClientRect().top : 0;
1460
- const topInset = Math.max(0, flowUi?.itineraryStickyTopOffsetPx ?? 0);
1461
- const stickLine = containerTop + topInset;
1462
- const enterStickyThreshold = stickLine + 1;
1463
- const nextSticky = wasSticky
1464
- ? currentTop >= stickLine - atTopBand && currentTop <= stickLine + atTopBand
1465
- : currentTop <= enterStickyThreshold;
1466
-
1467
- if (nextSticky !== wasSticky) {
1468
- const now = Date.now();
1469
- if (now - lastStickyChangeRef.current < COOLDOWN_MS) return; // Cooldown: prevent rapid toggling
1470
-
1471
- lastStickyChangeRef.current = now;
1472
- isItineraryStickyRef.current = nextSticky;
1473
- setIsItinerarySticky(nextSticky);
1474
- }
1475
- };
1476
-
1477
- const handleScroll = () => {
1478
- if (!ticking) {
1479
- window.requestAnimationFrame(() => {
1480
- updateStickyState();
1481
- ticking = false;
1482
- });
1483
- ticking = true;
1484
- }
1496
+ setStickyState(rect.top <= containerTop + topInset + 1);
1485
1497
  };
1486
1498
 
1487
1499
  if (scrollTarget) {
1488
- scrollTarget.addEventListener('scroll', handleScroll, { passive: true });
1500
+ scrollTarget.addEventListener('scroll', updateStickyState, { passive: true });
1489
1501
  updateStickyState();
1490
- return () => scrollTarget.removeEventListener('scroll', handleScroll);
1502
+ return () => scrollTarget.removeEventListener('scroll', updateStickyState);
1491
1503
  }
1492
1504
  return undefined;
1493
- }, [selectedDate, selectedAvailability, useWindowScroll, flowUi?.itineraryStickyTopOffsetPx]); // Re-check when itinerary / scroll mode / host chrome changes
1505
+ }, [selectedDate, selectedAvailability, useWindowScroll, flowUi?.itineraryStickyTopOffsetPx, contentRef]); // Re-check when itinerary / scroll mode / host chrome changes
1494
1506
 
1495
1507
  // Find the earliest availability date - memoize with a stable reference
1496
1508
  // Only recalculate if we don't have a cached value or if the new earliest is actually earlier