(
{
allow,
allowFullScreen,
iframeStyle,
loading: loadingProp,
matchesMessagingOrigin = DEFAULT_MATCHES_MESSAGING_ORIGIN,
messageHandler,
name,
onReadyState,
ready = true,
sandbox,
src,
title,
...rest
},
ref
)
| 32 | * @return {import('preact').VNode} |
| 33 | */ |
| 34 | export function IframeEmbedWithRef( |
| 35 | { |
| 36 | allow, |
| 37 | allowFullScreen, |
| 38 | iframeStyle, |
| 39 | loading: loadingProp, |
| 40 | matchesMessagingOrigin = DEFAULT_MATCHES_MESSAGING_ORIGIN, |
| 41 | messageHandler, |
| 42 | name, |
| 43 | onReadyState, |
| 44 | ready = true, |
| 45 | sandbox, |
| 46 | src, |
| 47 | title, |
| 48 | ...rest |
| 49 | }, |
| 50 | ref |
| 51 | ) { |
| 52 | const {playable} = useAmpContext(); |
| 53 | const loading = useLoading(loadingProp); |
| 54 | const mount = loading !== Loading_Enum.UNLOAD; |
| 55 | |
| 56 | const loadedRef = useRef(false); |
| 57 | // The `onReadyStateRef` is passed via a ref to avoid the changed values |
| 58 | // of `onReadyState` re-triggering the side effects. |
| 59 | const onReadyStateRef = useValueRef(onReadyState); |
| 60 | const setLoaded = useCallback( |
| 61 | /** @param {boolean} value */ |
| 62 | (value) => { |
| 63 | if (value !== loadedRef.current) { |
| 64 | loadedRef.current = value; |
| 65 | const onReadyState = onReadyStateRef.current; |
| 66 | onReadyState?.( |
| 67 | value ? ReadyState_Enum.COMPLETE : ReadyState_Enum.LOADING |
| 68 | ); |
| 69 | } |
| 70 | }, |
| 71 | [onReadyStateRef] |
| 72 | ); |
| 73 | |
| 74 | /** @type {import('preact/hooks').MutableRef<HTMLIFrameElement?>} */ |
| 75 | const iframeRef = useRef(null); |
| 76 | |
| 77 | // Component API: IframeEmbedDef.Api. |
| 78 | useImperativeHandle( |
| 79 | ref, |
| 80 | () => ({ |
| 81 | // Standard Bento |
| 82 | get readyState() { |
| 83 | return loadedRef.current |
| 84 | ? ReadyState_Enum.COMPLETE |
| 85 | : ReadyState_Enum.LOADING; |
| 86 | }, |
| 87 | get node() { |
| 88 | return iframeRef.current; |
| 89 | }, |
| 90 | }), |
| 91 | [] |
nothing calls this directly
no test coverage detected