@prismicio/react 3.4.0-canary.e2a0168 → 3.4.0-pr.257.68f2f80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/PrismicImage.d.ts +20 -28
  2. package/dist/PrismicImage.d.ts.map +1 -1
  3. package/dist/PrismicImage.js +6 -8
  4. package/dist/PrismicImage.js.map +1 -1
  5. package/dist/PrismicLink.d.ts +18 -21
  6. package/dist/PrismicLink.d.ts.map +1 -1
  7. package/dist/PrismicLink.js +6 -9
  8. package/dist/PrismicLink.js.map +1 -1
  9. package/dist/PrismicRichText.d.ts +31 -37
  10. package/dist/PrismicRichText.d.ts.map +1 -1
  11. package/dist/PrismicRichText.js +5 -7
  12. package/dist/PrismicRichText.js.map +1 -1
  13. package/dist/PrismicTable.d.ts +15 -16
  14. package/dist/PrismicTable.d.ts.map +1 -1
  15. package/dist/PrismicTable.js +4 -6
  16. package/dist/PrismicTable.js.map +1 -1
  17. package/dist/PrismicText.d.ts +8 -11
  18. package/dist/PrismicText.d.ts.map +1 -1
  19. package/dist/PrismicText.js +4 -6
  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 +5 -8
  24. package/dist/PrismicToolbar.js.map +1 -1
  25. package/dist/SliceZone.d.ts +31 -51
  26. package/dist/SliceZone.d.ts.map +1 -1
  27. package/dist/SliceZone.js +7 -10
  28. package/dist/SliceZone.js.map +1 -1
  29. package/dist/index.js +1 -2
  30. package/dist/lib/devMsg.js +7 -10
  31. package/dist/lib/devMsg.js.map +1 -1
  32. package/dist/package.js +2 -2
  33. package/package.json +32 -34
  34. package/src/PrismicImage.tsx +95 -122
  35. package/src/PrismicLink.tsx +28 -38
  36. package/src/PrismicRichText.tsx +41 -49
  37. package/src/PrismicTable.tsx +15 -19
  38. package/src/PrismicText.tsx +6 -7
  39. package/src/PrismicToolbar.tsx +12 -16
  40. package/src/SliceZone.tsx +36 -76
  41. package/src/lib/devMsg.ts +6 -8
@@ -1,6 +1,6 @@
1
1
  import { JSXMapSerializer } from "./PrismicRichText.js";
2
- import { ComponentType, FC, ReactNode } from "react";
3
2
  import { TableField, TableFieldBody, TableFieldBodyRow, TableFieldDataCell, TableFieldHead, TableFieldHeadRow, TableFieldHeaderCell } from "@prismicio/client";
3
+ import { ComponentType, FC, ReactNode } from "react";
4
4
 
5
5
  //#region src/PrismicTable.d.ts
