Skip to content

Commit 0191304

Browse files
authored
fix: allow scrolling over embeddables (#37)
* fix: allow scrolling over embeddables - Added CSS variable for pointer-events to manage interaction during scrolling. - Introduced lockEmbeddables function to disable pointer-events while scrolling and reset after scrolling ends using a debounced function. - Updated ExcalidrawWrapper to integrate scrolling behavior with embeddables. * fix: simplify lockEmbeddables function signature
1 parent ca6a00f commit 0191304

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/frontend/index.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
font-display: swap;
88
}
99

10+
/* CSS Variables */
11+
:root {
12+
--embeddable-pointer-events: all;
13+
}
14+
1015
/* Override Excalidraw styles */
1116

1217
body {
@@ -77,6 +82,6 @@ body {
7782

7883
.excalidraw__embeddable__outer { /* 3rd layer */
7984
padding: 0px !important;
80-
pointer-events: all !important;
85+
pointer-events: var(--embeddable-pointer-events, all) !important;
8186
display: flex;
8287
}

src/frontend/src/CustomEmbeddableRenderer.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import { debounce } from './utils/debounce';
23
import type { NonDeleted, ExcalidrawEmbeddableElement } from '@atyrode/excalidraw/element/types';
34
import type { AppState } from '@atyrode/excalidraw/types';
45
import {
@@ -85,3 +86,24 @@ export const renderCustomEmbeddable = (
8586
);
8687
}
8788
};
89+
90+
// Track scrolling state
91+
let isScrolling = false;
92+
93+
export const lockEmbeddables = () => {
94+
if (!isScrolling) {
95+
isScrolling = true;
96+
// Set pointer-events to none during scrolling
97+
document.documentElement.style.setProperty('--embeddable-pointer-events', 'none');
98+
}
99+
100+
// Reset the pointer-events after scrolling stops
101+
debouncedScrollEnd();
102+
};
103+
104+
// Create a debounced function to detect when scrolling ends
105+
const debouncedScrollEnd = debounce(() => {
106+
isScrolling = false;
107+
// Set pointer-events back to all when not scrolling
108+
document.documentElement.style.setProperty('--embeddable-pointer-events', 'all');
109+
}, 150); // 150ms debounce seems reasonable, but can be adjusted as needed

src/frontend/src/ExcalidrawWrapper.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { ExcalidrawImperativeAPI } from '@atyrode/excalidraw/types';
55
import type { NonDeletedExcalidrawElement } from '@atyrode/excalidraw/element/types';
66
import type { AppState } from '@atyrode/excalidraw/types';
77
import { MainMenuConfig } from './ui/MainMenu';
8-
import { renderCustomEmbeddable } from './CustomEmbeddableRenderer';
8+
import { lockEmbeddables, renderCustomEmbeddable } from './CustomEmbeddableRenderer';
99
import AuthDialog from './ui/AuthDialog';
1010
import BackupsModal from './ui/BackupsDialog';
1111

@@ -25,6 +25,7 @@ interface ExcalidrawWrapperProps {
2525
setExcalidrawAPI: (api: ExcalidrawImperativeAPI) => void;
2626
initialData?: any;
2727
onChange: (elements: NonDeletedExcalidrawElement[], state: AppState) => void;
28+
onScrollChange: (scrollX: number, scrollY: number) => void;
2829
MainMenu: any;
2930
renderTopRightUI?: () => React.ReactNode;
3031
isAuthenticated?: boolean | null;
@@ -37,6 +38,7 @@ export const ExcalidrawWrapper: React.FC<ExcalidrawWrapperProps> = ({
3738
setExcalidrawAPI,
3839
initialData,
3940
onChange,
41+
onScrollChange,
4042
MainMenu,
4143
renderTopRightUI,
4244
isAuthenticated = null,
@@ -80,6 +82,7 @@ export const ExcalidrawWrapper: React.FC<ExcalidrawWrapperProps> = ({
8082
initialData: initialData ?? defaultInitialData,
8183
onChange: onChange,
8284
name: "Pad.ws",
85+
onScrollChange: lockEmbeddables,
8386
validateEmbeddable: true,
8487
renderEmbeddable: (element, appState) => renderCustomEmbeddable(element, appState, excalidrawAPI),
8588
renderTopRightUI: renderTopRightUI ?? (() => (

0 commit comments

Comments
 (0)