@prismicio/next 1.7.1 → 2.0.0-alpha.1
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 +5 -3
- package/dist/PrismicNextImage.d.ts +7 -8
- package/dist/PrismicNextImage.js +8 -8
- package/dist/PrismicNextImage.js.map +1 -1
- package/dist/PrismicNextLink.d.ts +99 -100
- package/dist/PrismicNextLink.js +3 -5
- package/dist/PrismicNextLink.js.map +1 -1
- package/dist/PrismicPreview.d.ts +5 -13
- package/dist/PrismicPreview.js +6 -19
- package/dist/PrismicPreview.js.map +1 -1
- package/dist/PrismicPreviewClient.d.ts +5 -3
- package/dist/PrismicPreviewClient.js +58 -68
- package/dist/PrismicPreviewClient.js.map +1 -1
- package/dist/createLocaleRedirect.d.ts +8 -15
- package/dist/createLocaleRedirect.js +4 -28
- package/dist/createLocaleRedirect.js.map +1 -1
- package/dist/enableAutoPreviews.d.ts +7 -31
- package/dist/enableAutoPreviews.js +24 -35
- package/dist/enableAutoPreviews.js.map +1 -1
- package/dist/exitPreview.d.ts +4 -46
- package/dist/exitPreview.js +8 -15
- package/dist/exitPreview.js.map +1 -1
- package/dist/imgixLoader.js.map +1 -1
- package/dist/index.d.ts +15 -18
- package/dist/index.js +2 -4
- package/dist/index.js.map +1 -1
- package/dist/lib/devMsg.d.ts +1 -1
- package/dist/lib/devMsg.js.map +1 -1
- package/dist/package.json.js +1 -1
- package/dist/pages/PrismicPreview.d.ts +31 -0
- package/dist/pages/PrismicPreview.js +64 -0
- package/dist/pages/PrismicPreview.js.map +1 -0
- package/dist/pages/enableAutoPreviews.d.ts +31 -0
- package/dist/pages/enableAutoPreviews.js +19 -0
- package/dist/pages/enableAutoPreviews.js.map +1 -0
- package/dist/pages/exitPreview.d.ts +33 -0
- package/dist/pages/exitPreview.js +10 -0
- package/dist/pages/exitPreview.js.map +1 -0
- package/dist/pages/index.d.ts +18 -0
- package/dist/pages/redirectToPreviewURL.d.ts +43 -0
- package/dist/pages/redirectToPreviewURL.js +16 -0
- package/dist/pages/redirectToPreviewURL.js.map +1 -0
- package/dist/{setPreviewData.d.ts → pages/setPreviewData.d.ts} +3 -9
- package/dist/{setPreviewData.js → pages/setPreviewData.js} +2 -2
- package/dist/pages/setPreviewData.js.map +1 -0
- package/dist/pages/types.d.ts +30 -0
- package/dist/pages.js +21 -0
- package/dist/pages.js.map +1 -0
- package/dist/redirectToPreviewURL.d.ts +11 -41
- package/dist/redirectToPreviewURL.js +16 -22
- package/dist/redirectToPreviewURL.js.map +1 -1
- package/dist/types.d.ts +2 -51
- package/package.json +61 -54
- package/src/PrismicNextImage.tsx +19 -16
- package/src/PrismicNextLink.tsx +17 -13
- package/src/PrismicPreview.tsx +20 -50
- package/src/PrismicPreviewClient.tsx +112 -138
- package/src/createLocaleRedirect.ts +14 -56
- package/src/enableAutoPreviews.ts +38 -110
- package/src/exitPreview.ts +18 -81
- package/src/index.ts +15 -26
- package/src/lib/devMsg.ts +1 -1
- package/src/pages/PrismicPreview.tsx +145 -0
- package/src/pages/enableAutoPreviews.ts +62 -0
- package/src/pages/exitPreview.ts +45 -0
- package/src/pages/index.ts +27 -0
- package/src/pages/redirectToPreviewURL.ts +77 -0
- package/src/{setPreviewData.ts → pages/setPreviewData.ts} +5 -11
- package/src/pages/types.ts +36 -0
- package/src/redirectToPreviewURL.ts +44 -95
- package/src/types.ts +2 -56
- package/dist/PrismicNextImage.cjs +0 -64
- package/dist/PrismicNextImage.cjs.map +0 -1
- package/dist/PrismicNextLink.cjs +0 -40
- package/dist/PrismicNextLink.cjs.map +0 -1
- package/dist/PrismicPreview.cjs +0 -28
- package/dist/PrismicPreview.cjs.map +0 -1
- package/dist/PrismicPreviewClient.cjs +0 -81
- package/dist/PrismicPreviewClient.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/cookie.cjs +0 -5
- package/dist/_node_modules/@prismicio/client/dist/cookie.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/cookie.js +0 -5
- package/dist/_node_modules/@prismicio/client/dist/cookie.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs +0 -16
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js +0 -16
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.cjs +0 -13
- package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.js +0 -13
- package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs +0 -47
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js +0 -47
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.cjs +0 -28
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.js +0 -28
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs +0 -27
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js +0 -27
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.cjs +0 -14
- package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.js +0 -14
- package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.cjs +0 -7
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.js +0 -7
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.cjs +0 -9
- package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.js +0 -9
- package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.cjs +0 -10
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.js +0 -10
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.js.map +0 -1
- package/dist/createLocaleRedirect.cjs +0 -32
- package/dist/createLocaleRedirect.cjs.map +0 -1
- package/dist/enableAutoPreviews.cjs +0 -40
- package/dist/enableAutoPreviews.cjs.map +0 -1
- package/dist/exitPreview.cjs +0 -20
- package/dist/exitPreview.cjs.map +0 -1
- package/dist/imgixLoader.cjs +0 -17
- package/dist/imgixLoader.cjs.map +0 -1
- package/dist/index.cjs +0 -21
- package/dist/index.cjs.map +0 -1
- package/dist/lib/devMsg.cjs +0 -8
- package/dist/lib/devMsg.cjs.map +0 -1
- package/dist/lib/getPreviewCookieRepositoryName.cjs +0 -7
- package/dist/lib/getPreviewCookieRepositoryName.cjs.map +0 -1
- package/dist/lib/getPreviewCookieRepositoryName.d.ts +0 -9
- package/dist/lib/getPreviewCookieRepositoryName.js +0 -7
- package/dist/lib/getPreviewCookieRepositoryName.js.map +0 -1
- package/dist/lib/getPrismicPreviewCookie.cjs +0 -21
- package/dist/lib/getPrismicPreviewCookie.cjs.map +0 -1
- package/dist/lib/getPrismicPreviewCookie.d.ts +0 -9
- package/dist/lib/getPrismicPreviewCookie.js +0 -21
- package/dist/lib/getPrismicPreviewCookie.js.map +0 -1
- package/dist/package.json.cjs +0 -5
- package/dist/package.json.cjs.map +0 -1
- package/dist/redirectToPreviewURL.cjs +0 -30
- package/dist/redirectToPreviewURL.cjs.map +0 -1
- package/dist/setPreviewData.cjs +0 -11
- package/dist/setPreviewData.cjs.map +0 -1
- package/dist/setPreviewData.js.map +0 -1
- package/src/lib/getPreviewCookieRepositoryName.ts +0 -14
- package/src/lib/getPrismicPreviewCookie.ts +0 -33
package/README.md
CHANGED
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
|
|
10
10
|
Helpers to integrate Prismic into Next.js apps.
|
|
11
11
|
|
|
12
|
-
- 👁️ Easily set up Prismic
|
|
13
|
-
-
|
|
12
|
+
- 👁️ Easily set up Prismic previews
|
|
13
|
+
- 👁️ Render Prismic links with [`next/link`][next-link]
|
|
14
|
+
- 🖼️ Optimize Prismic images using [`next/image`][next-image] and Prismic's built-in [Imgix][imgix] integration
|
|
14
15
|
|
|
15
16
|
## Install
|
|
16
17
|
|
|
@@ -58,7 +59,8 @@ For more clarity on this project and its structure you can also check out the de
|
|
|
58
59
|
|
|
59
60
|
[prismic]: https://prismic.io
|
|
60
61
|
[imgix]: https://imgix.com/
|
|
61
|
-
[next-
|
|
62
|
+
[next-link]: https://nextjs.org/docs/app/api-reference/components/link
|
|
63
|
+
[next-image]: https://nextjs.org/docs/app/api-reference/components/image
|
|
62
64
|
|
|
63
65
|
<!-- TODO: Replace link with a more useful one if available -->
|
|
64
66
|
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import { JSX } from "react";
|
|
2
2
|
import { ImageProps } from "next/image";
|
|
3
3
|
import { ImgixURLParams } from "imgix-url-builder";
|
|
4
|
-
import
|
|
5
|
-
export type PrismicNextImageProps = Omit<ImageProps, "src" | "alt"> & {
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
*/
|
|
9
|
-
field: prismic.ImageFieldImage | null | undefined;
|
|
4
|
+
import { ImageFieldImage } from "@prismicio/client";
|
|
5
|
+
export type PrismicNextImageProps = Omit<ImageProps, "src" | "alt" | "loader"> & {
|
|
6
|
+
/** The Prismic Image field or thumbnail to render. */
|
|
7
|
+
field: ImageFieldImage | null | undefined;
|
|
10
8
|
/**
|
|
11
9
|
* An object of Imgix URL API parameters to transform the image.
|
|
12
10
|
*
|
|
@@ -35,6 +33,7 @@ export type PrismicNextImageProps = Omit<ImageProps, "src" | "alt"> & {
|
|
|
35
33
|
* be rendered.
|
|
36
34
|
*/
|
|
37
35
|
fallback?: React.ReactNode;
|
|
36
|
+
loader?: ImageProps["loader"] | null;
|
|
38
37
|
};
|
|
39
38
|
/**
|
|
40
39
|
* React component that renders an image from a Prismic Image field or one of
|
|
@@ -52,4 +51,4 @@ export type PrismicNextImageProps = Omit<ImageProps, "src" | "alt"> & {
|
|
|
52
51
|
*
|
|
53
52
|
* @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image
|
|
54
53
|
*/
|
|
55
|
-
export declare const PrismicNextImage: ({ field, imgixParams, alt, fallbackAlt, fill, width, height, fallback, ...restProps }: PrismicNextImageProps) => JSX.Element;
|
|
54
|
+
export declare const PrismicNextImage: ({ field, imgixParams, alt, fallbackAlt, fill, width, height, fallback, loader, ...restProps }: PrismicNextImageProps) => JSX.Element;
|
package/dist/PrismicNextImage.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
'use client';
|
|
1
|
+
"use client";
|
|
3
2
|
import { jsx, Fragment } from "react/jsx-runtime";
|
|
4
3
|
import Image from "next/image";
|
|
5
4
|
import { buildURL } from "imgix-url-builder";
|
|
5
|
+
import { isFilled } from "@prismicio/client";
|
|
6
|
+
import { DEV } from "esm-env";
|
|
6
7
|
import { devMsg } from "./lib/devMsg.js";
|
|
7
8
|
import { imgixLoader } from "./imgixLoader.js";
|
|
8
|
-
import { imageThumbnail } from './_node_modules/@prismicio/client/dist/helpers/isFilled.js';
|
|
9
9
|
const castInt = (input) => {
|
|
10
10
|
if (typeof input === "number" || typeof input === "undefined") {
|
|
11
11
|
return input;
|
|
@@ -18,8 +18,8 @@ const castInt = (input) => {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
|
-
const PrismicNextImage = ({ field, imgixParams = {}, alt, fallbackAlt, fill, width, height, fallback = null, ...restProps }) => {
|
|
22
|
-
if (
|
|
21
|
+
const PrismicNextImage = ({ field, imgixParams = {}, alt, fallbackAlt, fill, width, height, fallback = null, loader = imgixLoader, ...restProps }) => {
|
|
22
|
+
if (DEV) {
|
|
23
23
|
if (typeof alt === "string" && alt !== "") {
|
|
24
24
|
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")}`);
|
|
25
25
|
}
|
|
@@ -27,7 +27,7 @@ const PrismicNextImage = ({ field, imgixParams = {}, alt, fallbackAlt, fill, wid
|
|
|
27
27
|
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")}`);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
if (imageThumbnail(field)) {
|
|
30
|
+
if (isFilled.imageThumbnail(field)) {
|
|
31
31
|
const resolvedImgixParams = imgixParams;
|
|
32
32
|
for (const x in imgixParams) {
|
|
33
33
|
if (resolvedImgixParams[x] === null) {
|
|
@@ -46,14 +46,14 @@ const PrismicNextImage = ({ field, imgixParams = {}, alt, fallbackAlt, fill, wid
|
|
|
46
46
|
resolvedWidth = castedHeight * ar;
|
|
47
47
|
}
|
|
48
48
|
const resolvedAlt = alt ?? (field.alt || fallbackAlt);
|
|
49
|
-
if (
|
|
49
|
+
if (DEV && typeof resolvedAlt !== "string") {
|
|
50
50
|
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);
|
|
51
51
|
}
|
|
52
52
|
let ResolvedImage = Image;
|
|
53
53
|
if ("default" in ResolvedImage) {
|
|
54
54
|
ResolvedImage = ResolvedImage.default;
|
|
55
55
|
}
|
|
56
|
-
return jsx(ResolvedImage, { src, width: fill ? void 0 : resolvedWidth, height: fill ? void 0 : resolvedHeight, alt: resolvedAlt, fill, loader:
|
|
56
|
+
return jsx(ResolvedImage, { src, width: fill ? void 0 : resolvedWidth, height: fill ? void 0 : resolvedHeight, alt: resolvedAlt, fill, loader: loader === null ? void 0 : loader, ...restProps });
|
|
57
57
|
} else {
|
|
58
58
|
return jsx(Fragment, { children: fallback });
|
|
59
59
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicNextImage.js","sources":["
|
|
1
|
+
{"version":3,"file":"PrismicNextImage.js","sources":["../src/PrismicNextImage.tsx"],"sourcesContent":["\"use client\";\n\nimport { JSX } 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.js\";\n\nimport { imgixLoader } from \"./imgixLoader.js\";\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 */\nexport const PrismicNextImage = ({\n\tfield,\n\timgixParams = {},\n\talt,\n\tfallbackAlt,\n\tfill,\n\twidth,\n\theight,\n\tfallback = null,\n\tloader = imgixLoader,\n\t...restProps\n}: PrismicNextImageProps): JSX.Element => {\n\tif (DEV) {\n\t\tif (typeof alt === \"string\" && alt !== \"\") {\n\t\t\tconsole.warn(\n\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\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\tif (typeof fallbackAlt === \"string\" && fallbackAlt !== \"\") {\n\t\t\tconsole.warn(\n\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\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tif (isFilled.imageThumbnail(field)) {\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\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\t// TODO: Remove once https://github.com/vercel/next.js/issues/52216 is resolved.\n\t\t// `next/image` seems to be affected by a default + named export bundling bug.\n\t\tlet ResolvedImage = Image;\n\t\tif (\"default\" in ResolvedImage) {\n\t\t\tResolvedImage = (ResolvedImage as unknown as { default: typeof Image })\n\t\t\t\t.default;\n\t\t}\n\n\t\treturn (\n\t\t\t<ResolvedImage\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} else {\n\t\treturn <>{fallback}</>;\n\t}\n};\n"],"names":["_jsx","_Fragment"],"mappings":";;;;;;;;AAYA,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;AA0DO,MAAM,mBAAmB,CAAC,EAChC,OACA,cAAc,IACd,KACA,aACA,MACA,OACA,QACA,WAAW,MACX,SAAS,aACT,GAAG,gBACqC;AACxC,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;AAGG,MAAA,SAAS,eAAe,KAAK,GAAG;AACnC,UAAM,sBAAsB;AAC5B,eAAW,KAAK,aAAa;AACxB,UAAA,oBAAoB,CAAqC,MAAM,MAAM;AACxE,4BAAoB,CAAqC,IAAI;AAAA,MAAA;AAAA,IAC9D;AAGD,UAAM,MAAM,SAAS,MAAM,KAAK,WAA6B;AAE7D,UAAM,KAAK,MAAM,WAAW,QAAQ,MAAM,WAAW;AAE/C,UAAA,cAAc,QAAQ,KAAK;AAC3B,UAAA,eAAe,QAAQ,MAAM;AAE/B,QAAA,gBAAgB,eAAe,MAAM,WAAW;AAChD,QAAA,iBAAiB,gBAAgB,MAAM,WAAW;AAElD,QAAA,eAAe,QAAQ,gBAAgB,MAAM;AAChD,uBAAiB,cAAc;AAAA,IACrB,WAAA,eAAe,QAAQ,gBAAgB,MAAM;AACvD,sBAAgB,eAAe;AAAA,IAAA;AAM1B,UAAA,cAAe,QAAQ,MAAM,OAAO;AAEtC,QAAA,OAAO,OAAO,gBAAgB,UAAU;AACnC,cAAA,MACP,mNACA,GAAG;AAAA,IAAA;AAML,QAAI,gBAAgB;AACpB,QAAI,aAAa,eAAe;AAC/B,sBAAiB,cACf;AAAA,IAAA;AAIF,WAAAA,IAAC,eACA,EAAA,KACA,OAAO,OAAO,SAAY,eAC1B,QAAQ,OAAO,SAAY,gBAC3B,KAAK,aACL,MACA,QAAQ,WAAW,OAAO,SAAY,QAClC,GAAA,UAAA,CACH;AAAA,EAAA,OAEG;AACN,WAAOA,IAAAC,UAAA,EAAA,UAAG,UAAQ;AAAA,EAAA;AAEpB;"}
|
|
@@ -1,126 +1,125 @@
|
|
|
1
|
-
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
import * as prismic from "@prismicio/client";
|
|
1
|
+
import { ComponentProps } from "react";
|
|
4
2
|
import Link from "next/link";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
import { AsLinkAttrsConfig, LinkField, LinkResolverFunction, PrismicDocument } from "@prismicio/client";
|
|
4
|
+
export type PrismicNextLinkProps = Omit<ComponentProps<typeof Link>, "field" | "document" | "href" | "rel"> & {
|
|
5
|
+
linkResolver?: LinkResolverFunction;
|
|
6
|
+
rel?: string | AsLinkAttrsConfig["rel"];
|
|
8
7
|
} & ({
|
|
9
|
-
field:
|
|
8
|
+
field: LinkField | null | undefined;
|
|
10
9
|
document?: never;
|
|
11
10
|
href?: never;
|
|
12
11
|
} | {
|
|
13
12
|
field?: never;
|
|
14
|
-
document:
|
|
13
|
+
document: PrismicDocument | null | undefined;
|
|
15
14
|
href?: never;
|
|
16
15
|
} | {
|
|
17
16
|
field?: never;
|
|
18
17
|
document?: never;
|
|
19
|
-
href:
|
|
18
|
+
href: ComponentProps<typeof Link>["href"];
|
|
20
19
|
});
|
|
21
|
-
export declare const PrismicNextLink:
|
|
20
|
+
export declare const PrismicNextLink: import("react").ForwardRefExoticComponent<(Omit<Omit<Omit<import("react").AnchorHTMLAttributes<HTMLAnchorElement>, keyof {
|
|
22
21
|
href: string | import("url").UrlObject;
|
|
23
|
-
as?:
|
|
24
|
-
replace?: boolean
|
|
25
|
-
scroll?: boolean
|
|
26
|
-
shallow?: boolean
|
|
27
|
-
passHref?: boolean
|
|
28
|
-
prefetch?: boolean | null
|
|
29
|
-
locale?: string | false
|
|
30
|
-
legacyBehavior?: boolean
|
|
31
|
-
onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement
|
|
32
|
-
onTouchStart?: React.TouchEventHandler<HTMLAnchorElement
|
|
33
|
-
onClick?: React.MouseEventHandler<HTMLAnchorElement
|
|
22
|
+
as?: string | import("url").UrlObject;
|
|
23
|
+
replace?: boolean;
|
|
24
|
+
scroll?: boolean;
|
|
25
|
+
shallow?: boolean;
|
|
26
|
+
passHref?: boolean;
|
|
27
|
+
prefetch?: boolean | null;
|
|
28
|
+
locale?: string | false;
|
|
29
|
+
legacyBehavior?: boolean;
|
|
30
|
+
onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement>;
|
|
31
|
+
onTouchStart?: React.TouchEventHandler<HTMLAnchorElement>;
|
|
32
|
+
onClick?: React.MouseEventHandler<HTMLAnchorElement>;
|
|
34
33
|
}> & {
|
|
35
34
|
href: string | import("url").UrlObject;
|
|
36
|
-
as?:
|
|
37
|
-
replace?: boolean
|
|
38
|
-
scroll?: boolean
|
|
39
|
-
shallow?: boolean
|
|
40
|
-
passHref?: boolean
|
|
41
|
-
prefetch?: boolean | null
|
|
42
|
-
locale?: string | false
|
|
43
|
-
legacyBehavior?: boolean
|
|
44
|
-
onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement
|
|
45
|
-
onTouchStart?: React.TouchEventHandler<HTMLAnchorElement
|
|
46
|
-
onClick?: React.MouseEventHandler<HTMLAnchorElement
|
|
35
|
+
as?: string | import("url").UrlObject;
|
|
36
|
+
replace?: boolean;
|
|
37
|
+
scroll?: boolean;
|
|
38
|
+
shallow?: boolean;
|
|
39
|
+
passHref?: boolean;
|
|
40
|
+
prefetch?: boolean | null;
|
|
41
|
+
locale?: string | false;
|
|
42
|
+
legacyBehavior?: boolean;
|
|
43
|
+
onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement>;
|
|
44
|
+
onTouchStart?: React.TouchEventHandler<HTMLAnchorElement>;
|
|
45
|
+
onClick?: React.MouseEventHandler<HTMLAnchorElement>;
|
|
47
46
|
} & {
|
|
48
|
-
children?: React.ReactNode;
|
|
49
|
-
} &
|
|
50
|
-
linkResolver?:
|
|
51
|
-
rel?: string |
|
|
47
|
+
children?: React.ReactNode | undefined;
|
|
48
|
+
} & import("react").RefAttributes<HTMLAnchorElement>, "rel" | "field" | "document" | "href"> & {
|
|
49
|
+
linkResolver?: LinkResolverFunction;
|
|
50
|
+
rel?: string | AsLinkAttrsConfig["rel"];
|
|
52
51
|
} & {
|
|
53
|
-
field:
|
|
54
|
-
document?:
|
|
55
|
-
href?:
|
|
56
|
-
}, "ref"> | Omit<Omit<Omit<
|
|
52
|
+
field: LinkField | null | undefined;
|
|
53
|
+
document?: never;
|
|
54
|
+
href?: never;
|
|
55
|
+
}, "ref"> | Omit<Omit<Omit<import("react").AnchorHTMLAttributes<HTMLAnchorElement>, keyof {
|
|
57
56
|
href: string | import("url").UrlObject;
|
|
58
|
-
as?:
|
|
59
|
-
replace?: boolean
|
|
60
|
-
scroll?: boolean
|
|
61
|
-
shallow?: boolean
|
|
62
|
-
passHref?: boolean
|
|
63
|
-
prefetch?: boolean | null
|
|
64
|
-
locale?: string | false
|
|
65
|
-
legacyBehavior?: boolean
|
|
66
|
-
onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement
|
|
67
|
-
onTouchStart?: React.TouchEventHandler<HTMLAnchorElement
|
|
68
|
-
onClick?: React.MouseEventHandler<HTMLAnchorElement
|
|
57
|
+
as?: string | import("url").UrlObject;
|
|
58
|
+
replace?: boolean;
|
|
59
|
+
scroll?: boolean;
|
|
60
|
+
shallow?: boolean;
|
|
61
|
+
passHref?: boolean;
|
|
62
|
+
prefetch?: boolean | null;
|
|
63
|
+
locale?: string | false;
|
|
64
|
+
legacyBehavior?: boolean;
|
|
65
|
+
onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement>;
|
|
66
|
+
onTouchStart?: React.TouchEventHandler<HTMLAnchorElement>;
|
|
67
|
+
onClick?: React.MouseEventHandler<HTMLAnchorElement>;
|
|
69
68
|
}> & {
|
|
70
69
|
href: string | import("url").UrlObject;
|
|
71
|
-
as?:
|
|
72
|
-
replace?: boolean
|
|
73
|
-
scroll?: boolean
|
|
74
|
-
shallow?: boolean
|
|
75
|
-
passHref?: boolean
|
|
76
|
-
prefetch?: boolean | null
|
|
77
|
-
locale?: string | false
|
|
78
|
-
legacyBehavior?: boolean
|
|
79
|
-
onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement
|
|
80
|
-
onTouchStart?: React.TouchEventHandler<HTMLAnchorElement
|
|
81
|
-
onClick?: React.MouseEventHandler<HTMLAnchorElement
|
|
70
|
+
as?: string | import("url").UrlObject;
|
|
71
|
+
replace?: boolean;
|
|
72
|
+
scroll?: boolean;
|
|
73
|
+
shallow?: boolean;
|
|
74
|
+
passHref?: boolean;
|
|
75
|
+
prefetch?: boolean | null;
|
|
76
|
+
locale?: string | false;
|
|
77
|
+
legacyBehavior?: boolean;
|
|
78
|
+
onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement>;
|
|
79
|
+
onTouchStart?: React.TouchEventHandler<HTMLAnchorElement>;
|
|
80
|
+
onClick?: React.MouseEventHandler<HTMLAnchorElement>;
|
|
82
81
|
} & {
|
|
83
|
-
children?: React.ReactNode;
|
|
84
|
-
} &
|
|
85
|
-
linkResolver?:
|
|
86
|
-
rel?: string |
|
|
82
|
+
children?: React.ReactNode | undefined;
|
|
83
|
+
} & import("react").RefAttributes<HTMLAnchorElement>, "rel" | "field" | "document" | "href"> & {
|
|
84
|
+
linkResolver?: LinkResolverFunction;
|
|
85
|
+
rel?: string | AsLinkAttrsConfig["rel"];
|
|
87
86
|
} & {
|
|
88
|
-
field?:
|
|
89
|
-
document:
|
|
90
|
-
href?:
|
|
91
|
-
}, "ref"> | Omit<Omit<Omit<
|
|
87
|
+
field?: never;
|
|
88
|
+
document: PrismicDocument | null | undefined;
|
|
89
|
+
href?: never;
|
|
90
|
+
}, "ref"> | Omit<Omit<Omit<import("react").AnchorHTMLAttributes<HTMLAnchorElement>, keyof {
|
|
92
91
|
href: string | import("url").UrlObject;
|
|
93
|
-
as?:
|
|
94
|
-
replace?: boolean
|
|
95
|
-
scroll?: boolean
|
|
96
|
-
shallow?: boolean
|
|
97
|
-
passHref?: boolean
|
|
98
|
-
prefetch?: boolean | null
|
|
99
|
-
locale?: string | false
|
|
100
|
-
legacyBehavior?: boolean
|
|
101
|
-
onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement
|
|
102
|
-
onTouchStart?: React.TouchEventHandler<HTMLAnchorElement
|
|
103
|
-
onClick?: React.MouseEventHandler<HTMLAnchorElement
|
|
92
|
+
as?: string | import("url").UrlObject;
|
|
93
|
+
replace?: boolean;
|
|
94
|
+
scroll?: boolean;
|
|
95
|
+
shallow?: boolean;
|
|
96
|
+
passHref?: boolean;
|
|
97
|
+
prefetch?: boolean | null;
|
|
98
|
+
locale?: string | false;
|
|
99
|
+
legacyBehavior?: boolean;
|
|
100
|
+
onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement>;
|
|
101
|
+
onTouchStart?: React.TouchEventHandler<HTMLAnchorElement>;
|
|
102
|
+
onClick?: React.MouseEventHandler<HTMLAnchorElement>;
|
|
104
103
|
}> & {
|
|
105
104
|
href: string | import("url").UrlObject;
|
|
106
|
-
as?:
|
|
107
|
-
replace?: boolean
|
|
108
|
-
scroll?: boolean
|
|
109
|
-
shallow?: boolean
|
|
110
|
-
passHref?: boolean
|
|
111
|
-
prefetch?: boolean | null
|
|
112
|
-
locale?: string | false
|
|
113
|
-
legacyBehavior?: boolean
|
|
114
|
-
onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement
|
|
115
|
-
onTouchStart?: React.TouchEventHandler<HTMLAnchorElement
|
|
116
|
-
onClick?: React.MouseEventHandler<HTMLAnchorElement
|
|
105
|
+
as?: string | import("url").UrlObject;
|
|
106
|
+
replace?: boolean;
|
|
107
|
+
scroll?: boolean;
|
|
108
|
+
shallow?: boolean;
|
|
109
|
+
passHref?: boolean;
|
|
110
|
+
prefetch?: boolean | null;
|
|
111
|
+
locale?: string | false;
|
|
112
|
+
legacyBehavior?: boolean;
|
|
113
|
+
onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement>;
|
|
114
|
+
onTouchStart?: React.TouchEventHandler<HTMLAnchorElement>;
|
|
115
|
+
onClick?: React.MouseEventHandler<HTMLAnchorElement>;
|
|
117
116
|
} & {
|
|
118
|
-
children?: React.ReactNode;
|
|
119
|
-
} &
|
|
120
|
-
linkResolver?:
|
|
121
|
-
rel?: string |
|
|
117
|
+
children?: React.ReactNode | undefined;
|
|
118
|
+
} & import("react").RefAttributes<HTMLAnchorElement>, "rel" | "field" | "document" | "href"> & {
|
|
119
|
+
linkResolver?: LinkResolverFunction;
|
|
120
|
+
rel?: string | AsLinkAttrsConfig["rel"];
|
|
122
121
|
} & {
|
|
123
|
-
field?:
|
|
124
|
-
document?:
|
|
125
|
-
href:
|
|
126
|
-
}, "ref">) &
|
|
122
|
+
field?: never;
|
|
123
|
+
document?: never;
|
|
124
|
+
href: ComponentProps<typeof Link>["href"];
|
|
125
|
+
}, "ref">) & import("react").RefAttributes<HTMLAnchorElement>>;
|
package/dist/PrismicNextLink.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
'use client';
|
|
3
1
|
import { jsx } from "react/jsx-runtime";
|
|
4
|
-
import
|
|
2
|
+
import { forwardRef } from "react";
|
|
5
3
|
import Link from "next/link";
|
|
6
|
-
import { asLinkAttrs } from
|
|
7
|
-
const PrismicNextLink =
|
|
4
|
+
import { asLinkAttrs } from "@prismicio/client";
|
|
5
|
+
const PrismicNextLink = forwardRef(function PrismicNextLink2(props, ref) {
|
|
8
6
|
const { field, document, linkResolver, children, ...restProps } = props;
|
|
9
7
|
const { href: computedHref, rel: computedRel, ...attrs } = asLinkAttrs(field ?? document, {
|
|
10
8
|
linkResolver,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicNextLink.js","sources":["
|
|
1
|
+
{"version":3,"file":"PrismicNextLink.js","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;"}
|
package/dist/PrismicPreview.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
/**
|
|
3
|
-
* Props for `<PrismicPreview>`.
|
|
4
|
-
*/
|
|
1
|
+
import type { ReactNode, JSX } from "react";
|
|
2
|
+
/** Props for `<PrismicPreview>`. */
|
|
5
3
|
export type PrismicPreviewProps = {
|
|
6
4
|
/**
|
|
7
5
|
* The name of your Prismic repository. A Prismic Toolbar will be registered
|
|
@@ -9,23 +7,17 @@ export type PrismicPreviewProps = {
|
|
|
9
7
|
*/
|
|
10
8
|
repositoryName: string;
|
|
11
9
|
/**
|
|
12
|
-
* **Only used in the Pages Directory (/pages).**
|
|
13
|
-
*
|
|
14
10
|
* The URL of your app's Prismic preview endpoint (default: `/api/preview`).
|
|
15
11
|
* This URL will be fetched on preview update events.
|
|
16
12
|
*/
|
|
17
13
|
updatePreviewURL?: string;
|
|
18
14
|
/**
|
|
19
|
-
* **Only used in the Pages Directory (/pages).**
|
|
20
|
-
*
|
|
21
15
|
* The URL of your app's exit preview endpoint (default: `/api/exit-preview`).
|
|
22
16
|
* This URL will be fetched on preview exit events.
|
|
23
17
|
*/
|
|
24
18
|
exitPreviewURL?: string;
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
*/
|
|
28
|
-
children?: React.ReactNode;
|
|
19
|
+
/** Children to render adjacent to the Prismic Toolbar. */
|
|
20
|
+
children?: ReactNode;
|
|
29
21
|
};
|
|
30
22
|
/**
|
|
31
23
|
* React component that sets up Prismic Previews using the Prismic Toolbar. When
|
|
@@ -36,4 +28,4 @@ export type PrismicPreviewProps = {
|
|
|
36
28
|
* This component can be wrapped around your app or added anywhere in your app's
|
|
37
29
|
* tree. It must be rendered on every page.
|
|
38
30
|
*/
|
|
39
|
-
export declare function PrismicPreview(
|
|
31
|
+
export declare function PrismicPreview(props: PrismicPreviewProps): Promise<JSX.Element>;
|
package/dist/PrismicPreview.js
CHANGED
|
@@ -1,26 +1,13 @@
|
|
|
1
1
|
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
2
2
|
import Script from "next/script";
|
|
3
|
-
import {
|
|
4
|
-
import { useRouter } from "next/router";
|
|
3
|
+
import { getToolbarSrc } from "@prismicio/client";
|
|
5
4
|
import { PrismicPreviewClient } from "./PrismicPreviewClient.js";
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
async function PrismicPreview(props) {
|
|
6
|
+
const { repositoryName, children, ...otherProps } = props;
|
|
7
|
+
const { draftMode } = await import("next/headers");
|
|
8
8
|
const toolbarSrc = getToolbarSrc(repositoryName);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
let isAppRouter = true;
|
|
12
|
-
try {
|
|
13
|
-
useRouter();
|
|
14
|
-
isAppRouter = false;
|
|
15
|
-
} catch {
|
|
16
|
-
}
|
|
17
|
-
if (isAppRouter) {
|
|
18
|
-
return new Promise(async (res) => {
|
|
19
|
-
isDraftMode = (await draftMode()).isEnabled;
|
|
20
|
-
res(result);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
return result;
|
|
9
|
+
const isDraftMode = (await draftMode()).isEnabled;
|
|
10
|
+
return jsxs(Fragment, { children: [children, jsx(PrismicPreviewClient, { repositoryName, isDraftMode, ...otherProps }), jsx(Script, { src: toolbarSrc, strategy: "lazyOnload" })] });
|
|
24
11
|
}
|
|
25
12
|
export {
|
|
26
13
|
PrismicPreview
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicPreview.js","sources":["
|
|
1
|
+
{"version":3,"file":"PrismicPreview.js","sources":["../src/PrismicPreview.tsx"],"sourcesContent":["import type { ReactNode, JSX } from \"react\";\nimport Script from \"next/script\";\nimport { getToolbarSrc } from \"@prismicio/client\";\n\nimport { PrismicPreviewClient } from \"./PrismicPreviewClient.js\";\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 async function PrismicPreview(\n\tprops: PrismicPreviewProps,\n): Promise<JSX.Element> {\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,eAAsB,eACrB,OAA0B;AAE1B,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;"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
type PrismicPreviewClientProps = {
|
|
2
|
+
repositoryName: string;
|
|
3
3
|
isDraftMode: boolean;
|
|
4
|
+
updatePreviewURL?: string;
|
|
5
|
+
exitPreviewURL?: string;
|
|
4
6
|
};
|
|
5
|
-
export declare function PrismicPreviewClient(
|
|
7
|
+
export declare function PrismicPreviewClient(props: PrismicPreviewClientProps): null;
|
|
6
8
|
export {};
|