6
6
  type TableComponents = {
@@ -31,24 +31,24 @@ type TableComponents = {
31
31
  };
32
32
  /** Props for `<PrismicTable>`. */
33
33
  type PrismicTableProps = {
34
- /** The Prismic table field to render. */
35
- field: TableField;
34
+ /** The Prismic table field to render. */field: TableField;
36
35
  /**
37
36
  * An object that maps a table block to a React component.
38
37
  *
39
- * @example A map serializer.
38
+ * @example
39
+ * A map serializer.
40
40
  *
41
- * ```jsx
42
- * {
43
- * table: ({children}) => <table>{children}</table>
44
- * thead: ({children}) => <thead>{children}</thead>
45
- * }
46
- * ```
41
+ * ```jsx
42
+ * {
43
+ * table: ({children}) => <table>{children}</table>
44
+ * thead: ({children}) => <thead>{children}</thead>
45
+ * }
46
+ * ```
47
47
  */
48
48
  components?: JSXMapSerializer & TableComponents;
49
49
  /**
50
- * The value to be rendered when the field is empty. If a fallback is not
51
- * given, `null` will be rendered.
50
+ * The value to be rendered when the field is empty. If a fallback is not given, `null` will be
51
+ * rendered.
52
52
  */
53
53
  fallback?: ReactNode;
54
54
  };
@@ -56,10 +56,9 @@ type PrismicTableProps = {
56
56
  * Renders content from a Prismic table field as React components.
57
57
  *
58
58
  * @example
59
- *
60
- * ```tsx
61
- * <PrismicTable field={slice.primary.pricing_table} />;
62
- * ```
59
+ * ```tsx
60
+ * <PrismicTable field={slice.primary.pricing_table} />;
61
+ * ```
63
62
  *
64
63
  * @see Learn how to style tables and customize table element components: {@link https://prismic.io/docs/fields/table}
65
64
  */
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicTable.d.ts","names":[],"sources":["../src/PrismicTable.tsx"],"sourcesContent":[],"mappings":";;;;;KAcK,eAAA;UACI;IADJ,KAAA,EAC2B,UADZ,CAAA,QAAA,CAAA;IACY,QAAA,EAAgC,SAAhC;EAAgC,CAAA,CAAA;EAAvD,KAAA,CAAA,EACA,aADA,CAAA;IACsB,IAAA,EAAA,cAAA;IAA0B,QAAA,EAAA,SAAA;EAAhD,CAAA,CAAA;EACsB,KAAA,CAAA,EAAtB,aAAsB,CAAA;IAA0B,IAAA,EAA1B,cAA0B;IAAhD,QAAA,EAAgD,SAAhD;EAEF,CAAA,CAAA;EAAoB,EAAA,CAAA,EADrB,aACqB,CAAA;IACf,GAAA,EADL,iBACK,GADe,iBACf;IAFN,QAAA,EAEM,SAFN;EAIsB,CAAA,CAAA;EAAgC,EAAA,CAAA,EAAtD,aAAsD,CAAA;IAAtD,IAAA,EAAsB,oBAAtB;IACsB,QAAA,EADgC,SAChC;EAA8B,CAAA,CAAA;EAApD,EAAA,CAAA,EAAA,aAAA,CAAA;IAAa,IAAA,EAAS,kBAAT;IAaP,QAAA,EAb8C,SAa7B;EAErB,CAAA,CAAA;CAcM;;AAMF,KAtBA,iBAAA,GAsBA;EAAS;EAcR,KAAA,EAlCL,UA+DP;;;;;;;;;;;;;eAjDa,mBAAmB;;;;;aAMrB;;;;;;;;;;;;;cAcC,cAAc,GAAG"}
1
+ {"version":3,"file":"PrismicTable.d.ts","names":[],"sources":["../src/PrismicTable.tsx"],"mappings":";;;;;KAcK,eAAA;EACJ,KAAA,GAAQ,aAAA;IAAgB,KAAA,EAAO,UAAA;IAAsB,QAAA,EAAU,SAAA;EAAA;EAC/D,KAAA,GAAQ,aAAA;IAAgB,IAAA,EAAM,cAAA;IAAgB,QAAA,EAAU,SAAA;EAAA;EACxD,KAAA,GAAQ,aAAA;IAAgB,IAAA,EAAM,cAAA;IAAgB,QAAA,EAAU,SAAA;EAAA;EACxD,EAAA,GAAK,aAAA;IACJ,GAAA,EAAK,iBAAA,GAAoB,iBAAA;IACzB,QAAA,EAAU,SAAA;EAAA;EAEX,EAAA,GAAK,aAAA;IAAgB,IAAA,EAAM,oBAAA;IAAsB,QAAA,EAAU,SAAA;EAAA;EAC3D,EAAA,GAAK,aAAA;IAAgB,IAAA,EAAM,kBAAA;IAAoB,QAAA,EAAU,SAAA;EAAA;AAAA;;KAa9C,iBAAA;EArBa,yCAuBxB,KAAA,EAAO,UAAA;EAvB8C;;;;;;;;;;;;;EAsCrD,UAAA,GAAa,gBAAA,GAAmB,eAAA;EAnChC;;;;EAyCA,QAAA,GAAW,SAAA;AAAA;;;;;;;;;;;cAaC,YAAA,EAAc,EAAA,CAAG,iBAAA"}
@@ -1,7 +1,6 @@
1
1
  import { PrismicRichText } from "./PrismicRichText.js";
2
2
  import { isFilled } from "@prismicio/client";
3
3
  import { jsx, jsxs } from "react/jsx-runtime";
4
-
5
4
  //#region src/PrismicTable.tsx
6
5
  const defaultComponents = {
7
6
  table: ({ children }) => /* @__PURE__ */ jsx("table", { children }),
@@ -15,10 +14,9 @@ const defaultComponents = {
15
14
  * Renders content from a Prismic table field as React components.
16
15
  *
17
16
  * @example
18
- *
19
- * ```tsx
20
- * <PrismicTable field={slice.primary.pricing_table} />;
21
- * ```
17
+ * ```tsx
18
+ * <PrismicTable field={slice.primary.pricing_table} />;
19
+ * ```
22
20
  *
23
21
  * @see Learn how to style tables and customize table element components: {@link https://prismic.io/docs/fields/table}
24
22
  */
@@ -69,7 +67,7 @@ function TableRow(props) {
69
67
  }, cell.key))
70
68
  });
71
69
  }
72
-
73
70
  //#endregion
74
71
  export { PrismicTable };
72
+
75
73
  //# sourceMappingURL=PrismicTable.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicTable.js","names":[],"sources":["../src/PrismicTable.tsx"],"sourcesContent":["import type { ComponentType, FC, ReactNode } from \"react\";\nimport {\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\";\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 A map serializer.\n\t *\n\t * ```jsx\n\t * {\n\t * table: ({children}) => <table>{children}</table>\n\t * thead: ({children}) => <thead>{children}</thead>\n\t * }\n\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\n\t * given, `null` will be rendered.\n\t */\n\tfallback?: ReactNode;\n};\n\n/**\n * Renders content from a Prismic table field as React components.\n *\n * @example\n *\n * ```tsx\n * <PrismicTable field={slice.primary.pricing_table} />;\n * ```\n *\n * @see Learn how to style tables and customize table element components: {@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 {\n\t\ttable: Table,\n\t\tthead: Thead,\n\t\ttbody: Tbody,\n\t} = { ...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,WAAO,WAAiB;CAClD,QAAQ,EAAE,eAAe,oBAAC,WAAO,WAAiB;CAClD,QAAQ,EAAE,eAAe,oBAAC,WAAO,WAAiB;CAClD,KAAK,EAAE,eAAe,oBAAC,QAAI,WAAc;CACzC,KAAK,EAAE,eAAe,oBAAC,QAAI,WAAc;CACzC,KAAK,EAAE,eAAe,oBAAC,QAAI,WAAc;CACzC;;;;;;;;;;;;AAuCD,MAAa,gBAAuC,UAAU;CAC7D,MAAM,EAAE,OAAO,YAAY,WAAW,SAAS;AAE/C,KAAI,CAAC,SAAS,MAAM,MAAM,CACzB,QAAO;CAGR,MAAM,EACL,OAAO,OACP,OAAO,OACP,OAAO,UACJ;EAAE,GAAG;EAAmB,GAAG;EAAY;AAE3C,QACC,qBAAC;EAAM,OAAO;aACZ,MAAM,QACN,oBAAC;GAAM,MAAM,MAAM;aACjB,MAAM,KAAK,KAAK,KAAK,QACrB,oBAAC;IAA4B;IAAiB;MAA/B,IAAI,IAAyC,CAC3D;IACK,EAET,oBAAC;GAAM,MAAM,MAAM;aACjB,MAAM,KAAK,KAAK,KAAK,QACrB,oBAAC;IAA4B;IAAiB;MAA/B,IAAI,IAAyC,CAC3D;IACK;GACD;;AASV,SAAS,SAAS,OAAsB;CACvC,MAAM,EAAE,KAAK,eAAe;CAE5B,MAAM,EAAE,IAAI,IAAI,IAAI,IAAI,IAAI,OAAO;EAAE,GAAG;EAAmB,GAAG;EAAY;AAE1E,QACC,oBAAC;EAAQ;YACP,IAAI,MAAM,KAAK,SACf,KAAK,SAAS,WACb,oBAAC;GAAwB;aACxB,oBAAC;IAAgB,OAAO,KAAK;IAAqB;KAAc;KADxD,KAAK,IAET,GAEL,oBAAC;GAAwB;aACxB,oBAAC;IAAgB,OAAO,KAAK;IAAqB;KAAc;KADxD,KAAK,IAET,CAEN;GACG"}
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,UAAiB,CAAA;CAClD,QAAQ,EAAE,eAAe,oBAAC,SAAD,EAAQ,UAAiB,CAAA;CAClD,QAAQ,EAAE,eAAe,oBAAC,SAAD,EAAQ,UAAiB,CAAA;CAClD,KAAK,EAAE,eAAe,oBAAC,MAAD,EAAK,UAAc,CAAA;CACzC,KAAK,EAAE,eAAe,oBAAC,MAAD,EAAK,UAAc,CAAA;CACzC,KAAK,EAAE,eAAe,oBAAC,MAAD,EAAK,UAAc,CAAA;CACzC;;;;;;;;;;;AAuCD,MAAa,gBAAuC,UAAU;CAC7D,MAAM,EAAE,OAAO,YAAY,WAAW,SAAS;AAE/C,KAAI,CAAC,SAAS,MAAM,MAAM,CACzB,QAAO;CAGR,MAAM,EAAE,OAAO,OAAO,OAAO,OAAO,OAAO,UAAU;EAAE,GAAG;EAAmB,GAAG;EAAY;AAE5F,QACC,qBAAC,OAAD;EAAO,OAAO;YAAd,CACE,MAAM,QACN,oBAAC,OAAD;GAAO,MAAM,MAAM;aACjB,MAAM,KAAK,KAAK,KAAK,QACrB,oBAAC,UAAD;IAA6B;IAAiB;IAAc,EAA7C,IAAI,IAAyC,CAC3D;GACK,CAAA,EAET,oBAAC,OAAD;GAAO,MAAM,MAAM;aACjB,MAAM,KAAK,KAAK,KAAK,QACrB,oBAAC,UAAD;IAA6B;IAAiB;IAAc,EAA7C,IAAI,IAAyC,CAC3D;GACK,CAAA,CACD;;;AASV,SAAS,SAAS,OAAsB;CACvC,MAAM,EAAE,KAAK,eAAe;CAE5B,MAAM,EAAE,IAAI,IAAI,IAAI,IAAI,IAAI,OAAO;EAAE,GAAG;EAAmB,GAAG;EAAY;AAE1E,QACC,oBAAC,IAAD;EAAS;YACP,IAAI,MAAM,KAAK,SACf,KAAK,SAAS,WACb,oBAAC,IAAD;GAAyB;aACxB,oBAAC,iBAAD;IAAiB,OAAO,KAAK;IAAqB;IAAc,CAAA;GAC5D,EAFI,KAAK,IAET,GAEL,oBAAC,IAAD;GAAyB;aACxB,oBAAC,iBAAD;IAAiB,OAAO,KAAK;IAAqB;IAAc,CAAA;GAC5D,EAFI,KAAK,IAET,CAEN;EACG,CAAA"}
@@ -1,27 +1,24 @@
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
- /** The Prismic rich text field to render. */
8
- field: RichTextField | null | undefined;
7
+ /** The Prismic rich text field to render. */field: RichTextField | null | undefined;
9
8
  /**
10
- * The string rendered when the field is empty. If a fallback is not given,
11
- * `null` will be rendered.
9
+ * The string rendered when the field is empty. If a fallback is not given, `null` will be
10
+ * rendered.
12
11
  */
13
- fallback?: string;
14
- /** The separator used between blocks. Defaults to `\n`. */
12
+ fallback?: string; /** The separator used between blocks. Defaults to `\n`. */
15
13
  separator?: string;
16
14
  };
