* @param {!BentoMathmlDef.Props} props * @param {{current: BentoMathmlDef.Api}} ref * @return {PreactDef.Renderable}
(props, ref)
| 20 | * @return {PreactDef.Renderable} |
| 21 | */ |
| 22 | function 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 | |
| 66 | const BentoMathml = forwardRef(BentoMathmlWithRef); |
| 67 | BentoMathml.displayName = 'BentoMathml'; // Make findable for tests. |
nothing calls this directly
no test coverage detected