@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.
Files changed (150) hide show
  1. package/README.md +5 -3
  2. package/dist/PrismicNextImage.d.ts +7 -8
  3. package/dist/PrismicNextImage.js +8 -8
  4. package/dist/PrismicNextImage.js.map +1 -1
  5. package/dist/PrismicNextLink.d.ts +99 -100
  6. package/dist/PrismicNextLink.js +3 -5
  7. package/dist/PrismicNextLink.js.map +1 -1
  8. package/dist/PrismicPreview.d.ts +5 -13
  9. package/dist/PrismicPreview.js +6 -19
  10. package/dist/PrismicPreview.js.map +1 -1
  11. package/dist/PrismicPreviewClient.d.ts +5 -3
  12. package/dist/PrismicPreviewClient.js +58 -68
  13. package/dist/PrismicPreviewClient.js.map +1 -1
  14. package/dist/createLocaleRedirect.d.ts +8 -15
  15. package/dist/createLocaleRedirect.js +4 -28
  16. package/dist/createLocaleRedirect.js.map +1 -1
  17. package/dist/enableAutoPreviews.d.ts +7 -31
  18. package/dist/enableAutoPreviews.js +24 -35
  19. package/dist/enableAutoPreviews.js.map +1 -1
  20. package/dist/exitPreview.d.ts +4 -46
  21. package/dist/exitPreview.js +8 -15
  22. package/dist/exitPreview.js.map +1 -1
  23. package/dist/imgixLoader.js.map +1 -1
  24. package/dist/index.d.ts +15 -18
  25. package/dist/index.js +2 -4
  26. package/dist/index.js.map +1 -1
  27. package/dist/lib/devMsg.d.ts +1 -1
  28. package/dist/lib/devMsg.js.map +1 -1
  29. package/dist/package.json.js +1 -1
  30. package/dist/pages/PrismicPreview.d.ts +31 -0
  31. package/dist/pages/PrismicPreview.js +64 -0
  32. package/dist/pages/PrismicPreview.js.map +1 -0
  33. package/dist/pages/enableAutoPreviews.d.ts +31 -0
  34. package/dist/pages/enableAutoPreviews.js +19 -0
  35. package/dist/pages/enableAutoPreviews.js.map +1 -0
  36. package/dist/pages/exitPreview.d.ts +33 -0
  37. package/dist/pages/exitPreview.js +10 -0
  38. package/dist/pages/exitPreview.js.map +1 -0
  39. package/dist/pages/index.d.ts +18 -0
  40. package/dist/pages/redirectToPreviewURL.d.ts +43 -0
  41. package/dist/pages/redirectToPreviewURL.js +16 -0
  42. package/dist/pages/redirectToPreviewURL.js.map +1 -0
  43. package/dist/{setPreviewData.d.ts → pages/setPreviewData.d.ts} +3 -9
  44. package/dist/{setPreviewData.js → pages/setPreviewData.js} +2 -2
  45. package/dist/pages/setPreviewData.js.map +1 -0
  46. package/dist/pages/types.d.ts +30 -0
  47. package/dist/pages.js +21 -0
  48. package/dist/pages.js.map +1 -0
  49. package/dist/redirectToPreviewURL.d.ts +11 -41
  50. package/dist/redirectToPreviewURL.js +16 -22
  51. package/dist/redirectToPreviewURL.js.map +1 -1
  52. package/dist/types.d.ts +2 -51
  53. package/package.json +61 -54
  54. package/src/PrismicNextImage.tsx +19 -16
  55. package/src/PrismicNextLink.tsx +17 -13
  56. package/src/PrismicPreview.tsx +20 -50
  57. package/src/PrismicPreviewClient.tsx +112 -138
  58. package/src/createLocaleRedirect.ts +14 -56
  59. package/src/enableAutoPreviews.ts +38 -110
  60. package/src/exitPreview.ts +18 -81
  61. package/src/index.ts +15 -26
  62. package/src/lib/devMsg.ts +1 -1
  63. package/src/pages/PrismicPreview.tsx +145 -0
  64. package/src/pages/enableAutoPreviews.ts +62 -0
  65. package/src/pages/exitPreview.ts +45 -0
  66. package/src/pages/index.ts +27 -0
  67. package/src/pages/redirectToPreviewURL.ts +77 -0
  68. package/src/{setPreviewData.ts → pages/setPreviewData.ts} +5 -11
  69. package/src/pages/types.ts +36 -0
  70. package/src/redirectToPreviewURL.ts +44 -95
  71. package/src/types.ts +2 -56
  72. package/dist/PrismicNextImage.cjs +0 -64
  73. package/dist/PrismicNextImage.cjs.map +0 -1
  74. package/dist/PrismicNextLink.cjs +0 -40
  75. package/dist/PrismicNextLink.cjs.map +0 -1
  76. package/dist/PrismicPreview.cjs +0 -28
  77. package/dist/PrismicPreview.cjs.map +0 -1
  78. package/dist/PrismicPreviewClient.cjs +0 -81
  79. package/dist/PrismicPreviewClient.cjs.map +0 -1
  80. package/dist/_node_modules/@prismicio/client/dist/cookie.cjs +0 -5
  81. package/dist/_node_modules/@prismicio/client/dist/cookie.cjs.map +0 -1
  82. package/dist/_node_modules/@prismicio/client/dist/cookie.js +0 -5
  83. package/dist/_node_modules/@prismicio/client/dist/cookie.js.map +0 -1
  84. package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs +0 -16
  85. package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs.map +0 -1
  86. package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js +0 -16
  87. package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js.map +0 -1
  88. package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.cjs +0 -13
  89. package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.cjs.map +0 -1
  90. package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.js +0 -13
  91. package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.js.map +0 -1
  92. package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs +0 -47
  93. package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs.map +0 -1
  94. package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js +0 -47
  95. package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js.map +0 -1
  96. package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.cjs +0 -28
  97. package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.cjs.map +0 -1
  98. package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.js +0 -28
  99. package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.js.map +0 -1
  100. package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs +0 -27
  101. package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs.map +0 -1
  102. package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js +0 -27
  103. package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js.map +0 -1
  104. package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.cjs +0 -14
  105. package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.cjs.map +0 -1
  106. package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.js +0 -14
  107. package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.js.map +0 -1
  108. package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.cjs +0 -7
  109. package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.cjs.map +0 -1
  110. package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.js +0 -7
  111. package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.js.map +0 -1
  112. package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.cjs +0 -9
  113. package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.cjs.map +0 -1
  114. package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.js +0 -9
  115. package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.js.map +0 -1
  116. package/dist/_node_modules/@prismicio/client/dist/types/value/link.cjs +0 -10
  117. package/dist/_node_modules/@prismicio/client/dist/types/value/link.cjs.map +0 -1
  118. package/dist/_node_modules/@prismicio/client/dist/types/value/link.js +0 -10
  119. package/dist/_node_modules/@prismicio/client/dist/types/value/link.js.map +0 -1
  120. package/dist/createLocaleRedirect.cjs +0 -32
  121. package/dist/createLocaleRedirect.cjs.map +0 -1
  122. package/dist/enableAutoPreviews.cjs +0 -40
  123. package/dist/enableAutoPreviews.cjs.map +0 -1
  124. package/dist/exitPreview.cjs +0 -20
  125. package/dist/exitPreview.cjs.map +0 -1
  126. package/dist/imgixLoader.cjs +0 -17
  127. package/dist/imgixLoader.cjs.map +0 -1
  128. package/dist/index.cjs +0 -21
  129. package/dist/index.cjs.map +0 -1
  130. package/dist/lib/devMsg.cjs +0 -8
  131. package/dist/lib/devMsg.cjs.map +0 -1
  132. package/dist/lib/getPreviewCookieRepositoryName.cjs +0 -7
  133. package/dist/lib/getPreviewCookieRepositoryName.cjs.map +0 -1
  134. package/dist/lib/getPreviewCookieRepositoryName.d.ts +0 -9
  135. package/dist/lib/getPreviewCookieRepositoryName.js +0 -7
  136. package/dist/lib/getPreviewCookieRepositoryName.js.map +0 -1
  137. package/dist/lib/getPrismicPreviewCookie.cjs +0 -21
  138. package/dist/lib/getPrismicPreviewCookie.cjs.map +0 -1
  139. package/dist/lib/getPrismicPreviewCookie.d.ts +0 -9
  140. package/dist/lib/getPrismicPreviewCookie.js +0 -21
  141. package/dist/lib/getPrismicPreviewCookie.js.map +0 -1
  142. package/dist/package.json.cjs +0 -5
  143. package/dist/package.json.cjs.map +0 -1
  144. package/dist/redirectToPreviewURL.cjs +0 -30
  145. package/dist/redirectToPreviewURL.cjs.map +0 -1
  146. package/dist/setPreviewData.cjs +0 -11
  147. package/dist/setPreviewData.cjs.map +0 -1
  148. package/dist/setPreviewData.js.map +0 -1
  149. package/src/lib/getPreviewCookieRepositoryName.ts +0 -14
  150. 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 Preview
