Skip to content

Commit df990a7

Browse files
committed
Improve isFile propType
1 parent a645946 commit df990a7

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

src/shared/propTypes.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import PropTypes from 'prop-types';
22
import { mouseEvents, touchEvents, keyboardEvents } from 'make-event-props';
3+
import { PDFDataRangeTransport } from 'pdfjs-dist';
34

45
import { isDefined } from './utils';
56

@@ -15,13 +16,34 @@ export const eventProps = (() => {
1516
return result;
1617
})();
1718

19+
const isTypedArray = PropTypes.oneOfType([
20+
PropTypes.instanceOf(Int8Array),
21+
PropTypes.instanceOf(Uint8Array),
22+
PropTypes.instanceOf(Uint8ClampedArray),
23+
PropTypes.instanceOf(Int16Array),
24+
PropTypes.instanceOf(Uint16Array),
25+
PropTypes.instanceOf(Int32Array),
26+
PropTypes.instanceOf(Uint32Array),
27+
PropTypes.instanceOf(Float32Array),
28+
PropTypes.instanceOf(Float64Array),
29+
]);
30+
1831
const fileTypes = [
1932
PropTypes.string,
2033
PropTypes.instanceOf(ArrayBuffer),
2134
PropTypes.shape({
22-
data: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
23-
range: PropTypes.object,
24-
url: PropTypes.string,
35+
data: PropTypes.oneOfType([
36+
PropTypes.string,
37+
PropTypes.instanceOf(ArrayBuffer),
38+
PropTypes.arrayOf(PropTypes.number.isRequired),
39+
isTypedArray,
40+
]).isRequired,
41+
}),
42+
PropTypes.shape({
43+
range: PropTypes.instanceOf(PDFDataRangeTransport).isRequired,
44+
}),
45+
PropTypes.shape({
46+
url: PropTypes.string.isRequired,
2547
}),
2648
];
2749
if (typeof Blob !== 'undefined') {

test/shared/propTypes.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11
import PropTypes from 'prop-types';
2+
import { PDFDataRangeTransport } from 'pdfjs-dist';
3+
4+
const isTypedArray = PropTypes.oneOfType([
5+
PropTypes.instanceOf(Int8Array),
6+
PropTypes.instanceOf(Uint8Array),
7+
PropTypes.instanceOf(Uint8ClampedArray),
8+
PropTypes.instanceOf(Int16Array),
9+
PropTypes.instanceOf(Uint16Array),
10+
PropTypes.instanceOf(Int32Array),
11+
PropTypes.instanceOf(Uint32Array),
12+
PropTypes.instanceOf(Float32Array),
13+
PropTypes.instanceOf(Float64Array),
14+
]);
215

316
const fileTypes = [
417
PropTypes.string,
518
PropTypes.instanceOf(ArrayBuffer),
619
PropTypes.shape({
7-
data: PropTypes.object,
8-
range: PropTypes.object,
9-
url: PropTypes.string,
20+
data: PropTypes.oneOfType([
21+
PropTypes.string,
22+
PropTypes.instanceOf(ArrayBuffer),
23+
PropTypes.arrayOf(PropTypes.number.isRequired),
24+
isTypedArray,
25+
]).isRequired,
26+
}),
27+
PropTypes.shape({
28+
range: PropTypes.instanceOf(PDFDataRangeTransport).isRequired,
29+
}),
30+
PropTypes.shape({
31+
url: PropTypes.string.isRequired,
1032
}),
1133
];
1234
if (typeof Blob !== 'undefined') {

0 commit comments

Comments
 (0)