@prismicio/react 3.2.1 → 3.2.2-canary.8d3ad6d

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 (47) hide show
  1. package/dist/PrismicImage.d.ts +66 -72
  2. package/dist/PrismicImage.d.ts.map +1 -0
  3. package/dist/PrismicImage.js +54 -47
  4. package/dist/PrismicImage.js.map +1 -1
  5. package/dist/PrismicLink.d.ts +71 -64
  6. package/dist/PrismicLink.d.ts.map +1 -0
  7. package/dist/PrismicLink.js +59 -40
  8. package/dist/PrismicLink.js.map +1 -1
  9. package/dist/PrismicRichText.d.ts +79 -100
  10. package/dist/PrismicRichText.d.ts.map +1 -0
  11. package/dist/PrismicRichText.js +125 -71
  12. package/dist/PrismicRichText.js.map +1 -1
  13. package/dist/PrismicTable.d.ts +58 -76
  14. package/dist/PrismicTable.d.ts.map +1 -0
  15. package/dist/PrismicTable.js +68 -21
  16. package/dist/PrismicTable.js.map +1 -1
  17. package/dist/PrismicText.d.ts +21 -25
  18. package/dist/PrismicText.d.ts.map +1 -0
  19. package/dist/PrismicText.js +30 -23
  20. package/dist/PrismicText.js.map +1 -1
  21. package/dist/PrismicToolbar.d.ts +21 -9
  22. package/dist/PrismicToolbar.d.ts.map +1 -0
  23. package/dist/PrismicToolbar.js +32 -19
  24. package/dist/PrismicToolbar.js.map +1 -1
  25. package/dist/SliceZone.d.ts +84 -83
  26. package/dist/SliceZone.d.ts.map +1 -0
  27. package/dist/SliceZone.js +54 -27
  28. package/dist/SliceZone.js.map +1 -1
  29. package/dist/index.d.ts +9 -15
  30. package/dist/index.js +4 -14
  31. package/dist/lib/devMsg.js +23 -6
  32. package/dist/lib/devMsg.js.map +1 -1
  33. package/dist/package.js +6 -0
  34. package/dist/package.js.map +1 -0
  35. package/package.json +21 -41
  36. package/src/PrismicImage.tsx +17 -25
  37. package/src/PrismicLink.tsx +21 -10
  38. package/src/PrismicRichText.tsx +26 -53
  39. package/src/PrismicTable.tsx +14 -36
  40. package/src/PrismicText.tsx +9 -18
  41. package/src/PrismicToolbar.tsx +10 -3
  42. package/src/SliceZone.tsx +46 -50
  43. package/src/lib/devMsg.ts +1 -1
  44. package/dist/index.js.map +0 -1
  45. package/dist/lib/devMsg.d.ts +0 -16
  46. package/dist/package.json.js +0 -5
  47. package/dist/package.json.js.map +0 -1
@@ -1,117 +1,96 @@
1
+ import { LinkProps } from "./PrismicLink.js";
1
2
  import { ComponentType, FC, ReactNode } from "react";
2
3
  import { LinkResolverFunction, RichTextField } from "@prismicio/client";
3
4
  import { RichTextFunctionSerializer, RichTextMapSerializer } from "@prismicio/client/richtext";
4
- import { LinkProps } from "./PrismicLink.js";
5
+
6
+ //#region src/PrismicRichText.d.ts
7
+
5
8
  /**
6
- * A function mapping Rich Text block types to React Components. It is used to
7
- * render Rich Text or Title fields.
9
+ * A function mapping rich text block types to React Components. It is used to
10
+ * render rich text fields.
8
11
  *
9
- * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/technologies/templating-rich-text-and-title-fields-javascript}
12
+ * @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text}
10
13
  */
11
- export type JSXFunctionSerializer = RichTextFunctionSerializer<ReactNode>;
14
+ type JSXFunctionSerializer = RichTextFunctionSerializer<ReactNode>;
12
15
  /**
13
- * A map of Rich Text block types to React Components. It is used to render Rich
14
- * Text or Title fields.
16
+ * A map of rich text block types to React Components. It is used to render rich
17
+ * text fields.
15
18
  *
16
- * @see Templating Rich Text and Title fields from Prismic {@link https://prismic.io/docs/technologies/templating-rich-text-and-title-fields-javascript}
19
+ * @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text}
17
20
  */
18
- export type JSXMapSerializer = RichTextMapSerializer<ReactNode>;
21
+ type JSXMapSerializer = RichTextMapSerializer<ReactNode>;
19
22
  /** Props for `<PrismicRichText>`. */