13
- - 🖼️  Render optimized images using [`next/image`][next-image] and Prismic's built-in [Imgix][imgix] integration
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-image]: https://nextjs.org/docs/basic-features/image-optimization
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
- /// <reference types="react" />
1
+ import { JSX } from "react";
2
2
  import { ImageProps } from "next/image";
3
3
  import { ImgixURLParams } from "imgix-url-builder";
4
- import * as prismic from "@prismicio/client";
5
- export type PrismicNextImageProps = Omit<ImageProps, "src" | "alt"> & {
6
- /**
7
- * The Prismic Image field or thumbnail to render.
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;
@@ -1,11 +1,11 @@
1
- 'use client';
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 (process.env.NODE_ENV !== "production") {
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 (process.env.NODE_ENV !== "production" && typeof resolvedAlt !== "string") {
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: imgixLoader, ...restProps });
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":["../../src/PrismicNextImage.tsx"],"sourcesContent":["\"use client\";\n\nimport Image, { ImageProps } from \"next/image\";\nimport { buildURL, ImgixURLParams } from \"imgix-url-builder\";\nimport * as prismic from \"@prismicio/client\";\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<ImageProps, \"src\" | \"alt\"> & {\n\t/**\n\t * The Prismic Image field or thumbnail to render.\n\t */\n\tfield: prismic.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\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\t...restProps\n}: PrismicNextImageProps): JSX.Element => {\n\tif (process.env.NODE_ENV !== \"production\") {\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 (prismic.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\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst resolvedAlt = (alt ?? (field.alt || fallbackAlt))!;\n\n\t\tif (\n\t\t\tprocess.env.NODE_ENV !== \"production\" &&\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\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={imgixLoader}\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":[],"mappings":";;;;;;;;AAUA;AACC;AACQ;AAAA;AAED;AAEF;AACI;AAAA;AAEA;AAAA;AACP;AAEH;AAuDO;AAWF;AACH;AACC;AAGI;AAIL;AACC;AAGI;AAEJ;AAGF;AACC;AACA;AACK;AACH;AAA6D;AAC7D;AAGF;AAEA;AAEM;AACA;AAEF;AACA;AAEA;AACH;AAA+B;AAE/B;AAA+B;AAM1B;AAEN;AAIS;AAEJ;AAML;AACA;AACC;AACE;AAGH;AASG;AAGH;AAAkB;AAEpB;;;;"}
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
- /// <reference types="node" />
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
- export type PrismicNextLinkProps = Omit<React.ComponentProps<typeof Link>, "field" | "document" | "href" | "rel"> & {
6
- linkResolver?: prismic.LinkResolverFunction;
7
- rel?: string | prismic.AsLinkAttrsConfig["rel"];
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: prismic.LinkField | null | undefined;
8
+ field: LinkField | null | undefined;
10
9
  document?: never;
11
10
  href?: never;
12
11
  } | {
13
12
  field?: never;
14
- document: prismic.PrismicDocument | null | undefined;
13
+ document: PrismicDocument | null | undefined;
15
14
  href?: never;
16
15
  } | {
17
16
  field?: never;
18
17
  document?: never;
19
- href: React.ComponentProps<typeof Link>["href"];
18
+ href: ComponentProps<typeof Link>["href"];
20
19
  });
