diff --git a/package.json b/package.json index 82eb27e6a..96f82db82 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/Document.jsx b/src/Document.jsx index 6da8d7879..ce3a63343 100644 --- a/src/Document.jsx +++ b/src/Document.jsx @@ -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() { diff --git a/src/Document.spec.jsx b/src/Document.spec.jsx index 7dfe1d650..a2a5f3f46 100644 --- a/src/Document.spec.jsx +++ b/src/Document.spec.jsx @@ -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(); @@ -528,7 +528,7 @@ describe('Document', () => { await onLoadSuccessPromise; - expect(component.instance().linkService.externalLinkTarget).toBe(linkServiceTarget); + expect(component.instance().linkService.externalLinkTarget).toBe(target); }); }); diff --git a/src/LinkService.js b/src/LinkService.js index 0d55134c7..26a37bbc5 100644 --- a/src/LinkService.js +++ b/src/LinkService.js @@ -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() { @@ -31,6 +31,10 @@ export default class LinkService { this.pdfViewer = pdfViewer; } + setExternalLinkTarget(externalLinkTarget) { + this.externalLinkTarget = externalLinkTarget; + } + setHistory() {} get pagesCount() { @@ -104,6 +108,11 @@ export default class LinkService { goToPage() {} + addLinkAttributes(link, url, newWindow) { + link.href = url; + link.target = newWindow ? '_blank' : this.externalLinkTarget || ''; + } + getDestinationHash() { return '#'; } diff --git a/src/Page/AnnotationLayer.spec.jsx b/src/Page/AnnotationLayer.spec.jsx index e83be8c4f..e4e2e4480 100644 --- a/src/Page/AnnotationLayer.spec.jsx +++ b/src/Page/AnnotationLayer.spec.jsx @@ -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(