17
15
  /**
18
16
  * Renders content from a Prismic rich text field as plain text (no HTML).
19
17
  *
20
18
  * @example
21
- *
22
- * ```tsx
23
- * <PrismicText field={slice.primary.text} />;
24
- * ```
19
+ * ```tsx
20
+ * <PrismicText field={slice.primary.text} />;
21
+ * ```
25
22
  *
26
23
  * @see Learn how to display rich text as plain text or React components: {@link https://prismic.io/docs/fields/rich-text}
27
24
  */
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicText.d.ts","names":[],"sources":["../src/PrismicText.tsx"],"sourcesContent":[],"mappings":";;;;;KAOY,gBAAA;EAAA;EAyBC,KAAA,EAvBL,aAuDP,GAAA,IAhC4B,GAAA,SAAA;;;;;;;;;;;;;;;;;;;;cAAhB,aAAa,GAAG"}
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"}
@@ -2,16 +2,14 @@ import { devMsg } from "./lib/devMsg.js";
2
2
  import { asText, isFilled } from "@prismicio/client";
3
3
  import { DEV } from "esm-env";
4
4
  import { Fragment, jsx } from "react/jsx-runtime";
5
-
6
5
  //#region src/PrismicText.tsx
7
6
  /**
8
7
  * Renders content from a Prismic rich text field as plain text (no HTML).
9
8
  *
10
9
  * @example
11
- *
12
- * ```tsx
13
- * <PrismicText field={slice.primary.text} />;
14
- * ```
10
+ * ```tsx
11
+ * <PrismicText field={slice.primary.text} />;
12
+ * ```
15
13
  *
16
14
  * @see Learn how to display rich text as plain text or React components: {@link https://prismic.io/docs/fields/rich-text}
17
15
  */
