diff --git a/package-lock.json b/package-lock.json index 83b8354..b3e4929 100644 --- a/package-lock.json +++ b/package-lock.json @@ -50,7 +50,6 @@ }, "peerDependencies": { "lodash": "4.x", - "prop-types": "15.x", "react": "18.x", "react-dom": "18.x" } @@ -7205,6 +7204,7 @@ "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "devOptional": true, "engines": { "node": ">=0.10.0" } @@ -7857,6 +7857,7 @@ "version": "15.8.1", "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz", "integrity": "sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==", + "dev": true, "dependencies": { "loose-envify": "^1.4.0", "object-assign": "^4.1.1", @@ -7999,7 +8000,8 @@ "node_modules/react-is": { "version": "16.13.1", "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", - "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" + "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==", + "dev": true }, "node_modules/react-pdf": { "version": "9.1.1", @@ -15345,7 +15347,8 @@ "object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==" + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "devOptional": true }, "object-inspect": { "version": "1.12.3", @@ -15798,6 +15801,7 @@ "version": "15.8.1", "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz", "integrity": "sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==", + "dev": true, "requires": { "loose-envify": "^1.4.0", "object-assign": "^4.1.1", @@ -15900,7 +15904,8 @@ "react-is": { "version": "16.13.1", "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", - "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" + "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==", + "dev": true }, "react-pdf": { "version": "9.1.1", diff --git a/package.json b/package.json index e8624e6..4e2f022 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,6 @@ }, "peerDependencies": { "lodash": "4.x", - "prop-types": "15.x", "react": "18.x", "react-dom": "18.x" }, diff --git a/src/PDFPasswordForm.tsx b/src/PDFPasswordForm.tsx index c06d0cd..f86d773 100644 --- a/src/PDFPasswordForm.tsx +++ b/src/PDFPasswordForm.tsx @@ -1,5 +1,4 @@ import React, {useState, useRef, useMemo, type ChangeEvent, type FormEventHandler} from 'react'; -import PropTypes from 'prop-types'; import {pdfPasswordFormStyles as styles} from './styles'; import {isSafari} from './helpers'; @@ -11,27 +10,6 @@ type Props = { onPasswordFieldFocus?: (isFocused: boolean) => void; }; -const propTypes = { - /** If the submitted password is invalid (show an error message) */ - isPasswordInvalid: PropTypes.bool, - - /** Notify parent that the password form has been submitted */ - onSubmit: PropTypes.func, - - /** Notify parent that the password has been updated/edited */ - onPasswordChange: PropTypes.func, - - /** Notify parent that a text field has been focused or blurred */ - onPasswordFieldFocus: PropTypes.func, -}; - -const defaultProps = { - isPasswordInvalid: false, - onSubmit: () => {}, - onPasswordChange: () => {}, - onPasswordFieldFocus: () => {}, -}; - function PDFPasswordForm({isPasswordInvalid, onSubmit, onPasswordChange, onPasswordFieldFocus}: Props) { const [password, setPassword] = useState(''); const [validationErrorText, setValidationErrorText] = useState(''); @@ -151,8 +129,6 @@ function PDFPasswordForm({isPasswordInvalid, onSubmit, onPasswordChange, onPassw ); } -PDFPasswordForm.propTypes = propTypes; -PDFPasswordForm.defaultProps = defaultProps; PDFPasswordForm.displayName = 'PDFPasswordForm'; export type {Props as PDFPasswordFormProps}; diff --git a/src/PDFPreviewer.tsx b/src/PDFPreviewer.tsx index 3197349..9b18e2a 100644 --- a/src/PDFPreviewer.tsx +++ b/src/PDFPreviewer.tsx @@ -4,7 +4,6 @@ import pdfWorkerSource from 'pdfjs-dist/legacy/build/pdf.worker.mjs'; import React, {memo, useCallback, useLayoutEffect, useRef, useState} from 'react'; import type {CSSProperties, ReactNode} from 'react'; import times from 'lodash/times'; -import PropTypes from 'prop-types'; import {VariableSizeList as List} from 'react-window'; import {Document, pdfjs} from 'react-pdf'; import 'react-pdf/dist/Page/AnnotationLayer.css'; @@ -21,9 +20,9 @@ type Props = { file: string; pageMaxWidth: number; isSmallScreen: boolean; - maxCanvasWidth: number | null; - maxCanvasHeight: number | null; - maxCanvasArea: number | null; + maxCanvasWidth?: number; + maxCanvasHeight?: number; + maxCanvasArea?: number; renderPasswordForm?: ({isPasswordInvalid, onSubmit, onPasswordChange}: Omit) => ReactNode | null; LoadingComponent?: ReactNode; ErrorComponent?: ReactNode; @@ -35,39 +34,11 @@ type Props = { type OnPasswordCallback = (password: string | null) => void; -const propTypes = { - file: PropTypes.string.isRequired, - pageMaxWidth: PropTypes.number.isRequired, - isSmallScreen: PropTypes.bool.isRequired, - maxCanvasWidth: PropTypes.number, - maxCanvasHeight: PropTypes.number, - maxCanvasArea: PropTypes.number, - renderPasswordForm: PropTypes.func, - LoadingComponent: PropTypes.node, - ErrorComponent: PropTypes.node, - shouldShowErrorComponent: PropTypes.bool, - onLoadError: PropTypes.func, - // eslint-disable-next-line react/forbid-prop-types - containerStyle: PropTypes.object, - // eslint-disable-next-line react/forbid-prop-types - contentContainerStyle: PropTypes.object, -}; - -const defaultProps = { - maxCanvasWidth: null, - maxCanvasHeight: null, - maxCanvasArea: null, - renderPasswordForm: null, - LoadingComponent:

