@prismicio/react 3.4.1 → 3.4.2-canary.ec5cd66
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.
- package/README.md +6 -0
- package/dist/PrismicImage.d.ts +10 -9
- package/dist/PrismicImage.d.ts.map +1 -1
- package/dist/PrismicImage.js +3 -3
- package/dist/PrismicImage.js.map +1 -1
- package/dist/PrismicLink.d.ts +6 -7
- package/dist/PrismicLink.d.ts.map +1 -1
- package/dist/PrismicLink.js +4 -3
- package/dist/PrismicLink.js.map +1 -1
- package/dist/PrismicRichText.d.ts +8 -9
- package/dist/PrismicRichText.d.ts.map +1 -1
- package/dist/PrismicRichText.js +1 -1
- package/dist/PrismicRichText.js.map +1 -1
- package/dist/PrismicTable.d.ts +5 -6
- package/dist/PrismicTable.d.ts.map +1 -1
- package/dist/PrismicTable.js +1 -1
- package/dist/PrismicTable.js.map +1 -1
- package/dist/PrismicText.d.ts +7 -7
- package/dist/PrismicText.d.ts.map +1 -1
- package/dist/PrismicText.js +1 -1
- package/dist/PrismicText.js.map +1 -1
- package/dist/PrismicToolbar.d.ts +3 -5
- package/dist/PrismicToolbar.d.ts.map +1 -1
- package/dist/PrismicToolbar.js +5 -3
- package/dist/PrismicToolbar.js.map +1 -1
- package/dist/SliceZone.d.ts +25 -21
- package/dist/SliceZone.d.ts.map +1 -1
- package/dist/SliceZone.js +4 -3
- package/dist/SliceZone.js.map +1 -1
- package/dist/lib/devMsg.js +1 -1
- package/dist/lib/devMsg.js.map +1 -1
- package/dist/package.js +1 -1
- package/package.json +17 -16
- package/src/PrismicImage.tsx +34 -34
- package/src/PrismicLink.tsx +43 -43
- package/src/PrismicRichText.tsx +43 -43
- package/src/PrismicTable.tsx +29 -29
- package/src/PrismicText.tsx +16 -16
- package/src/PrismicToolbar.tsx +32 -30
- package/src/SliceZone.tsx +41 -41
- package/src/index.ts +15 -15
- package/src/lib/devMsg.ts +3 -3
package/src/PrismicLink.tsx
CHANGED
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
type PrismicDocument,
|
|
5
5
|
asLinkAttrs,
|
|
6
6
|
type AsLinkAttrsConfig,
|
|
7
|
-
} from "@prismicio/client"
|
|
8
|
-
import { DEV } from "esm-env"
|
|
7
|
+
} from "@prismicio/client"
|
|
8
|
+
import { DEV } from "esm-env"
|
|
9
9
|
import {
|
|
10
10
|
type ComponentProps,
|
|
11
11
|
type ComponentType,
|
|
@@ -13,32 +13,32 @@ import {
|
|
|
13
13
|
type HTMLAttributeAnchorTarget,
|
|
14
14
|
type ReactNode,
|
|
15
15
|
forwardRef,
|
|
16
|
-
} from "react"
|
|
16
|
+
} from "react"
|
|
17
17
|
|
|
18
|
-
import { devMsg } from "./lib/devMsg.js"
|
|
18
|
+
import { devMsg } from "./lib/devMsg.js"
|
|
19
19
|
|
|
20
20
|
/** The default component rendered for internal and external links. */
|
|
21
|
-
const defaultComponent = "a"
|
|
21
|
+
const defaultComponent = "a"
|
|
22
22
|
|
|
23
23
|
/** Props provided to a component when rendered with `<PrismicLink>`. */
|
|
24
24
|
export interface LinkProps {
|
|
25
25
|
/** The URL to link. */
|
|
26
|
-
href: string
|
|
26
|
+
href: string
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* The `target` attribute for anchor elements. If the Prismic field is configured to open in a new
|
|
30
30
|
* window, this prop defaults to `_blank`.
|
|
31
31
|
*/
|
|
32
|
-
target?: HTMLAttributeAnchorTarget
|
|
32
|
+
target?: HTMLAttributeAnchorTarget
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* The `rel` attribute for anchor elements. If the `target` prop is set to `"_blank"`, this prop
|
|
36
36
|
* defaults to `"noopener noreferrer"`.
|
|
37
37
|
*/
|
|
38
|
-
rel?: string
|
|
38
|
+
rel?: string
|
|
39
39
|
|
|
40
40
|
/** Children for the component. */
|
|
41
|
-
children?: ReactNode
|
|
41
|
+
children?: ReactNode
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
export type PrismicLinkProps<
|
|
@@ -50,7 +50,7 @@ export type PrismicLinkProps<
|
|
|
50
50
|
* external. This prop can be provided a function to use the link's metadata to determine the
|
|
51
51
|
* `rel` value.
|
|
52
52
|
*/
|
|
53
|
-
rel?: string | AsLinkAttrsConfig["rel"]
|
|
53
|
+
rel?: string | AsLinkAttrsConfig["rel"]
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
56
|
* The link resolver used to resolve links.
|
|
@@ -60,7 +60,7 @@ export type PrismicLinkProps<
|
|
|
60
60
|
* resolver does not need to be provided.
|
|
61
61
|
* @see Learn about link resolvers and route resolvers {@link https://prismic.io/docs/routes}
|
|
62
62
|
*/
|
|
63
|
-
linkResolver?: LinkResolverFunction
|
|
63
|
+
linkResolver?: LinkResolverFunction
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
66
|
* The component rendered for internal URLs. Defaults to `<a>`.
|
|
@@ -68,39 +68,39 @@ export type PrismicLinkProps<
|
|
|
68
68
|
* If your app uses a client-side router that requires a special Link component, provide the Link
|
|
69
69
|
* component to this prop.
|
|
70
70
|
*/
|
|
71
|
-
internalComponent?: ComponentType<InternalComponentProps
|
|
71
|
+
internalComponent?: ComponentType<InternalComponentProps>
|
|
72
72
|
|
|
73
73
|
/** The component rendered for external URLs. Defaults to `<a>`. */
|
|
74
|
-
externalComponent?: ComponentType<ExternalComponentProps
|
|
74
|
+
externalComponent?: ComponentType<ExternalComponentProps>
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
77
|
* The children to render for the link. If no children are provided, the link's `text` property
|
|
78
78
|
* will be used.
|
|
79
79
|
*/
|
|
80
|
-
children?: ReactNode
|
|
80
|
+
children?: ReactNode
|
|
81
81
|
} & (
|
|
82
82
|
| {
|
|
83
|
-
document: PrismicDocument | null | undefined
|
|
84
|
-
href?: never
|
|
85
|
-
field?: never
|
|
83
|
+
document: PrismicDocument | null | undefined
|
|
84
|
+
href?: never
|
|
85
|
+
field?: never
|
|
86
86
|
}
|
|
87
87
|
| {
|
|
88
|
-
field: LinkField | null | undefined
|
|
89
|
-
href?: never
|
|
90
|
-
document?: never
|
|
88
|
+
field: LinkField | null | undefined
|
|
89
|
+
href?: never
|
|
90
|
+
document?: never
|
|
91
91
|
}
|
|
92
92
|
| {
|
|
93
|
-
href: LinkProps["href"]
|
|
94
|
-
field?: LinkField | null | undefined
|
|
95
|
-
document?: never
|
|
93
|
+
href: LinkProps["href"]
|
|
94
|
+
field?: LinkField | null | undefined
|
|
95
|
+
document?: never
|
|
96
96
|
}
|
|
97
|
-
)
|
|
97
|
+
)
|
|
98
98
|
|
|
99
99
|
/**
|
|
100
100
|
* Renders a link from a Prismic link field or page.
|
|
101
101
|
*
|
|
102
102
|
* @example
|
|
103
|
-
*
|
|
103
|
+
* ;```tsx
|
|
104
104
|
* <PrismicLink field={slice.primary.link}>Click here</PrismicLink>;
|
|
105
105
|
* ```
|
|
106
106
|
*
|
|
@@ -121,7 +121,7 @@ export const PrismicLink = forwardRef(function PrismicLink<
|
|
|
121
121
|
externalComponent,
|
|
122
122
|
children,
|
|
123
123
|
...restProps
|
|
124
|
-
} = props
|
|
124
|
+
} = props
|
|
125
125
|
|
|
126
126
|
if (DEV) {
|
|
127
127
|
if (field) {
|
|
@@ -129,12 +129,12 @@ export const PrismicLink = forwardRef(function PrismicLink<
|
|
|
129
129
|
console.error(
|
|
130
130
|
`[PrismicLink] This "field" prop value caused an error to be thrown.\n`,
|
|
131
131
|
field,
|
|
132
|
-
)
|
|
132
|
+
)
|
|
133
133
|
throw new Error(
|
|
134
134
|
`[PrismicLink] The provided field is missing required properties to properly render a link. The link will not render. For more details, see ${devMsg(
|
|
135
135
|
"missing-link-properties",
|
|
136
136
|
)}`,
|
|
137
|
-
)
|
|
137
|
+
)
|
|
138
138
|
} else if (
|
|
139
139
|
("text" in field ? Object.keys(field).length > 2 : Object.keys(field).length > 1) &&
|
|
140
140
|
!("url" in field || "uid" in field || "id" in field)
|
|
@@ -144,7 +144,7 @@ export const PrismicLink = forwardRef(function PrismicLink<
|
|
|
144
144
|
"missing-link-properties",
|
|
145
145
|
)}`,
|
|
146
146
|
field,
|
|
147
|
-
)
|
|
147
|
+
)
|
|
148
148
|
}
|
|
149
149
|
} else if (doc) {
|
|
150
150
|
if (!("url" in doc || "id" in doc)) {
|
|
@@ -153,7 +153,7 @@ export const PrismicLink = forwardRef(function PrismicLink<
|
|
|
153
153
|
"missing-link-properties",
|
|
154
154
|
)}`,
|
|
155
155
|
doc,
|
|
156
|
-
)
|
|
156
|
+
)
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
}
|
|
@@ -165,36 +165,36 @@ export const PrismicLink = forwardRef(function PrismicLink<
|
|
|
165
165
|
} = asLinkAttrs(field ?? doc, {
|
|
166
166
|
linkResolver,
|
|
167
167
|
rel: typeof restProps.rel === "function" ? restProps.rel : undefined,
|
|
168
|
-
})
|
|
168
|
+
})
|
|
169
169
|
|
|
170
|
-
let rel: string | undefined = computedRel
|
|
170
|
+
let rel: string | undefined = computedRel
|
|
171
171
|
if ("rel" in restProps && typeof restProps.rel !== "function") {
|
|
172
|
-
rel = restProps.rel
|
|
172
|
+
rel = restProps.rel
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
const href = ("href" in restProps ? restProps.href : computedHref) || ""
|
|
175
|
+
const href = ("href" in restProps ? restProps.href : computedHref) || ""
|
|
176
176
|
|
|
177
|
-
const InternalComponent = (internalComponent || defaultComponent) as ComponentType<LinkProps
|
|
178
|
-
const ExternalComponent = (externalComponent || defaultComponent) as ComponentType<LinkProps
|
|
177
|
+
const InternalComponent = (internalComponent || defaultComponent) as ComponentType<LinkProps>
|
|
178
|
+
const ExternalComponent = (externalComponent || defaultComponent) as ComponentType<LinkProps>
|
|
179
179
|
const Component = href
|
|
180
180
|
? isInternalURL(href)
|
|
181
181
|
? InternalComponent
|
|
182
182
|
: ExternalComponent
|
|
183
|
-
: InternalComponent
|
|
183
|
+
: InternalComponent
|
|
184
184
|
|
|
185
185
|
return (
|
|
186
186
|
<Component ref={ref} {...attrs} {...restProps} href={href} rel={rel}>
|
|
187
187
|
{"children" in props ? children : field?.text}
|
|
188
188
|
</Component>
|
|
189
|
-
)
|
|
189
|
+
)
|
|
190
190
|
}) as <
|
|
191
191
|
InternalComponentProps = ComponentProps<typeof defaultComponent>,
|
|
192
192
|
ExternalComponentProps = ComponentProps<typeof defaultComponent>,
|
|
193
193
|
>(
|
|
194
194
|
props: PrismicLinkProps<InternalComponentProps, ExternalComponentProps> & {
|
|
195
|
-
ref?: ForwardedRef<Element
|
|
195
|
+
ref?: ForwardedRef<Element>
|
|
196
196
|
},
|
|
197
|
-
) => ReactNode
|
|
197
|
+
) => ReactNode
|
|
198
198
|
|
|
199
199
|
/**
|
|
200
200
|
* Determines if a URL is internal or external.
|
|
@@ -204,8 +204,8 @@ export const PrismicLink = forwardRef(function PrismicLink<
|
|
|
204
204
|
*/
|
|
205
205
|
// TODO: This does not detect all relative URLs as internal such as `about` or `./about`. This function assumes relative URLs start with a "/" or "#"`.
|
|
206
206
|
export function isInternalURL(url: string): boolean {
|
|
207
|
-
const isInternal = /^(\/(?!\/)|#)/.test(url)
|
|
208
|
-
const isSpecialLink = !isInternal && !/^https?:\/\//.test(url)
|
|
207
|
+
const isInternal = /^(\/(?!\/)|#)/.test(url)
|
|
208
|
+
const isSpecialLink = !isInternal && !/^https?:\/\//.test(url)
|
|
209
209
|
|
|
210
|
-
return isInternal && !isSpecialLink
|
|
210
|
+
return isInternal && !isSpecialLink
|
|
211
211
|
}
|
package/src/PrismicRichText.tsx
CHANGED
|
@@ -3,15 +3,15 @@ import {
|
|
|
3
3
|
type LinkResolverFunction,
|
|
4
4
|
type RichTextField,
|
|
5
5
|
type RTAnyNode,
|
|
6
|
-
} from "@prismicio/client"
|
|
6
|
+
} from "@prismicio/client"
|
|
7
7
|
import {
|
|
8
8
|
composeSerializers,
|
|
9
9
|
serialize,
|
|
10
10
|
wrapMapSerializer,
|
|
11
11
|
type RichTextFunctionSerializer,
|
|
12
12
|
type RichTextMapSerializer,
|
|
13
|
-
} from "@prismicio/client/richtext"
|
|
14
|
-
import { DEV } from "esm-env"
|
|
13
|
+
} from "@prismicio/client/richtext"
|
|
14
|
+
import { DEV } from "esm-env"
|
|
15
15
|
import {
|
|
16
16
|
cloneElement,
|
|
17
17
|
type ComponentType,
|
|
@@ -19,10 +19,10 @@ import {
|
|
|
19
19
|
Fragment,
|
|
20
20
|
isValidElement,
|
|
21
21
|
type ReactNode,
|
|
22
|
-
} from "react"
|
|
22
|
+
} from "react"
|
|
23
23
|
|
|
24
|
-
import { devMsg } from "./lib/devMsg.js"
|
|
25
|
-
import { type LinkProps, PrismicLink } from "./PrismicLink.js"
|
|
24
|
+
import { devMsg } from "./lib/devMsg.js"
|
|
25
|
+
import { type LinkProps, PrismicLink } from "./PrismicLink.js"
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* A function mapping rich text block types to React Components. It is used to render rich text
|
|
@@ -30,22 +30,22 @@ import { type LinkProps, PrismicLink } from "./PrismicLink.js";
|
|
|
30
30
|
*
|
|
31
31
|
* @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text}
|
|
32
32
|
*/
|
|
33
|
-
export type JSXFunctionSerializer = RichTextFunctionSerializer<ReactNode
|
|
33
|
+
export type JSXFunctionSerializer = RichTextFunctionSerializer<ReactNode>
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
* A map of rich text block types to React Components. It is used to render rich text fields.
|
|
37
37
|
*
|
|
38
38
|
* @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text}
|
|
39
39
|
*/
|
|
40
|
-
export type RichTextComponents = RichTextMapSerializer<ReactNode
|
|
40
|
+
export type RichTextComponents = RichTextMapSerializer<ReactNode>
|
|
41
41
|
|
|
42
42
|
/** @deprecated Use `RichTextComponents` instead. */
|
|
43
|
-
export type JSXMapSerializer = RichTextComponents
|
|
43
|
+
export type JSXMapSerializer = RichTextComponents
|
|
44
44
|
|
|
45
45
|
/** Props for `<PrismicRichText>`. */
|
|
46
46
|
export type PrismicRichTextProps = {
|
|
47
47
|
/** The Prismic rich text field to render. */
|
|
48
|
-
field: RichTextField | null | undefined
|
|
48
|
+
field: RichTextField | null | undefined
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* The link resolver used to resolve links.
|
|
@@ -55,7 +55,7 @@ export type PrismicRichTextProps = {
|
|
|
55
55
|
* resolver does not need to be provided.
|
|
56
56
|
* @see Learn about link resolvers and route resolvers {@link https://prismic.io/docs/routes}
|
|
57
57
|
*/
|
|
58
|
-
linkResolver?: LinkResolverFunction
|
|
58
|
+
linkResolver?: LinkResolverFunction
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
61
|
* A map or function that maps a rich text block to a React component.
|
|
@@ -85,40 +85,40 @@ export type PrismicRichTextProps = {
|
|
|
85
85
|
* };
|
|
86
86
|
* ```
|
|
87
87
|
*/
|
|
88
|
-
components?: RichTextComponents | JSXFunctionSerializer
|
|
88
|
+
components?: RichTextComponents | JSXFunctionSerializer
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
91
|
* The React component rendered for links when the URL is internal.
|
|
92
92
|
*
|
|
93
93
|
* @defaultValue `<a>`
|
|
94
94
|
*/
|
|
95
|
-
internalLinkComponent?: ComponentType<LinkProps
|
|
95
|
+
internalLinkComponent?: ComponentType<LinkProps>
|
|
96
96
|
|
|
97
97
|
/**
|
|
98
98
|
* The React component rendered for links when the URL is external.
|
|
99
99
|
*
|
|
100
100
|
* @defaultValue `<a>`
|
|
101
101
|
*/
|
|
102
|
-
externalLinkComponent?: ComponentType<LinkProps
|
|
102
|
+
externalLinkComponent?: ComponentType<LinkProps>
|
|
103
103
|
|
|
104
104
|
/**
|
|
105
105
|
* The value to be rendered when the field is empty. If a fallback is not given, `null` will be
|
|
106
106
|
* rendered.
|
|
107
107
|
*/
|
|
108
|
-
fallback?: ReactNode
|
|
109
|
-
}
|
|
108
|
+
fallback?: ReactNode
|
|
109
|
+
}
|
|
110
110
|
|
|
111
111
|
type CreateDefaultSerializerArgs = {
|
|
112
|
-
linkResolver: LinkResolverFunction | undefined
|
|
113
|
-
internalLinkComponent?: ComponentType<LinkProps
|
|
114
|
-
externalLinkComponent?: ComponentType<LinkProps
|
|
115
|
-
}
|
|
112
|
+
linkResolver: LinkResolverFunction | undefined
|
|
113
|
+
internalLinkComponent?: ComponentType<LinkProps>
|
|
114
|
+
externalLinkComponent?: ComponentType<LinkProps>
|
|
115
|
+
}
|
|
116
116
|
|
|
117
117
|
const getDir = (node: RTAnyNode): "rtl" | undefined => {
|
|
118
118
|
if ("direction" in node && node.direction === "rtl") {
|
|
119
|
-
return "rtl"
|
|
119
|
+
return "rtl"
|
|
120
120
|
}
|
|
121
|
-
}
|
|
121
|
+
}
|
|
122
122
|
|
|
123
123
|
const createDefaultSerializer = (args: CreateDefaultSerializerArgs): JSXFunctionSerializer =>
|
|
124
124
|
wrapMapSerializer<ReactNode>({
|
|
@@ -179,7 +179,7 @@ const createDefaultSerializer = (args: CreateDefaultSerializerArgs): JSXFunction
|
|
|
179
179
|
alt={node.alt ?? undefined}
|
|
180
180
|
data-copyright={node.copyright ? node.copyright : undefined}
|
|
181
181
|
/>
|
|
182
|
-
)
|
|
182
|
+
)
|
|
183
183
|
|
|
184
184
|
return (
|
|
185
185
|
<p key={key} className="block-img">
|
|
@@ -196,7 +196,7 @@ const createDefaultSerializer = (args: CreateDefaultSerializerArgs): JSXFunction
|
|
|
196
196
|
img
|
|
197
197
|
)}
|
|
198
198
|
</p>
|
|
199
|
-
)
|
|
199
|
+
)
|
|
200
200
|
},
|
|
201
201
|
embed: ({ node, key }) => (
|
|
202
202
|
<div
|
|
@@ -224,28 +224,28 @@ const createDefaultSerializer = (args: CreateDefaultSerializerArgs): JSXFunction
|
|
|
224
224
|
</span>
|
|
225
225
|
),
|
|
226
226
|
span: ({ text, key }) => {
|
|
227
|
-
const result: ReactNode[] = []
|
|
227
|
+
const result: ReactNode[] = []
|
|
228
228
|
|
|
229
|
-
let i = 0
|
|
229
|
+
let i = 0
|
|
230
230
|
for (const line of text.split("\n")) {
|
|
231
231
|
if (i > 0) {
|
|
232
|
-
result.push(<br key={`${i}__break`} />)
|
|
232
|
+
result.push(<br key={`${i}__break`} />)
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
-
result.push(<Fragment key={`${i}__line`}>{line}</Fragment>)
|
|
235
|
+
result.push(<Fragment key={`${i}__line`}>{line}</Fragment>)
|
|
236
236
|
|
|
237
|
-
i
|
|
237
|
+
i++
|
|
238
238
|
}
|
|
239
239
|
|
|
240
|
-
return <Fragment key={key}>{result}</Fragment
|
|
240
|
+
return <Fragment key={key}>{result}</Fragment>
|
|
241
241
|
},
|
|
242
|
-
})
|
|
242
|
+
})
|
|
243
243
|
|
|
244
244
|
/**
|
|
245
245
|
* Renders content from a Prismic rich text field as React components.
|
|
246
246
|
*
|
|
247
247
|
* @example
|
|
248
|
-
*
|
|
248
|
+
* ;```tsx
|
|
249
249
|
* <PrismicRichText field={slice.primary.text} />;
|
|
250
250
|
* ```
|
|
251
251
|
*
|
|
@@ -260,7 +260,7 @@ export const PrismicRichText: FC<PrismicRichTextProps> = (props) => {
|
|
|
260
260
|
externalLinkComponent,
|
|
261
261
|
internalLinkComponent,
|
|
262
262
|
...restProps
|
|
263
|
-
} = props
|
|
263
|
+
} = props
|
|
264
264
|
|
|
265
265
|
if (DEV) {
|
|
266
266
|
if ("className" in restProps) {
|
|
@@ -269,12 +269,12 @@ export const PrismicRichText: FC<PrismicRichTextProps> = (props) => {
|
|
|
269
269
|
"classname-is-not-a-valid-prop",
|
|
270
270
|
)}.`,
|
|
271
271
|
field,
|
|
272
|
-
)
|
|
272
|
+
)
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
if (!isFilled.richText(field)) {
|
|
277
|
-
return fallback != null ? <>{fallback}</> : null
|
|
277
|
+
return fallback != null ? <>{fallback}</> : null
|
|
278
278
|
}
|
|
279
279
|
|
|
280
280
|
const serializer = composeSerializers<ReactNode>(
|
|
@@ -284,24 +284,24 @@ export const PrismicRichText: FC<PrismicRichTextProps> = (props) => {
|
|
|
284
284
|
internalLinkComponent,
|
|
285
285
|
externalLinkComponent,
|
|
286
286
|
}),
|
|
287
|
-
)
|
|
287
|
+
)
|
|
288
288
|
|
|
289
289
|
// The serializer is wrapped in a higher-order function that
|
|
290
290
|
// automatically applies a key to React Elements if one is not already
|
|
291
291
|
// given.
|
|
292
292
|
const serialized = serialize<ReactNode>(field, (type, node, text, children, key) => {
|
|
293
|
-
const result = serializer(type, node, text, children, key)
|
|
293
|
+
const result = serializer(type, node, text, children, key)
|
|
294
294
|
|
|
295
295
|
if (isValidElement(result) && result.key == null) {
|
|
296
|
-
return cloneElement(result, { key })
|
|
296
|
+
return cloneElement(result, { key })
|
|
297
297
|
} else {
|
|
298
|
-
return result
|
|
298
|
+
return result
|
|
299
299
|
}
|
|
300
|
-
})
|
|
300
|
+
})
|
|
301
301
|
|
|
302
302
|
if (!serialized) {
|
|
303
|
-
return fallback != null ? <>{fallback}</> : null
|
|
303
|
+
return fallback != null ? <>{fallback}</> : null
|
|
304
304
|
}
|
|
305
305
|
|
|
306
|
-
return <>{serialized}
|
|
307
|
-
}
|
|
306
|
+
return <>{serialized}</>
|
|
307
|
+
}
|
package/src/PrismicTable.tsx
CHANGED
|
@@ -7,22 +7,22 @@ import {
|
|
|
7
7
|
type TableFieldBodyRow,
|
|
8
8
|
type TableFieldHeaderCell,
|
|
9
9
|
type TableFieldDataCell,
|
|
10
|
-
} from "@prismicio/client"
|
|
11
|
-
import type { ComponentType, FC, ReactNode } from "react"
|
|
10
|
+
} from "@prismicio/client"
|
|
11
|
+
import type { ComponentType, FC, ReactNode } from "react"
|
|
12
12
|
|
|
13
|
-
import { type JSXMapSerializer, PrismicRichText } from "./PrismicRichText.js"
|
|
13
|
+
import { type JSXMapSerializer, PrismicRichText } from "./PrismicRichText.js"
|
|
14
14
|
|
|
15
15
|
type TableComponents = {
|
|
16
|
-
table?: ComponentType<{ table: TableField<"filled">; children: ReactNode }
|
|
17
|
-
thead?: ComponentType<{ head: TableFieldHead; children: ReactNode }
|
|
18
|
-
tbody?: ComponentType<{ body: TableFieldBody; children: ReactNode }
|
|
16
|
+
table?: ComponentType<{ table: TableField<"filled">; children: ReactNode }>
|
|
17
|
+
thead?: ComponentType<{ head: TableFieldHead; children: ReactNode }>
|
|
18
|
+
tbody?: ComponentType<{ body: TableFieldBody; children: ReactNode }>
|
|
19
19
|
tr?: ComponentType<{
|
|
20
|
-
row: TableFieldHeadRow | TableFieldBodyRow
|
|
21
|
-
children: ReactNode
|
|
22
|
-
}
|
|
23
|
-
th?: ComponentType<{ cell: TableFieldHeaderCell; children: ReactNode }
|
|
24
|
-
td?: ComponentType<{ cell: TableFieldDataCell; children: ReactNode }
|
|
25
|
-
}
|
|
20
|
+
row: TableFieldHeadRow | TableFieldBodyRow
|
|
21
|
+
children: ReactNode
|
|
22
|
+
}>
|
|
23
|
+
th?: ComponentType<{ cell: TableFieldHeaderCell; children: ReactNode }>
|
|
24
|
+
td?: ComponentType<{ cell: TableFieldDataCell; children: ReactNode }>
|
|
25
|
+
}
|
|
26
26
|
|
|
27
27
|
const defaultComponents: Required<TableComponents> = {
|
|
28
28
|
table: ({ children }) => <table>{children}</table>,
|
|
@@ -31,12 +31,12 @@ const defaultComponents: Required<TableComponents> = {
|
|
|
31
31
|
tr: ({ children }) => <tr>{children}</tr>,
|
|
32
32
|
th: ({ children }) => <th>{children}</th>,
|
|
33
33
|
td: ({ children }) => <td>{children}</td>,
|
|
34
|
-
}
|
|
34
|
+
}
|
|
35
35
|
|
|
36
36
|
/** Props for `<PrismicTable>`. */
|
|
37
37
|
export type PrismicTableProps = {
|
|
38
38
|
/** The Prismic table field to render. */
|
|
39
|
-
field: TableField
|
|
39
|
+
field: TableField
|
|
40
40
|
|
|
41
41
|
/**
|
|
42
42
|
* An object that maps a table block to a React component.
|
|
@@ -51,33 +51,33 @@ export type PrismicTableProps = {
|
|
|
51
51
|
* }
|
|
52
52
|
* ```
|
|
53
53
|
*/
|
|
54
|
-
components?: JSXMapSerializer & TableComponents
|
|
54
|
+
components?: JSXMapSerializer & TableComponents
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
* The value to be rendered when the field is empty. If a fallback is not given, `null` will be
|
|
58
58
|
* rendered.
|
|
59
59
|
*/
|
|
60
|
-
fallback?: ReactNode
|
|
61
|
-
}
|
|
60
|
+
fallback?: ReactNode
|
|
61
|
+
}
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
64
|
* Renders content from a Prismic table field as React components.
|
|
65
65
|
*
|
|
66
66
|
* @example
|
|
67
|
-
*
|
|
67
|
+
* ;```tsx
|
|
68
68
|
* <PrismicTable field={slice.primary.pricing_table} />;
|
|
69
69
|
* ```
|
|
70
70
|
*
|
|
71
71
|
* @see Learn how to style tables and customize table element components: {@link https://prismic.io/docs/fields/table}
|
|
72
72
|
*/
|
|
73
73
|
export const PrismicTable: FC<PrismicTableProps> = (props) => {
|
|
74
|
-
const { field, components, fallback = null } = props
|
|
74
|
+
const { field, components, fallback = null } = props
|
|
75
75
|
|
|
76
76
|
if (!isFilled.table(field)) {
|
|
77
|
-
return fallback
|
|
77
|
+
return fallback
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
const { table: Table, thead: Thead, tbody: Tbody } = { ...defaultComponents, ...components }
|
|
80
|
+
const { table: Table, thead: Thead, tbody: Tbody } = { ...defaultComponents, ...components }
|
|
81
81
|
|
|
82
82
|
return (
|
|
83
83
|
<Table table={field}>
|
|
@@ -94,18 +94,18 @@ export const PrismicTable: FC<PrismicTableProps> = (props) => {
|
|
|
94
94
|
))}
|
|
95
95
|
</Tbody>
|
|
96
96
|
</Table>
|
|
97
|
-
)
|
|
98
|
-
}
|
|
97
|
+
)
|
|
98
|
+
}
|
|
99
99
|
|
|
100
100
|
type TableRowProps = {
|
|
101
|
-
row: TableFieldHeadRow | TableFieldBodyRow
|
|
102
|
-
components?: JSXMapSerializer & TableComponents
|
|
103
|
-
}
|
|
101
|
+
row: TableFieldHeadRow | TableFieldBodyRow
|
|
102
|
+
components?: JSXMapSerializer & TableComponents
|
|
103
|
+
}
|
|
104
104
|
|
|
105
105
|
function TableRow(props: TableRowProps) {
|
|
106
|
-
const { row, components } = props
|
|
106
|
+
const { row, components } = props
|
|
107
107
|
|
|
108
|
-
const { tr: Tr, th: Th, td: Td } = { ...defaultComponents, ...components }
|
|
108
|
+
const { tr: Tr, th: Th, td: Td } = { ...defaultComponents, ...components }
|
|
109
109
|
|
|
110
110
|
return (
|
|
111
111
|
<Tr row={row}>
|
|
@@ -121,5 +121,5 @@ function TableRow(props: TableRowProps) {
|
|
|
121
121
|
),
|
|
122
122
|
)}
|
|
123
123
|
</Tr>
|
|
124
|
-
)
|
|
124
|
+
)
|
|
125
125
|
}
|
package/src/PrismicText.tsx
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import { asText, isFilled, type RichTextField } from "@prismicio/client"
|
|
2
|
-
import { DEV } from "esm-env"
|
|
3
|
-
import type { FC } from "react"
|
|
1
|
+
import { asText, isFilled, type RichTextField } from "@prismicio/client"
|
|
2
|
+
import { DEV } from "esm-env"
|
|
3
|
+
import type { FC } from "react"
|
|
4
4
|
|
|
5
|
-
import { devMsg } from "./lib/devMsg.js"
|
|
5
|
+
import { devMsg } from "./lib/devMsg.js"
|
|
6
6
|
|
|
7
7
|
/** Props for `<PrismicText>`. */
|
|
8
8
|
export type PrismicTextProps = {
|
|
9
9
|
/** The Prismic rich text field to render. */
|
|
10
|
-
field: RichTextField | null | undefined
|
|
10
|
+
field: RichTextField | null | undefined
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* The string rendered when the field is empty. If a fallback is not given, `null` will be
|
|
14
14
|
* rendered.
|
|
15
15
|
*/
|
|
16
|
-
fallback?: string
|
|
16
|
+
fallback?: string
|
|
17
17
|
|
|
18
18
|
/** The separator used between blocks. Defaults to `\n`. */
|
|
19
|
-
separator?: string
|
|
20
|
-
}
|
|
19
|
+
separator?: string
|
|
20
|
+
}
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Renders content from a Prismic rich text field as plain text (no HTML).
|
|
24
24
|
*
|
|
25
25
|
* @example
|
|
26
|
-
*
|
|
26
|
+
* ;```tsx
|
|
27
27
|
* <PrismicText field={slice.primary.text} />;
|
|
28
28
|
* ```
|
|
29
29
|
*
|
|
30
30
|
* @see Learn how to display rich text as plain text or React components: {@link https://prismic.io/docs/fields/rich-text}
|
|
31
31
|
*/
|
|
32
32
|
export const PrismicText: FC<PrismicTextProps> = (props) => {
|
|
33
|
-
const { field, fallback, separator } = props
|
|
33
|
+
const { field, fallback, separator } = props
|
|
34
34
|
|
|
35
35
|
if (DEV) {
|
|
36
36
|
if ("className" in props) {
|
|
@@ -39,7 +39,7 @@ export const PrismicText: FC<PrismicTextProps> = (props) => {
|
|
|
39
39
|
"classname-is-not-a-valid-prop",
|
|
40
40
|
)}.`,
|
|
41
41
|
props.field,
|
|
42
|
-
)
|
|
42
|
+
)
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
|
|
@@ -50,15 +50,15 @@ export const PrismicText: FC<PrismicTextProps> = (props) => {
|
|
|
50
50
|
"prismictext-works-only-with-rich-text-and-title-fields",
|
|
51
51
|
)}`,
|
|
52
52
|
props.field,
|
|
53
|
-
)
|
|
53
|
+
)
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
return null
|
|
56
|
+
return null
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
if (!isFilled.richText(field)) {
|
|
60
|
-
return fallback != null ? <>{fallback}</> : null
|
|
60
|
+
return fallback != null ? <>{fallback}</> : null
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
return <>{asText(field, { separator })}
|
|
64
|
-
}
|
|
63
|
+
return <>{asText(field, { separator })}</>
|
|
64
|
+
}
|