@prismicio/react 3.4.1 → 3.4.2-canary.c2e05c8
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 +6 -0
- package/dist/PrismicImage.d.ts +10 -9
- package/dist/PrismicImage.d.ts.map +1 -1
- package/dist/PrismicImage.js +3 -3
- package/dist/PrismicImage.js.map +1 -1
- package/dist/PrismicLink.d.ts +6 -7
- package/dist/PrismicLink.d.ts.map +1 -1
- package/dist/PrismicLink.js +4 -3
- package/dist/PrismicLink.js.map +1 -1
- package/dist/PrismicRichText.d.ts +8 -9
- package/dist/PrismicRichText.d.ts.map +1 -1
- package/dist/PrismicRichText.js +1 -1
- package/dist/PrismicRichText.js.map +1 -1
- package/dist/PrismicTable.d.ts +5 -6
- package/dist/PrismicTable.d.ts.map +1 -1
- package/dist/PrismicTable.js +1 -1
- package/dist/PrismicTable.js.map +1 -1
- package/dist/PrismicText.d.ts +7 -7
- package/dist/PrismicText.d.ts.map +1 -1
- package/dist/PrismicText.js +1 -1
- package/dist/PrismicText.js.map +1 -1
- package/dist/PrismicToolbar.d.ts +3 -5
- package/dist/PrismicToolbar.d.ts.map +1 -1
- package/dist/PrismicToolbar.js +5 -3
- package/dist/PrismicToolbar.js.map +1 -1
- package/dist/SliceZone.d.ts +25 -21
- package/dist/SliceZone.d.ts.map +1 -1
- package/dist/SliceZone.js +4 -3
- package/dist/SliceZone.js.map +1 -1
- package/dist/lib/devMsg.js +1 -1
- package/dist/lib/devMsg.js.map +1 -1
- package/dist/package.js +1 -1
- package/package.json +17 -16
- package/src/PrismicImage.tsx +34 -34
- package/src/PrismicLink.tsx +43 -43
- package/src/PrismicRichText.tsx +43 -43
- package/src/PrismicTable.tsx +29 -29
- package/src/PrismicText.tsx +16 -16
- package/src/PrismicToolbar.tsx +32 -30
- package/src/SliceZone.tsx +41 -41
- package/src/index.ts +15 -15
- package/src/lib/devMsg.ts +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicToolbar.js","names":[],"sources":["../src/PrismicToolbar.tsx"],"sourcesContent":["\"use client\"
|
|
1
|
+
{"version":3,"file":"PrismicToolbar.js","names":[],"sources":["../src/PrismicToolbar.tsx"],"sourcesContent":["\"use client\"\n\nimport { getToolbarSrc } from \"@prismicio/client\"\nimport { type FC, useEffect, useRef } from \"react\"\n\n/** Props for `<PrismicToolbar>`. */\nexport type PrismicToolbarProps = {\n\t/**\n\t * The name of the Prismic repository. For example, `\"my-repo\"` if the repository URL is\n\t * `my-repo.prismic.io`.\n\t */\n\trepositoryName: string\n\n\t/**\n\t * Called when the Prismic toolbar triggers a preview update. This happens when the previewed\n\t * content changes.\n\t *\n\t * The new ref can be read from `event.detail.ref`.\n\t *\n\t * The default page reload behavior can be cancelled with `event.preventDefault()`.\n\t */\n\tonPreviewUpdate?: (event: CustomEvent<{ ref: string }>) => void\n\n\t/**\n\t * Called when the Prismic toolbar triggers a preview end. This happens when a preview session is\n\t * closed.\n\t *\n\t * The default page reload behavior can be cancelled with `event.preventDefault()`.\n\t */\n\tonPreviewEnd?: (event: CustomEvent<null>) => void\n}\n\n/**\n * Renders the Prismic Toolbar script to support draft previews.\n *\n * @example\n * \t;```tsx\n * \t<PrismicToolbar repositoryName=\"my-repo\" />;\n * \t```\n *\n * @see Learn how to set up preview functionality and the toolbar's role in preview sessions: {@link https://prismic.io/docs/previews}\n */\nexport const PrismicToolbar: FC<PrismicToolbarProps> = (props) => {\n\tconst { repositoryName, onPreviewUpdate, onPreviewEnd } = props\n\n\tconst src = getToolbarSrc(repositoryName)\n\n\tconst onPreviewUpdateRef = useRef(onPreviewUpdate)\n\tconst onPreviewEndRef = useRef(onPreviewEnd)\n\n\tuseEffect(() => {\n\t\tonPreviewUpdateRef.current = onPreviewUpdate\n\t\tonPreviewEndRef.current = onPreviewEnd\n\t})\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\tuseEffect(() => {\n\t\tconst controller = new AbortController()\n\n\t\twindow.addEventListener(\n\t\t\t\"prismicPreviewUpdate\",\n\t\t\t(event) => onPreviewUpdateRef.current?.(event as CustomEvent<{ ref: string }>),\n\t\t\t{ signal: controller.signal },\n\t\t)\n\n\t\twindow.addEventListener(\n\t\t\t\"prismicPreviewEnd\",\n\t\t\t(event) => onPreviewEndRef.current?.(event as CustomEvent<null>),\n\t\t\t{ signal: controller.signal },\n\t\t)\n\n\t\treturn () => controller.abort()\n\t}, [])\n\n\treturn null\n}\n"],"mappings":";;;;;;;;;;;;;;AA0CA,MAAa,kBAA2C,UAAU;CACjE,MAAM,EAAE,gBAAgB,iBAAiB,iBAAiB;CAE1D,MAAM,MAAM,cAAc,cAAc;CAExC,MAAM,qBAAqB,OAAO,eAAe;CACjD,MAAM,kBAAkB,OAAO,YAAY;CAE3C,gBAAgB;EACf,mBAAmB,UAAU;EAC7B,gBAAgB,UAAU;CAC3B,CAAC;CAED,gBAAgB;EAGf,IAAI,CAFmB,SAAS,cAAc,eAAe,IAAI,GAE/C,GAAG;GACpB,MAAM,SAAS,SAAS,cAAc,QAAQ;GAC9C,OAAO,MAAM;GACb,OAAO,QAAQ;GAGf,OAAO,QAAQ,iBAAiB;GAChC,OAAO,QAAQ,iBAAiB;GAIhC,OAAO,kBAAkB;GAEzB,SAAS,KAAK,YAAY,MAAM;EACjC;CACD,GAAG,CAAC,gBAAgB,GAAG,CAAC;CAExB,gBAAgB;EACf,MAAM,aAAa,IAAI,gBAAgB;EAEvC,OAAO,iBACN,yBACC,UAAU,mBAAmB,UAAU,KAAqC,GAC7E,EAAE,QAAQ,WAAW,OAAO,CAC7B;EAEA,OAAO,iBACN,sBACC,UAAU,gBAAgB,UAAU,KAA0B,GAC/D,EAAE,QAAQ,WAAW,OAAO,CAC7B;EAEA,aAAa,WAAW,MAAM;CAC/B,GAAG,CAAC,CAAC;CAEL,OAAO;AACR"}
|
package/dist/SliceZone.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Slice } from "@prismicio/client";
|
|
2
2
|
import { ComponentType, FC, ReactNode } from "react";
|
|
3
|
-
|
|
4
3
|
//#region src/SliceZone.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* Returns the type of a `SliceLike` type.
|
|
@@ -14,14 +13,14 @@ type ExtractSliceType<TSlice extends SliceLike> = TSlice extends Slice ? TSlice[
|
|
|
14
13
|
*
|
|
15
14
|
* @typeParam SliceType - Type name of the slice.
|
|
16
15
|
*/
|
|
17
|
-
type SliceLikeRestV2<TSliceType extends string = string> = Pick<Slice<TSliceType>, "id" | "slice_type">;
|
|
16
|
+
export type SliceLikeRestV2<TSliceType extends string = string> = Pick<Slice<TSliceType>, "id" | "slice_type">;
|
|
18
17
|
/**
|
|
19
18
|
* The minimum required properties to represent a Prismic slice from the Prismic GraphQL API for the
|
|
20
19
|
* `mapSliceZone()` helper.
|
|
21
20
|
*
|
|
22
21
|
* @typeParam SliceType - Type name of the slice.
|
|
23
22
|
*/
|
|
24
|
-
type SliceLikeGraphQL<TSliceType extends string = string> = {
|
|
23
|
+
export type SliceLikeGraphQL<TSliceType extends string = string> = {
|
|
25
24
|
type: Slice<TSliceType>["slice_type"];
|
|
26
25
|
};
|
|
27
26
|
/**
|
|
@@ -32,7 +31,7 @@ type SliceLikeGraphQL<TSliceType extends string = string> = {
|
|
|
32
31
|
*
|
|
33
32
|
* @typeParam SliceType - Type name of the slice.
|
|
34
33
|
*/
|
|
35
|
-
type SliceLike<TSliceType extends string = string> = (SliceLikeRestV2<TSliceType> | SliceLikeGraphQL<TSliceType>) & {
|
|
34
|
+
export type SliceLike<TSliceType extends string = string> = (SliceLikeRestV2<TSliceType> | SliceLikeGraphQL<TSliceType>) & {
|
|
36
35
|
/**
|
|
37
36
|
* If `true`, this slice has been modified from its original value using a mapper and
|
|
38
37
|
* `@prismicio/client`'s `mapSliceZone()`.
|
|
@@ -49,7 +48,7 @@ type SliceLike<TSliceType extends string = string> = (SliceLikeRestV2<TSliceType
|
|
|
49
48
|
*
|
|
50
49
|
* @typeParam TSlice - The type(s) of a slice in the slice zone.
|
|
51
50
|
*/
|
|
52
|
-
type SliceZoneLike<TSlice extends SliceLike = SliceLike> = readonly TSlice[];
|
|
51
|
+
export type SliceZoneLike<TSlice extends SliceLike = SliceLike> = readonly TSlice[];
|
|
53
52
|
/**
|
|
54
53
|
* React props for a component rendering content from a Prismic slice using the `<SliceZone>`
|
|
55
54
|
* component.
|
|
@@ -58,10 +57,14 @@ type SliceZoneLike<TSlice extends SliceLike = SliceLike> = readonly TSlice[];
|
|
|
58
57
|
* @typeParam TContext - Arbitrary data passed to `<SliceZone>` and made available to all slice
|
|
59
58
|
* components.
|
|
60
59
|
*/
|
|
61
|
-
type SliceComponentProps<TSlice extends SliceLike = SliceLike, TContext = unknown> = {
|
|
62
|
-
/** Slice data for this component. */
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
export type SliceComponentProps<TSlice extends SliceLike = SliceLike, TContext = unknown> = {
|
|
61
|
+
/** Slice data for this component. */
|
|
62
|
+
slice: TSlice;
|
|
63
|
+
/** The index of the slice in the slice zone. */
|
|
64
|
+
index: number;
|
|
65
|
+
/** All slices from the slice zone to which the slice belongs. */
|
|
66
|
+
slices: SliceZoneLike<TSlice extends SliceLikeGraphQL ? SliceLikeGraphQL : SliceLikeRestV2>;
|
|
67
|
+
/** Arbitrary data passed to `<SliceZone>` and made available to all slice components. */
|
|
65
68
|
context: TContext;
|
|
66
69
|
};
|
|
67
70
|
/**
|
|
@@ -70,7 +73,7 @@ type SliceComponentProps<TSlice extends SliceLike = SliceLike, TContext = unknow
|
|
|
70
73
|
* @typeParam TSlice - The type(s) of a slice in the slice zone.
|
|
71
74
|
* @typeParam TContext - Arbitrary data made available to all slice components.
|
|
72
75
|
*/
|
|
73
|
-
type SliceComponentType<TSlice extends SliceLike = any, TContext = unknown> = ComponentType<SliceComponentProps<TSlice, TContext>>;
|
|
76
|
+
export type SliceComponentType<TSlice extends SliceLike = any, TContext = unknown> = ComponentType<SliceComponentProps<TSlice, TContext>>;
|
|
74
77
|
/**
|
|
75
78
|
* A record of slice types mapped to a React component. The component will be rendered for each
|
|
76
79
|
* instance of its slice.
|
|
@@ -80,17 +83,21 @@ type SliceComponentType<TSlice extends SliceLike = any, TContext = unknown> = Co
|
|
|
80
83
|
* @typeParam TSlice - The type(s) of a slice in the slice zone.
|
|
81
84
|
* @typeParam TContext - Arbitrary data made available to all slice components.
|
|
82
85
|
*/
|
|
83
|
-
type SliceZoneComponents<TSlice extends SliceLike = SliceLike, TContext = unknown> = { [SliceType in ExtractSliceType<TSlice>]: SliceComponentType<Extract<TSlice, SliceLike<SliceType>> extends never ? SliceLike : Extract<TSlice, SliceLike<SliceType>>, TContext
|
|
86
|
+
export type SliceZoneComponents<TSlice extends SliceLike = SliceLike, TContext = unknown> = { [SliceType in ExtractSliceType<TSlice>]: SliceComponentType<Extract<TSlice, SliceLike<SliceType>> extends never ? SliceLike : Extract<TSlice, SliceLike<SliceType>>, TContext>; };
|
|
84
87
|
/**
|
|
85
88
|
* React props for the `<SliceZone>` component.
|
|
86
89
|
*
|
|
87
90
|
* @typeParam TSlice - The type(s) of a slice in the slice zone.
|
|
88
91
|
* @typeParam TContext - Arbitrary data made available to all slice components.
|
|
89
92
|
*/
|
|
90
|
-
type SliceZoneProps<TContext = unknown> = {
|
|
91
|
-
/** List of slice data from the slice zone. */
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
export type SliceZoneProps<TContext = unknown> = {
|
|
94
|
+
/** List of slice data from the slice zone. */
|
|
95
|
+
slices?: SliceZoneLike;
|
|
96
|
+
/** A record mapping slice types to React components. */
|
|
97
|
+
components?: Record<string, ComponentType<any>>;
|
|
98
|
+
/** The React component rendered if a component mapping from the `components` prop cannot be found. */
|
|
99
|
+
defaultComponent?: ComponentType<SliceComponentProps<any, TContext>>;
|
|
100
|
+
/** Arbitrary data made available to all slice components. */
|
|
94
101
|
context?: TContext;
|
|
95
102
|
};
|
|
96
103
|
/**
|
|
@@ -99,22 +106,19 @@ type SliceZoneProps<TContext = unknown> = {
|
|
|
99
106
|
* This is also the default React component rendered when a component mapping cannot be found in
|
|
100
107
|
* `<SliceZone>`.
|
|
101
108
|
*/
|
|
102
|
-
declare const TODOSliceComponent: <TSlice extends SliceLike>({
|
|
103
|
-
slice
|
|
104
|
-
}: {
|
|
109
|
+
export declare const TODOSliceComponent: <TSlice extends SliceLike>({ slice }: {
|
|
105
110
|
slice: TSlice;
|
|
106
111
|
}) => ReactNode;
|
|
107
112
|
/**
|
|
108
113
|
* Renders slices in a slice zone as React components.
|
|
109
114
|
*
|
|
110
115
|
* @example
|
|
111
|
-
*
|
|
116
|
+
* ;```tsx
|
|
112
117
|
* <SliceZone slices={page.data.slices} components={components} />;
|
|
113
118
|
* ```
|
|
114
119
|
*
|
|
115
120
|
* @see Learn how to create slices, use slice variations, and display slices: {@link https://prismic.io/docs/slices}
|
|
116
121
|
*/
|
|
117
|
-
declare const SliceZone: FC<SliceZoneProps>;
|
|
122
|
+
export declare const SliceZone: FC<SliceZoneProps>;
|
|
118
123
|
//#endregion
|
|
119
|
-
export { SliceComponentProps, SliceComponentType, SliceLike, SliceLikeGraphQL, SliceLikeRestV2, SliceZone, SliceZoneComponents, SliceZoneLike, SliceZoneProps, TODOSliceComponent };
|
|
120
124
|
//# sourceMappingURL=SliceZone.d.ts.map
|
package/dist/SliceZone.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SliceZone.d.ts","names":[],"sources":["../src/SliceZone.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"SliceZone.d.ts","names":[],"sources":["../src/SliceZone.tsx"],"mappings":";;;;;;;;KASK,iBAAiB,eAAe,aAAa,eAAe,QAC9D,uBACA,eAAe,mBACd;;;;;;;YASQ,gBAAgB,sCAAsC,KACjE,MAAM;;;;;;;YAUK,iBAAiB;EAC5B,MAAM,MAAM;;;;;;;;;;YAWD,UAAU,uCACnB,gBAAgB,cAChB,iBAAiB;;;;;;;EAQnB;;;;;;;;;;YAWW,cAAc,eAAe,YAAY,sBAAsB;;;;;;;;;YAU/D,oBAAoB,eAAe,YAAY,WAAW;;EAErE,OAAO;;EAGP;;EAOA,QAAQ,cAAc,eAAe,mBAAmB,mBAAmB;;EAG3E,SAAS;;;;;;;;YASE,mBAEX,eAAe,iBACf,sBACG,cAAc,oBAAoB,QAAQ;;;;;;;;;;YAWlC,oBAAoB,eAAe,YAAY,WAAW,yBAWnE,aAAa,iBAAiB,UAAU,mBACxC,QAAQ,QAAQ,UAAU,4BACvB,YACA,QAAQ,QAAQ,UAAU,aAC7B;;;;;;;YAUS,eAAe;;EAE1B,SAAS;;EAIT,aAAa,eAAe;;EAI5B,mBAAmB,cAAc,yBAAyB;;EAG1D,UAAU;;;;;;;;qBASE,qBAAsB,eAAe,aAAS;EAG1D,OAAO;MACJ;;;;;;;;;;;qBA2BS,WAAW,GAAG"}
|
package/dist/SliceZone.js
CHANGED
|
@@ -25,7 +25,7 @@ const TODOSliceComponent = ({ slice }) => {
|
|
|
25
25
|
* Renders slices in a slice zone as React components.
|
|
26
26
|
*
|
|
27
27
|
* @example
|
|
28
|
-
*
|
|
28
|
+
* ;```tsx
|
|
29
29
|
* <SliceZone slices={page.data.slices} components={components} />;
|
|
30
30
|
* ```
|
|
31
31
|
*
|
|
@@ -33,7 +33,7 @@ const TODOSliceComponent = ({ slice }) => {
|
|
|
33
33
|
*/
|
|
34
34
|
const SliceZone = (props) => {
|
|
35
35
|
const { slices = [], components = {}, defaultComponent, context = {} } = props;
|
|
36
|
-
|
|
36
|
+
const renderedSlices = slices.map((slice, index) => {
|
|
37
37
|
const type = "slice_type" in slice ? slice.slice_type : slice.type;
|
|
38
38
|
const key = "id" in slice && slice.id ? slice.id : `${index}-${JSON.stringify(slice)}`;
|
|
39
39
|
const Comp = components[type] || defaultComponent;
|
|
@@ -48,7 +48,8 @@ const SliceZone = (props) => {
|
|
|
48
48
|
slices,
|
|
49
49
|
context
|
|
50
50
|
}, key);
|
|
51
|
-
})
|
|
51
|
+
});
|
|
52
|
+
return /* @__PURE__ */ jsx(Fragment, { children: renderedSlices });
|
|
52
53
|
};
|
|
53
54
|
//#endregion
|
|
54
55
|
export { SliceZone, TODOSliceComponent };
|
package/dist/SliceZone.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SliceZone.js","names":[],"sources":["../src/SliceZone.tsx"],"sourcesContent":["import type { Slice } from \"@prismicio/client\"
|
|
1
|
+
{"version":3,"file":"SliceZone.js","names":[],"sources":["../src/SliceZone.tsx"],"sourcesContent":["import type { Slice } from \"@prismicio/client\"\nimport { DEV } from \"esm-env\"\nimport type { ComponentType, FC, ReactNode } from \"react\"\n\n/**\n * Returns the type of a `SliceLike` type.\n *\n * @typeParam TSlice - 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 Content API for the\n * `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 GraphQL API for the\n * `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 `mapSliceZone()` helper.\n *\n * If using Prismic's Content API, use the `Slice` export from `@prismicio/client` for a full\n * 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 mapper and\n\t * `@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 `SliceLike`.\n *\n * If using Prismic's Content API, use the `SliceZone` export from `@prismicio/client` for the full\n * type.\n *\n * @typeParam TSlice - The type(s) of a slice in the slice zone.\n */\nexport type SliceZoneLike<TSlice extends SliceLike = SliceLike> = readonly TSlice[]\n\n/**\n * React props for a component rendering content from a Prismic slice using the `<SliceZone>`\n * component.\n *\n * @typeParam TSlice - The slice passed as a prop.\n * @typeParam TContext - Arbitrary data passed to `<SliceZone>` and made available to all slice\n * components.\n */\nexport type SliceComponentProps<TSlice extends SliceLike = SliceLike, TContext = unknown> = {\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<TSlice extends SliceLikeGraphQL ? SliceLikeGraphQL : SliceLikeRestV2>\n\n\t/** Arbitrary data passed to `<SliceZone>` and made available to all slice components. */\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 rendered for each\n * 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<TSlice extends SliceLike = SliceLike, TContext = unknown> =\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/** The React component rendered if a component mapping from the `components` prop cannot be found. */\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 implementation.\n *\n * This is also the default React component rendered when a component mapping cannot be found in\n * `<SliceZone>`.\n */\nexport const TODOSliceComponent = <TSlice extends SliceLike>({\n\tslice,\n}: {\n\tslice: TSlice\n}): ReactNode => {\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(`[SliceZone] Could not find a component for slice type \"${type}\"`, slice)\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 slices in a slice zone as React components.\n *\n * @example\n * \t;```tsx\n * \t<SliceZone slices={page.data.slices} components={components} />;\n * \t```\n *\n * @see Learn how to create slices, use slice variations, and display slices: {@link https://prismic.io/docs/slices}\n */\nexport const SliceZone: FC<SliceZoneProps> = (props) => {\n\tconst { slices = [], components = {}, defaultComponent, context = {} } = 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 = \"id\" in slice && slice.id ? slice.id : `${index}-${JSON.stringify(slice)}`\n\n\t\tconst Comp = components[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 <Comp key={key} slice={slice} index={index} slices={slices} context={context} />\n\t})\n\n\treturn <>{renderedSlices}</>\n}\n"],"mappings":";;;;;;;;;AAiKA,MAAa,sBAAgD,EAC5D,YAGgB;CAChB,IAAI,CAAC,KACJ,OAAO;CAGR,MAAM,OAAO,gBAAgB,QAAQ,MAAM,aAAa,MAAM;CAE9D,QAAQ,KAAK,0DAA0D,KAAK,IAAI,KAAK;CAErF,OACC,qBAAC,WAAD;EAAS,kCAA+B;EAAG,mBAAiB;EAA5D,UAAA;GAAkE;GACf;GAAK;EAE/C;;AAEX;;;;;;;;;;;AAYA,MAAa,aAAiC,UAAU;CACvD,MAAM,EAAE,SAAS,CAAC,GAAG,aAAa,CAAC,GAAG,kBAAkB,UAAU,CAAC,MAAM;CAEzE,MAAM,iBAAiB,OAAO,KAAK,OAAO,UAAU;EACnD,MAAM,OAAO,gBAAgB,QAAQ,MAAM,aAAa,MAAM;EAE9D,MAAM,MAAM,QAAQ,SAAS,MAAM,KAAK,MAAM,KAAK,GAAG,MAAM,GAAG,KAAK,UAAU,KAAK;EAEnF,MAAM,OAAO,WAAW,SAAoC;EAE5D,IAAI,CAAC,MACJ,OAAO,oBAAC,oBAAD,EAAqC,MAAQ,GAApB,GAAoB;EAGrD,IAAI,MAAM,UAAU;GACnB,MAAM,EAAE,UAAU,GAAG,gBAAgB;GAErC,OAAO,oBAAC,MAAD,EAAgB,GAAI,YAAc,GAAvB,GAAuB;EAC1C;EAEA,OAAO,oBAAC,MAAD;GAAuB;GAAc;GAAe;GAAiB;EAAU,GAApE,GAAoE;CACvF,CAAC;CAED,OAAO,oBAAA,UAAA,EAAA,UAAG,eAAiB,CAAA;AAC5B"}
|
package/dist/lib/devMsg.js
CHANGED
package/dist/lib/devMsg.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devMsg.js","names":[],"sources":["../../src/lib/devMsg.ts"],"sourcesContent":["import { version } from \"../../package.json\"
|
|
1
|
+
{"version":3,"file":"devMsg.js","names":[],"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 * \t;```ts\n * \tdevMsg(\"missing-param\");\n * \t// => \"https://prismic.dev/msg/react/v1.2.3/missing-param\"\n * \t```\n *\n * @param slug - Slug for the message. This corresponds to a Markdown file in the Git repository's\n * `/messages` directory.\n * @returns The `prismic.dev/msg` URL for the given slug.\n */\nexport function devMsg(slug: string): string {\n\treturn `https://prismic.dev/msg/react/v${version}/${slug}`\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,SAAgB,OAAO,MAAsB;CAC5C,OAAO,kCAAkC,QAAQ,GAAG;AACrD"}
|
package/dist/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismicio/react",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.2-canary.c2e05c8",
|
|
4
4
|
"description": "React components and hooks to fetch and present Prismic content",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"prismic",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"e2e-projects/*"
|
|
19
19
|
],
|
|
20
20
|
"files": [
|
|
21
|
-
"dist",
|
|
22
|
-
"src"
|
|
21
|
+
"./dist",
|
|
22
|
+
"./src"
|
|
23
23
|
],
|
|
24
24
|
"type": "module",
|
|
25
25
|
"sideEffects": false,
|
|
@@ -53,24 +53,25 @@
|
|
|
53
53
|
"esm-env": "^1.2.2"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@playwright/test": "^1.
|
|
57
|
-
"@prismicio/client": "^7.
|
|
58
|
-
"@types
|
|
59
|
-
"@types/react
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"react
|
|
66
|
-
"
|
|
67
|
-
"
|
|
56
|
+
"@playwright/test": "^1.63.0",
|
|
57
|
+
"@prismicio/client": "^7.22.1",
|
|
58
|
+
"@prismicio/types-internal": "^3.17.2",
|
|
59
|
+
"@types/react": "^19.3.0",
|
|
60
|
+
"@types/react-dom": "^19.3.0",
|
|
61
|
+
"dotenv": "^18.0.0",
|
|
62
|
+
"oxfmt": "^0.68.0",
|
|
63
|
+
"oxlint": "^1.83.0",
|
|
64
|
+
"playwright": "^1.63.0",
|
|
65
|
+
"react": "^19.3.0",
|
|
66
|
+
"react-dom": "^19.3.0",
|
|
67
|
+
"tsdown": "^0.23.0",
|
|
68
|
+
"typescript": "^7.0.2"
|
|
68
69
|
},
|
|
69
70
|
"peerDependencies": {
|
|
70
71
|
"@prismicio/client": "^7",
|
|
71
72
|
"react": "^18 || ^19"
|
|
72
73
|
},
|
|
73
74
|
"engines": {
|
|
74
|
-
"node": ">=
|
|
75
|
+
"node": ">=22"
|
|
75
76
|
}
|
|
76
77
|
}
|
package/src/PrismicImage.tsx
CHANGED
|
@@ -3,33 +3,33 @@ import {
|
|
|
3
3
|
asImagePixelDensitySrcSet,
|
|
4
4
|
asImageWidthSrcSet,
|
|
5
5
|
isFilled,
|
|
6
|
-
} from "@prismicio/client"
|
|
7
|
-
import { DEV } from "esm-env"
|
|
8
|
-
import { type ForwardedRef, forwardRef, type ComponentProps, type FC, type ReactNode } from "react"
|
|
6
|
+
} from "@prismicio/client"
|
|
7
|
+
import { DEV } from "esm-env"
|
|
8
|
+
import { type ForwardedRef, forwardRef, type ComponentProps, type FC, type ReactNode } from "react"
|
|
9
9
|
|
|
10
|
-
import { devMsg } from "./lib/devMsg.js"
|
|
10
|
+
import { devMsg } from "./lib/devMsg.js"
|
|
11
11
|
|
|
12
12
|
type ImgixURLParams = Omit<NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>, "widths"> &
|
|
13
|
-
Omit<NonNullable<Parameters<typeof asImagePixelDensitySrcSet>[1]>, "pixelDensities"
|
|
13
|
+
Omit<NonNullable<Parameters<typeof asImagePixelDensitySrcSet>[1]>, "pixelDensities">
|
|
14
14
|
|
|
15
15
|
/** Props for `<PrismicImage>`. */
|
|
16
16
|
export type PrismicImageProps = Omit<ComponentProps<"img">, "src" | "srcset" | "alt"> & {
|
|
17
17
|
/** The Prismic image field or thumbnail to render. */
|
|
18
|
-
field: ImageFieldImage | null | undefined
|
|
18
|
+
field: ImageFieldImage | null | undefined
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* An object of Imgix URL API parameters to transform the image.
|
|
22
22
|
*
|
|
23
23
|
* See: https://docs.imgix.com/apis/rendering
|
|
24
24
|
*/
|
|
25
|
-
imgixParams?: { [P in keyof ImgixURLParams]: ImgixURLParams[P] | null }
|
|
25
|
+
imgixParams?: { [P in keyof ImgixURLParams]: ImgixURLParams[P] | null }
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* Declare an image as decorative by providing `alt=""`.
|
|
29
29
|
*
|
|
30
30
|
* See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
31
31
|
*/
|
|
32
|
-
alt?: ""
|
|
32
|
+
alt?: ""
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* Declare an image as decorative only if the image field does not have alternative text by
|
|
@@ -37,13 +37,13 @@ export type PrismicImageProps = Omit<ComponentProps<"img">, "src" | "srcset" | "
|
|
|
37
37
|
*
|
|
38
38
|
* See: https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/alt#decorative_images
|
|
39
39
|
*/
|
|
40
|
-
fallbackAlt?: ""
|
|
40
|
+
fallbackAlt?: ""
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* The value to be rendered when the field is empty. If a fallback is not given, `null` will be
|
|
44
44
|
* rendered.
|
|
45
45
|
*/
|
|
46
|
-
fallback?: ReactNode
|
|
46
|
+
fallback?: ReactNode
|
|
47
47
|
} & (
|
|
48
48
|
| {
|
|
49
49
|
/**
|
|
@@ -55,13 +55,13 @@ export type PrismicImageProps = Omit<ComponentProps<"img">, "src" | "srcset" | "
|
|
|
55
55
|
* If the image field contains responsive views, each responsive view can be used as a width
|
|
56
56
|
* in the resulting `srcset` by passing `"thumbnails"` as the `widths` prop.
|
|
57
57
|
*/
|
|
58
|
-
widths?: NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>["widths"] | "defaults"
|
|
58
|
+
widths?: NonNullable<Parameters<typeof asImageWidthSrcSet>[1]>["widths"] | "defaults"
|
|
59
59
|
/** Not used when the `widths` prop is used. */
|
|
60
|
-
pixelDensities?: never
|
|
60
|
+
pixelDensities?: never
|
|
61
61
|
}
|
|
62
62
|
| {
|
|
63
63
|
/** Not used when the `widths` prop is used. */
|
|
64
|
-
widths?: never
|
|
64
|
+
widths?: never
|
|
65
65
|
/**
|
|
66
66
|
* Pixel densities used to build a `srcset` value for the image field.
|
|
67
67
|
*
|
|
@@ -70,15 +70,15 @@ export type PrismicImageProps = Omit<ComponentProps<"img">, "src" | "srcset" | "
|
|
|
70
70
|
*/
|
|
71
71
|
pixelDensities:
|
|
72
72
|
| NonNullable<Parameters<typeof asImagePixelDensitySrcSet>[1]>["pixelDensities"]
|
|
73
|
-
| "defaults"
|
|
73
|
+
| "defaults"
|
|
74
74
|
}
|
|
75
|
-
)
|
|
75
|
+
)
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
78
|
* Renders an optimized image from a Prismic image field.
|
|
79
79
|
*
|
|
80
80
|
* @example
|
|
81
|
-
*
|
|
81
|
+
* ;```tsx
|
|
82
82
|
* <PrismicImage field={slice.primary.photo} />;
|
|
83
83
|
* ```
|
|
84
84
|
*
|
|
@@ -97,7 +97,7 @@ export const PrismicImage: FC<PrismicImageProps> = forwardRef(function PrismicIm
|
|
|
97
97
|
pixelDensities,
|
|
98
98
|
fallback,
|
|
99
99
|
...restProps
|
|
100
|
-
} = props
|
|
100
|
+
} = props
|
|
101
101
|
|
|
102
102
|
if (DEV) {
|
|
103
103
|
if (typeof alt === "string" && alt !== "") {
|
|
@@ -105,7 +105,7 @@ export const PrismicImage: FC<PrismicImageProps> = forwardRef(function PrismicIm
|
|
|
105
105
|
`[PrismicImage] The "alt" prop can only be used to declare an image as decorative by passing an empty string (alt="") but was provided a non-empty string. You can resolve this warning by removing the "alt" prop or changing it to alt="". For more details, see ${devMsg(
|
|
106
106
|
"alt-must-be-an-empty-string",
|
|
107
107
|
)}`,
|
|
108
|
-
)
|
|
108
|
+
)
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
if (typeof fallbackAlt === "string" && fallbackAlt !== "") {
|
|
@@ -113,46 +113,46 @@ export const PrismicImage: FC<PrismicImageProps> = forwardRef(function PrismicIm
|
|
|
113
113
|
`[PrismicImage] The "fallbackAlt" prop can only be used to declare an image as decorative by passing an empty string (fallbackAlt="") but was provided a non-empty string. You can resolve this warning by removing the "fallbackAlt" prop or changing it to fallbackAlt="". For more details, see ${devMsg(
|
|
114
114
|
"alt-must-be-an-empty-string",
|
|
115
115
|
)}`,
|
|
116
|
-
)
|
|
116
|
+
)
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
if (widths && pixelDensities) {
|
|
120
120
|
console.warn(
|
|
121
121
|
`[PrismicImage] Only one of "widths" or "pixelDensities" props can be provided. You can resolve this warning by removing either the "widths" or "pixelDensities" prop. "widths" will be used in this case.`,
|
|
122
|
-
)
|
|
122
|
+
)
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
if (!isFilled.imageThumbnail(field)) {
|
|
127
|
-
return <>{fallback}
|
|
127
|
+
return <>{fallback}</>
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
const resolvedImgixParams = imgixParams
|
|
131
|
-
for (const x in
|
|
130
|
+
const resolvedImgixParams = { ...imgixParams }
|
|
131
|
+
for (const x in resolvedImgixParams) {
|
|
132
132
|
if (resolvedImgixParams[x as keyof typeof resolvedImgixParams] === null) {
|
|
133
|
-
resolvedImgixParams[x as keyof typeof resolvedImgixParams] = undefined
|
|
133
|
+
resolvedImgixParams[x as keyof typeof resolvedImgixParams] = undefined
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
let src: string | undefined
|
|
138
|
-
let srcSet: string | undefined
|
|
137
|
+
let src: string | undefined
|
|
138
|
+
let srcSet: string | undefined
|
|
139
139
|
|
|
140
140
|
if (widths || !pixelDensities) {
|
|
141
141
|
const res = asImageWidthSrcSet(field, {
|
|
142
142
|
...resolvedImgixParams,
|
|
143
143
|
widths: widths === "defaults" ? undefined : widths,
|
|
144
|
-
} as ImgixURLParams)
|
|
144
|
+
} as ImgixURLParams)
|
|
145
145
|
|
|
146
|
-
src = res.src
|
|
147
|
-
srcSet = res.srcset
|
|
146
|
+
src = res.src
|
|
147
|
+
srcSet = res.srcset
|
|
148
148
|
} else if (pixelDensities) {
|
|
149
149
|
const res = asImagePixelDensitySrcSet(field, {
|
|
150
150
|
...resolvedImgixParams,
|
|
151
151
|
pixelDensities: pixelDensities === "defaults" ? undefined : pixelDensities,
|
|
152
|
-
} as ImgixURLParams)
|
|
152
|
+
} as ImgixURLParams)
|
|
153
153
|
|
|
154
|
-
src = res.src
|
|
155
|
-
srcSet = res.srcset
|
|
154
|
+
src = res.src
|
|
155
|
+
srcSet = res.srcset
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
return (
|
|
@@ -163,5 +163,5 @@ export const PrismicImage: FC<PrismicImageProps> = forwardRef(function PrismicIm
|
|
|
163
163
|
alt={alt ?? (field.alt || fallbackAlt)}
|
|
164
164
|
{...restProps}
|
|
165
165
|
/>
|
|
166
|
-
)
|
|
167
|
-
})
|
|
166
|
+
)
|
|
167
|
+
})
|