@prismicio/react 3.4.0-pr.257.5417830 → 3.4.0-pr.257.68f2f80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/PrismicImage.d.ts +17 -22
  2. package/dist/PrismicImage.d.ts.map +1 -1
  3. package/dist/PrismicImage.js +4 -5
  4. package/dist/PrismicImage.js.map +1 -1
  5. package/dist/PrismicLink.d.ts +17 -19
  6. package/dist/PrismicLink.d.ts.map +1 -1
  7. package/dist/PrismicLink.js +4 -6
  8. package/dist/PrismicLink.js.map +1 -1
  9. package/dist/PrismicRichText.d.ts +30 -34
  10. package/dist/PrismicRichText.d.ts.map +1 -1
  11. package/dist/PrismicRichText.js +4 -5
  12. package/dist/PrismicRichText.js.map +1 -1
  13. package/dist/PrismicTable.d.ts +14 -14
  14. package/dist/PrismicTable.d.ts.map +1 -1
  15. package/dist/PrismicTable.js +3 -4
  16. package/dist/PrismicTable.js.map +1 -1
  17. package/dist/PrismicText.d.ts +6 -7
  18. package/dist/PrismicText.d.ts.map +1 -1
  19. package/dist/PrismicText.js +3 -4
  20. package/dist/PrismicText.js.map +1 -1
  21. package/dist/PrismicToolbar.d.ts +11 -14
  22. package/dist/PrismicToolbar.d.ts.map +1 -1
  23. package/dist/PrismicToolbar.js +4 -5
  24. package/dist/PrismicToolbar.js.map +1 -1
  25. package/dist/SliceZone.d.ts +27 -40
  26. package/dist/SliceZone.d.ts.map +1 -1
  27. package/dist/SliceZone.js +6 -8
  28. package/dist/SliceZone.js.map +1 -1
  29. package/dist/lib/devMsg.js +6 -8
  30. package/dist/lib/devMsg.js.map +1 -1
  31. package/dist/package.js +1 -1
  32. package/package.json +27 -29
  33. package/src/PrismicImage.tsx +95 -122
  34. package/src/PrismicLink.tsx +28 -38
  35. package/src/PrismicRichText.tsx +41 -49
  36. package/src/PrismicTable.tsx +15 -19
  37. package/src/PrismicText.tsx +6 -7
  38. package/src/PrismicToolbar.tsx +12 -16
  39. package/src/SliceZone.tsx +36 -76
  40. package/src/lib/devMsg.ts +6 -8
@@ -1,13 +1,13 @@
1
- import { FC } from "react";
2
1
  import { RichTextField } from "@prismicio/client";
2
+ import { FC } from "react";
3
3
 
4
4
  //#region src/PrismicText.d.ts
5
5
  /** Props for `<PrismicText>`. */