20
- export type PrismicRichTextProps = {
21
- /** The Prismic Rich Text field to render. */
22
- field: RichTextField | null | undefined;
23
- /**
24
- * The Link Resolver used to resolve links.
25
- *
26
- * @remarks
27
- * If your app uses Route Resolvers when querying for your Prismic
28
- * repository's content, a Link Resolver does not need to be provided.
29
- *
30
- * @see Learn about Link Resolvers and Route Resolvers {@link https://io/docs/core-concepts/link-resolver-route-resolver}
31
- */
32
- linkResolver?: LinkResolverFunction;
33
- /**
34
- * A map or function that maps a Rich Text block to a React component.
35
- *
36
- * @remarks
37
- * Prefer using a map serializer over the function serializer when possible.
38
- * The map serializer is simpler to maintain.
39
- *
40
- * @example A map serializer.
41
- *
42
- * ```jsx
43
- * {
44
- * heading1: ({children}) => <Heading>{children}</Heading>
45
- * }
46
- * ```
47
- *
48
- * @example A function serializer.
49
- *
50
- * ```jsx
51
- * (type, node, content, children) => {
52
- * switch (type) {
53
- * case "heading1": {
54
- * return <Heading>{children}</Heading>;
55
- * }
56
- * }
57
- * };
58
- * ```
59
- */
60
- components?: JSXMapSerializer | JSXFunctionSerializer;
61
- /**
62
- * The React component rendered for links when the URL is internal.
63
- *
64
- * @defaultValue `<a>`
65
- */
66
- internalLinkComponent?: ComponentType<LinkProps>;
67
- /**
68
- * The React component rendered for links when the URL is external.
69
- *
70
- * @defaultValue `<a>`
71
- */
72
- externalLinkComponent?: ComponentType<LinkProps>;
73
- /**
74
- * The value to be rendered when the field is empty. If a fallback is not
75
- * given, `null` will be rendered.
76
- */
77
- fallback?: ReactNode;
23
+ type PrismicRichTextProps = {
24
+ /** The Prismic rich text field to render. */
25
+ field: RichTextField | null | undefined;
26
+ /**
27
+ * The link resolver used to resolve links.
28
+ *
29
+ * @remarks
30
+ * If your app uses route resolvers when querying for your Prismic
31
+ * repository's content, a link resolver does not need to be provided.
32
+ *
33
+ * @see Learn about link resolvers and route resolvers {@link https://prismic.io/docs/routes}
34
+ */
35
+ linkResolver?: LinkResolverFunction;
36
+ /**
37
+ * A map or function that maps a rich text block to a React component.
38
+ *
39
+ * @remarks
40
+ * Prefer using a map serializer over the function serializer when possible.
41
+ * The map serializer is simpler to maintain.
42
+ *
43
+ * @example A map serializer.
44
+ *
45
+ * ```jsx
46
+ * {
47
+ * heading1: ({children}) => <Heading>{children}</Heading>
48
+ * }
49
+ * ```
50
+ *
51
+ * @example A function serializer.
52
+ *
53
+ * ```jsx
54
+ * (type, node, content, children) => {
55
+ * switch (type) {
56
+ * case "heading1": {
57
+ * return <Heading>{children}</Heading>;
58
+ * }
59
+ * }
60
+ * };
61
+ * ```
62
+ */
63
+ components?: JSXMapSerializer | JSXFunctionSerializer;
64
+ /**
65
+ * The React component rendered for links when the URL is internal.
66
+ *
67
+ * @defaultValue `<a>`
68
+ */
69
+ internalLinkComponent?: ComponentType<LinkProps>;
70
+ /**
71
+ * The React component rendered for links when the URL is external.
72
+ *
73
+ * @defaultValue `<a>`
74
+ */
75
+ externalLinkComponent?: ComponentType<LinkProps>;
76
+ /**
77
+ * The value to be rendered when the field is empty. If a fallback is not
78
+ * given, `null` will be rendered.
79
+ */
80
+ fallback?: ReactNode;
78
81
  };
79
82
  /**
80
- * React component that renders content from a Prismic Rich Text field. By
81
- * default, HTML elements are rendered for each piece of content. A `heading1`
82
- * block will render an `<h1>` HTML element, for example. Links will use
83
- * `<PrismicLink>` by default which can be customized using the
84
- * `internalLinkComponent` and `externalLinkComponent` props.
85
- *
86
- * To customize the components that are rendered, provide a map or function
87
- * serializer to the `components` prop.
83
+ * Renders content from a Prismic rich text field as React components.
88
84
  *
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>`.
85
+ * @example
92
86
  *
93
- * @example Rendering a Rich Text field using the default HTMl elements.
94
- *
95
- * ```jsx
96
- * <PrismicRichText field={document.data.content} />;
87
+ * ```tsx
88
+ * <PrismicRichText field={slice.primary.text} />;
97
89
  * ```
98
90
  *
99
- * @example Rendering a Rich Text field using a custom set of React components.
100
- *
101
- * ```jsx
102
- * <PrismicRichText
103
- * field={document.data.content}
104
- * components={{
105
- * heading1: ({ children }) => <Heading>{children}</Heading>,
106
- * }}
107
- * />;
108
- * ```
109
- *
110
- * @param props - Props for the component.
111
- *
112
- * @returns The Rich Text field's content as React components.
113
- *
114
- * @see Learn about Rich Text fields {@link https://io/docs/core-concepts/rich-text-title}
115
- * @see Learn about Rich Text serializers {@link https://io/docs/core-concepts/html-serializer}
91
+ * @see Learn how to style rich text, use custom components, and use labels for custom formatting: {@link https://prismic.io/docs/fields/rich-text}
116
92
  */
117
- export declare const PrismicRichText: FC<PrismicRichTextProps>;
93
+ declare const PrismicRichText: FC<PrismicRichTextProps>;
94
+ //#endregion
95
+ export { JSXFunctionSerializer, JSXMapSerializer, PrismicRichText, PrismicRichTextProps };
96
+ //# sourceMappingURL=PrismicRichText.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismicRichText.d.ts","names":[],"sources":["../src/PrismicRichText.tsx"],"sourcesContent":[],"mappings":";;;;;;;;;AAiCA;AAQA;AAGA;;AAagB,KAxBJ,qBAAA,GAAwB,0BAwBpB,CAxB+C,SAwB/C,CAAA;;;;;;;AAiDJ,KAjEA,gBAAA,GAAmB,qBAiEnB,CAjEyC,SAiEzC,CAAA;;AAqJC,KAnND,oBAAA,GAmNqB;;SAjNzB;;;;;;;;;;iBAWQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;eA6BF,mBAAmB;;;;;;0BAOR,cAAc;;;;;;0BAOd,cAAc;;;;;aAM3B;;;;;;;;;;;;;cAqJC,iBAAiB,GAAG"}
@@ -1,79 +1,133 @@
1
- import { jsx, Fragment } from "react/jsx-runtime";
2
- import { isValidElement, cloneElement, Fragment as Fragment$1 } from "react";
3
- import { isFilled } from "@prismicio/client";
4
- import { composeSerializers, wrapMapSerializer, serialize } from "@prismicio/client/richtext";
5
- import { DEV } from "esm-env";
6
1
  import { devMsg } from "./lib/devMsg.js";
7
2
  import { PrismicLink } from "./PrismicLink.js";
3
+ import { Fragment, cloneElement, isValidElement } from "react";
4
+ import { isFilled } from "@prismicio/client";
5
+ import { DEV } from "esm-env";
6
+ import { Fragment as Fragment$1, jsx } from "react/jsx-runtime";
7
+ import { composeSerializers, serialize, wrapMapSerializer } from "@prismicio/client/richtext";
8
+
9
+ //#region src/PrismicRichText.tsx
8
10
  const getDir = (node) => {
9
- if ("direction" in node && node.direction === "rtl") {
10
- return "rtl";
11
- }
11
+ if ("direction" in node && node.direction === "rtl") return "rtl";
12
12
  };
13
13
  const createDefaultSerializer = (args) => wrapMapSerializer({
14
- heading1: ({ node, children, key }) => jsx("h1", { dir: getDir(node), children }, key),
15
- heading2: ({ node, children, key }) => jsx("h2", { dir: getDir(node), children }, key),
16
- heading3: ({ node, children, key }) => jsx("h3", { dir: getDir(node), children }, key),
17
- heading4: ({ node, children, key }) => jsx("h4", { dir: getDir(node), children }, key),
18
- heading5: ({ node, children, key }) => jsx("h5", { dir: getDir(node), children }, key),
19
- heading6: ({ node, children, key }) => jsx("h6", { dir: getDir(node), children }, key),
20
- paragraph: ({ node, children, key }) => jsx("p", { dir: getDir(node), children }, key),
21
- preformatted: ({ node, key }) => jsx("pre", { children: node.text }, key),
22
- strong: ({ children, key }) => jsx("strong", { children }, key),
23
- em: ({ children, key }) => jsx("em", { children }, key),
24
- listItem: ({ node, children, key }) => jsx("li", { dir: getDir(node), children }, key),
25
- oListItem: ({ node, children, key }) => jsx("li", { dir: getDir(node), children }, key),
26
- list: ({ children, key }) => jsx("ul", { children }, key),
27
- oList: ({ children, key }) => jsx("ol", { children }, key),
28
- image: ({ node, key }) => {
29
- const img = jsx("img", { src: node.url, alt: node.alt ?? void 0, "data-copyright": node.copyright ? node.copyright : void 0 });
30
- return jsx("p", { className: "block-img", children: node.linkTo ? jsx(PrismicLink, { linkResolver: args.linkResolver, internalComponent: args.internalLinkComponent, externalComponent: args.externalLinkComponent, field: node.linkTo, children: img }) : img }, key);
31
- },
32
- embed: ({ node, key }) => 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),
33
- hyperlink: ({ node, children, key }) => jsx(PrismicLink, { field: node.data, linkResolver: args.linkResolver, internalComponent: args.internalLinkComponent, externalComponent: args.externalLinkComponent, children }, key),
34
- label: ({ node, children, key }) => jsx("span", { className: node.data.label, children }, key),
35
- span: ({ text, key }) => {
36
- const result = [];
37
- let i = 0;
38
- for (const line of text.split("\n")) {
39
- if (i > 0) {
40
- result.push(jsx("br", {}, `${i}__break`));
41
- }
42
- result.push(jsx(Fragment$1, { children: line }, `${i}__line`));
43
- i++;
44
- }
45
- return jsx(Fragment$1, { children: result }, key);
46
- }
14
+ heading1: ({ node, children, key }) => /* @__PURE__ */ jsx("h1", {
15
+ dir: getDir(node),
16
+ children
17
+ }, key),
18
+ heading2: ({ node, children, key }) => /* @__PURE__ */ jsx("h2", {
19
+ dir: getDir(node),
20
+ children
21
+ }, key),
22
+ heading3: ({ node, children, key }) => /* @__PURE__ */ jsx("h3", {
23
+ dir: getDir(node),
24
+ children
25
+ }, key),
26
+ heading4: ({ node, children, key }) => /* @__PURE__ */ jsx("h4", {
27
+ dir: getDir(node),
28
+ children
29
+ }, key),
30
+ heading5: ({ node, children, key }) => /* @__PURE__ */ jsx("h5", {
31
+ dir: getDir(node),
32
+ children
33
+ }, key),
34
+ heading6: ({ node, children, key }) => /* @__PURE__ */ jsx("h6", {
35
+ dir: getDir(node),
36
+ children
37
+ }, key),
38
+ paragraph: ({ node, children, key }) => /* @__PURE__ */ jsx("p", {
39
+ dir: getDir(node),
40
+ children
41
+ }, key),
42
+ preformatted: ({ node, key }) => /* @__PURE__ */ jsx("pre", { children: node.text }, key),
43
+ strong: ({ children, key }) => /* @__PURE__ */ jsx("strong", { children }, key),
44
+ em: ({ children, key }) => /* @__PURE__ */ jsx("em", { children }, key),
45
+ listItem: ({ node, children, key }) => /* @__PURE__ */ jsx("li", {
46
+ dir: getDir(node),
47
+ children
48
+ }, key),
49
+ oListItem: ({ node, children, key }) => /* @__PURE__ */ jsx("li", {
50
+ dir: getDir(node),
51
+ children
52
+ }, key),
53
+ list: ({ children, key }) => /* @__PURE__ */ jsx("ul", { children }, key),
54
+ oList: ({ children, key }) => /* @__PURE__ */ jsx("ol", { children }, key),
55
+ image: ({ node, key }) => {
56
+ const img = /* @__PURE__ */ jsx("img", {
57
+ src: node.url,
58
+ alt: node.alt ?? void 0,
59
+ "data-copyright": node.copyright ? node.copyright : void 0
60
+ });
61
+ return /* @__PURE__ */ jsx("p", {
62
+ className: "block-img",
63
+ children: node.linkTo ? /* @__PURE__ */ jsx(PrismicLink, {
64
+ linkResolver: args.linkResolver,
65
+ internalComponent: args.internalLinkComponent,
66
+ externalComponent: args.externalLinkComponent,
67
+ field: node.linkTo,
68
+ children: img
69
+ }) : img
70
+ }, key);
71
+ },
72
+ embed: ({ node, key }) => /* @__PURE__ */ jsx("div", {
73
+ "data-oembed": node.oembed.embed_url,
74
+ "data-oembed-type": node.oembed.type,
75
+ "data-oembed-provider": node.oembed.provider_name,
76
+ dangerouslySetInnerHTML: { __html: node.oembed.html ?? "" }
77
+ }, key),
78
+ hyperlink: ({ node, children, key }) => /* @__PURE__ */ jsx(PrismicLink, {
79
+ field: node.data,
80
+ linkResolver: args.linkResolver,
81
+ internalComponent: args.internalLinkComponent,
82
+ externalComponent: args.externalLinkComponent,
83
+ children
84
+ }, key),
85
+ label: ({ node, children, key }) => /* @__PURE__ */ jsx("span", {
86
+ className: node.data.label,
87
+ children
88
+ }, key),
89
+ span: ({ text, key }) => {
90
+ const result = [];
91
+ let i = 0;
92
+ for (const line of text.split("\n")) {
93
+ if (i > 0) result.push(/* @__PURE__ */ jsx("br", {}, `${i}__break`));
94
+ result.push(/* @__PURE__ */ jsx(Fragment, { children: line }, `${i}__line`));
95
+ i++;
96
+ }
97
+ return /* @__PURE__ */ jsx(Fragment, { children: result }, key);
98
+ }
47
99
  });
