@prismicio/react 3.4.2-pr.270.b8e16cb → 3.4.2-pr.271.d473965
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 +9 -8
- package/dist/PrismicImage.d.ts.map +1 -1
- package/dist/PrismicImage.js +2 -2
- package/dist/PrismicImage.js.map +1 -1
- package/dist/PrismicLink.d.ts +5 -6
- package/dist/PrismicLink.d.ts.map +1 -1
- package/dist/PrismicLink.js +3 -2
- package/dist/PrismicLink.js.map +1 -1
- package/dist/PrismicRichText.d.ts +7 -8
- package/dist/PrismicRichText.d.ts.map +1 -1
- package/dist/PrismicRichText.js.map +1 -1
- package/dist/PrismicTable.d.ts +4 -5
- package/dist/PrismicTable.d.ts.map +1 -1
- package/dist/PrismicTable.js.map +1 -1
- package/dist/PrismicText.d.ts +6 -6
- package/dist/PrismicText.d.ts.map +1 -1
- package/dist/PrismicText.js.map +1 -1
- package/dist/PrismicToolbar.d.ts +2 -4
- package/dist/PrismicToolbar.d.ts.map +1 -1
- package/dist/PrismicToolbar.js +4 -2
- package/dist/PrismicToolbar.js.map +1 -1
- package/dist/SliceZone.d.ts +24 -20
- package/dist/SliceZone.d.ts.map +1 -1
- package/dist/SliceZone.js +9 -15
- package/dist/SliceZone.js.map +1 -1
- package/dist/lib/devMsg.js.map +1 -1
- package/dist/package.js +1 -1
- package/package.json +15 -14
- package/src/PrismicImage.tsx +2 -2
- package/src/PrismicToolbar.tsx +5 -3
- package/src/SliceZone.tsx +7 -18
- package/dist/SliceBoundary.js +0 -55
- package/dist/SliceBoundary.js.map +0 -1
- package/src/SliceBoundary.tsx +0 -77
package/dist/PrismicImage.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { ImageFieldImage, asImagePixelDensitySrcSet, asImageWidthSrcSet } from "@prismicio/client";
|
|
2
2
|
import { ComponentProps, FC, ReactNode } from "react";
|
|
3
|
-
|
|
4
3
|
//#region src/PrismicImage.d.ts
|
|
5
4
|
type ImgixURLParams = Omit<NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>, "widths"> & Omit<NonNullable<Parameters<typeof asImagePixelDensitySrcSet>[1]>, "pixelDensities">;
|
|
6
5
|
/** Props for `<PrismicImage>`. */
|
|
7
|
-
type PrismicImageProps = Omit<ComponentProps<"img">, "src" | "srcset" | "alt"> & {
|
|
8
|
-
/** The Prismic image field or thumbnail to render. */
|
|
6
|
+
export type PrismicImageProps = Omit<ComponentProps<"img">, "src" | "srcset" | "alt"> & {
|
|
7
|
+
/** The Prismic image field or thumbnail to render. */
|
|
8
|
+
field: ImageFieldImage | null | undefined;
|
|
9
9
|
/**
|
|
10
10
|
* An object of Imgix URL API parameters to transform the image.
|
|
11
11
|
*
|
|
12
12
|
* See: https://docs.imgix.com/apis/rendering
|
|
13
13
|
*/
|
|
14
|
-
imgixParams?: { [P in keyof ImgixURLParams]: ImgixURLParams[P] | null };
|
|
14
|
+
imgixParams?: { [P in keyof ImgixURLParams]: ImgixURLParams[P] | null; };
|
|
15
15
|
/**
|
|
16
16
|
* Declare an image as decorative by providing `alt=""`.
|
|
17
17
|
*
|
|
@@ -40,10 +40,12 @@ type PrismicImageProps = Omit<ComponentProps<"img">, "src" | "srcset" | "alt"> &
|
|
|
40
40
|
* If the image field contains responsive views, each responsive view can be used as a width
|
|
41
41
|
* in the resulting `srcset` by passing `"thumbnails"` as the `widths` prop.
|
|
42
42
|
*/
|
|
43
|
-
widths?: NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>["widths"] | "defaults";
|
|
43
|
+
widths?: NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>["widths"] | "defaults";
|
|
44
|
+
/** Not used when the `widths` prop is used. */
|
|
44
45
|
pixelDensities?: never;
|
|
45
46
|
} | {
|
|
46
|
-
/** Not used when the `widths` prop is used. */
|
|
47
|
+
/** Not used when the `widths` prop is used. */
|
|
48
|
+
widths?: never;
|
|
47
49
|
/**
|
|
48
50
|
* Pixel densities used to build a `srcset` value for the image field.
|
|
49
51
|
*
|
|
@@ -62,7 +64,6 @@ type PrismicImageProps = Omit<ComponentProps<"img">, "src" | "srcset" | "alt"> &
|
|
|
62
64
|
*
|
|
63
65
|
* @see Learn how to optimize images with imgix, use responsive images, and use framework-specific image components: {@link https://prismic.io/docs/fields/image}
|
|
64
66
|
*/
|
|
65
|
-
declare const PrismicImage: FC<PrismicImageProps>;
|
|
67
|
+
export declare const PrismicImage: FC<PrismicImageProps>;
|
|
66
68
|
//#endregion
|
|
67
|
-
export { PrismicImage, PrismicImageProps };
|
|
68
69
|
//# sourceMappingURL=PrismicImage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicImage.d.ts","names":[],"sources":["../src/PrismicImage.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"PrismicImage.d.ts","names":[],"sources":["../src/PrismicImage.tsx"],"mappings":";;;KAWK,iBAAiB,KAAK,YAAY,kBAAkB,qCACxD,KAAK,YAAY,kBAAkB;;YAGxB,oBAAoB,KAAK;;EAEpC,OAAO;;;;;;EAOP,iBAAiB,WAAW,iBAAiB,eAAe;;;;;;EAO5D;;;;;;;EAQA;;;;;EAMA,WAAW;;;;;;;;;;;EAYR,SAAS,YAAY,kBAAkB;;EAEvC;;;EAIA;;;;;;;EAOA,gBACG,YAAY,kBAAkB;;;;;;;;;;;;qBAexB,cAAc,GAAG"}
|
package/dist/PrismicImage.js
CHANGED
|
@@ -22,8 +22,8 @@ const PrismicImage = forwardRef(function PrismicImage(props, ref) {
|
|
|
22
22
|
if (widths && pixelDensities) console.warn(`[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.`);
|
|
23
23
|
}
|
|
24
24
|
if (!isFilled.imageThumbnail(field)) return /* @__PURE__ */ jsx(Fragment$1, { children: fallback });
|
|
25
|
-
const resolvedImgixParams = imgixParams;
|
|
26
|
-
for (const x in
|
|
25
|
+
const resolvedImgixParams = { ...imgixParams };
|
|
26
|
+
for (const x in resolvedImgixParams) if (resolvedImgixParams[x] === null) resolvedImgixParams[x] = void 0;
|
|
27
27
|
let src;
|
|
28
28
|
let srcSet;
|
|
29
29
|
if (widths || !pixelDensities) {
|
package/dist/PrismicImage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
|
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 resolvedImgixParams) {\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,CAAC,GACf,QACA,gBACA,UACA,GAAG,cACA;CAEJ,IAAI,KAAK;EACR,IAAI,OAAO,QAAQ,YAAY,QAAQ,IACtC,QAAQ,KACP,qQAAqQ,OACpQ,6BACD,GACD;EAGD,IAAI,OAAO,gBAAgB,YAAY,gBAAgB,IACtD,QAAQ,KACP,qSAAqS,OACpS,6BACD,GACD;EAGD,IAAI,UAAU,gBACb,QAAQ,KACP,2MACD;CAEF;CAEA,IAAI,CAAC,SAAS,eAAe,KAAK,GACjC,OAAO,oBAAA,YAAA,EAAA,UAAG,SAAW,CAAA;CAGtB,MAAM,sBAAsB,EAAE,GAAG,YAAY;CAC7C,KAAK,MAAM,KAAK,qBACf,IAAI,oBAAoB,OAA2C,MAClE,oBAAoB,KAAyC,KAAA;CAI/D,IAAI;CACJ,IAAI;CAEJ,IAAI,UAAU,CAAC,gBAAgB;EAC9B,MAAM,MAAM,mBAAmB,OAAO;GACrC,GAAG;GACH,QAAQ,WAAW,aAAa,KAAA,IAAY;EAC7C,CAAmB;EAEnB,MAAM,IAAI;EACV,SAAS,IAAI;CACd,OAAO,IAAI,gBAAgB;EAC1B,MAAM,MAAM,0BAA0B,OAAO;GAC5C,GAAG;GACH,gBAAgB,mBAAmB,aAAa,KAAA,IAAY;EAC7D,CAAmB;EAEnB,MAAM,IAAI;EACV,SAAS,IAAI;CACd;CAEA,OACC,oBAAC,OAAD;EACM;EACA;EACG;EACR,KAAK,QAAQ,MAAM,OAAO;EAC1B,GAAI;CACJ,CAAA;AAEH,CAAC"}
|
package/dist/PrismicLink.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { AsLinkAttrsConfig, LinkField, LinkResolverFunction, PrismicDocument } from "@prismicio/client";
|
|
2
2
|
import { ComponentProps, ComponentType, ForwardedRef, HTMLAttributeAnchorTarget, ReactNode } from "react";
|
|
3
|
-
|
|
4
3
|
//#region src/PrismicLink.d.ts
|
|
5
4
|
/** The default component rendered for internal and external links. */
|
|
6
5
|
declare const defaultComponent = "a";
|
|
7
6
|
/** Props provided to a component when rendered with `<PrismicLink>`. */
|
|
8
|
-
interface LinkProps {
|
|
7
|
+
export interface LinkProps {
|
|
9
8
|
/** The URL to link. */
|
|
10
9
|
href: string;
|
|
11
10
|
/**
|
|
@@ -21,7 +20,7 @@ interface LinkProps {
|
|
|
21
20
|
/** Children for the component. */
|
|
22
21
|
children?: ReactNode;
|
|
23
22
|
}
|
|
24
|
-
type PrismicLinkProps<InternalComponentProps = ComponentProps<typeof defaultComponent>, ExternalComponentProps = ComponentProps<typeof defaultComponent>> = Omit<InternalComponentProps & ExternalComponentProps, "rel" | "href" | "children"> & {
|
|
23
|
+
export type PrismicLinkProps<InternalComponentProps = ComponentProps<typeof defaultComponent>, ExternalComponentProps = ComponentProps<typeof defaultComponent>> = Omit<InternalComponentProps & ExternalComponentProps, "rel" | "href" | "children"> & {
|
|
25
24
|
/**
|
|
26
25
|
* The `rel` attribute for the link. By default, `"noreferrer"` is provided if the link's URL is
|
|
27
26
|
* external. This prop can be provided a function to use the link's metadata to determine the
|
|
@@ -43,7 +42,8 @@ type PrismicLinkProps<InternalComponentProps = ComponentProps<typeof defaultComp
|
|
|
43
42
|
* If your app uses a client-side router that requires a special Link component, provide the Link
|
|
44
43
|
* component to this prop.
|
|
45
44
|
*/
|
|
46
|
-
internalComponent?: ComponentType<InternalComponentProps>;
|
|
45
|
+
internalComponent?: ComponentType<InternalComponentProps>;
|
|
46
|
+
/** The component rendered for external URLs. Defaults to `<a>`. */
|
|
47
47
|
externalComponent?: ComponentType<ExternalComponentProps>;
|
|
48
48
|
/**
|
|
49
49
|
* The children to render for the link. If no children are provided, the link's `text` property
|
|
@@ -73,9 +73,8 @@ type PrismicLinkProps<InternalComponentProps = ComponentProps<typeof defaultComp
|
|
|
73
73
|
*
|
|
74
74
|
* @see Learn how to display links and use variants for styling: {@link https://prismic.io/docs/fields/link}
|
|
75
75
|
*/
|
|
76
|
-
declare const PrismicLink: <InternalComponentProps = ComponentProps<typeof defaultComponent>, ExternalComponentProps = ComponentProps<typeof defaultComponent>>(props: PrismicLinkProps<InternalComponentProps, ExternalComponentProps> & {
|
|
76
|
+
export declare const PrismicLink: <InternalComponentProps = ComponentProps<typeof defaultComponent>, ExternalComponentProps = ComponentProps<typeof defaultComponent>>(props: PrismicLinkProps<InternalComponentProps, ExternalComponentProps> & {
|
|
77
77
|
ref?: ForwardedRef<Element>;
|
|
78
78
|
}) => ReactNode;
|
|
79
79
|
//#endregion
|
|
80
|
-
export { LinkProps, PrismicLink, PrismicLinkProps };
|
|
81
80
|
//# sourceMappingURL=PrismicLink.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicLink.d.ts","names":[],"sources":["../src/PrismicLink.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"PrismicLink.d.ts","names":[],"sources":["../src/PrismicLink.tsx"],"mappings":";;;;cAoBM;;iBAGW;;EAEhB;;;;;EAMA,SAAS;;;;;EAMT;;EAGA,WAAW;;YAGA,iBACX,yBAAyB,sBAAsB,mBAC/C,yBAAyB,sBAAsB,qBAC5C,KAAK,yBAAyB;;;;;;EAMjC,eAAe;;;;;;;;;EAUf,eAAe;;;;;;;EAQf,oBAAoB,cAAc;;EAGlC,oBAAoB,cAAc;;;;;EAMlC,WAAW;;EAGR,UAAU;EACV;EACA;;EAGA,OAAO;EACP;EACA;;EAGA,MAAM;EACN,QAAQ;EACR;;;;;;;;;;;;qBAcS,cAkFZ,yBAAyB,sBAAsB,mBAC/C,yBAAyB,sBAAsB,mBAE/C,OAAO,iBAAiB,wBAAwB;EAC/C,MAAM,aAAa;MAEhB"}
|
package/dist/PrismicLink.js
CHANGED
|
@@ -37,7 +37,8 @@ const PrismicLink = forwardRef(function PrismicLink(props, ref) {
|
|
|
37
37
|
const href = ("href" in restProps ? restProps.href : computedHref) || "";
|
|
38
38
|
const InternalComponent = internalComponent || defaultComponent;
|
|
39
39
|
const ExternalComponent = externalComponent || defaultComponent;
|
|
40
|
-
|
|
40
|
+
const Component = href ? isInternalURL(href) ? InternalComponent : ExternalComponent : InternalComponent;
|
|
41
|
+
return /* @__PURE__ */ jsx(Component, {
|
|
41
42
|
ref,
|
|
42
43
|
...attrs,
|
|
43
44
|
...restProps,
|
|
@@ -58,6 +59,6 @@ function isInternalURL(url) {
|
|
|
58
59
|
return isInternal && !isSpecialLink;
|
|
59
60
|
}
|
|
60
61
|
//#endregion
|
|
61
|
-
export { PrismicLink };
|
|
62
|
+
export { PrismicLink, isInternalURL };
|
|
62
63
|
|
|
63
64
|
//# sourceMappingURL=PrismicLink.js.map
|
package/dist/PrismicLink.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;CAEJ,IAAI,KAAK;EACR,IAAI,OAAO;GACV,IAAI,CAAC,MAAM,WAAW;IACrB,QAAQ,MACP,yEACA,KACD;IACA,MAAM,IAAI,MACT,8IAA8I,OAC7I,yBACD,GACD;GACD,OAAO,KACL,UAAU,QAAQ,OAAO,KAAK,KAAK,CAAC,CAAC,SAAS,IAAI,OAAO,KAAK,KAAK,CAAC,CAAC,SAAS,MAC/E,EAAE,SAAS,SAAS,SAAS,SAAS,QAAQ,QAE9C,QAAQ,KACP,uJAAuJ,OACtJ,yBACD,KACA,KACD;EAEF,OAAO,IAAI,KACN;OAAA,EAAE,SAAS,OAAO,QAAQ,MAC7B,QAAQ,KACP,0JAA0J,OACzJ,yBACD,KACA,GACD;EAAA;CAGH;CAEA,MAAM,EACL,MAAM,cACN,KAAK,aACL,GAAG,UACA,YAAY,SAAS,KAAK;EAC7B;EACA,KAAK,OAAO,UAAU,QAAQ,aAAa,UAAU,MAAM,KAAA;CAC5D,CAAC;CAED,IAAI,MAA0B;CAC9B,IAAI,SAAS,aAAa,OAAO,UAAU,QAAQ,YAClD,MAAM,UAAU;CAGjB,MAAM,QAAQ,UAAU,YAAY,UAAU,OAAO,iBAAiB;CAEtE,MAAM,oBAAqB,qBAAqB;CAChD,MAAM,oBAAqB,qBAAqB;CAChD,MAAM,YAAY,OACf,cAAc,IAAI,IACjB,oBACA,oBACD;CAEH,OACC,oBAAC,WAAD;EAAgB;EAAK,GAAI;EAAO,GAAI;EAAiB;EAAW;EAC9D,UAAA,cAAc,QAAQ,WAAW,OAAO;CAC/B,CAAA;AAEb,CAAC;;;;;;;AAgBD,SAAgB,cAAc,KAAsB;CACnD,MAAM,aAAa,gBAAgB,KAAK,GAAG;CAC3C,MAAM,gBAAgB,CAAC,cAAc,CAAC,eAAe,KAAK,GAAG;CAE7D,OAAO,cAAc,CAAC;AACvB"}
|
|
@@ -2,7 +2,6 @@ import { LinkProps } from "./PrismicLink.js";
|
|
|
2
2
|
import { LinkResolverFunction, RichTextField } from "@prismicio/client";
|
|
3
3
|
import { ComponentType, FC, ReactNode } from "react";
|
|
4
4
|
import { RichTextFunctionSerializer, RichTextMapSerializer } from "@prismicio/client/richtext";
|
|
5
|
-
|
|
6
5
|
//#region src/PrismicRichText.d.ts
|
|
7
6
|
/**
|
|
8
7
|
* A function mapping rich text block types to React Components. It is used to render rich text
|
|
@@ -10,18 +9,19 @@ import { RichTextFunctionSerializer, RichTextMapSerializer } from "@prismicio/cl
|
|
|
10
9
|
*
|
|
11
10
|
* @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text}
|
|
12
11
|
*/
|
|
13
|
-
type JSXFunctionSerializer = RichTextFunctionSerializer<ReactNode>;
|
|
12
|
+
export type JSXFunctionSerializer = RichTextFunctionSerializer<ReactNode>;
|
|
14
13
|
/**
|
|
15
14
|
* A map of rich text block types to React Components. It is used to render rich text fields.
|
|
16
15
|
*
|
|
17
16
|
* @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text}
|
|
18
17
|
*/
|
|
19
|
-
type RichTextComponents = RichTextMapSerializer<ReactNode>;
|
|
18
|
+
export type RichTextComponents = RichTextMapSerializer<ReactNode>;
|
|
20
19
|
/** @deprecated Use `RichTextComponents` instead. */
|
|
21
|
-
type JSXMapSerializer = RichTextComponents;
|
|
20
|
+
export type JSXMapSerializer = RichTextComponents;
|
|
22
21
|
/** Props for `<PrismicRichText>`. */
|
|
23
|
-
type PrismicRichTextProps = {
|
|
24
|
-
/** The Prismic rich text field to render. */
|
|
22
|
+
export type PrismicRichTextProps = {
|
|
23
|
+
/** The Prismic rich text field to render. */
|
|
24
|
+
field: RichTextField | null | undefined;
|
|
25
25
|
/**
|
|
26
26
|
* The link resolver used to resolve links.
|
|
27
27
|
*
|
|
@@ -88,7 +88,6 @@ type PrismicRichTextProps = {
|
|
|
88
88
|
*
|
|
89
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}
|
|
90
90
|
*/
|
|
91
|
-
declare const PrismicRichText: FC<PrismicRichTextProps>;
|
|
91
|
+
export declare const PrismicRichText: FC<PrismicRichTextProps>;
|
|
92
92
|
//#endregion
|
|
93
|
-
export { JSXFunctionSerializer, JSXMapSerializer, PrismicRichText, PrismicRichTextProps, RichTextComponents };
|
|
94
93
|
//# sourceMappingURL=PrismicRichText.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicRichText.d.ts","names":[],"sources":["../src/PrismicRichText.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"PrismicRichText.d.ts","names":[],"sources":["../src/PrismicRichText.tsx"],"mappings":";;;;;;;;;;;YAgCY,wBAAwB,2BAA2B;;;;;;YAOnD,qBAAqB,sBAAsB;;YAG3C,mBAAmB;;YAGnB;;EAEX,OAAO;;;;;;;;;EAUP,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8Bf,aAAa,qBAAqB;;;;;;EAOlC,wBAAwB,cAAc;;;;;;EAOtC,wBAAwB,cAAc;;;;;EAMtC,WAAW;;;;;;;;;;;;qBAkJC,iBAAiB,GAAG"}
|
|
@@ -1 +1 @@
|
|
|
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}</>\n}\n"],"mappings":"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"}
|
|
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}</>\n}\n"],"mappings":"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"}
|
package/dist/PrismicTable.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { JSXMapSerializer } from "./PrismicRichText.js";
|
|
2
2
|
import { TableField, TableFieldBody, TableFieldBodyRow, TableFieldDataCell, TableFieldHead, TableFieldHeadRow, TableFieldHeaderCell } from "@prismicio/client";
|
|
3
3
|
import { ComponentType, FC, ReactNode } from "react";
|
|
4
|
-
|
|
5
4
|
//#region src/PrismicTable.d.ts
|
|
6
5
|
type TableComponents = {
|
|
7
6
|
table?: ComponentType<{
|
|
@@ -30,8 +29,9 @@ type TableComponents = {
|
|
|
30
29
|
}>;
|
|
31
30
|
};
|
|
32
31
|
/** Props for `<PrismicTable>`. */
|
|
33
|
-
type PrismicTableProps = {
|
|
34
|
-
/** The Prismic table field to render. */
|
|
32
|
+
export type PrismicTableProps = {
|
|
33
|
+
/** The Prismic table field to render. */
|
|
34
|
+
field: TableField;
|
|
35
35
|
/**
|
|
36
36
|
* An object that maps a table block to a React component.
|
|
37
37
|
*
|
|
@@ -62,7 +62,6 @@ type PrismicTableProps = {
|
|
|
62
62
|
*
|
|
63
63
|
* @see Learn how to style tables and customize table element components: {@link https://prismic.io/docs/fields/table}
|
|
64
64
|
*/
|
|
65
|
-
declare const PrismicTable: FC<PrismicTableProps>;
|
|
65
|
+
export declare const PrismicTable: FC<PrismicTableProps>;
|
|
66
66
|
//#endregion
|
|
67
|
-
export { PrismicTable, PrismicTableProps };
|
|
68
67
|
//# sourceMappingURL=PrismicTable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicTable.d.ts","names":[],"sources":["../src/PrismicTable.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"PrismicTable.d.ts","names":[],"sources":["../src/PrismicTable.tsx"],"mappings":";;;;KAcK;EACJ,QAAQ;IAAgB,OAAO;IAAsB,UAAU;;EAC/D,QAAQ;IAAgB,MAAM;IAAgB,UAAU;;EACxD,QAAQ;IAAgB,MAAM;IAAgB,UAAU;;EACxD,KAAK;IACJ,KAAK,oBAAoB;IACzB,UAAU;;EAEX,KAAK;IAAgB,MAAM;IAAsB,UAAU;;EAC3D,KAAK;IAAgB,MAAM;IAAoB,UAAU;;;;YAa9C;;EAEX,OAAO;;;;;;;;;;;;;;EAeP,aAAa,mBAAmB;;;;;EAMhC,WAAW;;;;;;;;;;;;qBAaC,cAAc,GAAG"}
|
package/dist/PrismicTable.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicTable.js","names":[],"sources":["../src/PrismicTable.tsx"],"sourcesContent":["import {\n\tisFilled,\n\ttype TableField,\n\ttype TableFieldHead,\n\ttype TableFieldHeadRow,\n\ttype TableFieldBody,\n\ttype TableFieldBodyRow,\n\ttype TableFieldHeaderCell,\n\ttype TableFieldDataCell,\n} from \"@prismicio/client\"\nimport type { ComponentType, FC, ReactNode } from \"react\"\n\nimport { type JSXMapSerializer, PrismicRichText } from \"./PrismicRichText.js\"\n\ntype TableComponents = {\n\ttable?: ComponentType<{ table: TableField<\"filled\">; children: ReactNode }>\n\tthead?: ComponentType<{ head: TableFieldHead; children: ReactNode }>\n\ttbody?: ComponentType<{ body: TableFieldBody; children: ReactNode }>\n\ttr?: ComponentType<{\n\t\trow: TableFieldHeadRow | TableFieldBodyRow\n\t\tchildren: ReactNode\n\t}>\n\tth?: ComponentType<{ cell: TableFieldHeaderCell; children: ReactNode }>\n\ttd?: ComponentType<{ cell: TableFieldDataCell; children: ReactNode }>\n}\n\nconst defaultComponents: Required<TableComponents> = {\n\ttable: ({ children }) => <table>{children}</table>,\n\tthead: ({ children }) => <thead>{children}</thead>,\n\ttbody: ({ children }) => <tbody>{children}</tbody>,\n\ttr: ({ children }) => <tr>{children}</tr>,\n\tth: ({ children }) => <th>{children}</th>,\n\ttd: ({ children }) => <td>{children}</td>,\n}\n\n/** Props for `<PrismicTable>`. */\nexport type PrismicTableProps = {\n\t/** The Prismic table field to render. */\n\tfield: TableField\n\n\t/**\n\t * An object that maps a table block to a React component.\n\t *\n\t * @example\n\t * \tA map serializer.\n\t *\n\t * \t```jsx\n\t * \t{\n\t * \ttable: ({children}) => <table>{children}</table>\n\t * \tthead: ({children}) => <thead>{children}</thead>\n\t * \t}\n\t * \t```\n\t */\n\tcomponents?: JSXMapSerializer & TableComponents\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\n/**\n * Renders content from a Prismic table field as React components.\n *\n * @example\n * \t;```tsx\n * \t<PrismicTable field={slice.primary.pricing_table} />;\n * \t```\n *\n * @see Learn how to style tables and customize table element components: {@link https://prismic.io/docs/fields/table}\n */\nexport const PrismicTable: FC<PrismicTableProps> = (props) => {\n\tconst { field, components, fallback = null } = props\n\n\tif (!isFilled.table(field)) {\n\t\treturn fallback\n\t}\n\n\tconst { table: Table, thead: Thead, tbody: Tbody } = { ...defaultComponents, ...components }\n\n\treturn (\n\t\t<Table table={field}>\n\t\t\t{field.head && (\n\t\t\t\t<Thead head={field.head}>\n\t\t\t\t\t{field.head.rows.map((row) => (\n\t\t\t\t\t\t<TableRow key={row.key} row={row} components={components} />\n\t\t\t\t\t))}\n\t\t\t\t</Thead>\n\t\t\t)}\n\t\t\t<Tbody body={field.body}>\n\t\t\t\t{field.body.rows.map((row) => (\n\t\t\t\t\t<TableRow key={row.key} row={row} components={components} />\n\t\t\t\t))}\n\t\t\t</Tbody>\n\t\t</Table>\n\t)\n}\n\ntype TableRowProps = {\n\trow: TableFieldHeadRow | TableFieldBodyRow\n\tcomponents?: JSXMapSerializer & TableComponents\n}\n\nfunction TableRow(props: TableRowProps) {\n\tconst { row, components } = props\n\n\tconst { tr: Tr, th: Th, td: Td } = { ...defaultComponents, ...components }\n\n\treturn (\n\t\t<Tr row={row}>\n\t\t\t{row.cells.map((cell) =>\n\t\t\t\tcell.type === \"header\" ? (\n\t\t\t\t\t<Th key={cell.key} cell={cell}>\n\t\t\t\t\t\t<PrismicRichText field={cell.content} components={components} />\n\t\t\t\t\t</Th>\n\t\t\t\t) : (\n\t\t\t\t\t<Td key={cell.key} cell={cell}>\n\t\t\t\t\t\t<PrismicRichText field={cell.content} components={components} />\n\t\t\t\t\t</Td>\n\t\t\t\t),\n\t\t\t)}\n\t\t</Tr>\n\t)\n}\n"],"mappings":";;;;AA0BA,MAAM,oBAA+C;CACpD,QAAQ,EAAE,eAAe,oBAAC,SAAD,EAAQ,
|
|
1
|
+
{"version":3,"file":"PrismicTable.js","names":[],"sources":["../src/PrismicTable.tsx"],"sourcesContent":["import {\n\tisFilled,\n\ttype TableField,\n\ttype TableFieldHead,\n\ttype TableFieldHeadRow,\n\ttype TableFieldBody,\n\ttype TableFieldBodyRow,\n\ttype TableFieldHeaderCell,\n\ttype TableFieldDataCell,\n} from \"@prismicio/client\"\nimport type { ComponentType, FC, ReactNode } from \"react\"\n\nimport { type JSXMapSerializer, PrismicRichText } from \"./PrismicRichText.js\"\n\ntype TableComponents = {\n\ttable?: ComponentType<{ table: TableField<\"filled\">; children: ReactNode }>\n\tthead?: ComponentType<{ head: TableFieldHead; children: ReactNode }>\n\ttbody?: ComponentType<{ body: TableFieldBody; children: ReactNode }>\n\ttr?: ComponentType<{\n\t\trow: TableFieldHeadRow | TableFieldBodyRow\n\t\tchildren: ReactNode\n\t}>\n\tth?: ComponentType<{ cell: TableFieldHeaderCell; children: ReactNode }>\n\ttd?: ComponentType<{ cell: TableFieldDataCell; children: ReactNode }>\n}\n\nconst defaultComponents: Required<TableComponents> = {\n\ttable: ({ children }) => <table>{children}</table>,\n\tthead: ({ children }) => <thead>{children}</thead>,\n\ttbody: ({ children }) => <tbody>{children}</tbody>,\n\ttr: ({ children }) => <tr>{children}</tr>,\n\tth: ({ children }) => <th>{children}</th>,\n\ttd: ({ children }) => <td>{children}</td>,\n}\n\n/** Props for `<PrismicTable>`. */\nexport type PrismicTableProps = {\n\t/** The Prismic table field to render. */\n\tfield: TableField\n\n\t/**\n\t * An object that maps a table block to a React component.\n\t *\n\t * @example\n\t * \tA map serializer.\n\t *\n\t * \t```jsx\n\t * \t{\n\t * \ttable: ({children}) => <table>{children}</table>\n\t * \tthead: ({children}) => <thead>{children}</thead>\n\t * \t}\n\t * \t```\n\t */\n\tcomponents?: JSXMapSerializer & TableComponents\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\n/**\n * Renders content from a Prismic table field as React components.\n *\n * @example\n * \t;```tsx\n * \t<PrismicTable field={slice.primary.pricing_table} />;\n * \t```\n *\n * @see Learn how to style tables and customize table element components: {@link https://prismic.io/docs/fields/table}\n */\nexport const PrismicTable: FC<PrismicTableProps> = (props) => {\n\tconst { field, components, fallback = null } = props\n\n\tif (!isFilled.table(field)) {\n\t\treturn fallback\n\t}\n\n\tconst { table: Table, thead: Thead, tbody: Tbody } = { ...defaultComponents, ...components }\n\n\treturn (\n\t\t<Table table={field}>\n\t\t\t{field.head && (\n\t\t\t\t<Thead head={field.head}>\n\t\t\t\t\t{field.head.rows.map((row) => (\n\t\t\t\t\t\t<TableRow key={row.key} row={row} components={components} />\n\t\t\t\t\t))}\n\t\t\t\t</Thead>\n\t\t\t)}\n\t\t\t<Tbody body={field.body}>\n\t\t\t\t{field.body.rows.map((row) => (\n\t\t\t\t\t<TableRow key={row.key} row={row} components={components} />\n\t\t\t\t))}\n\t\t\t</Tbody>\n\t\t</Table>\n\t)\n}\n\ntype TableRowProps = {\n\trow: TableFieldHeadRow | TableFieldBodyRow\n\tcomponents?: JSXMapSerializer & TableComponents\n}\n\nfunction TableRow(props: TableRowProps) {\n\tconst { row, components } = props\n\n\tconst { tr: Tr, th: Th, td: Td } = { ...defaultComponents, ...components }\n\n\treturn (\n\t\t<Tr row={row}>\n\t\t\t{row.cells.map((cell) =>\n\t\t\t\tcell.type === \"header\" ? (\n\t\t\t\t\t<Th key={cell.key} cell={cell}>\n\t\t\t\t\t\t<PrismicRichText field={cell.content} components={components} />\n\t\t\t\t\t</Th>\n\t\t\t\t) : (\n\t\t\t\t\t<Td key={cell.key} cell={cell}>\n\t\t\t\t\t\t<PrismicRichText field={cell.content} components={components} />\n\t\t\t\t\t</Td>\n\t\t\t\t),\n\t\t\t)}\n\t\t</Tr>\n\t)\n}\n"],"mappings":";;;;AA0BA,MAAM,oBAA+C;CACpD,QAAQ,EAAE,eAAe,oBAAC,SAAD,EAAQ,SAAgB,CAAA;CACjD,QAAQ,EAAE,eAAe,oBAAC,SAAD,EAAQ,SAAgB,CAAA;CACjD,QAAQ,EAAE,eAAe,oBAAC,SAAD,EAAQ,SAAgB,CAAA;CACjD,KAAK,EAAE,eAAe,oBAAC,MAAD,EAAK,SAAa,CAAA;CACxC,KAAK,EAAE,eAAe,oBAAC,MAAD,EAAK,SAAa,CAAA;CACxC,KAAK,EAAE,eAAe,oBAAC,MAAD,EAAK,SAAa,CAAA;AACzC;;;;;;;;;;;AAuCA,MAAa,gBAAuC,UAAU;CAC7D,MAAM,EAAE,OAAO,YAAY,WAAW,SAAS;CAE/C,IAAI,CAAC,SAAS,MAAM,KAAK,GACxB,OAAO;CAGR,MAAM,EAAE,OAAO,OAAO,OAAO,OAAO,OAAO,UAAU;EAAE,GAAG;EAAmB,GAAG;CAAW;CAE3F,OACC,qBAAC,OAAD;EAAO,OAAO;EAAd,UAAA,CACE,MAAM,QACN,oBAAC,OAAD;GAAO,MAAM,MAAM;GACjB,UAAA,MAAM,KAAK,KAAK,KAAK,QACrB,oBAAC,UAAD;IAA6B;IAAiB;GAAa,GAA5C,IAAI,GAAwC,CAC3D;EACK,CAAA,GAER,oBAAC,OAAD;GAAO,MAAM,MAAM;GACjB,UAAA,MAAM,KAAK,KAAK,KAAK,QACrB,oBAAC,UAAD;IAA6B;IAAiB;GAAa,GAA5C,IAAI,GAAwC,CAC3D;EACK,CAAA,CACD;;AAET;AAOA,SAAS,SAAS,OAAsB;CACvC,MAAM,EAAE,KAAK,eAAe;CAE5B,MAAM,EAAE,IAAI,IAAI,IAAI,IAAI,IAAI,OAAO;EAAE,GAAG;EAAmB,GAAG;CAAW;CAEzE,OACC,oBAAC,IAAD;EAAS;EACP,UAAA,IAAI,MAAM,KAAK,SACf,KAAK,SAAS,WACb,oBAAC,IAAD;GAAyB;GACxB,UAAA,oBAAC,iBAAD;IAAiB,OAAO,KAAK;IAAqB;GAAa,CAAA;EAC5D,GAFK,KAAK,GAEV,IAEJ,oBAAC,IAAD;GAAyB;GACxB,UAAA,oBAAC,iBAAD;IAAiB,OAAO,KAAK;IAAqB;GAAa,CAAA;EAC5D,GAFK,KAAK,GAEV,CAEN;CACG,CAAA;AAEN"}
|
package/dist/PrismicText.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { RichTextField } from "@prismicio/client";
|
|
2
2
|
import { FC } from "react";
|
|
3
|
-
|
|
4
3
|
//#region src/PrismicText.d.ts
|
|
5
4
|
/** Props for `<PrismicText>`. */
|
|
6
|
-
type PrismicTextProps = {
|
|
7
|
-
/** The Prismic rich text field to render. */
|
|
5
|
+
export type PrismicTextProps = {
|
|
6
|
+
/** The Prismic rich text field to render. */
|
|
7
|
+
field: RichTextField | null | undefined;
|
|
8
8
|
/**
|
|
9
9
|
* The string rendered when the field is empty. If a fallback is not given, `null` will be
|
|
10
10
|
* rendered.
|
|
11
11
|
*/
|
|
12
|
-
fallback?: string;
|
|
12
|
+
fallback?: string;
|
|
13
|
+
/** The separator used between blocks. Defaults to `\n`. */
|
|
13
14
|
separator?: string;
|
|
14
15
|
};
|
|
15
16
|
/**
|
|
@@ -22,7 +23,6 @@ type PrismicTextProps = {
|
|
|
22
23
|
*
|
|
23
24
|
* @see Learn how to display rich text as plain text or React components: {@link https://prismic.io/docs/fields/rich-text}
|
|
24
25
|
*/
|
|
25
|
-
declare const PrismicText: FC<PrismicTextProps>;
|
|
26
|
+
export declare const PrismicText: FC<PrismicTextProps>;
|
|
26
27
|
//#endregion
|
|
27
|
-
export { PrismicText, PrismicTextProps };
|
|
28
28
|
//# sourceMappingURL=PrismicText.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicText.d.ts","names":[],"sources":["../src/PrismicText.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"PrismicText.d.ts","names":[],"sources":["../src/PrismicText.tsx"],"mappings":";;;;YAOY;;EAEX,OAAO;;;;;EAMP;;EAGA;;;;;;;;;;;;qBAaY,aAAa,GAAG"}
|
package/dist/PrismicText.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicText.js","names":[],"sources":["../src/PrismicText.tsx"],"sourcesContent":["import { asText, isFilled, type RichTextField } from \"@prismicio/client\"\nimport { DEV } from \"esm-env\"\nimport type { FC } from \"react\"\n\nimport { devMsg } from \"./lib/devMsg.js\"\n\n/** Props for `<PrismicText>`. */\nexport type PrismicTextProps = {\n\t/** The Prismic rich text field to render. */\n\tfield: RichTextField | null | undefined\n\n\t/**\n\t * The string rendered when the field is empty. If a fallback is not given, `null` will be\n\t * rendered.\n\t */\n\tfallback?: string\n\n\t/** The separator used between blocks. Defaults to `\\n`. */\n\tseparator?: string\n}\n\n/**\n * Renders content from a Prismic rich text field as plain text (no HTML).\n *\n * @example\n * \t;```tsx\n * \t<PrismicText field={slice.primary.text} />;\n * \t```\n *\n * @see Learn how to display rich text as plain text or React components: {@link https://prismic.io/docs/fields/rich-text}\n */\nexport const PrismicText: FC<PrismicTextProps> = (props) => {\n\tconst { field, fallback, separator } = props\n\n\tif (DEV) {\n\t\tif (\"className\" in props) {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicText] className cannot be passed to <PrismicText> since it renders plain text 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\tprops.field,\n\t\t\t)\n\t\t}\n\t}\n\n\tif (typeof props.field === \"string\") {\n\t\tif (DEV) {\n\t\t\tconsole.error(\n\t\t\t\t`[PrismicText] The \"field\" prop only accepts a rich text field's value but was provided a different type of field instead (e.g. a key text or select field). You can resolve this error by rendering the field value inline without <PrismicText>. For more details, see ${devMsg(\n\t\t\t\t\t\"prismictext-works-only-with-rich-text-and-title-fields\",\n\t\t\t\t)}`,\n\t\t\t\tprops.field,\n\t\t\t)\n\t\t}\n\n\t\treturn null\n\t}\n\n\tif (!isFilled.richText(field)) {\n\t\treturn fallback != null ? <>{fallback}</> : null\n\t}\n\n\treturn <>{asText(field, { separator })}</>\n}\n"],"mappings":";;;;;;;;;;;;;;;AA+BA,MAAa,eAAqC,UAAU;CAC3D,MAAM,EAAE,OAAO,UAAU,cAAc;
|
|
1
|
+
{"version":3,"file":"PrismicText.js","names":[],"sources":["../src/PrismicText.tsx"],"sourcesContent":["import { asText, isFilled, type RichTextField } from \"@prismicio/client\"\nimport { DEV } from \"esm-env\"\nimport type { FC } from \"react\"\n\nimport { devMsg } from \"./lib/devMsg.js\"\n\n/** Props for `<PrismicText>`. */\nexport type PrismicTextProps = {\n\t/** The Prismic rich text field to render. */\n\tfield: RichTextField | null | undefined\n\n\t/**\n\t * The string rendered when the field is empty. If a fallback is not given, `null` will be\n\t * rendered.\n\t */\n\tfallback?: string\n\n\t/** The separator used between blocks. Defaults to `\\n`. */\n\tseparator?: string\n}\n\n/**\n * Renders content from a Prismic rich text field as plain text (no HTML).\n *\n * @example\n * \t;```tsx\n * \t<PrismicText field={slice.primary.text} />;\n * \t```\n *\n * @see Learn how to display rich text as plain text or React components: {@link https://prismic.io/docs/fields/rich-text}\n */\nexport const PrismicText: FC<PrismicTextProps> = (props) => {\n\tconst { field, fallback, separator } = props\n\n\tif (DEV) {\n\t\tif (\"className\" in props) {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicText] className cannot be passed to <PrismicText> since it renders plain text 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\tprops.field,\n\t\t\t)\n\t\t}\n\t}\n\n\tif (typeof props.field === \"string\") {\n\t\tif (DEV) {\n\t\t\tconsole.error(\n\t\t\t\t`[PrismicText] The \"field\" prop only accepts a rich text field's value but was provided a different type of field instead (e.g. a key text or select field). You can resolve this error by rendering the field value inline without <PrismicText>. For more details, see ${devMsg(\n\t\t\t\t\t\"prismictext-works-only-with-rich-text-and-title-fields\",\n\t\t\t\t)}`,\n\t\t\t\tprops.field,\n\t\t\t)\n\t\t}\n\n\t\treturn null\n\t}\n\n\tif (!isFilled.richText(field)) {\n\t\treturn fallback != null ? <>{fallback}</> : null\n\t}\n\n\treturn <>{asText(field, { separator })}</>\n}\n"],"mappings":";;;;;;;;;;;;;;;AA+BA,MAAa,eAAqC,UAAU;CAC3D,MAAM,EAAE,OAAO,UAAU,cAAc;CAEvC,IAAI,KACC;MAAA,eAAe,OAClB,QAAQ,KACP,6IAA6I,OAC5I,+BACD,EAAE,IACF,MAAM,KACP;CAAA;CAIF,IAAI,OAAO,MAAM,UAAU,UAAU;EACpC,IAAI,KACH,QAAQ,MACP,2QAA2Q,OAC1Q,wDACD,KACA,MAAM,KACP;EAGD,OAAO;CACR;CAEA,IAAI,CAAC,SAAS,SAAS,KAAK,GAC3B,OAAO,YAAY,OAAO,oBAAA,UAAA,EAAA,UAAG,SAAW,CAAA,IAAI;CAG7C,OAAO,oBAAA,UAAA,EAAA,UAAG,OAAO,OAAO,EAAE,UAAU,CAAC,EAAI,CAAA;AAC1C"}
|
package/dist/PrismicToolbar.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { FC } from "react";
|
|
2
|
-
|
|
3
2
|
//#region src/PrismicToolbar.d.ts
|
|
4
3
|
/** Props for `<PrismicToolbar>`. */
|
|
5
|
-
type PrismicToolbarProps = {
|
|
4
|
+
export type PrismicToolbarProps = {
|
|
6
5
|
/**
|
|
7
6
|
* The name of the Prismic repository. For example, `"my-repo"` if the repository URL is
|
|
8
7
|
* `my-repo.prismic.io`.
|
|
@@ -37,7 +36,6 @@ type PrismicToolbarProps = {
|
|
|
37
36
|
*
|
|
38
37
|
* @see Learn how to set up preview functionality and the toolbar's role in preview sessions: {@link https://prismic.io/docs/previews}
|
|
39
38
|
*/
|
|
40
|
-
declare const PrismicToolbar: FC<PrismicToolbarProps>;
|
|
39
|
+
export declare const PrismicToolbar: FC<PrismicToolbarProps>;
|
|
41
40
|
//#endregion
|
|
42
|
-
export { PrismicToolbar, PrismicToolbarProps };
|
|
43
41
|
//# sourceMappingURL=PrismicToolbar.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicToolbar.d.ts","names":[],"sources":["../src/PrismicToolbar.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"PrismicToolbar.d.ts","names":[],"sources":["../src/PrismicToolbar.tsx"],"mappings":";;;YAMY;;;;;EAKX;;;;;;;;;EAUA,mBAAmB,OAAO;IAAc;;;;;;;;EAQxC,gBAAgB,OAAO;;;;;;;;;;;;qBAaX,gBAAgB,GAAG"}
|
package/dist/PrismicToolbar.js
CHANGED
|
@@ -16,9 +16,11 @@ const PrismicToolbar = (props) => {
|
|
|
16
16
|
const { repositoryName, onPreviewUpdate, onPreviewEnd } = props;
|
|
17
17
|
const src = getToolbarSrc(repositoryName);
|
|
18
18
|
const onPreviewUpdateRef = useRef(onPreviewUpdate);
|
|
19
|
-
onPreviewUpdateRef.current = onPreviewUpdate;
|
|
20
19
|
const onPreviewEndRef = useRef(onPreviewEnd);
|
|
21
|
-
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
onPreviewUpdateRef.current = onPreviewUpdate;
|
|
22
|
+
onPreviewEndRef.current = onPreviewEnd;
|
|
23
|
+
});
|
|
22
24
|
useEffect(() => {
|
|
23
25
|
if (!document.querySelector(`script[src="${src}"]`)) {
|
|
24
26
|
const script = document.createElement("script");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicToolbar.js","names":[],"sources":["../src/PrismicToolbar.tsx"],"sourcesContent":["\"use client\"\n\nimport { getToolbarSrc } from \"@prismicio/client\"\nimport { type FC, useEffect, useRef } from \"react\"\n\n/** Props for `<PrismicToolbar>`. */\nexport type PrismicToolbarProps = {\n\t/**\n\t * The name of the Prismic repository. For example, `\"my-repo\"` if the repository URL is\n\t * `my-repo.prismic.io`.\n\t */\n\trepositoryName: string\n\n\t/**\n\t * Called when the Prismic toolbar triggers a preview update. This happens when the previewed\n\t * content changes.\n\t *\n\t * The new ref can be read from `event.detail.ref`.\n\t *\n\t * The default page reload behavior can be cancelled with `event.preventDefault()`.\n\t */\n\tonPreviewUpdate?: (event: CustomEvent<{ ref: string }>) => void\n\n\t/**\n\t * Called when the Prismic toolbar triggers a preview end. This happens when a preview session is\n\t * closed.\n\t *\n\t * The default page reload behavior can be cancelled with `event.preventDefault()`.\n\t */\n\tonPreviewEnd?: (event: CustomEvent<null>) => void\n}\n\n/**\n * Renders the Prismic Toolbar script to support draft previews.\n *\n * @example\n * \t;```tsx\n * \t<PrismicToolbar repositoryName=\"my-repo\" />;\n * \t```\n *\n * @see Learn how to set up preview functionality and the toolbar's role in preview sessions: {@link https://prismic.io/docs/previews}\n */\nexport const PrismicToolbar: FC<PrismicToolbarProps> = (props) => {\n\tconst { repositoryName, onPreviewUpdate, onPreviewEnd } = props\n\n\tconst src = getToolbarSrc(repositoryName)\n\n\tconst onPreviewUpdateRef = useRef(onPreviewUpdate)\n\
|
|
1
|
+
{"version":3,"file":"PrismicToolbar.js","names":[],"sources":["../src/PrismicToolbar.tsx"],"sourcesContent":["\"use client\"\n\nimport { getToolbarSrc } from \"@prismicio/client\"\nimport { type FC, useEffect, useRef } from \"react\"\n\n/** Props for `<PrismicToolbar>`. */\nexport type PrismicToolbarProps = {\n\t/**\n\t * The name of the Prismic repository. For example, `\"my-repo\"` if the repository URL is\n\t * `my-repo.prismic.io`.\n\t */\n\trepositoryName: string\n\n\t/**\n\t * Called when the Prismic toolbar triggers a preview update. This happens when the previewed\n\t * content changes.\n\t *\n\t * The new ref can be read from `event.detail.ref`.\n\t *\n\t * The default page reload behavior can be cancelled with `event.preventDefault()`.\n\t */\n\tonPreviewUpdate?: (event: CustomEvent<{ ref: string }>) => void\n\n\t/**\n\t * Called when the Prismic toolbar triggers a preview end. This happens when a preview session is\n\t * closed.\n\t *\n\t * The default page reload behavior can be cancelled with `event.preventDefault()`.\n\t */\n\tonPreviewEnd?: (event: CustomEvent<null>) => void\n}\n\n/**\n * Renders the Prismic Toolbar script to support draft previews.\n *\n * @example\n * \t;```tsx\n * \t<PrismicToolbar repositoryName=\"my-repo\" />;\n * \t```\n *\n * @see Learn how to set up preview functionality and the toolbar's role in preview sessions: {@link https://prismic.io/docs/previews}\n */\nexport const PrismicToolbar: FC<PrismicToolbarProps> = (props) => {\n\tconst { repositoryName, onPreviewUpdate, onPreviewEnd } = props\n\n\tconst src = getToolbarSrc(repositoryName)\n\n\tconst onPreviewUpdateRef = useRef(onPreviewUpdate)\n\tconst onPreviewEndRef = useRef(onPreviewEnd)\n\n\tuseEffect(() => {\n\t\tonPreviewUpdateRef.current = onPreviewUpdate\n\t\tonPreviewEndRef.current = onPreviewEnd\n\t})\n\n\tuseEffect(() => {\n\t\tconst existingScript = document.querySelector(`script[src=\"${src}\"]`)\n\n\t\tif (!existingScript) {\n\t\t\tconst script = document.createElement(\"script\")\n\t\t\tscript.src = src\n\t\t\tscript.defer = true\n\n\t\t\t// Used to distinguish the toolbar element from other elements.\n\t\t\tscript.dataset.prismicToolbar = \"\"\n\t\t\tscript.dataset.repositoryName = repositoryName\n\n\t\t\t// Disable Happy DOM `<script>` evaluation during tests.\n\t\t\t// @ts-expect-error - `_evaluateScript` is a Happy DOM-specific property.\n\t\t\tscript._evaluateScript = false\n\n\t\t\tdocument.body.appendChild(script)\n\t\t}\n\t}, [repositoryName, src])\n\n\tuseEffect(() => {\n\t\tconst controller = new AbortController()\n\n\t\twindow.addEventListener(\n\t\t\t\"prismicPreviewUpdate\",\n\t\t\t(event) => onPreviewUpdateRef.current?.(event as CustomEvent<{ ref: string }>),\n\t\t\t{ signal: controller.signal },\n\t\t)\n\n\t\twindow.addEventListener(\n\t\t\t\"prismicPreviewEnd\",\n\t\t\t(event) => onPreviewEndRef.current?.(event as CustomEvent<null>),\n\t\t\t{ signal: controller.signal },\n\t\t)\n\n\t\treturn () => controller.abort()\n\t}, [])\n\n\treturn null\n}\n"],"mappings":";;;;;;;;;;;;;;AA0CA,MAAa,kBAA2C,UAAU;CACjE,MAAM,EAAE,gBAAgB,iBAAiB,iBAAiB;CAE1D,MAAM,MAAM,cAAc,cAAc;CAExC,MAAM,qBAAqB,OAAO,eAAe;CACjD,MAAM,kBAAkB,OAAO,YAAY;CAE3C,gBAAgB;EACf,mBAAmB,UAAU;EAC7B,gBAAgB,UAAU;CAC3B,CAAC;CAED,gBAAgB;EAGf,IAAI,CAFmB,SAAS,cAAc,eAAe,IAAI,GAE/C,GAAG;GACpB,MAAM,SAAS,SAAS,cAAc,QAAQ;GAC9C,OAAO,MAAM;GACb,OAAO,QAAQ;GAGf,OAAO,QAAQ,iBAAiB;GAChC,OAAO,QAAQ,iBAAiB;GAIhC,OAAO,kBAAkB;GAEzB,SAAS,KAAK,YAAY,MAAM;EACjC;CACD,GAAG,CAAC,gBAAgB,GAAG,CAAC;CAExB,gBAAgB;EACf,MAAM,aAAa,IAAI,gBAAgB;EAEvC,OAAO,iBACN,yBACC,UAAU,mBAAmB,UAAU,KAAqC,GAC7E,EAAE,QAAQ,WAAW,OAAO,CAC7B;EAEA,OAAO,iBACN,sBACC,UAAU,gBAAgB,UAAU,KAA0B,GAC/D,EAAE,QAAQ,WAAW,OAAO,CAC7B;EAEA,aAAa,WAAW,MAAM;CAC/B,GAAG,CAAC,CAAC;CAEL,OAAO;AACR"}
|
package/dist/SliceZone.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Slice } from "@prismicio/client";
|
|
2
2
|
import { ComponentType, FC, ReactNode } from "react";
|
|
3
|
-
|
|
4
3
|
//#region src/SliceZone.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Returns the type of a `SliceLike` type.
|
|
@@ -14,14 +13,14 @@ type ExtractSliceType<TSlice extends SliceLike> = TSlice extends Slice ? TSlice[
|
|
|
14
13
|
*
|
|
15
14
|
* @typeParam SliceType - Type name of the slice.
|
|
16
15
|
*/
|
|
17
|
-
type SliceLikeRestV2<TSliceType extends string = string> = Pick<Slice<TSliceType>, "id" | "slice_type">;
|
|
16
|
+
export type SliceLikeRestV2<TSliceType extends string = string> = Pick<Slice<TSliceType>, "id" | "slice_type">;
|
|
18
17
|
/**
|
|
19
18
|
* The minimum required properties to represent a Prismic slice from the Prismic GraphQL API for the
|
|
20
19
|
* `mapSliceZone()` helper.
|
|
21
20
|
*
|
|
22
21
|
* @typeParam SliceType - Type name of the slice.
|
|
23
22
|
*/
|
|
24
|
-
type SliceLikeGraphQL<TSliceType extends string = string> = {
|
|
23
|
+
export type SliceLikeGraphQL<TSliceType extends string = string> = {
|
|
25
24
|
type: Slice<TSliceType>["slice_type"];
|
|
26
25
|
};
|
|
27
26
|
/**
|
|
@@ -32,7 +31,7 @@ type SliceLikeGraphQL<TSliceType extends string = string> = {
|
|
|
32
31
|
*
|
|
33
32
|
* @typeParam SliceType - Type name of the slice.
|
|
34
33
|
*/
|
|
35
|
-
type SliceLike<TSliceType extends string = string> = (SliceLikeRestV2<TSliceType> | SliceLikeGraphQL<TSliceType>) & {
|
|
34
|
+
export type SliceLike<TSliceType extends string = string> = (SliceLikeRestV2<TSliceType> | SliceLikeGraphQL<TSliceType>) & {
|
|
36
35
|
/**
|
|
37
36
|
* If `true`, this slice has been modified from its original value using a mapper and
|
|
38
37
|
* `@prismicio/client`'s `mapSliceZone()`.
|
|
@@ -49,7 +48,7 @@ type SliceLike<TSliceType extends string = string> = (SliceLikeRestV2<TSliceType
|
|
|
49
48
|
*
|
|
50
49
|
* @typeParam TSlice - The type(s) of a slice in the slice zone.
|
|
51
50
|
*/
|
|
52
|
-
type SliceZoneLike<TSlice extends SliceLike = SliceLike> = readonly TSlice[];
|
|
51
|
+
export type SliceZoneLike<TSlice extends SliceLike = SliceLike> = readonly TSlice[];
|
|
53
52
|
/**
|
|
54
53
|
* React props for a component rendering content from a Prismic slice using the `<SliceZone>`
|
|
55
54
|
* component.
|
|
@@ -58,10 +57,14 @@ type SliceZoneLike<TSlice extends SliceLike = SliceLike> = readonly TSlice[];
|
|
|
58
57
|
* @typeParam TContext - Arbitrary data passed to `<SliceZone>` and made available to all slice
|
|
59
58
|
* components.
|
|
60
59
|
*/
|
|
61
|
-
type SliceComponentProps<TSlice extends SliceLike = SliceLike, TContext = unknown> = {
|
|
62
|
-
/** Slice data for this component. */
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
export type SliceComponentProps<TSlice extends SliceLike = SliceLike, TContext = unknown> = {
|
|
61
|
+
/** Slice data for this component. */
|
|
62
|
+
slice: TSlice;
|
|
63
|
+
/** The index of the slice in the slice zone. */
|
|
64
|
+
index: number;
|
|
65
|
+
/** All slices from the slice zone to which the slice belongs. */
|
|
66
|
+
slices: SliceZoneLike<TSlice extends SliceLikeGraphQL ? SliceLikeGraphQL : SliceLikeRestV2>;
|
|
67
|
+
/** Arbitrary data passed to `<SliceZone>` and made available to all slice components. */
|
|
65
68
|
context: TContext;
|
|
66
69
|
};
|
|
67
70
|
/**
|
|
@@ -70,7 +73,7 @@ type SliceComponentProps<TSlice extends SliceLike = SliceLike, TContext = unknow
|
|
|
70
73
|
* @typeParam TSlice - The type(s) of a slice in the slice zone.
|
|
71
74
|
* @typeParam TContext - Arbitrary data made available to all slice components.
|
|
72
75
|
*/
|
|
73
|
-
type SliceComponentType<TSlice extends SliceLike = any, TContext = unknown> = ComponentType<SliceComponentProps<TSlice, TContext>>;
|
|
76
|
+
export type SliceComponentType<TSlice extends SliceLike = any, TContext = unknown> = ComponentType<SliceComponentProps<TSlice, TContext>>;
|
|
74
77
|
/**
|
|
75
78
|
* A record of slice types mapped to a React component. The component will be rendered for each
|
|
76
79
|
* instance of its slice.
|
|
@@ -80,17 +83,21 @@ type SliceComponentType<TSlice extends SliceLike = any, TContext = unknown> = Co
|
|
|
80
83
|
* @typeParam TSlice - The type(s) of a slice in the slice zone.
|
|
81
84
|
* @typeParam TContext - Arbitrary data made available to all slice components.
|
|
82
85
|
*/
|
|
83
|
-
type SliceZoneComponents<TSlice extends SliceLike = SliceLike, TContext = unknown> = { [SliceType in ExtractSliceType<TSlice>]: SliceComponentType<Extract<TSlice, SliceLike<SliceType>> extends never ? SliceLike : Extract<TSlice, SliceLike<SliceType>>, TContext
|
|
86
|
+
export type SliceZoneComponents<TSlice extends SliceLike = SliceLike, TContext = unknown> = { [SliceType in ExtractSliceType<TSlice>]: SliceComponentType<Extract<TSlice, SliceLike<SliceType>> extends never ? SliceLike : Extract<TSlice, SliceLike<SliceType>>, TContext>; };
|
|
84
87
|
/**
|
|
85
88
|
* React props for the `<SliceZone>` component.
|
|
86
89
|
*
|
|
87
90
|
* @typeParam TSlice - The type(s) of a slice in the slice zone.
|
|
88
91
|
* @typeParam TContext - Arbitrary data made available to all slice components.
|
|
89
92
|
*/
|
|
90
|
-
type SliceZoneProps<TContext = unknown> = {
|
|
91
|
-
/** List of slice data from the slice zone. */
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
export type SliceZoneProps<TContext = unknown> = {
|
|
94
|
+
/** List of slice data from the slice zone. */
|
|
95
|
+
slices?: SliceZoneLike;
|
|
96
|
+
/** A record mapping slice types to React components. */
|
|
97
|
+
components?: Record<string, ComponentType<any>>;
|
|
98
|
+
/** The React component rendered if a component mapping from the `components` prop cannot be found. */
|
|
99
|
+
defaultComponent?: ComponentType<SliceComponentProps<any, TContext>>;
|
|
100
|
+
/** Arbitrary data made available to all slice components. */
|
|
94
101
|
context?: TContext;
|
|
95
102
|
};
|
|
96
103
|
/**
|
|
@@ -99,9 +106,7 @@ type SliceZoneProps<TContext = unknown> = {
|
|
|
99
106
|
* This is also the default React component rendered when a component mapping cannot be found in
|
|
100
107
|
* `<SliceZone>`.
|
|
101
108
|
*/
|
|
102
|
-
declare const TODOSliceComponent: <TSlice extends SliceLike>({
|
|
103
|
-
slice
|
|
104
|
-
}: {
|
|
109
|
+
export declare const TODOSliceComponent: <TSlice extends SliceLike>({ slice }: {
|
|
105
110
|
slice: TSlice;
|
|
106
111
|
}) => ReactNode;
|
|
107
112
|
/**
|
|
@@ -114,7 +119,6 @@ declare const TODOSliceComponent: <TSlice extends SliceLike>({
|
|
|
114
119
|
*
|
|
115
120
|
* @see Learn how to create slices, use slice variations, and display slices: {@link https://prismic.io/docs/slices}
|
|
116
121
|
*/
|
|
117
|
-
declare const SliceZone: FC<SliceZoneProps>;
|
|
122
|
+
export declare const SliceZone: FC<SliceZoneProps>;
|
|
118
123
|
//#endregion
|
|
119
|
-
export { SliceComponentProps, SliceComponentType, SliceLike, SliceLikeGraphQL, SliceLikeRestV2, SliceZone, SliceZoneComponents, SliceZoneLike, SliceZoneProps, TODOSliceComponent };
|
|
120
124
|
//# sourceMappingURL=SliceZone.d.ts.map
|
package/dist/SliceZone.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SliceZone.d.ts","names":[],"sources":["../src/SliceZone.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"SliceZone.d.ts","names":[],"sources":["../src/SliceZone.tsx"],"mappings":";;;;;;;;KASK,iBAAiB,eAAe,aAAa,eAAe,QAC9D,uBACA,eAAe,mBACd;;;;;;;YASQ,gBAAgB,sCAAsC,KACjE,MAAM;;;;;;;YAUK,iBAAiB;EAC5B,MAAM,MAAM;;;;;;;;;;YAWD,UAAU,uCACnB,gBAAgB,cAChB,iBAAiB;;;;;;;EAQnB;;;;;;;;;;YAWW,cAAc,eAAe,YAAY,sBAAsB;;;;;;;;;YAU/D,oBAAoB,eAAe,YAAY,WAAW;;EAErE,OAAO;;EAGP;;EAOA,QAAQ,cAAc,eAAe,mBAAmB,mBAAmB;;EAG3E,SAAS;;;;;;;;YASE,mBAEX,eAAe,iBACf,sBACG,cAAc,oBAAoB,QAAQ;;;;;;;;;;YAWlC,oBAAoB,eAAe,YAAY,WAAW,yBAWnE,aAAa,iBAAiB,UAAU,mBACxC,QAAQ,QAAQ,UAAU,4BACvB,YACA,QAAQ,QAAQ,UAAU,aAC7B;;;;;;;YAUS,eAAe;;EAE1B,SAAS;;EAIT,aAAa,eAAe;;EAI5B,mBAAmB,cAAc,yBAAyB;;EAG1D,UAAU;;;;;;;;qBASE,qBAAsB,eAAe,aAAS;EAG1D,OAAO;MACJ;;;;;;;;;;;qBA2BS,WAAW,GAAG"}
|
package/dist/SliceZone.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { SliceBoundary } from "./SliceBoundary.js";
|
|
2
1
|
import { DEV } from "esm-env";
|
|
3
|
-
import { Fragment } from "react";
|
|
4
|
-
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
3
|
//#region src/SliceZone.tsx
|
|
6
4
|
/**
|
|
7
5
|
* This slice component can be used as a reminder to provide a proper implementation.
|
|
@@ -35,27 +33,23 @@ const TODOSliceComponent = ({ slice }) => {
|
|
|
35
33
|
*/
|
|
36
34
|
const SliceZone = (props) => {
|
|
37
35
|
const { slices = [], components = {}, defaultComponent, context = {} } = props;
|
|
38
|
-
|
|
36
|
+
const renderedSlices = slices.map((slice, index) => {
|
|
39
37
|
const type = "slice_type" in slice ? slice.slice_type : slice.type;
|
|
40
38
|
const key = "id" in slice && slice.id ? slice.id : `${index}-${JSON.stringify(slice)}`;
|
|
41
39
|
const Comp = components[type] || defaultComponent;
|
|
42
|
-
|
|
43
|
-
if (
|
|
44
|
-
else if (slice.__mapped) {
|
|
40
|
+
if (!Comp) return /* @__PURE__ */ jsx(TODOSliceComponent, { slice }, key);
|
|
41
|
+
if (slice.__mapped) {
|
|
45
42
|
const { __mapped, ...mappedProps } = slice;
|
|
46
|
-
|
|
47
|
-
}
|
|
43
|
+
return /* @__PURE__ */ jsx(Comp, { ...mappedProps }, key);
|
|
44
|
+
}
|
|
45
|
+
return /* @__PURE__ */ jsx(Comp, {
|
|
48
46
|
slice,
|
|
49
47
|
index,
|
|
50
48
|
slices,
|
|
51
49
|
context
|
|
52
|
-
});
|
|
53
|
-
if ("id" in slice && slice.id) return /* @__PURE__ */ jsx(SliceBoundary, {
|
|
54
|
-
sliceId: slice.id,
|
|
55
|
-
children: renderedSlice
|
|
56
50
|
}, key);
|
|
57
|
-
|
|
58
|
-
|
|
51
|
+
});
|
|
52
|
+
return /* @__PURE__ */ jsx(Fragment, { children: renderedSlices });
|
|
59
53
|
};
|
|
60
54
|
//#endregion
|
|
61
55
|
export { SliceZone, TODOSliceComponent };
|
package/dist/SliceZone.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SliceZone.js","names":[],"sources":["../src/SliceZone.tsx"],"sourcesContent":["import type { Slice } from \"@prismicio/client\"\nimport { DEV } from \"esm-env\"\nimport {
|
|
1
|
+
{"version":3,"file":"SliceZone.js","names":[],"sources":["../src/SliceZone.tsx"],"sourcesContent":["import type { Slice } from \"@prismicio/client\"\nimport { DEV } from \"esm-env\"\nimport type { ComponentType, FC, ReactNode } from \"react\"\n\n/**\n * Returns the type of a `SliceLike` type.\n *\n * @typeParam TSlice - The slice from which the type will be extracted.\n */\ntype ExtractSliceType<TSlice extends SliceLike> = TSlice extends Slice\n\t? TSlice[\"slice_type\"]\n\t: TSlice extends SliceLikeGraphQL\n\t\t? TSlice[\"type\"]\n\t\t: never\n\n/**\n * The minimum required properties to represent a Prismic slice from the Prismic Content API for the\n * `mapSliceZone()` helper.\n *\n * @typeParam SliceType - Type name of the slice.\n */\nexport type SliceLikeRestV2<TSliceType extends string = string> = Pick<\n\tSlice<TSliceType>,\n\t\"id\" | \"slice_type\"\n>\n\n/**\n * The minimum required properties to represent a Prismic slice from the Prismic GraphQL API for the\n * `mapSliceZone()` helper.\n *\n * @typeParam SliceType - Type name of the slice.\n */\nexport type SliceLikeGraphQL<TSliceType extends string = string> = {\n\ttype: Slice<TSliceType>[\"slice_type\"]\n}\n\n/**\n * The minimum required properties to represent a Prismic slice for the `mapSliceZone()` helper.\n *\n * If using Prismic's Content API, use the `Slice` export from `@prismicio/client` for a full\n * interface.\n *\n * @typeParam SliceType - Type name of the slice.\n */\nexport type SliceLike<TSliceType extends string = string> = (\n\t| SliceLikeRestV2<TSliceType>\n\t| SliceLikeGraphQL<TSliceType>\n) & {\n\t/**\n\t * If `true`, this slice has been modified from its original value using a mapper and\n\t * `@prismicio/client`'s `mapSliceZone()`.\n\t *\n\t * @internal\n\t */\n\t__mapped?: true\n}\n\n/**\n * A looser version of the `SliceZone` type from `@prismicio/client` using `SliceLike`.\n *\n * If using Prismic's Content API, use the `SliceZone` export from `@prismicio/client` for the full\n * type.\n *\n * @typeParam TSlice - The type(s) of a slice in the slice zone.\n */\nexport type SliceZoneLike<TSlice extends SliceLike = SliceLike> = readonly TSlice[]\n\n/**\n * React props for a component rendering content from a Prismic slice using the `<SliceZone>`\n * component.\n *\n * @typeParam TSlice - The slice passed as a prop.\n * @typeParam TContext - Arbitrary data passed to `<SliceZone>` and made available to all slice\n * components.\n */\nexport type SliceComponentProps<TSlice extends SliceLike = SliceLike, TContext = unknown> = {\n\t/** Slice data for this component. */\n\tslice: TSlice\n\n\t/** The index of the slice in the slice zone. */\n\tindex: number\n\n\t/** All slices from the slice zone to which the slice belongs. */\n\t// TODO: We have to keep this list of slices general due to circular\n\t// reference limtiations. If we had another generic to determine the full\n\t// union of slice types, it would include TSlice. This causes TypeScript to\n\t// throw a compilation error.\n\tslices: SliceZoneLike<TSlice extends SliceLikeGraphQL ? SliceLikeGraphQL : SliceLikeRestV2>\n\n\t/** Arbitrary data passed to `<SliceZone>` and made available to all slice components. */\n\tcontext: TContext\n}\n\n/**\n * A React component to be rendered for each instance of its slice.\n *\n * @typeParam TSlice - The type(s) of a slice in the slice zone.\n * @typeParam TContext - Arbitrary data made available to all slice components.\n */\nexport type SliceComponentType<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTSlice extends SliceLike = any,\n\tTContext = unknown,\n> = ComponentType<SliceComponentProps<TSlice, TContext>>\n\n/**\n * A record of slice types mapped to a React component. The component will be rendered for each\n * instance of its slice.\n *\n * @deprecated This type is no longer used by `@prismicio/react`. Prefer using\n * `Record<string, SliceComponentType<any>>` instead.\n * @typeParam TSlice - The type(s) of a slice in the slice zone.\n * @typeParam TContext - Arbitrary data made available to all slice components.\n */\nexport type SliceZoneComponents<TSlice extends SliceLike = SliceLike, TContext = unknown> =\n\t// This is purposely not wrapped in Partial to ensure a component is provided\n\t// for all slice types. <SliceZone> will render a default component if one is\n\t// not provided, but it *should* be a type error if an explicit component is\n\t// missing.\n\t//\n\t// If a developer purposely does not want to provide a component, they can\n\t// assign it to the TODOSliceComponent exported from this package. This\n\t// signals to future developers that it is a placeholder and should be\n\t// implemented.\n\t{\n\t\t[SliceType in ExtractSliceType<TSlice>]: SliceComponentType<\n\t\t\tExtract<TSlice, SliceLike<SliceType>> extends never\n\t\t\t\t? SliceLike\n\t\t\t\t: Extract<TSlice, SliceLike<SliceType>>,\n\t\t\tTContext\n\t\t>\n\t}\n\n/**\n * React props for the `<SliceZone>` component.\n *\n * @typeParam TSlice - The type(s) of a slice in the slice zone.\n * @typeParam TContext - Arbitrary data made available to all slice components.\n */\nexport type SliceZoneProps<TContext = unknown> = {\n\t/** List of slice data from the slice zone. */\n\tslices?: SliceZoneLike\n\n\t/** A record mapping slice types to React components. */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tcomponents?: Record<string, ComponentType<any>>\n\n\t/** The React component rendered if a component mapping from the `components` prop cannot be found. */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tdefaultComponent?: ComponentType<SliceComponentProps<any, TContext>>\n\n\t/** Arbitrary data made available to all slice components. */\n\tcontext?: TContext\n}\n\n/**\n * This slice component can be used as a reminder to provide a proper implementation.\n *\n * This is also the default React component rendered when a component mapping cannot be found in\n * `<SliceZone>`.\n */\nexport const TODOSliceComponent = <TSlice extends SliceLike>({\n\tslice,\n}: {\n\tslice: TSlice\n}): ReactNode => {\n\tif (!DEV) {\n\t\treturn null\n\t}\n\n\tconst type = \"slice_type\" in slice ? slice.slice_type : slice.type\n\n\tconsole.warn(`[SliceZone] Could not find a component for slice type \"${type}\"`, slice)\n\n\treturn (\n\t\t<section data-slice-zone-todo-component=\"\" data-slice-type={type}>\n\t\t\tCould not find a component for slice type “{type}\n\t\t\t”\n\t\t</section>\n\t)\n}\n\n/**\n * Renders slices in a slice zone as React components.\n *\n * @example\n * \t;```tsx\n * \t<SliceZone slices={page.data.slices} components={components} />;\n * \t```\n *\n * @see Learn how to create slices, use slice variations, and display slices: {@link https://prismic.io/docs/slices}\n */\nexport const SliceZone: FC<SliceZoneProps> = (props) => {\n\tconst { slices = [], components = {}, defaultComponent, context = {} } = props\n\n\tconst renderedSlices = slices.map((slice, index) => {\n\t\tconst type = \"slice_type\" in slice ? slice.slice_type : slice.type\n\n\t\tconst key = \"id\" in slice && slice.id ? slice.id : `${index}-${JSON.stringify(slice)}`\n\n\t\tconst Comp = components[type as keyof typeof components] || defaultComponent\n\n\t\tif (!Comp) {\n\t\t\treturn <TODOSliceComponent key={key} slice={slice} />\n\t\t}\n\n\t\tif (slice.__mapped) {\n\t\t\tconst { __mapped, ...mappedProps } = slice\n\n\t\t\treturn <Comp key={key} {...mappedProps} />\n\t\t}\n\n\t\treturn <Comp key={key} slice={slice} index={index} slices={slices} context={context} />\n\t})\n\n\treturn <>{renderedSlices}</>\n}\n"],"mappings":";;;;;;;;;AAiKA,MAAa,sBAAgD,EAC5D,YAGgB;CAChB,IAAI,CAAC,KACJ,OAAO;CAGR,MAAM,OAAO,gBAAgB,QAAQ,MAAM,aAAa,MAAM;CAE9D,QAAQ,KAAK,0DAA0D,KAAK,IAAI,KAAK;CAErF,OACC,qBAAC,WAAD;EAAS,kCAA+B;EAAG,mBAAiB;EAA5D,UAAA;GAAkE;GACf;GAAK;EAE/C;;AAEX;;;;;;;;;;;AAYA,MAAa,aAAiC,UAAU;CACvD,MAAM,EAAE,SAAS,CAAC,GAAG,aAAa,CAAC,GAAG,kBAAkB,UAAU,CAAC,MAAM;CAEzE,MAAM,iBAAiB,OAAO,KAAK,OAAO,UAAU;EACnD,MAAM,OAAO,gBAAgB,QAAQ,MAAM,aAAa,MAAM;EAE9D,MAAM,MAAM,QAAQ,SAAS,MAAM,KAAK,MAAM,KAAK,GAAG,MAAM,GAAG,KAAK,UAAU,KAAK;EAEnF,MAAM,OAAO,WAAW,SAAoC;EAE5D,IAAI,CAAC,MACJ,OAAO,oBAAC,oBAAD,EAAqC,MAAQ,GAApB,GAAoB;EAGrD,IAAI,MAAM,UAAU;GACnB,MAAM,EAAE,UAAU,GAAG,gBAAgB;GAErC,OAAO,oBAAC,MAAD,EAAgB,GAAI,YAAc,GAAvB,GAAuB;EAC1C;EAEA,OAAO,oBAAC,MAAD;GAAuB;GAAc;GAAe;GAAiB;EAAU,GAApE,GAAoE;CACvF,CAAC;CAED,OAAO,oBAAA,UAAA,EAAA,UAAG,eAAiB,CAAA;AAC5B"}
|
package/dist/lib/devMsg.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devMsg.js","names":[],"sources":["../../src/lib/devMsg.ts"],"sourcesContent":["import { version } from \"../../package.json\"\n\n/**\n * Returns a `prismic.dev/msg` URL for a given message slug.\n *\n * @example\n * \t;```ts\n * \tdevMsg(\"missing-param\");\n * \t// => \"https://prismic.dev/msg/react/v1.2.3/missing-param\"\n * \t```\n *\n * @param slug - Slug for the message. This corresponds to a Markdown file in the Git repository's\n * `/messages` directory.\n * @returns The `prismic.dev/msg` URL for the given slug.\n */\nexport function devMsg(slug: string): string {\n\treturn `https://prismic.dev/msg/react/v${version}/${slug}`\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,SAAgB,OAAO,MAAsB;
|
|
1
|
+
{"version":3,"file":"devMsg.js","names":[],"sources":["../../src/lib/devMsg.ts"],"sourcesContent":["import { version } from \"../../package.json\"\n\n/**\n * Returns a `prismic.dev/msg` URL for a given message slug.\n *\n * @example\n * \t;```ts\n * \tdevMsg(\"missing-param\");\n * \t// => \"https://prismic.dev/msg/react/v1.2.3/missing-param\"\n * \t```\n *\n * @param slug - Slug for the message. This corresponds to a Markdown file in the Git repository's\n * `/messages` directory.\n * @returns The `prismic.dev/msg` URL for the given slug.\n */\nexport function devMsg(slug: string): string {\n\treturn `https://prismic.dev/msg/react/v${version}/${slug}`\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,SAAgB,OAAO,MAAsB;CAC5C,OAAO,kCAAkC,QAAQ,GAAG;AACrD"}
|
package/dist/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismicio/react",
|
|
3
|
-
"version": "3.4.2-pr.
|
|
3
|
+
"version": "3.4.2-pr.271.d473965",
|
|
4
4
|
"description": "React components and hooks to fetch and present Prismic content",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"prismic",
|
|
@@ -53,24 +53,25 @@
|
|
|
53
53
|
"esm-env": "^1.2.2"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@playwright/test": "^1.
|
|
57
|
-
"@prismicio/client": "^7.
|
|
58
|
-
"@types
|
|
59
|
-
"@types/react
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"react
|
|
66
|
-
"
|
|
67
|
-
"
|
|
56
|
+
"@playwright/test": "^1.63.0",
|
|
57
|
+
"@prismicio/client": "^7.22.1",
|
|
58
|
+
"@prismicio/types-internal": "^3.17.2",
|
|
59
|
+
"@types/react": "^19.3.0",
|
|
60
|
+
"@types/react-dom": "^19.3.0",
|
|
61
|
+
"dotenv": "^18.0.0",
|
|
62
|
+
"oxfmt": "^0.68.0",
|
|
63
|
+
"oxlint": "^1.83.0",
|
|
64
|
+
"playwright": "^1.63.0",
|
|
65
|
+
"react": "^19.3.0",
|
|
66
|
+
"react-dom": "^19.3.0",
|
|
67
|
+
"tsdown": "^0.23.0",
|
|
68
|
+
"typescript": "^7.0.2"
|
|
68
69
|
},
|
|
69
70
|
"peerDependencies": {
|
|
70
71
|
"@prismicio/client": "^7",
|
|
71
72
|
"react": "^18 || ^19"
|
|
72
73
|
},
|
|
73
74
|
"engines": {
|
|
74
|
-
"node": ">=
|
|
75
|
+
"node": ">=22"
|
|
75
76
|
}
|
|
76
77
|
}
|
package/src/PrismicImage.tsx
CHANGED
|
@@ -127,8 +127,8 @@ export const PrismicImage: FC<PrismicImageProps> = forwardRef(function PrismicIm
|
|
|
127
127
|
return <>{fallback}</>
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
const resolvedImgixParams = imgixParams
|
|
131
|
-
for (const x in
|
|
130
|
+
const resolvedImgixParams = { ...imgixParams }
|
|
131
|
+
for (const x in resolvedImgixParams) {
|
|
132
132
|
if (resolvedImgixParams[x as keyof typeof resolvedImgixParams] === null) {
|
|
133
133
|
resolvedImgixParams[x as keyof typeof resolvedImgixParams] = undefined
|
|
134
134
|
}
|
package/src/PrismicToolbar.tsx
CHANGED
|
@@ -46,10 +46,12 @@ export const PrismicToolbar: FC<PrismicToolbarProps> = (props) => {
|
|
|
46
46
|
const src = getToolbarSrc(repositoryName)
|
|
47
47
|
|
|
48
48
|
const onPreviewUpdateRef = useRef(onPreviewUpdate)
|
|
49
|
-
onPreviewUpdateRef.current = onPreviewUpdate
|
|
50
|
-
|
|
51
49
|
const onPreviewEndRef = useRef(onPreviewEnd)
|
|
52
|
-
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
onPreviewUpdateRef.current = onPreviewUpdate
|
|
53
|
+
onPreviewEndRef.current = onPreviewEnd
|
|
54
|
+
})
|
|
53
55
|
|
|
54
56
|
useEffect(() => {
|
|
55
57
|
const existingScript = document.querySelector(`script[src="${src}"]`)
|
package/src/SliceZone.tsx
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { Slice } from "@prismicio/client"
|
|
2
2
|
import { DEV } from "esm-env"
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
import { SliceBoundary } from "./SliceBoundary.js"
|
|
3
|
+
import type { ComponentType, FC, ReactNode } from "react"
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
6
|
* Returns the type of a `SliceLike` type.
|
|
@@ -201,27 +199,18 @@ export const SliceZone: FC<SliceZoneProps> = (props) => {
|
|
|
201
199
|
const key = "id" in slice && slice.id ? slice.id : `${index}-${JSON.stringify(slice)}`
|
|
202
200
|
|
|
203
201
|
const Comp = components[type as keyof typeof components] || defaultComponent
|
|
204
|
-
let renderedSlice: ReactNode
|
|
205
202
|
|
|
206
203
|
if (!Comp) {
|
|
207
|
-
|
|
208
|
-
} else if (slice.__mapped) {
|
|
209
|
-
const { __mapped, ...mappedProps } = slice
|
|
210
|
-
|
|
211
|
-
renderedSlice = <Comp {...mappedProps} />
|
|
212
|
-
} else {
|
|
213
|
-
renderedSlice = <Comp slice={slice} index={index} slices={slices} context={context} />
|
|
204
|
+
return <TODOSliceComponent key={key} slice={slice} />
|
|
214
205
|
}
|
|
215
206
|
|
|
216
|
-
if (
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
</SliceBoundary>
|
|
221
|
-
)
|
|
207
|
+
if (slice.__mapped) {
|
|
208
|
+
const { __mapped, ...mappedProps } = slice
|
|
209
|
+
|
|
210
|
+
return <Comp key={key} {...mappedProps} />
|
|
222
211
|
}
|
|
223
212
|
|
|
224
|
-
return <
|
|
213
|
+
return <Comp key={key} slice={slice} index={index} slices={slices} context={context} />
|
|
225
214
|
})
|
|
226
215
|
|
|
227
216
|
return <>{renderedSlices}</>
|
package/dist/SliceBoundary.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useId, useLayoutEffect, useRef, useSyncExternalStore } from "react";
|
|
3
|
-
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
-
//#region src/SliceBoundary.tsx
|
|
5
|
-
function SliceBoundary(props) {
|
|
6
|
-
const { children, sliceId } = props;
|
|
7
|
-
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
8
|
-
/* @__PURE__ */ jsx(CommentMarker, { value: `prismic-slice-start:${sliceId}` }),
|
|
9
|
-
children,
|
|
10
|
-
/* @__PURE__ */ jsx(CommentMarker, { value: `prismic-slice-end:${sliceId}` })
|
|
11
|
-
] });
|
|
12
|
-
}
|
|
13
|
-
function CommentMarker(props) {
|
|
14
|
-
const { value } = props;
|
|
15
|
-
const id = useId();
|
|
16
|
-
const isClient = useIsClient();
|
|
17
|
-
const anchorRef = useRef(null);
|
|
18
|
-
useLayoutEffect(() => {
|
|
19
|
-
let anchor = anchorRef.current;
|
|
20
|
-
if (!anchor?.isConnected) {
|
|
21
|
-
anchor = findTextNode(id);
|
|
22
|
-
if (!anchor) return;
|
|
23
|
-
anchor.data = "";
|
|
24
|
-
anchorRef.current = anchor;
|
|
25
|
-
}
|
|
26
|
-
const comment = document.createComment(value);
|
|
27
|
-
anchor.after(comment);
|
|
28
|
-
return () => comment.remove();
|
|
29
|
-
});
|
|
30
|
-
return isClient ? id : null;
|
|
31
|
-
}
|
|
32
|
-
function useIsClient() {
|
|
33
|
-
return useSyncExternalStore(subscribe, getClientSnapshot, getServerSnapshot);
|
|
34
|
-
}
|
|
35
|
-
function subscribe() {
|
|
36
|
-
return () => {};
|
|
37
|
-
}
|
|
38
|
-
function getClientSnapshot() {
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
function getServerSnapshot() {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
function findTextNode(value) {
|
|
45
|
-
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
|
|
46
|
-
while (walker.nextNode()) {
|
|
47
|
-
const node = walker.currentNode;
|
|
48
|
-
if (node instanceof Text && node.data === value) return node;
|
|
49
|
-
}
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
//#endregion
|
|
53
|
-
export { SliceBoundary };
|
|
54
|
-
|
|
55
|
-
//# sourceMappingURL=SliceBoundary.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SliceBoundary.js","names":[],"sources":["../src/SliceBoundary.tsx"],"sourcesContent":["\"use client\"\n\nimport { type ReactNode, useId, useLayoutEffect, useRef, useSyncExternalStore } from \"react\"\n\ntype SliceBoundaryProps = {\n\tchildren: ReactNode\n\tsliceId: string\n}\n\nexport function SliceBoundary(props: SliceBoundaryProps): ReactNode {\n\tconst { children, sliceId } = props\n\n\treturn (\n\t\t<>\n\t\t\t<CommentMarker value={`prismic-slice-start:${sliceId}`} />\n\t\t\t{children}\n\t\t\t<CommentMarker value={`prismic-slice-end:${sliceId}`} />\n\t\t</>\n\t)\n}\n\ntype CommentMarkerProps = {\n\tvalue: string\n}\n\nfunction CommentMarker(props: CommentMarkerProps) {\n\tconst { value } = props\n\tconst id = useId()\n\tconst isClient = useIsClient()\n\tconst anchorRef = useRef<Text>(null)\n\n\tuseLayoutEffect(() => {\n\t\tlet anchor = anchorRef.current\n\n\t\tif (!anchor?.isConnected) {\n\t\t\tanchor = findTextNode(id)\n\t\t\tif (!anchor) return\n\n\t\t\tanchor.data = \"\"\n\t\t\tanchorRef.current = anchor\n\t\t}\n\n\t\tconst comment = document.createComment(value)\n\t\tanchor.after(comment)\n\n\t\treturn () => comment.remove()\n\t})\n\n\treturn isClient ? id : null\n}\n\nfunction useIsClient() {\n\treturn useSyncExternalStore(subscribe, getClientSnapshot, getServerSnapshot)\n}\n\nfunction subscribe() {\n\treturn () => {}\n}\n\nfunction getClientSnapshot() {\n\treturn true\n}\n\nfunction getServerSnapshot() {\n\treturn false\n}\n\nfunction findTextNode(value: string) {\n\tconst walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT)\n\n\twhile (walker.nextNode()) {\n\t\tconst node = walker.currentNode\n\t\tif (node instanceof Text && node.data === value) return node\n\t}\n\n\treturn null\n}\n"],"mappings":";;;;AASA,SAAgB,cAAc,OAAsC;CACnE,MAAM,EAAE,UAAU,YAAY;AAE9B,QACC,qBAAA,YAAA,EAAA,UAAA;EACC,oBAAC,eAAD,EAAe,OAAO,uBAAuB,WAAa,CAAA;EACzD;EACD,oBAAC,eAAD,EAAe,OAAO,qBAAqB,WAAa,CAAA;EACtD,EAAA,CAAA;;AAQL,SAAS,cAAc,OAA2B;CACjD,MAAM,EAAE,UAAU;CAClB,MAAM,KAAK,OAAO;CAClB,MAAM,WAAW,aAAa;CAC9B,MAAM,YAAY,OAAa,KAAK;AAEpC,uBAAsB;EACrB,IAAI,SAAS,UAAU;AAEvB,MAAI,CAAC,QAAQ,aAAa;AACzB,YAAS,aAAa,GAAG;AACzB,OAAI,CAAC,OAAQ;AAEb,UAAO,OAAO;AACd,aAAU,UAAU;;EAGrB,MAAM,UAAU,SAAS,cAAc,MAAM;AAC7C,SAAO,MAAM,QAAQ;AAErB,eAAa,QAAQ,QAAQ;GAC5B;AAEF,QAAO,WAAW,KAAK;;AAGxB,SAAS,cAAc;AACtB,QAAO,qBAAqB,WAAW,mBAAmB,kBAAkB;;AAG7E,SAAS,YAAY;AACpB,cAAa;;AAGd,SAAS,oBAAoB;AAC5B,QAAO;;AAGR,SAAS,oBAAoB;AAC5B,QAAO;;AAGR,SAAS,aAAa,OAAe;CACpC,MAAM,SAAS,SAAS,iBAAiB,SAAS,MAAM,WAAW,UAAU;AAE7E,QAAO,OAAO,UAAU,EAAE;EACzB,MAAM,OAAO,OAAO;AACpB,MAAI,gBAAgB,QAAQ,KAAK,SAAS,MAAO,QAAO;;AAGzD,QAAO"}
|
package/src/SliceBoundary.tsx
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
import { type ReactNode, useId, useLayoutEffect, useRef, useSyncExternalStore } from "react"
|
|
4
|
-
|
|
5
|
-
type SliceBoundaryProps = {
|
|
6
|
-
children: ReactNode
|
|
7
|
-
sliceId: string
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function SliceBoundary(props: SliceBoundaryProps): ReactNode {
|
|
11
|
-
const { children, sliceId } = props
|
|
12
|
-
|
|
13
|
-
return (
|
|
14
|
-
<>
|
|
15
|
-
<CommentMarker value={`prismic-slice-start:${sliceId}`} />
|
|
16
|
-
{children}
|
|
17
|
-
<CommentMarker value={`prismic-slice-end:${sliceId}`} />
|
|
18
|
-
</>
|
|
19
|
-
)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
type CommentMarkerProps = {
|
|
23
|
-
value: string
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function CommentMarker(props: CommentMarkerProps) {
|
|
27
|
-
const { value } = props
|
|
28
|
-
const id = useId()
|
|
29
|
-
const isClient = useIsClient()
|
|
30
|
-
const anchorRef = useRef<Text>(null)
|
|
31
|
-
|
|
32
|
-
useLayoutEffect(() => {
|
|
33
|
-
let anchor = anchorRef.current
|
|
34
|
-
|
|
35
|
-
if (!anchor?.isConnected) {
|
|
36
|
-
anchor = findTextNode(id)
|
|
37
|
-
if (!anchor) return
|
|
38
|
-
|
|
39
|
-
anchor.data = ""
|
|
40
|
-
anchorRef.current = anchor
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const comment = document.createComment(value)
|
|
44
|
-
anchor.after(comment)
|
|
45
|
-
|
|
46
|
-
return () => comment.remove()
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
return isClient ? id : null
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function useIsClient() {
|
|
53
|
-
return useSyncExternalStore(subscribe, getClientSnapshot, getServerSnapshot)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function subscribe() {
|
|
57
|
-
return () => {}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function getClientSnapshot() {
|
|
61
|
-
return true
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function getServerSnapshot() {
|
|
65
|
-
return false
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function findTextNode(value: string) {
|
|
69
|
-
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT)
|
|
70
|
-
|
|
71
|
-
while (walker.nextNode()) {
|
|
72
|
-
const node = walker.currentNode
|
|
73
|
-
if (node instanceof Text && node.data === value) return node
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return null
|
|
77
|
-
}
|