Skip to content

Commit

Permalink
Update pdfjs-dist to 2.12.313 (#936)
Browse files Browse the repository at this point in the history
* Update pdfjs-dist to 2.12.313

* Update LinkService to work with pdfjs-dist 2.12.313
  • Loading branch information
wojtekmaj authored Jan 26, 2022
1 parent d36e888 commit 5eba583
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 38 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"make-event-props": "^1.1.0",
"merge-class-names": "^1.1.1",
"merge-refs": "^1.0.0",
"pdfjs-dist": "2.10.377",
"pdfjs-dist": "2.12.313",
"prop-types": "^15.6.2",
"tiny-invariant": "^1.0.0",
"tiny-warning": "^1.0.0"
Expand Down
16 changes: 3 additions & 13 deletions src/Document.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,10 @@ export default class Document extends PureComponent {
}

setupLinkService = () => {
const { externalLinkTarget } = this.props;

this.linkService.setViewer(this.viewer);
const documentInstance = this;
Object.defineProperty(this.linkService, 'externalLinkTarget', {
get() {
const { externalLinkTarget } = documentInstance.props;
switch (externalLinkTarget) {
case '_self': return 1;
case '_blank': return 2;
case '_parent': return 3;
case '_top': return 4;
default: return 0;
}
},
});
this.linkService.setExternalLinkTarget(externalLinkTarget);
}

get childContext() {
Expand Down
18 changes: 9 additions & 9 deletions src/Document.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -505,14 +505,14 @@ describe('Document', () => {

describe('linkService', () => {
it.each`
externalLinkTarget | linkServiceTarget
${null} | ${0}
${'_self'} | ${1}
${'_blank'} | ${2}
${'_parent'} | ${3}
${'_top'} | ${4}
`('returns externalLinkTarget = $linkServiceTarget given externalLinkTarget prop = $externalLinkTarget', async ({
externalLinkTarget, linkServiceTarget,
externalLinkTarget | target
${null} | ${null}
${'_self'} | ${'_self'}
${'_blank'} | ${'_blank'}
${'_parent'} | ${'_parent'}
${'_top'} | ${'_top'}
`('returns externalLinkTarget = $target given externalLinkTarget prop = $externalLinkTarget', async ({
externalLinkTarget, target,
}) => {
const { func: onLoadSuccess, promise: onLoadSuccessPromise } = makeAsyncCallback();

Expand All @@ -528,7 +528,7 @@ describe('Document', () => {

await onLoadSuccessPromise;

expect(component.instance().linkService.externalLinkTarget).toBe(linkServiceTarget);
expect(component.instance().linkService.externalLinkTarget).toBe(target);
});
});

Expand Down
11 changes: 10 additions & 1 deletion src/LinkService.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
import invariant from 'tiny-invariant';

/* eslint-disable class-methods-use-this, no-empty-function */
/* eslint-disable class-methods-use-this, no-empty-function, no-param-reassign */

export default class LinkService {
constructor() {
Expand All @@ -31,6 +31,10 @@ export default class LinkService {
this.pdfViewer = pdfViewer;
}

setExternalLinkTarget(externalLinkTarget) {
this.externalLinkTarget = externalLinkTarget;
}

setHistory() {}

get pagesCount() {
Expand Down Expand Up @@ -104,6 +108,11 @@ export default class LinkService {

goToPage() {}

addLinkAttributes(link, url, newWindow) {
link.href = url;
link.target = newWindow ? '_blank' : this.externalLinkTarget || '';
}

getDestinationHash() {
return '#';
}
Expand Down
19 changes: 11 additions & 8 deletions src/Page/AnnotationLayer.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,22 @@ describe('AnnotationLayer', () => {
});

it.each`
linkServiceTarget | target
${1} | ${'_self'}
${2} | ${'_blank'}
${3} | ${'_parent'}
${4} | ${'_top'}
`('renders all links with target $target given externalLinkTarget = $target', ({
linkServiceTarget, target,
externalLinkTarget | target
${null} | ${''}
${'_self'} | ${'_self'}
${'_blank'} | ${'_blank'}
${'_parent'} | ${'_parent'}
${'_top'} | ${'_top'}
`('renders all links with target $target given externalLinkTarget = $externalLinkTarget', ({
externalLinkTarget, target,
}) => {
const {
func: onRenderAnnotationLayerSuccess, promise: onRenderAnnotationLayerSuccessPromise,
} = makeAsyncCallback();
const customLinkService = new LinkService();
customLinkService.externalLinkTarget = linkServiceTarget;
if (externalLinkTarget) {
customLinkService.setExternalLinkTarget(externalLinkTarget);
}

const component = mount(
<AnnotationLayer
Expand Down
15 changes: 9 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5883,12 +5883,15 @@ __metadata:
languageName: node
linkType: hard

"pdfjs-dist@npm:2.10.377":
version: 2.10.377
resolution: "pdfjs-dist@npm:2.10.377"
"pdfjs-dist@npm:2.12.313":
version: 2.12.313
resolution: "pdfjs-dist@npm:2.12.313"
peerDependencies:
worker-loader: ^3.0.7
checksum: 5a4c14777676e15aeca9a627cc1f368821071ae040154983edf21f1040cb89acd9b0168b43b64ac10d66f86094dcb48b33513b9810b6d422446c599fb172d5a4
worker-loader: ^3.0.8
peerDependenciesMeta:
worker-loader:
optional: true
checksum: 0571ff3653d75e7eaf86c840c6fe83a92456c20b6f40c2de666df2e3c30de1e05a4920f18799a3d59005c73dcea1a6f45728845a20fdae9b08a3a774d13aee1b
languageName: node
linkType: hard

Expand Down Expand Up @@ -6119,7 +6122,7 @@ __metadata:
make-event-props: ^1.1.0
merge-class-names: ^1.1.1
merge-refs: ^1.0.0
pdfjs-dist: 2.10.377
pdfjs-dist: 2.12.313
prop-types: ^15.6.2
react: ^17.0.0
react-dom: ^17.0.0
Expand Down

0 comments on commit 5eba583

Please sign in to comment.