@weaverse/next 0.1.0-alpha.9 → 1.0.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 +161 -73
- package/dist/{chunk-6PMZ77RA.mjs → chunk-OSC5HR5V.mjs} +117 -8
- package/dist/chunk-OSC5HR5V.mjs.map +1 -0
- package/dist/client-boundary.js +1425 -0
- package/dist/client-boundary.js.map +1 -0
- package/dist/client-boundary.mjs +1395 -0
- package/dist/client-boundary.mjs.map +1 -0
- package/dist/index.js +292 -1003
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +90 -966
- package/dist/index.mjs.map +1 -1
- package/dist/server.js +321 -91
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +205 -28
- package/dist/server.mjs.map +1 -1
- package/dist/types/client-boundary.d.ts +25 -0
- package/dist/types/client-boundary.d.ts.map +1 -0
- package/dist/types/client.d.ts +16 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/hooks.d.ts +20 -0
- package/dist/types/hooks.d.ts.map +1 -0
- package/dist/types/index.d.ts +33 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/item.d.ts +60 -0
- package/dist/types/item.d.ts.map +1 -0
- package/dist/types/loader.d.ts +25 -0
- package/dist/types/loader.d.ts.map +1 -0
- package/dist/types/main.d.ts +11 -0
- package/dist/types/main.d.ts.map +1 -0
- package/dist/types/provider.d.ts +82 -0
- package/dist/types/provider.d.ts.map +1 -0
- package/dist/types/registry.d.ts +15 -0
- package/dist/types/registry.d.ts.map +1 -0
- package/dist/types/renderer.d.ts +21 -0
- package/dist/types/renderer.d.ts.map +1 -0
- package/dist/types/request-info.d.ts +19 -0
- package/dist/types/request-info.d.ts.map +1 -0
- package/dist/types/revalidate-item.d.ts +82 -0
- package/dist/types/revalidate-item.d.ts.map +1 -0
- package/dist/types/root-provider.d.ts +62 -0
- package/dist/types/root-provider.d.ts.map +1 -0
- package/dist/types/runtime.d.ts +113 -0
- package/dist/types/runtime.d.ts.map +1 -0
- package/dist/types/seo.d.ts +55 -0
- package/dist/types/seo.d.ts.map +1 -0
- package/dist/types/server/configs.d.ts +27 -0
- package/dist/types/server/configs.d.ts.map +1 -0
- package/dist/types/server/normalize-page-url.d.ts +19 -0
- package/dist/types/server/normalize-page-url.d.ts.map +1 -0
- package/dist/types/server/revalidate-handler.d.ts +55 -0
- package/dist/types/server/revalidate-handler.d.ts.map +1 -0
- package/dist/types/server/server-client.d.ts +21 -0
- package/dist/types/server/server-client.d.ts.map +1 -0
- package/dist/types/server.d.ts +19 -0
- package/dist/types/server.d.ts.map +1 -0
- package/dist/types/studio-bridge.d.ts +16 -0
- package/dist/types/studio-bridge.d.ts.map +1 -0
- package/dist/types/studio-connect.d.ts +27 -0
- package/dist/types/studio-connect.d.ts.map +1 -0
- package/dist/types/studio-router.d.ts +50 -0
- package/dist/types/studio-router.d.ts.map +1 -0
- package/dist/types/studio-script-src.d.ts +12 -0
- package/dist/types/studio-script-src.d.ts.map +1 -0
- package/dist/types/theme-settings-store.d.ts +18 -0
- package/dist/types/theme-settings-store.d.ts.map +1 -0
- package/dist/types/translate.d.ts +56 -0
- package/dist/types/translate.d.ts.map +1 -0
- package/dist/types/translation-context.d.ts +109 -0
- package/dist/types/translation-context.d.ts.map +1 -0
- package/dist/types/translation-store.d.ts +44 -0
- package/dist/types/translation-store.d.ts.map +1 -0
- package/dist/types/types.d.ts +665 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/use-weaverse-next-studio.d.ts +34 -0
- package/dist/types/use-weaverse-next-studio.d.ts.map +1 -0
- package/dist/types/utils.d.ts +22 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/package.json +12 -27
- package/src/client-boundary.ts +50 -0
- package/src/client.ts +102 -0
- package/src/hooks.ts +50 -0
- package/src/index.ts +143 -0
- package/src/item.ts +167 -0
- package/src/loader.ts +135 -0
- package/src/main.tsx +45 -0
- package/src/provider.tsx +223 -0
- package/src/registry.ts +63 -0
- package/src/renderer.tsx +100 -0
- package/src/request-info.ts +124 -0
- package/src/revalidate-item.ts +211 -0
- package/src/root-provider.tsx +180 -0
- package/src/runtime.ts +555 -0
- package/src/seo.ts +157 -0
- package/src/server/configs.ts +178 -0
- package/src/server/normalize-page-url.ts +73 -0
- package/src/server/revalidate-handler.ts +357 -0
- package/src/server/server-client.ts +728 -0
- package/src/server.ts +67 -0
- package/src/studio-bridge.tsx +82 -0
- package/src/studio-connect.tsx +88 -0
- package/src/studio-router.ts +85 -0
- package/src/studio-script-src.ts +128 -0
- package/src/theme-settings-store.ts +47 -0
- package/src/translate.ts +125 -0
- package/src/translation-context.tsx +182 -0
- package/src/translation-store.ts +69 -0
- package/src/types.ts +753 -0
- package/src/use-weaverse-next-studio.tsx +106 -0
- package/src/utils.ts +49 -0
- package/dist/chunk-6PMZ77RA.mjs.map +0 -1
- package/dist/index.d.mts +0 -580
- package/dist/index.d.ts +0 -580
- package/dist/seo-Dos9t22_.d.mts +0 -477
- package/dist/seo-Dos9t22_.d.ts +0 -477
- package/dist/server.d.mts +0 -99
- package/dist/server.d.ts +0 -99
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC1C,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,QAAQ,CAAA;AAIf,OAAO,KAAK,EAGV,oBAAoB,EACpB,uBAAuB,EACvB,yBAAyB,EACzB,2BAA2B,EAC3B,8BAA8B,EAE9B,0BAA0B,EAC3B,MAAM,SAAS,CAAA;AAEhB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,UAAU,CAAC,EAAE,mBAAmB,CAAA;QAChC,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAA;KAClD;CACF;AAgJD,yEAAyE;AACzE,MAAM,WAAW,0BAA2B,SAAQ,oBAAoB;IACtE,oEAAoE;IACpE,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;GAGG;AACH,qBAAa,mBAAoB,SAAQ,QAAQ;IAC/C,mDAAmD;IACnD,MAAM,EAAE,MAAM,CAAA;IACd,kEAAkE;IAClE,QAAQ,EAAE,2BAA2B,CAAA;IACrC,8DAA8D;IAC9D,WAAW,EAAE,uBAAuB,CAAA;IACpC,wDAAwD;IACxD,aAAa,EAAE,OAAO,CAAA;IACtB,qDAAqD;IACrD,iBAAiB,EAAE,OAAO,CAAA;IAC1B,uDAAuD;IACvD,WAAW,CAAC,EAAE,MAAM,CAAA;IAGpB;;;;OAIG;IACH,cAAc,EAAE,0BAA0B,CAAK;IAC/C,iEAAiE;IACjE,iBAAiB,SAAW;IAC5B,iEAAiE;IACjE,qBAAqB,SAAW;IAEhC;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,0BAA0B,CAAA;IAE/C;;;;;OAKG;IACH,kBAAkB,EAAE,gBAAgB,EAAE,CAAK;IAE3C,2EAA2E;gBAC/D,MAAM,EAAE,yBAAyB;IAuD7C;;;;;;OAMG;IACH,yBAAyB,aAexB;IAED;;;;OAIG;IACH,qBAAqB,GACnB,MAAK,0BAA+B,EACpC,eAAW,EACX,mBAAe,UAMhB;IAED;;;;OAIG;IACH,iBAAiB,GACf,QAAQ,MAAM,EACd,KAAK,MAAM,EACX,eAAe,MAAM,EACrB,iBAAiB,MAAM,UAcxB;IAED;;;;OAIG;IACH,qBAAqB,QAAO,8BAA8B,GAAG,SAAS,CAsBrE;IAED;;;;;OAKG;IACH,cAAc,GAAI,MAAM,0BAA0B,UAIjD;IAED;;;;;;OAMG;IACH,uBAAuB,aActB;CACF;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,yBAAyB,GAChC,mBAAmB,CA2FrB;AAED;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,OAAO,EAAE,mBAAmB,WAwCzE"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { PageSEOData } from '@weaverse/schema';
|
|
2
|
+
import type { Metadata } from 'next';
|
|
3
|
+
import type { WeaverseNextLoaderData, WeaverseNextPageData } from './types';
|
|
4
|
+
/** Object containing an optional Weaverse page for SEO extraction. */
|
|
5
|
+
export interface WeaverseNextSeoPageContainer {
|
|
6
|
+
/** Page whose published SEO fields should be formatted. */
|
|
7
|
+
page?: WeaverseNextPageData | null;
|
|
8
|
+
}
|
|
9
|
+
/** Input accepted by {@link getWeaverseNextSeoMetadata}. */
|
|
10
|
+
export type WeaverseNextSeoInput = WeaverseNextLoaderData | WeaverseNextPageData | WeaverseNextSeoPageContainer | null | undefined;
|
|
11
|
+
/** Open Graph metadata accepted by Next.js's `Metadata` API. */
|
|
12
|
+
export type NextOpenGraph = NonNullable<Metadata['openGraph']>;
|
|
13
|
+
/** Twitter card metadata accepted by Next.js's `Metadata` API. */
|
|
14
|
+
export type NextTwitter = NonNullable<Metadata['twitter']>;
|
|
15
|
+
/**
|
|
16
|
+
* Weaverse page SEO expressed as a subset of Next's `Metadata`. Assignable to
|
|
17
|
+
* `Metadata` as-is: `const metadata: Metadata = getWeaverseNextSeoMetadata(data)`.
|
|
18
|
+
*/
|
|
19
|
+
export interface WeaverseNextSeoMetadata {
|
|
20
|
+
/** Canonical URL settings for Next's metadata API. */
|
|
21
|
+
alternates?: {
|
|
22
|
+
/** Preferred URL for search indexing. */
|
|
23
|
+
canonical?: string;
|
|
24
|
+
};
|
|
25
|
+
/** Page meta description. */
|
|
26
|
+
description?: string;
|
|
27
|
+
/** Page meta keywords. */
|
|
28
|
+
keywords?: string;
|
|
29
|
+
/** Open Graph metadata normalized to Next's supported union. */
|
|
30
|
+
openGraph?: NextOpenGraph;
|
|
31
|
+
/** Search crawler indexing and link-following directives. */
|
|
32
|
+
robots: {
|
|
33
|
+
/** Whether crawlers may follow links on the page. */
|
|
34
|
+
follow: boolean;
|
|
35
|
+
/** Whether crawlers may index the page. */
|
|
36
|
+
index: boolean;
|
|
37
|
+
};
|
|
38
|
+
/** Page title. */
|
|
39
|
+
title?: string;
|
|
40
|
+
/** Twitter card metadata normalized for Next's metadata API. */
|
|
41
|
+
twitter?: NextTwitter;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Convert Builder SEO fields into metadata accepted by Next.js.
|
|
45
|
+
*
|
|
46
|
+
* Unsupported Open Graph product types and incomplete Twitter app/player
|
|
47
|
+
* cards are safely downgraded to renderable Next.js variants.
|
|
48
|
+
*/
|
|
49
|
+
export declare function formatWeaverseNextSeoMetadata(seo: PageSEOData | null | undefined): WeaverseNextSeoMetadata;
|
|
50
|
+
/**
|
|
51
|
+
* Read page SEO from loader data or a page payload and format it for Next.js
|
|
52
|
+
* `generateMetadata`. Missing data returns indexable/followable robot defaults.
|
|
53
|
+
*/
|
|
54
|
+
export declare function getWeaverseNextSeoMetadata(data: WeaverseNextSeoInput): WeaverseNextSeoMetadata;
|
|
55
|
+
//# sourceMappingURL=seo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seo.d.ts","sourceRoot":"","sources":["../../src/seo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAA;AACpC,OAAO,KAAK,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAE3E,sEAAsE;AACtE,MAAM,WAAW,4BAA4B;IAC3C,2DAA2D;IAC3D,IAAI,CAAC,EAAE,oBAAoB,GAAG,IAAI,CAAA;CACnC;AAED,4DAA4D;AAC5D,MAAM,MAAM,oBAAoB,GAC5B,sBAAsB,GACtB,oBAAoB,GACpB,4BAA4B,GAC5B,IAAI,GACJ,SAAS,CAAA;AAEb,gEAAgE;AAChE,MAAM,MAAM,aAAa,GAAG,WAAW,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAA;AAE9D,kEAAkE;AAClE,MAAM,MAAM,WAAW,GAAG,WAAW,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAA;AAE1D;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,sDAAsD;IACtD,UAAU,CAAC,EAAE;QACX,yCAAyC;QACzC,SAAS,CAAC,EAAE,MAAM,CAAA;KACnB,CAAA;IACD,6BAA6B;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,gEAAgE;IAChE,SAAS,CAAC,EAAE,aAAa,CAAA;IACzB,6DAA6D;IAC7D,MAAM,EAAE;QACN,qDAAqD;QACrD,MAAM,EAAE,OAAO,CAAA;QACf,2CAA2C;QAC3C,KAAK,EAAE,OAAO,CAAA;KACf,CAAA;IACD,kBAAkB;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,gEAAgE;IAChE,OAAO,CAAC,EAAE,WAAW,CAAA;CACtB;AA+BD;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,GAAG,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,GAClC,uBAAuB,CAiDzB;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,oBAAoB,GACzB,uBAAuB,CASzB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { WeaverseNextBaseConfigs, WeaverseNextRequestContext } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Extract the request search params from the explicit Next request context.
|
|
4
|
+
* Prefers `searchParams`, falls back to parsing `url`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getContextSearchParams(context?: WeaverseNextRequestContext): URLSearchParams;
|
|
7
|
+
/** Overrides used while resolving request-scoped Weaverse configuration. */
|
|
8
|
+
export interface ResolveConfigsOptions {
|
|
9
|
+
/** Environment values; missing keys fall back to `process.env`. */
|
|
10
|
+
env?: Record<string, string | undefined>;
|
|
11
|
+
/** Public data API base override. */
|
|
12
|
+
weaverseApiBase?: string;
|
|
13
|
+
/** Studio origin override. */
|
|
14
|
+
weaverseHost?: string;
|
|
15
|
+
/** Studio asset version override. */
|
|
16
|
+
weaverseVersion?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Derive Weaverse configs from the request context and env, close to Hydrogen's
|
|
20
|
+
* `getWeaverseConfigs`. Resolves the trusted host, public API base, design /
|
|
21
|
+
* preview / revision flags, and public env — but never resolves the final
|
|
22
|
+
* `projectId` (that priority chain, which may call an async resolver, lives in
|
|
23
|
+
* the server client). Query/env projectId candidates are returned for the
|
|
24
|
+
* client to combine with function/string inputs.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getWeaverseNextConfigs(context?: WeaverseNextRequestContext, options?: ResolveConfigsOptions): WeaverseNextBaseConfigs;
|
|
27
|
+
//# sourceMappingURL=configs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configs.d.ts","sourceRoot":"","sources":["../../../src/server/configs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,uBAAuB,EACvB,0BAA0B,EAC3B,MAAM,UAAU,CAAA;AA6CjB;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,CAAC,EAAE,0BAA0B,GACnC,eAAe,CAWjB;AAkCD,4EAA4E;AAC5E,MAAM,WAAW,qBAAqB;IACpC,mEAAmE;IACnE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;IACxC,qCAAqC;IACrC,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,8BAA8B;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,qCAAqC;IACrC,eAAe,CAAC,EAAE,MAAM,CAAA;CACzB;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,CAAC,EAAE,0BAA0B,EACpC,OAAO,GAAE,qBAA0B,GAClC,uBAAuB,CAuDzB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { WeaverseNextRequestContext } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Normalize the storefront URL sent in the Builder page API request body.
|
|
4
|
+
*
|
|
5
|
+
* The Builder reads only the pathname (locale/type/handle fallback) and the
|
|
6
|
+
* Weaverse/Studio control params from this URL, so keep exactly those and drop
|
|
7
|
+
* tracking params. Params are sorted for a stable, cache-friendly string.
|
|
8
|
+
*
|
|
9
|
+
* Ported from `@weaverse/hydrogen`'s `normalizePageUrl`, but tolerant of a
|
|
10
|
+
* relative URL (Next route handlers may only know the pathname).
|
|
11
|
+
*/
|
|
12
|
+
export declare function normalizeNextPageUrl(url: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Build an absolute-ish request URL string from the explicit request context,
|
|
15
|
+
* preferring `url`, then `pathname` + `searchParams`. Used as the input to
|
|
16
|
+
* {@link normalizeNextPageUrl}.
|
|
17
|
+
*/
|
|
18
|
+
export declare function resolveRequestUrl(context?: WeaverseNextRequestContext): string;
|
|
19
|
+
//# sourceMappingURL=normalize-page-url.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-page-url.d.ts","sourceRoot":"","sources":["../../../src/server/normalize-page-url.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAA;AAa1D;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAqBxD;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,CAAC,EAAE,0BAA0B,GACnC,MAAM,CAkBR"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type WeaverseNextRevalidateRouteContext } from '../revalidate-item';
|
|
2
|
+
import type { WeaverseNextComponentData, WeaverseNextRequestContext, WeaverseNextServerClient } from '../types';
|
|
3
|
+
/** Configuration for the App Router item-revalidation handler. */
|
|
4
|
+
export interface WeaverseNextRevalidateHandlerConfig {
|
|
5
|
+
/**
|
|
6
|
+
* Reuse the app's server-client factory so the loader runs with the same
|
|
7
|
+
* component registry and commerce (storefront) context as page loads.
|
|
8
|
+
*
|
|
9
|
+
* The optional second argument is the validated, same-origin route context
|
|
10
|
+
* reconstructed from the request body. It is `undefined` for legacy bodies
|
|
11
|
+
* that carry no `routeContext`, so a one-argument `(request) => client`
|
|
12
|
+
* callback remains valid. Consumers must still source project ID, Studio
|
|
13
|
+
* host, API bases/keys, and env from server config — never from this
|
|
14
|
+
* browser-provided context.
|
|
15
|
+
*/
|
|
16
|
+
getClient: (request: Request, requestContext?: WeaverseNextRequestContext) => Promise<WeaverseNextServerClient> | WeaverseNextServerClient;
|
|
17
|
+
}
|
|
18
|
+
/** POST body accepted by the revalidate route. */
|
|
19
|
+
export interface WeaverseNextRevalidateRequestBody {
|
|
20
|
+
/** Unsaved Studio item settings to pass to the registered component loader. */
|
|
21
|
+
draftItem: WeaverseNextComponentData;
|
|
22
|
+
/** Public route identity used to reconstruct the loader request context. */
|
|
23
|
+
routeContext?: WeaverseNextRevalidateRouteContext;
|
|
24
|
+
}
|
|
25
|
+
/** App Router handler returned for Studio item revalidation requests. */
|
|
26
|
+
export interface WeaverseNextRevalidateHandler {
|
|
27
|
+
/** Handle a Studio request to rerun one registered component loader. */
|
|
28
|
+
POST: (request: Request) => Promise<Response>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Create the Studio per-item revalidation route handler.
|
|
32
|
+
*
|
|
33
|
+
* Studio design-mode edits to loader-backed inputs (e.g. resource pickers) need
|
|
34
|
+
* fresh server loader data for a single item. Re-running it through
|
|
35
|
+
* `router.refresh()` re-applies the whole RSC tree — and the draft-item query
|
|
36
|
+
* rewrite changes the App Router page segment key, remounting the page and
|
|
37
|
+
* resetting scroll. This handler runs just the edited component's `loader`
|
|
38
|
+
* with the unsaved draft settings and returns the payload for an in-place
|
|
39
|
+
* client update (see the `2026-07-02--next-item-revalidation` spec).
|
|
40
|
+
*
|
|
41
|
+
* Security: only registered component types are executable, the handler never
|
|
42
|
+
* persists anything, and responses are `no-store`. Exposure is equivalent to
|
|
43
|
+
* the existing `weaverseDraftItem` URL param, which already lets any visitor
|
|
44
|
+
* run design-mode loaders with arbitrary draft settings.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* // app/api/weaverse/revalidate/route.ts
|
|
49
|
+
* export const { POST } = createWeaverseNextRevalidateHandler({
|
|
50
|
+
* getClient: () => getWeaverseServerClient(Promise.resolve({})),
|
|
51
|
+
* })
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function createWeaverseNextRevalidateHandler(config: WeaverseNextRevalidateHandlerConfig): WeaverseNextRevalidateHandler;
|
|
55
|
+
//# sourceMappingURL=revalidate-handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"revalidate-handler.d.ts","sourceRoot":"","sources":["../../../src/server/revalidate-handler.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,kCAAkC,EACxC,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EACV,yBAAyB,EAEzB,0BAA0B,EAC1B,wBAAwB,EACzB,MAAM,UAAU,CAAA;AAsBjB,kEAAkE;AAClE,MAAM,WAAW,mCAAmC;IAClD;;;;;;;;;;OAUG;IACH,SAAS,EAAE,CACT,OAAO,EAAE,OAAO,EAChB,cAAc,CAAC,EAAE,0BAA0B,KACxC,OAAO,CAAC,wBAAwB,CAAC,GAAG,wBAAwB,CAAA;CAClE;AAED,kDAAkD;AAClD,MAAM,WAAW,iCAAiC;IAChD,+EAA+E;IAC/E,SAAS,EAAE,yBAAyB,CAAA;IACpC,4EAA4E;IAC5E,YAAY,CAAC,EAAE,kCAAkC,CAAA;CAClD;AAoMD,yEAAyE;AACzE,MAAM,WAAW,6BAA6B;IAC5C,wEAAwE;IACxE,IAAI,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CAC9C;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,mCAAmC,CACjD,MAAM,EAAE,mCAAmC,GAC1C,6BAA6B,CAqE/B"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { WeaverseNextServerClient, WeaverseNextServerClientConfig } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Create a server-side {@link WeaverseNextServerClient} for Next.js App Router
|
|
4
|
+
* routes / server components.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* let weaverse = createWeaverseNextServerClient({
|
|
9
|
+
* projectId: process.env.WEAVERSE_PROJECT_ID,
|
|
10
|
+
* components,
|
|
11
|
+
* commerce: { storefront },
|
|
12
|
+
* requestContext: { url, headers, searchParams, i18n },
|
|
13
|
+
* cache: { revalidate: 60, tags: ['weaverse'] },
|
|
14
|
+
* })
|
|
15
|
+
* let data = await weaverse.loadPage({ type: 'INDEX' })
|
|
16
|
+
* let theme = await weaverse.loadThemeSettings()
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare function createWeaverseNextServerClient(config: WeaverseNextServerClientConfig): WeaverseNextServerClient;
|
|
20
|
+
export { getContextSearchParams } from './configs';
|
|
21
|
+
//# sourceMappingURL=server-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-client.d.ts","sourceRoot":"","sources":["../../../src/server/server-client.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAgBV,wBAAwB,EACxB,8BAA8B,EAM/B,MAAM,UAAU,CAAA;AAsqBjB;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,8BAA8B,GACrC,wBAAwB,CAE1B;AAED,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-only Weaverse APIs for Next.js App Router server components and route
|
|
3
|
+
* handlers.
|
|
4
|
+
*
|
|
5
|
+
* When migrating from Hydrogen's `context.weaverse`, create a request-scoped
|
|
6
|
+
* client with {@link createWeaverseNextServerClient}, then call `loadPage()` or
|
|
7
|
+
* `loadThemeSettings()`. Keep rendering providers and components imported from
|
|
8
|
+
* the root `@weaverse/next` entrypoint.
|
|
9
|
+
*
|
|
10
|
+
* @packageDocumentation
|
|
11
|
+
*/
|
|
12
|
+
export type { WeaverseNextRevalidateRouteContext } from './revalidate-item';
|
|
13
|
+
export { formatWeaverseNextSeoMetadata, getWeaverseNextSeoMetadata, type NextOpenGraph, type NextTwitter, type WeaverseNextSeoInput, type WeaverseNextSeoMetadata, type WeaverseNextSeoPageContainer, } from './seo';
|
|
14
|
+
export { getWeaverseNextConfigs, type ResolveConfigsOptions, } from './server/configs';
|
|
15
|
+
export { normalizeNextPageUrl, resolveRequestUrl, } from './server/normalize-page-url';
|
|
16
|
+
export { createWeaverseNextRevalidateHandler, type WeaverseNextRevalidateHandler, type WeaverseNextRevalidateHandlerConfig, type WeaverseNextRevalidateRequestBody, } from './server/revalidate-handler';
|
|
17
|
+
export { createWeaverseNextServerClient } from './server/server-client';
|
|
18
|
+
export type { WeaverseNextBaseConfigs, WeaverseNextCacheConfig, WeaverseNextClient, WeaverseNextCommerceContext, WeaverseNextComponent, WeaverseNextComponentData, WeaverseNextComponentLoaderArgs, WeaverseNextComponentProps, WeaverseNextConfigs, WeaverseNextCustomPageEntry, WeaverseNextFetchCustomPagesOptions, WeaverseNextFetchOptions, WeaverseNextI18n, WeaverseNextLoaderData, WeaverseNextLoadPageInput, WeaverseNextPageAssignment, WeaverseNextPageData, WeaverseNextProjectId, WeaverseNextRequestContext, WeaverseNextServerClient, WeaverseNextServerClientConfig, WeaverseNextServerLoadPageInput, WeaverseNextStorefront, WeaverseNextThemeSchema, WeaverseNextThemeSchemaGroup, WeaverseNextThemeSchemaInput, WeaverseNextThemeSettingsOptions, WeaverseNextThemeSettingsResponse, } from './types';
|
|
19
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,YAAY,EAAE,kCAAkC,EAAE,MAAM,mBAAmB,CAAA;AAC3E,OAAO,EACL,6BAA6B,EAC7B,0BAA0B,EAC1B,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,4BAA4B,GAClC,MAAM,OAAO,CAAA;AACd,OAAO,EACL,sBAAsB,EACtB,KAAK,qBAAqB,GAC3B,MAAM,kBAAkB,CAAA;AACzB,OAAO,EACL,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,6BAA6B,CAAA;AACpC,OAAO,EACL,mCAAmC,EACnC,KAAK,6BAA6B,EAClC,KAAK,mCAAmC,EACxC,KAAK,iCAAiC,GACvC,MAAM,6BAA6B,CAAA;AACpC,OAAO,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAA;AACvE,YAAY,EACV,uBAAuB,EACvB,uBAAuB,EACvB,kBAAkB,EAClB,2BAA2B,EAC3B,qBAAqB,EACrB,yBAAyB,EACzB,+BAA+B,EAC/B,0BAA0B,EAC1B,mBAAmB,EACnB,2BAA2B,EAC3B,mCAAmC,EACnC,wBAAwB,EACxB,gBAAgB,EAChB,sBAAsB,EACtB,yBAAyB,EACzB,0BAA0B,EAC1B,oBAAoB,EACpB,qBAAqB,EACrB,0BAA0B,EAC1B,wBAAwB,EACxB,8BAA8B,EAC9B,+BAA+B,EAC/B,sBAAsB,EACtB,uBAAuB,EACvB,4BAA4B,EAC5B,4BAA4B,EAC5B,gCAAgC,EAChC,iCAAiC,GAClC,MAAM,SAAS,CAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type WeaverseNextRuntime } from './runtime';
|
|
2
|
+
import type { WeaverseNextRuntimeInternal } from './types';
|
|
3
|
+
/** Runtime and host callbacks attached to the Builder Studio bridge. */
|
|
4
|
+
export interface WeaverseNextStudioBridgeProps {
|
|
5
|
+
/** Preview navigation callback. */
|
|
6
|
+
navigate?: WeaverseNextRuntimeInternal['navigate'];
|
|
7
|
+
/** Whole-route refresh callback used as a legacy fallback. */
|
|
8
|
+
revalidate?: WeaverseNextRuntimeInternal['revalidate'];
|
|
9
|
+
/** Preferred per-item loader revalidation callback. */
|
|
10
|
+
revalidateItem?: WeaverseNextRuntimeInternal['revalidateItem'];
|
|
11
|
+
/** Browser runtime to initialize or refresh in Studio. */
|
|
12
|
+
runtime: WeaverseNextRuntime;
|
|
13
|
+
}
|
|
14
|
+
/** Page-level Studio runtime binder. */
|
|
15
|
+
export declare function WeaverseNextStudioBridge(props: WeaverseNextStudioBridgeProps): null;
|
|
16
|
+
//# sourceMappingURL=studio-bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"studio-bridge.d.ts","sourceRoot":"","sources":["../../src/studio-bridge.tsx"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,WAAW,CAAA;AAClB,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAA;AAK1D,wEAAwE;AACxE,MAAM,WAAW,6BAA6B;IAC5C,mCAAmC;IACnC,QAAQ,CAAC,EAAE,2BAA2B,CAAC,UAAU,CAAC,CAAA;IAClD,8DAA8D;IAC9D,UAAU,CAAC,EAAE,2BAA2B,CAAC,YAAY,CAAC,CAAA;IACtD,uDAAuD;IACvD,cAAc,CAAC,EAAE,2BAA2B,CAAC,gBAAgB,CAAC,CAAA;IAC9D,0DAA0D;IAC1D,OAAO,EAAE,mBAAmB,CAAA;CAC7B;AAED,wCAAwC;AACxC,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,6BAA6B,QAwD5E"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { WeaverseNextRequestContext } from './types';
|
|
2
|
+
/** Trust context used while loading the Studio bridge script. */
|
|
3
|
+
export interface LoadWeaverseNextStudioScriptOptions {
|
|
4
|
+
/** Storefront hostname; required to permit loopback Studio origins. */
|
|
5
|
+
storefrontHostname?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Resolve and append the Next Studio bridge script for the given request
|
|
9
|
+
* context, deduping by src. SSR-safe (no-op without `document`) so it can run
|
|
10
|
+
* unconditionally from a root layout/error boundary before any page tree or
|
|
11
|
+
* runtime exists — e.g. App Router `not-found.tsx` / `error.tsx` routes.
|
|
12
|
+
*/
|
|
13
|
+
export declare function loadWeaverseNextStudioScript(context?: WeaverseNextRequestContext, options?: LoadWeaverseNextStudioScriptOptions): void;
|
|
14
|
+
/** Props for the root-level Studio script connector. */
|
|
15
|
+
export interface WeaverseNextStudioConnectProps {
|
|
16
|
+
/** Explicit request context used to resolve Studio mode and host. */
|
|
17
|
+
context?: WeaverseNextRequestContext;
|
|
18
|
+
/** Storefront hostname; required to permit loopback Studio origins. */
|
|
19
|
+
storefrontHostname?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Root-level Studio script connector for Next client boundaries. Mount once
|
|
23
|
+
* near the app root (e.g. root layout) so it also covers routes that never
|
|
24
|
+
* render `WeaverseNextRenderer`, such as `not-found.tsx` / `error.tsx`.
|
|
25
|
+
*/
|
|
26
|
+
export declare function WeaverseNextStudioConnect(props: WeaverseNextStudioConnectProps): null;
|
|
27
|
+
//# sourceMappingURL=studio-connect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"studio-connect.d.ts","sourceRoot":"","sources":["../../src/studio-connect.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;AA0BzD,iEAAiE;AACjE,MAAM,WAAW,mCAAmC;IAClD,uEAAuE;IACvE,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC5B;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,CAAC,EAAE,0BAA0B,EACpC,OAAO,GAAE,mCAAwC,QAkBlD;AAED,wDAAwD;AACxD,MAAM,WAAW,8BAA8B;IAC7C,qEAAqE;IACrE,OAAO,CAAC,EAAE,0BAA0B,CAAA;IACpC,uEAAuE;IACvE,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC5B;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,8BAA8B,QAStC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { WeaverseNextRuntimeInternal } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Minimal structural shape of the Next App Router returned by `useRouter()`
|
|
4
|
+
* (`next/navigation`) that the Studio bridge needs. Declared locally — rather
|
|
5
|
+
* than importing `AppRouterInstance` from `next` — so the adapter stays a pure
|
|
6
|
+
* function that unit tests can drive with a plain mock and never pulls
|
|
7
|
+
* `next/navigation` into the test graph.
|
|
8
|
+
*/
|
|
9
|
+
export interface WeaverseNextRouterLike {
|
|
10
|
+
/** Add a route to browser history. */
|
|
11
|
+
push: (href: string, options?: {
|
|
12
|
+
/** Whether to scroll to the top after navigation. */
|
|
13
|
+
scroll?: boolean;
|
|
14
|
+
}) => void;
|
|
15
|
+
/** Refresh the current App Router route and server data. */
|
|
16
|
+
refresh: () => void;
|
|
17
|
+
/** Replace the current browser-history entry. */
|
|
18
|
+
replace: (href: string, options?: {
|
|
19
|
+
/** Whether to scroll to the top after navigation. */
|
|
20
|
+
scroll?: boolean;
|
|
21
|
+
}) => void;
|
|
22
|
+
}
|
|
23
|
+
/** Resolved Studio navigation/revalidation callbacks for a Next runtime. */
|
|
24
|
+
export interface WeaverseNextStudioInternals {
|
|
25
|
+
/** Navigate Studio's preview with React Router-compatible options. */
|
|
26
|
+
navigate: NonNullable<WeaverseNextRuntimeInternal['navigate']>;
|
|
27
|
+
/** Refresh the current App Router route. */
|
|
28
|
+
revalidate: NonNullable<WeaverseNextRuntimeInternal['revalidate']>;
|
|
29
|
+
}
|
|
30
|
+
/** Controls how Studio navigation maps to the Next App Router. */
|
|
31
|
+
export interface CreateWeaverseNextStudioInternalsOptions {
|
|
32
|
+
/** Use `router.replace` instead of `router.push` for navigation. */
|
|
33
|
+
replace?: boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Build Studio `navigate` / `revalidate` callbacks from a Next App Router.
|
|
37
|
+
*
|
|
38
|
+
* Maps Hydrogen's React Router semantics onto Next App Router:
|
|
39
|
+
* - `navigate(to, { preventScrollReset })` → `router.push(to, { scroll })`,
|
|
40
|
+
* where `scroll` is the inverse of `preventScrollReset`. Studio passes
|
|
41
|
+
* `preventScrollReset` for in-place edits so the preview viewport is kept,
|
|
42
|
+
* matching React Router's `navigate({ preventScrollReset })`.
|
|
43
|
+
* - `revalidate()` → `router.refresh()`, the App Router's loader-backed refresh
|
|
44
|
+
* and the closest equivalent to React Router's `useRevalidator`.
|
|
45
|
+
*
|
|
46
|
+
* Pure (no React, no `next/navigation`) so it is unit-testable with a mock
|
|
47
|
+
* router; the {@link WeaverseNextRouterLike} contract is the only coupling.
|
|
48
|
+
*/
|
|
49
|
+
export declare function createWeaverseNextStudioInternals(router: WeaverseNextRouterLike, options?: CreateWeaverseNextStudioInternalsOptions): WeaverseNextStudioInternals;
|
|
50
|
+
//# sourceMappingURL=studio-router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"studio-router.d.ts","sourceRoot":"","sources":["../../src/studio-router.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAA;AAE1D;;;;;;GAMG;AACH,MAAM,WAAW,sBAAsB;IACrC,sCAAsC;IACtC,IAAI,EAAE,CACJ,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;QACR,qDAAqD;QACrD,MAAM,CAAC,EAAE,OAAO,CAAA;KACjB,KACE,IAAI,CAAA;IACT,4DAA4D;IAC5D,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,iDAAiD;IACjD,OAAO,EAAE,CACP,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;QACR,qDAAqD;QACrD,MAAM,CAAC,EAAE,OAAO,CAAA;KACjB,KACE,IAAI,CAAA;CACV;AAED,4EAA4E;AAC5E,MAAM,WAAW,2BAA2B;IAC1C,sEAAsE;IACtE,QAAQ,EAAE,WAAW,CAAC,2BAA2B,CAAC,UAAU,CAAC,CAAC,CAAA;IAC9D,4CAA4C;IAC5C,UAAU,EAAE,WAAW,CAAC,2BAA2B,CAAC,YAAY,CAAC,CAAC,CAAA;CACnE;AAED,kEAAkE;AAClE,MAAM,WAAW,wCAAwC;IACvD,oEAAoE;IACpE,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAWD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iCAAiC,CAC/C,MAAM,EAAE,sBAAsB,EAC9B,OAAO,GAAE,wCAA6C,GACrD,2BAA2B,CAc7B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { WeaverseNextRequestContext } from './types';
|
|
2
|
+
/** Trust context used when resolving a Studio bridge script URL. */
|
|
3
|
+
export interface ResolveWeaverseNextStudioScriptSrcOptions {
|
|
4
|
+
/** Storefront hostname; required to permit loopback Studio origins. */
|
|
5
|
+
storefrontHostname?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Resolve the Studio script URL from request/search context. `@weaverse/next`
|
|
9
|
+
* uses the dedicated Next bridge path served by Builder.
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveWeaverseNextStudioScriptSrc(context?: WeaverseNextRequestContext, options?: ResolveWeaverseNextStudioScriptSrcOptions): string | null;
|
|
12
|
+
//# sourceMappingURL=studio-script-src.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"studio-script-src.d.ts","sourceRoot":"","sources":["../../src/studio-script-src.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;AAmFzD,oEAAoE;AACpE,MAAM,WAAW,yCAAyC;IACxD,uEAAuE;IACvE,kBAAkB,CAAC,EAAE,MAAM,CAAA;CAC5B;AAED;;;GAGG;AACH,wBAAgB,kCAAkC,CAChD,OAAO,CAAC,EAAE,0BAA0B,EACpC,OAAO,GAAE,yCAA8C,GACtD,MAAM,GAAG,IAAI,CA+Bf"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { SchemaType } from '@weaverse/schema';
|
|
2
|
+
import type { WeaverseNextThemeSchema, WeaverseNextThemeSettingsStore } from './types';
|
|
3
|
+
/** Initial values for a root-scoped theme-settings store. */
|
|
4
|
+
export interface CreateWeaverseNextThemeSettingsStoreOptions {
|
|
5
|
+
/** Public environment values exposed alongside the store. */
|
|
6
|
+
publicEnv?: Record<string, string | undefined>;
|
|
7
|
+
/** Theme schema associated with the settings. */
|
|
8
|
+
schema?: SchemaType | WeaverseNextThemeSchema;
|
|
9
|
+
/** Initial setting values. */
|
|
10
|
+
settings?: Record<string, unknown>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Small external store shape compatible with the Studio bridge and React's
|
|
14
|
+
* `useSyncExternalStore` contract. The bridge calls `updateThemeSettings` during
|
|
15
|
+
* live theme edits, so keep that method name stable.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createWeaverseNextThemeSettingsStore(options?: CreateWeaverseNextThemeSettingsStoreOptions): WeaverseNextThemeSettingsStore;
|
|
18
|
+
//# sourceMappingURL=theme-settings-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme-settings-store.d.ts","sourceRoot":"","sources":["../../src/theme-settings-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,KAAK,EACV,uBAAuB,EACvB,8BAA8B,EAC/B,MAAM,SAAS,CAAA;AAEhB,6DAA6D;AAC7D,MAAM,WAAW,2CAA2C;IAC1D,6DAA6D;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;IAC9C,iDAAiD;IACjD,MAAM,CAAC,EAAE,UAAU,GAAG,uBAAuB,CAAA;IAC7C,8BAA8B;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACnC;AAED;;;;GAIG;AACH,wBAAgB,oCAAoC,CAClD,OAAO,GAAE,2CAAgD,GACxD,8BAA8B,CAuBhC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure translation helpers, free of React so server code can call them.
|
|
3
|
+
*
|
|
4
|
+
* `translation-context.tsx` builds the client provider and hook on top of
|
|
5
|
+
* these; keeping them apart lets the root entry export them as real functions
|
|
6
|
+
* outside the `'use client'` boundary.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Traverse a nested object by dot-path.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* getNestedKey({ cart: { title: 'Cart' } }, 'cart.title') // => 'Cart'
|
|
13
|
+
* getNestedKey({}, 'cart.title', 'fallback') // => 'fallback'
|
|
14
|
+
*/
|
|
15
|
+
export declare function getNestedKey(obj: Record<string, unknown>, path: string, fallback?: string): string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Replace `{{variable}}` patterns in a string with provided values.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* interpolate('Hello {{name}}!', { name: 'World' }) // => 'Hello World!'
|
|
21
|
+
* interpolate('-{{percentage}}% Off', { percentage: 15 }) // => '-15% Off'
|
|
22
|
+
*/
|
|
23
|
+
export declare function interpolate(template: string, variables?: Record<string, string | number>): string;
|
|
24
|
+
/**
|
|
25
|
+
* Signature for a translation function.
|
|
26
|
+
*/
|
|
27
|
+
export type TranslateFunction = (key: string, variables?: Record<string, string | number>) => string;
|
|
28
|
+
/** Translation sources accepted by {@link createTranslate}. */
|
|
29
|
+
export interface CreateTranslateSources {
|
|
30
|
+
/** Unsaved live overrides received from Builder design mode. */
|
|
31
|
+
designOverrides?: Record<string, string>;
|
|
32
|
+
/** Host application's highest-priority translation function. */
|
|
33
|
+
externalT?: TranslateFunction;
|
|
34
|
+
/** Active-locale static-text overrides loaded from Weaverse. */
|
|
35
|
+
merchantOverrides?: Record<string, unknown>;
|
|
36
|
+
/** Default-locale static content from the theme schema. */
|
|
37
|
+
staticContent: Record<string, unknown>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Build the `t()` translation function over a fixed set of sources.
|
|
41
|
+
*
|
|
42
|
+
* Resolution order, highest priority first:
|
|
43
|
+
* 1. `externalT` – host i18n (e.g. Shopify), unless it echoes the key
|
|
44
|
+
* 2. `designOverrides` – live design-mode edits, flat dot-path keys
|
|
45
|
+
* 3. `merchantOverrides` – locale overrides from the API, nested
|
|
46
|
+
* 4. `staticContent` – the theme's default locale JSON
|
|
47
|
+
* 5. the key itself
|
|
48
|
+
*
|
|
49
|
+
* Design overrides are looked up per-key (own properties only) rather than
|
|
50
|
+
* merged into `merchantOverrides`: a flat key like `cart.title` must override
|
|
51
|
+
* exactly that leaf without wiping sibling keys (`cart.subtitle`), and a
|
|
52
|
+
* per-key own-property lookup never builds nested objects from
|
|
53
|
+
* merchant-controlled keys, so it cannot pollute `Object.prototype`.
|
|
54
|
+
*/
|
|
55
|
+
export declare function createTranslate(sources: CreateTranslateSources): TranslateFunction;
|
|
56
|
+
//# sourceMappingURL=translate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translate.d.ts","sourceRoot":"","sources":["../../src/translate.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,IAAI,EAAE,MAAM,EACZ,QAAQ,CAAC,EAAE,MAAM,GAChB,MAAM,GAAG,SAAS,CAgBpB;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,QAAQ,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,GAC1C,MAAM,CASR;AAED;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAC9B,GAAG,EAAE,MAAM,EACX,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,KACxC,MAAM,CAAA;AAEX,+DAA+D;AAC/D,MAAM,WAAW,sBAAsB;IACrC,gEAAgE;IAChE,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACxC,gEAAgE;IAChE,SAAS,CAAC,EAAE,iBAAiB,CAAA;IAC7B,gEAAgE;IAChE,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC3C,2DAA2D;IAC3D,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACvC;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,sBAAsB,GAC9B,iBAAiB,CA4BnB"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import { type TranslateFunction } from './translate';
|
|
3
|
+
import type { TranslationStore } from './translation-store';
|
|
4
|
+
/** Translation function and live override stores exposed by `useTranslation`. */
|
|
5
|
+
export interface TranslationValue {
|
|
6
|
+
/** Active-locale translated keys loaded from the storefront API. */
|
|
7
|
+
merchantOverrides: Record<string, unknown> | null;
|
|
8
|
+
/**
|
|
9
|
+
* Translate a key with optional variable interpolation.
|
|
10
|
+
*
|
|
11
|
+
* Priority chain (highest wins):
|
|
12
|
+
* 1. External `t` (passed into `WeaverseNextRootProvider` / `TranslationProvider`)
|
|
13
|
+
* 2. Design overrides (live Builder edits from `TranslationStore`)
|
|
14
|
+
* 3. `merchantOverrides` (DB/API overrides for the current locale)
|
|
15
|
+
* 4. `staticContent` (theme default JSON)
|
|
16
|
+
* 5. The key itself (fallback)
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* t('cart.title') // => "Cart"
|
|
20
|
+
* t('badge.sale', { percentage: 15 }) // => "-15% Off"
|
|
21
|
+
*/
|
|
22
|
+
t: TranslateFunction;
|
|
23
|
+
/**
|
|
24
|
+
* Legacy name for the live design-mode translation store.
|
|
25
|
+
*
|
|
26
|
+
* @deprecated Migrate to {@link TranslationValue.translationStore}. This
|
|
27
|
+
* alias points at the same store instance.
|
|
28
|
+
*/
|
|
29
|
+
themeTextStore: TranslationStore | null;
|
|
30
|
+
/** Exposed so the runtime/Studio bridge can attach it to `internal`. */
|
|
31
|
+
translationStore: TranslationStore | null;
|
|
32
|
+
}
|
|
33
|
+
/** Sources and content rendered by {@link TranslationProvider}. */
|
|
34
|
+
export interface TranslationProviderProps {
|
|
35
|
+
/** React subtree that can call `useTranslation`. */
|
|
36
|
+
children: ReactNode;
|
|
37
|
+
/** Active-locale static-text overrides loaded from Weaverse. */
|
|
38
|
+
merchantOverrides?: Record<string, unknown>;
|
|
39
|
+
/** Default-locale static content from the theme schema. */
|
|
40
|
+
staticContent: Record<string, unknown>;
|
|
41
|
+
/**
|
|
42
|
+
* Optional external translation function.
|
|
43
|
+
* When provided it becomes the **highest-priority** source:
|
|
44
|
+
* if it returns a non-empty string that differs from the raw key,
|
|
45
|
+
* that value is used; otherwise the internal resolution chain continues.
|
|
46
|
+
*/
|
|
47
|
+
t?: TranslateFunction;
|
|
48
|
+
/**
|
|
49
|
+
* Legacy prop name for the live translation store.
|
|
50
|
+
*
|
|
51
|
+
* @deprecated Migrate to {@link TranslationProviderProps.translationStore}.
|
|
52
|
+
* Still accepted for backward compatibility; ignored when `translationStore`
|
|
53
|
+
* is also provided.
|
|
54
|
+
*/
|
|
55
|
+
themeTextStore?: TranslationStore | null;
|
|
56
|
+
/** Optional store for live design-mode text overrides from the builder. */
|
|
57
|
+
translationStore?: TranslationStore | null;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Provider that wraps the app to expose the `t()` function.
|
|
61
|
+
*
|
|
62
|
+
* - `staticContent` – the theme's default locale JSON (from themeSchema.i18n)
|
|
63
|
+
* - `merchantOverrides` – locale-specific overrides fetched from the API
|
|
64
|
+
* - `translationStore` – optional store for live design-mode text overrides
|
|
65
|
+
* (the deprecated `themeTextStore` prop is accepted as a fallback)
|
|
66
|
+
*/
|
|
67
|
+
export declare function TranslationProvider({ staticContent, merchantOverrides, t: externalT, translationStore, themeTextStore, children, }: TranslationProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
68
|
+
/**
|
|
69
|
+
* Hook to access the translation `t()` function.
|
|
70
|
+
*
|
|
71
|
+
* Must be used inside a component wrapped by `WeaverseNextRootProvider` or
|
|
72
|
+
* `TranslationProvider`.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```tsx
|
|
76
|
+
* function CartTitle() {
|
|
77
|
+
* let { t } = useTranslation()
|
|
78
|
+
* return <h2>{t('cart.title')}</h2>
|
|
79
|
+
* }
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare function useTranslation(): TranslationValue;
|
|
83
|
+
/**
|
|
84
|
+
* Legacy name for {@link TranslationProvider}.
|
|
85
|
+
*
|
|
86
|
+
* @deprecated Replace `ThemeTextProvider` with {@link TranslationProvider};
|
|
87
|
+
* the props and runtime behavior are unchanged.
|
|
88
|
+
*/
|
|
89
|
+
export declare const ThemeTextProvider: typeof TranslationProvider;
|
|
90
|
+
/**
|
|
91
|
+
* Legacy name for {@link useTranslation}.
|
|
92
|
+
*
|
|
93
|
+
* @deprecated Replace `useThemeText` with {@link useTranslation}; the return
|
|
94
|
+
* value is unchanged.
|
|
95
|
+
*/
|
|
96
|
+
export declare const useThemeText: typeof useTranslation;
|
|
97
|
+
/**
|
|
98
|
+
* Legacy name for {@link TranslationValue}.
|
|
99
|
+
*
|
|
100
|
+
* @deprecated Import {@link TranslationValue} instead.
|
|
101
|
+
*/
|
|
102
|
+
export type ThemeTextValue = TranslationValue;
|
|
103
|
+
/**
|
|
104
|
+
* Legacy name for {@link TranslationProviderProps}.
|
|
105
|
+
*
|
|
106
|
+
* @deprecated Import {@link TranslationProviderProps} instead.
|
|
107
|
+
*/
|
|
108
|
+
export type ThemeTextProviderProps = TranslationProviderProps;
|
|
109
|
+
//# sourceMappingURL=translation-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translation-context.d.ts","sourceRoot":"","sources":["../../src/translation-context.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAiB,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAA;AAC1E,OAAO,EAAmB,KAAK,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACrE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAM3D,iFAAiF;AACjF,MAAM,WAAW,gBAAgB;IAC/B,oEAAoE;IACpE,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAA;IACjD;;;;;;;;;;;;;OAaG;IACH,CAAC,EAAE,iBAAiB,CAAA;IACpB;;;;;OAKG;IACH,cAAc,EAAE,gBAAgB,GAAG,IAAI,CAAA;IACvC,wEAAwE;IACxE,gBAAgB,EAAE,gBAAgB,GAAG,IAAI,CAAA;CAC1C;AAKD,mEAAmE;AACnE,MAAM,WAAW,wBAAwB;IACvC,oDAAoD;IACpD,QAAQ,EAAE,SAAS,CAAA;IACnB,gEAAgE;IAChE,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC3C,2DAA2D;IAC3D,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACtC;;;;;OAKG;IACH,CAAC,CAAC,EAAE,iBAAiB,CAAA;IACrB;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAAA;IACxC,2EAA2E;IAC3E,gBAAgB,CAAC,EAAE,gBAAgB,GAAG,IAAI,CAAA;CAC3C;AAUD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,aAAa,EACb,iBAAiB,EACjB,CAAC,EAAE,SAAS,EACZ,gBAAgB,EAChB,cAAc,EACd,QAAQ,GACT,EAAE,wBAAwB,2CAgC1B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,IAAI,gBAAgB,CAQjD;AAMD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,4BAAsB,CAAA;AACpD;;;;;GAKG;AACH,eAAO,MAAM,YAAY,uBAAiB,CAAA;AAC1C;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,gBAAgB,CAAA;AAC7C;;;;GAIG;AACH,MAAM,MAAM,sBAAsB,GAAG,wBAAwB,CAAA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal mutable store for design-mode static text overrides.
|
|
3
|
+
*
|
|
4
|
+
* `useSyncExternalStore`-compatible. Passed into {@link TranslationProvider}
|
|
5
|
+
* (from `./translation-context`) which subscribes internally and layers
|
|
6
|
+
* overrides on top of `merchantOverrides`/`staticContent`. The Studio bridge
|
|
7
|
+
* calls `updateOverrides()` via `runtime.internal.translationStore` (also
|
|
8
|
+
* exposed as the deprecated `runtime.internal.themeTextStore` alias) so live
|
|
9
|
+
* static-text edits reach the runtime — identical surface to Hydrogen's store,
|
|
10
|
+
* so Builder's existing static-text RPC works with `@weaverse/next` unchanged.
|
|
11
|
+
*
|
|
12
|
+
* Shape: flat `Record<string, string>` — dot-notation keys map to values
|
|
13
|
+
* (e.g. "cart.title" → "Shopping Cart").
|
|
14
|
+
*/
|
|
15
|
+
export declare class TranslationStore {
|
|
16
|
+
/** Current flat translation overrides keyed by dot path. */
|
|
17
|
+
overrides: Record<string, string>;
|
|
18
|
+
private readonly listeners;
|
|
19
|
+
/** Replace every override and notify subscribers. */
|
|
20
|
+
setOverrides: (overrides: Record<string, string>) => void;
|
|
21
|
+
/** Merge changed overrides into the current values and notify subscribers. */
|
|
22
|
+
updateOverrides: (newOverrides: Record<string, string>) => void;
|
|
23
|
+
/** Return the current client-side override snapshot. */
|
|
24
|
+
getSnapshot: () => Record<string, string>;
|
|
25
|
+
/** Return the override snapshot used during server rendering. */
|
|
26
|
+
getServerSnapshot: () => Record<string, string>;
|
|
27
|
+
/** Subscribe to override changes and return an unsubscribe function. */
|
|
28
|
+
subscribe: (callback: () => void) => () => void;
|
|
29
|
+
private readonly emit;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Legacy constructor name for {@link TranslationStore}.
|
|
33
|
+
*
|
|
34
|
+
* @deprecated Replace `ThemeTextStore` with {@link TranslationStore}; the
|
|
35
|
+
* store contract and runtime behavior are unchanged.
|
|
36
|
+
*/
|
|
37
|
+
export declare const ThemeTextStore: typeof TranslationStore;
|
|
38
|
+
/**
|
|
39
|
+
* Legacy type name for {@link TranslationStore}.
|
|
40
|
+
*
|
|
41
|
+
* @deprecated Import {@link TranslationStore} instead.
|
|
42
|
+
*/
|
|
43
|
+
export type ThemeTextStore = TranslationStore;
|
|
44
|
+
//# sourceMappingURL=translation-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translation-store.d.ts","sourceRoot":"","sources":["../../src/translation-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,qBAAa,gBAAgB;IAC3B,4DAA4D;IAC5D,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAK;IACtC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA6B;IAEvD,qDAAqD;IACrD,YAAY,GAAI,WAAW,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,UAGhD;IAED,8EAA8E;IAC9E,eAAe,GAAI,cAAc,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,UAGtD;IAED,wDAAwD;IACxD,WAAW,+BAAuB;IAElC,iEAAiE;IACjE,iBAAiB,+BAAuB;IAExC,wEAAwE;IACxE,SAAS,GAAI,UAAU,MAAM,IAAI,gBAKhC;IAED,OAAO,CAAC,QAAQ,CAAC,IAAI,CAQpB;CACF;AAED;;;;;GAKG;AACH,eAAO,MAAM,cAAc,yBAAmB,CAAA;AAC9C;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG,gBAAgB,CAAA"}
|