@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redirectToPreviewURL.
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.cjs","sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import type { Client } from \"@prismicio/client\";\nimport type { NextApiRequest, NextApiResponse } from \"next\";\nimport type { LinkResolverFunction } from \"@prismicio/helpers\";\n\ntype PrismicNextQuery = {\n\tdocumentId: string;\n\ttoken: string;\n};\n\n/**\n * Determines if a query object from a Next.js API route request contains\n * Prismic preview data.\n *\n * @param query - Query object to check.\n *\n * @returns `true` if `query` contains Prismic preview data, `false` otherwise.\n */\nconst isPrismicNextQuery = (\n\tquery: NextApiRequest[\"query\"],\n): query is PrismicNextQuery => {\n\treturn (\n\t\ttypeof query.documentId === \"string\" && typeof query.token === \"string\"\n\t);\n};\n\n/**\n * Preview config for enabling previews with redirectToPreviewURL\n */\nexport type RedirectToPreviewURLConfig<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTLinkResolverFunction extends LinkResolverFunction<any> = LinkResolverFunction,\n> = {\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\treq: {\n\t\tquery: NextApiRequest[\"query\"];\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\tredirect: NextApiResponse[\"redirect\"];\n\t};\n\n\t/**\n\t * The Prismic client configured for the preview session's repository.\n\t */\n\tclient: Client;\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: TLinkResolverFunction;\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed\n\t * document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the\n\t * `defaultURL` option must _not_ include it. Instead, provide the `basePath`\n\t * property using the `basePath` option.\n\t */\n\tdefaultURL?: string;\n\n\t/**\n\t * The `basePath` for the Next.js app as it is defined in `next.config.js`.\n\t * This option can be omitted if the app does not have a `basePath`.\n\t *\n\t * @remarks\n\t * The API route is unable to detect the app's `basePath` automatically. It\n\t * must be provided to `redirectToPreviewURL()` manually.\n\t */\n\tbasePath?: string;\n};\n\n/**\n * Redirects a user to the URL of a previewed Prismic document from within a\n * Next.js API route.\n */\nexport async function redirectToPreviewURL<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTLinkResolverFunction extends LinkResolverFunction<any>,\n>(config: RedirectToPreviewURLConfig<TLinkResolverFunction>): Promise<void> {\n\tconst defaultURL = config.defaultURL || \"/\";\n\tconst basePath = config.basePath || \"\";\n\n\tif (isPrismicNextQuery(config.req.query)) {\n\t\tconst previewUrl = await config.client.resolvePreviewURL({\n\t\t\tlinkResolver: config.linkResolver,\n\t\t\tdefaultURL,\n\t\t\tdocumentID: config.req.query.documentId,\n\t\t\tpreviewToken: config.req.query.token,\n\t\t});\n\n\t\tconfig.res.redirect(basePath + previewUrl);\n\n\t\treturn;\n\t}\n\n\tconfig.res.redirect(basePath + defaultURL);\n}\n"],"names":[],"mappings":";;AAiBA,MAAM,qBAAqB,CAC1B,UAC8B;AAC9B,SACC,OAAO,MAAM,eAAe,YAAY,OAAO,MAAM,UAAU;AAEjE;AAkEA,eAAsB,qBAGpB,QAAyD;AACpD,QAAA,aAAa,OAAO,cAAc;AAClC,QAAA,WAAW,OAAO,YAAY;AAEpC,MAAI,mBAAmB,OAAO,IAAI,KAAK,GAAG;AACzC,UAAM,aAAa,MAAM,OAAO,OAAO,kBAAkB;AAAA,MACxD,cAAc,OAAO;AAAA,MACrB;AAAA,MACA,YAAY,OAAO,IAAI,MAAM;AAAA,MAC7B,cAAc,OAAO,IAAI,MAAM;AAAA,IAAA,CAC/B;AAEM,WAAA,IAAI,SAAS,WAAW,UAAU;AAEzC;AAAA,EACA;AAEM,SAAA,IAAI,SAAS,WAAW,UAAU;AAC1C;;"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { Client } from "@prismicio/client";
|
|
2
|
+
import type { NextApiRequest, NextApiResponse } from "next";
|
|
3
|
+
import type { LinkResolverFunction } from "@prismicio/helpers";
|
|
4
|
+
/**
|
|
5
|
+
* Preview config for enabling previews with redirectToPreviewURL
|
|
6
|
+
*/
|
|
7
|
+
export declare type RedirectToPreviewURLConfig<TLinkResolverFunction extends LinkResolverFunction<any> = LinkResolverFunction> = {
|
|
8
|
+
/**
|
|
9
|
+
* The `req` object from a Next.js API route. This is given as a parameter to
|
|
10
|
+
* the API route.
|
|
11
|
+
*
|
|
12
|
+
* @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}
|
|
13
|
+
*/
|
|
14
|
+
req: {
|
|
15
|
+
query: NextApiRequest["query"];
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The `res` object from a Next.js API route. This is given as a parameter to
|
|
19
|
+
* the API route.
|
|
20
|
+
*
|
|
21
|
+
* @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}
|
|
22
|
+
*/
|
|
23
|
+
res: {
|
|
24
|
+
redirect: NextApiResponse["redirect"];
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The Prismic client configured for the preview session's repository.
|
|
28
|
+
*/
|
|
29
|
+
client: Client;
|
|
30
|
+
/**
|
|
31
|
+
* A Link Resolver used to resolve the previewed document's URL.
|
|
32
|
+
*
|
|
33
|
+
* @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}
|
|
34
|
+
*/
|
|
35
|
+
linkResolver?: TLinkResolverFunction;
|
|
36
|
+
/**
|
|
37
|
+
* The default redirect URL if a URL cannot be determined for the previewed
|
|
38
|
+
* document.
|
|
39
|
+
*
|
|
40
|
+
* **Note**: If you `next.config.js` file contains a `basePath`, the
|
|
41
|
+
* `defaultURL` option must _not_ include it. Instead, provide the `basePath`
|
|
42
|
+
* property using the `basePath` option.
|
|
43
|
+
*/
|
|
44
|
+
defaultURL?: string;
|
|
45
|
+
/**
|
|
46
|
+
* The `basePath` for the Next.js app as it is defined in `next.config.js`.
|
|
47
|
+
* This option can be omitted if the app does not have a `basePath`.
|
|
48
|
+
*
|
|
49
|
+
* @remarks
|
|
50
|
+
* The API route is unable to detect the app's `basePath` automatically. It
|
|
51
|
+
* must be provided to `redirectToPreviewURL()` manually.
|
|
52
|
+
*/
|
|
53
|
+
basePath?: string;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Redirects a user to the URL of a previewed Prismic document from within a
|
|
57
|
+
* Next.js API route.
|
|
58
|
+
*/
|
|
59
|
+
export declare function redirectToPreviewURL<TLinkResolverFunction extends LinkResolverFunction<any>>(config: RedirectToPreviewURLConfig<TLinkResolverFunction>): Promise<void>;
|
|
@@ -16,6 +16,7 @@ async function redirectToPreviewURL(config) {
|
|
|
16
16
|
}
|
|
17
17
|
config.res.redirect(basePath + defaultURL);
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
export {
|
|
20
|
+
redirectToPreviewURL
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=redirectToPreviewURL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"redirectToPreviewURL.js","sources":["../src/redirectToPreviewURL.ts"],"sourcesContent":["import type { Client } from \"@prismicio/client\";\nimport type { NextApiRequest, NextApiResponse } from \"next\";\nimport type { LinkResolverFunction } from \"@prismicio/helpers\";\n\ntype PrismicNextQuery = {\n\tdocumentId: string;\n\ttoken: string;\n};\n\n/**\n * Determines if a query object from a Next.js API route request contains\n * Prismic preview data.\n *\n * @param query - Query object to check.\n *\n * @returns `true` if `query` contains Prismic preview data, `false` otherwise.\n */\nconst isPrismicNextQuery = (\n\tquery: NextApiRequest[\"query\"],\n): query is PrismicNextQuery => {\n\treturn (\n\t\ttypeof query.documentId === \"string\" && typeof query.token === \"string\"\n\t);\n};\n\n/**\n * Preview config for enabling previews with redirectToPreviewURL\n */\nexport type RedirectToPreviewURLConfig<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTLinkResolverFunction extends LinkResolverFunction<any> = LinkResolverFunction,\n> = {\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\treq: {\n\t\tquery: NextApiRequest[\"query\"];\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\tredirect: NextApiResponse[\"redirect\"];\n\t};\n\n\t/**\n\t * The Prismic client configured for the preview session's repository.\n\t */\n\tclient: Client;\n\n\t/**\n\t * A Link Resolver used to resolve the previewed document's URL.\n\t *\n\t * @see To learn more about Link Resolver: {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: TLinkResolverFunction;\n\n\t/**\n\t * The default redirect URL if a URL cannot be determined for the previewed\n\t * document.\n\t *\n\t * **Note**: If you `next.config.js` file contains a `basePath`, the\n\t * `defaultURL` option must _not_ include it. Instead, provide the `basePath`\n\t * property using the `basePath` option.\n\t */\n\tdefaultURL?: string;\n\n\t/**\n\t * The `basePath` for the Next.js app as it is defined in `next.config.js`.\n\t * This option can be omitted if the app does not have a `basePath`.\n\t *\n\t * @remarks\n\t * The API route is unable to detect the app's `basePath` automatically. It\n\t * must be provided to `redirectToPreviewURL()` manually.\n\t */\n\tbasePath?: string;\n};\n\n/**\n * Redirects a user to the URL of a previewed Prismic document from within a\n * Next.js API route.\n */\nexport async function redirectToPreviewURL<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTLinkResolverFunction extends LinkResolverFunction<any>,\n>(config: RedirectToPreviewURLConfig<TLinkResolverFunction>): Promise<void> {\n\tconst defaultURL = config.defaultURL || \"/\";\n\tconst basePath = config.basePath || \"\";\n\n\tif (isPrismicNextQuery(config.req.query)) {\n\t\tconst previewUrl = await config.client.resolvePreviewURL({\n\t\t\tlinkResolver: config.linkResolver,\n\t\t\tdefaultURL,\n\t\t\tdocumentID: config.req.query.documentId,\n\t\t\tpreviewToken: config.req.query.token,\n\t\t});\n\n\t\tconfig.res.redirect(basePath + previewUrl);\n\n\t\treturn;\n\t}\n\n\tconfig.res.redirect(basePath + defaultURL);\n}\n"],"names":[],"mappings":"AAiBA,MAAM,qBAAqB,CAC1B,UAC8B;AAC9B,SACC,OAAO,MAAM,eAAe,YAAY,OAAO,MAAM,UAAU;AAEjE;AAkEA,eAAsB,qBAGpB,QAAyD;AACpD,QAAA,aAAa,OAAO,cAAc;AAClC,QAAA,WAAW,OAAO,YAAY;AAEpC,MAAI,mBAAmB,OAAO,IAAI,KAAK,GAAG;AACzC,UAAM,aAAa,MAAM,OAAO,OAAO,kBAAkB;AAAA,MACxD,cAAc,OAAO;AAAA,MACrB;AAAA,MACA,YAAY,OAAO,IAAI,MAAM;AAAA,MAC7B,cAAc,OAAO,IAAI,MAAM;AAAA,IAAA,CAC/B;AAEM,WAAA,IAAI,SAAS,WAAW,UAAU;AAEzC;AAAA,EACA;AAEM,SAAA,IAAI,SAAS,WAAW,UAAU;AAC1C;"}
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
function setPreviewData({ req, res }) {
|
|
24
|
+
const ref = req.query.token || req.cookies[prismic__namespace.cookie.preview];
|
|
25
|
+
if (ref) {
|
|
26
|
+
res.setPreviewData({ ref });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.setPreviewData = setPreviewData;
|
|
30
|
+
//# sourceMappingURL=setPreviewData.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setPreviewData.
|
|
1
|
+
{"version":3,"file":"setPreviewData.cjs","sources":["../src/setPreviewData.ts"],"sourcesContent":["import { NextApiResponse, NextApiRequest } from \"next\";\nimport * as prismic from \"@prismicio/client\";\n\n/**\n * Configuration for `setPreviewData`.\n */\nexport type SetPreviewDataConfig = {\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\treq: {\n\t\tquery: NextApiRequest[\"query\"];\n\t\tcookies: NextApiRequest[\"cookies\"];\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\tsetPreviewData: NextApiResponse[\"setPreviewData\"];\n\t};\n};\n\n/**\n * Set Prismic preview data for Next.js's Preview Mode.\n */\nexport function setPreviewData({ req, res }: SetPreviewDataConfig): void {\n\tconst ref = req.query.token || req.cookies[prismic.cookie.preview];\n\n\tif (ref) {\n\t\tres.setPreviewData({ ref });\n\t}\n}\n"],"names":["prismic"],"mappings":";;;;;;;;;;;;;;;;;;;;;;SAgCgB,eAAe,EAAE,KAAK,OAA2B;AAChE,QAAM,MAAM,IAAI,MAAM,SAAS,IAAI,QAAQA,mBAAQ,OAAO;AAE1D,MAAI,KAAK;AACJ,QAAA,eAAe,EAAE,IAAA,CAAK;AAAA,EAC1B;AACF;;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { NextApiResponse, NextApiRequest } from "next";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for `setPreviewData`.
|
|
4
|
+
*/
|
|
5
|
+
export declare type SetPreviewDataConfig = {
|
|
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
|
+
query: NextApiRequest["query"];
|
|
14
|
+
cookies: NextApiRequest["cookies"];
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* The `res` object from a Next.js API route. This is given as a parameter to
|
|
18
|
+
* the API route.
|
|
19
|
+
*
|
|
20
|
+
* @see Next.js API route docs: {@link https://nextjs.org/docs/api-routes/introduction}
|
|
21
|
+
*/
|
|
22
|
+
res: {
|
|
23
|
+
setPreviewData: NextApiResponse["setPreviewData"];
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Set Prismic preview data for Next.js's Preview Mode.
|
|
28
|
+
*/
|
|
29
|
+
export declare function setPreviewData({ req, res }: SetPreviewDataConfig): void;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import * as prismic from
|
|
2
|
-
|
|
1
|
+
import * as prismic from "@prismicio/client";
|
|
3
2
|
function setPreviewData({ req, res }) {
|
|
4
3
|
const ref = req.query.token || req.cookies[prismic.cookie.preview];
|
|
5
4
|
if (ref) {
|
|
6
5
|
res.setPreviewData({ ref });
|
|
7
6
|
}
|
|
8
7
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
export {
|
|
9
|
+
setPreviewData
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=setPreviewData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setPreviewData.js","sources":["../src/setPreviewData.ts"],"sourcesContent":["import { NextApiResponse, NextApiRequest } from \"next\";\nimport * as prismic from \"@prismicio/client\";\n\n/**\n * Configuration for `setPreviewData`.\n */\nexport type SetPreviewDataConfig = {\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\treq: {\n\t\tquery: NextApiRequest[\"query\"];\n\t\tcookies: NextApiRequest[\"cookies\"];\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\tsetPreviewData: NextApiResponse[\"setPreviewData\"];\n\t};\n};\n\n/**\n * Set Prismic preview data for Next.js's Preview Mode.\n */\nexport function setPreviewData({ req, res }: SetPreviewDataConfig): void {\n\tconst ref = req.query.token || req.cookies[prismic.cookie.preview];\n\n\tif (ref) {\n\t\tres.setPreviewData({ ref });\n\t}\n}\n"],"names":[],"mappings":";SAgCgB,eAAe,EAAE,KAAK,OAA2B;AAChE,QAAM,MAAM,IAAI,MAAM,SAAS,IAAI,QAAQ,QAAQ,OAAO;AAE1D,MAAI,KAAK;AACJ,QAAA,eAAe,EAAE,IAAA,CAAK;AAAA,EAC1B;AACF;"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { PreviewData, NextApiRequest } from "next";
|
|
2
|
+
import type { ClientConfig } from "@prismicio/client";
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for creating a Prismic client with automatic preview support in
|
|
5
|
+
* Next.js apps.
|
|
6
|
+
*/
|
|
7
|
+
export declare type CreateClientConfig = {
|
|
8
|
+
/**
|
|
9
|
+
* Preview data coming from Next.js context object. This context object comes
|
|
10
|
+
* from `getStaticProps` or `getServerSideProps`.
|
|
11
|
+
*
|
|
12
|
+
* Pass `previewData` when using outside a Next.js API endpoint.
|
|
13
|
+
*/
|
|
14
|
+
previewData?: PreviewData;
|
|
15
|
+
/**
|
|
16
|
+
* A Next.js API endpoint request object.
|
|
17
|
+
*
|
|
18
|
+
* Pass a `req` object when using in a Next.js API endpoint.
|
|
19
|
+
*/
|
|
20
|
+
req?: NextApiRequest;
|
|
21
|
+
} & ClientConfig;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismicio/next",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6-alpha.0",
|
|
4
4
|
"description": "Helpers to integrate Prismic into Next.js apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -16,21 +16,23 @@
|
|
|
16
16
|
"license": "Apache-2.0",
|
|
17
17
|
"author": "Prismic <contact@prismic.io> (https://prismic.io)",
|
|
18
18
|
"sideEffects": false,
|
|
19
|
-
"type": "module",
|
|
20
19
|
"exports": {
|
|
21
|
-
".":
|
|
20
|
+
".": {
|
|
21
|
+
"require": "./dist/index.cjs",
|
|
22
|
+
"import": "./dist/index.js"
|
|
23
|
+
},
|
|
22
24
|
"./package.json": "./package.json"
|
|
23
25
|
},
|
|
24
|
-
"main": "./dist/index.
|
|
25
|
-
"module": "./dist/index.
|
|
26
|
+
"main": "./dist/index.cjs",
|
|
27
|
+
"module": "./dist/index.js",
|
|
26
28
|
"types": "dist/index.d.ts",
|
|
27
29
|
"files": [
|
|
28
30
|
"dist",
|
|
29
31
|
"src"
|
|
30
32
|
],
|
|
31
33
|
"scripts": {
|
|
32
|
-
"build": "
|
|
33
|
-
"dev": "
|
|
34
|
+
"build": "vite build",
|
|
35
|
+
"dev": "vite build --watch",
|
|
34
36
|
"format": "prettier --write .",
|
|
35
37
|
"lint": "eslint --ext .js,.ts .",
|
|
36
38
|
"prepare": "npm run build",
|
|
@@ -44,10 +46,11 @@
|
|
|
44
46
|
"unit:watch": "vitest watch"
|
|
45
47
|
},
|
|
46
48
|
"dependencies": {
|
|
47
|
-
"@prismicio/client": "^6.
|
|
49
|
+
"@prismicio/client": "^6.0.0",
|
|
48
50
|
"@prismicio/helpers": "^2.3.3",
|
|
49
51
|
"@prismicio/react": "^2.5.0",
|
|
50
52
|
"@prismicio/types": "^0.2.3",
|
|
53
|
+
"@rollup/plugin-typescript": "^8.5.0",
|
|
51
54
|
"eslint-plugin-react": "^7.31.7",
|
|
52
55
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
53
56
|
"imgix-url-builder": "^0.0.3"
|
|
@@ -59,7 +62,6 @@
|
|
|
59
62
|
"@typescript-eslint/eslint-plugin": "^5.36.2",
|
|
60
63
|
"@typescript-eslint/parser": "^5.36.2",
|
|
61
64
|
"@vitest/coverage-c8": "^0.23.1",
|
|
62
|
-
"chokidar-cli": "^3.0.0",
|
|
63
65
|
"eslint": "^8.23.0",
|
|
64
66
|
"eslint-config-prettier": "^8.5.0",
|
|
65
67
|
"eslint-plugin-prettier": "^4.2.1",
|
|
@@ -74,7 +76,7 @@
|
|
|
74
76
|
"size-limit": "^8.1.0",
|
|
75
77
|
"standard-version": "^9.5.0",
|
|
76
78
|
"typescript": "^4.8.3",
|
|
77
|
-
"
|
|
79
|
+
"vite": "^3.1.1",
|
|
78
80
|
"vitest": "^0.23.1"
|
|
79
81
|
},
|
|
80
82
|
"peerDependencies": {
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import Image from 'next/image';
|
|
3
|
-
import { buildURL } from 'imgix-url-builder';
|
|
4
|
-
import * as prismicH from '@prismicio/helpers';
|
|
5
|
-
import { __PRODUCTION__ } from './lib/__PRODUCTION__.mjs';
|
|
6
|
-
import { devMsg } from './lib/devMsg.mjs';
|
|
7
|
-
|
|
8
|
-
const imgixLoader = (args) => {
|
|
9
|
-
const url = new URL(args.src);
|
|
10
|
-
const params = {
|
|
11
|
-
fit: url.searchParams.get("fit") || "max",
|
|
12
|
-
w: args.width,
|
|
13
|
-
h: void 0
|
|
14
|
-
};
|
|
15
|
-
if (args.quality) {
|
|
16
|
-
params.q = args.quality;
|
|
17
|
-
}
|
|
18
|
-
return buildURL(args.src, params);
|
|
19
|
-
};
|
|
20
|
-
const PrismicNextImage = ({
|
|
21
|
-
field,
|
|
22
|
-
imgixParams = {},
|
|
23
|
-
alt,
|
|
24
|
-
fallbackAlt,
|
|
25
|
-
layout,
|
|
26
|
-
...restProps
|
|
27
|
-
}) => {
|
|
28
|
-
if (!__PRODUCTION__) {
|
|
29
|
-
if (typeof alt === "string" && alt !== "") {
|
|
30
|
-
console.warn(
|
|
31
|
-
`[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(
|
|
32
|
-
"alt-must-be-an-empty-string"
|
|
33
|
-
)}`
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
if (typeof fallbackAlt === "string" && fallbackAlt !== "") {
|
|
37
|
-
console.warn(
|
|
38
|
-
`[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(
|
|
39
|
-
"alt-must-be-an-empty-string"
|
|
40
|
-
)}`
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (prismicH.isFilled.imageThumbnail(field)) {
|
|
45
|
-
const src = buildURL(field.url, imgixParams);
|
|
46
|
-
return /* @__PURE__ */ jsx(Image, {
|
|
47
|
-
src,
|
|
48
|
-
width: layout === "fill" ? void 0 : field.dimensions.width,
|
|
49
|
-
height: layout === "fill" ? void 0 : field.dimensions.height,
|
|
50
|
-
alt: alt ?? (field.alt || fallbackAlt),
|
|
51
|
-
loader: imgixLoader,
|
|
52
|
-
layout,
|
|
53
|
-
...restProps
|
|
54
|
-
});
|
|
55
|
-
} else {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
export { PrismicNextImage };
|
|
61
|
-
//# sourceMappingURL=PrismicNextImage.mjs.map
|
package/dist/index.mjs
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { setPreviewData } from './setPreviewData.mjs';
|
|
2
|
-
export { exitPreview } from './exitPreview.mjs';
|
|
3
|
-
export { PrismicPreview } from './PrismicPreview.mjs';
|
|
4
|
-
export { enableAutoPreviews } from './enableAutoPreviews.mjs';
|
|
5
|
-
export { redirectToPreviewURL } from './redirectToPreviewURL.mjs';
|
|
6
|
-
export { PrismicNextImage } from './PrismicNextImage.mjs';
|
|
7
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
|
package/dist/lib/devMsg.mjs
DELETED
package/dist/package.mjs
DELETED
package/dist/package.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"package.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;"}
|