@prismicio/react 2.5.1 → 2.6.0-alpha.0

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 (92) hide show
  1. package/dist/PrismicImage.cjs +7 -11
  2. package/dist/PrismicImage.cjs.map +1 -1
  3. package/dist/PrismicImage.d.ts +162 -163
  4. package/dist/PrismicImage.js +6 -10
  5. package/dist/PrismicImage.js.map +1 -1
  6. package/dist/PrismicLink.cjs +4 -66
  7. package/dist/PrismicLink.cjs.map +1 -1
  8. package/dist/PrismicLink.d.ts +6 -105
  9. package/dist/PrismicLink.js +4 -65
  10. package/dist/PrismicLink.js.map +1 -1
  11. package/dist/PrismicProvider.cjs.map +1 -1
  12. package/dist/PrismicProvider.d.ts +83 -84
  13. package/dist/PrismicProvider.js.map +1 -1
  14. package/dist/PrismicRichText.cjs +4 -71
  15. package/dist/PrismicRichText.cjs.map +1 -1
  16. package/dist/PrismicRichText.d.ts +4 -116
  17. package/dist/PrismicRichText.js +5 -70
  18. package/dist/PrismicRichText.js.map +1 -1
  19. package/dist/PrismicText.cjs +4 -4
  20. package/dist/PrismicText.cjs.map +1 -1
  21. package/dist/PrismicText.d.ts +39 -39
  22. package/dist/PrismicText.js +3 -3
  23. package/dist/PrismicText.js.map +1 -1
  24. package/dist/PrismicToolbar.cjs +6 -4
  25. package/dist/PrismicToolbar.cjs.map +1 -1
  26. package/dist/PrismicToolbar.d.ts +23 -21
  27. package/dist/PrismicToolbar.js +6 -4
  28. package/dist/PrismicToolbar.js.map +1 -1
  29. package/dist/SliceZone.cjs +4 -17
  30. package/dist/SliceZone.cjs.map +1 -1
  31. package/dist/SliceZone.d.ts +127 -188
  32. package/dist/SliceZone.js +4 -17
  33. package/dist/SliceZone.js.map +1 -1
  34. package/dist/clientHooks.d.ts +357 -357
  35. package/dist/index.cjs +0 -2
  36. package/dist/index.cjs.map +1 -1
  37. package/dist/index.d.ts +21 -46
  38. package/dist/index.js +1 -4
  39. package/dist/index.js.map +1 -1
  40. package/dist/lib/__PRODUCTION__.d.ts +7 -7
  41. package/dist/lib/devMsg.d.ts +16 -16
  42. package/dist/lib/invariant.d.ts +24 -24
  43. package/dist/lib/isInternalURL.d.ts +8 -8
  44. package/dist/lib/pascalCase.d.ts +26 -26
  45. package/dist/package.json.cjs +1 -1
  46. package/dist/package.json.js +1 -1
  47. package/dist/react-server/PrismicLink.cjs +59 -0
  48. package/dist/react-server/PrismicLink.cjs.map +1 -0
  49. package/dist/react-server/PrismicLink.d.ts +72 -0
  50. package/dist/react-server/PrismicLink.js +42 -0
  51. package/dist/react-server/PrismicLink.js.map +1 -0
  52. package/dist/react-server/PrismicRichText.cjs +92 -0
  53. package/dist/react-server/PrismicRichText.cjs.map +1 -0
  54. package/dist/react-server/PrismicRichText.d.ts +104 -0
  55. package/dist/react-server/PrismicRichText.js +73 -0
  56. package/dist/react-server/PrismicRichText.js.map +1 -0
  57. package/dist/react-server/index.d.ts +4 -0
  58. package/dist/react-server/unsupported.cjs +97 -0
  59. package/dist/react-server/unsupported.cjs.map +1 -0
  60. package/dist/react-server/unsupported.d.ts +22 -0
  61. package/dist/react-server/unsupported.js +97 -0
  62. package/dist/react-server/unsupported.js.map +1 -0
  63. package/dist/react-server.cjs +44 -0
  64. package/dist/react-server.cjs.map +1 -0
  65. package/dist/react-server.js +41 -0
  66. package/dist/react-server.js.map +1 -0
  67. package/dist/types.d.ts +19 -19
  68. package/dist/usePrismicClient.d.ts +11 -11
  69. package/dist/usePrismicContext.d.ts +8 -8
  70. package/dist/usePrismicPreviewResolver.d.ts +45 -45
  71. package/dist/useStatefulPrismicClientMethod.cjs +6 -0
  72. package/dist/useStatefulPrismicClientMethod.cjs.map +1 -1
  73. package/dist/useStatefulPrismicClientMethod.d.ts +44 -44
  74. package/dist/useStatefulPrismicClientMethod.js +6 -0
  75. package/dist/useStatefulPrismicClientMethod.js.map +1 -1
  76. package/package.json +42 -47
  77. package/src/PrismicImage.tsx +30 -37
  78. package/src/PrismicLink.tsx +29 -259
  79. package/src/PrismicProvider.tsx +9 -8
  80. package/src/PrismicRichText.tsx +28 -275
  81. package/src/PrismicText.tsx +4 -5
  82. package/src/PrismicToolbar.tsx +7 -6
  83. package/src/SliceZone.tsx +8 -129
  84. package/src/index.ts +1 -9
  85. package/src/react-server/PrismicLink.tsx +179 -0
  86. package/src/react-server/PrismicRichText.tsx +267 -0
  87. package/src/react-server/index.ts +38 -0
  88. package/src/react-server/unsupported.ts +98 -0
  89. package/dist/lib/pascalCase.cjs +0 -10
  90. package/dist/lib/pascalCase.cjs.map +0 -1
  91. package/dist/lib/pascalCase.js +0 -10
  92. package/dist/lib/pascalCase.js.map +0 -1
