@decocms/blocks 8.3.0 → 8.4.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/v8/draft.d.ts +2 -0
- package/dist/v8/draft.d.ts.map +1 -1
- package/dist/v8/draft.js +2 -1
- package/dist/v8/draft.js.map +1 -1
- package/dist/v8/preview/DraftBadge.d.ts +52 -0
- package/dist/v8/preview/DraftBadge.d.ts.map +1 -0
- package/dist/v8/preview/DraftBadge.js +167 -0
- package/dist/v8/preview/DraftBadge.js.map +1 -0
- package/dist/v8/preview/StudioBridge.d.ts +78 -0
- package/dist/v8/preview/StudioBridge.d.ts.map +1 -0
- package/dist/v8/preview/StudioBridge.js +137 -0
- package/dist/v8/preview/StudioBridge.js.map +1 -0
- package/dist/v8/preview/decoMark.d.ts +7 -0
- package/dist/v8/preview/decoMark.d.ts.map +1 -0
- package/dist/v8/preview/decoMark.js +7 -0
- package/dist/v8/preview/decoMark.js.map +1 -0
- package/dist/v8/preview/index.d.ts +14 -0
- package/dist/v8/preview/index.d.ts.map +1 -0
- package/dist/v8/preview/index.js +14 -0
- package/dist/v8/preview/index.js.map +1 -0
- package/package.json +6 -1
- package/src/v8/draft.ts +2 -1
- package/src/v8/preview/DraftBadge.tsx +278 -0
- package/src/v8/preview/StudioBridge.ts +183 -0
- package/src/v8/preview/decoMark.ts +7 -0
- package/src/v8/preview/index.ts +18 -0
package/dist/v8/draft.d.ts
CHANGED
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
* parser lifts them out of `path` into `variants`.
|
|
11
11
|
*/
|
|
12
12
|
import type { DraftPointer, RequestLike } from "./types.ts";
|
|
13
|
+
/** The draft link's query parameter. Shared with `./preview` (the badge's links); not exported from the package. */
|
|
14
|
+
export declare const DRAFT_PARAM = "__draft";
|
|
13
15
|
/**
|
|
14
16
|
* Parses a pointer, strictly: `null` on a scheme, a stray `@`, an unrooted
|
|
15
17
|
* path, an odd character in the host or version, or a port out of range. The
|
package/dist/v8/draft.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"draft.d.ts","sourceRoot":"","sources":["../../src/v8/draft.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,YAAY,EAAiB,WAAW,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"draft.d.ts","sourceRoot":"","sources":["../../src/v8/draft.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,YAAY,EAAiB,WAAW,EAAE,MAAM,YAAY,CAAC;AAK3E,oHAAoH;AACpH,eAAO,MAAM,WAAW,YAAY,CAAC;AAarC;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,YAAY,GAAG,IAAI,CAoBrF;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,CAiBhE;AA8ED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,GAAG,IAAI,CAMpE;AAED;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,MAAM,GAAG,IAAI,CAMlE;AAED,wGAAwG;AACxG,wBAAgB,WAAW,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAEzD"}
|
package/dist/v8/draft.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** The draft cookie's name. Not exported from the package: reading it directly would skip the host check. */
|
|
2
2
|
const DRAFT_COOKIE = "__deco_draft";
|
|
3
|
-
|
|
3
|
+
/** The draft link's query parameter. Shared with `./preview` (the badge's links); not exported from the package. */
|
|
4
|
+
export const DRAFT_PARAM = "__draft";
|
|
4
5
|
const DRAFT_OFF = "off";
|
|
5
6
|
/** Lowercase DNS name; a single label (`localhost`) is allowed. */
|
|
6
7
|
const HOST_RE = /^[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/;
|
package/dist/v8/draft.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"draft.js","sourceRoot":"","sources":["../../src/v8/draft.ts"],"names":[],"mappings":"AAaA,6GAA6G;AAC7G,MAAM,YAAY,GAAG,cAAc,CAAC;AAEpC,MAAM,WAAW,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"draft.js","sourceRoot":"","sources":["../../src/v8/draft.ts"],"names":[],"mappings":"AAaA,6GAA6G;AAC7G,MAAM,YAAY,GAAG,cAAc,CAAC;AAEpC,oHAAoH;AACpH,MAAM,CAAC,MAAM,WAAW,GAAG,SAAS,CAAC;AACrC,MAAM,SAAS,GAAG,KAAK,CAAC;AAExB,mEAAmE;AACnE,MAAM,OAAO,GAAG,mEAAmE,CAAC;AACpF,MAAM,OAAO,GAAG,cAAc,CAAC;AAC/B,MAAM,UAAU,GAAG,wBAAwB,CAAC;AAC5C,wFAAwF;AACxF,MAAM,OAAO,GAAG,2BAA2B,CAAC;AAC5C,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAChC,MAAM,aAAa,GAAG,YAAY,CAAC;AACnC,MAAM,QAAQ,GAAG,uBAAuB,CAAC;AAEzC;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,GAA8B;IAC9D,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,IAAI,GAAG,CAAC,MAAM,GAAG,kBAAkB;QAAE,OAAO,IAAI,CAAC;IAChG,MAAM,EAAE,GAAG,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAChC,IAAI,EAAE,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IACzB,MAAM,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IAClC,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C,IAAI,CAAC,CAAC;AACf,CAAC;AAED,SAAS,UAAU,CAAC,OAAoB;IACtC,IAAI,CAAC;QACH,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,kBAAkB,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAChF,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED,SAAS,UAAU,CAAC,MAAqB,EAAE,IAAY;IACrD,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QACrC,MAAM,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC7B,IAAI,EAAE,KAAK,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,IAAI;YAAE,SAAS;QAC7D,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACxC,IAAI,CAAC;YACH,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC;QACnC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The "Preview mode" badge: v7's `DraftPreviewBadge`, unchanged on screen.
|
|
3
|
+
*
|
|
4
|
+
* A draft preview keeps its pointer in a cookie, so after the first click the
|
|
5
|
+
* URL no longer shows `?__draft=` and a reviewer can mistake the draft for the
|
|
6
|
+
* live site. While a draft is bound, this badge floats over the page; clicking
|
|
7
|
+
* it offers the two things a reviewer needs: leave the preview, or copy a link
|
|
8
|
+
* to this exact draft version.
|
|
9
|
+
*
|
|
10
|
+
* - Renders nothing without a `pointer`, so a binding can mount it on every
|
|
11
|
+
* page and pass the request's draft pointer (or `null`).
|
|
12
|
+
* - Hidden inside a frame: Studio's site editor shows the draft in an iframe
|
|
13
|
+
* with its own chrome. A reviewer who opens a shared link in their own tab
|
|
14
|
+
* still sees it.
|
|
15
|
+
* - Starts hidden on the server and on the first client render, and shows only
|
|
16
|
+
* after an effect confirms the page isn't framed. Rendering it and hiding it
|
|
17
|
+
* later would flash it inside Studio and break hydration (the server has no
|
|
18
|
+
* `window`).
|
|
19
|
+
* - Inline styles and an inlined mark: no dependency on the site's CSS or
|
|
20
|
+
* assets.
|
|
21
|
+
*
|
|
22
|
+
* `"use client"`: it has state and effects. In Next.js a Server Component can
|
|
23
|
+
* render it directly.
|
|
24
|
+
*/
|
|
25
|
+
import { type ReactNode } from "react";
|
|
26
|
+
export interface DraftBadgeProps {
|
|
27
|
+
/**
|
|
28
|
+
* The draft pointer this page was rendered from (`cms.draftPointer`). The
|
|
29
|
+
* badge renders nothing when it's `null`, `undefined` or empty.
|
|
30
|
+
*/
|
|
31
|
+
pointer: string | null | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* Where "Exit preview" goes. Defaults to the current URL with
|
|
34
|
+
* `?__draft=off`, which clears the draft cookie.
|
|
35
|
+
*/
|
|
36
|
+
exitHref?: string;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The link "Share preview" copies: the current URL with `?__draft=<pointer>`,
|
|
40
|
+
* so the recipient sees this exact draft version.
|
|
41
|
+
*/
|
|
42
|
+
export declare function buildShareUrl(href: string, pointer: string): string;
|
|
43
|
+
/** The current URL with `?__draft=off`: ends the preview and shows the published page. */
|
|
44
|
+
export declare function buildExitUrl(href: string): string;
|
|
45
|
+
/**
|
|
46
|
+
* Whether the page is in another page's frame (Studio's site editor). A
|
|
47
|
+
* reference comparison, so it never throws across origins. No `window` (the
|
|
48
|
+
* server) reads as not framed.
|
|
49
|
+
*/
|
|
50
|
+
export declare function isFramed(win?: typeof window | undefined): boolean;
|
|
51
|
+
export declare function DraftBadge({ pointer, exitHref }: DraftBadgeProps): ReactNode;
|
|
52
|
+
//# sourceMappingURL=DraftBadge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DraftBadge.d.ts","sourceRoot":"","sources":["../../../src/v8/preview/DraftBadge.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAE,KAAK,SAAS,EAA4C,MAAM,OAAO,CAAC;AAIjF,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IACnC;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAInE;AAED,0FAA0F;AAC1F,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAIjD;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,GAAG,GAAE,OAAO,MAAM,GAAG,SAA6B,GAAG,OAAO,CAEpF;AAiDD,wBAAgB,UAAU,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,eAAe,GAAG,SAAS,CAwH5E"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* The "Preview mode" badge: v7's `DraftPreviewBadge`, unchanged on screen.
|
|
5
|
+
*
|
|
6
|
+
* A draft preview keeps its pointer in a cookie, so after the first click the
|
|
7
|
+
* URL no longer shows `?__draft=` and a reviewer can mistake the draft for the
|
|
8
|
+
* live site. While a draft is bound, this badge floats over the page; clicking
|
|
9
|
+
* it offers the two things a reviewer needs: leave the preview, or copy a link
|
|
10
|
+
* to this exact draft version.
|
|
11
|
+
*
|
|
12
|
+
* - Renders nothing without a `pointer`, so a binding can mount it on every
|
|
13
|
+
* page and pass the request's draft pointer (or `null`).
|
|
14
|
+
* - Hidden inside a frame: Studio's site editor shows the draft in an iframe
|
|
15
|
+
* with its own chrome. A reviewer who opens a shared link in their own tab
|
|
16
|
+
* still sees it.
|
|
17
|
+
* - Starts hidden on the server and on the first client render, and shows only
|
|
18
|
+
* after an effect confirms the page isn't framed. Rendering it and hiding it
|
|
19
|
+
* later would flash it inside Studio and break hydration (the server has no
|
|
20
|
+
* `window`).
|
|
21
|
+
* - Inline styles and an inlined mark: no dependency on the site's CSS or
|
|
22
|
+
* assets.
|
|
23
|
+
*
|
|
24
|
+
* `"use client"`: it has state and effects. In Next.js a Server Component can
|
|
25
|
+
* render it directly.
|
|
26
|
+
*/
|
|
27
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
28
|
+
import { DRAFT_PARAM } from "../draft.js";
|
|
29
|
+
import { DECO_MARK_DATA_URI } from "./decoMark.js";
|
|
30
|
+
/**
|
|
31
|
+
* The link "Share preview" copies: the current URL with `?__draft=<pointer>`,
|
|
32
|
+
* so the recipient sees this exact draft version.
|
|
33
|
+
*/
|
|
34
|
+
export function buildShareUrl(href, pointer) {
|
|
35
|
+
const url = new URL(href);
|
|
36
|
+
url.searchParams.set(DRAFT_PARAM, pointer);
|
|
37
|
+
return url.toString();
|
|
38
|
+
}
|
|
39
|
+
/** The current URL with `?__draft=off`: ends the preview and shows the published page. */
|
|
40
|
+
export function buildExitUrl(href) {
|
|
41
|
+
const url = new URL(href);
|
|
42
|
+
url.searchParams.set(DRAFT_PARAM, "off");
|
|
43
|
+
return url.toString();
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Whether the page is in another page's frame (Studio's site editor). A
|
|
47
|
+
* reference comparison, so it never throws across origins. No `window` (the
|
|
48
|
+
* server) reads as not framed.
|
|
49
|
+
*/
|
|
50
|
+
export function isFramed(win = globalThis.window) {
|
|
51
|
+
return typeof win !== "undefined" && win.top !== win;
|
|
52
|
+
}
|
|
53
|
+
const DECO_GREEN = "#0b3d1e";
|
|
54
|
+
/** The badge background, Deco lime; text sits on it in dark green. */
|
|
55
|
+
const DECO_LIME = "#d0ec1a";
|
|
56
|
+
/** Leaving preview: an arrow back to the published site. */
|
|
57
|
+
function ExitIcon() {
|
|
58
|
+
return (_jsxs("svg", { width: 14, height: 14, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("path", { d: "M19 12H5" }), _jsx("path", { d: "M12 19l-7-7 7-7" })] }));
|
|
59
|
+
}
|
|
60
|
+
/** Sharing the draft: the three-node share glyph. */
|
|
61
|
+
function ShareIcon() {
|
|
62
|
+
return (_jsxs("svg", { width: 14, height: 14, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("circle", { cx: 18, cy: 5, r: 3 }), _jsx("circle", { cx: 6, cy: 12, r: 3 }), _jsx("circle", { cx: 18, cy: 19, r: 3 }), _jsx("path", { d: "M8.59 13.51l6.83 3.98" }), _jsx("path", { d: "M15.41 6.51l-6.82 3.98" })] }));
|
|
63
|
+
}
|
|
64
|
+
export function DraftBadge({ pointer, exitHref }) {
|
|
65
|
+
const [open, setOpen] = useState(false);
|
|
66
|
+
const [copied, setCopied] = useState(false);
|
|
67
|
+
const [visible, setVisible] = useState(false);
|
|
68
|
+
const rootRef = useRef(null);
|
|
69
|
+
// The only place isFramed() runs: after mount, so the server render and the
|
|
70
|
+
// first client render agree (both hidden).
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (!isFramed())
|
|
73
|
+
setVisible(true);
|
|
74
|
+
}, []);
|
|
75
|
+
// Close the menu on an outside click or Escape.
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (!open)
|
|
78
|
+
return;
|
|
79
|
+
const onPointerDown = (e) => {
|
|
80
|
+
if (rootRef.current && !rootRef.current.contains(e.target))
|
|
81
|
+
setOpen(false);
|
|
82
|
+
};
|
|
83
|
+
const onKeyDown = (e) => {
|
|
84
|
+
if (e.key === "Escape")
|
|
85
|
+
setOpen(false);
|
|
86
|
+
};
|
|
87
|
+
document.addEventListener("mousedown", onPointerDown);
|
|
88
|
+
document.addEventListener("keydown", onKeyDown);
|
|
89
|
+
return () => {
|
|
90
|
+
document.removeEventListener("mousedown", onPointerDown);
|
|
91
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
92
|
+
};
|
|
93
|
+
}, [open]);
|
|
94
|
+
const exitPreview = useCallback(() => {
|
|
95
|
+
window.location.href = exitHref ?? buildExitUrl(window.location.href);
|
|
96
|
+
}, [exitHref]);
|
|
97
|
+
const sharePreviewLink = useCallback(async () => {
|
|
98
|
+
if (!pointer)
|
|
99
|
+
return;
|
|
100
|
+
const link = buildShareUrl(window.location.href, pointer);
|
|
101
|
+
try {
|
|
102
|
+
await navigator.clipboard.writeText(link);
|
|
103
|
+
setCopied(true);
|
|
104
|
+
window.setTimeout(() => setCopied(false), 2000);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
// No clipboard (an insecure context, a denied permission): let the
|
|
108
|
+
// reviewer copy the link by hand.
|
|
109
|
+
window.prompt("Copy preview link:", link);
|
|
110
|
+
}
|
|
111
|
+
}, [pointer]);
|
|
112
|
+
if (!pointer || !visible)
|
|
113
|
+
return null;
|
|
114
|
+
return (_jsxs("div", { ref: rootRef, "data-deco-preview-badge": "", style: {
|
|
115
|
+
position: "fixed",
|
|
116
|
+
bottom: 16,
|
|
117
|
+
left: 16,
|
|
118
|
+
zIndex: 2147483647,
|
|
119
|
+
fontFamily: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif",
|
|
120
|
+
fontSize: 13,
|
|
121
|
+
lineHeight: 1.4,
|
|
122
|
+
}, children: [open ? (_jsxs("div", { role: "menu", style: {
|
|
123
|
+
position: "absolute",
|
|
124
|
+
bottom: "calc(100% + 8px)",
|
|
125
|
+
left: 0,
|
|
126
|
+
minWidth: 200,
|
|
127
|
+
background: "#fff",
|
|
128
|
+
color: "#1a1a1a",
|
|
129
|
+
borderRadius: 12,
|
|
130
|
+
boxShadow: "0 8px 30px rgba(0,0,0,0.18), 0 0 0 1px rgba(0,0,0,0.05)",
|
|
131
|
+
overflow: "hidden",
|
|
132
|
+
}, children: [_jsx(MenuItem, { onClick: exitPreview, label: "Exit preview", icon: _jsx(ExitIcon, {}) }), _jsx("div", { style: { height: 1, background: "rgba(0,0,0,0.07)" } }), _jsx(MenuItem, { onClick: sharePreviewLink, label: copied ? "Copied!" : "Share preview", icon: _jsx(ShareIcon, {}) })] })) : null, _jsxs("button", { type: "button", "aria-expanded": open, "aria-label": "Preview mode", onClick: () => setOpen((v) => !v), style: {
|
|
133
|
+
display: "inline-flex",
|
|
134
|
+
alignItems: "center",
|
|
135
|
+
gap: 8,
|
|
136
|
+
padding: "7px 12px 7px 8px",
|
|
137
|
+
background: DECO_LIME,
|
|
138
|
+
color: DECO_GREEN,
|
|
139
|
+
border: "none",
|
|
140
|
+
borderRadius: 9999,
|
|
141
|
+
cursor: "pointer",
|
|
142
|
+
fontSize: 13,
|
|
143
|
+
fontWeight: 600,
|
|
144
|
+
boxShadow: "0 4px 14px rgba(0,0,0,0.25)",
|
|
145
|
+
}, children: [_jsx("img", { src: DECO_MARK_DATA_URI, alt: "", width: 18, height: 18, style: { display: "block", borderRadius: 4 } }), _jsx("span", { children: "Preview mode" })] })] }));
|
|
146
|
+
}
|
|
147
|
+
function MenuItem({ onClick, label, icon, }) {
|
|
148
|
+
return (_jsxs("button", { type: "button", role: "menuitem", onClick: onClick, style: {
|
|
149
|
+
display: "flex",
|
|
150
|
+
alignItems: "center",
|
|
151
|
+
gap: 10,
|
|
152
|
+
width: "100%",
|
|
153
|
+
textAlign: "left",
|
|
154
|
+
padding: "10px 14px",
|
|
155
|
+
background: "transparent",
|
|
156
|
+
border: "none",
|
|
157
|
+
color: "inherit",
|
|
158
|
+
cursor: "pointer",
|
|
159
|
+
fontSize: 13,
|
|
160
|
+
whiteSpace: "nowrap",
|
|
161
|
+
}, onMouseEnter: (e) => {
|
|
162
|
+
e.currentTarget.style.background = "rgba(0,0,0,0.05)";
|
|
163
|
+
}, onMouseLeave: (e) => {
|
|
164
|
+
e.currentTarget.style.background = "transparent";
|
|
165
|
+
}, children: [_jsx("span", { style: { display: "inline-flex", flexShrink: 0, color: DECO_GREEN }, children: icon }), _jsx("span", { children: label })] }));
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=DraftBadge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DraftBadge.js","sourceRoot":"","sources":["../../../src/v8/preview/DraftBadge.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,OAAO,EAAkB,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACjF,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAenD;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,OAAe;IACzD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC;IAC1B,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAC3C,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;AACxB,CAAC;AAED,0FAA0F;AAC1F,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC;IAC1B,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,C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AAC,EAAE,EACN,KAAK,EAAE,EAAE,EACT,MAAM,EAAE,EAAE,EACV,KAAK,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,EAAE,GAC5C,EACF,0CAAyB,IAClB,IACL,CACP,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,EAChB,OAAO,EACP,KAAK,EACL,IAAI,GAKL;IACC,OAAO,CACL,kBACE,IAAI,EAAC,QAAQ,EACb,IAAI,EAAC,UAAU,EACf,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE;YACL,OAAO,EAAE,MAAM;YACf,UAAU,EAAE,QAAQ;YACpB,GAAG,EAAE,EAAE;YACP,KAAK,EAAE,MAAM;YACb,SAAS,EAAE,MAAM;YACjB,OAAO,EAAE,WAAW;YACpB,UAAU,EAAE,aAAa;YACzB,MAAM,EAAE,MAAM;YACd,KAAK,EAAE,SAAS;YAChB,MAAM,EAAE,SAAS;YACjB,QAAQ,EAAE,EAAE;YACZ,UAAU,EAAE,QAAQ;SACrB,EACD,YAAY,EAAE,CAAC,CAAC,EAAE,EAAE;YAClB,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,UAAU,GAAG,kBAAkB,CAAC;QACxD,CAAC,EACD,YAAY,EAAE,CAAC,CAAC,EAAE,EAAE;YAClB,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,UAAU,GAAG,aAAa,CAAC;QACnD,CAAC,aAED,eAAM,KAAK,EAAE,EAAE,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,YAAG,IAAI,GAAQ,EACxF,yBAAO,KAAK,GAAQ,IACb,CACV,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Studio bridge: what lets Deco Studio's site editor drive a page it
|
|
3
|
+
* shows in an iframe (v7's `LiveControls`).
|
|
4
|
+
*
|
|
5
|
+
* When the frame loads, Studio posts `{ type: "editor::inject", args: {
|
|
6
|
+
* script } }` to it; the bridge runs that script, which draws the section
|
|
7
|
+
* overlay and handles Studio's `cms-editor::*` messages itself. The bridge also
|
|
8
|
+
* answers v7's `scrollToComponent` and `editor::rerender` (same-origin
|
|
9
|
+
* navigation only).
|
|
10
|
+
*
|
|
11
|
+
* In a frame it answers only messages from the parent window whose origin is
|
|
12
|
+
* one of `trustedOrigins`. On a page that isn't framed it answers no message;
|
|
13
|
+
* there it only listens for the "." shortcut (`editShortcut`), which opens the
|
|
14
|
+
* page in Studio's editor, as v7's `LiveControls` did. Studio signs the editor
|
|
15
|
+
* in: `/choose-editor` sends a visitor who isn't signed in to Studio's login
|
|
16
|
+
* and back.
|
|
17
|
+
* The binding passes Studio's origins in (`@decocms/blocks` holds no list of
|
|
18
|
+
* them); with none, the bridge answers nothing. It doesn't trust the page's own
|
|
19
|
+
* origin: under a test runner that proxies the site, the runner's own messages
|
|
20
|
+
* would navigate the page.
|
|
21
|
+
*
|
|
22
|
+
* An inline script, not an effect: Studio posts on the frame's `load` event,
|
|
23
|
+
* which can come before React hydrates, so the listener must exist as soon as
|
|
24
|
+
* the HTML is parsed. No hooks, so it renders from a Next.js Server Component
|
|
25
|
+
* as well as from a client tree. Its settings travel in `data-*` attributes;
|
|
26
|
+
* the script itself is static.
|
|
27
|
+
*/
|
|
28
|
+
import { type ReactNode } from "react";
|
|
29
|
+
export interface StudioBridgeProps {
|
|
30
|
+
/** The site's name in Deco (the "." shortcut sends it to Studio). */
|
|
31
|
+
site: string;
|
|
32
|
+
/**
|
|
33
|
+
* The origins Studio's site editor frames the page from, in the CSP source
|
|
34
|
+
* form (`https://host`, or `https://*.host` for any name under it, same
|
|
35
|
+
* scheme and port). Required: the binding owns Studio's origins and passes
|
|
36
|
+
* them here. An empty list makes the bridge answer nothing.
|
|
37
|
+
*/
|
|
38
|
+
trustedOrigins: readonly string[];
|
|
39
|
+
/**
|
|
40
|
+
* v7's editor shortcut: on a page that isn't framed, "." (or Ctrl+Shift+E)
|
|
41
|
+
* opens it in Studio, and Ctrl or Cmd+"." opens it in a new tab. On by
|
|
42
|
+
* default, as in v7; `false` turns it off.
|
|
43
|
+
*/
|
|
44
|
+
editShortcut?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* The page being shown, when the layout that renders the bridge knows it:
|
|
47
|
+
* the "." shortcut sends its path template (and id), so Studio opens that
|
|
48
|
+
* page rather than guessing from the URL. A page can declare itself instead
|
|
49
|
+
* with `StudioPage` (for a layout that doesn't re-render per page, such as a
|
|
50
|
+
* Next.js root layout); a `StudioPage` on the page wins.
|
|
51
|
+
*/
|
|
52
|
+
page?: StudioPageInfo;
|
|
53
|
+
/** The CSP nonce for the inline script, when the site sends one. */
|
|
54
|
+
nonce?: string;
|
|
55
|
+
}
|
|
56
|
+
/** The page the "." shortcut opens in Studio. */
|
|
57
|
+
export interface StudioPageInfo {
|
|
58
|
+
/** The page block's `path`, as `matchRoute` matched it (`/products/:slug/p`, `/*`). */
|
|
59
|
+
pathTemplate?: string;
|
|
60
|
+
/** The page block's id, when the site knows it. */
|
|
61
|
+
id?: string;
|
|
62
|
+
}
|
|
63
|
+
/** The browser side. Static: everything it needs comes from the script element's attributes. */
|
|
64
|
+
export declare const STUDIO_BRIDGE_SCRIPT = "(function(){\nvar s=document.currentScript;\nif(!s||window.__decoStudioBridge)return;\nwindow.__decoStudioBridge=true;\nvar origins=[];\ntry{origins=JSON.parse(s.getAttribute(\"data-origins\")||\"[]\")}catch(e){}\nvar site=s.getAttribute(\"data-site\")||\"\";\nfunction page(){\n var all=document.querySelectorAll(\"[data-deco-page]\"),el=all.length?all[all.length-1]:null;\n if(!el||!el.getAttribute(\"data-path-template\")){el=document.querySelector(\"script[data-deco-studio-bridge]\")||s}\n return{t:el.getAttribute(\"data-path-template\")||\"\",id:el.getAttribute(\"data-page-id\")||\"\"};\n}\nfunction trusted(o){\n if(typeof o!==\"string\"||!o)return false;\n var u;\n try{u=new URL(o)}catch(e){return false}\n if(u.origin!==o)return false;\n for(var i=0;i<origins.length;i++){\n var p=origins[i];\n if(p===o)return true;\n var m=/^([a-z][a-z0-9+.-]*:)\\/\\/\\*\\.([^\\/:]+)(?::([0-9]+))?$/.exec(p);\n if(m&&u.protocol===m[1]&&u.port===(m[3]||\"\")&&u.hostname.slice(-m[2].length-1)===\".\"+m[2])return true;\n }\n return false;\n}\nif(window.self!==window.top){\n window.addEventListener(\"message\",function(e){\n if(e.source!==window.parent||!trusted(e.origin))return;\n var d=e.data;\n if(!d||typeof d!==\"object\")return;\n var a=d.args||{};\n if(d.type===\"editor::inject\"){\n if(typeof a.script===\"string\"){try{(0,eval)(a.script)}catch(err){console.error(\"[deco] Studio script failed:\",err)}}\n }else if(d.type===\"scrollToComponent\"){\n var id=typeof a.id===\"string\"?a.id:\"\";\n if(!id)return;\n var el=null,all=document.querySelectorAll(\"[data-manifest-key]\");\n for(var i=0;i<all.length&&!el;i++)if(all[i].getAttribute(\"data-manifest-key\")===id)el=all[i];\n el=el||document.getElementById(id);\n if(el)el.scrollIntoView({behavior:\"smooth\",block:\"center\"});\n }else if(d.type===\"editor::rerender\"){\n if(typeof a.url!==\"string\")return;\n try{var t=new URL(a.url,location.origin);if(t.origin===location.origin)location.href=t.href}catch(err){}\n }\n });\n}else if(s.hasAttribute(\"data-shortcut\")){\n document.addEventListener(\"keydown\",function(e){\n var t=e.target;\n if(e.defaultPrevented||(t&&(t.tagName===\"INPUT\"||t.tagName===\"TEXTAREA\"||t.tagName===\"SELECT\"||t.isContentEditable)))return;\n if(e.key!==\".\"&&!(e.ctrlKey&&e.shiftKey&&e.key===\"E\"))return;\n e.preventDefault();\n e.stopPropagation();\n var p=page(),h=new URL(\"https://studio.decocms.com/choose-editor\");\n h.searchParams.set(\"site\",site);\n h.searchParams.set(\"domain\",location.origin);\n if(p.id)h.searchParams.set(\"pageId\",p.id);\n h.searchParams.set(\"path\",location.pathname+location.search);\n h.searchParams.set(\"pathTemplate\",p.t||\"/*\");\n if((e.ctrlKey||e.metaKey)&&e.key===\".\"){window.open(h.toString(),\"_blank\");return}\n location.href=h.toString();\n });\n}\n})();";
|
|
65
|
+
/**
|
|
66
|
+
* Lets Studio's site editor select and edit sections on the page. Render it
|
|
67
|
+
* once, in the root layout's `<body>`.
|
|
68
|
+
*/
|
|
69
|
+
export declare function StudioBridge({ site, trustedOrigins, editShortcut, page, nonce, }: StudioBridgeProps): ReactNode;
|
|
70
|
+
/**
|
|
71
|
+
* Tells the bridge which page is on screen: render it inside the page (not a
|
|
72
|
+
* layout that stays across navigations), with the page block's `path` as
|
|
73
|
+
* `matchRoute` matched it. A `<meta>`, which React places in the document's
|
|
74
|
+
* `<head>` wherever the page renders it, so it adds nothing to the page's own
|
|
75
|
+
* markup; the "." shortcut reads the last one when the key is pressed.
|
|
76
|
+
*/
|
|
77
|
+
export declare function StudioPage({ pathTemplate, id }: StudioPageInfo): ReactNode;
|
|
78
|
+
//# sourceMappingURL=StudioBridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StudioBridge.d.ts","sourceRoot":"","sources":["../../../src/v8/preview/StudioBridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,EAAiB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEtD,MAAM,WAAW,iBAAiB;IAChC,qEAAqE;IACrE,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC;;;;OAIG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,cAAc,CAAC;IACtB,oEAAoE;IACpE,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,iDAAiD;AACjD,MAAM,WAAW,cAAc;IAC7B,uFAAuF;IACvF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mDAAmD;IACnD,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAUD,gGAAgG;AAChG,eAAO,MAAM,oBAAoB,s4FA8D3B,CAAC;AAEP;;;GAGG;AACH,wBAAgB,YAAY,CAAC,EAC3B,IAAI,EACJ,cAAc,EACd,YAAmB,EACnB,IAAI,EACJ,KAAK,GACN,EAAE,iBAAiB,GAAG,SAAS,CAgB/B;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,EAAE,cAAc,GAAG,SAAS,CAS1E"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Studio bridge: what lets Deco Studio's site editor drive a page it
|
|
3
|
+
* shows in an iframe (v7's `LiveControls`).
|
|
4
|
+
*
|
|
5
|
+
* When the frame loads, Studio posts `{ type: "editor::inject", args: {
|
|
6
|
+
* script } }` to it; the bridge runs that script, which draws the section
|
|
7
|
+
* overlay and handles Studio's `cms-editor::*` messages itself. The bridge also
|
|
8
|
+
* answers v7's `scrollToComponent` and `editor::rerender` (same-origin
|
|
9
|
+
* navigation only).
|
|
10
|
+
*
|
|
11
|
+
* In a frame it answers only messages from the parent window whose origin is
|
|
12
|
+
* one of `trustedOrigins`. On a page that isn't framed it answers no message;
|
|
13
|
+
* there it only listens for the "." shortcut (`editShortcut`), which opens the
|
|
14
|
+
* page in Studio's editor, as v7's `LiveControls` did. Studio signs the editor
|
|
15
|
+
* in: `/choose-editor` sends a visitor who isn't signed in to Studio's login
|
|
16
|
+
* and back.
|
|
17
|
+
* The binding passes Studio's origins in (`@decocms/blocks` holds no list of
|
|
18
|
+
* them); with none, the bridge answers nothing. It doesn't trust the page's own
|
|
19
|
+
* origin: under a test runner that proxies the site, the runner's own messages
|
|
20
|
+
* would navigate the page.
|
|
21
|
+
*
|
|
22
|
+
* An inline script, not an effect: Studio posts on the frame's `load` event,
|
|
23
|
+
* which can come before React hydrates, so the listener must exist as soon as
|
|
24
|
+
* the HTML is parsed. No hooks, so it renders from a Next.js Server Component
|
|
25
|
+
* as well as from a client tree. Its settings travel in `data-*` attributes;
|
|
26
|
+
* the script itself is static.
|
|
27
|
+
*/
|
|
28
|
+
import { createElement } from "react";
|
|
29
|
+
/** The marker a page renders to tell the bridge which page it is (read on each keypress). */
|
|
30
|
+
const PAGE_MARKER = "data-deco-page";
|
|
31
|
+
/** Where the "." shortcut sends an editor; Studio picks the project the site belongs to. */
|
|
32
|
+
const CHOOSE_EDITOR_URL = "https://studio.decocms.com/choose-editor";
|
|
33
|
+
const GLOBAL = "__decoStudioBridge";
|
|
34
|
+
/** The browser side. Static: everything it needs comes from the script element's attributes. */
|
|
35
|
+
export const STUDIO_BRIDGE_SCRIPT = `(function(){
|
|
36
|
+
var s=document.currentScript;
|
|
37
|
+
if(!s||window.${GLOBAL})return;
|
|
38
|
+
window.${GLOBAL}=true;
|
|
39
|
+
var origins=[];
|
|
40
|
+
try{origins=JSON.parse(s.getAttribute("data-origins")||"[]")}catch(e){}
|
|
41
|
+
var site=s.getAttribute("data-site")||"";
|
|
42
|
+
function page(){
|
|
43
|
+
var all=document.querySelectorAll("[${PAGE_MARKER}]"),el=all.length?all[all.length-1]:null;
|
|
44
|
+
if(!el||!el.getAttribute("data-path-template")){el=document.querySelector("script[data-deco-studio-bridge]")||s}
|
|
45
|
+
return{t:el.getAttribute("data-path-template")||"",id:el.getAttribute("data-page-id")||""};
|
|
46
|
+
}
|
|
47
|
+
function trusted(o){
|
|
48
|
+
if(typeof o!=="string"||!o)return false;
|
|
49
|
+
var u;
|
|
50
|
+
try{u=new URL(o)}catch(e){return false}
|
|
51
|
+
if(u.origin!==o)return false;
|
|
52
|
+
for(var i=0;i<origins.length;i++){
|
|
53
|
+
var p=origins[i];
|
|
54
|
+
if(p===o)return true;
|
|
55
|
+
var m=/^([a-z][a-z0-9+.-]*:)\\/\\/\\*\\.([^\\/:]+)(?::([0-9]+))?$/.exec(p);
|
|
56
|
+
if(m&&u.protocol===m[1]&&u.port===(m[3]||"")&&u.hostname.slice(-m[2].length-1)==="."+m[2])return true;
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
if(window.self!==window.top){
|
|
61
|
+
window.addEventListener("message",function(e){
|
|
62
|
+
if(e.source!==window.parent||!trusted(e.origin))return;
|
|
63
|
+
var d=e.data;
|
|
64
|
+
if(!d||typeof d!=="object")return;
|
|
65
|
+
var a=d.args||{};
|
|
66
|
+
if(d.type==="editor::inject"){
|
|
67
|
+
if(typeof a.script==="string"){try{(0,eval)(a.script)}catch(err){console.error("[deco] Studio script failed:",err)}}
|
|
68
|
+
}else if(d.type==="scrollToComponent"){
|
|
69
|
+
var id=typeof a.id==="string"?a.id:"";
|
|
70
|
+
if(!id)return;
|
|
71
|
+
var el=null,all=document.querySelectorAll("[data-manifest-key]");
|
|
72
|
+
for(var i=0;i<all.length&&!el;i++)if(all[i].getAttribute("data-manifest-key")===id)el=all[i];
|
|
73
|
+
el=el||document.getElementById(id);
|
|
74
|
+
if(el)el.scrollIntoView({behavior:"smooth",block:"center"});
|
|
75
|
+
}else if(d.type==="editor::rerender"){
|
|
76
|
+
if(typeof a.url!=="string")return;
|
|
77
|
+
try{var t=new URL(a.url,location.origin);if(t.origin===location.origin)location.href=t.href}catch(err){}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}else if(s.hasAttribute("data-shortcut")){
|
|
81
|
+
document.addEventListener("keydown",function(e){
|
|
82
|
+
var t=e.target;
|
|
83
|
+
if(e.defaultPrevented||(t&&(t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.tagName==="SELECT"||t.isContentEditable)))return;
|
|
84
|
+
if(e.key!=="."&&!(e.ctrlKey&&e.shiftKey&&e.key==="E"))return;
|
|
85
|
+
e.preventDefault();
|
|
86
|
+
e.stopPropagation();
|
|
87
|
+
var p=page(),h=new URL("${CHOOSE_EDITOR_URL}");
|
|
88
|
+
h.searchParams.set("site",site);
|
|
89
|
+
h.searchParams.set("domain",location.origin);
|
|
90
|
+
if(p.id)h.searchParams.set("pageId",p.id);
|
|
91
|
+
h.searchParams.set("path",location.pathname+location.search);
|
|
92
|
+
h.searchParams.set("pathTemplate",p.t||"/*");
|
|
93
|
+
if((e.ctrlKey||e.metaKey)&&e.key==="."){window.open(h.toString(),"_blank");return}
|
|
94
|
+
location.href=h.toString();
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
})();`;
|
|
98
|
+
/**
|
|
99
|
+
* Lets Studio's site editor select and edit sections on the page. Render it
|
|
100
|
+
* once, in the root layout's `<body>`.
|
|
101
|
+
*/
|
|
102
|
+
export function StudioBridge({ site, trustedOrigins, editShortcut = true, page, nonce, }) {
|
|
103
|
+
return createElement("script", {
|
|
104
|
+
"data-deco-studio-bridge": "",
|
|
105
|
+
"data-site": site,
|
|
106
|
+
"data-origins": JSON.stringify(trustedOrigins),
|
|
107
|
+
"data-shortcut": editShortcut ? "" : undefined,
|
|
108
|
+
// Read on each keypress, so a client-side navigation that re-renders the
|
|
109
|
+
// bridge with the next page updates them.
|
|
110
|
+
"data-path-template": page?.pathTemplate || undefined,
|
|
111
|
+
"data-page-id": page?.id || undefined,
|
|
112
|
+
nonce,
|
|
113
|
+
// Browsers hide a nonce from the DOM after parsing, which React would
|
|
114
|
+
// report as a hydration mismatch.
|
|
115
|
+
suppressHydrationWarning: true,
|
|
116
|
+
dangerouslySetInnerHTML: { __html: STUDIO_BRIDGE_SCRIPT },
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Tells the bridge which page is on screen: render it inside the page (not a
|
|
121
|
+
* layout that stays across navigations), with the page block's `path` as
|
|
122
|
+
* `matchRoute` matched it. A `<meta>`, which React places in the document's
|
|
123
|
+
* `<head>` wherever the page renders it, so it adds nothing to the page's own
|
|
124
|
+
* markup; the "." shortcut reads the last one when the key is pressed.
|
|
125
|
+
*/
|
|
126
|
+
export function StudioPage({ pathTemplate, id }) {
|
|
127
|
+
if (!pathTemplate)
|
|
128
|
+
return null;
|
|
129
|
+
return createElement("meta", {
|
|
130
|
+
name: "deco:page",
|
|
131
|
+
content: pathTemplate,
|
|
132
|
+
[PAGE_MARKER]: "",
|
|
133
|
+
"data-path-template": pathTemplate,
|
|
134
|
+
"data-page-id": id || undefined,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
//# sourceMappingURL=StudioBridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StudioBridge.js","sourceRoot":"","sources":["../../../src/v8/preview/StudioBridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,EAAE,aAAa,EAAkB,MAAM,OAAO,CAAC;AAsCtD,6FAA6F;AAC7F,MAAM,WAAW,GAAG,gBAAgB,CAAC;AAErC,4FAA4F;AAC5F,MAAM,iBAAiB,GAAG,0CAA0C,CAAC;AAErE,MAAM,MAAM,GAAG,oBAAoB,CAAC;AAEpC,gGAAgG;AAChG,MAAM,CAAC,MAAM,oBAAoB,GAAG;;gBAEpB,MAAM;SACb,MAAM;;;;;wCAKyB,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8BA4CrB,iBAAiB;;;;;;;;;;MAUzC,CAAC;AAEP;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,EAC3B,IAAI,EACJ,cAAc,EACd,YAAY,GAAG,IAAI,EACnB,IAAI,EACJ,KAAK,GACa;IAClB,OAAO,aAAa,CAAC,QAAQ,EAAE;QAC7B,yBAAyB,EAAE,EAAE;QAC7B,WAAW,EAAE,IAAI;QACjB,cAAc,EAAE,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC;QAC9C,eAAe,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS;QAC9C,yEAAyE;QACzE,0CAA0C;QAC1C,oBAAoB,EAAE,IAAI,EAAE,YAAY,IAAI,SAAS;QACrD,cAAc,EAAE,IAAI,EAAE,EAAE,IAAI,SAAS;QACrC,KAAK;QACL,sEAAsE;QACtE,kCAAkC;QAClC,wBAAwB,EAAE,IAAI;QAC9B,uBAAuB,EAAE,EAAE,MAAM,EAAE,oBAAoB,EAAE;KAC1D,CAAC,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,EAAE,YAAY,EAAE,EAAE,EAAkB;IAC7D,IAAI,CAAC,YAAY;QAAE,OAAO,IAAI,CAAC;IAC/B,OAAO,aAAa,CAAC,MAAM,EAAE;QAC3B,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,YAAY;QACrB,CAAC,WAAW,CAAC,EAAE,EAAE;QACjB,oBAAoB,EAAE,YAAY;QAClC,cAAc,EAAE,EAAE,IAAI,SAAS;KAChC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Deco mark the draft badge shows, inlined so the badge needs no asset
|
|
3
|
+
* from the site: a 36×36 PNG (the 18px icon at 2x). v7 shipped the 720px
|
|
4
|
+
* original (about 22KB) in every client bundle that mounted the badge.
|
|
5
|
+
*/
|
|
6
|
+
export declare const DECO_MARK_DATA_URI = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAkCAYAAADhAJiYAAAGlUlEQVRYw63Ya4yU1RkH8N87Mwu7LMsuF1FAYFXQIF5quSoXKUWUqqnXYpOa9GJrUv1gWtumafupSZuUfmh6MU0NMelF29im1frBQqmogMWiCCpqC4TLchO5w7K77MzbD+edmfedGW7qSTY7e/a8c/7n//yf//OcN/IxjoHzxqCEKJmJEXXiVtyHq5J/voMn8Ht0Q+/K3aSe/IhARtdOtWIK7sAtmICmmjW9WIrv4mgZVOGjAGmeN0YsTrjIixQn4mbciWloO9M58HV04cflyehjYqYNj+ABjDvd+lKJKAo/qbEVC7EF8h8ezMWJRjThh/ge2mvXxXEAMnAAl1zMgCaOd2dADcU+vPyRABU6B5c/zsOSJARVEDG5iAtHMG86X7qHB+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RxIHDvLqhcb/bVGDRjbQNzj6zdz/Pv1RXYk7gd0nK61nZ1RDQyPTE8PZQEioLIrbvZs/+UG5r2bniktD71Brh8tVs3VmnnZex6kyFOZdkWcUMC4WasEQcPBT6m6gBO3csCFmZzqyuvTyzoi6E5WtPdyMxpwH1ps3weHe2ZRDTkbBWiqvlpFgM4r9pdjYsxSJ/eZ5tXXXsvIR/nK11yWFvmupd+0JbUGknklp2500Maw+N17B2bp/PI1+kbVAVUD4XPOfZf9Xt041f4tiZ2Cn70BtJpoVU3cPG95h/fThtHDOomYfv57MLOHKM9rbQuKdZy+XYsYfHnqy2GKnxzLmwA/lCZ9tA3Fa+6p7qD0Y287rQ8aVPP3woYy4MDKVTOZ8Pov/J47z2Vh2YnXgYu87GThnQ+8ndalw5bHv2s+8Aky6jo60avjjOpnY+H/7e+C5LHmfthjowp/AD/L2s0f5tx84K6CR6EpYq/rxlB+veDEVxYFO1UhdLIeMOHeGt//LUc/zmj2ze0bDXWYoflX3nbOxAlDRozfg5vlp3F8/RMZgRw0Jzns/T28uho3xwKABucF8v16sHsf9cwaTbjx58H8NxV7oeweFjAUBceeUTAOSihqzE+BO+UQZzPiNf6ByStvUXkuvO5PTdK6oBkGvMSLlwLkl080FAF+k7R3YgX9x2TApUN1ZgfdI9XoCWs3xHMWm0nsa3ItGTabM9HzCZ90MN3oINSl46LUj6pUuS1y35ZMP9eA9rEmbfTsA5H83Ujv8DiTxDVO4oYfoAAAAASUVORK5CYII=";
|
|
7
|
+
//# sourceMappingURL=decoMark.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decoMark.d.ts","sourceRoot":"","sources":["../../../src/v8/preview/decoMark.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,+yEAC+wE,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Deco mark the draft badge shows, inlined so the badge needs no asset
|
|
3
|
+
* from the site: a 36×36 PNG (the 18px icon at 2x). v7 shipped the 720px
|
|
4
|
+
* original (about 22KB) in every client bundle that mounted the badge.
|
|
5
|
+
*/
|
|
6
|
+
export const DECO_MARK_DATA_URI = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAkCAYAAADhAJiYAAAGlUlEQVRYw63Ya4yU1RkH8N87Mwu7LMsuF1FAYFXQIF5quSoXKUWUqqnXYpOa9GJrUv1gWtumafupSZuUfmh6MU0NMelF29im1frBQqmogMWiCCpqC4TLchO5w7K77MzbD+edmfedGW7qSTY7e/a8c/7n//yf//OcN/IxjoHzxqCEKJmJEXXiVtyHq5J/voMn8Ht0Q+/K3aSe/IhARtdOtWIK7sAtmICmmjW9WIrv4mgZVOGjAGmeN0YsTrjIixQn4mbciWloO9M58HV04cflyehjYqYNj+ABjDvd+lKJKAo/qbEVC7EF8h8ezMWJRjThh/ge2mvXxXEAMnAAl1zMgCaOd2dADcU+vPyRABU6B5c/zsOSJARVEDG5iAtHMG86X7qHB+5l7ChWv0axlPm6UXgWRwsfRjelRDfJWFirlcGtTLqUudOY+YkAoqkpAJ09hU9OZvXr5HOVR65MdPeLwrmlchVALK4ILy+vqDgqzcyIoTz6FWZNYVBLNWTFYhXsXQtZv4mevoyI78fT+TMJttCZOXge4zELt+NzsXgx5iY6EEX097PvIL19XDqWpgY7XDiCd7awbVcIazJGoquOoY55nU7qS08NwadxL67HaAw43UFO9bNuI80DuGNB/f+jiCGDufsWXn+b7p6KwJtwT6E2PFUwUY54Ib6JOWnRnlVnA1k0l9ZB1VCVwT73Am2tjBvN+DFs2pzJuEsLWU+paKWD+Nt4KGFIo3SuPXnZay4bx/Rrw+fyyOXYvJ3H/hDSfngHR4+H+dToK4TMGS92Kh3Ln+HzjYyN4CWDWsLvKKLvFCe66U/YmDM1iDsNulRi+SoOHw0g3j9QZ5Dw70LInFMpZurBlEoMGMDlncy4lisncNEIWlpClvT08uuneGEtw9u5cXrYrAwoF9G1jxf/U89oauzArwop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bDXWYoflX3nbOxAlDRozfg5vlp3F8/RMZgRw0Jzns/T28uho3xwKABucF8v16sHsf9cwaTbjx58H8NxV7oeweFjAUBceeUTAOSihqzE+BO+UQZzPiNf6ByStvUXkuvO5PTdK6oBkGvMSLlwLkl080FAF+k7R3YgX9x2TApUN1ZgfdI9XoCWs3xHMWm0nsa3ItGTabM9HzCZ90MN3oINSl46LUj6pUuS1y35ZMP9eA9rEmbfTsA5H83Ujv8DiTxDVO4oYfoAAAAASUVORK5CYII=";
|
|
7
|
+
//# sourceMappingURL=decoMark.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decoMark.js","sourceRoot":"","sources":["../../../src/v8/preview/decoMark.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAC7B,4yEAA4yE,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@decocms/blocks/preview`: the two pieces of the page that serve Deco
|
|
3
|
+
* Studio and draft previews, with no framework code. `@decocms/tanstack`'s
|
|
4
|
+
* document mounts both; a Next.js site adds them to its root layout.
|
|
5
|
+
*
|
|
6
|
+
* - `DraftBadge`: the "Preview mode" badge on a page rendered from a draft,
|
|
7
|
+
* outside Studio's frame.
|
|
8
|
+
* - `StudioBridge`: lets Studio's site editor drive the page when Studio
|
|
9
|
+
* frames it, and opens the page in Studio on "." when it isn't framed.
|
|
10
|
+
* - `StudioPage`: what a page renders to tell the bridge which page it is.
|
|
11
|
+
*/
|
|
12
|
+
export { DraftBadge, type DraftBadgeProps } from "./DraftBadge.tsx";
|
|
13
|
+
export { StudioBridge, type StudioBridgeProps, StudioPage, type StudioPageInfo, } from "./StudioBridge.ts";
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/v8/preview/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,UAAU,EAAE,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EACL,YAAY,EACZ,KAAK,iBAAiB,EACtB,UAAU,EACV,KAAK,cAAc,GACpB,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@decocms/blocks/preview`: the two pieces of the page that serve Deco
|
|
3
|
+
* Studio and draft previews, with no framework code. `@decocms/tanstack`'s
|
|
4
|
+
* document mounts both; a Next.js site adds them to its root layout.
|
|
5
|
+
*
|
|
6
|
+
* - `DraftBadge`: the "Preview mode" badge on a page rendered from a draft,
|
|
7
|
+
* outside Studio's frame.
|
|
8
|
+
* - `StudioBridge`: lets Studio's site editor drive the page when Studio
|
|
9
|
+
* frames it, and opens the page in Studio on "." when it isn't framed.
|
|
10
|
+
* - `StudioPage`: what a page renders to tell the bridge which page it is.
|
|
11
|
+
*/
|
|
12
|
+
export { DraftBadge } from "./DraftBadge.js";
|
|
13
|
+
export { StudioBridge, StudioPage, } from "./StudioBridge.js";
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/v8/preview/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,UAAU,EAAwB,MAAM,iBAAkB,CAAC;AACpE,OAAO,EACL,YAAY,EAEZ,UAAU,GAEX,MAAM,mBAAmB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/blocks",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=24"
|
|
@@ -53,6 +53,11 @@
|
|
|
53
53
|
"source": "./src/v8/image.ts",
|
|
54
54
|
"default": "./dist/v8/image.js"
|
|
55
55
|
},
|
|
56
|
+
"./preview": {
|
|
57
|
+
"types": "./dist/v8/preview/index.d.ts",
|
|
58
|
+
"source": "./src/v8/preview/index.ts",
|
|
59
|
+
"default": "./dist/v8/preview/index.js"
|
|
60
|
+
},
|
|
56
61
|
"./secrets": {
|
|
57
62
|
"types": "./dist/v8/secrets.d.ts",
|
|
58
63
|
"source": "./src/v8/secrets.ts",
|
package/src/v8/draft.ts
CHANGED
|
@@ -14,7 +14,8 @@ import type { DraftPointer, ForcedVariant, RequestLike } from "./types.ts";
|
|
|
14
14
|
/** The draft cookie's name. Not exported from the package: reading it directly would skip the host check. */
|
|
15
15
|
const DRAFT_COOKIE = "__deco_draft";
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
/** The draft link's query parameter. Shared with `./preview` (the badge's links); not exported from the package. */
|
|
18
|
+
export const DRAFT_PARAM = "__draft";
|
|
18
19
|
const DRAFT_OFF = "off";
|
|
19
20
|
|
|
20
21
|
/** Lowercase DNS name; a single label (`localhost`) is allowed. */
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The "Preview mode" badge: v7's `DraftPreviewBadge`, unchanged on screen.
|
|
5
|
+
*
|
|
6
|
+
* A draft preview keeps its pointer in a cookie, so after the first click the
|
|
7
|
+
* URL no longer shows `?__draft=` and a reviewer can mistake the draft for the
|
|
8
|
+
* live site. While a draft is bound, this badge floats over the page; clicking
|
|
9
|
+
* it offers the two things a reviewer needs: leave the preview, or copy a link
|
|
10
|
+
* to this exact draft version.
|
|
11
|
+
*
|
|
12
|
+
* - Renders nothing without a `pointer`, so a binding can mount it on every
|
|
13
|
+
* page and pass the request's draft pointer (or `null`).
|
|
14
|
+
* - Hidden inside a frame: Studio's site editor shows the draft in an iframe
|
|
15
|
+
* with its own chrome. A reviewer who opens a shared link in their own tab
|
|
16
|
+
* still sees it.
|
|
17
|
+
* - Starts hidden on the server and on the first client render, and shows only
|
|
18
|
+
* after an effect confirms the page isn't framed. Rendering it and hiding it
|
|
19
|
+
* later would flash it inside Studio and break hydration (the server has no
|
|
20
|
+
* `window`).
|
|
21
|
+
* - Inline styles and an inlined mark: no dependency on the site's CSS or
|
|
22
|
+
* assets.
|
|
23
|
+
*
|
|
24
|
+
* `"use client"`: it has state and effects. In Next.js a Server Component can
|
|
25
|
+
* render it directly.
|
|
26
|
+
*/
|
|
27
|
+
import { type ReactNode, useCallback, useEffect, useRef, useState } from "react";
|
|
28
|
+
import { DRAFT_PARAM } from "../draft.ts";
|
|
29
|
+
import { DECO_MARK_DATA_URI } from "./decoMark.ts";
|
|
30
|
+
|
|
31
|
+
export interface DraftBadgeProps {
|
|
32
|
+
/**
|
|
33
|
+
* The draft pointer this page was rendered from (`cms.draftPointer`). The
|
|
34
|
+
* badge renders nothing when it's `null`, `undefined` or empty.
|
|
35
|
+
*/
|
|
36
|
+
pointer: string | null | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Where "Exit preview" goes. Defaults to the current URL with
|
|
39
|
+
* `?__draft=off`, which clears the draft cookie.
|
|
40
|
+
*/
|
|
41
|
+
exitHref?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The link "Share preview" copies: the current URL with `?__draft=<pointer>`,
|
|
46
|
+
* so the recipient sees this exact draft version.
|
|
47
|
+
*/
|
|
48
|
+
export function buildShareUrl(href: string, pointer: string): string {
|
|
49
|
+
const url = new URL(href);
|
|
50
|
+
url.searchParams.set(DRAFT_PARAM, pointer);
|
|
51
|
+
return url.toString();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The current URL with `?__draft=off`: ends the preview and shows the published page. */
|
|
55
|
+
export function buildExitUrl(href: string): string {
|
|
56
|
+
const url = new URL(href);
|
|
57
|
+
url.searchParams.set(DRAFT_PARAM, "off");
|
|
58
|
+
return url.toString();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Whether the page is in another page's frame (Studio's site editor). A
|
|
63
|
+
* reference comparison, so it never throws across origins. No `window` (the
|
|
64
|
+
* server) reads as not framed.
|
|
65
|
+
*/
|
|
66
|
+
export function isFramed(win: typeof window | undefined = globalThis.window): boolean {
|
|
67
|
+
return typeof win !== "undefined" && win.top !== win;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const DECO_GREEN = "#0b3d1e";
|
|
71
|
+
/** The badge background, Deco lime; text sits on it in dark green. */
|
|
72
|
+
const DECO_LIME = "#d0ec1a";
|
|
73
|
+
|
|
74
|
+
/** Leaving preview: an arrow back to the published site. */
|
|
75
|
+
function ExitIcon() {
|
|
76
|
+
return (
|
|
77
|
+
<svg
|
|
78
|
+
width={14}
|
|
79
|
+
height={14}
|
|
80
|
+
viewBox="0 0 24 24"
|
|
81
|
+
fill="none"
|
|
82
|
+
stroke="currentColor"
|
|
83
|
+
strokeWidth={2}
|
|
84
|
+
strokeLinecap="round"
|
|
85
|
+
strokeLinejoin="round"
|
|
86
|
+
aria-hidden="true"
|
|
87
|
+
>
|
|
88
|
+
<path d="M19 12H5" />
|
|
89
|
+
<path d="M12 19l-7-7 7-7" />
|
|
90
|
+
</svg>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Sharing the draft: the three-node share glyph. */
|
|
95
|
+
function ShareIcon() {
|
|
96
|
+
return (
|
|
97
|
+
<svg
|
|
98
|
+
width={14}
|
|
99
|
+
height={14}
|
|
100
|
+
viewBox="0 0 24 24"
|
|
101
|
+
fill="none"
|
|
102
|
+
stroke="currentColor"
|
|
103
|
+
strokeWidth={2}
|
|
104
|
+
strokeLinecap="round"
|
|
105
|
+
strokeLinejoin="round"
|
|
106
|
+
aria-hidden="true"
|
|
107
|
+
>
|
|
108
|
+
<circle cx={18} cy={5} r={3} />
|
|
109
|
+
<circle cx={6} cy={12} r={3} />
|
|
110
|
+
<circle cx={18} cy={19} r={3} />
|
|
111
|
+
<path d="M8.59 13.51l6.83 3.98" />
|
|
112
|
+
<path d="M15.41 6.51l-6.82 3.98" />
|
|
113
|
+
</svg>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export function DraftBadge({ pointer, exitHref }: DraftBadgeProps): ReactNode {
|
|
118
|
+
const [open, setOpen] = useState(false);
|
|
119
|
+
const [copied, setCopied] = useState(false);
|
|
120
|
+
const [visible, setVisible] = useState(false);
|
|
121
|
+
const rootRef = useRef<HTMLDivElement>(null);
|
|
122
|
+
|
|
123
|
+
// The only place isFramed() runs: after mount, so the server render and the
|
|
124
|
+
// first client render agree (both hidden).
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
if (!isFramed()) setVisible(true);
|
|
127
|
+
}, []);
|
|
128
|
+
|
|
129
|
+
// Close the menu on an outside click or Escape.
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
if (!open) return;
|
|
132
|
+
const onPointerDown = (e: MouseEvent) => {
|
|
133
|
+
if (rootRef.current && !rootRef.current.contains(e.target as Node)) setOpen(false);
|
|
134
|
+
};
|
|
135
|
+
const onKeyDown = (e: KeyboardEvent) => {
|
|
136
|
+
if (e.key === "Escape") setOpen(false);
|
|
137
|
+
};
|
|
138
|
+
document.addEventListener("mousedown", onPointerDown);
|
|
139
|
+
document.addEventListener("keydown", onKeyDown);
|
|
140
|
+
return () => {
|
|
141
|
+
document.removeEventListener("mousedown", onPointerDown);
|
|
142
|
+
document.removeEventListener("keydown", onKeyDown);
|
|
143
|
+
};
|
|
144
|
+
}, [open]);
|
|
145
|
+
|
|
146
|
+
const exitPreview = useCallback(() => {
|
|
147
|
+
window.location.href = exitHref ?? buildExitUrl(window.location.href);
|
|
148
|
+
}, [exitHref]);
|
|
149
|
+
|
|
150
|
+
const sharePreviewLink = useCallback(async () => {
|
|
151
|
+
if (!pointer) return;
|
|
152
|
+
const link = buildShareUrl(window.location.href, pointer);
|
|
153
|
+
try {
|
|
154
|
+
await navigator.clipboard.writeText(link);
|
|
155
|
+
setCopied(true);
|
|
156
|
+
window.setTimeout(() => setCopied(false), 2000);
|
|
157
|
+
} catch {
|
|
158
|
+
// No clipboard (an insecure context, a denied permission): let the
|
|
159
|
+
// reviewer copy the link by hand.
|
|
160
|
+
window.prompt("Copy preview link:", link);
|
|
161
|
+
}
|
|
162
|
+
}, [pointer]);
|
|
163
|
+
|
|
164
|
+
if (!pointer || !visible) return null;
|
|
165
|
+
|
|
166
|
+
return (
|
|
167
|
+
<div
|
|
168
|
+
ref={rootRef}
|
|
169
|
+
data-deco-preview-badge=""
|
|
170
|
+
style={{
|
|
171
|
+
position: "fixed",
|
|
172
|
+
bottom: 16,
|
|
173
|
+
left: 16,
|
|
174
|
+
zIndex: 2147483647,
|
|
175
|
+
fontFamily:
|
|
176
|
+
"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif",
|
|
177
|
+
fontSize: 13,
|
|
178
|
+
lineHeight: 1.4,
|
|
179
|
+
}}
|
|
180
|
+
>
|
|
181
|
+
{open ? (
|
|
182
|
+
<div
|
|
183
|
+
role="menu"
|
|
184
|
+
style={{
|
|
185
|
+
position: "absolute",
|
|
186
|
+
bottom: "calc(100% + 8px)",
|
|
187
|
+
left: 0,
|
|
188
|
+
minWidth: 200,
|
|
189
|
+
background: "#fff",
|
|
190
|
+
color: "#1a1a1a",
|
|
191
|
+
borderRadius: 12,
|
|
192
|
+
boxShadow: "0 8px 30px rgba(0,0,0,0.18), 0 0 0 1px rgba(0,0,0,0.05)",
|
|
193
|
+
overflow: "hidden",
|
|
194
|
+
}}
|
|
195
|
+
>
|
|
196
|
+
<MenuItem onClick={exitPreview} label="Exit preview" icon={<ExitIcon />} />
|
|
197
|
+
<div style={{ height: 1, background: "rgba(0,0,0,0.07)" }} />
|
|
198
|
+
<MenuItem
|
|
199
|
+
onClick={sharePreviewLink}
|
|
200
|
+
label={copied ? "Copied!" : "Share preview"}
|
|
201
|
+
icon={<ShareIcon />}
|
|
202
|
+
/>
|
|
203
|
+
</div>
|
|
204
|
+
) : null}
|
|
205
|
+
|
|
206
|
+
<button
|
|
207
|
+
type="button"
|
|
208
|
+
aria-expanded={open}
|
|
209
|
+
aria-label="Preview mode"
|
|
210
|
+
onClick={() => setOpen((v) => !v)}
|
|
211
|
+
style={{
|
|
212
|
+
display: "inline-flex",
|
|
213
|
+
alignItems: "center",
|
|
214
|
+
gap: 8,
|
|
215
|
+
padding: "7px 12px 7px 8px",
|
|
216
|
+
background: DECO_LIME,
|
|
217
|
+
color: DECO_GREEN,
|
|
218
|
+
border: "none",
|
|
219
|
+
borderRadius: 9999,
|
|
220
|
+
cursor: "pointer",
|
|
221
|
+
fontSize: 13,
|
|
222
|
+
fontWeight: 600,
|
|
223
|
+
boxShadow: "0 4px 14px rgba(0,0,0,0.25)",
|
|
224
|
+
}}
|
|
225
|
+
>
|
|
226
|
+
<img
|
|
227
|
+
src={DECO_MARK_DATA_URI}
|
|
228
|
+
alt=""
|
|
229
|
+
width={18}
|
|
230
|
+
height={18}
|
|
231
|
+
style={{ display: "block", borderRadius: 4 }}
|
|
232
|
+
/>
|
|
233
|
+
<span>Preview mode</span>
|
|
234
|
+
</button>
|
|
235
|
+
</div>
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function MenuItem({
|
|
240
|
+
onClick,
|
|
241
|
+
label,
|
|
242
|
+
icon,
|
|
243
|
+
}: {
|
|
244
|
+
onClick: () => void;
|
|
245
|
+
label: string;
|
|
246
|
+
icon: ReactNode;
|
|
247
|
+
}) {
|
|
248
|
+
return (
|
|
249
|
+
<button
|
|
250
|
+
type="button"
|
|
251
|
+
role="menuitem"
|
|
252
|
+
onClick={onClick}
|
|
253
|
+
style={{
|
|
254
|
+
display: "flex",
|
|
255
|
+
alignItems: "center",
|
|
256
|
+
gap: 10,
|
|
257
|
+
width: "100%",
|
|
258
|
+
textAlign: "left",
|
|
259
|
+
padding: "10px 14px",
|
|
260
|
+
background: "transparent",
|
|
261
|
+
border: "none",
|
|
262
|
+
color: "inherit",
|
|
263
|
+
cursor: "pointer",
|
|
264
|
+
fontSize: 13,
|
|
265
|
+
whiteSpace: "nowrap",
|
|
266
|
+
}}
|
|
267
|
+
onMouseEnter={(e) => {
|
|
268
|
+
e.currentTarget.style.background = "rgba(0,0,0,0.05)";
|
|
269
|
+
}}
|
|
270
|
+
onMouseLeave={(e) => {
|
|
271
|
+
e.currentTarget.style.background = "transparent";
|
|
272
|
+
}}
|
|
273
|
+
>
|
|
274
|
+
<span style={{ display: "inline-flex", flexShrink: 0, color: DECO_GREEN }}>{icon}</span>
|
|
275
|
+
<span>{label}</span>
|
|
276
|
+
</button>
|
|
277
|
+
);
|
|
278
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Studio bridge: what lets Deco Studio's site editor drive a page it
|
|
3
|
+
* shows in an iframe (v7's `LiveControls`).
|
|
4
|
+
*
|
|
5
|
+
* When the frame loads, Studio posts `{ type: "editor::inject", args: {
|
|
6
|
+
* script } }` to it; the bridge runs that script, which draws the section
|
|
7
|
+
* overlay and handles Studio's `cms-editor::*` messages itself. The bridge also
|
|
8
|
+
* answers v7's `scrollToComponent` and `editor::rerender` (same-origin
|
|
9
|
+
* navigation only).
|
|
10
|
+
*
|
|
11
|
+
* In a frame it answers only messages from the parent window whose origin is
|
|
12
|
+
* one of `trustedOrigins`. On a page that isn't framed it answers no message;
|
|
13
|
+
* there it only listens for the "." shortcut (`editShortcut`), which opens the
|
|
14
|
+
* page in Studio's editor, as v7's `LiveControls` did. Studio signs the editor
|
|
15
|
+
* in: `/choose-editor` sends a visitor who isn't signed in to Studio's login
|
|
16
|
+
* and back.
|
|
17
|
+
* The binding passes Studio's origins in (`@decocms/blocks` holds no list of
|
|
18
|
+
* them); with none, the bridge answers nothing. It doesn't trust the page's own
|
|
19
|
+
* origin: under a test runner that proxies the site, the runner's own messages
|
|
20
|
+
* would navigate the page.
|
|
21
|
+
*
|
|
22
|
+
* An inline script, not an effect: Studio posts on the frame's `load` event,
|
|
23
|
+
* which can come before React hydrates, so the listener must exist as soon as
|
|
24
|
+
* the HTML is parsed. No hooks, so it renders from a Next.js Server Component
|
|
25
|
+
* as well as from a client tree. Its settings travel in `data-*` attributes;
|
|
26
|
+
* the script itself is static.
|
|
27
|
+
*/
|
|
28
|
+
import { createElement, type ReactNode } from "react";
|
|
29
|
+
|
|
30
|
+
export interface StudioBridgeProps {
|
|
31
|
+
/** The site's name in Deco (the "." shortcut sends it to Studio). */
|
|
32
|
+
site: string;
|
|
33
|
+
/**
|
|
34
|
+
* The origins Studio's site editor frames the page from, in the CSP source
|
|
35
|
+
* form (`https://host`, or `https://*.host` for any name under it, same
|
|
36
|
+
* scheme and port). Required: the binding owns Studio's origins and passes
|
|
37
|
+
* them here. An empty list makes the bridge answer nothing.
|
|
38
|
+
*/
|
|
39
|
+
trustedOrigins: readonly string[];
|
|
40
|
+
/**
|
|
41
|
+
* v7's editor shortcut: on a page that isn't framed, "." (or Ctrl+Shift+E)
|
|
42
|
+
* opens it in Studio, and Ctrl or Cmd+"." opens it in a new tab. On by
|
|
43
|
+
* default, as in v7; `false` turns it off.
|
|
44
|
+
*/
|
|
45
|
+
editShortcut?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* The page being shown, when the layout that renders the bridge knows it:
|
|
48
|
+
* the "." shortcut sends its path template (and id), so Studio opens that
|
|
49
|
+
* page rather than guessing from the URL. A page can declare itself instead
|
|
50
|
+
* with `StudioPage` (for a layout that doesn't re-render per page, such as a
|
|
51
|
+
* Next.js root layout); a `StudioPage` on the page wins.
|
|
52
|
+
*/
|
|
53
|
+
page?: StudioPageInfo;
|
|
54
|
+
/** The CSP nonce for the inline script, when the site sends one. */
|
|
55
|
+
nonce?: string;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The page the "." shortcut opens in Studio. */
|
|
59
|
+
export interface StudioPageInfo {
|
|
60
|
+
/** The page block's `path`, as `matchRoute` matched it (`/products/:slug/p`, `/*`). */
|
|
61
|
+
pathTemplate?: string;
|
|
62
|
+
/** The page block's id, when the site knows it. */
|
|
63
|
+
id?: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The marker a page renders to tell the bridge which page it is (read on each keypress). */
|
|
67
|
+
const PAGE_MARKER = "data-deco-page";
|
|
68
|
+
|
|
69
|
+
/** Where the "." shortcut sends an editor; Studio picks the project the site belongs to. */
|
|
70
|
+
const CHOOSE_EDITOR_URL = "https://studio.decocms.com/choose-editor";
|
|
71
|
+
|
|
72
|
+
const GLOBAL = "__decoStudioBridge";
|
|
73
|
+
|
|
74
|
+
/** The browser side. Static: everything it needs comes from the script element's attributes. */
|
|
75
|
+
export const STUDIO_BRIDGE_SCRIPT = `(function(){
|
|
76
|
+
var s=document.currentScript;
|
|
77
|
+
if(!s||window.${GLOBAL})return;
|
|
78
|
+
window.${GLOBAL}=true;
|
|
79
|
+
var origins=[];
|
|
80
|
+
try{origins=JSON.parse(s.getAttribute("data-origins")||"[]")}catch(e){}
|
|
81
|
+
var site=s.getAttribute("data-site")||"";
|
|
82
|
+
function page(){
|
|
83
|
+
var all=document.querySelectorAll("[${PAGE_MARKER}]"),el=all.length?all[all.length-1]:null;
|
|
84
|
+
if(!el||!el.getAttribute("data-path-template")){el=document.querySelector("script[data-deco-studio-bridge]")||s}
|
|
85
|
+
return{t:el.getAttribute("data-path-template")||"",id:el.getAttribute("data-page-id")||""};
|
|
86
|
+
}
|
|
87
|
+
function trusted(o){
|
|
88
|
+
if(typeof o!=="string"||!o)return false;
|
|
89
|
+
var u;
|
|
90
|
+
try{u=new URL(o)}catch(e){return false}
|
|
91
|
+
if(u.origin!==o)return false;
|
|
92
|
+
for(var i=0;i<origins.length;i++){
|
|
93
|
+
var p=origins[i];
|
|
94
|
+
if(p===o)return true;
|
|
95
|
+
var m=/^([a-z][a-z0-9+.-]*:)\\/\\/\\*\\.([^\\/:]+)(?::([0-9]+))?$/.exec(p);
|
|
96
|
+
if(m&&u.protocol===m[1]&&u.port===(m[3]||"")&&u.hostname.slice(-m[2].length-1)==="."+m[2])return true;
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
if(window.self!==window.top){
|
|
101
|
+
window.addEventListener("message",function(e){
|
|
102
|
+
if(e.source!==window.parent||!trusted(e.origin))return;
|
|
103
|
+
var d=e.data;
|
|
104
|
+
if(!d||typeof d!=="object")return;
|
|
105
|
+
var a=d.args||{};
|
|
106
|
+
if(d.type==="editor::inject"){
|
|
107
|
+
if(typeof a.script==="string"){try{(0,eval)(a.script)}catch(err){console.error("[deco] Studio script failed:",err)}}
|
|
108
|
+
}else if(d.type==="scrollToComponent"){
|
|
109
|
+
var id=typeof a.id==="string"?a.id:"";
|
|
110
|
+
if(!id)return;
|
|
111
|
+
var el=null,all=document.querySelectorAll("[data-manifest-key]");
|
|
112
|
+
for(var i=0;i<all.length&&!el;i++)if(all[i].getAttribute("data-manifest-key")===id)el=all[i];
|
|
113
|
+
el=el||document.getElementById(id);
|
|
114
|
+
if(el)el.scrollIntoView({behavior:"smooth",block:"center"});
|
|
115
|
+
}else if(d.type==="editor::rerender"){
|
|
116
|
+
if(typeof a.url!=="string")return;
|
|
117
|
+
try{var t=new URL(a.url,location.origin);if(t.origin===location.origin)location.href=t.href}catch(err){}
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}else if(s.hasAttribute("data-shortcut")){
|
|
121
|
+
document.addEventListener("keydown",function(e){
|
|
122
|
+
var t=e.target;
|
|
123
|
+
if(e.defaultPrevented||(t&&(t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.tagName==="SELECT"||t.isContentEditable)))return;
|
|
124
|
+
if(e.key!=="."&&!(e.ctrlKey&&e.shiftKey&&e.key==="E"))return;
|
|
125
|
+
e.preventDefault();
|
|
126
|
+
e.stopPropagation();
|
|
127
|
+
var p=page(),h=new URL("${CHOOSE_EDITOR_URL}");
|
|
128
|
+
h.searchParams.set("site",site);
|
|
129
|
+
h.searchParams.set("domain",location.origin);
|
|
130
|
+
if(p.id)h.searchParams.set("pageId",p.id);
|
|
131
|
+
h.searchParams.set("path",location.pathname+location.search);
|
|
132
|
+
h.searchParams.set("pathTemplate",p.t||"/*");
|
|
133
|
+
if((e.ctrlKey||e.metaKey)&&e.key==="."){window.open(h.toString(),"_blank");return}
|
|
134
|
+
location.href=h.toString();
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
})();`;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Lets Studio's site editor select and edit sections on the page. Render it
|
|
141
|
+
* once, in the root layout's `<body>`.
|
|
142
|
+
*/
|
|
143
|
+
export function StudioBridge({
|
|
144
|
+
site,
|
|
145
|
+
trustedOrigins,
|
|
146
|
+
editShortcut = true,
|
|
147
|
+
page,
|
|
148
|
+
nonce,
|
|
149
|
+
}: StudioBridgeProps): ReactNode {
|
|
150
|
+
return createElement("script", {
|
|
151
|
+
"data-deco-studio-bridge": "",
|
|
152
|
+
"data-site": site,
|
|
153
|
+
"data-origins": JSON.stringify(trustedOrigins),
|
|
154
|
+
"data-shortcut": editShortcut ? "" : undefined,
|
|
155
|
+
// Read on each keypress, so a client-side navigation that re-renders the
|
|
156
|
+
// bridge with the next page updates them.
|
|
157
|
+
"data-path-template": page?.pathTemplate || undefined,
|
|
158
|
+
"data-page-id": page?.id || undefined,
|
|
159
|
+
nonce,
|
|
160
|
+
// Browsers hide a nonce from the DOM after parsing, which React would
|
|
161
|
+
// report as a hydration mismatch.
|
|
162
|
+
suppressHydrationWarning: true,
|
|
163
|
+
dangerouslySetInnerHTML: { __html: STUDIO_BRIDGE_SCRIPT },
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Tells the bridge which page is on screen: render it inside the page (not a
|
|
169
|
+
* layout that stays across navigations), with the page block's `path` as
|
|
170
|
+
* `matchRoute` matched it. A `<meta>`, which React places in the document's
|
|
171
|
+
* `<head>` wherever the page renders it, so it adds nothing to the page's own
|
|
172
|
+
* markup; the "." shortcut reads the last one when the key is pressed.
|
|
173
|
+
*/
|
|
174
|
+
export function StudioPage({ pathTemplate, id }: StudioPageInfo): ReactNode {
|
|
175
|
+
if (!pathTemplate) return null;
|
|
176
|
+
return createElement("meta", {
|
|
177
|
+
name: "deco:page",
|
|
178
|
+
content: pathTemplate,
|
|
179
|
+
[PAGE_MARKER]: "",
|
|
180
|
+
"data-path-template": pathTemplate,
|
|
181
|
+
"data-page-id": id || undefined,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Deco mark the draft badge shows, inlined so the badge needs no asset
|
|
3
|
+
* from the site: a 36×36 PNG (the 18px icon at 2x). v7 shipped the 720px
|
|
4
|
+
* original (about 22KB) in every client bundle that mounted the badge.
|
|
5
|
+
*/
|
|
6
|
+
export const DECO_MARK_DATA_URI =
|
|
7
|
+
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACQAAAAkCAYAAADhAJiYAAAGlUlEQVRYw63Ya4yU1RkH8N87Mwu7LMsuF1FAYFXQIF5quSoXKUWUqqnXYpOa9GJrUv1gWtumafupSZuUfmh6MU0NMelF29im1frBQqmogMWiCCpqC4TLchO5w7K77MzbD+edmfedGW7qSTY7e/a8c/7n//yf//OcN/IxjoHzxqCEKJmJEXXiVtyHq5J/voMn8Ht0Q+/K3aSe/IhARtdOtWIK7sAtmICmmjW9WIrv4mgZVOGjAGmeN0YsTrjIixQn4mbciWloO9M58HV04cflyehjYqYNj+ABjDvd+lKJKAo/qbEVC7EF8h8ezMWJRjThh/ge2mvXxXEAMnAAl1zMgCaOd2dADcU+vPyRABU6B5c/zsOSJARVEDG5iAtHMG86X7qHB+5l7ChWv0axlPm6UXgWRwsfRjelRDfJWFirlcGtTLqUudOY+YkAoqkpAJ09hU9OZvXr5HOVR65MdPeLwrmlchVALK4ILy+vqDgqzcyIoTz6FWZNYVBLNWTF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cPBT6m6gBO3csCFmZzqyuvTyzoi6E5WtPdyMxpwH1ps3weHe2ZRDTkbBWiqvlpFgM4r9pdjYsxSJ/eZ5tXXXsvIR/nK11yWFvmupd+0JbUGknklp2500Maw+N17B2bp/PI1+kbVAVUD4XPOfZf9Xt041f4tiZ2Cn70BtJpoVU3cPG95h/fThtHDOomYfv57MLOHKM9rbQuKdZy+XYsYfHnqy2GKnxzLmwA/lCZ9tA3Fa+6p7qD0Y287rQ8aVPP3woYy4MDKVTOZ8Pov/J47z2Vh2YnXgYu87GThnQ+8ndalw5bHv2s+8Aky6jo60avjjOpnY+H/7e+C5LHmfthjowp/AD/L2s0f5tx84K6CR6EpYq/rxlB+veDEVxYFO1UhdLIeMOHeGt//LUc/zmj2ze0bDXWYoflX3nbOxAlDRozfg5vlp3F8/RMZgRw0Jzns/T28uho3xwKABucF8v16sHsf9cwaTbjx58H8NxV7oeweFjAUBceeUTAOSihqzE+BO+UQZzPiNf6ByStvUXkuvO5PTdK6oBkGvMSLlwLkl080FAF+k7R3YgX9x2TApUN1ZgfdI9XoCWs3xHMWm0nsa3ItGTabM9HzCZ90MN3oINSl46LUj6pUuS1y35ZMP9eA9rEmbfTsA5H83Ujv8DiTxDVO4oYfoAAAAASUVORK5CYII=";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@decocms/blocks/preview`: the two pieces of the page that serve Deco
|
|
3
|
+
* Studio and draft previews, with no framework code. `@decocms/tanstack`'s
|
|
4
|
+
* document mounts both; a Next.js site adds them to its root layout.
|
|
5
|
+
*
|
|
6
|
+
* - `DraftBadge`: the "Preview mode" badge on a page rendered from a draft,
|
|
7
|
+
* outside Studio's frame.
|
|
8
|
+
* - `StudioBridge`: lets Studio's site editor drive the page when Studio
|
|
9
|
+
* frames it, and opens the page in Studio on "." when it isn't framed.
|
|
10
|
+
* - `StudioPage`: what a page renders to tell the bridge which page it is.
|
|
11
|
+
*/
|
|
12
|
+
export { DraftBadge, type DraftBadgeProps } from "./DraftBadge.tsx";
|
|
13
|
+
export {
|
|
14
|
+
StudioBridge,
|
|
15
|
+
type StudioBridgeProps,
|
|
16
|
+
StudioPage,
|
|
17
|
+
type StudioPageInfo,
|
|
18
|
+
} from "./StudioBridge.ts";
|