@@ -12,7 +12,7 @@ import {
12
12
createReactBlockSpec ,
13
13
} from '@blocknote/react' ;
14
14
import { TFunction } from 'i18next' ;
15
- import React , { useState } from 'react' ;
15
+ import React , { useEffect , useRef , useState } from 'react' ;
16
16
import { css } from 'styled-components' ;
17
17
18
18
import { Box , Icon } from '@/components' ;
@@ -53,15 +53,48 @@ export const IFrameViewer = (
53
53
const aspectRatio = props . block . props . aspectRatio || 16 / 9 ;
54
54
55
55
const [ iframeError , setIframeError ] = useState ( false ) ;
56
+ const containerRef = useRef ( null ) ;
57
+ const [ isResizing , setIsResizing ] = useState ( false ) ;
58
+
59
+ useEffect ( ( ) => {
60
+ if ( ! containerRef . current ) {
61
+ return ;
62
+ }
63
+
64
+ const currentEl = containerRef . current as HTMLElement ;
65
+ const wrapperEl = currentEl . closest ( '.bn-file-block-content-wrapper' ) ;
66
+ if ( ! wrapperEl ) {
67
+ return ;
68
+ }
69
+
70
+ const startResizing = ( ) => {
71
+ setIsResizing ( true ) ;
72
+ } ;
73
+ const stopResizing = ( ) => {
74
+ setIsResizing ( false ) ;
75
+ } ;
76
+
77
+ wrapperEl . addEventListener ( 'pointerdown' , startResizing ) ;
78
+ document . addEventListener ( 'pointerup' , stopResizing ) ;
79
+
80
+ return ( ) => {
81
+ wrapperEl . removeEventListener ( 'pointerdown' , startResizing ) ;
82
+ document . removeEventListener ( 'pointerdown' , stopResizing ) ;
83
+ } ;
84
+ } , [ ] ) ;
85
+
56
86
if ( ! url ) {
57
87
return < Box > No URL provided for embed.</ Box > ;
58
88
}
59
89
60
90
return ! iframeError ? (
61
91
< div
92
+ ref = { containerRef }
62
93
style = { {
63
94
position : 'relative' ,
95
+ padding : '10px' ,
64
96
width : '100%' ,
97
+ background : '#ff0000' ,
65
98
paddingTop : `${ 100 / aspectRatio } %` , // padding-top sets height relative to width
66
99
} }
67
100
>
@@ -80,6 +113,17 @@ export const IFrameViewer = (
80
113
title = "Embedded content"
81
114
onError = { ( ) => setIframeError ( true ) }
82
115
/>
116
+ { isResizing && (
117
+ < div
118
+ style = { {
119
+ position : 'absolute' ,
120
+ inset : 0 ,
121
+ backgroundColor : 'transparent' ,
122
+ pointerEvents : 'all' ,
123
+ zIndex : 10 ,
124
+ } }
125
+ />
126
+ ) }
83
127
</ div >
84
128
) : (
85
129
< Box
0 commit comments