Skip to content

Commit 9bb7abb

Browse files
ThomasMetzgerSimonClo
authored andcommitted
🐛(frontend) embed-block: fixed drag-and-drop over iframe
1 parent 4dafc5b commit 9bb7abb

File tree

1 file changed

+45
-1
lines changed
  • src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-blocks

1 file changed

+45
-1
lines changed

src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-blocks/EmbedBlock.tsx

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
createReactBlockSpec,
1313
} from '@blocknote/react';
1414
import { TFunction } from 'i18next';
15-
import React, { useState } from 'react';
15+
import React, { useEffect, useRef, useState } from 'react';
1616
import { css } from 'styled-components';
1717

1818
import { Box, Icon } from '@/components';
@@ -53,15 +53,48 @@ export const IFrameViewer = (
5353
const aspectRatio = props.block.props.aspectRatio || 16 / 9;
5454

5555
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+
5686
if (!url) {
5787
return <Box>No URL provided for embed.</Box>;
5888
}
5989

6090
return !iframeError ? (
6191
<div
92+
ref={containerRef}
6293
style={{
6394
position: 'relative',
95+
padding: '10px',
6496
width: '100%',
97+
background: '#ff0000',
6598
paddingTop: `${100 / aspectRatio}%`, // padding-top sets height relative to width
6699
}}
67100
>
@@ -80,6 +113,17 @@ export const IFrameViewer = (
80113
title="Embedded content"
81114
onError={() => setIframeError(true)}
82115
/>
116+
{isResizing && (
117+
<div
118+
style={{
119+
position: 'absolute',
120+
inset: 0,
121+
backgroundColor: 'transparent',
122+
pointerEvents: 'all',
123+
zIndex: 10,
124+
}}
125+
/>
126+
)}
83127
</div>
84128
) : (
85129
<Box

0 commit comments

Comments
 (0)