@usethrottle/builder-react 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-GZN4SYTE.js → chunk-65KZ5CIP.js} +35 -6
- package/dist/{chunk-L7COZ3SN.cjs → chunk-ZCXPIZU7.cjs} +52 -23
- package/dist/index.cjs +39 -7
- package/dist/index.d.cts +15 -4
- package/dist/index.d.ts +15 -4
- package/dist/index.js +39 -7
- package/dist/next.cjs +18 -11
- package/dist/next.d.cts +2 -0
- package/dist/next.d.ts +2 -0
- package/dist/next.js +13 -6
- package/dist/server.cjs +22 -22
- package/dist/server.d.cts +7 -0
- package/dist/server.d.ts +7 -0
- package/dist/server.js +3 -3
- package/package.json +2 -2
|
@@ -84,7 +84,7 @@ function pageOf(raw, initialData) {
|
|
|
84
84
|
meta
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
|
-
async function staticDataFor(documents, registry, locale) {
|
|
87
|
+
async function staticDataFor(documents, registry, locale, currency) {
|
|
88
88
|
const bindings = /* @__PURE__ */ new Map();
|
|
89
89
|
for (const document of documents) {
|
|
90
90
|
for (const [key, binding] of collectBindings(document, registry)) bindings.set(key, binding);
|
|
@@ -93,7 +93,7 @@ async function staticDataFor(documents, registry, locale) {
|
|
|
93
93
|
return resolveBindings(
|
|
94
94
|
bindings,
|
|
95
95
|
registry,
|
|
96
|
-
{ locale, preview: false, signal: new AbortController().signal },
|
|
96
|
+
{ locale, ...currency === void 0 ? {} : { currency }, preview: false, signal: new AbortController().signal },
|
|
97
97
|
{ include: "static" }
|
|
98
98
|
);
|
|
99
99
|
}
|
|
@@ -1231,6 +1231,13 @@ function prepare(field, value, ctx) {
|
|
|
1231
1231
|
}
|
|
1232
1232
|
return value;
|
|
1233
1233
|
}
|
|
1234
|
+
function storedLinkPart(value) {
|
|
1235
|
+
if (!isRecord2(value) || value.kind !== "page") return value;
|
|
1236
|
+
const { slug: _slug, href: _href, ...stored } = value;
|
|
1237
|
+
void _slug;
|
|
1238
|
+
void _href;
|
|
1239
|
+
return stored;
|
|
1240
|
+
}
|
|
1234
1241
|
function settingsAt(node, fields, device, ctx) {
|
|
1235
1242
|
const base = {};
|
|
1236
1243
|
for (const field of fields.values()) base[field.key] = field.default;
|
|
@@ -1239,7 +1246,8 @@ function settingsAt(node, fields, device, ctx) {
|
|
|
1239
1246
|
for (const [key, value] of Object.entries(resolved)) {
|
|
1240
1247
|
const field = fields.get(key);
|
|
1241
1248
|
const freeText = field?.control === "text" || field?.control === "richtext";
|
|
1242
|
-
const
|
|
1249
|
+
const checked = field?.control === "link" ? storedLinkPart(value) : value;
|
|
1250
|
+
const usable = field === void 0 || (freeText ? value !== null : validateSettingValue2(field, checked) === null) ? value : field.default;
|
|
1243
1251
|
out[key] = prepare(field, usable, ctx);
|
|
1244
1252
|
}
|
|
1245
1253
|
return out;
|
|
@@ -1360,11 +1368,16 @@ function BuilderRenderer(props) {
|
|
|
1360
1368
|
] });
|
|
1361
1369
|
}
|
|
1362
1370
|
|
|
1371
|
+
// src/context.ts
|
|
1372
|
+
import { createContext, useContext } from "react";
|
|
1373
|
+
var BuilderContext = typeof createContext === "function" ? createContext(null) : null;
|
|
1374
|
+
var useBuilder = () => useContext(BuilderContext);
|
|
1375
|
+
|
|
1363
1376
|
// src/part-view.tsx
|
|
1364
1377
|
import { jsx as jsx18 } from "react/jsx-runtime";
|
|
1365
1378
|
var BoundaryBase = Component ?? class {
|
|
1366
1379
|
};
|
|
1367
|
-
var
|
|
1380
|
+
var Boundary = class extends BoundaryBase {
|
|
1368
1381
|
constructor() {
|
|
1369
1382
|
super(...arguments);
|
|
1370
1383
|
__publicField(this, "state", { failed: false });
|
|
@@ -1374,11 +1387,27 @@ var PartBoundary = class extends BoundaryBase {
|
|
|
1374
1387
|
}
|
|
1375
1388
|
componentDidCatch(error, _info) {
|
|
1376
1389
|
warnOnce(`part:${this.props.label}`, `${this.props.label} failed to render (${String(error)}); rendering nothing for it`);
|
|
1390
|
+
try {
|
|
1391
|
+
this.props.onError?.(error, { part: this.props.label });
|
|
1392
|
+
} catch {
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
componentDidUpdate(previous) {
|
|
1396
|
+
const moved = previous.resetKeys.length !== this.props.resetKeys.length || previous.resetKeys.some((key, i) => !Object.is(key, this.props.resetKeys[i]));
|
|
1397
|
+
if (moved && this.state.failed) this.setState({ failed: false });
|
|
1377
1398
|
}
|
|
1378
1399
|
render() {
|
|
1379
1400
|
return this.state.failed ? null : this.props.children;
|
|
1380
1401
|
}
|
|
1381
1402
|
};
|
|
1403
|
+
function PartBoundary({
|
|
1404
|
+
label,
|
|
1405
|
+
resetKey,
|
|
1406
|
+
children
|
|
1407
|
+
}) {
|
|
1408
|
+
const builder = useBuilder();
|
|
1409
|
+
return /* @__PURE__ */ jsx18(Boundary, { label, resetKeys: [builder?.site, resetKey], onError: builder?.onError, children });
|
|
1410
|
+
}
|
|
1382
1411
|
|
|
1383
1412
|
// src/custom/template-widget.tsx
|
|
1384
1413
|
import { Suspense } from "react";
|
|
@@ -1918,12 +1947,12 @@ function createRendererRegistry(packs, options = {}) {
|
|
|
1918
1947
|
// src/server/load-page.ts
|
|
1919
1948
|
import { BuilderNotFoundError } from "@usethrottle/builder";
|
|
1920
1949
|
async function loadBuilderPage(options) {
|
|
1921
|
-
const { slug, locale, packs = [], slots } = options;
|
|
1950
|
+
const { slug, locale, packs = [], slots, currency } = options;
|
|
1922
1951
|
const bundle = await getBundle({ client: clientOf(options), locale, page: slug, slots });
|
|
1923
1952
|
const found = bundle.page;
|
|
1924
1953
|
if (found === void 0) throw new BuilderNotFoundError(slug);
|
|
1925
1954
|
if (isRedirect(found)) return { kind: "redirect", redirectTo: found.redirectTo };
|
|
1926
|
-
const data = await staticDataFor([found.document], createRendererRegistry(packs), locale);
|
|
1955
|
+
const data = await staticDataFor([found.document], createRendererRegistry(packs), locale, currency);
|
|
1927
1956
|
return pageOf(found, data);
|
|
1928
1957
|
}
|
|
1929
1958
|
|
|
@@ -84,7 +84,7 @@ function pageOf(raw, initialData) {
|
|
|
84
84
|
meta
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
|
-
async function staticDataFor(documents, registry, locale) {
|
|
87
|
+
async function staticDataFor(documents, registry, locale, currency) {
|
|
88
88
|
const bindings = /* @__PURE__ */ new Map();
|
|
89
89
|
for (const document of documents) {
|
|
90
90
|
for (const [key, binding] of collectBindings(document, registry)) bindings.set(key, binding);
|
|
@@ -93,7 +93,7 @@ async function staticDataFor(documents, registry, locale) {
|
|
|
93
93
|
return resolveBindings(
|
|
94
94
|
bindings,
|
|
95
95
|
registry,
|
|
96
|
-
{ locale, preview: false, signal: new AbortController().signal },
|
|
96
|
+
{ locale, ...currency === void 0 ? {} : { currency }, preview: false, signal: new AbortController().signal },
|
|
97
97
|
{ include: "static" }
|
|
98
98
|
);
|
|
99
99
|
}
|
|
@@ -1231,6 +1231,13 @@ function prepare(field, value, ctx) {
|
|
|
1231
1231
|
}
|
|
1232
1232
|
return value;
|
|
1233
1233
|
}
|
|
1234
|
+
function storedLinkPart(value) {
|
|
1235
|
+
if (!isRecord2(value) || value.kind !== "page") return value;
|
|
1236
|
+
const { slug: _slug, href: _href, ...stored } = value;
|
|
1237
|
+
void _slug;
|
|
1238
|
+
void _href;
|
|
1239
|
+
return stored;
|
|
1240
|
+
}
|
|
1234
1241
|
function settingsAt(node, fields, device, ctx) {
|
|
1235
1242
|
const base = {};
|
|
1236
1243
|
for (const field of fields.values()) base[field.key] = field.default;
|
|
@@ -1239,7 +1246,8 @@ function settingsAt(node, fields, device, ctx) {
|
|
|
1239
1246
|
for (const [key, value] of Object.entries(resolved)) {
|
|
1240
1247
|
const field = fields.get(key);
|
|
1241
1248
|
const freeText = _optionalChain([field, 'optionalAccess', _44 => _44.control]) === "text" || _optionalChain([field, 'optionalAccess', _45 => _45.control]) === "richtext";
|
|
1242
|
-
const
|
|
1249
|
+
const checked = _optionalChain([field, 'optionalAccess', _46 => _46.control]) === "link" ? storedLinkPart(value) : value;
|
|
1250
|
+
const usable = field === void 0 || (freeText ? value !== null : _builderschema.validateSettingValue.call(void 0, field, checked) === null) ? value : field.default;
|
|
1243
1251
|
out[key] = prepare(field, usable, ctx);
|
|
1244
1252
|
}
|
|
1245
1253
|
return out;
|
|
@@ -1360,11 +1368,16 @@ function BuilderRenderer(props) {
|
|
|
1360
1368
|
] });
|
|
1361
1369
|
}
|
|
1362
1370
|
|
|
1371
|
+
// src/context.ts
|
|
1372
|
+
|
|
1373
|
+
var BuilderContext = typeof _react.createContext === "function" ? _react.createContext.call(void 0, null) : null;
|
|
1374
|
+
var useBuilder = () => _react.useContext.call(void 0, BuilderContext);
|
|
1375
|
+
|
|
1363
1376
|
// src/part-view.tsx
|
|
1364
1377
|
|
|
1365
1378
|
var BoundaryBase = _nullishCoalesce(_react.Component, () => ( class {
|
|
1366
1379
|
}));
|
|
1367
|
-
var
|
|
1380
|
+
var Boundary = class extends BoundaryBase {
|
|
1368
1381
|
constructor() {
|
|
1369
1382
|
super(...arguments);
|
|
1370
1383
|
__publicField(this, "state", { failed: false });
|
|
@@ -1374,11 +1387,27 @@ var PartBoundary = class extends BoundaryBase {
|
|
|
1374
1387
|
}
|
|
1375
1388
|
componentDidCatch(error, _info) {
|
|
1376
1389
|
warnOnce(`part:${this.props.label}`, `${this.props.label} failed to render (${String(error)}); rendering nothing for it`);
|
|
1390
|
+
try {
|
|
1391
|
+
_optionalChain([this, 'access', _47 => _47.props, 'access', _48 => _48.onError, 'optionalCall', _49 => _49(error, { part: this.props.label })]);
|
|
1392
|
+
} catch (e5) {
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
componentDidUpdate(previous) {
|
|
1396
|
+
const moved = previous.resetKeys.length !== this.props.resetKeys.length || previous.resetKeys.some((key, i) => !Object.is(key, this.props.resetKeys[i]));
|
|
1397
|
+
if (moved && this.state.failed) this.setState({ failed: false });
|
|
1377
1398
|
}
|
|
1378
1399
|
render() {
|
|
1379
1400
|
return this.state.failed ? null : this.props.children;
|
|
1380
1401
|
}
|
|
1381
1402
|
};
|
|
1403
|
+
function PartBoundary({
|
|
1404
|
+
label,
|
|
1405
|
+
resetKey,
|
|
1406
|
+
children
|
|
1407
|
+
}) {
|
|
1408
|
+
const builder = useBuilder();
|
|
1409
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, Boundary, { label, resetKeys: [_optionalChain([builder, 'optionalAccess', _50 => _50.site]), resetKey], onError: _optionalChain([builder, 'optionalAccess', _51 => _51.onError]), children });
|
|
1410
|
+
}
|
|
1382
1411
|
|
|
1383
1412
|
// src/custom/template-widget.tsx
|
|
1384
1413
|
|
|
@@ -1491,7 +1520,7 @@ var ROLES = new Set(_builderschema.ALLOWED_ROLES);
|
|
|
1491
1520
|
function attrAllowed(tag, name) {
|
|
1492
1521
|
if (_builderschema.DATA_ATTR_RE.test(name)) return !name.startsWith(_builderschema.RESERVED_DATA_PREFIX);
|
|
1493
1522
|
const own = Object.hasOwn(_builderschema.ALLOWED_ATTRS, tag) ? _builderschema.ALLOWED_ATTRS[tag] : void 0;
|
|
1494
|
-
return (_nullishCoalesce(_optionalChain([_builderschema.ALLOWED_ATTRS, 'access',
|
|
1523
|
+
return (_nullishCoalesce(_optionalChain([_builderschema.ALLOWED_ATTRS, 'access', _52 => _52["*"], 'optionalAccess', _53 => _53.includes, 'call', _54 => _54(name)]), () => ( false))) || (_nullishCoalesce(_optionalChain([own, 'optionalAccess', _55 => _55.includes, 'call', _56 => _56(name)]), () => ( false)));
|
|
1495
1524
|
}
|
|
1496
1525
|
function attrText(attr, env, scope) {
|
|
1497
1526
|
return attr.value.map((part) => part.type === "text" ? part.value : filtered(lookup(part.path, env, scope), part.filters)).join("");
|
|
@@ -1614,14 +1643,14 @@ function compile(snapshot, registry) {
|
|
|
1614
1643
|
const source = snapshot.template;
|
|
1615
1644
|
if (typeof source !== "string") return refuse("no template source");
|
|
1616
1645
|
const parsed = _builderschema.parseTemplate.call(void 0, source);
|
|
1617
|
-
if (!parsed.ok) return refuse(`template does not parse: ${_nullishCoalesce(_optionalChain([parsed, 'access',
|
|
1646
|
+
if (!parsed.ok) return refuse(`template does not parse: ${_nullishCoalesce(_optionalChain([parsed, 'access', _57 => _57.issues, 'access', _58 => _58[0], 'optionalAccess', _59 => _59.message]), () => ( "invalid"))}`);
|
|
1618
1647
|
const data = snapshot.data;
|
|
1619
1648
|
const issues = _builderschema.validateTemplate.call(void 0, parsed.ast, {
|
|
1620
1649
|
settings: snapshot.settings,
|
|
1621
1650
|
data: typeof data === "object" && data !== null ? data : {},
|
|
1622
1651
|
sources: registry.sources()
|
|
1623
1652
|
});
|
|
1624
|
-
if (issues.length > 0) return refuse(`template does not validate: ${_nullishCoalesce(_optionalChain([issues, 'access',
|
|
1653
|
+
if (issues.length > 0) return refuse(`template does not validate: ${_nullishCoalesce(_optionalChain([issues, 'access', _60 => _60[0], 'optionalAccess', _61 => _61.message]), () => ( "invalid"))}`);
|
|
1625
1654
|
if (!fitsBudget(parsed.ast)) return refuse(`it can render more than ${String(_builderschema.MAX_TEMPLATE_WEIGHT)} nodes`);
|
|
1626
1655
|
const css = scopedCss(snapshot.css, snapshot.type);
|
|
1627
1656
|
if (css === null) return refuse("its css does not pass the sanitiser");
|
|
@@ -1653,16 +1682,16 @@ function parseBody(raw) {
|
|
|
1653
1682
|
const stack = Array.isArray(raw.stack) ? raw.stack : void 0;
|
|
1654
1683
|
if (columns === void 0 === (stack === void 0)) return null;
|
|
1655
1684
|
const children = columns !== void 0 ? [{ id: WRAP.inner, type: "inner-section", props: {}, columns }] : _nullishCoalesce(stack, () => ( []));
|
|
1656
|
-
if (_optionalChain([stack, 'optionalAccess',
|
|
1685
|
+
if (_optionalChain([stack, 'optionalAccess', _62 => _62.some, 'call', _63 => _63((node) => isRecord3(node) && node.type === "inner-section")])) return null;
|
|
1657
1686
|
const parsed = _builderschema.pageDocumentSchema.safeParse({
|
|
1658
1687
|
schemaVersion: 1,
|
|
1659
1688
|
sections: [{ id: WRAP.section, type: "section", props: {}, columns: [{ id: WRAP.column, type: "column", props: { width: 100 }, children }] }]
|
|
1660
1689
|
});
|
|
1661
1690
|
if (!parsed.success) return null;
|
|
1662
|
-
const first = _nullishCoalesce(_optionalChain([parsed, 'access',
|
|
1691
|
+
const first = _nullishCoalesce(_optionalChain([parsed, 'access', _64 => _64.data, 'access', _65 => _65.sections, 'access', _66 => _66[0], 'optionalAccess', _67 => _67.columns, 'access', _68 => _68[0], 'optionalAccess', _69 => _69.children]), () => ( []));
|
|
1663
1692
|
if (columns !== void 0) {
|
|
1664
1693
|
const inner = first[0];
|
|
1665
|
-
return _optionalChain([inner, 'optionalAccess',
|
|
1694
|
+
return _optionalChain([inner, 'optionalAccess', _70 => _70.type]) === "inner-section" ? { columns: inner.columns } : null;
|
|
1666
1695
|
}
|
|
1667
1696
|
return { stack: first.filter((node) => node.type !== "inner-section") };
|
|
1668
1697
|
}
|
|
@@ -1716,7 +1745,7 @@ var DEVICES3 = ["tablet", "phone"];
|
|
|
1716
1745
|
function withoutAnchor(node) {
|
|
1717
1746
|
delete node.props.anchor;
|
|
1718
1747
|
const responsive = node.responsive;
|
|
1719
|
-
for (const device of DEVICES3) if (_optionalChain([responsive, 'optionalAccess',
|
|
1748
|
+
for (const device of DEVICES3) if (_optionalChain([responsive, 'optionalAccess', _71 => _71[device]]) !== void 0) delete responsive[device].anchor;
|
|
1720
1749
|
}
|
|
1721
1750
|
function instanceId(outer, inner) {
|
|
1722
1751
|
let a = 3735928559;
|
|
@@ -1736,9 +1765,9 @@ function build(input) {
|
|
|
1736
1765
|
const assets = {};
|
|
1737
1766
|
const hrefs = /* @__PURE__ */ new Map();
|
|
1738
1767
|
const innerData = {};
|
|
1739
|
-
const keep = (child) => _optionalChain([registry, 'access',
|
|
1740
|
-
const columns = _optionalChain([body, 'access',
|
|
1741
|
-
const stack = _optionalChain([body, 'access',
|
|
1768
|
+
const keep = (child) => _optionalChain([registry, 'access', _72 => _72.widget, 'call', _73 => _73(child.type, child.v), 'optionalAccess', _74 => _74.kind]) !== "composite";
|
|
1769
|
+
const columns = _optionalChain([body, 'access', _75 => _75.columns, 'optionalAccess', _76 => _76.map, 'call', _77 => _77((column2) => ({ ...column2, children: column2.children.filter(keep) }))]);
|
|
1770
|
+
const stack = _optionalChain([body, 'access', _78 => _78.stack, 'optionalAccess', _79 => _79.filter, 'call', _80 => _80(keep)]);
|
|
1742
1771
|
const widgets2 = columns !== void 0 ? columns.flatMap((column2) => column2.children) : _nullishCoalesce(stack, () => ( []));
|
|
1743
1772
|
for (const widget of widgets2) {
|
|
1744
1773
|
withoutAnchor(widget);
|
|
@@ -1773,15 +1802,15 @@ function build(input) {
|
|
|
1773
1802
|
const value = props[binding.setting];
|
|
1774
1803
|
for (const target of binding.targets) {
|
|
1775
1804
|
const inner = byId.get(target.node);
|
|
1776
|
-
const innerField = inner === void 0 ? void 0 : _optionalChain([registry, 'access',
|
|
1805
|
+
const innerField = inner === void 0 ? void 0 : _optionalChain([registry, 'access', _81 => _81.widget, 'call', _82 => _82(inner.type, inner.v), 'optionalAccess', _83 => _83.settings, 'access', _84 => _84.find, 'call', _85 => _85((f) => f.key === target.prop)]);
|
|
1777
1806
|
if (inner === void 0 || innerField === void 0 || innerField.control !== field.control) continue;
|
|
1778
1807
|
const converted = convert(field, value);
|
|
1779
1808
|
if (_builderschema.validateSettingValue.call(void 0, innerField, converted) !== null) continue;
|
|
1780
1809
|
inner.props[target.prop] = converted;
|
|
1781
1810
|
const responsive = inner.responsive;
|
|
1782
1811
|
for (const device of DEVICES3) {
|
|
1783
|
-
if (_optionalChain([responsive, 'optionalAccess',
|
|
1784
|
-
const raw = _optionalChain([outer, 'access',
|
|
1812
|
+
if (_optionalChain([responsive, 'optionalAccess', _86 => _86[device]]) !== void 0) delete responsive[device][target.prop];
|
|
1813
|
+
const raw = _optionalChain([outer, 'access', _87 => _87.responsive, 'optionalAccess', _88 => _88[device]]);
|
|
1785
1814
|
const plain = field.output === "css" && field.translatable !== true && field.control !== "image" && field.control !== "link";
|
|
1786
1815
|
if (plain && raw !== void 0 && Object.hasOwn(raw, binding.setting) && _builderschema.validateSettingValue.call(void 0, innerField, raw[binding.setting]) === null) {
|
|
1787
1816
|
const target$ = _nullishCoalesce(inner.responsive, () => ( (inner.responsive = {})));
|
|
@@ -1796,7 +1825,7 @@ function build(input) {
|
|
|
1796
1825
|
for (const target of input$.targets) {
|
|
1797
1826
|
const inner = byId.get(target.node);
|
|
1798
1827
|
const def = inner === void 0 ? void 0 : registry.widget(inner.type, inner.v);
|
|
1799
|
-
if (inner === void 0 || _optionalChain([def, 'optionalAccess',
|
|
1828
|
+
if (inner === void 0 || _optionalChain([def, 'optionalAccess', _89 => _89.data]) === void 0 || !Object.hasOwn(def.data, target.input)) continue;
|
|
1800
1829
|
inner.data = { ..._nullishCoalesce(inner.data, () => ( {})), [target.input]: { source: key } };
|
|
1801
1830
|
innerData[key] = data[name];
|
|
1802
1831
|
}
|
|
@@ -1814,7 +1843,7 @@ function build(input) {
|
|
|
1814
1843
|
schemaVersion: 1,
|
|
1815
1844
|
sections: [{ id: ids.section, type: "section", props: { width: "full" }, columns: [column] }]
|
|
1816
1845
|
};
|
|
1817
|
-
let weight = 2 + (_nullishCoalesce(_optionalChain([columns, 'optionalAccess',
|
|
1846
|
+
let weight = 2 + (_nullishCoalesce(_optionalChain([columns, 'optionalAccess', _90 => _90.length]), () => ( 0))) + (columns === void 0 ? 0 : 1);
|
|
1818
1847
|
for (const widget of widgets2) {
|
|
1819
1848
|
const component = registry.component(widget);
|
|
1820
1849
|
weight += 1 + (component === void 0 ? 0 : _nullishCoalesce(componentWeights.get(component), () => ( 0)));
|
|
@@ -1839,7 +1868,7 @@ function CompositeBody(props) {
|
|
|
1839
1868
|
locale,
|
|
1840
1869
|
assets: built.assets,
|
|
1841
1870
|
mediaOrigin,
|
|
1842
|
-
resolveLink: (target) => _nullishCoalesce(_nullishCoalesce(built.hrefs.get(JSON.stringify(target)), () => ( _optionalChain([resolveLink, 'optionalCall',
|
|
1871
|
+
resolveLink: (target) => _nullishCoalesce(_nullishCoalesce(built.hrefs.get(JSON.stringify(target)), () => ( _optionalChain([resolveLink, 'optionalCall', _91 => _91(target)]))), () => ( null))
|
|
1843
1872
|
}
|
|
1844
1873
|
);
|
|
1845
1874
|
}
|
|
@@ -1918,12 +1947,12 @@ function createRendererRegistry(packs, options = {}) {
|
|
|
1918
1947
|
// src/server/load-page.ts
|
|
1919
1948
|
|
|
1920
1949
|
async function loadBuilderPage(options) {
|
|
1921
|
-
const { slug, locale, packs = [], slots } = options;
|
|
1950
|
+
const { slug, locale, packs = [], slots, currency } = options;
|
|
1922
1951
|
const bundle = await getBundle({ client: clientOf(options), locale, page: slug, slots });
|
|
1923
1952
|
const found = bundle.page;
|
|
1924
1953
|
if (found === void 0) throw new (0, _builder.BuilderNotFoundError)(slug);
|
|
1925
1954
|
if (isRedirect(found)) return { kind: "redirect", redirectTo: found.redirectTo };
|
|
1926
|
-
const data = await staticDataFor([found.document], createRendererRegistry(packs), locale);
|
|
1955
|
+
const data = await staticDataFor([found.document], createRendererRegistry(packs), locale, currency);
|
|
1927
1956
|
return pageOf(found, data);
|
|
1928
1957
|
}
|
|
1929
1958
|
|
|
@@ -1964,7 +1993,7 @@ function pagePathOf(settings, page, resolve) {
|
|
|
1964
1993
|
return _nullishCoalesce(_builderschema.safeUrl.call(void 0, resolve({ ...page, path }), "href", { mediaOrigin: "" }), () => ( path));
|
|
1965
1994
|
}
|
|
1966
1995
|
function originOf(storeUrl) {
|
|
1967
|
-
const origin = _optionalChain([storeUrl, 'optionalAccess',
|
|
1996
|
+
const origin = _optionalChain([storeUrl, 'optionalAccess', _92 => _92.replace, 'call', _93 => _93(/\/+$/u, "")]);
|
|
1968
1997
|
return origin !== void 0 && ORIGIN_RE.test(origin) ? origin : void 0;
|
|
1969
1998
|
}
|
|
1970
1999
|
function siteLocales(settings) {
|
package/dist/index.cjs
CHANGED
|
@@ -492,6 +492,13 @@ function prepare(field, value, ctx) {
|
|
|
492
492
|
}
|
|
493
493
|
return value;
|
|
494
494
|
}
|
|
495
|
+
function storedLinkPart(value) {
|
|
496
|
+
if (!isRecord(value) || value.kind !== "page") return value;
|
|
497
|
+
const { slug: _slug, href: _href, ...stored } = value;
|
|
498
|
+
void _slug;
|
|
499
|
+
void _href;
|
|
500
|
+
return stored;
|
|
501
|
+
}
|
|
495
502
|
function settingsAt(node, fields, device, ctx) {
|
|
496
503
|
const base = {};
|
|
497
504
|
for (const field of fields.values()) base[field.key] = field.default;
|
|
@@ -500,7 +507,8 @@ function settingsAt(node, fields, device, ctx) {
|
|
|
500
507
|
for (const [key, value] of Object.entries(resolved)) {
|
|
501
508
|
const field = fields.get(key);
|
|
502
509
|
const freeText = field?.control === "text" || field?.control === "richtext";
|
|
503
|
-
const
|
|
510
|
+
const checked = field?.control === "link" ? storedLinkPart(value) : value;
|
|
511
|
+
const usable = field === void 0 || (freeText ? value !== null : (0, import_builder_schema5.validateSettingValue)(field, checked) === null) ? value : field.default;
|
|
504
512
|
out[key] = prepare(field, usable, ctx);
|
|
505
513
|
}
|
|
506
514
|
return out;
|
|
@@ -676,7 +684,7 @@ var import_ui6 = require("@usethrottle/ui");
|
|
|
676
684
|
|
|
677
685
|
// src/context.ts
|
|
678
686
|
var import_react2 = require("react");
|
|
679
|
-
var BuilderContext = (0, import_react2.createContext)(null);
|
|
687
|
+
var BuilderContext = typeof import_react2.createContext === "function" ? (0, import_react2.createContext)(null) : null;
|
|
680
688
|
var useBuilder = () => (0, import_react2.useContext)(BuilderContext);
|
|
681
689
|
|
|
682
690
|
// src/page.tsx
|
|
@@ -825,7 +833,7 @@ var import_react5 = require("react");
|
|
|
825
833
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
826
834
|
var BoundaryBase = import_react5.Component ?? class {
|
|
827
835
|
};
|
|
828
|
-
var
|
|
836
|
+
var Boundary = class extends BoundaryBase {
|
|
829
837
|
constructor() {
|
|
830
838
|
super(...arguments);
|
|
831
839
|
__publicField(this, "state", { failed: false });
|
|
@@ -835,11 +843,27 @@ var PartBoundary = class extends BoundaryBase {
|
|
|
835
843
|
}
|
|
836
844
|
componentDidCatch(error, _info) {
|
|
837
845
|
warnOnce(`part:${this.props.label}`, `${this.props.label} failed to render (${String(error)}); rendering nothing for it`);
|
|
846
|
+
try {
|
|
847
|
+
this.props.onError?.(error, { part: this.props.label });
|
|
848
|
+
} catch {
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
componentDidUpdate(previous) {
|
|
852
|
+
const moved = previous.resetKeys.length !== this.props.resetKeys.length || previous.resetKeys.some((key, i) => !Object.is(key, this.props.resetKeys[i]));
|
|
853
|
+
if (moved && this.state.failed) this.setState({ failed: false });
|
|
838
854
|
}
|
|
839
855
|
render() {
|
|
840
856
|
return this.state.failed ? null : this.props.children;
|
|
841
857
|
}
|
|
842
858
|
};
|
|
859
|
+
function PartBoundary({
|
|
860
|
+
label,
|
|
861
|
+
resetKey,
|
|
862
|
+
children
|
|
863
|
+
}) {
|
|
864
|
+
const builder = useBuilder();
|
|
865
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Boundary, { label, resetKeys: [builder?.site, resetKey], onError: builder?.onError, children });
|
|
866
|
+
}
|
|
843
867
|
function contextData(context) {
|
|
844
868
|
if (typeof context !== "object" || context === null) return {};
|
|
845
869
|
return Object.fromEntries(Object.entries(context).map(([key, value]) => [`context.${key}`, value]));
|
|
@@ -2051,6 +2075,14 @@ function createRendererRegistry(packs, options = {}) {
|
|
|
2051
2075
|
// src/slot.tsx
|
|
2052
2076
|
var import_react14 = require("react");
|
|
2053
2077
|
var import_jsx_runtime24 = require("react/jsx-runtime");
|
|
2078
|
+
function contextKey(context) {
|
|
2079
|
+
if (typeof context !== "object" || context === null) return "";
|
|
2080
|
+
return Object.values(context).map((value) => {
|
|
2081
|
+
const record = typeof value === "object" && value !== null ? value : {};
|
|
2082
|
+
const id = record["id"] ?? record["handle"] ?? record["slug"];
|
|
2083
|
+
return typeof id === "string" || typeof id === "number" ? String(id) : "";
|
|
2084
|
+
}).join("|");
|
|
2085
|
+
}
|
|
2054
2086
|
function BuilderSlot({ name, context }) {
|
|
2055
2087
|
const builder = useBuilder();
|
|
2056
2088
|
if (builder === null || builder.site.status !== "ok") return null;
|
|
@@ -2058,7 +2090,7 @@ function BuilderSlot({ name, context }) {
|
|
|
2058
2090
|
if (part === void 0 || part.document.sections.length === 0) return null;
|
|
2059
2091
|
return (
|
|
2060
2092
|
// Suspense inside the boundary: see parts.tsx.
|
|
2061
|
-
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(PartBoundary, { label: `Builder slot ${name}`, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { "data-throttle-part": "builder-slot", "data-b-slot": name, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_react14.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(PartView, { part, context }) }) }) })
|
|
2093
|
+
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(PartBoundary, { label: `Builder slot ${name}`, resetKey: contextKey(context), children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)("div", { "data-throttle-part": "builder-slot", "data-b-slot": name, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(import_react14.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(PartView, { part, context }) }) }) })
|
|
2062
2094
|
);
|
|
2063
2095
|
}
|
|
2064
2096
|
|
|
@@ -2248,7 +2280,7 @@ var EMPTY = {};
|
|
|
2248
2280
|
function useParentFont() {
|
|
2249
2281
|
return (0, import_react15.useContext)(import_ui6.AppearanceContext)?.variables?.fontFamily;
|
|
2250
2282
|
}
|
|
2251
|
-
function BuilderProvider({ builderKey, client, packs, site, children }) {
|
|
2283
|
+
function BuilderProvider({ builderKey, client, packs, site, onError, children }) {
|
|
2252
2284
|
const packsKey = packs.map((pack) => `${pack.id}@${pack.version}`).join("|");
|
|
2253
2285
|
const registryRef = (0, import_react15.useRef)(null);
|
|
2254
2286
|
if (registryRef.current?.key !== packsKey) {
|
|
@@ -2290,8 +2322,8 @@ function BuilderProvider({ builderKey, client, packs, site, children }) {
|
|
|
2290
2322
|
[site]
|
|
2291
2323
|
);
|
|
2292
2324
|
const value = (0, import_react15.useMemo)(
|
|
2293
|
-
() => ({ client: builder, packs, registry, site, locale: site.locale, mediaOrigin, resolveLink }),
|
|
2294
|
-
[builder, packs, registry, site, mediaOrigin, resolveLink]
|
|
2325
|
+
() => ({ client: builder, packs, registry, site, locale: site.locale, mediaOrigin, onError, resolveLink }),
|
|
2326
|
+
[builder, packs, registry, site, mediaOrigin, onError, resolveLink]
|
|
2295
2327
|
);
|
|
2296
2328
|
const design = (0, import_react15.useMemo)(
|
|
2297
2329
|
() => site.status === "ok" ? siteDesignOf(site.settings, resolveLink, pageOutlet, mediaOrigin) : null,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ReactNode, ComponentType, CSSProperties } from 'react';
|
|
1
|
+
import { ReactNode, ComponentType, CSSProperties, Context } from 'react';
|
|
3
2
|
import { TemplateAst, WidgetNode, SettingValue, WidgetDefinition, DataSourceDescriptor, PageDocument, FrozenAsset, WidgetRegistry, CustomWidgetSnapshot, SettingField, DataBinding } from '@usethrottle/builder-schema';
|
|
4
3
|
import { BuilderClient } from '@usethrottle/builder';
|
|
5
4
|
export { BuilderNotFoundError, BuilderUnavailableError } from '@usethrottle/builder';
|
|
@@ -301,6 +300,10 @@ type BuilderProviderProps = {
|
|
|
301
300
|
packs: readonly WidgetPack[];
|
|
302
301
|
/** What `loadSite()` read on the server. */
|
|
303
302
|
site: LoadedSite;
|
|
303
|
+
/** Called when a part, slot or page fails to render (it then renders nothing): send it to your error monitoring. `info.part` names it. */
|
|
304
|
+
onError?: (error: unknown, info: {
|
|
305
|
+
part: string;
|
|
306
|
+
}) => void;
|
|
304
307
|
children: ReactNode;
|
|
305
308
|
};
|
|
306
309
|
/**
|
|
@@ -317,7 +320,7 @@ type BuilderProviderProps = {
|
|
|
317
320
|
* With a site the Builder could not answer (`status: 'unavailable'`) it fills
|
|
318
321
|
* nothing, so the catalog's own design shows and every part renders nothing.
|
|
319
322
|
*/
|
|
320
|
-
declare function BuilderProvider({ builderKey, client, packs, site, children }: BuilderProviderProps): ReactNode;
|
|
323
|
+
declare function BuilderProvider({ builderKey, client, packs, site, onError, children }: BuilderProviderProps): ReactNode;
|
|
321
324
|
|
|
322
325
|
type BuilderContextValue = {
|
|
323
326
|
client: BuilderClient | null;
|
|
@@ -326,12 +329,20 @@ type BuilderContextValue = {
|
|
|
326
329
|
site: LoadedSite;
|
|
327
330
|
locale: string;
|
|
328
331
|
mediaOrigin: string;
|
|
332
|
+
onError?: ((error: unknown, info: {
|
|
333
|
+
part: string;
|
|
334
|
+
}) => void) | undefined;
|
|
329
335
|
resolveLink: (target: {
|
|
330
336
|
kind: string;
|
|
331
337
|
[key: string]: unknown;
|
|
332
338
|
}) => string | null;
|
|
333
339
|
};
|
|
334
|
-
|
|
340
|
+
/**
|
|
341
|
+
* `react` has no `createContext` in a React Server Components build, and the server entries share this module's chunk
|
|
342
|
+
* through `PartBoundary`. Nothing reads the context on the server (`useBuilder` runs only in client components), so
|
|
343
|
+
* evaluating this module there must not throw.
|
|
344
|
+
*/
|
|
345
|
+
declare const BuilderContext: Context<BuilderContextValue | null>;
|
|
335
346
|
/** The provider's value, or null outside a `BuilderProvider`. */
|
|
336
347
|
declare const useBuilder: () => BuilderContextValue | null;
|
|
337
348
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ReactNode, ComponentType, CSSProperties } from 'react';
|
|
1
|
+
import { ReactNode, ComponentType, CSSProperties, Context } from 'react';
|
|
3
2
|
import { TemplateAst, WidgetNode, SettingValue, WidgetDefinition, DataSourceDescriptor, PageDocument, FrozenAsset, WidgetRegistry, CustomWidgetSnapshot, SettingField, DataBinding } from '@usethrottle/builder-schema';
|
|
4
3
|
import { BuilderClient } from '@usethrottle/builder';
|
|
5
4
|
export { BuilderNotFoundError, BuilderUnavailableError } from '@usethrottle/builder';
|
|
@@ -301,6 +300,10 @@ type BuilderProviderProps = {
|
|
|
301
300
|
packs: readonly WidgetPack[];
|
|
302
301
|
/** What `loadSite()` read on the server. */
|
|
303
302
|
site: LoadedSite;
|
|
303
|
+
/** Called when a part, slot or page fails to render (it then renders nothing): send it to your error monitoring. `info.part` names it. */
|
|
304
|
+
onError?: (error: unknown, info: {
|
|
305
|
+
part: string;
|
|
306
|
+
}) => void;
|
|
304
307
|
children: ReactNode;
|
|
305
308
|
};
|
|
306
309
|
/**
|
|
@@ -317,7 +320,7 @@ type BuilderProviderProps = {
|
|
|
317
320
|
* With a site the Builder could not answer (`status: 'unavailable'`) it fills
|
|
318
321
|
* nothing, so the catalog's own design shows and every part renders nothing.
|
|
319
322
|
*/
|
|
320
|
-
declare function BuilderProvider({ builderKey, client, packs, site, children }: BuilderProviderProps): ReactNode;
|
|
323
|
+
declare function BuilderProvider({ builderKey, client, packs, site, onError, children }: BuilderProviderProps): ReactNode;
|
|
321
324
|
|
|
322
325
|
type BuilderContextValue = {
|
|
323
326
|
client: BuilderClient | null;
|
|
@@ -326,12 +329,20 @@ type BuilderContextValue = {
|
|
|
326
329
|
site: LoadedSite;
|
|
327
330
|
locale: string;
|
|
328
331
|
mediaOrigin: string;
|
|
332
|
+
onError?: ((error: unknown, info: {
|
|
333
|
+
part: string;
|
|
334
|
+
}) => void) | undefined;
|
|
329
335
|
resolveLink: (target: {
|
|
330
336
|
kind: string;
|
|
331
337
|
[key: string]: unknown;
|
|
332
338
|
}) => string | null;
|
|
333
339
|
};
|
|
334
|
-
|
|
340
|
+
/**
|
|
341
|
+
* `react` has no `createContext` in a React Server Components build, and the server entries share this module's chunk
|
|
342
|
+
* through `PartBoundary`. Nothing reads the context on the server (`useBuilder` runs only in client components), so
|
|
343
|
+
* evaluating this module there must not throw.
|
|
344
|
+
*/
|
|
345
|
+
declare const BuilderContext: Context<BuilderContextValue | null>;
|
|
335
346
|
/** The provider's value, or null outside a `BuilderProvider`. */
|
|
336
347
|
declare const useBuilder: () => BuilderContextValue | null;
|
|
337
348
|
|
package/dist/index.js
CHANGED
|
@@ -446,6 +446,13 @@ function prepare(field, value, ctx) {
|
|
|
446
446
|
}
|
|
447
447
|
return value;
|
|
448
448
|
}
|
|
449
|
+
function storedLinkPart(value) {
|
|
450
|
+
if (!isRecord(value) || value.kind !== "page") return value;
|
|
451
|
+
const { slug: _slug, href: _href, ...stored } = value;
|
|
452
|
+
void _slug;
|
|
453
|
+
void _href;
|
|
454
|
+
return stored;
|
|
455
|
+
}
|
|
449
456
|
function settingsAt(node, fields, device, ctx) {
|
|
450
457
|
const base = {};
|
|
451
458
|
for (const field of fields.values()) base[field.key] = field.default;
|
|
@@ -454,7 +461,8 @@ function settingsAt(node, fields, device, ctx) {
|
|
|
454
461
|
for (const [key, value] of Object.entries(resolved)) {
|
|
455
462
|
const field = fields.get(key);
|
|
456
463
|
const freeText = field?.control === "text" || field?.control === "richtext";
|
|
457
|
-
const
|
|
464
|
+
const checked = field?.control === "link" ? storedLinkPart(value) : value;
|
|
465
|
+
const usable = field === void 0 || (freeText ? value !== null : validateSettingValue2(field, checked) === null) ? value : field.default;
|
|
458
466
|
out[key] = prepare(field, usable, ctx);
|
|
459
467
|
}
|
|
460
468
|
return out;
|
|
@@ -630,7 +638,7 @@ import { AppearanceContext, SiteDesignProvider, SlotOutletProvider, ThrottleUIPr
|
|
|
630
638
|
|
|
631
639
|
// src/context.ts
|
|
632
640
|
import { createContext, useContext } from "react";
|
|
633
|
-
var BuilderContext = createContext(null);
|
|
641
|
+
var BuilderContext = typeof createContext === "function" ? createContext(null) : null;
|
|
634
642
|
var useBuilder = () => useContext(BuilderContext);
|
|
635
643
|
|
|
636
644
|
// src/page.tsx
|
|
@@ -779,7 +787,7 @@ import { Component } from "react";
|
|
|
779
787
|
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
780
788
|
var BoundaryBase = Component ?? class {
|
|
781
789
|
};
|
|
782
|
-
var
|
|
790
|
+
var Boundary = class extends BoundaryBase {
|
|
783
791
|
constructor() {
|
|
784
792
|
super(...arguments);
|
|
785
793
|
__publicField(this, "state", { failed: false });
|
|
@@ -789,11 +797,27 @@ var PartBoundary = class extends BoundaryBase {
|
|
|
789
797
|
}
|
|
790
798
|
componentDidCatch(error, _info) {
|
|
791
799
|
warnOnce(`part:${this.props.label}`, `${this.props.label} failed to render (${String(error)}); rendering nothing for it`);
|
|
800
|
+
try {
|
|
801
|
+
this.props.onError?.(error, { part: this.props.label });
|
|
802
|
+
} catch {
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
componentDidUpdate(previous) {
|
|
806
|
+
const moved = previous.resetKeys.length !== this.props.resetKeys.length || previous.resetKeys.some((key, i) => !Object.is(key, this.props.resetKeys[i]));
|
|
807
|
+
if (moved && this.state.failed) this.setState({ failed: false });
|
|
792
808
|
}
|
|
793
809
|
render() {
|
|
794
810
|
return this.state.failed ? null : this.props.children;
|
|
795
811
|
}
|
|
796
812
|
};
|
|
813
|
+
function PartBoundary({
|
|
814
|
+
label,
|
|
815
|
+
resetKey,
|
|
816
|
+
children
|
|
817
|
+
}) {
|
|
818
|
+
const builder = useBuilder();
|
|
819
|
+
return /* @__PURE__ */ jsx6(Boundary, { label, resetKeys: [builder?.site, resetKey], onError: builder?.onError, children });
|
|
820
|
+
}
|
|
797
821
|
function contextData(context) {
|
|
798
822
|
if (typeof context !== "object" || context === null) return {};
|
|
799
823
|
return Object.fromEntries(Object.entries(context).map(([key, value]) => [`context.${key}`, value]));
|
|
@@ -2016,6 +2040,14 @@ function createRendererRegistry(packs, options = {}) {
|
|
|
2016
2040
|
// src/slot.tsx
|
|
2017
2041
|
import { Suspense as Suspense3 } from "react";
|
|
2018
2042
|
import { jsx as jsx24 } from "react/jsx-runtime";
|
|
2043
|
+
function contextKey(context) {
|
|
2044
|
+
if (typeof context !== "object" || context === null) return "";
|
|
2045
|
+
return Object.values(context).map((value) => {
|
|
2046
|
+
const record = typeof value === "object" && value !== null ? value : {};
|
|
2047
|
+
const id = record["id"] ?? record["handle"] ?? record["slug"];
|
|
2048
|
+
return typeof id === "string" || typeof id === "number" ? String(id) : "";
|
|
2049
|
+
}).join("|");
|
|
2050
|
+
}
|
|
2019
2051
|
function BuilderSlot({ name, context }) {
|
|
2020
2052
|
const builder = useBuilder();
|
|
2021
2053
|
if (builder === null || builder.site.status !== "ok") return null;
|
|
@@ -2023,7 +2055,7 @@ function BuilderSlot({ name, context }) {
|
|
|
2023
2055
|
if (part === void 0 || part.document.sections.length === 0) return null;
|
|
2024
2056
|
return (
|
|
2025
2057
|
// Suspense inside the boundary: see parts.tsx.
|
|
2026
|
-
/* @__PURE__ */ jsx24(PartBoundary, { label: `Builder slot ${name}`, children: /* @__PURE__ */ jsx24("div", { "data-throttle-part": "builder-slot", "data-b-slot": name, children: /* @__PURE__ */ jsx24(Suspense3, { fallback: null, children: /* @__PURE__ */ jsx24(PartView, { part, context }) }) }) })
|
|
2058
|
+
/* @__PURE__ */ jsx24(PartBoundary, { label: `Builder slot ${name}`, resetKey: contextKey(context), children: /* @__PURE__ */ jsx24("div", { "data-throttle-part": "builder-slot", "data-b-slot": name, children: /* @__PURE__ */ jsx24(Suspense3, { fallback: null, children: /* @__PURE__ */ jsx24(PartView, { part, context }) }) }) })
|
|
2027
2059
|
);
|
|
2028
2060
|
}
|
|
2029
2061
|
|
|
@@ -2213,7 +2245,7 @@ var EMPTY = {};
|
|
|
2213
2245
|
function useParentFont() {
|
|
2214
2246
|
return useContext2(AppearanceContext)?.variables?.fontFamily;
|
|
2215
2247
|
}
|
|
2216
|
-
function BuilderProvider({ builderKey, client, packs, site, children }) {
|
|
2248
|
+
function BuilderProvider({ builderKey, client, packs, site, onError, children }) {
|
|
2217
2249
|
const packsKey = packs.map((pack) => `${pack.id}@${pack.version}`).join("|");
|
|
2218
2250
|
const registryRef = useRef2(null);
|
|
2219
2251
|
if (registryRef.current?.key !== packsKey) {
|
|
@@ -2255,8 +2287,8 @@ function BuilderProvider({ builderKey, client, packs, site, children }) {
|
|
|
2255
2287
|
[site]
|
|
2256
2288
|
);
|
|
2257
2289
|
const value = useMemo(
|
|
2258
|
-
() => ({ client: builder, packs, registry, site, locale: site.locale, mediaOrigin, resolveLink }),
|
|
2259
|
-
[builder, packs, registry, site, mediaOrigin, resolveLink]
|
|
2290
|
+
() => ({ client: builder, packs, registry, site, locale: site.locale, mediaOrigin, onError, resolveLink }),
|
|
2291
|
+
[builder, packs, registry, site, mediaOrigin, onError, resolveLink]
|
|
2260
2292
|
);
|
|
2261
2293
|
const design = useMemo(
|
|
2262
2294
|
() => site.status === "ok" ? siteDesignOf(site.settings, resolveLink, pageOutlet, mediaOrigin) : null,
|
package/dist/next.cjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
7
|
+
var _chunkZCXPIZU7cjs = require('./chunk-ZCXPIZU7.cjs');
|
|
8
8
|
|
|
9
9
|
// src/next/index.ts
|
|
10
10
|
var _react = require('react');
|
|
@@ -39,6 +39,10 @@ function slugOf(options, params) {
|
|
|
39
39
|
if (slug === void 0 || slug === "") _navigation.notFound.call(void 0, );
|
|
40
40
|
return slug;
|
|
41
41
|
}
|
|
42
|
+
async function currencyOf(options, params) {
|
|
43
|
+
return typeof options.currency === "function" ? options.currency(params) : options.currency;
|
|
44
|
+
}
|
|
45
|
+
var isNamed = (error, name) => typeof error === "object" && error !== null && error.name === name;
|
|
42
46
|
async function localeOf(options, params) {
|
|
43
47
|
if (typeof options.locale === "function") return options.locale(params);
|
|
44
48
|
if (options.locale !== void 0) return options.locale;
|
|
@@ -49,12 +53,15 @@ function createBuilderPage(options) {
|
|
|
49
53
|
async function Page(props) {
|
|
50
54
|
const params = await props.params;
|
|
51
55
|
const slug = slugOf(options, params);
|
|
52
|
-
const
|
|
53
|
-
|
|
56
|
+
const currency = await currencyOf(options, params);
|
|
57
|
+
const { currency: _currency, ...rest } = options;
|
|
58
|
+
const loaded = await _chunkZCXPIZU7cjs.loadBuilderPage.call(void 0, {
|
|
59
|
+
...rest,
|
|
54
60
|
slug,
|
|
55
|
-
locale: await localeOf(options, params)
|
|
61
|
+
locale: await localeOf(options, params),
|
|
62
|
+
...currency === void 0 ? {} : { currency }
|
|
56
63
|
}).catch((error) => {
|
|
57
|
-
if (error instanceof _builder.BuilderNotFoundError) _navigation.notFound.call(void 0, );
|
|
64
|
+
if (error instanceof _builder.BuilderNotFoundError || isNamed(error, "BuilderNotFoundError")) _navigation.notFound.call(void 0, );
|
|
58
65
|
throw error;
|
|
59
66
|
});
|
|
60
67
|
if (loaded.kind === "redirect") {
|
|
@@ -68,12 +75,12 @@ function createBuilderPage(options) {
|
|
|
68
75
|
const params = await props.params;
|
|
69
76
|
const slug = slugOf(options, params);
|
|
70
77
|
const locale = await localeOf(options, params);
|
|
71
|
-
const client =
|
|
78
|
+
const client = _chunkZCXPIZU7cjs.clientOf.call(void 0, options);
|
|
72
79
|
try {
|
|
73
|
-
const bundle = await
|
|
80
|
+
const bundle = await _chunkZCXPIZU7cjs.getBundle.call(void 0, { client, locale, page: slug, slots: options.slots });
|
|
74
81
|
const page = bundle.page;
|
|
75
|
-
if (page === void 0 ||
|
|
76
|
-
return
|
|
82
|
+
if (page === void 0 || _chunkZCXPIZU7cjs.isRedirect.call(void 0, page)) return {};
|
|
83
|
+
return _chunkZCXPIZU7cjs.metadataOf.call(void 0, page, {
|
|
77
84
|
settings: bundle.site.settings,
|
|
78
85
|
mediaOrigin: _nullishCoalesce(options.mediaOrigin, () => ( "")),
|
|
79
86
|
storeUrl: options.storeUrl,
|
|
@@ -81,8 +88,8 @@ function createBuilderPage(options) {
|
|
|
81
88
|
routeLocale: options.locale === void 0 && typeof params.locale === "string" ? params.locale : void 0
|
|
82
89
|
});
|
|
83
90
|
} catch (error) {
|
|
84
|
-
if (error instanceof _builder.BuilderNotFoundError) return {};
|
|
85
|
-
if (error instanceof _builder.BuilderUnavailableError && client.mode !== "build") return {};
|
|
91
|
+
if (error instanceof _builder.BuilderNotFoundError || isNamed(error, "BuilderNotFoundError")) return {};
|
|
92
|
+
if ((error instanceof _builder.BuilderUnavailableError || isNamed(error, "BuilderUnavailableError")) && client.mode !== "build") return {};
|
|
86
93
|
throw error;
|
|
87
94
|
}
|
|
88
95
|
}
|
package/dist/next.d.cts
CHANGED
|
@@ -13,6 +13,8 @@ type CreateBuilderPageOptions = ({
|
|
|
13
13
|
packs?: readonly WidgetPack[];
|
|
14
14
|
/** The locale of the page; by default `params.locale` when the route has one, else `en`. */
|
|
15
15
|
locale?: string | ((params: Params) => string | Promise<string>);
|
|
16
|
+
/** The shopper's currency (a value, or read from the route's params, e.g. from a cookie), as for `loadSite({ currency })`. */
|
|
17
|
+
currency?: string | ((params: Params) => string | undefined | Promise<string | undefined>);
|
|
16
18
|
/** The slots the layout reads, so the page read can share the layout's. */
|
|
17
19
|
slots?: readonly string[];
|
|
18
20
|
/** The store's origin (`https://shop.example.com`), for the canonical link. The Builder does not publish it, so without it a page has no canonical. */
|
package/dist/next.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ type CreateBuilderPageOptions = ({
|
|
|
13
13
|
packs?: readonly WidgetPack[];
|
|
14
14
|
/** The locale of the page; by default `params.locale` when the route has one, else `en`. */
|
|
15
15
|
locale?: string | ((params: Params) => string | Promise<string>);
|
|
16
|
+
/** The shopper's currency (a value, or read from the route's params, e.g. from a cookie), as for `loadSite({ currency })`. */
|
|
17
|
+
currency?: string | ((params: Params) => string | undefined | Promise<string | undefined>);
|
|
16
18
|
/** The slots the layout reads, so the page read can share the layout's. */
|
|
17
19
|
slots?: readonly string[];
|
|
18
20
|
/** The store's origin (`https://shop.example.com`), for the canonical link. The Builder does not publish it, so without it a page has no canonical. */
|
package/dist/next.js
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
isRedirect,
|
|
5
5
|
loadBuilderPage,
|
|
6
6
|
metadataOf
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-65KZ5CIP.js";
|
|
8
8
|
|
|
9
9
|
// src/next/index.ts
|
|
10
10
|
import { createElement } from "react";
|
|
@@ -39,6 +39,10 @@ function slugOf(options, params) {
|
|
|
39
39
|
if (slug === void 0 || slug === "") notFound();
|
|
40
40
|
return slug;
|
|
41
41
|
}
|
|
42
|
+
async function currencyOf(options, params) {
|
|
43
|
+
return typeof options.currency === "function" ? options.currency(params) : options.currency;
|
|
44
|
+
}
|
|
45
|
+
var isNamed = (error, name) => typeof error === "object" && error !== null && error.name === name;
|
|
42
46
|
async function localeOf(options, params) {
|
|
43
47
|
if (typeof options.locale === "function") return options.locale(params);
|
|
44
48
|
if (options.locale !== void 0) return options.locale;
|
|
@@ -49,12 +53,15 @@ function createBuilderPage(options) {
|
|
|
49
53
|
async function Page(props) {
|
|
50
54
|
const params = await props.params;
|
|
51
55
|
const slug = slugOf(options, params);
|
|
56
|
+
const currency = await currencyOf(options, params);
|
|
57
|
+
const { currency: _currency, ...rest } = options;
|
|
52
58
|
const loaded = await loadBuilderPage({
|
|
53
|
-
...
|
|
59
|
+
...rest,
|
|
54
60
|
slug,
|
|
55
|
-
locale: await localeOf(options, params)
|
|
61
|
+
locale: await localeOf(options, params),
|
|
62
|
+
...currency === void 0 ? {} : { currency }
|
|
56
63
|
}).catch((error) => {
|
|
57
|
-
if (error instanceof BuilderNotFoundError) notFound();
|
|
64
|
+
if (error instanceof BuilderNotFoundError || isNamed(error, "BuilderNotFoundError")) notFound();
|
|
58
65
|
throw error;
|
|
59
66
|
});
|
|
60
67
|
if (loaded.kind === "redirect") {
|
|
@@ -81,8 +88,8 @@ function createBuilderPage(options) {
|
|
|
81
88
|
routeLocale: options.locale === void 0 && typeof params.locale === "string" ? params.locale : void 0
|
|
82
89
|
});
|
|
83
90
|
} catch (error) {
|
|
84
|
-
if (error instanceof BuilderNotFoundError) return {};
|
|
85
|
-
if (error instanceof BuilderUnavailableError && client.mode !== "build") return {};
|
|
91
|
+
if (error instanceof BuilderNotFoundError || isNamed(error, "BuilderNotFoundError")) return {};
|
|
92
|
+
if ((error instanceof BuilderUnavailableError || isNamed(error, "BuilderUnavailableError")) && client.mode !== "build") return {};
|
|
86
93
|
throw error;
|
|
87
94
|
}
|
|
88
95
|
}
|
package/dist/server.cjs
CHANGED
|
@@ -12,25 +12,25 @@
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _chunkZCXPIZU7cjs = require('./chunk-ZCXPIZU7.cjs');
|
|
16
16
|
|
|
17
17
|
// src/server/load-site.ts
|
|
18
18
|
var _builder = require('@usethrottle/builder');
|
|
19
19
|
async function loadSite(options) {
|
|
20
|
-
const { locale, slots = [], packs = [], page, mediaOrigin = "" } = options;
|
|
21
|
-
const client =
|
|
20
|
+
const { locale, slots = [], packs = [], page, mediaOrigin = "", currency } = options;
|
|
21
|
+
const client = _chunkZCXPIZU7cjs.clientOf.call(void 0, options);
|
|
22
22
|
let bundle;
|
|
23
23
|
try {
|
|
24
|
-
bundle = await
|
|
24
|
+
bundle = await _chunkZCXPIZU7cjs.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
|
-
|
|
27
|
+
_chunkZCXPIZU7cjs.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 =
|
|
30
|
+
const registry = _chunkZCXPIZU7cjs.createRendererRegistry.call(void 0, packs);
|
|
31
31
|
const names = Object.keys(bundle.slots);
|
|
32
32
|
const documents = [bundle.header.document, bundle.footer.document, ...names.map((n) => bundle.slots[n].document)];
|
|
33
|
-
const data = await
|
|
33
|
+
const data = await _chunkZCXPIZU7cjs.staticDataFor.call(void 0, documents, registry, locale, currency);
|
|
34
34
|
return {
|
|
35
35
|
status: "ok",
|
|
36
36
|
locale,
|
|
@@ -38,9 +38,9 @@ async function loadSite(options) {
|
|
|
38
38
|
siteVersion: bundle.site.siteVersion,
|
|
39
39
|
mediaOrigin,
|
|
40
40
|
settings: bundle.site.settings,
|
|
41
|
-
header:
|
|
42
|
-
footer:
|
|
43
|
-
slots: Object.fromEntries(names.map((name) => [name,
|
|
41
|
+
header: _chunkZCXPIZU7cjs.partOf.call(void 0, bundle.header, data),
|
|
42
|
+
footer: _chunkZCXPIZU7cjs.partOf.call(void 0, bundle.footer, data),
|
|
43
|
+
slots: Object.fromEntries(names.map((name) => [name, _chunkZCXPIZU7cjs.partOf.call(void 0, bundle.slots[name], data)]))
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -48,13 +48,13 @@ async function loadSite(options) {
|
|
|
48
48
|
|
|
49
49
|
async function builderSitemap(options) {
|
|
50
50
|
if (options.client === void 0 && (options.builderKey === void 0 || options.builderKey === "")) {
|
|
51
|
-
|
|
51
|
+
_chunkZCXPIZU7cjs.warnOnce.call(void 0, "sitemap-no-key", "builderSitemap has no builderKey (is THROTTLE_BUILDER_KEY set?); the sitemap leaves out the Builder pages");
|
|
52
52
|
return [];
|
|
53
53
|
}
|
|
54
|
-
const client =
|
|
55
|
-
const origin =
|
|
54
|
+
const client = _chunkZCXPIZU7cjs.clientOf.call(void 0, options);
|
|
55
|
+
const origin = _chunkZCXPIZU7cjs.originOf.call(void 0, options.storeUrl);
|
|
56
56
|
if (origin === void 0) {
|
|
57
|
-
|
|
57
|
+
_chunkZCXPIZU7cjs.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.");
|
|
58
58
|
return [];
|
|
59
59
|
}
|
|
60
60
|
const locale = _nullishCoalesce(options.locale, () => ( "en"));
|
|
@@ -62,16 +62,16 @@ async function builderSitemap(options) {
|
|
|
62
62
|
const pages = await client.pages.list();
|
|
63
63
|
const { settings } = await client.site({ locale });
|
|
64
64
|
const indexable = await withoutNoindex(client, pages, locale);
|
|
65
|
-
const { list } =
|
|
65
|
+
const { list } = _chunkZCXPIZU7cjs.siteLocales.call(void 0, settings);
|
|
66
66
|
const prefixes = options.localeRoute !== true ? [void 0] : list.length > 0 ? list : [locale];
|
|
67
67
|
return indexable.flatMap((page) => {
|
|
68
|
-
const path =
|
|
68
|
+
const path = _chunkZCXPIZU7cjs.pagePathOf.call(void 0, settings, page, options.pagePath);
|
|
69
69
|
if (path === null) return [];
|
|
70
|
-
return prefixes.map((prefix) => ({ url: `${origin}${
|
|
70
|
+
return prefixes.map((prefix) => ({ url: `${origin}${_chunkZCXPIZU7cjs.localized.call(void 0, path, prefix)}`, lastModified: new Date(page.updatedAt) }));
|
|
71
71
|
});
|
|
72
72
|
} catch (error) {
|
|
73
73
|
if (!(error instanceof _builder.BuilderUnavailableError) || client.mode === "build") throw error;
|
|
74
|
-
|
|
74
|
+
_chunkZCXPIZU7cjs.warnOnce.call(void 0, "sitemap-unavailable", `The Builder could not be read (${error.reason}); the sitemap leaves out its pages`);
|
|
75
75
|
return [];
|
|
76
76
|
}
|
|
77
77
|
}
|
|
@@ -85,14 +85,14 @@ async function withoutNoindex(client, pages, locale) {
|
|
|
85
85
|
slice.map(
|
|
86
86
|
(page) => client.pages.get(page.slug, { locale }).catch((error) => {
|
|
87
87
|
if (error instanceof _builder.BuilderNotFoundError) return "gone";
|
|
88
|
-
|
|
88
|
+
_chunkZCXPIZU7cjs.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`);
|
|
89
89
|
return void 0;
|
|
90
90
|
})
|
|
91
91
|
)
|
|
92
92
|
);
|
|
93
93
|
slice.forEach((page, index) => {
|
|
94
94
|
const answer = answers[index];
|
|
95
|
-
if (answer === "gone" || answer !== void 0 && (
|
|
95
|
+
if (answer === "gone" || answer !== void 0 && (_chunkZCXPIZU7cjs.isRedirect.call(void 0, answer) || _chunkZCXPIZU7cjs.pageSeoOf.call(void 0, answer).noindex)) skip.add(page.slug);
|
|
96
96
|
});
|
|
97
97
|
}
|
|
98
98
|
return pages.filter((page) => !skip.has(page.slug));
|
|
@@ -100,7 +100,7 @@ async function withoutNoindex(client, pages, locale) {
|
|
|
100
100
|
|
|
101
101
|
// src/server/static-params.ts
|
|
102
102
|
async function builderStaticParams(options) {
|
|
103
|
-
const client =
|
|
103
|
+
const client = _chunkZCXPIZU7cjs.clientOf.call(void 0, options);
|
|
104
104
|
if (client.mode !== "build")
|
|
105
105
|
throw new TypeError(
|
|
106
106
|
'builderStaticParams generates every page of a frozen release: give it a client made with createBuilderClient({ mode: "build" }). A live store keeps its pages dynamic.'
|
|
@@ -119,4 +119,4 @@ async function builderStaticParams(options) {
|
|
|
119
119
|
|
|
120
120
|
|
|
121
121
|
|
|
122
|
-
exports.BuilderNotFoundError = _builder.BuilderNotFoundError; exports.BuilderUnavailableError = _builder.BuilderUnavailableError; exports.builderSitemap = builderSitemap; exports.builderStaticParams = builderStaticParams; exports.getBundle =
|
|
122
|
+
exports.BuilderNotFoundError = _builder.BuilderNotFoundError; exports.BuilderUnavailableError = _builder.BuilderUnavailableError; exports.builderSitemap = builderSitemap; exports.builderStaticParams = builderStaticParams; exports.getBundle = _chunkZCXPIZU7cjs.getBundle; exports.loadBuilderPage = _chunkZCXPIZU7cjs.loadBuilderPage; exports.loadSite = loadSite;
|
package/dist/server.d.cts
CHANGED
|
@@ -16,6 +16,11 @@ type LoadSiteOptions = ClientOptions & {
|
|
|
16
16
|
*/
|
|
17
17
|
mediaOrigin?: string;
|
|
18
18
|
packs?: readonly WidgetPack[];
|
|
19
|
+
/**
|
|
20
|
+
* The shopper's currency, when the store keeps one (a cookie): data sources that price things answer in it
|
|
21
|
+
* (`ctx.currency`). Without it they answer in the store's own currency.
|
|
22
|
+
*/
|
|
23
|
+
currency?: string;
|
|
19
24
|
};
|
|
20
25
|
/**
|
|
21
26
|
* Reads the site design once for a request: settings, header, footer and the
|
|
@@ -35,6 +40,8 @@ type LoadBuilderPageOptions = ClientOptions & {
|
|
|
35
40
|
packs?: readonly WidgetPack[];
|
|
36
41
|
/** The slots the layout reads, so this read can share the layout's. */
|
|
37
42
|
slots?: readonly string[];
|
|
43
|
+
/** The shopper's currency, as for `loadSite({ currency })`. */
|
|
44
|
+
currency?: string;
|
|
38
45
|
};
|
|
39
46
|
/**
|
|
40
47
|
* Reads one published page for a request. Data of the page's non-perShopper
|
package/dist/server.d.ts
CHANGED
|
@@ -16,6 +16,11 @@ type LoadSiteOptions = ClientOptions & {
|
|
|
16
16
|
*/
|
|
17
17
|
mediaOrigin?: string;
|
|
18
18
|
packs?: readonly WidgetPack[];
|
|
19
|
+
/**
|
|
20
|
+
* The shopper's currency, when the store keeps one (a cookie): data sources that price things answer in it
|
|
21
|
+
* (`ctx.currency`). Without it they answer in the store's own currency.
|
|
22
|
+
*/
|
|
23
|
+
currency?: string;
|
|
19
24
|
};
|
|
20
25
|
/**
|
|
21
26
|
* Reads the site design once for a request: settings, header, footer and the
|
|
@@ -35,6 +40,8 @@ type LoadBuilderPageOptions = ClientOptions & {
|
|
|
35
40
|
packs?: readonly WidgetPack[];
|
|
36
41
|
/** The slots the layout reads, so this read can share the layout's. */
|
|
37
42
|
slots?: readonly string[];
|
|
43
|
+
/** The shopper's currency, as for `loadSite({ currency })`. */
|
|
44
|
+
currency?: string;
|
|
38
45
|
};
|
|
39
46
|
/**
|
|
40
47
|
* Reads one published page for a request. Data of the page's non-perShopper
|
package/dist/server.js
CHANGED
|
@@ -12,12 +12,12 @@ import {
|
|
|
12
12
|
siteLocales,
|
|
13
13
|
staticDataFor,
|
|
14
14
|
warnOnce
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-65KZ5CIP.js";
|
|
16
16
|
|
|
17
17
|
// src/server/load-site.ts
|
|
18
18
|
import { BuilderUnavailableError } from "@usethrottle/builder";
|
|
19
19
|
async function loadSite(options) {
|
|
20
|
-
const { locale, slots = [], packs = [], page, mediaOrigin = "" } = options;
|
|
20
|
+
const { locale, slots = [], packs = [], page, mediaOrigin = "", currency } = options;
|
|
21
21
|
const client = clientOf(options);
|
|
22
22
|
let bundle;
|
|
23
23
|
try {
|
|
@@ -30,7 +30,7 @@ async function loadSite(options) {
|
|
|
30
30
|
const registry = createRendererRegistry(packs);
|
|
31
31
|
const names = Object.keys(bundle.slots);
|
|
32
32
|
const documents = [bundle.header.document, bundle.footer.document, ...names.map((n) => bundle.slots[n].document)];
|
|
33
|
-
const data = await staticDataFor(documents, registry, locale);
|
|
33
|
+
const data = await staticDataFor(documents, registry, locale, currency);
|
|
34
34
|
return {
|
|
35
35
|
status: "ok",
|
|
36
36
|
locale,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usethrottle/builder-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
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",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@usethrottle/builder-schema": "^0.1.2",
|
|
61
61
|
"@usethrottle/ui": "^0.1.2",
|
|
62
|
-
"@usethrottle/builder": "^0.
|
|
62
|
+
"@usethrottle/builder": "^0.4.0"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
65
|
"next": ">=15",
|