Files
Stirling-PDF/frontend/src/components/viewer/PanAPIBridge.tsx
Reece Browne 065bb46c1e Feature/v2/embed pdf (#4437)
Switched to Embed pdf for viewer

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: James Brunton <james@stirlingpdf.com>
2025-09-19 15:35:51 +01:00

46 lines
1.0 KiB
TypeScript

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