100
+ /**
101
+ * Renders content from a Prismic rich text field as React components.
102
+ *
103
+ * @example
104
+ *
105
+ * ```tsx
106
+ * <PrismicRichText field={slice.primary.text} />;
107
+ * ```
108
+ *
109
+ * @see Learn how to style rich text, use custom components, and use labels for custom formatting: {@link https://prismic.io/docs/fields/rich-text}
110
+ */
48
111
  const PrismicRichText = (props) => {
49
- const { linkResolver, field, fallback, components, externalLinkComponent, internalLinkComponent, ...restProps } = props;
50
- if (DEV) {
51
- if ("className" in restProps) {
52
- console.warn(`[PrismicRichText] className cannot be passed to <PrismicRichText> since it renders an array without a wrapping component. For more details, see ${devMsg("classname-is-not-a-valid-prop")}.`, field);
53
- }
54
- }
55
- if (!isFilled.richText(field)) {
56
- return fallback != null ? jsx(Fragment, { children: fallback }) : null;
57
- }
58
- const serializer = composeSerializers(typeof components === "object" ? wrapMapSerializer(components) : components, createDefaultSerializer({
59
- linkResolver,
60
- internalLinkComponent,
61
- externalLinkComponent
62
- }));
63
- const serialized = serialize(field, (type, node, text, children, key) => {
64
- const result = serializer(type, node, text, children, key);
65
- if (isValidElement(result) && result.key == null) {
66
- return cloneElement(result, { key });
67
- } else {
68
- return result;
69
- }
70
- });
71
- if (!serialized) {
72
- return fallback != null ? jsx(Fragment, { children: fallback }) : null;
73
- }
74
- return jsx(Fragment, { children: serialized });
75
- };
76
- export {
77
- PrismicRichText
112
+ const { linkResolver, field, fallback, components, externalLinkComponent, internalLinkComponent, ...restProps } = props;
113
+ if (DEV) {
114
+ if ("className" in restProps) console.warn(`[PrismicRichText] className cannot be passed to <PrismicRichText> since it renders an array without a wrapping component. For more details, see ${devMsg("classname-is-not-a-valid-prop")}.`, field);
115
+ }
116
+ if (!isFilled.richText(field)) return fallback != null ? /* @__PURE__ */ jsx(Fragment$1, { children: fallback }) : null;
117
+ const serializer = composeSerializers(typeof components === "object" ? wrapMapSerializer(components) : components, createDefaultSerializer({
118
+ linkResolver,
119
+ internalLinkComponent,
120
+ externalLinkComponent
121
+ }));
122
+ const serialized = serialize(field, (type, node, text, children, key) => {
123
+ const result = serializer(type, node, text, children, key);
124
+ if (isValidElement(result) && result.key == null) return cloneElement(result, { key });
125
+ else return result;
126
+ });
127
+ if (!serialized) return fallback != null ? /* @__PURE__ */ jsx(Fragment$1, { children: fallback }) : null;
128
+ return /* @__PURE__ */ jsx(Fragment$1, { children: serialized });
78
129
  };