21
- export declare const PrismicNextLink: React.ForwardRefExoticComponent<(Omit<Omit<Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, keyof {
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?: (string | import("url").UrlObject) | undefined;
24
- replace?: boolean | undefined;
25
- scroll?: boolean | undefined;
26
- shallow?: boolean | undefined;
27
- passHref?: boolean | undefined;
28
- prefetch?: boolean | null | undefined;
29
- locale?: string | false | undefined;
30
- legacyBehavior?: boolean | undefined;
31
- onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
32
- onTouchStart?: React.TouchEventHandler<HTMLAnchorElement> | undefined;
33
- onClick?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
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?: (string | import("url").UrlObject) | undefined;
37
- replace?: boolean | undefined;
38
- scroll?: boolean | undefined;
39
- shallow?: boolean | undefined;
40
- passHref?: boolean | undefined;
41
- prefetch?: boolean | null | undefined;
42
- locale?: string | false | undefined;
43
- legacyBehavior?: boolean | undefined;
44
- onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
45
- onTouchStart?: React.TouchEventHandler<HTMLAnchorElement> | undefined;
46
- onClick?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
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
- } & React.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "document" | "href"> & {
50
- linkResolver?: prismic.LinkResolverFunction | undefined;
51
- rel?: string | prismic.AsLinkAttrsConfig["rel"];
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: prismic.LinkField | null | undefined;
54
- document?: undefined;
55
- href?: undefined;
56
- }, "ref"> | Omit<Omit<Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, keyof {
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?: (string | import("url").UrlObject) | undefined;
59
- replace?: boolean | undefined;
60
- scroll?: boolean | undefined;
61
- shallow?: boolean | undefined;
62
- passHref?: boolean | undefined;
63
- prefetch?: boolean | null | undefined;
64
- locale?: string | false | undefined;
65
- legacyBehavior?: boolean | undefined;
66
- onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
67
- onTouchStart?: React.TouchEventHandler<HTMLAnchorElement> | undefined;
68
- onClick?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
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?: (string | import("url").UrlObject) | undefined;
72
- replace?: boolean | undefined;
73
- scroll?: boolean | undefined;
74
- shallow?: boolean | undefined;
75
- passHref?: boolean | undefined;
76
- prefetch?: boolean | null | undefined;
77
- locale?: string | false | undefined;
78
- legacyBehavior?: boolean | undefined;
79
- onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
80
- onTouchStart?: React.TouchEventHandler<HTMLAnchorElement> | undefined;
81
- onClick?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
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
- } & React.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "document" | "href"> & {
85
- linkResolver?: prismic.LinkResolverFunction | undefined;
86
- rel?: string | prismic.AsLinkAttrsConfig["rel"];
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?: undefined;
89
- document: prismic.PrismicDocument | null | undefined;
90
- href?: undefined;
91
- }, "ref"> | Omit<Omit<Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, keyof {
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?: (string | import("url").UrlObject) | undefined;
94
- replace?: boolean | undefined;
95
- scroll?: boolean | undefined;
96
- shallow?: boolean | undefined;
97
- passHref?: boolean | undefined;
98
- prefetch?: boolean | null | undefined;
99
- locale?: string | false | undefined;
100
- legacyBehavior?: boolean | undefined;
101
- onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
102
- onTouchStart?: React.TouchEventHandler<HTMLAnchorElement> | undefined;
103
- onClick?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
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?: (string | import("url").UrlObject) | undefined;
107
- replace?: boolean | undefined;
108
- scroll?: boolean | undefined;
109
- shallow?: boolean | undefined;
110
- passHref?: boolean | undefined;
111
- prefetch?: boolean | null | undefined;
112
- locale?: string | false | undefined;
113
- legacyBehavior?: boolean | undefined;
114
- onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
115
- onTouchStart?: React.TouchEventHandler<HTMLAnchorElement> | undefined;
116
- onClick?: React.MouseEventHandler<HTMLAnchorElement> | undefined;
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
- } & React.RefAttributes<HTMLAnchorElement>, "rel" | "field" | "document" | "href"> & {
120
- linkResolver?: prismic.LinkResolverFunction | undefined;
121
- rel?: string | prismic.AsLinkAttrsConfig["rel"];
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?: undefined;
124
- document?: undefined;
125
- href: React.ComponentProps<typeof Link>["href"];
126
- }, "ref">) & React.RefAttributes<HTMLAnchorElement>>;
122
+ field?: never;
123
+ document?: never;
124
+ href: ComponentProps<typeof Link>["href"];
125
+ }, "ref">) & import("react").RefAttributes<HTMLAnchorElement>>;
@@ -1,10 +1,8 @@
1
- 'use client';
2
- 'use client';
3
1
  import { jsx } from "react/jsx-runtime";
