1
1
import React , { useEffect , useRef , useState } from 'react' ;
2
2
import styles from './EmbedAnything.module.css' ;
3
- import { registerVevComponent , useEditorState , useVisible } from '@vev/react' ;
3
+ import { registerVevComponent , useEditorState , useModel , useVisible } from '@vev/react' ;
4
4
5
5
type Props = {
6
6
html : string ;
@@ -43,8 +43,9 @@ function EmbedAnything({
43
43
) ;
44
44
}
45
45
46
- if ( isStatic ) return < StaticHTML html = { html } allowScroll = { allowScroll } /> ;
47
46
if ( encapsulate ) return < EmbedIframe html = { html } /> ;
47
+ if ( isStatic ) return < StaticHTML html = { html } allowScroll = { allowScroll } /> ;
48
+
48
49
return (
49
50
< EmbedScript
50
51
html = { html }
@@ -56,12 +57,13 @@ function EmbedAnything({
56
57
}
57
58
58
59
function EmbedIframe ( { html } : { html : string } ) {
60
+ const { key : messageFrom } = useModel ( ) || { key : 'none' } ;
59
61
const iframeRef = useRef ( null ) ;
60
62
const [ iframeHeight , setIframeHeight ] = useState ( 'auto' ) ;
61
63
62
64
useEffect ( ( ) => {
63
65
function handleIframeMessage ( event ) {
64
- if ( event . data . iframeHeight ) {
66
+ if ( event . data . iframeHeight && event . data . messageFrom === messageFrom ) {
65
67
setIframeHeight ( `${ event . data . iframeHeight } px` ) ;
66
68
}
67
69
}
@@ -99,7 +101,7 @@ function EmbedIframe({ html }: { html: string }) {
99
101
const height = document.body.scrollHeight;
100
102
if(prevHeight !== height){
101
103
prevHeight = height;
102
- window.parent.postMessage({ iframeHeight: height }, '*');
104
+ window.parent.postMessage({ iframeHeight: height, messageFrom: ' ${ messageFrom } ' }, '*');
103
105
}
104
106
}
105
107
@@ -221,6 +223,9 @@ registerVevComponent(EmbedAnything, {
221
223
type : 'boolean' ,
222
224
description : 'Static HTML (mounted directly)' ,
223
225
initialValue : false ,
226
+ hidden : ( context ) => {
227
+ return context . value . encapsulate ;
228
+ } ,
224
229
} ,
225
230
{
226
231
title : 'Allow inner scroll' ,
0 commit comments