Loading...

, - ErrorComponent:

Failed to load the PDF file :(

, - shouldShowErrorComponent: true, - containerStyle: {}, - contentContainerStyle: {}, - onLoadError: () => {}, -}; - pdfjs.GlobalWorkerOptions.workerSrc = URL.createObjectURL(new Blob([pdfWorkerSource], {type: 'text/javascript'})); +const DefaultLoadingComponent =

Loading...

; +const DefaultErrorComponent =

Failed to load the PDF file :(

; + function PDFPreviewer({ file, pageMaxWidth, @@ -75,12 +46,12 @@ function PDFPreviewer({ maxCanvasWidth, maxCanvasHeight, maxCanvasArea, - LoadingComponent, - ErrorComponent, + LoadingComponent = DefaultLoadingComponent, + ErrorComponent = DefaultErrorComponent, renderPasswordForm, containerStyle, contentContainerStyle, - shouldShowErrorComponent, + shouldShowErrorComponent = true, onLoadError, }: Props) { const [pageViewports, setPageViewports] = useState([]); @@ -285,7 +256,5 @@ function PDFPreviewer({ } PDFPasswordForm.displayName = 'PDFPreviewer'; -PDFPreviewer.propTypes = propTypes; -PDFPreviewer.defaultProps = defaultProps; export default memo(PDFPreviewer); diff --git a/src/PageRenderer.tsx b/src/PageRenderer.tsx index 262a421..237483d 100644 --- a/src/PageRenderer.tsx +++ b/src/PageRenderer.tsx @@ -1,5 +1,4 @@ import React, {memo, type CSSProperties} from 'react'; -import PropTypes from 'prop-types'; import {Page} from 'react-pdf'; import {pdfPreviewerStyles as styles} from './styles'; import {PAGE_BORDER} from './constants'; @@ -17,31 +16,6 @@ type Props = { }; }; -const propTypes = { - /** Index of the PDF page to be displayed passed by VariableSizeList */ - index: PropTypes.number.isRequired, - - /** Page extra data passed by VariableSizeList's data prop */ - data: PropTypes.shape({ - /** Width of a single page in the document */ - pageWidth: PropTypes.number.isRequired, - /** The estimated height of a single page in the document */ - estimatedPageHeight: PropTypes.number.isRequired, - /** Function that calculates the height of a page given its index */ - calculatePageHeight: PropTypes.func.isRequired, - /** Function that calculates the pixel ratio for a page given its calculated width and height */ - getDevicePixelRatio: PropTypes.func.isRequired, - /** The number of pages in the document */ - numPages: PropTypes.number.isRequired, - /** The height of the container view */ - containerHeight: PropTypes.number.isRequired, - }).isRequired, - - /** Additional style props passed by VariableSizeList */ - // eslint-disable-next-line react/forbid-prop-types - style: PropTypes.object.isRequired, -}; - function PageRenderer({index, style, data}: Props) { const {pageWidth, estimatedPageHeight, calculatePageHeight, getDevicePixelRatio, numPages, containerHeight} = data; /** @@ -70,6 +44,5 @@ function PageRenderer({index, style, data}: Props) { } PageRenderer.displayName = 'PageRenderer'; -PageRenderer.propTypes = propTypes; export default memo(PageRenderer);