@prismicio/next 2.2.0-pr.125.afe01f5 → 2.2.0-pr.128.294b07c

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.
Files changed (67) hide show
  1. package/dist/PrismicNextImage.cjs +71 -0
  2. package/dist/PrismicNextImage.cjs.map +1 -0
  3. package/dist/PrismicNextImage.d.cts +57 -0
  4. package/dist/PrismicNextLink.cjs +31 -0
  5. package/dist/PrismicNextLink.cjs.map +1 -0
  6. package/dist/PrismicNextLink.d.cts +54 -0
  7. package/dist/PrismicPreview.cjs +41 -0
  8. package/dist/PrismicPreview.cjs.map +1 -0
  9. package/dist/PrismicPreview.d.cts +36 -0
  10. package/dist/PrismicPreviewClient.cjs +77 -0
  11. package/dist/PrismicPreviewClient.cjs.map +1 -0
  12. package/dist/SliceSimulator.cjs +49 -0
  13. package/dist/SliceSimulator.cjs.map +1 -0
  14. package/dist/SliceSimulator.d.cts +25 -0
  15. package/dist/SliceSimulatorWrapper.cjs +36 -0
  16. package/dist/SliceSimulatorWrapper.cjs.map +1 -0
  17. package/dist/_virtual/rolldown_runtime.cjs +29 -0
  18. package/dist/createLocaleRedirect.cjs +14 -0
  19. package/dist/createLocaleRedirect.cjs.map +1 -0
  20. package/dist/createLocaleRedirect.d.cts +14 -0
  21. package/dist/enableAutoPreviews.cjs +30 -0
  22. package/dist/enableAutoPreviews.cjs.map +1 -0
  23. package/dist/enableAutoPreviews.d.cts +18 -0
  24. package/dist/exitPreview.cjs +27 -0
  25. package/dist/exitPreview.cjs.map +1 -0
  26. package/dist/exitPreview.d.cts +21 -0
  27. package/dist/getSlices.cjs +12 -0
  28. package/dist/getSlices.cjs.map +1 -0
  29. package/dist/getSlices.d.cts +7 -0
  30. package/dist/imgixLoader.cjs +24 -0
  31. package/dist/imgixLoader.cjs.map +1 -0
  32. package/dist/imgixLoader.d.cts +15 -0
  33. package/dist/index.cjs +21 -0
  34. package/dist/index.d.cts +12 -0
  35. package/dist/lib/devMsg.cjs +25 -0
  36. package/dist/lib/devMsg.cjs.map +1 -0
  37. package/dist/lib/resolveDefaultExport.cjs +26 -0
  38. package/dist/lib/resolveDefaultExport.cjs.map +1 -0
  39. package/dist/package.cjs +12 -0
  40. package/dist/package.cjs.map +1 -0
  41. package/dist/package.js +1 -1
  42. package/dist/pages/PrismicPreview.cjs +76 -0
  43. package/dist/pages/PrismicPreview.cjs.map +1 -0
  44. package/dist/pages/PrismicPreview.d.cts +36 -0
  45. package/dist/pages/SliceSimulator.cjs +41 -0
  46. package/dist/pages/SliceSimulator.cjs.map +1 -0
  47. package/dist/pages/SliceSimulator.d.cts +37 -0
  48. package/dist/pages/enableAutoPreviews.cjs +26 -0
  49. package/dist/pages/enableAutoPreviews.cjs.map +1 -0
  50. package/dist/pages/enableAutoPreviews.d.cts +37 -0
  51. package/dist/pages/exitPreview.cjs +27 -0
  52. package/dist/pages/exitPreview.cjs.map +1 -0
  53. package/dist/pages/exitPreview.d.cts +38 -0
  54. package/dist/pages/redirectToPreviewURL.cjs +16 -0
  55. package/dist/pages/redirectToPreviewURL.cjs.map +1 -0
  56. package/dist/pages/redirectToPreviewURL.d.cts +48 -0
  57. package/dist/pages/setPreviewData.cjs +13 -0
  58. package/dist/pages/setPreviewData.cjs.map +1 -0
  59. package/dist/pages/setPreviewData.d.cts +26 -0
  60. package/dist/pages/types.d.cts +36 -0
  61. package/dist/pages.cjs +21 -0
  62. package/dist/pages.d.cts +12 -0
  63. package/dist/redirectToPreviewURL.cjs +24 -0
  64. package/dist/redirectToPreviewURL.cjs.map +1 -0
  65. package/dist/redirectToPreviewURL.d.cts +33 -0
  66. package/dist/types.d.cts +31 -0
  67. package/package.json +12 -4
