@prismicio/next 2.2.0-canary.469c917 → 2.2.0-pr.123.1c009e2

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.
@@ -2,16 +2,16 @@
2
2
 
3
3
  const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
4
4
  const require_resolveDefaultExport = require('./lib/resolveDefaultExport.cjs');
5
- const require_devMsg = require('./lib/devMsg.cjs');
6
5
  const require_imgixLoader = require('./imgixLoader.cjs');
6
+ const require_devMsg = require('./lib/devMsg.cjs');
7
7
  let _prismicio_client = require("@prismicio/client");
8
8
  let react = require("react");
9
9
  let react_jsx_runtime = require("react/jsx-runtime");
10
+ let imgix_url_builder = require("imgix-url-builder");
10
11
  let next_image = require("next/image");
11
12
  next_image = require_rolldown_runtime.__toESM(next_image);
12
- let imgix_url_builder = require("imgix-url-builder");
13
13
 
14
- //#region src/PrismicNextImage.tsx
14
+ //#region src/PrismicImage.tsx
15
15
  const castInt = (input) => {
16
16
  if (typeof input === "number" || typeof input === "undefined") return input;
17
17
  else {
@@ -36,10 +36,10 @@ const castInt = (input) => {
36
36
  *
37
37
  * @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image
38
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) {
39
+ const PrismicImage = (0, react.forwardRef)(function PrismicImage$1({ field, imgixParams = {}, alt, fallbackAlt, fill, width, height, fallback = null, loader = require_imgixLoader.imgixLoader, ...restProps }, ref) {
40
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")}`);
41
+ if (typeof alt === "string" && alt !== "") console.warn(`[PrismicImage] 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(`[PrismicImage] 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
43
  }
44
44
  if (!_prismicio_client.isFilled.imageThumbnail(field)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: fallback });
45
45
  const resolvedImgixParams = imgixParams;
@@ -53,7 +53,7 @@ const PrismicNextImage = (0, react.forwardRef)(function PrismicNextImage$1({ fie
53
53
  if (castedWidth != null && castedHeight == null) resolvedHeight = castedWidth / ar;
54
54
  else if (castedWidth == null && castedHeight != null) resolvedWidth = castedHeight * ar;
55
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);
56
+ if (process.env.NODE_ENV === "development" && typeof resolvedAlt !== "string") console.error(`[PrismicImage] 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
57
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_resolveDefaultExport.resolveDefaultExport(next_image.default), {
58
58
  ref,
59
59
  src,
@@ -67,5 +67,5 @@ const PrismicNextImage = (0, react.forwardRef)(function PrismicNextImage$1({ fie
67
67
  });
68
68
 
69
69
  //#endregion
70
- exports.PrismicNextImage = PrismicNextImage;
71
- //# sourceMappingURL=PrismicNextImage.cjs.map
70
+ exports.PrismicImage = PrismicImage;
71
+ //# sourceMappingURL=PrismicImage.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismicImage.cjs","names":["PrismicImage","imgixLoader","devMsg","isFilled","resolveDefaultExport","Image"],"sources":["../src/PrismicImage.tsx"],"sourcesContent":["\"use client\";\n\nimport { imgixLoader } from \"./imgixLoader\";\nimport { devMsg } from \"./lib/devMsg\";\nimport { resolveDefaultExport } from \"./lib/resolveDefaultExport\";\nimport type { ImageFieldImage } from \"@prismicio/client\";\nimport { isFilled } from \"@prismicio/client\";\nimport type { ImgixURLParams } from \"imgix-url-builder\";\nimport { buildURL } from \"imgix-url-builder\";\nimport type { ImageProps } from \"next/image\";\nimport Image from \"next/image\";\nimport type {\n\tForwardRefExoticComponent,\n\tPropsWithoutRef,\n\tRefAttributes,\n} from \"react\";\nimport { forwardRef } from \"react\";\n\n/**\n * @deprecated Use `PrismicImage` instead.\n */\nexport { PrismicImage as PrismicNextImage };\n\n/**\n * @deprecated Use `PrismicImageProps` instead.\n */\nexport type { PrismicImageProps as PrismicNextImageProps };\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 PrismicImageProps = Omit<ImageProps, \"src\" | \"alt\" | \"loader\"> & {\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 PrismicImage: ForwardRefExoticComponent<\n\tPropsWithoutRef<PrismicImageProps> & RefAttributes<HTMLImageElement>\n> = forwardRef<HTMLImageElement, PrismicImageProps>(function PrismicImage(\n\t{\n\t\tfield,\n\t\timgixParams = {},\n\t\talt,\n\t\tfallbackAlt,\n\t\tfill,\n\t\twidth,\n\t\theight,\n\t\tfallback = null,\n\t\tloader = imgixLoader,\n\t\t...restProps\n\t},\n\tref,\n) {\n\tif (process.env.NODE_ENV === \"development\") {\n\t\tif (typeof alt === \"string\" && alt !== \"\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicImage] 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`[PrismicImage] 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\treturn <>{fallback}</>;\n\t}\n\n\tconst resolvedImgixParams = imgixParams;\n\tfor (const x in imgixParams) {\n\t\tif (resolvedImgixParams[x as keyof typeof resolvedImgixParams] === null) {\n\t\t\tresolvedImgixParams[x as keyof typeof resolvedImgixParams] = undefined;\n\t\t}\n\t}\n\n\tconst src = buildURL(field.url, imgixParams as ImgixURLParams);\n\n\tconst ar = field.dimensions.width / field.dimensions.height;\n\n\tconst castedWidth = castInt(width);\n\tconst castedHeight = castInt(height);\n\n\tlet resolvedWidth = castedWidth ?? field.dimensions.width;\n\tlet resolvedHeight = castedHeight ?? field.dimensions.height;\n\n\tif (castedWidth != null && castedHeight == null) {\n\t\tresolvedHeight = castedWidth / ar;\n\t} else if (castedWidth == null && castedHeight != null) {\n\t\tresolvedWidth = castedHeight * ar;\n\t}\n\n\t// A non-null assertion is required since we can't statically\n\t// know if an alt attribute is available.\n\tconst resolvedAlt = (alt ?? (field.alt || fallbackAlt))!;\n\n\tif (\n\t\tprocess.env.NODE_ENV === \"development\" &&\n\t\ttypeof resolvedAlt !== \"string\"\n\t) {\n\t\tconsole.error(\n\t\t\t`[PrismicImage] 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\tsrc,\n\t\t);\n\t}\n\n\tconst ResolvedImage = resolveDefaultExport(Image);\n\n\treturn (\n\t\t<ResolvedImage\n\t\t\tref={ref}\n\t\t\tsrc={src}\n\t\t\twidth={fill ? undefined : resolvedWidth}\n\t\t\theight={fill ? undefined : resolvedHeight}\n\t\t\talt={resolvedAlt}\n\t\t\tfill={fill}\n\t\t\tloader={loader === null ? undefined : loader}\n\t\t\t{...restProps}\n\t\t/>\n\t);\n});\n"],"mappings":";;;;;;;;;;;;;;AA4BA,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;;;;;;;;;;;;;;;;;;;AA2DV,MAAa,qCAEuC,SAASA,eAC5D,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,qQAAqQC,sBACpQ,8BACA,GACD;AAGF,MAAI,OAAO,gBAAgB,YAAY,gBAAgB,GACtD,SAAQ,KACP,qSAAqSA,sBACpS,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,+MACA,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;EAEF"}
@@ -1,10 +1,11 @@
1
1
  import { ForwardRefExoticComponent, PropsWithoutRef, RefAttributes } from "react";
2
2
  import { ImageFieldImage } from "@prismicio/client";
3
- import { ImageProps } from "next/image";
4
3
  import { ImgixURLParams } from "imgix-url-builder";
4
+ import { ImageProps } from "next/image";
5
+
6
+ //#region src/PrismicImage.d.ts
5
7
 
6
- //#region src/PrismicNextImage.d.ts
7
- type PrismicNextImageProps = Omit<ImageProps, "src" | "alt" | "loader"> & {
8
+ type PrismicImageProps = Omit<ImageProps, "src" | "alt" | "loader"> & {
8
9
  /** The Prismic Image field or thumbnail to render. */
9
10
  field: ImageFieldImage | null | undefined;
10
11
  /**
@@ -51,7 +52,7 @@ type PrismicNextImageProps = Omit<ImageProps, "src" | "alt" | "loader"> & {
51
52
  *
52
53
  * @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image
53
54
  */
54
- declare const PrismicNextImage: ForwardRefExoticComponent<PropsWithoutRef<PrismicNextImageProps> & RefAttributes<HTMLImageElement>>;
55
+ declare const PrismicImage: ForwardRefExoticComponent<PropsWithoutRef<PrismicImageProps> & RefAttributes<HTMLImageElement>>;
55
56
  //#endregion
56
- export { PrismicNextImage, PrismicNextImageProps };
57
- //# sourceMappingURL=PrismicNextImage.d.cts.map
57
+ export { PrismicImage, PrismicImageProps };
58
+ //# sourceMappingURL=PrismicImage.d.cts.map
@@ -6,8 +6,8 @@ let react_jsx_runtime = require("react/jsx-runtime");
6
6
  let next_link = require("next/link");
7
7
  next_link = require_rolldown_runtime.__toESM(next_link);
8
8
 
9
- //#region src/PrismicNextLink.tsx
10
- const PrismicNextLink = (0, react.forwardRef)(function PrismicNextLink$1(props, ref) {
9
+ //#region src/PrismicLink.tsx
10
+ const PrismicLink = (0, react.forwardRef)(function PrismicLink$1(props, ref) {
11
11
  const { field, document, linkResolver, children, ...restProps } = props;
12
12
  const { href: computedHref, rel: computedRel, ...attrs } = (0, _prismicio_client.asLinkAttrs)(field ?? document, {
13
13
  linkResolver,
@@ -27,5 +27,5 @@ const PrismicNextLink = (0, react.forwardRef)(function PrismicNextLink$1(props,
27
27
  });
28
28
 
29
29
  //#endregion
30
- exports.PrismicNextLink = PrismicNextLink;
31
- //# sourceMappingURL=PrismicNextLink.cjs.map
30
+ exports.PrismicLink = PrismicLink;
31
+ //# sourceMappingURL=PrismicLink.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismicLink.cjs","names":["PrismicLink","resolveDefaultExport","Link"],"sources":["../src/PrismicLink.tsx"],"sourcesContent":["import { resolveDefaultExport } from \"./lib/resolveDefaultExport\";\nimport type {\n\tAsLinkAttrsConfig,\n\tLinkField,\n\tLinkResolverFunction,\n\tPrismicDocument,\n} from \"@prismicio/client\";\nimport { asLinkAttrs } from \"@prismicio/client\";\nimport Link from \"next/link\";\nimport type { ComponentProps } from \"react\";\nimport { forwardRef } from \"react\";\n\n/**\n * @deprecated Use `PrismicLink` instead.\n */\nexport { PrismicLink as PrismicNextLink } from \"./PrismicLink\";\n\n/**\n * @deprecated Use `PrismicLinkProps` instead.\n */\nexport type { PrismicLinkProps as PrismicNextLinkProps } from \"./PrismicLink\";\n\nexport type PrismicLinkProps = 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 PrismicLink = forwardRef<HTMLAnchorElement, PrismicLinkProps>(\n\tfunction PrismicLink(props, ref) {\n\t\tconst { field, document, linkResolver, children, ...restProps } = props;\n\t\tconst {\n\t\t\thref: computedHref,\n\t\t\trel: computedRel,\n\t\t\t...attrs\n\t\t} = asLinkAttrs(field ?? document, {\n\t\t\tlinkResolver,\n\t\t\trel: typeof restProps.rel === \"function\" ? restProps.rel : undefined,\n\t\t});\n\n\t\tconst href = (\"href\" in restProps ? restProps.href : computedHref) || \"\";\n\n\t\tlet rel = computedRel;\n\t\tif (\"rel\" in restProps && typeof restProps.rel !== \"function\") {\n\t\t\trel = restProps.rel;\n\t\t}\n\n\t\tconst ResolvedLink = resolveDefaultExport(Link);\n\n\t\treturn (\n\t\t\t<ResolvedLink ref={ref} {...attrs} {...restProps} href={href} rel={rel}>\n\t\t\t\t{\"children\" in props ? children : field?.text}\n\t\t\t</ResolvedLink>\n\t\t);\n\t},\n);\n"],"mappings":";;;;;;;;;AA8CA,MAAa,oCACZ,SAASA,cAAY,OAAO,KAAK;CAChC,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;EAGjB"}
@@ -1,11 +1,12 @@
1
1
  import * as react0 from "react";
2
2
  import { ComponentProps } from "react";
3
+ import { AsLinkAttrsConfig, LinkField, LinkResolverFunction, PrismicDocument } from "@prismicio/client";
3
4
  import * as next_link0 from "next/link";
4
5
  import Link from "next/link";
5
- import { AsLinkAttrsConfig, LinkField, LinkResolverFunction, PrismicDocument } from "@prismicio/client";
6
6
 
7
- //#region src/PrismicNextLink.d.ts
8
- type PrismicNextLinkProps = Omit<ComponentProps<typeof Link>, "field" | "document" | "href" | "rel"> & {
7
+ //#region src/PrismicLink.d.ts
8
+
9
+ type PrismicLinkProps = Omit<ComponentProps<typeof Link>, "field" | "document" | "href" | "rel"> & {
9
10
  linkResolver?: LinkResolverFunction;
10
11
  rel?: string | AsLinkAttrsConfig["rel"];
11
12
  } & ({
@@ -21,7 +22,7 @@ type PrismicNextLinkProps = Omit<ComponentProps<typeof Link>, "field" | "documen
21
22
  document?: never;
22
23
  href: ComponentProps<typeof Link>["href"];
23
24
  });
24
- declare const PrismicNextLink: react0.ForwardRefExoticComponent<(Omit<Omit<Omit<react0.AnchorHTMLAttributes<HTMLAnchorElement>, keyof next_link0.LinkProps<any>> & next_link0.LinkProps<any> & {
25
+ declare const PrismicLink: react0.ForwardRefExoticComponent<(Omit<Omit<Omit<react0.AnchorHTMLAttributes<HTMLAnchorElement>, keyof next_link0.LinkProps<any>> & next_link0.LinkProps<any> & {
25
26
  children?: React.ReactNode | undefined;
26
27
  } & react0.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
27
28
  linkResolver?: LinkResolverFunction;
@@ -50,5 +51,5 @@ declare const PrismicNextLink: react0.ForwardRefExoticComponent<(Omit<Omit<Omit<
50
51
  href: ComponentProps<typeof Link>["href"];
51
52
  }, "ref">) & react0.RefAttributes<HTMLAnchorElement>>;
52
53
  //#endregion
53
- export { PrismicNextLink, PrismicNextLinkProps };
54
- //# sourceMappingURL=PrismicNextLink.d.cts.map
54
+ export { PrismicLink, PrismicLinkProps };
55
+ //# sourceMappingURL=PrismicLink.d.cts.map
@@ -0,0 +1,50 @@
1
+ "use client";
2
+
3
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
4
+ const require_PrismicImage = require('./PrismicImage.cjs');
5
+ const require_PrismicLink = require('./PrismicLink.cjs');
6
+ let react_jsx_runtime = require("react/jsx-runtime");
7
+ let _prismicio_react = require("@prismicio/react");
8
+
9
+ //#region src/PrismicRichText.tsx
10
+ const defaultComponents = {
11
+ image: ({ node, key }) => {
12
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
13
+ className: "block-img",
14
+ children: node.linkTo ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PrismicLink.PrismicLink, {
15
+ field: node.linkTo,
16
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PrismicImage.PrismicImage, { field: node })
17
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PrismicImage.PrismicImage, { field: node })
18
+ }, key);
19
+ },
20
+ hyperlink: ({ node, children }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PrismicLink.PrismicLink, {
21
+ field: node.data,
22
+ children
23
+ })
24
+ };
25
+ /**
26
+ * Renders content from a Prismic rich text field as React components with
27
+ * Next.js-optimized defaults for images and links.
28
+ *
29
+ * @example
30
+ *
31
+ * ```tsx
32
+ * <PrismicRichText field={slice.primary.text} />;
33
+ * ```
34
+ *
35
+ * @see {@link https://prismic.io/docs/fields/rich-text}
36
+ */
37
+ const PrismicRichText = ({ components, ...restProps }) => {
38
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_prismicio_react.PrismicRichText, {
39
+ components: {
40
+ ...defaultComponents,
41
+ ...components
42
+ },
43
+ ...restProps
44
+ });
45
+ };
46
+
47
+ //#endregion
48
+ exports.PrismicRichText = PrismicRichText;
49
+ exports.defaultComponents = defaultComponents;
50
+ //# sourceMappingURL=PrismicRichText.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismicRichText.cjs","names":["PrismicLink","PrismicImage","BasePrismicRichText"],"sources":["../src/PrismicRichText.tsx"],"sourcesContent":["\"use client\";\n\nimport { PrismicImage } from \"./PrismicImage\";\nimport { PrismicLink } from \"./PrismicLink\";\nimport {\n\tPrismicRichText as BasePrismicRichText,\n\ttype PrismicRichTextProps as BasePrismicRichTextProps,\n\ttype RichTextComponents,\n} from \"@prismicio/react\";\nimport type { FC } from \"react\";\n\n/**\n * Props for `<PrismicRichText>`.\n */\nexport type PrismicRichTextProps = Omit<\n\tBasePrismicRichTextProps,\n\t\"components\"\n> & {\n\tcomponents?: RichTextComponents;\n};\n\nexport const defaultComponents: RichTextComponents = {\n\timage: ({ node, key }) => {\n\t\treturn (\n\t\t\t<p key={key} className=\"block-img\">\n\t\t\t\t{node.linkTo ? (\n\t\t\t\t\t<PrismicLink field={node.linkTo}>\n\t\t\t\t\t\t<PrismicImage field={node} />\n\t\t\t\t\t</PrismicLink>\n\t\t\t\t) : (\n\t\t\t\t\t<PrismicImage field={node} />\n\t\t\t\t)}\n\t\t\t</p>\n\t\t);\n\t},\n\thyperlink: ({ node, children }) => (\n\t\t<PrismicLink field={node.data}>{children}</PrismicLink>\n\t),\n};\n\n/**\n * Renders content from a Prismic rich text field as React components with\n * Next.js-optimized defaults for images and links.\n *\n * @example\n *\n * ```tsx\n * <PrismicRichText field={slice.primary.text} />;\n * ```\n *\n * @see {@link https://prismic.io/docs/fields/rich-text}\n */\nexport const PrismicRichText: FC<PrismicRichTextProps> = ({\n\tcomponents,\n\t...restProps\n}) => {\n\treturn (\n\t\t<BasePrismicRichText\n\t\t\tcomponents={{ ...defaultComponents, ...components }}\n\t\t\t{...restProps}\n\t\t/>\n\t);\n};\n"],"mappings":";;;;;;;;;AAqBA,MAAa,oBAAwC;CACpD,QAAQ,EAAE,MAAM,UAAU;AACzB,SACC,2CAAC;GAAY,WAAU;aACrB,KAAK,SACL,2CAACA;IAAY,OAAO,KAAK;cACxB,2CAACC,qCAAa,OAAO,OAAQ;KAChB,GAEd,2CAACA,qCAAa,OAAO,OAAQ;KANvB,IAQJ;;CAGN,YAAY,EAAE,MAAM,eACnB,2CAACD;EAAY,OAAO,KAAK;EAAO;GAAuB;CAExD;;;;;;;;;;;;;AAcD,MAAa,mBAA6C,EACzD,YACA,GAAG,gBACE;AACL,QACC,2CAACE;EACA,YAAY;GAAE,GAAG;GAAmB,GAAG;GAAY;EACnD,GAAI;GACH"}
@@ -0,0 +1,27 @@
1
+ import { FC } from "react";
2
+ import { PrismicRichTextProps, RichTextComponents } from "@prismicio/react";
3
+
4
+ //#region src/PrismicRichText.d.ts
5
+
6
+ /**
7
+ * Props for `<PrismicRichText>`.
8
+ */
9
+ type PrismicRichTextProps$1 = Omit<PrismicRichTextProps, "components"> & {
10
+ components?: RichTextComponents;
11
+ };
12
+ /**
13
+ * Renders content from a Prismic rich text field as React components with
14
+ * Next.js-optimized defaults for images and links.
15
+ *
16
+ * @example
17
+ *
18
+ * ```tsx
19
+ * <PrismicRichText field={slice.primary.text} />;
20
+ * ```
21
+ *
22
+ * @see {@link https://prismic.io/docs/fields/rich-text}
23
+ */
24
+ declare const PrismicRichText: FC<PrismicRichTextProps$1>;
25
+ //#endregion
26
+ export { PrismicRichText, PrismicRichTextProps$1 as PrismicRichTextProps };
27
+ //# sourceMappingURL=PrismicRichText.d.cts.map
@@ -0,0 +1,34 @@
1
+ "use client";
2
+
3
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
4
+ const require_PrismicRichText = require('./PrismicRichText.cjs');
5
+ let react_jsx_runtime = require("react/jsx-runtime");
6
+ let _prismicio_react = require("@prismicio/react");
7
+
8
+ //#region src/PrismicTable.tsx
9
+ /**
10
+ * Renders content from a Prismic table field as React components with
11
+ * Next.js-optimized defaults for images and links in cell content.
12
+ *
13
+ * @example
14
+ *
15
+ * ```tsx
16
+ * <PrismicTable field={slice.primary.pricing_table} />;
17
+ * ```
18
+ *
19
+ * @see Learn how to style tables and customize table element components:
20
+ * {@link https://prismic.io/docs/fields/table}
21
+ */
22
+ const PrismicTable = ({ components, ...restProps }) => {
23
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_prismicio_react.PrismicTable, {
24
+ components: {
25
+ ...require_PrismicRichText.defaultComponents,
26
+ ...components
27
+ },
28
+ ...restProps
29
+ });
30
+ };
31
+
32
+ //#endregion
33
+ exports.PrismicTable = PrismicTable;
34
+ //# sourceMappingURL=PrismicTable.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismicTable.cjs","names":["BasePrismicTable","defaultComponents"],"sources":["../src/PrismicTable.tsx"],"sourcesContent":["\"use client\";\n\nimport { defaultComponents } from \"./PrismicRichText\";\nimport {\n\tPrismicTable as BasePrismicTable,\n\ttype PrismicTableProps,\n} from \"@prismicio/react\";\nimport type { FC } from \"react\";\n\n/**\n * Renders content from a Prismic table field as React components with\n * Next.js-optimized defaults for images and links in cell content.\n *\n * @example\n *\n * ```tsx\n * <PrismicTable field={slice.primary.pricing_table} />;\n * ```\n *\n * @see Learn how to style tables and customize table element components:\n * {@link https://prismic.io/docs/fields/table}\n */\nexport const PrismicTable: FC<PrismicTableProps> = ({\n\tcomponents,\n\t...restProps\n}) => {\n\treturn (\n\t\t<BasePrismicTable\n\t\t\tcomponents={{ ...defaultComponents, ...components }}\n\t\t\t{...restProps}\n\t\t/>\n\t);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,gBAAuC,EACnD,YACA,GAAG,gBACE;AACL,QACC,2CAACA;EACA,YAAY;GAAE,GAAGC;GAAmB,GAAG;GAAY;EACnD,GAAI;GACH"}
@@ -0,0 +1,22 @@
1
+ import { FC } from "react";
2
+ import { PrismicTableProps } from "@prismicio/react";
3
+
4
+ //#region src/PrismicTable.d.ts
5
+
6
+ /**
7
+ * Renders content from a Prismic table field as React components with
8
+ * Next.js-optimized defaults for images and links in cell content.
9
+ *
10
+ * @example
11
+ *
12
+ * ```tsx
13
+ * <PrismicTable field={slice.primary.pricing_table} />;
14
+ * ```
15
+ *
16
+ * @see Learn how to style tables and customize table element components:
17
+ * {@link https://prismic.io/docs/fields/table}
18
+ */
19
+ declare const PrismicTable: FC<PrismicTableProps>;
20
+ //#endregion
21
+ export { PrismicTable };
22
+ //# sourceMappingURL=PrismicTable.d.cts.map
package/dist/index.cjs CHANGED
@@ -1,18 +1,44 @@
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
1
2
  const require_exitPreview = require('./exitPreview.cjs');
2
3
  const require_PrismicPreview = require('./PrismicPreview.cjs');
3
- const require_PrismicNextLink = require('./PrismicNextLink.cjs');
4
+ const require_imgixLoader = require('./imgixLoader.cjs');
5
+ const require_PrismicImage = require('./PrismicImage.cjs');
6
+ const require_PrismicLink = require('./PrismicLink.cjs');
7
+ const require_PrismicRichText = require('./PrismicRichText.cjs');
8
+ const require_PrismicTable = require('./PrismicTable.cjs');
4
9
  const require_enableAutoPreviews = require('./enableAutoPreviews.cjs');
5
10
  const require_redirectToPreviewURL = require('./redirectToPreviewURL.cjs');
6
- const require_imgixLoader = require('./imgixLoader.cjs');
7
- const require_PrismicNextImage = require('./PrismicNextImage.cjs');
8
11
  const require_getSlices = require('./getSlices.cjs');
9
12
  const require_SliceSimulator = require('./SliceSimulator.cjs');
10
13
  const require_createLocaleRedirect = require('./createLocaleRedirect.cjs');
14
+ let _prismicio_react = require("@prismicio/react");
11
15
 
12
- exports.PrismicNextImage = require_PrismicNextImage.PrismicNextImage;
13
- exports.PrismicNextLink = require_PrismicNextLink.PrismicNextLink;
16
+ exports.PrismicImage = require_PrismicImage.PrismicImage;
17
+ exports.PrismicLink = require_PrismicLink.PrismicLink;
18
+ exports.PrismicNextImage = require_PrismicImage.PrismicImage;
19
+ exports.PrismicNextLink = require_PrismicLink.PrismicLink;
14
20
  exports.PrismicPreview = require_PrismicPreview.PrismicPreview;
21
+ exports.PrismicRichText = require_PrismicRichText.PrismicRichText;
22
+ exports.PrismicTable = require_PrismicTable.PrismicTable;
23
+ Object.defineProperty(exports, 'PrismicText', {
24
+ enumerable: true,
25
+ get: function () {
26
+ return _prismicio_react.PrismicText;
27
+ }
28
+ });
15
29
  exports.SliceSimulator = require_SliceSimulator.SliceSimulator;
30
+ Object.defineProperty(exports, 'SliceZone', {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _prismicio_react.SliceZone;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, 'TODOSliceComponent', {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _prismicio_react.TODOSliceComponent;
40
+ }
41
+ });
16
42
  exports.createLocaleRedirect = require_createLocaleRedirect.createLocaleRedirect;
17
43
  exports.enableAutoPreviews = require_enableAutoPreviews.enableAutoPreviews;
18
44
  exports.exitPreview = require_exitPreview.exitPreview;
package/dist/index.d.cts CHANGED
@@ -1,12 +1,15 @@
1
1
  import { exitPreview } from "./exitPreview.cjs";
2
2
  import { PrismicPreview, PrismicPreviewProps } from "./PrismicPreview.cjs";
3
- import { PrismicNextLink, PrismicNextLinkProps } from "./PrismicNextLink.cjs";
3
+ import { PrismicImage, PrismicImageProps } from "./PrismicImage.cjs";
4
+ import { PrismicLink, PrismicLinkProps } from "./PrismicLink.cjs";
5
+ import { PrismicRichText, PrismicRichTextProps } from "./PrismicRichText.cjs";
6
+ import { PrismicTable } from "./PrismicTable.cjs";
4
7
  import { EnableAutoPreviewsConfig, enableAutoPreviews } from "./enableAutoPreviews.cjs";
5
8
  import { CreateClientConfig } from "./types.cjs";
6
9
  import { RedirectToPreviewURLConfig, redirectToPreviewURL } from "./redirectToPreviewURL.cjs";
7
- import { PrismicNextImage, PrismicNextImageProps } from "./PrismicNextImage.cjs";
8
10
  import { SliceSimulator, SliceSimulatorParams, SliceSimulatorProps } from "./SliceSimulator.cjs";
9
11
  import { getSlices } from "./getSlices.cjs";
10
12
  import { imgixLoader } from "./imgixLoader.cjs";
11
13
  import { CreateLocaleRedirectConfig, createLocaleRedirect } from "./createLocaleRedirect.cjs";
12
- export { type CreateClientConfig, type CreateLocaleRedirectConfig, type EnableAutoPreviewsConfig, PrismicNextImage, type PrismicNextImageProps, PrismicNextLink, type PrismicNextLinkProps, PrismicPreview, type PrismicPreviewProps, type RedirectToPreviewURLConfig, SliceSimulator, type SliceSimulatorParams, type SliceSimulatorProps, createLocaleRedirect, enableAutoPreviews, exitPreview, getSlices, imgixLoader, redirectToPreviewURL };
14
+ import { PrismicTableProps, PrismicText, PrismicTextProps, RichTextComponents, SliceComponentProps, SliceComponentType, SliceZone, SliceZoneProps, TODOSliceComponent } from "@prismicio/react";
15
+ export { type CreateClientConfig, type CreateLocaleRedirectConfig, type EnableAutoPreviewsConfig, PrismicImage, type PrismicImageProps, PrismicLink, type PrismicLinkProps, PrismicImage as PrismicNextImage, type PrismicImageProps as PrismicNextImageProps, PrismicLink as PrismicNextLink, type PrismicLinkProps as PrismicNextLinkProps, PrismicPreview, type PrismicPreviewProps, PrismicRichText, type PrismicRichTextProps, PrismicTable, type PrismicTableProps, PrismicText, type PrismicTextProps, type RedirectToPreviewURLConfig, type RichTextComponents, type SliceComponentProps, type SliceComponentType, SliceSimulator, type SliceSimulatorParams, type SliceSimulatorProps, SliceZone, type SliceZoneProps, TODOSliceComponent, createLocaleRedirect, enableAutoPreviews, exitPreview, getSlices, imgixLoader, redirectToPreviewURL };
package/dist/package.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  //#region package.json
3
- var version = "2.2.0-canary.469c917";
3
+ var version = "2.2.0-pr.123.1c009e2";
4
4
 
5
5
  //#endregion
6
6
  Object.defineProperty(exports, 'version', {
package/dist/pages.cjs CHANGED
@@ -1,6 +1,9 @@
1
- const require_PrismicNextLink = require('./PrismicNextLink.cjs');
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
2
  const require_imgixLoader = require('./imgixLoader.cjs');
3
- const require_PrismicNextImage = require('./PrismicNextImage.cjs');
3
+ const require_PrismicImage = require('./PrismicImage.cjs');
4
+ const require_PrismicLink = require('./PrismicLink.cjs');
5
+ const require_PrismicRichText = require('./PrismicRichText.cjs');
6
+ const require_PrismicTable = require('./PrismicTable.cjs');
4
7
  const require_createLocaleRedirect = require('./createLocaleRedirect.cjs');
5
8
  const require_SliceSimulator = require('./pages/SliceSimulator.cjs');
6
9
  const require_PrismicPreview = require('./pages/PrismicPreview.cjs');
@@ -8,11 +11,34 @@ const require_enableAutoPreviews = require('./pages/enableAutoPreviews.cjs');
8
11
  const require_redirectToPreviewURL = require('./pages/redirectToPreviewURL.cjs');
9
12
  const require_exitPreview = require('./pages/exitPreview.cjs');
10
13
  const require_setPreviewData = require('./pages/setPreviewData.cjs');
14
+ let _prismicio_react = require("@prismicio/react");
11
15
 
12
- exports.PrismicNextImage = require_PrismicNextImage.PrismicNextImage;
13
- exports.PrismicNextLink = require_PrismicNextLink.PrismicNextLink;
16
+ exports.PrismicImage = require_PrismicImage.PrismicImage;
17
+ exports.PrismicLink = require_PrismicLink.PrismicLink;
18
+ exports.PrismicNextImage = require_PrismicImage.PrismicImage;
19
+ exports.PrismicNextLink = require_PrismicLink.PrismicLink;
14
20
  exports.PrismicPreview = require_PrismicPreview.PrismicPreview;
21
+ exports.PrismicRichText = require_PrismicRichText.PrismicRichText;
22
+ exports.PrismicTable = require_PrismicTable.PrismicTable;
23
+ Object.defineProperty(exports, 'PrismicText', {
24
+ enumerable: true,
25
+ get: function () {
26
+ return _prismicio_react.PrismicText;
27
+ }
28
+ });
15
29
  exports.SliceSimulator = require_SliceSimulator.SliceSimulator;
30
+ Object.defineProperty(exports, 'SliceZone', {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _prismicio_react.SliceZone;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, 'TODOSliceComponent', {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _prismicio_react.TODOSliceComponent;
40
+ }
41
+ });
16
42
  exports.createLocaleRedirect = require_createLocaleRedirect.createLocaleRedirect;
17
43
  exports.enableAutoPreviews = require_enableAutoPreviews.enableAutoPreviews;
18
44
  exports.exitPreview = require_exitPreview.exitPreview;
package/dist/pages.d.cts CHANGED
@@ -1,5 +1,7 @@
1
- import { PrismicNextLink, PrismicNextLinkProps } from "./PrismicNextLink.cjs";
2
- import { PrismicNextImage, PrismicNextImageProps } from "./PrismicNextImage.cjs";
1
+ import { PrismicImage, PrismicImageProps } from "./PrismicImage.cjs";
2
+ import { PrismicLink, PrismicLinkProps } from "./PrismicLink.cjs";
3
+ import { PrismicRichText, PrismicRichTextProps } from "./PrismicRichText.cjs";
4
+ import { PrismicTable } from "./PrismicTable.cjs";
3
5
  import { imgixLoader } from "./imgixLoader.cjs";
4
6
  import { CreateLocaleRedirectConfig, createLocaleRedirect } from "./createLocaleRedirect.cjs";
5
7
  import { SliceSimulator, SliceSimulatorProps, SliceSimulatorSliceZoneProps } from "./pages/SliceSimulator.cjs";
@@ -9,4 +11,5 @@ import { EnableAutoPreviewsConfig, enableAutoPreviews } from "./pages/enableAuto
9
11
  import { RedirectToPreviewURLConfig, redirectToPreviewURL } from "./pages/redirectToPreviewURL.cjs";
10
12
  import { ExitPreviewAPIRouteConfig, exitPreview } from "./pages/exitPreview.cjs";
11
13
  import { SetPreviewDataConfig, setPreviewData } from "./pages/setPreviewData.cjs";
12
- export { type CreateClientConfig, type CreateLocaleRedirectConfig, type EnableAutoPreviewsConfig, type ExitPreviewAPIRouteConfig, PrismicNextImage, type PrismicNextImageProps, PrismicNextLink, type PrismicNextLinkProps, PrismicPreview, type PrismicPreviewProps, type RedirectToPreviewURLConfig, type SetPreviewDataConfig, SliceSimulator, type SliceSimulatorProps, type SliceSimulatorSliceZoneProps, createLocaleRedirect, enableAutoPreviews, exitPreview, imgixLoader, redirectToPreviewURL, setPreviewData };
14
+ import { PrismicTableProps, PrismicText, PrismicTextProps, RichTextComponents, SliceComponentProps, SliceComponentType, SliceZone, SliceZoneProps, TODOSliceComponent } from "@prismicio/react";
15
+ export { type CreateClientConfig, type CreateLocaleRedirectConfig, type EnableAutoPreviewsConfig, type ExitPreviewAPIRouteConfig, PrismicImage, type PrismicImageProps, PrismicLink, type PrismicLinkProps, PrismicImage as PrismicNextImage, type PrismicImageProps as PrismicNextImageProps, PrismicLink as PrismicNextLink, type PrismicLinkProps as PrismicNextLinkProps, PrismicPreview, type PrismicPreviewProps, PrismicRichText, type PrismicRichTextProps, PrismicTable, type PrismicTableProps, PrismicText, type PrismicTextProps, type RedirectToPreviewURLConfig, type RichTextComponents, type SetPreviewDataConfig, type SliceComponentProps, type SliceComponentType, SliceSimulator, type SliceSimulatorProps, type SliceSimulatorSliceZoneProps, SliceZone, type SliceZoneProps, TODOSliceComponent, createLocaleRedirect, enableAutoPreviews, exitPreview, imgixLoader, redirectToPreviewURL, setPreviewData };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/next",
3
- "version": "2.2.0-canary.469c917",
3
+ "version": "2.2.0-pr.123.1c009e2",
4
4
  "description": "Helpers to integrate Prismic into Next.js apps",
5
5
  "keywords": [
6
6
  "typescript",
@@ -55,13 +55,14 @@
55
55
  "types": "tsc --noEmit"
56
56
  },
57
57
  "dependencies": {
58
+ "@prismicio/react": "^3.3.0",
58
59
  "@prismicio/simulator": "^0.2.0",
59
60
  "imgix-url-builder": "^0.0.5",
60
61
  "lz-string": "^1.5.0"
61
62
  },
62
63
  "devDependencies": {
63
64
  "@playwright/test": "^1.49.1",
64
- "@prismicio/client": "^7.12.0",
65
+ "@prismicio/client": "^7.21.3",
65
66
  "@trivago/prettier-plugin-sort-imports": "^6.0.2",
66
67
  "@types/node": "^22.10.2",
67
68
  "@types/react": "^19.2.3",
@@ -0,0 +1,187 @@
1
+ "use client";
2
+
3
+ import { imgixLoader } from "./imgixLoader";
4
+ import { devMsg } from "./lib/devMsg";
5
+ import { resolveDefaultExport } from "./lib/resolveDefaultExport";
6
+ import type { ImageFieldImage } from "@prismicio/client";
7
+ import { isFilled } from "@prismicio/client";
8
+ import type { ImgixURLParams } from "imgix-url-builder";
9
+ import { buildURL } from "imgix-url-builder";
10
+ import type { ImageProps } from "next/image";
11
+ import Image from "next/image";
12
+ import type {
13
+ ForwardRefExoticComponent,
14
+ PropsWithoutRef,
15
+ RefAttributes,
16
+ } from "react";
17
+ import { forwardRef } from "react";
18
+
19
+ /**
20
+ * @deprecated Use `PrismicImage` instead.
21
+ */
22
+ export { PrismicImage as PrismicNextImage };
23
+
24
+ /**
25
+ * @deprecated Use `PrismicImageProps` instead.
26
+ */
27
+ export type { PrismicImageProps as PrismicNextImageProps };
28
+
29
+ const castInt = (input: string | number | undefined): number | undefined => {
30
+ if (typeof input === "number" || typeof input === "undefined") {
31
+ return input;
32
+ } else {
33
+ const parsed = Number.parseInt(input);
34
+
35
+ if (Number.isNaN(parsed)) {
36
+ return undefined;
37
+ } else {
38
+ return parsed;
39
+ }
40
+ }
41
+ };
42
+
43
+ export type PrismicImageProps = Omit<ImageProps, "src" | "alt" | "loader"> & {
44
+ /** The Prismic Image field or thumbnail to render. */
45
+ field: ImageFieldImage | null | undefined;
46
+
47
+ /**
48
+ * An object of Imgix URL API parameters to transform the image.
49
+ *
50
+ * @see https://docs.imgix.com/apis/rendering
51
+ */
52
+ imgixParams?: { [P in keyof ImgixURLParams]: ImgixURLParams[P] | null };
53
+
54
+ /**
55
+ * Declare an image as decorative by providing `alt=""`.
56
+ *
57
+ * See:
58
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
59
+ */
60
+ alt?: "";
61
+
62
+ /**
63
+ * Declare an image as decorative only if the Image field does not have
64
+ * alternative text by providing `fallbackAlt=""`.
65
+ *
66
+ * See:
67
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
68
+ */
69
+ fallbackAlt?: "";
70
+
71
+ /**
72
+ * Rendered when the field is empty. If a fallback is not given, `null` will
73
+ * be rendered.
74
+ */
75
+ fallback?: React.ReactNode;
76
+
77
+ loader?: ImageProps["loader"] | null;
78
+ };
79
+
80
+ /**
81
+ * React component that renders an image from a Prismic Image field or one of
82
+ * its thumbnails using `next/image`. It will automatically set the `alt`
83
+ * attribute using the Image field's `alt` property.
84
+ *
85
+ * It uses an Imgix URL-based loader by default. A custom loader can be provided
86
+ * with the `loader` prop. If you would like to use the Next.js Image
87
+ * Optimization API instead, set `loader={undefined}`.
88
+ *
89
+ * @param props - Props for the component.
90
+ *
91
+ * @returns A responsive image component using `next/image` for the given Image
92
+ * field.
93
+ *
94
+ * @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image
95
+ */
96
+ // The type annotation is necessary to avoid a type reference issue.
97
+ export const PrismicImage: ForwardRefExoticComponent<
98
+ PropsWithoutRef<PrismicImageProps> & RefAttributes<HTMLImageElement>
99
+ > = forwardRef<HTMLImageElement, PrismicImageProps>(function PrismicImage(
100
+ {
101
+ field,
102
+ imgixParams = {},
103
+ alt,
104
+ fallbackAlt,
105
+ fill,
106
+ width,
107
+ height,
108
+ fallback = null,
109
+ loader = imgixLoader,
110
+ ...restProps
111
+ },
112
+ ref,
113
+ ) {
114
+ if (process.env.NODE_ENV === "development") {
115
+ if (typeof alt === "string" && alt !== "") {
116
+ console.warn(
117
+ `[PrismicImage] 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(
118
+ "alt-must-be-an-empty-string",
119
+ )}`,
120
+ );
121
+ }
122
+
123
+ if (typeof fallbackAlt === "string" && fallbackAlt !== "") {
124
+ console.warn(
125
+ `[PrismicImage] 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(
126
+ "alt-must-be-an-empty-string",
127
+ )}`,
128
+ );
129
+ }
130
+ }
131
+
132
+ if (!isFilled.imageThumbnail(field)) {
133
+ return <>{fallback}</>;
134
+ }
135
+
136
+ const resolvedImgixParams = imgixParams;
137
+ for (const x in imgixParams) {
138
+ if (resolvedImgixParams[x as keyof typeof resolvedImgixParams] === null) {
139
+ resolvedImgixParams[x as keyof typeof resolvedImgixParams] = undefined;
140
+ }
141
+ }
142
+
143
+ const src = buildURL(field.url, imgixParams as ImgixURLParams);
144
+
145
+ const ar = field.dimensions.width / field.dimensions.height;
146
+
147
+ const castedWidth = castInt(width);
148
+ const castedHeight = castInt(height);
149
+
150
+ let resolvedWidth = castedWidth ?? field.dimensions.width;
151
+ let resolvedHeight = castedHeight ?? field.dimensions.height;
152
+
153
+ if (castedWidth != null && castedHeight == null) {
154
+ resolvedHeight = castedWidth / ar;
155
+ } else if (castedWidth == null && castedHeight != null) {
156
+ resolvedWidth = castedHeight * ar;
157
+ }
158
+
159
+ // A non-null assertion is required since we can't statically
160
+ // know if an alt attribute is available.
161
+ const resolvedAlt = (alt ?? (field.alt || fallbackAlt))!;
162
+
163
+ if (
164
+ process.env.NODE_ENV === "development" &&
165
+ typeof resolvedAlt !== "string"
166
+ ) {
167
+ console.error(
168
+ `[PrismicImage] 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=""\`.`,
169
+ src,
170
+ );
171
+ }
172
+
173
+ const ResolvedImage = resolveDefaultExport(Image);
174
+
175
+ return (
176
+ <ResolvedImage
177
+ ref={ref}
178
+ src={src}
179
+ width={fill ? undefined : resolvedWidth}
180
+ height={fill ? undefined : resolvedHeight}
181
+ alt={resolvedAlt}
182
+ fill={fill}
183
+ loader={loader === null ? undefined : loader}
184
+ {...restProps}
185
+ />
186
+ );
187
+ });
@@ -0,0 +1,74 @@
1
+ import { resolveDefaultExport } from "./lib/resolveDefaultExport";
2
+ import type {
3
+ AsLinkAttrsConfig,
4
+ LinkField,
5
+ LinkResolverFunction,
6
+ PrismicDocument,
7
+ } from "@prismicio/client";
8
+ import { asLinkAttrs } from "@prismicio/client";
9
+ import Link from "next/link";
10
+ import type { ComponentProps } from "react";
11
+ import { forwardRef } from "react";
12
+
13
+ /**
14
+ * @deprecated Use `PrismicLink` instead.
15
+ */
16
+ export { PrismicLink as PrismicNextLink } from "./PrismicLink";
17
+
18
+ /**
19
+ * @deprecated Use `PrismicLinkProps` instead.
20
+ */
21
+ export type { PrismicLinkProps as PrismicNextLinkProps } from "./PrismicLink";
22
+
23
+ export type PrismicLinkProps = Omit<
24
+ ComponentProps<typeof Link>,
25
+ "field" | "document" | "href" | "rel"
26
+ > & {
27
+ linkResolver?: LinkResolverFunction;
28
+ rel?: string | AsLinkAttrsConfig["rel"];
29
+ } & (
30
+ | {
31
+ field: LinkField | null | undefined;
32
+ document?: never;
33
+ href?: never;
34
+ }
35
+ | {
36
+ field?: never;
37
+ document: PrismicDocument | null | undefined;
38
+ href?: never;
39
+ }
40
+ | {
41
+ field?: never;
42
+ document?: never;
43
+ href: ComponentProps<typeof Link>["href"];
44
+ }
45
+ );
46
+
47
+ export const PrismicLink = forwardRef<HTMLAnchorElement, PrismicLinkProps>(
48
+ function PrismicLink(props, ref) {
49
+ const { field, document, linkResolver, children, ...restProps } = props;
50
+ const {
51
+ href: computedHref,
52
+ rel: computedRel,
53
+ ...attrs
54
+ } = asLinkAttrs(field ?? document, {
55
+ linkResolver,
56
+ rel: typeof restProps.rel === "function" ? restProps.rel : undefined,
57
+ });
58
+
59
+ const href = ("href" in restProps ? restProps.href : computedHref) || "";
60
+
61
+ let rel = computedRel;
62
+ if ("rel" in restProps && typeof restProps.rel !== "function") {
63
+ rel = restProps.rel;
64
+ }
65
+
66
+ const ResolvedLink = resolveDefaultExport(Link);
67
+
68
+ return (
69
+ <ResolvedLink ref={ref} {...attrs} {...restProps} href={href} rel={rel}>
70
+ {"children" in props ? children : field?.text}
71
+ </ResolvedLink>
72
+ );
73
+ },
74
+ );
@@ -0,0 +1,63 @@
1
+ "use client";
2
+
3
+ import { PrismicImage } from "./PrismicImage";
4
+ import { PrismicLink } from "./PrismicLink";
5
+ import {
6
+ PrismicRichText as BasePrismicRichText,
7
+ type PrismicRichTextProps as BasePrismicRichTextProps,
8
+ type RichTextComponents,
9
+ } from "@prismicio/react";
10
+ import type { FC } from "react";
11
+
12
+ /**
13
+ * Props for `<PrismicRichText>`.
14
+ */
15
+ export type PrismicRichTextProps = Omit<
16
+ BasePrismicRichTextProps,
17
+ "components"
18
+ > & {
19
+ components?: RichTextComponents;
20
+ };
21
+
22
+ export const defaultComponents: RichTextComponents = {
23
+ image: ({ node, key }) => {
24
+ return (
25
+ <p key={key} className="block-img">
26
+ {node.linkTo ? (
27
+ <PrismicLink field={node.linkTo}>
28
+ <PrismicImage field={node} />
29
+ </PrismicLink>
30
+ ) : (
31
+ <PrismicImage field={node} />
32
+ )}
33
+ </p>
34
+ );
35
+ },
36
+ hyperlink: ({ node, children }) => (
37
+ <PrismicLink field={node.data}>{children}</PrismicLink>
38
+ ),
39
+ };
40
+
41
+ /**
42
+ * Renders content from a Prismic rich text field as React components with
43
+ * Next.js-optimized defaults for images and links.
44
+ *
45
+ * @example
46
+ *
47
+ * ```tsx
48
+ * <PrismicRichText field={slice.primary.text} />;
49
+ * ```
50
+ *
51
+ * @see {@link https://prismic.io/docs/fields/rich-text}
52
+ */
53
+ export const PrismicRichText: FC<PrismicRichTextProps> = ({
54
+ components,
55
+ ...restProps
56
+ }) => {
57
+ return (
58
+ <BasePrismicRichText
59
+ components={{ ...defaultComponents, ...components }}
60
+ {...restProps}
61
+ />
62
+ );
63
+ };
@@ -0,0 +1,33 @@
1
+ "use client";
2
+
3
+ import { defaultComponents } from "./PrismicRichText";
4
+ import {
5
+ PrismicTable as BasePrismicTable,
6
+ type PrismicTableProps,
7
+ } from "@prismicio/react";
8
+ import type { FC } from "react";
9
+
10
+ /**
11
+ * Renders content from a Prismic table field as React components with
12
+ * Next.js-optimized defaults for images and links in cell content.
13
+ *
14
+ * @example
15
+ *
16
+ * ```tsx
17
+ * <PrismicTable field={slice.primary.pricing_table} />;
18
+ * ```
19
+ *
20
+ * @see Learn how to style tables and customize table element components:
21
+ * {@link https://prismic.io/docs/fields/table}
22
+ */
23
+ export const PrismicTable: FC<PrismicTableProps> = ({
24
+ components,
25
+ ...restProps
26
+ }) => {
27
+ return (
28
+ <BasePrismicTable
29
+ components={{ ...defaultComponents, ...components }}
30
+ {...restProps}
31
+ />
32
+ );
33
+ };
package/src/index.ts CHANGED
@@ -3,8 +3,17 @@ export { exitPreview } from "./exitPreview";
3
3
  export { PrismicPreview } from "./PrismicPreview";
4
4
  export type { PrismicPreviewProps } from "./PrismicPreview";
5
5
 
6
- export { PrismicNextLink } from "./PrismicNextLink";
7
- export type { PrismicNextLinkProps } from "./PrismicNextLink";
6
+ export { PrismicImage, PrismicNextImage } from "./PrismicImage";
7
+ export type { PrismicImageProps, PrismicNextImageProps } from "./PrismicImage";
8
+
9
+ export { PrismicLink, PrismicNextLink } from "./PrismicLink";
10
+ export type { PrismicLinkProps, PrismicNextLinkProps } from "./PrismicLink";
11
+
12
+ export { PrismicRichText } from "./PrismicRichText";
13
+ export type { PrismicRichTextProps } from "./PrismicRichText";
14
+
15
+ export { PrismicTable } from "./PrismicTable";
16
+ export type { PrismicTableProps } from "@prismicio/react";
8
17
 
9
18
  export { enableAutoPreviews } from "./enableAutoPreviews";
10
19
  export type { EnableAutoPreviewsConfig } from "./enableAutoPreviews";
@@ -12,9 +21,6 @@ export type { EnableAutoPreviewsConfig } from "./enableAutoPreviews";
12
21
  export { redirectToPreviewURL } from "./redirectToPreviewURL";
13
22
  export type { RedirectToPreviewURLConfig } from "./redirectToPreviewURL";
14
23
 
15
- export { PrismicNextImage } from "./PrismicNextImage";
16
- export type { PrismicNextImageProps } from "./PrismicNextImage";
17
-
18
24
  export { SliceSimulator } from "./SliceSimulator";
19
25
  export type {
20
26
  SliceSimulatorProps,
@@ -29,3 +35,13 @@ export type { CreateClientConfig } from "./types";
29
35
 
30
36
  export { createLocaleRedirect } from "./createLocaleRedirect";
31
37
  export type { CreateLocaleRedirectConfig } from "./createLocaleRedirect";
38
+
39
+ // Re-exports from @prismicio/react
40
+ export { PrismicText, SliceZone, TODOSliceComponent } from "@prismicio/react";
41
+ export type {
42
+ SliceComponentProps,
43
+ SliceComponentType,
44
+ SliceZoneProps,
45
+ RichTextComponents,
46
+ PrismicTextProps,
47
+ } from "@prismicio/react";
@@ -1,8 +1,14 @@
1
- export { PrismicNextLink } from "../PrismicNextLink";
2
- export { type PrismicNextLinkProps } from "../PrismicNextLink";
1
+ export { PrismicImage, PrismicNextImage } from "../PrismicImage";
2
+ export type { PrismicImageProps, PrismicNextImageProps } from "../PrismicImage";
3
3
 
4
- export { PrismicNextImage } from "../PrismicNextImage";
5
- export { type PrismicNextImageProps } from "../PrismicNextImage";
4
+ export { PrismicLink, PrismicNextLink } from "../PrismicLink";
5
+ export type { PrismicLinkProps, PrismicNextLinkProps } from "../PrismicLink";
6
+
7
+ export { PrismicRichText } from "../PrismicRichText";
8
+ export type { PrismicRichTextProps } from "../PrismicRichText";
9
+
10
+ export { PrismicTable } from "../PrismicTable";
11
+ export type { PrismicTableProps } from "@prismicio/react";
6
12
 
7
13
  export { SliceSimulator } from "./SliceSimulator";
8
14
  export type {
@@ -31,3 +37,13 @@ export type { CreateClientConfig } from "./types";
31
37
 
32
38
  export { createLocaleRedirect } from "../createLocaleRedirect";
33
39
  export type { CreateLocaleRedirectConfig } from "../createLocaleRedirect";
40
+
41
+ // Re-exports from @prismicio/react
42
+ export { PrismicText, SliceZone, TODOSliceComponent } from "@prismicio/react";
43
+ export type {
44
+ SliceComponentProps,
45
+ SliceComponentType,
46
+ SliceZoneProps,
47
+ RichTextComponents,
48
+ PrismicTextProps,
49
+ } from "@prismicio/react";
@@ -1 +0,0 @@
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"}
@@ -1 +0,0 @@
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"}
@@ -1,185 +0,0 @@
1
- "use client";
2
-
3
- import type {
4
- ForwardRefExoticComponent,
5
- PropsWithoutRef,
6
- RefAttributes} from "react";
7
- import {
8
- forwardRef
9
- } from "react";
10
- import type { ImageProps } from "next/image";
11
- import Image from "next/image";
12
- import type { ImgixURLParams } from "imgix-url-builder";
13
- import { buildURL } from "imgix-url-builder";
14
- import type { ImageFieldImage} from "@prismicio/client";
15
- import { isFilled } from "@prismicio/client";
16
-
17
- import { devMsg } from "./lib/devMsg";
18
- import { resolveDefaultExport } from "./lib/resolveDefaultExport";
19
-
20
- import { imgixLoader } from "./imgixLoader";
21
-
22
- const castInt = (input: string | number | undefined): number | undefined => {
23
- if (typeof input === "number" || typeof input === "undefined") {
24
- return input;
25
- } else {
26
- const parsed = Number.parseInt(input);
27
-
28
- if (Number.isNaN(parsed)) {
29
- return undefined;
30
- } else {
31
- return parsed;
32
- }
33
- }
34
- };
35
-
36
- export type PrismicNextImageProps = Omit<
37
- ImageProps,
38
- "src" | "alt" | "loader"
39
- > & {
40
- /** The Prismic Image field or thumbnail to render. */
41
- field: ImageFieldImage | null | undefined;
42
-
43
- /**
44
- * An object of Imgix URL API parameters to transform the image.
45
- *
46
- * @see https://docs.imgix.com/apis/rendering
47
- */
48
- imgixParams?: { [P in keyof ImgixURLParams]: ImgixURLParams[P] | null };
49
-
50
- /**
51
- * Declare an image as decorative by providing `alt=""`.
52
- *
53
- * See:
54
- * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
55
- */
56
- alt?: "";
57
-
58
- /**
59
- * Declare an image as decorative only if the Image field does not have
60
- * alternative text by providing `fallbackAlt=""`.
61
- *
62
- * See:
63
- * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
64
- */
65
- fallbackAlt?: "";
66
-
67
- /**
68
- * Rendered when the field is empty. If a fallback is not given, `null` will
69
- * be rendered.
70
- */
71
- fallback?: React.ReactNode;
72
-
73
- loader?: ImageProps["loader"] | null;
74
- };
75
-
76
- /**
77
- * React component that renders an image from a Prismic Image field or one of
78
- * its thumbnails using `next/image`. It will automatically set the `alt`
79
- * attribute using the Image field's `alt` property.
80
- *
81
- * It uses an Imgix URL-based loader by default. A custom loader can be provided
82
- * with the `loader` prop. If you would like to use the Next.js Image
83
- * Optimization API instead, set `loader={undefined}`.
84
- *
85
- * @param props - Props for the component.
86
- *
87
- * @returns A responsive image component using `next/image` for the given Image
88
- * field.
89
- *
90
- * @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image
91
- */
92
- // The type annotation is necessary to avoid a type reference issue.
93
- export const PrismicNextImage: ForwardRefExoticComponent<
94
- PropsWithoutRef<PrismicNextImageProps> & RefAttributes<HTMLImageElement>
95
- > = forwardRef<HTMLImageElement, PrismicNextImageProps>(
96
- function PrismicNextImage(
97
- {
98
- field,
99
- imgixParams = {},
100
- alt,
101
- fallbackAlt,
102
- fill,
103
- width,
104
- height,
105
- fallback = null,
106
- loader = imgixLoader,
107
- ...restProps
108
- },
109
- ref,
110
- ) {
111
- if (process.env.NODE_ENV === "development") {
112
- if (typeof alt === "string" && alt !== "") {
113
- console.warn(
114
- `[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(
115
- "alt-must-be-an-empty-string",
116
- )}`,
117
- );
118
- }
119
-
120
- if (typeof fallbackAlt === "string" && fallbackAlt !== "") {
121
- console.warn(
122
- `[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(
123
- "alt-must-be-an-empty-string",
124
- )}`,
125
- );
126
- }
127
- }
128
-
129
- if (!isFilled.imageThumbnail(field)) {
130
- return <>{fallback}</>;
131
- }
132
-
133
- const resolvedImgixParams = imgixParams;
134
- for (const x in imgixParams) {
135
- if (resolvedImgixParams[x as keyof typeof resolvedImgixParams] === null) {
136
- resolvedImgixParams[x as keyof typeof resolvedImgixParams] = undefined;
137
- }
138
- }
139
-
140
- const src = buildURL(field.url, imgixParams as ImgixURLParams);
141
-
142
- const ar = field.dimensions.width / field.dimensions.height;
143
-
144
- const castedWidth = castInt(width);
145
- const castedHeight = castInt(height);
146
-
147
- let resolvedWidth = castedWidth ?? field.dimensions.width;
148
- let resolvedHeight = castedHeight ?? field.dimensions.height;
149
-
150
- if (castedWidth != null && castedHeight == null) {
151
- resolvedHeight = castedWidth / ar;
152
- } else if (castedWidth == null && castedHeight != null) {
153
- resolvedWidth = castedHeight * ar;
154
- }
155
-
156
- // A non-null assertion is required since we can't statically
157
- // know if an alt attribute is available.
158
- const resolvedAlt = (alt ?? (field.alt || fallbackAlt))!;
159
-
160
- if (
161
- process.env.NODE_ENV === "development" &&
162
- typeof resolvedAlt !== "string"
163
- ) {
164
- console.error(
165
- `[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=""\`.`,
166
- src,
167
- );
168
- }
169
-
170
- const ResolvedImage = resolveDefaultExport(Image);
171
-
172
- return (
173
- <ResolvedImage
174
- ref={ref}
175
- src={src}
176
- width={fill ? undefined : resolvedWidth}
177
- height={fill ? undefined : resolvedHeight}
178
- alt={resolvedAlt}
179
- fill={fill}
180
- loader={loader === null ? undefined : loader}
181
- {...restProps}
182
- />
183
- );
184
- },
185
- );
@@ -1,67 +0,0 @@
1
- import type { ComponentProps} from "react";
2
- import { forwardRef } from "react";
3
- import Link from "next/link";
4
- import type {
5
- AsLinkAttrsConfig,
6
- LinkField,
7
- LinkResolverFunction,
8
- PrismicDocument} from "@prismicio/client";
9
- import {
10
- asLinkAttrs,
11
- } from "@prismicio/client";
12
-
13
- import { resolveDefaultExport } from "./lib/resolveDefaultExport";
14
-
15
- export type PrismicNextLinkProps = Omit<
16
- ComponentProps<typeof Link>,
17
- "field" | "document" | "href" | "rel"
18
- > & {
19
- linkResolver?: LinkResolverFunction;
20
- rel?: string | AsLinkAttrsConfig["rel"];
21
- } & (
22
- | {
23
- field: LinkField | null | undefined;
24
- document?: never;
25
- href?: never;
26
- }
27
- | {
28
- field?: never;
29
- document: PrismicDocument | null | undefined;
30
- href?: never;
31
- }
32
- | {
33
- field?: never;
34
- document?: never;
35
- href: ComponentProps<typeof Link>["href"];
36
- }
37
- );
38
-
39
- export const PrismicNextLink = forwardRef<
40
- HTMLAnchorElement,
41
- PrismicNextLinkProps
42
- >(function PrismicNextLink(props, ref) {
43
- const { field, document, linkResolver, children, ...restProps } = props;
44
- const {
45
- href: computedHref,
46
- rel: computedRel,
47
- ...attrs
48
- } = asLinkAttrs(field ?? document, {
49
- linkResolver,
50
- rel: typeof restProps.rel === "function" ? restProps.rel : undefined,
51
- });
52
-
53
- const href = ("href" in restProps ? restProps.href : computedHref) || "";
54
-
55
- let rel = computedRel;
56
- if ("rel" in restProps && typeof restProps.rel !== "function") {
57
- rel = restProps.rel;
58
- }
59
-
60
- const ResolvedLink = resolveDefaultExport(Link);
61
-
62
- return (
63
- <ResolvedLink ref={ref} {...attrs} {...restProps} href={href} rel={rel}>
64
- {"children" in props ? children : field?.text}
65
- </ResolvedLink>
66
- );
67
- });