Remove propTypes

This commit is contained in:
Wojciech Maj
2024-04-26 13:29:10 +02:00
parent 6e58540b5a
commit 46b47cd4d0
8 changed files with 2 additions and 289 deletions
-1
View File
@@ -61,7 +61,6 @@
"make-event-props": "^1.6.0",
"merge-refs": "^1.2.1",
"pdfjs-dist": "3.11.174",
"prop-types": "^15.6.2",
"tiny-invariant": "^1.0.0",
"warning": "^4.0.0"
},
-1
View File
@@ -18,7 +18,6 @@ const pdfFile2 = loadPDF('./../../__mocks__/_pdf2.pdf');
const OK = Symbol('OK');
// eslint-disable-next-line react/prop-types
function ChildInternal({
renderMode,
rotate,
-58
View File
@@ -1,7 +1,6 @@
'use client';
import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef } from 'react';
import PropTypes from 'prop-types';
import makeEventProps from 'make-event-props';
import makeCancellable from 'make-cancellable-promise';
import clsx from 'clsx';
@@ -29,7 +28,6 @@ import {
} from './shared/utils.js';
import useResolver from './shared/hooks/useResolver.js';
import { eventProps, isClassName, isFile, isRef } from './shared/propTypes.js';
import type { PDFDocumentProxy } from 'pdfjs-dist';
import type { EventProps } from 'make-event-props';
@@ -635,60 +633,4 @@ const Document = forwardRef(function Document(
);
});
const isFunctionOrNode = PropTypes.oneOfType([PropTypes.func, PropTypes.node]);
Document.propTypes = {
...eventProps,
children: PropTypes.node,
className: isClassName,
error: isFunctionOrNode,
externalLinkRel: PropTypes.string,
externalLinkTarget: PropTypes.oneOf(['_self', '_blank', '_parent', '_top'] as const),
file: isFile,
imageResourcesPath: PropTypes.string,
inputRef: isRef,
loading: isFunctionOrNode,
noData: isFunctionOrNode,
onItemClick: PropTypes.func,
onLoadError: PropTypes.func,
onLoadProgress: PropTypes.func,
onLoadSuccess: PropTypes.func,
onPassword: PropTypes.func,
onSourceError: PropTypes.func,
onSourceSuccess: PropTypes.func,
options: PropTypes.shape({
canvasFactory: PropTypes.any,
canvasMaxAreaInBytes: PropTypes.number,
cMapPacked: PropTypes.bool,
CMapReaderFactory: PropTypes.any,
cMapUrl: PropTypes.string,
disableAutoFetch: PropTypes.bool,
disableFontFace: PropTypes.bool,
disableRange: PropTypes.bool,
disableStream: PropTypes.bool,
docBaseUrl: PropTypes.string,
enableXfa: PropTypes.bool,
filterFactory: PropTypes.any,
fontExtraProperties: PropTypes.bool,
httpHeaders: PropTypes.object,
isEvalSupported: PropTypes.bool,
isOffscreenCanvasSupported: PropTypes.bool,
length: PropTypes.number,
maxImageSize: PropTypes.number,
ownerDocument: PropTypes.any,
password: PropTypes.string,
pdfBug: PropTypes.bool,
rangeChunkSize: PropTypes.number,
StandardFontDataFactory: PropTypes.any,
standardFontDataUrl: PropTypes.string,
stopAtErrors: PropTypes.bool,
useSystemFonts: PropTypes.bool,
useWorkerFetch: PropTypes.bool,
verbosity: PropTypes.number,
withCredentials: PropTypes.bool,
worker: PropTypes.any,
}),
rotate: PropTypes.number,
};
export default Document;
-12
View File
@@ -1,7 +1,6 @@
'use client';
import { useEffect, useMemo } from 'react';
import PropTypes from 'prop-types';
import makeCancellable from 'make-cancellable-promise';
import makeEventProps from 'make-event-props';
import clsx from 'clsx';
@@ -16,7 +15,6 @@ import { cancelRunningTask } from './shared/utils.js';
import useDocumentContext from './shared/hooks/useDocumentContext.js';
import useResolver from './shared/hooks/useResolver.js';
import { eventProps, isClassName, isPdf, isRef } from './shared/propTypes.js';
import type { PDFDocumentProxy } from 'pdfjs-dist';
import type { EventProps } from 'make-event-props';
@@ -204,14 +202,4 @@ const Outline: React.FC<OutlineProps> = function Outline(props) {
);
};
Outline.propTypes = {
...eventProps,
className: isClassName,
inputRef: isRef,
onItemClick: PropTypes.func,
onLoadError: PropTypes.func,
onLoadSuccess: PropTypes.func,
pdf: isPdf,
};
export default Outline;
-48
View File
@@ -1,7 +1,6 @@
'use client';
import { useEffect, useMemo, useRef } from 'react';
import PropTypes from 'prop-types';
import makeCancellable from 'make-cancellable-promise';
import makeEventProps from 'make-event-props';
import clsx from 'clsx';
@@ -21,16 +20,6 @@ import { cancelRunningTask, isProvided, makePageCallback } from './shared/utils.
import useDocumentContext from './shared/hooks/useDocumentContext.js';
import useResolver from './shared/hooks/useResolver.js';
import {
eventProps,
isClassName,
isPageIndex,
isPageNumber,
isPdf,
isRef,
isRenderMode,
isRotate,
} from './shared/propTypes.js';
import type { PDFDocumentProxy, PDFPageProxy } from 'pdfjs-dist';
import type { EventProps } from 'make-event-props';
@@ -657,41 +646,4 @@ const Page: React.FC<PageProps> = function Page(props) {
);
};
const isFunctionOrNode = PropTypes.oneOfType([PropTypes.func, PropTypes.node]);
Page.propTypes = {
...eventProps,
canvasBackground: PropTypes.string,
canvasRef: isRef,
children: PropTypes.node,
className: isClassName,
customRenderer: PropTypes.func,
customTextRenderer: PropTypes.func,
devicePixelRatio: PropTypes.number,
error: isFunctionOrNode,
height: PropTypes.number,
imageResourcesPath: PropTypes.string,
inputRef: isRef,
loading: isFunctionOrNode,
noData: isFunctionOrNode,
onGetTextError: PropTypes.func,
onGetTextSuccess: PropTypes.func,
onLoadError: PropTypes.func,
onLoadSuccess: PropTypes.func,
onRenderError: PropTypes.func,
onRenderSuccess: PropTypes.func,
onRenderTextLayerError: PropTypes.func,
onRenderTextLayerSuccess: PropTypes.func,
pageIndex: isPageIndex,
pageNumber: isPageNumber,
pdf: isPdf,
renderAnnotationLayer: PropTypes.bool,
renderForms: PropTypes.bool,
renderMode: isRenderMode,
renderTextLayer: PropTypes.bool,
rotate: isRotate,
scale: PropTypes.number,
width: PropTypes.number,
};
export default Page;
+1
View File
@@ -92,6 +92,7 @@ const Thumbnail: React.FC<ThumbnailProps> = function Thumbnail(props) {
}
}
// eslint-disable-next-line react/prop-types
const { className: classNameProps, onItemClick: onItemClickProps, ...pageProps } = props;
return (
-167
View File
@@ -1,167 +0,0 @@
import PropTypes from 'prop-types';
import { allEvents } from 'make-event-props';
import pdfjs from '../pdfjs.js';
import { isDefined } from './utils.js';
import LinkService from '../LinkService.js';
import type { Validator } from 'prop-types';
const { PDFDataRangeTransport } = pdfjs;
type AllEvents = (typeof allEvents)[number];
type Props = {
[K in AllEvents]?: typeof PropTypes.func;
};
export const eventProps: Props = (() => {
const result: Props = {};
allEvents.forEach((eventName) => {
result[eventName] = PropTypes.func;
});
return result;
})();
const isTypedArray = PropTypes.oneOfType([
PropTypes.instanceOf(Int8Array),
PropTypes.instanceOf(Uint8Array),
PropTypes.instanceOf(Uint8ClampedArray),
PropTypes.instanceOf(Int16Array),
PropTypes.instanceOf(Uint16Array),
PropTypes.instanceOf(Int32Array),
PropTypes.instanceOf(Uint32Array),
PropTypes.instanceOf(Float32Array),
PropTypes.instanceOf(Float64Array),
]);
const fileTypes = [
PropTypes.string,
PropTypes.instanceOf(ArrayBuffer),
PropTypes.shape({
data: PropTypes.oneOfType([
PropTypes.string,
PropTypes.instanceOf(ArrayBuffer),
PropTypes.arrayOf(PropTypes.number.isRequired),
isTypedArray,
]).isRequired,
}),
PropTypes.shape({
range: PropTypes.instanceOf(PDFDataRangeTransport).isRequired,
}),
PropTypes.shape({
url: PropTypes.string.isRequired,
}),
];
if (typeof Blob !== 'undefined') {
(fileTypes as PropTypes.Validator<unknown>[]).push(PropTypes.instanceOf(Blob));
}
export const isClassName = PropTypes.oneOfType([
PropTypes.string,
PropTypes.arrayOf(PropTypes.string),
]);
export const isFile = PropTypes.oneOfType(fileTypes);
export const isLinkService = PropTypes.instanceOf(LinkService);
export const isLinkTarget = PropTypes.oneOf(['_self', '_blank', '_parent', '_top'] as const);
export const isPage = PropTypes.shape({
commonObjs: PropTypes.shape({}).isRequired,
getAnnotations: PropTypes.func.isRequired,
getTextContent: PropTypes.func.isRequired,
getViewport: PropTypes.func.isRequired,
render: PropTypes.func.isRequired,
});
export const isPageIndex: Validator<number> = function isPageIndex(props, propName, componentName) {
const { [propName]: pageIndex, pageNumber, pdf } = props;
if (!isDefined(pdf)) {
return null;
}
if (isDefined(pageIndex)) {
if (typeof pageIndex !== 'number') {
return new Error(
`\`${propName}\` of type \`${typeof pageIndex}\` supplied to \`${componentName}\`, expected \`number\`.`,
);
}
if (pageIndex < 0) {
return new Error(`Expected \`${propName}\` to be greater or equal to 0.`);
}
const { numPages } = pdf;
if (pageIndex + 1 > numPages) {
return new Error(`Expected \`${propName}\` to be less or equal to ${numPages - 1}.`);
}
} else if (!isDefined(pageNumber)) {
return new Error(
`\`${propName}\` not supplied. Either pageIndex or pageNumber must be supplied to \`${componentName}\`.`,
);
}
// Everything is fine
return null;
};
export const isPageNumber: Validator<number> = function isPageNumber(
props,
propName,
componentName,
) {
const { [propName]: pageNumber, pageIndex, pdf } = props;
if (!isDefined(pdf)) {
return null;
}
if (isDefined(pageNumber)) {
if (typeof pageNumber !== 'number') {
return new Error(
`\`${propName}\` of type \`${typeof pageNumber}\` supplied to \`${componentName}\`, expected \`number\`.`,
);
}
if (pageNumber < 1) {
return new Error(`Expected \`${propName}\` to be greater or equal to 1.`);
}
const { numPages } = pdf;
if (pageNumber > numPages) {
return new Error(`Expected \`${propName}\` to be less or equal to ${numPages}.`);
}
} else if (!isDefined(pageIndex)) {
return new Error(
`\`${propName}\` not supplied. Either pageIndex or pageNumber must be supplied to \`${componentName}\`.`,
);
}
// Everything is fine
return null;
};
export const isPdf = PropTypes.oneOfType([
// Ideally, this would be `PropTypes.instanceOf(PDFDocumentProxy)`, but it can't be imported.
PropTypes.any,
PropTypes.oneOf([false] as const),
]);
export const isRef = PropTypes.oneOfType([
PropTypes.func,
PropTypes.exact({
current: PropTypes.any,
}),
]);
export const isRenderMode = PropTypes.oneOf(['canvas', 'custom', 'none', 'svg'] as const);
export const isRotate = PropTypes.oneOf([0, 90, 180, 270] as const);
+1 -2
View File
@@ -4402,7 +4402,7 @@ __metadata:
languageName: node
linkType: hard
"prop-types@npm:^15.6.2, prop-types@npm:^15.8.1":
"prop-types@npm:^15.8.1":
version: 15.8.1
resolution: "prop-types@npm:15.8.1"
dependencies:
@@ -4521,7 +4521,6 @@ __metadata:
nodemon: "npm:^3.0.0"
pdfjs-dist: "npm:3.11.174"
prettier: "npm:^3.2.0"
prop-types: "npm:^15.6.2"
react: "npm:^18.2.0"
react-dom: "npm:^18.2.0"
rimraf: "npm:^3.0.0"