@decocms/tanstack 8.0.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.
Files changed (150) hide show
  1. package/README.md +79 -0
  2. package/dist/draft.d.ts +33 -0
  3. package/dist/draft.d.ts.map +1 -0
  4. package/dist/draft.js +41 -0
  5. package/dist/draft.js.map +1 -0
  6. package/dist/index.d.ts +9 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +9 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/react/DecoDocument.d.ts +61 -0
  11. package/dist/react/DecoDocument.d.ts.map +1 -0
  12. package/dist/react/DecoDocument.js +96 -0
  13. package/dist/react/DecoDocument.js.map +1 -0
  14. package/dist/react/Image.d.ts +96 -0
  15. package/dist/react/Image.d.ts.map +1 -0
  16. package/dist/react/Image.js +79 -0
  17. package/dist/react/Image.js.map +1 -0
  18. package/dist/react/index.d.ts +7 -0
  19. package/dist/react/index.d.ts.map +1 -0
  20. package/dist/react/index.js +7 -0
  21. package/dist/react/index.js.map +1 -0
  22. package/dist/react/pageValues.d.ts +10 -0
  23. package/dist/react/pageValues.d.ts.map +1 -0
  24. package/dist/react/pageValues.js +29 -0
  25. package/dist/react/pageValues.js.map +1 -0
  26. package/dist/react/scripts.d.ts +14 -0
  27. package/dist/react/scripts.d.ts.map +1 -0
  28. package/dist/react/scripts.js +96 -0
  29. package/dist/react/scripts.js.map +1 -0
  30. package/dist/router/index.d.ts +38 -0
  31. package/dist/router/index.d.ts.map +1 -0
  32. package/dist/router/index.js +60 -0
  33. package/dist/router/index.js.map +1 -0
  34. package/dist/scope/browser.d.ts +11 -0
  35. package/dist/scope/browser.d.ts.map +1 -0
  36. package/dist/scope/browser.js +8 -0
  37. package/dist/scope/browser.js.map +1 -0
  38. package/dist/scope/server.d.ts +13 -0
  39. package/dist/scope/server.d.ts.map +1 -0
  40. package/dist/scope/server.js +26 -0
  41. package/dist/scope/server.js.map +1 -0
  42. package/dist/server/index.d.ts +27 -0
  43. package/dist/server/index.d.ts.map +1 -0
  44. package/dist/server/index.js +31 -0
  45. package/dist/server/index.js.map +1 -0
  46. package/dist/shared.d.ts +26 -0
  47. package/dist/shared.d.ts.map +1 -0
  48. package/dist/shared.js +26 -0
  49. package/dist/shared.js.map +1 -0
  50. package/dist/start/index.d.ts +9 -0
  51. package/dist/start/index.d.ts.map +1 -0
  52. package/dist/start/index.js +33 -0
  53. package/dist/start/index.js.map +1 -0
  54. package/dist/studio.d.ts +28 -0
  55. package/dist/studio.d.ts.map +1 -0
  56. package/dist/studio.js +53 -0
  57. package/dist/studio.js.map +1 -0
  58. package/dist/vite/index.d.ts +15 -0
  59. package/dist/vite/index.d.ts.map +1 -0
  60. package/dist/vite/index.js +95 -0
  61. package/dist/vite/index.js.map +1 -0
  62. package/dist/worker/cacheProfiles.d.ts +43 -0
  63. package/dist/worker/cacheProfiles.d.ts.map +1 -0
  64. package/dist/worker/cacheProfiles.js +162 -0
  65. package/dist/worker/cacheProfiles.js.map +1 -0
  66. package/dist/worker/cookies.d.ts +20 -0
  67. package/dist/worker/cookies.d.ts.map +1 -0
  68. package/dist/worker/cookies.js +69 -0
  69. package/dist/worker/cookies.js.map +1 -0
  70. package/dist/worker/drafts.d.ts +59 -0
  71. package/dist/worker/drafts.d.ts.map +1 -0
  72. package/dist/worker/drafts.js +140 -0
  73. package/dist/worker/drafts.js.map +1 -0
  74. package/dist/worker/index.d.ts +107 -0
  75. package/dist/worker/index.d.ts.map +1 -0
  76. package/dist/worker/index.js +511 -0
  77. package/dist/worker/index.js.map +1 -0
  78. package/dist/worker/security.d.ts +14 -0
  79. package/dist/worker/security.d.ts.map +1 -0
  80. package/dist/worker/security.js +48 -0
  81. package/dist/worker/security.js.map +1 -0
  82. package/dist/worker/segment.d.ts +21 -0
  83. package/dist/worker/segment.d.ts.map +1 -0
  84. package/dist/worker/segment.js +43 -0
  85. package/dist/worker/segment.js.map +1 -0
  86. package/package.json +86 -31
  87. package/src/draft.ts +43 -0
  88. package/src/index.ts +8 -44
  89. package/src/react/DecoDocument.tsx +234 -0
  90. package/src/react/Image.tsx +213 -0
  91. package/src/react/index.ts +24 -0
  92. package/src/react/pageValues.ts +35 -0
  93. package/src/react/scripts.ts +98 -0
  94. package/src/router/index.ts +80 -0
  95. package/src/scope/browser.ts +18 -0
  96. package/src/scope/server.ts +37 -0
  97. package/src/server/index.ts +43 -0
  98. package/src/shared.ts +29 -0
  99. package/src/start/index.ts +31 -0
  100. package/src/studio.ts +52 -0
  101. package/src/vite/index.ts +105 -0
  102. package/src/worker/cacheProfiles.ts +180 -0
  103. package/src/worker/cookies.ts +65 -0
  104. package/src/worker/drafts.ts +157 -0
  105. package/src/worker/index.ts +648 -0
  106. package/src/worker/security.ts +63 -0
  107. package/src/worker/segment.ts +49 -0
  108. package/src/cms/kvBlockSource.test.ts +0 -82
  109. package/src/cms/kvBlockSource.ts +0 -68
  110. package/src/daemon/auth.ts +0 -204
  111. package/src/daemon/fs.ts +0 -238
  112. package/src/daemon/index.ts +0 -8
  113. package/src/daemon/middleware.ts +0 -156
  114. package/src/daemon/tunnel.ts +0 -129
  115. package/src/daemon/volumes.ts +0 -366
  116. package/src/daemon/watch.ts +0 -272
  117. package/src/hooks/DecoPageRenderer.tsx +0 -688
  118. package/src/hooks/DecoRootLayout.tsx +0 -111
  119. package/src/hooks/NavigationProgress.tsx +0 -21
  120. package/src/hooks/PreviewProviders.tsx +0 -26
  121. package/src/hooks/StableOutlet.tsx +0 -30
  122. package/src/hooks/index.ts +0 -9
  123. package/src/routes/adminRoutes.test.ts +0 -99
  124. package/src/routes/adminRoutes.ts +0 -153
  125. package/src/routes/cmsRoute.test.ts +0 -100
  126. package/src/routes/cmsRoute.ts +0 -944
  127. package/src/routes/components.tsx +0 -57
  128. package/src/routes/index.ts +0 -24
  129. package/src/routes/pageUrl.test.ts +0 -70
  130. package/src/routes/pageUrl.ts +0 -54
  131. package/src/routes/withSiteGlobals.test.ts +0 -206
  132. package/src/routes/withSiteGlobals.ts +0 -222
  133. package/src/sdk/cookiePassthrough.ts +0 -58
  134. package/src/sdk/createInvoke.ts +0 -77
  135. package/src/sdk/deferredSectionLoader.test.ts +0 -94
  136. package/src/sdk/deferredSectionLoader.ts +0 -46
  137. package/src/sdk/kvHydration.test.ts +0 -215
  138. package/src/sdk/kvHydration.ts +0 -193
  139. package/src/sdk/outboundHeaders.test.ts +0 -113
  140. package/src/sdk/outboundHeaders.ts +0 -81
  141. package/src/sdk/router.ts +0 -92
  142. package/src/sdk/useHydrated.ts +0 -19
  143. package/src/sdk/workerEntry.test.ts +0 -495
  144. package/src/sdk/workerEntry.ts +0 -2307
  145. package/src/setupFastDeploy.ts +0 -13
  146. package/src/vite/plugin-scaffold-gen.test.js +0 -106
  147. package/src/vite/plugin.js +0 -850
  148. package/src/vite/plugin.test.js +0 -113
  149. package/src/vite/plugin.test.ts +0 -52
  150. 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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 -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":["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AAC,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,53 +1,108 @@
