MCPcopy Create free account
hub / github.com/bjsi/incremental-everything / SourceReaderView

Function SourceReaderView

src/components/SourceReaderView.tsx:20–151  ·  view source on GitHub ↗
({ hostRemId, hoveredRemId, kind, onClose }: SourceReaderViewProps)

Source from the content-addressed store, hash-verified

18 moveCount?: number;
19}
20
21// How long to wait for the host to apply the last move, then how long the reader
22// must stay 1px shorter: two changes landing in one host frame would cancel out.
23const REANCHOR_DELAY_MS = 100;
24const REANCHOR_HOLD_MS = 150;
25
26/**
27 * Shared reader UI for both the modal (pdf_source_popup) and floating
28 * (pdf_source_floating) Source-popup variants. Renders the SDK PDFWebReader for
29 * a Reader source and, for highlights, auto-scrolls to the highlighted passage.
30 */
31export function SourceReaderView({
32 hostRemId,
33 hoveredRemId,
34 kind,
35 onClose,
36 onHeaderPointerDown,
37 moveCount = 0,
38}: SourceReaderViewProps) {
39 const plugin = usePlugin() as ReactRNPlugin;
40 const hasScrolled = useRef(false);
41 const [sourceName, setSourceName] = useState('');
42 const [reanchoring, setReanchoring] = useState(false);
43
44 // The PDF canvas caches its on-screen origin and re-reads it only when its size
45 // changes, so after a move every click lands where the reader used to be and
46 // misses the highlights. Height only: a width change would rescale the page.
47 // The padding shrinks the embed's parent, which the SDK forwards to the host.
48 useEffect(() => {
49 if (!moveCount) return;
50 const start = setTimeout(() => setReanchoring(true), REANCHOR_DELAY_MS);
51 const end = setTimeout(() => setReanchoring(false), REANCHOR_DELAY_MS + REANCHOR_HOLD_MS);
52 return () => {
53 clearTimeout(start);
54 clearTimeout(end);
55 };
56 }, [moveCount]);
57
58 // Name of the source document, shown after "Source" in the header.
59 useEffect(() => {
60 let cancelled = false;
61 (async () => {
62 try {
63 const rem = await plugin.rem.findOne(hostRemId);
64 const name = rem ? (await safeRemTextToString(plugin, rem.text)).trim() : '';
65 if (!cancelled) setSourceName(name);
66 } catch (e) {
67 console.error('[SourceReaderView] name lookup error', e);
68 }
69 })();
70 return () => {
71 cancelled = true;
72 };
73 }, [hostRemId, plugin]);
74
75 // Scroll the reader to the hovered highlight (highlights only).
76 //
77 // PDF.js / the native reader takes several seconds to mount inside the iframe

Callers

nothing calls this directly

Calls 1

attemptScrollFunction · 0.85

Tested by

no test coverage detected