@prismicio/next 2.0.1-alpha.1 → 2.0.2-canary.7bb987d
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 +2 -2
- package/dist/PrismicNextImage.cjs.map +1 -1
- package/dist/PrismicNextLink.cjs +2 -2
- package/dist/PrismicNextLink.cjs.map +1 -1
- package/dist/PrismicNextLink.d.ts +3 -81
- package/dist/PrismicPreview.cjs +2 -2
- package/dist/PrismicPreview.cjs.map +1 -1
- package/dist/PrismicPreviewClient.cjs.map +1 -1
- package/dist/lib/resolveDefaultExport.cjs +7 -0
- package/dist/lib/resolveDefaultExport.cjs.map +1 -0
- package/dist/lib/resolveDefaultExport.d.ts +18 -0
- package/dist/package.json.cjs +1 -1
- package/package.json +6 -6
- package/src/PrismicNextImage.tsx +2 -2
- package/src/PrismicNextLink.tsx +2 -2
- package/src/PrismicPreview.tsx +2 -2
- package/src/lib/resolveDefaultExport.ts +21 -0
- package/dist/lib/resolveCJS.cjs +0 -7
- package/dist/lib/resolveCJS.cjs.map +0 -1
- package/dist/lib/resolveCJS.d.ts +0 -9
- package/src/lib/resolveCJS.ts +0 -12
|
@@ -7,7 +7,7 @@ const Image = require("next/image");
|
|
|
7
7
|
const imgixUrlBuilder = require("imgix-url-builder");
|
|
8
8
|
const client = require("@prismicio/client");
|
|
9
9
|
const devMsg = require("./lib/devMsg.cjs");
|
|
10
|
-
const
|
|
10
|
+
const resolveDefaultExport = require("./lib/resolveDefaultExport.cjs");
|
|
11
11
|
const imgixLoader = require("./imgixLoader.cjs");
|
|
12
12
|
const castInt = (input) => {
|
|
13
13
|
if (typeof input === "number" || typeof input === "undefined") {
|
|
@@ -54,7 +54,7 @@ const PrismicNextImage = react.forwardRef(function PrismicNextImage2({ field, im
|
|
|
54
54
|
if (process.env.NODE_ENV === "development" && typeof resolvedAlt !== "string") {
|
|
55
55
|
console.error(`[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=""\`.`, src);
|
|
56
56
|
}
|
|
57
|
-
const ResolvedImage =
|
|
57
|
+
const ResolvedImage = resolveDefaultExport.resolveDefaultExport(Image);
|
|
58
58
|
return jsxRuntime.jsx(ResolvedImage, { ref, src, width: fill ? void 0 : resolvedWidth, height: fill ? void 0 : resolvedHeight, alt: resolvedAlt, fill, loader: loader === null ? void 0 : loader, ...restProps });
|
|
59
59
|
});
|
|
60
60
|
exports.PrismicNextImage = PrismicNextImage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicNextImage.cjs","sources":["../src/PrismicNextImage.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n\tforwardRef,\n\tForwardRefExoticComponent,\n\tPropsWithoutRef,\n\tRefAttributes,\n} from \"react\";\nimport Image, { ImageProps } from \"next/image\";\nimport { buildURL, ImgixURLParams } from \"imgix-url-builder\";\nimport { ImageFieldImage, isFilled } from \"@prismicio/client\";\n\nimport { devMsg } from \"./lib/devMsg\";\nimport {
|
|
1
|
+
{"version":3,"file":"PrismicNextImage.cjs","sources":["../src/PrismicNextImage.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n\tforwardRef,\n\tForwardRefExoticComponent,\n\tPropsWithoutRef,\n\tRefAttributes,\n} from \"react\";\nimport Image, { ImageProps } from \"next/image\";\nimport { buildURL, ImgixURLParams } from \"imgix-url-builder\";\nimport { ImageFieldImage, isFilled } from \"@prismicio/client\";\n\nimport { devMsg } from \"./lib/devMsg\";\nimport { resolveDefaultExport } from \"./lib/resolveDefaultExport\";\n\nimport { imgixLoader } from \"./imgixLoader\";\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 PrismicNextImageProps = Omit<\n\tImageProps,\n\t\"src\" | \"alt\" | \"loader\"\n> & {\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 PrismicNextImage: ForwardRefExoticComponent<\n\tPropsWithoutRef<PrismicNextImageProps> & RefAttributes<HTMLImageElement>\n> = forwardRef<HTMLImageElement, PrismicNextImageProps>(\n\tfunction PrismicNextImage(\n\t\t{\n\t\t\tfield,\n\t\t\timgixParams = {},\n\t\t\talt,\n\t\t\tfallbackAlt,\n\t\t\tfill,\n\t\t\twidth,\n\t\t\theight,\n\t\t\tfallback = null,\n\t\t\tloader = imgixLoader,\n\t\t\t...restProps\n\t\t},\n\t\tref,\n\t) {\n\t\tif (process.env.NODE_ENV === \"development\") {\n\t\t\tif (typeof alt === \"string\" && alt !== \"\") {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[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(\n\t\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t\t)}`,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (typeof fallbackAlt === \"string\" && fallbackAlt !== \"\") {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[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(\n\t\t\t\t\t\t\"alt-must-be-an-empty-string\",\n\t\t\t\t\t)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (!isFilled.imageThumbnail(field)) {\n\t\t\treturn <>{fallback}</>;\n\t\t}\n\n\t\tconst resolvedImgixParams = imgixParams;\n\t\tfor (const x in imgixParams) {\n\t\t\tif (resolvedImgixParams[x as keyof typeof resolvedImgixParams] === null) {\n\t\t\t\tresolvedImgixParams[x as keyof typeof resolvedImgixParams] = undefined;\n\t\t\t}\n\t\t}\n\n\t\tconst src = buildURL(field.url, imgixParams as ImgixURLParams);\n\n\t\tconst ar = field.dimensions.width / field.dimensions.height;\n\n\t\tconst castedWidth = castInt(width);\n\t\tconst castedHeight = castInt(height);\n\n\t\tlet resolvedWidth = castedWidth ?? field.dimensions.width;\n\t\tlet resolvedHeight = castedHeight ?? field.dimensions.height;\n\n\t\tif (castedWidth != null && castedHeight == null) {\n\t\t\tresolvedHeight = castedWidth / ar;\n\t\t} else if (castedWidth == null && castedHeight != null) {\n\t\t\tresolvedWidth = castedHeight * ar;\n\t\t}\n\n\t\t// A non-null assertion is required since we can't statically\n\t\t// know if an alt attribute is available.\n\t\tconst resolvedAlt = (alt ?? (field.alt || fallbackAlt))!;\n\n\t\tif (\n\t\t\tprocess.env.NODE_ENV === \"development\" &&\n\t\t\ttypeof resolvedAlt !== \"string\"\n\t\t) {\n\t\t\tconsole.error(\n\t\t\t\t`[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=\"\"\\`.`,\n\t\t\t\tsrc,\n\t\t\t);\n\t\t}\n\n\t\tconst ResolvedImage = resolveDefaultExport(Image);\n\n\t\treturn (\n\t\t\t<ResolvedImage\n\t\t\t\tref={ref}\n\t\t\t\tsrc={src}\n\t\t\t\twidth={fill ? undefined : resolvedWidth}\n\t\t\t\theight={fill ? undefined : resolvedHeight}\n\t\t\t\talt={resolvedAlt}\n\t\t\t\tfill={fill}\n\t\t\t\tloader={loader === null ? undefined : loader}\n\t\t\t\t{...restProps}\n\t\t\t/>\n\t\t);\n\t},\n);\n"],"names":["forwardRef","PrismicNextImage","imgixLoader","devMsg","isFilled","_jsx","_Fragment","buildURL","resolveDefaultExport"],"mappings":";;;;;;;;;;;AAiBA,MAAM,UAAU,CAAC,UAA0D;AAC1E,MAAI,OAAO,UAAU,YAAY,OAAO,UAAU,aAAa;AACvD,WAAA;AAAA,EAAA,OACD;AACA,UAAA,SAAS,OAAO,SAAS,KAAK;AAEhC,QAAA,OAAO,MAAM,MAAM,GAAG;AAClB,aAAA;AAAA,IAAA,OACD;AACC,aAAA;AAAA,IAAA;AAAA,EACR;AAEF;AA2Da,MAAA,mBAETA,MAAAA,WACH,SAASC,kBACR,EACC,OACA,cAAc,CAAA,GACd,KACA,aACA,MACA,OACA,QACA,WAAW,MACX,SAASC,yBACT,GAAG,UAAS,GAEb,KAAG;AAEC,MAAA,QAAQ,IAAI,aAAa,eAAe;AAC3C,QAAI,OAAO,QAAQ,YAAY,QAAQ,IAAI;AAC1C,cAAQ,KACP,yQAAyQC,OAAAA,OACxQ,6BAA6B,CAC7B,EAAE;AAAA,IAAA;AAIL,QAAI,OAAO,gBAAgB,YAAY,gBAAgB,IAAI;AAC1D,cAAQ,KACP,ySAAySA,OAAAA,OACxS,6BAA6B,CAC7B,EAAE;AAAA,IAAA;AAAA,EAEL;AAGD,MAAI,CAACC,OAAA,SAAS,eAAe,KAAK,GAAG;AACpC,WAAOC,WAAA,IAAAC,WAAA,UAAA,EAAA,UAAG,UAAQ;AAAA,EAAA;AAGnB,QAAM,sBAAsB;AAC5B,aAAW,KAAK,aAAa;AACxB,QAAA,oBAAoB,CAAqC,MAAM,MAAM;AACxE,0BAAoB,CAAqC,IAAI;AAAA,IAAA;AAAA,EAC9D;AAGD,QAAM,MAAMC,gBAAA,SAAS,MAAM,KAAK,WAA6B;AAE7D,QAAM,KAAK,MAAM,WAAW,QAAQ,MAAM,WAAW;AAE/C,QAAA,cAAc,QAAQ,KAAK;AAC3B,QAAA,eAAe,QAAQ,MAAM;AAE/B,MAAA,gBAAgB,eAAe,MAAM,WAAW;AAChD,MAAA,iBAAiB,gBAAgB,MAAM,WAAW;AAElD,MAAA,eAAe,QAAQ,gBAAgB,MAAM;AAChD,qBAAiB,cAAc;AAAA,EACrB,WAAA,eAAe,QAAQ,gBAAgB,MAAM;AACvD,oBAAgB,eAAe;AAAA,EAAA;AAK1B,QAAA,cAAe,QAAQ,MAAM,OAAO;AAE1C,MACC,QAAQ,IAAI,aAAa,iBACzB,OAAO,gBAAgB,UACtB;AACO,YAAA,MACP,mNACA,GAAG;AAAA,EAAA;AAIC,QAAA,gBAAgBC,0CAAqB,KAAK;AAG/C,SAAAH,eAAC,eAAa,EACb,KACA,KACA,OAAO,OAAO,SAAY,eAC1B,QAAQ,OAAO,SAAY,gBAC3B,KAAK,aACL,MACA,QAAQ,WAAW,OAAO,SAAY,QAAM,GACxC,UAAA,CAAS;AAGhB,CAAC;;"}
|
package/dist/PrismicNextLink.cjs
CHANGED
|
@@ -4,7 +4,7 @@ const jsxRuntime = require("react/jsx-runtime");
|
|
|
4
4
|
const react = require("react");
|
|
5
5
|
const Link = require("next/link");
|
|
6
6
|
const client = require("@prismicio/client");
|
|
7
|
-
const
|
|
7
|
+
const resolveDefaultExport = require("./lib/resolveDefaultExport.cjs");
|
|
8
8
|
const PrismicNextLink = react.forwardRef(function PrismicNextLink2(props, ref) {
|
|
9
9
|
const { field, document, linkResolver, children, ...restProps } = props;
|
|
10
10
|
const { href: computedHref, rel: computedRel, ...attrs } = client.asLinkAttrs(field ?? document, {
|
|
@@ -16,7 +16,7 @@ const PrismicNextLink = react.forwardRef(function PrismicNextLink2(props, ref) {
|
|
|
16
16
|
if ("rel" in restProps && typeof restProps.rel !== "function") {
|
|
17
17
|
rel = restProps.rel;
|
|
18
18
|
}
|
|
19
|
-
const ResolvedLink =
|
|
19
|
+
const ResolvedLink = resolveDefaultExport.resolveDefaultExport(Link);
|
|
20
20
|
return jsxRuntime.jsx(ResolvedLink, { ref, ...attrs, ...restProps, href, rel, children: "children" in props ? children : field == null ? void 0 : field.text });
|
|
21
21
|
});
|
|
22
22
|
exports.PrismicNextLink = PrismicNextLink;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicNextLink.cjs","sources":["../src/PrismicNextLink.tsx"],"sourcesContent":["import { ComponentProps, forwardRef } from \"react\";\nimport Link from \"next/link\";\nimport {\n\tAsLinkAttrsConfig,\n\tLinkField,\n\tLinkResolverFunction,\n\tPrismicDocument,\n\tasLinkAttrs,\n} from \"@prismicio/client\";\n\nimport {
|
|
1
|
+
{"version":3,"file":"PrismicNextLink.cjs","sources":["../src/PrismicNextLink.tsx"],"sourcesContent":["import { ComponentProps, forwardRef } from \"react\";\nimport Link from \"next/link\";\nimport {\n\tAsLinkAttrsConfig,\n\tLinkField,\n\tLinkResolverFunction,\n\tPrismicDocument,\n\tasLinkAttrs,\n} from \"@prismicio/client\";\n\nimport { resolveDefaultExport } from \"./lib/resolveDefaultExport\";\n\nexport type PrismicNextLinkProps = 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 PrismicNextLink = forwardRef<\n\tHTMLAnchorElement,\n\tPrismicNextLinkProps\n>(function PrismicNextLink(props, ref) {\n\tconst { field, document, linkResolver, children, ...restProps } = props;\n\tconst {\n\t\thref: computedHref,\n\t\trel: computedRel,\n\t\t...attrs\n\t} = asLinkAttrs(field ?? document, {\n\t\tlinkResolver,\n\t\trel: typeof restProps.rel === \"function\" ? restProps.rel : undefined,\n\t});\n\n\tconst href = (\"href\" in restProps ? restProps.href : computedHref) || \"\";\n\n\tlet rel = computedRel;\n\tif (\"rel\" in restProps && typeof restProps.rel !== \"function\") {\n\t\trel = restProps.rel;\n\t}\n\n\tconst ResolvedLink = resolveDefaultExport(Link);\n\n\treturn (\n\t\t<ResolvedLink ref={ref} {...attrs} {...restProps} href={href} rel={rel}>\n\t\t\t{\"children\" in props ? children : field?.text}\n\t\t</ResolvedLink>\n\t);\n});\n"],"names":["forwardRef","PrismicNextLink","asLinkAttrs","resolveDefaultExport","_jsx"],"mappings":";;;;;;;AAoCO,MAAM,kBAAkBA,MAAAA,WAG7B,SAASC,iBAAgB,OAAO,KAAG;AACpC,QAAM,EAAE,OAAO,UAAU,cAAc,UAAU,GAAG,cAAc;AAC5D,QAAA,EACL,MAAM,cACN,KAAK,aACL,GAAG,UACAC,OAAAA,YAAY,SAAS,UAAU;AAAA,IAClC;AAAA,IACA,KAAK,OAAO,UAAU,QAAQ,aAAa,UAAU,MAAM;AAAA,EAAA,CAC3D;AAED,QAAM,QAAQ,UAAU,YAAY,UAAU,OAAO,iBAAiB;AAEtE,MAAI,MAAM;AACV,MAAI,SAAS,aAAa,OAAO,UAAU,QAAQ,YAAY;AAC9D,UAAM,UAAU;AAAA,EAAA;AAGX,QAAA,eAAeC,0CAAqB,IAAI;AAE9C,SACCC,WAAAA,IAAC,cAAY,EAAC,KAAc,GAAA,UAAW,WAAW,MAAY,eAC5D,cAAc,QAAQ,WAAW,+BAAO,MAAI;AAGhD,CAAC;;"}
|
|
@@ -17,33 +17,7 @@ export type PrismicNextLinkProps = Omit<ComponentProps<typeof Link>, "field" | "
|
|
|
17
17
|
document?: never;
|
|
18
18
|
href: ComponentProps<typeof Link>["href"];
|
|
19
19
|
});
|
|
20
|
-
export declare const PrismicNextLink: import("react").ForwardRefExoticComponent<(Omit<Omit<Omit<import("react").AnchorHTMLAttributes<HTMLAnchorElement>, keyof {
|
|
21
|
-
href: string | import("url").UrlObject;
|
|
22
|
-
as?: string | import("url").UrlObject;
|
|
23
|
-
replace?: boolean;
|
|
24
|
-
scroll?: boolean;
|
|
25
|
-
shallow?: boolean;
|
|
26
|
-
passHref?: boolean;
|
|
27
|
-
prefetch?: boolean | null;
|
|
28
|
-
locale?: string | false;
|
|
29
|
-
legacyBehavior?: boolean;
|
|
30
|
-
onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement>;
|
|
31
|
-
onTouchStart?: React.TouchEventHandler<HTMLAnchorElement>;
|
|
32
|
-
onClick?: React.MouseEventHandler<HTMLAnchorElement>;
|
|
33
|
-
}> & {
|
|
34
|
-
href: string | import("url").UrlObject;
|
|
35
|
-
as?: string | import("url").UrlObject;
|
|
36
|
-
replace?: boolean;
|
|
37
|
-
scroll?: boolean;
|
|
38
|
-
shallow?: boolean;
|
|
39
|
-
passHref?: boolean;
|
|
40
|
-
prefetch?: boolean | null;
|
|
41
|
-
locale?: string | false;
|
|
42
|
-
legacyBehavior?: boolean;
|
|
43
|
-
onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement>;
|
|
44
|
-
onTouchStart?: React.TouchEventHandler<HTMLAnchorElement>;
|
|
45
|
-
onClick?: React.MouseEventHandler<HTMLAnchorElement>;
|
|
46
|
-
} & {
|
|
20
|
+
export declare const PrismicNextLink: import("react").ForwardRefExoticComponent<(Omit<Omit<Omit<import("react").AnchorHTMLAttributes<HTMLAnchorElement>, keyof import("next/link").LinkProps<any>> & import("next/link").LinkProps<any> & {
|
|
47
21
|
children?: React.ReactNode | undefined;
|
|
48
22
|
} & import("react").RefAttributes<HTMLAnchorElement>, "rel" | "field" | "document" | "href"> & {
|
|
49
23
|
linkResolver?: LinkResolverFunction;
|
|
@@ -52,33 +26,7 @@ export declare const PrismicNextLink: import("react").ForwardRefExoticComponent<
|
|
|
52
26
|
field: LinkField | null | undefined;
|
|
53
27
|
document?: never;
|
|
54
28
|
href?: never;
|
|
55
|
-
}, "ref"> | Omit<Omit<Omit<import("react").AnchorHTMLAttributes<HTMLAnchorElement>, keyof {
|
|
56
|
-
href: string | import("url").UrlObject;
|
|
57
|
-
as?: string | import("url").UrlObject;
|
|
58
|
-
replace?: boolean;
|
|
59
|
-
scroll?: boolean;
|
|
60
|
-
shallow?: boolean;
|
|
61
|
-
passHref?: boolean;
|
|
62
|
-
prefetch?: boolean | null;
|
|
63
|
-
locale?: string | false;
|
|
64
|
-
legacyBehavior?: boolean;
|
|
65
|
-
onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement>;
|
|
66
|
-
onTouchStart?: React.TouchEventHandler<HTMLAnchorElement>;
|
|
67
|
-
onClick?: React.MouseEventHandler<HTMLAnchorElement>;
|
|
68
|
-
}> & {
|
|
69
|
-
href: string | import("url").UrlObject;
|
|
70
|
-
as?: string | import("url").UrlObject;
|
|
71
|
-
replace?: boolean;
|
|
72
|
-
scroll?: boolean;
|
|
73
|
-
shallow?: boolean;
|
|
74
|
-
passHref?: boolean;
|
|
75
|
-
prefetch?: boolean | null;
|
|
76
|
-
locale?: string | false;
|
|
77
|
-
legacyBehavior?: boolean;
|
|
78
|
-
onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement>;
|
|
79
|
-
onTouchStart?: React.TouchEventHandler<HTMLAnchorElement>;
|
|
80
|
-
onClick?: React.MouseEventHandler<HTMLAnchorElement>;
|
|
81
|
-
} & {
|
|
29
|
+
}, "ref"> | Omit<Omit<Omit<import("react").AnchorHTMLAttributes<HTMLAnchorElement>, keyof import("next/link").LinkProps<any>> & import("next/link").LinkProps<any> & {
|
|
82
30
|
children?: React.ReactNode | undefined;
|
|
83
31
|
} & import("react").RefAttributes<HTMLAnchorElement>, "rel" | "field" | "document" | "href"> & {
|
|
84
32
|
linkResolver?: LinkResolverFunction;
|
|
@@ -87,33 +35,7 @@ export declare const PrismicNextLink: import("react").ForwardRefExoticComponent<
|
|
|
87
35
|
field?: never;
|
|
88
36
|
document: PrismicDocument | null | undefined;
|
|
89
37
|
href?: never;
|
|
90
|
-
}, "ref"> | Omit<Omit<Omit<import("react").AnchorHTMLAttributes<HTMLAnchorElement>, keyof {
|
|
91
|
-
href: string | import("url").UrlObject;
|
|
92
|
-
as?: string | import("url").UrlObject;
|
|
93
|
-
replace?: boolean;
|
|
94
|
-
scroll?: boolean;
|
|
95
|
-
shallow?: boolean;
|
|
96
|
-
passHref?: boolean;
|
|
97
|
-
prefetch?: boolean | null;
|
|
98
|
-
locale?: string | false;
|
|
99
|
-
legacyBehavior?: boolean;
|
|
100
|
-
onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement>;
|
|
101
|
-
onTouchStart?: React.TouchEventHandler<HTMLAnchorElement>;
|
|
102
|
-
onClick?: React.MouseEventHandler<HTMLAnchorElement>;
|
|
103
|
-
}> & {
|
|
104
|
-
href: string | import("url").UrlObject;
|
|
105
|
-
as?: string | import("url").UrlObject;
|
|
106
|
-
replace?: boolean;
|
|
107
|
-
scroll?: boolean;
|
|
108
|
-
shallow?: boolean;
|
|
109
|
-
passHref?: boolean;
|
|
110
|
-
prefetch?: boolean | null;
|
|
111
|
-
locale?: string | false;
|
|
112
|
-
legacyBehavior?: boolean;
|
|
113
|
-
onMouseEnter?: React.MouseEventHandler<HTMLAnchorElement>;
|
|
114
|
-
onTouchStart?: React.TouchEventHandler<HTMLAnchorElement>;
|
|
115
|
-
onClick?: React.MouseEventHandler<HTMLAnchorElement>;
|
|
116
|
-
} & {
|
|
38
|
+
}, "ref"> | Omit<Omit<Omit<import("react").AnchorHTMLAttributes<HTMLAnchorElement>, keyof import("next/link").LinkProps<any>> & import("next/link").LinkProps<any> & {
|
|
117
39
|
children?: React.ReactNode | undefined;
|
|
118
40
|
} & import("react").RefAttributes<HTMLAnchorElement>, "rel" | "field" | "document" | "href"> & {
|
|
119
41
|
linkResolver?: LinkResolverFunction;
|
package/dist/PrismicPreview.cjs
CHANGED
|
@@ -25,14 +25,14 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
25
25
|
const jsxRuntime = require("react/jsx-runtime");
|
|
26
26
|
const Script = require("next/script");
|
|
27
27
|
const client = require("@prismicio/client");
|
|
28
|
-
const
|
|
28
|
+
const resolveDefaultExport = require("./lib/resolveDefaultExport.cjs");
|
|
29
29
|
const PrismicPreviewClient = require("./PrismicPreviewClient.cjs");
|
|
30
30
|
const PrismicPreview = async (props) => {
|
|
31
31
|
const { repositoryName, children, ...otherProps } = props;
|
|
32
32
|
const { draftMode } = await import("next/headers");
|
|
33
33
|
const toolbarSrc = client.getToolbarSrc(repositoryName);
|
|
34
34
|
const isDraftMode = (await draftMode()).isEnabled;
|
|
35
|
-
const ResolvedScript =
|
|
35
|
+
const ResolvedScript = resolveDefaultExport.resolveDefaultExport(Script);
|
|
36
36
|
return jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [children, jsxRuntime.jsx(PrismicPreviewClient.PrismicPreviewClient, { repositoryName, isDraftMode, ...otherProps }), jsxRuntime.jsx(ResolvedScript, { src: toolbarSrc, strategy: "lazyOnload" })] });
|
|
37
37
|
};
|
|
38
38
|
exports.PrismicPreview = PrismicPreview;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicPreview.cjs","sources":["../src/PrismicPreview.tsx"],"sourcesContent":["import type { FC, ReactNode } from \"react\";\nimport Script from \"next/script\";\nimport { getToolbarSrc } from \"@prismicio/client\";\n\nimport {
|
|
1
|
+
{"version":3,"file":"PrismicPreview.cjs","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"],"names":["getToolbarSrc","resolveDefaultExport","_jsxs","_Fragment","_jsx","PrismicPreviewClient"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCa,MAAA,iBAA0C,OAAO,UAAS;AACtE,QAAM,EAAE,gBAAgB,UAAU,GAAG,WAAe,IAAA;AAKpD,QAAM,EAAE,UAAA,IAAc,MAAM,OAAO,cAAc;AAE3C,QAAA,aAAaA,qBAAc,cAAc;AACzC,QAAA,eAAe,MAAM,UAAA,GAAa;AAElC,QAAA,iBAAiBC,0CAAqB,MAAM;AAGjD,SAAAC,WAAA,KAAAC,qBAAA,EAAA,UAAA,CACE,UACDC,eAACC,qBAAAA,sBACA,EAAA,gBACA,aAAwB,GACpB,YAAU,GAEfD,eAAC,gBAAc,EAAC,KAAK,YAAY,UAAS,cAAe,CAAA,GAAA;AAG5D;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicPreviewClient.cjs","sources":["../src/PrismicPreviewClient.tsx"],"sourcesContent":["\"use client\";\n\nimport { FC, useEffect } from \"react\";\nimport { cookie as prismicCookie } from \"@prismicio/client\";\nimport { useRouter } from \"next/navigation\";\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\tconsole.log(\"starting preview link\");\n\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"],"names":["useRouter","useEffect","value","prismicCookie"],"mappings":";;;;;;AAaa,MAAA,uBAAsD,CAAC,UAAS;AAC5E,QAAM,EACL,gBACA,aACA,mBAAmB,gBACnB,iBAAiB,wBACd;AAEE,QAAA,EAAE,QAAO,IAAKA;AAEpBC,QAAAA,UAAU,MAAK;AACR,UAAA,aAAa,IAAI;AAEhB,WAAA,iBAAiB,wBAAwB,UAAU;AAAA,MACzD,QAAQ,WAAW;AAAA,IAAA,CACnB;AACM,WAAA,iBAAiB,qBAAqB,OAAO;AAAA,MACnD,QAAQ,WAAW;AAAA,IAAA,CACnB;AAED,UAAM,SAAS,wBAAwB,OAAO,SAAS,MAAM;AACvD,UAAA,uBAAuB,UACzB,mBAAmB,MAAM,EAAE,MAAM,wBAAwB,KAAK,
|
|
1
|
+
{"version":3,"file":"PrismicPreviewClient.cjs","sources":["../src/PrismicPreviewClient.tsx"],"sourcesContent":["\"use client\";\n\nimport { FC, useEffect } from \"react\";\nimport { cookie as prismicCookie } from \"@prismicio/client\";\nimport { useRouter } from \"next/navigation\";\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\tconsole.log(\"starting preview link\");\n\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"],"names":["useRouter","useEffect","value","prismicCookie"],"mappings":";;;;;;AAaa,MAAA,uBAAsD,CAAC,UAAS;AAC5E,QAAM,EACL,gBACA,aACA,mBAAmB,gBACnB,iBAAiB,wBACd;AAEE,QAAA,EAAE,QAAO,IAAKA;AAEpBC,QAAAA,UAAU,MAAK;AACR,UAAA,aAAa,IAAI;AAEhB,WAAA,iBAAiB,wBAAwB,UAAU;AAAA,MACzD,QAAQ,WAAW;AAAA,IAAA,CACnB;AACM,WAAA,iBAAiB,qBAAqB,OAAO;AAAA,MACnD,QAAQ,WAAW;AAAA,IAAA,CACnB;AAED,UAAM,SAAS,wBAAwB,OAAO,SAAS,MAAM;AACvD,UAAA,uBAAuB,UACzB,mBAAmB,MAAM,EAAE,MAAM,wBAAwB,KAAK,CAAA,GAAI,CAAC,IACpE;AACH,UAAM,yBAAyB,yBAAyB;AAKpD,QAAA,0BAA0B,CAAC,aAAa;AAC3C,cAAQ,IAAI,uBAAuB;AAMnC,iBACE,MAAM,kBAAkB;AAAA,QACxB,UAAU;AAAA,QACV,QAAQ,WAAW;AAAA,MAAA,CACnB,EACA,KAAK,CAAC,QAAO;AACT,YAAA,IAAI,SAAS,kBAAkB;AAC1B,kBAAA,MACP,yDAAyD,gBAAgB,mBAAmB;AAG7F;AAAA,QAAA;;OAID,EACA,MAAM,MAAK;AAAA,MAAA,CAEX;AAAA,IAAA;AAGH,aAAS,SAAS,OAAY;AAC7B,YAAM,eAAc;;;AAIrB,aAAS,MAAM,OAAY;AAC1B,YAAM,eAAc;AAElB,iBAAA,MAAM,gBAAgB,EAAE,QAAQ,WAAW,QAAQ,EACnD,KAAK,CAAC,QAAO;AACT,YAAA,CAAC,IAAI,IAAI;AACJ,kBAAA,MACP,6DAA6D,cAAc,gCAAgC;AAG5G;AAAA,QAAA;;OAID,EACA,MAAM,MAAK;AAAA,MAAA,CAEX;AAAA,IAAA;AAGI,WAAA,MAAM,WAAW;KACtB,CAAC,gBAAgB,aAAa,kBAAkB,gBAAgB,OAAO,CAAC;AAEpE,SAAA;AACR;AAUA,SAAS,wBAAwB,WAAiB;AACjD,WAAS,UAAUC,QAAa;AACxBA,WAAAA,OAAM,QAAQ,QAAQ,GAAG;AAAA,EAAA;AAG3B,QAAA,UAAU,UAAU,MAAM,IAAI;AAEhC,MAAA;AAEJ,aAAW,UAAU,SAAS;AACvB,UAAA,QAAQ,OAAO,MAAM,GAAG;AACxB,UAAA,OAAO,UAAU,MAAM,CAAC,CAAC,EAAE,QAAQ,QAAQ,GAAG;AAEhD,QAAA,SAASC,cAAc,SAAS;AACnC,cAAQ,UAAU,MAAM,MAAM,CAAC,EAAE,KAAK,GAAG,CAAC;AAC1C;AAAA,IAAA;AAAA,EACD;AAGM,SAAA;AACR;;"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
function resolveDefaultExport(mod) {
|
|
4
|
+
return "default" in mod ? mod.default : mod;
|
|
5
|
+
}
|
|
6
|
+
exports.resolveDefaultExport = resolveDefaultExport;
|
|
7
|
+
//# sourceMappingURL=resolveDefaultExport.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveDefaultExport.cjs","sources":["../../src/lib/resolveDefaultExport.ts"],"sourcesContent":["/**\n * Resolves a module's default export. The module may provide its default export\n * as a `default` property on an object. This happens when named and default\n * exports are mixed in modules.\n *\n * In ES Modules, mixing is fine since the module resolver can distinguish\n * default and named exports. In transpiled modules, however, all exports are\n * put into a single object, and the default export is provided at a property\n * called `default`.\n *\n * This helper is needed by Next.js uses CJS files with named and default\n * exports.\n *\n * This helper _should_ be a temporary hack until Next.js and Node.js resolve\n * their ESM difficulties. This will likely not be removed any time soon,\n * unfortunately.\n */\nexport function resolveDefaultExport<T>(mod: T): T {\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\treturn \"default\" in (mod as any) ? (mod as any).default : mod;\n}\n"],"names":[],"mappings":";;AAiBM,SAAU,qBAAwB,KAAM;AAEtC,SAAA,aAAc,MAAe,IAAY,UAAU;AAC3D;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves a module's default export. The module may provide its default export
|
|
3
|
+
* as a `default` property on an object. This happens when named and default
|
|
4
|
+
* exports are mixed in modules.
|
|
5
|
+
*
|
|
6
|
+
* In ES Modules, mixing is fine since the module resolver can distinguish
|
|
7
|
+
* default and named exports. In transpiled modules, however, all exports are
|
|
8
|
+
* put into a single object, and the default export is provided at a property
|
|
9
|
+
* called `default`.
|
|
10
|
+
*
|
|
11
|
+
* This helper is needed by Next.js uses CJS files with named and default
|
|
12
|
+
* exports.
|
|
13
|
+
*
|
|
14
|
+
* This helper _should_ be a temporary hack until Next.js and Node.js resolve
|
|
15
|
+
* their ESM difficulties. This will likely not be removed any time soon,
|
|
16
|
+
* unfortunately.
|
|
17
|
+
*/
|
|
18
|
+
export declare function resolveDefaultExport<T>(mod: T): T;
|
package/dist/package.json.cjs
CHANGED
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"e2e-projects/*"
|
|
5
5
|
],
|
|
6
6
|
"name": "@prismicio/next",
|
|
7
|
-
"version": "2.0.
|
|
7
|
+
"version": "2.0.2-canary.7bb987d",
|
|
8
8
|
"description": "Helpers to integrate Prismic into Next.js apps",
|
|
9
9
|
"keywords": [
|
|
10
10
|
"typescript",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"@rollup/plugin-typescript": "^12.1.2",
|
|
74
74
|
"@size-limit/preset-small-lib": "^11.1.6",
|
|
75
75
|
"@types/node": "^22.10.2",
|
|
76
|
-
"@types/react": "^19.
|
|
76
|
+
"@types/react": "^19.2.3",
|
|
77
77
|
"@vitejs/plugin-react": "^4.3.4",
|
|
78
78
|
"dotenv": "^16.4.7",
|
|
79
79
|
"eslint": "^9.17.0",
|
|
@@ -82,12 +82,12 @@
|
|
|
82
82
|
"eslint-plugin-react": "^7.37.2",
|
|
83
83
|
"eslint-plugin-react-hooks": "^5.1.0",
|
|
84
84
|
"eslint-plugin-tsdoc": "^0.4.0",
|
|
85
|
-
"next": "
|
|
85
|
+
"next": "16.0.8",
|
|
86
86
|
"playwright": "^1.49.1",
|
|
87
87
|
"prettier": "^3.4.2",
|
|
88
88
|
"prettier-plugin-jsdoc": "^1.3.0",
|
|
89
|
-
"react": "^19.
|
|
90
|
-
"react-dom": "^19.
|
|
89
|
+
"react": "^19.2.1",
|
|
90
|
+
"react-dom": "^19.2.1",
|
|
91
91
|
"rollup-preserve-directives": "^1.1.3",
|
|
92
92
|
"size-limit": "^11.1.6",
|
|
93
93
|
"standard-version": "^9.5.0",
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
},
|
|
98
98
|
"peerDependencies": {
|
|
99
99
|
"@prismicio/client": "^7",
|
|
100
|
-
"next": "^13.4.5 || ^14 || ^15",
|
|
100
|
+
"next": "^13.4.5 || ^14 || ^15 || ^16",
|
|
101
101
|
"react": "^18 || ^19"
|
|
102
102
|
},
|
|
103
103
|
"engines": {
|
package/src/PrismicNextImage.tsx
CHANGED
|
@@ -11,7 +11,7 @@ import { buildURL, ImgixURLParams } from "imgix-url-builder";
|
|
|
11
11
|
import { ImageFieldImage, isFilled } from "@prismicio/client";
|
|
12
12
|
|
|
13
13
|
import { devMsg } from "./lib/devMsg";
|
|
14
|
-
import {
|
|
14
|
+
import { resolveDefaultExport } from "./lib/resolveDefaultExport";
|
|
15
15
|
|
|
16
16
|
import { imgixLoader } from "./imgixLoader";
|
|
17
17
|
|
|
@@ -163,7 +163,7 @@ export const PrismicNextImage: ForwardRefExoticComponent<
|
|
|
163
163
|
);
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
const ResolvedImage =
|
|
166
|
+
const ResolvedImage = resolveDefaultExport(Image);
|
|
167
167
|
|
|
168
168
|
return (
|
|
169
169
|
<ResolvedImage
|
package/src/PrismicNextLink.tsx
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
asLinkAttrs,
|
|
9
9
|
} from "@prismicio/client";
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import { resolveDefaultExport } from "./lib/resolveDefaultExport";
|
|
12
12
|
|
|
13
13
|
export type PrismicNextLinkProps = Omit<
|
|
14
14
|
ComponentProps<typeof Link>,
|
|
@@ -55,7 +55,7 @@ export const PrismicNextLink = forwardRef<
|
|
|
55
55
|
rel = restProps.rel;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
const ResolvedLink =
|
|
58
|
+
const ResolvedLink = resolveDefaultExport(Link);
|
|
59
59
|
|
|
60
60
|
return (
|
|
61
61
|
<ResolvedLink ref={ref} {...attrs} {...restProps} href={href} rel={rel}>
|
package/src/PrismicPreview.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import type { FC, ReactNode } from "react";
|
|
|
2
2
|
import Script from "next/script";
|
|
3
3
|
import { getToolbarSrc } from "@prismicio/client";
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { resolveDefaultExport } from "./lib/resolveDefaultExport";
|
|
6
6
|
import { PrismicPreviewClient } from "./PrismicPreviewClient";
|
|
7
7
|
|
|
8
8
|
/** Props for `<PrismicPreview>`. */
|
|
@@ -49,7 +49,7 @@ export const PrismicPreview: FC<PrismicPreviewProps> = async (props) => {
|
|
|
49
49
|
const toolbarSrc = getToolbarSrc(repositoryName);
|
|
50
50
|
const isDraftMode = (await draftMode()).isEnabled;
|
|
51
51
|
|
|
52
|
-
const ResolvedScript =
|
|
52
|
+
const ResolvedScript = resolveDefaultExport(Script);
|
|
53
53
|
|
|
54
54
|
return (
|
|
55
55
|
<>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves a module's default export. The module may provide its default export
|
|
3
|
+
* as a `default` property on an object. This happens when named and default
|
|
4
|
+
* exports are mixed in modules.
|
|
5
|
+
*
|
|
6
|
+
* In ES Modules, mixing is fine since the module resolver can distinguish
|
|
7
|
+
* default and named exports. In transpiled modules, however, all exports are
|
|
8
|
+
* put into a single object, and the default export is provided at a property
|
|
9
|
+
* called `default`.
|
|
10
|
+
*
|
|
11
|
+
* This helper is needed by Next.js uses CJS files with named and default
|
|
12
|
+
* exports.
|
|
13
|
+
*
|
|
14
|
+
* This helper _should_ be a temporary hack until Next.js and Node.js resolve
|
|
15
|
+
* their ESM difficulties. This will likely not be removed any time soon,
|
|
16
|
+
* unfortunately.
|
|
17
|
+
*/
|
|
18
|
+
export function resolveDefaultExport<T>(mod: T): T {
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
+
return "default" in (mod as any) ? (mod as any).default : mod;
|
|
21
|
+
}
|
package/dist/lib/resolveCJS.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"resolveCJS.cjs","sources":["../../src/lib/resolveCJS.ts"],"sourcesContent":["/**\n * Resolves a CommonJS import that might have a `default` property. This happens\n * when named and default exports are mixed in modules. Next.js seems to do this\n * in the exact set up `@prismicio/next` uses.\n *\n * This is _should_ be a temporary hack until Next.js and Node.js resolve their\n * ESM difficulties. This will likely not be removed any time soon.\n */\nexport function resolveCJS<T>(mod: T): T {\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\treturn \"default\" in (mod as any) ? (mod as any).default : mod;\n}\n"],"names":[],"mappings":";;AAQM,SAAU,WAAc,KAAM;AAE5B,SAAA,aAAc,MAAe,IAAY,UAAU;AAC3D;;"}
|
package/dist/lib/resolveCJS.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Resolves a CommonJS import that might have a `default` property. This happens
|
|
3
|
-
* when named and default exports are mixed in modules. Next.js seems to do this
|
|
4
|
-
* in the exact set up `@prismicio/next` uses.
|
|
5
|
-
*
|
|
6
|
-
* This is _should_ be a temporary hack until Next.js and Node.js resolve their
|
|
7
|
-
* ESM difficulties. This will likely not be removed any time soon.
|
|
8
|
-
*/
|
|
9
|
-
export declare function resolveCJS<T>(mod: T): T;
|
package/src/lib/resolveCJS.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Resolves a CommonJS import that might have a `default` property. This happens
|
|
3
|
-
* when named and default exports are mixed in modules. Next.js seems to do this
|
|
4
|
-
* in the exact set up `@prismicio/next` uses.
|
|
5
|
-
*
|
|
6
|
-
* This is _should_ be a temporary hack until Next.js and Node.js resolve their
|
|
7
|
-
* ESM difficulties. This will likely not be removed any time soon.
|
|
8
|
-
*/
|
|
9
|
-
export function resolveCJS<T>(mod: T): T {
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
-
return "default" in (mod as any) ? (mod as any).default : mod;
|
|
12
|
-
}
|