6
6
  type PrismicTextProps = {
7
7
  /** The Prismic rich text field to render. */field: RichTextField | null | undefined;
8
8
  /**
9
- * The string rendered when the field is empty. If a fallback is not given,
10
- * `null` will be rendered.
9
+ * The string rendered when the field is empty. If a fallback is not given, `null` will be
10
+ * rendered.
11
11
  */
12
12
  fallback?: string; /** The separator used between blocks. Defaults to `\n`. */
13
13
  separator?: string;
@@ -16,10 +16,9 @@ type PrismicTextProps = {
16
16
  * Renders content from a Prismic rich text field as plain text (no HTML).
17
17
  *
18
18
  * @example
19
- *
20
- * ```tsx
21
- * <PrismicText field={slice.primary.text} />;
22
- * ```
19
+ * ```tsx
20
+ * <PrismicText field={slice.primary.text} />;
21
+ * ```
23
22
  *
24
23
  * @see Learn how to display rich text as plain text or React components: {@link https://prismic.io/docs/fields/rich-text}
25
24
  */
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicText.d.ts","names":[],"sources":["../src/PrismicText.tsx"],"mappings":";;;;;KAOY,gBAAA;EAAA,6CAEX,KAAA,EAAO,aAAA;;;;;EAMP,QAAA,WAGA;EAAA,SAAA;AAAA;AAcD;;;;;;;;;;;AAAA,cAAa,WAAA,EAAa,EAAA,CAAG,gBAAA"}
1
+ {"version":3,"file":"PrismicText.d.ts","names":[],"sources":["../src/PrismicText.tsx"],"mappings":";;;;;KAOY,gBAAA;EAAA,6CAEX,KAAA,EAAO,aAAA;;;;;EAMP,QAAA,WAGA;EAAA,SAAA;AAAA;AAaD;;;;;;;;;;AAAA,cAAa,WAAA,EAAa,EAAA,CAAG,gBAAA"}
@@ -7,10 +7,9 @@ import { Fragment, jsx } from "react/jsx-runtime";
7
7
  * Renders content from a Prismic rich text field as plain text (no HTML).
8
8
  *
9
9
  * @example
10
- *
11
- * ```tsx
12
- * <PrismicText field={slice.primary.text} />;
13
- * ```
10
+ * ```tsx
11
+ * <PrismicText field={slice.primary.text} />;
12
+ * ```
14
13
  *
15
14
  * @see Learn how to display rich text as plain text or React components: {@link https://prismic.io/docs/fields/rich-text}
16
15
  */
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicText.js","names":[],"sources":["../src/PrismicText.tsx"],"sourcesContent":["import type { FC } from \"react\";\nimport { asText, isFilled, type RichTextField } from \"@prismicio/client\";\nimport { DEV } from \"esm-env\";\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,\n\t * `null` will be 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 *\n * ```tsx\n * <PrismicText field={slice.primary.text} />;\n * ```\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":";;;;;;;;;;;;;;;;AAgCA,MAAa,eAAqC,UAAU;CAC3D,MAAM,EAAE,OAAO,UAAU,cAAc;AAEvC,KAAI;MACC,eAAe,MAClB,SAAQ,KACP,6IAA6I,OAC5I,gCACA,CAAC,IACF,MAAM,MACN;;AAIH,KAAI,OAAO,MAAM,UAAU,UAAU;AACpC,MAAI,IACH,SAAQ,MACP,2QAA2Q,OAC1Q,yDACA,IACD,MAAM,MACN;AAGF,SAAO;;AAGR,KAAI,CAAC,SAAS,SAAS,MAAM,CAC5B,QAAO,YAAY,OAAO,oBAAA,UAAA,EAAA,UAAG,UAAY,CAAA,GAAG;AAG7C,QAAO,oBAAA,UAAA,EAAA,UAAG,OAAO,OAAO,EAAE,WAAW,CAAC,EAAI,CAAA"}
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;AAEvC,KAAI;MACC,eAAe,MAClB,SAAQ,KACP,6IAA6I,OAC5I,gCACA,CAAC,IACF,MAAM,MACN;;AAIH,KAAI,OAAO,MAAM,UAAU,UAAU;AACpC,MAAI,IACH,SAAQ,MACP,2QAA2Q,OAC1Q,yDACA,IACD,MAAM,MACN;AAGF,SAAO;;AAGR,KAAI,CAAC,SAAS,SAAS,MAAM,CAC5B,QAAO,YAAY,OAAO,oBAAA,UAAA,EAAA,UAAG,UAAY,CAAA,GAAG;AAG7C,QAAO,oBAAA,UAAA,EAAA,UAAG,OAAO,OAAO,EAAE,WAAW,CAAC,EAAI,CAAA"}
@@ -4,28 +4,26 @@ import { FC } from "react";
4
4
  /** Props for `<PrismicToolbar>`. */
5
5
  type PrismicToolbarProps = {
6
6
  /**
7
- * The name of the Prismic repository. For example, `"my-repo"` if the
8
- * repository URL is `my-repo.prismic.io`.
7
+ * The name of the Prismic repository. For example, `"my-repo"` if the repository URL is
8
+ * `my-repo.prismic.io`.
9
9
  */
10
10
  repositoryName: string;
11
11
  /**
12
- * Called when the Prismic toolbar triggers a preview update. This happens
13
- * when the previewed content changes.
12
+ * Called when the Prismic toolbar triggers a preview update. This happens when the previewed
13
+ * content changes.
14
14
  *
15
15
  * The new ref can be read from `event.detail.ref`.
16
16
  *
17
- * The default page reload behavior can be cancelled with
18
- * `event.preventDefault()`.
17
+ * The default page reload behavior can be cancelled with `event.preventDefault()`.
19
18
  */
20
19
  onPreviewUpdate?: (event: CustomEvent<{
21
20
  ref: string;
22
21
  }>) => void;
23
22
  /**
24
- * Called when the Prismic toolbar triggers a preview end. This happens when
25
- * a preview session is closed.
23
+ * Called when the Prismic toolbar triggers a preview end. This happens when a preview session is
24
+ * closed.
26
25
  *
27
- * The default page reload behavior can be cancelled with
28
- * `event.preventDefault()`.
26
+ * The default page reload behavior can be cancelled with `event.preventDefault()`.
29
27
  */
30
28
  onPreviewEnd?: (event: CustomEvent<null>) => void;
31
29
  };
@@ -33,10 +31,9 @@ type PrismicToolbarProps = {
33
31
  * Renders the Prismic Toolbar script to support draft previews.
34
32
  *
35
33
  * @example
36
- *
37
- * ```tsx
38
- * <PrismicToolbar repositoryName="my-repo" />;
39
- * ```
34
+ * ```tsx
35
+ * <PrismicToolbar repositoryName="my-repo" />;
36
+ * ```
40
37
  *
41
38
  * @see Learn how to set up preview functionality and the toolbar's role in preview sessions: {@link https://prismic.io/docs/previews}
42
39
  */
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicToolbar.d.ts","names":[],"sources":["../src/PrismicToolbar.tsx"],"mappings":";;;;KAMY,mBAAA;EAAA;;;;EAKX,cAAA;EAWA;;;;;;;;;EAAA,eAAA,IAAmB,KAAA,EAAO,WAAA;IAAc,GAAA;EAAA;EAuBZ;;;;;;;EAd5B,YAAA,IAAgB,KAAA,EAAO,WAAA;AAAA;;;;;;;;;;;;cAcX,cAAA,EAAgB,EAAA,CAAG,mBAAA"}
1
+ {"version":3,"file":"PrismicToolbar.d.ts","names":[],"sources":["../src/PrismicToolbar.tsx"],"mappings":";;;;KAMY,mBAAA;EAAA;;;;EAKX,cAAA;EAUA;;;;;;;;EAAA,eAAA,IAAmB,KAAA,EAAO,WAAA;IAAc,GAAA;EAAA;;;;;;;EAQxC,YAAA,IAAgB,KAAA,EAAO,WAAA;AAAA;;;;;;;;;;;cAaX,cAAA,EAAgB,EAAA,CAAG,mBAAA"}
@@ -1,15 +1,14 @@
1
1
  "use client";
2
- import { useEffect, useRef } from "react";
3
2
  import { getToolbarSrc } from "@prismicio/client";
3
+ import { useEffect, useRef } from "react";
4
4
  //#region src/PrismicToolbar.tsx
5
5
  /**
6
6
  * Renders the Prismic Toolbar script to support draft previews.
7
7
  *
8
8
  * @example
9
- *
10
- * ```tsx
11
- * <PrismicToolbar repositoryName="my-repo" />;
12
- * ```
9
+ * ```tsx
10
+ * <PrismicToolbar repositoryName="my-repo" />;
11
+ * ```
13
12
  *
14
13
  * @see Learn how to set up preview functionality and the toolbar's role in preview sessions: {@link https://prismic.io/docs/previews}
15
14
  */
@@ -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\n\t * repository URL is `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\n\t * when the previewed 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\n\t * `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\n\t * a preview session is closed.\n\t *\n\t * The default page reload behavior can be cancelled with\n\t * `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 *\n * ```tsx\n * <PrismicToolbar repositoryName=\"my-repo\" />;\n * ```\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\tonPreviewUpdateRef.current = onPreviewUpdate;\n\n\tconst onPreviewEndRef = useRef(onPreviewEnd);\n\tonPreviewEndRef.current = onPreviewEnd;\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) =>\n\t\t\t\tonPreviewUpdateRef.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":";;;;;;;;;;;;;;;AA6CA,MAAa,kBAA2C,UAAU;CACjE,MAAM,EAAE,gBAAgB,iBAAiB,iBAAiB;CAE1D,MAAM,MAAM,cAAc,eAAe;CAEzC,MAAM,qBAAqB,OAAO,gBAAgB;AAClD,oBAAmB,UAAU;CAE7B,MAAM,kBAAkB,OAAO,aAAa;AAC5C,iBAAgB,UAAU;AAE1B,iBAAgB;AAGf,MAAI,CAFmB,SAAS,cAAc,eAAe,IAAI,IAAI,EAEhD;GACpB,MAAM,SAAS,SAAS,cAAc,SAAS;AAC/C,UAAO,MAAM;AACb,UAAO,QAAQ;AAGf,UAAO,QAAQ,iBAAiB;AAChC,UAAO,QAAQ,iBAAiB;AAIhC,UAAO,kBAAkB;AAEzB,YAAS,KAAK,YAAY,OAAO;;IAEhC,CAAC,gBAAgB,IAAI,CAAC;AAEzB,iBAAgB;EACf,MAAM,aAAa,IAAI,iBAAiB;AAExC,SAAO,iBACN,yBACC,UACA,mBAAmB,UAAU,MAAsC,EACpE,EAAE,QAAQ,WAAW,QAAQ,CAC7B;AAED,SAAO,iBACN,sBACC,UAAU,gBAAgB,UAAU,MAA2B,EAChE,EAAE,QAAQ,WAAW,QAAQ,CAC7B;AAED,eAAa,WAAW,OAAO;IAC7B,EAAE,CAAC;AAEN,QAAO"}
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\tonPreviewUpdateRef.current = onPreviewUpdate;\n\n\tconst onPreviewEndRef = useRef(onPreviewEnd);\n\tonPreviewEndRef.current = onPreviewEnd;\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,eAAe;CAEzC,MAAM,qBAAqB,OAAO,gBAAgB;AAClD,oBAAmB,UAAU;CAE7B,MAAM,kBAAkB,OAAO,aAAa;AAC5C,iBAAgB,UAAU;AAE1B,iBAAgB;AAGf,MAAI,CAFmB,SAAS,cAAc,eAAe,IAAI,IAAI,EAEhD;GACpB,MAAM,SAAS,SAAS,cAAc,SAAS;AAC/C,UAAO,MAAM;AACb,UAAO,QAAQ;AAGf,UAAO,QAAQ,iBAAiB;AAChC,UAAO,QAAQ,iBAAiB;AAIhC,UAAO,kBAAkB;AAEzB,YAAS,KAAK,YAAY,OAAO;;IAEhC,CAAC,gBAAgB,IAAI,CAAC;AAEzB,iBAAgB;EACf,MAAM,aAAa,IAAI,iBAAiB;AAExC,SAAO,iBACN,yBACC,UAAU,mBAAmB,UAAU,MAAsC,EAC9E,EAAE,QAAQ,WAAW,QAAQ,CAC7B;AAED,SAAO,iBACN,sBACC,UAAU,gBAAgB,UAAU,MAA2B,EAChE,EAAE,QAAQ,WAAW,QAAQ,CAC7B;AAED,eAAa,WAAW,OAAO;IAC7B,EAAE,CAAC;AAEN,QAAO"}
@@ -1,5 +1,5 @@
1
- import { ComponentType, FC, ReactNode } from "react";
2
1
  import { Slice } from "@prismicio/client";
2
+ import { ComponentType, FC, ReactNode } from "react";
3
3
 
4
4
  //#region src/SliceZone.d.ts
5
5
  /**
@@ -9,15 +9,15 @@ import { Slice } from "@prismicio/client";
9
9
  */
10
10
  type ExtractSliceType<TSlice extends SliceLike> = TSlice extends Slice ? TSlice["slice_type"] : TSlice extends SliceLikeGraphQL ? TSlice["type"] : never;
11
11
  /**
12
- * The minimum required properties to represent a Prismic slice from the Prismic
13
- * Content API for the `mapSliceZone()` helper.
12
+ * The minimum required properties to represent a Prismic slice from the Prismic Content API for the
13
+ * `mapSliceZone()` helper.
14
14
  *
15
15
  * @typeParam SliceType - Type name of the slice.
16
16
  */
17
17
  type SliceLikeRestV2<TSliceType extends string = string> = Pick<Slice<TSliceType>, "id" | "slice_type">;
18
18
  /**
19
- * The minimum required properties to represent a Prismic slice from the Prismic
20
- * GraphQL API for the `mapSliceZone()` helper.
19
+ * The minimum required properties to represent a Prismic slice from the Prismic GraphQL API for the
20
+ * `mapSliceZone()` helper.
21
21
  *
22
22
  * @typeParam SliceType - Type name of the slice.
23
23
  */
@@ -25,49 +25,43 @@ type SliceLikeGraphQL<TSliceType extends string = string> = {
25
25
  type: Slice<TSliceType>["slice_type"];
26
26
  };
27
27
  /**
28
- * The minimum required properties to represent a Prismic slice for the
29
- * `mapSliceZone()` helper.
28
+ * The minimum required properties to represent a Prismic slice for the `mapSliceZone()` helper.
30
29
  *
31
- * If using Prismic's Content API, use the `Slice` export from
32
- * `@prismicio/client` for a full interface.
30
+ * If using Prismic's Content API, use the `Slice` export from `@prismicio/client` for a full
31
+ * interface.
33
32
  *
34
33
  * @typeParam SliceType - Type name of the slice.
35
34
  */
36
35
  type SliceLike<TSliceType extends string = string> = (SliceLikeRestV2<TSliceType> | SliceLikeGraphQL<TSliceType>) & {
37
36
  /**
38
- * If `true`, this slice has been modified from its original value using a
39
- * mapper and `@prismicio/client`'s `mapSliceZone()`.
37
+ * If `true`, this slice has been modified from its original value using a mapper and
38
+ * `@prismicio/client`'s `mapSliceZone()`.
40
39
  *
41
40
  * @internal
42
41
  */
43
42
  __mapped?: true;
44
43
  };
45
44
  /**
46
- * A looser version of the `SliceZone` type from `@prismicio/client` using
47
- * `SliceLike`.
45
+ * A looser version of the `SliceZone` type from `@prismicio/client` using `SliceLike`.
48
46
  *
49
- * If using Prismic's Content API, use the `SliceZone` export from
50
- * `@prismicio/client` for the full type.
47
+ * If using Prismic's Content API, use the `SliceZone` export from `@prismicio/client` for the full
48
+ * type.
51
49
  *
52
50
  * @typeParam TSlice - The type(s) of a slice in the slice zone.
53
51
  */
54
52
  type SliceZoneLike<TSlice extends SliceLike = SliceLike> = readonly TSlice[];
55
53
  /**
56
- * React props for a component rendering content from a Prismic slice using the
57
- * `<SliceZone>` component.
54
+ * React props for a component rendering content from a Prismic slice using the `<SliceZone>`
55
+ * component.
58
56
  *
59
57
  * @typeParam TSlice - The slice passed as a prop.
60
- * @typeParam TContext - Arbitrary data passed to `<SliceZone>` and made
61
- * available to all slice components.
58
+ * @typeParam TContext - Arbitrary data passed to `<SliceZone>` and made available to all slice
59
+ * components.
62
60
  */
63
61
  type SliceComponentProps<TSlice extends SliceLike = SliceLike, TContext = unknown> = {
64
62
  /** Slice data for this component. */slice: TSlice; /** The index of the slice in the slice zone. */
65
63
  index: number; /** All slices from the slice zone to which the slice belongs. */
66
- slices: SliceZoneLike<TSlice extends SliceLikeGraphQL ? SliceLikeGraphQL : SliceLikeRestV2>;
67
- /**
68
- * Arbitrary data passed to `<SliceZone>` and made available to all slice
69
- * components.
70
- */
64
+ slices: SliceZoneLike<TSlice extends SliceLikeGraphQL ? SliceLikeGraphQL : SliceLikeRestV2>; /** Arbitrary data passed to `<SliceZone>` and made available to all slice components. */
71
65
  context: TContext;
72
66
  };
73
67
  /**
@@ -78,12 +72,11 @@ type SliceComponentProps<TSlice extends SliceLike = SliceLike, TContext = unknow
78
72
  */
79
73
  type SliceComponentType<TSlice extends SliceLike = any, TContext = unknown> = ComponentType<SliceComponentProps<TSlice, TContext>>;
80
74
  /**
81
- * A record of slice types mapped to a React component. The component will be
82
- * rendered for each instance of its slice.
75
+ * A record of slice types mapped to a React component. The component will be rendered for each
76
+ * instance of its slice.
83
77
  *
84
78
  * @deprecated This type is no longer used by `@prismicio/react`. Prefer using
85
79
  * `Record<string, SliceComponentType<any>>` instead.
86
- *
87
80
  * @typeParam TSlice - The type(s) of a slice in the slice zone.
88
81
  * @typeParam TContext - Arbitrary data made available to all slice components.
89
82
  */
@@ -96,20 +89,15 @@ type SliceZoneComponents<TSlice extends SliceLike = SliceLike, TContext = unknow
96
89
  */
97
90
  type SliceZoneProps<TContext = unknown> = {
98
91
  /** List of slice data from the slice zone. */slices?: SliceZoneLike; /** A record mapping slice types to React components. */
99
- components?: Record<string, ComponentType<any>>;
100
- /**
101
- * The React component rendered if a component mapping from the `components`
102
- * prop cannot be found.
103
- */
92
+ components?: Record<string, ComponentType<any>>; /** The React component rendered if a component mapping from the `components` prop cannot be found. */
104
93
  defaultComponent?: ComponentType<SliceComponentProps<any, TContext>>; /** Arbitrary data made available to all slice components. */
105
94
  context?: TContext;
106
95
  };
107
96
  /**
108
- * This slice component can be used as a reminder to provide a proper
109
- * implementation.
97
+ * This slice component can be used as a reminder to provide a proper implementation.
110
98
  *
111
- * This is also the default React component rendered when a component mapping
112
- * cannot be found in `<SliceZone>`.
99
+ * This is also the default React component rendered when a component mapping cannot be found in
100
+ * `<SliceZone>`.
113
101
  */
114
102
  declare const TODOSliceComponent: <TSlice extends SliceLike>({
115
103
  slice
@@ -120,10 +108,9 @@ declare const TODOSliceComponent: <TSlice extends SliceLike>({
120
108
  * Renders slices in a slice zone as React components.
121
109
  *
122
110
  * @example
123
- *
124
- * ```tsx
125
- * <SliceZone slices={page.data.slices} components={components} />;
126
- * ```
111
+ * ```tsx
112
+ * <SliceZone slices={page.data.slices} components={components} />;
113
+ * ```
127
114
  *
128
115
  * @see Learn how to create slices, use slice variations, and display slices: {@link https://prismic.io/docs/slices}
129
116
  */
@@ -1 +1 @@
1
- {"version":3,"file":"SliceZone.d.ts","names":[],"sources":["../src/SliceZone.tsx"],"mappings":";;;;;;AAC+C;;;KAQ1C,gBAAA,gBAAgC,SAAA,IAAa,MAAA,SAAe,KAAA,GAC9D,MAAA,iBACA,MAAA,SAAe,gBAAA,GACd,MAAA;;;;;;;KASQ,eAAA,uCAAsD,IAAA,CACjE,KAAA,CAAM,UAAA;;;;;;;KAUK,gBAAA;EACX,IAAA,EAAM,KAAA,CAAM,UAAA;AAAA;;;AAZb;;;;;;;KAwBY,SAAA,wCACT,eAAA,CAAgB,UAAA,IAChB,gBAAA,CAAiB,UAAA;EA1BQ;;;;;;EAkC3B,QAAA;AAAA;;;;;;;;;AAVD;KAsBY,aAAA,gBAA6B,SAAA,GAAY,SAAA,aAC3C,MAAA;;;;;;;;;KAUE,mBAAA,gBACI,SAAA,GAAY,SAAA;EAjCT,qCAqClB,KAAA,EAAO,MAAA,EApCY;EAuCnB,KAAA,UA/BQ;EAsCR,MAAA,EAAQ,aAAA,CACP,MAAA,SAAe,gBAAA,GAAmB,gBAAA,GAAmB,eAAA;EA3B3C;;;;EAkCX,OAAA,EAAS,QAAA;AAAA;;;;;;;KASE,kBAAA,gBAEI,SAAA,8BAEZ,aAAA,CAAc,mBAAA,CAAoB,MAAA,EAAQ,QAAA;;AApC9C;;;;;;;;;KAgDY,mBAAA,gBACI,SAAA,GAAY,SAAA,wCAaZ,gBAAA,CAAiB,MAAA,IAAU,kBAAA,CACxC,OAAA,CAAQ,MAAA,EAAQ,SAAA,CAAU,SAAA,mBACvB,SAAA,GACA,OAAA,CAAQ,MAAA,EAAQ,SAAA,CAAU,SAAA,IAC7B,QAAA;;;;;;;KAUS,cAAA;EAvEJ,8CAyEP,MAAA,GAAS,aAAA,EA/DT;EAmEA,UAAA,GAAa,MAAA,SAAe,aAAA;EAlE3B;;;;EAyED,gBAAA,GAAmB,aAAA,CAAc,mBAAA,MAAyB,QAAA,IAlEjD;EAqET,OAAA,GAAU,QAAA;AAAA;AA5DX;;;;;;;AAAA,cAsEa,kBAAA,kBAAqC,SAAA;EAAW;AAAA;EAG5D,KAAA,EAAO,MAAA;AAAA,MACJ,SAAA;;;;;;;;;;AA1DJ;;cAyFa,SAAA,EAAW,EAAA,CAAG,cAAA"}
1
+ {"version":3,"file":"SliceZone.d.ts","names":[],"sources":["../src/SliceZone.tsx"],"mappings":";;;;;;AAE0D;;;KAOrD,gBAAA,gBAAgC,SAAA,IAAa,MAAA,SAAe,KAAA,GAC9D,MAAA,iBACA,MAAA,SAAe,gBAAA,GACd,MAAA;;;;;;;KASQ,eAAA,uCAAsD,IAAA,CACjE,KAAA,CAAM,UAAA;;;;;;;KAUK,gBAAA;EACX,IAAA,EAAM,KAAA,CAAM,UAAA;AAAA;;;AAZb;;;;;;KAuBY,SAAA,wCACT,eAAA,CAAgB,UAAA,IAChB,gBAAA,CAAiB,UAAA;EAzBkD;;;;;;EAiCrE,QAAA;AAAA;;;;;;;;;KAWW,aAAA,gBAA6B,SAAA,GAAY,SAAA,aAAsB,MAAA;AArB3E;;;;;;;;AAAA,KA+BY,mBAAA,gBAAmC,SAAA,GAAY,SAAA;EA/BrC,qCAiCrB,KAAA,EAAO,MAAA,EAhCW;EAmClB,KAAA,UAlCmB;EAyCnB,MAAA,EAAQ,aAAA,CAAc,MAAA,SAAe,gBAAA,GAAmB,gBAAA,GAAmB,eAAA,GAjCnE;EAoCR,OAAA,EAAS,QAAA;AAAA;;;;;;;KASE,kBAAA,gBAEI,SAAA,8BAEZ,aAAA,CAAc,mBAAA,CAAoB,MAAA,EAAQ,QAAA;;;;;;;AA5B9C;;;KAuCY,mBAAA,gBAAmC,SAAA,GAAY,SAAA,wCAW3C,gBAAA,CAAiB,MAAA,IAAU,kBAAA,CACxC,OAAA,CAAQ,MAAA,EAAQ,SAAA,CAAU,SAAA,mBACvB,SAAA,GACA,OAAA,CAAQ,MAAA,EAAQ,SAAA,CAAU,SAAA,IAC7B,QAAA;;;;;;;KAUS,cAAA;EAjDM,8CAmDjB,MAAA,GAAS,aAAA,EAlEqC;EAsE9C,UAAA,GAAa,MAAA,SAAe,aAAA,QAtEyC;EA0ErE,gBAAA,GAAmB,aAAA,CAAc,mBAAA,MAAyB,QAAA,IAxEnD;EA2EP,OAAA,GAAU,QAAA;AAAA;;;;;;;cASE,kBAAA,kBAAqC,SAAA;EAAW;AAAA;EAG5D,KAAA,EAAO,MAAA;AAAA,MACJ,SAAA;AAlEJ;;;;;;;;;;AAAA,cA6Fa,SAAA,EAAW,EAAA,CAAG,cAAA"}
package/dist/SliceZone.js CHANGED
@@ -2,11 +2,10 @@ import { DEV } from "esm-env";
2
2
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
3
  //#region src/SliceZone.tsx
4
4
  /**
5
- * This slice component can be used as a reminder to provide a proper
6
- * implementation.
5
+ * This slice component can be used as a reminder to provide a proper implementation.
7
6
  *
8
- * This is also the default React component rendered when a component mapping
9
- * cannot be found in `<SliceZone>`.
7
+ * This is also the default React component rendered when a component mapping cannot be found in
8
+ * `<SliceZone>`.
10
9
  */
11
10
  const TODOSliceComponent = ({ slice }) => {
12
11
  if (!DEV) return null;
@@ -26,10 +25,9 @@ const TODOSliceComponent = ({ slice }) => {
26
25
  * Renders slices in a slice zone as React components.
27
26
  *
28
27
  * @example
29
- *
30
- * ```tsx
31
- * <SliceZone slices={page.data.slices} components={components} />;
32
- * ```
28
+ * ```tsx
29
+ * <SliceZone slices={page.data.slices} components={components} />;
30
+ * ```
33
31
  *
34
32
  * @see Learn how to create slices, use slice variations, and display slices: {@link https://prismic.io/docs/slices}
35
33
  */
@@ -1 +1 @@
1
- {"version":3,"file":"SliceZone.js","names":[],"sources":["../src/SliceZone.tsx"],"sourcesContent":["import type { ComponentType, FC, ReactNode } from \"react\";\nimport type { Slice } from \"@prismicio/client\";\nimport { DEV } from \"esm-env\";\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\n * Content API for the `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\n * GraphQL API for the `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\n * `mapSliceZone()` helper.\n *\n * If using Prismic's Content API, use the `Slice` export from\n * `@prismicio/client` for a full 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\n\t * mapper and `@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\n * `SliceLike`.\n *\n * If using Prismic's Content API, use the `SliceZone` export from\n * `@prismicio/client` for the full type.\n *\n * @typeParam TSlice - The type(s) of a slice in the slice zone.\n */\nexport type SliceZoneLike<TSlice extends SliceLike = SliceLike> =\n\treadonly TSlice[];\n\n/**\n * React props for a component rendering content from a Prismic slice using the\n * `<SliceZone>` component.\n *\n * @typeParam TSlice - The slice passed as a prop.\n * @typeParam TContext - Arbitrary data passed to `<SliceZone>` and made\n * available to all slice components.\n */\nexport type SliceComponentProps<\n\tTSlice extends SliceLike = SliceLike,\n\tTContext = unknown,\n> = {\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<\n\t\tTSlice extends SliceLikeGraphQL ? SliceLikeGraphQL : SliceLikeRestV2\n\t>;\n\n\t/**\n\t * Arbitrary data passed to `<SliceZone>` and made available to all slice\n\t * components.\n\t */\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\n * rendered for each 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 *\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<\n\tTSlice extends SliceLike = SliceLike,\n\tTContext = unknown,\n> =\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/**\n\t * The React component rendered if a component mapping from the `components`\n\t * prop cannot be found.\n\t */\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\n * implementation.\n *\n * This is also the default React component rendered when a component mapping\n * cannot be found in `<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(\n\t\t`[SliceZone] Could not find a component for slice type \"${type}\"`,\n\t\tslice,\n\t);\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 &ldquo;{type}\n\t\t\t&rdquo;\n\t\t</section>\n\t);\n};\n\n/**\n * Renders slices in a slice zone as React components.\n *\n * @example\n *\n * ```tsx\n * <SliceZone slices={page.data.slices} components={components} />;\n * ```\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 {\n\t\tslices = [],\n\t\tcomponents = {},\n\t\tdefaultComponent,\n\t\tcontext = {},\n\t} = 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 =\n\t\t\t\"id\" in slice && slice.id\n\t\t\t\t? slice.id\n\t\t\t\t: `${index}-${JSON.stringify(slice)}`;\n\n\t\tconst Comp =\n\t\t\tcomponents[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 (\n\t\t\t<Comp\n\t\t\t\tkey={key}\n\t\t\t\tslice={slice}\n\t\t\t\tindex={index}\n\t\t\t\tslices={slices}\n\t\t\t\tcontext={context}\n\t\t\t/>\n\t\t);\n\t});\n\n\treturn <>{renderedSlices}</>;\n};\n"],"mappings":";;;;;;;;;;AAoLA,MAAa,sBAAgD,EAC5D,YAGgB;AAChB,KAAI,CAAC,IACJ,QAAO;CAGR,MAAM,OAAO,gBAAgB,QAAQ,MAAM,aAAa,MAAM;AAE9D,SAAQ,KACP,0DAA0D,KAAK,IAC/D,MACA;AAED,QACC,qBAAC,WAAD;EAAS,kCAA+B;EAAG,mBAAiB;YAA5D;GAAkE;GACf;GAAK;GAE9C;;;;;;;;;;;;;;AAeZ,MAAa,aAAiC,UAAU;CACvD,MAAM,EACL,SAAS,EAAE,EACX,aAAa,EAAE,EACf,kBACA,UAAU,EAAE,KACT;AAkCJ,QAAO,oBAAA,UAAA,EAAA,UAhCgB,OAAO,KAAK,OAAO,UAAU;EACnD,MAAM,OAAO,gBAAgB,QAAQ,MAAM,aAAa,MAAM;EAE9D,MAAM,MACL,QAAQ,SAAS,MAAM,KACpB,MAAM,KACN,GAAG,MAAM,GAAG,KAAK,UAAU,MAAM;EAErC,MAAM,OACL,WAAW,SAAoC;AAEhD,MAAI,CAAC,KACJ,QAAO,oBAAC,oBAAD,EAAqC,OAAS,EAArB,IAAqB;AAGtD,MAAI,MAAM,UAAU;GACnB,MAAM,EAAE,UAAU,GAAG,gBAAgB;AAErC,UAAO,oBAAC,MAAD,EAAgB,GAAI,aAAe,EAAxB,IAAwB;;AAG3C,SACC,oBAAC,MAAD;GAEQ;GACA;GACC;GACC;GACR,EALI,IAKJ;GAEF,EAE0B,CAAA"}
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 &ldquo;{type}\n\t\t\t&rdquo;\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;AAChB,KAAI,CAAC,IACJ,QAAO;CAGR,MAAM,OAAO,gBAAgB,QAAQ,MAAM,aAAa,MAAM;AAE9D,SAAQ,KAAK,0DAA0D,KAAK,IAAI,MAAM;AAEtF,QACC,qBAAC,WAAD;EAAS,kCAA+B;EAAG,mBAAiB;YAA5D;GAAkE;GACf;GAAK;GAE9C;;;;;;;;;;;;;AAcZ,MAAa,aAAiC,UAAU;CACvD,MAAM,EAAE,SAAS,EAAE,EAAE,aAAa,EAAE,EAAE,kBAAkB,UAAU,EAAE,KAAK;AAsBzE,QAAO,oBAAA,UAAA,EAAA,UApBgB,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,MAAM;EAEpF,MAAM,OAAO,WAAW,SAAoC;AAE5D,MAAI,CAAC,KACJ,QAAO,oBAAC,oBAAD,EAAqC,OAAS,EAArB,IAAqB;AAGtD,MAAI,MAAM,UAAU;GACnB,MAAM,EAAE,UAAU,GAAG,gBAAgB;AAErC,UAAO,oBAAC,MAAD,EAAgB,GAAI,aAAe,EAAxB,IAAwB;;AAG3C,SAAO,oBAAC,MAAD;GAAuB;GAAc;GAAe;GAAiB;GAAW,EAArE,IAAqE;GACtF,EAE0B,CAAA"}
@@ -4,15 +4,13 @@ import { version } from "../package.js";
4
4
  * Returns a `prismic.dev/msg` URL for a given message slug.
5
5
  *
6
6
  * @example
7
+ * ```ts
8
+ * devMsg("missing-param");
9
+ * // => "https://prismic.dev/msg/react/v1.2.3/missing-param"
10
+ * ```
7
11
  *
8
- * ```ts
9
- * devMsg("missing-param");
10
- * // => "https://prismic.dev/msg/react/v1.2.3/missing-param"
11
- * ```
12
- *
13
- * @param slug - Slug for the message. This corresponds to a Markdown file in
14
- * the Git repository's `/messages` directory.
15
- *
12
+ * @param slug - Slug for the message. This corresponds to a Markdown file in the Git repository's
13
+ * `/messages` directory.
16
14
  * @returns The `prismic.dev/msg` URL for the given slug.
17
15
  */
18
16
  function devMsg(slug) {
@@ -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 *\n * ```ts\n * devMsg(\"missing-param\");\n * // => \"https://prismic.dev/msg/react/v1.2.3/missing-param\"\n * ```\n *\n * @param slug - Slug for the message. This corresponds to a Markdown file in\n * the Git repository's `/messages` directory.\n *\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":";;;;;;;;;;;;;;;;;AAiBA,SAAgB,OAAO,MAAsB;AAC5C,QAAO,kCAAkC,QAAQ,GAAG"}
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;AAC5C,QAAO,kCAAkC,QAAQ,GAAG"}
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "3.4.0-pr.257.5417830";
2
+ var version = "3.4.0-pr.257.68f2f80";
3
3
  //#endregion
4
4
  export { version };
5
5
 
package/package.json CHANGED
@@ -1,24 +1,28 @@
1
1
  {
2
2
  "name": "@prismicio/react",
3
- "version": "3.4.0-pr.257.5417830",
3
+ "version": "3.4.0-pr.257.68f2f80",
4
4
  "description": "React components and hooks to fetch and present Prismic content",
5
5
  "keywords": [
6
- "typescript",
7
6
  "prismic",
8
- "react"
7
+ "react",
8
+ "typescript"
9
9
  ],
10
+ "license": "Apache-2.0",
11
+ "author": "Prismic <contact@prismic.io> (https://prismic.io)",
10
12
  "repository": {
11
13
  "type": "git",
12
14
  "url": "git+https://github.com/prismicio/prismic-react.git"
13
15
  },
14
- "license": "Apache-2.0",
15
- "author": "Prismic <contact@prismic.io> (https://prismic.io)",
16
- "sideEffects": false,
16
+ "workspaces": [
17
+ ".",
18
+ "e2e-projects/*"
19
+ ],
20
+ "files": [
21
+ "dist",
22
+ "src"
23
+ ],
17
24
  "type": "module",
18
- "exports": {
19
- ".": "./dist/index.js",
20
- "./package.json": "./package.json"
21
- },
25
+ "sideEffects": false,
22
26
  "types": "./dist/index.d.ts",
23
27
  "typesVersions": {
24
28
  "*": {
@@ -27,20 +31,19 @@
27
31
  ]
28
32
  }
29
33
  },
30
- "files": [
31
- "dist",
32
- "src"
33
- ],
34
- "workspaces": [
35
- ".",
36
- "e2e-projects/*"
37
- ],
34
+ "exports": {
35
+ ".": "./dist/index.js",
36
+ "./package.json": "./package.json"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
38
41
  "scripts": {
39
42
  "build": "tsdown",
40
43
  "dev": "tsdown --watch",
41
44
  "e2e": "playwright test",
42
45
  "e2e:ui": "npm run e2e -- --ui",
43
- "format": "prettier --write .",
46
+ "format": "oxfmt",
44
47
  "lint": "oxlint --deny-warnings",
45
48
  "prepare": "npm run build",
46
49
  "test": "npm run lint && npm run types && npm run build && npm run e2e",
@@ -50,20 +53,18 @@
50
53
  "esm-env": "^1.2.2"
51
54
  },
52
55
  "devDependencies": {
53
- "@playwright/test": "^1.58.2",
56
+ "@playwright/test": "^1.59.1",
54
57
  "@prismicio/client": "^7.17.0",
55
- "@trivago/prettier-plugin-sort-imports": "^6.0.2",
56
58
  "@types/react": "^19.2.14",
57
59
  "@types/react-dom": "^19.2.3",
58
- "dotenv": "^17.3.1",
60
+ "dotenv": "^17.4.0",
61
+ "oxfmt": "^0.43.0",
59
62
  "oxlint": "^1.58.0",
60
- "playwright": "^1.58.2",
61
- "prettier": "^3.8.1",
62
- "prettier-plugin-jsdoc": "^1.8.0",
63
+ "playwright": "^1.59.1",
63
64
  "react": "^19.2.4",
64
65
  "react-dom": "^19.2.4",
65
66
  "tsdown": "^0.21.7",
66
- "typescript": "^5.9.3"
67
+ "typescript": "^6.0.2"
67
68
  },
68
69
  "peerDependencies": {
69
70
  "@prismicio/client": "^7",
@@ -71,8 +72,5 @@
71
72
  },
72
73
  "engines": {
73
74
  "node": ">=20"
74
- },
75
- "publishConfig": {
76
- "access": "public"
77
75
  }
78
76
  }