@prismicio/react 3.2.2-pr.241.0f293b1 → 3.2.2-pr.242.531bab1

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 (48) hide show
  1. package/dist/PrismicImage.d.ts +60 -58
  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 +63 -67
  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 +68 -66
  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 +53 -49
  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 +16 -11
  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 +12 -7
  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 +52 -47
  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 +19 -39
  36. package/src/PrismicImage.tsx +3 -3
  37. package/src/PrismicLink.tsx +5 -5
  38. package/src/PrismicRichText.tsx +11 -16
  39. package/src/PrismicTable.tsx +9 -9
  40. package/src/PrismicText.tsx +2 -2
  41. package/src/PrismicToolbar.tsx +1 -1
  42. package/src/SliceZone.tsx +2 -2
  43. package/src/index.ts +0 -1
  44. package/src/lib/devMsg.ts +1 -1
  45. package/dist/index.js.map +0 -1
  46. package/dist/lib/devMsg.d.ts +0 -16
  47. package/dist/package.json.js +0 -5
  48. package/dist/package.json.js.map +0 -1
@@ -1,84 +1,83 @@
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
9
  * A function mapping rich text block types to React Components. It is used to
7
10
  * render rich text fields.
8
11
  *
9
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
16
  * A map of rich text block types to React Components. It is used to render rich
14
17
  * text fields.
15
18
  *
16
19
  * @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text}
17
20
  */
18
- export type RichTextComponents = RichTextMapSerializer<ReactNode>;
19
- /**
20
- * @deprecated Use `RichTextComponents` instead.
21
- */
22
- export type JSXMapSerializer = RichTextComponents;
21
+ type JSXMapSerializer = RichTextMapSerializer<ReactNode>;
23
22
  /** Props for `<PrismicRichText>`. */
24
- export type PrismicRichTextProps = {
25
- /** The Prismic rich text field to render. */
26
- field: RichTextField | null | undefined;
27
- /**
28
- * The link resolver used to resolve links.
29
- *
30
- * @remarks
31
- * If your app uses route resolvers when querying for your Prismic
32
- * repository's content, a link resolver does not need to be provided.
33
- *
34
- * @see Learn about link resolvers and route resolvers {@link https://prismic.io/docs/routes}
35
- */
36
- linkResolver?: LinkResolverFunction;
37
- /**
38
- * A map or function that maps a rich text block to a React component.
39
- *
40
- * @remarks
41
- * Prefer using a map serializer over the function serializer when possible.
42
- * The map serializer is simpler to maintain.
43
- *
44
- * @example A map serializer.
45
- *
46
- * ```jsx
47
- * {
48
- * heading1: ({children}) => <Heading>{children}</Heading>
49
- * }
50
- * ```
51
- *
52
- * @example A function serializer.
53
- *
54
- * ```jsx
55
- * (type, node, content, children) => {
56
- * switch (type) {
57
- * case "heading1": {
58
- * return <Heading>{children}</Heading>;
59
- * }
60
- * }
61
- * };
62
- * ```
63
- */
64
- components?: RichTextComponents | JSXFunctionSerializer;
65
- /**
66
- * The React component rendered for links when the URL is internal.
67
- *
68
- * @defaultValue `<a>`
69
- */
70
- internalLinkComponent?: ComponentType<LinkProps>;
71
- /**
72
- * The React component rendered for links when the URL is external.
73
- *
74
- * @defaultValue `<a>`
75
- */
76
- externalLinkComponent?: ComponentType<LinkProps>;
77
- /**
78
- * The value to be rendered when the field is empty. If a fallback is not
79
- * given, `null` will be rendered.
80
- */
81
- 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;
82
81
  };
83
82
  /**
84
83
  * Renders content from a Prismic rich text field as React components.
@@ -91,4 +90,7 @@ export type PrismicRichTextProps = {
91
90
  *
92
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}
93
92
  */
