From 863e441558154d776cf0c9b53a1e6cc5d317caf5 Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Fri, 26 Apr 2024 13:29:10 +0200 Subject: [PATCH] Remove propTypes --- packages/react-pdf/package.json | 1 - packages/react-pdf/src/Document.spec.tsx | 1 - packages/react-pdf/src/Document.tsx | 58 ------- packages/react-pdf/src/Outline.tsx | 12 -- packages/react-pdf/src/Page.tsx | 48 ------ packages/react-pdf/src/Thumbnail.tsx | 1 + packages/react-pdf/src/shared/propTypes.ts | 167 --------------------- yarn.lock | 3 +- 8 files changed, 2 insertions(+), 289 deletions(-) delete mode 100644 packages/react-pdf/src/shared/propTypes.ts diff --git a/packages/react-pdf/package.json b/packages/react-pdf/package.json index 8fc9326e6..9bf544575 100644 --- a/packages/react-pdf/package.json +++ b/packages/react-pdf/package.json @@ -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" }, diff --git a/packages/react-pdf/src/Document.spec.tsx b/packages/react-pdf/src/Document.spec.tsx index 4b397de6c..b6c5539d2 100644 --- a/packages/react-pdf/src/Document.spec.tsx +++ b/packages/react-pdf/src/Document.spec.tsx @@ -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, diff --git a/packages/react-pdf/src/Document.tsx b/packages/react-pdf/src/Document.tsx index 6cd7e22ba..107294fbc 100644 --- a/packages/react-pdf/src/Document.tsx +++ b/packages/react-pdf/src/Document.tsx @@ -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; diff --git a/packages/react-pdf/src/Outline.tsx b/packages/react-pdf/src/Outline.tsx index 47be1a466..9f20dccb6 100644 --- a/packages/react-pdf/src/Outline.tsx +++ b/packages/react-pdf/src/Outline.tsx @@ -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 = function Outline(props) { ); }; -Outline.propTypes = { - ...eventProps, - className: isClassName, - inputRef: isRef, - onItemClick: PropTypes.func, - onLoadError: PropTypes.func, - onLoadSuccess: PropTypes.func, - pdf: isPdf, -}; - export default Outline; diff --git a/packages/react-pdf/src/Page.tsx b/packages/react-pdf/src/Page.tsx index fb221ae62..4c0921f43 100644 --- a/packages/react-pdf/src/Page.tsx +++ b/packages/react-pdf/src/Page.tsx @@ -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 = 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; diff --git a/packages/react-pdf/src/Thumbnail.tsx b/packages/react-pdf/src/Thumbnail.tsx index 3e7918776..45831989b 100644 --- a/packages/react-pdf/src/Thumbnail.tsx +++ b/packages/react-pdf/src/Thumbnail.tsx @@ -92,6 +92,7 @@ const Thumbnail: React.FC = function Thumbnail(props) { } } + // eslint-disable-next-line react/prop-types const { className: classNameProps, onItemClick: onItemClickProps, ...pageProps } = props; return ( diff --git a/packages/react-pdf/src/shared/propTypes.ts b/packages/react-pdf/src/shared/propTypes.ts deleted file mode 100644 index ce04485da..000000000 --- a/packages/react-pdf/src/shared/propTypes.ts +++ /dev/null @@ -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[]).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 = 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 = 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); diff --git a/yarn.lock b/yarn.lock index 4ce33a71d..0d2ddfa70 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"