79
- //# sourceMappingURL=PrismicRichText.js.map
130
+
131
+ //#endregion
132
+ export { PrismicRichText };
133
+ //# sourceMappingURL=PrismicRichText.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PrismicRichText.js","sources":["../src/PrismicRichText.tsx"],"sourcesContent":["import {\n\tcloneElement,\n\tComponentType,\n\tFC,\n\tFragment,\n\tisValidElement,\n\tReactNode,\n} from \"react\";\nimport {\n\tisFilled,\n\tLinkResolverFunction,\n\tRichTextField,\n\tRTAnyNode,\n} from \"@prismicio/client\";\nimport {\n\tcomposeSerializers,\n\tserialize,\n\twrapMapSerializer,\n\tRichTextFunctionSerializer,\n\tRichTextMapSerializer,\n} from \"@prismicio/client/richtext\";\nimport { DEV } from \"esm-env\";\n\nimport { devMsg } from \"./lib/devMsg.js\";\n\nimport { LinkProps, PrismicLink } from \"./PrismicLink.js\";\n\n/**\n * A function mapping Rich Text block types to React Components. It is used to\n * render Rich Text or Title fields.\n *\n * @see Templating rich text and title fields from Prismic {@link https://prismic.io/docs/technologies/templating-rich-text-and-title-fields-javascript}\n */\nexport type JSXFunctionSerializer = RichTextFunctionSerializer<ReactNode>;\n\n/**\n * A map of Rich Text block types to React Components. It is used to render Rich\n * Text or Title fields.\n *\n * @see Templating Rich Text and Title fields from Prismic {@link https://prismic.io/docs/technologies/templating-rich-text-and-title-fields-javascript}\n */\nexport type JSXMapSerializer = RichTextMapSerializer<ReactNode>;\n\n/** Props for `<PrismicRichText>`. */\nexport type PrismicRichTextProps = {\n\t/** The Prismic Rich Text field to render. */\n\tfield: RichTextField | null | undefined;\n\n\t/**\n\t * The Link Resolver used to resolve links.\n\t *\n\t * @remarks\n\t * If your app uses Route Resolvers when querying for your Prismic\n\t * repository's content, a Link Resolver does not need to be provided.\n\t *\n\t * @see Learn about Link Resolvers and Route Resolvers {@link https://io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * A map or function that maps a Rich Text block to a React component.\n\t *\n\t * @remarks\n\t * Prefer using a map serializer over the function serializer when possible.\n\t * The map serializer is simpler to maintain.\n\t *\n\t * @example A map serializer.\n\t *\n\t * ```jsx\n\t * {\n\t * heading1: ({children}) => <Heading>{children}</Heading>\n\t * }\n\t * ```\n\t *\n\t * @example A function serializer.\n\t *\n\t * ```jsx\n\t * (type, node, content, children) => {\n\t * \tswitch (type) {\n\t * \t\tcase \"heading1\": {\n\t * \t\t\treturn <Heading>{children}</Heading>;\n\t * \t\t}\n\t * \t}\n\t * };\n\t * ```\n\t */\n\tcomponents?: 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?: ComponentType<LinkProps>;\n\n\t/**\n\t * The React component rendered for links when the URL is external.\n\t *\n\t * @defaultValue `<a>`\n\t */\n\texternalLinkComponent?: ComponentType<LinkProps>;\n\n\t/**\n\t * The value to be rendered when the field is empty. If a fallback is not\n\t * given, `null` will be rendered.\n\t */\n\tfallback?: ReactNode;\n};\n\ntype CreateDefaultSerializerArgs = {\n\tlinkResolver: LinkResolverFunction | undefined;\n\tinternalLinkComponent?: ComponentType<LinkProps>;\n\texternalLinkComponent?: ComponentType<LinkProps>;\n};\n\nconst getDir = (node: RTAnyNode): \"rtl\" | undefined => {\n\tif (\"direction\" in node && node.direction === \"rtl\") {\n\t\treturn \"rtl\";\n\t}\n};\n\nconst createDefaultSerializer = (\n\targs: CreateDefaultSerializerArgs,\n): JSXFunctionSerializer =>\n\twrapMapSerializer<ReactNode>({\n\t\theading1: ({ node, children, key }) => (\n\t\t\t<h1 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h1>\n\t\t),\n\t\theading2: ({ node, children, key }) => (\n\t\t\t<h2 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h2>\n\t\t),\n\t\theading3: ({ node, children, key }) => (\n\t\t\t<h3 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h3>\n\t\t),\n\t\theading4: ({ node, children, key }) => (\n\t\t\t<h4 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h4>\n\t\t),\n\t\theading5: ({ node, children, key }) => (\n\t\t\t<h5 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h5>\n\t\t),\n\t\theading6: ({ node, children, key }) => (\n\t\t\t<h6 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h6>\n\t\t),\n\t\tparagraph: ({ node, children, key }) => (\n\t\t\t<p key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</p>\n\t\t),\n\t\tpreformatted: ({ node, key }) => <pre key={key}>{node.text}</pre>,\n\t\tstrong: ({ children, key }) => <strong key={key}>{children}</strong>,\n\t\tem: ({ children, key }) => <em key={key}>{children}</em>,\n\t\tlistItem: ({ node, children, key }) => (\n\t\t\t<li key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</li>\n\t\t),\n\t\toListItem: ({ node, children, key }) => (\n\t\t\t<li key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</li>\n\t\t),\n\t\tlist: ({ children, key }) => <ul key={key}>{children}</ul>,\n\t\toList: ({ children, key }) => <ol key={key}>{children}</ol>,\n\t\timage: ({ node, key }) => {\n\t\t\tconst img = (\n\t\t\t\t<img\n\t\t\t\t\tsrc={node.url}\n\t\t\t\t\talt={node.alt ?? undefined}\n\t\t\t\t\tdata-copyright={node.copyright ? node.copyright : undefined}\n\t\t\t\t/>\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\t<p key={key} className=\"block-img\">\n\t\t\t\t\t{node.linkTo ? (\n\t\t\t\t\t\t<PrismicLink\n\t\t\t\t\t\t\tlinkResolver={args.linkResolver}\n\t\t\t\t\t\t\tinternalComponent={args.internalLinkComponent}\n\t\t\t\t\t\t\texternalComponent={args.externalLinkComponent}\n\t\t\t\t\t\t\tfield={node.linkTo}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{img}\n\t\t\t\t\t\t</PrismicLink>\n\t\t\t\t\t) : (\n\t\t\t\t\t\timg\n\t\t\t\t\t)}\n\t\t\t\t</p>\n\t\t\t);\n\t\t},\n\t\tembed: ({ node, key }) => (\n\t\t\t<div\n\t\t\t\tkey={key}\n\t\t\t\tdata-oembed={node.oembed.embed_url}\n\t\t\t\tdata-oembed-type={node.oembed.type}\n\t\t\t\tdata-oembed-provider={node.oembed.provider_name}\n\t\t\t\tdangerouslySetInnerHTML={{ __html: node.oembed.html ?? \"\" }}\n\t\t\t/>\n\t\t),\n\t\thyperlink: ({ node, children, key }) => (\n\t\t\t<PrismicLink\n\t\t\t\tkey={key}\n\t\t\t\tfield={node.data}\n\t\t\t\tlinkResolver={args.linkResolver}\n\t\t\t\tinternalComponent={args.internalLinkComponent}\n\t\t\t\texternalComponent={args.externalLinkComponent}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</PrismicLink>\n\t\t),\n\t\tlabel: ({ node, children, key }) => (\n\t\t\t<span key={key} className={node.data.label}>\n\t\t\t\t{children}\n\t\t\t</span>\n\t\t),\n\t\tspan: ({ text, key }) => {\n\t\t\tconst result: ReactNode[] = [];\n\n\t\t\tlet i = 0;\n\t\t\tfor (const line of text.split(\"\\n\")) {\n\t\t\t\tif (i > 0) {\n\t\t\t\t\tresult.push(<br key={`${i}__break`} />);\n\t\t\t\t}\n\n\t\t\t\tresult.push(<Fragment key={`${i}__line`}>{line}</Fragment>);\n\n\t\t\t\ti++;\n\t\t\t}\n\n\t\t\treturn <Fragment key={key}>{result}</Fragment>;\n\t\t},\n\t});\n\n/**\n * 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 * @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 *\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://io/docs/core-concepts/rich-text-title}\n * @see Learn about Rich Text serializers {@link https://io/docs/core-concepts/html-serializer}\n */\nexport const PrismicRichText: FC<PrismicRichTextProps> = (props) => {\n\tconst {\n\t\tlinkResolver,\n\t\tfield,\n\t\tfallback,\n\t\tcomponents,\n\t\texternalLinkComponent,\n\t\tinternalLinkComponent,\n\t\t...restProps\n\t} = props;\n\n\tif (DEV) {\n\t\tif (\"className\" in restProps) {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicRichText] className cannot be passed to <PrismicRichText> since it renders an array without a wrapping component. For more details, see ${devMsg(\n\t\t\t\t\t\"classname-is-not-a-valid-prop\",\n\t\t\t\t)}.`,\n\t\t\t\tfield,\n\t\t\t);\n\t\t}\n\t}\n\n\tif (!isFilled.richText(field)) {\n\t\treturn fallback != null ? <>{fallback}</> : null;\n\t}\n\n\tconst serializer = composeSerializers<ReactNode>(\n\t\ttypeof components === \"object\" ? wrapMapSerializer(components) : components,\n\t\tcreateDefaultSerializer({\n\t\t\tlinkResolver,\n\t\t\tinternalLinkComponent,\n\t\t\texternalLinkComponent,\n\t\t}),\n\t);\n\n\t// The serializer is wrapped in a higher-order function that\n\t// automatically applies a key to React Elements if one is not already\n\t// given.\n\tconst serialized = serialize<ReactNode>(\n\t\tfield,\n\t\t(type, node, text, children, key) => {\n\t\t\tconst result = serializer(type, node, text, children, key);\n\n\t\t\tif (isValidElement(result) && result.key == null) {\n\t\t\t\treturn cloneElement(result, { key });\n\t\t\t} else {\n\t\t\t\treturn result;\n\t\t\t}\n\t\t},\n\t);\n\n\tif (!serialized) {\n\t\treturn fallback != null ? <>{fallback}</> : null;\n\t}\n\n\treturn <>{serialized}</>;\n};\n"],"names":["_jsx","Fragment","_Fragment"],"mappings":";;;;;;;AAmHA,MAAM,SAAS,CAAC,SAAsC;AACrD,MAAI,eAAe,QAAQ,KAAK,cAAc,OAAO;AAC7C,WAAA;AAAA,EAAA;AAET;AAEA,MAAM,0BAA0B,CAC/B,SAEA,kBAA6B;AAAA,EAC5B,UAAU,CAAC,EAAE,MAAM,UAAU,IAC5B,MAAAA,IAAc,MAAA,EAAA,KAAK,OAAO,IAAI,GAAC,SAAA,GAAtB,GAAG;AAAA,EAIb,UAAU,CAAC,EAAE,MAAM,UAAU,IAC5B,MAAAA,IAAc,MAAA,EAAA,KAAK,OAAO,IAAI,GAAC,SAAA,GAAtB,GAAG;AAAA,EAIb,UAAU,CAAC,EAAE,MAAM,UAAU,IAC5B,MAAAA,IAAc,MAAA,EAAA,KAAK,OAAO,IAAI,GAAC,SAAA,GAAtB,GAAG;AAAA,EAIb,UAAU,CAAC,EAAE,MAAM,UAAU,IAC5B,MAAAA,IAAc,MAAA,EAAA,KAAK,OAAO,IAAI,GAAC,SAAA,GAAtB,GAAG;AAAA,EAIb,UAAU,CAAC,EAAE,MAAM,UAAU,IAC5B,MAAAA,IAAc,MAAA,EAAA,KAAK,OAAO,IAAI,GAAC,SAAA,GAAtB,GAAG;AAAA,EAIb,UAAU,CAAC,EAAE,MAAM,UAAU,IAC5B,MAAAA,IAAc,MAAA,EAAA,KAAK,OAAO,IAAI,GAAC,SAAA,GAAtB,GAAG;AAAA,EAIb,W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A,IACA;AAAA,EAAA,CACA,CAAC;AAMG,QAAA,aAAa,UAClB,OACA,CAAC,MAAM,MAAM,MAAM,UAAU,QAAO;AACnC,UAAM,SAAS,WAAW,MAAM,MAAM,MAAM,UAAU,GAAG;AAEzD,QAAI,eAAe,MAAM,KAAK,OAAO,OAAO,MAAM;AACjD,aAAO,aAAa,QAAQ,EAAE,KAAK;AAAA,IAAA,OAC7B;AACC,aAAA;AAAA,IAAA;AAAA,EACR,CACA;AAGF,MAAI,CAAC,YAAY;AACT,WAAA,YAAY,OAAOF,IAAGE,UAAA,EAAA,UAAA,SAAY,CAAA,IAAG;AAAA,EAAA;AAG7C,SAAOF,IAAAE,UAAA,EAAA,UAAG,YAAU;AACrB;"}
1
+ {"version":3,"file":"PrismicRichText.js","names":[],"sources":["../src/PrismicRichText.tsx"],"sourcesContent":["import {\n\tcloneElement,\n\ttype ComponentType,\n\ttype FC,\n\tFragment,\n\tisValidElement,\n\ttype ReactNode,\n} from \"react\";\nimport {\n\tisFilled,\n\ttype LinkResolverFunction,\n\ttype RichTextField,\n\ttype RTAnyNode,\n} from \"@prismicio/client\";\nimport {\n\tcomposeSerializers,\n\tserialize,\n\twrapMapSerializer,\n\ttype RichTextFunctionSerializer,\n\ttype RichTextMapSerializer,\n} from \"@prismicio/client/richtext\";\nimport { DEV } from \"esm-env\";\n\nimport { devMsg } from \"./lib/devMsg.js\";\n\nimport { type LinkProps, PrismicLink } from \"./PrismicLink.js\";\n\n/**\n * A function mapping rich text block types to React Components. It is used to\n * render rich text fields.\n *\n * @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text}\n */\nexport type JSXFunctionSerializer = RichTextFunctionSerializer<ReactNode>;\n\n/**\n * A map of rich text block types to React Components. It is used to render rich\n * text fields.\n *\n * @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text}\n */\nexport type JSXMapSerializer = RichTextMapSerializer<ReactNode>;\n\n/** Props for `<PrismicRichText>`. */\nexport type PrismicRichTextProps = {\n\t/** The Prismic rich text field to render. */\n\tfield: RichTextField | null | undefined;\n\n\t/**\n\t * The link resolver used to resolve links.\n\t *\n\t * @remarks\n\t * If your app uses route resolvers when querying for your Prismic\n\t * repository's content, a link resolver does not need to be provided.\n\t *\n\t * @see Learn about link resolvers and route resolvers {@link https://prismic.io/docs/routes}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * A map or function that maps a rich text block to a React component.\n\t *\n\t * @remarks\n\t * Prefer using a map serializer over the function serializer when possible.\n\t * The map serializer is simpler to maintain.\n\t *\n\t * @example A map serializer.\n\t *\n\t * ```jsx\n\t * {\n\t * heading1: ({children}) => <Heading>{children}</Heading>\n\t * }\n\t * ```\n\t *\n\t * @example A function serializer.\n\t *\n\t * ```jsx\n\t * (type, node, content, children) => {\n\t * \tswitch (type) {\n\t * \t\tcase \"heading1\": {\n\t * \t\t\treturn <Heading>{children}</Heading>;\n\t * \t\t}\n\t * \t}\n\t * };\n\t * ```\n\t */\n\tcomponents?: 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?: ComponentType<LinkProps>;\n\n\t/**\n\t * The React component rendered for links when the URL is external.\n\t *\n\t * @defaultValue `<a>`\n\t */\n\texternalLinkComponent?: ComponentType<LinkProps>;\n\n\t/**\n\t * The value to be rendered when the field is empty. If a fallback is not\n\t * given, `null` will be rendered.\n\t */\n\tfallback?: ReactNode;\n};\n\ntype CreateDefaultSerializerArgs = {\n\tlinkResolver: LinkResolverFunction | undefined;\n\tinternalLinkComponent?: ComponentType<LinkProps>;\n\texternalLinkComponent?: ComponentType<LinkProps>;\n};\n\nconst getDir = (node: RTAnyNode): \"rtl\" | undefined => {\n\tif (\"direction\" in node && node.direction === \"rtl\") {\n\t\treturn \"rtl\";\n\t}\n};\n\nconst createDefaultSerializer = (\n\targs: CreateDefaultSerializerArgs,\n): JSXFunctionSerializer =>\n\twrapMapSerializer<ReactNode>({\n\t\theading1: ({ node, children, key }) => (\n\t\t\t<h1 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h1>\n\t\t),\n\t\theading2: ({ node, children, key }) => (\n\t\t\t<h2 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h2>\n\t\t),\n\t\theading3: ({ node, children, key }) => (\n\t\t\t<h3 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h3>\n\t\t),\n\t\theading4: ({ node, children, key }) => (\n\t\t\t<h4 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h4>\n\t\t),\n\t\theading5: ({ node, children, key }) => (\n\t\t\t<h5 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h5>\n\t\t),\n\t\theading6: ({ node, children, key }) => (\n\t\t\t<h6 key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</h6>\n\t\t),\n\t\tparagraph: ({ node, children, key }) => (\n\t\t\t<p key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</p>\n\t\t),\n\t\tpreformatted: ({ node, key }) => <pre key={key}>{node.text}</pre>,\n\t\tstrong: ({ children, key }) => <strong key={key}>{children}</strong>,\n\t\tem: ({ children, key }) => <em key={key}>{children}</em>,\n\t\tlistItem: ({ node, children, key }) => (\n\t\t\t<li key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</li>\n\t\t),\n\t\toListItem: ({ node, children, key }) => (\n\t\t\t<li key={key} dir={getDir(node)}>\n\t\t\t\t{children}\n\t\t\t</li>\n\t\t),\n\t\tlist: ({ children, key }) => <ul key={key}>{children}</ul>,\n\t\toList: ({ children, key }) => <ol key={key}>{children}</ol>,\n\t\timage: ({ node, key }) => {\n\t\t\tconst img = (\n\t\t\t\t<img\n\t\t\t\t\tsrc={node.url}\n\t\t\t\t\talt={node.alt ?? undefined}\n\t\t\t\t\tdata-copyright={node.copyright ? node.copyright : undefined}\n\t\t\t\t/>\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\t<p key={key} className=\"block-img\">\n\t\t\t\t\t{node.linkTo ? (\n\t\t\t\t\t\t<PrismicLink\n\t\t\t\t\t\t\tlinkResolver={args.linkResolver}\n\t\t\t\t\t\t\tinternalComponent={args.internalLinkComponent}\n\t\t\t\t\t\t\texternalComponent={args.externalLinkComponent}\n\t\t\t\t\t\t\tfield={node.linkTo}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{img}\n\t\t\t\t\t\t</PrismicLink>\n\t\t\t\t\t) : (\n\t\t\t\t\t\timg\n\t\t\t\t\t)}\n\t\t\t\t</p>\n\t\t\t);\n\t\t},\n\t\tembed: ({ node, key }) => (\n\t\t\t<div\n\t\t\t\tkey={key}\n\t\t\t\tdata-oembed={node.oembed.embed_url}\n\t\t\t\tdata-oembed-type={node.oembed.type}\n\t\t\t\tdata-oembed-provider={node.oembed.provider_name}\n\t\t\t\tdangerouslySetInnerHTML={{ __html: node.oembed.html ?? \"\" }}\n\t\t\t/>\n\t\t),\n\t\thyperlink: ({ node, children, key }) => (\n\t\t\t<PrismicLink\n\t\t\t\tkey={key}\n\t\t\t\tfield={node.data}\n\t\t\t\tlinkResolver={args.linkResolver}\n\t\t\t\tinternalComponent={args.internalLinkComponent}\n\t\t\t\texternalComponent={args.externalLinkComponent}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</PrismicLink>\n\t\t),\n\t\tlabel: ({ node, children, key }) => (\n\t\t\t<span key={key} className={node.data.label}>\n\t\t\t\t{children}\n\t\t\t</span>\n\t\t),\n\t\tspan: ({ text, key }) => {\n\t\t\tconst result: ReactNode[] = [];\n\n\t\t\tlet i = 0;\n\t\t\tfor (const line of text.split(\"\\n\")) {\n\t\t\t\tif (i > 0) {\n\t\t\t\t\tresult.push(<br key={`${i}__break`} />);\n\t\t\t\t}\n\n\t\t\t\tresult.push(<Fragment key={`${i}__line`}>{line}</Fragment>);\n\n\t\t\t\ti++;\n\t\t\t}\n\n\t\t\treturn <Fragment key={key}>{result}</Fragment>;\n\t\t},\n\t});\n\n/**\n * Renders content from a Prismic rich text field as React components.\n *\n * @example\n *\n * ```tsx\n * <PrismicRichText field={slice.primary.text} />;\n * ```\n *\n * @see Learn how to style rich text, use custom components, and use labels for custom formatting: {@link https://prismic.io/docs/fields/rich-text}\n */\nexport const PrismicRichText: FC<PrismicRichTextProps> = (props) => {\n\tconst {\n\t\tlinkResolver,\n\t\tfield,\n\t\tfallback,\n\t\tcomponents,\n\t\texternalLinkComponent,\n\t\tinternalLinkComponent,\n\t\t...restProps\n\t} = props;\n\n\tif (DEV) {\n\t\tif (\"className\" in restProps) {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicRichText] className cannot be passed to <PrismicRichText> since it renders an array without a wrapping component. For more details, see ${devMsg(\n\t\t\t\t\t\"classname-is-not-a-valid-prop\",\n\t\t\t\t)}.`,\n\t\t\t\tfield,\n\t\t\t);\n\t\t}\n\t}\n\n\tif (!isFilled.richText(field)) {\n\t\treturn fallback != null ? <>{fallback}</> : null;\n\t}\n\n\tconst serializer = composeSerializers<ReactNode>(\n\t\ttypeof components === \"object\" ? wrapMapSerializer(components) : components,\n\t\tcreateDefaultSerializer({\n\t\t\tlinkResolver,\n\t\t\tinternalLinkComponent,\n\t\t\texternalLinkComponent,\n\t\t}),\n\t);\n\n\t// The serializer is wrapped in a higher-order function that\n\t// automatically applies a key to React Elements if one is not already\n\t// given.\n\tconst serialized = serialize<ReactNode>(\n\t\tfield,\n\t\t(type, node, text, children, key) => {\n\t\t\tconst result = serializer(type, node, text, children, key);\n\n\t\t\tif (isValidElement(result) && result.key == null) {\n\t\t\t\treturn cloneElement(result, { key });\n\t\t\t} else {\n\t\t\t\treturn result;\n\t\t\t}\n\t\t},\n\t);\n\n\tif (!serialized) {\n\t\treturn fallback != null ? <>{fallback}</> : null;\n\t}\n\n\treturn <>{serialized}</>;\n};\n"],"mappings":";;;;;;;;;AAmHA,MAAM,UAAU,SAA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,WAAY,GAAG;CAG7C,MAAM,aAAa,mBAClB,OAAO,eAAe,WAAW,kBAAkB,WAAW,GAAG,YACjE,wBAAwB;EACvB;EACA;EACA;EACA,CAAC,CACF;CAKD,MAAM,aAAa,UAClB,QACC,MAAM,MAAM,MAAM,UAAU,QAAQ;EACpC,MAAM,SAAS,WAAW,MAAM,MAAM,MAAM,UAAU,IAAI;AAE1D,MAAI,eAAe,OAAO,IAAI,OAAO,OAAO,KAC3C,QAAO,aAAa,QAAQ,EAAE,KAAK,CAAC;MAEpC,QAAO;GAGT;AAED,KAAI,CAAC,WACJ,QAAO,YAAY,OAAO,4CAAG,WAAY,GAAG;AAG7C,QAAO,4CAAG,aAAc"}
@@ -1,87 +1,69 @@
1
- import { ComponentType, FC, ReactNode } from "react";
2
- import { TableField, TableFieldHead, TableFieldHeadRow, TableFieldBody, TableFieldBodyRow, TableFieldHeaderCell, TableFieldDataCell } from "@prismicio/client";
3
1
  import { JSXMapSerializer } from "./PrismicRichText.js";
