46 lines
1.0 KiB
TypeScript
Raw Normal View History

2025-09-11 22:51:10 +01:00
import { useEffect, useState } from 'react';
import { usePan } from '@embedpdf/plugin-pan/react';
import { useViewer } from '../../contexts/ViewerContext';
2025-09-11 22:51:10 +01:00
/**
* Component that runs inside EmbedPDF context and updates pan state in ViewerContext
2025-09-11 22:51:10 +01:00
*/
2025-09-12 16:26:05 +01:00
export function PanAPIBridge() {
2025-09-11 22:51:10 +01:00
const { provides: pan, isPanning } = usePan();
const { registerBridge } = useViewer();
// Store state locally
const [_localState, setLocalState] = useState({
isPanning: false
});
2025-09-11 22:51:10 +01:00
useEffect(() => {
if (pan) {
// Update local state
const newState = {
isPanning
2025-09-11 22:51:10 +01:00
};
setLocalState(newState);
2025-09-12 16:26:05 +01:00
// Register this bridge with ViewerContext
registerBridge('pan', {
state: newState,
api: {
enable: () => {
pan.enablePan();
},
disable: () => {
pan.disablePan();
},
toggle: () => {
pan.togglePan();
},
makePanDefault: () => pan.makePanDefault(),
}
});
2025-09-11 22:51:10 +01:00
}
}, [pan, isPanning]);
2025-09-11 22:51:10 +01:00
2025-09-12 16:26:05 +01:00
return null;
}