1
1
  {
2
2
  "name": "@decocms/tanstack",
3
- "version": "8.0.0",
3
+ "version": "8.4.0",
4
4
  "type": "module",
5
- "description": "Deco framework binding for TanStack Start + Cloudflare Workers",
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
- "main": "./src/index.ts",
14
+ "files": [
15
+ "dist",
16
+ "src",
17
+ "!src/**/*.test.ts",
18
+ "!src/**/*.test.tsx",
19
+ "!src/**/__tests__",
20
+ "!src/**/testing.ts"
21
+ ],
12
22
  "exports": {
13
- ".": "./src/index.ts",
14
- "./vite": "./src/vite/plugin.js",
15
- "./daemon": "./src/daemon/index.ts",
16
- "./sdk/createInvoke": "./src/sdk/createInvoke.ts",
17
- "./sdk/cookiePassthrough": "./src/sdk/cookiePassthrough.ts",
18
- "./sdk/deferredSectionLoader": "./src/sdk/deferredSectionLoader.ts"
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
+ }
19
77
  },
20
78
  "scripts": {
21
- "build": "tsc",
79
+ "build": "node ../../scripts/tsc.mjs --clean dist -p tsconfig.build.json",
80
+ "prepack": "npm run build",
22
81
  "test": "vitest run --root ../.. packages/tanstack/",
23
- "typecheck": "tsc --noEmit",
24
- "lint:unused": "knip"
25
- },
26
- "dependencies": {
27
- "@decocms/blocks": "8.0.0",
28
- "@decocms/blocks-admin": "8.0.0",
29
- "@decocms/blocks-cli": "8.0.0",
30
- "@deco-cx/warp-node": "^0.3.16",
31
- "fast-json-patch": "^3.1.0",
32
- "ws": "^8.18.0"
82
+ "typecheck": "node ../../scripts/tsc.mjs -p tsconfig.json"
33
83
  },
