Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: wojtekmaj/react-pdf
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v6.2.0
Choose a base ref
...
head repository: wojtekmaj/react-pdf
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v6.2.1
Choose a head ref
  • 10 commits
  • 12 files changed
  • 2 contributors

Commits on Nov 23, 2022

  1. Verified

    This commit was signed with the committer’s verified signature.
    wojtekmaj Wojciech Maj
    Copy the full SHA
    373335c View commit details
  2. Use Node 18 for CI

    wojtekmaj committed Nov 23, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    wojtekmaj Wojciech Maj
    Copy the full SHA
    0401e2a View commit details
  3. Verified

    This commit was signed with the committer’s verified signature.
    wojtekmaj Wojciech Maj
    Copy the full SHA
    34fbf09 View commit details
  4. Verified

    This commit was signed with the committer’s verified signature.
    wojtekmaj Wojciech Maj
    Copy the full SHA
    425834e View commit details

Commits on Nov 24, 2022

  1. Update documentation on compatibility

    Related to #1193
    wojtekmaj committed Nov 24, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    wojtekmaj Wojciech Maj
    Copy the full SHA
    a34a52e View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    wojtekmaj Wojciech Maj
    Copy the full SHA
    300712e View commit details

Commits on Dec 2, 2022

  1. Verified

    This commit was signed with the committer’s verified signature.
    wojtekmaj Wojciech Maj
    Copy the full SHA
    97d8b87 View commit details

