@decocms/tanstack 8.1.0-next.0 → 8.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +107 -0
- package/dist/worker/index.d.ts.map +1 -0
- package/dist/worker/index.js +511 -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 +648 -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
package/README.md
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# @decocms/tanstack
|
|
2
|
+
|
|
3
|
+
Deco CMS for [TanStack Start](https://tanstack.com/start) sites on Cloudflare Workers, deployed the way Deco deploys them. It is opinionated: one worker entry with a few options, one escape hatch for your own routes, and the behaviour every Deco TanStack site should have, always on.
|
|
4
|
+
|
|
5
|
+
Peers: `@decocms/blocks` (same version), `@tanstack/react-start`, `@tanstack/react-router`, `react`, and `vite` for `/vite`.
|
|
6
|
+
|
|
7
|
+
## The worker
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
// src/worker-entry.ts (wrangler.jsonc "main")
|
|
11
|
+
import { createDecoWorker } from "@decocms/tanstack/worker";
|
|
12
|
+
import handler, { createServerEntry } from "@tanstack/react-start/server-entry";
|
|
13
|
+
import { cms } from "./cms";
|
|
14
|
+
|
|
15
|
+
export default createDecoWorker({
|
|
16
|
+
serverEntry: createServerEntry({ fetch: handler.fetch }),
|
|
17
|
+
cms,
|
|
18
|
+
site: "my-store",
|
|
19
|
+
buildHash: __BUILD_HASH__,
|
|
20
|
+
dev: import.meta.env.DEV,
|
|
21
|
+
});
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Always on: `/deco/_liveness`; 404 for v7's admin paths; Studio may frame the site (`frame-ancestors`, no `X-Frame-Options`) and the security headers; drafts (the host allowlist, the draft cookie, never cached, `noindex`); the CMS redirects; an edge cache keyed on the build, the content revision, the device and your `segment`, with stale-while-revalidate and stale-if-error; CDN caching of client-side navigation data under a checked `__cseg` token; one `Set-Cookie` per cookie; `x-page-status`.
|
|
25
|
+
|
|
26
|
+
Options, each for a value a site needs to change: `csp`, `segment`, `cacheProfiles`, `safeCookies`, `purgeToken`, `preload`, `previewHosts`, `routes` and `onCache`.
|
|
27
|
+
|
|
28
|
+
### Draft hosts
|
|
29
|
+
|
|
30
|
+
A draft link (`?__draft=`) previews where v7 allowed it: on the preview hosts the site declares (the `CMS` block's `preview.hosts`, or `createCMS`'s) and always on the hosts Deco runs the site on, `<site>.deco.site` and `<site>.deco-cx.workers.dev`. A site that declares no hosts previews only on those two, not on every host. `previewHosts: [...]` replaces the declared list with exact hosts (`["localhost:5173"]` for local development), as v7's `DECO_ALLOWED_PREVIEW_HOSTS` did; `previewHosts: "none"` turns previews off on every host. The worker passes the accepted draft to the app in the `x-deco-draft` request header: read it with `contentClient(cms)` from `@decocms/tanstack/server`.
|
|
31
|
+
|
|
32
|
+
### Names and Studio's origins
|
|
33
|
+
|
|
34
|
+
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`, `DRAFT_HEADER` `x-deco-draft`), `draftResponseHeaders(pointer)` (`no-store, private`, `Vary: Cookie`, `noindex`), and Studio's origins: `STUDIO_ORIGINS`, `STUDIO_FRAME_ANCESTORS` (what the worker's `frame-ancestors` starts from) and `isStudioOrigin`. `DecoDocument` passes `STUDIO_ORIGINS` to the Studio bridge.
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { DRAFT_HEADER, STUDIO_ORIGINS } from "@decocms/tanstack";
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## The app
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
// vite.config.ts
|
|
44
|
+
plugins: [cloudflare({ viteEnvironment: { name: "ssr" } }), tanstackStart(), react(),
|
|
45
|
+
decoTanstack({ buildHash: process.env.WORKERS_CI_COMMIT_SHA })]
|
|
46
|
+
|
|
47
|
+
// src/router.tsx
|
|
48
|
+
export const getRouter = () => createDecoRouter({ routeTree });
|
|
49
|
+
|
|
50
|
+
// src/start.ts
|
|
51
|
+
export const startInstance = createStart(() => ({ serverFns: { fetch: decoServerFnFetch } }));
|
|
52
|
+
|
|
53
|
+
// src/routes/__root.tsx
|
|
54
|
+
export const Route = createRootRoute({ component: () => <DecoDocument site="my-store" /> });
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`DecoDocument` mounts Studio's bridge and the draft badge. 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 bridge, the badge and the draft they read.
|
|
58
|
+
|
|
59
|
+
## Images
|
|
60
|
+
|
|
61
|
+
```tsx
|
|
62
|
+
// src/imageUrl.ts: the site's image URLs (@decocms/blocks/image plus its platform's helpers)
|
|
63
|
+
import { createImageUrl, decoCdn } from "@decocms/blocks/image";
|
|
64
|
+
import { vtexCatalog } from "@decocms/apps-vtex/image"; // a VTEX store
|
|
65
|
+
import { shopifyCdn } from "@decocms/apps-shopify/image"; // a Shopify store
|
|
66
|
+
export const imageUrl = createImageUrl({
|
|
67
|
+
providers: [vtexCatalog(), shopifyCdn(), decoCdn({ quality: "high", sources: "all" })],
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// src/router.tsx: around every page
|
|
71
|
+
createDecoRouter({ routeTree, Wrap: ({ children }) => <ImageUrlProvider value={imageUrl}>{children}</ImageUrlProvider> });
|
|
72
|
+
|
|
73
|
+
// any component
|
|
74
|
+
<Image src={src} width={400} height={300} preload={isLcp} />
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
`Image`, `Picture` and `Source` from `/react` take v7's props and render v7's markup, so a migrated call site only changes its import. This package knows no commerce platform: v7's components resized VTEX catalog and Shopify images on those platforms' hosts, and a site keeps those URLs by listing the platform's helper before `decoCdn` as above (v7's URLs, byte for byte, with the `decoCdn` options of the 7.x release the site ran, e.g. `stripAssetHosts: "leading"` from 7.71.4: the v7 to v8 migration skill lists them). An `Image` or `Source` without a width writes v7's `width=NaN` candidates, as v7 did. Without an `ImageUrlProvider` every source goes through `assets.decocms.com` (`DECO_IMAGE_URL`).
|
|
78
|
+
|
|
79
|
+
`examples/tanstack-worker-smoke` in the repository is a complete app.
|
package/dist/draft.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
* The query parameter a draft link carries (`?__draft=<pointer>`, or `off` to
|
|
11
|
+
* end a preview). The worker reads it after its host check; reading it
|
|
12
|
+
* directly would skip that check.
|
|
13
|
+
*/
|
|
14
|
+
export declare const DRAFT_PARAM = "__draft";
|
|
15
|
+
/**
|
|
16
|
+
* The cookie that keeps a preview going after the first draft link. Like
|
|
17
|
+
* {@link DRAFT_PARAM}, the worker reads it after its host check.
|
|
18
|
+
*/
|
|
19
|
+
export declare const DRAFT_COOKIE = "__deco_draft";
|
|
20
|
+
/**
|
|
21
|
+
* The request header the worker sets on the request it hands the app once it
|
|
22
|
+
* accepted the draft: the pointer, already checked. The worker removes any
|
|
23
|
+
* copy that arrives from outside, so a client can't send one itself.
|
|
24
|
+
*/
|
|
25
|
+
export declare const DRAFT_HEADER = "x-deco-draft";
|
|
26
|
+
/**
|
|
27
|
+
* The response headers of a page rendered from a draft: never stored by a
|
|
28
|
+
* browser or a CDN (`Cache-Control: no-store, private`, `Vary: Cookie`) and
|
|
29
|
+
* never indexed (`X-Robots-Tag: noindex, nofollow`). `{}` when `pointer` is
|
|
30
|
+
* `null`, so the result of the draft decision applies as is.
|
|
31
|
+
*/
|
|
32
|
+
export declare function draftResponseHeaders(pointer: string | null | undefined): Record<string, string>;
|
|
33
|
+
//# sourceMappingURL=draft.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draft.d.ts","sourceRoot":"","sources":["../src/draft.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;GAIG;AACH,eAAO,MAAM,WAAW,YAAY,CAAC;AAErC;;;GAGG;AACH,eAAO,MAAM,YAAY,iBAAiB,CAAC;AAE3C;;;;GAIG;AACH,eAAO,MAAM,YAAY,iBAAiB,CAAC;AAE3C;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAO/F"}
|
package/dist/draft.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
* The query parameter a draft link carries (`?__draft=<pointer>`, or `off` to
|
|
11
|
+
* end a preview). The worker reads it after its host check; reading it
|
|
12
|
+
* directly would skip that check.
|
|
13
|
+
*/
|
|
14
|
+
export const DRAFT_PARAM = "__draft";
|
|
15
|
+
/**
|
|
16
|
+
* The cookie that keeps a preview going after the first draft link. Like
|
|
17
|
+
* {@link DRAFT_PARAM}, the worker reads it after its host check.
|
|
18
|
+
*/
|
|
19
|
+
export const DRAFT_COOKIE = "__deco_draft";
|
|
20
|
+
/**
|
|
21
|
+
* The request header the worker sets on the request it hands the app once it
|
|
22
|
+
* accepted the draft: the pointer, already checked. The worker removes any
|
|
23
|
+
* copy that arrives from outside, so a client can't send one itself.
|
|
24
|
+
*/
|
|
25
|
+
export const DRAFT_HEADER = "x-deco-draft";
|
|
26
|
+
/**
|
|
27
|
+
* The response headers of a page rendered from a draft: never stored by a
|
|
28
|
+
* browser or a CDN (`Cache-Control: no-store, private`, `Vary: Cookie`) and
|
|
29
|
+
* never indexed (`X-Robots-Tag: noindex, nofollow`). `{}` when `pointer` is
|
|
30
|
+
* `null`, so the result of the draft decision applies as is.
|
|
31
|
+
*/
|
|
32
|
+
export function draftResponseHeaders(pointer) {
|
|
33
|
+
if (!pointer)
|
|
34
|
+
return {};
|
|
35
|
+
return {
|
|
36
|
+
"Cache-Control": "no-store, private",
|
|
37
|
+
Vary: "Cookie",
|
|
38
|
+
"X-Robots-Tag": "noindex, nofollow",
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=draft.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draft.js","sourceRoot":"","sources":["../src/draft.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,SAAS,CAAC;AAErC;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,cAAc,CAAC;AAE3C;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,cAAc,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAkC;IACrE,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IACxB,OAAO;QACL,eAAe,EAAE,mBAAmB;QACpC,IAAI,EAAE,QAAQ;QACd,cAAc,EAAE,mBAAmB;KACpC,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
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";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAC3F,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
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.js";
|
|
8
|
+
export { isStudioOrigin, STUDIO_FRAME_ANCESTORS, STUDIO_ORIGINS } from "./studio.js";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAC3F,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
__deco_ready?: boolean;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export interface NavigationProgressProps {
|
|
8
|
+
/** Any CSS color. Default: the site's `--color-brand-primary-500`, else the text color. */
|
|
9
|
+
color?: string;
|
|
10
|
+
}
|
|
11
|
+
/** A loading bar at the top of the page during client-side navigation. */
|
|
12
|
+
export declare function NavigationProgress({ color, }: NavigationProgressProps): import("react").JSX.Element | null;
|
|
13
|
+
/** Keeps the content area's height while the next page loads, so the footer doesn't jump. */
|
|
14
|
+
export declare function StableOutlet(): import("react").JSX.Element;
|
|
15
|
+
export interface DecoPreviewProps {
|
|
16
|
+
/** The site's name in Deco (the "." shortcut opens the page under it). */
|
|
17
|
+
site: string;
|
|
18
|
+
/**
|
|
19
|
+
* The "." shortcut that opens the page in Studio (on by default; `false`
|
|
20
|
+
* turns it off). It opens the page whose route returns `pathTemplate` (and
|
|
21
|
+
* optionally `pageId`) in its loader data; without one, Studio picks the
|
|
22
|
+
* page from the URL.
|
|
23
|
+
*/
|
|
24
|
+
editShortcut?: boolean;
|
|
25
|
+
/** The CSP nonce for the inline scripts, when the site enforces one. */
|
|
26
|
+
nonce?: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* What `DecoDocument` mounts for Studio and draft previews, for a site that
|
|
30
|
+
* keeps its own document (a skip link before `<main>`, say): the request's
|
|
31
|
+
* draft and CDN segment token published to the browser, `StudioBridge` and
|
|
32
|
+
* `DraftBadge`. Render it once, in the `<body>`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function DecoPreview({ site, editShortcut, nonce }: DecoPreviewProps): import("react").JSX.Element;
|
|
35
|
+
export interface DecoDocumentProps {
|
|
36
|
+
/** The site's name in Deco (the Studio bridge's shortcut opens the page under it). */
|
|
37
|
+
site: string;
|
|
38
|
+
/** `<html lang>`. Default `"en"`. */
|
|
39
|
+
lang?: string;
|
|
40
|
+
/** `<body class>`. Default `"bg-base-200 text-base-content"`. */
|
|
41
|
+
bodyClassName?: string;
|
|
42
|
+
/** The commerce account, for `window.__RUNTIME__` (analytics scripts read it). */
|
|
43
|
+
account?: string;
|
|
44
|
+
/** Milliseconds after hydration before `deco:ready` fires. Default 500. */
|
|
45
|
+
readyDelay?: number;
|
|
46
|
+
/** The element around the page: `"main"` (default), or `"div"` when the page renders its own `<main>`. */
|
|
47
|
+
outlet?: "main" | "div";
|
|
48
|
+
/**
|
|
49
|
+
* The "." shortcut that opens the page in Studio (on by default; `false`
|
|
50
|
+
* turns it off). It opens the page whose route returns `pathTemplate` (and
|
|
51
|
+
* optionally `pageId`) in its loader data; without one, Studio picks the
|
|
52
|
+
* page from the URL.
|
|
53
|
+
*/
|
|
54
|
+
editShortcut?: boolean;
|
|
55
|
+
/** The CSP nonce for the inline scripts, when the site enforces one. */
|
|
56
|
+
nonce?: string;
|
|
57
|
+
/** Rendered after the page (toasts, drawers, analytics). */
|
|
58
|
+
children?: ReactNode;
|
|
59
|
+
}
|
|
60
|
+
export declare function DecoDocument({ site, lang, bodyClassName, account, readyDelay, outlet, editShortcut, nonce, children, }: DecoDocumentProps): import("react").JSX.Element;
|
|
61
|
+
//# sourceMappingURL=DecoDocument.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DecoDocument.d.ts","sourceRoot":"","sources":["../../src/react/DecoDocument.tsx"],"names":[],"mappings":"AAoBA,OAAO,EAAE,KAAK,SAAS,EAA+B,MAAM,OAAO,CAAC;AAKpE,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,YAAY,CAAC,EAAE,OAAO,CAAC;KACxB;CACF;AAED,MAAM,WAAW,uBAAuB;IACtC,2FAA2F;IAC3F,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,0EAA0E;AAC1E,wBAAgB,kBAAkB,CAAC,EACjC,KAAsD,GACvD,EAAE,uBAAuB,sCAmBzB;AAED,6FAA6F;AAC7F,wBAAgB,YAAY,gCAa3B;AA+CD,MAAM,WAAW,gBAAgB;IAC/B,0EAA0E;IAC1E,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,wEAAwE;IACxE,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,EAAE,gBAAgB,+BAe1E;AAED,MAAM,WAAW,iBAAiB;IAChC,sFAAsF;IACtF,IAAI,EAAE,MAAM,CAAC;IACb,qCAAqC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,iEAAiE;IACjE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kFAAkF;IAClF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2EAA2E;IAC3E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,0GAA0G;IAC1G,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACxB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,wEAAwE;IACxE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,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,QAAQ,GACT,EAAE,iBAAiB,+BAuCnB"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The document every page of a Deco TanStack site renders in. Mount it as the
|
|
4
|
+
* root route's component (or shell). Everything is always on:
|
|
5
|
+
*
|
|
6
|
+
* - `<html data-theme="light">` (DaisyUI reads its colors from it);
|
|
7
|
+
* - the `DECO.events` bus and the `data-event` observer analytics go through;
|
|
8
|
+
* - a progress bar during client-side navigation, and a content area that
|
|
9
|
+
* keeps its height while the next page loads;
|
|
10
|
+
* - the CDN segment token and the draft this request renders, for
|
|
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
|
+
*
|
|
17
|
+
* A site that keeps its own document renders `DecoPreview` in its `<body>`
|
|
18
|
+
* for the bridge, the badge and the draft they read.
|
|
19
|
+
*/
|
|
20
|
+
import { DraftBadge, StudioBridge } from "@decocms/blocks/preview";
|
|
21
|
+
import { HeadContent, Outlet, ScriptOnce, Scripts, useRouterState } from "@tanstack/react-router";
|
|
22
|
+
import { useEffect, useRef, useState } from "react";
|
|
23
|
+
import { STUDIO_ORIGINS } from "../studio.js";
|
|
24
|
+
import { pageValues, publishScript } from "./pageValues.js";
|
|
25
|
+
import { DATA_EVENT_OBSERVER, eventsBootstrap, PROGRESS_CSS } from "./scripts.js";
|
|
26
|
+
/** A loading bar at the top of the page during client-side navigation. */
|
|
27
|
+
export function NavigationProgress({ color = "var(--color-brand-primary-500, currentColor)", }) {
|
|
28
|
+
const isLoading = useRouterState({ select: (s) => s.isLoading });
|
|
29
|
+
if (!isLoading)
|
|
30
|
+
return null;
|
|
31
|
+
return (_jsxs("div", { className: "fixed top-0 left-0 right-0 z-[9999] h-1 overflow-hidden", style: { color }, role: "progressbar", "aria-label": "Carregando p\u00E1gina", children: [_jsx("style", { dangerouslySetInnerHTML: { __html: PROGRESS_CSS } }), _jsx("div", { className: "absolute inset-0", style: { backgroundColor: "currentColor", opacity: 0.2 } }), _jsx("div", { className: "nav-progress-bar absolute inset-y-0 left-0 w-1/3 rounded-full", style: { backgroundColor: "currentColor" } })] }));
|
|
32
|
+
}
|
|
33
|
+
/** Keeps the content area's height while the next page loads, so the footer doesn't jump. */
|
|
34
|
+
export function StableOutlet() {
|
|
35
|
+
const isLoading = useRouterState({ select: (s) => s.isLoading });
|
|
36
|
+
const ref = useRef(null);
|
|
37
|
+
const [savedHeight, setSavedHeight] = useState(undefined);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (isLoading && ref.current)
|
|
40
|
+
setSavedHeight(ref.current.offsetHeight);
|
|
41
|
+
else if (!isLoading)
|
|
42
|
+
setSavedHeight(undefined);
|
|
43
|
+
}, [isLoading]);
|
|
44
|
+
return (_jsx("div", { ref: ref, style: savedHeight ? { minHeight: savedHeight } : undefined, children: _jsx(Outlet, {}) }));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The page the "." shortcut opens in Studio: the deepest matched route whose
|
|
48
|
+
* loader data carries a string `pathTemplate` (the page block's `path`, as
|
|
49
|
+
* `matchRoute` matched it) and, optionally, `pageId`. v7's document read the
|
|
50
|
+
* same thing from its CMS route's `path` and `blockKey`.
|
|
51
|
+
*/
|
|
52
|
+
function studioPageOf(matches) {
|
|
53
|
+
for (let i = matches.length - 1; i >= 0; i--) {
|
|
54
|
+
const data = matches[i]?.loaderData;
|
|
55
|
+
if (data && typeof data === "object" && typeof data.pathTemplate === "string") {
|
|
56
|
+
return {
|
|
57
|
+
pathTemplate: data.pathTemplate,
|
|
58
|
+
id: typeof data.pageId === "string" ? data.pageId : undefined,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
/** The Studio bridge, with the page on screen, and the badge for the request's draft. */
|
|
65
|
+
function StudioPieces({ site, editShortcut, nonce, draft, }) {
|
|
66
|
+
// Two primitives, so a navigation that keeps the page doesn't re-render the document.
|
|
67
|
+
const pathTemplate = useRouterState({ select: (s) => studioPageOf(s.matches)?.pathTemplate });
|
|
68
|
+
const pageId = useRouterState({ select: (s) => studioPageOf(s.matches)?.id });
|
|
69
|
+
return (_jsxs(_Fragment, { children: [_jsx(StudioBridge, { site: site, trustedOrigins: STUDIO_ORIGINS, editShortcut: editShortcut, page: { pathTemplate, id: pageId }, nonce: nonce }), _jsx(DraftBadge, { pointer: draft ?? null })] }));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* What `DecoDocument` mounts for Studio and draft previews, for a site that
|
|
73
|
+
* keeps its own document (a skip link before `<main>`, say): the request's
|
|
74
|
+
* draft and CDN segment token published to the browser, `StudioBridge` and
|
|
75
|
+
* `DraftBadge`. Render it once, in the `<body>`.
|
|
76
|
+
*/
|
|
77
|
+
export function DecoPreview({ site, editShortcut, nonce }) {
|
|
78
|
+
const values = pageValues();
|
|
79
|
+
const publish = publishScript(values);
|
|
80
|
+
return (_jsxs(_Fragment, { children: [publish && (_jsx("script", { nonce: nonce, suppressHydrationWarning: true, dangerouslySetInnerHTML: { __html: publish } })), _jsx(StudioPieces, { site: site, editShortcut: editShortcut, nonce: nonce, draft: values.draft })] }));
|
|
81
|
+
}
|
|
82
|
+
export function DecoDocument({ site, lang = "en", bodyClassName = "bg-base-200 text-base-content", account = "", readyDelay = 500, outlet = "main", editShortcut, nonce, children, }) {
|
|
83
|
+
// Pages wait for this signal before running work that must follow hydration.
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
const id = setTimeout(() => {
|
|
86
|
+
window.__deco_ready = true;
|
|
87
|
+
document.dispatchEvent(new Event("deco:ready"));
|
|
88
|
+
}, readyDelay);
|
|
89
|
+
return () => clearTimeout(id);
|
|
90
|
+
}, [readyDelay]);
|
|
91
|
+
const values = pageValues();
|
|
92
|
+
const publish = publishScript(values);
|
|
93
|
+
const Outer = outlet;
|
|
94
|
+
return (_jsxs("html", { lang: lang, "data-theme": "light", suppressHydrationWarning: true, children: [_jsxs("head", { children: [_jsx(HeadContent, {}), publish && (_jsx("script", { nonce: nonce, suppressHydrationWarning: true, dangerouslySetInnerHTML: { __html: publish } }))] }), _jsxs("body", { className: bodyClassName, suppressHydrationWarning: true, children: [_jsx(ScriptOnce, { children: eventsBootstrap(account) }), _jsx(NavigationProgress, {}), _jsx(Outer, { children: _jsx(StableOutlet, {}) }), children, _jsx(StudioPieces, { site: site, editShortcut: editShortcut, nonce: nonce, draft: values.draft }), _jsx(ScriptOnce, { children: DATA_EVENT_OBSERVER }), _jsx(Scripts, {})] })] }));
|
|
95
|
+
}
|
|
96
|
+
//# sourceMapp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AE,KAAK,EAAE,MAAM,CAAC,KAAK,GAAI,EAC3F,KAAC,UAAU,cAAE,mBAAmB,GAAc,EAC9C,KAAC,OAAO,KAAG,IACN,IACF,CACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Image`, `Picture` and `Source`: v7's components (`@decocms/blocks` 7.x
|
|
3
|
+
* `hooks/Image.tsx` and `hooks/Picture.tsx`) with the same props and the same
|
|
4
|
+
* markup, so call sites move by changing the import. The URLs come from an
|
|
5
|
+
* `ImageUrl` (`@decocms/blocks/image`) instead of v7's module-wide
|
|
6
|
+
* `registerImageCdnDomain` / `registerImageQuality`: wrap the app in
|
|
7
|
+
* `<ImageUrlProvider value={imageUrl}>` with the site's own `createImageUrl`.
|
|
8
|
+
*
|
|
9
|
+
* This package knows no commerce platform. v7's components resized VTEX
|
|
10
|
+
* catalog and Shopify images on those platforms' hosts; a site that shows
|
|
11
|
+
* them lists the platform's helper first in its own `createImageUrl`
|
|
12
|
+
* (`vtexCatalog()` from `@decocms/apps-vtex/image`, `shopifyCdn()` from
|
|
13
|
+
* `@decocms/apps-shopify/image`), then `decoCdn({ sources: "all" })`, and
|
|
14
|
+
* gets v7's URLs byte for byte. Without a provider every source goes through
|
|
15
|
+
* the Deco image CDN (`assets.decocms.com`, the CDN's default quality):
|
|
16
|
+
* {@link DECO_IMAGE_URL}.
|
|
17
|
+
*
|
|
18
|
+
* Difference from v7, on purpose: no "Missing height" warning on every render.
|
|
19
|
+
*/
|
|
20
|
+
import { type Fit, type ImageUrl } from "@decocms/blocks/image";
|
|
21
|
+
import { type ComponentPropsWithoutRef, type ImgHTMLAttributes, type ReactNode } from "react";
|
|
22
|
+
/**
|
|
23
|
+
* The URLs without an `ImageUrlProvider`: every source through the Deco image
|
|
24
|
+
* CDN, as v7 sent every source that wasn't a VTEX catalog or Shopify image.
|
|
25
|
+
*/
|
|
26
|
+
export declare const DECO_IMAGE_URL: ImageUrl;
|
|
27
|
+
/** The site's image URLs for every `Image`, `Picture` and `Source` below it. */
|
|
28
|
+
export declare function ImageUrlProvider({ value, children }: {
|
|
29
|
+
value: ImageUrl;
|
|
30
|
+
children?: ReactNode;
|
|
31
|
+
}): import("react").JSX.Element;
|
|
32
|
+
/** The `ImageUrl` the nearest `ImageUrlProvider` gives ({@link DECO_IMAGE_URL} without one). */
|
|
33
|
+
export declare function useImageUrl(): ImageUrl;
|
|
34
|
+
export interface ImageProps extends Omit<ImgHTMLAttributes<HTMLImageElement>, "src" | "width" | "height"> {
|
|
35
|
+
src: string;
|
|
36
|
+
/** @description Improves Web Vitals (CLS/LCP) */
|
|
37
|
+
width: number;
|
|
38
|
+
/** @description Improves Web Vitals (CLS/LCP) */
|
|
39
|
+
height?: number;
|
|
40
|
+
/** @description Object-fit */
|
|
41
|
+
fit?: Fit;
|
|
42
|
+
/**
|
|
43
|
+
* @description Web Vitals (LCP). Injects a `<link rel="preload">` tag
|
|
44
|
+
* alongside the `<img>`, sets `fetchPriority="high"` and `loading="eager"`.
|
|
45
|
+
* Use once per page for the LCP image.
|
|
46
|
+
*/
|
|
47
|
+
preload?: boolean;
|
|
48
|
+
/** @description Media query for responsive preloading (e.g. "(min-width: 768px)") */
|
|
49
|
+
media?: string;
|
|
50
|
+
}
|
|
51
|
+
export declare const Image: import("react").ForwardRefExoticComponent<ImageProps & import("react").RefAttributes<HTMLImageElement>>;
|
|
52
|
+
export type SourceProps = Omit<ComponentPropsWithoutRef<"source">, "width" | "height"> & {
|
|
53
|
+
src: string;
|
|
54
|
+
/** @description Improves Web Vitals (CLS|LCP) */
|
|
55
|
+
width: number;
|
|
56
|
+
/** @description Improves Web Vitals (CLS|LCP) */
|
|
57
|
+
height?: number;
|
|
58
|
+
/** @description Improves Web Vitals (LCP). Use high for LCP image. */
|
|
59
|
+
fetchPriority?: "high" | "low" | "auto";
|
|
60
|
+
/** @description Object-fit */
|
|
61
|
+
fit?: Fit;
|
|
62
|
+
};
|
|
63
|
+
/** A `<source>` with its srcset built for it; inside `<Picture preload>`, it also preloads for its media query. */
|
|
64
|
+
export declare const Source: import("react").ForwardRefExoticComponent<Omit<Omit<import("react").DetailedHTMLProps<import("react").SourceHTMLAttributes<HTMLSourceElement>, HTMLSourceElement>, "ref">, "height" | "width"> & {
|
|
65
|
+
src: string;
|
|
66
|
+
/** @description Improves Web Vitals (CLS|LCP) */
|
|
67
|
+
width: number;
|
|
68
|
+
/** @description Improves Web Vitals (CLS|LCP) */
|
|
69
|
+
height?: number;
|
|
70
|
+
/** @description Improves Web Vitals (LCP). Use high for LCP image. */
|
|
71
|
+
fetchPriority?: "high" | "low" | "auto";
|
|
72
|
+
/** @description Object-fit */
|
|
73
|
+
fit?: Fit;
|
|
74
|
+
} & import("react").RefAttributes<HTMLSourceElement>>;
|
|
75
|
+
export type PictureProps = ComponentPropsWithoutRef<"picture"> & {
|
|
76
|
+
children: ReactNode;
|
|
77
|
+
/** @description When true, child `<Source>` elements inject `<link rel="preload">` tags for their media queries. */
|
|
78
|
+
preload?: boolean;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Art direction: `<Source>`s per media query and an `<Image>` fallback.
|
|
82
|
+
*
|
|
83
|
+
* ```tsx
|
|
84
|
+
* <Picture preload={isLcp}>
|
|
85
|
+
* <Source media="(max-width: 767px)" src={mobile} width={320} height={280} />
|
|
86
|
+
* <Source media="(min-width: 768px)" src={desktop} width={1280} height={280} />
|
|
87
|
+
* <Image src={desktop} width={1280} height={280} />
|
|
88
|
+
* </Picture>
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare const Picture: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLElement>, HTMLElement>, "ref"> & {
|
|
92
|
+
children: ReactNode;
|
|
93
|
+
/** @description When true, child `<Source>` elements inject `<link rel="preload">` tags for their media queries. */
|
|
94
|
+
preload?: boolean;
|
|
95
|
+
} & import("react").RefAttributes<HTMLPicture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AM,CAAC;IACd,iDAAiD;IACjD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sEAAsE;IACtE,aAAa,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,CAAC;IACxC,8BAA8B;IAC9B,GAAG,CAAC,EAAE,GAAG,CAAC;CACX,CAAC;AAEF,mHAAmH;AACnH,eAAO,MAAM,MAAM;SAZZ,MAAM;IACX,iDAAiD;WAC1C,MAAM;IACb,iDAAiD;aACxC,MAAM;IACf,sEAAsE;oBACtD,MAAM,GAAG,KAAK,GAAG,MAAM;IACvC,8BAA8B;UACxB,GAAG;qDA4BT,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,wBAAwB,CAAC,SAAS,CAAC,GAAG;IAC/D,QAAQ,EAAE,SAAS,CAAC;IACpB,oHAAoH;IACpH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,OAAO;cAhBR,SAAS;IACnB,oHAAoH;cAC1G,OAAO;sDA0BjB,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
/**
|
|
4
|
+
* `Image`, `Picture` and `Source`: v7's components (`@decocms/blocks` 7.x
|
|
5
|
+
* `hooks/Image.tsx` and `hooks/Picture.tsx`) with the same props and the same
|
|
6
|
+
* markup, so call sites move by changing the import. The URLs come from an
|
|
7
|
+
* `ImageUrl` (`@decocms/blocks/image`) instead of v7's module-wide
|
|
8
|
+
* `registerImageCdnDomain` / `registerImageQuality`: wrap the app in
|
|
9
|
+
* `<ImageUrlProvider value={imageUrl}>` with the site's own `createImageUrl`.
|
|
10
|
+
*
|
|
11
|
+
* This package knows no commerce platform. v7's components resized VTEX
|
|
12
|
+
* catalog and Shopify images on those platforms' hosts; a site that shows
|
|
13
|
+
* them lists the platform's helper first in its own `createImageUrl`
|
|
14
|
+
* (`vtexCatalog()` from `@decocms/apps-vtex/image`, `shopifyCdn()` from
|
|
15
|
+
* `@decocms/apps-shopify/image`), then `decoCdn({ sources: "all" })`, and
|
|
16
|
+
* gets v7's URLs byte for byte. Without a provider every source goes through
|
|
17
|
+
* the Deco image CDN (`assets.decocms.com`, the CDN's default quality):
|
|
18
|
+
* {@link DECO_IMAGE_URL}.
|
|
19
|
+
*
|
|
20
|
+
* Difference from v7, on purpose: no "Missing height" warning on every render.
|
|
21
|
+
*/
|
|
22
|
+
import { createImageUrl, decoCdn, srcSet as srcSetOf, } from "@decocms/blocks/image";
|
|
23
|
+
import { createContext, forwardRef, useContext, useMemo, } from "react";
|
|
24
|
+
/**
|
|
25
|
+
* The URLs without an `ImageUrlProvider`: every source through the Deco image
|
|
26
|
+
* CDN, as v7 sent every source that wasn't a VTEX catalog or Shopify image.
|
|
27
|
+
*/
|
|
28
|
+
export const DECO_IMAGE_URL = createImageUrl({
|
|
29
|
+
providers: [decoCdn({ sources: "all" })],
|
|
30
|
+
});
|
|
31
|
+
// One pair of contexts per process even if a bundler duplicates this module,
|
|
32
|
+
// so a provider always reaches its components.
|
|
33
|
+
const KEY = Symbol.for("decocms.tanstack.imageContexts");
|
|
34
|
+
const holder = globalThis;
|
|
35
|
+
const contexts = holder[KEY] ?? {
|
|
36
|
+
imageUrl: createContext(DECO_IMAGE_URL),
|
|
37
|
+
preload: createContext({ preload: false }),
|
|
38
|
+
};
|
|
39
|
+
holder[KEY] = contexts;
|
|
40
|
+
/** The site's image URLs for every `Image`, `Picture` and `Source` below it. */
|
|
41
|
+
export function ImageUrlProvider({ value, children }) {
|
|
42
|
+
return _jsx(contexts.imageUrl.Provider, { value: value, children: children });
|
|
43
|
+
}
|
|
44
|
+
/** The `ImageUrl` the nearest `ImageUrlProvider` gives ({@link DECO_IMAGE_URL} without one). */
|
|
45
|
+
export function useImageUrl() {
|
|
46
|
+
return useContext(contexts.imageUrl);
|
|
47
|
+
}
|
|
48
|
+
const DEFAULT_SIZES = "(max-width: 768px) 100vw, 50vw";
|
|
49
|
+
export const Image = forwardRef(function Image({ src, width, height, fit = "cover", preload, media, loading, decoding, srcSet: srcSetProp, sizes, fetchPriority, ...rest }, ref) {
|
|
50
|
+
const url = useImageUrl();
|
|
51
|
+
const optimizedSrc = url(src, { width, height, fit });
|
|
52
|
+
const srcSet = srcSetProp ?? srcSetOf(url, src, { width, height, fit });
|
|
53
|
+
const resolvedSizes = srcSet ? (sizes ?? DEFAULT_SIZES) : undefined;
|
|
54
|
+
return (_jsxs(_Fragment, { children: [preload && (_jsx("link", { as: "image", rel: "preload", href: optimizedSrc, imageSrcSet: srcSet, imageSizes: resolvedSizes, fetchPriority: fetchPriority ?? "high", media: media })), _jsx("img", { ...rest, src: optimizedSrc, srcSet: srcSet, sizes: resolvedSizes, width: width, height: height, loading: loading ?? (preload ? "eager" : "lazy"), decoding: decoding ?? "async", fetchPriority: preload ? "high" : fetchPriority, ref: ref })] }));
|
|
55
|
+
});
|
|
56
|
+
/** A `<source>` with its srcset built for it; inside `<Picture preload>`, it also preloads for its media query. */
|
|
57
|
+
export const Source = forwardRef(function Source({ src, width, height, fetchPriority, fit = "cover", ...rest }, ref) {
|
|
58
|
+
const { preload } = useContext(contexts.preload);
|
|
59
|
+
const url = useImageUrl();
|
|
60
|
+
const optimizedSrc = url(src, { width, height, fit });
|
|
61
|
+
const srcSet = rest.srcSet ?? srcSetOf(url, src, { width, height, fit });
|
|
62
|
+
return (_jsxs(_Fragment, { children: [preload && (_jsx("link", { as: "image", rel: "preload", href: optimizedSrc, imageSrcSet: srcSet, fetchPriority: fetchPriority ?? "high", media: rest.media })), _jsx("source", { ...rest, srcSet: srcSet ?? optimizedSrc, width: width, height: height, ref: ref })] }));
|
|
63
|
+
});
|
|
64
|
+
/**
|
|
65
|
+
* Art direction: `<Source>`s per media query and an `<Image>` fallback.
|
|
66
|
+
*
|
|
67
|
+
* ```tsx
|
|
68
|
+
* <Picture preload={isLcp}>
|
|
69
|
+
* <Source media="(max-width: 767px)" src={mobile} width={320} height={280} />
|
|
70
|
+
* <Source media="(min-width: 768px)" src={desktop} width={1280} height={280} />
|
|
71
|
+
* <Image src={desktop} width={1280} height={280} />
|
|
72
|
+
* </Picture>
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export const Picture = forwardRef(function Picture({ children, preload = false, ...props }, ref) {
|
|
76
|
+
const value = useMemo(() => ({ preload }), [preload]);
|
|
77
|
+
return (_jsx(contexts.preload.Provider, { value: value, children: _jsx("picture", { ...props, ref: ref, children: children }) }));
|
|
78
|
+
});
|
|
79
|
+
//# sourceMappingURL=Image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Image.js","sourceRoot":"","sources":["../../src/react/Image.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AACb;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EACL,cAAc,EACd,OAAO,EAGP,MAAM,IAAI,QAAQ,GACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAGL,aAAa,EACb,UAAU,EAGV,UAAU,EACV,OAAO,GACR,MAAM,OAAO,CAAC;AAEf;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAa,cAAc,CAAC;IACrD,SAAS,EAAE,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;CACzC,CAAC,CAAC;AAOH,6EAA6E;AAC7E,+CAA+C;AAC/C,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;AACzD,MAAM,MAAM,GAAG,UAA6D,CAAC;AAC7E,MAAM,QAAQ,GAAa,MAAM,CAAC,GAAG,CAAC,IAAI;IACxC,QAAQ,EAAE,aAAa,CAAW,cAAc,CAAC;IACjD,OAAO,EAAE,aAAa,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;CAC3C,CAAC;AACF,MAAM,CAAC,GAAG,CAAC,GAAG,QA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AAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,GAAI,IAC3F,CACJ,CAAC;AACJ,CAAC,CAAC,CAAC;AAQH;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,UAAU,CAAmC,SAAS,OAAO,CAClF,EAAE,QAAQ,EAAE,OAAO,GAAG,KAAK,EAAE,GAAG,KAAK,EAAE,EACvC,GAAG;IAEH,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IACtD,OAAO,CACL,KAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YACrC,qBAAa,KAAK,EAAE,GAAG,EAAE,GAAG,YACzB,QAAQ,GACD,GACgB,CAC7B,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@decocms/tanstack/react`: the root document and its pieces, and the image
|
|
3
|
+
* components. Safe in the browser bundle.
|
|
4
|
+
*/
|
|
5
|
+
export { DecoDocument, type DecoDocumentProps, DecoPreview, type DecoPreviewProps, NavigationProgress, type NavigationProgressProps, StableOutlet, } from "./DecoDocument.tsx";
|
|
6
|
+
export { DECO_IMAGE_URL, Image, type ImageProps, ImageUrlProvider, Picture, type PictureProps, Source, type SourceProps, useImageUrl, } from "./Image.tsx";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,YAAY,EACZ,KAAK,iBAAiB,EACtB,WAAW,EACX,KAAK,gBAAgB,EACrB,kBAAkB,EAClB,KAAK,uBAAuB,EAC5B,YAAY,GACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,cAAc,EACd,KAAK,EACL,KAAK,UAAU,EACf,gBAAgB,EAChB,OAAO,EACP,KAAK,YAAY,EACjB,MAAM,EACN,KAAK,WAAW,EAChB,WAAW,GACZ,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@decocms/tanstack/react`: the root document and its pieces, and the image
|
|
3
|
+
* components. Safe in the browser bundle.
|
|
4
|
+
*/
|
|
5
|
+
export { DecoDocument, DecoPreview, NavigationProgress, StableOutlet, } from "./DecoDocument.js";
|
|
6
|
+
export { DECO_IMAGE_URL, Image, ImageUrlProvider, Picture, Source, useImageUrl, } from "./Image.js";
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,YAAY,EAEZ,WAAW,EAEX,kBAAkB,EAElB,YAAY,GACb,MAAM,mBAAoB,CAAC;AAC5B,OAAO,EACL,cAAc,EACd,KAAK,EAEL,gBAAgB,EAChB,OAAO,EAEP,MAAM,EAEN,WAAW,GACZ,MAAM,YAAa,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const DRAFT_GLOBAL = "__DECO_DRAFT";
|
|
2
|
+
export interface PageValues {
|
|
3
|
+
cseg?: string;
|
|
4
|
+
draft?: string;
|
|
5
|
+
}
|
|
6
|
+
/** On the server, the request scope; in the browser, what the server published on `window`. */
|
|
7
|
+
export declare function pageValues(): PageValues;
|
|
8
|
+
/** The script that publishes `pageValues()`; the same markup on the server and in the browser. */
|
|
9
|
+
export declare function publishScript(values: PageValues): string | null;
|
|
10
|
+
//# sourceMappingURL=pageValues.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pageValues.d.ts","sourceRoot":"","sources":["../../src/react/pageValues.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,YAAY,iBAAiB,CAAC;AAE3C,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,+FAA+F;AAC/F,wBAAgB,UAAU,IAAI,UAAU,CASvC;AAED,kGAAkG;AAClG,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CAO/D"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the worker handed this request's render (the CDN segment token and the
|
|
3
|
+
* draft), and the inline script that publishes it to the browser.
|
|
4
|
+
*/
|
|
5
|
+
import { currentScope } from "@decocms/tanstack/scope";
|
|
6
|
+
import { CSEG_GLOBAL } from "../shared.js";
|
|
7
|
+
export const DRAFT_GLOBAL = "__DECO_DRAFT";
|
|
8
|
+
/** On the server, the request scope; in the browser, what the server published on `window`. */
|
|
9
|
+
export function pageValues() {
|
|
10
|
+
if (typeof window !== "undefined") {
|
|
11
|
+
const w = window;
|
|
12
|
+
const pick = (k) => typeof w[k] === "string" && w[k] !== "" ? w[k] : undefined;
|
|
13
|
+
return { cseg: pick(CSEG_GLOBAL), draft: pick(DRAFT_GLOBAL) };
|
|
14
|
+
}
|
|
15
|
+
const scope = currentScope();
|
|
16
|
+
return { cseg: scope?.csegToken, draft: scope?.draft };
|
|
17
|
+
}
|
|
18
|
+
/** The script that publishes `pageValues()`; the same markup on the server and in the browser. */
|
|
19
|
+
export function publishScript(values) {
|
|
20
|
+
const parts = [];
|
|
21
|
+
// JSON.stringify keeps the values inert; `<` is escaped so they can't close the script.
|
|
22
|
+
const literal = (v) => JSON.stringify(v).replace(/</g, "\\u003c");
|
|
23
|
+
if (values.cseg)
|
|
24
|
+
parts.push(`window.${CSEG_GLOBAL}=${literal(values.cseg)}`);
|
|
25
|
+
if (values.draft)
|
|
26
|
+
parts.push(`window.${DRAFT_GLOBAL}=${literal(values.draft)}`);
|
|
27
|
+
return parts.length ? parts.join(";") : null;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=pageValues.js.map
|