@@ -1,116 +1,4 @@
1
- import * as React from "react";
2
- import * as prismicT from "@prismicio/types";
3
- import * as prismicH from "@prismicio/helpers";
4
- import { JSXFunctionSerializer, JSXMapSerializer } from "./types";
5
- import { PrismicLinkProps } from "./PrismicLink";
6
- /**
7
- * Props for `<PrismicRichText>`.
8
- */
9
- export type PrismicRichTextProps<LinkResolverFunction extends prismicH.LinkResolverFunction<any> = prismicH.LinkResolverFunction> = {
10
- /**
11
- * The Prismic Rich Text field to render.
12
- */
13
- field: prismicT.RichTextField | null | undefined;
14
- /**
15
- * The Link Resolver used to resolve links.
16
- *
17
- * @remarks
18
- * If your app uses Route Resolvers when querying for your Prismic
19
- * repository's content, a Link Resolver does not need to be provided.
20
- * @see Learn about Link Resolvers and Route Resolvers {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}
21
- */
22
- linkResolver?: LinkResolverFunction;
23
- /**
24
- * A function that maps a Rich Text block to a React component.
25
- *
26
- * @deprecated Use the `components` prop instead. Prefer using a map
27
- * serializer when possible.
28
- * @see Learn about Rich Text serializers {@link https://prismic.io/docs/core-concepts/html-serializer}
29
- */
30
- htmlSerializer?: JSXFunctionSerializer;
31
- /**
32
- * A map or function that maps a Rich Text block to a React component.
33
- *
34
- * @remarks
35
- * Prefer using a map serializer over the function serializer when possible.
36
- * The map serializer is simpler to maintain.
37
- * @example A map serializer.
38
- *
39
- * ```jsx
40
- * {
41
- * heading1: ({children}) => <Heading>{children}</Heading>
42
- * }
43
- * ```
44
- *
45
- * @example A function serializer.
46
- *
47
- * ```jsx
48
- * (type, node, content, children) => {
49
- * switch (type) {
50
- * case "heading1": {
51
- * return <Heading>{children}</Heading>;
52
- * }
53
- * }
54
- * };
55
- * ```
56
- */
57
- components?: JSXMapSerializer | JSXFunctionSerializer;
58
- /**
59
- * The React component rendered for links when the URL is internal.
60
- *
61
- * @defaultValue `<a>`
62
- */
63
- internalLinkComponent?: PrismicLinkProps["internalComponent"];
64
- /**
65
- * The React component rendered for links when the URL is external.
66
- *
67
- * @defaultValue `<a>`
68
- */
69
- externalLinkComponent?: PrismicLinkProps["externalComponent"];
70
- /**
71
- * The value to be rendered when the field is empty. If a fallback is not
72
- * given, `null` will be rendered.
73
- */
74
- fallback?: React.ReactNode;
75
- };
76
- /**
77
- * React component that renders content from a Prismic Rich Text field. By
78
- * default, HTML elements are rendered for each piece of content. A `heading1`
79
- * block will render an `<h1>` HTML element, for example. Links will use
80
- * `<PrismicLink>` by default which can be customized using the
81
- * `internalLinkComponent` and `externalLinkComponent` props.
82
- *
83
- * To customize the components that are rendered, provide a map or function
84
- * serializer to the `components` prop.
85
- *
86
- * Components can also be provided in a centralized location using the
87
- * `<PrismicProvider>` React context provider.
88
- *
89
- * @remarks
90
- * This component returns a React fragment with no wrapping element around the
91
- * content. If you need a wrapper, add a component around `<PrismicRichText>`.
92
- * @example Rendering a Rich Text field using the default HTMl elements.
93
- *
94
- * ```jsx
95
- * <PrismicRichText field={document.data.content} />;
96
- * ```
97
- *
98
- * @example Rendering a Rich Text field using a custom set of React components.
99
- *
100
- * ```jsx
101
- * <PrismicRichText
102
- * field={document.data.content}
103
- * components={{
104
- * heading1: ({ children }) => <Heading>{children}</Heading>,
105
- * }}
106
- * />;
107
- * ```
108
- *
109
- * @param props - Props for the component.
110
- *
111
- * @returns The Rich Text field's content as React components.
112
- *
113
- * @see Learn about Rich Text fields {@link https://prismic.io/docs/core-concepts/rich-text-title}
114
- * @see Learn about Rich Text serializers {@link https://prismic.io/docs/core-concepts/html-serializer}
115
- */
116
- export declare const PrismicRichText: <LinkResolverFunction extends prismicH.LinkResolverFunction<any> = prismicH.LinkResolverFunction<string>>(props: PrismicRichTextProps<LinkResolverFunction>) => JSX.Element | null;
1
+ import * as prismic from "@prismicio/client";
2
+ import { PrismicRichTextProps } from "./react-server/PrismicRichText";
3
+ export { PrismicRichTextProps };
4
+ export declare const PrismicRichText: <LinkResolverFunction extends prismic.LinkResolverFunction<any> = prismic.LinkResolverFunction>({ components, ...restProps }: PrismicRichTextProps<LinkResolverFunction>) => JSX.Element;
@@ -1,76 +1,11 @@
1
- import { jsx, Fragment } from "react/jsx-runtime";
2
- import * as React from "react";
3
- import * as prismicH from "@prismicio/helpers";
1
+ import { jsx } from "react/jsx-runtime";
4
2
  import * as prismicR from "@prismicio/richtext";
5
- import { PrismicLink } from "./PrismicLink.js";
3
+ import { PrismicRichText as PrismicRichText$1 } from "./react-server/PrismicRichText.js";
6
4
  import { usePrismicContext } from "./usePrismicContext.js";
