@@ -14,8 +14,7 @@ export function ElementWebframe(props: ContentKitClientElementProps<ContentKitWe
14
14
const renderer = useContentKitClientContext ( ) ;
15
15
const iframeRef = React . useRef < HTMLIFrameElement > ( null ) ;
16
16
const [ size , setSize ] = React . useState < {
17
- maxWidth ?: number ;
18
- maxHeight ?: number ;
17
+ height ?: number ;
19
18
aspectRatio ?: number ;
20
19
} > ( { } ) ;
21
20
@@ -88,9 +87,8 @@ export function ElementWebframe(props: ContentKitClientElementProps<ContentKitWe
88
87
const height = parsed . height ;
89
88
90
89
setSize ( {
91
- maxWidth : width ,
92
90
aspectRatio : width / height ,
93
- maxHeight : height ,
91
+ height : height ,
94
92
} ) ;
95
93
}
96
94
} catch ( _err ) {
@@ -108,11 +106,25 @@ export function ElementWebframe(props: ContentKitClientElementProps<ContentKitWe
108
106
messagesQueueRef . current = [ ] ;
109
107
break ;
110
108
case '@webframe.resize' :
111
- setSize ( {
112
- maxWidth : Number ( message . action . size . maxWidth ) ,
113
- maxHeight : Number ( message . action . size . maxHeight ) ,
114
- aspectRatio : Number ( message . action . size . aspectRatio ) ,
115
- } ) ;
109
+ setSize ( ( size ) => ( {
110
+ aspectRatio :
111
+ typeof message . action . size . aspectRatio !== 'undefined'
112
+ ? Number ( message . action . size . aspectRatio )
113
+ : size . aspectRatio ,
114
+
115
+ height : ( ( ) => {
116
+ if ( typeof message . action . size . height !== 'undefined' ) {
117
+ return Number ( message . action . size . height ) ;
118
+ }
119
+
120
+ // maxHeight was used prior to moving to height, maintain it for backward compatibility.
121
+ if ( typeof message . action . size . maxHeight !== 'undefined' ) {
122
+ return Number ( message . action . size . maxHeight ) ;
123
+ }
124
+
125
+ return size . height ;
126
+ } ) ( ) ,
127
+ } ) ) ;
116
128
break ;
117
129
default :
118
130
renderer . update ( {
@@ -149,33 +161,33 @@ export function ElementWebframe(props: ContentKitClientElementProps<ContentKitWe
149
161
return sendMessage ( { state } ) ;
150
162
} , [ element . data , renderer . state , sendMessage ] ) ;
151
163
164
+ if ( ! mounted ) {
165
+ return null ;
166
+ }
167
+
168
+ const aspectRatio = size . aspectRatio || element . aspectRatio ;
169
+
152
170
return (
153
- < div
154
- className = { 'contentkit-webframe' }
171
+ < iframe
172
+ ref = { iframeRef }
173
+ src = { element . source . url }
174
+ title = { element . source . url }
175
+ allowFullScreen
176
+ allow = "clipboard-write"
177
+ className = "contentkit-webframe"
155
178
style = { {
156
- aspectRatio : size . aspectRatio || element . aspectRatio || undefined ,
157
- maxWidth : size . maxWidth || undefined ,
158
- maxHeight : size . maxHeight || undefined ,
179
+ // If given an aspect ratio, use width as auto dimension and let height take precedence.
180
+ ...( aspectRatio
181
+ ? {
182
+ width : 'auto' ,
183
+ aspectRatio,
184
+ }
185
+ : { width : '100%' } ) ,
186
+
187
+ maxWidth : '100%' ,
188
+ height : Math . max ( size . height || 0 , 32 ) ,
189
+ border : 'none' ,
159
190
} }
160
- >
161
- { mounted ? (
162
- < iframe
163
- ref = { iframeRef }
164
- src = { element . source . url }
165
- allowFullScreen
166
- allow = "clipboard-write"
167
- style = { {
168
- position : 'absolute' ,
169
- top : 0 ,
170
- left : 0 ,
171
- bottom : 0 ,
172
- right : 0 ,
173
- width : '100%' ,
174
- height : '100%' ,
175
- border : 'none' ,
176
- } }
177
- />
178
- ) : null }
179
- </ div >
191
+ />
180
192
) ;
181
193
}
0 commit comments