@decocms/tanstack 8.13.0 → 8.15.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/README.md +2 -2
- package/dist/react/DecoDocument.d.ts +3 -3
- package/dist/react/DecoDocument.d.ts.map +1 -1
- package/dist/react/DecoDocument.js +17 -12
- package/dist/react/DecoDocument.js.map +1 -1
- package/dist/studio.d.ts +1 -2
- package/dist/studio.d.ts.map +1 -1
- package/dist/studio.js +1 -2
- package/dist/studio.js.map +1 -1
- package/dist/studioShortcut.d.ts +52 -0
- package/dist/studioShortcut.d.ts.map +1 -0
- package/dist/studioShortcut.js +74 -0
- package/dist/studioShortcut.js.map +1 -0
- package/package.json +2 -2
- package/src/react/DecoDocument.tsx +18 -14
- package/src/studio.ts +1 -2
- package/src/studioShortcut.ts +99 -0
package/README.md
CHANGED
|
@@ -58,7 +58,7 @@ A complete worker entry with a page cache is [`examples/tanstack-worker-smoke/sr
|
|
|
58
58
|
|
|
59
59
|
### Names and Studio's origins
|
|
60
60
|
|
|
61
|
-
The root export holds what the worker, `/server` and `DecoDocument` share, for a site's own code: the draft names (`DRAFT_PARAM` `__draft`, `DRAFT_COOKIE` `__deco_draft`), the headers the worker hands the app (`VERSION_HEADER` `x-deco-version`, `VISITOR_HEADER` `x-deco-visitor`, `ASSIGNMENTS_HEADER` `x-deco-assignments`), `draftResponseHeaders(preview)` (`max-age=0, no-cache, must-revalidate`, `Vary: Cookie`, `noindex`; pass the version, or `true` for any request with a draft signal), and Studio's origins: `STUDIO_ORIGINS`, `STUDIO_FRAME_ANCESTORS` (what the worker's `frame-ancestors` starts from) and `isStudioOrigin`; the Studio channel's exact list, `DEFAULT_STUDIO_ORIGINS` and `studioOrigins(option?)`; and `withStudioCsp(directives)`, what the worker does to the site's `csp` (Studio's origins in `script-src` and `frame-ancestors`), for a policy the site sends some other way.
|
|
61
|
+
The root export holds what the worker, `/server` and `DecoDocument` share, for a site's own code: the draft names (`DRAFT_PARAM` `__draft`, `DRAFT_COOKIE` `__deco_draft`), the headers the worker hands the app (`VERSION_HEADER` `x-deco-version`, `VISITOR_HEADER` `x-deco-visitor`, `ASSIGNMENTS_HEADER` `x-deco-assignments`), `draftResponseHeaders(preview)` (`max-age=0, no-cache, must-revalidate`, `Vary: Cookie`, `noindex`; pass the version, or `true` for any request with a draft signal), and Studio's origins: `STUDIO_ORIGINS`, `STUDIO_FRAME_ANCESTORS` (what the worker's `frame-ancestors` starts from) and `isStudioOrigin`; the Studio channel's exact list, `DEFAULT_STUDIO_ORIGINS` and `studioOrigins(option?)`; and `withStudioCsp(directives)`, what the worker does to the site's `csp` (Studio's origins in `script-src` and `frame-ancestors`), for a policy the site sends some other way.
|
|
62
62
|
|
|
63
63
|
```ts
|
|
64
64
|
import { STUDIO_ORIGINS, VERSION_HEADER } from "@decocms/tanstack";
|
|
@@ -81,7 +81,7 @@ export const startInstance = createStart(() => ({ serverFns: { fetch: decoServer
|
|
|
81
81
|
export const Route = createRootRoute({ component: () => <DecoDocument site="my-store" /> });
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
`DecoDocument` mounts
|
|
84
|
+
`DecoDocument` mounts v7's "." edit shortcut, the Studio channel and the draft badge. It is v8 only: v7's framed handler (`scrollToComponent`, `editor::rerender`) is gone, so no script on the page compares the window with `top` or `parent`, and a test runner that rewrites "frame-busting" code (Cypress's `modifyObstructiveCode`) serves the page byte for byte. The Studio channel is on every page, production included: a small inline script (about 0.7 kB gzipped) through which Studio loads its own editor code (the section wireframe, the page swap after a save) into the page when it frames it. It is the only way Studio runs code in the page: the bridge evaluates no script Studio sends. The page trusts a list of exact Studio origins: the `studioOrigins` prop when given, else the `DECO_STUDIO_ORIGIN` environment variable, comma-separated (read on the server; a local Studio, such as `http://localhost:3000`), else Studio's production and staging origins (`DEFAULT_STUDIO_ORIGINS`). Framed, the page posts `{ type: "deco:ready" }` with each of them as the target origin (only a parent at one of them receives it) and imports a module only when Studio's answer, `{ type: "deco:load", url }`, comes from exactly one of them and names a URL on the origin of that message; not framed, or framed by any other origin, it does nothing. The worker adds the same list to every HTML response's CSP: to `frame-ancestors`, and to `script-src` (or `script-src-elem`; a policy that restricts scripts only through `default-src` gets a `script-src` with its sources plus Studio's). A site that sets `studioOrigins` on `DecoDocument` sets the worker's `studioOrigins` option too; `DECO_STUDIO_ORIGIN` sets both. The inline scripts take the site's `nonce`. The message and module types are in `@decocms/blocks/protocol`. A page route returns `pathTemplate` (the page block's `path`, as `matchRoute` matched it) in its loader data, so "." on the store page opens that page in Studio's editor. A site that keeps its own document (a skip link before `<main>`, say) renders `<DecoPreview site="my-store" />` in its `<body>` instead: the shortcut, the channel, the badge and the draft they read.
|
|
85
85
|
|
|
86
86
|
## Images
|
|
87
87
|
|
|
@@ -35,12 +35,12 @@ export interface DecoPreviewProps {
|
|
|
35
35
|
/**
|
|
36
36
|
* What `DecoDocument` mounts for Studio and draft previews, for a site that
|
|
37
37
|
* keeps its own document (a skip link before `<main>`, say): the request's
|
|
38
|
-
* draft and CDN segment token published to the browser,
|
|
39
|
-
* `DraftBadge`. Render it once, in the `<body>`.
|
|
38
|
+
* draft and CDN segment token published to the browser, the "." shortcut,
|
|
39
|
+
* `StudioChannel` and `DraftBadge`. Render it once, in the `<body>`.
|
|
40
40
|
*/
|
|
41
41
|
export declare function DecoPreview({ site, editShortcut, nonce, studioOrigins }: DecoPreviewProps): import("react").JSX.Element;
|
|
42
42
|
export interface DecoDocumentProps {
|
|
43
|
-
/** The site's name in Deco (the
|
|
43
|
+
/** The site's name in Deco (the "." shortcut opens the page under it). */
|
|
44
44
|
site: string;
|
|
45
45
|
/** `<html lang>`. Default `"en"`. */
|
|
46
46
|
lang?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DecoDocument.d.ts","sourceRoot":"","sources":["../../src/react/DecoDocument.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DecoDocument.d.ts","sourceRoot":"","sources":["../../src/react/Dec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S,MAAM,EAAE,CAAC;IAClC,4DAA4D;IAC5D,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,wBAAgB,YAAY,CAAC,EAC3B,IAAI,EACJ,IAAW,EACX,aAA+C,EAC/C,OAAY,EACZ,UAAgB,EAChB,MAAe,EACf,YAAY,EACZ,KAAK,EACL,aAAa,EACb,QAAQ,GACT,EAAE,iBAAiB,+BA8CnB"}
|
|
@@ -9,23 +9,28 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
|
|
|
9
9
|
* keeps its height while the next page loads;
|
|
10
10
|
* - the CDN segment token and the draft this request renders, for
|
|
11
11
|
* `decoServerFnFetch` and the draft badge;
|
|
12
|
-
* - `StudioBridge` (in Studio's frame it answers Studio's origins,
|
|
13
|
-
* `STUDIO_ORIGINS`; outside it, "." opens the page in Studio's editor, with
|
|
14
|
-
* the page's `pathTemplate` from the route's loader data) and `DraftBadge`
|
|
15
|
-
* (only on a draft page outside Studio's frame), from `@decocms/blocks/preview`;
|
|
16
12
|
* - `StudioChannel` (every page, production included: framed by one of
|
|
17
13
|
* Studio's origins, `studioOrigins` / `DECO_STUDIO_ORIGIN` / Studio's
|
|
18
14
|
* production and staging origins, each exact, it loads the editor's own
|
|
19
|
-
* modules from that origin; otherwise it does nothing)
|
|
20
|
-
*
|
|
15
|
+
* modules from that origin; otherwise it does nothing) and `DraftBadge`
|
|
16
|
+
* (only on a draft page outside Studio's frame), from
|
|
17
|
+
* `@decocms/blocks/preview`. The worker adds the same origins to the
|
|
18
|
+
* page's CSP `script-src` and `frame-ancestors`;
|
|
19
|
+
* - v7's "." edit shortcut (`../studioShortcut.ts`: outside Studio's frame,
|
|
20
|
+
* "." opens the page in Studio's editor, with the page's `pathTemplate`
|
|
21
|
+
* from the route's loader data). v8 only: v7's framed handler
|
|
22
|
+
* (`scrollToComponent`, `editor::rerender`) is gone, so no script compares
|
|
23
|
+
* the window with `top` or `parent` in a form a test runner's
|
|
24
|
+
* "frame-busting" rewrite matches (Cypress's `modifyObstructiveCode`).
|
|
21
25
|
*
|
|
22
26
|
* A site that keeps its own document renders `DecoPreview` in its `<body>`
|
|
23
27
|
* for the bridge, the badge and the draft they read.
|
|
24
28
|
*/
|
|
25
|
-
import { DraftBadge,
|
|
29
|
+
import { DraftBadge, StudioChannel } from "@decocms/blocks/preview";
|
|
26
30
|
import { HeadContent, Outlet, ScriptOnce, Scripts, useRouterState } from "@tanstack/react-router";
|
|
27
31
|
import { useEffect, useRef, useState } from "react";
|
|
28
|
-
import {
|
|
32
|
+
import { studioOrigins } from "../studio.js";
|
|
33
|
+
import { StudioShortcut } from "../studioShortcut.js";
|
|
29
34
|
import { pageValues, publishScript } from "./pageValues.js";
|
|
30
35
|
import { DATA_EVENT_OBSERVER, eventsBootstrap, PROGRESS_CSS } from "./scripts.js";
|
|
31
36
|
/** A loading bar at the top of the page during client-side navigation. */
|
|
@@ -66,18 +71,18 @@ function studioPageOf(matches) {
|
|
|
66
71
|
}
|
|
67
72
|
return undefined;
|
|
68
73
|
}
|
|
69
|
-
/** The
|
|
74
|
+
/** The "." shortcut, with the page on screen, the Studio channel, and the badge for the request's draft. */
|
|
70
75
|
function StudioPieces({ site, editShortcut, nonce, studioOrigins: origins, draft, draftUnavailable, }) {
|
|
71
76
|
// Two primitives, so a navigation that keeps the page doesn't re-render the document.
|
|
72
77
|
const pathTemplate = useRouterState({ select: (s) => studioPageOf(s.matches)?.pathTemplate });
|
|
73
78
|
const pageId = useRouterState({ select: (s) => studioPageOf(s.matches)?.id });
|
|
74
|
-
return (_jsxs(_Fragment, { children: [_jsx(
|
|
79
|
+
return (_jsxs(_Fragment, { children: [_jsx(StudioShortcut, { site: site, editShortcut: editShortcut, page: { pathTemplate, id: pageId }, nonce: nonce }), _jsx(StudioChannel, { studioOrigins: studioOrigins(origins), nonce: nonce }), _jsx(DraftBadge, { pointer: draft ?? null, unavailable: draftUnavailable })] }));
|
|
75
80
|
}
|
|
76
81
|
/**
|
|
77
82
|
* What `DecoDocument` mounts for Studio and draft previews, for a site that
|
|
78
83
|
* keeps its own document (a skip link before `<main>`, say): the request's
|
|
79
|
-
* draft and CDN segment token published to the browser,
|
|
80
|
-
* `DraftBadge`. Render it once, in the `<body>`.
|
|
84
|
+
* draft and CDN segment token published to the browser, the "." shortcut,
|
|
85
|
+
* `StudioChannel` and `DraftBadge`. Render it once, in the `<body>`.
|
|
81
86
|
*/
|
|
82
87
|
export function DecoPreview({ site, editShortcut, nonce, studioOrigins }) {
|
|
83
88
|
const values = pageValues();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DecoDocument.js","sourceRoot":"","sources":["../../src/react/DecoDocument.tsx"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"DecoDocument.js","sourceRoot":"","sources":["../../src/react/DecoDocument.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAClG,OAAO,EAAkB,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAalF,0EAA0E;AAC1E,MAAM,UAAU,kBAAkB,CAAC,EACjC,KAAK,GAAG,8CAA8C,GAC9B;IACxB,MAAM,SAAS,GAAG,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,S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,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;IAEjB,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;IAC5B,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IACtC,MAAM,KAAK,GAAG,MAAM,CAAC;IAErB,OAAO,CACL,gBAAM,IAAI,EAAE,IAAI,gBAAa,OAAO,EAAC,wBAAwB,mBAC3D,2BACE,KAAC,WAAW,KAAG,EACd,OAAO,IAAI,CACV,iBACE,KAAK,EAAE,KAAK,EACZ,wBAAwB,QACxB,uBAAuB,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,GAC5C,CACH,IACI,EACP,gBAAM,SAAS,EAAE,aAAa,EAAE,wBAAwB,mBACtD,KAAC,UAAU,cAAE,eAAe,CAAC,OAAO,CAAC,GAAc,EACnD,KAAC,kBAAkB,KAAG,EACtB,KAAC,KAAK,cACJ,KAAC,YAAY,KAAG,GACV,EACP,QAAQ,EACT,KAAC,YAAY,IACX,IAAI,EAAE,IAAI,EACV,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,KAAK,EACZ,aAAa,EAAE,aAAa,EAC5B,KAAK,EAAE,MAAM,CAAC,KAAK,EACnB,gBAAgB,EAAE,MAAM,CAAC,gBAAgB,GACzC,EACF,KAAC,UAAU,cAAE,mBAAmB,GAAc,EAC9C,KAAC,OAAO,KAAG,IACN,IACF,CACR,CAAC;AACJ,CAAC"}
|
package/dist/studio.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Where Deco Studio runs: the origins its site editor frames a site from and
|
|
3
3
|
* talks to it from (`postMessage`). One list, so the worker's
|
|
4
|
-
* `frame-ancestors` and
|
|
5
|
-
* apart.
|
|
4
|
+
* `frame-ancestors` and a site's own never drift apart.
|
|
6
5
|
*
|
|
7
6
|
* No module state and no framework code: safe in a browser bundle.
|
|
8
7
|
*/
|
package/dist/studio.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"studio.d.ts","sourceRoot":"","sources":["../src/studio.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"studio.d.ts","sourceRoot":"","sources":["../src/studio.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAK1C,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,EAAE,SAAS,MAAM,EAIlD,CAAC;AAEH,kCAAkC;AAClC,eAAO,MAAM,aAAa,+BAA+B,CAAC;AAE1D;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,SAAS,MAAM,EAGlD,CAAC;AAkBH;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAAC,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,MAAM,EAAE,CAK3E;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAazE"}
|
package/dist/studio.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Where Deco Studio runs: the origins its site editor frames a site from and
|
|
3
3
|
* talks to it from (`postMessage`). One list, so the worker's
|
|
4
|
-
* `frame-ancestors` and
|
|
5
|
-
* apart.
|
|
4
|
+
* `frame-ancestors` and a site's own never drift apart.
|
|
6
5
|
*
|
|
7
6
|
* No module state and no framework code: safe in a browser bundle.
|
|
8
7
|
*/
|
package/dist/studio.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"studio.js","sourceRoot":"","sources":["../src/studio.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"studio.js","sourceRoot":"","sources":["../src/studio.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAsB,MAAM,CAAC,MA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AE,GAAG,EAAE,kBAAkB,CAAC;IAC5B,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC;IAC/E,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAC1D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,MAAiC;IAC9D,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,EAAE;QAAE,OAAO,KAAK,CAAC;IAC9D,IAAI,GAAQ,CAAC;IACb,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IACxB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;IACD,8EAA8E;IAC9E,yBAAyB;IACzB,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,KAAK,EAAE;QAAE,OAAO,KAAK,CAAC;IACxF,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAC;IAC1B,OAAO,IAAI,KAAK,aAAa,IAAI,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;AACjE,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v7's "." edit shortcut, alone: on a page that isn't framed, "." (or
|
|
3
|
+
* Ctrl+Shift+E) opens the page in Studio's editor (`/choose-editor`, which
|
|
4
|
+
* signs a visitor who isn't signed in in first), and Ctrl or Cmd+"." opens it
|
|
5
|
+
* in a new tab. In a frame it does nothing: Studio's editor reaches a framed
|
|
6
|
+
* page through the Studio channel (`StudioChannel`) only.
|
|
7
|
+
*
|
|
8
|
+
* Safe under a test runner that rewrites "frame-busting" code in the HTML it
|
|
9
|
+
* proxies (Cypress's `modifyObstructiveCode`): the script compares no window
|
|
10
|
+
* with `top` or `parent` in a form those rewrites match, so the HTML reaches
|
|
11
|
+
* the browser byte for byte (a rewrite changes the length of a React Server
|
|
12
|
+
* Components payload that carries the script and breaks the page).
|
|
13
|
+
*
|
|
14
|
+
* A key typed in a field is left alone, also in a field inside an open shadow
|
|
15
|
+
* root (a third-party widget's form): its events reach the document with the
|
|
16
|
+
* host as their target, so the script reads the field from the event's
|
|
17
|
+
* composed path.
|
|
18
|
+
*
|
|
19
|
+
* The page it sends: the last `StudioPage` marker the page rendered, else the
|
|
20
|
+
* `page` the binding passed, read at the keypress. An inline script with no
|
|
21
|
+
* hooks, so a Server Component renders it; its settings travel in `data-*`
|
|
22
|
+
* attributes (the same as v7's bridge's: `data-deco-studio-bridge`,
|
|
23
|
+
* `data-site`, `data-shortcut`, `data-path-template`, `data-page-id`) and the
|
|
24
|
+
* script itself is static.
|
|
25
|
+
*
|
|
26
|
+
* `@decocms/nextjs` and `@decocms/tanstack` each carry this file (neither
|
|
27
|
+
* imports the other); tests/studio-shortcut.test.ts keeps the two the same.
|
|
28
|
+
*/
|
|
29
|
+
import { type ReactNode } from "react";
|
|
30
|
+
/** The page the "." shortcut opens in Studio. */
|
|
31
|
+
interface ShortcutPage {
|
|
32
|
+
/** The page block's `path`, as `matchRoute` matched it (`/products/:slug/p`, `/*`). */
|
|
33
|
+
pathTemplate?: string;
|
|
34
|
+
/** The page block's id, when the site knows it. */
|
|
35
|
+
id?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface StudioShortcutProps {
|
|
38
|
+
/** The site's name in Deco (the shortcut sends it to Studio). */
|
|
39
|
+
site: string;
|
|
40
|
+
/** On by default; `false` turns it off. */
|
|
41
|
+
editShortcut?: boolean;
|
|
42
|
+
/** The page on screen, when the component that renders the shortcut knows it. */
|
|
43
|
+
page?: ShortcutPage;
|
|
44
|
+
/** The CSP nonce for the inline script, when the site sends one. */
|
|
45
|
+
nonce?: string;
|
|
46
|
+
}
|
|
47
|
+
/** The browser side. Static: everything it needs comes from the script element's attributes. */
|
|
48
|
+
export declare const STUDIO_SHORTCUT_SCRIPT = "(function(){\nvar s=document.currentScript,w=window,p=w.parent;\nif(!s||p!==w||w.__decoStudioShortcut||!s.hasAttribute(\"data-shortcut\"))return;\nw.__decoStudioShortcut=true;\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}\ndocument.addEventListener(\"keydown\",function(e){\n var t=e.composedPath?e.composedPath()[0]: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 g=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(g.id)h.searchParams.set(\"pageId\",g.id);\n h.searchParams.set(\"path\",location.pathname+location.search);\n h.searchParams.set(\"pathTemplate\",g.t||\"/*\");\n if((e.ctrlKey||e.metaKey)&&e.key===\".\"){w.open(h.toString(),\"_blank\");return}\n location.href=h.toString();\n});\n})();";
|
|
49
|
+
/** The "." shortcut's script. Render it once, in the `<body>`. */
|
|
50
|
+
export declare function StudioShortcut({ site, editShortcut, page, nonce, }: StudioShortcutProps): ReactNode;
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=studioShortcut.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"studioShortcut.d.ts","sourceRoot":"","sources":["../src/studioShortcut.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,EAAiB,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEtD,iDAAiD;AACjD,UAAU,YAAY;IACpB,uFAAuF;IACvF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mDAAmD;IACnD,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,mBAAmB;IAClC,iEAAiE;IACjE,IAAI,EAAE,MAAM,CAAC;IACb,2CAA2C;IAC3C,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,iFAAiF;IACjF,IAAI,CAAC,EAAE,YAAY,CAAC;IACpB,oEAAoE;IACpE,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,gGAAgG;AAChG,eAAO,MAAM,sBAAsB,s2CAyB7B,CAAC;AAEP,kEAAkE;AAClE,wBAAgB,cAAc,CAAC,EAC7B,IAAI,EACJ,YAAmB,EACnB,IAAI,EACJ,KAAK,GACN,EAAE,mBAAmB,GAAG,SAAS,CAejC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v7's "." edit shortcut, alone: on a page that isn't framed, "." (or
|
|
3
|
+
* Ctrl+Shift+E) opens the page in Studio's editor (`/choose-editor`, which
|
|
4
|
+
* signs a visitor who isn't signed in in first), and Ctrl or Cmd+"." opens it
|
|
5
|
+
* in a new tab. In a frame it does nothing: Studio's editor reaches a framed
|
|
6
|
+
* page through the Studio channel (`StudioChannel`) only.
|
|
7
|
+
*
|
|
8
|
+
* Safe under a test runner that rewrites "frame-busting" code in the HTML it
|
|
9
|
+
* proxies (Cypress's `modifyObstructiveCode`): the script compares no window
|
|
10
|
+
* with `top` or `parent` in a form those rewrites match, so the HTML reaches
|
|
11
|
+
* the browser byte for byte (a rewrite changes the length of a React Server
|
|
12
|
+
* Components payload that carries the script and breaks the page).
|
|
13
|
+
*
|
|
14
|
+
* A key typed in a field is left alone, also in a field inside an open shadow
|
|
15
|
+
* root (a third-party widget's form): its events reach the document with the
|
|
16
|
+
* host as their target, so the script reads the field from the event's
|
|
17
|
+
* composed path.
|
|
18
|
+
*
|
|
19
|
+
* The page it sends: the last `StudioPage` marker the page rendered, else the
|
|
20
|
+
* `page` the binding passed, read at the keypress. An inline script with no
|
|
21
|
+
* hooks, so a Server Component renders it; its settings travel in `data-*`
|
|
22
|
+
* attributes (the same as v7's bridge's: `data-deco-studio-bridge`,
|
|
23
|
+
* `data-site`, `data-shortcut`, `data-path-template`, `data-page-id`) and the
|
|
24
|
+
* script itself is static.
|
|
25
|
+
*
|
|
26
|
+
* `@decocms/nextjs` and `@decocms/tanstack` each carry this file (neither
|
|
27
|
+
* imports the other); tests/studio-shortcut.test.ts keeps the two the same.
|
|
28
|
+
*/
|
|
29
|
+
import { createElement } from "react";
|
|
30
|
+
/** The browser side. Static: everything it needs comes from the script element's attributes. */
|
|
31
|
+
export const STUDIO_SHORTCUT_SCRIPT = `(function(){
|
|
32
|
+
var s=document.currentScript,w=window,p=w.parent;
|
|
33
|
+
if(!s||p!==w||w.__decoStudioShortcut||!s.hasAttribute("data-shortcut"))return;
|
|
34
|
+
w.__decoStudioShortcut=true;
|
|
35
|
+
var site=s.getAttribute("data-site")||"";
|
|
36
|
+
function page(){
|
|
37
|
+
var all=document.querySelectorAll("[data-deco-page]"),el=all.length?all[all.length-1]:null;
|
|
38
|
+
if(!el||!el.getAttribute("data-path-template")){el=document.querySelector("script[data-deco-studio-bridge]")||s}
|
|
39
|
+
return{t:el.getAttribute("data-path-template")||"",id:el.getAttribute("data-page-id")||""};
|
|
40
|
+
}
|
|
41
|
+
document.addEventListener("keydown",function(e){
|
|
42
|
+
var t=e.composedPath?e.composedPath()[0]:e.target;
|
|
43
|
+
if(e.defaultPrevented||(t&&(t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.tagName==="SELECT"||t.isContentEditable)))return;
|
|
44
|
+
if(e.key!=="."&&!(e.ctrlKey&&e.shiftKey&&e.key==="E"))return;
|
|
45
|
+
e.preventDefault();
|
|
46
|
+
e.stopPropagation();
|
|
47
|
+
var g=page(),h=new URL("https://studio.decocms.com/choose-editor");
|
|
48
|
+
h.searchParams.set("site",site);
|
|
49
|
+
h.searchParams.set("domain",location.origin);
|
|
50
|
+
if(g.id)h.searchParams.set("pageId",g.id);
|
|
51
|
+
h.searchParams.set("path",location.pathname+location.search);
|
|
52
|
+
h.searchParams.set("pathTemplate",g.t||"/*");
|
|
53
|
+
if((e.ctrlKey||e.metaKey)&&e.key==="."){w.open(h.toString(),"_blank");return}
|
|
54
|
+
location.href=h.toString();
|
|
55
|
+
});
|
|
56
|
+
})();`;
|
|
57
|
+
/** The "." shortcut's script. Render it once, in the `<body>`. */
|
|
58
|
+
export function StudioShortcut({ site, editShortcut = true, page, nonce, }) {
|
|
59
|
+
return createElement("script", {
|
|
60
|
+
"data-deco-studio-bridge": "",
|
|
61
|
+
"data-site": site,
|
|
62
|
+
"data-shortcut": editShortcut ? "" : undefined,
|
|
63
|
+
// Read on each keypress, so a client-side navigation that re-renders the
|
|
64
|
+
// script with the next page updates them.
|
|
65
|
+
"data-path-template": page?.pathTemplate || undefined,
|
|
66
|
+
"data-page-id": page?.id || undefined,
|
|
67
|
+
nonce,
|
|
68
|
+
// Browsers hide a nonce from the DOM after parsing, which React would
|
|
69
|
+
// report as a hydration mismatch.
|
|
70
|
+
suppressHydrationWarning: true,
|
|
71
|
+
dangerouslySetInnerHTML: { __html: STUDIO_SHORTCUT_SCRIPT },
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=studioShortcut.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"studioShortcut.js","sourceRoot":"","sources":["../src/studioShortcut.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,EAAE,aAAa,EAAkB,MAAM,OAAO,CAAC;AAqBtD,gGAAgG;AAChG,MAAM,CAAC,MAAM,sBAAsB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;MAyBhC,CAAC;AAEP,kEAAkE;AAClE,MAAM,UAAU,cAAc,CAAC,EAC7B,IAAI,EACJ,YAAY,GAAG,IAAI,EACnB,IAAI,EACJ,KAAK,GACe;IACpB,OAAO,aAAa,CAAC,QAAQ,EAAE;QAC7B,yBAAyB,EAAE,EAAE;QAC7B,WAAW,EAAE,IAAI;QACjB,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,sBAAsB,EAAE;KAC5D,CAAC,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/tanstack",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.15.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=24"
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
}
|
|
95
95
|
},
|
|
96
96
|
"devDependencies": {
|
|
97
|
-
"@decocms/blocks": "8.
|
|
97
|
+
"@decocms/blocks": "8.15.0",
|
|
98
98
|
"@tanstack/react-router": "1.170.39",
|
|
99
99
|
"@tanstack/react-start": "1.168.58",
|
|
100
100
|
"@types/react": "^19.0.0",
|
|
@@ -8,23 +8,28 @@
|
|
|
8
8
|
* keeps its height while the next page loads;
|
|
9
9
|
* - the CDN segment token and the draft this request renders, for
|
|
10
10
|
* `decoServerFnFetch` and the draft badge;
|
|
11
|
-
* - `StudioBridge` (in Studio's frame it answers Studio's origins,
|
|
12
|
-
* `STUDIO_ORIGINS`; outside it, "." opens the page in Studio's editor, with
|
|
13
|
-
* the page's `pathTemplate` from the route's loader data) and `DraftBadge`
|
|
14
|
-
* (only on a draft page outside Studio's frame), from `@decocms/blocks/preview`;
|
|
15
11
|
* - `StudioChannel` (every page, production included: framed by one of
|
|
16
12
|
* Studio's origins, `studioOrigins` / `DECO_STUDIO_ORIGIN` / Studio's
|
|
17
13
|
* production and staging origins, each exact, it loads the editor's own
|
|
18
|
-
* modules from that origin; otherwise it does nothing)
|
|
19
|
-
*
|
|
14
|
+
* modules from that origin; otherwise it does nothing) and `DraftBadge`
|
|
15
|
+
* (only on a draft page outside Studio's frame), from
|
|
16
|
+
* `@decocms/blocks/preview`. The worker adds the same origins to the
|
|
17
|
+
* page's CSP `script-src` and `frame-ancestors`;
|
|
18
|
+
* - v7's "." edit shortcut (`../studioShortcut.ts`: outside Studio's frame,
|
|
19
|
+
* "." opens the page in Studio's editor, with the page's `pathTemplate`
|
|
20
|
+
* from the route's loader data). v8 only: v7's framed handler
|
|
21
|
+
* (`scrollToComponent`, `editor::rerender`) is gone, so no script compares
|
|
22
|
+
* the window with `top` or `parent` in a form a test runner's
|
|
23
|
+
* "frame-busting" rewrite matches (Cypress's `modifyObstructiveCode`).
|
|
20
24
|
*
|
|
21
25
|
* A site that keeps its own document renders `DecoPreview` in its `<body>`
|
|
22
26
|
* for the bridge, the badge and the draft they read.
|
|
23
27
|
*/
|
|
24
|
-
import { DraftBadge,
|
|
28
|
+
import { DraftBadge, StudioChannel } from "@decocms/blocks/preview";
|
|
25
29
|
import { HeadContent, Outlet, ScriptOnce, Scripts, useRouterState } from "@tanstack/react-router";
|
|
26
30
|
import { type ReactNode, useEffect, useRef, useState } from "react";
|
|
27
|
-
import {
|
|
31
|
+
import { studioOrigins } from "../studio.ts";
|
|
32
|
+
import { StudioShortcut } from "../studioShortcut.ts";
|
|
28
33
|
import { pageValues, publishScript } from "./pageValues.ts";
|
|
29
34
|
import { DATA_EVENT_OBSERVER, eventsBootstrap, PROGRESS_CSS } from "./scripts.ts";
|
|
30
35
|
|
|
@@ -100,7 +105,7 @@ function studioPageOf(
|
|
|
100
105
|
return undefined;
|
|
101
106
|
}
|
|
102
107
|
|
|
103
|
-
/** The
|
|
108
|
+
/** The "." shortcut, with the page on screen, the Studio channel, and the badge for the request's draft. */
|
|
104
109
|
function StudioPieces({
|
|
105
110
|
site,
|
|
106
111
|
editShortcut,
|
|
@@ -117,9 +122,8 @@ function StudioPieces({
|
|
|
117
122
|
const pageId = useRouterState({ select: (s) => studioPageOf(s.matches)?.id });
|
|
118
123
|
return (
|
|
119
124
|
<>
|
|
120
|
-
<
|
|
125
|
+
<StudioShortcut
|
|
121
126
|
site={site}
|
|
122
|
-
trustedOrigins={STUDIO_ORIGINS}
|
|
123
127
|
editShortcut={editShortcut}
|
|
124
128
|
page={{ pathTemplate, id: pageId }}
|
|
125
129
|
nonce={nonce}
|
|
@@ -154,8 +158,8 @@ export interface DecoPreviewProps {
|
|
|
154
158
|
/**
|
|
155
159
|
* What `DecoDocument` mounts for Studio and draft previews, for a site that
|
|
156
160
|
* keeps its own document (a skip link before `<main>`, say): the request's
|
|
157
|
-
* draft and CDN segment token published to the browser,
|
|
158
|
-
* `DraftBadge`. Render it once, in the `<body>`.
|
|
161
|
+
* draft and CDN segment token published to the browser, the "." shortcut,
|
|
162
|
+
* `StudioChannel` and `DraftBadge`. Render it once, in the `<body>`.
|
|
159
163
|
*/
|
|
160
164
|
export function DecoPreview({ site, editShortcut, nonce, studioOrigins }: DecoPreviewProps) {
|
|
161
165
|
const values = pageValues();
|
|
@@ -182,7 +186,7 @@ export function DecoPreview({ site, editShortcut, nonce, studioOrigins }: DecoPr
|
|
|
182
186
|
}
|
|
183
187
|
|
|
184
188
|
export interface DecoDocumentProps {
|
|
185
|
-
/** The site's name in Deco (the
|
|
189
|
+
/** The site's name in Deco (the "." shortcut opens the page under it). */
|
|
186
190
|
site: string;
|
|
187
191
|
/** `<html lang>`. Default `"en"`. */
|
|
188
192
|
lang?: string;
|
package/src/studio.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Where Deco Studio runs: the origins its site editor frames a site from and
|
|
3
3
|
* talks to it from (`postMessage`). One list, so the worker's
|
|
4
|
-
* `frame-ancestors` and
|
|
5
|
-
* apart.
|
|
4
|
+
* `frame-ancestors` and a site's own never drift apart.
|
|
6
5
|
*
|
|
7
6
|
* No module state and no framework code: safe in a browser bundle.
|
|
8
7
|
*/
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v7's "." edit shortcut, alone: on a page that isn't framed, "." (or
|
|
3
|
+
* Ctrl+Shift+E) opens the page in Studio's editor (`/choose-editor`, which
|
|
4
|
+
* signs a visitor who isn't signed in in first), and Ctrl or Cmd+"." opens it
|
|
5
|
+
* in a new tab. In a frame it does nothing: Studio's editor reaches a framed
|
|
6
|
+
* page through the Studio channel (`StudioChannel`) only.
|
|
7
|
+
*
|
|
8
|
+
* Safe under a test runner that rewrites "frame-busting" code in the HTML it
|
|
9
|
+
* proxies (Cypress's `modifyObstructiveCode`): the script compares no window
|
|
10
|
+
* with `top` or `parent` in a form those rewrites match, so the HTML reaches
|
|
11
|
+
* the browser byte for byte (a rewrite changes the length of a React Server
|
|
12
|
+
* Components payload that carries the script and breaks the page).
|
|
13
|
+
*
|
|
14
|
+
* A key typed in a field is left alone, also in a field inside an open shadow
|
|
15
|
+
* root (a third-party widget's form): its events reach the document with the
|
|
16
|
+
* host as their target, so the script reads the field from the event's
|
|
17
|
+
* composed path.
|
|
18
|
+
*
|
|
19
|
+
* The page it sends: the last `StudioPage` marker the page rendered, else the
|
|
20
|
+
* `page` the binding passed, read at the keypress. An inline script with no
|
|
21
|
+
* hooks, so a Server Component renders it; its settings travel in `data-*`
|
|
22
|
+
* attributes (the same as v7's bridge's: `data-deco-studio-bridge`,
|
|
23
|
+
* `data-site`, `data-shortcut`, `data-path-template`, `data-page-id`) and the
|
|
24
|
+
* script itself is static.
|
|
25
|
+
*
|
|
26
|
+
* `@decocms/nextjs` and `@decocms/tanstack` each carry this file (neither
|
|
27
|
+
* imports the other); tests/studio-shortcut.test.ts keeps the two the same.
|
|
28
|
+
*/
|
|
29
|
+
import { createElement, type ReactNode } from "react";
|
|
30
|
+
|
|
31
|
+
/** The page the "." shortcut opens in Studio. */
|
|
32
|
+
interface ShortcutPage {
|
|
33
|
+
/** The page block's `path`, as `matchRoute` matched it (`/products/:slug/p`, `/*`). */
|
|
34
|
+
pathTemplate?: string;
|
|
35
|
+
/** The page block's id, when the site knows it. */
|
|
36
|
+
id?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface StudioShortcutProps {
|
|
40
|
+
/** The site's name in Deco (the shortcut sends it to Studio). */
|
|
41
|
+
site: string;
|
|
42
|
+
/** On by default; `false` turns it off. */
|
|
43
|
+
editShortcut?: boolean;
|
|
44
|
+
/** The page on screen, when the component that renders the shortcut knows it. */
|
|
45
|
+
page?: ShortcutPage;
|
|
46
|
+
/** The CSP nonce for the inline script, when the site sends one. */
|
|
47
|
+
nonce?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The browser side. Static: everything it needs comes from the script element's attributes. */
|
|
51
|
+
export const STUDIO_SHORTCUT_SCRIPT = `(function(){
|
|
52
|
+
var s=document.currentScript,w=window,p=w.parent;
|
|
53
|
+
if(!s||p!==w||w.__decoStudioShortcut||!s.hasAttribute("data-shortcut"))return;
|
|
54
|
+
w.__decoStudioShortcut=true;
|
|
55
|
+
var site=s.getAttribute("data-site")||"";
|
|
56
|
+
function page(){
|
|
57
|
+
var all=document.querySelectorAll("[data-deco-page]"),el=all.length?all[all.length-1]:null;
|
|
58
|
+
if(!el||!el.getAttribute("data-path-template")){el=document.querySelector("script[data-deco-studio-bridge]")||s}
|
|
59
|
+
return{t:el.getAttribute("data-path-template")||"",id:el.getAttribute("data-page-id")||""};
|
|
60
|
+
}
|
|
61
|
+
document.addEventListener("keydown",function(e){
|
|
62
|
+
var t=e.composedPath?e.composedPath()[0]:e.target;
|
|
63
|
+
if(e.defaultPrevented||(t&&(t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.tagName==="SELECT"||t.isContentEditable)))return;
|
|
64
|
+
if(e.key!=="."&&!(e.ctrlKey&&e.shiftKey&&e.key==="E"))return;
|
|
65
|
+
e.preventDefault();
|
|
66
|
+
e.stopPropagation();
|
|
67
|
+
var g=page(),h=new URL("https://studio.decocms.com/choose-editor");
|
|
68
|
+
h.searchParams.set("site",site);
|
|
69
|
+
h.searchParams.set("domain",location.origin);
|
|
70
|
+
if(g.id)h.searchParams.set("pageId",g.id);
|
|
71
|
+
h.searchParams.set("path",location.pathname+location.search);
|
|
72
|
+
h.searchParams.set("pathTemplate",g.t||"/*");
|
|
73
|
+
if((e.ctrlKey||e.metaKey)&&e.key==="."){w.open(h.toString(),"_blank");return}
|
|
74
|
+
location.href=h.toString();
|
|
75
|
+
});
|
|
76
|
+
})();`;
|
|
77
|
+
|
|
78
|
+
/** The "." shortcut's script. Render it once, in the `<body>`. */
|
|
79
|
+
export function StudioShortcut({
|
|
80
|
+
site,
|
|
81
|
+
editShortcut = true,
|
|
82
|
+
page,
|
|
83
|
+
nonce,
|
|
84
|
+
}: StudioShortcutProps): ReactNode {
|
|
85
|
+
return createElement("script", {
|
|
86
|
+
"data-deco-studio-bridge": "",
|
|
87
|
+
"data-site": site,
|
|
88
|
+
"data-shortcut": editShortcut ? "" : undefined,
|
|
89
|
+
// Read on each keypress, so a client-side navigation that re-renders the
|
|
90
|
+
// script with the next page updates them.
|
|
91
|
+
"data-path-template": page?.pathTemplate || undefined,
|
|
92
|
+
"data-page-id": page?.id || undefined,
|
|
93
|
+
nonce,
|
|
94
|
+
// Browsers hide a nonce from the DOM after parsing, which React would
|
|
95
|
+
// report as a hydration mismatch.
|
|
96
|
+
suppressHydrationWarning: true,
|
|
97
|
+
dangerouslySetInnerHTML: { __html: STUDIO_SHORTCUT_SCRIPT },
|
|
98
|
+
});
|
|
99
|
+
}
|