@usethrottle/builder-react 0.4.1 → 0.4.3

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.
@@ -352,11 +352,11 @@ import { BASIC_WIDGET_DEFINITIONS, resolveResponsive, safeUrl } from "@usethrott
352
352
 
353
353
  // src/basics/styles.ts
354
354
  var BASICS_CSS = `@layer throttle{
355
- .tb-b-heading{margin:0;text-align:var(--b-align,left);color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-l));line-height:1.2;overflow-wrap:anywhere}
355
+ .tb-b-heading{margin:0;font-family:var(--throttle-font-family-heading,inherit);text-align:var(--b-align,left);color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-l));line-height:1.2;overflow-wrap:anywhere}
356
356
  .tb-b-text{text-align:var(--b-align,left);color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-m));line-height:1.6;overflow-wrap:anywhere}
357
357
  .tb-b-text>:first-child{margin-block-start:0}
358
358
  .tb-b-text>:last-child{margin-block-end:0}
359
- .tb-b-text h2,.tb-b-text h3,.tb-b-text h4{line-height:1.25}
359
+ .tb-b-text h2,.tb-b-text h3,.tb-b-text h4{font-family:var(--throttle-font-family-heading,inherit);line-height:1.25}
360
360
  .tb-b-text blockquote{margin-inline:0;padding-inline-start:var(--tb-space-m);border-inline-start:3px solid var(--tb-color-border,currentColor)}
361
361
  .tb-b-text code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:.9em}
362
362
  .tb-b-link{color:var(--tb-color-primary,currentColor);text-decoration:underline}
@@ -1309,6 +1309,44 @@ function Video({ node, props, editMode }) {
1309
1309
  ] });
1310
1310
  }
1311
1311
 
1312
+ // src/basics/v2/announcement-v2.tsx
1313
+ var announcementV2Widgets = [];
1314
+
1315
+ // src/basics/v2/breadcrumbs.tsx
1316
+ var breadcrumbsWidgets = [];
1317
+
1318
+ // src/basics/v2/faq.tsx
1319
+ var faqWidgets = [];
1320
+
1321
+ // src/basics/v2/icon-list.tsx
1322
+ var iconListWidgets = [];
1323
+
1324
+ // src/basics/v2/merge.ts
1325
+ function mergeV2Widgets(v1, v2) {
1326
+ const replacement = /* @__PURE__ */ new Map();
1327
+ for (const widget of v2) {
1328
+ if (replacement.has(widget.type)) throw new Error(`Two v2 widgets of type ${widget.type}`);
1329
+ replacement.set(widget.type, widget);
1330
+ }
1331
+ const v1Types = new Set(v1.map((widget) => widget.type));
1332
+ return [
1333
+ ...v1.map((widget) => replacement.get(widget.type) ?? widget),
1334
+ ...[...replacement.values()].filter((widget) => !v1Types.has(widget.type))
1335
+ ];
1336
+ }
1337
+
1338
+ // src/basics/v2/menu-v2.tsx
1339
+ var menuV2Widgets = [];
1340
+
1341
+ // src/basics/v2/quote.tsx
1342
+ var quoteWidgets = [];
1343
+
1344
+ // src/basics/v2/rich-content.tsx
1345
+ var richContentWidgets = [];
1346
+
1347
+ // src/basics/v2/svg.tsx
1348
+ var svgWidgets = [];
1349
+
1312
1350
  // src/basics/index.ts
1313
1351
  var BASIC_COMPONENTS = {
1314
1352
  "basic.heading": Heading,
@@ -1324,9 +1362,19 @@ var BASIC_COMPONENTS = {
1324
1362
  "basic.copyright": Copyright,
1325
1363
  "basic.countdown": Countdown
1326
1364
  };
1327
- var widgets = BASIC_WIDGET_DEFINITIONS2.flatMap(
1365
+ var v1Widgets = BASIC_WIDGET_DEFINITIONS2.flatMap(
1328
1366
  (definition) => Object.hasOwn(BASIC_COMPONENTS, definition.type) ? [{ ...definition, Component: BASIC_COMPONENTS[definition.type] }] : []
1329
1367
  );
1368
+ var widgets = mergeV2Widgets(v1Widgets, [
1369
+ ...faqWidgets,
1370
+ ...richContentWidgets,
1371
+ ...breadcrumbsWidgets,
1372
+ ...svgWidgets,
1373
+ ...iconListWidgets,
1374
+ ...quoteWidgets,
1375
+ ...menuV2Widgets,
1376
+ ...announcementV2Widgets
1377
+ ]);
1330
1378
  var basicPack = { id: "basic", version: "0.0.0", widgets, dataSources: [] };
1331
1379
 
1332
1380
  // src/custom/factory.ts
@@ -352,11 +352,11 @@ var _ui = require('@usethrottle/ui');
352
352
 
353
353
  // src/basics/styles.ts
354
354
  var BASICS_CSS = `@layer throttle{
355
- .tb-b-heading{margin:0;text-align:var(--b-align,left);color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-l));line-height:1.2;overflow-wrap:anywhere}
355
+ .tb-b-heading{margin:0;font-family:var(--throttle-font-family-heading,inherit);text-align:var(--b-align,left);color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-l));line-height:1.2;overflow-wrap:anywhere}
356
356
  .tb-b-text{text-align:var(--b-align,left);color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-m));line-height:1.6;overflow-wrap:anywhere}
357
357
  .tb-b-text>:first-child{margin-block-start:0}
358
358
  .tb-b-text>:last-child{margin-block-end:0}
359
- .tb-b-text h2,.tb-b-text h3,.tb-b-text h4{line-height:1.25}
359
+ .tb-b-text h2,.tb-b-text h3,.tb-b-text h4{font-family:var(--throttle-font-family-heading,inherit);line-height:1.25}
360
360
  .tb-b-text blockquote{margin-inline:0;padding-inline-start:var(--tb-space-m);border-inline-start:3px solid var(--tb-color-border,currentColor)}
361
361
  .tb-b-text code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:.9em}
362
362
  .tb-b-link{color:var(--tb-color-primary,currentColor);text-decoration:underline}
@@ -1309,6 +1309,44 @@ function Video({ node, props, editMode }) {
1309
1309
  ] });
1310
1310
  }
1311
1311
 
1312
+ // src/basics/v2/announcement-v2.tsx
1313
+ var announcementV2Widgets = [];
1314
+
1315
+ // src/basics/v2/breadcrumbs.tsx
1316
+ var breadcrumbsWidgets = [];
1317
+
1318
+ // src/basics/v2/faq.tsx
1319
+ var faqWidgets = [];
1320
+
1321
+ // src/basics/v2/icon-list.tsx
1322
+ var iconListWidgets = [];
1323
+
1324
+ // src/basics/v2/merge.ts
1325
+ function mergeV2Widgets(v1, v2) {
1326
+ const replacement = /* @__PURE__ */ new Map();
1327
+ for (const widget of v2) {
1328
+ if (replacement.has(widget.type)) throw new Error(`Two v2 widgets of type ${widget.type}`);
1329
+ replacement.set(widget.type, widget);
1330
+ }
1331
+ const v1Types = new Set(v1.map((widget) => widget.type));
1332
+ return [
1333
+ ...v1.map((widget) => _nullishCoalesce(replacement.get(widget.type), () => ( widget))),
1334
+ ...[...replacement.values()].filter((widget) => !v1Types.has(widget.type))
1335
+ ];
1336
+ }
1337
+
1338
+ // src/basics/v2/menu-v2.tsx
1339
+ var menuV2Widgets = [];
1340
+
1341
+ // src/basics/v2/quote.tsx
1342
+ var quoteWidgets = [];
1343
+
1344
+ // src/basics/v2/rich-content.tsx
1345
+ var richContentWidgets = [];
1346
+
1347
+ // src/basics/v2/svg.tsx
1348
+ var svgWidgets = [];
1349
+
1312
1350
  // src/basics/index.ts
