@prismicio/next 0.1.5 → 0.1.6-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/dist/PrismicNextImage.cjs +59 -0
- package/dist/{PrismicNextImage.mjs.map → PrismicNextImage.cjs.map} +1 -1
- package/dist/PrismicNextImage.d.ts +48 -0
- package/dist/PrismicNextImage.js +38 -0
- package/dist/PrismicNextImage.js.map +1 -0
- package/dist/PrismicPreview.cjs +81 -0
- package/dist/{PrismicPreview.mjs.map → PrismicPreview.cjs.map} +1 -1
- package/dist/PrismicPreview.d.ts +42 -0
- package/dist/{PrismicPreview.mjs → PrismicPreview.js} +18 -44
- package/dist/PrismicPreview.js.map +1 -0
- package/dist/enableAutoPreviews.cjs +17 -0
- package/dist/{enableAutoPreviews.mjs.map → enableAutoPreviews.cjs.map} +1 -1
- package/dist/enableAutoPreviews.d.ts +38 -0
- package/dist/{enableAutoPreviews.mjs → enableAutoPreviews.js} +4 -3
- package/dist/enableAutoPreviews.js.map +1 -0
- package/dist/exitPreview.cjs +8 -0
- package/dist/{exitPreview.mjs.map → exitPreview.cjs.map} +1 -1
- package/dist/exitPreview.d.ts +34 -0
- package/dist/{exitPreview.mjs → exitPreview.js} +4 -3
- package/dist/exitPreview.js.map +1 -0
- package/dist/index.cjs +15 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +13 -273
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/__PRODUCTION__.cjs +5 -0
- package/dist/lib/{__PRODUCTION__.mjs.map → __PRODUCTION__.cjs.map} +1 -1
- package/dist/lib/__PRODUCTION__.d.ts +7 -0
- package/dist/lib/__PRODUCTION__.js +5 -0
- package/dist/lib/__PRODUCTION__.js.map +1 -0
- package/dist/lib/devMsg.cjs +8 -0
- package/dist/lib/{devMsg.mjs.map → devMsg.cjs.map} +1 -1
- package/dist/lib/devMsg.d.ts +16 -0
- package/dist/lib/devMsg.js +8 -0
- package/dist/lib/devMsg.js.map +1 -0
- package/dist/lib/getPreviewCookieRepositoryName.cjs +7 -0
- package/dist/lib/{getPreviewCookieRepositoryName.mjs.map → getPreviewCookieRepositoryName.cjs.map} +1 -1
- package/dist/lib/getPreviewCookieRepositoryName.d.ts +9 -0
- package/dist/lib/{getPreviewCookieRepositoryName.mjs → getPreviewCookieRepositoryName.js} +4 -3
- package/dist/lib/getPreviewCookieRepositoryName.js.map +1 -0
- package/dist/lib/getPrismicPreviewCookie.cjs +40 -0
- package/dist/lib/{getPrismicPreviewCookie.mjs.map → getPrismicPreviewCookie.cjs.map} +1 -1
- package/dist/lib/getPrismicPreviewCookie.d.ts +9 -0
- package/dist/lib/{getPrismicPreviewCookie.mjs → getPrismicPreviewCookie.js} +5 -5
- package/dist/lib/getPrismicPreviewCookie.js.map +1 -0
- package/dist/package.cjs +5 -0
- package/dist/package.cjs.map +1 -0
- package/dist/package.js +5 -0
- package/dist/package.js.map +1 -0
- package/dist/redirectToPreviewURL.cjs +22 -0
- package/dist/{redirectToPreviewURL.mjs.map → redirectToPreviewURL.cjs.map} +1 -1
- package/dist/redirectToPreviewURL.d.ts +59 -0
- package/dist/{redirectToPreviewURL.mjs → redirectToPreviewURL.js} +4 -3
- package/dist/redirectToPreviewURL.js.map +1 -0
- package/dist/setPreviewData.cjs +30 -0
- package/dist/{setPreviewData.mjs.map → setPreviewData.cjs.map} +1 -1
- package/dist/setPreviewData.d.ts +29 -0
- package/dist/{setPreviewData.mjs → setPreviewData.js} +5 -5
- package/dist/setPreviewData.js.map +1 -0
- package/dist/types.d.ts +21 -0
- package/package.json +12 -10
- package/dist/PrismicNextImage.mjs +0 -61
- package/dist/index.mjs +0 -7
- package/dist/index.mjs.map +0 -1
- package/dist/lib/__PRODUCTION__.mjs +0 -4
- package/dist/lib/devMsg.mjs +0 -8
- package/dist/package.mjs +0 -4
- package/dist/package.mjs.map +0 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { NextApiResponse, NextApiRequest } from "next";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for `exitPreview`.
|
|
4
|
+
*/
|
|
5
|
+
export declare type ExitPreviewConfig = {
|
|
6
|
+
/**
|
|
7
|
+
* The `req` object from a Next.js API route. This is given as a parameter to
|
|
8
|
+
* the API route.
|
|
9
|
+
*
|
|
10
|
+
* @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}
|
|
11
|
+
*/
|
|
12
|
+
req: {
|
|
13
|
+
headers: NextApiRequest["headers"];
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The `res` object from a Next.js API route. This is given as a parameter to
|
|
17
|
+
* the API route.
|
|
18
|
+
*
|
|
19
|
+
* @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}
|
|
20
|
+
*/
|
|
21
|
+
res: {
|
|
22
|
+
clearPreviewData: NextApiResponse["clearPreviewData"];
|
|
23
|
+
status: NextApiResponse["status"];
|
|
24
|
+
json: NextApiResponse["json"];
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated - This property is no longer used. It can be deleted safely.
|
|
28
|
+
*/
|
|
29
|
+
exitPreviewURL?: string;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Exits Next.js's Preview Mode from within a Next.js API route.
|
|
33
|
+
*/
|
|
34
|
+
export declare function exitPreview(config: ExitPreviewConfig): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exitPreview.js","sources":["../src/exitPreview.ts"],"sourcesContent":["import type { NextApiResponse, NextApiRequest } from \"next\";\n\n/**\n * Configuration for `exitPreview`.\n */\nexport type ExitPreviewConfig = {\n\t/**\n\t * The `req` object from a Next.js API route. This is given as a parameter to\n\t * the API route.\n\t *\n\t * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}\n\t */\n\t// `req` is no longer used in `exitPreview()`. It previously would\n\t// redirect the user to the referring URL, but it no longer has that\n\t// behavior.\n\t//\n\t// `req` is retained as a parameter to make setting up an exit preview\n\t// API route easier (this eliminates the awkward need to handle an\n\t// unused `req` param).\n\t//\n\t// It is also retained in case it is needed in the future, such as\n\t// reading headers or metadata about the request.\n\treq: {\n\t\theaders: NextApiRequest[\"headers\"];\n\t};\n\n\t/**\n\t * The `res` object from a Next.js API route. This is given as a parameter to\n\t * the API route.\n\t *\n\t * @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}\n\t */\n\tres: {\n\t\tclearPreviewData: NextApiResponse[\"clearPreviewData\"];\n\t\tstatus: NextApiResponse[\"status\"];\n\t\tjson: NextApiResponse[\"json\"];\n\t};\n\n\t/**\n\t * @deprecated - This property is no longer used. It can be deleted safely.\n\t */\n\texitPreviewURL?: string;\n};\n\n/**\n * Exits Next.js's Preview Mode from within a Next.js API route.\n */\nexport function exitPreview(config: ExitPreviewConfig): void {\n\t// Exit the current user from Preview Mode.\n\tconfig.res.clearPreviewData();\n\n\t// 205 status is used to prevent CDN-level caching. The default 200\n\t// status code is typically treated as non-changing and cacheable.\n\tconfig.res.status(205).json({ success: true });\n}\n"],"names":[],"mappings":"AA+CM,SAAU,YAAY,QAAyB;AAEpD,SAAO,IAAI;AAIJ,SAAA,IAAI,OAAO,GAAG,EAAE,KAAK,EAAE,SAAS,MAAM;AAC9C;"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const setPreviewData = require("./setPreviewData.cjs");
|
|
4
|
+
const exitPreview = require("./exitPreview.cjs");
|
|
5
|
+
const PrismicPreview = require("./PrismicPreview.cjs");
|
|
6
|
+
const enableAutoPreviews = require("./enableAutoPreviews.cjs");
|
|
7
|
+
const redirectToPreviewURL = require("./redirectToPreviewURL.cjs");
|
|
8
|
+
const PrismicNextImage = require("./PrismicNextImage.cjs");
|
|
9
|
+
exports.setPreviewData = setPreviewData.setPreviewData;
|
|
10
|
+
exports.exitPreview = exitPreview.exitPreview;
|
|
11
|
+
exports.PrismicPreview = PrismicPreview.PrismicPreview;
|
|
12
|
+
exports.enableAutoPreviews = enableAutoPreviews.enableAutoPreviews;
|
|
13
|
+
exports.redirectToPreviewURL = redirectToPreviewURL.redirectToPreviewURL;
|
|
14
|
+
exports.PrismicNextImage = PrismicNextImage.PrismicNextImage;
|
|
15
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,273 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* The `req` object from a Next.js API route. This is given as a parameter to
|
|
15
|
-
* the API route.
|
|
16
|
-
*
|
|
17
|
-
* @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}
|
|
18
|
-
*/
|
|
19
|
-
req: {
|
|
20
|
-
query: NextApiRequest["query"];
|
|
21
|
-
cookies: NextApiRequest["cookies"];
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* The `res` object from a Next.js API route. This is given as a parameter to
|
|
25
|
-
* the API route.
|
|
26
|
-
*
|
|
27
|
-
* @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}
|
|
28
|
-
*/
|
|
29
|
-
res: {
|
|
30
|
-
setPreviewData: NextApiResponse["setPreviewData"];
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* Set Prismic preview data for Next.js's Preview Mode.
|
|
35
|
-
*/
|
|
36
|
-
declare function setPreviewData({ req, res }: SetPreviewDataConfig): void;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Configuration for `exitPreview`.
|
|
40
|
-
*/
|
|
41
|
-
declare type ExitPreviewConfig = {
|
|
42
|
-
/**
|
|
43
|
-
* The `req` object from a Next.js API route. This is given as a parameter to
|
|
44
|
-
* the API route.
|
|
45
|
-
*
|
|
46
|
-
* @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}
|
|
47
|
-
*/
|
|
48
|
-
req: {
|
|
49
|
-
headers: NextApiRequest["headers"];
|
|
50
|
-
};
|
|
51
|
-
/**
|
|
52
|
-
* The `res` object from a Next.js API route. This is given as a parameter to
|
|
53
|
-
* the API route.
|
|
54
|
-
*
|
|
55
|
-
* @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}
|
|
56
|
-
*/
|
|
57
|
-
res: {
|
|
58
|
-
clearPreviewData: NextApiResponse["clearPreviewData"];
|
|
59
|
-
status: NextApiResponse["status"];
|
|
60
|
-
json: NextApiResponse["json"];
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* @deprecated - This property is no longer used. It can be deleted safely.
|
|
64
|
-
*/
|
|
65
|
-
exitPreviewURL?: string;
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* Exits Next.js's Preview Mode from within a Next.js API route.
|
|
69
|
-
*/
|
|
70
|
-
declare function exitPreview(config: ExitPreviewConfig): void;
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Props for `<PrismicPreview>`.
|
|
74
|
-
*/
|
|
75
|
-
declare type PrismicPreviewProps = {
|
|
76
|
-
/**
|
|
77
|
-
* The name of your Prismic repository. A Prismic Toolbar will be registered
|
|
78
|
-
* using this repository.
|
|
79
|
-
*/
|
|
80
|
-
repositoryName: string;
|
|
81
|
-
/**
|
|
82
|
-
* The URL of your app's Prismic preview endpoint (default: `/api/preview`).
|
|
83
|
-
* This URL will be fetched on preview update events.
|
|
84
|
-
*
|
|
85
|
-
* **Note**: If your `next.config.js` file contains a `basePath`, it is
|
|
86
|
-
* automatically included.
|
|
87
|
-
*/
|
|
88
|
-
updatePreviewURL?: string;
|
|
89
|
-
/**
|
|
90
|
-
* The URL of your app's exit preview endpoint (default: `/api/exit-preview`).
|
|
91
|
-
* This URL will be fetched on preview exit events.
|
|
92
|
-
*
|
|
93
|
-
* **Note**: If your `next.config.js` file contains a `basePath`, it is
|
|
94
|
-
* automatically included.
|
|
95
|
-
*/
|
|
96
|
-
exitPreviewURL?: string;
|
|
97
|
-
/**
|
|
98
|
-
* Children to render adjacent to the Prismic Toolbar. The Prismic Toolbar
|
|
99
|
-
* will be rendered last.
|
|
100
|
-
*/
|
|
101
|
-
children?: React.ReactNode;
|
|
102
|
-
};
|
|
103
|
-
/**
|
|
104
|
-
* React component that sets up Prismic Previews using the Prismic Toolbar. When
|
|
105
|
-
* the Prismic Toolbar send events to the browser, such as on preview updates
|
|
106
|
-
* and exiting, this component will automatically update the Next.js preview
|
|
107
|
-
* cookie and refresh the page.
|
|
108
|
-
*
|
|
109
|
-
* This component can be wrapped around your app or added anywhere in your app's
|
|
110
|
-
* tree. It must be rendered on every page.
|
|
111
|
-
*/
|
|
112
|
-
declare function PrismicPreview({ repositoryName, children, updatePreviewURL, exitPreviewURL, }: PrismicPreviewProps): JSX.Element;
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Configuration for `enableAutoPreviews`.
|
|
116
|
-
*
|
|
117
|
-
* @typeParam TPreviewData - Next.js preview data object.
|
|
118
|
-
*/
|
|
119
|
-
declare type EnableAutoPreviewsConfig<TPreviewData extends PreviewData = PreviewData> = {
|
|
120
|
-
/**
|
|
121
|
-
* Prismic client with which automatic previews will be enabled.
|
|
122
|
-
*/
|
|
123
|
-
client: Client;
|
|
124
|
-
} & ({
|
|
125
|
-
/**
|
|
126
|
-
* A Next.js context object (such as the context object from
|
|
127
|
-
* `getStaticProps` or `getServerSideProps`).
|
|
128
|
-
*
|
|
129
|
-
* Pass a `context` object when using `enableAutoPreviews` outside a
|
|
130
|
-
* Next.js API endpoint.
|
|
131
|
-
*/
|
|
132
|
-
previewData?: TPreviewData;
|
|
133
|
-
} | {
|
|
134
|
-
/**
|
|
135
|
-
* A Next.js API endpoint request object.
|
|
136
|
-
*
|
|
137
|
-
* Pass a `req` object when using `enableAutoPreviews` in a Next.js API
|
|
138
|
-
* endpoint.
|
|
139
|
-
*/
|
|
140
|
-
req?: HttpRequestLike;
|
|
141
|
-
});
|
|
142
|
-
/**
|
|
143
|
-
* Configures a Prismic client to automatically query draft content during a
|
|
144
|
-
* preview session. It either takes in a Next.js `getStaticProps` context object
|
|
145
|
-
* or a Next.js API endpoint request object.
|
|
146
|
-
*
|
|
147
|
-
* @param config - Configuration for the function.
|
|
148
|
-
*/
|
|
149
|
-
declare const enableAutoPreviews: <TPreviewData extends PreviewData>(config: EnableAutoPreviewsConfig<TPreviewData>) => void;
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Preview config for enabling previews with redirectToPreviewURL
|
|
153
|
-
*/
|
|
154
|
-
declare type RedirectToPreviewURLConfig<TLinkResolverFunction extends LinkResolverFunction<any> = LinkResolverFunction> = {
|
|
155
|
-
/**
|
|
156
|
-
* The `req` object from a Next.js API route. This is given as a parameter to
|
|
157
|
-
* the API route.
|
|
158
|
-
*
|
|
159
|
-
* @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}
|
|
160
|
-
*/
|
|
161
|
-
req: {
|
|
162
|
-
query: NextApiRequest["query"];
|
|
163
|
-
};
|
|
164
|
-
/**
|
|
165
|
-
* The `res` object from a Next.js API route. This is given as a parameter to
|
|
166
|
-
* the API route.
|
|
167
|
-
*
|
|
168
|
-
* @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}
|
|
169
|
-
*/
|
|
170
|
-
res: {
|
|
171
|
-
redirect: NextApiResponse["redirect"];
|
|
172
|
-
};
|
|
173
|
-
/**
|
|
174
|
-
* The Prismic client configured for the preview session's repository.
|
|
175
|
-
*/
|
|
176
|
-
client: Client;
|
|
177
|
-
/**
|
|
178
|
-
* A Link Resolver used to resolve the previewed document's URL.
|
|
179
|
-
*
|
|
180
|
-
* @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}
|
|
181
|
-
*/
|
|
182
|
-
linkResolver?: TLinkResolverFunction;
|
|
183
|
-
/**
|
|
184
|
-
* The default redirect URL if a URL cannot be determined for the previewed
|
|
185
|
-
* document.
|
|
186
|
-
*
|
|
187
|
-
* **Note**: If you `next.config.js` file contains a `basePath`, the
|
|
188
|
-
* `defaultURL` option must _not_ include it. Instead, provide the `basePath`
|
|
189
|
-
* property using the `basePath` option.
|
|
190
|
-
*/
|
|
191
|
-
defaultURL?: string;
|
|
192
|
-
/**
|
|
193
|
-
* The `basePath` for the Next.js app as it is defined in `next.config.js`.
|
|
194
|
-
* This option can be omitted if the app does not have a `basePath`.
|
|
195
|
-
*
|
|
196
|
-
* @remarks
|
|
197
|
-
* The API route is unable to detect the app's `basePath` automatically. It
|
|
198
|
-
* must be provided to `redirectToPreviewURL()` manually.
|
|
199
|
-
*/
|
|
200
|
-
basePath?: string;
|
|
201
|
-
};
|
|
202
|
-
/**
|
|
203
|
-
* Redirects a user to the URL of a previewed Prismic document from within a
|
|
204
|
-
* Next.js API route.
|
|
205
|
-
*/
|
|
206
|
-
declare function redirectToPreviewURL<TLinkResolverFunction extends LinkResolverFunction<any>>(config: RedirectToPreviewURLConfig<TLinkResolverFunction>): Promise<void>;
|
|
207
|
-
|
|
208
|
-
declare type PrismicNextImageProps = Omit<ImageProps, "src" | "alt" | "width" | "height"> & {
|
|
209
|
-
/**
|
|
210
|
-
* The Prismic Image field or thumbnail to render.
|
|
211
|
-
*/
|
|
212
|
-
field: prismicT.ImageFieldImage | null | undefined;
|
|
213
|
-
/**
|
|
214
|
-
* An object of Imgix URL API parameters to transform the image.
|
|
215
|
-
*
|
|
216
|
-
* @see https://docs.imgix.com/apis/rendering
|
|
217
|
-
*/
|
|
218
|
-
imgixParams?: ImgixURLParams;
|
|
219
|
-
/**
|
|
220
|
-
* Declare an image as decorative by providing `alt=""`.
|
|
221
|
-
*
|
|
222
|
-
* See:
|
|
223
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
224
|
-
*/
|
|
225
|
-
alt?: "";
|
|
226
|
-
/**
|
|
227
|
-
* Declare an image as decorative only if the Image field does not have
|
|
228
|
-
* alternative text by providing `fallbackAlt=""`.
|
|
229
|
-
*
|
|
230
|
-
* See:
|
|
231
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
232
|
-
*/
|
|
233
|
-
fallbackAlt?: "";
|
|
234
|
-
};
|
|
235
|
-
/**
|
|
236
|
-
* React component that renders an image from a Prismic Image field or one of
|
|
237
|
-
* its thumbnails using `next/image`. It will automatically set the `alt`
|
|
238
|
-
* attribute using the Image field's `alt` property.
|
|
239
|
-
*
|
|
240
|
-
* It uses an Imgix URL-based loader by default. A custom loader can be provided
|
|
241
|
-
* with the `loader` prop. If you would like to use the Next.js Image
|
|
242
|
-
* Optimization API instead, set `loader={undefined}`.
|
|
243
|
-
*
|
|
244
|
-
* @param props - Props for the component.
|
|
245
|
-
*
|
|
246
|
-
* @returns A responsive image component using `next/image` for the given Image
|
|
247
|
-
* field.
|
|
248
|
-
*
|
|
249
|
-
* @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image
|
|
250
|
-
*/
|
|
251
|
-
declare const PrismicNextImage: ({ field, imgixParams, alt, fallbackAlt, layout, ...restProps }: PrismicNextImageProps) => JSX.Element | null;
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Configuration for creating a Prismic client with automatic preview support in
|
|
255
|
-
* Next.js apps.
|
|
256
|
-
*/
|
|
257
|
-
declare type CreateClientConfig = {
|
|
258
|
-
/**
|
|
259
|
-
* Preview data coming from Next.js context object. This context object comes
|
|
260
|
-
* from `getStaticProps` or `getServerSideProps`.
|
|
261
|
-
*
|
|
262
|
-
* Pass `previewData` when using outside a Next.js API endpoint.
|
|
263
|
-
*/
|
|
264
|
-
previewData?: PreviewData;
|
|
265
|
-
/**
|
|
266
|
-
* A Next.js API endpoint request object.
|
|
267
|
-
*
|
|
268
|
-
* Pass a `req` object when using in a Next.js API endpoint.
|
|
269
|
-
*/
|
|
270
|
-
req?: NextApiRequest;
|
|
271
|
-
} & ClientConfig;
|
|
272
|
-
|
|
273
|
-
export { CreateClientConfig, EnableAutoPreviewsConfig, ExitPreviewConfig, PrismicNextImage, PrismicNextImageProps, PrismicPreview, PrismicPreviewProps, RedirectToPreviewURLConfig, SetPreviewDataConfig, enableAutoPreviews, exitPreview, redirectToPreviewURL, setPreviewData };
|
|
1
|
+
export { setPreviewData } from "./setPreviewData";
|
|
2
|
+
export type { SetPreviewDataConfig } from "./setPreviewData";
|
|
3
|
+
export { exitPreview } from "./exitPreview";
|
|
4
|
+
export type { ExitPreviewConfig } from "./exitPreview";
|
|
5
|
+
export { PrismicPreview } from "./PrismicPreview";
|
|
6
|
+
export type { PrismicPreviewProps } from "./PrismicPreview";
|
|
7
|
+
export { enableAutoPreviews } from "./enableAutoPreviews";
|
|
8
|
+
export type { EnableAutoPreviewsConfig } from "./enableAutoPreviews";
|
|
9
|
+
export { redirectToPreviewURL } from "./redirectToPreviewURL";
|
|
10
|
+
export type { RedirectToPreviewURLConfig } from "./redirectToPreviewURL";
|
|
11
|
+
export { PrismicNextImage } from "./PrismicNextImage";
|
|
12
|
+
export type { PrismicNextImageProps } from "./PrismicNextImage";
|
|
13
|
+
export type { CreateClientConfig } from "./types";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { setPreviewData } from "./setPreviewData.js";
|
|
2
|
+
import { exitPreview } from "./exitPreview.js";
|
|
3
|
+
import { PrismicPreview } from "./PrismicPreview.js";
|
|
4
|
+
import { enableAutoPreviews } from "./enableAutoPreviews.js";
|
|
5
|
+
import { redirectToPreviewURL } from "./redirectToPreviewURL.js";
|
|
6
|
+
import { PrismicNextImage } from "./PrismicNextImage.js";
|
|
7
|
+
export {
|
|
8
|
+
PrismicNextImage,
|
|
9
|
+
PrismicPreview,
|
|
10
|
+
enableAutoPreviews,
|
|
11
|
+
exitPreview,
|
|
12
|
+
redirectToPreviewURL,
|
|
13
|
+
setPreviewData
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const __PRODUCTION__ = process.env.NODE_ENV === "production";
|
|
4
|
+
exports.__PRODUCTION__ = __PRODUCTION__;
|
|
5
|
+
//# sourceMappingURL=__PRODUCTION__.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"__PRODUCTION__.
|
|
1
|
+
{"version":3,"file":"__PRODUCTION__.cjs","sources":["../../src/lib/__PRODUCTION__.ts"],"sourcesContent":["/**\n * `true` if in the production environment, `false` otherwise.\n *\n * This boolean can be used to perform actions only in development environments,\n * such as logging.\n */\nexport const __PRODUCTION__ = process.env.NODE_ENV === \"production\";\n"],"names":[],"mappings":";;AAMa,MAAA,iBAAiB,QAAQ,IAAI,aAAa;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"__PRODUCTION__.js","sources":["../../src/lib/__PRODUCTION__.ts"],"sourcesContent":["/**\n * `true` if in the production environment, `false` otherwise.\n *\n * This boolean can be used to perform actions only in development environments,\n * such as logging.\n */\nexport const __PRODUCTION__ = process.env.NODE_ENV === \"production\";\n"],"names":[],"mappings":"AAMa,MAAA,iBAAiB,QAAQ,IAAI,aAAa;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const _package = require("../package.cjs");
|
|
4
|
+
const devMsg = (slug) => {
|
|
5
|
+
return `https://prismic.dev/msg/next/v${_package.version}/${slug}`;
|
|
6
|
+
};
|
|
7
|
+
exports.devMsg = devMsg;
|
|
8
|
+
//# sourceMappingURL=devMsg.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devMsg.
|
|
1
|
+
{"version":3,"file":"devMsg.cjs","sources":["../../src/lib/devMsg.ts"],"sourcesContent":["import { version } from \"../../package.json\";\n\n/**\n * Returns a `prismic.dev/msg` URL for a given message slug.\n *\n * @example\n *\n * ```ts\n * devMsg(\"missing-param\");\n * // => \"https://prismic.dev/msg/next/v1.2.3/missing-param.md\"\n * ```\n *\n * @param slug - Slug for the message. This corresponds to a Markdown file in\n * the Git repository's `/messages` directory.\n *\n * @returns The `prismic.dev/msg` URL for the given slug.\n */\nexport const devMsg = (slug: string) => {\n\treturn `https://prismic.dev/msg/next/v${version}/${slug}`;\n};\n"],"names":["version"],"mappings":";;;AAiBa,MAAA,SAAS,CAAC,SAAgB;AACtC,SAAO,iCAAiCA,SAAAA,WAAW;AACpD;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a `prismic.dev/msg` URL for a given message slug.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* devMsg("missing-param");
|
|
8
|
+
* // => "https://prismic.dev/msg/next/v1.2.3/missing-param.md"
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* @param slug - Slug for the message. This corresponds to a Markdown file in
|
|
12
|
+
* the Git repository's `/messages` directory.
|
|
13
|
+
*
|
|
14
|
+
* @returns The `prismic.dev/msg` URL for the given slug.
|
|
15
|
+
*/
|
|
16
|
+
export declare const devMsg: (slug: string) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devMsg.js","sources":["../../src/lib/devMsg.ts"],"sourcesContent":["import { version } from \"../../package.json\";\n\n/**\n * Returns a `prismic.dev/msg` URL for a given message slug.\n *\n * @example\n *\n * ```ts\n * devMsg(\"missing-param\");\n * // => \"https://prismic.dev/msg/next/v1.2.3/missing-param.md\"\n * ```\n *\n * @param slug - Slug for the message. This corresponds to a Markdown file in\n * the Git repository's `/messages` directory.\n *\n * @returns The `prismic.dev/msg` URL for the given slug.\n */\nexport const devMsg = (slug: string) => {\n\treturn `https://prismic.dev/msg/next/v${version}/${slug}`;\n};\n"],"names":[],"mappings":";AAiBa,MAAA,SAAS,CAAC,SAAgB;AACtC,SAAO,iCAAiC,WAAW;AACpD;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const getPreviewCookieRepositoryName = (previewCookie) => {
|
|
4
|
+
return (decodeURIComponent(previewCookie).match(/"(.+).prismic.io"/) || [])[1];
|
|
5
|
+
};
|
|
6
|
+
exports.getPreviewCookieRepositoryName = getPreviewCookieRepositoryName;
|
|
7
|
+
//# sourceMappingURL=getPreviewCookieRepositoryName.cjs.map
|
package/dist/lib/{getPreviewCookieRepositoryName.mjs.map → getPreviewCookieRepositoryName.cjs.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPreviewCookieRepositoryName.
|
|
1
|
+
{"version":3,"file":"getPreviewCookieRepositoryName.cjs","sources":["../../src/lib/getPreviewCookieRepositoryName.ts"],"sourcesContent":["/**\n * Extracts preview reference repo name from stringified Prismic preview cookie\n *\n * @param previewCookie - The Prismic preview cookie.\n *\n * @returns The repository name for the Prismic preview cookie. If the cookie\n * represents an inactive preview session, `undefined` will be returned.\n */\nexport const getPreviewCookieRepositoryName = (\n\tpreviewCookie: string,\n): string | undefined => {\n\treturn (decodeURIComponent(previewCookie).match(/\"(.+).prismic.io\"/) ||\n\t\t[])[1];\n};\n"],"names":[],"mappings":";;AAQa,MAAA,iCAAiC,CAC7C,kBACuB;AACvB,UAAQ,mBAAmB,aAAa,EAAE,MAAM,mBAAmB,KAClE,CAAA,GAAI;AACN;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts preview reference repo name from stringified Prismic preview cookie
|
|
3
|
+
*
|
|
4
|
+
* @param previewCookie - The Prismic preview cookie.
|
|
5
|
+
*
|
|
6
|
+
* @returns The repository name for the Prismic preview cookie. If the cookie
|
|
7
|
+
* represents an inactive preview session, `undefined` will be returned.
|
|
8
|
+
*/
|
|
9
|
+
export declare const getPreviewCookieRepositoryName: (previewCookie: string) => string | undefined;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const getPreviewCookieRepositoryName = (previewCookie) => {
|
|
2
2
|
return (decodeURIComponent(previewCookie).match(/"(.+).prismic.io"/) || [])[1];
|
|
3
3
|
};
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export {
|
|
5
|
+
getPreviewCookieRepositoryName
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=getPreviewCookieRepositoryName.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPreviewCookieRepositoryName.js","sources":["../../src/lib/getPreviewCookieRepositoryName.ts"],"sourcesContent":["/**\n * Extracts preview reference repo name from stringified Prismic preview cookie\n *\n * @param previewCookie - The Prismic preview cookie.\n *\n * @returns The repository name for the Prismic preview cookie. If the cookie\n * represents an inactive preview session, `undefined` will be returned.\n */\nexport const getPreviewCookieRepositoryName = (\n\tpreviewCookie: string,\n): string | undefined => {\n\treturn (decodeURIComponent(previewCookie).match(/\"(.+).prismic.io\"/) ||\n\t\t[])[1];\n};\n"],"names":[],"mappings":"AAQa,MAAA,iCAAiC,CAC7C,kBACuB;AACvB,UAAQ,mBAAmB,aAAa,EAAE,MAAM,mBAAmB,KAClE,CAAA,GAAI;AACN;"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const prismic = require("@prismicio/client");
|
|
4
|
+
function _interopNamespace(e) {
|
|
5
|
+
if (e && e.__esModule)
|
|
6
|
+
return e;
|
|
7
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
8
|
+
if (e) {
|
|
9
|
+
for (const k in e) {
|
|
10
|
+
if (k !== "default") {
|
|
11
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: () => e[k]
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
n.default = e;
|
|
20
|
+
return Object.freeze(n);
|
|
21
|
+
}
|
|
22
|
+
const prismic__namespace = /* @__PURE__ */ _interopNamespace(prismic);
|
|
23
|
+
const readValue = (value) => {
|
|
24
|
+
return value.replace(/%3B/g, ";");
|
|
25
|
+
};
|
|
26
|
+
const getPrismicPreviewCookie = (cookieJar) => {
|
|
27
|
+
const cookies = cookieJar.split("; ");
|
|
28
|
+
let value;
|
|
29
|
+
for (const cookie of cookies) {
|
|
30
|
+
const parts = cookie.split("=");
|
|
31
|
+
const name = readValue(parts[0]).replace(/%3D/g, "=");
|
|
32
|
+
if (name === prismic__namespace.cookie.preview) {
|
|
33
|
+
value = readValue(parts.slice(1).join("="));
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return value;
|
|
38
|
+
};
|
|
39
|
+
exports.getPrismicPreviewCookie = getPrismicPreviewCookie;
|
|
40
|
+
//# sourceMappingURL=getPrismicPreviewCookie.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPrismicPreviewCookie.
|
|
1
|
+
{"version":3,"file":"getPrismicPreviewCookie.cjs","sources":["../../src/lib/getPrismicPreviewCookie.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\n\nconst readValue = (value: string): string => {\n\treturn value.replace(/%3B/g, \";\");\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 */\nexport const getPrismicPreviewCookie = (\n\tcookieJar: string,\n): string | undefined => {\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 === prismic.cookie.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"],"names":["prismic"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAEA,MAAM,YAAY,CAAC,UAAyB;AACpC,SAAA,MAAM,QAAQ,QAAQ,GAAG;AACjC;AAUa,MAAA,0BAA0B,CACtC,cACuB;AACjB,QAAA,UAAU,UAAU,MAAM,IAAI;AAEhC,MAAA;AAEJ,aAAW,UAAU,SAAS;AACvB,UAAA,QAAQ,OAAO,MAAM,GAAG;AAC9B,UAAM,OAAO,UAAU,MAAM,EAAE,EAAE,QAAQ,QAAQ,GAAG;AAEhD,QAAA,SAASA,mBAAQ,OAAO,SAAS;AACpC,cAAQ,UAAU,MAAM,MAAM,CAAC,EAAE,KAAK,GAAG,CAAC;AAC1C;AAAA,IACA;AAAA,EACD;AAEM,SAAA;AACR;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the value of a cookie from a given cookie store.
|
|
3
|
+
*
|
|
4
|
+
* @param cookieJar - The stringified cookie store from which to read the
|
|
5
|
+
* cookie.
|
|
6
|
+
*
|
|
7
|
+
* @returns The value of the cookie, if it exists.
|
|
8
|
+
*/
|
|
9
|
+
export declare const getPrismicPreviewCookie: (cookieJar: string) => string | undefined;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import * as prismic from
|
|
2
|
-
|
|
1
|
+
import * as prismic from "@prismicio/client";
|
|
3
2
|
const readValue = (value) => {
|
|
4
3
|
return value.replace(/%3B/g, ";");
|
|
5
4
|
};
|
|
@@ -16,6 +15,7 @@ const getPrismicPreviewCookie = (cookieJar) => {
|
|
|
16
15
|
}
|
|
17
16
|
return value;
|
|
18
17
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
export {
|
|
19
|
+
getPrismicPreviewCookie
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=getPrismicPreviewCookie.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPrismicPreviewCookie.js","sources":["../../src/lib/getPrismicPreviewCookie.ts"],"sourcesContent":["import * as prismic from \"@prismicio/client\";\n\nconst readValue = (value: string): string => {\n\treturn value.replace(/%3B/g, \";\");\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 */\nexport const getPrismicPreviewCookie = (\n\tcookieJar: string,\n): string | undefined => {\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 === prismic.cookie.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"],"names":[],"mappings":";AAEA,MAAM,YAAY,CAAC,UAAyB;AACpC,SAAA,MAAM,QAAQ,QAAQ,GAAG;AACjC;AAUa,MAAA,0BAA0B,CACtC,cACuB;AACjB,QAAA,UAAU,UAAU,MAAM,IAAI;AAEhC,MAAA;AAEJ,aAAW,UAAU,SAAS;AACvB,UAAA,QAAQ,OAAO,MAAM,GAAG;AAC9B,UAAM,OAAO,UAAU,MAAM,EAAE,EAAE,QAAQ,QAAQ,GAAG;AAEhD,QAAA,SAAS,QAAQ,OAAO,SAAS;AACpC,cAAQ,UAAU,MAAM,MAAM,CAAC,EAAE,KAAK,GAAG,CAAC;AAC1C;AAAA,IACA;AAAA,EACD;AAEM,SAAA;AACR;"}
|
package/dist/package.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|
package/dist/package.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"package.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const isPrismicNextQuery = (query) => {
|
|
4
|
+
return typeof query.documentId === "string" && typeof query.token === "string";
|
|
5
|
+
};
|
|
6
|
+
async function redirectToPreviewURL(config) {
|
|
7
|
+
const defaultURL = config.defaultURL || "/";
|
|
8
|
+
const basePath = config.basePath || "";
|
|
9
|
+
if (isPrismicNextQuery(config.req.query)) {
|
|
10
|
+
const previewUrl = await config.client.resolvePreviewURL({
|
|
11
|
+
linkResolver: config.linkResolver,
|
|
12
|
+
defaultURL,
|
|
13
|
+
documentID: config.req.query.documentId,
|
|
14
|
+
previewToken: config.req.query.token
|
|
15
|
+
});
|
|
16
|
+
config.res.redirect(basePath + previewUrl);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
config.res.redirect(basePath + defaultURL);
|
|
20
|
+
}
|
|
21
|
+
exports.redirectToPreviewURL = redirectToPreviewURL;
|
|
22
|
+
//# sourceMappingURL=redirectToPreviewURL.cjs.map
|