2
+ import { ComponentType, FC, ReactNode } from "react";
3
+ import { TableField, TableFieldBody, TableFieldBodyRow, TableFieldDataCell, TableFieldHead, TableFieldHeadRow, TableFieldHeaderCell } from "@prismicio/client";
4
+
5
+ //#region src/PrismicTable.d.ts
4
6
  type TableComponents = {
5
- table?: ComponentType<{
6
- table: TableField<"filled">;
7
- children: ReactNode;
8
- }>;
9
- thead?: ComponentType<{
10
- head: TableFieldHead;
11
- children: ReactNode;
12
- }>;
13
- tbody?: ComponentType<{
14
- body: TableFieldBody;
15
- children: ReactNode;
16
- }>;
17
- tr?: ComponentType<{
18
- row: TableFieldHeadRow | TableFieldBodyRow;
19
- children: ReactNode;
20
- }>;
21
- th?: ComponentType<{
22
- cell: TableFieldHeaderCell;
23
- children: ReactNode;
24
- }>;
25
- td?: ComponentType<{
26
- cell: TableFieldDataCell;
27
- children: ReactNode;
28
- }>;
7
+ table?: ComponentType<{
8
+ table: TableField<"filled">;
9
+ children: ReactNode;
10
+ }>;
11
+ thead?: ComponentType<{
12
+ head: TableFieldHead;
13
+ children: ReactNode;
14
+ }>;
15
+ tbody?: ComponentType<{
16
+ body: TableFieldBody;
17
+ children: ReactNode;
18
+ }>;
19
+ tr?: ComponentType<{
20
+ row: TableFieldHeadRow | TableFieldBodyRow;
21
+ children: ReactNode;
22
+ }>;
23
+ th?: ComponentType<{
24
+ cell: TableFieldHeaderCell;
25
+ children: ReactNode;
26
+ }>;
27
+ td?: ComponentType<{
28
+ cell: TableFieldDataCell;
29
+ children: ReactNode;
30
+ }>;
29
31
  };
