@usethrottle/builder-react 0.2.0 → 0.2.2
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/CLAUDE.md +6 -0
- package/dist/index.cjs +10 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +12 -3
- package/dist/server.cjs +4 -0
- package/dist/server.d.cts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +4 -0
- package/package.json +2 -2
package/CLAUDE.md
CHANGED
|
@@ -42,6 +42,12 @@ export { generateMetadata };
|
|
|
42
42
|
which a server component cannot pass down, so the store creates its packs in a
|
|
43
43
|
client module. `site` is plain data (what `loadSite` returned).
|
|
44
44
|
|
|
45
|
+
**Nesting.** `BuilderProvider` lays the site theme over an enclosing `@usethrottle/ui` appearance (it merges
|
|
46
|
+
`variables`, `darkVariables`, `elements`, `parts`, `components`; the Builder's values win except `fontFamily`,
|
|
47
|
+
which stays the host's when it set one), so it can sit inside a store's ui provider without dropping its part
|
|
48
|
+
classes. Put it OUTSIDE `StorefrontNextProvider` anyway: that provider reads the site design, which only exists
|
|
49
|
+
below `BuilderProvider`, and it builds its own appearance from that design.
|
|
50
|
+
|
|
45
51
|
## Rules (do not break)
|
|
46
52
|
|
|
47
53
|
- **No time-based revalidation, ever.** Every read goes through the
|
package/dist/index.cjs
CHANGED
|
@@ -2239,6 +2239,9 @@ function siteDesignOf(settings, resolve, pageOutlet, mediaOrigin) {
|
|
|
2239
2239
|
// src/provider.tsx
|
|
2240
2240
|
var import_jsx_runtime25 = require("react/jsx-runtime");
|
|
2241
2241
|
var EMPTY = {};
|
|
2242
|
+
function useParentFont() {
|
|
2243
|
+
return (0, import_react15.useContext)(import_ui6.AppearanceContext)?.variables?.fontFamily;
|
|
2244
|
+
}
|
|
2242
2245
|
function BuilderProvider({ builderKey, client, packs, site, children }) {
|
|
2243
2246
|
const packsKey = packs.map((pack) => `${pack.id}@${pack.version}`).join("|");
|
|
2244
2247
|
const registryRef = (0, import_react15.useRef)(null);
|
|
@@ -2288,7 +2291,13 @@ function BuilderProvider({ builderKey, client, packs, site, children }) {
|
|
|
2288
2291
|
() => site.status === "ok" ? siteDesignOf(site.settings, resolveLink, pageOutlet, mediaOrigin) : null,
|
|
2289
2292
|
[site, resolveLink, pageOutlet, mediaOrigin]
|
|
2290
2293
|
);
|
|
2291
|
-
const
|
|
2294
|
+
const own = (0, import_react15.useMemo)(() => site.status === "ok" ? appearanceOf(site.settings) : void 0, [site]);
|
|
2295
|
+
const merged = (0, import_ui6.useAppearanceProviderValue)(own);
|
|
2296
|
+
const parentFont = useParentFont();
|
|
2297
|
+
const appearance = (0, import_react15.useMemo)(() => {
|
|
2298
|
+
if (own === void 0) return void 0;
|
|
2299
|
+
return parentFont === void 0 ? merged : { ...merged, variables: { ...merged.variables, fontFamily: parentFont } };
|
|
2300
|
+
}, [own, merged, parentFont]);
|
|
2292
2301
|
return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(BuilderContext.Provider, { value, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_ui6.ThrottleUIProvider, { ...appearance === void 0 ? {} : { appearance }, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(import_ui6.SiteDesignProvider, { value: design, children: /* @__PURE__ */ (0, import_jsx_runtime25.jsxs)(import_ui6.SlotOutletProvider, { resolve: resolveSlot, children: [
|
|
2293
2302
|
site.status === "ok" ? /* @__PURE__ */ (0, import_jsx_runtime25.jsx)("style", { children: themeCss(site.settings) }) : null,
|
|
2294
2303
|
children
|
package/dist/index.d.cts
CHANGED
|
@@ -308,6 +308,10 @@ type BuilderProviderProps = {
|
|
|
308
308
|
* the theme and a renderer for a Builder page by slug) and `SlotOutletContext`
|
|
309
309
|
* from a loaded site, and gives the Builder components their registry.
|
|
310
310
|
*
|
|
311
|
+
* It lays the site theme over an enclosing `@usethrottle/ui` appearance (for example `StorefrontNextProvider`'s
|
|
312
|
+
* `parts`) instead of replacing it, so it can sit inside or outside that provider. Outside is better: a
|
|
313
|
+
* storefront provider reads the site design, which only exists below this one.
|
|
314
|
+
*
|
|
311
315
|
* Put it in a client module of the store, where the packs are created: a pack
|
|
312
316
|
* holds components and functions, which a server component cannot pass down.
|
|
313
317
|
* With a site the Builder could not answer (`status: 'unavailable'`) it fills
|
package/dist/index.d.ts
CHANGED
|
@@ -308,6 +308,10 @@ type BuilderProviderProps = {
|
|
|
308
308
|
* the theme and a renderer for a Builder page by slug) and `SlotOutletContext`
|
|
309
309
|
* from a loaded site, and gives the Builder components their registry.
|
|
310
310
|
*
|
|
311
|
+
* It lays the site theme over an enclosing `@usethrottle/ui` appearance (for example `StorefrontNextProvider`'s
|
|
312
|
+
* `parts`) instead of replacing it, so it can sit inside or outside that provider. Outside is better: a
|
|
313
|
+
* storefront provider reads the site design, which only exists below this one.
|
|
314
|
+
*
|
|
311
315
|
* Put it in a client module of the store, where the packs are created: a pack
|
|
312
316
|
* holds components and functions, which a server component cannot pass down.
|
|
313
317
|
* With a site the Builder could not answer (`status: 'unavailable'`) it fills
|
package/dist/index.js
CHANGED
|
@@ -616,9 +616,9 @@ function WidgetStyle({ css }) {
|
|
|
616
616
|
}
|
|
617
617
|
|
|
618
618
|
// src/provider.tsx
|
|
619
|
-
import { Suspense as Suspense4, useCallback, useMemo, useRef as useRef2 } from "react";
|
|
619
|
+
import { Suspense as Suspense4, useCallback, useContext as useContext2, useMemo, useRef as useRef2 } from "react";
|
|
620
620
|
import { createBuilderClient } from "@usethrottle/builder";
|
|
621
|
-
import { SiteDesignProvider, SlotOutletProvider, ThrottleUIProvider } from "@usethrottle/ui";
|
|
621
|
+
import { AppearanceContext, SiteDesignProvider, SlotOutletProvider, ThrottleUIProvider, useAppearanceProviderValue } from "@usethrottle/ui";
|
|
622
622
|
|
|
623
623
|
// src/context.ts
|
|
624
624
|
import { createContext, useContext } from "react";
|
|
@@ -2202,6 +2202,9 @@ function siteDesignOf(settings, resolve, pageOutlet, mediaOrigin) {
|
|
|
2202
2202
|
// src/provider.tsx
|
|
2203
2203
|
import { jsx as jsx25, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
2204
2204
|
var EMPTY = {};
|
|
2205
|
+
function useParentFont() {
|
|
2206
|
+
return useContext2(AppearanceContext)?.variables?.fontFamily;
|
|
2207
|
+
}
|
|
2205
2208
|
function BuilderProvider({ builderKey, client, packs, site, children }) {
|
|
2206
2209
|
const packsKey = packs.map((pack) => `${pack.id}@${pack.version}`).join("|");
|
|
2207
2210
|
const registryRef = useRef2(null);
|
|
@@ -2251,7 +2254,13 @@ function BuilderProvider({ builderKey, client, packs, site, children }) {
|
|
|
2251
2254
|
() => site.status === "ok" ? siteDesignOf(site.settings, resolveLink, pageOutlet, mediaOrigin) : null,
|
|
2252
2255
|
[site, resolveLink, pageOutlet, mediaOrigin]
|
|
2253
2256
|
);
|
|
2254
|
-
const
|
|
2257
|
+
const own = useMemo(() => site.status === "ok" ? appearanceOf(site.settings) : void 0, [site]);
|
|
2258
|
+
const merged = useAppearanceProviderValue(own);
|
|
2259
|
+
const parentFont = useParentFont();
|
|
2260
|
+
const appearance = useMemo(() => {
|
|
2261
|
+
if (own === void 0) return void 0;
|
|
2262
|
+
return parentFont === void 0 ? merged : { ...merged, variables: { ...merged.variables, fontFamily: parentFont } };
|
|
2263
|
+
}, [own, merged, parentFont]);
|
|
2255
2264
|
return /* @__PURE__ */ jsx25(BuilderContext.Provider, { value, children: /* @__PURE__ */ jsx25(ThrottleUIProvider, { ...appearance === void 0 ? {} : { appearance }, children: /* @__PURE__ */ jsx25(SiteDesignProvider, { value: design, children: /* @__PURE__ */ jsxs15(SlotOutletProvider, { resolve: resolveSlot, children: [
|
|
2256
2265
|
site.status === "ok" ? /* @__PURE__ */ jsx25("style", { children: themeCss(site.settings) }) : null,
|
|
2257
2266
|
children
|
package/dist/server.cjs
CHANGED
|
@@ -47,6 +47,10 @@ async function loadSite(options) {
|
|
|
47
47
|
// src/server/sitemap.ts
|
|
48
48
|
|
|
49
49
|
async function builderSitemap(options) {
|
|
50
|
+
if (options.client === void 0 && (options.builderKey === void 0 || options.builderKey === "")) {
|
|
51
|
+
_chunkS2XR224Acjs.warnOnce.call(void 0, "sitemap-no-key", "builderSitemap has no builderKey (is THROTTLE_BUILDER_KEY set?); the sitemap leaves out the Builder pages");
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
50
54
|
const client = _chunkS2XR224Acjs.clientOf.call(void 0, options);
|
|
51
55
|
const origin = _chunkS2XR224Acjs.originOf.call(void 0, options.storeUrl);
|
|
52
56
|
if (origin === void 0) {
|
package/dist/server.d.cts
CHANGED
|
@@ -60,7 +60,7 @@ type BuilderSitemapOptions = ClientOptions & {
|
|
|
60
60
|
/** Where your store serves a page, as for `createBuilderPage`. Pass the same function. */
|
|
61
61
|
pagePath?: PagePathResolver;
|
|
62
62
|
};
|
|
63
|
-
/** The published pages as sitemap entries. An unavailable Builder gives an empty list, never a failed sitemap (a build-mode client fails the build instead). */
|
|
63
|
+
/** The published pages as sitemap entries. An unavailable Builder, or no key at all, gives an empty list and a warning, never a failed sitemap (a build-mode client fails the build instead). */
|
|
64
64
|
declare function builderSitemap(options: BuilderSitemapOptions): Promise<{
|
|
65
65
|
url: string;
|
|
66
66
|
lastModified: Date;
|
package/dist/server.d.ts
CHANGED
|
@@ -60,7 +60,7 @@ type BuilderSitemapOptions = ClientOptions & {
|
|
|
60
60
|
/** Where your store serves a page, as for `createBuilderPage`. Pass the same function. */
|
|
61
61
|
pagePath?: PagePathResolver;
|
|
62
62
|
};
|
|
63
|
-
/** The published pages as sitemap entries. An unavailable Builder gives an empty list, never a failed sitemap (a build-mode client fails the build instead). */
|
|
63
|
+
/** The published pages as sitemap entries. An unavailable Builder, or no key at all, gives an empty list and a warning, never a failed sitemap (a build-mode client fails the build instead). */
|
|
64
64
|
declare function builderSitemap(options: BuilderSitemapOptions): Promise<{
|
|
65
65
|
url: string;
|
|
66
66
|
lastModified: Date;
|
package/dist/server.js
CHANGED
|
@@ -47,6 +47,10 @@ async function loadSite(options) {
|
|
|
47
47
|
// src/server/sitemap.ts
|
|
48
48
|
import { BuilderNotFoundError, BuilderUnavailableError as BuilderUnavailableError2 } from "@usethrottle/builder";
|
|
49
49
|
async function builderSitemap(options) {
|
|
50
|
+
if (options.client === void 0 && (options.builderKey === void 0 || options.builderKey === "")) {
|
|
51
|
+
warnOnce("sitemap-no-key", "builderSitemap has no builderKey (is THROTTLE_BUILDER_KEY set?); the sitemap leaves out the Builder pages");
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
50
54
|
const client = clientOf(options);
|
|
51
55
|
const origin = originOf(options.storeUrl);
|
|
52
56
|
if (origin === void 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usethrottle/builder-react",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Renders a published Throttle Builder page document as React in a merchant's store: responsive CSS, header, footer, slots and the site design provider.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"nextjs"
|
|
58
58
|
],
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@usethrottle/builder": "^0.
|
|
60
|
+
"@usethrottle/builder": "^0.3.0",
|
|
61
61
|
"@usethrottle/builder-schema": "^0.1.2",
|
|
62
62
|
"@usethrottle/ui": "^0.1.2"
|
|
63
63
|
},
|