94
- 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 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 RichTextComponents = RichTextMapSerializer<ReactNode>;\n\n/**\n * @deprecated Use `RichTextComponents` instead.\n */\nexport type JSXMapSerializer = RichTextComponents;\n\n/** Props for `<PrismicRichText>`. */\nexport type PrismicRichTextProps = {\n\t/** The Prismic rich text field to render. */\n\tfield: RichTextField | null | undefined;\n\n\t/**\n\t * The link resolver used to resolve links.\n\t *\n\t * @remarks\n\t * If your app uses route resolvers when querying for your Prismic\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?: RichTextComponents | JSXFunctionSerializer;\n\n\t/**\n\t * The React component rendered for links when the URL is internal.\n\t *\n\t * @defaultValue `<a>`\n\t */\n\tinternalLinkComponent?: ComponentType<LinkProps>;\n\n\t/**\n\t * The React component rendered for links when the URL is external.\n\t *\n\t * @defaultValue `<a>`\n\t */\n\texternalLinkComponent?: ComponentType<LinkProps>;\n\n\t/**\n\t * The value to be rendered when the field is empty. If a fallback is not\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}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AAM;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,SAAuC;AACtD,KAAI,eAAe,QAAQ,KAAK,cAAc,MAC7C,QAAO;;AAIT,MAAM,2BACL,SAEA,kBAA6B;CAC5B,WAAW,EAAE,MAAM,UAAU,UAC5B,oBAAC;EAAa,KAAK,OAAO,KAAK;EAC7B;IADO,IAEJ;CAEN,WAAW,EAAE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M,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,54 +1,56 @@
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
56
  * Renders content from a Prismic table field as React components.
@@ -61,5 +63,7 @@ export type PrismicTableProps = {
61
63
  *
62
64
  * @see Learn how to style tables and customize table element components: {@link https://prismic.io/docs/fields/table}
63
65
  */
64
- export declare const PrismicTable: FC<PrismicTableProps>;
65
- 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"}
@@ -1,28 +1,75 @@
1
- import { jsxs, jsx } from "react/jsx-runtime";
2
- import { isFilled } from "@prismicio/client";
3
1
  import { PrismicRichText } from "./PrismicRichText.js";
2
+ import { isFilled } from "@prismicio/client";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+
5
+ //#region src/PrismicTable.tsx
4
6
  const defaultComponents = {
5
- table: ({ children }) => jsx("table", { children }),
6
- thead: ({ children }) => jsx("thead", { children }),
7
- tbody: ({ children }) => jsx("tbody", { children }),
8
- tr: ({ children }) => jsx("tr", { children }),
9
- th: ({ children }) => jsx("th", { children }),
10
- td: ({ children }) => jsx("td", { children })
7
+ table: ({ children }) => /* @__PURE__ */ jsx("table", { children }),
8
+ thead: ({ children }) => /* @__PURE__ */ jsx("thead", { children }),
9
+ tbody: ({ children }) => /* @__PURE__ */ jsx("tbody", { children }),
10
+ tr: ({ children }) => /* @__PURE__ */ jsx("tr", { children }),
11
+ th: ({ children }) => /* @__PURE__ */ jsx("th", { children }),
12
+ td: ({ children }) => /* @__PURE__ */ jsx("td", { children })
11
13
  };
14
+ /**
15
+ * Renders content from a Prismic table field as React components.
16
+ *
17
+ * @example
18
+ *
19
+ * ```tsx
20
+ * <PrismicTable field={slice.primary.pricing_table} />;
21
+ * ```
22
+ *
23
+ * @see Learn how to style tables and customize table element components: {@link https://prismic.io/docs/fields/table}
24
+ */
12
25
  const PrismicTable = (props) => {
13
- const { field, components, fallback = null } = props;
14
- if (!isFilled.table(field)) {
15
- return fallback;
16
- }
17
- const { table: Table, thead: Thead, tbody: Tbody } = { ...defaultComponents, ...components };
18
- return jsxs(Table, { table: field, children: [field.head && jsx(Thead, { head: field.head, children: field.head.rows.map((row) => jsx(TableRow, { row, components }, row.key)) }), jsx(Tbody, { body: field.body, children: field.body.rows.map((row) => jsx(TableRow, { row, components }, row.key)) })] });
26
+ const { field, components, fallback = null } = props;
27
+ if (!isFilled.table(field)) return fallback;
28
+ const { table: Table, thead: Thead, tbody: Tbody } = {
29
+ ...defaultComponents,
30
+ ...components
31
+ };
32
+ return /* @__PURE__ */ jsxs(Table, {
33
+ table: field,
34
+ children: [field.head && /* @__PURE__ */ jsx(Thead, {
35
+ head: field.head,
36
+ children: field.head.rows.map((row) => /* @__PURE__ */ jsx(TableRow, {
37
+ row,
38
+ components
39
+ }, row.key))
40
+ }), /* @__PURE__ */ jsx(Tbody, {
41
+ body: field.body,
42
+ children: field.body.rows.map((row) => /* @__PURE__ */ jsx(TableRow, {
43
+ row,
44
+ components
45
+ }, row.key))
46
+ })]
47
+ });
19
48
  };
20
49
  function TableRow(props) {
21
- const { row, components } = props;
22
- const { tr: Tr, th: Th, td: Td } = { ...defaultComponents, ...components };
23
- return jsx(Tr, { row, children: row.cells.map((cell) => cell.type === "header" ? jsx(Th, { cell, children: jsx(PrismicRichText, { field: cell.content, components }) }, cell.key) : jsx(Td, { cell, children: jsx(PrismicRichText, { field: cell.content, components }) }, cell.key)) });
50
+ const { row, components } = props;
51
+ const { tr: Tr, th: Th, td: Td } = {
52
+ ...defaultComponents,
53
+ ...components
54
+ };
55
+ return /* @__PURE__ */ jsx(Tr, {
56
+ row,
57
+ children: row.cells.map((cell) => cell.type === "header" ? /* @__PURE__ */ jsx(Th, {
58
+ cell,
59
+ children: /* @__PURE__ */ jsx(PrismicRichText, {
60
+ field: cell.content,
61
+ components
62
+ })
63
+ }, cell.key) : /* @__PURE__ */ jsx(Td, {
64
+ cell,
65
+ children: /* @__PURE__ */ jsx(PrismicRichText, {
66
+ field: cell.content,
67
+ components
68
+ })
69
+ }, cell.key))
70
+ });
24
71
  }
25
- export {
26
- PrismicTable
27
- };
28
- //# sourceMappingURL=PrismicTable.js.map
72
+
73
+ //#endregion
74
+ export { PrismicTable };
75
+ //# sourceMappingURL=PrismicTable.js.map