7
- const createDefaultSerializer = (args) => prismicR.wrapMapSerializer({
8
- heading1: ({ children, key }) => /* @__PURE__ */ jsx("h1", { children }, key),
9
- heading2: ({ children, key }) => /* @__PURE__ */ jsx("h2", { children }, key),
10
- heading3: ({ children, key }) => /* @__PURE__ */ jsx("h3", { children }, key),
11
- heading4: ({ children, key }) => /* @__PURE__ */ jsx("h4", { children }, key),
12
- heading5: ({ children, key }) => /* @__PURE__ */ jsx("h5", { children }, key),
13
- heading6: ({ children, key }) => /* @__PURE__ */ jsx("h6", { children }, key),
14
- paragraph: ({ children, key }) => /* @__PURE__ */ jsx("p", { children }, key),
15
- preformatted: ({ node, key }) => /* @__PURE__ */ jsx("pre", { children: node.text }, key),
16
- strong: ({ children, key }) => /* @__PURE__ */ jsx("strong", { children }, key),
17
- em: ({ children, key }) => /* @__PURE__ */ jsx("em", { children }, key),
18
- listItem: ({ children, key }) => /* @__PURE__ */ jsx("li", { children }, key),
19
- oListItem: ({ children, key }) => /* @__PURE__ */ jsx("li", { children }, key),
20
- list: ({ children, key }) => /* @__PURE__ */ jsx("ul", { children }, key),
21
- oList: ({ children, key }) => /* @__PURE__ */ jsx("ol", { children }, key),
22
- image: ({ node, key }) => {
23
- const img = /* @__PURE__ */ jsx("img", { src: node.url, alt: node.alt ?? void 0, "data-copyright": node.copyright ? node.copyright : void 0 });
24
- return /* @__PURE__ */ jsx("p", { className: "block-img", children: node.linkTo ? /* @__PURE__ */ jsx(PrismicLink, { linkResolver: args.linkResolver, internalComponent: args.internalLinkComponent, externalComponent: args.externalLinkComponent, field: node.linkTo, children: img }) : img }, key);
25
- },
26
- embed: ({ node, key }) => /* @__PURE__ */ jsx("div", { "data-oembed": node.oembed.embed_url, "data-oembed-type": node.oembed.type, "data-oembed-provider": node.oembed.provider_name, dangerouslySetInnerHTML: { __html: node.oembed.html ?? "" } }, key),
27
- hyperlink: ({ node, children, key }) => /* @__PURE__ */ jsx(PrismicLink, { field: node.data, linkResolver: args.linkResolver, internalComponent: args.internalLinkComponent, externalComponent: args.externalLinkComponent, children }, key),
28
- label: ({ node, children, key }) => /* @__PURE__ */ jsx("span", { className: node.data.label, children }, key),
29
- span: ({ text, key }) => {
30
- const result = [];
31
- let i = 0;
32
- for (const line of text.split("\n")) {
33
- if (i > 0) {
34
- result.push(/* @__PURE__ */ jsx("br", {}, `${i}__break`));
35
- }
36
- result.push(/* @__PURE__ */ jsx(React.Fragment, { children: line }, `${i}__line`));
37
- i++;
38
- }
39
- return /* @__PURE__ */ jsx(React.Fragment, { children: result }, key);
40
- }
41
- });
42
- const PrismicRichText = (props) => {
5
+ const PrismicRichText = function PrismicRichText2({ components, ...restProps }) {
43
6
  const context = usePrismicContext();
44
- return React.useMemo(() => {
45
- if (prismicH.isFilled.richText(props.field)) {
46
- const linkResolver = props.linkResolver || context.linkResolver;
47
- const serializer = prismicR.composeSerializers(typeof props.components === "object" ? prismicR.wrapMapSerializer(props.components) : props.components, typeof context.richTextComponents === "object" ? prismicR.wrapMapSerializer(context.richTextComponents) : context.richTextComponents, createDefaultSerializer({
48
- linkResolver,
49
- internalLinkComponent: props.internalLinkComponent,
50
- externalLinkComponent: props.externalLinkComponent
51
- }));
52
- const serialized = prismicR.serialize(props.field, (type, node, text, children, key) => {
53
- const result = serializer(type, node, text, children, key);
54
- if (React.isValidElement(result) && result.key == null) {
55
- return React.cloneElement(result, { key });
56
- } else {
57
- return result;
58
- }
59
- });
60
- return /* @__PURE__ */ jsx(Fragment, { children: serialized });
61
- } else {
62
- return props.fallback != null ? /* @__PURE__ */ jsx(Fragment, { children: props.fallback }) : null;
63
- }
64
- }, [
65
- props.field,
66
- props.internalLinkComponent,
67
- props.externalLinkComponent,
68
- props.components,
69
- props.linkResolver,
70
- props.fallback,
71
- context.linkResolver,
72
- context.richTextComponents
73
- ]);
7
+ const serializer = prismicR.composeSerializers(typeof components === "object" ? prismicR.wrapMapSerializer(components) : components, typeof context.richTextComponents === "object" ? prismicR.wrapMapSerializer(context.richTextComponents) : context.richTextComponents);
8
+ return /* @__PURE__ */ jsx(PrismicRichText$1, { components: serializer, internalLinkComponent: context.internalLinkComponent, externalLinkComponent: context.externalLinkComponent, ...restProps });
74
9
  };
75
10
  export {
76
11
  PrismicRichText
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicRichText.js","sources":["../../src/PrismicRichText.tsx"],"sourcesContent":["/* eslint-disable react/display-name */\n/* eslint-disable react/prop-types */\n\nimport * as React from \"react\";\nimport * as prismicT from \"@prismicio/types\";\nimport * as prismicH from \"@prismicio/helpers\";\nimport * as prismicR from \"@prismicio/richtext\";\n\nimport { JSXFunctionSerializer, JSXMapSerializer } from \"./types\";\nimport { PrismicLink, PrismicLinkProps } from \"./PrismicLink\";\nimport { usePrismicContext } from \"./usePrismicContext\";\n\n/**\n * Props for `<PrismicRichText>`.\n */\nexport type PrismicRichTextProps<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tLinkResolverFunction extends prismicH.LinkResolverFunction<any> = prismicH.LinkResolverFunction,\n> = {\n\t/**\n\t * The Prismic Rich Text field to render.\n\t */\n\tfield: prismicT.RichTextField | null | undefined;\n\n\t/**\n\t * The Link Resolver used to resolve links.\n\t *\n\t * @remarks\n\t * If your app uses Route Resolvers when querying for your Prismic\n\t * repository's content, a Link Resolver does not need to be provided.\n\t * @see Learn about Link Resolvers and Route Resolvers {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * A function that maps a Rich Text block to a React component.\n\t *\n\t * @deprecated Use the `components` prop instead. Prefer using a map\n\t * serializer when possible.\n\t * @see Learn about Rich Text serializers {@link https://prismic.io/docs/core-concepts/html-serializer}\n\t */\n\thtmlSerializer?: JSXFunctionSerializer;\n\n\t/**\n\t * A map or function that maps a Rich Text block to a React component.\n\t *\n\t * @remarks\n\t * Prefer using a map serializer over the function serializer when possible.\n\t * The map serializer is simpler to maintain.\n\t * @example A map serializer.\n\t *\n\t * ```jsx\n\t * {\n\t * heading1: ({children}) => <Heading>{children}</Heading>\n\t * }\n\t * ```\n\t *\n\t * @example A function serializer.\n\t *\n\t * ```jsx\n\t * (type, node, content, children) => {\n\t * \tswitch (type) {\n\t * \t\tcase \"heading1\": {\n\t * \t\t\treturn <Heading>{children}</Heading>;\n\t * \t\t}\n\t * \t}\n\t * };\n\t * ```\n\t */\n\tcomponents?: JSXMapSerializer | JSXFunctionSerializer;\n\n\t/**\n\t * The React component rendered for links when the URL is internal.\n\t *\n\t * @defaultValue `<a>`\n\t */\n\tinternalLinkComponent?: PrismicLinkProps[\"internalComponent\"];\n\n\t/**\n\t * The React component rendered for links when the URL is external.\n\t *\n\t * @defaultValue `<a>`\n\t */\n\texternalLinkComponent?: PrismicLinkProps[\"externalComponent\"];\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?: React.ReactNode;\n};\n\ntype CreateDefaultSerializerArgs<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tLinkResolverFunction extends prismicH.LinkResolverFunction<any> = prismicH.LinkResolverFunction,\n> = {\n\tlinkResolver: LinkResolverFunction | undefined;\n\tinternalLinkComponent: PrismicRichTextProps[\"internalLinkComponent\"];\n\texternalLinkComponent: PrismicRichTextProps[\"externalLinkComponent\"];\n};\n\nconst createDefaultSerializer = (\n\targs: CreateDefaultSerializerArgs,\n): JSXFunctionSerializer =>\n\tprismicR.wrapMapSerializer({\n\t\theading1: ({ children, key }) => <h1 key={key}>{children}</h1>,\n\t\theading2: ({ children, key }) => <h2 key={key}>{children}</h2>,\n\t\theading3: ({ children, key }) => <h3 key={key}>{children}</h3>,\n\t\theading4: ({ children, key }) => <h4 key={key}>{children}</h4>,\n\t\theading5: ({ children, key }) => <h5 key={key}>{children}</h5>,\n\t\theading6: ({ children, key }) => <h6 key={key}>{children}</h6>,\n\t\tparagraph: ({ children, key }) => <p key={key}>{children}</p>,\n\t\tpreformatted: ({ node, key }) => <pre key={key}>{node.text}</pre>,\n\t\tstrong: ({ children, key }) => <strong key={key}>{children}</strong>,\n\t\tem: ({ children, key }) => <em key={key}>{children}</em>,\n\t\tlistItem: ({ children, key }) => <li key={key}>{children}</li>,\n\t\toListItem: ({ children, key }) => <li key={key}>{children}</li>,\n\t\tlist: ({ children, key }) => <ul key={key}>{children}</ul>,\n\t\toList: ({ children, key }) => <ol key={key}>{children}</ol>,\n\t\timage: ({ node, key }) => {\n\t\t\tconst img = (\n\t\t\t\t<img\n\t\t\t\t\tsrc={node.url}\n\t\t\t\t\talt={node.alt ?? undefined}\n\t\t\t\t\tdata-copyright={node.copyright ? node.copyright : undefined}\n\t\t\t\t/>\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\t<p key={key} className=\"block-img\">\n\t\t\t\t\t{node.linkTo ? (\n\t\t\t\t\t\t<PrismicLink\n\t\t\t\t\t\t\tlinkResolver={args.linkResolver}\n\t\t\t\t\t\t\tinternalComponent={args.internalLinkComponent}\n\t\t\t\t\t\t\texternalComponent={args.externalLinkComponent}\n\t\t\t\t\t\t\tfield={node.linkTo}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{img}\n\t\t\t\t\t\t</PrismicLink>\n\t\t\t\t\t) : (\n\t\t\t\t\t\timg\n\t\t\t\t\t)}\n\t\t\t\t</p>\n\t\t\t);\n\t\t},\n\t\tembed: ({ node, key }) => (\n\t\t\t<div\n\t\t\t\tkey={key}\n\t\t\t\tdata-oembed={node.oembed.embed_url}\n\t\t\t\tdata-oembed-type={node.oembed.type}\n\t\t\t\tdata-oembed-provider={node.oembed.provider_name}\n\t\t\t\tdangerouslySetInnerHTML={{ __html: node.oembed.html ?? \"\" }}\n\t\t\t/>\n\t\t),\n\t\thyperlink: ({ node, children, key }) => (\n\t\t\t<PrismicLink\n\t\t\t\tkey={key}\n\t\t\t\tfield={node.data}\n\t\t\t\tlinkResolver={args.linkResolver}\n\t\t\t\tinternalComponent={args.internalLinkComponent}\n\t\t\t\texternalComponent={args.externalLinkComponent}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</PrismicLink>\n\t\t),\n\t\tlabel: ({ node, children, key }) => (\n\t\t\t<span key={key} className={node.data.label}>\n\t\t\t\t{children}\n\t\t\t</span>\n\t\t),\n\t\tspan: ({ text, key }) => {\n\t\t\tconst result: React.ReactNode[] = [];\n\n\t\t\tlet i = 0;\n\t\t\tfor (const line of text.split(\"\\n\")) {\n\t\t\t\tif (i > 0) {\n\t\t\t\t\tresult.push(<br key={`${i}__break`} />);\n\t\t\t\t}\n\n\t\t\t\tresult.push(<React.Fragment key={`${i}__line`}>{line}</React.Fragment>);\n\n\t\t\t\ti++;\n\t\t\t}\n\n\t\t\treturn <React.Fragment key={key}>{result}</React.Fragment>;\n\t\t},\n\t});\n\n/**\n * React component that renders content from a Prismic Rich Text field. By\n * default, HTML elements are rendered for each piece of content. A `heading1`\n * block will render an `<h1>` HTML element, for example. Links will use\n * `<PrismicLink>` by default which can be customized using the\n * `internalLinkComponent` and `externalLinkComponent` props.\n *\n * To customize the components that are rendered, provide a map or function\n * serializer to the `components` prop.\n *\n * Components can also be provided in a centralized location using the\n * `<PrismicProvider>` React context provider.\n *\n * @remarks\n * This component returns a React fragment with no wrapping element around the\n * content. If you need a wrapper, add a component around `<PrismicRichText>`.\n * @example Rendering a Rich Text field using the default HTMl elements.\n *\n * ```jsx\n * <PrismicRichText field={document.data.content} />;\n * ```\n *\n * @example Rendering a Rich Text field using a custom set of React components.\n *\n * ```jsx\n * <PrismicRichText\n * \tfield={document.data.content}\n * \tcomponents={{\n * \t\theading1: ({ children }) => <Heading>{children}</Heading>,\n * \t}}\n * />;\n * ```\n *\n * @param props - Props for the component.\n *\n * @returns The Rich Text field's content as React components.\n *\n * @see Learn about Rich Text fields {@link https://prismic.io/docs/core-concepts/rich-text-title}\n * @see Learn about Rich Text serializers {@link https://prismic.io/docs/core-concepts/html-serializer}\n */\nexport const PrismicRichText = <\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tLinkResolverFunction extends prismicH.LinkResolverFunction<any> = prismicH.LinkResolverFunction,\n>(\n\tprops: PrismicRichTextProps<LinkResolverFunction>,\n): JSX.Element | null => {\n\tconst context = usePrismicContext();\n\n\treturn React.useMemo(() => {\n\t\tif (prismicH.isFilled.richText(props.field)) {\n\t\t\tconst linkResolver = props.linkResolver || context.linkResolver;\n\n\t\t\tconst serializer = prismicR.composeSerializers(\n\t\t\t\ttypeof props.components === \"object\"\n\t\t\t\t\t? prismicR.wrapMapSerializer(props.components)\n\t\t\t\t\t: props.components,\n\t\t\t\ttypeof context.richTextComponents === \"object\"\n\t\t\t\t\t? prismicR.wrapMapSerializer(context.richTextComponents)\n\t\t\t\t\t: context.richTextComponents,\n\t\t\t\tcreateDefaultSerializer({\n\t\t\t\t\tlinkResolver,\n\t\t\t\t\tinternalLinkComponent: props.internalLinkComponent,\n\t\t\t\t\texternalLinkComponent: props.externalLinkComponent,\n\t\t\t\t}),\n\t\t\t);\n\n\t\t\t// The serializer is wrapped in a higher-order function\n\t\t\t// that automatically applies a key to React Elements\n\t\t\t// if one is not already given.\n\t\t\tconst serialized = prismicR.serialize<JSX.Element>(\n\t\t\t\tprops.field,\n\t\t\t\t(type, node, text, children, key) => {\n\t\t\t\t\tconst result = serializer(type, node, text, children, key);\n\n\t\t\t\t\tif (React.isValidElement(result) && result.key == null) {\n\t\t\t\t\t\treturn React.cloneElement(result, { key });\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\n\t\t\treturn <>{serialized}</>;\n\t\t} else {\n\t\t\treturn props.fallback != null ? <>{props.fallback}</> : null;\n\t\t}\n\t}, [\n\t\tprops.field,\n\t\tprops.internalLinkComponent,\n\t\tprops.externalLinkComponent,\n\t\tprops.components,\n\t\tprops.linkResolver,\n\t\tprops.fallback,\n\t\tcontext.linkResolver,\n\t\tcontext.richTextComponents,\n\t]);\n};\n"],"names":[],"mappings":"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"}
1
+ {"version":3,"file":"PrismicRichText.js","sources":["../../src/PrismicRichText.tsx"],"sourcesContent":["\"use client\";\n\nimport * as prismic from \"@prismicio/client\";\nimport * as prismicR from \"@prismicio/richtext\";\n\nimport {\n\tPrismicRichText as ServerPrismicRichText,\n\tPrismicRichTextProps,\n} from \"./react-server/PrismicRichText\";\n\nimport { usePrismicContext } from \"./usePrismicContext\";\n\nexport { PrismicRichTextProps };\n\nexport const PrismicRichText = function PrismicRichText<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tLinkResolverFunction extends prismic.LinkResolverFunction<any> = prismic.LinkResolverFunction,\n>({ components, ...restProps }: PrismicRichTextProps<LinkResolverFunction>) {\n\tconst context = usePrismicContext();\n\n\tconst serializer = prismicR.composeSerializers(\n\t\ttypeof components === \"object\"\n\t\t\t? prismicR.wrapMapSerializer(components)\n\t\t\t: components,\n\t\ttypeof context.richTextComponents === \"object\"\n\t\t\t? prismicR.wrapMapSerializer(context.richTextComponents)\n\t\t\t: context.richTextComponents,\n\t);\n\n\treturn (\n\t\t<ServerPrismicRichText\n\t\t\tcomponents={serializer}\n\t\t\tinternalLinkComponent={context.internalLinkComponent}\n\t\t\texternalLinkComponent={context.externalLinkComponent}\n\t\t\t{...restProps}\n\t\t/>\n\t);\n};\n"],"names":["PrismicRichText","ServerPrismicRichText"],"mappings":";;;;AAcO,MAAM,kBAAkB,SAASA,iBAGtC,EAAE,YAAY,GAAG,aAAuD;AACzE,QAAM,UAAU;AAEV,QAAA,aAAa,SAAS,mBAC3B,OAAO,eAAe,WACnB,SAAS,kBAAkB,UAAU,IACrC,YACH,OAAO,QAAQ,uBAAuB,WACnC,SAAS,kBAAkB,QAAQ,kBAAkB,IACrD,QAAQ,kBAAkB;AAI7B,SAAA,oBAACC,mBACA,EAAA,YAAY,YACZ,uBAAuB,QAAQ,uBAC/B,uBAAuB,QAAQ,uBAC3B,GAAA,UAAU,CAAA;AAGjB;"}
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("react/jsx-runtime");
4
4
  const React = require("react");
