UNPKG

@pdf-viewer/react

Version:

A react-pdf-viewer component for React and Next.js. Suitable for react-pdf document.

72 lines (71 loc) 2.19 kB
import { jsx as v } from "react/jsx-runtime"; import { createContext as L, useState as g, useCallback as l, useContext as h, useRef as w, useMemo as R } from "react"; import { LicenseType as A } from "../utils/types.js"; import { useDimensionPagesContext as y } from "./DimensionPagesContext.js"; import { usePagesRotateContext as O } from "./PagesRotateContext.js"; import { useLicenseContext as S } from "./LicenseContext.js"; import { useZoomContext as T } from "./ZoomContext.js"; import { ORGANIZATION_ALLOWED_FEATURES_MESSAGE as u } from "../utils/const.js"; const d = L(void 0), k = ({ children: i }) => { const [m, o] = g({}), { widths: t, heights: c } = y(), { pageRotate: a } = O(), { zoomLevel: f } = T(), x = l( (e, r) => { o((n) => { const s = { width: t[e], height: c[e] }; return { ...n, [e]: r(n[e], s, a[e], f) }; }); }, [t, c, f, a] ), p = l((e) => { o((r) => { const n = { ...r }; return delete n[e], n; }); }, []), C = l((e, r) => { o((n) => { const s = { ...n }; return s[e] = s[e].filter((_, P) => P !== r), s; }); }, []); return /* @__PURE__ */ v( d.Provider, { value: { updateElement: x, clearElements: p, removeElement: C, elementList: m }, children: i } ); }, E = () => { }, U = () => { const i = h(d), { type: m, validating: o } = S(), t = w(0), c = R(() => { if (o !== !1) return { updateElement: E, clearElements: E, removeElement: E, elementList: {} }; if (m !== A.Organization) return { updateElement: () => { t.current === 0 && (console.error(u), t.current++); }, clearElements: () => { t.current === 0 && (console.error(u), t.current++); }, removeElement: () => { t.current === 0 && (console.error(u), t.current++); }, elementList: {} }; }, [m, o]); if (!i) throw new Error("useElementPageContext must be used within a ElementPageProvider"); return c || i; }; export { d as ElementPageContext, k as ElementPageProvider, U as useElementPageContext };