1313
1351
  var BASIC_COMPONENTS = {
1314
1352
  "basic.heading": Heading,
@@ -1324,9 +1362,19 @@ var BASIC_COMPONENTS = {
1324
1362
  "basic.copyright": Copyright,
1325
1363
  "basic.countdown": Countdown
1326
1364
  };
1327
- var widgets = _builderschema.BASIC_WIDGET_DEFINITIONS.flatMap(
1365
+ var v1Widgets = _builderschema.BASIC_WIDGET_DEFINITIONS.flatMap(
1328
1366
  (definition) => Object.hasOwn(BASIC_COMPONENTS, definition.type) ? [{ ...definition, Component: BASIC_COMPONENTS[definition.type] }] : []
1329
1367
  );
1368
+ var widgets = mergeV2Widgets(v1Widgets, [
1369
+ ...faqWidgets,
1370
+ ...richContentWidgets,
1371
+ ...breadcrumbsWidgets,
1372
+ ...svgWidgets,
1373
+ ...iconListWidgets,
1374
+ ...quoteWidgets,
1375
+ ...menuV2Widgets,
1376
+ ...announcementV2Widgets
1377
+ ]);
1330
1378
  var basicPack = { id: "basic", version: "0.0.0", widgets, dataSources: [] };
1331
1379
 
1332
1380
  // src/custom/factory.ts
package/dist/index.cjs CHANGED
@@ -2028,11 +2028,11 @@ var import_builder_schema14 = require("@usethrottle/builder-schema");
2028
2028
 
2029
2029
  // src/basics/styles.ts
2030
2030
  var BASICS_CSS = `@layer throttle{
2031
- .tb-b-heading{margin:0;text-align:var(--b-align,left);color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-l));line-height:1.2;overflow-wrap:anywhere}
2031
+ .tb-b-heading{margin:0;font-family:var(--throttle-font-family-heading,inherit);text-align:var(--b-align,left);color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-l));line-height:1.2;overflow-wrap:anywhere}
2032
2032
  .tb-b-text{text-align:var(--b-align,left);color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-m));line-height:1.6;overflow-wrap:anywhere}
2033
2033
  .tb-b-text>:first-child{margin-block-start:0}
2034
2034
  .tb-b-text>:last-child{margin-block-end:0}
2035
- .tb-b-text h2,.tb-b-text h3,.tb-b-text h4{line-height:1.25}
2035
+ .tb-b-text h2,.tb-b-text h3,.tb-b-text h4{font-family:var(--throttle-font-family-heading,inherit);line-height:1.25}
2036
2036
  .tb-b-text blockquote{margin-inline:0;padding-inline-start:var(--tb-space-m);border-inline-start:3px solid var(--tb-color-border,currentColor)}
2037
2037
  .tb-b-text code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:.9em}
2038
2038
  .tb-b-link{color:var(--tb-color-primary,currentColor);text-decoration:underline}
@@ -2707,6 +2707,44 @@ function Video({ node, props, editMode }) {
2707
2707
  ] });
2708
2708
  }
2709
2709
 
2710
+ // src/basics/v2/announcement-v2.tsx
2711
+ var announcementV2Widgets = [];
2712
+
2713
+ // src/basics/v2/breadcrumbs.tsx
2714
+ var breadcrumbsWidgets = [];
2715
+
2716
+ // src/basics/v2/faq.tsx
2717
+ var faqWidgets = [];
2718
+
2719
+ // src/basics/v2/icon-list.tsx
2720
+ var iconListWidgets = [];
2721
+
2722
+ // src/basics/v2/merge.ts
2723
+ function mergeV2Widgets(v1, v2) {
2724
+ const replacement = /* @__PURE__ */ new Map();
2725
+ for (const widget of v2) {
2726
+ if (replacement.has(widget.type)) throw new Error(`Two v2 widgets of type ${widget.type}`);
2727
+ replacement.set(widget.type, widget);
2728
+ }
2729
+ const v1Types = new Set(v1.map((widget) => widget.type));
2730
+ return [
2731
+ ...v1.map((widget) => replacement.get(widget.type) ?? widget),
2732
+ ...[...replacement.values()].filter((widget) => !v1Types.has(widget.type))
2733
+ ];
2734
+ }
2735
+
2736
+ // src/basics/v2/menu-v2.tsx
2737
+ var menuV2Widgets = [];
2738
+
2739
+ // src/basics/v2/quote.tsx
2740
+ var quoteWidgets = [];
2741
+
2742
+ // src/basics/v2/rich-content.tsx
2743
+ var richContentWidgets = [];
2744
+
2745
+ // src/basics/v2/svg.tsx
2746
+ var svgWidgets = [];
2747
+
2710
2748
  // src/basics/index.ts
2711
2749
  var BASIC_COMPONENTS = {
2712
2750
  "basic.heading": Heading,
@@ -2722,9 +2760,19 @@ var BASIC_COMPONENTS = {
2722
2760
  "basic.copyright": Copyright,
2723
2761
  "basic.countdown": Countdown
2724
2762
  };
2725
- var widgets = import_builder_schema21.BASIC_WIDGET_DEFINITIONS.flatMap(
2763
+ var v1Widgets = import_builder_schema21.BASIC_WIDGET_DEFINITIONS.flatMap(
2726
2764
  (definition) => Object.hasOwn(BASIC_COMPONENTS, definition.type) ? [{ ...definition, Component: BASIC_COMPONENTS[definition.type] }] : []
2727
2765
  );
2766
+ var widgets = mergeV2Widgets(v1Widgets, [
2767
+ ...faqWidgets,
2768
+ ...richContentWidgets,
2769
+ ...breadcrumbsWidgets,
2770
+ ...svgWidgets,
2771
+ ...iconListWidgets,
2772
+ ...quoteWidgets,
2773
+ ...menuV2Widgets,
2774
+ ...announcementV2Widgets
2775
+ ]);
2728
2776
  var basicPack = { id: "basic", version: "0.0.0", widgets, dataSources: [] };
2729
2777
 
2730
2778
  // src/custom/factory.ts
@@ -3118,9 +3166,10 @@ var kebab = (key) => key.replace(/^color/, "").replace(/([a-z])([A-Z])/g, "$1-$2
3118
3166
  function colourDecls(p) {
3119
3167
  return PALETTE_KEYS.map((key) => `--tb-color-${kebab(key)}:${p[key]}`).join(";");
3120
3168
  }
3121
- function themeCss(settings) {
3169
+ function themeCss(settings, options = {}) {
3122
3170
  const { tokens, colorScheme } = themeTokens(settings);
3123
- const light = `:root{--tb-scale:${String(SCALE[tokens.spacingScale])};${colourDecls(tokens.light)}}`;
3171
+ const heading = options.hostFont === true ? "" : `--throttle-font-family-heading:${fontStack(tokens.fonts.heading)};`;
3172
+ const light = `:root{--tb-scale:${String(SCALE[tokens.spacingScale])};${heading}${colourDecls(tokens.light)}}`;
3124
3173
  const dark = colourDecls(tokens.dark);
3125
3174
  if (colorScheme === "light") return light;
3126
3175
  if (colorScheme === "dark") return `${light}:root{${dark}}`;
@@ -3296,7 +3345,7 @@ function BuilderProvider({ builderKey, client, packs, site, onError, interactive
3296
3345
  return parentFont === void 0 ? merged : { ...merged, variables: { ...merged.variables, fontFamily: parentFont } };
3297
3346
  }, [own, merged, parentFont]);
3298
3347
  return /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(BuilderContext.Provider, { value, children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_ui6.ThrottleUIProvider, { ...appearance === void 0 ? {} : { appearance }, children: /* @__PURE__ */ (0, import_jsx_runtime33.jsx)(import_ui6.SiteDesignProvider, { value: design, children: /* @__PURE__ */ (0, import_jsx_runtime33.jsxs)(import_ui6.SlotOutletProvider, { resolve: resolveSlot, children: [
3299
- site.status === "ok" ? /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("style", { children: themeCss(site.settings) }) : null,
3348
+ site.status === "ok" ? /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("style", { children: themeCss(site.settings, { hostFont: parentFont !== void 0 }) }) : null,
3300
3349
  customCss === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("style", { children: customCssSheet(customCss) }),
3301
3350
  leaving ? /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("div", { "data-b-leaving": "", hidden: true }) : children
3302
3351
  ] }) }) }) });
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ReactNode, ComponentType, CSSProperties, Context } from 'react';
2
- import { TemplateAst, WidgetNode, SettingValue, WidgetDefinition, DataSourceDescriptor, PageDocument, FrozenAsset, SavedSectionsAnswer, CodeRuntimeAnswer, WidgetRegistry, CustomWidgetSnapshot, CodeWidgetSnapshotLive, AnyCustomWidgetSnapshot, SettingField, DataBinding, SavedSectionRefNode } from '@usethrottle/builder-schema';
2
+ import { TemplateAst, TemplateName, RootNode, StoreRoutes, WidgetNode, SettingValue, WidgetDefinition, DataSourceDescriptor, PageDocument, FrozenAsset, SavedSectionsAnswer, CodeRuntimeAnswer, WidgetRegistry, CustomWidgetSnapshot, CodeWidgetSnapshotLive, AnyCustomWidgetSnapshot, SettingField, DataBinding, SavedSectionRefNode } from '@usethrottle/builder-schema';
3
3
  import { BuilderClient } from '@usethrottle/builder';
4
4
  export { BuilderNotFoundError, BuilderUnavailableError } from '@usethrottle/builder';
5
5
 
@@ -29,6 +29,62 @@ type Budget = Pick<RenderBudget, 'limit' | 'used' | 'exhausted' | 'take'>;
29
29
  /** True when a template's worst case fits the budget; the interpreter refuses the template otherwise. */
30
30
  declare const fitsBudget: (ast: TemplateAst, limit?: number) => boolean;
31
31
 
32
+ /** The route a template loader serves: the matched path, its dynamic params and the query string. */
33
+ type TemplateRoute = {
34
+ path: string;
35
+ params: Record<string, string>;
36
+ query: Record<string, string | string[]>;
37
+ };
38
+ /**
39
+ * What a template's widgets read (spec §5.1): the loaded catalog or shopper data of the route. Each field
40
+ * is plain data a loader resolved on the server; the owning stream (T-P, T-L, T-A) narrows its own field.
41
+ */
42
+ type TemplateContext = {
43
+ product?: unknown;
44
+ listing?: unknown;
45
+ cart?: unknown;
46
+ customer?: unknown;
47
+ route: TemplateRoute;
48
+ };
49
+ /** The answer of a template loader. */
50
+ type TemplateLoadResult = {
51
+ status: 'ok';
52
+ context: TemplateContext;
53
+ } | {
54
+ status: 'not-found';
55
+ } | {
56
+ status: 'redirect';
57
+ to: string;
58
+ } | {
59
+ status: 'unavailable';
60
+ };
61
+ /** Reads what one template needs for one request. */
62
+ type TemplateLoader = (args: {
63
+ params: Record<string, string | string[] | undefined>;
64
+ searchParams: Record<string, string | string[] | undefined>;
65
+ route: TemplateRoute;
66
+ }) => Promise<TemplateLoadResult>;
67
+ /** The sections of a document: what `PageDocument.sections` holds. */
68
+ type DocumentNodes = RootNode[];
69
+ /** What a widget pack contributes for one template: its loader and its default composition. */
70
+ type PackTemplateContribution = {
71
+ name: TemplateName;
72
+ loader: TemplateLoader;
73
+ /** The pack's default composition of the template, optionally one of its `variants`. */
74
+ defaultComposition: (variant?: string) => DocumentNodes;
75
+ variants?: string[];
76
+ };
77
+ /** What the store hands the template route (spec §5.1). */
78
+ type BuilderRouteConfig = {
79
+ site: LoadedSite;
80
+ packs: readonly WidgetPack[];
81
+ /** Catalog route prefixes the store serves (`shop`, `collection`, ...), by template name. */
82
+ catalogRoutes?: Partial<Record<TemplateName, string>>;
83
+ /** Paths of the store templates the merchant renamed (`routes.store`). */
84
+ storeRoutes?: Partial<StoreRoutes>;
85
+ loaders: Partial<Record<TemplateName, TemplateLoader>>;
86
+ };
87
+
32
88
  /** Resolved data by binding key (`bindingKey`), plus `context.*` entries a slot supplies. */
33
89
  type DataMap = Record<string, unknown>;
34
90
  type WidgetRenderProps = {
@@ -101,6 +157,8 @@ type WidgetPack = {
101
157
  dataSources: PackDataSource[];
102
158
  linkTargets?: LinkTargetProvider;
103
159
  slots?: SlotPoint[];
160
+ /** The templates the pack contributes: loaders and default compositions (spec §5.1). */
161
+ templates?: PackTemplateContribution[];
104
162
  };
105
163
  /** A page document as the store reads it (a published snapshot). */
106
164
  type PageAssets = Record<string, FrozenAsset>;
@@ -626,4 +684,4 @@ declare function CompositeWidget(props: CompositeWidgetProps): ReactNode;
626
684
  */
627
685
  declare const customWidgetFactory: CustomWidgetFactory;
628
686
 
629
- export { AssetImage, BASE_CSS, BASIC_COMPONENTS, BuilderContext, type BuilderContextValue, BuilderFooter, BuilderHeader, BuilderPage, BuilderPageView, BuilderProvider, type BuilderProviderProps, BuilderRenderer, type BuilderRendererProps, BuilderSlot, CODE_ROUTE_DENY, CUSTOM_WIDGET_CONTAINMENT, type CodeRender, CodeWidget, type CodeWidgetProps, CompositeWidget, type CompositeWidgetProps, type CustomWidgetFactory, DEFAULT_CATALOG_ROUTES, type DataMap, type DataSourceResolver, type EditModeHooks, type LinkTargetProvider, type LoadedPage, type LoadedPart, type LoadedRedirect, type LoadedSite, MAX_RENDERED_NODES, MissingSavedSection, NodeWrapper, type PackDataSource, type PackWidget, RenderBudget, type RenderWarning, type RendererRegistry, type RendererRegistryOptions, type ResolveContext, RichText, type SlotPoint, TemplateWidget, type TemplateWidgetProps, type WidgetPack, type WidgetRenderProps, WidgetStyle, basicPack, bindingKey, bindingsOf, codeScriptUrl, collectBindings, compileResponsiveCss, createRendererRegistry, cssValue, customWidgetFactory, embedSrc, expandSavedSections, fitsBudget, isCodeRoute, isFrozenAsset, jsonForScript, parseRichText, parseVideoUrl, pickLocale, resolveBindings, useBuilder, validateRender };
687
+ export { AssetImage, BASE_CSS, BASIC_COMPONENTS, BuilderContext, type BuilderContextValue, BuilderFooter, BuilderHeader, BuilderPage, BuilderPageView, BuilderProvider, type BuilderProviderProps, BuilderRenderer, type BuilderRendererProps, type BuilderRouteConfig, BuilderSlot, CODE_ROUTE_DENY, CUSTOM_WIDGET_CONTAINMENT, type CodeRender, CodeWidget, type CodeWidgetProps, CompositeWidget, type CompositeWidgetProps, type CustomWidgetFactory, DEFAULT_CATALOG_ROUTES, type DataMap, type DataSourceResolver, type DocumentNodes, type EditModeHooks, type LinkTargetProvider, type LoadedPage, type LoadedPart, type LoadedRedirect, type LoadedSite, MAX_RENDERED_NODES, MissingSavedSection, NodeWrapper, type PackDataSource, type PackTemplateContribution, type PackWidget, RenderBudget, type RenderWarning, type RendererRegistry, type RendererRegistryOptions, type ResolveContext, RichText, type SlotPoint, type TemplateContext, type TemplateLoadResult, type TemplateLoader, type TemplateRoute, TemplateWidget, type TemplateWidgetProps, type WidgetPack, type WidgetRenderProps, WidgetStyle, basicPack, bindingKey, bindingsOf, codeScriptUrl, collectBindings, compileResponsiveCss, createRendererRegistry, cssValue, customWidgetFactory, embedSrc, expandSavedSections, fitsBudget, isCodeRoute, isFrozenAsset, jsonForScript, parseRichText, parseVideoUrl, pickLocale, resolveBindings, useBuilder, validateRender };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ReactNode, ComponentType, CSSProperties, Context } from 'react';
2
- import { TemplateAst, WidgetNode, SettingValue, WidgetDefinition, DataSourceDescriptor, PageDocument, FrozenAsset, SavedSectionsAnswer, CodeRuntimeAnswer, WidgetRegistry, CustomWidgetSnapshot, CodeWidgetSnapshotLive, AnyCustomWidgetSnapshot, SettingField, DataBinding, SavedSectionRefNode } from '@usethrottle/builder-schema';
2
+ import { TemplateAst, TemplateName, RootNode, StoreRoutes, WidgetNode, SettingValue, WidgetDefinition, DataSourceDescriptor, PageDocument, FrozenAsset, SavedSectionsAnswer, CodeRuntimeAnswer, WidgetRegistry, CustomWidgetSnapshot, CodeWidgetSnapshotLive, AnyCustomWidgetSnapshot, SettingField, DataBinding, SavedSectionRefNode } from '@usethrottle/builder-schema';
3
3
  import { BuilderClient } from '@usethrottle/builder';
4
4
  export { BuilderNotFoundError, BuilderUnavailableError } from '@usethrottle/builder';
5
5
 
@@ -29,6 +29,62 @@ type Budget = Pick<RenderBudget, 'limit' | 'used' | 'exhausted' | 'take'>;
29
29
  /** True when a template's worst case fits the budget; the interpreter refuses the template otherwise. */
30
30
  declare const fitsBudget: (ast: TemplateAst, limit?: number) => boolean;
31
31
 
32
+ /** The route a template loader serves: the matched path, its dynamic params and the query string. */
33
+ type TemplateRoute = {
34
+ path: string;
35
+ params: Record<string, string>;
36
+ query: Record<string, string | string[]>;
37
+ };
38
+ /**
39
+ * What a template's widgets read (spec §5.1): the loaded catalog or shopper data of the route. Each field
40
+ * is plain data a loader resolved on the server; the owning stream (T-P, T-L, T-A) narrows its own field.
41
+ */
42
+ type TemplateContext = {
43
+ product?: unknown;
44
+ listing?: unknown;
45
+ cart?: unknown;
46
+ customer?: unknown;
47
+ route: TemplateRoute;
48
+ };
49
+ /** The answer of a template loader. */
50
+ type TemplateLoadResult = {
51
+ status: 'ok';
52
+ context: TemplateContext;
53
+ } | {
54
+ status: 'not-found';
55
+ } | {
56
+ status: 'redirect';
57
+ to: string;
58
+ } | {
59
+ status: 'unavailable';
60
+ };
61
+ /** Reads what one template needs for one request. */
62
+ type TemplateLoader = (args: {
63
+ params: Record<string, string | string[] | undefined>;
64
+ searchParams: Record<string, string | string[] | undefined>;
65
+ route: TemplateRoute;
66
+ }) => Promise<TemplateLoadResult>;
67
+ /** The sections of a document: what `PageDocument.sections` holds. */
68
+ type DocumentNodes = RootNode[];
69
+ /** What a widget pack contributes for one template: its loader and its default composition. */
70
+ type PackTemplateContribution = {
71
+ name: TemplateName;
72
+ loader: TemplateLoader;
73
+ /** The pack's default composition of the template, optionally one of its `variants`. */
74
+ defaultComposition: (variant?: string) => DocumentNodes;
75
+ variants?: string[];
76
+ };
77
+ /** What the store hands the template route (spec §5.1). */
78
+ type BuilderRouteConfig = {
79
+ site: LoadedSite;
80
+ packs: readonly WidgetPack[];
81
+ /** Catalog route prefixes the store serves (`shop`, `collection`, ...), by template name. */
82
+ catalogRoutes?: Partial<Record<TemplateName, string>>;
83
+ /** Paths of the store templates the merchant renamed (`routes.store`). */
84
+ storeRoutes?: Partial<StoreRoutes>;
85
+ loaders: Partial<Record<TemplateName, TemplateLoader>>;
86
+ };
87
+
32
88
  /** Resolved data by binding key (`bindingKey`), plus `context.*` entries a slot supplies. */
33
89
  type DataMap = Record<string, unknown>;
34
90
  type WidgetRenderProps = {
@@ -101,6 +157,8 @@ type WidgetPack = {
101
157
  dataSources: PackDataSource[];
102
158
  linkTargets?: LinkTargetProvider;
103
159
  slots?: SlotPoint[];
160
+ /** The templates the pack contributes: loaders and default compositions (spec §5.1). */
161
+ templates?: PackTemplateContribution[];
104
162
  };
105
163
  /** A page document as the store reads it (a published snapshot). */
106
164
  type PageAssets = Record<string, FrozenAsset>;
@@ -626,4 +684,4 @@ declare function CompositeWidget(props: CompositeWidgetProps): ReactNode;
626
684
  */
627
685
  declare const customWidgetFactory: CustomWidgetFactory;
628
686
 
629
- export { AssetImage, BASE_CSS, BASIC_COMPONENTS, BuilderContext, type BuilderContextValue, BuilderFooter, BuilderHeader, BuilderPage, BuilderPageView, BuilderProvider, type BuilderProviderProps, BuilderRenderer, type BuilderRendererProps, BuilderSlot, CODE_ROUTE_DENY, CUSTOM_WIDGET_CONTAINMENT, type CodeRender, CodeWidget, type CodeWidgetProps, CompositeWidget, type CompositeWidgetProps, type CustomWidgetFactory, DEFAULT_CATALOG_ROUTES, type DataMap, type DataSourceResolver, type EditModeHooks, type LinkTargetProvider, type LoadedPage, type LoadedPart, type LoadedRedirect, type LoadedSite, MAX_RENDERED_NODES, MissingSavedSection, NodeWrapper, type PackDataSource, type PackWidget, RenderBudget, type RenderWarning, type RendererRegistry, type RendererRegistryOptions, type ResolveContext, RichText, type SlotPoint, TemplateWidget, type TemplateWidgetProps, type WidgetPack, type WidgetRenderProps, WidgetStyle, basicPack, bindingKey, bindingsOf, codeScriptUrl, collectBindings, compileResponsiveCss, createRendererRegistry, cssValue, customWidgetFactory, embedSrc, expandSavedSections, fitsBudget, isCodeRoute, isFrozenAsset, jsonForScript, parseRichText, parseVideoUrl, pickLocale, resolveBindings, useBuilder, validateRender };
687
+ export { AssetImage, BASE_CSS, BASIC_COMPONENTS, BuilderContext, type BuilderContextValue, BuilderFooter, BuilderHeader, BuilderPage, BuilderPageView, BuilderProvider, type BuilderProviderProps, BuilderRenderer, type BuilderRendererProps, type BuilderRouteConfig, BuilderSlot, CODE_ROUTE_DENY, CUSTOM_WIDGET_CONTAINMENT, type CodeRender, CodeWidget, type CodeWidgetProps, CompositeWidget, type CompositeWidgetProps, type CustomWidgetFactory, DEFAULT_CATALOG_ROUTES, type DataMap, type DataSourceResolver, type DocumentNodes, type EditModeHooks, type LinkTargetProvider, type LoadedPage, type LoadedPart, type LoadedRedirect, type LoadedSite, MAX_RENDERED_NODES, MissingSavedSection, NodeWrapper, type PackDataSource, type PackTemplateContribution, type PackWidget, RenderBudget, type RenderWarning, type RendererRegistry, type RendererRegistryOptions, type ResolveContext, RichText, type SlotPoint, type TemplateContext, type TemplateLoadResult, type TemplateLoader, type TemplateRoute, TemplateWidget, type TemplateWidgetProps, type WidgetPack, type WidgetRenderProps, WidgetStyle, basicPack, bindingKey, bindingsOf, codeScriptUrl, collectBindings, compileResponsiveCss, createRendererRegistry, cssValue, customWidgetFactory, embedSrc, expandSavedSections, fitsBudget, isCodeRoute, isFrozenAsset, jsonForScript, parseRichText, parseVideoUrl, pickLocale, resolveBindings, useBuilder, validateRender };
package/dist/index.js CHANGED
@@ -1989,11 +1989,11 @@ import { BASIC_WIDGET_DEFINITIONS, resolveResponsive as resolveResponsive3, safe
1989
1989
 
1990
1990
  // src/basics/styles.ts
1991
1991
  var BASICS_CSS = `@layer throttle{
1992
- .tb-b-heading{margin:0;text-align:var(--b-align,left);color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-l));line-height:1.2;overflow-wrap:anywhere}
1992
+ .tb-b-heading{margin:0;font-family:var(--throttle-font-family-heading,inherit);text-align:var(--b-align,left);color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-l));line-height:1.2;overflow-wrap:anywhere}
1993
1993
  .tb-b-text{text-align:var(--b-align,left);color:var(--b-color,inherit);font-size:var(--b-size,var(--tb-text-m));line-height:1.6;overflow-wrap:anywhere}
