EANCH-WP-0004: HtmlViewer scroll parity and viewer-shell workplan
Export HtmlViewerAdapter from package root, add scrollRequestKey parity, register finished workplan, update SCOPE.
This commit is contained in:
parent
49d9810c93
commit
bbeba96173
4 changed files with 119 additions and 5 deletions
|
|
@ -32,6 +32,11 @@ export interface HtmlViewerAdapterProps {
|
|||
readonly representation: DocumentRepresentation;
|
||||
readonly storedAnnotations?: readonly StoredHtmlAnnotation[];
|
||||
readonly scrollToAnnotationId?: string;
|
||||
/**
|
||||
* Bumps when the same annotation should be re-scrolled (e.g. repeat click).
|
||||
* Format is opaque — typically `${annotationId}:${version}`.
|
||||
*/
|
||||
readonly scrollRequestKey?: string;
|
||||
readonly activeAnnotationId?: string | null;
|
||||
readonly debug?: HtmlViewerDebugOptions;
|
||||
onSelectionCaptured?(capture: DomSelectionCapture, selectors: Selector[]): void;
|
||||
|
|
@ -50,6 +55,7 @@ export function HtmlViewerAdapter(props: HtmlViewerAdapterProps): ReactNode {
|
|||
representation,
|
||||
storedAnnotations = [],
|
||||
scrollToAnnotationId,
|
||||
scrollRequestKey,
|
||||
activeAnnotationId,
|
||||
debug,
|
||||
onSelectionCaptured,
|
||||
|
|
@ -91,12 +97,13 @@ export function HtmlViewerAdapter(props: HtmlViewerAdapterProps): ReactNode {
|
|||
}, [html, storedAnnotations, representation, activeAnnotationId]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!scrollToAnnotationId || !rootRef.current) return;
|
||||
const requestKey = scrollRequestKey ?? scrollToAnnotationId ?? null;
|
||||
if (!requestKey || !scrollToAnnotationId || !rootRef.current) return;
|
||||
const mark = rootRef.current.querySelector(
|
||||
`[data-highlight-id="${CSS.escape(scrollToAnnotationId)}"]`,
|
||||
);
|
||||
mark?.scrollIntoView({ block: "center", behavior: "smooth" });
|
||||
}, [scrollToAnnotationId, renderedHtml]);
|
||||
}, [scrollToAnnotationId, scrollRequestKey, renderedHtml]);
|
||||
|
||||
return (
|
||||
<div
|
||||
|
|
|
|||
14
src/index.ts
14
src/index.ts
|
|
@ -20,6 +20,20 @@ export {
|
|||
type CreateSelectorsOptions,
|
||||
} from "./selectors";
|
||||
|
||||
// DOM adapter (re-exported from the src/dom/ boundary).
|
||||
export {
|
||||
HtmlViewerAdapter,
|
||||
resolveHtmlSelectors,
|
||||
scrollToHtmlTarget,
|
||||
renderHtmlHighlight,
|
||||
captureFromRange,
|
||||
domPathToNode,
|
||||
nodeAtPath,
|
||||
type HtmlViewerAdapterProps,
|
||||
type HtmlViewerDebugOptions,
|
||||
type StoredHtmlAnnotation,
|
||||
} from "./dom";
|
||||
|
||||
// PDF adapter + helpers (re-exported from the src/pdf/ boundary).
|
||||
export {
|
||||
PdfViewerAdapter,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue