@pdf-viewer/react
Version:
A react-pdf-viewer component for React and Next.js. Suitable for react-pdf document.
54 lines (53 loc) • 1.45 kB
JavaScript
import { jsx as D } from "react/jsx-runtime";
import { createContext as x, useContext as C, useState as P, useCallback as r } from "react";
import { useDocumentContext as h } from "./RPDocumentContext.js";
import { useToolbarComponentContext as F } from "./ToolbarComponentContext.js";
import { useDocumentPasswordContext as v } from "./DocumentPasswordContext.js";
const p = x({
dragging: !1,
handleDragLeave: () => {
},
handleDragEnter: () => {
},
handleDrop: () => {
}
}), w = () => C(p), E = ({ children: i }) => {
const [c, o] = P(!1), { setFilename: n, setPdfSrc: a } = h(), { openFileTool: s } = F(), {
setPassword: f
} = v(), u = r(
(e) => {
var l;
e.preventDefault(), e.stopPropagation(), o(!1);
const t = (l = e.dataTransfer) == null ? void 0 : l.files[0];
if (!t || t.type !== "application/pdf")
return;
const m = URL.createObjectURL(t);
n(t.name), a(m), f("");
},
[n, a]
), g = r(
(e) => {
e.preventDefault(), e.stopPropagation(), s && o(!0);
},
[s]
), d = r((e) => {
e.preventDefault(), e.stopPropagation(), o(!1);
}, []);
return /* @__PURE__ */ D(
p.Provider,
{
value: {
dragging: c,
handleDragLeave: d,
handleDragEnter: g,
handleDrop: u
},
children: i
}
);
};
export {
p as DropFileZoneContext,
E as DropFileZoneProvider,
w as useDropFileZoneContext
};