@prismicio/react 2.9.1 → 3.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -11
- package/dist/PrismicImage.d.ts +18 -633
- package/dist/PrismicImage.js +32 -33
- package/dist/PrismicImage.js.map +1 -1
- package/dist/PrismicLink.d.ts +77 -6
- package/dist/PrismicLink.js +42 -7
- package/dist/PrismicLink.js.map +1 -1
- package/dist/PrismicRichText.d.ts +117 -4
- package/dist/PrismicRichText.js +74 -8
- package/dist/PrismicRichText.js.map +1 -1
- package/dist/PrismicText.d.ts +8 -13
- package/dist/PrismicText.js +15 -16
- package/dist/PrismicText.js.map +1 -1
- package/dist/PrismicToolbar.d.ts +2 -12
- package/dist/PrismicToolbar.js +8 -10
- package/dist/PrismicToolbar.js.map +1 -1
- package/dist/SliceZone.d.ts +16 -70
- package/dist/SliceZone.js +16 -37
- package/dist/SliceZone.js.map +1 -1
- package/dist/index.d.ts +13 -21
- package/dist/index.js +2 -29
- package/dist/index.js.map +1 -1
- package/dist/lib/devMsg.d.ts +2 -2
- package/dist/lib/devMsg.js +2 -2
- package/dist/lib/devMsg.js.map +1 -1
- package/dist/package.json.js +1 -1
- package/package.json +53 -70
- package/src/PrismicImage.tsx +80 -65
- package/src/PrismicLink.tsx +196 -26
- package/src/PrismicRichText.tsx +333 -33
- package/src/PrismicText.tsx +25 -30
- package/src/PrismicToolbar.tsx +10 -30
- package/src/SliceZone.tsx +58 -150
- package/src/index.ts +17 -53
- package/src/lib/devMsg.ts +3 -3
- package/dist/PrismicImage.cjs +0 -68
- package/dist/PrismicImage.cjs.map +0 -1
- package/dist/PrismicLink.cjs +0 -29
- package/dist/PrismicLink.cjs.map +0 -1
- package/dist/PrismicProvider.cjs +0 -41
- package/dist/PrismicProvider.cjs.map +0 -1
- package/dist/PrismicProvider.d.ts +0 -83
- package/dist/PrismicProvider.js +0 -24
- package/dist/PrismicProvider.js.map +0 -1
- package/dist/PrismicRichText.cjs +0 -30
- package/dist/PrismicRichText.cjs.map +0 -1
- package/dist/PrismicText.cjs +0 -44
- package/dist/PrismicText.cjs.map +0 -1
- package/dist/PrismicToolbar.cjs +0 -43
- package/dist/PrismicToolbar.cjs.map +0 -1
- package/dist/SliceZone.cjs +0 -53
- package/dist/SliceZone.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs +0 -16
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js +0 -16
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.cjs +0 -13
- package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.js +0 -13
- package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.cjs +0 -22
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.js +0 -22
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.cjs +0 -46
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.js +0 -46
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs +0 -47
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js +0 -47
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.cjs +0 -28
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.js +0 -28
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asText.cjs +0 -21
- package/dist/_node_modules/@prismicio/client/dist/helpers/asText.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asText.js +0 -21
- package/dist/_node_modules/@prismicio/client/dist/helpers/asText.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs +0 -27
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js +0 -27
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.cjs +0 -24
- package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.js +0 -24
- package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.cjs +0 -7
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.js +0 -7
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.cjs +0 -9
- package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.js +0 -9
- package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/richtext/asText.cjs +0 -13
- package/dist/_node_modules/@prismicio/client/dist/richtext/asText.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/richtext/asText.js +0 -13
- package/dist/_node_modules/@prismicio/client/dist/richtext/asText.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.cjs +0 -10
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.js +0 -10
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.js.map +0 -1
- package/dist/_node_modules/imgix-url-builder/dist/buildPixelDensitySrcSet.cjs +0 -10
- package/dist/_node_modules/imgix-url-builder/dist/buildPixelDensitySrcSet.cjs.map +0 -1
- package/dist/_node_modules/imgix-url-builder/dist/buildPixelDensitySrcSet.js +0 -10
- package/dist/_node_modules/imgix-url-builder/dist/buildPixelDensitySrcSet.js.map +0 -1
- package/dist/_node_modules/imgix-url-builder/dist/buildURL.cjs +0 -29
- package/dist/_node_modules/imgix-url-builder/dist/buildURL.cjs.map +0 -1
- package/dist/_node_modules/imgix-url-builder/dist/buildURL.js +0 -29
- package/dist/_node_modules/imgix-url-builder/dist/buildURL.js.map +0 -1
- package/dist/_node_modules/imgix-url-builder/dist/buildWidthSrcSet.cjs +0 -10
- package/dist/_node_modules/imgix-url-builder/dist/buildWidthSrcSet.cjs.map +0 -1
- package/dist/_node_modules/imgix-url-builder/dist/buildWidthSrcSet.js +0 -10
- package/dist/_node_modules/imgix-url-builder/dist/buildWidthSrcSet.js.map +0 -1
- package/dist/clientHooks.cjs +0 -40
- package/dist/clientHooks.cjs.map +0 -1
- package/dist/clientHooks.d.ts +0 -321
- package/dist/clientHooks.js +0 -40
- package/dist/clientHooks.js.map +0 -1
- package/dist/index.cjs +0 -48
- package/dist/index.cjs.map +0 -1
- package/dist/lib/devMsg.cjs +0 -8
- package/dist/lib/devMsg.cjs.map +0 -1
- package/dist/lib/isInternalURL.cjs +0 -9
- package/dist/lib/isInternalURL.cjs.map +0 -1
- package/dist/lib/isInternalURL.d.ts +0 -8
- package/dist/lib/isInternalURL.js +0 -9
- package/dist/lib/isInternalURL.js.map +0 -1
- package/dist/lib/pascalCase.cjs +0 -10
- package/dist/lib/pascalCase.cjs.map +0 -1
- package/dist/lib/pascalCase.d.ts +0 -26
- package/dist/lib/pascalCase.js +0 -10
- package/dist/lib/pascalCase.js.map +0 -1
- package/dist/package.json.cjs +0 -5
- package/dist/package.json.cjs.map +0 -1
- package/dist/react-server/PrismicLink.cjs +0 -59
- package/dist/react-server/PrismicLink.cjs.map +0 -1
- package/dist/react-server/PrismicLink.d.ts +0 -77
- package/dist/react-server/PrismicLink.js +0 -42
- package/dist/react-server/PrismicLink.js.map +0 -1
- package/dist/react-server/PrismicRichText.cjs +0 -102
- package/dist/react-server/PrismicRichText.cjs.map +0 -1
- package/dist/react-server/PrismicRichText.d.ts +0 -104
- package/dist/react-server/PrismicRichText.js +0 -84
- package/dist/react-server/PrismicRichText.js.map +0 -1
- package/dist/react-server/index.d.ts +0 -4
- package/dist/react-server/unsupported.cjs +0 -97
- package/dist/react-server/unsupported.cjs.map +0 -1
- package/dist/react-server/unsupported.d.ts +0 -22
- package/dist/react-server/unsupported.js +0 -97
- package/dist/react-server/unsupported.js.map +0 -1
- package/dist/react-server.cjs +0 -44
- package/dist/react-server.cjs.map +0 -1
- package/dist/react-server.js +0 -41
- package/dist/react-server.js.map +0 -1
- package/dist/types.d.ts +0 -19
- package/dist/usePrismicClient.cjs +0 -13
- package/dist/usePrismicClient.cjs.map +0 -1
- package/dist/usePrismicClient.d.ts +0 -11
- package/dist/usePrismicClient.js +0 -13
- package/dist/usePrismicClient.js.map +0 -1
- package/dist/usePrismicContext.cjs +0 -26
- package/dist/usePrismicContext.cjs.map +0 -1
- package/dist/usePrismicContext.d.ts +0 -8
- package/dist/usePrismicContext.js +0 -9
- package/dist/usePrismicContext.js.map +0 -1
- package/dist/usePrismicPreviewResolver.cjs +0 -44
- package/dist/usePrismicPreviewResolver.cjs.map +0 -1
- package/dist/usePrismicPreviewResolver.d.ts +0 -45
- package/dist/usePrismicPreviewResolver.js +0 -27
- package/dist/usePrismicPreviewResolver.js.map +0 -1
- package/dist/useStatefulPrismicClientMethod.cjs +0 -91
- package/dist/useStatefulPrismicClientMethod.cjs.map +0 -1
- package/dist/useStatefulPrismicClientMethod.d.ts +0 -44
- package/dist/useStatefulPrismicClientMethod.js +0 -74
- package/dist/useStatefulPrismicClientMethod.js.map +0 -1
- package/src/PrismicProvider.tsx +0 -132
- package/src/clientHooks.ts +0 -472
- package/src/lib/isInternalURL.ts +0 -14
- package/src/lib/pascalCase.ts +0 -79
- package/src/react-server/PrismicLink.tsx +0 -197
- package/src/react-server/PrismicRichText.tsx +0 -326
- package/src/react-server/index.ts +0 -38
- package/src/react-server/unsupported.ts +0 -184
- package/src/types.ts +0 -23
- package/src/usePrismicClient.ts +0 -30
- package/src/usePrismicContext.ts +0 -13
- package/src/usePrismicPreviewResolver.ts +0 -93
- package/src/useStatefulPrismicClientMethod.ts +0 -196
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import {
|
|
3
|
-
LinkField,
|
|
4
|
-
LinkResolverFunction,
|
|
5
|
-
PrismicDocument,
|
|
6
|
-
asLinkAttrs,
|
|
7
|
-
AsLinkAttrsConfig,
|
|
8
|
-
} from "@prismicio/client";
|
|
9
|
-
|
|
10
|
-
import { devMsg } from "../lib/devMsg";
|
|
11
|
-
import { isInternalURL } from "../lib/isInternalURL";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* The default component rendered for internal and external links.
|
|
15
|
-
*/
|
|
16
|
-
export const defaultComponent = "a";
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Props provided to a component when rendered with `<PrismicLink>`.
|
|
20
|
-
*/
|
|
21
|
-
export interface LinkProps {
|
|
22
|
-
/**
|
|
23
|
-
* The URL to link.
|
|
24
|
-
*/
|
|
25
|
-
href: string;
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* The `target` attribute for anchor elements. If the Prismic field is
|
|
29
|
-
* configured to open in a new window, this prop defaults to `_blank`.
|
|
30
|
-
*/
|
|
31
|
-
target?: React.HTMLAttributeAnchorTarget;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* The `rel` attribute for anchor elements. If the `target` prop is set to
|
|
35
|
-
* `"_blank"`, this prop defaults to `"noopener noreferrer"`.
|
|
36
|
-
*/
|
|
37
|
-
rel?: string;
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Children for the component. *
|
|
41
|
-
*/
|
|
42
|
-
children?: React.ReactNode;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export type PrismicLinkProps<
|
|
46
|
-
InternalComponentProps = React.ComponentProps<typeof defaultComponent>,
|
|
47
|
-
ExternalComponentProps = React.ComponentProps<typeof defaultComponent>,
|
|
48
|
-
> = Omit<
|
|
49
|
-
InternalComponentProps & ExternalComponentProps,
|
|
50
|
-
"rel" | "href" | "children"
|
|
51
|
-
> & {
|
|
52
|
-
/**
|
|
53
|
-
* The `rel` attribute for the link. By default, `"noreferrer"` is provided if
|
|
54
|
-
* the link's URL is external. This prop can be provided a function to use the
|
|
55
|
-
* link's metadata to determine the `rel` value.
|
|
56
|
-
*/
|
|
57
|
-
rel?: string | AsLinkAttrsConfig["rel"];
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* The Link Resolver used to resolve links.
|
|
61
|
-
*
|
|
62
|
-
* @remarks
|
|
63
|
-
* If your app uses Route Resolvers when querying for your Prismic
|
|
64
|
-
* repository's content, a Link Resolver does not need to be provided.
|
|
65
|
-
* @see Learn about Link Resolvers and Route Resolvers {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}
|
|
66
|
-
*/
|
|
67
|
-
linkResolver?: LinkResolverFunction;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* The component rendered for internal URLs. Defaults to `<a>`.
|
|
71
|
-
*
|
|
72
|
-
* If your app uses a client-side router that requires a special Link
|
|
73
|
-
* component, provide the Link component to this prop.
|
|
74
|
-
*/
|
|
75
|
-
internalComponent?: React.ElementType<InternalComponentProps>;
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* The component rendered for external URLs. Defaults to `<a>`.
|
|
79
|
-
*/
|
|
80
|
-
externalComponent?: React.ComponentType<ExternalComponentProps>;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* The children to render for the link. If no children are provided, the
|
|
84
|
-
* link's `text` property will be used.
|
|
85
|
-
*/
|
|
86
|
-
children?: React.ReactNode;
|
|
87
|
-
} & (
|
|
88
|
-
| {
|
|
89
|
-
document: PrismicDocument | null | undefined;
|
|
90
|
-
href?: never;
|
|
91
|
-
field?: never;
|
|
92
|
-
}
|
|
93
|
-
| {
|
|
94
|
-
field: LinkField | null | undefined;
|
|
95
|
-
href?: never;
|
|
96
|
-
document?: never;
|
|
97
|
-
}
|
|
98
|
-
| {
|
|
99
|
-
href: LinkProps["href"];
|
|
100
|
-
field?: LinkField | null | undefined;
|
|
101
|
-
document?: never;
|
|
102
|
-
}
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
export const PrismicLink = React.forwardRef(function PrismicLink<
|
|
106
|
-
InternalComponentProps = React.ComponentProps<typeof defaultComponent>,
|
|
107
|
-
ExternalComponentProps = React.ComponentProps<typeof defaultComponent>,
|
|
108
|
-
>(
|
|
109
|
-
props: PrismicLinkProps<InternalComponentProps, ExternalComponentProps>,
|
|
110
|
-
ref: React.ForwardedRef<Element>,
|
|
111
|
-
): JSX.Element {
|
|
112
|
-
const {
|
|
113
|
-
field,
|
|
114
|
-
document: doc,
|
|
115
|
-
linkResolver,
|
|
116
|
-
internalComponent,
|
|
117
|
-
externalComponent,
|
|
118
|
-
children,
|
|
119
|
-
...restProps
|
|
120
|
-
} = props;
|
|
121
|
-
|
|
122
|
-
if (
|
|
123
|
-
typeof process !== "undefined" &&
|
|
124
|
-
process.env.NODE_ENV === "development"
|
|
125
|
-
) {
|
|
126
|
-
if (field) {
|
|
127
|
-
if (!field.link_type) {
|
|
128
|
-
console.error(
|
|
129
|
-
`[PrismicLink] This "field" prop value caused an error to be thrown.\n`,
|
|
130
|
-
field,
|
|
131
|
-
);
|
|
132
|
-
throw new Error(
|
|
133
|
-
`[PrismicLink] The provided field is missing required properties to properly render a link. The link will not render. For more details, see ${devMsg(
|
|
134
|
-
"missing-link-properties",
|
|
135
|
-
)}`,
|
|
136
|
-
);
|
|
137
|
-
} else if (
|
|
138
|
-
("text" in field
|
|
139
|
-
? Object.keys(field).length > 2
|
|
140
|
-
: Object.keys(field).length > 1) &&
|
|
141
|
-
!("url" in field || "uid" in field || "id" in field)
|
|
142
|
-
) {
|
|
143
|
-
console.warn(
|
|
144
|
-
`[PrismicLink] The provided field is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg(
|
|
145
|
-
"missing-link-properties",
|
|
146
|
-
)}`,
|
|
147
|
-
field,
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
} else if (doc) {
|
|
151
|
-
if (!("url" in doc || "id" in doc)) {
|
|
152
|
-
console.warn(
|
|
153
|
-
`[PrismicLink] The provided document is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg(
|
|
154
|
-
"missing-link-properties",
|
|
155
|
-
)}`,
|
|
156
|
-
doc,
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const {
|
|
163
|
-
href: computedHref,
|
|
164
|
-
rel: computedRel,
|
|
165
|
-
...attrs
|
|
166
|
-
} = asLinkAttrs(field ?? doc, {
|
|
167
|
-
linkResolver,
|
|
168
|
-
rel: typeof restProps.rel === "function" ? restProps.rel : undefined,
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
let rel: string | undefined = computedRel;
|
|
172
|
-
if ("rel" in restProps && typeof restProps.rel !== "function") {
|
|
173
|
-
rel = restProps.rel;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const href = ("href" in restProps ? restProps.href : computedHref) || "";
|
|
177
|
-
|
|
178
|
-
const InternalComponent = (internalComponent ||
|
|
179
|
-
defaultComponent) as React.ComponentType<LinkProps>;
|
|
180
|
-
const ExternalComponent = (externalComponent ||
|
|
181
|
-
defaultComponent) as React.ComponentType<LinkProps>;
|
|
182
|
-
const Component =
|
|
183
|
-
href && isInternalURL(href) ? InternalComponent : ExternalComponent;
|
|
184
|
-
|
|
185
|
-
return (
|
|
186
|
-
<Component ref={ref} {...attrs} {...restProps} href={href} rel={rel}>
|
|
187
|
-
{"children" in props ? children : field?.text}
|
|
188
|
-
</Component>
|
|
189
|
-
);
|
|
190
|
-
}) as <
|
|
191
|
-
InternalComponentProps = React.ComponentProps<typeof defaultComponent>,
|
|
192
|
-
ExternalComponentProps = React.ComponentProps<typeof defaultComponent>,
|
|
193
|
-
>(
|
|
194
|
-
props: PrismicLinkProps<InternalComponentProps, ExternalComponentProps> & {
|
|
195
|
-
ref?: React.ForwardedRef<Element>;
|
|
196
|
-
},
|
|
197
|
-
) => JSX.Element;
|
|
@@ -1,326 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import * as prismic from "@prismicio/client";
|
|
3
|
-
import * as prismicR from "@prismicio/richtext";
|
|
4
|
-
import * as prismicT from "@prismicio/types";
|
|
5
|
-
|
|
6
|
-
import { JSXFunctionSerializer, JSXMapSerializer } from "../types";
|
|
7
|
-
import { LinkProps, PrismicLink } from "./PrismicLink";
|
|
8
|
-
import { devMsg } from "../lib/devMsg";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Props for `<PrismicRichText>`.
|
|
12
|
-
*/
|
|
13
|
-
export type PrismicRichTextProps<
|
|
14
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
-
LinkResolverFunction extends prismic.LinkResolverFunction<any> = prismic.LinkResolverFunction,
|
|
16
|
-
> = {
|
|
17
|
-
/**
|
|
18
|
-
* The Prismic Rich Text field to render.
|
|
19
|
-
*/
|
|
20
|
-
field: prismic.RichTextField | null | undefined;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* The Link Resolver used to resolve links.
|
|
24
|
-
*
|
|
25
|
-
* @remarks
|
|
26
|
-
* If your app uses Route Resolvers when querying for your Prismic
|
|
27
|
-
* repository's content, a Link Resolver does not need to be provided.
|
|
28
|
-
* @see Learn about Link Resolvers and Route Resolvers {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}
|
|
29
|
-
*/
|
|
30
|
-
linkResolver?: LinkResolverFunction;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* A map or function that maps a Rich Text block to a React component.
|
|
34
|
-
*
|
|
35
|
-
* @remarks
|
|
36
|
-
* Prefer using a map serializer over the function serializer when possible.
|
|
37
|
-
* The map serializer is simpler to maintain.
|
|
38
|
-
* @example A map serializer.
|
|
39
|
-
*
|
|
40
|
-
* ```jsx
|
|
41
|
-
* {
|
|
42
|
-
* heading1: ({children}) => <Heading>{children}</Heading>
|
|
43
|
-
* }
|
|
44
|
-
* ```
|
|
45
|
-
*
|
|
46
|
-
* @example A function serializer.
|
|
47
|
-
*
|
|
48
|
-
* ```jsx
|
|
49
|
-
* (type, node, content, children) => {
|
|
50
|
-
* switch (type) {
|
|
51
|
-
* case "heading1": {
|
|
52
|
-
* return <Heading>{children}</Heading>;
|
|
53
|
-
* }
|
|
54
|
-
* }
|
|
55
|
-
* };
|
|
56
|
-
* ```
|
|
57
|
-
*/
|
|
58
|
-
components?: JSXMapSerializer | JSXFunctionSerializer;
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* The React component rendered for links when the URL is internal.
|
|
62
|
-
*
|
|
63
|
-
* @defaultValue `<a>`
|
|
64
|
-
*/
|
|
65
|
-
internalLinkComponent?: React.ComponentType<LinkProps>;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* The React component rendered for links when the URL is external.
|
|
69
|
-
*
|
|
70
|
-
* @defaultValue `<a>`
|
|
71
|
-
*/
|
|
72
|
-
externalLinkComponent?: React.ComponentType<LinkProps>;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* The value to be rendered when the field is empty. If a fallback is not
|
|
76
|
-
* given, `null` will be rendered.
|
|
77
|
-
*/
|
|
78
|
-
fallback?: React.ReactNode;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
type CreateDefaultSerializerArgs<
|
|
82
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
83
|
-
LinkResolverFunction extends prismic.LinkResolverFunction<any> = prismic.LinkResolverFunction,
|
|
84
|
-
> = {
|
|
85
|
-
linkResolver: LinkResolverFunction | undefined;
|
|
86
|
-
internalLinkComponent?: React.ComponentType<LinkProps>;
|
|
87
|
-
externalLinkComponent?: React.ComponentType<LinkProps>;
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const getDir = (node: prismicT.RTAnyNode): "rtl" | undefined => {
|
|
91
|
-
if ("direction" in node && node.direction === "rtl") {
|
|
92
|
-
return "rtl";
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const createDefaultSerializer = <
|
|
97
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
98
|
-
LinkResolverFunction extends prismic.LinkResolverFunction<any>,
|
|
99
|
-
>(
|
|
100
|
-
args: CreateDefaultSerializerArgs<LinkResolverFunction>,
|
|
101
|
-
): JSXFunctionSerializer =>
|
|
102
|
-
prismicR.wrapMapSerializer({
|
|
103
|
-
heading1: ({ node, children, key }) => (
|
|
104
|
-
<h1 key={key} dir={getDir(node)}>
|
|
105
|
-
{children}
|
|
106
|
-
</h1>
|
|
107
|
-
),
|
|
108
|
-
heading2: ({ node, children, key }) => (
|
|
109
|
-
<h2 key={key} dir={getDir(node)}>
|
|
110
|
-
{children}
|
|
111
|
-
</h2>
|
|
112
|
-
),
|
|
113
|
-
heading3: ({ node, children, key }) => (
|
|
114
|
-
<h3 key={key} dir={getDir(node)}>
|
|
115
|
-
{children}
|
|
116
|
-
</h3>
|
|
117
|
-
),
|
|
118
|
-
heading4: ({ node, children, key }) => (
|
|
119
|
-
<h4 key={key} dir={getDir(node)}>
|
|
120
|
-
{children}
|
|
121
|
-
</h4>
|
|
122
|
-
),
|
|
123
|
-
heading5: ({ node, children, key }) => (
|
|
124
|
-
<h5 key={key} dir={getDir(node)}>
|
|
125
|
-
{children}
|
|
126
|
-
</h5>
|
|
127
|
-
),
|
|
128
|
-
heading6: ({ node, children, key }) => (
|
|
129
|
-
<h6 key={key} dir={getDir(node)}>
|
|
130
|
-
{children}
|
|
131
|
-
</h6>
|
|
132
|
-
),
|
|
133
|
-
paragraph: ({ node, children, key }) => (
|
|
134
|
-
<p key={key} dir={getDir(node)}>
|
|
135
|
-
{children}
|
|
136
|
-
</p>
|
|
137
|
-
),
|
|
138
|
-
preformatted: ({ node, key }) => <pre key={key}>{node.text}</pre>,
|
|
139
|
-
strong: ({ children, key }) => <strong key={key}>{children}</strong>,
|
|
140
|
-
em: ({ children, key }) => <em key={key}>{children}</em>,
|
|
141
|
-
listItem: ({ node, children, key }) => (
|
|
142
|
-
<li key={key} dir={getDir(node)}>
|
|
143
|
-
{children}
|
|
144
|
-
</li>
|
|
145
|
-
),
|
|
146
|
-
oListItem: ({ node, children, key }) => (
|
|
147
|
-
<li key={key} dir={getDir(node)}>
|
|
148
|
-
{children}
|
|
149
|
-
</li>
|
|
150
|
-
),
|
|
151
|
-
list: ({ children, key }) => <ul key={key}>{children}</ul>,
|
|
152
|
-
oList: ({ children, key }) => <ol key={key}>{children}</ol>,
|
|
153
|
-
image: ({ node, key }) => {
|
|
154
|
-
const img = (
|
|
155
|
-
<img
|
|
156
|
-
src={node.url}
|
|
157
|
-
alt={node.alt ?? undefined}
|
|
158
|
-
data-copyright={node.copyright ? node.copyright : undefined}
|
|
159
|
-
/>
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
return (
|
|
163
|
-
<p key={key} className="block-img">
|
|
164
|
-
{node.linkTo ? (
|
|
165
|
-
<PrismicLink
|
|
166
|
-
linkResolver={args.linkResolver}
|
|
167
|
-
internalComponent={args.internalLinkComponent}
|
|
168
|
-
externalComponent={args.externalLinkComponent}
|
|
169
|
-
field={node.linkTo}
|
|
170
|
-
>
|
|
171
|
-
{img}
|
|
172
|
-
</PrismicLink>
|
|
173
|
-
) : (
|
|
174
|
-
img
|
|
175
|
-
)}
|
|
176
|
-
</p>
|
|
177
|
-
);
|
|
178
|
-
},
|
|
179
|
-
embed: ({ node, key }) => (
|
|
180
|
-
<div
|
|
181
|
-
key={key}
|
|
182
|
-
data-oembed={node.oembed.embed_url}
|
|
183
|
-
data-oembed-type={node.oembed.type}
|
|
184
|
-
data-oembed-provider={node.oembed.provider_name}
|
|
185
|
-
dangerouslySetInnerHTML={{ __html: node.oembed.html ?? "" }}
|
|
186
|
-
/>
|
|
187
|
-
),
|
|
188
|
-
hyperlink: ({ node, children, key }) => (
|
|
189
|
-
<PrismicLink
|
|
190
|
-
key={key}
|
|
191
|
-
field={node.data}
|
|
192
|
-
linkResolver={args.linkResolver}
|
|
193
|
-
internalComponent={args.internalLinkComponent}
|
|
194
|
-
externalComponent={args.externalLinkComponent}
|
|
195
|
-
>
|
|
196
|
-
{children}
|
|
197
|
-
</PrismicLink>
|
|
198
|
-
),
|
|
199
|
-
label: ({ node, children, key }) => (
|
|
200
|
-
<span key={key} className={node.data.label}>
|
|
201
|
-
{children}
|
|
202
|
-
</span>
|
|
203
|
-
),
|
|
204
|
-
span: ({ text, key }) => {
|
|
205
|
-
const result: React.ReactNode[] = [];
|
|
206
|
-
|
|
207
|
-
let i = 0;
|
|
208
|
-
for (const line of text.split("\n")) {
|
|
209
|
-
if (i > 0) {
|
|
210
|
-
result.push(<br key={`${i}__break`} />);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
result.push(<React.Fragment key={`${i}__line`}>{line}</React.Fragment>);
|
|
214
|
-
|
|
215
|
-
i++;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return <React.Fragment key={key}>{result}</React.Fragment>;
|
|
219
|
-
},
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* React component that renders content from a Prismic Rich Text field. By
|
|
224
|
-
* default, HTML elements are rendered for each piece of content. A `heading1`
|
|
225
|
-
* block will render an `<h1>` HTML element, for example. Links will use
|
|
226
|
-
* `<PrismicLink>` by default which can be customized using the
|
|
227
|
-
* `internalLinkComponent` and `externalLinkComponent` props.
|
|
228
|
-
*
|
|
229
|
-
* To customize the components that are rendered, provide a map or function
|
|
230
|
-
* serializer to the `components` prop.
|
|
231
|
-
*
|
|
232
|
-
* @remarks
|
|
233
|
-
* This component returns a React fragment with no wrapping element around the
|
|
234
|
-
* content. If you need a wrapper, add a component around `<PrismicRichText>`.
|
|
235
|
-
* @example Rendering a Rich Text field using the default HTMl elements.
|
|
236
|
-
*
|
|
237
|
-
* ```jsx
|
|
238
|
-
* <PrismicRichText field={document.data.content} />;
|
|
239
|
-
* ```
|
|
240
|
-
*
|
|
241
|
-
* @example Rendering a Rich Text field using a custom set of React components.
|
|
242
|
-
*
|
|
243
|
-
* ```jsx
|
|
244
|
-
* <PrismicRichText
|
|
245
|
-
* field={document.data.content}
|
|
246
|
-
* components={{
|
|
247
|
-
* heading1: ({ children }) => <Heading>{children}</Heading>,
|
|
248
|
-
* }}
|
|
249
|
-
* />;
|
|
250
|
-
* ```
|
|
251
|
-
*
|
|
252
|
-
* @param props - Props for the component.
|
|
253
|
-
*
|
|
254
|
-
* @returns The Rich Text field's content as React components.
|
|
255
|
-
*
|
|
256
|
-
* @see Learn about Rich Text fields {@link https://prismic.io/docs/core-concepts/rich-text-title}
|
|
257
|
-
* @see Learn about Rich Text serializers {@link https://prismic.io/docs/core-concepts/html-serializer}
|
|
258
|
-
*/
|
|
259
|
-
export function PrismicRichText<
|
|
260
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
261
|
-
LinkResolverFunction extends prismic.LinkResolverFunction<any>,
|
|
262
|
-
>({
|
|
263
|
-
linkResolver,
|
|
264
|
-
field,
|
|
265
|
-
fallback,
|
|
266
|
-
components,
|
|
267
|
-
externalLinkComponent,
|
|
268
|
-
internalLinkComponent,
|
|
269
|
-
...restProps
|
|
270
|
-
}: PrismicRichTextProps<LinkResolverFunction>): JSX.Element | null {
|
|
271
|
-
return React.useMemo(() => {
|
|
272
|
-
if (
|
|
273
|
-
typeof process !== "undefined" &&
|
|
274
|
-
process.env.NODE_ENV === "development"
|
|
275
|
-
) {
|
|
276
|
-
if ("className" in restProps) {
|
|
277
|
-
console.warn(
|
|
278
|
-
`[PrismicRichText] className cannot be passed to <PrismicRichText> since it renders an array without a wrapping component. For more details, see ${devMsg(
|
|
279
|
-
"classname-is-not-a-valid-prop",
|
|
280
|
-
)}.`,
|
|
281
|
-
field,
|
|
282
|
-
);
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
if (prismic.isFilled.richText(field)) {
|
|
287
|
-
const serializer = prismicR.composeSerializers(
|
|
288
|
-
typeof components === "object"
|
|
289
|
-
? prismicR.wrapMapSerializer(components)
|
|
290
|
-
: components,
|
|
291
|
-
createDefaultSerializer({
|
|
292
|
-
linkResolver,
|
|
293
|
-
internalLinkComponent,
|
|
294
|
-
externalLinkComponent,
|
|
295
|
-
}),
|
|
296
|
-
);
|
|
297
|
-
|
|
298
|
-
// The serializer is wrapped in a higher-order function
|
|
299
|
-
// that automatically applies a key to React Elements
|
|
300
|
-
// if one is not already given.
|
|
301
|
-
const serialized = prismicR.serialize<JSX.Element>(
|
|
302
|
-
field,
|
|
303
|
-
(type, node, text, children, key) => {
|
|
304
|
-
const result = serializer(type, node, text, children, key);
|
|
305
|
-
|
|
306
|
-
if (React.isValidElement(result) && result.key == null) {
|
|
307
|
-
return React.cloneElement(result, { key });
|
|
308
|
-
} else {
|
|
309
|
-
return result;
|
|
310
|
-
}
|
|
311
|
-
},
|
|
312
|
-
);
|
|
313
|
-
|
|
314
|
-
return <>{serialized}</>;
|
|
315
|
-
} else {
|
|
316
|
-
return fallback != null ? <>{fallback}</> : null;
|
|
317
|
-
}
|
|
318
|
-
}, [
|
|
319
|
-
field,
|
|
320
|
-
internalLinkComponent,
|
|
321
|
-
externalLinkComponent,
|
|
322
|
-
components,
|
|
323
|
-
linkResolver,
|
|
324
|
-
fallback,
|
|
325
|
-
]);
|
|
326
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export { PrismicLink } from "./PrismicLink";
|
|
2
|
-
export { PrismicRichText } from "./PrismicRichText";
|
|
3
|
-
|
|
4
|
-
export {
|
|
5
|
-
PrismicProvider,
|
|
6
|
-
useAllPrismicDocumentsByEveryTag,
|
|
7
|
-
useAllPrismicDocumentsByIDs,
|
|
8
|
-
useAllPrismicDocumentsBySomeTags,
|
|
9
|
-
useAllPrismicDocumentsByTag,
|
|
10
|
-
useAllPrismicDocumentsByType,
|
|
11
|
-
useAllPrismicDocumentsByUIDs,
|
|
12
|
-
useAllPrismicDocumentsDangerously,
|
|
13
|
-
useFirstPrismicDocument,
|
|
14
|
-
usePrismicClient,
|
|
15
|
-
usePrismicContext,
|
|
16
|
-
usePrismicDocumentByID,
|
|
17
|
-
usePrismicDocumentByUID,
|
|
18
|
-
usePrismicDocuments,
|
|
19
|
-
usePrismicDocumentsByEveryTag,
|
|
20
|
-
usePrismicDocumentsByIDs,
|
|
21
|
-
usePrismicDocumentsBySomeTags,
|
|
22
|
-
usePrismicDocumentsByTag,
|
|
23
|
-
usePrismicDocumentsByType,
|
|
24
|
-
usePrismicDocumentsByUIDs,
|
|
25
|
-
usePrismicPreviewResolver,
|
|
26
|
-
useSinglePrismicDocument,
|
|
27
|
-
} from "./unsupported";
|
|
28
|
-
|
|
29
|
-
// The following exports do not have RSC-specific implementations.
|
|
30
|
-
// They are aliases for the default package exports.
|
|
31
|
-
export {
|
|
32
|
-
Element,
|
|
33
|
-
PrismicImage,
|
|
34
|
-
PrismicText,
|
|
35
|
-
PrismicToolbar,
|
|
36
|
-
SliceZone,
|
|
37
|
-
TODOSliceComponent,
|
|
38
|
-
} from "..";
|