Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-pdf-js

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-pdf-js - npm Package Compare versions

Comparing version 1.0.24 to 1.0.25

README.md

60

lib/Pdf.js

@@ -39,2 +39,6 @@ 'use strict';

var _promise = require('babel-runtime/core-js/promise');
var _promise2 = _interopRequireDefault(_promise);
var _react = require('react');

@@ -49,2 +53,22 @@

var makeCancelable = function makeCancelable(promise) {
var hasCanceled = false;
var wrappedPromise = new _promise2.default(function (resolve, reject) {
promise.then(function (val) {
return hasCanceled ? reject({ pdf: val, isCanceled: true }) : resolve(val);
});
promise.catch(function (error) {
return hasCanceled ? reject({ isCanceled: true }) : reject(error);
});
});
return {
promise: wrappedPromise,
cancel: function cancel() {
hasCanceled = true;
}
};
};
var Pdf = function (_React$Component) {

@@ -77,2 +101,8 @@ (0, _inherits3.default)(Pdf, _React$Component);

_this.getDocument = _this.getDocument.bind(_this);
if (!(typeof _this.getDocument === 'function')) {
throw new TypeError('Value of "this.getDocument" violates contract.\n\nExpected:\n(any) => any\n\nGot:\n' + _inspect(_this.getDocument));
}
return _this;

@@ -118,3 +148,8 @@ }

pdf.destroy();
if (pdf) {
pdf.destroy();
}
if (this.documentPromise) {
this.documentPromise.cancel();
}
}

@@ -158,2 +193,9 @@ }, {

}, {
key: 'onDocumentError',
value: function onDocumentError(err) {
if (err.isCanceled && err.pdf) {
err.pdf.destroy();
}
}
}, {
key: 'onPageComplete',

@@ -170,5 +212,15 @@ value: function onPageComplete(page) {

}, {
key: 'getDocument',
value: function getDocument(val) {
if (this.documentPromise) {
this.documentPromise.cancel();
}
this.documentPromise = makeCancelable(window.PDFJS.getDocument(val).promise);
this.documentPromise.promise.then(this.onDocumentComplete).catch(this.onDocumentError);
return this.documentPromise;
}
}, {
key: 'loadByteArray',
value: function loadByteArray(byteArray) {
window.PDFJS.getDocument(byteArray).then(this.onDocumentComplete);
this.getDocument(byteArray);
}

@@ -184,3 +236,3 @@ }, {

return {
v: window.PDFJS.getDocument(props.file).then(_this2.onDocumentComplete)
v: _this2.getDocument(props.file)
};

@@ -208,3 +260,3 @@ }

} else if (!!props.documentInitParameters) {
return window.PDFJS.getDocument(props.documentInitParameters).then(this.onDocumentComplete);
return this.getDocument(props.documentInitParameters);
} else {

@@ -211,0 +263,0 @@ throw new Error('react-pdf-js works with a file(URL) or (base64)content. At least one needs to be provided!');

16

package.json
{
"name": "react-pdf-js",
"version": "1.0.24",
"version": "1.0.25",
"description": "A React component to wrap PDF.js",

@@ -33,8 +33,8 @@ "main": "./lib/index.js",

"dependencies": {
"pdfjs-dist": "1.5.326"
"pdfjs-dist": "1.5.361"
},
"devDependencies": {
"babel-cli": "6.10.1",
"babel-core": "6.10.4",
"babel-eslint": "6.1.1",
"babel-cli": "6.11.4",
"babel-core": "6.11.4",
"babel-eslint": "6.1.2",
"babel-loader": "6.2.4",

@@ -46,6 +46,6 @@ "babel-plugin-react-transform": "2.0.2",

"babel-preset-react": "6.11.1",
"babel-runtime": "6.9.2",
"babel-runtime": "6.11.6",
"eslint": "2.13.1",
"eslint-config-airbnb": "9.0.1",
"eslint-plugin-import": "1.10.2",
"eslint-plugin-import": "1.12.0",
"eslint-plugin-react": "5.2.2",

@@ -55,3 +55,3 @@ "eslint-plugin-jsx-a11y": "1.5.5",

"rifraf": "2.0.2",
"rimraf": "2.5.3",
"rimraf": "2.5.4",
"webpack": "1.13.1"

@@ -58,0 +58,0 @@ },

@@ -5,2 +5,22 @@ import React from 'react';

const makeCancelable = (promise) => {
let hasCanceled = false;
const wrappedPromise = new Promise((resolve, reject) => {
promise.then((val) => (
hasCanceled ? reject({ pdf: val, isCanceled: true }) : resolve(val)
));
promise.catch((error) => (
hasCanceled ? reject({ isCanceled: true }) : reject(error)
));
});
return {
promise: wrappedPromise,
cancel() {
hasCanceled = true;
},
};
};
class Pdf extends React.Component {

@@ -13,2 +33,3 @@ constructor(props) {

this.onPageComplete = this.onPageComplete.bind(this);
this.getDocument = this.getDocument.bind(this);
}

@@ -52,3 +73,8 @@

const { pdf } = this.state;
pdf.destroy();
if (pdf) {
pdf.destroy();
}
if (this.documentPromise) {
this.documentPromise.cancel();
}
}

@@ -82,2 +108,8 @@

onDocumentError(err) {
if (err.isCanceled && err.pdf) {
err.pdf.destroy();
}
}
onPageComplete(page) {

@@ -92,4 +124,17 @@ this.setState({ page });

getDocument(val) {
if (this.documentPromise) {
this.documentPromise.cancel();
}
this.documentPromise = makeCancelable(window.PDFJS.getDocument(val).promise);
this.documentPromise
.promise
.then(this.onDocumentComplete)
.catch(this.onDocumentError);
return this.documentPromise;
}
loadByteArray(byteArray) {
window.PDFJS.getDocument(byteArray).then(this.onDocumentComplete);
this.getDocument(byteArray);
}

@@ -100,4 +145,3 @@

if (typeof props.file === 'string') {
return window.PDFJS.getDocument(props.file)
.then(this.onDocumentComplete);
return this.getDocument(props.file);
}

@@ -120,4 +164,3 @@ // Is a File object

} else if (!!props.documentInitParameters) {
return window.PDFJS.getDocument(props.documentInitParameters)
.then(this.onDocumentComplete);
return this.getDocument(props.documentInitParameters);
} else {

@@ -124,0 +167,0 @@ throw new Error('react-pdf-js works with a file(URL) or (base64)content. At least one needs to be provided!');

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc