@prismicio/next 2.2.3 → 2.2.4
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/PrismicNextImage.cjs +9 -11
- package/dist/PrismicNextImage.cjs.map +1 -1
- package/dist/PrismicNextImage.d.cts +13 -21
- package/dist/PrismicNextImage.d.cts.map +1 -0
- package/dist/PrismicNextImage.d.ts +13 -21
- package/dist/PrismicNextImage.d.ts.map +1 -0
- package/dist/PrismicNextImage.js +9 -11
- package/dist/PrismicNextImage.js.map +1 -1
- package/dist/PrismicNextLink.cjs.map +1 -1
- package/dist/PrismicNextLink.d.cts +3 -3
- package/dist/PrismicNextLink.d.cts.map +1 -0
- package/dist/PrismicNextLink.d.ts +3 -3
- package/dist/PrismicNextLink.d.ts.map +1 -0
- package/dist/PrismicNextLink.js.map +1 -1
- package/dist/PrismicPreview.cjs +6 -7
- package/dist/PrismicPreview.cjs.map +1 -1
- package/dist/PrismicPreview.d.cts +11 -12
- package/dist/PrismicPreview.d.cts.map +1 -0
- package/dist/PrismicPreview.d.ts +11 -12
- package/dist/PrismicPreview.d.ts.map +1 -0
- package/dist/PrismicPreview.js +6 -7
- package/dist/PrismicPreview.js.map +1 -1
- package/dist/PrismicPreviewClient.cjs +1 -3
- package/dist/PrismicPreviewClient.cjs.map +1 -1
- package/dist/PrismicPreviewClient.js +1 -3
- package/dist/PrismicPreviewClient.js.map +1 -1
- package/dist/SliceSimulator.cjs +3 -3
- package/dist/SliceSimulator.cjs.map +1 -1
- package/dist/SliceSimulator.d.cts +3 -5
- package/dist/SliceSimulator.d.cts.map +1 -0
- package/dist/SliceSimulator.d.ts +3 -5
- package/dist/SliceSimulator.d.ts.map +1 -0
- package/dist/SliceSimulator.js +3 -3
- package/dist/SliceSimulator.js.map +1 -1
- package/dist/SliceSimulatorWrapper.cjs +1 -4
- package/dist/SliceSimulatorWrapper.cjs.map +1 -1
- package/dist/SliceSimulatorWrapper.js +1 -4
- package/dist/SliceSimulatorWrapper.js.map +1 -1
- package/dist/createLocaleRedirect.cjs.map +1 -1
- package/dist/createLocaleRedirect.d.cts.map +1 -0
- package/dist/createLocaleRedirect.d.ts.map +1 -0
- package/dist/createLocaleRedirect.js.map +1 -1
- package/dist/enableAutoPreviews.cjs +1 -2
- package/dist/enableAutoPreviews.cjs.map +1 -1
- package/dist/enableAutoPreviews.d.cts +1 -2
- package/dist/enableAutoPreviews.d.cts.map +1 -0
- package/dist/enableAutoPreviews.d.ts +1 -2
- package/dist/enableAutoPreviews.d.ts.map +1 -0
- package/dist/enableAutoPreviews.js +1 -2
- package/dist/enableAutoPreviews.js.map +1 -1
- package/dist/exitPreview.cjs +9 -10
- package/dist/exitPreview.cjs.map +1 -1
- package/dist/exitPreview.d.cts +9 -10
- package/dist/exitPreview.d.cts.map +1 -0
- package/dist/exitPreview.d.ts +9 -10
- package/dist/exitPreview.d.ts.map +1 -0
- package/dist/exitPreview.js +9 -10
- package/dist/exitPreview.js.map +1 -1
- package/dist/getSlices.cjs.map +1 -1
- package/dist/getSlices.d.cts.map +1 -0
- package/dist/getSlices.d.ts.map +1 -0
- package/dist/getSlices.js.map +1 -1
- package/dist/imgixLoader.cjs +2 -2
- package/dist/imgixLoader.cjs.map +1 -1
- package/dist/imgixLoader.d.cts +2 -2
- package/dist/imgixLoader.d.cts.map +1 -0
- package/dist/imgixLoader.d.ts +2 -2
- package/dist/imgixLoader.d.ts.map +1 -0
- package/dist/imgixLoader.js +2 -2
- package/dist/imgixLoader.js.map +1 -1
- package/dist/lib/devMsg.cjs +6 -8
- package/dist/lib/devMsg.cjs.map +1 -1
- package/dist/lib/devMsg.js +6 -8
- package/dist/lib/devMsg.js.map +1 -1
- package/dist/lib/resolveDefaultExport.cjs +8 -12
- package/dist/lib/resolveDefaultExport.cjs.map +1 -1
- package/dist/lib/resolveDefaultExport.js +8 -12
- package/dist/lib/resolveDefaultExport.js.map +1 -1
- package/dist/package.cjs +1 -1
- package/dist/package.js +1 -1
- package/dist/pages/PrismicPreview.cjs +6 -7
- package/dist/pages/PrismicPreview.cjs.map +1 -1
- package/dist/pages/PrismicPreview.d.cts +11 -12
- package/dist/pages/PrismicPreview.d.cts.map +1 -0
- package/dist/pages/PrismicPreview.d.ts +11 -12
- package/dist/pages/PrismicPreview.d.ts.map +1 -0
- package/dist/pages/PrismicPreview.js +6 -7
- package/dist/pages/PrismicPreview.js.map +1 -1
- package/dist/pages/SliceSimulator.cjs +2 -2
- package/dist/pages/SliceSimulator.cjs.map +1 -1
- package/dist/pages/SliceSimulator.d.cts +10 -13
- package/dist/pages/SliceSimulator.d.cts.map +1 -0
- package/dist/pages/SliceSimulator.d.ts +10 -13
- package/dist/pages/SliceSimulator.d.ts.map +1 -0
- package/dist/pages/SliceSimulator.js +2 -2
- package/dist/pages/SliceSimulator.js.map +1 -1
- package/dist/pages/enableAutoPreviews.cjs +3 -3
- package/dist/pages/enableAutoPreviews.cjs.map +1 -1
- package/dist/pages/enableAutoPreviews.d.cts +5 -5
- package/dist/pages/enableAutoPreviews.d.cts.map +1 -0
- package/dist/pages/enableAutoPreviews.d.ts +5 -5
- package/dist/pages/enableAutoPreviews.d.ts.map +1 -0
- package/dist/pages/enableAutoPreviews.js +3 -3
- package/dist/pages/enableAutoPreviews.js.map +1 -1
- package/dist/pages/exitPreview.cjs +9 -10
- package/dist/pages/exitPreview.cjs.map +1 -1
- package/dist/pages/exitPreview.d.cts +9 -10
- package/dist/pages/exitPreview.d.cts.map +1 -0
- package/dist/pages/exitPreview.d.ts +9 -10
- package/dist/pages/exitPreview.d.ts.map +1 -0
- package/dist/pages/exitPreview.js +9 -10
- package/dist/pages/exitPreview.js.map +1 -1
- package/dist/pages/redirectToPreviewURL.cjs.map +1 -1
- package/dist/pages/redirectToPreviewURL.d.cts +7 -9
- package/dist/pages/redirectToPreviewURL.d.cts.map +1 -0
- package/dist/pages/redirectToPreviewURL.d.ts +7 -9
- package/dist/pages/redirectToPreviewURL.d.ts.map +1 -0
- package/dist/pages/redirectToPreviewURL.js.map +1 -1
- package/dist/pages/setPreviewData.cjs.map +1 -1
- package/dist/pages/setPreviewData.d.cts.map +1 -0
- package/dist/pages/setPreviewData.d.ts.map +1 -0
- package/dist/pages/setPreviewData.js.map +1 -1
- package/dist/pages/types.d.cts +3 -8
- package/dist/pages/types.d.cts.map +1 -0
- package/dist/pages/types.d.ts +3 -8
- package/dist/pages/types.d.ts.map +1 -0
- package/dist/redirectToPreviewURL.cjs.map +1 -1
- package/dist/redirectToPreviewURL.d.cts +3 -5
- package/dist/redirectToPreviewURL.d.cts.map +1 -0
- package/dist/redirectToPreviewURL.d.ts +3 -5
- package/dist/redirectToPreviewURL.d.ts.map +1 -0
- package/dist/redirectToPreviewURL.js.map +1 -1
- package/dist/types.d.cts +1 -2
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.ts +1 -2
- package/dist/types.d.ts.map +1 -0
- package/package.json +32 -34
- package/src/PrismicNextImage.tsx +113 -134
- package/src/PrismicNextLink.tsx +43 -45
- package/src/PrismicPreview.tsx +28 -29
- package/src/PrismicPreviewClient.tsx +42 -44
- package/src/SliceSimulator.tsx +38 -43
- package/src/SliceSimulatorWrapper.tsx +15 -25
- package/src/createLocaleRedirect.ts +3 -3
- package/src/enableAutoPreviews.ts +15 -16
- package/src/exitPreview.ts +12 -13
- package/src/getSlices.ts +6 -10
- package/src/imgixLoader.ts +10 -10
- package/src/index.ts +18 -21
- package/src/lib/devMsg.ts +9 -11
- package/src/lib/resolveDefaultExport.ts +9 -13
- package/src/pages/PrismicPreview.tsx +47 -51
- package/src/pages/SliceSimulator.tsx +35 -37
- package/src/pages/enableAutoPreviews.ts +17 -17
- package/src/pages/exitPreview.ts +17 -18
- package/src/pages/index.ts +20 -23
- package/src/pages/redirectToPreviewURL.ts +22 -33
- package/src/pages/setPreviewData.ts +7 -7
- package/src/pages/types.ts +16 -20
- package/src/redirectToPreviewURL.ts +21 -30
- package/src/types.ts +12 -13
package/package.json
CHANGED
|
@@ -1,22 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismicio/next",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.4",
|
|
4
4
|
"description": "Helpers to integrate Prismic into Next.js apps",
|
|
5
5
|
"keywords": [
|
|
6
|
-
"typescript",
|
|
7
|
-
"prismic",
|
|
8
6
|
"next",
|
|
9
|
-
"
|
|
10
|
-
"
|
|
7
|
+
"preview",
|
|
8
|
+
"prismic",
|
|
9
|
+
"typescript",
|
|
10
|
+
"vercel"
|
|
11
11
|
],
|
|
12
|
+
"license": "Apache-2.0",
|
|
13
|
+
"author": "Prismic <contact@prismic.io> (https://prismic.io)",
|
|
12
14
|
"repository": {
|
|
13
15
|
"type": "git",
|
|
14
16
|
"url": "git+https://github.com/prismicio/prismic-next.git"
|
|
15
17
|
},
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
"workspaces": [
|
|
19
|
+
".",
|
|
20
|
+
"e2e-projects/*"
|
|
21
|
+
],
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"src"
|
|
25
|
+
],
|
|
19
26
|
"type": "module",
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"main": "./dist/index.cjs",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
20
30
|
"exports": {
|
|
21
31
|
".": {
|
|
22
32
|
"types": "./dist/index.d.ts",
|
|
@@ -28,45 +38,36 @@
|
|
|
28
38
|
},
|
|
29
39
|
"./package.json": "./package.json"
|
|
30
40
|
},
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"dist",
|
|
35
|
-
"src"
|
|
36
|
-
],
|
|
37
|
-
"workspaces": [
|
|
38
|
-
".",
|
|
39
|
-
"e2e-projects/*"
|
|
40
|
-
],
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
41
44
|
"scripts": {
|
|
42
45
|
"build": "tsdown",
|
|
43
46
|
"dev": "tsdown --watch",
|
|
44
47
|
"e2e": "playwright test",
|
|
45
48
|
"e2e:ui": "npm run e2e -- --ui",
|
|
46
|
-
"format": "
|
|
49
|
+
"format": "oxfmt",
|
|
47
50
|
"lint": "oxlint --deny-warnings",
|
|
48
51
|
"prepare": "npm run build",
|
|
49
52
|
"test": "npm run lint && npm run types && npm run build && npm run e2e",
|
|
50
53
|
"types": "tsc --noEmit"
|
|
51
54
|
},
|
|
52
55
|
"dependencies": {
|
|
53
|
-
"@prismicio/simulator": "^0.2.
|
|
56
|
+
"@prismicio/simulator": "^0.2.2",
|
|
54
57
|
"imgix-url-builder": "^0.0.6",
|
|
55
58
|
"lz-string": "^1.5.0"
|
|
56
59
|
},
|
|
57
60
|
"devDependencies": {
|
|
58
|
-
"@playwright/test": "^1.
|
|
59
|
-
"@prismicio/client": "^7.
|
|
60
|
-
"@
|
|
61
|
-
"@types/node": "^25.5.0",
|
|
61
|
+
"@playwright/test": "^1.59.1",
|
|
62
|
+
"@prismicio/client": "^7.21.8",
|
|
63
|
+
"@types/node": "^25.5.2",
|
|
62
64
|
"@types/react": "^19.2.14",
|
|
63
|
-
"next": "16.2.
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"react": "^19.2.
|
|
69
|
-
"react-dom": "^19.2.4",
|
|
65
|
+
"next": "16.2.3",
|
|
66
|
+
"oxfmt": "^0.44.0",
|
|
67
|
+
"oxlint": "^1.59.0",
|
|
68
|
+
"playwright": "^1.59.1",
|
|
69
|
+
"react": "^19.2.5",
|
|
70
|
+
"react-dom": "^19.2.5",
|
|
70
71
|
"tsdown": "^0.21.7",
|
|
71
72
|
"typescript": "^6.0.2"
|
|
72
73
|
},
|
|
@@ -77,8 +78,5 @@
|
|
|
77
78
|
},
|
|
78
79
|
"engines": {
|
|
79
80
|
"node": ">=20"
|
|
80
|
-
},
|
|
81
|
-
"publishConfig": {
|
|
82
|
-
"access": "public"
|
|
83
81
|
}
|
|
84
82
|
}
|
package/src/PrismicNextImage.tsx
CHANGED
|
@@ -1,185 +1,164 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
} from "react"
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
import
|
|
13
|
-
import {
|
|
14
|
-
import
|
|
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";
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import type { ImageFieldImage } from "@prismicio/client"
|
|
4
|
+
import { isFilled } from "@prismicio/client"
|
|
5
|
+
import type { ImgixURLParams } from "imgix-url-builder"
|
|
6
|
+
import { buildURL } from "imgix-url-builder"
|
|
7
|
+
import type { ImageProps } from "next/image"
|
|
8
|
+
import Image from "next/image"
|
|
9
|
+
import type { ForwardRefExoticComponent, PropsWithoutRef, RefAttributes } from "react"
|
|
10
|
+
import { forwardRef } from "react"
|
|
11
|
+
|
|
12
|
+
import { imgixLoader } from "./imgixLoader"
|
|
13
|
+
import { devMsg } from "./lib/devMsg"
|
|
14
|
+
import { resolveDefaultExport } from "./lib/resolveDefaultExport"
|
|
21
15
|
|
|
22
16
|
const castInt = (input: string | number | undefined): number | undefined => {
|
|
23
17
|
if (typeof input === "number" || typeof input === "undefined") {
|
|
24
|
-
return input
|
|
18
|
+
return input
|
|
25
19
|
} else {
|
|
26
|
-
const parsed = Number.parseInt(input)
|
|
20
|
+
const parsed = Number.parseInt(input)
|
|
27
21
|
|
|
28
22
|
if (Number.isNaN(parsed)) {
|
|
29
|
-
return undefined
|
|
23
|
+
return undefined
|
|
30
24
|
} else {
|
|
31
|
-
return parsed
|
|
25
|
+
return parsed
|
|
32
26
|
}
|
|
33
27
|
}
|
|
34
|
-
}
|
|
28
|
+
}
|
|
35
29
|
|
|
36
|
-
export type PrismicNextImageProps = Omit<
|
|
37
|
-
ImageProps,
|
|
38
|
-
"src" | "alt" | "loader"
|
|
39
|
-
> & {
|
|
30
|
+
export type PrismicNextImageProps = Omit<ImageProps, "src" | "alt" | "loader"> & {
|
|
40
31
|
/** The Prismic Image field or thumbnail to render. */
|
|
41
|
-
field: ImageFieldImage | null | undefined
|
|
32
|
+
field: ImageFieldImage | null | undefined
|
|
42
33
|
|
|
43
34
|
/**
|
|
44
35
|
* An object of Imgix URL API parameters to transform the image.
|
|
45
36
|
*
|
|
46
37
|
* @see https://docs.imgix.com/apis/rendering
|
|
47
38
|
*/
|
|
48
|
-
imgixParams?: { [P in keyof ImgixURLParams]: ImgixURLParams[P] | null }
|
|
39
|
+
imgixParams?: { [P in keyof ImgixURLParams]: ImgixURLParams[P] | null }
|
|
49
40
|
|
|
50
41
|
/**
|
|
51
42
|
* Declare an image as decorative by providing `alt=""`.
|
|
52
43
|
*
|
|
53
|
-
* See:
|
|
54
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
44
|
+
* See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
55
45
|
*/
|
|
56
|
-
alt?: ""
|
|
46
|
+
alt?: ""
|
|
57
47
|
|
|
58
48
|
/**
|
|
59
|
-
* Declare an image as decorative only if the Image field does not have
|
|
60
|
-
*
|
|
49
|
+
* Declare an image as decorative only if the Image field does not have alternative text by
|
|
50
|
+
* providing `fallbackAlt=""`.
|
|
61
51
|
*
|
|
62
|
-
* See:
|
|
63
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
52
|
+
* See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
64
53
|
*/
|
|
65
|
-
fallbackAlt?: ""
|
|
54
|
+
fallbackAlt?: ""
|
|
66
55
|
|
|
67
|
-
/**
|
|
68
|
-
|
|
69
|
-
* be rendered.
|
|
70
|
-
*/
|
|
71
|
-
fallback?: React.ReactNode;
|
|
56
|
+
/** Rendered when the field is empty. If a fallback is not given, `null` will be rendered. */
|
|
57
|
+
fallback?: React.ReactNode
|
|
72
58
|
|
|
73
|
-
loader?: ImageProps["loader"] | null
|
|
74
|
-
}
|
|
59
|
+
loader?: ImageProps["loader"] | null
|
|
60
|
+
}
|
|
75
61
|
|
|
76
62
|
/**
|
|
77
|
-
* React component that renders an image from a Prismic Image field or one of
|
|
78
|
-
*
|
|
79
|
-
*
|
|
63
|
+
* React component that renders an image from a Prismic Image field or one of its thumbnails using
|
|
64
|
+
* `next/image`. It will automatically set the `alt` attribute using the Image field's `alt`
|
|
65
|
+
* property.
|
|
80
66
|
*
|
|
81
|
-
* It uses an Imgix URL-based loader by default. A custom loader can be provided
|
|
82
|
-
*
|
|
83
|
-
*
|
|
67
|
+
* It uses an Imgix URL-based loader by default. A custom loader can be provided with the `loader`
|
|
68
|
+
* prop. If you would like to use the Next.js Image Optimization API instead, set
|
|
69
|
+
* `loader={undefined}`.
|
|
84
70
|
*
|
|
85
71
|
* @param props - Props for the component.
|
|
86
|
-
*
|
|
87
72
|
* @returns A responsive image component using `next/image` for the given Image
|
|
88
|
-
*
|
|
89
|
-
*
|
|
73
|
+
* field.
|
|
90
74
|
* @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image
|
|
91
75
|
*/
|
|
92
76
|
// The type annotation is necessary to avoid a type reference issue.
|
|
93
77
|
export const PrismicNextImage: ForwardRefExoticComponent<
|
|
94
78
|
PropsWithoutRef<PrismicNextImageProps> & RefAttributes<HTMLImageElement>
|
|
95
|
-
> = forwardRef<HTMLImageElement, PrismicNextImageProps>(
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
) {
|
|
111
|
-
if (
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
}
|
|
79
|
+
> = forwardRef<HTMLImageElement, PrismicNextImageProps>(function PrismicNextImage(
|
|
80
|
+
{
|
|
81
|
+
field,
|
|
82
|
+
imgixParams = {},
|
|
83
|
+
alt,
|
|
84
|
+
fallbackAlt,
|
|
85
|
+
fill,
|
|
86
|
+
width,
|
|
87
|
+
height,
|
|
88
|
+
fallback = null,
|
|
89
|
+
loader = imgixLoader,
|
|
90
|
+
...restProps
|
|
91
|
+
},
|
|
92
|
+
ref,
|
|
93
|
+
) {
|
|
94
|
+
if (process.env.NODE_ENV === "development") {
|
|
95
|
+
if (typeof alt === "string" && alt !== "") {
|
|
96
|
+
console.warn(
|
|
97
|
+
`[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(
|
|
98
|
+
"alt-must-be-an-empty-string",
|
|
99
|
+
)}`,
|
|
100
|
+
)
|
|
127
101
|
}
|
|
128
102
|
|
|
129
|
-
if (
|
|
130
|
-
|
|
103
|
+
if (typeof fallbackAlt === "string" && fallbackAlt !== "") {
|
|
104
|
+
console.warn(
|
|
105
|
+
`[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(
|
|
106
|
+
"alt-must-be-an-empty-string",
|
|
107
|
+
)}`,
|
|
108
|
+
)
|
|
131
109
|
}
|
|
110
|
+
}
|
|
132
111
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
112
|
+
if (!isFilled.imageThumbnail(field)) {
|
|
113
|
+
return <>{fallback}</>
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const resolvedImgixParams = imgixParams
|
|
117
|
+
for (const x in imgixParams) {
|
|
118
|
+
if (resolvedImgixParams[x as keyof typeof resolvedImgixParams] === null) {
|
|
119
|
+
resolvedImgixParams[x as keyof typeof resolvedImgixParams] = undefined
|
|
138
120
|
}
|
|
121
|
+
}
|
|
139
122
|
|
|
140
|
-
|
|
123
|
+
const src = buildURL(field.url, imgixParams as ImgixURLParams)
|
|
141
124
|
|
|
142
|
-
|
|
125
|
+
const ar = field.dimensions.width / field.dimensions.height
|
|
143
126
|
|
|
144
|
-
|
|
145
|
-
|
|
127
|
+
const castedWidth = castInt(width)
|
|
128
|
+
const castedHeight = castInt(height)
|
|
146
129
|
|
|
147
|
-
|
|
148
|
-
|
|
130
|
+
let resolvedWidth = castedWidth ?? field.dimensions.width
|
|
131
|
+
let resolvedHeight = castedHeight ?? field.dimensions.height
|
|
149
132
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
133
|
+
if (castedWidth != null && castedHeight == null) {
|
|
134
|
+
resolvedHeight = castedWidth / ar
|
|
135
|
+
} else if (castedWidth == null && castedHeight != null) {
|
|
136
|
+
resolvedWidth = castedHeight * ar
|
|
137
|
+
}
|
|
155
138
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
-
}
|
|
139
|
+
// A non-null assertion is required since we can't statically
|
|
140
|
+
// know if an alt attribute is available.
|
|
141
|
+
const resolvedAlt = (alt ?? (field.alt || fallbackAlt))!
|
|
169
142
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
143
|
+
if (process.env.NODE_ENV === "development" && typeof resolvedAlt !== "string") {
|
|
144
|
+
console.error(
|
|
145
|
+
`[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=""\`.`,
|
|
146
|
+
src,
|
|
147
|
+
)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const ResolvedImage = resolveDefaultExport(Image)
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<ResolvedImage
|
|
154
|
+
ref={ref}
|
|
155
|
+
src={src}
|
|
156
|
+
width={fill ? undefined : resolvedWidth}
|
|
157
|
+
height={fill ? undefined : resolvedHeight}
|
|
158
|
+
alt={resolvedAlt}
|
|
159
|
+
fill={fill}
|
|
160
|
+
loader={loader === null ? undefined : loader}
|
|
161
|
+
{...restProps}
|
|
162
|
+
/>
|
|
163
|
+
)
|
|
164
|
+
})
|
package/src/PrismicNextLink.tsx
CHANGED
|
@@ -1,67 +1,65 @@
|
|
|
1
|
-
import type { ComponentProps} from "react";
|
|
2
|
-
import { forwardRef } from "react";
|
|
3
|
-
import Link from "next/link";
|
|
4
1
|
import type {
|
|
5
2
|
AsLinkAttrsConfig,
|
|
6
3
|
LinkField,
|
|
7
4
|
LinkResolverFunction,
|
|
8
|
-
PrismicDocument
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
PrismicDocument,
|
|
6
|
+
} from "@prismicio/client"
|
|
7
|
+
import { asLinkAttrs } from "@prismicio/client"
|
|
8
|
+
import Link from "next/link"
|
|
9
|
+
import type { ComponentProps } from "react"
|
|
10
|
+
import { forwardRef } from "react"
|
|
12
11
|
|
|
13
|
-
import { resolveDefaultExport } from "./lib/resolveDefaultExport"
|
|
12
|
+
import { resolveDefaultExport } from "./lib/resolveDefaultExport"
|
|
14
13
|
|
|
15
14
|
export type PrismicNextLinkProps = Omit<
|
|
16
15
|
ComponentProps<typeof Link>,
|
|
17
16
|
"field" | "document" | "href" | "rel"
|
|
18
17
|
> & {
|
|
19
|
-
linkResolver?: LinkResolverFunction
|
|
20
|
-
rel?: string | AsLinkAttrsConfig["rel"]
|
|
18
|
+
linkResolver?: LinkResolverFunction
|
|
19
|
+
rel?: string | AsLinkAttrsConfig["rel"]
|
|
21
20
|
} & (
|
|
22
21
|
| {
|
|
23
|
-
field: LinkField | null | undefined
|
|
24
|
-
document?: never
|
|
25
|
-
href?: never
|
|
22
|
+
field: LinkField | null | undefined
|
|
23
|
+
document?: never
|
|
24
|
+
href?: never
|
|
26
25
|
}
|
|
27
26
|
| {
|
|
28
|
-
field?: never
|
|
29
|
-
document: PrismicDocument | null | undefined
|
|
30
|
-
href?: never
|
|
27
|
+
field?: never
|
|
28
|
+
document: PrismicDocument | null | undefined
|
|
29
|
+
href?: never
|
|
31
30
|
}
|
|
32
31
|
| {
|
|
33
|
-
field?: never
|
|
34
|
-
document?: never
|
|
35
|
-
href: ComponentProps<typeof Link>["href"]
|
|
32
|
+
field?: never
|
|
33
|
+
document?: never
|
|
34
|
+
href: ComponentProps<typeof Link>["href"]
|
|
36
35
|
}
|
|
37
|
-
)
|
|
36
|
+
)
|
|
38
37
|
|
|
39
|
-
export const PrismicNextLink = forwardRef<
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
rel: typeof restProps.rel === "function" ? restProps.rel : undefined,
|
|
51
|
-
});
|
|
38
|
+
export const PrismicNextLink = forwardRef<HTMLAnchorElement, PrismicNextLinkProps>(
|
|
39
|
+
function PrismicNextLink(props, ref) {
|
|
40
|
+
const { field, document, linkResolver, children, ...restProps } = props
|
|
41
|
+
const {
|
|
42
|
+
href: computedHref,
|
|
43
|
+
rel: computedRel,
|
|
44
|
+
...attrs
|
|
45
|
+
} = asLinkAttrs(field ?? document, {
|
|
46
|
+
linkResolver,
|
|
47
|
+
rel: typeof restProps.rel === "function" ? restProps.rel : undefined,
|
|
48
|
+
})
|
|
52
49
|
|
|
53
|
-
|
|
50
|
+
const href = ("href" in restProps ? restProps.href : computedHref) || ""
|
|
54
51
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
let rel = computedRel
|
|
53
|
+
if ("rel" in restProps && typeof restProps.rel !== "function") {
|
|
54
|
+
rel = restProps.rel
|
|
55
|
+
}
|
|
59
56
|
|
|
60
|
-
|
|
57
|
+
const ResolvedLink = resolveDefaultExport(Link)
|
|
61
58
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
59
|
+
return (
|
|
60
|
+
<ResolvedLink ref={ref} {...attrs} {...restProps} href={href} rel={rel}>
|
|
61
|
+
{"children" in props ? children : field?.text}
|
|
62
|
+
</ResolvedLink>
|
|
63
|
+
)
|
|
64
|
+
},
|
|
65
|
+
)
|
package/src/PrismicPreview.tsx
CHANGED
|
@@ -1,55 +1,54 @@
|
|
|
1
|
-
import
|
|
2
|
-
import Script from "next/script"
|
|
3
|
-
import {
|
|
1
|
+
import { getToolbarSrc } from "@prismicio/client"
|
|
2
|
+
import Script from "next/script"
|
|
3
|
+
import type { FC, ReactNode } from "react"
|
|
4
4
|
|
|
5
|
-
import { resolveDefaultExport } from "./lib/resolveDefaultExport"
|
|
6
|
-
import { PrismicPreviewClient } from "./PrismicPreviewClient"
|
|
5
|
+
import { resolveDefaultExport } from "./lib/resolveDefaultExport"
|
|
6
|
+
import { PrismicPreviewClient } from "./PrismicPreviewClient"
|
|
7
7
|
|
|
8
8
|
/** Props for `<PrismicPreview>`. */
|
|
9
9
|
export type PrismicPreviewProps = {
|
|
10
10
|
/**
|
|
11
|
-
* The name of your Prismic repository. A Prismic Toolbar will be registered
|
|
12
|
-
*
|
|
11
|
+
* The name of your Prismic repository. A Prismic Toolbar will be registered using this
|
|
12
|
+
* repository.
|
|
13
13
|
*/
|
|
14
|
-
repositoryName: string
|
|
14
|
+
repositoryName: string
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* The URL of your app's Prismic preview endpoint (default: `/api/preview`).
|
|
18
|
-
*
|
|
17
|
+
* The URL of your app's Prismic preview endpoint (default: `/api/preview`). This URL will be
|
|
18
|
+
* fetched on preview update events.
|
|
19
19
|
*/
|
|
20
|
-
updatePreviewURL?: string
|
|
20
|
+
updatePreviewURL?: string
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
|
-
* The URL of your app's exit preview endpoint (default: `/api/exit-preview`).
|
|
24
|
-
*
|
|
23
|
+
* The URL of your app's exit preview endpoint (default: `/api/exit-preview`). This URL will be
|
|
24
|
+
* fetched on preview exit events.
|
|
25
25
|
*/
|
|
26
|
-
exitPreviewURL?: string
|
|
26
|
+
exitPreviewURL?: string
|
|
27
27
|
|
|
28
28
|
/** Children to render adjacent to the Prismic Toolbar. */
|
|
29
|
-
children?: ReactNode
|
|
30
|
-
}
|
|
29
|
+
children?: ReactNode
|
|
30
|
+
}
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
* React component that sets up Prismic Previews using the Prismic Toolbar. When
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* changes.
|
|
33
|
+
* React component that sets up Prismic Previews using the Prismic Toolbar. When the Prismic Toolbar
|
|
34
|
+
* send events to the browser, such as on preview updates and exiting, this component will
|
|
35
|
+
* automatically refresh the page with the changes.
|
|
37
36
|
*
|
|
38
|
-
* This component can be wrapped around your app or added anywhere in your app's
|
|
39
|
-
*
|
|
37
|
+
* This component can be wrapped around your app or added anywhere in your app's tree. It must be
|
|
38
|
+
* rendered on every page.
|
|
40
39
|
*/
|
|
41
40
|
export const PrismicPreview: FC<PrismicPreviewProps> = async (props) => {
|
|
42
|
-
const { repositoryName, children, ...otherProps } = props
|
|
41
|
+
const { repositoryName, children, ...otherProps } = props
|
|
43
42
|
|
|
44
43
|
// Need this to avoid the following Next.js build-time error:
|
|
45
44
|
// You're importing a component that needs next/headers. That only works
|
|
46
45
|
// in a Server Component which is not supported in the pages/ directory.
|
|
47
|
-
const { draftMode } = await import("next/headers")
|
|
46
|
+
const { draftMode } = await import("next/headers")
|
|
48
47
|
|
|
49
|
-
const toolbarSrc = getToolbarSrc(repositoryName)
|
|
50
|
-
const isDraftMode = (await draftMode()).isEnabled
|
|
48
|
+
const toolbarSrc = getToolbarSrc(repositoryName)
|
|
49
|
+
const isDraftMode = (await draftMode()).isEnabled
|
|
51
50
|
|
|
52
|
-
const ResolvedScript = resolveDefaultExport(Script)
|
|
51
|
+
const ResolvedScript = resolveDefaultExport(Script)
|
|
53
52
|
|
|
54
53
|
return (
|
|
55
54
|
<>
|
|
@@ -61,5 +60,5 @@ export const PrismicPreview: FC<PrismicPreviewProps> = async (props) => {
|
|
|
61
60
|
/>
|
|
62
61
|
<ResolvedScript src={toolbarSrc} strategy="lazyOnload" />
|
|
63
62
|
</>
|
|
64
|
-
)
|
|
65
|
-
}
|
|
63
|
+
)
|
|
64
|
+
}
|