@ticketboothapp/booking 1.2.40 → 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
|
@@ -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,86 +1422,35 @@ export function BookingFlow({
|
|
|
1423
1422
|
return null;
|
|
1424
1423
|
};
|
|
1425
1424
|
|
|
1426
|
-
const
|
|
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);
|
|
1446
|
-
|
|
1447
|
-
const COOLDOWN_MS = 600; // After a state change, ignore reverse changes for this long (covers 0.25s collapse animation + layout settle)
|
|
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
|
-
);
|
|
1425
|
+
const scrollParent = !useWindowScroll ? findScrollParent(el) : null;
|
|
1482
1426
|
|
|
1483
|
-
observer.observe(sentinel);
|
|
1484
|
-
return () => {
|
|
1485
|
-
observer.disconnect();
|
|
1486
|
-
sentinel.remove();
|
|
1487
|
-
};
|
|
1488
|
-
}
|
|
1489
|
-
|
|
1490
|
-
// Fallback path for environments without IntersectionObserver.
|
|
1491
1427
|
const updateStickyState = () => {
|
|
1492
1428
|
if (!itineraryRef.current) return;
|
|
1429
|
+
|
|
1493
1430
|
const rect = itineraryRef.current.getBoundingClientRect();
|
|
1494
1431
|
const containerTop =
|
|
1495
1432
|
scrollParent && !useWindowScroll ? scrollParent.getBoundingClientRect().top : 0;
|
|
1496
|
-
|
|
1433
|
+
const topInset = Math.max(0, flowUi?.itineraryStickyTopOffsetPx ?? 0);
|
|
1434
|
+
const nextSticky = rect.top <= containerTop + topInset + 1;
|
|
1435
|
+
if (nextSticky !== isItineraryStickyRef.current) {
|
|
1436
|
+
isItineraryStickyRef.current = nextSticky;
|
|
1437
|
+
setIsItinerarySticky(nextSticky);
|
|
1438
|
+
}
|
|
1497
1439
|
};
|
|
1498
1440
|
|
|
1499
|
-
|
|
1500
|
-
|
|
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 }));
|
|
1501
1447
|
updateStickyState();
|
|
1502
|
-
return () =>
|
|
1448
|
+
return () => {
|
|
1449
|
+
targets.forEach((target) => target.removeEventListener('scroll', updateStickyState));
|
|
1450
|
+
};
|
|
1503
1451
|
}
|
|
1504
1452
|
return undefined;
|
|
1505
|
-
}, [selectedDate, selectedAvailability, useWindowScroll, flowUi?.itineraryStickyTopOffsetPx
|
|
1453
|
+
}, [selectedDate, selectedAvailability, useWindowScroll, flowUi?.itineraryStickyTopOffsetPx]); // Re-check when itinerary / scroll mode / host chrome changes
|
|
1506
1454
|
|
|
1507
1455
|
// Find the earliest availability date - memoize with a stable reference
|
|
1508
1456
|
// Only recalculate if we don't have a cached value or if the new earliest is actually earlier
|
|
@@ -166,36 +166,8 @@ export function ItineraryBox({
|
|
|
166
166
|
const handlePickupLocationClick = () => {
|
|
167
167
|
const pickupSection = document.getElementById('pickup-location-section');
|
|
168
168
|
if (!pickupSection) return;
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
let parent = node.parentElement;
|
|
172
|
-
while (parent) {
|
|
173
|
-
const { overflowY } = getComputedStyle(parent);
|
|
174
|
-
if (overflowY === 'auto' || overflowY === 'scroll' || overflowY === 'overlay') return parent;
|
|
175
|
-
parent = parent.parentElement;
|
|
176
|
-
}
|
|
177
|
-
return null;
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
const scrollParent = useWindowScroll ? null : findScrollParent(pickupSection);
|
|
181
|
-
const itineraryBox = document.querySelector('[class*="sticky top-"]');
|
|
182
|
-
const itineraryHeight = itineraryBox?.getBoundingClientRect().height ?? 0;
|
|
183
|
-
// Extra offset so sticky header doesn't block the pickup section (mobile needs more clearance)
|
|
184
|
-
const STICKY_HEADER_CLEARANCE = isMobile ? 280 : 270;
|
|
185
|
-
const targetOffsetFromTop = itineraryHeight + 16 + STICKY_HEADER_CLEARANCE;
|
|
186
|
-
|
|
187
|
-
if (scrollParent) {
|
|
188
|
-
const elementPosition = pickupSection.getBoundingClientRect().top;
|
|
189
|
-
const scrollDelta = elementPosition - targetOffsetFromTop;
|
|
190
|
-
scrollParent.scrollTo({
|
|
191
|
-
top: Math.max(0, scrollParent.scrollTop + scrollDelta),
|
|
192
|
-
behavior: 'smooth',
|
|
193
|
-
});
|
|
194
|
-
} else if (typeof window !== 'undefined') {
|
|
195
|
-
const elementPosition = pickupSection.getBoundingClientRect().top + window.scrollY;
|
|
196
|
-
const scrollTop = Math.max(0, elementPosition - targetOffsetFromTop);
|
|
197
|
-
window.scrollTo({ top: scrollTop, behavior: 'smooth' });
|
|
198
|
-
}
|
|
169
|
+
// Let browser handle the active scroll container (window or nested dialog/content area).
|
|
170
|
+
pickupSection.scrollIntoView({ behavior: 'smooth', block: 'center', inline: 'nearest' });
|
|
199
171
|
};
|
|
200
172
|
|
|
201
173
|
const getDisplayLabel = (label: string): string => {
|