@decocms/tanstack 8.1.0-next.0 → 8.5.1
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 +79 -0
- package/dist/draft.d.ts +33 -0
- package/dist/draft.d.ts.map +1 -0
- package/dist/draft.js +41 -0
- package/dist/draft.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/react/DecoDocument.d.ts +61 -0
- package/dist/react/DecoDocument.d.ts.map +1 -0
- package/dist/react/DecoDocument.js +96 -0
- package/dist/react/DecoDocument.js.map +1 -0
- package/dist/react/Image.d.ts +96 -0
- package/dist/react/Image.d.ts.map +1 -0
- package/dist/react/Image.js +79 -0
- package/dist/react/Image.js.map +1 -0
- package/dist/react/index.d.ts +7 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +7 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/pageValues.d.ts +10 -0
- package/dist/react/pageValues.d.ts.map +1 -0
- package/dist/react/pageValues.js +29 -0
- package/dist/react/pageValues.js.map +1 -0
- package/dist/react/scripts.d.ts +14 -0
- package/dist/react/scripts.d.ts.map +1 -0
- package/dist/react/scripts.js +96 -0
- package/dist/react/scripts.js.map +1 -0
- package/dist/router/index.d.ts +38 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/index.js +60 -0
- package/dist/router/index.js.map +1 -0
- package/dist/scope/browser.d.ts +11 -0
- package/dist/scope/browser.d.ts.map +1 -0
- package/dist/scope/browser.js +8 -0
- package/dist/scope/browser.js.map +1 -0
- package/dist/scope/server.d.ts +13 -0
- package/dist/scope/server.d.ts.map +1 -0
- package/dist/scope/server.js +26 -0
- package/dist/scope/server.js.map +1 -0
- package/dist/server/index.d.ts +27 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +31 -0
- package/dist/server/index.js.map +1 -0
- package/dist/shared.d.ts +26 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +26 -0
- package/dist/shared.js.map +1 -0
- package/dist/start/index.d.ts +9 -0
- package/dist/start/index.d.ts.map +1 -0
- package/dist/start/index.js +33 -0
- package/dist/start/index.js.map +1 -0
- package/dist/studio.d.ts +28 -0
- package/dist/studio.d.ts.map +1 -0
- package/dist/studio.js +53 -0
- package/dist/studio.js.map +1 -0
- package/dist/vite/index.d.ts +15 -0
- package/dist/vite/index.d.ts.map +1 -0
- package/dist/vite/index.js +95 -0
- package/dist/vite/index.js.map +1 -0
- package/dist/worker/cacheProfiles.d.ts +43 -0
- package/dist/worker/cacheProfiles.d.ts.map +1 -0
- package/dist/worker/cacheProfiles.js +162 -0
- package/dist/worker/cacheProfiles.js.map +1 -0
- package/dist/worker/cookies.d.ts +20 -0
- package/dist/worker/cookies.d.ts.map +1 -0
- package/dist/worker/cookies.js +69 -0
- package/dist/worker/cookies.js.map +1 -0
- package/dist/worker/drafts.d.ts +59 -0
- package/dist/worker/drafts.d.ts.map +1 -0
- package/dist/worker/drafts.js +140 -0
- package/dist/worker/drafts.js.map +1 -0
- package/dist/worker/index.d.ts +111 -0
- package/dist/worker/index.d.ts.map +1 -0
- package/dist/worker/index.js +618 -0
- package/dist/worker/index.js.map +1 -0
- package/dist/worker/security.d.ts +14 -0
- package/dist/worker/security.d.ts.map +1 -0
- package/dist/worker/security.js +48 -0
- package/dist/worker/security.js.map +1 -0
- package/dist/worker/segment.d.ts +21 -0
- package/dist/worker/segment.d.ts.map +1 -0
- package/dist/worker/segment.js +43 -0
- package/dist/worker/segment.js.map +1 -0
- package/package.json +85 -37
- package/src/draft.ts +43 -0
- package/src/index.ts +8 -61
- package/src/react/DecoDocument.tsx +234 -0
- package/src/react/Image.tsx +213 -0
- package/src/react/index.ts +24 -0
- package/src/react/pageValues.ts +35 -0
- package/src/react/scripts.ts +98 -0
- package/src/router/index.ts +80 -0
- package/src/scope/browser.ts +18 -0
- package/src/scope/server.ts +37 -0
- package/src/server/index.ts +43 -0
- package/src/shared.ts +29 -0
- package/src/start/index.ts +31 -0
- package/src/studio.ts +52 -0
- package/src/vite/index.ts +105 -0
- package/src/worker/cacheProfiles.ts +180 -0
- package/src/worker/cookies.ts +65 -0
- package/src/worker/drafts.ts +157 -0
- package/src/worker/index.ts +784 -0
- package/src/worker/security.ts +63 -0
- package/src/worker/segment.ts +49 -0
- package/src/__conformance__/observability.test.ts +0 -221
- package/src/cms/kvBlockSource.test.ts +0 -82
- package/src/cms/kvBlockSource.ts +0 -68
- package/src/daemon/auth.ts +0 -204
- package/src/daemon/fs.ts +0 -238
- package/src/daemon/index.ts +0 -8
- package/src/daemon/middleware.ts +0 -156
- package/src/daemon/tunnel.ts +0 -129
- package/src/daemon/volumes.ts +0 -366
- package/src/daemon/watch.ts +0 -272
- package/src/hooks/CdnSegmentMarker.tsx +0 -38
- package/src/hooks/DecoPageRenderer.tsx +0 -750
- package/src/hooks/DecoRootLayout.tsx +0 -192
- package/src/hooks/DraftPreviewIndicator.test.tsx +0 -60
- package/src/hooks/DraftPreviewIndicator.tsx +0 -64
- package/src/hooks/NavigationProgress.test.tsx +0 -58
- package/src/hooks/NavigationProgress.tsx +0 -63
- package/src/hooks/PreviewProviders.test.tsx +0 -42
- package/src/hooks/PreviewProviders.tsx +0 -45
- package/src/hooks/StableOutlet.tsx +0 -30
- package/src/hooks/deferredObserverTiming.test.tsx +0 -91
- package/src/hooks/index.ts +0 -10
- package/src/routes/adminRoutes.test.ts +0 -99
- package/src/routes/adminRoutes.ts +0 -153
- package/src/routes/cmsRoute.test.ts +0 -267
- package/src/routes/cmsRoute.ts +0 -1053
- package/src/routes/components.tsx +0 -57
- package/src/routes/index.ts +0 -24
- package/src/routes/pageUrl.test.ts +0 -70
- package/src/routes/pageUrl.ts +0 -55
- package/src/routes/withSiteGlobals.test.ts +0 -243
- package/src/routes/withSiteGlobals.ts +0 -243
- package/src/sdk/backgroundTasks.test.ts +0 -68
- package/src/sdk/backgroundTasks.ts +0 -38
- package/src/sdk/cdnSegment.test.ts +0 -67
- package/src/sdk/cdnSegment.ts +0 -71
- package/src/sdk/cookiePassthrough.ts +0 -58
- package/src/sdk/createInvoke.ts +0 -77
- package/src/sdk/deferredSectionLoader.test.ts +0 -94
- package/src/sdk/deferredSectionLoader.ts +0 -46
- package/src/sdk/draft.test.ts +0 -341
- package/src/sdk/draft.ts +0 -277
- package/src/sdk/draftShared.ts +0 -16
- package/src/sdk/kvHydration.test.ts +0 -371
- package/src/sdk/kvHydration.ts +0 -263
- package/src/sdk/kvRedirects.test.ts +0 -132
- package/src/sdk/kvRedirects.ts +0 -125
- package/src/sdk/outboundHeaders.test.ts +0 -113
- package/src/sdk/outboundHeaders.ts +0 -81
- package/src/sdk/router.ts +0 -101
- package/src/sdk/serverFnFetch.ts +0 -59
- package/src/sdk/speculationRules.test.ts +0 -82
- package/src/sdk/speculationRules.ts +0 -136
- package/src/sdk/startEntry.ts +0 -31
- package/src/sdk/useHydrated.ts +0 -19
- package/src/sdk/workerEntry.cacheStorage.test.ts +0 -147
- package/src/sdk/workerEntry.test.ts +0 -1033
- package/src/sdk/workerEntry.trackingCache.test.ts +0 -328
- package/src/sdk/workerEntry.ts +0 -3154
- package/src/setupFastDeploy.ts +0 -13
- package/src/v8/__conformance__/delivery.test.ts +0 -100
- package/src/v8/binding.ts +0 -70
- package/src/v8/kvLoader.bundle.test.ts +0 -42
- package/src/v8/kvLoader.test.ts +0 -74
- package/src/v8/kvLoader.ts +0 -43
- package/src/vite/plugin-scaffold-gen.test.js +0 -106
- package/src/vite/plugin.js +0 -1022
- package/src/vite/plugin.test.js +0 -238
- package/src/vite/plugin.test.ts +0 -176
- package/tsconfig.json +0 -7
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const SECURITY_HEADERS: Readonly<Record<string, string>>;
|
|
2
|
+
export interface CspOptions {
|
|
3
|
+
/** The enforced policy's directives (`frame-ancestors` is added when they have none). */
|
|
4
|
+
enforce?: string | readonly string[];
|
|
5
|
+
/** Directives sent as `Content-Security-Policy-Report-Only`. */
|
|
6
|
+
reportOnly?: string | readonly string[];
|
|
7
|
+
/** More origins that may frame the site, besides Studio's (a marketing tool's editor). */
|
|
8
|
+
frameAncestors?: readonly string[];
|
|
9
|
+
}
|
|
10
|
+
/** The `frame-ancestors` sources: Studio's, the site's own, and loopback in development. */
|
|
11
|
+
export declare function frameAncestors(csp: CspOptions | undefined, dev: boolean): string[];
|
|
12
|
+
/** Every HTML response's security headers. */
|
|
13
|
+
export declare function htmlSecurityHeaders(csp: CspOptions | undefined, dev: boolean): Record<string, string>;
|
|
14
|
+
//# sourceMappingURL=security.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../src/worker/security.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAO7D,CAAC;AAKF,MAAM,WAAW,UAAU;IACzB,yFAAyF;IACzF,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;IACrC,gEAAgE;IAChE,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAAC;IACxC,0FAA0F;IAC1F,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC;AAQD,4FAA4F;AAC5F,wBAAgB,cAAc,CAAC,GAAG,EAAE,UAAU,GAAG,SAAS,EAAE,GAAG,EAAE,OAAO,GAAG,MAAM,EAAE,CAQlF;AAED,8CAA8C;AAC9C,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,UAAU,GAAG,SAAS,EAC3B,GAAG,EAAE,OAAO,GACX,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAWxB"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The headers every HTML response carries: v7's security headers, the site's
|
|
3
|
+
* Content-Security-Policy, and `frame-ancestors` so Deco Studio's site editor
|
|
4
|
+
* (and nothing else the site doesn't name) can show the page in its frame. No
|
|
5
|
+
* `X-Frame-Options`: `frame-ancestors` supersedes it and, unlike `SAMEORIGIN`,
|
|
6
|
+
* can allow Studio's origin.
|
|
7
|
+
*/
|
|
8
|
+
import { STUDIO_FRAME_ANCESTORS } from "../studio.js";
|
|
9
|
+
export const SECURITY_HEADERS = {
|
|
10
|
+
"X-Content-Type-Options": "nosniff",
|
|
11
|
+
"Referrer-Policy": "strict-origin-when-cross-origin",
|
|
12
|
+
"Permissions-Policy": "camera=(), microphone=(), geolocation=()",
|
|
13
|
+
"X-XSS-Protection": "1; mode=block",
|
|
14
|
+
"Strict-Transport-Security": "max-age=63072000; includeSubDomains; preload",
|
|
15
|
+
"Cross-Origin-Opener-Policy": "same-origin-allow-popups",
|
|
16
|
+
};
|
|
17
|
+
/** A Studio on this machine, in local development. */
|
|
18
|
+
const LOOPBACK_ANCESTORS = ["http://localhost:*", "http://127.0.0.1:*"];
|
|
19
|
+
function directives(value) {
|
|
20
|
+
if (value === undefined)
|
|
21
|
+
return [];
|
|
22
|
+
const list = typeof value === "string" ? value.split(";") : [...value];
|
|
23
|
+
return list.map((d) => d.trim()).filter(Boolean);
|
|
24
|
+
}
|
|
25
|
+
/** The `frame-ancestors` sources: Studio's, the site's own, and loopback in development. */
|
|
26
|
+
export function frameAncestors(csp, dev) {
|
|
27
|
+
return [
|
|
28
|
+
...new Set([
|
|
29
|
+
...STUDIO_FRAME_ANCESTORS,
|
|
30
|
+
...(csp?.frameAncestors ?? []),
|
|
31
|
+
...(dev ? LOOPBACK_ANCESTORS : []),
|
|
32
|
+
]),
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
/** Every HTML response's security headers. */
|
|
36
|
+
export function htmlSecurityHeaders(csp, dev) {
|
|
37
|
+
const enforce = directives(csp?.enforce);
|
|
38
|
+
if (!enforce.some((d) => /^frame-ancestors(\s|$)/i.test(d))) {
|
|
39
|
+
enforce.push(`frame-ancestors ${frameAncestors(csp, dev).join(" ")}`);
|
|
40
|
+
}
|
|
41
|
+
const reportOnly = directives(csp?.reportOnly);
|
|
42
|
+
return {
|
|
43
|
+
...SECURITY_HEADERS,
|
|
44
|
+
"Content-Security-Policy": enforce.join("; "),
|
|
45
|
+
...(reportOnly.length ? { "Content-Security-Policy-Report-Only": reportOnly.join("; ") } : {}),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=security.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"security.js","sourceRoot":"","sources":["../../src/worker/security.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAEtD,MAAM,CAAC,MAAM,gBAAgB,GAAqC;IAChE,wBAAwB,EAAE,SAAS;IACnC,iBAAiB,EAAE,iCAAiC;IACpD,oBAAoB,EAAE,0CAA0C;IAChE,kBAAkB,EAAE,eAAe;IACnC,2BAA2B,EAAE,8CAA8C;IAC3E,4BAA4B,EAAE,0BAA0B;CACzD,CAAC;AAEF,sDAAsD;AACtD,MAAM,kBAAkB,GAAG,CAAC,oBAAoB,EAAE,oBAAoB,CAAC,CAAC;AAWxE,SAAS,UAAU,CAAC,KAA6C;IAC/D,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IACnC,MAAM,IAAI,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC;IACvE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AACnD,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,cAAc,CAAC,GAA2B,EAAE,GAAY;IACtE,OAAO;QACL,GAAG,IAAI,GAAG,CAAC;YACT,GAAG,sBAAsB;YACzB,GAAG,CAAC,GAAG,EAAE,cAAc,IAAI,EAAE,CAAC;YAC9B,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,CAAC;SACnC,CAAC;KACH,CAAC;AACJ,CAAC;AAED,8CAA8C;AAC9C,MAAM,UAAU,mBAAmB,CACjC,GAA2B,EAC3B,GAAY;IAEZ,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACzC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,yBAAyB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5D,OAAO,CAAC,IAAI,CAAC,mBAAmB,cAAc,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACxE,CAAC;IACD,MAAM,UAAU,GAAG,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IAC/C,OAAO;QACL,GAAG,gBAAgB;QACnB,yBAAyB,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;QAC7C,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,qCAAqC,EAAE,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC/F,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What splits the edge cache: the device class, plus whatever the site's
|
|
3
|
+
* `segment` option adds (a region, a sales channel, an A/B cohort). Every part
|
|
4
|
+
* is in the cache key, and in the `__cseg` token the page hands to the browser,
|
|
5
|
+
* so the CDN can cache client-side navigation data under the same split.
|
|
6
|
+
*/
|
|
7
|
+
export type Device = "mobile" | "tablet" | "desktop";
|
|
8
|
+
/** A cache split: part name to value. `device` is always present. */
|
|
9
|
+
export type Segment = Readonly<Record<string, string>>;
|
|
10
|
+
export declare function detectDevice(userAgent: string): Device;
|
|
11
|
+
export declare const DEVICES: readonly Device[];
|
|
12
|
+
/** A segment as one stable string: parts sorted by name, values URL-encoded. */
|
|
13
|
+
export declare function segmentKey(segment: Segment): string;
|
|
14
|
+
/** DJB2 over UTF-16 code units, as 8 hex digits. */
|
|
15
|
+
export declare function djb2Hex(text: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* The `__cseg` token for a segment and cache version, or `null` when there is
|
|
18
|
+
* no version to bind it to (a dev build), so stale URLs can never match.
|
|
19
|
+
*/
|
|
20
|
+
export declare function segmentToken(segment: Segment, version: string): string | null;
|
|
21
|
+
//# sourceMappingURL=segment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"segment.d.ts","sourceRoot":"","sources":["../../src/worker/segment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,MAAM,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;AAErD,qEAAqE;AACrE,MAAM,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAOvD,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAItD;AAED,eAAO,MAAM,OAAO,EAAE,SAAS,MAAM,EAAoC,CAAC;AAE1E,gFAAgF;AAChF,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAMnD;AAED,oDAAoD;AACpD,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAI5C;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAG7E"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What splits the edge cache: the device class, plus whatever the site's
|
|
3
|
+
* `segment` option adds (a region, a sales channel, an A/B cohort). Every part
|
|
4
|
+
* is in the cache key, and in the `__cseg` token the page hands to the browser,
|
|
5
|
+
* so the CDN can cache client-side navigation data under the same split.
|
|
6
|
+
*/
|
|
7
|
+
// v7's expressions (@decocms/blocks/sdk/detectDevice): tablets first, so
|
|
8
|
+
// `android(?!.*mobile)` takes Android tablets before the phone rule.
|
|
9
|
+
const MOBILE_RE = /mobile|android.*mobile|iphone|ipod|webos|blackberry|opera mini|iemobile/i;
|
|
10
|
+
const TABLET_RE = /ipad|tablet|kindle|silk|playbook|android(?!.*mobile)/i;
|
|
11
|
+
export function detectDevice(userAgent) {
|
|
12
|
+
if (TABLET_RE.test(userAgent))
|
|
13
|
+
return "tablet";
|
|
14
|
+
if (MOBILE_RE.test(userAgent))
|
|
15
|
+
return "mobile";
|
|
16
|
+
return "desktop";
|
|
17
|
+
}
|
|
18
|
+
export const DEVICES = ["mobile", "tablet", "desktop"];
|
|
19
|
+
/** A segment as one stable string: parts sorted by name, values URL-encoded. */
|
|
20
|
+
export function segmentKey(segment) {
|
|
21
|
+
return Object.keys(segment)
|
|
22
|
+
.filter((name) => segment[name] !== undefined && segment[name] !== "")
|
|
23
|
+
.sort()
|
|
24
|
+
.map((name) => `${name}=${encodeURIComponent(segment[name])}`)
|
|
25
|
+
.join("|");
|
|
26
|
+
}
|
|
27
|
+
/** DJB2 over UTF-16 code units, as 8 hex digits. */
|
|
28
|
+
export function djb2Hex(text) {
|
|
29
|
+
let hash = 5381;
|
|
30
|
+
for (let i = 0; i < text.length; i++)
|
|
31
|
+
hash = ((hash << 5) + hash + text.charCodeAt(i)) | 0;
|
|
32
|
+
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The `__cseg` token for a segment and cache version, or `null` when there is
|
|
36
|
+
* no version to bind it to (a dev build), so stale URLs can never match.
|
|
37
|
+
*/
|
|
38
|
+
export function segmentToken(segment, version) {
|
|
39
|
+
if (!version || version === "dev")
|
|
40
|
+
return null;
|
|
41
|
+
return djb2Hex(`${segmentKey(segment)}|${version}`);
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=segment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"segment.js","sourceRoot":"","sources":["../../src/worker/segment.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,yEAAyE;AACzE,qEAAqE;AACrE,MAAM,SAAS,GAAG,0EAA0E,CAAC;AAC7F,MAAM,SAAS,GAAG,uDAAuD,CAAC;AAE1E,MAAM,UAAU,YAAY,CAAC,SAAiB;IAC5C,IAAI,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC/C,IAAI,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC/C,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAAsB,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;AAE1E,gFAAgF;AAChF,MAAM,UAAU,UAAU,CAAC,OAAgB;IACzC,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;SACxB,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;SACrE,IAAI,EAAE;SACN,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,IAAI,IAAI,kBAAkB,CAAC,OAAO,CAAC,IAAI,CAAW,CAAC,EAAE,CAAC;SACvE,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC;AAED,oDAAoD;AACpD,MAAM,UAAU,OAAO,CAAC,IAAY;IAClC,IAAI,IAAI,GAAG,IAAI,CAAC;IAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC3F,OAAO,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AACpD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,OAAgB,EAAE,OAAe;IAC5D,IAAI,CAAC,OAAO,IAAI,OAAO,KAAK,KAAK;QAAE,OAAO,IAAI,CAAC;IAC/C,OAAO,OAAO,CAAC,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,OAAO,EAAE,CAAC,CAAC;AACtD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,60 +1,108 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@decocms/tanstack",
|
|
3
|
-
"version": "8.1
|
|
3
|
+
"version": "8.5.1",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"
|
|
5
|
+
"engines": {
|
|
6
|
+
"node": ">=24"
|
|
7
|
+
},
|
|
8
|
+
"description": "Deco CMS for TanStack Start on Cloudflare Workers: the worker, the root document, the router and the Vite plugin",
|
|
6
9
|
"repository": {
|
|
7
10
|
"type": "git",
|
|
8
11
|
"url": "https://github.com/decocms/blocks.git",
|
|
9
12
|
"directory": "packages/tanstack"
|
|
10
13
|
},
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
"
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"src",
|
|
17
|
+
"!src/**/*.test.ts",
|
|
18
|
+
"!src/**/*.test.tsx",
|
|
19
|
+
"!src/**/__tests__",
|
|
20
|
+
"!src/**/testing.ts"
|
|
15
21
|
],
|
|
16
22
|
"exports": {
|
|
17
|
-
".":
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"./
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"source": "./src/index.ts",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./worker": {
|
|
29
|
+
"types": "./dist/worker/index.d.ts",
|
|
30
|
+
"source": "./src/worker/index.ts",
|
|
31
|
+
"default": "./dist/worker/index.js"
|
|
32
|
+
},
|
|
33
|
+
"./server": {
|
|
34
|
+
"types": "./dist/server/index.d.ts",
|
|
35
|
+
"source": "./src/server/index.ts",
|
|
36
|
+
"default": "./dist/server/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./start": {
|
|
39
|
+
"types": "./dist/start/index.d.ts",
|
|
40
|
+
"source": "./src/start/index.ts",
|
|
41
|
+
"default": "./dist/start/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./router": {
|
|
44
|
+
"types": "./dist/router/index.d.ts",
|
|
45
|
+
"source": "./src/router/index.ts",
|
|
46
|
+
"default": "./dist/router/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./react": {
|
|
49
|
+
"types": "./dist/react/index.d.ts",
|
|
50
|
+
"source": "./src/react/index.ts",
|
|
51
|
+
"default": "./dist/react/index.js"
|
|
52
|
+
},
|
|
53
|
+
"./vite": {
|
|
54
|
+
"types": "./dist/vite/index.d.ts",
|
|
55
|
+
"source": "./src/vite/index.ts",
|
|
56
|
+
"default": "./dist/vite/index.js"
|
|
57
|
+
},
|
|
58
|
+
"./scope": {
|
|
59
|
+
"types": "./dist/scope/server.d.ts",
|
|
60
|
+
"workerd": {
|
|
61
|
+
"source": "./src/scope/server.ts",
|
|
62
|
+
"default": "./dist/scope/server.js"
|
|
63
|
+
},
|
|
64
|
+
"node": {
|
|
65
|
+
"source": "./src/scope/server.ts",
|
|
66
|
+
"default": "./dist/scope/server.js"
|
|
67
|
+
},
|
|
68
|
+
"browser": {
|
|
69
|
+
"source": "./src/scope/browser.ts",
|
|
70
|
+
"default": "./dist/scope/browser.js"
|
|
71
|
+
},
|
|
72
|
+
"default": {
|
|
73
|
+
"source": "./src/scope/server.ts",
|
|
74
|
+
"default": "./dist/scope/server.js"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
26
77
|
},
|
|
27
78
|
"scripts": {
|
|
28
|
-
"build": "tsc",
|
|
79
|
+
"build": "node ../../scripts/tsc.mjs --clean dist -p tsconfig.build.json",
|
|
80
|
+
"prepack": "npm run build",
|
|
29
81
|
"test": "vitest run --root ../.. packages/tanstack/",
|
|
30
|
-
"typecheck": "tsc
|
|
31
|
-
"lint:unused": "knip"
|
|
32
|
-
},
|
|
33
|
-
"dependencies": {
|
|
34
|
-
"@decocms/blocks": "8.1.0-next.0",
|
|
35
|
-
"@decocms/blocks-admin": "8.1.0-next.0",
|
|
36
|
-
"@decocms/blocks-cli": "8.1.0-next.0",
|
|
37
|
-
"@deco-cx/warp-node": "^0.3.16",
|
|
38
|
-
"fast-json-patch": "^3.1.0",
|
|
39
|
-
"ws": "^8.18.0"
|
|
82
|
+
"typecheck": "node ../../scripts/tsc.mjs -p tsconfig.json"
|
|
40
83
|
},
|
|
41
84
|
"peerDependencies": {
|
|
42
|
-
"@
|
|
43
|
-
"@tanstack/react-
|
|
44
|
-
"@tanstack/
|
|
85
|
+
"@decocms/blocks": "^8.5.0",
|
|
86
|
+
"@tanstack/react-router": ">=1.166.0",
|
|
87
|
+
"@tanstack/react-start": ">=1.166.0",
|
|
45
88
|
"react": "^19.0.0",
|
|
46
|
-
"
|
|
47
|
-
|
|
89
|
+
"vite": ">=7.0.0"
|
|
90
|
+
},
|
|
91
|
+
"peerDependenciesMeta": {
|
|
92
|
+
"vite": {
|
|
93
|
+
"optional": true
|
|
94
|
+
}
|
|
48
95
|
},
|
|
49
96
|
"devDependencies": {
|
|
50
|
-
"@
|
|
51
|
-
"@tanstack/
|
|
97
|
+
"@decocms/blocks": "8.5.1",
|
|
98
|
+
"@tanstack/react-router": "1.170.39",
|
|
99
|
+
"@tanstack/react-start": "1.168.58",
|
|
52
100
|
"@types/react": "^19.0.0",
|
|
53
101
|
"@types/react-dom": "^19.0.0",
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"vite": "
|
|
102
|
+
"esbuild": "^0.27.3",
|
|
103
|
+
"react": "19.2.7",
|
|
104
|
+
"react-dom": "19.2.7",
|
|
105
|
+
"vite": "^8.0.1"
|
|
58
106
|
},
|
|
59
107
|
"publishConfig": {
|
|
60
108
|
"registry": "https://registry.npmjs.org",
|
package/src/draft.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The draft names and headers of a Deco TanStack site: the `?__draft=` link,
|
|
3
|
+
* the cookie that keeps a preview going, the request header the worker hands
|
|
4
|
+
* the app, and the response headers of a page rendered from a draft. The
|
|
5
|
+
* worker reads and writes them (`./worker/drafts.ts`); the app reads the
|
|
6
|
+
* header (`@decocms/tanstack/server`). No imports, no state: safe in every
|
|
7
|
+
* bundle.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The query parameter a draft link carries (`?__draft=<pointer>`, or `off` to
|
|
12
|
+
* end a preview). The worker reads it after its host check; reading it
|
|
13
|
+
* directly would skip that check.
|
|
14
|
+
*/
|
|
15
|
+
export const DRAFT_PARAM = "__draft";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The cookie that keeps a preview going after the first draft link. Like
|
|
19
|
+
* {@link DRAFT_PARAM}, the worker reads it after its host check.
|
|
20
|
+
*/
|
|
21
|
+
export const DRAFT_COOKIE = "__deco_draft";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The request header the worker sets on the request it hands the app once it
|
|
25
|
+
* accepted the draft: the pointer, already checked. The worker removes any
|
|
26
|
+
* copy that arrives from outside, so a client can't send one itself.
|
|
27
|
+
*/
|
|
28
|
+
export const DRAFT_HEADER = "x-deco-draft";
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The response headers of a page rendered from a draft: never stored by a
|
|
32
|
+
* browser or a CDN (`Cache-Control: no-store, private`, `Vary: Cookie`) and
|
|
33
|
+
* never indexed (`X-Robots-Tag: noindex, nofollow`). `{}` when `pointer` is
|
|
34
|
+
* `null`, so the result of the draft decision applies as is.
|
|
35
|
+
*/
|
|
36
|
+
export function draftResponseHeaders(pointer: string | null | undefined): Record<string, string> {
|
|
37
|
+
if (!pointer) return {};
|
|
38
|
+
return {
|
|
39
|
+
"Cache-Control": "no-store, private",
|
|
40
|
+
Vary: "Cookie",
|
|
41
|
+
"X-Robots-Tag": "noindex, nofollow",
|
|
42
|
+
};
|
|
43
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,61 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
StableOutlet,
|
|
10
|
-
} from "./hooks";
|
|
11
|
-
export {
|
|
12
|
-
CmsPage,
|
|
13
|
-
cmsHomeRouteConfig,
|
|
14
|
-
cmsRouteConfig,
|
|
15
|
-
decoInvokeRouteConfig,
|
|
16
|
-
decoMetaRouteConfig,
|
|
17
|
-
decoRenderRouteConfig,
|
|
18
|
-
loadCmsHomePage,
|
|
19
|
-
loadCmsPage,
|
|
20
|
-
loadDeferredSection,
|
|
21
|
-
NotFoundPage,
|
|
22
|
-
withSiteGlobals,
|
|
23
|
-
} from "./routes";
|
|
24
|
-
export type { CreateDecoRouterOptions } from "./sdk/router";
|
|
25
|
-
export {
|
|
26
|
-
createDecoRouter,
|
|
27
|
-
decoParseSearch,
|
|
28
|
-
decoStringifySearch,
|
|
29
|
-
} from "./sdk/router";
|
|
30
|
-
export type {
|
|
31
|
-
SpeculationAction,
|
|
32
|
-
SpeculationEagerness,
|
|
33
|
-
SpeculationRulesConfig,
|
|
34
|
-
} from "./sdk/speculationRules";
|
|
35
|
-
export {
|
|
36
|
-
buildSpeculationRules,
|
|
37
|
-
DEFAULT_EXCLUDED_HREF_MATCHES,
|
|
38
|
-
} from "./sdk/speculationRules";
|
|
39
|
-
export { createDecoWorkerEntry } from "./sdk/workerEntry";
|
|
40
|
-
export { setupTanstackFastDeploy } from "./setupFastDeploy";
|
|
41
|
-
// createInvokeFn is intentionally NOT re-exported from this root barrel.
|
|
42
|
-
// Its body contains a `createServerFn(...).handler(...)` call that is not a
|
|
43
|
-
// top-level variable declarator (it's returned from a factory function) --
|
|
44
|
-
// TanStack Start's compiler statically scans every file it processes for
|
|
45
|
-
// this pattern and throws "createServerFn must be assigned to a variable!"
|
|
46
|
-
// on ANY occurrence, whether or not the factory is ever actually called.
|
|
47
|
-
// Re-exporting it here would pull sdk/createInvoke.ts into the module graph
|
|
48
|
-
// of every site that imports anything else from this barrel (which is
|
|
49
|
-
// every site, for DecoRootLayout etc.), tripping that check even though
|
|
50
|
-
// createInvokeFn itself is never invoked at runtime -- it exists purely as
|
|
51
|
-
// a source-of-truth template that blocks-cli's generate-invoke.ts statically
|
|
52
|
-
// parses (never imports) to emit real top-level createServerFn declarations
|
|
53
|
-
// into each site's own src/server/invoke.gen.ts. Import it from the
|
|
54
|
-
// dedicated "@decocms/tanstack/sdk/createInvoke" subpath instead.
|
|
55
|
-
// decoServerFnFetch is intentionally NOT re-exported from this root barrel
|
|
56
|
-
// either. A site wires it in `src/start.ts`, which is part of the CLIENT
|
|
57
|
-
// bundle; importing it from here would drag `createDecoWorkerEntry` (and the
|
|
58
|
-
// whole server graph behind it) into that bundle. Import it from the dedicated
|
|
59
|
-
// "@decocms/tanstack/sdk/serverFnFetch" subpath instead.
|
|
60
|
-
// Next major (v8): the binding's documented surface. See /next/api-reference#loaders.
|
|
61
|
-
export { kvLoader } from "./v8/kvLoader";
|
|
1
|
+
/**
|
|
2
|
+
* `@decocms/tanstack`: the names and lists the worker, the server helpers and
|
|
3
|
+
* the document share, for a site that needs them in its own code (a route
|
|
4
|
+
* that sets its own headers, a CSP it writes itself). No imports, no state:
|
|
5
|
+
* safe in every bundle.
|
|
6
|
+
*/
|
|
7
|
+
export { DRAFT_COOKIE, DRAFT_HEADER, DRAFT_PARAM, draftResponseHeaders } from "./draft.ts";
|
|
8
|
+
export { isStudioOrigin, STUDIO_FRAME_ANCESTORS, STUDIO_ORIGINS } from "./studio.ts";
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The document every page of a Deco TanStack site renders in. Mount it as the
|
|
3
|
+
* root route's component (or shell). Everything is always on:
|
|
4
|
+
*
|
|
5
|
+
* - `<html data-theme="light">` (DaisyUI reads its colors from it);
|
|
6
|
+
* - the `DECO.events` bus and the `data-event` observer analytics go through;
|
|
7
|
+
* - a progress bar during client-side navigation, and a content area that
|
|
8
|
+
* keeps its height while the next page loads;
|
|
9
|
+
* - the CDN segment token and the draft this request renders, for
|
|
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
|
+
*
|
|
16
|
+
* A site that keeps its own document renders `DecoPreview` in its `<body>`
|
|
17
|
+
* for the bridge, the badge and the draft they read.
|
|
18
|
+
*/
|
|
19
|
+
import { DraftBadge, StudioBridge } from "@decocms/blocks/preview";
|
|
20
|
+
import { HeadContent, Outlet, ScriptOnce, Scripts, useRouterState } from "@tanstack/react-router";
|
|
21
|
+
import { type ReactNode, useEffect, useRef, useState } from "react";
|
|
22
|
+
import { STUDIO_ORIGINS } from "../studio.ts";
|
|
23
|
+
import { pageValues, publishScript } from "./pageValues.ts";
|
|
24
|
+
import { DATA_EVENT_OBSERVER, eventsBootstrap, PROGRESS_CSS } from "./scripts.ts";
|
|
25
|
+
|
|
26
|
+
declare global {
|
|
27
|
+
interface Window {
|
|
28
|
+
__deco_ready?: boolean;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface NavigationProgressProps {
|
|
33
|
+
/** Any CSS color. Default: the site's `--color-brand-primary-500`, else the text color. */
|
|
34
|
+
color?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** A loading bar at the top of the page during client-side navigation. */
|
|
38
|
+
export function NavigationProgress({
|
|
39
|
+
color = "var(--color-brand-primary-500, currentColor)",
|
|
40
|
+
}: NavigationProgressProps) {
|
|
41
|
+
const isLoading = useRouterState({ select: (s) => s.isLoading });
|
|
42
|
+
if (!isLoading) return null;
|
|
43
|
+
return (
|
|
44
|
+
<div
|
|
45
|
+
className="fixed top-0 left-0 right-0 z-[9999] h-1 overflow-hidden"
|
|
46
|
+
style={{ color }}
|
|
47
|
+
role="progressbar"
|
|
48
|
+
aria-label="Carregando página"
|
|
49
|
+
>
|
|
50
|
+
<style dangerouslySetInnerHTML={{ __html: PROGRESS_CSS }} />
|
|
51
|
+
{/* Track and bar are siblings so the track's 20% alpha does not inherit onto the bar. */}
|
|
52
|
+
<div className="absolute inset-0" style={{ backgroundColor: "currentColor", opacity: 0.2 }} />
|
|
53
|
+
<div
|
|
54
|
+
className="nav-progress-bar absolute inset-y-0 left-0 w-1/3 rounded-full"
|
|
55
|
+
style={{ backgroundColor: "currentColor" }}
|
|
56
|
+
/>
|
|
57
|
+
</div>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Keeps the content area's height while the next page loads, so the footer doesn't jump. */
|
|
62
|
+
export function StableOutlet() {
|
|
63
|
+
const isLoading = useRouterState({ select: (s) => s.isLoading });
|
|
64
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
65
|
+
const [savedHeight, setSavedHeight] = useState<number | undefined>(undefined);
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (isLoading && ref.current) setSavedHeight(ref.current.offsetHeight);
|
|
68
|
+
else if (!isLoading) setSavedHeight(undefined);
|
|
69
|
+
}, [isLoading]);
|
|
70
|
+
return (
|
|
71
|
+
<div ref={ref} style={savedHeight ? { minHeight: savedHeight } : undefined}>
|
|
72
|
+
<Outlet />
|
|
73
|
+
</div>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* The page the "." shortcut opens in Studio: the deepest matched route whose
|
|
79
|
+
* loader data carries a string `pathTemplate` (the page block's `path`, as
|
|
80
|
+
* `matchRoute` matched it) and, optionally, `pageId`. v7's document read the
|
|
81
|
+
* same thing from its CMS route's `path` and `blockKey`.
|
|
82
|
+
*/
|
|
83
|
+
function studioPageOf(
|
|
84
|
+
matches: readonly { loaderData?: unknown }[],
|
|
85
|
+
): { pathTemplate: string; id?: string } | undefined {
|
|
86
|
+
for (let i = matches.length - 1; i >= 0; i--) {
|
|
87
|
+
const data = matches[i]?.loaderData as { pathTemplate?: unknown; pageId?: unknown } | undefined;
|
|
88
|
+
if (data && typeof data === "object" && typeof data.pathTemplate === "string") {
|
|
89
|
+
return {
|
|
90
|
+
pathTemplate: data.pathTemplate,
|
|
91
|
+
id: typeof data.pageId === "string" ? data.pageId : undefined,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** The Studio bridge, with the page on screen, and the badge for the request's draft. */
|
|
99
|
+
function StudioPieces({
|
|
100
|
+
site,
|
|
101
|
+
editShortcut,
|
|
102
|
+
nonce,
|
|
103
|
+
draft,
|
|
104
|
+
}: Pick<DecoPreviewProps, "site" | "editShortcut" | "nonce"> & { draft: string | undefined }) {
|
|
105
|
+
// Two primitives, so a navigation that keeps the page doesn't re-render the document.
|
|
106
|
+
const pathTemplate = useRouterState({ select: (s) => studioPageOf(s.matches)?.pathTemplate });
|
|
107
|
+
const pageId = useRouterState({ select: (s) => studioPageOf(s.matches)?.id });
|
|
108
|
+
return (
|
|
109
|
+
<>
|
|
110
|
+
<StudioBridge
|
|
111
|
+
site={site}
|
|
112
|
+
trustedOrigins={STUDIO_ORIGINS}
|
|
113
|
+
editShortcut={editShortcut}
|
|
114
|
+
page={{ pathTemplate, id: pageId }}
|
|
115
|
+
nonce={nonce}
|
|
116
|
+
/>
|
|
117
|
+
<DraftBadge pointer={draft ?? null} />
|
|
118
|
+
</>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface DecoPreviewProps {
|
|
123
|
+
/** The site's name in Deco (the "." shortcut opens the page under it). */
|
|
124
|
+
site: string;
|
|
125
|
+
/**
|
|
126
|
+
* The "." shortcut that opens the page in Studio (on by default; `false`
|
|
127
|
+
* turns it off). It opens the page whose route returns `pathTemplate` (and
|
|
128
|
+
* optionally `pageId`) in its loader data; without one, Studio picks the
|
|
129
|
+
* page from the URL.
|
|
130
|
+
*/
|
|
131
|
+
editShortcut?: boolean;
|
|
132
|
+
/** The CSP nonce for the inline scripts, when the site enforces one. */
|
|
133
|
+
nonce?: string;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* What `DecoDocument` mounts for Studio and draft previews, for a site that
|
|
138
|
+
* keeps its own document (a skip link before `<main>`, say): the request's
|
|
139
|
+
* draft and CDN segment token published to the browser, `StudioBridge` and
|
|
140
|
+
* `DraftBadge`. Render it once, in the `<body>`.
|
|
141
|
+
*/
|
|
142
|
+
export function DecoPreview({ site, editShortcut, nonce }: DecoPreviewProps) {
|
|
143
|
+
const values = pageValues();
|
|
144
|
+
const publish = publishScript(values);
|
|
145
|
+
return (
|
|
146
|
+
<>
|
|
147
|
+
{publish && (
|
|
148
|
+
<script
|
|
149
|
+
nonce={nonce}
|
|
150
|
+
suppressHydrationWarning
|
|
151
|
+
dangerouslySetInnerHTML={{ __html: publish }}
|
|
152
|
+
/>
|
|
153
|
+
)}
|
|
154
|
+
<StudioPieces site={site} editShortcut={editShortcut} nonce={nonce} draft={values.draft} />
|
|
155
|
+
</>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface DecoDocumentProps {
|
|
160
|
+
/** The site's name in Deco (the Studio bridge's shortcut opens the page under it). */
|
|
161
|
+
site: string;
|
|
162
|
+
/** `<html lang>`. Default `"en"`. */
|
|
163
|
+
lang?: string;
|
|
164
|
+
/** `<body class>`. Default `"bg-base-200 text-base-content"`. */
|
|
165
|
+
bodyClassName?: string;
|
|
166
|
+
/** The commerce account, for `window.__RUNTIME__` (analytics scripts read it). */
|
|
167
|
+
account?: string;
|
|
168
|
+
/** Milliseconds after hydration before `deco:ready` fires. Default 500. */
|
|
169
|
+
readyDelay?: number;
|
|
170
|
+
/** The element around the page: `"main"` (default), or `"div"` when the page renders its own `<main>`. */
|
|
171
|
+
outlet?: "main" | "div";
|
|
172
|
+
/**
|
|
173
|
+
* The "." shortcut that opens the page in Studio (on by default; `false`
|
|
174
|
+
* turns it off). It opens the page whose route returns `pathTemplate` (and
|
|
175
|
+
* optionally `pageId`) in its loader data; without one, Studio picks the
|
|
176
|
+
* page from the URL.
|
|
177
|
+
*/
|
|
178
|
+
editShortcut?: boolean;
|
|
179
|
+
/** The CSP nonce for the inline scripts, when the site enforces one. */
|
|
180
|
+
nonce?: string;
|
|
181
|
+
/** Rendered after the page (toasts, drawers, analytics). */
|
|
182
|
+
children?: ReactNode;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export function DecoDocument({
|
|
186
|
+
site,
|
|
187
|
+
lang = "en",
|
|
188
|
+
bodyClassName = "bg-base-200 text-base-content",
|
|
189
|
+
account = "",
|
|
190
|
+
readyDelay = 500,
|
|
191
|
+
outlet = "main",
|
|
192
|
+
editShortcut,
|
|
193
|
+
nonce,
|
|
194
|
+
children,
|
|
195
|
+
}: DecoDocumentProps) {
|
|
196
|
+
// Pages wait for this signal before running work that must follow hydration.
|
|
197
|
+
useEffect(() => {
|
|
198
|
+
const id = setTimeout(() => {
|
|
199
|
+
window.__deco_ready = true;
|
|
200
|
+
document.dispatchEvent(new Event("deco:ready"));
|
|
201
|
+
}, readyDelay);
|
|
202
|
+
return () => clearTimeout(id);
|
|
203
|
+
}, [readyDelay]);
|
|
204
|
+
|
|
205
|
+
const values = pageValues();
|
|
206
|
+
const publish = publishScript(values);
|
|
207
|
+
const Outer = outlet;
|
|
208
|
+
|
|
209
|
+
return (
|
|
210
|
+
<html lang={lang} data-theme="light" suppressHydrationWarning>
|
|
211
|
+
<head>
|
|
212
|
+
<HeadContent />
|
|
213
|
+
{publish && (
|
|
214
|
+
<script
|
|
215
|
+
nonce={nonce}
|
|
216
|
+
suppressHydrationWarning
|
|
217
|
+
dangerouslySetInnerHTML={{ __html: publish }}
|
|
218
|
+
/>
|
|
219
|
+
)}
|
|
220
|
+
</head>
|
|
221
|
+
<body className={bodyClassName} suppressHydrationWarning>
|
|
222
|
+
<ScriptOnce>{eventsBootstrap(account)}</ScriptOnce>
|
|
223
|
+
<NavigationProgress />
|
|
224
|
+
<Outer>
|
|
225
|
+
<StableOutlet />
|
|
226
|
+
</Outer>
|
|
227
|
+
{children}
|
|
228
|
+
<StudioPieces site={site} editShortcut={editShortcut} nonce={nonce} draft={values.draft} />
|
|
229
|
+
<ScriptOnce>{DATA_EVENT_OBSERVER}</ScriptOnce>
|
|
230
|
+
<Scripts />
|
|
231
|
+
</body>
|
|
232
|
+
</html>
|
|
233
|
+
);
|
|
234
|
+
}
|