1994
1994
  .tb-b-text>:first-child{margin-block-start:0}
1995
1995
  .tb-b-text>:last-child{margin-block-end:0}
1996
- .tb-b-text h2,.tb-b-text h3,.tb-b-text h4{line-height:1.25}
1996
+ .tb-b-text h2,.tb-b-text h3,.tb-b-text h4{font-family:var(--throttle-font-family-heading,inherit);line-height:1.25}
1997
1997
  .tb-b-text blockquote{margin-inline:0;padding-inline-start:var(--tb-space-m);border-inline-start:3px solid var(--tb-color-border,currentColor)}
1998
1998
  .tb-b-text code{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:.9em}
1999
1999
  .tb-b-link{color:var(--tb-color-primary,currentColor);text-decoration:underline}
@@ -2668,6 +2668,44 @@ function Video({ node, props, editMode }) {
2668
2668
  ] });
2669
2669
  }
2670
2670
 
2671
+ // src/basics/v2/announcement-v2.tsx
2672
+ var announcementV2Widgets = [];
2673
+
2674
+ // src/basics/v2/breadcrumbs.tsx
2675
+ var breadcrumbsWidgets = [];
2676
+
2677
+ // src/basics/v2/faq.tsx
2678
+ var faqWidgets = [];
2679
+
2680
+ // src/basics/v2/icon-list.tsx
2681
+ var iconListWidgets = [];
2682
+
2683
+ // src/basics/v2/merge.ts
2684
+ function mergeV2Widgets(v1, v2) {
2685
+ const replacement = /* @__PURE__ */ new Map();
2686
+ for (const widget of v2) {
2687
+ if (replacement.has(widget.type)) throw new Error(`Two v2 widgets of type ${widget.type}`);
2688
+ replacement.set(widget.type, widget);
2689
+ }
2690
+ const v1Types = new Set(v1.map((widget) => widget.type));
2691
+ return [
2692
+ ...v1.map((widget) => replacement.get(widget.type) ?? widget),
2693
+ ...[...replacement.values()].filter((widget) => !v1Types.has(widget.type))
2694
+ ];
2695
+ }
2696
+
2697
+ // src/basics/v2/menu-v2.tsx
2698
+ var menuV2Widgets = [];
2699
+
2700
+ // src/basics/v2/quote.tsx
2701
+ var quoteWidgets = [];
2702
+
2703
+ // src/basics/v2/rich-content.tsx
2704
+ var richContentWidgets = [];
2705
+
2706
+ // src/basics/v2/svg.tsx
2707
+ var svgWidgets = [];
2708
+
2671
2709
  // src/basics/index.ts