@@ -27,7 +25,7 @@ const PrismicText = (props) => {
27
25
  if (!isFilled.richText(field)) return fallback != null ? /* @__PURE__ */ jsx(Fragment, { children: fallback }) : null;
28
26
  return /* @__PURE__ */ jsx(Fragment, { children: asText(field, { separator }) });
29
27
  };
30
-
31
28
  //#endregion
32
29
  export { PrismicText };
30
+
33
31
  //# sourceMappingURL=PrismicText.js.map
@@ -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,KACH;MAAI,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,0CAAG,WAAY,GAAG;AAG7C,QAAO,0CAAG,OAAO,OAAO,EAAE,WAAW,CAAC,GAAI"}
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"],"sourcesContent":[],"mappings":";;;;KAMY,mBAAA;EAAA;AAuCZ;;;;;;;;;;;;;4BAvB2B;;;;;;;;;;yBASH;;;;;;;;;;;;;cAcX,gBAAgB,GAAG"}
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,17 +1,14 @@
1
1
  "use client";
2
-
3
- import { useEffect, useRef } from "react";
4
2
  import { getToolbarSrc } from "@prismicio/client";
5
-
3
+ import { useEffect, useRef } from "react";
6
4
  //#region src/PrismicToolbar.tsx
7
5
  /**
8
6
  * Renders the Prismic Toolbar script to support draft previews.
9
7
  *
10
8
  * @example
11
- *
12
- * ```tsx
13
- * <PrismicToolbar repositoryName="my-repo" />;
14
- * ```
9
+ * ```tsx
10
+ * <PrismicToolbar repositoryName="my-repo" />;
11
+ * ```
15
12
  *
16
13
  * @see Learn how to set up preview functionality and the toolbar's role in preview sessions: {@link https://prismic.io/docs/previews}
17
14
  */
