@ticketboothapp/booking 1.2.38 → 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
|
@@ -1423,67 +1423,85 @@ export function BookingFlow({
|
|
|
1423
1423
|
return null;
|
|
1424
1424
|
};
|
|
1425
1425
|
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
const
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
}
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1426
|
+
const detectedScrollParent = findScrollParent(el);
|
|
1427
|
+
const explicitScrollContainer = contentRef?.current ?? null;
|
|
1428
|
+
const isElementScrollable = (node: HTMLElement | null): node is HTMLElement => {
|
|
1429
|
+
if (!node) return false;
|
|
1430
|
+
const style = getComputedStyle(node);
|
|
1431
|
+
const allowsScroll = style.overflowY === 'auto' || style.overflowY === 'scroll' || style.overflowY === 'overlay';
|
|
1432
|
+
return allowsScroll && node.scrollHeight > node.clientHeight + 1;
|
|
1433
|
+
};
|
|
1434
|
+
|
|
1435
|
+
// Deterministic host-aware choice:
|
|
1436
|
+
// 1) explicit contentRef when it is truly scrollable
|
|
1437
|
+
// 2) nearest detected scroll parent when it is truly scrollable
|
|
1438
|
+
// 3) window scroll
|
|
1439
|
+
const scrollParent =
|
|
1440
|
+
!useWindowScroll && isElementScrollable(explicitScrollContainer)
|
|
1441
|
+
? explicitScrollContainer
|
|
1442
|
+
: !useWindowScroll && isElementScrollable(detectedScrollParent)
|
|
1443
|
+
? detectedScrollParent
|
|
1444
|
+
: null;
|
|
1445
|
+
const scrollTarget = scrollParent ?? (typeof window !== 'undefined' ? window : null);
|
|
1437
1446
|
|
|
1438
|
-
let ticking = false;
|
|
1439
1447
|
const COOLDOWN_MS = 600; // After a state change, ignore reverse changes for this long (covers 0.25s collapse animation + layout settle)
|
|
1440
|
-
const
|
|
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
|
+
}
|
|
1441
1489
|
|
|
1490
|
+
// Fallback path for environments without IntersectionObserver.
|
|
1442
1491
|
const updateStickyState = () => {
|
|
1443
1492
|
if (!itineraryRef.current) return;
|
|
1444
|
-
|
|
1445
1493
|
const rect = itineraryRef.current.getBoundingClientRect();
|
|
1446
|
-
const currentTop = rect.top;
|
|
1447
|
-
const wasSticky = isItineraryStickyRef.current;
|
|
1448
|
-
|
|
1449
1494
|
const containerTop =
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
const stickLine = containerTop + topInset;
|
|
1453
|
-
const enterStickyThreshold = stickLine + 1;
|
|
1454
|
-
const nextSticky = wasSticky
|
|
1455
|
-
? currentTop >= stickLine - atTopBand && currentTop <= stickLine + atTopBand
|
|
1456
|
-
: currentTop <= enterStickyThreshold;
|
|
1457
|
-
|
|
1458
|
-
if (nextSticky !== wasSticky) {
|
|
1459
|
-
const now = Date.now();
|
|
1460
|
-
if (now - lastStickyChangeRef.current < COOLDOWN_MS) return; // Cooldown: prevent rapid toggling
|
|
1461
|
-
|
|
1462
|
-
lastStickyChangeRef.current = now;
|
|
1463
|
-
isItineraryStickyRef.current = nextSticky;
|
|
1464
|
-
setIsItinerarySticky(nextSticky);
|
|
1465
|
-
}
|
|
1495
|
+
scrollParent && !useWindowScroll ? scrollParent.getBoundingClientRect().top : 0;
|
|
1496
|
+
setStickyState(rect.top <= containerTop + topInset + 1);
|
|
1466
1497
|
};
|
|
1467
1498
|
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
ticking = true;
|
|
1475
|
-
}
|
|
1476
|
-
};
|
|
1477
|
-
|
|
1478
|
-
scrollTargets.forEach((target) => {
|
|
1479
|
-
target.addEventListener('scroll', handleScroll, { passive: true });
|
|
1480
|
-
});
|
|
1481
|
-
updateStickyState();
|
|
1482
|
-
return () => {
|
|
1483
|
-
scrollTargets.forEach((target) => {
|
|
1484
|
-
target.removeEventListener('scroll', handleScroll);
|
|
1485
|
-
});
|
|
1486
|
-
};
|
|
1499
|
+
if (scrollTarget) {
|
|
1500
|
+
scrollTarget.addEventListener('scroll', updateStickyState, { passive: true });
|
|
1501
|
+
updateStickyState();
|
|
1502
|
+
return () => scrollTarget.removeEventListener('scroll', updateStickyState);
|
|
1503
|
+
}
|
|
1504
|
+
return undefined;
|
|
1487
1505
|
}, [selectedDate, selectedAvailability, useWindowScroll, flowUi?.itineraryStickyTopOffsetPx, contentRef]); // Re-check when itinerary / scroll mode / host chrome changes
|
|
1488
1506
|
|
|
1489
1507
|
// Find the earliest availability date - memoize with a stable reference
|