({
allowFullScreen,
allowPaymentRequest,
iframeStyle,
onLoad = NOOP,
referrerPolicy,
requestResize,
sandbox,
src,
srcdoc,
...rest
})
| 22 | * @return {PreactDef.Renderable} |
| 23 | */ |
| 24 | export function BentoIframe({ |
| 25 | allowFullScreen, |
| 26 | allowPaymentRequest, |
| 27 | iframeStyle, |
| 28 | onLoad = NOOP, |
| 29 | referrerPolicy, |
| 30 | requestResize, |
| 31 | sandbox, |
| 32 | src, |
| 33 | srcdoc, |
| 34 | ...rest |
| 35 | }) { |
| 36 | const iframeRef = useRef(); |
| 37 | const dataRef = useRef(null); |
| 38 | const isIntersectingRef = useRef(null); |
| 39 | const containerRef = useRef(null); |
| 40 | const observerRef = useRef(null); |
| 41 | const targetOriginRef = useRef(null); |
| 42 | |
| 43 | const viewabilityCb = (entries) => { |
| 44 | const iframe = iframeRef.current; |
| 45 | const targetOrigin = targetOriginRef.current; |
| 46 | if (!iframe || !targetOrigin) { |
| 47 | return; |
| 48 | } |
| 49 | postMessage( |
| 50 | iframe, |
| 51 | MessageType_Enum.INTERSECTION, |
| 52 | {'changes': entries.map(cloneEntryForCrossOrigin)}, |
| 53 | targetOrigin |
| 54 | ); |
| 55 | }; |
| 56 | |
| 57 | const handleSendIntersectionsPostMessage = useCallback((event) => { |
| 58 | const iframe = iframeRef.current; |
| 59 | if (!iframe) { |
| 60 | return; |
| 61 | } |
| 62 | if ( |
| 63 | event.source !== iframe.contentWindow || |
| 64 | event.data?.type !== MessageType_Enum.SEND_INTERSECTIONS |
| 65 | ) { |
| 66 | return; |
| 67 | } |
| 68 | targetOriginRef.current = event.origin; |
| 69 | const win = getWin(iframe); |
| 70 | observerRef.current = new win.IntersectionObserver(viewabilityCb, { |
| 71 | threshold: DEFAULT_THRESHOLD, |
| 72 | }); |
| 73 | observerRef.current.observe(iframe); |
| 74 | }, []); |
| 75 | |
| 76 | useEffect(() => { |
| 77 | const iframe = iframeRef.current; |
| 78 | if (!iframe) { |
| 79 | return; |
| 80 | } |
| 81 | const win = getWin(iframe); |
nothing calls this directly
no test coverage detected