Fix listeners cleaning on unmount
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -102,8 +102,6 @@ export function TableColumnMenu({ editor }: TableColumnMenuProps) {
|
||||
|
||||
const [hoveredCol, setHoveredCol] = useState<HoveredColumn | null>(null);
|
||||
|
||||
if (!hoveredCol && !menuOpen) return null;
|
||||
|
||||
return (
|
||||
<>
|
||||
<TableColumnMenuTrigger
|
||||
|
||||
@@ -207,9 +207,9 @@ export function TableColumnMenuContent({
|
||||
if (!table) return;
|
||||
|
||||
const map = TableMap.get(table);
|
||||
const firstCellPos = map.map[colIndex] + tableStart;
|
||||
const firstCellPos = map.map[colIndex] + tableStart + 1;
|
||||
const lastCellPos
|
||||
= map.map[(map.height - 1) * map.width + colIndex] + tableStart;
|
||||
= map.map[(map.height - 1) * map.width + colIndex] + tableStart + 1;
|
||||
|
||||
const $anchor = editor.state.doc.resolve(firstCellPos);
|
||||
const $head = editor.state.doc.resolve(lastCellPos);
|
||||
|
||||
@@ -45,11 +45,18 @@ export function TableColumnMenuTrigger({
|
||||
const dragStartPos = useRef({ x: 0, y: 0 });
|
||||
const rafId = useRef<number | null>(null);
|
||||
const hoveredColRef = useRef<HoveredColumn | null>(null);
|
||||
const dragCleanupRef = useRef<(() => void) | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
hoveredColRef.current = hoveredCol;
|
||||
}, [hoveredCol]);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
dragCleanupRef.current?.();
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (editor.isDestroyed || !editor.isEditable) return;
|
||||
|
||||
@@ -285,6 +292,7 @@ export function TableColumnMenuTrigger({
|
||||
const onMouseUp = (ev: MouseEvent) => {
|
||||
document.removeEventListener("mousemove", onMouseMove);
|
||||
document.removeEventListener("mouseup", onMouseUp);
|
||||
dragCleanupRef.current = null;
|
||||
|
||||
if (draggingRef.current) {
|
||||
setDragIndicator(null);
|
||||
@@ -327,6 +335,10 @@ export function TableColumnMenuTrigger({
|
||||
|
||||
document.addEventListener("mousemove", onMouseMove);
|
||||
document.addEventListener("mouseup", onMouseUp);
|
||||
dragCleanupRef.current = () => {
|
||||
document.removeEventListener("mousemove", onMouseMove);
|
||||
document.removeEventListener("mouseup", onMouseUp);
|
||||
};
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user