MCPcopy Create free account
hub / github.com/ampproject/amphtml / BentoMathmlWithRef

Function BentoMathmlWithRef

extensions/amp-mathml/1.0/component.js:22–64  ·  view source on GitHub ↗

* @param {!BentoMathmlDef.Props} props * @param {{current: BentoMathmlDef.Api}} ref * @return {PreactDef.Renderable}

(props, ref)

Source from the content-addressed store, hash-verified

20 * @return {PreactDef.Renderable}
21 */
22function BentoMathmlWithRef(props, ref) {
23 const {
24 formula,
25 inline = false,
26 onLoad,
27 title = 'MathML formula',
28 ...rest
29 } = props;
30 const onLoadRef = useValueRef(onLoad);
31 const classes = useStyles();
32
33 const messageHandler = useCallback(
34 (e) => {
35 const data = tryParseJson(e.data) ?? deserializeMessage(e.data);
36 if (data['type'] == MessageType_Enum.EMBED_SIZE) {
37 onLoadRef.current?.();
38 }
39 },
40 [onLoadRef]
41 );
42
43 const iframeOptions = useMemo(() => ({formula}), [formula]);
44
45 if (!validProps(props)) {
46 return null;
47 }
48
49 return (
50 <ProxyIframeEmbed
51 class={objStr({
52 [classes.inline]: inline,
53 })}
54 allowFullscreen
55 ref={ref}
56 type={TYPE}
57 title={title}
58 options={iframeOptions}
59 matchesMessagingOrigin={ORIGIN_MATCHER}
60 messageHandler={messageHandler}
61 {...rest}
62 ></ProxyIframeEmbed>
63 );
64}
65
66const BentoMathml = forwardRef(BentoMathmlWithRef);
67BentoMathml.displayName = 'BentoMathml'; // Make findable for tests.

Callers

nothing calls this directly

Calls 6

useValueRefFunction · 0.90
useStylesFunction · 0.90
tryParseJsonFunction · 0.90
deserializeMessageFunction · 0.90
validPropsFunction · 0.85
currentMethod · 0.80

Tested by

no test coverage detected