34
84
  "peerDependencies": {
35
- "@tanstack/react-query": ">=5.0.0",
36
- "@tanstack/react-start": ">=1.0.0",
37
- "@tanstack/store": ">=0.7.0",
85
+ "@decocms/blocks": "^8.4.0",
86
+ "@tanstack/react-router": ">=1.166.0",
87
+ "@tanstack/react-start": ">=1.166.0",
38
88
  "react": "^19.0.0",
39
- "react-dom": "^19.0.0",
40
- "vite": ">=6.0.0 || >=7.0.0 || >=8.0.0"
89
+ "vite": ">=7.0.0"
90
+ },
91
+ "peerDependenciesMeta": {
92
+ "vite": {
93
+ "optional": true
94
+ }
41
95
  },
42
96
  "devDependencies": {
43
- "@tanstack/react-query": "^5.96.0",
44
- "@tanstack/store": "^0.9.1",
97
+ "@decocms/blocks": "8.4.0",
98
+ "@tanstack/react-router": "1.170.39",
99
+ "@tanstack/react-start": "1.168.58",
45
100
  "@types/react": "^19.0.0",
46
101
  "@types/react-dom": "^19.0.0",
47
- "@types/ws": "^8.18.0",
48
- "knip": "^5.86.0",
49
- "typescript": "^5.9.0",
50
- "vite": ">=6.0.0"
102
+ "esbuild": "^0.27.3",
103
+ "react": "19.2.7",
104
+ "react-dom": "19.2.7",
105
+ "vite": "^8.0.1"
51
106
  },
52
107
  "publishConfig": {
53
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,44 +1,8 @@
1
- export {
2
- cmsHomeRouteConfig,
3
- cmsRouteConfig,
4
- CmsPage,
5
- decoInvokeRouteConfig,
6
- decoMetaRouteConfig,
7
- decoRenderRouteConfig,
8
- loadCmsHomePage,
9
- loadCmsPage,
10
- loadDeferredSection,
11
- NotFoundPage,
12
- withSiteGlobals,
13
- } from "./routes";
14
- export {
15
- DecoPageRenderer,
16
- DecoRootLayout,
17
- NavigationProgress,
18
- PreviewProviders,
19
- SectionList,
20
- SectionRenderer,
21
- StableOutlet,
22
- } from "./hooks";
23
- export { createDecoWorkerEntry } from "./sdk/workerEntry";
24
- export { setupTanstackFastDeploy } from "./setupFastDeploy";
25
- export {
26
- createDecoRouter,
27
- decoParseSearch,
28
- decoStringifySearch,
29
- } from "./sdk/router";
30
- export type { CreateDecoRouterOptions } from "./sdk/router";
31
- // createInvokeFn is intentionally NOT re-exported from this root barrel.
32
- // Its body contains a `createServerFn(...).handler(...)` call that is not a
33
- // top-level variable declarator (it's returned from a factory function) --
34
- // TanStack Start's compiler statically scans every file it processes for
35
- // this pattern and throws "createServerFn must be assigned to a variable!"
36
- // on ANY occurrence, whether or not the factory is ever actually called.
37
- // Re-exporting it here would pull sdk/createInvoke.ts into the module graph
38
- // of every site that imports anything else from this barrel (which is
39
- // every site, for DecoRootLayout etc.), tripping that check even though
40
- // createInvokeFn itself is never invoked at runtime -- it exists purely as
41
- // a source-of-truth template that blocks-cli's generate-invoke.ts statically
42
- // parses (never imports) to emit real top-level createServerFn declarations
43
- // into each site's own src/server/invoke.gen.ts. Import it from the
44
- // dedicated "@decocms/tanstack/sdk/createInvoke" subpath instead.
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
+ }