@@ -41,7 +38,7 @@ const PrismicToolbar = (props) => {
41
38
  }, []);
42
39
  return null;
43
40
  };
44
-
45
41
  //#endregion
46
42
  export { PrismicToolbar };
43
+
47
44
  //# sourceMappingURL=PrismicToolbar.js.map
@@ -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,8 +1,7 @@
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
-
6
5
  /**
7
6
  * Returns the type of a `SliceLike` type.
8
7
  *
@@ -10,15 +9,15 @@ import { Slice } from "@prismicio/client";
10
9
  */
11
10
  type ExtractSliceType<TSlice extends SliceLike> = TSlice extends Slice ? TSlice["slice_type"] : TSlice extends SliceLikeGraphQL ? TSlice["type"] : never;
12
11
  /**
13
- * The minimum required properties to represent a Prismic slice from the Prismic
14
- * 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.
15
14
  *
16
15
  * @typeParam SliceType - Type name of the slice.
17
16
  */
18
17
  type SliceLikeRestV2<TSliceType extends string = string> = Pick<Slice<TSliceType>, "id" | "slice_type">;
19
18
  /**
20
- * The minimum required properties to represent a Prismic slice from the Prismic
21
- * 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.
22
21
  *
23
22
  * @typeParam SliceType - Type name of the slice.
24
23
  */
@@ -26,52 +25,43 @@ type SliceLikeGraphQL<TSliceType extends string = string> = {
26
25
  type: Slice<TSliceType>["slice_type"];
27
26
  };
28
27
  /**
29
- * The minimum required properties to represent a Prismic slice for the
30
- * `mapSliceZone()` helper.
28
+ * The minimum required properties to represent a Prismic slice for the `mapSliceZone()` helper.
31
29
  *
32
- * If using Prismic's Content API, use the `Slice` export from
33
- * `@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.
34
32
  *
35
33
  * @typeParam SliceType - Type name of the slice.
36
34
  */
37
35
  type SliceLike<TSliceType extends string = string> = (SliceLikeRestV2<TSliceType> | SliceLikeGraphQL<TSliceType>) & {
38
36
  /**
39
- * If `true`, this slice has been modified from its original value using a
40
- * 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()`.
41
39
  *
42
40
  * @internal
43
41
  */
44
42
  __mapped?: true;
45
43
  };
