@prismicio/react 2.9.2 → 3.0.0-alpha.1
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/README.md +10 -11
- package/dist/PrismicImage.d.ts +18 -633
- package/dist/PrismicImage.js +32 -33
- package/dist/PrismicImage.js.map +1 -1
- package/dist/PrismicLink.d.ts +77 -6
- package/dist/PrismicLink.js +42 -7
- package/dist/PrismicLink.js.map +1 -1
- package/dist/PrismicRichText.d.ts +117 -4
- package/dist/PrismicRichText.js +74 -8
- package/dist/PrismicRichText.js.map +1 -1
- package/dist/PrismicText.d.ts +9 -14
- package/dist/PrismicText.js +13 -14
- package/dist/PrismicText.js.map +1 -1
- package/dist/PrismicToolbar.d.ts +3 -12
- package/dist/PrismicToolbar.js +7 -9
- package/dist/PrismicToolbar.js.map +1 -1
- package/dist/SliceZone.d.ts +16 -70
- package/dist/SliceZone.js +17 -38
- package/dist/SliceZone.js.map +1 -1
- package/dist/index.d.ts +13 -21
- package/dist/index.js +2 -29
- package/dist/index.js.map +1 -1
- package/dist/lib/devMsg.d.ts +2 -2
- package/dist/lib/devMsg.js +2 -2
- package/dist/lib/devMsg.js.map +1 -1
- package/dist/package.json.js +1 -1
- package/package.json +54 -71
- package/src/PrismicImage.tsx +80 -65
- package/src/PrismicLink.tsx +196 -26
- package/src/PrismicRichText.tsx +333 -32
- package/src/PrismicText.tsx +25 -31
- package/src/PrismicToolbar.tsx +9 -29
- package/src/SliceZone.tsx +59 -151
- package/src/index.ts +17 -53
- package/src/lib/devMsg.ts +3 -3
- package/dist/PrismicImage.cjs +0 -68
- package/dist/PrismicImage.cjs.map +0 -1
- package/dist/PrismicLink.cjs +0 -29
- package/dist/PrismicLink.cjs.map +0 -1
- package/dist/PrismicProvider.cjs +0 -41
- package/dist/PrismicProvider.cjs.map +0 -1
- package/dist/PrismicProvider.d.ts +0 -83
- package/dist/PrismicProvider.js +0 -24
- package/dist/PrismicProvider.js.map +0 -1
- package/dist/PrismicRichText.cjs +0 -30
- package/dist/PrismicRichText.cjs.map +0 -1
- package/dist/PrismicText.cjs +0 -44
- package/dist/PrismicText.cjs.map +0 -1
- package/dist/PrismicToolbar.cjs +0 -43
- package/dist/PrismicToolbar.cjs.map +0 -1
- package/dist/SliceZone.cjs +0 -53
- package/dist/SliceZone.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs +0 -16
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js +0 -16
- package/dist/_node_modules/@prismicio/client/dist/errors/PrismicError.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.cjs +0 -13
- package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.js +0 -13
- package/dist/_node_modules/@prismicio/client/dist/getToolbarSrc.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.cjs +0 -22
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.js +0 -22
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImagePixelDensitySrcSet.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.cjs +0 -46
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.js +0 -46
- package/dist/_node_modules/@prismicio/client/dist/helpers/asImageWidthSrcSet.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs +0 -47
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js +0 -47
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLink.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.cjs +0 -28
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.js +0 -28
- package/dist/_node_modules/@prismicio/client/dist/helpers/asLinkAttrs.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asText.cjs +0 -21
- package/dist/_node_modules/@prismicio/client/dist/helpers/asText.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/asText.js +0 -21
- package/dist/_node_modules/@prismicio/client/dist/helpers/asText.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs +0 -27
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js +0 -27
- package/dist/_node_modules/@prismicio/client/dist/helpers/documentToLinkField.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.cjs +0 -24
- package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.js +0 -24
- package/dist/_node_modules/@prismicio/client/dist/helpers/isFilled.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.cjs +0 -7
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.js +0 -7
- package/dist/_node_modules/@prismicio/client/dist/isRepositoryName.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.cjs +0 -9
- package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.js +0 -9
- package/dist/_node_modules/@prismicio/client/dist/lib/isInternalURL.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/richtext/asText.cjs +0 -13
- package/dist/_node_modules/@prismicio/client/dist/richtext/asText.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/richtext/asText.js +0 -13
- package/dist/_node_modules/@prismicio/client/dist/richtext/asText.js.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.cjs +0 -10
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.cjs.map +0 -1
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.js +0 -10
- package/dist/_node_modules/@prismicio/client/dist/types/value/link.js.map +0 -1
- package/dist/_node_modules/imgix-url-builder/dist/buildPixelDensitySrcSet.cjs +0 -10
- package/dist/_node_modules/imgix-url-builder/dist/buildPixelDensitySrcSet.cjs.map +0 -1
- package/dist/_node_modules/imgix-url-builder/dist/buildPixelDensitySrcSet.js +0 -10
- package/dist/_node_modules/imgix-url-builder/dist/buildPixelDensitySrcSet.js.map +0 -1
- package/dist/_node_modules/imgix-url-builder/dist/buildURL.cjs +0 -29
- package/dist/_node_modules/imgix-url-builder/dist/buildURL.cjs.map +0 -1
- package/dist/_node_modules/imgix-url-builder/dist/buildURL.js +0 -29
- package/dist/_node_modules/imgix-url-builder/dist/buildURL.js.map +0 -1
- package/dist/_node_modules/imgix-url-builder/dist/buildWidthSrcSet.cjs +0 -10
- package/dist/_node_modules/imgix-url-builder/dist/buildWidthSrcSet.cjs.map +0 -1
- package/dist/_node_modules/imgix-url-builder/dist/buildWidthSrcSet.js +0 -10
- package/dist/_node_modules/imgix-url-builder/dist/buildWidthSrcSet.js.map +0 -1
- package/dist/clientHooks.cjs +0 -40
- package/dist/clientHooks.cjs.map +0 -1
- package/dist/clientHooks.d.ts +0 -321
- package/dist/clientHooks.js +0 -40
- package/dist/clientHooks.js.map +0 -1
- package/dist/index.cjs +0 -48
- package/dist/index.cjs.map +0 -1
- package/dist/lib/devMsg.cjs +0 -8
- package/dist/lib/devMsg.cjs.map +0 -1
- package/dist/lib/isInternalURL.cjs +0 -9
- package/dist/lib/isInternalURL.cjs.map +0 -1
- package/dist/lib/isInternalURL.d.ts +0 -8
- package/dist/lib/isInternalURL.js +0 -9
- package/dist/lib/isInternalURL.js.map +0 -1
- package/dist/lib/pascalCase.cjs +0 -10
- package/dist/lib/pascalCase.cjs.map +0 -1
- package/dist/lib/pascalCase.d.ts +0 -26
- package/dist/lib/pascalCase.js +0 -10
- package/dist/lib/pascalCase.js.map +0 -1
- package/dist/package.json.cjs +0 -5
- package/dist/package.json.cjs.map +0 -1
- package/dist/react-server/PrismicLink.cjs +0 -59
- package/dist/react-server/PrismicLink.cjs.map +0 -1
- package/dist/react-server/PrismicLink.d.ts +0 -77
- package/dist/react-server/PrismicLink.js +0 -42
- package/dist/react-server/PrismicLink.js.map +0 -1
- package/dist/react-server/PrismicRichText.cjs +0 -102
- package/dist/react-server/PrismicRichText.cjs.map +0 -1
- package/dist/react-server/PrismicRichText.d.ts +0 -104
- package/dist/react-server/PrismicRichText.js +0 -84
- package/dist/react-server/PrismicRichText.js.map +0 -1
- package/dist/react-server/index.d.ts +0 -4
- package/dist/react-server/unsupported.cjs +0 -97
- package/dist/react-server/unsupported.cjs.map +0 -1
- package/dist/react-server/unsupported.d.ts +0 -22
- package/dist/react-server/unsupported.js +0 -97
- package/dist/react-server/unsupported.js.map +0 -1
- package/dist/react-server.cjs +0 -44
- package/dist/react-server.cjs.map +0 -1
- package/dist/react-server.js +0 -41
- package/dist/react-server.js.map +0 -1
- package/dist/types.d.ts +0 -19
- package/dist/usePrismicClient.cjs +0 -13
- package/dist/usePrismicClient.cjs.map +0 -1
- package/dist/usePrismicClient.d.ts +0 -11
- package/dist/usePrismicClient.js +0 -13
- package/dist/usePrismicClient.js.map +0 -1
- package/dist/usePrismicContext.cjs +0 -26
- package/dist/usePrismicContext.cjs.map +0 -1
- package/dist/usePrismicContext.d.ts +0 -8
- package/dist/usePrismicContext.js +0 -9
- package/dist/usePrismicContext.js.map +0 -1
- package/dist/usePrismicPreviewResolver.cjs +0 -44
- package/dist/usePrismicPreviewResolver.cjs.map +0 -1
- package/dist/usePrismicPreviewResolver.d.ts +0 -45
- package/dist/usePrismicPreviewResolver.js +0 -27
- package/dist/usePrismicPreviewResolver.js.map +0 -1
- package/dist/useStatefulPrismicClientMethod.cjs +0 -91
- package/dist/useStatefulPrismicClientMethod.cjs.map +0 -1
- package/dist/useStatefulPrismicClientMethod.d.ts +0 -44
- package/dist/useStatefulPrismicClientMethod.js +0 -74
- package/dist/useStatefulPrismicClientMethod.js.map +0 -1
- package/src/PrismicProvider.tsx +0 -132
- package/src/clientHooks.ts +0 -472
- package/src/lib/isInternalURL.ts +0 -14
- package/src/lib/pascalCase.ts +0 -79
- package/src/react-server/PrismicLink.tsx +0 -197
- package/src/react-server/PrismicRichText.tsx +0 -326
- package/src/react-server/index.ts +0 -38
- package/src/react-server/unsupported.ts +0 -184
- package/src/types.ts +0 -24
- package/src/usePrismicClient.ts +0 -30
- package/src/usePrismicContext.ts +0 -13
- package/src/usePrismicPreviewResolver.ts +0 -93
- package/src/useStatefulPrismicClientMethod.ts +0 -196
package/dist/PrismicText.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicText.js","sources":["
|
|
1
|
+
{"version":3,"file":"PrismicText.js","sources":["../src/PrismicText.tsx"],"sourcesContent":["import { FC } from \"react\";\nimport { asText, isFilled, RichTextField } from \"@prismicio/client\";\nimport { DEV } from \"esm-env\";\n\nimport { devMsg } from \"./lib/devMsg.js\";\n\n/** Props for `<PrismicText>`. */\nexport type PrismicTextProps = {\n\t/** The Prismic Rich Text field to render. */\n\tfield: RichTextField | null | undefined;\n\n\t/**\n\t * The string rendered when the field is empty. If a fallback is not given,\n\t * `null` will be rendered.\n\t */\n\tfallback?: string;\n\n\t/** The separator used between blocks. Defaults to `\\n`. */\n\tseparator?: string;\n};\n\n/**\n * React component that renders content from a Prismic Rich Text field as plain\n * text.\n *\n * @remarks\n * This component returns a React fragment with no wrapping element around the\n * content. If you need a wrapper, add a component around `<PrismicText>`.\n *\n * @example Rendering a Rich Text field as plain text.\n *\n * ```jsx\n * <PrismicText field={document.data.content} />;\n * ```\n *\n * @param props - Props for the component.\n *\n * @returns The Rich Text field's content as plain text.\n *\n * @see Learn about Rich Text fields {@link https://io/docs/core-concepts/rich-text-title}\n */\nexport const PrismicText: FC<PrismicTextProps> = (props) => {\n\tconst { field, fallback, separator } = props;\n\n\tif (DEV) {\n\t\tif (\"className\" in props) {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicText] className cannot be passed to <PrismicText> since it renders plain text without a wrapping component. For more details, see ${devMsg(\n\t\t\t\t\t\"classname-is-not-a-valid-prop\",\n\t\t\t\t)}.`,\n\t\t\t\tprops.field,\n\t\t\t);\n\t\t}\n\t}\n\n\tif (typeof props.field === \"string\") {\n\t\tif (DEV) {\n\t\t\tconsole.error(\n\t\t\t\t`[PrismicText] The \"field\" prop only accepts a Rich Text or Title field's value but was provided a different type of field instead (e.g. a Key Text or Select field). You can resolve this error by rendering the field value inline without <PrismicText>. For more details, see ${devMsg(\n\t\t\t\t\t\"prismictext-works-only-with-rich-text-and-title-fields\",\n\t\t\t\t)}`,\n\t\t\t\tprops.field,\n\t\t\t);\n\t\t}\n\n\t\treturn null;\n\t}\n\n\tif (!isFilled.richText(field)) {\n\t\treturn fallback != null ? <>{fallback}</> : null;\n\t}\n\n\treturn <>{asText(field, { separator })}</>;\n};\n"],"names":["_jsx","_Fragment"],"mappings":";;;;AAyCa,MAAA,cAAoC,CAAC,UAAS;AAC1D,QAAM,EAAE,OAAO,UAAU,UAAc,IAAA;AAEvC,MAAI,KAAK;AACR,QAAI,eAAe,OAAO;AACzB,cAAQ,KACP,6IAA6I,OAC5I,+BAA+B,CAC/B,KACD,MAAM,KAAK;AAAA,IAAA;AAAA,EAEb;AAGG,MAAA,OAAO,MAAM,UAAU,UAAU;AACpC,QAAI,KAAK;AACR,cAAQ,MACP,oRAAoR,OACnR,wDAAwD,CACxD,IACD,MAAM,KAAK;AAAA,IAAA;AAIN,WAAA;AAAA,EAAA;AAGR,MAAI,CAAC,SAAS,SAAS,KAAK,GAAG;AACvB,WAAA,YAAY,OAAOA,IAAGC,UAAA,EAAA,UAAA,SAAY,CAAA,IAAG;AAAA,EAAA;AAGtC,SAAAD,IAAAC,UAAA,EAAA,UAAG,OAAO,OAAO,EAAE,UAAW,CAAA,GAAC;AACvC;"}
|
package/dist/PrismicToolbar.d.ts
CHANGED
|
@@ -1,23 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
1
|
+
import { FC } from "react";
|
|
2
|
+
/** Props for `<PrismicToolbar>`. */
|
|
4
3
|
export type PrismicToolbarProps = {
|
|
5
4
|
/**
|
|
6
5
|
* The name of the Prismic repository. For example, `"my-repo"` if the
|
|
7
6
|
* repository URL is `my-repo.prismic.io`.
|
|
8
7
|
*/
|
|
9
8
|
repositoryName: string;
|
|
10
|
-
/**
|
|
11
|
-
* The type of toolbar needed for the repository. Defaults to `"new"`.
|
|
12
|
-
*
|
|
13
|
-
* @deprecated All repositories use the "new"-type toolbar. This option can be
|
|
14
|
-
* removed.
|
|
15
|
-
* @see To check which version you need, view the Prismic Toolbar documentation {@link https://prismic.io/docs/technologies/previews-and-the-prismic-toolbar-reactjs}
|
|
16
|
-
*/
|
|
17
|
-
type?: "new" | "legacy";
|
|
18
9
|
};
|
|
19
10
|
/**
|
|
20
11
|
* React component that injects the Prismic Toolbar into the app. This component
|
|
21
12
|
* can be placed anywhere in the React tree.
|
|
22
13
|
*/
|
|
23
|
-
export declare const PrismicToolbar:
|
|
14
|
+
export declare const PrismicToolbar: FC<PrismicToolbarProps>;
|
package/dist/PrismicToolbar.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
const
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect } from "react";
|
|
3
|
+
import { getToolbarSrc } from "@prismicio/client";
|
|
4
|
+
const PrismicToolbar = (props) => {
|
|
5
|
+
const { repositoryName } = props;
|
|
6
6
|
const src = getToolbarSrc(repositoryName);
|
|
7
|
-
|
|
7
|
+
useEffect(() => {
|
|
8
8
|
const existingScript = document.querySelector(`script[src="${src}"]`);
|
|
9
9
|
if (!existingScript) {
|
|
10
10
|
const script = document.createElement("script");
|
|
@@ -12,9 +12,7 @@ const PrismicToolbar = ({ repositoryName }) => {
|
|
|
12
12
|
script.defer = true;
|
|
13
13
|
script.dataset.prismicToolbar = "";
|
|
14
14
|
script.dataset.repositoryName = repositoryName;
|
|
15
|
-
|
|
16
|
-
script._evaluateScript = false;
|
|
17
|
-
}
|
|
15
|
+
script._evaluateScript = false;
|
|
18
16
|
document.body.appendChild(script);
|
|
19
17
|
}
|
|
20
18
|
}, [repositoryName, src]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicToolbar.js","sources":["
|
|
1
|
+
{"version":3,"file":"PrismicToolbar.js","sources":["../src/PrismicToolbar.tsx"],"sourcesContent":["\"use client\";\n\nimport { FC, useEffect } from \"react\";\nimport { getToolbarSrc } from \"@prismicio/client\";\n\n/** Props for `<PrismicToolbar>`. */\nexport type PrismicToolbarProps = {\n\t/**\n\t * The name of the Prismic repository. For example, `\"my-repo\"` if the\n\t * repository URL is `my-repo.prismic.io`.\n\t */\n\trepositoryName: string;\n};\n\n/**\n * React component that injects the Prismic Toolbar into the app. This component\n * can be placed anywhere in the React tree.\n */\nexport const PrismicToolbar: FC<PrismicToolbarProps> = (props) => {\n\tconst { repositoryName } = props;\n\n\tconst src = getToolbarSrc(repositoryName);\n\n\tuseEffect(() => {\n\t\tconst existingScript = document.querySelector(`script[src=\"${src}\"]`);\n\n\t\tif (!existingScript) {\n\t\t\tconst script = document.createElement(\"script\");\n\t\t\tscript.src = src;\n\t\t\tscript.defer = true;\n\n\t\t\t// Used to distinguish the toolbar element from other elements.\n\t\t\tscript.dataset.prismicToolbar = \"\";\n\t\t\tscript.dataset.repositoryName = repositoryName;\n\n\t\t\t// Disable Happy DOM `<script>` evaluation during tests.\n\t\t\t// @ts-expect-error - `_evaluateScript` is a Happy DOM-specific property.\n\t\t\tscript._evaluateScript = false;\n\n\t\t\tdocument.body.appendChild(script);\n\t\t}\n\t}, [repositoryName, src]);\n\n\treturn null;\n};\n"],"names":[],"mappings":";;;AAkBa,MAAA,iBAA0C,CAAC,UAAS;AAC1D,QAAA,EAAE,mBAAmB;AAErB,QAAA,MAAM,cAAc,cAAc;AAExC,YAAU,MAAK;AACd,UAAM,iBAAiB,SAAS,cAAc,eAAe,GAAG,IAAI;AAEpE,QAAI,CAAC,gBAAgB;AACd,YAAA,SAAS,SAAS,cAAc,QAAQ;AAC9C,aAAO,MAAM;AACb,aAAO,QAAQ;AAGf,aAAO,QAAQ,iBAAiB;AAChC,aAAO,QAAQ,iBAAiB;AAIhC,aAAO,kBAAkB;AAEhB,eAAA,KAAK,YAAY,MAAM;AAAA,IAAA;AAAA,EACjC,GACE,CAAC,gBAAgB,GAAG,CAAC;AAEjB,SAAA;AACR;"}
|
package/dist/SliceZone.d.ts
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
|
-
import { ComponentType } from "react";
|
|
2
|
-
import
|
|
3
|
-
import { PascalCase } from "./lib/pascalCase";
|
|
1
|
+
import type { ComponentType, FC } from "react";
|
|
2
|
+
import type { Slice } from "@prismicio/client";
|
|
4
3
|
/**
|
|
5
4
|
* Returns the type of a `SliceLike` type.
|
|
6
5
|
*
|
|
7
6
|
* @typeParam Slice - The Slice from which the type will be extracted.
|
|
8
7
|
*/
|
|
9
|
-
type ExtractSliceType<TSlice extends SliceLike> = TSlice extends
|
|
8
|
+
type ExtractSliceType<TSlice extends SliceLike> = TSlice extends Slice ? TSlice["slice_type"] : TSlice extends SliceLikeGraphQL ? TSlice["type"] : never;
|
|
10
9
|
/**
|
|
11
10
|
* The minimum required properties to represent a Prismic Slice from the Prismic
|
|
12
11
|
* Rest API V2 for the `unstable_mapSliceZone()` helper.
|
|
13
12
|
*
|
|
14
13
|
* @typeParam SliceType - Type name of the Slice.
|
|
15
14
|
*/
|
|
16
|
-
export type SliceLikeRestV2<TSliceType extends string = string> = Pick<
|
|
15
|
+
export type SliceLikeRestV2<TSliceType extends string = string> = Pick<Slice<TSliceType>, "id" | "slice_type">;
|
|
17
16
|
/**
|
|
18
17
|
* The minimum required properties to represent a Prismic Slice from the Prismic
|
|
19
18
|
* GraphQL API for the `unstable_mapSliceZone()` helper.
|
|
@@ -21,7 +20,7 @@ export type SliceLikeRestV2<TSliceType extends string = string> = Pick<prismic.S
|
|
|
21
20
|
* @typeParam SliceType - Type name of the Slice.
|
|
22
21
|
*/
|
|
23
22
|
export type SliceLikeGraphQL<TSliceType extends string = string> = {
|
|
24
|
-
type:
|
|
23
|
+
type: Slice<TSliceType>["slice_type"];
|
|
25
24
|
};
|
|
26
25
|
/**
|
|
27
26
|
* The minimum required properties to represent a Prismic Slice for the
|
|
@@ -60,17 +59,11 @@ export type SliceZoneLike<TSlice extends SliceLike = SliceLike> = readonly TSlic
|
|
|
60
59
|
* available to all Slice components.
|
|
61
60
|
*/
|
|
62
61
|
export type SliceComponentProps<TSlice extends SliceLike = SliceLike, TContext = unknown> = {
|
|
63
|
-
/**
|
|
64
|
-
* Slice data for this component.
|
|
65
|
-
*/
|
|
62
|
+
/** Slice data for this component. */
|
|
66
63
|
slice: TSlice;
|
|
67
|
-
/**
|
|
68
|
-
* The index of the Slice in the Slice Zone.
|
|
69
|
-
*/
|
|
64
|
+
/** The index of the Slice in the Slice Zone. */
|
|
70
65
|
index: number;
|
|
71
|
-
/**
|
|
72
|
-
* All Slices from the Slice Zone to which the Slice belongs.
|
|
73
|
-
*/
|
|
66
|
+
/** All Slices from the Slice Zone to which the Slice belongs. */
|
|
74
67
|
slices: SliceZoneLike<TSlice extends SliceLikeGraphQL ? SliceLikeGraphQL : SliceLikeRestV2>;
|
|
75
68
|
/**
|
|
76
69
|
* Arbitrary data passed to `<SliceZone>` and made available to all Slice
|
|
@@ -84,50 +77,20 @@ export type SliceComponentProps<TSlice extends SliceLike = SliceLike, TContext =
|
|
|
84
77
|
* @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
|
|
85
78
|
* @typeParam TContext - Arbitrary data made available to all Slice components.
|
|
86
79
|
*/
|
|
87
|
-
export type SliceComponentType<TSlice extends SliceLike = any, TContext = unknown> =
|
|
80
|
+
export type SliceComponentType<TSlice extends SliceLike = any, TContext = unknown> = ComponentType<SliceComponentProps<TSlice, TContext>>;
|
|
88
81
|
/**
|
|
89
82
|
* A record of Slice types mapped to a React component. The component will be
|
|
90
83
|
* rendered for each instance of its Slice.
|
|
91
84
|
*
|
|
92
85
|
* @deprecated This type is no longer used by `@prismicio/react`. Prefer using
|
|
93
86
|
* `Record<string, SliceComponentType<any>>` instead.
|
|
87
|
+
*
|
|
94
88
|
* @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
|
|
95
89
|
* @typeParam TContext - Arbitrary data made available to all Slice components.
|
|
96
90
|
*/
|
|
97
91
|
export type SliceZoneComponents<TSlice extends SliceLike = SliceLike, TContext = unknown> = {
|
|
98
92
|
[SliceType in ExtractSliceType<TSlice>]: SliceComponentType<Extract<TSlice, SliceLike<SliceType>> extends never ? SliceLike : Extract<TSlice, SliceLike<SliceType>>, TContext>;
|
|
99
93
|
};
|
|
100
|
-
/**
|
|
101
|
-
* Arguments for a `<SliceZone>` `resolver` function.
|
|
102
|
-
*/
|
|
103
|
-
type SliceZoneResolverArgs<TSlice extends SliceLike = any> = {
|
|
104
|
-
/**
|
|
105
|
-
* The Slice to resolve to a React component.
|
|
106
|
-
*/
|
|
107
|
-
slice: TSlice;
|
|
108
|
-
/**
|
|
109
|
-
* The name of the Slice.
|
|
110
|
-
*/
|
|
111
|
-
sliceName: PascalCase<ExtractSliceType<TSlice>>;
|
|
112
|
-
/**
|
|
113
|
-
* The index of the Slice in the Slice Zone.
|
|
114
|
-
*/
|
|
115
|
-
i: number;
|
|
116
|
-
};
|
|
117
|
-
/**
|
|
118
|
-
* A function that determines the rendered React component for each Slice in the
|
|
119
|
-
* Slice Zone. If a nullish value is returned, the component will fallback to
|
|
120
|
-
* the `components` or `defaultComponent` props to determine the rendered
|
|
121
|
-
* component.
|
|
122
|
-
*
|
|
123
|
-
* @deprecated Use the `components` prop instead.
|
|
124
|
-
*
|
|
125
|
-
* @param args - Arguments for the resolver function.
|
|
126
|
-
*
|
|
127
|
-
* @returns The React component to render for a Slice.
|
|
128
|
-
*/
|
|
129
|
-
export type SliceZoneResolver<TSlice extends SliceLike = any> = (args: SliceZoneResolverArgs<TSlice>) => // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
130
|
-
ComponentType<any> | undefined | null;
|
|
131
94
|
/**
|
|
132
95
|
* React props for the `<SliceZone>` component.
|
|
133
96
|
*
|
|
@@ -135,33 +98,16 @@ ComponentType<any> | undefined | null;
|
|
|
135
98
|
* @typeParam TContext - Arbitrary data made available to all Slice components.
|
|
136
99
|
*/
|
|
137
100
|
export type SliceZoneProps<TContext = unknown> = {
|
|
138
|
-
/**
|
|
139
|
-
* List of Slice data from the Slice Zone.
|
|
140
|
-
*/
|
|
101
|
+
/** List of Slice data from the Slice Zone. */
|
|
141
102
|
slices?: SliceZoneLike;
|
|
142
|
-
/**
|
|
143
|
-
* A record mapping Slice types to React components.
|
|
144
|
-
*/
|
|
103
|
+
/** A record mapping Slice types to React components. */
|
|
145
104
|
components?: Record<string, ComponentType<any>>;
|
|
146
|
-
/**
|
|
147
|
-
* A function that determines the rendered React component for each Slice in
|
|
148
|
-
* the Slice Zone.
|
|
149
|
-
*
|
|
150
|
-
* @deprecated Use the `components` prop instead.
|
|
151
|
-
*
|
|
152
|
-
* @param args - Arguments for the resolver function.
|
|
153
|
-
*
|
|
154
|
-
* @returns The React component to render for a Slice.
|
|
155
|
-
*/
|
|
156
|
-
resolver?: SliceZoneResolver<any>;
|
|
157
105
|
/**
|
|
158
106
|
* The React component rendered if a component mapping from the `components`
|
|
159
107
|
* prop cannot be found.
|
|
160
108
|
*/
|
|
161
109
|
defaultComponent?: ComponentType<SliceComponentProps<any, TContext>>;
|
|
162
|
-
/**
|
|
163
|
-
* Arbitrary data made available to all Slice components.
|
|
164
|
-
*/
|
|
110
|
+
/** Arbitrary data made available to all Slice components. */
|
|
165
111
|
context?: TContext;
|
|
166
112
|
};
|
|
167
113
|
/**
|
|
@@ -171,9 +117,9 @@ export type SliceZoneProps<TContext = unknown> = {
|
|
|
171
117
|
* This is also the default React component rendered when a component mapping
|
|
172
118
|
* cannot be found in `<SliceZone>`.
|
|
173
119
|
*/
|
|
174
|
-
export declare const TODOSliceComponent: <TSlice extends SliceLike
|
|
120
|
+
export declare const TODOSliceComponent: <TSlice extends SliceLike>({ slice, }: {
|
|
175
121
|
slice: TSlice;
|
|
176
|
-
}) =>
|
|
122
|
+
}) => import("react/jsx-runtime").JSX.Element | null;
|
|
177
123
|
/**
|
|
178
124
|
* Renders content from a Prismic Slice Zone using React components for each
|
|
179
125
|
* type of Slice.
|
|
@@ -189,5 +135,5 @@ export declare const TODOSliceComponent: <TSlice extends SliceLike<string>>({ sl
|
|
|
189
135
|
*
|
|
190
136
|
* @see Learn about Prismic Slices and Slice Zones {@link https://prismic.io/docs/core-concepts/slices}
|
|
191
137
|
*/
|
|
192
|
-
export declare
|
|
138
|
+
export declare const SliceZone: FC<SliceZoneProps>;
|
|
193
139
|
export {};
|
package/dist/SliceZone.js
CHANGED
|
@@ -1,51 +1,30 @@
|
|
|
1
1
|
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { DEV } from "esm-env";
|
|
3
3
|
const TODOSliceComponent = ({ slice }) => {
|
|
4
|
-
if (
|
|
5
|
-
const type = "slice_type" in slice ? slice.slice_type : slice.type;
|
|
6
|
-
console.warn(`[SliceZone] Could not find a component for Slice type "${type}"`, slice);
|
|
7
|
-
return /* @__PURE__ */ jsxs("section", { "data-slice-zone-todo-component": "", "data-slice-type": type, children: [
|
|
8
|
-
"Could not find a component for Slice type “",
|
|
9
|
-
type,
|
|
10
|
-
"”"
|
|
11
|
-
] });
|
|
12
|
-
} else {
|
|
4
|
+
if (!DEV) {
|
|
13
5
|
return null;
|
|
14
6
|
}
|
|
7
|
+
const type = "slice_type" in slice ? slice.slice_type : slice.type;
|
|
8
|
+
console.warn(`[SliceZone] Could not find a component for Slice type "${type}"`, slice);
|
|
9
|
+
return jsxs("section", { "data-slice-zone-todo-component": "", "data-slice-type": type, children: ["Could not find a component for Slice type “", type, "”"] });
|
|
15
10
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (resolver) {
|
|
19
|
-
console.warn("The `resolver` prop is deprecated. Please replace it with a components map using the `components` prop.");
|
|
20
|
-
}
|
|
21
|
-
}
|
|
11
|
+
const SliceZone = (props) => {
|
|
12
|
+
const { slices = [], components = {}, defaultComponent, context = {} } = props;
|
|
22
13
|
const renderedSlices = slices.map((slice, index) => {
|
|
23
14
|
const type = "slice_type" in slice ? slice.slice_type : slice.type;
|
|
24
|
-
let Comp = components[type] || defaultComponent;
|
|
25
|
-
if (resolver) {
|
|
26
|
-
const resolvedComp = resolver({
|
|
27
|
-
slice,
|
|
28
|
-
sliceName: pascalCase(type),
|
|
29
|
-
i: index
|
|
30
|
-
});
|
|
31
|
-
if (resolvedComp) {
|
|
32
|
-
Comp = resolvedComp;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
15
|
const key = "id" in slice && slice.id ? slice.id : `${index}-${JSON.stringify(slice)}`;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
} else {
|
|
44
|
-
return /* @__PURE__ */ jsx(TODOSliceComponent, { slice }, key);
|
|
16
|
+
const Comp = components[type] || defaultComponent;
|
|
17
|
+
if (!Comp) {
|
|
18
|
+
return jsx(TODOSliceComponent, { slice }, key);
|
|
19
|
+
}
|
|
20
|
+
if (slice.__mapped) {
|
|
21
|
+
const { __mapped, ...mappedProps } = slice;
|
|
22
|
+
return jsx(Comp, { ...mappedProps }, key);
|
|
45
23
|
}
|
|
24
|
+
return jsx(Comp, { slice, index, slices, context }, key);
|
|
46
25
|
});
|
|
47
|
-
return
|
|
48
|
-
}
|
|
26
|
+
return jsx(Fragment, { children: renderedSlices });
|
|
27
|
+
};
|
|
49
28
|
export {
|
|
50
29
|
SliceZone,
|
|
51
30
|
TODOSliceComponent
|
package/dist/SliceZone.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SliceZone.js","sources":["../../src/SliceZone.tsx"],"sourcesContent":["import { ComponentType } from \"react\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { pascalCase, PascalCase } from \"./lib/pascalCase\";\n\n/**\n * Returns the type of a `SliceLike` type.\n *\n * @typeParam Slice - The Slice from which the type will be extracted.\n */\ntype ExtractSliceType<TSlice extends SliceLike> = TSlice extends prismic.Slice\n\t? TSlice[\"slice_type\"]\n\t: TSlice extends SliceLikeGraphQL\n\t? TSlice[\"type\"]\n\t: never;\n\n/**\n * The minimum required properties to represent a Prismic Slice from the Prismic\n * Rest API V2 for the `unstable_mapSliceZone()` helper.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\nexport type SliceLikeRestV2<TSliceType extends string = string> = Pick<\n\tprismic.Slice<TSliceType>,\n\t\"id\" | \"slice_type\"\n>;\n\n/**\n * The minimum required properties to represent a Prismic Slice from the Prismic\n * GraphQL API for the `unstable_mapSliceZone()` helper.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\nexport type SliceLikeGraphQL<TSliceType extends string = string> = {\n\ttype: prismic.Slice<TSliceType>[\"slice_type\"];\n};\n\n/**\n * The minimum required properties to represent a Prismic Slice for the\n * `unstable_mapSliceZone()` helper.\n *\n * If using Prismic's Rest API V2, use the `Slice` export from\n * `@prismicio/client` for a full interface.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\nexport type SliceLike<TSliceType extends string = string> = (\n\t| SliceLikeRestV2<TSliceType>\n\t| SliceLikeGraphQL<TSliceType>\n) & {\n\t/**\n\t * If `true`, this Slice has been modified from its original value using a\n\t * mapper and `@prismicio/client`'s `mapSliceZone()`.\n\t *\n\t * @internal\n\t */\n\t__mapped?: true;\n};\n\n/**\n * A looser version of the `SliceZone` type from `@prismicio/client` using\n * `SliceLike`.\n *\n * If using Prismic's Rest API V2, use the `SliceZone` export from\n * `@prismicio/client` for the full type.\n *\n * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.\n */\nexport type SliceZoneLike<TSlice extends SliceLike = SliceLike> =\n\treadonly TSlice[];\n\n/**\n * React props for a component rendering content from a Prismic Slice using the\n * `<SliceZone>` component.\n *\n * @typeParam TSlice - The Slice passed as a prop.\n * @typeParam TContext - Arbitrary data passed to `<SliceZone>` and made\n * available to all Slice components.\n */\nexport type SliceComponentProps<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTSlice extends SliceLike = SliceLike,\n\tTContext = unknown,\n> = {\n\t/**\n\t * Slice data for this component.\n\t */\n\tslice: TSlice;\n\n\t/**\n\t * The index of the Slice in the Slice Zone.\n\t */\n\tindex: number;\n\n\t/**\n\t * All Slices from the Slice Zone to which the Slice belongs.\n\t */\n\t// TODO: We have to keep this list of Slices general due to circular\n\t// reference limtiations. If we had another generic to determine the full\n\t// union of Slice types, it would include TSlice. This causes TypeScript to\n\t// throw a compilation error.\n\tslices: SliceZoneLike<\n\t\tTSlice extends SliceLikeGraphQL ? SliceLikeGraphQL : SliceLikeRestV2\n\t>;\n\n\t/**\n\t * Arbitrary data passed to `<SliceZone>` and made available to all Slice\n\t * components.\n\t */\n\tcontext: TContext;\n};\n\n/**\n * A React component to be rendered for each instance of its Slice.\n *\n * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.\n * @typeParam TContext - Arbitrary data made available to all Slice components.\n */\nexport type SliceComponentType<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTSlice extends SliceLike = any,\n\tTContext = unknown,\n> = React.ComponentType<SliceComponentProps<TSlice, TContext>>;\n\n/**\n * A record of Slice types mapped to a React component. The component will be\n * rendered for each instance of its Slice.\n *\n * @deprecated This type is no longer used by `@prismicio/react`. Prefer using\n * `Record<string, SliceComponentType<any>>` instead.\n * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.\n * @typeParam TContext - Arbitrary data made available to all Slice components.\n */\nexport type SliceZoneComponents<\n\tTSlice extends SliceLike = SliceLike,\n\tTContext = unknown,\n> =\n\t// This is purposely not wrapped in Partial to ensure a component is provided\n\t// for all Slice types. <SliceZone> will render a default component if one is\n\t// not provided, but it *should* be a type error if an explicit component is\n\t// missing.\n\t//\n\t// If a developer purposely does not want to provide a component, they can\n\t// assign it to the TODOSliceComponent exported from this package. This\n\t// signals to future developers that it is a placeholder and should be\n\t// implemented.\n\t{\n\t\t[SliceType in ExtractSliceType<TSlice>]: SliceComponentType<\n\t\t\tExtract<TSlice, SliceLike<SliceType>> extends never\n\t\t\t\t? SliceLike\n\t\t\t\t: Extract<TSlice, SliceLike<SliceType>>,\n\t\t\tTContext\n\t\t>;\n\t};\n\n/**\n * Arguments for a `<SliceZone>` `resolver` function.\n */\ntype SliceZoneResolverArgs<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTSlice extends SliceLike = any,\n> = {\n\t/**\n\t * The Slice to resolve to a React component.\n\t */\n\tslice: TSlice;\n\n\t/**\n\t * The name of the Slice.\n\t */\n\tsliceName: PascalCase<ExtractSliceType<TSlice>>;\n\n\t/**\n\t * The index of the Slice in the Slice Zone.\n\t */\n\ti: number;\n};\n\n/**\n * A function that determines the rendered React component for each Slice in the\n * Slice Zone. If a nullish value is returned, the component will fallback to\n * the `components` or `defaultComponent` props to determine the rendered\n * component.\n *\n * @deprecated Use the `components` prop instead.\n *\n * @param args - Arguments for the resolver function.\n *\n * @returns The React component to render for a Slice.\n */\nexport type SliceZoneResolver<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTSlice extends SliceLike = any,\n> = (\n\targs: SliceZoneResolverArgs<TSlice>,\n) => // eslint-disable-next-line @typescript-eslint/no-explicit-any\nComponentType<any> | undefined | null;\n\n/**\n * React props for the `<SliceZone>` component.\n *\n * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.\n * @typeParam TContext - Arbitrary data made available to all Slice components.\n */\nexport type SliceZoneProps<TContext = unknown> = {\n\t/**\n\t * List of Slice data from the Slice Zone.\n\t */\n\tslices?: SliceZoneLike;\n\n\t/**\n\t * A record mapping Slice types to React components.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tcomponents?: Record<string, ComponentType<any>>;\n\n\t/**\n\t * A function that determines the rendered React component for each Slice in\n\t * the Slice Zone.\n\t *\n\t * @deprecated Use the `components` prop instead.\n\t *\n\t * @param args - Arguments for the resolver function.\n\t *\n\t * @returns The React component to render for a Slice.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tresolver?: SliceZoneResolver<any>;\n\n\t/**\n\t * The React component rendered if a component mapping from the `components`\n\t * prop cannot be found.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tdefaultComponent?: ComponentType<SliceComponentProps<any, TContext>>;\n\n\t/**\n\t * Arbitrary data made available to all Slice components.\n\t */\n\tcontext?: TContext;\n};\n\n/**\n * This Slice component can be used as a reminder to provide a proper\n * implementation.\n *\n * This is also the default React component rendered when a component mapping\n * cannot be found in `<SliceZone>`.\n */\nexport const TODOSliceComponent = <TSlice extends SliceLike>({\n\tslice,\n}: {\n\tslice: TSlice;\n}): React.JSX.Element | null => {\n\tif (\n\t\ttypeof process !== \"undefined\" &&\n\t\tprocess.env.NODE_ENV === \"development\"\n\t) {\n\t\tconst type = \"slice_type\" in slice ? slice.slice_type : slice.type;\n\n\t\tconsole.warn(\n\t\t\t`[SliceZone] Could not find a component for Slice type \"${type}\"`,\n\t\t\tslice,\n\t\t);\n\n\t\treturn (\n\t\t\t<section data-slice-zone-todo-component=\"\" data-slice-type={type}>\n\t\t\t\tCould not find a component for Slice type “{type}\n\t\t\t\t”\n\t\t\t</section>\n\t\t);\n\t} else {\n\t\treturn null;\n\t}\n};\n\n/**\n * Renders content from a Prismic Slice Zone using React components for each\n * type of Slice.\n *\n * If a component is not provided for a type of Slice, a default component can\n * be provided. A fallback component is provided by default that will not be\n * rendered in a production build of your app.\n *\n * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.\n * @typeParam TContext - Arbitrary data made available to all Slice components.\n *\n * @returns The Slice Zone's content as React components.\n *\n * @see Learn about Prismic Slices and Slice Zones {@link https://prismic.io/docs/core-concepts/slices}\n */\nexport function SliceZone<TContext>({\n\tslices = [],\n\tcomponents = {},\n\tresolver,\n\tdefaultComponent,\n\tcontext = {} as TContext,\n}: SliceZoneProps<TContext>) {\n\t// TODO: Remove in v3 when the `resolver` prop is removed.\n\tif (process.env.NODE_ENV === \"development\") {\n\t\tif (resolver) {\n\t\t\tconsole.warn(\n\t\t\t\t\"The `resolver` prop is deprecated. Please replace it with a components map using the `components` prop.\",\n\t\t\t);\n\t\t}\n\t}\n\n\tconst renderedSlices = slices.map((slice, index) => {\n\t\tconst type = \"slice_type\" in slice ? slice.slice_type : slice.type;\n\n\t\tlet Comp = components[type as keyof typeof components] || defaultComponent;\n\n\t\t// TODO: Remove `resolver` in v3 in favor of `components`.\n\t\tif (resolver) {\n\t\t\tconst resolvedComp = resolver({\n\t\t\t\tslice,\n\t\t\t\tsliceName: pascalCase(type),\n\t\t\t\ti: index,\n\t\t\t});\n\n\t\t\tif (resolvedComp) {\n\t\t\t\tComp = resolvedComp as typeof Comp;\n\t\t\t}\n\t\t}\n\n\t\tconst key =\n\t\t\t\"id\" in slice && slice.id\n\t\t\t\t? slice.id\n\t\t\t\t: `${index}-${JSON.stringify(slice)}`;\n\n\t\tif (Comp) {\n\t\t\tif (slice.__mapped) {\n\t\t\t\tconst { __mapped, ...mappedProps } = slice;\n\n\t\t\t\treturn <Comp key={key} {...mappedProps} />;\n\t\t\t} else {\n\t\t\t\treturn (\n\t\t\t\t\t<Comp\n\t\t\t\t\t\tkey={key}\n\t\t\t\t\t\tslice={slice}\n\t\t\t\t\t\tindex={index}\n\t\t\t\t\t\tslices={slices}\n\t\t\t\t\t\tcontext={context}\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\treturn <TODOSliceComponent key={key} slice={slice} />;\n\t\t}\n\t});\n\n\treturn <>{renderedSlices}</>;\n}\n"],"names":[],"mappings":";;AAyPO,MAAM,qBAAqB,CAA2B,EAC5D,YAG8B;AAC9B,MACC,OAAO,YAAY,eACnB,QAAQ,IAAI,aAAa,eACxB;AACD,UAAM,OAAO,gBAAgB,QAAQ,MAAM,aAAa,MAAM;AAEtD,YAAA,KACP,0DAA0D,SAC1D,KAAK;AAGN,WACE,qBAAA,WAAA,EAAQ,kCAA+B,IAAG,mBAAiB,MAC3D,UAAA;AAAA,MAAA;AAAA,MAAkD;AAAA,MAClD;AAAA,IACD,EAAA,CAAA;AAAA,EAAA,OAEK;AACC,WAAA;AAAA,EACP;AACF;SAiBgB,UAAoB,EACnC,SAAS,CAAA,GACT,aAAa,IACb,UACA,kBACA,UAAU,CAAA,KACgB;AAEtB,MAAA,QAAQ,IAAI,aAAa,eAAe;AAC3C,QAAI,UAAU;AACb,cAAQ,KACP,yGAAyG;AAAA,IAE1G;AAAA,EACD;AAED,QAAM,iBAAiB,OAAO,IAAI,CAAC,OAAO,UAAS;AAClD,UAAM,OAAO,gBAAgB,QAAQ,MAAM,aAAa,MAAM;AAE1D,QAAA,OAAO,WAAW,IAA+B,KAAK;AAG1D,QAAI,UAAU;AACb,YAAM,eAAe,SAAS;AAAA,QAC7B;AAAA,QACA,WAAW,WAAW,IAAI;AAAA,QAC1B,GAAG;AAAA,MAAA,CACH;AAED,UAAI,cAAc;AACV,eAAA;AAAA,MACP;AAAA,IACD;AAEK,UAAA,MACL,QAAQ,SAAS,MAAM,KACpB,MAAM,KACN,GAAG,SAAS,KAAK,UAAU,KAAK;AAEpC,QAAI,MAAM;AACT,UAAI,MAAM,UAAU;AACnB,cAAM,EAAE,UAAU,GAAG,YAAA,IAAgB;AAErC,eAAQ,oBAAA,MAAA,EAAe,GAAI,YAAA,GAAT,GAAqB;AAAA,MAAA,OACjC;AACN,mCACE,MAEA,EAAA,OACA,OACA,QACA,WAJK,GAIY;AAAA,MAGnB;AAAA,IAAA,OACK;AACC,aAAA,oBAAC,oBAA6B,EAAA,MAAA,GAAL,GAAkB;AAAA,IAClD;AAAA,EAAA,CACD;AAED,yCAAU,UAAe,eAAA,CAAA;AAC1B;"}
|
|
1
|
+
{"version":3,"file":"SliceZone.js","sources":["../src/SliceZone.tsx"],"sourcesContent":["import type { ComponentType, FC } from \"react\";\nimport type { Slice } from \"@prismicio/client\";\nimport { DEV } from \"esm-env\";\n\n/**\n * Returns the type of a `SliceLike` type.\n *\n * @typeParam Slice - The Slice from which the type will be extracted.\n */\ntype ExtractSliceType<TSlice extends SliceLike> = TSlice extends Slice\n\t? TSlice[\"slice_type\"]\n\t: TSlice extends SliceLikeGraphQL\n\t\t? TSlice[\"type\"]\n\t\t: never;\n\n/**\n * The minimum required properties to represent a Prismic Slice from the Prismic\n * Rest API V2 for the `unstable_mapSliceZone()` helper.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\nexport type SliceLikeRestV2<TSliceType extends string = string> = Pick<\n\tSlice<TSliceType>,\n\t\"id\" | \"slice_type\"\n>;\n\n/**\n * The minimum required properties to represent a Prismic Slice from the Prismic\n * GraphQL API for the `unstable_mapSliceZone()` helper.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\nexport type SliceLikeGraphQL<TSliceType extends string = string> = {\n\ttype: Slice<TSliceType>[\"slice_type\"];\n};\n\n/**\n * The minimum required properties to represent a Prismic Slice for the\n * `unstable_mapSliceZone()` helper.\n *\n * If using Prismic's Rest API V2, use the `Slice` export from\n * `@prismicio/client` for a full interface.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\nexport type SliceLike<TSliceType extends string = string> = (\n\t| SliceLikeRestV2<TSliceType>\n\t| SliceLikeGraphQL<TSliceType>\n) & {\n\t/**\n\t * If `true`, this Slice has been modified from its original value using a\n\t * mapper and `@prismicio/client`'s `mapSliceZone()`.\n\t *\n\t * @internal\n\t */\n\t__mapped?: true;\n};\n\n/**\n * A looser version of the `SliceZone` type from `@prismicio/client` using\n * `SliceLike`.\n *\n * If using Prismic's Rest API V2, use the `SliceZone` export from\n * `@prismicio/client` for the full type.\n *\n * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.\n */\nexport type SliceZoneLike<TSlice extends SliceLike = SliceLike> =\n\treadonly TSlice[];\n\n/**\n * React props for a component rendering content from a Prismic Slice using the\n * `<SliceZone>` component.\n *\n * @typeParam TSlice - The Slice passed as a prop.\n * @typeParam TContext - Arbitrary data passed to `<SliceZone>` and made\n * available to all Slice components.\n */\nexport type SliceComponentProps<\n\tTSlice extends SliceLike = SliceLike,\n\tTContext = unknown,\n> = {\n\t/** Slice data for this component. */\n\tslice: TSlice;\n\n\t/** The index of the Slice in the Slice Zone. */\n\tindex: number;\n\n\t/** All Slices from the Slice Zone to which the Slice belongs. */\n\t// TODO: We have to keep this list of Slices general due to circular\n\t// reference limtiations. If we had another generic to determine the full\n\t// union of Slice types, it would include TSlice. This causes TypeScript to\n\t// throw a compilation error.\n\tslices: SliceZoneLike<\n\t\tTSlice extends SliceLikeGraphQL ? SliceLikeGraphQL : SliceLikeRestV2\n\t>;\n\n\t/**\n\t * Arbitrary data passed to `<SliceZone>` and made available to all Slice\n\t * components.\n\t */\n\tcontext: TContext;\n};\n\n/**\n * A React component to be rendered for each instance of its Slice.\n *\n * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.\n * @typeParam TContext - Arbitrary data made available to all Slice components.\n */\nexport type SliceComponentType<\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tTSlice extends SliceLike = any,\n\tTContext = unknown,\n> = ComponentType<SliceComponentProps<TSlice, TContext>>;\n\n/**\n * A record of Slice types mapped to a React component. The component will be\n * rendered for each instance of its Slice.\n *\n * @deprecated This type is no longer used by `@prismicio/react`. Prefer using\n * `Record<string, SliceComponentType<any>>` instead.\n *\n * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.\n * @typeParam TContext - Arbitrary data made available to all Slice components.\n */\nexport type SliceZoneComponents<\n\tTSlice extends SliceLike = SliceLike,\n\tTContext = unknown,\n> =\n\t// This is purposely not wrapped in Partial to ensure a component is provided\n\t// for all Slice types. <SliceZone> will render a default component if one is\n\t// not provided, but it *should* be a type error if an explicit component is\n\t// missing.\n\t//\n\t// If a developer purposely does not want to provide a component, they can\n\t// assign it to the TODOSliceComponent exported from this package. This\n\t// signals to future developers that it is a placeholder and should be\n\t// implemented.\n\t{\n\t\t[SliceType in ExtractSliceType<TSlice>]: SliceComponentType<\n\t\t\tExtract<TSlice, SliceLike<SliceType>> extends never\n\t\t\t\t? SliceLike\n\t\t\t\t: Extract<TSlice, SliceLike<SliceType>>,\n\t\t\tTContext\n\t\t>;\n\t};\n\n/**\n * React props for the `<SliceZone>` component.\n *\n * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.\n * @typeParam TContext - Arbitrary data made available to all Slice components.\n */\nexport type SliceZoneProps<TContext = unknown> = {\n\t/** List of Slice data from the Slice Zone. */\n\tslices?: SliceZoneLike;\n\n\t/** A record mapping Slice types to React components. */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tcomponents?: Record<string, ComponentType<any>>;\n\n\t/**\n\t * The React component rendered if a component mapping from the `components`\n\t * prop cannot be found.\n\t */\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tdefaultComponent?: ComponentType<SliceComponentProps<any, TContext>>;\n\n\t/** Arbitrary data made available to all Slice components. */\n\tcontext?: TContext;\n};\n\n/**\n * This Slice component can be used as a reminder to provide a proper\n * implementation.\n *\n * This is also the default React component rendered when a component mapping\n * cannot be found in `<SliceZone>`.\n */\nexport const TODOSliceComponent = <TSlice extends SliceLike>({\n\tslice,\n}: {\n\tslice: TSlice;\n}) => {\n\tif (!DEV) {\n\t\treturn null;\n\t}\n\n\tconst type = \"slice_type\" in slice ? slice.slice_type : slice.type;\n\n\tconsole.warn(\n\t\t`[SliceZone] Could not find a component for Slice type \"${type}\"`,\n\t\tslice,\n\t);\n\n\treturn (\n\t\t<section data-slice-zone-todo-component=\"\" data-slice-type={type}>\n\t\t\tCould not find a component for Slice type “{type}\n\t\t\t”\n\t\t</section>\n\t);\n};\n\n/**\n * Renders content from a Prismic Slice Zone using React components for each\n * type of Slice.\n *\n * If a component is not provided for a type of Slice, a default component can\n * be provided. A fallback component is provided by default that will not be\n * rendered in a production build of your app.\n *\n * @typeParam TSlice - The type(s) of a Slice in the Slice Zone.\n * @typeParam TContext - Arbitrary data made available to all Slice components.\n *\n * @returns The Slice Zone's content as React components.\n *\n * @see Learn about Prismic Slices and Slice Zones {@link https://prismic.io/docs/core-concepts/slices}\n */\nexport const SliceZone: FC<SliceZoneProps> = (props) => {\n\tconst {\n\t\tslices = [],\n\t\tcomponents = {},\n\t\tdefaultComponent,\n\t\tcontext = {},\n\t} = props;\n\n\tconst renderedSlices = slices.map((slice, index) => {\n\t\tconst type = \"slice_type\" in slice ? slice.slice_type : slice.type;\n\n\t\tconst key =\n\t\t\t\"id\" in slice && slice.id\n\t\t\t\t? slice.id\n\t\t\t\t: `${index}-${JSON.stringify(slice)}`;\n\n\t\tconst Comp =\n\t\t\tcomponents[type as keyof typeof components] || defaultComponent;\n\n\t\tif (!Comp) {\n\t\t\treturn <TODOSliceComponent key={key} slice={slice} />;\n\t\t}\n\n\t\tif (slice.__mapped) {\n\t\t\tconst { __mapped, ...mappedProps } = slice;\n\n\t\t\treturn <Comp key={key} {...mappedProps} />;\n\t\t}\n\n\t\treturn (\n\t\t\t<Comp\n\t\t\t\tkey={key}\n\t\t\t\tslice={slice}\n\t\t\t\tindex={index}\n\t\t\t\tslices={slices}\n\t\t\t\tcontext={context}\n\t\t\t/>\n\t\t);\n\t});\n\n\treturn <>{renderedSlices}</>;\n};\n"],"names":["_jsxs","_jsx","_Fragment"],"mappings":";;AAoLO,MAAM,qBAAqB,CAA2B,EAC5D,YAGI;AACJ,MAAI,CAAC,KAAK;AACF,WAAA;AAAA,EAAA;AAGR,QAAM,OAAO,gBAAgB,QAAQ,MAAM,aAAa,MAAM;AAE9D,UAAQ,KACP,0DAA0D,IAAI,KAC9D,KAAK;AAGN,SACCA,oDAAwC,IAAE,mBAAkB,MACT,UAAA,CAAA,+CAAA,MAEzC,GAAA,GAAA;AAEZ;AAiBa,MAAA,YAAgC,CAAC,UAAS;AAChD,QAAA,EACL,SAAS,CAAA,GACT,aAAa,CAAA,GACb,kBACA,UAAU,OACP;AAEJ,QAAM,iBAAiB,OAAO,IAAI,CAAC,OAAO,UAAS;AAClD,UAAM,OAAO,gBAAgB,QAAQ,MAAM,aAAa,MAAM;AAE9D,UAAM,MACL,QAAQ,SAAS,MAAM,KACpB,MAAM,KACN,GAAG,KAAK,IAAI,KAAK,UAAU,KAAK,CAAC;AAE/B,UAAA,OACL,WAAW,IAA+B,KAAK;AAEhD,QAAI,CAAC,MAAM;AACV,aAAOC,IAAC,oBAA6B,EAAA,MAAA,GAAL,GAAG;AAAA,IAAA;AAGpC,QAAI,MAAM,UAAU;AACnB,YAAM,EAAE,UAAU,GAAG,YAAA,IAAgB;AAErC,aAAOA,IAAC,MAAI,EAAA,GAAe,YAAA,GAAT,GAAG;AAAA,IAAA;AAIrB,WAAAA,IAAC,MAAI,EAEJ,OACA,OACA,QACA,WAJK,GAAG;AAAA,EAAA,CAOV;AAED,SAAOA,IAAAC,UAAA,EAAA,UAAG,gBAAc;AACzB;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,21 +1,13 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export type {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export type {
|
|
7
|
-
export {
|
|
8
|
-
export
|
|
9
|
-
export {
|
|
10
|
-
export
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
export type {
|
|
14
|
-
export { SliceZone, TODOSliceComponent } from "./SliceZone";
|
|
15
|
-
export type { SliceComponentProps, SliceComponentType, SliceLike, SliceLikeGraphQL, SliceLikeRestV2, SliceZoneComponents, SliceZoneLike, SliceZoneProps, } from "./SliceZone";
|
|
16
|
-
export { PrismicToolbar } from "./PrismicToolbar";
|
|
17
|
-
export type { PrismicToolbarProps } from "./PrismicToolbar";
|
|
18
|
-
export { usePrismicPreviewResolver } from "./usePrismicPreviewResolver";
|
|
19
|
-
export type { UsePrismicPreviewResolverArgs } from "./usePrismicPreviewResolver";
|
|
20
|
-
export { useAllPrismicDocumentsDangerously, useAllPrismicDocumentsByEveryTag, useAllPrismicDocumentsByIDs, useAllPrismicDocumentsBySomeTags, useAllPrismicDocumentsByTag, useAllPrismicDocumentsByType, useAllPrismicDocumentsByUIDs, useFirstPrismicDocument, usePrismicDocumentByID, usePrismicDocumentByUID, usePrismicDocuments, usePrismicDocumentsByEveryTag, usePrismicDocumentsByIDs, usePrismicDocumentsBySomeTags, usePrismicDocumentsByTag, usePrismicDocumentsByType, usePrismicDocumentsByUIDs, useSinglePrismicDocument, } from "./clientHooks";
|
|
21
|
-
export type { JSXMapSerializer, JSXFunctionSerializer, PrismicClientHookState, } from "./types";
|
|
1
|
+
export { PrismicLink } from "./PrismicLink.js";
|
|
2
|
+
export type { PrismicLinkProps, LinkProps } from "./PrismicLink.js";
|
|
3
|
+
export { PrismicText } from "./PrismicText.js";
|
|
4
|
+
export type { PrismicTextProps } from "./PrismicText.js";
|
|
5
|
+
export { PrismicRichText } from "./PrismicRichText.js";
|
|
6
|
+
export type { PrismicRichTextProps, JSXMapSerializer, JSXFunctionSerializer, } from "./PrismicRichText.js";
|
|
7
|
+
export { Element } from "@prismicio/client/richtext";
|
|
8
|
+
export { PrismicImage } from "./PrismicImage.js";
|
|
9
|
+
export type { PrismicImageProps } from "./PrismicImage.js";
|
|
10
|
+
export { SliceZone, TODOSliceComponent } from "./SliceZone.js";
|
|
11
|
+
export type { SliceComponentProps, SliceComponentType, SliceLike, SliceLikeGraphQL, SliceLikeRestV2, SliceZoneComponents, SliceZoneLike, SliceZoneProps, } from "./SliceZone.js";
|
|
12
|
+
export { PrismicToolbar } from "./PrismicToolbar.js";
|
|
13
|
+
export type { PrismicToolbarProps } from "./PrismicToolbar.js";
|
package/dist/index.js
CHANGED
|
@@ -1,45 +1,18 @@
|
|
|
1
|
-
import { PrismicProvider } from "./PrismicProvider.js";
|
|
2
|
-
import { usePrismicContext } from "./usePrismicContext.js";
|
|
3
|
-
import { usePrismicClient } from "./usePrismicClient.js";
|
|
4
1
|
import { PrismicLink } from "./PrismicLink.js";
|
|
5
2
|
import { PrismicText } from "./PrismicText.js";
|
|
6
3
|
import { PrismicRichText } from "./PrismicRichText.js";
|
|
7
|
-
import { Element } from "@prismicio/richtext";
|
|
4
|
+
import { Element } from "@prismicio/client/richtext";
|
|
8
5
|
import { PrismicImage } from "./PrismicImage.js";
|
|
9
6
|
import { SliceZone, TODOSliceComponent } from "./SliceZone.js";
|
|
10
7
|
import { PrismicToolbar } from "./PrismicToolbar.js";
|
|
11
|
-
import { usePrismicPreviewResolver } from "./usePrismicPreviewResolver.js";
|
|
12
|
-
import { useAllPrismicDocumentsByEveryTag, useAllPrismicDocumentsByIDs, useAllPrismicDocumentsBySomeTags, useAllPrismicDocumentsByTag, useAllPrismicDocumentsByType, useAllPrismicDocumentsByUIDs, useAllPrismicDocumentsDangerously, useFirstPrismicDocument, usePrismicDocumentByID, usePrismicDocumentByUID, usePrismicDocuments, usePrismicDocumentsByEveryTag, usePrismicDocumentsByIDs, usePrismicDocumentsBySomeTags, usePrismicDocumentsByTag, usePrismicDocumentsByType, usePrismicDocumentsByUIDs, useSinglePrismicDocument } from "./clientHooks.js";
|
|
13
8
|
export {
|
|
14
9
|
Element,
|
|
15
10
|
PrismicImage,
|
|
16
11
|
PrismicLink,
|
|
17
|
-
PrismicProvider,
|
|
18
12
|
PrismicRichText,
|
|
19
13
|
PrismicText,
|
|
20
14
|
PrismicToolbar,
|
|
21
15
|
SliceZone,
|
|
22
|
-
TODOSliceComponent
|
|
23
|
-
useAllPrismicDocumentsByEveryTag,
|
|
24
|
-
useAllPrismicDocumentsByIDs,
|
|
25
|
-
useAllPrismicDocumentsBySomeTags,
|
|
26
|
-
useAllPrismicDocumentsByTag,
|
|
27
|
-
useAllPrismicDocumentsByType,
|
|
28
|
-
useAllPrismicDocumentsByUIDs,
|
|
29
|
-
useAllPrismicDocumentsDangerously,
|
|
30
|
-
useFirstPrismicDocument,
|
|
31
|
-
usePrismicClient,
|
|
32
|
-
usePrismicContext,
|
|
33
|
-
usePrismicDocumentByID,
|
|
34
|
-
usePrismicDocumentByUID,
|
|
35
|
-
usePrismicDocuments,
|
|
36
|
-
usePrismicDocumentsByEveryTag,
|
|
37
|
-
usePrismicDocumentsByIDs,
|
|
38
|
-
usePrismicDocumentsBySomeTags,
|
|
39
|
-
usePrismicDocumentsByTag,
|
|
40
|
-
usePrismicDocumentsByType,
|
|
41
|
-
usePrismicDocumentsByUIDs,
|
|
42
|
-
usePrismicPreviewResolver,
|
|
43
|
-
useSinglePrismicDocument
|
|
16
|
+
TODOSliceComponent
|
|
44
17
|
};
|
|
45
18
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;"}
|
package/dist/lib/devMsg.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* ```ts
|
|
7
7
|
* devMsg("missing-param");
|
|
8
|
-
* // => "https://prismic.dev/msg/react/v1.2.3/missing-param
|
|
8
|
+
* // => "https://prismic.dev/msg/react/v1.2.3/missing-param"
|
|
9
9
|
* ```
|
|
10
10
|
*
|
|
11
11
|
* @param slug - Slug for the message. This corresponds to a Markdown file in
|
|
@@ -13,4 +13,4 @@
|
|
|
13
13
|
*
|
|
14
14
|
* @returns The `prismic.dev/msg` URL for the given slug.
|
|
15
15
|
*/
|
|
16
|
-
export declare
|
|
16
|
+
export declare function devMsg(slug: string): string;
|
package/dist/lib/devMsg.js
CHANGED
package/dist/lib/devMsg.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devMsg.js","sources":["
|
|
1
|
+
{"version":3,"file":"devMsg.js","sources":["../../src/lib/devMsg.ts"],"sourcesContent":["import { version } from \"../../package.json\";\n\n/**\n * Returns a `prismic.dev/msg` URL for a given message slug.\n *\n * @example\n *\n * ```ts\n * devMsg(\"missing-param\");\n * // => \"https://prismic.dev/msg/react/v1.2.3/missing-param\"\n * ```\n *\n * @param slug - Slug for the message. This corresponds to a Markdown file in\n * the Git repository's `/messages` directory.\n *\n * @returns The `prismic.dev/msg` URL for the given slug.\n */\nexport function devMsg(slug: string) {\n\treturn `https://prismic.dev/msg/react/v${version}/${slug}`;\n}\n"],"names":[],"mappings":";AAiBM,SAAU,OAAO,MAAY;AAC3B,SAAA,kCAAkC,OAAO,IAAI,IAAI;AACzD;"}
|
package/dist/package.json.js
CHANGED