UNPKG

@prismicio/next

Version:

Helpers to integrate Prismic into Next.js apps

37 lines (36 loc) 1.35 kB
import { resolveDefaultExport } from "./lib/resolveDefaultExport.js"; import { PrismicPreviewClient } from "./PrismicPreviewClient.js"; import { getToolbarSrc } from "@prismicio/client"; import Script from "next/script.js"; import { Fragment, jsx, jsxs } from "react/jsx-runtime"; //#region src/PrismicPreview.tsx /** * React component that sets up Prismic Previews using the Prismic Toolbar. When the Prismic Toolbar * send events to the browser, such as on preview updates and exiting, this component will * automatically refresh the page with the changes. * * This component can be wrapped around your app or added anywhere in your app's tree. It must be * rendered on every page. */ const PrismicPreview = async (props) => { const { repositoryName, children, ...otherProps } = props; const { draftMode } = await import("next/headers.js"); const toolbarSrc = getToolbarSrc(repositoryName); const isDraftMode = (await draftMode()).isEnabled; const ResolvedScript = resolveDefaultExport(Script); return /* @__PURE__ */ jsxs(Fragment, { children: [ children, /* @__PURE__ */ jsx(PrismicPreviewClient, { repositoryName, isDraftMode, ...otherProps }), /* @__PURE__ */ jsx(ResolvedScript, { src: toolbarSrc, strategy: "lazyOnload" }) ] }); }; //#endregion export { PrismicPreview }; //# sourceMappingURL=PrismicPreview.js.map