2672
2710
  var BASIC_COMPONENTS = {
2673
2711
  "basic.heading": Heading,
@@ -2683,9 +2721,19 @@ var BASIC_COMPONENTS = {
2683
2721
  "basic.copyright": Copyright,
2684
2722
  "basic.countdown": Countdown
2685
2723
  };
2686
- var widgets = BASIC_WIDGET_DEFINITIONS2.flatMap(
2724
+ var v1Widgets = BASIC_WIDGET_DEFINITIONS2.flatMap(
2687
2725
  (definition) => Object.hasOwn(BASIC_COMPONENTS, definition.type) ? [{ ...definition, Component: BASIC_COMPONENTS[definition.type] }] : []
2688
2726
  );
2727
+ var widgets = mergeV2Widgets(v1Widgets, [
2728
+ ...faqWidgets,
2729
+ ...richContentWidgets,
2730
+ ...breadcrumbsWidgets,
2731
+ ...svgWidgets,
2732
+ ...iconListWidgets,
2733
+ ...quoteWidgets,
2734
+ ...menuV2Widgets,
2735
+ ...announcementV2Widgets
2736
+ ]);
2689
2737
  var basicPack = { id: "basic", version: "0.0.0", widgets, dataSources: [] };
2690
2738
 
2691
2739
  // src/custom/factory.ts
@@ -3079,9 +3127,10 @@ var kebab = (key) => key.replace(/^color/, "").replace(/([a-z])([A-Z])/g, "$1-$2
3079
3127
  function colourDecls(p) {
3080
3128
  return PALETTE_KEYS.map((key) => `--tb-color-${kebab(key)}:${p[key]}`).join(";");
3081
3129
  }
3082
- function themeCss(settings) {
3130
+ function themeCss(settings, options = {}) {
3083
3131
  const { tokens, colorScheme } = themeTokens(settings);
3084
- const light = `:root{--tb-scale:${String(SCALE[tokens.spacingScale])};${colourDecls(tokens.light)}}`;
3132
+ const heading = options.hostFont === true ? "" : `--throttle-font-family-heading:${fontStack(tokens.fonts.heading)};`;
3133
+ const light = `:root{--tb-scale:${String(SCALE[tokens.spacingScale])};${heading}${colourDecls(tokens.light)}}`;
3085
3134
  const dark = colourDecls(tokens.dark);
3086
3135
  if (colorScheme === "light") return light;
3087
3136
  if (colorScheme === "dark") return `${light}:root{${dark}}`;
@@ -3257,7 +3306,7 @@ function BuilderProvider({ builderKey, client, packs, site, onError, interactive
3257
3306
  return parentFont === void 0 ? merged : { ...merged, variables: { ...merged.variables, fontFamily: parentFont } };
3258
3307
  }, [own, merged, parentFont]);
3259
3308
  return /* @__PURE__ */ jsx33(BuilderContext.Provider, { value, children: /* @__PURE__ */ jsx33(ThrottleUIProvider, { ...appearance === void 0 ? {} : { appearance }, children: /* @__PURE__ */ jsx33(SiteDesignProvider, { value: design, children: /* @__PURE__ */ jsxs21(SlotOutletProvider, { resolve: resolveSlot, children: [
3260
- site.status === "ok" ? /* @__PURE__ */ jsx33("style", { children: themeCss(site.settings) }) : null,
3309
+ site.status === "ok" ? /* @__PURE__ */ jsx33("style", { children: themeCss(site.settings, { hostFont: parentFont !== void 0 }) }) : null,
3261
3310
  customCss === "" ? null : /* @__PURE__ */ jsx33("style", { children: customCssSheet(customCss) }),
3262
3311
  leaving ? /* @__PURE__ */ jsx33("div", { "data-b-leaving": "", hidden: true }) : children
3263
3312
  ] }) }) }) });
package/dist/next.cjs CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
 
6
6
 
7
- var _chunk3HSHGY7Mcjs = require('./chunk-3HSHGY7M.cjs');
7
+ var _chunkE7SRVAFVcjs = require('./chunk-E7SRVAFV.cjs');
8
8
 
9
9
  // src/next/index.ts
10
10
  var _react = require('react');
@@ -55,7 +55,7 @@ function createBuilderPage(options) {
55
55
  const slug = slugOf(options, params);
56
56
  const currency = await currencyOf(options, params);
57
57
  const { currency: _currency, ...rest } = options;
58
- const loaded = await _chunk3HSHGY7Mcjs.loadBuilderPage.call(void 0, {
58
+ const loaded = await _chunkE7SRVAFVcjs.loadBuilderPage.call(void 0, {
59
59
  ...rest,
60
60
  slug,
61
61
  locale: await localeOf(options, params),
@@ -75,12 +75,12 @@ function createBuilderPage(options) {
75
75
  const params = await props.params;
76
76
  const slug = slugOf(options, params);
77
77
  const locale = await localeOf(options, params);
78
- const client = _chunk3HSHGY7Mcjs.clientOf.call(void 0, options);
78
+ const client = _chunkE7SRVAFVcjs.clientOf.call(void 0, options);
79
79
  try {
80
- const bundle = await _chunk3HSHGY7Mcjs.getBundle.call(void 0, { client, locale, page: slug, slots: options.slots });
80
+ const bundle = await _chunkE7SRVAFVcjs.getBundle.call(void 0, { client, locale, page: slug, slots: options.slots });
81
81
  const page = bundle.page;
82
- if (page === void 0 || _chunk3HSHGY7Mcjs.isRedirect.call(void 0, page)) return {};
83
- return _chunk3HSHGY7Mcjs.metadataOf.call(void 0, page, {
82
+ if (page === void 0 || _chunkE7SRVAFVcjs.isRedirect.call(void 0, page)) return {};
83
+ return _chunkE7SRVAFVcjs.metadataOf.call(void 0, page, {
84
84
  settings: bundle.site.settings,
85
85
  mediaOrigin: _nullishCoalesce(options.mediaOrigin, () => ( "")),
86
86
  storeUrl: options.storeUrl,
package/dist/next.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { Metadata } from 'next';
3
- import { C as ClientOptions, W as WidgetPack, P as PagePathResolver } from './seo-CNZ9DrlU.cjs';
3
+ import { C as ClientOptions, W as WidgetPack, P as PagePathResolver } from './seo-BYBk3Sya.cjs';
4
4
  import '@usethrottle/builder-schema';
5
5
  import '@usethrottle/builder';
6
6
 
package/dist/next.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { Metadata } from 'next';
3
- import { C as ClientOptions, W as WidgetPack, P as PagePathResolver } from './seo-CNZ9DrlU.js';
3
+ import { C as ClientOptions, W as WidgetPack, P as PagePathResolver } from './seo-BYBk3Sya.js';
4
4
  import '@usethrottle/builder-schema';
5
5
  import '@usethrottle/builder';
6
6
 
package/dist/next.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  isRedirect,
5
5
  loadBuilderPage,
6
6
  metadataOf
7
- } from "./chunk-TS2WCTZ3.js";
7
+ } from "./chunk-C57AQKJI.js";
8
8
 
9
9
  // src/next/index.ts
10
10
  import { createElement } from "react";
@@ -1,5 +1,5 @@
1
1
  import { ComponentType, ReactNode } from 'react';
2
- import { WidgetDefinition, WidgetNode, SettingValue, DataSourceDescriptor, PageDocument, FrozenAsset, SavedSectionsAnswer, CodeRuntimeAnswer } from '@usethrottle/builder-schema';
2
+ import { TemplateName, RootNode, WidgetDefinition, WidgetNode, SettingValue, DataSourceDescriptor, PageDocument, FrozenAsset, SavedSectionsAnswer, CodeRuntimeAnswer } from '@usethrottle/builder-schema';
3
3
  import { BuilderClient, BuilderBundle } from '@usethrottle/builder';
4
4
 
5
5
  /** A count of rendered nodes with a ceiling. One per custom widget render. */
@@ -19,6 +19,52 @@ declare class RenderBudget {
19
19
  */
20
20
  type Budget = Pick<RenderBudget, 'limit' | 'used' | 'exhausted' | 'take'>;
21
21
 
22
+ /** The route a template loader serves: the matched path, its dynamic params and the query string. */
23
+ type TemplateRoute = {
24
+ path: string;
25
+ params: Record<string, string>;
26
+ query: Record<string, string | string[]>;
27
+ };
28
+ /**
29
+ * What a template's widgets read (spec §5.1): the loaded catalog or shopper data of the route. Each field
30
+ * is plain data a loader resolved on the server; the owning stream (T-P, T-L, T-A) narrows its own field.
31
+ */
32
+ type TemplateContext = {
33
+ product?: unknown;
34
+ listing?: unknown;
35
+ cart?: unknown;
36
+ customer?: unknown;
37
+ route: TemplateRoute;
38
+ };
39
+ /** The answer of a template loader. */
40
+ type TemplateLoadResult = {
41
+ status: 'ok';
42
+ context: TemplateContext;
43
+ } | {
44
+ status: 'not-found';
45
+ } | {
46
+ status: 'redirect';
47
+ to: string;
48
+ } | {
49
+ status: 'unavailable';
50
+ };
51
+ /** Reads what one template needs for one request. */
52
+ type TemplateLoader = (args: {
53
+ params: Record<string, string | string[] | undefined>;
54
+ searchParams: Record<string, string | string[] | undefined>;
55
+ route: TemplateRoute;
56
+ }) => Promise<TemplateLoadResult>;
57
+ /** The sections of a document: what `PageDocument.sections` holds. */
58
+ type DocumentNodes = RootNode[];
59
+ /** What a widget pack contributes for one template: its loader and its default composition. */
60
+ type PackTemplateContribution = {
61
+ name: TemplateName;
62
+ loader: TemplateLoader;
63
+ /** The pack's default composition of the template, optionally one of its `variants`. */
64
+ defaultComposition: (variant?: string) => DocumentNodes;
65
+ variants?: string[];
66
+ };
67
+
22
68
  /** Resolved data by binding key (`bindingKey`), plus `context.*` entries a slot supplies. */
23
69
  type DataMap = Record<string, unknown>;
24
70
  type WidgetRenderProps = {
@@ -85,6 +131,8 @@ type WidgetPack = {
85
131
  dataSources: PackDataSource[];
86
132
  linkTargets?: LinkTargetProvider;
87
133
  slots?: SlotPoint[];
134
+ /** The templates the pack contributes: loaders and default compositions (spec §5.1). */
135
+ templates?: PackTemplateContribution[];
88
136
  };
89
137
  /** A page document as the store reads it (a published snapshot). */
90
138
  type PageAssets = Record<string, FrozenAsset>;
@@ -1,5 +1,5 @@
1
1
  import { ComponentType, ReactNode } from 'react';
2
- import { WidgetDefinition, WidgetNode, SettingValue, DataSourceDescriptor, PageDocument, FrozenAsset, SavedSectionsAnswer, CodeRuntimeAnswer } from '@usethrottle/builder-schema';
2
+ import { TemplateName, RootNode, WidgetDefinition, WidgetNode, SettingValue, DataSourceDescriptor, PageDocument, FrozenAsset, SavedSectionsAnswer, CodeRuntimeAnswer } from '@usethrottle/builder-schema';
3
3
  import { BuilderClient, BuilderBundle } from '@usethrottle/builder';
4
4
 
5
5
  /** A count of rendered nodes with a ceiling. One per custom widget render. */
@@ -19,6 +19,52 @@ declare class RenderBudget {
19
19
  */
20
20
  type Budget = Pick<RenderBudget, 'limit' | 'used' | 'exhausted' | 'take'>;
21
21
 
22
+ /** The route a template loader serves: the matched path, its dynamic params and the query string. */
23
+ type TemplateRoute = {
24
+ path: string;
25
+ params: Record<string, string>;
26
+ query: Record<string, string | string[]>;
27
+ };
28
+ /**
29
+ * What a template's widgets read (spec §5.1): the loaded catalog or shopper data of the route. Each field
30
+ * is plain data a loader resolved on the server; the owning stream (T-P, T-L, T-A) narrows its own field.
31
+ */
32
+ type TemplateContext = {
33
+ product?: unknown;
34
+ listing?: unknown;
35
+ cart?: unknown;
36
+ customer?: unknown;
37
+ route: TemplateRoute;
38
+ };
39
+ /** The answer of a template loader. */
40
+ type TemplateLoadResult = {
41
+ status: 'ok';
42
+ context: TemplateContext;
43
+ } | {
44
+ status: 'not-found';
45
+ } | {
46
+ status: 'redirect';
47
+ to: string;
48
+ } | {
49
+ status: 'unavailable';
50
+ };
51
+ /** Reads what one template needs for one request. */
52
+ type TemplateLoader = (args: {
53
+ params: Record<string, string | string[] | undefined>;
54
+ searchParams: Record<string, string | string[] | undefined>;
55
+ route: TemplateRoute;
56
+ }) => Promise<TemplateLoadResult>;
57
+ /** The sections of a document: what `PageDocument.sections` holds. */
58
+ type DocumentNodes = RootNode[];
59
+ /** What a widget pack contributes for one template: its loader and its default composition. */
60
+ type PackTemplateContribution = {
61
+ name: TemplateName;
62
+ loader: TemplateLoader;
63
+ /** The pack's default composition of the template, optionally one of its `variants`. */
64
+ defaultComposition: (variant?: string) => DocumentNodes;
65
+ variants?: string[];
66
+ };
67
+
22
68
  /** Resolved data by binding key (`bindingKey`), plus `context.*` entries a slot supplies. */
23
69
  type DataMap = Record<string, unknown>;
24
70
  type WidgetRenderProps = {
@@ -85,6 +131,8 @@ type WidgetPack = {
85
131
  dataSources: PackDataSource[];
86
132
  linkTargets?: LinkTargetProvider;
87
133
  slots?: SlotPoint[];
134
+ /** The templates the pack contributes: loaders and default compositions (spec §5.1). */
135
+ templates?: PackTemplateContribution[];
88
136
  };
89
137
  /** A page document as the store reads it (a published snapshot). */
90
138
  type PageAssets = Record<string, FrozenAsset>;
package/dist/server.cjs CHANGED
@@ -12,29 +12,29 @@
12
12
 
13
13
 
14
14
 
15
- var _chunk3HSHGY7Mcjs = require('./chunk-3HSHGY7M.cjs');
15
+ var _chunkE7SRVAFVcjs = require('./chunk-E7SRVAFV.cjs');
16
16
 
17
17
  // src/server/load-site.ts
18
18
  var _builder = require('@usethrottle/builder');
19
19
  async function loadSite(options) {
20
20
  const { locale, slots = [], packs = [], page, mediaOrigin = "", currency } = options;
21
- const client = _chunk3HSHGY7Mcjs.clientOf.call(void 0, options);
21
+ const client = _chunkE7SRVAFVcjs.clientOf.call(void 0, options);
22
22
  let bundle;
23
23
  try {
24
- bundle = await _chunk3HSHGY7Mcjs.getBundle.call(void 0, { client, locale, slots, page });
24
+ bundle = await _chunkE7SRVAFVcjs.getBundle.call(void 0, { client, locale, slots, page });
25
25
  } catch (error) {
26
26
  if (!(error instanceof _builder.BuilderUnavailableError) || client.mode === "build") throw error;
27
- _chunk3HSHGY7Mcjs.warnOnce.call(void 0, "site-unavailable", `The Builder could not be read (${error.reason}); the store renders without its Builder header, footer and slots`);
27
+ _chunkE7SRVAFVcjs.warnOnce.call(void 0, "site-unavailable", `The Builder could not be read (${error.reason}); the store renders without its Builder header, footer and slots`);
28
28
  return { status: "unavailable", locale };
29
29
  }
30
- const registry = _chunk3HSHGY7Mcjs.createRendererRegistry.call(void 0, packs);
30
+ const registry = _chunkE7SRVAFVcjs.createRendererRegistry.call(void 0, packs);
31
31
  const names = Object.keys(bundle.slots);
32
32
  const withShared = (loaded) => ({
33
33
  ...loaded,
34
34
  ...(_nullishCoalesce(loaded.savedSections, () => ( bundle.savedSections))) === void 0 ? {} : { savedSections: _nullishCoalesce(loaded.savedSections, () => ( bundle.savedSections)) }
35
35
  });
36
36
  const documents = [bundle.header, bundle.footer, ...names.map((n) => bundle.slots[n])].map(withShared);
37
- const data = await _chunk3HSHGY7Mcjs.staticDataFor.call(void 0, documents, registry, locale, currency);
37
+ const data = await _chunkE7SRVAFVcjs.staticDataFor.call(void 0, documents, registry, locale, currency);
38
38
  return {
39
39
  status: "ok",
40
40
  locale,
@@ -42,9 +42,9 @@ async function loadSite(options) {
42
42
  siteVersion: bundle.site.siteVersion,
43
43
  mediaOrigin,
44
44
  settings: bundle.site.settings,
45
- header: _chunk3HSHGY7Mcjs.partOf.call(void 0, bundle.header, data, bundle),
46
- footer: _chunk3HSHGY7Mcjs.partOf.call(void 0, bundle.footer, data, bundle),
47
- slots: Object.fromEntries(names.map((name) => [name, _chunk3HSHGY7Mcjs.partOf.call(void 0, bundle.slots[name], data, bundle)]))
45
+ header: _chunkE7SRVAFVcjs.partOf.call(void 0, bundle.header, data, bundle),
46
+ footer: _chunkE7SRVAFVcjs.partOf.call(void 0, bundle.footer, data, bundle),
47
+ slots: Object.fromEntries(names.map((name) => [name, _chunkE7SRVAFVcjs.partOf.call(void 0, bundle.slots[name], data, bundle)]))
48
48
  };
49
49
  }
50
50
 
@@ -52,13 +52,13 @@ async function loadSite(options) {
52
52
 
53
53
  async function builderSitemap(options) {
54
54
  if (options.client === void 0 && (options.builderKey === void 0 || options.builderKey === "")) {
55
- _chunk3HSHGY7Mcjs.warnOnce.call(void 0, "sitemap-no-key", "builderSitemap has no builderKey (is THROTTLE_BUILDER_KEY set?); the sitemap leaves out the Builder pages");
55
+ _chunkE7SRVAFVcjs.warnOnce.call(void 0, "sitemap-no-key", "builderSitemap has no builderKey (is THROTTLE_BUILDER_KEY set?); the sitemap leaves out the Builder pages");
56
56
  return [];
57
57
  }
58
- const client = _chunk3HSHGY7Mcjs.clientOf.call(void 0, options);
59
- const origin = _chunk3HSHGY7Mcjs.originOf.call(void 0, options.storeUrl);
58
+ const client = _chunkE7SRVAFVcjs.clientOf.call(void 0, options);
59
+ const origin = _chunkE7SRVAFVcjs.originOf.call(void 0, options.storeUrl);
60
60
  if (origin === void 0) {
61
- _chunk3HSHGY7Mcjs.warnOnce.call(void 0, "sitemap-origin", "builderSitemap needs a storeUrl (https://shop.example.com) that is an http(s) origin. The Builder does not publish the store URL.");
61
+ _chunkE7SRVAFVcjs.warnOnce.call(void 0, "sitemap-origin", "builderSitemap needs a storeUrl (https://shop.example.com) that is an http(s) origin. The Builder does not publish the store URL.");
62
62
  return [];
63
63
  }
64
64
  const locale = _nullishCoalesce(options.locale, () => ( "en"));
@@ -66,16 +66,16 @@ async function builderSitemap(options) {
66
66
  const pages = await client.pages.list();
67
67
  const { settings } = await client.site({ locale });
68
68
  const indexable = await withoutNoindex(client, pages, locale);
69
- const { list } = _chunk3HSHGY7Mcjs.siteLocales.call(void 0, settings);
69
+ const { list } = _chunkE7SRVAFVcjs.siteLocales.call(void 0, settings);
70
70
  const prefixes = options.localeRoute !== true ? [void 0] : list.length > 0 ? list : [locale];
71
71
  return indexable.flatMap((page) => {
72
- const path = _chunk3HSHGY7Mcjs.pagePathOf.call(void 0, settings, page, options.pagePath);
72
+ const path = _chunkE7SRVAFVcjs.pagePathOf.call(void 0, settings, page, options.pagePath);
73
73
  if (path === null) return [];
74
- return prefixes.map((prefix) => ({ url: `${origin}${_chunk3HSHGY7Mcjs.localized.call(void 0, path, prefix)}`, lastModified: new Date(page.updatedAt) }));
74
+ return prefixes.map((prefix) => ({ url: `${origin}${_chunkE7SRVAFVcjs.localized.call(void 0, path, prefix)}`, lastModified: new Date(page.updatedAt) }));
75
75
  });
76
76
  } catch (error) {
77
77
  if (!(error instanceof _builder.BuilderUnavailableError) || client.mode === "build") throw error;
78
- _chunk3HSHGY7Mcjs.warnOnce.call(void 0, "sitemap-unavailable", `The Builder could not be read (${error.reason}); the sitemap leaves out its pages`);
78
+ _chunkE7SRVAFVcjs.warnOnce.call(void 0, "sitemap-unavailable", `The Builder could not be read (${error.reason}); the sitemap leaves out its pages`);
79
79
  return [];
80
80
  }
81
81
  }
@@ -89,14 +89,14 @@ async function withoutNoindex(client, pages, locale) {
89
89
  slice.map(
90
90
  (page) => client.pages.get(page.slug, { locale }).catch((error) => {
91
91
  if (error instanceof _builder.BuilderNotFoundError) return "gone";
92
- _chunk3HSHGY7Mcjs.warnOnce.call(void 0, "sitemap-page-read", `A page could not be read for the sitemap (${error instanceof Error ? error.message : "unknown error"}); it stays listed`);
92
+ _chunkE7SRVAFVcjs.warnOnce.call(void 0, "sitemap-page-read", `A page could not be read for the sitemap (${error instanceof Error ? error.message : "unknown error"}); it stays listed`);
93
93
  return void 0;
94
94
  })
95
95
  )
96
96
  );
97
97
  slice.forEach((page, index) => {
98
98
  const answer = answers[index];
99
- if (answer === "gone" || answer !== void 0 && (_chunk3HSHGY7Mcjs.isRedirect.call(void 0, answer) || _chunk3HSHGY7Mcjs.pageSeoOf.call(void 0, answer).noindex)) skip.add(page.slug);
99
+ if (answer === "gone" || answer !== void 0 && (_chunkE7SRVAFVcjs.isRedirect.call(void 0, answer) || _chunkE7SRVAFVcjs.pageSeoOf.call(void 0, answer).noindex)) skip.add(page.slug);
100
100
  });
101
101
  }
102
102
  return pages.filter((page) => !skip.has(page.slug));
@@ -104,7 +104,7 @@ async function withoutNoindex(client, pages, locale) {
104
104
 
105
105
  // src/server/static-params.ts
106
106
  async function builderStaticParams(options) {
107
- const client = _chunk3HSHGY7Mcjs.clientOf.call(void 0, options);
107
+ const client = _chunkE7SRVAFVcjs.clientOf.call(void 0, options);
108
108
  if (client.mode !== "build")
109
109
  throw new TypeError(
110
110
  'builderStaticParams generates every page of a frozen release: give it a client made with createBuilderClient({ mode: "build" }). A live store keeps its pages dynamic.'
@@ -123,4 +123,4 @@ async function builderStaticParams(options) {
123
123
 
124
124
 
125
125
 
126
- exports.BuilderNotFoundError = _builder.BuilderNotFoundError; exports.BuilderUnavailableError = _builder.BuilderUnavailableError; exports.builderSitemap = builderSitemap; exports.builderStaticParams = builderStaticParams; exports.getBundle = _chunk3HSHGY7Mcjs.getBundle; exports.loadBuilderPage = _chunk3HSHGY7Mcjs.loadBuilderPage; exports.loadSite = loadSite;
126
+ exports.BuilderNotFoundError = _builder.BuilderNotFoundError; exports.BuilderUnavailableError = _builder.BuilderUnavailableError; exports.builderSitemap = builderSitemap; exports.builderStaticParams = builderStaticParams; exports.getBundle = _chunkE7SRVAFVcjs.getBundle; exports.loadBuilderPage = _chunkE7SRVAFVcjs.loadBuilderPage; exports.loadSite = loadSite;
package/dist/server.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as ClientOptions, W as WidgetPack, b as LoadedSite, L as LoadedPage, a as LoadedRedirect, P as PagePathResolver } from './seo-CNZ9DrlU.cjs';
2
- export { B as BundleAsk, g as getBundle } from './seo-CNZ9DrlU.cjs';
1
+ import { C as ClientOptions, W as WidgetPack, b as LoadedSite, L as LoadedPage, a as LoadedRedirect, P as PagePathResolver } from './seo-BYBk3Sya.cjs';
2
+ export { B as BundleAsk, g as getBundle } from './seo-BYBk3Sya.cjs';
3
3
  export { BuilderNotFoundError, BuilderUnavailableError } from '@usethrottle/builder';
4
4
  import 'react';
5
5
  import '@usethrottle/builder-schema';
package/dist/server.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as ClientOptions, W as WidgetPack, b as LoadedSite, L as LoadedPage, a as LoadedRedirect, P as PagePathResolver } from './seo-CNZ9DrlU.js';
2
- export { B as BundleAsk, g as getBundle } from './seo-CNZ9DrlU.js';
1
+ import { C as ClientOptions, W as WidgetPack, b as LoadedSite, L as LoadedPage, a as LoadedRedirect, P as PagePathResolver } from './seo-BYBk3Sya.js';
2
+ export { B as BundleAsk, g as getBundle } from './seo-BYBk3Sya.js';
3
3
  export { BuilderNotFoundError, BuilderUnavailableError } from '@usethrottle/builder';
4
4
  import 'react';
5
5
  import '@usethrottle/builder-schema';
package/dist/server.js CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  siteLocales,
13
13
  staticDataFor,
14
14
  warnOnce
15
- } from "./chunk-TS2WCTZ3.js";
15
+ } from "./chunk-C57AQKJI.js";
16
16
 
17
17
  // src/server/load-site.ts
18
18
  import { BuilderUnavailableError } from "@usethrottle/builder";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usethrottle/builder-react",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
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,9 +57,9 @@
57
57
  "nextjs"
58
58
  ],
59
59
  "dependencies": {
60
- "@usethrottle/builder-schema": "^0.2.1",
60
+ "@usethrottle/builder-schema": "^0.3.0",
61
61
  "@usethrottle/ui": "^0.1.2",
62
- "@usethrottle/builder": "^0.5.0"
62
+ "@usethrottle/builder": "^0.5.1"
63
63
  },
64
64
  "peerDependencies": {
65
65
  "next": ">=15",