@prismicio/react 3.4.0-canary.e2a0168 → 3.4.0-pr.257.68f2f80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/PrismicImage.d.ts +20 -28
- package/dist/PrismicImage.d.ts.map +1 -1
- package/dist/PrismicImage.js +6 -8
- package/dist/PrismicImage.js.map +1 -1
- package/dist/PrismicLink.d.ts +18 -21
- package/dist/PrismicLink.d.ts.map +1 -1
- package/dist/PrismicLink.js +6 -9
- package/dist/PrismicLink.js.map +1 -1
- package/dist/PrismicRichText.d.ts +31 -37
- package/dist/PrismicRichText.d.ts.map +1 -1
- package/dist/PrismicRichText.js +5 -7
- package/dist/PrismicRichText.js.map +1 -1
- package/dist/PrismicTable.d.ts +15 -16
- package/dist/PrismicTable.d.ts.map +1 -1
- package/dist/PrismicTable.js +4 -6
- package/dist/PrismicTable.js.map +1 -1
- package/dist/PrismicText.d.ts +8 -11
- package/dist/PrismicText.d.ts.map +1 -1
- package/dist/PrismicText.js +4 -6
- package/dist/PrismicText.js.map +1 -1
- package/dist/PrismicToolbar.d.ts +11 -14
- package/dist/PrismicToolbar.d.ts.map +1 -1
- package/dist/PrismicToolbar.js +5 -8
- package/dist/PrismicToolbar.js.map +1 -1
- package/dist/SliceZone.d.ts +31 -51
- package/dist/SliceZone.d.ts.map +1 -1
- package/dist/SliceZone.js +7 -10
- package/dist/SliceZone.js.map +1 -1
- package/dist/index.js +1 -2
- package/dist/lib/devMsg.js +7 -10
- package/dist/lib/devMsg.js.map +1 -1
- package/dist/package.js +2 -2
- package/package.json +32 -34
- package/src/PrismicImage.tsx +95 -122
- package/src/PrismicLink.tsx +28 -38
- package/src/PrismicRichText.tsx +41 -49
- package/src/PrismicTable.tsx +15 -19
- package/src/PrismicText.tsx +6 -7
- package/src/PrismicToolbar.tsx +12 -16
- package/src/SliceZone.tsx +36 -76
- package/src/lib/devMsg.ts +6 -8
package/dist/PrismicImage.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { ComponentProps, FC, ReactNode } from "react";
|
|
2
1
|
import { ImageFieldImage, asImagePixelDensitySrcSet, asImageWidthSrcSet } from "@prismicio/client";
|
|
2
|
+
import { ComponentProps, FC, ReactNode } from "react";
|
|
3
3
|
|
|
4
4
|
//#region src/PrismicImage.d.ts
|
|
5
5
|
type ImgixURLParams = Omit<NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>, "widths"> & Omit<NonNullable<Parameters<typeof asImagePixelDensitySrcSet>[1]>, "pixelDensities">;
|
|
6
6
|
/** Props for `<PrismicImage>`. */
|
|
7
7
|
type PrismicImageProps = Omit<ComponentProps<"img">, "src" | "srcset" | "alt"> & {
|
|
8
|
-
/** The Prismic image field or thumbnail to render. */
|
|
9
|
-
field: ImageFieldImage | null | undefined;
|
|
8
|
+
/** The Prismic image field or thumbnail to render. */field: ImageFieldImage | null | undefined;
|
|
10
9
|
/**
|
|
11
10
|
* An object of Imgix URL API parameters to transform the image.
|
|
12
11
|
*
|
|
@@ -16,46 +15,40 @@ type PrismicImageProps = Omit<ComponentProps<"img">, "src" | "srcset" | "alt"> &
|
|
|
16
15
|
/**
|
|
17
16
|
* Declare an image as decorative by providing `alt=""`.
|
|
18
17
|
*
|
|
19
|
-
* See:
|
|
20
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
18
|
+
* See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
21
19
|
*/
|
|
22
20
|
alt?: "";
|
|
23
21
|
/**
|
|
24
|
-
* Declare an image as decorative only if the image field does not have
|
|
25
|
-
*
|
|
22
|
+
* Declare an image as decorative only if the image field does not have alternative text by
|
|
23
|
+
* providing `fallbackAlt=""`.
|
|
26
24
|
*
|
|
27
|
-
* See:
|
|
28
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
25
|
+
* See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
29
26
|
*/
|
|
30
27
|
fallbackAlt?: "";
|
|
31
28
|
/**
|
|
32
|
-
* The value to be rendered when the field is empty. If a fallback is not
|
|
33
|
-
*
|
|
29
|
+
* The value to be rendered when the field is empty. If a fallback is not given, `null` will be
|
|
30
|
+
* rendered.
|
|
34
31
|
*/
|
|
35
32
|
fallback?: ReactNode;
|
|
36
33
|
} & ({
|
|
37
34
|
/**
|
|
38
|
-
* Widths (in pixels) used to build a `srcset` value for the image
|
|
39
|
-
* field.
|
|
35
|
+
* Widths (in pixels) used to build a `srcset` value for the image field.
|
|
40
36
|
*
|
|
41
|
-
* If omitted or set to `"defaults"`, the following widths will be used:
|
|
42
|
-
*
|
|
37
|
+
* If omitted or set to `"defaults"`, the following widths will be used: 640, 750, 828,
|
|
38
|
+
* 1080, 1200, 1920, 2048, 3840.
|
|
43
39
|
*
|
|
44
|
-
* If the image field contains responsive views, each responsive view
|
|
45
|
-
*
|
|
46
|
-
* `"thumbnails"` as the `widths` prop.
|
|
40
|
+
* If the image field contains responsive views, each responsive view can be used as a width
|
|
41
|
+
* in the resulting `srcset` by passing `"thumbnails"` as the `widths` prop.
|
|
47
42
|
*/
|
|
48
|
-
widths?: NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>["widths"] | "defaults";
|
|
49
|
-
/** Not used when the `widths` prop is used. */
|
|
43
|
+
widths?: NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>["widths"] | "defaults"; /** Not used when the `widths` prop is used. */
|
|
50
44
|
pixelDensities?: never;
|
|
51
45
|
} | {
|
|
52
|
-
/** Not used when the `widths` prop is used. */
|
|
53
|
-
widths?: never;
|
|
46
|
+
/** Not used when the `widths` prop is used. */widths?: never;
|
|
54
47
|
/**
|
|
55
48
|
* Pixel densities used to build a `srcset` value for the image field.
|
|
56
49
|
*
|
|
57
|
-
* If a `pixelDensities` prop is passed `"defaults"`, the following
|
|
58
|
-
*
|
|
50
|
+
* If a `pixelDensities` prop is passed `"defaults"`, the following pixel densities will be
|
|
51
|
+
* used: 1, 2, 3.
|
|
59
52
|
*/
|
|
60
53
|
pixelDensities: NonNullable<Parameters<typeof asImagePixelDensitySrcSet>[1]>["pixelDensities"] | "defaults";
|
|
61
54
|
});
|
|
@@ -63,10 +56,9 @@ type PrismicImageProps = Omit<ComponentProps<"img">, "src" | "srcset" | "alt"> &
|
|
|
63
56
|
* Renders an optimized image from a Prismic image field.
|
|
64
57
|
*
|
|
65
58
|
* @example
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
* ```
|
|
59
|
+
* ```tsx
|
|
60
|
+
* <PrismicImage field={slice.primary.photo} />;
|
|
61
|
+
* ```
|
|
70
62
|
*
|
|
71
63
|
* @see Learn how to optimize images with imgix, use responsive images, and use framework-specific image components: {@link https://prismic.io/docs/fields/image}
|
|
72
64
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicImage.d.ts","names":[],"sources":["../src/PrismicImage.tsx"],"
|
|
1
|
+
{"version":3,"file":"PrismicImage.d.ts","names":[],"sources":["../src/PrismicImage.tsx"],"mappings":";;;;KAWK,cAAA,GAAiB,IAAA,CAAK,WAAA,CAAY,UAAA,QAAkB,kBAAA,mBACxD,IAAA,CAAK,WAAA,CAAY,UAAA,QAAkB,yBAAA;;KAGxB,iBAAA,GAAoB,IAAA,CAAK,cAAA;EAJlB,sDAMlB,KAAA,EAAO,eAAA;EANiD;;;;;EAaxD,WAAA,iBAA4B,cAAA,GAAiB,cAAA,CAAe,CAAA;EAZxD;;;;;EAmBJ,GAAA;EAnBA;;;;;;EA2BA,WAAA;EAxB4B;;;;EA8B5B,QAAA,GAAW,SAAA;AAAA;EArBkC;;;;;;;;;EAiC1C,MAAA,GAAS,WAAA,CAAY,UAAA,QAAkB,kBAAA,8BAczB;EAZd,cAAA;AAAA;EA1CH,+CA8CG,MAAA;EAvCH;;;;;;EA8CG,cAAA,EACG,WAAA,CAAY,UAAA,QAAkB,yBAAA;AAAA;;;;;;;;;;;cAexB,YAAA,EAAc,EAAA,CAAG,iBAAA"}
|
package/dist/PrismicImage.js
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import { devMsg } from "./lib/devMsg.js";
|
|
2
|
-
import { forwardRef } from "react";
|
|
3
2
|
import { asImagePixelDensitySrcSet, asImageWidthSrcSet, isFilled } from "@prismicio/client";
|
|
4
3
|
import { DEV } from "esm-env";
|
|
4
|
+
import { forwardRef } from "react";
|
|
5
5
|
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
6
|
-
|
|
7
6
|
//#region src/PrismicImage.tsx
|
|
8
7
|
/**
|
|
9
8
|
* Renders an optimized image from a Prismic image field.
|
|
10
9
|
*
|
|
11
10
|
* @example
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* ```
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <PrismicImage field={slice.primary.photo} />;
|
|
13
|
+
* ```
|
|
16
14
|
*
|
|
17
15
|
* @see Learn how to optimize images with imgix, use responsive images, and use framework-specific image components: {@link https://prismic.io/docs/fields/image}
|
|
18
16
|
*/
|
|
19
|
-
const PrismicImage = forwardRef(function PrismicImage
|
|
17
|
+
const PrismicImage = forwardRef(function PrismicImage(props, ref) {
|
|
20
18
|
const { field, alt, fallbackAlt, imgixParams = {}, widths, pixelDensities, fallback, ...restProps } = props;
|
|
21
19
|
if (DEV) {
|
|
22
20
|
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 ${devMsg("alt-must-be-an-empty-string")}`);
|
|
@@ -51,7 +49,7 @@ const PrismicImage = forwardRef(function PrismicImage$1(props, ref) {
|
|
|
51
49
|
...restProps
|
|
52
50
|
});
|
|
53
51
|
});
|
|
54
|
-
|
|
55
52
|
//#endregion
|
|
56
53
|
export { PrismicImage };
|
|
54
|
+
|
|
57
55
|
//# sourceMappingURL=PrismicImage.js.map
|
package/dist/PrismicImage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicImage.js","names":[
|
|
1
|
+
{"version":3,"file":"PrismicImage.js","names":[],"sources":["../src/PrismicImage.tsx"],"sourcesContent":["import {\n\ttype ImageFieldImage,\n\tasImagePixelDensitySrcSet,\n\tasImageWidthSrcSet,\n\tisFilled,\n} from \"@prismicio/client\";\nimport { DEV } from \"esm-env\";\nimport { type ForwardedRef, forwardRef, type ComponentProps, type FC, type ReactNode } from \"react\";\n\nimport { devMsg } from \"./lib/devMsg.js\";\n\ntype ImgixURLParams = Omit<NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>, \"widths\"> &\n\tOmit<NonNullable<Parameters<typeof asImagePixelDensitySrcSet>[1]>, \"pixelDensities\">;\n\n/** Props for `<PrismicImage>`. */\nexport type PrismicImageProps = Omit<ComponentProps<\"img\">, \"src\" | \"srcset\" | \"alt\"> & {\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: 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 alternative text by\n\t * providing `fallbackAlt=\"\"`.\n\t *\n\t * See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\tfallbackAlt?: \"\";\n\n\t/**\n\t * The value to be rendered when the field is empty. If a fallback is not given, `null` will be\n\t * rendered.\n\t */\n\tfallback?: ReactNode;\n} & (\n\t\t| {\n\t\t\t\t/**\n\t\t\t\t * Widths (in pixels) used to build a `srcset` value for the image field.\n\t\t\t\t *\n\t\t\t\t * If omitted or set to `\"defaults\"`, the following widths will be used: 640, 750, 828,\n\t\t\t\t * 1080, 1200, 1920, 2048, 3840.\n\t\t\t\t *\n\t\t\t\t * If the image field contains responsive views, each responsive view can be used as a width\n\t\t\t\t * in the resulting `srcset` by passing `\"thumbnails\"` as the `widths` prop.\n\t\t\t\t */\n\t\t\t\twidths?: NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>[\"widths\"] | \"defaults\";\n\t\t\t\t/** Not used when the `widths` prop is used. */\n\t\t\t\tpixelDensities?: never;\n\t\t }\n\t\t| {\n\t\t\t\t/** Not used when the `widths` prop is used. */\n\t\t\t\twidths?: never;\n\t\t\t\t/**\n\t\t\t\t * Pixel densities used to build a `srcset` value for the image field.\n\t\t\t\t *\n\t\t\t\t * If a `pixelDensities` prop is passed `\"defaults\"`, the following pixel densities will be\n\t\t\t\t * used: 1, 2, 3.\n\t\t\t\t */\n\t\t\t\tpixelDensities:\n\t\t\t\t\t| NonNullable<Parameters<typeof asImagePixelDensitySrcSet>[1]>[\"pixelDensities\"]\n\t\t\t\t\t| \"defaults\";\n\t\t }\n\t);\n\n/**\n * Renders an optimized image from a Prismic image field.\n *\n * @example\n * \t```tsx\n * \t<PrismicImage field={slice.primary.photo} />;\n * \t```\n *\n * @see Learn how to optimize images with imgix, use responsive images, and use framework-specific image components: {@link https://prismic.io/docs/fields/image}\n */\nexport const PrismicImage: FC<PrismicImageProps> = forwardRef(function PrismicImage(\n\tprops: PrismicImageProps,\n\tref: ForwardedRef<HTMLImageElement>,\n) {\n\tconst {\n\t\tfield,\n\t\talt,\n\t\tfallbackAlt,\n\t\timgixParams = {},\n\t\twidths,\n\t\tpixelDensities,\n\t\tfallback,\n\t\t...restProps\n\t} = props;\n\n\tif (DEV) {\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\n\t\tif (widths && pixelDensities) {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicImage] Only one of \"widths\" or \"pixelDensities\" props can be provided. You can resolve this warning by removing either the \"widths\" or \"pixelDensities\" prop. \"widths\" will be used in this case.`,\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\tlet src: string | undefined;\n\tlet srcSet: string | undefined;\n\n\tif (widths || !pixelDensities) {\n\t\tconst res = asImageWidthSrcSet(field, {\n\t\t\t...resolvedImgixParams,\n\t\t\twidths: widths === \"defaults\" ? undefined : widths,\n\t\t} as ImgixURLParams);\n\n\t\tsrc = res.src;\n\t\tsrcSet = res.srcset;\n\t} else if (pixelDensities) {\n\t\tconst res = asImagePixelDensitySrcSet(field, {\n\t\t\t...resolvedImgixParams,\n\t\t\tpixelDensities: pixelDensities === \"defaults\" ? undefined : pixelDensities,\n\t\t} as ImgixURLParams);\n\n\t\tsrc = res.src;\n\t\tsrcSet = res.srcset;\n\t}\n\n\treturn (\n\t\t<img\n\t\t\tref={ref}\n\t\t\tsrc={src}\n\t\t\tsrcSet={srcSet}\n\t\t\talt={alt ?? (field.alt || fallbackAlt)}\n\t\t\t{...restProps}\n\t\t/>\n\t);\n});\n"],"mappings":";;;;;;;;;;;;;;;;AAsFA,MAAa,eAAsC,WAAW,SAAS,aACtE,OACA,KACC;CACD,MAAM,EACL,OACA,KACA,aACA,cAAc,EAAE,EAChB,QACA,gBACA,UACA,GAAG,cACA;AAEJ,KAAI,KAAK;AACR,MAAI,OAAO,QAAQ,YAAY,QAAQ,GACtC,SAAQ,KACP,qQAAqQ,OACpQ,8BACA,GACD;AAGF,MAAI,OAAO,gBAAgB,YAAY,gBAAgB,GACtD,SAAQ,KACP,qSAAqS,OACpS,8BACA,GACD;AAGF,MAAI,UAAU,eACb,SAAQ,KACP,4MACA;;AAIH,KAAI,CAAC,SAAS,eAAe,MAAM,CAClC,QAAO,oBAAA,YAAA,EAAA,UAAG,UAAY,CAAA;CAGvB,MAAM,sBAAsB;AAC5B,MAAK,MAAM,KAAK,YACf,KAAI,oBAAoB,OAA2C,KAClE,qBAAoB,KAAyC,KAAA;CAI/D,IAAI;CACJ,IAAI;AAEJ,KAAI,UAAU,CAAC,gBAAgB;EAC9B,MAAM,MAAM,mBAAmB,OAAO;GACrC,GAAG;GACH,QAAQ,WAAW,aAAa,KAAA,IAAY;GAC5C,CAAmB;AAEpB,QAAM,IAAI;AACV,WAAS,IAAI;YACH,gBAAgB;EAC1B,MAAM,MAAM,0BAA0B,OAAO;GAC5C,GAAG;GACH,gBAAgB,mBAAmB,aAAa,KAAA,IAAY;GAC5D,CAAmB;AAEpB,QAAM,IAAI;AACV,WAAS,IAAI;;AAGd,QACC,oBAAC,OAAD;EACM;EACA;EACG;EACR,KAAK,QAAQ,MAAM,OAAO;EAC1B,GAAI;EACH,CAAA;EAEF"}
|
package/dist/PrismicLink.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ComponentProps, ComponentType, ForwardedRef, HTMLAttributeAnchorTarget, ReactNode } from "react";
|
|
2
1
|
import { AsLinkAttrsConfig, LinkField, LinkResolverFunction, PrismicDocument } from "@prismicio/client";
|
|
2
|
+
import { ComponentProps, ComponentType, ForwardedRef, HTMLAttributeAnchorTarget, ReactNode } from "react";
|
|
3
3
|
|
|
4
4
|
//#region src/PrismicLink.d.ts
|
|
5
5
|
/** The default component rendered for internal and external links. */
|
|
@@ -9,13 +9,13 @@ interface LinkProps {
|
|
|
9
9
|
/** The URL to link. */
|
|
10
10
|
href: string;
|
|
11
11
|
/**
|
|
12
|
-
* The `target` attribute for anchor elements. If the Prismic field is
|
|
13
|
-
*
|
|
12
|
+
* The `target` attribute for anchor elements. If the Prismic field is configured to open in a new
|
|
13
|
+
* window, this prop defaults to `_blank`.
|
|
14
14
|
*/
|
|
15
15
|
target?: HTMLAttributeAnchorTarget;
|
|
16
16
|
/**
|
|
17
|
-
* The `rel` attribute for anchor elements. If the `target` prop is set to
|
|
18
|
-
*
|
|
17
|
+
* The `rel` attribute for anchor elements. If the `target` prop is set to `"_blank"`, this prop
|
|
18
|
+
* defaults to `"noopener noreferrer"`.
|
|
19
19
|
*/
|
|
20
20
|
rel?: string;
|
|
21
21
|
/** Children for the component. */
|
|
@@ -23,33 +23,31 @@ interface LinkProps {
|
|
|
23
23
|
}
|
|
24
24
|
type PrismicLinkProps<InternalComponentProps = ComponentProps<typeof defaultComponent>, ExternalComponentProps = ComponentProps<typeof defaultComponent>> = Omit<InternalComponentProps & ExternalComponentProps, "rel" | "href" | "children"> & {
|
|
25
25
|
/**
|
|
26
|
-
* The `rel` attribute for the link. By default, `"noreferrer"` is provided if
|
|
27
|
-
*
|
|
28
|
-
*
|
|
26
|
+
* The `rel` attribute for the link. By default, `"noreferrer"` is provided if the link's URL is
|
|
27
|
+
* external. This prop can be provided a function to use the link's metadata to determine the
|
|
28
|
+
* `rel` value.
|
|
29
29
|
*/
|
|
30
30
|
rel?: string | AsLinkAttrsConfig["rel"];
|
|
31
31
|
/**
|
|
32
32
|
* The link resolver used to resolve links.
|
|
33
33
|
*
|
|
34
34
|
* @remarks
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
35
|
+
* If your app uses route resolvers when querying for your Prismic repository's content, a link
|
|
36
|
+
* resolver does not need to be provided.
|
|
38
37
|
* @see Learn about link resolvers and route resolvers {@link https://prismic.io/docs/routes}
|
|
39
38
|
*/
|
|
40
39
|
linkResolver?: LinkResolverFunction;
|
|
41
40
|
/**
|
|
42
41
|
* The component rendered for internal URLs. Defaults to `<a>`.
|
|
43
42
|
*
|
|
44
|
-
* If your app uses a client-side router that requires a special Link
|
|
45
|
-
* component
|
|
43
|
+
* If your app uses a client-side router that requires a special Link component, provide the Link
|
|
44
|
+
* component to this prop.
|
|
46
45
|
*/
|
|
47
|
-
internalComponent?: ComponentType<InternalComponentProps>;
|
|
48
|
-
/** The component rendered for external URLs. Defaults to `<a>`. */
|
|
46
|
+
internalComponent?: ComponentType<InternalComponentProps>; /** The component rendered for external URLs. Defaults to `<a>`. */
|
|
49
47
|
externalComponent?: ComponentType<ExternalComponentProps>;
|
|
50
48
|
/**
|
|
51
|
-
* The children to render for the link. If no children are provided, the
|
|
52
|
-
*
|
|
49
|
+
* The children to render for the link. If no children are provided, the link's `text` property
|
|
50
|
+
* will be used.
|
|
53
51
|
*/
|
|
54
52
|
children?: ReactNode;
|
|
55
53
|
} & ({
|
|
@@ -69,10 +67,9 @@ type PrismicLinkProps<InternalComponentProps = ComponentProps<typeof defaultComp
|
|
|
69
67
|
* Renders a link from a Prismic link field or page.
|
|
70
68
|
*
|
|
71
69
|
* @example
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* ```
|
|
70
|
+
* ```tsx
|
|
71
|
+
* <PrismicLink field={slice.primary.link}>Click here</PrismicLink>;
|
|
72
|
+
* ```
|
|
76
73
|
*
|
|
77
74
|
* @see Learn how to display links and use variants for styling: {@link https://prismic.io/docs/fields/link}
|
|
78
75
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicLink.d.ts","names":[],"sources":["../src/PrismicLink.tsx"],"
|
|
1
|
+
{"version":3,"file":"PrismicLink.d.ts","names":[],"sources":["../src/PrismicLink.tsx"],"mappings":";;;;;cAoBM,gBAAA;AALS;AAAA,UAQE,SAAA;;EAEhB,IAAA;EALqB;AAGtB;;;EAQC,MAAA,GAAS,yBAAA;EANT;;;;EAYA,GAAA;EAGW;EAAX,QAAA,GAAW,SAAA;AAAA;AAAA,KAGA,gBAAA,0BACc,cAAA,QAAsB,gBAAA,4BACtB,cAAA,QAAsB,gBAAA,KAC5C,IAAA,CAAK,sBAAA,GAAyB,sBAAA;EAHN;;;;;EAS3B,GAAA,YAAe,iBAAA;EANP;;;;;;;;EAgBR,YAAA,GAAe,oBAAA;EAiBJ;;;;;;EATX,iBAAA,GAAoB,aAAA,CAAc,sBAAA,GA1BlC;EA6BA,iBAAA,GAAoB,aAAA,CAAc,sBAAA;EA7Ba;;;;EAmC/C,QAAA,GAAW,SAAA;AAAA;EAGR,QAAA,EAAU,eAAA;EACV,IAAA;EACA,KAAA;AAAA;EAGA,KAAA,EAAO,SAAA;EACP,IAAA;EACA,QAAA;AAAA;EAGA,IAAA,EAAM,SAAA;EACN,KAAA,GAAQ,SAAA;EACR,QAAA;AAAA;;;;;;;;;;;cAcS,WAAA,4BAkFa,cAAA,QAAsB,gBAAA,4BACtB,cAAA,QAAsB,gBAAA,GAE/C,KAAA,EAAO,gBAAA,CAAiB,sBAAA,EAAwB,sBAAA;EAC/C,GAAA,GAAM,YAAA,CAAa,OAAA;AAAA,MAEhB,SAAA"}
|
package/dist/PrismicLink.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { devMsg } from "./lib/devMsg.js";
|
|
2
|
-
import { forwardRef } from "react";
|
|
3
2
|
import { asLinkAttrs } from "@prismicio/client";
|
|
4
3
|
import { DEV } from "esm-env";
|
|
4
|
+
import { forwardRef } from "react";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
|
-
|
|
7
6
|
//#region src/PrismicLink.tsx
|
|
8
7
|
/** The default component rendered for internal and external links. */
|
|
9
8
|
const defaultComponent = "a";
|
|
@@ -11,14 +10,13 @@ const defaultComponent = "a";
|
|
|
11
10
|
* Renders a link from a Prismic link field or page.
|
|
12
11
|
*
|
|
13
12
|
* @example
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* ```
|
|
13
|
+
* ```tsx
|
|
14
|
+
* <PrismicLink field={slice.primary.link}>Click here</PrismicLink>;
|
|
15
|
+
* ```
|
|
18
16
|
*
|
|
19
17
|
* @see Learn how to display links and use variants for styling: {@link https://prismic.io/docs/fields/link}
|
|
20
18
|
*/
|
|
21
|
-
const PrismicLink = forwardRef(function PrismicLink
|
|
19
|
+
const PrismicLink = forwardRef(function PrismicLink(props, ref) {
|
|
22
20
|
const { field, document: doc, linkResolver, internalComponent, externalComponent, children, ...restProps } = props;
|
|
23
21
|
if (DEV) {
|
|
24
22
|
if (field) {
|
|
@@ -52,7 +50,6 @@ const PrismicLink = forwardRef(function PrismicLink$1(props, ref) {
|
|
|
52
50
|
* Determines if a URL is internal or external.
|
|
53
51
|
*
|
|
54
52
|
* @param url - The URL to check if internal or external.
|
|
55
|
-
*
|
|
56
53
|
* @returns `true` if `url` is internal, `false` otherwise.
|
|
57
54
|
*/
|
|
58
55
|
function isInternalURL(url) {
|
|
@@ -60,7 +57,7 @@ function isInternalURL(url) {
|
|
|
60
57
|
const isSpecialLink = !isInternal && !/^https?:\/\//.test(url);
|
|
61
58
|
return isInternal && !isSpecialLink;
|
|
62
59
|
}
|
|
63
|
-
|
|
64
60
|
//#endregion
|
|
65
61
|
export { PrismicLink };
|
|
62
|
+
|
|
66
63
|
//# sourceMappingURL=PrismicLink.js.map
|
package/dist/PrismicLink.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicLink.js","names":[
|
|
1
|
+
{"version":3,"file":"PrismicLink.js","names":[],"sources":["../src/PrismicLink.tsx"],"sourcesContent":["import {\n\ttype LinkField,\n\ttype LinkResolverFunction,\n\ttype PrismicDocument,\n\tasLinkAttrs,\n\ttype AsLinkAttrsConfig,\n} from \"@prismicio/client\";\nimport { DEV } from \"esm-env\";\nimport {\n\ttype ComponentProps,\n\ttype ComponentType,\n\ttype ForwardedRef,\n\ttype HTMLAttributeAnchorTarget,\n\ttype ReactNode,\n\tforwardRef,\n} from \"react\";\n\nimport { devMsg } from \"./lib/devMsg.js\";\n\n/** The default component rendered for internal and external links. */\nconst defaultComponent = \"a\";\n\n/** Props provided to a component when rendered with `<PrismicLink>`. */\nexport interface LinkProps {\n\t/** The URL to link. */\n\thref: string;\n\n\t/**\n\t * The `target` attribute for anchor elements. If the Prismic field is configured to open in a new\n\t * window, this prop defaults to `_blank`.\n\t */\n\ttarget?: HTMLAttributeAnchorTarget;\n\n\t/**\n\t * The `rel` attribute for anchor elements. If the `target` prop is set to `\"_blank\"`, this prop\n\t * defaults to `\"noopener noreferrer\"`.\n\t */\n\trel?: string;\n\n\t/** Children for the component. */\n\tchildren?: ReactNode;\n}\n\nexport type PrismicLinkProps<\n\tInternalComponentProps = ComponentProps<typeof defaultComponent>,\n\tExternalComponentProps = ComponentProps<typeof defaultComponent>,\n> = Omit<InternalComponentProps & ExternalComponentProps, \"rel\" | \"href\" | \"children\"> & {\n\t/**\n\t * The `rel` attribute for the link. By default, `\"noreferrer\"` is provided if the link's URL is\n\t * external. This prop can be provided a function to use the link's metadata to determine the\n\t * `rel` value.\n\t */\n\trel?: string | AsLinkAttrsConfig[\"rel\"];\n\n\t/**\n\t * The link resolver used to resolve links.\n\t *\n\t * @remarks\n\t * If your app uses route resolvers when querying for your Prismic repository's content, a link\n\t * resolver does not need to be provided.\n\t * @see Learn about link resolvers and route resolvers {@link https://prismic.io/docs/routes}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * The component rendered for internal URLs. Defaults to `<a>`.\n\t *\n\t * If your app uses a client-side router that requires a special Link component, provide the Link\n\t * component to this prop.\n\t */\n\tinternalComponent?: ComponentType<InternalComponentProps>;\n\n\t/** The component rendered for external URLs. Defaults to `<a>`. */\n\texternalComponent?: ComponentType<ExternalComponentProps>;\n\n\t/**\n\t * The children to render for the link. If no children are provided, the link's `text` property\n\t * will be used.\n\t */\n\tchildren?: ReactNode;\n} & (\n\t\t| {\n\t\t\t\tdocument: PrismicDocument | null | undefined;\n\t\t\t\thref?: never;\n\t\t\t\tfield?: never;\n\t\t }\n\t\t| {\n\t\t\t\tfield: LinkField | null | undefined;\n\t\t\t\thref?: never;\n\t\t\t\tdocument?: never;\n\t\t }\n\t\t| {\n\t\t\t\thref: LinkProps[\"href\"];\n\t\t\t\tfield?: LinkField | null | undefined;\n\t\t\t\tdocument?: never;\n\t\t }\n\t);\n\n/**\n * Renders a link from a Prismic link field or page.\n *\n * @example\n * \t```tsx\n * \t<PrismicLink field={slice.primary.link}>Click here</PrismicLink>;\n * \t```\n *\n * @see Learn how to display links and use variants for styling: {@link https://prismic.io/docs/fields/link}\n */\nexport const PrismicLink = forwardRef(function PrismicLink<\n\tInternalComponentProps = ComponentProps<typeof defaultComponent>,\n\tExternalComponentProps = ComponentProps<typeof defaultComponent>,\n>(\n\tprops: PrismicLinkProps<InternalComponentProps, ExternalComponentProps>,\n\tref: ForwardedRef<Element>,\n) {\n\tconst {\n\t\tfield,\n\t\tdocument: doc,\n\t\tlinkResolver,\n\t\tinternalComponent,\n\t\texternalComponent,\n\t\tchildren,\n\t\t...restProps\n\t} = props;\n\n\tif (DEV) {\n\t\tif (field) {\n\t\t\tif (!field.link_type) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`[PrismicLink] This \"field\" prop value caused an error to be thrown.\\n`,\n\t\t\t\t\tfield,\n\t\t\t\t);\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`[PrismicLink] The provided field is missing required properties to properly render a link. The link will not render. For more details, see ${devMsg(\n\t\t\t\t\t\t\"missing-link-properties\",\n\t\t\t\t\t)}`,\n\t\t\t\t);\n\t\t\t} else if (\n\t\t\t\t(\"text\" in field ? Object.keys(field).length > 2 : Object.keys(field).length > 1) &&\n\t\t\t\t!(\"url\" in field || \"uid\" in field || \"id\" in field)\n\t\t\t) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[PrismicLink] The provided field is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg(\n\t\t\t\t\t\t\"missing-link-properties\",\n\t\t\t\t\t)}`,\n\t\t\t\t\tfield,\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (doc) {\n\t\t\tif (!(\"url\" in doc || \"id\" in doc)) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[PrismicLink] The provided document is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg(\n\t\t\t\t\t\t\"missing-link-properties\",\n\t\t\t\t\t)}`,\n\t\t\t\t\tdoc,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst {\n\t\thref: computedHref,\n\t\trel: computedRel,\n\t\t...attrs\n\t} = asLinkAttrs(field ?? doc, {\n\t\tlinkResolver,\n\t\trel: typeof restProps.rel === \"function\" ? restProps.rel : undefined,\n\t});\n\n\tlet rel: string | undefined = computedRel;\n\tif (\"rel\" in restProps && typeof restProps.rel !== \"function\") {\n\t\trel = restProps.rel;\n\t}\n\n\tconst href = (\"href\" in restProps ? restProps.href : computedHref) || \"\";\n\n\tconst InternalComponent = (internalComponent || defaultComponent) as ComponentType<LinkProps>;\n\tconst ExternalComponent = (externalComponent || defaultComponent) as ComponentType<LinkProps>;\n\tconst Component = href\n\t\t? isInternalURL(href)\n\t\t\t? InternalComponent\n\t\t\t: ExternalComponent\n\t\t: InternalComponent;\n\n\treturn (\n\t\t<Component ref={ref} {...attrs} {...restProps} href={href} rel={rel}>\n\t\t\t{\"children\" in props ? children : field?.text}\n\t\t</Component>\n\t);\n}) as <\n\tInternalComponentProps = ComponentProps<typeof defaultComponent>,\n\tExternalComponentProps = ComponentProps<typeof defaultComponent>,\n>(\n\tprops: PrismicLinkProps<InternalComponentProps, ExternalComponentProps> & {\n\t\tref?: ForwardedRef<Element>;\n\t},\n) => ReactNode;\n\n/**\n * Determines if a URL is internal or external.\n *\n * @param url - The URL to check if internal or external.\n * @returns `true` if `url` is internal, `false` otherwise.\n */\n// TODO: This does not detect all relative URLs as internal such as `about` or `./about`. This function assumes relative URLs start with a \"/\" or \"#\"`.\nexport function isInternalURL(url: string): boolean {\n\tconst isInternal = /^(\\/(?!\\/)|#)/.test(url);\n\tconst isSpecialLink = !isInternal && !/^https?:\\/\\//.test(url);\n\n\treturn isInternal && !isSpecialLink;\n}\n"],"mappings":";;;;;;;AAoBA,MAAM,mBAAmB;;;;;;;;;;;AAwFzB,MAAa,cAAc,WAAW,SAAS,YAI9C,OACA,KACC;CACD,MAAM,EACL,OACA,UAAU,KACV,cACA,mBACA,mBACA,UACA,GAAG,cACA;AAEJ,KAAI;MACC;OACC,CAAC,MAAM,WAAW;AACrB,YAAQ,MACP,yEACA,MACA;AACD,UAAM,IAAI,MACT,8IAA8I,OAC7I,0BACA,GACD;eAEA,UAAU,QAAQ,OAAO,KAAK,MAAM,CAAC,SAAS,IAAI,OAAO,KAAK,MAAM,CAAC,SAAS,MAC/E,EAAE,SAAS,SAAS,SAAS,SAAS,QAAQ,OAE9C,SAAQ,KACP,uJAAuJ,OACtJ,0BACA,IACD,MACA;aAEQ;OACN,EAAE,SAAS,OAAO,QAAQ,KAC7B,SAAQ,KACP,0JAA0J,OACzJ,0BACA,IACD,IACA;;;CAKJ,MAAM,EACL,MAAM,cACN,KAAK,aACL,GAAG,UACA,YAAY,SAAS,KAAK;EAC7B;EACA,KAAK,OAAO,UAAU,QAAQ,aAAa,UAAU,MAAM,KAAA;EAC3D,CAAC;CAEF,IAAI,MAA0B;AAC9B,KAAI,SAAS,aAAa,OAAO,UAAU,QAAQ,WAClD,OAAM,UAAU;CAGjB,MAAM,QAAQ,UAAU,YAAY,UAAU,OAAO,iBAAiB;CAEtE,MAAM,oBAAqB,qBAAqB;CAChD,MAAM,oBAAqB,qBAAqB;AAOhD,QACC,oBAPiB,OACf,cAAc,KAAK,GAClB,oBACA,oBACD,mBAGF;EAAgB;EAAK,GAAI;EAAO,GAAI;EAAiB;EAAW;YAC9D,cAAc,QAAQ,WAAW,OAAO;EAC9B,CAAA;EAEZ;;;;;;;AAgBF,SAAgB,cAAc,KAAsB;CACnD,MAAM,aAAa,gBAAgB,KAAK,IAAI;CAC5C,MAAM,gBAAgB,CAAC,cAAc,CAAC,eAAe,KAAK,IAAI;AAE9D,QAAO,cAAc,CAAC"}
|
|
@@ -1,39 +1,33 @@
|
|
|
1
1
|
import { LinkProps } from "./PrismicLink.js";
|
|
2
|
-
import { ComponentType, FC, ReactNode } from "react";
|
|
3
2
|
import { LinkResolverFunction, RichTextField } from "@prismicio/client";
|
|
3
|
+
import { ComponentType, FC, ReactNode } from "react";
|
|
4
4
|
import { RichTextFunctionSerializer, RichTextMapSerializer } from "@prismicio/client/richtext";
|
|
5
5
|
|
|
6
6
|
//#region src/PrismicRichText.d.ts
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
|
-
* A function mapping rich text block types to React Components. It is used to
|
|
10
|
-
*
|
|
8
|
+
* A function mapping rich text block types to React Components. It is used to render rich text
|
|
9
|
+
* fields.
|
|
11
10
|
*
|
|
12
11
|
* @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text}
|
|
13
12
|
*/
|
|
14
13
|
type JSXFunctionSerializer = RichTextFunctionSerializer<ReactNode>;
|
|
15
14
|
/**
|
|
16
|
-
* A map of rich text block types to React Components. It is used to render rich
|
|
17
|
-
* text fields.
|
|
15
|
+
* A map of rich text block types to React Components. It is used to render rich text fields.
|
|
18
16
|
*
|
|
19
17
|
* @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text}
|
|
20
18
|
*/
|
|
21
19
|
type RichTextComponents = RichTextMapSerializer<ReactNode>;
|
|
22
|
-
/**
|
|
23
|
-
* @deprecated Use `RichTextComponents` instead.
|
|
24
|
-
*/
|
|
20
|
+
/** @deprecated Use `RichTextComponents` instead. */
|
|
25
21
|
type JSXMapSerializer = RichTextComponents;
|
|
26
22
|
/** Props for `<PrismicRichText>`. */
|
|
27
23
|
type PrismicRichTextProps = {
|
|
28
|
-
/** The Prismic rich text field to render. */
|
|
29
|
-
field: RichTextField | null | undefined;
|
|
24
|
+
/** The Prismic rich text field to render. */field: RichTextField | null | undefined;
|
|
30
25
|
/**
|
|
31
26
|
* The link resolver used to resolve links.
|
|
32
27
|
*
|
|
33
28
|
* @remarks
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
29
|
+
* If your app uses route resolvers when querying for your Prismic repository's content, a link
|
|
30
|
+
* resolver does not need to be provided.
|
|
37
31
|
* @see Learn about link resolvers and route resolvers {@link https://prismic.io/docs/routes}
|
|
38
32
|
*/
|
|
39
33
|
linkResolver?: LinkResolverFunction;
|
|
@@ -41,28 +35,29 @@ type PrismicRichTextProps = {
|
|
|
41
35
|
* A map or function that maps a rich text block to a React component.
|
|
42
36
|
*
|
|
43
37
|
* @remarks
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
38
|
+
* Prefer using a map serializer over the function serializer when possible. The map serializer
|
|
39
|
+
* is simpler to maintain.
|
|
40
|
+
* @example
|
|
41
|
+
* A map serializer.
|
|
48
42
|
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
43
|
+
* ```jsx
|
|
44
|
+
* {
|
|
45
|
+
* heading1: ({children}) => <Heading>{children}</Heading>
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
54
48
|
*
|
|
55
|
-
* @example
|
|
49
|
+
* @example
|
|
50
|
+
* A function serializer.
|
|
56
51
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
52
|
+
* ```jsx
|
|
53
|
+
* (type, node, content, children) => {
|
|
59
54
|
* switch (type) {
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* }
|
|
55
|
+
* case "heading1": {
|
|
56
|
+
* return <Heading>{children}</Heading>;
|
|
63
57
|
* }
|
|
64
|
-
*
|
|
65
|
-
*
|
|
58
|
+
* }
|
|
59
|
+
* };
|
|
60
|
+
* ```
|
|
66
61
|
*/
|
|
67
62
|
components?: RichTextComponents | JSXFunctionSerializer;
|
|
68
63
|
/**
|
|
@@ -78,8 +73,8 @@ type PrismicRichTextProps = {
|
|
|
78
73
|
*/
|
|
79
74
|
externalLinkComponent?: ComponentType<LinkProps>;
|
|
80
75
|
/**
|
|
81
|
-
* The value to be rendered when the field is empty. If a fallback is not
|
|
82
|
-
*
|
|
76
|
+
* The value to be rendered when the field is empty. If a fallback is not given, `null` will be
|
|
77
|
+
* rendered.
|
|
83
78
|
*/
|
|
84
79
|
fallback?: ReactNode;
|
|
85
80
|
};
|
|
@@ -87,10 +82,9 @@ type PrismicRichTextProps = {
|
|
|
87
82
|
* Renders content from a Prismic rich text field as React components.
|
|
88
83
|
*
|
|
89
84
|
* @example
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* ```
|
|
85
|
+
* ```tsx
|
|
86
|
+
* <PrismicRichText field={slice.primary.text} />;
|
|
87
|
+
* ```
|
|
94
88
|
*
|
|
95
89
|
* @see Learn how to style rich text, use custom components, and use labels for custom formatting: {@link https://prismic.io/docs/fields/rich-text}
|
|
96
90
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicRichText.d.ts","names":[],"sources":["../src/PrismicRichText.tsx"],"
|
|
1
|
+
{"version":3,"file":"PrismicRichText.d.ts","names":[],"sources":["../src/PrismicRichText.tsx"],"mappings":";;;;;;;;AAgCA;;;;KAAY,qBAAA,GAAwB,0BAAA,CAA2B,SAAA;AAO/D;;;;;AAAA,KAAY,kBAAA,GAAqB,qBAAA,CAAsB,SAAA;;KAG3C,gBAAA,GAAmB,kBAAA;;KAGnB,oBAAA;EAAA,6CAEX,KAAA,EAAO,aAAA;;;;;;;;;EAUP,YAAA,GAAe,oBAAA;EAkDJ;;;;;;;;;;;;;;;;;;;;AAkJZ;;;;;;;;EAtKC,UAAA,GAAa,kBAAA,GAAqB,qBAAA;;;;;;EAOlC,qBAAA,GAAwB,aAAA,CAAc,SAAA;;;;;;EAOtC,qBAAA,GAAwB,aAAA,CAAc,SAAA;;;;;EAMtC,QAAA,GAAW,SAAA;AAAA;;;;;;;;;;;cAkJC,eAAA,EAAiB,EAAA,CAAG,oBAAA"}
|
package/dist/PrismicRichText.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { devMsg } from "./lib/devMsg.js";
|
|
2
2
|
import { PrismicLink } from "./PrismicLink.js";
|
|
3
|
-
import { Fragment, cloneElement, isValidElement } from "react";
|
|
4
3
|
import { isFilled } from "@prismicio/client";
|
|
5
4
|
import { DEV } from "esm-env";
|
|
5
|
+
import { Fragment, cloneElement, isValidElement } from "react";
|
|
6
6
|
import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
|
|
7
7
|
import { composeSerializers, serialize, wrapMapSerializer } from "@prismicio/client/richtext";
|
|
8
|
-
|
|
9
8
|
//#region src/PrismicRichText.tsx
|
|
10
9
|
const getDir = (node) => {
|
|
11
10
|
if ("direction" in node && node.direction === "rtl") return "rtl";
|
|
@@ -101,10 +100,9 @@ const createDefaultSerializer = (args) => wrapMapSerializer({
|
|
|
101
100
|
* Renders content from a Prismic rich text field as React components.
|
|
102
101
|
*
|
|
103
102
|
* @example
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* ```
|
|
103
|
+
* ```tsx
|
|
104
|
+
* <PrismicRichText field={slice.primary.text} />;
|
|
105
|
+
* ```
|
|
108
106
|
*
|
|
109
107
|
* @see Learn how to style rich text, use custom components, and use labels for custom formatting: {@link https://prismic.io/docs/fields/rich-text}
|
|
110
108
|
*/
|
|
@@ -127,7 +125,7 @@ const PrismicRichText = (props) => {
|
|
|
127
125
|
if (!serialized) return fallback != null ? /* @__PURE__ */ jsx(Fragment$1, { children: fallback }) : null;
|
|
128
126
|
return /* @__PURE__ */ jsx(Fragment$1, { children: serialized });
|
|
129
127
|
};
|
|
130
|
-
|
|
131
128
|
//#endregion
|
|
132
129
|
export { PrismicRichText };
|
|
130
|
+
|
|
133
131
|
//# sourceMappingURL=PrismicRichText.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicRichText.js","names":[],"sources":["../src/PrismicRichText.tsx"],"sourcesContent":["import { type LinkProps, PrismicLink } from \"./PrismicLink.js\";\nimport { devMsg } from \"./lib/devMsg.js\";\nimport {\n\tisFilled,\n\ttype LinkResolverFunction,\n\ttype RichTextField,\n\ttype RTAnyNode,\n} from \"@prismicio/client\";\nimport {\n\tcomposeSerializers,\n\tserialize,\n\twrapMapSerializer,\n\ttype RichTextFunctionSerializer,\n\ttype RichTextMapSerializer,\n} from \"@prismicio/client/richtext\";\nimport { DEV } from \"esm-env\";\nimport {\n\tcloneElement,\n\ttype ComponentType,\n\ttype FC,\n\tFragment,\n\tisValidElement,\n\ttype ReactNode,\n} from \"react\";\n\n/**\n * A function mapping rich text block types to React Components. It is used to\n * render rich text fields.\n *\n * @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text}\n */\nexport type JSXFunctionSerializer = RichTextFunctionSerializer<ReactNode>;\n\n/**\n * A map of rich text block types to React Components. It is used to render rich\n * text fields.\n *\n * @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text}\n */\nexport type RichTextComponents = RichTextMapSerializer<ReactNode>;\n\n/**\n * @deprecated Use `RichTextComponents` instead.\n */\nexport type JSXMapSerializer = RichTextComponents;\n\n/** Props for `<PrismicRichText>`. */\nexport type PrismicRichTextProps = {\n\t/** The Prismic rich text field to render. */\n\tfield: RichTextField | null | undefined;\n\n\t/**\n\t * The link resolver used to resolve links.\n\t *\n\t * @remarks\n\t * If your app uses route resolvers when querying for your Prismic\n\t * repository's content, a link resolver does not need to be provided.\n\t *\n\t * @see Learn about link resolvers and route resolvers {@link https://prismic.io/docs/routes}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * A map or function that maps a rich text block to a React component.\n\t *\n\t * @remarks\n\t * Prefer using a map serializer over the function serializer when possible.\n\t * The map serializer is simpler to maintain.\n\t *\n\t * @example A map serializer.\n\t *\n\t * ```jsx\n\t * {\n\t * heading1: ({children}) => <Heading>{children}</Heading>\n\t * }\n\t * ```\n\t *\n\t * @example A function serializer.\n\t *\n\t * ```jsx\n\t * (type, node, content, children) => {\n\t * \tswitch (type) {\n\t * \t\tcase \"heading1\": {\n\t * \t\t\treturn <Heading>{children}</Heading>;\n\t * \t\t}\n\t * \t}\n\t * };\n\t * ```\n\t */\n\tcomponents?: RichTextComponents | JSXFunctionSerializer;\n\n\t/**\n\t * The React component rendered for links when the URL is internal.\n\t *\n\t * @defaultValue `<a>`\n\t */\n\tinternalLinkComponent?: ComponentType<LinkProps>;\n\n\t/**\n\t * The React component rendered for links when the URL is external.\n\t *\n\t * @defaultValue `<a>`\n\t */\n\texternalLinkComponent?: ComponentType<LinkProps>;\n\n\t/**\n\t * The value to be rendered when the field is empty. If a fallback is not\n\t * given, `null` will be rendered.\n\t */\n\tfallback?: ReactNode;\n};\n\ntype CreateDefaultSerializerArgs = {\n\tlinkResolver: LinkResolverFunction | undefined;\n\tinternalLinkComponent?: ComponentType<LinkProps>;\n\texternalLinkComponent?: ComponentType<LinkProps>;\n};\n\nconst getDir = (node: RTAnyNode): \"rtl\" | undefined => {\n\tif (\"direction\" in node && node.direction === \"rtl\") {\n\t\treturn \"rtl\";\n\t}\n};\n\nconst createDefaultSerializer = (\n\targs: CreateDefaultSerializerArgs,\n): JSXFunctionSerializer =>\n\twrapMapSerializer<ReactNode>({\n\t\theading1: ({ node, children, key }) => (\n\t\t\t<h1 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h1>\n\t\t),\n\t\theading2: ({ node, children, key }) => (\n\t\t\t<h2 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h2>\n\t\t),\n\t\theading3: ({ node, children, key }) => (\n\t\t\t<h3 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h3>\n\t\t),\n\t\theading4: ({ node, children, key }) => (\n\t\t\t<h4 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h4>\n\t\t),\n\t\theading5: ({ node, children, key }) => (\n\t\t\t<h5 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h5>\n\t\t),\n\t\theading6: ({ node, children, key }) => (\n\t\t\t<h6 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h6>\n\t\t),\n\t\tparagraph: ({ node, children, key }) => (\n\t\t\t<p key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</p>\n\t\t),\n\t\tpreformatted: ({ node, key }) => <pre key={key}>{node.text}</pre>,\n\t\tstrong: ({ children, key }) => <strong key={key}>{children}</strong>,\n\t\tem: ({ children, key }) => <em key={key}>{children}</em>,\n\t\tlistItem: ({ node, children, key }) => (\n\t\t\t<li key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</li>\n\t\t),\n\t\toListItem: ({ node, children, key }) => (\n\t\t\t<li key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</li>\n\t\t),\n\t\tlist: ({ children, key }) => <ul key={key}>{children}</ul>,\n\t\toList: ({ children, key }) => <ol key={key}>{children}</ol>,\n\t\timage: ({ node, key }) => {\n\t\t\tconst img = (\n\t\t\t\t<img\n\t\t\t\t\tsrc={node.url}\n\t\t\t\t\talt={node.alt ?? undefined}\n\t\t\t\t\tdata-copyright={node.copyright ? node.copyright : undefined}\n\t\t\t\t/>\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\t<p key={key} className=\"block-img\">\n\t\t\t\t\t{node.linkTo ? (\n\t\t\t\t\t\t<PrismicLink\n\t\t\t\t\t\t\tlinkResolver={args.linkResolver}\n\t\t\t\t\t\t\tinternalComponent={args.internalLinkComponent}\n\t\t\t\t\t\t\texternalComponent={args.externalLinkComponent}\n\t\t\t\t\t\t\tfield={node.linkTo}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{img}\n\t\t\t\t\t\t</PrismicLink>\n\t\t\t\t\t) : (\n\t\t\t\t\t\timg\n\t\t\t\t\t)}\n\t\t\t\t</p>\n\t\t\t);\n\t\t},\n\t\tembed: ({ node, key }) => (\n\t\t\t<div\n\t\t\t\tkey={key}\n\t\t\t\tdata-oembed={node.oembed.embed_url}\n\t\t\t\tdata-oembed-type={node.oembed.type}\n\t\t\t\tdata-oembed-provider={node.oembed.provider_name}\n\t\t\t\tdangerouslySetInnerHTML={{ __html: node.oembed.html ?? \"\" }}\n\t\t\t/>\n\t\t),\n\t\thyperlink: ({ node, children, key }) => (\n\t\t\t<PrismicLink\n\t\t\t\tkey={key}\n\t\t\t\tfield={node.data}\n\t\t\t\tlinkResolver={args.linkResolver}\n\t\t\t\tinternalComponent={args.internalLinkComponent}\n\t\t\t\texternalComponent={args.externalLinkComponent}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</PrismicLink>\n\t\t),\n\t\tlabel: ({ node, children, key }) => (\n\t\t\t<span key={key} className={node.data.label}>\n\t\t\t\t{children}\n\t\t\t</span>\n\t\t),\n\t\tspan: ({ text, key }) => {\n\t\t\tconst result: ReactNode[] = [];\n\n\t\t\tlet i = 0;\n\t\t\tfor (const line of text.split(\"\\n\")) {\n\t\t\t\tif (i > 0) {\n\t\t\t\t\tresult.push(<br key={`${i}__break`} />);\n\t\t\t\t}\n\n\t\t\t\tresult.push(<Fragment key={`${i}__line`}>{line}</Fragment>);\n\n\t\t\t\ti++;\n\t\t\t}\n\n\t\t\treturn <Fragment key={key}>{result}</Fragment>;\n\t\t},\n\t});\n\n/**\n * Renders content from a Prismic rich text field as React components.\n *\n * @example\n *\n * ```tsx\n * <PrismicRichText field={slice.primary.text} />;\n * ```\n *\n * @see Learn how to style rich text, use custom components, and use labels for custom formatting: {@link https://prismic.io/docs/fields/rich-text}\n */\nexport const PrismicRichText: FC<PrismicRichTextProps> = (props) => {\n\tconst {\n\t\tlinkResolver,\n\t\tfield,\n\t\tfallback,\n\t\tcomponents,\n\t\texternalLinkComponent,\n\t\tinternalLinkComponent,\n\t\t...restProps\n\t} = props;\n\n\tif (DEV) {\n\t\tif (\"className\" in restProps) {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicRichText] className cannot be passed to <PrismicRichText> since it renders an array without a wrapping component. For more details, see ${devMsg(\n\t\t\t\t\t\"classname-is-not-a-valid-prop\",\n\t\t\t\t)}.`,\n\t\t\t\tfield,\n\t\t\t);\n\t\t}\n\t}\n\n\tif (!isFilled.richText(field)) {\n\t\treturn fallback != null ? <>{fallback}</> : null;\n\t}\n\n\tconst serializer = composeSerializers<ReactNode>(\n\t\ttypeof components === \"object\" ? wrapMapSerializer(components) : components,\n\t\tcreateDefaultSerializer({\n\t\t\tlinkResolver,\n\t\t\tinternalLinkComponent,\n\t\t\texternalLinkComponent,\n\t\t}),\n\t);\n\n\t// The serializer is wrapped in a higher-order function that\n\t// automatically applies a key to React Elements if one is not already\n\t// given.\n\tconst serialized = serialize<ReactNode>(\n\t\tfield,\n\t\t(type, node, text, children, key) => {\n\t\t\tconst result = serializer(type, node, text, children, key);\n\n\t\t\tif (isValidElement(result) && result.key == null) {\n\t\t\t\treturn cloneElement(result, { key });\n\t\t\t} else {\n\t\t\t\treturn result;\n\t\t\t}\n\t\t},\n\t);\n\n\tif (!serialized) {\n\t\treturn fallback != null ? <>{fallback}</> : null;\n\t}\n\n\treturn <>{serialized}</>;\n};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,SAAS,MAAM,CAC5B,QAAO,YAAY,OAAO,4CAAG,WAAY,GAAG;CAG7C,MAAM,aAAa,mBAClB,OAAO,eAAe,WAAW,kBAAkB,WAAW,GAAG,YACjE,wBAAwB;EACvB;EACA;EACA;EACA,CAAC,CACF;CAKD,MAAM,aAAa,UAClB,QACC,MAAM,MAAM,MAAM,UAAU,QAAQ;EACpC,MAAM,SAAS,WAAW,MAAM,MAAM,MAAM,UAAU,IAAI;AAE1D,MAAI,eAAe,OAAO,IAAI,OAAO,OAAO,KAC3C,QAAO,aAAa,QAAQ,EAAE,KAAK,CAAC;MAEpC,QAAO;GAGT;AAED,KAAI,CAAC,WACJ,QAAO,YAAY,OAAO,4CAAG,WAAY,GAAG;AAG7C,QAAO,4CAAG,aAAc"}
|
|
1
|
+
{"version":3,"file":"PrismicRichText.js","names":[],"sources":["../src/PrismicRichText.tsx"],"sourcesContent":["import {\n\tisFilled,\n\ttype LinkResolverFunction,\n\ttype RichTextField,\n\ttype RTAnyNode,\n} from \"@prismicio/client\";\nimport {\n\tcomposeSerializers,\n\tserialize,\n\twrapMapSerializer,\n\ttype RichTextFunctionSerializer,\n\ttype RichTextMapSerializer,\n} from \"@prismicio/client/richtext\";\nimport { DEV } from \"esm-env\";\nimport {\n\tcloneElement,\n\ttype ComponentType,\n\ttype FC,\n\tFragment,\n\tisValidElement,\n\ttype ReactNode,\n} from \"react\";\n\nimport { devMsg } from \"./lib/devMsg.js\";\nimport { type LinkProps, PrismicLink } from \"./PrismicLink.js\";\n\n/**\n * A function mapping rich text block types to React Components. It is used to render rich text\n * fields.\n *\n * @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text}\n */\nexport type JSXFunctionSerializer = RichTextFunctionSerializer<ReactNode>;\n\n/**\n * A map of rich text block types to React Components. It is used to render rich text fields.\n *\n * @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text}\n */\nexport type RichTextComponents = RichTextMapSerializer<ReactNode>;\n\n/** @deprecated Use `RichTextComponents` instead. */\nexport type JSXMapSerializer = RichTextComponents;\n\n/** Props for `<PrismicRichText>`. */\nexport type PrismicRichTextProps = {\n\t/** The Prismic rich text field to render. */\n\tfield: RichTextField | null | undefined;\n\n\t/**\n\t * The link resolver used to resolve links.\n\t *\n\t * @remarks\n\t * If your app uses route resolvers when querying for your Prismic repository's content, a link\n\t * resolver does not need to be provided.\n\t * @see Learn about link resolvers and route resolvers {@link https://prismic.io/docs/routes}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * A map or function that maps a rich text block to a React component.\n\t *\n\t * @remarks\n\t * Prefer using a map serializer over the function serializer when possible. The map serializer\n\t * is simpler to maintain.\n\t * @example\n\t * \tA map serializer.\n\t *\n\t * \t```jsx\n\t * \t{\n\t * \theading1: ({children}) => <Heading>{children}</Heading>\n\t * \t}\n\t * \t```\n\t *\n\t * @example\n\t * \tA function serializer.\n\t *\n\t * \t```jsx\n\t * \t(type, node, content, children) => {\n\t * \tswitch (type) {\n\t * \tcase \"heading1\": {\n\t * \treturn <Heading>{children}</Heading>;\n\t * \t}\n\t * \t}\n\t * \t};\n\t * \t```\n\t */\n\tcomponents?: RichTextComponents | JSXFunctionSerializer;\n\n\t/**\n\t * The React component rendered for links when the URL is internal.\n\t *\n\t * @defaultValue `<a>`\n\t */\n\tinternalLinkComponent?: ComponentType<LinkProps>;\n\n\t/**\n\t * The React component rendered for links when the URL is external.\n\t *\n\t * @defaultValue `<a>`\n\t */\n\texternalLinkComponent?: ComponentType<LinkProps>;\n\n\t/**\n\t * The value to be rendered when the field is empty. If a fallback is not given, `null` will be\n\t * rendered.\n\t */\n\tfallback?: ReactNode;\n};\n\ntype CreateDefaultSerializerArgs = {\n\tlinkResolver: LinkResolverFunction | undefined;\n\tinternalLinkComponent?: ComponentType<LinkProps>;\n\texternalLinkComponent?: ComponentType<LinkProps>;\n};\n\nconst getDir = (node: RTAnyNode): \"rtl\" | undefined => {\n\tif (\"direction\" in node && node.direction === \"rtl\") {\n\t\treturn \"rtl\";\n\t}\n};\n\nconst createDefaultSerializer = (args: CreateDefaultSerializerArgs): JSXFunctionSerializer =>\n\twrapMapSerializer<ReactNode>({\n\t\theading1: ({ node, children, key }) => (\n\t\t\t<h1 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h1>\n\t\t),\n\t\theading2: ({ node, children, key }) => (\n\t\t\t<h2 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h2>\n\t\t),\n\t\theading3: ({ node, children, key }) => (\n\t\t\t<h3 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h3>\n\t\t),\n\t\theading4: ({ node, children, key }) => (\n\t\t\t<h4 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h4>\n\t\t),\n\t\theading5: ({ node, children, key }) => (\n\t\t\t<h5 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h5>\n\t\t),\n\t\theading6: ({ node, children, key }) => (\n\t\t\t<h6 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h6>\n\t\t),\n\t\tparagraph: ({ node, children, key }) => (\n\t\t\t<p key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</p>\n\t\t),\n\t\tpreformatted: ({ node, key }) => <pre key={key}>{node.text}</pre>,\n\t\tstrong: ({ children, key }) => <strong key={key}>{children}</strong>,\n\t\tem: ({ children, key }) => <em key={key}>{children}</em>,\n\t\tlistItem: ({ node, children, key }) => (\n\t\t\t<li key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</li>\n\t\t),\n\t\toListItem: ({ node, children, key }) => (\n\t\t\t<li key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</li>\n\t\t),\n\t\tlist: ({ children, key }) => <ul key={key}>{children}</ul>,\n\t\toList: ({ children, key }) => <ol key={key}>{children}</ol>,\n\t\timage: ({ node, key }) => {\n\t\t\tconst img = (\n\t\t\t\t<img\n\t\t\t\t\tsrc={node.url}\n\t\t\t\t\talt={node.alt ?? undefined}\n\t\t\t\t\tdata-copyright={node.copyright ? node.copyright : undefined}\n\t\t\t\t/>\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\t<p key={key} className=\"block-img\">\n\t\t\t\t\t{node.linkTo ? (\n\t\t\t\t\t\t<PrismicLink\n\t\t\t\t\t\t\tlinkResolver={args.linkResolver}\n\t\t\t\t\t\t\tinternalComponent={args.internalLinkComponent}\n\t\t\t\t\t\t\texternalComponent={args.externalLinkComponent}\n\t\t\t\t\t\t\tfield={node.linkTo}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{img}\n\t\t\t\t\t\t</PrismicLink>\n\t\t\t\t\t) : (\n\t\t\t\t\t\timg\n\t\t\t\t\t)}\n\t\t\t\t</p>\n\t\t\t);\n\t\t},\n\t\tembed: ({ node, key }) => (\n\t\t\t<div\n\t\t\t\tkey={key}\n\t\t\t\tdata-oembed={node.oembed.embed_url}\n\t\t\t\tdata-oembed-type={node.oembed.type}\n\t\t\t\tdata-oembed-provider={node.oembed.provider_name}\n\t\t\t\tdangerouslySetInnerHTML={{ __html: node.oembed.html ?? \"\" }}\n\t\t\t/>\n\t\t),\n\t\thyperlink: ({ node, children, key }) => (\n\t\t\t<PrismicLink\n\t\t\t\tkey={key}\n\t\t\t\tfield={node.data}\n\t\t\t\tlinkResolver={args.linkResolver}\n\t\t\t\tinternalComponent={args.internalLinkComponent}\n\t\t\t\texternalComponent={args.externalLinkComponent}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</PrismicLink>\n\t\t),\n\t\tlabel: ({ node, children, key }) => (\n\t\t\t<span key={key} className={node.data.label}>\n\t\t\t\t{children}\n\t\t\t</span>\n\t\t),\n\t\tspan: ({ text, key }) => {\n\t\t\tconst result: ReactNode[] = [];\n\n\t\t\tlet i = 0;\n\t\t\tfor (const line of text.split(\"\\n\")) {\n\t\t\t\tif (i > 0) {\n\t\t\t\t\tresult.push(<br key={`${i}__break`} />);\n\t\t\t\t}\n\n\t\t\t\tresult.push(<Fragment key={`${i}__line`}>{line}</Fragment>);\n\n\t\t\t\ti++;\n\t\t\t}\n\n\t\t\treturn <Fragment key={key}>{result}</Fragment>;\n\t\t},\n\t});\n\n/**\n * Renders content from a Prismic rich text field as React components.\n *\n * @example\n * \t```tsx\n * \t<PrismicRichText field={slice.primary.text} />;\n * \t```\n *\n * @see Learn how to style rich text, use custom components, and use labels for custom formatting: {@link https://prismic.io/docs/fields/rich-text}\n */\nexport const PrismicRichText: FC<PrismicRichTextProps> = (props) => {\n\tconst {\n\t\tlinkResolver,\n\t\tfield,\n\t\tfallback,\n\t\tcomponents,\n\t\texternalLinkComponent,\n\t\tinternalLinkComponent,\n\t\t...restProps\n\t} = props;\n\n\tif (DEV) {\n\t\tif (\"className\" in restProps) {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicRichText] className cannot be passed to <PrismicRichText> since it renders an array without a wrapping component. For more details, see ${devMsg(\n\t\t\t\t\t\"classname-is-not-a-valid-prop\",\n\t\t\t\t)}.`,\n\t\t\t\tfield,\n\t\t\t);\n\t\t}\n\t}\n\n\tif (!isFilled.richText(field)) {\n\t\treturn fallback != null ? <>{fallback}</> : null;\n\t}\n\n\tconst serializer = composeSerializers<ReactNode>(\n\t\ttypeof components === \"object\" ? wrapMapSerializer(components) : components,\n\t\tcreateDefaultSerializer({\n\t\t\tlinkResolver,\n\t\t\tinternalLinkComponent,\n\t\t\texternalLinkComponent,\n\t\t}),\n\t);\n\n\t// The serializer is wrapped in a higher-order function that\n\t// automatically applies a key to React Elements if one is not already\n\t// given.\n\tconst serialized = serialize<ReactNode>(field, (type, node, text, children, key) => {\n\t\tconst result = serializer(type, node, text, children, key);\n\n\t\tif (isValidElement(result) && result.key == null) {\n\t\t\treturn cloneElement(result, { key });\n\t\t} else {\n\t\t\treturn result;\n\t\t}\n\t});\n\n\tif (!serialized) {\n\t\treturn fallback != null ? <>{fallback}</> : null;\n\t}\n\n\treturn <>{serialized}</>;\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