@prismicio/react 3.3.0-pr.249.21ed294 → 3.3.0-pr.249.e5e9e21
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/PrismicToolbar.d.ts
CHANGED
|
@@ -10,14 +10,23 @@ type PrismicToolbarProps = {
|
|
|
10
10
|
repositoryName: string;
|
|
11
11
|
/**
|
|
12
12
|
* Called when the Prismic toolbar triggers a preview update. This happens
|
|
13
|
-
* when
|
|
13
|
+
* when the previewed content changes.
|
|
14
|
+
*
|
|
15
|
+
* The callback receives the full `CustomEvent`, giving access to
|
|
16
|
+
* `event.detail.ref` (the preview ref) and `event.preventDefault()` to
|
|
17
|
+
* cancel the toolbar's default reload behavior.
|
|
14
18
|
*/
|
|
15
|
-
onPreviewUpdate?: (
|
|
19
|
+
onPreviewUpdate?: (event: CustomEvent<{
|
|
20
|
+
ref: string;
|
|
21
|
+
}>) => void;
|
|
16
22
|
/**
|
|
17
23
|
* Called when the Prismic toolbar triggers a preview end. This happens when
|
|
18
24
|
* a preview session is closed.
|
|
25
|
+
*
|
|
26
|
+
* The callback receives the full `CustomEvent`, giving access to
|
|
27
|
+
* `event.preventDefault()` to cancel the toolbar's default reload behavior.
|
|
19
28
|
*/
|
|
20
|
-
onPreviewEnd?: () => void
|
|
29
|
+
onPreviewEnd?: (event: CustomEvent<null>) => void;
|
|
21
30
|
};
|
|
22
31
|
/**
|
|
23
32
|
* Renders the Prismic Toolbar script to support draft previews.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicToolbar.d.ts","names":[],"sources":["../src/PrismicToolbar.tsx"],"sourcesContent":[],"mappings":";;;;KAMY,mBAAA;EAAA;
|
|
1
|
+
{"version":3,"file":"PrismicToolbar.d.ts","names":[],"sources":["../src/PrismicToolbar.tsx"],"sourcesContent":[],"mappings":";;;;KAMY,mBAAA;EAAA;AAsCZ;;;;;;;;;;;;4BAvB2B;;;;;;;;;;yBASH;;;;;;;;;;;;;cAcX,gBAAgB,GAAG"}
|
package/dist/PrismicToolbar.js
CHANGED
|
@@ -35,8 +35,8 @@ const PrismicToolbar = (props) => {
|
|
|
35
35
|
}, [repositoryName, src]);
|
|
36
36
|
useEffect(() => {
|
|
37
37
|
const controller = new AbortController();
|
|
38
|
-
window.addEventListener("prismicPreviewUpdate", () => onPreviewUpdateRef.current?.(), { signal: controller.signal });
|
|
39
|
-
window.addEventListener("prismicPreviewEnd", () => onPreviewEndRef.current?.(), { signal: controller.signal });
|
|
38
|
+
window.addEventListener("prismicPreviewUpdate", (event) => onPreviewUpdateRef.current?.(event), { signal: controller.signal });
|
|
39
|
+
window.addEventListener("prismicPreviewEnd", (event) => onPreviewEndRef.current?.(event), { signal: controller.signal });
|
|
40
40
|
return () => controller.abort();
|
|
41
41
|
}, []);
|
|
42
42
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismicToolbar.js","names":[],"sources":["../src/PrismicToolbar.tsx"],"sourcesContent":["\"use client\";\n\nimport { type FC, useEffect, useRef } 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\t/**\n\t * Called when the Prismic toolbar triggers a preview update. This happens\n\t * when
|
|
1
|
+
{"version":3,"file":"PrismicToolbar.js","names":[],"sources":["../src/PrismicToolbar.tsx"],"sourcesContent":["\"use client\";\n\nimport { type FC, useEffect, useRef } 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\t/**\n\t * Called when the Prismic toolbar triggers a preview update. This happens\n\t * when the previewed content changes.\n\t *\n\t * The callback receives the full `CustomEvent`, giving access to\n\t * `event.detail.ref` (the preview ref) and `event.preventDefault()` to\n\t * cancel the toolbar's default reload behavior.\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\n\t * a preview session is closed.\n\t *\n\t * The callback receives the full `CustomEvent`, giving access to\n\t * `event.preventDefault()` to cancel the toolbar's default reload behavior.\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 *\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, onPreviewUpdate, onPreviewEnd } = props;\n\n\tconst src = getToolbarSrc(repositoryName);\n\n\tconst onPreviewUpdateRef = useRef(onPreviewUpdate);\n\tonPreviewUpdateRef.current = onPreviewUpdate;\n\n\tconst onPreviewEndRef = useRef(onPreviewEnd);\n\tonPreviewEndRef.current = onPreviewEnd;\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) =>\n\t\t\t\tonPreviewUpdateRef.current?.(\n\t\t\t\t\tevent as CustomEvent<{ ref: string }>,\n\t\t\t\t),\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) =>\n\t\t\t\tonPreviewEndRef.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":";;;;;;;;;;;;;;;;;AA4CA,MAAa,kBAA2C,UAAU;CACjE,MAAM,EAAE,gBAAgB,iBAAiB,iBAAiB;CAE1D,MAAM,MAAM,cAAc,eAAe;CAEzC,MAAM,qBAAqB,OAAO,gBAAgB;AAClD,oBAAmB,UAAU;CAE7B,MAAM,kBAAkB,OAAO,aAAa;AAC5C,iBAAgB,UAAU;AAE1B,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,iBAAgB;EACf,MAAM,aAAa,IAAI,iBAAiB;AAExC,SAAO,iBACN,yBACC,UACA,mBAAmB,UAClB,MACA,EACF,EAAE,QAAQ,WAAW,QAAQ,CAC7B;AAED,SAAO,iBACN,sBACC,UACA,gBAAgB,UAAU,MAA2B,EACtD,EAAE,QAAQ,WAAW,QAAQ,CAC7B;AAED,eAAa,WAAW,OAAO;IAC7B,EAAE,CAAC;AAEN,QAAO"}
|
package/dist/package.js
CHANGED
package/package.json
CHANGED
package/src/PrismicToolbar.tsx
CHANGED
|
@@ -13,15 +13,22 @@ export type PrismicToolbarProps = {
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Called when the Prismic toolbar triggers a preview update. This happens
|
|
16
|
-
* when
|
|
16
|
+
* when the previewed content changes.
|
|
17
|
+
*
|
|
18
|
+
* The callback receives the full `CustomEvent`, giving access to
|
|
19
|
+
* `event.detail.ref` (the preview ref) and `event.preventDefault()` to
|
|
20
|
+
* cancel the toolbar's default reload behavior.
|
|
17
21
|
*/
|
|
18
|
-
onPreviewUpdate?: () => void
|
|
22
|
+
onPreviewUpdate?: (event: CustomEvent<{ ref: string }>) => void;
|
|
19
23
|
|
|
20
24
|
/**
|
|
21
25
|
* Called when the Prismic toolbar triggers a preview end. This happens when
|
|
22
26
|
* a preview session is closed.
|
|
27
|
+
*
|
|
28
|
+
* The callback receives the full `CustomEvent`, giving access to
|
|
29
|
+
* `event.preventDefault()` to cancel the toolbar's default reload behavior.
|
|
23
30
|
*/
|
|
24
|
-
onPreviewEnd?: () => void
|
|
31
|
+
onPreviewEnd?: (event: CustomEvent<null>) => void;
|
|
25
32
|
};
|
|
26
33
|
|
|
27
34
|
/**
|
|
@@ -71,13 +78,17 @@ export const PrismicToolbar: FC<PrismicToolbarProps> = (props) => {
|
|
|
71
78
|
|
|
72
79
|
window.addEventListener(
|
|
73
80
|
"prismicPreviewUpdate",
|
|
74
|
-
() =>
|
|
81
|
+
(event) =>
|
|
82
|
+
onPreviewUpdateRef.current?.(
|
|
83
|
+
event as CustomEvent<{ ref: string }>,
|
|
84
|
+
),
|
|
75
85
|
{ signal: controller.signal },
|
|
76
86
|
);
|
|
77
87
|
|
|
78
88
|
window.addEventListener(
|
|
79
89
|
"prismicPreviewEnd",
|
|
80
|
-
() =>
|
|
90
|
+
(event) =>
|
|
91
|
+
onPreviewEndRef.current?.(event as CustomEvent<null>),
|
|
81
92
|
{ signal: controller.signal },
|
|
82
93
|
);
|
|
83
94
|
|