Skip to content

Commit

Permalink
Closes #1
Browse files Browse the repository at this point in the history
  • Loading branch information
rsimon committed Oct 3, 2021
1 parent 942f178 commit 263c875
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/pdf/PDFViewer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ const store = new Store();
/**
* Helper to insert the page index into the annotation target
*/
const extendTarget = (annotation, page) => ({
const extendTarget = (annotation, source, page) => ({
...annotation,
target: {
source,
selector: annotation.target.selector.map(selector =>
selector.type === 'TextPositionSelector' ?
{ ...selector, page } : selector)
Expand Down Expand Up @@ -84,7 +85,7 @@ const PDFViewer = props => {

const onCreateAnnotation = a => {
// Insert page number in target
const extended = extendTarget(a, page.pageNumber);
const extended = extendTarget(a, props.url, page.pageNumber);

// Store in memory
store.createAnnotation(extended);
Expand All @@ -94,16 +95,16 @@ const PDFViewer = props => {
}

const onUpdateAnnotation = (a, p) => {
const updated = extendTarget(a, page.pageNumber);
const previous = extendTarget(p, page.pageNumber);
const updated = extendTarget(a, props.url, page.pageNumber);
const previous = extendTarget(p, props.url, page.pageNumber);

store.updateAnnotation(updated, previous);

props.onUpdateAnnotation && props.onUpdateAnnotation(updated, previous);
}

const onDeleteAnnotation = a => {
const extended = extendTarget(a, page.pageNumber);
const extended = extendTarget(a, props.url, page.pageNumber);
store.deleteAnnotation(extended);
props.onDeleteAnnotation && props.onDeleteAnnotation(extended);
}
Expand Down
3 changes: 2 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const App = () => {
return (
<PDFViewer
url="compressed.tracemonkey-pldi-09.pdf"
annotations={annotations} />
annotations={annotations}
onCreateAnnotation={a => console.log(JSON.stringify(a))} />
)

}
Expand Down

0 comments on commit 263c875

Please sign in to comment.