@prismicio/react 3.2.1 → 3.2.2-canary.8d3ad6d
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.d.ts +66 -72
- package/dist/PrismicImage.d.ts.map +1 -0
- package/dist/PrismicImage.js +54 -47
- package/dist/PrismicImage.js.map +1 -1
- package/dist/PrismicLink.d.ts +71 -64
- package/dist/PrismicLink.d.ts.map +1 -0
- package/dist/PrismicLink.js +59 -40
- package/dist/PrismicLink.js.map +1 -1
- package/dist/PrismicRichText.d.ts +79 -100
- package/dist/PrismicRichText.d.ts.map +1 -0
- package/dist/PrismicRichText.js +125 -71
- package/dist/PrismicRichText.js.map +1 -1
- package/dist/PrismicTable.d.ts +58 -76
- package/dist/PrismicTable.d.ts.map +1 -0
- package/dist/PrismicTable.js +68 -21
- package/dist/PrismicTable.js.map +1 -1
- package/dist/PrismicText.d.ts +21 -25
- package/dist/PrismicText.d.ts.map +1 -0
- package/dist/PrismicText.js +30 -23
- package/dist/PrismicText.js.map +1 -1
- package/dist/PrismicToolbar.d.ts +21 -9
- package/dist/PrismicToolbar.d.ts.map +1 -0
- package/dist/PrismicToolbar.js +32 -19
- package/dist/PrismicToolbar.js.map +1 -1
- package/dist/SliceZone.d.ts +84 -83
- package/dist/SliceZone.d.ts.map +1 -0
- package/dist/SliceZone.js +54 -27
- package/dist/SliceZone.js.map +1 -1
- package/dist/index.d.ts +9 -15
- package/dist/index.js +4 -14
- package/dist/lib/devMsg.js +23 -6
- package/dist/lib/devMsg.js.map +1 -1
- package/dist/package.js +6 -0
- package/dist/package.js.map +1 -0
- package/package.json +21 -41
- package/src/PrismicImage.tsx +17 -25
- package/src/PrismicLink.tsx +21 -10
- package/src/PrismicRichText.tsx +26 -53
- package/src/PrismicTable.tsx +14 -36
- package/src/PrismicText.tsx +9 -18
- package/src/PrismicToolbar.tsx +10 -3
- package/src/SliceZone.tsx +46 -50
- package/src/lib/devMsg.ts +1 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/devMsg.d.ts +0 -16
- package/dist/package.json.js +0 -5
- package/dist/package.json.js.map +0 -1
package/dist/PrismicTable.js
CHANGED
|
@@ -1,28 +1,75 @@
|
|
|
1
|
-
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
-
import { isFilled } from "@prismicio/client";
|
|
3
1
|
import { PrismicRichText } from "./PrismicRichText.js";
|
|
2
|
+
import { isFilled } from "@prismicio/client";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
|
|
5
|
+
//#region src/PrismicTable.tsx
|
|
4
6
|
const defaultComponents = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
table: ({ children }) => /* @__PURE__ */ jsx("table", { children }),
|
|
8
|
+
thead: ({ children }) => /* @__PURE__ */ jsx("thead", { children }),
|
|
9
|
+
tbody: ({ children }) => /* @__PURE__ */ jsx("tbody", { children }),
|
|
10
|
+
tr: ({ children }) => /* @__PURE__ */ jsx("tr", { children }),
|
|
11
|
+
th: ({ children }) => /* @__PURE__ */ jsx("th", { children }),
|
|
12
|
+
td: ({ children }) => /* @__PURE__ */ jsx("td", { children })
|
|
11
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* Renders content from a Prismic table field as React components.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
*
|
|
19
|
+
* ```tsx
|
|
20
|
+
* <PrismicTable field={slice.primary.pricing_table} />;
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @see Learn how to style tables and customize table element components: {@link https://prismic.io/docs/fields/table}
|
|
24
|
+
*/
|
|
12
25
|
const PrismicTable = (props) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
26
|
+
const { field, components, fallback = null } = props;
|
|
27
|
+
if (!isFilled.table(field)) return fallback;
|
|
28
|
+
const { table: Table, thead: Thead, tbody: Tbody } = {
|
|
29
|
+
...defaultComponents,
|
|
30
|
+
...components
|
|
31
|
+
};
|
|
32
|
+
return /* @__PURE__ */ jsxs(Table, {
|
|
33
|
+
table: field,
|
|
34
|
+
children: [field.head && /* @__PURE__ */ jsx(Thead, {
|
|
35
|
+
head: field.head,
|
|
36
|
+
children: field.head.rows.map((row) => /* @__PURE__ */ jsx(TableRow, {
|
|
37
|
+
row,
|
|
38
|
+
components
|
|
39
|
+
}, row.key))
|
|
40
|
+
}), /* @__PURE__ */ jsx(Tbody, {
|
|
41
|
+
body: field.body,
|
|
42
|
+
children: field.body.rows.map((row) => /* @__PURE__ */ jsx(TableRow, {
|
|
43
|
+
row,
|
|
44
|
+
components
|
|
45
|
+
}, row.key))
|
|
46
|
+
})]
|
|
47
|
+
});
|
|
19
48
|
};
|
|
20
49
|
function TableRow(props) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
50
|
+
const { row, components } = props;
|
|
51
|
+
const { tr: Tr, th: Th, td: Td } = {
|
|
52
|
+
...defaultComponents,
|
|
53
|
+
...components
|
|
54
|
+
};
|
|
55
|
+
return /* @__PURE__ */ jsx(Tr, {
|
|
56
|
+
row,
|
|
57
|
+
children: row.cells.map((cell) => cell.type === "header" ? /* @__PURE__ */ jsx(Th, {
|
|
58
|
+
cell,
|
|
59
|
+
children: /* @__PURE__ */ jsx(PrismicRichText, {
|
|
60
|
+
field: cell.content,
|
|
61
|
+
components
|
|
62
|
+
})
|
|
63
|
+
}, cell.key) : /* @__PURE__ */ jsx(Td, {
|
|
64
|
+
cell,
|
|
65
|
+
children: /* @__PURE__ */ jsx(PrismicRichText, {
|
|
66
|
+
field: cell.content,
|
|
67
|
+
components
|
|
68
|
+
})
|
|
69
|
+
}, cell.key))
|
|
70
|
+
});
|
|
24
71
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
28
|
-
//# sourceMappingURL=PrismicTable.js.map
|
|
72
|
+
|
|
73
|
+
//#endregion
|
|
74
|
+
export { PrismicTable };
|
|
75
|
+
//# sourceMappingURL=PrismicTable.js.map
|
package/dist/PrismicTable.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicTable.js","sources":["../src/PrismicTable.tsx"],"sourcesContent":["import { ComponentType, FC, ReactNode } from \"react\";\nimport {\n\tisFilled,\n\
|
|
1
|
+
{"version":3,"file":"PrismicTable.js","names":[],"sources":["../src/PrismicTable.tsx"],"sourcesContent":["import type { ComponentType, FC, ReactNode } from \"react\";\nimport {\n\tisFilled,\n\ttype TableField,\n\ttype TableFieldHead,\n\ttype TableFieldHeadRow,\n\ttype TableFieldBody,\n\ttype TableFieldBodyRow,\n\ttype TableFieldHeaderCell,\n\ttype TableFieldDataCell,\n} from \"@prismicio/client\";\n\nimport { type JSXMapSerializer, PrismicRichText } from \"./PrismicRichText.js\";\n\ntype TableComponents = {\n\ttable?: ComponentType<{ table: TableField<\"filled\">; children: ReactNode }>;\n\tthead?: ComponentType<{ head: TableFieldHead; children: ReactNode }>;\n\ttbody?: ComponentType<{ body: TableFieldBody; children: ReactNode }>;\n\ttr?: ComponentType<{\n\t\trow: TableFieldHeadRow | TableFieldBodyRow;\n\t\tchildren: ReactNode;\n\t}>;\n\tth?: ComponentType<{ cell: TableFieldHeaderCell; children: ReactNode }>;\n\ttd?: ComponentType<{ cell: TableFieldDataCell; children: ReactNode }>;\n};\n\nconst defaultComponents: Required<TableComponents> = {\n\ttable: ({ children }) => <table>{children}</table>,\n\tthead: ({ children }) => <thead>{children}</thead>,\n\ttbody: ({ children }) => <tbody>{children}</tbody>,\n\ttr: ({ children }) => <tr>{children}</tr>,\n\tth: ({ children }) => <th>{children}</th>,\n\ttd: ({ children }) => <td>{children}</td>,\n};\n\n/** Props for `<PrismicTable>`. */\nexport type PrismicTableProps = {\n\t/** The Prismic table field to render. */\n\tfield: TableField;\n\n\t/**\n\t * An object that maps a table block to a React component.\n\t *\n\t * @example A map serializer.\n\t *\n\t * ```jsx\n\t * {\n\t * table: ({children}) => <table>{children}</table>\n\t * thead: ({children}) => <thead>{children}</thead>\n\t * }\n\t * ```\n\t */\n\tcomponents?: JSXMapSerializer & TableComponents;\n\n\t/**\n\t * The value to be rendered when the field is empty. If a fallback is not\n\t * given, `null` will be rendered.\n\t */\n\tfallback?: ReactNode;\n};\n\n/**\n * Renders content from a Prismic table field as React components.\n *\n * @example\n *\n * ```tsx\n * <PrismicTable field={slice.primary.pricing_table} />;\n * ```\n *\n * @see Learn how to style tables and customize table element components: {@link https://prismic.io/docs/fields/table}\n */\nexport const PrismicTable: FC<PrismicTableProps> = (props) => {\n\tconst { field, components, fallback = null } = props;\n\n\tif (!isFilled.table(field)) {\n\t\treturn fallback;\n\t}\n\n\tconst {\n\t\ttable: Table,\n\t\tthead: Thead,\n\t\ttbody: Tbody,\n\t} = { ...defaultComponents, ...components };\n\n\treturn (\n\t\t<Table table={field}>\n\t\t\t{field.head && (\n\t\t\t\t<Thead head={field.head}>\n\t\t\t\t\t{field.head.rows.map((row) => (\n\t\t\t\t\t\t<TableRow key={row.key} row={row} components={components} />\n\t\t\t\t\t))}\n\t\t\t\t</Thead>\n\t\t\t)}\n\t\t\t<Tbody body={field.body}>\n\t\t\t\t{field.body.rows.map((row) => (\n\t\t\t\t\t<TableRow key={row.key} row={row} components={components} />\n\t\t\t\t))}\n\t\t\t</Tbody>\n\t\t</Table>\n\t);\n};\n\ntype TableRowProps = {\n\trow: TableFieldHeadRow | TableFieldBodyRow;\n\tcomponents?: JSXMapSerializer & TableComponents;\n};\n\nfunction TableRow(props: TableRowProps) {\n\tconst { row, components } = props;\n\n\tconst { tr: Tr, th: Th, td: Td } = { ...defaultComponents, ...components };\n\n\treturn (\n\t\t<Tr row={row}>\n\t\t\t{row.cells.map((cell) =>\n\t\t\t\tcell.type === \"header\" ? (\n\t\t\t\t\t<Th key={cell.key} cell={cell}>\n\t\t\t\t\t\t<PrismicRichText field={cell.content} components={components} />\n\t\t\t\t\t</Th>\n\t\t\t\t) : (\n\t\t\t\t\t<Td key={cell.key} cell={cell}>\n\t\t\t\t\t\t<PrismicRichText field={cell.content} components={components} />\n\t\t\t\t\t</Td>\n\t\t\t\t),\n\t\t\t)}\n\t\t</Tr>\n\t);\n}\n"],"mappings":";;;;;AA0BA,MAAM,oBAA+C;CACpD,QAAQ,EAAE,eAAe,oBAAC,WAAO,WAAiB;CAClD,QAAQ,EAAE,eAAe,oBAAC,WAAO,WAAiB;CAClD,QAAQ,EAAE,eAAe,oBAAC,WAAO,WAAiB;CAClD,KAAK,EAAE,eAAe,oBAAC,QAAI,WAAc;CACzC,KAAK,EAAE,eAAe,oBAAC,QAAI,WAAc;CACzC,KAAK,EAAE,eAAe,oBAAC,QAAI,WAAc;CACzC;;;;;;;;;;;;AAuCD,MAAa,gBAAuC,UAAU;CAC7D,MAAM,EAAE,OAAO,YAAY,WAAW,SAAS;AAE/C,KAAI,CAAC,SAAS,MAAM,MAAM,CACzB,QAAO;CAGR,MAAM,EACL,OAAO,OACP,OAAO,OACP,OAAO,UACJ;EAAE,GAAG;EAAmB,GAAG;EAAY;AAE3C,QACC,qBAAC;EAAM,OAAO;aACZ,MAAM,QACN,oBAAC;GAAM,MAAM,MAAM;aACjB,MAAM,KAAK,KAAK,KAAK,QACrB,oBAAC;IAA4B;IAAiB;MAA/B,IAAI,IAAyC,CAC3D;IACK,EAET,oBAAC;GAAM,MAAM,MAAM;aACjB,MAAM,KAAK,KAAK,KAAK,QACrB,oBAAC;IAA4B;IAAiB;MAA/B,IAAI,IAAyC,CAC3D;IACK;GACD;;AASV,SAAS,SAAS,OAAsB;CACvC,MAAM,EAAE,KAAK,eAAe;CAE5B,MAAM,EAAE,IAAI,IAAI,IAAI,IAAI,IAAI,OAAO;EAAE,GAAG;EAAmB,GAAG;EAAY;AAE1E,QACC,oBAAC;EAAQ;YACP,IAAI,MAAM,KAAK,SACf,KAAK,SAAS,WACb,oBAAC;GAAwB;aACxB,oBAAC;IAAgB,OAAO,KAAK;IAAqB;KAAc;KADxD,KAAK,IAET,GAEL,oBAAC;GAAwB;aACxB,oBAAC;IAAgB,OAAO,KAAK;IAAqB;KAAc;KADxD,KAAK,IAET,CAEN;GACG"}
|
package/dist/PrismicText.d.ts
CHANGED
|
@@ -1,35 +1,31 @@
|
|
|
1
1
|
import { FC } from "react";
|
|
2
2
|
import { RichTextField } from "@prismicio/client";
|
|
3
|
+
|
|
4
|
+
//#region src/PrismicText.d.ts
|
|
3
5
|
/** Props for `<PrismicText>`. */
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
type PrismicTextProps = {
|
|
7
|
+
/** The Prismic rich text field to render. */
|
|
8
|
+
field: RichTextField | null | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* The string rendered when the field is empty. If a fallback is not given,
|
|
11
|
+
* `null` will be rendered.
|
|
12
|
+
*/
|
|
13
|
+
fallback?: string;
|
|
14
|
+
/** The separator used between blocks. Defaults to `\n`. */
|
|
15
|
+
separator?: string;
|
|
14
16
|
};
|
|
15
17
|
/**
|
|
16
|
-
*
|
|
17
|
-
* text.
|
|
18
|
+
* Renders content from a Prismic rich text field as plain text (no HTML).
|
|
18
19
|
*
|
|
19
|
-
* @
|
|
20
|
-
* This component returns a React fragment with no wrapping element around the
|
|
21
|
-
* content. If you need a wrapper, add a component around `<PrismicText>`.
|
|
20
|
+
* @example
|
|
22
21
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* ```jsx
|
|
26
|
-
* <PrismicText field={document.data.content} />;
|
|
22
|
+
* ```tsx
|
|
23
|
+
* <PrismicText field={slice.primary.text} />;
|
|
27
24
|
* ```
|
|
28
25
|
*
|
|
29
|
-
* @
|
|
30
|
-
*
|
|
31
|
-
* @returns The Rich Text field's content as plain text.
|
|
32
|
-
*
|
|
33
|
-
* @see Learn about Rich Text fields {@link https://io/docs/core-concepts/rich-text-title}
|
|
26
|
+
* @see Learn how to display rich text as plain text or React components: {@link https://prismic.io/docs/fields/rich-text}
|
|
34
27
|
*/
|
|
35
|
-
|
|
28
|
+
declare const PrismicText: FC<PrismicTextProps>;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { PrismicText, PrismicTextProps };
|
|
31
|
+
//# sourceMappingURL=PrismicText.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrismicText.d.ts","names":[],"sources":["../src/PrismicText.tsx"],"sourcesContent":[],"mappings":";;;;;KAOY,gBAAA;EAAA;EAyBC,KAAA,EAvBL,aAuDP,GAAA,IAhC4B,GAAA,SAAA;;;;;;;;;;;;;;;;;;;;cAAhB,aAAa,GAAG"}
|
package/dist/PrismicText.js
CHANGED
|
@@ -1,26 +1,33 @@
|
|
|
1
|
-
import { jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { isFilled, asText } from "@prismicio/client";
|
|
3
|
-
import { DEV } from "esm-env";
|
|
4
1
|
import { devMsg } from "./lib/devMsg.js";
|
|
2
|
+
import { asText, isFilled } from "@prismicio/client";
|
|
3
|
+
import { DEV } from "esm-env";
|
|
4
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
5
|
+
|
|
6
|
+
//#region src/PrismicText.tsx
|
|
7
|
+
/**
|
|
8
|
+
* Renders content from a Prismic rich text field as plain text (no HTML).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
*
|
|
12
|
+
* ```tsx
|
|
13
|
+
* <PrismicText field={slice.primary.text} />;
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @see Learn how to display rich text as plain text or React components: {@link https://prismic.io/docs/fields/rich-text}
|
|
17
|
+
*/
|
|
5
18
|
const PrismicText = (props) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
if (!isFilled.richText(field)) {
|
|
19
|
-
return fallback != null ? jsx(Fragment, { children: fallback }) : null;
|
|
20
|
-
}
|
|
21
|
-
return jsx(Fragment, { children: asText(field, { separator }) });
|
|
22
|
-
};
|
|
23
|
-
export {
|
|
24
|
-
PrismicText
|
|
19
|
+
const { field, fallback, separator } = props;
|
|
20
|
+
if (DEV) {
|
|
21
|
+
if ("className" in props) console.warn(`[PrismicText] className cannot be passed to <PrismicText> since it renders plain text without a wrapping component. For more details, see ${devMsg("classname-is-not-a-valid-prop")}.`, props.field);
|
|
22
|
+
}
|
|
23
|
+
if (typeof props.field === "string") {
|
|
24
|
+
if (DEV) console.error(`[PrismicText] The "field" prop only accepts a rich text field's value but was provided a different type of field instead (e.g. a key text or select field). You can resolve this error by rendering the field value inline without <PrismicText>. For more details, see ${devMsg("prismictext-works-only-with-rich-text-and-title-fields")}`, props.field);
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
if (!isFilled.richText(field)) return fallback != null ? /* @__PURE__ */ jsx(Fragment, { children: fallback }) : null;
|
|
28
|
+
return /* @__PURE__ */ jsx(Fragment, { children: asText(field, { separator }) });
|
|
25
29
|
};
|
|
26
|
-
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { PrismicText };
|
|
33
|
+
//# sourceMappingURL=PrismicText.js.map
|
package/dist/PrismicText.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicText.js","sources":["../src/PrismicText.tsx"],"sourcesContent":["import { FC } from \"react\";\nimport { asText, isFilled, RichTextField } from \"@prismicio/client\";\nimport { DEV } from \"esm-env\";\n\nimport { devMsg } from \"./lib/devMsg.js\";\n\n/** Props for `<PrismicText>`. */\nexport type PrismicTextProps = {\n\t/** The Prismic
|
|
1
|
+
{"version":3,"file":"PrismicText.js","names":[],"sources":["../src/PrismicText.tsx"],"sourcesContent":["import type { FC } from \"react\";\nimport { asText, isFilled, type RichTextField } from \"@prismicio/client\";\nimport { DEV } from \"esm-env\";\n\nimport { devMsg } from \"./lib/devMsg.js\";\n\n/** Props for `<PrismicText>`. */\nexport type PrismicTextProps = {\n\t/** The Prismic rich text field to render. */\n\tfield: RichTextField | null | undefined;\n\n\t/**\n\t * The string rendered when the field is empty. If a fallback is not given,\n\t * `null` will be rendered.\n\t */\n\tfallback?: string;\n\n\t/** The separator used between blocks. Defaults to `\\n`. */\n\tseparator?: string;\n};\n\n/**\n * Renders content from a Prismic rich text field as plain text (no HTML).\n *\n * @example\n *\n * ```tsx\n * <PrismicText field={slice.primary.text} />;\n * ```\n *\n * @see Learn how to display rich text as plain text or React components: {@link https://prismic.io/docs/fields/rich-text}\n */\nexport const PrismicText: FC<PrismicTextProps> = (props) => {\n\tconst { field, fallback, separator } = props;\n\n\tif (DEV) {\n\t\tif (\"className\" in props) {\n\t\t\tconsole.warn(\n\t\t\t\t`[PrismicText] className cannot be passed to <PrismicText> since it renders plain text without a wrapping component. For more details, see ${devMsg(\n\t\t\t\t\t\"classname-is-not-a-valid-prop\",\n\t\t\t\t)}.`,\n\t\t\t\tprops.field,\n\t\t\t);\n\t\t}\n\t}\n\n\tif (typeof props.field === \"string\") {\n\t\tif (DEV) {\n\t\t\tconsole.error(\n\t\t\t\t`[PrismicText] The \"field\" prop only accepts a rich text field's value but was provided a different type of field instead (e.g. a key text or select field). You can resolve this error by rendering the field value inline without <PrismicText>. For more details, see ${devMsg(\n\t\t\t\t\t\"prismictext-works-only-with-rich-text-and-title-fields\",\n\t\t\t\t)}`,\n\t\t\t\tprops.field,\n\t\t\t);\n\t\t}\n\n\t\treturn null;\n\t}\n\n\tif (!isFilled.richText(field)) {\n\t\treturn fallback != null ? <>{fallback}</> : null;\n\t}\n\n\treturn <>{asText(field, { separator })}</>;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAgCA,MAAa,eAAqC,UAAU;CAC3D,MAAM,EAAE,OAAO,UAAU,cAAc;AAEvC,KAAI,KACH;MAAI,eAAe,MAClB,SAAQ,KACP,6IAA6I,OAC5I,gCACA,CAAC,IACF,MAAM,MACN;;AAIH,KAAI,OAAO,MAAM,UAAU,UAAU;AACpC,MAAI,IACH,SAAQ,MACP,2QAA2Q,OAC1Q,yDACA,IACD,MAAM,MACN;AAGF,SAAO;;AAGR,KAAI,CAAC,SAAS,SAAS,MAAM,CAC5B,QAAO,YAAY,OAAO,0CAAG,WAAY,GAAG;AAG7C,QAAO,0CAAG,OAAO,OAAO,EAAE,WAAW,CAAC,GAAI"}
|
package/dist/PrismicToolbar.d.ts
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
import { FC } from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/PrismicToolbar.d.ts
|
|
2
4
|
/** Props for `<PrismicToolbar>`. */
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
type PrismicToolbarProps = {
|
|
6
|
+
/**
|
|
7
|
+
* The name of the Prismic repository. For example, `"my-repo"` if the
|
|
8
|
+
* repository URL is `my-repo.prismic.io`.
|
|
9
|
+
*/
|
|
10
|
+
repositoryName: string;
|
|
9
11
|
};
|
|
10
12
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
+
* Renders the Prismic Toolbar script to support draft previews.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* ```tsx
|
|
18
|
+
* <PrismicToolbar repositoryName="my-repo" />;
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @see Learn how to set up preview functionality and the toolbar's role in preview sessions: {@link https://prismic.io/docs/previews}
|
|
13
22
|
*/
|
|
14
|
-
|
|
23
|
+
declare const PrismicToolbar: FC<PrismicToolbarProps>;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { PrismicToolbar, PrismicToolbarProps };
|
|
26
|
+
//# sourceMappingURL=PrismicToolbar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrismicToolbar.d.ts","names":[],"sources":["../src/PrismicToolbar.tsx"],"sourcesContent":[],"mappings":";;;;KAMY,mBAAA;EAAA;AAmBZ;;;;;;;;;;;;;;;;cAAa,gBAAgB,GAAG"}
|
package/dist/PrismicToolbar.js
CHANGED
|
@@ -1,24 +1,37 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
|
|
2
3
|
import { useEffect } from "react";
|
|
3
4
|
import { getToolbarSrc } from "@prismicio/client";
|
|
5
|
+
|
|
6
|
+
//#region src/PrismicToolbar.tsx
|
|
7
|
+
/**
|
|
8
|
+
* Renders the Prismic Toolbar script to support draft previews.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
*
|
|
12
|
+
* ```tsx
|
|
13
|
+
* <PrismicToolbar repositoryName="my-repo" />;
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @see Learn how to set up preview functionality and the toolbar's role in preview sessions: {@link https://prismic.io/docs/previews}
|
|
17
|
+
*/
|
|
4
18
|
const PrismicToolbar = (props) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return null;
|
|
19
|
+
const { repositoryName } = props;
|
|
20
|
+
const src = getToolbarSrc(repositoryName);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (!document.querySelector(`script[src="${src}"]`)) {
|
|
23
|
+
const script = document.createElement("script");
|
|
24
|
+
script.src = src;
|
|
25
|
+
script.defer = true;
|
|
26
|
+
script.dataset.prismicToolbar = "";
|
|
27
|
+
script.dataset.repositoryName = repositoryName;
|
|
28
|
+
script._evaluateScript = false;
|
|
29
|
+
document.body.appendChild(script);
|
|
30
|
+
}
|
|
31
|
+
}, [repositoryName, src]);
|
|
32
|
+
return null;
|
|
20
33
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
//# sourceMappingURL=PrismicToolbar.js.map
|
|
34
|
+
|
|
35
|
+
//#endregion
|
|
36
|
+
export { PrismicToolbar };
|
|
37
|
+
//# sourceMappingURL=PrismicToolbar.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicToolbar.js","sources":["../src/PrismicToolbar.tsx"],"sourcesContent":["\"use client\";\n\nimport { FC, useEffect } from \"react\";\nimport { getToolbarSrc } from \"@prismicio/client\";\n\n/** Props for `<PrismicToolbar>`. */\nexport type PrismicToolbarProps = {\n\t/**\n\t * The name of the Prismic repository. For example, `\"my-repo\"` if the\n\t * repository URL is `my-repo.prismic.io`.\n\t */\n\trepositoryName: string;\n};\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"PrismicToolbar.js","names":[],"sources":["../src/PrismicToolbar.tsx"],"sourcesContent":["\"use client\";\n\nimport { type FC, useEffect } from \"react\";\nimport { getToolbarSrc } from \"@prismicio/client\";\n\n/** Props for `<PrismicToolbar>`. */\nexport type PrismicToolbarProps = {\n\t/**\n\t * The name of the Prismic repository. For example, `\"my-repo\"` if the\n\t * repository URL is `my-repo.prismic.io`.\n\t */\n\trepositoryName: string;\n};\n\n/**\n * Renders the Prismic Toolbar script to support draft previews.\n *\n * @example\n *\n * ```tsx\n * <PrismicToolbar repositoryName=\"my-repo\" />;\n * ```\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 } = props;\n\n\tconst src = getToolbarSrc(repositoryName);\n\n\tuseEffect(() => {\n\t\tconst existingScript = document.querySelector(`script[src=\"${src}\"]`);\n\n\t\tif (!existingScript) {\n\t\t\tconst script = document.createElement(\"script\");\n\t\t\tscript.src = src;\n\t\t\tscript.defer = true;\n\n\t\t\t// Used to distinguish the toolbar element from other elements.\n\t\t\tscript.dataset.prismicToolbar = \"\";\n\t\t\tscript.dataset.repositoryName = repositoryName;\n\n\t\t\t// Disable Happy DOM `<script>` evaluation during tests.\n\t\t\t// @ts-expect-error - `_evaluateScript` is a Happy DOM-specific property.\n\t\t\tscript._evaluateScript = false;\n\n\t\t\tdocument.body.appendChild(script);\n\t\t}\n\t}, [repositoryName, src]);\n\n\treturn null;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAyBA,MAAa,kBAA2C,UAAU;CACjE,MAAM,EAAE,mBAAmB;CAE3B,MAAM,MAAM,cAAc,eAAe;AAEzC,iBAAgB;AAGf,MAAI,CAFmB,SAAS,cAAc,eAAe,IAAI,IAAI,EAEhD;GACpB,MAAM,SAAS,SAAS,cAAc,SAAS;AAC/C,UAAO,MAAM;AACb,UAAO,QAAQ;AAGf,UAAO,QAAQ,iBAAiB;AAChC,UAAO,QAAQ,iBAAiB;AAIhC,UAAO,kBAAkB;AAEzB,YAAS,KAAK,YAAY,OAAO;;IAEhC,CAAC,gBAAgB,IAAI,CAAC;AAEzB,QAAO"}
|
package/dist/SliceZone.d.ts
CHANGED
|
@@ -1,139 +1,140 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { ComponentType, FC, ReactNode } from "react";
|
|
2
|
+
import { Slice } from "@prismicio/client";
|
|
3
|
+
|
|
4
|
+
//#region src/SliceZone.d.ts
|
|
5
|
+
|
|
3
6
|
/**
|
|
4
7
|
* Returns the type of a `SliceLike` type.
|
|
5
8
|
*
|
|
6
|
-
* @typeParam
|
|
9
|
+
* @typeParam TSlice - The slice from which the type will be extracted.
|
|
7
10
|
*/
|
|
8
11
|
type ExtractSliceType<TSlice extends SliceLike> = TSlice extends Slice ? TSlice["slice_type"] : TSlice extends SliceLikeGraphQL ? TSlice["type"] : never;
|
|
9
12
|
/**
|
|
10
|
-
* The minimum required properties to represent a Prismic
|
|
11
|
-
*
|
|
13
|
+
* The minimum required properties to represent a Prismic slice from the Prismic
|
|
14
|
+
* Content API for the `mapSliceZone()` helper.
|
|
12
15
|
*
|
|
13
|
-
* @typeParam SliceType - Type name of the
|
|
16
|
+
* @typeParam SliceType - Type name of the slice.
|
|
14
17
|
*/
|
|
15
|
-
|
|
18
|
+
type SliceLikeRestV2<TSliceType extends string = string> = Pick<Slice<TSliceType>, "id" | "slice_type">;
|
|
16
19
|
/**
|
|
17
|
-
* The minimum required properties to represent a Prismic
|
|
18
|
-
* GraphQL API for the `
|
|
20
|
+
* The minimum required properties to represent a Prismic slice from the Prismic
|
|
21
|
+
* GraphQL API for the `mapSliceZone()` helper.
|
|
19
22
|
*
|
|
20
|
-
* @typeParam SliceType - Type name of the
|
|
23
|
+
* @typeParam SliceType - Type name of the slice.
|
|
21
24
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
type SliceLikeGraphQL<TSliceType extends string = string> = {
|
|
26
|
+
type: Slice<TSliceType>["slice_type"];
|
|
24
27
|
};
|
|
25
28
|
/**
|
|
26
|
-
* The minimum required properties to represent a Prismic
|
|
27
|
-
* `
|
|
29
|
+
* The minimum required properties to represent a Prismic slice for the
|
|
30
|
+
* `mapSliceZone()` helper.
|
|
28
31
|
*
|
|
29
|
-
* If using Prismic's
|
|
32
|
+
* If using Prismic's Content API, use the `Slice` export from
|
|
30
33
|
* `@prismicio/client` for a full interface.
|
|
31
34
|
*
|
|
32
|
-
* @typeParam SliceType - Type name of the
|
|
35
|
+
* @typeParam SliceType - Type name of the slice.
|
|
33
36
|
*/
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
type SliceLike<TSliceType extends string = string> = (SliceLikeRestV2<TSliceType> | SliceLikeGraphQL<TSliceType>) & {
|
|
38
|
+
/**
|
|
39
|
+
* If `true`, this slice has been modified from its original value using a
|
|
40
|
+
* mapper and `@prismicio/client`'s `mapSliceZone()`.
|
|
41
|
+
*
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
__mapped?: true;
|
|
42
45
|
};
|
|
43
46
|
/**
|
|
44
47
|
* A looser version of the `SliceZone` type from `@prismicio/client` using
|
|
45
48
|
* `SliceLike`.
|
|
46
49
|
*
|
|
47
|
-
* If using Prismic's
|
|
50
|
+
* If using Prismic's Content API, use the `SliceZone` export from
|
|
48
51
|
* `@prismicio/client` for the full type.
|
|
49
52
|
*
|
|
50
|
-
* @typeParam TSlice - The type(s) of a
|
|
53
|
+
* @typeParam TSlice - The type(s) of a slice in the slice zone.
|
|
51
54
|
*/
|
|
52
|
-
|
|
55
|
+
type SliceZoneLike<TSlice extends SliceLike = SliceLike> = readonly TSlice[];
|
|
53
56
|
/**
|
|
54
|
-
* React props for a component rendering content from a Prismic
|
|
57
|
+
* React props for a component rendering content from a Prismic slice using the
|
|
55
58
|
* `<SliceZone>` component.
|
|
56
59
|
*
|
|
57
|
-
* @typeParam TSlice - The
|
|
60
|
+
* @typeParam TSlice - The slice passed as a prop.
|
|
58
61
|
* @typeParam TContext - Arbitrary data passed to `<SliceZone>` and made
|
|
59
|
-
* available to all
|
|
62
|
+
* available to all slice components.
|
|
60
63
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
64
|
+
type SliceComponentProps<TSlice extends SliceLike = SliceLike, TContext = unknown> = {
|
|
65
|
+
/** Slice data for this component. */
|
|
66
|
+
slice: TSlice;
|
|
67
|
+
/** The index of the slice in the slice zone. */
|
|
68
|
+
index: number;
|
|
69
|
+
/** All slices from the slice zone to which the slice belongs. */
|
|
70
|
+
slices: SliceZoneLike<TSlice extends SliceLikeGraphQL ? SliceLikeGraphQL : SliceLikeRestV2>;
|
|
71
|
+
/**
|
|
72
|
+
* Arbitrary data passed to `<SliceZone>` and made available to all slice
|
|
73
|
+
* components.
|
|
74
|
+
*/
|
|
75
|
+
context: TContext;
|
|
73
76
|
};
|
|
74
77
|
/**
|
|
75
|
-
* A React component to be rendered for each instance of its
|
|
78
|
+
* A React component to be rendered for each instance of its slice.
|
|
76
79
|
*
|
|
77
|
-
* @typeParam TSlice - The type(s) of a
|
|
78
|
-
* @typeParam TContext - Arbitrary data made available to all
|
|
80
|
+
* @typeParam TSlice - The type(s) of a slice in the slice zone.
|
|
81
|
+
* @typeParam TContext - Arbitrary data made available to all slice components.
|
|
79
82
|
*/
|
|
80
|
-
|
|
83
|
+
type SliceComponentType<TSlice extends SliceLike = any, TContext = unknown> = ComponentType<SliceComponentProps<TSlice, TContext>>;
|
|
81
84
|
/**
|
|
82
|
-
* A record of
|
|
83
|
-
* rendered for each instance of its
|
|
85
|
+
* A record of slice types mapped to a React component. The component will be
|
|
86
|
+
* rendered for each instance of its slice.
|
|
84
87
|
*
|
|
85
88
|
* @deprecated This type is no longer used by `@prismicio/react`. Prefer using
|
|
86
89
|
* `Record<string, SliceComponentType<any>>` instead.
|
|
87
90
|
*
|
|
88
|
-
* @typeParam TSlice - The type(s) of a
|
|
89
|
-
* @typeParam TContext - Arbitrary data made available to all
|
|
91
|
+
* @typeParam TSlice - The type(s) of a slice in the slice zone.
|
|
92
|
+
* @typeParam TContext - Arbitrary data made available to all slice components.
|
|
90
93
|
*/
|
|
91
|
-
|
|
92
|
-
[SliceType in ExtractSliceType<TSlice>]: SliceComponentType<Extract<TSlice, SliceLike<SliceType>> extends never ? SliceLike : Extract<TSlice, SliceLike<SliceType>>, TContext>;
|
|
93
|
-
};
|
|
94
|
+
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> };
|
|
94
95
|
/**
|
|
95
96
|
* React props for the `<SliceZone>` component.
|
|
96
97
|
*
|
|
97
|
-
* @typeParam TSlice - The type(s) of a
|
|
98
|
-
* @typeParam TContext - Arbitrary data made available to all
|
|
98
|
+
* @typeParam TSlice - The type(s) of a slice in the slice zone.
|
|
99
|
+
* @typeParam TContext - Arbitrary data made available to all slice components.
|
|
99
100
|
*/
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
101
|
+
type SliceZoneProps<TContext = unknown> = {
|
|
102
|
+
/** List of slice data from the slice zone. */
|
|
103
|
+
slices?: SliceZoneLike;
|
|
104
|
+
/** A record mapping slice types to React components. */
|
|
105
|
+
components?: Record<string, ComponentType<any>>;
|
|
106
|
+
/**
|
|
107
|
+
* The React component rendered if a component mapping from the `components`
|
|
108
|
+
* prop cannot be found.
|
|
109
|
+
*/
|
|
110
|
+
defaultComponent?: ComponentType<SliceComponentProps<any, TContext>>;
|
|
111
|
+
/** Arbitrary data made available to all slice components. */
|
|
112
|
+
context?: TContext;
|
|
112
113
|
};
|
|
113
114
|
/**
|
|
114
|
-
* This
|
|
115
|
+
* This slice component can be used as a reminder to provide a proper
|
|
115
116
|
* implementation.
|
|
116
117
|
*
|
|
117
118
|
* This is also the default React component rendered when a component mapping
|
|
118
119
|
* cannot be found in `<SliceZone>`.
|
|
119
120
|
*/
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
121
|
+
declare const TODOSliceComponent: <TSlice extends SliceLike>({
|
|
122
|
+
slice
|
|
123
|
+
}: {
|
|
124
|
+
slice: TSlice;
|
|
125
|
+
}) => ReactNode;
|
|
123
126
|
/**
|
|
124
|
-
* Renders
|
|
125
|
-
* type of Slice.
|
|
126
|
-
*
|
|
127
|
-
* If a component is not provided for a type of Slice, a default component can
|
|
128
|
-
* be provided. A fallback component is provided by default that will not be
|
|
129
|
-
* rendered in a production build of your app.
|
|
127
|
+
* Renders slices in a slice zone as React components.
|
|
130
128
|
*
|
|
131
|
-
* @
|
|
132
|
-
* @typeParam TContext - Arbitrary data made available to all Slice components.
|
|
129
|
+
* @example
|
|
133
130
|
*
|
|
134
|
-
*
|
|
131
|
+
* ```tsx
|
|
132
|
+
* <SliceZone slices={page.data.slices} components={components} />;
|
|
133
|
+
* ```
|
|
135
134
|
*
|
|
136
|
-
* @see Learn
|
|
135
|
+
* @see Learn how to create slices, use slice variations, and display slices: {@link https://prismic.io/docs/slices}
|
|
137
136
|
*/
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
declare const SliceZone: FC<SliceZoneProps>;
|
|
138
|
+
//#endregion
|
|
139
|
+
export { SliceComponentProps, SliceComponentType, SliceLike, SliceLikeGraphQL, SliceLikeRestV2, SliceZone, SliceZoneComponents, SliceZoneLike, SliceZoneProps, TODOSliceComponent };
|
|
140
|
+
//# sourceMappingURL=SliceZone.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SliceZone.d.ts","names":[],"sources":["../src/SliceZone.tsx"],"sourcesContent":[],"mappings":";;;;;;;AAC+C;;;KAQ1C,gBAA4D,CAAA,eAA5B,SAA4B,CAAA,GAAf,MAAe,SAAA,KAAA,GAC9D,MAD8D,CAAA,YAAA,CAAA,GAE9D,MAF8D,SAE/C,gBAF+C,GAG7D,MAH6D,CAAA,MAAA,CAAA,GAAA,KAAA;;;;;;AAYjE;AACO,KADK,eACL,CAAA,mBAAA,MAAA,GAAA,MAAA,CAAA,GAD2D,IAC3D,CAAN,KAAM,CAAA,UAAA,CAAA,EAAA,IAAA,GAAA,YAAA,CAAA;;;;AAUP;AAaA;;AACG,KAdS,gBAcT,CAAA,mBAAA,MAAA,GAAA,MAAA,CAAA,GAAA;EACiB,IAAA,EAdb,KAca,CAdP,UAcO,CAAA,CAAA,YAAA,CAAA;CAAjB;;AAoBH;;;;;AAWA;;;AAKQ,KAtCI,SAsCJ,CAAA,mBAAA,MAAA,GAAA,MAAA,CAAA,GAAA,CArCL,eAqCK,CArCW,UAqCX,CAAA,GApCL,gBAoCK,CApCY,UAoCZ,CAAA,CAAA,GAAA;EAWN;;;;;;EAOgB,QAAA,CAAA,EAAA,IAAA;AASlB,CAAA;;;;;;;AAgBA;;;AAciC,KAzErB,aAyEqB,CAAA,eAzEQ,SAyER,GAzEoB,SAyEpB,CAAA,GAAA,SAxEvB,MAwEuB,EAAA;;;;;;;;;AAGX,KAjEV,mBAiEU,CAAA,eAhEN,SAgEM,GAhEM,SAgEN,EAAA,WAAA,OAAA,CAAA,GAAA;EAAhB;EACH,KAAA,EA7DK,MA6DL;EAJwC;EAAkB,KAAA,EAAA,MAAA;EAcjD;EAEF,MAAA,EA/DD,aA+DC,CA9DR,MA8DQ,SA9DO,gBA8DP,GA9D0B,gBA8D1B,GA9D6C,eA8D7C,CAAA;EAImB;;;;EAOT,OAAA,EAlEV,QAkEU;CAGT;;AAUX;;;;;AAsBC,KA5FW,kBA4FX,CAAA,eA1Fe,SA0Ff,GAAA,GAAA,EAAA,WAAA,OAAA,CAAA,GAxFG,aAwFH,CAxFiB,mBAwFjB,CAxFqC,MAwFrC,EAxF6C,QAwF7C,CAAA,CAAA;AAaD;;;;;;;;;;KAzFY,mCACI,YAAY,iDAaZ,iBAAiB,UAAU,mBACxC,QAAQ,QAAQ,UAAU,4BACvB,YACA,QAAQ,QAAQ,UAAU,aAC7B;;;;;;;KAUS;;WAEF;;eAII,eAAe;;;;;qBAOT,cAAc,yBAAyB;;YAGhD;;;;;;;;;cAUE,oCAAqC;;;SAG1C;MACJ;;;;;;;;;;;;cA+BS,WAAW,GAAG"}
|