@prismicio/react 2.5.2 → 2.6.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/PrismicImage.cjs +7 -11
- package/dist/PrismicImage.cjs.map +1 -1
- package/dist/PrismicImage.d.ts +14 -15
- package/dist/PrismicImage.js +6 -10
- package/dist/PrismicImage.js.map +1 -1
- package/dist/PrismicLink.cjs +4 -66
- package/dist/PrismicLink.cjs.map +1 -1
- package/dist/PrismicLink.d.ts +5 -104
- package/dist/PrismicLink.js +4 -65
- package/dist/PrismicLink.js.map +1 -1
- package/dist/PrismicProvider.cjs.map +1 -1
- package/dist/PrismicProvider.d.ts +8 -9
- package/dist/PrismicProvider.js.map +1 -1
- package/dist/PrismicRichText.cjs +4 -71
- package/dist/PrismicRichText.cjs.map +1 -1
- package/dist/PrismicRichText.d.ts +4 -116
- package/dist/PrismicRichText.js +5 -70
- package/dist/PrismicRichText.js.map +1 -1
- package/dist/PrismicText.cjs +4 -4
- package/dist/PrismicText.cjs.map +1 -1
- package/dist/PrismicText.d.ts +2 -2
- package/dist/PrismicText.js +3 -3
- package/dist/PrismicText.js.map +1 -1
- package/dist/PrismicToolbar.cjs +6 -4
- package/dist/PrismicToolbar.cjs.map +1 -1
- package/dist/PrismicToolbar.d.ts +3 -1
- package/dist/PrismicToolbar.js +6 -4
- package/dist/PrismicToolbar.js.map +1 -1
- package/dist/SliceZone.cjs +4 -17
- package/dist/SliceZone.cjs.map +1 -1
- package/dist/SliceZone.d.ts +4 -65
- package/dist/SliceZone.js +4 -17
- package/dist/SliceZone.js.map +1 -1
- package/dist/index.cjs +0 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -27
- package/dist/index.js +1 -4
- package/dist/index.js.map +1 -1
- package/dist/package.json.cjs +1 -1
- package/dist/package.json.js +1 -1
- package/dist/react-server/PrismicLink.cjs +59 -0
- package/dist/react-server/PrismicLink.cjs.map +1 -0
- package/dist/react-server/PrismicLink.d.ts +72 -0
- package/dist/react-server/PrismicLink.js +42 -0
- package/dist/react-server/PrismicLink.js.map +1 -0
- package/dist/react-server/PrismicRichText.cjs +92 -0
- package/dist/react-server/PrismicRichText.cjs.map +1 -0
- package/dist/react-server/PrismicRichText.d.ts +104 -0
- package/dist/react-server/PrismicRichText.js +73 -0
- package/dist/react-server/PrismicRichText.js.map +1 -0
- package/dist/react-server/index.d.ts +4 -0
- package/dist/react-server/unsupported.cjs +97 -0
- package/dist/react-server/unsupported.cjs.map +1 -0
- package/dist/react-server/unsupported.d.ts +22 -0
- package/dist/react-server/unsupported.js +97 -0
- package/dist/react-server/unsupported.js.map +1 -0
- package/dist/react-server.cjs +44 -0
- package/dist/react-server.cjs.map +1 -0
- package/dist/react-server.js +41 -0
- package/dist/react-server.js.map +1 -0
- package/dist/useStatefulPrismicClientMethod.cjs +6 -0
- package/dist/useStatefulPrismicClientMethod.cjs.map +1 -1
- package/dist/useStatefulPrismicClientMethod.d.ts +1 -1
- package/dist/useStatefulPrismicClientMethod.js +6 -0
- package/dist/useStatefulPrismicClientMethod.js.map +1 -1
- package/package.json +42 -47
- package/src/PrismicImage.tsx +30 -37
- package/src/PrismicLink.tsx +29 -258
- package/src/PrismicProvider.tsx +9 -8
- package/src/PrismicRichText.tsx +28 -275
- package/src/PrismicText.tsx +4 -5
- package/src/PrismicToolbar.tsx +7 -6
- package/src/SliceZone.tsx +8 -129
- package/src/index.ts +1 -9
- package/src/react-server/PrismicLink.tsx +179 -0
- package/src/react-server/PrismicRichText.tsx +267 -0
- package/src/react-server/index.ts +38 -0
- package/src/react-server/unsupported.ts +98 -0
- package/dist/lib/pascalCase.cjs +0 -10
- package/dist/lib/pascalCase.cjs.map +0 -1
- package/dist/lib/pascalCase.js +0 -10
- package/dist/lib/pascalCase.js.map +0 -1
package/dist/PrismicToolbar.cjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use client';
|
|
1
3
|
"use strict";
|
|
2
4
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
5
|
const React = require("react");
|
|
6
|
+
const prismic = require("@prismicio/client");
|
|
4
7
|
function _interopNamespaceDefault(e) {
|
|
5
8
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
6
9
|
if (e) {
|
|
@@ -18,8 +21,8 @@ function _interopNamespaceDefault(e) {
|
|
|
18
21
|
return Object.freeze(n);
|
|
19
22
|
}
|
|
20
23
|
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
21
|
-
const PrismicToolbar = ({ repositoryName
|
|
22
|
-
const src =
|
|
24
|
+
const PrismicToolbar = ({ repositoryName }) => {
|
|
25
|
+
const src = prismic.getToolbarSrc(repositoryName);
|
|
23
26
|
React__namespace.useEffect(() => {
|
|
24
27
|
const existingScript = document.querySelector(`script[src="${src}"]`);
|
|
25
28
|
if (!existingScript) {
|
|
@@ -28,13 +31,12 @@ const PrismicToolbar = ({ repositoryName, type = "new" }) => {
|
|
|
28
31
|
script.defer = true;
|
|
29
32
|
script.dataset.prismicToolbar = "";
|
|
30
33
|
script.dataset.repositoryName = repositoryName;
|
|
31
|
-
script.dataset.type = type;
|
|
32
34
|
if (process.env.NODE_ENV === "test") {
|
|
33
35
|
script._evaluateScript = false;
|
|
34
36
|
}
|
|
35
37
|
document.body.appendChild(script);
|
|
36
38
|
}
|
|
37
|
-
}, [repositoryName,
|
|
39
|
+
}, [repositoryName, src]);
|
|
38
40
|
return null;
|
|
39
41
|
};
|
|
40
42
|
exports.PrismicToolbar = PrismicToolbar;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicToolbar.cjs","sources":["../../src/PrismicToolbar.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"PrismicToolbar.cjs","sources":["../../src/PrismicToolbar.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { getToolbarSrc } from \"@prismicio/client\";\n\n/**\n * Props for `<PrismicToolbar>`.\n */\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\t/**\n\t * The type of toolbar needed for the repository. Defaults to `\"new\"`.\n\t *\n\t * @deprecated All repositories use the \"new\"-type toolbar. This option can be\n\t * removed.\n\t * @see To check which version you need, view the Prismic Toolbar documentation {@link https://prismic.io/docs/technologies/previews-and-the-prismic-toolbar-reactjs}\n\t */\n\ttype?: \"new\" | \"legacy\";\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 = ({\n\trepositoryName,\n}: PrismicToolbarProps): null => {\n\tconst src = getToolbarSrc(repositoryName);\n\n\tReact.useEffect(() => {\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\n\t\t\t// tests.\n\t\t\t//\n\t\t\t// This is a patch ONLY INCLUDED DURING TESTS. It will\n\t\t\t// be pruned during code minification in non-test\n\t\t\t// environments.\n\t\t\t//\n\t\t\t// @see https://github.com/capricorn86/happy-dom/blob/02ae081e36f990c06171eda44f9d885fd9413d73/packages/happy-dom/src/nodes/html-script-element/HTMLScriptElement.ts#L191-L209\n\t\t\tif (process.env.NODE_ENV === \"test\") {\n\t\t\t\t// @ts-expect-error - `_evaluateScript` is a Happy DOM-specific property.\n\t\t\t\tscript._evaluateScript = false;\n\t\t\t}\n\n\t\t\tdocument.body.appendChild(script);\n\t\t}\n\t}, [repositoryName, src]);\n\n\treturn null;\n};\n"],"names":["React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA6BO;AAGA;AAENA;AACC;AAEA;AACO;AACN;AACA;AAGA;AACA;AAUI;AAEH;AAAyB;AAGjB;AAAuB;AAChC;AAGK;AACR;;"}
|
package/dist/PrismicToolbar.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export type PrismicToolbarProps = {
|
|
|
10
10
|
/**
|
|
11
11
|
* The type of toolbar needed for the repository. Defaults to `"new"`.
|
|
12
12
|
*
|
|
13
|
+
* @deprecated All repositories use the "new"-type toolbar. This option can be
|
|
14
|
+
* removed.
|
|
13
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}
|
|
14
16
|
*/
|
|
15
17
|
type?: "new" | "legacy";
|
|
@@ -18,4 +20,4 @@ export type PrismicToolbarProps = {
|
|
|
18
20
|
* React component that injects the Prismic Toolbar into the app. This component
|
|
19
21
|
* can be placed anywhere in the React tree.
|
|
20
22
|
*/
|
|
21
|
-
export declare const PrismicToolbar: ({ repositoryName,
|
|
23
|
+
export declare const PrismicToolbar: ({ repositoryName, }: PrismicToolbarProps) => null;
|
package/dist/PrismicToolbar.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use client';
|
|
1
3
|
import * as React from "react";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
+
import { getToolbarSrc } from "@prismicio/client";
|
|
5
|
+
const PrismicToolbar = ({ repositoryName }) => {
|
|
6
|
+
const src = getToolbarSrc(repositoryName);
|
|
4
7
|
React.useEffect(() => {
|
|
5
8
|
const existingScript = document.querySelector(`script[src="${src}"]`);
|
|
6
9
|
if (!existingScript) {
|
|
@@ -9,13 +12,12 @@ const PrismicToolbar = ({ repositoryName, type = "new" }) => {
|
|
|
9
12
|
script.defer = true;
|
|
10
13
|
script.dataset.prismicToolbar = "";
|
|
11
14
|
script.dataset.repositoryName = repositoryName;
|
|
12
|
-
script.dataset.type = type;
|
|
13
15
|
if (process.env.NODE_ENV === "test") {
|
|
14
16
|
script._evaluateScript = false;
|
|
15
17
|
}
|
|
16
18
|
document.body.appendChild(script);
|
|
17
19
|
}
|
|
18
|
-
}, [repositoryName,
|
|
20
|
+
}, [repositoryName, src]);
|
|
19
21
|
return null;
|
|
20
22
|
};
|
|
21
23
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicToolbar.js","sources":["../../src/PrismicToolbar.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"PrismicToolbar.js","sources":["../../src/PrismicToolbar.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { getToolbarSrc } from \"@prismicio/client\";\n\n/**\n * Props for `<PrismicToolbar>`.\n */\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\t/**\n\t * The type of toolbar needed for the repository. Defaults to `\"new\"`.\n\t *\n\t * @deprecated All repositories use the \"new\"-type toolbar. This option can be\n\t * removed.\n\t * @see To check which version you need, view the Prismic Toolbar documentation {@link https://prismic.io/docs/technologies/previews-and-the-prismic-toolbar-reactjs}\n\t */\n\ttype?: \"new\" | \"legacy\";\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 = ({\n\trepositoryName,\n}: PrismicToolbarProps): null => {\n\tconst src = getToolbarSrc(repositoryName);\n\n\tReact.useEffect(() => {\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\n\t\t\t// tests.\n\t\t\t//\n\t\t\t// This is a patch ONLY INCLUDED DURING TESTS. It will\n\t\t\t// be pruned during code minification in non-test\n\t\t\t// environments.\n\t\t\t//\n\t\t\t// @see https://github.com/capricorn86/happy-dom/blob/02ae081e36f990c06171eda44f9d885fd9413d73/packages/happy-dom/src/nodes/html-script-element/HTMLScriptElement.ts#L191-L209\n\t\t\tif (process.env.NODE_ENV === \"test\") {\n\t\t\t\t// @ts-expect-error - `_evaluateScript` is a Happy DOM-specific property.\n\t\t\t\tscript._evaluateScript = false;\n\t\t\t}\n\n\t\t\tdocument.body.appendChild(script);\n\t\t}\n\t}, [repositoryName, src]);\n\n\treturn null;\n};\n"],"names":[],"mappings":";;;;AA6BO;AAGA;AAEN;AACC;AAEA;AACO;AACN;AACA;AAGA;AACA;AAUI;AAEH;AAAyB;AAGjB;AAAuB;AAChC;AAGK;AACR;;;;"}
|
package/dist/SliceZone.cjs
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const jsxRuntime = require("react/jsx-runtime");
|
|
4
4
|
const React = require("react");
|
|
5
5
|
const __PRODUCTION__ = require("./lib/__PRODUCTION__.cjs");
|
|
6
|
-
const pascalCase = require("./lib/pascalCase.cjs");
|
|
7
6
|
function _interopNamespaceDefault(e) {
|
|
8
7
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
9
8
|
if (e) {
|
|
@@ -23,34 +22,22 @@ function _interopNamespaceDefault(e) {
|
|
|
23
22
|
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
24
23
|
const TODOSliceComponent = __PRODUCTION__.__PRODUCTION__ ? () => null : ({ slice }) => {
|
|
25
24
|
const type = "slice_type" in slice ? slice.slice_type : slice.type;
|
|
26
|
-
|
|
27
|
-
console.warn(`[SliceZone] Could not find a component for Slice type "${type}"`, slice);
|
|
28
|
-
}, [slice, type]);
|
|
25
|
+
console.warn(`[SliceZone] Could not find a component for Slice type "${type}"`);
|
|
29
26
|
return /* @__PURE__ */ jsxRuntime.jsxs("section", { "data-slice-zone-todo-component": "", "data-slice-type": type, children: [
|
|
30
27
|
"Could not find a component for Slice type “",
|
|
31
28
|
type,
|
|
32
29
|
"”"
|
|
33
30
|
] });
|
|
34
31
|
};
|
|
35
|
-
const SliceZone = ({ slices = [], components = {},
|
|
32
|
+
const SliceZone = ({ slices = [], components = {}, defaultComponent = TODOSliceComponent, context = {} }) => {
|
|
36
33
|
const renderedSlices = React__namespace.useMemo(() => {
|
|
37
34
|
return slices.map((slice, index) => {
|
|
38
35
|
const type = "slice_type" in slice ? slice.slice_type : slice.type;
|
|
39
|
-
|
|
40
|
-
if (resolver) {
|
|
41
|
-
const resolvedComp = resolver({
|
|
42
|
-
slice,
|
|
43
|
-
sliceName: pascalCase.pascalCase(type),
|
|
44
|
-
i: index
|
|
45
|
-
});
|
|
46
|
-
if (resolvedComp) {
|
|
47
|
-
Comp = resolvedComp;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
36
|
+
const Comp = components[type] || defaultComponent;
|
|
50
37
|
const key = "id" in slice && slice.id ? slice.id : `${index}-${JSON.stringify(slice)}`;
|
|
51
38
|
return /* @__PURE__ */ jsxRuntime.jsx(Comp, { slice, index, slices, context }, key);
|
|
52
39
|
});
|
|
53
|
-
}, [components, context, defaultComponent, slices
|
|
40
|
+
}, [components, context, defaultComponent, slices]);
|
|
54
41
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: renderedSlices });
|
|
55
42
|
};
|
|
56
43
|
exports.SliceZone = SliceZone;
|
package/dist/SliceZone.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SliceZone.cjs","sources":["../../src/SliceZone.tsx"],"sourcesContent":["import * as React from \"react\";\nimport * as prismicT from \"@prismicio/types\";\n\nimport { __PRODUCTION__ } from \"./lib/__PRODUCTION__\";\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<Slice extends SliceLike> = Slice extends SliceLikeRestV2\n\t? Slice[\"slice_type\"]\n\t: Slice extends SliceLikeGraphQL\n\t? Slice[\"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 `<SliceZone>` component.\n *\n * If using Prismic's Rest API V2, use the `Slice` export from\n * `@prismicio/types` for a full interface.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\nexport type SliceLikeRestV2<SliceType extends string = string> = {\n\tslice_type: prismicT.Slice<SliceType>[\"slice_type\"];\n\tid?: string;\n};\n\n/**\n * The minimum required properties to represent a Prismic Slice from the Prismic\n * GraphQL API for the `<SliceZone>` component.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\nexport type SliceLikeGraphQL<SliceType extends string = string> = {\n\ttype: prismicT.Slice<SliceType>[\"slice_type\"];\n};\n\n/**\n * The minimum required properties to represent a Prismic Slice for the\n * `<SliceZone>` component.\n *\n * If using Prismic's Rest API V2, use the `Slice` export from\n * `@prismicio/types` for a full interface.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\nexport type SliceLike<SliceType extends string = string> =\n\t| SliceLikeRestV2<SliceType>\n\t| SliceLikeGraphQL<SliceType>;\n\n/**\n * A looser version of the `SliceZone` type from `@prismicio/types` using\n * `SliceLike`.\n *\n * If using Prismic's Rest API V2, use the `SliceZone` export from\n * `@prismicio/types` 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 = any,\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<SliceLike>;\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 * 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 = __PRODUCTION__\n\t? () => null\n\t: <TSlice extends SliceLike, TContext>({\n\t\t\tslice,\n\t }: SliceComponentProps<TSlice, TContext>): JSX.Element | null => {\n\t\t\tconst type = \"slice_type\" in slice ? slice.slice_type : slice.type;\n\n\t\t\tReact.useEffect(() => {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[SliceZone] Could not find a component for Slice type \"${type}\"`,\n\t\t\t\t\tslice,\n\t\t\t\t);\n\t\t\t}, [slice, type]);\n\n\t\t\treturn (\n\t\t\t\t<section data-slice-zone-todo-component=\"\" data-slice-type={type}>\n\t\t\t\t\tCould not find a component for Slice type “{type}\n\t\t\t\t\t”\n\t\t\t\t</section>\n\t\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\tTContext = unknown,\n> = (args: SliceZoneResolverArgs<TSlice>) =>\n\t| SliceComponentType<\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\tany,\n\t\t\tTContext\n\t >\n\t| undefined\n\t| 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, SliceComponentType<any, TContext>>;\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, TContext>;\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?: SliceComponentType<any, TContext>;\n\n\t/**\n\t * Arbitrary data made available to all Slice components.\n\t */\n\tcontext?: TContext;\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 = <TContext,>({\n\tslices = [],\n\tcomponents = {},\n\tresolver,\n\tdefaultComponent = TODOSliceComponent,\n\tcontext = {} as TContext,\n}: SliceZoneProps<TContext>): JSX.Element => {\n\tconst renderedSlices = React.useMemo(() => {\n\t\treturn slices.map((slice, index) => {\n\t\t\tconst type = \"slice_type\" in slice ? slice.slice_type : slice.type;\n\n\t\t\tlet Comp =\n\t\t\t\tcomponents[type as keyof typeof components] || defaultComponent;\n\n\t\t\t// TODO: Remove `resolver` in v3 in favor of `components`.\n\t\t\tif (resolver) {\n\t\t\t\tconst resolvedComp = resolver({\n\t\t\t\t\tslice,\n\t\t\t\t\tsliceName: pascalCase(type),\n\t\t\t\t\ti: index,\n\t\t\t\t});\n\n\t\t\t\tif (resolvedComp) {\n\t\t\t\t\tComp = resolvedComp as typeof Comp;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst key =\n\t\t\t\t\"id\" in slice && slice.id\n\t\t\t\t\t? slice.id\n\t\t\t\t\t: `${index}-${JSON.stringify(slice)}`;\n\n\t\t\treturn (\n\t\t\t\t<Comp\n\t\t\t\t\tkey={key}\n\t\t\t\t\tslice={slice}\n\t\t\t\t\tindex={index}\n\t\t\t\t\tslices={slices}\n\t\t\t\t\tcontext={context}\n\t\t\t\t/>\n\t\t\t);\n\t\t});\n\t}, [components, context, defaultComponent, slices, resolver]);\n\n\treturn <>{renderedSlices}</>;\n};\n"],"names":["__PRODUCTION__","React","jsxs","pascalCase"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA2JO,MAAM,qBAAqBA,eAAAA,iBAC/B,MAAM,OACN,CAAqC,EACrC,YACgE;AAChE,QAAM,OAAO,gBAAgB,QAAQ,MAAM,aAAa,MAAM;AAE9DC,mBAAM,UAAU,MAAK;AACZ,YAAA,KACP,0DAA0D,SAC1D,KAAK;AAAA,EAAA,GAEJ,CAAC,OAAO,IAAI,CAAC;AAEhB,SACEC,2BAAAA,KAAA,WAAA,EAAQ,kCAA+B,IAAG,mBAAiB,MAC3D,UAAA;AAAA,IAAA;AAAA,IAAkD;AAAA,IAClD;AAAA,EACD,EAAA,CAAA;AAED;AA6GI,MAAM,YAAY,CAAY,EACpC,SAAS,CAAA,GACT,aAAa,CAAA,GACb,UACA,mBAAmB,oBACnB,UAAU,SACiC;AACrC,QAAA,iBAAiBD,iBAAM,QAAQ,MAAK;AACzC,WAAO,OAAO,IAAI,CAAC,OAAO,UAAS;AAClC,YAAM,OAAO,gBAAgB,QAAQ,MAAM,aAAa,MAAM;AAE1D,UAAA,OACH,WAAW,SAAoC;AAGhD,UAAI,UAAU;AACb,cAAM,eAAe,SAAS;AAAA,UAC7B;AAAA,UACA,WAAWE,sBAAW,IAAI;AAAA,UAC1B,GAAG;AAAA,QAAA,CACH;AAED,YAAI,cAAc;AACV,iBAAA;AAAA,QACP;AAAA,MACD;AAEK,YAAA,MACL,QAAQ,SAAS,MAAM,KACpB,MAAM,KACN,GAAG,SAAS,KAAK,UAAU,KAAK;AAEpC,4CACE,MAEA,EAAA,OACA,OACA,QACA,WAJK,GAIY;AAAA,IAAA,CAGnB;AAAA,EAAA,GACC,CAAC,YAAY,SAAS,kBAAkB,QAAQ,QAAQ,CAAC;AAE5D,+DAAU,UAAe,eAAA,CAAA;AAC1B;;;"}
|
|
1
|
+
{"version":3,"file":"SliceZone.cjs","sources":["../../src/SliceZone.tsx"],"sourcesContent":["import * as React from \"react\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { __PRODUCTION__ } from \"./lib/__PRODUCTION__\";\n\n/**\n * The minimum required properties to represent a Prismic Slice from the Prismic\n * Rest API V2 for the `<SliceZone>` component.\n *\n * If using Prismic's Rest API V2, use the `Slice` export from\n * `@prismicio/types` for a full interface.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\nexport type SliceLikeRestV2<SliceType extends string = string> = {\n\tslice_type: prismic.Slice<SliceType>[\"slice_type\"];\n\tid?: string;\n};\n\n/**\n * The minimum required properties to represent a Prismic Slice from the Prismic\n * GraphQL API for the `<SliceZone>` component.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\nexport type SliceLikeGraphQL<SliceType extends string = string> = {\n\ttype: prismic.Slice<SliceType>[\"slice_type\"];\n};\n\n/**\n * The minimum required properties to represent a Prismic Slice for the\n * `<SliceZone>` component.\n *\n * If using Prismic's Rest API V2, use the `Slice` export from\n * `@prismicio/types` for a full interface.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\nexport type SliceLike<SliceType extends string = string> =\n\t| SliceLikeRestV2<SliceType>\n\t| SliceLikeGraphQL<SliceType>;\n\n/**\n * A looser version of the `SliceZone` type from `@prismicio/types` using\n * `SliceLike`.\n *\n * If using Prismic's Rest API V2, use the `SliceZone` export from\n * `@prismicio/types` 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 = any,\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<SliceLike>;\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 * 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 = __PRODUCTION__\n\t? () => null\n\t: <TSlice extends SliceLike, TContext>({\n\t\t\tslice,\n\t }: SliceComponentProps<TSlice, TContext>): JSX.Element | null => {\n\t\t\tconst type = \"slice_type\" in slice ? slice.slice_type : slice.type;\n\n\t\t\tconsole.warn(\n\t\t\t\t`[SliceZone] Could not find a component for Slice type \"${type}\"`,\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\t<section data-slice-zone-todo-component=\"\" data-slice-type={type}>\n\t\t\t\t\tCould not find a component for Slice type “{type}\n\t\t\t\t\t”\n\t\t\t\t</section>\n\t\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/**\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, SliceComponentType<any, TContext>>;\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?: SliceComponentType<any, TContext>;\n\n\t/**\n\t * Arbitrary data made available to all Slice components.\n\t */\n\tcontext?: TContext;\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 = <TContext,>({\n\tslices = [],\n\tcomponents = {},\n\tdefaultComponent = TODOSliceComponent,\n\tcontext = {} as TContext,\n}: SliceZoneProps<TContext>): JSX.Element => {\n\tconst renderedSlices = React.useMemo(() => {\n\t\treturn slices.map((slice, index) => {\n\t\t\tconst type = \"slice_type\" in slice ? slice.slice_type : slice.type;\n\n\t\t\tconst Comp =\n\t\t\t\tcomponents[type as keyof typeof components] || defaultComponent;\n\n\t\t\tconst key =\n\t\t\t\t\"id\" in slice && slice.id\n\t\t\t\t\t? slice.id\n\t\t\t\t\t: `${index}-${JSON.stringify(slice)}`;\n\n\t\t\treturn (\n\t\t\t\t<Comp\n\t\t\t\t\tkey={key}\n\t\t\t\t\tslice={slice}\n\t\t\t\t\tindex={index}\n\t\t\t\t\tslices={slices}\n\t\t\t\t\tcontext={context}\n\t\t\t\t/>\n\t\t\t);\n\t\t});\n\t}, [components, context, defaultComponent, slices]);\n\n\treturn <>{renderedSlices}</>;\n};\n"],"names":["__PRODUCTION__","jsxs","React"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAgHO,MAAM,qBAAqBA,eAAAA,iBAC/B,MAAM,OACN,CAAqC,EACrC,YACgE;AAChE,QAAM,OAAO,gBAAgB,QAAQ,MAAM,aAAa,MAAM;AAEtD,UAAA,KACP,0DAA0D,OAAO;AAGlE,SACEC,2BAAAA,KAAA,WAAA,EAAQ,kCAA+B,IAAG,mBAAiB,MAC3D,UAAA;AAAA,IAAA;AAAA,IAAkD;AAAA,IAClD;AAAA,EACD,EAAA,CAAA;AAED;AAgDI,MAAM,YAAY,CAAY,EACpC,SAAS,CAAA,GACT,aAAa,IACb,mBAAmB,oBACnB,UAAU,CAAA,QACiC;AACrC,QAAA,iBAAiBC,iBAAM,QAAQ,MAAK;AACzC,WAAO,OAAO,IAAI,CAAC,OAAO,UAAS;AAClC,YAAM,OAAO,gBAAgB,QAAQ,MAAM,aAAa,MAAM;AAExD,YAAA,OACL,WAAW,IAA+B,KAAK;AAE1C,YAAA,MACL,QAAQ,SAAS,MAAM,KACpB,MAAM,KACN,GAAG,SAAS,KAAK,UAAU,KAAK;AAEpC,4CACE,MAEA,EAAA,OACA,OACA,QACA,WAJK,GAIY;AAAA,IAAA,CAGnB;AAAA,KACC,CAAC,YAAY,SAAS,kBAAkB,MAAM,CAAC;AAElD,+DAAU,UAAe,eAAA,CAAA;AAC1B;;;"}
|
package/dist/SliceZone.d.ts
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import * as
|
|
3
|
-
import { PascalCase } from "./lib/pascalCase";
|
|
4
|
-
/**
|
|
5
|
-
* Returns the type of a `SliceLike` type.
|
|
6
|
-
*
|
|
7
|
-
* @typeParam Slice - The Slice from which the type will be extracted.
|
|
8
|
-
*/
|
|
9
|
-
type ExtractSliceType<Slice extends SliceLike> = Slice extends SliceLikeRestV2 ? Slice["slice_type"] : Slice extends SliceLikeGraphQL ? Slice["type"] : never;
|
|
2
|
+
import * as prismic from "@prismicio/client";
|
|
10
3
|
/**
|
|
11
4
|
* The minimum required properties to represent a Prismic Slice from the Prismic
|
|
12
5
|
* Rest API V2 for the `<SliceZone>` component.
|
|
@@ -17,7 +10,7 @@ type ExtractSliceType<Slice extends SliceLike> = Slice extends SliceLikeRestV2 ?
|
|
|
17
10
|
* @typeParam SliceType - Type name of the Slice.
|
|
18
11
|
*/
|
|
19
12
|
export type SliceLikeRestV2<SliceType extends string = string> = {
|
|
20
|
-
slice_type:
|
|
13
|
+
slice_type: prismic.Slice<SliceType>["slice_type"];
|
|
21
14
|
id?: string;
|
|
22
15
|
};
|
|
23
16
|
/**
|
|
@@ -27,7 +20,7 @@ export type SliceLikeRestV2<SliceType extends string = string> = {
|
|
|
27
20
|
* @typeParam SliceType - Type name of the Slice.
|
|
28
21
|
*/
|
|
29
22
|
export type SliceLikeGraphQL<SliceType extends string = string> = {
|
|
30
|
-
type:
|
|
23
|
+
type: prismic.Slice<SliceType>["slice_type"];
|
|
31
24
|
};
|
|
32
25
|
/**
|
|
33
26
|
* The minimum required properties to represent a Prismic Slice for the
|
|
@@ -83,18 +76,6 @@ export type SliceComponentProps<TSlice extends SliceLike = any, TContext = unkno
|
|
|
83
76
|
* @typeParam TContext - Arbitrary data made available to all Slice components.
|
|
84
77
|
*/
|
|
85
78
|
export type SliceComponentType<TSlice extends SliceLike = any, TContext = unknown> = React.ComponentType<SliceComponentProps<TSlice, TContext>>;
|
|
86
|
-
/**
|
|
87
|
-
* A record of Slice types mapped to a React component. The component will be
|
|
88
|
-
* rendered for each instance of its Slice.
|
|
89
|
-
*
|
|
90
|
-
* @deprecated This type is no longer used by `@prismicio/react`. Prefer using
|
|
91
|
-
* `Record<string, SliceComponentType<any>>` instead.
|
|
92
|
-
* @typeParam TSlice - The type(s) of a Slice in the Slice Zone.
|
|
93
|
-
* @typeParam TContext - Arbitrary data made available to all Slice components.
|
|
94
|
-
*/
|
|
95
|
-
export type SliceZoneComponents<TSlice extends SliceLike = SliceLike, TContext = unknown> = {
|
|
96
|
-
[SliceType in ExtractSliceType<TSlice>]: SliceComponentType<Extract<TSlice, SliceLike<SliceType>> extends never ? SliceLike : Extract<TSlice, SliceLike<SliceType>>, TContext>;
|
|
97
|
-
};
|
|
98
79
|
/**
|
|
99
80
|
* This Slice component can be used as a reminder to provide a proper
|
|
100
81
|
* implementation.
|
|
@@ -103,36 +84,6 @@ export type SliceZoneComponents<TSlice extends SliceLike = SliceLike, TContext =
|
|
|
103
84
|
* cannot be found in `<SliceZone>`.
|
|
104
85
|
*/
|
|
105
86
|
export declare const TODOSliceComponent: <TSlice extends SliceLike<string>, TContext>({ slice, }: SliceComponentProps<TSlice, TContext>) => JSX.Element | null;
|
|
106
|
-
/**
|
|
107
|
-
* Arguments for a `<SliceZone>` `resolver` function.
|
|
108
|
-
*/
|
|
109
|
-
type SliceZoneResolverArgs<TSlice extends SliceLike = any> = {
|
|
110
|
-
/**
|
|
111
|
-
* The Slice to resolve to a React component.
|
|
112
|
-
*/
|
|
113
|
-
slice: TSlice;
|
|
114
|
-
/**
|
|
115
|
-
* The name of the Slice.
|
|
116
|
-
*/
|
|
117
|
-
sliceName: PascalCase<ExtractSliceType<TSlice>>;
|
|
118
|
-
/**
|
|
119
|
-
* The index of the Slice in the Slice Zone.
|
|
120
|
-
*/
|
|
121
|
-
i: number;
|
|
122
|
-
};
|
|
123
|
-
/**
|
|
124
|
-
* A function that determines the rendered React component for each Slice in the
|
|
125
|
-
* Slice Zone. If a nullish value is returned, the component will fallback to
|
|
126
|
-
* the `components` or `defaultComponent` props to determine the rendered
|
|
127
|
-
* component.
|
|
128
|
-
*
|
|
129
|
-
* @deprecated Use the `components` prop instead.
|
|
130
|
-
*
|
|
131
|
-
* @param args - Arguments for the resolver function.
|
|
132
|
-
*
|
|
133
|
-
* @returns The React component to render for a Slice.
|
|
134
|
-
*/
|
|
135
|
-
export type SliceZoneResolver<TSlice extends SliceLike = any, TContext = unknown> = (args: SliceZoneResolverArgs<TSlice>) => SliceComponentType<any, TContext> | undefined | null;
|
|
136
87
|
/**
|
|
137
88
|
* React props for the `<SliceZone>` component.
|
|
138
89
|
*
|
|
@@ -148,17 +99,6 @@ export type SliceZoneProps<TContext = unknown> = {
|
|
|
148
99
|
* A record mapping Slice types to React components.
|
|
149
100
|
*/
|
|
150
101
|
components?: Record<string, SliceComponentType<any, TContext>>;
|
|
151
|
-
/**
|
|
152
|
-
* A function that determines the rendered React component for each Slice in
|
|
153
|
-
* the Slice Zone.
|
|
154
|
-
*
|
|
155
|
-
* @deprecated Use the `components` prop instead.
|
|
156
|
-
*
|
|
157
|
-
* @param args - Arguments for the resolver function.
|
|
158
|
-
*
|
|
159
|
-
* @returns The React component to render for a Slice.
|
|
160
|
-
*/
|
|
161
|
-
resolver?: SliceZoneResolver<any, TContext>;
|
|
162
102
|
/**
|
|
163
103
|
* The React component rendered if a component mapping from the `components`
|
|
164
104
|
* prop cannot be found.
|
|
@@ -184,5 +124,4 @@ export type SliceZoneProps<TContext = unknown> = {
|
|
|
184
124
|
*
|
|
185
125
|
* @see Learn about Prismic Slices and Slice Zones {@link https://prismic.io/docs/core-concepts/slices}
|
|
186
126
|
*/
|
|
187
|
-
export declare const SliceZone: <TContext>({ slices, components,
|
|
188
|
-
export {};
|
|
127
|
+
export declare const SliceZone: <TContext>({ slices, components, defaultComponent, context, }: SliceZoneProps<TContext>) => JSX.Element;
|
package/dist/SliceZone.js
CHANGED
|
@@ -1,37 +1,24 @@
|
|
|
1
1
|
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { __PRODUCTION__ } from "./lib/__PRODUCTION__.js";
|
|
4
|
-
import { pascalCase } from "./lib/pascalCase.js";
|
|
5
4
|
const TODOSliceComponent = __PRODUCTION__ ? () => null : ({ slice }) => {
|
|
6
5
|
const type = "slice_type" in slice ? slice.slice_type : slice.type;
|
|
7
|
-
|
|
8
|
-
console.warn(`[SliceZone] Could not find a component for Slice type "${type}"`, slice);
|
|
9
|
-
}, [slice, type]);
|
|
6
|
+
console.warn(`[SliceZone] Could not find a component for Slice type "${type}"`);
|
|
10
7
|
return /* @__PURE__ */ jsxs("section", { "data-slice-zone-todo-component": "", "data-slice-type": type, children: [
|
|
11
8
|
"Could not find a component for Slice type “",
|
|
12
9
|
type,
|
|
13
10
|
"”"
|
|
14
11
|
] });
|
|
15
12
|
};
|
|
16
|
-
const SliceZone = ({ slices = [], components = {},
|
|
13
|
+
const SliceZone = ({ slices = [], components = {}, defaultComponent = TODOSliceComponent, context = {} }) => {
|
|
17
14
|
const renderedSlices = React.useMemo(() => {
|
|
18
15
|
return slices.map((slice, index) => {
|
|
19
16
|
const type = "slice_type" in slice ? slice.slice_type : slice.type;
|
|
20
|
-
|
|
21
|
-
if (resolver) {
|
|
22
|
-
const resolvedComp = resolver({
|
|
23
|
-
slice,
|
|
24
|
-
sliceName: pascalCase(type),
|
|
25
|
-
i: index
|
|
26
|
-
});
|
|
27
|
-
if (resolvedComp) {
|
|
28
|
-
Comp = resolvedComp;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
17
|
+
const Comp = components[type] || defaultComponent;
|
|
31
18
|
const key = "id" in slice && slice.id ? slice.id : `${index}-${JSON.stringify(slice)}`;
|
|
32
19
|
return /* @__PURE__ */ jsx(Comp, { slice, index, slices, context }, key);
|
|
33
20
|
});
|
|
34
|
-
}, [components, context, defaultComponent, slices
|
|
21
|
+
}, [components, context, defaultComponent, slices]);
|
|
35
22
|
return /* @__PURE__ */ jsx(Fragment, { children: renderedSlices });
|
|
36
23
|
};
|
|
37
24
|
export {
|
package/dist/SliceZone.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SliceZone.js","sources":["../../src/SliceZone.tsx"],"sourcesContent":["import * as React from \"react\";\nimport * as prismicT from \"@prismicio/types\";\n\nimport { __PRODUCTION__ } from \"./lib/__PRODUCTION__\";\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<Slice extends SliceLike> = Slice extends SliceLikeRestV2\n\t? Slice[\"slice_type\"]\n\t: Slice extends SliceLikeGraphQL\n\t? Slice[\"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 `<SliceZone>` component.\n *\n * If using Prismic's Rest API V2, use the `Slice` export from\n * `@prismicio/types` for a full interface.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\nexport type SliceLikeRestV2<SliceType extends string = string> = {\n\tslice_type: prismicT.Slice<SliceType>[\"slice_type\"];\n\tid?: string;\n};\n\n/**\n * The minimum required properties to represent a Prismic Slice from the Prismic\n * GraphQL API for the `<SliceZone>` component.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\nexport type SliceLikeGraphQL<SliceType extends string = string> = {\n\ttype: prismicT.Slice<SliceType>[\"slice_type\"];\n};\n\n/**\n * The minimum required properties to represent a Prismic Slice for the\n * `<SliceZone>` component.\n *\n * If using Prismic's Rest API V2, use the `Slice` export from\n * `@prismicio/types` for a full interface.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\nexport type SliceLike<SliceType extends string = string> =\n\t| SliceLikeRestV2<SliceType>\n\t| SliceLikeGraphQL<SliceType>;\n\n/**\n * A looser version of the `SliceZone` type from `@prismicio/types` using\n * `SliceLike`.\n *\n * If using Prismic's Rest API V2, use the `SliceZone` export from\n * `@prismicio/types` 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 = any,\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<SliceLike>;\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 * 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 = __PRODUCTION__\n\t? () => null\n\t: <TSlice extends SliceLike, TContext>({\n\t\t\tslice,\n\t }: SliceComponentProps<TSlice, TContext>): JSX.Element | null => {\n\t\t\tconst type = \"slice_type\" in slice ? slice.slice_type : slice.type;\n\n\t\t\tReact.useEffect(() => {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[SliceZone] Could not find a component for Slice type \"${type}\"`,\n\t\t\t\t\tslice,\n\t\t\t\t);\n\t\t\t}, [slice, type]);\n\n\t\t\treturn (\n\t\t\t\t<section data-slice-zone-todo-component=\"\" data-slice-type={type}>\n\t\t\t\t\tCould not find a component for Slice type “{type}\n\t\t\t\t\t”\n\t\t\t\t</section>\n\t\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\tTContext = unknown,\n> = (args: SliceZoneResolverArgs<TSlice>) =>\n\t| SliceComponentType<\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\tany,\n\t\t\tTContext\n\t >\n\t| undefined\n\t| 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, SliceComponentType<any, TContext>>;\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, TContext>;\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?: SliceComponentType<any, TContext>;\n\n\t/**\n\t * Arbitrary data made available to all Slice components.\n\t */\n\tcontext?: TContext;\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 = <TContext,>({\n\tslices = [],\n\tcomponents = {},\n\tresolver,\n\tdefaultComponent = TODOSliceComponent,\n\tcontext = {} as TContext,\n}: SliceZoneProps<TContext>): JSX.Element => {\n\tconst renderedSlices = React.useMemo(() => {\n\t\treturn slices.map((slice, index) => {\n\t\t\tconst type = \"slice_type\" in slice ? slice.slice_type : slice.type;\n\n\t\t\tlet Comp =\n\t\t\t\tcomponents[type as keyof typeof components] || defaultComponent;\n\n\t\t\t// TODO: Remove `resolver` in v3 in favor of `components`.\n\t\t\tif (resolver) {\n\t\t\t\tconst resolvedComp = resolver({\n\t\t\t\t\tslice,\n\t\t\t\t\tsliceName: pascalCase(type),\n\t\t\t\t\ti: index,\n\t\t\t\t});\n\n\t\t\t\tif (resolvedComp) {\n\t\t\t\t\tComp = resolvedComp as typeof Comp;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst key =\n\t\t\t\t\"id\" in slice && slice.id\n\t\t\t\t\t? slice.id\n\t\t\t\t\t: `${index}-${JSON.stringify(slice)}`;\n\n\t\t\treturn (\n\t\t\t\t<Comp\n\t\t\t\t\tkey={key}\n\t\t\t\t\tslice={slice}\n\t\t\t\t\tindex={index}\n\t\t\t\t\tslices={slices}\n\t\t\t\t\tcontext={context}\n\t\t\t\t/>\n\t\t\t);\n\t\t});\n\t}, [components, context, defaultComponent, slices, resolver]);\n\n\treturn <>{renderedSlices}</>;\n};\n"],"names":[],"mappings":";;;;AA2JO,MAAM,qBAAqB,iBAC/B,MAAM,OACN,CAAqC,EACrC,YACgE;AAChE,QAAM,OAAO,gBAAgB,QAAQ,MAAM,aAAa,MAAM;AAE9D,QAAM,UAAU,MAAK;AACZ,YAAA,KACP,0DAA0D,SAC1D,KAAK;AAAA,EAAA,GAEJ,CAAC,OAAO,IAAI,CAAC;AAEhB,SACE,qBAAA,WAAA,EAAQ,kCAA+B,IAAG,mBAAiB,MAC3D,UAAA;AAAA,IAAA;AAAA,IAAkD;AAAA,IAClD;AAAA,EACD,EAAA,CAAA;AAED;AA6GI,MAAM,YAAY,CAAY,EACpC,SAAS,CAAA,GACT,aAAa,CAAA,GACb,UACA,mBAAmB,oBACnB,UAAU,SACiC;AACrC,QAAA,iBAAiB,MAAM,QAAQ,MAAK;AACzC,WAAO,OAAO,IAAI,CAAC,OAAO,UAAS;AAClC,YAAM,OAAO,gBAAgB,QAAQ,MAAM,aAAa,MAAM;AAE1D,UAAA,OACH,WAAW,SAAoC;AAGhD,UAAI,UAAU;AACb,cAAM,eAAe,SAAS;AAAA,UAC7B;AAAA,UACA,WAAW,WAAW,IAAI;AAAA,UAC1B,GAAG;AAAA,QAAA,CACH;AAED,YAAI,cAAc;AACV,iBAAA;AAAA,QACP;AAAA,MACD;AAEK,YAAA,MACL,QAAQ,SAAS,MAAM,KACpB,MAAM,KACN,GAAG,SAAS,KAAK,UAAU,KAAK;AAEpC,iCACE,MAEA,EAAA,OACA,OACA,QACA,WAJK,GAIY;AAAA,IAAA,CAGnB;AAAA,EAAA,GACC,CAAC,YAAY,SAAS,kBAAkB,QAAQ,QAAQ,CAAC;AAE5D,yCAAU,UAAe,eAAA,CAAA;AAC1B;"}
|
|
1
|
+
{"version":3,"file":"SliceZone.js","sources":["../../src/SliceZone.tsx"],"sourcesContent":["import * as React from \"react\";\nimport * as prismic from \"@prismicio/client\";\n\nimport { __PRODUCTION__ } from \"./lib/__PRODUCTION__\";\n\n/**\n * The minimum required properties to represent a Prismic Slice from the Prismic\n * Rest API V2 for the `<SliceZone>` component.\n *\n * If using Prismic's Rest API V2, use the `Slice` export from\n * `@prismicio/types` for a full interface.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\nexport type SliceLikeRestV2<SliceType extends string = string> = {\n\tslice_type: prismic.Slice<SliceType>[\"slice_type\"];\n\tid?: string;\n};\n\n/**\n * The minimum required properties to represent a Prismic Slice from the Prismic\n * GraphQL API for the `<SliceZone>` component.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\nexport type SliceLikeGraphQL<SliceType extends string = string> = {\n\ttype: prismic.Slice<SliceType>[\"slice_type\"];\n};\n\n/**\n * The minimum required properties to represent a Prismic Slice for the\n * `<SliceZone>` component.\n *\n * If using Prismic's Rest API V2, use the `Slice` export from\n * `@prismicio/types` for a full interface.\n *\n * @typeParam SliceType - Type name of the Slice.\n */\nexport type SliceLike<SliceType extends string = string> =\n\t| SliceLikeRestV2<SliceType>\n\t| SliceLikeGraphQL<SliceType>;\n\n/**\n * A looser version of the `SliceZone` type from `@prismicio/types` using\n * `SliceLike`.\n *\n * If using Prismic's Rest API V2, use the `SliceZone` export from\n * `@prismicio/types` 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 = any,\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<SliceLike>;\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 * 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 = __PRODUCTION__\n\t? () => null\n\t: <TSlice extends SliceLike, TContext>({\n\t\t\tslice,\n\t }: SliceComponentProps<TSlice, TContext>): JSX.Element | null => {\n\t\t\tconst type = \"slice_type\" in slice ? slice.slice_type : slice.type;\n\n\t\t\tconsole.warn(\n\t\t\t\t`[SliceZone] Could not find a component for Slice type \"${type}\"`,\n\t\t\t);\n\n\t\t\treturn (\n\t\t\t\t<section data-slice-zone-todo-component=\"\" data-slice-type={type}>\n\t\t\t\t\tCould not find a component for Slice type “{type}\n\t\t\t\t\t”\n\t\t\t\t</section>\n\t\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/**\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, SliceComponentType<any, TContext>>;\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?: SliceComponentType<any, TContext>;\n\n\t/**\n\t * Arbitrary data made available to all Slice components.\n\t */\n\tcontext?: TContext;\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 = <TContext,>({\n\tslices = [],\n\tcomponents = {},\n\tdefaultComponent = TODOSliceComponent,\n\tcontext = {} as TContext,\n}: SliceZoneProps<TContext>): JSX.Element => {\n\tconst renderedSlices = React.useMemo(() => {\n\t\treturn slices.map((slice, index) => {\n\t\t\tconst type = \"slice_type\" in slice ? slice.slice_type : slice.type;\n\n\t\t\tconst Comp =\n\t\t\t\tcomponents[type as keyof typeof components] || defaultComponent;\n\n\t\t\tconst key =\n\t\t\t\t\"id\" in slice && slice.id\n\t\t\t\t\t? slice.id\n\t\t\t\t\t: `${index}-${JSON.stringify(slice)}`;\n\n\t\t\treturn (\n\t\t\t\t<Comp\n\t\t\t\t\tkey={key}\n\t\t\t\t\tslice={slice}\n\t\t\t\t\tindex={index}\n\t\t\t\t\tslices={slices}\n\t\t\t\t\tcontext={context}\n\t\t\t\t/>\n\t\t\t);\n\t\t});\n\t}, [components, context, defaultComponent, slices]);\n\n\treturn <>{renderedSlices}</>;\n};\n"],"names":[],"mappings":";;;AAgHO,MAAM,qBAAqB,iBAC/B,MAAM,OACN,CAAqC,EACrC,YACgE;AAChE,QAAM,OAAO,gBAAgB,QAAQ,MAAM,aAAa,MAAM;AAEtD,UAAA,KACP,0DAA0D,OAAO;AAGlE,SACE,qBAAA,WAAA,EAAQ,kCAA+B,IAAG,mBAAiB,MAC3D,UAAA;AAAA,IAAA;AAAA,IAAkD;AAAA,IAClD;AAAA,EACD,EAAA,CAAA;AAED;AAgDI,MAAM,YAAY,CAAY,EACpC,SAAS,CAAA,GACT,aAAa,IACb,mBAAmB,oBACnB,UAAU,CAAA,QACiC;AACrC,QAAA,iBAAiB,MAAM,QAAQ,MAAK;AACzC,WAAO,OAAO,IAAI,CAAC,OAAO,UAAS;AAClC,YAAM,OAAO,gBAAgB,QAAQ,MAAM,aAAa,MAAM;AAExD,YAAA,OACL,WAAW,IAA+B,KAAK;AAE1C,YAAA,MACL,QAAQ,SAAS,MAAM,KACpB,MAAM,KACN,GAAG,SAAS,KAAK,UAAU,KAAK;AAEpC,iCACE,MAEA,EAAA,OACA,OACA,QACA,WAJK,GAIY;AAAA,IAAA,CAGnB;AAAA,KACC,CAAC,YAAY,SAAS,kBAAkB,MAAM,CAAC;AAElD,yCAAU,UAAe,eAAA,CAAA;AAC1B;"}
|
package/dist/index.cjs
CHANGED
|
@@ -12,7 +12,6 @@ const SliceZone = require("./SliceZone.cjs");
|
|
|
12
12
|
const PrismicToolbar = require("./PrismicToolbar.cjs");
|
|
13
13
|
const usePrismicPreviewResolver = require("./usePrismicPreviewResolver.cjs");
|
|
14
14
|
const clientHooks = require("./clientHooks.cjs");
|
|
15
|
-
const Elements = prismicR.Element;
|
|
16
15
|
exports.PrismicProvider = PrismicProvider.PrismicProvider;
|
|
17
16
|
exports.usePrismicContext = usePrismicContext.usePrismicContext;
|
|
18
17
|
exports.usePrismicClient = usePrismicClient.usePrismicClient;
|
|
@@ -46,5 +45,4 @@ exports.usePrismicDocumentsByTag = clientHooks.usePrismicDocumentsByTag;
|
|
|
46
45
|
exports.usePrismicDocumentsByType = clientHooks.usePrismicDocumentsByType;
|
|
47
46
|
exports.usePrismicDocumentsByUIDs = clientHooks.usePrismicDocumentsByUIDs;
|
|
48
47
|
exports.useSinglePrismicDocument = clientHooks.useSinglePrismicDocument;
|
|
49
|
-
exports.Elements = Elements;
|
|
50
48
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,36 +8,11 @@ export { PrismicText } from "./PrismicText";
|
|
|
8
8
|
export type { PrismicTextProps } from "./PrismicText";
|
|
9
9
|
export { PrismicRichText } from "./PrismicRichText";
|
|
10
10
|
export type { PrismicRichTextProps } from "./PrismicRichText";
|
|
11
|
-
|
|
12
|
-
export { Element };
|
|
13
|
-
/**
|
|
14
|
-
* @deprecated Renamed to `Element` (without an "s").
|
|
15
|
-
*/
|
|
16
|
-
export declare const Elements: {
|
|
17
|
-
readonly heading1: "heading1";
|
|
18
|
-
readonly heading2: "heading2";
|
|
19
|
-
readonly heading3: "heading3";
|
|
20
|
-
readonly heading4: "heading4";
|
|
21
|
-
readonly heading5: "heading5";
|
|
22
|
-
readonly heading6: "heading6";
|
|
23
|
-
readonly paragraph: "paragraph";
|
|
24
|
-
readonly preformatted: "preformatted";
|
|
25
|
-
readonly strong: "strong";
|
|
26
|
-
readonly em: "em";
|
|
27
|
-
readonly listItem: "list-item";
|
|
28
|
-
readonly oListItem: "o-list-item";
|
|
29
|
-
readonly list: "group-list-item";
|
|
30
|
-
readonly oList: "group-o-list-item";
|
|
31
|
-
readonly image: "image";
|
|
32
|
-
readonly embed: "embed";
|
|
33
|
-
readonly hyperlink: "hyperlink";
|
|
34
|
-
readonly label: "label";
|
|
35
|
-
readonly span: "span";
|
|
36
|
-
};
|
|
11
|
+
export { Element } from "@prismicio/richtext";
|
|
37
12
|
export { PrismicImage } from "./PrismicImage";
|
|
38
13
|
export type { PrismicImageProps } from "./PrismicImage";
|
|
39
14
|
export { SliceZone, TODOSliceComponent } from "./SliceZone";
|
|
40
|
-
export type { SliceComponentProps, SliceComponentType, SliceLikeRestV2, SliceLikeGraphQL, SliceLike,
|
|
15
|
+
export type { SliceComponentProps, SliceComponentType, SliceLikeRestV2, SliceLikeGraphQL, SliceLike, SliceZoneLike, SliceZoneProps, } from "./SliceZone";
|
|
41
16
|
export { PrismicToolbar } from "./PrismicToolbar";
|
|
42
17
|
export type { PrismicToolbarProps } from "./PrismicToolbar";
|
|
43
18
|
export { usePrismicPreviewResolver } from "./usePrismicPreviewResolver";
|
package/dist/index.js
CHANGED
|
@@ -5,16 +5,13 @@ import { PrismicLink } from "./PrismicLink.js";
|
|
|
5
5
|
import { PrismicText } from "./PrismicText.js";
|
|
6
6
|
import { PrismicRichText } from "./PrismicRichText.js";
|
|
7
7
|
import { Element } from "@prismicio/richtext";
|
|
8
|
-
import { Element as Element2 } from "@prismicio/richtext";
|
|
9
8
|
import { PrismicImage } from "./PrismicImage.js";
|
|
10
9
|
import { SliceZone, TODOSliceComponent } from "./SliceZone.js";
|
|
11
10
|
import { PrismicToolbar } from "./PrismicToolbar.js";
|
|
12
11
|
import { usePrismicPreviewResolver } from "./usePrismicPreviewResolver.js";
|
|
13
12
|
import { useAllPrismicDocumentsByEveryTag, useAllPrismicDocumentsByIDs, useAllPrismicDocumentsBySomeTags, useAllPrismicDocumentsByTag, useAllPrismicDocumentsByType, useAllPrismicDocumentsByUIDs, useAllPrismicDocumentsDangerously, useFirstPrismicDocument, usePrismicDocumentByID, usePrismicDocumentByUID, usePrismicDocuments, usePrismicDocumentsByEveryTag, usePrismicDocumentsByIDs, usePrismicDocumentsBySomeTags, usePrismicDocumentsByTag, usePrismicDocumentsByType, usePrismicDocumentsByUIDs, useSinglePrismicDocument } from "./clientHooks.js";
|
|
14
|
-
const Elements = Element;
|
|
15
13
|
export {
|
|
16
|
-
|
|
17
|
-
Elements,
|
|
14
|
+
Element,
|
|
18
15
|
PrismicImage,
|
|
19
16
|
PrismicLink,
|
|
20
17
|
PrismicProvider,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
|
package/dist/package.json.cjs
CHANGED
package/dist/package.json.js
CHANGED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
+
const React = require("react");
|
|
5
|
+
const prismic = require("@prismicio/client");
|
|
6
|
+
const __PRODUCTION__ = require("../lib/__PRODUCTION__.cjs");
|
|
7
|
+
const devMsg = require("../lib/devMsg.cjs");
|
|
8
|
+
const isInternalURL = require("../lib/isInternalURL.cjs");
|
|
9
|
+
function _interopNamespaceDefault(e) {
|
|
10
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
11
|
+
if (e) {
|
|
12
|
+
for (const k in e) {
|
|
13
|
+
if (k !== "default") {
|
|
14
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: () => e[k]
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
n.default = e;
|
|
23
|
+
return Object.freeze(n);
|
|
24
|
+
}
|
|
25
|
+
const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
|
|
26
|
+
const defaultComponent = "a";
|
|
27
|
+
const PrismicLink = React__namespace.forwardRef(function PrismicLink2({ field, document: doc, linkResolver, internalComponent, externalComponent, ...restProps }, ref) {
|
|
28
|
+
if (!__PRODUCTION__.__PRODUCTION__) {
|
|
29
|
+
if (field) {
|
|
30
|
+
if (!field.link_type) {
|
|
31
|
+
console.error(`[PrismicLink] This "field" prop value caused an error to be thrown.
|
|
32
|
+
`, field);
|
|
33
|
+
throw new Error(`[PrismicLink] The provided field is missing required properties to properly render a link. The link will not render. For more details, see ${devMsg.devMsg("missing-link-properties")}`);
|
|
34
|
+
} else if (Object.keys(field).length > 1 && !("url" in field || "uid" in field || "id" in field)) {
|
|
35
|
+
console.warn(`[PrismicLink] The provided field is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg.devMsg("missing-link-properties")}`, field);
|
|
36
|
+
}
|
|
37
|
+
} else if (doc) {
|
|
38
|
+
if (!("url" in doc || "id" in doc)) {
|
|
39
|
+
console.warn(`[PrismicLink] The provided document is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg.devMsg("missing-link-properties")}`, doc);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const { href: computedHref, rel: computedRel, ...attrs } = prismic.asLinkAttrs(field ?? doc, {
|
|
44
|
+
linkResolver,
|
|
45
|
+
rel: typeof restProps.rel === "function" ? restProps.rel : void 0
|
|
46
|
+
});
|
|
47
|
+
let rel = computedRel;
|
|
48
|
+
if ("rel" in restProps && typeof restProps.rel !== "function") {
|
|
49
|
+
rel = restProps.rel;
|
|
50
|
+
}
|
|
51
|
+
const href = ("href" in restProps ? restProps.href : computedHref) || "";
|
|
52
|
+
const InternalComponent = internalComponent || defaultComponent;
|
|
53
|
+
const ExternalComponent = externalComponent || defaultComponent;
|
|
54
|
+
const Component = href && isInternalURL.isInternalURL(href) ? InternalComponent : ExternalComponent;
|
|
55
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Component, { ref, ...attrs, ...restProps, href, rel });
|
|
56
|
+
});
|
|
57
|
+
exports.PrismicLink = PrismicLink;
|
|
58
|
+
exports.defaultComponent = defaultComponent;
|
|
59
|
+
//# sourceMappingURL=PrismicLink.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrismicLink.cjs","sources":["../../../src/react-server/PrismicLink.tsx"],"sourcesContent":["import * as React from \"react\";\nimport {\n\tLinkField,\n\tLinkResolverFunction,\n\tPrismicDocument,\n\tasLinkAttrs,\n\tAsLinkAttrsConfig,\n} from \"@prismicio/client\";\n\nimport { __PRODUCTION__ } from \"../lib/__PRODUCTION__\";\nimport { devMsg } from \"../lib/devMsg\";\nimport { isInternalURL } from \"../lib/isInternalURL\";\n\n/**\n * The default component rendered for internal and external links.\n */\nexport const defaultComponent = \"a\";\n\n/**\n * Props provided to a component when rendered with `<PrismicLink>`.\n */\nexport interface LinkProps {\n\t/**\n\t * The URL to link.\n\t */\n\thref: string;\n\n\t/**\n\t * The `target` attribute for anchor elements. If the Prismic field is\n\t * configured to open in a new window, this prop defaults to `_blank`.\n\t */\n\ttarget?: React.HTMLAttributeAnchorTarget;\n\n\t/**\n\t * The `rel` attribute for anchor elements. If the `target` prop is set to\n\t * `\"_blank\"`, this prop defaults to `\"noopener noreferrer\"`.\n\t */\n\trel?: string;\n\n\t/**\n\t * Children for the component. *\n\t */\n\tchildren?: React.ReactNode;\n}\n\nexport type PrismicLinkProps<\n\tInternalComponentProps = React.ComponentProps<typeof defaultComponent>,\n\tExternalComponentProps = React.ComponentProps<typeof defaultComponent>,\n> = Omit<InternalComponentProps & ExternalComponentProps, \"rel\" | \"href\"> & {\n\t/**\n\t * The `rel` attribute for the link. By default, `\"noreferrer\"` is provided if\n\t * the link's URL is external. This prop can be provided a function to use the\n\t * link's metadata to determine the `rel` value.\n\t */\n\trel?: string | AsLinkAttrsConfig[\"rel\"];\n\n\t/**\n\t * The Link Resolver used to resolve links.\n\t *\n\t * @remarks\n\t * If your app uses Route Resolvers when querying for your Prismic\n\t * repository's content, a Link Resolver does not need to be provided.\n\t * @see Learn about Link Resolvers and Route Resolvers {@link https://prismic.io/docs/core-concepts/link-resolver-route-resolver}\n\t */\n\tlinkResolver?: LinkResolverFunction;\n\n\t/**\n\t * The component rendered for internal URLs. Defaults to `<a>`.\n\t *\n\t * If your app uses a client-side router that requires a special Link\n\t * component, provide the Link component to this prop.\n\t */\n\tinternalComponent?: React.ElementType<InternalComponentProps>;\n\n\t/**\n\t * The component rendered for external URLs. Defaults to `<a>`.\n\t */\n\texternalComponent?: React.ComponentType<ExternalComponentProps>;\n} & (\n\t\t| {\n\t\t\t\tdocument: PrismicDocument | null | undefined;\n\t\t\t\thref?: never;\n\t\t\t\tfield?: never;\n\t\t }\n\t\t| {\n\t\t\t\tfield: LinkField | null | undefined;\n\t\t\t\thref?: never;\n\t\t\t\tdocument?: never;\n\t\t }\n\t\t| {\n\t\t\t\thref: LinkProps[\"href\"];\n\t\t\t\tfield?: LinkField | null | undefined;\n\t\t\t\tdocument?: never;\n\t\t }\n\t);\n\nexport const PrismicLink = React.forwardRef(function PrismicLink<\n\tInternalComponentProps = React.ComponentProps<typeof defaultComponent>,\n\tExternalComponentProps = React.ComponentProps<typeof defaultComponent>,\n>(\n\t{\n\t\tfield,\n\t\tdocument: doc,\n\t\tlinkResolver,\n\t\tinternalComponent,\n\t\texternalComponent,\n\t\t...restProps\n\t}: PrismicLinkProps<InternalComponentProps, ExternalComponentProps>,\n\tref: React.ForwardedRef<Element>,\n): JSX.Element {\n\tif (!__PRODUCTION__) {\n\t\tif (field) {\n\t\t\tif (!field.link_type) {\n\t\t\t\tconsole.error(\n\t\t\t\t\t`[PrismicLink] This \"field\" prop value caused an error to be thrown.\\n`,\n\t\t\t\t\tfield,\n\t\t\t\t);\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`[PrismicLink] The provided field is missing required properties to properly render a link. The link will not render. For more details, see ${devMsg(\n\t\t\t\t\t\t\"missing-link-properties\",\n\t\t\t\t\t)}`,\n\t\t\t\t);\n\t\t\t} else if (\n\t\t\t\tObject.keys(field).length > 1 &&\n\t\t\t\t!(\"url\" in field || \"uid\" in field || \"id\" in field)\n\t\t\t) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[PrismicLink] The provided field is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg(\n\t\t\t\t\t\t\"missing-link-properties\",\n\t\t\t\t\t)}`,\n\t\t\t\t\tfield,\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (doc) {\n\t\t\tif (!(\"url\" in doc || \"id\" in doc)) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`[PrismicLink] The provided document is missing required properties to properly render a link. The link may not render correctly. For more details, see ${devMsg(\n\t\t\t\t\t\t\"missing-link-properties\",\n\t\t\t\t\t)}`,\n\t\t\t\t\tdoc,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst {\n\t\thref: computedHref,\n\t\trel: computedRel,\n\t\t...attrs\n\t} = asLinkAttrs(field ?? doc, {\n\t\tlinkResolver,\n\t\trel: typeof restProps.rel === \"function\" ? restProps.rel : undefined,\n\t});\n\n\tlet rel: string | undefined = computedRel;\n\tif (\"rel\" in restProps && typeof restProps.rel !== \"function\") {\n\t\trel = restProps.rel;\n\t}\n\n\tconst href = (\"href\" in restProps ? restProps.href : computedHref) || \"\";\n\n\tconst InternalComponent = (internalComponent ||\n\t\tdefaultComponent) as React.ComponentType<LinkProps>;\n\tconst ExternalComponent = (externalComponent ||\n\t\tdefaultComponent) as React.ComponentType<LinkProps>;\n\tconst Component =\n\t\thref && isInternalURL(href) ? InternalComponent : ExternalComponent;\n\n\treturn (\n\t\t<Component ref={ref} {...attrs} {...restProps} href={href} rel={rel} />\n\t);\n}) as <\n\tInternalComponentProps = React.ComponentProps<typeof defaultComponent>,\n\tExternalComponentProps = React.ComponentProps<typeof defaultComponent>,\n>(\n\tprops: PrismicLinkProps<InternalComponentProps, ExternalComponentProps> & {\n\t\tref?: React.ForwardedRef<Element>;\n\t},\n) => JSX.Element;\n"],"names":["React","PrismicLink","__PRODUCTION__","devMsg","asLinkAttrs","isInternalURL","jsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAgBO,MAAM,mBAAmB;AAgFzB,MAAM,cAAcA,iBAAM,WAAW,SAASC,aAIpD,EACC,OACA,UAAU,KACV,cACA,mBACA,mBACA,GAAG,UAAA,GAEJ,KAAgC;AAEhC,MAAI,CAACC,eAAAA,gBAAgB;AACpB,QAAI,OAAO;AACN,UAAA,CAAC,MAAM,WAAW;AACrB,gBAAQ,MACP;AAAA,GACA,KAAK;AAEN,cAAM,IAAI,MACT,8IAA8IC,OAAA,OAC7I,yBAAyB,GACvB;AAAA,MAGJ,WAAA,OAAO,KAAK,KAAK,EAAE,SAAS,KAC5B,EAAE,SAAS,SAAS,SAAS,SAAS,QAAQ,QAC7C;AACD,gBAAQ,KACP,uJAAuJA,OAAAA,OACtJ,yBAAyB,KAE1B,KAAK;AAAA,MAEN;AAAA,eACS,KAAK;AACf,UAAI,EAAE,SAAS,OAAO,QAAQ,MAAM;AACnC,gBAAQ,KACP,0JAA0JA,OAAAA,OACzJ,yBAAyB,KAE1B,GAAG;AAAA,MAEJ;AAAA,IACD;AAAA,EACD;AAEK,QAAA,EACL,MAAM,cACN,KAAK,aACL,GAAG,UACAC,QAAAA,YAAY,SAAS,KAAK;AAAA,IAC7B;AAAA,IACA,KAAK,OAAO,UAAU,QAAQ,aAAa,UAAU,MAAM;AAAA,EAAA,CAC3D;AAED,MAAI,MAA0B;AAC9B,MAAI,SAAS,aAAa,OAAO,UAAU,QAAQ,YAAY;AAC9D,UAAM,UAAU;AAAA,EAChB;AAED,QAAM,QAAQ,UAAU,YAAY,UAAU,OAAO,iBAAiB;AAEtE,QAAM,oBAAqB,qBAC1B;AACD,QAAM,oBAAqB,qBAC1B;AACD,QAAM,YACL,QAAQC,cAAAA,cAAc,IAAI,IAAI,oBAAoB;AAGlD,SAAAC,2BAAA,IAAC,aAAU,KAAc,GAAA,OAAO,GAAI,WAAW,MAAY,IAAS,CAAA;AAEtE,CAAC;;;"}
|