@ticketboothapp/booking 1.2.41 → 1.2.43
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
|
@@ -1405,77 +1405,51 @@ export function BookingFlow({
|
|
|
1405
1405
|
};
|
|
1406
1406
|
}, [showTooltip]);
|
|
1407
1407
|
|
|
1408
|
-
// Detect when itinerary box becomes sticky
|
|
1409
|
-
//
|
|
1410
|
-
//
|
|
1411
|
-
const lastStickyChangeRef = useRef<number>(0);
|
|
1408
|
+
// Detect when itinerary box becomes sticky.
|
|
1409
|
+
// Use a viewport IntersectionObserver sentinel so host-specific scroll containers
|
|
1410
|
+
// (dashboard embeds, dialog content, etc.) don't need custom scroll wiring.
|
|
1412
1411
|
useEffect(() => {
|
|
1413
1412
|
const el = itineraryRef.current;
|
|
1414
1413
|
if (!el) return;
|
|
1414
|
+
if (typeof window === 'undefined' || !('IntersectionObserver' in window)) return;
|
|
1415
|
+
|
|
1416
|
+
const topInset = Math.max(0, flowUi?.itineraryStickyTopOffsetPx ?? 0);
|
|
1417
|
+
const sentinel = document.createElement('div');
|
|
1418
|
+
sentinel.setAttribute('data-itinerary-sticky-sentinel', 'true');
|
|
1419
|
+
sentinel.style.height = '1px';
|
|
1420
|
+
sentinel.style.margin = '0';
|
|
1421
|
+
sentinel.style.padding = '0';
|
|
1422
|
+
sentinel.style.pointerEvents = 'none';
|
|
1423
|
+
el.parentElement?.insertBefore(sentinel, el);
|
|
1424
|
+
|
|
1425
|
+
const observer = new IntersectionObserver(
|
|
1426
|
+
([entry]) => {
|
|
1427
|
+
const nextSticky = !entry.isIntersecting;
|
|
1428
|
+
if (nextSticky !== isItineraryStickyRef.current) {
|
|
1429
|
+
isItineraryStickyRef.current = nextSticky;
|
|
1430
|
+
setIsItinerarySticky(nextSticky);
|
|
1431
|
+
}
|
|
1432
|
+
},
|
|
1433
|
+
{
|
|
1434
|
+
root: null,
|
|
1435
|
+
rootMargin: `${-topInset}px 0px 0px 0px`,
|
|
1436
|
+
threshold: 0,
|
|
1437
|
+
},
|
|
1438
|
+
);
|
|
1415
1439
|
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
if (overflowY === 'auto' || overflowY === 'scroll' || overflowY === 'overlay') return parent;
|
|
1421
|
-
parent = parent.parentElement;
|
|
1422
|
-
}
|
|
1423
|
-
return null;
|
|
1424
|
-
};
|
|
1425
|
-
|
|
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)
|
|
1435
|
-
|
|
1436
|
-
const updateStickyState = () => {
|
|
1437
|
-
if (!itineraryRef.current) return;
|
|
1438
|
-
|
|
1439
|
-
const rect = itineraryRef.current.getBoundingClientRect();
|
|
1440
|
-
const currentTop = rect.top;
|
|
1441
|
-
const wasSticky = isItineraryStickyRef.current;
|
|
1442
|
-
|
|
1443
|
-
const containerTop =
|
|
1444
|
-
scrollParent && !useWindowScroll ? scrollParent.getBoundingClientRect().top : 0;
|
|
1445
|
-
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;
|
|
1457
|
-
isItineraryStickyRef.current = nextSticky;
|
|
1458
|
-
setIsItinerarySticky(nextSticky);
|
|
1459
|
-
}
|
|
1460
|
-
};
|
|
1461
|
-
|
|
1462
|
-
const handleScroll = () => {
|
|
1463
|
-
if (!ticking) {
|
|
1464
|
-
window.requestAnimationFrame(() => {
|
|
1465
|
-
updateStickyState();
|
|
1466
|
-
ticking = false;
|
|
1467
|
-
});
|
|
1468
|
-
ticking = true;
|
|
1469
|
-
}
|
|
1440
|
+
observer.observe(sentinel);
|
|
1441
|
+
return () => {
|
|
1442
|
+
observer.disconnect();
|
|
1443
|
+
sentinel.remove();
|
|
1470
1444
|
};
|
|
1445
|
+
}, [selectedDate, selectedAvailability, flowUi?.itineraryStickyTopOffsetPx]); // Re-check when itinerary changes or host top inset changes
|
|
1471
1446
|
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
}, [selectedDate, selectedAvailability, useWindowScroll, flowUi?.itineraryStickyTopOffsetPx]); // Re-check when itinerary / scroll mode / host chrome changes
|
|
1447
|
+
// TEMP DEBUG: confirm sticky state transitions in host embeds.
|
|
1448
|
+
useEffect(() => {
|
|
1449
|
+
if (typeof window === 'undefined') return;
|
|
1450
|
+
// eslint-disable-next-line no-console
|
|
1451
|
+
console.log('[booking-flow] isItinerarySticky:', isItinerarySticky);
|
|
1452
|
+
}, [isItinerarySticky]);
|
|
1479
1453
|
|
|
1480
1454
|
// Find the earliest availability date - memoize with a stable reference
|
|
1481
1455
|
// Only recalculate if we don't have a cached value or if the new earliest is actually earlier
|