@@ -0,0 +1,71 @@
1
+ "use client";
2
+
3
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
4
+ const require_resolveDefaultExport = require('./lib/resolveDefaultExport.cjs');
5
+ const require_devMsg = require('./lib/devMsg.cjs');
6
+ const require_imgixLoader = require('./imgixLoader.cjs');
7
+ let _prismicio_client = require("@prismicio/client");
8
+ let react = require("react");
9
+ let react_jsx_runtime = require("react/jsx-runtime");
10
+ let next_image = require("next/image");
11
+ next_image = require_rolldown_runtime.__toESM(next_image);
12
+ let imgix_url_builder = require("imgix-url-builder");
13
+
14
+ //#region src/PrismicNextImage.tsx
15
+ const castInt = (input) => {
16
+ if (typeof input === "number" || typeof input === "undefined") return input;
17
+ else {
18
+ const parsed = Number.parseInt(input);
19
+ if (Number.isNaN(parsed)) return;
20
+ else return parsed;
21
+ }
22
+ };
23
+ /**
24
+ * React component that renders an image from a Prismic Image field or one of
25
+ * its thumbnails using `next/image`. It will automatically set the `alt`
26
+ * attribute using the Image field's `alt` property.
27
+ *
28
+ * It uses an Imgix URL-based loader by default. A custom loader can be provided
29
+ * with the `loader` prop. If you would like to use the Next.js Image
30
+ * Optimization API instead, set `loader={undefined}`.
31
+ *
32
+ * @param props - Props for the component.
33
+ *
34
+ * @returns A responsive image component using `next/image` for the given Image
35
+ * field.
36
+ *
37
+ * @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image
38
+ */
39
+ const PrismicNextImage = (0, react.forwardRef)(function PrismicNextImage$1({ field, imgixParams = {}, alt, fallbackAlt, fill, width, height, fallback = null, loader = require_imgixLoader.imgixLoader, ...restProps }, ref) {
40
+ if (process.env.NODE_ENV === "development") {
41
+ if (typeof alt === "string" && alt !== "") console.warn(`[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 ${require_devMsg.devMsg("alt-must-be-an-empty-string")}`);
42
+ if (typeof fallbackAlt === "string" && fallbackAlt !== "") console.warn(`[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 ${require_devMsg.devMsg("alt-must-be-an-empty-string")}`);
43
+ }
44
+ if (!_prismicio_client.isFilled.imageThumbnail(field)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: fallback });
45
+ const resolvedImgixParams = imgixParams;
46
+ for (const x in imgixParams) if (resolvedImgixParams[x] === null) resolvedImgixParams[x] = void 0;
47
+ const src = (0, imgix_url_builder.buildURL)(field.url, imgixParams);
48
+ const ar = field.dimensions.width / field.dimensions.height;
49
+ const castedWidth = castInt(width);
50
+ const castedHeight = castInt(height);
51
+ let resolvedWidth = castedWidth ?? field.dimensions.width;
52
+ let resolvedHeight = castedHeight ?? field.dimensions.height;
53
+ if (castedWidth != null && castedHeight == null) resolvedHeight = castedWidth / ar;
54
+ else if (castedWidth == null && castedHeight != null) resolvedWidth = castedHeight * ar;
55
+ const resolvedAlt = alt ?? (field.alt || fallbackAlt);
56
+ if (process.env.NODE_ENV === "development" && typeof resolvedAlt !== "string") console.error(`[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);
57
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_resolveDefaultExport.resolveDefaultExport(next_image.default), {
58
+ ref,
59
+ src,
60
+ width: fill ? void 0 : resolvedWidth,
61
+ height: fill ? void 0 : resolvedHeight,
62
+ alt: resolvedAlt,
63
+ fill,
64
+ loader: loader === null ? void 0 : loader,
65
+ ...restProps
66
+ });
67
+ });
68
+
69
+ //#endregion
70
+ exports.PrismicNextImage = PrismicNextImage;
71
+ //# sourceMappingURL=PrismicNextImage.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismicNextImage.cjs","names":["PrismicNextImage","imgixLoader","devMsg","isFilled","resolveDefaultExport","Image"],"sources":["../src/PrismicNextImage.tsx"],"sourcesContent":["\"use client\";\n\nimport type {\n\tForwardRefExoticComponent,\n\tPropsWithoutRef,\n\tRefAttributes} from \"react\";\nimport {\n\tforwardRef\n} from \"react\";\nimport type { ImageProps } from \"next/image\";\nimport Image from \"next/image\";\nimport type { ImgixURLParams } from \"imgix-url-builder\";\nimport { buildURL } from \"imgix-url-builder\";\nimport type { ImageFieldImage} from \"@prismicio/client\";\nimport { 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"],"mappings":";;;;;;;;;;;;;;AAqBA,MAAM,WAAW,UAA2D;AAC3E,KAAI,OAAO,UAAU,YAAY,OAAO,UAAU,YACjD,QAAO;MACD;EACN,MAAM,SAAS,OAAO,SAAS,MAAM;AAErC,MAAI,OAAO,MAAM,OAAO,CACvB;MAEA,QAAO;;;;;;;;;;;;;;;;;;;AA8DV,MAAa,yCAGZ,SAASA,mBACR,EACC,OACA,cAAc,EAAE,EAChB,KACA,aACA,MACA,OACA,QACA,WAAW,MACX,SAASC,iCACT,GAAG,aAEJ,KACC;AACD,KAAI,QAAQ,IAAI,aAAa,eAAe;AAC3C,MAAI,OAAO,QAAQ,YAAY,QAAQ,GACtC,SAAQ,KACP,yQAAyQC,sBACxQ,8BACA,GACD;AAGF,MAAI,OAAO,gBAAgB,YAAY,gBAAgB,GACtD,SAAQ,KACP,ySAAySA,sBACxS,8BACA,GACD;;AAIH,KAAI,CAACC,2BAAS,eAAe,MAAM,CAClC,QAAO,mFAAG,WAAY;CAGvB,MAAM,sBAAsB;AAC5B,MAAK,MAAM,KAAK,YACf,KAAI,oBAAoB,OAA2C,KAClE,qBAAoB,KAAyC;CAI/D,MAAM,sCAAe,MAAM,KAAK,YAA8B;CAE9D,MAAM,KAAK,MAAM,WAAW,QAAQ,MAAM,WAAW;CAErD,MAAM,cAAc,QAAQ,MAAM;CAClC,MAAM,eAAe,QAAQ,OAAO;CAEpC,IAAI,gBAAgB,eAAe,MAAM,WAAW;CACpD,IAAI,iBAAiB,gBAAgB,MAAM,WAAW;AAEtD,KAAI,eAAe,QAAQ,gBAAgB,KAC1C,kBAAiB,cAAc;UACrB,eAAe,QAAQ,gBAAgB,KACjD,iBAAgB,eAAe;CAKhC,MAAM,cAAe,QAAQ,MAAM,OAAO;AAE1C,KACC,QAAQ,IAAI,aAAa,iBACzB,OAAO,gBAAgB,SAEvB,SAAQ,MACP,mNACA,IACA;AAKF,QACC,2CAHqBC,kDAAqBC,mBAAM;EAI1C;EACA;EACL,OAAO,OAAO,SAAY;EAC1B,QAAQ,OAAO,SAAY;EAC3B,KAAK;EACC;EACN,QAAQ,WAAW,OAAO,SAAY;EACtC,GAAI;GACH;EAGJ"}
@@ -0,0 +1,57 @@
1
+ import { ForwardRefExoticComponent, PropsWithoutRef, RefAttributes } from "react";
2
+ import { ImageFieldImage } from "@prismicio/client";
3
+ import { ImageProps } from "next/image";
4
+ import { ImgixURLParams } from "imgix-url-builder";
5
+
6
+ //#region src/PrismicNextImage.d.ts
7
+ type PrismicNextImageProps = Omit<ImageProps, "src" | "alt" | "loader"> & {
8
+ /** The Prismic Image field or thumbnail to render. */
9
+ field: ImageFieldImage | null | undefined;
10
+ /**
11
+ * An object of Imgix URL API parameters to transform the image.
12
+ *
13
+ * @see https://docs.imgix.com/apis/rendering
14
+ */
15
+ imgixParams?: { [P in keyof ImgixURLParams]: ImgixURLParams[P] | null };
16
+ /**
17
+ * Declare an image as decorative by providing `alt=""`.
18
+ *
19
+ * See:
20
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
21
+ */
22
+ alt?: "";
23
+ /**
24
+ * Declare an image as decorative only if the Image field does not have
25
+ * alternative text by providing `fallbackAlt=""`.
26
+ *
27
+ * See:
28
+ * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
29
+ */
30
+ fallbackAlt?: "";
31
+ /**
32
+ * Rendered when the field is empty. If a fallback is not given, `null` will
33
+ * be rendered.
34
+ */
35
+ fallback?: React.ReactNode;
36
+ loader?: ImageProps["loader"] | null;
37
+ };
38
+ /**
39
+ * React component that renders an image from a Prismic Image field or one of
40
+ * its thumbnails using `next/image`. It will automatically set the `alt`
41
+ * attribute using the Image field's `alt` property.
42
+ *
43
+ * It uses an Imgix URL-based loader by default. A custom loader can be provided
44
+ * with the `loader` prop. If you would like to use the Next.js Image
45
+ * Optimization API instead, set `loader={undefined}`.
46
+ *
47
+ * @param props - Props for the component.
48
+ *
49
+ * @returns A responsive image component using `next/image` for the given Image
50
+ * field.
51
+ *
52
+ * @see To learn more about `next/image`, see: https://nextjs.org/docs/api-reference/next/image
53
+ */
54
+ declare const PrismicNextImage: ForwardRefExoticComponent<PropsWithoutRef<PrismicNextImageProps> & RefAttributes<HTMLImageElement>>;
55
+ //#endregion
56
+ export { PrismicNextImage, PrismicNextImageProps };
57
+ //# sourceMappingURL=PrismicNextImage.d.cts.map
@@ -0,0 +1,31 @@
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ const require_resolveDefaultExport = require('./lib/resolveDefaultExport.cjs');
3
+ let _prismicio_client = require("@prismicio/client");
4
+ let react = require("react");
5
+ let react_jsx_runtime = require("react/jsx-runtime");
6
+ let next_link = require("next/link");
7
+ next_link = require_rolldown_runtime.__toESM(next_link);
8
+
9
+ //#region src/PrismicNextLink.tsx
10
+ const PrismicNextLink = (0, react.forwardRef)(function PrismicNextLink$1(props, ref) {
11
+ const { field, document, linkResolver, children, ...restProps } = props;
12
+ const { href: computedHref, rel: computedRel, ...attrs } = (0, _prismicio_client.asLinkAttrs)(field ?? document, {
13
+ linkResolver,
14
+ rel: typeof restProps.rel === "function" ? restProps.rel : void 0
15
+ });
16
+ const href = ("href" in restProps ? restProps.href : computedHref) || "";
17
+ let rel = computedRel;
18
+ if ("rel" in restProps && typeof restProps.rel !== "function") rel = restProps.rel;
19
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_resolveDefaultExport.resolveDefaultExport(next_link.default), {
20
+ ref,
21
+ ...attrs,
22
+ ...restProps,
23
+ href,
24
+ rel,
25
+ children: "children" in props ? children : field?.text
26
+ });
27
+ });
28
+
29
+ //#endregion
30
+ exports.PrismicNextLink = PrismicNextLink;
31
+ //# sourceMappingURL=PrismicNextLink.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismicNextLink.cjs","names":["PrismicNextLink","resolveDefaultExport","Link"],"sources":["../src/PrismicNextLink.tsx"],"sourcesContent":["import type { ComponentProps} from \"react\";\nimport { forwardRef } from \"react\";\nimport Link from \"next/link\";\nimport type {\n\tAsLinkAttrsConfig,\n\tLinkField,\n\tLinkResolverFunction,\n\tPrismicDocument} from \"@prismicio/client\";\nimport {\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"],"mappings":";;;;;;;;;AAsCA,MAAa,wCAGX,SAASA,kBAAgB,OAAO,KAAK;CACtC,MAAM,EAAE,OAAO,UAAU,cAAc,UAAU,GAAG,cAAc;CAClE,MAAM,EACL,MAAM,cACN,KAAK,aACL,GAAG,6CACY,SAAS,UAAU;EAClC;EACA,KAAK,OAAO,UAAU,QAAQ,aAAa,UAAU,MAAM;EAC3D,CAAC;CAEF,MAAM,QAAQ,UAAU,YAAY,UAAU,OAAO,iBAAiB;CAEtE,IAAI,MAAM;AACV,KAAI,SAAS,aAAa,OAAO,UAAU,QAAQ,WAClD,OAAM,UAAU;AAKjB,QACC,2CAHoBC,kDAAqBC,kBAAK;EAG3B;EAAK,GAAI;EAAO,GAAI;EAAiB;EAAW;YACjE,cAAc,QAAQ,WAAW,OAAO;GAC3B;EAEf"}
@@ -0,0 +1,54 @@
1
+ import * as react0 from "react";
2
+ import { ComponentProps } from "react";
3
+ import * as next_link0 from "next/link";
4
+ import Link from "next/link";
5
+ import { AsLinkAttrsConfig, LinkField, LinkResolverFunction, PrismicDocument } from "@prismicio/client";
6
+
7
+ //#region src/PrismicNextLink.d.ts
8
+ type PrismicNextLinkProps = Omit<ComponentProps<typeof Link>, "field" | "document" | "href" | "rel"> & {
9
+ linkResolver?: LinkResolverFunction;
10
+ rel?: string | AsLinkAttrsConfig["rel"];
11
+ } & ({
12
+ field: LinkField | null | undefined;
13
+ document?: never;
14
+ href?: never;
15
+ } | {
16
+ field?: never;
17
+ document: PrismicDocument | null | undefined;
18
+ href?: never;
19
+ } | {
20
+ field?: never;
21
+ document?: never;
22
+ href: ComponentProps<typeof Link>["href"];
23
+ });
24
+ declare const PrismicNextLink: react0.ForwardRefExoticComponent<(Omit<Omit<Omit<react0.AnchorHTMLAttributes<HTMLAnchorElement>, keyof next_link0.LinkProps<any>> & next_link0.LinkProps<any> & {
25
+ children?: React.ReactNode | undefined;
26
+ } & react0.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
27
+ linkResolver?: LinkResolverFunction;
28
+ rel?: string | AsLinkAttrsConfig["rel"];
29
+ } & {
30
+ field: LinkField | null | undefined;
31
+ document?: never;
32
+ href?: never;
33
+ }, "ref"> | Omit<Omit<Omit<react0.AnchorHTMLAttributes<HTMLAnchorElement>, keyof next_link0.LinkProps<any>> & next_link0.LinkProps<any> & {
34
+ children?: React.ReactNode | undefined;
35
+ } & react0.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
36
+ linkResolver?: LinkResolverFunction;
37
+ rel?: string | AsLinkAttrsConfig["rel"];
38
+ } & {
39
+ field?: never;
40
+ document: PrismicDocument | null | undefined;
41
+ href?: never;
42
+ }, "ref"> | Omit<Omit<Omit<react0.AnchorHTMLAttributes<HTMLAnchorElement>, keyof next_link0.LinkProps<any>> & next_link0.LinkProps<any> & {
43
+ children?: React.ReactNode | undefined;
44
+ } & react0.RefAttributes<HTMLAnchorElement>, "href" | "rel" | "field" | "document"> & {
45
+ linkResolver?: LinkResolverFunction;
46
+ rel?: string | AsLinkAttrsConfig["rel"];
47
+ } & {
48
+ field?: never;
49
+ document?: never;
50
+ href: ComponentProps<typeof Link>["href"];
51
+ }, "ref">) & react0.RefAttributes<HTMLAnchorElement>>;
52
+ //#endregion
53
+ export { PrismicNextLink, PrismicNextLinkProps };
54
+ //# sourceMappingURL=PrismicNextLink.d.cts.map
@@ -0,0 +1,41 @@
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ const require_resolveDefaultExport = require('./lib/resolveDefaultExport.cjs');
3
+ const require_PrismicPreviewClient = require('./PrismicPreviewClient.cjs');
4
+ let next_script = require("next/script");
5
+ next_script = require_rolldown_runtime.__toESM(next_script);
6
+ let _prismicio_client = require("@prismicio/client");
7
+ let react_jsx_runtime = require("react/jsx-runtime");
8
+
9
+ //#region src/PrismicPreview.tsx
10
+ /**
11
+ * React component that sets up Prismic Previews using the Prismic Toolbar. When
12
+ * the Prismic Toolbar send events to the browser, such as on preview updates
13
+ * and exiting, this component will automatically refresh the page with the
14
+ * changes.
15
+ *
16
+ * This component can be wrapped around your app or added anywhere in your app's
17
+ * tree. It must be rendered on every page.
18
+ */
19
+ const PrismicPreview = async (props) => {
20
+ const { repositoryName, children, ...otherProps } = props;
21
+ const { draftMode } = await import("next/headers");
22
+ const toolbarSrc = (0, _prismicio_client.getToolbarSrc)(repositoryName);
23
+ const isDraftMode = (await draftMode()).isEnabled;
24
+ const ResolvedScript = require_resolveDefaultExport.resolveDefaultExport(next_script.default);
25
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
26
+ children,
27
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_PrismicPreviewClient.PrismicPreviewClient, {
28
+ repositoryName,
29
+ isDraftMode,
30
+ ...otherProps
31
+ }),
32
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ResolvedScript, {
33
+ src: toolbarSrc,
34
+ strategy: "lazyOnload"
35
+ })
36
+ ] });
37
+ };
38
+
39
+ //#endregion
40
+ exports.PrismicPreview = PrismicPreview;
41
+ //# sourceMappingURL=PrismicPreview.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismicPreview.cjs","names":["resolveDefaultExport","Script","PrismicPreviewClient"],"sources":["../src/PrismicPreview.tsx"],"sourcesContent":["import type { FC, ReactNode } from \"react\";\nimport Script from \"next/script\";\nimport { getToolbarSrc } from \"@prismicio/client\";\n\nimport { resolveDefaultExport } from \"./lib/resolveDefaultExport\";\nimport { PrismicPreviewClient } from \"./PrismicPreviewClient\";\n\n/** Props for `<PrismicPreview>`. */\nexport type PrismicPreviewProps = {\n\t/**\n\t * The name of your Prismic repository. A Prismic Toolbar will be registered\n\t * using this repository.\n\t */\n\trepositoryName: string;\n\n\t/**\n\t * The URL of your app's Prismic preview endpoint (default: `/api/preview`).\n\t * This URL will be fetched on preview update events.\n\t */\n\tupdatePreviewURL?: string;\n\n\t/**\n\t * The URL of your app's exit preview endpoint (default: `/api/exit-preview`).\n\t * This URL will be fetched on preview exit events.\n\t */\n\texitPreviewURL?: string;\n\n\t/** Children to render adjacent to the Prismic Toolbar. */\n\tchildren?: ReactNode;\n};\n\n/**\n * React component that sets up Prismic Previews using the Prismic Toolbar. When\n * the Prismic Toolbar send events to the browser, such as on preview updates\n * and exiting, this component will automatically refresh the page with the\n * changes.\n *\n * This component can be wrapped around your app or added anywhere in your app's\n * tree. It must be rendered on every page.\n */\nexport const PrismicPreview: FC<PrismicPreviewProps> = async (props) => {\n\tconst { repositoryName, children, ...otherProps } = props;\n\n\t// Need this to avoid the following Next.js build-time error:\n\t// You're importing a component that needs next/headers. That only works\n\t// in a Server Component which is not supported in the pages/ directory.\n\tconst { draftMode } = await import(\"next/headers\");\n\n\tconst toolbarSrc = getToolbarSrc(repositoryName);\n\tconst isDraftMode = (await draftMode()).isEnabled;\n\n\tconst ResolvedScript = resolveDefaultExport(Script);\n\n\treturn (\n\t\t<>\n\t\t\t{children}\n\t\t\t<PrismicPreviewClient\n\t\t\t\trepositoryName={repositoryName}\n\t\t\t\tisDraftMode={isDraftMode}\n\t\t\t\t{...otherProps}\n\t\t\t/>\n\t\t\t<ResolvedScript src={toolbarSrc} strategy=\"lazyOnload\" />\n\t\t</>\n\t);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAwCA,MAAa,iBAA0C,OAAO,UAAU;CACvE,MAAM,EAAE,gBAAgB,UAAU,GAAG,eAAe;CAKpD,MAAM,EAAE,cAAc,MAAM,OAAO;CAEnC,MAAM,kDAA2B,eAAe;CAChD,MAAM,eAAe,MAAM,WAAW,EAAE;CAExC,MAAM,iBAAiBA,kDAAqBC,oBAAO;AAEnD,QACC;EACE;EACD,2CAACC;GACgB;GACH;GACb,GAAI;IACH;EACF,2CAAC;GAAe,KAAK;GAAY,UAAS;IAAe;KACvD"}
@@ -0,0 +1,36 @@
1
+ import { FC, ReactNode } from "react";
2
+
3
+ //#region src/PrismicPreview.d.ts
4
+ /** Props for `<PrismicPreview>`. */
5
+ type PrismicPreviewProps = {
6
+ /**
7
+ * The name of your Prismic repository. A Prismic Toolbar will be registered
8
+ * using this repository.
9
+ */
10
+ repositoryName: string;
11
+ /**
12
+ * The URL of your app's Prismic preview endpoint (default: `/api/preview`).
13
+ * This URL will be fetched on preview update events.
14
+ */
15
+ updatePreviewURL?: string;
16
+ /**
17
+ * The URL of your app's exit preview endpoint (default: `/api/exit-preview`).
18
+ * This URL will be fetched on preview exit events.
19
+ */
20
+ exitPreviewURL?: string;
21
+ /** Children to render adjacent to the Prismic Toolbar. */
22
+ children?: ReactNode;
23
+ };
24
+ /**
25
+ * React component that sets up Prismic Previews using the Prismic Toolbar. When
26
+ * the Prismic Toolbar send events to the browser, such as on preview updates
27
+ * and exiting, this component will automatically refresh the page with the
28
+ * changes.
29
+ *
30
+ * This component can be wrapped around your app or added anywhere in your app's
31
+ * tree. It must be rendered on every page.
32
+ */
33
+ declare const PrismicPreview: FC<PrismicPreviewProps>;
34
+ //#endregion
35
+ export { PrismicPreview, PrismicPreviewProps };
36
+ //# sourceMappingURL=PrismicPreview.d.cts.map
@@ -0,0 +1,77 @@
1
+ "use client";
2
+
3
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
4
+ let _prismicio_client = require("@prismicio/client");
5
+ let next_navigation = require("next/navigation");
6
+ let react = require("react");
7
+
8
+ //#region src/PrismicPreviewClient.tsx
9
+ const PrismicPreviewClient = (props) => {
10
+ const { repositoryName, isDraftMode, updatePreviewURL = "/api/preview", exitPreviewURL = "/api/exit-preview" } = props;
11
+ const { refresh } = (0, next_navigation.useRouter)();
12
+ (0, react.useEffect)(() => {
13
+ const controller = new AbortController();
14
+ window.addEventListener("prismicPreviewUpdate", onUpdate, { signal: controller.signal });
15
+ window.addEventListener("prismicPreviewEnd", onEnd, { signal: controller.signal });
16
+ const cookie = getPrismicPreviewCookie(window.document.cookie);
17
+ if ((cookie ? (decodeURIComponent(cookie).match(/"([^"]+)\.prismic\.io"/) || [])[1] : void 0) === repositoryName && !isDraftMode) globalThis.fetch(updatePreviewURL, {
18
+ redirect: "manual",
19
+ signal: controller.signal
20
+ }).then((res) => {
21
+ if (res.type !== "opaqueredirect") {
22
+ console.error(`[<PrismicPreview>] Failed to start the preview using "${updatePreviewURL}". Does it exist?`);
23
+ return;
24
+ }
25
+ refresh();
26
+ }).catch(() => {});
27
+ function onUpdate(event) {
28
+ event.preventDefault();
29
+ refresh();
30
+ }
31
+ function onEnd(event) {
32
+ event.preventDefault();
33
+ globalThis.fetch(exitPreviewURL, { signal: controller.signal }).then((res) => {
34
+ if (!res.ok) {
35
+ console.error(`[<PrismicPreview>] Failed to exit Preview Mode using the "${exitPreviewURL}" API endpoint. Does it exist?`);
36
+ return;
37
+ }
38
+ refresh();
39
+ }).catch(() => {});
40
+ }
41
+ return () => controller.abort();
42
+ }, [
43
+ repositoryName,
44
+ isDraftMode,
45
+ updatePreviewURL,
46
+ exitPreviewURL,
47
+ refresh
48
+ ]);
49
+ return null;
50
+ };
51
+ /**
52
+ * Returns the value of a cookie from a given cookie store.
53
+ *
54
+ * @param cookieJar - The stringified cookie store from which to read the
55
+ * cookie.
56
+ *
57
+ * @returns The value of the cookie, if it exists.
58
+ */
59
+ function getPrismicPreviewCookie(cookieJar) {
60
+ function readValue(value$1) {
61
+ return value$1.replace(/%3B/g, ";");
62
+ }
63
+ const cookies = cookieJar.split("; ");
64
+ let value;
65
+ for (const cookie of cookies) {
66
+ const parts = cookie.split("=");
67
+ if (readValue(parts[0]).replace(/%3D/g, "=") === _prismicio_client.cookie.preview) {
68
+ value = readValue(parts.slice(1).join("="));
69
+ continue;
70
+ }
71
+ }
72
+ return value;
73
+ }
74
+
75
+ //#endregion
76
+ exports.PrismicPreviewClient = PrismicPreviewClient;
77
+ //# sourceMappingURL=PrismicPreviewClient.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrismicPreviewClient.cjs","names":["value","prismicCookie"],"sources":["../src/PrismicPreviewClient.tsx"],"sourcesContent":["\"use client\";\n\nimport { cookie as prismicCookie } from \"@prismicio/client\";\nimport { useRouter } from \"next/navigation\";\nimport type { FC } from \"react\";\nimport { useEffect } from \"react\";\n\ntype PrismicPreviewClientProps = {\n\trepositoryName: string;\n\tisDraftMode: boolean;\n\tupdatePreviewURL?: string;\n\texitPreviewURL?: string;\n};\n\nexport const PrismicPreviewClient: FC<PrismicPreviewClientProps> = (props) => {\n\tconst {\n\t\trepositoryName,\n\t\tisDraftMode,\n\t\tupdatePreviewURL = \"/api/preview\",\n\t\texitPreviewURL = \"/api/exit-preview\",\n\t} = props;\n\n\tconst { refresh } = useRouter();\n\n\tuseEffect(() => {\n\t\tconst controller = new AbortController();\n\n\t\twindow.addEventListener(\"prismicPreviewUpdate\", onUpdate, {\n\t\t\tsignal: controller.signal,\n\t\t});\n\t\twindow.addEventListener(\"prismicPreviewEnd\", onEnd, {\n\t\t\tsignal: controller.signal,\n\t\t});\n\n\t\tconst cookie = getPrismicPreviewCookie(window.document.cookie);\n\t\tconst cookieRepositoryName = cookie\n\t\t\t? (decodeURIComponent(cookie).match(/\"([^\"]+)\\.prismic\\.io\"/) || [])[1]\n\t\t\t: undefined;\n\t\tconst hasCookieForRepository = cookieRepositoryName === repositoryName;\n\n\t\t// Start the preview for preview share links. Previews from\n\t\t// share links do not go to the `updatePreviewURL` like a normal\n\t\t// preview.\n\t\tif (hasCookieForRepository && !isDraftMode) {\n\t\t\t// We check `opaqueredirect` because we don't care if\n\t\t\t// the redirect was successful or not. As long as it\n\t\t\t// redirects, we know the endpoint exists and draft mode\n\t\t\t// is active.\n\t\t\tglobalThis\n\t\t\t\t.fetch(updatePreviewURL, {\n\t\t\t\t\tredirect: \"manual\",\n\t\t\t\t\tsignal: controller.signal,\n\t\t\t\t})\n\t\t\t\t.then((res) => {\n\t\t\t\t\tif (res.type !== \"opaqueredirect\") {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`[<PrismicPreview>] Failed to start the preview using \"${updatePreviewURL}\". Does it exist?`,\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\trefresh();\n\t\t\t\t})\n\t\t\t\t.catch(() => {\n\t\t\t\t\t// noop\n\t\t\t\t});\n\t\t}\n\n\t\tfunction onUpdate(event: Event) {\n\t\t\tevent.preventDefault();\n\t\t\trefresh();\n\t\t}\n\n\t\tfunction onEnd(event: Event) {\n\t\t\tevent.preventDefault();\n\t\t\tglobalThis\n\t\t\t\t.fetch(exitPreviewURL, { signal: controller.signal })\n\t\t\t\t.then((res) => {\n\t\t\t\t\tif (!res.ok) {\n\t\t\t\t\t\tconsole.error(\n\t\t\t\t\t\t\t`[<PrismicPreview>] Failed to exit Preview Mode using the \"${exitPreviewURL}\" API endpoint. Does it exist?`,\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\trefresh();\n\t\t\t\t})\n\t\t\t\t.catch(() => {\n\t\t\t\t\t// noop\n\t\t\t\t});\n\t\t}\n\n\t\treturn () => controller.abort();\n\t}, [repositoryName, isDraftMode, updatePreviewURL, exitPreviewURL, refresh]);\n\n\treturn null;\n};\n\n/**\n * Returns the value of a cookie from a given cookie store.\n *\n * @param cookieJar - The stringified cookie store from which to read the\n * cookie.\n *\n * @returns The value of the cookie, if it exists.\n */\nfunction getPrismicPreviewCookie(cookieJar: string): string | undefined {\n\tfunction readValue(value: string): string {\n\t\treturn value.replace(/%3B/g, \";\");\n\t}\n\n\tconst cookies = cookieJar.split(\"; \");\n\n\tlet value: string | undefined;\n\n\tfor (const cookie of cookies) {\n\t\tconst parts = cookie.split(\"=\");\n\t\tconst name = readValue(parts[0]).replace(/%3D/g, \"=\");\n\n\t\tif (name === prismicCookie.preview) {\n\t\t\tvalue = readValue(parts.slice(1).join(\"=\"));\n\t\t\tcontinue;\n\t\t}\n\t}\n\n\treturn value;\n}\n"],"mappings":";;;;;;;;AAcA,MAAa,wBAAuD,UAAU;CAC7E,MAAM,EACL,gBACA,aACA,mBAAmB,gBACnB,iBAAiB,wBACd;CAEJ,MAAM,EAAE,4CAAuB;AAE/B,4BAAgB;EACf,MAAM,aAAa,IAAI,iBAAiB;AAExC,SAAO,iBAAiB,wBAAwB,UAAU,EACzD,QAAQ,WAAW,QACnB,CAAC;AACF,SAAO,iBAAiB,qBAAqB,OAAO,EACnD,QAAQ,WAAW,QACnB,CAAC;EAEF,MAAM,SAAS,wBAAwB,OAAO,SAAS,OAAO;AAS9D,OAR6B,UACzB,mBAAmB,OAAO,CAAC,MAAM,yBAAyB,IAAI,EAAE,EAAE,KACnE,YACqD,kBAK1B,CAAC,YAK9B,YACE,MAAM,kBAAkB;GACxB,UAAU;GACV,QAAQ,WAAW;GACnB,CAAC,CACD,MAAM,QAAQ;AACd,OAAI,IAAI,SAAS,kBAAkB;AAClC,YAAQ,MACP,yDAAyD,iBAAiB,mBAC1E;AAED;;AAGD,YAAS;IACR,CACD,YAAY,GAEX;EAGJ,SAAS,SAAS,OAAc;AAC/B,SAAM,gBAAgB;AACtB,YAAS;;EAGV,SAAS,MAAM,OAAc;AAC5B,SAAM,gBAAgB;AACtB,cACE,MAAM,gBAAgB,EAAE,QAAQ,WAAW,QAAQ,CAAC,CACpD,MAAM,QAAQ;AACd,QAAI,CAAC,IAAI,IAAI;AACZ,aAAQ,MACP,6DAA6D,eAAe,gCAC5E;AAED;;AAGD,aAAS;KACR,CACD,YAAY,GAEX;;AAGJ,eAAa,WAAW,OAAO;IAC7B;EAAC;EAAgB;EAAa;EAAkB;EAAgB;EAAQ,CAAC;AAE5E,QAAO;;;;;;;;;;AAWR,SAAS,wBAAwB,WAAuC;CACvE,SAAS,UAAU,SAAuB;AACzC,SAAOA,QAAM,QAAQ,QAAQ,IAAI;;CAGlC,MAAM,UAAU,UAAU,MAAM,KAAK;CAErC,IAAI;AAEJ,MAAK,MAAM,UAAU,SAAS;EAC7B,MAAM,QAAQ,OAAO,MAAM,IAAI;AAG/B,MAFa,UAAU,MAAM,GAAG,CAAC,QAAQ,QAAQ,IAAI,KAExCC,yBAAc,SAAS;AACnC,WAAQ,UAAU,MAAM,MAAM,EAAE,CAAC,KAAK,IAAI,CAAC;AAC3C;;;AAIF,QAAO"}
@@ -0,0 +1,49 @@
1
+ "use client";
2
+
3
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
4
+ const require_SliceSimulatorWrapper = require('./SliceSimulatorWrapper.cjs');
5
+ const require_getSlices = require('./getSlices.cjs');
6
+ let next_navigation = require("next/navigation");
7
+ let react = require("react");
8
+ let react_jsx_runtime = require("react/jsx-runtime");
9
+ let _prismicio_simulator_kit = require("@prismicio/simulator/kit");
10
+ let lz_string = require("lz-string");
11
+
12
+ //#region src/SliceSimulator.tsx
13
+ const STATE_PARAMS_KEY = "state";
14
+ const simulatorManager = new _prismicio_simulator_kit.SimulatorManager();
15
+ /**
16
+ * Simulate slices in isolation. The slice simulator enables live slice
17
+ * development in Slice Machine and live previews in the Page Builder.
18
+ */
19
+ const SliceSimulator = ({ children, background, zIndex, className }) => {
20
+ const [message, setMessage] = (0, react.useState)(() => (0, _prismicio_simulator_kit.getDefaultMessage)());
21
+ const router = (0, next_navigation.useRouter)();
22
+ const hasSlices = require_getSlices.getSlices(typeof window !== "undefined" ? new URL(window.location.href).searchParams.get(STATE_PARAMS_KEY) : void 0).length > 0;
23
+ (0, react.useEffect)(() => {
24
+ simulatorManager.state.on(_prismicio_simulator_kit.StateEventType.Slices, (newSlices) => {
25
+ const url = new URL(window.location.href);
26
+ url.searchParams.set(STATE_PARAMS_KEY, (0, lz_string.compressToEncodedURIComponent)(JSON.stringify(newSlices)));
27
+ window.history.replaceState(null, "", url);
28
+ setTimeout(() => router.refresh(), 0);
29
+ }, "simulator-slices");
30
+ simulatorManager.state.on(_prismicio_simulator_kit.StateEventType.Message, (newMessage) => setMessage(newMessage), "simulator-message");
31
+ simulatorManager.init();
32
+ return () => {
33
+ simulatorManager.state.off(_prismicio_simulator_kit.StateEventType.Slices, "simulator-slices");
34
+ simulatorManager.state.off(_prismicio_simulator_kit.StateEventType.Message, "simulator-message");
35
+ };
36
+ }, [router]);
37
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_SliceSimulatorWrapper.SliceSimulatorWrapper, {
38
+ message,
39
+ hasSlices,
40
+ background,
41
+ zIndex,
42
+ className,
43
+ children
44
+ });
45
+ };
46
+
47
+ //#endregion
48
+ exports.SliceSimulator = SliceSimulator;
49
+ //# sourceMappingURL=SliceSimulator.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SliceSimulator.cjs","names":["SimulatorManager","getSlices","StateEventType","SliceSimulatorWrapper"],"sources":["../src/SliceSimulator.tsx"],"sourcesContent":["\"use client\";\n\nimport { SliceSimulatorWrapper } from \"./SliceSimulatorWrapper\";\nimport { getSlices } from \"./getSlices\";\nimport {\n\tSimulatorManager,\n\tStateEventType,\n\tgetDefaultMessage,\n} from \"@prismicio/simulator/kit\";\nimport type { SliceSimulatorProps as BaseSliceSimulatorProps } from \"@prismicio/simulator/kit\";\nimport { compressToEncodedURIComponent } from \"lz-string\";\nimport { useRouter } from \"next/navigation\";\nimport { useEffect, useState } from \"react\";\nimport type { FC, ReactNode } from \"react\";\n\nconst STATE_PARAMS_KEY = \"state\";\n\nconst simulatorManager = new SimulatorManager();\n\n/**\n * Parameters provided to the Slice Simulator page.\n */\nexport type SliceSimulatorParams = {\n\tsearchParams: Promise<{\n\t\tstate?: string;\n\t}>;\n};\n\nexport type SliceSimulatorProps = BaseSliceSimulatorProps & {\n\tchildren: ReactNode;\n\tclassName?: string;\n};\n\n/**\n * Simulate slices in isolation. The slice simulator enables live slice\n * development in Slice Machine and live previews in the Page Builder.\n */\nexport const SliceSimulator: FC<SliceSimulatorProps> = ({\n\tchildren,\n\tbackground,\n\tzIndex,\n\tclassName,\n}) => {\n\tconst [message, setMessage] = useState(() => getDefaultMessage());\n\tconst router = useRouter();\n\n\tconst state =\n\t\ttypeof window !== \"undefined\"\n\t\t\t? new URL(window.location.href).searchParams.get(STATE_PARAMS_KEY)\n\t\t\t: undefined;\n\tconst hasSlices = getSlices(state).length > 0;\n\n\tuseEffect(() => {\n\t\tsimulatorManager.state.on(\n\t\t\tStateEventType.Slices,\n\t\t\t(newSlices) => {\n\t\t\t\tconst url = new URL(window.location.href);\n\t\t\t\turl.searchParams.set(\n\t\t\t\t\tSTATE_PARAMS_KEY,\n\t\t\t\t\tcompressToEncodedURIComponent(JSON.stringify(newSlices)),\n\t\t\t\t);\n\n\t\t\t\twindow.history.replaceState(null, \"\", url);\n\t\t\t\t// Wait until the next tick to prevent URL state race conditions.\n\t\t\t\tsetTimeout(() => router.refresh(), 0);\n\t\t\t},\n\t\t\t\"simulator-slices\",\n\t\t);\n\t\tsimulatorManager.state.on(\n\t\t\tStateEventType.Message,\n\t\t\t(newMessage) => setMessage(newMessage),\n\t\t\t\"simulator-message\",\n\t\t);\n\n\t\tsimulatorManager.init();\n\n\t\treturn () => {\n\t\t\tsimulatorManager.state.off(StateEventType.Slices, \"simulator-slices\");\n\n\t\t\tsimulatorManager.state.off(StateEventType.Message, \"simulator-message\");\n\t\t};\n\t}, [router]);\n\n\treturn (\n\t\t<SliceSimulatorWrapper\n\t\t\tmessage={message}\n\t\t\thasSlices={hasSlices}\n\t\t\tbackground={background}\n\t\t\tzIndex={zIndex}\n\t\t\tclassName={className}\n\t\t>\n\t\t\t{children}\n\t\t</SliceSimulatorWrapper>\n\t);\n};\n"],"mappings":";;;;;;;;;;;;AAeA,MAAM,mBAAmB;AAEzB,MAAM,mBAAmB,IAAIA,2CAAkB;;;;;AAoB/C,MAAa,kBAA2C,EACvD,UACA,YACA,QACA,gBACK;CACL,MAAM,CAAC,SAAS,yFAAgD,CAAC;CACjE,MAAM,yCAAoB;CAM1B,MAAM,YAAYC,4BAHjB,OAAO,WAAW,cACf,IAAI,IAAI,OAAO,SAAS,KAAK,CAAC,aAAa,IAAI,iBAAiB,GAChE,OAC8B,CAAC,SAAS;AAE5C,4BAAgB;AACf,mBAAiB,MAAM,GACtBC,wCAAe,SACd,cAAc;GACd,MAAM,MAAM,IAAI,IAAI,OAAO,SAAS,KAAK;AACzC,OAAI,aAAa,IAChB,+DAC8B,KAAK,UAAU,UAAU,CAAC,CACxD;AAED,UAAO,QAAQ,aAAa,MAAM,IAAI,IAAI;AAE1C,oBAAiB,OAAO,SAAS,EAAE,EAAE;KAEtC,mBACA;AACD,mBAAiB,MAAM,GACtBA,wCAAe,UACd,eAAe,WAAW,WAAW,EACtC,oBACA;AAED,mBAAiB,MAAM;AAEvB,eAAa;AACZ,oBAAiB,MAAM,IAAIA,wCAAe,QAAQ,mBAAmB;AAErE,oBAAiB,MAAM,IAAIA,wCAAe,SAAS,oBAAoB;;IAEtE,CAAC,OAAO,CAAC;AAEZ,QACC,2CAACC;EACS;EACE;EACC;EACJ;EACG;EAEV;GACsB"}
@@ -0,0 +1,25 @@
1
+ import { FC, ReactNode } from "react";
2
+ import { SliceSimulatorProps } from "@prismicio/simulator/kit";
3
+
4
+ //#region src/SliceSimulator.d.ts
5
+
6
+ /**
7
+ * Parameters provided to the Slice Simulator page.
8
+ */
9
+ type SliceSimulatorParams = {
10
+ searchParams: Promise<{
11
+ state?: string;
12
+ }>;
13
+ };
14
+ type SliceSimulatorProps$1 = SliceSimulatorProps & {
15
+ children: ReactNode;
16
+ className?: string;
17
+ };
18
+ /**
19
+ * Simulate slices in isolation. The slice simulator enables live slice
20
+ * development in Slice Machine and live previews in the Page Builder.
21
+ */
22
+ declare const SliceSimulator: FC<SliceSimulatorProps$1>;
23
+ //#endregion
24
+ export { SliceSimulator, SliceSimulatorParams, SliceSimulatorProps$1 as SliceSimulatorProps };
25
+ //# sourceMappingURL=SliceSimulator.d.cts.map
@@ -0,0 +1,36 @@
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ let react_jsx_runtime = require("react/jsx-runtime");
3
+ let _prismicio_simulator_kit = require("@prismicio/simulator/kit");
4
+
5
+ //#region src/SliceSimulatorWrapper.tsx
6
+ /**
7
+ * A wrapper for the slice simulator that isolates the given children from the
8
+ * page's layout.
9
+ */
10
+ const SliceSimulatorWrapper = ({ className, children, zIndex, background, message, hasSlices }) => {
11
+ const defaultProps = (0, _prismicio_simulator_kit.getDefaultProps)();
12
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
13
+ className: [_prismicio_simulator_kit.simulatorClass, className].filter(Boolean).join(" "),
14
+ style: {
15
+ zIndex: typeof zIndex === "undefined" ? defaultProps.zIndex : zIndex ?? void 0,
16
+ position: "fixed",
17
+ top: 0,
18
+ left: 0,
19
+ width: "100%",
20
+ height: "100vh",
21
+ overflow: "auto",
22
+ background: typeof background === "undefined" ? defaultProps.background : background ?? void 0
23
+ },
24
+ children: message ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("article", { dangerouslySetInnerHTML: { __html: message } }) : hasSlices ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
25
+ id: "root",
26
+ className: _prismicio_simulator_kit.simulatorRootClass,
27
+ onClickCapture: _prismicio_simulator_kit.onClickHandler,
28
+ onSubmitCapture: _prismicio_simulator_kit.disableEventHandler,
29
+ children
30
+ }) : null
31
+ });
32
+ };
33
+
34
+ //#endregion
35
+ exports.SliceSimulatorWrapper = SliceSimulatorWrapper;
36
+ //# sourceMappingURL=SliceSimulatorWrapper.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SliceSimulatorWrapper.cjs","names":["simulatorClass","simulatorRootClass","onClickHandler","disableEventHandler"],"sources":["../src/SliceSimulatorWrapper.tsx"],"sourcesContent":["import {\n\tdisableEventHandler,\n\tgetDefaultProps,\n\tonClickHandler,\n\tsimulatorClass,\n\tsimulatorRootClass,\n} from \"@prismicio/simulator/kit\";\nimport type { SliceSimulatorProps } from \"@prismicio/simulator/kit\";\nimport type { FC, ReactNode } from \"react\";\n\ntype SliceSimulatorWrapperProps = SliceSimulatorProps & {\n\tchildren: ReactNode;\n\tclassName?: string;\n\tmessage?: string;\n\thasSlices: boolean;\n};\n\n/**\n * A wrapper for the slice simulator that isolates the given children from the\n * page's layout.\n */\nexport const SliceSimulatorWrapper: FC<SliceSimulatorWrapperProps> = ({\n\tclassName,\n\tchildren,\n\tzIndex,\n\tbackground,\n\tmessage,\n\thasSlices,\n}) => {\n\tconst defaultProps = getDefaultProps();\n\n\treturn (\n\t\t<div\n\t\t\tclassName={[simulatorClass, className].filter(Boolean).join(\" \")}\n\t\t\tstyle={{\n\t\t\t\tzIndex:\n\t\t\t\t\ttypeof zIndex === \"undefined\"\n\t\t\t\t\t\t? defaultProps.zIndex\n\t\t\t\t\t\t: (zIndex ?? undefined),\n\t\t\t\tposition: \"fixed\",\n\t\t\t\ttop: 0,\n\t\t\t\tleft: 0,\n\t\t\t\twidth: \"100%\",\n\t\t\t\theight: \"100vh\",\n\t\t\t\toverflow: \"auto\",\n\t\t\t\tbackground:\n\t\t\t\t\ttypeof background === \"undefined\"\n\t\t\t\t\t\t? defaultProps.background\n\t\t\t\t\t\t: (background ?? undefined),\n\t\t\t}}\n\t\t>\n\t\t\t{message ? (\n\t\t\t\t<article dangerouslySetInnerHTML={{ __html: message }} />\n\t\t\t) : hasSlices ? (\n\t\t\t\t<div\n\t\t\t\t\tid=\"root\"\n\t\t\t\t\tclassName={simulatorRootClass}\n\t\t\t\t\tonClickCapture={onClickHandler as unknown as React.MouseEventHandler}\n\t\t\t\t\tonSubmitCapture={\n\t\t\t\t\t\tdisableEventHandler as unknown as React.FormEventHandler\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t</div>\n\t\t\t) : null}\n\t\t</div>\n\t);\n};\n"],"mappings":";;;;;;;;;AAqBA,MAAa,yBAAyD,EACrE,WACA,UACA,QACA,YACA,SACA,gBACK;CACL,MAAM,8DAAgC;AAEtC,QACC,2CAAC;EACA,WAAW,CAACA,yCAAgB,UAAU,CAAC,OAAO,QAAQ,CAAC,KAAK,IAAI;EAChE,OAAO;GACN,QACC,OAAO,WAAW,cACf,aAAa,SACZ,UAAU;GACf,UAAU;GACV,KAAK;GACL,MAAM;GACN,OAAO;GACP,QAAQ;GACR,UAAU;GACV,YACC,OAAO,eAAe,cACnB,aAAa,aACZ,cAAc;GACnB;YAEA,UACA,2CAAC,aAAQ,yBAAyB,EAAE,QAAQ,SAAS,GAAI,GACtD,YACH,2CAAC;GACA,IAAG;GACH,WAAWC;GACX,gBAAgBC;GAChB,iBACCC;GAGA;IACI,GACH;GACC"}
@@ -0,0 +1,29 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+
29
+ exports.__toESM = __toESM;
@@ -0,0 +1,14 @@
1
+ const require_devMsg = require('./lib/devMsg.cjs');
2
+
3
+ //#region src/createLocaleRedirect.ts
4
+ /**
5
+ * @deprecated `createLocaleRedirect()` has been removed due to performance
6
+ * issues.
7
+ */
8
+ function createLocaleRedirect() {
9
+ throw new Error(`createLocaleRedirect() has been removed due to performance issues. See ${require_devMsg.devMsg("replace-createLocaleRedirect")} for more details.`);
10
+ }
11
+
12
+ //#endregion
13
+ exports.createLocaleRedirect = createLocaleRedirect;
14
+ //# sourceMappingURL=createLocaleRedirect.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createLocaleRedirect.cjs","names":["devMsg"],"sources":["../src/createLocaleRedirect.ts"],"sourcesContent":["import { devMsg } from \"./lib/devMsg\";\n\n/**\n * @deprecated `createLocaleRedirect()` has been removed due to performance\n * issues.\n */\nexport function createLocaleRedirect(): never {\n\tthrow new Error(\n\t\t`createLocaleRedirect() has been removed due to performance issues. See ${devMsg(\n\t\t\t\"replace-createLocaleRedirect\",\n\t\t)} for more details.`,\n\t);\n}\n/**\n * @deprecated `createLocaleRedirect()` has been removed due to performance\n * issues.\n */\nexport type CreateLocaleRedirectConfig = never;\n"],"mappings":";;;;;;;AAMA,SAAgB,uBAA8B;AAC7C,OAAM,IAAI,MACT,0EAA0EA,sBACzE,+BACA,CAAC,oBACF"}
@@ -0,0 +1,14 @@
1
+ //#region src/createLocaleRedirect.d.ts
2
+ /**
3
+ * @deprecated `createLocaleRedirect()` has been removed due to performance
4
+ * issues.
5
+ */
6
+ declare function createLocaleRedirect(): never;
7
+ /**
8
+ * @deprecated `createLocaleRedirect()` has been removed due to performance
9
+ * issues.
10
+ */
11
+ type CreateLocaleRedirectConfig = never;
12
+ //#endregion
13
+ export { CreateLocaleRedirectConfig, createLocaleRedirect };
14
+ //# sourceMappingURL=createLocaleRedirect.d.cts.map