46
44
  /**
47
- * A looser version of the `SliceZone` type from `@prismicio/client` using
48
- * `SliceLike`.
45
+ * A looser version of the `SliceZone` type from `@prismicio/client` using `SliceLike`.
49
46
  *
50
- * If using Prismic's Content API, use the `SliceZone` export from
51
- * `@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.
52
49
  *
53
50
  * @typeParam TSlice - The type(s) of a slice in the slice zone.
54
51
  */
55
52
  type SliceZoneLike<TSlice extends SliceLike = SliceLike> = readonly TSlice[];
56
53
  /**
57
- * React props for a component rendering content from a Prismic slice using the
58
- * `<SliceZone>` component.
54
+ * React props for a component rendering content from a Prismic slice using the `<SliceZone>`
55
+ * component.
59
56
  *
60
57
  * @typeParam TSlice - The slice passed as a prop.
61
- * @typeParam TContext - Arbitrary data passed to `<SliceZone>` and made
62
- * available to all slice components.
58
+ * @typeParam TContext - Arbitrary data passed to `<SliceZone>` and made available to all slice
59
+ * components.
63
60
  */
64
61
  type SliceComponentProps<TSlice extends SliceLike = SliceLike, TContext = unknown> = {
65
- /** Slice data for this component. */
66
- slice: TSlice;
67
- /** The index of the slice in the slice zone. */
68
- index: number;
69
- /** All slices from the slice zone to which the slice belongs. */
70
- slices: SliceZoneLike<TSlice extends SliceLikeGraphQL ? SliceLikeGraphQL : SliceLikeRestV2>;
71
- /**
72
- * Arbitrary data passed to `<SliceZone>` and made available to all slice
73
- * components.
74
- */
62
+ /** Slice data for this component. */slice: TSlice; /** The index of the slice in the slice zone. */
63
+ index: number; /** All slices from the slice zone to which the slice belongs. */
64
+ slices: SliceZoneLike<TSlice extends SliceLikeGraphQL ? SliceLikeGraphQL : SliceLikeRestV2>; /** Arbitrary data passed to `<SliceZone>` and made available to all slice components. */
75
65
  context: TContext;
76
66
  };
77
67
  /**
@@ -82,12 +72,11 @@ type SliceComponentProps<TSlice extends SliceLike = SliceLike, TContext = unknow
82
72
  */
83
73
  type SliceComponentType<TSlice extends SliceLike = any, TContext = unknown> = ComponentType<SliceComponentProps<TSlice, TContext>>;
84
74
  /**
85
- * A record of slice types mapped to a React component. The component will be
86
- * 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.
87
77
  *
88
78
  * @deprecated This type is no longer used by `@prismicio/react`. Prefer using
89
79
  * `Record<string, SliceComponentType<any>>` instead.
90
- *
91
80
  * @typeParam TSlice - The type(s) of a slice in the slice zone.
92
81
  * @typeParam TContext - Arbitrary data made available to all slice components.
93
82
  */
@@ -99,24 +88,16 @@ type SliceZoneComponents<TSlice extends SliceLike = SliceLike, TContext = unknow
99
88
  * @typeParam TContext - Arbitrary data made available to all slice components.
100
89
  */
101
90
  type SliceZoneProps<TContext = unknown> = {
102
- /** List of slice data from the slice zone. */
103
- slices?: SliceZoneLike;
104
- /** A record mapping slice types to React components. */
105
- components?: Record<string, ComponentType<any>>;
106
- /**
107
- * The React component rendered if a component mapping from the `components`
108
- * prop cannot be found.
109
- */
110
- defaultComponent?: ComponentType<SliceComponentProps<any, TContext>>;
111
- /** Arbitrary data made available to all slice components. */
91
+ /** List of slice data from the slice zone. */slices?: SliceZoneLike; /** A record mapping slice types to React components. */
92
+ components?: Record<string, ComponentType<any>>; /** The React component rendered if a component mapping from the `components` prop cannot be found. */
93
+ defaultComponent?: ComponentType<SliceComponentProps<any, TContext>>; /** Arbitrary data made available to all slice components. */
112
94
  context?: TContext;
113
95
  };
114
96
  /**
115
- * This slice component can be used as a reminder to provide a proper
116
- * implementation.
97
+ * This slice component can be used as a reminder to provide a proper implementation.
117
98
  *
118
- * This is also the default React component rendered when a component mapping
119
- * cannot be found in `<SliceZone>`.
99
+ * This is also the default React component rendered when a component mapping cannot be found in
100
+ * `<SliceZone>`.
120
101
  */
