@prismicio/next 2.0.0-alpha.2 → 2.0.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/PrismicNextImage.d.ts +2 -2
- package/dist/PrismicNextImage.mjs +60 -0
- package/dist/PrismicNextImage.mjs.map +1 -0
- package/dist/{PrismicNextLink.js → PrismicNextLink.mjs} +1 -1
- package/dist/PrismicNextLink.mjs.map +1 -0
- package/dist/{PrismicPreview.js → PrismicPreview.mjs} +2 -2
- package/dist/PrismicPreview.mjs.map +1 -0
- package/dist/{PrismicPreviewClient.js → PrismicPreviewClient.mjs} +1 -1
- package/dist/PrismicPreviewClient.mjs.map +1 -0
- package/dist/{createLocaleRedirect.js → createLocaleRedirect.mjs} +2 -2
- package/dist/createLocaleRedirect.mjs.map +1 -0
- package/dist/{enableAutoPreviews.js → enableAutoPreviews.mjs} +1 -1
- package/dist/enableAutoPreviews.mjs.map +1 -0
- package/dist/{exitPreview.js → exitPreview.mjs} +1 -1
- package/dist/exitPreview.mjs.map +1 -0
- package/dist/{imgixLoader.js → imgixLoader.mjs} +1 -1
- package/dist/imgixLoader.mjs.map +1 -0
- package/dist/index.d.ts +15 -15
- package/dist/index.mjs +19 -0
- package/dist/index.mjs.map +1 -0
- package/dist/lib/{devMsg.js → devMsg.mjs} +2 -2
- package/dist/lib/devMsg.mjs.map +1 -0
- package/dist/package.json.mjs +5 -0
- package/dist/package.json.mjs.map +1 -0
- package/dist/pages/{PrismicPreview.js → PrismicPreview.mjs} +1 -1
- package/dist/pages/PrismicPreview.mjs.map +1 -0
- package/dist/pages/enableAutoPreviews.d.ts +1 -1
- package/dist/pages/{enableAutoPreviews.js → enableAutoPreviews.mjs} +1 -1
- package/dist/pages/enableAutoPreviews.mjs.map +1 -0
- package/dist/pages/exitPreview.d.ts +1 -1
- package/dist/pages/{exitPreview.js → exitPreview.mjs} +1 -1
- package/dist/pages/exitPreview.mjs.map +1 -0
- package/dist/pages/index.d.ts +18 -18
- package/dist/pages/redirectToPreviewURL.d.ts +1 -1
- package/dist/pages/{redirectToPreviewURL.js → redirectToPreviewURL.mjs} +1 -1
- package/dist/pages/redirectToPreviewURL.mjs.map +1 -0
- package/dist/pages/setPreviewData.d.ts +1 -1
- package/dist/pages/{setPreviewData.js → setPreviewData.mjs} +1 -1
- package/dist/pages/setPreviewData.mjs.map +1 -0
- package/dist/pages/types.d.ts +1 -1
- package/dist/pages.mjs +21 -0
- package/dist/pages.mjs.map +1 -0
- package/dist/redirectToPreviewURL.d.ts +1 -1
- package/dist/{redirectToPreviewURL.js → redirectToPreviewURL.mjs} +1 -1
- package/dist/redirectToPreviewURL.mjs.map +1 -0
- package/package.json +5 -5
- package/src/PrismicNextImage.tsx +49 -44
- package/src/PrismicPreview.tsx +1 -1
- package/src/createLocaleRedirect.ts +1 -1
- package/src/index.ts +15 -15
- package/src/pages/enableAutoPreviews.ts +1 -1
- package/src/pages/exitPreview.ts +1 -1
- package/src/pages/index.ts +18 -18
- package/src/pages/redirectToPreviewURL.ts +1 -1
- package/src/pages/setPreviewData.ts +1 -1
- package/src/pages/types.ts +1 -1
- package/src/redirectToPreviewURL.ts +1 -1
- package/dist/PrismicNextImage.js +0 -64
- package/dist/PrismicNextImage.js.map +0 -1
- package/dist/PrismicNextLink.js.map +0 -1
- package/dist/PrismicPreview.js.map +0 -1
- package/dist/PrismicPreviewClient.js.map +0 -1
- package/dist/createLocaleRedirect.js.map +0 -1
- package/dist/enableAutoPreviews.js.map +0 -1
- package/dist/exitPreview.js.map +0 -1
- package/dist/imgixLoader.js.map +0 -1
- package/dist/index.js +0 -19
- package/dist/index.js.map +0 -1
- package/dist/lib/devMsg.js.map +0 -1
- package/dist/package.json.js +0 -5
- package/dist/package.json.js.map +0 -1
- package/dist/pages/PrismicPreview.js.map +0 -1
- package/dist/pages/enableAutoPreviews.js.map +0 -1
- package/dist/pages/exitPreview.js.map +0 -1
- package/dist/pages/redirectToPreviewURL.js.map +0 -1
- package/dist/pages/setPreviewData.js.map +0 -1
- package/dist/pages.js +0 -21
- package/dist/pages.js.map +0 -1
- package/dist/redirectToPreviewURL.js.map +0 -1
package/README.md
CHANGED
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
|
|
10
10
|
Helpers to integrate Prismic into Next.js apps.
|
|
11
11
|
|
|
12
|
-
- 👁️
|
|
13
|
-
-
|
|
14
|
-
- 🖼️
|
|
12
|
+
- 👁️ Set up Prismic previews.
|
|
13
|
+
- 🔗 Display Prismic images using [`next/image`][next-image].
|
|
14
|
+
- 🖼️ Display Prismic links using [`next/link`][next-link].
|
|
15
15
|
|
|
16
16
|
## Install
|
|
17
17
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ForwardRefExoticComponent, PropsWithoutRef, RefAttributes } from "react";
|
|
2
2
|
import { ImageProps } from "next/image";
|
|
3
3
|
import { ImgixURLParams } from "imgix-url-builder";
|
|
4
4
|
import { ImageFieldImage } from "@prismicio/client";
|
|
@@ -51,4 +51,4 @@ export type PrismicNextImageProps = Omit<ImageProps, "src" | "alt" | "loader"> &
|
|
|
51
51
|
*
|
|
52
52
|
* @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image
|
|
53
53
|
*/
|
|
54
|
-
export declare const PrismicNextImage:
|
|
54
|
+
export declare const PrismicNextImage: ForwardRefExoticComponent<PropsWithoutRef<PrismicNextImageProps> & RefAttributes<HTMLImageElement>>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx, Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { forwardRef } from "react";
|
|
4
|
+
import Image from "next/image";
|
|
5
|
+
import { buildURL } from "imgix-url-builder";
|
|
6
|
+
import { isFilled } from "@prismicio/client";
|
|
7
|
+
import { DEV } from "esm-env";
|
|
8
|
+
import { devMsg } from "./lib/devMsg.mjs";
|
|
9
|
+
import { imgixLoader } from "./imgixLoader.mjs";
|
|
10
|
+
const castInt = (input) => {
|
|
11
|
+
if (typeof input === "number" || typeof input === "undefined") {
|
|
12
|
+
return input;
|
|
13
|
+
} else {
|
|
14
|
+
const parsed = Number.parseInt(input);
|
|
15
|
+
if (Number.isNaN(parsed)) {
|
|
16
|
+
return void 0;
|
|
17
|
+
} else {
|
|
18
|
+
return parsed;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const PrismicNextImage = forwardRef(function PrismicNextImage2({ field, imgixParams = {}, alt, fallbackAlt, fill, width, height, fallback = null, loader = imgixLoader, ...restProps }, ref) {
|
|
23
|
+
if (DEV) {
|
|
24
|
+
if (typeof alt === "string" && alt !== "") {
|
|
25
|
+
console.warn(`[PrismicNextImage] The "alt" prop can only be used to declare an image as decorative by passing an empty string (alt="") but was provided a non-empty string. You can resolve this warning by removing the "alt" prop or changing it to alt="". For more details, see ${devMsg("alt-must-be-an-empty-string")}`);
|
|
26
|
+
}
|
|
27
|
+
if (typeof fallbackAlt === "string" && fallbackAlt !== "") {
|
|
28
|
+
console.warn(`[PrismicNextImage] The "fallbackAlt" prop can only be used to declare an image as decorative by passing an empty string (fallbackAlt="") but was provided a non-empty string. You can resolve this warning by removing the "fallbackAlt" prop or changing it to fallbackAlt="". For more details, see ${devMsg("alt-must-be-an-empty-string")}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (!isFilled.imageThumbnail(field)) {
|
|
32
|
+
return jsx(Fragment, { children: fallback });
|
|
33
|
+
}
|
|
34
|
+
const resolvedImgixParams = imgixParams;
|
|
35
|
+
for (const x in imgixParams) {
|
|
36
|
+
if (resolvedImgixParams[x] === null) {
|
|
37
|
+
resolvedImgixParams[x] = void 0;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const src = buildURL(field.url, imgixParams);
|
|
41
|
+
const ar = field.dimensions.width / field.dimensions.height;
|
|
42
|
+
const castedWidth = castInt(width);
|
|
43
|
+
const castedHeight = castInt(height);
|
|
44
|
+
let resolvedWidth = castedWidth ?? field.dimensions.width;
|
|
45
|
+
let resolvedHeight = castedHeight ?? field.dimensions.height;
|
|
46
|
+
if (castedWidth != null && castedHeight == null) {
|
|
47
|
+
resolvedHeight = castedWidth / ar;
|
|
48
|
+
} else if (castedWidth == null && castedHeight != null) {
|
|
49
|
+
resolvedWidth = castedHeight * ar;
|
|
50
|
+
}
|
|
51
|
+
const resolvedAlt = alt ?? (field.alt || fallbackAlt);
|
|
52
|
+
if (DEV && typeof resolvedAlt !== "string") {
|
|
53
|
+
console.error(`[PrismicNextImage] The following image is missing an "alt" property. Please add Alternative Text to the image in Prismic. To mark the image as decorative instead, add one of \`alt=""\` or \`fallbackAlt=""\`.`, src);
|
|
54
|
+
}
|
|
55
|
+
return jsx(Image, { ref, src, width: fill ? void 0 : resolvedWidth, height: fill ? void 0 : resolvedHeight, alt: resolvedAlt, fill, loader: loader === null ? void 0 : loader, ...restProps });
|
|
56
|
+
});
|
|
57
|
+
export {
|
|
58
|
+
PrismicNextImage
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=PrismicNextImage.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrismicNextImage.mjs","sources":["../src/PrismicNextImage.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n\tforwardRef,\n\tForwardRefExoticComponent,\n\tPropsWithoutRef,\n\tRefAttributes,\n} from \"react\";\nimport Image, { ImageProps } from \"next/image\";\nimport { buildURL, ImgixURLParams } from \"imgix-url-builder\";\nimport { ImageFieldImage, isFilled } from \"@prismicio/client\";\nimport { DEV } from \"esm-env\";\n\nimport { devMsg } from \"./lib/devMsg\";\n\nimport { imgixLoader } from \"./imgixLoader\";\n\nconst castInt = (input: string | number | undefined): number | undefined => {\n\tif (typeof input === \"number\" || typeof input === \"undefined\") {\n\t\treturn input;\n\t} else {\n\t\tconst parsed = Number.parseInt(input);\n\n\t\tif (Number.isNaN(parsed)) {\n\t\t\treturn undefined;\n\t\t} else {\n\t\t\treturn parsed;\n\t\t}\n\t}\n};\n\nexport type PrismicNextImageProps = Omit<\n\tImageProps,\n\t\"src\" | \"alt\" | \"loader\"\n> & {\n\t/** The Prismic Image field or thumbnail to render. */\n\tfield: ImageFieldImage | null | undefined;\n\n\t/**\n\t * An object of Imgix URL API parameters to transform the image.\n\t *\n\t * @see https://docs.imgix.com/apis/rendering\n\t */\n\timgixParams?: { [P in keyof ImgixURLParams]: ImgixURLParams[P] | null };\n\n\t/**\n\t * Declare an image as decorative by providing `alt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\talt?: \"\";\n\n\t/**\n\t * Declare an image as decorative only if the Image field does not have\n\t * alternative text by providing `fallbackAlt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\tfallbackAlt?: \"\";\n\n\t/**\n\t * Rendered when the field is empty. If a fallback is not given, `null` will\n\t * be rendered.\n\t */\n\tfallback?: React.ReactNode;\n\n\tloader?: ImageProps[\"loader\"] | null;\n};\n\n/**\n * React component that renders an image from a Prismic Image field or one of\n * its thumbnails using `next/image`. It will automatically set the `alt`\n * attribute using the Image field's `alt` property.\n *\n * It uses an Imgix URL-based loader by default. A custom loader can be provided\n * with the `loader` prop. If you would like to use the Next.js Image\n * Optimization API instead, set `loader={undefined}`.\n *\n * @param props - Props for the component.\n *\n * @returns A responsive image component using `next/image` for the given Image\n * field.\n *\n * @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image\n */\n// The type annotation is necessary to avoid a type reference issue.\nexport const PrismicNextImage: ForwardRefExoticComponent<\n\tPropsWithoutRef<PrismicNextImageProps> & RefAttributes<HTMLImageElement>\n> = forwardRef<HTMLImageElement, PrismicNextImageProps>(\n\tfunction PrismicNextImage(\n\t\t{\n\t\t\tfield,\n\t\t\timgixParams = {},\n\t\t\talt,\n\t\t\tfallbackAlt,\n\t\t\tfill,\n\t\t\twidth,\n\t\t\theight,\n\t\t\tfallback = null,\n\t\t\tloader = imgixLoader,\n\t\t\t...restProps\n\t\t},\n\t\tref,\n\t) {\n\t\tif (DEV) {\n\t\t\tif (typeof alt === \"string\" && alt !== \"\") {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[PrismicNextImage] The \"alt\" prop can only be used to declare an image as decorative by passing an empty string (alt=\"\") but was provided a non-empty string. You can resolve this warning by removing the \"alt\" prop or changing it to alt=\"\". For more details, see ${devMsg(\n\t\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t\t)}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (typeof fallbackAlt === \"string\" && fallbackAlt !== \"\") {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[PrismicNextImage] The \"fallbackAlt\" prop can only be used to declare an image as decorative by passing an empty string (fallbackAlt=\"\") but was provided a non-empty string. You can resolve this warning by removing the \"fallbackAlt\" prop or changing it to fallbackAlt=\"\". For more details, see ${devMsg(\n\t\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t\t)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (!isFilled.imageThumbnail(field)) {\n\t\t\treturn <>{fallback}</>;\n\t\t}\n\n\t\tconst resolvedImgixParams = imgixParams;\n\t\tfor (const x in imgixParams) {\n\t\t\tif (resolvedImgixParams[x as keyof typeof resolvedImgixParams] === null) {\n\t\t\t\tresolvedImgixParams[x as keyof typeof resolvedImgixParams] = undefined;\n\t\t\t}\n\t\t}\n\n\t\tconst src = buildURL(field.url, imgixParams as ImgixURLParams);\n\n\t\tconst ar = field.dimensions.width / field.dimensions.height;\n\n\t\tconst castedWidth = castInt(width);\n\t\tconst castedHeight = castInt(height);\n\n\t\tlet resolvedWidth = castedWidth ?? field.dimensions.width;\n\t\tlet resolvedHeight = castedHeight ?? field.dimensions.height;\n\n\t\tif (castedWidth != null && castedHeight == null) {\n\t\t\tresolvedHeight = castedWidth / ar;\n\t\t} else if (castedWidth == null && castedHeight != null) {\n\t\t\tresolvedWidth = castedHeight * ar;\n\t\t}\n\n\t\t// A non-null assertion is required since we can't statically\n\t\t// know if an alt attribute is available.\n\t\tconst resolvedAlt = (alt ?? (field.alt || fallbackAlt))!;\n\n\t\tif (DEV && typeof resolvedAlt !== \"string\") {\n\t\t\tconsole.error(\n\t\t\t\t`[PrismicNextImage] The following image is missing an \"alt\" property. Please add Alternative Text to the image in Prismic. To mark the image as decorative instead, add one of \\`alt=\"\"\\` or \\`fallbackAlt=\"\"\\`.`,\n\t\t\t\tsrc,\n\t\t\t);\n\t\t}\n\n\t\treturn (\n\t\t\t<Image\n\t\t\t\tref={ref}\n\t\t\t\tsrc={src}\n\t\t\t\twidth={fill ? undefined : resolvedWidth}\n\t\t\t\theight={fill ? undefined : resolvedHeight}\n\t\t\t\talt={resolvedAlt}\n\t\t\t\tfill={fill}\n\t\t\t\tloader={loader === null ? undefined : loader}\n\t\t\t\t{...restProps}\n\t\t\t/>\n\t\t);\n\t},\n);\n"],"names":["PrismicNextImage","_jsx","_Fragment"],"mappings":";;;;;;;;;AAiBA,MAAM,UAAU,CAAC,UAA0D;AAC1E,MAAI,OAAO,UAAU,YAAY,OAAO,UAAU,aAAa;AACvD,WAAA;AAAA,EAAA,OACD;AACA,UAAA,SAAS,OAAO,SAAS,KAAK;AAEhC,QAAA,OAAO,MAAM,MAAM,GAAG;AAClB,aAAA;AAAA,IAAA,OACD;AACC,aAAA;AAAA,IAAA;AAAA,EACR;AAEF;AA2Da,MAAA,mBAET,WACH,SAASA,kBACR,EACC,OACA,cAAc,CAAA,GACd,KACA,aACA,MACA,OACA,QACA,WAAW,MACX,SAAS,aACT,GAAG,UAAS,GAEb,KAAG;AAEH,MAAI,KAAK;AACR,QAAI,OAAO,QAAQ,YAAY,QAAQ,IAAI;AAC1C,cAAQ,KACP,yQAAyQ,OACxQ,6BAA6B,CAC7B,EAAE;AAAA,IAAA;AAIL,QAAI,OAAO,gBAAgB,YAAY,gBAAgB,IAAI;AAC1D,cAAQ,KACP,ySAAyS,OACxS,6BAA6B,CAC7B,EAAE;AAAA,IAAA;AAAA,EAEL;AAGD,MAAI,CAAC,SAAS,eAAe,KAAK,GAAG;AACpC,WAAOC,IAAAC,UAAA,EAAA,UAAG,UAAQ;AAAA,EAAA;AAGnB,QAAM,sBAAsB;AAC5B,aAAW,KAAK,aAAa;AACxB,QAAA,oBAAoB,CAAqC,MAAM,MAAM;AACxE,0BAAoB,CAAqC,IAAI;AAAA,IAAA;AAAA,EAC9D;AAGD,QAAM,MAAM,SAAS,MAAM,KAAK,WAA6B;AAE7D,QAAM,KAAK,MAAM,WAAW,QAAQ,MAAM,WAAW;AAE/C,QAAA,cAAc,QAAQ,KAAK;AAC3B,QAAA,eAAe,QAAQ,MAAM;AAE/B,MAAA,gBAAgB,eAAe,MAAM,WAAW;AAChD,MAAA,iBAAiB,gBAAgB,MAAM,WAAW;AAElD,MAAA,eAAe,QAAQ,gBAAgB,MAAM;AAChD,qBAAiB,cAAc;AAAA,EACrB,WAAA,eAAe,QAAQ,gBAAgB,MAAM;AACvD,oBAAgB,eAAe;AAAA,EAAA;AAK1B,QAAA,cAAe,QAAQ,MAAM,OAAO;AAEtC,MAAA,OAAO,OAAO,gBAAgB,UAAU;AACnC,YAAA,MACP,mNACA,GAAG;AAAA,EAAA;AAKJ,SAAAD,IAAC,OAAK,EACL,KACA,KACA,OAAO,OAAO,SAAY,eAC1B,QAAQ,OAAO,SAAY,gBAC3B,KAAK,aACL,MACA,QAAQ,WAAW,OAAO,SAAY,QAAM,GACxC,UAAA,CAAS;AAGhB,CAAC;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrismicNextLink.mjs","sources":["../src/PrismicNextLink.tsx"],"sourcesContent":["import { ComponentProps, forwardRef } from \"react\";\nimport Link from \"next/link\";\nimport {\n\tAsLinkAttrsConfig,\n\tLinkField,\n\tLinkResolverFunction,\n\tPrismicDocument,\n\tasLinkAttrs,\n} from \"@prismicio/client\";\n\nexport type PrismicNextLinkProps = Omit<\n\tComponentProps<typeof Link>,\n\t\"field\" | \"document\" | \"href\" | \"rel\"\n> & {\n\tlinkResolver?: LinkResolverFunction;\n\trel?: string | AsLinkAttrsConfig[\"rel\"];\n} & (\n\t\t| {\n\t\t\t\tfield: LinkField | null | undefined;\n\t\t\t\tdocument?: never;\n\t\t\t\thref?: never;\n\t\t }\n\t\t| {\n\t\t\t\tfield?: never;\n\t\t\t\tdocument: PrismicDocument | null | undefined;\n\t\t\t\thref?: never;\n\t\t }\n\t\t| {\n\t\t\t\tfield?: never;\n\t\t\t\tdocument?: never;\n\t\t\t\thref: ComponentProps<typeof Link>[\"href\"];\n\t\t }\n\t);\n\nexport const PrismicNextLink = forwardRef<\n\tHTMLAnchorElement,\n\tPrismicNextLinkProps\n>(function PrismicNextLink(props, ref) {\n\tconst { field, document, linkResolver, children, ...restProps } = props;\n\tconst {\n\t\thref: computedHref,\n\t\trel: computedRel,\n\t\t...attrs\n\t} = asLinkAttrs(field ?? document, {\n\t\tlinkResolver,\n\t\trel: typeof restProps.rel === \"function\" ? restProps.rel : undefined,\n\t});\n\n\tconst href = (\"href\" in restProps ? restProps.href : computedHref) || \"\";\n\n\tlet rel = computedRel;\n\tif (\"rel\" in restProps && typeof restProps.rel !== \"function\") {\n\t\trel = restProps.rel;\n\t}\n\n\treturn (\n\t\t<Link ref={ref} {...attrs} {...restProps} href={href} rel={rel}>\n\t\t\t{\"children\" in props ? children : field?.text}\n\t\t</Link>\n\t);\n});\n"],"names":["PrismicNextLink","_jsx"],"mappings":";;;;AAkCO,MAAM,kBAAkB,WAG7B,SAASA,iBAAgB,OAAO,KAAG;AACpC,QAAM,EAAE,OAAO,UAAU,cAAc,UAAU,GAAG,cAAc;AAC5D,QAAA,EACL,MAAM,cACN,KAAK,aACL,GAAG,UACA,YAAY,SAAS,UAAU;AAAA,IAClC;AAAA,IACA,KAAK,OAAO,UAAU,QAAQ,aAAa,UAAU,MAAM;AAAA,EAAA,CAC3D;AAED,QAAM,QAAQ,UAAU,YAAY,UAAU,OAAO,iBAAiB;AAEtE,MAAI,MAAM;AACV,MAAI,SAAS,aAAa,OAAO,UAAU,QAAQ,YAAY;AAC9D,UAAM,UAAU;AAAA,EAAA;AAGjB,SACCC,IAAC,MAAI,EAAC,KAAc,GAAA,UAAW,WAAW,MAAY,eACpD,cAAc,QAAQ,WAAW,+BAAO,MAAI;AAGhD,CAAC;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
2
2
|
import Script from "next/script";
|
|
3
3
|
import { getToolbarSrc } from "@prismicio/client";
|
|
4
|
-
import { PrismicPreviewClient } from "./PrismicPreviewClient.
|
|
4
|
+
import { PrismicPreviewClient } from "./PrismicPreviewClient.mjs";
|
|
5
5
|
const PrismicPreview = async (props) => {
|
|
6
6
|
const { repositoryName, children, ...otherProps } = props;
|
|
7
7
|
const { draftMode } = await import("next/headers");
|
|
@@ -12,4 +12,4 @@ const PrismicPreview = async (props) => {
|
|
|
12
12
|
export {
|
|
13
13
|
PrismicPreview
|
|
14
14
|
};
|
|
15
|
-
//# sourceMappingURL=PrismicPreview.
|
|
15
|
+
//# sourceMappingURL=PrismicPreview.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrismicPreview.mjs","sources":["../src/PrismicPreview.tsx"],"sourcesContent":["import type { FC, ReactNode } from \"react\";\nimport Script from \"next/script\";\nimport { getToolbarSrc } from \"@prismicio/client\";\n\nimport { PrismicPreviewClient } from \"./PrismicPreviewClient\";\n\n/** Props for `<PrismicPreview>`. */\nexport type PrismicPreviewProps = {\n\t/**\n\t * The name of your Prismic repository. A Prismic Toolbar will be registered\n\t * using this repository.\n\t */\n\trepositoryName: string;\n\n\t/**\n\t * The URL of your app's Prismic preview endpoint (default: `/api/preview`).\n\t * This URL will be fetched on preview update events.\n\t */\n\tupdatePreviewURL?: string;\n\n\t/**\n\t * The URL of your app's exit preview endpoint (default: `/api/exit-preview`).\n\t * This URL will be fetched on preview exit events.\n\t */\n\texitPreviewURL?: string;\n\n\t/** Children to render adjacent to the Prismic Toolbar. */\n\tchildren?: ReactNode;\n};\n\n/**\n * React component that sets up Prismic Previews using the Prismic Toolbar. When\n * the Prismic Toolbar send events to the browser, such as on preview updates\n * and exiting, this component will automatically refresh the page with the\n * changes.\n *\n * This component can be wrapped around your app or added anywhere in your app's\n * tree. It must be rendered on every page.\n */\nexport const PrismicPreview: FC<PrismicPreviewProps> = async (props) => {\n\tconst { repositoryName, children, ...otherProps } = props;\n\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { draftMode } = await import(\"next/headers\");\n\n\tconst toolbarSrc = getToolbarSrc(repositoryName);\n\tconst isDraftMode = (await draftMode()).isEnabled;\n\n\treturn (\n\t\t<>\n\t\t\t{children}\n\t\t\t<PrismicPreviewClient\n\t\t\t\trepositoryName={repositoryName}\n\t\t\t\tisDraftMode={isDraftMode}\n\t\t\t\t{...otherProps}\n\t\t\t/>\n\t\t\t<Script src={toolbarSrc} strategy=\"lazyOnload\" />\n\t\t</>\n\t);\n};\n"],"names":["_jsxs","_Fragment","_jsx"],"mappings":";;;;AAuCa,MAAA,iBAA0C,OAAO,UAAS;AACtE,QAAM,EAAE,gBAAgB,UAAU,GAAG,WAAe,IAAA;AAKpD,QAAM,EAAE,UAAA,IAAc,MAAM,OAAO,cAAc;AAE3C,QAAA,aAAa,cAAc,cAAc;AACzC,QAAA,eAAe,MAAM,UAAA,GAAa;AAGvC,SAAAA,KAAAC,UAAA,EAAA,UAAA,CACE,UACDC,IAAC,sBACA,EAAA,gBACA,aAAwB,GACpB,YAAU,GAEfA,IAAC,QAAM,EAAC,KAAK,YAAY,UAAS,cAAe,CAAA,GAAA;AAGpD;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrismicPreviewClient.mjs","sources":["../src/PrismicPreviewClient.tsx"],"sourcesContent":["\"use client\";\n\nimport { FC, useEffect } from \"react\";\nimport { cookie as prismicCookie } from \"@prismicio/client\";\nimport { useRouter } from \"next/navigation\";\n\ntype PrismicPreviewClientProps = {\n\trepositoryName: string;\n\tisDraftMode: boolean;\n\tupdatePreviewURL?: string;\n\texitPreviewURL?: string;\n};\n\nexport const PrismicPreviewClient: FC<PrismicPreviewClientProps> = (props) => {\n\tconst {\n\t\trepositoryName,\n\t\tisDraftMode,\n\t\tupdatePreviewURL = \"/api/preview\",\n\t\texitPreviewURL = \"/api/exit-preview\",\n\t} = props;\n\n\tconst { refresh } = useRouter();\n\n\tuseEffect(() => {\n\t\tconst controller = new AbortController();\n\n\t\twindow.addEventListener(\"prismicPreviewUpdate\", onUpdate, {\n\t\t\tsignal: controller.signal,\n\t\t});\n\t\twindow.addEventListener(\"prismicPreviewEnd\", onEnd, {\n\t\t\tsignal: controller.signal,\n\t\t});\n\n\t\tconst cookie = getPrismicPreviewCookie(window.document.cookie);\n\t\tconst cookieRepositoryName = cookie\n\t\t\t? (decodeURIComponent(cookie).match(/\"([^\"]+)\\.prismic\\.io\"/) || [])[1]\n\t\t\t: undefined;\n\t\tconst hasCookieForRepository = cookieRepositoryName === repositoryName;\n\n\t\t// Start the preview for preview share links. Previews from\n\t\t// share links do not go to the `updatePreviewURL` like a normal\n\t\t// preview.\n\t\tif (hasCookieForRepository && !isDraftMode) {\n\t\t\tconsole.log(\"starting preview link\");\n\n\t\t\t// We check `opaqueredirect` because we don't care if\n\t\t\t// the redirect was successful or not. As long as it\n\t\t\t// redirects, we know the endpoint exists and draft mode\n\t\t\t// is active.\n\t\t\tglobalThis\n\t\t\t\t.fetch(updatePreviewURL, {\n\t\t\t\t\tredirect: \"manual\",\n\t\t\t\t\tsignal: controller.signal,\n\t\t\t\t})\n\t\t\t\t.then((res) => {\n\t\t\t\t\tif (res.type !== \"opaqueredirect\") {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`[<PrismicPreview>] Failed to start the preview using \"${updatePreviewURL}\". Does it exist?`,\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\trefresh();\n\t\t\t\t})\n\t\t\t\t.catch(() => {\n\t\t\t\t\t// noop\n\t\t\t\t});\n\t\t}\n\n\t\tfunction onUpdate(event: Event) {\n\t\t\tevent.preventDefault();\n\t\t\trefresh();\n\t\t}\n\n\t\tfunction onEnd(event: Event) {\n\t\t\tevent.preventDefault();\n\t\t\tglobalThis\n\t\t\t\t.fetch(exitPreviewURL, { signal: controller.signal })\n\t\t\t\t.then((res) => {\n\t\t\t\t\tif (!res.ok) {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`[<PrismicPreview>] Failed to exit Preview Mode using the \"${exitPreviewURL}\" API endpoint. Does it exist?`,\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\trefresh();\n\t\t\t\t})\n\t\t\t\t.catch(() => {\n\t\t\t\t\t// noop\n\t\t\t\t});\n\t\t}\n\n\t\treturn () => controller.abort();\n\t}, [repositoryName, isDraftMode, updatePreviewURL, exitPreviewURL, refresh]);\n\n\treturn null;\n};\n\n/**\n * Returns the value of a cookie from a given cookie store.\n *\n * @param cookieJar - The stringified cookie store from which to read the\n * cookie.\n *\n * @returns The value of the cookie, if it exists.\n */\nfunction getPrismicPreviewCookie(cookieJar: string): string | undefined {\n\tfunction readValue(value: string): string {\n\t\treturn value.replace(/%3B/g, \";\");\n\t}\n\n\tconst cookies = cookieJar.split(\"; \");\n\n\tlet value: string | undefined;\n\n\tfor (const cookie of cookies) {\n\t\tconst parts = cookie.split(\"=\");\n\t\tconst name = readValue(parts[0]).replace(/%3D/g, \"=\");\n\n\t\tif (name === prismicCookie.preview) {\n\t\t\tvalue = readValue(parts.slice(1).join(\"=\"));\n\t\t\tcontinue;\n\t\t}\n\t}\n\n\treturn value;\n}\n"],"names":["cookie","value","prismicCookie"],"mappings":";;;;AAaa,MAAA,uBAAsD,CAAC,UAAS;AAC5E,QAAM,EACL,gBACA,aACA,mBAAmB,gBACnB,iBAAiB,wBACd;AAEE,QAAA,EAAE,QAAO,IAAK;AAEpB,YAAU,MAAK;AACR,UAAA,aAAa,IAAI;AAEhB,WAAA,iBAAiB,wBAAwB,UAAU;AAAA,MACzD,QAAQ,WAAW;AAAA,IAAA,CACnB;AACM,WAAA,iBAAiB,qBAAqB,OAAO;AAAA,MACnD,QAAQ,WAAW;AAAA,IAAA,CACnB;AAED,UAAMA,UAAS,wBAAwB,OAAO,SAAS,MAAM;AACvD,UAAA,uBAAuBA,WACzB,mBAAmBA,OAAM,EAAE,MAAM,wBAAwB,KAAK,CAAA,GAAI,CAAC,IACpE;AACH,UAAM,yBAAyB,yBAAyB;AAKpD,QAAA,0BAA0B,CAAC,aAAa;AAC3C,cAAQ,IAAI,uBAAuB;AAMnC,iBACE,MAAM,kBAAkB;AAAA,QACxB,UAAU;AAAA,QACV,QAAQ,WAAW;AAAA,MAAA,CACnB,EACA,KAAK,CAAC,QAAO;AACT,YAAA,IAAI,SAAS,kBAAkB;AAC1B,kBAAA,MACP,yDAAyD,gBAAgB,mBAAmB;AAG7F;AAAA,QAAA;;OAID,EACA,MAAM,MAAK;AAAA,MAAA,CAEX;AAAA,IAAA;AAGH,aAAS,SAAS,OAAY;AAC7B,YAAM,eAAc;;;AAIrB,aAAS,MAAM,OAAY;AAC1B,YAAM,eAAc;AAElB,iBAAA,MAAM,gBAAgB,EAAE,QAAQ,WAAW,QAAQ,EACnD,KAAK,CAAC,QAAO;AACT,YAAA,CAAC,IAAI,IAAI;AACJ,kBAAA,MACP,6DAA6D,cAAc,gCAAgC;AAG5G;AAAA,QAAA;;OAID,EACA,MAAM,MAAK;AAAA,MAAA,CAEX;AAAA,IAAA;AAGI,WAAA,MAAM,WAAW;KACtB,CAAC,gBAAgB,aAAa,kBAAkB,gBAAgB,OAAO,CAAC;AAEpE,SAAA;AACR;AAUA,SAAS,wBAAwB,WAAiB;AACjD,WAAS,UAAUC,QAAa;AACxBA,WAAAA,OAAM,QAAQ,QAAQ,GAAG;AAAA,EAAA;AAG3B,QAAA,UAAU,UAAU,MAAM,IAAI;AAEhC,MAAA;AAEJ,aAAWD,YAAU,SAAS;AACvB,UAAA,QAAQA,SAAO,MAAM,GAAG;AACxB,UAAA,OAAO,UAAU,MAAM,CAAC,CAAC,EAAE,QAAQ,QAAQ,GAAG;AAEhD,QAAA,SAASE,OAAc,SAAS;AACnC,cAAQ,UAAU,MAAM,MAAM,CAAC,EAAE,KAAK,GAAG,CAAC;AAC1C;AAAA,IAAA;AAAA,EACD;AAGM,SAAA;AACR;"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { devMsg } from "./lib/devMsg.
|
|
1
|
+
import { devMsg } from "./lib/devMsg.mjs";
|
|
2
2
|
function createLocaleRedirect() {
|
|
3
3
|
throw new Error(`createLocaleRedirect() has been removed due to performance issues. See ${devMsg("replace-createLocaleRedirect")} for more details.`);
|
|
4
4
|
}
|
|
5
5
|
export {
|
|
6
6
|
createLocaleRedirect
|
|
7
7
|
};
|
|
8
|
-
//# sourceMappingURL=createLocaleRedirect.
|
|
8
|
+
//# sourceMappingURL=createLocaleRedirect.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createLocaleRedirect.mjs","sources":["../src/createLocaleRedirect.ts"],"sourcesContent":["import { devMsg } from \"./lib/devMsg\";\n\n/**\n * @deprecated `createLocaleRedirect()` has been removed due to performance\n * issues.\n */\nexport function createLocaleRedirect() {\n\tthrow new Error(\n\t\t`createLocaleRedirect() has been removed due to performance issues. See ${devMsg(\n\t\t\t\"replace-createLocaleRedirect\",\n\t\t)} for more details.`,\n\t);\n}\n/**\n * @deprecated `createLocaleRedirect()` has been removed due to performance\n * issues.\n */\nexport type CreateLocaleRedirectConfig = never;\n"],"names":[],"mappings":";SAMgB,uBAAoB;AACnC,QAAM,IAAI,MACT,0EAA0E,OACzE,8BAA8B,CAC9B,oBAAoB;AAEvB;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enableAutoPreviews.mjs","sources":["../src/enableAutoPreviews.ts"],"sourcesContent":["import { type Client, cookie as prismicCookie } from \"@prismicio/client\";\n\n/** Configuration for `enableAutoPreviews`. */\nexport type EnableAutoPreviewsConfig = {\n\t/** Prismic client with which automatic previews will be enabled. */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<Client, \"queryContentFromRef\" | \"enableAutoPreviewsFromReq\">;\n};\n\n/**\n * Configures a Prismic client to automatically query draft content during a\n * preview session.\n *\n * @param config - Configuration for the function.\n */\nexport function enableAutoPreviews(config: EnableAutoPreviewsConfig): void {\n\t// We use a function value so the cookie is checked on every\n\t// request. We don't have a static value to read from.\n\tconfig.client.queryContentFromRef(async () => {\n\t\t// Need this to avoid the following Next.js build-time error:\n\t\t// You're importing a component that needs next/headers. That only works\n\t\t// in a Server Component which is not supported in the pages/ directory.\n\t\tconst { cookies, draftMode } = await import(\"next/headers\");\n\n\t\tlet isDraftModeEnabled = false;\n\t\ttry {\n\t\t\tisDraftModeEnabled = (await draftMode()).isEnabled;\n\t\t} catch {\n\t\t\t// `draftMode()` may have been called in a palce that\n\t\t\t// does not have access to its async storage. This\n\t\t\t// occurs in places like `generateStaticParams()`. We\n\t\t\t// can ignore this case.\n\t\t\treturn;\n\t\t}\n\t\tif (!isDraftModeEnabled) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst cookie = (await cookies()).get(prismicCookie.preview)?.value;\n\t\tif (!cookie) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst isActiveCookie = cookie.includes(\"websitePreviewId=\");\n\t\tif (!isActiveCookie) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn cookie;\n\t});\n}\n"],"names":["cookie","prismicCookie"],"mappings":";AAiBM,SAAU,mBAAmB,QAAgC;AAG3D,SAAA,OAAO,oBAAoB,YAAW;;AAI5C,UAAM,EAAE,SAAS,cAAc,MAAM,OAAO,cAAc;AAE1D,QAAI,qBAAqB;AACrB,QAAA;AACmB,4BAAA,MAAM,aAAa;AAAA,IAAA,QAClC;AAKP;AAAA,IAAA;AAED,QAAI,CAAC,oBAAoB;AACxB;AAAA,IAAA;AAGD,UAAMA,YAAU,YAAM,QAAA,GAAW,IAAIC,OAAc,OAAO,MAA1C,mBAA6C;AAC7D,QAAI,CAACD,UAAQ;AACZ;AAAA,IAAA;AAGK,UAAA,iBAAiBA,SAAO,SAAS,mBAAmB;AAC1D,QAAI,CAAC,gBAAgB;AACpB;AAAA,IAAA;AAGM,WAAAA;AAAAA,EAAA,CACP;AACF;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exitPreview.mjs","sources":["../src/exitPreview.ts"],"sourcesContent":["/**\n * Ends a Prismic preview session within a Next.js app. This function should be\n * used in a Router Handler.\n *\n * @example\n *\n * ```typescript\n * // src/app/api/exit-preview/route.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export async function GET() {\n * \treturn await exitPreview();\n * }\n * ```\n */\nexport async function exitPreview(): Promise<Response> {\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { draftMode } = await import(\"next/headers\");\n\n\t(await draftMode()).disable();\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\treturn new Response(JSON.stringify({ success: true }), {\n\t\theaders: {\n\t\t\t\"Cache-Control\": \"no-store\",\n\t\t},\n\t});\n}\n"],"names":[],"mappings":"AAgBA,eAAsB,cAAW;AAIhC,QAAM,EAAE,UAAA,IAAc,MAAM,OAAO,cAAc;AAEhD,GAAA,MAAM,UAAS,GAAI;AAGb,SAAA,IAAI,SAAS,KAAK,UAAU,EAAE,SAAS,KAAA,CAAM,GAAG;AAAA,IACtD,SAAS;AAAA,MACR,iBAAiB;AAAA,IAAA;AAAA,EACjB,CACD;AACF;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imgixLoader.mjs","sources":["../src/imgixLoader.ts"],"sourcesContent":["import { ImageLoaderProps } from \"next/image\";\nimport { buildURL, ImgixURLParams } from \"imgix-url-builder\";\n\n/**\n * A `next/image` loader for Imgix, which Prismic uses, with an optional\n * collection of default Imgix parameters.\n *\n * @see To learn about `next/image` loaders: https://nextjs.org/docs/api-reference/next/image#loader\n * @see To learn about Imgix's URL API: https://docs.imgix.com/apis/rendering\n */\nexport const imgixLoader = (args: ImageLoaderProps): string => {\n\tconst url = new URL(args.src);\n\n\tconst params: ImgixURLParams = {\n\t\tfit: (url.searchParams.get(\"fit\") as ImgixURLParams[\"fit\"]) || \"max\",\n\t\tw: args.width,\n\t\th: undefined,\n\t};\n\n\tif (args.quality) {\n\t\tparams.q = args.quality;\n\t}\n\n\treturn buildURL(args.src, params);\n};\n"],"names":[],"mappings":";AAUa,MAAA,cAAc,CAAC,SAAkC;AAC7D,QAAM,MAAM,IAAI,IAAI,KAAK,GAAG;AAE5B,QAAM,SAAyB;AAAA,IAC9B,KAAM,IAAI,aAAa,IAAI,KAAK,KAA+B;AAAA,IAC/D,GAAG,KAAK;AAAA,IACR,GAAG;AAAA;AAGJ,MAAI,KAAK,SAAS;AACjB,WAAO,IAAI,KAAK;AAAA,EAAA;AAGV,SAAA,SAAS,KAAK,KAAK,MAAM;AACjC;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export { exitPreview } from "./exitPreview
|
|
2
|
-
export { PrismicPreview } from "./PrismicPreview
|
|
3
|
-
export type { PrismicPreviewProps } from "./PrismicPreview
|
|
4
|
-
export { PrismicNextLink } from "./PrismicNextLink
|
|
5
|
-
export type { PrismicNextLinkProps } from "./PrismicNextLink
|
|
6
|
-
export { enableAutoPreviews } from "./enableAutoPreviews
|
|
7
|
-
export type { EnableAutoPreviewsConfig } from "./enableAutoPreviews
|
|
8
|
-
export { redirectToPreviewURL } from "./redirectToPreviewURL
|
|
9
|
-
export type { RedirectToPreviewURLConfig } from "./redirectToPreviewURL
|
|
10
|
-
export { PrismicNextImage } from "./PrismicNextImage
|
|
11
|
-
export type { PrismicNextImageProps } from "./PrismicNextImage
|
|
12
|
-
export { imgixLoader } from "./imgixLoader
|
|
13
|
-
export type { CreateClientConfig } from "./types
|
|
14
|
-
export { createLocaleRedirect } from "./createLocaleRedirect
|
|
15
|
-
export type { CreateLocaleRedirectConfig } from "./createLocaleRedirect
|
|
1
|
+
export { exitPreview } from "./exitPreview";
|
|
2
|
+
export { PrismicPreview } from "./PrismicPreview";
|
|
3
|
+
export type { PrismicPreviewProps } from "./PrismicPreview";
|
|
4
|
+
export { PrismicNextLink } from "./PrismicNextLink";
|
|
5
|
+
export type { PrismicNextLinkProps } from "./PrismicNextLink";
|
|
6
|
+
export { enableAutoPreviews } from "./enableAutoPreviews";
|
|
7
|
+
export type { EnableAutoPreviewsConfig } from "./enableAutoPreviews";
|
|
8
|
+
export { redirectToPreviewURL } from "./redirectToPreviewURL";
|
|
9
|
+
export type { RedirectToPreviewURLConfig } from "./redirectToPreviewURL";
|
|
10
|
+
export { PrismicNextImage } from "./PrismicNextImage";
|
|
11
|
+
export type { PrismicNextImageProps } from "./PrismicNextImage";
|
|
12
|
+
export { imgixLoader } from "./imgixLoader";
|
|
13
|
+
export type { CreateClientConfig } from "./types";
|
|
14
|
+
export { createLocaleRedirect } from "./createLocaleRedirect";
|
|
15
|
+
export type { CreateLocaleRedirectConfig } from "./createLocaleRedirect";
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { exitPreview } from "./exitPreview.mjs";
|
|
2
|
+
import { PrismicPreview } from "./PrismicPreview.mjs";
|
|
3
|
+
import { PrismicNextLink } from "./PrismicNextLink.mjs";
|
|
4
|
+
import { enableAutoPreviews } from "./enableAutoPreviews.mjs";
|
|
5
|
+
import { redirectToPreviewURL } from "./redirectToPreviewURL.mjs";
|
|
6
|
+
import { PrismicNextImage } from "./PrismicNextImage.mjs";
|
|
7
|
+
import { imgixLoader } from "./imgixLoader.mjs";
|
|
8
|
+
import { createLocaleRedirect } from "./createLocaleRedirect.mjs";
|
|
9
|
+
export {
|
|
10
|
+
PrismicNextImage,
|
|
11
|
+
PrismicNextLink,
|
|
12
|
+
PrismicPreview,
|
|
13
|
+
createLocaleRedirect,
|
|
14
|
+
enableAutoPreviews,
|
|
15
|
+
exitPreview,
|
|
16
|
+
imgixLoader,
|
|
17
|
+
redirectToPreviewURL
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { version } from "../package.json.
|
|
1
|
+
import { version } from "../package.json.mjs";
|
|
2
2
|
const devMsg = (slug) => {
|
|
3
3
|
return `https://prismic.dev/msg/next/v${version}/${slug}`;
|
|
4
4
|
};
|
|
5
5
|
export {
|
|
6
6
|
devMsg
|
|
7
7
|
};
|
|
8
|
-
//# sourceMappingURL=devMsg.
|
|
8
|
+
//# sourceMappingURL=devMsg.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devMsg.mjs","sources":["../../src/lib/devMsg.ts"],"sourcesContent":["import { version } from \"../../package.json\";\n\n/**\n * Returns a `prismic.dev/msg` URL for a given message slug.\n *\n * @example\n *\n * ```ts\n * devMsg(\"missing-param\");\n * // => \"https://prismic.dev/msg/next/v1.2.3/missing-param\"\n * ```\n *\n * @param slug - Slug for the message. This corresponds to a Markdown file in\n * the Git repository's `/messages` directory.\n *\n * @returns The `prismic.dev/msg` URL for the given slug.\n */\nexport const devMsg = (slug: string) => {\n\treturn `https://prismic.dev/msg/next/v${version}/${slug}`;\n};\n"],"names":[],"mappings":";AAiBa,MAAA,SAAS,CAAC,SAAgB;AAC/B,SAAA,iCAAiC,OAAO,IAAI,IAAI;AACxD;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.json.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrismicPreview.mjs","sources":["../../src/pages/PrismicPreview.tsx"],"sourcesContent":["import { type ReactNode, useEffect, FC } from \"react\";\nimport { useRouter } from \"next/router\";\nimport Script from \"next/script\";\nimport { getToolbarSrc, cookie as prismicCookie } from \"@prismicio/client\";\n\n/** Props for `<PrismicPreview>`. */\nexport type PrismicPreviewProps = {\n\t/**\n\t * The name of your Prismic repository. A Prismic Toolbar will be registered\n\t * using this repository.\n\t */\n\trepositoryName: string;\n\n\t/**\n\t * The URL of your app's Prismic preview endpoint (default: `/api/preview`).\n\t * This URL will be fetched on preview update events.\n\t */\n\tupdatePreviewURL?: string;\n\n\t/**\n\t * The URL of your app's exit preview endpoint (default: `/api/exit-preview`).\n\t * This URL will be fetched on preview exit events.\n\t */\n\texitPreviewURL?: string;\n\n\t/** Children to render adjacent to the Prismic Toolbar. */\n\tchildren?: ReactNode;\n};\n\n/**\n * React component that sets up Prismic Previews using the Prismic Toolbar. When\n * the Prismic Toolbar send events to the browser, such as on preview updates\n * and exiting, this component will automatically refresh the page with the\n * changes.\n *\n * This component can be wrapped around your app or added anywhere in your app's\n * tree. It must be rendered on every page.\n */\nexport const PrismicPreview: FC<PrismicPreviewProps> = (props) => {\n\tconst {\n\t\trepositoryName,\n\t\tupdatePreviewURL = \"/api/preview\",\n\t\texitPreviewURL = \"/api/exit-preview\",\n\t\tchildren,\n\t} = props;\n\n\tconst router = useRouter();\n\n\tconst toolbarSrc = getToolbarSrc(repositoryName);\n\n\tuseEffect(() => {\n\t\tconst controller = new AbortController();\n\n\t\twindow.addEventListener(\"prismicPreviewUpdate\", onUpdate, {\n\t\t\tsignal: controller.signal,\n\t\t});\n\t\twindow.addEventListener(\"prismicPreviewEnd\", onEnd, {\n\t\t\tsignal: controller.signal,\n\t\t});\n\n\t\t// Start the preview for preview share links. Previews from\n\t\t// share links do not go to the `updatePreviewURL` like a normal\n\t\t// preview.\n\t\t//\n\t\t// We check that the current URL is a descendant of the base\n\t\t// path to prevent infinite refrehes.\n\t\tif (\n\t\t\twindow.location.href.startsWith(\n\t\t\t\twindow.location.origin + router.basePath,\n\t\t\t) &&\n\t\t\tgetPreviewCookieRepositoryName() === repositoryName &&\n\t\t\t!router.isPreview\n\t\t) {\n\t\t\tstart();\n\t\t}\n\n\t\tfunction onEnd(event: Event) {\n\t\t\tevent.preventDefault();\n\t\t\tfetch(router.basePath + exitPreviewURL, { signal: controller.signal })\n\t\t\t\t.then((res) => {\n\t\t\t\t\tif (!res.ok) {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`[<PrismicPreview>] Failed to exit Preview Mode using the \"${exitPreviewURL}\" API endpoint. Does it exist?`,\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\trefresh();\n\t\t\t\t})\n\t\t\t\t.catch(() => {});\n\t\t}\n\n\t\tfunction onUpdate(event: Event) {\n\t\t\tevent.preventDefault();\n\t\t\tstart();\n\t\t}\n\n\t\tfunction start() {\n\t\t\t// We check `opaqueredirect` because we don't care if\n\t\t\t// the redirect was successful or not. As long as it\n\t\t\t// redirects, we know the endpoint exists and at least\n\t\t\t// attempted to set preview data.\n\t\t\tfetch(router.basePath + updatePreviewURL, {\n\t\t\t\tredirect: \"manual\",\n\t\t\t\tsignal: controller.signal,\n\t\t\t})\n\t\t\t\t.then((res) => {\n\t\t\t\t\tif (res.type !== \"opaqueredirect\") {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`[<PrismicPreview>] Failed to start or update the preview using \"${updatePreviewURL}\". Does it exist?`,\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\trefresh();\n\t\t\t\t})\n\t\t\t\t.catch(() => {});\n\t\t}\n\n\t\tfunction refresh() {\n\t\t\trouter.replace(router.asPath, undefined, { scroll: false });\n\t\t}\n\n\t\treturn () => controller.abort();\n\t}, [exitPreviewURL, updatePreviewURL, repositoryName, router]);\n\n\treturn (\n\t\t<>\n\t\t\t{children}\n\t\t\t<Script src={toolbarSrc} strategy=\"lazyOnload\" />\n\t\t</>\n\t);\n};\n\nfunction getPreviewCookieRepositoryName() {\n\tconst cookie = window.document.cookie\n\t\t.split(\"; \")\n\t\t.find((row) => row.startsWith(`${prismicCookie.preview}=`))\n\t\t?.split(\"=\")[1];\n\n\treturn (decodeURIComponent(cookie ?? \"\").match(/\"([^\"]+)\\.prismic\\.io\"/) ||\n\t\t[])[1];\n}\n"],"names":["_jsxs","_Fragment","_jsx","cookie","prismicCookie"],"mappings":";;;;;AAsCa,MAAA,iBAA0C,CAAC,UAAS;AAChE,QAAM,EACL,gBACA,mBAAmB,gBACnB,iBAAiB,qBACjB,aACG;AAEJ,QAAM,SAAS,UAAS;AAElB,QAAA,aAAa,cAAc,cAAc;AAE/C,YAAU,MAAK;AACR,UAAA,aAAa,IAAI;AAEhB,WAAA,iBAAiB,wBAAwB,UAAU;AAAA,MACzD,QAAQ,WAAW;AAAA,IAAA,CACnB;AACM,WAAA,iBAAiB,qBAAqB,OAAO;AAAA,MACnD,QAAQ,WAAW;AAAA,IAAA,CACnB;AAQD,QACC,OAAO,SAAS,KAAK,WACpB,OAAO,SAAS,SAAS,OAAO,QAAQ,KAEzC,+BAA8B,MAAO,kBACrC,CAAC,OAAO,WACP;;;AAIF,aAAS,MAAM,OAAY;AAC1B,YAAM,eAAc;AACd,YAAA,OAAO,WAAW,gBAAgB,EAAE,QAAQ,WAAW,OAAQ,CAAA,EACnE,KAAK,CAAC,QAAO;AACT,YAAA,CAAC,IAAI,IAAI;AACJ,kBAAA,MACP,6DAA6D,cAAc,gCAAgC;AAG5G;AAAA,QAAA;;OAID,EACA,MAAM,MAAO;AAAA,MAAA,CAAC;AAAA,IAAA;AAGjB,aAAS,SAAS,OAAY;AAC7B,YAAM,eAAc;;;AAIrB,aAAS,QAAK;AAKP,YAAA,OAAO,WAAW,kBAAkB;AAAA,QACzC,UAAU;AAAA,QACV,QAAQ,WAAW;AAAA,MAAA,CACnB,EACC,KAAK,CAAC,QAAO;AACT,YAAA,IAAI,SAAS,kBAAkB;AAC1B,kBAAA,MACP,mEAAmE,gBAAgB,mBAAmB;AAGvG;AAAA,QAAA;;OAID,EACA,MAAM,MAAO;AAAA,MAAA,CAAC;AAAA,IAAA;AAGjB,aAAS,UAAO;AACf,aAAO,QAAQ,OAAO,QAAQ,QAAW,EAAE,QAAQ,OAAO;AAAA,IAAA;AAGpD,WAAA,MAAM,WAAW;KACtB,CAAC,gBAAgB,kBAAkB,gBAAgB,MAAM,CAAC;AAE7D,SACCA,KACEC,UAAA,EAAA,UAAA,CAAA,UACDC,IAAC,QAAO,EAAA,KAAK,YAAY,UAAS,aAAe,CAAA,CAAA,GAAA;AAGpD;AAEA,SAAS,iCAA8B;;AAChC,QAAAC,YAAS,YAAO,SAAS,OAC7B,MAAM,IAAI,EACV,KAAK,CAAC,QAAQ,IAAI,WAAW,GAAGC,OAAc,OAAO,GAAG,CAAC,MAF5C,mBAGZ,MAAM,KAAK;AAEN,UAAA,mBAAmBD,YAAU,EAAE,EAAE,MAAM,wBAAwB,KACtE,CAAA,GAAI,CAAC;AACP;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enableAutoPreviews.mjs","sources":["../../src/pages/enableAutoPreviews.ts"],"sourcesContent":["import type { PreviewData } from \"next\";\nimport type { Client } from \"@prismicio/client\";\n\nimport type { NextApiRequestLike } from \"./types\";\n\n/**\n * Configuration for `enableAutoPreviews`.\n *\n * @typeParam TPreviewData - Next.js preview data object.\n */\nexport type EnableAutoPreviewsConfig = {\n\t/** Prismic client with which automatic previews will be enabled. */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<Client, \"queryContentFromRef\" | \"enableAutoPreviewsFromReq\">;\n\n\t/**\n\t * The `previewData` object provided in the `getStaticProps()` or\n\t * `getServerSideProps()` context object.\n\t */\n\tpreviewData?: PreviewData;\n\n\t/**\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n};\n\n/**\n * Configures a Prismic client to automatically query draft content during a\n * preview session. It either takes in a Next.js `getStaticProps` context object\n * or a Next.js API endpoint request object.\n *\n * @param config - Configuration for the function.\n */\nexport function enableAutoPreviews(config: EnableAutoPreviewsConfig): void {\n\tif (\"previewData\" in config && config.previewData) {\n\t\t// Assume we are in `getStaticProps()` or\n\t\t// `getServerSideProps()` with active Preview Mode.\n\n\t\tif (isPrismicPreviewData(config.previewData)) {\n\t\t\tconfig.client.queryContentFromRef(config.previewData.ref);\n\t\t}\n\n\t\treturn;\n\t}\n\n\tif (\"req\" in config && config.req) {\n\t\t// Assume we are in an API Route.\n\n\t\tconfig.client.enableAutoPreviewsFromReq(config.req);\n\n\t\treturn;\n\t}\n}\n\nfunction isPrismicPreviewData(input: unknown): input is { ref: string } {\n\treturn typeof input === \"object\" && input !== null && \"ref\" in input;\n}\n"],"names":[],"mappings":"AAsCM,SAAU,mBAAmB,QAAgC;AAC9D,MAAA,iBAAiB,UAAU,OAAO,aAAa;AAI9C,QAAA,qBAAqB,OAAO,WAAW,GAAG;AAC7C,aAAO,OAAO,oBAAoB,OAAO,YAAY,GAAG;AAAA,IAAA;AAGzD;AAAA,EAAA;AAGG,MAAA,SAAS,UAAU,OAAO,KAAK;AAG3B,WAAA,OAAO,0BAA0B,OAAO,GAAG;AAElD;AAAA,EAAA;AAEF;AAEA,SAAS,qBAAqB,OAAc;AAC3C,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,SAAS;AAChE;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exitPreview.mjs","sources":["../../src/pages/exitPreview.ts"],"sourcesContent":["import type { NextApiRequestLike, NextApiResponseLike } from \"./types\";\n\n/** Configuration for `exitPreview()`. */\nexport type ExitPreviewAPIRouteConfig = {\n\t/**\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq?: NextApiRequestLike;\n\n\t/**\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres: NextApiResponseLike;\n};\n\n/**\n * Ends a Prismic preview session within a Next.js app. This function should be\n * used in an API route.\n *\n * @example\n *\n * ```typescript\n * // src/pages/api/exit-preview.js\n *\n * import { exitPreview } from \"@prismicio/next\";\n *\n * export default function handler(_req, res) {\n * \treturn exitPreview({ res });\n * }\n * ```\n */\nexport function exitPreview(config: ExitPreviewAPIRouteConfig): void {\n\tconfig.res.clearPreviewData();\n\n\t// `Cache-Control` header is used to prevent CDN-level caching.\n\tconfig.res.setHeader(\"Cache-Control\", \"no-store\");\n\n\tconfig.res.json({ success: true });\n\n\treturn;\n}\n"],"names":[],"mappings":"AAmCM,SAAU,YAAY,QAAiC;AAC5D,SAAO,IAAI;AAGJ,SAAA,IAAI,UAAU,iBAAiB,UAAU;AAEhD,SAAO,IAAI,KAAK,EAAE,SAAS,MAAM;AAEjC;AACD;"}
|
package/dist/pages/index.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export { PrismicNextLink } from "../PrismicNextLink
|
|
2
|
-
export { type PrismicNextLinkProps } from "../PrismicNextLink
|
|
3
|
-
export { PrismicNextImage } from "../PrismicNextImage
|
|
4
|
-
export { type PrismicNextImageProps } from "../PrismicNextImage
|
|
5
|
-
export { imgixLoader } from "../imgixLoader
|
|
6
|
-
export { PrismicPreview } from "./PrismicPreview
|
|
7
|
-
export type { PrismicPreviewProps } from "./PrismicPreview
|
|
8
|
-
export { enableAutoPreviews } from "./enableAutoPreviews
|
|
9
|
-
export type { EnableAutoPreviewsConfig } from "./enableAutoPreviews
|
|
10
|
-
export { redirectToPreviewURL } from "./redirectToPreviewURL
|
|
11
|
-
export type { RedirectToPreviewURLConfig } from "./redirectToPreviewURL
|
|
12
|
-
export { exitPreview } from "./exitPreview
|
|
13
|
-
export type { ExitPreviewAPIRouteConfig } from "./exitPreview
|
|
14
|
-
export { setPreviewData } from "./setPreviewData
|
|
15
|
-
export type { SetPreviewDataConfig } from "./setPreviewData
|
|
16
|
-
export type { CreateClientConfig } from "./types
|
|
17
|
-
export { createLocaleRedirect } from "../createLocaleRedirect
|
|
18
|
-
export type { CreateLocaleRedirectConfig } from "../createLocaleRedirect
|
|
1
|
+
export { PrismicNextLink } from "../PrismicNextLink";
|
|
2
|
+
export { type PrismicNextLinkProps } from "../PrismicNextLink";
|
|
3
|
+
export { PrismicNextImage } from "../PrismicNextImage";
|
|
4
|
+
export { type PrismicNextImageProps } from "../PrismicNextImage";
|
|
5
|
+
export { imgixLoader } from "../imgixLoader";
|
|
6
|
+
export { PrismicPreview } from "./PrismicPreview";
|
|
7
|
+
export type { PrismicPreviewProps } from "./PrismicPreview";
|
|
8
|
+
export { enableAutoPreviews } from "./enableAutoPreviews";
|
|
9
|
+
export type { EnableAutoPreviewsConfig } from "./enableAutoPreviews";
|
|
10
|
+
export { redirectToPreviewURL } from "./redirectToPreviewURL";
|
|
11
|
+
export type { RedirectToPreviewURLConfig } from "./redirectToPreviewURL";
|
|
12
|
+
export { exitPreview } from "./exitPreview";
|
|
13
|
+
export type { ExitPreviewAPIRouteConfig } from "./exitPreview";
|
|
14
|
+
export { setPreviewData } from "./setPreviewData";
|
|
15
|
+
export type { SetPreviewDataConfig } from "./setPreviewData";
|
|
16
|
+
export type { CreateClientConfig } from "./types";
|
|
17
|
+
export { createLocaleRedirect } from "../createLocaleRedirect";
|
|
18
|
+
export type { CreateLocaleRedirectConfig } from "../createLocaleRedirect";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { LinkResolverFunction, Client } from "@prismicio/client";
|
|
2
|
-
import type { NextApiRequestLike, NextApiResponseLike } from "./types
|
|
2
|
+
import type { NextApiRequestLike, NextApiResponseLike } from "./types";
|
|
3
3
|
export type RedirectToPreviewURLConfig = {
|
|
4
4
|
/** The Prismic client configured for the preview session's repository. */
|
|
5
5
|
client: Pick<Client, "resolvePreviewURL">;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.mjs","sources":["../../src/pages/redirectToPreviewURL.ts"],"sourcesContent":["import type { LinkResolverFunction, Client } from \"@prismicio/client\";\n\nimport type { NextApiRequestLike, NextApiResponseLike } from \"./types\";\n\nexport type RedirectToPreviewURLConfig = {\n\t/** The Prismic client configured for the preview session's repository. */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<Client, \"resolvePreviewURL\">;\n\n\t/**\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\n\t */\n\treq: NextApiRequestLike;\n\n\t/**\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/pages/building-your-application/routing/api-routes\\>\n\t */\n\tres: NextApiResponseLike;\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed\n\t * document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the\n\t * `defaultURL` option must _not_ include it. Instead, provide the `basePath`\n\t * property using the `basePath` option.\n\t */\n\tdefaultURL?: string;\n\n\t/**\n\t * The `basePath` for the Next.js app as it is defined in `next.config.js`.\n\t * This option can be omitted if the app does not have a `basePath`.\n\t *\n\t * @remarks\n\t * The Router Handler or API route is unable to detect the app's `basePath`\n\t * automatically. It must be provided to `redirectToPreviewURL()` manually.\n\t */\n\tbasePath?: string;\n};\n\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLConfig,\n): Promise<void> {\n\tconst {\n\t\tclient,\n\t\treq,\n\t\tres,\n\t\tlinkResolver,\n\t\tdefaultURL = \"/\",\n\t\tbasePath = \"\",\n\t} = config;\n\n\tconst previewToken = req.query.token?.toString();\n\n\tconst previewURL = await client.resolvePreviewURL({\n\t\tlinkResolver,\n\t\tdefaultURL,\n\t\tpreviewToken,\n\t});\n\n\tres.redirect(basePath + previewURL);\n\n\treturn;\n}\n"],"names":[],"mappings":"AAqDA,eAAsB,qBACrB,QAAkC;AADnC;AAGO,QAAA,EACL,QACA,KACA,KACA,cACA,aAAa,KACb,WAAW,GAAA,IACR;AAEJ,QAAM,gBAAe,SAAI,MAAM,UAAV,mBAAiB;AAEhC,QAAA,aAAa,MAAM,OAAO,kBAAkB;AAAA,IACjD;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACA;AAEG,MAAA,SAAS,WAAW,UAAU;AAElC;AACD;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setPreviewData.mjs","sources":["../../src/pages/setPreviewData.ts"],"sourcesContent":["import { cookie } from \"@prismicio/client\";\n\nimport type { NextApiRequestLike, NextApiResponseLike } from \"./types\";\n\n/** Configuration for `setPreviewData`. */\nexport type SetPreviewDataConfig = {\n\t/**\n\t * The `req` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\treq: NextApiRequestLike;\n\n\t/**\n\t * The `res` object from a Next.js API route.\n\t *\n\t * @see Next.js API route docs: \\<https://nextjs.org/docs/api-routes/introduction\\>\n\t */\n\tres: NextApiResponseLike;\n};\n\n/** Set Prismic preview data for Next.js's Preview Mode. */\nexport function setPreviewData({ req, res }: SetPreviewDataConfig): void {\n\tconst ref = req.query.token || req.cookies[cookie.preview];\n\n\tif (ref) {\n\t\tres.setPreviewData({ ref });\n\t}\n}\n"],"names":[],"mappings":";SAsBgB,eAAe,EAAE,KAAK,OAA2B;AAChE,QAAM,MAAM,IAAI,MAAM,SAAS,IAAI,QAAQ,OAAO,OAAO;AAEzD,MAAI,KAAK;AACJ,QAAA,eAAe,EAAE,KAAK;AAAA,EAAA;AAE5B;"}
|
package/dist/pages/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ClientConfig } from "@prismicio/client";
|
|
2
|
-
import { EnableAutoPreviewsConfig } from "./enableAutoPreviews
|
|
2
|
+
import { EnableAutoPreviewsConfig } from "./enableAutoPreviews";
|
|
3
3
|
/**
|
|
4
4
|
* Configuration for creating a Prismic client with automatic preview support in
|
|
5
5
|
* Next.js apps.
|
package/dist/pages.mjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { PrismicNextLink } from "./PrismicNextLink.mjs";
|
|
2
|
+
import { PrismicNextImage } from "./PrismicNextImage.mjs";
|
|
3
|
+
import { imgixLoader } from "./imgixLoader.mjs";
|
|
4
|
+
import { PrismicPreview } from "./pages/PrismicPreview.mjs";
|
|
5
|
+
import { enableAutoPreviews } from "./pages/enableAutoPreviews.mjs";
|
|
6
|
+
import { redirectToPreviewURL } from "./pages/redirectToPreviewURL.mjs";
|
|
7
|
+
import { exitPreview } from "./pages/exitPreview.mjs";
|
|
8
|
+
import { setPreviewData } from "./pages/setPreviewData.mjs";
|
|
9
|
+
import { createLocaleRedirect } from "./createLocaleRedirect.mjs";
|
|
10
|
+
export {
|
|
11
|
+
PrismicNextImage,
|
|
12
|
+
PrismicNextLink,
|
|
13
|
+
PrismicPreview,
|
|
14
|
+
createLocaleRedirect,
|
|
15
|
+
enableAutoPreviews,
|
|
16
|
+
exitPreview,
|
|
17
|
+
imgixLoader,
|
|
18
|
+
redirectToPreviewURL,
|
|
19
|
+
setPreviewData
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=pages.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pages.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Client, type LinkResolverFunction } from "@prismicio/client";
|
|
2
|
-
import { NextRequestLike } from "./types
|
|
2
|
+
import { NextRequestLike } from "./types";
|
|
3
3
|
export type RedirectToPreviewURLConfig = {
|
|
4
4
|
/** The Prismic client configured for the preview session's repository. */
|
|
5
5
|
client: Pick<Client, "resolvePreviewURL">;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.mjs","sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import { redirect } from \"next/navigation\";\nimport {\n\tcookie as prismicCookie,\n\ttype Client,\n\ttype LinkResolverFunction,\n} from \"@prismicio/client\";\n\nimport { NextRequestLike } from \"./types\";\n\nexport type RedirectToPreviewURLConfig = {\n\t/** The Prismic client configured for the preview session's repository. */\n\t// `Pick` is used to use the smallest possible subset of\n\t// `prismic.Client`. Doing this reduces the surface area for breaking\n\t// type changes.\n\tclient: Pick<Client, \"resolvePreviewURL\">;\n\n\t/**\n\t * The `request` object from a Next.js Route Handler.\n\t *\n\t * @see Next.js Route Handler docs: \\<https://nextjs.org/docs/app/building-your-application/routing/route-handlers\\>\n\t */\n\trequest: NextRequestLike;\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed\n\t * document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the\n\t * `defaultURL` option must _not_ include it. Instead, provide the `basePath`\n\t * property using the `basePath` option.\n\t */\n\tdefaultURL?: string;\n};\n\nexport async function redirectToPreviewURL(\n\tconfig: RedirectToPreviewURLConfig,\n): Promise<never> {\n\tconst { client, request, linkResolver, defaultURL = \"/\" } = config;\n\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { cookies, draftMode } = await import(\"next/headers\");\n\n\tconst documentID =\n\t\trequest.nextUrl.searchParams.get(\"documentId\") ?? undefined;\n\n\t// Set the initial preview cookie. Setting the cookie here is necessary\n\t// to support unpublished previews. Without setting it here, the page\n\t// will try to render without the preview cookie, leading to a\n\t// PrismicNotFound error.\n\tconst previewToken = request.nextUrl.searchParams.get(\"token\") ?? undefined;\n\tif (previewToken) {\n\t\tconst cookieJar = await cookies();\n\t\tcookieJar.set(prismicCookie.preview, previewToken);\n\t}\n\n\tconst previewURL = await client.resolvePreviewURL({\n\t\tdocumentID,\n\t\tpreviewToken,\n\t\tdefaultURL,\n\t\tlinkResolver,\n\t});\n\n\t(await draftMode()).enable();\n\n\tredirect(previewURL);\n}\n"],"names":["prismicCookie"],"mappings":";;AAyCA,eAAsB,qBACrB,QAAkC;AAElC,QAAM,EAAE,QAAQ,SAAS,cAAc,aAAa,QAAQ;AAK5D,QAAM,EAAE,SAAS,cAAc,MAAM,OAAO,cAAc;AAE1D,QAAM,aACL,QAAQ,QAAQ,aAAa,IAAI,YAAY,KAAK;AAMnD,QAAM,eAAe,QAAQ,QAAQ,aAAa,IAAI,OAAO,KAAK;AAClE,MAAI,cAAc;AACX,UAAA,YAAY,MAAM;AACd,cAAA,IAAIA,OAAc,SAAS,YAAY;AAAA,EAAA;AAG5C,QAAA,aAAa,MAAM,OAAO,kBAAkB;AAAA,IACjD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,CACA;AAEA,GAAA,MAAM,UAAS,GAAI;AAEpB,WAAS,UAAU;AACpB;"}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"e2e-projects/*"
|
|
5
5
|
],
|
|
6
6
|
"name": "@prismicio/next",
|
|
7
|
-
"version": "2.0.
|
|
7
|
+
"version": "2.0.1-alpha.0",
|
|
8
8
|
"description": "Helpers to integrate Prismic into Next.js apps",
|
|
9
9
|
"keywords": [
|
|
10
10
|
"typescript",
|
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
"exports": {
|
|
25
25
|
".": {
|
|
26
26
|
"types": "./dist/index.d.ts",
|
|
27
|
-
"default": "./dist/index.
|
|
27
|
+
"default": "./dist/index.mjs"
|
|
28
28
|
},
|
|
29
29
|
"./pages": {
|
|
30
30
|
"types": "./dist/pages/index.d.ts",
|
|
31
|
-
"default": "./dist/pages.
|
|
31
|
+
"default": "./dist/pages.mjs"
|
|
32
32
|
},
|
|
33
33
|
"./package.json": "./package.json"
|
|
34
34
|
},
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"lint": "eslint",
|
|
54
54
|
"prepare": "npm run build",
|
|
55
55
|
"release": "npm run build && npm run test && standard-version && git push --follow-tags && npm run build && npm publish",
|
|
56
|
-
"release:alpha": "npm run build && npm run test && standard-version --
|
|
57
|
-
"release:alpha:dry": "standard-version --
|
|
56
|
+
"release:alpha": "npm run build && npm run test && standard-version --prerelease alpha && git push --follow-tags && npm run build && npm publish --tag alpha",
|
|
57
|
+
"release:alpha:dry": "standard-version --prerelease alpha --dry-run",
|
|
58
58
|
"release:dry": "standard-version --dry-run",
|
|
59
59
|
"size": "size-limit",
|
|
60
60
|
"test": "npm run lint && npm run types && npm run build && npm run e2e && npm run size && npm run e2e",
|