react-pdf
Advanced tools
Comparing version 7.0.1 to 7.0.2
@@ -111,9 +111,7 @@ "use strict"; | ||
}); | ||
(0, react_1.useImperativeHandle)(ref, () => { | ||
return { | ||
linkService, | ||
pages, | ||
viewer, | ||
}; | ||
}, []); | ||
(0, react_1.useImperativeHandle)(ref, () => ({ | ||
linkService, | ||
pages, | ||
viewer, | ||
}), []); | ||
/** | ||
@@ -266,2 +264,5 @@ * Called when a document source is resolved correctly | ||
.catch((error) => { | ||
if (loadingTask.destroyed) { | ||
return; | ||
} | ||
pdfDispatch({ type: 'REJECT', error }); | ||
@@ -268,0 +269,0 @@ }); |
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { isPageIndex, isPageNumber } from './shared/propTypes'; | ||
import type { PDFDocumentProxy } from 'pdfjs-dist'; | ||
@@ -70,4 +69,4 @@ import type { EventProps } from 'make-event-props'; | ||
onRenderTextLayerSuccess: PropTypes.Requireable<(...args: any[]) => any>; | ||
pageIndex: typeof isPageIndex; | ||
pageNumber: typeof isPageNumber; | ||
pageIndex: PropTypes.Validator<number>; | ||
pageNumber: PropTypes.Validator<number>; | ||
pdf: PropTypes.Requireable<NonNullable<boolean | PropTypes.InferProps<{ | ||
@@ -74,0 +73,0 @@ getDestination: PropTypes.Validator<(...args: any[]) => any>; |
@@ -5,3 +5,3 @@ import PropTypes from 'prop-types'; | ||
import LinkService from '../LinkService'; | ||
import type { PDFDocumentProxy } from 'pdfjs-dist'; | ||
import type { Validator } from 'prop-types'; | ||
type AllEvents = (typeof allEvents)[number]; | ||
@@ -29,8 +29,4 @@ type Props = { | ||
}>>; | ||
export declare function isPageIndex(props: Record<string, unknown> & { | ||
pdf?: PDFDocumentProxy; | ||
}, propName: string, componentName: string): Error | null; | ||
export declare function isPageNumber(props: Record<string, unknown> & { | ||
pdf?: PDFDocumentProxy; | ||
}, propName: string, componentName: string): Error | null; | ||
export declare const isPageIndex: Validator<number>; | ||
export declare const isPageNumber: Validator<number>; | ||
export declare const isPdf: PropTypes.Requireable<NonNullable<boolean | PropTypes.InferProps<{ | ||
@@ -37,0 +33,0 @@ getDestination: PropTypes.Validator<(...args: any[]) => any>; |
@@ -65,3 +65,3 @@ "use strict"; | ||
}); | ||
function isPageIndex(props, propName, componentName) { | ||
const isPageIndex = function isPageIndex(props, propName, componentName) { | ||
const { [propName]: pageIndex, pageNumber, pdf } = props; | ||
@@ -88,5 +88,5 @@ if (!(0, utils_1.isDefined)(pdf)) { | ||
return null; | ||
} | ||
}; | ||
exports.isPageIndex = isPageIndex; | ||
function isPageNumber(props, propName, componentName) { | ||
const isPageNumber = function isPageNumber(props, propName, componentName) { | ||
const { [propName]: pageNumber, pageIndex, pdf } = props; | ||
@@ -113,3 +113,3 @@ if (!(0, utils_1.isDefined)(pdf)) { | ||
return null; | ||
} | ||
}; | ||
exports.isPageNumber = isPageNumber; | ||
@@ -116,0 +116,0 @@ exports.isPdf = prop_types_1.default.oneOfType([ |
@@ -83,9 +83,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}); | ||
useImperativeHandle(ref, () => { | ||
return { | ||
linkService, | ||
pages, | ||
viewer, | ||
}; | ||
}, []); | ||
useImperativeHandle(ref, () => ({ | ||
linkService, | ||
pages, | ||
viewer, | ||
}), []); | ||
/** | ||
@@ -238,2 +236,5 @@ * Called when a document source is resolved correctly | ||
.catch((error) => { | ||
if (loadingTask.destroyed) { | ||
return; | ||
} | ||
pdfDispatch({ type: 'REJECT', error }); | ||
@@ -240,0 +241,0 @@ }); |
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { isPageIndex, isPageNumber } from './shared/propTypes'; | ||
import type { PDFDocumentProxy } from 'pdfjs-dist'; | ||
@@ -70,4 +69,4 @@ import type { EventProps } from 'make-event-props'; | ||
onRenderTextLayerSuccess: PropTypes.Requireable<(...args: any[]) => any>; | ||
pageIndex: typeof isPageIndex; | ||
pageNumber: typeof isPageNumber; | ||
pageIndex: PropTypes.Validator<number>; | ||
pageNumber: PropTypes.Validator<number>; | ||
pdf: PropTypes.Requireable<NonNullable<boolean | PropTypes.InferProps<{ | ||
@@ -74,0 +73,0 @@ getDestination: PropTypes.Validator<(...args: any[]) => any>; |
@@ -5,3 +5,3 @@ import PropTypes from 'prop-types'; | ||
import LinkService from '../LinkService'; | ||
import type { PDFDocumentProxy } from 'pdfjs-dist'; | ||
import type { Validator } from 'prop-types'; | ||
type AllEvents = (typeof allEvents)[number]; | ||
@@ -29,8 +29,4 @@ type Props = { | ||
}>>; | ||
export declare function isPageIndex(props: Record<string, unknown> & { | ||
pdf?: PDFDocumentProxy; | ||
}, propName: string, componentName: string): Error | null; | ||
export declare function isPageNumber(props: Record<string, unknown> & { | ||
pdf?: PDFDocumentProxy; | ||
}, propName: string, componentName: string): Error | null; | ||
export declare const isPageIndex: Validator<number>; | ||
export declare const isPageNumber: Validator<number>; | ||
export declare const isPdf: PropTypes.Requireable<NonNullable<boolean | PropTypes.InferProps<{ | ||
@@ -37,0 +33,0 @@ getDestination: PropTypes.Validator<(...args: any[]) => any>; |
@@ -59,3 +59,3 @@ import PropTypes from 'prop-types'; | ||
}); | ||
export function isPageIndex(props, propName, componentName) { | ||
export const isPageIndex = function isPageIndex(props, propName, componentName) { | ||
const { [propName]: pageIndex, pageNumber, pdf } = props; | ||
@@ -82,4 +82,4 @@ if (!isDefined(pdf)) { | ||
return null; | ||
} | ||
export function isPageNumber(props, propName, componentName) { | ||
}; | ||
export const isPageNumber = function isPageNumber(props, propName, componentName) { | ||
const { [propName]: pageNumber, pageIndex, pdf } = props; | ||
@@ -106,3 +106,3 @@ if (!isDefined(pdf)) { | ||
return null; | ||
} | ||
}; | ||
export const isPdf = PropTypes.oneOfType([ | ||
@@ -109,0 +109,0 @@ PropTypes.shape({ |
{ | ||
"name": "react-pdf", | ||
"version": "7.0.1", | ||
"version": "7.0.2", | ||
"description": "Display PDFs in your React app as easily as if they were images.", | ||
@@ -51,3 +51,3 @@ "main": "dist/cjs/index.js", | ||
"eslint": "^8.26.0", | ||
"eslint-config-wojtekmaj": "^0.8.3", | ||
"eslint-config-wojtekmaj": "^0.8.4", | ||
"husky": "^8.0.0", | ||
@@ -54,0 +54,0 @@ "jsdom": "^21.1.0", |
@@ -43,10 +43,10 @@ [![npm](https://img.shields.io/npm/v/react-pdf.svg)](https://www.npmjs.com/package/react-pdf) ![downloads](https://img.shields.io/npm/dt/react-pdf.svg) [![CI](https://github.com/wojtekmaj/react-pdf/workflows/CI/badge.svg)](https://github.com/wojtekmaj/react-pdf/actions) | ||
The following browsers are supported in React-PDF v7: | ||
The following browsers are supported out of the box in React-PDF v7: | ||
- Chrome ≥88 | ||
- Edge ≥88 | ||
- Safari ≥14.1 | ||
- Firefox ESR | ||
- Chrome ≥92 | ||
- Edge ≥92 | ||
- Safari ≥15.4 | ||
- Firefox ≥90 | ||
You may extend the list of supported browsers by providing additional polyfills (e.g. for `Promise.allSettled`) and configuring your bundler to transpile `pdfjs-dist`. | ||
You may extend the list of supported browsers by providing additional polyfills (e.g. for `Array.prototype.at` or `Promise.allSettled`) and either configuring your bundler to transpile `pdfjs-dist` or using [legacy PDF.js worker](#legacy-pdfjs-worker). | ||
@@ -181,2 +181,21 @@ If you need to support older browsers, you will need to use React-PDF v6 or v5. | ||
#### Legacy PDF.js worker | ||
If you need to support older browsers, you may use legacy PDF.js worker. To do so, follow the instructions above, but replace `/build/` with `legacy/build/` in PDF.js worker import path, for example: | ||
```diff | ||
pdfjs.GlobalWorkerOptions.workerSrc = new URL( | ||
- 'pdfjs-dist/build/pdf.worker.min.js', | ||
+ 'pdfjs-dist/legacy/build/pdf.worker.min.js', | ||
import.meta.url, | ||
).toString(); | ||
``` | ||
or: | ||
```diff | ||
-pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/build/pdf.worker.min.js`; | ||
+pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/legacy/build/pdf.worker.min.js`; | ||
``` | ||
### Support for annotations | ||
@@ -183,0 +202,0 @@ |
@@ -9,3 +9,3 @@ import PropTypes from 'prop-types'; | ||
import type { PDFDocumentProxy } from 'pdfjs-dist'; | ||
import type { Validator } from 'prop-types'; | ||
@@ -81,7 +81,3 @@ type AllEvents = (typeof allEvents)[number]; | ||
export function isPageIndex( | ||
props: Record<string, unknown> & { pdf?: PDFDocumentProxy }, | ||
propName: string, | ||
componentName: string, | ||
) { | ||
export const isPageIndex: Validator<number> = function isPageIndex(props, propName, componentName) { | ||
const { [propName]: pageIndex, pageNumber, pdf } = props; | ||
@@ -117,8 +113,8 @@ | ||
return null; | ||
} | ||
}; | ||
export function isPageNumber( | ||
props: Record<string, unknown> & { pdf?: PDFDocumentProxy }, | ||
propName: string, | ||
componentName: string, | ||
export const isPageNumber: Validator<number> = function isPageNumber( | ||
props, | ||
propName, | ||
componentName, | ||
) { | ||
@@ -155,3 +151,3 @@ const { [propName]: pageNumber, pageIndex, pdf } = props; | ||
return null; | ||
} | ||
}; | ||
@@ -158,0 +154,0 @@ export const isPdf = PropTypes.oneOfType([ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
481974
523
10605