Commits on Dec 22, 2022

  1. Fix typos (#1227)

    letavocado authored Dec 22, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    39cf51e View commit details

Commits on Dec 28, 2022

  1. Fix first annotation not clickable

    Fixes #1231
    wojtekmaj committed Dec 28, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    wojtekmaj Wojciech Maj
    Copy the full SHA
    1ee0376 View commit details
  2. v6.2.1

    wojtekmaj committed Dec 28, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    wojtekmaj Wojciech Maj
    Copy the full SHA
    2297b2d View commit details
Showing with 64 additions and 26 deletions.
  1. +3 −3 .github/workflows/ci.yml
  2. +1 −1 .github/workflows/dependabot-dedupe.yml
  3. +9 −5 README.md
  4. +1 −0 jest.config.json
  5. +1 −1 package.json
  6. +11 −8 src/OutlineItem.jsx
  7. +24 −0 src/OutlineItem.spec.jsx
  8. +3 −0 src/Page.jsx
  9. +1 −2 src/Page/TextLayer.css
  10. +5 −1 src/Page/TextLayer.jsx
  11. +4 −4 src/shared/utils.js
  12. +1 −1 test/Test.jsx
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '16'
node-version: '18'

- name: Enable Corepack
run: corepack enable
@@ -65,7 +65,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '16'
node-version: '18'

- name: Enable Corepack
run: corepack enable
@@ -99,7 +99,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '16'
node-version: '18'

- name: Enable Corepack
run: corepack enable
2 changes: 1 addition & 1 deletion .github/workflows/dependabot-dedupe.yml
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '16'
node-version: '18'

- name: Enable Corepack
run: corepack enable
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -41,12 +41,16 @@ React-PDF supports all modern browsers. It is tested with the latest versions of

The following browsers are supported in React-PDF v6:

- Chrome ≥73
- Chrome ≥76
- Edge (Chromium-based)
- Safari ≥12.1
- Firefox ≥45(?)
- Safari ≥14.1
- Firefox ≥90(?)

If you need to support older browsers, you will need to use React-PDF v5. If you need to support Internet Explorer 11, you will need to use React-PDF v4.
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`.

If you need to support older browsers, you will need to use React-PDF v5.

If you need to support Internet Explorer 11, you will need to use React-PDF v4.

#### React

@@ -405,7 +409,7 @@ Displays a page. Should be placed inside `<Document />`. Alternatively, it can h
| canvasBackground | Canvas background color. Any valid `canvas.fillStyle` can be used. If you set `renderMode` to `"svg"` this prop will be ignored. | n/a | `"transparent"` |
| canvasRef | A prop that behaves like [ref](https://reactjs.org/docs/refs-and-the-dom.html), but it's passed to `<canvas>` rendered by `<PageCanvas>` component. If you set `renderMode` to `"svg"` this prop will be ignored. | n/a | <ul><li>Function:<br />`(ref) => { this.myPage = ref; }`</li><li>Ref created using `React.createRef`:<br />`this.ref = React.createRef();`<br />…<br />`inputRef={this.ref}`</li><li>Ref created using `React.useRef`:<br />`const ref = React.useRef();`<br />…<br />`inputRef={ref}`</li></ul> |
| className | Class name(s) that will be added to rendered element along with the default `react-pdf__Page`. | n/a | <ul><li>String:<br />`"custom-class-name-1 custom-class-name-2"`</li><li>Array of strings:<br />`["custom-class-name-1", "custom-class-name-2"]`</li></ul> |
| customTextRenderer | Function that customizes how a text layer is rendered. | n/a | `` ({ str, itemIndex }) => str.replace(/ipsum/g, `<mark>ipsum</mark>`) `` |
| customTextRenderer | Function that customizes how a text layer is rendered. | n/a | `` ({ str, itemIndex }) => str.replace(/ipsum/g, value => `<mark>${value}</mark>`) `` |
| devicePixelRatio | The ratio between physical pixels and device-independent pixels (DIPs) on the current device. | `window.devicePixelRatio` | `1` |
| error | What the component should display in case of an error. | `"Failed to load the page."` | <ul><li>String:<br />`"An error occurred!"`</li><li>React element:<br />`<div>An error occurred!</div>`</li><li>Function:<br />`this.renderError`</li></ul> |
| height | Page height. If neither `height` nor `width` are defined, page will be rendered at the size defined in PDF. If you define `width` and `height` at the same time, `height` will be ignored. If you define `height` and `scale` at the same time, the height will be multiplied by a given factor. | Page's default height | `300` |
1 change: 1 addition & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
"\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js",
"pdfjs-dist/(.*)": "pdfjs-dist/legacy/$1"
},
"reporters": ["default", "github-actions"],
"setupFilesAfterEnv": ["jest-canvas-mock", "<rootDir>/jest.setup.js"],
"testEnvironment": "<rootDir>/jest.env.js"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-pdf",
"version": "6.2.0",
"version": "6.2.1",
"description": "Display PDFs in your React app as easily as if they were images.",
"main": "dist/cjs/entry.js",
"module": "dist/esm/entry.js",
19 changes: 11 additions & 8 deletions src/OutlineItem.jsx
Original file line number Diff line number Diff line change
@@ -13,17 +13,18 @@ import { isPdf } from './shared/propTypes';
export class OutlineItemInternal extends PureComponent {
getDestination = () =>
new Promise((resolve, reject) => {
if (isDefined(this.destination)) {
resolve(this.destination);
return;
}

const { item, pdf } = this.props;

if (!isDefined(this.destination)) {
if (typeof item.dest === 'string') {
pdf.getDestination(item.dest).then(resolve).catch(reject);
} else {
resolve(item.dest);
}
if (typeof item.dest === 'string') {
pdf.getDestination(item.dest).then(resolve).catch(reject);
} else {
resolve(item.dest);
}

return this.destination;
}).then((destination) => {
this.destination = destination;
return destination;
@@ -34,6 +35,7 @@ export class OutlineItemInternal extends PureComponent {
const { pdf } = this.props;
if (isDefined(this.pageIndex)) {
resolve(this.pageIndex);
return;
}

this.getDestination().then((destination) => {
@@ -53,6 +55,7 @@ export class OutlineItemInternal extends PureComponent {
new Promise((resolve, reject) => {
if (isDefined(this.pageNumber)) {
resolve(this.pageNumber);
return;
}

this.getPageIndex()
24 changes: 24 additions & 0 deletions src/OutlineItem.spec.jsx
Original file line number Diff line number Diff line change
@@ -53,5 +53,29 @@ describe('OutlineItem', () => {

expect(onClick).toHaveBeenCalled();
});

it('calls onClick with proper arguments multiple times when clicked a link multiple times', async () => {
const { func: onClick, promise: onClickPromise } = makeAsyncCallback();

const { rerender } = render(<OutlineItem item={outlineItem} onClick={onClick} pdf={pdf} />);

const item = screen.getAllByRole('listitem')[0];
const link = getAllByRole(item, 'link')[0];
fireEvent.click(link);

await onClickPromise;

expect(onClick).toHaveBeenCalledTimes(1);

const { func: onClick2, promise: onClickPromise2 } = makeAsyncCallback();

rerender(<OutlineItem item={outlineItem} onClick={onClick2} pdf={pdf} />);

fireEvent.click(link);

await onClickPromise2;

expect(onClick2).toHaveBeenCalledTimes(1);
});
});
});
3 changes: 3 additions & 0 deletions src/Page.jsx
Original file line number Diff line number Diff line change
@@ -70,6 +70,7 @@ export class PageInternal extends PureComponent {
}

get childContext() {
const { pageIndex, pageNumber } = this;
const { page } = this.state;

if (!page) {
@@ -109,6 +110,8 @@ export class PageInternal extends PureComponent {
onRenderTextLayerError,
onRenderTextLayerSuccess,
page,
pageIndex,
pageNumber,
renderForms: renderForms ?? renderInteractiveForms, // For backward compatibility
rotate: this.rotate,
scale: this.scale,
3 changes: 1 addition & 2 deletions src/Page/TextLayer.css
Original file line number Diff line number Diff line change
@@ -37,7 +37,6 @@
white-space: pre;
cursor: text;
transform-origin: 0% 0%;
z-index: 1;
}

/* Only necessary in Google Chrome, see issue 14205, and most unfortunately
@@ -86,7 +85,7 @@
top: 100%;
right: 0;
bottom: 0;
z-index: 0;
z-index: -1;
cursor: default;
user-select: none;
}
6 changes: 5 additions & 1 deletion src/Page/TextLayer.jsx
Original file line number Diff line number Diff line change
@@ -145,7 +145,7 @@ export class TextLayerInternal extends PureComponent {
const container = this.layerElement.current;

const { viewport } = this;
const { customTextRenderer } = this.props;
const { customTextRenderer, pageIndex, pageNumber } = this.props;

// If another rendering is in progress, let's cancel it
cancelRunningTask(this.runningTask);
@@ -174,6 +174,8 @@ export class TextLayerInternal extends PureComponent {
const child = this.layerElement.current.children[index];

const content = customTextRenderer({
pageIndex,
pageNumber,
itemIndex,
...item,
});
@@ -212,6 +214,8 @@ TextLayerInternal.propTypes = {
onRenderTextLayerError: PropTypes.func,
onRenderTextLayerSuccess: PropTypes.func,
page: isPage.isRequired,
pageIndex: PropTypes.number.isRequired,
pageNumber: PropTypes.number.isRequired,
rotate: isRotate,
scale: PropTypes.number,
};
8 changes: 4 additions & 4 deletions src/shared/utils.js
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import warning from 'tiny-warning';
/**
* Checks if we're running in a browser environment.
*/
export const isBrowser = typeof window !== 'undefined';
export const isBrowser = typeof document !== 'undefined';

/**
* Checks whether we're running from a local file system.
@@ -30,7 +30,7 @@ export function isProvided(variable) {
}

/**
* Checkes whether a variable provided is a string.
* Checks whether a variable provided is a string.
*
* @param {*} variable Variable to check
*/
@@ -48,7 +48,7 @@ export function isArrayBuffer(variable) {
}

/**
* Checkes whether a variable provided is a Blob.
* Checks whether a variable provided is a Blob.
*
* @param {*} variable Variable to check
*/
@@ -59,7 +59,7 @@ export function isBlob(variable) {
}

/**
* Checkes whether a variable provided is a File.
* Checks whether a variable provided is a File.
*
* @param {*} variable Variable to check
*/
2 changes: 1 addition & 1 deletion test/Test.jsx
Original file line number Diff line number Diff line change
@@ -187,7 +187,7 @@ export default function Test() {
scale: pageScale,
width: pageWidth,
customTextRenderer: useCustomTextRenderer
? ({ str }) => str.replace(/ipsum/g, `<mark>ipsum</mark>`)
? ({ str }) => str.replace(/ipsum/g, (value) => `<mark>${value}</mark>`)
: null,
};
}