@prismicio/next 2.2.0-pr.123.1c009e2 → 2.2.0-pr.125.afe01f5
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/dist/{PrismicImage.d.cts → PrismicNextImage.d.ts} +7 -8
- package/dist/PrismicNextImage.js +69 -0
- package/dist/PrismicNextImage.js.map +1 -0
- package/dist/{PrismicLink.d.cts → PrismicNextLink.d.ts} +6 -7
- package/dist/PrismicNextLink.js +29 -0
- package/dist/PrismicNextLink.js.map +1 -0
- package/dist/{PrismicPreview.d.cts → PrismicPreview.d.ts} +1 -1
- package/dist/PrismicPreview.js +39 -0
- package/dist/PrismicPreview.js.map +1 -0
- package/dist/{PrismicPreviewClient.cjs → PrismicPreviewClient.js} +12 -13
- package/dist/PrismicPreviewClient.js.map +1 -0
- package/dist/{SliceSimulator.d.cts → SliceSimulator.d.ts} +1 -1
- package/dist/SliceSimulator.js +48 -0
- package/dist/SliceSimulator.js.map +1 -0
- package/dist/SliceSimulatorWrapper.js +35 -0
- package/dist/SliceSimulatorWrapper.js.map +1 -0
- package/dist/{createLocaleRedirect.d.cts → createLocaleRedirect.d.ts} +1 -1
- package/dist/createLocaleRedirect.js +14 -0
- package/dist/createLocaleRedirect.js.map +1 -0
- package/dist/{enableAutoPreviews.d.cts → enableAutoPreviews.d.ts} +1 -1
- package/dist/{enableAutoPreviews.cjs → enableAutoPreviews.js} +7 -8
- package/dist/enableAutoPreviews.js.map +1 -0
- package/dist/{exitPreview.d.cts → exitPreview.d.ts} +1 -1
- package/dist/{exitPreview.cjs → exitPreview.js} +2 -3
- package/dist/exitPreview.js.map +1 -0
- package/dist/{getSlices.d.cts → getSlices.d.ts} +1 -1
- package/dist/getSlices.js +11 -0
- package/dist/getSlices.js.map +1 -0
- package/dist/{imgixLoader.d.cts → imgixLoader.d.ts} +1 -1
- package/dist/{imgixLoader.cjs → imgixLoader.js} +4 -5
- package/dist/imgixLoader.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +12 -0
- package/dist/lib/{devMsg.cjs → devMsg.js} +4 -4
- package/dist/lib/devMsg.js.map +1 -0
- package/dist/lib/{resolveDefaultExport.cjs → resolveDefaultExport.js} +2 -3
- package/dist/lib/resolveDefaultExport.js.map +1 -0
- package/dist/package.js +6 -0
- package/dist/package.js.map +1 -0
- package/dist/pages/{PrismicPreview.d.cts → PrismicPreview.d.ts} +1 -1
- package/dist/pages/{PrismicPreview.cjs → PrismicPreview.js} +13 -15
- package/dist/pages/PrismicPreview.js.map +1 -0
- package/dist/pages/{SliceSimulator.d.cts → SliceSimulator.d.ts} +1 -1
- package/dist/pages/SliceSimulator.js +40 -0
- package/dist/pages/SliceSimulator.js.map +1 -0
- package/dist/pages/{enableAutoPreviews.d.cts → enableAutoPreviews.d.ts} +2 -2
- package/dist/pages/{enableAutoPreviews.cjs → enableAutoPreviews.js} +2 -3
- package/dist/pages/enableAutoPreviews.js.map +1 -0
- package/dist/pages/{exitPreview.d.cts → exitPreview.d.ts} +2 -2
- package/dist/pages/{exitPreview.cjs → exitPreview.js} +2 -3
- package/dist/pages/exitPreview.js.map +1 -0
- package/dist/pages/{redirectToPreviewURL.d.cts → redirectToPreviewURL.d.ts} +2 -2
- package/dist/pages/{redirectToPreviewURL.cjs → redirectToPreviewURL.js} +2 -3
- package/dist/pages/redirectToPreviewURL.js.map +1 -0
- package/dist/pages/{setPreviewData.d.cts → setPreviewData.d.ts} +2 -2
- package/dist/pages/setPreviewData.js +12 -0
- package/dist/pages/setPreviewData.js.map +1 -0
- package/dist/pages/{types.d.cts → types.d.ts} +2 -2
- package/dist/pages.d.ts +12 -0
- package/dist/pages.js +12 -0
- package/dist/{redirectToPreviewURL.d.cts → redirectToPreviewURL.d.ts} +2 -2
- package/dist/{redirectToPreviewURL.cjs → redirectToPreviewURL.js} +6 -7
- package/dist/redirectToPreviewURL.js.map +1 -0
- package/dist/{types.d.cts → types.d.ts} +1 -1
- package/package.json +5 -18
- package/src/PrismicNextImage.tsx +185 -0
- package/src/PrismicNextLink.tsx +67 -0
- package/src/index.ts +5 -21
- package/src/pages/index.ts +4 -20
- package/dist/PrismicImage.cjs +0 -71
- package/dist/PrismicImage.cjs.map +0 -1
- package/dist/PrismicLink.cjs +0 -31
- package/dist/PrismicLink.cjs.map +0 -1
- package/dist/PrismicPreview.cjs +0 -41
- package/dist/PrismicPreview.cjs.map +0 -1
- package/dist/PrismicPreviewClient.cjs.map +0 -1
- package/dist/PrismicRichText.cjs +0 -50
- package/dist/PrismicRichText.cjs.map +0 -1
- package/dist/PrismicRichText.d.cts +0 -27
- package/dist/PrismicTable.cjs +0 -34
- package/dist/PrismicTable.cjs.map +0 -1
- package/dist/PrismicTable.d.cts +0 -22
- package/dist/SliceSimulator.cjs +0 -49
- package/dist/SliceSimulator.cjs.map +0 -1
- package/dist/SliceSimulatorWrapper.cjs +0 -36
- package/dist/SliceSimulatorWrapper.cjs.map +0 -1
- package/dist/_virtual/rolldown_runtime.cjs +0 -29
- package/dist/createLocaleRedirect.cjs +0 -14
- package/dist/createLocaleRedirect.cjs.map +0 -1
- package/dist/enableAutoPreviews.cjs.map +0 -1
- package/dist/exitPreview.cjs.map +0 -1
- package/dist/getSlices.cjs +0 -12
- package/dist/getSlices.cjs.map +0 -1
- package/dist/imgixLoader.cjs.map +0 -1
- package/dist/index.cjs +0 -47
- package/dist/index.d.cts +0 -15
- package/dist/lib/devMsg.cjs.map +0 -1
- package/dist/lib/resolveDefaultExport.cjs.map +0 -1
- package/dist/package.cjs +0 -12
- package/dist/package.cjs.map +0 -1
- package/dist/pages/PrismicPreview.cjs.map +0 -1
- package/dist/pages/SliceSimulator.cjs +0 -41
- package/dist/pages/SliceSimulator.cjs.map +0 -1
- package/dist/pages/enableAutoPreviews.cjs.map +0 -1
- package/dist/pages/exitPreview.cjs.map +0 -1
- package/dist/pages/redirectToPreviewURL.cjs.map +0 -1
- package/dist/pages/setPreviewData.cjs +0 -13
- package/dist/pages/setPreviewData.cjs.map +0 -1
- package/dist/pages.cjs +0 -47
- package/dist/pages.d.cts +0 -15
- package/dist/redirectToPreviewURL.cjs.map +0 -1
- package/src/PrismicImage.tsx +0 -187
- package/src/PrismicLink.tsx +0 -74
- package/src/PrismicRichText.tsx +0 -63
- package/src/PrismicTable.tsx +0 -33
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
ForwardRefExoticComponent,
|
|
5
|
+
PropsWithoutRef,
|
|
6
|
+
RefAttributes} from "react";
|
|
7
|
+
import {
|
|
8
|
+
forwardRef
|
|
9
|
+
} from "react";
|
|
10
|
+
import type { ImageProps } from "next/image";
|
|
11
|
+
import Image from "next/image";
|
|
12
|
+
import type { ImgixURLParams } from "imgix-url-builder";
|
|
13
|
+
import { buildURL } from "imgix-url-builder";
|
|
14
|
+
import type { ImageFieldImage} from "@prismicio/client";
|
|
15
|
+
import { isFilled } from "@prismicio/client";
|
|
16
|
+
|
|
17
|
+
import { devMsg } from "./lib/devMsg";
|
|
18
|
+
import { resolveDefaultExport } from "./lib/resolveDefaultExport";
|
|
19
|
+
|
|
20
|
+
import { imgixLoader } from "./imgixLoader";
|
|
21
|
+
|
|
22
|
+
const castInt = (input: string | number | undefined): number | undefined => {
|
|
23
|
+
if (typeof input === "number" || typeof input === "undefined") {
|
|
24
|
+
return input;
|
|
25
|
+
} else {
|
|
26
|
+
const parsed = Number.parseInt(input);
|
|
27
|
+
|
|
28
|
+
if (Number.isNaN(parsed)) {
|
|
29
|
+
return undefined;
|
|
30
|
+
} else {
|
|
31
|
+
return parsed;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type PrismicNextImageProps = Omit<
|
|
37
|
+
ImageProps,
|
|
38
|
+
"src" | "alt" | "loader"
|
|
39
|
+
> & {
|
|
40
|
+
/** The Prismic Image field or thumbnail to render. */
|
|
41
|
+
field: ImageFieldImage | null | undefined;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* An object of Imgix URL API parameters to transform the image.
|
|
45
|
+
*
|
|
46
|
+
* @see https://docs.imgix.com/apis/rendering
|
|
47
|
+
*/
|
|
48
|
+
imgixParams?: { [P in keyof ImgixURLParams]: ImgixURLParams[P] | null };
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Declare an image as decorative by providing `alt=""`.
|
|
52
|
+
*
|
|
53
|
+
* See:
|
|
54
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
55
|
+
*/
|
|
56
|
+
alt?: "";
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Declare an image as decorative only if the Image field does not have
|
|
60
|
+
* alternative text by providing `fallbackAlt=""`.
|
|
61
|
+
*
|
|
62
|
+
* See:
|
|
63
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
64
|
+
*/
|
|
65
|
+
fallbackAlt?: "";
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Rendered when the field is empty. If a fallback is not given, `null` will
|
|
69
|
+
* be rendered.
|
|
70
|
+
*/
|
|
71
|
+
fallback?: React.ReactNode;
|
|
72
|
+
|
|
73
|
+
loader?: ImageProps["loader"] | null;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* React component that renders an image from a Prismic Image field or one of
|
|
78
|
+
* its thumbnails using `next/image`. It will automatically set the `alt`
|
|
79
|
+
* attribute using the Image field's `alt` property.
|
|
80
|
+
*
|
|
81
|
+
* It uses an Imgix URL-based loader by default. A custom loader can be provided
|
|
82
|
+
* with the `loader` prop. If you would like to use the Next.js Image
|
|
83
|
+
* Optimization API instead, set `loader={undefined}`.
|
|
84
|
+
*
|
|
85
|
+
* @param props - Props for the component.
|
|
86
|
+
*
|
|
87
|
+
* @returns A responsive image component using `next/image` for the given Image
|
|
88
|
+
* field.
|
|
89
|
+
*
|
|
90
|
+
* @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image
|
|
91
|
+
*/
|
|
92
|
+
// The type annotation is necessary to avoid a type reference issue.
|
|
93
|
+
export const PrismicNextImage: ForwardRefExoticComponent<
|
|
94
|
+
PropsWithoutRef<PrismicNextImageProps> & RefAttributes<HTMLImageElement>
|
|
95
|
+
> = forwardRef<HTMLImageElement, PrismicNextImageProps>(
|
|
96
|
+
function PrismicNextImage(
|
|
97
|
+
{
|
|
98
|
+
field,
|
|
99
|
+
imgixParams = {},
|
|
100
|
+
alt,
|
|
101
|
+
fallbackAlt,
|
|
102
|
+
fill,
|
|
103
|
+
width,
|
|
104
|
+
height,
|
|
105
|
+
fallback = null,
|
|
106
|
+
loader = imgixLoader,
|
|
107
|
+
...restProps
|
|
108
|
+
},
|
|
109
|
+
ref,
|
|
110
|
+
) {
|
|
111
|
+
if (process.env.NODE_ENV === "development") {
|
|
112
|
+
if (typeof alt === "string" && alt !== "") {
|
|
113
|
+
console.warn(
|
|
114
|
+
`[PrismicNextImage] The "alt" prop can only be used to declare an image as decorative by passing an empty string (alt="") but was provided a non-empty string. You can resolve this warning by removing the "alt" prop or changing it to alt="". For more details, see ${devMsg(
|
|
115
|
+
"alt-must-be-an-empty-string",
|
|
116
|
+
)}`,
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (typeof fallbackAlt === "string" && fallbackAlt !== "") {
|
|
121
|
+
console.warn(
|
|
122
|
+
`[PrismicNextImage] The "fallbackAlt" prop can only be used to declare an image as decorative by passing an empty string (fallbackAlt="") but was provided a non-empty string. You can resolve this warning by removing the "fallbackAlt" prop or changing it to fallbackAlt="". For more details, see ${devMsg(
|
|
123
|
+
"alt-must-be-an-empty-string",
|
|
124
|
+
)}`,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (!isFilled.imageThumbnail(field)) {
|
|
130
|
+
return <>{fallback}</>;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const resolvedImgixParams = imgixParams;
|
|
134
|
+
for (const x in imgixParams) {
|
|
135
|
+
if (resolvedImgixParams[x as keyof typeof resolvedImgixParams] === null) {
|
|
136
|
+
resolvedImgixParams[x as keyof typeof resolvedImgixParams] = undefined;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const src = buildURL(field.url, imgixParams as ImgixURLParams);
|
|
141
|
+
|
|
142
|
+
const ar = field.dimensions.width / field.dimensions.height;
|
|
143
|
+
|
|
144
|
+
const castedWidth = castInt(width);
|
|
145
|
+
const castedHeight = castInt(height);
|
|
146
|
+
|
|
147
|
+
let resolvedWidth = castedWidth ?? field.dimensions.width;
|
|
148
|
+
let resolvedHeight = castedHeight ?? field.dimensions.height;
|
|
149
|
+
|
|
150
|
+
if (castedWidth != null && castedHeight == null) {
|
|
151
|
+
resolvedHeight = castedWidth / ar;
|
|
152
|
+
} else if (castedWidth == null && castedHeight != null) {
|
|
153
|
+
resolvedWidth = castedHeight * ar;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// A non-null assertion is required since we can't statically
|
|
157
|
+
// know if an alt attribute is available.
|
|
158
|
+
const resolvedAlt = (alt ?? (field.alt || fallbackAlt))!;
|
|
159
|
+
|
|
160
|
+
if (
|
|
161
|
+
process.env.NODE_ENV === "development" &&
|
|
162
|
+
typeof resolvedAlt !== "string"
|
|
163
|
+
) {
|
|
164
|
+
console.error(
|
|
165
|
+
`[PrismicNextImage] The following image is missing an "alt" property. Please add Alternative Text to the image in Prismic. To mark the image as decorative instead, add one of \`alt=""\` or \`fallbackAlt=""\`.`,
|
|
166
|
+
src,
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const ResolvedImage = resolveDefaultExport(Image);
|
|
171
|
+
|
|
172
|
+
return (
|
|
173
|
+
<ResolvedImage
|
|
174
|
+
ref={ref}
|
|
175
|
+
src={src}
|
|
176
|
+
width={fill ? undefined : resolvedWidth}
|
|
177
|
+
height={fill ? undefined : resolvedHeight}
|
|
178
|
+
alt={resolvedAlt}
|
|
179
|
+
fill={fill}
|
|
180
|
+
loader={loader === null ? undefined : loader}
|
|
181
|
+
{...restProps}
|
|
182
|
+
/>
|
|
183
|
+
);
|
|
184
|
+
},
|
|
185
|
+
);
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { ComponentProps} from "react";
|
|
2
|
+
import { forwardRef } from "react";
|
|
3
|
+
import Link from "next/link";
|
|
4
|
+
import type {
|
|
5
|
+
AsLinkAttrsConfig,
|
|
6
|
+
LinkField,
|
|
7
|
+
LinkResolverFunction,
|
|
8
|
+
PrismicDocument} from "@prismicio/client";
|
|
9
|
+
import {
|
|
10
|
+
asLinkAttrs,
|
|
11
|
+
} from "@prismicio/client";
|
|
12
|
+
|
|
13
|
+
import { resolveDefaultExport } from "./lib/resolveDefaultExport";
|
|
14
|
+
|
|
15
|
+
export type PrismicNextLinkProps = Omit<
|
|
16
|
+
ComponentProps<typeof Link>,
|
|
17
|
+
"field" | "document" | "href" | "rel"
|
|
18
|
+
> & {
|
|
19
|
+
linkResolver?: LinkResolverFunction;
|
|
20
|
+
rel?: string | AsLinkAttrsConfig["rel"];
|
|
21
|
+
} & (
|
|
22
|
+
| {
|
|
23
|
+
field: LinkField | null | undefined;
|
|
24
|
+
document?: never;
|
|
25
|
+
href?: never;
|
|
26
|
+
}
|
|
27
|
+
| {
|
|
28
|
+
field?: never;
|
|
29
|
+
document: PrismicDocument | null | undefined;
|
|
30
|
+
href?: never;
|
|
31
|
+
}
|
|
32
|
+
| {
|
|
33
|
+
field?: never;
|
|
34
|
+
document?: never;
|
|
35
|
+
href: ComponentProps<typeof Link>["href"];
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
export const PrismicNextLink = forwardRef<
|
|
40
|
+
HTMLAnchorElement,
|
|
41
|
+
PrismicNextLinkProps
|
|
42
|
+
>(function PrismicNextLink(props, ref) {
|
|
43
|
+
const { field, document, linkResolver, children, ...restProps } = props;
|
|
44
|
+
const {
|
|
45
|
+
href: computedHref,
|
|
46
|
+
rel: computedRel,
|
|
47
|
+
...attrs
|
|
48
|
+
} = asLinkAttrs(field ?? document, {
|
|
49
|
+
linkResolver,
|
|
50
|
+
rel: typeof restProps.rel === "function" ? restProps.rel : undefined,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const href = ("href" in restProps ? restProps.href : computedHref) || "";
|
|
54
|
+
|
|
55
|
+
let rel = computedRel;
|
|
56
|
+
if ("rel" in restProps && typeof restProps.rel !== "function") {
|
|
57
|
+
rel = restProps.rel;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const ResolvedLink = resolveDefaultExport(Link);
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<ResolvedLink ref={ref} {...attrs} {...restProps} href={href} rel={rel}>
|
|
64
|
+
{"children" in props ? children : field?.text}
|
|
65
|
+
</ResolvedLink>
|
|
66
|
+
);
|
|
67
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -3,17 +3,8 @@ export { exitPreview } from "./exitPreview";
|
|
|
3
3
|
export { PrismicPreview } from "./PrismicPreview";
|
|
4
4
|
export type { PrismicPreviewProps } from "./PrismicPreview";
|
|
5
5
|
|
|
6
|
-
export {
|
|
7
|
-
export type {
|
|
8
|
-
|
|
9
|
-
export { PrismicLink, PrismicNextLink } from "./PrismicLink";
|
|
10
|
-
export type { PrismicLinkProps, PrismicNextLinkProps } from "./PrismicLink";
|
|
11
|
-
|
|
12
|
-
export { PrismicRichText } from "./PrismicRichText";
|
|
13
|
-
export type { PrismicRichTextProps } from "./PrismicRichText";
|
|
14
|
-
|
|
15
|
-
export { PrismicTable } from "./PrismicTable";
|
|
16
|
-
export type { PrismicTableProps } from "@prismicio/react";
|
|
6
|
+
export { PrismicNextLink } from "./PrismicNextLink";
|
|
7
|
+
export type { PrismicNextLinkProps } from "./PrismicNextLink";
|
|
17
8
|
|
|
18
9
|
export { enableAutoPreviews } from "./enableAutoPreviews";
|
|
19
10
|
export type { EnableAutoPreviewsConfig } from "./enableAutoPreviews";
|
|
@@ -21,6 +12,9 @@ export type { EnableAutoPreviewsConfig } from "./enableAutoPreviews";
|
|
|
21
12
|
export { redirectToPreviewURL } from "./redirectToPreviewURL";
|
|
22
13
|
export type { RedirectToPreviewURLConfig } from "./redirectToPreviewURL";
|
|
23
14
|
|
|
15
|
+
export { PrismicNextImage } from "./PrismicNextImage";
|
|
16
|
+
export type { PrismicNextImageProps } from "./PrismicNextImage";
|
|
17
|
+
|
|
24
18
|
export { SliceSimulator } from "./SliceSimulator";
|
|
25
19
|
export type {
|
|
26
20
|
SliceSimulatorProps,
|
|
@@ -35,13 +29,3 @@ export type { CreateClientConfig } from "./types";
|
|
|
35
29
|
|
|
36
30
|
export { createLocaleRedirect } from "./createLocaleRedirect";
|
|
37
31
|
export type { CreateLocaleRedirectConfig } from "./createLocaleRedirect";
|
|
38
|
-
|
|
39
|
-
// Re-exports from @prismicio/react
|
|
40
|
-
export { PrismicText, SliceZone, TODOSliceComponent } from "@prismicio/react";
|
|
41
|
-
export type {
|
|
42
|
-
SliceComponentProps,
|
|
43
|
-
SliceComponentType,
|
|
44
|
-
SliceZoneProps,
|
|
45
|
-
RichTextComponents,
|
|
46
|
-
PrismicTextProps,
|
|
47
|
-
} from "@prismicio/react";
|
package/src/pages/index.ts
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export
|
|
1
|
+
export { PrismicNextLink } from "../PrismicNextLink";
|
|
2
|
+
export { type PrismicNextLinkProps } from "../PrismicNextLink";
|
|
3
3
|
|
|
4
|
-
export {
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
export { PrismicRichText } from "../PrismicRichText";
|
|
8
|
-
export type { PrismicRichTextProps } from "../PrismicRichText";
|
|
9
|
-
|
|
10
|
-
export { PrismicTable } from "../PrismicTable";
|
|
11
|
-
export type { PrismicTableProps } from "@prismicio/react";
|
|
4
|
+
export { PrismicNextImage } from "../PrismicNextImage";
|
|
5
|
+
export { type PrismicNextImageProps } from "../PrismicNextImage";
|
|
12
6
|
|
|
13
7
|
export { SliceSimulator } from "./SliceSimulator";
|
|
14
8
|
export type {
|
|
@@ -37,13 +31,3 @@ export type { CreateClientConfig } from "./types";
|
|
|
37
31
|
|
|
38
32
|
export { createLocaleRedirect } from "../createLocaleRedirect";
|
|
39
33
|
export type { CreateLocaleRedirectConfig } from "../createLocaleRedirect";
|
|
40
|
-
|
|
41
|
-
// Re-exports from @prismicio/react
|
|
42
|
-
export { PrismicText, SliceZone, TODOSliceComponent } from "@prismicio/react";
|
|
43
|
-
export type {
|
|
44
|
-
SliceComponentProps,
|
|
45
|
-
SliceComponentType,
|
|
46
|
-
SliceZoneProps,
|
|
47
|
-
RichTextComponents,
|
|
48
|
-
PrismicTextProps,
|
|
49
|
-
} from "@prismicio/react";
|
package/dist/PrismicImage.cjs
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
4
|
-
const require_resolveDefaultExport = require('./lib/resolveDefaultExport.cjs');
|
|
5
|
-
const require_imgixLoader = require('./imgixLoader.cjs');
|
|
6
|
-
const require_devMsg = require('./lib/devMsg.cjs');
|
|
7
|
-
let _prismicio_client = require("@prismicio/client");
|
|
8
|
-
let react = require("react");
|
|
9
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
10
|
-
let imgix_url_builder = require("imgix-url-builder");
|
|
11
|
-
let next_image = require("next/image");
|
|
12
|
-
next_image = require_rolldown_runtime.__toESM(next_image);
|
|
13
|
-
|
|
14
|
-
//#region src/PrismicImage.tsx
|
|
15
|
-
const castInt = (input) => {
|
|
16
|
-
if (typeof input === "number" || typeof input === "undefined") return input;
|
|
17
|
-
else {
|
|
18
|
-
const parsed = Number.parseInt(input);
|
|
19
|
-
if (Number.isNaN(parsed)) return;
|
|
20
|
-
else return parsed;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* React component that renders an image from a Prismic Image field or one of
|
|
25
|
-
* its thumbnails using `next/image`. It will automatically set the `alt`
|
|
26
|
-
* attribute using the Image field's `alt` property.
|
|
27
|
-
*
|
|
28
|
-
* It uses an Imgix URL-based loader by default. A custom loader can be provided
|
|
29
|
-
* with the `loader` prop. If you would like to use the Next.js Image
|
|
30
|
-
* Optimization API instead, set `loader={undefined}`.
|
|
31
|
-
*
|
|
32
|
-
* @param props - Props for the component.
|
|
33
|
-
*
|
|
34
|
-
* @returns A responsive image component using `next/image` for the given Image
|
|
35
|
-
* field.
|
|
36
|
-
*
|
|
37
|
-
* @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image
|
|
38
|
-
*/
|
|
39
|
-
const PrismicImage = (0, react.forwardRef)(function PrismicImage$1({ field, imgixParams = {}, alt, fallbackAlt, fill, width, height, fallback = null, loader = require_imgixLoader.imgixLoader, ...restProps }, ref) {
|
|
40
|
-
if (process.env.NODE_ENV === "development") {
|
|
41
|
-
if (typeof alt === "string" && alt !== "") console.warn(`[PrismicImage] The "alt" prop can only be used to declare an image as decorative by passing an empty string (alt="") but was provided a non-empty string. You can resolve this warning by removing the "alt" prop or changing it to alt="". For more details, see ${require_devMsg.devMsg("alt-must-be-an-empty-string")}`);
|
|
42
|
-
if (typeof fallbackAlt === "string" && fallbackAlt !== "") console.warn(`[PrismicImage] The "fallbackAlt" prop can only be used to declare an image as decorative by passing an empty string (fallbackAlt="") but was provided a non-empty string. You can resolve this warning by removing the "fallbackAlt" prop or changing it to fallbackAlt="". For more details, see ${require_devMsg.devMsg("alt-must-be-an-empty-string")}`);
|
|
43
|
-
}
|
|
44
|
-
if (!_prismicio_client.isFilled.imageThumbnail(field)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: fallback });
|
|
45
|
-
const resolvedImgixParams = imgixParams;
|
|
46
|
-
for (const x in imgixParams) if (resolvedImgixParams[x] === null) resolvedImgixParams[x] = void 0;
|
|
47
|
-
const src = (0, imgix_url_builder.buildURL)(field.url, imgixParams);
|
|
48
|
-
const ar = field.dimensions.width / field.dimensions.height;
|
|
49
|
-
const castedWidth = castInt(width);
|
|
50
|
-
const castedHeight = castInt(height);
|
|
51
|
-
let resolvedWidth = castedWidth ?? field.dimensions.width;
|
|
52
|
-
let resolvedHeight = castedHeight ?? field.dimensions.height;
|
|
53
|
-
if (castedWidth != null && castedHeight == null) resolvedHeight = castedWidth / ar;
|
|
54
|
-
else if (castedWidth == null && castedHeight != null) resolvedWidth = castedHeight * ar;
|
|
55
|
-
const resolvedAlt = alt ?? (field.alt || fallbackAlt);
|
|
56
|
-
if (process.env.NODE_ENV === "development" && typeof resolvedAlt !== "string") console.error(`[PrismicImage] The following image is missing an "alt" property. Please add Alternative Text to the image in Prismic. To mark the image as decorative instead, add one of \`alt=""\` or \`fallbackAlt=""\`.`, src);
|
|
57
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_resolveDefaultExport.resolveDefaultExport(next_image.default), {
|
|
58
|
-
ref,
|
|
59
|
-
src,
|
|
60
|
-
width: fill ? void 0 : resolvedWidth,
|
|
61
|
-
height: fill ? void 0 : resolvedHeight,
|
|
62
|
-
alt: resolvedAlt,
|
|
63
|
-
fill,
|
|
64
|
-
loader: loader === null ? void 0 : loader,
|
|
65
|
-
...restProps
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
//#endregion
|
|
70
|
-
exports.PrismicImage = PrismicImage;
|
|
71
|
-
//# sourceMappingURL=PrismicImage.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicImage.cjs","names":["PrismicImage","imgixLoader","devMsg","isFilled","resolveDefaultExport","Image"],"sources":["../src/PrismicImage.tsx"],"sourcesContent":["\"use client\";\n\nimport { imgixLoader } from \"./imgixLoader\";\nimport { devMsg } from \"./lib/devMsg\";\nimport { resolveDefaultExport } from \"./lib/resolveDefaultExport\";\nimport type { ImageFieldImage } from \"@prismicio/client\";\nimport { isFilled } from \"@prismicio/client\";\nimport type { ImgixURLParams } from \"imgix-url-builder\";\nimport { buildURL } from \"imgix-url-builder\";\nimport type { ImageProps } from \"next/image\";\nimport Image from \"next/image\";\nimport type {\n\tForwardRefExoticComponent,\n\tPropsWithoutRef,\n\tRefAttributes,\n} from \"react\";\nimport { forwardRef } from \"react\";\n\n/**\n * @deprecated Use `PrismicImage` instead.\n */\nexport { PrismicImage as PrismicNextImage };\n\n/**\n * @deprecated Use `PrismicImageProps` instead.\n */\nexport type { PrismicImageProps as PrismicNextImageProps };\n\nconst castInt = (input: string | number | undefined): number | undefined => {\n\tif (typeof input === \"number\" || typeof input === \"undefined\") {\n\t\treturn input;\n\t} else {\n\t\tconst parsed = Number.parseInt(input);\n\n\t\tif (Number.isNaN(parsed)) {\n\t\t\treturn undefined;\n\t\t} else {\n\t\t\treturn parsed;\n\t\t}\n\t}\n};\n\nexport type PrismicImageProps = Omit<ImageProps, \"src\" | \"alt\" | \"loader\"> & {\n\t/** The Prismic Image field or thumbnail to render. */\n\tfield: ImageFieldImage | null | undefined;\n\n\t/**\n\t * An object of Imgix URL API parameters to transform the image.\n\t *\n\t * @see https://docs.imgix.com/apis/rendering\n\t */\n\timgixParams?: { [P in keyof ImgixURLParams]: ImgixURLParams[P] | null };\n\n\t/**\n\t * Declare an image as decorative by providing `alt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\talt?: \"\";\n\n\t/**\n\t * Declare an image as decorative only if the Image field does not have\n\t * alternative text by providing `fallbackAlt=\"\"`.\n\t *\n\t * See:\n\t * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images\n\t */\n\tfallbackAlt?: \"\";\n\n\t/**\n\t * Rendered when the field is empty. If a fallback is not given, `null` will\n\t * be rendered.\n\t */\n\tfallback?: React.ReactNode;\n\n\tloader?: ImageProps[\"loader\"] | null;\n};\n\n/**\n * React component that renders an image from a Prismic Image field or one of\n * its thumbnails using `next/image`. It will automatically set the `alt`\n * attribute using the Image field's `alt` property.\n *\n * It uses an Imgix URL-based loader by default. A custom loader can be provided\n * with the `loader` prop. If you would like to use the Next.js Image\n * Optimization API instead, set `loader={undefined}`.\n *\n * @param props - Props for the component.\n *\n * @returns A responsive image component using `next/image` for the given Image\n * field.\n *\n * @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image\n */\n// The type annotation is necessary to avoid a type reference issue.\nexport const PrismicImage: ForwardRefExoticComponent<\n\tPropsWithoutRef<PrismicImageProps> & RefAttributes<HTMLImageElement>\n> = forwardRef<HTMLImageElement, PrismicImageProps>(function PrismicImage(\n\t{\n\t\tfield,\n\t\timgixParams = {},\n\t\talt,\n\t\tfallbackAlt,\n\t\tfill,\n\t\twidth,\n\t\theight,\n\t\tfallback = null,\n\t\tloader = imgixLoader,\n\t\t...restProps\n\t},\n\tref,\n) {\n\tif (process.env.NODE_ENV === \"development\") {\n\t\tif (typeof alt === \"string\" && alt !== \"\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicImage] The \"alt\" prop can only be used to declare an image as decorative by passing an empty string (alt=\"\") but was provided a non-empty string. You can resolve this warning by removing the \"alt\" prop or changing it to alt=\"\". For more details, see ${devMsg(\n\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\n\t\tif (typeof fallbackAlt === \"string\" && fallbackAlt !== \"\") {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicImage] The \"fallbackAlt\" prop can only be used to declare an image as decorative by passing an empty string (fallbackAlt=\"\") but was provided a non-empty string. You can resolve this warning by removing the \"fallbackAlt\" prop or changing it to fallbackAlt=\"\". For more details, see ${devMsg(\n\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t)}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tif (!isFilled.imageThumbnail(field)) {\n\t\treturn <>{fallback}</>;\n\t}\n\n\tconst resolvedImgixParams = imgixParams;\n\tfor (const x in imgixParams) {\n\t\tif (resolvedImgixParams[x as keyof typeof resolvedImgixParams] === null) {\n\t\t\tresolvedImgixParams[x as keyof typeof resolvedImgixParams] = undefined;\n\t\t}\n\t}\n\n\tconst src = buildURL(field.url, imgixParams as ImgixURLParams);\n\n\tconst ar = field.dimensions.width / field.dimensions.height;\n\n\tconst castedWidth = castInt(width);\n\tconst castedHeight = castInt(height);\n\n\tlet resolvedWidth = castedWidth ?? field.dimensions.width;\n\tlet resolvedHeight = castedHeight ?? field.dimensions.height;\n\n\tif (castedWidth != null && castedHeight == null) {\n\t\tresolvedHeight = castedWidth / ar;\n\t} else if (castedWidth == null && castedHeight != null) {\n\t\tresolvedWidth = castedHeight * ar;\n\t}\n\n\t// A non-null assertion is required since we can't statically\n\t// know if an alt attribute is available.\n\tconst resolvedAlt = (alt ?? (field.alt || fallbackAlt))!;\n\n\tif (\n\t\tprocess.env.NODE_ENV === \"development\" &&\n\t\ttypeof resolvedAlt !== \"string\"\n\t) {\n\t\tconsole.error(\n\t\t\t`[PrismicImage] The following image is missing an \"alt\" property. Please add Alternative Text to the image in Prismic. To mark the image as decorative instead, add one of \\`alt=\"\"\\` or \\`fallbackAlt=\"\"\\`.`,\n\t\t\tsrc,\n\t\t);\n\t}\n\n\tconst ResolvedImage = resolveDefaultExport(Image);\n\n\treturn (\n\t\t<ResolvedImage\n\t\t\tref={ref}\n\t\t\tsrc={src}\n\t\t\twidth={fill ? undefined : resolvedWidth}\n\t\t\theight={fill ? undefined : resolvedHeight}\n\t\t\talt={resolvedAlt}\n\t\t\tfill={fill}\n\t\t\tloader={loader === null ? undefined : loader}\n\t\t\t{...restProps}\n\t\t/>\n\t);\n});\n"],"mappings":";;;;;;;;;;;;;;AA4BA,MAAM,WAAW,UAA2D;AAC3E,KAAI,OAAO,UAAU,YAAY,OAAO,UAAU,YACjD,QAAO;MACD;EACN,MAAM,SAAS,OAAO,SAAS,MAAM;AAErC,MAAI,OAAO,MAAM,OAAO,CACvB;MAEA,QAAO;;;;;;;;;;;;;;;;;;;AA2DV,MAAa,qCAEuC,SAASA,eAC5D,EACC,OACA,cAAc,EAAE,EAChB,KACA,aACA,MACA,OACA,QACA,WAAW,MACX,SAASC,iCACT,GAAG,aAEJ,KACC;AACD,KAAI,QAAQ,IAAI,aAAa,eAAe;AAC3C,MAAI,OAAO,QAAQ,YAAY,QAAQ,GACtC,SAAQ,KACP,qQAAqQC,sBACpQ,8BACA,GACD;AAGF,MAAI,OAAO,gBAAgB,YAAY,gBAAgB,GACtD,SAAQ,KACP,qSAAqSA,sBACpS,8BACA,GACD;;AAIH,KAAI,CAACC,2BAAS,eAAe,MAAM,CAClC,QAAO,mFAAG,WAAY;CAGvB,MAAM,sBAAsB;AAC5B,MAAK,MAAM,KAAK,YACf,KAAI,oBAAoB,OAA2C,KAClE,qBAAoB,KAAyC;CAI/D,MAAM,sCAAe,MAAM,KAAK,YAA8B;CAE9D,MAAM,KAAK,MAAM,WAAW,QAAQ,MAAM,WAAW;CAErD,MAAM,cAAc,QAAQ,MAAM;CAClC,MAAM,eAAe,QAAQ,OAAO;CAEpC,IAAI,gBAAgB,eAAe,MAAM,WAAW;CACpD,IAAI,iBAAiB,gBAAgB,MAAM,WAAW;AAEtD,KAAI,eAAe,QAAQ,gBAAgB,KAC1C,kBAAiB,cAAc;UACrB,eAAe,QAAQ,gBAAgB,KACjD,iBAAgB,eAAe;CAKhC,MAAM,cAAe,QAAQ,MAAM,OAAO;AAE1C,KACC,QAAQ,IAAI,aAAa,iBACzB,OAAO,gBAAgB,SAEvB,SAAQ,MACP,+MACA,IACA;AAKF,QACC,2CAHqBC,kDAAqBC,mBAAM;EAI1C;EACA;EACL,OAAO,OAAO,SAAY;EAC1B,QAAQ,OAAO,SAAY;EAC3B,KAAK;EACC;EACN,QAAQ,WAAW,OAAO,SAAY;EACtC,GAAI;GACH;EAEF"}
|
package/dist/PrismicLink.cjs
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
-
const require_resolveDefaultExport = require('./lib/resolveDefaultExport.cjs');
|
|
3
|
-
let _prismicio_client = require("@prismicio/client");
|
|
4
|
-
let react = require("react");
|
|
5
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
6
|
-
let next_link = require("next/link");
|
|
7
|
-
next_link = require_rolldown_runtime.__toESM(next_link);
|
|
8
|
-
|
|
9
|
-
//#region src/PrismicLink.tsx
|
|
10
|
-
const PrismicLink = (0, react.forwardRef)(function PrismicLink$1(props, ref) {
|
|
11
|
-
const { field, document, linkResolver, children, ...restProps } = props;
|
|
12
|
-
const { href: computedHref, rel: computedRel, ...attrs } = (0, _prismicio_client.asLinkAttrs)(field ?? document, {
|
|
13
|
-
linkResolver,
|
|
14
|
-
rel: typeof restProps.rel === "function" ? restProps.rel : void 0
|
|
15
|
-
});
|
|
16
|
-
const href = ("href" in restProps ? restProps.href : computedHref) || "";
|
|
17
|
-
let rel = computedRel;
|
|
18
|
-
if ("rel" in restProps && typeof restProps.rel !== "function") rel = restProps.rel;
|
|
19
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_resolveDefaultExport.resolveDefaultExport(next_link.default), {
|
|
20
|
-
ref,
|
|
21
|
-
...attrs,
|
|
22
|
-
...restProps,
|
|
23
|
-
href,
|
|
24
|
-
rel,
|
|
25
|
-
children: "children" in props ? children : field?.text
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
//#endregion
|
|
30
|
-
exports.PrismicLink = PrismicLink;
|
|
31
|
-
//# sourceMappingURL=PrismicLink.cjs.map
|
package/dist/PrismicLink.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicLink.cjs","names":["PrismicLink","resolveDefaultExport","Link"],"sources":["../src/PrismicLink.tsx"],"sourcesContent":["import { resolveDefaultExport } from \"./lib/resolveDefaultExport\";\nimport type {\n\tAsLinkAttrsConfig,\n\tLinkField,\n\tLinkResolverFunction,\n\tPrismicDocument,\n} from \"@prismicio/client\";\nimport { asLinkAttrs } from \"@prismicio/client\";\nimport Link from \"next/link\";\nimport type { ComponentProps } from \"react\";\nimport { forwardRef } from \"react\";\n\n/**\n * @deprecated Use `PrismicLink` instead.\n */\nexport { PrismicLink as PrismicNextLink } from \"./PrismicLink\";\n\n/**\n * @deprecated Use `PrismicLinkProps` instead.\n */\nexport type { PrismicLinkProps as PrismicNextLinkProps } from \"./PrismicLink\";\n\nexport type PrismicLinkProps = Omit<\n\tComponentProps<typeof Link>,\n\t\"field\" | \"document\" | \"href\" | \"rel\"\n> & {\n\tlinkResolver?: LinkResolverFunction;\n\trel?: string | AsLinkAttrsConfig[\"rel\"];\n} & (\n\t\t| {\n\t\t\t\tfield: LinkField | null | undefined;\n\t\t\t\tdocument?: never;\n\t\t\t\thref?: never;\n\t\t }\n\t\t| {\n\t\t\t\tfield?: never;\n\t\t\t\tdocument: PrismicDocument | null | undefined;\n\t\t\t\thref?: never;\n\t\t }\n\t\t| {\n\t\t\t\tfield?: never;\n\t\t\t\tdocument?: never;\n\t\t\t\thref: ComponentProps<typeof Link>[\"href\"];\n\t\t }\n\t);\n\nexport const PrismicLink = forwardRef<HTMLAnchorElement, PrismicLinkProps>(\n\tfunction PrismicLink(props, ref) {\n\t\tconst { field, document, linkResolver, children, ...restProps } = props;\n\t\tconst {\n\t\t\thref: computedHref,\n\t\t\trel: computedRel,\n\t\t\t...attrs\n\t\t} = asLinkAttrs(field ?? document, {\n\t\t\tlinkResolver,\n\t\t\trel: typeof restProps.rel === \"function\" ? restProps.rel : undefined,\n\t\t});\n\n\t\tconst href = (\"href\" in restProps ? restProps.href : computedHref) || \"\";\n\n\t\tlet rel = computedRel;\n\t\tif (\"rel\" in restProps && typeof restProps.rel !== \"function\") {\n\t\t\trel = restProps.rel;\n\t\t}\n\n\t\tconst ResolvedLink = resolveDefaultExport(Link);\n\n\t\treturn (\n\t\t\t<ResolvedLink ref={ref} {...attrs} {...restProps} href={href} rel={rel}>\n\t\t\t\t{\"children\" in props ? children : field?.text}\n\t\t\t</ResolvedLink>\n\t\t);\n\t},\n);\n"],"mappings":";;;;;;;;;AA8CA,MAAa,oCACZ,SAASA,cAAY,OAAO,KAAK;CAChC,MAAM,EAAE,OAAO,UAAU,cAAc,UAAU,GAAG,cAAc;CAClE,MAAM,EACL,MAAM,cACN,KAAK,aACL,GAAG,6CACY,SAAS,UAAU;EAClC;EACA,KAAK,OAAO,UAAU,QAAQ,aAAa,UAAU,MAAM;EAC3D,CAAC;CAEF,MAAM,QAAQ,UAAU,YAAY,UAAU,OAAO,iBAAiB;CAEtE,IAAI,MAAM;AACV,KAAI,SAAS,aAAa,OAAO,UAAU,QAAQ,WAClD,OAAM,UAAU;AAKjB,QACC,2CAHoBC,kDAAqBC,kBAAK;EAG3B;EAAK,GAAI;EAAO,GAAI;EAAiB;EAAW;YACjE,cAAc,QAAQ,WAAW,OAAO;GAC3B;EAGjB"}
|
package/dist/PrismicPreview.cjs
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
-
const require_resolveDefaultExport = require('./lib/resolveDefaultExport.cjs');
|
|
3
|
-
const require_PrismicPreviewClient = require('./PrismicPreviewClient.cjs');
|
|
4
|
-
let next_script = require("next/script");
|
|
5
|
-
next_script = require_rolldown_runtime.__toESM(next_script);
|
|
6
|
-
let _prismicio_client = require("@prismicio/client");
|
|
7
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
8
|
-
|
|
9
|
-
//#region src/PrismicPreview.tsx
|
|
10
|
-
/**
|
|
11
|
-
* React component that sets up Prismic Previews using the Prismic Toolbar. When
|
|
12
|
-
* the Prismic Toolbar send events to the browser, such as on preview updates
|
|
13
|
-
* and exiting, this component will automatically refresh the page with the
|
|
14
|
-
* changes.
|
|
15
|
-
*
|
|
16
|
-
* This component can be wrapped around your app or added anywhere in your app's
|
|
17
|
-
* tree. It must be rendered on every page.
|
|
18
|
-
*/
|
|
19
|
-
const PrismicPreview = async (props) => {
|
|
20
|
-
const { repositoryName, children, ...otherProps } = props;
|
|
21
|
-
const { draftMode } = await import("next/headers");
|
|
22
|
-
const toolbarSrc = (0, _prismicio_client.getToolbarSrc)(repositoryName);
|
|
23
|
-
const isDraftMode = (await draftMode()).isEnabled;
|
|
24
|
-
const ResolvedScript = require_resolveDefaultExport.resolveDefaultExport(next_script.default);
|
|
25
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
26
|
-
children,
|
|
27
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PrismicPreviewClient.PrismicPreviewClient, {
|
|
28
|
-
repositoryName,
|
|
29
|
-
isDraftMode,
|
|
30
|
-
...otherProps
|
|
31
|
-
}),
|
|
32
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ResolvedScript, {
|
|
33
|
-
src: toolbarSrc,
|
|
34
|
-
strategy: "lazyOnload"
|
|
35
|
-
})
|
|
36
|
-
] });
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
//#endregion
|
|
40
|
-
exports.PrismicPreview = PrismicPreview;
|
|
41
|
-
//# sourceMappingURL=PrismicPreview.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicPreview.cjs","names":["resolveDefaultExport","Script","PrismicPreviewClient"],"sources":["../src/PrismicPreview.tsx"],"sourcesContent":["import type { FC, ReactNode } from \"react\";\nimport Script from \"next/script\";\nimport { getToolbarSrc } from \"@prismicio/client\";\n\nimport { resolveDefaultExport } from \"./lib/resolveDefaultExport\";\nimport { PrismicPreviewClient } from \"./PrismicPreviewClient\";\n\n/** Props for `<PrismicPreview>`. */\nexport type PrismicPreviewProps = {\n\t/**\n\t * The name of your Prismic repository. A Prismic Toolbar will be registered\n\t * using this repository.\n\t */\n\trepositoryName: string;\n\n\t/**\n\t * The URL of your app's Prismic preview endpoint (default: `/api/preview`).\n\t * This URL will be fetched on preview update events.\n\t */\n\tupdatePreviewURL?: string;\n\n\t/**\n\t * The URL of your app's exit preview endpoint (default: `/api/exit-preview`).\n\t * This URL will be fetched on preview exit events.\n\t */\n\texitPreviewURL?: string;\n\n\t/** Children to render adjacent to the Prismic Toolbar. */\n\tchildren?: ReactNode;\n};\n\n/**\n * React component that sets up Prismic Previews using the Prismic Toolbar. When\n * the Prismic Toolbar send events to the browser, such as on preview updates\n * and exiting, this component will automatically refresh the page with the\n * changes.\n *\n * This component can be wrapped around your app or added anywhere in your app's\n * tree. It must be rendered on every page.\n */\nexport const PrismicPreview: FC<PrismicPreviewProps> = async (props) => {\n\tconst { repositoryName, children, ...otherProps } = props;\n\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { draftMode } = await import(\"next/headers\");\n\n\tconst toolbarSrc = getToolbarSrc(repositoryName);\n\tconst isDraftMode = (await draftMode()).isEnabled;\n\n\tconst ResolvedScript = resolveDefaultExport(Script);\n\n\treturn (\n\t\t<>\n\t\t\t{children}\n\t\t\t<PrismicPreviewClient\n\t\t\t\trepositoryName={repositoryName}\n\t\t\t\tisDraftMode={isDraftMode}\n\t\t\t\t{...otherProps}\n\t\t\t/>\n\t\t\t<ResolvedScript src={toolbarSrc} strategy=\"lazyOnload\" />\n\t\t</>\n\t);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwCA,MAAa,iBAA0C,OAAO,UAAU;CACvE,MAAM,EAAE,gBAAgB,UAAU,GAAG,eAAe;CAKpD,MAAM,EAAE,cAAc,MAAM,OAAO;CAEnC,MAAM,kDAA2B,eAAe;CAChD,MAAM,eAAe,MAAM,WAAW,EAAE;CAExC,MAAM,iBAAiBA,kDAAqBC,oBAAO;AAEnD,QACC;EACE;EACD,2CAACC;GACgB;GACH;GACb,GAAI;IACH;EACF,2CAAC;GAAe,KAAK;GAAY,UAAS;IAAe;KACvD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicPreviewClient.cjs","names":["value","prismicCookie"],"sources":["../src/PrismicPreviewClient.tsx"],"sourcesContent":["\"use client\";\n\nimport { cookie as prismicCookie } from \"@prismicio/client\";\nimport { useRouter } from \"next/navigation\";\nimport type { FC } from \"react\";\nimport { useEffect } from \"react\";\n\ntype PrismicPreviewClientProps = {\n\trepositoryName: string;\n\tisDraftMode: boolean;\n\tupdatePreviewURL?: string;\n\texitPreviewURL?: string;\n};\n\nexport const PrismicPreviewClient: FC<PrismicPreviewClientProps> = (props) => {\n\tconst {\n\t\trepositoryName,\n\t\tisDraftMode,\n\t\tupdatePreviewURL = \"/api/preview\",\n\t\texitPreviewURL = \"/api/exit-preview\",\n\t} = props;\n\n\tconst { refresh } = useRouter();\n\n\tuseEffect(() => {\n\t\tconst controller = new AbortController();\n\n\t\twindow.addEventListener(\"prismicPreviewUpdate\", onUpdate, {\n\t\t\tsignal: controller.signal,\n\t\t});\n\t\twindow.addEventListener(\"prismicPreviewEnd\", onEnd, {\n\t\t\tsignal: controller.signal,\n\t\t});\n\n\t\tconst cookie = getPrismicPreviewCookie(window.document.cookie);\n\t\tconst cookieRepositoryName = cookie\n\t\t\t? (decodeURIComponent(cookie).match(/\"([^\"]+)\\.prismic\\.io\"/) || [])[1]\n\t\t\t: undefined;\n\t\tconst hasCookieForRepository = cookieRepositoryName === repositoryName;\n\n\t\t// Start the preview for preview share links. Previews from\n\t\t// share links do not go to the `updatePreviewURL` like a normal\n\t\t// preview.\n\t\tif (hasCookieForRepository && !isDraftMode) {\n\t\t\t// We check `opaqueredirect` because we don't care if\n\t\t\t// the redirect was successful or not. As long as it\n\t\t\t// redirects, we know the endpoint exists and draft mode\n\t\t\t// is active.\n\t\t\tglobalThis\n\t\t\t\t.fetch(updatePreviewURL, {\n\t\t\t\t\tredirect: \"manual\",\n\t\t\t\t\tsignal: controller.signal,\n\t\t\t\t})\n\t\t\t\t.then((res) => {\n\t\t\t\t\tif (res.type !== \"opaqueredirect\") {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`[<PrismicPreview>] Failed to start the preview using \"${updatePreviewURL}\". Does it exist?`,\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\trefresh();\n\t\t\t\t})\n\t\t\t\t.catch(() => {\n\t\t\t\t\t// noop\n\t\t\t\t});\n\t\t}\n\n\t\tfunction onUpdate(event: Event) {\n\t\t\tevent.preventDefault();\n\t\t\trefresh();\n\t\t}\n\n\t\tfunction onEnd(event: Event) {\n\t\t\tevent.preventDefault();\n\t\t\tglobalThis\n\t\t\t\t.fetch(exitPreviewURL, { signal: controller.signal })\n\t\t\t\t.then((res) => {\n\t\t\t\t\tif (!res.ok) {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`[<PrismicPreview>] Failed to exit Preview Mode using the \"${exitPreviewURL}\" API endpoint. Does it exist?`,\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\trefresh();\n\t\t\t\t})\n\t\t\t\t.catch(() => {\n\t\t\t\t\t// noop\n\t\t\t\t});\n\t\t}\n\n\t\treturn () => controller.abort();\n\t}, [repositoryName, isDraftMode, updatePreviewURL, exitPreviewURL, refresh]);\n\n\treturn null;\n};\n\n/**\n * Returns the value of a cookie from a given cookie store.\n *\n * @param cookieJar - The stringified cookie store from which to read the\n * cookie.\n *\n * @returns The value of the cookie, if it exists.\n */\nfunction getPrismicPreviewCookie(cookieJar: string): string | undefined {\n\tfunction readValue(value: string): string {\n\t\treturn value.replace(/%3B/g, \";\");\n\t}\n\n\tconst cookies = cookieJar.split(\"; \");\n\n\tlet value: string | undefined;\n\n\tfor (const cookie of cookies) {\n\t\tconst parts = cookie.split(\"=\");\n\t\tconst name = readValue(parts[0]).replace(/%3D/g, \"=\");\n\n\t\tif (name === prismicCookie.preview) {\n\t\t\tvalue = readValue(parts.slice(1).join(\"=\"));\n\t\t\tcontinue;\n\t\t}\n\t}\n\n\treturn value;\n}\n"],"mappings":";;;;;;;;AAcA,MAAa,wBAAuD,UAAU;CAC7E,MAAM,EACL,gBACA,aACA,mBAAmB,gBACnB,iBAAiB,wBACd;CAEJ,MAAM,EAAE,4CAAuB;AAE/B,4BAAgB;EACf,MAAM,aAAa,IAAI,iBAAiB;AAExC,SAAO,iBAAiB,wBAAwB,UAAU,EACzD,QAAQ,WAAW,QACnB,CAAC;AACF,SAAO,iBAAiB,qBAAqB,OAAO,EACnD,QAAQ,WAAW,QACnB,CAAC;EAEF,MAAM,SAAS,wBAAwB,OAAO,SAAS,OAAO;AAS9D,OAR6B,UACzB,mBAAmB,OAAO,CAAC,MAAM,yBAAyB,IAAI,EAAE,EAAE,KACnE,YACqD,kBAK1B,CAAC,YAK9B,YACE,MAAM,kBAAkB;GACxB,UAAU;GACV,QAAQ,WAAW;GACnB,CAAC,CACD,MAAM,QAAQ;AACd,OAAI,IAAI,SAAS,kBAAkB;AAClC,YAAQ,MACP,yDAAyD,iBAAiB,mBAC1E;AAED;;AAGD,YAAS;IACR,CACD,YAAY,GAEX;EAGJ,SAAS,SAAS,OAAc;AAC/B,SAAM,gBAAgB;AACtB,YAAS;;EAGV,SAAS,MAAM,OAAc;AAC5B,SAAM,gBAAgB;AACtB,cACE,MAAM,gBAAgB,EAAE,QAAQ,WAAW,QAAQ,CAAC,CACpD,MAAM,QAAQ;AACd,QAAI,CAAC,IAAI,IAAI;AACZ,aAAQ,MACP,6DAA6D,eAAe,gCAC5E;AAED;;AAGD,aAAS;KACR,CACD,YAAY,GAEX;;AAGJ,eAAa,WAAW,OAAO;IAC7B;EAAC;EAAgB;EAAa;EAAkB;EAAgB;EAAQ,CAAC;AAE5E,QAAO;;;;;;;;;;AAWR,SAAS,wBAAwB,WAAuC;CACvE,SAAS,UAAU,SAAuB;AACzC,SAAOA,QAAM,QAAQ,QAAQ,IAAI;;CAGlC,MAAM,UAAU,UAAU,MAAM,KAAK;CAErC,IAAI;AAEJ,MAAK,MAAM,UAAU,SAAS;EAC7B,MAAM,QAAQ,OAAO,MAAM,IAAI;AAG/B,MAFa,UAAU,MAAM,GAAG,CAAC,QAAQ,QAAQ,IAAI,KAExCC,yBAAc,SAAS;AACnC,WAAQ,UAAU,MAAM,MAAM,EAAE,CAAC,KAAK,IAAI,CAAC;AAC3C;;;AAIF,QAAO"}
|
package/dist/PrismicRichText.cjs
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
4
|
-
const require_PrismicImage = require('./PrismicImage.cjs');
|
|
5
|
-
const require_PrismicLink = require('./PrismicLink.cjs');
|
|
6
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
|
-
let _prismicio_react = require("@prismicio/react");
|
|
8
|
-
|
|
9
|
-
//#region src/PrismicRichText.tsx
|
|
10
|
-
const defaultComponents = {
|
|
11
|
-
image: ({ node, key }) => {
|
|
12
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
13
|
-
className: "block-img",
|
|
14
|
-
children: node.linkTo ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PrismicLink.PrismicLink, {
|
|
15
|
-
field: node.linkTo,
|
|
16
|
-
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PrismicImage.PrismicImage, { field: node })
|
|
17
|
-
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PrismicImage.PrismicImage, { field: node })
|
|
18
|
-
}, key);
|
|
19
|
-
},
|
|
20
|
-
hyperlink: ({ node, children }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PrismicLink.PrismicLink, {
|
|
21
|
-
field: node.data,
|
|
22
|
-
children
|
|
23
|
-
})
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Renders content from a Prismic rich text field as React components with
|
|
27
|
-
* Next.js-optimized defaults for images and links.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
*
|
|
31
|
-
* ```tsx
|
|
32
|
-
* <PrismicRichText field={slice.primary.text} />;
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* @see {@link https://prismic.io/docs/fields/rich-text}
|
|
36
|
-
*/
|
|
37
|
-
const PrismicRichText = ({ components, ...restProps }) => {
|
|
38
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_prismicio_react.PrismicRichText, {
|
|
39
|
-
components: {
|
|
40
|
-
...defaultComponents,
|
|
41
|
-
...components
|
|
42
|
-
},
|
|
43
|
-
...restProps
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
//#endregion
|
|
48
|
-
exports.PrismicRichText = PrismicRichText;
|
|
49
|
-
exports.defaultComponents = defaultComponents;
|
|
50
|
-
//# sourceMappingURL=PrismicRichText.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicRichText.cjs","names":["PrismicLink","PrismicImage","BasePrismicRichText"],"sources":["../src/PrismicRichText.tsx"],"sourcesContent":["\"use client\";\n\nimport { PrismicImage } from \"./PrismicImage\";\nimport { PrismicLink } from \"./PrismicLink\";\nimport {\n\tPrismicRichText as BasePrismicRichText,\n\ttype PrismicRichTextProps as BasePrismicRichTextProps,\n\ttype RichTextComponents,\n} from \"@prismicio/react\";\nimport type { FC } from \"react\";\n\n/**\n * Props for `<PrismicRichText>`.\n */\nexport type PrismicRichTextProps = Omit<\n\tBasePrismicRichTextProps,\n\t\"components\"\n> & {\n\tcomponents?: RichTextComponents;\n};\n\nexport const defaultComponents: RichTextComponents = {\n\timage: ({ node, key }) => {\n\t\treturn (\n\t\t\t<p key={key} className=\"block-img\">\n\t\t\t\t{node.linkTo ? (\n\t\t\t\t\t<PrismicLink field={node.linkTo}>\n\t\t\t\t\t\t<PrismicImage field={node} />\n\t\t\t\t\t</PrismicLink>\n\t\t\t\t) : (\n\t\t\t\t\t<PrismicImage field={node} />\n\t\t\t\t)}\n\t\t\t</p>\n\t\t);\n\t},\n\thyperlink: ({ node, children }) => (\n\t\t<PrismicLink field={node.data}>{children}</PrismicLink>\n\t),\n};\n\n/**\n * Renders content from a Prismic rich text field as React components with\n * Next.js-optimized defaults for images and links.\n *\n * @example\n *\n * ```tsx\n * <PrismicRichText field={slice.primary.text} />;\n * ```\n *\n * @see {@link https://prismic.io/docs/fields/rich-text}\n */\nexport const PrismicRichText: FC<PrismicRichTextProps> = ({\n\tcomponents,\n\t...restProps\n}) => {\n\treturn (\n\t\t<BasePrismicRichText\n\t\t\tcomponents={{ ...defaultComponents, ...components }}\n\t\t\t{...restProps}\n\t\t/>\n\t);\n};\n"],"mappings":";;;;;;;;;AAqBA,MAAa,oBAAwC;CACpD,QAAQ,EAAE,MAAM,UAAU;AACzB,SACC,2CAAC;GAAY,WAAU;aACrB,KAAK,SACL,2CAACA;IAAY,OAAO,KAAK;cACxB,2CAACC,qCAAa,OAAO,OAAQ;KAChB,GAEd,2CAACA,qCAAa,OAAO,OAAQ;KANvB,IAQJ;;CAGN,YAAY,EAAE,MAAM,eACnB,2CAACD;EAAY,OAAO,KAAK;EAAO;GAAuB;CAExD;;;;;;;;;;;;;AAcD,MAAa,mBAA6C,EACzD,YACA,GAAG,gBACE;AACL,QACC,2CAACE;EACA,YAAY;GAAE,GAAG;GAAmB,GAAG;GAAY;EACnD,GAAI;GACH"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { FC } from "react";
|
|
2
|
-
import { PrismicRichTextProps, RichTextComponents } from "@prismicio/react";
|
|
3
|
-
|
|
4
|
-
//#region src/PrismicRichText.d.ts
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Props for `<PrismicRichText>`.
|
|
8
|
-
*/
|
|
9
|
-
type PrismicRichTextProps$1 = Omit<PrismicRichTextProps, "components"> & {
|
|
10
|
-
components?: RichTextComponents;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Renders content from a Prismic rich text field as React components with
|
|
14
|
-
* Next.js-optimized defaults for images and links.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
*
|
|
18
|
-
* ```tsx
|
|
19
|
-
* <PrismicRichText field={slice.primary.text} />;
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* @see {@link https://prismic.io/docs/fields/rich-text}
|
|
23
|
-
*/
|
|
24
|
-
declare const PrismicRichText: FC<PrismicRichTextProps$1>;
|
|
25
|
-
//#endregion
|
|
26
|
-
export { PrismicRichText, PrismicRichTextProps$1 as PrismicRichTextProps };
|
|
27
|
-
//# sourceMappingURL=PrismicRichText.d.cts.map
|
package/dist/PrismicTable.cjs
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
4
|
-
const require_PrismicRichText = require('./PrismicRichText.cjs');
|
|
5
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
6
|
-
let _prismicio_react = require("@prismicio/react");
|
|
7
|
-
|
|
8
|
-
//#region src/PrismicTable.tsx
|
|
9
|
-
/**
|
|
10
|
-
* Renders content from a Prismic table field as React components with
|
|
11
|
-
* Next.js-optimized defaults for images and links in cell content.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
*
|
|
15
|
-
* ```tsx
|
|
16
|
-
* <PrismicTable field={slice.primary.pricing_table} />;
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* @see Learn how to style tables and customize table element components:
|
|
20
|
-
* {@link https://prismic.io/docs/fields/table}
|
|
21
|
-
*/
|
|
22
|
-
const PrismicTable = ({ components, ...restProps }) => {
|
|
23
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_prismicio_react.PrismicTable, {
|
|
24
|
-
components: {
|
|
25
|
-
...require_PrismicRichText.defaultComponents,
|
|
26
|
-
...components
|
|
27
|
-
},
|
|
28
|
-
...restProps
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
//#endregion
|
|
33
|
-
exports.PrismicTable = PrismicTable;
|
|
34
|
-
//# sourceMappingURL=PrismicTable.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicTable.cjs","names":["BasePrismicTable","defaultComponents"],"sources":["../src/PrismicTable.tsx"],"sourcesContent":["\"use client\";\n\nimport { defaultComponents } from \"./PrismicRichText\";\nimport {\n\tPrismicTable as BasePrismicTable,\n\ttype PrismicTableProps,\n} from \"@prismicio/react\";\nimport type { FC } from \"react\";\n\n/**\n * Renders content from a Prismic table field as React components with\n * Next.js-optimized defaults for images and links in cell content.\n *\n * @example\n *\n * ```tsx\n * <PrismicTable field={slice.primary.pricing_table} />;\n * ```\n *\n * @see Learn how to style tables and customize table element components:\n * {@link https://prismic.io/docs/fields/table}\n */\nexport const PrismicTable: FC<PrismicTableProps> = ({\n\tcomponents,\n\t...restProps\n}) => {\n\treturn (\n\t\t<BasePrismicTable\n\t\t\tcomponents={{ ...defaultComponents, ...components }}\n\t\t\t{...restProps}\n\t\t/>\n\t);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,gBAAuC,EACnD,YACA,GAAG,gBACE;AACL,QACC,2CAACA;EACA,YAAY;GAAE,GAAGC;GAAmB,GAAG;GAAY;EACnD,GAAI;GACH"}
|