4
- import * as React from "react";
2
+ import { forwardRef } from "react";
5
3
  import Link from "next/link";
6
- import { asLinkAttrs } from './_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.js';
7
- const PrismicNextLink = React.forwardRef(function PrismicNextLink2(props, ref) {
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":["../../src/PrismicNextLink.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport * as prismic from \"@prismicio/client\";\nimport Link from \"next/link\";\n\nexport type PrismicNextLinkProps = Omit<\n\tReact.ComponentProps<typeof Link>,\n\t\"field\" | \"document\" | \"href\" | \"rel\"\n> & {\n\tlinkResolver?: prismic.LinkResolverFunction;\n\trel?: string | prismic.AsLinkAttrsConfig[\"rel\"];\n} & (\n\t\t| {\n\t\t\t\tfield: prismic.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: prismic.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: React.ComponentProps<typeof Link>[\"href\"];\n\t\t }\n\t);\n\nexport const PrismicNextLink = React.forwardRef<\n\tHTMLAnchorElement,\n\tPrismicNextLinkProps\n>(function PrismicNextLink(props, ref): JSX.Element | null {\n\tconst { field, document, linkResolver, children, ...restProps } = props;\n\tconst {\n\t\thref: computedHref,\n\t\trel: computedRel,\n\t\t...attrs\n\t} = prismic.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":[],"mappings":";;;;;;AA8BO;AAIN;AACM;AAIqC;AAC1C;AAC2D;AAG5D;AAEA;AACA;AACC;AAAgB;AAGjB;AAKD;;;;"}
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;"}
@@ -1,7 +1,5 @@
1
- import * as React from "react";
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
- * Children to render adjacent to the Prismic Toolbar.
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({ repositoryName, children, ...props }: PrismicPreviewProps): JSX.Element | Promise<JSX.Element>;
31
+ export declare function PrismicPreview(props: PrismicPreviewProps): Promise<JSX.Element>;
@@ -1,26 +1,13 @@
1
1
  import { jsxs, Fragment, jsx } from "react/jsx-runtime";
2
2
  import Script from "next/script";
3
- import { draftMode } from "next/headers";
4
- import { useRouter } from "next/router";
3
+ import { getToolbarSrc } from "@prismicio/client";
5
4
  import { PrismicPreviewClient } from "./PrismicPreviewClient.js";
6
- import { getToolbarSrc } from './_node_modules/@prismicio/client/dist/getToolbarSrc.js';
7
- function PrismicPreview({ repositoryName, children, ...props }) {
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
- let isDraftMode = false;
10
- const result = jsxs(Fragment, { children: [children, jsx(PrismicPreviewClient, { repositoryName, isDraftMode, ...props }), jsx(Script, { src: toolbarSrc, strategy: "lazyOnload" })] });
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":["../../src/PrismicPreview.tsx"],"sourcesContent":["import Script from \"next/script\";\nimport { draftMode } from \"next/headers\";\nimport { useRouter as usePagesRouter } from \"next/router\";\nimport * as React from \"react\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { PrismicPreviewClient } from \"./PrismicPreviewClient\";\n\n/**\n * Props for `<PrismicPreview>`.\n */\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 * **Only used in the Pages Directory (/pages).**\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 * **Only used in the Pages Directory (/pages).**\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/**\n\t * Children to render adjacent to the Prismic Toolbar.\n\t */\n\tchildren?: React.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 function PrismicPreview({\n\trepositoryName,\n\tchildren,\n\t...props\n}: PrismicPreviewProps): JSX.Element | Promise<JSX.Element> {\n\tconst toolbarSrc = prismic.getToolbarSrc(repositoryName);\n\tlet isDraftMode = false;\n\n\tconst result = (\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{...props}\n\t\t\t/>\n\t\t\t<Script src={toolbarSrc} strategy=\"lazyOnload\" />\n\t\t</>\n\t);\n\n\t// We need to check `draftMode()`, an async method, when running in the\n\t// App Router. The Pages Router does not support async components, so we\n\t// need to do some trickery to return a Promise in the App Router and\n\t// unwrapped JSX in the Pages Router.\n\t//\n\t// Alternatively, we could serve a special server-only\n\t// `<PrismicPreview>`, but that requires extra set up and depends on the\n\t// compiler to recognize the `react-server` entry point. It is an\n\t// undocumented feature that could be removed.\n\tlet isAppRouter = true;\n\ttry {\n\t\tusePagesRouter();\n\t\tisAppRouter = false;\n\t} catch {}\n\n\tif (isAppRouter) {\n\t\treturn new Promise(async (res) => {\n\t\t\tisDraftMode = (await draftMode()).isEnabled;\n\n\t\t\tres(result);\n\t\t});\n\t}\n\n\treturn result;\n}\n"],"names":["prismic.getToolbarSrc","_jsxs","_Fragment","_jsx"],"mappings":";;;;;;AAiDM,SAAU,eAAe,EAC9B,gBACA,UACA,GAAG,SACkB;AACf,QAAA,aAAaA,cAAsB,cAAc;AACvD,MAAI,cAAc;AAEZ,QAAA,SACLC,KAAAC,UAAA,EAAA,UAAA,CACE,UACDC,IAAC,sBAAoB,EACpB,gBACA,aACI,GAAA,OACH,GACFA,IAAC,UAAO,KAAK,YAAY,UAAS,aAAe,CAAA,CAAA,EAAA,CAAA;AAanD,MAAI,cAAc;AACd,MAAA;;AAEW,kBAAA;AAAA,EAAA,QACP;AAAA,EAAE;AAEV,MAAI,aAAa;AACT,WAAA,IAAI,QAAQ,OAAO,QAAO;AACjB,qBAAA,MAAM,UAAa,GAAA;AAElC,UAAI,MAAM;AAAA,IAAA,CACV;AAAA,EACD;AAEM,SAAA;AACR;"}
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
- import { PrismicPreviewProps } from "./PrismicPreview";
2
- type PrismicPreviewClientProps = Omit<PrismicPreviewProps, "children"> & {
1
+ type PrismicPreviewClientProps = {
2
+ repositoryName: string;
3
3
  isDraftMode: boolean;
4
+ updatePreviewURL?: string;
5
+ exitPreviewURL?: string;
4
6
  };
5
- export declare function PrismicPreviewClient({ repositoryName, updatePreviewURL, exitPreviewURL, isDraftMode, }: PrismicPreviewClientProps): null;
7
+ export declare function PrismicPreviewClient(props: PrismicPreviewClientProps): null;
6
8
  export {};