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: v7.7.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: v7.7.1
Choose a head ref

Commits on Jan 17, 2024

  1. Copy the full SHA
    7807060 View commit details
  2. Copy the full SHA
    42eb211 View commit details

Commits on Jan 23, 2024

  1. Copy the full SHA
    4e77ef3 View commit details

Commits on Jan 25, 2024

  1. Copy the full SHA
    5895876 View commit details

Commits on Jan 31, 2024

  1. Update husky to 9.0.0

    wojtekmaj committed Jan 31, 2024
    Copy the full SHA
    aa8c564 View commit details

Commits on Feb 1, 2024

  1. Copy the full SHA
    cf5327b View commit details
  2. Copy the full SHA
    e339525 View commit details

Commits on Feb 12, 2024

  1. Copy the full SHA
    57eaaf7 View commit details
  2. Copy the full SHA
    8629bb3 View commit details
  3. Copy the full SHA
    46aecb9 View commit details
  4. Copy the full SHA
    2706679 View commit details

Commits on Feb 20, 2024

  1. Update Yarn to 4.1.0

    wojtekmaj committed Feb 20, 2024
    Copy the full SHA
    d4b781a View commit details
  2. Copy the full SHA
    a9d0b52 View commit details
  3. Copy the full SHA
    f01d41e View commit details
  4. Bump ip from 2.0.0 to 2.0.1 (#1731)

    Bumps [ip](https://github.com/indutny/node-ip) from 2.0.0 to 2.0.1.
    - [Commits](indutny/node-ip@v2.0.0...v2.0.1)
    
    ---
    updated-dependencies:
    - dependency-name: ip
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Feb 20, 2024
    Copy the full SHA
    01d30b0 View commit details
  5. Bump ip from 2.0.0 to 2.0.1 in /sample/create-react-app-5 (#1726)

    Bumps [ip](https://github.com/indutny/node-ip) from 2.0.0 to 2.0.1.
    - [Commits](indutny/node-ip@v2.0.0...v2.0.1)
    
    ---
    updated-dependencies:
    - dependency-name: ip
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Feb 20, 2024
    Copy the full SHA
    88409e5 View commit details
  6. Bump ip from 2.0.0 to 2.0.1 in /sample/next-app (#1729)

    Bumps [ip](https://github.com/indutny/node-ip) from 2.0.0 to 2.0.1.
    - [Commits](indutny/node-ip@v2.0.0...v2.0.1)
    
    ---
    updated-dependencies:
    - dependency-name: ip
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Feb 20, 2024
    Copy the full SHA
    cdc04fc View commit details
  7. Bump ip from 2.0.0 to 2.0.1 in /sample/next-pages (#1728)

    Bumps [ip](https://github.com/indutny/node-ip) from 2.0.0 to 2.0.1.
    - [Commits](indutny/node-ip@v2.0.0...v2.0.1)
    
    ---
    updated-dependencies:
    - dependency-name: ip
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Feb 20, 2024
    Copy the full SHA
    1c3ce0a View commit details
  8. Bump ip from 2.0.0 to 2.0.1 in /sample/parcel2 (#1725)

    Bumps [ip](https://github.com/indutny/node-ip) from 2.0.0 to 2.0.1.
    - [Commits](indutny/node-ip@v2.0.0...v2.0.1)
    
    ---
    updated-dependencies:
    - dependency-name: ip
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Feb 20, 2024
    Copy the full SHA
    18b78c5 View commit details
  9. Bump ip from 2.0.0 to 2.0.1 in /sample/vite (#1730)

    Bumps [ip](https://github.com/indutny/node-ip) from 2.0.0 to 2.0.1.
    - [Commits](indutny/node-ip@v2.0.0...v2.0.1)
    
    ---
    updated-dependencies:
    - dependency-name: ip
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Feb 20, 2024
    Copy the full SHA
    3b6a290 View commit details
  10. Bump ip from 2.0.0 to 2.0.1 in /sample/webpack5 (#1727)

    Bumps [ip](https://github.com/indutny/node-ip) from 2.0.0 to 2.0.1.
    - [Commits](indutny/node-ip@v2.0.0...v2.0.1)
    
    ---
    updated-dependencies:
    - dependency-name: ip
      dependency-type: indirect
    ...
    
    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    dependabot[bot] authored Feb 20, 2024
    Copy the full SHA
    95b240d View commit details

Commits on Feb 21, 2024

  1. v7.7.1

    wojtekmaj committed Feb 21, 2024
    Copy the full SHA
    93b09c3 View commit details
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ jobs:
uses: actions/checkout@v4

- name: Cache Yarn cache
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: yarn-cache
with:
@@ -54,7 +54,7 @@ jobs:
uses: actions/checkout@v4

- name: Cache Yarn cache
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: yarn-cache
with:
@@ -89,7 +89,7 @@ jobs:
uses: actions/checkout@v4

- name: Cache Yarn cache
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: yarn-cache
with:
@@ -121,7 +121,7 @@ jobs:
uses: actions/checkout@v4

- name: Cache Yarn cache
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: yarn-cache
with:
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ jobs:
uses: actions/checkout@v4

- name: Cache Yarn cache
uses: actions/cache@v3
uses: actions/cache@v4
env:
cache-name: yarn-cache
with:
3 changes: 0 additions & 3 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged
2 changes: 1 addition & 1 deletion .yarn/plugins/@yarnpkg/plugin-nolyfill.cjs
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
module.exports = {
name: "@yarnpkg/plugin-nolyfill",
factory: function (require) {
"use strict";var plugin=(()=>{var p=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var n=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var c=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(r,e)=>(typeof require<"u"?require:r)[e]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw new Error('Dynamic require of "'+t+'" is not supported')});var l=(t,r)=>{for(var e in r)p(t,e,{get:r[e],enumerable:!0})},g=(t,r,e,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of n(r))!y.call(t,a)&&a!==e&&p(t,a,{get:()=>r[a],enumerable:!(s=i(r,a))||s.enumerable});return t};var f=t=>g(p({},"__esModule",{value:!0}),t);var b={};l(b,{default:()=>u});var o=c("@yarnpkg/core"),d=["array-buffer-byte-length","array-includes","array.from","array.of","array.prototype.at","array.prototype.every","array.prototype.find","array.prototype.findlast","array.prototype.findlastindex","array.prototype.flat","array.prototype.flatmap","array.prototype.flatmap","array.prototype.foreach","array.prototype.reduce","array.prototype.tosorted","arraybuffer.prototype.slice","assert","asynciterator.prototype","available-typed-arrays","deep-equal","define-properties","es-aggregate-error","es-iterator-helpers","es-set-tostringtag","es6-object-assign","function-bind","function.prototype.name","get-symbol-description","globalthis","gopd","harmony-reflect","has","has-property-descriptors","has-proto","has-symbols","has-tostringtag","hasown","internal-slot","is-arguments","is-array-buffer","is-date-object","is-generator-function","is-nan","is-regex","is-shared-array-buffer","is-string","is-symbol","is-typed-array","is-weakref","isarray","iterator.prototype","jsonify","object-is","object-keys","object.assign","object.entries","object.fromentries","object.getownpropertydescriptors","object.groupby","object.hasown","object.values","promise.allsettled","promise.any","reflect.getprototypeof","reflect.ownkeys","regexp.prototype.flags","safe-array-concat","safe-regex-test","set-function-length","side-channel","string.prototype.at","string.prototype.codepointat","string.prototype.includes","string.prototype.matchall","string.prototype.padend","string.prototype.padstart","string.prototype.repeat","string.prototype.replaceall","string.prototype.split","string.prototype.startswith","string.prototype.trim","string.prototype.trimend","string.prototype.trimleft","string.prototype.trimright","string.prototype.trimstart","typed-array-buffer","typed-array-byte-length","typed-array-byte-offset","typed-array-length","typedarray","unbox-primitive","which-boxed-primitive","which-typed-array"],h=new Map(d.map(t=>[o.structUtils.makeIdent(null,t).identHash,o.structUtils.makeIdent("nolyfill",t)])),m={hooks:{reduceDependency:async t=>{let r=h.get(t.identHash);if(r){let e=o.structUtils.makeDescriptor(r,"latest"),s=o.structUtils.makeRange({protocol:"npm:",source:null,selector:o.structUtils.stringifyDescriptor(e),params:null});return o.structUtils.makeDescriptor(t,s)}return t}}},u=m;return f(b);})();
"use strict";var plugin=(()=>{var p=Object.defineProperty;var i=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var n=Object.prototype.hasOwnProperty;var l=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(r,e)=>(typeof require<"u"?require:r)[e]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw new Error('Dynamic require of "'+t+'" is not supported')});var c=(t,r)=>{for(var e in r)p(t,e,{get:r[e],enumerable:!0})},g=(t,r,e,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of y(r))!n.call(t,a)&&a!==e&&p(t,a,{get:()=>r[a],enumerable:!(s=i(r,a))||s.enumerable});return t};var f=t=>g(p({},"__esModule",{value:!0}),t);var u={};c(u,{default:()=>m});var o=l("@yarnpkg/core"),d=["abab","array-buffer-byte-length","array-includes","array.from","array.of","array.prototype.at","array.prototype.every","array.prototype.find","array.prototype.findlast","array.prototype.findlastindex","array.prototype.flat","array.prototype.flatmap","array.prototype.flatmap","array.prototype.foreach","array.prototype.reduce","array.prototype.toreversed","array.prototype.tosorted","arraybuffer.prototype.slice","assert","asynciterator.prototype","available-typed-arrays","deep-equal","define-properties","es-aggregate-error","es-iterator-helpers","es-set-tostringtag","es6-object-assign","function-bind","function.prototype.name","get-symbol-description","globalthis","gopd","harmony-reflect","has","has-property-descriptors","has-proto","has-symbols","has-tostringtag","hasown","internal-slot","is-arguments","is-array-buffer","is-date-object","is-generator-function","is-nan","is-regex","is-shared-array-buffer","is-string","is-symbol","is-typed-array","is-weakref","isarray","iterator.prototype","jsonify","object-is","object-keys","object.assign","object.entries","object.fromentries","object.getownpropertydescriptors","object.groupby","object.hasown","object.values","promise.allsettled","promise.any","reflect.getprototypeof","reflect.ownkeys","regexp.prototype.flags","safe-array-concat","safe-regex-test","set-function-length","side-channel","string.prototype.at","string.prototype.codepointat","string.prototype.includes","string.prototype.matchall","string.prototype.padend","string.prototype.padstart","string.prototype.repeat","string.prototype.replaceall","string.prototype.split","string.prototype.startswith","string.prototype.trim","string.prototype.trimend","string.prototype.trimleft","string.prototype.trimright","string.prototype.trimstart","typed-array-buffer","typed-array-byte-length","typed-array-byte-offset","typed-array-length","typedarray","unbox-primitive","util.promisify","which-boxed-primitive","which-typed-array"],h=new Map(d.map(t=>[o.structUtils.makeIdent(null,t).identHash,o.structUtils.makeIdent("nolyfill",t)])),b={hooks:{reduceDependency:async t=>{let r=h.get(t.identHash);if(r){let e=o.structUtils.makeDescriptor(r,"latest"),s=o.structUtils.makeRange({protocol:"npm:",source:null,selector:o.structUtils.stringifyDescriptor(e),params:null});return o.structUtils.makeDescriptor(t,s)}return t}}},m=b;return f(u);})();
return plugin;
}
};
4 changes: 2 additions & 2 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -5,6 +5,6 @@ logFilters:
nodeLinker: node-modules

plugins:
- checksum: e3ca535b4c4288976eebb726082e2e6547c43e0ba1492b3ddbb0cdadc9d61d82ff14307358da06c46a446328345a464364d6c148b2d39fccc18cf6d232291858
- checksum: 24a2171abe511205f3184779105076031ca8daefb3fecb744e3d4f3f4010785881127bfc2d73445f7f101bf200d4a5931ec75feb543e50ffbf584da53a2f62cf
path: .yarn/plugins/@yarnpkg/plugin-nolyfill.cjs
spec: 'https://raw.githubusercontent.com/wojtekmaj/yarn-plugin-nolyfill/v0.1.1/bundles/@yarnpkg/plugin-nolyfill.js'
spec: 'https://raw.githubusercontent.com/wojtekmaj/yarn-plugin-nolyfill/v0.1.3/bundles/@yarnpkg/plugin-nolyfill.js'
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -11,19 +11,19 @@
"build": "yarn workspace react-pdf build",
"dev": "yarn workspace react-pdf watch & yarn workspace test dev",
"lint": "yarn workspaces foreach --all run lint",
"postinstall": "husky install",
"postinstall": "husky",
"prettier": "yarn workspaces foreach --all run prettier",
"test": "yarn workspaces foreach --all run test",
"tsc": "yarn workspaces foreach --all run tsc",
"unit": "yarn workspaces foreach --all run unit"
},
"devDependencies": {
"husky": "^8.0.0",
"husky": "^9.0.0",
"lint-staged": "^15.0.0",
"prettier": "^3.0.0"
},
"resolutions": {
"eslint-plugin-import": "npm:eslint-plugin-i@^2.28.0"
},
"packageManager": "yarn@4.0.2"
"packageManager": "yarn@4.1.0"
}
16 changes: 13 additions & 3 deletions packages/react-pdf/README.md
Original file line number Diff line number Diff line change
@@ -241,10 +241,15 @@ Add [`vite-plugin-static-copy`](https://www.npmjs.com/package/vite-plugin-static
```diff
+import path from 'node:path';
+import { createRequire } from 'node:module';

-import { defineConfig } from 'vite';
+import { defineConfig, normalizePath } from 'vite';
+import { viteStaticCopy } from 'vite-plugin-static-copy';

+const require = createRequire(import.meta.url);
+const cMapsDir = path.join(path.dirname(require.resolve('pdfjs-dist/package.json')), 'cmaps');
+const cMapsDir = normalizePath(
+ path.join(path.dirname(require.resolve('pdfjs-dist/package.json')), 'cmaps')
+);

export default defineConfig({
plugins: [
@@ -351,10 +356,15 @@ Add [`vite-plugin-static-copy`](https://www.npmjs.com/package/vite-plugin-static
```diff
+import path from 'node:path';
+import { createRequire } from 'node:module';

-import { defineConfig } from 'vite';
+import { defineConfig, normalizePath } from 'vite';
+import { viteStaticCopy } from 'vite-plugin-static-copy';

+const require = createRequire(import.meta.url);
+const standardFontsDir = path.join(path.dirname(require.resolve('pdfjs-dist/package.json')), 'standard_fonts');
+const standardFontsDir = normalizePath(
+ path.join(path.dirname(require.resolve('pdfjs-dist/package.json')), 'standard_fonts')
+);

export default defineConfig({
plugins: [
@@ -475,7 +485,7 @@ Loads a document passed using `file` prop.

### Page

Displays a page. Should be placed inside `<Document />`. Alternatively, it can have `pdf` prop passed, which can be obtained from `<Document />`'s `onLoadSuccess` callback function, however some advanced functions like linking between pages inside a document may not be working correctly.
Displays a page. Should be placed inside `<Document />`. Alternatively, it can have `pdf` prop passed, which can be obtained from `<Document />`'s `onLoadSuccess` callback function, however some advanced functions like rendering annotations and linking between pages inside a document may not be working correctly.

#### Props

8 changes: 4 additions & 4 deletions packages/react-pdf/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-pdf",
"version": "7.7.0",
"version": "7.7.1",
"description": "Display PDFs in your React app as easily as if they were images.",
"type": "module",
"sideEffects": [
@@ -74,9 +74,9 @@
"@types/warning": "^3.0.0",
"canvas": "^2.11.2",
"cpy-cli": "^5.0.0",
"eslint": "^8.26.0",
"eslint-config-wojtekmaj": "^0.9.0",
"jsdom": "^21.1.0",
"eslint": "^8.56.0",
"eslint-config-wojtekmaj": "^0.11.0",
"jsdom": "^24.0.0",
"nodemon": "^3.0.0",
"prettier": "^3.0.0",
"react": "^18.2.0",
14 changes: 12 additions & 2 deletions packages/react-pdf/src/Outline.spec.tsx
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ describe('Outline', () => {
});

describe('loading', () => {
it('loads an outline and calls onLoadSuccess callback properly', async () => {
it('loads an outline and calls onLoadSuccess callback properly when placed inside Document', async () => {
const { func: onLoadSuccess, promise: onLoadSuccessPromise } = makeAsyncCallback();

renderWithContext(<Outline onLoadSuccess={onLoadSuccess} />, { pdf });
@@ -68,6 +68,16 @@ describe('Outline', () => {
await expect(onLoadSuccessPromise).resolves.toMatchObject([desiredLoadedOutline]);
});

it('loads an outline and calls onLoadSuccess callback properly when pdf prop is passed', async () => {
const { func: onLoadSuccess, promise: onLoadSuccessPromise } = makeAsyncCallback();

render(<Outline onLoadSuccess={onLoadSuccess} pdf={pdf} />);

expect.assertions(1);

await expect(onLoadSuccessPromise).resolves.toMatchObject([desiredLoadedOutline]);
});

it('calls onLoadError when failed to load an outline', async () => {
const { func: onLoadError, promise: onLoadErrorPromise } = makeAsyncCallback();

@@ -99,7 +109,7 @@ describe('Outline', () => {
await expect(onLoadSuccessPromise2).resolves.toMatchObject([desiredLoadedOutline2]);
});

it('throws an error when placed outside Document', () => {
it('throws an error when placed outside Document without pdf prop passed', () => {
muteConsole();

expect(() => render(<Outline />)).toThrow();
16 changes: 9 additions & 7 deletions packages/react-pdf/src/Outline.tsx
Original file line number Diff line number Diff line change
@@ -69,11 +69,6 @@ export type OutlineProps = {
const Outline: React.FC<OutlineProps> = function Outline(props) {
const documentContext = useDocumentContext();

invariant(
documentContext,
'Unable to find Document context. Did you wrap <Outline /> in <Document />?',
);

const mergedProps = { ...documentContext, ...props };
const {
className,
@@ -85,7 +80,10 @@ const Outline: React.FC<OutlineProps> = function Outline(props) {
...otherProps
} = mergedProps;

invariant(pdf, 'Attempted to load an outline, but no document was specified.');
invariant(
pdf,
'Attempted to load an outline, but no document was specified. Wrap <Outline /> in a <Document /> or pass explicit `pdf` prop.',
);

const [outlineState, outlineDispatch] = useResolver<PDFOutline | null>();
const { value: outline, error: outlineError } = outlineState;
@@ -189,7 +187,11 @@ const Outline: React.FC<OutlineProps> = function Outline(props) {
return (
<ul>
{outline.map((item, itemIndex) => (
<OutlineItem key={typeof item.dest === 'string' ? item.dest : itemIndex} item={item} />
<OutlineItem
key={typeof item.dest === 'string' ? item.dest : itemIndex}
item={item}
pdf={pdf}
/>
))}
</ul>
);
19 changes: 12 additions & 7 deletions packages/react-pdf/src/OutlineItem.tsx
Original file line number Diff line number Diff line change
@@ -16,24 +16,23 @@ type PDFOutlineItem = PDFOutline[number];

type OutlineItemProps = {
item: PDFOutlineItem;
pdf?: PDFDocumentProxy | false;
};

export default function OutlineItem(props: OutlineItemProps) {
const documentContext = useDocumentContext();

invariant(
documentContext,
'Unable to find Document context. Did you wrap <Outline /> in <Document />?',
);

const outlineContext = useOutlineContext();

invariant(outlineContext, 'Unable to find Outline context.');

const mergedProps = { ...documentContext, ...outlineContext, ...props };
const { item, linkService, onItemClick, pdf, ...otherProps } = mergedProps;

invariant(pdf, 'Attempted to load an outline, but no document was specified.');
invariant(
pdf,
'Attempted to load an outline, but no document was specified. Wrap <Outline /> in a <Document /> or pass explicit `pdf` prop.',
);

const getDestination = useCachedValue(() => {
if (typeof item.dest === 'string') {
@@ -64,6 +63,11 @@ export default function OutlineItem(props: OutlineItemProps) {
function onClick(event: React.MouseEvent<HTMLAnchorElement>) {
event.preventDefault();

invariant(
onItemClick || linkService,
'Either onItemClick callback or linkService must be defined in order to navigate to an outline item.',
);

if (onItemClick) {
Promise.all([getDestination(), getPageIndex(), getPageNumber()]).then(
([dest, pageIndex, pageNumber]) => {
@@ -74,7 +78,7 @@ export default function OutlineItem(props: OutlineItemProps) {
});
},
);
} else {
} else if (linkService) {
linkService.goToDestination(item.dest);
}
}
@@ -92,6 +96,7 @@ export default function OutlineItem(props: OutlineItemProps) {
<OutlineItem
key={typeof subitem.dest === 'string' ? subitem.dest : subitemIndex}
item={subitem}
pdf={pdf}
{...otherProps}
/>
))}
Loading