5
- const prismicH = require("@prismicio/helpers");
5
+ const prismic = require("@prismicio/client");
6
6
  const __PRODUCTION__ = require("./lib/__PRODUCTION__.cjs");
7
7
  const devMsg = require("./lib/devMsg.cjs");
8
8
  function _interopNamespaceDefault(e) {
@@ -22,7 +22,7 @@ function _interopNamespaceDefault(e) {
22
22
  return Object.freeze(n);
23
23
  }
24
24
  const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
25
- const prismicH__namespace = /* @__PURE__ */ _interopNamespaceDefault(prismicH);
25
+ const prismic__namespace = /* @__PURE__ */ _interopNamespaceDefault(prismic);
26
26
  const PrismicText = (props) => {
27
27
  if (!__PRODUCTION__.__PRODUCTION__) {
28
28
  if (typeof props.field === "string") {
@@ -30,8 +30,8 @@ const PrismicText = (props) => {
30
30
  }
31
31
  }
32
32
  return React__namespace.useMemo(() => {
33
- if (prismicH__namespace.isFilled.richText(props.field)) {
34
- const text = prismicH__namespace.asText(props.field, props.separator);
33
+ if (prismic__namespace.isFilled.richText(props.field)) {
34
+ const text = prismic__namespace.asText(props.field, props.separator);
35
35
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: text });
36
36
  } else {
37
37
  return props.fallback != null ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: props.fallback }) : null;
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicText.cjs","sources":["../../src/PrismicText.tsx"],"sourcesContent":["import * as React from \"react\";\nimport * as prismicT from \"@prismicio/types\";\nimport * as prismicH from \"@prismicio/helpers\";\n\nimport { __PRODUCTION__ } from \"./lib/__PRODUCTION__\";\nimport { devMsg } from \"./lib/devMsg\";\n\n/**\n * Props for `<PrismicText>`.\n */\nexport type PrismicTextProps = {\n\t/**\n\t * The Prismic Rich Text field to render.\n\t */\n\tfield: prismicT.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/**\n\t * The separator used between blocks. Defaults to `\\n`.\n\t */\n\tseparator?: string;\n};\n\n/**\n * React component that renders content from a Prismic Rich Text field as plain\n * text.\n *\n * @remarks\n * This component returns a React fragment with no wrapping element around the\n * content. If you need a wrapper, add a component around `<PrismicText>`.\n * @example Rendering a Rich Text field as plain text.\n *\n * ```jsx\n * <PrismicText field={document.data.content} />;\n * ```\n *\n * @param props - Props for the component.\n *\n * @returns The Rich Text field's content as plain text.\n *\n * @see Learn about Rich Text fields {@link https://prismic.io/docs/core-concepts/rich-text-title}\n */\nexport const PrismicText = (props: PrismicTextProps): JSX.Element | null => {\n\tif (!__PRODUCTION__) {\n\t\tif (typeof props.field === \"string\") {\n\t\t\tthrow new Error(\n\t\t\t\t`[PrismicText] The \"field\" prop only accepts a Rich Text or Title 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);\n\t\t}\n\t}\n\n\treturn React.useMemo(() => {\n\t\tif (prismicH.isFilled.richText(props.field)) {\n\t\t\tconst text = prismicH.asText(props.field, props.separator);\n\n\t\t\treturn <>{text}</>;\n\t\t} else {\n\t\t\treturn props.fallback != null ? <>{props.fallback}</> : null;\n\t\t}\n\t}, [props.field, props.fallback, props.separator]);\n};\n"],"names":["__PRODUCTION__","devMsg","React","prismicH","jsx","Fragment"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA+Ca,MAAA,cAAc,CAAC,UAA+C;AAC1E,MAAI,CAACA,eAAAA,gBAAgB;AAChB,QAAA,OAAO,MAAM,UAAU,UAAU;AACpC,YAAM,IAAI,MACT,oRAAoRC,OAAA,OACnR,wDAAwD,GACtD;AAAA,IAEJ;AAAA,EACD;AAEM,SAAAC,iBAAM,QAAQ,MAAK;AACzB,QAAIC,oBAAS,SAAS,SAAS,MAAM,KAAK,GAAG;AAC5C,YAAM,OAAOA,oBAAS,OAAO,MAAM,OAAO,MAAM,SAAS;AAEzD,mEAAU,UAAK,KAAA,CAAA;AAAA,IAAA,OACT;AACN,aAAO,MAAM,YAAY,OAAUC,+BAAAC,WAAAA,UAAA,EAAA,UAAA,MAAM,SAAS,CAAA,IAAM;AAAA,IACxD;AAAA,EAAA,GACC,CAAC,MAAM,OAAO,MAAM,UAAU,MAAM,SAAS,CAAC;AAClD;;"}
1
+ {"version":3,"file":"PrismicText.cjs","sources":["../../src/PrismicText.tsx"],"sourcesContent":["import * as React from \"react\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { __PRODUCTION__ } from \"./lib/__PRODUCTION__\";\nimport { devMsg } from \"./lib/devMsg\";\n\n/**\n * Props for `<PrismicText>`.\n */\nexport type PrismicTextProps = {\n\t/**\n\t * The Prismic Rich Text field to render.\n\t */\n\tfield: prismic.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/**\n\t * The separator used between blocks. Defaults to `\\n`.\n\t */\n\tseparator?: string;\n};\n\n/**\n * React component that renders content from a Prismic Rich Text field as plain\n * text.\n *\n * @remarks\n * This component returns a React fragment with no wrapping element around the\n * content. If you need a wrapper, add a component around `<PrismicText>`.\n * @example Rendering a Rich Text field as plain text.\n *\n * ```jsx\n * <PrismicText field={document.data.content} />;\n * ```\n *\n * @param props - Props for the component.\n *\n * @returns The Rich Text field's content as plain text.\n *\n * @see Learn about Rich Text fields {@link https://prismic.io/docs/core-concepts/rich-text-title}\n */\nexport const PrismicText = (props: PrismicTextProps): JSX.Element | null => {\n\tif (!__PRODUCTION__) {\n\t\tif (typeof props.field === \"string\") {\n\t\t\tthrow new Error(\n\t\t\t\t`[PrismicText] The \"field\" prop only accepts a Rich Text or Title 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);\n\t\t}\n\t}\n\n\treturn React.useMemo(() => {\n\t\tif (prismic.isFilled.richText(props.field)) {\n\t\t\tconst text = prismic.asText(props.field, props.separator);\n\n\t\t\treturn <>{text}</>;\n\t\t} else {\n\t\t\treturn props.fallback != null ? <>{props.fallback}</> : null;\n\t\t}\n\t}, [props.field, props.fallback, props.separator]);\n};\n"],"names":["__PRODUCTION__","devMsg","React","prismic","jsx","Fragment"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA8Ca,MAAA,cAAc,CAAC,UAA+C;AAC1E,MAAI,CAACA,eAAAA,gBAAgB;AAChB,QAAA,OAAO,MAAM,UAAU,UAAU;AACpC,YAAM,IAAI,MACT,oRAAoRC,OAAA,OACnR,wDAAwD,GACtD;AAAA,IAEJ;AAAA,EACD;AAEM,SAAAC,iBAAM,QAAQ,MAAK;AACzB,QAAIC,mBAAQ,SAAS,SAAS,MAAM,KAAK,GAAG;AAC3C,YAAM,OAAOA,mBAAQ,OAAO,MAAM,OAAO,MAAM,SAAS;AAExD,mEAAU,UAAK,KAAA,CAAA;AAAA,IAAA,OACT;AACN,aAAO,MAAM,YAAY,OAAUC,+BAAAC,WAAAA,UAAA,EAAA,UAAA,MAAM,SAAS,CAAA,IAAM;AAAA,IACxD;AAAA,EAAA,GACC,CAAC,MAAM,OAAO,MAAM,UAAU,MAAM,SAAS,CAAC;AAClD;;"}
@@ -1,39 +1,39 @@
1
- import * as prismicT from "@prismicio/types";
2
- /**
3
- * Props for `<PrismicText>`.
4
- */
5
- export type PrismicTextProps = {
6
- /**
7
- * The Prismic Rich Text field to render.
8
- */
9
- field: prismicT.RichTextField | null | undefined;
10
- /**
11
- * The string rendered when the field is empty. If a fallback is not given,
12
- * `null` will be rendered.
13
- */
14
- fallback?: string;
15
- /**
16
- * The separator used between blocks. Defaults to `\n`.
17
- */
18
- separator?: string;
19
- };
20
- /**
21
- * React component that renders content from a Prismic Rich Text field as plain
22
- * text.
23
- *
24
- * @remarks
25
- * This component returns a React fragment with no wrapping element around the
26
- * content. If you need a wrapper, add a component around `<PrismicText>`.
27
- * @example Rendering a Rich Text field as plain text.
28
- *
29
- * ```jsx
30
- * <PrismicText field={document.data.content} />;
31
- * ```
32
- *
33
- * @param props - Props for the component.
34
- *
35
- * @returns The Rich Text field's content as plain text.
36
- *
37
- * @see Learn about Rich Text fields {@link https://prismic.io/docs/core-concepts/rich-text-title}
38
- */
39
- export declare const PrismicText: (props: PrismicTextProps) => JSX.Element | null;
1
+ import * as prismic from "@prismicio/client";
2
+ /**
3
+ * Props for `<PrismicText>`.
4
+ */
5
+ export type PrismicTextProps = {
6
+ /**
7
+ * The Prismic Rich Text field to render.
8
+ */
9
+ field: prismic.RichTextField | null | undefined;
10
+ /**
11
+ * The string rendered when the field is empty. If a fallback is not given,
12
+ * `null` will be rendered.
13
+ */
14
+ fallback?: string;
15
+ /**
16
+ * The separator used between blocks. Defaults to `\n`.
17
+ */
18
+ separator?: string;
19
+ };
20
+ /**
21
+ * React component that renders content from a Prismic Rich Text field as plain
22
+ * text.
23
+ *
24
+ * @remarks
25
+ * This component returns a React fragment with no wrapping element around the
26
+ * content. If you need a wrapper, add a component around `<PrismicText>`.
27
+ * @example Rendering a Rich Text field as plain text.
28
+ *
29
+ * ```jsx
30
+ * <PrismicText field={document.data.content} />;
31
+ * ```
32
+ *
33
+ * @param props - Props for the component.
34
+ *
35
+ * @returns The Rich Text field's content as plain text.
36
+ *
37
+ * @see Learn about Rich Text fields {@link https://prismic.io/docs/core-concepts/rich-text-title}
38
+ */
39
+ export declare const PrismicText: (props: PrismicTextProps) => JSX.Element | null;
@@ -1,6 +1,6 @@
1
1
  import { jsx, Fragment } from "react/jsx-runtime";
2
2
  import * as React from "react";
3
- import * as prismicH from "@prismicio/helpers";
3
+ import * as prismic from "@prismicio/client";
4
4
  import { __PRODUCTION__ } from "./lib/__PRODUCTION__.js";
5
5
  import { devMsg } from "./lib/devMsg.js";
6
6
  const PrismicText = (props) => {
@@ -10,8 +10,8 @@ const PrismicText = (props) => {
10
10
  }
11
11
  }
12
12
  return React.useMemo(() => {
13
- if (prismicH.isFilled.richText(props.field)) {
14
- const text = prismicH.asText(props.field, props.separator);
13
+ if (prismic.isFilled.richText(props.field)) {
14
+ const text = prismic.asText(props.field, props.separator);
15
15
  return /* @__PURE__ */ jsx(Fragment, { children: text });
16
16
  } else {
17
17
  return props.fallback != null ? /* @__PURE__ */ jsx(Fragment, { children: props.fallback }) : null;
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicText.js","sources":["../../src/PrismicText.tsx"],"sourcesContent":["import * as React from \"react\";\nimport * as prismicT from \"@prismicio/types\";\nimport * as prismicH from \"@prismicio/helpers\";\n\nimport { __PRODUCTION__ } from \"./lib/__PRODUCTION__\";\nimport { devMsg } from \"./lib/devMsg\";\n\n/**\n * Props for `<PrismicText>`.\n */\nexport type PrismicTextProps = {\n\t/**\n\t * The Prismic Rich Text field to render.\n\t */\n\tfield: prismicT.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/**\n\t * The separator used between blocks. Defaults to `\\n`.\n\t */\n\tseparator?: string;\n};\n\n/**\n * React component that renders content from a Prismic Rich Text field as plain\n * text.\n *\n * @remarks\n * This component returns a React fragment with no wrapping element around the\n * content. If you need a wrapper, add a component around `<PrismicText>`.\n * @example Rendering a Rich Text field as plain text.\n *\n * ```jsx\n * <PrismicText field={document.data.content} />;\n * ```\n *\n * @param props - Props for the component.\n *\n * @returns The Rich Text field's content as plain text.\n *\n * @see Learn about Rich Text fields {@link https://prismic.io/docs/core-concepts/rich-text-title}\n */\nexport const PrismicText = (props: PrismicTextProps): JSX.Element | null => {\n\tif (!__PRODUCTION__) {\n\t\tif (typeof props.field === \"string\") {\n\t\t\tthrow new Error(\n\t\t\t\t`[PrismicText] The \"field\" prop only accepts a Rich Text or Title 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);\n\t\t}\n\t}\n\n\treturn React.useMemo(() => {\n\t\tif (prismicH.isFilled.richText(props.field)) {\n\t\t\tconst text = prismicH.asText(props.field, props.separator);\n\n\t\t\treturn <>{text}</>;\n\t\t} else {\n\t\t\treturn props.fallback != null ? <>{props.fallback}</> : null;\n\t\t}\n\t}, [props.field, props.fallback, props.separator]);\n};\n"],"names":[],"mappings":";;;;;AA+Ca,MAAA,cAAc,CAAC,UAA+C;AAC1E,MAAI,CAAC,gBAAgB;AAChB,QAAA,OAAO,MAAM,UAAU,UAAU;AACpC,YAAM,IAAI,MACT,oRAAoR,OACnR,wDAAwD,GACtD;AAAA,IAEJ;AAAA,EACD;AAEM,SAAA,MAAM,QAAQ,MAAK;AACzB,QAAI,SAAS,SAAS,SAAS,MAAM,KAAK,GAAG;AAC5C,YAAM,OAAO,SAAS,OAAO,MAAM,OAAO,MAAM,SAAS;AAEzD,6CAAU,UAAK,KAAA,CAAA;AAAA,IAAA,OACT;AACN,aAAO,MAAM,YAAY,OAAU,oBAAA,UAAA,EAAA,UAAA,MAAM,SAAS,CAAA,IAAM;AAAA,IACxD;AAAA,EAAA,GACC,CAAC,MAAM,OAAO,MAAM,UAAU,MAAM,SAAS,CAAC;AAClD;"}
1
+ {"version":3,"file":"PrismicText.js","sources":["../../src/PrismicText.tsx"],"sourcesContent":["import * as React from \"react\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { __PRODUCTION__ } from \"./lib/__PRODUCTION__\";\nimport { devMsg } from \"./lib/devMsg\";\n\n/**\n * Props for `<PrismicText>`.\n */\nexport type PrismicTextProps = {\n\t/**\n\t * The Prismic Rich Text field to render.\n\t */\n\tfield: prismic.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/**\n\t * The separator used between blocks. Defaults to `\\n`.\n\t */\n\tseparator?: string;\n};\n\n/**\n * React component that renders content from a Prismic Rich Text field as plain\n * text.\n *\n * @remarks\n * This component returns a React fragment with no wrapping element around the\n * content. If you need a wrapper, add a component around `<PrismicText>`.\n * @example Rendering a Rich Text field as plain text.\n *\n * ```jsx\n * <PrismicText field={document.data.content} />;\n * ```\n *\n * @param props - Props for the component.\n *\n * @returns The Rich Text field's content as plain text.\n *\n * @see Learn about Rich Text fields {@link https://prismic.io/docs/core-concepts/rich-text-title}\n */\nexport const PrismicText = (props: PrismicTextProps): JSX.Element | null => {\n\tif (!__PRODUCTION__) {\n\t\tif (typeof props.field === \"string\") {\n\t\t\tthrow new Error(\n\t\t\t\t`[PrismicText] The \"field\" prop only accepts a Rich Text or Title 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);\n\t\t}\n\t}\n\n\treturn React.useMemo(() => {\n\t\tif (prismic.isFilled.richText(props.field)) {\n\t\t\tconst text = prismic.asText(props.field, props.separator);\n\n\t\t\treturn <>{text}</>;\n\t\t} else {\n\t\t\treturn props.fallback != null ? <>{props.fallback}</> : null;\n\t\t}\n\t}, [props.field, props.fallback, props.separator]);\n};\n"],"names":[],"mappings":";;;;;AA8Ca,MAAA,cAAc,CAAC,UAA+C;AAC1E,MAAI,CAAC,gBAAgB;AAChB,QAAA,OAAO,MAAM,UAAU,UAAU;AACpC,YAAM,IAAI,MACT,oRAAoR,OACnR,wDAAwD,GACtD;AAAA,IAEJ;AAAA,EACD;AAEM,SAAA,MAAM,QAAQ,MAAK;AACzB,QAAI,QAAQ,SAAS,SAAS,MAAM,KAAK,GAAG;AAC3C,YAAM,OAAO,QAAQ,OAAO,MAAM,OAAO,MAAM,SAAS;AAExD,6CAAU,UAAK,KAAA,CAAA;AAAA,IAAA,OACT;AACN,aAAO,MAAM,YAAY,OAAU,oBAAA,UAAA,EAAA,UAAA,MAAM,SAAS,CAAA,IAAM;AAAA,IACxD;AAAA,EAAA,GACC,CAAC,MAAM,OAAO,MAAM,UAAU,MAAM,SAAS,CAAC;AAClD;"}
@@ -1,6 +1,9 @@
1
+ 'use client';
2
+ 'use client';
1
3
  "use strict";
2
4
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
5
  const React = require("react");
6
+ const prismic = require("@prismicio/client");
4
7
  function _interopNamespaceDefault(e) {
5
8
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
6
9
  if (e) {
@@ -18,8 +21,8 @@ function _interopNamespaceDefault(e) {
18
21
  return Object.freeze(n);
19
22
  }
20
23
  const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
21
- const PrismicToolbar = ({ repositoryName, type = "new" }) => {
22
- const src = `https://static.cdn.prismic.io/prismic.js?repo=${repositoryName}${type === "new" ? "&new=true" : ""}`;
24
+ const PrismicToolbar = ({ repositoryName }) => {
25
+ const src = prismic.getToolbarSrc(repositoryName);
23
26
  React__namespace.useEffect(() => {
24
27
  const existingScript = document.querySelector(`script[src="${src}"]`);
25
28
  if (!existingScript) {
@@ -28,13 +31,12 @@ const PrismicToolbar = ({ repositoryName, type = "new" }) => {
28
31
  script.defer = true;
29
32
  script.dataset.prismicToolbar = "";
30
33
  script.dataset.repositoryName = repositoryName;
31
- script.dataset.type = type;
32
34
  if (process.env.NODE_ENV === "test") {
33
35
  script._evaluateScript = false;
34
36
  }
35
37
  document.body.appendChild(script);
36
38
  }
37
- }, [repositoryName, type, src]);
39
+ }, [repositoryName, src]);
38
40
  return null;
39
41
  };
40
42
  exports.PrismicToolbar = PrismicToolbar;
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicToolbar.cjs","sources":["../../src/PrismicToolbar.tsx"],"sourcesContent":["import * as React from \"react\";\n\n/**\n * Props for `<PrismicToolbar>`.\n */\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 * The type of toolbar needed for the repository. Defaults to `\"new\"`.\n\t *\n\t * @see To check which version you need, view the Prismic Toolbar documentation {@link https://prismic.io/docs/technologies/previews-and-the-prismic-toolbar-reactjs}\n\t */\n\ttype?: \"new\" | \"legacy\";\n};\n\n/**\n * React component that injects the Prismic Toolbar into the app. This component\n * can be placed anywhere in the React tree.\n */\nexport const PrismicToolbar = ({\n\trepositoryName,\n\ttype = \"new\",\n}: PrismicToolbarProps): null => {\n\tconst src = `https://static.cdn.prismic.io/prismic.js?repo=${repositoryName}${\n\t\ttype === \"new\" ? \"&new=true\" : \"\"\n\t}`;\n\n\tReact.useEffect(() => {\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\t\t\tscript.dataset.type = type;\n\n\t\t\t// Disable Happy DOM `<script>` evaluation during\n\t\t\t// tests.\n\t\t\t//\n\t\t\t// This is a patch ONLY INCLUDED DURING TESTS. It will\n\t\t\t// be pruned during code minification in non-test\n\t\t\t// environments.\n\t\t\t//\n\t\t\t// @see https://github.com/capricorn86/happy-dom/blob/02ae081e36f990c06171eda44f9d885fd9413d73/packages/happy-dom/src/nodes/html-script-element/HTMLScriptElement.ts#L191-L209\n\t\t\tif (process.env.NODE_ENV === \"test\") {\n\t\t\t\t// @ts-expect-error - `_evaluateScript` is a Happy DOM-specific property.\n\t\t\t\tscript._evaluateScript = false;\n\t\t\t}\n\n\t\t\tdocument.body.appendChild(script);\n\t\t}\n\t}, [repositoryName, type, src]);\n\n\treturn null;\n};\n"],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;AAwBO,MAAM,iBAAiB,CAAC,EAC9B,gBACA,OAAO,YACwB;AAC/B,QAAM,MAAM,iDAAiD,iBAC5D,SAAS,QAAQ,cAAc;AAGhCA,mBAAM,UAAU,MAAK;AACpB,UAAM,iBAAiB,SAAS,cAAc,eAAe,OAAO;AAEpE,QAAI,CAAC,gBAAgB;AACd,YAAA,SAAS,SAAS,cAAc,QAAQ;AAC9C,aAAO,MAAM;AACb,aAAO,QAAQ;AAGf,aAAO,QAAQ,iBAAiB;AAChC,aAAO,QAAQ,iBAAiB;AAChC,aAAO,QAAQ,OAAO;AAUlB,UAAA,QAAQ,IAAI,aAAa,QAAQ;AAEpC,eAAO,kBAAkB;AAAA,MACzB;AAEQ,eAAA,KAAK,YAAY,MAAM;AAAA,IAChC;AAAA,EACC,GAAA,CAAC,gBAAgB,MAAM,GAAG,CAAC;AAEvB,SAAA;AACR;;"}
1
+ {"version":3,"file":"PrismicToolbar.cjs","sources":["../../src/PrismicToolbar.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { getToolbarSrc } from \"@prismicio/client\";\n\n/**\n * Props for `<PrismicToolbar>`.\n */\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 * The type of toolbar needed for the repository. Defaults to `\"new\"`.\n\t *\n\t * @deprecated All repositories use the \"new\"-type toolbar. This option can be\n\t * removed.\n\t * @see To check which version you need, view the Prismic Toolbar documentation {@link https://prismic.io/docs/technologies/previews-and-the-prismic-toolbar-reactjs}\n\t */\n\ttype?: \"new\" | \"legacy\";\n};\n\n/**\n * React component that injects the Prismic Toolbar into the app. This component\n * can be placed anywhere in the React tree.\n */\nexport const PrismicToolbar = ({\n\trepositoryName,\n}: PrismicToolbarProps): null => {\n\tconst src = getToolbarSrc(repositoryName);\n\n\tReact.useEffect(() => {\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\n\t\t\t// tests.\n\t\t\t//\n\t\t\t// This is a patch ONLY INCLUDED DURING TESTS. It will\n\t\t\t// be pruned during code minification in non-test\n\t\t\t// environments.\n\t\t\t//\n\t\t\t// @see https://github.com/capricorn86/happy-dom/blob/02ae081e36f990c06171eda44f9d885fd9413d73/packages/happy-dom/src/nodes/html-script-element/HTMLScriptElement.ts#L191-L209\n\t\t\tif (process.env.NODE_ENV === \"test\") {\n\t\t\t\t// @ts-expect-error - `_evaluateScript` is a Happy DOM-specific property.\n\t\t\t\tscript._evaluateScript = false;\n\t\t\t}\n\n\t\t\tdocument.body.appendChild(script);\n\t\t}\n\t}, [repositoryName, src]);\n\n\treturn null;\n};\n"],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA6BO;AAGA;AAENA;AACC;AAEA;AACO;AACN;AACA;AAGA;AACA;AAUI;AAEH;AAAyB;AAGjB;AAAuB;AAChC;AAGK;AACR;;"}
@@ -1,21 +1,23 @@
1
- /**
2
- * Props for `<PrismicToolbar>`.
3
- */
4
- export type PrismicToolbarProps = {
5
- /**
6
- * The name of the Prismic repository. For example, `"my-repo"` if the
7
- * repository URL is `my-repo.prismic.io`.
8
- */
9
- repositoryName: string;
10
- /**
11
- * The type of toolbar needed for the repository. Defaults to `"new"`.
12
- *
13
- * @see To check which version you need, view the Prismic Toolbar documentation {@link https://prismic.io/docs/technologies/previews-and-the-prismic-toolbar-reactjs}
14
- */
15
- type?: "new" | "legacy";
16
- };
17
- /**
18
- * React component that injects the Prismic Toolbar into the app. This component
19
- * can be placed anywhere in the React tree.
20
- */
21
- export declare const PrismicToolbar: ({ repositoryName, type, }: PrismicToolbarProps) => null;
1
+ /**
2
+ * Props for `<PrismicToolbar>`.
3
+ */
4
+ export type PrismicToolbarProps = {
5
+ /**
6
+ * The name of the Prismic repository. For example, `"my-repo"` if the
7
+ * repository URL is `my-repo.prismic.io`.
8
+ */
9
+ repositoryName: string;
10
+ /**
11
+ * The type of toolbar needed for the repository. Defaults to `"new"`.
12
+ *
13
+ * @deprecated All repositories use the "new"-type toolbar. This option can be
14
+ * removed.
15
+ * @see To check which version you need, view the Prismic Toolbar documentation {@link https://prismic.io/docs/technologies/previews-and-the-prismic-toolbar-reactjs}
16
+ */
17
+ type?: "new" | "legacy";
18
+ };
19
+ /**
20
+ * React component that injects the Prismic Toolbar into the app. This component
21
+ * can be placed anywhere in the React tree.
22
+ */
23
+ export declare const PrismicToolbar: ({ repositoryName, }: PrismicToolbarProps) => null;
@@ -1,6 +1,9 @@
1
+ 'use client';
2
+ 'use client';
1
3
  import * as React from "react";
2
- const PrismicToolbar = ({ repositoryName, type = "new" }) => {
3
- const src = `https://static.cdn.prismic.io/prismic.js?repo=${repositoryName}${type === "new" ? "&new=true" : ""}`;
4
+ import { getToolbarSrc } from "@prismicio/client";
5
+ const PrismicToolbar = ({ repositoryName }) => {
6
+ const src = getToolbarSrc(repositoryName);
4
7
  React.useEffect(() => {
5
8
  const existingScript = document.querySelector(`script[src="${src}"]`);
6
9
  if (!existingScript) {
@@ -9,13 +12,12 @@ const PrismicToolbar = ({ repositoryName, type = "new" }) => {
9
12
  script.defer = true;
10
13
  script.dataset.prismicToolbar = "";
11
14
  script.dataset.repositoryName = repositoryName;
12
- script.dataset.type = type;
13
15
  if (process.env.NODE_ENV === "test") {
14
16
  script._evaluateScript = false;
15
17
  }
16
18
  document.body.appendChild(script);
17
19
  }
18
- }, [repositoryName, type, src]);
20
+ }, [repositoryName, src]);
19
21
  return null;
20
22
  };
21
23
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicToolbar.js","sources":["../../src/PrismicToolbar.tsx"],"sourcesContent":["import * as React from \"react\";\n\n/**\n * Props for `<PrismicToolbar>`.\n */\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 * The type of toolbar needed for the repository. Defaults to `\"new\"`.\n\t *\n\t * @see To check which version you need, view the Prismic Toolbar documentation {@link https://prismic.io/docs/technologies/previews-and-the-prismic-toolbar-reactjs}\n\t */\n\ttype?: \"new\" | \"legacy\";\n};\n\n/**\n * React component that injects the Prismic Toolbar into the app. This component\n * can be placed anywhere in the React tree.\n */\nexport const PrismicToolbar = ({\n\trepositoryName,\n\ttype = \"new\",\n}: PrismicToolbarProps): null => {\n\tconst src = `https://static.cdn.prismic.io/prismic.js?repo=${repositoryName}${\n\t\ttype === \"new\" ? \"&new=true\" : \"\"\n\t}`;\n\n\tReact.useEffect(() => {\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\t\t\tscript.dataset.type = type;\n\n\t\t\t// Disable Happy DOM `<script>` evaluation during\n\t\t\t// tests.\n\t\t\t//\n\t\t\t// This is a patch ONLY INCLUDED DURING TESTS. It will\n\t\t\t// be pruned during code minification in non-test\n\t\t\t// environments.\n\t\t\t//\n\t\t\t// @see https://github.com/capricorn86/happy-dom/blob/02ae081e36f990c06171eda44f9d885fd9413d73/packages/happy-dom/src/nodes/html-script-element/HTMLScriptElement.ts#L191-L209\n\t\t\tif (process.env.NODE_ENV === \"test\") {\n\t\t\t\t// @ts-expect-error - `_evaluateScript` is a Happy DOM-specific property.\n\t\t\t\tscript._evaluateScript = false;\n\t\t\t}\n\n\t\t\tdocument.body.appendChild(script);\n\t\t}\n\t}, [repositoryName, type, src]);\n\n\treturn null;\n};\n"],"names":[],"mappings":";AAwBO,MAAM,iBAAiB,CAAC,EAC9B,gBACA,OAAO,YACwB;AAC/B,QAAM,MAAM,iDAAiD,iBAC5D,SAAS,QAAQ,cAAc;AAGhC,QAAM,UAAU,MAAK;AACpB,UAAM,iBAAiB,SAAS,cAAc,eAAe,OAAO;AAEpE,QAAI,CAAC,gBAAgB;AACd,YAAA,SAAS,SAAS,cAAc,QAAQ;AAC9C,aAAO,MAAM;AACb,aAAO,QAAQ;AAGf,aAAO,QAAQ,iBAAiB;AAChC,aAAO,QAAQ,iBAAiB;AAChC,aAAO,QAAQ,OAAO;AAUlB,UAAA,QAAQ,IAAI,aAAa,QAAQ;AAEpC,eAAO,kBAAkB;AAAA,MACzB;AAEQ,eAAA,KAAK,YAAY,MAAM;AAAA,IAChC;AAAA,EACC,GAAA,CAAC,gBAAgB,MAAM,GAAG,CAAC;AAEvB,SAAA;AACR;"}
1
+ {"version":3,"file":"PrismicToolbar.js","sources":["../../src/PrismicToolbar.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { getToolbarSrc } from \"@prismicio/client\";\n\n/**\n * Props for `<PrismicToolbar>`.\n */\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 * The type of toolbar needed for the repository. Defaults to `\"new\"`.\n\t *\n\t * @deprecated All repositories use the \"new\"-type toolbar. This option can be\n\t * removed.\n\t * @see To check which version you need, view the Prismic Toolbar documentation {@link https://prismic.io/docs/technologies/previews-and-the-prismic-toolbar-reactjs}\n\t */\n\ttype?: \"new\" | \"legacy\";\n};\n\n/**\n * React component that injects the Prismic Toolbar into the app. This component\n * can be placed anywhere in the React tree.\n */\nexport const PrismicToolbar = ({\n\trepositoryName,\n}: PrismicToolbarProps): null => {\n\tconst src = getToolbarSrc(repositoryName);\n\n\tReact.useEffect(() => {\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\n\t\t\t// tests.\n\t\t\t//\n\t\t\t// This is a patch ONLY INCLUDED DURING TESTS. It will\n\t\t\t// be pruned during code minification in non-test\n\t\t\t// environments.\n\t\t\t//\n\t\t\t// @see https://github.com/capricorn86/happy-dom/blob/02ae081e36f990c06171eda44f9d885fd9413d73/packages/happy-dom/src/nodes/html-script-element/HTMLScriptElement.ts#L191-L209\n\t\t\tif (process.env.NODE_ENV === \"test\") {\n\t\t\t\t// @ts-expect-error - `_evaluateScript` is a Happy DOM-specific property.\n\t\t\t\tscript._evaluateScript = false;\n\t\t\t}\n\n\t\t\tdocument.body.appendChild(script);\n\t\t}\n\t}, [repositoryName, src]);\n\n\treturn null;\n};\n"],"names":[],"mappings":";;;;AA6BO;AAGA;AAEN;AACC;AAEA;AACO;AACN;AACA;AAGA;AACA;AAUI;AAEH;AAAyB;AAGjB;AAAuB;AAChC;AAGK;AACR;;;;"}
@@ -3,7 +3,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("react/jsx-runtime");
4
4
  const React = require("react");
5
5
  const __PRODUCTION__ = require("./lib/__PRODUCTION__.cjs");
6
- const pascalCase = require("./lib/pascalCase.cjs");
7
6
  function _interopNamespaceDefault(e) {
8
7
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
9
8
  if (e) {
@@ -23,34 +22,22 @@ function _interopNamespaceDefault(e) {
23
22
  const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
24
23
  const TODOSliceComponent = __PRODUCTION__.__PRODUCTION__ ? () => null : ({ slice }) => {
25
24
  const type = "slice_type" in slice ? slice.slice_type : slice.type;
26
- React__namespace.useEffect(() => {
27
- console.warn(`[SliceZone] Could not find a component for Slice type "${type}"`, slice);
28
- }, [slice, type]);
25
+ console.warn(`[SliceZone] Could not find a component for Slice type "${type}"`);
29
26
  return /* @__PURE__ */ jsxRuntime.jsxs("section", { "data-slice-zone-todo-component": "", "data-slice-type": type, children: [
30
27
  "Could not find a component for Slice type “",
31
28
  type,
32
29
  "”"
33
30
  ] });
34
31
  };
35
- const SliceZone = ({ slices = [], components = {}, resolver, defaultComponent = TODOSliceComponent, context = {} }) => {
32
+ const SliceZone = ({ slices = [], components = {}, defaultComponent = TODOSliceComponent, context = {} }) => {
36
33
  const renderedSlices = React__namespace.useMemo(() => {
37
34
  return slices.map((slice, index) => {
38
35
  const type = "slice_type" in slice ? slice.slice_type : slice.type;
39
- let Comp = components[type] || defaultComponent;
40
- if (resolver) {
41
- const resolvedComp = resolver({
42
- slice,
43
- sliceName: pascalCase.pascalCase(type),
44
- i: index
45
- });
46
- if (resolvedComp) {
47
- Comp = resolvedComp;
48
- }
49
- }
36
+ const Comp = components[type] || defaultComponent;
50
37
  const key = "id" in slice && slice.id ? slice.id : `${index}-${JSON.stringify(slice)}`;
51
38
  return /* @__PURE__ */ jsxRuntime.jsx(Comp, { slice, index, slices, context }, key);
52
39
  });
53
- }, [components, context, defaultComponent, slices, resolver]);
40
+ }, [components, context, defaultComponent, slices]);
54
41
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderedSlices });
55
42
  };
56
43
  exports.SliceZone = SliceZone;