Skip to content

Commit 9d3bcf1

Browse files
authored
Merge pull request #222 from open-source-labs/denton/mouserelease
fix dragging of bottom panel over iframe
2 parents 059d78e + 976803d commit 9d3bcf1

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

CHANGE_LOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Changes:<br>
1414
- Typescript continued and now sits at ~80%
1515
- Dev Bug Fixes:
1616
- Additional logic added for edge cases in inputs for state manager (passing in non-Arrays/non-Objects as Array type and Object type).
17+
- Fixed issue with the bottom panel not dragging or sticking to the mouse when the mouse is over the demorender iframe
1718
- Cleaned up hundreds of lines of outdated code and archived multiple unused and duplicate files
1819
- User Features:
1920
- UI updated with a modern style for a better developer experience

app/src/components/bottom/BottomPanel.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import BottomTabs from './BottomTabs';
44
const BottomPanel = (props): JSX.Element => {
55
let y: number = 0;
66
let h: number = 0;
7-
87
const node = useRef() as React.MutableRefObject<HTMLDivElement>;
98

109
const mouseDownHandler = (e): void => {
@@ -13,12 +12,25 @@ const BottomPanel = (props): JSX.Element => {
1312
const styles = window.getComputedStyle(node.current);
1413
h = parseInt(styles.height, 10);
1514

15+
//Start listeners when the user clicks the bottom panel tab
1616
document.addEventListener('mousemove', mouseMoveHandler);
1717
document.addEventListener('mouseup', mouseUpHandler);
18+
window.addEventListener('message', handleIframeMessage);//listens for messages from the iframe when the mouse is over it
1819
};
20+
21+
//Interpret the messages from the iframe
22+
const handleIframeMessage = (e) => {
23+
if (e.data === 'iframeMouseUp') {
24+
mouseUpHandler();
25+
}else if(e.data.type === 'iframeMouseMove'){
26+
mouseMoveHandler(e.data)
27+
}
28+
}
29+
1930

2031
const mouseMoveHandler = function (e: MouseEvent): void {
2132
// How far the mouse has been moved
33+
2234
const dy = y - e.clientY;
2335

2436
// Adjust the dimension of element
@@ -32,6 +44,7 @@ const BottomPanel = (props): JSX.Element => {
3244
// Remove the handlers of `mousemove` and `mouseup`
3345
document.removeEventListener('mousemove', mouseMoveHandler);
3446
document.removeEventListener('mouseup', mouseUpHandler);
47+
window.removeEventListener('message', handleIframeMessage);
3548
};
3649

3750
useEffect(() => {

app/src/components/main/DemoRender.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,21 @@ const DemoRender = (): JSX.Element => {
5353
const handleClickInsideIframe = () => {
5454
window.parent.postMessage('iframeClicked', '*');
5555
};
56+
const handleMouseUpInsideIframe = () => {
57+
window.parent.postMessage('iframeMouseUp', '*');
58+
};
59+
const handleMouseMoveInsideIframe = (e) => {
60+
const msgData = {
61+
type: 'iframeMouseMove',
62+
clientY: e.clientY + 70 //change the 70 to the value of the height of the navbar
63+
}
64+
window.parent.postMessage(msgData, '*');
65+
};
5666
window.addEventListener('click', handleClickInsideIframe);
67+
window.addEventListener('mouseup', handleMouseUpInsideIframe);
68+
window.addEventListener('mousemove', handleMouseMoveInsideIframe);
69+
70+
5771
</script>
5872
</body>
5973
</html>

app/src/components/top/NavBarButtons.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ function navbarDropDown(props) {
311311

312312
return () => {
313313
window.removeEventListener('click', handleClick, true);
314-
window.addEventListener('message', handleClick); //cleanup for memory purposes. ensures handleclick isn't called after the component is no longer rendered
314+
window.removeEventListener('message', handleClick); //cleanup for memory purposes. ensures handleclick isn't called after the component is no longer rendered
315315
};
316316
}, [dropdownRef]);
317317

0 commit comments

Comments
 (0)