121
102
  declare const TODOSliceComponent: <TSlice extends SliceLike>({
122
103
  slice
@@ -127,10 +108,9 @@ declare const TODOSliceComponent: <TSlice extends SliceLike>({
127
108
  * Renders slices in a slice zone as React components.
128
109
  *
129
110
  * @example
130
- *
131
- * ```tsx
132
- * <SliceZone slices={page.data.slices} components={components} />;
133
- * ```
111
+ * ```tsx
112
+ * <SliceZone slices={page.data.slices} components={components} />;
113
+ * ```
134
114
  *
135
115
  * @see Learn how to create slices, use slice variations, and display slices: {@link https://prismic.io/docs/slices}
136
116
  */
@@ -1 +1 @@
1
- {"version":3,"file":"SliceZone.d.ts","names":[],"sources":["../src/SliceZone.tsx"],"sourcesContent":[],"mappings":";;;;;;;AAC+C;;;KAQ1C,gBAA4D,CAAA,eAA5B,SAA4B,CAAA,GAAf,MAAe,SAAA,KAAA,GAC9D,MAD8D,CAAA,YAAA,CAAA,GAE9D,MAF8D,SAE/C,gBAF+C,GAG7D,MAH6D,CAAA,MAAA,CAAA,GAAA,KAAA;;;;;;AAYjE;AACO,KADK,eACL,CAAA,mBAAA,MAAA,GAAA,MAAA,CAAA,GAD2D,IAC3D,CAAN,KAAM,CAAA,UAAA,CAAA,EAAA,IAAA,GAAA,YAAA,CAAA;;;;AAUP;AAaA;;AACG,KAdS,gBAcT,CAAA,mBAAA,MAAA,GAAA,MAAA,CAAA,GAAA;EACiB,IAAA,EAdb,KAca,CAdP,UAcO,CAAA,CAAA,YAAA,CAAA;CAAjB;;AAoBH;;;;;AAWA;;;AAKQ,KAtCI,SAsCJ,CAAA,mBAAA,MAAA,GAAA,MAAA,CAAA,GAAA,CArCL,eAqCK,CArCW,UAqCX,CAAA,GApCL,gBAoCK,CApCY,UAoCZ,CAAA,CAAA,GAAA;EAWN;;;;;;EAOgB,QAAA,CAAA,EAAA,IAAA;AASlB,CAAA;;;;;;;AAgBA;;;AAciC,KAzErB,aAyEqB,CAAA,eAzEQ,SAyER,GAzEoB,SAyEpB,CAAA,GAAA,SAxEvB,MAwEuB,EAAA;;;;;;;;;AAGX,KAjEV,mBAiEU,CAAA,eAhEN,SAgEM,GAhEM,SAgEN,EAAA,WAAA,OAAA,CAAA,GAAA;EAAhB;EACH,KAAA,EA7DK,MA6DL;EAJwC;EAAkB,KAAA,EAAA,MAAA;EAcjD;EAEF,MAAA,EA/DD,aA+DC,CA9DR,MA8DQ,SA9DO,gBA8DP,GA9D0B,gBA8D1B,GA9D6C,eA8D7C,CAAA;EAImB;;;;EAOT,OAAA,EAlEV,QAkEU;CAGT;;AAUX;;;;;AAsBC,KA5FW,kBA4FX,CAAA,eA1Fe,SA0Ff,GAAA,GAAA,EAAA,WAAA,OAAA,CAAA,GAxFG,aAwFH,CAxFiB,mBAwFjB,CAxFqC,MAwFrC,EAxF6C,QAwF7C,CAAA,CAAA;AAaD;;;;;;;;;;KAzFY,mCACI,YAAY,iDAaZ,iBAAiB,UAAU,mBACxC,QAAQ,QAAQ,UAAU,4BACvB,YACA,QAAQ,QAAQ,UAAU,aAC7B;;;;;;;KAUS;;WAEF;;eAII,eAAe;;;;;qBAOT,cAAc,yBAAyB;;YAGhD;;;;;;;;;cAUE,oCAAqC;;;SAG1C;MACJ;;;;;;;;;;;;cA+BS,WAAW,GAAG"}
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
@@ -1,13 +1,11 @@
1
1
  import { DEV } from "esm-env";
2
2
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
-
4
3
  //#region src/SliceZone.tsx
5
4
  /**
6
- * This slice component can be used as a reminder to provide a proper
7
- * implementation.
5
+ * This slice component can be used as a reminder to provide a proper implementation.
8
6
  *
9
- * This is also the default React component rendered when a component mapping
10
- * cannot be found in `<SliceZone>`.
7
+ * This is also the default React component rendered when a component mapping cannot be found in
8
+ * `<SliceZone>`.
11
9
  */
12
10
  const TODOSliceComponent = ({ slice }) => {
13
11
  if (!DEV) return null;
@@ -27,10 +25,9 @@ const TODOSliceComponent = ({ slice }) => {
27
25
  * Renders slices in a slice zone as React components.
28
26
  *
29
27
  * @example
30
- *
31
- * ```tsx
32
- * <SliceZone slices={page.data.slices} components={components} />;
33
- * ```
28
+ * ```tsx
29
+ * <SliceZone slices={page.data.slices} components={components} />;
30
+ * ```
34
31
  *
35
32
  * @see Learn how to create slices, use slice variations, and display slices: {@link https://prismic.io/docs/slices}
36
33
  */
@@ -53,7 +50,7 @@ const SliceZone = (props) => {
53
50
  }, key);
54
51
  }) });
55
52
  };
56
-
57
53
  //#endregion
58
54
  export { SliceZone, TODOSliceComponent };
55
+
59
56
  //# sourceMappingURL=SliceZone.js.map
@@ -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;EAAQ,kCAA+B;EAAG,mBAAiB;;GAAM;GACf;GAAK;;GAE9C;;;;;;;;;;;;;AAeZ,MAAa,aAAiC,UAAU;CACvD,MAAM,EACL,SAAS,EAAE,EACX,aAAa,EAAE,EACf,kBACA,UAAU,EAAE,KACT;AAkCJ,QAAO,0CAhCgB,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,sBAAoC,SAAZ,IAAqB;AAGtD,MAAI,MAAM,UAAU;GACnB,MAAM,EAAE,UAAU,GAAG,gBAAgB;AAErC,UAAO,oBAAC,QAAe,GAAI,eAAT,IAAwB;;AAG3C,SACC,oBAAC;GAEO;GACA;GACC;GACC;KAJJ,IAKJ;GAEF,GAE0B"}
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"}
package/dist/index.js CHANGED
@@ -6,5 +6,4 @@ import { PrismicImage } from "./PrismicImage.js";
6
6
  import { SliceZone, TODOSliceComponent } from "./SliceZone.js";
7
7
  import { PrismicToolbar } from "./PrismicToolbar.js";
8
8
  import { Element } from "@prismicio/client/richtext";
9
-
10
- export { Element, PrismicImage, PrismicLink, PrismicRichText, PrismicTable, PrismicText, PrismicToolbar, SliceZone, TODOSliceComponent };
9
+ export { Element, PrismicImage, PrismicLink, PrismicRichText, PrismicTable, PrismicText, PrismicToolbar, SliceZone, TODOSliceComponent };
@@ -1,25 +1,22 @@
1
1
  import { version } from "../package.js";
2
-
3
2
  //#region src/lib/devMsg.ts
4
3
  /**
5
4
  * Returns a `prismic.dev/msg` URL for a given message slug.
6
5
  *
7
6
  * @example
7
+ * ```ts
8
+ * devMsg("missing-param");
9
+ * // => "https://prismic.dev/msg/react/v1.2.3/missing-param"
10
+ * ```
8
11
  *
9
- * ```ts
10
- * devMsg("missing-param");
11
- * // => "https://prismic.dev/msg/react/v1.2.3/missing-param"
12
- * ```
13
- *
14
- * @param slug - Slug for the message. This corresponds to a Markdown file in
15
- * the Git repository's `/messages` directory.
16
- *
12
+ * @param slug - Slug for the message. This corresponds to a Markdown file in the Git repository's
13
+ * `/messages` directory.
17
14
  * @returns The `prismic.dev/msg` URL for the given slug.
18
15
  */
19
16
  function devMsg(slug) {
20
17
  return `https://prismic.dev/msg/react/v${version}/${slug}`;
21
18
  }
22
-
23
19
  //#endregion
24
20
  export { devMsg };
21
+
25
22
  //# sourceMappingURL=devMsg.js.map