@pdf-viewer/react
Version:
A react-pdf-viewer component for React and Next.js. Suitable for react-pdf document.
50 lines (49 loc) • 1.61 kB
JavaScript
import { jsxs as d, jsx as x } from "react/jsx-runtime";
import { createContext as C, useRef as s, useContext as F } from "react";
import { useDocumentContext as h } from "./RPDocumentContext.js";
import { useDocumentPasswordContext as P } from "./DocumentPasswordContext.js";
import "../utils/hooks/useLoadPdf.js";
import "pdfjs-dist";
import "../utils/types.js";
import "../th_TH-d627cd51.js";
import "../utils/getThumbnailViewport.js";
import "./ConfigContext.js";
import "../utils/hooks/usePdfProperties.js";
import "../utils/convertPdfDate.js";
import "../utils/formatFileSize.js";
import "../utils/appConsole.js";
const c = C(null), S = ({ children: e }) => {
const { setFilename: l, setPdfSrc: u } = h(), o = s(), n = s(null), { setPassword: m } = P(), a = () => {
var t;
(t = n.current) == null || t.click();
}, f = (t) => {
var p;
const r = (p = t.target.files) == null ? void 0 : p[0];
if (!r || r.type !== "application/pdf")
return;
const i = URL.createObjectURL(r);
o.current && URL.revokeObjectURL(o.current), o.current = i, l(r.name), u(i), t.target.value = "", m("");
};
return /* @__PURE__ */ d(c.Provider, { value: { openFile: a }, children: [
e,
/* @__PURE__ */ x(
"input",
{
accept: "application/pdf",
type: "file",
ref: n,
style: { display: "none" },
onChange: f
}
)
] });
}, q = () => {
const e = F(c);
if (!e)
throw new Error("useOpenFileContext must be used within FileInputProvider");
return e;
};
export {
S as FileInputProvider,
q as useOpenFileContext
};