30
32
  /** Props for `<PrismicTable>`. */
31
- export type PrismicTableProps = {
32
- /** The Prismic table field to render. */
33
- field: TableField;
34
- /**
35
- * An object that maps a table block to a React component.
36
- *
37
- * @example A map serializer.
38
- *
39
- * ```jsx
40
- * {
41
- * table: ({children}) => <table>{children}</table>
42
- * thead: ({children}) => <thead>{children}</thead>
43
- * }
44
- * ```
45
- */
46
- components?: JSXMapSerializer & TableComponents;
47
- /**
48
- * The value to be rendered when the field is empty. If a fallback is not
49
- * given, `null` will be rendered.
50
- */
51
- fallback?: ReactNode;
33
+ type PrismicTableProps = {
34
+ /** The Prismic table field to render. */
35
+ field: TableField;
36
+ /**
37
+ * An object that maps a table block to a React component.
38
+ *
39
+ * @example A map serializer.
40
+ *
41
+ * ```jsx
42
+ * {
43
+ * table: ({children}) => <table>{children}</table>
44
+ * thead: ({children}) => <thead>{children}</thead>
45
+ * }
46
+ * ```
47
+ */
48
+ components?: JSXMapSerializer & TableComponents;
49
+ /**
50
+ * The value to be rendered when the field is empty. If a fallback is not
51
+ * given, `null` will be rendered.
52
+ */
53
+ fallback?: ReactNode;
52
54
  };
53
55
  /**
54
- * React component that renders content from a Prismic table field. By default,
55
- * HTML elements are rendered for each piece of content. A `tbody` block will
56
- * render a `<tbody>` HTML element, for example.
57
- *
58
- * To customize the components that are rendered, provide a map serializer to
59
- * the `components` prop.
60
- *
61
- * @example Rendering a table field using the default HTMl elements.
56
+ * Renders content from a Prismic table field as React components.
62
57
  *
63
- * ```jsx
64
- * <PrismicTable field={document.data.my_table} />;
65
- * ```
66
- *
67
- * @example Rendering a table field using a custom set of React components.
58
+ * @example
68
59
  *
69
- * ```jsx
70
- * <PrismicTable
71
- * field={document.data.my_table}
72
- * components={{
73
- * tbody: ({ children }) => (
74
- * <tbody className="my-class">{children}</tbody>
75
- * ),
76
- * }}
77
- * />;
60
+ * ```tsx
61
+ * <PrismicTable field={slice.primary.pricing_table} />;
78
62
  * ```
79
63
  *
80
- * @param props - Props for the component.
81
- *
82
- * @returns The table field's content as React components.
83
- *
84
- * @see Learn about table fields {@link https://prismic.io/docs/core-concepts/table}
64
+ * @see Learn how to style tables and customize table element components: {@link https://prismic.io/docs/fields/table}
85
65
  */
86
- export declare const PrismicTable: FC<PrismicTableProps>;
87
- export {};
66
+ declare const PrismicTable: FC<PrismicTableProps>;
67
+ //#endregion
68
+ export { PrismicTable, PrismicTableProps };
69
+ //# sourceMappingURL=PrismicTable.d.ts.map
@@ -0,0 +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"}