@prismicio/next 2.0.1 → 2.0.2-canary.6f580fa
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/dist/PrismicNextImage.cjs +66 -56
- package/dist/PrismicNextImage.cjs.map +1 -1
- package/dist/PrismicNextImage.d.cts +57 -0
- package/dist/PrismicNextLink.cjs +29 -21
- package/dist/PrismicNextLink.cjs.map +1 -1
- package/dist/PrismicNextLink.d.cts +54 -0
- package/dist/PrismicNextRichText.cjs +34 -0
- package/dist/PrismicNextRichText.cjs.map +1 -0
- package/dist/PrismicNextRichText.d.cts +11 -0
- package/dist/PrismicPreview.cjs +38 -36
- package/dist/PrismicPreview.cjs.map +1 -1
- package/dist/PrismicPreview.d.cts +36 -0
- package/dist/PrismicPreviewClient.cjs +71 -65
- package/dist/PrismicPreviewClient.cjs.map +1 -1
- package/dist/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/createLocaleRedirect.cjs +11 -5
- package/dist/createLocaleRedirect.cjs.map +1 -1
- package/dist/createLocaleRedirect.d.cts +14 -0
- package/dist/enableAutoPreviews.cjs +27 -48
- package/dist/enableAutoPreviews.cjs.map +1 -1
- package/dist/enableAutoPreviews.d.cts +18 -0
- package/dist/exitPreview.cjs +24 -32
- package/dist/exitPreview.cjs.map +1 -1
- package/dist/{exitPreview.d.ts → exitPreview.d.cts} +5 -1
- package/dist/imgixLoader.cjs +21 -14
- package/dist/imgixLoader.cjs.map +1 -1
- package/dist/{imgixLoader.d.ts → imgixLoader.d.cts} +7 -1
- package/dist/index.cjs +19 -19
- package/dist/index.d.cts +11 -0
- package/dist/lib/devMsg.cjs +22 -5
- package/dist/lib/devMsg.cjs.map +1 -1
- package/dist/lib/resolveDefaultExport.cjs +23 -4
- package/dist/lib/resolveDefaultExport.cjs.map +1 -1
- package/dist/package.cjs +12 -0
- package/dist/package.cjs.map +1 -0
- package/dist/pages/PrismicPreview.cjs +71 -59
- package/dist/pages/PrismicPreview.cjs.map +1 -1
- package/dist/pages/PrismicPreview.d.cts +36 -0
- package/dist/pages/enableAutoPreviews.cjs +21 -14
- package/dist/pages/enableAutoPreviews.cjs.map +1 -1
- package/dist/pages/enableAutoPreviews.d.cts +37 -0
- package/dist/pages/exitPreview.cjs +24 -7
- package/dist/pages/exitPreview.cjs.map +1 -1
- package/dist/pages/exitPreview.d.cts +38 -0
- package/dist/pages/redirectToPreviewURL.cjs +13 -13
- package/dist/pages/redirectToPreviewURL.cjs.map +1 -1
- package/dist/pages/redirectToPreviewURL.d.cts +48 -0
- package/dist/pages/setPreviewData.cjs +10 -8
- package/dist/pages/setPreviewData.cjs.map +1 -1
- package/dist/pages/setPreviewData.d.cts +26 -0
- package/dist/pages/types.d.cts +36 -0
- package/dist/pages.cjs +21 -21
- package/dist/pages.d.cts +12 -0
- package/dist/redirectToPreviewURL.cjs +21 -43
- package/dist/redirectToPreviewURL.cjs.map +1 -1
- package/dist/redirectToPreviewURL.d.cts +33 -0
- package/dist/types.d.cts +31 -0
- package/package.json +34 -49
- package/src/PrismicNextImage.tsx +10 -6
- package/src/PrismicNextLink.tsx +5 -3
- package/src/PrismicNextRichText.tsx +41 -0
- package/src/PrismicPreviewClient.tsx +2 -3
- package/src/createLocaleRedirect.ts +1 -1
- package/src/imgixLoader.ts +3 -2
- package/src/index.ts +3 -0
- package/src/lib/devMsg.ts +1 -1
- package/src/pages/PrismicPreview.tsx +2 -1
- package/src/pages/index.ts +3 -0
- package/src/pages/types.ts +2 -3
- package/src/redirectToPreviewURL.ts +1 -1
- package/dist/PrismicNextImage.d.ts +0 -54
- package/dist/PrismicNextLink.d.ts +0 -125
- package/dist/PrismicPreview.d.ts +0 -31
- package/dist/PrismicPreviewClient.d.ts +0 -9
- package/dist/createLocaleRedirect.d.ts +0 -10
- package/dist/enableAutoPreviews.d.ts +0 -13
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts +0 -15
- package/dist/lib/devMsg.d.ts +0 -16
- package/dist/lib/resolveDefaultExport.d.ts +0 -18
- package/dist/package.json.cjs +0 -5
- package/dist/package.json.cjs.map +0 -1
- package/dist/pages/PrismicPreview.d.ts +0 -31
- package/dist/pages/enableAutoPreviews.d.ts +0 -31
- package/dist/pages/exitPreview.d.ts +0 -33
- package/dist/pages/index.d.ts +0 -18
- package/dist/pages/redirectToPreviewURL.d.ts +0 -43
- package/dist/pages/setPreviewData.d.ts +0 -18
- package/dist/pages/types.d.ts +0 -30
- package/dist/pages.cjs.map +0 -1
- package/dist/redirectToPreviewURL.d.ts +0 -28
- package/dist/types.d.ts +0 -26
|
@@ -1,61 +1,71 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
|
|
3
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
4
|
+
const require_resolveDefaultExport = require('./lib/resolveDefaultExport.cjs');
|
|
5
|
+
const require_devMsg = require('./lib/devMsg.cjs');
|
|
6
|
+
const require_imgixLoader = require('./imgixLoader.cjs');
|
|
7
|
+
let _prismicio_client = require("@prismicio/client");
|
|
8
|
+
let react = require("react");
|
|
9
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
10
|
+
let next_image = require("next/image");
|
|
11
|
+
next_image = require_rolldown_runtime.__toESM(next_image);
|
|
12
|
+
let imgix_url_builder = require("imgix-url-builder");
|
|
13
|
+
|
|
14
|
+
//#region src/PrismicNextImage.tsx
|
|
12
15
|
const castInt = (input) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
} else {
|
|
20
|
-
return parsed;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
16
|
+
if (typeof input === "number" || typeof input === "undefined") return input;
|
|
17
|
+
else {
|
|
18
|
+
const parsed = Number.parseInt(input);
|
|
19
|
+
if (Number.isNaN(parsed)) return;
|
|
20
|
+
else return parsed;
|
|
21
|
+
}
|
|
23
22
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
23
|
+
/**
|
|
24
|
+
* React component that renders an image from a Prismic Image field or one of
|
|
25
|
+
* its thumbnails using `next/image`. It will automatically set the `alt`
|
|
26
|
+
* attribute using the Image field's `alt` property.
|
|
27
|
+
*
|
|
28
|
+
* It uses an Imgix URL-based loader by default. A custom loader can be provided
|
|
29
|
+
* with the `loader` prop. If you would like to use the Next.js Image
|
|
30
|
+
* Optimization API instead, set `loader={undefined}`.
|
|
31
|
+
*
|
|
32
|
+
* @param props - Props for the component.
|
|
33
|
+
*
|
|
34
|
+
* @returns A responsive image component using `next/image` for the given Image
|
|
35
|
+
* field.
|
|
36
|
+
*
|
|
37
|
+
* @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image
|
|
38
|
+
*/
|
|
39
|
+
const PrismicNextImage = (0, react.forwardRef)(function PrismicNextImage$1({ field, imgixParams = {}, alt, fallbackAlt, fill, width, height, fallback = null, loader = require_imgixLoader.imgixLoader, ...restProps }, ref) {
|
|
40
|
+
if (process.env.NODE_ENV === "development") {
|
|
41
|
+
if (typeof alt === "string" && alt !== "") 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 ${require_devMsg.devMsg("alt-must-be-an-empty-string")}`);
|
|
42
|
+
if (typeof fallbackAlt === "string" && fallbackAlt !== "") 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 ${require_devMsg.devMsg("alt-must-be-an-empty-string")}`);
|
|
43
|
+
}
|
|
44
|
+
if (!_prismicio_client.isFilled.imageThumbnail(field)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: fallback });
|
|
45
|
+
const resolvedImgixParams = imgixParams;
|
|
46
|
+
for (const x in imgixParams) if (resolvedImgixParams[x] === null) resolvedImgixParams[x] = void 0;
|
|
47
|
+
const src = (0, imgix_url_builder.buildURL)(field.url, imgixParams);
|
|
48
|
+
const ar = field.dimensions.width / field.dimensions.height;
|
|
49
|
+
const castedWidth = castInt(width);
|
|
50
|
+
const castedHeight = castInt(height);
|
|
51
|
+
let resolvedWidth = castedWidth ?? field.dimensions.width;
|
|
52
|
+
let resolvedHeight = castedHeight ?? field.dimensions.height;
|
|
53
|
+
if (castedWidth != null && castedHeight == null) resolvedHeight = castedWidth / ar;
|
|
54
|
+
else if (castedWidth == null && castedHeight != null) resolvedWidth = castedHeight * ar;
|
|
55
|
+
const resolvedAlt = alt ?? (field.alt || fallbackAlt);
|
|
56
|
+
if (process.env.NODE_ENV === "development" && typeof resolvedAlt !== "string") 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);
|
|
57
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_resolveDefaultExport.resolveDefaultExport(next_image.default), {
|
|
58
|
+
ref,
|
|
59
|
+
src,
|
|
60
|
+
width: fill ? void 0 : resolvedWidth,
|
|
61
|
+
height: fill ? void 0 : resolvedHeight,
|
|
62
|
+
alt: resolvedAlt,
|
|
63
|
+
fill,
|
|
64
|
+
loader: loader === null ? void 0 : loader,
|
|
65
|
+
...restProps
|
|
66
|
+
});
|
|
59
67
|
});
|
|
68
|
+
|
|
69
|
+
//#endregion
|
|
60
70
|
exports.PrismicNextImage = PrismicNextImage;
|
|
61
|
-
//# sourceMappingURL=PrismicNextImage.cjs.map
|
|
71
|
+
//# sourceMappingURL=PrismicNextImage.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicNextImage.cjs","sources":["../src/PrismicNextImage.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n\
|
|
1
|
+
{"version":3,"file":"PrismicNextImage.cjs","names":["PrismicNextImage","imgixLoader","devMsg","isFilled","resolveDefaultExport","Image"],"sources":["../src/PrismicNextImage.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n\tForwardRefExoticComponent,\n\tPropsWithoutRef,\n\tRefAttributes} from \"react\";\nimport {\n\tforwardRef\n} from \"react\";\nimport type { ImageProps } from \"next/image\";\nimport Image from \"next/image\";\nimport type { ImgixURLParams } from \"imgix-url-builder\";\nimport { buildURL } from \"imgix-url-builder\";\nimport type { ImageFieldImage} from \"@prismicio/client\";\nimport { isFilled } from \"@prismicio/client\";\n\nimport { devMsg } from \"./lib/devMsg\";\nimport { resolveDefaultExport } from \"./lib/resolveDefaultExport\";\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 (process.env.NODE_ENV === \"development\") {\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 (\n\t\t\tprocess.env.NODE_ENV === \"development\" &&\n\t\t\ttypeof resolvedAlt !== \"string\"\n\t\t) {\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\tconst ResolvedImage = resolveDefaultExport(Image);\n\n\t\treturn (\n\t\t\t<ResolvedImage\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"],"mappings":";;;;;;;;;;;;;;AAqBA,MAAM,WAAW,UAA2D;AAC3E,KAAI,OAAO,UAAU,YAAY,OAAO,UAAU,YACjD,QAAO;MACD;EACN,MAAM,SAAS,OAAO,SAAS,MAAM;AAErC,MAAI,OAAO,MAAM,OAAO,CACvB;MAEA,QAAO;;;;;;;;;;;;;;;;;;;AA8DV,MAAa,yCAGZ,SAASA,mBACR,EACC,OACA,cAAc,EAAE,EAChB,KACA,aACA,MACA,OACA,QACA,WAAW,MACX,SAASC,iCACT,GAAG,aAEJ,KACC;AACD,KAAI,QAAQ,IAAI,aAAa,eAAe;AAC3C,MAAI,OAAO,QAAQ,YAAY,QAAQ,GACtC,SAAQ,KACP,yQAAyQC,sBACxQ,8BACA,GACD;AAGF,MAAI,OAAO,gBAAgB,YAAY,gBAAgB,GACtD,SAAQ,KACP,ySAAySA,sBACxS,8BACA,GACD;;AAIH,KAAI,CAACC,2BAAS,eAAe,MAAM,CAClC,QAAO,mFAAG,WAAY;CAGvB,MAAM,sBAAsB;AAC5B,MAAK,MAAM,KAAK,YACf,KAAI,oBAAoB,OAA2C,KAClE,qBAAoB,KAAyC;CAI/D,MAAM,sCAAe,MAAM,KAAK,YAA8B;CAE9D,MAAM,KAAK,MAAM,WAAW,QAAQ,MAAM,WAAW;CAErD,MAAM,cAAc,QAAQ,MAAM;CAClC,MAAM,eAAe,QAAQ,OAAO;CAEpC,IAAI,gBAAgB,eAAe,MAAM,WAAW;CACpD,IAAI,iBAAiB,gBAAgB,MAAM,WAAW;AAEtD,KAAI,eAAe,QAAQ,gBAAgB,KAC1C,kBAAiB,cAAc;UACrB,eAAe,QAAQ,gBAAgB,KACjD,iBAAgB,eAAe;CAKhC,MAAM,cAAe,QAAQ,MAAM,OAAO;AAE1C,KACC,QAAQ,IAAI,aAAa,iBACzB,OAAO,gBAAgB,SAEvB,SAAQ,MACP,mNACA,IACA;AAKF,QACC,2CAHqBC,kDAAqBC,mBAAM;EAI1C;EACA;EACL,OAAO,OAAO,SAAY;EAC1B,QAAQ,OAAO,SAAY;EAC3B,KAAK;EACC;EACN,QAAQ,WAAW,OAAO,SAAY;EACtC,GAAI;GACH;EAGJ"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ForwardRefExoticComponent, PropsWithoutRef, RefAttributes } from "react";
|
|
2
|
+
import { ImageFieldImage } from "@prismicio/client";
|
|
3
|
+
import { ImageProps } from "next/image";
|
|
4
|
+
import { ImgixURLParams } from "imgix-url-builder";
|
|
5
|
+
|
|
6
|
+
//#region src/PrismicNextImage.d.ts
|
|
7
|
+
type PrismicNextImageProps = Omit<ImageProps, "src" | "alt" | "loader"> & {
|
|
8
|
+
/** The Prismic Image field or thumbnail to render. */
|
|
9
|
+
field: ImageFieldImage | null | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* An object of Imgix URL API parameters to transform the image.
|
|
12
|
+
*
|
|
13
|
+
* @see https://docs.imgix.com/apis/rendering
|
|
14
|
+
*/
|
|
15
|
+
imgixParams?: { [P in keyof ImgixURLParams]: ImgixURLParams[P] | null };
|
|
16
|
+
/**
|
|
17
|
+
* Declare an image as decorative by providing `alt=""`.
|
|
18
|
+
*
|
|
19
|
+
* See:
|
|
20
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
21
|
+
*/
|
|
22
|
+
alt?: "";
|
|
23
|
+
/**
|
|
24
|
+
* Declare an image as decorative only if the Image field does not have
|
|
25
|
+
* alternative text by providing `fallbackAlt=""`.
|
|
26
|
+
*
|
|
27
|
+
* See:
|
|
28
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
29
|
+
*/
|
|
30
|
+
fallbackAlt?: "";
|
|
31
|
+
/**
|
|
32
|
+
* Rendered when the field is empty. If a fallback is not given, `null` will
|
|
33
|
+
* be rendered.
|
|
34
|
+
*/
|
|
35
|
+
fallback?: React.ReactNode;
|
|
36
|
+
loader?: ImageProps["loader"] | null;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* React component that renders an image from a Prismic Image field or one of
|
|
40
|
+
* its thumbnails using `next/image`. It will automatically set the `alt`
|
|
41
|
+
* attribute using the Image field's `alt` property.
|
|
42
|
+
*
|
|
43
|
+
* It uses an Imgix URL-based loader by default. A custom loader can be provided
|
|
44
|
+
* with the `loader` prop. If you would like to use the Next.js Image
|
|
45
|
+
* Optimization API instead, set `loader={undefined}`.
|
|
46
|
+
*
|
|
47
|
+
* @param props - Props for the component.
|
|
48
|
+
*
|
|
49
|
+
* @returns A responsive image component using `next/image` for the given Image
|
|
50
|
+
* field.
|
|
51
|
+
*
|
|
52
|
+
* @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image
|
|
53
|
+
*/
|
|
54
|
+
declare const PrismicNextImage: ForwardRefExoticComponent<PropsWithoutRef<PrismicNextImageProps> & RefAttributes<HTMLImageElement>>;
|
|
55
|
+
//#endregion
|
|
56
|
+
export { PrismicNextImage, PrismicNextImageProps };
|
|
57
|
+
//# sourceMappingURL=PrismicNextImage.d.cts.map
|
package/dist/PrismicNextLink.cjs
CHANGED
|
@@ -1,23 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_resolveDefaultExport = require('./lib/resolveDefaultExport.cjs');
|
|
3
|
+
let _prismicio_client = require("@prismicio/client");
|
|
4
|
+
let react = require("react");
|
|
5
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
6
|
+
let next_link = require("next/link");
|
|
7
|
+
next_link = require_rolldown_runtime.__toESM(next_link);
|
|
8
|
+
|
|
9
|
+
//#region src/PrismicNextLink.tsx
|
|
10
|
+
const PrismicNextLink = (0, react.forwardRef)(function PrismicNextLink$1(props, ref) {
|
|
11
|
+
const { field, document, linkResolver, children, ...restProps } = props;
|
|
12
|
+
const { href: computedHref, rel: computedRel, ...attrs } = (0, _prismicio_client.asLinkAttrs)(field ?? document, {
|
|
13
|
+
linkResolver,
|
|
14
|
+
rel: typeof restProps.rel === "function" ? restProps.rel : void 0
|
|
15
|
+
});
|
|
16
|
+
const href = ("href" in restProps ? restProps.href : computedHref) || "";
|
|
17
|
+
let rel = computedRel;
|
|
18
|
+
if ("rel" in restProps && typeof restProps.rel !== "function") rel = restProps.rel;
|
|
19
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_resolveDefaultExport.resolveDefaultExport(next_link.default), {
|
|
20
|
+
ref,
|
|
21
|
+
...attrs,
|
|
22
|
+
...restProps,
|
|
23
|
+
href,
|
|
24
|
+
rel,
|
|
25
|
+
children: "children" in props ? children : field?.text
|
|
26
|
+
});
|
|
21
27
|
});
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
22
30
|
exports.PrismicNextLink = PrismicNextLink;
|
|
23
|
-
//# sourceMappingURL=PrismicNextLink.cjs.map
|
|
31
|
+
//# sourceMappingURL=PrismicNextLink.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicNextLink.cjs","sources":["../src/PrismicNextLink.tsx"],"sourcesContent":["import { ComponentProps
|
|
1
|
+
{"version":3,"file":"PrismicNextLink.cjs","names":["PrismicNextLink","resolveDefaultExport","Link"],"sources":["../src/PrismicNextLink.tsx"],"sourcesContent":["import type { ComponentProps} from \"react\";\nimport { forwardRef } from \"react\";\nimport Link from \"next/link\";\nimport type {\n\tAsLinkAttrsConfig,\n\tLinkField,\n\tLinkResolverFunction,\n\tPrismicDocument} from \"@prismicio/client\";\nimport {\n\tasLinkAttrs,\n} from \"@prismicio/client\";\n\nimport { resolveDefaultExport } from \"./lib/resolveDefaultExport\";\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\tconst ResolvedLink = resolveDefaultExport(Link);\n\n\treturn (\n\t\t<ResolvedLink ref={ref} {...attrs} {...restProps} href={href} rel={rel}>\n\t\t\t{\"children\" in props ? children : field?.text}\n\t\t</ResolvedLink>\n\t);\n});\n"],"mappings":";;;;;;;;;AAsCA,MAAa,wCAGX,SAASA,kBAAgB,OAAO,KAAK;CACtC,MAAM,EAAE,OAAO,UAAU,cAAc,UAAU,GAAG,cAAc;CAClE,MAAM,EACL,MAAM,cACN,KAAK,aACL,GAAG,6CACY,SAAS,UAAU;EAClC;EACA,KAAK,OAAO,UAAU,QAAQ,aAAa,UAAU,MAAM;EAC3D,CAAC;CAEF,MAAM,QAAQ,UAAU,YAAY,UAAU,OAAO,iBAAiB;CAEtE,IAAI,MAAM;AACV,KAAI,SAAS,aAAa,OAAO,UAAU,QAAQ,WAClD,OAAM,UAAU;AAKjB,QACC,2CAHoBC,kDAAqBC,kBAAK;EAG3B;EAAK,GAAI;EAAO,GAAI;EAAiB;EAAW;YACjE,cAAc,QAAQ,WAAW,OAAO;GAC3B;EAEf"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as react0 from "react";
|
|
2
|
+
import { ComponentProps } from "react";
|
|
3
|
+
import * as next_link0 from "next/link";
|
|
4
|
+
import Link from "next/link";
|
|
5
|
+
import { AsLinkAttrsConfig, LinkField, LinkResolverFunction, PrismicDocument } from "@prismicio/client";
|
|
6
|
+
|
|
7
|
+
//#region src/PrismicNextLink.d.ts
|
|
8
|
+
type PrismicNextLinkProps = Omit<ComponentProps<typeof Link>, "field" | "document" | "href" | "rel"> & {
|
|
9
|
+
linkResolver?: LinkResolverFunction;
|
|
10
|
+
rel?: string | AsLinkAttrsConfig["rel"];
|
|
11
|
+
} & ({
|
|
12
|
+
field: LinkField | null | undefined;
|
|
13
|
+
document?: never;
|
|
14
|
+
href?: never;
|
|
15
|
+
} | {
|
|
16
|
+
field?: never;
|
|
17
|
+
document: PrismicDocument | null | undefined;
|
|
18
|
+
href?: never;
|
|
19
|
+
} | {
|
|
20
|
+
field?: never;
|
|
21
|
+
document?: never;
|
|
22
|
+
href: ComponentProps<typeof Link>["href"];
|
|
23
|
+
});
|
|
24
|
+
declare const PrismicNextLink: react0.ForwardRefExoticComponent<(Omit<Omit<Omit<react0.AnchorHTMLAttributes<HTMLAnchorElement>, keyof next_link0.LinkProps<any>> & next_link0.LinkProps<any> & {
|
|
25
|
+
children?: React.ReactNode | undefined;
|
|
26
|
+
} & react0.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
|
|
27
|
+
linkResolver?: LinkResolverFunction;
|
|
28
|
+
rel?: string | AsLinkAttrsConfig["rel"];
|
|
29
|
+
} & {
|
|
30
|
+
field: LinkField | null | undefined;
|
|
31
|
+
document?: never;
|
|
32
|
+
href?: never;
|
|
33
|
+
}, "ref"> | Omit<Omit<Omit<react0.AnchorHTMLAttributes<HTMLAnchorElement>, keyof next_link0.LinkProps<any>> & next_link0.LinkProps<any> & {
|
|
34
|
+
children?: React.ReactNode | undefined;
|
|
35
|
+
} & react0.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
|
|
36
|
+
linkResolver?: LinkResolverFunction;
|
|
37
|
+
rel?: string | AsLinkAttrsConfig["rel"];
|
|
38
|
+
} & {
|
|
39
|
+
field?: never;
|
|
40
|
+
document: PrismicDocument | null | undefined;
|
|
41
|
+
href?: never;
|
|
42
|
+
}, "ref"> | Omit<Omit<Omit<react0.AnchorHTMLAttributes<HTMLAnchorElement>, keyof next_link0.LinkProps<any>> & next_link0.LinkProps<any> & {
|
|
43
|
+
children?: React.ReactNode | undefined;
|
|
44
|
+
} & react0.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "href" | "document"> & {
|
|
45
|
+
linkResolver?: LinkResolverFunction;
|
|
46
|
+
rel?: string | AsLinkAttrsConfig["rel"];
|
|
47
|
+
} & {
|
|
48
|
+
field?: never;
|
|
49
|
+
document?: never;
|
|
50
|
+
href: ComponentProps<typeof Link>["href"];
|
|
51
|
+
}, "ref">) & react0.RefAttributes<HTMLAnchorElement>>;
|
|
52
|
+
//#endregion
|
|
53
|
+
export { PrismicNextLink, PrismicNextLinkProps };
|
|
54
|
+
//# sourceMappingURL=PrismicNextLink.d.cts.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_PrismicNextLink = require('./PrismicNextLink.cjs');
|
|
3
|
+
const require_PrismicNextImage = require('./PrismicNextImage.cjs');
|
|
4
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
5
|
+
let _prismicio_react = require("@prismicio/react");
|
|
6
|
+
|
|
7
|
+
//#region src/PrismicNextRichText.tsx
|
|
8
|
+
const defaultComponents = {
|
|
9
|
+
image: ({ node }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
10
|
+
className: "block-img",
|
|
11
|
+
children: node.linkTo ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PrismicNextLink.PrismicNextLink, {
|
|
12
|
+
field: node.linkTo,
|
|
13
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PrismicNextImage.PrismicNextImage, { field: node })
|
|
14
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PrismicNextImage.PrismicNextImage, { field: node })
|
|
15
|
+
}),
|
|
16
|
+
hyperlink: ({ node, children }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PrismicNextLink.PrismicNextLink, {
|
|
17
|
+
field: node.data,
|
|
18
|
+
children
|
|
19
|
+
})
|
|
20
|
+
};
|
|
21
|
+
const PrismicNextRichText = (props) => {
|
|
22
|
+
const { components, ...restProps } = props;
|
|
23
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_prismicio_react.PrismicRichText, {
|
|
24
|
+
components: {
|
|
25
|
+
...defaultComponents,
|
|
26
|
+
...components
|
|
27
|
+
},
|
|
28
|
+
...restProps
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
exports.PrismicNextRichText = PrismicNextRichText;
|
|
34
|
+
//# sourceMappingURL=PrismicNextRichText.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrismicNextRichText.cjs","names":["PrismicNextLink","PrismicNextImage","PrismicRichText"],"sources":["../src/PrismicNextRichText.tsx"],"sourcesContent":["import type { FC } from \"react\";\nimport { PrismicRichText } from \"@prismicio/react\";\nimport type { PrismicRichTextProps, JSXMapSerializer } from \"@prismicio/react\";\n\nimport { PrismicNextImage } from \"./PrismicNextImage\";\nimport { PrismicNextLink } from \"./PrismicNextLink\";\n\nexport type PrismicNextRichTextProps = Omit<\n\tPrismicRichTextProps,\n\t\"components\"\n> & {\n\tcomponents?: JSXMapSerializer;\n};\n\nconst defaultComponents: JSXMapSerializer = {\n\timage: ({ node }) => (\n\t\t<p className=\"block-img\">\n\t\t\t{node.linkTo ? (\n\t\t\t\t<PrismicNextLink field={node.linkTo}>\n\t\t\t\t\t<PrismicNextImage field={node} />\n\t\t\t\t</PrismicNextLink>\n\t\t\t) : (\n\t\t\t\t<PrismicNextImage field={node} />\n\t\t\t)}\n\t\t</p>\n\t),\n\thyperlink: ({ node, children }) => (\n\t\t<PrismicNextLink field={node.data}>{children}</PrismicNextLink>\n\t),\n};\n\nexport const PrismicNextRichText: FC<PrismicNextRichTextProps> = (props) => {\n\tconst { components, ...restProps } = props;\n\n\treturn (\n\t\t<PrismicRichText\n\t\t\tcomponents={{ ...defaultComponents, ...components }}\n\t\t\t{...restProps}\n\t\t/>\n\t);\n};\n"],"mappings":";;;;;;;AAcA,MAAM,oBAAsC;CAC3C,QAAQ,EAAE,WACT,2CAAC;EAAE,WAAU;YACX,KAAK,SACL,2CAACA;GAAgB,OAAO,KAAK;aAC5B,2CAACC,6CAAiB,OAAO,OAAQ;IAChB,GAElB,2CAACA,6CAAiB,OAAO,OAAQ;GAE/B;CAEL,YAAY,EAAE,MAAM,eACnB,2CAACD;EAAgB,OAAO,KAAK;EAAO;GAA2B;CAEhE;AAED,MAAa,uBAAqD,UAAU;CAC3E,MAAM,EAAE,YAAY,GAAG,cAAc;AAErC,QACC,2CAACE;EACA,YAAY;GAAE,GAAG;GAAmB,GAAG;GAAY;EACnD,GAAI;GACH"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FC } from "react";
|
|
2
|
+
import { JSXMapSerializer, PrismicRichTextProps } from "@prismicio/react";
|
|
3
|
+
|
|
4
|
+
//#region src/PrismicNextRichText.d.ts
|
|
5
|
+
type PrismicNextRichTextProps = Omit<PrismicRichTextProps, "components"> & {
|
|
6
|
+
components?: JSXMapSerializer;
|
|
7
|
+
};
|
|
8
|
+
declare const PrismicNextRichText: FC<PrismicNextRichTextProps>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { PrismicNextRichText, PrismicNextRichTextProps };
|
|
11
|
+
//# sourceMappingURL=PrismicNextRichText.d.cts.map
|
package/dist/PrismicPreview.cjs
CHANGED
|
@@ -1,39 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
-
mod
|
|
23
|
-
));
|
|
24
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
25
|
-
const jsxRuntime = require("react/jsx-runtime");
|
|
26
|
-
const Script = require("next/script");
|
|
27
|
-
const client = require("@prismicio/client");
|
|
28
|
-
const resolveDefaultExport = require("./lib/resolveDefaultExport.cjs");
|
|
29
|
-
const PrismicPreviewClient = require("./PrismicPreviewClient.cjs");
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_resolveDefaultExport = require('./lib/resolveDefaultExport.cjs');
|
|
3
|
+
const require_PrismicPreviewClient = require('./PrismicPreviewClient.cjs');
|
|
4
|
+
let next_script = require("next/script");
|
|
5
|
+
next_script = require_rolldown_runtime.__toESM(next_script);
|
|
6
|
+
let _prismicio_client = require("@prismicio/client");
|
|
7
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
|
+
|
|
9
|
+
//#region src/PrismicPreview.tsx
|
|
10
|
+
/**
|
|
11
|
+
* React component that sets up Prismic Previews using the Prismic Toolbar. When
|
|
12
|
+
* the Prismic Toolbar send events to the browser, such as on preview updates
|
|
13
|
+
* and exiting, this component will automatically refresh the page with the
|
|
14
|
+
* changes.
|
|
15
|
+
*
|
|
16
|
+
* This component can be wrapped around your app or added anywhere in your app's
|
|
17
|
+
* tree. It must be rendered on every page.
|
|
18
|
+
*/
|
|
30
19
|
const PrismicPreview = async (props) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
20
|
+
const { repositoryName, children, ...otherProps } = props;
|
|
21
|
+
const { draftMode } = await import("next/headers");
|
|
22
|
+
const toolbarSrc = (0, _prismicio_client.getToolbarSrc)(repositoryName);
|
|
23
|
+
const isDraftMode = (await draftMode()).isEnabled;
|
|
24
|
+
const ResolvedScript = require_resolveDefaultExport.resolveDefaultExport(next_script.default);
|
|
25
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
26
|
+
children,
|
|
27
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PrismicPreviewClient.PrismicPreviewClient, {
|
|
28
|
+
repositoryName,
|
|
29
|
+
isDraftMode,
|
|
30
|
+
...otherProps
|
|
31
|
+
}),
|
|
32
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ResolvedScript, {
|
|
33
|
+
src: toolbarSrc,
|
|
34
|
+
strategy: "lazyOnload"
|
|
35
|
+
})
|
|
36
|
+
] });
|
|
37
37
|
};
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
38
40
|
exports.PrismicPreview = PrismicPreview;
|
|
39
|
-
//# sourceMappingURL=PrismicPreview.cjs.map
|
|
41
|
+
//# sourceMappingURL=PrismicPreview.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicPreview.cjs","sources":["../src/PrismicPreview.tsx"],"sourcesContent":["import type { FC, ReactNode } from \"react\";\nimport Script from \"next/script\";\nimport { getToolbarSrc } from \"@prismicio/client\";\n\nimport { resolveDefaultExport } from \"./lib/resolveDefaultExport\";\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\tconst ResolvedScript = resolveDefaultExport(Script);\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<ResolvedScript src={toolbarSrc} strategy=\"lazyOnload\" />\n\t\t</>\n\t);\n};\n"],"
|
|
1
|
+
{"version":3,"file":"PrismicPreview.cjs","names":["resolveDefaultExport","Script","PrismicPreviewClient"],"sources":["../src/PrismicPreview.tsx"],"sourcesContent":["import type { FC, ReactNode } from \"react\";\nimport Script from \"next/script\";\nimport { getToolbarSrc } from \"@prismicio/client\";\n\nimport { resolveDefaultExport } from \"./lib/resolveDefaultExport\";\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\tconst ResolvedScript = resolveDefaultExport(Script);\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<ResolvedScript src={toolbarSrc} strategy=\"lazyOnload\" />\n\t\t</>\n\t);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwCA,MAAa,iBAA0C,OAAO,UAAU;CACvE,MAAM,EAAE,gBAAgB,UAAU,GAAG,eAAe;CAKpD,MAAM,EAAE,cAAc,MAAM,OAAO;CAEnC,MAAM,kDAA2B,eAAe;CAChD,MAAM,eAAe,MAAM,WAAW,EAAE;CAExC,MAAM,iBAAiBA,kDAAqBC,oBAAO;AAEnD,QACC;EACE;EACD,2CAACC;GACgB;GACH;GACb,GAAI;IACH;EACF,2CAAC;GAAe,KAAK;GAAY,UAAS;IAAe;KACvD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { FC, ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/PrismicPreview.d.ts
|
|
4
|
+
/** Props for `<PrismicPreview>`. */
|
|
5
|
+
type PrismicPreviewProps = {
|
|
6
|
+
/**
|
|
7
|
+
* The name of your Prismic repository. A Prismic Toolbar will be registered
|
|
8
|
+
* using this repository.
|
|
9
|
+
*/
|
|
10
|
+
repositoryName: string;
|
|
11
|
+
/**
|
|
12
|
+
* The URL of your app's Prismic preview endpoint (default: `/api/preview`).
|
|
13
|
+
* This URL will be fetched on preview update events.
|
|
14
|
+
*/
|
|
15
|
+
updatePreviewURL?: string;
|
|
16
|
+
/**
|
|
17
|
+
* The URL of your app's exit preview endpoint (default: `/api/exit-preview`).
|
|
18
|
+
* This URL will be fetched on preview exit events.
|
|
19
|
+
*/
|
|
20
|
+
exitPreviewURL?: string;
|
|
21
|
+
/** Children to render adjacent to the Prismic Toolbar. */
|
|
22
|
+
children?: ReactNode;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* React component that sets up Prismic Previews using the Prismic Toolbar. When
|
|
26
|
+
* the Prismic Toolbar send events to the browser, such as on preview updates
|
|
27
|
+
* and exiting, this component will automatically refresh the page with the
|
|
28
|
+
* changes.
|
|
29
|
+
*
|
|
30
|
+
* This component can be wrapped around your app or added anywhere in your app's
|
|
31
|
+
* tree. It must be rendered on every page.
|
|
32
|
+
*/
|
|
33
|
+
declare const PrismicPreview: FC<PrismicPreviewProps>;
|
|
34
|
+
//#endregion
|
|
35
|
+
export { PrismicPreview, PrismicPreviewProps };
|
|
36
|
+
//# sourceMappingURL=PrismicPreview.d.cts.map
|